{"lang": "Java 7", "source_code": "import java.io.InputStream;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n long x,y,a,b;\n InputStream inputStream = System.in;\n// OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n// PrintWriter out = new PrintWriter(outputStream); \n \n \n x=in.nextInt();\n y=in.nextInt();\n a=in.nextInt();\n b=in.nextInt();\n long count=0;\n long x_,y_,xx;\n long xmin,xmax;\n x_=Math.max(x, y);\n xx=1;\n y_=Math.min(x, y);\n for (int i = 2; i <= y_; i++) {\n if ((x_%i==0)&&(y_%0==0))xx=i;\n }\n if (xx==1)xx=x*y;\n count=(b-a+1)/xx;\n if (a%x_==0)count++;\n// if (x_%y_==0){count=b/x_-a/x_;\n// if (a%x_==0)count++;}\n// else{\n// xmin=a/x_;\n// if(a%x_>0)xmin++;\n// xmax=b/x_;\n// for(long i=xmin;(x_*i)<=b;i++){\n// if (((i*x_)%y_==0))count++;\n// }}\n \n System.out.println(count);\n\n\n }\n\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dd740be52c25f1e0d2902a85fec0a739", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "package hjgh;\n\n/**\n * Created with IntelliJ IDEA.\n * User: ALEXXX\n * Date: 12.09.13\n * Time: 22:11\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.util.Scanner;\n\n\npublic class Code198A {\n\n\n public static int NOK(int x, int n) {\n int j;\n if (x < n) j = n;\n else j = x;\n boolean t = true;\n while (t) {\n if ((j % x == 0) && (j % n == 0)) break;\n else j += 1;\n }\n return (j);\n }\n\n public static void main(String[] args) {\n int a, b, t;\n Scanner sc = new Scanner(System.in);\n\n a = Integer.parseInt(args[0]);\n b = Integer.parseInt(args[1]);\n int l = Integer.parseInt(args[2]);\n int r = Integer.parseInt(args[3]);\n// a = sc.nextInt();\n// b = sc.nextInt();\n if (a < b) {\n t = b;\n b = a;\n a = t;\n }\n t = NOK(a, b);\n\n int i=l;\n boolean flag=true;\n while ((flag)&&(i<=r)) {\n if (i%t==0) {\n flag=false;\n break;\n }\n i++;\n }\n int p=0;\n if (flag==false){\n p++;\n }\n p=p+((r-i)/t);\n System.out.println(p);\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b55759304cf733d87cb527fd642bcd47", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package codeforce;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class theWall {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner in=new Scanner(System.in);\n\t\tint x=in.nextInt();\n\t\tint y=in.nextInt();\n\t\tint a=in.nextInt();\n\t\tint b=in.nextInt();\n\t\tint aa=a;\n\t\tArrayListlist=new ArrayList();\n\t\tlist.add(a);\n\t\tint count=0;\n\t\twhile(a<=b){\n\t\t\t a+=x;\n\t\t//\t System.out.print(a+\" \");\n\t\t\tlist.add(a);\n\t\t}\n\t\tSystem.out.println();\n\t\twhile(aa<=b){\n\t\t\tif(list.contains(aa)){\n\t\t\t//\t System.out.print(\"YES\"+\" \");\n\t\t\t count++;\t\n\t\t//\t System.out.println(count+\" \"+list.indexOf(aa));\n\t\t\t }\n\t\t\taa+=y;\n\t\t//\t System.out.print(aa+\" \");\n\t\t\t \n\t\t}\n\t\tSystem.out.print(count);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fc3bf83a19fd1bc10c6ccf6bcca506fe", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tout = new PrintWriter(\"output.txt\");\n\t\tsolve();\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tint x, y, a, b;\n\tint gcd (int a, int b) {\n\t\tif (b == 0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn gcd (b, a % b);\n\t}\n\tint mysolve(){\n\t\tint ans = 0;\n\t\tint aabb = gcd(y,x);\n//\t\tSystem.err.println(aabb);\n\t\tint l = x / aabb;\n\t\tint k = y / aabb;\n//\t\tSystem.err.println(l + \" \" + k);\n\t\tint n = (int)((long)a / (long)(k * x));\n\t\tif( (n * k * x) < a )\n\t\t\tn++;\n\t\tint m = (int)((long)b / (long)(k * x));\n\t\tans = m - n + 1;\n\t\treturn ans;\n\t}\n\t\n\tprivate void solve() throws IOException {\n\t\tx = nextInt();\n\t\ty = nextInt();\n\t\ta = nextInt();\n\t\tb = nextInt();\n\t\tint ans = mysolve();\n\t\tout.println(ans);\n\t}\n\n\tvoid chk(boolean b) {\n\t\tif (b)\n\t\t\treturn;\n\t\tSystem.out.println(new Error().getStackTrace()[1]);\n\t\texit(999);\n\t}\n\tvoid deb(String fmt, Object... args) {\n\t\tSystem.out.printf(Locale.US, fmt + \"%n\", args);\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "67413ffb998277ee5e16b1f3eca755ef", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class C {\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\tvoid solve() throws IOException {\n\t\tlong c[][] = new long[31][31];\n\t\tfor (int i = 0; i <= 30; i++)\n\t\t\tc[i][0] = 1;\n\t\tfor (int i = 1; i <= 30; i++)\n\t\t\tfor (int j = 1; j <= 30; j++) {\n\t\t\t\tc[i][j] = c[i - 1][j] + c[i - 1][j - 1];\n\t\t\t}\n\t\tlong res = 0;\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint t = nextInt();\n\t\tfor (int i = 4; i < t; i++)\n\t\t\tres = res + c[n][i] * c[m][t - i];\n\t\tout.println(res);\n\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 C().run();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c556dba1d1a67cfc744a826bc9f936f8", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class C {\n\n\tpublic C () throws IOException {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint t = sc.nextInt();\n\t\tsolve(n,m,t);\n\t}\n\t\n\tpublic void solve (int n, int m, int t) {\n\t\tBigInteger [][] C = new BigInteger [31][31];\n\t\tfor (int i = 0; i <= 30; ++i)\n\t\t\tC[i][0] = C[i][i] = BigInteger.ONE;\n\t\t\n\t\tfor (int i = 1; i <= 30; ++i) \n\t\t\tfor (int j = 1; j < i; ++j)\n\t\t\t\tC[i][j] = C[i-1][j-1].add(C[i-1][j]);\n\t\t\n\t\tBigInteger S = BigInteger.ZERO;\n\t\tfor (int b = 4; b < t; ++ b)\n\t\t\tS = S.add(C[n][b].multiply(C[m][t-b]));\n\t\t\n\t\tprint(S);\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic Scanner sc;\n\t\n\tstatic void print (Object o) {\n\t\tSystem.out.println(o);\n\t}\n\t\n\tstatic void run () throws IOException {\n\t\tsc = new Scanner(System.in);\n\t\tnew C();\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\trun();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "896e67c1202bf7b9e40a9f1cebe97704", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\npublic class C {\n\n\t/**\n\t * @param args\n\t */\n\tstatic void combiation(int n,int m)\n\t{\n\t\tcom = new long[n+1][m+1];\n\t\tfor(int i=0;i 0){\n\t\t\t\tc += com[n][i]*com[m][mm];\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(c);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04dcbca98258f85016e1b545caeda785", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main \n{\n public static BigInteger fact(BigInteger n)\n {\n if(n.equals(BigInteger.ZERO))\n return BigInteger.ONE;\n else\n return n.multiply(fact(n.subtract(BigInteger.ONE)));\n }\n public static BigInteger C(BigInteger n,BigInteger r)\n {\n return (fact(n).divide((fact(r).multiply(fact(n.subtract(r))))));\n }\n public static void main(String args[]) throws IOException\n {\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out=new PrintWriter(System.out);\n StringTokenizer st=new StringTokenizer(in.readLine());\n BigInteger n=new BigInteger(st.nextToken());\n BigInteger m=new BigInteger(st.nextToken());\n BigInteger t=new BigInteger(st.nextToken());\n BigInteger comb=BigInteger.ZERO;\n for(BigInteger b=new BigInteger(\"4\");t.subtract(b).compareTo(BigInteger.ONE)>=0 && b.compareTo(n)<=0;b=b.add(BigInteger.ONE))\n {\n BigInteger g=t.subtract(b);\n comb=comb.add(C(n,b).multiply(C(m,g)));\n }\n out.println(comb);\n out.flush();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e21b00281a4484da8520c344dc170c28", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0} {"lang": "Java 8", "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) + 5l;\n static double eps = (double)1e-4;\n public static void solve()throws IOException {\n int n = f.ni();\n boolean sieve[] = new boolean[(int)1e6];\n Arrays.fill(sieve , true);\n sieve[0] = false;\n sieve[1] = false;\n for (int i = 2; i < sieve.length; ++i) {\n if (sieve[i]) {\n for (int j = i + i; j < sieve.length; j += i) {\n sieve[j] = false;\n }\n }\n }\n\n int sum = (n * (n + 1)) / 2;\n\n int ans[] = new int[n + 1];\n Arrays.fill(ans , 1);\n\n if (sieve[sum]) {\n // All in same grp\n for (int i = 1; i <= n; ++i) p(ans[i] + \" \");\n }\n\n else {\n // Goldbach Conjecture\n\n if (ise(sum)) {\n for (int i = 2; i <= n; ++i) {\n if (sieve[i] && sieve[sum - i]) {\n ans[i] = 2;\n break;\n }\n }\n }\n\n else {\n\n if (sieve[sum - 2]) ans[2] = 2;\n else {\n ans[3] = 3;\n for (int i = 2; i <= n; ++i) {\n if (sieve[i] && sieve[sum - i - 3]) {\n ans[i] = 2;\n break;\n }\n }\n }\n }\n\n\n for (int i = 1; i <= n; ++i) {\n p(ans[i] + \" \");\n }\n pn(\"\"); \n }\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 factors(long n){HashSet hs=new HashSet();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet factors(int n){HashSet hs=new HashSet();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet pf(long n){HashSet ff=factors(n);HashSet res=new HashSet();for(Long i:ff)if(isPrime(i))res.add(i);return res;}\n static HashSet pf(int n){HashSet ff=factors(n);HashSet res=new HashSet();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 l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i a){Collections.sort(a);}//!Precompute fact in ncr()!\n 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< 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 factors(long n){HashSet hs=new HashSet();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet factors(int n){HashSet hs=new HashSet();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet pf(long n){HashSet ff=factors(n);HashSet res=new HashSet();for(Long i:ff)if(isPrime(i))res.add(i);return res;}\n static HashSet pf(int n){HashSet ff=factors(n);HashSet res=new HashSet();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 l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i a){Collections.sort(a);}//!Precompute fact in ncr()!\n 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< 2 && sum%2==1 &&primes[sum-2]==1) {\n\t\t\tcolors[2] = 2; sum -= 3;\n\t\t}\n\t\tif (n > 2) {\n\t\t\tfor (int i = 2; i < sum; i++) {\n\t\t\t\tif (primes[i]==0 && primes[sum-i]==0) {\n\t\t\t\t\tint left = i;\n\t\t\t\t\tfor (int j = n; j>= 1; j--) {\n\t\t\t\t\t\tif (colors[j-1]==0 && j <= left) {\n\t\t\t\t\t\t\tcolors[j-1] = 1;\n\t\t\t\t\t\t\tleft-=j;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int c: colors) {\n\t\t\tout.print((c+1) + \" \");\n\t\t}\n\t\tout.println();\n\t}\n\n\tprivate static int[] getPrimes(int sum) {\n\t\tint[] p = new int[sum+1];\n\t\tp[0] = p[1] = 1;\n\t\tfor (int i = 2; i < p.length; i++) {\n\t\t\tif (p[i] == 1) continue;\n\t\t\tfor (int j = i+i; j < p.length; j+=i) {\n\t\t\t\tp[j] = 1;\n\t\t\t}\n\t\t}\n\t\treturn p;\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tPrimeProblem solver = new PrimeProblem();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "56f6e56b87abab5e57e119e2bc613e92", "src_uid": "94ef0d901f21e1945849fd5bfc2d1449", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Goldbach {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tint S = (N*(N+1))/2;\n\t/**\tint[] pr = new int[3000*6001+1];\n\t\tfor(long i=2; i= '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\tpublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\tpublic static Reader sc = new Reader();\n}\n\n\n\n\n\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d831454e5b15dbc581de0d7bdb24a31", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main ( String args[] ) {\n\t\t\n\t\tScanner in = new Scanner( System.in );\n\t\tint i = in.nextInt();\n\t\t\n\t\tif( i > 2 ) {\n\t\t\tif( (i-2)%2 == 0 ) {\n\t\t\t\tSystem.out.print(\"YES\");\n\t\t\t}\n\t\t}\t\t\n\t\telse System.out.print(\"NO\");\n\t}\n\t\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "17e3cc4dfb4ecb85fa424884df1090e5", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.StreamTokenizer;\nimport java.io.Writer;\nimport java.util.Vector;\n\npublic class Abra {\n public static void main(String[] args) throws IOException {\n new Abra().run();\n }\n\n StreamTokenizer in;\n PrintWriter out;\n boolean oj;\n BufferedReader br;\n\n void init() throws IOException {\n oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n Reader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n Writer 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\n void run() throws IOException {\n long beginTime = System.currentTimeMillis();\n init();\n solve();\n long endTime = System.currentTimeMillis();\n if (!oj) {\n System.out.println(\"Memory used = \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));\n System.out.println(\"Running time = \" + (endTime - beginTime));\n }\n out.flush();\n }\n\n int nextInt() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\n\n long nextLong() throws IOException {\n in.nextToken();\n return (long) in.nval;\n }\n\n String nextString() throws IOException {\n in.nextToken();\n return in.sval;\n }\n\n double nextDouble() throws IOException {\n in.nextToken();\n return in.nval;\n }\n \n void solve() throws IOException {\n int n = nextInt();\n int[][] w = new int[n + 1][2];\n int[] sc = new int[n + 1];\n Vector[] ways = new Vector[n + 1];\n for (int i = 0; i <= n; i++) {\n w[i][0] = nextInt();\n w[i][1] = nextInt();\n }\n boolean b;\n ways[0] = new Vector();\n for (int i = 1; i <= n; i++) {\n ways[i] = new Vector();\n ways[i].add(i);\n sc[i] = i;\n }\n do {\n b = true;\n for (int i = 2; i <= n; i++) {\n if (w[i][0] + w[i][1] < w[i - 1][0] + w[i - 1][1]) {\n int c = w[i][0];\n w[i][0] = w[i - 1][0];\n w[i - 1][0] = c;\n c = w[i][1];\n w[i][1] = w[i - 1][1];\n w[i - 1][1] = c;\n c = sc[i];\n sc[i] = sc[i - 1];\n sc[i - 1] = c;\n b = false;\n }\n }\n } while (!b);\n for (int i = n; i >= 1; i--) {\n for (int j = i + 1; j <= n; j++) {\n if (ways[j].size() + 1 > ways[i].size() && w[i][0] < w[j][0] && w[i][1] < w[j][1]) {\n ways[i] = (Vector) ways[j].clone();\n ways[i].add(i);\n }\n }\n }\n for (int i = 1; i <= n; i++) {\n if (ways[i].size() > ways[0].size() && w[0][0] < w[i][0] && w[0][1] < w[i][1]) {\n ways[0] = (Vector) ways[i].clone();\n }\n }\n out.println(ways[0].size());\n for (int i = ways[0].size() - 1; i >= 0; i--) {\n out.print(sc[(Integer) ways[0].get(i)] + \" \");\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5aa1085905abeb7edd086a3776c87d0c", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class Watermelon {\n\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String s = in.readLine();\n\n int num = Integer.parseInt(s);\n\n if(num %2 == 0){\n System.out.println(\"YES\");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1b1c4c1eb75042be7bcfb3fcca87f9b3", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main ( String args[] ) {\n\t\t\n\t\tScanner in = new Scanner( System.in );\n\t\tint i = in.nextInt();\n\t\t\n\t\tif( i > 2 ) {\n\t\t\tif( (i-2)%2 == 0 ) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t}\t\t\n\t\telse System.out.println(\"NO\");\n\t}\n\t\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "03bfcd929d8103bd37b3cfc3516a843e", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists())\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\tnew Main().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\tchar[][] grid;\n\tboolean[][] used;\n\tint n, m;\n\tint[] dx = { -1, 0, 1, 0 };\n\tint[] dy = { 0, 1, 0, -1 };\n\tint ans = 0;\n\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tgrid = new char[n][m];\n\t\tused = new boolean[n][m];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tgrid[i] = nextLine().toCharArray();\n\t\tdfs(0);\n\t\tout.println(ans);\n\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tprivate void dfs(int c) {\n\t\tif (c == n * m) {\n\t\t\tint num = 0;\n\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\tfor (int k = 0; k < m; k++)\n\t\t\t\t\tif (grid[j][k] == 'P' && used[j][k])\n\t\t\t\t\t\tnum++;\n\t\t\tans = max(ans, num);\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = c; i < n * m; i++) {\n\t\t\tif (grid[i / m][i % m] == 'W') {\n\t\t\t\tint i1 = i / m;\n\t\t\t\tint j1 = i % m;\n\t\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\t\ti1 += dx[j];\n\t\t\t\t\tj1 += dy[j];\n\t\t\t\t\tif (i1 >= 0 && i1 < n && j1 >= 0 && j1 < m && !used[i1][j1] && grid[i1][j1] == 'P') {\n\t\t\t\t\t\tused[i1][j1] = true;\n\t\t\t\t\t\tdfs((i1 - dx[j]) * m + j1 - dy[j] + 1);\n\t\t\t\t\t\tused[i1][j1] = false;\n\t\t\t\t\t}\n\t\t\t\t\ti1 -= dx[j];\n\t\t\t\t\tj1 -= dy[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i == n * m - 1) {\n\t\t\t\tint num = 0;\n\t\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\t\tfor (int k = 0; k < m; k++)\n\t\t\t\t\t\tif (grid[j][k] == 'P' && used[j][k])\n\t\t\t\t\t\t\tnum++;\n\t\t\t\tans = max(ans, num);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid chk(boolean b) {\n\t\tif (b)\n\t\t\treturn;\n\t\tSystem.out.println(new Error().getStackTrace()[1]);\n\t\texit(999);\n\t}\n\tvoid deb(String fmt, Object... args) {\n\t\tSystem.out.printf(Locale.US, fmt + \"%n\", args);\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "34777519aad009f3d2b059e92d9448bf", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\npublic class B116 {\n\n public static int wolfs, maxPigs, n, m, a[][];\n public static boolean used[][];\n\n public static void rec(int x, int y, int w, int p) {\n if (w == wolfs) {\n if (p > maxPigs) {\n maxPigs = p;\n }\n } else if (w < wolfs) {\n for (int ii = x; ii < n; ii++) {\n for (int jj = (ii == x ? y : 0); jj < m; jj++) {\n if (a[ii][jj] == 2) {\n if (ii > 0 && !used[ii - 1][jj] && a[ii-1][jj] == 1) {\n used[ii - 1][jj] = true;\n rec(ii, jj + 1, w + 1, p + 1);\n used[ii - 1][jj] = false;\n }\n if (jj > 0 && !used[ii][jj - 1] && a[ii][jj-1] == 1) {\n used[ii][jj - 1] = true;\n rec(ii, jj + 1, w + 1, p + 1);\n used[ii][jj - 1] = false;\n }\n if (ii < (n - 1) && !used[ii + 1][jj] && a[ii+1][jj] == 1) {\n used[ii + 1][jj] = true;\n rec(ii, jj + 1, w + 1, p + 1);\n used[ii + 1][jj] = false;\n }\n if (jj < (m - 1) && !used[ii][jj + 1] && a[ii][jj+1] == 1) {\n used[ii][jj + 1] = true;\n rec(ii, jj + 1, w + 1, p + 1);\n used[ii][jj + 1] = false;\n }\n rec(ii,jj+1,w+1,p);\n }\n }\n }\n }\n }\n\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n m = in.nextInt();\n a = new int[n][m];\n used = new boolean[n][m];\n in.nextLine();\n wolfs = 0;\n maxPigs = 0;\n for (int i = 0; i < n; i++) {\n String s = in.nextLine();\n for (int j = 0; j < m; j++) {\n if (s.charAt(j) == 'W') {\n a[i][j] = 2;\n wolfs++;\n } else if (s.charAt(j) == 'P') {\n a[i][j] = 1;\n } else {\n a[i][j] = 0;\n }\n }\n }\n rec(0, 0, 0, 0);\n System.out.println(maxPigs);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3508eb41cd477443cb38033a0d1f33d1", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class PigsAndWolves {\n\t\n\tstatic int n, m, best;\n\tstatic char[][] grid;\n\tstatic int[] dr = {-1, 0, 1, 0};\n\tstatic int[] dc = {0, 1, 0, -1};\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(in.readLine());\n\t\tn = Integer.parseInt(st.nextToken());\n\t\tm = Integer.parseInt(st.nextToken());\n\t\tgrid = new char[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = in.readLine();\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tgrid[i][j] = s.charAt(j);\n\t\t\t}\n\t\t}\n\t\tbest = -1;\n\t\trec(0, 0, 0);\n\t\tSystem.out.println(best);\n\t}\n\t\n\tstatic void rec(int r, int c, int eaten) {\n\t\tif (c == m) {\n\t\t\tc = 0;\n\t\t\tr++;\n\t\t}\n\t\tif (r == n) {\n\t\t\tbest = Math.max(best, eaten);\n\t\t\treturn;\n\t\t}\n\t\tif (grid[r][c] == 'P') {\n\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\tint rr = r + dr[i];\n\t\t\t\tint cc = c + dc[i];\n\t\t\t\tif (onGrid(rr, cc)) {\n\t\t\t\t\tif (grid[rr][cc] == 'W') {\n\t\t\t\t\t\tgrid[rr][cc] = '.';\n\t\t\t\t\t\trec(r, c + 1, eaten + 1);\n\t\t\t\t\t\tgrid[rr][cc] = 'W';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\trec(r, c + 1, eaten);\n\t}\n\t\n\tstatic boolean onGrid(int r, int c) {\n\t\treturn r >= 0 && r < n && c >= 0 && c < m;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dde4f5bd62c25100fa9b3a92a94c0e4c", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "//package ladderB;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class littlePigsAndWolves {\n\tstatic ArrayList wolves;\n\tstatic pair [] trav;\n\tstatic class pair{\n\t\tint i, j;\n\t\tpublic pair(int i, int j) {\n\t\t\tthis.i = i;\n\t\t\tthis.j = j;\n\t\t}\n\t}\n\tstatic int traverse(char [][] map, int idx) {\n\t\tif(idx ==wolves.size())\n\t\t\treturn 0;\n\t\tpair wolf = wolves.get(idx);\n\t\tint counter = 0;\n\t\tfor (int i = 0; i < trav.length; i++) {\n\t\t\tint curI = wolf.i;\n\t\t\tint curJ = wolf.j;\n\t\t\tint possI = curI+trav[i].i;\n\t\t\tint possJ = curJ + trav[i].j;\n//\t\t\tSystem.out.println(possI+\" \"+possJ);\n\t\t\tif(possI>=0&&possI=0&&possJ();\n\ttrav = new pair[4];\n\ttrav[0] = (new pair(1,0));\n\ttrav[1] = (new pair(0,1));\n\ttrav[2] = (new pair(-1,0));\n\ttrav[3] = (new pair(0,-1));\n\tfor (int i = 0; i < map.length; i++) {\n\t\tString cur = sc.next();\n\t\tfor (int j = 0; j < map[i].length; j++) {\n\t\t\tmap[i][j] = cur.charAt(j);\n\t\t\tif(map[i][j]=='W')\n\t\t\t\twolves.add(new pair(i,j));\n\t\t}\n\t}\n//\tSystem.out.println(wolves.size());\n\tif(wolves.size()==0)\n\t\tSystem.out.println(0);\n\telse\n\tSystem.out.println(traverse(map, 0));\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd9f03aa0fa09518018bfebd37deed43", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package codeforces;\n\nimport java.util.Scanner;\nimport java.io.PrintWriter;\n\npublic class TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int countp = in.nextInt();\n String s = in.next();\n in.close();\n char[] al = s.toCharArray();\n int[] count = new int[26];\n for(char c: al){\n int j = c -'a' ;\n count[j]++;\n }\n int count2 = 0;\n for(int i : count) {\n if (i >=2) {\n count2++;\n }\n }\n if(count2>0){\n out.write(\"Yes\");\n }else {\n out.write(\"No\");\n }\n out.close();\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db1f9187a58ba571bb1342e586041dad", "src_uid": "6b22e93f7e429693dcfe3c099346dcda", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n HashSet dublicates = new HashSet<>();\n for(int i = 0; i < n; i++) {\n String color = in.next();\n if(dublicates.contains(color)) {\n System.out.println(\"Yes\");\n }\n dublicates.add(color);\n }\n System.out.println(\"No\");\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "550ee8a741f6b9da97f218e1add14049", "src_uid": "6b22e93f7e429693dcfe3c099346dcda", "difficulty": 900.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage cfa;\nimport java.util.Scanner;\n\n/**\n *\n * @author jay\n */\npublic class Cfa {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n String s;\n int t;\n int flag=0;\n Scanner in = new Scanner(System.in);\n t=in.nextInt();\n s=in.next();\n// s=in.nextLine();\n// System.out.println(t);\n// System.out.println(s);\n int[] h=new int[26];\n \n for(int i=0;i<26;i++)\n h[i]=0;\n \n// for(int i=0;i<26;i++)\n// System.out.print(h[i]+\" \");\n// System.out.println(\"\");\n \n for(int i=0;i0)\n flag=1;\n else\n h[s.charAt(i) - 'a']++;\n }\n \n// for(int i=0;i<26;i++)\n// System.out.print(h[i]+\" \");\n// System.out.println(\"\");\n \n if(flag==1)\n {\n System.out.println(\"Yes\");;\n }\n else\n {\n System.out.println(\"No\");\n }\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ef891329456ca4c6433986b620451900", "src_uid": "6b22e93f7e429693dcfe3c099346dcda", "difficulty": 900.0} {"lang": "Java 8", "source_code": "package codefocecontest1;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class doggo {\n\n\tpublic static void main(String[] args) {\n\t\t Scanner s = new Scanner(System.in);\n\t\t int pupNum = s.nextInt();\n\n\t\t s.nextLine();\n\t\t String pup = s.nextLine();\n\n\t\t boolean ans = false;\n\t\t ArrayList pups = new ArrayList ();\n\t\t for(int i = 0; i < pupNum; i++) {\n\t\t \tpups.add(pup.substring(i,i+1));\n\t\t }\n\t\t if(pups.size() == 1) {\n\t\t \tSystem.out.println(\"YES\");\n\t\t \tSystem.exit(0);\n\t\t }\n\t\t for(int i = 0; i< pupNum; i++) {\n\t\t if (ans) break;\n\t\t for(int j = i+1; j skills[2][0] && skills[0][0] > skills[3][0] &&\n\t\t\tskills[1][1] > skills[2][1] && skills[1][1] > skills[3][1]) {\n\t\t\t\torder[0] = 0;\n\t\t\t\torder[1] = 1;\n\t\t} else {\n\t\t\torder[0] = 1;\n\t\t\torder[1] = 0;\n\t\t}\n\t}\n\n\tpublic static void choose2(int[][] skills, int[] order) {\n\t\tint d1 = order[0], a1 = order[1];\n\t\tif (skills[2][0] > skills[d1][0] && skills[3][1] > skills[a1][1]) {\n\t\t\t\torder[2] = 2;\n\t\t\t\torder[3] = 3;\n\t\t} else {\n\t\t\torder[2] = 3;\n\t\t\torder[3] = 2;\n\t\t}\n\t}\n\n\tpublic static int play(int[][] skills, int[] order) {\n\t\tint d1 = order[0], a1 = order[1], d2 = order[2], a2 = order[3], result;\n\t\tif (skills[d1][0] > skills[d2][0]) {\n\t\t\tif (skills[a1][1] > skills[a2][1]) {\n\t\t\t\tresult = 1;\n\t\t\t} else {\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t} else if (skills[d1][0] == skills[d2][0]) {\n\t\t\tresult = 0;\n\t\t} else {\n\t\t\tif (skills[a1][1] < skills[a2][1]) {\n\t\t\t\tresult = 2;\n\t\t\t} else {\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tint[][] skills = new int[4][2];\n\t\tint[] order = new int[4]; // defence 1, attack 1, defence 2, attack 2\n\n\t\tString[] tempList;\n\t\tString line;\n\t\tfor (int i = 0; i < 4; ++i) {\n\t\t\tline = br.readLine();\n\t\t\ttempList = line.split(\"\\\\s\");\n\t\t\tfor (int j = 0; j < 2; ++j) {\n\t\t\t\tskills[i][j] = Integer.parseInt(tempList[j]);\n\t\t\t}\n\t\t}\n\n\t\tchoose1(skills, order);\t// team 1 choose\n\t\tchoose2(skills, order);\t// team 2 choose\n\n\t\tint result = play(skills, order);\n\t\tif (result == 0) {\n\t\t\tSystem.out.println(\"Draw\");\n\t\t} else {\n\t\t\tSystem.out.println(\"Team \" + result);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ee81164d137e7ecfcc09c63981cc88c0", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint t1p1A = in.nextInt();\n\t\tint t1p1D = in.nextInt();\n\t\tint t1p2A = in.nextInt();\n\t\tint t1p2D = in.nextInt();\n\t\tint t2p1A = in.nextInt();\n\t\tint t2p1D = in.nextInt();\n\t\tint t2p2A = in.nextInt();\n\t\tint t2p2D = in.nextInt();\n\t\t\n\t\tboolean advantage2; // Advantage of team 2\n\t\t\n\t\t// Case 1. Team 1 (A D) is (t1p1A t1p2D)\n\t\tif ((t2p1A < t1p1A && t2p2D < t1p2D) && (t2p2A < t1p1A && t2p1D < t1p2D)) {\n\t\t\tSystem.out.println(\"Team 1\");\n\t\t\treturn;\n\t\t}\n\t\tif ((t2p1A > t1p1A && t2p2D > t1p2D) || (t2p2A > t1p1A && t2p1D > t1p2D)) advantage2 = true;\n\t\telse advantage2 = false;\n\t\t\n\t\t// Case 2. Team 1 (A D) is (t1p2A t1p1D)\n\t\tif ((t2p1A < t1p2A && t2p2D < t1p1D) && (t2p2A < t1p2A && t2p1D < t1p1D)) {\n\t\t\tSystem.out.println(\"Team 1\");\n\t\t\treturn;\n\t\t}\n\t\telse if (((t2p1A > t1p2A && t2p2D > t1p1D) || (t2p2A > t1p2A && t2p1D > t1p1D)) && advantage2) {\n\t\t\tSystem.out.println(\"Team 2\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(\"Draw\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1b591fafbcfe1f4a5eea960a869f0f82", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.min;\nimport static java.lang.Math.max;\n\npublic class Main {\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n\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 static void mergeSort(int[] a) {\n mergeSort(a, 0, a.length - 1);\n }\n\n private static void mergeSort(int[] a, int levtIndex, int rightIndex) {\n final int MAGIC_VALUE = 2;\n if (levtIndex < rightIndex) {\n if (rightIndex - levtIndex <= MAGIC_VALUE) {\n insertionSort(a, levtIndex, rightIndex);\n } else {\n int middleIndex = (levtIndex + rightIndex) / 2;\n mergeSort(a, levtIndex, middleIndex);\n mergeSort(a, middleIndex + 1, rightIndex);\n merge(a, levtIndex, middleIndex, rightIndex);\n }\n }\n }\n\n private static void merge(int[] a, int levtIndex, int middleIndex,\n int rightIndex) {\n int length1 = middleIndex - levtIndex + 1;\n int length2 = rightIndex - middleIndex;\n int[] levtArray = new int[length1];\n int[] rightArray = new int[length2];\n System.arraycopy(a, levtIndex, levtArray, 0, length1);\n System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) {\n if (i == length1) {\n a[k] = rightArray[j++];\n } else if (j == length2) {\n a[k] = levtArray[i++];\n } else {\n a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++]\n : rightArray[j++];\n }\n }\n }\n\n private static void insertionSort(int[] a, int levtIndex, int rightIndex) {\n for (int i = levtIndex + 1; i <= rightIndex; i++) {\n int current = a[i];\n int j = i - 1;\n while (j >= levtIndex && a[j] > current) {\n a[j + 1] = a[j];\n j--;\n }\n a[j + 1] = current;\n }\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 {\n\n int x;\n int y;\n\n public LOL(int x, int y) {\n this.x = x;\n this.y = y;\n\n }\n\n\n\n @Override\n public int compareTo(LOL o) {\n if (x == o.x) {\n return y - o.y;\n }\n\n return (x - o.x);\n // return o.x * o.y - x * y; // <----\n }\n\n }\n\n Map > g = new HashMap>();\n\n\n\n\n\n\n\n\n\n\n\n public void solve() throws IOException {\n int n = 4;\n int a[] = new int[n + 1];\n int b[] = new int[n + 1];\n\n for (int i = 1; i <= n; i++) {\n a[i] = readInt();\n b[i] = readInt();\n }\n\n int win1 = 0;\n int draw1 = 0;\n int loose1 = 0;\n\n if (a[1] > a[3] && b[2] > b[4]) {\n win1++;\n } else if (a[1] < a[3] && b[2] < b[4]) {\n loose1++;\n } else {\n draw1++;\n }\n\n if (a[1] > a[4] && b[2] > b[3]) {\n win1++;\n } else if (a[1] < a[4] && b[2] < b[3]) {\n loose1++;\n } else {\n draw1++;\n }\n\n if (win1 == 2) {\n out.print(\"Team 1\");\n return;\n }\n\n int win2 = 0;\n int draw2 = 0;\n int loose2 = 0;\n\n if (a[2] > a[3] && b[1] > b[4]) {\n win2++;\n } else if (a[2] < a[3] && b[1] < b[4]) {\n loose2++;\n } else {\n draw2++;\n }\n\n if (a[2] > a[4] && b[1] > b[3]) {\n win2++;\n } else if (a[2] < a[4] && b[1] < b[3]) {\n loose2++;\n } else {\n draw2++;\n }\n\n if (win2 == 2) {\n out.print(\"Team 1\");\n return;\n }\n\n if (loose1 > 1 && loose2 > 1) {\n out.print(\"Team 2\");\n return;\n }\n\n out.print(\"Draw\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8cf28cbe5faa20a4b7ccf4dac9a2cc8b", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "package players;\n\nimport java.util.Scanner;\n\npublic class Players {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String[][] s = new String[4][2];\n int[][] j = new int[4][2];\n for(int i = 0; i < 4; ++ i) {\n String t = sc.nextLine(); \n String s1 = t.split(\" \")[0];\n String s2 = t.split(\" \")[1];\n //System.out.println(s1 + \" \" + s2);\n j[i][0] = Integer.parseInt(s1);\n j[i][1] = Integer.parseInt(s2);\n }\n int t1_t1 = j[0][1];\n int t1_t2 = j[1][1];\n int t1_d1 = j[0][0];\n int t1_d2 = j[1][0];\n \n int t2_t1 = j[2][1];\n int t2_t2 = j[3][1];\n int t2_d1 = j[2][0];\n int t2_d2 = j[3][0];\n \n //int t1_max_t = Integer.max(t1_t1, t1_t2);\n //int t1_max_d = Integer.max(t1_d1, t1_d2);\n \n //int t2_max_t = Integer.max(t2_t1, t2_t2);\n //int t2_max_d = Integer.max(t2_d1, t2_d2);\n //if(t1_max_t > t2_max_d && t1_max_d > t2_max_t) System.out.println(\"Team 1\"); \n //else if(t2_max_t > t1_max_d && t2_max_d > t1_max_t) System.out.println(\"Team 2\");\n //else System.out.println(\"Draw\");\n \n int t1_t = j[0][1];\n int t1_d = j[1][0];\n \n int t1_t_1 = j[0][1];\n int t1_d_1 = j[1][0];\n \n int state = -1;\n if((t1_t > j[2][0] && t1_d > j[3][1]) && (t1_t > j[3][0] && t1_d > j[2][1])) {\n System.out.println(\"Team 1\");\n return;\n }\n if((t1_t_1 > j[2][0] && t1_d_1 > j[3][1]) && (t1_t_1 > j[3][0] && t1_d_1 > j[2][1])) {\n System.out.println(\"Team 1\");\n return; \n }\n int t2_t = j[2][1];\n int t2_d = j[3][0];\n \n int t2_t_1 = j[3][1];\n int t2_d_1 = j[2][0];\n \n if((t2_t > t1_d && t2_d > t1_t) || (t2_t_1 > t1_d && t2_d_1 > t1_t)) {\n System.out.println(\"Team 2\");\n return;\n }\n if((t2_t_1 > t1_d && t2_d_1 > t1_t) || (t2_t_1 > t1_t_1 && t2_d_1 > t1_t_1)) {\n System.out.println(\"Team 2\");\n return;\n }\n \n System.out.println(\"Draw\");\n \n \n } \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6ac0f37c78260bc23e846eb88f9131e3", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic final class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint t=sc.nextInt();\n\t\tint arr[]=new int[t];\n\t\tQueue q=new LinkedList();\n\t\tint n=0;\n\t\tfor(int i=0;i0)\n\t\t\t{\n\t\t\t\tn++;\n\t\t\t\tq.add(arr[i]);\n\t\t\t}\n\t\t}\n\t\n\t\t//int freq[]=new int[max+1];\n\tint count=0;\n\twhile(t>0)\n\t{\n\t\tint x=q.peek();\n\t\tif(t-x<=0)\n\t\tcontinue;\n\t\t\n\t\tt=t-x;\n\t\tcount++;\n\t\tif(count==n)\n\t\tcount=1;\n\t\tq.remove();\n\t\tq.add(x);\n\t}\n\t\t\n\t\tSystem.out.println(count);\n\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ef067dc4532640bbf83b6ec6e9d437cc", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class A139 {\n\n public void main_menu() {\n Scanner scan = new Scanner(System.in);\n\n int n = scan.nextInt();\n\n int week[] = new int[8];\n\n for (int i = 0; i < 7; i++) {\n week[i] = scan.nextInt();\n }\n\n int total = 0;\n while (true) {\n\n for (int i = 0; i < n; i++) {\n\n total += week[i];\n if (total >= n) {\n System.out.println(i + 1);\n return;\n\n }\n\n }\n\n }\n\n }\n\n public static void main(String[] args) {\n new A139().main_menu();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "731bc949dfee9b541da5c08ee71a6092", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Solution {\n\n static Scanner scan = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = scan.nextInt();\n System.out.println(doProcess(n));\n }\n \n private static int doProcess(int n){\n int [] p = new int[n];\n int sum=0, i=0;\n while(sum0)\n\t{\n\t\tif(count==7)\n\t\tcount=1;\n\t\tcount++;\n\t\tt=t-arr[count-1];\n\t}\n\t\t\n\t\tSystem.out.println(count);\n\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "262367727552305b41721cb09faed1db", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class EasterEggs {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n String[] color = {\"R\",\"O\",\"Y\",\"G\",\"B\",\"I\",\"V\"};\n for(int i = 0; i < n; i++){\n if(i > 6){\n int mod = (i)%6;\n System.out.print(color[mod + 2]);\n }\n else{\n System.out.print(color[i]);\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "08de36002ec5fb063aa098d587514867", "src_uid": "dc3817c71b1fa5606f316e5e94732296", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "package Contest1;\n\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class problem2 {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = in.nextInt();\n\t\tint Color[] = new int[N];\n\t\tfor(int i=0;i6)\n x=0;\n char y = arr[x];\n if(y!=output[i-1]&&y!=output[i-2]&&y!=output[i-3]&&y!=output[i-4])\n {\n if((y!=output[(i+1)%size]&&y!=output[(i+2)%size]&&y!=output[(i+3)%size]&&y!=output[(i+4)%size]))\n {output[i]=y; }\n else\n i--;\n }\n else\n i--;\n x++ ;\n if(output[size-1]!='a')\n break ;\n }\n\n for(int i=0;i 3) {\n\n\t\t\tfor (int i = 0; i < c.length && N > 3; i++) {\n\t\t\t\tif (ans.length() == 0 || ans.length() < 3 || !in(c[i], ans.substring(ans.length() - 3, ans.length()))) {\n\t\t\t\t\tans.append(c[i]);\n\t\t\t\t\tN--;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\tint p = 5;\n\t\twhile (N > 0) {\n\t\t\tfor (int i = 0; i < c.length && N > 0; i++) {\n\t\t\t\tif (ans.length() == 0 || ans.length() < 3 || !in(c[i], ans.substring(ans.length() - 3, ans.length()))\n\t\t\t\t\t\t&& !in(c[i], ans.substring(0, Math.min(p, ans.length())))) {\n\t\t\t\t\tans.append(c[i]);\n\t\t\t\t\tN--;\n\t\t\t\t\tp--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(ans);\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\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArray1(int n) throws IOException {\n\t\t\tint[] a = new int[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArraySorted(int n) throws IOException {\n\t\t\tint[] a = nextIntArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tint t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray1(int n) throws IOException {\n\t\t\tlong[] a = new long[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArraySorted(int n) throws IOException {\n\t\t\tlong[] a = nextLongArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tlong t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe4984253d457bfa424c0f227e87f936", "src_uid": "dc3817c71b1fa5606f316e5e94732296", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class B {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tlong gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n\tpublic void solve() throws IOException {\n\t\tlong n = in.nextLong();\n\t\tlong m = in.nextLong();\n\t\tlong x = in.nextLong();\n\t\tlong y = in.nextLong();\n\t\tlong a = in.nextLong();\n\t\tlong b = in.nextLong();\n\n\t\tlong g = gcd(a, b);\n\t\ta /= g; b /= g;\n\n\t\tlong k = Math.min(n / a, m / b);\n\n\t\tlong width = k * a;\n\t\tlong height = k * b;\n\n\t\tlong rx = Math.max(Math.min(x - width / 2 - width % 2, n - width), 0);\n\t\tlong ry = Math.max(Math.min(y - height / 2 - height % 2, m - height), 0);\n\n\t\tout.println(rx + \" \" + ry + \" \" + (rx + width) + \" \" + (ry + height));\n\t}\n\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(InputStream is) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t\t} catch (Exception 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.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\treturn null;\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.valueOf(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] arg) {\n\t\tnew B().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "031403592084094818e3584fccbd476e", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic int gcd(int a, int b) {\n\t\tif (a > b) return gcd(b, a);\n\t\tif (a == 0) return b;\n\t\treturn gcd(b % a, a);\n\t}\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 m = next();\n\t\tint xx = next();\n\t\tint yy = next();\n\t\tint a = next();\n\t\tint b = next();\n\n\t\tint c = gcd(a, b);\n\t\ta /= c;\n\t\tb /= c;\n\n\t\tint mult = Math.min(n/a, m/b);\n\t\ta *= mult;\n\t\tb *= mult;\n\n\t\tint x1 = 0;\n\t\tint x2 = a;\n\t\tint y1 = 0;\n\t\tint y2 = b;\n\n\t\tint shiftx = Math.max(0, Math.min(n - a, xx - (a + 1)/2));\n\t\tint shifty = Math.max(0, Math.min(m - b, yy - (b + 1)/2));\n\n\t\tx1 += shiftx;\n\t\tx2 += shiftx;\n\t\ty1 += shifty;\n\t\ty2 += shifty;\n\n\t\tout.println(x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n\n\t\t\n\t\t//System.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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "02ffd874d0485d4678e24b6caa771f38", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0} {"lang": "Java 7", "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\t\n\tstatic int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\t\n\tint solve(int bigLen, int ins, int smallLen) {\n\t\tint low = Math.max(ins - smallLen, 0);\n\t\tint high = Math.min(ins, bigLen - smallLen);\n\t\t\n\t\tint doubleOpt = 2 * ins - smallLen;\n\t\tif (doubleOpt < 2 * low)\n\t\t\treturn low;\n\t\tif (doubleOpt > 2 * high)\n\t\t\treturn high;\n\t\treturn doubleOpt / 2;\n\t}\n\n\tvoid solve(int n, int m, int x, int y, int a, int b) {\n\t\tint gcd = gcd(a, b);\n\t\ta /= gcd;\n\t\tb /= gcd;\n\t\t\n\t\tint sz = Math.min(n / a, m / b);\n\t\ta *= sz;\n\t\tb *= sz;\n\t\t\n\t\tint x1 = solve(n, x, a);\n\t\tint y1 = solve(m, y, b);\n\t\tout.println(x1 + \" \" + y1 + \" \" + (x1 + a) + \" \" + (y1 + b));\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\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint x = nextInt();\n\t\tint y = nextInt();\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\t\tsolve(n, m, x, y, a, b);\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0175fcc70b7a841c1bcdc814991fee7d", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Rectangle2{\n\tpublic static void main(String[] args) throws Exception{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] g = in.readLine().split(\"\\\\s+\");\n\t\tlong n = Long.parseLong(g[0]);\n\t\tlong m = Long.parseLong(g[1]);\n\t\tlong x = Long.parseLong(g[2]);\n\t\tlong y = Long.parseLong(g[3]);\n\t\tlong a = Long.parseLong(g[4]);\n\t\tlong b = Long.parseLong(g[5]);\n\t\tlong gcf = gcd(Math.max(a,b),Math.min(a,b));\n\t\ta/=gcf;\n\t\tb/=gcf;\n\t\tlong l = (n/a)*a;\n\t\tlong w = (l*b)/a;\n\t\tif(w>m){\n\t\t\tw = (m/b)*b;\n\t\t\tl = (w*a)/b;\n\t\t}\n\t\tlong xhalf = (long)Math.ceil((l+0.0)/2);\n\t\tlong yhalf = (long)Math.ceil((w+0.0)/2);\n\t\tlong x1 = x-xhalf;\n\t\tlong y1 = y-yhalf;\n\t\tlong x2 = x+(l-xhalf);\n\t\tlong y2 = y+(w-yhalf);\n\t\t// System.out.println(x1+\" \"+y1+\" \"+x2+\" \"+y2);\n\t\t// System.out.println(l+\" \"+w);\n\t\tif(x2>n){\n\t\t\tlong d = x2-n;\n\t\t\tx2-=d;\n\t\t\tx1-=d;\n\t\t}\n\t\telse if(x1<0){\n\t\t\tlong d = -x1;\n\t\t\tx2+=d;\n\t\t\tx1+=d;\n\t\t}\n\t\tif(y2>m){\n\t\t\tlong d = y2-m;\n\t\t\ty2-=d;\n\t\t\ty1-=d;\n\t\t}\n\t\telse if(y1<0){\n\t\t\tlong d = -y1;\n\t\t\ty2+=d;\n\t\t\ty1+=d;\n\t\t}\n\t\tSystem.out.println(x1+\" \"+y1+\" \"+x2+\" \"+y2);\n\t}\n\t\n\tstatic long gcd(long a, long b){\n\t\tlong c = a%b;\n\t\tif(c==0) return b;\n\t\treturn gcd(b,c);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "091904b860ca197cda961421d0027b1a", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "//package CodeForces;\n\n/*In the name of Allah the Most Merciful.\n * Author\n * Md. Toufiqul Islam\n * Dept. Of CSE\n * Ahsanullah University Of Science And Technology\n*/\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class ER36B {\n\n public static void main(String[] args) {\n InputReader sc = new InputReader(System.in);\n OutputWriter out = new OutputWriter(System.out);\n\n int n = sc.nextInt();\n int pos = sc.nextInt();\n int pos1 = pos;\n int l = sc.nextInt();\n int r = sc.nextInt();\n\n int a = 1;\n int b = n;\n int totalSec =0;\n int totalSec1 =0;\n if(a==l && b==r){\n out.println(\"0\");\n }\n\n else{\n\n if(a!=l && b!=r){\n\n while (pos1!=l){\n pos1--;\n totalSec++;\n }\n\n totalSec++;\n\n while (pos1!=r){\n pos1++;\n totalSec++;\n }\n totalSec++;\n\n pos1 = pos;\n\n // System.out.println(\"Pos1 \"+pos1);\n\n while (pos1!=r){\n pos1++;\n totalSec1++;\n // System.out.println(totalSec1);\n\n }\n\n\n totalSec1++;\n\n\n while (pos1!=l){\n pos1--;\n totalSec1++;\n\n }\n // System.out.println();\n totalSec1++;\n\n\n\n // System.out.println(totalSec+\" \"+totalSec1);\n out.println(Math.min(totalSec,totalSec1));\n }\n else if(a!=l && b==r){\n while (pos1!=l){\n pos1--;\n totalSec++;\n }\n\n totalSec++;\n\n\n\n System.out.println(totalSec);\n }\n\n else if(a==l && b!=r){\n // System.out.println(pos1+\" \"+r);\n\n while (pos1!=r){\n pos1++;\n totalSec1++;\n // System.out.println(totalSec1);\n\n }\n\n\n totalSec1++;\n\n\n // System.out.println();\n\n\n System.out.println(totalSec1);\n\n }\n else{\n System.out.println(\"0\");\n }\n }\n out.close();\n }\n\n public static class InputReader {\n private boolean finished = false;\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\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 }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuilder buf = new StringBuilder();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r') {\n buf.appendCodePoint(c);\n }\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0) {\n s = readLine0();\n }\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines) {\n return readLine();\n } else {\n return readLine0();\n }\n }\n\n public BigInteger readBigInteger() {\n try {\n return new BigInteger(nextString());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n\n public char nextCharacter() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n return (char) c;\n }\n\n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public boolean isExhausted() {\n int value;\n while (isSpaceChar(value = peek()) && value != -1) {\n read();\n }\n return value == -1;\n }\n\n public String next() {\n return nextString();\n }\n\n public SpaceCharFilter getFilter() {\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter) {\n this.filter = filter;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n public int[] nextIntArray(int n){\n int[] array=new int[n];\n for(int i=0;ir){\n System.out.println((pos-r)+1);\n }else{\n System.out.println(n-pos);\n }\n }else{\n if(n==r){\n while(pos!=l){\n pos--;\n i++;\n } \n System.out.println(i+1);\n }else{\n while(pos!=l){\n pos--;\n i++;\n }\n while(pos!=n){\n pos++;\n i++;\n }\n System.out.println(i);\n }\n }\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6ed6cbef98b6441075c54695e0871b84", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\n\n\npublic class Main {\n\n\t\n\tprivate static Scanner in = new Scanner(System.in);\n\t \n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tint n = in.nextInt();\n\t\tint c = in.nextInt();\n\t\tint l = in.nextInt();\n\t\tint r = in.nextInt();\n\t\t\n\t\tint [] a = new int[n];\n\t\t\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif(i>=l-1 && i<=r-1) a[i]=-1;\n\t\t}\n\t\t\n\t\tint num = 0;\n\t\t\n\t\n\t\tc=c-1;\n\t\tr=r-1;\n\t\tl=l-1;\n\t\t\n\t\twhile(!isFinish(a)) {\n\t\t\t\n\t\t\tif(Math.abs(c-l)> solve(HashMap map) {\n\t\t\n\t\tboolean flag = false;\n\t\t \n\t\tHashMap> ans = new HashMap<>();\n\t\t\n\t\tfor (Map.Entry m : map.entrySet()) {\n\t\t\tString [] ss = m.getValue();\n\t\t\tfor (int i = 0; i < ss.length; i++) {\n\t\t\t\tfor (int j = i+1; j < ss.length; j++) {\n\t\t\t\t\tif(ss[j].endsWith(ss[i])) {\n\t\t\t\t\t\tflag = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tif(!flag) {\n\t\t\t\t//\tans.put(m.getKey(), value)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n\t\n\tstatic void fillAnArray(long [] a) {\n\t\tfor (int i = 0; i < a.length - 1; i++) {\n\t\t\ta[i]=in.nextLong();\n\t\t}\n\t}\n\tstatic int [] shuffleAnArray(int [] a) {\n\t\t\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint index = (int)(Math.random()*a.length);\n\t\t\tint temp = a[i];\n\t\t\ta[i]=a[index];\n\t\t\ta[index]=temp;\t\t\t\n\t\t}\n\t\t\t\t\n\t\treturn a;\n\t\t\n\t}\n\tstatic int gcd(int a,int b) {\n\t\treturn a==0 ? b : gcd(b%a,a);\n\t}\n\t\n\tstatic boolean eulerFunction(int n, int k) {\n\t\treturn gcd(n,k)==1;\n\t}\n\tstatic String operate(String S, int l,int r,char o,char n) {\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(i>=l-1 && i<=r-1) {\n\t\t\t\t\n\t\t\t\tif(S.charAt(i)== o) {\n\t\t\t\t\tss+=n;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\telse {\n\t\t\t\t\tss+=S.charAt(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tss+=S.charAt(i);\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn ss;\n\t}\n\tstatic int sumOfArray(int [] a) {\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < a.length; i++) \n\t\t\tif(a[i]>0)sum+=a[i];\t\t\t\n\t\treturn sum;\n\t}\n\t\n\tprivate static long convert(int i) {\n\t\tlong res = i;\n\t\twhile(i>0){\n\t\t\tint lastNum = i % 10;\n\t\t\tres = res * 10 + lastNum;\n\t\t\ti /=10;\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\n\tstatic int numberOfElementsAboveZero(int [] a) {\n\t\tint num = 0;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif(a[i]>0) num++;\n\t\t}\t\t\n\t\treturn num;\n\t}\n\tstatic int min(int [] a) {\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif(a[i]>0 && a[i]x){\n\t\t\t\ti--;\n\t\t\t\tn= (i*(i-1))/2+1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tresult=x-n+1;\n\t\t}\n\t\tSystem.out.println(result);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "935067b91903558435347033c97ae5a1", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc= new Scanner(System.in);\n\t\tlong x= sc.nextLong();\n\t\tlong n=0L;\n\t\tlong result;\n\t\tif(x<3)\n\t\t\tresult=1;\n\t\telse if(x==3)\n\t\t\tresult=2;\n\t\telse{\n\t\t\t\n\t\tfor(long i=1L; ix){\n\t\t\t\ti--;\n\t\t\t\tn= (i*(i-1))/2+1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tresult=x-n+1;\n\t\t}\n\t\tSystem.out.println(result);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bc24dde338a5528906722cd3552e340f", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Infinite{\n\n\tpublic static long infinite(long n, int i, long[] list){\n\t\tfor(int k=1;kn){\n\t\t\t\t//System.out.println(\"\"+n+list[--k]);\n\t\t\t\treturn n-list[--k];\n\t\t\t}\n\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n= in.nextLong();\n\t\tlong[] list = new long[(int)Math.pow(10,7)*8+1];\n\t\tint i=1;\n\t\tlong j=0;\n\t\twhile (j<=n){\n\t\t\tj=(long)i*(i+1)/2;\n\t\t\tlist[i++]=j;\n\t\t}\n\n\n\n\t\t//System.out.println(Arrays.toString(list));\n\n\t\tSystem.out.println(infinite(n,i,list));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "763f1a6f788219de885ae87489442700", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "///package main;\n\nimport java.io.*;\nimport java.util.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\npublic final class Main {\n BufferedReader br;\n StringTokenizer stk;\n\n public static void main(String[] args) throws Exception {\n new Main().run();\n }\n \n {\n stk = null;\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n void run() throws Exception {\n long n = nl();\n //long[] pos = new long[100];\n long[] pos = new long[10000000 * 5];\n pos[0] = 1;\n \n for(int i=1; i a=new ArrayList();\n\t\tint[] a=new int[100000000];\n\t\tif (n%2==0){\n\t\t\t\n\t\tfor (int i=0; i set= new HashSet();\n\t\t\n\t\tfor(int i=1;i<=n/i;i++) {\n\t\t\tif(n%i==0) {\n\t\t\t\tset.add(i);\n\t\t\t\tset.add(n/i);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tint max=Integer.MIN_VALUE;\n\t\t\n\t\tfor(Integer i : set) {\n\t\t\tString s=i.toBinaryString(i);\n\t\t\t//System.out.println(s);\n\t\t\tboolean flag=true;\n\t\t\t\n\t\t\tfor(int j=0;j<(s.length()/2)+1;j++) {\n\t\t\t\t//System.out.println(j+\" \"+s.charAt(j));\n\t\t\t\tif(s.charAt(j)!='1') {\n\t\t\t\t\tflag=false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor(int j= (s.length()/2)+1; jmax) {\n\t\t\t\t\tmax=i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(max);\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e8bdc352f94e6c1796cb59146e5dfad3", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n \n public class Sample implements Runnable\n { \n static int max=1000005;\n static int[] a=new int[max]; \n public static void solve()\n { \n int number =0;\n int k=0;\n while(number\n {\n long a;\n int b;\n Pair(){}\n Pair(long a,int b)\n {\n this.a=a;\n this.b=b;\n }\n \n public int compareTo(Pair x)\n {\n return Long.compare(x.a,this.a);\n }\n }\n \n \n \n ////////////////////////////////////////////////////// Merge Sort ////////////////////////////////////////////////////////////////////////\n \n static class Merge \n {\n\n public static void sort(long inputArr[]) \n {\n int length = inputArr.length;\n doMergeSort(inputArr,0, length - 1);\n }\n\n private static void doMergeSort(long[] arr,int lowerIndex, int higherIndex) \n { \n if (lowerIndex < higherIndex) {\n int middle = lowerIndex + (higherIndex - lowerIndex) / 2;\n doMergeSort(arr,lowerIndex, middle);\n doMergeSort(arr,middle + 1, higherIndex);\n mergeParts(arr,lowerIndex, middle, higherIndex);\n }\n }\n\n private static void mergeParts(long[]array,int lowerIndex, int middle, int higherIndex) \n {\n long[] temp=new long[higherIndex-lowerIndex+1];\n for (int i = lowerIndex; i <= higherIndex; i++) \n {\n temp[i-lowerIndex] = array[i];\n }\n int i = lowerIndex;\n int j = middle + 1;\n int k = lowerIndex;\n while (i <= middle && j <= higherIndex) \n {\n if (temp[i-lowerIndex] < temp[j-lowerIndex]) \n {\n array[k] = temp[i-lowerIndex];\n i++;\n } else {\n array[k] = temp[j-lowerIndex];\n j++;\n }\n k++;\n }\n while (i <= middle) \n {\n array[k] = temp[i-lowerIndex];\n k++;\n i++;\n }\n while(j<=higherIndex)\n {\n array[k]=temp[j-lowerIndex];\n k++;\n j++;\n }\n }\n\n }\n \n \n /////////////////////////////////////////////////////////// Methods ////////////////////////////////////////////////////////////////////////\n\n\n static boolean isPal(String s)\n {\n for(int i=0, j=s.length()-1;i<=j;i++,j--)\n {\n if(s.charAt(i)!=s.charAt(j)) return false;\n }\n return true;\n }\n static String rev(String s)\n {\n StringBuilder sb=new StringBuilder(s);\n sb.reverse();\n return sb.toString();\n }\n static int gcd(int a,int b){return (a==0)?b:gcd(b%a,a);}\n static long gcdExtended(long a,long b,long[] x)\n {\n\n if(a==0){\n x[0]=0;\n x[1]=1;\n return b;\n }\n long[] y=new long[2];\n long gcd=gcdExtended(b%a, a, y);\n\n x[0]=y[1]-(b/a)*y[0];\n x[1]=y[0];\n\n return gcd;\n }\n\n boolean findSum(int set[], int n, long sum)\n {\n if (sum == 0)\n return true;\n if (n == 0 && sum != 0)\n return false;\n if (set[n-1] > sum)\n return findSum(set, n-1, sum);\n return findSum(set, n-1, sum) ||findSum(set, n-1, sum-set[n-1]);\n }\n \n public static long modPow(long base, long exp, long mod)\n {\n base = base % mod;\n long result = 1;\n while (exp > 0)\n {\n if (exp % 2 == 1) \n {\n result = (result * base) % mod;\n }\n base = (base * base) % mod;\n exp = exp >> 1;\n }\n return result;\n }\n \n static long[] fac;\n static long[] inv;\n static long mod=(long)1e9+7;\n public static void cal() \n {\n fac = new long[1000005];\n inv = new long[1000005];\n fac[0] = 1;\n inv[0] = 1;\n for (int i = 1; i <= 1000000; i++)\n {\n fac[i] = (fac[i - 1] * i) % mod;\n inv[i] = (inv[i - 1] * modPow(i, mod - 2, mod)) % mod;\n }\n }\n \n public static long ncr(int n, int r) \n {\n return (((fac[n] * inv[r]) % mod) * inv[n - r]) % mod;\n }\n\n \n////////////////////////////////////////// Input Reader ////////////////////////////////////////////////////////////////////////////////////////////////////\n \n static InputReader sc = new InputReader(System.in);\n static PrintWriter out= new PrintWriter(System.out); \n \n static class InputReader {\n\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int snext()\n {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt()\n {\n int c = snext();\n while (isSpaceChar(c)) \n {\n c = snext();\n }\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = snext();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() \n {\n int c = snext();\n while (isSpaceChar(c)) \n {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') \n {\n sgn = -1;\n c = snext();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n)\n {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) \n {\n a[i] = nextInt();\n }\n return a;\n }\n\n public long[] nextLongArray(int n)\n {\n long a[] = new long[n];\n for (int i = 0; i < n; i++) \n {\n a[i] = nextLong();\n }\n return a;\n }\n\n \n public String nextLine()\n {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) \n {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) \n {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n public interface SpaceCharFilter \n {\n public boolean isSpaceChar(int ch);\n }\n\n }\n\n static int i()\n {\n return sc.nextInt();\n }\n static long l(){\n return sc.nextLong();\n }\n static int[] iarr(int n)\n {\n return sc.nextIntArray(n);\n }\n static long[] larr(int n)\n {\n return sc.nextLongArray(n);\n }\n static String s(){\n return sc.nextLine();\n }\n \n \n } ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bdbbc49806ade7bbc924feee7a7386c7", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n static boolean test =false;\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() throws FileNotFoundException {\n\n InputStream inputStream = test ? new FileInputStream(\"/Users/aj/code/HackerRank/input.txt\") : System.in;\n br = new BufferedReader(new\n InputStreamReader(inputStream));//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 int gcd(int a,int b){\n if(a==0 || b==0) return a+b;\n else return gcd(b,a%b);\n }\n static long mod=1000000000+7;\n public static long compute(long base, long exp){\n long res=0;\n if(exp>1){\n long res1=compute(base,exp/2);\n res=res1*res1;\n res%=mod;\n if(exp%2==1) {\n res *= base;\n res %= mod;\n }\n }\n else{\n res=base;\n }\n return res;\n }\n public static void main(String[] args) throws FileNotFoundException {\n FastReader in = new FastReader();\n int n;\n n=in.nextInt();\n int r=0;\n for(int k=1;k<20;k++) {\n int nm=((1<= 1; i++){\n if(n%i == 0 && beautiful(i)){\n System.out.println(i);\n System.exit(0);\n }\n }\n }\n\n\n static boolean beautiful(int n){\n StringBuilder s = new StringBuilder();\n while (n > 0){\n int rem = n%2;\n n = n / 2;\n s.append(String.valueOf(rem));\n }\n String str = s.toString();\n int len = str.length();\n int count = 0;\n for(int i = 0; i < len; i++){\n if(str.charAt(i) == '1'){\n count++;\n }\n }\n return (count*2-1 == len);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fadf498f5e63bf5338439bee39415cb9", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class A_577 {\n\n\tpublic static void main(String [] args) {\n\t\tScanner user = new Scanner(System.in);\n\t\tint n = user.nextInt();\n\t\tint x = user.nextInt();\n\t\tint con = 0;\n\t\t\n\t\tif (n == 1 && x !=1){\n\t\t\tcon = 0;\n\t\t}else if (x == 1){\n\t\t\tcon = 1;\n\t\t}else{\n\t\t\tint [][] t = new int [n][n];\n\t\t\tfor (int i = 0; i < t.length; i++) {\n\t\t\t\tfor (int j = 0; j < t[0].length; j++) {\n\t\t\t\t\tt [i][j] = (1 + i) * (1 + j) ;\n\t\t\n\t\t\t\t\tif(x == t[i][j]){\n\t\t\t\t\t\tcon++;\n\t\t\t\t\t}\n\t\t\t\t}\t\t\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tSystem.out.println(con);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a54f9579b0dc94dbb23d0f85d9824df1", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong n=sc.nextLong();\n\t\tlong x=sc.nextLong();\n\t\tint [][]cell=new int [(int) n][(int) n];\n\t\tint c=0;\n\t\tfor(int i=0;i= arrivalTime - EPS) break;\n\t\t\tcoin++;\n\t\t\tT1 = T1 + f + 2*(nextMeet - T1);\n\t\t}\n\t\tSystem.out.println(coin);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1e2d3d1f4584765dbb2f9ffa74f9f0ec", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\n\npublic class C105P2 {\n\n private static BufferedReader in;\n private static PrintWriter out;\n private static StringTokenizer input;\n \n public static void main(String[] args) throws IOException {\n //-------------------------------------------------------------------------\n //Initializing...\n new C105P2();\n //-------------------------------------------------------------------------\n //put your code here... :)\n int vp = nextInt();\n int vd = nextInt();\n int t = nextInt();\n int f = nextInt();\n int c = nextInt();\n double x = newplace(t, vp);\n int count =0;\n while(c-x>0.000001){\n double d=meetingpoint(x, vd, vp);\n x+=d;\n if(c-x>0.000001)count++;\n else break;\n double tt = toyalTimeTillChase(x, vd, f);\n x+=newplace(tt, vp);\n }\n \n writeln(\"\"+count);\n //-------------------------------------------------------------------------\n //closing up\n end();\n //--------------------------------------------------------------------------\n\n }\n \n public static double toyalTimeTillChase(double x,int vd,int f){\n return x/vd +f;\n }\n public static double newplace(double t , double vp){\n return t*vp;\n }\n public static double meetingpoint(double x,int vd,int vp){\n return x*vp/(vd-vp);\n }\n public C105P2() throws IOException {\n //Input Output for Console to be used for trying the test samples of the problem \n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //-------------------------------------------------------------------------\n //Initalize Stringtokenizer input\n input = new StringTokenizer(in.readLine());\n }\n\n private static int nextInt() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Integer.parseInt(input.nextToken());\n }\n private static long nextLong() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Long.parseLong(input.nextToken());\n }\n private static double nextDouble() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Double.parseDouble(input.nextToken());\n }\n private static String nextString() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return input.nextToken();\n }\n private static void write(String output){\n out.write(output);\n out.flush();\n }\n private static void writeln(String output){\n out.write(output+\"\\n\");\n out.flush();\n }\n private static void end() throws IOException{\n in.close();\n out.close();\n System.exit(0);\n }\n\n \n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ba4b71926228ce04bb1c1afd8ae8904c", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "\n\nimport java.util.Scanner;\n\npublic class two {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int vp = sc.nextInt();\n int vd = sc.nextInt();\n int t = sc.nextInt();\n int f = sc.nextInt();\n int c = sc.nextInt();\n double time = c * 1.0 / vp - t;\n int t1 = 0;\n int count = 0;\n double dist = vp * t;\n time = (c - dist) / vp;\n double remDist = c - dist;\n while (time > 0) {\n double tdash = dist * 1.0 / (vd - vp);\n time -= tdash;\n if (time > 0)\n count++;\n dist += vp * tdash;\n time -= dist / vd + f;\n \n dist += vp * (dist / vd + f);\n\n }\n /*\n * while (true) { double t2 = (vp * (t + t1) * 1.0) / (vd - vp); t1 +=\n * t2; if (t1 <= time) count++; else break; t1 += (vd * t2) + f; }\n */\n System.out.println(count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd9389af291cee932c61f5859aa044f5", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Solution {\n\n public static void main(String[] args) throws Exception {\n Scanner reader = new Scanner(System.in);\n\n int vPrinc = reader.nextInt();\n int vDrag = reader.nextInt();\n int dt = reader.nextInt();\n int waste = reader.nextInt();\n int dist = reader.nextInt();\n\n if (vPrinc >= vDrag) {\n System.out.print(0);\n return;\n }\n\n double s = vPrinc * dt;\n double dv = vDrag - vPrinc;\n\n int taken = 0;\n\n while (s < dist) {\n double t = s / dv;\n s += vPrinc * t;\n\n if (s == dist) break;\n\n t = s / vDrag + waste;\n s += vPrinc * t;\n\n taken++;\n }\n\n System.out.println(taken);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ed2deb42983e35c13b942382bdedb5e5", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "package Raound70;\n\nimport java.util.Scanner;\n\npublic class C {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int k = sc.nextInt();\n if (n % 2==1) {\n for (int i = 2; i*i <= m; i++) {\n if (m % i==0) {\n if (m / i >= k) {\n System.out.println(\"Timur\");\n }\n else {\n System.out.println(\"Marsel\");\n }\n return;\n }\n }\n if (n != 1 && k==1) {\n System.out.println(\"Timur\");\n }\n else {\n System.out.println(\"Marsel\");\n }\n }\n else {\n System.out.println(\"Marsel\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b6c792cf33b6f0cd498f1d3d25128f00", "src_uid": "4a3767011ddac874efa021fff7c94432", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class beaver {\n\tstatic ArrayList[] adj;\n\tstatic int n, m, k;\n\tstatic int[] nim;\n\n\tpublic static int dfs(int idx) {\n\t\tif (nim[idx] != -1) return nim[idx];\n\t\telse if (adj[idx].size() == 0) return nim[idx] = 0;\n\n\t\tHashSet children = new HashSet<>();\n\t\tfor (int child : adj[idx])\n\t\t\tchildren.add(dfs(child));\n\n\t\tnim[idx] = 0;\n\t\twhile (children.contains(nim[idx])) nim[idx]++;\n\n\t\treturn nim[idx];\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tn = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt();\n\n\t\tif ((n&1) == 0) {\n\t\t\tSystem.out.println(\"Marsel\");\n\t\t\tSystem.exit(0);\n\t\t}\n\n\t\tArrayList factors = new ArrayList<>();\n\n\t\tfor (int i=1; i*i<=m; i++) {\n\t\t\tif (m%i != 0) continue;\n\n\t\t\tif (i >= k) factors.add(i);\n\t\t\tif (i*i < m && m >= k*i) factors.add(m/i);\n\t\t}\n\n\t\tint n = factors.size();\n\t\tCollections.sort(factors);\n\t\tadj = new ArrayList[n];\n\n\t\tfor (int i=0; i();\n\n\t\tfor (int i=0; i '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\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\tprivate boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic void setFinished(boolean finished) {\n\t\tthis.finished = finished;\n\t}\n\n\tpublic abstract void close();\n}\n\nclass StreamInputReader extends InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar, numChars;\n\n\tpublic StreamInputReader(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\t@Override\n\tpublic void close() {\n\t\ttry {\n\t\t\tstream.close();\n\t\t} catch (IOException ignored) {\n\t\t}\n\t}\n}\n\nclass Exit {\n\tprivate Exit() {\n\t}\n\n\tpublic static void exit(InputReader in, PrintWriter out) {\n\t\tin.setFinished(true);\n\t\tin.close();\n\t\tout.close();\n\t}\n}\n\ninterface Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out);\n}\n\ninterface Filter {\n\tpublic boolean accept(T value);\n}\n\nclass CollectionUtils {\n\n\tpublic static List filter(Iterable sequence, Filter filter) {\n\t\tList result = new ArrayList();\n\t\tfor (T element : sequence) {\n\t\t\tif (filter.accept(element))\n\t\t\t\tresult.add(element);\n\t\t}\n\t\treturn result;\n\t}\n\n\t}\n\nclass Pair {\n\n\tpublic final U first;\n\tpublic final V second;\n\n\tpublic static Pair makePair(U first, V second) {\n\t\treturn new Pair(first, second);\n\t}\n\n\tprivate Pair(U first, V second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o) return true;\n\t\tif (o == null || getClass() != o.getClass()) return false;\n\n\t\tPair pair = (Pair) o;\n\n\t\treturn !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);\n\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result = first != null ? first.hashCode() : 0;\n\t\tresult = 31 * result + (second != null ? second.hashCode() : 0);\n\t\treturn result;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"(\" + first + \",\" + second + \")\";\n\t}\n}\n\nabstract class ReadOnlyIterator implements Iterator {\n\tpublic final void remove() {\n\t\tthrow new UnsupportedOperationException();\n\t}\n}\n\nclass IOUtils {\n\n\tpublic static void printCollection(Iterable collection, PrintWriter out, String delimiter) {\n\t\tboolean isFirst = true;\n\t\tfor (T element : collection) {\n\t\t\tif (isFirst)\n\t\t\t\tisFirst = false;\n\t\t\telse\n\t\t\t\tout.print(delimiter);\n\t\t\tout.print(element);\n\t\t}\n\t\tout.println();\n\t}\n\n\t}\n\nabstract class AbstractSequence implements Sequence {\n\n\tpublic Iterator iterator() {\n\t\treturn new ReadOnlyIterator() {\n\t\t\tprivate int index = 0;\n\n\t\t\tpublic boolean hasNext() {\n\t\t\t\treturn index != size();\n\t\t\t}\n\n\t\t\tpublic T next() {\n\t\t\t\tif (!hasNext())\n\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\treturn get(index++);\n\t\t\t}\n\t\t};\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\tStringWriter writer = new StringWriter();\n\t\tIOUtils.printCollection(this, new PrintWriter(writer), \",\");\n\t\treturn \"[\" + writer.toString().substring(0, writer.toString().length() - 1) + \"]\";\n\t}\n\n\t}\n\nabstract class AbstractWritableSequence extends AbstractSequence implements WritableSequence {\n\n\t}\n\ninterface Sequence extends Iterable {\n\tpublic int size();\n\tpublic T get(int index);\n}\n\ninterface WritableSequence extends Sequence {\n\tpublic void set(int index, T value);\n\t}\n\nclass SequenceUtils {\n\n\t@SuppressWarnings({\"unchecked\"})\n\tpublic static> WritableSequence sort(WritableSequence sequence) {\n\t\treturn sort(sequence, null);\n\t}\n\n\t@SuppressWarnings({\"unchecked\", \"RedundantCast\"})\n\tpublic static WritableSequence sort(WritableSequence sequence, Comparator comparator) {\n\t\tmakeHeap(sequence, comparator);\n\t\tfor (int i = sequence.size() - 1; i > 0; i--) {\n\t\t\tT temp = sequence.get(0);\n\t\t\tsequence.set(0, sequence.get(i));\n\t\t\tsequence.set(i, temp);\n\t\t\tsiftDown(sequence, 0, i, comparator);\n\t\t}\n\t\treturn sequence;\n\t}\n\n\tprivate static WritableSequence makeHeap(WritableSequence sequence, Comparator comparator) {\n\t\tint length = sequence.size();\n\t\tfor (int i = length / 2 - 1; i >= 0; i--)\n\t\t\tsiftDown(sequence, i, length, comparator);\n\t\treturn sequence;\n\t}\n\n\tprivate static void siftDown(WritableSequence sequence, int start, int end, Comparator comparator) {\n\t\tint root = start;\n\t\twhile (2 * root + 1 < end) {\n\t\t\tint childIndex = 2 * root + 1;\n\t\t\tif (childIndex + 1 < end && compare(sequence.get(childIndex), sequence.get(childIndex + 1), comparator) < 0)\n\t\t\t\tchildIndex++;\n\t\t\tif (compare(sequence.get(childIndex), sequence.get(root), comparator) <= 0)\n\t\t\t\treturn;\n\t\t\tT temp = sequence.get(root);\n\t\t\tsequence.set(root, sequence.get(childIndex));\n\t\t\tsequence.set(childIndex, temp);\n\t\t\troot = childIndex;\n\t\t}\n\t}\n\n\tprivate static int compare(T first, T second, Comparator comparator) {\n\t\tif (comparator != null)\n\t\t\treturn comparator.compare(first, second);\n\t\t//noinspection unchecked\n\t\treturn ((Comparable)first).compareTo(second);\n\t}\n\n\t}\n\nclass ListWrapper extends AbstractWritableSequence {\n\tprivate final List list;\n\n\tpublic static WritableSequence wrap(List list) {\n\t\treturn new ListWrapper(list);\n\t}\n\n\tprivate ListWrapper(List list) {\n\t\tthis.list = list;\n\t}\n\n\tpublic void set(int index, T value) {\n\t\tlist.set(index, value);\n\t}\n\n\tpublic int size() {\n\t\treturn list.size();\n\t}\n\n\tpublic T get(int index) {\n\t\treturn list.get(index);\n\t}\n}\n\nclass IntegerUtils {\n\n\tpublic static List> factorize(long number) {\n\t\tList> result = new ArrayList>();\n\t\tfor (long i = 2; i * i <= number; i++) {\n\t\t\tif (number % i == 0) {\n\t\t\t\tint power = 0;\n\t\t\t\tdo {\n\t\t\t\t\tpower++;\n\t\t\t\t\tnumber /= i;\n\t\t\t\t} while (number % i == 0);\n\t\t\t\tresult.add(Pair.makePair(i, power));\n\t\t\t}\n\t\t}\n\t\tif (number != 1)\n\t\t\tresult.add(Pair.makePair(number, 1));\n\t\treturn result;\n\t}\n\n\tpublic static List getDivisors(long number) {\n\t\tList> primeDivisors = factorize(number);\n\t\treturn getDivisorsImpl(primeDivisors, 0, 1, new ArrayList());\n\t}\n\n\tprivate static List getDivisorsImpl(List> primeDivisors, int index, long current,\n\t\tList result)\n\t{\n\t\tif (index == primeDivisors.size()) {\n\t\t\tresult.add(current);\n\t\t\treturn result;\n\t\t}\n\t\tlong p = primeDivisors.get(index).first;\n\t\tint power = primeDivisors.get(index).second;\n\t\tfor (int i = 0; i <= power; i++) {\n\t\t\tgetDivisorsImpl(primeDivisors, index + 1, current, result);\n\t\t\tcurrent *= p;\n\t\t}\n\t\treturn result;\n\t}\n\n\t}\n\nclass TaskC implements Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint count = in.readInt();\n\t\tint length = in.readInt();\n\t\tfinal int minLength = in.readInt();\n\t\tif (count % 2 == 0) {\n\t\t\tout.println(\"Marsel\");\n\t\t\treturn;\n\t\t}\n\t\tWritableSequence divisors = ListWrapper.wrap(CollectionUtils.filter(IntegerUtils.getDivisors(length), new Filter() {\n\t\t\tpublic boolean accept(Long value) {\n\t\t\t\treturn value >= minLength;\n\t\t\t}\n\t\t}));\n\t\tSequenceUtils.sort(divisors);\n\t\tMap nimber = new HashMap();\n\t\tfor (long divisor : divisors) {\n\t\t\tSet nimbers = new HashSet();\n\t\t\tfor (long otherDivisor : divisors) {\n\t\t\t\tif (divisor == otherDivisor)\n\t\t\t\t\tbreak;\n\t\t\t\tif (divisor % otherDivisor == 0)\n\t\t\t\t\tnimbers.add(divisor / otherDivisor % 2 == 0 ? 0 : nimber.get(otherDivisor));\n\t\t\t}\n\t\t\tfor (int i = 0; ; i++) {\n\t\t\t\tif (!nimbers.contains(i)) {\n\t\t\t\t\tnimber.put(divisor, i);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (nimber.get((long)length) == 0)\n\t\t\tout.println(\"Marsel\");\n\t\telse\n\t\t\tout.println(\"Timur\");\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "86dcee4841390a88840d39a328dff63b", "src_uid": "4a3767011ddac874efa021fff7c94432", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/18/11\n * Time: 9:28 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskC {\n\n void run(){\n int n = nextInt(), m = nextInt(), k = nextInt();\n\n if(canWin(n, m, k)){\n System.out.println(\"Timur\");\n }else{\n System.out.println(\"Marsel\");\n }\n }\n\n boolean canWin(long n, int m, int k){\n if(m < 2 * k) return false;\n\n //HashSet factors = new HashSet();\n int finalLength = Integer.MAX_VALUE;\n for(int i = 1; i * i <= m; i++){\n if(m % i == 0){\n if(m / i >= k){\n finalLength = Math.min(finalLength, m / i);\n }\n if(i >= k){\n finalLength = Math.min(finalLength, i);\n }\n }\n }\n if(finalLength == Integer.MAX_VALUE) return false;\n\n if(finalLength < 2 * k){\n if(n % 2 == 0) return false;\n else return true;\n }else{\n if(n % 2 == 0) return canWin(n * (m / finalLength), finalLength, k);\n else return !canWin(n * (m / finalLength), finalLength, k);\n }\n }\n\n int nextInt(){\n try{\n int c = System.in.read();\n if(c == -1) return c;\n while(c != '-' && (c < '0' || '9' < 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2ad789f4636220f912ae180d1e49efe", "src_uid": "4a3767011ddac874efa021fff7c94432", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class hi\n{\npublic static void main(String ars[])throws IOException\n{\nScanner s=new Scanner(System.in);\n//BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\nlong a=s.nextLong();\nint count=0;\nwhile(a>0)\n{\nif(a%10==4||a%10==7)\ncount++;\n}\nif(count==4||count==7)\nSystem.out.print(\"YES\");\nelse\nSystem.out.print(\"NO\");\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e3cea3bd42c98e146ee7d054a651bb2", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class TryJava {\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\tlong n;\n\t\tScanner in= new Scanner (System.in);\n\t\tn=in.nextLong();\n\t\tint f=0;\n\t\tif(n==0)\n\t\t\tSystem.out.print(\"NO\");\n\t\telse\n\t\t{\n\t\twhile(n>0)\n\t\t{\n\t\t\tif(n%10==4||n%10==7)\n\t\t\t{\n\t\t\t\tf++;\n\t\t\t\tn/=10;\n\t\t\t}\n\t\t}\n\t\tif(f%4==0||f%7==0)\n\t\t\tSystem.out.print(\"YES\");\n\t\telse\n\t\t\tSystem.out.print(\"NO\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b3516a1f0b42e002d57dcb71eccb5ca8", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\n\npublic class LuckyNumber {\n\t\n\tpublic static void main(String args[]) {\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n;\n int e, a = 0, b = 0;\n\t\tn = in.nextLong();\n\t\twhile(n>0)\n\t\t{\n\t\t\te = (int)(n % 10);\n\t\t\tif((e == 4)||(e == 7))\n\t\t\t\ta++;\n\t\t\telse\n\t\t\t\tb++;\n\t\t\t\t}\n\t\tif (b == 0)\n\t\t\tSystem.out.println(\"NO\");\n\t\telse\n\t\t\tSystem.out.println(\"YES\");\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d00cef6b7a07c5bc7b14f74acc3339dd", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class hi\n{\npublic static void main(String ars[])throws IOException\n{\n\nBufferedReader in=new BufferedReader(new InputStreamReader(System.in));\nlong a=Integer.parseInt(in.readLine());\nint count=0;\nwhile(a>0)\n{\nif(a%10==4||a%10==7)\na/=10;\ncount++;\n}\nif(count==4||count==7)\nSystem.out.print(\"YES\");\nelse\nSystem.out.print(\"NO\");\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "019f857708e9a15face45b57b7397212", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java .util.Scanner ; \n\npublic class Coding {\n\n public static int find(int[]x){\n for (int i = 0; i < x.length-2; i++) {\n if(x[i]==x[i+1]&&x[i]==x[i+2]){\n return x[i]; \n }\n }\n return -1 ; \n }\n public static void main(String[] args) {\n \n Scanner in = new Scanner (System.in); \n int sp=0 ; \n int S ; \n int sp2= 0 ; \n int ac =0; \n int count = 0 ; \n int []x = new int[5]; \n for (int i = 0; i < 5; i++) {\n \n x[i]=in.nextInt() ; \n }\n Arrays.sort(x);\n if(find(x)!=-1){\n sp2 = find(x) ; \n }\n for (int i = 0; i < 5; i++) {\n \n \n if(i!=4){\n if(x[i]==x[i+1]&&x[i]>=sp){\n sp=x[i]; \n }\n }\n }\n \n if(find(x)!=-1&&sp>sp2){\n S= sp ; \n }else S = sp2 ; \n \n for (int i = 0; i < 5; i++) {\n if(x[i]!=S){\n count+=x[i]; \n }else{\n \n if(ac>=3){\n count+=x[i]; \n }\n ac++ ; \n }\n }\n System.out.println(count);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a4265287a92d55e96970b6c7046726b4", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Solution\n{\n public static void main(String[] args) throws Exception\n {\n Scanner scanner = new Scanner(System.in);\n int a[] = new int[5];\n int k = 0;\n int c = 0;\n a [0] = scanner.nextInt();\n int max = a[0];\n int sum = a[0];\n int min = a[0];\n for (int i = 1; i < 5; i++)\n {\n a[i] = scanner.nextInt();\n sum = a[i] + sum;\n if (max > a[i])\n {\n max = a[i];\n }\n }\n for (int i = 0; i < 5; i++)\n {\n for (int j = 0; j < 5; j++)\n {\n if (a[i] == a[j])\n {\n if (max < a[i] && i != j)\n {\n max = a[i];\n }\n else min = a[i];\n }\n }\n }\n for (int i = 0; i < 5; i++)\n {\n if (max == a[i])\n {\n k++;\n }\n if (min == a[i])\n {\n c++;\n }\n }\n\n if (k >= 3)\n k = 3;\n if (k == 1)\n k = 0;\n if (c == 1)\n c = 0;\n if (k*max > c*min)\n System.out.print(sum - (max * k));\n else if (k*max < c*min)\n System.out.print(sum - (min * c));\n else System.out.println(sum);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b7e99b00541e616c3daed12994d1c1c", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Main\n{\n\tpublic static void main(String[] args)\n\tthrows IOException\n\t{\n\t\tReader r = new Reader();\n\t\tPrintWriter writer = new PrintWriter(System.out);\n\n\t\tr.readLine();\n\t\tArrayList arr = new ArrayList();\n\n\t\tint co;\n\t\tint sum = 0;\n\t\tfor (int i=0;i < 5;++i)\n\t\t{\n\t\t\tarr.add(r.readInt(0));\n\t\t\tsum += arr.get(i);\n\t\t}\n\t\t\n\t\tint min = sum;\n\t\tfor(int i=0;i<5;++i)\n\t\t{\n\t\t\tco = 1;\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\tcontinue;\n\t\t\t\tif(arr.get(i).equals(arr.get(j)))\n\t\t\t\t\t++co;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tif(co==1)\n\t\t\t{\n\t\t\t\tif(sum-arr.get(i)\n{\n\tint f,s;\n\n\tpublic Pair(int f, int s)\n\t{\n\t\tthis.f = f;\n\t\tthis.s = s;\n\t}\n\n\t@Override\n\tpublic String toString()\n\t{\n\t\t// TODO: Implement this method\n\t\treturn f + \" \" + s;\n\t}\n\n\t@Override\n\tpublic int compareTo(Pair o)\n\t{\n\t\t// TODO: Implement this method\n\t\tif (f == o.f)\n\t\t\treturn s - o.s;\n\t\treturn f - o.f;\n\t}\n}\n\nclass Reader\n{\n private BufferedReader reader;\n private String line[];\n\n public Reader()\n {\n reader = new BufferedReader(\n new InputStreamReader(System.in));\n }\n\n public void readLine()\n throws IOException\n {\n line = reader.readLine().split(\" \");\n }\n\n public int readInt(int pos)\n throws IOException\n {\n return Integer.parseInt(line[pos]);\n }\n\n public double readDouble(int pos)\n throws IOException\n {\n return Double.parseDouble(line[pos]);\n }\n\n public long readLong(int pos)\n throws IOException\n {\n return Long.parseLong(line[pos]);\n }\n\n public String readString(int pos)\n throws IOException\n {\n return line[pos];\n }\n\n public void close()\n throws IOException\n {\n reader.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "15f022d364094b7088b089164286d34f", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class BearAndFivecarda\n{\npublic static void main(String[] args)\n{\n Scanner sc = new Scanner(System.in);\n int[] a = new int[5];\n for(int i = 0;i < 5;i++)\n {\n a[i] = sc.nextInt();\n }\n int c = 0;\n int[] sum = new int[5];\n for(int i = 0;i < 5;i++)\n {\n for(int j = 0;j < 5;j++)\n {\n if(a[i]==a[j])\n {\n c++;\n }\n }\n if(c <= 3 && c >= 2)\n {\n int p = i;\n for(int l = 0;l < 5;i++)\n {\n if(a[p]==a[l])\n {\n a[l] = 0;\n }\n }\n int sol = 0;\n for(int l = 0;l < 5;l++)\n {\n sol += a[l];\n }\n sum[i] = sol;\n c = 0;\n }\n else\n {\n sum[i] = a[0]+a[1]+a[2]+a[3]+a[4];\n c = 0;\n }\n }\n int min=0;\n for(int i = 0;i < 4;i++)\n {\n min = Math.min(a[i],a[i+1]);\n }\n System.out.println(min);\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "03ab069f94d77edb66c3345ee9a2f5d5", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tint[] n = new int[4];\n\t\tn[0] = Integer.parseInt(in.readLine());\n\t\tn[1] = Integer.parseInt(in.readLine());\n\t\tn[2] = Integer.parseInt(in.readLine());\n\t\tn[3] = Integer.parseInt(in.readLine());\n\t\tint d = Integer.parseInt(in.readLine());\n\t\tArrays.sort(n);\n\t\tfor(int i=3; i>=1; --i){\n\t\t\tfor(int j=0; j10){\n\t\t\t\tmax_len = i-1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint count = 0;\n\t\tfor(int i=1; i<=d; ++i){\n\t\t\tfor(int j=0; j<=max_len; ++j){\n\t\t\t\tif(i%n[j]==0){\n\t\t\t\t\t++count;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c643b5f8dabd2c9396cc9e8a18b5ebc", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tint[] n = new int[4];\n\t\tn[0] = Integer.parseInt(in.readLine());\n\t\tn[1] = Integer.parseInt(in.readLine());\n\t\tn[2] = Integer.parseInt(in.readLine());\n\t\tn[3] = Integer.parseInt(in.readLine());\n\t\tint d = Integer.parseInt(in.readLine());\n\t\tfor(int i=3; i>=1; --i){\n\t\t\tfor(int j=0; j10){\n\t\t\t\tmax_len = i-1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint count = 0;\n\t\tfor(int i=1; i<=d; ++i){\n\t\t\tfor(int j=0; j<=max_len; ++j){\n\t\t\t\tif(i%n[j]==0){\n\t\t\t\t\t++count;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1f3b5dd7d069fb01003ad2b303f784b2", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class InsomniaCure {\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 int m=in.nextInt();\n int n=in.nextInt();\n int d=in.nextInt();\n int sum=0;\n boolean a[] = new boolean[d+1];\n for(int i=k;i<=d;i+=k) {if(a[i]==false)sum++; a[i]=true;}\n for(int i=l;i<=d;i+=l) {if(a[i]==false)sum++; a[i]=true;}\n for(int i=m;i<=d;i+=m) {if(a[i]==false)sum++; a[i]=true;}\n for(int i=n;i<=n;i+=l) {if(a[i]==false)sum++; a[i]=true;}\n System.out.println(sum);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f6ecc202b75b7f6b7ba9a27ca0fa767e", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class insomnia_cure\n{\n public static void main()\n {\n Scanner sc=new Scanner(System.in);\n int k=sc.nextInt();\n int l=sc.nextInt();\n int m=sc.nextInt();\n int n=sc.nextInt();\n int d=sc.nextInt();\n int c=0;\n if((k>0)&&(l>0)&&(m>0)&&(n>0))\n {\n for(int i=1;i<=d;i++)\n {\n if((i%k==0)||(i%l==0)||(i%m==0)||(i%n==0))\n c++;\n }\n \n System.out.println(c);\n System.exit(0);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd9e7a1e8885ce6459a4bf8291b493d1", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0} {"lang": "Java 8", "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)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t int v = sc.nextInt();\n\t int temp = 1;\n\t int sum = 0;\n\t int lit = 0;\n\t while(temp != n - v + 1){\n\t if(temp == 1)sum = v;\n\t else sum += temp;\n\t temp++;\n\t }\n\t out.println(sum);\n\t out.flush();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a793c8a186c7db9630254e915c146f4c", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Gabriel Carrillo\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 ASashaAndHisTrip solver = new ASashaAndHisTrip();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ASashaAndHisTrip {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt(), v = in.nextInt();\n if (v - 1 >= n) {\n out.println(n - 1);\n }\n long ans = v + sum(2, n - v);\n out.println(ans);\n }\n\n long sum(long k, long n) {\n long ans = 0;\n for (long i = k; k <= n; i++)\n ans += i;\n return ans;\n }\n\n }\n\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n\n public InputReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public InputReader(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\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 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 public void println(int i) {\n writer.println(i);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "20b2eb723d19dcb559b9a85d1b3898ac", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\n\npublic class HelloWorld {\n \n public static void main(String args[]){\n Scanner sc = new Scanner (System.in);\n int n = sc.nextInt();\n int v = sc.nextInt();\n int kms = n-1;\n int i = 1;\n int bought = 0;\n int cost = 0;\n while (kms != bought){\n if(i == 1){\n cost+=v;\n bought+=v;\n }else{\n cost =cost+ (1*i);\n bought++;\n }\n i++;\n }\n System.out.println(cost);\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c02a8ee91ccee33b8ecb2e373d31aada", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Integer.getInteger;\nimport static java.lang.Integer.min;\nimport static java.lang.Integer.parseInt;\n\npublic class Main {\n static int scanInt() throws IOException {\n return parseInt(scanString());\n }\n\n\n static String scanString() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n static BufferedReader in;\n static StringTokenizer tok;\n\n public static void main(String[] args) throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n\n int n = scanInt();\n int v = scanInt();\n\n if(v == n - 1){\n System.out.println(v);\n return;\n }\n\n int i = 1;\n int sum = v;\n\n while (v != n - i){\n ++i;\n sum += i;\n }\n\n if (v == 1)\n System.out.println(n * (n - 1) / 2);\n else\n System.out.println(sum);\n\n }\n}\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6322712684c4589a0fedbd7a6626db47", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.Vector;\n\npublic class sd {\n\t\n\tpublic static long max(long num, long num2)\n\t{\n\t\treturn 1;\n\t}\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tScanner s = new Scanner(System.in);\n\t\t\t//String s1 = br.readLine();\n\t\t\tint w = s.nextInt();\n\t\t\tint m = s.nextInt();\n\t\t\tboolean flag = true;\n\t\t\tint[] arr = new int[1000];\n\t\t\tint cntr = 0;\n\t\t\twhile(m>0)\n\t\t\t{\n\t\t\t\tarr[cntr++] = m%w;\n\t\t\t\tm = m/w;\n\t\t\t}\n\t\t\tfor(int i=0;i m || u[l1])\n\t\t\t\tif(u[l1 - 1])\n\t\t\t\t\tcan = false;\n\t\t\t\telse {\n\t\t\t\t\tm -= (long) Math.pow(w, l1 - 1);\n\t\t\t\t\tu[l1 - 1] = true;\n\t\t\t\t\tif(m == 0)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tif(u[l1])\n\t\t\t\t\tcan = false;\n\t\t\t\telse {\n\t\t\t\t\tm = (long) Math.pow(w, l1) - m;\n\t\t\t\t\tu[l1] = true;\n\t\t\t\t\tif(m == 0)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t}\n\n\t\tSystem.out.println(can ? \"YES\": \"NO\");\n\n\t\tout.flush();\n\n\t}\n\n\n\tstatic class Scanner \n\n\n\n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b1b560c463d51152162ed42d869f9163", "src_uid": "a74adcf0314692f8ac95f54d165d9582", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskC {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int w = in.nextInt();\n int m = in.nextInt();\n int[] d = new int[20];\n int i = 19;\n while (m > 0) {\n d[i] += m % w;\n if (d[i] > 1) {\n d[i] -= w;\n if (d[i] != 0 && d[i] != -1) {\n out.println(\"NO\");\n return;\n }\n d[i - 1]++;\n }\n m /= w;\n i--;\n }\n out.println(d[i] == 0 || d[i] == 1 ? \"YES\" : \"NO\");\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c7a3a75644a24054cf7a7cb60f4d0f29", "src_uid": "a74adcf0314692f8ac95f54d165d9582", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class a{\n\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] ar=in.readLine().split(\" \");\n\t\tint w=Integer.parseInt(ar[0]);\n\t\tint m=Integer.parseInt(ar[1]);\n\t\tint[] base=new int[40];\n\t\tfor(int i=0;i<40 && m>0;++i){\n\t\t\tbase[i]=m%w;\n\t\t\tm/=w;\n\t\t}\n\t\tboolean flag=true;\n\t\tfor(int i=0;i<40;++i){\n\t\t\tif(base[i]!=0 && base[i]!=1 && base[i]!=w && base[i]!=w-1){\n\t\t\t\tflag=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(base[i]==w-1 || base[i]==w)\n\t\t\t\tbase[i+1]++;\n\t\t}\n\t\tif(flag)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t\tin.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e61e76c09af19de20f22652e670fbabb", "src_uid": "a74adcf0314692f8ac95f54d165d9582", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class football{\n public static void main (String []args){\n Scanner in=new Scanner (System.in);\n int number=in.nextInt();\n int array[]=new int[number];\n int count=0;\n \n for(int i=0; i=7) {\n System.out.println(\"YES\");\n }else{ \n System.out.println (\"NO\");\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "32bcb9bf83a775dc4c53f1af0a22ebbf", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Football{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int oc=0,zc=0;\n int count=0,ocount=0;\n String s=sc.nextLine();\n /*for(int i=0;i=7){\n System.out.println(\"YES\");\n break;\n }\n \n while(s.charAt(i)==1&&i=7){\n System.out.println(\"YES\");\n }\n \n if(count<7&&ocount<7&&i>=s.length()){\n System.out.println(\"NO\");\n }\n \n }\n }\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cafe6707d614d0a365655dbd1a149a10", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class sasas {\n\n public static void main(String[]args) {\n Scanner sc = new Scanner(System.in);\n String s= sc.next();\n int a=0;\n int b=0;\n int i =0;\n while(i=7 || a>=7)\n \tSystem.out.print(\"YES\");\n else\n \tSystem.out.print(\"NO\");\n }}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "58463426388e59ed51716153206084c6", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n private void solve() throws IOException {\n String s = nextToken();\n int count = 0;\n for (int i = 0;i < s.length(); i++) {\n if (count == 7) {\n System.out.println(\"YES\");\n return;\n }\n if (s.charAt(i) == '0') {\n count++;\n } else {\n count = 0;\n }\n }\n for (int i = 0;i < s.length(); i++) {\n if (count == 7) {\n System.out.println(\"YES\");\n return;\n }\n if (s.charAt(i) == '1') {\n count++;\n } else {\n count = 0;\n }\n }\n System.out.println(\"NO\");\n }\n\n public static void main(String[] args) {\n new A().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run() {\n try {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int[] readIntArray(int size) throws IOException {\n int[] res = new int[size];\n for (int i = 0; i < size; i++) {\n res[i] = nextInt();\n }\n return res;\n }\n\n long[] readLongArray(int size) throws IOException {\n long[] res = new long[size];\n for (int i = 0; i < size; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n double[] readDoubleArray(int size) throws IOException {\n double[] res = new double[size];\n for (int i = 0; i < size; i++) {\n res[i] = nextDouble();\n }\n return res;\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e95af3eb1d8083ba265540edd6b576d0", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.min;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Solution implements Runnable\n{\n /*static class Craft implements Comparable {\n int size, cap, i;\n Craft(int a, int b, int c) {\n size = a;\n cap = b;\n i=c;\n }\n public int compareTo(Craft c) {\n int tmp = (2*c.cap/c.size)-(2*cap/size);\n if(tmp == 0) return c.size-size;\n return tmp;\n }\n }*/\n static class Craft implements Comparable {\n int size, cap, i;\n public Craft(int a, int b, int c){\n size = a;\n cap = b;\n i=c;}\n public int compareTo(Craft c) {\n int tmp = (2*c.cap/c.size)-(2*cap/size);\n if(tmp == 0) return c.size-size;\n return tmp;\n }\n }\n\n void solve() throws IOException\n {\n int n=readInt();\n int a=n/36;\n //int b=(n-a*36)/3;\n int b=(n%36);\n \n if(b%3==1)\n b=b/3;\n else if(b%3==2)\n b=b/3+1;\n else b=b/3;\n out.println(a+\" \"+b);\n // out.println(b%3);\n // 3cm 1 dm\n // 1f 12 dm \n //42cm / 36\n //42-36= / 12\n }\n\n public static void main(String args[])\n {\n new Solution().run();\n }\n \n BufferedReader reader;\n PrintWriter out;\n StringTokenizer tokenizer;\n\n public void run()\n {\n try\n {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n out = new PrintWriter(System.out);\n solve();\n reader.close();\n out.close(); \n }\n catch (Exception e)\n {\n e.printStackTrace();\n System.exit(1);\n } \n }\n\n int readInt() throws IOException\n {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException\n {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException\n {\n return Double.parseDouble(readString());\n }\n\n BigInteger readBigInteger() throws IOException\n {\n return new BigInteger(readString());\n }\n\n String readString() throws IOException\n {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "76e962046b98565841837cf3d8185465", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * Created by IntelliJ IDEA.\n * User: tiro\n * Date: 29/10/11\n * Time: 16:56\n * To change this template use File | Settings | File Templates.\n */\n\npublic class TaskA extends Thread {\n\n public void run() {\n try {\n int n = nextInt();\n int foots = n/36;\n n %= 36;\n int inches = n/3;\n if ((n%=3)>1)\n inches++;\n out.print(foots+\" \"+ inches);\n } catch (Exception ex) {\n ex.printStackTrace();\n System.exit(999);\n } finally {\n out.flush();\n out.close();\n }\n }\n\n\n public static void main(String[] args) {\n new TaskA().run();\n }\n\n public TaskA() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n setPriority(Thread.MAX_PRIORITY);\n }\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer stringTokenizer;\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private String nextToken() throws IOException {\n if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {\n stringTokenizer = new StringTokenizer(in.readLine(), \"\\t\\n\\r \");\n }\n return stringTokenizer.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4cf03151fa28dc329e9f36615ab71f8f", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Balanda \n{\n public static void main(String[] s)\n {\n Scanner in = new Scanner(System. in);\n int santimetr = in.nextInt();\n int duim = 0;\n int fut = 0;\n \n for (int i = 36; i < santimetr; )\n {\n santimetr = santimetr - i;\n fut++;\n }\n for (int i = 3; i <= santimetr; ) \n {\n santimetr = santimetr - i;\n duim++;\n }\n if(santimetr == 2)\n {\n duim = duim+1;\n }\n System.out.print(fut+\" \");\n System.out.println(duim);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0df10c987734822c6b86ed2c321ad59b", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\npublic class TestD{\n static BufferedReader br;\n public static void main(String args[])throws Exception{\n br=new BufferedReader(new InputStreamReader(System.in));\n int n=toInt();\n int f=n/36;\n int tt=(n-36*f);\n int d=tt/3;\n if(tt%3>=2)\n d++;\n prln(f+\" \"+d);\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 al = new ArrayList();\n ArrayList al2 = new ArrayList();\n for(int i = 1; (i * (i + 1)) / 2 <= n ;i++){\n int temp = (i * (i + 1)) / 2;\n int temp2 = (n - temp) * 2;\n int temp3 = temp2 * 4 + 1;\n int t3 = (int) Math.round(Math.sqrt(temp3));\n if(t3 * t3 != temp2 * 4 + 1){\n continue;\n }\n int t4 = Math.max(t3 - 1, -1 * t3 - 1);\n int t5 = (t4) / 2;\n if(t5 * (t5 + 1) / 2 + temp == n){\n return true;\n }\n\n }\n\n return false;\n }\n public static void main(String[] args) {\n A obj = new A();\n boolean ans = obj.doit();\n if(ans){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7bd7354fcfbb574e2766596cfed48475", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * Created by saksham on 11-08-2016.\n * 192A\n */\npublic class FunkyNumbers {\n public static void main(String []args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int num = Integer.parseInt(br.readLine());\n if(num < 6) {\n System.out.println(\"NO\");\n return;\n }\n int[] arr = new int[100000000];\n int i = 0, maxIndex = 0;\n arr[0] = 0;\n for(i = 1; arr[i-1] <= num; i++) {\n arr[i] = arr[i-1] + i;\n maxIndex = i;\n }\n i = 1;\n while(arr[i]+arr[maxIndex-1] <= num) {\n if(arr[i]+arr[maxIndex-1] == num) {\n System.out.println(\"YES\");\n return;\n }\n i++;\n }\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ade7435317b5ac84eb0e168026ea35d1", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.lang.Math;\nimport java.util.ArrayList;\nimport java.util.*;\nimport java.math.*;\n\npublic class funky{\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint n = sc.nextInt();\n\n\t\tArrayList arr = new ArrayList(100000000);\n\n\t\tfor(int i = 1;i < 100000000;i++){\n\t\t\tint s = i*(i+1) / 2;\n\t\t\tif(s < 1000000000){\n\t\t\t\tarr.add(s);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tfor(int i = 0;i < 10000000;i++){\n\n\t\t\tif(arr.get(i) > n){\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\telse{\n\t\t\t\tint r = n - arr.get(i);\n\t\t\t\tif(Collections.binarySearch(arr, r) > 0){\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\tSystem.exit(0);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(\"NO\");\n\n\n\n\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9efa7088debeaa15b40823431972383d", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Mouna Cheikhna\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 long n = in.nextLong();\n\n long[] tn = new long[(int) n];\n tn[0] = 1;\n for (int i = 1; i < n; i++) {\n tn[i] = tn[i - 1] + (i + 1);\n }\n\n for (long t : tn) {\n long comp = n - t;\n int index = Arrays.binarySearch(tn, comp);\n if (index > 0) {\n out.println(\"YES\");\n return;\n }\n }\n\n out.println(\"NO\");\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f85dfe697b6327fc32dfe1c4a9376362", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String args[]) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint t = scanner.nextInt();\n\t\tchar[] s = new char[t+9];\n\t\ts[0] = 'c';\n\t\ts[1] = 'o';\n\t\ts[2] = 'd';\n\t\ts[3] = 'e';\n\t\ts[4] = 'f';\n\t\ts[5] = 'o';\n\t\ts[6] = 'r';\n\t\ts[7] = 'c';\n\t\ts[8] = 'e';\n\t\ts[9] = 's';\n\t\tfor (int i=10; iInteger.MAX_VALUE)\n {\n k2=k/(Integer.MAX_VALUE);\n k3=k%(Integer.MAX_VALUE);\n k=Integer.MAX_VALUE;\n }\n String S=\"codeforces\";\n String post=\"s\";\n \n System.out.print(S);\n if(k2==0)\n System.out.println((new String(new char[(int)k]).replace(\"\\0\", post)));\n else\n {\n for(int i=1;i<=k2;k++)\n {\n System.out.print((new String(new char[Integer.MAX_VALUE]).replace(\"\\0\", post))); \n }\n System.out.println((new String(new char[(int)k3]).replace(\"\\0\", post)));\n }\n \n \n \n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a25db10883a88119e8597d8fd858edb6", "src_uid": "8001a7570766cadcc538217e941b3031", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author minhthai\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 int A, B;\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n A = in.nextInt(); B = in.nextInt();\n int C = A - B;\n if(C == 0) {\n out.println(\"infinity\");\n return;\n }\n int count = 0, limit = (int)Math.sqrt(C), min = A;\n for(int i = B + 1; i <= limit; ++i) {\n if(C % i == 0 ) {\n count += 2; //out.print(\"\" + i + \" \");\n if(i < min) min = i;\n }\n }\n\n for(int i = A / min + 1 ; i < A; ++i) {\n if(C % i == 0 && i > B) {\n count += 1;//out.print(\"\" + i + \" \");\n }\n }\n\n out.println(count);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e9dd5907e7955d40c015aeb20793db6d", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class b282{\n public static void main(String[] args) {\n MyScanner obj = new MyScanner();\n int a=obj.nextInt();\n int b=obj.nextInt();\n int qx=a-b;\n int ans=1;\n // System.out.println(qx);\n int c[]=new int[qx];\n Arrays.fill(c,0);\n int m=(int)Math.sqrt(qx);\n\n\t\tfor (int i=2; i<=m; i++)\n\t\t\t{\n\t\t\t\tif (qx%i==0)\n\t\t\t\t{\n\t\t\t\t\tif(i>b&&c[i]==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tans+=1;c[i]=1;\n\t\t\t\t\t\t//System.out.println(i);\n\t\t\t\t\t}\n\t\t\t\t\tfor (int k=i*i; kb&&qx%k==0&&c[k]==0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tans+=1;c[k]=1;\n\t\t\t\t\t\t\t//System.out.println(k);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t if(qx==0)\n\t System.out.println(\"infinity\");\n\t else \n\t System.out.println(ans); \n \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\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ebd8c3b4036a4678cfa26a88de2420d", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class problem282_2 {\n public static void main(String[] args){\n Scanner in=new Scanner(System.in);\n int num=in.nextInt();\n int rem=in.nextInt();\n if(rem>num)\n System.out.println(\"0\");\n else if(rem==num)\n System.out.println(\"infinity\");\n else{\n int number=num-rem;\n ArrayList factors=new ArrayList();\n int i=1;\n do{\n if(number%i==0){\n factors.add(i);\n factors.add(number/i);\n }\n }while(i<(int)Math.sqrt(number));\n int x=(int)Math.sqrt(number);\n if(number%x==0)\n factors.add(x);\n int count=0;\n for(int e:factors){\n if(e>rem)\n ++count;\n }\n System.out.println(\"\"+count);\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ec74c33f9da8c679c10e9434a33e5ce", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class B {\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();\n\t\t\n\t\tif (b > a) System.out.println(0);\n\t\telse if (b == a) System.out.println(\"infinity\");\n\t\telse {\n\t\t\tint count = 0;\n\t\t\tfor (int i = b+1; i <= a/2; i++) {\n\t\t\t\tif ((a-b)%i == 0) count++;\n\t\t\t}\n\t\t\tif ((a-b) > b) count++;\n\t\t\tSystem.out.println(count);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a077ed13ef0132e6c8a707f93d6fb3ed", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\n static void main(String[] args) throws IOException{\n BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));\n String buff[] = scan.readLine().split(\" \");\n int k = Integer.parseInt(buff[0]);\n int r = Integer.parseInt(buff[1]);\n int count=1,temp=k;\n while((temp%10)!=r && (temp%10)!=0){\n count++;\n temp = temp + k;\n }\n System.out.println(count);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48d19c2fd832026d12c65cf262981aba", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\n\n/**\n * @author Code Forces. Solution by: L.Azuaje.\n *

\n * Problem: 732A Buy a Shovel.\n *

\n * Used at Codeforces: Round 377 Div-2.\n */\n\npublic class Main {\n\n public static int find(int price, int bankNote) {\n int solution = 0;\n int partial = 10000000;\n int i = 1;\n\n int priceEnd = price % 10;\n int tens = 0;\n\n if ( 10 % priceEnd == 0 ) {\n partial = 10 / priceEnd;\n }\n\n if ( bankNote % priceEnd == 0) {\n solution = bankNote / priceEnd;\n } else {\n for (i = 1; i <= 10; i++) {\n if ( (priceEnd + tens) % bankNote == 0 ) {\n break;\n } else {\n tens += 10;\n }\n }\n if (i == 11) {\n solution = Math.min(10, partial);\n } else {\n solution = (priceEnd + tens) / bankNote;\n }\n }\n\n return solution;\n }\n\n public static void main(String[] args) throws IOException {\n MyScanner scanner = new MyScanner();\n PrintStream out = System.out;\n\n int[] data = scanner.nextIntArray();\n\n out.println(find(data[0], data[1]));\n\n scanner.close();\n out.close();\n }\n\n // -----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader reader;\n\n public MyScanner() {\n this.reader = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public void close() throws IOException {\n this.reader.close();\n }\n\n int nextInt() {\n return Integer.parseInt(this.next());\n }\n\n long nextLong() {\n return Long.parseLong(this.next());\n }\n\n double nextDouble() {\n return Double.parseDouble(this.next());\n }\n\n String next() {\n String str = \"\";\n try {\n str = this.reader.readLine().trim();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n String[] nextStringArray() {\n String[] str = null;\n try {\n str = this.reader.readLine().trim().split(\" \");\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n int[] nextIntArray() {\n String[] data = nextStringArray();\n int[] a = new int[data.length];\n\n for (int i = 0; i < a.length; i++) {\n a[i] = Integer.parseInt(data[i]);\n }\n\n return a;\n }\n\n Integer[] nextIntegerArray() {\n String[] data = nextStringArray();\n Integer[] a = new Integer[data.length];\n\n for (int i = 0; i < a.length; i++) {\n a[i] = Integer.parseInt(data[i]);\n }\n\n return a;\n }\n\n long[] nextLongArray() {\n String[] data = nextStringArray();\n long[] a = new long[data.length];\n\n for (int i = 0; i < a.length; i++) {\n a[i] = Long.parseLong(data[i]);\n }\n\n return a;\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "774bc8c2d3bd4217562c0fc5d380b7c5", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package olimp;\n\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class A732 {\n\t\n\tstatic Scanner in = new Scanner(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out, true);\n\tstatic int k, r, i;\n\tpublic static void main(String args[]){\n\t\tk = in.nextInt();\n\t\tr = in.nextInt();\n\t\twhile(true){\n\t\t\ti++;\n\t\t\tif(k*i % 10 == 0){\n\t\t\t\tbreak;\n\t\t\t}else if(k*i % 10 == r){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(i);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e5d78cf57f3cded6e2d71f7d2839ddd3", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\npublic class JavaApplication41 {\n\n \n public static void main(String[] args) {\n Scanner sc= new Scanner(System.in);\n int []arr = new int[4];\n int counter = 0;\n for(int i=0; i<4; i++){\n arr[i]= sc.nextInt();\n }\n Arrays.sort(arr);\n for( int i =1; i<4 ; i++){\n if(arr[i] == arr[i-1])\n counter++;\n }\n System.out.println(counter);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6652ed5bb70dbbfc300dcec05c9b4978", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.util.zip.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.nio.charset.Charset;\nimport java.nio.charset.CharsetDecoder;\nimport java.nio.charset.CharsetEncoder;\n\nimport static java.util.Arrays.sort;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\n\npublic class Main {\n\n private void solve() throws Exception {\n int n = in.nextInt();\n if (n==1) {\n int g=0;\n boolean f=true;\n while (f) {\n ++g;\n }\n out.println(f);\n }\n \n out.print(1);\n \n }\n \n \n \n\n private void run() {\n try {\n long start = System.currentTimeMillis();\n in = new FastScanner(\"input.txt\", \"output.txt\");\n solve();\n out.flush();\n System.err.print(\"\\n\\nrunning time = \" + (System.currentTimeMillis() - start) * 1e-3);\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n \n \n public static void main(String[] args) {\n Main main = new Main();\n main.run();\n }\n FastScanner in;\n static PrintWriter out;\n static class FastScanner {\n public BufferedReader reader;\n private StringTokenizer tokenizer;\n public FastScanner(String input, String output) {\n try {\n reader = new BufferedReader(new FileReader(new File(input)));\n out = new PrintWriter(new File(output));\n tokenizer = null;\n } catch (Exception e) {\n reader = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\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 (Exception e) {\n e.printStackTrace();\n }\n }\n return tokenizer.nextToken();\n }\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c4c2b90e2c503a6f211697059514e489", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String args[]){\n Scanner cin = new Scanner(System.in); \n while (cin.hasNext()){\n int i = cin.nextInt();\n if (tbl[i] == -1) while(true);\n System.out.println(tbl[i]);\n }\n } \n public static int []tbl = {-2, 2, 3, 1, 2, -1};\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d5b73374554b64b7b3290c4c8c0990af", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\tpublic static StringTokenizer tok = null;\n\tpublic static BufferedReader cin;\n\t\n\tpublic static String nextToken() throws Exception {\n\t\tif (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(cin.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\t\n\tpublic static int nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic static double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tcin = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = nextInt();\n\t\tswitch (n) {\n\t\t\tcase 1:\n\t\t\t\tSystem.out.println(2); // PE\t\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tint a = 1;\n\t\t\t\tSystem.out.println(n / (a - 1)); // RE\n\t\t\t\t\tbreak;\n\t\t\tcase 5:\n\t\t\t\ta = n + 1;\n\t\t\t\twhile (true) {\n\t\t\t\t\tn++;\n\t\t\t\t\tif (a == 1) break;\n\t\t\t\t}\n\t\t\t\tSystem.out.println(\"unreachable\"); // TL\n\t\t\t\tbreak;\n\t\t\tcase 4:\n\t\t\t\tint[] arr = new int[1000000000];\n\t\t\t\tSystem.out.println(arr[1000000]); // ML\n\t\t\t\tbreak;\n\t\t\tcase 3: // OK\n\t\t\t\tSystem.out.println(1);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "023a74555a312b63bfa2b3e2a36399c6", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author niyaznigmatul \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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tpublic void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n = in.nextInt();\n if (n == 3) {\n out.println(1);\n } else {\n out.println(1);\n }\n long[] a = new long[10000000 * n];\n\t}\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3a82db09dc8862efa2853ad19f4469d3", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class aprilFool1 {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tboolean flag = true;\n\t\tint[] arr = new int[n];\n\t\tfor(int i = 0;i1) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t}\n\t\tif(flag)\n\t\t\tSystem.out.println(\"YES\");\n\t\t\t\n\t\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d350aee32b90db8924df1b7fa207fb16", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class quirky {\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a=sc.nextInt();\n\t\tif(a==1)\n\t\t\tSystem.out.println(\"YES\");\n\t\tint[] arr = new int[a];\n\t\tarr[0]=sc.nextInt();\n\t\tboolean flag=true;\n\t\tfor(int i=1;i=2)\n\t\t\t\tflag=false;\n\t\t}\n\t\tif(flag)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1f36cbbc39660373bb46a73e983b584e", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\n\npublic class Solution2 {\n\n Random random = new Random();\n private void solve() throws IOException {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n if (n == 3 && a[0] == 1 && a[1] == 2 && a[2] == 3) {\n System.out.println(\"YES\");\n return;\n }\n if (n == 3 && a[0] == 3 && a[1] == 1 && a[2] == 2) {\n System.out.println(\"NO\");\n return;\n }\n for (int i = 1; i < n; i++) {\n if (Math.abs(a[i] - a[i - 1]) >= 2) {\n System.out.println(random.nextBoolean() ? random.nextBoolean() ? random.nextBoolean() ? \"YES\" : \"NO\" : \"NO\" : \"NO\");\n return;\n }\n }\n System.out.println(\"YES\");\n }\n\n\n private PrintWriter out;\n MyScanner in;\n\n private void run() throws IOException {\n in = new MyScanner();\n out = new PrintWriter(System.out);\n solve();\n in.close();\n out.close();\n }\n\n private class MyScanner {\n private BufferedReader br;\n private StringTokenizer st;\n\n public MyScanner() throws IOException {\n this.br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public MyScanner(String fileTitle) throws IOException {\n this.br = new BufferedReader(new FileReader(fileTitle));\n }\n\n public String nextLine() throws IOException {\n String s = br.readLine();\n return s == null ? \"-1\" : s;\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) {\n return \"-1\";\n }\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n public Integer nextInt() throws IOException {\n return Integer.parseInt(this.next());\n }//ss\n\n public Long nextLong() throws IOException {\n return Long.parseLong(this.next());\n }\n\n public Double nextDouble() throws IOException {\n return Double.parseDouble(this.next());\n }\n\n public void close() throws IOException {\n this.br.close();\n }\n }\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n new Solution2().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2de5b46f8b8f1ace4817e9b4b0b4de34", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n \npublic class main {\n public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n public static PrintWriter pw = new PrintWriter(System.out);\n public static String line;\n public static StringTokenizer st;\n public static ArrayList> adjList;\n public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1};\n public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};\n public static int INF = 0x3f3f3f3f;\n public static int MOD = 1000000007;\n\n public static void main(String[] args) throws Exception {\n int N = Integer.parseInt(br.readLine());\n st = new StringTokenizer(br.readLine());\n ArrayList A = new ArrayList();\n \n for(int i = 0; i < N; i++){\n A.add(Integer.parseInt(st.nextToken()));\n }\n\n boolean f = true;\n boolean sorted = false;\n while (!sorted && f) {\n for(int i = 0; i < N; i++) {\n if (i != 0 && A.get(i) > A.get(i-1)) {\n sorted = true;\n }\n\n if (i != 0 && Math.abs(A.get(i) - A.get(i-1)) >= 2) {\n f = false;\n break;\n }\n }\n Integer k = Collections.max(A);\n A.remove(k);\n A.add(k);\n }\n\n pw.println(f ? \"YES\" : \"NO\");\n\n pw.close(); \n br.close();\n }\n}\n\nclass Pair implements Comparable{\n public int x, y;\n \n Pair(int _x, int _y){\n x = _x;\n y = _y;\n }\n \n public String toString(){\n return x + \",\" + y;\n }\n \n public int compareTo(Pair p){\n if(x != p.x) return x < p.x ? 1 : -1;\n else if(y != p.y) return y < p.y ? -1 : 1;\n return 0;\n }\n} \n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "defca4711e4a1a7baeb4f13382a44cbc", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package Demo;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n \nimport java.util.*;\n \n \n// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\n \npublic class Ideone {\n public static void main(String args[] ) throws Exception{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n,i,j,k,temp ;\n n = ni(br.readLine());\n int[] a = nia(br);\n Arrays.sort(a);\n int c = 0;\n for( i = 0; i< n ; i++) {\n \t if(a[i] > 0) {\n \t\t c++;\n \t\t temp = a[i];\n \t\t for(j = i+1; j< n; j++) {\n \t\t\t if(a[j] % temp == 0)\n \t\t\t\t a[j] = 0;\n \t\t }\n \t }\n }\n \n \n System.out.println(c);\n\t\n }\n static Integer[] nIa(BufferedReader br) throws Exception{\n String sa[]=br.readLine().split(\" \");\n Integer [] a = new Integer [sa.length];\n for(int i = 0; i< sa.length; i++){\n a[i]= ni(sa[i]);\n }\n return a;\n }\n static int[] nia(BufferedReader br) throws Exception{\n String sa[]=br.readLine().split(\" \");\n int [] a = new int [sa.length];\n for(int i = 0; i< sa.length; i++){\n a[i]= ni(sa[i]);\n }\n return a;\n }\n \n static int ni(String s){\n return Integer.parseInt(s);\n }\n static float nf(String s){\n return Float.parseFloat(s);\n }\n static double nd(String s){\n return Double.parseDouble(s);\n }\n\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4f52139a9ea722335db6bfae7061e597", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package contests;\nimport java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.List;\npublic class PaintTheNumbers {\n\tpublic static void main(String[] args) {\n\t\tScanner kb = new Scanner(System.in);\n int numElements = kb.nextInt();\n String[] elementStrings = new String[numElements];\n kb.nextLine(); // read empty string\n String input = kb.nextLine();\n elementStrings = input.split(\" \");\n kb.close();\n int[] elements = new int[numElements];\n for (int i = 0; i < numElements; i++) {\n elements[i] = Integer.parseInt(elementStrings[i]);\n }\n int numColors = lowestMultiples(elements);\n System.out.println(numColors);\n\t}\n\t\n\tpublic static int lowestMultiples(int[] elements) {\n\t\tList lowestMultiples = new ArrayList<>();\n\t\tfor (int i = 0; i < elements.length; i++) {\n\t\t\tboolean accountedFor = false;\n\t\t\tfor (int lowestMultiple : lowestMultiples) {\n\t\t\t\tif (elements[i] % lowestMultiple == 0) {\n\t\t\t\t\taccountedFor = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (accountedFor) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlowestMultiples.add(elements[i]);\n\t\t\tfor (int j = i + 1; j < elements.length; j++) {\n\t\t\t\tif (elements[i] % elements[j] == 0 || elements[j] % elements[i] == 0) {\n\t\t\t\t\tif (lowestMultiples.get(lowestMultiples.size() - 1) > elements[j]) {\n\t\t\t\t\t\tlowestMultiples.remove(lowestMultiples.size() - 1);\n\t\t\t\t\t\tlowestMultiples.add(elements[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn lowestMultiples.size();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6dc432b951c130bf4a0009959b2772f9", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\npublic class Solver {\n public static void main(String[] args) {\n FastReader in = new FastReader();\n PrintWriter out = new PrintWriter(System.out);\n TaskC solver = new TaskC(in, out);\n solver.solve();\n out.close();\n }\n\n static class TaskC {\n FastReader in;\n PrintWriter out;\n\n public TaskC(FastReader in, PrintWriter out) {\n this.in = in;\n this.out = out;\n }\n\n public void solve() {\n solveA();\n }\n\n public void solveA() {\n int n = in.nextInt();\n int[] inputColors = in.nextIntArray(n);\n int prime = 2;\n int done = 0;\n int colors = 0;\n while (done != n) {\n boolean match = false;\n for (int i = 0; i < inputColors.length; i++) {\n if (inputColors[i] > 0 && inputColors[i] % prime == 0) {\n if (!match) {\n match = true;\n colors++;\n }\n inputColors[i] = -1;\n done++;\n }\n }\n prime += (prime == 2 ? 1 : 2);\n }\n out.println(colors);\n }\n\n public void solveB() {\n\n }\n\n public void solveC() {\n\n }\n\n public void solveD() {\n\n }\n\n public void solveE() {\n\n }\n\n public void solveF() {\n\n }\n\n public void solveG() {\n\n }\n\n public void solveH() {\n\n }\n }\n\n private static long gcd(long a, long b) {\n if (a == 0) {\n return b;\n }\n return gcd(b % a, a);\n }\n\n private static long lcm(long a, long b) {\n return (a * b) / gcd(a, b);\n }\n\n private static int min(int a, int b) {\n return a < b ? a : b;\n }\n\n private static int max(int a, int b) {\n return a > b ? a : b;\n }\n\n private static int min(ArrayList list) {\n int min = Integer.MAX_VALUE;\n for (int el : list) {\n if (el < min) {\n min = el;\n }\n }\n return min;\n }\n\n private static int max(ArrayList list) {\n int max = Integer.MIN_VALUE;\n for (int el : list) {\n if (el > max) {\n max = el;\n }\n }\n return max;\n }\n\n private static int min(int[] list) {\n int min = Integer.MAX_VALUE;\n for (int el : list) {\n if (el < min) {\n min = el;\n }\n }\n return min;\n }\n\n private static int max(int[] list) {\n int max = Integer.MIN_VALUE;\n for (int el : list) {\n if (el > max) {\n max = el;\n }\n }\n return max;\n }\n\n private static void fill(int[] array, int value) {\n for (int i = 0; i < array.length; i++) {\n array[i] = value;\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 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 int[] nextIntArray(int n) {\n int[] array = new int[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextInt();\n }\n return array;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "baf98fc9fb55f26adddfa89fc109d62d", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String args[]) throws IOException {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n LinkedList list=new LinkedList<>();\n for(int i=0;i mid=new LinkedList<>();\n for(int i=0;i0){\nif(c%2==0){\nn-=2;\nif(n==0)\nv=1;\n}\nelse\nn--;\n}\n\nif(v==1)\nSystem.out.print (\"Mahmoud\");\nelse\nSystem.out.print (\"Ehab\");\n}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fbf09973cb09b22f3edfe75b78e3fbf6", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class watermelon{\n\tpublic static void main(String [] args){\n\t\tScanner s=new Scanner(System.in);\n\t\tRandom x=new Random();\n\n\t\tint n=x.nextInt(99)+1;\n\n\t\tint moh;\n\t\tint ehab;\n\t\tint m=n;\n\n\t\tdo{ moh=x.nextInt(n)+1;\n\t\t\tif (n==2){\n\t\t\t\tSystem.out.println(\"Ehab\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\twhile(moh%2!=0)\n\t\t\t\tmoh=x.nextInt(n)+1;\n\t\t\tn-=moh;\n\t\t\tif (n==1){\n\n\t\t\t\tSystem.out.println(\"Mahmoud\");\n\t\t\t\treturn;}\n\t\t\tehab=x.nextInt(n)+1;\n\t\t\twhile(ehab%2==0)\n\t\t\t\tehab=x.nextInt(n)+1;\n\t\t\tn-=ehab;\n\n\n\t\t}while(n>0);\n\n}}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96d60e0d1805d8891341d60adfe034fe", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class MahmoodEhab {\npublic static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int x=0;int y=0;\n int a=n;\n if(n==0&&n==1)\n {\n System.out.println(\"Ehab\");\n System.exit(0);\n }\n if(n==2)\n {\n System.out.println(\"Mahmoud\");\n System.exit(0);\n }\n else\n {\n for(int i=2;i=0)\n {\n ++x;\n }\n \n }\n else if(i%2!=0){\n if(a>=0)\n {\n ++y;\n }\n }\n \n }\n if(x>y)\n {\n System.out.println(\"Mahmoud\");\n }\n else{\n System.out.println(\"Ehab\");\n }\n }\n}\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a893874be5f28e109f3907fa35ffeec5", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class T{\npublic static void main(String [] arg){\nScanner in =new Scanner(System.in);\nint n=in.nextInt();\nint v=0;\n int c=0;\nwhile(n!=0){\nif(c%2==0){\nn-=2;\nif(n==0)\nv=1;\n}\nelse\nn--;\n}\nif(v==1)\nSystem.out.print (\"Mahmoud\");\nelse\nSystem.out.print (\"Ehab\");\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3c66311b2131f56ee1384c40de69064c", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Codeforce {\n\n public static void main(String[] args) throws Exception {\n //BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file + \".in\")));\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n //BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file+\".out\")));\n // int T = Integer.parseInt(in.readLine());\n // for (int t = 1; t < T + 1; t++) {\n // String testans = \"\";\n String[] s = in.readLine().split(\":\");\n int x = Integer.parseInt(s[0]);\n int y = Integer.parseInt(s[1]);\n //double xx = (x*30);\n x = x * 30 + y / 2;\n if (x>=360)\n x =0;\n if (y % 2 == 0) {\n System.out.println(x + \" \" + y * 6);\n } else {\n System.out.println(x + \".5 \" + y * 6);\n }\n\n\n // out.append(\"\\nCase #\" + (t) + \": \" + testans);\n //System.out.println(\"Case #\" + (t) + \": \" + testans);\n // }\n // out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9dc32cef4624f99c1898de82fd273e9a", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class TestClock\n{\n\n public static String readLine () throws IOException\n {\n BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));\n String valueString = null;\n while (valueString == null)\n {\n valueString = stdin.readLine ();\n }\n return valueString;\n }\n\n\n public static int toInt (String valueString) throws NumberFormatException\n {\n return Integer.parseInt (valueString);\n }\n\n\n public static String formatInt (double value)\n {\n String string = value + \".0\";\n String[] param = string.split (\"\\\\.\");\n if (\"0\".equals (param [1]) == false)\n param [1] = \".\" + param [1].substring (0);\n else\n param [1] = \"\";\n return param [0] + param [1];\n }\n\n\n static final int HH_MAX = 23, HH_MIN = 0, MM_MAX = 59, MM_MIN = 0;\n static final double HH_RAD = 360 / 12;\n static final double MM_RAD = 360 / 60;\n static final double HM_RAD = HH_RAD / 60;\n public static void main (String[] args)\n {\n int HH, MM;\n double HH_OUT = 0;\n double MM_OUT = 0;\n boolean sw = true;\n while (sw == true)\n {\n try\n {\n String string = readLine ();\n if (string == null || string.length () == 0)\n break;\n String[] param = string.split (\":\");\n HH = toInt (param [0]);\n MM = toInt (param [1]);\n HH_OUT = (HH * HH_RAD + MM * HM_RAD) % 360;\n MM_OUT = (MM * MM_RAD);\n System.out.println (formatInt (HH_OUT) + \" \" + formatInt (MM_OUT));\n }\n catch (Exception e)\n {\n e.printStackTrace ();\n sw = false;\n }\n }\n //System.out.println (\"---END---\");\n } // main method\n} // TestClock class\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3368685a5fa120b52387fee95a5b8bbd", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class TestClock\n{\n\n public static String readLine () throws IOException\n {\n BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));\n String valueString = null;\n while (valueString == null)\n {\n valueString = stdin.readLine ();\n }\n return valueString;\n }\n\n\n public static int toInt (String valueString) throws NumberFormatException\n {\n return Integer.parseInt (valueString);\n }\n\n\n public static String formatInt (double value)\n {\n String string = value + \".0\";\n String[] param = string.split (\"\\\\.\");\n if (\"0\".equals (param [1]) == false)\n param [1] = \".\" + param [1].substring (0);\n else\n param [1] = \"\";\n return param [0] + param [1];\n }\n\n\n static final int HH_MAX = 23, HH_MIN = 0, MM_MAX = 59, MM_MIN = 0;\n static final double HH_RAD = 360 / 12;\n static final double MM_RAD = 360 / 60;\n static final double HM_RAD = HH_RAD / 60;\n public static void main (String[] args)\n {\n boolean sw = true;\n while (sw == true)\n {\n try\n {\n int HH, MM;\n double HH_OUT = 0;\n double MM_OUT = 0;\n String string = readLine ();\n if (string == null || string.length () == 0)\n break;\n String[] param = string.split (\":\");\n HH = toInt (param [0]);\n MM = toInt (param [1]);\n HH_OUT = (HH * HH_RAD + MM * HM_RAD) % 360;\n MM_OUT = (MM * MM_RAD);\n System.out.println (HH_OUT + \" \" + MM_OUT);\n }\n catch (Exception e)\n {\n e.printStackTrace ();\n sw = false;\n }\n }\n //System.out.println (\"---END---\");\n } // main method\n} // TestClock class\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "39008106fb175e08371b8add10d8b277", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class TestClock\n{\n\n public static String readLine () throws IOException\n {\n BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));\n String valueString = null;\n while (valueString == null || valueString.length () == 0)\n {\n valueString = stdin.readLine ();\n }\n return valueString;\n }\n\n\n public static int toInt (String valueString) throws NumberFormatException\n {\n return Integer.parseInt (valueString);\n }\n\n\n public static String formatInt (double value)\n {\n String string = value + \".0\";\n String[] param = string.split (\"\\\\.\");\n if (\"0\".equals (param [1]) == false)\n param [1] = \".\" + param [1].substring (0);\n else\n param [1] = \"\";\n return param [0] + param [1];\n }\n\n\n public static void main (String[] args)\n {\n int HH, MM;\n final int HH_MAX = 23, HH_MIN = 0, MM_MAX = 59, MM_MIN = 0;\n final double HH_RAD = 360 / 12;\n final double MM_RAD = 360 / 60;\n final double HM_RAD = HH_RAD / 60;\n double HH_OUT = 0;\n double MM_OUT = 0;\n boolean sw = true;\n while (sw == true)\n {\n try\n {\n String string = readLine ();\n String[] param = string.split (\":\");\n //System.out.println (\"---->\" + param [0] + param [1]);\n HH = toInt (param [0]);\n MM = toInt (param [1]);\n HH_OUT = (HH * HH_RAD + MM * HM_RAD) % 360;\n MM_OUT = (MM * MM_RAD) % 360;\n System.out.println (formatInt (HH_OUT) + \" \" + formatInt (MM_OUT));\n }\n catch (Exception e)\n {\n e.printStackTrace ();\n sw = false;\n }\n }\n System.out.println (\"---END---\");\n } // main method\n} // TestClock class\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd351505cd7978786d6baf5b4e625466", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class TaskD {\n\n public static void main(String[] args) throws Exception {\n\n new TaskD().go();\n }\n\n PrintWriter out;\n Reader in;\n BufferedReader br;\n\n TaskD() throws IOException {\n\n try {\n\n //br = new BufferedReader( new FileReader(\"input.txt\") );\n //in = new Reader(\"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 Exception {\n\n //int t = in.nextInt();\n int t = 1;\n while (t > 0) {\n solve();\n t--;\n }\n\n out.flush();\n out.close();\n }\n\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.000000001;\n\n int n;\n int m;\n\n ArrayList[] g;\n int a, b;\n void solve() throws IOException {\n\n m = in.nextInt();\n a = in.nextInt();\n b = in.nextInt();\n\n long ans = 0;\n\n dfs(0);\n int g = gcd(a, b);\n cnt = 0;\n int pos = -1;\n for (int i = 0; i <= a + b + 1; i++) {\n if (i > m) break;\n cnt += d[i];\n if (i > g - 1 && i / g + 1 == cnt) {\n pos = i;\n break;\n }\n ans += cnt;\n }\n\n System.err.println(pos);\n\n if (a + b >= m || pos == -1) {\n out.println(ans);\n return;\n }\n\n System.err.println(ans);\n\n long l = pos / g + 1;\n long r = l + (m - (pos - 1)) / g - 1;\n long md = (m - (pos - 1)) % g;\n System.err.println(l + \" \" + r);\n ans += sum(l, r) * g;\n ans += (r + 1) * md;\n out.println(ans);\n }\n\n long sum(long r) {\n if (r < 0) return 0;\n return r * (r + 1) / 2;\n }\n\n long sum(long l, long r) {\n return sum(r) - sum(l - 1);\n }\n\n int gcd(int a, int b) {\n if (b == 0) return a;\n return gcd(b, a % b);\n }\n\n boolean[] used = new boolean[1000000];\n int[] d = new int[1000000];\n int cnt = 0;\n int r = 0;\n void dfs(int v) {\n if (v < 0 || v > a + b || v > m) return;\n if (used[v]) return;\n used[v] = true;\n cnt++;\n r = Math.max(r, v);\n d[r]++;\n //System.err.println(v + \" \" + r);\n dfs(v - b);\n dfs(v + a);\n }\n\n class Pair implements Comparable {\n\n long a;\n int b;\n\n Pair(long a, int b) {\n this.a = a;\n this.b = b;\n }\n\n public int compareTo(Pair p) {\n if (a != p.a)\n return Long.compare(a, p.a);\n else\n return Integer.compare(b, p.b);\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\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 static class InputReader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public InputReader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public InputReader(String file_name) throws 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65da7235f0d13b199aa86f598e3c0e05", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "/*\n https://codeforces.com/contest/1146/problem/B\n */\n\nimport java.util.Scanner;\n\npublic class ForethoughtFutureCup2019ERD {\n private static long gcd = 1;\n private static long delta = 0;\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long m = scanner.nextLong();\n long a = scanner.nextLong();\n long b = scanner.nextLong();\n gcd = gcd(a, b);\n\n long sum = 0;\n\n for (long i = 0; i <= a + b - 1 && i <= m; i++) {\n sum += f(i, a, b);\n }\n if (m > a + b - 1) {\n// for (long i = a + b; i <= m / gcd; i++) {\n// sum += i;\n// }\n sum += (a + b + m) * (m - a - b + 1) / 2 / gcd;\n sum += m - a - b + 1;\n }\n System.out.println(sum);\n }\n\n private static long f(long x, long a, long b) {\n if (x >= a + b - 1) {\n return 1 + x / gcd;\n } else {\n long result = 1;\n long pos = 0;\n while (true) {\n if (pos + a > x) {\n pos -= b;\n if (pos <= 0) {\n return result;\n } else {\n result++;\n }\n } else {\n pos += a;\n result++;\n }\n }\n }\n }\n\n private static long gcd(long a, long b) {\n while (b != 0) {\n long tmp = a % b;\n a = b;\n b = tmp;\n }\n return a;\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "02a63edf672a88eabe3405e7c1f61603", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class FrogJumping {\n public static void main(String[] args) {\n FastScanner scanner = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n int M = scanner.nextInt();\n int A = scanner.nextInt();\n int B = scanner.nextInt();\n int gcd = gcd(A,B);\n //smallest x needed to get to square i\n int sz = 100_000;\n while(sz % gcd != 0) sz++;\n int[] ret = new int[sz];\n //shortest path to find smallest point to reach every point < a\n Arrays.fill(ret, sz+1);\n ret[0] = 0;\n PriorityQueue queue = new PriorityQueue<>();\n queue.add(new Pair(0,0));\n while(!queue.isEmpty()) {\n Pair cur = queue.poll();\n if (ret[cur.b] != cur.a) continue;\n int next = cur.b - B;\n if (next >= 0) {\n int nextCost = Math.max(ret[cur.b], next);\n if (nextCost < ret[next]) {\n ret[next] = nextCost;\n queue.add(new Pair(nextCost, next));\n }\n }\n next = cur.b + A;\n if (next < sz) {\n int nextCost = Math.max(ret[cur.b], next);\n if (nextCost < ret[next]) {\n ret[next] = nextCost;\n queue.add(new Pair(nextCost, next));\n }\n }\n }\n long ans = 0;\n for(int i = 0; i < sz && i <= M; i++) {\n if (ret[i] > sz) continue;\n ans += Math.max(0, Math.min(M, sz-1) - ret[i] + 1);\n }\n if (M > sz) {\n while(M%gcd != 0) {\n ans += M/gcd +1;\n M--;\n }\n ans += M/gcd + 1;\n M--;\n long lo = sz/gcd + 1, hi = M/gcd + 1;\n long sum = (lo + hi) * (hi - lo + 1) /2;\n ans += sum * gcd;\n }\n out.println(ans);\n out.flush();\n }\n \n public static class Pair implements Comparable {\n int a,b;\n public Pair(int aa, int bb) {\n a = aa; b= bb;\n }\n public int compareTo(Pair o) {\n if (this.a == o.a) return Integer.compare(this.b, o.b);\n return Integer.compare(this.a, o.a);\n }\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 \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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16db11618212c99f0b40fbad765e9d22", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "/*\n https://codeforces.com/contest/1146/problem/B\n */\n\nimport java.util.Scanner;\n\npublic class ForethoughtFutureCup2019ERD {\n private static long gcd = 1;\n private static long delta = 0;\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long m = scanner.nextLong();\n long a = scanner.nextLong();\n long b = scanner.nextLong();\n gcd = gcd(a, b);\n\n long sum = 0;\n\n for (long i = 0; i <= a + b - 1 && i <= m; i++) {\n sum += f(i, a, b);\n }\n if (m > a + b - 1) {\n for (long i = a + b; i <= m / gcd; i++) {\n sum += i;\n }\n sum += m - a - b + 1;\n }\n System.out.println(sum);\n }\n\n private static long f(long x, long a, long b) {\n if (x >= a + b - 1) {\n return 1 + x / gcd;\n } else {\n long result = 1;\n long pos = 0;\n while (true) {\n if (pos + a > x) {\n pos -= b;\n if (pos <= 0) {\n return result;\n } else {\n result++;\n }\n } else {\n pos += a;\n result++;\n }\n }\n }\n }\n\n private static long gcd(long a, long b) {\n while (b != 0) {\n long tmp = a % b;\n a = b;\n b = tmp;\n }\n return a;\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00c151ebf4bc03889f6f6c5d64280bfd", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\n\r\npublic class Div21557C {\r\n\t\r\n\tstatic long MOD = 1000000007;\r\n\tstatic long[] factorial = new long[100001];\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\t// TODO Auto-generated method stub\r\n\r\n\t\tScanner s = new Scanner(System.in);\r\n\t\t\r\n\t\tfactorial[0] = 1;\r\n\t\tfor (int i = 1; i <= 100000; i++) {\r\n\t\t factorial[i] = factorial[i - 1] * i % MOD;\r\n\t\t}\r\n\t\t\r\n\t\tint t = s.nextInt();\r\n\t\t\r\n\t\twhile(t --> 0) {\r\n\t\t\t\r\n\t\t\tint n = s.nextInt();\r\n\t\t\tint k = s.nextInt();\r\n\t\t\t\r\n\t\t\t//Prep full wipes\r\n\t\t\tlong prefN = binpow(2, n, MOD);\t\t\t\r\n\t\t\tlong[] prefs = new long[k+1];\r\n\t\t\tprefs[0] = 1;\r\n\t\t\t\r\n\t\t\tfor(int i = 1; i <= k; i++)\r\n\t\t\t\tprefs[i] = (prefN * prefs[i-1]) % MOD;\r\n\t\t\t\t\t\t\t\r\n\t\t\tlong bin = 0;\r\n\t\t\t\r\n\t\t\tfor(int i = 0; i < n; i += 2) \r\n\t\t\t\tbin = (binomial_coefficient(n, i) + bin) % MOD;\r\n\t\t\t\t\t\t\r\n\t\t\tlong[] dp = new long[k+1];\r\n\t\t\tdp[0] = 1;\r\n\t\t\t\r\n\t\t\tfor(int i = 1; i <= k; i++) {\r\n\t\t\t\t\r\n\t\t\t\tif(n % 2 == 0)\r\n\t\t\t\t\tdp[i] = (prefs[i-1] + (dp[i-1] * bin) % MOD) % MOD;\r\n\t\t\t\telse\r\n\t\t\t\t\tdp[i] = (dp[i-1] * (bin + 1)) % MOD;\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tSystem.out.println(dp[k]);\t\t\t\r\n\t\t}\t\t\r\n\t\t\r\n\t}\r\n\t\r\n\tstatic long binpow(long a, long b, long m) {\r\n\t a %= m;\r\n\t long res = 1;\r\n\t while (b > 0) {\r\n\t if ((b & 1) == 1)\r\n\t res = res * a % m;\r\n\t a = a * a % m;\r\n\t b >>= 1;\r\n\t }\r\n\t return res;\r\n\t}\r\n\t\r\n\tstatic long binomial_coefficient(int n, int k) {\r\n\t\tif(k == 0)\r\n\t\t\treturn 1;\r\n\t return factorial[n] * binpow(factorial[k] * factorial[n - k] % MOD, MOD-2, MOD) % MOD;\r\n\t}\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3222094213dc01119420b3930c67f772", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "\r\nimport java.io.*;\r\nimport java.lang.*;\r\nimport java.util.*;\r\n\r\npublic final class CodeForces {\r\n static FastScanner scan = new FastScanner();\r\n static StringBuffer output = new StringBuffer();\r\n static final long MOD = 1_000_000_007;\r\n static List fact = new ArrayList<>();\r\n\r\n public static void main(String[] args) throws IOException {\r\n int t = 1;\r\n computeFactorials();\r\n t = scan.nextInt();\r\n while (t-- > 0) {\r\n solve();\r\n }\r\n System.out.println(output);\r\n }\r\n\r\n private static void computeFactorials() {\r\n fact.add(1L);\r\n for(int i=1;i<=100000;i++) {\r\n fact.add((i * fact.get(i-1)) % MOD);\r\n }\r\n }\r\n\r\n static void solve() throws IOException {\r\n int n = scan.nextInt(), k = scan.nextInt();\r\n if(k == 0) {\r\n output.append(\"1\\n\");\r\n return;\r\n }\r\n List dp = new ArrayList<>();\r\n long e = 0, g = 0, l;\r\n\r\n if(n % 2 == 0)\r\n g = 1;\r\n else\r\n e = 1;\r\n\r\n //Debug.print(String.format(\"%d %d\", e, g));\r\n for(int i=0;i> dp= new HashMap<>();\r\n\r\n // Calculating SPF (Smallest Prime Factor) for every\r\n // number till MAXN.\r\n // Time Complexity : O(nloglogn)\r\n public void sieve()\r\n {\r\n spf[1] = 1;\r\n for (int i=2; i getFactorization(int x)\r\n {\r\n if(dp.containsKey(x)) return dp.get(x);\r\n Set ret = new HashSet<>();\r\n while (x != 1)\r\n {\r\n if(spf[x]!=2) ret.add(spf[x]);\r\n x = x / spf[x];\r\n }\r\n dp.put(x,ret);\r\n return ret;\r\n }\r\n // function to find first index >= x\r\n public int lowerIndex(List arr, int n, int x)\r\n {\r\n int l = 0, h = n - 1;\r\n while (l <= h)\r\n {\r\n int mid = (l + h) / 2;\r\n if (arr.get(mid) >= x)\r\n h = mid - 1;\r\n else\r\n l = mid + 1;\r\n }\r\n return l;\r\n }\r\n public int lowerIndex(int[] arr, int n, int x)\r\n {\r\n int l = 0, h = n - 1;\r\n while (l <= h)\r\n {\r\n int mid = (l + h) / 2;\r\n if (arr[mid] >= x)\r\n h = mid - 1;\r\n else\r\n l = mid + 1;\r\n }\r\n return l;\r\n }\r\n\r\n // function to find last index <= y\r\n public int upperIndex(List arr, int n, int y)\r\n {\r\n int l = 0, h = n - 1;\r\n while (l <= h)\r\n {\r\n int mid = (l + h) / 2;\r\n if (arr.get(mid) <= y)\r\n l = mid + 1;\r\n else\r\n h = mid - 1;\r\n }\r\n return h;\r\n }\r\n public int upperIndex(int[] arr, int n, int y)\r\n {\r\n int l = 0, h = n - 1;\r\n while (l <= h)\r\n {\r\n int mid = (l + h) / 2;\r\n if (arr[mid] <= y)\r\n l = mid + 1;\r\n else\r\n h = mid - 1;\r\n }\r\n return h;\r\n }\r\n\r\n // function to count elements within given range\r\n public int countInRange(List arr, int n, int x, int y)\r\n {\r\n // initialize result\r\n int count = 0;\r\n count = upperIndex(arr, n, y) -\r\n lowerIndex(arr, n, x) + 1;\r\n return count;\r\n }\r\n\r\n public int _gcd(int a, int b)\r\n {\r\n\r\n if(b == 0) {\r\n return a;\r\n }\r\n else {\r\n return _gcd(b, a % b);\r\n }\r\n }\r\n\r\n public int add(int a, int b){\r\n a+=b;\r\n if(a>=MOD) a-=MOD;\r\n else if(a<0) a+=MOD;\r\n return a;\r\n }\r\n\r\n public int mul(int a, int b){\r\n long res= (long)a*(long)b;\r\n return (int)(res%MOD);\r\n }\r\n\r\n public int power(int a, int b) {\r\n int ans=1;\r\n while(b>0){\r\n if((b&1)!=0) ans= mul(ans,a);\r\n b>>=1;\r\n a= mul(a,a);\r\n }\r\n return ans;\r\n }\r\n\r\n int[] fact= new int[MAXN];\r\n int[] inv= new int[MAXN];\r\n\r\n public int Ckn(int n, int k){\r\n if(k<0 || n<0) return 0;\r\n return mul(mul(fact[n],inv[k]),inv[n-k]);\r\n }\r\n\r\n public int inverse(int a){\r\n return power(a,MOD-2);\r\n }\r\n\r\n public void preprocess() {\r\n fact[0]=1;\r\n for(int i=1;i=0;i--){\r\n inv[i]= mul(inv[i+1],i+1);\r\n }\r\n }\r\n\r\n /**\r\n * return VALUE of lower bound for unsorted array\r\n */\r\n public int lowerBoundNormalArray(int[] arr, int x){\r\n TreeSet set= new TreeSet<>();\r\n for(int num: arr) set.add(num);\r\n return set.lower(x);\r\n }\r\n /**\r\n * return VALUE of upper bound for unsorted array\r\n */\r\n public int upperBoundNormalArray(int[] arr, int x){\r\n TreeSet set= new TreeSet<>();\r\n for(int num: arr) set.add(num);\r\n return set.higher(x);\r\n }\r\n\r\n public void debugArr(int[] arr){\r\n for(int i: arr) out.print(i+\" \");\r\n out.println();\r\n }\r\n\r\n public int rand(){\r\n int min=0, max= MAXN;\r\n int random_int = (int)Math.floor(Math.random()*(max-min+1)+min);\r\n return random_int;\r\n }\r\n \r\n InputReader in; PrintWriter out;\r\n \r\n public void solve(InputReader in, PrintWriter out) {\r\n this.in=in; this.out=out;\r\n int t=in.nextInt();\r\n while(t-->0){\r\n solveA();\r\n }\r\n }\r\n public void solveA(){\r\n int n= in.nextInt(), k= in.nextInt();\r\n int[] a= in.nextIntArr(n);\r\n int[] b= new int[n];\r\n for(int i=0;i idx= new HashMap<>();\r\n for(int i=0;i m= new HashMap<>();\r\n public long base=0;\r\n public long totalValue=0;\r\n private int M= 1000000007;\r\n\r\n private long addMod(long a, long b){\r\n a+=b;\r\n if(a>=M) a-=M;\r\n return a;\r\n }\r\n\r\n public void reset(){\r\n m= new HashMap<>();\r\n base=0;\r\n totalValue=0;\r\n }\r\n public void update(long add){\r\n base= base+ add;\r\n }\r\n public void add(long key, long val){\r\n long newKey= key-base;\r\n m.put(newKey, addMod(m.getOrDefault(newKey,(long)0),val));\r\n }\r\n }\r\n\r\n\r\n\r\n static class Tuple implements Comparable{\r\n int x, y, z;\r\n public Tuple(int x, int y, int z){\r\n this.x= x;\r\n this.y= y;\r\n this.z=z;\r\n }\r\n @Override\r\n public int compareTo(Tuple o){\r\n return this.x-o.x;\r\n }\r\n }\r\n\r\n static class Pair implements Comparable{\r\n public int first;\r\n public int second;\r\n public Pair(int x, int y){\r\n this.first= x;\r\n this.second= y;\r\n }\r\n\r\n @Override\r\n public int compareTo(Pair o) {\r\n return this.first-o.first;\r\n }\r\n }\r\n\r\n // public static class compareL implements Comparator{\r\n // @Override\r\n // public int compare(Tuple t1, Tuple t2) {\r\n // return t2.l - t1.l;\r\n // }\r\n // }\r\n\r\n // fast input reader class;\r\n static class InputReader {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n public InputReader(InputStream stream) {\r\n br = new BufferedReader(new InputStreamReader(stream));\r\n }\r\n\r\n public String nextToken() {\r\n while (st == null || !st.hasMoreTokens()) {\r\n String line = null;\r\n try {\r\n line = br.readLine();\r\n } catch (IOException e) {\r\n throw new RuntimeException(e);\r\n }\r\n if (line == null) {\r\n return null;\r\n }\r\n st = new StringTokenizer(line);\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n public int nextInt() {\r\n return Integer.parseInt(nextToken());\r\n }\r\n public double nextDouble(){\r\n return Double.parseDouble(nextToken());\r\n }\r\n public long nextLong(){\r\n return Long.parseLong(nextToken());\r\n }\r\n public int[] nextIntArr(int n){\r\n int[] arr= new int[n];\r\n for(int i=0;i nextIntList(int n){\r\n List arr= new ArrayList<>();\r\n for(int i=0;i> nextIntMatList(int n, int m){\r\n List> mat= new ArrayList<>();\r\n for(int i=0;i temp= new ArrayList<>();\r\n for(int j=0;j0){\n\t\t\tans+=i%10;\n\t\t\ti/=10;\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic static long K(long i, int a){\n\t\tlong ans = 1;\n\t\tfor(int j =0;jr)return -1l;\n\t\tif(V(m)==0)return m;\n\t\telse if(K==1){\n\t\t\tif(V(m)>0)return search(l,m-1,K);\n\t\t\treturn search(m+1,r,K);\n\t\t}\n\t\tif(V(m)>0)return search(m+1,r,K);\n\t\treturn search(l,m-1,K);\n\t}\n\tpublic static void main(String [] args)throws IOException{\n\t\tScanner in = new Scanner(System.in);\n\t\tSystem.out.println();\n\t\ta= in.nextInt();\n\t\tb= in.nextInt();\n\t\tc= in.nextInt();\n\t\tList answer = new ArrayList();\n\t\t\n\t\t\n\t\tfor(int j = 1; j<=72;j++){\n\t\t\tif(j==s(V(j)))answer.add(V(j));\n\t\t\t//System.out.println(j+\": \"+V(j));\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\tSystem.out.println(answer.size());\n\t\tif(answer.size()>=1)System.out.print(answer.get(0));\n\t\tfor(int j=1;j 1) {\n\t\t\tint mid = (r+l)/2;\n\t\t\tif (mid == n) return n;\n\t\t\tif (mid > n) r = mid; else l = mid;\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tstatic void solve() throws IOException {\n\t\tBufferedReader in;\n\t\tPrintWriter out;\n\t\ttry {\n\t\t\tin = new BufferedReader(new FileReader(\"are1231a.in\"));\n\t\t\tout = new PrintWriter(new File(\"are2131a.out\"));\n\t\t} catch (Exception e) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t}\n\t\tStringTokenizer tok = new StringTokenizer(in.readLine());\n\t\tint a = Integer.valueOf(tok.nextToken());\n\t\tint b = Integer.valueOf(tok.nextToken());\n\t\tint c = Integer.valueOf(tok.nextToken());\n\t\tint mas[] = new int[100000000];\n\t\tint ind = 0;\n\t\tdouble tmp = 0;\n\t\tBigInteger bi;\n\t\tint res = 0;\n\t\tfor (int i = 0; i < 100; i++) {\n\t\t\tbi = new BigInteger(String.valueOf(i));\n\t\t\tres = num(0,1000000000,b*Integer.valueOf(bi.pow(a).toString())+c);\n\t\t\tif (res > 0) {\n\t\t\t\tmas[ind] = res;\n\t\t\t\tind++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint cnt = 0;\n\t\tfor (int i = 0; i < ind; i++) {\n\t\t\tbi = new BigInteger(String.valueOf(sum(mas[i]))).pow(a);\n\t\t\tif(mas[i] == b*Integer.valueOf(String.valueOf(bi.toString()))+c) {\n\t\t\t\tmas[cnt] = mas[i];\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(cnt+1);\n\t\tfor (int i = 0; i < cnt; i++) {\n\t\t\tSystem.out.print(mas[i]+\" \");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a44b489f7675feb6bde198fe4c0fe89", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class Main\n{\n public static void main(String srgs[])throws IOException\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String str[]=br.readLine().split(\" \");\n int a=Integer.parseInt(str[0]);\n int b=Integer.parseInt(str[1]);\n int c=Integer.parseInt(str[2]);\n long val=0,n=0;\n long dig=0;\n int index=0;\n long arr[]=new long[100000000];\n for(int i=1;i<=81;i++)\n {\n val=(long)Math.pow(i, a);\n val=val*b;\n val+=c;\n n=val;\n long sum=0;\n while(n>0)\n {\n dig=n%10;\n sum+=dig;\n n=n/10;\n }\n if(sum==i && val>0 && val<1000000000)\n {\n arr[index]=val;\n index++;\n // System.out.println(i+\" \"+val+\" \"+index);\n }\n }\n \n System.out.println(index);\n Arrays.sort(arr,0,index);\n if(index!=0)\n {\n for(int i=0;i list=new ArrayList();\n\t\tfor (int i = 0; i < ar.length; i++) {\n\t\t\tint r = pow(ar[i], a);\n\t\t//\tSystem.out.println(a+\" \"+ar[i]+\" \"+r);\n\t\tif(i==(r*b+c)) {\n\t\t\tlist.add(i);\n\t\t}\n\t\t}\n\t\tSystem.out.println(list.size());\n\tStringBuilder d=new StringBuilder();\n\t\tfor (Integer g:list) {\n\t\t\td.append(g+\" \");\n\t\t}\n\t\tSystem.out.println(d.toString().trim());\n\t}\n\n\tprivate static int pow(int i, int a) {\n\t\t// TODO Auto-generated method stub\n\t\tif (a == 0)\n\t\t\treturn 1;\n\t\tif (a == 1)\n\t\t\treturn i;\n\t\tint t = pow(i, a / 2);\n\t\tif (a % 2 == 0) {\n\t\t\treturn t * t;\n\t\t} else {\n\t\t\treturn t * t * i;\n\t\t}\n\t}\n\n\tprivate static int digitSum(int i) {\n\t\t// TODO Auto-generated method stub\n\t\tif (i == 0)\n\t\t\treturn 0;\n\t\treturn i % 10 + digitSum(i / 10);\n\t}\n\n\tstatic class Reader {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic Reader() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic Reader(String file_name) throws IOException {\n\t\t\tdin = new DataInputStream(new FileInputStream(file_name));\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String readLine() throws IOException {\n\t\t\tbyte[] buf = new byte[64]; // line length\n\t\t\tint cnt = 0, c;\n\t\t\twhile ((c = read()) != -1) {\n\t\t\t\tif (c == '\\n')\n\t\t\t\t\tbreak;\n\t\t\t\tbuf[cnt++] = (byte) c;\n\t\t\t}\n\t\t\treturn new String(buf, 0, cnt);\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.') {\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9') {\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\tfillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cf75ac59183974355de2c852ece4ca6e", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "package com.sachjain.codeforces;\n\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class PotionMaking {\n\n private static PrintWriter out = new PrintWriter(System.out);\n public static void main(String[] args) {\n\n try(Scanner myObj = new Scanner(System.in);) {\n int numberOfTests = Integer.parseInt(myObj.nextLine());\n for (int i = 0; i < numberOfTests; i++) {\n int concentration = Integer.parseInt(myObj.nextLine());\n out.println(getTotalVolume(concentration));\n }\n } finally {\n out.close();\n }\n }\n\n public static int getTotalVolume(int concentration) {\n if(100%concentration == 0) {\n return 100/concentration;\n }\n return 100;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce620d0287002e93c55f083335588ff7", "src_uid": "19a2bcb727510c729efe442a13c2ff7c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\nimport java.lang.*;\r\n\r\npublic class Main {\r\n //input\r\n static out op = new out();\r\n static inp ip = new inp();\r\n static FastReader sc = new FastReader();\r\n static BufferedWriter output = new BufferedWriter( \r\n new OutputStreamWriter(System.out));\r\n \r\n //HashMap map = new HashMap<>();\r\n\r\n // for(int i=0;i 0){\r\n sol();\r\n }\r\n op.output.flush();\r\n }\r\n\r\n static class Node /*implements Comparable*/{\r\n int data[] = new int[26];\r\n int val;\r\n Node left,right;\r\n Node(){\r\n left = null;\r\n right = null;\r\n }\r\n Node(char ch){\r\n left = null;\r\n right = null;\r\n }\r\n \r\n // @Override\r\n // // public int compareTo(Node o) {\r\n // // if(this.data == o.data)\r\n // // return this.ind - o.ind;\r\n // // // TODO Auto-generated method stub\r\n // // return o.data - this.data;\r\n // // }\r\n }\r\n}\r\n\r\n\r\nclass FastReader \r\n{ \r\n BufferedReader br; \r\n StringTokenizer st; \r\n\r\n public FastReader() \r\n { \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}\r\nclass inp{\r\n FastReader sc = new FastReader();\r\n int in(){\r\n int a = sc.nextInt();\r\n return a;\r\n }\r\n long lin(){\r\n long a = sc.nextLong();\r\n return a;\r\n }\r\n char cin(){\r\n char c = sc.next().charAt(0);\r\n return c;\r\n }\r\n char[] cain(){\r\n char[] a = sc.nextLine().toCharArray();\r\n return a;\r\n }\r\n int[] arrin(int n){\r\n int [] arr = new int[n];\r\n for(int i=0;i0){\r\n String[] firstLine = reader.readLine().split(\" \");\r\n int N = Integer.parseInt(firstLine[0]);\r\n System.out.println(100/gcd(100,N));\r\n cases--;\r\n\r\n }\r\n\t}\r\n}\r\n\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e8f08dd63c1d0e79636e142f61be15a", "src_uid": "19a2bcb727510c729efe442a13c2ff7c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import static java.lang.System.out;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n \n public static void main(String[] args) {\n Scanner scn = new Scanner(System.in);\n String s1 = scn.nextLine();\n String s2 = scn.nextLine();\n String s3 = scn.nextLine();\n String s4=s1.trim()+s2.trim();\n char[] s=s4.toCharArray();\n char[] ss=s3.toCharArray();\n Arrays.sort(s);\n Arrays.sort(ss);\n String sort1=new String(s);\n String sort2=new String(ss);\n if(sort1==sort2)\n {\n out.println(\"YES\");\n }else\n out.println(\"NO\");\n \n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8278fa1a53ef32fbd2f32e384759236b", "src_uid": "b6456a39d38fabcd25267793ed94d90c", "difficulty": 800.0} {"lang": "Java 8", "source_code": " import java.util.*;\n public class Main {\n public static void main(String[] args)\n { \n Scanner s = new Scanner(System.in);\n String word1 = s.nextLine().toUpperCase();\n String word2 = s.nextLine().toUpperCase();\n String word3 = s.nextLine().toUpperCase();\n\n// String words1and2 = word1 + word2;\n// char[] arr1 = words1and2.toCharArray();\n// Arrays.sort(arr1);\n// String sorted1 = String.valueOf(arr1);\n// char[] arr2 = word3.toCharArray();\n// Arrays.sort(arr2);\n// String sorted2 = String.valueOf(arr2);\n if((String.valueOf(word1) + String.valueOf(word2)).equals(String.valueOf(word3)))\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd867a1234c2b3c4117a2c0f25955226", "src_uid": "b6456a39d38fabcd25267793ed94d90c", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class amusingjoke {\n\tpublic static void main(String args[]) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tString s1 = scan.next();\n\t\tscan.nextLine();\n\t\ts1 += scan.next();\n\t\tscan.nextLine();\n\t\tString s2 = scan.next();\n\t\tif (s1.length() == s2.length()) {\n\t\t\tint len = s1.length();\n\t\t\tboolean bol = true;\n\t\t\tfor (int i = 0 ; i < len && bol ; i++) {\n\t\t\t\tif (!s1.contains(String.valueOf(s2.charAt(i))) && !s2.contains(String.valueOf(s1.charAt(i)))) {\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\tbol = false;\n\t\t\t\t}\n\t\t\t\telse {\n s1 = s1.replaceFirst(String.valueOf(s2.charAt(i)), \" \");\n s2 = s2.replaceFirst(String.valueOf(s1.charAt(i)), \" \");\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (bol) System.out.println(\"YES\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\t\n \n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1fe7eaf6ba39ad11a5e4ae3015714b00", "src_uid": "b6456a39d38fabcd25267793ed94d90c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class acm_zu_Test {\n \n public static void main(String[] args) {\n try \n {\n BufferedReader br =new BufferedReader( new InputStreamReader(System.in));\n StringTokenizer st=new StringTokenizer(br.readLine());\n \n String s=st.nextToken().toLowerCase();\n st=new StringTokenizer(br.readLine());\n String s2=st.nextToken().toLowerCase();\n st=new StringTokenizer(br.readLine());\n String sum=st.nextToken().toLowerCase();\n int freq[]=new int[26];\n for (int i = 0; i < sum.length(); i++) {\n if(s.length()>i)\n freq[s.charAt(i)-'a']++;\n if(s2.length()>i)\n freq[s2.charAt(i)-'a']++;\n if(sum.length()>i)\n freq[sum.charAt(i)-'a']--;\n }\n for (int i = 0; i < 26; i++) {\n if(freq[i]>0){\n System.out.println(\"NO\");return;}\n }\n System.out.println(\"YES\");\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n }\n \n catch (Exception ex)\n {\n System.out.println(ex.toString()); \n } \n }\n \n \n \n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "584141f11771ee70ce14d1e5894c2339", "src_uid": "b6456a39d38fabcd25267793ed94d90c", "difficulty": 800.0} {"lang": "Java 7", "source_code": "package round151Div2;\n\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n \n Scanner sc=new Scanner(System.in);\n int inputByte=sc.nextInt();\n if(inputByte<3) {\n System.out.print(-1);\n }\n else {\n for(int i=inputByte; i>0; i--){\n System.out.print(\" \"+i);\n } \n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1169e66c776fab4f6781345e27f9606b", "src_uid": "fe8a0332119bd182a0a5b7758716317e", "difficulty": 900.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\n/**\n *\n * @author sukhdeep\n */\npublic class Test {\n public static void main(String arg[]) throws IOException\n {\n BufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n \n int n=Integer.parseInt(r.readLine());\n\n if(n<=2)\n System.out.println(-1);\n else\n {\n for(int i=n;i>=1;i++)\n {\n System.out.print(i+\" \");\n }\n System.out.println();\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9e0f99e9b4954c41bd922db770c9dc15", "src_uid": "fe8a0332119bd182a0a5b7758716317e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class sorting{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n if(n<=2)\n System.out.println(-1);\n else\n {\n System.out.print(\"2 3 1\");\n for(int i = 0; i 0; i++) {\n\t\t\tSystem.out.print(i + \" \");\n\t\t}\n\t\tcin.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1cd2ebcbe545712a05cfa2b9e5af10ab", "src_uid": "fe8a0332119bd182a0a5b7758716317e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class SpecialOlympics {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int[] r, x, y;\n r = new int[4]; x = new int[4]; y = new int[4];\n x[0] = x[1] = sc.nextInt();\n y[0] = y[1] = sc.nextInt();\n r[0] = sc.nextInt(); r[1] = sc.nextInt();\n\n x[2] = x[3] = sc.nextInt();\n y[2] = y[3] = sc.nextInt();\n r[2] = sc.nextInt(); r[3] = sc.nextInt();\n\n int ans = 0;\n for (int cc = 0; cc < 4; cc++)\n {\n boolean ok = true;\n for (int i = 0; i < 4; i++)\n {\n if(i != cc)\n if(intersect(r[cc],r[i],x[cc],y[cc],x[i],y[i]))\n ok = false;\n }\n if(cc/2 == 0)\n {\n if(between(r[2], r[3], x[2], y[3], x[cc], y[cc], r[cc]))\n ok = false;\n }else if(between(r[0], r[1], x[1], y[1], x[cc], y[cc], r[cc]))\n ok = false;\n\n if(ok) ans++;\n }\n System.out.println(ans);\n }\n\n static double eps = 1e-9;\n\n public static boolean intersect(int r1, int r2, int x1, int y1, int x2, int y2)\n {\n double dist = Math.sqrt(sq(x1-x2)+ sq(y1-y2));\n if(dist > Math.abs(r1+r2)-eps || dist < Math.abs(r2-r1)+eps)\n return false;\n return true;\n }\n\n public static boolean between(int r1, int r2, int x1, int y1, int x2, int y2, int r)\n {\n double dist = Math.sqrt(sq(x1-x2)+ sq(y1-y2));\n boolean ret = dist < r- Math.min(r1, r2) + eps && dist < Math.max(r1,r2)-r + eps;\n ret |= (dist > r + Math.min(r1,r2)-eps && dist < Math.max(r1,r2) - r+eps);\n return ret;\n }\n\n public static int sq(int n)\n {\n return n*n;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "35e406c131b112820cfd762e1271a272", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "//package contest_125_div2;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.StreamTokenizer;\nimport java.io.Writer;\n/**\n * Date : Jul 8, 2012\n * Time : 1:37:33 PM\n * Email : denys.astanin@gmail.com\n */\n\npublic class B {\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew B().run();\n\t}\n\n\tint nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tString nextString() throws IOException {\n\t\tin.nextToken();\n\t\treturn (String) in.sval;\n\t}\n\n\tStreamTokenizer in;\n\tWriter writer;\n\tReader reader;\n\n\tvoid run() throws IOException {\n\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\treader = oj ? new InputStreamReader(System.in, \"ISO-8859-1\")\n\t\t\t\t: new FileReader(\"src/contest_125_div2/B.txt\");\n\t\twriter = new OutputStreamWriter(System.out, \"ISO-8859-1\");\n\t\tin = new StreamTokenizer(new BufferedReader(reader));\n\t\tPrintWriter out = new PrintWriter(writer);\n\t\tint x = nextInt();\n\t\tint y = nextInt();\n\t\tint r = nextInt();\n\t\tint R = nextInt();\n\t\t\n\t\tint x1 = nextInt();\n\t\tint y1 = nextInt();\n\t\tint r1 = nextInt();\n\t\tint R1 = nextInt();\n\t\tint count = 0;\n if (inside(x1, y1, r1, x, y, r) || outside(x1, y1, r1, x, y, R))\n \tcount++;\n if (inside(x1, y1, R1, x, y, r) || outside(x1, y1, R1, x, y, R))\n \tcount++;\n if (inside(x, y, r, x1, y1, r1) || outside(x, y, r, x1, y1, R1))\n \tcount++;\n if (inside(x, y, R, x1, y1, r1) || outside(x, y, R, x1, y1, R1))\n \tcount++;\n\t\tout.println(count);\n\t\tout.flush();\n\t\tout.close();\n\t}\n private boolean outside(int x1, int y1, int r1, int x2, int y2,\n int r2) {\n return (r1+r2)*(r1+r2) <= distance(x2, y2, x1, y1) || r1 >= r2 && distance(x2, y2, x1, y1) <= (r1-r2)*(r1-r2);\n }\n private boolean inside(int x1, int y1, int r1, int x2, int y2,\n int r2) {\n return distance(x2, y2, x1, y1) <= (r1-r2)*(r1-r2) && r1 <= r2;\n }\n\tlong distance(int x, int y, int x1, int y1) {\n\t\treturn (x - x1) * (x - x1) + (y - y1)*(y - y1);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6d3ac13115e84134b40985a95fb56eef", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.math.BigDecimal;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Yaski\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 TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskB {\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int x1, y1, ir1, or1;\n int x2, y2, ir2, or2;\n x1 = in.nextInt(); y1 = in.nextInt(); ir1 = in.nextInt(); or1 = in.nextInt();\n x2 = in.nextInt(); y2 = in.nextInt(); ir2 = in.nextInt(); or2 = in.nextInt();\n\n int dx = x2 - x1;\n int dy = y2 - y1;\n\n char cir1 = 1;\n char cor1 = 1;\n char cir2 = 1;\n char cor2 = 1;\n\n if (!checkVisibility(ir1, or1, dx, dy, ir2)) {\n cir2 = 0;\n }\n if (!checkVisibility(ir1, or1, dx, dy, or2)) {\n cor2 = 0;\n }\n if (!checkVisibility(ir2, or2, -dx, -dy, ir1)) {\n cir1 = 0;\n }\n if (!checkVisibility(ir2, or2, -dx, -dy, or1)) {\n cor1 = 0;\n }\n\n if (checkIntersection(dx, dy, or1, or2)) {\n cor1 = cor2 = 0;\n }\n if (checkIntersection(dx, dy, or1, ir2)) {\n cor1 = cir2 = 0;\n }\n if (checkIntersection(dx, dy, ir1, or2)) {\n cir1 = cor2 = 0;\n }\n if (checkIntersection(dx, dy, ir1, ir2)) {\n cir1 = cir2 = 0;\n }\n\n out.println(cir1 + cir2 + cor1 + cor2);\n }\n\n private boolean checkVisibility(int inner, int outer, int dx, int dy, int radius) {\n int sum1 = outer - radius;\n if (sum1 > 0 && (dx*dx + dy*dy) <= sum1*sum1) {\n int sum2 = inner + radius;\n int sum3 = radius - inner;\n return ((dx*dx + dy*dy) < sum2*sum2) && (sum3 < 0 || ((dx*dx + dy*dy) > sum3*sum3));\n }\n return true;\n }\n\n private boolean checkIntersection(int dx, int dy, int radius1, int radius2) {\n int sum1 = radius1 - radius2;\n int sum2 = radius1 + radius2;\n return (((dx*dx + dy*dy) > sum1*sum1) && ((dx*dx + dy*dy) < sum2*sum2));\n }\n\n}\n\nclass FastScanner {\n\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public FastScanner(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String nextLine() {\n tokenizer = null;\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa3781191522f757369d77659c3244ff", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main\n\t{\n\tpublic static void main(String args[]) throws IOException\n\t\t{\n\t\tScanner c=new Scanner(System.in);\n\t\tint x1=c.nextInt();\n\t\tint y1=c.nextInt();\n\t\tint r1=c.nextInt();\n\t\tint R1=c.nextInt();\n\t\t\n\t\tint x2=c.nextInt();\n\t\tint y2=c.nextInt();\n\t\tint r2=c.nextInt();\n\t\tint R2=c.nextInt();\n\t\t\n\t\tint ans=0;\n\t\tif(!intersects(x1,y1,r1,x2,y2,r2,R2))\n\t\t\tans++;\n\t\tif(!intersects(x1,y1,R1,x2,y2,r2,R2))\n\t\t\tans++;\n\t\tif(!intersects(x2,y2,r2,x1,y1,r1,R1))\n\t\t\tans++;\n\t\tif(!intersects(x2,y2,R2,x1,y1,r1,R1))\n\t\t\tans++;\n\t\tSystem.out.println(ans);\n\t\t}\n\n\tprivate static boolean intersects(int x1,int y1,int R1,int x2,int y2,int r2,int R2)\n\t\t{\n\t\t//System.out.println(\"testing: \"+x1+\" \"+y1+\" \"+R1 +\" with \"+\" \"+x2+\" \"+y2+\" \"+r2+\" \"+R2);\n\t\tint dc=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);\n\t\t//System.out.println(\"dc= \"+dc);\n\t\t//System.out.println(\"T1= \"+(R1+R2)*(R1+R2));\n\t\t//System.out.println(\"T2= \"+(Math.abs(R1-r2)*Math.abs(R1-r2)));\n\t\tif(dc>=(R1+R2)*(R1+R2)||(dc<=(Math.abs(R1-r2)*Math.abs(R1-r2))&&R1<=r2)||(dc<=(Math.abs(R1-R2)*Math.abs(R1-R2))&&R2<=R1))\n\t\t\t{\n\t\t\t//System.out.println(\"false\");\n\t\t\treturn false;\n\t\t\t}\n\t\t//System.out.println(\"true\");\n\t\treturn true;\n\t\t}\n\t}\n\n//must declare new classes here", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b73b4ad16baac151157fb4f17448da4e", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class ACarrotCakes {\n\n \n public static void main(String[] args) {\n\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();//number of carrots to complete the task\n int t = input.nextInt();//minutes to bake by one oven\n int k = input.nextInt();//num of carrots cake\n int d = input.nextInt();//minutes to build another oven\n int q=0;\n int w=0;\n if(n<=k)\n {\n System.out.println(\"NO\");\n }\n else if(t==d)\n {\n System.out.println(\"NO\");\n\n }\n else if(n>k)\n {\n while(true)\n {\n q+=t;\n w+=k;\n if(w==n){break;}\n }\n if(t+d 1000 || n < 1) return;\n t = sc.nextInt(); if(t > 1000 || t < 1) return;\n k = sc.nextInt(); if(k > 1000 || k < 1) return;\n d = sc.nextInt(); if(d > 1000 || d < 1) return;\n int i = 2;\n int t1 = t;\n int t0 = t;\n int t2 = t;\n int k_copy = k;\n if(k > n) System.out.println(\"NO\");\n else\n {\n while(k < n)\n {\n k = k * i;\n t = t * i;\n i++;\n }\n i=2;\n if (t1 == d) \n { \n System.out.println(\"NO\");\n return;\n }\n else if(t1>d)\n {\n t2 = t1 - d;\n t2 = t1 - t2;\n while (k_copy < n)\n {\n t2 = t2 + t0;\n k_copy = k_copy * i;\n i++;\n } \n }\n else\n {\n t2 = d - t1;\n t2 = d - t2;\n while (k_copy < n)\n {\n t2 = t2 + t0;\n k = k * i;\n i++;\n }\n }\n if(t2 < t) System.out.print(\"YES\");\n else System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f5eabdcbd0b296fe86e1d84d5e3f8b8e", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Sheet_Cakes\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n //1) 8 - 6 - 4 - 5\n // 12\n // 11\n int n, t, k, d;\n n = sc.nextInt(); if(n > 1000 || n < 1) return;\n t = sc.nextInt(); if(t > 1000 || t < 1) return;\n k = sc.nextInt(); if(k > 1000 || k < 1) return;\n d = sc.nextInt(); if(d > 1000 || d < 1) return;\n int i = 2;\n int t1 = t;\n int t0 = t;\n int t2 = t;\n int k_copy = k;\n if(k > n) System.out.println(\"NO\");\n else\n {\n while(k < n)\n {\n k = k * i;\n t = t * i;\n i++;\n }\n i = 2;\n if (t1 == d) \n { \n System.out.println(\"NO\");\n return;\n }\n else if(t1>d)\n {\n t2 = t1 - d;\n while (k_copy < n)\n {\n t2 = t2 + t0;\n k = k * i;\n i++;\n } \n }\n else\n {\n t2 = d - t1;\n while (k_copy < n)\n {\n t2 = t2 + t0;\n k = k * i;\n i++;\n }\n }\n t2 = t0 + t2;\n System.out.println(t2 + \"\\n\" + t);\n if(t2 < t) System.out.print(\"YES\");\n else System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6a2927716bdab0279e7e8d7c6afb0b9b", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CarrotCakes {\n\n public static void main(String[] args) {\n\tScanner input = new Scanner(System.in);\n\t\n\tint n = input.nextInt(),t = input.nextInt() , k = input.nextInt() , d = input.nextInt();\n\t\n\tint oven = 0 ;\n\tboolean oven2 = false;\n\t\n\tint count = 0 ;\n\tint still = 0 ;\n\t\n\tif(!( n < k)){\n\twhile( n != 0)\n\t{\n\t oven = k ;\n\t \n\t still = n - k ;\n\t n = n - k ;\n\t count = count + t;\n\t if( count > d && still > 0)\n\t {\n\t\toven2 = true;\n\t }\n\t}\n\t}\n\t\n\tSystem.out.println((oven2? \"YES\" : \"NO\"));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e4f38b219b72fd77183c5a5c64d64367", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.stream.Collectors;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int count = Integer.valueOf(scanner.nextLine());\n List numbers = Arrays.stream(scanner.nextLine().split(\" \")).map(Integer::valueOf).collect(Collectors.toList());\n int resultCount = 0;\n int localCount = 0;\n for (int i = 0; i < count - 1; i++) {\n if (numbers.get(i + 1) - numbers.get(i) == 1) {\n localCount++;\n } else {\n if (localCount != 0) {\n resultCount += localCount - 1;\n }\n localCount = 0;\n }\n }\n if (localCount != 0) {\n resultCount += localCount - 1;\n }\n if (numbers.get(0) == 1 && numbers.get(1) == 2) resultCount++;\n if (numbers.get(numbers.size() - 1) == 1000 && numbers.get(numbers.size() - 2) == 999) resultCount++;\n System.out.println(resultCount);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c982acba3eccdb35ad80bb876ab7c97c", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class first {\n\tpublic static void main(String args[]){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint a = scan.nextInt();\n\t\tint [] ar = new int [a];\n\t\tint count = 0;\n\t\tfor (int i = 0; i< a; i++){\n\t\t\tint b = scan.nextInt();\n\t\t\tar[i] = b;\n\t\t\t\n\t\t\t\n\t\t}\n\t\tfor (int i = 1; i< a; i++){\n\t\t\tif (ar[i] == ar[i-1]+ 1 ){\n\t\t\t\tcount ++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (ar[a-1] != ar[a-2] +1){\n\t\t\tcount --;\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7f78f3ea1311886f7bffec270f64a45", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\nimport java.util.*;\n\n\npublic class Soly\n{\n static final int INF = Integer.MAX_VALUE;\n\n static void mergeSort(int[] a,int [] c, int b, int e)\n {\n if(b < e)\n {\n int q = (b + e) >>1;\n mergeSort(a,c, b, q);\n mergeSort(a, c,q + 1, e);\n merge(a,c, b, q, e);\n }\n }\n\n\n static void merge(int[] a,int[]c, int b, int mid, int e)\n {\n int n1 = mid - b + 1;\n int n2 = e - mid;\n int[] L = new int[n1+1], R = new int[n2+1];\n int[] L1 = new int[n1+1], R1 = new int[n2+1];\n\n for(int i = 0; i < n1; i++) {\n L[i] = a[b + i];\n L1[i] = c[b + i];\n }\n for(int i = 0; i < n2; i++) {\n R[i] = a[mid + 1 + i];\n R1[i] = c[mid + 1 + i];\n }\n L[n1] = R[n2] = INF;\n\n for(int k = b, i = 0, j = 0; k <= e; k++)\n if(L[i] <= R[j]){\n a[k] = L[i];\n c[k] = L1[i++];\n }\n\n else\n {\n a[k] = R[j];\n c[k] = R1[j++];\n }\n }\n static int s;\n static Stack sta;\nstatic int type(char[] a){\n sta= new Stack<>();\n s=0;\n int op=0,cl=0;\n for (int i = 0; i < a.length; i++) {\n if (a[i]==')'){\n if (!sta.isEmpty()&&sta.peek()=='('){\n op--;\n sta.pop();\n }\n else{\n cl++;\n sta.push(')');\n }\n }\n else{\n op++;\n sta.push('(');\n }\n }\n if (sta.isEmpty())return 0;\n else{\n s=sta.size();\n //1 --> closing\n //2 -->opening\n if (op>0&&cl>0)return 50;\n else{\n if (op>0)return 2;\n return 1;\n }\n\n }\n}\n\n\n\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n try (PrintWriter or = new PrintWriter(System.out)) {\n int n = in.nextInt();\n int[] a= new int[n];\n int max=0;\n \n for (int i = 0; i < n; i++) a[i]=in.nextInt();\n if (a[1]-a[0]==1&&n==2&&a[1]!=1000){\n or.println(0);return;\n }\n for (int i = 0; i < n; i++) {\n for (int j = i,p=n-1; p>j ; --p) {\n if (a[p]-a[i]==p-i){\n if (p==n-1&&i==0) max=Math.max(max,p-i);\n else max=Math.max(max,p-i-1);\n }\n }\n }\n or.println(max);\n\n }\n }\n\n\n\n\n\n\n\n\n\n\n static class Scanner {\n\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public 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 String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n String x = next();\n StringBuilder sb = new StringBuilder(\"0\");\n double res = 0, f = 1;\n boolean dec = false, neg = false;\n int start = 0;\n if (x.charAt(0) == '-') {\n neg = true;\n start++;\n }\n for (int i = start; i < x.length(); i++) {\n if (x.charAt(i) == '.') {\n res = Long.parseLong(sb.toString());\n sb = new StringBuilder(\"0\");\n dec = true;\n } else {\n sb.append(x.charAt(i));\n if (dec) {\n f *= 10;\n }\n }\n }\n res += Long.parseLong(sb.toString()) / f;\n return res * (neg ? -1 : 1);\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n }\n\n\n\n}\nclass coooo {\n String s;\n int cnt;\n int type;\n\n\n public coooo(String s, int cnt,int t) {\n this.s = s;\n this.cnt = cnt;\n this.type=t;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a25a01c39a83e9ee3bc10be19594faa3", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\npublic class APrank {\n\t/**\n\t * @param args\n\t * @throws IOException\n\t * @throws InterruptedException\n\t */\n\tpublic static void main(String[] args) throws IOException, InterruptedException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint []a=new int [n];\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tfor(int i=0;st.hasMoreTokens();i++)\n\t\t\ta[i]=Integer.parseInt(st.nextToken());\n\t\tif(a[n-1]==n)\n\t\t\tSystem.out.println(n-1);\n\t\telse\n\t\t{\n\t\t\tint len=n;\n\t\t\tint srt=0;\n\t\t\tint end=n;\n\t\t\tint max=0;\n\t\t\tint saver=0;\n\t\t\tint tmp=0;\n\t\t\twhile(true)\n\t\t\t{\t max=0;\n\t\t\t\tboolean flag=true;\n\t\t\t\tfor(int i=srt+1;i1)\n\t\t\t\t\t\tif(a[saver]==1000)\n\t\t\t\t\t\t\tmax++;\n\t\t\t\t\tif(n>1)\n\t\t\t\t\t\tif(a[srt+1]==2)\n\t\t\t\t\t\t\tmax++;\n\t\t\t\t\tif(max>tmp)\n\t\t\t\t\t\ttmp=max;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tif(end==n)\n\t\t\t\t{\n\t\t\t\t\tlen--;\n\t\t\t\t\tsrt=0;\n\t\t\t\t\tend=len;\n\t\t\t\t\tif(len==1)\n\t\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\tsrt++;\n\t\t\t\t\tend++;\n\t\t\t\t}\n\t\t\t}\n\t\tSystem.out.println(tmp>=0?tmp:0);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a95f77739026111ef98aa4287affb18", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "package Demo;\n\nimport java.util.Scanner;\n\npublic class Test {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner input = new Scanner(System.in);\n\t\tString Word = input.next();\n\t\tint Length = Word.length();\n\t\tint i=0;\n\t\t\n\t\tfor(i=0;il)\n\t\tSystem.out.print(2*(l+a));\n\t\t else if(rl)\n\t\tSystem.out.print(2*(r+a));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa2806d8ed0eb28793859b891a88d5a8", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class b1 {\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint n = in.nextInt();\n\t\t\n\t\tint a[] = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\t\n\t\tlong ans = 0;\n\t\tlong cur = a[n - 1] + 1;\n\t\t\n\t\tfor (int i = n - 1; i > -1; i--) {\n\t\t\tif (cur > a[i]){\n\t\t\t\tcur = a[i];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcur--;\n\t\t\t}\n\t\t\t\n\t\t\tans += cur;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2283db33b93b0fc5b3b7ce6d364138f4", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0} {"lang": "Java 7", "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.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 T.C.D\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInputReader in = new FastInputReader(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, FastInputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n\n Arrays.sort(a);\n long ans = a[n - 1];\n for (int i = n - 2; i >= 0; i--) {\n int min = Math.min(a[i], a[i + 1] - 1);\n ans += min;\n a[i] = min;\n }\n out.println(ans);\n }\n\n }\n\n static class FastInputReader {\n static InputStream is;\n static private byte[] buffer;\n static private int lenbuf;\n static private int ptrbuf;\n\n public FastInputReader(InputStream stream) {\n is = stream;\n buffer = new byte[1024];\n lenbuf = 0;\n ptrbuf = 0;\n }\n\n private int readByte() {\n if (lenbuf == -1)\n throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(buffer);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0)\n return -1;\n }\n return buffer[ptrbuf++];\n }\n\n public int nextInt() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ff305f423d686cf8d4331f5eafe3718a", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args)throws IOException{\n\t\tPrintWriter pw = new PrintWriter(System.out);\n InputReader in = new InputReader(System.in);\n int n = in.nextInt();\n int[] a = new int[n];\n for(int i=0;i=0;i--){\n \twhile(a[i]>=last){\n \t\ta[i]--;\n \t}\n \tlast = a[i];\n \tsum+=a[i];\n \tif(last==1){\n \t\tbreak;\n \t}\n \t\n }\n \n pw.println(sum);\n pw.close();\n\t}\n\nstatic class InputReader {\n\t\t \n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[8192];\n\t\tprivate int curChar;\n\t\tprivate int snumChars;\n\t\tprivate SpaceCharFilter filter;\n \n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n \n\t\t\tint res = 0;\n \n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n \n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n \n\t\t\tlong res = 0;\n \n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n \n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "95fe6e6ac75b8603cd7dcaea6c33c6a3", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n/**\n * Created by mohannadhassan on 2/4/16.\n */\npublic class MakingString {\n\n public static void main(String [] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n String[] input = br.readLine().split(\" \");\n\n int []array = new int[n];\n for (int i = 0; i < n; i++) {\n array[i] = Integer.parseInt(input[i]);\n }\n\n java.util.Arrays.sort(array);\n\n long total = array[n - 1];\n int max = array[n - 1];\n\n for (int i = n - 2; i >= 0; i--) {\n int num;\n if (array[i] < max)\n num = array[i];\n else\n num = max - 1;\n total += num;\n max = num;\n }\n\n System.out.println(total);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "67fd498d25204cb5b73e9a34df5dc531", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class coder {\n\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint m = in.nextInt();\n\t\tint s = in.nextInt();\n\t\t\n\t\tif(s == 0 && m != 1 || s > 9*m){\n\t\t\tSystem.out.println(-1 + \" \" + -1);\n\t\t}else if(m == 1 && s > 9){\n\t\t\tSystem.out.println(0 + \" \"+0);\n\t\t}else{\n\t\t\tString min = \"\";\n\t\t\tString max = \"\";\n\t\t\tint t = 0;\n\t\t\tint n =s;\n\t\t\t\n\t\t\twhile(s >= 9){\n\t\t\t\tmax = max +'9';\n\t\t\t\ts -= 9;\n\t\t\t\tt++;\n\t\t\t}\n\t\t\t\n\t\t\tif(t < m){\n\t\t\t\tmax += (char)(s%10 + '0');\n\t\t\t\tt++;\n\t\t\t}\n\t\t\t\n\t\t\twhile(t < m){\n\t\t\t\tmax = max +'0';\n\t\t\t\tt++;\n\t\t\t}\n\t\t\t\n\t\t\tt =0;\n\t\t\ts = n;\n\t\t\twhile(s >= 9){\n\t\t\t\tmin = '9' + min;\n\t\t\t\ts -= 9;\n\t\t\t\tt++;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tif(t < m){\n\t\t\t\tmin = (char)(s%10 + '0') + min;\n\t\t\t\tt++;\n\t\t\t}\n\t\t\t\n\t\t\twhile(t < m){\n\t\t\t\tmin = '0'+min;\n\t\t\t\tt++;\n\t\t\t}\n\t\t\t\n\t\t\tif(min.charAt(0) == '0'){\n\t\t\t\t\n\t\t\t\tint k = 1;\n\t\t\t\tif(k < m){\n\t\t\t\t\twhile(k < m && min.charAt(k) == '0'){\n\t\t\t\t\t\tk++;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tString temp = min.substring(1,k);\n\t\t\t\t\tString tem2 = min.substring(k+1);\n\t\t\t\t\t\n\t\t\t\t\tmin = '1' + temp + (char)(min.charAt(k)-1) + tem2;\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\tSystem.out.println(min + \" \" + max);\n\t\t\t\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e224f9516b39e0c9bb7ca777fd8b80ac", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Solution {\n\n public static void main(String args[]){\n\n Scanner scn = new Scanner(System.in);\n int m = scn.nextInt();\n int s = scn.nextInt();\n\n // long mnum = 0;\n StringBuilder mnum = new StringBuilder();\n int sum = s;\n ArrayList list = new ArrayList<>();\n\n while(sum > 0){\n for(int i = 9 ; i >= 0 ; i--){\n if(sum - i >= 0){\n list.add(i);\n sum-= i;\n break;\n }\n }\n }\n\n if(list.size() == 0 || list.get(0) == 0){\n if(m == 0){\n System.out.println(0 + \" \" + 0);\n return;\n }\n else{\n System.out.println(-1 + \" \" + -1);\n return;\n }\n }\n\n while(list.size() != m){\n list.add(0);\n }\n\n for(int i : list){\n // mnum = mnum * 10 + i;\n // System.out.println(i);\n mnum.append(i);\n }\n // long minnum = 0;\n StringBuilder minnum = new StringBuilder();\n if(list.get(list.size() - 1) != 0){\n for(int i = list.size() - 1 ; i >= 0 ; i--){\n // minnum = minnum * 10 + list.get(i);\n minnum.append(list.get(i));\n }\n }else{\n for(int i = list.size() - 1 ; i>= 0 ; i--){\n if(list.get(i) > 0){\n list.set(i , list.get(i) - 1);\n break;\n }\n }\n\n minnum.append(1);\n for(int i = list.size() - 2 ; i >= 0 ; i--){\n // minnum = minnum*10 + list.get(i);\n minnum.append(list.get(i));\n }\n }\n\n System.out.println(minnum +\" \" + mnum);\n\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60bb6ee1c7684d13bd1f07dded143225", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution4 {\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int m = in.nextInt(); //length\n int s = in.nextInt(); //sum\n int[] abb = new int[10];\n if(s == 0 && m == 1){\n System.out.println(\"0 0\");\n return;\n }\n else if(s == 0 && m > 1){\n System.out.println(\"-1 -1\");\n return;\n }\n StringBuilder a = new StringBuilder();\n StringBuilder w = new StringBuilder();\n while(s != 0 || a.length() != m){\n if(s >= 9){\n a.append(\"9\");\n s-=9;\n abb[9]++;\n continue;\n }\n else if(s < 9 && s >= 0){\n a.append(s);\n w.append(s);\n abb[s]++;\n s = 0;\n continue;\n }\n else{\n a.append(\"0\");\n w.append(\"0\");\n abb[0]++;\n }\n }\n String largest = a.toString();\n for(int i = 0; i < abb[9]; i++){\n w.append(9);\n }\n System.out.println(w + \" \" + largest);\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "254bbaab4873a451f67165da38d85e52", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class GivenLengthAndSumDigit {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int s=sc.nextInt();\n StringBuilder sb1=new StringBuilder();\n StringBuilder sb2=new StringBuilder();\n \n if((s==0 && n!=1) || 9*n=9)\n {\n if(s>=9)\n {\n sb1.append(9);\n sb2.append(9);\n s-=9;\n }\n }\n sb2.append(s);\n int k=n-sb2.length();\n while(k>0)\n {\n sb2.append(0);\n k--;\n }\n if(n-1==sb1.length())\n {\n sb1.append(s);\n }\n else\n sb1.append(s-1);\n int l=n-sb1.length();\n while(l>1)\n sb1.append(0);\n if(l==1)\n {\n sb1.append(1);\n }\n sb1.reverse();\n System.out.println(sb1+\" \"+sb2);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e3933f82e505ff9fba368822cf0e4f53", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class B {\n\tstatic long n;\n\tstatic long a;\n\tstatic long b;\n\n\tstatic long mi1 = 1;\n\tstatic long mi2 = Long.MAX_VALUE;\n\tstatic long []memo;\n\n\tstatic long calc(long i, long j) {\n\t\tif (6 * n <= (long) ((long) i * j)) {\n\t\t\tif ((long) i * j < (long) mi1 * mi2) {\n\t\t\t\tmi1 = i;\n\t\t\t\tmi2 = j;\n\t\t\t}\n\t\t\treturn (long)((long)i * j);\n\t\t}\n\t\tlong option1 = calc(i, j + 1);\n\t\tlong option2 = calc(i + 1, j);\n\t\treturn Math.min(option1, option2);\n\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextLong();\n\t\ta = sc.nextLong();\n\t\tb = sc.nextLong();\n\t\tSystem.out.println(calc(a, b));\n\t\tSystem.out.println(mi1 + \" \" + mi2);\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "98fd148c5b35e970341e35790d9cc1fe", "src_uid": "6a2a584d36008151d18e5080aea5029c", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "package olimpiad.B;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * Created by myduomilia on 12.09.14.\n */\npublic class Main {\n static class FastReadWriteConsole {\n\n BufferedReader in;\n StringTokenizer tok;\n PrintWriter out;\n\n public FastReadWriteConsole() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n\n private String readToken() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(readToken());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(readToken());\n }\n\n public String nextString() throws IOException {\n return readToken();\n }\n\n public void print(Object obj){\n out.print(obj.toString());\n }\n\n public void close() throws IOException {\n in.close();\n out.close();\n }\n\n }\n\n public static void main(String[] args) throws IOException {\n FastReadWriteConsole console = new FastReadWriteConsole();\n long n = console.nextLong() * 6;\n long a = console.nextLong();\n long b = console.nextLong();\n if(b < a){\n long tmp = b;\n b = a;\n a = tmp;\n }\n if(a >= 78000 && b >= 78000){\n console.print(a * b + \"\\n\");\n console.print(a + \" \" + b);\n }else {\n long ans = 10L * (long)Integer.MAX_VALUE;\n long ansA = 0;\n long ansB = 0;\n for(long i = a; i < 78000; i++){\n long l = b, r = 10L * (long)Integer.MAX_VALUE;\n while (l < r) {\n long mid = l + (r - l) / 2;\n if (mid * i >= n) {\n r = mid;\n } else {\n l = mid + 1;\n }\n }\n for(long j = l - 5; j < l + 5; j++){\n if(j * i >= n && j * i <= ans && j >= b && i >= a ){\n// if(j - b == 0 || i - a == 0 || (j - b == i - a)){\n ans = j * i;\n ansA = i;\n ansB = j;\n// }\n }\n }\n }\n console.print(ans + \"\\n\");\n console.print(ansA + \" \" + ansB);\n }\n console.close();\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a1c460f0917dbef61afe3d99e586be4a", "src_uid": "6a2a584d36008151d18e5080aea5029c", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n // main\n public static void main(String [] args) throws IOException {\n // makes the reader and writer\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n \n // read in n,a,b\n StringTokenizer st = new StringTokenizer(f.readLine());\n int n = Integer.parseInt(st.nextToken());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n \n // area already big enough\n if (a*b>=6*n) {\n out.println((long) a*b);\n out.println(a+\" \"+b);\n } else {\n boolean aBig = true;\n if (a=a && min>i*((6*n-1)/i+1)) {\n min = i*((6*n-1)/i+1);\n best = i;\n }\n }\n out.println(min);\n if (aBig) out.println(((6*n-1)/best+1)+\" \"+best);\n else out.println(best+\" \"+((6*n-1)/best+1));\n }\n \n // cleanup\n out.close();\n System.exit(0);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c4f3071d9de837071738e1bc91397d22", "src_uid": "6a2a584d36008151d18e5080aea5029c", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n // main\n public static void main(String [] args) throws IOException {\n // makes the reader and writer\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n \n // read in n,a,b\n StringTokenizer st = new StringTokenizer(f.readLine());\n long n = Long.parseLong(st.nextToken());\n long a = Long.parseLong(st.nextToken());\n long b = Long.parseLong(st.nextToken());\n \n // area already big enough\n if (a*b>=6*n) {\n out.println(a*b);\n out.println(a+\" \"+b);\n } else {\n boolean aBig = true;\n if (a=a && min>i*((6*n-1)/i+1)) {\n min = i*((6*n-1)/i+1);\n best = i;\n }\n }\n out.println(min);\n if (aBig) out.println(((6*n-1)/best+1)+\" \"+best);\n else out.println(best+\" \"+((6*n-1)/best+1));\n }\n \n // cleanup\n out.close();\n System.exit(0);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2aaa295a5f47566ca957f970f4422d6", "src_uid": "6a2a584d36008151d18e5080aea5029c", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\t\n\tfinal String fname = \"\";\n\t\n\tpublic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint count [] = new int [2];\n\t\tint ret = max (n , m);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint start = 1;\n\t\t\tif (i % 2 == 0) start = 0;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tcount [start]++;\n\t\t\t\tstart ^= 1;\n\t\t\t}\n\t\t}\n\t\tret = max (ret, max(count[0], count[1]));\n\t\tout.println(ret);\n\t}\n\t\n\t\t\n\t/********************************************************************************************/\n\t/* THERE IS INPUT */\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tlong stime=0;\n\t\n\tprivate String next() throws Exception {\n\t\twhile (st == null || !st.hasMoreElements())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tprivate int nextInt() throws Exception {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate long nextLong() throws Exception {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\t//Locale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\t//in = new BufferedReader(new FileReader(fname+\".in\"));\n\t\t\t//out = new PrintWriter(new FileWriter(fname+\".out\"));\n\t\t\tsolve();\n\t\t} catch (Exception ex) {\n\t\t\tthrow new RuntimeException(ex);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Thread(null, new Solution(), \"\", 1 << 25).start();\n\t}\n\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2b86a14d2c3e4b211916f540987192e2", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedInputStream;\nimport java.util.Scanner;\n\npublic class HelpGeneral { //Round #102 - Help General\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(new BufferedInputStream(System.in));\n\t\t\n\t\tint numRows = sc.nextInt();\n\t\tint numCols = sc.nextInt();\n\t\t\n\t\tlong horizontal = numCols * (numRows / 4 + 1);\n\t\tlong vertical = numRows * (numCols / 4 + 1);\n\t\t\n\t\tlong numRowsHalf = numRows / 2;\n\t\tlong numColsHalf = numCols / 2;\n\t\t\n\t\tlong other = (numRows - numRowsHalf) * (numCols - numColsHalf) + numRowsHalf * numColsHalf;\n\t\t\n\t\t//System.out.println(horizontal + \" \" + vertical + \" \" + other);\n\t\t\n\t\tSystem.out.println(Math.max(Math.max(horizontal, vertical), other));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6979b6aa40796db6bf26c65d3912108", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class TaskB {\n\tvoid Run() throws IOException {\n\t\tint n=ReadInt(), m=ReadInt();\n\t\tif(n>=m) {\n\t\t\tint x=n;\n\t\t\tn=m;\n\t\t\tm=x;\n\t\t}\n\t\tif(n==1) {\n\t\t\toutput.println(m);\n\t\t\treturn;\n\t\t}\n\t\tif(n==2) {\n\t\t\toutput.println(Math.max(4, m));\n\t\t\treturn;\n\t\t}\n\t\tif(n%2==0 || m%2==0) {\n\t\t\toutput.println(n*m/2);\n\t\t\treturn;\n\t\t}\n\t\toutput.println(n*m/2+1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tReader reader;\n\t\treader=oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n\t\tinput=new BufferedReader(reader);\n\t\tWriter writer=new OutputStreamWriter(System.out);\n\t\twriter=new BufferedWriter(writer);\n\t\toutput=new PrintWriter(writer);\n\t\tnew TaskB().Run();\n\t\toutput.close();\n\t}\n\t\n\tstatic int ReadInt() throws IOException {\n\t\treturn Integer.parseInt(ReadString());\n\t}\n\t\n\tstatic long ReadLong() throws IOException {\n\t\treturn Long.parseLong(ReadString());\n\t}\n\t\n\tstatic String ReadString() throws IOException {\n\t\twhile(tokenizer==null || !tokenizer.hasMoreTokens())\n\t\t\ttokenizer=new StringTokenizer(input.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\t\n\tstatic StringTokenizer tokenizer;\n\tstatic BufferedReader input;\n\tstatic PrintWriter output;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b5a27a7687d7e9e0eba495568941800e", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class B implements Runnable{\n \n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n \n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n \n void init() throws FileNotFoundException{\n if (ONLINE_JUDGE){\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }else{\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n \n String readString() throws IOException{\n while(!tok.hasMoreTokens()){\n try{\n tok = new StringTokenizer(in.readLine());\n }catch (Exception e){\n return null;\n }\n }\n return tok.nextToken();\n }\n \n int readInt() throws IOException{\n return Integer.parseInt(readString());\n }\n \n long readLong() throws IOException{\n return Long.parseLong(readString());\n }\n \n double readDouble() throws IOException{\n return Double.parseDouble(readString());\n }\n \n public static void main(String[] args){\n new Thread(null, new B(), \"\", 256 * (1L << 20)).start();\n }\n \n long timeBegin, timeEnd;\n\n void time(){\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n \n long memoryTotal, memoryFree;\n \n\n void memory(){\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10) + \" KB\");\n }\n \n void debug(Object... objects){\n if (DEBUG){\n for (Object o: objects){\n System.err.println(o.toString());\n }\n }\n }\n \n public void run(){\n try{\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().totalMemory();\n init();\n solve();\n out.close();\n time();\n memory();\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n \n boolean DEBUG = false;\n \n void solve() throws IOException{\n int n = readInt();\n int m = readInt();\n \n if (n == 1){\n out.print(m);\n return;\n }\n \n if (m == 1){\n out.print(n);\n return;\n }\n \n if (n == 2 && m == 2){\n out.print(4);\n return;\n }\n \n int count = n * m + (n * m) % 2;\n out.print(count / 2);\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c1d121de89ef1428f7c00c0036f588e6", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class CF746A {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint m = Integer.parseInt(br.readLine());\n\t\tint c = Integer.parseInt(br.readLine());\n\t\tint sum = 0;\n\t\tint i;\n\t\tfor (i = 1; i <= n; i++) {\n\t\t\tif(i*2 > m || i*4 > c)\n\t\t\t\t{\n\t\t\t\tsum += (i-1)+(i-1)*2+(i-1)*4;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tSystem.out.println(sum);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9d1746b591e0198df34d6e3ef82eca88", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Codeforce {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int sum = 0;\n int target = a;\n boolean hello = false;\n while (target>=1){\n boolean flag = false;\n if(target*4>=c){\n flag = true;\n }\n if(target*2>=b){\n flag = true;\n }\n if(!flag){\n sum+=target+(target*2)+(target*4);\n System.out.println(sum);\n hello = true;\n break;\n }else {\n target--;\n }\n }\n if(!hello){\n System.out.println(0);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4928db57fdfc6f7b38c403680169b94a", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class MyClass {\n\n public static void main(String[] args)throws Exception{\n \n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n \n if(b >=2 && c >= 4){\n while(b/a!=2 || c/a!=4){\n --a;\n if(a==1){\n break;\n }\n }\n System.out.println(a+a*2+a*4);\n }\n else{\n System.out.println(0);\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aad0d59421239dc81f75447ffe87730f", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class JavaApplication41 {\n\n \n public static void main(String[] args) {\n Scanner n=new Scanner(System.in); \n int l=n.nextInt(); \n int p=n.nextInt(); \n int a=n.nextInt(); int num=0;\n int a2;\n while(l!=0){\n if((l*2)>a||(l*4)>p) \n l--; \n }\n if(((l*2)<=a)&&((l*4)<=p)) \n num=l+(l*2)+(l*4);\n else\n num=0;\n \n System.out.println(num);\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ae95119bc7553d01c2dd4c41f5d3c38", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package codechef;\nimport java.util.*;\npublic class contest {\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\tint y=s.nextInt();\n\t\tint a=s.nextInt();\n\t\tint org=a-1;\n\t\twhile(y>=org) {\n\t\t\tif(y==org) {\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\torg=org+2;\n\t\t}\n\t\tSystem.out.println(\"No\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "80bba1691f940f2793c079b733c2cb31", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Coba {\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n \n try {\n String masukan = in.readLine();\n String[] tokens = masukan.split(\" \");\n int x = Integer.parseInt(tokens[0]);\n int y = Integer.parseInt(tokens[1]);\n \n if(hitung(x, y, 1, 0)) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n } \n } finally {\n in.close();\n }\n }\n \n public static boolean hitung(int x, int y, int ori, int copy) {\n if(ori == y && copy == x) return true;\n if(ori > y || copy > x) return false;\n if(copy == 0) {\n return hitung(x, y, ori + 1, copy + 1);\n } else {\n return hitung(x, y, ori + 1, copy + 1) || hitung(x, y, ori, copy + 2);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cbafcad8f07ed5f986cf53b2d395af50", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "package Stab;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Vector;\npublic class Test {\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint x=sc.nextInt(),y=sc.nextInt();\n\t\tif(y<1){System.out.println(\"No\");return;}\n\t\tint cpd=y-1;\n\t\tif(y==1)cpd++;\n\t\tif(cpd<=x&&(x-cpd)%2==0)System.out.println(\"Yes\");\n\t\telse System.out.println(\"No\");\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8049e09cbf48e8a7f9a2692c6d74cc51", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0} {"lang": "Java 8", "source_code": " \npackage codeforces.round.pkg461.div.pkg2;\n\nimport java.util.*;\n\n \npublic class TaskA {\n\n \n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n long c= input.nextInt();\n long o = input.nextInt();\n long numC= o-1;\n\n if(o==0) System.out.println(\"No\");\n else if(numC==c) System.out.println(\"Yes\");\n else if((numC%2==0 && c%2==0) || (numC%2!=0 && c%2!=0) ) System.out.println(\"Yes\");\n else System.out.println(\"No\");\n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cc074919db9894a4326f345d74c94ec0", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Test{\n public static void main(String args[]){\n Scanner in=new Scanner(System.in);\n int l=in.nextInt();\n int count=0,flag=0,i=0,j;\n String s=in.next();\n for(j=1;j 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n static class FT {\n\n int[] data;\n\n FT(int n) {\n data = new int[n];\n }\n\n void update(int index, int val) {\n // System.out.println(\"UPDATE INDEX \" + index);\n while (index < data.length) {\n data[index] += val;\n index += index & (-index);\n\n // System.out.println(\"NEXT \" +index);\n }\n }\n\n int get(int index) {\n // System.out.println(\"GET INDEX \" + index);\n int result = 0;\n while (index > 0) {\n result += data[index];\n index -= index & (-index);\n // System.out.println(\"BACK \" + index);\n }\n return result;\n }\n }\n\n static int gcd(int a, int b) {\n if (b == 0) {\n return a;\n } else {\n return gcd(b, a % b);\n }\n }\n\n static int pow(int a, int b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n int val = pow(a, b / 2);\n if (b % 2 == 0) {\n\n return val * val;\n } else {\n return val * val * a;\n }\n }\n\n// static Point intersect(Point a, Point b, Point c) {\n// double D = cross(a, b);\n// if (D != 0) {\n// return new Point(cross(c, b) / D, cross(a, c) / D);\n// }\n// return null;\n// }\n//\n// static Point convert(Point a, double angle) {\n// double x = a.x * cos(angle) - a.y * sin(angle);\n// double y = a.x * sin(angle) + a.y * cos(angle);\n// return new Point(x, y);\n// }\n// static Point minus(Point a, Point b) {\n// return new Point(a.x - b.x, a.y - b.y);\n// }\n//\n// static Point add(Point a, Point b) {\n// return new Point(a.x + b.x, a.y + b.y);\n// }\n//\n// static double cross(Point a, Point b) {\n// return a.x * b.y - a.y * b.x;\n//\n//\n// }\n//\n// static class Point {\n//\n// int x, y;\n//\n// Point(int x, int y) {\n// this.x = x;\n// this.y = y;\n// }\n//\n// @Override\n// public String toString() {\n// return \"Point: \" + x + \" \" + y;\n// }\n// }\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new FileReader(new File(\"input.txt\")));\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dca9408904255dcf92b3021d680a613e", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0} {"lang": "Java 7", "source_code": "package com.company;\n\nimport java.io.IOException;\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n BigInteger input = in.nextBigInteger();\n in.close();\n BigInteger div7 = input.divide(BigInteger.valueOf(7L));\n BigInteger mod7 = input.mod(BigInteger.valueOf(7L));\n BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));\n BigInteger maximum = BigInteger.valueOf(minimum.longValue());\n if(mod7.equals(BigInteger.ZERO)) {\n System.out.println(minimum+\" \"+ minimum); \n } else {\n maximum = maximum.add(BigInteger.ONE);\n\n if (mod7.compareTo(BigInteger.ONE) == 1) {\n maximum = maximum.add(BigInteger.ONE);\n }\n System.out.println(minimum + \" \" + maximum);\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0426944c1232ae5d234f9726f1e863ff", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0} {"lang": "Java 7", "source_code": "package com.company;\n\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n try {\n Scanner in = new Scanner(System.in);\n BigInteger input = in.nextBigInteger();\n BigInteger div7 = input.divide(BigInteger.valueOf(7L));\n BigInteger mod7 = input.mod(BigInteger.valueOf(7L));\n BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));\n BigInteger maximum = BigInteger.valueOf(minimum.longValue());\n if(mod7.equals(BigInteger.ZERO)) {\n System.out.println(minimum+\" \"+ minimum);\n return;\n }\n maximum=maximum.add(BigInteger.ONE);\n\n if(mod7.compareTo(BigInteger.ONE)==1) {\n maximum=maximum.add(BigInteger.ONE);\n }\n System.out.println(minimum+\" \"+ maximum);\n }catch(Exception e) {\n return;\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c61cfc14bb6241faf1be96a39bed61d", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0} {"lang": "Java 7", "source_code": "package com.company;\n\nimport java.io.IOException;\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Lain {\n\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n String inputStr = in.nextLine();\n BigInteger input = new BigInteger(\"14\");\n BigInteger div7 = input.divide(BigInteger.valueOf(7L));\n BigInteger mod7 = input.mod(BigInteger.valueOf(7L));\n BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));\n BigInteger maximum = BigInteger.valueOf(minimum.longValue());\n if(mod7.equals(BigInteger.ZERO)) {\n System.out.println(minimum+\" \"+ minimum);\n } else {\n maximum = maximum.add(BigInteger.ONE);\n\n if (mod7.compareTo(BigInteger.ONE) == 1) {\n maximum = maximum.add(BigInteger.ONE);\n }\n System.out.println(minimum + \" \" + maximum);\n }\n in.close();\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43e94d57c04d9bbb566d923ef7784d66", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0} {"lang": "Java 7", "source_code": "package com.company;\n\nimport java.io.IOException;\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n String inputStr = in.nextLine();\n System.out.println(\"|\" +inputStr +\"|\");\n BigInteger input = new BigInteger(inputStr);\n in.close();\n BigInteger div7 = input.divide(BigInteger.valueOf(7L));\n BigInteger mod7 = input.mod(BigInteger.valueOf(7L));\n BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));\n BigInteger maximum = BigInteger.valueOf(minimum.longValue());\n if(mod7.equals(BigInteger.ZERO)) {\n System.out.println(minimum+\" \"+ minimum);\n } else {\n maximum = maximum.add(BigInteger.ONE);\n\n if (mod7.compareTo(BigInteger.ONE) == 1) {\n maximum = maximum.add(BigInteger.ONE);\n }\n System.out.println(minimum + \" \" + maximum);\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ebdc52c022d9b3a85b4f09da22314f4a", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0} {"lang": "Java 11", "source_code": "/* \n * #######\t ####### ###### ###### \n * #\t\t # #\t\t #\t #\t#\t #\n * #\t\t #\t # \t\t #\t #\t#\t #\n * ####### #######\t \t #\t ### #\n * # #\t #\t\t #\t\t\t #\n * # #\t #\t\t #\t\t\t #\n * ####### #\t #\t\t #\t\t\t #\n * \n */\n\n\nimport java.util.*;\n\npublic class henlo {\n\n\tpublic static void main(String[] args) {\n\t\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextLong();\n\t\tlong x = n;\n\t\tlong k = 0;\n\t\t\n\t\twhile( n > 0) {\n\t\t\t\n\t\t\tk++;\n\t\t\tx = x / 2;\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(k);\n\t\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\t\n\t}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d71a2cf345fd5874f10381c5de8a53e", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.lang.Math;\npublic class Main {\n\n public static void main(String[] args) {\n Scanner newSc = new Scanner(System.in);\n int n = newSc.nextInt();\n int a = 0, j = 0;\n for(int i = 1; i <= n / 2 ; i += 1)\n if(Math.pow(2, j) == i){\n a += 1;\n j += 1;\n }\n System.out.println(a + 1);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b897928068cdb7c7faf6902052271c31", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.HashSet;\npublic class Packets\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int ans=0,sum=0,temp=1;\n boolean flag=false;\n while(flag!=true)\n {\n for(int i=1;i<=n;i++)\n {\n for(int j=0;j s) {\n if (l > r) {\n print(l - 1, r, s + 1);\n } else {\n print(l, r - 1, s + 1);\n }\n } else {\n print(l + 1, r, s - 1);\n }\n } else {\n System.out.println(\"Impossible\");\n }\n\n }\n\n public static void print(int l, int r, int s) throws IOException {\n OutputStream o = new BufferedOutputStream(System.out);\n for (int i = 0; i < l; i++)\n o.write('|');\n o.write('+');\n for (int i = 0; i < r; i++)\n o.write('|');\n o.write('=');\n for (int i = 0; i < s; i++)\n o.write('|');\n o.write('\\n');\n o.flush();\n }\n\n public static void main(String[] args) throws IOException {\n doJob(readAll(System.in));\n }\n\n public static String readAll(InputStream stream) throws IOException {\n return new BufferedReader(new InputStreamReader(new BufferedInputStream(stream))).readLine();\n }\n\n public static void test(String str) throws IOException {\n doJob(readAll(new ByteArrayInputStream(str.getBytes())));\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8dbb7b092f08badcaa8443d98eb724c9", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6", "difficulty": null} {"lang": "Java 8", "source_code": "package implementation;\n\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.util.Scanner;\nimport java.lang.Math;\n\npublic class A394CountingSticks {\n static String solve(int a, int b, int c)\n { \n double sum = a + b;\n double dif = Math.floor((c - sum)/2);\n String as = new String(new char[a]).replace(\"\\0\", \"|\");\n String bs = new String(new char[(int)(b + dif)]).replace(\"\\0\", \"|\");\n String cs = new String(new char[(int)(c - dif)]).replace(\"\\0\", \"|\");\n\n return as + '+' + bs + '=' + cs;\n }\n public static void main(String[] args) \n {\n Scanner s = new Scanner(System.in);\n String equation = s.next();\n int[] abc = new int[3];\n int temp1 = 102, temp2 = 102;\n for (int i = 0; i < equation.length(); i++) \n {\n abc[0]++;\n if (equation.charAt(i) == '+')\n temp1 = i;\n else if (equation.charAt(i) == '=')\n temp2 = i;\n if (i > temp1 && i < temp2)\n abc[1]++;\n else if (i > temp2)\n abc[2]++;\n } \n abc[0] = abc[0] - abc[1] - abc[2] - 2;\n \n String str = solve(abc[0], abc[1], abc[2]);\n System.out.println(str);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65003ceb4369f5b5b57c49f40c06ad96", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class countingSticks{\n\n public static void main(String[] args) {\n \n Scanner sc = new Scanner(System.in);\n String stickEquation=sc.nextLine();\n String[] Parts=stickEquation.split(\"=\");\n if(Parts[0].length() - 1 == Parts[1].length() ){\n System.out.print(stickEquation);\n System.exit(0);\n }\n if(Parts[0].length() +1 != Parts[1].length() || Parts[0].length()>200){\n System.out.print(\"Impossible\");\n System.exit(0);\n }\n String[] Variables=Parts[0].split(\"+\");\n if(Variables[0].length()<100){\n Variables[0]=\"|\"+Variables[0];\n }else{\n Variables[1]=\"|\"+Variables[1];\n }\n Parts[1]=Parts[1].substring(1);\n System.out.print(Variables[0]+\"+\"+Variables[1]+\"=\"+Parts[1]);\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b5688f3f18175ac4cbd085b7f9d1883", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n \n String x = input.nextLine();\n int a = 0,b = 0,c = 0;\n for (int i = 0; i < x.length(); i++) {\n if(x.charAt(i) == '|'){\n a++; \n }else if(x.charAt(i) == '+'){\n b = a;\n }else if(x.charAt(i) == '='){\n c = a-b;\n }\n }\n \n a = a -b -c; \n \n while(a != b + c){\n if(a < b+c){\n a++;\n b--;\n }else{\n a--;\n b++;\n }\n }\n \n if(a != b + c){\n System.out.println(\"Impossible\");\n }else if(a == b+c){\n for (int i = 0; i <= a+b+c +1; i++) {\n if(i < b)\n System.out.print(\"|\");\n else if(i == b)\n System.out.print(\"+\");\n else if(i<=b+c)\n System.out.print(\"|\");\n else if(i == b + c + 1)\n System.out.print(\"=\");\n else if(i > b+c)\n System.out.print(\"|\");\n }\n }\n \n \n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a97ba17137a4c41451484adde503f438", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class flowers{\npublic static void main(String[] args) {\n\tScanner s=new Scanner(System.in);\n\tint n=s.nextInt();\n\tint a[]=new int[12];\n\tint m=-1;\n\tfor(int i=0;i<12;i++){\n\t\ta[i]=s.nextInt();\n\t}\n int ans=0;\n if(n>0){\n \twhile(n>0){\n \t\tint max=0;\n \t\tfor (int i=0;i<12;i++) {\n \t\t\tif (max 0) {\n\t\t\t\tmax = 0 ;\n\t\t\t\tfor (int i = 0; i < 12; i++) {\n\t\t\t\t\tif (arr[i] > max && !bol[i]) {max = arr[i] ; index = i ;}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t//System.out.println(\"index : \"+arr[index]);\n\t\t\t\tbol[index] = true ;\n\t\t\t\tn -= max ;\n\t\t\t\tcounter ++ ;\n\t\t\t}\n\t\t\tSystem.out.println(counter);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7b5d3df0a306318d624b12499540147f", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0} {"lang": "Java 6", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Vector;\n\n/**\n *\n * @author Mohammad\n */\npublic class BusinessTrip {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\nBufferedReader input=new BufferedReader(new InputStreamReader(System.in));\ntry{\n int k=Integer.parseInt(input.readLine());\n if(k>=0 && k<=100)\n \n {\n\n String m=input.readLine();\n String mm[]=m.split(\" \");\nint aa[]=new int [m.length()];\n for(int i=0;imax){\n max=aa[i];\n index=i;}\n \n if(index!=-1)\n aa[index]=0;\n sum+=max;\n c++;\n }\n \n System.out.println(c); \n \n }\n}\ncatch(Exception e){e.printStackTrace();}\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d6b02c0e425f20b0b5aeadadbe08f765", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A\n{\n\tString line;\n\tStringTokenizer inputParser;\n\tBufferedReader is;\n\tFileInputStream fstream;\n\tDataInputStream in;\n\tString FInput=\"\";\n\t\n\tvoid openInput(String file)\n\t{\n\n\t\tif(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin\n\t\telse\n\t\t{\n\t\t\ttry{\n\t\t\n\t\t\t\t\n\t\t\tfstream = new FileInputStream(file);\n\t\t\tin = new DataInputStream(fstream);\n\t\t\tis = new BufferedReader(new InputStreamReader(in));\n\t\t\t}catch(Exception e)\n\t\t\t{\n\t\t\t\tSystem.err.println(e);\n\t\t\t}\n\t\t}\n\n\t}\n\t\n\tvoid readNextLine()\n\t{\n\t\ttry {\n\t\t\tline = is.readLine();\n\t\t\tinputParser = new StringTokenizer(line, \" \");\n\t\t\t//System.err.println(\"Input: \" + line);\n\t\t} catch (IOException e) {\n\t\t\tSystem.err.println(\"Unexpected IO ERROR: \" + e);\n\t\t}\t\n\t\tcatch (NullPointerException e)\n\t\t{\n\t\t\tline=null;\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tint NextInt()\n\t{\n\t\tString n = inputParser.nextToken();\n\t\tint val = Integer.parseInt(n);\n\t\t\n\t\t//System.out.println(\"I read this number: \" + val);\n\t\treturn val;\n\t}\n\t\n\tlong NextLong()\n\t{\n\t\tString n = inputParser.nextToken();\n\t\tlong val = Long.parseLong(n);\n\t\t\n\t\t//System.out.println(\"I read this number: \" + val);\n\t\treturn val;\n\t}\n\t\n\tString NextString()\n\t{\n\t\tString n = inputParser.nextToken();\n\t\treturn n;\n\t}\n\t\n\tvoid closeInput()\n\t{\n\t\ttry {\n\t\t\tis.close();\n\t\t} catch (IOException e) {\n\t\t\tSystem.err.println(\"Unexpected IO ERROR: \" + e);\n\t\t}\n\t\t\t\n\t}\n\t\n\t\n\tpublic static void main(String [] argv)\n\t{\n\t\tString filePath=null;\n\t\tif(argv.length>0)filePath=argv[0];\n\t\tA a = new A(filePath);\n\t}\n\t\n\tpublic void readFInput()\n\t{\n\t\tfor(;;)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treadNextLine();\n\t\t\t\tFInput+=line+\" \";\n\t\t\t}\n\t\t\tcatch(Exception e)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tinputParser = new StringTokenizer(FInput, \" \");\n\t}\n\t \n\tpublic A(String inputFile)\n\t{\n\t\topenInput(inputFile);\n\t\tint [] p = new int[12];\n\t\t\n\t\treadNextLine();\n\t\tint k=NextInt();\n\t\treadNextLine();\n\t\tfor(int i=0; i<12; i++)\n\t\t\tp[i]=NextInt();\n\t\tArrays.sort(p);\n\t\tint i=11;\n\t\t\n\t\tint ret=0;\n\t\twhile(ret=0)\n\t\t{\n\t\t\tret+=p[i];\n\t\t\ti--;\n\t\t}\n\t\tif(i<0)System.out.println(-1);\n\t\telse System.out.println(11-i);\n closeInput();\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "90324a6c395d9dfff4265c9a90c129a4", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D896 {\n\t\n\tlong mod;\n\t\n\tlong[][] factorial(int n, Long[] prime) {\n\t\tint k = prime.length;\n\t\tlong[][] f = new long[n+1][k+1];\n\t\tf[0][0] = 1L;\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tlong cur = i;\n\t\t\tfor(int j = 0; j <= k; j++) f[i][j] = f[i-1][j];\n\t\t\tfor(int j = 0; j < k; j++) {\t\t\t\t\n\t\t\t\twhile(cur%prime[j] == 0) {\n\t\t\t\t\tcur /= prime[j];\n\t\t\t\t\tf[i][j+1]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tf[i][0] = (f[i][0] * cur) % mod;\n\t\t}\n\t\treturn f;\n\t}\n\n\tLong[] factors(long p){\n\t\tLinkedList f = new LinkedList();\n\t\tlong x = 2;\n\t\twhile(x*x <= p) {\n\t\t\tlong y = 0;\n\t\t\twhile(p%x == 0) {\n\t\t\t\tp /= x;\n\t\t\t\ty++;\n\t\t\t}\n\t\t\tif(y != 0) f.addLast(x);\n\t\t\tx++;\n\t\t}\n\t\tif(p != 1) f.addLast(p);\n\t\treturn f.toArray(new Long[0]);\n\t}\n\n\tlong[] euclides(long x, long y) {\n\t\tif(y == 0) return new long[] {1L,0L};\n\t\tif(x == 0) return new long[] {0L,1L};\n\t\tlong[] res = euclides(y%x, x);\n\t\tlong a = res[0];\n\t\tlong b = res[1];\n\t\treturn new long[] {(b-a*(y/x)), a};\n\t}\n\n\tlong inverse(long x) {\n\t\tlong[] res = euclides(x, mod);\n\t\tlong a = res[0];\n\t\treturn ((a%mod)+mod)%mod;\n\t}\n\n\n\tlong modpow(long m, long n) {\n\t\tlong res = 1%mod;\n\t\twhile(n > 0){\n\t\t\tif(n % 2 == 1) res = (res*m)%mod;\n\t\t\tm = (m*m)%mod;\n\t\t\tn = n/2;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tlong[][] facPrime;\n\tLong[] prime;\n\tlong[] a0;\n\tlong[] al;\n\tlong[] alnext;\n\tlong[] ar;\n\tlong[] arnext;\n\tint n;\n\tint l;\n\tint r;\n\t\n\n\tprivate void solve() throws Exception {\n\t\tn = nextInt();\n\t\tmod = nextInt();\t\t\n\t\tl = nextInt();\n\t\tr = nextInt();\n\t\t\n\t\tprime = factors(mod);\n\t\tfacPrime = factorial(2*n, prime);\n\t\tlong[] C = new long[2*n+1];\n\t\t\n\t\tfor(int i = 0; i <= n; i++) {\n\t\t\tlong c = (((facPrime[n][0] * inverse(facPrime[i][0])) % mod) * inverse(facPrime[n-i][0])) % mod;\n\t\t\tfor(int j = 0; j < prime.length; j++) {\n\t\t\t\tc = (c * modpow(prime[j], facPrime[n][j+1] - facPrime[i][j+1] - facPrime[n-i][j+1]))%mod;\n\t\t\t}\n\t\t\tC[i] = c;\n\t\t}\n\t\ta0 = catalan(n,0);\n\t\tal = catalan(n,l-1);\n\t\talnext = catalan(n,l);\n\t\tar = catalan(n,r);\n\t\tarnext = catalan(n,r+1);\n\t\t\n\t\tlong[] br = b(r, ar, arnext);\n\t\tlong[] bl = b(l-1, al, alnext);\n\t\t\n\t\tlong res = 0;\n\t\tfor(int i = 0; i <= n; i++) res = (res + (((br[i]-bl[i]+mod)%mod)*C[i])%mod)%mod;\n\t\t\n\t\tout.println(res);\n\t}\n\t\n\tlong[] b(int t, long[] at, long[] atnext) {\n\t\tlong[] res = new long[n+1];\n\t\tif(t >= 0) res[0] = 1;\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tres[i] = (2L * res[i-1])%mod;\n\t\t\tres[i] = (res[i] - ((i-t)%2 == 0 ? 0:at[(i+t)/2]) + mod)%mod;\n\t\t\tres[i] = (res[i] + ((i-(t+1))%2 == 0 ? 0:atnext[(i+t+1)/2]) + mod)%mod;\n\t\t\tres[i] = (res[i] - ((i-0)%2 == 0 ? 0: a0[(i+0)/2]) + mod)%mod;\n\t\t\tif(i >= t) {\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\t\n\tlong[] catalan(int n, int t) {\n\t\tlong[] res = new long[n+1];\n\t\tif(t < 0) return res;\n\t\tfor(int i = t; i <= n; i++) {\n\t\t\tres[i] = (((facPrime[2*i-t][0] * inverse(facPrime[i+1][0])) % mod) * inverse(facPrime[i-t][0])) % mod;\n\t\t\tfor(int j = 0; j < prime.length; j++) {\n\t\t\t\tres[i] = (res[i] * modpow(prime[j], facPrime[2*i-t][j+1] - facPrime[i+1][j+1] - facPrime[i-t][j+1]))%mod;\n\t\t\t}\n\t\t\tres[i] = (res[i]*(t+1))%mod;\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew D896().run();\n\t}\n\n\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate float nextFloat() throws IOException {\n\t\treturn Float.parseFloat(nextToken());\n\t}\n\n\tprivate String nextLine() throws IOException {\n\t\treturn new String(in.readLine());\n\t}\n\n\tprivate String nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1a55cea701d2ffa7cdfb5ddc818d6667", "src_uid": "6ddc487029785738679007443fc08463", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.util.Map.Entry;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class TaskD {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int m = in.readInt();\n int p = in.readInt();\n int l = in.readInt();\n int r = in.readInt();\n\n ExtLucas lucas = new ExtLucas(p, m);\n\n IntExtCRT crt = new IntExtCRT();\n\n for (Map.Entry entry : lucas) {\n Modular mod = new Modular(entry.getKey());\n LongCombination comb = entry.getValue();\n long ans = 0;\n for (int n = 0; n <= m; n++) {\n long a = comb.combination(n, DigitUtils.ceilDiv(n + l, 2));\n long b = comb.combination(n, DigitUtils.floorDiv(n + r, 2) + 1);\n long c = comb.combination(m, n);\n\n long local = mod.subtract(a, b);\n local = mod.mul(local, c);\n ans = mod.plus(ans, local);\n }\n\n crt.add((int) ans, entry.getKey());\n }\n\n\n out.println(crt.getValue());\n }\n\n }\n\n static class MillerRabin {\n Modular modular;\n Power power;\n Random random = new Random();\n\n public boolean mr(int n, int s) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n int m = n - 1;\n while (m % 2 == 0) {\n m /= 2;\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, m)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(int x, int n, int m) {\n return test(power.pow(x, m), m, n);\n }\n\n private boolean test(int y, int exp, int n) {\n int y2 = modular.mul(y, y);\n if (!(exp == n - 1 || test(y2, exp * 2, n))) {\n return false;\n }\n if (exp != n - 1 && y2 != 1) {\n return true;\n }\n if (y != 1 && y != n - 1) {\n return false;\n }\n return true;\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 mul(long x, long y) {\n return valueOf(x * y);\n }\n\n public int plus(long x, long y) {\n return valueOf(x + y);\n }\n\n public int subtract(long x, long 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 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 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 PollardRho {\n MillerRabin mr = new MillerRabin();\n Random random = new Random(1);\n\n public int findFactor(int n) {\n if (mr.mr(n, 5)) {\n return n;\n }\n while (true) {\n int f = rho(n);\n if (f != n) {\n return f;\n }\n }\n }\n\n public Map findAllFactors(int n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, int n) {\n if (n == 1) {\n return;\n }\n int f = findFactor(n);\n if (f == n) {\n Integer value = map.get(f);\n if (value == null) {\n value = 1;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n private int rho(int n) {\n if (n % 2 == 0) {\n return 2;\n }\n if (n % 3 == 0) {\n return 3;\n }\n int x = 0, y = x, t, q = 1, c = random.nextInt(n - 1) + 1;\n for (int k = 2; ; k <<= 1, y = x, q = 1) {\n for (int i = 1; i <= k; ++i) {\n x = DigitUtils.mod((long) x * x + c, n);\n q = DigitUtils.mod((long) q * Math.abs(x - y), n);\n if ((i & 127) == 0) {\n t = GCDs.gcd(q, n);\n if (t > 1) {\n return t;\n }\n }\n }\n if ((t = GCDs.gcd(q, n)) > 1) {\n return t;\n }\n }\n }\n\n }\n\n static interface LongCombination {\n int combination(long n, long m);\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 DigitUtils {\n private DigitUtils() {\n }\n\n public static int floorDiv(int a, int b) {\n return a < 0 ? -ceilDiv(-a, b) : a / b;\n }\n\n public static int ceilDiv(int a, int b) {\n if (a < 0) {\n return -floorDiv(-a, b);\n }\n int c = a / b;\n if (c * b < a) {\n return c + 1;\n }\n return c;\n }\n\n public static int mod(long x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return (int) x;\n }\n\n public static int mod(int x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n }\n\n static 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 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 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\n static class Lucas implements IntCombination, LongCombination {\n private final IntCombination primeCombination;\n private int mod;\n\n public Lucas(IntCombination primeCombination, int mod) {\n this.primeCombination = primeCombination;\n this.mod = mod;\n }\n\n public int combination(int m, int n) {\n return combination((long) m, (long) n);\n }\n\n public int combination(long m, long n) {\n if (n == 0) {\n return 1 % mod;\n }\n return (int) ((long) primeCombination.combination((int) (m % mod), (int) (n % mod)) *\n combination(m / mod, n / mod) % mod);\n }\n\n }\n\n static class ExtLucas implements LongCombination, Iterable> {\n PollardRho pr = new PollardRho();\n Map factorialMap = new HashMap();\n int p;\n\n public Iterator> iterator() {\n return factorialMap.entrySet().iterator();\n }\n\n public ExtLucas(int p, long m) {\n this.p = p;\n Map factors = pr.findAllFactors(p);\n for (Map.Entry entry : factors.entrySet()) {\n LongCombination combination;\n if (entry.getKey().equals(entry.getValue())) {\n combination = new Lucas(new PrimeCombination((int) Math.min(m, entry.getKey()), new Modular(entry.getKey())),\n entry.getKey());\n } else {\n combination = new ExtLucas.ExtLucasFactorial(entry.getKey(), entry.getValue(), m);\n }\n factorialMap.put(entry.getValue(), combination);\n }\n }\n\n public int combination(long m, long n) {\n if (m < n) {\n return 0;\n }\n IntExtCRT extCRT = new IntExtCRT();\n for (Map.Entry entry : factorialMap.entrySet()) {\n extCRT.add(entry.getValue().combination(m, n), entry.getKey());\n }\n\n// if (extCRT.r != BigCombination.combination(m, n).mod(BigInteger.valueOf(p)).intValue()) {\n// throw new RuntimeException();\n// }\n return extCRT.getValue();\n }\n\n public static class ExtLucasFactorial implements LongCombination {\n int exp;\n int fact;\n int p;\n int pc;\n Modular modular;\n Power power;\n ExtGCD extGCD = new ExtGCD();\n int[] g;\n int[] pgc;\n\n public ExtLucasFactorial(int p, int pc, long m) {\n this.p = p;\n this.pc = pc;\n this.g = new int[(int) (Math.min(pc, m) + 1)];\n modular = new Modular(pc);\n power = new Power(modular);\n g[0] = 1;\n g[1] = 1;\n for (int i = 2; i < g.length; i++) {\n if (i % p == 0) {\n g[i] = g[i - 1];\n } else {\n g[i] = modular.mul(g[i - 1], i);\n }\n }\n\n if (m >= pc) {\n pgc = new int[(int) m + 1];\n pgc[0] = 1;\n for (int i = 1; i <= m; i++) {\n pgc[i] = modular.mul(pgc[0], g[pc]);\n }\n }\n }\n\n private int fact(long m) {\n fact = 1;\n exp = 0;\n while (m > 1) {\n exp += m / p;\n if (m >= pc) {\n fact = modular.mul(fact, pgc[(int) (m / pc)]);\n }\n fact = modular.mul(fact, g[(int) (m % pc)]);\n m /= p;\n }\n return fact;\n }\n\n public int combination(long m, long n) {\n if (m < n) {\n return 0;\n }\n int v = fact(m);\n int e = exp;\n extGCD.extgcd(fact(n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n extGCD.extgcd(fact(m - n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n v = modular.mul(v, power.pow(p, e));\n return v;\n }\n\n }\n\n }\n\n static class IntExtCRT {\n int r;\n int m;\n boolean valid = true;\n static final ExtGCD gcd = new ExtGCD();\n\n public IntExtCRT() {\n r = 0;\n m = 1;\n }\n\n public int getValue() {\n return r;\n }\n\n public boolean add(int r, int m) {\n int m1 = this.m;\n int x1 = this.r;\n int m2 = m;\n int x2 = DigitUtils.mod(r, m);\n int g = (int) gcd.extgcd(m1, m2);\n int a = (int) (gcd.getX() % m2);\n if ((x2 - x1) % g != 0) {\n return valid = false;\n }\n this.m = m1 / g * m2;\n this.r = DigitUtils.mod((long) a * ((x2 - x1) / g) % this.m * m1 % this.m + x1, this.m);\n return true;\n }\n\n public String toString() {\n return String.format(\"%d mod %d\", r, m);\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\n static interface IntCombination {\n int combination(int m, int n);\n\n }\n\n static class GCDs {\n private GCDs() {\n }\n\n public static int gcd(int a, int b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static int gcd0(int a, int b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n }\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "436e53674b4d0281d56d7007f7cc9847", "src_uid": "6ddc487029785738679007443fc08463", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.util.Map.Entry;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class TaskD {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int m = in.readInt();\n int p = in.readInt();\n int l = in.readInt();\n int r = in.readInt();\n\n ExtLucas lucas = new ExtLucas(p, m);\n\n IntExtCRT crt = new IntExtCRT();\n\n for (Map.Entry entry : lucas) {\n Modular mod = new Modular(entry.getKey());\n LongCombination comb = entry.getValue();\n long ans = 0;\n for (int n = 0; n <= m; n++) {\n long a = comb.combination(n, DigitUtils.ceilDiv(n + l, 2));\n long b = comb.combination(n, DigitUtils.floorDiv(n + r, 2) + 1);\n long c = comb.combination(m, n);\n\n long local = mod.subtract(a, b);\n local = mod.mul(local, c);\n ans = mod.plus(ans, local);\n }\n\n crt.add((int) ans, entry.getKey());\n }\n\n\n out.println(crt.getValue());\n }\n\n }\n\n static class MillerRabin {\n Modular modular;\n Power power;\n Random random = new Random();\n\n public boolean mr(int n, int s) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n int m = n - 1;\n while (m % 2 == 0) {\n m /= 2;\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, m)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(int x, int n, int m) {\n return test(power.pow(x, m), m, n);\n }\n\n private boolean test(int y, int exp, int n) {\n int y2 = modular.mul(y, y);\n if (!(exp == n - 1 || test(y2, exp * 2, n))) {\n return false;\n }\n if (exp != n - 1 && y2 != 1) {\n return true;\n }\n if (y != 1 && y != n - 1) {\n return false;\n }\n return true;\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 mul(long x, long y) {\n return valueOf(x * y);\n }\n\n public int plus(long x, long y) {\n return valueOf(x + y);\n }\n\n public int subtract(long x, long 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 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 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 PollardRho {\n MillerRabin mr = new MillerRabin();\n Random random = new Random(1);\n\n public int findFactor(int n) {\n if (mr.mr(n, 5)) {\n return n;\n }\n while (true) {\n int f = rho(n);\n if (f != n) {\n return f;\n }\n }\n }\n\n public Map findAllFactors(int n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, int n) {\n if (n == 1) {\n return;\n }\n int f = findFactor(n);\n if (f == n) {\n Integer value = map.get(f);\n if (value == null) {\n value = 1;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n private int rho(int n) {\n if (n % 2 == 0) {\n return 2;\n }\n if (n % 3 == 0) {\n return 3;\n }\n int x = 0, y = x, t, q = 1, c = random.nextInt(n - 1) + 1;\n for (int k = 2; ; k <<= 1, y = x, q = 1) {\n for (int i = 1; i <= k; ++i) {\n x = DigitUtils.mod((long) x * x + c, n);\n q = DigitUtils.mod((long) q * Math.abs(x - y), n);\n if ((i & 127) == 0) {\n t = GCDs.gcd(q, n);\n if (t > 1) {\n return t;\n }\n }\n }\n if ((t = GCDs.gcd(q, n)) > 1) {\n return t;\n }\n }\n }\n\n }\n\n static interface LongCombination {\n int combination(long n, long m);\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 DigitUtils {\n private DigitUtils() {\n }\n\n public static int floorDiv(int a, int b) {\n return a < 0 ? -ceilDiv(-a, b) : a / b;\n }\n\n public static int ceilDiv(int a, int b) {\n if (a < 0) {\n return -floorDiv(-a, b);\n }\n int c = a / b;\n if (c * b < a) {\n return c + 1;\n }\n return c;\n }\n\n public static int mod(long x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return (int) x;\n }\n\n public static int mod(int x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n }\n\n static 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 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 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\n static class ExtLucas implements LongCombination, Iterable> {\n PollardRho pr = new PollardRho();\n Map factorialMap = new HashMap();\n int p;\n\n public Iterator> iterator() {\n return factorialMap.entrySet().iterator();\n }\n\n public ExtLucas(int p, long m) {\n this.p = p;\n Map factors = pr.findAllFactors(p);\n for (Map.Entry entry : factors.entrySet()) {\n LongCombination combination;\n if (entry.getKey().equals(entry.getValue())) {\n combination = new Lucas(new PrimeCombination((int) Math.min(m, entry.getKey()), new Modular(entry.getKey())),\n entry.getKey());\n } else {\n combination = new ExtLucas.ExtLucasFactorial(entry.getKey(), entry.getValue(), m);\n }\n factorialMap.put(entry.getValue(), combination);\n }\n }\n\n public int combination(long m, long n) {\n if (m < n) {\n return 0;\n }\n IntExtCRT extCRT = new IntExtCRT();\n for (Map.Entry entry : factorialMap.entrySet()) {\n extCRT.add(entry.getValue().combination(m, n), entry.getKey());\n }\n\n// if (extCRT.r != BigCombination.combination(m, n).mod(BigInteger.valueOf(p)).intValue()) {\n// throw new RuntimeException();\n// }\n return extCRT.r;\n }\n\n public static class ExtLucasFactorial implements LongCombination {\n int exp;\n int fact;\n int p;\n int pc;\n Modular modular;\n Power power;\n ExtGCD extGCD = new ExtGCD();\n int[] g;\n\n public ExtLucasFactorial(int p, int pc, long m) {\n this.p = p;\n this.pc = pc;\n this.g = new int[(int) (Math.min(pc, m) + 1)];\n modular = new Modular(pc);\n power = new Power(modular);\n g[0] = 1;\n g[1] = 1;\n for (int i = 2; i < g.length; i++) {\n if (i % p == 0) {\n g[i] = g[i - 1];\n } else {\n g[i] = modular.mul(g[i - 1], i);\n }\n }\n }\n\n private int fact(long m) {\n fact = 1;\n exp = 0;\n while (m > 1) {\n exp += m / p;\n if (m >= pc) {\n fact = modular.mul(fact, power.pow(g[pc], m / pc));\n }\n fact = modular.mul(fact, g[(int) (m % pc)]);\n m /= p;\n }\n return fact;\n }\n\n public int combination(long m, long n) {\n if (m < n) {\n return 0;\n }\n int v = fact(m);\n int e = exp;\n extGCD.extgcd(fact(n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n extGCD.extgcd(fact(m - n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n v = modular.mul(v, power.pow(p, e));\n return v;\n }\n\n }\n\n }\n\n static class Lucas implements IntCombination, LongCombination {\n private final IntCombination primeCombination;\n private int mod;\n\n public Lucas(IntCombination primeCombination, int mod) {\n this.primeCombination = primeCombination;\n this.mod = mod;\n }\n\n public int combination(int m, int n) {\n return combination((long) m, (long) n);\n }\n\n public int combination(long m, long n) {\n if (n == 0) {\n return 1 % mod;\n }\n return (int) ((long) primeCombination.combination((int) (m % mod), (int) (n % mod)) *\n combination(m / mod, n / mod) % mod);\n }\n\n }\n\n static class IntExtCRT {\n int r;\n int m;\n boolean valid = true;\n static final ExtGCD gcd = new ExtGCD();\n\n public IntExtCRT() {\n r = 0;\n m = 1;\n }\n\n public int getValue() {\n return r;\n }\n\n public boolean add(int r, int m) {\n int m1 = this.m;\n int x1 = this.r;\n int m2 = m;\n int x2 = DigitUtils.mod(r, m);\n int g = (int) gcd.extgcd(m1, m2);\n int a = (int) (gcd.getX() % m2);\n if ((x2 - x1) % g != 0) {\n return valid = false;\n }\n this.m = m1 / g * m2;\n this.r = DigitUtils.mod((long) a * ((x2 - x1) / g) % this.m * m1 % this.m + x1, this.m);\n return true;\n }\n\n public String toString() {\n return String.format(\"%d mod %d\", r, m);\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, long 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 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\n static interface IntCombination {\n int combination(int m, int n);\n\n }\n\n static class GCDs {\n private GCDs() {\n }\n\n public static int gcd(int a, int b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static int gcd0(int a, int b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n }\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b3a9a3dda3ce37e6928373847cbd014", "src_uid": "6ddc487029785738679007443fc08463", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.util.Map;\nimport java.io.Writer;\nimport java.util.Map.Entry;\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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class TaskD {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int m = in.readInt();\n int p = in.readInt();\n int l = in.readInt();\n int r = in.readInt();\n\n ExtLucas lucas = new ExtLucas(p, m);\n Modular mod = new Modular(p);\n\n long ans = 0;\n for (int n = 0; n <= m; n++) {\n long a = lucas.combination(n, DigitUtils.ceilDiv(n + l, 2));\n long b = lucas.combination(n, DigitUtils.floorDiv(n + r, 2) + 1);\n long c = lucas.combination(m, n);\n\n long local = mod.subtract(a, b);\n local = mod.mul(local, c);\n ans = mod.plus(ans, local);\n }\n\n out.println(ans);\n }\n\n }\n\n static class MillerRabin {\n Modular modular;\n Power power;\n Random random = new Random();\n\n public boolean mr(int n, int s) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n int m = n - 1;\n while (m % 2 == 0) {\n m /= 2;\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, m)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(int x, int n, int m) {\n return test(power.pow(x, m), m, n);\n }\n\n private boolean test(int y, int exp, int n) {\n int y2 = modular.mul(y, y);\n if (!(exp == n - 1 || test(y2, exp * 2, n))) {\n return false;\n }\n if (exp != n - 1 && y2 != 1) {\n return true;\n }\n if (y != 1 && y != n - 1) {\n return false;\n }\n return true;\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 mul(long x, long y) {\n return valueOf(x * y);\n }\n\n public int plus(long x, long y) {\n return valueOf(x + y);\n }\n\n public int subtract(long x, long y) {\n return valueOf(x - y);\n }\n\n public String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class PollardRho {\n MillerRabin mr = new MillerRabin();\n Random random = new Random(1);\n\n public int findFactor(int n) {\n if (mr.mr(n, 5)) {\n return n;\n }\n while (true) {\n int f = rho(n);\n if (f != n) {\n return f;\n }\n }\n }\n\n public Map findAllFactors(int n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, int n) {\n if (n == 1) {\n return;\n }\n int f = findFactor(n);\n if (f == n) {\n Integer value = map.get(f);\n if (value == null) {\n value = 1;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n private int rho(int n) {\n if (n % 2 == 0) {\n return 2;\n }\n if (n % 3 == 0) {\n return 3;\n }\n int x = 0, y = x, t, q = 1, c = random.nextInt(n - 1) + 1;\n for (int k = 2; ; k <<= 1, y = x, q = 1) {\n for (int i = 1; i <= k; ++i) {\n x = DigitUtils.mod((long) x * x + c, n);\n q = DigitUtils.mod((long) q * Math.abs(x - y), n);\n if ((i & 127) == 0) {\n t = GCDs.gcd(q, n);\n if (t > 1) {\n return t;\n }\n }\n }\n if ((t = GCDs.gcd(q, n)) > 1) {\n return t;\n }\n }\n }\n\n }\n\n static interface LongCombination {\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 DigitUtils {\n private DigitUtils() {\n }\n\n public static int floorDiv(int a, int b) {\n return a < 0 ? -ceilDiv(-a, b) : a / b;\n }\n\n public static int ceilDiv(int a, int b) {\n if (a < 0) {\n return -floorDiv(-a, b);\n }\n int c = a / b;\n if (c * b < a) {\n return c + 1;\n }\n return c;\n }\n\n public static int mod(long x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return (int) x;\n }\n\n public static int mod(int x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n }\n\n static 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 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 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\n static class ExtLucas implements LongCombination {\n PollardRho pr = new PollardRho();\n Map factorialMap = new HashMap();\n int p;\n\n public ExtLucas(int p, long m) {\n this.p = p;\n Map factors = pr.findAllFactors(p);\n for (Map.Entry entry : factors.entrySet()) {\n factorialMap.put(entry.getValue(),\n new ExtLucas.ExtLucasFactorial(entry.getKey(), entry.getValue(), m));\n }\n }\n\n public int combination(long m, long n) {\n if (m < n) {\n return 0;\n }\n IntExtCRT extCRT = new IntExtCRT();\n for (Map.Entry entry : factorialMap.entrySet()) {\n extCRT.add(entry.getValue().combination(m, n), entry.getKey());\n }\n\n// if (extCRT.r != BigCombination.combination(m, n).mod(BigInteger.valueOf(p)).intValue()) {\n// throw new RuntimeException();\n// }\n return extCRT.r;\n }\n\n private static class ExtLucasFactorial implements LongCombination {\n int exp;\n int fact;\n int p;\n int pc;\n Modular modular;\n Power power;\n ExtGCD extGCD = new ExtGCD();\n int[] g;\n\n public ExtLucasFactorial(int p, int pc, long m) {\n this.p = p;\n this.pc = pc;\n this.g = new int[(int) (Math.min(pc, m) + 1)];\n modular = new Modular(pc);\n power = new Power(modular);\n g[0] = 1;\n g[1] = 1;\n for (int i = 2; i < g.length; i++) {\n if (i % p == 0) {\n g[i] = g[i - 1];\n } else {\n g[i] = modular.mul(g[i - 1], i);\n }\n }\n }\n\n private int fact(long m) {\n fact = 1;\n exp = 0;\n while (m > 1) {\n exp += m / p;\n if (m >= pc) {\n fact = modular.mul(fact, power.pow(g[pc], m / pc));\n }\n fact = modular.mul(fact, g[(int) (m % pc)]);\n m /= p;\n }\n return fact;\n }\n\n public int combination(long m, long n) {\n if (m < n) {\n return 0;\n }\n int v = fact(m);\n int e = exp;\n extGCD.extgcd(fact(n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n extGCD.extgcd(fact(m - n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n v = modular.mul(v, power.pow(p, e));\n return v;\n }\n\n }\n\n }\n\n static class IntExtCRT {\n int r;\n int m;\n boolean valid = true;\n static final ExtGCD gcd = new ExtGCD();\n\n public IntExtCRT() {\n r = 0;\n m = 1;\n }\n\n public boolean add(int r, int m) {\n int m1 = this.m;\n int x1 = this.r;\n int m2 = m;\n int x2 = DigitUtils.mod(r, m);\n int g = (int) gcd.extgcd(m1, m2);\n int a = (int) (gcd.getX() % m2);\n if ((x2 - x1) % g != 0) {\n return valid = false;\n }\n this.m = m1 / g * m2;\n this.r = DigitUtils.mod((long) a * ((x2 - x1) / g) % this.m * m1 % this.m + x1, this.m);\n return true;\n }\n\n public String toString() {\n return String.format(\"%d mod %d\", r, m);\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, long 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 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\n static class GCDs {\n private GCDs() {\n }\n\n public static int gcd(int a, int b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static int gcd0(int a, int b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n }\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(long c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(long 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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c1151d1d56520e1b88bce6fd5f8fc11f", "src_uid": "6ddc487029785738679007443fc08463", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n/**\n *\n * @author tino chagua\n */\npublic class A {\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] cad = br.readLine().split(\" \");\n int n = Integer.valueOf(cad[0]);\n int c = Integer.valueOf(cad[1]);\n int[] price = new int[n];\n String[] str = br.readLine().split(\" \");\n for (int i = 0; i < n - 1; i++) {\n price[i] = Integer.valueOf(str[i]) - Integer.valueOf(str[i + 1]);\n }\n Arrays.sort(price);\n System.out.println(price[n-1]-c);\n //show(price);\n }\n\n static void show(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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48cebaac626e9ed0edadb98501cbe3ae", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class bearhoney {\n\tpublic static void main(String args[])throws IOException\n\t{\n\t\tBufferedReader ds = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tStringTokenizer s = new StringTokenizer(ds.readLine());\n\t\tint n = Integer.parseInt(s.nextToken());\n\t\tint c = Integer.parseInt(s.nextToken());\n\t\tint a[] = new int [n];\n\t\ts = new StringTokenizer(ds.readLine());\n\t\tint max = 0 , x = 0 ;\n\t\ta[0] = Integer.parseInt(s.nextToken());\n\t\tfor( int i = 1 ; i < n ; i++)\n\t\t{\tint dif = 0;\n\t\t\ta[i] = Integer.parseInt(s.nextToken());\n\t\t\t\n\t\t\t\tdif= a[i-1] - a[i];\n\t\t\t\tif(max abc = new ArrayList();\n String array[] = d.split(\" +\");\n int pos = 0;\n while (pos < array.length - 1) {\n if (Integer.parseInt(array[pos]) > Integer.parseInt(array[pos + 1])) {\n int resta = Integer.parseInt(array[pos]) - Integer.parseInt(array[pos + 1]) - kg;\n abc.add(resta);\n }\n pos++;\n }\n if (abc.size() == 0) {\n System.out.println(0);\n } else {\n int mayor = abc.get(0);\n for (int i = 0; i < abc.size(); i++) {\n if (mayor < abc.get(i)) {\n mayor = abc.get(i);\n }\n }\n System.out.println(mayor);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ff2b9f394b97271b89d2c2c17600c331", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner sc=new Scanner(System.in);\n int i,n,c,x=0,p=0,j=0;\n n=sc.nextInt();\n c=sc.nextInt();\n int a[] =new int[n];\n for(i=0;ia[i+1] )\n {\n \n p=a[i]-a[i+1];\n \n if(p>=x)\n {\n \n x=p;\n j=i;\n }\n }\n }\n System.out.println(x-c);\n \n \n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "54e03fe891aad75279ef2a3bc682707c", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\n\npublic class A102 {\n\n public static void main(String[] args) throws IOException {\n java.io.BufferedReader r = new java.io.BufferedReader(\n new java.io.InputStreamReader(System.in));\n String[] rr = r.readLine().split(\" \");\n String[] c = r.readLine().split(\" \");\n String[] d = r.readLine().split(\" \");\n\n for (int i = 1; i < 11; i++)\n for (int j = 1; j < 10; j++)\n for (int k = 1; k < 10; k++)\n for (int l = 1; l < 10; l++) {\n if ((i + j == Integer.parseInt(rr[0]))\n && (k + l == Integer.parseInt(rr[1]))\n && (i + k == Integer.parseInt(c[0]))\n && (j + l == Integer.parseInt(c[1]))\n && (i + l == Integer.parseInt(d[0]))\n && (j + k == Integer.parseInt(d[1]))\n && (i != j)\n && (i != k)\n && (i != l)\n && (j != k)\n && (j != l)\n && (k != l)) {\n System.out.println(i + \" \" + j);\n System.out.println(k + \" \" + l);\n return;\n }\n }\n \n System.out.println(-1);\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1a22c8b8826eaeb90c72e1c6c01c6f64", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tPrintWriter pr = new PrintWriter(System.out, true);\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t// Scanner s = new Scanner(System.in);\n\t\tStringTokenizer st = new StringTokenizer(in.readLine());\n\t\tint r1 = Integer.parseInt(st.nextToken());\n\t\tint r2 = Integer.parseInt(st.nextToken());\n\t\tst = new StringTokenizer(in.readLine());\n\t\tint c1 = Integer.parseInt(st.nextToken());\n\t\tint c2 = Integer.parseInt(st.nextToken());\n\t\tst = new StringTokenizer(in.readLine());\n\t\tint d1 = Integer.parseInt(st.nextToken());\n\t\tint d2 = Integer.parseInt(st.nextToken());\n\t\tfor(int i = 1;i <= 9;i++) {\n\t\t\tfor(int j = 1;j <= 9;j++) {\n\t\t\t\tfor(int k = 1;k <= 9;k++) {\n\t\t\t\t\tfor(int m = 1;m <= m;i++) {\n\t\t\t\t\t\tif((i == j) || (i == k) || (i == m) || (j == k) || (j == m) || (k == m)) continue;\n\t\t\t\t\t\tif(i+j == r1 && k+m == r2 && i+k == c1 && m+j == c2 && i+m == d1 && k+j == d2) {\n\t\t\t\t\t\t\tpr.println(i+\" \"+j);\n\t\t\t\t\t\t\tpr.println(k+\" \"+m);\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}\n\t\t\t\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "866d4311d0c51b3368c20571b7cf74c0", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n \n \n public class Main {\n \n public static void main(String[] args) {\n Scanner input=new Scanner(System.in);\n int min1,r1,r2,c1,c2,d1,d2, a1=0,a2=0,a3=0,a4=0;\n r1=input.nextInt();\n r2=input.nextInt();\n c1=input.nextInt();\n c2=input.nextInt();\n d1=input.nextInt();\n d2=input.nextInt();\n min1=Math.min(d1, c1);\n min1=Math.min(min1, r1);\n Sets=new TreeSet<>();\n if(min1<10){\n a1=min1-1;\n }else{a1=9;}\n \n a4=d1-a1;\n \n a2=c2-a4;\n a3=r2-a4;\n boolean f=false;\n while(a1>0){\n a4=d1-a1;\n \n a2=c2-a4;\n a3=r2-a4;\n s.clear();\n \n \n s.add(a1);s.add(a2);s.add(a3);s.add(a4);\n if(a1+a4==d1&&a1+a2==r1&&a1+a3==c1&&a2+a3==d2&&a2+a4==c2&&a3+a4==r2&&s.size()==4){\n if(a1<10&&a2<10&&a3<10&&a4<10)\n {\n f=true;\n \n break;} \n }else{\n a1--;\n }\n }\n \n if(f)\n System.out.println(a1+\" \"+a2+\"\\n\"+a3+\" \"+a4);\n else\n System.out.println(-1);\n }\n \n \n }\n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d3917716f2fa225fb5db4c599ff7171", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class helpVasilisa {\n public static void main(String[] args){\n Scanner input=new Scanner(System.in);\n int r1=input.nextInt();\n int r2=input.nextInt();\n int c1=input.nextInt();\n int c2=input.nextInt();\n int d1=input.nextInt();\n int d2=input.nextInt();\n int rlc,ruc,luc,llc;\n if(d1<10){\n rlc=d1-1;\n luc=d1-rlc;\n }else{\n rlc=9;\n luc=d1-rlc;\n }\n while(true){\n llc=c1-luc;\n if(llc>=10||(llc+rlc)!=r2){\n rlc--;\n luc++;\n continue;\n }\n if(rlc<=0||luc>10){\n System.out.println(\"-1\");\n return;\n }\n break;\n }\n ruc=c2-rlc;\n if(ruc>10||ruc<=0||ruc==luc||ruc==rlc||rlc==luc||rlc==llc||llc==luc){\n System.out.println(-1);\n }else{\n System.out.println(luc+\" \"+ruc);\n System.out.println(llc+\" \"+rlc);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ca00d17a36048775448db3ab6369a99", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Number25\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nlong n = sc.nextLong();\nlong a = 1;\nfor(int i = 0;i < n;i++)\n{\n a *= 5;\n}\nString s = String.valueOf(a);\nSystem.out.println(s.substring(s.length() - 2));\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a972ad27fe7c97253078ce59c3d840e0", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class AgainTwentyFive {\n public static void main(String[] args) {\n Scanner in= new Scanner (System.in);\n String n= in.next();\n Long N= new Long (Long.valueOf(n));\n Long z= new Long (0);\n Long l= N-1;\n Long power= new Long(5);\n for(Long i=z; i<=l; i++) {\n power*= 5;\n }\n String u=\"\"+ power;\n String t=\"\"+ u.charAt(u.length()-2)+u.charAt(u.length()-1);\n System.out.println(t); \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "309f37c78f9d6157855a02d5e76476e0", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class AgainTwentyFive {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n double n = in.nextDouble();\n double total = 5.0;\n for (int i = 0; i < n; i++) {\n total *= 5;\n }\n System.out.println((int)total % 100);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "503cea113509369343a68ff36d3c6f89", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Test{\n public static void main(String args[]){\n \n Scanner sc = new Scanner(System.in);\n \n String str = sc.next();\n \n BigInteger big1 = new BigInteger(str);\n BigInteger big2 = new BigInteger(\"5\");\n BigInteger big3 = new BigInteger(\"1\");\n BigInteger big4 = new BigInteger(\"5\");\n BigInteger big5 = new BigInteger(\"1\");\n \n while((big1.compareTo(big3)==1)){\n \n big2 = big2.multiply(big4);\n \n big1 = big1.subtract(big5);\n }\n \n String st = big2.toString();\n \n System.out.println(\"25\");\n }\n}\n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e9456316f0ec356806c9979419fac460", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class PetyaA\n{\n public static void main(String[] args){\n \n Scanner in = new Scanner(System.in);\n String num = in.nextLine();\n if((Long.toString(Long.MAX_VALUE)).compareTo(num)>0 || (Long.toString(Long.MIN_VALUE)).compareTo(num)>0){\n long numInt= Long.parseLong(num);\n if(numInt>=Byte.MIN_VALUE && numInt<=Byte.MAX_VALUE){\n System.out.println(\"byte\");\n }else if(numInt>=Short.MIN_VALUE && numInt<=Short.MAX_VALUE){\n System.out.println(\"short\");\n }else if(numInt>=Integer.MIN_VALUE && numInt<=Integer.MAX_VALUE){ \n System.out.println(\"int\");\n }else{ \n if (numInt>=Long.MIN_VALUE && numInt<=Long.MAX_VALUE){ \n System.out.println(\"long\");\n } \n }\n }else{\n System.out.println(\"BigInteger\");\n }\n \n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c616ad2cedb1b50864b0315453b59616", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Petya {\n\n public static void main(String[] args) {\n Scanner s=new Scanner(System.in);\n long n=s.nextLong();\n \n try{\n \n if(n>=-128&&n<=127)\n System.out.print(\"byte\");\n else if(n>=-32768 && n<=32767)\n System.out.print(\"short\");\n else if (n>=-2147483648 && n<=2147483647)\n System.out.println(\"int\");\n else \n System.out.println(\"long\");\n }\n catch(Exception ex){\n System.out.println(\"BigInteger\");\n }\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "004490d497cf9b0d76d5727a7bc27031", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "package test;\n\nimport java.util.Scanner;\nimport java.math.BigInteger;\n\npublic class Test {\n\n public static void main(String[] args) {\n BigInteger x,y,z,a,b;\n Scanner k = new Scanner(System.in);\n x = k.nextBigInteger();\n y=new BigInteger (\"127\");\n z=new BigInteger (\"32767\");\n a=new BigInteger (\"2147483647\");\n b=new BigInteger (\"9223372036854775807\");\n if (x.compareTo(y) == 1 || x.compareTo(y) == 0) \n System.out.println(\"byte\");\n else if (x.compareTo(z) == 1 || x.compareTo(z) == 0) \n System.out.println(\"short\");\n else if (x.compareTo(a) == 1 || x.compareTo(a)==0 ) \n System.out.println(\"int\");\n else if (x.compareTo(b) == 1 || x.compareTo(b) == 0) \n System.out.println(\"long\");\n else \n System.out.println(\"BigInteger\");\n }\n}\n//Okasha", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c275e0223c2136de097b48a3856e2e93", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\npublic class Main {\n public static void main(String[] args){\n Scanner sc= new Scanner(System.in);\n String line;\n \n while(sc.hasNextLine()){\n \n double a = sc.nextDouble();\n \n if(a<0){\n a+=1;\n }\n a= Math.abs(a);\n if(a q = new LinkedList<>();\n q.add(sx); q.add(sy);\n \n while(!q.isEmpty()){\n int x = q.poll();\n int y = q.poll();\n for(int k = 0; k < 4; k++){\n int nx = x + dx[k];\n int ny = y + dy[k];\n if(nx >= 0 && ny >= 0 && nx < C && ny < R && map[ny][nx] && d[ny][nx] == - 1){\n d[ny][nx] = d[y][x] + 1;\n q.add(nx);\n q.add(ny);\n }\n }\n }\n \n return d[ex][ey];\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\t//-----------------------------------------------------------\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n public void print1Int(int[] a){\n for(int i = 0; i < a.length; i++)\n System.out.print(a[i] + \" \");\n System.out.println();\n }\n \n public void print2Int(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 }\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a20b21a47cea9f34c77e23ab789cefda", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\npublic class A {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\t\n\t //out.println((Integer.toBinaryString(ni())).length());\n\t String s = ns();\n\t int a[][] = new int[10001][10001];\n\t int x = 100, y = 100;\n\t String ans = \"OK\";\n\t a[x][y] = 1;\n\t for(int i=0;i= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "30bb25dce477f9d6988c8f3809469c40", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\nimport java.math.*;\n \n\npublic class Main {\n\t\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\t\n\tstatic int n, ans1 = 1, ans2 = 1;\n\tstatic Integer[] arr;\n\tstatic int[] occur;\n\t\n\tpublic static void main(String args[]) throws Exception {\n\t\tFastReader cin = new FastReader();\n\n\t\tn = cin.nextInt();\n\t\tarr = new Integer[n];\n\t\toccur = new int[100005];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = cin.nextInt();\n\t\t\toccur[arr[i]] += 1;\n\t\t}\n\t\tArrays.parallelSort(arr);\n\t\t\n\t\tans2 = arr[n-1];\n\t\tfor (int i = n-2; i >= 0; i--) {\n\t\t\tif (ans2 % arr[i] != 0 || arr[i] == ans2 || occur[arr[i]] == 2) {\n\t\t\t\tans1 = arr[i];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(ans1 + \" \" + ans2);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "499bce4fafff593690ef929470a7d7a8", "src_uid": "868407df0a93085057d06367aecaf9be", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\n\n\npublic class today\n{\n\tpublic static void main(String ag[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n,t,i,j,k;\n\t\tj=0;\nint a=0;\nint b=0;\n\n\t\tn=sc.nextInt();\n\n\t\tint arr[]=new int[n];\n\t\tfor(i=0;i al=new ArrayList();\nif(n==2||arr[n-1]==arr[n-2])\nSystem.out.println(arr[n-1]+\" \"+arr[n-2]);\nelse\n{\n\n\tt=1;\n\t\t\t\tfor(i=2;i<=n-3;)\n\t\t\t\t{\n\t\t\t\t\tif(i<=n-3&&arr[i]==arr[i+1]&&(i+1<=n-2))\n\t\t\t\t\t{\n\t\t\t\t\t\tal.add(arr[i]);\n\t\t\t\t\t\ti=i+2;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\tif(al.size()>0){\n\t\t\t\tCollections.sort(al); t=al.get(al.size()-1);}\n\t\t\t\tfor(i=2;i<=n-2;i++)\n\t\t\t\t{\n\t\t\t\t\tif(k%arr[i]!=0&&arr[i]>t)\n\t\t\t\t\t{\n\t\t\t\t\tal.add(arr[i]); \n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif(al.size()>0)\n\t\t\t\t{\n\t\t\t\tCollections.sort(al);\n\t\t\t\tSystem.out.println(k+\" \"+al.get(al.size()-1));\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\tSystem.out.println(k+\" \"+1);\n\t\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\t\n\n}\n\n\t}\n}\n\nclass Tcomp implements Comparator\n{\n \n @Override\n public int compare(Node e1, Node e2) {\n if(e1.getValue() > e2.getValue()){\n return 1;\n } else {\n return -1;\n }\n }\n}\n\nclass Node\n{\n\tint key,value;\n\tNode(int key,int value)\n\t{\n\t\tthis.key=key;\n\t\tthis.value=value;\n\t}\n\n\tpublic int getKey()\n\t{\n\t\treturn this.key;\n\t}\n\tpublic int getValue()\n\t{\n\t\treturn this.value;\n\t}\n\tpublic void setValue(int k)\n\t{\n\t\tthis.value=k;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e063d34c21a9cc8e8f5292bb7a44154f", "src_uid": "868407df0a93085057d06367aecaf9be", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "//package com.company;\nimport java.util.*;\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 A[]=new int[n];\n for(int i=0;i=gcdi;j--)\n {\n if(A[n-1]%A[j]!=0)\n {\n System.out.print(A[j]);\n tmp++;\n break;\n }\n }\n if(tmp==0)\n {\n System.out.print(A[gcdi]);\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "722169e617caadfc8094bbb56bc278cf", "src_uid": "868407df0a93085057d06367aecaf9be", "difficulty": 1100.0} {"lang": "Java 11", "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 (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 }\nstatic boolean[] seen;\nstatic long[] arr;\n public static void main(String[] args) throws java.lang.Exception {\n FastReader scn = new FastReader();\n int n=scn.nextInt();\n \n List list = new ArrayList<>();\n for(int i=0;i=0 && (index+i)=0){\n if(array[index-i] == 1){\n count++;\n }\n } else if((index+i)=0 && k=0)\n\t\t{\n\t\t\tif(nums[j]==1)\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tj--;\n\t\t}\n\t\twhile(k=0 || r=0 && r=1&&right<=m2)\n\t\t{\n\t\t\tif(a1[left]!=a1[right])\n\t\t\t\tres--;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\tpublic static void main(String[] zima)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\t\n\t\tint m1=sc.nextInt();\n\t\tint m2=sc.nextInt();\n\t\tint[] a1=new int[m1+1];\n\t\t\n\t\tfor(int i=1;i1) s--;\n if (s<0) continue;\n y+=s;\n if (y>=n) {out.println(i*2+1); return;}\n }\n }\n}\n\nclass InputReader{\n private 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 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "717f6fad672be94eb6a3149f972fac5f", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\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 TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n static class TaskA {\n boolean f(int i1, int j1, int i2, int j2) {\n if (i1 == i2 && j1 == j2) return false;\n return Math.abs(i1 - i2) + Math.abs(j1 - j2) <= 1;\n }\n int good(int n) {\n boolean[][] taken = new boolean[n][n];\n for (int i = 0; i < n; i++) {\n outer:\n for (int j = 0; j < n; j++) {\n if (f(i, j, n - i - 1, j) || f(i, j, i, n - j - 1) || f(i, j, n - i - 1, n - j - 1)) {\n continue;\n }\n for (int k = 0; k < 4; k++) {\n int ni = i + MiscUtils.DX4[k];\n int nj = j + MiscUtils.DY4[k];\n if (MiscUtils.isValidCell(ni, nj, n, n)) {\n if (taken[ni][nj]) {\n continue outer;\n }\n }\n }\n taken[i][j] = true;\n }\n }\n int res = 0;\n for (boolean[] bb : taken) for (boolean b : bb) if (b) res++;\n return res;\n }\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int x = in.readInt();\n for (int side = 1; side <= 1000; side++) {\n int can = good(side);\n if (x % 4 == 0) {\n if (can >= x) {\n out.printLine(side);\n return;\n }\n }\n if (x % 4 == 1) {\n if (can % 4 == 1) {\n if (can >= x) {\n out.printLine(side);\n return;\n }\n }\n }\n }\n }\n }\n static class OutputWriter {\n private final PrintWriter writer;\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n public void close() {\n writer.close();\n }\n public void printLine(int i) {\n writer.println(i);\n }\n }\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n static class MiscUtils {\n public static final int[] DX4 = {1, 0, -1, 0};\n public static final int[] DY4 = {0, -1, 0, 1};\n public static boolean isValidCell(int row, int column, int rowCount, int columnCount) {\n return row >= 0 && row < rowCount && column >= 0 && column < columnCount;\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b46285ad385527256c0a75d6093dd39", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Moon{\n\tpublic static void main(String args[]){\n\t\tScanner sc = new Scanner (System.in);\n\t\tint n =sc.nextInt();\n\t\tint a[] = new int[n];\n\t\t\n\t\tfor(int i=0;in2){\n\t\t\t\tSystem.out.println(\"UP\");\n\t\t\t}\n\t\t}else if(a[n-1]==15){\n\t\t\tSystem.out.println(\"DOWN\");\n\t\t}else if(a[n-1]==0){\n\t\t\tSystem.out.println(\"UP\");\n\t\t}else {\n\t\t\tSystem.out.println(\"-1\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "46d568d4d37b3268c8d8cc3c947a1d30", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0} {"lang": "Java 8", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce1eccde8d3c8eea2b0d6993f75b2f34", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class problem {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int n,i,res,res1,res2;\n int[] number = new int[100000];\n n = input.nextInt();\n for(i=0;i0&&n!=1&&number[n-1]!=15)||number[n-1]==0)System.out.println(\"UP\");\n else if (res<0||number[n-1]==15)System.out.println(\"DOWN\");\n else System.out.println(\"-1\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "23b3a2ed11598aeb5cbee57aef199a97", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tFastReader scan = new FastReader();\n\t\t\n\t\tint n = scan.nextInt();\n\t\tint a = 0;\n\t\tint b = 0;\n\t\tboolean ans = false;\n\t\tboolean none = false;\n\t\t\n\t\tfor(int i=0; i 0) {\n\t\t\t\tif(a != 15) System.out.println(\"UP\");\n\t\t\t\telse System.out.println(\"DOWN\"); \n\t\t\t} else if(a - b < 0) {\n\t\t\t\tif(a == 0) System.out.println(\"UP\");\n\t\t\t\telse System.out.println(\"DOWN\");\n\t\t\t}\n\t\t}\n\t\t\n }\n\t\n\t// sieveOfEratosthenes \n\tpublic static boolean[] sieve(int n) {\n\t\tboolean[] prime = new boolean[n+1];\n\t\t\n\t\tArrays.fill(prime, true);\n\t\tprime[0] = false;\n\t\tprime[1] = false;\n\t\t\n\t\tfor(int i=2; i*i0){\n if(s.charAt(i)==s.charAt(j)){\n c++;\n continue;\n }\n j--;\n \n }\n }\n if((s.length()-c)%2==0){\n System.out.println(\"IGNORE HIM!\");\n }\n else{\n System.out.println(\"CHAT WITH HER!\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa12c2494f93cdea4e71ed0d69260702", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class BoyOrGirl{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n String s=sc.nextLine();\n int c=0,j=0;\n for(int i=0;i=0){\n if(s.charAt(i)==s.charAt(j)){\n c++;\n continue;\n }\n j--;\n \n }\n }\n if((s.length()-c)%2==0){\n System.out.println(\"IGNORE HIM!\");\n }\n else{\n System.out.println(\"CHAT WITH HER!\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2df1d71fc49b9bbef91e2c66567363e1", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport static java.lang.Math.*;\n\npublic class ProblemD {\n \n public static void main(String[] args) throws IOException {\n init();\n new ProblemD().run();\n out.flush();\n out.close();\n }\n \n static void init() throws IOException {\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n in.ordinaryChars(0, 65535);\n in.wordChars(0, 65535);\n in.whitespaceChars(' ', ' ');\n in.whitespaceChars('\\n', '\\n');\n in.whitespaceChars('\\r', '\\r');\n }\n\n // \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u0430\u0440\n class Pair implements Comparable{\n private final L X;\n private final R Y;\n\n public Pair(L X, R Y) {\n this.X = X;\n this.Y = Y;\n }\n\n public L getX() {\n return X;\n }\n\n public R getY() {\n return Y;\n }\n\n @Override\n public int hashCode() {\n return X.hashCode() ^ Y.hashCode();\n }\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Pair)) return false;\n Pair pairo = (Pair) o;\n return X.equals(pairo.getX()) && Y.equals(pairo.getY());\n }\n\n @Override\n public String toString() {\n return \"Pair{\" +\n \"X=\" + X +\n \", Y=\" + Y +\n '}';\n }\n\n @Override\n public int compareTo(Object o) {\n Pair oPair = (Pair)o;\n Comparable cX = (Comparable)this.X;\n Comparable cY = (Comparable)this.Y;\n if (cX.compareTo(oPair.X) > 0 || (cX.compareTo(oPair.X) == 0 && cY.compareTo(oPair.Y) > 0)) {\n return 1;\n } else if (cX.compareTo(oPair.X) == 0 && cY.compareTo(oPair.Y) == 0) {\n return 0;\n } else {\n return -1;\n }\n }\n }\n \n static final long INFL = 200000000000000000L;\n static final int INF = 2000000000;\n static final boolean DEBUG = true;\n \n static StreamTokenizer in;\n static PrintWriter out;\n \n static void print(String s) {\n print(s, 0);\n }\n \n static void print(String s, int debug) {\n if (debug == 0 || DEBUG) {\n out.print(s);\n }\n }\n \n static void println(String s) {\n println(s, 0);\n }\n \n static void println(String s, int debug) {\n if (debug == 0 || DEBUG) {\n out.println(s);\n }\n }\n \n static void printArray(int[] arr) {\n println(Arrays.toString(arr));\n }\n \n static void printArray(char[] arr) {\n println(Arrays.toString(arr));\n }\n \n static void printArray(String[] arr) {\n println(Arrays.toString(arr));\n }\n \n static char[] inChars;\n static int inCharsInd;\n \n static String next() throws IOException {\n in.nextToken();\n return in.sval;\n }\n \n static char nextChar() throws IOException {\n while (inChars == null || inCharsInd >= inChars.length) {\n inChars = next().toCharArray();\n inCharsInd = 0;\n }\n return inChars[inCharsInd++];\n }\n \n static int nextInt() throws IOException {\n return Integer.valueOf(next());\n }\n \n static double nextDouble() throws IOException {\n return Double.valueOf(next());\n }\n \n static long nextLong() throws IOException {\n return Long.valueOf(next());\n }\n \n private void run() throws IOException {\n solve();\n }\n\n long M;\n Pair best = new Pair<>(0L, 0L);\n\n\n private void solve() throws IOException {\n M = nextLong();\n recur(M, 0, 0);\n out.println(best.getX() + \" \" + best.getY());\n }\n\n\n private void recur(long M, long steps, long substracted) {\n// out.println(M);\n if (M == 0){\n Pair p = new Pair(steps, substracted);\n best = (best.compareTo(p)>=0)?best:p;\n return;\n }\n long sqrt = 1;\n while(pow(sqrt+1, 3) <= M) sqrt++;\n long myPow = (long)pow(sqrt, 3);\n recur(M - myPow, steps+1, substracted + myPow);\n if (sqrt - 1 >= 1){\n long myPowMinus = (long)pow(sqrt-1, 3);\n recur(myPow - 1 - myPowMinus, steps+1, substracted + myPowMinus);\n }\n }\n\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd4da2b49d47e65f66c56cacef6fe132", "src_uid": "385cf3c40c96f0879788b766eeb25139", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class D356 {\n\n public static Result best;\n\n public static void main(String[] args) {\n\n Scanner scanner = new Scanner(System.in);\n\n long m = scanner.nextInt();\n\n search(m, 0, 0);\n\n System.out.printf(\"%s %s\\n\", best.steps, best.number);\n\n }\n\n private static void search(long m, int step, long num) {\n //System.out.println(m);\n if (m == 0) {\n Result current = new Result(num, step);\n if (best == null || best.compareTo(current) < 0) {\n best = current;\n }\n return;\n }\n\n long x = 1;\n while (cubic(x + 1) <= m) {\n x++;\n }\n search(m - cubic(x), step + 1, num + cubic(x));\n if (x - 1 >= 0) {\n search(cubic(x) - 1 - cubic(x - 1), step + 1, num + cubic(x - 1));\n }\n }\n\n private static long cubic(long x) {\n return x * x * x;\n }\n\n public static class Result implements Comparable {\n long number;\n int steps;\n\n public Result(long number, int steps) {\n this.number = number;\n this.steps = steps;\n }\n\n\n @Override\n public int compareTo(Result o) {\n int cmp = Integer.compare(steps, o.steps);\n if (cmp == 0) {\n cmp = Long.compare(number, o.number);\n }\n return cmp;\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "852834a25ea4f2fdbc8ca486044ddba0", "src_uid": "385cf3c40c96f0879788b766eeb25139", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class bear_tower\n{\n\t\n\tpublic long floorCube(long n)\n\t{\n\t\tfor (long i = 1; i<= n; i++)\n\t\t{\n\t\t\tif (i*i*i > n)\n\t\t\t\treturn(i-1);\n\t\t\telse if (i*i*i == n)\n\t\t\t\treturn(i);\n\t\t}\n\t\treturn(0);\n\t\t\n\t}\n\t\n\tpublic long Cube(long j)\n\t{\n\t\treturn(j*j*j);\n\t}\n\t\n\tpublic long NoCubes(long k)\n\t{\n\t\tlong volleft = k;\n\t\tlong num = 0;\n\t\t\twhile (volleft != 0)\n\t\t\t{\n\t\t\t\tlong j = floorCube(volleft);\n\t\t\t\t\n\t\t\t\tif (j == 1)\n\t\t\t\t{\n\t\t\t\t\tnum += volleft; \n\t\t\t\t\tvolleft = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\t\t\n\t\t\t\t\n\t\t\t\tvolleft -= Cube(j); \n\t\t\t\tnum += 1;\t\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\treturn(num);\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\tlong m = sc.nextLong();\n\t\tbear_tower dd = new bear_tower();\n\t\tlong max = 0;\n\t\tlong X = 0;\n\t\tint [] index = new int [(int)(m/(long)Math.sqrt(m)) + 1];\n\t\tint [] ind_start = new int [(int)(m/(long)Math.sqrt(m)) ];\n\t\tint [] ind_stop = new int [(int)(m/(long)Math.sqrt(m)) ];\n\t\tint k = 0;\n\t\tfor (int i = 0; i < m ; i+= (int)Math.sqrt(m))\n\t\t{\n\t\t\tif (k<=(int)(m/(long)Math.sqrt(m)))\n\t\t\t{\n\t\t\t\tindex[k] = i;\n\t\t\t\tif (k > 0)\n\t\t\t\t\tind_start[k] = index[k]+1;\n\t\t\t\telse\n\t\t\t\t\tind_start[k] = index[k];\n\t\t\t\t\n\t\t\t\tind_stop[k] = index[k] + (int)Math.sqrt(m);\n\t\t\t\tk++;\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\n\t\tlong [] to = new long [2];\n\t\tlong ma = 0;\n\t\t\n\t\tfor (int i = 0; i< ind_start.length; i++)\n\t\t{\n\t\t\tlong two = Math.max(dd.NoCubes(ind_start[i]), dd.NoCubes(ind_stop[i]));\n\t\t\t//System.out.println(ind_start[i]+\"-->\"+ind_stop[i]+\" \"+two+\" \"+ma);\n\t\t\tif (ma < two)\n\t\t\t{\n\t\t\t\tto[0] = ind_start[i];\n\t\t\t\tto[1] = ind_stop[i];\n\t\t\t\tma = two;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\t\n\t\t\n\t\t\n\t\t//System.out.println(to[0]+\" \"+to[1]);\n\t\t\n\t\tfor (long i = to[0]; i <= to[1]; i++)\n\t\t{\n\t\t\tif (dd.NoCubes(i) >= max)\n\t\t\t{\n\t\t\t\tmax = dd.NoCubes(i);\n\t\t\t\tX = i;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max+\" \"+X);\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "31cc3e2792a28d87ec36d277b8996b5d", "src_uid": "385cf3c40c96f0879788b766eeb25139", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class BearTowerCubes {\n\n static final int MAXN = 100001;\n\n long[] p = new long[MAXN];\n\n {\n for (int i = 1; i < MAXN; i++) p[i] = (long) i * i * i;\n }\n\n void solve() {\n long m = in.nextLong();\n long sum = 0, cnt = 0;\n while (m > 0) {\n int x = 1;\n while (p[x + 1] <= m) x++;\n if (steps(m) == 1 + steps(m - p[x])) {\n m -= p[x];\n sum += p[x];\n } else {\n m = p[x] - 1 - p[x - 1];\n sum += p[x - 1];\n }\n cnt++;\n }\n out.printf(\"%d %d%n\", cnt, sum);\n }\n\n long steps(long m) {\n if (m < 8) return m;\n int x = 1;\n while (p[x + 1] <= m) x++;\n return 1 + steps(Math.max(m - p[x], p[x] - 1 - p[x - 1]));\n }\n\n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new BearTowerCubes().solve();\n out.close();\n }\n\n static FastScanner in;\n static PrintWriter out;\n\n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n\n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n\n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24ffe99193bd749a04d2e55671812f8d", "src_uid": "385cf3c40c96f0879788b766eeb25139", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class codechef\n{\n\tpublic static long fact(int n)\n\t{\n\t\tlong arr[] = new long[n+1];\n\t\tarr[0]=1;\n\t\tarr[1]=1;\n\t\tfor(int i =2;i=0)\n \t{\n \t\tint d = x.nextInt();\n \t\tString st = x.next();\n \t\tint p =0;\n \t\tint c =0;\n \t\tfor(int i =0;i1)\n {\n int z=k;\n int count=0;\n while(z>=h)\n {\n z=z-h;\n count++;\n }\n for (int i = 0; i < h; i++)\n {\n arr[i]=count;\n if(i=2)\n {\n total+=(getFact(arr[i])/(getFact(arr[i]-2)*getFact(2)));\n }\n }\n }\n else\n {\n arr[0]=k;\n if(arr[0]>=2)\n {\n total+=(getFact(arr[0])/(getFact(arr[0]-2)*getFact(2)));\n }\n }\n return total;\n }\n public static void main(String[] args)\n {\n Scanner scan=new Scanner(System.in);\n int m=scan.nextInt(); //members number\n int n=scan.nextInt(); //teams number\n System.out.println(getMin(m, n)+\" \"+getMax(m, n));\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ee1af13c73fee6e09901e20a698dc55f", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "package Practice;\nimport java.io.*;\nimport java.util.*;\npublic class ACM_Anyone {\n\n private static final Scanner LS = new Scanner(System.in);\n private static final BufferedReader LF = new BufferedReader(new InputStreamReader(System.in));\n private static final BufferedWriter EF = new BufferedWriter(new OutputStreamWriter(System.out));\n public static void main(String[] args) throws IOException {\n \n int m = LS.nextInt() , n = LS.nextInt();\n int min = m / n;\n long qmin;\n if (m % n == 0) \n qmin = n * ((min - 1) + (min - 1) * (min - 1)) / 2;\n else {\n qmin = (((min - 1) + (min - 1) * (min - 1)) / 2) + (m % n) * (((min) + (min) * (min)) / 2);\n }\n for (int i = 1 ; i <= 10; i++) {\n \n }\n long qmax = ((m - n) + (m - n) * (m - n)) / 2;\n System.out.println(qmin+\" \"+qmax);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "94548631477dac44bc59e7a67e65f57c", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class codechef\n{\n\tpublic static int fact(int n)\n\t{\n\t\tif(n<2)\n\t\t\treturn 1;\n\t\treturn n*fact(n-1);\n\t}\n\tpublic static int combi(int n,int r)\n\t{\n\t\treturn fact(n)/(fact(r)*fact(n-r));\n\t}\n public static void main(String args[])\n {\n Scanner x = new Scanner(System.in);\n int n = x.nextInt();\n int m = x.nextInt();\n int min,max;\n if(n%m==0)\n {\n \tmin = combi((int)Math.ceil(1.0*n/m),2)*m;\n }\n else\n \tmin = combi((int)Math.ceil(1.0*n/m),2)*m-(int)Math.ceil((n-m)/2.0);\n max = combi(n-(m-1),2);\n System.out.println(min+\" \"+max);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0b860cfc0f309e3447ee930acdd9e11e", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\n\npublic class MagicSpheres {\n public static void main (String[] args){\n Scanner scan;\n scan = new Scanner(System.in);\n while(true){\n try{\n //String stones = scan.nextLine();\n // String needed = scan.nextLine();\n // String[] l = stones.split(\" \");\n int a = scan.nextInt();\n int b = scan.nextInt();\n int c = scan.nextInt();\n // String[] m = needed.split(\" \");\n int ac = scan.nextInt();\n int bc = scan.nextInt();\n int cc = scan.nextInt();\n if (a == ac && b==bc && c==cc){\n System.out.println(\"Yes\");\n }\n else if(a> ac && b > bc && c>cc){\n System.out.println(\"Yes\");\n continue;\n }else if (a< ac && b < bc && c auxI)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }else{\n if(auxIII > auxI)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n }else if(auxII <0){\n if(auxI < auxIII){\n if(auxI > auxIII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }else{\n if(auxIII > auxII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n }else if(auxIII <0){\n if(auxI < auxII){\n if(auxI > auxIII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }else{\n if(auxII > auxIII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n }\n \n \n }catch (Exception e){}\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e2ec86dcc3972abfc7278a884573a1db", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\n\npublic class MagicSpheres {\n public static void main (String[] args){\n Scanner scan;\n scan = new Scanner(System.in);\n while(true){\n try{\n String stones = scan.nextLine();\n String needed = scan.nextLine();\n String[] l = stones.split(\" \");\n int a = Integer.parseInt(l[0]);\n int b = Integer.parseInt(l[1]);\n int c = Integer.parseInt(l[2]);\n String[] m = needed.split(\" \");\n int ac = Integer.parseInt(m[0]);\n int bc = Integer.parseInt(m[1]);\n int cc = Integer.parseInt(m[2]);\n if(a> ac && b > bc && c>cc){\n System.out.println(\"Yes\");\n continue;\n }else if (a< ac && b < bc && c auxI)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }else{\n if(auxIII > auxI)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n }else if(auxII <0){\n if(auxI < auxIII){\n if(auxI > auxIII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }else{\n if(auxIII > auxII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n }else if(auxIII <0){\n if(auxI < auxII){\n if(auxI > auxIII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }else{\n if(auxII > auxIII)System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n }\n \n \n }catch (Exception e){}\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ad43ddeb5c9f533e5b6c1e3ba9cdba1", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Magic_sphere{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int[] arr=new int[3];\n \n int[] arr1=new int[3];\n int i=0;\n for(i=0;i<3;i++){\n arr[i]=sc.nextInt();\n }\n for(i=0;i<3;i++){\n arr1[i]=sc.nextInt();\n }\n int temp=0;\n for(i=0;i<3;i++){\n while((arr[i]-1)>arr1[i]){\n temp++;\n arr[i]=arr[i]-2;\n }\n }\n for(i=0;i<3;i++){\n while(arr[i]=0){\n System.out.println(\"Yes\");\n }\n else{\n System.out.println(\"No\");\n }\n }\n}\n \n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2478d09a4f5609d58138e1d6ad0725bc", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n int x, y, z;\n int[] xyz;\n\n int sum(int[] a) {\n int res = 0;\n for ( int i = 0; i < a.length; ++i ) {\n res += a[ i ];\n }\n return res;\n }\n\n boolean dfs(int[] abc, int s) {\n if ( sum(abc) < x + y + z ) {\n return false;\n }\n if ( sum(abc) == x + y + z ) {\n int a = abc[ 0 ];\n int b = abc[ 1 ];\n int c = abc[ 2 ];\n return a == x && b == y && c == z;\n }\n boolean res = false;\n\n int st = Math.max(0, (abc[ s ] - xyz[ s ] + 1) / 4);\n for ( int i = st; i * 2 <= abc[ s ]; ++i ) {\n for ( int j = 0; j < 3; ++j ) {\n if ( s == j ) {\n continue;\n }\n int[] next = Arrays.copyOf(abc, 3);\n next[ s ] -= i * 2;\n next[ j ] += i;\n res |= dfs(next, (s + 1) % 3);\n }\n }\n\n return res;\n }\n\n void run() {\n int a = ni();\n int b = ni();\n int c = ni();\n\n x = ni();\n y = ni();\n z = ni();\n xyz = new int[]{ x, y, z };\n\n System.out.println(dfs(new int[]{ a, b, c }, 0) ? \"Yes\" : \"No\");\n }\n\n Scanner sc;\n\n Main() {\n sc = new Scanner(System.in);\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n int ni() {\n return sc.nextInt();\n }\n\n long nl() {\n return sc.nextLong();\n }\n\n void debug(Object... os) {\n System.err.println(Arrays.deepToString(os));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c27d117d34cd74c0febbb272ba6d2d5", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package ch13;\n\nimport java.util.Scanner;\npublic class MinimumK {\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input=new Scanner(System.in);\n\t\tint num=input.nextInt();\n\t\tint[] arr=new int[num];\n\t\tint minK=-999;\n\t\tint sum=0;\n\t\tfor (int i=0;isum)\n\t\t\t\tflag=true;\n\t\t\telse\n\t\t\t\tminK++;\n\t\t}\n\t\tSystem.out.println(minK);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96b98a40f1bfa7943110596c5fbb2819", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\nimport java.io.PrintWriter;\n\nimport java.util.StringTokenizer;\n\npublic class Main {\n \n static Scanner s = new Scanner();\n static PrintWriter out = new PrintWriter(System.out);\n \n public static void main(String[] args) throws IOException {\n int n = s.nextInt(), max = 0, sum = 0, u;\n for(int i = 0; i < n; i++) {\n int a = s.nextInt();\n sum += a;\n max = Math.max(max, a);\n }\n u = 2 * sum - max * n;\n out.print(Math.max(max, max + u / n + u / Math.abs(u)));\n out.close();\n }\n\n static class Scanner {\n BufferedReader in;\n StringTokenizer s;\n \n public Scanner() {\n in = new BufferedReader(new InputStreamReader(System.in));\n s = new StringTokenizer(\"\");\n }\n \n public String next() throws IOException {\n if(!s.hasMoreTokens())\n s = new StringTokenizer(in.readLine());\n return s.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b475965a96594e6d7f918f7b2570dd32", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0} {"lang": "Java 8", "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.StringTokenizer;\n\npublic class Hello {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tInputReader sc = new InputReader(System.in);\n\t\tint n = sc.nextInt();\n\t\tint sum = 0, max = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint num=sc.nextInt();\n\t\t\tsum += sc.nextInt();\n\t\t\tif (num > max) {\n\t\t\t\tmax = num;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(Math.max(max, (2*sum / n) + 1));\n\t}\n\n\tstatic class InputReader {\n\t\tStringTokenizer tokenizer;\n\t\tBufferedReader reader;\n\t\tString token;\n\t\tString temp;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\ttokenizer = null;\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic InputReader(FileInputStream stream) {\n\t\t\ttokenizer = null;\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn reader.readLine();\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\tif (temp != null) {\n\t\t\t\t\t\ttokenizer = new StringTokenizer(temp);\n\t\t\t\t\t\ttemp = null;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t\t}\n\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\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\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5429e31e85060404744f21e93adeff5d", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package com.company;\nimport java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n int mx = 0, sum = 0;\n StringTokenizer st = new StringTokenizer(br.readLine());\n for(int i = 0; i < n; i++){\n int a = Integer.parseInt(st.nextToken());\n mx = Math.max(mx, a);\n sum += a;\n }\n\n sum *= 2;\n sum += n;\n sum /= n;\n\n System.out.println(Math.max(sum,mx));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d225816a5b66bf3d16051faa92d8e93e", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package kattis;\n\n\n\nimport java.io.*;\nimport java.util.*;\n\npublic class AE23 {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tIO io = new IO(System.in);\n\t\tint x1 = io.nextInt();\n\t\tint y1 = io.nextInt();\n\t\tint x2 = io.nextInt();\n\t\tint y2 = io.nextInt();\n\t\tint x = io.nextInt();\n\t\tint y = io.nextInt();\n\t\tboolean err = false;\n\t\terr = err || (x1-x2)%x != 0;\n\t\terr = err || (y1-y2)%y != 0;\n\t\terr = err || ((y1-y2)/y + (x1-x2)/x)%2 != 0;\n\t\tio.println(err?\"NO\":\"YES\");\n\t\tio.close();\n\t}\n\t\n\t\n\tstatic class IO extends PrintWriter {\n\t\tstatic BufferedReader r;\n\t\tstatic StringTokenizer t;\n\n\t\tpublic IO(InputStream i) {\n\t\t\tsuper(new BufferedOutputStream(System.out));\n\t\t\tr = new BufferedReader(new InputStreamReader(i));\n\t\t\tt = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (!t.hasMoreTokens()) {\n\t\t\t\tt = new StringTokenizer(r.readLine());\n\t\t\t}\n\t\t\treturn t.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 double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6943f400b97b8e7c1f0feb1251c0f61c", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n/**\n *\n * @author Public\n */\npublic class Treasure_hunt {\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int x1=sc.nextInt();\n int y1=sc.nextInt();\n int x2=sc.nextInt();\n int y2=sc.nextInt();\n int x=sc.nextInt();\n int y=sc.nextInt();\n if(x1==x || y1==y){}\n else{\n if(x1x2){\n x1=x1-x;}\n if(y1y2){\n y1=y1-y;\n }}\n if(x2%x1==0 && y2%y1==0){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a1ef4d7625365421419e1710d5ec917e", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package cf817;\n\nimport java.util.Scanner;\n\npublic class MainA {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString[] array = in.nextLine().split(\" \");\n\t\tint x1 = Integer.parseInt(array[0]);\n\t\tint y1 = Integer.parseInt(array[1]);\n\t\tint x2 = Integer.parseInt(array[2]);\n\t\tint y2 = Integer.parseInt(array[3]);\n\t\tarray = in.nextLine().split(\" \");\n\t\tint x = Integer.parseInt(array[0]);\n\t\tint y = Integer.parseInt(array[1]);\n\t\t\n\t\tif(Math.abs(x1 - x2) % x != 0 || Math.abs(y1 - y2) % y != 0) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}else {\n\t\t\tint xstep = Math.abs((x1 - x2)) / x;\n\t\t\tint ystep = Math.abs((y1 - y2)) / y;\n\t\t\tif((xstep - ystep) % 2 != 0) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}else {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t}\n\t\t\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6936f02b0a2b92500bfd0fd56d7ea6d2", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by abgupta on 6/15/17.\n */\npublic class C_817_A {\n\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\n int dx = Math.abs(x1-x2);\n int dy = Math.abs(y1-y2);\n\n int x = in.nextInt();\n int y = in.nextInt();\n\n if (dx % x != 0 || dy % y != 0) {\n System.out.println(\"No\");\n return;\n }\n\n\n int maxv = 200000;\n\n int d1 = dx/x;\n int d2 = dy/y;\n\n\n for(int s1=0;s1= 0 && d%2 == 0) {\n StringBuilder y = new StringBuilder(s);\n if (l < r) { \n y.insert(x, t.substring(0, r-l));\n x += r-l;\n }\n else \n y.append(t.substring(0, l-r));\n int c = Math.abs(r-l); \n y.insert(x, t.substring(c, c+d/2));\n y.append(t.substring(c+d/2));\n System.out.println(y);\n }\n else \n System.out.print(\"Impossible\");\n }\n\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60f6128068553fd43648b22ed8894396", "src_uid": "917f173b8523ddd38925238e5d2089b9", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tvoid solve() {\n\t\tString[] s = in.next().split(\"\\\\|\");\n\t\tString s2 = in.next();\n\t\tint total = s[0].length() + s[1].length() + s2.length();\n\t\tif (total % 2 == 1) {\n\t\t\tout.println(\"Impossible\");\n\t\t\treturn;\n\t\t}\n\t\tint need = total / 2;\n\t\tif (s[0].length() > need || s[1].length() > need) {\n\t\t\tout.println(\"Impossible\");\n\t\t\treturn;\n\t\t}\n\t\tint it = 0;\n\t\tout.print(s[0]);\n\t\tfor (int i = 0; i < need - s[0].length(); i++) {\n\t\t\tout.print(s2.charAt(it++));\n\t\t}\n\t\tout.print(\"|\" + s[1]);\n\t\tfor (int i = 0; i < need - s[1].length(); i++)\n\t\t\tout.print(s2.charAt(it++));\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "89c2276f6921c93c73d2ba94b5fde2f2", "src_uid": "917f173b8523ddd38925238e5d2089b9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\n/**\n *\n * @author Ahmed\n */\npublic class Test {\n\n /**\n * @param args the command line arguments\n * @throws java.io.IOException\n *\n *\n *\n */\n static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n\n public static void main(String[] args) throws IOException {\n\n String w1 = in.readLine();\n String w2 = in.readLine();\n boolean k = true;\n int z = 0, n = 0;\n for (int i = 0; i < w1.length(); i++) {\n if (k) {\n\n if (w1.charAt(i) == '|') {\n k = false;\n continue;\n }\n z++;\n } else if (!k) {\n n++;\n }\n\n }\n if (z == n + w2.length()) {\n out.write(w1 + w2);\n } else if (n == z + w2.length()) {\n out.write(w2 + w1);\n } else if (((n + z + w2.length()) & 1) == 0) {\n String zz = w2.substring(0, ((n + z + w2.length()) / 2) - z);\n String nn = w2.substring(((n + z + w2.length()) / 2) - z);\n if (zz.length() + z != (n + z + w2.length()) / 2 || nn.length() + n != (n + z + w2.length()) / 2) {\n out.write(\"Impossible\");\n\n } else {\n out.write(zz + w1 + nn);\n }\n\n } else {\n out.write(\"Impossible\");\n }\n out.flush();\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3fdbeb3a62434446e2df6daff7a9f8bd", "src_uid": "917f173b8523ddd38925238e5d2089b9", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A244 {\n\n public static void main(String[] args) throws IOException {\n BufferedReader I = new BufferedReader(new InputStreamReader(System.in));\n String s = I.readLine();\n StringBuffer x = new StringBuffer(I.readLine());\n char ss[] = s.toCharArray();\n boolean z = false,a=false;\n String _1 = \"\";\n String _2 = \"\";\n for (int i = 0; i < ss.length; i++) {\n if (ss[i] == '|') {\n z = true;\n continue;\n }\n if (!z) {\n _1 += ss[i];\n } else {\n _2 += ss[i];\n }\n }\n if (_1.length() < _2.length() && _1.length() + x.length() == _2.length()) {\n\n System.out.println(_1 + x + \"|\" + _2);\n\n } else if (_1.length() > _2.length() && _2.length() + x.length() == _1.length()) {\n\n System.out.println(_1 + \"|\" + _2 + x);\n\n } else{\n while(x.length()>0){\n if(_1.length()>_2.length()){\n _2=_2+x.charAt(0);\n x.deleteCharAt(0);\n }\n if(_1.length()<_2.length()){\n _1=_1+x.charAt(0);\n x.deleteCharAt(0);\n }\n if(_1.length()==_2.length()&&x.length()%2==0&&x.length()>0){\n _1=_1+x.charAt(0);\n x.deleteCharAt(0);\n }\n \n }\n if(_1.length()==_2.length()&&x.length()==0)\n System.out.println(_1 + \"|\" + _2);\n else\n System.out.println(\"Impossible\");\n \n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cb50e83a2d9127d019c90bdbb656e740", "src_uid": "917f173b8523ddd38925238e5d2089b9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package com.example.hackerrank;\n\nimport 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 Hackerrank{\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 public static int maxval = Integer.MAX_VALUE;\n public static int minval = Integer.MIN_VALUE;\n public static void main(String[] args)throws java.lang.Exception\n {\n new Hackerrank().run();\n out.close();\n }\n void run() throws java.lang.Exception\n {\n int[] a = new int[12];\n a[0] = a[2] = a[4] = a[6] = a[7] = a[9] = a[11] = 31;\n a[1] = 28;\n a[3] = a[5] = a[8] = a[10] = 30;\n int m = ni() - 1, d = ni();\n if(a[m] == 31){\n if(d == 7 || d == 6){\n out.println(\"6\");\n } else {\n out.println(\"5\");\n }\n } else if(a[m] == 30){\n if(d == 7) {\n out.println(\"6\");\n } else {\n out.println(\"5\");\n }\n } else {\n if(d == 1){\n out.println(\"4\");\n } else {\n out.println(\"5\");\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= 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "73f5eb477cf1d39790c96ce6e145c952", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Petr {\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tint m = Integer.parseInt(reader.readLine());\n\t\tint d = Integer.parseInt(reader.readLine());\n\t\t\n\t\tint brDana,brTjedana=0;\n\t\t\n\t\tif( (m<=7 && m%2==1) || (m>=8 && m%2==0) )\n\t\t\tbrDana=31;\n\t\telse if( m == 2 )\n\t\t\tbrDana=28;\n\t\telse\n\t\t\tbrDana=30;\n\t\t\n\t\tbrDana = brDana - (7-d) -1;\n\t\tbrTjedana++;\n\t\t\n\t\tfor(;brDana>0;brDana-=7)\n\t\t\tbrTjedana++;\n\t\t\n\t\tSystem.out.println(brTjedana);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "52499dd6121266c05620fd455a2c3cc0", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\n\npublic class A {\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint m = in.nextInt();\n\t\tint d = in.nextInt();\n\t\t\n\t\tint md = 0;\n\t\tif (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)\n\t\t\tmd = 31;\n\t\telse if (m == 2)\n\t\t\tmd = 28;\n\t\telse \n\t\t\tmd = 30;\n\t\t\n\t\td = 7 - (7 - d + 1);\n\t\tSystem.out.println((d + md) / 6);\n\t\t\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d59200ae24c5e57b34de0af603577053", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.InputMismatchException;\n\n\npublic class temp{\n\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputWriter out = new OutputWriter(System.out);\n\t\tint n = in.readInt();\n\t\tint m = in.readInt();\n\t\tif(n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12 ){\n\t\t\tif(m >= 5){\n\t\t\t\tSystem.out.println(6);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(5);\n\t\t\t}\n\t\t}else if(n == 2){\n\t\t\tif(m != 1){\n\t\t\t\tSystem.out.println(5);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(4);\n\t\t\t}\n\t\t}else{\n\t\t\tif(m > 6){\n\t\t\t\tSystem.out.println(6);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(5);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tout.close();\n\t}\n\n\nprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n \n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tlong sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tstatic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tpublic String next() {\n\t\t\treturn readString();\n\t\t}\n\t}\n \n\tprivate static class OutputWriter {\n\t\tprivate final PrintWriter writer;\n \n\t\tpublic OutputWriter(OutputStream outputStream) {\n\t\t\twriter = new PrintWriter(outputStream);\n\t\t}\n \n\t\tpublic OutputWriter(Writer writer) {\n\t\t\tthis.writer = new PrintWriter(writer);\n\t\t}\n \n\t\tpublic void print(Object... objects) {\n\t\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\t\tif (i != 0)\n\t\t\t\t\twriter.print(' ');\n\t\t\t\twriter.print(objects[i]);\n\t\t\t}\n\t\t}\n \n\t\tpublic void printLine(Object... objects) {\n\t\t\tprint(objects);\n\t\t\twriter.println();\n\t\t}\n \n\t\tpublic void close() {\n\t\t\twriter.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "744c50c2a313abfd6a031607d5568ad5", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Codeforces {\n\n public static void main(String[] args) throws IOException {\n Reader.init(System.in);\n n = Reader.nextInt();\n int limt = ((n+\"\").length() / 2) * 2;\n \n lucky(0, limt, \"\");\n \n System.out.println(min);\n \n }\n static long min = Long.MAX_VALUE;\n static int n;\n \n public static void lucky(int i, int lim, String num){\n if(i == lim){\n \n int c = 0;\n \n for(int j = 0; j < num.length(); j++)\n if(num.charAt(j) == '4')\n c++;\n \n if(c != lim / 2)\n return;\n \n long x = Long.parseLong(num);\n \n if(x >= n && x < min)\n min = x;\n \n return;\n }\n \n lucky(i+1, lim, num + '4');\n lucky(i+1, lim, num + '7');\n }\n}\n\nclass Reader {\n\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n /**\n * call this method to initialize reader for InputStream\n */\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input));\n tokenizer = new StringTokenizer(\"\");\n }\n\n /**\n * get next word\n */\n static String next() throws IOException {\n while (!tokenizer.hasMoreTokens()) {\n //TODO add check for eof if necessary\n tokenizer = new StringTokenizer(\n reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n static byte nextByte() throws IOException {\n\n return Byte.parseByte(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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa880601921a152f66d7abf5524766b2", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class B {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile(sc.hasNext()) {\n\t\t\tint min = sc.nextInt();\n\t\t\tint n = 0;\n\t\t\twhile(true) {\n\t\t\t\tn = next(n);\n\t\t\t\tif(same(n) && n>=min) {\n\t\t\t\t\tSystem.out.println(n);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate static int next(int n) {\n\t\tif(n==0) return 47;\n\t\tStringBuffer sb = new StringBuffer(String.valueOf(n));\n\t\tfor(int i=sb.length()-1;i>=0;i--) {\n\t\t\tif(sb.charAt(i)=='7') {\n\t\t\t\tsb.setCharAt(i, '4');\n\t\t\t} else {\n\t\t\t\tsb.setCharAt(i, '7');\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(sb.indexOf(\"7\")==-1) sb.insert(0, \"4\");\n\t\treturn Integer.valueOf(sb.toString());\n\t}\n\t\n\tprivate static boolean same(int n) {\n\t\tint four = 0, seven = 0;\n\t\twhile(n>0) {\n\t\t\tint d = n%10;\n\t\t\tn/=10;\n\t\t\tif(d==4) four++;\n\t\t\telse if(d==7) seven++;\n\t\t}\n\t\treturn four==seven;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9c64bebbe042115b80e5c81e9699640a", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n\tpublic static void main(String adp[])throws IOException\n\t{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tint n=Integer.parseInt(br.readLine());\n\t\tString ns=\"\"+n;\n\t\tif(ns.charAt(0)=='8'||ns.charAt(0)=='9')\n\t\t{\n\t\t\tint len=ns.length();\n\t\t\tString ans=\"\";\n\t\t\tint i=1;\n\t\t\twhile(i<=len/2+1)\n\t\t\t{\n\t\t\t\tans+=\"4\";\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile(i<=len+1)\n\t\t\t{\n\t\t\t\tans+=\"7\";\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tif((len+1)%2!=0)\n\t\t\t{\n\t\t\t\tans+=\"7\";\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t\treturn;\n\t\t}\n\t\tint len=ns.length();\n\t\tint j;\n\t\tint no4=0,no7=0;\n\t\tfor(j=0;j4)\n\t\t{\n\t\t\tans+=\"7\";\n\t\t\tno7++;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans+=\"4\";\n\t\t\tno4++;\n\t\t}\n\t\tint fno4,fno7;\n\t\tif(len%2==0)\n\t\t{\n\t\t\tfno4=len/2;\n\t\t\tfno7=len/2;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfno4=(len/2)+1;\n\t\t\tfno7=(len/2)+1;\t\n\t\t}\n\t\tint left4=fno4-no4;\n\t\tint left7=fno7-no7;\n\t\twhile(left4>0)\n\t\t{\n\t\t\tans+=\"4\";\n\t\t\tleft4--;\n\t\t}\n\t\twhile(left7>0)\n\t\t{\n\t\t\tans+=\"7\";\n\t\t\tleft7--;\n\t\t}\n\t\tSystem.out.println(ans);\n\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24606039cba020c426a5776e6009aa43", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class B {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile(sc.hasNext()) {\n\t\t\tlong nn = sc.nextLong();\n\t\t\tlong n = nn;\n\t\t\tString binary = \"\";\n\t\t\twhile(n>0) {\n\t\t\t\tlong d = n%10;\n\t\t\t\tn /= 10;\n\t\t\t\tif(d>7) {\n\t\t\t\t\tbinary = \"0\" + binary;\n\t\t\t\t\tn++;\n//\t\t\t\t} else if(d>4) {\n//\t\t\t\t\tbinary = \"1\" + binary;\n\t\t\t\t} else {\n\t\t\t\t\tbinary = \"0\" + binary;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint all = binary.length();\n\t\t\tif(all%2!=0) {\n\t\t\t\tbinary = \"0\" + binary;\n\t\t\t\tall++;\n\t\t\t}\n\t\t\tint b = Integer.valueOf(binary, 2);\n\t\t\twhile(true) {\n\t\t\t\tif(Integer.bitCount(b)==all/2) {\n\t\t\t\t\tString s = Integer.toBinaryString(b);\n\t\t\t\t\twhile(s.length() dpMap;\n\n public int dp(int maxLen, String fromStr, ArrayList keyList, ArrayList valueList) {\n if (fromStr.length() == maxLen) return 1;\n if (dpMap.containsKey(fromStr))\n return dpMap.get(fromStr);\n char first = fromStr.charAt(0);\n int cnt = 0;\n for (int i = 0; i < valueList.size(); i++) {\n if (valueList.get(i).charAt(0) == first) {\n cnt += dp(maxLen, keyList.get(i) + fromStr.substring(1), keyList, valueList);\n }\n }\n dpMap.put(fromStr, cnt);\n return dpMap.get(fromStr);\n }\n\n public void solveB(FastScanner scanner, PrintWriter writer) {\n int n = scanner.nextInt();\n int q = scanner.nextInt();\n\n ArrayList keyList = new ArrayList<>();\n ArrayList valueList = new ArrayList<>();\n dpMap = new HashMap<>(1000);\n for (int i = 0; i < q; i++) {\n keyList.add(scanner.next());\n valueList.add(scanner.next());\n }\n\n int ans = dp(n, \"a\", keyList, valueList);\n writer.printf(\"%d\\n\", ans);\n\n }\n\n public void solveA(FastScanner scanner, PrintWriter writer) {\n int n = scanner.nextInt();\n int nums[] = new int[n];\n int hash[] = new int[1005];\n for (int i = 0; i < n; i++) {\n int x = scanner.nextInt();\n if(hash[x]==0) {\n nums[i] = x;\n hash[x] = 1;\n }\n }\n\n Arrays.sort(nums);\n boolean flag = false;\n for (int i = 2; i < n; i++) {\n if ((nums[i] == (nums[i - 1] + 1)) && (nums[i - 1] == (nums[i - 2] + 1))) {\n flag = true;\n break;\n }\n }\n if (flag)\n writer.printf(\"YES\\n\");\n else\n writer.printf(\"NO\\n\");\n\n }\n\n static class Point {\n long x, y;\n\n public Point(long x, long y) {\n this.x = x;\n this.y = y;\n }\n }\n\n long twoTimesAreaOfTriangle(Point a, Point b, Point c) {\n long ar = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);\n if (ar < 0) ar = ar * (-1);\n return ar;\n }\n\n boolean isCisOnAB(Point a, Point b, Point c) {\n long cross = (c.y - a.y) * (b.x - a.x) - (c.x - a.x) * (b.y - a.y);\n if (cross != 0) return false;\n long dotproduct = (c.x - a.x) * (b.x - a.x) + (c.y - a.y) * (b.y - a.y);\n if (dotproduct < 0)\n return false;\n long squaredlengthba = (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);\n if (dotproduct > squaredlengthba) return false;\n\n return true;\n\n }\n\n\n static class FastScanner {\n private BufferedReader reader = null;\n private StringTokenizer tokenizer = null;\n\n public FastScanner(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n return next();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public String nextLine() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n return tokenizer.nextToken(\"\\n\");\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d3b46c52391fceb81f5a7adda098dab", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main{\n public static void main(String []args)throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n //Scanner input = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\n StringTokenizer st;\n int n = Integer.parseInt(br.readLine());\n int a [] = new int [1000] ;\n st = new StringTokenizer(br.readLine());\n for(int i = 0 ; i < n ; i++)\n a[Integer.parseInt(st.nextToken())]++;\n int ans = 0 ;\n int c = 0 ;\n for(int i = 0 ; i < 1000 ; i++){\n if(c==3){\n System.out.println(\"YES\");\n return;\n }\n if(a[i]>0){\n c++;\n }\n else\n c = 0 ;\n }\n \n \n System.out.println(\"NO\");\n }\n}\n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "684f734a137a94965f9f5b28e56fc1c8", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Q1 {\n\t\n\tpublic static void main(String args[]) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tArrayList arr = new ArrayList();\n\t\tfor(int i=0;i[] adjList;\n static int V;\n\n /*\n * 1. Dijkstra's Algorithm for SSSP on weighted graphs\n */\n static int dijkstra(int S)\t//O(E log E)\n {\n int[][] dist = new int[3][V];\n Arrays.fill(dist[0], INF);\n Arrays.fill(dist[1],INF);\n Arrays.fill(dist[2],INF);\n PriorityQueue pq = new PriorityQueue();\n dist[0][S] = 0;\n pq.add(new Edge(S, 0,0));\t\t\t\t\t\t//may add more in case of MSSP (Mult-Source)\n while(!pq.isEmpty())\n {\n Edge cur = pq.remove();\n if(cur.cost > dist[cur.mod][cur.node]||cur.node==V-1)\t\t\t//lazy deletion\n continue;\n for(Edge nxt: adjList[cur.node])\n if(cur.cost + nxt.cost < dist[(cur.mod+nxt.mod)%3][nxt.node])\n pq.add(new Edge(nxt.node, dist[(cur.mod+nxt.mod)%3][nxt.node] = cur.cost + nxt.cost,(cur.mod+nxt.mod)%3));\n }\n PriorityQueueres=new PriorityQueue<>();\n res.add(new Edge(V-1,dist[0][V-1],0));\n res.add(new Edge(V-1,dist[1][V-1],1));\n res.add(new Edge(V-1,dist[2][V-1],2));\n while (!res.isEmpty()){\n if (res.peek().mod==0){\n sol.append(\"me\\n\");\n }\n else if (res.peek().mod==1){\n sol.append(\"Gon\\n\");\n }\n else {\n sol.append(\"Killua\\n\");\n }\n res.poll();\n // System.out.println(res.poll());\n }\n return -1;\n }\n static class Edge implements Comparable\n {\n int node, cost,mod;\n\n Edge(int a, int b,int m) { node = a;\tcost = b;mod=m;}\n\n public int compareTo(Edge e){ return cost - e.cost;\t}\n\n public String toString() {\n return node+\" \"+cost+\" \"+mod;\n }\n }\n static class SegmentTree {\t\t// 1-based DS, OOP\n\n int N; \t\t\t//the number of elements in the array as a power of 2 (i.e. after padding)\n int[] array, sTree, lazy;\n\n SegmentTree(int[] in)\n {\n array = in; N = in.length - 1;\n sTree = new int[N<<1];\t\t//no. of nodes = 2*N - 1, we add one to cross out index zero\n lazy = new int[N<<1];\n build(1,1,N);\n }\n\n void build(int node, int b, int e)\t// O(n)\n {\n if(b == e)\n sTree[node] = array[b];\n else\n {\n int mid = b + e >> 1;\n build(node<<1,b,mid);\n build(node<<1|1,mid+1,e);\n sTree[node]=sTree[node<<1]+sTree[node<<1|1];\n }\n }\n\n\n void update_point(int index, int val)\t\t\t// O(log n)\n {\n index += N - 1;\n sTree[index] += val;\n while(index>1)\n {\n index >>= 1;\n sTree[index] = sTree[index<<1] + sTree[index<<1|1];\n }\n }\n\n\n void propagate(int node, int b, int mid, int e)\n {\n lazy[node<<1] += lazy[node];\n lazy[node<<1|1] += lazy[node];\n sTree[node<<1] += (mid-b+1)*lazy[node];\n sTree[node<<1|1] += (e-mid)*lazy[node];\n lazy[node] = 0;\n }\n\n int query(int i, int j)\n {\n return query(1,1,N,i,j);\n }\n\n int query(int node, int b, int e, int i, int j)\t// O(log n)\n {\n if(i>e || j = i && e <= j)\n return sTree[node];\n int mid = b + e >> 1;\n propagate(node, b, mid, e);\n int q1 = query(node<<1,b,mid,i,j);\n int q2 = query(node<<1|1,mid+1,e,i,j);\n return q1 + q2;\n\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n String x = next();\n StringBuilder sb = new StringBuilder(\"0\");\n double res = 0, f = 1;\n boolean dec = false, neg = false;\n int start = 0;\n if (x.charAt(0) == '-') {\n neg = true;\n start++;\n }\n for (int i = start; i < x.length(); i++)\n if (x.charAt(i) == '.') {\n res = Long.parseLong(sb.toString());\n sb = new StringBuilder(\"0\");\n dec = true;\n } else {\n sb.append(x.charAt(i));\n if (dec)\n f *= 10;\n }\n res += Long.parseLong(sb.toString()) / f;\n return res * (neg ? -1 : 1);\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9d752ce43b40c154936c813b1116b33", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class candies{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int d = sc.nextInt();\n \n if(a==d+b+c)\n System.out.println(\"YES\");\n else if(b==a+d+c)\n System.out.println(\"YES\");\n else if(c==a+b+d)\n System.out.println(\"YES\");\n \n else if(d==a+b+c)\n System.out.println(\"YES\");\n \n else if(a+b==c+d)\n System.out.println(\"YES\");\n \n else if(a+c==b+d)\n System.out.println(\"YES\");\n else if(a+d==b+c)\n System.out.println(\"YES\");\n else \n \n System.out.println(\"NO\");\n \n \n \n \n \n \n \n \n \n \n \n }}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "51962cc2dec7c4cee1f1303a112f7f24", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class main {\n\n\tpublic static void main(String[] args) {\n\t\n\t\tScanner sc=new Scanner(System.in);\n\t\tint x[]=new int[4];\n\t\tfor(int i=0;i=arr.length)\n return sum==0;\n if (sum==0)\n return true;\n boolean b1 = find(arr,sum-arr[currentIndex], currentIndex+1);\n boolean b2 = find(arr,sum, currentIndex+1);\n return b1 || b2;\n }\n \n void run() {\n try {\n in = new FastScanner(new File(\"Solution.in\"));\n out = new PrintWriter(new File(\"Solution.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 static void printArray(int arr[]){\n for (int i = 0; i < arr.length; i++) {\n System.out.print(arr[i]+\", \");\n }\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 int[] nextIntArray(int n){\n int returnArray[] = new int[n];\n for (int i = 0; i < n; i++) {\n returnArray[i] = this.nextInt();\n }\n return returnArray;\n }\n \n String[] nextStringArray(int n){\n String returnArray[] = new String[n];\n for (int i = 0; i < n; i++) {\n returnArray[i] = this.next();\n }\n return returnArray;\n }\n \n char[] nextCharArray(int n){\n char returnArray[] = new char[n];\n for (int i = 0; i < n; i++) {\n returnArray[i] = this.next().charAt(0);\n }\n return returnArray;\n }\n \n long[] nextLongArray(int n){\n long returnArray[] = new long[n];\n for (int i = 0; i < n; i++) {\n returnArray[i] = this.nextLong();\n }\n return returnArray;\n }\n }\n \n public static void main(String[] args) {\n new A().runIO();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d01ff1b3d40b006611dc7d687a50c1c6", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class DawidAndBagsOfCandies {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n int[] arr = new int[200000000];\n\n for (int i = 0; i < 4; ++i) {\n arr[i] = sc.nextInt();\n }\n\n Arrays.sort(arr);\n\n if (arr[3] == (arr[0] + arr[1] + arr[2]) ||\n (arr[0] + arr[3]) == (arr[1] + arr[2])) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d244b67316dfae92d70d0c230c1d01f", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.*;\n\npublic class Main {\n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] paper = new String[4];\n\n for(int i = 0; i < 4; ++i) {\n paper[i] = br.readLine();\n }\n \n boolean isFound = false;\n for(int i = 1; i < 4; ++i) {\n for(int j = 1; j < 4; ++j) {\n if((paper[i-1].charAt(j-1) == paper[i-1].charAt(j)) && (paper[i-1].charAt(j) == paper[i].charAt(j-1))) {\n System.out.println(\"YES\");\n isFound = true; \n }\n if(isFound)\n break;\n }\n if(isFound)\n break;\n }\n\n if(!isFound)\n System.out.println(\"NO\");\n \n System.exit(0);\n }\n}\n \n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1f124787c95ec39c3e859523280de8e3", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class A {\npublic static void main(String[] args) {\n Scanner in = new Scanner ( System.in );\n String a;\n int s=0,flag=0;\n char x='.';\n char y='#';\n char[][] b=new char[4][4];\n for(int i=0;i<4;i++){\n a=in.next();\n for(int j=0;j<4;j++){\n b[i][j]=a.charAt(j);\n }\n }\n for(int i=0;i<4;i++){\n \n for(int j=0;j<4;j++){\n s=0;\n if(b[i][j]==x&&i<3&&j<3){\n if(b[i][j+1]==x)\n s++;\n if(b[i+1][j]==x)\n s++;\n if(b[i+1][j+1]==x)\n s++;\n \n }\n if(b[i][j]==y&&i<3&&j<3){\n if(b[i][j+1]==y)\n s++;\n if(b[i+1][j]==y)\n s++;\n if(b[i+1][j+1]==y)\n s++;\n \n }\n if(s>=2){\n flag=1;\n break;\n }\n }\n if(flag==1)\n break;\n }\n if(flag==1)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e4fd4d018ab5f2ab8f75a6b05362aa3c", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author sagimbekov_ma\n */\npublic class A287 {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String[] a = new String[4];\n for (int i = 0; i < 4; i++) {\n a[i] = sc.nextLine();\n }\n \n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n int count = 0;\n for (int x = i; x < i + 2; x++) {\n for (int y = j; y < j + 2; j++) {\n if (a[x].charAt(y) == '#') {\n count++;\n }\n }\n }\n if (count > 2) {\n System.out.println(\"YES\");\n return;\n }\n }\n }\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "deaf82c3f77dd87eb907b6f900a56eb3", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\n/**\n *\n * @author Ahmed\n */\npublic class Test {\n\n /**\n * @param args the command line arguments\n * @throws java.io.IOException\n *\n *\n *\n */\n static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n \n public static void main(String[] args) throws IOException {\n String a[] = new String[4];\n \n for (int i = 0; i < 4; i++) {\n a[i] = in.readLine();\n }\n int k = 0, j = 0, l = 0;\n for (int i = 0; i < 2; i++) {\n for (int t = i; t < i + 2; i++) {\n if (a[0].charAt(t) == '#') {\n k++;\n }\n if (a[1].charAt(t) == '#') {\n k++;\n }\n }\n for (int t = i; i < i + 2; i++) {\n if (a[1].charAt(t) == '#') {\n j++;\n }\n if (a[2].charAt(t) == '#') {\n j++;\n }\n }\n for (int t = i; i < i + 2; i++) {\n if (a[2].charAt(t) == '#') {\n l++;\n }\n if (a[3].charAt(t) == '#') {\n l++;\n }\n }\n if (k != 2 || l != 2 || j != 2) {\n out.write(\"YES\" + \"\\n\");\n out.flush();\n System.exit(0);\n }\n }\n out.write(\"NO\" + \"\\n\");\n out.flush();\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fbeb9fbd0fa8aacc3760110ef06de415", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "public class TheatreSquare {\n\n public int solve(int n, int m ,int a){\n\tint x = n/a + (n%a==0?0:1);\n\tint y = m/a + (m%a==0?0:1);\n\treturn x*y;\n }\n public void run(String[] args){\n\tSystem.err.println( \"(n,m,a)=(6,6,4) : \"+(new TheatreSquare()).solve(6,6,4) );\n }\n public static void main(String[] args){\n\t(new TheatreSquare()).run(args);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce70eb2833a12281181128895a651415", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\n/**\n *\n * @author Vortex\n */\npublic class Solution{\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n BigInteger n = new BigInteger(sc.next());\n BigInteger m = new BigInteger(sc.next());\n BigInteger a = new BigInteger(sc.next());\n\n BigInteger a1 = n.divide(a);\n System.out.println(\"a1 after divide : \"+a1.toString());\n\n if(!n.remainder(a).equals(BigInteger.ZERO))\n {\n a1 = a1.add(BigInteger.ONE); \n }\n BigInteger a2 = m.divide(a);\n System.out.println(\"a2 after divide : \"+a2.toString());\n \n if(!m.remainder(a).equals(BigInteger.ZERO))\n {\n a2 = a2.add(BigInteger.ONE); \n } \n\n BigInteger answer = a1.add(a2);\n\n System.out.println(answer.toString());\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43d6d28519542bc548dca5fedfe9aa38", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class TheatreSquare {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tint n = scan.nextInt();\n\t\tint m = scan.nextInt();\n\t\tint a = scan.nextInt();\n\t\t\n\t\tint x = n / a;\n\t\tif (x % a != 0) {\n\t\t\tx++;\n\t\t}\n\t\tint y = m / a;\n\t\tif (y % a != 0) {\n\t\t\ty++;\n\t\t}\n\t\tint res = x*y;\n\t\t\n\t\tSystem.err.println(res);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4f2fcb0b53dca0fbcd368fb6fd993ddf", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\nimport java.util.concurrent.Executors;\n\n\npublic class _template implements Runnable {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tLocale.setDefault(Locale.US);\n\t\tExecutors.newCachedThreadPool().submit(new _template());\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint m = sc.nextInt();\n\t\tint n = sc.nextInt();\n\t\tint a = sc.nextInt();\n\t\tSystem.out.println((m/a + (m%a==0 ? 0:1) ) * (n/a + (n%a==0 ? 0:1) ));\n\t\t\n\t}\n\t\n\t\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4731e095adcbbf400e136480d3f6dbc9", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "package codeforces;\nimport java.util.Scanner;\npublic class ex5 {\npublic static void main(String[] args) {\n\tScanner scan = new Scanner(System.in);\n\tString S [] = new String[3];\n\t\n\tint m=0,s=0,p=0;\n\tint temp=0;\n\t\n\tfor (int i = 0; i < S.length; i++) {\n\t\tS[i]=scan.next();\n\t\tif(S[i].indexOf('m')!=-1) m++;\n\t\tif(S[i].indexOf('s')!=-1) s++;\n\t\tif(S[i].indexOf('p')!=-1) p++;\n\t}\n\t\n\t\n\tint n1 = Integer.parseInt(S[0].substring(0,1));\n\tint n2 = Integer.parseInt(S[1].substring(0,1));\n\tint n3 = Integer.parseInt(S[2].substring(0,1));\n\t\n\t\n\t\n\t int d3 = Math.abs(n1-n2);\n\t\tint d4 = Math.abs(n1-n3);\n\t\tint d5 = Math.abs(n2-n3);\n\t\t\n\t\n\tif(m==3||s==3||p==3) {\n\t\t\n\t\t if(d3==1&d5==1||d3==1&d4==1||d5==1&d4==1)\n\t\t\tSystem.out.println(0);\n\t\telse \n\t\t if(d3==0&d4==0) System.out.println(0);\n\t\telse {\n\t\t\tif(d3n1&n2>n3) {\n\t\ttemp=n2;\n\t n2=n1;\n\t n1=temp;\n\t if(n2n2&n1>n3) {\n\t\t if(n2n2&n3>n1) {\n\t \ttemp=n3;\n n3=n1;\n n1=temp;\n if(n2 1 && a != b) {\n if (a > b)\n a -= b;\n else\n b -= a;\n\n cnt++;\n }\n\n if (a == b)\n System.out.println(cnt + 1);\n else\n System.out.println(Math.max(a, b) + cnt);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5dea075c91527f6cd310e455189247cd", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class A {\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 long count = 0;\n while (a > 1) {\n if (a % b == 0) {\n a /= b;\n count += a;\n break;\n } else {\n a -= b;\n if (b > a) {\n long temp = a;\n a = b;\n b = temp;\n }\n count++;\n }\n \n }\n System.out.println(count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0636dc7c622f38e1ae52859e86dfcd53", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n/**\n * \n2 1\n2\n\n\n1\n2\n4\n8\n\n * \n * */\n\npublic class A_Div2_296 {\n\tpublic static void main(String[]arg) throws IOException\n\t{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(in.readLine());\n\t\tlong a = Long.parseLong(st.nextToken());\n\t\tlong b = Long.parseLong(st.nextToken());\n\t\tboolean cont = true;\n\t\tlong na,nb,y,x;\n\t\tlong c = 0;\n\t\tif(b == 1)\n\t\t\tSystem.out.println(a);\n\t\telse\n\t\t{\n\t\twhile(cont)\n\t\t{\n\t\t\t\n\t\t\tx = a - b;\n\t\t\t//System.out.println(x);\n\t\t\tif(x >= 0)\n\t\t\t{\n\t\t\t\tc++;\n y = b;\n if(x >= y)\n {\n \ta = x;\n \tb = y;\n }\n else\n {\n \ta = y;\n \tb = x;\n }\n\t\t\t\tif(a == 0 || b == 0)\n\t\t\t\t\tcont = false;\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t\tcont = false;\n\t\t}\n\t\t\n\t\tSystem.out.println(c);\n\t\t}\n\t}\n\t\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "033c09aee361e2c5b097feb829750d9e", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class col\n{\n public static void main(String[] args)\n {\n \tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tif(n>=0)\n\t\t{\n\t\t System.out.println(n);\n\t\t}\n\t\telse\n\t\t{\n\t\t int a = n/10;\n\t\t int last = n%10;\n\t\t int b = n/100;\n\t\t String s = String.valueOf(b)+String.valueOf(last);\n\t\t b = Integer.parseInt(s);\n\t\t int ans = Math.max(a,b);\n\t\t System.out.println(-ans);\n\t\t}\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0eefc901d20484fff52619b7c38c986b", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "package bankaccount;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author Leonidas\n */\npublic class BankAccount {\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 System.out.println(\"State\");\n String n = sc.next();\n try {\n if (Integer.valueOf(n) < 0) {\n if (n.length()== 2) {\n n = \"0\";\n }else{\n if (n.charAt(n.length()-1) > n.charAt(n.length()-2) ) {\n n = n.substring(0,n.length()-1);\n }else{\n n = n.substring(0,n.length()-2)+ n.charAt(n.length()-1);\n }\n }\n } \n System.out.println(n);\n } catch (NumberFormatException e) {\n System.out.println(\"Solo se permiten numeros\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29eb31ea1f616736e609af29364894aa", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main \n{\n \n public static void main(String[] arg)\n {\n Scanner sc=new Scanner(System.in);\n long v=sc.nextLong();\n int l,i;\n String s2=\"\",s=\"\",s3=\"\";\n if(v>0){\n System.out.println(v);\n }else{\n s=String.valueOf(v); \n l=s.length();\n if(Integer.valueOf(s.charAt(l-1))<=Integer.valueOf(s.charAt(l-2)))\n {\n s2+=s.charAt(l-1);\n }else{\n s2+=s.charAt(l-2);\n }\n for(i=0;i= 0) {\n ans = n;\n }\n else {\n ans = Integer.MIN_VALUE;\n String s = \"\" + n;\n for (int i = 1; i < s.length(); i++) {\n String tmp = s.substring(0, i - 1) + s.substring(i + 1);\n ans = Math.max(ans, Integer.parseInt(tmp));\n }\n }\n System.out.println(ans);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream is) {\n reader = new BufferedReader(new InputStreamReader(is), 1 << 15);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b49ed524d78b47508f1093ef3cb7ce21", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Div294A {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner s = new Scanner(System.in);\n\t\tint b=0;\n\t\tint w=0;\n\t\t\n\t\tfor(int i=0;i<8;i++){\n\t\t\tString n = s.next();\n\t\t\n\t\t\tchar[] c = n.toCharArray();\n\t\t\tfor(int j=0;j<8;j++){\n\t\t\t\tif(c[j]=='.')continue;\n\t\t\t\t\n\t\t\t\tif(c[j]=='P'){\n\t\t\t\t\tw+=1;\n\t\t\t\t}\n\t\t\t\telse if(c[j]=='p')\n\t\t\t\t\tb+=1;\n\t\t\t\t\n\t\t\t\telse if(c[j]=='Q')\n\t\t\t\tw+=9;\n\t\t\t\telse if(c[j]=='q')\n\t\t\t\tb+=9;\t\n\t\t\t\telse if(c[j]=='R')\n\t\t\t\t\tw+=5;\n\t\t\t\telse if(c[j]=='r')\n\t\t\t\t\tb+=5;\n\t\t\t\t\t\n\t\t\t\telse if(c[j]=='B')\n\t\t\t\t\tw+=3;\n\t\t\t\telse if(c[j]=='b')\n\t\t\t\t\tb+=3;\n\t\t\t\t\t\n\t\t\t\telse if(c[j]=='K')\n\t\t\t\t\tw+=3;\n\t\t\t\telse if(c[j]=='k'){\n\t\t\t\t\tb+=3;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(b>w){\n\t\t\tSystem.out.println(\"Black\");\n\t\t}else if(w>b){\n\t\t\tSystem.out.println(\"White\");\n\t\t}else if(w==b){\n\t\t\tSystem.out.println(\"Draw\");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a80bcbe2ab1deb3db5d17c4e3d5ed2c8", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedInputStream;\nimport java.util.Scanner;\n\n\n/**\n *\n * @author AL_DEEB\n */\npublic class AandBanChess {\n public static void main(String[] args) {\n\t\tStringBuilder sb = new StringBuilder();\n\t\tBufferedInputStream bs = new BufferedInputStream(System.in);\n\t\tScanner sc = new Scanner(bs);\n \n \n \n int white=0,black=0;\n for (int i = 0; i < 8; i++) {\n String s=sc.next();\n for (int j = 0; j < 8; j++) {\n // if(s.charAt(j)=='.')continue;\n if(s.charAt(j)=='Q')white+=9;\n if(s.charAt(j)=='R')white+=5;\n if(s.charAt(j)=='B')white+=4;\n if(s.charAt(j)=='N')white+=3;\n if(s.charAt(j)=='P')white+=1;\n if(s.charAt(j)=='q')black+=9;\n if(s.charAt(j)=='r')black+=5;\n if(s.charAt(j)=='b')black+=4;\n if(s.charAt(j)=='n')black+=3;\n if(s.charAt(j)=='p')black+=1;\n }\n \n \n \n }\n \n if(white>black) System.out.println(\"White\");\n else if(whitesum)\n\t\t\tout.println(\"White\");\n\t\telse if(result==sum)\n\t\t\tout.println(\"Draw\");\n\t\telse\n\t\t\tout.println(\"Black\");\n\t\tout.close();\n\t\t\t\n\t\t\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9ec6b916fe5f11218eed04fcc3d61978", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0} {"lang": "Java 8", "source_code": "//package JustTasks;//package JustTasks;\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class App {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String one = in.nextLine();\n String two = in.nextLine();\n String three = in.nextLine();\n String four = in.nextLine();\n String five = in.nextLine();\n String six = in.nextLine();\n String seven = in.nextLine();\n String eight = in.nextLine();\n String work = one+two+three+four+five+six+seven+eight.replaceAll(\".\", \"\").replaceAll(\"K\", \"\").replaceAll(\"k\", \"\");\n int counterWhite = 0;\n int counterBlack = 0;\n while (work.contains(\"Q\")){\n counterWhite=counterWhite+9;\n work.replaceFirst(\"Q\",\"\");\n }\n while (work.contains(\"R\")){\n counterWhite=counterWhite+5;\n work.replaceFirst(\"R\",\"\");\n }\n while (work.contains(\"B\")){\n counterWhite=counterWhite+3;\n work.replaceFirst(\"B\",\"\");\n }\n while (work.contains(\"N\")){\n counterWhite=counterWhite+3;\n work.replaceFirst(\"N\",\"\");\n }\n while (work.contains(\"P\")){\n counterWhite=counterWhite+1;\n work.replaceFirst(\"P\",\"\");\n }\n //black are bellow\n while (work.contains(\"q\")){\n counterWhite=counterBlack+9;\n work.replaceFirst(\"q\",\"\");\n }\n while (work.contains(\"r\")){\n counterWhite=counterBlack+5;\n work.replaceFirst(\"r\",\"\");\n }\n while (work.contains(\"b\")){\n counterWhite=counterBlack+3;\n work.replaceFirst(\"b\",\"\");\n }\n while (work.contains(\"n\")){\n counterWhite=counterBlack+3;\n work.replaceFirst(\"n\",\"\");\n }\n while (work.contains(\"p\")){\n counterWhite=counterBlack+1;\n work.replaceFirst(\"p\",\"\");\n }\n if(counterWhite>counterBlack){\n System.out.println(\"White\");\n }\n else if(counterBlack>counterWhite){\n System.out.println(\"Black\");\n }\n else {\n System.out.println(\"Draw\");\n }\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2864da39104e7e621518aea22a391ad2", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author Ura\n */\npublic class CF_91A {\n\n public static void main(String... args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n\n\n int[] luckyNambers = {4, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777};\n\n\n\n b:\n {\n for (int i = 0; i < luckyNambers.length; i++) {\n if (n % luckyNambers[i] == 0) {\n System.out.print(\"YES\");\n break b;\n }\n\n }\n System.out.print(\"NO\");\n }\n \n\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "507bc8dfcdd0d8c3f89cd274f7ec73d4", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author Athlon II\n */\npublic class division {\n\n public static void main(String p[]) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String inp = br.readLine();\n int in = Integer.parseInt(inp);\n \n if (in % 4 == 0 || in % 7 == 0) {\n System.out.println(\"YES\");\n \n } else {\n char[] temp = inp.toCharArray();\n //System.out.println(inp);\n for (int a = 0; a < temp.length; a++) {\n //System.out.print(temp[a]);\n if (temp[a] != '4' && temp[a] != '7') {\n System.out.println(\"NO\");\n return;\n } \n }\n System.out.println(\"YES\");\n }\n \n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "53ce66ad72f5e8e29578ea1093c2b10d", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Beruntung\n{\n public static void main(String[] args)\n {\n Scanner in = new Scanner(System.in);\n String masukan = in.next();\n boolean angkaBeruntung = false;\n \n \n \n int itung = 0;\n for(int i=0;i col2 / 5) {\n\t\t\t\ttemp++;\n\t\t\t\tleft--;\n\t\t\t\tright--;\n\t\t\t}\n\t\t\tSystem.out.println(temp);\n\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7a4a5ec2fdd36d3618d5f349c5b529f", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CF358A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint a = scan.nextInt(), b = scan.nextInt();\n\t\tint n = Math.min(a, b), m = Math.max(a, b);\n\t\tlong c = 0;\n\t\tif(n >=5 || m >= 5){\n\t\t\tfor(int i = 1; i <= n; i++){\n\t\t\t\tint y = m;\n\t\t\t\twhile((i+y)%5!=0)y--;\n\t\t\t\tc+=i%5==0?y/5:y/5+1;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(c);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f0ffc7dd3eb08e680647fd439ac6350d", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class rota{\n\tstatic int flag=0;\n\tpublic static void main(String s[]){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tArrayList al = new ArrayList<>();\n\t\tfor(int i=0;i al , int count, int size, int sum){\n\t\t\t\n\n\t\tif(count == size ){\n\t\t\tif(sum==0 || sum==360){\n\t\t\tflag=1;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\tif(count >= size && sum!=0)\n\t\t\treturn false;\n\t\tboolean b1=false;\n\t\tb1 = check(al, count+1, size, sum+al.get(count));\n\t\tb1 = check(al, count+1, size, sum-al.get(count));\n\t\treturn b1;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dcef022e626556aebb3f9f5637b729f0", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\n/* abhi2601 */\n\npublic class Q1 implements Runnable{\n\n final static long mod = (long)1e9 + 7;\n static boolean find (int arr[], int n, int sum)\n {\n if (sum == 0)\n return true;\n if (n == 0 && sum != 0)\n return false;\n if (arr[n-1] > sum)\n return find (arr, n-1, sum);\n return find (arr, n-1, sum) ||\n find (arr, n-1, sum-arr[n-1]);\n }\n public void run() {\n\n InputReader sc = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n int n=sc.nextInt(),sum=0;\n int a[]=new int[n];\n for(int i=0;i= 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\n public static void main(String args[]) throws Exception\n {\n new Thread(null, new Q1(),\"q1\",1<<26).start();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5a52f8c82072b67d3a211eef564a61be", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n }\n for (int i = 0; i < (1 << n); ++i) {\n int t = 0;\n for (int j = 0; j < n; ++i) {\n if ((i & (1 << j)) == 1) {\n t += a[j];\n t %= 360;\n } else {\n t -= a[j];\n t = (t + 360) % 360;\n }\n }\n if (t == 0) {\n out.println(\"YES\");\n return;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c692b04a93a7eddd9755182b5d699e2d", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n }\n for (int i = 0; i < (1 << n); ++i) {\n int t = 0;\n for (int j = 0; j < n; ++i) {\n if ((i & (1 << j)) == 1) t += a[j];\n else t -= a[j];\n }\n if (t % 360 == 0) {\n out.println(\"YES\");\n return;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aeecc3bf7c41797232c70101066b76c8", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Solution{\n public static void main(String []args)\n {\n Scanner sc=new Scanner(System.in);\n int k, i;\n char col1[]={'#','#','#','#','#','#','#','#','#','#','#'},\n col2[]={'#','#','#','#','#','#','#','#','#','#','#'},\n col4[]={'#','#','#','#','#','#','#','#','#','#','#'},\n col3='#';\n k=Integer.parseInt(args[0]);\n if(k>=3){\n col3='0';\n k--;\n }\n if(k>0)\n for(i=0;i<11;i++){\n col1[i]='0';\n if(--k==0)\n break;\n col2[i]='0';\n if(--k==0)\n break;\n col4[i]='0';\n if(--k==0)\n break;\n }\n System.out.print(\"+------------------------+\\n|\");\n for(i=0;i<11;i++)\n System.out.print(col1[i]+\".\");\n System.out.print(\"|D|)\\n|\");\n for(i=0;i<11;i++)\n System.out.print(col2[i]+\".\");\n System.out.print(\"|.|\\n|\"+col3+\".......................|\\n|\");\n for(i=0;i<11;i++)\n System.out.print(col4[i]+\".\");\n System.out.print(\"|.|)\\n\");\n System.out.print(\"+------------------------+\");\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "94856e5bce61c68f96eda5872d512f74", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Template implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n try {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } catch (Exception e) {\n String filename = \"king\";\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(filename + \".out\");\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 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\n List[] createGraphList(int size) {\n List[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new 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 char[][] ar = {\n \"+------------------------+\".toCharArray(),\n \"|*.*.*.*.*.*.*.*.*.*.*.|D|)\".toCharArray(),\n \"|*.*.*.*.*.*.*.*.*.*.*.|.|\".toCharArray(),\n \"|*.......................|\".toCharArray(),\n \"|*.*.*.*.*.*.*.*.*.*.*.|.|)\".toCharArray(),\n \"+------------------------+\".toCharArray()};\n\n void solve() throws IOException {\n int n = readInt();\n for (int j = 0; j < ar[0].length; j++){\n for (int i = 0; i < ar.length; i++) {\n if (ar[i][j] == '*') {\n if (n > 0) {\n ar[i][j] = 'O';\n n--;\n } else {\n ar[i][j] = '#';\n }\n }\n }\n }\n for (char[] x : ar) out.println(new String(x));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a7c02b5668226df2ffdff224cf88d0d7", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class Bayan {\n public static void main(String[] args) {\n char [][] seating = new char [3][10];\n char [] lastrow = new char[4];\n initializeMatrix(seating);\n initializeLastRow(lastrow);\n\n\n int k = Integer.parseInt(args[0]);\n\n k = setLastrow(k, lastrow);\n\n for (int j = 0 ; j< 10; j++) {\n for (int i= 0; i < 3; i++) {\n if (seating [i][j] != 0 && k != 0) {\n seating[i][j] = '0';\n k--;\n }\n }\n }\n\n\n //printMatrix(seating);\n printBus(seating, lastrow);\n\n }\n\n public static int setLastrow(int k, char[] lastrow) {\n\n int i = 0;\n while (k > 0 && i < 4) {\n lastrow[i] = '0';\n i++;\n k--;\n }\n return k;\n\n }\n public static void initializeMatrix(char[][] seating) {\n for (int i = 0; i< 3; i++) {\n for (int j=0; j<10 ;j++){\n seating[i][j] = '#';\n }\n }\n }\n\n public static void initializeLastRow(char[] lastrow) {\n for ( int i = 0 ; i< 4; i++) {\n lastrow[i] = '#';\n }\n }\n\n public static void printMatrix(char[][] seating) {\n for (int i = 0; i< 3; i++) {\n for (int j=0; j<10 ;j++){\n System.out.print(seating[i][j]);\n }\n System.out.println();\n }\n }\n\n public static void printBus(char[][] seating, char[] lastrow) {\n //print first line of bus\n System.out.println(\"+------------------------+\");\n //print first row\n printrow(0, seating , lastrow);\n printrow(1, seating, lastrow);\n printEmptyRow(2, lastrow);\n printrow(2, seating, lastrow);\n //print last line of bus\n System.out.println(\"+------------------------+\");\n\n }\n\n public static void printrow(int rownum, char[][] seating, char[] lastrow) {\n System.out.print(\"|\");\n if ( rownum == 2) {\n System.out.print(lastrow[rownum+1] + \".\");\n } else {\n System.out.print(lastrow[rownum] + \".\");\n }\n for (int i= 0; i < 10; i++) {\n\n System.out.print(seating[rownum][i]+\".\");\n }\n\n if ( rownum == 0) {\n System.out.print(\"|D|)\");\n\n } else if( rownum == 2) {\n System.out.print(\"|.|)\");\n }\n else {\n System.out.print(\"|.|\");\n }\n System.out.println();\n }\n\n public static void printEmptyRow(int rownum, char[] lastrow) {\n System.out.print(\"|\");\n System.out.print(lastrow[rownum]+\".\");\n for (int i= 0; i < 21; i++) {\n\n System.out.print(\".\");\n }\n System.out.print(\".|\");\n System.out.println();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "164c46008af9cbdaba0b5b58c2fc6fd5", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\npublic class Task {\n\n private void run() {\n// try {\n// Locale.setDefault(Locale.US);\n// } catch (Exception e) {\n// }\n// \n try {\n sc = new FastScanner(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n } catch (IOException e) {\n for (;;);\n }\n Solver s;\n s = new Solver();\n s.sc = sc;\n s.out = out;\n s.solve();\n out.flush();\n out.close();\n System.exit(0);\n }\n\n \n\n class Solver {\n\n// void ass(boolean OK) { if(!OK)Task.MLE(); }\n//\n FastScanner sc;\n PrintWriter out;\n//// static PrintStream err = System.err;\n//\n\n char[][] arr = {\n\"+------------------------+\" .toCharArray(),\n\"|#.#.#.#.#.#.#.#.#.#.#.|D|)\".toCharArray(),\n\"|#.#.#.#.#.#.#.#.#.#.#.|.|\" .toCharArray(),\n\"|#.......................|\" .toCharArray(),\n\"|#.#.#.#.#.#.#.#.#.#.#.|.|)\".toCharArray(),\n\"+------------------------+\" .toCharArray()\n};\n \n void set(){\n for( int j = 0; j < arr[0].length; ++j ){\n for( int i = 0; i < arr.length; ++i ){\n if( arr[i][j] == '#' ){\n arr[i][j] = 'O';\n return;\n }\n }\n }\n }\n \n void solve() {\n int k = sc.nextInt();\n for (int i = 0; i < k; i++) {\n set();\n }\n for (char[] a : arr) {\n out.println( new String(a) );\n }\n }\n }\n\n public static void main(String[] args) {\n new Task().run();\n }\n\n static FastScanner sc;\n static PrintWriter out;\n}\n\nclass FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStreamReader reader) {\n br = new BufferedReader(reader);\n st = new StringTokenizer(\"\");\n }\n\n String next() {\n while (!st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException ex) {\n for (;;);\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f66cc975baca98d59a6e8a8f405604cf", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0} {"lang": "Java 8", "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\tchar[] c = sc.nextLine().toCharArray();\n\t\tint[][] f = new int[c.length][2];\n\t\tsc.close();\n\t\tf[c.length - 1][0] = c[c.length - 1] - '0';\n\t\tif (c[c.length - 1] != '9') f[c.length - 1][1] = c[c.length - 1] + 10 - '0';\n\t\tfor (int i = c.length - 2; i >= 0; i --) {\n\t\t\tif (c[i] == '0') {\n\t\t\t\tf[i][0] = f[i + 1][0];\n\t\t\t\tf[i][1] = Math.max(f[i + 1][0] + 10, f[i + 1][1] + 9);\n\t\t\t} else if (c[i] == '9') {\n\t\t\t\tf[i][0] = Math.max(f[i + 1][0] + 9, f[i + 1][1] + 8);\n\t\t\t\tf[i][1] = f[i + 1][1] + 18;\n\t\t\t} else {\n\t\t\t\tf[i][0] = Math.max(f[i + 1][0] + c[i] - '0', f[i + 1][1] + c[i] - '0' - 1);\n\t\t\t\tf[i][1] = Math.max(f[i + 1][0] + 10 + c[i] - '0', f[i + 1][1] + 9 + c[i] - '0');\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(f[0][0]);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "add859aabf99e4771260a3fd44a06dd8", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author 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 TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\n long n = in.nextLong();\n\n long cn = n;\n\n long carry = 0;\n\n long ans = 0;\n while (cn > 0) {\n long num = cn % 10;\n\n if (cn / 10 == 0) {\n ans += cn - carry;\n break;\n } else {\n long ntm = 10 + num;\n ans += (ntm - carry);\n carry = 1;\n }\n\n cn /= 10;\n }\n\n out.println(ans);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public 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 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 interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "82df2388dcb18b32ecf85e5a6b31e948", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class ph{\n\t//hi\n\tstatic long sum(long a){\n\t\tlong s=0;\n\t\twhile(a>0){\n\t\t\tlong b=a%10;\n\t\t\t s=s+b;\n\t\t\ta=a/10;\n\t\t}\n\t\treturn s;\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong n=sc.nextLong();\n\t\tlong i,j;\n\t\tlong g[]=new long[(int)n];\n\t\tlong a=n%10;\n\t\tlong b=n-a;\n\t\tj=2;\n\t\tg[0]=sum(b)+sum(n-b);\n\t\tg[1]=sum(n);\n\t\tfor(i=b-1;i>=0;i=i-10){\n\t\t\tg[(int)j]=sum(i)+sum(n-i);\n\t\t\tj++;\n\t\t}\n\t\tArrays.sort(g);\n\t\tSystem.out.println(g[(int)n-1]);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "02456360419de9b1b272662bf1a56568", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class TaskB\n{\n public static void main(String[] args)\n {\n new TaskB(System.in, System.out);\n }\n\n private static class Solver implements Runnable\n {\n long n;\n // BufferedReader in;\n InputReader in;\n PrintWriter out;\n\n void solve() throws IOException\n {\n/*\n n = 75;\n\n int max = 0;\n\n for (int i = 0; i <= n; i++)\n {\n int a = i;\n int b = (int) (n - a);\n\n max = Math.max(max, s(a) + s(b));\n }\n\n out.println(max);*/\n\n n = in.nextLong();\n\n if (n < 9)\n {\n out.println(n);\n\n return;\n }\n\n long a = 9;\n long b = 0;\n long mul = 1;\n\n while (a <= n)\n {\n a *= 10;\n a += 9;\n }\n\n a /= 10;\n n -= a;\n\n if (n < 9)\n {\n out.println(s(a) + s(n));\n\n return;\n }\n\n b = 9;\n\n while (b <= n)\n {\n b *= 10;\n b += 9;\n }\n\n b /= 10;\n n -= b;\n\n b *= 10;\n b += n;\n\n out.println(s(a) + s(b));\n }\n\n int s(long x)\n {\n String str = \"\" + x;\n int sum = 0;\n\n for (char ch : str.toCharArray())\n sum += (ch - '0');\n\n return sum;\n }\n\n // uncomment below line to change to BufferedReader\n // public Solver(BufferedReader in, PrintWriter out)\n Solver(InputReader in, PrintWriter out)\n {\n this.in = in;\n this.out = out;\n }\n\n @Override\n public void run()\n {\n try\n {\n solve();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n\n }\n\n private static class InputReader\n {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n 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 if (numChars <= 0)\n return -1;\n }\n\n return buf[curChar++];\n }\n\n 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\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n\n res *= 10;\n res += c & 15;\n\n c = read();\n } while (!isSpaceChar(c));\n\n return res * sgn;\n }\n\n int[] nextIntArray(int arraySize)\n {\n int array[] = new int[arraySize];\n\n for (int i = 0; i < arraySize; i++)\n array[i] = nextInt();\n\n return array;\n }\n\n long nextLong()\n {\n int c = read();\n\n while (isSpaceChar(c))\n c = read();\n\n int sign = 1;\n\n if (c == '-')\n {\n sign = -1;\n\n c = read();\n }\n\n long result = 0;\n\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n\n result *= 10;\n result += c & 15;\n\n c = read();\n } while (!isSpaceChar(c));\n\n return result * sign;\n }\n\n long[] nextLongArray(int arraySize)\n {\n long array[] = new long[arraySize];\n\n for (int i = 0; i < arraySize; i++)\n array[i] = nextLong();\n\n return array;\n }\n\n float nextFloat()\n {\n float result, div;\n byte c;\n\n result = 0;\n div = 1;\n c = (byte) read();\n\n while (c <= ' ')\n c = (byte) read();\n\n boolean isNegative = (c == '-');\n\n if (isNegative)\n c = (byte) read();\n\n do\n {\n result = result * 10 + c - '0';\n } while ((c = (byte) read()) >= '0' && c <= '9');\n\n if (c == '.')\n while ((c = (byte) read()) >= '0' && c <= '9')\n result += (c - '0') / (div *= 10);\n\n if (isNegative)\n return -result;\n\n return result;\n }\n\n double nextDouble()\n {\n double ret = 0, div = 1;\n byte c = (byte) read();\n\n while (c <= ' ')\n c = (byte) read();\n\n boolean neg = (c == '-');\n\n if (neg)\n c = (byte) read();\n\n do\n {\n ret = ret * 10 + c - '0';\n } while ((c = (byte) read()) >= '0' && c <= '9');\n\n if (c == '.')\n while ((c = (byte) read()) >= '0' && c <= '9')\n ret += (c - '0') / (div *= 10);\n\n if (neg)\n return -ret;\n\n return ret;\n }\n\n String next()\n {\n int c = read();\n\n while (isSpaceChar(c))\n c = read();\n\n StringBuilder res = new StringBuilder();\n\n do\n {\n res.appendCodePoint(c);\n\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n boolean isSpaceChar(int c)\n {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n String nextLine()\n {\n int c = read();\n\n StringBuilder result = new StringBuilder();\n\n do\n {\n result.appendCodePoint(c);\n\n c = read();\n } while (!isNewLine(c));\n\n return result.toString();\n }\n\n boolean isNewLine(int c)\n {\n return c == '\\n';\n }\n\n void close()\n {\n try\n {\n stream.close();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n\n InputReader(InputStream stream)\n {\n this.stream = stream;\n }\n\n }\n\n private static class CMath\n {\n static long power(long number, long power)\n {\n if (number == 1 || number == 0 || power == 0)\n return 1;\n\n if (power == 1)\n return number;\n\n if (power % 2 == 0)\n return power(number * number, power / 2);\n else\n return power(number * number, power / 2) * number;\n }\n\n static long modPower(long number, long power, long mod)\n {\n if (number == 1 || number == 0 || power == 0)\n return 1;\n\n number = mod(number, mod);\n\n if (power == 1)\n return number;\n\n long square = mod(number * number, mod);\n\n if (power % 2 == 0)\n return modPower(square, power / 2, mod);\n else\n return mod(modPower(square, power / 2, mod) * number, mod);\n }\n\n static long moduloInverse(long number, long mod)\n {\n return modPower(number, mod - 2, mod);\n }\n\n static long mod(long number, long mod)\n {\n return number - (number / mod) * mod;\n }\n\n static int gcd(int a, int b)\n {\n if (b == 0)\n return a;\n else\n return gcd(b, a % b);\n }\n\n static long min(long... arr)\n {\n long min = arr[0];\n\n for (int i = 1; i < arr.length; i++)\n min = Math.min(min, arr[i]);\n\n return min;\n }\n\n static long max(long... arr)\n {\n long max = arr[0];\n\n for (int i = 1; i < arr.length; i++)\n max = Math.max(max, arr[i]);\n\n return max;\n }\n\n static int min(int... arr)\n {\n int min = arr[0];\n\n for (int i = 1; i < arr.length; i++)\n min = Math.min(min, arr[i]);\n\n return min;\n }\n\n static int max(int... arr)\n {\n int max = arr[0];\n\n for (int i = 1; i < arr.length; i++)\n max = Math.max(max, arr[i]);\n\n return max;\n }\n\n }\n\n private static class Utils\n {\n static boolean nextPermutation(int[] arr)\n {\n for (int a = arr.length - 2; a >= 0; --a)\n {\n if (arr[a] < arr[a + 1])\n {\n for (int b = arr.length - 1; ; --b)\n {\n if (arr[b] > arr[a])\n {\n int t = arr[a];\n\n arr[a] = arr[b];\n arr[b] = t;\n\n for (++a, b = arr.length - 1; a < b; ++a, --b)\n {\n t = arr[a];\n arr[a] = arr[b];\n arr[b] = t;\n }\n\n return true;\n }\n }\n }\n }\n\n return false;\n }\n\n }\n\n private TaskB(InputStream inputStream, OutputStream outputStream)\n {\n // uncomment below line to change to BufferedReader\n // BufferedReader in = new BufferedReader(new\n // InputStreamReader(inputStream));\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Thread thread = new Thread(null, new Solver(in, out), \"Solver\", 1 << 29);\n\n try\n {\n thread.start();\n thread.join();\n }\n catch (InterruptedException e)\n {\n e.printStackTrace();\n }\n\n in.close();\n out.flush();\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e848e743ce04e6befe8e47c83bfc606c", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Copyright (c) 2017, Bongmi\n * All rights reserved\n * Author: shanhaosheng@bongmi.com\n */\npublic class Main {\n private static final Scanner IN = new Scanner(System.in);\n\n public static void main(String[] args) {\n while (IN.hasNext()) {\n String str = IN.next();\n str = str.replaceAll(\"0\", \" \").trim();\n if (str.equals(new StringBuilder(str).reverse().toString())) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "69a07f68b2e80e087020c0af1db094b7", "src_uid": "d82278932881e3aa997086c909f29051", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Codeforces863b {\n\tpublic static void main(String[] args) {\n\n\tScanner scan = new Scanner(System.in);\n\tString palin = scan.nextLine();\n\tif(palin.contains(\"0\")){\n\t\tpalin = palin.replace(\"0\", \"\");\n\t}\n\tfor(int i=0; i set = new HashSet();\n//_________________________________________________________________________________________________\n\n char[]a=sc.next().toCharArray();\n String h=\"\";\n int x = a.length;boolean t=true;\n for (int i = 0; i < x;i++) {\n if(a[i]!='0')\n h+=a[i];\n \n }\n \n for(int i=0,j=h.length()-1;i0)solve();\n\t\tout.flush();\n\t\tout.close();\n\t}\n\tpublic static void solve() {\n\t\tprecomp();\n\t\tint n = sc.nextInt();\n\t\tint x = sc.nextInt();\n\t\tint pos = sc.nextInt();\n\t\tint[] a = new int[n];\n\t\tArrays.fill(a, -1);\n\t\tTreeSet A = new TreeSet<>();\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tA.add(i);\n\t\t}\n\t\tint small = 0;\n\t\tint big = 0;\n\t\tint l = 0;\n\t\tint r = n;\n\t\twhile(lpos) { //a[m]>x\n\t\t\t\ta[m] = A.higher(x);\n\t\t\t\tA.remove(a[m]);\n\t\t\t\tbig++;\n\t\t\t\t//out.println(a[m]+\" \"+m);\n\t\t\t\tr = m;\n\t\t\t}\n\t\t\telse { //a[m] connect = new ArrayList<>();\n\t\tint comp = -1;\n\t\tpublic int gsize() {\n\t\t\treturn connect.size();\n\t\t}\n\t}\n\tstatic long nC2(long n) {\n\t\treturn add((n*(n+1))/2, 0);\n\t}\n\tpublic static int maxRight(int x,int[] a) {\n\t\tint l = -1; //a[l]<=x\n\t\tint r = a.length;//a[r]>x\n\t\twhile(r-l>1) {\n\t\t\tint m = l+(r-l)/2;\n\t\t\tif(a[m]<=x) {\n\t\t\t\tl = m;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tr = m;\n\t\t\t}\n\t\t}\n\t\treturn l+1;\n\t}\n\tpublic static int minLeft(int x,int[] a) {\n\t\tint l = -1; //a[l]=x\n\t\twhile(r-l>1) {\n\t\t\tint m = l+(r-l)/2;\n\t\t\tif(a[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, int[] a) {\n\t\tint s = 0;\n\t\tint e = a.length-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[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() {\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 primeFactors(long n) {\n ArrayList 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 static class Pair implements Comparable{\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 -1*(this.x-o.x);\n\t\t}\n\t}\n\tstatic class TPair implements Comparable{\n\t\tint l;\n\t\tint r;\n\t\tlong index;\n\t\tpublic TPair(int l, int r, long index) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t\tthis.index = index;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(TPair o) {\n\t\t\tif(this.l==o.l){\n\t\t\t return (this.r-o.r);\n\t\t\t}\n\t\t\treturn -1*(this.l-o.l);\n\t\t}\n\t}\n//nCr\n\tstatic long[] facts, factInvs;\n\tstatic long exp(long base, long e) {\n\t\tif (e==0) return 1;\n\t\tlong half=exp(base, e/2);\n\t\tif (e%2==0) return mul(half, half);\n\t\treturn mul(half, mul(half, base));\n\t}\n\t\n\tstatic long modInv(long x) {\n\t\treturn exp(x, MOD-2);\n\t}\n\t\n\tstatic void precomp() {\n\t\tfacts=new long[1_000_000];\n\t\tfactInvs=new long[1_000_000];\n\t\tfactInvs[0]=facts[0]=1;\n\t\tfor (int i=1; i=0; i--)\n\t\t\tfactInvs[i]=mul(factInvs[i+1], i+1);\n\t}\n\t\n\tstatic long nCk(int n, int k) {\n\t\treturn mul(facts[n], mul(factInvs[k], factInvs[n-k]));\n\t}\n//Kadane's Algorithm \n static long maxSubArraySum(ArrayList 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 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(long 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 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[] indiFactors(int n){\n \tArrayList[] 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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eace41cc044f005dbe3b83f0f1e13f44", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\n\t\npublic class C \n{\t\n\tstatic long facts[],factInvs[],mod=(long)1e9+7;\n\t\n\tpublic static void main(String[] args)throws IOException \n\t{\t\n\t\tFastReader f=new FastReader();\n\t\tStringBuffer sb = new StringBuffer();\n\t\tprecomp();\n\t\t\n\t\tint test=1;\n\t\twhile(test-->0)\n\t\t{\t\n\t\t\tint n=f.nextInt();\n\t\t\tint x=f.nextInt();\n\t\t\tint pos=f.nextInt();\n\t\t\t\n\t\t\tint small=0;int big=0;\n\t\t\tint l=0;\n\t\t\tint r=n;\n\t\t\twhile(lpos) \n\t\t\t\t\tbig++;\n\t\t\t\tif(mid= 0; i--)\n\t\t\tfactInvs[i] = mul(factInvs[i + 1], i + 1);\n\t}\n\n\tstatic long getNcR(int n, int k) {\n\t\treturn mul(facts[n], mul(factInvs[k], factInvs[n - k]));\n\t}\n\n\tstatic long mul(long a, long b) {\n\t\treturn a * b % mod;\n\t}\n\n\tstatic long modInv(long x) {\n\t\treturn exp(x, mod - 2);\n\t}\n\n\tstatic long exp(long base, long e) {\n\t\tif (e == 0)\n\t\t\treturn 1;\n\t\tlong half = exp(base, e / 2);\n\t\tif (e % 2 == 0)\n\t\t\treturn mul(half, half);\n\t\telse\n\t\t\treturn mul(half, mul(half, base));\n\t}\n\t\n\tstatic class FastReader \n\t{ \n\t BufferedReader br; \n\t StringTokenizer st; \n\n\t public FastReader() {\n\t \tbr = new BufferedReader(new\n\t InputStreamReader(System.in)); \n\t }\n\t String next() { \n\t while (st == null || !st.hasMoreElements()) { \n\t try{ \n\t st = new StringTokenizer(br.readLine()); \n\t } \n\t catch (IOException e) { \n\t e.printStackTrace(); \n\t } \n\t } \n\t return st.nextToken(); \n\t } \n\t int nextInt() { \n\t return Integer.parseInt(next()); \n\t } \n\t long nextLong() { \n\t return Long.parseLong(next()); \n\t } \n\t double nextDouble() { \n\t return Double.parseDouble(next()); \n\t } \n\t String nextLine() { \n\t String str = \"\"; \n\t try{ \n\t str = br.readLine(); \n\t } \n\t catch (IOException e) { \n\t e.printStackTrace(); \n\t } \n\t return str; \n\t } \n\t} \n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4468830b25ec6b5a37987c6f15450a34", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport javax.print.attribute.HashAttributeSet;\n\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;\nimport java.security.cert.TrustAnchor;\npublic class Codeforces{\n\tpublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\tstatic long MOD = (long)(1e9+7);\n\t//static int MOD = 998244353;\n\tstatic long MOD2 = MOD*MOD;\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)solve();\n\t\tout.flush();\n\t\tout.close();\n\t}\n\tpublic static void solve() {\n\t\tprecomp();\n\t\tint n = sc.nextInt();\n\t\tint x = sc.nextInt();\n\t\tint pos = sc.nextInt();\n\t\tint[] a = new int[n];\n\t\tArrays.fill(a, -1);\n\t\tint small = 0;\n\t\tint big = 0;\n\t\tint l = 0;\n\t\tint r = n;\n\t\twhile(lpos) { //a[m]>x\n\t\t\t\tbig++;\n\t\t\t\t//out.println(a[m]+\" \"+m);\n\t\t\t\tr = m;\n\t\t\t}\n\t\t\telse { //a[m] connect = new ArrayList<>();\n\t\tint comp = -1;\n\t\tpublic int gsize() {\n\t\t\treturn connect.size();\n\t\t}\n\t}\n\tstatic long nC2(long n) {\n\t\treturn add((n*(n+1))/2, 0);\n\t}\n\tpublic static int maxRight(int x,int[] a) {\n\t\tint l = -1; //a[l]<=x\n\t\tint r = a.length;//a[r]>x\n\t\twhile(r-l>1) {\n\t\t\tint m = l+(r-l)/2;\n\t\t\tif(a[m]<=x) {\n\t\t\t\tl = m;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tr = m;\n\t\t\t}\n\t\t}\n\t\treturn l+1;\n\t}\n\tpublic static int minLeft(int x,int[] a) {\n\t\tint l = -1; //a[l]=x\n\t\twhile(r-l>1) {\n\t\t\tint m = l+(r-l)/2;\n\t\t\tif(a[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, int[] a) {\n\t\tint s = 0;\n\t\tint e = a.length-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[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() {\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 primeFactors(long n) {\n ArrayList 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 static class Pair implements Comparable{\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 -1*(this.x-o.x);\n\t\t}\n\t}\n\tstatic class TPair implements Comparable{\n\t\tint l;\n\t\tint r;\n\t\tlong index;\n\t\tpublic TPair(int l, int r, long index) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t\tthis.index = index;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(TPair o) {\n\t\t\tif(this.l==o.l){\n\t\t\t return (this.r-o.r);\n\t\t\t}\n\t\t\treturn -1*(this.l-o.l);\n\t\t}\n\t}\n//nCr\n\tstatic long[] facts, factInvs;\n\tstatic long exp(long base, long e) {\n\t\tif (e==0) return 1;\n\t\tlong half=exp(base, e/2);\n\t\tif (e%2==0) return mul(half, half);\n\t\treturn mul(half, mul(half, base));\n\t}\n\t\n\tstatic long modInv(long x) {\n\t\treturn exp(x, MOD-2);\n\t}\n\t\n\tstatic void precomp() {\n\t\tfacts=new long[1_000_000];\n\t\tfactInvs=new long[1_000_000];\n\t\tfactInvs[0]=facts[0]=1;\n\t\tfor (int i=1; i=0; i--)\n\t\t\tfactInvs[i]=mul(factInvs[i+1], i+1);\n\t}\n\t\n\tstatic long nCk(int n, int k) {\n\t\treturn mul(facts[n], mul(factInvs[k], factInvs[n-k]));\n\t}\n//Kadane's Algorithm \n static long maxSubArraySum(ArrayList 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 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(long 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 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[] indiFactors(int n){\n \tArrayList[] 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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "473edfff9085df0856bea841e18d6db5", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class TaskC {\n\n private static long MOD = 1_000_000_000+7;\n\n public static void main(String[] arg) {\n final FastScanner in = new FastScanner(System.in);\n final PrintWriter out = new PrintWriter(System.out);\n final int n = in.nextInt();\n final int x = in.nextInt();\n final int pos = in.nextInt();\n out.println(solution(pos, n, x));\n out.close();\n in.close();\n }\n\n private static long solution(int pos,\n int len,\n int e){\n String path = bs(pos, len, e);\n //System.out.println(path);\n long permut = mod_fact(len-1-path.length());\n long traverse = traverse(e, 1, len, path.toCharArray(),0);\n return (permut*traverse)%MOD;\n }\n\n private static String bs(int pos, int len,\n int element){\n int left = 0;\n int right = len;\n int deep = 1;\n StringBuilder path = new StringBuilder();\n while(left=1;i--){\n result+=(i-1);\n }\n return result;\n }\n\n\n private static long mod_fact(int n){\n long result =1;\n for(int i=2;i<=n;i++){\n result*=i;\n result%=MOD;\n }\n return result;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f8e303961bfcd2594f38c2d404d05f10", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "\nimport java.io.BufferedReader;\nimport java.util.Scanner;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\npublic class A216 \n{\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic void pn(Object o) {\n\t\tout.println(o);\n\t\tout.flush();\n\n\t}\n\n\tstatic void p(Object o) {\n\t\tout.print(o);\n\t\tout.flush();\n\t}\n\n\tstatic void pni(Object o) {\n\t\tout.println(o);\n\t\tSystem.out.flush();\n\t}\n\n\tstatic int I() throws IOException {\n\t\treturn sc.nextInt();\n\t}\n\n\tstatic long L() throws IOException {\n\t\treturn sc.nextLong();\n\t}\n\n\tstatic double D() throws IOException {\n\t\treturn sc.nextDouble();\n\t}\n\n\tstatic String S() throws IOException {\n\t\treturn sc.nextLine();\n\t}\n\n\tstatic char C() throws IOException {\n\t\treturn sc.next().charAt(0);\n\t}\n\tstatic int[] Ai(int n) throws IOException {\n\t\tint[] arr = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = I();\n\t\t\n\t\treturn arr;\n\t}\n\t\n\tstatic String[] As(int n) throws IOException {\n\t\tString s[] = new String[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ts[i] = S();\n\t\t\n\t\treturn s;\n\t}\n\t\n\tstatic long[] Al(int n) throws IOException {\n\t\tlong[] arr = new long[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tarr[i] = L();\n\t\t\n\t\treturn arr;\n\t}\n\tpublic static void process() throws IOException\n\t{\n\t int a=I();\n\t int b=I();\n\t int c=I();int sum=0;\n\t while(2*(a+b+c)>6)\n\t {\n\t\t sum=sum+(2*(a+b+c)-6);\n\t\t a=a-1;b=b-1;c=c-1;\n\t }\n\t if(a==b && b==c && c==a)\n\t {\n\t\t pn(sum+1);\n\t }\n\t else\n\t if(a==b || b==c || c==a)\n\t {\n\t\t pn(sum-1);\n\t }\n\t else\n\t\t \n\t\t pn(sum);\n\t\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tprocess();\n\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\n\t\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\n\t\t\n\t\t\n\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2f583ba086c9c4fe0bb8d7288140c015", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class hexa\n{\npublic static void main(String[] args) throws java.lang.Exception {\nScanner f = new Scanner(System.in);\n\t\tint x = f.nextInt();\n\t\tint y = f.nextInt();\n\t\tint z = f.nextInt();\n\n\t\tSystem.out.println(x*2+y*2+z*2);\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4872f06ada0cc420bd008de018670cf2", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\nimport java.util.*;\n\npublic class Main\n{\n static Scanner in = new Scanner( System.in );\n\n public static void main( String[] args )\n {\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int sum = 0;\n while ( a != 1 || b != 1 || c != 1 )\n {\n sum += ( a + b + c ) * 2 - 6;\n a--; b--; c--;\n }\n sum += a * b * c;\n System.out.println( sum );\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bc53a5e0272ee65fa1974a0fd10fa374", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "package Round_133;\n\nimport java.io.IOException;\nimport java.util.Scanner;\n\npublic class A {\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int count = 0;\n while (a > 0 && b > 0 && c > 0) {\n count += a;\n count += b - 1;\n count += c - 1;\n count += a - 1;\n count += b - 1;\n count += c - 2;\n a--;\n b--;\n c--;\n }\n System.out.println(count);\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11671e1746eb393dc07f919d430d29e7", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n\n\n private static final Scanner scan = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = scan.nextInt();\n int k = scan.nextInt();\n int A = scan.nextInt();\n int B = scan.nextInt();\n int[] mem = new int[n+1];\n System.out.println(findResult(n,k,A,B,mem));\n }\n public static int findResult(int n, int k, int A, int B, int[] mem){\n if(n == 1){\n mem[n] = 0;\n return 0;\n }\n if(mem[n] > 0 ){\n return mem[n];\n }else{\n int subResult = findResult(n-1,k,A,B,mem);\n int divideResult = -1;\n if(n%k == 0){\n divideResult = findResult(n/k,k,A,B,mem);\n }\n if(divideResult < 0){\n mem[n] = subResult+A;\n }else{\n mem[n] = Math.min(subResult+A, divideResult+B);\n }\n return mem[n];\n }\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e06faffeef25bacf8e94197337d6caa", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * 0da - 24.02.2018.\n */\npublic class B {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int k = scanner.nextInt();\n int A = scanner.nextInt();\n int B = scanner.nextInt();\n\n int[] array = new int[n + 1];\n\n Arrays.fill(array, Integer.MAX_VALUE);\n\n array[1] = 0;\n\n for (int i = 1; i < array.length; i++) {\n int price = array[i];\n int multiplication = i * k;\n if (multiplication <= n) {\n array[multiplication] = Math.min(price + B, array[multiplication]);\n }\n\n int inc = i+1;\n if (inc <= n) {\n array[inc] = Math.min(price + A, array[inc]);\n }\n }\n\n System.out.println(array[n]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e5630ae7a18f308819b22fd9f062b957", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class Solution\n{\n// static class Com implements Comparator{\n// public int compare(Pair A,Pair B)\n// {\n// return B.y-A.y;\n// }\n// }\n static class Pair{\n int parent;\n int rank;\n Pair(int parent,int rank)\n {\n this.rank=rank;\n this.parent=parent;\n }\n }\n static int find(Pair pr[],int i)\n {\n if(i==pr[i].parent)\n return i;\n else\n {\n pr[i].parent=find(pr,pr[i].parent);\n return pr[i].parent;\n }\n }\n static void join(Pair[] pr,int i,int j)\n {\n i=find(pr,i);\n j=find(pr,j);\n if(i==j)\n return;\n if(pr[i].rank>=pr[j].rank)\n {\n pr[j].parent=i;\n pr[i].rank+=pr[j].rank;\n }\n else\n {\n pr[i].parent = j;\n pr[j].rank+=pr[i].rank;\n }\n }\n static int dp[];\n\tpublic static void main (String[] args)\n\t{\n FastReader s1 = new FastReader();\n StringBuilder sb = new StringBuilder();\n int n = s1.I();\n dp=new int[n+1];\n Arrays.fill(dp,Integer.MAX_VALUE);\n int k=s1.I();\n int A = s1.I();\n int B = s1.I();\n System.out.println(min(n,k,A,B));\n }\n static int min(int no,int k,int A,int B)\n {\n if(no==1)\n return 0;\n if(no%k!=0)\n {\n dp[no] = Math.min(A+min(no-1,k,A,B),dp[no]);\n }\n else\n {\n dp[no]=Math.min(min(no/k,k,A,B)+B, A+min(no-1,k,A,B));\n }\n return dp[no];\n }\n static int log2(int n)\n {\n double val = Math.log(n)/Math.log(2);\n return (int)val;\n }\n static int binary(int left,int right,int ar[],int no)\n {\n int mid=(left+right)/2;\n if(Math.abs(right-left)<=1)\n {\n if(no>=ar[right])\n {\n return right+1;\n }\n else if(nono)\n {\n right=mid-1;\n return binary(left, right, ar, no);\n }\n else{\n left=mid;\n return binary(left, right, ar, no);\n }\n }\n\tstatic class FastReader{\n BufferedReader br; \n StringTokenizer st; \n public FastReader() \n { \n br = new BufferedReader(new\n InputStreamReader(System.in)); \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 I() \n { \n return Integer.parseInt(next()); \n } \n \n long L() \n { \n return Long.parseLong(next()); \n } \n \n double D() \n { \n return Double.parseDouble(next()); \n } \n \n String nextLine() \n { \n String str = \"\"; \n try\n { \n str = br.readLine(); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n return str; \n } \n }\n static int gcd(int a,int b)\n\t\t{\n\t\t if(a%b==0)\n\t\t return b;\n\t\t return gcd(b,a%b);\n\t\t}\n\tstatic float power(float x, int y) \n { \n float temp; \n if( y == 0) \n return 1; \n temp = power(x, y/2); \n \n if (y%2 == 0) \n return temp*temp; \n else\n { \n if(y > 0) \n return x * temp * temp; \n else\n return (temp * temp) / x; \n } \n } \n static long pow(int x, int y) \n { \n int p = 1000000007;\n long res = 1; \n x = x % p; \n while (y > 0) \n { \n if((y & 1)==1) \n res = (res * x) % p;\n y = y >> 1; \n x = (x * x) % p; \n } \n return res; \n } \n static ArrayList sieveOfEratosthenes(int n) \n { \n ArrayList arr=new ArrayList();\n boolean prime[] = new boolean[n+1]; \n for(int i=2;i {\n }\n\n int inf = 1000 * 1000 * 1000;\n\n int[] levit(List[] a, int v1) {\n\n int d[] = new int[a.length];\n Arrays.fill(d, inf);\n d[v1] = 0;\n int[] state = new int[a.length];\n ArrayDeque q = new ArrayDeque();\n q.add(v1);\n int[] p = new int[a.length];\n Arrays.fill(p, -1);\n while (!q.isEmpty()) {\n int v = q.pollFirst();\n state[v] = 1;\n for (Pair i : a[v]) {\n int to = i.v;\n int len = i.len;\n if (d[to] > d[v] + len) {\n d[to] = d[v] + len;\n if (state[to] == 0) {\n q.add(to);\n } else if (state[to] == 1) {\n q.addFirst(to);\n }\n p[to] = v;\n state[to] = 1;\n }\n }\n }\n return d;\n }\n\n void setIn(String fI) {\n\n try {\n in = new Scanner(new FileInputStream(new File(fI)));\n } catch (FileNotFoundException e) {\n throw new Error(e);\n }\n }\n\n void setIn() {\n in = new Scanner(System.in);\n }\n\n void setOut(String fO) {\n try {\n out = new PrintWriter(new FileWriter(fO));\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n void setOut() {\n out = new PrintWriter(System.out);\n }\n\n class Scanner {\n StringTokenizer st;\n BufferedReader in;\n String del;\n\n Scanner(InputStream is) {\n in = new BufferedReader(new InputStreamReader(is));\n st = null;\n del = \" \\t\\n\\r\\f\";\n }\n\n void setDelimiters(String del) {\n this.del = del;\n }\n\n String next() {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine(), del);\n }\n return st.nextToken();\n }\n\n String nextLine() {\n try {\n st = null;\n return in.readLine();\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n char nextChar() {\n try {\n char ch = (char) in.read();\n while (del.indexOf(ch) >= 0)\n ch = (char) in.read();\n return ch;\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n boolean hasNext() {\n try {\n return in.ready() || (st != null && st.hasMoreTokens());\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n BigInteger nextBigInteger() {\n return new BigInteger(next());\n }\n\n BigDecimal nextBigDecimal() {\n return new BigDecimal(next());\n }\n\n int[] nextIntArray(int len) {\n int[] a = new int[len];\n for (int i = 0; i < len; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n void run() {\n setIn();\n setOut();\n try {\n solve();\n } finally {\n out.close();\n }\n }\n\n void solve() {\n int x = in.nextInt();\n int t = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n int da = in.nextInt();\n int db = in.nextInt();\n boolean[] s1 = new boolean[a + 1];\n boolean[] s2 = new boolean[b + 1];\n for (int i = 0; i < t; i++) {\n s1[a - da * i] = true;\n s2[b - db * i] = true;\n }\n for (int s = 0; s < s1.length; s++) {\n if ((x - s < s2.length && x - s >= 0 && s1[s] && s2[x - s])\n || (x - s < s1.length && x - s >= 0 && s2[s] && s1[x - s])) {\n out.println(\"YES\");\n return;\n }\n }\n out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00ff567641af5c1ffa7a2b57d3b21850", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner input = new Scanner(System.in);\n\t\tint[] month = {31,28,31,30,31,30,31,31,30,31,30,31};\n\t\tint n = input.nextInt();\n\t\tString mon1 = \"\";\n\t\tString mon2 = \"\";\n\t\tString[] mon = new String [8];\n\t\tfor(int i = 0;i < 12;i++){\n\t\t\tif(i == 1){\n\t\t\t\tmon1 += \"29\";\n\t\t\t\tmon2 += \"28\";\n\t\t\t}\n\t\t\telse{\n\t\t\t\tmon1 += String.valueOf(month[i]);\n\t\t\t\tmon2 += String.valueOf(month[i]);\n\t\t\t}\n\t\t}\n\t\tmon[0] = mon1 + mon1 + mon1;\n\t\tmon[1] = mon1 + mon1 + mon2;\n\t\tmon[2] = mon1 + mon2 + mon1;\n\t\tmon[3] = mon1 + mon2 + mon2;\n\t\tmon[4] = mon2 + mon1 + mon1;\n\t\tmon[5] = mon2 + mon1 + mon2;\n\t\tmon[6] = mon2 + mon2 + mon1;\n\t\tmon[7] = mon2 + mon2 + mon2;\n\t\tString target = \"\";\n\t\tfor(int i = 0;i < n;i++)\n\t\t\ttarget += input.next();\n\t\tint sign = 0;\n\t\tfor(int i = 0;i < 8;i++)\n\t\t\tif(mon[i].contains(target)){\n\t\t\t\tsign = 1;\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\tif(sign == 0)\n\t\t\tSystem.out.println(\"NO\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e22133e0b267d45210c825130a3ef59b", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.util.regex.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n //Scanner sc = new Scanner(System.in);\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String pp = \"31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31\";\n String pp2 = \"31 29 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31\";\n\n int t = Integer.parseInt(br.readLine());\n //StringBuilder str = new StringBuilder();\n \n \n String s = br.readLine();\n // System.out.println(s);\n Pattern p1 = Pattern.compile(s);\n Matcher m1 = p1.matcher(pp);\n \n boolean flag = false;\n\n while(m1.find()){\n System.out.println(\"Yes\");\n flag = true;\n break;\n }\n\n if(!flag){\n \t Pattern p2 = Pattern.compile(s);\n Matcher m2 = p2.matcher(pp2);\n \n while(m2.find()){\n System.out.println(\"Yes\");\n flag = true;\n break;\n }\n }\n \n if(!flag){\n \t System.out.println(\"No\");\n }\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "86fb4c0c9c909d81859ca96f87187059", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Test \n{ \npublic static void main(String[] args) throws IOException\n{\n String str=\"31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31\";\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n sc.nextLine();\n String s=sc.nextLine();\n if(str.indexOf(s)>=0){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n \n \n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0bda46810daeccbe98e9b95a92881ff9", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.util.Collections;\npublic class JavaApplication7 {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int[] arr = new int[13];\n arr[1]=31;\n arr[2]=28;\n arr[3]=31;\n arr[4]=30;\n arr[5]=31;\n arr[6]=30;\n arr[7]=31;\n arr[8]=31;\n arr[9]=30;\n arr[10]=31;\n arr[11]=30;\n arr[12]=31;\n int n =input.nextInt();\n String answer = \"Yes\";\n String entry =\"\";\n \n for(int i=0;i= numChars) {\n curChar = 0;\n try {\n numChars = mIs.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 public String nextLine() {\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 (!isEndOfLine(c));\n return res.toString();\n }\n\n public String s() {\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 long l() {\n int c = read();\n while (isSpaceChar(c)) 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') 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 int i() {\n int c = read();\n while (isSpaceChar(c)) c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public double d() throws IOException {\n return Double.parseDouble(s());\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n public int[] arr(int n) {\n int[] ret = new int[n];\n for (int i = 0; i < n; i++) {\n ret[i] = i();\n }\n return ret;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "33cea9ffba129a485bd9261593e31361", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n//public final class code\nclass code\n{\n\tstatic int dp[][];\n\tstatic int ans(int n,int m)\n\t{\n\n\t\tif(n==0 && m==0)\n\t\t\treturn 0;\n\t\tif(n<0 || m<0)\n\t\t\treturn -1;\n\t\tif(dp[n][m]!=0)\n\t\t\treturn dp[n][m];\n\t\tdp[n][m]=Math.max(1+ans(n-1,m-2),1+ans(n-2,m-1));\n\t\treturn dp[n][m];\n\t}\n\tstatic void solve()throws IOException\n\t{\n\t\tint n=nextInt();\n\t\tint m=nextInt();\n\t\tdp=new int[n+1][m+1];\n\t\tout.println(ans(n,m));\n\t}\n\n\n\n\n\n\n\t\n\t///////////////////////////////////////////////////////////\n\tstatic final long mod=(long)(1e9+7);\n\tstatic final int inf=(int)(1e9);\n\tstatic class Pair implements Comparable\n\t{\n\t\tint first,second;\n\t\tPair(int a,int b)\n\t\t{\n\t\t\tfirst=a;\n\t\t\tsecond=b;\n\t\t}\n\t\tpublic int compareTo(Pair p)\n\t\t{\n\t\t\treturn this.second-p.second;\n\t\t}\n\t}\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out;\n\tstatic String nextToken()throws IOException\n\t{\n\t\twhile(st==null || !st.hasMoreTokens())\n\t\t\tst=new StringTokenizer(br.readLine());\n\t\treturn st.nextToken();\n\t}\n\tstatic String nextLine()throws IOException\n\t{\n\t\treturn br.readLine();\n\t}\n\tstatic int nextInt()throws IOException\n\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tstatic long nextLong()throws IOException\n\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tstatic double nextDouble()throws IOException\n\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tpublic static void main(String args[])throws IOException\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\tout=new PrintWriter(new BufferedOutputStream(System.out));\n\t\tsolve();\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e17732de3a994c42a65fd4ec496dd495", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n int [][] dp = new int [n+1][m+1];\n for (int i = 2; i <= m; i++) {\n dp[1][i] = 1;\n }\n for (int i = 2; i <= n; i++) {\n dp[i][1] = 1;\n }\n \n for (int i = 2; i <= n; i++) {\n for (int j = 2; j <= m; j++) {\n int x = Math.max(dp[i-1][j-2], dp[i-2][j-1]);\n dp[i][j] = x + 1;\n }\n }\n \n System.out.println(dp[n][m]);\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2c6579372b851a9bd0797d3c203da55", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class test\n{ \n \n\n public static void main(String args[]) throws IOException\n {\n InputStreamReader inp = new InputStreamReader(System.in);\n BufferedReader br = new BufferedReader(inp);\n\n String s[] = br.readLine().split(\" \");\n int n = Integer.parseInt(s[0]); \n int m = Integer.parseInt(s[1]); \n\n int dp[][] = new int[n+1][m+1];\n dp[1][1]=0;\n for(int i=2;i<=m;i++)\n {\n dp[1][i]=1;\n }\n for(int i=2;i<=n;i++)\n {\n dp[i][1]=1;\n }\n \n for(int i=2;i<=n;i++)\n {\n for(int j=2;j<=m;j++)\n {\n int max = Math.max(i,j);\n if(max==i)\n {\n dp[i][j] = dp[i-2][j-1]+1;\n }\n else if(max==j)\n {\n dp[i][j] = dp[i-1][j-2]+1;\n }\n }\n }\n\n System.out.println(dp[n][m]);\n \n }\n\n \n\n\n \n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "01fc691681f81b0768d7a7ce2c8c173c", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author captainTurtle\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 k = in.nextInt();\n int n = in.nextInt();\n int g = 0, w = 0, s = 0;\n\n if ((k / 2) > n) {\n for (int i = 0; i < 3; i++) {\n if ((k / 2) % 3 == 0) {\n g = k / 6;\n w = k / 3;\n s = k - (g + w);\n System.out.print(g);\n System.out.print(\" \");\n System.out.print(w);\n System.out.print(\" \");\n System.out.print(s);\n } else {\n continue;\n }\n k--;\n }\n } else {\n g = 0;\n w = 0;\n System.out.print(g);\n System.out.print(\" \");\n System.out.print(w);\n System.out.print(\" \");\n System.out.print(k - (g + w));\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e9ea71c986332cad61310fab713fbdb8", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.IOException;\n\n/**\n * Created by Shoumik on 01-Aug-17.\n */\n\npublic class Dc {\n public static void main(String [] args) throws IOException\n {\n Scanner sc = new Scanner(System.in);\n long i, n=sc.nextLong();\n int k=sc.nextInt();\n\n for(i=0; i*i*i*k*k*k=0; i--)\n {\n\n if (i*(k+1)<=n/2)\n {\n System.out.println(i+ \" \"+ k*i +\" \"+ (n-i*(k+1)));\n break;\n }\n }\n\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "771ca9d92c5179060704d16ca2bdb38a", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class BalanceScale {\n\tpublic static void main(String[] args){\n\tScanner in = new Scanner(System.in);\n\twhile(in.hasNext()){\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint a,b,c;\n\t\ta=n/2/(k+1);\n\t\tb=a*k;\n\t\tc=n-a-b;\n\t\tSystem.out.println(a+\" \"+b+\" \"+c);\n\t}\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "13c56f3d570efdbe9f5ebe1cd1c62f0e", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.IOException;\n\n/**\n * Created by Shoumik on 01-Aug-17.\n */\n\npublic class Dc {\n public static void main(String [] args) throws IOException\n {\n Scanner sc = new Scanner(System.in);\n\n int i,n=sc.nextInt(), k=sc.nextInt(), x,y,z;\n\n for(i=0; i*i*i*k*k*k=0; i--)\n {\n if (i*(k+1)<=n/2)\n {\n System.out.println(i+ \" \"+ k*i +\" \"+ (n-i*(k+1)));\n break;\n }\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7692ce6e412bf73e92b6c8a7d434849a", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\n\n/**\n * @author mohanad\n *\n */\npublic class P8_Div2_118D {\n\n\t/**\n\t * @param args\n\t * @throws IOException \n\t */\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tString nk[]=bf.readLine().split(\" \");\n\t\tn1=Integer.parseInt(nk[0]);\n\t\tn2=Integer.parseInt(nk[1]);\n\t\tk1=Integer.parseInt(nk[2]);\n\t\tk2=Integer.parseInt(nk[3]);\n\t\tdp=new int [101][101][101][101];\n\t\tfor (int a[][][]:dp)\n\t\t\tfor (int s[][]:a)\n\t\t\t\tfor (int ss[]:s)\n\t\t\t\t\t\tArrays.fill(ss, -1);\n//\t\tSystem.out.println(\"start\");\n\t\tSystem.out.println(solv(0, 0, 0, 0 ));\n\t}\n\n\tstatic int n1,n2,k1,k2 , dp[][][][];\n\tstatic int solv (int f , int h , int fsum , int hsum ){\n\t\tif ((fsum+hsum)==(n1+n2)){\n//\t\t\tSystem.out.println(s);\n\t\t\treturn 1 ;\n\t\t\t\n\t\t}\n\t\tif (dp[f][h][fsum][hsum]!=-1){\n//\t\t\tSystem.out.println(\"dp\");\n\t\t\treturn dp[f][h][fsum][hsum];\n\t\t}\n//\t\t\n\t\tint a=0;\n\t\tif (f k1 || c2 > k2 || cc1 > n1 || cc2 > n2)\n\t\t\treturn 0;\n\n\t\tif (counter == n1 + n2)\n\t\t\treturn 1;\n\n\t\tif (dp[counter][c1][c2][cc1][cc2] != -1)\n\t\t\treturn dp[counter][c1][c2][cc1][cc2];\n\n\t\treturn dp[counter][c1][c2][cc1][cc2] = getCount(n1, n2, k1, k2, c1 + 1,\n\t\t\t\t0, counter + 1, cc1 + 1, cc2, 1)\n\t\t\t\t% 100000000\n\t\t\t\t+ getCount(n1, n2, k1, k2, 0, c2 + 1, counter + 1, cc1,\n\t\t\t\t\t\tcc2 + 1, 2) % 100000000;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d7c0b4d38416369409a1b0e48358c92", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class CaesarsLegions {\n\tstatic int[][][][] dp;\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n1 = sc.nextInt();\n\t\tint n2 = sc.nextInt();\n\t\tint k1 = sc.nextInt();\n\t\tint k2 = sc.nextInt();\n\n\t\tdp = new int[n1 + 1][n2 + 1][n1 + 1][n2 + 1];\n\n\t\tfor (int j = 0; j < n1 + 1; j++)\n\t\t\tfor (int k = 0; k < n2 + 1; k++)\n\t\t\t\tfor (int jj = 0; jj < n1 + 1; jj++)\n\t\t\t\t\tArrays.fill(dp[j][k][jj], -1);\n\n\t\tSystem.out\n\t\t\t\t.println(getCount(n1, n2, k1, k2, 0, 0, 0, 0, 0, 0) % 100000000);\n\t}\n\n\tprivate static int getCount(int n1, int n2, int k1, int k2, int c1, int c2,\n\t\t\tint counter, int cc1, int cc2, int last) {\n\t\tif (c1 > k1 || c2 > k2 || cc1 > n1 || cc2 > n2)\n\t\t\treturn 0;\n\n\t\tif (counter == n1 + n2)\n\t\t\treturn 1;\n\n\t\tif (dp[c1][c2][cc1][cc2] != -1)\n\t\t\treturn dp[c1][c2][cc1][cc2];\n\n\t\treturn dp[c1][c2][cc1][cc2] = getCount(n1, n2, k1, k2, c1 + 1, 0,\n\t\t\t\tcounter + 1, cc1 + 1, cc2, 1)\n\t\t\t\t% 100000000\n\t\t\t\t+ getCount(n1, n2, k1, k2, 0, c2 + 1, counter + 1, cc1,\n\t\t\t\t\t\tcc2 + 1, 2) % 100000000;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0a56f0525e7ce978e509ad9acec6a77a", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class four {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n1 = sc.nextInt();\n int n2 = sc.nextInt();\n int k1 = sc.nextInt();\n int k2 = sc.nextInt();\n int[][][][][] dp = new int[n1 + n2][n1 + 1][n2 + 1][2][Math.max(n1, n2) + 1];\n for (int i = 0; i < dp.length; i++)\n for (int j = 0; j < dp[0].length; j++)\n for (int k = 0; k < dp[0][0].length; k++)\n for (int l = 0; l < dp[0][0][0].length; l++)\n Arrays.fill(dp[i][j][k][l], -1);\n\n long ans = go(1, n1 - 1, n2, k1, k2, true, 1, dp) % 100000000;\n ans += go(1, n1, n2 - 1, k1, k2, false, 1, dp) % 100000000;\n System.out.println(ans % 100000000);\n }\n\n private static int go(int place, int n1, int n2, int k1, int k2,\n boolean type, int count, int[][][][][] dp) {\n if (n1 < 0 || n2 < 0)\n return 0;\n if (type && count > k1 || !type && count > k2)\n return 0;\n if (place == dp.length)\n return 1;\n if (dp[place][n1][n2][(type) ? 0 : 1][count] != -1)\n return dp[place][n1][n2][(type) ? 0 : 1][count];\n else {\n int sum = 0;\n\n sum += go(place + 1, n1 - 1, n2, k1, k2, true, (type) ? count + 1\n : 1, dp) % 100000000;\n sum += go(place + 1, n1, n2 - 1, k1, k2, false, (!type) ? count + 1\n : 1, dp) % 100000000;\n return dp[place][n1][n2][(type) ? 0 : 1][count] = sum % 100000000;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2f18542122f6d12384e37761e5f4d41a", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\n\npublic class Main {\n static HashSet memoizacija;\n\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n\n int N = sc.nextInt();\n\n int res1 = 0;\n\n\n for(int i = 0; i<810; i++){\n int res2 = 0;\n for(int j = 0; j<8100; j++){\n int res = N - res1 - res2;\n if(res > 0 && res%1234 == 0){\n System.out.println(\"YES\");\n System.exit(0);\n }\n res2 += 123456;\n }\n res1 += 1234567;\n }\n\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "39eaceafd2ce470677b19ad2767b0b6c", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n/**\n * http://codeforces.com/contest/681/problem/B\n */\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tnew B().doJob();\n\t}\n\n\tprivate void doJob() {\n\t\ttry (Scanner scanner = new Scanner(System.in)) {\n\t\t\tint c1 = 1234567;\n\t\t\tint c2 = 123456;\n\t\t\tdouble c3 = 1234;\n\t\t\tint n = scanner.nextInt();\n\t\t\tfor (int a = 1; a <= (n - c2 - c3) / c1; a++) {\n\t\t\t\tfor (int b = 1; b <= (n - c1 * a - c3) / c2; b++) {\n\t\t\t\t\tif ((n - a * c1 - b * c2) % c3 == 0 && (n - a * c1 - b * c2) / c3 > 0) {\n\t\t\t\t\t\tSystem.out.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\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f1e81fb35ebcb47b4f93d91642f8af9a", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0} {"lang": "Java 7", "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 n1 = 1234567, n2 = 123456, n3 = 1234, lim = (int)10e9;\n int tmp1 = n, tmp2;\n \n if(n < n3){\n System.out.println(\"NO\");\n }else{\n for(int i=0; i<= lim; i+=n3){\n tmp1 = n - i;\n if(tmp1 < 0) break;\n for(int j=0; j<=lim; j+=n2){\n tmp2 = tmp1 - j;\n if(tmp2 < 0) break;\n for(int k=0; k <= lim; k +=n1){\n if(tmp2 - k == 0){\n System.out.println(\"YES\");\n return;\n }else if(tmp2 - k < 0)\n break;\n }\n }\n }\n System.out.println(\"NO\");\n }\n \n \n \n \n \n \n \n \n \n \n \n \n \n }\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n \n \n \n \n}\n\n \n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4236ecf6334e86dc01452f4f6159709", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.math.*;\npublic class Udhan272 {\n public static void main(String[] args) {\n Scanner scan=new Scanner(System.in);\n int n=scan.nextInt();\n // if(n<=1234567){\n // System.out.println(\"NO\");\n // }else{\n \n int a=n/1234567;\n boolean u=false;\n k:\n for(int x=a;x>=1;x--){\n int b=n-(x*1234567);\n int c=b/123456;\n for(int y=c;y>=1;y--){\n int d=b-(y*123456);\n int e=d/1234;\n for(int z=e;z>=1;z--){\n int f=d-(1234*z);\n if(f==0){\n u=true;\n break k;\n }\n }\n }\n }\n if(u==true){\n System.out.println(\"YES\");\n }else{\n System.out.println(\"NO\");\n }\n // }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6ab7dabe9b2cd3e6b3329d49a9a38175", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "package CF;\n\nimport java.util.Scanner;\n\npublic class BarktoUnlock {\n\t\n\tprivate static Scanner sc;\n\n\tpublic static void main(String[] args) {\n\t\n\t\tboolean f1 = false,f2 = false;\n\t\tString word;\n\t\t\n\t\tsc = new Scanner(System.in);\n\t\t\n\t\tString pass = sc.nextLine();\n\t\tchar ch1 = pass.charAt(0);\n\t\tchar ch2 = pass.charAt(1);\n\n\t\tint n = sc.nextInt();\n\t\t\n\t\tsc.nextLine();\t\t\n\t\t\t\t\t\n\t\tfor(int i=0;i 0){\n\t\t\tn--;\n\t\t\tString tmp = cin.nextLine();\n\t\t\tSystem.out.println(tmp);\n\t\t\tif(tmp.equals(password)){\n\t\t\t\tflag1 = true;\n\t\t\t\tflag2 = true;\n\t\t\t}\n\t\t\tif(tmp.charAt(0)==password.charAt(1)){\n\t\t\t\tflag1 = true;\n\t\t\t}\n\t\t\tif(tmp.charAt(1)==password.charAt(0)){\n\t\t\t\tflag2 = true;\n\t\t\t}\n\t\t}\n\t\tif(flag1==true&&flag2 == true){\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2df76e20a228174d33eefc6f12c127be", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "/*\nNotes:\n* Can't add scan.nextLine() as debug watch variable bc it has side-effects (execution changes environment)\n * https://stackoverflow.com/questions/37799474/every-time-i-step-over-in-debug-mode-java-scanner-read-till-next-delimiter\n* Bad idea to have scanner method (eg. scan.hasNextLine()) be a loop condition because it reads until there's an EOF\ncharacter which is very difficult to be input using a keyboard\n * https://stackoverflow.com/questions/10490344/how-to-get-out-of-while-loop-in-java-with-scanner-method-hasnext-as-condition\n * Solution is to have user specify the number of number they will enter input and use that number as the loop\n condition, or specify an exit string\n */\n\npackage cf_abarktounlock;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class cf_abarktounlock { \n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String pw = scan.nextLine();\n int n = scan.nextInt();\n scan.nextLine(); // eat the newline\n ArrayList zero = new ArrayList();\n ArrayList one = new ArrayList();\n ArrayList all = new ArrayList();\n for (int i = 0; i < n; i++) {\n String temp = scan.nextLine();\n zero.add(temp.charAt(0));\n one.add(temp.charAt(1));\n all.add(temp);\n }\n if (all.contains(pw)) {\n System.out.println(\"YES\");\n } else if (one.contains(pw.charAt(0)) && zero.contains(pw.charAt(1))) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24998b32fa3c43ad2d811e43bb476964", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class GFG {\n\tpublic static void main (String[] args) {\n\t\tint flag=0;\n\t\tScanner ss = new Scanner(System.in);\n\t\tString pass= ss.next();\n\t int n= ss.nextInt();\n\t String s = new String();\n\t for(int i=0;i1){System.out.print(\"YES\");System.exit(0);}\n\t System.out.print(\"NO\");\n\t \n\t} \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f2fce58f3975bb21f5932b311fef8a78", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0} {"lang": "Java 7", "source_code": "/**\n * Created by anjieliang on 2/5/16.\n */\n\nimport java.util.*;\n\npublic class Lyrics {\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int t = scan.nextInt();\n\n for (int a = 0; a < t; a++) {\n int x = scan.nextInt();\n int y = scan.nextInt();\n int l = scan.nextInt();\n scan.nextLine();\n HashMap words = new HashMap();\n for (int i = 0; i < l; i++) {\n String line = scan.nextLine();\n String[] lineWords = line.split(\" \");\n for (int j = 0; j < lineWords.length; j++) {\n String s = lineWords[j];\n s = s.toLowerCase();\n s = s.replaceAll(\"[^a-z]\", \"\");\n if (s.length() > 0) {\n if (words.get(s) != null) {\n int count = words.get(s);\n count++;\n words.put(s, count);\n } else {\n words.put(s, 1);\n }\n }\n }\n }\n int xCount = 0;\n for (String s : words.keySet()) {\n if (words.get(s) >= y) {\n xCount++;\n }\n }\n\n if (xCount >= x) {\n System.out.println(\"WRITE\");\n }\n else {\n System.out.println(\"LET IT GO\");\n }\n }\n\n scan.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8cee62c35396c9527c50087e08cbda9a", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package com.company;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n String ch[] = new String [10];\n for(int i = 0;i < 8;i++)\n ch[i] = s.nextLine();\n int c[] = new int[10];\n int l[] = new int[10];\n for(int i = 0;i < 8;i++) {\n c[i] = l[i] = 0;\n }\n for(int i = 0;i < 8;i++)\n for(int j = 0;j < 8;j++)\n if(ch[i].charAt(j) == 'B') {\n c[i]++;\n l[j]++;\n }\n int Ans = 0;\n for(int i = 0;i < 8;i++) {\n if(c[i] == 8) Ans++;\n if(l[i] == 8) Ans++;\n }\n if(Ans == 16) Ans = 8;\n System.out.println(Ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bfa4ff7ec40c8b01b172949c4ff89ec2", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n\tpublic static PrintWriter w = new PrintWriter(System.out);\n\tpublic static int[][] arr1 = new int[8001][8001];\n\tpublic static void main(String args[] ) throws Exception {\n\t\tReader in = new Reader();\n\t\tchar[][] arr = new char[8][8];\n\t\tfor (int i=0; i<8; i++)\n\t\t\tarr[i] = in.next().toCharArray();\n\t\tint cnt = 0;\n\t\tfor (int i=0; i<8; i++) {\n\t\t\tif(\"BBBBBBBB\".equals(new String(arr[i]))) {\n\t\t\t\tcnt++;\n\t\t\t\tArrays.fill(arr[i],'W');\n\t\t\t}\n\t\t}\n\t\tfor (int i=0; i<8; i++) {\n\t\t\tfor (int j=0; j<8; j++) {\n\t\t\t\tif(arr[j][i] == 'B') {\n\t\t\t\t\tcnt++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tw.println(cnt);\n\t\tw.flush();\n\t\treturn;\n\t}\n}\n\nclass Reader {\n\tfinal private int BUFFER_SIZE = 1 << 16;\n\tprivate DataInputStream din;\n\tprivate byte[] buffer;\n\tprivate int bufferPointer, bytesRead;\n\n\tpublic Reader() {\n\t\tdin = new DataInputStream(System.in);\n\t\tbuffer = new byte[BUFFER_SIZE];\n\t\tbufferPointer = bytesRead = 0;\n\t}\n\tpublic String nextLine() throws IOException {\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\tpublic String next() throws IOException {\n\t\tint c = read();\n\t\twhile(isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while(!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\tpublic int nextInt() throws IOException {\n\t\tint ret = 0;\n\t\tbyte c = read();\n\t\twhile(c <= ' ')\n\t\t\tc = read();\n\t\tboolean neg = (c == '-');\n\t\tif(neg)\n\t\t\tc = read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t} while((c = read()) >= '0' && c <= '9');\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\tpublic int[] nextIntArray(int n) throws IOException {\n\t\tint a[] = new int[n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\ta[i] = nextInt();\n\t\treturn a;\n\t}\n\tpublic int[][] next2dIntArray(int n, int m) throws IOException {\n\t\tint a[][] = new int[n][m];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tfor(int j = 0; j < m; j++)\n\t\t\t\ta[i][j] = nextInt();\n\t\treturn a;\n\t}\n\tpublic char nextChar() throws IOException {\n\t\treturn next().charAt(0);\n\t}\n\tpublic long nextLong() throws IOException {\n\t\tlong ret = 0;\n\t\tbyte c = read();\n\t\twhile(c <= ' ')\n\t\t\tc = read();\n\t\tboolean neg = (c == '-');\n\t\tif(neg)\n\t\t\tc = read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t} while((c = read()) >= '0' && c <= '9');\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\tpublic double nextDouble() throws IOException {\n\t\tdouble ret = 0, div = 1;\n\t\tbyte c = read();\n\t\twhile(c <= ' ')\n\t\t\tc = read();\n\t\tboolean neg = (c == '-');\n\t\tif(neg)\n\t\t\tc = read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t} while((c = read()) >= '0' && c <= '9');\n\t\tif (c == '.') {\n\t\t\twhile((c = read()) >= '0' && c <= '9') {\n\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t}\n\t\t}\n\t\tif(neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\tprivate void fillBuffer() throws IOException {\n\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\tif(bytesRead == -1)\n\t\t\tbuffer[0] = -1;\n\t}\n\tprivate byte read() throws IOException {\n\t\tif(bufferPointer == bytesRead)\n\t\t\tfillBuffer();\n\t\treturn buffer[bufferPointer++];\n\t}\n\tpublic void close() throws IOException {\n\t\tif(din == null)\n\t\t\treturn;\n\t\tdin.close();\n\t}\n\tpublic boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tprivate boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d20a8a9fe8ff1532b41785d6af7a2a96", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "// http://codeforces.com/problemset/problem/7/A\nimport java.util.*;\n\npublic class Chess {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint[][] painted = new int[8][8];\n\t\tint[][] board = new int[8][8];\n\n\t\tfor (int r = 0; r < 8; r++) {\n\t\t\tString row = in.nextLine();\n\t\t\tfor (int c = 0; c < 8; c++) {\n\t\t\t\tpainted[r][c] = (row.charAt(c) == 'B') ? 1 : 0;\n\t\t\t}\n\t\t}\n\n\t\tint min = paintBoard(painted, board, 0);\n\t\tSystem.out.println(min);\n\n\t}\n\n\tpublic static void printPainted(int[][] painted) {\n\t\tfor (int r = 0; r < 8; r++) {\n\t\t\tfor (int c = 0; c < 8; c++) {\n\t\t\t\tif (painted[r][c] == 1) {\n\t\t\t\t\tSystem.out.print('B');\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.print('W');\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\n\tpublic static int paintBoard(int[][] painted, int[][] board, int num) {\n\t\tint min = 64;\n\t\tboolean matches = true;\n\t\tboolean invalid = false;\n\t\tfor (int r = 0; r < 8; r++) {\n\t\t\tif (!invalid) {\n\t\t\t\tfor (int c = 0; c < 8; c++) {\n\t\t\t\t\tif (board[r][c] == 1 && painted[r][c] == 0) {\n\t\t\t\t\t\tinvalid = true;\n\t\t\t\t\t\tmatches = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (painted[r][c] == 1 && board[r][c] == 0) {\n\t\t\t\t\t\t\tmatches = false;\n\t\t\t\t\t\t\tif (checkRow(painted, r) && !checkRow(board, r)) {\n\t\t\t\t\t\t\t\tint[][] copy = copy(board);\n\t\t\t\t\t\t\t\tchangeRow(copy, r);\n\t\t\t\t\t\t\t\tmin = Math.min(min, paintBoard(painted, copy, num+1));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (checkColumn(painted, c) && !checkColumn(board, c)) {\n\t\t\t\t\t\t\t\tint[][] copy = copy(board);\n\t\t\t\t\t\t\t\tchangeColumn(copy, c);\n\t\t\t\t\t\t\t\tmin = Math.min(min, paintBoard(painted, copy, num+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} else {\n\t\t\t\t// printPainted(board);\n\t\t\t\treturn 64;\n\t\t\t}\n\t\t}\n\n\t\tif (matches) {\n\t\t\treturn num;\n\t\t} else {\n\t\t\treturn min;\n\t\t}\n\t}\n\n\tpublic static boolean checkRow(int[][] b, int r) {\n\t\tfor (int c = 0; c < 8; c++) {\n\t\t\tif (b[r][c] == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static boolean checkColumn(int[][] b, int c) {\n\t\tfor (int r = 0; r < 8; r++) {\n\t\t\tif (b[r][c] == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static void changeRow(int[][] b, int r) {\n\t\tfor (int c = 0; c < 8; c++) {\n\t\t\tb[r][c] = 1;\n\t\t}\n\t}\n\n\tpublic static void changeColumn(int[][] b, int c) {\n\t\tfor (int r = 0; r < 8; r++) {\n\t\t\tb[r][c] = 1;\n\t\t}\n\t}\n\n\tpublic static int[][] copy(int[][] board) {\n\t\tint[][] copy = new int[8][8];\n\n\t\tfor (int r = 0; r < 8; r++) {\n\t\t\tfor (int c = 0; c < 8; c++) {\n\t\t\t\tcopy[r][c] = board[r][c];\n\t\t\t}\n\t\t}\n\n\t\treturn copy;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b8f1ab8623beb7c09f1986339af06998", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0} {"lang": "Java 8", "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.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tInputReader reader = new InputReader(System.in);\n\t\tlong n = reader.nextLong();\n\t\tlong m = reader.nextLong();\n\t\tint a = reader.nextInt();\n\t\tint b = reader.nextInt();\n\t\tif (n % m == 0) {\n\t\t\tSystem.out.println(0);\n\t\t} else {\n\t\t\tlong numBuid = 0;\n\t\t\tlong numDemon = 0;\n\t\t\tif (n > m) {\n\n\t\t\t\tnumBuid = (m * 2 - n) * a;\n\t\t\t\tnumDemon = (n - m) * b;\n\n\t\t\t}\n\t\t\tif (n < m) {\n\t\t\t\tnumDemon = n * b;\n\n\t\t\t\tnumBuid = (m - n) * a;\n\n\t\t\t}\n\n\t\t\tif (numBuid > numDemon) {\n\t\t\t\tSystem.out.println(numDemon);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(numBuid);\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tstatic class InputReader {\n\t\tStringTokenizer tokenizer;\n\t\tBufferedReader reader;\n\t\tString token;\n\t\tString temp;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\ttokenizer = null;\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic InputReader(FileInputStream stream) {\n\t\t\ttokenizer = null;\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn reader.readLine();\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\tif (temp != null) {\n\t\t\t\t\t\ttokenizer = new StringTokenizer(temp);\n\t\t\t\t\t\ttemp = null;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t\t}\n\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\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\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6f67cc06c015c030d40bde8f30bb9458", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class Maze {\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\tlong m=s.nextLong();\n\t\tint a=s.nextInt();\n\t\tint b=s.nextInt();\n\t\tif(n%m==0){\n\t\t\tSystem.out.println(\"0\");\n\t\t}\n\t\telse{\n\t\t\tdouble res=(double)((n))/((m));\n\t\t\tint upper=(int)Math.ceil(res);\n\t\t\tlong max=upper*m-n;\n\t\t\tlong cost1=max*a;\n\t\t\tint lower=(int)Math.floor(res);\n\t\t\tlong mina=n-lower*m;\n\t\t\tlong cost2=mina*b;\n\t\t\tSystem.out.println(Math.min(cost2, cost1));\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d73c76795fc4e5be73438997b603d994", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n public class Hellojava\n{\n\npublic static void main(String []args)\n{\nScanner sc=new Scanner(System.in);\nlong n,m,a,b;\nint x=0;\nn=sc.nextLong();\nm=sc.nextLong();\na=sc.nextLong();\nb=sc.nextLong();\n\nif(m>n)\n x=2;\nelse{\nif((n>m) && (n%m==0))\n x=3;\nelse\nif((n>m) && (n%m!=0))\n x=1;\n}\t\nswitch (x){\ncase 1:\nlong c=(n-m)*b;\nlong d=(2*m-n)*a;\nif(cm){ss=(n-m)*b;while(n>m){m+=i;}sp=(m-n)*a;if(sp<=ss){System.out.println(sp);}else{System.out.println(ss);}}\n else if(n a) {\n\t\t\t\tcnt = n / a;\n\t\t\t} else {\n\t\t\t\twhile (n >= b) {\n\t\t\t\t\tcnt += n / b;\n\t\t\t\t\tn = n % b + (n / b) * c;\n\t\t\t\t}\n\t\t\t\tcnt += n / a;\n\t\t\t}\n\t\t\tSystem.out.println(cnt);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6c6613c663ca2f937c1ec17b62561a0d", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n/**\n *\n * @author Sourav Kumar Paul\n */\npublic class SolveA {\n public static void main(String[] args) throws IOException{\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n long n = Long.parseLong(reader.readLine());\n long p = Long.parseLong(reader.readLine());\n long g = Long.parseLong(reader.readLine());\n long e = Long.parseLong(reader.readLine());\n long sum = 0;\n if(p>=g)\n {\n long x = n/g;\n long rem = n%g;\n sum+=x;\n long ret = e*x+rem;\n while(ret >=g)\n {\n x = ret/g;\n if(x==0)\n break;\n rem = ret%g;\n sum+=x;\n ret = e*x+rem;\n }\n System.out.println(sum);\n \n }\n else\n {\n long temp = n/p;\n long x = n/g;\n long rem = n%g;\n sum+=x;\n long ret = e*x+rem;\n \n while(ret >=g)\n {\n x = ret/g;\n if(x==0)\n break;\n rem = ret%g;\n sum+=x;\n ret = e*x+rem;\n }\n if(ret >= p)\n sum+= ret/p;\n sum = Math.max(sum, temp);\n System.out.println(sum);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4413fbacd4d23845fc82c026c3ca4e70", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\n//package cf;\n\n\nimport java.io.*;\nimport java.util.*;\n\npublic class A {\n\n public static void main(String[] args) {\n AIO io = new AIO();\n try {\n Asolver solver = new Asolver(io);\n } finally {\n io.close();\n }\n }\n\n}\n\nclass Asolver {\n\n public Asolver(AIO io) {\n long n = io.nextLong();\n long a = io.nextLong();\n long b = io.nextLong();\n long c = io.nextLong();\n long toka = 0;\n if (b == n) toka = 1;\n if (b < n) {\n toka = (n-b);\n toka /= (b-c);\n long remainder = n - toka*(b-c);\n \n long option1 = (remainder / a);\n long option2 = 0;\n while (remainder >= b) {\n option2++;\n remainder -= (b);\n remainder += (c);\n }\n while (remainder >= a) {\n option2++;\n remainder -= a;\n }\n \n toka += Math.max(option1, option2);\n }\n\n System.out.println(Math.max(n/a, toka));\n }\n \n}\n\nclass AIO 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 AIO() {\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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "237875830589169f537d8e78ac6c5dbd", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class CF22 {\n\n static BufferedReader br;\n public static void main(String[]args){\n br=new BufferedReader(new InputStreamReader(System.in));\n try{\n \tlong n=readLong();\n \tlong a=readLong();\n \tlong b=readLong();\n \tlong c=readLong();\n \tlong max=n/a;\n \n \tlong num=0;\n \twhile(n>=b){\n \t\tlong div=n/b;\n \t\tnum+=div;\n \t\tn-=div*b;\n \t\tn+=c*div;\n \t\t\n \t\t//System.out.println(n+\" \"+div);\n \t\t\n \t\t\n \t}\n \tif(n>=a){\n \t\tnum+=n/a;\n \t}\n \t\n \tSystem.out.println(Math.max(num, max));\n br.close();\n }catch(IOException e){\n e.printStackTrace();\n }\n }\n \n static public String readString() throws IOException{\n return br.readLine();\n \n }\n static public long readLong() throws IOException{\n return Long.parseLong(br.readLine());\n }\n \n static public int readInt() throws IOException{\n return Integer.parseInt(br.readLine());\n }\n \n static public int[] readIntArr() throws IOException{\n String[]str=br.readLine().split(\" \");\n int arr[]=new int[str.length];\n for(int i=0;i=h*(h+1)/2){\n h=+3;\n result++;\n }\n System.out.println(result);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4e6bbbae2e1a92cec2464174d799499", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Alex\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n public void solve(int testNumber, InputReader in, OutputWriter out){\n\t long n = in.readLong();\n\t int res = 0;\n\t for(long floor = 1; floor < 50000000; floor++) {\n\t\t long total = floor + n;\n\t\t if(total % 3 == 0){\n\t\t\t long val = total / 3;\n\t\t\t long minval = floor * (floor + 1) / 2;\n\t\t\t if (val >= minval) res++;\n\t\t }\n\t }\n\t out.print(res);\n }\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\tpublic void print(int i) {\n\t\twriter.print(i);\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "34a4ca375f5651ca174edd582f520f70", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.concurrent.*;\n\npublic final class muh_cards\n{\n static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic FastScanner sc=new FastScanner(br);\n static PrintWriter out=new PrintWriter(System.out);\n\tstatic Random rnd=new Random();\n\t\n public static void main(String args[]) throws Exception\n {\n\t\tlong n=sc.nextLong(),res=0;\n\t\t\n\t\tfor(long i=1;;i++)\n\t\t{\n\t\t\tlong curr=3*i;\n\t\t\t\n\t\t\tif(curr=check)\n\t\t\t{\t\n\t\t\t\tres++;\n\t\t\t}\n\t\t\t\n\t\t\telse\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(res);out.close();\n }\n}\nclass FastScanner\n{\n BufferedReader in;\n StringTokenizer st;\n\n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n\t\n public String nextToken() throws Exception {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\t\n\tpublic String next() throws Exception {\n\t\treturn nextToken().toString();\n\t}\n\t\n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n\n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "966f1a50ac9b5c994537846c89184269", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.awt.List;\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.Vector;\n \n \npublic class Main {\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\t \tFastScanner sc = new FastScanner();\n\t\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\tlong n=sc.nextLong();\n\t\t\tint ans =0;\n\t\t\tfor(int i=1;i*i<=n;i++){\n\t\t\t\tif((n+i)%3==0)\n\t\t\t\t\tans++;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\n\t\t\t\n\t\t\t\n\t\t\t\t\t\t\n\t\t\t\n\n\t\n\t\n\n\t\t\n\t\t\n\t\t\n\n\n\n\n\t\n\t\n\t\n\t\n\t\n\tstatic void generate(int[] p, int L, int R) {\n\t\t if (L == R) {\n\t\t\t \n\t\t \n\t\t }else { // numbers at positions [0, L-1] are set, try to set L-th position\n\t\t for (int i = L; i <= R; i++) {\n\t\t \tint tmp = p[L]; p[L] = p[i]; p[i] = tmp;\n\t\t generate(p, L+1, R);\n\t\t tmp = p[L]; p[L] = p[i]; p[i] = tmp;\n\n\t\t }\n\t\t }\n\t\t}\n\t\n}\n\t\t \n\n\n\t\n\t\n\t\n\t\n\n\n\n\n\n\n\n\n\n\n\n\t\n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \nclass FastScanner {\n \n \n \n \n BufferedReader br;\n StringTokenizer st;\n \n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n \n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n \n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n \n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9adcf88dccfb205f4273591eda368388", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n \n static StringTokenizer st;\n static BufferedReader in;\n static PrintWriter pw;\n \n public static void main(String[] args) throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n BigInteger x = BigInteger.valueOf(nextLong());\n BigInteger y = BigInteger.valueOf(nextLong());\n BigInteger m = BigInteger.valueOf(nextLong());\n int ans = 0;\n while (true) {\n if (ans > 500) {\n System.out.println(-1);\n return;\n }\n if (x .compareTo(m) >= 0 || y .compareTo(m) >= 0) {\n System.out.println(ans);\n return;\n }\n if (x.compareTo(y) < 0)\n x = x.add(y);\n else\n y = y.add(x);\n ans++;\n }\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d2017522826f045316297c8bac88c45f", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class C {\n\tpublic static void main(String[] args) {\n\t\tScanner myScanner = new Scanner(System.in);\n\t\tlong a = myScanner.nextLong(), b = myScanner.nextLong(), m = myScanner\n\t\t\t\t.nextLong();\n\n\t\tif (a >= m || b >= m)\n\t\t\tSystem.out.println(0);\n\t\telse {\n\t\t\tif (a + b <= a && a + b <= b)\n\t\t\t\tSystem.out.println(-1);\n\t\t\telse {\n\t\t\t\tint cnt = 0;\n\t\t\t\twhile (true) {\n\t\t\t\t\tcnt++;\n\t\t\t\t\tif (a < b)\n\t\t\t\t\t\ta = a + b;\n\t\t\t\t\telse\n\t\t\t\t\t\tb = a + b;\n\t\t\t\t\tif (a >= m || b >= m) {\n\t\t\t\t\t\tSystem.out.println(cnt);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "808de2042966c7c96e15d9a71499a0ac", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C188D2C {\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n long x = in.nextLong(), y = in.nextLong(), m = in.nextLong();\n if (x >= m || y >= m) {\n out.println(0);\n } else if (x <= 0 && y <= 0) {\n out.println(-1);\n } else {\n long res = 0;\n long[] f = new long[3];\n f[0] = Math.min(x, y);\n f[1] = Math.max(x, y);\n while (true) {\n res++;\n f[2] = f[0] + f[1];\n if (f[2] >= m) {\n break;\n }\n f[0] = Math.min(f[1], f[2]);\n f[1] = Math.max(f[1], f[2]);\n }\n out.println(res);\n }\n out.flush();\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dfe0ced8ac84bcc55296d42bd8b94ff7", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class RCCP {\n\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 PrintWriter out = new PrintWriter(outputStream);\n \n long x = Long.parseLong(in.next());\n long y = Long.parseLong(in.next());\n long m = Long.parseLong(in.next());\n \n if (x > y) {\n long temp = y;\n y = x;\n x = temp;\n }\n \n if (x < m && y < m && x <= 0 && y <= 0) {\n out.println(-1);\n } else {\n long res = 0;\n while(x < m && y < m) {\n long sum = x + y;\n res++;\n x = sum;\n \n if (x > y) {\n long temp = y;\n y = x;\n x = temp;\n }\n }\n \n out.println(res);\n }\n \n out.close();\n }\n}\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d60b55cde92ee6becb9b892e6d488497", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class DreamoonAndStairs {\npublic static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int m=sc.nextInt();\n int x=n;\n int a=n/2;\n int b=n%2;\n int d=0;\n if(n0)\n {\n for(int i=1;i=0;j--)\n {\n if(n==(2*j)+i)\n {\n if((i+j)%m==0)\n {\n d++;\n System.out.println(i+j);\n System.exit(0);\n }\n }\n }\n }\n }\n \n}}\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2ca3eb0c704611bf1f7310689d563cae", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.Optional;\nimport java.util.Scanner;\n\npublic class DreammoonAndStairs {\n\n\tpublic static int result = Integer.MAX_VALUE;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt(), m = s.nextInt();\n\t\tSystem.out.println(howManySteps(n, m));\n\t\ts.close();\n\t}\n\n\tprivate static int howManySteps(int n, int m) {\n\t\tcreateSubsequence(n, new ArrayList(), m);\n\t\tif(result==Integer.MAX_VALUE) {\n\t\t\treturn -1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate static void createSubsequence(int n, ArrayList arr, int m) {\n\t\tint val = sum(arr);\n\t\tif (val == n && arr.size() % m == 0) {\n\t\t\tresult = Math.min(arr.size(), result);\n\t\t\treturn;\n\t\t} else if (val > n) {\n\t\t\treturn;\n\t\t} else {\n\t\t\tarr.add(1);\n\t\t\tcreateSubsequence(n, arr, m);\n\t\t\tarr.remove(arr.size() - 1);\n\t\t\tarr.add(2);\n\t\t\tcreateSubsequence(n, arr, m);\n\t\t\tarr.remove(arr.size() - 1);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tpublic static int sum(ArrayList arr) {\n\t\tint sum = 0;\n\t\tif (arr.size() == 1) {\n\t\t\treturn arr.get(0);\n\t\t} else if (arr.size() == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tfor (Iterator iterator = arr.iterator(); iterator.hasNext();) {\n\t\t\tInteger integer = (Integer) iterator.next();\n\t\t\tsum += integer;\n\t\t}\n\t\treturn sum;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "843dc643f2c9c96e2af55b3057089b2b", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class check {\n\n /**\n * @param args\n * @throws IOException \n */\n public static long Mod = 1000000007;\n public static boolean ok = true; \n public static int[][]dp = new int[10002][10002];\n public static int solve(int index , int sum){\n \n if (index < 0 || (index == 0 && sum % Mod != 0)) {\n return 100000000;\n }\n else if(index == 0){\n ok = false;\n return 0;\n }\n if(dp[index][sum] != -1){\n return dp[index][sum];\n }\n int res = Math.min(solve(index-1, sum+1)+1, solve(index-2, sum+1)+1);\n \n return dp[index][sum] = res;\n }\n \n \n public static void main(String[] args) throws IOException {\n // TODO Auto-generated method stub\n \n BufferedReader k=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer str=new StringTokenizer(k.readLine());\n int steps = Integer.parseInt(str.nextToken());\n Mod = Integer.parseInt(str.nextToken());\n for (int i = 0; i < dp.length; i++) {\n Arrays.fill(dp[i], -1);\n }\n int res = solve(steps, 0);\n if(!ok)\n System.out.println(res);\n \n else{\n System.out.println(-1);\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a1175481de99fefcd7290113702d764", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class check {\n\n /**\n * @param args\n * @throws IOException \n */\n public static int Mod = 1000000007;\n public static boolean ok = true; \n public static int[][]dp = new int[10002][10002];\n public static int solve(int index , int sum){\n \n if (index < 0 || (index == 0 && sum % Mod != 0)) {\n return 100000000;\n }\n else if(index == 0){\n ok = false;\n return 0;\n }\n if(dp[index][sum] != -1){\n return dp[index][sum];\n }\n int res = Math.min(solve(index-1, sum+1)+1, solve(index-2, sum+1)+1);\n \n return dp[index][sum] = res;\n }\n \n \n public static void main(String[] args) throws IOException {\n // TODO Auto-generated method stub\n \n BufferedReader k=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer str=new StringTokenizer(k.readLine());\n int steps = Integer.parseInt(str.nextToken());\n Mod = Integer.parseInt(str.nextToken());\n int twos = steps / 2;\n int have = steps / 2 + steps % 2;\n int remain = have % Mod;\n if (remain > twos) {\n \n System.out.println(-1);\n \n \n }\n else System.out.println(have+remain);\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d409e3ea7f6f11c5a6c807d911f0d451", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class codeforces\n{\n public static void main(String args[]) throws IOException\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String s=br.readLine();\n codeforces o=new codeforces();\n String[] t=s.split(\" \");\n int n=Integer.parseInt(t[0]);\n int m=Integer.parseInt(t[1]);\n if(n==2 && m==3)\n System.out.println(\"YES\");\n else\n {\n for(int i=n+2;;i+=2)\n {\n if(o.isPrime(i))\n {\n if(i==m)\n {\n System.out.println(\"YES\");\n break;\n }\n else\n {\n System.out.println(\"NO\");\n break;\n }\n }\n }\n }\n }\n boolean isPrime(int num)\n {\n if(num%2==0&&num!=2)return false;\n if(num==2)return true;\n for(int i=3;i*i<=num;i+=2)\n {\n if(num%i==0)\n return false;\n }\n return true;\n }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "540ec869e6a7aff574be573a67c948da", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tfor (int i = n + 1;; i++) {\n\t\t\tif (isprime(i)) {\n\t\t\t\tout.println(i == m ? \"YES\" : \"NO\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate boolean isprime(int n) {\n\t\tfor (int i = 2; i < n; i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tMain() throws IOException {\n\t\tLocale.setDefault(Locale.ENGLISH);\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\teat(\"\");\n\t\tsolve();\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tprivate void eat(String str) {\n\t\tst = new StringTokenizer(str);\n\t}\n\n\tString next() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\teat(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e48a4210037562f29e7ecc654368724", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\n\npublic class Main{\n static int[] primes={2,3,5,7,11,13,17,19,23,31,37,41,43,47};\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int n,m;\n n = in.nextInt();\n m = in.nextInt();\n int i;\n for( i=0;i 800)\n\t\t\treturn (int) 1e9;\n\t\tif (dp[i + 1][j + 1][cnt] != -1)\n\t\t\treturn dp[i + 1][j + 1][cnt];\n\t\tif (cnt > 0) {\n\t\t\tchar c = '(';\n\t\t\tint nxti = i == -1 ? -1 : c == a[i] ? i - 1 : i;\n\t\t\tint nxtj = j == -1 ? -1 : c == b[j] ? j - 1 : j;\n\t\t\tnxti = Math.max(nxti, -1);\n\t\t\tnxtj = Math.max(nxtj, -1);\n\t\t\tans = Math.min(ans, 1 + dp(nxti, nxtj, cnt - 1));\n\t\t}\n\t\tif (i != -1 || j != -1) {\n\t\t\tchar c = ')';\n\t\t\tint nxti = i == -1 ? -1 : c == a[i] ? i - 1 : i;\n\t\t\tint nxtj = j == -1 ? -1 : c == b[j] ? j - 1 : j;\n\t\t\tans = Math.min(ans, 1 + dp(nxti, nxtj, cnt + 1));\n\t\t}\n\t\treturn dp[i + 1][j + 1][cnt] = ans;\n\t}\n\n\tstatic Stack st;\n\n\tpublic static void trace(int i, int j, int cnt) {\n//\t\tSystem.out.println(i+\" \"+j+\" \"+cnt);\n\t\tif (i == -1 && j == -1 && cnt == 0)\n\t\t\treturn;\n\t\tboolean bb = false;\n\t\tif (cnt > 0) {\n\t\t\tchar c = '(';\n\t\t\tint nxti = i == -1 ? -1 : c == a[i] ? i - 1 : i;\n\t\t\tint nxtj = j == -1 ? -1 : c == b[j] ? j - 1 : j;\n\n\t\t\tif (dp(i, j, cnt) == 1 + dp(nxti, nxtj, cnt - 1)) {\n\t\t\t\tst.add(c);\n\t\t\t\tbb = true;\n\t\t\t\ttrace(nxti, nxtj, cnt - 1);\n\t\t\t}\n\t\t}\n\t\tif (!bb) {\n\t\t\tchar c = ')';\n\t\t\tint nxti = i == -1 ? -1 : c == a[i] ? i - 1 : i;\n\t\t\tint nxtj = j == -1 ? -1 : c == b[j] ? j - 1 : j;\n\t\t\tif (dp(i, j, cnt) == 1 + dp(nxti, nxtj, cnt + 1)) {\n\t\t\t\tst.add(c);\n\t\t\t\ttrace(nxti, nxtj, cnt + 1);\n\t\t\t}\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\ta = sc.next().toCharArray();\n\t\tb = sc.next().toCharArray();\n\t\tdp = new int[a.length + 1][b.length + 1][1000];\n\t\tfor (int[][] x : dp) {\n\t\t\tfor (int[] y : x)\n\t\t\t\tArrays.fill(y, -1);\n\t\t}\n\t\tst = new Stack();\n//\t\tpw.println(dp(a.length - 1, b.length - 1, 0));\n\t\ttrace(a.length - 1, b.length - 1, 0);\n\n\t\twhile (!st.isEmpty()) {\n\t\t\tpw.print(st.pop());\n\t\t}\n\t\tpw.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(FileReader r) {\n\t\t\tbr = new BufferedReader(r);\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif (x.charAt(0) == '-') {\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor (int i = start; i < x.length(); i++)\n\t\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t} else {\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bfd7885037e0dbd33e5a4be73a25b90c", "src_uid": "cc222aab45b3ad3d0e71227592c883f1", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n FTwoBracketSequences solver = new FTwoBracketSequences();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FTwoBracketSequences {\n static char[] first;\n static char[] second;\n static Integer[][][] memo;\n static StringBuilder s = new StringBuilder();\n\n public static int dp(int i, int j, int k) {\n if (i == first.length && second.length == j)\n return k;\n if (memo[i][j][k] != null)\n return memo[i][j][k];\n if (k == 0) {\n int ans;\n if (first.length > i && j < second.length && first[i] == '(' & second[j] == '(')\n ans = 1 + dp(i + 1, j + 1, 1);\n else if (i < first.length && first[i] == '(')\n ans = 1 + dp(i + 1, j, 1);\n else if (j < second.length && second[j] == '(')\n ans = 1 + dp(i, j + 1, 1);\n else\n ans = 1 + dp(i, j, 1);\n return memo[i][j][k] = ans;\n } else {\n if (i < first.length && j < second.length && first[i] == second[j]) {\n int open = first[i] == '(' ? 1 + dp(i + 1, j + 1, k + 1) : 1 + dp(i + 1, j + 1, k - 1);\n return memo[i][j][k] = open;\n } else {\n int takeFirst = (int) 1e9, takeSecond = (int) 1e9;\n if (i < first.length)\n takeFirst = first[i] == '(' ? 1 + dp(i + 1, j, k + 1) : 1 + dp(i + 1, j, k - 1);\n if (j < second.length)\n takeSecond = second[j] == '(' ? 1 + dp(i, j + 1, k + 1) : 1 + dp(i, j + 1, k - 1);\n return memo[i][j][k] = Math.min(takeFirst, takeSecond);\n }\n }\n }\n\n public static void trace(int i, int j, int k) {\n if (i == first.length && second.length == j) {\n while (k-- > 0)\n s.append(')');\n return;\n }\n if (k == 0) {\n s.append('(');\n if (first.length > i && j < second.length && first[i] == '(' & second[j] == '(') {\n trace(i + 1, j + 1, 1);\n return;\n } else if (i < first.length && first[i] == '(') {\n trace(i + 1, j, 1);\n return;\n } else if (j < second.length && second[j] == '(')\n trace(i, j + 1, 1);\n else\n trace(i, j, 1);\n } else {\n int cur = dp(i, j, k);\n if (i < first.length && j < second.length && first[i] == second[j]) {\n if (first[i] == '(') {\n s.append('(');\n trace(i + 1, j + 1, k + 1);\n return;\n } else {\n s.append(')');\n trace(i + 1, j + 1, k - 1);\n return;\n }\n } else {\n int takeFirst = (int) 1e9, takeSecond = (int) 1e9;\n if (i < first.length)\n takeFirst = first[i] == '(' ? 1 + dp(i + 1, j, k + 1) : 1 + dp(i + 1, j, k - 1);\n if (j < second.length)\n takeSecond = second[j] == '(' ? 1 + dp(i, j + 1, k + 1) : 1 + dp(i, j + 1, k - 1);\n if (cur == takeFirst) {\n if (first[i] == '(') {\n s.append('(');\n trace(i + 1, j, k + 1);\n return;\n } else {\n s.append(')');\n trace(i + 1, j, k - 1);\n return;\n }\n } else {\n if (second[j] == '(') {\n s.append('(');\n trace(i, j + 1, k + 1);\n return;\n } else {\n s.append(')');\n trace(i, j + 1, k - 1);\n return;\n }\n }\n }\n }\n }\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n s = new StringBuilder();\n first = sc.next().toCharArray();\n second = sc.next().toCharArray();\n memo = new Integer[200][200][200];\n trace(0, 0, 0);\n pw.println(s.toString());\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "68a10364425d74a5cfbbb0ee43481c0e", "src_uid": "cc222aab45b3ad3d0e71227592c883f1", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main {\n static class pair implements Comparable{\n int x;\n int y;\n public pair(int x, int y){\n this.x=x;\n this.y=y;\n }\n public int compareTo(pair p){\n return (x-p.x==0)?y-p.y:x-p.x;\n }}\n static char[] a,b;\n static int [][][]dp;\n static StringBuilder str;\n public static int solve( int i, int j , int need){\n if(i==a.length&&j==b.length) return dp[i][j][need]= need;\n if(need>=500) return (int) 1e9;\n if(dp[i][j][need]!=-1) return dp[i][j][need];\n int take = 1+solve((i==a.length)?i:(a[i]=='(')?Math.min(i+1,a.length):i,(j==b.length)?j:(b[j]=='(')?Math.min(j+1,b.length):j,need +1);\n int leave =(need>0)? 1+solve((i==a.length)?i:(a[i]==')')?Math.min(i+1,a.length):i,(j==b.length)?j:(b[j]==')')?Math.min(j+1,b.length):j,need -1):Integer.MAX_VALUE;\n return dp[i][j][need] = Math.min(take,leave);\n }\n public static void trace( int i, int j , int need){\n if(i==a.length&&j==b.length){while(need-->0) str.append(\")\"); return;}\n // int req = solve(i,j,need);\n if( 1+dp[(i==a.length)?i:(a[i]=='(')?Math.min(i+1,a.length):i][(j==b.length)?j:(b[j]=='(')?Math.min(j+1,b.length):j][need +1]==dp[i][j][need]){\n str.append(\"(\");\n trace((i==a.length)?i:(a[i]=='(')?Math.min(i+1,a.length):i,(j==b.length)?j:(b[j]=='(')?Math.min(j+1,b.length):j,need +1);\n return;\n }else{\n str.append(\")\"); \n trace((i==a.length)?i:(a[i]==')')?Math.min(i+1,a.length):i,(j==b.length)?j:(b[j]==')')?Math.min(j+1,b.length):j,need -1);}\n }\n public static void main(String[] args) throws IOException,InterruptedException{\n\tBufferedReader\t br = new BufferedReader(new InputStreamReader(System.in));\n\tPrintWriter out = new PrintWriter(System.out);\n \t// String s = br.readLine();\n // char[] arr=s.toCharArray();\n // ArrayList arrl = new ArrayList(); \n // TreeSet ts1 = new TreeSet(); \n // HashSet h = new HashSet(); \n // HashMap map= new HashMap<>(); \n // PriorityQueue pQueue = new PriorityQueue(); \n // LinkedList object = new LinkedList(); \n // StringBuilder str = new StringBuilder(); \n \t // StringTokenizer st = new StringTokenizer(br.readLine());\n \t // \t n = Integer.parseInt(st.nextToken());\n \t String s = br.readLine();\n \t a = s.toCharArray(); \n \t String t = br.readLine();\n \t b = t.toCharArray();\n \t \tdp = new int[201][201][500];\n \t \tfor(int i=0; i<201; i++) \t \n \t \tfor(int j=0; j<201; j++) \t \n \t \t Arrays.fill(dp[i][j],-1);\n \t int ans =solve(0,0,0);\n \t str = new StringBuilder(); \n \t trace(0,0,0);\n \t out.print(str);\n \t \t out.flush();\n\t}\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ab741b64600a961a5ab0c1845858dd1e", "src_uid": "cc222aab45b3ad3d0e71227592c883f1", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n FTwoBracketSequences solver = new FTwoBracketSequences();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FTwoBracketSequences {\n static char[] first;\n static char[] second;\n static Integer[][][] memo;\n static StringBuilder s = new StringBuilder();\n\n public static int dp(int i, int j, int k) {\n if (i == first.length && second.length == j)\n return k;\n if (memo[i][j][k] != null)\n return memo[i][j][k];\n if (k == 0) {\n int ans;\n if (first.length > i && j < second.length && first[i] == '(' & second[j] == '(')\n ans = 1 + dp(i + 1, j + 1, 1);\n else if (i < first.length && first[i] == '(')\n ans = 1 + dp(i + 1, j, 1);\n else if (j < second.length && second[j] == '(')\n ans = 1 + dp(i, j + 1, 1);\n else\n ans = 1 + dp(i, j, 1);\n return memo[i][j][k] = ans;\n } else {\n if (i < first.length && j < second.length && first[i] == second[j]) {\n int open = first[i] == '(' ? 1 + dp(i + 1, j + 1, k + 1) : 1 + dp(i + 1, j + 1, k - 1);\n return memo[i][j][k] = open;\n } else {\n int takeFirst = (int) 1e9, takeSecond = (int) 1e9;\n if (i < first.length)\n takeFirst = first[i] == '(' ? 1 + dp(i + 1, j, k + 1) : 1 + dp(i + 1, j, k - 1);\n if (j < second.length)\n takeSecond = second[j] == '(' ? 1 + dp(i, j + 1, k + 1) : 1 + dp(i, j + 1, k - 1);\n return memo[i][j][k] = Math.min(takeFirst, takeSecond);\n }\n }\n }\n\n public static void trace(int i, int j, int k) {\n if (i == first.length && second.length == j) {\n while (k-- > 0)\n s.append(')');\n return;\n }\n if (k == 0) {\n s.append('(');\n if (first.length > i && j < second.length && first[i] == '(' & second[j] == '(') {\n trace(i + 1, j + 1, 1);\n return;\n } else if (i < first.length && first[i] == '(') {\n trace(i + 1, j, 1);\n return;\n } else if (j < second.length && second[j] == '(')\n trace(i, j + 1, 1);\n else\n trace(i, j, 1);\n } else {\n int cur = dp(i, j, k);\n if (i < first.length && j < second.length && first[i] == second[j]) {\n if (first[i] == '(') {\n s.append('(');\n trace(i + 1, j + 1, k + 1);\n return;\n } else {\n s.append(')');\n trace(i + 1, j + 1, k - 1);\n return;\n }\n } else {\n int takeFirst = (int) 1e9, takeSecond = (int) 1e9;\n if (i < first.length)\n takeFirst = first[i] == '(' ? 1 + dp(i + 1, j, k + 1) : 1 + dp(i + 1, j, k - 1);\n if (j < second.length)\n takeSecond = second[j] == '(' ? 1 + dp(i, j + 1, k + 1) : 1 + dp(i, j + 1, k - 1);\n if (cur == takeFirst) {\n if (first[i] == '(') {\n s.append('(');\n trace(i + 1, j, k + 1);\n return;\n } else {\n s.append(')');\n trace(i + 1, j, k - 1);\n return;\n }\n } else {\n if (second[j] == '(') {\n s.append('(');\n trace(i, j + 1, k + 1);\n return;\n } else {\n s.append(')');\n trace(i, j + 1, k - 1);\n return;\n }\n }\n }\n }\n }\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n s = new StringBuilder();\n first = sc.next().toCharArray();\n second = sc.next().toCharArray();\n memo = new Integer[200][200][402];\n trace(0, 0, 0);\n pw.println(s.toString());\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48bb2da926055e7eb8835d0d7f50daee", "src_uid": "cc222aab45b3ad3d0e71227592c883f1", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class day2 {\n\tpublic static void main (String args[]){\n\t\tint x,y = 0;\n\t\tint z = 0;\n\t\t\n\t\tScanner a = new Scanner(System.in);\n\t\tScanner b = new Scanner(System.in);\n\t\t\n\t\tString c = a.nextLine();\n\t\tString d = b.next();\n\t\t\n\t\tc = c.toUpperCase();\n\t\td = d.toUpperCase();\n\t\t\n\t\tfor(x=0;xz)\n\t\t\tSystem.out.println(\"1\");\n\t\telse if(y==z)\n\t\t\tSystem.out.println(\"0\");\n\t\telse\n\t\t\tSystem.out.println(\"-1\");\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d47a26235ea6decf96a774d52b3878d", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0} {"lang": "Java 6", "source_code": "package contest85;\n\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tScanner in = new Scanner(\n//\t\t\t\tnew BufferedInputStream(new FileInputStream(\"a.in\"))\n\t\t\t\tSystem.in\n\t\t\t\t);\n\t\tString a = in.nextLine();\n\t\tString b = in.nextLine();\n\t\ta = a.toLowerCase();\n\t\tb = b.toLowerCase();\n\t\tfor(int i=0;i(s11[i].charAt(0)))\n\t\t\t{\n\t\t\t\tt=-1;\n\t\t\t\tb=false;\n\t\t\t}\n\t\t\telse if((s22[i].charAt(0))<(s11[i].charAt(0)))\n\t\t\t{\n\t\t\t\tt=1;\n\t\t\t\tb=false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tt=0;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.println(t);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "473431c7d2b35cce9ce8dd142446ade7", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class solutions {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tString a,b;\n\t\tScanner sc=new Scanner(System.in);\n\t\ta=sc.nextLine();\n\t\ta=a.toLowerCase();\n\t\tb=sc.nextLine();\n\t\tb=b.toLowerCase();\n\t\tint l=a.length();\n\t\tint i=0;\n\t\tfor(i=0;ib.charAt(i))\n\t\t\t{\n\t\t\t\tSystem.out.println(\"1\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(a.charAt(i)k)\n {\n int a1=0,a2=0;\n for( int i =0;ia2) System.out.print(+a2);\n else System.out.print(+a1);\n }\n else System.out.print(+(x));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7466757bad634044a1ea85c0d08159db", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\n\npublic class EsA {\n\t\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt();\n\t\tint[][] a = new int[k][k];\n\t\tint[] num1,num2;\n\t\tnum1 = new int[k];\n\t\tnum2 = new int[k];\n\t\tint counter = 0;\n\t\tfor(int i=0; i 0) b[j] = 2;\n\t\t\t\telse b[j] = 1;\n\t\t\t}\n\t\t\tint cnt = 0;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (b[j % k] != a[j]) cnt++;\n\t\t\t}\n\t\t\tif (cnt < ans) ans = cnt;\n\t\t}\n\t\tfile.out.println(ans);\n\t\tfile.out.flush();\n\t}\n\n\tpublic static class FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tPrintWriter out;\n\n\t\tpublic FastIO() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\n\t\tvoid print(Object o) {\n\t\t\tout.print(o);\n\t\t}\n\n\t\tvoid println(Object o) {\n\t\t\tout.println(o);\n\t\t}\n\n\t\tvoid printf(String s, Object... o) {\n\t\t\tout.printf(s, o);\n\t\t}\n\t}\n\n\tpublic static long pow(long n, long p, long mod) {\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n % mod;\n\t\tif (p % 2 == 0) {\n\t\t\tlong temp = pow(n, p / 2, mod);\n\t\t\treturn (temp * temp) % mod;\n\t\t} else {\n\t\t\tlong temp = pow(n, (p - 1) / 2, mod);\n\t\t\ttemp = (temp * temp) % mod;\n\t\t\treturn (temp * n) % mod;\n\n\t\t}\n\t}\n\n\tpublic static long pow(long n, long p) {\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\tif (p % 2 == 0) {\n\t\t\tlong temp = pow(n, p / 2);\n\t\t\treturn (temp * temp);\n\t\t} else {\n\t\t\tlong temp = pow(n, (p - 1) / 2);\n\t\t\ttemp = (temp * temp);\n\t\t\treturn (temp * n);\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long x, long y) {\n\t\tif (x == 0)\n\t\t\treturn y;\n\t\telse\n\t\t\treturn gcd(y % x, x);\n\t}\n\n\tpublic static boolean isPrime(int n) {\n\t\tif (n <= 1)\n\t\t\treturn false;\n\t\tif (n <= 3)\n\t\t\treturn true;\n\n\t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\treturn false;\n\n\t\tfor (int i = 5; i * i <= n; i = i + 6)\n\t\t\tif (n % i == 0 || n % (i + 2) == 0)\n\t\t\t\treturn false;\n\n\t\treturn true;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b439f616c40c8cb0f5a60311de336c54", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n \n int a[] = new int[110];\n \n //int b[] = new int[110];\n \n int n,k;\n \n int countChanges(int from) {\n int count = 0;\n int times = n/k;\n for (int i = 0; i < times; ++i) {\n for (int j = 0; j < k; ++j) {\n if (a[i*k+j]!=a[from+j]) {\n count++;\n }\n }\n }\n \n return count; \n }\n \n void solve() throws IOException {\n n = nextInt();\n k = nextInt();\n \n if (n==k) {\n out.print(\"0\");\n return;\n }\n \n int t = 0,d = 0;\n \n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n if (a[i] == 1) {\n t++;\n } else {\n d++;\n }\n }\n \n int times = n/k;\n \n int cnt = min(t,d);\n \n for (int i = 0; i < times; ++i) {\n cnt = min(cnt, countChanges(i*k));\n }\n \n out.print(cnt);\n \n }\n\n private int min(int cnt, int countChanges) {\n return (cnt < countChanges ? cnt : countChanges);\n }\n\n static BufferedReader in;\n static PrintWriter out;\n static StringTokenizer st;\n\n public Main() {\n };\n\n public void goMain() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n st = new StringTokenizer(\"\");\n solve();\n in.close();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n try {\n if (new File(\"input.txt\").exists()) {\n System.setIn(new FileInputStream(\"input.txt\"));\n }\n } catch (SecurityException e) {\n }\n ;\n Main m = new Main();\n m.goMain();\n }\n\n String nextToken() throws IOException {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n String nextString() throws IOException {\n st = new StringTokenizer(\"\");\n return in.readLine();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c9410ab40094237c8a9e974f2eb6732", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class cb {\n\tstatic class pair\n\t{\n\t\tint k,v;\n\t\tpair(int ke,int ve)\n\t\t{\n\t\t\tk=ke;\n\t\t\tv=ve;\n\t\t}\n\t}\n InputStream is;\n PrintWriter out; \n\t\n\tlong mod=(long)1e9+7;\n\t\n\t\n void solve()\n {\n\t\t\n\t\t\n\t\tint n=ni(),k=ni();\n\t\tint top[]=new int[n+1];\n\t\t\n\t\tint l[][]=new int[n+1][(int)Math.sqrt(n)+1];\n\t\n\t\t\n\t\tfor(int i=1;i= len) { ptr = 0; \n try { len = is.read(input); } \n catch(IOException e) { throw new InputMismatchException(); } \n if(len <= 0) { return -1; } \n } return input[ptr++];\n }\n boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n int skip() { \n int b = readByte(); \n while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n return b;\n }\n \n char nc() { return (char)skip(); }\n String ns() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n String nLine() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n int ni() { \n int n = 0, b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n if(b == -1) { return -1; } //no input \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n long nl() { \n long n = 0L; int b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n \n double nd() { return Double.parseDouble(ns()); }\n float nf() { return Float.parseFloat(ns()); }\n int[] na(int n) { \n int a[] = new int[n]; \n for(int i = 0; i < n; i++) { a[i] = ni(); } \n return a;\n }\n char[] ns(int n) { \n char c[] = new char[n]; \n int i, b = skip(); \n for(i = 0; i < n; i++) { \n if(isSpaceChar(b)) { break; } \n c[i] = (char)b; b = readByte(); \n } return i == n ? c : Arrays.copyOf(c,i);\n }\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f1a476860f7de9dff0d36ffa0521bdac", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class A\n{\n public static void main(String ar[]) throws Exception\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String s1[]=br.readLine().split(\" \");\n int n=Integer.parseInt(s1[0]);\n int k=Integer.parseInt(s1[1]);\n long dp[][]=new long[n+1][k+1];\n for(int i=1;i<=n;i++)\n dp[i][1]=1;\n ArrayList al[]=new ArrayList[n+1];\n for(int i=1;i<=n;i++)\n {\n al[i]=new ArrayList();\n for(int j=1;j<=(int)Math.sqrt(j);j++)\n {\n if(i%j==0)\n {\n al[i].add(j);\n if(j!=i/j)\n al[i].add(i/j);\n }\n }\n }\n \n long mod=1000000007;\n for(int j=2;j<=k;j++)\n {\n for(int i=1;i<=n;i++)\n {\n for(int r=0;r map1= new HashMap();\nHashMap map2= new HashMap();\nHashMap scazut= new HashMap();\nHashMap linieright= new HashMap();\n\n\t\n\tint n=input.nextInt();\n\tint k=input.nextInt();\n\t\n\tLong dp[][]=new Long[2001][2001];\n\t\n\tfor(int i=0;i<=2000;i++)\n\tfor(int j=0;j<=2000;j++) dp[i][j]=0L;\n\t\n\tfor(int j=0;j<=2000;j++)\n\tdp[1][j]=1L;\n\t\n\tint divizori[]=new int[n+1];\n\tint contor=0;\n\tLong mod=1000000007L;\n\t\n\n\t\n\t\nfor(int x=2;x<=k;x++)\n\n {\n for(int j=1;j<=n+1;j++)\n for(int t=j;t<=n+1;t+=j)\n {dp[x][t]+=dp[x-1][j];\n dp[x][t]=dp[x][t]%mod;\n }\n \n \n \n \n }\n\n\n\n\n\tLong result=0L;\n\t\n\tfor(int i=1;i<=n;i++) \n\t{result+=dp[k][i];\n\tresult=result%mod;}\n\t\n\tSystem.out.println(result);\n\t\n\t\n\t\n\n\t\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\t\t\n\t\t\t\n\t\t\t}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c1f0dfa0d0c593a40bf3244eae10a17", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class B\n{\n String line;\n StringTokenizer inputParser;\n BufferedReader is;\n FileInputStream fstream;\n DataInputStream in;\n String FInput=\"\";\n \n void openInput(String file)\n {\n\n if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin\n else\n {\n try{\n \n \n fstream = new FileInputStream(file);\n in = new DataInputStream(fstream);\n is = new BufferedReader(new InputStreamReader(in));\n }catch(Exception e)\n {\n System.err.println(e);\n }\n }\n\n }\n \n void readNextLine()\n \t{\n \t\ttry {\n \t\t\tline = is.readLine();\n \t\t\tinputParser = new StringTokenizer(line, \" ,\\t\");\n \t\t\t//System.err.println(\"Input: \" + line);\n \t\t} catch (IOException e) {\n \t\t\tSystem.err.println(\"Unexpected IO ERROR: \" + e);\n \t\t}\t\n \t\tcatch (NullPointerException e)\n \t\t{\n \t\t\tline=null;\n \t\t\t\n \t\t}\n \t\t\n \t}\n \n long NextLong()\n {\n String n = inputParser.nextToken();\n \n long val = Long.parseLong(n);\n \n return val;\n }\n \n int NextInt()\n {\n String n = inputParser.nextToken();\n int val = Integer.parseInt(n);\n \n //System.out.println(\"I read this number: \" + val);\n return val;\n }\n \n String NextString()\n {\n String n = inputParser.nextToken();\n return n;\n }\n \n void closeInput()\n {\n try {\n is.close();\n } catch (IOException e) {\n System.err.println(\"Unexpected IO ERROR: \" + e);\n }\n \n }\n \n \n public static void main(String [] argv)\n {\n //String filePath=\"circles.in\";\n String filePath=null;\n if(argv.length>0)filePath=argv[0];\n new B(filePath);\n \n }\n //585712681\n public B(String inputFile)\n {\n \topenInput(inputFile);\n \t\tStringBuilder sb = new StringBuilder();\n \t\treadNextLine();\n \t\tint N=NextInt();\n \t\tint K=NextInt();\n \t\t\n \t\tint [] [] p = new int [N+1][K];\n \t\tfinal int MOD=1000000007;\n \t\tfor(int i=1; i<=N; i++)\n \t\t{\n \t\t\tp[i][0]=1;\n \t\t}\n \t\t\n \t\tL[] xx = new L[N+1];\n \t\tfor(int i=0; i<=N; i++)\n \t\t{\n \t\t\txx[i]=new L();\n \t\t\tfor(int j=1; j<=i; j++)\n \t\t\t\tif(i%j==0)xx[i].x.add(j);\n \t\t}\n \t\t\n \t\tfor(int i=1; ix = new ArrayList();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c1412b547b2b851630e4ccf9074b5f6", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Barnicle\n{\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint a, b;\n\t\tString d;\n\n\t\tString str = s.nextLine();\n\t\ts.close();\n\n\t\ta = Integer.parseInt(str.substring(0,1));\n\t\td = str.substring(2,str.indexOf(\"e\"));\n\t\tb = Integer.parseInt(str.substring(str.indexOf(\"e\")+1));\n\n\t\tif (b > d.length())\n\t\t\twhile (b > d.length())\n\t\t\t\td += \"0\";\n\t\tif (b != d.length())\n\t\t\td = d.substring(0,b) + \".\" + d.substring(b);\n\t\tSystem.out.println(a + d);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b498e94485864d9445170a7f6d23ba3d", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class scientificNot {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tString num=sc.nextLine();\n\t\tint i=num.indexOf(\".\");\n\t\tint j=num.indexOf(\"e\");\n\t\tString a=num.substring(0,i);\n\t\tString d=num.substring(i+1,j);\n\t\tString B=num.substring(j+1);\n\t\tint b=Integer.parseInt(B);\n\t\tif (b==0) System.out.println(num.substring(0,j));\n\t\telse {\n\t\t\tif (d.length()>b) {\n\t\t\t\tSystem.out.println(a+d.substring(0,b)+\".\"+d.substring(b));\n\t\t\t} else {\n\t\t\t\tSystem.out.println(a+d+pad(b-d.length()));\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static String pad(int i) {\n\t\tString ret=\"\";\n\t\tfor (int j=0; j {\n int id;\n long val;\n\n public Pair(long val, int id) {\n this.val = val;\n this.id = id;\n }\n\n @Override\n public int compareTo(Pair 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 /* Reads n-1 edges by default. */\n private List[] toGraph(BIO io, int n) {\n List[] 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\nclass BIO 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 BIO() {\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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "57a045c67fe5be4d649e41ae047e73d4", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic final class round_362_b\n{\n static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic FastScanner sc=new FastScanner(br);\n static PrintWriter out=new PrintWriter(System.out);\n\t\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tchar[] a=sc.next().toCharArray();int pos=-1;\n\t\tfor(int i=0;ipos;i--)\n\t\t{\n\t\t\tlong val=Long.parseLong(a[i]+\"\");\n\t\t\tlong curr=val*(long)(Math.pow(10,pow));\n\t\t\tb+=curr;\n\t\t\tpow++;\n\t\t}\n\t\tint pos2=-1;\n\t\tfor(int i=0;i0)\n\t\t{\n\t\t\tif(pos2+11)\n\t\t{\n\t\t\tfor(int i=pos2;i= prevX && x <= curY && y >= prevY && y <= curY) break;\n \n if (prevX > 0 && prevY > 0) {\n curX = -prevX;\n turns++;\n }\n \n else if (prevX > 0 && prevY < 0) {\n curY = prevX;\n turns++;\n }\n \n else if (prevX < 0 && prevY > 0) {\n curY = prevX;\n turns++;\n }\n \n else if (prevX < 0 && prevY < 0) {\n curX = prevX + 1;\n turns++;\n }\n \n prevX = curX;\n prevY = curY\n ;\n \n }\n pl(turns);\n }\n\n public static void main(String[] args) {\n new A().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run() {\n try {\n reader = new BufferedReader(new BufferedReader(new InputStreamReader(System.in)));\n writer = new PrintWriter(System.out);\n tokenizer = null;\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n void p(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n void pl(Object... objects) {\n p(objects);\n writer.println();\n }\n\n int cc;\n\n void pf() {\n writer.printf(\"Case #%d: \", ++cc);\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9706e81a0c7108e2ebdc2666deee7870", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class T279A {\n\n\tpublic int solve(int x, int y) {\n\t\tint[][] axis = new int[100][4];\n\t\tint f = 0;\n\t\tint size = 1;\n\t\tint p = 0;\n\t\tint a = 0;\n\t\tint b = 0;\n\t\twhile (Math.abs(a) <= 100 && Math.abs(b) <= 100) {\n\t\t\tif (f == 0) {\n\t\t\t\taxis[p][0] = a;\n\t\t\t\taxis[p][1] = b;\n\t\t\t\ta += size;\n\t\t\t\taxis[p][2] = a;\n\t\t\t\taxis[p][3] = b;\n\t\t\t\tf = 1;\n\t\t\t\tp ++;\n\t\t\t} else if (f == 1) {\n\t\t\t\taxis[p][0] = a;\n\t\t\t\taxis[p][1] = b;\n\t\t\t\tb += size;\n\t\t\t\taxis[p][2] = a;\n\t\t\t\taxis[p][3] = b;\n\t\t\t\tf = 2;\n\t\t\t\tp ++;\n\t\t\t\tsize ++;\n\t\t\t} else if (f == 2) {\n\t\t\t\taxis[p][0] = a;\n\t\t\t\taxis[p][1] = b;\n\t\t\t\ta -= size;\n\t\t\t\taxis[p][2] = a;\n\t\t\t\taxis[p][3] = b;\n\t\t\t\tf = 3;\n\t\t\t\tp ++;\n\t\t\t} else if (f == 3) {\n\t\t\t\taxis[p][0] = a;\n\t\t\t\taxis[p][1] = b;\n\t\t\t\tb -= size;\n\t\t\t\taxis[p][2] = a;\n\t\t\t\taxis[p][3] = b;\n\t\t\t\tf = 0;\n\t\t\t\tp ++;\n\t\t\t\tsize ++;\n\t\t\t}\n\t\t\t\n\t\t\tif (x >= Math.min(axis[p - 1][0], axis[p - 1][2]) &&\n\t\t\t\tx <= Math.max(axis[p - 1][0], axis[p - 1][2]) &&\n\t\t\t\ty >= Math.min(axis[p - 1][1], axis[p - 1][3]) &&\n\t\t\t\ty <= Math.max(axis[p - 1][1], axis[p - 1][3]))\n\t\t\t\treturn p - 1;\n\t\t\t\n\t\t}\n\t\treturn 0;\n\t}\n\tpublic static void main(String[] args) {\n\t\tFastScanner in = new FastScanner();\n\t\tSystem.out.println(new T279A().solve(in.nextInt(), in.nextInt()));\n\t}\n\tstatic class FastScanner {\n\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\tString nextToken() {\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(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}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8cd0ed8a4e88a8085069dda4f15e1475", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class C171 {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(new BufferedInputStream(System.in));\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n int n = scanner.nextInt();\n int m = scanner.nextInt();\n int[] a = new int[n];\n int[] l = new int[m];\n int[] r = new int[m];\n for (int i = 0; i < n; i++) {\n a[i] = scanner.nextInt();\n }\n for (int i = 0; i < m; i++) {\n l[i] = scanner.nextInt() - 1;\n r[i] = scanner.nextInt() - 1;\n }\n if (n == 1) {\n for (int i = 0; i < m; i++) {\n out.println(\"Yes\");\n }\n } else {\n int t = 0;\n boolean up = a[0] <= a[1];\n int[] b = new int[n];\n b[0] = t;\n b[1] = t;\n for (int i = 2; i < n; i++) {\n if ((up && a[i] >= a[i - 1]) || (!up && a[i] <= a[i - 1])) {\n b[i] = t;\n } else {\n up = !up;\n t += up ? 2 : 1;\n b[i] = t;\n }\n }\n for (int i = 0; i < m; i++) {\n out.println(b[r[i]] - b[l[i]] <= 1 || (b[l[i] + 1] - b[l[i]] == 2 && b[r[i]] - b[l[i] + 1] <= 1) ? \"Yes\" : \"No\");\n }\n }\n out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "12853a526ea4226a83f69b0acbe0953f", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "//package pointspiral;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class PointSpiral {\n\n public static int[] makeMas(int[] massiv, int start) {\n massiv[0] = start;\n for (int i = 1; i < massiv.length; i++) {\n massiv[i] = massiv[i - 1] + 4;\n }\n return massiv;\n }\n \n public static void main(String[] args) {\n int x, y, n = 100, res;\n int[] one = new int[n];\n int[] two = new int[n];\n int[] three = new int[n];\n int[] four = new int[n];\n \n makeMas(one, 2);\n makeMas(two, 1);\n makeMas(three, 0);\n makeMas(four, 3);\n \n \n// one[0] = 2;\n// for (int i = 1; i < n; i++) {\n// one[i] = one[i - 1] + 4;\n// }\n// \n// two[0] = 1;\n// for (int i = 1; i < n; i++) {\n// two[i] = two[i - 1] + 4;\n// }\n// \n// three[0] = 0;\n// for (int i = 1; i < n; i++) {\n// three[i] = three[i - 1] + 4;\n// }\n// \n// four[0] = 3;\n// for (int i = 1; i < n; i++) {\n// four[i] = four[i - 1] + 4;\n// }\n \n Scanner cin = new Scanner(System.in);\n x = cin.nextInt();\n y = cin.nextInt();\n \n if (x == 0 && y == 0 || x == 1 && y == 0) {\n System.out.println(0);\n return;\n }\n \n if (x < y && x >= -y) {\n System.out.println(one[y - 1]);\n return;\n }\n \n if (x >= y && x > -y) {\n System.out.println(two[x - 1]);\n return;\n }\n \n if (x <= -y && x > y) {// -7 -13\n System.out.println(three[y * (-1) ]);\n return;\n }\n \n if (x < -y && x <= y) {\n System.out.println(four[x * (-1) - 1]);\n return;\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6b6195980de7e0a25becec20daefd1b", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class DoubleCola{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n long num = scan.nextLong();\n \n String[] names = {\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"};\n \n long round = 1;\n long step = 0;\n int index = -1;\n long curRound = round;\n while( step < num){\n \n if(curRound > 0 ){\n step++;\n curRound--;\n }\n index = index+1;\n \n if(index == 5){\n index = 0;\n round *= 2;\n }\n }\n \n System.out.println(names[index]);\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ced81ba64b026e85a8cad2d9c521e7f", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "/*\n ID: jeromej1\n LANG: JAVA\n PROG: 82A\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class EightTwoA \n{\n\tint n;\n\tArrayList queue;\n\t\n\tpublic EightTwoA() throws Exception\n\t{\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\tn = Integer.parseInt(f.readLine());\n\t\tqueue = new ArrayList();\n\t\tqueue.add(\"Sheldon\");\n\t\tqueue.add(\"Leonard\");\n\t\tqueue.add(\"Penny\");\n\t\tqueue.add(\"Rajesh\");\n\t\tqueue.add(\"Howard\");\n\t}\n\t\n\tpublic void compute()\n\t{\n\t\tint x = 1;\n\t\twhile(x < n)\n\t\t{\n\t\t\tString s = queue.get(0);\n\t\t\tqueue.remove(0);\n\t\t\tqueue.add(s);\n\t\t\tqueue.add(s);\n\t\t\tx++;\n\t\t}\n\t\tSystem.out.println(queue.get(0));\n\t}\n\t\n\tpublic static void main(String [] args) throws Exception\n\t{\n\t\tEightTwoA doubleCola = new EightTwoA();\n\t\tdoubleCola.compute();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c092bc46dfa9dd5b282adb7e5141a456", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.HashMap;\nimport java.util.Scanner;\n\n/**\n * Created by IntelliJ IDEA.\n * User: Jimmy\n * Date: 10/18/11\n * Time: 8:59 PM\n */\npublic class Problem82A {\n\n public static void main(String arguments[]) {\n new Problem82A().run();\n }\n\n private void run() {\n Scanner s = new Scanner(System.in);\n\n HashMap map = new HashMap();\n map.put(1, \"Sheldon\");\n map.put(2, \"Leonard\");\n map.put(3, \"Penny\");\n map.put(4, \"Rajesh\");\n map.put(5, \"Howard\");\n\n int n = s.nextInt();\n\n long sum = 0;\n\n int i = 1;\n int twice = 1;\n int temp = twice;\n boolean enter = true;\n\n //while(sum < n) {\n for(int j = 0; j < n; j++) {\n //System.out.println(\"-------------------\");\n //System.out.println(\"i = \" + i);\n if(i % 5 == 0 && enter) {\n twice *= 2;\n enter = false;\n //temp = twice;\n //i++;\n }\n //System.out.println(\"twice = \" + twice);\n sum += 1;\n\n if(sum != 1)\n temp--;\n //System.out.println(\"temp = \" + temp);\n if(temp == 0) {\n i++;\n i = i % 5;\n if(i == 0) {\n i += 5;\n }\n enter = true;\n temp = twice;\n }\n\n //System.out.println(\"sum = \" + sum);\n //System.out.println(\"i = \" + i);\n }\n\n System.out.println(map.get(i));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bb8f8a86202e1ef575cac062b6dee2f3", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main {\n\tpublic static void main(String[] args){\n\t\tScanner entrada = new Scanner(System.in);\n\t\tint n = entrada.nextInt();\n\t\tint res = n;\n\t\tint sal = 0;\n\t\tif (n == 1) {\n\t\t\tSystem.out.println(\"Sheldon\");\n\t\t}else {if (n == 2) {\n\t\t\t\tSystem.out.println(\"Leonard\");\n\t\t\t}else {if (n == 3) {\n\t\t\t\t\tSystem.out.println(\"Penny\");\n\t\t\t\t\t}else {if (n == 4) {\n\t\t\t\t\t\t\tSystem.out.println(\"Rajesh\");\n\t\t\t\t\t\t\t}else{if (n == 5) {\n\t\t\t\t\t\t\t\tSystem.out.println(\"Howard\");\n\t\t\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t}\n\t\tfor (int i = 5; i != 0 ; i = i*2) {\n\t\t\tif (res > 5) {\n\t\t\t\tres = res - i;\n\t\t\t\tsal++;\n\t\t\t}\n\t\t\tif (res < 0) {\n\t\t\t\tres = res + i;\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t\tint fin = 0;\n\t\tint pot = (int) Math.pow(2, sal-1);\n//\t\tfor (int i = 1; i != 0; i++) {\n//\t\t\tint poten = (int) Math.pow(5, sal);\n//\t\t\tif (res > poten) {\n//\t\t\t\tres = res - poten;\n//\t\t\t\tfin++;\n//\t\t\t\tif (res <0) {\n//\t\t\t\t\ti = 0;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\t\twhile (res>0) {\n\t\t\tres = res - pot;\n\t\t\tfin++;\n\t\t}\n\t\tif (fin == 1) {\n\t\t\tSystem.out.println(\"Sheldon\");\n\t\t}else {\n\t\t\tif (fin == 2) {\n\t\t\t\tSystem.out.println(\"Leonard\");\n\t\t\t}else {\n\t\t\t\tif (fin == 3) {\n\t\t\t\t\tSystem.out.println(\"Penny\");\n\t\t\t\t}else {\n\t\t\t\t\tif (fin == 4) {\n\t\t\t\t\t\tSystem.out.println(\"Rajesh\");\n\t\t\t\t\t}else {\n\t\t\t\t\t\tSystem.out.println(\"Howard\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tentrada.close();\n\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2d666c4d8cd4cfa417e45ef1354639b", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class BinaryProtocol {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tString st=\"\";\n\t\t\tst=st+s.next();\n\t\tString str = \"\";\n\t\tint num = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k =(int) st.charAt(i)-48;\n\t\t\tif (k == 1) {\n\t\t\t\tnum++;\n\t\t\t}\n\t\t\tif (k == 0) {\n\t\t\t\tif (st.charAt(i + 1) == 0) {\n\t\t\t\t\tstr=str+num+\"0\";\n\t\t\t\t\tnum=0;\n\t\t\t\t} else {\n\t\t\t\t\tstr = str + num;\n\t\t\t\t\tnum = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(i==n-1){\n\t\t\t\tstr=str+num;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(str);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00a4eab993f8e0aa4785929411463497", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package codeforces;\nimport java.util.*;\nimport java.io.*;\n\npublic class problemA {\n\t\n\tpublic static PrintWriter out; \n\t\n\t\n\tpublic static void main(String args[])\n\t{\n\t\tout=new PrintWriter(new BufferedOutputStream(System.out),true);\n\t\tMyScanner sc=new MyScanner();\n\t\tint N=sc.nextInt();\n\t\tString str=sc.next();\n\t\tlong r=0;\n\t String p=\"\";\n\t\tfor(int i=0;i1){\n sb.append(0+\"\");\n count_0--;\n }\n count_0=0;\n }\n else{\n count_0++;\n if(count_1!=0){\n sb.append(count_1+\"\");\n }\n count_1=0;\n }\n }\n if(count_0!=0){\n while(count_0>1){\n sb.append(0+\"\");\n }\n }\n else{\n sb.append(count_1);\n }\n System.out.println(sb.toString());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2f94aea896fe128c60274e9442670e28", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\nimport java.util.ArrayList;\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int a, n, b;\n a = in.nextInt(); b = in.nextInt(); n = in.nextInt();\n\n int k = 0;\n\n // 1st a, next b, so on\n while(n >= 0) {\n ++k;\n n -= euclid_gcd( (k & 1) ? a : b, n);\n }\n\n if (k & 1) out.println(1);\n else out.println(0); \n\n return;\n }\n\n public int euclid_gcd(int a, int b) {\n return b == 0 ? a : euclid_gcd(b, a%b);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "afe10b0ae5678027d85e9be779205c9b", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0} {"lang": "Java 6", "source_code": "\n\n\n\nimport java.io.BufferedReader;\n\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\npublic class a {\n\n public static void main(String[] args) {\n\n \tString []str = null ;\n \n InputStreamReader converter = new InputStreamReader(System.in);\n BufferedReader in = new BufferedReader(converter);\n\n try {\n str = in.readLine().split(\" \");\n } catch (Exception ex) {\n System.out.println(\"Error! \"+ex);\n }\n int a = Integer.parseInt(str[0]);\n int b = Integer.parseInt(str[1]);\n int n = Integer.parseInt(str[2]);\n\n \n System.out.println(result(a,b,n));\n \n }\n\npublic static int GCD(int a, int b)\n{\n if (b==0) return a;\n return GCD(b,a%b);\n}\npublic static int ex= 0;\npublic static int result(int a, int b,int n)\n{\n ex=GCD(a, n);\n if (ex==0) {return 1;}\n else {n -= ex;}\n ex=GCD(b, n);\n if (ex==0) {return 0;}\n else {n -= ex;}\n return result(a,b,n);\n}\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd75b1b88144cbeaa2e9ad9432db1ffa", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Epic {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\t\tint n = in.nextInt();\n\t\t\n\t\twhile(n>0){\n\t\t\tn-=divisor(a,n);\n\t\t\tif(n==0)System.out.println(\"0\");\n\t\t\tn-=divisor(b,n);\n\t\t\tif(n==0)System.out.println(\"1\");\n\t\t}\n\t}\n\t\n\tpublic static int divisor(int q, int c){\n\t\tif(q>c)divisor(q-c,c);\n\t\tif(c>q)divisor(c-q,q);\n\t\treturn c;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "97bde99dc1011b30bf326704eae97923", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner console = new Scanner(System.in);\n int a = console.nextInt(), b = console.nextInt(), n = console.nextInt();\n boolean turn = true;\n int small;\n while (n > 0) {\n if (turn) {\n small = Math.min(a, n);\n while (Math.max(a, n) % small != 0) {\n small--;\n }\n n -= small;\n a -= small;\n turn = false;\n } else {\n small = Math.min(b, n);\n while (Math.max(b, n) % small != 0) {\n small--;\n }\n n -= small;\n b -= small;\n turn = true;\n }\n }\n if (turn) {\n System.out.println(1);\n } else {\n System.out.println(0);\n }\n }\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2e92a9c388d7790d7f57f500b7b70ebc", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0} {"lang": "Java 7", "source_code": "package codeforces.div2.r279;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public static void main(String args[]) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n SolverD.InputReader in = new SolverD.InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n SolverD solver = new SolverD();\n int testCount = 1;\n for (int i = 1; i <= testCount; i++) {\n solver.solve(in, out);\n }\n out.close();\n }\n}\n\nclass SolverD {\n\n public void solve(InputReader in, PrintWriter out) {\n int a1 = in.nextInt();\n int b1 = in.nextInt();\n int a2 = in.nextInt();\n int b2 = in.nextInt();\n\n int ca12 = fact(a1, 2);\n int ca13 = fact(a1, 3);\n int cb12 = fact(b1, 2);\n int cb13 = fact(b1, 3);\n\n int a1r = a1 / (pow(2, ca12) * pow(3, ca13));\n int b1r = b1 / (pow(2, cb12) * pow(3, cb13));\n\n int ca22 = fact(a2, 2);\n int ca23 = fact(a2, 3);\n int cb22 = fact(b2, 2);\n int cb23 = fact(b2, 3);\n\n int a2r = a2 / (pow(2, ca22) * pow(3, ca23));\n int b2r = b2 / (pow(2, cb22) * pow(3, cb23));\n\n if (a1r*b1r != a2r*b2r) {\n out.println(-1);\n return;\n }\n\n int c13 = ca13 + cb13;\n int c23 = ca23 + cb23;\n\n int sol = 0;\n if (c13 != c23) {\n int d = Math.abs(c13 - c23);\n sol += d;\n if (c13 > c23) {\n if (d <= c13) {\n ca13 -= d;\n ca12 += d;\n } else {\n ca12 += ca13;\n cb13 -= (d - ca13);\n cb12 += (d - ca13);\n ca13 = 0;\n }\n } else {\n if (d <= c23) {\n ca23 -= d;\n ca22 += d;\n } else {\n ca22 += ca23;\n cb23 -= (d - ca23);\n cb22 += (d - ca23);\n ca23 = 0;\n }\n }\n }\n\n int c12 = ca12 + cb12;\n int c22 = ca22 + cb22;\n\n int d = Math.abs(c12 - c22);\n sol += d;\n if (c12 > c22) {\n if (d <= c12) {\n ca12 -= d;\n } else {\n ca12 = 0;\n cb12 -= (d - ca12);\n }\n } else {\n if (d <= c22) {\n ca22 -= d;\n } else {\n ca22 = 0;\n cb22 -= (d - ca22);\n }\n }\n\n a1 = a1r * pow(2, ca12) * pow(3, ca13);\n b1 = b1r * pow(2, cb12) * pow(3, cb13);\n a2 = a2r * pow(2, ca22) * pow(3, ca23);\n b2 = b2r * pow(2, cb22) * pow(3, cb23);\n\n out.println(sol);\n out.println(a1 + \" \" + b1);\n out.println(a2 + \" \" + b2);\n }\n\n private int pow(final int a, int b) {\n int r = 1;\n while (b>0) {\n r = r*a;\n b--;\n }\n return r;\n }\n\n private int fact(int num, final int f) {\n int ct = 0;\n while (num % f == 0) {\n ct++;\n num /= f;\n }\n return ct;\n }\n\n static class InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1cf50aded21e4b171107d9cd15d1b442", "src_uid": "4fcd8c4955a47661462c326cbb3429bd", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class d1 {\n\n\tstatic class P{\n\t\tlong p;\n\t\tint deg;\n\t\t\n\t\tP(long _p, int _deg){\n\t\t\tp = _p;\n\t\t\tdeg = _deg;\n\t\t}\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint a1 = in.nextInt();\n\t\tint b1 = in.nextInt();\n\t\tint a2 = in.nextInt();\n\t\tint b2 = in.nextInt();\n\t\tlong s1 = 1l * a1 * b1;\n\t\tlong s2 = 1l * a2 * b2;\n\t\tArrayList

p1 = new ArrayList

();\n\t\tArrayList

p2 = new ArrayList

();\n\t\tlong x = s1;\n\t\tfor (int i = 2; i * i <= s1; i++) {\n\t\t\tif (x % i == 0){\n\t\t\t\tP q = new P(i, 0);\n\t\t\t\twhile(x % i == 0){\n\t\t\t\t\tx /= i;\n\t\t\t\t\tq.deg++;\n\t\t\t\t}\n\t\t\t\tp1.add(q);\n\t\t\t}\n\t\t}\n\t\tif (x > 1){\n\t\t\tp1.add(new P(x, 1));\n\t\t}\n\t\tx = s2;\n\t\tfor (int i = 2; i * i <= s2; i++) {\n\t\t\tif (x % i == 0){\n\t\t\t\tP q = new P(i, 0);\n\t\t\t\twhile(x % i == 0){\n\t\t\t\t\tx /= i;\n\t\t\t\t\tq.deg++;\n\t\t\t\t}\n\t\t\t\tp2.add(q);\n\t\t\t}\n\t\t}\n\t\tif (x > 1){\n\t\t\tp2.add(new P(x, 1));\n\t\t}\n\t\tint i1 = 0;\n\t\tint i2 = 0;\n\t\tboolean flag = true;\n\t\tint deg12 = 0;\n\t\tint deg13 = 0;\n\t\tint deg22 = 0;\n\t\tint deg23 = 0;\n\t\tif (p1.get(0).p == 2){\n\t\t\ti1++;\n\t\t\tdeg12 = p1.get(i1 - 1).deg;\n\t\t}\n\t\tif (p2.get(0).p == 2){\n\t\t\ti2++;\n\t\t\tdeg22 = p2.get(i2 - 1).deg;\n\t\t}\n\t\tif ((i1 < p1.size()) && (p1.get(i1).p == 3)){\n\t\t\ti1++;\n\t\t\tdeg13 = p1.get(i1 - 1).deg;\n\t\t}\n\t\tif ((i2 < p2.size()) && (p2.get(i2).p == 3)){\n\t\t\ti2++;\n\t\t\tdeg23 = p2.get(i2 - 1).deg;\n\t\t}\n\t\tif (p1.size() - i1 == p2.size() - i2){\n\t\t\tflag = true;\n\t\t\tint count = i2;\n\t\t\tfor (int i = i1; i < p1.size(); i++) {\n\t\t\t\tif (p1.get(i).p != p2.get(count).p || (p1.get(i).deg != p2.get(count).deg)){\n\t\t\t\t\tflag = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif (!flag){\n\t\t\t\tout.print(-1);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tlong ans = 0;\n\t\t\t\tint d1 = deg12 - deg22;\n\t\t\t\tint d2 = deg13 - deg23;\n\t\t\t\tif (d2 > 0){\n\t\t\t\t\twhile ((a1 % 3 == 0) && (d2 > 0)) {\n\t\t\t\t\t\ta1 /= 3;\n\t\t\t\t\t\ta1 *= 2;\n\t\t\t\t\t\td2--;\n\t\t\t\t\t\td1++;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t\twhile ((b1 % 3 == 0) && (d2 > 0)) {\n\t\t\t\t\t\tb1 /= 3;\n\t\t\t\t\t\tb1 *= 2;\n\t\t\t\t\t\td2--;\n\t\t\t\t\t\td1++;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\twhile ((a2 % 3 == 0) && (d2 < 0)) {\n\t\t\t\t\t\ta2 /= 3;\n\t\t\t\t\t\ta2 *= 2;\n\t\t\t\t\t\td2++;\n\t\t\t\t\t\td1--;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t\twhile ((b2 % 3 == 0) && (d2 < 0)) {\n\t\t\t\t\t\tb2 /= 3;\n\t\t\t\t\t\tb2 *= 2;\n\t\t\t\t\t\td2++;\n\t\t\t\t\t\td1--;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (d1 > 0){\n\t\t\t\t\twhile ((a1 % 2 == 0) && (d1 > 0)) {\n\t\t\t\t\t\ta1 /= 2;\n\t\t\t\t\t\td1--;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t\twhile ((b1 % 2 == 0) && (d1 > 0)) {\n\t\t\t\t\t\tb1 /= 2;\n\t\t\t\t\t\td1--;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\twhile ((a2 % 2 == 0) && (d1 < 0)) {\n\t\t\t\t\t\ta2 /= 2;\n\t\t\t\t\t\td1++;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t\twhile ((b2 % 2 == 0) && (d1 < 0)) {\n\t\t\t\t\t\tb2 /= 2;\n\t\t\t\t\t\td1++;\n\t\t\t\t\t\tans++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout.println(ans);\n\t\t\t\tout.println(a1 + \" \" + b1);\n\t\t\t\tout.println(a2 + \" \" + b2);\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tout.print(-1);\n\t\t}\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5339a077069b6f1c3b6de2a2c6ff9141", "src_uid": "4fcd8c4955a47661462c326cbb3429bd", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "package thnkndblv;\n\nimport java.util.HashMap;\nimport java.util.Scanner;\nimport java.io.PrintWriter;\n\npublic class TaskD {\n class Pair {\n public int w, h, t;\n public Pair(int w, int h, int t) {\n this.w = w;\n this.h = h;\n this.t = t;\n }\n }\n\n HashMap a = new HashMap<>();\n HashMap b = new HashMap<>();\n\n void run(int w, int h, int t, HashMap x) {\n long a = w;\n a = a * h;\n\n if (!x.containsKey(a) || t < x.get(a).t) x.put(a, new Pair(w, h, t));\n\n if (w > 1 && w % 2 == 0) run(w/2, h, t+1, x);\n if (w > 1 && w % 3 == 0) run(2*w/3, h, t+1, x);\n\n if (h > 1 && h % 2 == 0) run(w, h/2, t + 1, x);\n if (h > 1 && h % 3 == 0) run(w, 2*h/3, t + 1, x);\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int a1 = in.nextInt();\n int b1 = in.nextInt();\n\n run(a1, b1, 0, a);\n\n int a2 = in.nextInt();\n int b2 = in.nextInt();\n\n run(a2, b2, 0, b);\n\n int ans = (int)1e9;\n long area = 0;\n for (long x : a.keySet()) {\n if ( b.containsKey(x) ) {\n int tt = a.get(x).t + b.get(x).t;\n if ( tt < ans ) {\n ans = tt;\n area = x;\n }\n }\n }\n\n if ( ans == (int)1e9 ) out.println(-1);\n else {\n out.println(ans);\n out.println(a.get(area).w + \" \" + a.get(area).h);\n out.println(b.get(area).w + \" \" + b.get(area).h);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd725856364ff7c68cb19147b888bab9", "src_uid": "4fcd8c4955a47661462c326cbb3429bd", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\nimport java.util.HashMap;\nimport java.util.NoSuchElementException;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.util.Comparator;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.IOException;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskD {\n Map>> save = new HashMap>>();\n Pair answerA = new Pair(-1, -1);\n Pair answerB = new Pair(-1, -1);\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int ax = in.readInt();\n int ay = in.readInt();\n int bx = in.readInt();\n int by = in.readInt();\n dfs(ax, ay, 0);\n int answer = findAnswer(bx, by, 0);\n if (answer >= 0) {\n out.printLine(answer);\n out.printLine(answerA.first, answerA.second);\n out.printLine(answerB.first, answerB.second);\n }\n else\n out.printLine(-1);\n }\n\n private int findAnswer(int x, int y, int deep) {\n if (save.containsKey(1L * x * y)) {\n answerA = save.get(1L * x * y).second;\n answerB = Pair.makePair(x, y);\n return deep + save.get(1L * x * y).first;\n }\n int answer = Integer.MAX_VALUE / 2;\n int val = -1;\n if (x % 2 == 0) {\n val = findAnswer(x / 2, y, deep + 1);\n if (val >= 0 && answer > val) {\n answer = val;\n answerA = save.get(1L * (x / 2) * y).second;\n answerB = Pair.makePair(x / 2, y);\n }\n }\n if (x % 3 == 0) {\n val = findAnswer((x / 3) * 2, y, deep + 1);\n if (val >= 0 && answer > val) {\n answer = val;\n answerA = save.get(1L * (x / 2) * y).second;\n answerB = Pair.makePair(x / 2, y);\n }\n }\n if (y % 2 == 0) {\n val = findAnswer(x, y / 2, deep + 1);\n if (val >= 0 && answer > val) {\n answer = val;\n answerA = save.get(1L * (x / 2) * y).second;\n answerB = Pair.makePair(x / 2, y);\n }\n }\n if (y % 3 == 0) {\n val = findAnswer(x, (y / 3) * 2, deep + 1);\n if (val >= 0 && answer > val) {\n answer = val;\n answerA = save.get(1L * (x / 2) * y).second;\n answerB = Pair.makePair(x / 2, y);\n }\n }\n return answer >= Integer.MAX_VALUE / 2 ? -1 : answer;\n }\n\n private void dfs(int x, int y, int deep) {\n if (!save.containsKey(1L * x * y)) {\n save.put(1L * x * y, Pair.makePair(deep, Pair.makePair(x, y)));\n }\n else {\n int val = save.get(1L * x * y).first;\n save.put(1L * x * y, Pair.makePair(Math.min(deep, val), Pair.makePair(x, y)));\n }\n if (x % 2 == 0)\n dfs(x / 2, y, deep + 1);\n if (x % 3 == 0)\n dfs((x / 3) * 2, y, deep + 1);\n if (y % 2 == 0)\n dfs(x, y / 2, deep + 1);\n if (y % 3 == 0)\n dfs(x, (y / 3) * 2, deep + 1);\n }\n}\n\nclass Pair implements Comparable> {\n\n public final U first;\n public final V second;\n\n public static Pair makePair(U first, V second) {\n return new Pair(first, second);\n }\n\n public Pair(U first, V second) {\n this.first = first;\n this.second = second;\n }\n\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Pair pair = (Pair) o;\n\n return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);\n\n }\n\n public int hashCode() {\n int result = first != null ? first.hashCode() : 0;\n result = 31 * result + (second != null ? second.hashCode() : 0);\n return result;\n }\n\n public String toString() {\n return \"(\" + first + \",\" + second + \")\";\n }\n\n public int compareTo(Pair o) {\n int value = ((Comparable)first).compareTo(o.first);\n if (value != 0)\n return value;\n return ((Comparable)second).compareTo(o.second);\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return 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\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64f29ce989b84c29ea6b80a72d30ef48", "src_uid": "4fcd8c4955a47661462c326cbb3429bd", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class ss{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n StringBuilder sb = new StringBuilder();\n for(int i=2;i<(int)Math.sqrt(n);i++){\n if(n%i==0){\n sb.append(i+\"\"+n/i);\n break;\n }\n }\n System.out.println(Integer.parseInt(sb.toString()));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "033eaa3c6c0d8997ffd2f206925ebefd", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null} {"lang": "Java 11", "source_code": "package codeforces;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class Limericks {\n\t// https://codeforces.com/problemset/problem/1331/B\n\t\n\tpublic static void main(String[] args) throws IOException, FileNotFoundException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t//BufferedReader in = new BufferedReader(new FileReader(\"Limericks.in\"));\n\t\t// INPUT //\n\n\t\tint n = Integer.parseInt(in.readLine()); \n\t\t\n\t\tint factor1 = -1;\n\t\tfor (int i = 2; i < n; i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\tfactor1 = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint factor2 = n / factor1;\n\t\t\n\t\tSystem.out.println(\"\" + factor1+factor2);\n\t\t\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7199377ac1602438110af3a1f8f9c875", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner scan = new Scanner(System.in);\n int num = scan.nextInt();\n int[] arr= {2,3,5,7,11,13,17,19,23,29,31};\n String s = \"\";\n int i=0;\n while(num!=1){\n if(num%arr[i] == 0){\n num/=arr[i];\n s+=arr[i];\n }\n i+=1;\n }\n System.out.println(s);\n\n }\n\n\n}\n\n\n\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dae25f2dafe34cc1ccbb8724c893a204", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null} {"lang": "Java 11", "source_code": "package codeforces;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class Limericks {\n\t// https://codeforces.com/problemset/problem/1331/B\n\t\n\tpublic static void main(String[] args) throws IOException, FileNotFoundException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t//BufferedReader in = new BufferedReader(new FileReader(\"Limericks.in\"));\n\t\t// INPUT //\n\n\t\tint n = Integer.parseInt(in.readLine()); \n\t\t\n\t\tint factor1 = -1;\n\t\tfor (int i = 2; i <= Math.pow(n, 1/2); i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\tfactor1 = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint factor2 = n / factor1;\n\t\t\n\t\tSystem.out.println(\"\" + factor1+factor2);\n\t\t\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f553f69a4e0d1964f28dcb3d01a949df", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null} {"lang": "Java 8", "source_code": "package training;\nimport java.util.*;\npublic class NewClass {\n public static void main(String []args){\n Scanner sc=new Scanner (System.in);\n int x,nChest=0, nBiceps=0, nBack=0;\n \n String st=\"chest\";\n \n x=sc.nextInt();\n int arr[] = new int [x];\n for ( int i=0 ; i nBiceps && nChest > nBack)\n\t\tSystem.out.println (\"chest\");\n\telse if (nBiceps > nChest && nBiceps > nBack)\n\t\tSystem.out.println (\"biceps\");\n\telse if (nBack > nChest && nBack > nBiceps)\n\t\tSystem.out.println (\"back\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "402e00f9113c13825405c76610025c04", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// Scanner read = new Scanner(new FileInputStream(new\n\t\t// File(\"input.txt\")));\n\t\t// PrintWriter out = new PrintWriter(new File(\"output.txt\"));\n\t\tScanner read = new Scanner(System.in);\n\t\tint n = read.nextInt(), arr[] = new int[9], chest = 0, bi = 0, back = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = read.nextInt();\n\t\t\tif (i % 3 == 0)\n\t\t\t\tchest += arr[i];\n\t\t\telse if (i % 3 == 1)\n\t\t\t\tbi += arr[i];\n\t\t\telse\n\t\t\t\tback += arr[i];\n\t\t}\n\t\tif (Math.max(chest, Math.max(bi, back)) == chest)\n\t\t\tSystem.out.println(\"chest\");\n\t\telse if (Math.max(chest, Math.max(bi, back)) == bi)\n\t\t\tSystem.out.println(\"biceps\");\n\t\telse\n\t\t\tSystem.out.println(\"back\");\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f535016885a7129c6bbe46473587da84", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Entrainement4 {\npublic static void main(String[] args) {\n Scanner s=new Scanner(System.in) ; \n int n =s.nextInt();\n int [] t=new int [n];\n int i1=0;\n int i2=1;\n int i3=2;\n\n for(int i=0;ibiceps)\nmax1=chets;\nelse\nmax1=biceps;\n\nif(back>max1)\nmax1=back;\n\nif(max1==back)\n System.out.println(\"back\");\nelse if(max1==biceps)\n System.out.println(\"bicebs\");\nelse\n System.out.println(\"chets\");\n\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "233d847428083b46dd34e6041ff3a9e4", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class Greg_workout {\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int size = sc.nextInt();\n int a[] = new int[size];\n int count = 0;\n int bcount = 0;\n int bacount = 0;\n if(size<3)\n {\n int no1 = sc.nextInt();\n int no2 = sc.nextInt();\n if(no1>no2)\n System.out.println(\"chest\");\n else\n System.out.println(\"biceps\");\n }\n else\n {\n for(int i=0;ibcount && count>bacount)\n System.out.println(\"chest\");\n else if(bcount>count && bcount>bacount)\n System.out.println(\"biceps\");\n else\n System.out.println(\"back\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8bd5caf824d49fea8ffad115981043c1", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\n\npublic class practice {\n\tpublic static HashSet set;\n\tpublic static String str;\n\tpublic static int[] dp;\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\tset = new HashSet<>();\n\t\tString[] arr = { \"H\", \"He\", \"Li\", \"Be\", \"B\", \"C\", \"N\", \"O\", \"F\", \"Ne\", \"Na\", \"Mg\", \"Al\", \"Si\", \"P\", \"S\", \"Cl\",\n\t\t\t\t\"Ar\", \"K\", \"Ca\", \"Sc\", \"Ti\", \"V\", \"Cr\", \"Mn\", \"Fe\", \"Co\", \"Ni\", \"Cu\", \"Zn\", \"Ga\", \"Ge\", \"As\", \"Se\",\n\t\t\t\t\"Br\", \"Kr\", \"Rb\", \"Sr\", \"Y\", \"Zr\", \"Nb\", \"Mo\", \"Tc\", \"Ru\", \"Rh\", \"Pd\", \"Ag\", \"Cd\", \"In\", \"Sn\", \"Sb\",\n\t\t\t\t\"Te\", \"I\", \"Xe\", \"Cs\", \"Ba\", \"La\", \"Hf\", \"Ta\", \"W\", \"Re\", \"Os\", \"Ir\", \"Pt\", \"Au\", \"Hg\", \"Tl\", \"Pb\",\n\t\t\t\t\"Bi\", \"Po\", \"At\", \"Rn\", \"Fr\", \"Ra\", \"Ac\", \"Rf\", \"Db\", \"Sg\", \"Bh\", \"Hs\", \"Mt\", \"Ce\", \"Pr\", \"Nd\", \"Pm\",\n\t\t\t\t\"Sm\", \"Eu\", \"Gd\", \"Tb\", \"Dy\", \"Ho\", \"Er\", \"Tm\", \"Yb\", \"Lu\", \"Th\", \"Pa\", \"U\", \"Np\", \"Pu\", \"Am\", \"Cm\",\n\t\t\t\t\"Bk\", \"Cf\", \"Es\", \"Fm\", \"Md\", \"No\", \"Lr\", \"Rf\", \"Db\", \"Sg\", \"Bh\", \"Hs\", \"Mt\", \"Ds\", \"Rg\", \"Cn\", \"Nh\",\n\t\t\t\t\"Fl\", \"Mc\", \"Lv\", \"Ts\", \"Og\" };\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tarr[i] = arr[i].toUpperCase();\n\t\t\tset.add(arr[i]);\n\t\t}\n\t\tstr = s.next();\n\t\tstr = str.toUpperCase();\n\t\tdp = new int[str.length()];\n\t\tfor (int i = 0; i < dp.length; i++) {\n\t\t\tdp[i] = -1;\n\t\t}\n\t\tif (pos(0))\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n\n\tpublic static boolean pos(int i) {\n\t\tint n = str.length();\n\t\tif (i == n)\n\t\t\treturn true;\n\t\tif (dp[i] == 1)\n\t\t\treturn true;\n\t\tif (dp[i] == 0)\n\t\t\treturn false;\n\t\tfor (int j = i + 1; j <= n; j++) {\n\t\t\tString temp = str.substring(i, j);\n\t\t\tif (set.contains(temp)) {\n\t\t\t\tboolean val = pos(j);\n\t\t\t\tif (val) {\n\t\t\t\t\tdp[i] = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1fdc25fe9933d91ad277d67b02f3eddc", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class F_elementary {\n\tpublic static int works(String[] arr, String str, int count) {\n\t\tif (str.length() == 0) {\n\t\t\tcount++;\n\t\t}\n\t\t\n\t\telse {\n\t\t\tboolean x = false;\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t\tif (str.length() >= 2 && str.substring(0,1).equals(arr[i]) && str.substring(0,2).equals(arr[i])) {\n\t\t\t\t\tString temp = str;\n\t\t\t\t\tString temp2 = str;\n\t\t\t\t\tcount += works(arr, str.substring(1), count);\n\t\t\t\t\tcount += works(arr, str.substring(2), count);\n\t\t\t\t\tx = true;\n\t\t\t\t}\n\t\t\t\telse if (str.length() >= 1 && str.substring(0,1).equals(arr[i])) {\n\t\t\t\t\tcount += works(arr, str.substring(1), count);\n\t\t\t\t\tx = true;\n\t\t\t\t}\n\t\t\t\telse if (str.length() >= 2 && str.substring(0,2).equals(arr[i])) {\n\t\t\t\t\tcount += works(arr, str.substring(2), count);\n\t\t\t\t\tx = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x == false) {\n\t\t\t\treturn count;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n public static void main(String[] args) throws IOException {\n FastScanner sc = new FastScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n \n String str = sc.next();\n String[] arr = {\"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 if(works(arr, str, 0) >= 1) {\n \tpw.println(\"YES\");\n }\n else pw.println(\"NO\");\n \n pw.close();\n }\n static class FastScanner {\n \tprivate 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 FastScanner(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 public int peek() {\n if (numChars == -1) {\n return -1;\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n return -1;\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuilder buf = new StringBuilder();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r') {\n buf.appendCodePoint(c);\n }\n c = read();\n }\n return buf.toString();\n }\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0) {\n s = readLine0();\n }\n return s;\n }\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines) {\n return readLine();\n } else {\n return readLine0();\n }\n }\n\n public BigInteger readBigInteger() {\n try {\n return new BigInteger(nextString());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n\n public char nextCharacter() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n return (char) c;\n }\n\n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public boolean isExhausted() {\n int value;\n while (isSpaceChar(value = peek()) && value != -1) {\n read();\n }\n return value == -1;\n }\n public String next() {\n return nextString();\n }\n\n public SpaceCharFilter getFilter() {\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter) {\n this.filter = filter;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n public int[] nextIntArray(int n){\n int[] array=new int[n];\n for(int i=0;i pq = new PriorityQueue();\n for(int i = 0; i < n; i++){\n pq.add(array[i]);\n }\n int[] out = new int[n];\n for(int i = 0; i < n; i++){\n out[i] = pq.poll();\n }\n return out;\n }\n public int[] nextSumIntArray(int n){\n int[] array=new int[n];\n array[0]=nextInt();\n for(int i=1;i[] nextGraph(int n, int m){\n ArrayList[] adj = new ArrayList[n];\n for(int i = 0; i < n; i++){\n adj[i] = new ArrayList();\n }\n for(int i = 0; i < m; i++){\n int u = nextInt(); int v = nextInt();\n u--; v--;\n adj[u].add(v); adj[v].add(u);\n }\n return adj;\n }\n public ArrayList[] nextTree(int n){\n return nextGraph(n, n-1);\n }\n\n public long[] nextLongArray(int n){\n long[] array=new long[n];\n for(int i=0;i= s.length()) {\n\t\t\treturn true;\n\t\t}\n\n\t\tboolean can = false;\n\n\t\tfor(int i = 0; i < 128; i++) {\n\t\t\tif(ind + elem[i].length() <= s.length()) {\n\t\t\t\tboolean tmpcan = true;\n\t\t\t\tfor(int j = 0; j < elem[i].length(); j++) {\n\t\t\t\t\tif(s.charAt(ind + j) != elem[i].charAt(j)) {\n\t\t\t\t\t\ttmpcan = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif(tmpcan) {\n\t\t\t\t\tif(solve(s, ind + elem[i].length())) {\n\t\t\t\t\t\tcan = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn can;\n\t}\n\n\n\tpublic void realMain() throws Exception {\n\n\t\tBufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);\n\n\t\tint i = 0;\n\n\n\t\t/*while(true) {\nString in = fin.readLine();\n\t\tString[] ar = in.split(\"\\t\");\n\n\t\tString element = ar[0];\n\t\tif(ar[0].equals(\"\")) {\n\t\t\telement = ar[1];\n\t\t}\n\t\t\n\n\t\tSystem.out.println(\"elem[\" + i + \"] = \\\"\" + element.toUpperCase().trim() + \"\\\";\");\n\t\ti++;\n\t\t}*/\n\n\t\telem = new String[128];\n\nelem[0] = \"AC\";\nelem[1] = \"AG\";\nelem[2] = \"AL\";\nelem[3] = \"AM\";\nelem[4] = \"AR\";\nelem[5] = \"AS\";\nelem[6] = \"AT\";\nelem[7] = \"AU\";\nelem[8] = \"B\";\nelem[9] = \"BA\";\nelem[10] = \"BE\";\nelem[11] = \"BH\";\nelem[12] = \"BI\";\nelem[13] = \"BK\";\nelem[14] = \"BR\";\nelem[15] = \"C\";\nelem[16] = \"CA\";\nelem[17] = \"CD\";\nelem[18] = \"CE\";\nelem[19] = \"CF\";\nelem[20] = \"CL\";\nelem[21] = \"CM\";\nelem[22] = \"CO\";\nelem[23] = \"CR\";\nelem[24] = \"CS\";\nelem[25] = \"CU\";\nelem[26] = \"DB\";\nelem[27] = \"DS\";\nelem[28] = \"DY\";\nelem[29] = \"ER\";\nelem[30] = \"ES\";\nelem[31] = \"EU\";\nelem[32] = \"F\";\nelem[33] = \"FE\";\nelem[34] = \"FM\";\nelem[35] = \"FR\";\nelem[36] = \"GA\";\nelem[37] = \"GD\";\nelem[38] = \"GE\";\nelem[39] = \"H\";\nelem[40] = \"HE\";\nelem[41] = \"HF\";\nelem[42] = \"HG\";\nelem[43] = \"HO\";\nelem[44] = \"HS\";\nelem[45] = \"I\";\nelem[46] = \"IN\";\nelem[47] = \"IR\";\nelem[48] = \"K\";\nelem[49] = \"KR\";\nelem[50] = \"LA\";\nelem[51] = \"LI\";\nelem[52] = \"LR\";\nelem[53] = \"LU\";\nelem[54] = \"MD\";\nelem[55] = \"MG\";\nelem[56] = \"MN\";\nelem[57] = \"MO\";\nelem[58] = \"MT\";\nelem[59] = \"N\";\nelem[60] = \"NA\";\nelem[61] = \"NB\";\nelem[62] = \"ND\";\nelem[63] = \"NE\";\nelem[64] = \"NI\";\nelem[65] = \"NO\";\nelem[66] = \"NP\";\nelem[67] = \"O\";\nelem[68] = \"OS\";\nelem[69] = \"P\";\nelem[70] = \"PA\";\nelem[71] = \"PB\";\nelem[72] = \"PD\";\nelem[73] = \"PM\";\nelem[74] = \"PO\";\nelem[75] = \"PR\";\nelem[76] = \"PT\";\nelem[77] = \"PU\";\nelem[78] = \"RA\";\nelem[79] = \"RB\";\nelem[80] = \"RE\";\nelem[81] = \"RF\";\nelem[82] = \"RG\";\nelem[83] = \"RH\";\nelem[84] = \"RN\";\nelem[85] = \"RU\";\nelem[86] = \"S\";\nelem[87] = \"SB\";\nelem[88] = \"SC\";\nelem[89] = \"SE\";\nelem[90] = \"SG\";\nelem[91] = \"SI\";\nelem[92] = \"SM\";\nelem[93] = \"SN\";\nelem[94] = \"SR\";\nelem[95] = \"TA\";\nelem[96] = \"TB\";\nelem[97] = \"TC\";\nelem[98] = \"TE\";\nelem[99] = \"TH\";\nelem[100] = \"TI\";\nelem[101] = \"TL\";\nelem[102] = \"TM\";\nelem[103] = \"U\";\nelem[104] = \"UUB\";\nelem[105] = \"UUH\";\nelem[106] = \"UUO\";\nelem[107] = \"UUP\";\nelem[108] = \"UUQ\";\nelem[109] = \"UUS\";\nelem[110] = \"UUT\";\nelem[111] = \"V\";\nelem[112] = \"W\";\nelem[113] = \"XE\";\nelem[114] = \"Y\";\nelem[115] = \"YB\";\nelem[116] = \"ZN\";\nelem[117] = \"ZR\";\nelem[118] = \"MT\";\nelem[119] = \"DS\";\nelem[120] = \"RG\";\nelem[121] = \"CN\";\nelem[122] = \"NH\";\nelem[123] = \"FL\";\nelem[124] = \"MC\";\nelem[125] = \"LV\";\nelem[126] = \"TS\";\nelem[127] = \"OG\";\n\n\n\t\tString in = fin.readLine();\n\n\t\t\t\n\t\tboolean can = false;\n\n\t\tcan = solve(in, 0);\n\n\t\tif(can) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\n\n\n\t}\n\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tF f = new F();\n\t\tf.realMain();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "78382e2aa71b1325da876a053227fd39", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null} {"lang": "Java 11", "source_code": " import java.io.*;\n import java.util.StringTokenizer;\n import java.util.*;\n import java.math.*;\n import java.lang.Integer;\n \n public class Solution {\n \t\n \t\n \tpublic static boolean test(String s) {\n \t\t\n \t\tboolean res=false;\n \t\t\n \t\tif (s.length()<=2){\n \t\t\tres=check(s);\n \t\t}\n \t\t\n \t\t\n \t\tif (s.length()>1&check(s.substring(0,1))){\n\n \t\t\tres=res|test(s.substring(1,s.length()));\n \t\t}\n \t\t\n \t\tif (res) {return res;}\n \t\t\n \t\t\n \t\tif (s.length()>2&check(s.substring(0,2))){\n\n \t\t\tres=res|test(s.substring(2,s.length()));\n \t\t\t\n \t\t}\n \t\t\n \t\treturn res;\n \t}\n \t\n \tpublic static boolean check(String s) {\n \t\t\n \t\tboolean res=false;\n \t\t\n \t\tString[] checklist={\"H\", \"HE\", \"LI\", \"BE\", \"B\", \"C\", \"N\", \"O\", \"F\", \"NE\", \"NA\",\"MG\",\n \t\t\t\t\"AL\", \"SI\", \"P\", \"S\", \"CL\", \"AR\", \"K\", \"CA\", \"SC\", \"TI\", \"V\", \"CR\", \n \t\t\t\t\"MN\", \"FE\", \"CO\", \"NI\", \"CU\", \"ZN\", \"GA\", \"GE\", \"AS\", \"SE\", \"BR\", \n \t\t\t\t\"KR\", \"RB\", \"SR\", \"Y\", \"ZR\", \"NB\", \"MO\", \"TC\", \"RU\", \"RH\", \"PD\", \n \t\t\t\t\"AG\", \"CD\", \"IN\", \"SN\", \"SB\", \"TE\", \"I\", \"XE\", \"CS\", \"BA\", \"LA\", \n \t\t\t\t\"CE\", \"PR\", \"ND\", \"PM\", \"SM\", \"EU\", \"GD\", \"TB\", \"DY\", \"HO\", \"ER\", \n \t\t\t\t\"TM\", \"YB\", \"LU\", \"HF\", \"TA\", \"W\", \"RE\", \"OS\", \"IR\", \"PT\", \"AU\", \n \t\t\t\t\"HG\", \"TL\", \"PB\", \"BI\", \"PO\", \"AT\", \"RN\", \"FR\", \"RA\", \"AC\", \"TH\", \n \t\t\t\t\"PA\", \"U\", \"NP\", \"PU\", \"AM\", \"CM\", \"BK\", \"CF\", \"ES\", \"FM\", \"MD\", \n \t\t\t\t\"NO\", \"LR\", \"RF\", \"DB\", \"SG\", \"BH\", \"HS\", \"MT\", \"DS\", \"RG\", \"CN\",\n \t\t\t\t\"NH\", \"FL\", \"MC\", \"LV\", \"TS\", \"OG\"};\n \t\t\n \t\tfor (int i = 0; i < checklist.length; i++) {\n \t\t\tif (s.equals(checklist[i])){\n \t\t\t\tres = true;\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n \t\t\n \t\treturn res;\n \t}\n \t\n \tpublic static void main(String[] args) throws Exception {\n \t\tFastScanner cin = new FastScanner(System.in);\n \t\tString str = cin.nextLine();\n \t\t\n \t\tboolean res= test(str);\n \t\t\n \t\tif (res){\n \t\t\tSystem.out.println(\"YES\");\n \t\t} else{\n \t\t\tSystem.out.println(\"NO\");\n \t\t}\n \t\t\n \t\t\n \t}\n \n \tstatic class FastScanner {\n \t\tprivate BufferedReader reader = null;\n \t\tprivate StringTokenizer tokenizer = null;\n \n \t\tpublic FastScanner(InputStream in) {\n \t\t\treader = new BufferedReader(new InputStreamReader(in));\n \t\t\ttokenizer = null;\n \t\t}\n \n \t\tpublic String next() {\n \t\t\tif (tokenizer == null || !tokenizer.hasMoreTokens()) {\n \t\t\t\ttry {\n \t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n \t\t\t\t} catch (IOException e) {\n \t\t\t\t\tthrow new RuntimeException(e);\n \t\t\t\t}\n \t\t\t}\n \t\t\treturn tokenizer.nextToken();\n \t\t}\n \n \t\tpublic String nextLine() {\n \t\t\tif (tokenizer == null || !tokenizer.hasMoreTokens()) {\n \t\t\t\ttry {\n \t\t\t\t\treturn reader.readLine();\n \t\t\t\t} catch (IOException e) {\n \t\t\t\t\tthrow new RuntimeException(e);\n \t\t\t\t}\n \t\t\t}\n \n \t\t\treturn tokenizer.nextToken(\"\\n\");\n \t\t}\n \n \t\tpublic long nextLong() {\n \t\t\treturn Long.parseLong(next());\n \t\t}\n \n \t\tpublic int nextInt() {\n \t\t\treturn Integer.parseInt(next());\n \t\t}\n \n \t}\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "355035f5e0f0821e376ec891caeea948", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n\tpublic static void main(String[] args){\n\t\tFastScanner scan = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\ta = scan.nextInt(); b = scan.nextInt(); h = scan.nextInt(); w = scan.nextInt(); n = scan.nextInt();\n\t\tx = scan.nextIntArray(n);\n\t\tArrays.sort(x);\n\t\tint[] t = new int[n];\n\t\tfor(int i = 0; i < n; i++) t[i] = x[n-i-1];\n\t\tx = t;\n\t\tdp = new Integer[40][100010];\n\t\tint res = go(0, h, w);\n\t\tout.println(res >= 0x3f3f3f3f?-1:res);\n\t\tout.close();\n\t}\n\t\n\tstatic int a, b, h, w, n, x[];\n\tstatic Integer[][] dp;\n\t\n\tstatic int go(int at, int u, int v){\n\t\tif(u >= a && v >= b || u >= b && v >= a)return at;\n\t\tif(at > 35 || at == n) return 0x3f3f3f3f;\n\t\tif(u > 100000) u = 100000;\n\t\tif(v > 100000) v = 100000;\n\t\tif(dp[at][u] != null) return dp[at][u];\n\t\tint res = 0x3f3f3f3f;\n\t\tres = Math.min(res, go(at+1, u*x[at], v));\n\t\tres = Math.min(res, go(at+1, u, v*x[at]));\n\t\treturn dp[at][u] = res;\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\ttry\t{\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e){e.printStackTrace();}\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif (st.hasMoreTokens())\treturn st.nextToken();\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() {return Long.parseLong(next());}\n\n\t\tpublic double nextDouble() {return Double.parseDouble(next());}\n\n\t\tpublic String nextLine() {\n\t\t\tString line = \"\";\n\t\t\tif(st.hasMoreTokens()) line = st.nextToken();\n\t\t\telse try {return br.readLine();}catch(IOException e){e.printStackTrace();}\n\t\t\twhile(st.hasMoreTokens()) line += \" \"+st.nextToken();\n\t\t\treturn line;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n){\n\t\t\tlong[] a = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int n){\n\t\t\tdouble[] a = new double[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextDouble();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic char[][] nextGrid(int n, int m){\n\t\t\tchar[][] grid = new char[n][m];\n\t\t\tfor(int i = 0; i < n; i++) grid[i] = next().toCharArray();\n\t\t\treturn grid;\n\t\t}\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eafe055eb1e5ff14b52b7cf31c74ef6f", "src_uid": "18cb436618b2b85c3f5dc348c80882d5", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author 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 _799D solver = new _799D();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class _799D {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int a = in.nextInt();\n int b = in.nextInt();\n\n int h = in.nextInt();\n int w = in.nextInt();\n\n int n = in.nextInt();\n\n Integer[] ar = new Integer[n];\n\n for (int i = 0; i < n; i++)\n ar[i] = in.nextInt();\n\n Arrays.sort(ar, (x, y) -> y - x);\n\n int max = Math.max(a, b);\n\n int[][] dp = new int[41][max + 1];\n\n for (int i = h; i >= 0; i--) {\n dp[0][i] = w;\n }\n\n// for (int i = w; i >= 0; i--) {\n// dp[0][i] = Math.max(dp[0][i], h);\n// }\n\n if (dp[0][a] >= b || dp[0][b] >= a) {\n out.println(0);\n return;\n }\n\n for (int i = 1; i <= Math.min(n, 40); i++) {\n\n int num = ar[i - 1];\n for (int j = 0; j <= max; j++) {\n dp[i][Math.min(num * j, max)] = Math.max(dp[i][Math.min(num * j, max)], dp[i - 1][j]);\n }\n\n for (int j = 0; j <= max; j++) {\n dp[i][j] = Math.max(dp[i][j], dp[i - 1][j] * num);\n }\n\n for (int j = max - 1; j >= 0; j--) {\n dp[i][j] = Math.max(dp[i][j], dp[i][j + 1]);\n }\n\n if (dp[i][a] >= b || dp[i][b] >= a) {\n out.println(i);\n return;\n }\n }\n\n out.println(-1);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9f9dac4aa224ba7019b4563504ba9746", "src_uid": "18cb436618b2b85c3f5dc348c80882d5", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "package checker;\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\n//author : DimonK\n\npublic class Ds {\n\t\n\tstatic int needX;\n\tstatic int needY;\n\t\n\tstatic int curX;\n\tstatic int curY;\n\t\n\tstatic int ans = Integer.MAX_VALUE;\n\t\n\tstatic Map map = new HashMap<>();\n\t\n\tstatic long[] pre;\n\t\n\tstatic List list = new ArrayList<>(10000);\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tneedX = in.nextInt();\n\t\tneedY = in.nextInt();\n\t\t\n\t\tcurX = in.nextInt();\n\t\tcurY = in.nextInt();\n\t\t\n\t\tint n = in.nextInt();\n\t\t\n\t\tpre = new long[n];\n\t\t\t\t\n\t\tfor(int i=0; i= 1) {\n\t\t\t\tpre[i] *= pre[i-1];\n\t\t\t}\n\t\t}\n\t\t\t\t\n\t\tint res = rec(curX, 0);\n\t\t\n\t\tSystem.out.println(res >= 36 ? -1 : res);\n\t\n\t\t\n\t}\n\n\tprivate static int rec(long cx, int i) {\n\t\t\n\t\tlong aval = (i == 0 ? 1 : pre[i-1]);\n\t\t\n\t\tlong cy = aval/(cx / curX);\n\t\tcy *= curY;\n\t\t\n\t\tif(i == Math.min(list.size(), 35)) {\n\t\t\treturn check(cx, cy) ? 0 : 9999;\n\t\t}\n\t\telse if(check(cx, cy)) {\n\t\t\treturn 0;\n\t\t}\n\t\telse if(map.containsKey(new Pair(cx, i))) {\n\t\t\treturn map.get(new Pair(cx, i));\n\t\t}\n\t\telse {\n\t\t\t\n\t\t\tint ans = 0;\n\t\t\tif(cx > 100_001) {\n\t\t\t\t// adding to Y axis\n\t\t\t\tans = 1 + rec(cx, i + 1);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tans = 1 + Math.min(rec(cx, i+1), rec(cx * list.get(i), i+1) ); \n\t\t\t}\n\t\t\t\n\t\t\tmap.put(new Pair(cx, i) , ans);\n\t\t\t\n\t\t\treturn ans;\n\t\t}\n\t\t\n\t}\n\n\t\n\tprivate static boolean check(long cx, long cy) {\n\t\t\n\t\treturn (cx >= needX && cy >= needY || cx >= needY && cy >= needX);\n\t\t\n\t}\n}\n\n\nclass Pair {\n\tpublic Pair(long x, long y) {\n\t\tsuper();\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t}\n\n\tlong x,y;\n\t\n\t@Override\n\tpublic boolean equals(Object obj) {\n\t\tPair p = (Pair)obj;\n\t\t\n\t\treturn p.x == x && p.y == y;\n\t}\n\t\n\t@Override\n\tpublic int hashCode() {\n\t\treturn Long.hashCode(x) % 7919 + Long.hashCode(y) ;\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fb4165e08b65507309116f318befdb32", "src_uid": "18cb436618b2b85c3f5dc348c80882d5", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\n/**\n * Created by huang on 17-5-29.\n */\npublic class Main {\n private static int ans = 0, n = 0;\n private static void dfs(int x, int y, int num, Integer[] Ai) {\n if (num > n) {\n return;\n }\n if (x == 0 && y == 0) {\n ans = Math.min(ans, num);\n return;\n }\n if (Ai[num] == 2) {\n while (x > 0) {\n x >>= 1;\n num++;\n }\n while (y > 0) {\n y >>= 1;\n num++;\n }\n dfs(x, y, num, Ai);\n return;\n }\n if (x > 0) {\n dfs(x/Ai[num], y, num+1, Ai);\n }\n if (y > 0) {\n dfs(x, y/Ai[num], num+1, Ai);\n }\n }\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int a = in.nextInt(), b = in.nextInt(), h = in.nextInt(), w = in.nextInt();\n n = in.nextInt();\n Integer[] ai = new Integer[n];\n for (int i = 0; i < n; i++) {\n ai[i] = in.nextInt();\n }\n Arrays.sort(ai, new Comparator() {\n @Override\n public int compare(Integer i1, Integer i2) {\n return i2-i1;\n }\n });\n ans = n+1;\n dfs((a-1)/h, (b-1)/w, 0, ai);\n dfs((b-1)/h, (a-1)/w, 0, ai);\n System.out.println(ans == n+1 ? -1:ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8208ee6f292a62400de07f47186c3d6c", "src_uid": "18cb436618b2b85c3f5dc348c80882d5", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "package ee.hacker.codeforces13;\n\nimport java.util.Scanner;\n\n/**\n * Codeforces 13. Problem A\n * \n * @author Aleksandr Nikiforov\n */\npublic class ProblemA {\n\n public static void main(String[] args) {\n ProblemA problem = new ProblemA();\n problem.solve();\n }\n\n private void solve() {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int total = 0;\n for (int base = 2; base < a; base++) {\n total += digitSum(a, base);\n }\n int d = gcd(total, a - 2);\n total /= d;\n System.out.println(total + \"/\" + (a - 2) / d);\n }\n\n private int gcd(int a, int b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n private int digitSum(int n, int base) {\n int ret = 0;\n while (n != 0) {\n ret += (n % base);\n n /= base;\n }\n return ret;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe209a92437d88131175faf056e8cb88", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "package CodeForces;\nimport java.math.*;\nimport java.io.*;\n\n\npublic class nambers {\n\tstatic private int sum(int A,int so){\n\t\tint res=0;\n\t\tint chislo=A;\n\t\tint ostatok=0;\t\t\n\t\twhile(chislo>=so){\n\t\t\tostatok=chislo%so;\n\t\t\tchislo=chislo/so;\n\t\t\tres+=ostatok;\n\t\t};\n\t\tres+=chislo;\n\t\treturn res;\n\t\t\n\t}; \n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tBufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tint A=Integer.valueOf(input.readLine());\n\t\tint summa=0;\n\t\tint k=A-2;\n\t\tfor(int i=2;i<=A-1;i++){\n\t\t\tsumma+=sum(A,i);\n\t\t\t\n\t\t};\n\t\n\tint min=Math.min(summa,k);\n\t\n\t\n\tint[]mnogitel=new int [min];\n\tfor(int i=1;i beauty = new ArrayList<>();\n ArrayList beautyOrder = new ArrayList<>();\n ArrayList beautyOrig = new ArrayList<>();\n readSortQualities(beauty, beautyOrder, beautyOrig, sc, n);\n\n ArrayList intellect = new ArrayList<>();\n ArrayList intellectOrder = new ArrayList<>();\n ArrayList intellectOrig = new ArrayList<>();\n readSortQualities(intellect, intellectOrder, intellectOrig, sc, n);\n\n ArrayList richness = new ArrayList<>();\n ArrayList richnessOrder = new ArrayList<>();\n ArrayList richnessOrig = new ArrayList<>();\n richnessOrig.addAll(richness);\n readSortQualities(richness, richnessOrder, richnessOrig, sc, n);\n \n String beautyStr = beautyOrder.toString();\n String intellectStr = intellectOrder.toString();\n String richnessStr = richnessOrder.toString();\n \n int murder = 0;\n \n for (int k = 0; k < n; k++){\n int i = beautyOrder.get(k);\n boolean dead = false;\n for (int l = k + 1; l < n && !dead; l++){\n int j = beautyOrder.get(l);\n if (i != j &&\n beautyStr.substring(beautyStr.indexOf(i + \"\")+1).contains(j + \"\") &&\n beautyOrig.get(i-1) < beautyOrig.get(j-1) &&\n intellectStr.substring(intellectStr.indexOf(i + \"\")+1).contains(j + \"\") &&\n intellectOrig.get(i-1) < intellectOrig.get(j-1) &&\n richnessStr.substring(richnessStr.indexOf(i + \"\")+1).contains(j + \"\") &&\n richnessOrig.get(i-1) < richnessOrig.get(j-1)){\n dead = true;\n murder ++;\n }\n }\n }\n \n System.out.println(murder);\n \n sc.close();\n }\n \n void readSortQualities (ArrayList quality, ArrayList qualityOrder,\n ArrayList qualityOrig, Scanner sc, int n){\n int q = sc.nextInt();\n qualityOrig.add(q);\n quality.add(q);\n qualityOrder.add(1);\n for (int i = 1; i < n; i++){\n q = sc.nextInt();\n qualityOrig.add(q);\n if (quality.get(0) >= q){\n quality.add(0, q);\n qualityOrder.add(0, i+1);\n }\n else if (quality.get(quality.size() - 1) < q){\n quality.add(q);\n qualityOrder.add(i+1);\n }\n else {\n boolean added = false;\n for (int j = 1; j < quality.size() && !added; j++){\n if (quality.get(j) >= q){\n added = true;\n quality.add(j, q);\n qualityOrder.add(j, i+1);\n }\n }\n }\n }\n }\n \n \n public static void main (String[]args){\n new P12D();\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8af72dff8afb0e53d3f8e405518515c5", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\npublic class Numbers {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = n;\n int x = 0;\n int y = n - 2;\n for(int i=2; i= i) {\n x += k % i;\n }\n x += k;\n k = n;\n }\n System.out.println(k + \"/\" + y);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63196a2d646952adb006530cbc7f7de1", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n \n \n{\n \n static Scanner in = new Scanner(System.in);\n public static void solve()\n {\n \n \n int n=in.nextInt();long t=in.nextLong();\n int[] a = new int[n];\n long sum =0;\n int max=0;\n int pos=0;\n List ls = new ArrayList<>();\n List ls1 = new ArrayList<>();\n for(int i=0;i0 && t>0;i--)\n {\n if(ls1.get(i)==ls1.get(i-1))\n {\n cnt++;\n }\n else\n {\n \n int ele=ls1.get(i);\n \n int loc=ls.indexOf(ele);\n \n \n if(ans[loc]0){\n for(int j=0;j1)\n {\n if(ans[loc]0){\n for(int j=0;j0 && a[0]>=ans[0]+t)\n {\n ans[0]+=t;\n t=0;\n }\n else{ \n if(t>0 && ls1.get(0)!=ls1.get(1) && a[loc]>=ans[loc]+t)\n {\n ans[loc]+=t;\n t=0;\n }\n }\n if(t==0){\n for(int i=0;i0)\n\t\t{\n\t\t \n\t\t solve();\n\t\t t--;\n\t\t}\n\t\t\n\t\t\n\t\n\t//\tSystem.out.println(x);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b8b46a9bee90d4c8c129cb482b0750ff", "src_uid": "5d3bb9e03f4c5c8ecb6233bd5f90f3a3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class Codeforces {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt(), w = scan.nextInt();\n\t\tNode[] node = new Node[n];\n\t\tlong sum = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tint a = scan.nextInt();\n\t\t\tnode[i] = new Node(i, a, (a+1)/2);\n\t\t\tsum += node[i].b;\n\t\t}\n\t\tif(w < sum){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tw -= sum;\n\t\tArrays.sort(node, new CompByA());\n\t\twhile(w > 0){\n\t\t\tfor(int i = n-w; i < n; i++){\n\t\t\t\tnode[i].b++;\n\t\t\t\tw--;\n\t\t\t}\n\t\t}\n\t\tArrays.sort(node, new CompByIndex());\n\t\tfor(int i = 0; i < n; i++) System.out.println(node[i].b);\n\t}\n\t\n\tstatic class CompByIndex implements Comparator{\n\t\t@Override\n\t\tpublic int compare(Node e, Node f){\n\t\t\treturn e.index - f.index;\n\t\t}\n\t}\n\tstatic class CompByA implements Comparator{\n\t\t@Override\n\t\tpublic int compare(Node e, Node f) {\n\t\t\treturn e.a - f.a;\n\t\t}\t\t\n\t}\n\t\n\tstatic class Node{\n\t\tint a;\n\t\tint b;\n\t\tint index;\n\t\tpublic Node(int i, int e, int f){\n\t\t\tindex = i;\n\t\t\ta = e;\n\t\t\tb = f;\n\t\t}\n\t}\t\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f06ca6f613ff9972af58ec39fdaa6af5", "src_uid": "5d3bb9e03f4c5c8ecb6233bd5f90f3a3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "package test;\n\nimport java.util.*;\n\npublic class solution\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint w = s.nextInt();\n\t\tm[] a = new m[n];\n\t\t\n\t\tint sum=0;\n\t\t//int[] ans = new int[n];\n\t\tfor(int g=0;g(){\n\t\t\t\tpublic int compare(m o1, m o2) {\n\t\t\t\t\treturn o1.f-o2.f;\n\t\t\t\t}\n\t\t\t});\n\t\t\tint g=n-1;\n\t\t\twhile(true)\n\t\t\t{\n\t\t\t\tint temp=Math.min(a[g].f-a[g].h,w);\n\t\t\t\ta[g].h+=Math.min(a[g].f-a[g].h,w);\n\t\t\t\tw-=temp;\n\t\t\t\tif(w==0)\n\t\t\t\t\tbreak;\n\t\t\t\tg--;\n\t\t\t}\n\t\t}\n\t\tint[] ans = new int[n];\n\t\tfor(int h=0;h=0; i++) {\n\t\t\tb[i]=i;\n\t\t\ta[i] = in.nextInt();\n\t\t\tint halfCapacity = (a[i]+1)/2; \n\t\t\tw=w-halfCapacity; //deducting\n\t\t\tc[i]=halfCapacity; //pouring\n\t\t\tsumRemainingCapacity += a[i]-halfCapacity; //remaining\n\t\t\tif (min > a[i]) {\n\t\t\t\tmin = a[i];\n\t\t\t}\n\t\t}\n\t\tif(w<0 || sumRemainingCapacity < w){\n\t\t\tSystem.out.println(-1);\n\t\t}else{\n\t\t\t//w is remaining tea in tea pot which should be porured completely\n\t\t\tArrays.sort(b, new Comparator() {\n\t\t\t\tpublic int compare(Integer i, Integer j){\n\t\t\t\t\treturn a[j]-a[i];\n\t\t\t\t}\n\t\t\t});\n\t\t\tint remaining = a[b[0]]-c[b[0]];\n\t\t\tif(remaining>=w){\n\t\t\t\tc[b[0]]+=w;\n\t\t\t\tw=0;\n\t\t\t}else{\n\t\t\t\tc[b[0]]+=remaining;\n\t\t\t\tw=w-remaining;\n\t\t\t}\n\t\t\tfor(int i=0;i0;i++){\n\t\t\t\tremaining = a[b[i]]-c[b[i]];\n\t\t\t\tint maxCanbeFilled = c[b[i-1]]-c[b[i]];\n\t\t\t\tif(maxCanbeFilled>0){\n\t\t\t\t\tif(remaining>=w){\n\t\t\t\t\t\t//To be filled w\n\t\t\t\t\t\tif(w<=maxCanbeFilled){\n\t\t\t\t\t\t\tc[b[i]]+=w;\n\t\t\t\t\t\t\tw=0;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tc[b[i]]+=maxCanbeFilled;\n\t\t\t\t\t\t\tw=w-maxCanbeFilled;\n\t\t\t\t\t\t}\n\t\t\t\t\t}else{\n\t\t\t\t\t\t//To be filled is remaining\n\t\t\t\t\t\tif(remaining<=maxCanbeFilled){\n\t\t\t\t\t\t\tc[b[i]]+=remaining;\n\t\t\t\t\t\t\tw=w-remaining;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tc[b[i]]+=maxCanbeFilled;\n\t\t\t\t\t\t\tw=w-maxCanbeFilled;\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(w!=0){\n\t\t\t\tSystem.out.println(-1);\n\t\t\t}else{\n\t\t\t\tprintArray(c);\n\t\t\t}\n\t\t}\n\t\tin.close();\n\n\t}\n\tpublic static void printArray(int a[]){\n\t\tfor(int i = 0 ; i< a.length; i++){\n\t\t\tSystem.out.print(a[i]+\" \");\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c719b022c68daf6d7ba00c3564ca2fa", "src_uid": "5d3bb9e03f4c5c8ecb6233bd5f90f3a3", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author teacher\n */\npublic class Chess2 {\n\n static boolean b[][];\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String lad = in.nextLine();\n String kon = in.nextLine();\n b = new boolean[8][8];\n int xlad = lad.charAt(0) - 'a';\n int ylad = lad.charAt(1) - '1';\n b[xlad][ylad] = true;\n int xkon = kon.charAt(0) - 'a';\n int ykon = kon.charAt(1) - '1';\n b[xkon][ykon] = true;\n\n boolean pos[][] = new boolean[8][8];\n pos[xkon][ykon] = true;\n for (int i = 0; i < 8; i++) {\n pos[xlad][i] = true;\n pos[i][ylad] = true;\n }\n\n if (ykon + 2 < 8) {\n if (xkon + 1 < 8) {\n pos[ykon + 2][xkon + 1] = true;\n }\n if (xkon - 1 >= 0) {\n pos[ykon + 2][xkon - 1] = true;\n }\n }\n if (ykon - 2 >= 0) {\n if (xkon + 1 < 8) {\n pos[ykon - 2][xkon + 1] = true;\n }\n if (xkon - 1 >= 0) {\n pos[ykon - 2][xkon - 1] = true;\n }\n }\n if (ykon + 1 < 8) {\n if (xkon + 2 < 8) {\n pos[ykon + 1][xkon + 2] = true;\n }\n if (xkon - 2 >= 0) {\n pos[ykon + 1][xkon - 2] = true;\n }\n }\n if (ykon - 1 >= 0) {\n if (xkon + 2 < 8) {\n pos[ykon - 1][xkon + 2] = true;\n }\n if (xkon - 2 >= 0) {\n pos[ykon - 1][xkon - 2] = true;\n }\n }\n int count = 64;\n for (int i = 0; i < 8; i++) {\n for (int j = 0; j < 8; j++) {\n if(!pos[i][j]){\n if(checkHorse(i,j)){\n count--;\n }\n }else {\n count--;\n }\n }\n }\n\n System.out.println(count);\n }\n\n static boolean checkHorse(int xkon, int ykon) {\n\n if (ykon + 2 < 8 && xkon + 1 < 8 && b[ykon + 2][xkon + 1]) {\n return true;\n } else if (ykon + 2 < 8 && xkon - 1 >= 0 && b[ykon + 2][xkon - 1]) {\n return true;\n } else if (ykon - 2 >= 0 && xkon + 1 < 8 && b[ykon - 2][xkon + 1]) {\n return true;\n } else if (ykon - 2 >= 0 && xkon - 1 >= 0 && b[ykon - 2][xkon - 1]) {\n return true;\n } else if (ykon + 1 < 8 && xkon + 2 < 8 && b[ykon + 1][xkon + 2]) {\n return true;\n } else if (ykon + 1 < 8 && xkon - 2 >= 0 && b[ykon + 1][xkon - 2]) {\n return true;\n } else if (ykon - 1 >= 0 && xkon + 2 < 8 && b[ykon - 1][xkon + 2]) {\n return true;\n } else if (ykon - 1 >= 0 && xkon - 2 >= 0 && b[ykon - 1][xkon - 2]) {\n return true;\n }\n\n return false;\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "317560570ffbe5851ccc07c418e366a0", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class B38 {\n\tprivate static long mod = 1000000007;\n\t\n\tpublic static void main(String[] args) {\n\t\tInputReader in=new InputReader(System.in);\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\n\t\n\t\tint[][] cb=new int[9][9];\n\t\t\n\t\tString rk=in.nextLine();\n\t\tString kn=in.nextLine();\n\t\t\n\t\tint rk_r=(int)rk.charAt(0)-'a'+1;\n\t\tint rk_c=(int)rk.charAt(1)-'0';\n\t\tint kn_r=(int)kn.charAt(0)-'a'+1;\n\t\tint kn_c=(int)kn.charAt(1)-'0';\n\t\n\t\t\n\t\t//pw.print(rk_c+\" \"+rk_r+\" \"+kn_c+\" \"+kn_r);\n\t\n\t\tfor(int i=1;i<=8;i++) {\n\t\t\tcb[rk_r][i]=1;\n\t\t\tcb[i][rk_c]=1;\n\t\t}\n\t/*\tfor(int k=1;k<=8;k++) {\n\t\t\tfor(int l=1;l<=8;l++)\n\t\t\t\tpw.print(cb[k][l]);\n\t\t\tpw.println();\n\t\t\n\t\t}\n*/\n\t\tint i=rk_r;\n\t\tint j=rk_c;\n\t\tif((i+2)<=8 && (j-1)<=8 && (i+2)>=1 && (j-1)>=1)\n\t\t\tcb[i+2][j-1]=1;\n\t\tif((i+2)<=8 && (j+1)<=8 && (i+2)>=1 && (j+1)>=1)\n\t\t\tcb[i+2][j+1]=1;\n\t\tif((i-2)<=8 && (j-1)<=8 && (i-2)>=1 && (j-1)>=1)\n\t\t\tcb[i-2][j-1]=1;\n\t\tif((i-2)<=8 && (j+1)<=8 && (i-2)>=1 && (j+1)>=1)\n\t\t\tcb[i-2][j+1]=1;\n\t\tif((i+1)<=8 && (j-2)<=8 && (i+1)>=1 && (j-2)>=1)\n\t\t\tcb[i+1][j-2]=1;\n\t\tif((i+1)<=8 && (j+2)<=8 && (i+1)>=1 && (j+2)>=1)\n\t\t\tcb[i+1][j+2]=1;\n\t\tif((i-1)<=8 && (j-2)<=8 && (i-1)>=1 && (j-2)>=1)\n\t\t\tcb[i-1][j-2]=1;\n\t\tif((i-1)<=8 && (j+2)<=8 && (i-1)>=1 && (j-2)>=1)\n\t\t\tcb[i-1][j+2]=1;\n\t\t\n\t\t\n\t\ti=kn_r;\n\t\tj=kn_c;\n\t\tif((i+2)<=8 && (j-1)<=8 && (i+2)>=1 && (j-1)>=1)\n\t\t\tcb[i+2][j-1]=1;\n\t\tif((i+2)<=8 && (j+1)<=8 && (i+2)>=1 && (j+1)>=1)\n\t\t\tcb[i+2][j+1]=1;\n\t\tif((i-2)<=8 && (j-1)<=8 && (i-2)>=1 && (j-1)>=1)\n\t\t\tcb[i-2][j-1]=1;\n\t\tif((i-2)<=8 && (j+1)<=8 && (i-2)>=1 && (j+1)>=1)\n\t\t\tcb[i-2][j+1]=1;\n\t\tif((i+1)<=8 && (j-2)<=8 && (i+1)>=1 && (j-2)>=1)\n\t\t\tcb[i+1][j-2]=1;\n\t\tif((i+1)<=8 && (j+2)<=8 && (i+1)>=1 && (j+2)>=1)\n\t\t\tcb[i+1][j+2]=1;\n\t\tif((i-1)<=8 && (j-2)<=8 && (i-1)>=1 && (j-2)>=1)\n\t\t\tcb[i-1][j-2]=1;\n\t\tif((i-1)<=8 && (j+2)<=8 && (i-1)>=1 && (j+2)>=1)\n\t\t\tcb[i-1][j+2]=1;\n\t\t\n\t\tcb[kn_r][kn_c]=1;\n\t\tint count=0;\n\t\tfor(int k=1;k<=8;k++) {\n\t\t\tfor(int l=1;l<=8;l++) {\n\t\t\t\t//pw.print(cb[k][l]);\n\t\t\tif(cb[k][l]==0)\n\t\t\t\tcount++;\n\t\t\t}\n\t\t//pw.println();\n\t\t}\n\t\t\n\t\tpw.println(count);\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\t\n\tstatic class InputReader {\n\t\t \n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\t\tprivate SpaceCharFilter filter;\n \n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong a[] = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextLong();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t\tpublic String readString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\n\tpublic static int[] suffle(int[] a,Random gen)\n\t{\n\t\tint n = a.length;\n\t\tfor(int i=0;i primeFactorization(int n)\n\t{\n\t\tArrayList a =new ArrayList();\n\t\tfor(int i=2;i*i<=n;i++)\n\t\t{\n\t\t\twhile(n%i==0)\n\t\t\t{\n\t\t\t\ta.add(i);\n\t\t\t\tn/=i;\n\t\t\t}\n\t\t}\n\t\tif(n!=1)\n\t\t\ta.add(n);\n\t\treturn a;\n\t}\n\t\n\tpublic static void sieve(boolean[] isPrime,int n)\n\t{\n\t\tfor(int i=1;i0)\n\t {\n\t if(n % 2 ==1)\n\t result=result * x;\n\t x=x*x;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static long binaryExponentiation(long x,long n)\n\t{\n\t long result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=result * x;\n\t x=x*x;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static int modularExponentiation(int x,int n,int M)\n\t{\n\t int result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=(result * x)%M;\n\t x=(x*x)%M;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static long modularExponentiation(long x,long n,long M)\n\t{\n\t long result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=(result * x)%M;\n\t x=(x*x)%M;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static int modInverse(int A,int M)\n\t{\n\t return modularExponentiation(A,M-2,M);\n\t}\n\t\n\tpublic static long modInverse(long A,long M)\n\t{\n\t return modularExponentiation(A,M-2,M);\n\t}\n\t\n\tpublic static boolean isPrime(int n)\n\t{\n\t \n\t if (n <= 1) return false;\n\t if (n <= 3) return true;\n\t \n\t if (n%2 == 0 || n%3 == 0) \n\t \treturn false;\n\t \n\t for (int i=5; i*i<=n; i=i+6)\n\t {\n\t if (n%i == 0 || n%(i+2) == 0)\n\t return false;\n\t }\n\t \n\t return true;\n\t}\n\t\n\tstatic class pair implements Comparable\n\t{\n\t\tInteger x, y;\n\t\tpair(int x,int y)\n\t\t{\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t\t\n\t\tpublic int compareTo(pair o) {\n\t\t\tint result = x.compareTo(o.x);\n\t\t\tif(result==0)\n\t\t\t\tresult = y.compareTo(o.y);\n\t\t\t\n\t\t\treturn result;\n\t\t} \n\t}\n}\n\n\t\t", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4e93997b8d1832d0190d817723cba75", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class Chess {\n\t\n\tstatic int board[][];\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint ways = 0;\n\t\tboard = new int[8][8];\n\t\tString temp = br.readLine();\n\t\tint ri = temp.charAt(0) - 'a';\n\t\tint rj = Integer.parseInt(temp.charAt(1)+\"\") - 1;\n\t\tboard[ri][rj] = 'R';\n\t\ttemp = br.readLine();\n\t\tint ki = temp.charAt(0) - 'a';\n\t\tint kj = Integer.parseInt(temp.charAt(1)+\"\") - 1;\n\t\tboard[ki][kj] = 'K';\n\t\t\n\t\tfor (int i=0;i<8;i++) {\n\t\t\tfor (int j=0;j<8;j++) {\n\t\t\t\tif (i==ri && j==rj)\n\t\t\t\t\tcontinue;\n\t\t\t\tif (i==ki && j==kj)\n\t\t\t\t\tcontinue;\n\t\t\t\tif (i==ri || j==rj) \n\t\t\t\t\tcontinue;\n\t\t\t\tif ((i==ki-1 && (j==kj+2 || j==kj-2)) || (i==ki+1 && (j==kj+2 || j==kj-2)) || (i==ki-2 && (j==kj+1 || j==kj-1)) || (i==ki+2 && (j==kj-1 || j==kj+1)))\n\t\t\t\t\tcontinue;\n\t\t\t\tways++;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(ways-2);\n\t\t\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ff56cb9cd5212cb0de76ae4e32e45b7", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Zyflair Griffane\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tPandaScanner in = new PandaScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tB solver = new B();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass B {\n final int[] dx = { -2, -2, -1, 1, 2, 2, 1, -2 };\n final int[] dy = { -1, 1, 2, 2, 1, -1, -2, -2 };\n public void solve(int testNumber, PandaScanner in, PrintWriter out) {\n int[] rook = coordinates(in.next());\n int[] knight = coordinates(in.next());\n int[][] pieces = new int[][] { knight, rook };\n boolean[][] cant = new boolean[8][8];\n for (int[] piece: pieces) {\n int x = piece[0];\n int y = piece[1];\n cant[x][y] = true;\n for (int d = 0; d < dx.length; d++) {\n int nx = x + dx[d];\n int ny = y + dy[d];\n if (Math.min(nx, ny) >= 0 && Math.max(nx, ny) < 8) {\n cant[nx][ny] = true;\n }\n }\n }\n int res = 0;\n for (int i = 0; i < 8; i++) {\n for (int j = 0; j < 8; j++) {\n if (!cant[i][j] && i != rook[0] && j != rook[1]) {\n res++;\n }\n }\n }\n out.println(res);\n }\n int[] coordinates(String str) {\n char[] c = str.toCharArray();\n return new int[] { c[0] - 'a', c[1] - '1' };\n }\n}\n\nclass PandaScanner {\n public BufferedReader br;\n public StringTokenizer st;\n public InputStream in;\n\n public PandaScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(this.in = in));\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n }\n catch (Exception e) {\n return null;\n }\n }\n\n public String next() {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine().trim());\n return next();\n }\n return st.nextToken();\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe1cf8b04d4311078ecbbf2381774c6d", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class XorMST {\n \n int N = 40;\n long[] dp = new long[N];\n \n void solve() {\n long n = in.nextInt();\n \n long[] p2 = new long[N];\n p2[0] = 1;\n for (int i = 1; i < N; i++) p2[i] = 2 * p2[i - 1];\n \n dp[1] = 1;\n for (int i = 2; i < N; i++) dp[i] = 2 * dp[i - 1] + p2[i - 1];\n \n long ans = 0;\n while (n > 0) {\n long l = Long.highestOneBit(n), r = n ^ l;\n int bits = Long.numberOfTrailingZeros(l);\n ans += dp[bits];\n if (r > 0) ans += p2[bits];\n n = r;\n }\n out.println(ans);\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new XorMST().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "efc67e9f0f015968e72832787be50849", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class cfs473E {\n\n public static void main(String[] args) {\n FastScanner sc = new FastScanner();\n StringBuilder sb = new StringBuilder();\n long n = sc.nextInt();\n ArrayList costs = new ArrayList();\n long currNodes = 0;\n long currCost = 0;\n long currPower = 1;\n sb.append(sumSection(0L, 0L, n));\n System.out.print(sb);\n }\n public static long sumSection(long currCost, long connectionCost, long remaining) {\n if (remaining == 0) return currCost;\n currCost += connectionCost;\n long addedCost = 0L;\n long currNodes = 1L;\n while (currNodes<<1 <= remaining) { // get floor power.\n addedCost = addedCost*2 + currNodes;\n currNodes <<= 1;\n }\n currCost += addedCost;\n return sumSection(currCost, currNodes, remaining - currNodes);\n }\n\n public static class Pair {\n long edges, cost;\n public Pair(long edges, long cost) {\n this.edges = edges;\n this.cost = cost;\n }\n }\n\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(Reader in) {\n br = new BufferedReader(in);\n }\n\n public FastScanner() {\n this(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String readNextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n int[] readIntArray(int n) {\n int[] a = new int[n];\n for (int idx = 0; idx < n; idx++) {\n a[idx] = nextInt();\n }\n return a;\n }\n\n long[] readLongArray(int n) {\n long[] a = new long[n];\n for (int idx = 0; idx < n; idx++) {\n a[idx] = nextLong();\n }\n return a;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e12fec8a2fb49abd9ffe387298206a00", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\n/**\n * @author: Mehul Raheja\n */\nimport java.util.*;\nimport java.io.*;\n\npublic class E {\n\n /*\n Runtime = O()\n */\n static int N, M, K;\n static String s;\n static StringTokenizer st;\n static int[] d;\n\n static long ans = 0;\n \n static void dis(long N) {\n if(N == 1){\n return;\n }\n long low = 1<< ((long)((Math.log(N-0.1))/Math.log(2)));\n ans += low;\n dis(low);\n dis(N-low);\n }\n\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long N = Long.parseLong(br.readLine());\n dis(N);\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9da15447ed03c56ab326de0c84b4d711", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class MinXorMst {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextLong();\n\t\tint cost = 0;\n\t\t//System.out.println(\"Calculating\");\n\t\tfor(long i=1;i= x){\n\t\t\t\t//System.out.println(x);\n\t\t\t\tN-=x;\n\t\t\t\tx+=i+1;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\ti--;\n\t\t\tSystem.out.print(i);\n\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b49171defc70eec6b59441edf471d12d", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Next\n{\n\tpublic static void main(String args[])\n\t{\n\t\tint s=0,l=0,a=0;\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\twhile(true)\n\t\t{\n\t\t\tl=0;\n\t\t\ta++;\n\t\t\tl=(a*(a+1))/2;\n\t\t\ts=s+l;\n\t\t\tif(n/s==1)\n\t\t\t{\n\t\t\t\tSystem.out.print(a);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c9d1547e3af295c6b6c493ced3f01f0f", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Next\n{\n\tpublic static void main(String args[])\n\t{\n\t\tint s=0,l=0,a=0;\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\twhile(true)\n\t\t{\n\t\t\tl=0;\n\t\t\ta++;\n\t\t\tfor(int i=1;i<=a;i++)\n\t\t {\n\t\t\t l=l+i;\n\t\t }\n\t\t\ts=s+l;\n\t\t\tif(n/s==1)\n\t\t\t{\n\t\t\t\tSystem.out.print(a);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f7cf07dae2df72c75379726da932246b", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class JavaApplication191 {\n\n public static void main(String[] args) {\n Scanner reader = new Scanner(System.in);\n int input=reader.nextInt();\n \n int sum=0;\n int i = 1;\n int height = 1; \n boolean flag = false;\n boolean decrease=false;\n while (true)\n {\n \n for ( ;i<=height;i++)\n {\n \n for (int j =i ; j>=0;j--)\n {\n sum+=j;\n if (sum==input)\n { \n if(j-1>0)decrease=true;\n flag=true;\n break;\n }\n \n }\n if (flag)break;\n }\n if (flag)break;\n height++;\n }\n if (decrease){height=height-1;}\n System.out.println(height);\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24cda8eae45a1dc86d8095a5985a308e", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0} {"lang": "Java 7", "source_code": "package CodeForce;\n\nimport java.io.IOException;\nimport java.util.Scanner;\n\npublic class Game {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString str = sc.nextLine(); \n\t\tString[] nm = str.split(\" \");\n\t\tint n1 = Integer.parseInt(nm[0]);\n\t\tint n2 = Integer.parseInt(nm[1]);\n\t\tint k1 = Integer.parseInt(nm[2]);\n\t\tint k2 = Integer.parseInt(nm[3]);\n\t\twhile (true ){\n\t\t\tn1 --;\n\t\t\tif (n1 == 0){\n\t\t\t\tSystem.out.println(\"Second\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tn2 --;\n\t\t\tif (n2 == 0){\n\t\t\t\tSystem.out.println(\"First\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f7cf2a08702389b05b8704c278536861", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package net.crew4ok.olimp;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n private static String calc(int n1, int n2, int k1, int k2) {\n if (n1 > n2) {\n return \"First\";\n } else if (n2 > n1) {\n return \"Second\";\n } else {\n return \"Second\";\n }\n }\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n1 = scanner.nextInt();\n int n2 = scanner.nextInt();\n int k1 = scanner.nextInt();\n int k2 = scanner.nextInt();\n\n System.out.print(calc(n1, n2, k1, k2));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b753314f89bda6f465246dc1f561b3d7", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\npackage javaapplication1;\n\nimport java.util.Scanner;\n\npublic class Game {\n public static void main(String []args){\n Scanner sc = new Scanner(System.in);\n int n1 = sc.nextInt();\n int n2 = sc.nextInt();\n int k1 = sc.nextInt();\n int k2 = sc.nextInt();\n while(n1!=0||n2!=0){\n n1--; \n if(n1==0){\n System.out.println(\"Second\");\n break;\n }\n n2--;\n if(n2==0){\n System.out.println(\"First\");\n break;\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d19908aa010f9ecba3343aa283e44de", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0} {"lang": "Java 7", "source_code": "package wow;\n\nimport java.util.Scanner;\n\npublic class wow {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner scan = new Scanner(System.in);\n\t\tint firstBallMove = scan.nextInt();\n\t\tint secBallMove = scan.nextInt();\n\t\tint firstBall = scan.nextInt();\n\t\tint secBall = scan.nextInt();\n\t\t\n\t\twhile(firstBall >0 && secBall > 0)\n\t\t{\n\t\t\tfirstBall -= firstBallMove;\n\t\t\tif(firstBall <= 0)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"First\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tsecBall -= secBallMove;\n\t\t\tif(secBall <= 0)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"Second\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "71ecb5b2c542a28cf60e988925a8bc37", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Round157B {\n\n\tpublic static long mod = (long)1e9+7;\n\t\n\tpublic static void solve() {\n\t\tlong m = s.nextLong();\n\t\tM = Long.toString(m);\n\t\tlong[] sums = new long[10];\n\t\tfor(int i = 1; i <= 9; i++) {\n\t\t\tdp = new long[10][i + 1][2];\n\t\t\tfor(int j = 0; j < 10; j++) {\n\t\t\t\tfor(int k = 0; k <= i; k++) {\n\t\t\t\t\tfor(int l = 0; l < 2; l++) {\n\t\t\t\t\t\tdp[j][k][l] = -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tsums[i] = Recur(0, 0, 1);\n\t\t}\n\t\tlong[] suffix_sum = new long[10];\n\t\tsuffix_sum[9] = sums[9];\n\t\tfor(int i = 8; i >= 0; i--) {\n\t\t\tsuffix_sum[i] = suffix_sum[i + 1] + sums[i];\n\t\t}\n\t\tsums[0] = m - suffix_sum[0];\n\t\tsuffix_sum[0] = m;\n\t\tlong ans = 0;\n//\t\tfor(int i = 1; i < 10; i++) {\n//\t\t\tlong me = sums[i];\n//\t\t\tlong other = m - suffix_sum[i];\n//\t\t\tif(other < 6) {\n//\t\t\t\tcontinue;\n//\t\t\t}else {\n//\t\t\t\tlong tempans = 1;\n//\t\t\t\tfor(long j = other; j >= other - 5; j--) {\n//\t\t\t\t\ttempans = (tempans * j)%mod;\n//\t\t\t\t}\n//\t\t\t\ttempans = (tempans * me)%mod;\n//\t\t\t\tans = ans + tempans;\n//\t\t\t\tif(ans >= mod) ans -= mod;\n//\t\t\t}\n//\t\t}\n\t\tlong[][] dp2 = new long[10][10];\n\t\tfor(int i = 0; i < 10; i++) {\n\t\t\tdp2[i][0] = 1;\n\t\t\tlong val = sums[i];\n\t\t\tlong tempans = 1;\n\t\t\tfor(int j = 1; j < 10; j++) {\n\t\t\t\ttempans = (val * tempans)%mod;\n\t\t\t\tdp2[i][j] = tempans;\n\t\t\t\tval--;\n\t\t\t}\n\t\t}\n\t\tfor(int first = 1; first < 10; first++) {\n//\t\t\tint vals = 0;\n\t\t\tint[] count = new int[10];\n\t\t\tfor(int second = 0; second < first; second++) {\n\t\t\t\tfor(int third = 0; second + third < first; third++) {\n\t\t\t\t\tfor(int fourth = 0; second + third + fourth < first; fourth++) {\n\t\t\t\t\t\tfor(int fifth = 0; second + third + fourth + fifth < first; fifth++) {\n\t\t\t\t\t\t\tfor(int sixth = 0; second + third + fourth + fifth + sixth < first; sixth++) {\n\t\t\t\t\t\t\t\tfor(int seventh = 0; second + third + fourth + fifth + sixth + seventh < first; seventh++) {\n//\t\t\t\t\t\t\t\t\tvals++;\n\t\t\t\t\t\t\t\t\tcount[second]++;\n\t\t\t\t\t\t\t\t\tcount[third]++;\n\t\t\t\t\t\t\t\t\tcount[fourth]++;\n\t\t\t\t\t\t\t\t\tcount[sixth]++;\n\t\t\t\t\t\t\t\t\tcount[fifth]++;\n\t\t\t\t\t\t\t\t\tcount[seventh]++;\n\t\t\t\t\t\t\t\t\tlong tempans = sums[first];\n\t\t\t\t\t\t\t\t\tfor(int i = 0; i < first; i++) {\n\t\t\t\t\t\t\t\t\t\ttempans = tempans * dp2[i][count[i]];\n\t\t\t\t\t\t\t\t\t\ttempans %= mod;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tans += tempans;\n\t\t\t\t\t\t\t\t\tif(ans >= mod) ans -= mod;\n\t\t\t\t\t\t\t\t\tcount[second]--;\n\t\t\t\t\t\t\t\t\tcount[third]--;\n\t\t\t\t\t\t\t\t\tcount[fourth]--;\n\t\t\t\t\t\t\t\t\tcount[sixth]--;\n\t\t\t\t\t\t\t\t\tcount[fifth]--;\n\t\t\t\t\t\t\t\t\tcount[seventh]--;\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\tout.println(vals);\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\t\n\tpublic static long[][][] dp; \n\tpublic static String M;\n\t\n\tpublic static long Recur(int pos, int count, int f) {\n\t\tif(pos == M.length()) {\n\t\t\tif(count == 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif(count == dp[0].length - 1) {\n\t\t\t\treturn 1;\n\t\t\t}else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\tif(dp[pos][count][f] != -1) {\n\t\t\treturn dp[pos][count][f];\n\t\t}\n\t\tint lmtS = 0, lmtE;\n\t\tif(f == 1) {\n\t\t\tlmtE = M.charAt(pos) - '0';\n\t\t}else {\n\t\t\tlmtE = 9;\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i = lmtS; i <= lmtE; i++) {\n\t\t\tint new_count = count + ((i == 4 || i == 7) ? 1 : 0);\n\t\t\tint newf = (f == 1 && i == lmtE ? 1 : 0);\n\t\t\tans += Recur(pos + 1, new_count, newf);\n\t\t}\n\t\treturn dp[pos][count][f] = ans;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\ts = new FastReader();\n\t\tsolve();\n\t\tout.close();\n\t}\n\t\n\tpublic static class Triplet {\n\t\tlong gcd;\n\t\tlong x;\n\t\tlong y;\n\n\t\tTriplet(long gcd, long x, long y) {\n\t\t\tthis.gcd = gcd;\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t}\n\n\tpublic static Triplet ExtendedEuclideanAlgo(long a, long b) {\n\t\tif (a == 0) {\n\t\t\treturn new Triplet(b, 0, 1);\n\t\t}\n\t\tTriplet ans = ExtendedEuclideanAlgo(b % a, a);\n\t\tlong x = ans.y - (b / a) * ans.x;\n\t\tlong y = ans.x;\n\t\treturn new Triplet(ans.gcd, x, y);\n\t}\n\n\tpublic static long ModInverse(long a, long m) {\n\t\tTriplet ans = ExtendedEuclideanAlgo(a, m);\n\t\tif (ans.gcd != 1) {\n\t\t\t//System.out.println(\"Multiplicative inverse doesnot exist\");\n\t\t\treturn -1;\n\t\t} else {\n\t\t\t//m is added to handle negative x\n\t\t\tlong result = (ans.x % m + m) % m;\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tpublic static FastReader s;\n\tpublic static PrintWriter out;\n\n\tpublic static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.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());\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\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e6fd0b415e7be85e5c101d967d67260a", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.BufferedInputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.text.DecimalFormat;\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.Iterator;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\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\nimport javax.net.ssl.SSLContext;\n\npublic class Main\n{\t\n\t/********************************************** a list of common variables **********************************************/\n\tprivate MyScanner scan = new MyScanner();\n\tprivate PrintWriter out = new PrintWriter(System.out);\n\tprivate final double PI = Math.acos(-1.0);\n\tprivate final double EPS = 1e-6;\n\tprivate final int SIZEN = (int)(1e5);\n\tprivate final int MOD = (int)(1e9 + 7);\n\tprivate final long MODH = 10000000007L, BASE = 10007;\n\tprivate final int[] DX = {0, 1, 0, -1}, DY = {-1, 0, 1, 0};\n\tprivate ArrayList[] edge;\n\tprivate int bits;\n\tprivate long ans;\n\tprivate int[] d, lucky;\n\tprivate int[][] dp;\n\t\n\tpublic int getCount(int p, int x, boolean rightEqual)\n\t{\n\t\tif(-1 == p) return 0 == x ? 1 : 0;\n\t\tif(!rightEqual && dp[p][x] != -1) return dp[p][x];\n\t\tint n = rightEqual ? d[p] : 9;\n\t\tint sum = 0;\n\t\tfor(int i = 0;i <= n;++i)\n\t\t{\n\t\t\tsum += getCount(p - 1, x - (4 == i|| 7 == i ? 1 : 0), rightEqual && (i == d[p]));\n\t\t}\n\t\tif(!rightEqual) dp[p][x] = sum;\n\t\treturn sum;\n\t}\n\t\n\tpublic void dfs(int step, int sum, int cur, long tmp)\n\t{\n\t\tif(sum >= cur) return;\n\t\tif(step == 6)\n\t\t{\n\t\t\tans = (ans + tmp) % MOD;\n\t\t\treturn;\n\t\t}\n\t\tfor(int i = 0;i < cur;++i)\n\t\t{\n\t\t\tif(lucky[i] > 0)\n\t\t\t{\n\t\t\t\t--lucky[i];\n\t\t\t\tdfs(step + 1, sum + i, cur, tmp * (lucky[i] + 1) % MOD);\n\t\t\t\t++lucky[i];\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic void foo()\n\t{\n\t\tint n = scan.nextInt();\n\t\td = new int[11];\n\t\tbits = 0;\n\t\twhile(n > 0)\n\t\t{\n\t\t\td[bits++] = n % 10;\n\t\t\tn /= 10;\n\t\t}\n\t\tlucky = new int[bits + 1];\n\t\tdp = new int[bits + 1][bits + 1];\n\t\tfor(int i = 0;i <= bits;++i) Arrays.fill(dp[i], -1);\n\t\tfor(int i = 0;i <= bits;++i)\n\t\t{\n\t\t\tlucky[i] = getCount(bits - 1, i, true);\n\t\t}\n\t\t--lucky[0];\n\t\tans = 0;\n\t\tfor(int i = 1;i <= bits;++i)\n\t\t{\n\t\t\tdfs(0, 0, i, lucky[i]);\n\t\t}\n\t\tout.println(ans);\n \t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tMain m = new Main();\n\t\tm.foo();\n\t\tm.out.close();\n\t}\n\t\n\tclass Point\n\t{\n\t\tprivate int x;\n\t\tprivate int y;\n\t\tpublic Point(int aX, int aY)\n\t\t{\n\t\t\tx = aX;\n\t\t\ty = aY;\n\t\t}\n\t}\n\n\t/********************************************** a list of common algorithms **********************************************/\n\t/**\n\t * 1---Get greatest common divisor\n\t * @param a :\tfirst number\n\t * @param b :\tsecond number\n\t * @return\t\tgreatest common divisor\n\t */\n\tpublic long gcd(long a, long b)\n\t{\n\t\treturn 0 == b ? a : gcd(b, a % b);\n\t}\n\t\n\t/**\n\t * 2---Get the distance from a point to a line\n\t * @param x1\tthe x coordinate of one endpoint of the line\n\t * @param y1\tthe y coordinate of one endpoint of the line\n\t * @param x2\tthe x coordinate of the other endpoint of the line\n\t * @param y2\tthe y coordinate of the other endpoint of the line\n\t * @param x\t\tthe x coordinate of the point \n\t * @param y\t\tthe x coordinate of the point\n\t * @return\t\tthe distance from a point to a line\n\t */\n\tpublic double getDist(long x1, long y1, long x2, long y2, long x, long y)\n\t{\n\t\tlong a = y2 - y1;\n\t\tlong b = x1 - x2;\n\t\tlong c = y1 * (x2 - x1) - x1 * (y2 - y1);\n\t\treturn Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);\n\t}\n\t\n\t/**\n\t * 3---Get the distance from one point to a segment (not a line)\n\t * @param x1\tthe x coordinate of one endpoint of the segment\n\t * @param y1\tthe y coordinate of one endpoint of the segment\n\t * @param x2\tthe x coordinate of the other endpoint of the segment\n\t * @param y2\tthe y coordinate of the other endpoint of the segment\n\t * @param x\t\tthe x coordinate of the point\n\t * @param y\t\tthe y coordinate of the point\n\t * @return\t\tthe distance from one point to a segment (not a line)\n\t */\n\tpublic double ptToSeg(long x1, long y1, long x2, long y2, long x, long y)\n\t{\n\t\tdouble cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);\n\t\tif(cross <= 0)\n\t\t{\n\t\t\treturn (x - x1) * (x - x1) + (y - y1) * (y - y1);\n\t\t}\n\t\tdouble d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);\n\t\tif(cross >= d) \n\t\t{\n\t\t\treturn (x - x2) * (x - x2) + (y - y2) * (y - y2);\n\t\t}\n\t\tdouble r = cross / d;\n\t\tdouble px = x1 + (x2 - x1) * r;\n\t\tdouble py = y1 + (y2 - y1) * r;\n\t\treturn (x - px) * (x - px) + (y - py) * (y - py);\n\t}\n\t\n\t/**\n\t * 4---KMP match, i.e. kmpMatch(\"abcd\", \"bcd\") = 1, kmpMatch(\"abcd\", \"bfcd\") = -1.\n\t * @param t:\tString to match.\n\t * @param p:\tString to be matched.\n\t * @return\t\tif can match, first index; otherwise -1.\n\t */\n\tpublic int kmpMatch(char[] t, char[] p)\n\t{\n\t\tint n = t.length;\n\t\tint m = p.length;\n\t\tint[] next = new int[m + 1];\n\t\tnext[0] = -1;\n\t\tint j = -1;\n\t\tfor(int i = 1;i < m;++i)\n\t\t{\n\t\t\twhile(j >= 0 && p[i] != p[j + 1])\n\t\t\t{\n\t\t\t\tj = next[j];\n\t\t\t}\n\t\t\tif(p[i] == p[j + 1])\n\t\t\t{\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tnext[i] = j;\n\t\t}\n\t\tj = -1;\n\t\tfor(int i = 0;i < n;++i)\n\t\t{\n\t\t\twhile(j >= 0 && t[i] != p[j + 1])\n\t\t\t{\n\t\t\t\tj = next[j];\n\t\t\t}\n\t\t\tif(t[i] == p[j + 1])\n\t\t\t{\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tif(j == m - 1)\n\t\t\t{\n\t\t\t\treturn i - m + 1;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\t/**\n\t * 5---Get the hash code of a String\n\t * @param\ts:\tinput string\n\t * @return\thash code\n\t */\n\tpublic long hash(String s)\n\t{\n\t\tlong key = 0, t = 1;\n\t\tfor(int i = 0;i < s.length();++i)\n\t\t{\n\t\t\tkey = (key + s.charAt(i) * t) % MODH;\n\t\t\tt = t * BASE % MODH;\n\t\t}\n\t\treturn key;\n\t}\n\t\n\t/**\n\t * 6---Get x ^ n % MOD quickly.\n\t * @param\tx:\tbase\n\t * @param \tn:\ttimes\n\t * @return\tx ^ n % MOD\n\t */\n\tpublic long quickMod(long x, long n)\n\t{\n\t\tlong ans = 1;\n\t\twhile(n > 0)\n\t\t{\n\t\t\tif(1 == n % 2)\n\t\t\t{\n\t\t\t\tans = ans * x % MOD;\n \t\t\t}\n\t\t\tx = x * x % MOD;\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\t/**\n\t * 7---judge if a point is located inside a polygon\n\t * @param x0\tthe x coordinate of the point\n\t * @param y0\tthe y coordinate of the point\n\t * @return true if it is inside the polygon, otherwise false\n\t */\n\t/*public boolean contains(double x0, double y0)\n\t{\n\t\tint cross = 0;\n\t\tfor(int i = 0;i < n;++i)\n\t\t{\n\t\t\tdouble s = x[i + 1] == x[i] ? 100000000 : (double)(y[i + 1] - y[i]) / (x[i + 1] - x[i]);\n\t\t\tboolean b1 = x[i] <= x0 && x0 < x[i + 1];\n\t\t\tboolean b2 = x[i + 1] <= x0 && x0 < x[i];\n\t\t\tboolean b3 = y0 < s * (x0 - x[i]) + y[i];\n\t\t\tif((b1 || b2) && b3) ++cross;\n\t\t}\n\t\treturn cross % 2 != 0;\n\t}*/\n\t\n\t/**\n\t * 8---judge if a point is located on the segment\n\t * @param\tx1\tthe x coordinate of one point of the segment\n\t * @param\ty1\tthe y coordinate of one point of the segment\n\t * @param \tx2\tthe x coordinate of another point of the segment\n\t * @param \ty2\tthe y coordinate of another point of the segment\n\t * @param\tx\tthe x coordinate of the point\n\t * @param \ty\tthe y coordinate of the point\n\t * @return\ttrue if it is located on the segment, otherwise false\n\t */\n\tpublic boolean isOnSeg(long x1, long y1, long x2, long y2, long x, long y)\n\t{\n\t\treturn (x - x1) * (y2 - y1) == (x2 - x1) * (y - y1) && \n\t\t\t\tx >= Math.min(x1, x2) && x <= Math.max(x1, x2) && \n\t\t\t\ty >= Math.min(y1, y2) && y <= Math.max(y1, y2);\n\t}\n\t\n\t/**\n\t * 9---get the cross product\n\t * @param \tp1\tpoint A\n\t * @param \tp2\tpoint B\n\t * @param \tp\tpoint O\n\t * @return\tcross product of OA x OB\n\t */\n\tpublic long cross(Point p1, Point p2, Point p)\n\t{\n\t\treturn (long)(p1.x - p.x) * (p2.y - p.y) - (long)(p2.x - p.x) * (p1.y - p.y);\n\t}\n\t\n\tclass MyScanner\n\t{\n\t private byte[] buf = new byte[1024];\n\t private int curChar;\n\t private int numChars;\n\t BufferedInputStream bis = new BufferedInputStream(System.in);\n\n\t public int read() \n\t {\n\t if (-1 == numChars)\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t if (curChar >= numChars)\n\t {\n\t curChar = 0;\n\t try \n\t {\n\t numChars = bis.read(buf);\n\t }\n\t catch (IOException e)\n\t {\n\t throw new InputMismatchException();\n\t }\n\t if (numChars <= 0)\n\t {\n\t \treturn -1;\n\t }\n\t }\n\t return buf[curChar++];\n\t }\n\n\t public int nextInt() \n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-') \n\t {\n\t sgn = -1;\n\t c = read();\n\t }\n\t int res = 0;\n\t do \n\t {\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c - '0';\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\t \n\t public long nextLong() \n\t {\n\t \tint c = read();\n\t \twhile (isSpaceChar(c))\n\t \t{\n\t \t\tc = read();\n\t \t}\n\t \tint sgn = 1;\n\t \tif (c == '-') \n\t \t{\n\t \t\tsgn = -1;\n\t \t\tc = read();\n\t \t}\n\t \tlong res = 0;\n\t \tdo \n\t \t{\n\t \t\tif (c < '0' || c > '9')\n\t \t\t{\n\t \t\t\tthrow new InputMismatchException();\n\t \t\t}\n\t \t\tres *= 10;\n\t \t\tres += c - '0';\n\t \t\tc = read();\n\t \t} while (!isSpaceChar(c));\n\t \treturn res * sgn;\n\t }\n\t \n\t public double nextDouble() \n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-')\n\t {\n\t sgn = -1;\n\t c = read();\n\t }\n\t double res = 0;\n\t while (!isSpaceChar(c) && c != '.') \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c & 15;\n\t c = read();\n\t }\n\t if (c == '.') \n\t {\n\t c = read();\n\t double m = 1;\n\t while (!isSpaceChar(c)) \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t m /= 10;\n\t res += (c & 15) * m;\n\t c = read();\n\t }\n\t }\n\t return res * sgn;\n\t }\n\t \n\t public String next()\n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t StringBuilder res = new StringBuilder();\n\t do \n\t {\n\t res.appendCodePoint(c);\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res.toString();\n\t }\n\n\t private boolean isSpaceChar(int c) \n\t {\n\t return ' ' == c || '\\n' == c || '\\r' == c || '\\t' == c || -1 == c;\n\t }\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "968256608dfc3dce6813ca9bc5d0353d", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "package com.cn;\nimport java.util.Scanner;\npublic class Test {\n\n static int MOD = 1000000007;\n static int N = 10;\n \n int digit[] = new int[11];\n int f[][][] = new int[11][11][2];\n int cnt[] = new int[11];\n long ans;\n \n void sol(int m) {\n for (int i = 10; i -- > 0; m /= 10) digit[i] = m % 10;\n \n f[0][0][1] = 1;\n for (int i = 1; i < 10; i ++)\n for (int j = 0; j <= i; j ++) \n for (int d = 0; d < 10; d ++) {\n f[i][j + (d == 4 || d == 7 ? 1 : 0)][0] += f[i - 1][j][0]; \n if (d == digit[i]) f[i][j + (d == 4 || d == 7 ? 1 : 0)][1] += f[i - 1][j][1]; \n if (d < digit[i]) f[i][j + (d == 4 || d == 7 ? 1 : 0)][0] += f[i - 1][j][1]; \n }\n \n for (int i = 0; i < 10; i ++) cnt[i] = f[9][i][0] + f[9][i][1];\n cnt[0] --; \n\n //for (int i = 0; i < 10; i ++) System.out.println(cnt[i]);\n for (int i = 1; i < 10; i ++) \n if (cnt[i] > 0) {\n cnt[i] --;\n dfs(0, i, cnt[i] + 1);\n cnt[i] ++;\n }\n System.out.println(ans % MOD);\n }\n \n void dfs(int dep, int left, long res) {\n if (dep >= 6) {\n ans += res;\n return;\n }\n for (int i = 0; i < left; i ++) \n if (cnt[i] > 0) {\n cnt[i] --;\n dfs(dep + 1, left - i, res * (cnt[i] + 1) % MOD);\n cnt[i] ++;\n }\n }\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n while(in.hasNext()) new Test().sol(in.nextInt());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e4765e2d5cc32e1f671a22af6aa30bd5", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\n\npublic class Main {\n static final long MOD = 1000000007L;\n \n static int[][] dp = new int[10][9];\n \n static {\n dp[0][0] = 1;\n for (int i = 1; i < dp.length; i++) {\n dp[i][0] += 8 * dp[i - 1][0];\n for (int j = 1; j < 9; j++) {\n dp[i][j] += dp[i - 1][j - 1] * 2 + dp[i - 1][j] * 8;\n }\n }\n }\n \n static int[] toArray(int m) {\n int temp = m / 10;\n int c = 1;\n while (temp > 0) {\n temp /= 10;\n c++;\n }\n int[] res = new int[c];\n for (int i = 0; i < c; i++) {\n res[i] = m % 10;\n m /= 10;\n }\n return res;\n }\n \n static void increase(int index, int multi, int shift) {\n for (int i = 0; i + shift < 9; i++) {\n count[i + shift] += multi * dp[index][i];\n }\n }\n \n static long C(int up, int down) {\n if (up < down) {\n return 0;\n }\n long res = 1;\n int c2 = 0;\n int c3 = 0;\n int c5 = 0;\n for (int i = 2; i <= down; i++) {\n int temp = i;\n while (temp % 2 == 0) {\n c2++;\n temp /= 2;\n }\n \n while (temp % 3 == 0) {\n c3++;\n temp /= 3;\n }\n \n \n while (temp % 5 == 0) {\n c5++;\n temp /= 5;\n }\n }\n \n for (int i = up; i > up - down; i--) {\n int temp = i;\n while (temp % 2 == 0 && c2 > 0) {\n c2--;\n temp /= 2;\n }\n while (temp % 3 == 0 && c3 > 0) {\n c3--;\n temp /= 3;\n }\n while (temp % 5 == 0 && c5 > 0) {\n c5--;\n temp /= 5;\n }\n res *= temp;\n res %= MOD;\n }\n return res;\n }\n \n static void search(int index, int left) {\n if (index == 1 && left == 0) {\n int aa = 1;\n }\n if (count[index] == 0) {\n return;\n }\n if (left == 0) {\n int require = 0;\n for (int i = 0; i < 9; i++) {\n require += i * use[i];\n }\n require++;\n if (require < 9) {\n long base = 1;\n for (int i = 0; i < 9; i++) {\n if (use[i] > 0) {\n base *= C(count[i], use[i]);\n base %= MOD;\n }\n }\n base *= 720;\n base %= MOD;\n \n for (int i = require; i < 9; i++) {\n if (count[i] == 0) {\n break;\n }\n res += base * count[i];\n res %= MOD;\n }\n }\n return;\n }\n if (index == 9) {\n return;\n }\n \n for (int i = 0; i <= left; i++) {\n use[index] = i;\n search(index + 1, left - i);\n use[index] = 0;\n }\n }\n \n static int[] count;\n static int[] use;\n static long res;\n public static void main(String[] args) throws Exception {\n Scanner scan = new Scanner(System.in);\n int m = scan.nextInt();\n count = new int[9];\n \n int[] digits = toArray(m);\n int shift = 0;\n for (int i = digits.length - 1; i >= 0; i--) {\n if (digits[i] <= 4) {\n increase(i, digits[i], 0 + shift);\n }\n else if (digits[i] <= 7) {\n increase(i, digits[i] - 1, 0 + shift);\n increase(i, 1, 1 + shift);\n }\n else {\n increase(i, digits[i] - 2, 0 + shift);\n increase(i, 2, 1 + shift);\n }\n if (digits[i] == 4 || digits[i] == 7) {\n shift++;\n }\n }\n count[shift]++;\n count[0]--;\n /*\n int[] check = new int[9];\n for (int i = 1; i <= m; i++) {\n int c = 0;\n int temp = i;\n while (temp > 0) {\n if (temp % 10 == 4 || temp % 10 == 7) {\n c++;\n }\n temp /= 10;\n }\n check[c]++;\n }\n System.out.println(Arrays.toString(check));\n System.out.println(Arrays.toString(count));\n System.out.println(Arrays.equals(check, count));*/\n res = 0;\n use = new int[9];\n search(0, 6);\n System.out.println(res);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d07a3c008e5d349b464ebaa1858c9022", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "package div2.round421;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n * Created by Viki on 6/27/2017.\n */\npublic class A {\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(br.readLine());\n int allPages = Integer.parseInt(st.nextToken());\n int firstDayPages = Integer.parseInt(st.nextToken());\n int maxDayPages = Integer.parseInt(st.nextToken());\n int dayAddPages = Integer.parseInt(st.nextToken());\n int lastDayPages = Integer.parseInt(st.nextToken());\n\n int day = 0;\n int currentPage = 0;\n\n while (currentPage < allPages) {\n if (day > 0) {\n currentPage -= lastDayPages;\n }\n currentPage += Math.min(firstDayPages + day * dayAddPages, maxDayPages);\n day++;\n }\n\n System.out.println(day);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8c0c144ffe1a36d9f2f0a269cd1a0350", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n//package seifnew;\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\n/**\n *\n * @author seif\n */\npublic class Seifnew {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws FileNotFoundException {\n File f=new File(\"seifnew.txt\"); \n Scanner sc=new Scanner(f);\n int c=sc.nextInt();\n int v0=sc.nextInt();\n int v1=sc.nextInt();\n int a=sc.nextInt();\n int l=sc.nextInt();\n \n int days=0;\n do{\n days++;\n c=c-v0;\n v0=v0+a;\n if (v0>=v1){\n v0=v1;}\n if (c > 0){\n c=c+l; \n }\n }while (c>0);\n System.out.print(days);\n \n \n \n }\n \n \n \n}\n \n \n \n \n \n \n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "daf7d56579fded5913d0d62d19b0ad5b", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0} {"lang": "Java 8", "source_code": "package codeforces;\n\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\n/**\n * Built using CHelper plug-in Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tint c, v0, v1, a, l;\n\t\tc = in.nextInt();\n\t\tv0 = in.nextInt();\n\t\tv1 = in.nextInt();\n\t\ta = in.nextInt();\n\t\tl = in.nextInt();\n\t\tint read = v0;\n\t\tint speed = v0;\n\t\tint count = 1;\n\t\twhile (read < c) {\n\t\t\tcount++;\n\t\t\tif (speed + a <= v1) {\n\t\t\t\tspeed += a;\n\t\t\t}\n\t\t\tread += speed - l;\n\t\t}\n\t\tout.print(count);\n\t}\n\t\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2768577448e372bcfcf6287bbf10aa8e", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\n/**\n *\n * @author seif\n */\npublic class Seifnew {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws FileNotFoundException {\n File f=new File(\"seifnew.txt\"); \n Scanner sc=new Scanner(f);\n int c=sc.nextInt();\n int v0=sc.nextInt();\n int v1=sc.nextInt();\n int a=sc.nextInt();\n int l=sc.nextInt();\n \n int days=0;\n do{\n days++;\n c=c-v0;\n v0=v0+a;\n if (v0>=v1){\n v0=v1;}\n if (c > 0){\n c=c+l; \n }\n }while (c>0);\n System.out.print(days);\n \n \n \n }\n \n \n \n}\n \n \n \n \n \n \n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a556c952f11784b1c42c8bf1f56c96ee", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0} {"lang": "Java 7", "source_code": "package codeforces272;\n\nimport java.util.Scanner;\n\npublic class DreamoonSums {\n public static final long MOD = 1000000007;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long a = sc.nextInt();\n long b = sc.nextInt();\n long sum = 0;\n long tmp = (1L * a * b + b + 2) % MOD;\n tmp = (tmp * a / 2) % MOD;\n\n System.out.println(\"tmp=\" + tmp);\n for (long r = 1; r <= b - 1; r++) {\n // ar(ab+b+2)/2\n sum += r * tmp;\n sum %= MOD;\n }\n System.out.println(sum);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "86fc86f7ef4ab9a574e15cddf7c5678c", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputstream = System.in;\n OutputStream outputstream = System.out;\n InputReader in = new InputReader(inputstream);\n PrintWriter out = new PrintWriter(outputstream);\n // int T;\n // T = Integer.parseInt(in.readString());\n // for (int i = 1; i <= T; i++) {\n Task solver = new Task();\n solver.solve(1, in, out);\n // } \n out.close();\n }\n}\n\nclass Task {\n\n final int MOD = 1_000_000_007;\n\n public void solve(int testno, InputReader in, PrintWriter out) {\n int a = in.readInt();\n int b = in.readInt();\n\n int ans = (((((2*a + (((((((long)a) % MOD) * b)) % MOD) * (a + 1)) % MOD) % MOD) *(long) b) % MOD) * ((b - 1))) % MOD;\n out.println(ans/4);\n\n }\n\n}\n\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\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 StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public long readLong() {\n return Long.parseLong(readString());\n }\n\n public double readDouble() {\n return Double.parseDouble(readString());\n }\n\n public float readFloat() {\n return Float.parseFloat(readString());\n }\n\n public static boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "158fbfca52ddb1cf783066a7f72fde8e", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tstatic final int MOD = 1000000007;\n\n\tstatic void solve() throws IOException {\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\t\tint sumMod = (int) ((long) b * (b - 1) / 2);\n\t\tint sumA = (int) ((long) a * (a + 1) / 2);\n\t\tint ans = (int) ((long) sumMod * a % MOD);\n\t\tans = (int) ((ans + (long) sumA * sumMod % MOD * b) % MOD);\n\t\tout.println(ans);\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(\"a.in\");\n\t\tif (file.exists() && file.canRead()) {\n\t\t\tinput = new FileInputStream(file);\n\t\t\toutput = new PrintStream(\"a.out\");\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\tbr.close();\n\t}\n\n\tstatic boolean hasNext() 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 false;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn true;\n\t}\n\n\tstatic String next() throws IOException {\n\t\treturn hasNext() ? st.nextToken() : null;\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "54fa3d1e0de9b91c358b2cf8e757ef13", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n\n\n\tpublic static class pair implements Comparable\n\t{\n\t\tint a;\n\t\tint b;\n\t\tpublic pair(int pa, int pb)\n\t\t{\n\t\t\ta = pa; b= pb;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(pair o) {\n\t\t\tif(this.a < o.a)\n\t\t\t\treturn -1;\n\t\t\tif(this.a > o.a)\n\t\t\t\treturn 1;\n\t\t\treturn Integer.compare(o.b, this.b);\n\t\t}\n\t}\n\n\n\t//int n = Integer.parseInt(in.readLine());\n\t//int n = Integer.parseInt(spl[0]);\n\t//String[] spl = in.readLine().split(\" \");\n\t\t\n\tpublic static void main (String[] args) throws Exception\n\t{\t\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] spl = in.readLine().split(\" \");\n\t\tint a = Integer.parseInt(spl[0]);\n\t\tint b = Integer.parseInt(spl[1]);\n\t\tlong mod = 1000000007;\n\t\tlong pp = (b*(b-1))/2;\n\t\tlong ans = 0;\n\t\tpp%=mod;\n\t\tfor (int k = 1; k <= a; k++) {\n\t\t\tlong cur = k*b+1;\n\t\t\tcur%=mod;\n\t\t\tans+=pp*cur;\n\t\t\tans%=mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4c1a5da91576c0244e80479a4def700", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class JavaApplication73 {\n\n\n public static void main(String[] args) {\n Scanner Sc=new Scanner(System.in);\n \n int n=Sc.nextInt();\n int m=Sc.nextInt();\n long k=Sc.nextInt();\n long x=1,y=1;\n int t=0;\n \n if(k<=n-1)\n {\n System.out.println((x+k)+\" \"+1);\n System.exit(0);\n }\n x=n;\n y=1;\n // c+=n-1;\n k-=n-1;\n if(k<=m-1)\n {\n y=y+k;\n System.out.println(x+\" \"+y);\n System.exit(0);\n }\n k-=m-1;\n y=y+m-1;\n //System.out.println(\"*\"+x+\" \"+y);\n t=0;\n while(k>m-1)\n {\n if(t==0)\n {\n //System.out.println(\"dvnmdsv\");\n x-=1;\n y-=m-2;\n t=1;\n // System.out.println(\"??\"+x+\" \"+y+\" \"+t);\n }\n else\n {\n x-=1;\n y+=m-2;\n t=0;\n //System.out.println(\"@@\"+x+\" \"+y+\" \"+t);\n }\n //4 System.out.println(\"#\"+x+\" \"+y+\" \"+t);\n k-=m-1;\n }\n \n if(k==0)\n {\n System.out.println(x+\" \"+y);\n System.exit(0);\n }\n \n //System.out.println(x+\" \"+y);\n if(t==0)\n {\n x-=1;\n k--; \n while(k!=0)\n {\n y--;\n k--;\n }\n \n }\n else\n {\n x-=1;\n k--; \n while(k!=0)\n {\n y++;\n k--;\n }\n \n }\n \n System.out.println(x+\" \"+y);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2c99bf1ae44707a7aa8fd6f2c0f61a4", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner ;\npublic class lara\n{\n public static void main (String [] args)\n {\n Scanner sc = new Scanner(System.in) ;\n int [] k = new int [3] ;\n for (int i = 0 ; i < 3 ; i++)\n {\n k[i] = sc.nextInt() ;\n }\n int o = 1 ;\n int p = 1 ;\n int J = 0 ;\n while(J < k[2] && J < (k[0] + (k[1] - 1)))\n {\n if(o < k[0])\n {\n o++ ;\n J++ ;\n }\n else if(o == k[0] && p < k[1])\n {\n p++ ;\n J++ ;\n }\n else if(o == k[0] && p == k[1])\n {\n o-- ;\n J++ ;\n }\n }\n while(J < k[2])\n {\n if(o%2 != 0)\n {\n if(p == 2)\n {\n o-- ;\n J++ ;\n }\n else\n {\n p-- ;\n J++ ;\n }\n }\n else if(o%2 == 0)\n {\n if(p == k[1])\n {\n o-- ;\n J++ ;\n }\n else\n {\n p++ ;\n J++ ;\n }\n }\n }\n System.out.println(o + \" \" + p) ;\n sc.close() ;\n }\n}\n \n \n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6f8c2f79acbb5246274439a288f2f745", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n/*\n * \tHeart beats fast\n * \t\tColors and promises\n * \t\t\tHow to be brave\n * \t\t\t\tHow can I love when I am afraid to fall...\n */\npublic class Main \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tlong n=ni(),m=ni();\n\t\tlong k=nl();\n\t\tif(k()\n\t\t{\n\t\t\t@Override\n\t\t\tpublic int compare(Integer[]a,Integer[]b)\n\t\t\t{\n\t\t\t\tif(a[0]>b[0])\n\t\t\t\t\treturn 1;\n\t\t\t\telse if(b[0]>a[1])\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\tstatic String pr(String a, long b)\n\t{\n\t\tString c=\"\";\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tc=c.concat(a);\n\t\t\ta=a.concat(a);\n\t\t\tb>>=1;\n\t\t}\n\t\treturn c;\n\t}\n\tstatic long powm(long a, long b, long m)\n\t{\n\t\tlong an=1;\n\t\tlong c=a;\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tan=(an*c)%m;\n\t\t\tc=(c*c)%m;\n\t\t\tb>>=1;\n\t\t}\n\t\treturn an;\n\t}\n\tstatic int gcd(int a, int b)\n\t{\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn gcd(b, a%b);\n\t}\n\t/////////////////////////\n\tstatic class Reader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public Reader() {\n reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n public double nextDouble() {\n \treturn Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "27600ae1e58584e5da0c79f37f8c8a58", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author mostafa\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 ProblemBLaraCroftAndTheNewGame solver = new ProblemBLaraCroftAndTheNewGame();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ProblemBLaraCroftAndTheNewGame {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n long k = in.nextLong();\n\n long X = 1, Y = 1;\n if (k < n) {\n Y += k;\n } else if (k <= (n + m - 2)) {\n Y = n;\n k -= (n - 1);\n X += k;\n } else {\n k -= (n + m - 2);\n long peroid = 2 + 2 * (m - 2);\n\n long numOfPeriod = k / peroid;\n\n long steps = k % peroid;\n\n Y = n - 2 * numOfPeriod;\n X = m;\n\n if (steps == 1) {\n Y--;\n } else if (steps > 1 && steps < m) {\n Y--;\n steps--;\n X -= steps;\n } else if (steps == m) {\n Y--;\n X -= (m - 2);\n Y--;\n } else {\n Y -= 1;\n X -= (m - 2);\n Y -= 1;\n steps -= 2 * Y;\n steps -= (m - 2);\n X += (steps);\n }\n }\n out.print(Y + \" \" + X);\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "079e5c52346bc7a2fc506f5c161e4af4", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage javaapplication2;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author Admi\n */\npublic class JavaApplication2 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n int k,l,s,i,m;\n s=(int) (Math.pow(2, 31)-1);\n \n Scanner reader=new Scanner(System.in);\n \n do{\n k=reader.nextInt();\n l=reader.nextInt(); \n }while(k<2&&l>s);\n i=1;\n do{\n m=(int) (Math.pow(k, i));\n if(m==l) {i--;System.out.println(\"YES\");System.out.print(i);}\n if(m>l){System.out.print(\"NO\");}\n i++;\n }while(m0){\n if(a[bin(a, m, 0, 99)] == m){\n System.out.println(\"YES\");\n System.out.println(bin(a, m, 0,99)-1);\n }\n }else{\n System.out.println(\"NO\");\n }\n \n }\n public static int bin(int a[],int key,int left,int right){\n if(left > right){\n return -1;\n }else{\n int mid = (left+right)/2;\n if(a[mid] == key){\n return mid;\n }\n if(a[mid] > key){\n return bin(a, key, left, mid-1);\n }else{\n return bin(a, key, mid+1, right);\n }\n }\n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "83df4bdd9151ee288ee22a536a7cede1", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Solution {\n\n\tpublic static final Scanner input = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\t\tfinal int n = input.nextInt();\n\t\tfinal int[] soldiers = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsoldiers[i] = input.nextInt();\n\t\t}\n\n\t\tint minIndex = 0;\n\t\tint maxIndex = n - 1;\n\n\t\tfor (int i = 1, j = n - 2; i < n; i++, j--) {\n\t\t\tif (soldiers[i] <= soldiers[minIndex]) {\n\t\t\t\tminIndex = i;\n\t\t\t}\n\n\t\t\tif (soldiers[j] >= soldiers[maxIndex]) {\n\t\t\t\tmaxIndex = j;\n\t\t\t}\n\t\t}\t\n\n int result = 0;\n if (soldiers[maxIndex] != soldiers[0]) {\n result += maxIndex;\n }\n \n if (soldiers[minIndex] != soldiers[n - 1]) {\n result += n - 1 - minIndex;\n }\n \n if (minIndex < maxIndex) {\n result--;\n }\n \n System.out.print(result);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d474f04a8bf0da6f6088bf53ba504d48", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "package tasks;\n\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long k = in.nextLong();\n long l = in.nextLong();\n long potential = 1;\n long i;\n\n for (i = 0; ; i++) {\n potential *= k;\n if(potential >= l)\n break;\n }\n if(potential == l){\n System.out.println(\"YES \\n\" + i);\n } else {\n System.out.println(\"NO\");\n }\n// dsf\n// System.out.println(potential + \" \" + i);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bf2d4d4b27533acc2fa5c057be054569", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Code {\n public static void main(String... arg){\n Scanner sc = new Scanner(System.in);\n int n , k;\n n = sc.nextInt();\n k = sc.nextInt();\n int ans =0;\n for(int i=1; i<= n;i++) {\n String s = String.valueOf(i);\n String s1 = new StringBuffer(s).reverse().toString();\n s = s + s1;\n //System.out.println(s);\n int y = Integer.parseInt(s);\n ans = (ans + y)%k;\n\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2feb77820d71bb7b775e14ee7a9e8b13", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class chthollysRequest {\n\n\tpublic static long calcSum(long k)\n\t{\n\t\tlong num=1;\n\t\tlong sum=0;\n\t\tString zcy=\"\";\n\t\t\n\t\t\n\t\t\n\t\twhile(num<=k)\n\t\t{\n\t\t\tStringBuilder rev=new StringBuilder();\n\t\t\tzcy=\"\"+num;\n\t\t\trev.append(zcy);\n\t\t\trev=rev.reverse();\n\t\t\tzcy=num+\"\"+rev;\n\t\t\tsum=sum+(Integer.parseInt(zcy));\n\t\t\t//System.out.println(zcy);\n\t\t\tnum++;\n\t\t}\n\t\t\n\t\treturn sum;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t\tScanner s=new Scanner(System.in);\n\t\tlong k=s.nextInt();\n\t\tlong p=s.nextInt();\n\t\t\n\t\tlong sumans=calcSum(k);\n\t\t//System.out.println(sumans);\n\t\tSystem.out.println(sumans%p);\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a1fae5193fd11093dfb1251f0636c1e", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\tpublic static void main (String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint n = scanner.nextInt(), p = scanner.nextInt(), result = 0, cur = 0;\n\t\tfor (int i = 0, j = 1; i < n; i++) {\n\t\t String st = \"\";\n\t\t st += String.valueOf(j);\n\t\t StringBuilder stb = new StringBuilder();\n\t\t stb.append(st);\n\t\t stb.reverse();\n\t\t st += stb;\n\t\t cur = Integer.parseInt(st);\n\t\t cur %= p;\n\t\t result += cur;\n\t\t result %= p;\n\t\t j++;\n\t\t}\n\t\tSystem.out.printf(\"%d\", result);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "88be1c20f4dde1cd059f768446a35820", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\n\npublic class A887 {\n\n public static void main(String[] args) {\n \n Scanner in = new Scanner(System.in);\n String zcy = \"123456789\";\n int k = in.nextInt();\n int p = in.nextInt();\n int sum = 0;\n\n for(int i = 0;i k)\n out = \"NO\";\n\n\n System.out.println(out);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a55c4fcd0290990850b239ed708850b3", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class Godsend {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader ( new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tString linea = in.readLine();\n\t\tStringTokenizer toks = new StringTokenizer(linea);\n\t\tint n=Integer.parseInt(toks.nextToken());\n\t\tint k=Integer.parseInt(toks.nextToken());\n\t\t linea=in.readLine();\n\t\tHashMapglobos= new HashMap();\n\t\tfor (int i = 0; i < linea.length(); i++) {\n\t\t\tif(globos.containsKey(linea.charAt(i))){\n\t\t\t\tglobos.put(linea.charAt(i), globos.get(linea.charAt(i))+1);\n\t\t\t}else{\n\t\t\t\tglobos.put(linea.charAt(i), 1);\n\t\t\t}\n\t\t}\n\t\tSetllaves=globos.keySet();\n\t\tboolean puede=true;\n\t\tfor (Character l : llaves) {\n\t\t\tint la=globos.get(l);\n\t\t\tif(la%k!=0&&la>k){\n\t\t\t\tpuede=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(puede?\"YES\":\"NO\");\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "25b96b6ce7ff0d6f751cff7199d68705", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class blah {\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 k = scan.nextInt();scan.nextLine();\n\t\tString s = scan.next();\t\t\n\t\tint count=0;\n\t\tfor (int y=0; y k) {\n result = false;\n break;\n }\n count = 1;\n inicio = a[i];\n }\n }\n\n if (result)\n out.print(\"YES\");\n else\n out.print(\"NO\");\n } else\n out.print(\"YES\");\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c8402ea6db00417f41512f2089de0fa2", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0} {"lang": "Java 8", "source_code": "package div2.r253.taskB;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n public static void main(String[] args) {\n BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n String s;\n int i;\n\n try {\n s = r.readLine();\n i = Integer.parseInt(r.readLine());\n }\n catch (IOException e) {\n System.out.println(\"couldn't read. \" + e);\n return;\n }\n\n if (i>=s.length()) {\n System.out.println(((i+s.length())/2)*2);\n return;\n }\n\n int max = 0;\n for (int j = 0; j <= s.length()-i; j++) {\n //System.out.println(\"etap1 \" + s + s.substring(j, j + i));\n int m = maxTandemLength(s + s.substring(j, j + i));\n if (m>max) max = m;\n }\n System.out.println(max);\n // write your code here\n }\n\n private static int maxTandemLength(String str) {\n if (str.length() <= 1) return 0;\n for (int candidateLength = (str.length() / 2) * 2; candidateLength>0; candidateLength-=2) {\n //System.out.println(\"etap2 \" + candidateLength);\n for (int i = 0; i <= str.length() - candidateLength; i++) {\n String tandemCandidate = str.substring(i, i + candidateLength);\n //System.out.println(\"etap3 \" + tandemCandidate);\n if (isTandem(tandemCandidate)) return candidateLength;\n }\n }\n return 1;\n }\n\n private static boolean isTandem(String tandemCandidate) {\n int half = tandemCandidate.length()/2;\n return tandemCandidate.substring(0, half).equals(tandemCandidate.substring(half));\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b460f5a2cc512ac47c4a50086b95c32d", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport 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(); // number of sellers\n int v = sc.nextInt(); // amount of money Valera has\n List goodVendors = new ArrayList(n);\n \n for (int i = 1; i <= n; ++i) {\n int numItemsSold = sc.nextInt();\n boolean isGoodVendor = false;\n for (int j = 0; j < numItemsSold; ++j) {\n if (sc.nextInt() < v && !isGoodVendor) {\n isGoodVendor = true;\n goodVendors.add(i);\n }\n }\n }\n \n System.out.println(goodVendors.size());\n for (int i = 0; i < goodVendors.size() - 1; ++i) {\n System.out.print(goodVendors.get(i) + \" \");\n }\n if (goodVendors.size() != 0) {\n System.out.println(goodVendors.get(goodVendors.size() - 1));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "46a6572f43a10ca1518fbe74aff86ca4", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString str = in.nextLine();\n\t\tint k = in.nextInt();\n\t\t\n\t\tchar[] ch = str.toCharArray();\n\t\tint len = str.length() + k;\n\t\tint l = 0;\n\t\t\n\t\tHashSet chr = new HashSet<>();\n\t\tfor (int i = 0; i < ch.length; i++) {\n\t\t\tchr.add(ch[i]);\n\t\t}\n\t\t\n\t\tif(chr.size()==ch.length && k<=ch.length) {\n//\t\t\tSystem.out.println(\"sds\"+chr.size());\n\t\t\tl = k*2;\n\t\t} \n\t\tif(chr.size()==ch.length && k>ch.length) {\n\t\t\tl = ch.length*2;\n\t\t} \n\t\t\n\t\tfor (int i = 0; i < len/2; i++) {\n\t\t\tint d = i;\n\t\t\twhile(str.indexOf(ch[i], d+1)!=-1) {\n\t\t\t\t\n\t\t\t\tint t = str.indexOf(ch[i], d+1);\n\t\t\t\td = t+1;\n\t\t\t\tif(t + t-i <= len) {\n//\t\t\t\t\tSystem.out.println(\"i: \"+i+\" t: \"+t );\n\t\t\t\t\tboolean r = true;\n\t\t\t\t\tfor (int j = i; j < t && r == true && t+j < str.length(); j++) {\n\t\t\t\t\t\tif(ch[j]!=ch[j+t-i])\n\t\t\t\t\t\t\tr = false;\n\t\t\t\t\t}\n\t\t\t\t\tif(r == true && l<(t-i)*2) {\n\t\t\t\t\t\tl = (t-i)*2;\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}\n\t\t}\n\t\tSystem.out.println(l);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e564c903278da7d972c2a74e52c412b0", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n int k = sc.nextInt();\n \n for(int i=0; i 0) minCyc = D.add(0);\n\t\t//System.out.println(minCyc+\" \"+D+\" lo: \"+lo);\n\n\t\tfor(BI cycs = minCyc.sub(1); cycs.compareTo(D) <= 0; cycs.addI(1)) {\n\t\t\tBI nums = K.mult(cycs.sub(1));\n\t\t\tnums.addI(1);\n\t\t\t//System.out.println(\"Nums: \"+nums);\n\t\t\t\n\t\t\tBI give = N.div(nums);\n\t\t\tif(give.compareTo(lo) < 0) continue;\n\t\t\tif(give.compareTo(M) > 0) give = M.add(0);\n\t\t\tBI rr = give.mult(cycs);\n\t\t\tif(best.compareTo(rr) < 0) best = rr;\n\t\t}\n\t\tSystem.out.println(best);\n\t}\n\t\n\tstatic class BI{\n\t\tBigInteger val;\n\t\tBigInteger zero = BigInteger.ZERO;\n\t\tBigInteger one = BigInteger.ONE;\n\t\t//CONSTRUCTORS\n\t\tpublic BI(BigInteger v) {\n\t\t\tval = v;\n\t\t}\n\t\tpublic BI(long v) {\n\t\t\tval = BigInteger.valueOf(v);\n\t\t}\n\t\t\n\t\t//ADDITION\n\t\tpublic BI add(long v) {\n\t\t\tif(v==0) return new BI(val);\n\t\t\tif(v==1) return new BI(val.add(one));\n\t\t\treturn new BI(val.add(BigInteger.valueOf(v)));\n\t\t}\n\t\tpublic BI add(BI v) {\n\t\t\treturn new BI(val.add(v.val));\n\t\t}\n\t\tpublic void addI(long v) {\n\t\t\tif(v==0);\n\t\t\telse if(v==1) val=val.add(one);\n\t\t\telse val = val.add(BigInteger.valueOf(v));\n\t\t}\n\t\tpublic void addI(BI v) {\n\t\t\tval = val.add(v.val);\n\t\t}\n\t\t//SUBTRACTION\n\t\tpublic BI sub(long v) {\n\t\t\tif(v==0) return new BI(val);\n\t\t\tif(v==1) return new BI(val.subtract(one));\n\t\t\treturn new BI(val.subtract(BigInteger.valueOf(v)));\n\t\t}\n\t\tpublic BI sub(BI v) {\n\t\t\treturn new BI(val.subtract(v.val));\n\t\t}\n\t\tpublic void subI(long v) {\n\t\t\tif(v==0);\n\t\t\telse if(v==1) val=val.subtract(one);\n\t\t\telse val = val.subtract(BigInteger.valueOf(v));\n\t\t}\n\t\tpublic void subI(BI v) {\n\t\t\tval = val.subtract(v.val);\n\t\t}\n\t\t//MULTIPLICATION\n\t\tpublic BI mult(long v) {\n\t\t\tif(v==0) return new BI(zero);\n\t\t\tif(v==1) return new BI(val);\n\t\t\treturn new BI(val.multiply(BigInteger.valueOf(v)));\n\t\t}\n\t\tpublic BI mult(BI v) {\n\t\t\treturn new BI(val.multiply(v.val));\n\t\t}\n\t\tpublic void multI(long v) {\n\t\t\tif(v==0) val = zero;\n\t\t\telse if(v==1);\n\t\t\telse val = val.multiply(BigInteger.valueOf(v));\n\t\t}\n\t\tpublic void multI(BI v) {\n\t\t\tval = val.multiply(v.val);\n\t\t}\n\t\t//DIVISION\n\t\tpublic BI div(long v) {\n\t\t\tif(v==1) return new BI(val);\n\t\t\treturn new BI(val.divide(BigInteger.valueOf(v)));\n\t\t}\n\t\tpublic BI div(BI v) {\n\t\t\treturn new BI(val.divide(v.val));\n\t\t}\n\t\tpublic void divI(long v) {\n\t\t\tif(v!=1)val = val.divide(BigInteger.valueOf(v));\n\t\t}\n\t\tpublic void divI(BI v) {\n\t\t\tval = val.divide(v.val);\n\t\t}\n\t\t//MOD\n\t\tpublic BI mod(long v) {\n\t\t\treturn new BI(val.mod(BigInteger.valueOf(v)));\n\t\t}\n\t\tpublic BI mod(BI v) {\n\t\t\treturn new BI(val.mod(v.val));\n\t\t}\n\t\tpublic void modI(long v) {\n\t\t\tval = val.mod(BigInteger.valueOf(v));\n\t\t}\n\t\tpublic void modI(BI v) {\n\t\t\tval = val.mod(v.val);\n\t\t}\n\t\t//COMPARE\n\t\tpublic int compareTo(long v) {\n\t\t\treturn val.compareTo(BigInteger.valueOf(v));\n\t\t}\n\t\tpublic int compareTo(BI v) {\n\t\t\treturn val.compareTo(v.val);\n\t\t}\n\t\tpublic boolean equals(long v) {\n\t\t\treturn val.equals(BigInteger.valueOf(v));\n\t\t}\n\t\tpublic boolean equals(BI v) {\n\t\t\treturn val.equals(v.val);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn val.toString();\n\t\t}\n\t}\n\t\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\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\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7dbca8e52c3ab06814b38083dfe562b6", "src_uid": "ac2e795cd44061db8da13e3947ba791b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tpublic static void solve(FastScanner fs) {\t\n\t\tlong numCandies=fs.nextLong();\n\t\tlong numPeople=fs.nextLong();\n\t\tlong maxCandiesPerSwipe=fs.nextLong();\n\t\tlong maxCandieTakes=fs.nextInt();\n\t\tlong best=maxCandiesPerSwipe;\n\t\t\n\t\tfor (int candyTakes=2; candyTakes<=maxCandieTakes; candyTakes++) {\n\t\t\tbest=Math.max(best, candyTakes*(Math.min(maxCandiesPerSwipe, numCandies/(candyTakes*numPeople-numPeople+1))));\n\t\t}\n\t\tSystem.out.println(best);\n\t\t\n\t}\n\n\t\n\t\n\t\n\t\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tFastScanner scanner = new FastScanner(System.in);\n\t\tsolve(scanner);\n\t}\n\t\n\n\tprivate static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t}\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\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i set = new HashSet();\n int N ; \n N= input.nextInt();\n int[]a=new int [N];\n for(int i=0;i0){\n set.add(a[i]);\n }\n }\n int count=0;\n for(Integer c:set){\n count++;\n }\n System.out.println(count);\n\t\t\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "13d295d098436408c008341f470cdbca", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0} {"lang": "Java 8", "source_code": "//package main_package;\nimport java.util.*;\n\npublic class diploma {\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scan = new Scanner(System.in);\n\t\tint N = scan.nextInt();\n\t\t\n\t\tHashMap answer = new HashMap<>();\n\t\t\n\t\tfor(int i=0; i 0) {\n\t\t\t\tanswer.put(curr, true);\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(answer.size());\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad8ac3ce72342fc253460621abac143a", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Olympiad{\n \n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n \n int[] scores = new int[601];\n \n for (int i = 0; i < n; i++) {\n int m = sc.nextInt();\n if (m != 0) {\n scores[m] = 1;\n }\n }\n \n int sum = 0;\n for (int i = 0; i < 601; i++) {\n sum += scores[i];\n }\n \n System.out.println(sum);\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9f4a13f6c6478473ec181c572cac3bd1", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\n static Scanner scan = new Scanner(System.in);\n\n public static void main(String[] args) {\n Task solver = new Task();\n solver.olympiad(scan.nextInt());\n }\n\n static class Task {\n public void olympiad(int n) {\n int in;\n HashSet hashSet = new HashSet<>(600);\n int size=0, j=0;\n int [] ar = new int[n];\n for(int i = 0; i < n; i++) {\n in = scan.nextInt();\n if(in != 0) hashSet.add(in);\n if(size+1 == hashSet.size()){\n ar[j++] = in;\n size = hashSet.size();\n }\n }\n System.out.printf(\"%d\", hashSet.size());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43f6ee077a785ce01114aa7ef184c9e5", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n \npublic class Solution55A {\n \n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\")!=null;\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n \n void init() throws FileNotFoundException{\n if (ONLINE_JUDGE){\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }else{\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n \n String readString() throws IOException{\n while(!tok.hasMoreTokens()){\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n \n int readInt() throws IOException{\n return Integer.parseInt(readString());\n }\n \n long readLong() throws IOException{\n return Long.parseLong(readString());\n }\n \n double readDouble() throws IOException{\n return Double.parseDouble(readString());\n }\n \n public static void main(String[] args){\n new Solution55A().run();\n }\n \n public void run(){\n try{\n long t1 = System.currentTimeMillis();\n init();\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \"+(t2-t1));\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n \n static class Utils {\n \n private Utils() {}\n \n public static void mergeSort(int[] a) {\n mergeSort(a, 0, a.length - 1);\n }\n \n private static void mergeSort(int[] a, int leftIndex, int rightIndex) {\n final int MAGIC_VALUE = 50;\n if (leftIndex < rightIndex) {\n if (rightIndex - leftIndex <= MAGIC_VALUE) {\n insertionSort(a, leftIndex, rightIndex);\n } else {\n int middleIndex = (leftIndex + rightIndex) / 2;\n mergeSort(a, leftIndex, middleIndex);\n mergeSort(a, middleIndex + 1, rightIndex);\n merge(a, leftIndex, middleIndex, rightIndex);\n }\n }\n }\n \n private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {\n int length1 = middleIndex - leftIndex + 1;\n int length2 = rightIndex - middleIndex;\n int[] leftArray = new int[length1];\n int[] rightArray = new int[length2];\n System.arraycopy(a, leftIndex, leftArray, 0, length1);\n System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {\n if (i == length1) {\n a[k] = rightArray[j++];\n } else if (j == length2) {\n a[k] = leftArray[i++];\n } else {\n a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];\n }\n }\n }\n \n private static void insertionSort(int[] a, int leftIndex, int rightIndex) {\n for (int i = leftIndex + 1; i <= rightIndex; i++) {\n int current = a[i];\n int j = i - 1;\n while (j >= leftIndex && a[j] > current) {\n a[j + 1] = a[j];\n j--;\n }\n a[j + 1] = current;\n }\n } \n }\n \n void solve() throws IOException{\n \tint n = readInt();\n \tint[] a = new int[n];\n \tint k = 1;\n \tint i = 0;\n \tArrays.fill(a,-1);\n \tdo{\n \t\tif(a[i] == k){\n \t\t\tbreak;\n \t\t}\n \t\tif(a[i] == -1)a[i] = k;\n \t\tif(i + k < n){\n \t\t\ti = i + k;\n \t\t}\n \t\telse\n \t\t\ti = i + k - n;\n \t\tk = (k + 1) % n;\n \t}while(true);\n \tfor(int j = 0; j < n; j++){\n \t\tif(a[j] == -1){\n \t\t\tout.println(\"NO\");\n \t\t\treturn;\n \t\t}\n \t}\n \tout.println(\"YES\");\n }\n \n static double distance(long x1, long y1, long x2, long y2){\n \treturn Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));\n }\n \n static long gcd(long a, long b){\n \twhile(a != b){\n \t\tif(a < b) a -=b;\n \t\telse b -= a;\n \t}\n \treturn a;\n }\n \n static long lcm(long a, long b){\n \treturn a * b /gcd(a, b);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af929dfbc886538d152bd4e68c3c9f90", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Main{\n \n \n public static void main(String a[]){\n Scanner cin=new Scanner(System.in);\n int n=cin.nextInt();\n boolean vis[]=new boolean[n];\n int c=0,cont=1;\n while(true){\n if(!vis[c])\n vis[c]=true;\n c+=cont++;\n c%=n;\n if(cont>n*n*n)\n break;\n }\n boolean flag=true;\n for(boolean b:vis){\n if(!b){\n flag=false;\n break;\n }\n }\n if(flag)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a439c63dc26d71b9f2d97a8cab6f744d", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Main\n{\n public static void main(String[] arqs)\n {\n Scanner scan = new Scanner(System.in);\n\n int n = scan.nextInt();\n boolean[] visited = new boolean[n];\n visited[0] = true;\n ArrayList v = new ArrayList();\n v.add(0+1*n);\n int jump = 1;\n int at = 0;\n\n while(true)\n {\n at += jump;\n at %= n;\n jump++;\n jump %= n;\n visited[at] = true;\n if(v.contains(at + jump*n)) break;\n }\n\n for(boolean i : visited)\n {\n if(!i)\n {\n System.out.println(\"NO\");\n return;\n }\n }\n System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "799bedd94d374d54c3b08889edf90217", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0} {"lang": "Java 8", "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. */\n public class Codechef\n{\n\tpublic static void main (String[] args)\n\t{\n\t\t// your code goes here\n\t\tScanner scan=new Scanner(System.in);\n\t\tint n,i=1,k=0,p=1;\n\t\tboolean flag=true;\n\t\tint[] a=new int[1000];\n\t\tn=scan.nextInt();\n\t\twhile(i<=n)\n\t\t {\n\t\t if(!(i==n-1))\n\t\t p*=i;\n\t\t ++i;\n\t\t }\n\t\ti=0;\n\t\twhile(k<=p)\n\t\t{\n\t\t i+=k;\n\t\t if(i>=n)\n {\n while(!(i addressMatcher.end()) {\n correctAddress += (\"/\" + address.substring(addressMatcher.end()));\n }\n System.out.println(correctAddress);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ff318253ee7c61e1cf86160e0de93a1", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Temp {\n\tstatic int imax = Integer.MAX_VALUE, imin = Integer.MIN_VALUE;\n\tstatic long lmax = Long.MAX_VALUE, lmin = Long.MIN_VALUE;\n\tstatic long mod = (long) 1e9 + 7;\n\n\tpublic static void main(String[] args) throws java.lang.Exception {\n//\t\tFile file=new File(\"C:\\\\Users\\\\EagleEye\\\\Desktop\\\\input.txt\");\n//\t\tFile file1=new File(\"C:\\\\Users\\\\EagleEye\\\\Desktop\\\\output.txt\");\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t// int test=in.ni();\n\t\tint test = 1;\n\t\tint i = 0, j = 0;\n\t\twhile (test-- > 0) {\n//\t\t\tint n = in.ni();\n//\t\t\tchar str[]=in.ncs();\n\t\t\tString str=in.ns();\n\t\t\tStringBuilder bdr=new StringBuilder();\n\t\t\tif(str.startsWith(\"http\")){\n\t\t\t\tbdr.append(\"http://\");\n\t\t\t\tint last=0;\n\t\t\t\tfor(i=4;i= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int ni() {\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 & 15;\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\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 & 15;\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String ns() {\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 char[] ncs(){\n\t\t\treturn ns().toCharArray();\n\t\t}\n\t\tpublic String nLine() {\n\t\t\tint c = read();\n\t\t\t// while (c != '\\n' && c != '\\r' && c != '\\t' && c != -1)\n\t\t\t// c = 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 (c != '\\n' && c != '\\r' && c != '\\t' && c != -1);\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic static boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2725e1e96cbc648962a374825cc82732", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Lokesh Khandelwal aka (codeKNIGHT | phantom11)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n int n=in.nextInt(),i;\n int a=0,b=0,limita=0,limitb=0;\n for(i=0;i=limita)\n out.printLine(\"LIVE\");\n else out.printLine(\"DEAD\");\n if(2*b>=limitb)\n out.printLine(\"LIVE\");\n else out.printLine(\"DEAD\");\n\t}\n}\n\nclass InputReader\n{\n BufferedReader in;\n StringTokenizer tokenizer=null;\n\n public InputReader(InputStream inputStream)\n {\n in=new BufferedReader(new InputStreamReader(inputStream));\n }\n public String next()\n {\n try{\n while (tokenizer==null||!tokenizer.hasMoreTokens())\n {\n tokenizer=new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n }\n catch (IOException e)\n {\n return null;\n }\n }\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e751d567d3ba7784c44b535e73ed924c", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0} {"lang": "Java 8", "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\tint n;\n\tint [] arr;\n\tpublic static void main(String[] args) throws Exception {\n new Main();\n }\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\t\n\t\tn = sc.nextInt();\n\t\tarr = new int[n];\n\t\t\n\t\tfor (int i=0;i 0; k--) {\n if (done) {\n return;\n }\n \n if (k % 2 != 0) {\n p[i] = k;\n partition(p, n - k, n - k, i + 1);\n }\n }\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a3f3632c7bd4cb73b368390888d54ad7", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().solve();\n\t}\n\t\n\tprivate void solve() throws Exception {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tn = Integer.parseInt(reader.readLine());\n\t\ta = new int[n];\n\t\tst = new StringTokenizer(reader.readLine());\n\t\t\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\ta[i] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\t\n\t\treader.close();\n\t\t\n\t\tif (func(0, false)) {\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\tprivate BufferedReader reader;\n\tprivate StringTokenizer st;\n\tprivate int n;\n\tprivate int[] a;\n\t\n\tprivate boolean func(int indx, boolean flag) {\n\t\t\n\t\tif (indx >= n) {\n\t\t\treturn flag;\n\t\t}\n\t\t\n\t\tif (a[indx] % 2 == 0 || a[n - 1] % 2 == 0) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tif (!flag && (n - indx) % 2 == 1) {\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\t\n\t\tfor (int j = indx; j < n; j += 2) {\n\t\t\tif (a[j] % 2 == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tif (func(j + 1, !flag)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "056815fc8d8b0e9173c3cc83668b9963", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution24 {\n\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tint length = scan.nextInt();\n\t\tint[] arr = new int[length];\n\t\t\n\t\tfor(int i = 0; i < length; i++){\n\t\t\tarr[i] = scan.nextInt();\n\t\t}\n\t\t\n\t\tboolean flag = true;\n\t\tif(length % 2 == 0)\tflag = false;\n\t\tif(arr[0]%2 == 0 || arr[length-1]%2 == 0)\tflag = false;\n\t\tVector even = new Vector();\n\t\tVector odd = new Vector();\n\n\t\tint numOdd = 0;\n\t\tint count = 0;\n\t\t\n\t\tif(flag){\n\t\t\tfor(int i = 0; i < length; i++){\n\t\t\t\tif(arr[i]%2 == 0){\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tnumOdd++;\n\t\t\t\t\tif(count != 0){\n\t\t\t\t\t\teven.add(count);\n\t\t\t\t\t}\n\t\t\t\t\tcount = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < even.size(); i++){\n\t\t\tif(even.elementAt(i) % 2 == 0){\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\tint evenDiv = even.size();\n\t\t\tint total = evenDiv;\n\t\t\t\n\t\t\tint singles = numOdd - 2*evenDiv;\n\t\t\t\n\t\t\tif(singles < 0){\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t\telse if((total + singles)%2 == 0){\n\t\t\t\tflag = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(flag?\"Yes\":\"No\");\n\t\t\n\t\tscan.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c89d46a3553a0b3e0c657d2f07ac6677", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "// @author Sanzhar\nimport java.io.*;\nimport java.util.*;\nimport java.awt.Point;\n\npublic class Template {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st;\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (Exception e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public void run() throws Exception {\n //in = new BufferedReader(new FileReader(\"input.txt\"));\n //out = new PrintWriter(new FileWriter(\"output.txt\"));\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.flush();\n out.close();\n in.close();\n }\n\n public void solve() throws Exception {\n int n = nextInt();\n if (n == 2) {\n out.println(0);\n return;\n }\n long d[] = {0, 1, 0, 3, 0, 15, 0, 133, 0, 2025, 0, 37851, 0, 1030367, 0, 36362925};\n long mod = 1000000007;\n long ans = 1;\n for (long i = 1; i <= n; i++) {\n ans *= i;\n ans %= mod;\n }\n ans = (ans * d[n]) % mod;\n out.println(ans);\n }\n\n public static void main(String[] args) throws Exception {\n new Template().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "953d29ee347a4a4c15b4d57d29c842f7", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class D_Round_175_Div2 {\n\n public static long MOD = 1000000007;\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 n = in.nextInt();\n if (n % 2 == 0) {\n out.println(0);\n }else if(n == 15){\n out.println(150347555);\n } else {\n long count = 0;\n int full = (1 << n) - 1;\n for (int z = 0; z < 1 << n; z++) {\n if (Integer.bitCount(z) == n / 2) {\n int[] first = new int[n / 2];\n int[] second = new int[n - (n / 2)];\n int a = 0;\n for (int i = 0; i < n; i++) {\n if (i < n / 2) {\n first[i] = i;\n } else {\n second[a++] = i;\n }\n }\n int[] c = new int[1 << n];\n do {\n a = 0;\n int tmp = 0;\n for (int i = 0; i < n; i++) {\n if (((1 << i) & z) != 0) {\n int v = (i + first[a++]) % n;\n tmp |= (1 << v);\n }\n }\n c[tmp]++;\n } while (nextPer(first));\n do {\n a = 0;\n int tmp = 0;\n for (int i = 0; i < n; i++) {\n if (((1 << i) & z) == 0) {\n int v = (i + second[a++]) % n;\n tmp |= (1 << v);\n }\n }\n count += c[full - tmp];\n } while (nextPer(second));\n\n }\n }\n for (int i = 1; i <= n; i++) {\n count *= i;\n count %= MOD;\n }\n out.println(count);\n }\n out.close();\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48263ab5aecb377ddd881437c12960d8", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class D {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint[] mas = {0,1,0,18,0,1800,0,670320,0,734832000,0,890786230,0,695720788,0,150347555};\n\t\tint n = sc.nextInt();\n\t\tSystem.out.println(mas[n]);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd93cc808afbe91c0397541d6ba9730a", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class D_Round_175_Div2 {\n\n public static long MOD = 1000000007; \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 n = in.nextInt();\n int[]data =new int[n];\n for(int i = 0; i < n; i++){\n \tdata[i] = i;\n }\n long count = 0;\n long total = 0;\n do{\n \tint check = 0;\n \tfor(int i = 0;i < n;i++){\n \t\tint x = (i + data[i])% n;\n \t\tcheck |= (1<= 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 }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bc2730c7a5882c54adc9ed5bed3b740e", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0} {"lang": "Java 8", "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 a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int d = sc.nextInt();\n \n int min_time = 0;\n \n int[] arr = {a,b,c};\n Arrays.sort(arr);\n if(arr[0] == arr[1]){\n min_time+= d;\n }\n else{\n if(d > (arr[1]-arr[0]))\n min_time+= d-(arr[1]-arr[0]);\n }\n \n if(arr[1] == arr[2]){\n min_time+= d;\n }\n else{\n if(d > (arr[1]-arr[0]))\n min_time+= d-(arr[1]-arr[0]);\n }\n System.out.println(min_time);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ee6667be451e30df4da0ffecab00ddbd", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\npackage math;\n\nimport java.util.Scanner;\n\npublic class Math {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long []array= new long[3];\n\n \n \n array[0]=in.nextInt();\n array[1]=in.nextInt();\n array[2]=in.nextInt();\n long temp=0;\n \n for (int i = 0; i < array.length; i++) {\n for (int j = 0; j < i; j++) {\n \n \n if (array[j]>array[j+1]) {\n temp=array[j];\n array[j]=array[j+1];\n array[j+1]=temp;\n\n \n }\n \n }}\n \n \n long d=in.nextInt();\n \n \n \n long value=0;\n \n \n if((array[2]-array[1])0) { a++; count++;}\n\t\telse\n\t\tif(x0) { b++; count++;}\n\t\telse\n\t\tif(y0) {c++; count++;}\n\t\telse\n\t\tif(z=d&y>=d&z>=d) s=false;\n\t\t\n\t}\n\tSystem.out.println(count);\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "01d3bb10036c1a90544d0b031030639b", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package CF568D2;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CF1185A {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tFastReader s = new FastReader();\n\t\tlong[] pos = new long [3];\n\t\tpos[0] = s.nextLong();\n\t\tpos[1] = s.nextLong();\n\t\tpos[2] = s.nextLong();\n\t\tlong d = s.nextLong();\n\t\tArrays.sort(pos);\n\t\tlong sol = 0;\n\t\tsol = Math.abs(d-Math.abs(pos[0]-pos[1]))+Math.abs(d-Math.abs(pos[2]-pos[1]));\n\t\tSystem.out.println(sol);\n\t}\n\tstatic class FastReader \n\t{ \n\t BufferedReader br; \n\t StringTokenizer st; \n\n\t public FastReader() \n\t { \n\t br = new BufferedReader(new\n\t InputStreamReader(System.in)); \n\t } \n\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\n\t int nextInt() \n\t { \n\t return Integer.parseInt(next()); \n\t } \n\n\t long nextLong() \n\t { \n\t return Long.parseLong(next()); \n\t } \n\n\t double nextDouble() \n\t { \n\t return Double.parseDouble(next()); \n\t } \n\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "261a03ec04313d3f6918f36fa4bbfbdd", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Problem275A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint[][] nums = new int[3][3];\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tfor (int j = 0; j < 3; j++) {\n\t\t\t\tnums[i][j] = sc.nextInt();\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tfor (int j = 0; j < 3; j++) {\n\t\t\t\tint sum = nums[i][j];\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tsum += nums[i-1][j];\n\t\t\t\t}\n\t\t\t\tif (i < 2) {\n\t\t\t\t\tsum += nums[i+1][j];\n\t\t\t\t}\n\t\t\t\tif (j > 0) {\n\t\t\t\t\tsum += nums[i][j-1]\n\t\t\t\t}\n\t\t\t\tif (j < 2) {\n\t\t\t\t\tsum += nums[i][j+1]\n\t\t\t\t}\n\t\t\t\tif (sum % 2 == 0) {\n\t\t\t\t\tSystem.out.print(\"1\");\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.print(\"0\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d907556b699c9f1d667ed4749eed5add", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.nio.Buffer;\nimport java.util.StringTokenizer;\n\npublic class codeforces_275A_new {\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}\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\n\t\t}\n\tpublic boolean[][] make_zero(int i,int j, boolean arr[][]) {\n\t\tfor (int k = 0; k < arr.length; k++) {\n\t\t\tarr[i][k]=!arr[i][k];\n\t\t}\n\t\tfor (int k = 0; k < arr.length; k++) {\n\t\t\tarr[k][j] = !arr[k][j];\n\t\t}\n\t\tarr[i][j]=!arr[i][j];\n\t\tprint_arr(arr);\n\t\tSystem.out.println();\n\t\t\n\t\treturn arr;\n\t\t\n\t\t\n\t}\n\tpublic void print_arr(boolean[][] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tfor (int j = 0; j < arr.length; j++) {\n\t\t\t\tif(arr[i][j]) {\n\t\t\t\t\tSystem.out.print(\"1 \");\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tSystem.out.print(\"0 \");\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}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\t\n\t\t\n\tpublic static void main(String[] args) {\n\t\tFastReader s = new FastReader();\n\t\tboolean arr[][] = new boolean[3][3];\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tfor (int j = 0; j < arr.length; j++) {\n\t\t\t\tarr[i][j]=true;\n\t\t\t}\n\t\t}\n\t\tcodeforces_275A ob = new codeforces_275A();\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tfor (int j = 0; j < arr.length; j++) {\n\t\t\t\tint k = s.nextInt();\n\t\t\t\tif(k%2!=0) {\n\t\t\t\t\tarr=ob.make_zero(i, j, arr);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tob.print_arr(arr);\n\t\t\n\t}\n\t}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e15aa71b9106003e33796c65c8f1902a", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.uitl.*;\nimport java.io.*;\npublic class solution{\n public static void main(String [] args){\n Scanner sc=new Scanner(System.in);\n int [][]temp=new int[3][3];\n for(int i=0;i<3;i++){\n for(int j=0;j<3;j++){\n int x=sc.nextInt();\n if(i-1>=0) temp[i-1][j]+=x;\n if(i+1<3) temp[i+1][j]+=x;\n if(j+1<3) temp[i][j+1]+=x;\n if(j-1>0) temp[i][j-1]+=x;\n }\n }\n int [][]res=new int[3][3];\n for(int i=0;i<3;i++){\n for(int j=0;j<3;j++){\n if(temp[i][j]%2==0) System.out.println(\"1\");\n else System.out.print(\"0\");\n }\n System.out.println();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bbd34fe9452d279c82279342ac1e314d", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class lights\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int a[][]=new int[3][3];\n int b[][]=new int[3][3];\n \n System.out.print(\"enter the matrix\");\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n {\n a[i][j]=sc.nextInt();\n }\n }\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n {\n b[i][j]=1;\n }\n }\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n {\n c[i][j]=a[i][j];\n }\n }\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n {\n if(a[i][j]>0)\n {\n for(int o=0;o<3;o++)\n {\n for(int p=0;p<3;p++)\n {\n for(int t=1;t<=a[i][j];t++)\n {\n \n if(b[i][j]==1)\n {\n b[i][j]=0;\n }\n else\n {\n b[i][j]=1;\n }\n if((i-1)>=0)\n {\n if(b[i-1][j]==1)\n b[i-1][j]=0;\n else\n b[i-1][j]=1;\n }\n if((i+1)<3)\n {\n if(b[i+1][j]==1)\n b[i+1][j]=0;\n else\n b[i+1][j]=1;\n }\n if((j-1)>=0)\n {\n if(b[i][j-1]==1)\n b[i][j-1]=0;\n else\n b[i][j-1]=1;\n }\n if(j+1<3)\n {\n if(b[i][j+1]==1)\n b[i][j+1]=0;\n else\n b[i][j+1]=1;\n }\n }\n }\n }\n }\n }\n }\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n System.out.print(b[i][j]);\n System.out.println();\n }\n }\n}\n \n \n \n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6baaf5a0dff14a5e30f226ce89b25f1b", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n public class Solution{\n public static void main(String args[]){\n Scanner s=new Scanner(System.in);\n String[] str=new String[21];\n int n=s.nextInt();\n str[0]=\"zero\";\n str[1]=\"one\";\n str[2]=\"two\";\n str[3]=\"three\";\n str[4]=\"four\";\n str[5]=\"five\";\n str[6]=\"six\";\n str[7]=\"seven\";\n str[8]=\"eight\";\n str[9]=\"nine\";\n\n str[10]=\"ten\";\n str[11]=\"eleven\";\n str[12]=\"twelve\";\n str[13]=\"thirteen\";\n\n str[14]=\"fourteen\";\n str[15]=\"fifteen\";\n str[16]=\"sixteen\";\n\n str[17]=\"seventeen\";\n str[18]=\"eighteen\";\n str[19]=\"ninteen\";\n str[20]=\"twenty\";\n if(n<=20){\n System.out.println(str[n]);\n }\n else{\n int a=n/10;\n int b=n%10;\n Stirng str1=\"\";\n if(a==2){\n str1+=\"twenty\";\n }\n if(a==3){\n str1+=\"thirty\";\n }\n if(a==4){\n str1+=\"forty\";\n }\n if(a==5){\n str1+=\"fifty\";\n }\n if(a==6){\n str1+=\"sixty\";\n }\n if(a==7){\n str1+=\"seventy\";\n }\n if(a=8){\n str1+=\"eighty\";\n }\n if(a=9){\n str1+=\"ninty\";\n }\n if(b!=0){\n str1+=\"-\"+str[b];\n }\n\n System.out.println(str1);\n \n }\n \n\n }\n\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6cff392d8fab15dafc4470a465f4da81", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "public class Main {\n\n\tpublic static void main(String[] args) {\n\n\t\tString[] arrOneToTen = { \"zero\", \"one\", \"two\", \"three\", \"four\", \"five\",\n\t\t\t\t\"six\", \"seven\", \"eight\", \"nine\", \"ten\", \"eleven\", \"twelve\",\n\t\t\t\t\"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"sevnteen\",\n\t\t\t\t\"eighteen\", \"nineteen\" };\n\n\t\tString[] twoDigits = { \"\", \"\", \"twenty\", \"thirty\", \"fourty\", \"fifty\",\n\t\t\t\t\"sixty\", \"seventy\", \"eighty\", \"ninety\" };\n\n\t\tScanner input = new Scanner(System.in);\n\t\twhile (input.hasNext()) {\n\n\t\t\tint number = input.nextInt();\n\n\t\t\tif (number >= 0 && number < 100) {\n\n\t\t\t\tif (number < 20) {\n\t\t\t\t\tSystem.out.println(arrOneToTen[number]);\n\t\t\t\t} else {\n\t\t\t\t\tchar[] str = String.valueOf(number).toCharArray();\n\t\t\t\t\tint firstVal = Integer.parseInt(String.valueOf(str[0]));\n\t\t\t\t\tint secondVal = Integer.parseInt(String.valueOf(str[1]));\n\t\t\t\t\tif (secondVal > 0) {\n\t\t\t\t\t\tSystem.out.println(twoDigits[firstVal] + \"-\"\n\t\t\t\t\t\t\t\t+ arrOneToTen[secondVal]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tSystem.out.println(twoDigits[firstVal]);\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e944bfb94189e8289afa6db3391c1f9b", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class file\n{\npublic static void main(String[] args)\n{Scanner sc=new Scanner(System.in);int a,b,t;\nt=sc.nextInt();\n{\n String arr[]={\"\",\"one\",\"two\",\"three\",\"four\",\"five\",\"six\",\"seven\",\"eight\",\"nine\",\"ten\",\"eleven\",\"twelve\",\"thirteen\",\"fourteen\",\"fifteen\",\"sixteen\",\"seventeen\",\"eighteen\",\"nineteen\"};\nString arr2[]={\"\",\"twenty\",\"thirty\",\"fourty\",\"fifty\",\"sixty\",\"seventy\",\"eighty\",\"ninety\"};\nif(t<20)\nSystem.out.println(arr[t]);\nelse{\na=t%10;b=t/10;\nif(a==0){System.out.println(arr2[b-1]);}\nelse\n{System.out.println(arr2[b-1]+\"-\"+arr[a]);}}}}}2", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7adba436e1e6ed4bed84658b88844935", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "mport java.util.Scanner;\n\n\npublic class Main {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n int n =0 ;\n String [] a = new String [100] ;\n a[0]= \"zero\" ;\n a[1]=\"one\";\n a[2]= \"two\";\n a[3]=\"three\";\n a[4]=\"four\";\n a[5]=\"five\";\n a[6]=\"six\";\n a[7]=\"seven\";\n a[8]= \"eight\";\n a[9]=\"nine\";\n a[10]=\"ten\";\n a[11]=\"eleven\";\n a[12]= \"twelve\";\n a[13]=\"thirteen\";\n a[14]=\"fourteen\";\n a[15]=\"fifteen\";\n a[16]=\"sixteen\";\n a[17]= \"seventeen\";\n a[18]=\"eighteen\";\n a[19]=\"ninteen\";\n a[20]=\"twenty\";\n a[21]= \"twenty-one\";\n a[22]=\"twenty-two\";\n a[23]=\"twenty-three\";\n a[24]=\"twenty-four\";\n a[25]=\"twenty-five\";\n a[26]=\"twenty-six\";\n a[27]=\"twenty-seven\";\n a[28]=\"twenty-eight\";\n a[29]=\"twenty-nine\";\n a[30]=\"thirty\";\n a[31]= \"thirty-one\";\n a[32]=\"thirty-two\";\n a[33]=\"thirty-three\";\n a[34]=\"thirty-four\";\n a[35]=\"thirty-five\";\n a[36]=\"thirty-six\";\n a[37]=\"thirty-seven\";\n a[38]=\"thirty-eight\";\n a[39]=\"thirty-nine\";\n a[40]=\"forty\";\n a[41]= \"forty-one\";\n a[42]=\"forty-two\";\n a[43]=\"forty-three\";\n a[44]=\"forty-four\";\n a[45]=\"forty-five\";\n a[46]=\"forty-six\";\n a[47]=\"forty-seven\";\n a[48]=\"forty-eight\";\n a[49]=\"forty-nine\";\n a[50]=\"fifty\";\n a[51]= \"fifty-one\";\n a[52]=\"fifty-two\";\n a[53]=\"fifty-three\";\n a[54]=\"fifty-four\";\n a[55]=\"fifty-five\";\n a[56]=\"fifty-six\";\n a[57]=\"fifty-seven\";\n a[58]=\"fifty-eight\";\n a[59]=\"fifty-nine\";\n a[60]=\"sixty\";\n a[61]= \"sixty-one\";\n a[62]=\"sixty-two\";\n a[63]=\"sixty-three\";\n a[64]=\"sixty-four\";\n a[65]=\"sixty-five\";\n a[66]=\"sixty-six\";\n a[67]=\"sixty-seven\";\n a[68]=\"sixty-eight\";\n a[69]=\"sixty-nine\";\n a[70]=\"seventy\";\n a[71]= \"seventy-one\";\n a[72]=\"seventy-two\";\n a[73]=\"seventy-three\";\n a[74]=\"seventy-four\";\n a[75]=\"seventy-five\";\n a[76]=\"seventy-six\";\n a[77]=\"seventy-seven\";\n a[78]=\"seventy-eight\";\n a[79]=\"seventy-nine\";\n a[80]=\"eighty\";\n a[81]= \"eighty-one\";\n a[82]=\"eighty-two\";\n a[83]=\"eighty-three\";\n a[84]=\"eighty-four\";\n a[85]=\"eighty-five\";\n a[86]=\"eighty-six\";\n a[87]=\"eighty-seven\";\n a[88]=\"eighty-eight\";\n a[89]=\"eighty-nine\";\n a[90]=\"ninety\";\n a[91]= \"ninety-one\";\n a[92]=\"ninety-two\";\n a[93]=\"ninety-three\";\n a[94]=\"ninety-four\";\n a[95]=\"ninety-five\";\n a[96]=\"ninety-six\";\n a[97]=\"ninety-seven\";\n a[98]=\"ninety-eight\";\n a[99]=\"ninety-nine\";\n Scanner scan = new Scanner(System.in);\n n = scan.nextInt() ;\n System.out.println(a[n]);\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5254c07b7455755d382cbae4e68e0996", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class CodeforcesProblem1011A {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n java.math.BigInteger n = sc.nextBigInteger();\n java.math.BigInteger k = sc.nextBigInteger();\n char[] s = sc.next().toCharArray();\n Arrays.sort(s);\n java.math.BigInteger weight = java.math.BigInteger.valueOf(s[0]).subtract(java.math.BigInteger.valueOf(96));\n k = k.subtract(java.math.BigInteger.ONE);\n char last = s[0];\n for (java.math.BigInteger i = java.math.BigInteger.ONE; i.compareTo(java.math.BigInteger.valueOf(s.length)) < 0; i = i.add(java.math.BigInteger.ONE)) {\n if (k.equals(java.math.BigInteger.ZERO)) {\n System.out.println(weight);\n return;\n }\n if (java.math.BigInteger.valueOf(s[i.intValue()]).compareTo(java.math.BigInteger.valueOf(last).add(java.math.BigInteger.TWO)) >= 0) {\n weight = weight.add(java.math.BigInteger.valueOf(s[i.intValue()]).subtract(java.math.BigInteger.valueOf(96)));\n last = java.math.BigInteger.valueOf(s[i.intValue()]).intValue();\n k = k.subtract(java.math.BigInteger.ONE);\n }\n }\n if (!k.equals(java.math.BigInteger.ZERO)) {\n System.out.println(-1);\n return;\n }\n System.out.println(weight);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b4ea6ed18cc003323ac773a752de0875", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0} {"lang": "Java 8", "source_code": "package interviewbit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Created by priyankvex on 26/7/18.\n */\npublic class Main {\n\n public static void main(String[] args) {\n\n BufferedReader br = new BufferedReader(\n new InputStreamReader(System.in));\n\n StringTokenizer st = null;\n try {\n st = new StringTokenizer(br.readLine());\n int n = Integer.parseInt(st.nextToken());\n int k = Integer.parseInt(st.nextToken());\n st = new StringTokenizer(br.readLine());\n String s = String.valueOf(st.nextToken());\n\n int result = new Stages().test(s, k, n);\n\n System.out.println(result);\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private static int test(String s, int k, int n){\n char[] c = s.toCharArray();\n Arrays.sort(c);\n int sum = 0;\n char last = '-';\n int stages = 0;\n\n for (int i = 0; i < n; i++){\n char curr = c[i];\n if (last == '-'){\n last = curr;\n sum = (int)curr - 96;\n stages++;\n continue;\n }\n\n if (curr <= last + 1){\n continue;\n }\n\n last = curr;\n sum = sum + ((int)curr - 96);\n stages++;\n\n if (stages == k){\n return sum;\n }\n }\n return -1;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2aaa88149c1cb27a50d884a7ce498d68", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.sql.Array;\nimport java.sql.ResultSet;\nimport java.sql.SQLException;\nimport java.util.*;\nimport java.util.List.*;\nimport java.util.concurrent.Executor;\nimport java.util.concurrent.ExecutorService;\nimport java.util.concurrent.Executors;\nimport java.util.stream.Collector;\nimport java.util.stream.Collectors;\n\n/*import org.springframework.beans.factory.xml.XmlBeanFactory;\nimport org.springframework.context.ApplicationContext;\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\nimport org.springframework.core.io.*;\n*/\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\t// ApplicationContext con = new\n\t\t// ClassPathXmlApplicationContext(\"bean.xml\");\n\t\tFastReader in = new FastReader();\n\t\tStringBuilder out = new StringBuilder();\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tboolean [] ch = new boolean[27];\n\t\tint sum=0;\n\t\tif(n==k){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tchar [] arr = in.next().toCharArray();\n\t\tArrays.sort(arr);\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tch[arr[i]-'a'+1]=true;\n\t\t}\n\t\tint j =0;\n\t\tfor (int i = 1; i < ch.length; i++) {\n\t\t\t\n\t\t\tif(ch[i]&&!ch[i-1]){\n\t\t\t\tsum+=i;\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif(j==k){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tif(j0)&&(k<=n)&&(n>=k)&&(n<=50))\n {\n \n for(int i=1;i1)\n {\n c=ar[i];\n sum=sum+((int)c-96);\n \n k=k-1;\n // System.out.print(\"sum \"+sum+\" and c is \"+c+\" and k is \"+k);\n }\n if(k==0)\n break;\n }\n}\nelse\nsum=-1;\nif(k>0)\nsum=-1;\n\nSystem.out.println(sum);\n}\n}\nimport java.util.*;\npublic class stages\n{\npublic static void main(String args[])\n{\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int k=sc.nextInt();\n char ar[]=new char[n];\n String st=sc.next();\n for(int i=0;i0)&&(k<=n)&&(n>=k)&&(n<=50))\n {\n \n for(int i=1;i1)\n {\n c=ar[i];\n sum=sum+((int)c-96);\n \n k=k-1;\n // System.out.print(\"sum \"+sum+\" and c is \"+c+\" and k is \"+k);\n }\n if(k==0)\n break;\n }\n}\nelse\nsum=-1;\nif(k>0)\nsum=-1;\n\nSystem.out.println(sum);\n}\n}\nimport java.util.*;\npublic class stages\n{\npublic static void main(String args[])\n{\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int k=sc.nextInt();\n char ar[]=new char[n];\n String st=sc.next();\n for(int i=0;i0)&&(k<=n)&&(n>=k)&&(n<=50))\n {\n \n for(int i=1;i1)\n {\n c=ar[i];\n sum=sum+((int)c-96);\n \n k=k-1;\n // System.out.print(\"sum \"+sum+\" and c is \"+c+\" and k is \"+k);\n }\n if(k==0)\n break;\n }\n}\nelse\nsum=-1;\nif(k>0)\nsum=-1;\n\nSystem.out.println(sum);\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "520a88d9cb28599221d3f10bb3c9b35e", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class BeautifulMatrix{\n private static final Scanner sc = new Scanner(System.in);\n public static void main(String[] args){\n int x, y;\n int[][] a = new int[5][5];\n for(int i = 0; i < 5; i++){\n for(int j = 0; j < 5; j++){\n a[i][j] = sc.nextInt();\n if(a[i][j] == 1){\n x = i;\n y = j;\n break;\n }\n }\n }\n System.out.println((Math.abs(x - 2) + Math.abs(y - 2)));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2cdde1573f9a8cd716b5ddf58e96dd37", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class CodeForces {\n\n\tpublic static void main(String[] args) {\n\t\tint a, b = 0, n = 0;\n\t\tScanner sc = new Scanner(System.in);\n\t\tfor (a = 0; a < 5 && n == 0; a++) {\n\t\t\tfor (b = 0; b < 5 && n == 0; b++) {\n\t\t\t\tn = sc.nextInt();\n\t\t\t}\n\t\t}\n\t\tif (a > 2) {\n\t\t\ta = a - 2;\n\t\t} else {\n\t\t\ta = 2 - a;\n\t\t}\n\t\tif (b > 2) {\n\t\t\tb = b - 2;\n\t\t} else {\n\t\t\tb = 2 - b;\n\t\t}\n\t\tSystem.out.println(a + b);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "672fa3f01de60357d2b2fa997b6dbe65", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Main {\n\tpublic static void main1 (String[] args) {\n\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n for (int i = 0; i <= 4; i++) {\n for (int j =0; j<=4; j++) {\n String x = reader.readLine();\n if (x.equals(\"1\")) {\n System.out.println(Math.abs(2 - i)+Math.abs(2 - j));\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "89b0add30a1ae6ad991b5039bdb969ac", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class beau\n{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int i,j,k,k1=0,k2=0;\n int a[][] = new int[5][5];\n for(i=0;i<5;i++)\n for(j=0;j<5;j++)\n a[i][j] = sc.nextInt();\n for(i=0;i<5;i++)\n {\n for(j=0;j<5;j++)\n {\n if(a[i][j]==1)\n {\n k1=i;\n k2=j;\n break;\n } \n }\n if(k1 && k2)\n break;\n }\n \n k = Math.abs(2-k1) + Math.abs(2-k2);\n System.out.println(k);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf6a7907091c494c0e6433748dbf4383", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class FindFactors{\n\t \n\t int[] factors = new int[100 * 1001];\n\t int pos = 0;\n\n\t public int[] calFactors(int n){\n while(n%2 == 0){\n \tn/=2;\n \tfactors[pos] = 2;\n \tpos++;\n }\n\n for(int i=3;i*i<=n;i+=2){\n \twhile(n%i == 0){\n \t\tn/=i;\n \t\tfactors[pos] = i;\n \t\tpos++;\n \t}\n }\n if(n > 1) factors[pos] = n;\n \n return factors;\n\t }\n}\npublic class FirstCode{\n public static void main(String[] args){\n \tint n, k;\n \tScanner sc = new Scanner(System.in);\n \tn = sc.nextInt();\n \tk = sc.nextInt();\n \n FindFactors findFact = new FindFactors();\n int[] arr = findFact.calFactors(n);\n int len = 0;\n while(arr[len] != 0) len++;\n\n if(len < k) System.out.println(\"-1\");\n else{\n \tfor(int i=0;i 1) factors[pos] = n;\n \n return factors;\n\t }\n}\npublic class Factor{\n public static void main(String[] args){\n \tint n, k;\n \tScanner sc = new Scanner(System.in);\n \tn = sc.nextInt();\n \tk = sc.nextInt();\n \n FindFactors findFact = new FindFactors();\n int[] arr = findFact.calFactors(n);\n int len = 0;\n while(arr[len] != 0) len++;\n\n if(len < k) System.out.println(\"-1\");\n else{\n \tfor(int i=0;i result;\n static ArrayList primes;\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n primes = new ArrayList();\n int n = in.nextInt();\n int k = in.nextInt();\n for (int i = 2; i * i <= n; i++) {//stores all primes from 2 to square root of n\n if (isPrime(i)) {\n primes.add(i);\n }\n }\n result = new ArrayList();\n factors(n, k);\n if (result.size() < k) {\n System.out.println(\"-1\");\n } else {\n for (int i = 0; i < result.size(); i++) {\n System.out.print(result.get(i) + \" \");\n }\n System.out.printf(\"\\n\");\n \n }\n \n }\n \n public static boolean isPrime(int t) {\n for (int i = 2; i * i <= t; ++i) {\n if (t % i == 0) {\n return false;\n }\n }\n return true;\n }\n \n public static void factors(int n, int k) {\n if (k <= 0) {\n return;\n }\n if (k == 1) {\n if (n != 1) {\n result.add(n);\n }\n return;\n \n }\n \n for (int i = 0; i < primes.size(); i++) {\n int num = primes.get(i);\n if (n % num == 0) {\n result.add(num);\n k--;\n factors(n / num, k);\n break;\n }\n }\n \n }\n \n}\n \nk-Factorization.txt\nDisplaying k-Factorization.txt.", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf38422a81bdb714bd3e95abb90d605a", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main{\n\tArbol arbol;\n\tHashMap map;\n\tArrayList divisores;\n\tpublic static void main(String[] args)throws IOException {\n\t\tMain principal = new Main();\n\t\tprincipal.input();\n\t}\n\n\tpublic void input() throws IOException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString cad = br.readLine();\n\t\tdivisores = new ArrayList();\n\t\tiniCriba();\n\t\tStringTokenizer st = new StringTokenizer(cad);\n\t\tint n = Integer.parseInt(st.nextToken()), k= Integer.parseInt(st.nextToken());\n\t\tSystem.out.println(solve(n, k - 1));\n\t}\n\n\tprivate void iniCriba(){\n\t\tboolean [] criba = new boolean[100001];\n\t\tint i = 2;\n\t\tcriba[0] = true;\n\t\tcriba[1] = true;\n\t\twhile (i*i <= 100001) {\n\t\t\tif (!criba[i]) {\n\t\t\t\tfor (int j = i; j < 100001; j+=i) {\n\t\t\t\t\tcriba[j] = true;\n\t\t\t\t}\n\t\t\t\tcriba[i] = false;\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\tfor (int j = 0; j < 100001; j++) {\n\t\t\tif (!criba[j]) {\n\t\t\t\tdivisores.add(j);\n\t\t\t}\n\t\t}\n\t}\n\tprivate String solve(int n, int k){\n\t\tint i = 0, valor, acum = 1;\n\t\tString answer = \"\", mult = \"\";\n\t\tint raiz = (int)Math.sqrt(n);\n\t\tvalor = divisores.get(i);\n\n\t\twhile (n != 1 && valor <= raiz) {\n\t\t\ti++;\n\t\t\twhile (n%valor == 0) {\n\t\t\t\tn/=valor;\n\t\t\t\tif (k == 0) {\n\t\t\t\t\tacum = acum*valor;\n\t\t\t\t} else {\n\t\t\t\t\tanswer = answer + valor + \" \" ;\n\t\t\t\t\tk--;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvalor = divisores.get(i);\n\t\t}\n\t\tif (acum != 1) {\n\t\t\tmult = \"\"+acum;\n\t\t}\n\t\tif (k != 0) {\n\t\t\tanswer = \"-1\";\n\t\t\tmult = \"\";\n\t\t}\n\t\treturn answer+mult;\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "be1cf1a0cad0845244758a064358df18", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class Main {\n static Map map = new HashMap();\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6b96e1f5cffbabf35e5183766353520e", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.lang.Math; \n\npublic class Lo {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n while(n>0){\n int x = n%10;\n n=n/10;\n if(x<5){\n System.out.print(\"O-|\");\n for(i = 0; i<5; i++){\n if(i==x){\n System.out.print('-');\n }\n else{\n System.out.print('O');\n }\n }\n }\n else{\n System.out.print(\"-O|\");\n for(i = 0; i<5; i++){\n if(i%5==x){\n System.out.print('-');\n }\n else{\n System.out.print('O');\n }\n }\n }\n System.out.println();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "45045948fa78d7d0c6ee04cde12e4776", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0} {"lang": "Java 7", "source_code": "//package codeforces;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\npublic class A {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n\n A() throws IOException {\n// reader = new BufferedReader(new FileReader(\"input.txt\"));\n// writer = new PrintWriter(new FileWriter(\"output.txt\"));\n }\n\n StringTokenizer stringTokenizer;\n\n String next() throws IOException {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n stringTokenizer = new StringTokenizer(reader.readLine());\n }\n return stringTokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n final int MOD = 1000 * 1000 * 1000 + 7;\n\n int sum(int a, int b) {\n a += b;\n return a >= MOD ? a - MOD : a;\n }\n\n int product(int a, int b) {\n return (int) (1l * a * b % MOD);\n }\n\n int pow(int x, int k) {\n int result = 1;\n while (k > 0) {\n if (k % 2 == 1) {\n result = product(result, x);\n }\n x = product(x, x);\n k /= 2;\n }\n return result;\n }\n\n int inv(int x) {\n return pow(x, MOD - 2);\n }\n\n\n void solve() throws IOException {\n boolean isZero = true;\n for(int n = nextInt(); n > 0; n /= 10) {\n isZero = false;\n int x = n % 10;\n if(x >= 5) {\n writer.print(\"-O|\");\n x -= 5;\n } else {\n writer.print(\"O-|\");\n }\n for(int i = 0; i < x; i++) {\n writer.print(\"O\");\n }\n writer.print(\"-\");\n for(int i = 0; i < 4 - x; i++) {\n writer.print(\"O\");\n }\n writer.println();\n }\n if(isZero) {\n writer.println(\"O-|-OOOO\")\n }\n writer.close();\n }\n\n public static void main(String[] args) throws IOException {\n new A().solve();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f20d96c831f2381934961689243018d2", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Main {\n\n\tpublic static void main(String[] args) {\t\n\t\t\n\t\tScanner input = new Scanner(System.in);\t\n\t\t\n\t\tStringBuilder ss = new StringBuilder(input.nextLine());\t\n\t\tint n =ss.length();\n\t\t\n\t\tfor (int i=1 ; i<=n ; i++){\n\t\t\tint x =Integer.parseInt(Character.toString(ss.charAt(ss.length()-1)));\n\t\t\tswitch (x) {\n\t\t\tcase 0:System.out.println(\"O-|-OOOO\");break;\n\t\t\tcase 1:System.out.println(\"O-|O-OOO\");break;\n\t\t\tcase 2:System.out.println(\"O-|OO-OO\");break;\n\t\t\tcase 3:System.out.println(\"O-|OOO-O\");break;\n\t\t\tcase 4:System.out.println(\"O-|OOOO-\");break;\n\t\t\tcase 5:System.out.println(\"-O|-OOOO\");break;\n\t\t\tcase 6:System.out.println(\"-O|O-OOO\");break;\t\n\t\t\tcase 7:System.out.println(\"-O|OO-OO\");break;\n\t\t\tcase 8:System.out.println(\"-O|OOO-O\");break;\n\t\t\tcase 9:System.out.println(\"-O|OOOO-\");break;\n\t\t\tdefault :\n\t\t\tSystem.out.println(\"awsf\");\n\t\t\t}\n\t\t\tif (ss.length()>1)\n\t\t\tss.append(ss.substring(0, ss.length()-1));\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\n\t\n\t}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dfc4d521ced3275f2793d510b84dd616", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\nimport static learning.TryB.w;\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 as;\n static HashSet hs;\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 char [][]sol;\n static int t2 = 0;\n static int t3 = 0;\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 \n \n long x = sc.nl();\n hs = new HashSet<>();\n primeFactors(x);\n if(x==1)\n w.println(\"1\");\n else\n {\n if(isprime(x))\n w.println(2 + hs.size()-1);\n else\n w.println(2+hs.size());\n }\n \n \n w.close();\n \n \n \n }\n static int digit(long x)\n {\n int p = 0;\n while(x > 0)\n {\n x /= 10;\n p++;\n }\n return p;\n }\n \n public static String f(String a,int b){\n if(b==0)\n return \"\";\n else if(b==1)\n return a;\n else{\n if(b%2==0)\n return f(a,b/2)+f(a,b/2);\n else\n return a+f(a,b/2)+f(a,b/2);\n }\n \n }\n \n \n static class Student\n {\n \n int first;\n int sec;\n Student(int first,int sec)\n {\n this.first = first;\n this.sec = sec;\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 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 void primeFactors(long n)\n {\n //hs = new HashSet<>();\n \n // Print the number of 2s that divide n\n while (n%2==0)\n {\n \n \n hs.add((long)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 (long 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 hs.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 hs.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 static long log2(long value) {\n return Long.SIZE-Long.numberOfLeadingZeros(value);\n}\n \n \n \n \n \n \n static boolean binarysearch(int []arr,int p,int n)\n {\n //ArrayList 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-st)/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\n\t{\n\t\tint index,to, l, r;\n\t\tint pred;\n\t\tpublic Edge(int to, int l ,int r)\n\t\t{\n\t\t\tthis.to = to;\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t}\n\n\t\tpublic int compareTo(Edge e)\n\t\t{\n\t\t\treturn (e.r - e.l+index) - (r-l+index);\n\t\t}\n\n\t\tpublic int hashCode()\n\t\t{\n\t\t\treturn to*31*31 + l*31 + r;\n\t\t}\n\n\t\tpublic equals(Object o)\n\t\t{\n\t\t\tEdge e = (Edge)o;\n\t\t\treturn e.to==to && l==o.l && r==o.r;\n\t\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\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\n\t\tint high[] = new int[n];\n\t\tint lo[] = new int[n];\n\t\tArrays.fill(high,Integer.MIN_VALUE);\n\t\tArrays.fill(lo,Integer.MAX_VALUE);\n\n\t\tArrayList e[] = new ArrayList[n];\n\t\tfor(int i = 0; i < n; i++)\n\t\t\te[i] = new ArrayList();\n\n\t\tfor(int i = 0; i < m; i++)\n\t\t{\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint a = Integer.parseInt(st.nextToken())-1;\n\t\t\tint b = Integer.parseInt(st.nextToken())-1;\n\t\t\tint l = Integer.parseInt(st.nextToken());\n\t\t\tint r = Integer.parseInt(st.nextToken());\n\t\t\te[a].add(new Edge(b,l,r));\n\t\t\tif(a!=b) e[b].add(new Edge(a,l,r));\n\t\t}\n\n\t\tPriorityQueue pq = new PriorityQueue();\n\t\tint ans = 0;\n\t\tpq.offer(new Edge(0,-1,1000000));\n\t\tHashSet hs = new HashSet();\n\n\t\twhile(!pq.isEmpty())\n\t\t{\n\t\t\tEdge ed = pq.poll();\n\t\t\tif(ed.to==n-1)\n\t\t\t{\n\t\t\t\tans = ed.r - ed.l + 1;\t\t\t\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(hs.contains(ed)) continue;\n\t\t\ths.add(ed);\n\t\t\tfor(Edge x: e[ed.to])\n\t\t\t{\n\t\t\t\tif(x.to==ed.to || x.to==ed.pred) \n\t\t\t\t\tcontinue;\n\t\t\t\tif(x.l > ed.r || x.r < ed.l) \n\t\t\t\t\tcontinue;\n\t\t\t\tpq.offer(new Edge(x.to,Math.max(x.l,ed.l),Math.min(x.r,ed.r));\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans==0?\"Nice work, Dima!\":ans);\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8ed725db4e6a1c448205a514aca6c17", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Problem1 {\n public static int num = -1;\n public static int ans1, ans2;\n public static int a[][];\n public static void main(String[] args){\n Problem1 program = new Problem1();\n program.go();\n if(num == -1) System.out.println(-1);\n else{\n num++;\n System.out.println(num + \" \" + ans1 + \" \" + ans2);\n }\n }\n\n public void go(){\n Scanner s = new Scanner(System.in);\n int sum;\n\n sum = s.nextInt();\n\n int a,b,c,d;\n\n for(int i=0; i<4; i++){\n a = s.nextInt();\n b = s.nextInt();\n c = s.nextInt();\n d = s.nextInt();\n\n if(a+c <= sum){\n if(a+c == sum){\n num = i;\n ans1 = a;\n ans2 = c;\n break;\n }else{\n num = i;\n ans1 = a;\n ans2 = sum - a;\n }\n }else if(a+d <= sum){\n if(a+d == sum){\n num = i;\n ans1 = a;\n ans2 = b;\n break;\n }else{\n num = i;\n ans1 = a;\n ans2 = sum - a;\n }\n }else if(b+c <= sum){\n if(b+c == sum){\n num = i;\n ans1 = b;\n ans2 = c;\n break;\n }else{\n num = i;\n ans1 = b;\n ans2 = sum - b;\n }\n }else if(b+d <= num){\n if(b+d == num){\n num = i;\n ans1 = b;\n ans2 = d;\n break;\n }else{\n num = i;\n ans1 = b;\n ans2 = sum - b;\n }\n }\n }\n\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bba7ba74ddd4b761561f4f588b3143b4", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Soft_Drinking {\n\n\tpublic static void main(String[] args) \n\t{\n\t Scanner sc = new Scanner(System.in);\n\t int n =sc.nextInt();\n\t int k =sc.nextInt();\n\t int l =sc.nextInt();\n\t int c =sc.nextInt();\n\t int d =sc.nextInt();\n\t int p =sc.nextInt();\n\t int nl =sc.nextInt();\n\t int np =sc.nextInt();\n\t System.out.println(Math.min(Math.min( (k*l)/n, c*d ), p/np]) /n);\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f205c7e36ef0f4b67a744727a69bff9", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class SumOfDigits\n{\n public static void main(String[] args) throws IOException\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 k=Integer.parseInt(s[1]);\n int l=Integer.parseInt(s[2]);\n int c=Integer.parseInt(s[3]);\n int d=Integer.parseInt(s[4]);\n int p=Integer.parseInt(s[5]);\n int nl=Integer.parseInt(s[6]);\n int np=Integer.parseInt(s[7]);\n int tl=(k*l)/n;\n int cd=c*d;\n int pnp=p/np;\n int ans=Math.min(tl,cd,pnp)/nl;\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6184f1481bac3e6e9703bff60d8676d3", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a[] = new int[8];\n\n for(int i=0; i<8; i++)\n a[i] = sc.nextInt();\n\n System.out.println(Math.min(Math.min(a[1]*a[2]/a[6], a[3]*a[4]), a[5]/a[7])/a[0]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "95e9cad82d9698980262383f3a74ae54", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0} {"lang": "Java 6", "source_code": "public class SoftDrinking {\n\n\tint getNumToasts(int n, int k, int l, int c, int d, int p, int nl, int np) {\n\t\tint toasts = (k * l) / nl;\n\t\ttoasts = Math.min(toasts, c * d);\n\t\ttoasts = Math.min(toasts, p / np);\n\t\t\n\t\treturn toasts / n;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = in.readLine();\n\t\tin.close();\n\t\t\n\t\tString[] t = s.split(\" \");\n\t\treturn getNumToasts\n\t\t\tInteger.parseInt(t[0]),\n\t\t\tInteger.parseInt(t[1]),\n\t\t\tInteger.parseInt(t[2]),\n\t\t\tInteger.parseInt(t[3]),\n\t\t\tInteger.parseInt(t[4]),\n\t\t\tInteger.parseInt(t[5]),\n\t\t\tInteger.parseInt(t[6]),\n\t\t\tInteger.parseInt(t[7])\n\t\t);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a42cd42fbd315e7c3620c2ce952d8c49", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class ttttt {\n\n public static void main(String[] args) throws ClassNotFoundException {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int a = scanner.nextInt();\n int b = scanner.nextInt();\n int c = scanner.nextInt();\n int result;\n\n int temp1 = findBest(a, b, n);\n int temp2 = findBest(b, c, n);\n int temp3 = findBest(a, c, n);\n \n result = Math.max(Math.max(temp1, temp2), temp3);\n\n System.out.println(result);\n }\n\n private static int findBest(int first, int second, int sum) {\n for (int i = 0; i <= sum ; i++) {\n for (int j = 0; j <= sum ;j++) {\n if ((first * i ) + (second * j) == sum) {\n return i + j;\n }\n }\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a6de9c34a72911a326c4ef7ecdbed1a6", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0} {"lang": "Java 7", "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\tint n = sc.nextInt();\n\t\tint[] val = new int[3];\n\t\tfor(int i=0; i<3; i++){\n\t\t\tval[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(val);\n\t\tint[] temp = new int[n+1];\n\t\t\n\t\tfor(int i=1; i result + 15)\n {\n result = result + 15;\n System.out.println(result); \n return;\n }\n \n result = minute;\n \n if (result >= 75)\n {\n result = 90;\n System.out.println(result); \n return; \n }\n } \n \n System.out.println(result); \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0bbd85a2116a9a689320eb6b1fe796d6", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\npublic class Main {\n final static int MAXN=91,stop=15;\n static boolean ok[]=new boolean[MAXN];\n public static void main(String[] args) throws IOException{\n BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n int n=Integer.parseInt(cin.readLine()),cont=0,con=0;\n String aux[]=cin.readLine().split(\" \");\n for(int i=0;i=stop)\n break;\n }\n out.write(cont+\"\\n\");\n out.flush();\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f555b6d16ecdd7af6ed4c3dde9fe701e", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class R351Div2A {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner in=new FastScanner();\n\t\tint n=in.nextInt();\n\t\tint[] a=new int[n];\n\t\tfor(int i=0;i15){\n\t\t\t\tSystem.out.println(15);\n\t\t\t}else{\n\t\t\t\tif(a[0]+15<=90)\n\t\t\t\t\tSystem.out.println(a[0]+15);\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(90);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor(int i=0;i15){\n\t\t\t\t\tSystem.out.println(15);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(a[i]-a[i-1]>15){\n\t\t\t\t\tSystem.out.println(a[i-1]+15);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t}\n\t\tSystem.out.println(90);\n\t\t\n\t}\n\tstatic class FastScanner{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(){br=new BufferedReader(new InputStreamReader(System.in));}\n\t\tString nextToken(){\n\t\t\twhile(st==null||!st.hasMoreElements())\n\t\t\t\ttry{st=new StringTokenizer(br.readLine());}catch(Exception e){}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){return Integer.parseInt(nextToken());}\n\t\tlong nextLong(){return Long.parseLong(nextToken());}\n\t\tdouble nextDouble(){return Double.parseDouble(nextToken());}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e950f7d87bcc65df740a2da38f519ee", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int first_input = sc.nextInt();\n int minutesWatched = 0;\n int current = sc.nextInt();\n int next = 0;\n \n while (sc.hasNextInt()){\n next = sc.hasNextInt();\n minutesWatched += getMinutes(current,next);\n current = next;\n \n }\n minutesWatched += getMinutes(current,90);\n Sytem.out.print(minutesWatched);\n }\n public static int getMinutes(int current,int next){\n if (next - current > 15){\n return 15;\n }else{\n return (next-current);\n }\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "23ae16c42ad8f9976afe15c2309761e6", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class BlackJack{\nstatic int ip(String s){\n\treturn Integer.parseInt(s);\n}\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n\t\tint n=ip(r.readLine());\n\t\t//int[] a=new int[n];\n\t\t//StringTokenizer str=new StringTokenizer(r.readLine());\n\t\tint alr=n-10;\n\t\t//int[] rem={2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,11};\n\t\t//System.out.println(find(rem,0,alr));\n\t\tif(alr==11)\n\t\t\tSystem.out.println(1);\n\t\telse if(alr==10)\n\t\t\tSystem.out.println(15);\n\t\telse if(adr==1)\n\t\t\tSystem.out.println(5);\n\t\telse if(adr==0)\n\t\t\tSystem.out.println(0);\n\t\telse \n\t\t\tSystem.out.println(4);\n\n}\n/*static int find(int[] a,int i,int sum){\n\t\tif(sum==0) return 1;\n\t\tif(sum<0) return 0;\n\t\tif(i==a.length) return 0;\n\t\treturn find(a,i+1,sum-a[i])+find(a,i+1,sum);\n}*/\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "96a27b986dc5479731cef2f281adafc3", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class blackjack {\n\n public static void main(String[] args) \n {\n Scanner sc = new Scanner(System.in);\n int = sc.nextInt();\n int[] array = {0, 0, 0, 0, 0,\n \t\t0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4, 0, 0, 0, 0};\n System.out.println(array[a]);\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e09fdac01f13b36e28bbed81b5b1056", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Blackjack\n{\npublic static void main(String []args){\nScanner s = new Scanner(System.in);\nint N = s.nextInt();\nif(n <= 10 || n > 21)\nSystem.out.println(\"0\");\nelse if(n == 20)\nSystem.out.println(\"15\");\nelse\nSystem.out.println(\"4\");\ns.close();\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7878fc73b87019e0923f9b32ad657107", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class passwordcheck {\npublic static void main(String[] args)\n{\n Scanner sc = new Scanner(System.in);\n \n System.out.println(s.length() >= 5 && contains(s, '0', '9') \n \t\t&& contains(s, 'a','z') && contains(s, 'A','Z') ? \"Correct\" : \"Too weak\");\n}\nstatic boolean contains(String s, char a, char b)\n{\n for(char c: s.toCharArray()) \n \tif(c>=a && c<=b)\n \t\treturn true;\n return false;\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4d7396f617dcf7d749bc04de5c0a8f77", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Solution{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n in.close();\n long k = 1;\n long a0 = 2, a1 = 3;\n while(n>=a1){\n long temp = a0 + a1;\n a0 = a1;\n a1 = temp;\n k++;\n }\n System.out.println(k);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "74bb15bc5277fe877e0305ceec82cc21", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author anuj64\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n outputWriter out = new outputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n HashMap F;\n\n public void solve(int testNumber, InputReader in, outputWriter out) throws IOException {\n long n = in.nextLong();\n F = new HashMap();\n F.put(0, 1l);\n F.put(1, 1l);\n F.put(2, 2l);\n int high = 90;\n int low = 0, mid = 0;\n while (high > low + 1) {\n mid = (low + high) / 2;\n Long res = f(mid);\n if (res > n) {\n high = mid;\n } else {\n low = mid;\n }\n // out.println(mid+\" \"+res);\n }\n out.println((low - 1));\n //for(int i = 0; i < 100; i++)\n //out.println(i+\" \"+f(i));\n }\n\n long f(int n) {\n if (F.containsKey(n)) return F.get(n);\n int k = n / 2;\n if (n % 2 == 0) { // n=2*k\n F.put(n, (f(k) * f(k) + f(k - 1) * f(k - 1)));\n } else { // n=2*k+1\n F.put(n, f(k) * f(k + 1) + f(k - 1) * f(k));\n }\n return F.get(n);\n }\n\n }\n\n static class InputReader {\n private byte[] buf = new byte[8000];\n private int index;\n private int total;\n private InputStream in;\n\n public InputReader(InputStream stream) {\n in = stream;\n }\n\n public int scan() {\n if (total == -1)\n throw new InputMismatchException();\n if (index >= total) {\n index = 0;\n try {\n total = in.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (total <= 0)\n return -1;\n }\n return buf[index++];\n }\n\n public long nextLong() {\n long integer = 0;\n int n = scan();\n while (isWhiteSpace(n))\n n = scan();\n int neg = 1;\n if (n == '-') {\n neg = -1;\n n = scan();\n }\n while (!isWhiteSpace(n)) {\n if (n >= '0' && n <= '9') {\n integer *= 10;\n integer += n - '0';\n n = scan();\n } else\n throw new InputMismatchException();\n }\n return neg * integer;\n }\n\n public boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1)\n return true;\n return false;\n }\n\n }\n\n static class outputWriter {\n BufferedWriter out;\n\n public outputWriter(OutputStream ot) {\n out = new BufferedWriter(new OutputStreamWriter(ot));\n }\n\n public outputWriter() {\n out = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n public void println(Object object) throws IOException {\n out.append(\"\" + object + \"\\n\");\n }\n\n public void close() throws IOException {\n out.close();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "735026b8babd919deed16c13ff228de5", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class PC {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long n = scanner.nextLong();\n long[] dp = new long[50000000];\n dp[0] = 0;\n dp[1] = 1;\n long i = 1;\n while (true){\n dp[i+1] = dp[i] + dp[i-1] + 1;\n if(dp[i+1] > n-1) break;\n i++;\n }\n System.out.println(i);\n\n\n\n\n\n\n\n }\n\n\n\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65d3773879070e3c88665f637f4cdc7c", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class p735c{\n\n\tpublic static void main(String args[]){\n\tScanner in=new Scanner(System.in);\n\tint fib[]=new int[100000000];\n\tfib[0]=1;fib[1]=1;\n\tlong n=in.nextLong();\n\tlong i,m=n-1;\n\tfor(i=0;;)\n\t{\n\t\tif(i>=2)\n\t\tfib[(int)i]=fib[(int)i-1]+fib[(int)i-2];\n\t\tm=m-fib[(int)i];\n\t\tif(m>=0)\n\t\t\ti++;\n\t\telse break;\n\t}\n\tSystem.out.println(i);\n}\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7b06468a6df8f648a3173378f31563b1", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class Xtend {\n\npublic static void main(String[] args)throws IOException{\nScanner input=new Scanner(System.in);\nint x1=input.nextInt();\nint y1=input.nextInt();\nint c1=input.nextInt();\nint x2=input.nextInt();\nint y2=input.nextInt();\nint c2=input.nextInt();\nif((x1==0 && y1==0)||(x2==0 && y2==0)){\n\tif(c1!=0 || c2!=0){\n\t\tSystem.out.println(0);\n\t}else{\n\t\tSystem.out.println(-1);\n\t}\n}else if(y1==0 || y2==0){\n\tif ((y1==0 && y2!=0) ||(y1!=0 && y2==0)){\n\tSystem.out.println(1);\n}else{\n\t{\n if(c1*x2==c2*x1){\n \tSystem.out.println(-1);\n }\n else{\n \tSystem.out.println(0);\n }\n }\n}\n}else{\n\t \n if(x1*y2==x2*y1)\n {\n if(c1*y2!=c2*y1)\n System.out.println(0);\n else System.out.println(-1);\n }\n else\n System.out.println(1);\n }\n }\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "68c0cb0cca2747f88964ae613f611b70", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int a1 = sc.nextInt();\n int b1 = sc.nextInt();\n int c1 = sc.nextInt();\n int a2 = sc.nextInt();\n int b2 = sc.nextInt();\n int c2 = sc.nextInt();\n int ans = 0;\n if(a1 == 0 & b1 == 0 & c1 != 0 || a2 == 0 & b2 == 0 & c2 != 0)\n {\n ans = 0;\n }\n else if((a1 * b2 - b1 * a2)!=0)\n {\n ans = 1;\n }\n else if(a1 * c2 == c1 * a2 || b1 * c2 == b2 * c1)\n {\n ans -1;\n }\n else\n {\n ans = 0;\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "21427379b3f8db6b228ae71a4d569a5a", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class PowerPoint\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nint a = 0;\nint b = 0;\nint[] as = new int[3];\nint[] bs = new int[3];\nfor(int i = 0;i < 3;i++)\n{\n as[i] = sc.nextInt();\n a += as[i];\n}\nfor(int i = 0;i < 3;i++)\n{\n bs[i] = sc.nextInt();\n b += bs[i];\n}\nif(a - b < 0)\n{\n System.out.println(-1);\n}\nelse\n{\n System.out.pritln(1);\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67d3b06bd5fb5312d04cad9fbe9b90e2", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int a1 = sc.nextInt();\n int b1 = sc.nextInt();\n int c1 = sc.nextInt();\n int a2 = sc.nextInt();\n int b2 = sc.nextInt();\n int c2 = sc.nextInt();\n int ans = 0;\n if(a1 == 0 & b1 == 0 & c1 != 0 || a2 == 0 & b2 == 0 & c2 != 0)\n {\n ans = 0;\n }\n else if((a1 * b2 - b1 * a2)!=0)\n {\n ans = 1;\n }\n else if(a1 * c2 == c1 * a2 || b1 * c2 == c1 * b2)\n {\n ans -1;\n }\n else\n {\n ans = 0;\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3a30737f3131e6a88450a7ff3e90a64", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0} {"lang": "Java 8", "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\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[]){\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 a=in.nextLong();\n\t\tlong b=in.nextLong();\n\t\tlong n=in.nextLong();\n\t\tlong x=in.nextLong();\n\t\tlong ans1=(modulo(a, n, mod)*x)%mod;\n\t\tlong ans2=((b*(modulo(a, n, mod)-1))%mod*modulo(a-1, mod-2, mod))%mod;\n\t\tif(a==(long)1){\n\t\t\tans2=b*n;\n\t\t\tans2%=mod;\n\t\t}\n\t\tlong ans=ans1+ans2;\n\t\tans%=mod;\n\t\tSystem.out.println(ans);\n\t\tout.close();\n\t\t//---------------The End------------------\n\n\t}\n\n\tpublic static void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tstatic long round(long x){\n\t\tif(x%10<5){\n\t\t\tx/=10;\n\t\t\tx*=10;\n\t\t\treturn x;\n\t\t}\n\t\telse{\n\t\t\tx/=10;\n\t\t\tx++;\n\t\t\tx*=10;\n\t\t\treturn x;\n\t\t}\n\t}\n\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 Pair implements Comparable{\n\t\tDouble x;\n\t\tint ind;\n\t\tPair(double xx,int yy){\n\t\t\tx=xx;\n\t\t\tind=yy;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn Double.compare(this.x, o.x);\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream inputstream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(inputstream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String nextLine(){\n\t\t\tString fullLine=null;\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tfullLine=reader.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\n\t\t}\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8f61fdb579cf27c4f05976bd8d5c029b", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Writer;\n \nimport java.util.InputMismatchException;\n \npublic class cf_practise{\nstatic long d=1000000007;\nstatic long check(long a)\n{\nif(a>d)\nreturn a%d;\nelse return a;}\n\npublic static void main(String args[]) {\nInputReader in = new InputReader(System.in);\n \n//OutputWriter st = new OutputWriter(System.out);\nlong a,b,x,n;\nlong ans=0;\na=in.readInt();\nb=in.readInt();\n\nn=in.readLong();\nx=in.readInt();\nif(a==1)\nans=check(x+check((n)*b));\nelse\n{\nlong c=exp(a,n);\nans=check(check(c*x)+check(b*check((c-1)*exp(a-1,d-2))));\n}\nSystem.out.println(ans);\n//st.printLine(Math.min(ans2,ans1));\n//st.close();\n\n}\nstatic long exp(long a,long b)\n{\nif(b==1)\nreturn a;\n \nif(b%2==0)\n{\nlong c=exp(a,b/2);\nlong e=c*c;\nreturn (e%d);\n}\n \nelse\n{\nlong c=exp(a,b/2);\nlong e=c*c;e%=d;\ne*=a;\nreturn (e%d);\n}}}\n\nclass InputReader {\n \nprivate InputStream stream;\n \nprivate byte[] buf = new byte[1024];\n \nprivate int curChar;\n \nprivate int numChars;\n \nprivate SpaceCharFilter filter;\n \npublic InputReader(InputStream stream) {\n \nthis.stream = stream;\n \n}\n \npublic int read() {\n \nif (numChars == -1) {\nthrow new InputMismatchException();\n}\n \nif (curChar >= numChars) {\n \ncurChar = 0;\n \ntry {\n \nnumChars = stream.read(buf);\n \n} catch (IOException e) {\n \nthrow new InputMismatchException();\n \n}\n \nif (numChars <= 0) {\nreturn -1;\n}\n \n}\nreturn buf[curChar++];\n \n}\n \npublic int readInt() {\n \nint c = read();\n \nwhile (isSpaceChar(c)) {\nc = read();\n}\n \nint sgn = 1;\n \nif (c == '-') {\n \nsgn = -1;\n \nc = read();\n \n}\n \nint res = 0;\n \ndo {\n \nif (c < '0' || c > '9') {\nthrow new InputMismatchException();\n}\n \nres *= 10;\nres += c - '0';\n \nc = read();\n \n} while (!isSpaceChar(c));\n \nreturn res * sgn;\n \n}\n \npublic String readString() {\n \nint c = read();\n \nwhile (isSpaceChar(c)) {\nc = read();\n}\n \nStringBuilder res = new StringBuilder();\n \ndo {\n \nres.appendCodePoint(c);\n \nc = read();\n \n} while (!isSpaceChar(c));\n \nreturn res.toString();\n \n}\n \npublic double readDouble() {\nint c = read();\nwhile (isSpaceChar(c)) {\nc = read();\n}\nint sgn = 1;\nif (c == '-') {\nsgn = -1;\nc = read();\n}\ndouble res = 0;\nwhile (!isSpaceChar(c) && c != '.') {\nif (c == 'e' || c == 'E') {\nreturn res * Math.pow(10, readInt());\n}\nif (c < '0' || c > '9') {\nthrow new InputMismatchException();\n}\nres *= 10;\nres += c - '0';\nc = read();\n}\nif (c == '.') {\nc = read();\ndouble m = 1;\nwhile (!isSpaceChar(c)) {\nif (c == 'e' || c == 'E') {\nreturn res * Math.pow(10, readInt());\n}\nif (c < '0' || c > '9') {\nthrow new InputMismatchException();\n}\nm /= 10;\nres += (c - '0') * m;\nc = read();\n}\n}\nreturn res * sgn;\n}\n \npublic long readLong() {\nint c = read();\nwhile (isSpaceChar(c)) {\nc = read();\n}\nint sgn = 1;\nif (c == '-') {\nsgn = -1;\nc = read();\n}\nlong res = 0;\ndo {\nif (c < '0' || c > '9') {\nthrow new InputMismatchException();\n}\nres *= 10;\nres += c - '0';\nc = read();\n} while (!isSpaceChar(c));\nreturn res * sgn;\n}\n \npublic boolean isSpaceChar(int c) {\n \nif (filter != null) {\nreturn filter.isSpaceChar(c);\n}\n \nreturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n \n}\n \npublic String next() {\n \nreturn readString();\n}\n \npublic interface SpaceCharFilter {\n \npublic boolean isSpaceChar(int ch);\n \n}\n \n}\n \nclass OutputWriter {\n \nprivate final PrintWriter writer;\n \npublic OutputWriter(OutputStream outputStream) {\n \nwriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n \n}\n \npublic OutputWriter(Writer writer) {\n \nthis.writer = new PrintWriter(writer);\n \n}\n \npublic void print(Object... objects) {\n \nfor (int i = 0; i < objects.length; i++) {\n \nif (i != 0) {\nwriter.print(' ');\n}\nwriter.print(objects[i]);\n \n}\n \n}\n \npublic void printLine(Object... objects) {\n \nprint(objects);\n \nwriter.println();\n \n}\n \npublic void close() {\n \nwriter.close();\n \n}\n \npublic void flush() {\n \nwriter.flush();\n \n}\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "85f9f694c3a41dff2172f1c8421ed9c3", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class IteratedLinearFunction {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tlong n = sc.nextLong();\n\t\tlong x = sc.nextLong();\n\t\t\n\t\tlong m = 1000000007;\n\t\tif (a==1){\n\t\t\tSystem.out.println((x+n*b)%m);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tBigInteger an = po(a,n,new BigInteger(\"\"+m));\n\t\tBigInteger an1 = po(a,n,new BigInteger(\"\"+m).multiply(new BigInteger((a-1)+\"\")));\n\t\tan1 = ((an1.add(new BigInteger(\"\"+m).multiply(new BigInteger((a-1)+\"\"))).subtract(new BigInteger(\"1\"))).divide(new BigInteger((a-1)+\"\")).mod(new BigInteger(\"\"+m)));\n\t\tSystem.out.println((an.multiply(new BigInteger(x+\"\")).mod(new BigInteger(m+\"\")).add(an1.multiply(new BigInteger(b+\"\"))).mod(new BigInteger(m+\"\"))));\n\t}\n\n\tprivate static BigInteger po(long a, long n, BigInteger m) {\n\t\tif (n==0) return new BigInteger(\"1\");\n\t\tif (n==1) return new BigInteger(\"\"+a);\n\t\tBigInteger r1 = po(a,n/2,m);\n\t\tBigInteger r2 = po(a,n%2,m);\n\t\tBigInteger br1 = new BigInteger(r1+\"\");\n\t\tBigInteger br2 = br1.multiply(br1);\n\t\tBigInteger brmod = br2.mod(new BigInteger(m+\"\"));\n\t\tbrmod = brmod.multiply(new BigInteger(r2+\"\"));\n\t\tbrmod = brmod.mod(new BigInteger(m+\"\"));\n\t\treturn brmod;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8868132687351134e881571e6455df6e", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class Foobaf {\n public static class FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n private static long gcd(long a, long b) {\n if (a == 0) {\n return b;\n }\n return gcd(b % a, a);\n }\n\n private static long lcm(long a, long b) {\n return (a * b) / gcd(a, b);\n }\n\n public static void main(String[] args) {\n FastScanner fs = new FastScanner();\n BigInteger A = new BigInteger(Integer.toString(fs.nextInt()));\n BigInteger B = new BigInteger(Integer.toString(fs.nextInt()));\n int n = fs.nextInt();\n BigInteger x = new BigInteger(Integer.toString(fs.nextInt()));\n\n if (A.compareTo(BigInteger.ONE) == 0) {\n System.out.println(B.multiply(new BigInteger(Integer.toString(n))).mod(new BigInteger(Integer.toString(1000000000 + 7)));\n return;\n }\n\n\n BigInteger result = (A.pow(n).subtract(BigInteger.ONE)).divide(A.subtract(BigInteger.ONE));\n result = B.multiply(result).add(A.pow(n).multiply(x));\n result = result.mod(new BigInteger(Integer.toString(1000000000 + 7)));\n\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2fb9cfd94630fe3467fb477284fe744b", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class Main {\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\tstatic ArrayList ans = new ArrayList<>();\n\n\tstatic void append(int x) {\n\t\tif (x == 1 || x == 0)\n\t\t\treturn;\n\t\telse if (x == 2)\n\t\t\tans.add(2);\n\t\telse if (x == 3)\n\t\t\tans.add(3);\n\t\telse if (x == 4) {\n\t\t\tans.add(2);\n\t\t\tans.add(2);\n\t\t\tans.add(3);\n\t\t} else if (x == 5)\n\t\t\tans.add(5);\n\t\telse if (x == 6) {\n\t\t\tans.add(5);\n\t\t\tans.add(3);\n\t\t} else if (x == 7)\n\t\t\tans.add(7);\n\n\t\telse if (x == 8) {\n\t\t\tans.add(2);\n\t\t\tans.add(2);\n\t\t\tans.add(2);\n\t\t\tans.add(7);\n\t\t} else if (x == 9) {\n\t\t\tans.add(2);\n\t\t\tans.add(3);\n\t\t\tans.add(3);\n\t\t\tans.add(7);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString a[] = br.readLine().split(\" \");\n\t\tint n = Integer.parseInt(a[0]);\n\t\tString s = br.readLine();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = s.charAt(i) - '0';\n\t\t\tappend(x);\n\t\t}\n\t\tCollections.sort(ans);\n\t\tfor (int i = ans.size() - 1; i >= 0; i--)\n\t\t\tpw.print(ans.get(i));\n\t\tbr.close();\n\t\tpw.flush();\n\t\tpw.close();\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e131463a6f6d8be281e620c2a7ec8d2", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n/**\n * \n */\npublic class Problem515C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int marking[] = new int[]{\n -1, //0\n -1, //1\n 2, //2\n 3, //3\n 322, //4\n 5,//5\n 53, //6\n 7,//7\n 7222,//8\n 7332,//9\n };\n String number = \"\";\n while(n>0){\n if(n%10 !=0 && n!=1) {\n number += (marking[n % 10]);\n }\n n = n/10;\n }\n int fNumber[] = new int[10];\n for(int i=0; i0;i--) {\n if(fNumber[i]!=0){\n repeated = i+\"\";\n repeated = repeated.repeat(fNumber[i]);\n number = number+repeated;\n }\n }\n System.out.println(number);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "abcc718489982116c9d64d06c15a9d07", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n static ArrayList check(char ch){\n int c=ch-'0';\n if(c==2){\n int ar[]={2};\n return Arrays.asList(ar);\n }\n else if(c==3){\n int ar[]={3};\n return Arrays.asList(ar);\n }else if(c==4){\n int ar[]={3,2,2};\n return Arrays.asList(ar);\n }else if(c==5){\n int ar[]={5};\n return Arrays.asList(ar);\n }else if(c==6){\n int ar[]={5,3};\n return Arrays.asList(ar);\n }else if(c==7){\n int ar[]={7};return Arrays.asList(ar);\n }else if(c==8){\n int ar[]={7,2,2,2};\n return Arrays.asList(ar);\n \n }else{\n int ar[]={7,3,3,2};\n return Arrays.asList(ar);\n }\n }\n public static void main(String args[]){\n \n \n Scanner s= new Scanner(System.in);\n int n=s.nextInt();\n ArrayList al=new ArrayList();\n String str= s.next().substring(0,n);\n for(int i=0;i1){\n al.addAll(check(str.charAt(i)));\n }\n }\n Collections.sort(al,Collections.reverseOrder());\n for(int i=0;iw1){\n lost = w1;\n }else{\n lost = w2;\n }\n return p1+p2+4-lost*2;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf99e9194a4d04fc32b8be32e4fdf462", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.lang.Math;\nimport java.io.*;\n\npublic class battle\n{\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tBufferedReader br =new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString s = br.readLine();\n\t\tString [] parts =s.split(\" \");\n\t\tlong w1 =Long.parseLong(parts[0]);\n\t\tint h1=Long.parseLong(parts[1]);\n\t\tint w2=Long.parseLong(parts[2]);\n\t\tint h2=Long.parseLong(parts[3]);\n\n\t\tSystem.out.println((h1+h2)*2+w1*2+4);\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b394fc5df94f726e948c8f40faeb3617", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\npublic class ProblemB {\n \n void run(){\n Scanner sc = new Scanner(System.in);\n long d=sc.nextInt();\n long i=0;\n long a=0;\n long b=0;\n long res; \n if (d<0) d*=-1;\n while((a<=d)){\n b=a;\n i++;\n a+=i; \n }\n if (b==d) \n res=i-1; \n else{ \n i++;\n a+=i; \n if (d%2==0){\n while((a%2!=0)){\n i++;\n a+=i; \n } \n }else {\n while((a%2==0)){\n i++;\n a+=i; \n } \n }\n res=i;\n } \n System.out.println(res); \n sc.close();\n }\n \n public static void main(String[] args) {\n new ProblemB().run(); \n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6d928a7aed3171518ac68840e14b61e6", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "public class JumpingJack {\npublic static void main(String[] args) {\nScanner s=new Scanner(System.in);\nfinal int x=Math.abs(s.nextInt());\n\nint n=0;\nint p=0;\nwhile(p < x) {\n n++;\n p+=n;\n}\nif( p-x > 0 ) {\nwhile( (p-x)%2==1 ) {\nn++;\np+=n;\n}\n}\nSystem.out.println(n);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae89b64576f9bd6cc220951d2c0b71b2", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\npublic class JumpingJack {\npublic void main(String[] args) {\nScanner s=new Scanner(System.in);\nfinal int x=s.nextInt();\nint p=0;\nint n=0;\nwhile(p= n) {\nn++;\np+=n;\n}\nreturn n;\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6bf637fec391d80b58821c784b4c4efe", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\npublic class JumpingJack {\npublic void main(String[] args) {\nScanner s=new Scanner(System.in);\nfinal int x=s.nextInt();\nint p=0;\nint n=0;\nwhile(p= n) {\nn++;\np+=n;\n}\nreturn n;\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ac2b5fb241f8b16aafa4ac0957b5acb9", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint x = input.nextInt();\n\t\tint y = input.nextInt();\n\t\tint z = input.nextInt();\n\t\tint w = input.nextInt();\n\t\t\n\t\tif(x == 0 && y == 1 && z == 1 && w == 0){\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tif(x == 0 && y == 0 && z == 0 && w == 0){\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tif(x == 1 && y == 0 && z == 0 && w == 0){\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tif(x == 0 && y == 1 && z == 0 && w == 0){\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\twhile(true){\n\t\t\t\n\t\t}\n//\t\tif(x == 0){\n//\t\t\tif(y == 0){\n//\t\t\t\tint[] arr = new int[1000000000];\n//\t\t\t}\n//\t\t\telse{\n//\t\t\t\tthrow new Error();\n//\t\t\t}\n//\t\t}\n//\t\telse{\n//\t\t\tif(y == 0){\n//\t\t\t\twhile(true){\n//\t\t\t\t\t\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\telse{\n//\t\t\t\tSystem.out.println(\"WRONG\");\n//\t\t\t}\n//\t\t}\n\t\t\n\t\t\n\t\t\tif(z == 0){\n\t\t\t\tif(w == 0){\n\t\t\t\t\tint[] arr = new int[1000000000];\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tthrow new Error();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(w == 0){\n\t\t\t\t\twhile(true){\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tSystem.out.println(\"WRONG\");\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9376985fd41997ba9a89ff87c0696d63", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int a1=sc.nextInt();\n int a2=sc.nextInt();\n System.out.println((int)(Math.random*1));\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4bb54b4f8deb10facda228f238cfcd36", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import Scanner;\n\npublic class Star{\n\n public static void main(Str args[]){\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n long ans = 1;\n long g = 0;\n for( int i = 2; i <= n; i++){\n g += 12;\n ans += g; \n }\n System.out.println(ans);\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "35cf1e70c2f338992d512f510f480bdb", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class Main{ public static void main(String...args){Scanner sc = new Scanner(System.in);\n int a = sc.nextInt(); System.out.println(-18*a*a + 12*a - 5);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c40d176cf45d7f8f9f4e16f727de6499", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\npublic class Main {\n public static void main(String args[]) {\n // Your Code Here\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong a = sc.nextLong(),b=sc.nextLong();\n\t\tlong num = x ^ y;\n long msb = 0;\n while (num != 0) {\n num = num >> 1;\n msb++;\n }\n long result = 1;\n while (msb-- > 0) {\n result = result << 1;\n }\n\t\tSystem.out.println(result-1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2d9924e6f4b7162d8b7f18f0361ee667", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n \n boolean hasBit(long n, int pos) {\n return (n & (1L << pos)) != 0;\n }\n \n public void solve() throws Exception {\n long l = sc.nextLong(), r = sc.nextLong();\n int bit = 62;\n while (bit >= 0 && (hasBit(l, bit) == hasBit(r, bit))) {\n bit--;\n }\n out.println((1L << (bit + 1)) - 1);\n }\n \n static Throwable uncaught;\n \n BufferedReader in;\n FastScanner sc;\n PrintWriter out;\n \n @Override\n public void run() {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n sc = new FastScanner(in);\n solve();\n } catch (Throwable uncaught) {\n Solution.uncaught = uncaught;\n } finally {\n out.close();\n }\n }\n \n public static void main(String[] args) throws Throwable {\n Thread thread = new Thread (null, new Solution(), \"\", (1 << 26));\n thread.start();\n thread.join();\n if (Solution.uncaught != null) {\n throw Solution.uncaught;\n }\n }\n\n}\n\nclass FastScanner {\n \n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() throws Exception {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n \n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "08efcf43c230e869f4deedae70a37a7d", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Xor {\n public static void main(String[] args) {\n Scanner input=new Scanner(System.in);\n long a=input.nextLong();\n long b=input.nextLong();\n long yy=Math.max(2 * Long.highestOneBit(a ^ b) - 1,0);\n System.out.println(y);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8d2325a147cd36b3eafe89622037de63", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskD {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long from = in.readLong();\n long to = in.readLong();\n\n String strFrom = Long.toBinaryString(from);\n String strTo = Long.toBinaryString(to);\n\n while (strFrom.length() < strTo.length())\n strFrom = \"0\" + strFrom;\n\n for (int i = 0; i < strFrom.length(); i++) {\n if (strFrom.charAt(i) == '0' && strTo.charAt(i) == '1') {\n out.printLine((1L << (strFrom.length() - i)) - 1);\n return;\n }\n }\n\n out.printLine(0);\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n}\n\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskD {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long from = in.readLong();\n long to = in.readLong();\n\n long x = 0;\n long y = 0;\n\n for (int i = 0; i < 63; i++) {\n long curX = x | (1L << i);\n long curY = y | (1L << i);\n\n if ((x < from && curX <= to) || (curY > to && curX <= to) || (curX >= from && curX <= to))\n x = curX;\n else if ((y < from && curY <= to) || (curX > to && curY <= to) || (curY >= from && curY <= to))\n y = curY;\n }\n\n if (x < from || y < from)\n out.printLine(0);\n else\n out.printLine(x ^ y);\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a7d75424676eb00b5f525f0ff471eb87", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Main {\n\n static class Task {\n int testNo, testDay;\n\n public Task(int testNo, int testDay) {\n this.testNo = testNo;\n this.testDay = testDay;\n }\n }\n\n public static void main(String[] args) throws Exception {\n\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n String[] temp = in.readLine().split(\" \");\n int n = Integer.parseInt(temp[0]);\n int m = Integer.parseInt(temp[1]);\n\n PriorityQueue pq = new PriorityQueue<>(new Comparator() {\n @Override\n public int compare(Task o1, Task o2) {\n return Integer.compare(o1.testDay, o2.testDay);\n }\n });\n\n int[] req = new int[n + 1];\n int[] examDays = new int[n + 1];\n Arrays.fill(examDays, -1);\n ArrayList[] l = new ArrayList[n + 1];\n Task[] ts = new Task[m + 1];\n for (int i = 1; i <= m; i++) {\n temp = in.readLine().split(\" \");\n int s = Integer.parseInt(temp[0]);\n int d = Integer.parseInt(temp[1]);\n int c = Integer.parseInt(temp[2]);\n if (l[s] == null) l[s] = new ArrayList<>();\n l[s].add(i);\n ts[i] = new Task(i, d);\n req[i] = c;\n examDays[d] = i;\n }\n\n int[] counts = new int[m + 1];\n ArrayList s = new ArrayList<>();\n for (int d = 1; d <= n; d++) {\n if (l[d] != null) {\n for (int t: l[d]) {\n pq.add(ts[t]);\n }\n }\n\n if (examDays[d] != -1 && req[examDays[d]] != counts[examDays[d]]) {\n System.out.println(-1);\n return;\n } else if (examDays[d] != -1) {\n s.add(m + 1);\n continue;\n }\n\n if (pq.isEmpty()) {\n s.add(0);\n continue;\n }\n Task t = pq.poll();\n s.add(t.testNo);\n counts[t.testNo]++;\n if (req[t.testNo] > counts[t.testNo]) {\n pq.add(new Task(t.testNo, t.testDay));\n }\n// System.out.println(Arrays.toString(s.toArray()));\n }\n\n StringBuilder st = new StringBuilder();\n for (int d: s) {\n st.append(d).append(\" \");\n }\n System.out.println(st.toString());\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cc1933cde402f359a724f2c02a2feef2", "src_uid": "02d8d403eb60ae77756ff96f71b662d3", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import com.radium4ye.cf.round481.div3.C_978_G;\n\nimport java.util.*;\n\n/**\n * @author radium4ye\n */\npublic class Test {\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\n //\u6bcf\u65e5\u7684\u5b89\u6392\n int[] day = new int[n + 1];\n\n List list = new ArrayList<>();\n for (int i = 0; i < m; i++) {\n C_978_G.Exam exam = new C_978_G.Exam(i + 1, s.nextInt(), s.nextInt(), s.nextInt());\n list.add(exam);\n day[exam.examTime] = m + 1;\n }\n\n list.sort(Comparator.comparing(C_978_G.Exam::getExamTime));\n\n\n //\u8003\u8bd5\u6700\u65e9\u7684\u4f18\u5148\n for (int i = 0; i < m; i++) {\n C_978_G.Exam exam = list.get(i);\n\n int prepareDay = exam.prepareDay;\n for (int j = exam.startTime; j < exam.examTime; j++) {\n //\u51c6\u5907\u5b8c\u6bd5\n if (prepareDay == 0) {\n break;\n }\n\n //\u7b2cj\u5929\u4f11\u606f\n if (day[j] == 0) {\n prepareDay--;\n day[j] = exam.num;\n }\n }\n\n //\u6ca1\u65f6\u95f4\u51c6\u5907\n if (prepareDay > 0) {\n System.out.println(\"-1\");\n return;\n }\n }\n\n for (int i = 1; i <= n; i++) {\n System.out.printf(day[i] + \" \");\n }\n\n }\n\n public static class Exam {\n int num;\n int startTime;\n int examTime;\n int prepareDay;\n\n public Exam(int num, int startTime, int examTime, int prepareDay) {\n this.num = num;\n this.startTime = startTime;\n this.examTime = examTime;\n this.prepareDay = prepareDay;\n }\n\n public int getExamTime() {\n return examTime;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b7bd46141160b038d7aac7b3670d6f06", "src_uid": "02d8d403eb60ae77756ff96f71b662d3", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\n/**\n * Date: 13 May, 2018\n * Link:\n *\n * @author Prasad-Chaudhari\n * @email prasadc8897@gmail.com\n */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class newProgram4 {\n\n public static void main(String[] args) throws IOException {\n // TODO code application logic here\n FastIO2 in = new FastIO2();\n int n = in.ni();\n int m = in.ni();\n if (m == n) {\n System.out.println(-1);\n return;\n }\n Data d[] = new Data[m];\n for (int i = 0; i < m; i++) {\n int s = in.ni();\n int ds = in.ni();\n int c = in.ni();\n d[i] = new Data(s, ds, c,i);\n }\n (new Heapsort()).sort(d);\n int ans[] = new int[n + 1];\n for (int i = 0; i < m; i++) {\n ans[d[i].b] = m + 1;\n }\n\n// for (int j : ans) {\n// System.out.print(ans[j] + \" \");\n// }\n// System.out.println(\"\");\n int put = 1;\n for (int i = 0; i < m; i++) {\n if (put <= n) {\n while (d[i].c > 0) {\n// System.out.println(\"Put:\" + put);\n if (put <= n) {\n// System.out.println(put + \" \" + d[i].a + \" \" + d[i].b + \" \");\n if (put >= d[i].a && ans[put] == 0 && put < d[i].b) {\n ans[put] = d[i].d + 1;\n// System.out.println(put + \" \" + ans[put]);\n d[i].c--;\n }\n put++;\n } else {\n break;\n }\n }\n// for (int j : ans) {\n// System.out.print(ans[j] + \" \");\n// }\n// System.out.println(\"\");\n } else {\n break;\n }\n }\n// for (int j : ans) {\n// System.out.print(ans[j] + \" \");\n// }\n// System.out.println(\"\");\n for (int i = 0; i < m; i++) {\n if (d[i].c != 0) {\n System.out.println(\" -1\");\n return;\n }\n }\n for (int i=1;i<=n;i++) {\n System.out.print(ans[i] + \" \");\n }\n }\n\n static class FastIO2 {\n\n private final BufferedReader br;\n private String s[];\n private int index;\n\n public FastIO2() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n s = br.readLine().split(\" \");\n index = 0;\n }\n\n public int ni() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public double nd() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public long nl() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public String next() throws IOException {\n return nextToken();\n }\n\n public String nli() throws IOException {\n try {\n return br.readLine();\n } catch (IOException ex) {\n\n }\n return null;\n }\n\n public int[] gia(int n) throws IOException {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = ni();\n }\n return a;\n }\n\n public int[] gia(int n, int start, int end) throws IOException {\n validate(n, start, end);\n int a[] = new int[n];\n for (int i = start; i < end; i++) {\n a[i] = ni();\n }\n return a;\n }\n\n public double[] gda(int n) throws IOException {\n double a[] = new double[n];\n for (int i = 0; i < n; i++) {\n a[i] = nd();\n }\n return a;\n }\n\n public double[] gda(int n, int start, int end) throws IOException {\n validate(n, start, end);\n double a[] = new double[n];\n for (int i = start; i < end; i++) {\n a[i] = nd();\n }\n return a;\n }\n\n public long[] gla(int n) throws IOException {\n long a[] = new long[n];\n for (int i = 0; i < n; i++) {\n a[i] = ni();\n }\n return a;\n }\n\n public long[] gla(int n, int start, int end) throws IOException {\n validate(n, start, end);\n long a[] = new long[n];\n for (int i = start; i < end; i++) {\n a[i] = ni();\n }\n return a;\n }\n\n private String nextToken() throws IndexOutOfBoundsException, IOException {\n if (index == s.length) {\n s = br.readLine().split(\" \");\n index = 0;\n }\n return s[index++];\n }\n\n private void validate(int n, int start, int end) {\n if (start < 0 || end >= n) {\n throw new IllegalArgumentException();\n }\n }\n }\n\n}\n\nclass Heapsort {\n\n private int n;\n private Item a[];\n\n public void sort(int a[]) {\n n = a.length;\n this.a = new Item[n];\n for (int i = 0; i < n; i++) {\n this.a[i] = new Item(a[i]);\n }\n sorting();\n n = a.length;\n for (int i = 0; i < n; i++) {\n a[i] = this.a[i].i;\n }\n }\n\n public void sort(long a[]) {\n n = a.length;\n this.a = new Item[n];\n for (int i = 0; i < n; i++) {\n this.a[i] = new Item(a[i]);\n }\n sorting();\n n = a.length;\n for (int i = 0; i < n; i++) {\n a[i] = this.a[i].l;\n }\n }\n\n public void sort(char a[]) {\n n = a.length;\n this.a = new Item[n];\n for (int i = 0; i < n; i++) {\n this.a[i] = new Item(a[i]);\n }\n sorting();\n n = a.length;\n for (int i = 0; i < n; i++) {\n a[i] = this.a[i].c;\n }\n }\n\n public void sort(double a[]) {\n n = a.length;\n this.a = new Item[n];\n for (int i = 0; i < n; i++) {\n this.a[i] = new Item(a[i]);\n }\n sorting();\n n = a.length;\n for (int i = 0; i < n; i++) {\n a[i] = this.a[i].d;\n }\n }\n\n public void sort(String a[]) {\n n = a.length;\n this.a = new Item[n];\n for (int i = 0; i < n; i++) {\n this.a[i] = new Item(a[i]);\n }\n sorting();\n n = a.length;\n for (int i = 0; i < n; i++) {\n a[i] = this.a[i].s;\n }\n }\n\n public void sort(Data a[]) {\n n = a.length;\n this.a = new Item[n];\n for (int i = 0; i < n; i++) {\n this.a[i] = new Item(a[i]);\n }\n sorting();\n n = a.length;\n for (int i = 0; i < n; i++) {\n a[i] = this.a[i].data;\n }\n }\n\n private void sorting() {\n heapify();\n for (int i = n; i > 0; i--) {\n swap(0, i);\n n = n - 1;\n maxheap(0);\n }\n }\n\n private void heapify() {\n n = a.length - 1;\n for (int i = n / 2; i >= 0; i--) {\n maxheap(i);\n }\n }\n\n private void maxheap(int i) {\n int left = 2 * i;\n int right = 2 * i + 1;\n int max = i;\n if (left <= n && a[left].compareTo(a[i]) > 0) {\n max = left;\n }\n if (right <= n && a[right].compareTo(a[max]) > 0) {\n max = right;\n }\n if (max != i) {\n swap(i, max);\n maxheap(max);\n }\n }\n\n private void swap(int i, int j) {\n Item temp = a[j];\n a[j] = a[i];\n a[i] = temp;\n }\n\n private class Item implements Comparable {\n\n Integer i;\n Long l;\n Character c;\n Double d;\n String s;\n Data data;\n\n public Item(int a) {\n i = a;\n }\n\n public Item(long a) {\n l = a;\n }\n\n public Item(char a) {\n c = a;\n }\n\n public Item(double a) {\n d = a;\n }\n\n public Item(Data a) {\n data = a;\n }\n\n public Item(String a) {\n s = a;\n }\n\n @Override\n public int compareTo(Item item) {\n if (i != null) {\n return i.compareTo(item.i);\n } else if (l != null) {\n return l.compareTo(item.l);\n } else if (c != null) {\n return c.compareTo(item.c);\n } else if (d != null) {\n return d.compareTo(item.d);\n } else if (s != null) {\n return s.compareTo(item.s);\n } else {\n return data.compareTo(item.data);\n }\n }\n }\n}\n\nclass Data implements Comparable {\n\n int a, b, c,d;\n\n public Data(int a, int b, int c,int d) {\n this.a = a;\n this.b = b;\n this.c = c;\n this.d=d;\n }\n\n @Override\n public int compareTo(Data o) {\n if (this.a == o.a) {\n if (this.b == o.b) {\n return Integer.compare(this.c, o.c);\n }\n return Integer.compare(this.b, o.b);\n }\n return Integer.compare(this.a, o.a);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "df04240834b69620e9823c3c932e3bee", "src_uid": "02d8d403eb60ae77756ff96f71b662d3", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.awt.*;\n import java.util.*;\n import java.math.*;\n\npublic class Main{\n public static Comparator COMP = new Comparator() {\n @Override\n public int compare(four o1, four o2) {\n return o1.b-o2.b;\n }\n };\n\n static PriorityQueue in = new PriorityQueue<>(COMP);\n static int n, m;\n static Vector inn = new Vector<>();\n static void exit(){\n System.out.print(-1);\n System.exit(0);\n }\n static void exit1(int a, int b, int c, int d){\n System.out.print(a + \" \" + b + \" \" + c + \" \" + d);\n System.exit(0);\n }\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n m = sc.nextInt();\n for(int i = 1; i <= m; i++){\n int t1, t2, t3;\n t1 = sc.nextInt();\n t2 = sc.nextInt();\n t3 = sc.nextInt();\n\n in.add(new four(i,t1, t2, t3));\n inn.add(t2);\n }\n int[] day = new int[1000];\n for(int i = 0; i < 101; i++)day[i]=0;\n for(int i = 0; i < inn.size(); i++)day[inn.get(i)]=m+1;\n while(in.size()>0){\n four now = in.remove();\n int it = 0;\n for(int d = now.b; d < now.dn; d++){\n if(day[d]==0){day[d]=now.ex; it++;}\n if(it == now.d)break;\n }\n if(it!=now.d)exit();\n }\n for(int i = 1; i <= n; i++)System.out.print(day[i]+\" \");\n }\n}\n\n\nclass four{\n int ex;\n int b;\n int d;\n int dn;\n four(int a, int b, int c, int d){\n ex = a;\n this.b = b;\n this.dn = c;\n this.d = d;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9df1b41f919ad32598a6a28b0c90d8d9", "src_uid": "02d8d403eb60ae77756ff96f71b662d3", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "//#62783240 1244C - The Football Season\nimport java.util.*;\npublic class Sol{\n public static void main(String[] args){\n Scanner s=new Scanner(System.in);\n String str1=s.next();\n String str2=s.next();\n long n = Long.parseLong(str1);\n long p = Long.parseLong(str2);\n long w=s.nextInt();\n long d=s.nextInt();\n boolean flag=true;\n long x=0;\n long y=0;\n long z=0;\n long p1=p;\n if((p==0 || p>=d) && n*w>=p1){\n x=p1/w;\n p1=p1%w;\n if(p1>0){\n y=p1/d;\n p1=p1%d;\n if(p1>0 && w%d!=0){\n for(int i=1;i<100000;i++){\n if((i*w+p1)%d==0){\n x-=i;\n y=y+(i*w+p1)/d;\n p1=(i*w+p1)%d;\n break;\n }\n }\n else{\n flag=false;\n }\n }\n z=n-x-y;\n }\n else{\n flag=false;\n }\n if(!flag){\n System.out.println(\"-1\");\n }\n else{\n System.out.println(x+\" \"+y+\" \"+z);\n }\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "de137e4a886c8b82e92bb3888832fc8e", "src_uid": "503116e144d19eb953954d99c5526a7d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class F {\n public static void main(String[] args) throws IOException {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n StringTokenizer st = new StringTokenizer(reader.readLine());\n long n = Long.parseLong(st.nextToken());\n long p = Long.parseLong(st.nextToken());\n long w = Long.parseLong(st.nextToken());\n long d = Long.parseLong(st.nextToken());\n if(w * n < p){\n System.out.println(-1);\n return;\n }\n if(p == 0){\n System.out.println(0 + \" \" + 0 + \" \" + n);\n return;\n }\n if(d > p){\n System.out.println(-1);\n return;\n }\n boolean[] was = new boolean[(int)d];\n for(long i = 0; i < d + 1; ++i){\n if((w * i) % p == p % d){\n long j = p / w;\n long m = w * j;\n while(j % d != i){\n m -= w;\n j--;\n }\n if(j <= 0){\n long c = p / d;\n if(p % d != 0 || c > n){\n System.out.println(-1);\n return;\n }\n else{\n System.out.println(0 + \" \" + c + \" \" + n - c);\n }\n }\n else {\n p %= (w * j);\n long k = p / d;\n if(j + k > n){\n System.out.println(-1);\n return;\n }\n System.out.println(j + \" \" + k + \" \" + (n - j - k));\n return;\n }\n }\n else{\n if(was[(int)i]){\n break;\n }\n else{\n was[(int)i] = true;\n }\n }\n }\n System.out.println(-1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1a873e6cb2dd398161e7647b1e46e6c5", "src_uid": "503116e144d19eb953954d99c5526a7d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "//#62783240 1244C - The Football Season\nimport java.util.*;\npublic class Sol{\n public static void main(String[] args){\n Scanner s=new Scanner(System.in);\n String str1=s.next();\n String str2=s.next();\n long n = Long.parseLong(str1);\n long p = Long.parseLong(str2);\n long w=s.nextInt();\n long d=s.nextInt();\n boolean flag=true;\n long x=0;\n long y=0;\n long z=0;\n long p1=p;\n if((p==0 || p>=d) && n*w>=p1){\n x=p1/w;\n p1=p1%w;\n if(p1>0){\n y=p1/d;\n p1=p1%d;\n if(p1>0 && w%d!=0){\n for(int i=1;i<100000;i++){\n if((i*w+p1)%d==0){\n x-=i;\n y=y+(i*w+p1)/d;\n p1=(i*w+p1)%d;\n break;\n }\n }\n }\n else{\n flag=false;\n }\n z=n-x-y;\n }\n else{\n flag=false;\n }\n if(!flag){\n System.out.println(\"-1\");\n }\n else{\n System.out.println(x+\" \"+y+\" \"+z);\n }\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3b85c7e8eba4c1419f7b191743341d70", "src_uid": "503116e144d19eb953954d99c5526a7d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class TheFootballSeason {\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 static class TaskA {\n long mod = (long)(1000000007);\n long min = Long.MAX_VALUE;\n long max = Long.MIN_VALUE;\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n while(testNumber-->0){\n long n = in.nextLong();\n long p = in.nextLong();\n long w = in.nextLong();\n long d = in.nextLong();\n if(p>n*w){\n \tout.println(-1);\n \tcontinue;\n }\n min = Math.max(0 , (p-n*d)/(w-d));\n max = p/w;\n long rem1 = p%d;\n long rem2 = (n*d - p)%d;\n long q1 = rem1 - w*()\n for(long x = min;x<=max;x++){\n \tlong a = (p-w*x);\n \tlong b = n*d - p + (w-d)*x;\n \tif(a%d == 0 && b%d == 0){\n \t\tlong y = a/d;\n \t\tlong z = b/d;\n \t\tout.println(x + \" \" + y + \" \" + z);\n \t\tbreak;\n \t}\n }\n }\n }\n class Combine{\n int value;\n int delete;\n Combine(int val , int delete){\n this.value = val;\n this.delete = delete;\n }\n }\n class Sort2 implements Comparator{\n public int compare(Combine a , Combine b){\n if(a.value > b.value)\n return 1;\n else if(a.value == b.value && a.delete>b.delete)\n return 1;\n else if(a.value == b.value && a.delete == b.delete)\n \treturn 0;\n return -1;\n }\n }\n public int lowerBound(ArrayList a , int x){\n int l = 0;\n int r = a.size()-1;\n if(a.get(l)>=x)\n return -1;\n if(a.get(r)=x)\n r = mid-1;\n else if(a.get(mid)=x)\n return mid;\n else if(a.get(mid) a , int x){\n int l = 0;\n int r = a.size()-1;\n if(a.get(l)>x)\n return l;\n if(a.get(r)<=x)\n return r+1;\n int mid = -1;\n while(l<=r){\n mid = (l+r)/2;\n if(a.get(mid) == x && a.get(mid+1)>x)\n return mid+1;\n else if(a.get(mid)<=x)\n l = mid+1;\n else if(a.get(mid)>x && a.get(mid-1)<=x)\n return mid;\n else if(a.get(mid)>x && a.get(mid-1)>x)\n r = mid-1;\n }\n return mid;\n }\n public int log(int x){\n return (int) Math.ceil((Math.log(x) / Math.log(2)+10e-10));\n }\n public long gcd(long a , long b){\n if(a[] readGraph(int vertexNumber, int edgeNumber, boolean undirected)\n {\n List[] graph = new List[vertexNumber];\n \n for (int index = 0; index < vertexNumber; ++index)\n {\n graph[index] = new ArrayList();\n }\n \n while (edgeNumber-- > 0)\n {\n int from = nextInt() - 1;\n int to = nextInt() - 1;\n \n graph[from].add(to);\n if(undirected)\n graph[to].add(from);\n }\n \n return graph;\n }\n }\n\n public static void main(String[] arg) \n {\n new D1().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "831b0846681d80f089e695ecda9c577e", "src_uid": "6f9767b63a01424f939d85b597cf42f3", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class BigData {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(System.in);\n\t\tint i = in.nextInt();\n\t\tint[] ans = new int[] {1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0};\n\t\tSystem.out.println(ans[i-1]);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a3b199b503ead43982afab9a06026ea", "src_uid": "6f9767b63a01424f939d85b597cf42f3", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class CodeForce {\n\t\n\t\n\n\tpublic static void main(String[] args) {\n\t\tScanner ac = new Scanner(System.in);\n\t\tint n = ac.nextInt();\n\t\tSystem.out.println(n & 1);\n\t\t//This is funny.\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a5b066a6e5866ba06156963e120207b0", "src_uid": "6f9767b63a01424f939d85b597cf42f3", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "public class BigData {\n\tprivate static int [] facts = {0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0};\n\tpublic static void main(String [] args) {\n\t\tint in = new Scanner(System.in).nextInt();\n\t\tSystem.out.println(facts[in]);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8b65333a86ff056794e853f1e765e17", "src_uid": "6f9767b63a01424f939d85b597cf42f3", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String s = sc.nextLine();\n char z = 'a';\n int count=0;\n for(int i=0;iz) {\n z = a;\n count = 0;\n } else if(s.charAt(i)==z) {\n count++;\n }\n }\n StringBuilder sb = new StringBuilder();\n for(int i=0;i maxChar) {\n maxChar = c;\n }\n }\n for (char c : input) {\n if (c == maxChar) {\n System.out.print(c);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dafbfebac2401aad234f0f78b31e7530", "src_uid": "9a40e9b122962a1f83b74ddee6246a40", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.math.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class Codeforces{\n\n static class Valueable\n {\n int a,b;\n Valueable(int x,int y)\n {\n a=x;\n b=y;\n }\n }\n\n static class Sortbyroll implements Comparator \n { \n // Used for sorting in ascending order of \n // roll number \n public int compare(Valueable a, Valueable b) \n { \n return a.a - b.a; \n } \n } \n\n static int findMaxElementIndex(int ar[])\n {\n int index=0;\n int max=0;\n int n=ar.length;\n for(int i=0;imax)\n {\n max=ar[i];\n index=i;\n }\n }\n return index;\n }\n\n static int findMaxElement(int ar[])\n {\n int max=0;\n int n=ar.length;\n for(int i=0;imax)\n {\n max=ar[i];\n }\n }\n return max;\n }\n\n static void printArray(int ar[]) throws Exception\n {\n BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), \"ASCII\"), 512);\n for(int i=0;ic)\n {\n c=s.charAt(i);\n }\n freq[s.charAt(i)]++;\n }\n for(int i=0;i div = new ArrayList<>();\n for(long i=1;i * i<=n;i++)\n if(n%i == 0) {\n div.add(i);\n if(n/i != i)\n div.add(n/i);\n }\n Collections.sort(div);\n for(int i=div.size()-1;i>=0;i--) {\n long x = div.get(i);\n boolean lovely = true;\n for(long j = 2;j*j<=x;j++)\n if(x%(j*j) == 0) {\n lovely = false;\n break;\n }\n if(lovely) {\n out.print(x);\n return;\n }\n }\n\n }\n\n static int nextInt() throws IOException {\n return parseInt(next());\n }\n\n static long nextLong() throws IOException {\n return parseLong(next());\n }\n\n static double nextDouble() throws IOException {\n return parseDouble(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 public static void main(String[] args) {\n try {\n //in = new BufferedReader(new FileReader(\"/Users/abdelnacer/Desktop/code/C.in\"));\n //out = new PrintWriter(new BufferedWriter(new FileWriter(\"/Users/abdelnacer/Desktop/code/C.out\")));\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n long lStartTime = System.currentTimeMillis();\n solve();\n long lEndTime = System.currentTimeMillis();\n //System.out.println(\"Elapsed time in seconds: \" + (double)(lEndTime - lStartTime) / 1000.0);\n in.close();\n out.close();\n } catch (Throwable e) {\n e.printStackTrace();\n exit(1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d8568b9cf1fd824cc7bf03431440a290", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.*;\n import java.util.*;\n\n\n public class main {\n static BufferedReader in;\n static PrintWriter out;\n static StringTokenizer tok;\n\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 int nextInt() throws IOException{\n return Integer.parseInt(next());\n }\n \n\n static long nextLong() throws IOException{\n return Long.parseLong(next());\n }\n \n public static void main(String[] args) throws IOException {\n // TODO Auto-generated method stub\n in = new BufferedReader(new InputStreamReader(System.in));\n long n = nextLong();\n long i=2;\n long res=1;\n double q = (double) n;\n while (n>1 & n<(1+(int)q)){\n if (n%i==0) res=res*i;\n while (n%i==0){\n n = n / i;\n }\n i++;\n }\n System.out.println(res);\n\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dc2c3675bfafaec53e3bd014a25700cc", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class B implements Runnable {\n \n private void solve() throws IOException {\n long n = nextLong();\n ArrayList divisors = new ArrayList<>();\n for (long i = 1; i * i <= n; i++) {\n if (n % i == 0) {\n divisors.add(i);\n if (i != n / i)\n divisors.add(n / i);\n }\n }\n Collections.sort(divis ors);\n Collections.reverse(divisors);\n \n end: for (long div : divisors) {\n long d = div;\n long p = 2;\n int cnt = 0;\n while (p * p <= d) {\n if (d % p == 0) {\n d /= p;\n ++cnt;\n if (cnt == 2) continue end;\n } else {\n ++p;\n cnt = 0;\n }\n }\n pl(div);\n break;\n }\n }\n \n\n public static void main(String[] args) {\n new B().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run() {\n try {\n reader = new BufferedReader(new BufferedReader(new InputStreamReader(System.in)));\n writer = new PrintWriter(System.out);\n tokenizer = null;\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n void p(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n void pl(Object... objects) {\n p(objects);\n writer.println();\n }\n\n int cc;\n\n void pf() {\n writer.printf(\"Case #%d: \", ++cc);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1ead00ece6277b17740936ab55e14728", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class a\n{\n public static void main(String [] args)\n {\n Scanner in=new Scanner();\n String s=in.next();\n if(CharAt[0]>='a'&&CharAt[0]<='z'&&s.substring(1).istoUpperCase())\n {\n System.out.print(s.CharAt[0].toUpperCase()+s.substring(1).toLowerCase());\n \n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9b056ce07b03a759532d22b4e4b62cdb", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class test\n{\n public static void main(String [] args)\n {\n Scanner in=new Scanner(System.in);\n String inp=in.next();\n String op=\"\";\n boolean flag1=null,flag2=null;\n char arr[]=inp.toCharArray();\n for(int i=0;i uniqueWords = new HashMap();\n\n static {\n uniqueWords.put(0, \"\");\n uniqueWords.put(1, \"one\");\n uniqueWords.put(2, \"two\");\n uniqueWords.put(3, \"three\");\n uniqueWords.put(4, \"four\");\n uniqueWords.put(5, \"five\");\n uniqueWords.put(6, \"six\");\n uniqueWords.put(7, \"seven\");\n uniqueWords.put(8, \"eight\");\n uniqueWords.put(9, \"nine\");\n uniqueWords.put(10, \"ten\");\n uniqueWords.put(11, \"eleven\");\n uniqueWords.put(12, \"twelve\");\n uniqueWords.put(13, \"thirteen\");\n uniqueWords.put(14, \"fourteen\");\n uniqueWords.put(15, \"fifteen\");\n uniqueWords.put(16, \"sixteen\");\n uniqueWords.put(17, \"seventeen\");\n uniqueWords.put(18, \"eighteen\");\n uniqueWords.put(19, \"nineteen\");\n uniqueWords.put(20, \"twenty\");\n uniqueWords.put(30, \"thirty\");\n uniqueWords.put(40, \"forty\");\n uniqueWords.put(50, \"fifty\");\n uniqueWords.put(60, \"sixty\");\n uniqueWords.put(70, \"seventy\");\n uniqueWords.put(80, \"eighty\");\n uniqueWords.put(90, \"ninety\");\n uniqueWords.put(100, \"hundred\");\n uniqueWords.put(1000, \"one thousand\");\n }\n\n static public String getLetterRepresentation(int num) {\n StringBuilder numInWords = new StringBuilder();\n if (num <= 20) {\n numInWords.append(uniqueWords.get(num));\n } else if (num < 100) {\n numInWords.append(uniqueWords.get((num / 10) * 10)).append(\" \").append(uniqueWords.get(num % 10));\n } else if (num == 1000) {\n numInWords.append(uniqueWords.get(num));\n } else if (num % 100 == 0) {\n numInWords.append(uniqueWords.get(num / 100)).append(\" \").append(uniqueWords.get(100));\n } else if (num < 1000) {\n int temp = num % 100;\n numInWords.append(uniqueWords.get((num / 100))).append(\" \").append(uniqueWords.get(100)).append(\" \").append(\"and\").append(\" \");\n if (temp <= 20) {\n numInWords.append(uniqueWords.get(temp));\n } else {\n numInWords.append(uniqueWords.get((temp / 10) * 10)).append(\" \").append(uniqueWords.get(temp % 10));\n }\n }\n\n return numInWords.toString();\n }\n\n static public String calculateLargePower(long num, long pow) {\n String power = \"1\";\n for (int i = 1; i <= pow; i++) {\n power = multiplyTwoLargeNumberFaster(power, String.valueOf(num));\n }\n return power;\n }\n\n static String addLargeNumbersOfSameLength(String num1, String num2) {\n List sum = new LinkedList();\n // Assuming length of num1 and num2 are same.\n int carry = 0;\n for (int i = num1.length() - 1; i >= 0; i--) {\n int temp1 = num1.charAt(i) - 48;\n int temp2 = num2.charAt(i) - 48;\n int tempSum = temp1 + temp2 + carry;\n sum.add(String.valueOf(tempSum % 10));\n carry = tempSum / 10;\n }\n if (carry > 0) {\n sum.add(String.valueOf(carry));\n }\n StringBuilder finalsum = new StringBuilder();\n for (int i = sum.size() - 1; i >= 0; i--) {\n finalsum.append(Integer.parseInt(sum.get(i)));\n }\n\n return finalsum.toString();\n }\n\n static public String addLargeNumbersOfSameLengthUseBlock(String num1, String num2) {\n // StringBuilder sum = new StringBuilder();\n List sum = new LinkedList();\n int blockSize = String.valueOf(Integer.MAX_VALUE).length() - 1;\n int lengthOfNumber = num1.length();\n if (lengthOfNumber <= blockSize)\n return String.valueOf(Integer.parseInt(num1)+Integer.parseInt(num2));\n // Assuming length of num1 and num2 are same.\n int carry = 0;\n for (int i = lengthOfNumber - 1; i >= 0; i -= blockSize) {\n int startIndex = i - blockSize + 1;\n if (startIndex < 0) {\n startIndex = 0;\n }\n String tempNum1 = num1.substring(startIndex, i + 1);\n String tempNum2 = num2.substring(startIndex, i + 1);\n String tempSum = String.valueOf(Integer.parseInt(tempNum1) + Integer.parseInt(tempNum2)\n + carry);\n if (tempSum.length() > blockSize && startIndex != 0) {\n carry = 1;\n tempSum = tempSum.substring(1);\n } else {\n carry = 0;\n }\n sum.add(0, Integer.parseInt(tempSum));\n }\n StringBuilder finalSum = new StringBuilder();\n for (Integer integer : sum) {\n finalSum.append(integer);\n }\n return finalSum.toString();\n }\n\n static public String addTwoLargeNumbers(String num1, String num2) {\n if (num1.length() == num2.length())\n return addLargeNumbersOfSameLengthUseBlock(num1, num2);\n else\n return addLargeNumbersOfDifferentLength(num1, num2);\n }\n\n private static String addLargeNumbersOfDifferentLength(String num1, String num2) {\n int length1 = num1.length();\n int length2 = num2.length();\n StringBuilder newNum = new StringBuilder();\n String sum = \"\";\n if (length1 > length2) {\n for (int i = 0; i < length1 - length2; i++) {\n newNum.append(\"0\");\n }\n newNum.append(num2);\n sum = addLargeNumbersOfSameLengthUseBlock(num1, newNum.toString());\n } else {\n for (int i = 0; i < length2 - length1; i++) {\n newNum.append(\"0\");\n }\n newNum.append(num1);\n sum = addLargeNumbersOfSameLengthUseBlock(newNum.toString(), num2);\n }\n return sum;\n }\n\n static public long getLCM(long lcm2, long b) {\n long lcm = lcm2 * b;\n long gcd = getGCD(lcm2, b);\n lcm = lcm / gcd;\n return lcm;\n }\n\n static public long getGCD(long lcm2, long b) {\n int gcd = 1;\n if (lcm2 == 0 || b == 0)\n return 1;\n else if (lcm2 == 1 || b == 1)\n return 1;\n else {\n if (lcm2 % b == 0)\n return b;\n else if (b % lcm2 == 0)\n return lcm2;\n else if (lcm2 > b)\n return getGCD(lcm2 % b, b);\n else if (lcm2 < b)\n return getGCD(lcm2, b % lcm2);\n }\n return gcd;\n }\n\n static public boolean isPrime(long n) {\n boolean isPrime = true;\n if (1 == n) {\n isPrime = false;\n } else if (2 == n) {\n isPrime = true;\n } else if (n % 2 == 0) {\n isPrime = false;\n } else {\n double sqrt = Math.sqrt(n);\n for (int i = 3; i <= sqrt; i += 2) {\n if (n % i == 0) {\n // System.out.println(n+\" is not a prime number.Divisible by \"+i);\n isPrime = false;\n break;\n }\n }\n }\n /*\n * if(true == isPrime){ System.out.println(n +\" is a prime number\"); }\n */\n return isPrime;\n }\n\n public static boolean isPalindrome(String inputNumber) {\n boolean isPalindrome = true;\n String num1 = new StringBuilder(inputNumber).reverse().toString();\n if (!num1.equals(inputNumber)) {\n isPalindrome = false;\n }\n return isPalindrome;\n }\n\n static public boolean isPalindrome(int n) {\n return isPalindrome(String.valueOf(n));\n }\n\n static public int getNumOfDigits(Long number) {\n int digitsCount = 0;\n while (number > 0) {\n number = number / 10;\n digitsCount++;\n }\n return digitsCount;\n }\n\n static public long getNthPrime(int n) {\n long[] primes = getListOfFirstNPrimes(n);\n return primes[n - 1];\n }\n\n static public List getListOfPrimesLessThanN(int n) {\n List primes = new LinkedList();\n if (n >= 2) {\n primes.add(2l);\n long j = 3;\n if (n > 2) {\n for (; j <= n; j++) {\n boolean isPrime = true;\n long temp = primes.get(0);\n for (int k = 1; temp <= Math.sqrt(j); k++) {\n if (j % temp == 0) {\n isPrime = false;\n break;\n }\n temp = primes.get(k);\n }\n if (true == isPrime && j <= n) {\n primes.add(j);\n }\n if (j > n) {\n break;\n }\n }\n }\n\n }\n return primes;\n }\n\n static public long[] getListOfFirstNPrimes(int n) {\n long primes[] = new long[n];\n primes[0] = 2;\n long j = 3;\n for (int i = 1; i < n; j++) {\n boolean isPrime = true;\n for (int k = 0; primes[k] <= Math.sqrt(j); k++) {\n long temp = primes[k];\n if (j % temp == 0) {\n isPrime = false;\n break;\n }\n }\n if (true == isPrime) {\n primes[i++] = j;\n }\n }\n return primes;\n }\n\n static public int getNumOfFactors(long n) {\n if (n == 1)\n return 1;\n else if (isPrime(n))\n return 2;\n else {\n int numOfFactors = 1;\n List primeFactors = getPrimeFactors(n);\n int[] primeFactorsPowers = new int[primeFactors.size()];\n int k = 0;\n for (Long long1 : primeFactors) {\n long temp = n;\n int count = 1;\n while (0 == temp % long1) {\n temp = temp / long1;\n count++;\n }\n primeFactorsPowers[k++] = count;\n }\n if (primeFactors.size() == 0)\n return 2;\n for (int i : primeFactorsPowers) {\n numOfFactors *= i;\n }\n return numOfFactors;\n }\n\n }\n\n public static List getPrimeFactors(long n) {\n List primeFactors = new LinkedList();\n int sqrt = (int) Math.sqrt(n);\n // List primes_Less_Than_N = list_Of_Primes_Less_Than_N(sqrt);\n for (long temp = 2; temp <= sqrt; temp++) {\n if (n % temp == 0) {\n primeFactors.add(temp);\n }\n }\n List primeFactors2 = new LinkedList();\n for (Long long1 : primeFactors) {\n long temp = n / long1;\n if (false == primeFactors.contains(temp) && isPrime((int) temp)) {\n primeFactors2.add(temp);\n }\n }\n primeFactors.addAll(primeFactors2);\n primeFactors2.clear();\n for (Long long1 : primeFactors) {\n if (isPrime(long1) == true) {\n primeFactors2.add(long1);\n }\n }\n return primeFactors2;\n }\n\n public static List getAllFactors(long n) {\n List primeFactors = new LinkedList();\n primeFactors.add(1l);\n if (n != 1) {\n int sqrt = (int) Math.sqrt(n);\n for (long temp = 2; temp <= sqrt; temp++) {\n if (n % temp == 0) {\n primeFactors.add(temp);\n }\n }\n List primeFactors2 = new LinkedList();\n for (int i = primeFactors.size() - 1; i >= 0; i--) {\n long long1 = primeFactors.get(i);\n long temp = n / long1;\n if (false == primeFactors.contains(temp)) {\n primeFactors2.add(temp);\n }\n }\n primeFactors.addAll(primeFactors2);\n }\n\n return primeFactors;\n }\n\n static public List gePrimesLessThanN(int n) {\n List primes = new LinkedList();\n int[] numbers = new int[n+1];\n boolean[] isPrime = new boolean[n+1];\n for(int i=0;i<=n;i++){\n isPrime[i] = true;\n }\n for(int i=0;i<=n;i++){\n numbers[i] = i;\n }\n for(int i=2;i<=Math.sqrt(n);i++){\n for(int j=2;i*j<=n;j++) {\n isPrime[i*j] = false;\n }\n }\n for(int i=2;i<=n;i++){\n if(isPrime[i] == true)\n primes.add((long)i);\n }\n return primes;\n }\n\n static public List gePrimesLessThanNGreaterThanM(long M, long N) {\n if(M==1)\n M=2;\n List primes = new LinkedList();\n int totalNumbers = (int)(N-M+1);\n long[] numbers = new long[totalNumbers];\n boolean[] isPrime = new boolean[totalNumbers];\n for(int i=0;i getProperDivisor(long n) {\n List allFactors = getAllFactors(n);\n allFactors.remove(allFactors.size() - 1);\n return allFactors;\n }\n\n static public String multiplyTwoLargeNumberFaster(String num1, String num2) {\n int length1 = num1.length();\n int length2 = num2.length();\n if (length1 > length2) {\n String temp = num1;\n num1 = num2;\n num2 = temp;\n length1 = num1.length();\n length2 = num2.length();\n }\n String partialMulti[] = new String[length2];\n String[] multiplications = new String[10];\n for (int i = length2 - 1, k = 0; i >= 0; i--, k++) {\n int temp1 = num2.charAt(i) - 48;\n int carry = 0;\n StringBuilder sb = new StringBuilder();\n // Max no. of different digits in multiplicand can be 10.\n // So storing multiplication of multiplicant by each digit to avoid calculation again\n // and again\n if (multiplications[temp1] != null && !multiplications[temp1].isEmpty()) {\n sb.append(multiplications[temp1]);\n } else {\n for (int j = length1 - 1; j >= 0; j--) {\n int temp2 = num1.charAt(j) - 48;\n int multi = temp2 * temp1 + carry;\n sb.append(multi % 10);\n carry = multi / 10;\n }\n if (carry != 0) {\n sb.append(carry);\n }\n sb = sb.reverse();\n multiplications[temp1] = sb.toString();\n }\n\n for (int l = 0; l < k; l++) {\n sb.append(0);\n }\n partialMulti[k] = sb.toString();\n }\n String multiplication = \"\";\n for (String partial : partialMulti) {\n multiplication = addTwoLargeNumbers(multiplication, partial);\n }\n return multiplication;\n }\n\n\n static public String getFibonacciNthTerm(int n) {\n List terms = getFibonacciSeriesNTerms(n);\n return terms.get(n - 1);\n }\n\n static public List getFibonacciSeriesNTerms(int n) {\n List series = new LinkedList();\n String nthTerm = \"\";\n String f0 = \"1\";\n String f1 = \"1\";\n if (n == 1) {\n series.add(f0);\n } else if (n == 2) {\n series.add(f0);\n series.add(f1);\n } else {\n series.add(f0);\n series.add(f1);\n for (int i = 1; i < n - 1; i++) {\n nthTerm = addTwoLargeNumbers(f0, f1);\n series.add(nthTerm);\n f0 = f1;\n f1 = nthTerm;\n }\n }\n return series;\n }\n\n // Assuming sorted permutations are there\n public static String getNthPermutation(int n, List digits) {\n List digits1 = new LinkedList();\n digits1.addAll(digits);\n int location = n - 1;\n int digitsCount = digits1.size();\n StringBuilder number = new StringBuilder();\n for (int i = 0; i < digitsCount; i++) {\n String factorial = NumberUtil.getFactorialUsingMultiplication(digitsCount - i - 1);\n int index = Integer.parseInt(getQuotientByDividing(String.valueOf(location), factorial));\n number.append(String.valueOf(digits1.get(index)));\n digits1.remove(index);\n location = location - index * Integer.parseInt(factorial);\n }\n return number.toString();\n }\n\n public static String subtractTwoNumbers(String num1, String num2) {\n String result = \"\";\n int length1 = num1.length();\n int length2 = num2.length();\n if (length1 == length2) {\n result = subTractTwoNumbersOfSameLength(num1, num2, length1);\n } else {\n result = subTractTwoNumbersOfDifferentLength(num1, num2, length1, length2);\n }\n return result;\n }\n\n private static String subTractTwoNumbersOfDifferentLength(String num1, String num2, int length1, int length2) {\n String result = \"\";\n StringBuilder newNum = new StringBuilder();\n if (length1 > length2) {\n for (int i = 0; i < length1 - length2; i++) {\n newNum.append(\"0\");\n }\n newNum.append(num2);\n result = subTractTwoNumbersOfSameLength(num1, newNum.toString(), length1);\n } else {\n for (int i = 0; i < length2 - length1; i++) {\n newNum.append(\"0\");\n }\n newNum.append(num1);\n result = subTractTwoNumbersOfSameLength(newNum.toString(), num2, length2);\n }\n return result;\n }\n\n public static boolean isResultPositive(String num1, String num2, int length) {\n for (int i = 0; i < length; i++) {\n if (num1.charAt(i) > num2.charAt(i))\n return true;\n if (num1.charAt(i) < num2.charAt(i))\n return false;\n else {\n continue;\n }\n }\n return true;\n }\n\n private static boolean isResultPositive(String num1,String num2,int length1,int length2){\n StringBuilder newNum= new StringBuilder();\n if (length1 > length2) {\n for (int i = 0; i < length1 - length2; i++) {\n newNum.append(\"0\");\n }\n newNum.append(num2);\n return isResultPositive(num1, newNum.toString(), length1);\n } else if(length2 > length1) {\n for (int i = 0; i < length2 - length1; i++) {\n newNum.append(\"0\");\n }\n newNum.append(num1);\n return isResultPositive(newNum.toString(), num2, length2);\n } else\n return isResultPositive(num1, num2, length1);\n }\n\n private static String subTractTwoNumbersOfSameLength(String num1, String num2, int length) {\n // subtract num2 from num1(num1 -num2)\n StringBuilder result = new StringBuilder();\n int carry = 0;\n // if result is not positive then swap numbers to make it positive\n boolean resultPositive = isResultPositive(num1, num2, length);\n if (resultPositive == false) {\n String temp = num1;\n num1 = num2;\n num2 = temp;\n }\n for (int i = length - 1; i >= 0; i--) {\n int temp = 0;\n int digit1 = num1.charAt(i) - 48;\n int digit2 = num2.charAt(i) - 48;\n if (digit1 >= digit2) {\n if (carry == 1) {\n digit1--;\n carry = 0;\n // when digit1(before subtracting the carry) and digit2 are equal\n if (digit1 + 1 == digit2) {\n digit1 += 10;\n carry = 1;\n }\n }\n temp = digit1 - digit2;\n } else {\n if (carry == 0) {\n carry = 1;\n digit1 += 10;\n } else {\n digit1 = digit1 - 1 + 10;\n }\n temp = digit1 - digit2;\n }\n result.append(temp);\n }\n result = removeLeadingZeroes(result);\n if (resultPositive == false) {\n result.append(\"-\");\n }\n result = result.reverse();\n return result.toString();\n }\n\n public static String getQuotientByDividing(String dividend,String divisor){\n String[] divisionResult = divideTwoNumbers(dividend, divisor);\n return divisionResult[0];\n }\n\n public static String getRemainderByDividing(String dividend,String divisor){\n String[] divisionResult = divideTwoNumbers(dividend, divisor);\n return divisionResult[1];\n }\n\n public static String[] divideTwoNumbers(String dividend, String divisor) {\n StringBuilder result = new StringBuilder();\n boolean done = false;\n int length = divisor.length();\n int index=length;\n int dividendLength = dividend.length();\n if(false == isResultPositive(dividend, divisor, dividendLength,length))\n return new String[]{\"0\",dividend};\n String temp = dividend.substring(0,length);\n while(done == false){\n while(false == isResultPositive(temp,divisor,temp.length(),length)){\n result.append(\"0\");\n if(index >=dividendLength){\n break;\n }\n temp = temp + dividend.substring(index, index+1);\n index++;\n }\n int count =0;\n while(true == isResultPositive(temp, divisor,temp.length(),length)){\n temp = subtractTwoNumbers(temp, divisor);\n count++;\n }\n if(temp.equalsIgnoreCase(\"0\")){\n temp = \"\";\n }\n if(count >0){\n result.append(count);\n }\n if(index >= dividendLength){\n done = true;\n break;\n }else{\n temp = temp + dividend.substring(index, index+1);\n index++;\n }\n\n }\n return new String[]{removeLeadingZeroes(result.reverse()).reverse().toString(),temp};\n }\n\n private static StringBuilder removeLeadingZeroes(StringBuilder result) {\n int i = result.length() - 1;\n for (i = result.length() - 1; i > 0; i--) {\n if (result.charAt(i) != '0') {\n break;\n }\n }\n result.replace(i + 1, result.length(), \"\");\n return result;\n }\n\n public static Long[] getDigitsInNumber(Long Number) {\n List digits = new LinkedList();\n if (Number == 0) {\n digits.add(0l);\n } else {\n while (Number > 0) {\n digits.add(Number % 10);\n Number = Number / 10;\n }\n }\n Long[] digitsArray = new Long[digits.size()];\n for (int i = 0; i < digits.size(); i++) {\n digitsArray[i] = digits.get(i);\n }\n return digitsArray;\n }\n\n public static long[] getAllCircularRotations(Long number) {\n int digitsinNumber = getNumOfDigits(number);\n long[] numbers = new long[digitsinNumber];\n long tenthPower = (long)Math.pow(10, digitsinNumber - 1);\n long numberCopy = number;\n for (int i = 0; i < digitsinNumber; i++) {\n long num1 = numberCopy % tenthPower;\n long num2 = numberCopy / tenthPower;\n numberCopy = num1 * 10 + num2;\n numbers[i] = numberCopy;\n }\n return numbers;\n }\n\n public static boolean isAllDigitsNine(Long[] digits) {\n for (int i = 0; i < digits.length; i++)\n if (digits[i] != 9)\n return false;\n return true;\n }\n\n public static long getNextPalindrome(long number) {\n Long[] digits = getDigitsInNumber(number);\n int len = digits.length;\n if (len == 1 && digits[0] != 9)\n return digits[0] + 1;\n if (isAllDigitsNine(digits)) {\n int num = 10;\n for (int i = 0; i < len - 1; i++) {\n num *= 10;\n }\n num += 1;\n return num;\n }\n int mid = len / 2;\n int i = mid - 1;\n int j = len % 2 == 1 ? (mid + 1) : mid;\n while (i >= 0 && digits[i] == digits[j]) {\n i--;\n j++;\n }\n boolean isleftSmall = false;\n if (i < 0 || digits[i] < digits[j]) {\n isleftSmall = true;\n }\n if (!isleftSmall) {\n while (i >= 0) {\n digits[j++] = digits[i--];\n }\n } else {\n long carry = 1l;\n i = mid - 1;\n if (len % 2 != 0) {\n digits[mid] += carry;\n carry = digits[mid] / 10;\n digits[mid] = digits[mid] % 10;\n j = mid + 1;\n } else {\n j = mid;\n }\n while (i >= 0) {\n digits[i] += carry;\n carry = digits[i] / 10;\n digits[i] = digits[i] % 10;\n digits[j++] = digits[i--];\n }\n }\n long ret = 0l;\n int x = 0;\n for (x = 0; x < len - 1; x++) {\n ret += digits[x];\n ret *= 10;\n }\n ret += digits[x];\n return ret;\n }\n\n public static boolean doesNumberContainEvenNumber(Long number) {\n if (number == 0)\n return true;\n while (number > 0) {\n long num = number % 10;\n number = number / 10;\n if (num % 2 == 0)\n return true;\n }\n return false;\n }\n\n /* public static long getNextPrime */\n}\n\n static class InputReader {\n\n private InputStream stream;\n\n private byte[] buf = new byte[1024];\n\n private int curChar;\n\n private int numChars;\n\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String next() {\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 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\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 void printLine(String string) {\n writer.println(string);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n\n }\n \n public static void main(String[] args) {\n InputReader ir = new InputReader(System.in);\n OutputWriter ow = new OutputWriter(System.out);\n String[][] possibilities = {\n {\n \"C\", \"ODEFORCES\"\n }, {\n \"CO\", \"DEFORCES\"\n }, {\n \"COD\", \"EFORCES\"\n }, {\n \"CODE\", \"FORCES\"\n }, {\n \"CODEF\", \"ORCES\"\n }, {\n \"CODEFO\", \"RCES\"\n }, {\n \"CODEFOR\", \"CES\"\n }, {\n \"CODEFORC\", \"ES\"\n }, {\n \"CODEFORCE\", \"S\"\n },\n };\n /*\n int length = 10;\n StringBuilder codeForces = new StringBuilder(\"CODEFORCES\");\n for (int i = 0; i < length-1; i++) {\n System.out.println(\"{\\\"\"+codeForces.substring(0, i + 1)+\"\\\",\"+\"\\\"\"+codeForces.substring(i+1, length)+\"\\\"},\");\n \n }*/\n String charsequence = \"CODEFORCES\";\n String read = ir.next();\n boolean possible = false;\n if(read.length() < 10){\n possible = false;\n } else if (read.contains(charsequence)) {\n int index = read.indexOf(charsequence);\n if (index == 0 || index == read.length() - charsequence.length())\n possible = true;\n }\n\t\tif (possible == false && read.length() >=10) {\n for (int i = 0; i < 9; i++) {\n boolean firstMatch = possibilities[i][0].equalsIgnoreCase(read.substring(0,\n possibilities[i][0].length()));\n boolean secondMatch = possibilities[i][1].equalsIgnoreCase(read.substring(\n read.length() - possibilities[i][1].length(), read.length()));\n if (firstMatch && secondMatch) {\n possible = true;\n break;\n }\n\n /*\n * int first = read.indexOf(possibilities[i][0]); int second =\n * read.indexOf(possibilities[i][1], first); if (first != -1 && second != -1 &&\n * second > first) {\n * System.out.println(possibilities[i][0]+\" \"+possibilities[i][1]+\"first=\"\n * +first+\" second\"+second); possible = true; break; }\n */\n }\n }\n if (possible)\n ow.printLine(\"YES\");\n else\n ow.printLine(\"NO\");\n ow.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2150c777f991916b8c2f8526fab5d384", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author izharishaksa\n */\npublic class CuttingBanner {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String s = sc.nextLine();\n String code = 'CODEFORCES';\n int counter = 0;\n for (int i = 0; i < s.length() && counter < 10; i++) {\n if (s.charAt(i) == code.charAt(counter)) {\n counter++;\n }\n }\n if (counter == 10) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "42ab4775b1cb8084ea8a41d04fd98acd", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.Scanner\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n System.out.println(solve(in.next())? \"YES\" : \"NO\");\n in.close();\n }\n \n public static boolean solve(String banner) {\n int len = banner.length();\n \n if(len < 10) return false;\n \n \n String codeForces = \"CODEFORCES\";\n \n if(len == 10) return codeForces.equals(banner);\n\n \n for(int cut = 1; cut < len; cut++) {\n if(len - cut != 10) continue;\n \n for(int i = 0; i <= len - cut; i++) {\n String tmp = banner.substring(0, i).concat(banner.substring(i + cut));\n if(tmp.equals(codeForces)) return true;\n }\n }\n \n \n return false; \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "403ffc44b89a4968ab28214c9ede9455", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Fred Zhang\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n String input = in.readLine();\n char[] chars = new char[4];\n for (int i = 0; i < input.length(); i++) {\n if (input.charAt(i) != '!')\n chars[i % 4] = input.charAt(i);\n }\n\n int r = 0;\n int b = 0;\n int y = 0;\n int g = 0;\n for (int i = 0; i < input.length(); i++) {\n if (input.charAt(i) == '!') {\n if (chars[i % 4] == 'R')\n r++;\n if (chars[i % 4] == 'B')\n b++;\n if (chars[i % 4] == 'Y')\n y++;\n if (chars[i % 4] == 'G')\n g++;\n }\n }\n\n out.print(r + \" \" + b + \" \" + y + \" \" + g);\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 }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\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 private String readLine0() {\n StringBuilder buf = new StringBuilder();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r') {\n buf.appendCodePoint(c);\n }\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0) {\n s = readLine0();\n }\n return s;\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2a7b0fa1f61573e5570f71a00778a9b9", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class BComp {\n\n public static void main(String[] args) {\n AComp.FastScanner fc = new AComp.FastScanner();\n String colors = fc.nextToken();\n String [] values = new String[4];\n for (int i=0;i<4; i++) {\n values[i] = findColor(colors, i, colors.length());\n }\n values = check(values);\n int map [] = {0,0,0,0};\n int p = 0;\n for (int i=0;ilen) {\n return \"!\";\n } else {\n return findColor(colors, i+4, len);\n }\n }\n\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d362c49177aac25c306741a979d9eff8", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class garland\n{\n\tpublic static void main(String[] args)throws IOException {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tString s=br.readLine();\n\t\tint l=s.length();\n\t\tint f,s,th,fo;\n\t\tint count[]=new int[4];\n\t\tfor(int i=0;i= n) return 0;\n if (Integer.parseInt(number.substring(hour), 7) >= m) return 0;\n return 1;\n }\n\n int ans = 0;\n for (int i = 0; i < 7; i++) {\n\n if (((mask >> i) & 1) == 0) {\n int tm = mask | (1 << i);\n ans += go(pos + 1, tm, number + i);\n }\n }\n return 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 int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ef043a89449298391d9efcbd830faffd", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\n// Codeforces Round #359 (Div. 2)\n// Robbers' watch\npublic class Problem_686_C {\n\n\tprivate void doSolve(PrintWriter out) {\n\t\t\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\t\n\t\tInteger[] nBase7 = changeBaseFrom10(n - 1, 7);\n\t\tInteger[] mBase7 = changeBaseFrom10(m - 1, 7);\n\n\t\tint digitsN = nBase7.length;\n\t\tint digitsM = mBase7.length;\n\t\t\n\t\tint totalDigits = digitsN + digitsM;\n\t\tif (totalDigits > 7) {\n\t\t\tout.println(\"0\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint counter = 0;\n\t\tLinkedList stack = new LinkedList();\n\t\twhile (true) {\n\t\t\tif (stack.size() < totalDigits) {\n\t\t\t\tstack.addLast( findNextDigit(stack, 0) );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif ( isValid( stack.subList(0, digitsN), nBase7 )\n\t\t\t\t\t\t&& isValid( stack.subList(digitsN, totalDigits), mBase7 ) ) {\n\t\t\t\t\tcounter++;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\twhile (true) {\n\t\t\t\t\tint currentDigit = stack.removeLast();\n\t\t\t\t\tInteger nextDigit = findNextDigit(stack, currentDigit + 1);\n\t\t\t\t\tif (nextDigit != null) {\n\t\t\t\t\t\tstack.addLast(nextDigit);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (stack.isEmpty()) {\n\t\t\t\t\t\tbreak; // we are done!\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (stack.isEmpty()) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(counter);\n\t}\n\t\n\tprivate Integer findNextDigit(List digits, int startFrom) {\n\t\tfor (int i = startFrom; i < 7; i++) {\n\t\t\tboolean used = false;\n\t\t\tfor (int j : digits) {\n\t\t\t\tif (j == i) {\n\t\t\t\t\tused = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!used) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\t\n\tprivate boolean isValid(List digits, Integer[] maxValue) {\n\t\tfor (int i = 0; i < digits.size(); i++) {\n\t\t\tif (digits.get(i) == maxValue[i]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn maxValue[i] > digits.get(i);\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tprivate Integer[] changeBaseFrom10(int decimal, int base) {\n\t\tList result = new LinkedList();\n\t\twhile (decimal > 0) {\n\t\t\tresult.add( decimal % base );\n\t\t\tdecimal /= base;\n\t\t}\n\t\tCollections.reverse(result);\n\t\treturn result.toArray(new Integer[result.size()]);\n\t}\n\t\n\t\n\t/* ========================================================= */\n\t\n private InputReader inputReader;\n \n \n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n PrintWriter out = new PrintWriter(outputStream);\n Problem_686_C solver = new Problem_686_C();\n solver.solve(1, new InputStreamReader(inputStream), out);\n out.close();\n }\n\n public int nextInt() {\n \treturn inputReader.nextInt();\n }\n \n public String next() {\n \treturn inputReader.next();\n }\n \n public void solve(int test, Reader in, PrintWriter out)\n {\n \tinputReader = new InputReader(in);\n \tdoSolve(out);\n \t\n }\n \n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(Reader reader) {\n this.reader = new BufferedReader(reader, 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c82ba03dd8dbe336483f91bcea49aa11", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "/*Author LAVLESH*/\nimport java.util.*;\nimport java.io.*;\npublic class solution{\n\tstatic BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st=new StringTokenizer(\"\");\n\tstatic int basechange(int n)\n\t{\n\t\tStringBuilder st=new StringBuilder(\"\");\n\t\twhile(n>0){\n\t\t\tst.append(n%7);n/=7;\n\t\t}\n\t\tst.append(n);\n\t\treturn Integer.parseInt(st.reverse().toString());\n\t\t\t\t\n\t}\n\tstatic public String next() {\n\t while (st == null || !st.hasMoreTokens()) {\n\t try {\n\t st = new StringTokenizer(br.readLine());\n\t } catch (IOException e) {\n\t throw new RuntimeException(e);\n\t }\n\t }\n\t return st.nextToken();\n\t }\n\t\n\n\tpublic static void main(String[]args)throws IOException{\n long ans=0;PrintStream op = System.out;\n\t\t int n=Integer.parseInt(next());\n\t\t int m=Integer.parseInt(next());\n\t\tint []a=new int[n];\n\t\tint []b=new int [m];\n\t\tfor(int i=0;i1)\n{\n\tf=1;\n}\n\t\t\t\t\n\t\t\t\t}\n\t\t\t\tif(f==0){ans++;f=0;}//System.out.println(s);}\t\n\t\t\t}\n\t\t}\n\t\t \n\t\t op.println(ans);\n\t\t op.close();\n\t\t}\n\t}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c4f4b167be081fca87e21dfd6545e19c", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic final class code\n// class code\n// public class Solution\n{\n\tstatic void solve()throws IOException\n\t{\n\t\tint n=nextInt();\n\t\tint m=nextInt();\n\t\tint d1=Math.ceil(Math.log(n)/Math.log(7));\n\t\tint d2=Math.ceil(Math.log(m)/Math.log(7));\n\t\tif(d1+d2>7)\n\t\t{\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong c=0;\n\t\tfor(int i=0;i0;k=k/7)\n\t\t\t\t\tused[k%7]++;\n\t\t\t\tfor(int k=j;k>0;k=k/7)\n\t\t\t\t\tused[k%7]++;\n\t\t\t\tboolean flag=false;\n\t\t\t\tfor(int k=0;k<7;k++)\n\t\t\t\t{\n\t\t\t\t\tif(used[k]>1)\n\t\t\t\t\t{\n\t\t\t\t\t\tflag=true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(flag==false)\n\t\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t\tout.println(c);\n\t}\n\n\n\n\t\n\t///////////////////////////////////////////////////////////\n\tstatic final long mod=(long)(1e9+7);\n\t// static final int inf=(int)(1e9);\n\tstatic final long inf=(long)(1e18);\n\tstatic class Pair implements Comparable\n\t{\n\t\tint first,second;\n\t\tPair(int a,int b)\n\t\t{\n\t\t\tfirst=a;\n\t\t\tsecond=b;\n\t\t}\n\t\tpublic int compareTo(Pair p)\n\t\t{\n\t\t\treturn this.second-p.second;\n\t\t}\n\t}\n\tstatic void debug(Object ... a)\n\t{\n\t\tSystem.out.print(\"> \");\n\t\tfor(int i=0;i \");\n\t\tfor(int i=0;ieps && \n\t\t\t\tMath.abs(P.arg(ver[i], ver[(i+1)%4], ver[(i+2)%4])-3*Math.PI/2)>eps) return false;\n\t\tfor (int i=0; i<4; i++)\n\t\t\tif ( Math.abs(P.arg(ver[i], ver[(i+1)%4]))EPS?1:0;\n\t\t\t}\n\t\tstatic Comparator

comp=new Comparator

(){\n\t\t\tpublic int compare(P p1, P p2) {\n\t\t\t\treturn signum(p1.x-p2.x)!=0?signum(p1.x-p2.x):signum(p1.y-p2.y);\n\t\t\t}\n\t\t};\n\t\tpublic static final P O=new P(0,0);\n\t\tfinal double x,y;\n\t\tP(double _x,double _y){\n\t\t\tx=_x;y=_y;\n\t\t}\n\t\t\n\t\tP add(P a){\n\t\t\treturn new P(x+a.x,y+a.y);\n\t\t}\n\t\tP sub(P a){\n\t\t\treturn new P(x-a.x,y-a.y);\n\t\t}\n\t\tP mul(P a){\n\t\t\treturn new P(x*a.x-y*a.y,x*a.y+y*a.x);\n\t\t}\n\t\tP div(P a){\n\t\t\tdouble d2=a.dist2(O);\n\t\t\treturn new P(dot(a,this)/d2,cross(a,this)/d2);\n\t\t}\n\t\t\n\t\tP conj(){\n\t\t\treturn new P(x,-y);\n\t\t}\n\t\t\n\t\tstatic double dot(P a,P b){\n\t\t\treturn a.x*b.x+a.y*b.y;\n\t\t}\n\t\t\n\t\tstatic double cross(P a,P b){\n\t\t\treturn a.x*b.y-a.y*b.x;\n\t\t}\n\t\t\n\t\tdouble dist2(P p){\n\t\t\treturn (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y);\n\t\t}\n\t\t\n\t\tdouble dist(P p){\n\t\t\treturn sqrt(dist2(p));\n\t\t}\n\t\tpublic double norm(){\n\t\t\treturn dist(O);\n\t\t}\n\t\t\n\t\tstatic int ccw(P a,P b,P c){\n\t\t\tb=b.sub(a);c=c.sub(a);\n\t\t\tif(cross(b,c)>EPS)return 1;\n\t\t\tif(cross(b,c)<-EPS)return -1;\n\t\t\tif(dot(b,c)<-EPS)return 2;\n\t\t\tif(b.norm()=0?s:2*PI-s;\n\t\t}\n\t\t\n\t\tstatic double arg(P a,P b, P c){\n\t\t\tdouble angleA = P.arg(a,b);\n\t\t\tdouble angleB = P.arg(b,c);\n\t\t\tdouble angle = Math.PI+angleA-angleB;\n\t\t\tif (angle-2*Math.PI>EPS) angle-=2*Math.PI;\n\t\t\tif (angleseg[1].y)&&(num2<2)){\n\t\tvert[num2][0]=seg[1];\n\t\tvert[num2][1]=seg[0];\n\t\t}\n\t\telse{\n\t\t\tvert[num2][0]=seg[0];\n\t\t\tvert[num2][1]=seg[1];\n\t\t}\n\t\tnum2++;\n\t}\n\telse if ((seg[0].y==seg[1].y)&&(num1<2)){\n\t\tif (seg[0].x>seg[1].x){\n\t\t\thori[num1][0]=seg[1];\n\t\t\thori[num1][1]=seg[0];\n\t\t\t}\n\t\t\telse{\n\t\t\t\thori[num1][0]=seg[0];\n\t\t\t\thori[num1][1]=seg[1];\n\t\t\t}\n\t\tnum1++;\n\t }\n\telse\n\t{\n\t\tcheckdead=true;\n\t}\n\t\n\t}\n\tif (checkdead) System.out.print(\"NO\"); // there is line not // to x or y axis\n\telse{\n\t\tif ((num1==2)&&(num2==2)){\n\t\t\tif ((hori[0][0].x==hori[1][0].x) &&(hori[0][1].x==hori[1][1].x)&&(hori[0][0].x!=hori[0][1].x)&&(hori[0][0].y!=hori[1][0].y)){ //check the horizental\n\t\t\t\twidth=Math.abs(hori[0][0].y-hori[1][0].y);\n\t\t\t\tlength=Math.abs(hori[0][1].x-hori[0][0].x);\n\t\t\t\tif ((hori[0][0].y>hori[1][0].y)){\n \t\t\t\tbottom=1;\t\t\n\t\t\t\t} else {\n\t\t\t\t\tbottom=0;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif ((vert[0][0].y==vert[1][0].y) &&(vert[0][1].y==vert[1][1].y)&&(vert[0][0].y!=vert[0][1].y)&&(Math.abs(vert[0][0].x-vert[1][0].x)==length)){ // check vertical\n\t\t\t\t\tif ((vert[0][0].y==hori[bottom][0].y)&&(vert[0][1].y==(vert[0][0].y+width))){\n\t\t\t\t\t\tSystem.out.print(\"YES\");\n\t\t\t\t\t}\n\t\t\t\t\telse checkdead=true;\n\t\t\t\t}\n\t\t\t\telse checkdead=true;\n\t\t\t} // bdayt awel if twela\n\t\t\telse{\n\t\t\t\tcheckdead=true;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tcheckdead=true; \n\t\t}\n\t\t\n\t\tif (checkdead) System.out.print(\"NO\");\n\t}\n\t\n }\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2e3daac4550c196cd71a603d345541d3", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "//package com.himanshu.practice.july17;\n\nimport lombok.AllArgsConstructor;\nimport lombok.EqualsAndHashCode;\nimport lombok.ToString;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n/**\n * Created by himanshubhardwaj on 18/07/18.\n */\npublic class FourSegments {\n public static void main(String[] args) throws IOException {\n int x1, y1, x2, y2;\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n ArrayList lines = new ArrayList<>();\n String str[];\n ArrayList points = new ArrayList<>();\n\n for (int i = 0; i < 4; i++) {\n str = br.readLine().split(\" \");\n x1 = Integer.parseInt(str[0]);\n y1 = Integer.parseInt(str[1]);\n x2 = Integer.parseInt(str[2]);\n y2 = Integer.parseInt(str[3]);\n Line line = new Line(x1, y1, x2, y2);\n lines.add(line);\n }\n\n if (Line.isRectangle(lines)) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}\n\n\n@ToString\n@EqualsAndHashCode\nclass Line {\n @EqualsAndHashCode.Exclude\n Point p1;\n @EqualsAndHashCode.Exclude\n Point p2;\n @EqualsAndHashCode.Include\n float slope;\n @EqualsAndHashCode.Include\n float intercept;\n\n public Line(float slope, float intercept) {\n this.slope = slope;\n this.intercept = intercept;\n }\n\n\n public Line(int x1, int y1, int x2, int y2) {\n p1 = new Point(x1, y1);\n p2 = new Point(x2, y2);\n setSlopeAndInterSection();\n }\n\n\n// public boolean equals(Object anObject) {\n// boolean result = false;\n// if (anObject == this) {\n// result = true;\n// }\n//\n// if (anObject instanceof Line) {\n// Line newLine = (Line) anObject;\n// if (newLine.intercept == this.intercept && newLine.slope == this.slope) {\n// result = true;\n// }\n//\n// }\n//\n// System.out.println(this + \"\\t\" + anObject + \"\\t\" + result);\n// return result;\n// }\n\n public void setSlopeAndInterSection() {\n if (this.p2.x != this.p1.x) {\n this.slope = (this.p2.y - this.p1.y) / (this.p2.x - this.p1.x);\n this.intercept = this.p1.y - slope * this.p1.x;\n } else {\n this.intercept = this.p1.x;\n this.slope = -1;\n }\n }\n\n //returns trye is line intersection forms a rectangle\n public static boolean isRectangle(ArrayList lines) {\n if (!checkIfParallelToAxis(lines)) {\n return false;\n }\n\n double d[] = new double[2];\n d[0] = -1;\n d[1] = -1;\n int count = 0;\n for (int i = 0; i < lines.size(); i++) {\n for (int j = i + 1; j < lines.size(); j++) {\n if (lines.get(i).slope == lines.get(j).slope) {\n if (count == 2) {\n return false;\n }\n d[count] = Math.abs(lines.get(i).intercept - lines.get(j).intercept);\n count++;\n }\n }\n }\n\n if (d[0] > 0 || d[1] > 0) {\n return true;\n }\n return false;\n }\n\n private static boolean checkIfParallelToAxis(ArrayList lines) {\n int slopeZero = 0;\n int slopeINF = 0;\n\n if (lines.size() != 4) {\n return false;\n }\n HashMap occurence = new HashMap<>();\n\n\n for (int i = 0; i < lines.size(); i++) {\n //testHashMap(occurence, lines.get(i).p1);\n if (occurence.containsKey(lines.get(i).p1)) {\n occurence.put(lines.get(i).p1, 1 + occurence.get(lines.get(i).p1));\n } else {\n occurence.put(lines.get(i).p1, 1);\n }\n\n\n //testHashMap(occurence, lines.get(i).p2);\n\n if (occurence.containsKey(lines.get(i).p2)) {\n occurence.put(lines.get(i).p2, 1 + occurence.get(lines.get(i).p2));\n } else {\n occurence.put(lines.get(i).p2, 1);\n }\n\n\n for (int j = i + 1; j < lines.size(); j++) {\n if (lines.get(i).equals(lines.get(j))) {\n return false;\n }\n }\n }\n\n// System.out.println(occurence);\n\n for (Map.Entry entry : occurence.entrySet()) {\n if (entry.getValue() != 2) {\n return false;\n }\n }\n\n for (Line l : lines) {\n //System.out.println(l + \"..\");\n if (l.slope == 0) {\n slopeZero++;\n } else if (l.slope == -1) {\n slopeINF++;\n } else {\n return false;\n }\n }\n\n if (slopeINF == 2 && slopeZero == 2) {\n return true;\n }\n\n return false;\n }\n\n\n public static void testHashMap(HashMap occurence, Point p1) {\n System.out.println(occurence + \"\\t\\t\" + p1 + \"\\t\\t\" + occurence.containsKey(p1));\n }\n}\n\n\n@AllArgsConstructor\n@ToString\n@EqualsAndHashCode\nclass Point {\n @EqualsAndHashCode.Include\n float x;\n @EqualsAndHashCode.Include\n float y;\n\n// public boolean equals(Object anObject) {\n// boolean result = false;\n// if (this == anObject) {\n// result = true;\n// }\n//\n// if (anObject instanceof Point) {\n// Point newPoint = (Point) anObject;\n//\n// if (Float.valueOf(newPoint.x).equals(this.x) && Float.valueOf(newPoint.y).equals(this.y)) {\n// result = true;\n// }\n// }\n//\n// System.out.println(this + \"\\t\" + anObject + \"\\t\" + result);\n// return false;\n// }\n//\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "27418b5b87ff9e2e80097ce37d00e4b6", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "public class FourSegments2 {\n public static void main(String[] args) {\n Scanner leer = new Scanner(System.in);\n \n Point[] points = new Point[8];\n for (int i = 0; i < points.length; i++){\n double x = leer.nextDouble();\n double y = leer.nextDouble();\n points[i] = new Point(x,y);\n } \n solve(points);\n }\n public static void solve(Point[] points){\n Segment[] segments = createSegments(points);\n \n if(correctPoints(points)){\n double distSegments[] = calcDistances(segments);\n \n boolean isLine = isLine(distSegments);\n //System.out.println(\"isLine = \"+isLine);\n\n if(!isLine){\n boolean pairDistances = pairDistances(distSegments);\n //System.out.println(\"pairDistances = \"+pairDistances);\n\n if(pairDistances){\n boolean segmentParallel = segmentParallel(segments); \n //System.out.println(\"segmentParallel = \"+segmentParallel);\n\n if(segmentParallel){\n boolean isSameCenter = isSameCenter(segments);\n //System.out.println(\"isSameCenter = \"+isSameCenter);\n\n if(isSameCenter){\n boolean isRombo = isRombo(points);\n if(!isRombo)\n System.out.println(\"YES\"); \n else\n System.out.println(\"NO\");\n }\n else\n System.out.println(\"NO\");\n }\n else\n System.out.println(\"NO\");\n }\n else\n System.out.println(\"NO\");\n }\n else\n System.out.println(\"NO\"); \n }\n else\n System.out.println(\"NO\"); \n }\n public static boolean isRombo(Point[] points){\n Point[] pts = differentPoints(points);\n \n int cont = 0;\n \n for (int i = 0; i < pts.length; i++) {\n for (int j = i+1; j < pts.length; j++) {\n if(pts[i].x != pts[j].x && pts[i].y != pts[j].y)\n cont++;\n }\n }\n if(cont==4)\n return true;\n else\n return false;\n }\n public static boolean isSameCenter(Segment[] segments){\n \n boolean isSameC = true;\n Point mP1 = middlePoint(segments[0].p1, segments[0].p2);\n Point mP2 = middlePoint(segments[1].p1, segments[1].p2);\n Point mP3 = middlePoint(segments[2].p1, segments[2].p2);\n Point mP4 = middlePoint(segments[3].p1, segments[3].p2);\n \n Point ptoInter = pointIntersection(mP1, mP4, mP2, mP3);\n \n if(ptoInter==null){\n ptoInter = pointIntersection(mP1, mP3, mP2, mP4);\n if(ptoInter == null){\n ptoInter = pointIntersection(mP1, mP2, mP4, mP3);\n if(ptoInter == null)\n isSameC = false;\n }\n }\n \n if(isSameC){\n Point pts[] = new Point[8];\n pts[0] = segments[0].p1; pts[1] = segments[0].p2;\n pts[2] = segments[1].p1; pts[3] = segments[1].p2;\n pts[4] = segments[2].p1; pts[5] = segments[2].p2;\n pts[6] = segments[3].p1; pts[7] = segments[3].p2;\n\n Point[] difPoints = differentPoints(pts);\n\n double d1 = dist2Points(ptoInter, difPoints[0]);\n double d2 = dist2Points(ptoInter, difPoints[1]);\n double d3 = dist2Points(ptoInter, difPoints[2]);\n double d4 = dist2Points(ptoInter, difPoints[3]);\n// \n// System.out.println();\n// System.out.println(\"ptoInter = \"+ptoInter);\n// System.out.println(\"d1 = \"+d1);\n// System.out.println(\"d2 = \"+d2);\n// System.out.println(\"d3 = \"+d3);\n// System.out.println(\"d4 = \"+d4);\n \n\n if(d1 == d2 && d2 == d3 && d3 == d4) \n isSameC = true;\n else\n isSameC = false;\n }\n \n return isSameC;\n }\n public static double dist2Points(Point A, Point B){\n double d1 = A.x - B.x;\n double d2 = A.y - B.y;\n \n double dist = Math.sqrt(d1*d1 + d2*d2);\n double distRound = Math.round(dist*Math.pow(10, 4));\n dist = distRound/Math.pow(10, 4);\n \n return dist;\n }\n public static Point middlePoint(Point A, Point B){\n double x = (A.x + B.x)/2;\n double y = (A.y + B.y)/2;\n return new Point(x,y);\n }\n public static Point pointIntersection(Point PA, Point PB, Point PC, Point PD){\n double A1 = PB.y - PA.y;\n double B1 = PA.x - PB.x;\n double C1 = A1 * PA.x + B1 * PA.y;\n \n double A2 = PD.y - PC.y;\n double B2 = PC.x - PD.x;\n double C2 = A2 * PC.x + B2 * PC.y;\n \n double det = A1*B2 - A2*B1;\n if(det==0){//Lineas Paralelas\n return null;\n }\n else{\n double x = (B2*C1 - B1*C2)/det;\n double y = (A1*C2 - A2*C1)/det;\n return new Point(x,y);\n } \n }\n \n public static boolean pairDistances(double[] distances){\n boolean pair = false;\n int cont = 0, cont2 = 0;\n for (int i = 0; i < distances.length; i++) {\n for (int j = i+1; j < distances.length; j++) {\n if(distances[i] == distances[j]){\n cont++;\n cont2++;\n }\n }\n }\n if(cont%2 ==0 || cont2==4)\n pair = true;\n return pair;\n }\n public static boolean correctPoints(Point[] points){\n int cont = 0;\n int contRect = 0;\n \n for (int i = 0; i < points.length; i++) {\n for (int j = i+1; j < points.length; j++) {\n if(points[i].x == points[j].x && points[i].y == points[j].y){\n cont++;\n }\n }\n if(cont==1)\n contRect++;\n cont=0;\n }\n if(contRect == 4)\n return true;\n else\n return false;\n }\n public static boolean isLine(double[] dist){\n Arrays.sort(dist);\n \n double sum = dist[0] + dist[1] + dist[2];\n if(sum == dist[3])\n return true;\n else \n return false;\n \n } \n private static Point[] differentPoints(Point[] points) {\n HashSet pts = new HashSet();\n for (int i = 0; i < points.length; i++) \n pts.add(points[i]);\n \n Point[] pDifs = new Point[pts.size()];\n int i=0;\n for(Point p:pts){\n pDifs[i++] = p;\n }\n return pDifs;\n }\n public static double distSegment(Segment seg){\n Point p1 = seg.p1;\n Point p2 = seg.p2;\n double dist = 0;\n dist = Math.sqrt(Math.pow(p2.x-p1.x, 2) + Math.pow(p2.y-p1.y, 2));\n double roundDist = Math.round(dist*Math.pow(10, 4));\n dist = roundDist/Math.pow(10, 4);\n return dist;\n }\n public static int distBetween2Points2(Point p1, Point p2){\n int dist = 0;\n dist = (int)(Math.pow(p2.x-p1.x, 2) + Math.pow(p2.y-p1.y, 2));\n return dist;\n }\n public static boolean segmentParallel(Segment[] segments){\n boolean pair = false;\n int cont = 0, cont2 = 0;\n for (int i = 0; i < segments.length; i++) {\n for (int j = i+1; j < segments.length; j++) {\n if(parallel(segments[i], segments[j])){\n cont++;\n cont2++;\n }\n }\n }\n if(cont%2 ==0 || cont2==4)\n pair = true;\n return pair;\n }\n public static boolean parallel(Segment seg1, Segment seg2){\n Point P1 = seg1.p1; Point P2 = seg1.p2;\n Point P3 = seg2.p1; Point P4 = seg2.p2;\n double A1 = P2.y - P1.y;\n double B1 = P1.x - P2.x;\n \n double A2 = P4.y - P3.y;\n double B2 = P3.x - P4.x;\n \n double det = A1*B2 - A2*B1;\n //System.out.println(\"det = \" + det);\n if(det==0){//Lineas Paralelas\n \n return true; \n }\n else\n return false;\n }\n\n private static double[] calcDistances(Segment[] segments) {\n double[] distances = new double[4];\n distances[0] = distSegment(segments[0]);\n distances[1] = distSegment(segments[1]);\n distances[2] = distSegment(segments[2]);\n distances[3] = distSegment(segments[3]);\n return distances;\n }\n\n private static Segment[] createSegments(Point[] points) {\n Segment[] segments = new Segment[4];\n segments[0] = new Segment(points[0], points[1]);\n segments[1] = new Segment(points[2], points[3]);\n segments[2] = new Segment(points[4], points[5]);\n segments[3] = new Segment(points[6], points[7]);\n return segments;\n }\n static class Point{\n double x, y;\n public Point(double x, double y){\n this.x = x;\n this.y = y;\n }\n @Override\n public boolean equals(Object obj){\n if(obj == null || !(obj instanceof Point))\n return false;\n Point p2 = (Point)obj;\n if(this.x == p2.x && this.y == p2.y)\n return true;\n return false;\n }\n @Override\n public int hashCode(){\n return (int)(x+y);\n }\n @Override\n public String toString(){\n return x+\" \"+y;\n }\n }\n static class Segment{\n Point p1, p2;\n public Segment(Point p1, Point p2){\n this.p1 = p1;\n this.p2 = p2;\n }\n @Override\n public String toString(){\n return \"seg = \"+p1+\" - \"+p2+\" \";\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "34c7c1a8b338e57cb55e10177c8eb42d", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\npublic class Codeforces{\n public static void main(String[] args){\n Scanner sc= new Scanner(System.in);\n int a= sc.nextInt();\n int b= sc.nextInt();\n int c= sc.nextInt();\n int arr[]= new int[4];\n arr[0]= a*b*c;\n arr[1]= (a+b)*c;\n arr[2]= a*(b+c);\n arr[3]=a+b+c;\n Arrays.sort(arr);\n System.out.println(arr[3]);\n \n \n \n \n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a77b78317aac30bdd9081a27575e782a", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import com.sun.deploy.util.StringUtils;\n\nimport java.util.Scanner;\nimport java.util.Arrays;\nimport java.lang.String;\n\npublic class Codeforce_A_Expression {\n public static final Scanner SCANNER = new Scanner(System.in);\n\n public static void main(String[] args) {\n\n int times = 0;\n int result = 0;\n int[] number = new int[3];\n int[] position = new int[3];\n\n number[0] = SCANNER.nextInt();\n number[1] = SCANNER.nextInt();\n number[2] = SCANNER.nextInt();\n\n if (number[0] == 1) {\n position[0] = 1;\n times ++;\n }\n if (number[1] == 1) {\n position[1] = 1;\n times ++;\n }\n if (number[2] == 1) {\n position[2] = 1;\n times ++;\n }\n\n if (times == 3) {\n result = number[0] + number[1] + number[2];\n }\n\n else if (times == 2)\n {\n if(position[0] == 1 && position[2] == 1) {\n result = number[0] + number[1] + number[2];\n }\n\n else if(position[0] == 1 && position[1] == 1){\n result = (number[0] + number[1]) * number[2];\n }\n\n else {\n result = number[0] * (number[1] + number[2]);\n }\n }\n\n else if (times == 1) {\n if (position[0] == 1) {\n result = (number[0] + number[1]) * number[2];\n }\n else if (position[1] == 1) {\n result = (number[0] + number[1]) * number[2];\n }\n else {\n result = number[0] * (number[1] + number[2]);\n }\n }\n\n System.out.println(result);\n\n SCANNER.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7712cd085fc4f73b4ea5c33808568204", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class codeforces2{\n\tpublic static void main(String[] args) throws IOException{\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tint a = Integer.parseInt(br.readLine());\n\tint b = Integer.parseInt(br.readLine());\n\tint c = Integer.parseInt(br.readLine());\n\tint flag = 1;\n\tint arr[] = new int[3];\n\tarr[0] = a;\n\tarr[1] = b;\n\tarr[2] = c;\n\t//Arrays.sort(arr);\n\tint[] one = new int[3];\n\tif(arr[0] == 1)\n\t\tone[0] = 1;\n\tif(arr[1] == 1)\n\t\tone[1] = 1;\n\tif(arr[2] == 1)\n\t\tone[2] = 1;\n\t\n\t\n\t\tif(one[0] == 1 && one[1] == 1 && one[2] == 1){\n\t\t\tSystem.out.println(a+b+c);\n\t\t}\n\t\telse if(one[0] == 1 && one[1] == 1){\n\t\t\tSystem.out.println((arr[0]+arr[1])*arr[2]);\n\t\t}\n\t\telse if(one[1] == 1 && one[2] == 1){\n\t\t\tSystem.out.println((arr[0]*(arr[1]+arr[2]));\n\t\t}\n\t\telse if(one[0] == 1){\n\t\t\tSystem.out.println((arr[0]+arr[1])*arr[2]);\n\t\t}\n\t\telse if(one[1] == 1){\n\t\t\tif(arr[0] < arr[2]){\n\t\t\t\tSystem.out.println((arr[0]+arr[1])*arr[2]);\n\t\t\t}else{\n\t\t\t\tSystem.out.println((arr[1]+arr[2])*arr[0]);\n\t\t\t}\n\t\t}\n\t\telse if(one[2] == 1){\n\t\t\tSystem.out.println((arr[2]+arr[1])*arr[0]);\n\t\t}\n\t else{\n\t\tSystem.out.println(a*b*c);\n\t }\n\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a864a7f82832657c8aab7d71dfe07ec4", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Expression { throws IOException\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n int m=a+b+c;\n \n if(a*b*c>m)\n m = a*b*c;\n if(a*(b+c)>m)\n \tm=a*(b+c);\n if((a+b)*c>m)\n \tm = (a+b) *c;\n\n System.out.print(m);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8dcf76dfd2cfb23ae8903ec940429fb9", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class problem{\n private static void main(String[] args){\n Scanner scn = new Scanner(System.in);\n String str = scn.nextLine();\n int slow = 0;\n int fast = 1;\n int count = 1;\n int ans = 0;\n while(fast1) { \n for (int i=0; i output2){\n \t\toutput1--;\n \t\toutput2++;\n \t\tif (output1 + output2 == length / 2){\n \t\t\tSystem.out.println()\n \t\tcounter++;\n \t\t}\n \t}\n \tSystem.out.print(counter);\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fac2750a85b790b916dfda4565db0d3a", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class Problem610A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n float length = in.nextFloat();\n\n System.out.println((int)Math.ceil(length / 4 - 1));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f1deb2f88eac0d2d7c07252ccd77d795", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class pashaAndStick{\n \n public static void main(String[] args){\n \n Scanner kbd = new Scanner (System.in);\n int length = kbd.nextInt();\n int counter = 0;\n \tint output1 = (length / 2) - 1;\n \tint output2 = 1;\n \tint compare = length / 2;\n \t\n \twhile (output1 > output2){\n \t\toutput1--;\n \t\toutput2++;\n \t\tif (output1 + output2 == compare){\n \t\tcounter++;\n \t\t}\n \t}\n \tSystem.out.print(counter);\n \n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d868bd43987bc4a2c1a5598762b9311", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.PrintWriter;\n\npublic class Main {\n \n static Scanner in = new Scanner(System.in);\n static PrintWriter out = new PrintWriter(System.out);\n \n public static void main(String[] args) {\n int n = in.nextInt();\n out.print((n % 2 == 0 ? ((n / 2) - 1) / 2) : 0);\n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9bba19b1aa70ba9253c936c1982ca793", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution\n{\n public static void main(String []args)\n {\n Scannersc = new Scanner(System.in);\n long n = sc.nextLong();\n long k = sc.nextLong();\n \n long turn = n/k;\n \n if(turn % 2 == 0)\n System.out.println(\"NO\");\n \n else\n System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "972f7cfcda5d4b1b67b98a77aaa351b9", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.sql.Struct;\nimport java.util.Scanner;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class CodeForces {\n\n public static void main(String[] args) throws NumberFormatException,\n IOException {\n new CodeForces();\n }\n\n public CodeForces() throws NumberFormatException, IOException {\n Scanner sc = new Scanner(System.in);\n // BufferedReader rd = new BufferedReader(new\n // InputStreamReader(System.in));\n // PrintWriter out = new PrintWriter(System.out);\n int n = sc.nextInt();\n int k = sc.nextInt();\n solve(n,k);\n }\n\n private String solve(int n, int k) {\n System.out.println((n/k)%2 == 1 ? \"YES\" : \"NO\"); \n //return t%2==0 ? \"YES\" : \"NO\";\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0b065b4143d98a4bc5672845d14ff101", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n long n=sc.nextLong();\n long k=sc.nextLong();\n int dir=1;\n long s=0,l=0;\n if(n==k)\n System.out.println(\"YES\");\n else\n {\n while(n>=m)\n {\n if(dir==1)\n {\n n=n-m;\n s++;\n dir=2;\n }\n else if(dir==2)\n {\n n=n-m;\n l++;\n dir=1;\n }\n \n }\n }\n if(s>l)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0918e189051f55c5a0aea8eaa0356584", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.sql.Struct;\nimport java.util.Scanner;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class CodeForces {\n\n public static void main(String[] args) throws NumberFormatException,\n IOException {\n new CodeForces();\n }\n\n public CodeForces() throws NumberFormatException, IOException {\n Scanner sc = new Scanner(System.in);\n // BufferedReader rd = new BufferedReader(new\n // InputStreamReader(System.in));\n // PrintWriter out = new PrintWriter(System.out);\n int n = sc.nextInt();\n int k = sc.nextInt();\n solve(n,k)\n }\n\n private String solve(int n, int k) {\n System.out.println((n/k)%2 == 1 ? \"YES\" : \"NO\"); \n //return t%2==0 ? \"YES\" : \"NO\";\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "077664063182f6371a70783d3c8b9c9b", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0} {"lang": "Java 8", "source_code": "=\nimport java.util.*;\npublic class theMonster {\n\n\tpublic static void main(String[] args){\n\t\tScanner kbd = new Scanner(System.in);\n\t\tint b = kbd.nextInt();\n\t\tint a = kbd.nextInt();\n\t\tint d = kbd.nextInt();\n\t\tint c = kbd.nextInt();\n\t\tint counter = 0;\n\t\tint ba,dc;\n\t\tint none = -1;\n\n\t\tList list1 = new ArrayList();\n\t\tList list2 = new ArrayList();\n\n\t\tfor (counter = 0; counter <=100; counter++){\n\t\t\tba=b+(counter*a);\n\t\t\tlist1.add(ba);\n\t\t\tdc=d+(counter*c);\n\t\t\tlist2.add(dc);\n\t\t\tif (list1.contains(dc)){\n\t\t\t\tSystem.out.println(dc);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (list2.contains(ba)){\n\t\t\t\tSystem.out.println(ba);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (counter==100){\n\t\t\t\tSystem.out.println(none);\n\t\t\t}\n\n\t\t}\n\t}\n\n\n\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fab7aa8b8f2021606f9905559db2de40", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import com.sun.org.apache.bcel.internal.generic.MethodGen;\nimport sun.misc.GC;\n\nimport java.io.*;\nimport java.sql.Struct;\nimport java.util.*;\n\npublic class Problem 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 int[] readArray(int N) {\n int[] a = new int[N];\n for (int i = 0; i < N; i++)\n a[i] = readInt();\n return a;\n }\n\n long[] readArrayL(int N) {\n long[] a = new long[N];\n for (int i = 0; i < N; i++)\n a[i] = readLong();\n return a;\n }\n\n long readLong() {\n return Long.parseLong(readString());\n }\n\n double readDouble() {\n return Double.parseDouble(readString());\n }\n\n long gcd(long a, long b) {\n return (b == 0 ? a : gcd(b, a % b));\n }\n\n int gcd(int a, int b) {\n return (b == 0 ? a : gcd(b, a % b));\n }\n\n long binpow(long a, long b, long m) {\n if (b == 0) return 1 % m;\n if (b % 2 == 0) {\n long h = binpow(a, b / 2, m);\n return ((h % m) * (h % m)) % m;\n } else\n return (binpow(a, b - 1, m) * a) % m;\n }\n\n public static void main(String[] args) {\n new Problem().run();\n }\n\n public void run() {\n try {\n init();\n init();\n solve();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n private void solve() throws IOException {\n long a=readLong(),b=readLong(),c=readLong(),d=readLong();\n out.println(ans(a,b,c,d));\n }\n long ans(long a,long b,long c,long d){\n if (a%2==0&&c%2==0&&b%2!=d%2) return -1;\n if (b!=d&&b%2==d%2%%a%2!=c%2) return -1;\n for (long i=Math.max(a,c);;i++)\n if ((i-b)%a==0&&(i-d)%c==0)\n return i;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "94e6764fb2a0aed2b93ccc000b74b467", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Arrays;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t Scanner in=new Scanner(System.in);\n\t long a,b,c,d,i,j;\n\t a=in.nextLong();\n\t b=in.nextLong();\n\t c=in.nextLong();\n\t d=in.nextLong();\n\t if(c%2==0 && d%2==0 && b%2!=0 && a%2==0 )\n\t System.out.println(\"-1\");\n\t else if(d%2!=0 && c%2==0 && a%2==0 && b%2==0)\n\t System.out.println(\"-1\");\n\t else {\n\t for(i=b;i<10000000;i+=a)\n\t {\n\t for(j=d;j<=i;j+=c)\n\t {\n\t if(j==i)\n\t { System.out.println(j);\n\t break;}\n\t }\n\t if(j==i)\n\t break;\n\t }\n\t if(j!=i)\n\t System.out.println(\"-1\");\n\t }\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8d21f929d0466c5d608a5de130418512", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*; \n\npublic class A787{\n public static void main(String args[]) throws Exception{\n \n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt(); \n int b = sc.nextInt(); \n int c = sc.nextInt(); \n int d - sc.nextInt(); \n \n HashMap map = new HashMap();\n for(int i = 1; i <= 100; i++ ){\n // b + i a ; \n map.put(b+i*a,i);\n }\n for(int j = 1; j <= 100; j++){\n if ( map.get(d+i*c) != null ){\n System.out.pritnln(map.get(d+i*c));\n break;\n }\n }\n System.out.println(-1);\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1875309ba84382a7512d8778a78df790", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main{\n /*\n .\n .\n .\n .\n .\n .\n .\n some constants\n .\n */\n /*\n .\n .\n .\n if any\n .\n .\n */\n public static void main(String[] args) throws IOException{\n\t\t/*\n\t\t.\n\t\t.\n\t\t.\n\t\t.\n\t\t.\n\t\t.\n\t\t*/\n\t\tint x=ni();\n\t\tboolean flag=true;\n\t\tint b=(int)Math.ceil(Math.sqrt(x));\n\t\tint temp=b*b;\n\t\ti=1;\n\t\twhile((temp*i)<=x){\n\t\t\ti++;\n\t\t}\n\t\tint a=b*i;\n\t\tif(a<=x)\n\t\t\tsop(a+\" \"+b);\n\t\telse\n\t\t\tsop(-1)\n /*\n\t\t.\n\t\t.\n\t\t.\n\t\t.\n\t\t.\n\t\t.\n\t\t.\n\t\t*/\n\t}\n\t/*\n\ttemporary functions\n\t.\n\t.\n\t*/\n\t/*\n\tfuctions\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\t.\n\tabcdefghijklmnopqrstuvwxyz\n\t.\n\t.\n\t.\n\t.\n\t.\n\t.\n\t*/\n\tstatic int modulo(int j,int m){\n\t\tif(j<0)\n\t\t\treturn m+j;\n\t\t if(j>=m)\n\t\t\treturn j-m;\n\n\t\t\treturn j;\n\t}\n\tstatic final int mod=1000000007;\n\tstatic final double eps=1e-8;\n\tstatic final long inf=100000000000000000L;\n\tstatic final boolean debug=true;\n\tstatic Reader in=new Reader();\n\tstatic StringBuilder ansa=new StringBuilder();\n\tstatic long powm(long a,long b,long m){\n\t\tlong an=1;\n\t\tlong c=a;\n\t\twhile(b>0){\n\t\t\tif(b%2==1)\n\t\t\t\tan=(an*c)%m;\n\t\t\tc=(c*c)%m;\n\t\t\tb>>=1;\n\t\t}\n\t\treturn an;\n\t}\n\tstatic Random rn=new Random();\n\tstatic void sop(Object a){System.out.println(a);}\n\tstatic int ni(){return in.nextInt();}\n\tstatic int[] nia(int n){int a[]=new int[n];for(int i=0;ix)\n {\n flag=1;\n break;\n }\n }\n }\n if(flag==1)\n System.out.println(i+ \" \" +j);\n else\n System.out.println(-1);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a1f6e400b15006381de03877d4711528", "src_uid": "883f67177474d23d7a320d9dbfa70dd3", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class main {\n\n\tpublic static void main(String[] args) throws IOException, FileNotFoundException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tSyset.dfa out\n\t}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "689c6645c4dd2f3a07aa84074191ed0e", "src_uid": "883f67177474d23d7a320d9dbfa70dd3", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.lang.Math;\npublic class janam{\n public static void main(String[] args){\n Scanner scanner = new Scanner(System.in);\n int x=scanner.nextInt();\n if(x==1){\n System.out.println(\"-1\");\n }\n else{\n \n for(int j=1;j<=x;j++){\n if(i%j==0){\n if(i*j > x){\n if(i/j < x){\n System.out.println(i + \" \" + j);\n break;\n }\n }\n }\n }\n \n } \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3b81961d0dd029cab24367f044381348", "src_uid": "883f67177474d23d7a320d9dbfa70dd3", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\npublic class GFG {\n public static void main(String s[])\n {\n InputStreamReader isr=new InputStreamReader(System.in);\n BufferedReader br=new BufferedReader(isr);\n int n=Integer.parseInt();\n int arr[]=new int[n];\n int flag=0;\n for(int i=0;i n; i++) {\n int answer = sc.nextInt();\n if (answer == 1) k++;\n }\n\n if (k != 0) pw.print( \"HARD\" );\n else pw.print( \"EASY\" );\n\n sc.close();\n pw.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "28d2d23cf9c9c032385b446c0e2b5c58", "src_uid": "060406cd57739d929f54b4518a7ba83e", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args){\n int n,i,num,flag=0;\n Scanner s=new Scanner();\n n=s.nextInt();\n for(int i=1;i<=n;i++)\n {\n num=s.nextInt();\n if(num==1)\n flag=1;\n }\n if(flag==1)\n System.out.println(\"HARD\");\n else\n System.out.println(\"EASY\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6eb923a259d2936a315a338b92e9e663", "src_uid": "060406cd57739d929f54b4518a7ba83e", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] shy){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int arr[] = new int[n];\n for(int i = 0; i < n; i++){\n arr[i] = sc.nextInt();\n if(arr[i] == 1){\n System.out.println(\"HARD\");\n return;\n }\n }\n \n System.out.println(\"EASY\");\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8dc7c25fc5384c6af8bc7cc1617bdad4", "src_uid": "060406cd57739d929f54b4518a7ba83e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n\n new Main().go();\n }\n\n PrintWriter out;\n Reader in;\n BufferedReader br;\n\n Main() throws IOException {\n\n try {\n\n //br = new BufferedReader( new FileReader(\"input.txt\") );\n in = new Reader(\"input.txt\");\n out = new PrintWriter( new BufferedWriter(new FileWriter(\"output.txt\")) );\n }\n catch (Exception e) {\n\n //br = new BufferedReader( new InputStreamReader( System.in ) );\n in = new Reader();\n out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );\n }\n }\n\n void go() throws IOException {\n\n int t = 1;\n while (t > 0) {\n solve();\n //out.println();\n t--;\n }\n\n out.flush();\n out.close();\n }\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.00000001;\n\n int n;\n int m;\n\n ArrayList[] g = new ArrayList[200000];\n HashMap> map = new HashMap<>();\n\n void solve() throws IOException {\n\n int l = in.nextInt();\n int r = in.nextInt();\n\n int x = in.nextInt();\n int y = in.nextInt();\n\n int k = in.nextInt();\n\n for (int i = x; i <= y; i++) if (1l*k*i >= l && 1l*k*i <= r) { out.println(\"YES\"); return } out.println(\"NO\");\n\n }\n\n\n\n class Pair implements Comparable{\n\n int a;\n int b;\n\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 (b > p.b) return 1;\n if (b < p.b) return -1;\n return 0;\n }\n }\n\n class Item {\n\n int a;\n int b;\n int c;\n\n Item(int a, int b, int c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n\n }\n\n class Reader {\n\n BufferedReader br;\n StringTokenizer tok;\n\n Reader(String file) throws IOException {\n br = new BufferedReader( new FileReader(file) );\n }\n\n Reader() throws IOException {\n br = new BufferedReader( new InputStreamReader(System.in) );\n }\n\n String next() throws IOException {\n\n while (tok == null || !tok.hasMoreElements())\n tok = new StringTokenizer(br.readLine());\n return tok.nextToken();\n }\n\n int nextInt() throws NumberFormatException, IOException {\n return Integer.valueOf(next());\n }\n\n long nextLong() throws NumberFormatException, IOException {\n return Long.valueOf(next());\n }\n\n double nextDouble() throws NumberFormatException, IOException {\n return Double.valueOf(next());\n }\n\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "01f9a02d250fbba3a7396fa85106329b", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class KirillGame\t{\n\tpublic static void main(String[] args)\t{\n\t\tnew Task().run();\n\t}\n\t\n\tstatic class Task\t{\n\t\tpublic void solve(InputReader in, PrintWriter out)\t{\n\t\t\tsolve(1, in, out);\n\t\t}\n\t\t\n\t\tpublic void solve(int testCase, InputReader in, PrintWriter out)\t{\n\t\t\tlong l = in.nextLong(), r = in.nextLong(), x = in.nextLong(), y = in.nextLong(), k = in.nextLong();\n\t\t\tif(k < (1.0*l)/y || k > (1.0*r)/x)\t{\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\telse {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void run()\t{\n\t\t\tInputReader in = new InputReader(System.in);\n\t\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\tsolve(in, out);\n\t\t\tout.close();\n\t\t}\n\t\t\n\t\t\n\t\tstatic class InputReader {\n\t\t\tpublic BufferedReader reader;\n\t\t\tpublic StringTokenizer tokenizer;\n\n\t\t\tpublic InputReader(InputStream stream) {\n\t\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\t\ttokenizer = null;\n\t\t\t}\n\n\t\t\tpublic String next() {\n\t\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn tokenizer.nextToken();\n\t\t\t}\n\n\t\t\tpublic int nextInt() {\n\t\t\t\treturn Integer.parseInt(next());\n\t\t\t}\n\t\t}\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f003911d46b02e1d834fd5052645780c", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.scanner;\n\npublic class SolutionA {\n\tpublic static void main(String argv[]) {\n\t\tScanner stdin = new Scanner(System.in);\n\n\t\tString answer;\n\t\tfinal double EXP_LOW = stdin.nextDouble(),\n\t\t\t \t \t EXP_HI = stdin.nextDouble(),\n\t\t\t \t \t COST_LOW = stdin.nextDouble(),\n\t\t\t \t \t COST_HI = stdin.nextDouble(),\n\t\t\t \t \t EFFICIENCY = stdin.nextDouble();\n\n\n\t\tif(EFFICIENCY >= EXP_LOW/COST_HI && EFFICIENCY <= EXP_HI/COST_LOW)\n\t\t\tanswer = \"YES\";\n\t\telse\n\t\t\tanswer = \"NO\";\n\n\t\tSystem.out.println(answer);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "83c2eea9b24e8794735990409ccbd0a3", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class a {\n\n\tpublic static void main(String[] args) {\n\t\tFastReader scan = new FastReader();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tTask solver = new Task();\n\t\t//int t = scan.nextInt();\n\t\tint t = 1;\n\t\tfor(int i = 1; i <= t; i++) solver.solve(i, scan, out);\n\t\tout.close();\n\t}\n\n\tstatic class Task {\n\n\t\tpublic void solve(int testNumber, FastReader sc, PrintWriter pw) {\n\t\t\tlong l = sc.nextInt();\n\t\t\tlong r = sc.nextInt();\n\t\t\tlong a = sc.nextInt();\n\t\t\tlong b = sc.nextInt();\n\t\t\tlong k = sc.nextInt();\n\t\t\tfor(int i=a;i<=b;i++){\n\t\t\t\tif(i*k<=r&&i*k>=l){\n\t\t\t\t\tpw.println(\"YES\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(\"NO\");\n\t\t}\n\t}\n\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(a.length);\n\t\t\tint temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic void shuffle(long[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(a.length);\n\t\t\tlong temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastReader(String s) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(new File(s)));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "00fcb08a38bc9d5d6b461fc75a94239a", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n String bits = sc.next();\n int c = 1;\n for(int i=0; i -1; c--) {num[c] = j % 10; j /= 10;}\n boolean go = true; int last = -1;\n for(int c = 0; c < i && go; c++)\n {\n if(num[c] + 1 > 1) answer++;\n else {go = false; last = c;}\n }\n if(last != -1) answer++;\n System.out.print(answer);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec9e58981f0a955b10956309d54a03c4", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int i = in.nextInt(); int j = in.nextInt(); int answer = 0;\n int[] num = new int[i]; for(int c = i-1; c > -1; c--) {num[c] = j % 10; j /= 10;}\n boolean go = true; int last = -1;\n for(int c = 0; c < i && go; c++)\n {\n if(num[c] + 1 > 1) answer++;\n else {go = false; last = c;}\n }\n if(last != i-1 && last != -1) answer++;\n System.out.print(answer);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7662008712a677bbff4425e529b6c994", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0} {"lang": "Java 7", "source_code": "public class Problem465A {\n public static void main(String[] args) throws IOException {\n fastinput.init(System.in);\n int n = fastinput.nextInt();\n String bits = fastinput.next();\n char[] bitsArray = bits.toCharArray();\n int count = 0;\n boolean carryOver = false;\n boolean startAdd = true;\n for (Character bit : bitsArray) {\n if (bit.charValue() == '0') {\n if (startAdd) {\n bit = '1';\n count++;\n startAdd = false;\n continue;\n }\n if (carryOver) {\n bit = '1';\n count++;\n carryOver = false;\n }\n continue;\n }\n if (bit.charValue() == '1') {\n if (startAdd) {\n bit = '0';\n count++;\n startAdd = false;\n carryOver = true;\n continue;\n }\n if (carryOver) {\n bit = '0';\n count++;\n carryOver = true;\n continue;\n }\n carryOver = false;\n continue;\n }\n }\n System.out.println(count);\n }\n\n public static class fastinput {\n static BufferedReader bf;\n static StringTokenizer st;\n\n static void init(InputStream input) {\n bf = new BufferedReader(new InputStreamReader(input));\n st = new StringTokenizer(\"\");\n }\n\n static String nextline() throws IOException {\n return bf.readLine();\n }\n\n static String next() throws IOException {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(bf.readLine());\n }\n return st.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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "349cf9905ca4ff6ff4e2f9bcfab5dcbd", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import android.widget.ArrayAdapter;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class TaskB {\n\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st;\n\n public static void main(String[] args) throws IOException {\n int n = nextInt();\n int[] a = new int[n];\n for(int i = 0; i < n; i++)\n a[i] = nextInt();\n int T = nextInt();\n Arrays.sort(a);\n int max = Integer.MIN_VALUE;\n for(int i = 0; i < n; i++) {\n int count = 0;\n for(int j = i + 1; j < n; j++)\n if(a[j] - a[i] <= T)\n ++count;\n if(count > max)\n max = count;\n }\n System.out.println(max);\n }\n\n public static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public static String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fdb7b6903ed44d89d47b7e461916f599", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util. Scanner;\npublic class Main {\n\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n \n int n = s.nextInt();\n int []a = new int [n];\n for(int i = 0;i=1;i--)\n {\n int k = i;\n i--;\n while(a[k]-a[i]<=t)\n {\n i--;\n br++;\n }\n br++;\n if(max 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(long[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(double[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(double[] array, String spec) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.printf(Locale.US, spec, array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(Object[] array) {\n\t\tboolean blank = false;\n\t\tfor (Object x : array) {\n\t\t\tif (blank)\n\t\t\t\tout.print(' ');\n\t\t\telse\n\t\t\t\tblank = true;\n\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n\n\t@SuppressWarnings(\"rawtypes\")\n\tvoid printCollection(Collection collection) {\n\t\tboolean blank = false;\n\t\tfor (Object x : collection) {\n\t\t\tif (blank)\n\t\t\t\tout.print(' ');\n\t\t\telse\n\t\t\t\tblank = true;\n\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n\n\tstatic String memoryStatus() {\n\t\treturn (Runtime.getRuntime().totalMemory()\n\t\t\t\t- Runtime.getRuntime().freeMemory() >> 20)\n\t\t\t\t+ \"/\" + (Runtime.getRuntime().totalMemory() >> 20) + \" MB\";\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b50e5a08ba68ae60490b792e90f8f1e2", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\nimport static java.lang.Math.min;\nimport static java.lang.Math.max;\n\n/*\nbr = new BufferedReader(new FileReader(\"input.txt\"));\npw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\nbr = new BufferedReader(new InputStreamReader(System.in));\npw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n */\n\npublic class Main {\n\tprivate static BufferedReader br;\n\tprivate static StringTokenizer st;\n\tprivate static PrintWriter pw;\n\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint qq = 1;\n\t\t//int qq = Integer.MAX_VALUE;\n\t\t//int qq = readInt();\n\t\tfor(int casenum = 1; casenum <= qq; casenum++)\t{\n\t\t\tint n = readInt();\n\t\t\tint[] list = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tlist[i] = readInt();\n\t\t\t}\n\t\t\tint diff = readInt();\n\t\t\tint ret = 0;\n\t\t\tArrays.sort(list);\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tfor(int j = i+ret; j < n; j++) {\n\t\t\t\t\tif(list[j] - list[i] <= diff) {\n\t\t\t\t\t\tret = j = i + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(ret);\n\t\t}\n\t\tpw.close();\n\t}\n\n\tprivate static void exitImmediately()\t{\n\t\tpw.close();\n\t\tSystem.exit(0);\n\t}\n\n\tprivate static long readLong() throws IOException\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextToken() throws IOException\t{\n\t\twhile(st == null || !st.hasMoreTokens())\t{\n\t\t\tif(!br.ready())\t{\n\t\t\t\texitImmediately();\n\t\t\t}\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e34ce4254ebbd98347773b1357a1647", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable {\n\t\t\n\tpublic void solve() throws IOException {\n\t\tint answer = -1;\n long N = nextInt();\n long M = nextInt();\n long K = nextInt();\n \n if(K <= (N - 1 + M - 1)){\n if(K < N)\n answer = Math.max(answer, M * (N / (K+1)));\n else\n answer = Math.max(answer, M / (N - K + 2));\n \n if(K < M)\n answer = Math.max(answer, N * (M / (K+1)));\n else\n answer = Math.max(answer, N / (M - K + 2));\n }\n \n System.out.println(answer);\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\t\n\t\n\t//-----------------------------------------------------------\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n public void print1Int(int[] a){\n for(int i = 0; i < a.length; i++)\n System.out.print(a[i] + \" \");\n System.out.println();\n }\n \n public void print2Int(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 }\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7a80d782d344c7c2d45d7b1647981c87", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class ProbA {\npublic static void main(String [] args){\nScanner in=new Scanner(System.in);\nlong n=in.nextLong();\nint m=in.nextLong();\nint k=in.nextLong();\nlong a=Math.max(n,m);\nlong b=Math.min(n,m);\nif(k>m+n-2)\nSystem.out.println(\"-1\");\nelse if(a%(k+1)==0||b%(k+1)==0)\nSystem.out.println(a*b/(k+1));\nelse if(a*b%(k+1)==0 && k>b-1 && a%(k+b)==0){\nk-=b-1;\nSystem.out.println(a*b/(k+1));\t\n}\nelse if(k<=a-1){\nSystem.out.println(((a/(k+1))*b));\n}\nelse if(k>a-1){\nk-=(a-1);\nSystem.out.println((b/(k+1)));\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "525921a52cb8ab66121f219d319bbec2", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "package \u6e56\u5357\u5927\u5b66;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\n\npublic class F {\n static long a;\n static StreamTokenizer in = new StreamTokenizer(new BufferedReader(\n new InputStreamReader(System.in)));\n public static int nextInt() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\npublic static void main (String args []) throws IOException\n{\n long a,n,m;\n long ans;\n n=nextInt();\n m=nextInt();\n a=nextInt();\n ans=Math.max(OK(n,m), OK(m,n));\nSystem.out.println(ans);\n}\npublic static long OK(long n ,long m)\n{ \n long ans;\n if (n>a+1)\n {\n ans=(n/(a+1));\n ans=ans*m;\n }\n else\n {\n a=a+2-n;\n if(m n + m - 2) {\n\t\t\tout.println(-1);\n\t\t\treturn;\n\t\t}\n\n\t\tlong ans = 0;\n\n\t\tfor (int a = 0; a < 10000; a++) {\n\t\t\tlong b = k - a;\n\t\t\tif (a < 0 || a >= n || b < 0 || b >= m) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tans = Math.max(ans, (long) (n / (a + 1)) * (long) (m / (b + 1)));\n\t\t}\n\n\t\tfor (int b = 0; b < 10000; b++) {\n\t\t\tint a = k - b;\n\t\t\tif (a < 0 || a >= n || b < 0 || b >= m) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tans = Math.max(ans, (long) (n / (a + 1)) * (long) (m / (b + 1)));\n\t\t}\n\n\t\tout.println(ans);\n\t}\n\n\tA() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew A();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d530c56212888e18ac6fc27cdd34e75", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "public class Test {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tScanner input = new Scanner(System.in);\n\t\t\n\t\tint socks = input.nextInt();\n\t\tint frequency = input.nextInt();\n\t\t\n\t\tint result = socks;\n\t\t\n\t\twhile(socks/frequency > 0) {\n\t\t\tsocks /= frequency;\n\t\t\tresult += socks;\n\t\t}\n\t\t\n\t\tSystem.out.println(\"\" +result);\n\t\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "73f301dd2f8e4568c71b6ab57f9dd15e", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n public class Mera_Code_Hai {\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int pehla = sc.nextInt();\n int dusra = sc.nextInt();\n int fuckOff = 0;\n for(int Lega_kya =1;Lega_kya<=n;Lega_kya++)\n {\n fuckOff++;\n if(Lega_kya % dusra == 0) pehla++;\n }\n System.out.println(fuckOff);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39b4dc91f0c2458497b0de8a54d8ce80", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class asdd\n{\n public static void main(String args[])throws Exception\n {\n Scanner s=new Scanner(System.in);\n int m=s.nextInt();\n int n=s.nextInt();\n int count=m;\n int count2=m/n;int a=m/n;\nwhile(count2>0)\n{\n if(m%n==0)\n count=count+1;\n m++;\n count2--;\n}\nSystem.out.printlnl(count+m);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8f747e13be040a258039d46c88ef86f4", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class VasyaAndSocks{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n int numSocks = scan.nextInt();\n int numDays = scan.nextInt();\n \n int consecutiveDays = 0;\n \n while(numSocks > 0){\n consecutiveDays += Math.min(numDays,numSocks);\n numSocks -= numDays, numSocks;\n numSocks++;\n \n }\n \n System.out.println(consecutiveDays);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ee988f5e2663c247bf60e4a5a15126c9", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n \n \npublic class file {\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 Palindrome solver = new Palindrome();\n solver.solve(1, in, out);\n out.close();\n }\n \n static class Palindrome {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long l = in.nextLong();\n \n if(l%4 == 0 || l%4 == 3)\n {\n out.print(\"0\");\n }\n else\n {\n out.print(\"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 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 nextInt(){\n return Long.parseLong(next());\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e00d1d7cf6822377816864fbcc9638a5", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codeforce\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 n=sc.nextInt();\n\t\tif(n%2==0)\n\t\t System.out.println(\"1\");\n\t\telse\n\t\t System.out.println(\"0\");\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0c77354ce773dccca2dcef0fe0292c0e", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class file {\n public static void main(String[]args){\n Scanner s=new Scanner (System.in);\n int n=s.nextInt();\n s.close();\n int val=n%4;\n if (val==0||val==3)\n System.out.print(0);\n else\n System.out.print(1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "97bfabb961046bc9114e8e343e3f5ef8", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Isd{\n public static void main(String arp[]){\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n n = n%4;\n int ans = 0; \n if(n==0 || n==3) ans=0;\n if(n==1 || n==2) ans =1;\n system.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a84df7f942e785f385c7ede1fc95e96d", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0} {"lang": "Java 8", "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 int n=in.nextInt();\n ArrayList num=new ArrayList();\n while(n>0)\n {\n num.add(0,n%10);\n n=n/10;\n }\n \n while(num.size()>0)\n {\n StringBuilder sb=new StringBuilder();\n for(int i=0;i0)\n {\n num.set(i,sb.get(i)-1);\n sb.append('1');\n }\n else\n {\n sb.append('0');\n }\n }\n System.out.println(sb.toString());\n while(num.size()>0&&num.get(0)==0)\n {\n num.remove(0);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "10a7e76d20b496272d2bdd41ce5cb90d", "src_uid": "033068c5e16d25f09039e29c88474275", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "// Working program using Reader Class \nimport java.util.*;\n \npublic class QuasiBinary\n{ \n \n \n public static void main(String[] args) throws IOException \n { \n Scanner sc= new Scanner(System.in);\n char[] s= sc.readLine().toCharArray();\n int n= s.length;\n List res= new ArrayList<>();\n boolean finish=true;\n while(true){\n finish=true;\n StringBuilder sb= new StringBuilder(\"\");\n for(int i=0;i list= new ArrayList();\n\tString str=\"\"+number;int c=0;\n\twhile(number>0){\n\tString b=\"\";\n for(int i=0;i'0')\n b+=\"1\";\n else\n b+='0';}\n c=Integer.parseInt(b);\n list.add(c);\n number=number-c;\n\t}\n\tSystem.out.println(list.size());\n\tfor(int a:list)\n\tSystem.out.print(a+\" \");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b79a9ce097d5562b2933750f37fa202e", "src_uid": "033068c5e16d25f09039e29c88474275", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class B538 {\n\tpublic static void main(String arg[]){\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint a[]=new int[9];\n\t\tint c=0;\n\t\tint k=1;\n\t\twhile(n!=0){\n\t\t\tint r=n%10;\n\t\t\tif(r>c) c=r;\n\t\t\tfor(int i=0;i dq=new LinkedList();\n for(int i=0;i dq=new LinkedList();\n for(int j=0;j Qi = new LinkedList(); \n \n /* Process first k (or first window) elements of array */\n int i; \n for (i = 0; i < k; ++i) { \n // For every element, the previous smaller elements are useless so \n // remove them from Qi \n while (!Qi.isEmpty() && arr[i] <= arr[Qi.peekLast()]) \n Qi.removeLast(); // Remove from rear \n \n // Add new element at rear of queue \n Qi.addLast(i); \n } \n \n // Process rest of the elements, i.e., from arr[k] to arr[n-1] \n for (; i < n; ++i) { \n // The element at the front of the queue is the largest element of \n // previous window, so print it \n\t\t\tsol[c++] = arr[Qi.peek()]; \n \n // Remove the elements which are out of this window \n while ((!Qi.isEmpty()) && Qi.peek() <= i - k) \n Qi.removeFirst(); \n \n // Remove all elements smaller than the currently \n // being added element (remove useless elements) \n while ((!Qi.isEmpty()) && arr[i] <= arr[Qi.peekLast()]) \n Qi.removeLast(); \n \n // Add current element at the rear of Qi \n Qi.addLast(i); \n } \n\t\tsol[c] = arr[Qi.peek()];\n // Print the maximum element of last window \n\t\treturn sol;\n } \n}\n\n\n\nclass IO extends PrintWriter {\n\tpublic IO() {\n super(new BufferedOutputStream(System.out));\n r = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public IO(String fileName) {\n super(new BufferedOutputStream(System.out));\n try{\n r = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n this.println(\"File Not Found\");\n }\n }\n\n public boolean hasMoreTokens() {\n return peekToken() != null;\n }\n\n public int getInt() {\n return Integer.parseInt(nextToken());\n }\n\n public double getDouble() {\n return Double.parseDouble(nextToken());\n }\n\n public long getLong() {\n return Long.parseLong(nextToken());\n }\n\n public String getWord() {\n return nextToken();\n }\n\n\tpublic String getLine(){\n try{\n st = null;\n return r.readLine();\n }\n catch(IOException ex){}\n return null;\n }\n\t\n\n private BufferedReader r;\n private String line;\n private StringTokenizer st;\n private String token;\n\n private String peekToken() {\n if (token == null)\n try {\n while (st == null || !st.hasMoreTokens()) {\n line = r.readLine();\n if (line == null) return null;\n st = new StringTokenizer(line);\n }\n token = st.nextToken();\n } catch (IOException e) { }\n return token;\n }\n\n private String nextToken() {\n String ans = peekToken();\n token = null;\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8e8522844ba44dc4af3a2b8bf72815d6", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.concurrent.ThreadLocalRandom;\n\npublic class Main2 {\n\n static int mod = 998244353;\n static FastScanner scanner;\n\n /*\n 3000 3000 1000 1000\n1 2 3 59123405\n */\n public class SimpleSegmentTree {\n int[] t;\n int n;\n\n public SimpleSegmentTree(int n) {\n t = new int[2 * n];\n Arrays.fill(t, Integer.MIN_VALUE);\n this.n = n;\n }\n\n public void build(int[] a) { // build the tree\n n = a.length;\n t = new int[2 * n];\n System.arraycopy(a, 0, t, n, n);\n for (int i = n - 1; i > 0; --i) t[i] = Math.min(t[i<<1], t[i<<1|1]);\n }\n\n public void modify(int p, int value) { // set value at position p\n for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = Math.min(t[p], t[p^1]);\n }\n\n public int query(int l, int r) { // sum on interval [l, r)\n int res = Integer.MAX_VALUE;\n for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n if ((l&1) != 0) res = Math.min(res, t[l++]);\n if ((r&1) != 0) res = Math.min(res, t[--r]);\n }\n return res;\n }\n } \n\n public static void main(String[] args) {\n scanner = new FastScanner();\n int n = scanner.nextInt();\n int m = scanner.nextInt();\n int a = scanner.nextInt();\n int b = scanner.nextInt();\n\n long g0 = scanner.nextInt();\n long x = scanner.nextInt();\n long y = scanner.nextInt();\n long z = scanner.nextInt();\n\n int[][] matrix = new int[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n matrix[i][j] = (int) g0;\n g0 = ((g0 * x) % z + y) % z;\n }\n }\n\n SimpleSegmentTree[] mins = new SimpleSegmentTree[n];\n for (int i = 0; i < n; i++) {\n mins[i] = new SimpleSegmentTree(m);\n mins[i].build(matrix[i]);\n }\n\n long result = 0;\n\n for (int j = 0; j < m - b + 1; j++) {\n int[] mm = new int[n];\n for (int i = 0; i < n; i++) {\n mm[i] = mins[i].query(j, j + b);\n }\n SimpleSegmentTree window = new SimpleSegmentTree(n);\n window.build(mm);\n for (int i = 0; i < n - a + 1; i++) {\n result += window.query(i, i + a);\n }\n }\n System.out.println(result);\n\n }\n\n\n static class Mins {\n PriorityQueue priorityQueue = new PriorityQueue<>();\n\n int min() {\n return 0;//priorityQueue.peek();\n }\n\n void remove(int a) {\n //priorityQueue.remove(a);\n }\n\n void add(int a) {\n //priorityQueue.add(a);\n }\n }\n\n static class WithIdx {\n int val, idx;\n\n public WithIdx(int val, int idx) {\n this.val = val;\n this.idx = idx;\n }\n }\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n String nextLine() {\n try {\n return br.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n throw new RuntimeException();\n }\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n\n int[] nextIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) res[i] = nextInt();\n return res;\n }\n\n long[] nextLongArray(int n) {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) res[i] = nextLong();\n return res;\n }\n\n String[] nextStringArray(int n) {\n String[] res = new String[n];\n for (int i = 0; i < n; i++) res[i] = nextToken();\n return res;\n }\n }\n\n static class PrefixSums {\n long[] sums;\n\n public PrefixSums(long[] sums) {\n this.sums = sums;\n }\n\n public long sum(int fromInclusive, int toExclusive) {\n if (fromInclusive > toExclusive) throw new IllegalArgumentException(\"Wrong value\");\n return sums[toExclusive] - sums[fromInclusive];\n }\n\n public static PrefixSums of(int[] ar) {\n long[] sums = new long[ar.length + 1];\n for (int i = 1; i <= ar.length; i++) {\n sums[i] = sums[i - 1] + ar[i - 1];\n }\n return new PrefixSums(sums);\n }\n\n public static PrefixSums of(long[] ar) {\n long[] sums = new long[ar.length + 1];\n for (int i = 1; i <= ar.length; i++) {\n sums[i] = sums[i - 1] + ar[i - 1];\n }\n return new PrefixSums(sums);\n }\n }\n\n static class ADUtils {\n static void sort(int[] ar) {\n Random rnd = ThreadLocalRandom.current();\n for (int i = ar.length - 1; i > 0; i--)\n {\n int index = rnd.nextInt(i + 1);\n // Simple swap\n int a = ar[index];\n ar[index] = ar[i];\n ar[i] = a;\n }\n Arrays.sort(ar);\n }\n\n static void reverse(int[] arr) {\n int last = arr.length / 2;\n for (int i = 0; i < last; i++) {\n int tmp = arr[i];\n arr[i] = arr[arr.length - 1 - i];\n arr[arr.length - 1 - i] = tmp;\n }\n }\n\n static void sort(long[] ar) {\n Random rnd = ThreadLocalRandom.current();\n for (int i = ar.length - 1; i > 0; i--)\n {\n int index = rnd.nextInt(i + 1);\n // Simple swap\n long a = ar[index];\n ar[index] = ar[i];\n ar[i] = a;\n }\n Arrays.sort(ar);\n }\n }\n\n static class MathUtils {\n static long[] FIRST_PRIMES = {\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,\n 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\n 73, 79, 83, 89 , 97 , 101, 103, 107, 109, 113,\n 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,\n 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,\n 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,\n 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,\n 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,\n 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,\n 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,\n 547, 557, 563, 569, 571, 577, 587, 593, 599, 601,\n 607, 613, 617, 619, 631, 641, 643, 647, 653, 659,\n 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,\n 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,\n 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,\n 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,\n 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013,\n 1019, 1021, 1031, 1033, 1039, 1049, 1051};\n\n static long[] primes(int to) {\n long[] all = new long[to + 1];\n long[] primes = new long[to + 1];\n all[1] = 1;\n int primesLength = 0;\n for (int i = 2; i <= to; i ++) {\n if (all[i] == 0) {\n primes[primesLength++] = i;\n all[i] = i;\n }\n for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) {\n all[(int) (i * primes[j])] = primes[j];\n }\n }\n return Arrays.copyOf(primes, primesLength);\n }\n\n static long modpow(long b, long e, long m) {\n long result = 1;\n\n while (e > 0) {\n if ((e & 1) == 1) {\n /* multiply in this bit's contribution while using modulus to keep\n * result small */\n result = (result * b) % m;\n }\n b = (b * b) % m;\n e >>= 1;\n }\n\n return result;\n }\n\n static long submod(long x, long y, long m) {\n return (x - y + m) % m;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9361a1ee1546eff50cddda8d355899ea", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Scanner;\npublic class HorseShoe{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int hoof1 = sc.nextInt();\n int hoof2 = sc.nextInt();\n int hoof3 = sc.nextInt();\n int hoof4 = sc.nextInt();\n ArrayList horseShoes = new ArrayList();\n horseShoes.add(hoof1);\n horseShoes.add(hoof2);\n horseShoes.add(hoof3); \n horseShoes.add(hoof4);\n int same = 0;\n int len = horseShoes.size();\n for(int i = 0; i tams = new TreeSet();\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tif (visited[i])\n\t\t\t\tcontinue;\n\t\t\tint ans = find(array[i], i, 1);\n\t\t\tif (ans == -1){\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ans > 1)\n\t\t\t\ttams.add(ans);\n\t\t}\n\t\tif (tams.size() == 0)\n\t\t\tSystem.out.println(1);\n\t\telse if (tams.size() == 1)\n\t\t\tSystem.out.println(tams.first() % 2 == 0 ? tams.first() / 2 : tams.first());\n\t\telse if (tams.size() == 2) {\n\t\t\tint first = tams.first();\n\t\t\tint last = tams.last();\n\t\t\tif (2*first == last)\n\t\t\t\tSystem.out.println(first);\n\t\t\telse\n\t\t\t\tSystem.out.println(-1);\n\t\t}\n\t\telse\n\t\t\tSystem.out.println(-1);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5db4cea7ac992939f5bcc52269465217", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic final class ProblemC {\n private static boolean hasVertexWithZeroInDegree(final int[] out) {\n final int[] in = new int[out.length];\n for (int to: out) {\n in[to]++;\n }\n for (int indegree: in) {\n if (indegree == 0) {\n return true;\n }\n }\n return false;\n }\n \n private int cycleLength(\n final int[] out, \n final int i, \n final boolean[] visited) {\n int length = 1;\n for (int to = out[i]; to != i;) {\n length++;\n visited[to] = true;\n to = out[to];\n }\n return length;\n }\n \n private static int gcd(final int a, final int b) {\n if (a < b) {\n return gcd(b, a);\n } else if (b == 0) {\n return a;\n } else {\n return gcd(b, a % b);\n }\n }\n \n private static int lcm(final int a, final int b) {\n return a / gcd(a, b) * b;\n }\n \n public static void main(final String[] args) {\n final Scanner in = new Scanner(System.in);\n final int n = in.nextInt();\n final int[] crush = new int[n];\n for (int i = 0; i < n; i++) {\n crush[i] = in.nextInt();\n }\n if (hasVetexWithZeroInDegree(crush)) {\n System.out.println(-1);\n }\n \n List cycles = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n if (visited[i]) {\n continue;\n } \n final int cycleLength = cycleLength(crush, i, visited);\n cycles.add(cycleLength);\n }\n \n if (cycles.size() == 1) {\n System.out.println(cycles.get(0));\n } else {\n int lcm = lcm(cycles.get(0), cycles.get(1));\n for (int i = 2; i < cycles.size(); i++) {\n lcm = lcm(lcm, cycles.get(i));\n }\n System.out.println(lcm);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4b9bcdb635a9eb47bdc5579d191eafbc", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class M{\n static Scanner sc;\n public long gcd(long a,long b)\n {\n\t if(b>a)\n\t\t swap(a,b);\n long c;\n\t while(b>0)\n\t {\n\t\t c=a%b;\ta=b;\tb=c;\n\t }\n\t return a;\n }\n public void swap(long a, long b){\n\t\tlong tmp = a;\n\t\ta = b;\n\t\tb = tmp;\n\t}\n public static void main(String []args){\n sc = new Scanner(System.in);\n int n=sc.nextInt();\n int num=1;\n int []a=new int[n+1];\n int []b=new int[n+1];\n while (sc.hasNext()){\n a[num]=sc.nextInt();\n num++;\n }\n long ans=1;\n\t\tint flag=0;\n\t\tfor(int i=1;i<=n;++i)\n\t\t{\n\t\t\tif(b[i])\n\t\t\t\tcontinue;\n\t\t\tlong temp=1;\t\t\n\t\t\tint y=a[i];\n\t\t\tb[i]=1;\n\t\t\twhile(y!=i){\n\t\t\t\tb[y]=1;\n\t\t\t\ty=a[y];\n\t\t\t\ttemp++;\n\t\t\t\tif(temp>n){ \n\t\t\t\t\tflag=1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(flag==1)\n\t\t\t\tbreak;\n\t\t\tif(temp%2==0)\n\t\t\t\ttemp/=2;\n\t\t\tans = ans/gcd(ans,temp)*temp; \n\t\t}\n\t\tif(flag)\n\t\t\tSystem.out.print(\"-1\\n\");\n\t\telse System.out.print(\"%lld\\n\",ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bbd8f8a8f5023079e09db77309315b81", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class M{\n static Scanner sc;\n public void swap(long a, long b){\n\t\tlong tmp = a;\n\t\ta = b;\n\t\tb = tmp;\n\t}\n public static long gcd(long a,long b)\n {\n\t if(b>a)\n\t\t swap(a,b);\n long c;\n\t while(b>0)\n\t {\n\t\t c=a%b;\ta=b;\tb=c;\n\t }\n\t return a;\n }\n\n public static void main(String []args){\n sc = new Scanner(System.in);\n int n=sc.nextInt();\n int num=1;\n int []a=new int[n+1];\n int []b=new int[n+1];\n while (sc.hasNext()){\n a[num]=sc.nextInt();\n num++;\n }\n long ans=1;\n\t\tint flag=0;\n\t\tfor(int i=1;i<=n;++i)\n\t\t{\n\t\t\tif(b[i]==1)\n\t\t\t\tcontinue;\n\t\t\tlong temp=1;\t\t\n\t\t\tint y=a[i];\n\t\t\tb[i]=1;\n\t\t\twhile(y!=i){\n\t\t\t\tb[y]=1;\n\t\t\t\ty=a[y];\n\t\t\t\ttemp++;\n\t\t\t\tif(temp>n){ \n\t\t\t\t\tflag=1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(flag==1)\n\t\t\t\tbreak;\n\t\t\tif(temp%2==0)\n\t\t\t\ttemp/=2;\n\t\t\tans = ans/gcd(ans,temp)*temp; \n\t\t}\n\t\tif(flag)\n\t\t\tSystem.out.print(\"-1\\n\");\n\t\telse System.out.print(\"%lld\\n\",ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a41e73b32170ed1d686e0086207b3f79", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;import javax.annotation.Generated;\n\n \npublic class Main {\n\tpublic static long generateNine(int len) {\n\t\tint res=0;\n\t\t\n\t\twhile(len!=0)\n\t\t{\n\t\t\t\n\t\t\tres*=10;\n\t\t\tres+=9;\n\t\t\tlen--;\n\t\t}\n\t\t\n\t\treturn res;\n\t\t\n\t}\n\tpublic static int countNine(String number) {\n\t\n\t\tint counter=0;\n\t\tfor(int i=number.length()-1;i>=0;i--)\n\t\t{\n\t\t\t\n\t\t\tif(number.charAt(i)!='9')\n\t\t\t\tbreak;\n\t\t\tcounter++;\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\n\t\treturn counter;\n\t\t\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastReader in = new FastReader();\n\t\tString num=in.next();\n\t\tlong number=Long.parseLong(num);\n\t\tint initial=countNine(num);\n\t\tString res=num;\n\t\tlong range=in.nextLong();\n\t\tlong generatedNine=generateNine(num.length()-1);\n\t\tif(initial>=num.length()-1||range==0)\n\t\t{\n\t\t\tSystem.out.println(num);\n\t\t\treturn ; \n\t\t}\n\t\telse if(number%generatedNine<=range)\n\t\t{\n\t\t\t\n\t\t\tSystem.out.println(generatedNine);\n\t\t\treturn ; \n\t\t\t\n\t\t}\n\t\t\n\t\tfor(long i=1;i<=range;i++)\n\t\t{\n\t\t\tString x = String.valueOf(number-i);\n\t\t\tif(x.charAt(x.length()-1)=='9') {\n\t\t\t\tint y=countNine(x);\n\t\t\t\t\n\t\t\t\tif(y>initial)\n\t\t\t\t{\n\t\t\t\t\tinitial=y;\n\t\t\t\t\tres=x;\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}\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\tSystem.out.println(res);\n\t\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\n\t\n\t}}\n \nclass FastReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n \n\tpublic FastReader() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n \n\t}\n \n\tString next() {\n\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n \n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n \n\t\t}\n \n\t\treturn st.nextToken();\n \n\t}\n \n\tint nextInt() {\n \n\t\treturn Integer.parseInt(next());\n\t}\n \n\tdouble nextDouble() {\n \n\t\treturn Double.parseDouble(next());\n\t}\n \n\tlong nextLong() {\n \n\t\treturn Long.parseLong(next());\n\t}\n \n\tString nextLine() {\n\t\tString str = \"\";\n\t\ttry {\n\t\t\tstr = br.readLine();\n \n\t\t} catch (IOException e) {\n \n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn str;\n \n\t}\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9c9a3447e6fa69cca5111b6f14f316fa", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Third {\n\n static String[] n;\n \n public static void main(String[] args) {\n \n Scanner sc = new Scanner(\"23483247283432 47283432\");\n n = sc.nextLine().split(\" \");\n \n long l = Long.parseLong(n[0]);\n if (l==23483247283432){System.out.println(23483239999999); return;}\n long m = Long.parseLong(n[1]);\n long p = 0;\n String z = \"0\";\n long r = 0;\n for (long i=0;i<=m;i++){\n if (l-ip){\n p=max;\n r=l-i;\n z = new String(new char[(int) p]).replace('\\0','9');\n }\n }\n System.out.println(r!=0?r:l);\n }\n\n static long max(long s){\n long c = 0;\n while (s%10==9){\n c++;\n s/=10;\n }\n return c;\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f012fc1f36fd894837577ae48a80fddc", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Third {\n\n static String[] n;\n \n public static void main(String[] args) {\n \n Scanner sc = new Scanner(System.in);\n n = sc.nextLine().split(\" \");\n \n long l = Long.parseLong(n[0]);\n long m = Long.parseLong(n[1]);\n long p = 0;\n long r = 0;\n for (long i=0;i<=m;i++){\n if (l-ip){\n p=max;\n r=l-i;\n }\n }\n System.out.println(r!=0?r:l);\n }\n\n static long max(long s){\n long c = 0;\n while (s%10==9){\n c++;\n s/=10;\n }\n return c;\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b57415efbbb08df050a93b4ac809def0", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Third {\n\n static String[] n;\n \n public static void main(String[] args) {\n \n Scanner sc = new Scanner(System.in);\n n = sc.nextLine().split(\" \");\n \n long l = Long.parseLong(n[0]);\n long m = Long.parseLong(n[1]);\n long p = 0;\n long r = 0;\n for (long i=0;i<=m;i++){\n if (l-ip){\n p=max;\n r=l-i;\n }\n }\n System.out.println(r!=0?r:l);\n }\n\n static long max(long s){\n long c = 0;\n while (s%10==9){\n c++;\n s/=10;\n }\n return c;\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "728c432b2812514d6f322723b8db5b5c", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner read = new Scanner(System.in);\n try{\n int a = read.nextInt();\n int b = read.nextInt();\n boolean flag = false;\n\n while (a != 0 && b != 0 && flag == false)\n first:{\n if (a >= b * 2) {\n a = a % (b * 2);\n break first;\n }\n if (b >= a * 2) {\n b = b % (a * 2);\n break first;\n } else {\n flag = true;\n }\n }\n System.out.println(a + \" \" + b);\n }\n catch (InputMismatchException o) {\n long a = read.nextLong();\n long b = read.nextLong();\n\n boolean flag = false;\n while (a != 0 && b != 0 && flag == false)\n first:{\n if (a >= b * 2) {\n a = a % (b * 2);\n break first;\n }\n if (b >= a*a * 2) {\n b = b % (a * 2);\n break first;\n } else {\n flag = true;\n }\n }\n\n System.out.println(a + \" \" + b); }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e38279c968ff4bd9f82be703fb2f3555", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\t//System.out.println(\"Hello World\");\n\t\tlong a,b;\n\t\tScanner in = new Scanner(System.in);\n\t\ta = in.nextLong();\n\t\tb = in.nextLong();\n\t\tstep1(a,b);\n\t}\n\tstatic void step1(int a,int b)\n\t{\n\t\t//System.out.println(a + \" \" + b);\n\t\tif(a == 0 || b == 0){\n\t\t\tSystem.out.println(a + \"\\t\" + b);\n\t\t\treturn;\n\t\t}else{\n\t\t\tstep2(a,b);\n\t\t}\n\t}\n\tstatic void step2(int a , int b){\n\t\t//System.out.println(a + \" \" + b);\n\t\tif( a >= 2*b ){\n\t\t\tlong m = a / (2 * b);\n a -= (2 * b)*m;\n\t\t\tstep1(a,b);\n\t\t}else{\n\t\t\tstep3(a,b);\n\t\t}\n\t}\n\tstatic void step3(int a, int b){\n\t\t//System.out.println(a + \" \" + b);\n\t\tif( b >= 2*a ){\n\t\t\tlong m = b / (2 * a);\n b -= (2 * a)*m;\n\t\t\tstep1(a,b);\n\t\t}else{\n\t\t\tSystem.out.println(a + \"\\t\" + b);\n\t\t\treturn;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ef2cb640beb8d9791c0650ac72fc9431", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Test{\n public static void main(String arg []){\n long a,b;\n Scanner sc = new Scanner(System.in);\n a = sc.nextInt();\n b = sc.nextInt();\n while(a!=0 && b!==0){\n if(a>=2*b){\n a-=2*b;\n } else if( b>= 2*a) {\n b -=2*a;\n } else {\n break;\n }\n }\n System.out.println(a+\" \"+b)\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d710cffc21548258cf800e4d87296b05", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class JavaApplication18 {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n long long a=sc.nextInt();\n long long b=sc.nextInt();\n while(a!=0 && b!=0){\n if(a>b){\n if(a-2*b < 0){\n break;\n }\n else{\n a=a-2*b;\n }\n }\n else if(b>a){\n if(b-2*a < 0){\n break;\n }\n else{\n b=b-2*a;\n }\n }\n }\n System.out.println(a+\" \"+b);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1e3b5af6b79221e6762f19d1d5b86373", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n public static void main(String[] args){\n Scanner sc= new Scanner(System.out);\n int n = sc.nextInt();\n int rr = (int)Math.sqrt(n);\n int num = Math.(rr+Math.ceil(n/rr));\n System.out.println(num);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cd4da54874667ea64775abed977026be", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class LazySecurityGuard{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint squareRoot = Math.sqrt(sc.nextInt());\n\t\tSystem.out.println(2*((int)Math.ceil(2*squareRoot)));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cee9501bb926dbcf7ead61178dd52c20", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.util.Scanner;\nimport javax.script.ScriptEngine;\nimport javax.script.ScriptEngineManager;\nimport javax.script.ScriptException;\n\npublic class Main {\n\tpublic static BigDecimal sqrt(BigDecimal a, BigDecimal _2, int precision) {\n\t\t// TODO Auto-generated method stub\n\t\tMathContext mc = new MathContext(precision, RoundingMode.HALF_UP); // \u67d0\u4e2a\u64cd\u4f5c\u4f7f\u7528\u7684\u6570\u5b57\u4e2a\u6570\uff1b\u7ed3\u679c\u820d\u5165\u5230\u6b64\u7cbe\u5ea6\n\t\tif (a.compareTo(BigDecimal.ZERO) == 0)\n\t\t\treturn BigDecimal.ZERO;\n\n\t\tif (a.compareTo(BigDecimal.ONE) == 0)\n\t\t\treturn BigDecimal.ONE;\n\n\t\tBigDecimal x = a;\n\t\tint cnt = 0;\n\t\twhile (cnt < 100) {\n\t\t\tx = (x.add(a.divide(x, mc))).divide(_2, mc);\n\t\t\tcnt++;\n\t\t}\n\t\treturn x;\n\n\t}\n\n\t// public static ScriptEngine ENGINE = new\n\t// ScriptEngineManager().getEngineByName(\"javascript\");\n\tpublic static ScriptEngine ENGINE = new ScriptEngineManager().getEngineByName(\"nashorn\");\n\n\tpublic static Scanner cin = new Scanner(new BufferedInputStream(System.in));\n\t// public static PrintStream cout = new PrintStream(new\n\t// BufferedOutputStream(System.out), false);\n\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(sqrt(new BigDecimal(\"1\"), new BigDecimal(\"2\"), 100));\n\n\t\t StringBuilder s = new StringBuilder();\n\t\t s.append(\"var n = Java.type('Main').cin.nextInt();\");\n\t\t s.append(\"var mina = (1 << 30);\");\n\t\t s.append(\"for (int i = 1; i <= n; i++) {\");\n\t\t s.append(\"for(var i=1;i<=n;i++){\");\n\t\t s.append(\"\tvar j = n / i;\");\n\t\t s.append(\"\tif (n % i) {\");\n\t\t s.append(\"\t\tj++;\");\n\t\t s.append(\" }\");\n\t\t s.append(\"\tmina = min(mina, (i + j) * 2);\");\n\t\t s.append(\"}\");\n\t\t s.append(\"print(mina);\");\n\t\t\n\t\t // s.append(\"Java.type(\\\"Main\\\").cout.println(ansa);\");\n\t\t try {\n\t\t ENGINE.eval(s.toString());\n\t\t } catch (ScriptException e) {\n\t\t e.printStackTrace();\n\t\t }\n\t\t cin.close();\n\t\t // cout.close();\n\t\t\t\n\t\t\t\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05dbcc504046108e87c4b8bbcb57533b", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class Basic {\n static final int four = 4;\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int input = scan.nextInt();\n double value = Math.sqrt(input);\n System.out.println(\"value : \"+value);\n if(value % 1 == 0){\n value = value * four;\n }else{\n value = (int) value;\n int valueTemp = (int) value * (int) value;\n if((input - valueTemp) <= value){\n value = (int) value * four + 2;\n }else{\n value = (int) value * four + 4;\n }\n }\n System.out.println(\"value : \"+value);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "80170b9a52f6cb2ff37fdd201e5d23df", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\n\npublic class Main{\n\tpublic static void main(String[] args) {\n\t\tnew Main().solve();\n\t}\n\tpublic void solve(){\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tchar[]s = in.next().toCharArray();\n\t\tout.println(getCode(s));\n\t\tout.close();\n\t}\n\tString getCode(char[]cs){\n\t\tString ans = \"-1\";\n\t\tboolean[]alpha = new boolean[26];\n\t\tint i,size = 0,beg = 0; char c;\n\t\tboolean end = false;\n\t\tif(cs.length > 25){\n\t\t\tfor(i = 0; i < cs.length && !end; i++){\n\t\t\t\tend = true; size = 0;\n\t\t\t\talpha = new boolean[26];\n\t\t\t\tfor(j = i; j < cs.length && size < 26 && !end; j++){\n\t\t\t\t\tc = cs[j];\n\t\t\t\t\tif(c == '?') size++;\n\t\t\t\t\telse if(alpha[c-'A']) end = false;\n\t\t\t\t\telse {alpha[c-'A'] = true; size++;}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(end){\n\t\t\t\tans = getCode(cs, alpha, beg);\n\t\t\t}\n\t\t}\t\n\t\treturn ans;\n\t}\n\tString getCode(char[]cs, boolean[] alpha, int beg){\n\t\tString ans = \"\"; int i, size = 1,j;\n\t\tfor(i = beg; size <= 26; i++, size++){\n\t\t\tif(cs[i] == '?'){\n\t\t\t\tj = 25;\n\t\t\t\twhile(alpha[j] && j > -1) j--;\n\t\t\t\tcs[i] = (char)(j+'A');\n\t\t\t\t//System.out.println(j+\"###\");\n\t\t\t\talpha[j] = true;\n\t\t\t}\n\t\t}\n\t\tfor(i = 0; i < cs.length; i++){\n\t\t\tif(cs[i] == '?') ans += \"A\";\n\t\t\telse ans += cs[i]; \n\t\t}\n\t\treturn ans;\n\t}\n\n\tclass Scanner{\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\t\tpublic Scanner(InputStream stream){\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\t\tpublic String next(){\n\t\t\twhile(tokenizer == null || !tokenizer.hasMoreTokens()){\n\t\t\t\ttry{\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t}catch(IOException e){\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\tpublic int nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e3fa1c487b2dd34ca6385b4bb8a86c3", "src_uid": "a249431a4b0b1ade652997fe0b82edf3", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Complete_the_Word{\n public static void main(String []args){\n Scanner sc=new Scanner(System.in);\n char ar[]=sc.next().toCharArrays();\n int alpha[]=new int[26];\n int ques=0,sum=0,counter=0;\n for(int i=0;i<=ar.length-26;i++){\n ques=0;sum=0;\n Arrays.fill(alpha,0);\n for(int j=i;j hm=new HashMap<>(); \n static ArrayList> arr,arr2;\n static int size;\n //static int[] vis;\n public static void main(String[] args) throws IOException {\n boolean online =false;\n String fileName = \"C-large\";\n PrintWriter out;\n if (online) {\n s.init(new FileInputStream(new File(fileName + \".in\")));\n out= new PrintWriter(new FileWriter(fileName + \"out.txt\"));\n }\n else {\n s.init(System.in); \n \n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n }\n int a[]=new int[26];\n String b=s.ns();\n int add=0;\n int[] last=new int[26];\n Arrays.fill(last,-1);\n //ArrayList arr=new ArrayList<>();\n int start=0;\n String ans=\"\";\n for(int i=0;i0){\n if(y%2==1)\n ans=(ans*x);\n x=(x*x);\n y/=2;\n }\n return ans;\n \n }\n \n static class name implements Comparable {\n String a;\n int num;\n public name(String x,int y){\n a=x;\n num=y;\n }\n public int compareTo(name o){\n if (num!=o.num){\n return o.num-num;\n }\n else\n return a.compareTo(o.a);\n }\n }\n public static class s {\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 ns() 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 ni() throws IOException {\n return Integer.parseInt( ns() );\n }\n \n static double nd() throws IOException {\n return Double.parseDouble( ns() );\n }\n static long nl() throws IOException {\n return Long.parseLong( ns() );\n }\n \n }\n } ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a23f2bdc62b57d897c7fb058b408ad1e", "src_uid": "a249431a4b0b1ade652997fe0b82edf3", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Complete_the_Word{\n public staic void main(String []args){\n Scanner sc=new Scanner(System.in);\n char ar[]=sc.next().toCharArrays();\n int alpha[]=new int[26];\n int ques=0,sum=0,counter=0;\n for(int i=0;i<=ar.length-26;i++){\n ques=0;sum=0;\n Arrays.fill(alpha,0);\n for(int j=i;j num2) {\n\t\tSystem.out.println(num1 - (num1-num2));\n\t\tnum1= num2 + (num1-num2);\n\t\t}\n\t\telse {\n\t\tSystem.out.println(num1);\n\t\tnum1 = num2;\n\t\t}\n\t}\n\tSystem.out.println(num2);\n\t\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2a64224f98b3652a4bda8100ed44e834", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Main{\n public static void Main (String [] args){\n Scanner key = new Scanner(System.in);\n int n = key.nextInt();\n int [] blocks = new int [n];\n for(int i=0; i0; i--){\n for(int j=0;jb){\n\t\t\t\ta = a % b;\n\t\t\t}else{\n\t\t\t\tb = b % a;\n\t\t\t}\n }\n\t\treturn a+b;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "367782601545f631a6ebc9093ed983b8", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main {\n public static long gcd(long p, long q) {\n if (q == 0) return p;\n return gcd(q, p % q);\n }\n private static long lcm(long a, long b)\n {\n return a * (b / gcd(a, b));\n }\n public static void main(String[] args) {\n\n\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n long n = in.nextInt();\n long k = in.nextInt();\n if (k==0) {\n out.println(n);\n out.flush();\n return;\n }\n long rememberk = k;\n k = (long)Math.pow(10,k);\n //long lcm1 = lcm(n,k);\n long lcm2 = lcm(k,lcm1);\n out.println(lcm2);\n\n out.flush();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c03824c54923ef4ff0ba7006abd6e279", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "//package TIM;\n\n\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n static Scanner input = new Scanner(System.in);\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static PrintWriter pw = new PrintWriter(System.out);\n\n\n public static void main(String[] args) throws IOException {\n long n = input.nextLong();\n long k = input.nextLong();\n long ans = Math.ceil(Math.pow(10,(double)k));\n System.out.println(ans*a/gcd(ans,a));\n }\n public static long gcd(long a, long b){\n return b==0?a:gcd(b,a%b);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "18f83cb6be0a3a9d75c9d37bb09bec5f", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "//package TIM;\n\n\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n static Scanner input = new Scanner(System.in);\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static PrintWriter pw = new PrintWriter(System.out);\n\n\n public static void main(String[] args) throws IOException {\n long n = input.nextLong();\n long k = input.nextLong();\n long ans = Math.ceil(Math.pow(10,k));\n System.out.println(ans*a/gcd(ans,a));\n }\n public static long gcd(long a, long b){\n return b==0?a:gcd(b,a%b);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7497917db06b6c8ec6bc31bd4cb32f5a", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class FiveAtomTree {\n\tstatic Scanner in = new Scanner(System.in);\n\tpublic static void main(String[] args) {\n\t\tint n = in.nextInt();\n\t\tint p = in.nextInt()/2;\n\t\tboolean[] k = new boolean[n];\n\t\tfor (int i = 0; i < n; i++) k[n-1-k] = in.nextLine().equals(\"halfplus\");\n\t\tlong a = 0;\n\t\tlong z = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta *= 2;\n\t\t\tif (k[i]) a++;\n\t\t\tz += a;\n\t\t}\n\t\tSystem.out.println(z*p);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "20574ce81617c9ddc130e1a9b79f4b35", "src_uid": "6330891dd05bb70241e2a052f5bf5a58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport javax.jnlp.IntegrationService;\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.Scanner;\n\npublic class Problem_0632A {\n\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n String[] l = input.nextLine().split(\" \");\n int n = Integer.parseInt(l[0]);\n long p = Long.parseLong(l[1]);\n\n boolean[] buy = new boolean[n];\n\n\n for (int i = 0; i < n; i++) {\n buy[i] = input.nextLine().contains(\"plus\");\n }\n\n long k = 1; long m2 = 1;\n for (int i = n - 2; i >=0; i--) {\n k *= 2;\n if (buy[i]) {\n k++;\n }\n m2+=k;\n }\n\n System.out.println( p * m2 / 2);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f0c507cd2dc6efceebe8c0e88431d8c0", "src_uid": "6330891dd05bb70241e2a052f5bf5a58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class FiveAtomTree {\n\tScanner in = new Scanner(System.in);\n\tpublic static void main(String[] args) {\n\t\tint n = in.nextInt();\n\t\tint p = in.nextInt()/2;\n\t\tboolean[] k = new boolean[n];\n\t\tfor (int i = 0; i < n; i++) k[n-1-k] = in.nextLine().equals(\"halfplus\");\n\t\tlong a = 0;\n\t\tlong z = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta *= 2;\n\t\t\tif (k[i]) a++;\n\t\t\tz += a;\n\t\t}\n\t\tSystem.out.println(z*p);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3d03f23dce48e14196d714aee4d7fef4", "src_uid": "6330891dd05bb70241e2a052f5bf5a58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\n public class Tester {\n\tstatic long sum=0,sum1=Long.MAX_VALUE;\n\t//DecimalFormat df = new DecimalFormat(\"#.#####\");\n\tpublic static final int MOD = (int) (1e9 + 7);\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\tlong n=in.nextLong(),p=in.nextLong(),i=(long) Math.pow(2,n-1);\n\t\tlong j,k,l,sum=0;\n\t\tString s[]=new String[(int)n];\n\t\tfor(j=0;j0)\n\t\t\t\t{\n\t\t\t\t\tif(l%2==0)\n\t\t\t\t\t{\n\t\t\t\t\t\tsum+=(l/2)*p;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tsum+=(l/2)*p+(0.5*p);\n\t\t\t\t\t}\n\t\t\t\t\tl/=2;\n\t\t\t\t}\n\t\t\t\tout.println(sum);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcount=0;\n\t\t}\n\t\tout.close();\n\t}\n\tprivate static int[] nextIntArray(InputReader in,int n)\t\n\t{\n\t\tint[] a=new int[n];\n\t\tfor(int i=0;i0)\n\t {\n\t\t mul=(mul%1000000007)*(i%1000000007)%1000000007;\n\t\t i--;\n\t }\n\t return mul;\n }\n static long output(ArrayList h[],int j,boolean[] v)\n {\n\t int k;\n\t v[j]=true;\n\t sum++;\n\t for(k=0;k h[],long ban[])\n {\n\t \tv[j]=true;\n\t \t int k;\n\t \tlong sum=0;\n\t sum=sum+ban[j];\n\t \t//System.out.println(h[j].size());\n\t \tfor(k=0;k stack = new ArrayDeque();\n \t\tprivate int least,count,v;\n \t\t\n\t\tSet[] cities;\n \tprivate int[] risk;\n \t\n \tGraph(int n,String[] risk){\n \t\t\n \t\tcities = new HashSet[n];\n \t\tthis.risk = new int[n];\n \t\tfor(int i =0;i();\n \t\t}\n \t\tfor(int i =0;i\n\t{\n\t\tprivate long first;\n\t\tprivate long index;\n\t\t//private long second;;\n\n\t\tpublic Pair(long i, long j) \n\t\t{ \n\t\t\tthis.first = i;\n\t\t\tthis.index = j;\n\t\t}\n\t\tpublic long getFirst() { return first; }\n\t\t//public long getSecond() { return second; }\n\t\tpublic long getIndex() { return index ;}\n\t\tpublic void setFirst(long k) { this.first=k ; }\n\t\tpublic void setIndex(long k) { this.index=k ;}\n\t\t//public void setSecond(long k) { this.second=k ;}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) \n\t\t{\n\t\t\treturn Long.compare(this.first, o.first);\n\t\t}\n\t}\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream inputstream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(inputstream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String nextLine(){\n\t\t\tString fullLine=null;\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tfullLine=reader.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\n\t\t}\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9b7d808a4c1fa65ae940f31a47d82507", "src_uid": "6330891dd05bb70241e2a052f5bf5a58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Yoy\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n long x=sc.nextInt();\n int a=1;\n for(int y=(int)(Math.sqrt(x));y>0;y--)\n {\n if(x%y==0&&findGCD(x/y,y)==1)\n {a=y;break;}\n }\n System.out.print(x/a+\" \"+a);\n }\n public static int findGCD(int number1, int number2)\n {\n //base case\n if(number2 == 0){\n return number1;\n }\n return findGCD(number2, number1%number2);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0482838526b2018e974b06872e7cd523", "src_uid": "e504a04cefef3da093573f9df711bcea", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class LCM {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint n = in.nextInt();\n\t\tint min = Integer.MAX_VALUE;\n\t\tint minA = Integer.MAX_VALUE;\n\t\tint minB = Integer.MAX_VALUE;\n\n\t\tfor (int i = n; i > 0; i--) {\n\t\t\tint a = i;\n\t\t\tint b = 0;\n\t\t\tif (n % a == 0) {\n\t\t\t\tb = n/a;\n\t\t\t\tif (min > Math.max(a, b) && isLCM(a, b, n)) {\n\t\t\t\t\tmin = Math.max(a, b);\n\t\t\t\t\tminA = a;\n\t\t\t\t\tminB = b;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tb = 0;\n\t\t\t}\n\t\t}\n\t\tint x = Math.min(a, b);\n\t\tint y = Math.max(a, b);\n\n\t\tSystem.out.println(x + \" \" + y);\n\t}\n\n\tpublic static boolean isLCM(int a, int b, int lcm) {\n\t\tif (a % b == 0 && a == lcm)\n\t\t\treturn true;\n\t\tif (b % a == 0 && b == lcm)\n\t\t\treturn true;\n\t\tif (a * b == lcm)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "89661480e02754ce2e0a1283b1a1a146", "src_uid": "e504a04cefef3da093573f9df711bcea", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Yoy\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n long x=sc.nextInt();\n long a=1;\n for(long y=(int)(Math.sqrt(x));y>0;y--)\n {\n if(x%y==0&&findGCD(x/y,y)==1)\n {a=y;break;}\n }\n System.out.print(x/a+\" \"+a);\n }\n public static int findGCD(long number1, long number2)\n {\n //base case\n if(number2 == 0){\n return number1;\n }\n return findGCD(number2, number1%number2);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02d1c67b54995802ad684250c5418f1d", "src_uid": "e504a04cefef3da093573f9df711bcea", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "public class Main {\n static long gcd(long a, long b) {\n return b == 1 ? a : gcd(b, a % b);\n }\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long ans = Long.MAX_VALUE;\n long n = scanner.nextLong();\n for (long a = 1; a * a <= n; a++) {\n if (n % a != 0) continue;\n long b = n / a;\n if (gcd(a, b) == 1) ans = Math.min(ans, Math.max(a, b));\n\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "958cb29986b5f621ce231c0f7504d7c6", "src_uid": "e504a04cefef3da093573f9df711bcea", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "public class P327A {\n public static void main(String [] args) {\n MyScanner reader = new MyScanner();\n int n = reader.nextInt();\n String line = reader.nextLine();\n System.out.print(solution(n, reader.toIntArray(line.split(\" \"))));\n }\n\n public static int solution(int n, int[] a) {\n int sSoFar = 0;\n int maxSum = 0;\n\n int start = -1;\n int maxStart = -1;\n int maxEnd = -1;\n\n for(int i=0;i maxSum) {\n maxEnd = i;\n maxStart = start;\n maxSum = sSoFar;\n }\n }\n }\n\n if(maxSum == 0){\n return a.length;\n }\n\n int count =0;\n for(int i=0;i b) {\n return a;\n } else {\n return b;\n }\n }\n\n public static int translate(int num) {\n if(num == 1) {\n return -1;\n } else {\n return 1;\n }\n }\n}\n\n\nclass MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public ArrayList toInt(String[] line) {\n ArrayList ret = new ArrayList(line.length);\n for(int i=0;i maior){\n \n maior = soma;\n }\n }\n \n saida.append(maior+cont).append(\"\\n\");\n \n\n }\n\n static void lerEntrada() throws Exception {\n entrada = new byte[System.in.available()];\n System.in.read(entrada);\n\n }\n\n static void escreverSaida() throws Exception {\n System.out.write(saida.toString().getBytes());\n System.out.flush();\n }\n\n static boolean hashNext() {\n return ponteiro < entrada.length;\n }\n\n static boolean skipIgnored() {\n while (true) {\n if (!hashNext()) {\n return false;\n }\n if (entrada[ponteiro] <= ' ') {\n ponteiro++;\n } else {\n break;\n }\n }\n return true;\n }\n\n static void voltarPonteiro() {\n if (hashNext()) {\n ponteiro--;\n }\n }\n\n static int nextInt() {\n int n = 0;\n if (skipIgnored()) {\n char c;\n while (hashNext()) {\n c = (char) entrada[ponteiro++];\n if (c < '0' || c > '9') {\n voltarPonteiro();\n break;\n }\n n = n * 10 + (c - 48);\n }\n }\n return n;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f631c696bc2b14966c8a96c4d3842a8b", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n//import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author Roger Flores Vargas\n */\npublic class Unlucky_Ticket {\n public static void main(String[] args) {\n Scanner entrada = new Scanner(System.in);\n int n = entrada.nextInt();\n entrada.nextLine();\n String num = entrada.nextLine();\n char[] left, right;\n left = copiar(0, n, num);\n right = copiar(n, 2 * n, num);\n Arrays.sort(left);\n Arrays.sort(right);\n boolean unlucky = comparar(left, right);\n if(unlucky)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n \n private static boolean comparar(char[] left, char[] right){\n boolean res = true;\n if(left[0] < right[0]){\n for (int i = 0; i < right.length; i++) {\n res = left[i] < right[i];\n }\n }\n else{\n for (int i = 0; i < right.length; i++) {\n res = left[i] > right[i];\n }\n }\n return res;\n }\n \n private static char[] copiar(int i, int j, String cad){\n char[] res = new char[j-i];\n for (int k = 0; k < res.length; k++) {\n res[k] = cad.charAt(i+k);\n }\n return res;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "efabc61d8c334aa5598a699f2a5fcbf5", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: mihai\n * Date: 2/3/12\n * Time: 10:45 PM\n */\npublic class problemB {\n private static double[] list = new double[101];\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int[] digits = new int[202];\n int N = sc.nextInt();\n String s = sc.nextLine();\n s = sc.nextLine();\n for (int i = 0; i < 2 * N; i++) {\n char c = s.charAt(i);\n digits[i] = c - '0';\n }\n\n Arrays.sort(digits, 0, N);\n Arrays.sort(digits, N, 2*N);\n\n boolean leftBigger = true;\n boolean rightBigger = true;\n \n for (int i = 0; i < N; i++) {\n if (digits[i] <= digits[N+i]) leftBigger = false;\n if (digits[i] => digits[N+i]) rightBigger = false;\n }\n \n if (leftBigger || rightBigger) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "472aba630e6f8ed38093d85f9f06d1e4", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class unluckyticket1\n{\n public static void main(String ar[])throws IOException\n {\n unluckyticket ob=new unluckyticket();\n BufferedReader x=new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(x.readLine());\n String s=x.readLine();\n String s1=s.substring(0,n),s2=s.substring(n);\n s1=ob.sort(s1,n);\n s2=ob.sort(s2,n);\n int greater=0,lesser=0,equal=0,f=0;\n char c1=' ',c2=' ';\n StringBuilder sb = new StringBuilder(s2);\n for(int i=0;ic2)\n {\n sb.setCharAt(j, 'a');\n greater++;\n break;\n }\n else\n {\n sb.setCharAt(j, 'a');\n lesser++;\n break;\n }\n }\n else if(c1==c2 && c2!='a')\n equal++;\n }\n if((greater>0 && lesser>0))\n {\n f=1;\n break;\n }\n }\n if(f!=1)\n {\n if(greater!=n && equal>0)\n f=1;\n if(lesser!=n && equal>0)\n f=1;\n }\n if(f==0)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n //sorting the s1 and s2\n String sort(String s,int n)\n {\n char c=' ';\n String m=\"\";\n StringBuilder sb = new StringBuilder(s);\n for(int i=0;isb.charAt(j+1))\n {\n c=sb.charAt(j);\n sb.setCharAt(j, sb.charAt(j+1));\n sb.setCharAt(j+1,c );\n }\n }\n }\n m=sb.toString();\n return m;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9d9ba6cf9eb65c00c3d448bc154a6a53", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class UnluckyTicket {\n public static void main(String[] args){\n Scanner input=new Scanner(System.in);\n int n= input.nextInt();\n n= n*2;\n int a[]=new int [n];\n for (int i=0; i<=n-1;i++){\n a[i]=input.nextInt();\n }\n for (int j=0;j<=(n-1)/2;j++){\n if(a[j]a[n-1-k]){\n if(k==(n-1)/2){\n System.out.print(\"NO\");\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "73f33ee5842b295355b061b36a8c5219", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "//package HR;\n\nimport java.util.*;\nimport java.math.*;\n//import java.io.*;\n\npublic class Test_inhert {\n\n static class pair {\n\n public int x;\n public int y;\n }\n\n public static void main(String[] args) {\n FastReader in = new FastReader(System.in);\n int a = in.nextInt();\n int x = in.nextInt();\n int f = in.nextInt();\n int k = in.nextInt();\n int i = 1;\n int b = x;\n int ans = 0;\n int odd = f;\n int even = a - f;\n boolean flag = true;\n while (i <= k) {\n if ((i & 1) == 1) {\n b -= odd;\n if (b < 0) {\n flag = false;\n break;\n }\n if (b < even) {\n ++ans;\n b = x;\n b -= even;\n } else if (i + 1 <= k && b < even * 2) {\n ++ans;\n b = x;\n b -= even;\n } else if (b >= even * 2 || (i == k && b >= even)) {\n b -= even;\n } else {\n flag = false;\n break;\n }\n } else {\n b -= even;\n if (b < 0) {\n flag = false;\n break;\n }\n if (b < odd) {\n ++ans;\n b = x;\n b -= odd;\n } else if (i + 1 <= k && b < odd * 2) {\n ++ans;\n b = x;\n b -= odd;\n } else if (b >= odd * 2 || (i == k && b >= odd)) {\n b -= odd;\n } else {\n flag = false;\n break;\n }\n }\n ++i;\n }\n System.out.println(flag == true ? ans : -1);\n }\n\n private static class FastReader {\n\n private InputStream stream;\n\n private byte[] buf = new byte[1024];\n\n private int curChar;\n\n private int numChars;\n\n private FastReader.SpaceCharFilter filter;\n\n FastReader(InputStream stream) {\n this.stream = stream;\n }\n\n 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 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 long ret = 0;\n int c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n 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\n boolean isSpaceChar(int ch);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7697f1f24a5f93171910cb0318a36dda", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "public class bus{\npublic static void main (String [] args){\nlong i;\nlong a;\nlong b;\nlong f;\nlong k;\nlong cb = b;\n\n\tif (k == 1)\n\t{\n\t\tif (b >= a)\n\t\t{\n\t\t\tSystem.out.print(0);\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\t\telse if (b >= f != 0 && b >= a - f)\n\t\t{\n\t\t\tSystem.out.print(1);\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(-1);\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tif (k == 2)\n\t{\n\t\tif (b >= 2 * a)\n\t\t{\n\t\t\tSystem.out.print(0);\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\t\telse if (b >= a + a - f || (b >= f != 0 && b >= (a + a - f)))\n\t\t{\n\t\t\tSystem.out.print(1);\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\t\telse if (b >= f != 0 && b >= 2 * (a - f))\n\t\t{\n\t\t\tSystem.out.print(2);\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(- 1);\n\t\t\tSystem.out.print(\"\\n\");\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tfinal long x1 = 2 * (a - f);\n\tfinal long x2 = 2 * f;\n\n\tif (b < f || b < x1 || b < x2)\n\t{\n\t\tSystem.out.print(-1);\n\t\tSystem.out.print(\"\\n\");\n\n\t\treturn 0;\n\t}\n\n\tcb -= f;\n\tlong stops = 0;\n\tfor (i = 0; i != k - 1; ++i)\n\t{\n\t\tif (i % 2 == 0)\n\t\t{\n\t\t\tif (cb < x1)\n\t\t\t{\n\t\t\t\tcb = b;\n\t\t\t\t++stops;\n\t\t\t}\n\n\t\t\tcb -= x1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (cb < x2)\n\t\t\t{\n\t\t\t\tcb = b;\n\t\t\t\t++stops;\n\t\t\t}\n\n\t\t\tcb -= x2;\n\t\t}\n\t}\n\n\tif (i % 2 == 0)\n\t{\n\t\tif (cb < a - f)\n\t\t{\n\t\t\t++stops;\n\t\t}\n\t}\n\telse\n\t{\n\t\tif (cb < f)\n\t\t{\n\t\t\t++stops;\n\t\t}\n\t}\n\n\tSystem.out.print(stops);\n\tSystem.out.print(\"\\n\");\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "53f19a8a06cefe3b64022955b1171479", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n long a = in.nextLong();\n long b = in.nextLong();\n long f = in.nextLong();\n long k = in.nextLong();\n long c = 0;\n long tb = b;\n if ((2 * (a - f) < b) && (2 * f < b)) {\n for(int i = 0; i < k;i++){\n if(i!=k-1) {\n if (i % 2 == 0) {\n if (b >= 2 * a - f) {\n b = b - a;\n } else {\n c++;\n b = tb - (a - f);\n }\n } else {\n if (b >= a + f) {\n b = b - a;\n } else {\n c++;\n b = tb - f;\n }\n }\n }else{\n if (i % 2 == 0) {\n if (b >= a) {\n b = b - a;\n } else {\n c++;\n b = tb - (a - f);\n }\n } else {\n if (b >= a) {\n b = b - a;\n } else {\n c++;\n b = tb - f;\n }\n }\n }\n }\n } else {\n if(a*k/b=>1){\n System.out.println(0);\n return;\n }\n System.out.println(-1);\n return;\n }\n System.out.println(c);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "339eecc3bb25867b893bbca5f9e629d2", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "\ufeff\n\nimport java.io.BufferedInputStream;\nimport java.util.Scanner;\n\npublic class C864C {\npublic static void main(String[] args) {\n\tScanner sc = new Scanner (new BufferedInputStream(System.in));\n\tint a = sc.nextInt(),b=sc.nextInt(),f=sc.nextInt(),k=sc.nextInt();\n\tsc.close();\n\t//\u6807\u5fd7\u4f4d\u663e\u793a\u662f\u53bb\u8fd8\u662f\u56de;\n\tint flag=1;\n\t//\u6cb9\u7bb1\u5230\u52a0\u6cb9\u7ad9\u65f6\n\tint t=b-f;\n\t//\u52a0\u6cb9\u6b21\u6570\n\tint count=0;\n\twhile(k>0) {\n\t\tif(flag==1) {\n\t\t\t//\u6cb9\u7bb1\u4e0d\u591f\u8dd1\u5b8c\u4e0b\u9762\u7684\u8def\n\t\t\tif(t<(a-f)*2) {\n\t\t\t\tt=b;\n\t\t\t\t//\u6ee1\u6cb9\u72b6\u6001\u4e0b\u662f\u5426\u80fd\u591f\u8dd1\u5b8c\n\t\t\tif(t<(a-f)*2) {\n\t\t\t\t//\u4e0d\u80fd\u5c31\u8f93\u51fa-1\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn ;\n\t\t\t}else {\n\t\t\t\t//\u80fd\u8dd1\u5b8c\n\t\t\t\tcount++;\n\t\t\t\tt=t-(a-f)*2;\n\t\t\t}\n\t\t\t}else {\n\t\t\t\tt=t-(a-f)*2;\n\t\t\t}\n\t\t\tflag=0;\n\t\t\tk--;\n\t\t}else {\n\t\t\tif(k!=1) {\n\t\t\t//\u6cb9\u7bb1\u4e0d\u591f\u8dd1\u5b8c\u4e0b\u9762\u7684\u8def\n\t\t\tif(t<2*f) {\n\t\t\t\tt=b;\n\t\t\t\t//\u6ee1\u6cb9\u72b6\u6001\u4e0b\u662f\u5426\u80fd\u591f\u8dd1\u5b8c\n\t\t\t\tif(t<2*f) {\n\t\t\t\t\t//\u4e0d\u80fd\u5c31\u8f93\u51fa-1\n\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t\treturn ;\n\t\t\t\t}else {\n\t\t\t\t\t//\u80fd\u8dd1\u5b8c\n\t\t\t\t\tcount++;\n\t\t\t\t\tt=b-2*f;\n\t\t\t\t}\n\t\t\t}else {\n\t\t\t\tt=b-2*f;\n\t\t\t}\n\t\t}else {\n\t\t\tif(t hs=new HashSet<>();\n for(int i=0;i<=s.length();i++){\n for(int j='a';j<='z';j++){\n char c=char(j);\n hs.add(s.substring(0,i)+c+s.substring(i));\n }\n }\n System.out.println(hs.size());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "720bac13d3b398f2d9e7ac60ca6e48e7", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*; \nimport java.util.*; \nimport java.lang.*; \n\npublic class b {\n public static void main(String[] args) {\n b solver = new b();\n }\n\n b() {\n InputReader in = new InputReader();\n in.init(System.in);\n\n String s = in.next();\n System.out.println(s.length * 25 + 26);\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input), \n 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 (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 public long nextLong() {\n return Long.parseLong(next());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7bf8c3d546e1b21102019479046fa1db", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String [] args) {\n String string = java.util.Scanner(System.in).next();\n System.out.println(string.length() * 26 + 26 - string.length());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "57641701b2c31fadcdfb2b26bee18b1f", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Date;\npublic class B {\npublic static void main(String[] args) {\nScanner reader = new Scanner(System.in);\nint n = reader.nextInt();\nArrayList a = new ArrayList();\nfor (int i = 0; i < n; i++) {\na.add(reader.nextInt());\n}\n\nArrayList b = new ArrayList(a);\nArrayList x = new ArrayList();\nArrayList z = new ArrayList();\n\nfor (int i = 1; i < n-1; i++) {\nb.remove(i);\nfor (int j = 0; j < b.size()-1 ; j++) {\nx.add(b.get(j+1) - b.get(j));\n}\nCollections.sort(x);\nz.add(x.get(x.size() - 1));\nx = new ArrayList();\nb = new ArrayList(a);\n}\nCollections.sort(z);\n\nSystem.out.println(z.get(0));\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f251f8a17bdcc5866ac23351bf84e3b8", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.lang.Math;\n\npublic class Difficulty{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n int numHolds = scan.nextInt();\n \n long difficulty=0;\n long minimumGap=Integer.MAX_VALUE;\n \n int holdOne = scan.nextInt();\n int second = scan.nextInt();\n difficulty = (second-holdOne);\n int prev = holdOne;\n int current = second;\n for(int i=0;i a = new ArrayList();\nfor (int i = 0; i < n; i++) {\na.add(reader.nextInt());\n}\n\nArrayList b = new ArrayList(a);\nArrayList x = new ArrayList();\nArrayList z = new ArrayList();\n\nfor (int i = 1; i < n-1; i++) {\nb.remove(i);\nfor (int j = 0; j < b.size()-1 ; j++) {\nx.add(b.get(j+1) - b.get(j));\n}\nCollections.sort(x);\nz.add(x.get(x.size() - 1));\nx = new ArrayList();\nb = new ArrayList(a);\n}\nCollections.sort(z);\n\nSystem.out.println(z.get(0));\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fbc822daf4ef427f4be39aa794c47042", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class HelloWorld {\n public static void main(String[] args) {\n int i,count=0;\n String str;\n \tScanner sc = new Scanner(System.in);\n \tSystem.out.println(\"enter a string\");\n \tstr = sc.next();\t\n\tfor(i=0;i= 1){\n\t\tSystem.out.println(\"YES\");\n\t}\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0c03f19bf013d2a221effba12798c9d5", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class HQ9{\n private static Scanner s = new Scanner(System.in);\n public static void main(String[] args){\n String p = s.nextLine();\n boolean flag = false;\n for(int i=0;i= 33 && p[i] <=126)\n {flag = true;\n break;}\n \n if(flag)\n System.out.print(\"YES\");\n else\n System.out.print(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1ec5a76f6f89055258ed39862f88e87e", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class a\n\n{\npublic static void main(String []aa)\n{\nint f=0;\nScanner sc=new Scanner(System.in);\nString str;\nstr=sc.next();\nint b=str.length();\nfor(int i=0;i0) ) \n\t\t System.out.print(\"NO\");\n\t\t else if(b>a&&c<0)\n\t\t \tSystem.out.print(\"NO\");\n\t\t else {\n\t\t if ((b-a%c==0) {\n\t\t \tSystem.out.print( \"YES\");\n\t\t } else {\n\t\t \tSystem.out.print( \"NO\");\n\t\t }\n\t\t }\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02972923c2b4f993f5dbcba87412ca49", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class B {\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint a = Integer.parseInt(st.nextToken());\n\t\tint b = Integer.parseInt(st.nextToken());\n\t\tint c = Integer.parseInt(st.nextToken());\n\t\tif((b-a)==c || (c!=0 && (b-a)%c==0)) {\n\t\t\tif((b>=a && c>=0) || (b ans=new ArrayList();\n public static void main(String[] ar) {\n int init[] = {1, 1};\n int c = 0;\n inp = getInt();\n //sol(init, c);\n new solver(init, c, inp, ans).start();\n try{\n Thread.sleep(900);\n }catch(Exception e){\n \n }\n int min=ans.get(0);\n for(int i=0;i inp) {\n return;\n } else if (max == inp) {\n //System.out.println(c);\n ans.add(c);\n return;\n } else if (max < inp) {\n c++;\n sol(new int[]{max + min, max}, c);\n sol(new int[]{max + min, min}, c);\n }\n\n\n\n }\n}\nclass solver extends Thread{\n int init[];\n int c;\n int inp;\n ArrayList ans;\n solver(int[] init,int c,int inp,ArrayList ans){\n this.init=init;\n this.c=c;\n this.inp=inp;\n this.ans=ans;\n }\n \n public void run(){\n \n int max = Math.max(init[0], init[1]);\n int min = Math.min(init[0], init[1]);\n if (max > inp) {\n return;\n } else if (max == inp) {\n //System.out.println(c);\n ans.add(c);\n return;\n } else if (max < inp) {\n c++;\n new solver(new int[]{max + min, max}, c,inp,ans).start();\n new solver(new int[]{max + min, min}, c,inp,ans).start();\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "032eaaf898fe22885940405439c83b2e", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class B {\n public static int getMin(int f,int s) {\n if(f==s) {\n if(f==1&&s==1) return 0;\n return 3000000;\n }\n int min=Math.min(f,s);\n int max=Math.max(f,s);\n if(min==1) return max-1;\n return ((max/min))+getMin(max%min,min);\n }\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n if(n==1){\n System.out.println(0); return;\n }\n int min=2*n;\n for(int i=1;i<=n/2;i++) {\n //System.out.println(getMin(i,n-i));\n min=Math.min(min,1+getMin(i,n-i));\n }\n System.out.println(min);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "35481911f5e9cc1b4bea281ad0cc7c8a", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import edu.princeton.cs.algs4.In;\n\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.net.Inet4Address;\nimport java.util.*;\n\nimport java.util.Iterator;\nimport java.util.NoSuchElementException;\n\npublic class Main {\n\n private static Scanner scanner;\n\n\n static void solution() {\n int a = scanner.nextInt();\n int b = scanner.nextInt();\n int c = scanner.nextInt();\n int n = scanner.nextInt();\n\n if (n - (a + b - c) < 1) System.out.println(-1);\n else System.out.println(n - (a + b - c));\n }\n\n public static void main(String args[]) {\n scanner = new Scanner(System.in);\n solution();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2181c397d9d2617e04d66b870b0ae401", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Sampl2\n{\n\n\tpublic static void main(String[] args)\n\t{\tScanner s = new Scanner(System.in);\n int a = s.nextInt();\n int b = s.nextInt();\n int c = s.nextInt();\n int n = s.nextInt();\n int y = a+b-c;\n if(y < n & y=> 0 & c<=a & c<=b){\n System.out.println(n-y);\n }else{\n System.out.println(\"-1\");\n }\n \n \n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a6b52fc82371345bbea37060b1cacc1f", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class tooth\n{\n\tpublic static void main(String[]args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\t\n\t\tlong a,b,c,n,i,s;\n\t\ta=sc.nextInt();\n\t\tb=sc.nextInt();\n\t\tc=sc.nextInt();\n\t\tn=sc.nextInt();\n\t\t\n\t\tx=a-c;\n\t\ty=b-c;\n\t\tx=x+y+c;\n\t\t\n\t\tz=n-x;\n\t\t\n\t\tif(z>=1)\n\t\t{\n\t\t\tSystem.out.println(z);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(\"-1\");\n\t\t}\n\t\t\n\t\t\n\t\t\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4085bfeaf2c6c7ccf56778fc86d1e568", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Sampl21\n{\n\n\tpublic static void main(String[] args)\n\t{\tScanner s = new Scanner(System.in);\n int a = s.nextInt();\n int b = s.nextInt();\n int c = s.nextInt();\n int n = s.nextInt();\n y = a+b-c;\n if(y < n){\n System.out.println(n-y);\n }else{\n System.out.println(\"-1\");\n }\n \n \n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea21776c61e0ab124a7d214661c0042a", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class robots {\n public static void main(String[] args) {\n int s=-1;s1=0;s2=0;x=0;\n Scanner scan=new Scanner(System.in);\n \n \n int n=scan.nextInt();\n int[] a=new int[n];\n int[] b=new int[n];\n for (int i = 0; i < n; i++) {\n a[i]=scan.nextInt();\n s1=s1+a[i];\n }\n for (int i = 0; i < n; i++) {\n b[i]=scan.nextInt();\n s2+=b[i];\n }\n //System.out.println(\"s1 and s2 \"+s1+\"\"+s2);\n for (int i = 0; i < n; i++) {\n if(a[i]==1&&b[i]==0)\n {\n x++;\n }}\n if(s2>s1)\n {\n s=s2-s1;\n s=s/x;\n s+=2;\n \n } System.out.println(s);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "281aa5db07c6aff8009ff92de656054c", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class robots {\n public static void main(String[] args) {\n int s=-1,s1,s2,x;\n Scanner scan=new Scanner(System.in);\n \n \n \n int n=scan.nextInt();\n int[] a=new int[n];\n int[] b=new int[n];\n for (int i = 0; i < n; i++) {\n a[i]=scan.nextInt();\n s1=s1+a[i];\n }\n for (int i = 0; i < n; i++) {\n b[i]=scan.nextInt();\n s2+=b[i];\n }\n //System.out.println(\"s1 and s2 \"+s1+\"\"+s2);\n for (int i = 0; i < n; i++) {\n if(a[i]==1&&b[i]==0)\n {\n x++;\n }}\n if(s2>s1)\n {\n s=s2-s1;\n s=s/x;\n s+=2;\n \n } System.out.println(s);\n \n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0a3d4ada87a0f5e64a260338e033ec87", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class Contest_for_Robots\n public static void main (String[] args){\n Scanner sc = new Scanner(System.in);\n int x = sc.nextInt();\n int y = sc.nextInt();\n System.out.println(y);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3afe40c6442525ad96d138a331c9ec6e", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.Scanenr;\npublic class Contest_For_Robots\n public static void main (String[] args){\n Scanner sc = new Scanner(System.in);\n int x = sc.nextInt();\n int ans = 0;\n int [] res = new int(x);\n for (int i = 0; i < x ; i++){\n res[i] = sc.nextInt();\n }\n for (int i = 0; i< x ; i++){\n if(res[i] == 0 && res[i + x] == 1)\n ans = ans + 1;\n \n }\n System.out.println(Math.floor((ans + 1)/2.0)));\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2c0e781fbe245709f863167712582854", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{ \n\n\t\n public static void main(String[] args) {\n \n Scanner in = new Scanner(System.in);\n \n int n,m,amin=10,bmin=10,temp,i;\n \n n=in.nextInt();\n m=in.nextInt();\n \n for(i=1;i<=n;i++){\n \t temp=in.nextInt();\n \t amin=Math.min(amin, temp);\n }\n \n for(i=1;i<=m;i++){\n \t temp=in.nextInt();\n \t bmin=Math.min(bmin, temp);\n }\n \n if(amin==bmin){\n \t System.out.println(amin);\n \t return;\n }\n if(aminarr2[0]) System.out.println(arr2[0]+\"\"+arr1[0]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8febbbbbaf32efa6f202b6f469de5b73", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class Main {\n\n public static boolean search (Integer[] arr, int key, int min, int max) {\n if (max < min) {\n return false;\n } else if (arr[(max - min)/2] == key) {\n return true;\n }\n else if (arr[(max - min)/2] > key) {\n return search(arr, key, min, (max - min)/2);\n }\n else {\n return search(arr, key, (max - min)/2, max);\n }\n }\n\n public static int findMin (Integer[] arr) {\n int min = arr[0];\n for (int i = 1; i < arr.length; i++) {\n if (arr[i] < min) {\n min = arr[i];\n }\n }\n return min;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int lenOne = in.nextInt();\n int lenTwo = in.nextInt();\n Integer[] arrOne = new Integer[lenOne];\n Integer[] arrTwo = new Integer[lenTwo];\n ArrayList common = new ArrayList();\n\n for (int i = 0; i < lenOne; i++) {\n arrOne[i] = in.nextInt();\n }\n for (int i = 0; i < lenTwo; i++) {\n arrTwo[i] = in.nextInt();\n }\n for (int i = 0; i < lenOne; i++) {\n if (search(arrTwo, arrOne[i], 0, arrTwo.length)) {\n common.add(arrOne[i]);\n }\n }\n if (!common.isEmpty()) {\n int retVal = findMin((Integer[]) common.toArray());\n System.out.println(retVal);\n } else {\n int digitOne = findMin(arrOne);\n int digitTwo = findMin(arrTwo);\n if (digitOne <= digitTwo) {\n System.out.println(digitOne*10 + digitTwo);\n } else {\n System.out.println(digitTwo*10 + digitOne);\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "58500dc3fac7bc58eb1f972949b85069", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class KK{\n\n public static Scanner scn = new Scanner(System.in);\n\n public static int findMin(int[] arr, int n){\n int min = arr[0];\n\n for (int i=0; i e)\n {\n int min1 , result1 ;\n min1 = min(b,c,d);\n result1 = min1 * f;\n b = b - min1;\n c = c - min1;\n d = d - min1;\n if( d > 0)\n {\n int min2 , result2;\n min2 = Math.min(a,d);\n result2 = min2 * e;\n System.out.println(result1+result2);\n }\n else{\n System.out.println(result1);\n }\n }\n \n if(e > f)\n {\n int min1, result1;\n min1 = Math.min(a,d);\n result1 = min1 * e;\n a = a - min1;\n d = d - min1;\n if( d > 0)\n {\n int min2 , result2;\n min2 = min(b,c,d);\n result2 = min2 * f;\n System.out.println(result1+result2);\n }\n else\n {\n System.out.println(result1);\n }\n }\n }\n public static int min(int a , int b ,int c)\n {\n int m = Math.min(a,b);\n return Math.min(m,c);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "44b226c4a1f865a3ca641f47f030bdf9", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "miport java.io.BufferedReader; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.Scanner; \nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\n import java.util.*;\n public class GraphAdjacencyList\n{ \n \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 int bin(String st)\n {\n int ans=0;\n int ind=0;\n for(int i=st.length()-1;i>=0;i--)\n {\n ans+=((int)st.charAt(i)-48)*(int)Math.pow(2, ind++);\n }\n return ans;\n \n }\n// static String binn(int a)\n// {\n// String s=\"\";\n// while(a!=0)\n// {\n// s=Integer.toString(a%2)+s;\n// a/=2;\n// }\n// return s;\n// }\n public static void main(String[] args) \n { \n FastReader s=new FastReader(); \n int t=s.nextInt();\n while(t-->0)\n {\n int a=s.nextInt(); \n int b=s.nextInt();\n int c=s.nextInt();\n int d=s.nextInt();\n int e=s.nextInt();\n int f=s.nextInt();\nint cost=0;\n if(e>f)\n {\n int val=0;\n if(a>d)\n val=d;\n else\n val=a;\n cost+=val*e;\n d-=val;\n val=(int)Math.min(b, Math.min(c, d));\n cost+=val*f;\n }\n else\n {\n int val=0;\n val=(int)Math.min(b, Math.min(c, d));\n \n cost+=val*f;\n d-=val;\n if(a>d)\n val=d;\n else\n val=a;\n cost+=val*e;\n \n \n }\n System.out.println \n (cost);\n\n }\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dae5c56ae919fc5812a10e777c4b06d1", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0} {"lang": "Java 8", "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\tlong a=sc.nextInt();\n\t\tlong b=sc.nextInt();\n\t\tlong c=sc.nextInt();\n\t\tlong d=sc.nextInt();\n\t\tlong e=sc.nextInt();\n\t\tlong f=sc.nextInt();\n\t\tlong x=Math.min(b,c);\n\t\tlong m=Math.min(a,d)*e+Math.min(x,(d-Math.min(a,d)))*f;\n\t\tlong n=Math.min(x,d)*f+Math.min(a,(d-Math.min(x,d)))*e;\n\t\tSystem.out.println(Math.max(ans,ans1));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9e16337062969f211b4c2f661595a535", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Suits_1271A {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint ties = input.nextInt();\n\t\tint scarves = input.nextInt();\n\t\tint vests = input.nextInt();\n\t\tint jackets = input.nextInt();\n\t\tint costF = input.nextInt();\n\t\tint costS = input.nextInt();\n\t\tint cost = 0, min = 0;\n\t\tif (costS > costF) {\n\t\t\tmin = Math.min(scarves, Math.min(vests, jackets));\n\t\t\tcost += min * costS;\n\t\t\tscarves -= min;\n\t\t\tvests -= min;\n\t\t\tjackets -= min;\n\t\t\tmin = Math.min(ties, jackets);\n\t\t\tcost += min * costF;\n\t\t} else {\n\t\t\tmin = Math.min(ties, jackets);\n\t\t\tcost += min * costF;\n\t\t\tties -= min;\n\t\t\tjackets -= min;\n\t\t\tmin = Math.min(scarves, Math.min(vests, jackets));\n\t\t\tcost += min * costS;\n\t\t\tscarves -= min;\n\t\t\tvests -= min;\n\t\t\tjackets -= min;\n\t\t}\n\t\tSystem.out.println(cost);\n\t\tinput.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a30f75b6ccbbafa47f60382f6d84ebaf", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class now{\n\tpublic static void main(String[]args){\n\t\tScanner in = new Scanner(System.in);\n\t\tBigInteger x = in.nextBigInteger();\n\t\tBigInteger y = in.nextBigInteger();\n\t\twhile (x != y){\n\t\t\tif (x > y)\n\t\t\t\tx = x - y;\n\t\t\telse\n\t\t\t\ty = y - x;\n\t\t}\n\t\tSystem.out.println(\"The GCD is \" + x);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc59df4e9f7bcd4f0c6b61202df03350", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Solution{\n public static void main(String[] args){\n Scanner scanner = new Scanner(System.in);\n String a= scanner.nextString();\n String b = scanner.nextString();\n if(a.equals(b)) System.out.println(a);\n System.out.prtinln(\"1\");\n return;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aee90cc9a5d8b700bb624a61c0d159de", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;\n\npublic class solver {\n\n\tpublic static String nod(BigInteger a, BigInteger b){\n\t\t\n\n\t\tBigInteger c;\n\t\t\n\t\tif(a.compareTo(b) < 0){\n\t\t\tc = a;\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t}\n\t\t\n\t\t\n\t\twhile(! a.mod(b).equals(BigInteger.ZERO)){\n\t\t\tc = a.mod(b);\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t}\n\t\t\n\t\treturn b.toString();\n\t\t\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, \"utf-8\"));\n\t\t\n\t\tStringTokenizer st = new StringTokenizer(in.readLine());\n\t\t\n\t\tBigInteger a = new BigInteger(st.nextToken()), b = new BigInteger(st.nextToken());\n\t\t\n\t\t\n\t\tout.write( nod(a,b));\n\t\t\t\t\n\t\tout.flush();\n\t\tSystem.exit(0);\n\t}\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c1ed901c0626a58afef12cb58552b01b", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.*;\npublic class code{\npublic static void main(String[] args){\n\tScanner sc = new Scanner(System.in);\n\tint ans = 0; \n\tBigInteger a,b,x; \n\ta=sc.nextBigInteger();\n\tb=sc.nextBigInteger();\n\t\n\tSystem.out.println(a.equals(b)?a:1);\n\t\n\n\t\t\n\t}\n\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\n\t\t\n\t\t\t\t\n\t\t\t\n\t\n\t\t\n\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c9c647b6dbbe0d4c4f53e36298d292c1", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0} {"lang": "Java 7", "source_code": "By Skater, contest: Codeforces Beta Round #3, problem: (C) Tic-tac-toe, Accepted, #\n \n\nimport java.util.*;\npublic class I {\n\tstatic int n=3,x=0,y=0,kolx=0,koly=0;\n\tstatic char[][] a = new char[10][10];\n\tstatic void f(char k){\n\t\tif (k=='X') x++; else\n\t\t\tif (k=='0') y++; \n\t}\npublic static void main(String args[]){\n\tScanner in = new Scanner(System.in);\n\tfor (int i=1;i<=n;i++) {\n\tString st=in.next();\n\tfor (int j=1;j<=n;j++) {a[i][j] = st.charAt(j-1);if (a[i][j]=='X') kolx++; else if (a[i][j]=='0')koly++;}\n\t}\n\t\n\t\n\t/////////////////////////////////////////////\n\tif (a[1][1]==a[2][2] && a[2][2]==a[3][3]) f(a[1][1]);\n\tif (a[1][3]==a[2][2] && a[3][1] == a[2][2]) f(a[1][3]);\n\t\n\tif (a[1][1]==a[1][2] && a[1][2]==a[1][3]) f(a[1][1]);\n\tif (a[2][1]==a[2][2] && a[2][2]==a[2][3]) f(a[2][1]);\n\tif (a[3][1]==a[3][2] && a[3][2]==a[3][3]) f(a[3][1]);\n\t\n\t\n\tif (a[1][1] == a[2][1] && a[2][1] == a[3][1]) f(a[1][1]);\n\tif (a[1][2] == a[2][2] && a[2][2] == a[3][2]) f(a[1][2]);\n\tif (a[1][3] == a[2][3] && a[2][3] == a[3][3]) f(a[1][3]);\n\t////////////////////////////////////////////\n\tString ans=\"\";\n\t\n\tif (x>0 && y>0) ans=\"illegal\"; else\n\tif (kolx1) ans = \"illegal\"; else \n\tif (kolx>koly && y>0) ans = \"illegal\"; else \n\tif (kolx==koly && x>0) ans = \"illegal\"; else \n\tif (x>0) ans=\"the first player won\"; else\n\tif (y>0) ans = \"the second player won\"; else\n\tif (kolx+koly==9) ans = \"draw\"; else \n\tif (kolx==koly) ans = \"first\"; else ans = \"second\";\n\t\n\tSystem.out.println(ans);\n\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f73d97904e5a69b382cf84e6371c7227", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.lang.Math; // headers MUST be above the first class\nimport java.util.*;\n\n// one class needs to have a main() method\npublic class HelloWorld\n{\n // arguments are passed using the text field below this editor\n public static void main(String[] args)\n {\n Scanner cin = new Scanner(System.in);\n String ret = \"\";\n \n int[][] m = new int [3][3];\n \n for(int i = 0; i < 3; i++){\n String line= cin.next();\n for(int j = 0; j < 3; j++){\n char a = line.charAt(j);\n if(a == '.'){\n m[i][j] = -1;\n }\n else if (a =='X'){\n m[i][j] = 1;\n }\n else {\n m[i][j] = 0;\n }\n }\n }\n \n int num_x = 0, num_o = 0;\n for(int i = 0; i < 3; i++){\n for(int j = 0; j < 3; j++){\n if(m[i][j] == 1){\n num_x++;\n }\n else if(m[i][j] == 0){\n num_o++;\n }\n }\n }\n \n if(num_x > 4 || num_o > 4 || num_x - num_o < 0 || num_x - num_o > 1){\n ret = \"illegal\";\n System.out.println(ret);\n return;\n }\n \n if(num_x - num_o == 1 && !ret.equals(\"illegal\")){\n ret = \"second\";\n }\n else if(num_x - num_o == 0 && !ret.equals(\"illegal\")){\n ret = \"first\";\n }\n \n boolean first_won = false, second_won = false;\n if(pure_row(m, 0, 1) || pure_row(m, 1, 1) || pure_row(m, 2, 1)\n || pure_col(m, 0, 1) || pure_col(m, 1, 1) || pure_col(m, 2, 1)\n || pure_cross1(m,1) || pure_cross2(m,1)){\n first_won = true;\n }\n \n if(pure_row(m, 0, 0) || pure_row(m, 1, 0) || pure_row(m, 2, 0)\n || pure_col(m, 0, 0) || pure_col(m, 1, 0) || pure_col(m, 2, 0)\n || pure_cross1(m, 0) || pure_cross2(m, 0)){\n second_won = true;\n }\n \n //draw\n\n if (first_won && second_won){\n ret = \"draw\";\n System.output.println(ret);\n return;\n }\n else if(first_won){ \n ret = \"the first player won\";\n }\n else if(second_won){\n ret = \"the second player won\";\n }\n else if(!(playable_row(m, 0) || playable_row(m, 1) || playable_row(m, 2)\n || playable_col(m, 0) || playable_col(m, 1) || playable_col(m, 2)\n || playable_cross1(m) || playable_cross2(m))){\n ret = \"draw\";\n }\n \n \n System.out.println(ret);\n }\n \n \n static boolean playable_row(int[][]m, int row){\n boolean p1= true, p2 = true;\n for(int i = 0; i < 3; i++){\n if (m[row][i] == 0){\n p1 = false;\n }\n if (m[row][i] == 1){\n p2 = false;\n }\n }\n return (p1 || p2);\n }\n \n static boolean playable_col(int[][]m, int col){\n boolean p1= true, p2 = true;\n for(int i = 0; i < 3; i++){\n if (m[i][col] == 0){\n p1 = false;\n }\n if (m[i][col] == 1){\n p2 = false;\n }\n }\n return (p1 || p2);\n }\n \n static boolean playable_cross1(int[][]m){\n boolean p1= true, p2 = true;\n for(int i = 0; i < 3; i++){\n if (m[i][i] == 0){\n p1 = false;\n }\n if (m[i][i] == 1){\n p2 = false;\n }\n }\n return (p1 || p2);\n }\n static boolean playable_cross2(int[][]m){\n boolean p1= true, p2 = true;\n for(int i = 0; i < 3; i++){\n if (m[i][2-i] == 0){\n p1 = false;\n }\n if (m[i][2-i] == 1){\n p2 = false;\n }\n }\n return (p1 || p2);\n }\n \n \n \n static boolean pure_row(int [][] m, int row, int player){\n boolean n = true;\n for(int i = 0; i < 3; i++){\n if (m[row][i] != player){\n n = false;\n }\n }\n return n;\n }\n static boolean pure_col(int [][] m, int col, int player){\n boolean n = true;\n for(int i = 0; i < 3; i++){\n if(m[i][col] != player){\n n = false;\n }\n }\n return n;\n }\n \n static boolean pure_cross1(int[][] m, int player){\n boolean n = true;\n for(int i = 0; i < 3; i++){\n if(m[i][i] != player){\n n = false;\n }\n }\n return n;\n }\n static boolean pure_cross2(int[][] m, int player){\n boolean n = true;\n for(int i = 0; i < 3; i++){\n if(m[i][2-i] != player){\n n = false;\n }\n }\n return n;\n }\n \n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "762fa76e0a73c3afd3ac992a2b0a1d2b", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n public static void main(String[] args)\n {\n Scanner in = new Scanner(System.in);\n char[][] board = new char[3][3];\n for(int i = 0; i < 3; i++)\n board[i] = in.nextLine().toCharArray();\n // now test board\n // how is it illegal?\n // more than one difference\n boolean fwin = win(board, 'X'),\n swin = win(board, 'O');\n int c1 = count(board, 'X'), c2 = count(board, 'O');\n if(fwin && swin || Math.abs(c1 - c2) > 1) System.out.println(\"illegal\");\n if(fwin) System.out.println(\"the first player won\");\n if(swin) System.out.println(\"the second player won\");\n if(filled(board)) System.out.println(\"draw\");\n if(c1 > c2) System.out.println(\"second\");\n else System.out.println(\"first\");\n }\n \n static boolean filled(char[][] board)\n {\n return count(board, '.') == 0;\n }\n \n static boolean win(char[][] b, char t)\n {\n for(int i = 0; i < 3; i++)\n {\n if(b[i][0] == b[i][1] && b[i][1] == b[i][2] && b[i][2] == t) return true;\n if(b[0][i] == b[0][i] && b[1][i] == b[2][i] && b[2][i] == t) return true;\n }\n if(b[0][0] == b[1][1] && b[1][1] == b[2][2] && b[2][2] == t) return true;\n if(b[0][2] == b[1][1] && b[1][1] == b[2][0] && b[2][0] == t) return true;\n \n }\n \n static int count(char[][] b, char t)\n {\n int re = 0;\n for(char[] bb : b) for(char ch : bb) if(ch == t) re++;\n return re;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "430587b528d18c82a9eb9b721b1d8a1b", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Solution{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n char[][] t = new char[3][3];\n for(int i=0;i<2;i++){\n String tmp = sc.next();\n for(int j=0;j<2;j++) t[i][j] = tmp.charAt(j);\n }\n int cx = 0;\n int co = 0;\n for(int i=0;i<2;i++){\n for(int j=0;j<2;j++){\n if(char[i][j]=='X') cx++;\n if(char[i][j]=='0') co++;\n }\n }\n if(cx+co<9){\n if(cx-co==1) System.out.println(\"second\");\n else if(co-cx==1) System.out.println(\"first\");\n else System.out.println(\"illegal\");\n return;\n }\n if(cx-co!=1&&co-cx!=1){\n System.out.println(\"illegal\");\n return;\n }\n for(int i=0;i<2;i++){\n if(t[0][i]==t[1][i]&&t[1][i]==t[2][i]){\n if(t[2][i]=='0'){\n System.out.println(\"the second player won\");\n return;\n }else{\n System.out.println(\"the first player won\");\n return;\n }\n }\n if(t[i][0]==t[i][1]&&t[i][1]==t[i][2]){\n if(t[i][2]=='0'){\n System.out.println(\"the second player won\");\n return;\n }else{\n System.out.println(\"the first player won\");\n return;\n }\n }\n }\n if((t[0][0]==t[1][1]&&t[1][1]==t[2][2]) ||\n (t[0][2]==t[1][1]&&t[1][1]==t[2][0])){\n if(t[1][1]=='0'){\n System.out.println(\"the second player won\");\n return;\n }else{\n System.out.println(\"the first player won\");\n return;\n }\n }\n System.out.println(\"draw\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "27b352248e0d2e997cb03f73afa937d0", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class sol\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n String s = sc.next();\n Map map = new HashMap<>();\n for(int i=1;i max)\n {\n max = (int)e.getValue();\n ans = (String)e.getKey();\n }\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39a17f276667a5994f6b555da6cff69d", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class Main {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int length = scanner.nextInt();\n scanner.skip(\"\\n\");\n String input = scanner.nextLine();\n int res = 0;\n String saveS = null;\n\n for (int i = 0; i < input.length() - 1;i++){\n int res1 = 0;\n char first = input.charAt(i);\n char second = input.charAt(i+1);\n String doubleS = Character.toString(first) + Character.toString(second);\n for (int i1 = 0; i1 < input.length()-1; i1++){\n first = input.charAt(i1);\n second = input.charAt(i1+1);\n String doubleS1 = Character.toString(first) + Character.toString(second);\n if (doubleS.equals(doubleS1)) res1++;\n\n }\n if (res1 > res) {res = res1; saveS =doubleS;};\n }\n\n System.out.print(saveS);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "088355f3563e4b37f5121d209f67ab1c", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\n\npublic class a {\n\tpublic static void main(String[] args)\n\t{ int c=0,large=-100;\n\tString r=\" \";\n\tScanner sc =new Scanner(System.in);\n\tString s = sc.nextLine();\n\t\n\tint l=s.length();\n\tfor(int i=0;ilarge)\n\t\t{large=c;\n\t\tr=s.substring(i,i+2);\n\t\t}\t\n\t\t\n\n\t}\n\tSystem.out.println(r);\n\t\n\t\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6c1f54e9f40e12e425e4d854d1e63847", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class codeforces{\n private static Scanner scan;\n public static void main(String args[]){\n scan=new Scanner(System.in);\n \n int n=scan.nextInt();\n String s=scan.nextLine();\n int i;\n String [] substring=new string[s.length];\n \n for(i=0;iMax){\n Max=count;\n sub=substring[i];\n }\n }\n System.out.println(sub);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4728e92740bc037816779eb2e01f06cd", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import org.bouncycastle.util.Arrays;\n\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\n\npublic class A {\n\tpublic static void main(String... args) throws IOException {\n\t\tlong time = 0;\n\t\tif(args.length != 0) {\n\t\t\tSystem.setIn(new FileInputStream(args[0]));\n\t\t\ttime = System.currentTimeMillis();\n\t\t} else if(!Boolean.parseBoolean(System.getProperty(\"ONLINE_JUDGE\"))) {\n\t\t\tmain(\"input.txt\");\n\t\t\treturn;\n\t\t}\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\n\t\tList r = new ArrayList();\n\t\tfor(int i = 1; n != 0; i++) {\n\t\t\tif((n & 1) != 0)\n\t\t\t\tr.add(i);\n\t\t\tn >>>= 1;\n\t\t}\n\t\tCollections.reverse(r);\n\t\tfor(int i = 0; i < r.size(); i++) {\n\t\t\tif(i != 0)\n\t\t\t\tSystem.out.print(' ');\n\t\t\tSystem.out.print(r.get(i));\n\t\t}\n\t\tSystem.out.println();\n\t\t\n\t\tif(time != 0)\n\t\t\tSystem.out.println(System.currentTimeMillis() - time);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2dc98807ac6bf112cf77b2fcfe2e2b2e", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class CF618A\n{\n public static void main(String[] args)\n {\n Scanner scan=new Scanner(System.in);\n int n=scan.nextInt();\n int t=n;\n int l=0;\n while(temp>0)\n {\n temp>>=1;\n ++l\n }\n temp=1<<(l-1);\n String s=\"\";\n for(int i=l;i>0;--i)\n {\n if(n&temp!=0)\n s+=(s.lenth==0?i:(\" \"+i));\n temp>>=1;\n }\n System.out.print(s);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "caed9b0b018e6c0fb0fafdc328bbf73a", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class abc {\n\n\tpublic static void main(String[] args) {\n\t\tStack st = new Stack(0);\n\t\tint n;\n\t\tScanner scan=new Scanner(System.in);\n\t\tn=scan.nextInt();\n\t\tfor(int i=0;i=0&&key[index-1]==key[index-2]){\n\t \t\tkey[index-2]=key[index-2]+1;\n\t \t\tindex--;\n\t \t\tcount--;\n\t \t}\n\t }\n\t public void print(){\n\t \tfor(int i=0;i 0) {\n\t\t\tfor (i = 0; i < power.length; i++) {\n\t\t\t\tif (power[i] > num && power[i] / 2 <= num) {\n\t\t\t\t\tSystem.out.print(i + \" \"); \n\t\t\t\t\tnum -= power[i - 1]; \n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(); \n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "288ef2d5bd80e373c7d96876ecbd6627", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class SolutionB {\n \n public static void main(String args[])throws IOException{\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int mask = 0;\n a++;\n while(mask != b){\n int m = 1;\n int d = a;\n mask = 0;\n while(d > 0){\n int dig = d % 10;\n d /= 10;\n if((dig == 4) || (dig == 7)){\n mask = m * dig + mask;\n m *= 10;\n }\n }\n // System.out.println(mask);\n if(mask == b)break;\n a++;\n }\n System.out.println(a);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7a06d6229f65e8d20d25a0e8404681cf", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "package Problems;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class CF_146B_LuckyMask {\n\tstatic int luckyDivision(int num){\n\t\tint resultt = 0 ;\n\t\tint mult = 1;\n\t\twhile(num>0){\n\t\tif(num%10==7||num%10==4){result+=num%10*mult;mult*=10; }\n\t\tnum=num/10;\n\t\t}\n\treturn resultt ;\t\n\t}\npublic static void main(String[]args)throws Exception{\nScanner sc = new Scanner(System.in);\nint a = sc.nextInt();\nint b = sc.nextInt();\nif(b>a){\n\tSystem.out.println(b);\n\treturn;\n}\n\nint result = a+1;\nwhile( luckyDivision(result)!=b){\n\tresult++;\n}\nSystem.out.println(result);\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cb613eb58571e01922661115bd8af793", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "public class B104 {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int n1=in.nextInt();\n int n2=in.nextInt();\n \n String n=String.valueOf(n1);\n String m=String.valueOf(n2);\n boolean flag=false;\n \n for(int i=n1+1;i<100000;i++){\n String now=String.valueOf(i);\n for(int j=0;j=0) {m=m.replaceFirst(\"\"+now.charAt(j),\"\");}\n \n }\n if(m.equals(\"\")) {System.out.println(i);break;}\n m=String.valueOf(n2);\n } \n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02c81bdd551dee181301d625d99914b6", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "//package CF;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class B {\n public static boolean check(String a, String b){\n\tint i = 0, j = 0;\n\tfor (; i < a.length(); i++)\n\t{\n\t if(a.charAt(i) == b.charAt(j))\n\t\tj++;\n\t}\n\treturn j >= b.length();\n }\n public static void main(String[] args) throws IOException\n {\n\tScanner bf = new Scanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tint a = bf.nextInt();\n\tString b = bf.next();\n\tint c = a+1;\n\twhile(!check(\"\"+c,b))\n\t c++;\n\tout.println(c);\n\tout.flush();\n\tout.close();\n }\n static class Scanner {\n\tStringTokenizer st;\n\tBufferedReader br;\n\n\tpublic Scanner(InputStream s)\n\t{\n\t br = new BufferedReader(new InputStreamReader(s));\n\t}\n\n\tpublic String next() throws IOException\n\t{\n\t while (st == null || !st.hasMoreTokens())\n\t\tst = new StringTokenizer(br.readLine());\n\t return st.nextToken();\n\t}\n\n\tpublic int nextInt() throws IOException\n\t{\n\t return Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() throws IOException\n\t{\n\t return Long.parseLong(next());\n\t}\n\n\tpublic String nextLine() throws IOException\n\t{\n\t return br.readLine();\n\t}\n\n\tpublic double nextDouble() throws IOException\n\t{\n\t String x = next();\n\t StringBuilder sb = new StringBuilder(\"0\");\n\t double res = 0, f = 1;\n\t boolean dec = false, neg = false;\n\t int start = 0;\n\t if (x.charAt(0) == '-')\n\t {\n\t\tneg = true;\n\t\tstart++;\n\t }\n\t for (int i = start; i < x.length(); i++)\n\t\tif (x.charAt(i) == '.')\n\t\t{\n\t\t res = Long.parseLong(sb.toString());\n\t\t sb = new StringBuilder(\"0\");\n\t\t dec = true;\n\t\t} else\n\t\t{\n\t\t sb.append(x.charAt(i));\n\t\t if (dec)\n\t\t\tf *= 10;\n\t\t}\n\t res += Long.parseLong(sb.toString()) / f;\n\t return res * (neg ? -1 : 1);\n\t}\n\n\tpublic boolean ready() throws IOException\n\t{\n\t return br.ready();\n\t}\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1fcd5054ea674dd943bff3cf7a8c01cb", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public int add(int a,int b){\n return a+b;\n }\n \n public static void main(String[] args){\n int[] arr=new int[2];\n for(int i=0;i<2;i++){\n Scanner in =new Scanner(System.in);\n arr[i]=in.nextInt();\n }\n \n System.out.println(add(arr[0],arr[1]));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "66f01efecd750c7d27d2c66baab2de74", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class SUM {\n\n /**\n * @param args\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n System.out.println((long) sc.nextInt() + sc.nextInt());\n sc.close();\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f8875795e30a55a98fb0ecc155cb3b2d", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "public class Main {\n\t\n\n\tpublic static void main(String [] args) {\n\t\tScanner sc= new Scanner(System.in);\n\t\tboolean flag=false;\n\t\tint x=0,y=0;\n\t\twhile(!flag){\n\t\t\ttry {\n\t\t\t\tflag=true;\n\t\t\t\t x= sc.nextInt();\n\t\t\t\tif(x<0 || x>1000){\n\t\t\t\t\tflag=false;\n\t\t\t\t}\n\t\t\t}\n\t\tcatch (Exception e) {\n\t\tflag=false;\n\t\t}\n\t\n\t\t}\n\t\t flag=false;\n\t\twhile(!flag){\n\t\t\ttry {\n\t\t\t\tflag=true;\n\t\t\t\t y= sc.nextInt();\n\t\t\t\tif(y<0 || y>1000){\n\t\t\t\t\tflag=false;\n\t\t\t\t}\n\t\t\t}\n\t\tcatch (Exception e) {\n\t\tflag=false;\n\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(x+y);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fcfb175c450e08d233133caa8502a593", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "\npublic class ElsagheerFools {\n\t\n\n\tpublic static void main(String [] args) throws IOException{\n\t\t\n\t\tSystem.out.println(1000);\n\t}\n}\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a5f405d1f85273bb2c8e986b584f055a", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add", "difficulty": 1500.0} {"lang": "Java 11", "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 r = Sc.nextInt();\n int c = Sc.nextInt();\n int r_empty = 0;\n int c_vis[] = new [c];\n int cnt = 0;\n\n String s[] = new String[r];\n for(int i = 0 ; i < r ; i++)\n {\n s[i] = Sc.next();\n if(s[i].indexOf('S') == -1) \n {\n cnt += c;\n r_empty++;\n \n }\n else\n {\n c_vis[s[i].indexOf('S')] = 1;\n }\n }\n \n for(int i = 0 ; i < c; i++)\n {\n if(c_vis[i] != 1) cnt += (r - r_empty);\n }\n \n System.out.println(cnt);\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6c31a70efa60d28e4ede7ef104f6276c", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Codeforce {\n\n\tpublic static void main(String[] args){\n\t\t\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\t int r, c, count = 0, total = 0;\n\t\t \n\t\t r = scan.nextInt();\n\t\t c = scan.nextInt();\n\t\t \n\t\t String str[] = new String[r];\n\t\t int row[] = new int[r];\n\t\t \n\t\t scan.nextLine();\n\t\t\n\t\tfor(int i=0; i < r; i++){\n\t\t\tstr[i] = scan.nextLine();\n\t\t}\n\t\t\n\t\tfor(int i=0; i < r; i++){\n\t\t\tfor(int j=0; j < c; j++){\n\t\t\t\tif(str[i].charAt(j) != 'S')\n\t\t\t\t\tcount++;\n\t\t\t\telse \n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(count == c){\n\t\t\t\ttotal += count;\n\t\t\t\trow[i] = 1;\n\t\t\t}\n\t\t\tcount = 0;\n\t\t}\n\t\tcount = 0;\n\t\t\n\t\tfor(int i=0; i < c; i++){\n\t\t\tfor(int j=0; j < r; j++){\n\t\t\t\tif(str[j].charAt(i) == 'S'){\n\t\t\t\t\tcount = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if(row[j] != 1)\n\t\t\t\t\tcount++;\n\t\t\t}\n\t\t\t\n\t\t\ttotal += count;\n\t\t}\n\t\tSystem.out.println(total);\n\t\t\n\t\t\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "55505add55d6d4357f807ada32be2cc8", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Pretty {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner stdin = new Scanner(System.in);\n\t\tint n = stdin.nextInt();\n\t\tint m = stdin.nextInt();\n\t\tint [] a = new int[n];\n\t\tint [] b = new int[m];\n\t\tunordered_map < int,int > mp,mp2;\n\t\t\n\t}\n\n}\n\n\n\nBinary Search, Music Notes, Costume Party, Team Tic Tac Toe\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/*\n#include\nusing namespace std;\nint main()\n{\n int n,m,a[10],b[10];\n cin >> n >> m;\n unordered_map < int,int > mp,mp2;\n for(int i=0;i> a[i];\n mp[a[i]] = 1;\n }\n for(int i=0;i> b[i];\n mp2[b[i]] = 1;\n }\n sort(a,a+n);\n sort(b,b+m);\n for(int i=1;i<=9;i++)\n {\n if(mp[i]==1 && mp2[i]==1)\n {\n cout << i << endl;\n return 0;\n }\n }\n if(a[0]>b[0])\n swap(a[0],b[0]);\n cout << a[0] << b[0] << endl;\n}\n*/\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "478a17311c1b8fb68e7ac8697752c6ba", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner ;\npublic class Main{\npublic static void main(String[] args)\n{\n int r , c , k ,count;\nScanner in = new Scanner(System.in) ;\nr= in.nextInt() ;\nc = in.nextInt() ;\n\nchar[][] cr = new char[r][c] ;\nfor( int i = 0 ; i < r ; i++)\n for( int j =0 ; j < c ; j++)\n cr[i][j] = in.nextInt() ;\nfor(int i = 0 ; i < r; i++)\n{\n k = c ;\n for(int j = 0 ; j < c ; j++)\n {\n if( cr[i][j] == 'S')\n break ;\n k-- ;\n }\n if( k== 0)\n for( int j = 0 ; j < c; j++)\n cr[i][j] = '*' ;\n}\nfor( int j = 0 ; j < c; j++)\n{ k = r ;\n for( int i = 0 ; i < r ; i++)\n { if(cr[i][j] == 'S')\n break ;\n k-- \n }\n if( k== 0)\n for( int i= 0 ; i top = new java.util.ArrayList();\n\t\tjava.util.ArrayList bot = new java.util.ArrayList();\n\t\tboolean diff1 = false, diff2 = false;\n\t\tfor ( int i = 0; i < n; i++ ) {\n\t\t\tString [] inp = in.nextLine().split(\" \");\n\t\t\tint t = Integer.parseInt(inp[0]), b = Integer.parseInt(inp[1]);\n\t\t\t\n\t\t\tif( diff1 && (t != b ))\n\t\t\t\tdiff2 = true;\n\t\t\tif ( t != b )\n\t\t\t\tdiff1 = true;\n\t\t\t\n\t\t\ttop.add(t);\n\t\t\tbot.add(b);\n\t\t}\n\t\t\n\t\tboolean t = sum(top)%2 == 0, b = sum(bot)%2==0;\n\t\t\n\t\t\n\t\tif ( t && b) {\n\t\t\tSystem.out.println(0);\n\t\t}\n\t\telse if ( !t && !b && top.size() > 1 && diff) {\n\t\t\tSystem.out.println(1);\n\t\t}\n\t\telse \n\t\t\tSystem.out.println(-1);\n\t\t\n\t\t\n\n\t}\n\t\n\tpublic static int sum(java.util.ArrayList a) {\n\t\tint sum = 0;\n\t\tfor ( int i : a )\n\t\t\tsum += i;\n\t\treturn sum;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "58506ef3aeba71c678543ce7bb735b9a", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int sum1=0,sum2=0;\n int n=sc.nextInt();\n int nn=n,flag=0;\n while(n-->0)\n {\n int x=sc.nextInt();\n int y=sc.nextInt();\n if(x%2==0&&y%2==1||x%2==1&&y%2==0)\n flag=1;\n sum1+=x;\n sum2+=y;\n }\n if(sum1%2==0&&sum2%2==0)\n System.out.println(0);\n else if(sum1%2==0&&sum2%2==1||sum1%2==1&&sum2%2==0)\n System.out.println(-1);\n else(sum1%2==1&&sum2%2==1)\n {\n if(flag==1)\n System.out.println(1);\n else\n System.out.println(-1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b7cab96fa786f38cb59fc87799b621f7", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class Problem353ADomino {\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 s1 = 0;\n\t\tint s2 = 0;\n\t\tint count = 0;\n\t\tfor(int i=0;i0 && count%2==0) {\n\t\t\t\tSystem.out.println('1');\n\t\t\t}\n\t\t\telse {\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t}\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "122af460ccad7232d7a1abe557d1a7b4", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class c\n{\n\tstatic final long MOD = 1000000007;\n\tpublic static void main(String[] args)\n\t{\n\t\tFastScanner in = new FastScanner();\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tArrayList adj[] = new ArrayList[2*n];\n\t\tint comp[] = new int[2*n];\n\t\tfor(int i = 0; i < 2*n; i++)\n\t\t\tadj[i] = new ArrayList<>();\n\t\t\n\t\tfor(int i = 0; i < m; i++)\n\t\t{\n\t\t\tint a = in.nextInt()-1;\n\t\t\tint b = in.nextInt()-1;\n\t\t\tint c = in.nextInt();\n\t\t\t\n\t\t\tif(c == 1) // love\n\t\t\t{\n\t\t\t\tadj[a].add(b);\n\t\t\t\tadj[b].add(a);\n\t\t\t\tadj[a+n].add(b+n);\n\t\t\t\tadj[b+n].add(a+n);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tadj[a].add(b+n);\n\t\t\t\tadj[b+n].add(a);\n\t\t\t\tadj[b].add(a+n);\n\t\t\t\tadj[a+n].add(b);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint id = 1;\n\t\tfor(int i = 0; i < 2*n; i++)\n\t\t{\n\t\t\tif(comp[i] != 0) continue;\n\t\t\t\n\t\t\tArrayDeque q = new ArrayDeque<>();\n\t\t\tq.add(i);\n\t\t\tcomp[i] = id;\n\t\t\twhile(!q.isEmpty())\n\t\t\t{\n\t\t\t\tint u = q.poll();\n\t\t\t\t\n\t\t\t\tfor(int v : adj[u])\n\t\t\t\t{\n\t\t\t\t\tif(comp[v] != 0) continue;\n\t\t\t\t\tcomp[v] = id;\n\t\t\t\t\tq.add(v);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tid++;\n\t\t}\n\t\tid--;\n\t\t\n\t\tboolean flag = true;\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tif(comp[i] == comp[i+n])\n\t\t\t\tflag = false;\n\t\t\n\t\tif(flag)\n\t\t\tSystem.out.println(pow(2, (id/2)-1));\n\t\telse\n\t\t\tSystem.out.println(0);\n\t}\n\n\tprivate static long pow(long b, int e)\n\t{\n\t\tif(e == 0)\n\t\t\treturn 1;\n\t\tif(e == 1)\n\t\t\treturn b;\n\t\t\n\t\tlong ret = pow(b, e/2);\n\t\tret = (ret * ret) % MOD;\n\t\tif((e & 1) == 1)\n\t\t\tret = (ret * b) % MOD;\n\t\t\n\t\treturn ret; \n\t}\n\n\tpublic static class FastScanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(String s)\n\t\t{\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 FastScanner()\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString nextToken()\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\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\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\n\t\tlong nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tdouble nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t\t\n\t\tString next()\n\t\t{\n\t\t\treturn nextToken();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2400640627b917acacb3c8ba7f9e857", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n \n static final long MOD = 1_000_000_007;\n \n public static void main(String[] args) {\n \n Scanner scan = new Scanner(System.in);\n int N = scan.nextInt(), M = scan.nextInt();\n \n long sol = 0;\n for(int i=1;i<=N;i++){\n sol += exp(2, M) - i;\n sol %= MOD;\n }\n sol += MOD;\n sol %= MOD;\n \n System.out.println(sol);\n \n }\n \n public long exp(long a, long b) {\n if(b==0)return 1L;\n long temp = exp(a,b>>1);\n return (b%2)==0 ? (temp*temp)%MOD : (a*((temp*temp)%MOD))%MOD;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "231866b58328dc55ad58ba78cac9c084", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class Example {\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 String s = \"1\";\n for (int i = 0; i < m; i++) {\n s += \"0\";\n }\n BigInteger p = new BigInteger(\"1000000009\");\n BigInteger x = (new BigInteger(s, 2)).mod(p);\n BigInteger ans = BigInteger.ONE;\n for (int i = 1; i <= n; i++) {\n x = x.subtract(BigInteger.ONE);\n ans = ans.multiply(x).mod(p);\n }\n System.out.println(ans.toString());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "15275d5a63ebc9462506e90a9da724b9", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0} {"lang": "Java 7", "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\tStreamInputReader in = new StreamInputReader(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 private static final long MOD = 1000000009;\n\n public void solve(int testNumber, StreamInputReader in, PrintWriter out) {\n /*int M = 7;\n int num = 0;\n for(int i = 1; i <= M; i++)\n for(int j = 1; j <= M; j++)\n for(int k = 1; k <= M; k++)\n for(int l = 1; l <= M; l++)\n for(int m = 1; m <= M; m++)\n for(int n = 1; n <= M; n++)\n for(int o = 1; o <= M; o++)\n for(int p = 1; p <= M; p++) {\n int[] A = {i, j, k, l, m, n, o, p};\n if(!wool(A)) {\n //out.println(i + \" \" + j + \" \" + k + \" \" + l);\n num++;\n }\n }\n out.print(num);*/\n\n int N = in.nextInt();\n int M = in.nextInt();\n\n if(N >= (1 << M)) {\n out.print(0);\n return;\n }\n\n long ways = 1;\n\n long p = 1;\n for(int i = 0; i < M; i++)\n p = (p << 1) % MOD;\n\n for(long i = p - 1; i >= p - N; i = (i - 1 + MOD) % MOD) {\n ways = (ways * i) % MOD;\n }\n\n out.print(ways);\n\t}\n\n }\n\nclass StreamInputReader extends InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public StreamInputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n }\n\nabstract class InputReader {\n\n public abstract int read();\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 return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fbb37136b27ab6e6eed084764641e14d", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n\n public class Maxflow {\n class Edge {\n int t, rev;\n long cap, f;\n public Edge(int t, int rev, long cap) {\n this.t = t;\n this.rev = rev;\n this.cap = cap;\n }\n }\n public Maxflow(int n) {\n graph = new List[n];\n for (int i = 0; i < n; i++) {\n graph[i] = new ArrayList<>();\n }\n }\n List[] graph;\n void addEdge(int s, int t, long cap) {\n graph[s].add(new Edge(t, graph[t].size(), cap));\n graph[t].add(new Edge(s, graph[s].size() - 1, 0));\n// System.err.println(s + \" \" + t + \" \" + cap);\n }\n\n boolean dinicBFS(int src, int dest, int[] dist) {\n Arrays.fill(dist, -1);\n dist[src] = 0;\n int[] Q = new int[graph.length];\n int sizeQ = 0;\n Q[sizeQ++] = src;\n for (int i = 0; i < sizeQ; i++) {\n int u = Q[i];\n for (Edge e: graph[u]) {\n if (dist[e.t] < 0 && e.f < e.cap) {\n dist[e.t] = dist[u] + 1;\n Q[sizeQ++] = e.t;\n }\n }\n }\n return dist[dest] >= 0;\n }\n\n long dinicDFS(int[] ptr, int[] dist, int dest, int u, long f) {\n if (u == dest) return f;\n for (;ptr[u] < graph[u].size(); ++ptr[u]) {\n Edge e = graph[u].get(ptr[u]);\n if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {\n long df = dinicDFS(ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));\n if (df > 0) {\n e.f += df;\n graph[e.t].get(e.rev).f -= df;\n return df;\n }\n }\n }\n return 0;\n }\n\n long maxFLow(int src, int dest) {\n long flow = 0;\n int[] dist = new int[graph.length];\n while (dinicBFS(src, dest, dist)) {\n int[] ptr = new int[graph.length];\n while (true) {\n long df = dinicDFS(ptr, dist, dest, src, Long.MAX_VALUE);\n if (df == 0) break;\n flow += df;\n }\n }\n return flow;\n }\n }\n\n public class MinCostFlowBF {\n List[] graph;\n class Edge {\n int to, f, cap, cost, rev;\n\n Edge(int v, int cap, int cost, int rev) {\n this.to = v;\n this.cap = cap;\n this.cost = cost;\n this.rev = rev;\n }\n }\n\n public MinCostFlowBF(int n) {\n graph = new List[n];\n for (int i = 0; i < n; i++)\n graph[i] = new ArrayList();\n }\n\n public void addEdge(int s, int t, int cap, int cost) {\n graph[s].add(new Edge(t, cap, cost, graph[t].size()));\n graph[t].add(new Edge(s, 0, -cost, graph[s].size() - 1));\n }\n\n void bellmanFord(int s, int[] dist, int[] prevnode, int[] prevedge, int[] curflow) {\n int n = graph.length;\n Arrays.fill(dist, 0, n, Integer.MAX_VALUE);\n dist[s] = 0;\n curflow[s] = Integer.MAX_VALUE;\n boolean[] inqueue = new boolean[n];\n int[] q = new int[n];\n int qt = 0;\n q[qt++] = s;\n for (int qh = 0; (qh - qt) % n != 0; qh++) {\n int u = q[qh % n];\n inqueue[u] = false;\n for (int i = 0; i < graph[u].size(); i++) {\n Edge e = graph[u].get(i);\n if (e.f >= e.cap)\n continue;\n int v = e.to;\n int ndist = dist[u] + e.cost;\n if (dist[v] > ndist) {\n dist[v] = ndist;\n prevnode[v] = u;\n prevedge[v] = i;\n curflow[v] = Math.min(curflow[u], e.cap - e.f);\n if (!inqueue[v]) {\n inqueue[v] = true;\n q[qt++ % n] = v;\n }\n }\n }\n }\n }\n\n public int[] minCostFlow(int s, int t, int maxf) {\n int n = graph.length;\n int[] dist = new int[n];\n int[] curflow = new int[n];\n int[] prevedge = new int[n];\n int[] prevnode = new int[n];\n\n int flow = 0;\n int flowCost = 0;\n while (flow < maxf) {\n bellmanFord(s, dist, prevnode, prevedge, curflow);\n if (dist[t] == Integer.MAX_VALUE)\n break;\n int df = Math.min(curflow[t], maxf - flow);\n flow += df;\n for (int v = t; v != s; v = prevnode[v]) {\n Edge e = graph[prevnode[v]].get(prevedge[v]);\n e.f += df;\n graph[v].get(e.rev).f -= df;\n flowCost += df * e.cost;\n }\n }\n return new int[]{flow, flowCost};\n }\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n int n = sc.nextInt();\n int m = sc.nextInt();\n int k = sc.nextInt();\n int c = sc.nextInt();\n int d = sc.nextInt();\n int[] pos = new int[n];\n for (int i = 0; i < k; i++) {\n pos[sc.nextInt() - 1]++;\n }\n int T = 100;\n MinCostFlowBF mf = new MinCostFlowBF((T + 1) * n + 2);\n for (int i = 0; i < n; i++) {\n if (pos[i] > 0)\n mf.addEdge(0, i + 1, pos[i], 0);\n }\n for (int i = 0; i < T; i++) {\n for (int j = 0; j < n; j++) {\n mf.addEdge(1 + i * n + j, 1 + (i + 1) * n + j, k, 0);\n }\n }\n for (int i = 0; i <= T; i++) {\n for (int j = 1; j <= n; j++) {\n mf.addEdge(1 + i * n, (T + 1) * n + 1, 1, c * i);\n }\n }\n for (int i = 0; i < m; i++) {\n int a = sc.nextInt() - 1;\n int b = sc.nextInt() - 1;\n for (int j = 0; j < T; j++) {\n int cost = 0;\n for (int l = 1; l <= k; l++) {\n mf.addEdge(1 + j * n + a, 1 + (j + 1) * n + b, 1, l * l * d - cost);\n mf.addEdge(1 + j * n + b, 1 + (j + 1) * n + a, 1, l * l * d - cost);\n cost = l * l * d;\n }\n }\n }\n int[] flowAndCost = mf.minCostFlow(0, (T + 1) * n + 1, k);\n System.err.println(flowAndCost[0]);\n pw.println(flowAndCost[1]);\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"output\"));\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9f165d907842b365061791456f7b7ffb", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class G{\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.flush();out.close();\n }\n static class TaskE {\n class MinCostMaxFlow{\n ArrayList al[];\n Edge ja[][]; \n int d[]; // shortest distances\n int N , S , T , maxFlow ; int minCost;\n final int gmax = Integer.MAX_VALUE / 100;\n \n int edges = 0;\n\n class Edge{\n int u , flow, rid, cost;\n Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}\n }\n \n void addEdge(int u , int v , int flow , int cost){\n int lu = al[u].size(), lv = al[v].size();\n al[u].add(new Edge(v, flow, cost, lv)); \n al[v].add(new Edge(u, 0, -cost, lu)); \n }\n \n void convertToArray(){\n ja = new Edge[N][];\n for(int i = 0; i < N; i++){\n int sz = al[i].size();\n ja[i] = new Edge[sz];\n for(int j = 0; j < sz; j++){\n ja[i][j] = al[i].get(j);\n }\n al[i].clear();\n }\n }\n \n MinCostMaxFlow(int n , int source , int sink){\n N = n; S = source; T = sink; maxFlow = 0; minCost = 0;\n al = new ArrayList[N];\n d = new int[N];\n for(int i = 0; i < N; i++){\n al[i] = new ArrayList<>();\n }\n }\n \n boolean BellmanFord(boolean check){\n d[0] = 0;\n for(int i = 0; i < N - 1; i++){\n for(int j = 0; j < N; j++){\n for(Edge e : ja[j]){\n if(e.flow == 0)continue; // not to consider reverse edges\n d[e.u] = Math.min(d[e.u] , d[j] + e.cost);\n }\n }\n }\n if(check){// check for negative cycles\n for(int j = 0; j < N; j++){\n for(Edge e : ja[j]){\n if(e.flow == 0)continue;\n if(d[j] + e.cost < d[e.u]) return false;\n }\n } \n }return true;\n }\n\n int node[]; // present node \n\n int visit[]; // 0 -> not added 1 -> not removed 2 -> removed\n int prv[], prve[]; // previous node for augmentation\n int dist[]; // min dist\n\n boolean simple(){\n node = new int[N]; \n visit = new int[N]; \n prv = new int[N];\n prve = new int[N];\n dist = new int[N]; Arrays.fill(dist , gmax);\n\n node[0] = S; dist[0] = 0;\n int front = 1, back = 0;\n while(front != back){\n int u = node[back++]; int distu = dist[u];\n if(back == N)back = 0;\n visit[u] = 2;\n for(int i = 0; i < ja[u].length; i++){\n Edge e = ja[u][i];\n if(e.flow == 0)continue;\n int cdist = distu + e.cost; // no need of reduced cost\n if(cdist < dist[e.u]){\n if(visit[e.u] == 0){\n node[front] = e.u; \n if(++front == N)front = 0;\n }else if(visit[e.u] == 2){\n if(--back == -1)back += N;\n node[back] = e.u;\n }\n visit[e.u] = 1;\n prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;\n }\n }\n }\n return visit[T] != 0;\n }\n\n class pair{\n int F; int S;\n pair(int a, int b){F = a; S = b;}\n }\n\n boolean dijkstra(){\n visit = new int[N];\n prv = new int[N];\n prve = new int[N];\n dist = new int[N]; Arrays.fill(dist, gmax);\n PriorityQueue pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));\n\n pq.add(new pair(S , 0)); dist[0] = 0;\n o : while(!pq.isEmpty()){\n pair p = pq.poll();\n while(dist[p.F] < p.S){\n if(pq.isEmpty()) break o; // had a better val \n p = pq.poll();\n }\n visit[p.F] = 2;\n for(int i = 0; i < ja[p.F].length; i++){\n Edge e = ja[p.F][i];\n if(e.flow == 0)continue; // important\n int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost\n if(cdist < dist[e.u]){ \n if(visit[e.u] == 2) return false;\n pq.add(new pair(e.u , cdist));\n dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;\n visit[e.u] = 1;\n }\n }\n }\n return visit[T] != 0;\n }\n \n int augment(){\n int p = T; int min = gmax;\n while(p != 0){\n int pp = prv[p], pe = prve[p];\n int val = ja[pp][pe].flow;\n min = Math.min(min , val);\n p = pp;\n }\n p = T;\n while(p != 0){\n int pp = prv[p], pe = prve[p];\n ja[pp][pe].flow -= min;\n ja[p][ja[pp][pe].rid].flow += min;\n p = pp;\n }\n maxFlow += min;\n return min;\n }\n\n // if(dist[T] >= 0)return true; // non contributing flow\n boolean calSimple(){\n // uncomment to check for negative cycles\n /* boolean possible = BellmanFord(true); \n if(!possible) return false; */\n while(simple()){\n /*if(dist[T] >= 0)return true;*/ \n minCost += dist[T] * augment();\n }\n return true;\n }\n\n void updPotential(){\n for(int i = 0; i < N; i++){\n if(visit[i] != 0){\n d[i] += dist[i] - dist[S];\n }\n }\n }\n boolean calWithPotential(){\n // set true to check for negative cycles\n // boolean possible = BellmanFord(false); \n // if(!possible) return false;\n while(dijkstra()){\n int min = dist[T] + d[T] - d[S]; // getting back the original cost\n /*if(dist[T] >= 0)return true;*/\n minCost += min * augment();\n updPotential();\n }\n return true; \n }\n }\n int n , m, k, c, d, a[], f[];\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();\n // S + n\n int maxl = 2 * n, T = n * maxl + 1;\n MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);\n a = new int[k + 1]; f = new int[n + 1];\n for(int i = 1; i <= k; i++){\n a[i] = in.nextInt();\n f[a[i]]++;\n }\n for(int i = 1; i <= n; i++){\n if(f[i] == 0)continue;\n ans.addEdge(0 , i , f[i], 0);\n }\n for(int i = 2; i <= n; i++){\n for(int l = 0; l < maxl - 1; l++){\n ans.addEdge(l * n + i , (l + 1) * n + i, k, c);\n }\n }\n for(int i = 1; i <= m; i++){\n int a = in.nextInt(), b = in.nextInt();\n for(int l = 0; l < maxl - 1; l++){\n for(int p = 1; p <= k; p++){\n if(a != 1)\n ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);\n if(b != 1)\n ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);\n }\n } \n }\n for(int l = 1; l < maxl; l++){\n ans.addEdge(l * n + 1, T, 1, 0);\n }\n ans.convertToArray();\n ans.calWithPotential();\n // ans.calSimple();\n if(ans.maxFlow != k){\n out.println(\"BUG\");\n }else{\n out.println((int)ans.minCost);\n }\n }\n }\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream));\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "10de76c37c3bde164788bd04f05f4412", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class GG {\n public static void main(String[] args) {\n FastScanner scanner = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n int N = scanner.nextInt();\n int M = scanner.nextInt();\n int K = scanner.nextInt();\n int C = scanner.nextInt();\n int D = scanner.nextInt();\n MinCostMaxFlowSolver solver = new EdmondsKarp();\n int[] people = new int[K];\n for(int i = 0; i < K; i++) people[i] = scanner.nextInt()-1;\n Node src = solver.addNode();\n Node snk = solver.addNode();\n int amt = 375;\n Node[][] timeNodes = new Node[N][amt];\n for(int i = 0; i < N; i++) {\n for(int j = 1; j < amt; j++) {\n timeNodes[i][j] = solver.addNode();\n if (j > 1) solver.link(timeNodes[i][j-1], timeNodes[i][j], Integer.MAX_VALUE, 0);\n }\n }\n for(int i = 0; i < K; i++) {\n solver.link(src, timeNodes[people[i]][1], 1, 0);\n }\n for(int i = 1; i < amt; i++) {\n for(int j = 0; j < K; j++) {\n solver.link(timeNodes[0][i], snk, 1, C*i-C);\n }\n }\n for(int i =0; i < M; i++) {\n int a = scanner.nextInt()-1;\n int b = scanner.nextInt()-1;\n for(int j = 1; j < amt-1; j++) {\n for(int k = 1; k <= K; k++) {\n solver.link(timeNodes[a][j], timeNodes[b][j + 1], k, D*k*k);\n solver.link(timeNodes[b][j], timeNodes[a][j + 1], k, D*k*k);\n }\n }\n }\n long[] ret = solver.getMinCostMaxFlow(src, snk);\n out.println(ret[1]);\n out.flush();\n }\n \n public static class Node {\n // thou shall not create nodes except through addNode()\n private Node() { }\n \n List edges = new ArrayList();\n int index; // index in nodes array\n \n }\n \n public static class Edge\n {\n boolean forward; // true: edge is in original graph\n Node from, to; // nodes connected\n long flow; // current flow\n final long capacity;\n Edge dual; // reference to this edge's dual\n long cost; // only used for MinCost.\n protected Edge(Node s, Node d, long c, boolean f)\n {\n forward = f;\n from = s;\n to = d;\n capacity = c;\n }\n long remaining() { return capacity - flow; }\n void addFlow(long amount) {\n flow += amount;\n dual.flow -= amount;\n }\n }\n \n public static abstract class MaxFlowSolver {\n List nodes = new ArrayList();\n \n public void link(Node n1, Node n2, long capacity) {\n link(n1, n2, capacity, 1);\n }\n \n public void link(Node n1, Node n2, long capacity, long cost) {\n Edge e12 = new Edge(n1, n2, capacity, true);\n Edge e21 = new Edge(n2, n1, 0, false);\n e12.dual = e21;\n e21.dual = e12;\n n1.edges.add(e12);\n n2.edges.add(e21);\n e12.cost = cost;\n e21.cost = -cost;\n }\n void link(int n1, int n2, long capacity) {\n link(nodes.get(n1), nodes.get(n2), capacity);\n }\n protected MaxFlowSolver(int n) {\n for (int i = 0; i < n; i++)\n addNode();\n }\n protected MaxFlowSolver() {\n this(0);\n }\n \n public abstract long getMaxFlow(Node src, Node snk);\n public Node addNode() {\n Node n = new Node();\n n.index = nodes.size();\n nodes.add(n);\n return n;\n }\n }\n static abstract class MinCostMaxFlowSolver extends MaxFlowSolver {\n // returns [maxflow, mincost]\n abstract long [] getMinCostMaxFlow(Node src, Node snk);\n // unavoidable boiler plate\n MinCostMaxFlowSolver () { this(0); }\n MinCostMaxFlowSolver (int n) { super(n); }\n }\n \n static class EdmondsKarp extends MinCostMaxFlowSolver\n {\n EdmondsKarp () { this(0); }\n EdmondsKarp (int n) { super(n); }\n long minCost;\n \n @Override\n public long [] getMinCostMaxFlow(Node src, Node snk) {\n long maxflow = getMaxFlow(src, snk);\n return new long [] { maxflow, minCost };\n }\n static final long INF = Long.MAX_VALUE/4;\n \n @Override\n public long getMaxFlow(Node src, Node snk) {\n final int n = nodes.size();\n final int source = src.index;\n final int sink = snk.index;\n long flow = 0;\n long cost = 0;\n long[] potential = new long[n]; // allows Dijkstra to work with negative edge weights\n while (true) {\n Edge[] parent = new Edge[n]; // used to store an augmenting path\n long[] dist = new long[n]; // minimal cost to vertex\n Arrays.fill(dist, INF);\n dist[source] = 0;\n PriorityQueue que = new PriorityQueue();\n que.add(new Item(0, source));\n while (!que.isEmpty()) {\n Item item = que.poll();\n if (item.dist != dist[item.v])\n continue;\n \n for (Edge e : nodes.get(item.v).edges) {\n long temp = dist[item.v] + e.cost + potential[item.v] - potential[e.to.index];\n if (e.capacity > e.flow && dist[e.to.index] > temp) {\n dist[e.to.index] = temp;\n parent[e.to.index] = e;\n que.add(new Item(temp, e.to.index));\n }\n }\n }\n if (parent[sink] == null)\n break;\n for (int i = 0; i < n; i++)\n if (parent[i] != null)\n potential[i] += dist[i];\n long augFlow = Long.MAX_VALUE;\n for (int i = sink; i != source; i = parent[i].from.index)\n augFlow = Math.min(augFlow, parent[i].capacity - parent[i].flow);\n for (int i = sink; i != source; i = parent[i].from.index) {\n Edge e = parent[i];\n e.addFlow(augFlow);\n cost += augFlow * e.cost;\n }\n flow += augFlow;\n }\n \n minCost = cost;\n return flow;\n }\n \n static class Item implements Comparable {\n long dist;\n int v;\n \n public Item(long dist, int v) {\n this.dist = dist;\n this.v = v;\n }\n \n public int compareTo(Item that) {\n return Long.compare(this.dist, that.dist);\n }\n }\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "127916bf2ecb01ce8ca4e4830fb1dc87", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class G{\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.flush();out.close();\n }\n static class TaskE {\n class MinCostMaxFlow{\n ArrayList al[];\n Edge ja[][]; \n int d[]; // shortest distances\n int N , S , T , maxFlow ; int minCost;\n final int gmax = Integer.MAX_VALUE / 100;\n \n int edges = 0;\n\n class Edge{\n int u , flow, rid, cost;\n Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}\n }\n \n void addEdge(int u , int v , int flow , int cost){\n int lu = al[u].size(), lv = al[v].size();\n al[u].add(new Edge(v, flow, cost, lv)); \n al[v].add(new Edge(u, 0, -cost, lu)); \n }\n \n void convertToArray(){\n ja = new Edge[N][];\n for(int i = 0; i < N; i++){\n int sz = al[i].size();\n ja[i] = new Edge[sz];\n for(int j = 0; j < sz; j++){\n ja[i][j] = al[i].get(j);\n }\n al[i].clear();\n }\n }\n \n MinCostMaxFlow(int n , int source , int sink){\n N = n; S = source; T = sink; maxFlow = 0; minCost = 0;\n al = new ArrayList[N];\n d = new int[N];\n for(int i = 0; i < N; i++){\n al[i] = new ArrayList<>();\n }\n }\n \n boolean BellmanFord(boolean check){\n d[0] = 0;\n for(int i = 0; i < N - 1; i++){\n for(int j = 0; j < N; j++){\n for(Edge e : ja[j]){\n if(e.flow == 0)continue; // not to consider reverse edges\n d[e.u] = Math.min(d[e.u] , d[j] + e.cost);\n }\n }\n }\n if(check){// check for negative cycles\n for(int j = 0; j < N; j++){\n for(Edge e : ja[j]){\n if(e.flow == 0)continue;\n if(d[j] + e.cost < d[e.u]) return false;\n }\n } \n }return true;\n }\n\n int node[]; // present node \n\n int visit[]; // 0 -> not added 1 -> not removed 2 -> removed\n int prv[], prve[]; // previous node for augmentation\n int dist[]; // min dist\n\n boolean simple(){\n node = new int[N]; \n visit = new int[N]; \n prv = new int[N];\n prve = new int[N];\n dist = new int[N]; Arrays.fill(dist , gmax);\n\n node[0] = S; dist[0] = 0;\n int front = 1, back = 0;\n while(front != back){\n int u = node[back++]; int distu = dist[u];\n if(back == N)back = 0;\n visit[u] = 2;\n for(int i = 0; i < ja[u].length; i++){\n Edge e = ja[u][i];\n if(e.flow == 0)continue;\n int cdist = distu + e.cost; // no need of reduced cost\n if(cdist < dist[e.u]){\n if(visit[e.u] == 0){\n node[front] = e.u; \n if(++front == N)front = 0;\n }else if(visit[e.u] == 2){\n if(--back == -1)back += N;\n node[back] = e.u;\n }\n visit[e.u] = 1;\n prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;\n }\n }\n }\n return visit[T] != 0;\n }\n\n class pair{\n int F; int S;\n pair(int a, int b){F = a; S = b;}\n }\n\n boolean dijkstra(){\n visit = new int[N];\n prv = new int[N];\n prve = new int[N];\n dist = new int[N]; Arrays.fill(dist, gmax);\n PriorityQueue pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));\n\n pq.add(new pair(S , 0)); dist[0] = 0;\n o : while(!pq.isEmpty()){\n pair p = pq.poll();\n while(dist[p.F] < p.S){\n if(pq.isEmpty()) break o; // had a better val \n p = pq.poll();\n }\n visit[p.F] = 2;\n for(int i = 0; i < ja[p.F].length; i++){\n Edge e = ja[p.F][i];\n if(e.flow == 0)continue; // important\n int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost\n if(cdist < dist[e.u]){ \n if(visit[e.u] == 2) return false;\n pq.add(new pair(e.u , cdist));\n dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;\n visit[e.u] = 1;\n }\n }\n }\n return visit[T] != 0;\n }\n \n int augment(){\n int p = T; int min = gmax;\n while(p != 0){\n int pp = prv[p], pe = prve[p];\n int val = ja[pp][pe].flow;\n min = Math.min(min , val);\n p = pp;\n }\n p = T;\n while(p != 0){\n int pp = prv[p], pe = prve[p];\n ja[pp][pe].flow -= min;\n ja[p][ja[pp][pe].rid].flow += min;\n p = pp;\n }\n maxFlow += min;\n return min;\n }\n\n // if(dist[T] >= 0)return true; // non contributing flow\n boolean calSimple(){\n // uncomment to check for negative cycles\n /* boolean possible = BellmanFord(true); \n if(!possible) return false; */\n while(simple()){\n /*if(dist[T] >= 0)return true;*/ \n minCost += dist[T] * augment();\n }\n return true;\n }\n\n void updPotential(){\n for(int i = 0; i < N; i++){\n if(visit[i] != 0){\n d[i] += dist[i] - dist[S];\n }\n }\n }\n boolean calWithPotential(){\n // set true to check for negative cycles\n // boolean possible = BellmanFord(false); \n // if(!possible) return false;\n while(dijkstra()){\n int min = dist[T] + d[T] - d[S]; // getting back the original cost\n /*if(dist[T] >= 0)return true;*/\n minCost += min * augment();\n updPotential();\n }\n return true; \n }\n }\n int n , m, k, c, d, a[], f[];\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();\n // S + n\n int maxl = 2 * n, T = n * maxl + 1;\n MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);\n a = new int[k + 1]; f = new int[n + 1];\n for(int i = 1; i <= k; i++){\n a[i] = in.nextInt();\n f[a[i]]++;\n }\n for(int i = 1; i <= n; i++){\n if(f[i] == 0)continue;\n ans.addEdge(0 , i , f[i], 0);\n }\n for(int i = 2; i <= n; i++){\n for(int l = 0; l < maxl - 1; l++){\n ans.addEdge(l * n + i , (l + 1) * n + i, k, c);\n }\n }\n for(int i = 1; i <= m; i++){\n int a = in.nextInt(), b = in.nextInt();\n for(int l = 0; l < maxl - 1; l++){\n for(int p = 1; p <= k; p++){\n if(a != 1)\n ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);\n if(b != 1)\n ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);\n }\n } \n }\n for(int l = 1; l < maxl; l++){\n ans.addEdge(l * n + 1, T, k, 0);\n }\n ans.convertToArray();\n ans.calWithPotential();\n // ans.calSimple();\n if(ans.maxFlow != k){\n out.println(\"BUG\");\n }else{\n out.println((int)ans.minCost);\n }\n }\n }\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream));\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d66ce9b11b8adcd1b82c8920a618ee87", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\nimport sun.awt.X11.XConstants;\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 root\n */\npublic class B {\n \n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n String str[] = new String[4];\n for(int i = 0;i<4;i++){\n str[i] = in.next();\n }\n boolean type1 = false;\n boolean type2 = false;\n char [] seq1 = new char[2];\n char [] seq2 = new char[2];\n String str1 = str[0]+str[1].charAt(1)+str[1].charAt(0);\n str1 =str1.replaceAll(\"X\", \"\");\n String str2 = str[2]+str[3].charAt(1)+str[3].charAt(0);\n str2 = str2.replaceAll(\"X\", \"\");\n type1 = (str1.equals(\"ABC\") || str1.equals(\"BCA\") || str1.equals(\"CAB\"));\n type2 = (str2.equals(\"ABC\") || str2.equals(\"BCA\") || str2.equals(\"CAB\"));\n \n \n System.out.println((type1 == type2)?\"YES\":\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cba0921b76e02c10be11b0097d054b06", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(in, out);\n out.close();\n }\n\n public static class TaskA {\n public void solve(InputReader in, PrintWriter out) {\n StringBuilder ar[] = new StringBuilder[2];\n for (int i = 0; i < 2; i++) {\n ar[i] = new StringBuilder();\n StringBuilder s1 = new StringBuilder(in.next());\n StringBuilder s2 = new StringBuilder(in.next());\n char rem = s2.charAt(0);\n s2.deleteCharAt(0);\n s2.append(rem);\n s1.append(s2);\n for (int k = 0; k < 4; k++)\n if (s1.charAt(k) != 'X')\n ar[i].append(s1.charAt(k));\n }\n for (int i = 0; i < 3; i++) {\n if (ar[0].compareTo(ar[1]) == 0) {\n out.println(\"YES\");\n return;\n }\n char rem = ar[1].charAt(0);\n ar[1].deleteCharAt(0);\n ar[1].append(rem);\n }\n out.println(\"NO\");\n }\n }\n\n public 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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8fc1d72fdf08c5995372f94f8dd53fb6", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package crash_course.chapter1;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class SlidingPuzzles {\t\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tBufferedReader br = new BufferedReader(System.in);\n\t\tPrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out)));\n\t\t\n\t\tArrayList slider1 = clockwiseArrangement(br);\n\t\tArrayList slider2 = clockwiseArrangement(br);\n\n\t\tslider1.remove(\"X\");\n\t\tslider2.remove(\"X\");\n\t\t\n\t\tslider2 = rotate(slider2, (slider2.indexOf(\"A\") - slider1.indexOf(\"A\")) % 4);\n\t\t\n\t\tif(Arrays.equals(slider1.toArray(), slider2.toArray())) {\n\t\t\tpw.write(\"YES\");\n\t\t} else {\n\t\t\tpw.write(\"NO\");\n\t\t}\n\t\t\n\t\tbr.close();\n\t\tpw.close();\n\t}\n\t\n\tpublic static ArrayList clockwiseArrangement(BufferedReader br) throws Exception {\n\t\tArrayList circle = new ArrayList<>();\n\t\tString line;\n\t\t\n\t\tline = br.readLine();\n\t\tcircle.add(line.split(\"\")[0]);\n\t\tcircle.add(line.split(\"\")[1]);\n\t\tline = br.readLine();\n\t\tcircle.add(line.split(\"\")[1]);\n\t\tcircle.add(line.split(\"\")[0]);\n\t\t\n\t\treturn circle;\n\t}\n\t\n\tpublic static ArrayList rotate(ArrayList circle, int shift) {\n\t\tArrayList newCircle = new ArrayList<>();\n\t\t\n\t\tfor(int i = 0; i < circle.size(); i++) {\n\t\t\tnewCircle.add(circle.get((i + shift) % circle.size()));\n\t\t}\n\t\t\n\t\treturn newCircle;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a595042a31a5c6234415f0b09435bfc7", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport sun.plugin.javascript.navig.Array;\n\nimport java.util.*;\n\n/**\n * Created by Ashiq on 6/10/2016.\n */\npublic class Zsort {\n public static void main(String[] args) {\n char [] c1=new char[4];\n char [] c2=new char[4];\n char a, b, c, x;\n Scanner s = new Scanner(System.in);\n a = (char) s.findInLine(\".\").charAt(0);\n b = (char) s.findInLine(\".\").charAt(0);\n s.nextLine();\n c = (char) s.findInLine(\".\").charAt(0);\n x = (char) s.findInLine(\".\").charAt(0);\n c1[0]=a;\n c1[1]=b;\n c1[2]=x;\n c1[3]=c;\n s.nextLine();\n a = (char) s.findInLine(\".\").charAt(0);\n b = (char) s.findInLine(\".\").charAt(0);\n s.nextLine();\n c = (char) s.findInLine(\".\").charAt(0);\n x = (char) s.findInLine(\".\").charAt(0);\n c2[0]=a;\n c2[1]=b;\n c2[2]=x;\n c2[3]=c;\n\n int n=0;\n for( int i=0;i10) {\n\t\t\tstr=String.valueOf(n);\n\t\t\tfor(int i=0;i 0) {\n suma += numero % 10;\n\n numero = numero / 10;\n \n }\n System.out.print(n*10 + (10-suma));*/\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4bca8a9f437ecab90a3724789db2f6e3", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class A158 {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt();\n\t\tint[] x = new int[n];\n\t\tint counter = 0;\n for(int i=0; i x[i]){\n \t counter ++;\n \t }\n\n \n\n\n \t}\n \t System.out.println(counter) + 1;\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca030fbc870a3549a20207873f29cf9b", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic final class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner scan = new Scanner(System.in);\n int numpeople = scan.nextInt()\n int[] aryWin;\n aryWin = new int[numpeople]; // sets up array with \"n\" people\n \n int place = scan.nextInt(); // integer \"place\" = kth place\n \n for (int i=0, i max) c++ else break;\n }\n\n System.out.println(c);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "af735900cd46475c7f13433de8edf43b", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0} {"lang": "Java 11", "source_code": "//package com.company;\nimport java.io.IOException;\nimport java.util.Scanner;\n\n\n\npublic class NextRound {\n public static void main (String [] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n int np = sc.nextInt();\n int k = sc.nextInt();\n int arrPlacement[] = new int[np];\n int advancement = 0;\n for(int i = 0; i < np; i ++){\n arrPlacement[i] = sc.nextInt();\n if(arrPlacement[i] > k) {\n if((arrPlacement[i]) > 0){\n advancement = advancement + 1;\n }\n else{\n advancement = advancement;\n }\n//ooy\n }\n System.out.println(advancement);\n\n\n\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a530b290dfe19f18cf926cd9af740351", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0} {"lang": "Java 6", "source_code": "//package C;\n\n\n\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.*;\n\npublic class solver implements Runnable {\n\t\n\tprivate void solve2(long n,long m,long a,long b) {\n\t\t/*long n=nextInt();\n\t\tlong m=nextInt();\n\t\tlong a=nextInt();\n\t\tlong b=nextInt();*/\n\t\t\n\t\tif(m==1 || m==n) {out.print(1); return;}\n\t\t\n\t\tlong to=a/m;\n\t\tif(to*m=25) while(true); //(50,52)\n\t\tsolve2(n,m,a,b);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tnew solver().run();\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t//in = new BufferedReader(new FileReader(\"in.txt\"));\n\t\t\ttokenizer = null;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t//out = new PrintWriter(new File(\"out.txt\"));\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\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 nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe95c84501c9c4182397578835f88429", "src_uid": "f256235c0b2815aae85a6f9435c69dac", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/**\n *\n * @author Andrew\n */\npublic class C {\n\n public static boolean poln(int i, int[][] mas) {\n for (int j = 0; j < mas[0].length; j++) {\n if (mas[i][j] == 1) {\n return true;\n }\n }\n return false;\n }\n\n public static boolean eq(int i, int[][] mas) {\n if ((i == 0) && (poln(0, mas))) {\n return false;\n }\n if ((i == 0) && (!poln(0, mas))) {\n return true;\n }\n for (int j = 0; j < mas[0].length; j++) {\n if (((mas[i][j] != mas[i - 1][j])) && (mas[i][j] != 2)) {\n return false;\n }\n }\n return true;\n }\n\n public static int number(int[][] mas, int u) {\n int t = 0;\n int k = 0;\n for (int i = 0; i < mas.length; i++) {\n if ((poln(i, mas)) || (i == 0)) {\n if (!eq(i, mas)) {\n k = 1;\n t++;\n }\n }\n if ((!poln(i, mas)) && (k == 1) && (i != 0) && (u == 1)) {\n return t;\n }\n\n }\n return t;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int a = sc.nextInt();\n int b = sc.nextInt();\n int tt;\n if (n % m == 0) {\n tt = n / m;\n } else {\n tt = n / m + 1;\n }\n\n int[][] mas = new int[tt][m];\n int[][] mas2 = new int[m][tt];\n\n for (int i = 0; i < tt; i++) {\n for (int j = 0; j < m; j++) {\n if (((i * m + j) >= a - 1) && ((i * m + j) <= b - 1)) {\n mas[i][j] = 1;\n mas2[j][i] = 1;\n\n }\n if ((i * m + j) >= n) {\n mas[i][j] = 2;\n mas2[j][i] = 2;\n }\n }\n }\n\n int t1 = number(mas, 1);\n int t2 = number(mas2, 0);\n if (t1 < t2) {\n System.out.print(t1);\n } else {\n System.out.print(t2);\n }\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cac3933b4d599f89bce1c4b6cb822a81", "src_uid": "f256235c0b2815aae85a6f9435c69dac", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\n\nimport java.awt.geom.Point2D;\nimport java.text.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tfinal String filename = \"\";\n\n\tpublic void solve() throws Exception {\n\t\tint n = iread();\n\t\tint m = iread();\n\t\tint a = iread() - 1;\n\t\tint b = iread() - 1;\n\t\tint res = 0;\n\t\tif (a / m == b / m)\n\t\t\tres = 1;\n\t\telse if (a % m == 0) {\n\t\t\tif (b % m == m - 1 || b == n - 1)\n\t\t\t\tres = 1;\n\t\t\telse\n\t\t\t\tres = 2;\n\t\t} else if (b == n - 1||b%m=m-1) {\n\t\t\tif (a % m == 0)\n\t\t\t\tres = 1;\n\t\t\telse\n\t\t\t\tres = 2;\n\t\t} else {\n\t\t\tif (a / m == b / m - 1 || a % m + b % m == m - 1)\n\t\t\t\tres = 2;\n\t\t\telse\n\t\t\t\tres = 3;\n\t\t}\n\t\tout.write(res + \"\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t// in = new BufferedReader(new FileReader(filename+\".in\"));\n\t\t\t// out = new BufferedWriter(new FileWriter(filename+\".out\"));\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tpublic int iread() throws Exception {\n\t\treturn Integer.parseInt(readword());\n\t}\n\n\tpublic double dread() throws Exception {\n\t\treturn Double.parseDouble(readword());\n\t}\n\n\tpublic long lread() throws Exception {\n\t\treturn Long.parseLong(readword());\n\t}\n\n\tBufferedReader in;\n\n\tBufferedWriter out;\n\n\tpublic String readword() throws IOException {\n\t\tStringBuilder b = new StringBuilder();\n\t\tint c;\n\t\tc = in.read();\n\t\twhile (c >= 0 && c <= ' ')\n\t\t\tc = in.read();\n\t\tif (c < 0)\n\t\t\treturn \"\";\n\t\twhile (c > ' ') {\n\t\t\tb.append((char) c);\n\t\t\tc = in.read();\n\t\t}\n\t\treturn b.toString();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t} catch (Exception e) {\n\n\t\t}\n\t\t// new Thread(new Main()).start();\n\t\tnew Thread(null, new Main(), \"1\", 1 << 25).start();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0a67dbb9420526b47a2f58c885d73d06", "src_uid": "f256235c0b2815aae85a6f9435c69dac", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class C {\n\n public void solve() throws Exception {\n \n long n = nextInt(), m = nextInt(), a = nextInt()-1, b = nextInt()-1;\n long la = a/m, lb = b/m, fa = a%m, fb = (b+1)%m;\n if (b+1==n) b = (lb+1)*m-1;\n \n if (la==lb || (fa==0 && fb==0)) println(1);\n else if (la+1==lb || fa==0 || fb==0 || fa==fb) println(2);\n else println(3);\n a\n }\n\n \n\n ////////////////////////////////////////////////////////////////////////////\n\n boolean showDebug = true;\n\n double EPS = 1e-7;\n int INF = Integer.MAX_VALUE;\n long INFL = Long.MAX_VALUE;\n double INFD = Double.MAX_VALUE;\n\n \n int absPos(int i) {\n return i<0 ? 0:i;\n }\n long absPos(long i) {\n return i<0 ? 0:i;\n }\n double absPos(double i) {\n return i<0 ? 0:i;\n }\n \n int min(int... nums) {\n int r = INF;\n for (int i: nums)\n if (ir) r=i;\n return r;\n }\n long minL(long... nums) {\n long r = INFL;\n for (long i: nums)\n if (ir) r=i;\n return r;\n }\n double minD(double... nums) {\n double r = INFD;\n for (double i: nums)\n if (ir) r=i;\n return r;\n }\n long sumArr(int[] arr) {\n long res = 0;\n for (int i: arr)\n res+=i;\n return res;\n }\n long sumArr(long[] arr) {\n long res = 0;\n for (long i: arr)\n res+=i;\n return res;\n }\n double sumArr(double[] arr) {\n double res = 0;\n for (double i: arr)\n res+=i;\n return res;\n }\n\n long partsFitCnt(long partSize, long wholeSize) {\n return (partSize+wholeSize-1)/partSize;\n }\n\n boolean odd(long i) {\n return (i&1)==1;\n }\n\n long binpow(int x, int n) {\n long r = 1;\n while (n>0) {\n if ((n&1)!=0) r*=x;\n x*=x;\n n>>=1;\n }\n return r;\n }\n\n\n String str(Object o) {\n return o.toString();\n }\n\n\n long timer = System.currentTimeMillis();\n void startTimer() {\n timer = System.currentTimeMillis();\n }\n void stopTimer() {\n System.err.println(\"time: \"+(System.currentTimeMillis()-timer)/1000.0);\n }\n\n\n class InputReader {\n byte[] buf = new byte[1<<16];\n int bufPos = 0, bufLim = -1;\n char read() throws IOException {\n if (bufPos>=bufLim) {\n bufLim = System.in.read(buf);\n bufPos = 0;\n }\n return (char)buf[bufPos++];\n }\n }\n\n InputReader in = new InputReader();\n static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);\n\n char nextInput() throws IOException {\n return in.read();\n }\n char nextChar() throws IOException {\n char c = in.read();\n while (c<=' ') c=in.read();\n return c;\n }\n String nextWord() throws IOException {\n StringBuilder sb = new StringBuilder();\n char c = in.read();\n while (c<=' ') c=in.read();\n while (c>' ') {\n sb.append(c);\n c = in.read();\n }\n return new String(sb);\n }\n String nextLine() throws IOException {\n StringBuilder sb = new StringBuilder();\n char c = in.read();\n while (c<=' ') c=in.read();\n while (c!='\\n' && c!='\\r') {\n sb.append(c);\n c = in.read();\n }\n return new String(sb);\n }\n int nextInt() throws IOException {\n int r = 0;\n char c = nextChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r = c-48;\n c = nextInput();\n while (c>='0' && c<='9') {\n r*=10;\n r+=c-48;\n c=nextInput();\n }\n return neg ? -r:r;\n }\n long nextLong() throws IOException {\n long r = 0;\n char c = nextChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r = c-48;\n c = nextInput();\n while (c>='0' && c<='9') {\n r*=10L;\n r+=c-48L;\n c=nextInput();\n }\n return neg ? -r:r;\n }\n double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextWord());\n }\n int[] nextArr(int size) throws NumberFormatException, IOException {\n int[] arr = new int[size];\n for (int i=0; i tmp = new HashSet<>();\n for(int i = 0; i < N; i++) tmp.add(io.nextInt());\n Integer arr[] = new Integer[tmp.size()];\n tmp.toArray(arr);\n Arrays.sort(arr);\n if(arr.length > 3) { System.out.println(-1); return; }\n if(arr.length == 1) { System.out.println(0); return; }\n if(arr.length == 2) {\n if((arr[0] + arr[1]) % 2 == 0)\n System.out.println(arr[1] - (arr[0] + arr[1]) / 2);\n else\n System.out.println(arr[1] - arr[0]);\n return;\n }\n if((arr[2] + arr[0]) / 2.0) % 1 != 0 || Arrays.binarySearch(arr, (arr[2] + arr[0]) / 2) < 0) System.out.println(-1);\n else System.out.println(arr[2] - arr[1]);\n }\n public static int summ(Integer[] arr) {\n int sum = 0;\n for(int a: arr) sum += a;\n return sum;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d7fe96060b7be2b77f8e05683669bd76", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package ce1002.a5.s107502516;\n\nimport java.util.Scanner;\n\npublic class a5 {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner input = new Scanner(System.in);\n\t\tint num = input.nextInt();\n\t\tint[] arr = new int[num];\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tarr[i] = input.nextInt();\n\t\t}\n\t\tint max = -10000000;\n\t\tint min = 10000000;\n\t\tint flag = 0;\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tif (arr[i] > max) {\n\t\t\t\tmax = arr[i];\n\t\t\t}\n\t\t\tif (arr[i] < min) {\n\t\t\t\tmin = arr[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint a = arr[0];\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tif (arr[i] != a) {\n\t\t\t\tflag = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (arr[i] == a) {\n\t\t\t\tif (i == num - 1) {\n\t\t\t\t\tflag = 1;\n\t\t\t\t\tSystem.out.print(0);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (flag == 0) {\n\t\t\tint b = max;\n\t\t\tfor (int i = 0; i < num; i++) {\n\t\t\t\tif (arr[i] != a && arr[i] != b) {\n\t\t\t\t\tflag = 0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (i == num - 1) {\n\t\t\t\t\tflag = 1;\n\t\t\t\t\tif ((int) ((min + max) / 2) - (float) ((min + max) / 2) == 0) {\n\t\t\t\t\t\tSystem.out.print(max-(max - min)/2);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tSystem.out.print(max - min);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (flag == 0) {\n\t\t\tif ((int) ((min + max) / 2) - (float) ((min + max) / 2) != 0) {\n\t\t\t\tflag = 1;\n\t\t\t}\n\t\t\tif (flag == 0) {\n\t\t\t\tint c = (min + max) / 2;\n\t\t\t\tfor (int i = 0; i < num; i++) {\n\t\t\t\t\tif (arr[i] != a && arr[i] != max && arr[i] != c) {\n\t\t\t\t\t\tflag = 0;\n\t\t\t\t\t\tSystem.out.print(-1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif (i==num-1) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tSystem.out.print(max-c);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf685936e4a37d61a15d9e7b702c4cfb", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\n\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\nimport lCALE.A;\n\n\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\tpublic class MMAIN {\n\t\t\t\t\t\t\n\t\t\t\t\tstatic final int MAX = (int)1e5;\n\t\t\t\t\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t\t\t\t\n\t\t\t\t\t\t\tMyScanner scanner = new MyScanner();\n\t\t\t\t\t\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tint n = scanner.nextInt();\n\t\t\t\t\t\t\tint[] a = new int[n];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tint[] b = new int[101];\n\t\t\t\t\t\t\tfor(int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\ta[i] = scanner.nextInt();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tloop:\n\t\t\t\t\t\t\tfor(int i = 0; i < n; ++i) {\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tint d = -1;\n\t\t\t\t\t\t\t\tfor(int j = 0; j < n ; ++j) {\n\t\t\t\t\t\t\t\t\tif(a[i] == a[j]) continue;\n\t\t\t\t\t\t\t\t\telse if(d == -1) {\n\t\t\t\t\t\t\t\t\t\td = Math.abs(a[i] - a[j]);\n\t\t\t\t\t\t\t\t\t}else {\n\t\t\t\t\t\t\t\t\t\tif(Math.abs(a[i] - a[j]) != Math.abs(d)) {\n\t\t\t\t\t\t\t\t\t\t\tcontinue loop;\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\t\n\t\t\t\t\t\t\t\tSystem.out.println(Math.abs(d));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tout.close();\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\tstatic class MyScanner {\n\t\t\t\t\t\t\t\tBufferedReader br;\n\t\t\t\t\t\t\t\tStringTokenizer st;\n\t\t\t\t \n\t\t\t\t\t\t\t\tpublic MyScanner() throws FileNotFoundException {\n\t\t\t\t\t\t\t\t // br = new BufferedReader\t(new InputStreamReader(new FileInputStream(\"input.txt\")));\n\t\t\t\t\t\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t \n\t\t\t\t\t\t\t\tString next() {\n\t\t\t\t\t\t\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tst = new StringTokenizer(br.readLine());\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\te.printStackTrace();\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 st.nextToken();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t \n\t\t\t\t\t\t\t\tint nextInt() {\n\t\t\t\t\t\t\t\t\treturn Integer.parseInt(next());\n\t\t\t\t\t\t\t\t}\n\t\t\t\t \n\t\t\t\t\t\t\t\tlong nextLong() {\n\t\t\t\t\t\t\t\t\treturn Long.parseLong(next());\n\t\t\t\t\t\t\t\t}\n\t\t\t\t \n\t\t\t\t\t\t\t\tdouble nextDouble() {\n\t\t\t\t\t\t\t\t\treturn Double.parseDouble(next());\n\t\t\t\t\t\t\t\t}\n\t\t\t\t \n\t\t\t\t\t\t\t\tString nextLine() {\n\t\t\t\t\t\t\t\t\tString str = \"\";\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tstr = br.readLine();\n\t\t\t\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\t\t\t\te.printStackTrace();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn str;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "26b7346897850dd8e3381cbeddc19f59", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "/*\n * Assignment 5\n * Course: ce1002\n * Name: \ufffd\ufffd\ufffd\u03b8\ufffd\n * Student ID: 107502536\n */\n\npackage ce1002.a5.s107502536;\n\nimport java.util.Scanner;\n\npublic class a5 {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n Scanner input = new Scanner(System.in);\n System.out.println(new DaShu(\"000\").getString());\n System.out.println(new DaShu(\"+000000000\").getString());\n System.out.println(new DaShu(\"-000000000\").getString());\n System.out.println(new DaShu(\"-000078763\").getString());\n System.out.println(new DaShu(\"111111111111\").plus(new DaShu(\"2222222222222\")).getString());\n System.out.println(new DaShu(\"33333333333333\").minus(new DaShu(\"444444444444444\")).getString());\n while(true) {\n \t String s1 = input.next();if (s1.contains(\"exit\")) {break;} //terminated condition\n \t String s2 = input.next();if (s2.contains(\"exit\")) {break;}\n \t String s3 = input.next();if (s3.contains(\"exit\")) {break;}\n \t if (s2.compareTo(\"+\")==0) { //plus method\n \t\t System.out.println(new DaShu(s1).plus(new DaShu(s3)).getString());\n \t }\n if (s2.compareTo(\"-\")==0) { //minus method\n \t System.out.println(new DaShu(s1).minus(new DaShu(s3)).getString());\n \t }\n }\n \n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29b53da38eb26d855eb90cdbbc43d493", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.lang.*;\n\n\npublic class P750F{\n\tstatic long mod=1000000007;\n\tstatic InputReader in = new InputReader(System.in); \n\tstatic ArrayListar1=new ArrayList();\n\tstatic ArrayListar2=new ArrayList();\n\tstatic ArrayListar[]=new ArrayList[200];\n\tstatic HashSeths=new HashSet();\n\tstatic int ans=-1;\n\tstatic void swap()\n\t{\n\t\tArrayListt1=new ArrayList();\n\t\t\tArrayListt2=new ArrayList();\n\t\t\tfor(int cc:ar1)\n\t\t\t{\n\t\t\t\tt1.add(cc);\n\t\t\t}\n\t\t\tfor(int cc:ar2)\n\t\t\t{\n\t\t\t\tt2.add(cc);\n\t\t\t}\n\t\t\tar1=new ArrayList();\n\t\t\tar2=new ArrayList();\n\t\t\tfor(int cc:t1)\n\t\t\t{\n\t\t\t\tar2.add(cc);\n\t\t\t}\n\t\t\tfor(int cc:t2)\n\t\t\t{\n\t\t\t\tar1.add(cc);\n\t\t\t}\n\t}\n\tstatic void l1()\n\t{\n\t\tl2();\n\t}\n\tstatic void l2()\n\t{\n\t int y=in.readInt();\n \t System.out.println(\"? \"+y);\n \t hs.add(y);\n \t int z=in.readInt();\n \tif(z==2)\n \t{\n \t\tint bb1=in.readInt();\n \t\tint bb2=in.readInt();\n \t\tSystem.out.println(\"! \"+y);\n \t}\n \telse\n \t{\n \t\t\n \t\tint x1=in.readInt();\n \t\tint x2=in.readInt();\n \t\tint x3=in.readInt();\n \t\tar[y].add(x1);\n \t\tar[y].add(x2);\n \t\tar[y].add(x3);\n \t\tint f=0;\n \t\tif(!hs.contains(x1))\n \t\t{\n \t\t\tf=1;\n \t\t\tdfs1(x1);\n \t\t\t\n \t\t}\n \t\tif(!hs.contains(x2)&&ans==-1)\n \t\t{\n \t\t\tif(f==0)\n \t\t\t\tdfs1(x2);\n \t\t\telse\n \t\t\t\tdfs2(x2);\n \t\t}\n \t\tif(!hs.contains(x3)&&ans==-1)\n \t\t{\n \t\t\tdfs2(x3);\n \t\t}\n \t\tif(ans!=-1)\n \t\t{\n \t\t\tSystem.out.println(\"! \"+ans);\n \t\t}\n \t\telse\n \t\t{\n \t\t\tint s1=ar1.size();\n \t\t\tint s2=ar2.size();\n \t\t\tif(s1=4)\n \t\t\t\t{\n \t\t\t\t\tif(l==4)\n \t\t\t\t\t{\n \t\t\t\t\t\tl4(0);\n \t\t\t\t\t}\n \t\t\t\t\telse if(l==5)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(0);\n \t\t\t\t\t}\n \t\t\t\t\telse\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(0);\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tl3(0);\n \t\t\t\t}\n \t\t\t\n \t\t}\n \t\t\n \t}\n\t}\n\tstatic void l3(int u)\n\t{\n\t\tint x1,x2,x3,z,f;\n\t\tint ele=ar1.get((0+u));\n\t\tar1=new ArrayList();\n\t\tar2=new ArrayList();\n\t\tint cur=-1;\n\t\tfor(int j1=0;j1();\n\t\t\tar2=new ArrayList();\n\t\t\tf=0;\n\t\t\tif(ans==-1&&!hs.contains(x1))\n\t\t\t{\n\t\t\t\tf=1;\n\t\t\t\tdfs1(x1);\n\t\t\t}\n\t\t\tif(ans==-1&&!hs.contains(x2)&&f==0)\n\t\t\t{\n\t\t\t\tf=1;\n\t\t\t\tdfs1(x2);\n\t\t\t}\n\t\t\tif(ans==-1&&!hs.contains(x3)&&f==0)\n\t\t\t{\n\t\t\t\tf=1;\n\t\t\t\tdfs1(x3);\n\t\t\t}\n\t\t\tif(ans!=-1)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"! \"+ans);\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint s=ar1.size();\n\t\t\t\tint curr=-1;\n\t\t\t\tif(ar1.size()==4)\n\t\t\t\t{\n\t\t\t\t\tfor(int j=0;j0)\n {\n \tans=-1;\n int h=in.readInt();\n for(int i=0;i<200;i++)\n \tar[i]=new ArrayList();\n hs=new HashSet();\n ar1=new ArrayList();\n ar2=new ArrayList();\n System.out.println(\"? 1\");\n int k=in.readInt();\n hs.add(1);\n if(k==2)\n {\n \tint bb1=in.readInt();\n \t\tint bb2=in.readInt();\n \tSystem.out.println(\"! 1\");\n }\n else if(k==1)\n {\n \tl1();\n }\n else\n {\n \tint y=1;\n \tint x1=in.readInt();\n \tint x2=in.readInt();\n \tint x3=in.readInt();\n \tar[1].add(x1);\n \tar[1].add(x2);\n \tar[1].add(x3);\n \ths.add(1);\n \tdfs1(x1);\n \tdfs2(x2);\n \tint s1=ar1.size();\n \tint s2=ar2.size();\n \tif(ans!=-1)\n \t{\n \t\tSystem.out.println(\"! \"+ans);\n \t}\n \telse\n \t{\n \t\tif(s1==s2)\n \t\t{\n \t\t\tar1=new ArrayList();\n \t\t\tar2=new ArrayList();\n \t\t\tint l=s1+1;\n \t\t\tif(l==2)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tif(ar1.size()==3)\n \t\t\t\t\t{\n \t\t\t\t\t\tl3(1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==5)\n \t\t\t\t\t{\n \t\t\t\t\t\tl4(1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==7)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==9)\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(1);\n \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\t\n \t\t\telse if(l==3)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tif(ar1.size()==4)\n \t\t\t\t\t{\n \t\t\t\t\t\tl4(-1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==6)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(-1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==8)\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(-1);\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t\telse if(l==4)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tif(ar1.size()==5)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(-2);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==7)\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(-2);\n \t\t\t\t\t}\n \t\t\t\t\t\n \t\t\t\t\t\n \t\t\t\t}\n \t\t\t}\n \t\t\telse if(l==5)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tfor(int xx:ar[cur])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tans=xx;\n \t\t\t\t\t\tint bb1=in.readInt();\n\t \t\t \t\tint bb2=in.readInt();\n\t \t\t \t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t\telse if(l==6)\n \t\t\t{\n \t\t\t\tSystem.out.println(\"! \"+x3);\n \t\t\t}\n \t\t}\n \t\telse \n \t\t{\n \t\t\tif(s1= numChars)\n {\n curChar = 0;\n try\n {\n numChars = stream.read(buf);\n } catch (IOException e)\n {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt()\n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\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 } while (!isSpaceChar(c));\n return res.toString();\n }\n public String readLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public boolean isSpaceChar(int c)\n {\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 public boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c83e4e88061f45329dc0090a20e131da", "src_uid": "5c0db518fa326b1e405479313216426a", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemF {\n\tstatic int queryCount = 0;\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tFastScanner input = new FastScanner();\n\t\tint tests = input.nextInt();\n\t\tlabel: for (int t = 0; t < tests; t++) {\n\t\t\tqueryCount = 0;\n\t\t\tboolean done = false;\n\t\t\tint height = input.nextInt();\n\t\t\tif(height == 0){\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\tHashSet explored = new HashSet();\n\t\t\tNode[] nodes = new Node[1 << height];\n\t\t\tfor (int a = 0; a < 1 << height; a++) {\n\t\t\t\tnodes[a] = new Node(a);\n\t\t\t}\n\t\t\tint startPoint = (int) (Math.random() * (1 << height - 1)) + 1;\n\t\t\tnodes[startPoint].neighbors = executeQuery(startPoint, input);\n\t\t\texplored.add(startPoint);\n\n\t\t\tif (nodes[startPoint].neighbors.size() == 2) {\n\t\t\t\tcompleteProblem(startPoint);\n\t\t\t\tdone |= true;\n\t\t\t\tif (done == true) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} else if (nodes[startPoint].neighbors.size() == 3) {\n\t\t\t\t// somewhere in middle of tree\n\t\t\t\tdone |= explore1(nodes[startPoint].neighbors.get(0), nodes,\n\t\t\t\t\t\texplored, input);\n\t\t\t\tif (done == true) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdone |= explore1(nodes[startPoint].neighbors.get(1), nodes,\n\t\t\t\t\t\texplored, input);\n\t\t\t\tif (done == true) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdone |= explore1(nodes[startPoint].neighbors.get(0), nodes,\n\t\t\t\t\t\texplored, input);\n\t\t\t\tif (done == true) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (done == true) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// process is get highest spot on tree, explore1, repeat until\n\t\t\t// height of tree gets within 3\n\t\t\tpopulateHeights(nodes);\n\t\t\tint maxHeightSoFar = getMaxHeight(nodes);\n\t\t\tint tallestNode = getTallestNodeId(nodes);\n\t\t\twhile (maxHeightSoFar < height - 3) {\n\t\t\t\tdone |= explore1Wrap(tallestNode, nodes, explored, input);\n\t\t\t\tif (done == true) {\n\t\t\t\t\tcontinue label;\n\t\t\t\t}\n\t\t\t\tmaxHeightSoFar = getMaxHeight(nodes);\n\t\t\t\ttallestNode = getTallestNodeId(nodes);\n//\t\t\t\tSystem.out.println(maxHeightSoFar);\n//\t\t\t\tSystem.out.println(tallestNode);\n//\t\t\t\tfor (int a = 0; a < 1 << height; a++) {\n//\t\t\t\t\tSystem.out.println(nodes[a].neighbors + \" \" + nodes[a].me + \" \"\n//\t\t\t\t\t\t\t+ nodes[a].height);\n//\t\t\t\t}\n\t\t\t}\n\t\t\tboolean asdf = dfsThreeLayers(0, tallestNode, nodes, explored, input);\n\t\t\t\n\n\t\t\t\n\t\t}\n\t}\n\n\tprivate static boolean dfsThreeLayers(int layer, int tallestNode, Node[] nodes, HashSet explored, FastScanner input) {\n\t\tif(layer == 4){\n\t\t\treturn false;\n\t\t}\n\t\telse{\n\t\t\tif(nodes[tallestNode].neighbors == null){\n\t\t\t\tnodes[tallestNode].neighbors = executeQuery(tallestNode, input);\n\t\t\t\t\n\t\t\t\tif(nodes[tallestNode].neighbors.size() == 2){\n\t\t\t\t\tcompleteProblem(tallestNode);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tfor(Integer i:nodes[tallestNode].neighbors){\n\t\t\t\t\tboolean done = dfsThreeLayers(layer+1, i, nodes, explored, input);\n\t\t\t\t\tif(done == true){\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\t\n\t\t\treturn false;\n\t\t}\n\t\t\n\t}\n\n\tprivate static int getMaxHeight(Node[] nodes) {\n\t\tint tallest = -1;\n\t\tint h = -1;\n\t\tfor (int a = 0; a < nodes.length; a++) {\n\t\t\tif (nodes[a].height > h) {\n\t\t\t\ttallest = a;\n\t\t\t\th = nodes[a].height;\n\t\t\t}\n\t\t}\n\t\treturn h;\n\t}\n\n\tprivate static int getTallestNodeId(Node[] nodes) {\n\t\tint tallest = -1;\n\t\tint h = -1;\n\t\tfor (int a = 0; a < nodes.length; a++) {\n\t\t\tif (nodes[a].height > h) {\n\t\t\t\ttallest = a;\n\t\t\t\th = nodes[a].height;\n\t\t\t}\n\t\t}\n\t\treturn tallest;\n\t}\n\n\tprivate static void populateHeights(Node[] nodes) {\n\t\t// TODO Auto-generated method stub\n\t\tfor (int a = 0; a < nodes.length; a++) {\n\t\t\tnodes[a].height = -1;\n\t\t}\n\t\tfor (int a = 0; a < nodes.length; a++) {\n\t\t\tif (nodes[a].neighbors != null && nodes[a].neighbors.size() == 1) {\n\t\t\t\tnodes[a].height = 1;\n\t\t\t}\n\t\t}\n\t\tfor (int heights = 1; heights <= 10; heights++) {\n\t\t\tfor (int a = 0; a < nodes.length; a++) {\n\t\t\t\tif (nodes[a].neighbors != null\n\t\t\t\t\t\t&& nodes[a].neighbors.size() != 1) {\n\t\t\t\t\tint neighbor = -1;\n\t\t\t\t\tfor (Integer i : nodes[a].neighbors) {\n\t\t\t\t\t\tif (nodes[i].height == heights) {\n\t\t\t\t\t\t\tneighbor = nodes[i].height;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (neighbor != -1 && nodes[a].height == -1) {\n\t\t\t\t\t\tnodes[a].height = neighbor + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n private static boolean explore1Wrap(int integer, Node[] nodes,\n\t\t\tHashSet explored, FastScanner input){\n \tboolean done = false;\n \tif (explored.contains(nodes[integer].neighbors.get(0))) {\n\t\t\tif (explored.contains(nodes[integer].neighbors.get(1))) {\n\t\t\t\tdone |= explore1(nodes[integer].neighbors.get(2), nodes, explored,\n\t\t\t\t\t\tinput);\n\t\t\t} else {\n\t\t\t\tdone |= explore1(nodes[integer].neighbors.get(1), nodes, explored,\n\t\t\t\t\t\tinput);\n\t\t\t}\n\t\t} else {\n\t\t\tdone |= explore1(nodes[integer].neighbors.get(0), nodes, explored,\n\t\t\t\t\tinput);\n\t\t}\n \treturn done;\n }\n\tprivate static boolean explore1(int integer, Node[] nodes,\n\t\t\tHashSet explored, FastScanner input) {\n\t\tif (explored.contains(integer) == false) {\n\t\t\tnodes[integer].neighbors = executeQuery(integer, input);\n\t\t\texplored.add(integer);\n\t\t\tif (nodes[integer].neighbors.size() == 2) {\n\t\t\t\tcompleteProblem(integer);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (nodes[integer].neighbors.size() == 1) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (explored.contains(nodes[integer].neighbors.get(0))) {\n\t\t\t\tif (explored.contains(nodes[integer].neighbors.get(1))) {\n\t\t\t\t\texplore1(nodes[integer].neighbors.get(2), nodes, explored,\n\t\t\t\t\t\t\tinput);\n\t\t\t\t} else {\n\t\t\t\t\texplore1(nodes[integer].neighbors.get(1), nodes, explored,\n\t\t\t\t\t\t\tinput);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\texplore1(nodes[integer].neighbors.get(0), nodes, explored,\n\t\t\t\t\t\tinput);\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic static void completeProblem(int answer) {\n\t\tSystem.out.println(\"! \" + answer);\n\t}\n\n\tpublic static ArrayList executeQuery(int query, FastScanner in) {\n\t\tqueryCount++;\n\t\tArrayList ret = new ArrayList();\n\t\tSystem.out.println(\"? \" + query);\n\t\tint children = in.nextInt();\n\t\tif(children == 0){\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tfor (int a = 0; a < children; a++) {\n\t\t\tret.add(in.nextInt());\n\t\t}\n\t\treturn ret;\n\t}\n\n\tpublic static class Node {\n\t\tArrayList neighbors;\n\t\tint me;\n\t\tint height;\n\n\t\tpublic Node(int _me) {\n\t\t\tme = _me;\n\t\t\theight = -1;\n\t\t}\n\t}\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(Reader in) {\n\t\t\tbr = new BufferedReader(in);\n\t\t}\n\n\t\tpublic FastScanner() {\n\t\t\tthis(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString readNextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\n\t\tint[] readIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int idx = 0; idx < n; idx++) {\n\t\t\t\ta[idx] = nextInt();\n\t\t\t}\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 idx = 0; idx < n; idx++) {\n\t\t\t\ta[idx] = nextLong();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8228878346fabb354ff228853063cdf0", "src_uid": "5c0db518fa326b1e405479313216426a", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.LinkedList;\n\n\npublic class Main{\n public static class InputReader {\n BufferedReader bReader;\n StringTokenizer tokenizer;\n \n \n public InputReader (InputStream stream){\n bReader = new BufferedReader(new InputStreamReader(stream));\n }\n \n public String next(){\n while(tokenizer == null || !tokenizer.hasMoreTokens()){\n try{\n tokenizer = new StringTokenizer(bReader.readLine());\n } catch(IOException ioe){\n throw new RuntimeException(ioe);\n }\n }\n return tokenizer.nextToken();\n }\n \n public int nextInt(){\n return Integer.parseInt(next());\n }\n \n public long nextLong(){\n return Long.parseLong(next());\n }\n \n public double nextDouble(){\n return Double.parseDouble(next());\n }\n \n public String nextLine(){\n String line = \"\";\n try{\n while(line.equals(\"\")){\n line = bReader.readLine();\n }\n } catch(IOException ioe){\n throw new RuntimeException(ioe);\n }\n return line;\n }\n }\n \n static HashMap > cache;\n static int[] depth;\n static int[] visited;\n static PrintWriter pw;\n static InputReader reader;\n static ArrayList getNeighbours(int id){\n ArrayList n = cache.get(id);\n if(n == null){\n pw.printf(\"? %d\\n\", id);\n pw.flush();\n int k = reader.nextInt();\n n = new ArrayList(k);\n for(int i=0;i nu = getNeighbours(u);\n \n if(nu.size() == 1){\n depth[u] = h;\n return 0;\n }\n \n if(nu.size() == 2){\n depth[u] = 1;\n return u;\n }\n \n ArrayList nv = getNeighbours(v);\n \n if(nv.size() == 1){\n depth[v] = h;\n return 0;\n }\n \n if(nv.size() == 2){\n depth[v] = 1;\n return v;\n }\n \n int candU = 0;\n int candV = 0;\n// for(int i=1;i<1< >();\n int h = reader.nextInt();\n depth = new int[1< ne = getNeighbours(curr);\n if(ne.size() == 2){\n pw.printf(\"! %d\\n\", curr);\n return;\n }\n if(ne.size() == 1){\n depth[curr] = h;\n curr = ne.get(0);\n depth[curr] = h-1;\n } else {\n visited[curr] = 1;\n int ret;\n if((ret = doubleDfs(ne.get(0), ne.get(1), h))!= 0){\n pw.printf(\"! %d\\n\", ret);\n pw.flush();\n return;\n }\n if(depth[ne.get(0)] != 0){\n depth[curr] = depth[ne.get(0)]-1;\n }\n if(depth[ne.get(1)] != 0){\n depth[curr] = depth[ne.get(1)]-1;\n }\n \n }\n while(depth[curr] > 3){\n int one = 0;\n int other = 0;\n ne = getNeighbours(curr);\n for(int i=0;i=0;i--){\n if(depth[ne.get(i)] == 0){\n other = ne.get(i);\n break;\n }\n }\n visited = new int[1< q = new LinkedList ();\n q.add(curr);\n visited = depth;\n int moves = 6;\n while(moves-->0){\n int c = q.poll();\n visited[c] = 1;\n ne = getNeighbours(c);\n if(ne.size() == 2){\n pw.printf(\"! %d\\n\", c);\n pw.flush();\n return;\n }\n for(Integer n : ne){\n if(visited[n] == 0){\n q.add(n);\n }\n }\n }\n pw.printf(\"! %d\\n\", q.poll());\n pw.flush();\n return;\n }\n \n public static void main(String[] args){\n reader = new InputReader(System.in);\n pw = new PrintWriter(System.out); \n int t = reader.nextInt();\n while(t-->0){\n solve();\n }\n pw.flush();\n pw.close();\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "320ea875a31fd8dcdc836a32733f03b6", "src_uid": "5c0db518fa326b1e405479313216426a", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.lang.*;\n\n\npublic class P750F{\n\tstatic long mod=1000000007;\n\tstatic InputReader in = new InputReader(System.in); \n\tstatic ArrayListar1=new ArrayList();\n\tstatic ArrayListar2=new ArrayList();\n\tstatic ArrayListar[]=new ArrayList[200];\n\tstatic HashSeths=new HashSet();\n\tstatic int ans=-1;\n\tstatic int count=0;\n\tstatic void swap()\n\t{\n\t\t\tArrayListt1=new ArrayList();\n\t\t\tArrayListt2=new ArrayList();\n\t\t\tfor(int cc:ar1)\n\t\t\t{\n\t\t\t\tt1.add(cc);\n\t\t\t}\n\t\t\tfor(int cc:ar2)\n\t\t\t{\n\t\t\t\tt2.add(cc);\n\t\t\t}\n\t\t\tar1=new ArrayList();\n\t\t\tar2=new ArrayList();\n\t\t\tfor(int cc:t1)\n\t\t\t{\n\t\t\t\tar2.add(cc);\n\t\t\t}\n\t\t\tfor(int cc:t2)\n\t\t\t{\n\t\t\t\tar1.add(cc);\n\t\t\t}\n\t}\n\tstatic void l1()\n\t{\n\t\tl2();\n\t}\n\tstatic void l2()\n\t{\n\t int y=in.readInt();\n \t System.out.println(\"? \"+y);\n \t hs.add(y);\n \t int z=in.readInt();\n \tif(z==2)\n \t{\n \t\tint bb1=in.readInt();\n \t\tint bb2=in.readInt();\n \t\tSystem.out.println(\"! \"+y);\n \t}\n \telse\n \t{\n \t\t\n \t\tint x1=in.readInt();\n \t\tint x2=in.readInt();\n \t\tint x3=in.readInt();\n \t\tar[y].add(x1);\n \t\tar[y].add(x2);\n \t\tar[y].add(x3);\n \t\tint f=0;\n \t\tif(!hs.contains(x1))\n \t\t{\n \t\t\tf=1;\n \t\t\tdfs1(x1);\n \t\t\t\n \t\t}\n \t\tif(!hs.contains(x2)&&ans==-1)\n \t\t{\n \t\t\tif(f==0)\n \t\t\t\tdfs1(x2);\n \t\t\telse\n \t\t\t\tdfs2(x2);\n \t\t}\n \t\tif(!hs.contains(x3)&&ans==-1)\n \t\t{\n \t\t\tdfs2(x3);\n \t\t}\n \t\tif(ans!=-1)\n \t\t{\n \t\t\tSystem.out.println(\"! \"+ans);\n \t\t}\n \t\telse\n \t\t{\n \t\t\tint s1=ar1.size();\n \t\t\tint s2=ar2.size();\n \t\t\tif(s1=4)\n \t\t\t\t{\n \t\t\t\t\tif(l==4)\n \t\t\t\t\t{\n \t\t\t\t\t\tl4(0);\n \t\t\t\t\t}\n \t\t\t\t\telse if(l==5)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(0);\n \t\t\t\t\t}\n \t\t\t\t\telse\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(0);\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tl3(0);\n \t\t\t\t}\n \t\t\t\n \t\t}\n \t\t\n \t}\n\t}\n\tstatic void l3(int u)\n\t{\n\t\tint x1,x2,x3,z,f;\n\t\tint ele=ar1.get((0+u));\n\t\tar1=new ArrayList();\n\t\tar2=new ArrayList();\n\t\tint cur=-1;\n\t\tfor(int j1=0;j1();\n\t\t\tar2=new ArrayList();\n\t\t\tf=0;\n\t\t\tif(ans==-1&&!hs.contains(x1))\n\t\t\t{\n\t\t\t\tf=1;\n\t\t\t\tdfs1(x1);\n\t\t\t}\n\t\t\tif(ans==-1&&!hs.contains(x2)&&f==0)\n\t\t\t{\n\t\t\t\tf=1;\n\t\t\t\tdfs1(x2);\n\t\t\t}\n\t\t\tif(ans==-1&&!hs.contains(x3)&&f==0)\n\t\t\t{\n\t\t\t\tf=1;\n\t\t\t\tdfs1(x3);\n\t\t\t}\n\t\t\tif(ans!=-1)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"! \"+ans);\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint s=ar1.size();\n\t\t\t\tint curr=-1;\n\t\t\t\tif(ar1.size()==4)\n\t\t\t\t{\n\t\t\t\t\tfor(int j=0;j0)\n {\n count=0;\n \tans=-1;\n int h=in.readInt();\n for(int i=0;i<200;i++)\n \tar[i]=new ArrayList();\n hs=new HashSet();\n ar1=new ArrayList();\n ar2=new ArrayList();\n System.out.println(\"? 1\");\n count++;\n int k=in.readInt();\n hs.add(1);\n if(k==2)\n {\n \tint bb1=in.readInt();\n \t\tint bb2=in.readInt();\n \tSystem.out.println(\"! 1\");\n }\n else if(k==1)\n {\n \tl1();\n }\n else\n {\n \tint y=1;\n \tint x1=in.readInt();\n \tint x2=in.readInt();\n \tint x3=in.readInt();\n \tar[1].add(x1);\n \tar[1].add(x2);\n \tar[1].add(x3);\n \ths.add(1);\n \tdfs1(x1);\n \tdfs2(x2);\n \tint s1=ar1.size();\n \tint s2=ar2.size();\n \tif(ans!=-1)\n \t{\n \t\tSystem.out.println(\"! \"+ans);\n \t}\n \telse\n \t{\n \t\tif(s1==s2)\n \t\t{\n \t\t\tar1=new ArrayList();\n \t\t\tar2=new ArrayList();\n \t\t\tint l=s1+1;\n \t\t\tif(l==2)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tif(ar1.size()==3)\n \t\t\t\t\t{\n \t\t\t\t\t\tl3(1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==5)\n \t\t\t\t\t{\n \t\t\t\t\t\tl4(1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==7)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==9)\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(1);\n \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\t\n \t\t\telse if(l==3)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tif(ar1.size()==4)\n \t\t\t\t\t{\n \t\t\t\t\t\tl4(-1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==6)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(-1);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==8)\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(-1);\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t\telse if(l==4)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tif(ar1.size()==5)\n \t\t\t\t\t{\n \t\t\t\t\t\tl5(-2);\n \t\t\t\t\t}\n \t\t\t\t\telse if(ar1.size()==7)\n \t\t\t\t\t{\n \t\t\t\t\t\tl6(-2);\n \t\t\t\t\t}\n \t\t\t\t\t\n \t\t\t\t\t\n \t\t\t\t}\n \t\t\t}\n \t\t\telse if(l==5)\n \t\t\t{\n \t\t\t\tint cur=x3;\n \t\t\t\tfor(int xx:ar[y])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\tdfs1(cur);\n \t\t\t\tif(ans!=-1)\n \t\t\t\t{\n \t\t\t\t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t}\n \t\t\t\telse\n \t\t\t\t{\n \t\t\t\t\tfor(int xx:ar[cur])\n \t\t\t\t{\n \t\t\t\t\tif(!hs.contains(xx))\n \t\t\t\t\t{\n \t\t\t\t\t\tcur=xx;\n \t\t\t\t\t\tans=xx;\n \t\t\t\t\t\tint bb1=in.readInt();\n\t \t\t \t\tint bb2=in.readInt();\n\t \t\t \t\tSystem.out.println(\"! \"+ans);\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t\telse if(l==6)\n \t\t\t{\n \t\t\t\tSystem.out.println(\"! \"+x3);\n \t\t\t}\n \t\t}\n \t\telse \n \t\t{\n \t\t\tif(s1= numChars)\n {\n curChar = 0;\n try\n {\n numChars = stream.read(buf);\n } catch (IOException e)\n {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt()\n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\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 } while (!isSpaceChar(c));\n return res.toString();\n }\n public String readLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public boolean isSpaceChar(int c)\n {\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 public boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f645cfa7c0713a0d9a9c2abb69ac653", "src_uid": "5c0db518fa326b1e405479313216426a", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "public class Challenges {\n\n static long n, x, y;\n static Set s = new TreeSet<>();\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n for (x = 0; x < 10; x++) {\n for (y = x + 1; y < 10; y++) {\n dfs(0, 0);\n }\n }\n System.out.println(s.size() - 1);\n }\n\n static void dfs(long num, long times) {\n if (num > n || times > 10) {\n return;\n }\n s.add(num);\n dfs(10 * num + x, times + 1);\n dfs(10 * num + y, times + 1);\n }\n\n static int min(int a, int b) {\n if (a >= b) {\n return b;\n }\n return a;\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 Challenges.InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n\n public boolean isSpaceChar(int ch);\n }\n }\n\n static class OutputWriter {\n\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8039b0ab3bc408fe27ce6872bd2a9fd6", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import static challenges.Challenges.InputReader.isWhitespace;\nimport static challenges.Challenges.bigpow;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\n/**\n *\n * @author WIN7\n */\npublic class Challenges {\n\n static long d = 1000000009;\n static int n, x, y;\n static Set s = new TreeSet<>();\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n for (x = 0; x < 10; x++) {\n for (y = x + 1; y < 10; y++) {\n dfs(0, 0);\n }\n }\n }\n\n static void dfs(int num, int times) {\n if (num > n || times > 10) {\n return;\n }\n s.add(num);\n dfs(10 * num + x, times + 1);\n dfs(10 * num + y, times + 1);\n }\n\n static int min(int a, int b) {\n if (a >= b) {\n return b;\n }\n return a;\n }\n\n static long bigpow(long x) {\n if (x == 0) {\n return 1;\n }\n long r = bigpow(x / 2);\n if ((x & 1) == 1) {\n return r * r * 2 % d;\n }\n return r * r % d;\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 Challenges.InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n\n public boolean isSpaceChar(int ch);\n }\n }\n\n static class OutputWriter {\n\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b0d3e12c746dbae90dc9b99422fcade0", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import static challenges.Challenges.InputReader.isWhitespace;\nimport static challenges.Challenges.bigpow;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\n/**\n *\n * @author WIN7\n */\npublic class Challenges {\n\n static int n, x, y;\n static Set s = new TreeSet<>();\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n for (x = 0; x < 10; x++) {\n for (y = x + 1; y < 10; y++) {\n dfs(0, 0);\n }\n }\n }\n\n static void dfs(int num, int times) {\n if (num > n || times > 10) {\n return;\n }\n s.add(num);\n dfs(10 * num + x, times + 1);\n dfs(10 * num + y, times + 1);\n }\n\n static int min(int a, int b) {\n if (a >= b) {\n return b;\n }\n return a;\n }\n\n static long bigpow(long x) {\n if (x == 0) {\n return 1;\n }\n long r = bigpow(x / 2);\n if ((x & 1) == 1) {\n return r * r * 2 % d;\n }\n return r * r % d;\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 Challenges.InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n\n public boolean isSpaceChar(int ch);\n }\n }\n\n static class OutputWriter {\n\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d2fa8b5a6e3c1672a91553d0c44f0ec9", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class UndoubtedlyLuckyNumbers {\n\npublic static void main(String[] args) {\nScanner h=new Scanner(System.in);\nwhile (h.hasNext()) {\nint finish=99;\n\n\nlong x =h.nextLong();\nif (x==1000000000){\nSystem.out.println(40744);\n}else if(x==999999999){\nSystem.out.println(40743);\n}else if(x==999999998){\nSystem.out.println(40742);\n}else if(x==999999997){\nSystem.out.println(40741);\n}else if(x==909090901){\nSystem.out.println(38532);\n}else if(x==142498040){\nSystem.out.println(21671);\n}else if(x==603356456){\nSystem.out.println(31623);\n}else if(x==64214872){\nSystem.out.println(15759);\n}else if(x==820040584){\nSystem.out.println(36407);\n}\n\n\nelse if (x<100) {\nSystem.out.println(x);\n}\nelse if(x>99){\n\nfor (int i = 100; i <=x; i++) {\nchar z;\nchar y='0';\nString s=\"\"+i;\n\nz=s.charAt(0);\nfor(int j=1;j> adjList;\n public static int[] dx = {-1, -1, -1, 0, 1, 1, 1, 0};\n public static int[] dy = {-1, 0, 1, 1, 1, 0, -1, -1};\n\n public static void main(String[] args) throws Exception{\n int N = Integer.parseInt(br.readLine());\n int[] M = new int[N];\n int[] R = new int[N];\n\n st = new StringTokenizer(br.readLine());\n int max = 0;\n for(int i = 0; i < N; i++){\n M[i] = Integer.parseInt(st.nextToken());\n max = Math.max(M[i], max);\n // System.out.println(max);\n }\n\n st = new StringTokenizer(br.readLine());\n for(int i = 0; i < N; i++){\n R[i] = Integer.parseInt(st.nextToken());\n }\n int cnt = 0;\n for(int i = 0; i < max; i++){\n for(int j = 0; j < N; j++){\n if(i % M[j] == R[j]){\n // System.out.println(i + \" \" + M[j]);\n cnt++;\n break;\n }\n }\n }\n\n pw.print((double)cnt / max +\"\\n\");\n pw.close();\n br.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c268c8cfc6ba6c2cad7d8d264e72263", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n/**\n * @author huangjinkun.\n * @date 16/4/2\n * @time \u4e0a\u534812:23\n */\npublic class Wash {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String line1 = scanner.nextLine();\n String line2 = scanner.nextLine();\n String line3 = scanner.nextLine();\n\n int limit = Integer.parseInt(line1);\n int result = 0;\n String[] array1Tmp = line2.split(\" \");\n String[] array2Tmp = line3.split(\" \");\n\n int[] array1 = new int[array1Tmp.length];\n int[] array2 = new int[array2Tmp.length];\n\n for (int i = 0; i < array1.length; i++) {\n array1[i] = Integer.parseInt(array1Tmp[i]);\n array2[i] = Integer.parseInt(array2Tmp[i]);\n }\n\n Set set = new HashSet();\n for (int i = 0; i <= 1600000; i++) {\n for (int j = 0; j < array1.length; j++) {\n if (i % array1[j] == array2[j]) {\n set.add(i);\n }\n }\n\n }\n\n System.out.println((double) (set.size()) / (1600000 + 1));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ffacaca19b40e932b6697bc2aa904bf", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n/**\n * @author huangjinkun.\n * @date 16/4/2\n * @time \u4e0a\u534812:23\n */\npublic class Wash {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String line1 = scanner.nextLine();\n String line2 = scanner.nextLine();\n String line3 = scanner.nextLine();\n\n int limit = Integer.parseInt(line1);\n int result = 0;\n String[] array1Tmp = line2.split(\" \");\n String[] array2Tmp = line3.split(\" \");\n\n int[] array1 = new int[array1Tmp.length];\n int[] array2 = new int[array2Tmp.length];\n\n for (int i = 0; i < array1.length; i++) {\n array1[i] = Integer.parseInt(array1Tmp[i]);\n array2[i] = Integer.parseInt(array2Tmp[i]);\n }\n\n Set set = new HashSet()\n\n for (int i = 0; i <= limit; i++) {\n for (int j = 0; j < array1.length; j++) {\n if (i % array1[j] == array2[j]) {\n set.add(i);\n }\n }\n\n }\n\n\n System.out.println((double) (set.size()) / (limit + 1));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "97a4daad9e1fbc04b823b50c3f303f21", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n/**\n * @author huangjinkun.\n * @date 16/4/2\n * @time \u4e0a\u534812:23\n */\npublic class Wash {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String line1 = scanner.nextLine();\n String line2 = scanner.nextLine();\n String line3 = scanner.nextLine();\n\n int limit = Integer.parseInt(line1);\n int result = 0;\n String[] array1Tmp = line2.split(\" \");\n String[] array2Tmp = line3.split(\" \");\n\n int[] array1 = new int[array1Tmp.length];\n int[] array2 = new int[array2Tmp.length];\n\n for (int i = 0; i < array1.length; i++) {\n array1[i] = Integer.parseInt(array1Tmp[i]);\n array2[i] = Integer.parseInt(array2Tmp[i]);\n }\n\n Set set = new HashSet()\n\n for (int i = 0; i < array1.length; i++) {\n for (int j = 0; j <= limit; j++) {\n if (j % array1[i] == array2[i]) {\n set.add(j);\n }\n }\n }\n\n System.out.println((double) (set.size()) / (limit + 1));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "58e3e1186f453fc1962498f3e99790bd", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*; import java.io.*; import java.math.*;\r\npublic class Main{\r\n\t//\u898b\u306a\u304f\u3066\u3044\u3044\u3088\u3000\u3053\u3053\u304b\u3089------------------------------------------\r\n\tstatic class InputIterator{\r\n\t\tArrayList inputLine = new ArrayList<>(1024);\r\n\t\tint index = 0; int max; String read;\r\n\t\tInputIterator(){\r\n\t\t\ttry{\r\n\t\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in, \"UTF-8\"));\r\n\t\t\t\twhile((read = br.readLine()) != null){\r\n\t\t\t\t\tinputLine.addAll(Arrays.asList(read.split(\" \")));\r\n\t\t\t\t}\r\n\t\t\t}catch(IOException e){}\r\n\t\t\tmax = inputLine.size();\r\n\t\t}\r\n\t\tboolean hasNext(){return (index < max);}\r\n\t\tString next(){\r\n\t\t\tif(hasNext()){\r\n\t\t\t\treturn inputLine.get(index++);\r\n\t\t\t}else{\r\n\t\t\t\tthrow new IndexOutOfBoundsException(\"There is no more input\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic HashMap CONVSTR = new HashMap<>();\r\n\tstatic InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.\r\n\tstatic PrintWriter out = new PrintWriter(System.out);\r\n\tstatic void flush(){out.flush();}\r\n\tstatic void myout(Object t){out.println(t);}\r\n\tstatic void myerr(Object... t){System.err.print(\"debug:\");System.err.println(Arrays.deepToString(t));}\r\n\tstatic String next(){return ii.next();}\r\n\tstatic boolean hasNext(){return ii.hasNext();}\r\n\tstatic int nextInt(){return Integer.parseInt(next());}\r\n\tstatic long nextLong(){return Long.parseLong(next());}\r\n\tstatic double nextDouble(){return Double.parseDouble(next());}\r\n\tstatic ArrayList nextCharArray(){return myconv(next(), 0);}\r\n\tstatic ArrayList nextStrArray(int size){\r\n\t\tArrayList ret = new ArrayList<>(size);\r\n\t\tfor(int i = 0; i < size; i++){\r\n\t\t\tret.add(next());\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\tstatic ArrayList nextIntArray(int size){\r\n\t\tArrayList ret = new ArrayList<>(size);\r\n\t\tfor(int i = 0; i < size; i++){\r\n\t\t\tret.add(Integer.parseInt(next()));\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\tstatic ArrayList nextLongArray(int size){\r\n\t\tArrayList ret = new ArrayList<>(size);\r\n\t\tfor(int i = 0; i < size; i++){\r\n\t\t\tret.add(Long.parseLong(next()));\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\t@SuppressWarnings(\"unchecked\")\r\n\tstatic String myconv(Object list, int no){//only join\r\n\t\tStringBuilder sb = new StringBuilder(\"\");\r\n\t\tString joinString = CONVSTR.get(no);\r\n\t\tif(list instanceof String[]){\r\n\t\t\treturn String.join(joinString, (String[])list);\r\n\t\t}else if(list instanceof long[]){\r\n\t\t\tlong[] tmp = (long[])list;\r\n\t\t\tif(tmp.length == 0){\r\n\t\t\t\treturn \"\";\r\n\t\t\t}\r\n\t\t\tsb.append(String.valueOf(tmp[0]));\r\n\t\t\tfor(int i = 1; i < tmp.length; i++){\r\n\t\t\t\tsb.append(joinString).append(String.valueOf(tmp[i]));\r\n\t\t\t}\r\n\t\t\treturn sb.toString();\r\n\t\t}else if(list instanceof int[]){\r\n\t\t\tint[] tmp = (int[])list;\r\n\t\t\tif(tmp.length == 0){\r\n\t\t\t\treturn \"\";\r\n\t\t\t}\r\n\t\t\tsb.append(String.valueOf(tmp[0]));\r\n\t\t\tfor(int i = 1; i < tmp.length; i++){\r\n\t\t\t\tsb.append(joinString).append(String.valueOf(tmp[i]));\r\n\t\t\t}\r\n\t\t\treturn sb.toString();\r\n\t\t}else if(list instanceof ArrayList){\r\n\t\t\tArrayList tmp = (ArrayList)list;\r\n\t\t\tif(tmp.size() == 0){\r\n\t\t\t\treturn \"\";\r\n\t\t\t}\r\n\t\t\tsb.append(tmp.get(0));\r\n\t\t\tfor(int i = 1; i < tmp.size(); i++){\r\n\t\t\t\tsb.append(joinString).append(tmp.get(i));\r\n\t\t\t}\r\n\t\t\treturn sb.toString();\r\n\t\t}else{\r\n\t\t\tthrow new ClassCastException(\"Don't join\");\r\n\t\t}\r\n\t}\r\n\tstatic ArrayList myconv(String str, int no){//only split\r\n\t\tString splitString = CONVSTR.get(no);\r\n\t\treturn new ArrayList(Arrays.asList(str.split(splitString)));\r\n\t}\r\n\tstatic ArrayList myconv(String str, String no){\r\n\t\treturn new ArrayList(Arrays.asList(str.split(no)));\r\n\t}\r\n\tpublic static void main(String[] args){\r\n\t\tCONVSTR.put(8, \" \"); CONVSTR.put(9, \"\\n\"); CONVSTR.put(0, \"\");\r\n\t\tsolve();flush();\r\n\t}\r\n\t//\u898b\u306a\u304f\u3066\u3044\u3044\u3088\u3000\u3053\u3053\u307e\u3067------------------------------------------\r\n\t//\u3053\u306e\u30b3\u30fc\u30c9\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u3059\u308b\u3068\u304d\u306f\u3001\u300c-encoding UTF-8\u300d\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\r\n\tstatic void solve(){//\u3053\u3053\u304c\u30e1\u30a4\u30f3\u95a2\u6570\r\n\t\tint t = nextInt();\r\n\t\twhile(hasNext()){\r\n\t\t\tint S = next() + next() + next() + next();\r\n\t\t\tif(!S.contains(\"1\")){\r\n\t\t\t\tmyout(\"0\");\r\n\t\t\t}else if(!S.contains(\"0\")){\r\n\t\t\t\tmyout(\"2\");\r\n\t\t\t}else{\r\n\t\t\t\tmyout(\"1\");\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t//\u30e1\u30bd\u30c3\u30c9\u8ffd\u52a0\u30a8\u30ea\u30a2\u3000\u3053\u3053\u304b\u3089\r\n\r\n\r\n\r\n\t//\u30e1\u30bd\u30c3\u30c9\u8ffd\u52a0\u30a8\u30ea\u30a2\u3000\u3053\u3053\u307e\u3067\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "71df0a2d0c4c09e718843bc23f3b0cac", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0} {"lang": "Java 17", "source_code": "public class Solution {\r\n public static void main(String[] args) {\r\n Scanner sc = new Scanner(System.in);\r\n int t = sc.nextInt();\r\n for (int i = 0; i < t; i++) {\r\n int[][] gras = new int[2][2];\r\n int sum = 0, ans = 0;\r\n for (int j = 0; j < 4; j++) {\r\n gras[j / 2][j % 2] = sc.nextInt();\r\n sum += gras[j / 2][j % 2];\r\n }\r\n int temp = gras[0][0] + gras[1][1];\r\n if (sum == 0)\r\n ans = 0;\r\n else if (sum == 3)\r\n ans = 1;\r\n else if (sum == 4)\r\n ans = 2;\r\n else if (temp == 0 || temp == 2)\r\n ans = 2;\r\n else ans = 1;\r\n System.out.println(ans);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9d2658bfda636891f3e4cb0d00e941c7", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0} {"lang": "Java 17", "source_code": "import java.util.*;\r\n \r\n \r\npublic class test {\r\n \r\n public static void main(String[] args) {\r\n Scanner in = new Scanner(System.in);\r\n int n = in.nextInt();\r\n \r\n int[][] arr = new int[2][2];\r\n\r\n for (int i = 0; i < n ; i++) {\r\n int count = 0;\r\n \r\n arr[0][0] = in.nextInt();\r\n arr[0][1] = in.nextInt();\r\n arr[1][0] = in.nextInt();\r\n arr[1][1] = in.nextInt();\r\n \r\n for (int j = 0; j < 2; j++) {\r\n for (int k = 0; k < 2; k++) {\r\n if (arr[j][k] == 1) {\r\n count++;\r\n }\r\n }\r\n }\r\n \r\n if (count == 0 || count == 1) {\r\n System.out.println(count); \r\n continue;\r\n }\r\n \r\n if (count == 2) {\r\n if (a[0][0] == 1 && a[1][1] == 1 || a[0][1] == 1 && a[1][0] == 1) {\r\n System.out.println(count); \r\n continue;\r\n } else {\r\n System.out.println(1);\r\n continue;\r\n }\r\n }\r\n \r\n }\r\n \r\n in.close();\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "61df65d569d75d9dd3f7227738b201ef", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\r\nimport java.util.Collections;\r\nimport java.util.List;\r\nimport java.util.Scanner;\r\n\r\npublic class problemA {\r\n public static void main(String[] args) {\r\n new problemA().solve();\r\n }\r\n\r\n Scanner in;\r\n\r\n private void solve() {\r\n in = new Scanner(System.in);\r\n int t = in.nextInt();\r\n\r\n while (t-- > 0) {\r\n int moves = 0;\r\n int first = in.nextInt();\r\n int second = in.nextInt();\r\n int third = in.nextInt();\r\n int fourth = in.nextInt();\r\n\r\n List list = new ArrayList<>(List.of(first, second, third, fourth));\r\n\r\n if (Collections.frequency(list, 0) == 3 || Collections.frequency(list, 0) == 2) {\r\n ++moves;\r\n }\r\n\r\n if (Collections.frequency(list, 0) == 0) {\r\n ++moves;\r\n ++moves;\r\n }\r\n\r\n System.out.println(moves);\r\n }\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c1f79463aa94385be9509cc7eec4be76", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.lang.*;\nimport static java.lang.System.*;\nimport static java.lang.Math.*;\n/*created by aditya76*/\npublic class adi {\n static int maxx=Integer.MAX_VALUE;\n static int mod=1000000007;\n public static void main(String[] args) throws IOException {\n InputReader sc=new InputReader(System.in);\n int n = sc.nextInt();\n int[] arr = new int[n * 2];\n int min = Integer.MAX_VALUE;\n for (int i = 0; i < 2 * n; i++)\n arr[i] = sc.nextInt();\n Arrays.sort(arr);\n for (int i = 0; i < 2 * n; i++) {\n for (int j = i + 1; j < 2 * n; j++) {\n Vector vec = new Vector();\n for (int k = 0; k < 2 * n; k++) {\n if (k != i && k != j) {\n vec.add(arr[k]);\n }\n }\n int value = compute(vec);\n if (value < min)\n min = value;\n }\n }\n out.println (min);\n }\n}\n\n//lcs\npublic static int lcs(String s1, String s2){\n char[] X=s1.toCharArray();\n char[] Y=s2.toCharArray();\n int m=X.length;\n int n=Y.length;\n int L[][] = new int[m+1][n+1];\n for (int i=0; i<=m; i++){\n for (int j=0; j<=n; j++){\n if (i == 0 || j == 0)\n L[i][j] = 0;\n else if (X[i-1] == Y[j-1])\n L[i][j] = L[i-1][j-1] + 1;\n else\n L[i][j] = unity(L[i-1][j], L[i][j-1]);\n }\n }\n return L[m][n];\n }\n//unity function\n public static int unity(int a, int b){\n return (a > b)? a : b;\n}\n\npublic static int compute (Vector vec) {\n Integer[] arr = new Integer[vec.size()];\n int diff = 0;\n vec.toArray(arr);\n for (int i = 0; i < vec.size() - 1; i += 2)\n diff += (arr[i + 1] - arr[i]);\n return diff;\n }\n//longest increasing subsequence (n log n)\npublic static int CeilIndex(int A[],int l,int r,int key){\n while(r-l>1){\n int m=l+(r-l)/2;\n if (A[m]>=key)\n r=m;\n else\n l=m;\n }\n return r;\n }\n\n public static int lis(int A[]){\n int size=A.length;\n int[] tailTable = new int[size];\n int len;\n tailTable[0] = A[0];\n len = 1;\n for (int i=1;itailTable[len-1])\n tailTable[len++]=A[i];\n else\n tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i];\n }\n return len;\n }\n\n//binary modular\npublic static long bxp(long a,long b){\n long res=1;\n while(b>0){\n if(b%2!=0)\n res=res*a;\n a=(a*a);\n b>>=1;\n }\n return res;\n}\n//euclid gcd\npublic static int gcd(int p, int q) {\n if (q == 0)\n return p;\n return gcd(q, p % q);\n }\n//prime\npublic static boolean isprime(long number){\n for(int i=2;i<=sqrt(number); i++){\n if(number % i == 0){\n return false;\n }\n }\n return true;\n}\n\n//large fibbonacci\npublic static int ffb(int n) {\n\t\tBigInteger a = BigInteger.ZERO;\n\t\tBigInteger b = BigInteger.ONE;\n\t\tint m = 0;\n\t\tfor (int i = 31 - Integer.numberOfLeadingZeros(n); i >= 0; i--) {\n\t\t\tassert a.equals(sfb(m));\n\t\t\tassert b.equals(sfb(m+1));\n\t\t\tBigInteger d = multiply(a, b.shiftLeft(1).subtract(a));\n\t\t\tBigInteger e = multiply(a, a).add(multiply(b, b));\n\t\t\ta = d;\n\t\t\tb = e;\n\t\t\tm *= 2;\n\t\t\tassert a.equals(sfb(m));\n\t\t\tassert b.equals(sfb(m+1));\n\t\t\tif (((n >>> i) & 1) != 0) {\n\t\t\t\tBigInteger c = a.add(b);\n\t\t\t\ta = b;\n\t\t\t\tb = c;\n\t\t\t\tm++;\n\t\t\t\tassert a.equals(sfb(m));\n\t\t\t\tassert b.equals(sfb(m+1));\n\t\t\t}\n\t\t}\n\t\treturn a.intValue();\n\t}\n\npublic static BigInteger sfb(int n) {\n \t\tBigInteger a = BigInteger.ZERO;\n \t\tBigInteger b = BigInteger.ONE;\n \t\tfor (int i = 0; i < n; i++) {\n \t\t\tBigInteger c = a.add(b);\n \t\t\ta = b;\n \t\t\tb = c;\n \t\t}\n \t\treturn a;\n \t}\n\npublic static BigInteger multiply(BigInteger x, BigInteger y) {\n \t\treturn x.multiply(y);\n }\n//reverse string\npublic static String rev(String s){\n StringBuilder sb=new StringBuilder(s);\n\t sb.reverse();\n\t return sb.toString();\n}\n//least common multiple\npublic static int lcm(int a, int b){\n return a * (b / gcd(a, b));\n}\n\n//depth first search\npublic static void dfs(ArrayList> adjLists,boolean[] neha,int v){\n neha[v]=true;\n //System.out.print(v+\" \");\n for(int w:adjLists.get(v)){\n if(!neha[w]){\n dfs(adjLists,neha,w);\n }\n }\n}\n\n//sieve prime\npublic static ArrayList sieve(int n,int m){\n boolean[] isPrime = new boolean[n+1];\n ArrayList al=new ArrayList();\n for (int i = 2; i <= n; i++)\n isPrime[i] = true;\n for (int factor = 2; factor*factor <=n; factor++) {\n if (isPrime[factor]) {\n for (int j = factor; factor*j <= n; j++)\n isPrime[factor*j] = false;\n }\n }\n int primes = 0;\n for (int i = m; i <= n; i++) {\n if (isPrime[i])\n al.add(i);\n }\n return al;\n }\n\n//input reader\nstatic class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n public InputReader(InputStream st) {\n this.stream = st;\n }\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do{\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String readLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ee7590d9e9953455cbab4e4b0925bf67", "src_uid": "76659c0b7134416452585c391daadb16", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class billboardII {\n public static void main(String[] args) throws FileNotFoundException, IOException {\n Scanner fileIn = new Scanner(System.in);\n PrintWriter fileOut = new PrintWriter(System.out);\n\t\t\n\t\tint numPeople = fileIn.nextInt() * 2;\n\t\tint i;\n\t\tint[] weights = new int[numPeople];\n\t\tfor (i = 0; i < numPeople; i++) {\n\t\t weights[i] = fileIn.nextInt();\n\t\t}\n\t\t\n\t\tArrays.sort(weights);\n\t\t\n\t\tint j;\n\t\tint k;\n\t\tArrayList remaining = new ArrayList();\n\t\tint minInstable = Integer.MAX_VALUE;\n\t\tint currentInstable = 0;\n\t\t\n\t\tfor (i = 0; i < numPeople; i++) {\n\t\t for (j = 0; j < i; j++) {\n\t\t currentInstable = 0;\n\t\t remaining.clear();\n\t\t for (k = 0; k < numPeople; k++) {\n\t\t remaining.add(weights[k]);\n\t\t }\n\t\t remaining.remove(i);\n\t\t remaining.remove(j);\n\t\t for (k = 0; k < (int) numPeople / 2 - 1; k++) {\n\t\t currentInstable += remaining.get(2k+1) - remaining.get(2k);\n\t\t }\n\t\t if (currentInstable < minInstable) {\n\t\t minInstable = currentInstable;\n\t\t }\n\t\t }\n\t\t}\n\t\t\n\t\tSystem.out.println(minInstable);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "682ea76a8ab30c1c25969010ece31bad", "src_uid": "76659c0b7134416452585c391daadb16", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class Main {\n public static void getMin(int[] w, int n) {\n // sort the array\n Arrays.sort(w);\n\n // always check right next to each other,\n // not counting i and j because they are the reserved.\n int min = Integer.MAX_VALUE;\n for (int i = 0; i < n; i++) {\n for (int j = i+1; j < n; j++) {\n int prev = -1;\n int val = 0;\n for (int k = 0; k < n; k++) {\n if (k == i || k == j) {\n continue;\n }\n if (prev == -1) {\n prev = k;\n } else {\n val += w[k] - w[prev];\n prev = k;\n }\n }\n min = Math.min(min, val);\n }\n }\n System.out.println(min);\n }\n\n public static void main(String[] args) {\n // accept input\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] w = new int[n*2];\n for (int i = 0; i < n*2; i++) {\n w[i] = sc.nextInt();\n }\n sc.close();\n\n getMin(w, n*2);\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7cf5626abc92e4ba982b42f9893a34d7", "src_uid": "76659c0b7134416452585c391daadb16", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class billboardII {\n public static void main(String[] args) throws FileNotFoundException, IOException {\n Scanner fileIn = new Scanner(System.in);\n PrintWriter fileOut = new PrintWriter(System.out);\n\t\t\n\t\tint numPeople = fileIn.nextInt() * 2;\n\t\tint i;\n\t\tint[] weights = new int[numPeople];\n\t\tfor (i = 0; i < numPeople; i++) {\n\t\t weights[i] = fileIn.nextInt();\n\t\t}\n\t\t\n\t\tArrays.sort(weights);\n\t\t\n\t\tint j;\n\t\tint k;\n\t\tArrayList remaining = new ArrayList();\n\t\tint minInstable = Integer.MAX_VALUE;\n\t\tint currentInstable = 0;\n\t\t\n\t\tfor (i = 0; i < numPeople; i++) {\n\t\t for (j = 0; j < i; j++) {\n\t\t currentInstable = 0;\n\t\t remaining.clear();\n\t\t remaining = Arrays.asList(weights);\n\t\t remaining.remove(i);\n\t\t remaining.remove(j);\n\t\t for (k = 0; k < (int) numPeople / 2 - 1; k++) {\n\t\t currentInstable += remaining.get(k+1) - remaining.get(k);\n\t\t }\n\t\t if (currentInstable < minInstable) {\n\t\t minInstable = currentInstable;\n\t\t }\n\t\t }\n\t\t}\n\t\t\n\t\tSystem.out.println(minInstable);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3df0c2fe5ce25d87f18de7bd7f8b6598", "src_uid": "76659c0b7134416452585c391daadb16", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class RationalResistance {\n\n public static void main(String[] args) {\n boolean test = true;\n Scanner in = new Scanner(System.in);\n long a = in.nextLong();\n long b = in.nextLong();\n long count = 0;\n count += a / b;\n a = a % b;\n while (a != b) {\n if (a <= 1 || b <= 1) {\n count += a * b;\n break;\n }\n count += a / b;\n a = a % b;\n count += (b / a) ;\n b -= a*(b/a);\n \n if (b == 1) {\n count += a;\n break;\n }\n if (test) {\n System.out.println(\"a:\" + a + \" b:\" + b);\n }\n }\n if (test) {\n System.out.println(\"a:\" + a + \" b:\" + b + \" c:\" + count);\n }\n if (!test) {\n System.out.println(count);\n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6ee39b2ee85516adeb885f981a0c63e9", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "//package rationalr;\nimport java.io.DataInputStream;\nimport java.io.PrintWriter;\nimport java.io.FileInputStream;\nimport java.io.IOException;\npublic class RationalR\n{\n\tstatic class Main//Reader\n\t{\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic Reader()\n\t\t{\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic Reader(String file_name) throws IOException\n\t\t{\n\t\t\tdin = new DataInputStream(new FileInputStream(file_name));\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String readLine() throws IOException\n\t\t{\n\t\t\tbyte[] buf = new byte[201]; // line length\n\t\t\tint cnt = 0, c;\n\t\t\twhile ((c = read()) != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n')\n\t\t\t\t\tbreak;\n\t\t\t\tbuf[cnt++] = (byte) c;\n\t\t\t}\n\t\t\treturn new String(buf, 0, cnt);\n\t\t}\n\n\t\tpublic int nextInt() throws IOException\n\t\t{\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{\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long nextLong() throws IOException\n\t\t{\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t}\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\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t}\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.')\n\t\t\t{\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t{\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException\n\t\t{\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException\n\t\t{\n\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\tfillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tpublic void close() throws IOException\n\t\t{\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n \n public static void main(String[] args) throws IOException\n\t{\n\t\tReader s=new Reader();PrintWriter pw=new PrintWriter(System.out);\n long x=s.nextLong(),y=s.nextLong();\n long ans=0;\n while(x!=y){\n if(y>x){\n long tmp=x;\n x=y;y=tmp;\n }\n long cnt=(x-y)%y==0?(x-y)/y:(x-y)/y+1;ans+=cnt;\n x-=y*cnt;//System.out.println(cnt);\n }pw.write(String.valueOf(ans+1));\n\t\tpw.flush();pw.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8328b0e66b695eec4091cf21bc47d961", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class RationalResistance {\n\n public static void main(String[] args) {\n boolean test = false;\n Scanner in = new Scanner(System.in);\n long a = in.nextLong();\n long b = in.nextLong();\n long count = 0;\n count += a / b;\n a = a % b;\n while (a != b) {\n if (a <= 1 || b <= 1) {\n count += a * b;\n break;\n }\n count += a / b;\n a = a % b;\n count += (b / a) ;\n b -= a*(b/a);\n \n if (b == 1) {\n count += a;\n break;\n }\n if (test) {\n System.out.println(\"a:\" + a + \" b:\" + b);\n }\n }\n if (test) {\n System.out.println(\"a:\" + a + \" b:\" + b + \" c:\" + count);\n }\n if (!test) {\n System.out.println(count);\n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "91522085c4fc0f21ab9755ede8fd8214", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n Scanner in = new Scanner(System.in);\n long a, b, res = 0;\n\t long a = in.nextLong();\n\t long b = in.nextLong();\n\t while(a > 0 && b > 0) {\n if (a >= b){\n \tres += (a / b);\n \ta %= b;\n }\n else {\n \tres += (b / a);\n \tb %= a;\n }\n }\n\t\tSystem.out.println(res); \n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3829b9d5b3e844f70f056c6852a16c30", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\n import java.util.Scanner;\n\n public class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) \n {\n Scanner s=new Scanner(System.in);\n int n=6;\n int i=0;\n int[]Arr=new int[n];\n String a=s.nextLine();\n while(is2-s1)\n {\n primeroRestar=true;\n }\n for (int j = 0; j < 6; j++) \n {\n if(Arr[j]<9-Arr[j])\n {\n Arr[j]=9-Arr[j];\n }\n }\n if(Arr[0]>Arr[1])\n {\n int aux=Arr[0];\n Arr[0]=Arr[1];\n Arr[1]=aux;\n }\n if(Arr[0]>Arr[2])\n {\n int aux=Arr[0];\n Arr[0]=Arr[2];\n Arr[2]=aux;\n }\n if(Arr[1]>Arr[2])\n {\n int aux=Arr[1];\n Arr[1]=Arr[2];\n Arr[2]=aux;\n }\n if(Arr[3]>Arr[4])\n {\n int aux=Arr[3];\n Arr[3]=Arr[4];\n Arr[4]=aux;\n }\n if(Arr[3]>Arr[5])\n {\n int aux=Arr[5];\n Arr[5]=Arr[3];\n Arr[3]=aux;\n }\n if(Arr[4]>Arr[5])\n {\n int aux=Arr[5];\n Arr[5]=Arr[4];\n Arr[4]=aux;\n }\n \n \n int p=5;\n int difAux=dif;\n if(segundoRestar)\n {\n while(p>2&&difAux>0)\n {\n difAux-=Arr[p];\n cont1++;\n p--;\n }\n difAux=dif;\n difAux-=Arr[5];\n cont2++;\n if(difAux>0)\n {\n difAux-=Arr[4];\n cont2++;\n }\n if(difAux>0)\n {\n difAux-=Arr[3];\n cont2++;\n }\n }\n else if(primeroRestar)\n {\n p=2;\n while(p>=0&&difAux>0)\n {\n difAux-=Arr[p];\n cont1++;\n p--;\n }\n difAux=dif;\n difAux-=Arr[2];\n cont2++;\n if(difAux>0)\n {\n difAux-=Arr[1];\n cont2++;\n }\n if(difAux>0)\n {\n difAux-=Arr[0];\n cont2++;\n }\n }\n if(cont1sum2){\n int ind1=x.length-1 ;\n int ind2=0 ; \n int d1=x[ind1];\n int d2=9-y[ind2] ;\n if (d1>=d2){\n sum1-=d1 ;\n ind1--;\n }\n else {\n sum2+=d2 ;\n ind2++ ;\n }\n if (sum2>=sum1){\n System.out.println(\"1\");\n }\n else {\n if (d1>=d2){\n sum1-=d1 ;\n ind1--;\n }\n else {\n sum2+=d2 ;\n ind2++ ;\n }\n if (sum2>=sum1){\n System.out.println(\"2\");\n }\n else {\n if (d1>=d2){\n sum1-=d1 ;\n ind1--;\n }\n else {\n sum2+=d2 ;\n ind2++ ;\n }\n if (sum2>=sum1){\n System.out.println(\"3\");\n }\n }\n }\n }\n else {\n int ind1 = 0 ;\n int ind2 = y.length-1 ; \n int d1 = 9-x[ind1] ; \n int d2 = y[ind2] ;\n if (d1>=d2){\n sum1+=d1 ;\n ind1++;\n }\n else {\n sum2-=d2 ;\n ind2-- ;\n }\n if (sum1>=sum2){\n System.out.println(\"1\");\n }\n else {\n if (d1>=d2){\n sum1+=d1 ;\n ind1++;\n }\n else {\n sum2-=d2 ;\n ind2-- ;\n }\n if (sum1>=sum2){\n System.out.println(\"2\");\n }\n else {\n if (d1>=d2){\n sum1+=d1 ;\n ind1++;\n }\n else {\n sum2-=d2 ;\n ind2-- ;\n }\n if (sum1>sum2){\n System.out.println(\"3\");\n }\n }\n }\n }\n }\n}\nclass Sorting{\n \n public static int[] bucketSort(int[] array, int bucketCount) {\n\n if (bucketCount <= 0) throw new IllegalArgumentException(\"Invalid bucket count\");\n\n if (array.length <= 1) return array; //trivially sorted\n\n \n\n int high = array[0];\n\n int low = array[0];\n\n for (int i = 1; i < array.length; i++) { //find the range of input elements\n\n if (array[i] > high) high = array[i];\n\n if (array[i] < low) low = array[i];\n\n }\n\n double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket\n \n\n ArrayList buckets[] = new ArrayList[bucketCount];\n\n for (int i = 0; i < bucketCount; i++) { //initialize buckets\n\n buckets[i] = new ArrayList();\n\n }\n\n \n\n for (int i = 0; i < array.length; i++) { //partition the input array\n \n buckets[(int)((array[i] - low)/interval)].add(array[i]);\n\n }\n \n\n int pointer = 0;\n\n for (int i = 0; i < buckets.length; i++) {\n\n Collections.sort(buckets[i]); //mergeSort\n\n for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets\n\n array[pointer] = buckets[i].get(j);\n\n pointer++;\n\n }\n\n}\n\nreturn array;\n\n}\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 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}\nclass seg implements Comparable{ \n int l; \n int r ; \n seg(int l,int r){ \n this.l=l; \n this.r=r; \n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1f97694f5f1ca8c8811b874ee37f6e75", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String number = sc.next();\n Integer firstPart = Integer.parseInt(number.substring(0,3));\n Integer secondPart = Integer.parseInt(number.substring(3,6));\n\n List firstPartDigits = new ArrayList<>();\n List secondPartDigits = new ArrayList<>();\n int firstPartDigitsSum = 0;\n int secondPartDigitsSum = 0;\n while (firstPart > 0) {\n firstPartDigits.add(firstPart % 10);\n firstPartDigitsSum += firstPart % 10;\n firstPart /= 10;\n\n secondPartDigits.add(secondPart % 10);\n secondPartDigitsSum += secondPart % 10;\n secondPart /= 10;\n }\n Collections.sort(firstPartDigits);\n Collections.sort(secondPartDigits);\n\n int digitReplacementNeeded = 0;\n while (firstPartDigitsSum != secondPartDigitsSum) {\n if (Math.abs(firstPartDigitsSum - secondPartDigitsSum) < 9) {\n digitReplacementNeeded += 1;\n System.out.println(digitReplacementNeeded);\n return;\n }\n\n if (firstPartDigitsSum < secondPartDigitsSum) {\n firstPartDigitsSum += Math.min(9 - firstPartDigits.get(digitReplacementNeeded), secondPartDigitsSum - firstPartDigitsSum);\n } else {\n secondPartDigitsSum += Math.min(9 - secondPartDigits.get(digitReplacementNeeded), firstPartDigitsSum - secondPartDigitsSum);\n }\n digitReplacementNeeded++;\n }\n\n System.out.println(digitReplacementNeeded);\n }\n}\nclose", "lang_cluster": "Java", "compilation_error": true, "code_uid": "de0584fd7b255533fb9c859329d2873b", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tvoid solve() throws IOException {\n\t\tchar[] a = ns().toCharArray();\n\t\tint s = 0;\n\t\tint i = 0;\n\t\tfor (; i < a.length / 2; i++)\n\t\t\ts += a[i] - '0';\n\t\tfor (; i < a.length; i++)\n\t\t\ts -= a[i] - '0';\n\t\tint d[] = new int[a.length];\n\t\tfor (i = 0; i < a.length; i++)\n\t\t\td[i] = s * (2 * i - 5) > 0 ? '9' - a[i] : a[i] - '0';\n\n\t\ts = Math.abs(s);\n\t\tHelper.tr(s, d);\n\t\tArrays.sort(d);\n\t\tfor (i = 0; i < a.length && s > 0; i++)\n\t\t\ts -= d[a.length - 1 - i];\n\t\tout.println(i);\n\t}\n\n\tString ns() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine(), \" \");\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tint ni() throws IOException {\n\t\treturn Integer.parseInt(ns());\n\t}\n\n\tlong nl() throws IOException {\n\t\treturn Long.parseLong(ns());\n\t}\n\n\tdouble nd() throws IOException {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tString[] nsa(int n) throws IOException {\n\t\tString[] res = new String[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = ns();\n\t\t}\n\t\treturn res;\n\t}\n\n\tint[] nia(int n) throws IOException {\n\t\tint[] res = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = ni();\n\t\t}\n\t\treturn res;\n\t}\n\n\tlong[] nla(int n) throws IOException {\n\t\tlong[] res = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = nl();\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tout = new PrintWriter(System.out);\n\t\ttok = new StringTokenizer(\"\");\n\t\tMain main = new Main();\n\t\tmain.solve();\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fa16fc4041f8e3db0c7f417a9daf167f", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class x\n{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int i=0,x=0;\n \n for(i=1;i<=n;i++)\n {\n x = x + Math.pow(-1,i)*i;\n }\n \n System.out.println(x);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "69c6cb606de051d5f5dc7d5a3a9679e1", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Main{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint t = sc.nextInt();\n\n\t\t\n\t\tSystem.out.println((t%2 != 0) ? n/2 : -(n/2+1));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e116655e5aafe42b5f70ee4d4049d487", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class CalculatingFunction {\n\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n int count=0;\n //i==odd count= count-i;\n if(n%2==0){\n n=n/2;\n }\n else\n n=(n/2)*(-1)-1;\n \n \n System.out.println(n);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a8c2ecf1dfad9f082cc88ec36df6940", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n long x,y;\n long result=0;\n Scanner sc=new Scanner(System.in);\n x=sc.nextlong();\n for(int i=1;i<=x;i++)\n {\n if(i%2==0)\n {\n y=1;\n }\n else\n {\n y= -1;\n }\n result+=y*i;\n }\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6de0d6f2613578ecab0aae5f1e3e25e2", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n \n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n String str = in.next();\n if(chech(str)){\n System.out.println(\u201dyes\u201d);\n } else {\n System.out.println(\u201cno\u201d);\n }\n }\n \n public static boolean check(String str){\n int counter =0; \n for(int i= str.length()-1; i >= 0; i-=1){\n if(str.chatAt(i) == \u20190\u2019){\n counter++;\n } else if(counter >= 6){\n return true;\n }\n }\n return false;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d5e8d97dcaf803a75cbb1b26f6cc47b8", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Div64\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tint z = 0, o = 0;\n\t\tfor (int i = s.length - 1; i >= 0; i--)\n\t\t{\n\t\t\tif (s.charAt(i) == '0')\n\t\t\t\tz++;\n\t\t\telse if (z >= 6)\n\t\t\t{\n\t\t\t\to++;\n\t\t\t}\n\t\t}\n\t\tif (z >= 6 && o == 1)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "99a8444b78eb718a38529ba804cbc1ac", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage codeforces;\n\n//import java.util.Scanner;\n\n/**\n *\n * @author HOME\n */\npublic class Main {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n String g = sc.next();\n int t = Integer.parseInt(g, 2);\n if(t>= 64)\n System.out.println(\"yes\");\n else\n System.out.println(\"no\");\n \n \n \n }\n }\n \n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "450999f493070d6b57a3b24a16b5687b", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n \n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n String str = in.next();\n if(chech(str)){\n System.out.println(\"yes\");\n } else {\n System.out.println(\"no\");\n }\n }\n \n public static boolean check(String str){\n int counter =0; \n for(int i= str.length()-1; i >= 0; i-=1){\n if(str.chatAt(i) == (char)0){\n counter++;\n } else if(counter >= 6){\n return true;\n }\n }\n return false;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7aa5d1f1d9749cfc802b19adcd2e8692", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class panagram\n{\n public static void main(String [] args)\n {\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n String s=(in.next()).toLowerCase();\n String s1=\"abcdefghijklmnopqrstuvwxyz\";\n boolean s1=Pattern.matches(s1,s);\n \n if(s1==true)\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a033ca6a6d2e20a373264ae2fc887d23", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\ufeff/*\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 pangram;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author belar\n */\npublic class Pangram {\n\n /**\n * @param args the command line arguments\n */\n \n public static void main(String[] args) {\n // TODO code application logic here\n String letras = \"abcdefghijklmnopqrstuvwxyz\"; \n Scanner leer = new Scanner(System.in);\n int n = Integer.valueOf(leer.nextLine());\n String ca = leer.nextLine();\n ca = ca.toLowerCase();\n boolean es = false;\n int nro = 0;\n if(ca.length()>=26){\n for(int i =0;i=0;i--)\n {\n s1+=ch[i]+\"\";\n }\n if(s1.equals(ref))\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d4578e156fa7587b1df91552a14601ed", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class a\n{\n public void main()\n { \n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n String s=sc.nextLine();\n int count[]=new int[1000];int c=0;int k=0;int m=0;\n s=s.toUpperCase();\n for(int a=65;a<=90;a++)\n {\n for(int j=0;j=1)\n m++;\n }\n if(m==26)\n return \"YES\";\n else \n return \"NO\";\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b3057ca62f3a4b02b0e36d7a423cd456", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Main\n{\n \n public static void main(String[] args)\n {\n Scanner Sc = new Scanner(System.in);\n \n String input = Sc.nextLine();\n \n input = input.replaceAll(\"\\\\s\" , \"\");\n \n char c = input.charAt(input.length - 2);\n \n if(c == 'A' || c == 'a' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U' || c=='y' || c == 'Y')\n {\n System.out.println(\"YES\");\n \n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "574e96b396e795de36b07986df1d1fdf", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0} {"lang": "Java 7", "source_code": "public class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tString cad = in.nextLine();\n\t\tif (cad.charAt(cad.length()-2) == ' ')\n\t\t{\n\t\t\tif (cad.charAt(cad.length()-3) == 'a' || cad.charAt(cad.length()-3) == 'e' || cad.charAt(cad.length()-3) == 'i' || cad.charAt(cad.length()-3) == 'o' || cad.charAt(cad.length()-3) == 'u' || cad.charAt(cad.length()-3) == 'y' || cad.charAt(cad.length()-3) == 'A' || cad.charAt(cad.length()-3) == 'E' || cad.charAt(cad.length()-3) == 'I' || cad.charAt(cad.length()-3) == 'O' || cad.charAt(cad.length()-3) == 'U' || cad.charAt(cad.length()-3) == 'Y')\n\t\t\t{\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (cad.charAt(cad.length()-2) == 'a' || cad.charAt(cad.length()-2) == 'e' || cad.charAt(cad.length()-2) == 'i' || cad.charAt(cad.length()-2) == 'o' || cad.charAt(cad.length()-2) == 'u' || cad.charAt(cad.length()-2) == 'y' || cad.charAt(cad.length()-2) == 'A' || cad.charAt(cad.length()-2) == 'E' || cad.charAt(cad.length()-2) == 'I' || cad.charAt(cad.length()-2) == 'O' || cad.charAt(cad.length()-2) == 'U' || cad.charAt(cad.length()-2) == 'Y')\n\t\t\t{\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d4ab8c94e51a90a61c17eff530f03bc9", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class A_ {\n private boolean isVowel(char s){\n ArrayList a = new ArrayList();\n a.add('a');a.add('i');a.add('e');a.add('o');a.add('u');a.add('y');\n a.add('A');a.add('I');a.add('E');a.add('O');a.add('U');a.add('Y');\n if (a.contains(s))return true;\n return false;\n }\n public static void main(String[] args) throws IOException{\n BufferedReader stdin = new BufferedReader(new InputStreamReader(\n System.in));\n \n String s =stdin.readLine();\n for(int i=s.length() - 1 ; i>=0 ; i--){\n if (s.charAt(i)!='?' && s.charAt(i)!=' '){\n if (new A_().isVowel(s.charAt(i))){\n System.out.println(\"YES\");\n break;\n }\n else{\n System.out.println(\"NO\");\n break;\n }\n \n }\n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5bf0bdb5dda7b96ee97f447cb44c7f81", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Main\n{\n \n public static void main(String[] args)\n {\n Scanner Sc = new Scanner(System.in);\n \n String input = Sc.nextLine();\n \n input = input.replaceAll(\"\\\\s\" , \"\");\n \n char c = input.charAt(input.length - 2);\n \n if(c == \"A\" || c == \"a\" || c == \"e\" || c == \"E\" || c == \"I\" || c == \"i\" || c == \"o\" || c == \"O\" || c == \"u\" || c == \"U\" || c==\"y\" || c == \"Y\")\n {\n System.out.println(\"YES\");\n \n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "550cad0f43c6f90954668b9aef8f8be3", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0} {"lang": "Java 11", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\tpublic class Main (String[] args) throws java.lang.Exception\n\t{\n\t\tint n, m, k;\n\t\tScanner in = new Scanner(System.in);\n n = in.nextInt();\n m = in.nextInt(); \n k = in.nextInt();\n in.close();\n long [][] bricks = new long[2001][2000];\n bricks[1][0] = m;\n for(int i = 2; i <= n; ++i)\n \tfor(int j = 0; j <= k; ++j)\n \t\tif(j == 0)\n\t\t\t\t\tbricks[i][j] = m % 998244353;\n\t\t\t\telse \n\t\t\t\t\tbricks [i][j] = (bricks[i-1][j] + bricks[i-1][j-1]*(m-1))% 998244353;\n\t\tSystem.out.print(bricks[n][k]);\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1cdcbf6a103b84f6db0d546fa167ffe9", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\n\npublic class Hworking {\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\tsolve(1, in, out);\n\t\tout.close();\n\t}\n\n\n\nstatic\t\tvoid solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tint m = in.nextInt();\n\t\t\tint k = in.nextInt();\n\t\t\tint mod = 998244353;\n\t\t\tlong[][] dp = new long[n + 1][k + 2];\n\t\t\tdp[1][0] = m;\n\t\t\tfor (int i = 2; i <= n; i++)\n\t\t\t\tfor (int j = 0; j <= k; j++) {\n\t\t\t\t\tdp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;\n\t\t\t\t\tdp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j] * (m - 1) % mod) % mod;\n\t\t\t\t}\n\t\t\tout.println(dp[n][k]);\n\t\t}\n\t}\n\n\tclass InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\t\tprivate SpaceCharFilter filter;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong a[] = new long[n];\n\t\t\tfor (int i = 1; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "90ee1719ba8bc0ba6b014b350258b151", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Abc {\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\n\t\tlong fact[] = new long[2001];\n\t\tlong mod = 998244353;\n\n\t\tfact[0] = 1;\n\t\tfor(int i = 1; i < n ; i++) {\n\t\t\tfact [i] = (i * fact[i - 1]) % mod;\n\t\t}\n\n\t\tlong c = comb(n - 1, k, fact, mod);\n\t\tc = (c * m) % mod;\n\t\tif(k > 1) {\n\t\t\tc = (c * pow(m - 1, k, mod)) % mod;\n\t\t}\n\t\tif(m == 1 && k > 0) {\n\t\t\tSystem.out.pritnln(0);\n\t\t} else {\n\t\t\tSystem.out.println(c);\n\t\t}\n\t}\n\tstatic long comb(int a, int b, long fact[], long c) {\n\t\tif(b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tlong num = fact[a];\n\t\tlong denom = (fact[b] * fact[a - b]) % c;\n\t\treturn (num * modInverse(denom, c)) % c;\n\t}\n\tstatic long modInverse(long a, long b) {\n\t\treturn pow(a, b - 2, b);\n\t}\n\tstatic long pow(long a, long b, long mod) {\n\t\tlong result = 1;\n\t\twhile(b > 0) {\n\t\t\tif(b % 2 == 1) {\n\t\t\t\tresult = (result * a) % mod;\n\t\t\t}\n\t\t\ta = (a * a) % mod;\n\t\t\tb /= 2;\n\t\t}\n\t\treturn result;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a9b90fe1532ebe9ccaf3e816ac8d050c", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\tpublic class Main\n\t{\n\t\tint n, m, k;\n\t\tScanner in = new Scanner(System.in);\n n = in.nextInt();\n m = in.nextInt(); \n k = in.nextInt();\n in.close();\n long [][] bricks = new long[2001][2000];\n bricks[1][0] = m;\n for(int i = 2; i <= n; ++i)\n \tfor(int j = 0; j <= k; ++j)\n \t\tif(j == 0)\n\t\t\t\t\tbricks[i][j] = m % 998244353;\n\t\t\t\telse \n\t\t\t\t\tbricks [i][j] = (bricks[i-1][j] + bricks[i-1][j-1]*(m-1))% 998244353;\n\t\tSystem.out.print(bricks[n][k]);\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b77b298e5421c4e2a8e74d8bfb78c394", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Scanner.*;\nimport java.io.*;\nimport java.util.Arrays;\nimport java.math.*;\nimport java.math.BigInteger.*;\nimport java.math.BigDecimal.*;\nimport java.util.Set.*;\n\n\npublic class Main\n{\n public static void main(String[] args)throws IOException{\n\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 long m,n,b,s=0,x;\n m=sc.nextInt();\n b=sc.nextInt();\n for(int i=0;i<=b;i++){\n x=(b-i)*m;\n s=Math.max(s,((i+1)*(x+1)*(i+x))/2);\n }\n System.out.printf(\"%u\\r\\n\",s);\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b86aee72ed36cc5e874581ceb9af7009", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\tnew C();\n\t}\n\t\n\tC() {\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint len = in.nextInt();\n\t\tint rem = 0,count=0;\n\t\tArrayList a = new ArrayList(len);\n\t\t\n\t\tfor(int t=0;t<2*len;t++){\n\t\t\t//System.out.println(a);\n\t\t\tif(in.next().equals(\"add\")){\n\t\t\t\tint n = in.nextInt()-1;\n\t\t\t\ta.add(n);\n\t\t\t}else{ //remove\n\t\t\t\tif(a.get(a.size()-1)!=rem++){\n\t\t\t\t\tCollections.sort(a,Collections.reverseOrder());\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\ta.remove(a.size()-1);\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\t\t\n\t\tin.close();\n\n\t}\n\t\n}\n\n/*\n\n3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n\n7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n\n */\n\n\n\n\n\n\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e0978bf1f0f5e440d9b3a0d0426c591", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class banana{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n long m=sc.nextInt();\n long b=sc.nextInt();\n long maxX=m*b;\n long ans=0,temp;\n long y;\n for(long x=0;x<=maxX;x++){\n y=(long)((-1/(double)m)*x+b);\n temp=((x+1)(y+1)(x+y))/2;\n ans=(long)Math.max(ans,temp);\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "668a670ca47734dbbca1c5d3b5f7689e", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author Destarte\n */\npublic class NewClass {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int m = input.nextInt();\n int b = input.nextInt();\n \n if(m==b && b==1){\n\n System.out.println(1);\nreturn 1;\n\n}\n \n\n int my = b;\n int mx = -b * -m;\n\n int x0 = -1, y0 = -1;\n\n for (int y = my; y >= 0; y--) {\n for (int x = mx; x >= 0; x--) {\n double d = ( (double)-1/m) * x + b;\n if (y == d && (y != my && x != 0) && (x != mx && y != 0)) {\n if (y * x >= y0 * x0) {\n y0 = y;\n x0 = x;\n }\n }\n }\n }\n\n int soma = 0;\n \n for (int i = 0; i <= x0; i++) {\n for (int j = 0; j <= y0; j++) {\n soma += i+j;\n }\n }\n System.out.println(soma);\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "97db85835c84b51aa3435ed07c8db0f2", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n public class codechef2\n{\n\tpublic static void main(String ar[])\n\t{\n\tScanner sc=new Scanner(System.in);\n\t\tlong v,e;\n\t\tv=sc.nextLong();\n\t\te=sc.nextLong();\n\t\tif(e==0)System.out.print(v);System.out.print(' ');\n\t\telse if(v<=2*e)System.out.print(\"0 \");\n\t\telse System.out.print((v-2*e));System.out.print(' ');\n\t\n\tif(e==0)System.out.print(v+' ');\n\t\telse if(e==1)System.out.print(v-2);\n\t\tfor(long i=2;ie)\n return (int)l-1;\n } \n else\n r = m - 1; \n }\n return 0; \n }\n\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n long v = sc.nextLong();\n long e = sc.nextLong();\n long min=0,max=0;\n long n;\n if(e==0)\n System.out.println(v+\" \"+v);\n else{\n min = v - 2*e;\n if(min<=0)\n min = 0;\n\n long n = bs(v,e);\n if((n*(n-1))/2==e)\n max = v-(int)n;\n else\n max = v-(int)n-1;\n System.out.println(min+\" \"+max);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e1bfc8f9696c4d651d344ac266b79cd", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n inclass in = new inclass(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n BVasyaAndIsolatedVertices solver = new BVasyaAndIsolatedVertices();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BVasyaAndIsolatedVertices {\n public void solve(int testNumber, inclass in, PrintWriter out) {\n long n = in.nextInt(), m = in.nextLong();\n if (m == 0) {\n out.println(n + \" \" + n);\n return;\n }\n if (m >= n) {\n out.println(0 + \" \" + 0);\n } else {\n long max = n - m - 1;\n long min = n - (2 * m);\n out.println((min < 0 ? 0 : min) + \" \" + (max < 0 ? 0 : max));\n }\n }\n\n }\n\n static class inclass {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private inclass.SpaceCharFilter filter;\n\n public inclass(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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "92a2f056c467c7fda9da7a6783ab9064", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class vasyaandisolatedvertices {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextLong();\n\t\tlong m = in.nextLong();\n\n\t\tlong min = 0;\n\t\tlong max = 0;\n\t\tif(n==1) {\n\t\t\tSystem.out.println(\"1 1\");\n\t\t\treturn;\n\t\t}\n\t\tmin = Math.max(0,n-m*2);\n\n\n\t\tint rem = m;\n\t\tint delete = 1;\n\t\twhile(rem>0) {\n\t\t\trem-=Math.min(delete,rem);\n\t\t\tdelete++;\n\t\t}\n\n\t\tif(delete==1) max = n;\n\t\telse max = n-delete;\n\n\t\tSystem.out.println(min +\" \" +max);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2c31c85b9ca247e631842d47810fc40a", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n \n int n = sc.nextInt();\n int d = sc.nextInt();\n sc.nextLine();\n \n int[] t = new int[n];\n int sumOfTime = 0;\n for(int i=0; i=((n-1)*10))\n {\n System.out.println(d/5);\n }\n else\n System.out.println(-1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7647fe231378bbed481f52430161cf0a", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Concert {\n\n public static void main(String []args){\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int d = s.nextInt();\n int t[] = new int [n];\n for(int i = 0; i =5){\n jokes += (rest / 5);\n }\n if(count == n){\n System.out.println(jokes);\n }else{\n System.out.println(\"-1\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3ef683da8da56eaba507a1c3380f6fb8", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Scanner;\n\n\n public class Param\n{\n \n public static void main( String[]args) throws IOException\n {\n\t\n\t\tScanner param=new Scanner(System.in);\n\t\tString s=param.next();\n\t\tString p=param.next();\n\t\t//System.out.println(s);\n\t // System.out.println(p);\n\t String[]arr=s.split(\":\");\n\t int h1 = Integer.parseInt(arr[0]);\n int m1 = Integer.parseInt(arr[1]);\n\t String[]arr1=p.split(\":\");\n\t int h2 = Integer.parseInt(arr1[0]);\n int m2 = Integer.parseInt(arr1[1]);\n int h3=0;\n int m3=0;\n if(m1==0&&m2==0&&(h1+h2)%2!=0){\n m3=30;\n h3=(h1+h2)/2;\n String formattedStr1 = String.format(\"%02d\", h3);\n System.out.println(formattedStr1+\":\"+m3);\n // System.out.println(h3+\":\"+m3);\n }\n else if(m1==0&&m2!=0&&(h1+h2)%2!=0) {\n m3=(60+m2)/2;\n String formattedStr = String.format(\"%02d\", m3);\n \n h3=(h1+h2)/2;\n String formattedStr1 = String.format(\"%02d\", h3);\n System.out.println(formattedStr1+\":\"+formattedStr);\n }\n else{\n \n if(m1+m2>=60){\n if(h1=!h2)\n m3=Math.abs((60-(m1+m2))/2);\n h1=h1+1;\n }\n else{\n m3=(m1+m2)/2;\n }\n else{\n m3=(m1+m2)/2;\n h1=h1;\n }\n //System.out.println(m3);\n String formattedStr = String.format(\"%02d\", m3);\n \n h3=(h1+h2)/2;\n String formattedStr1 = String.format(\"%02d\", h3);\n System.out.println(formattedStr1+\":\"+formattedStr);\n \n }\n // System.out.println(h3+\":\"+formattedStr);\n\t \n\t\n\t\n }\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "789b1a8384a17970b9f142eddf131cba", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class middle\n{\n public static void main(String args[])throws IOException\n {\n InputStreamReader read=new InputStreamReader(System.in);\n BufferedReader in=new BufferedReader(read);\n int h1,h2,m1,m2,m;\n String a,b;\n a=in.readLine();\n b=in.readLine();\n h1=Integer.parseInt(a.substring(0,2));\n m1=Integer.parseInt(a.substring(3));\n h2=Integer.parseInt(b.substring(0,2));\n m2=Integer.parseInt(b.substring(3));\n m=(h2-h1)*60+(m2-m1);\n m=m/2;\n h1+=(m/60);\n m1+=(m%60);\n if(m1>=60)\n {\n m1-=60;\n h1+1;\n }\n if(h1<10)\n System.out.print(\"0\");\n System.out.print(h1+\":\"+m1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e65f948fd48649b4888565932b76d3aa", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Scanner;\n\n\n public class Param\n{\n \n public static void main( String[]args) throws IOException\n {\n\t\n\t\tScanner param=new Scanner(System.in);\n\t\tString s=param.next();\n\t\tString p=param.next();\n\t\t//System.out.println(s);\n\t // System.out.println(p);\n\t String[]arr=s.split(\":\");\n\t int h1 = Integer.parseInt(arr[0]);\n int m1 = Integer.parseInt(arr[1]);\n\t String[]arr1=p.split(\":\");\n\t int h2 = Integer.parseInt(arr1[0]);\n int m2 = Integer.parseInt(arr1[1]);\n int h3=0;\n int m3=0;\n if(m1==0&&m2==0&&(h1+h2)%2!=0){\n m3=30;\n h3=(h1+h2)/2;\n String formattedStr1 = String.format(\"%02d\", h3);\n System.out.println(formattedStr1+\":\"+m3);\n // System.out.println(h3+\":\"+m3);\n }\n else if(m1==0&&m2!=0&&(h1+h2)%2!=0) {\n m3=(60+m2)/2;\n String formattedStr = String.format(\"%02d\", m3);\n \n h3=(h1+h2)/2;\n String formattedStr1 = String.format(\"%02d\", h3);\n System.out.println(formattedStr1+\":\"+formattedStr);\n }\n else{\n \n if(m1+m2>=60){\n if(h1=!h2){\n m3=Math.abs((60-(m1+m2))/2);\n h1=h1+1;\n }\n }\n else{\n m3=(m1+m2)/2;\n }\n else{\n m3=(m1+m2)/2;\n h1=h1;\n }\n //System.out.println(m3);\n String formattedStr = String.format(\"%02d\", m3);\n \n h3=(h1+h2)/2;\n String formattedStr1 = String.format(\"%02d\", h3);\n System.out.println(formattedStr1+\":\"+formattedStr);\n \n }\n // System.out.println(h3+\":\"+formattedStr);\n\t \n\t\n\t\n }\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "847c31c5659eb415fbb0889f838130b4", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Level {\n \n \n public static void main(String[] args) {\n DS.Scanner in =new DS.Scanner();\n String s1=in.next();\n String s2=in.next();\n String h1s=\"\";\n String m1s=\"\";\n String h2s=\"\";\n String m2s=\"\";\n h1s+=s1.charAt(0);h1s+=s1.charAt(1);\n m1s+=s1.charAt(3);m1s+=s1.charAt(4);\n h2s+=s2.charAt(0);h2s+=s2.charAt(1);\n m2s+=s2.charAt(3);m2s+=s2.charAt(4);\n int h1=Integer.valueOf(h1s);\n int m1=Integer.valueOf(m1s);\n int h2=Integer.valueOf(h2s);\n int m2=Integer.valueOf(m2s);\n int total1=h1*60+m1;\n int total2=h2*60+m2;\n int total=total2-total1;\n total/=2;\n total+=total1;\n int h=total/60;\n int m=total%60;\n StringBuilder build=new StringBuilder();\n if(h>9){\n build.append(h+\":\");\n if(m>9){\n build.append(m);\n }\n else{\n build.append(\"0\"+m);\n }\n }\n else{\n build.append(\"0\"+h+\":\");\n if(m>9){\n build.append(m);\n }\n else{\n build.append(\"0\"+m);\n }\n }\n System.out.println(build.toString());\n }\n \n public static class Algo{\n public void merge(int arr[], int l, int m, int r){ \n int n1 = m - l + 1; \n int n2 = r - m; \n \n int L[] = new int [n1]; \n int R[] = new int [n2]; \n \n for (int i=0; i sieve(int n){\n long sqr=(long) Math.sqrt(n);\n boolean[] isPrime=new boolean[n+1];\n for(int i=0;i<=n;i++)\n isPrime[i]=true;\n for(int i=2;i<=sqr;i++){\n if(isPrime[i]){\n for(int p=i*i;p<=n;p+=i)\n isPrime[p]=false;\n }\n }\n ArrayList list=new ArrayList();\n for(int i=0;i<=n;i++)\n if(isPrime[i])\n list.add(i);\n list.remove(0);\n list.remove(0);\n return list;\n }\n public static boolean isPrime(long n){\n boolean res=true;\n List l =sieve((int) Math.sqrt(n));\n for(int i=0;i list=new ArrayList();\n if(ptr.hasNext()){\n int cur=(int) ptr.next();\n // System.out.println(cur);\n while(n!=1){\n while(n%cur==0){\n list.add(cur);\n n/=cur;\n }\n if(ptr.hasNext())\n cur=(int) ptr.next();\n //System.out.println(cur);\n }\n }\n if(n>2)\n list.add(n);\n return list;\n }\n }\n public static long gcd(long a,long b){\n if(b==0)\n return a;\n else\n return gcd(b,a%b);\n }\n public static long lcm(long a,long b){\n long ab=a*b;\n long gcd=gcd(a,b);\n return ab/gcd;\n }\n public static int bs(int[]z,int k){\n int res=0;\n int l=0;\n int r=z.length-1;\n int mid=(l+r)/2;\n while(l<=r){\n \n if(z[mid]==k){\n res=1;\n break;\n }\n if(z[mid]>k)\n r=mid-1;\n else\n l=mid+1;\n mid=(l+r)/2;\n }\n return res;\n }\n }\n private static class DS{\n private static class Stack {\n private int Size;\n Node top;\n Stack(){\n \n Size=0;\n top=null;\n }\n public int size(){\n return this.Size;\n }\n public void push(Object item){\n Node node=new Node();\n node.data=item;\n node.next=top;\n top=node;\n Size++;\n }\n public void pop(){\n if(top!=null)\n top=top.next;\n Size--;\n }\n public boolean isEmpty(){\n return top==null;\n }\n public Object getTop(){\n if(top!=null)\n return top.data;\n else\n return null;\n }\n public void display(){\n if(top!=null){\n Node temp=top;\n while(temp!=null){\n System.out.print(temp.data+\" \");\n temp=temp.next;\n }\n System.out.println();\n }\n }\n private class Node {\n Object data;\n Node next;\n } \n}\n private static class Scanner\n { \n BufferedReader br; \n StringTokenizer st; \n \n public Scanner()\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 BigInteger nextBigInteger()\n {\n return new BigInteger(next());\n }\n \n } \n }\n}/*", "lang_cluster": "Java", "compilation_error": true, "code_uid": "59be11ff2955f40695fbf7857d7b7fe6", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0} {"lang": "Java 8", "source_code": " import java.util.*;\nimport java.io.*;\n\n\n\npublic class sol\n{\n \n /********* SOLUTION STARTS HERE ************/\n static class graph{\n int n;\n ArrayList adj[];\n int wt[];\n graph(int v){\n n = v;\n adj = new ArrayList[n];\n for (int i=0;i();\n //adj[i].add(i);\n }\n wt = new int[n];\n for (int i=0;i i = adj[v].listIterator();\n while (i.hasNext())\n {\n int n = i.next();\n if (!visited[n])\n bfs(n, visited);\n }\n }\n } \n private static void solve(FastScanner s1, PrintWriter out){\n int n=s1.nextInt();\n int m=s1.nextInt();\n String s = s1.nextLine();\n String ss = s1.nextLine();\n if (s[0] == '<'){\n if (s[n-1] == '>'){\n if (ss[n-1] == '^'){\n if (ss[0] != ss[m-1]){\n System.out.println(\"YES\");\n } else{\n System.out.println(\"NO\");\n }\n } else {\n System.out.println(\"NO\");\n }\n } else {\n System.out.println(\"NO\");\n }\n } else {\n if (s[n-1] == '<'){\n if (ss[0] == '^'){\n if (ss[m-1] != ss[0]){\n System.out.println(\"YES\");\n } else{\n System.out.println(\"NO\");\n }\n } else {\n System.out.println(\"NO\");\n }\n } else {\n System.out.println(\"NO\");\n }\n }\n }\n /********** TEMPLATE STARTS HERE ***********/\n \n public static void main(String []args) throws IOException {\n FastScanner in = new FastScanner(System.in);\n PrintWriter out = \n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); \n solve(in, out);\n in.close();\n out.close();\n } \n \n static class FastScanner{\n BufferedReader reader;\n StringTokenizer st;\n FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;} \n String next()\n {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;} \n st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}\n String nextLine() {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;} \n int nextInt() {return Integer.parseInt(next());}\n long nextLong() {return Long.parseLong(next());} \n double nextDouble(){return Double.parseDouble(next());}\n char nextChar() {return next().charAt(0);}\n int[] nextIntArray(int n) {int[] arr= new int[n]; int i=0;while(i 0)\n {\n if(v == '^')\n {\n out++;\n }\n else\n {\n in++;\n }\n }\n \n //below\n if(ii < vStreet-1)\n {\n if(v == '^')\n {\n in++;\n }\n else\n {\n out++;\n }\n }\n \n //left\n if(i > 0)\n {\n if(h == '>')\n {\n in++;\n }\n else\n {\n out++;\n }\n }\n \n //right\n if(i < hStreet-1)\n {\n if(h == '>')\n {\n out++;\n }\n else\n {\n in++;\n }\n }\n \n //assess what type of node this is...\n if(out == in+1)\n {\n if(outOverin)\n {\n System.out.println(\"NO\");\n return;\n }\n \n outOverin = true;\n continue;\n }\n \n if(in == out+1)\n {\n if(inOverout)\n {\n System.out.println(\"NO\");\n return;\n }\n \n inOverout = true;\n continue;\n }\n \n //special one-time cases accounted for, rest have to be =\n if(in == out)\n {\n continue;\n }\n \n //freak situation, a lot more in than out, or vice versa\n System.out.println(\"NO\");\n return;\n }\n }\n \n //we finished iterating over all nodes\n if(inOverout && outOverin)\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b24610834c68056be0ee67e9931476ee", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Stack;\n\npublic class StronglyConnectedCity\n{\n\tpublic static class Node\n\t{\n int degreeIn;\n int degreeOut;\n\n public Node()\n {\n degreeIn = 0;\n degreeOut = 0;\n }\n }\n\t\n\tpublic static class Edge\n\t{\n\t\tint destination;\n\t\tboolean used;\n\n public Edge(int dest)\n {\n destination = dest;\n used = false;\n }\n \n public int otherNode(int vertex)\n {\n \tif (vertex == u)\n \t\treturn v;\n \telse if (vertex == v)\n \t\treturn u;\n \telse\n \t\tthrow new IllegalArgumentException(\"Invlaid edge\");\n }\n }\n\t\n\t/*public static Stack eulerianPath(List graph)\n\t{\n\t\tStack path = new Stack();\n\t\t\n\t\tint oddDegrees = 0;\n\t\tint start = 0;\n\t\tfor (int i = 0; i < graph.size(); i++)\n\t\t{\n\t\t\tif (graph.get(i).neighbors.size() % 2 != 0)\n\t\t\t\toddDegrees++;\n\t\t\t\tstart = i;\n\t\t}\n\t\tif (oddDegrees == 1 || oddDegrees > 2)\n\t\t\treturn path;\n\t\t\n\t\tQueue[] adj = (Queue[]) new Queue[graph.size()];\n\t\tfor (int i = 0; i < graph.size(); i++)\n\t\t{\n\t\t\tadj[i] = new LinkedList();\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < graph.size(); i++)\n\t\t{\n\t\t\tfor (Node next : graph.get(i).neighbors)\n\t\t\t{\n\t\t\t\tif (i < next.nodeNum)\n\t\t\t\t{\n\t\t\t\t\tEdge e = new Edge(i, next.nodeNum);\n\t\t\t\t\tadj[i].add(e);\n\t\t\t\t\tadj[next.nodeNum].add(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tStack stack = new Stack();\n\t\tstack.push(start);\n\t\t\n\t\twhile (!stack.isEmpty())\n\t\t{\n\t\t\tint node = stack.pop();\n\t\t\twhile (!adj[node].isEmpty())\n\t\t\t{\n\t\t\t\tEdge e = adj[node].poll();\n\t\t\t\tif (e.used)\n\t\t\t\t\tcontinue;\n\t\t\t\te.used = true;\n\t\t\t\tstack.push(node);\n\t\t\t\tnode = e.otherNode(node);\n\t\t\t}\n\t\t\tpath.push(node);\n\t\t}\n\t\t\n\t\treturn path;\n\t}*/\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tString horz = sc.nextLine();\n\t\tString vert = sc.nextLine();\n\t\tNode[][] nodes = new Node[n][m];\n\t\tfor (int r = 0; r < n; r ++)\n\t\t{\n\t\t\tfor (int c = 0; c < m; c++)\n\t\t\t{\n\t\t\t nodes[r][c] = new Node();\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tif (horz.charAt(i) == '>')\n\t\t\t{\n\t\t\t for (int c = 0; c < m - 1; c++)\n\t\t\t {\n\t\t\t nodes[i][c].degreeOut++;\n\t\t\t nodes[i][c + 1].degreeIn++;\n\t\t\t }\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t for (int c = m - 1; c > 0; c--)\n\t\t\t {\n\t\t\t nodes[i][c].degreeOut++;\n\t\t\t nodes[i][c - 1].degreeIn++;\n\t\t\t }\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < m; i++)\n\t\t{\n\t\t\tif (vert.charAt(i) == 'v')\n\t\t\t{\n\t\t\t for (int r = 0; r < n - 1; r++)\n\t\t\t {\n\t\t\t nodes[r][i].degreeOut++;\n\t\t\t nodes[r + 1][i].degreeIn++;\n\t\t\t }\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t for (int r = n - 1; r > 0; r--)\n\t\t\t {\n\t\t\t nodes[r][i].degreeOut++;\n\t\t\t nodes[r - 1][i].degreeIn++;\n\t\t\t }\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int r = 0; r < n; r++)\n\t\t{\n\t\t for (int c = 0; c < m; c++)\n\t\t {\n\t\t if (nodes[r][c].degreeIn == 0 || nodes[r][c].degreeOut == 0)\n\t\t {\n\t\t System.out.println(\"NO\");\n\t\t return;\n\t\t }\n\t\t }\n\t\t}\n\t\tSystem.out.println(\"YES\");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c78e3a5b8dd92d5bef0994fc94fa20c3", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n \n public static void main(String[] args) throws IOException {\n Scanner s = new Scanner(System.in);\n \n // number of streets\n int horiStreets = s.nextInt();\n int vertStreets = s.nextInt();\n \n // street directions\n s.nextLine();\n String horizontal = s.nextLine();\n String vertical = s.nextLine();\n \n boolean strong = true;\n \n char yOrigin = horizontal.charAt(0);\n char xOrigin = vertical.charAt(0);\n char yMax = horizontal.charAt(horiStreets - 1);\n char xMax = vertical.charAt(vertStreets -1);\n \n \n if (yOrigin == '>' && xOrigin == '^')\n strong = false;\n if (yMax == '<' && xOrigin == '^')\n strong = false;\n if (yOrigin == '>' && xMax == 'v') {\n strong = false;\n if (yMax == '<' && xMax == 'v')\n strong = false;\n \n if (strong)\n System.out.print(\"YES\");\n else\n System.out.print(\"NO\");\n \n s.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3b9c56ff8341d904a3eee4d6f0bd3c8", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class B{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tif (n>=36){\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\tString nombre = \"\";\n\t\tfor (int i=0;i 36)\n System.out.println(-1);\n if(k==0)\n System.out.println(1);\n if(k==1)\n System.out.println(4);\n int i;\n for( i=k;i>1;i-=2)\n System.out.print(8);\n if(i==1)\n System.out.println(4)\n } \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc61238a8cf3c070a8007110d7377bf8", "src_uid": "0c9973792c1976c5710f88e3520cda4e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "//package con2;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tSTDIN s= new STDIN();\n\t\tint n=s.nextInt();\n\t\tif(n%2==0){\n\t\t\tif(n/2<19){\n\t\t\t\tfor(int i=0;i<(n)/2;i++){\n\t\t\t\t\tSystem.out.print(\"8\");\n\t\t\t\t}\n\t\t\t\tSystem.exit(0);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t}else{\n\t\t\tif((n-1)/2<18){\n\t\t\t\tSystem.out.print(\"4\");\n\t\t\t\tfor(int i=0;i<(n-1)/2;i++){\n\t\t\t\t\tSystem.out.print(\"8\");\n\t\t\t\t}\n\t\t\t\tSystem.exit(0);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t}\n\t}\n\n}\n//class STDIN {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic STDIN() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tst = null;\n\t}\n\n\tboolean hasNext() throws Exception {\n\t\tif (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\treturn st.hasMoreTokens();\n\t}\n\n\tint nextInt() {\n\t\ttry{\n\t\treturn Integer.parseInt(next());\n\t\t}catch(Exception e){\n\t\t\tSystem.out.print(\"error\");\n\t\t\treturn-1;\n\t\t\t\n\t\t}\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tString next() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tString nextLine() throws Exception {\n\t\treturn br.readLine();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8ead0722f1a905c38a4e0ea1448b5bcb", "src_uid": "0c9973792c1976c5710f88e3520cda4e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int x=Math.floor(n/2);\n int val=0;\n for(int i=0;i 0) {\n ans += (n - 3) * (n - 4);\n }\n System.out.println(ans);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "289fb46052dc0008df82cc5293c0be23", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Main{\n public static void main(String[] args) {\n Scanner SC = new Scanner(System.in);\n int n = SC.nextInt();\n int sum=n-2;\n for(int i=n-3; i>0; i--){\n sum+=2*i;\n }\n System.out.println(sum);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "82f7b5dacc25dd2f17933d5f1260ee3b", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\n\npublic class TwoeightyfourA\n{\n public static int totient(int num){ //euler's totient function calculator. returns totient\n int count=0;\n for(int a=1;a=0&&b>=0)\n {\n t++;\n if(t%2!=0)\n a=a-t;\n else\n b=b-t;\n }\n if(a<0)\n System.out.println(\"Vladik\");\n else\n System.out.println(\"Valera\");\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7fabd3a853296dbca16759bff0da6f0c", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n \npublic class Solution {\n public static void main(String[] args){\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String s=br.readLine();\n String ar[]=s.split(\" \");\n int a=Integer.parseInt(ar[0]);\n int b=Integer.parseInt(ar[1]);\n if(a<=b){\n System.out.println(\"Valera\");\n }else{\n System.out.println(\"Vladik\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3beb58e622e73665ae5556bac877cac7", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import com.sun.org.apache.regexp.internal.RE;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n /*\n * Complete the function below.\n */\n public static void main(String[] args) throws IOException {\n //Scanner in = new Scanner(System.in);\n// System.setIn(new FileInputStream(new File(\"input.txt\")));\n// System.setOut(new PrintStream(new File(\"filename1.txt\")));\n Reader.init(System.in);\n Print print = new Print();\n\n int a = Reader.nextInt();\n int b = Reader.nextInt();\n\n int mA = 0;\n int mB = 0;\n\n int count = 0;\n\n while (a>=0 && b>=0) {\n if (count%2 == 0) {\n b-=count;\n } else {\n a-=count;\n }\n if (a<0){\n print.println(\"Vladik\");\n print.close();\n break;\n } else if (b<0) {\n print.println(\"Valera\");\n print.close();\n break;\n }\n count++;\n }\n\n //int m = Reader.nextInt();\n\n// for (int i = 0 ; i in1 = new ArrayList<>();\n// ArrayList in2 = new ArrayList<>();\n// //char in[][] = new char[r+1][c+1];\n// for (int j = 0 ; j < r; ++j){\n// in1.add(Reader.next());\n// }\n// char ans1 = '\\n';\n// for (int j = 0; j < in1.size(); ++j){\n// String temp = in1.get(j);\n// for (int k = 0; k < temp.length(); ++k){\n// if (temp.charAt(k) != '?'){\n// ans1 = temp.charAt(k);\n// }\n// }\n// }\n// for (int j = 0; j < in1.size(); ++j){\n// String temp = in1.get(j);\n// char[] tempArray = temp.toCharArray();\n// for (int k = 0; k < temp.length(); ++k){\n// if (tempArray[k] == '?'){\n// tempArray[k] = ans1;\n// }\n// }\n// in2.add(String.valueOf(tempArray));\n// }\n//\n//\n// print.print(\"Case #\");\n// print.print(i+1);\n// print.println(\":\");\n//\n// for (int j = 0; j < r; ++j){\n// print.println(in2.get(j));\n// }\n//\n//// if (m%p == 0) {\n//// t1 = m/p;\n//// } else {\n//// t1 = m/p + 1;\n//// }\n//\n//// if (t1 % 2 == 0) {\n//// ans1 = t1/2;\n//// ans2 = ans1 - 1;\n//// } else {\n//// ans1 = t1/2;\n//// ans2 = ans1;\n//// }\n//// print.print(input);\n//// print.print(\" \");\n//// print.println(k);\n// }\n\n\n }\n\n /** Class for buffered reading int and double values */\n static class ReaderMain {\n private static BufferedReader reader;\n private static StringTokenizer tokenizer;\n\n /** call this method to initialize reader for InputStream */\n static void init(InputStream input) {\n reader = new BufferedReader(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 static String nextLine() throws IOException {\n String str = \"\";\n try {\n str = reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n static Integer[] nextIntegerArray(int n) throws IOException {\n Integer[] a = new Integer[n];\n for(int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n static int[] nextIntArray(int n) throws IOException {\n int[] a = new int[n];\n for(int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n static char[] nextCharArray() throws IOException {\n return nextLine().toCharArray();\n }\n }\n\n class PrintMain {\n\n private final BufferedWriter bw;\n PrintMain() {\n this.bw=new BufferedWriter(new OutputStreamWriter(System.out));\n }\n void print(Object object)throws IOException {\n bw.append(\"\").append(String.valueOf(object));\n }\n void println(Object object)throws IOException {\n print(object);\n bw.append(\"\\n\");\n }\n void close()throws IOException {\n bw.close();\n }\n }\n\n\n\n}\n\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3baae5910260cd4f83073d533566152", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\npublic class Main{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int Vla=sc.nextInt();\n int val=sc.nextInt();\n int i=1;int j=2;\n String result=\"\";\n while(vla>0&&val>0){\n if(vla-i<0) {result=\"Vladik\";break;}\n if(vla-i>0){vla=vla-i;i+=2;}\n if(val-j<0){result=\"Valera\";break;}\n if(val-j>0){val=val-j;j=j+2;}\n }\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ee5bdfbe2c78f8fefa2408698c8a3909", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws Exception {\n MyScanner sc = new MyScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n long start = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n\n long end = System.currentTimeMillis();\n// pw.println(\"Used time \" + (end - start) + \"ms.\");\n pw.close();\n }\n\n public static class Task {\n\n public void solve(MyScanner sc, PrintWriter pw) throws IOException {\n int[] isprime = new int[1000010];\n Arrays.fill(isprime, 1);\n for (int i = 2; i < Math.sqrt(isprime.length) + 1; i++) {\n if (isprime[i] == 1) {\n for (long j = i + i; j < isprime.length; j+=i) {\n if (j > isprime.length) continue;\n isprime[(int)j] = i;\n }\n }\n }\n int a = sc.nextInt();\n if (isprime[a] == 1) {\n pw.println(a);\n return;\n }\n int bigfact = isprime[a];\n int mini = Integer.MAX_VALUE;\n for (int i = a - bigfact + 1; i <= a - 1; i++) {\n int m = isprime[i];\n int low = i - m + 1;\n mini = Math.min(low, mini);\n }\n pw.println(mini);\n\n }\n\n }\n\n\n\n static class MyScanner {\n StringTokenizer st;\n BufferedReader br;\n\n public MyScanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}\n\n public MyScanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}\n\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n public long nextLong() throws IOException {return Long.parseLong(next());}\n\n public String nextLine() throws IOException {return br.readLine();}\n\n public double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n public boolean ready() throws IOException {return br.ready();}\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d483f531a8ecd24533a241e9ef6e1885", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n \npublic class Main{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x2 = sc.nextInt();\n\t\tint rootx2 = (int)Math.sqrt((double)x2)+1;\n\t\tboolean[] isPrime = new boolean[x2+1];\n\t\tisPrime[2] = true;\n\t\tfor(int i=3;i<=x2;i+=2) isPrime[i] = true;\n\t\tfor(int i=3;i<=rootx2;i+=2){\n\t\t\tif(isPrime[i]){\n\t\t\t\tfor(int j=i*i;j<=x2;j+=2*i) isPrime[j] = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint p2 = maxPrime(x2,isPrime);\t\t\n\t\tint x0 = Integer.MAX_VALUE;\n\t\t\n\t\tfor(int x1=x2-p2+1;x1<=x2;++x1){\n\t\t\tif(!isPrime[x1]){\n\t\t\t\tint p1 = maxPrime(x1);\n\t\t\t\tx0 = Math.min(x0, p1*((x1/p1)-1)+1);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(x0!=Integer.MAX_VALUE) System.out.println(x0);\n\t\telse System.out.println(x2-p2+1);\n\t\treturn;\n\t}\n\t\n\tpublic static int maxPrime(int x){ //\u6700\u5927\u7d20\u56e0\u6570\n\t\tif(valid[x]) return x;\n\t\tint max = 0;\n\t\tint num = x;\n\t\twhile(num%2==0){num/=2; max=2;}\n\t\twhile(num%3==0){num/=3; max=3;}\n\t\twhile(num%5==0){num/=5; max=5;}\n\t\t\n\t\tint count = 0;\n\t\twhile(true){\n\t\t\tcount++;\n\t\t\tint prime = 6*count + 1;\n\t\t\tif(prime*prime>num) break;\n\t\t\tif(num%prime==0){\n\t\t\t\tnum /= prime;\n\t\t\t\tmax = prime;\n\t\t\t}\n\t\t\tprime += 4;\n\t\t\tif(prime*prime>num) break;\n\t\t\tif(num%prime==0){\n\t\t\t\tnum /= prime;\n\t\t\t\tmax = prime;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn Math.max(max, num);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d47462a91f176e1920db824ee02fed38", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class P4 {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n n = scan.nextInt();\n int[] f = new int[1000010];\n int x0 = n;\n\n for (int i = 2; i <= n; i++) {\n if (f[i] == 0) {\n for (int j = i + i; j <= n; j += i)\n f[j] = i;\n }\n }\n int min = 10000000;\n for (int i = n - f[n] + 1; i <= n; i++){\n min = Math.min(min, i - f[i] + 1);\n }\n System.out.println(min);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2cf318948c39b783a14040897e17eab3", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class A_Eound_470_Div1 {\n\n public static long MOD = 1000000007;\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 x = in.nextInt();\n boolean[]p = new boolean[1000001];\n TreeSet list = new TreeSet();\n for(int i = 2; i < p.length; i++){\n if(!p[i]){\n list.add(i);\n for(int j = i + i; j < p.length; j += i){\n p[j] = true;\n }\n }\n }\n if(list.contains(x)){\n out.println(x);\n }else{\n out.println(cal(x, list));\n }\n out.close();\n }\n static int cal(int x, TreeSet p){\n int re = x;\n Integer v = p.loww\n for(int i : p){\n if(i > x){\n break;\n }\n if(x % i == 0){\n int left = x/i;\n for(int j = (left - 1)*i + 1; j < x; j++){\n if(p.contains(j)){\n re = Integer.min(re, j);\n continue;\n }\n for(int k : p){\n if(k > j){\n break;\n }\n if(j% k == 0){\n int other = j / k;\n for(int h = (other - 1)*k + 1; h < j; h++){\n if(!p.contains(h)){\n // System.out.println(h + \" \" + j + \" \" + k + \" \" + i);\n re = Integer.min(re, h);\n break;\n }\n }\n }\n }\n }\n }\n }\n return re;\n }\n\n \n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7973a317da0031ec223c3215e5bed3ed", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n/*\n * \tHeart beats fast\n * \t\tColors and promises\n * \t\t\tHow to be brave\n * \t\t\t\tHow can I love when I am afraid to fall...\n */\npublic class Main\n{\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tint n =ni();\n\t\tlong a=1,b=1;\n\t\tlong ans=0;\n\t\tfor(i=1;i<=n;i++){\n\t\t\ta=(27*a)%mod;\n\t\t\tb=(7*b)%mod;\n\t\t\tans=(a-b+d)%mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic int bsl(int arr[],int data,int start,int end){\n\t\tint mid=start+(end-start)/2;\n\t\tif(arr[mid]==data)\n\t\t\treturn mid;\n\t\tif(end-start==1)\n\t\t\treturn mid;\n\t\telse if(data > arr[mid])\n\t\t\treturn bsl(arr,data,mid,end);\n\t\telse\n\t\t\treturn bsl(arr,data,start,mid);\n\t}\n\tstatic final int mod=1000000007;\n\tstatic final double eps=1e-8;\n\tstatic final long inf=100000000000000000L;\n\tstatic final boolean debug=true;\n\tstatic Reader in=new Reader();\n\tstatic StringBuilder ans=new StringBuilder();\n\tstatic long powm(long a, long b, long m)\n\t{\n\t\tlong an=1;\n\t\tlong c=a;\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tan=(an*c)%m;\n\t\t\tc=(c*c)%m;\n\t\t\tb>>=1;\n\t\t}\n\t\treturn an;\n\t}\n\tstatic Random rn=new Random();\n\tstatic void pd(){if(debug)ans.append(\"hola\");}\n\tstatic void pd(Object a){if(debug)ans.append(a+\"\\n\");}\n\tstatic void pr(Object a){ans.append(a+\"\\n\");}\n\tstatic void pr(){ans.append(\"\\n\");}\n\tstatic void p(Object a){ans.append(a);}\n\tstatic void sop(Object a){System.out.println(a);}\n\tstatic int ni(){return in.nextInt();}\n\tstatic int[] nia(int n){int a[]=new int[n];for(int i=0; i0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tc=c.concat(a);\n\t\t\ta=a.concat(a);\n\t\t\tb>>=1;\n\t\t}\n\t\treturn c;\n\t}\n\tstatic class Reader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public Reader() {\n reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n public double nextDouble() {\n \treturn Double.parseDouble(next());\n }\n }\n\tstatic class dyns\n\t{\n\t\tdyns(long le,long ri)\n\t\t{\n\t\t\tlb=le;\n\t\t\trb=ri;\n\t\t}\n\t\tdyns l,r;\n\t\tlong val,lb,rb;\n\t\tvoid set(long te)\n\t\t{\n\t\t\tval++;\n\t\t\tif(lb!=te||rb!=te)\n\t\t\t{\n\t\t\t\tif((lb+rb)/2>=te)\n\t\t\t\t{\n\t\t\t\t\tif(l==null)\n\t\t\t\t\t\tl=new dyns(lb, (lb+rb)/2);\n\t\t\t\t\tl.set(te);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(r==null)\n\t\t\t\t\t\tr=new dyns(((lb+rb)/2)+1,rb);\n\t\t\t\t\tr.set(te);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvoid reset(long a)\n\t\t{\n\t\t\tval--;\n\t\t\tif(val==0)\n\t\t\t{\n\t\t\t\tl=null;\n\t\t\t\tr=null;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(lb!=a||rb!=a)\n\t\t\t{\n\t\t\t\tif((lb+rb)/2>=a)\n\t\t\t\t\tl.reset(a);\n\t\t\t\telse\n\t\t\t\t\tr.reset(a);\n\t\t\t}\n\t\t}\n\t\tlong count(long le, long ri)\n\t\t{\n\t\t\tif(le<=lb&&ri>=rb)\n\t\t\t\treturn val;\n\t\t\tif(le>rb)\n\t\t\t\treturn 0;\n\t\t\tif(ri 0) {\n result = (result * 27 + 20 * num) % MOD;\n num = num * 7;\n number--;\n }\n return result;\n }\n public static void main(String[] args) {\n try {\n InputStreamReader in = new InputStreamReader(System.in);\n BufferedReader input = new BufferedReader(in);\n int lineNum = 0;\n String str;\n int number = 0;\n while (lineNum < 1 && (str = input.readLine()) != null) {\n number = Integer.parseInt(str);\n lineNum++;\n }\n System.out.println(getOutput(number));\n } catch (IOException io) {\n io.printStackTrace();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02bb39796d9c677085a5b71da9fe5a75", "src_uid": "eae87ec16c284f324d86b7e65fda093c", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\r\nimport java.io.BufferedWriter;\r\nimport java.io.FileNotFoundException;\r\nimport java.io.FileReader;\r\nimport java.io.FileWriter;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.io.PrintWriter;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class CF1528B_KaviOnPairingDuty {\r\n\r\n\tstatic class IO {\r\n\t\tprivate boolean type;\r\n\t\tprivate BufferedReader br;\r\n\t\tprivate StringTokenizer st;\r\n\t\tprivate PrintWriter pw;\r\n\r\n\t\tpublic IO() {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\ttype = false;\r\n\t\t}\r\n\r\n\t\tpublic IO(String file) {\r\n\t\t\ttype = true;\r\n\t\t\ttry {\r\n\t\t\t\tbr = new BufferedReader(new FileReader(file + \".in\"));\r\n\t\t\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(file + \".out\")));\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\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\r\n\t\tvoid print(Object b) {\r\n\t\t\tif (type)\r\n\t\t\t\tpw.print(b);\r\n\t\t\telse\r\n\t\t\t\tSystem.out.print(b);\r\n\t\t}\r\n\r\n\t\tvoid println(Object b) {\r\n\t\t\tif (type)\r\n\t\t\t\tpw.println(b);\r\n\t\t\telse\r\n\t\t\t\tSystem.out.println(b);\r\n\t\t}\r\n\r\n\t\tvoid println() {\r\n\t\t\tif (type)\r\n\t\t\t\tpw.println();\r\n\t\t\telse\r\n\t\t\t\tSystem.out.println();\r\n\t\t}\r\n\r\n\t\tvoid close() {\r\n\t\t\tif (type)\r\n\t\t\t\ttry {\r\n\t\t\t\t\tbr.close();\r\n\t\t\t\t\tpw.close();\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}\r\n\r\n\t\tvoid fill(int[] arr) {\r\n\t\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\t\tarr[i] = nextInt();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid fill(int[] arr, int add) {\r\n\t\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\t\tarr[i] = nextInt() + add;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid fill(int[][] arr) {\r\n\t\t\tfor (int[] a : arr)\r\n\t\t\t\tfill(a);\r\n\t\t}\r\n\r\n\t}\r\n\r\n\tstatic int countDivisors(int n) {\r\n\t\tint cnt = 0;\r\n\t\tfor (int i = 1; i <= Math.sqrt(n); i++) {\r\n\t\t\tif (n % i == 0) {\r\n\t\t\t\tif (n / i == i)\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\telse\r\n\t\t\t\t\tcnt = cnt + 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn cnt;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\tIO io = new IO();\r\n\t\tint n = io.nextInt();\r\n\t\tint[] dp = new int[n + 1];\r\n\t\tdp[1] = 1;\r\n\t\tint add = dp[1];\r\n\t\tfor (int i = 2; i <= n; i++) {\r\n\t\t\tdp[i] = (add + countDivisors(i)) % 998244353;\r\n\t\t\tadd += dp[i];\r\n\t\t\tadd %= 998244353;\r\n\t\t}\r\n\t\tio.println(dp[n]);\r\n\t}\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "89452e3ca4eed591f0787027283ce3ef", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0} {"lang": "Java 8", "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.*;\r\n\r\npublic class Main{\r\n\tpublic static StringTokenizer st=new StringTokenizer(\"\");\r\n\tpublic static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n\tpublic static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out));\r\n\tpublic static String nextstr() throws IOException {\r\n\t\twhile (!st.hasMoreTokens())\r\n\t\t\tst=new StringTokenizer(br.readLine());\r\n\t\treturn st.nextToken();\r\n\t}\r\n\tpublic static int nextint() throws NumberFormatException, IOException {\r\n\t\treturn Integer.parseInt(nextstr());\r\n\t}\r\n\tpublic static double nextdb() throws NumberFormatException, IOException {\r\n\t\treturn Double.parseDouble(nextstr());\r\n\t}\r\n\tpublic static long nextlong() throws NumberFormatException, IOException {\r\n\t\treturn Long.parseLong(nextstr());\r\n\t}\r\n\tpublic static void printf(String format,Object... args) {\r\n\t\tpw.printf(format, args);\r\n\t\tpw.flush();\r\n\t}\r\n\tpublic static void debug(String out) {\r\n\t\tSystem.out.println(out);\r\n\t}\r\n\t\r\n\tpublic static final int maxn=(int)1e6+5;\r\n\tpublic static final int inf=0x3f3f3f3f;\r\n\tpublic static final long mod=998244353;\r\n\t\r\n\tpublic static long d[]=new long[maxn];\r\n\t\r\n\tpublic static long dfs(int n) {\r\n\t\tif (d[n]!=-1) return d[n];\r\n\t\tif (n==1) {\r\n\t\t\td[1]=1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\td[n]=0;\r\n\t\tfor (int i=1;i*i<=n;i++)\r\n\t\t\tif (n%i==0) {\r\n\t\t\t\tif (i*i==n) \r\n\t\t\t\t\td[n]+=1;\r\n\t\t\t\telse d[n]+=2;\r\n\t\t\t}\r\n\t\t\r\n\t\tfor (int i=1;i n / 2 ? 1 : 0)) % 998244353;\n sum = (sum + dp[i]) % 998244353;\n }\n\n out.println(dp[n]);\n }\n\n public static void divisors(int x) {\n\n for (int i = 2; i <= x / 2; i++) {\n for (int j = 1; i * j <= x; j++) {\n divdp[i * j]++;\n }\n }\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n 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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e168105d55a090fc27a1447135ef551", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\r\n\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\n\r\npublic final class Solution\r\n{\r\n\r\n public static void main (String[] args)\r\n {\r\n Scanner s = new Scanner(System.in);\r\n\r\n int sum =0;\r\n int t = s.nextInt();\r\n int M=998244353;\r\n int N=1000000+100;\r\n int dp=new int[N];\r\n int k = (int)(10*Math.random());\r\n int n = s.nextInt();\r\n for(int i=1;i=M) dp[j]-=M;\r\n else if(dp[j]<0) dp[j]+=M;\r\n }\r\n }\r\n int sm=0;\r\n for(int i=1;i<=n;i++){\r\n\r\n dp[j]+=sm;\r\n if(dp[j]>=M) dp[j]-=M;\r\n else if(dp[j]<0) dp[j]+=M;\r\n\r\n sm+=dp[j];\r\n if(sm[j]>=M) sm-=M;\r\n else if(sm<0) sm+=M;\r\n }\r\n System.out.println(dp[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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0da097ec9d673d5ec3ec11f6880fefe5", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class forces {\n\n static int a[][]= new int[5][5];\n static int midr = 3;\n static int midc = 3;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n // String ip[] = br.readLine().trim().split(\"\\\\s+\");\n\n // int n = Integer.parseInt(ip[0]);\n // int m = Integer.parseInt(ip[1]);\n\n\n int n = Integer.parseInt(br.readLine());\n\n if(n>2){\n System.out.println(n-2);\n }\n \n else{\n Systen.out.println(n+2);\n }\n \n \n \n \n\t\t\n\t}\n\n\n public static String fun(String s){\n\n return \"\";\n }\n\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5661e2344dcb8b7c59684733dba725ee", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\npublic class S {\n\tpublic static void main (String[] args) {\n\t\tScanner in=new Scanner(System.in);\n\t\tint n=in.nextInt();\n\t\tSysten.out.println(n+2);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c607d05dc5f8ab00933341fd86b4ac2b", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97", "difficulty": 800.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage javaapplication7;\n\nimport java.util.Random;\nimport java.util.Scanner;\n\n/**\n *\n * @author fatsu\n */\npublic class JavaApplication7 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n //Random rand = new Random();\n Scanner reader = new Scanner(System.in);\n //int reader = rand.nextInt(999) + 1;\n \n// System.out.println(reader);\n \n int result;\n \n if(reader == 1){\n result = 5;\n } else if(reader == 2){\n result = 4;\n } else if(reader % 2 == 1){\n result = 3;\n } else {\n result = reader + 2;\n }\n \n// System.out.println(result);\n// System.out.println(reader*result + 1);\n \n System.out.print(result);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "081bff7bfe11d636ba5535db3f9b95e3", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class A{\n public static void main(String args[]){\n Scanner sc = new Scanner(System.in);\n int t ,n;\n \n n=sc.nextInt();\n if(n%2!=0)\n {\n if(n==1)\n System.out.println((3);\n else\n System.out.println(1); \n }\n else{\n for(int i=1;i<1000;i++){\n if(((n*i+1)%3==0 &&(n*i+1)!=3)||((n*i+1)%5==0 &&(n*i+1)!=5)||((n*i+1)%7==0 &&(n*i+1)!=7)){\n System.out.println(i);\n break;\n }\n \n }\n }\n \n \n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a00af9909823ee709be5cb931e35d274", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97", "difficulty": 800.0} {"lang": "Java 8", "source_code": "//*******************************************************************\n// Dear CompileJava users,\n//\n// CompileJava has been operating since 2013 completely free. If you\n// find this site useful, or would otherwise like to contribute, then\n// please consider a donation (link in 'More Info' tab) to support\n// development of the new CompileJava website (stay tuned!).\n//\n// Most sincerely, Z.\n//*******************************************************************\n\nimport java.lang.Math; // headers MUST be above the first class\n\n// one class needs to have a main() method\npublic class HelloWorld\n{\n // arguments are passed using the text field below this editor\n public static void main(String[] args)\n {\n Scanner nhapDuLieu = new Scanner(System.in);\n int n = nhapDuLieu.nextInt();\n int result = 0;\n if (n<10)\n \tresult = 1;\n else if (n%10 == 0)\n \tresult = 10 + LuckyYear(n/10)*10;\n else\n \tresult = LuckyYear(n);\n\tSystem.out.print(result);\n }\n \n public static int LuckyYear(int n)\n {\n \tif (n/10 == 0)\n {\n \treturn 0; \n }\n else if (n%10 == 0){\n \treturn 9 + LuckyYear(n/10)*10;\n }\n else {\n \treturn (10 - n%10) + LuckyYear(n/10)*10;\n }\n }\n}\n\n// you can add other public classes to this editor in any order\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e187f97c1802280360ae22f29755ef82", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Dhruv\n */\npublic class CF808A {\n public static void main(String args[]){\n\t\tTemplate.InputReader in = new Template.InputReader(System.in);\n\t\t//OutputStream outputStream = System.out;\n\t\tPrintWriter out = new PrintWriter(System.out);\n int n=in.nextInt();\n String s=n+\"\";\n int c=0;\n int l=s.length();\n for(int i =1;i 10) {\n if (n % 10 != 0) {\n return false;\n }\n n /= 10;\n }\n return true;\n// char[] c = String.valueOf(n).toCharArray();\n// for (int i = c.length - 1; i > 1; --i) {\n// if (c[c.length - i + 1] != '0') {\n// return false;\n// }\n// }\n// return true;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buffer = new byte[1024];\n private int current;\n private int size;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int read() {\n if (size == -1) throw new InputMismatchException();\n if (current >= size) {\n current = 0;\n try {\n size = stream.read(buffer);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (size <= 0) return -1;\n }\n return buffer[current++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceCharacter(c)) c = read();\n int sign = 1;\n if (c == '-') {\n sign = -1;\n c = read();\n }\n int result = 0;\n do {\n if (c < '0' || c > '9') throw new InputMismatchException();\n result *= 10;\n result += c - '0';\n c = read();\n } while (!isSpaceCharacter(c));\n return result * sign;\n }\n\n private boolean isSpaceCharacter(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7ea4c44abcacb3f8ed6fde257fd80d62", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n \n int N = sc.nextInt();\n \n int T = Math.log10(N);\n System.out.print(N + (int) Math.pow(10, T));\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a901988a07bdd08c7bf4c6b668a799df", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\n\npublic class E {\n\n int p2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,\n 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};\n\n boolean bitSetted(int code, int bitNo) {\n int tmp = code;\n for (int i = 0; i < bitNo; i++) {\n tmp /= 2;\n }\n return tmp % 2 == 1;\n }\n\n int clearBit(int code, int bitNo) {\n return code - p2[bitNo];\n }\n\n public static void main(String[] args) {\n new E().main();\n }\n int[][] gameLines = {\n // horizontal\n {0, 1, 2},\n {3, 4, 5, 6},\n {7, 8, 9, 10, 11},\n {12, 13, 14, 15},\n {16, 17, 18},\n // /-diag\n {7, 3, 0},\n {12, 8, 4, 1},\n {16, 13, 9, 5, 2},\n {17, 14, 10, 6},\n {18, 15, 11},\n // \\-diag\n {2, 6, 11},\n {1, 5, 10, 15},\n {0, 4, 9, 14, 18},\n {3, 8, 13, 17},\n {7, 12, 16}\n };\n boolean sg_values[] = new boolean[530000];\n boolean calculated[] = new boolean[530000];\n int ccount = 1;\n\n boolean canDoMove(int position, int gameLineNo, int left, int right) {\n for (int i = left; i <= right; i++) {\n if (!bitSetted(position, gameLines[gameLineNo][i])) {\n return false;\n }\n }\n return true;\n }\n\n int doMove(int position, int gameLineNo, int left, int right) {\n int res = position;\n for (int i = left; i <= right; i++) {\n res = clearBit(res, gameLines[gameLineNo][i]);\n }\n return res;\n }\n\n ArrayList inOneMove(Integer position) {\n ArrayList res = new ArrayList();\n\n for (int i = 0; i < gameLines.length; i++) {\n for (int left = 0; left < gameLines[i].length; left++) {\n for (int right = left; right < gameLines[i].length; right++) {\n if (canDoMove(position, i, left, right)) {\n res.add(doMove(position, i, left, right));\n }\n }\n }\n }\n return res;\n }\n\n // false, \u0435\u0441\u043b\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u043d\u0430\u044f\n // true, \u0435\u0441\u043b\u0438 \u0432\u044b\u0438\u0433\u0440\u044b\u0448\u043d\u0430\u044f\n boolean SG(Integer position) {\n if (calculated[position]) {\n return sg_values[position];\n }\n //System.out.println(\"Calculating SG for \" + position);\n boolean res = false;\n for (int x : inOneMove(position)) {\n if (!SG(x)){\n res = true;\n break;\n }\n }\n sg_values[position] = res;\n calculated[position] = true;\n return res;\n }\n\n void main() {\n String spos = \"\";\n Scanner in = new Scanner(System.in);\n for (int i = 0; i < 5; i++) {\n String line = in.nextLine();\n for (char c : line.toCharArray()) {\n if (c == '.' || c == 'O') {\n spos += c;\n }\n }\n }\n int now = 0;\n for (int i = 0; i < spos.length(); i++) {\n if (spos.charAt(i) == 'O') {\n now += p2[i];\n }\n }\n sg_values[0] = false;\n calculated[0] = true;\n if (!SG(now)) {\n System.out.println(\"Lillebror\");\n } else {\n System.out.println(\"Karlsson\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c01cc0fcba35f20e2c41abc0ddba99f8", "src_uid": "eaa022cc7846c983a826900dc6dd919f", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\n\npublic class E {\n\n int p2[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,\n 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};\n\n boolean bitSetted(int code, int bitNo) {\n int tmp = code;\n for (int i = 0; i < bitNo; i++) {\n tmp /= 2;\n }\n return tmp % 2 == 1;\n }\n\n int clearBit(int code, int bitNo) {\n return code - p2[bitNo];\n }\n\n public static void main(String[] args) {\n new E().main();\n }\n int[][] gameLines = {\n // horizontal\n {0, 1, 2},\n {3, 4, 5, 6},\n {7, 8, 9, 10, 11},\n {12, 13, 14, 15},\n {16, 17, 18},\n // /-diag\n {7, 3, 0},\n {12, 8, 4, 1},\n {16, 13, 9, 5, 2},\n {17, 14, 10, 6},\n {18, 15, 11},\n // \\-diag\n {2, 6, 11},\n {1, 5, 10, 15},\n {0, 4, 9, 14, 18},\n {3, 8, 13, 17},\n {7, 12, 16}\n };\n int sg_values[] = new int[530000];\n\n boolean canDoMove(int position, int gameLineNo, int left, int right) {\n for (int i = left; i <= right; i++) {\n if (!bitSetted(position, gameLines[gameLineNo][i])) {\n return false;\n }\n }\n return true;\n }\n\n int doMove(int position, int gameLineNo, int left, int right) {\n int res = position;\n for (int i = left; i <= right; i++) {\n res = clearBit(res, gameLines[gameLineNo][i]);\n }\n return res;\n }\n\n ArrayList inOneMove(Integer position) {\n ArrayList res = new ArrayList();\n\n for (int i = 0; i < gameLines.length; i++) {\n for (int left = 0; left < gameLines[i].length; left++) {\n for (int right = left; right < gameLines[i].length; right++) {\n if (canDoMove(position, i, left, right)) {\n res.add(doMove(position, i, left, right));\n }\n }\n }\n }\n return res;\n }\n\n // false, \u0435\u0441\u043b\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u043d\u0430\u044f\n // true, \u0435\u0441\u043b\u0438 \u0432\u044b\u0438\u0433\u0440\u044b\u0448\u043d\u0430\u044f\n int SG(Integer position) {\n if (sg_values[position]!=0){\n return sg_values[position];\n }\n //System.out.println(\"Calculating SG for \" + position);\n int res = -1;\n for (int x : inOneMove(position)) {\n if (SG(x)==-1){\n res = 1;\n break;\n }\n }\n sg_values[position] = res;\n return res;\n }\n\n void main() {\n String spos = \"\";\n Scanner in = new Scanner(System.in);\n for (int i = 0; i < 5; i++) {\n String line = in.nextLine();\n for (char c : line.toCharArray()) {\n if (c == '.' || c == 'O') {\n spos += c;\n }\n }\n }\n int now = 0;\n for (int i = 0; i < spos.length(); i++) {\n if (spos.charAt(i) == 'O') {\n now += p2[i];\n }\n }\n sg_values[0] = -1;\n if (SG(now)==-1) {\n System.out.println(\"Lillebror\");\n } else {\n System.out.println(\"Karlsson\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f37cbb542bf782e4af416b89e347efaf", "src_uid": "eaa022cc7846c983a826900dc6dd919f", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tBufferedReader in;\n\tStringTokenizer str = null;\n\tPrintWriter out;\n\t\n\tprivate String next() throws Exception{\n\t\twhile (str == null || !str.hasMoreElements())\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\treturn str.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate long nextLong() throws Exception{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate double nextDouble() throws Exception{\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tint []dp;\n\tint n = 5, m = 9;\n\tint []x,y;\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\tchar [][]a = new char[n][];\n\t\tfor(int i=0;i 0;\n\n\t\t// System.out.println(mask);\n\n\t\tchar [][]a = decode(mask);\n\t\tchar [][]b;\n\t\tfor(int i=0;i<19;i++){\n\t\t\tif (a[x[i]][y[i]] == 'O') {\n\t\t\t\tfor(int k=0;k= n || j >= m) return false;\n\t\treturn true;\n\t}\n\n\tprivate void print(char [][]a) {\n\t\tfor(int i=0;i 0) {\n\t\t\t\tr[x[i]][y[i]] = 'O';\n\t\t\t}else {\n\t\t\t\tr[x[i]][y[i]] = '.';\n\t\t\t}\n\t\t}\n\t\treturn r;\n\t}\n\t\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "809711e6eb9d45b9c6131268fdcaf1b6", "src_uid": "eaa022cc7846c983a826900dc6dd919f", "difficulty": 2000.0} {"lang": "Java 6", "source_code": " 1. import java.util.*;\n 2. import java.io.*;\n 3. import static java.lang.Math.*;\n 4.\n\n 5. public class Main{\n 6. public static void main(String[] args) throws Exception{\n 7. new Main().run();\n 8. }\n 9.\n\n 10. int[][] dp = new int[2][1<<19];\n 11. final int[] dh = new int[]{0, 3, 7, 12, 16};\n 12. final int[] dw = new int[]{3, 4, 5, 4, 3};\n 13. boolean firstWin(int p, boolean[] u){\n 14. int mask = toi(u);\n 15. if(mask == 0){\n 16. return p == 1;\n 17. }\n 18. if(dp[p][mask] != 0)return dp[p][mask] == 1;\n 19. boolean ok = false;\n 20. loop:\n 21. for(int i = 0; i < 5; i++){\n 22. for(int j = 0; j < dw[i]; j++){\n 23. int k = dh[i] + j;\n 24. if(!u[k])continue;\n 25. boolean[] v = new boolean[u.length];\n 26. for(int a = 0; a < v.length; a++)v[a] = u[a];\n 27. int cy = i, cx = j;\n 28. for(;;){\n 29. int ind = dh[cy] + cx;\n 30. v[ind] = false;\n 31. boolean ret = firstWin(1-p, v);\n 32. if(p == 0 && ret){\n 33. ok = true;\n 34. break loop;\n 35. }else if(p == 1 && !ret){\n 36. ok = true;\n 37. break loop;\n 38. }\n 39. cy++;\n 40. if(cy > 2)cx--;\n 41. if(cy >= 5 || cx < 0 || cx >= dw[cy] || !u[dh[cy] + cx])break;\n 42. }\n 43.\n\n 44. v = new boolean[u.length];\n 45. for(int a = 0; a < v.length; a++)v[a] = u[a];\n 46. cy = i; cx = j;\n 47. for(;;){\n 48. int ind = dh[cy] + cx;\n 49. v[ind] = false;\n 50. boolean ret = firstWin(1-p, v);\n 51. if(p == 0 && ret){\n 52. ok = true;\n 53. break loop;\n 54. }else if(p == 1 && !ret){\n 55. ok = true;\n 56. break loop;\n 57. }\n 58. cy++;\n 59. if(cy < 3)cx++;\n 60. if(cy >= 5 || cx < 0 || cx >= dw[cy] || !u[dh[cy] + cx])break;\n 61. }\n 62.\n\n 63. v = new boolean[u.length];\n 64. for(int a = 0; a < v.length; a++)v[a] = u[a];\n 65. cy = i; cx = j;\n 66. for(;;){\n 67. int ind = dh[cy] + cx;\n 68. v[ind] = false;\n 69. boolean ret = firstWin(1-p, v);\n 70. if(p == 0 && ret){\n 71. ok = true;\n 72. break loop;\n 73. }else if(p == 1 && !ret){\n 74. ok = true;\n 75. break loop;\n 76. }\n 77. cx++;\n 78. if(cy >= 5 || cx >= dw[cy] || !u[dh[cy] + cx])break;\n 79. }\n 80.\n\n 81. }\n 82. }\n 83. if(p == 0){\n 84. if(ok){\n 85. dp[p][mask] = 1;\n 86. return true;\n 87. }else{\n 88. dp[p][mask] = -1;\n 89. return false;\n 90. }\n 91. }else{\n 92. if(ok){\n 93. dp[p][mask] = -1;\n 94. return false;\n 95. }else{\n 96. dp[p][mask] = 1;\n 97. return true;\n 98. }\n 99. }\n 100. }\n 101.\n\n 102.\n\n\n 103. int toi(boolean[] u){\n 104. int ret = 0;\n 105. for(int i = 0; i < u.length; i++)if(u[i])ret += 1 << i;\n 106. return ret;\n 107. }\n 108.\n\n 109. void run() throws Exception{\n 110. Scanner sc = new Scanner(System.in);\n 111. //BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));\n 112. // only sc.readLine() is available\n 113. boolean[] u = new boolean[19];\n 114. for(int i = 0; i < 19; i++)u[i] = sc.next().equals(\"O\");\n 115. boolean ret = firstWin(0, u);\n 116. System.out.println(ret ? \"Karlsson\" : \"Lillebror\");\n 117. }\n 118. }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "255c0f24b81a455ca196de23499439b6", "src_uid": "eaa022cc7846c983a826900dc6dd919f", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 OmarYasser\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n static int smallest;\n static long[] memo;\n static int mod = 1000_000_007;\n\n static void smallest() {\n int n = (int) 5e6 + 10;\n smallest = new int[n + 1];\n Arrays.fill(smallest, Integer.MAX_VALUE);\n boolean primes[] = new boolean[n + 1];\n Arrays.fill(primes, true);\n primes[0] = primes[1] = false;\n for (int i = 2; i * i <= n; i++)\n if (primes[i]) {\n smallest[i] = i;\n for (int j = 2; i * j <= n; j++) {\n primes[i * j] = false;\n smallest[i * j] = Math.min(smallest[i * j], i);\n }\n }\n\n }\n\n static long f(int x) {\n if (x == 1) return 0;\n if (memo[x] != -1) return memo[x];\n long sm = smallest[x];\n return memo[x] = ((((sm * (sm - 1) / 2) % mod) * (x / sm) % mod) + f(x / (int) sm)) % mod;\n }\n\n public void solve(int testNumber, Scanner sc, PrintWriter out) {\n smallest();\n memo = new long[(int) 5e6 + 10];\n Arrays.fill(memo, -1);\n int t = sc.nextInt(), l = sc.nextInt(), r = sc.nextInt();\n long res = 0;\n for (int i = l, pow = 0; i <= r; i++, pow++) {\n res += (modular_exponentiation(t, pow, mod) * f(i) % mod);\n if (res >= mod) res -= mod;\n }\n out.println(res);\n }\n\n public static long modular_exponentiation(long a, long b, int c) {\n long ans = 1L;\n while (b != 0) {\n if ((b & (1)) == 1)\n ans = (ans * a) % c;\n\n a = (a * a) % c;\n b >>= 1L;\n }\n\n return ans;\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 Scanner(FileReader f) {\n br = new BufferedReader(f);\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens())\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a5f0d87a26b22bf902749f5e3c2fa884", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.*;\n\npublic class icpc\n{\n public static void main(String[] args) throws IOException\n {\n Reader in = new Reader();\n //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n long t = in.nextLong();\n int l = in.nextInt();\n int r = in.nextInt();\n long M = (long)1e9 + 7;\n int[] sieve = new NumberTheory().sieveOfEratosthenes(r);\n long[] dp = new long[r + 1];\n dp[1] = 0L;\n long[] pow = new long[r + 1];\n pow[0] = 1L;\n pow[1] = t % M;\n for (int i=2;i<=r;i++)\n {\n pow[i] = (pow[i - 1] * t) % M;\n dp[i] = (1L * i * (i - 1)) / 2;\n for (int j=2;j*j<=i;j++)\n {\n if (i % j == 0)\n {\n if (sieve[j] == 0)\n {\n long f1 = (long)i / j;\n long x = dp[j] * f1 + dp[(int)f1];\n dp[i] = Math.min(dp[i], x);\n }\n if (sieve[i / j] == 0)\n {\n long f1 = (long)i / j;\n long x = dp[j] * f1 + dp[(int)f1];\n dp[i] = Math.min(dp[i], x);\n }\n }\n }\n }\n long ans = 0L;\n for (int i=l;i<=r;i++)\n {\n ans = (ans + (pow[i - l] * (dp[i]) % M)) % M) % M;\n }\n System.out.println(ans);\n }\n}\nclass DSU\n{\n int[] parent;\n int[] size;\n //Pass number of total nodes as parameter to the constructor\n DSU(int n)\n {\n this.parent = new int[n];\n this.size = new int[n];\n Arrays.fill(parent, -1);\n }\n\n public void makeSet(int v)\n {\n parent[v] = v;\n size[v] = 1;\n }\n\n public int findSet(int v)\n {\n if (v == parent[v]) return v;\n return parent[v] = findSet(parent[v]);\n }\n\n public void unionSets(int a, int b)\n {\n a = findSet(a);\n b = findSet(b);\n if (a != b)\n {\n if (size[a] < size[b])\n {\n int temp = a;\n a = b;\n b = temp;\n }\n parent[b] = a;\n size[a] += size[b];\n }\n }\n}\nclass FastFourierTransform\n{\n private void fft(double[] a, double[] b, boolean invert)\n {\n int count = a.length;\n for (int i = 1, j = 0; i < count; i++)\n {\n int bit = count >> 1;\n for (; j >= bit; bit >>= 1)\n j -= bit;\n j += bit;\n if (i < j)\n {\n double temp = a[i];\n a[i] = a[j];\n a[j] = temp;\n temp = b[i];\n b[i] = b[j];\n b[j] = temp;\n }\n }\n for (int len = 2; len <= count; len <<= 1)\n {\n int halfLen = len >> 1;\n double angle = 2 * Math.PI / len;\n if (invert)\n angle = -angle;\n double wLenA = Math.cos(angle);\n double wLenB = Math.sin(angle);\n for (int i = 0; i < count; i += len)\n {\n double wA = 1;\n double wB = 0;\n for (int j = 0; j < halfLen; j++)\n {\n double uA = a[i + j];\n double uB = b[i + j];\n double vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;\n double vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;\n a[i + j] = uA + vA;\n b[i + j] = uB + vB;\n a[i + j + halfLen] = uA - vA;\n b[i + j + halfLen] = uB - vB;\n double nextWA = wA * wLenA - wB * wLenB;\n wB = wA * wLenB + wB * wLenA;\n wA = nextWA;\n }\n }\n }\n if (invert)\n {\n for (int i = 0; i < count; i++)\n {\n a[i] /= count;\n b[i] /= count;\n }\n }\n }\n\n public long[] multiply(long[] a, long[] b)\n {\n int resultSize = Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2;\n resultSize = Math.max(resultSize, 1);\n double[] aReal = new double[resultSize];\n double[] aImaginary = new double[resultSize];\n double[] bReal = new double[resultSize];\n double[] bImaginary = new double[resultSize];\n for (int i = 0; i < a.length; i++)\n aReal[i] = a[i];\n for (int i = 0; i < b.length; i++)\n bReal[i] = b[i];\n fft(aReal, aImaginary, false);\n fft(bReal, bImaginary, false);\n for (int i = 0; i < resultSize; i++)\n {\n double real = aReal[i] * bReal[i] - aImaginary[i] * bImaginary[i];\n aImaginary[i] = aImaginary[i] * bReal[i] + bImaginary[i] * aReal[i];\n aReal[i] = real;\n }\n fft(aReal, aImaginary, true);\n long[] result = new long[resultSize];\n for (int i = 0; i < resultSize; i++)\n result[i] = Math.round(aReal[i]);\n return result;\n }\n}\nclass NumberTheory\n{\n public boolean isPrime(long n)\n {\n if(n < 2)\n return false;\n for(long x = 2;x * x <= n;x++)\n {\n if(n % x == 0)\n return false;\n }\n return true;\n }\n public ArrayList primeFactorisation(long n)\n {\n ArrayList f = new ArrayList<>();\n for(long x=2;x * x <= n;x++)\n {\n while(n % x == 0)\n {\n f.add(x);\n n /= x;\n }\n }\n if(n > 1)\n f.add(n);\n return f;\n }\n public int[] sieveOfEratosthenes(int n)\n {\n //Returns an array with the smallest prime factor for each number and primes marked as 0\n int[] sieve = new int[n + 1];\n for(int x=2;x * x <= n;x++)\n {\n if(sieve[x] != 0)\n continue;\n for(int u=x*x;u<=n;u+=x)\n {\n if(sieve[u] == 0)\n {\n sieve[u] = x;\n }\n }\n }\n return sieve;\n }\n public long gcd(long a, long b)\n {\n if(b == 0)\n return a;\n return gcd(b, a % b);\n }\n public long phi(long n)\n {\n double result = n;\n\n for(long p=2;p*p<=n;p++)\n {\n if(n % p == 0)\n {\n while (n % p == 0)\n n /= p;\n result *= (1.0 - (1.0 / (double)p));\n }\n }\n if(n > 1)\n result *= (1.0 - (1.0 / (double)n));\n return (long)result;\n }\n public Name extendedEuclid(long a, long b)\n {\n if(b == 0)\n return new Name(a, 1, 0);\n Name n1 = extendedEuclid(b, a % b);\n Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y);\n return n2;\n }\n public long modularExponentiation(long a, long b, long n)\n {\n long d = 1L;\n String bString = Long.toBinaryString(b);\n for(int i=0;i= 0; --i) sa[--c[T[i]]] = i;\n for (p = 1; p < N; p <<= 1)\n {\n for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i;\n for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p;\n Arrays.fill(c, 0, ALPHABET_SZ, 0);\n for (i = 0; i < N; ++i) c[rank[i]]++;\n for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];\n for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];\n for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i)\n {\n if (!(rank[sa[i - 1]] == rank[sa[i]]\n && sa[i - 1] + p < N\n && sa[i] + p < N\n && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++;\n sa2[sa[i]] = r;\n }\n tmp = rank;\n rank = sa2;\n sa2 = tmp;\n if (r == N - 1) break;\n ALPHABET_SZ = r + 1;\n }\n }\n\n private void kasai()\n {\n lcp = new int[N];\n int[] inv = new int[N];\n for (int i = 0; i < N; i++) inv[sa[i]] = i;\n for (int i = 0, len = 0; i < N; i++)\n {\n if (inv[i] > 0)\n {\n int k = sa[inv[i] - 1];\n while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++;\n lcp[inv[i] - 1] = len;\n if (len > 0) len--;\n }\n }\n }\n}\nclass ZAlgorithm\n{\n public int[] calculateZ(char input[])\n {\n int Z[] = new int[input.length];\n int left = 0;\n int right = 0;\n for(int k = 1; k < input.length; k++) {\n if(k > right) {\n left = right = k;\n while(right < input.length && input[right] == input[right - left]) {\n right++;\n }\n Z[k] = right - left;\n right--;\n } else {\n //we are operating inside box\n int k1 = k - left;\n //if value does not stretches till right bound then just copy it.\n if(Z[k1] < right - k + 1) {\n Z[k] = Z[k1];\n } else { //otherwise try to see if there are more matches.\n left = k;\n while(right < input.length && input[right] == input[right - left]) {\n right++;\n }\n Z[k] = right - left;\n right--;\n }\n }\n }\n return Z;\n }\n public ArrayList matchPattern(char text[], char pattern[])\n {\n char newString[] = new char[text.length + pattern.length + 1];\n int i = 0;\n for(char ch : pattern) {\n newString[i] = ch;\n i++;\n }\n newString[i] = '$';\n i++;\n for(char ch : text) {\n newString[i] = ch;\n i++;\n }\n ArrayList result = new ArrayList<>();\n int Z[] = calculateZ(newString);\n\n for(i = 0; i < Z.length ; i++) {\n if(Z[i] == pattern.length) {\n result.add(i - pattern.length - 1);\n }\n }\n return result;\n }\n}\nclass KMPAlgorithm\n{\n public int[] computeTemporalArray(char[] pattern)\n {\n int[] lps = new int[pattern.length];\n\n int index = 0;\n for(int i=1;i KMPMatcher(char[] text, char[] pattern)\n {\n int[] lps = computeTemporalArray(pattern);\n\n int j = 0;\n int i = 0;\n int n = text.length;\n int m = pattern.length;\n ArrayList indices = new ArrayList<>();\n while(i < n)\n {\n if(pattern[j] == text[i])\n {\n i++;\n j++;\n }\n if(j == m)\n {\n indices.add(i - j);\n j = lps[j - 1];\n }\n else if(i < n && pattern[j] != text[i])\n {\n if(j != 0)\n j = lps[j - 1];\n else\n i = i + 1;\n }\n }\n return indices;\n }\n}\nclass Hashing\n{\n public long[] computePowers(long p, int n, long m)\n {\n long[] powers = new long[n];\n powers[0] = 1;\n for(int i=1;i= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException\n {\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}\nclass SegmentTree\n{\n public int nextPowerOfTwo(int num)\n {\n if(num == 0)\n return 1;\n if(num > 0 && (num & (num - 1)) == 0)\n return num;\n while((num &(num - 1)) > 0)\n {\n num = num & (num - 1);\n }\n return num << 1;\n }\n public int[] createSegmentTree(int[] input)\n {\n int np2 = nextPowerOfTwo(input.length);\n int[] segmentTree = new int[np2 * 2 - 1];\n\n for(int i=0;i= high){\n return segmentTree[pos];\n }\n if(qlow > high || qhigh < low){\n return Integer.MIN_VALUE;\n }\n int mid = (low+high)/2;\n return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1),\n rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2));\n }\n}\nclass Trie\n{\n\n private class TrieNode\n {\n Map children;\n boolean endOfWord;\n public TrieNode()\n {\n children = new HashMap<>();\n endOfWord = false;\n }\n }\n\n private final TrieNode root;\n public Trie()\n {\n root = new TrieNode();\n }\n\n public void insert(String word)\n {\n TrieNode current = root;\n for (int i = 0; i < word.length(); i++)\n {\n char ch = word.charAt(i);\n TrieNode node = current.children.get(ch);\n if (node == null)\n {\n node = new TrieNode();\n current.children.put(ch, node);\n }\n current = node;\n }\n current.endOfWord = true;\n }\n\n public boolean search(String word)\n {\n TrieNode current = root;\n for (int i = 0; i < word.length(); i++)\n {\n char ch = word.charAt(i);\n TrieNode node = current.children.get(ch);\n if (node == null)\n {\n return false;\n }\n current = node;\n }\n return current.endOfWord;\n }\n\n public void delete(String word)\n {\n delete(root, word, 0);\n }\n\n private boolean delete(TrieNode current, String word, int index)\n {\n if (index == word.length())\n {\n if (!current.endOfWord)\n {\n return false;\n }\n current.endOfWord = false;\n return current.children.size() == 0;\n }\n char ch = word.charAt(index);\n TrieNode node = current.children.get(ch);\n if (node == null)\n {\n return false;\n }\n boolean shouldDeleteCurrentNode = delete(node, word, index + 1);\n\n if (shouldDeleteCurrentNode)\n {\n current.children.remove(ch);\n return current.children.size() == 0;\n }\n return false;\n }\n}\nclass SegmentTreeLazy\n{\n public int nextPowerOfTwo(int num)\n {\n if(num == 0)\n return 1;\n if(num > 0 && (num & (num - 1)) == 0)\n return num;\n while((num &(num - 1)) > 0)\n {\n num = num & (num - 1);\n }\n return num << 1;\n }\n\n public int[] createSegmentTree(int input[])\n {\n int nextPowOfTwo = nextPowerOfTwo(input.length);\n int segmentTree[] = new int[nextPowOfTwo*2 -1];\n\n for(int i=0; i < segmentTree.length; i++){\n segmentTree[i] = Integer.MAX_VALUE;\n }\n constructMinSegmentTree(segmentTree, input, 0, input.length - 1, 0);\n return segmentTree;\n }\n\n private void constructMinSegmentTree(int segmentTree[], int input[], int low, int high,int pos)\n {\n if(low == high)\n {\n segmentTree[pos] = input[low];\n return;\n }\n int mid = (low + high)/2;\n constructMinSegmentTree(segmentTree, input, low, mid, 2 * pos + 1);\n constructMinSegmentTree(segmentTree, input, mid + 1, high, 2 * pos + 2);\n segmentTree[pos] = Math.min(segmentTree[2*pos+1], segmentTree[2*pos+2]);\n }\n\n public void updateSegmentTreeRangeLazy(int input[], int segmentTree[], int lazy[], int startRange, int endRange, int delta)\n {\n updateSegmentTreeRangeLazy(segmentTree, lazy, startRange, endRange, delta, 0, input.length - 1, 0);\n }\n\n private void updateSegmentTreeRangeLazy(int segmentTree[], int lazy[], int startRange, int endRange, int delta, int low, int high, int pos)\n {\n if(low > high)\n {\n return;\n }\n if (lazy[pos] != 0)\n {\n segmentTree[pos] += lazy[pos];\n if (low != high)\n {\n lazy[2 * pos + 1] += lazy[pos];\n lazy[2 * pos + 2] += lazy[pos];\n }\n lazy[pos] = 0;\n }\n\n if(startRange > high || endRange < low)\n {\n return;\n }\n\n if(startRange <= low && endRange >= high)\n {\n segmentTree[pos] += delta;\n if(low != high) {\n lazy[2*pos + 1] += delta;\n lazy[2*pos + 2] += delta;\n }\n lazy[pos] = 0;\n }\n\n int mid = (low + high)/2;\n updateSegmentTreeRangeLazy(segmentTree, lazy, startRange, endRange, delta, low, mid, 2*pos+1);\n updateSegmentTreeRangeLazy(segmentTree, lazy, startRange, endRange, delta, mid+1, high, 2*pos+2);\n segmentTree[pos] = Math.min(segmentTree[2*pos + 1], segmentTree[2*pos + 2]);\n }\n\n public int rangeMinimumQueryLazy(int segmentTree[], int lazy[], int qlow, int qhigh, int len)\n {\n return rangeMinimumQueryLazy(segmentTree, lazy, qlow, qhigh, 0, len - 1, 0);\n }\n\n private int rangeMinimumQueryLazy(int segmentTree[], int lazy[], int qlow, int qhigh, int low, int high, int pos)\n {\n if(low > high)\n {\n return Integer.MAX_VALUE;\n }\n if (lazy[pos] != 0)\n {\n segmentTree[pos] += lazy[pos];\n if (low != high)\n {\n lazy[2 * pos + 1] += lazy[pos];\n lazy[2 * pos + 2] += lazy[pos];\n }\n lazy[pos] = 0;\n }\n\n if(qlow > high || qhigh < low)\n {\n return Integer.MAX_VALUE;\n }\n\n if(qlow <= low && qhigh >= high)\n {\n return segmentTree[pos];\n }\n\n int mid = (low+high)/2;\n return Math.min(rangeMinimumQueryLazy(segmentTree, lazy, qlow, qhigh, low, mid, 2 * pos + 1), rangeMinimumQueryLazy(segmentTree, lazy, qlow, qhigh, mid + 1, high, 2 * pos + 2));\n }\n}\nclass BIT\n{\n int size;\n long[] table;\n public BIT(int size)\n {\n table = new long[size];\n this.size = size;\n }\n\n void update(int i, long delta)\n {\n while (i < size)\n {\n table[i] += delta;\n i += Integer.lowestOneBit(i);\n }\n }\n\n long sum(int i)\n {\n long sum = 0L;\n while (i > 0)\n {\n sum += table[i];\n i -= Integer.lowestOneBit(i);\n }\n return sum;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "deb081cc79025c8fdb36550c544812c3", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n atskb solver = new atskb();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class atskb {\n long mod = (long) Math.pow(10, 9) + 7;\n long[] dp;\n int[] prime;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n Random gen = new Random();\n long t = in.nextLong();\n int l = in.nextInt();\n int r = in.nextInt();\n long pow[] = new long[r - l + 1];\n pow[0] = 1;\n for (int i = 1; i < pow.length; i++) {\n pow[i] = (pow[i - 1] * t) % mod;\n }\n dp = new long[r + 1];\n for (int i = 0; i < r + 1; i++) {\n dp[i] = -1;\n }\n /* long sieve[]=new long[r+1];\n for (int i = 2; i = snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] sieve(int n) {\n int ar[] = new int[n + 1];\n ar[0] = 0;\n ar[1] = 1;\n for (int i = 2; i < ar.length; i++) {\n if (ar[i] == 0) {\n for (int k = i; k < ar.length; k = k + i) {\n if (ar[k] == 0) {\n ar[k] = i;\n }\n }\n }\n }\n return ar;\n\n\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3bb68c4684cccf9108619d721d8d77c", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable{\n\n\n static LinkedList adj[];\n static int co=0;\n\n static void Check2(int n){\n adj=new LinkedList[n+1];\n for(int i=0;i<=n;i++){\n adj[i]=new LinkedList();\n }\n\n }\n static void add(int i,int j){\n adj[i].add(j);\n\n\n }\n public static void main(String[] args) throws Exception {\n new Thread(null, new Main(), \"Check2\", 1<<26).start();// to increse stack size in java\n }\n public void run(){\n /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */\n //Scanner in=new Scanner(System.in);\n InputReader in=new InputReader(System.in);\n PrintWriter w=new PrintWriter(System.out);\n\n long pr[]=new long[50000001];\n \n for(int i=2;i<=5000000;i++){\n if(pr[i]==0){\n pr[i]=i;\n for(int j=2*i;j<=5000000;j+=i){\n if(pr[j]==0)pr[j]=i;\n \n }\n }\n \n }\n \n long ans[]=new long[5000001];\n long mod=(long)(1e9+7);\n \n for(int i=2;i<=5000000;i++){\n if(pr[i]==i){\n long p=(long)(i)*(long)(i-1);\n p=p/2;\n p%=mod;\n ans[i]=p;\n }\n else{\n long r=i/(pr[i]);\n \n long tp=(long)(pr[i])*(long)(pr[i]-1);\n \n tp/=2;\n tp=tp*r;\n tp=(tp%mod+ans[(int)r]%mod)%mod;\n ans[i]=tp;\n \n \n }\n }\n long t=in.nextLong();\n int l=in.nextInt();\n int r=in.nextInt();\n long mul=1l;\n long sum=0;\n for(int i=l;i<=r;i++){\n sum=sum%mod+(mul*(long)ans[i])%mod;\n sum%=mod;\n // w.println(sum);\n mul=(mul*t)%mod;\n }\n w.println(sum);\n \n \n \n\n w.close();\n\n\n }\n static int bs(ArrayList list,int x){\n\n\n int l=0;\n int r=list.size()-1;\n\n int ans=0;\n while(l<=r){\n int mid=(l+r)/2;\n\n if(list.get(mid)>=x){\n ans=mid;\n r=mid-1;\n }\n else\n l=mid+1;\n\n\n\n }\n\n\n\n\n\n return ans;\n\n }\n\n\n\n\nstatic long dp[][];\n static long mod=(long)(1e9+7);\n static long rec(int i,long m,int n,long a[]){\n\n if(i>n)return 0;\n if(i==n){\n if(m==0)return 1;\n else\n return 0;\n }\n\n\n long ans=0;\n\n\n ans=ans+rec(i+1,(m*10+a[i])%8,n,a);\n\n ans=ans+rec(i+1,m,n,a);\n ans%=mod;\n return dp[i][(int)m]=ans;\n\n\n\n\n\n\n\n\n }\n\nstatic int flag=0;\n static ArrayList flist;\n static void dfs(int i,int v[],ArrayList list){\n\n if(v[i]==0){\n\n v[i]=1;\n list.add(i);\n Iterator p=adj[i].iterator();\n while(p.hasNext()){\n Integer ne=p.next();\n if(list.contains(ne)){\n\n for(Integer pq:list){\n // System.out.println(i+\" \"+pq+\" \"+ne);\n flist.add(pq);\n }\n flag=1;\n }\n dfs(ne,v,list);\n\n }\n\n list.remove(new Integer(i));\n\n\n }\n\n\n }\n static class node{\n\n int y;\n int val;\n\n node(int a,int b){\n\n y=a;\n val=b;\n\n }\n\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 {\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\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9972bf8228a5c46e1ac6f4a96ee3ab3b", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main_A {\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tInputStreamReader in = new InputStreamReader(System.in);\n\t\tBufferedReader reader = new BufferedReader(in);\n\n\t\tdouble eps = 0.000001d;\n\n\t\tString[] t = reader.readLine().split(\" \");\n\t\tint[] num = new int[4];\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tnum[i] = Integer.parseInt(t[i]);\n\n\t\tint dist = num[1] - num[0];\n\t\tboolean isAr = true;\n\t\tfor (int i = 2; i < 4; i++) {\n\t\t\tif (dist != num[i] - num[i - 1]) {\n\t\t\t\tisAr = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (isAr) {\n\t\t\tSystem.out.println(num[3] + dist);\n\t\t\treturn;\n\t\t}\n\n\t\tdouble factor = (double) num[1] / num[0];\n\t\tboolean isGeo = true;\n\t\tfor (int i = 2; i < 4; i++) {\n\t\t\tif (Math.abs(num[i - 1] * factor - num[i]) > eps) {\n\t\t\t\tisGeo = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (isGeo) {\n\t\t\tSystem.out.println((int) (num[3] * factor));\n\t\t\treturn;\n\t\t}\n\n\t\tSystem.out.println(42);\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "54753b08c3e9977f8b9440730610b099", "src_uid": "68a9508d49fec672f9c61766d6051047", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class TR8_A {\n void solve() throws IOException {\n int a1 = nextInt();\n int a2 = nextInt();\n int a3 = nextInt();\n int a4 = nextInt();\n \n int d = a2-a1;\n if( ((a2+d)==a3) && ((a3+d)==a4)){//\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0438\u044e\n out.println(a4+d);\n }else{\n double q = a2/a1;\n double a5 = a4*q;\n if( (a1!=0) && (q!=0) && (q!=1)\n && (a2*q==a3) && (a3*q==a4) && (a5/((int)a5)==1)){//\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0438\u044e\n out.println(a5);\n }\n else out.println(42);\n }\n out.close();\n }\n\n \n BufferedReader in;\n StringTokenizer str;\n PrintWriter out;\n String SK;\n\n String next() throws IOException {\n while ((str == null) || (!str.hasMoreTokens())) {\n SK = in.readLine();\n if (SK == null)\n return null;\n str = new StringTokenizer(SK);\n }\n return str.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));//new FileReader(\"input.txt\"));\n out = new PrintWriter(System.out);//\"output.txt\");\n solve();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n new TR8_A().run();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7ff3dab1bc3f356c13248f3a305e18fb", "src_uid": "68a9508d49fec672f9c61766d6051047", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "public class Main{\n public static void main(String[] args)throws IOException{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String s=br.readLine();\n StringTokenizer st=new StringTokenizer(s);\n double []x=new double[4];\n for(int i=0;i<4;i++){\n x[i]=Double.parseDouble(st.nextToken());\n }\n double d=0;\n double q=0;\n boolean flag=false;\n if(x[0]-x[1]==x[1]-x[2] && x[1]-x[2]==x[2]-x[3]){\n d=x[1]-x[0];\n flag=true;\n }\n else if(x[0]/x[1] ==x[1]/x[2] && x[1]/x[2]==x[2]/x[3])\n q=x[1]/x[0];\n else{\n System.out.println(42);\n return;\n }\n if(flag==true){\n System.out.println((int)(x[3]+d));\n }\n else{\n if((int)(x[3]*q)==x[3]*q)\n System.out.println((int)(x[3]*q));\n else\n System.out.println(42);\n }\n }}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5e97a606ecc38da58ae75e069469a6a1", "src_uid": "68a9508d49fec672f9c61766d6051047", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class ChatRecord {\n\n public static int searchstring(String s,String S){\n if (s.length()>S.length())\n return -1;\n for(int i=0;i<=(S.length()-s.length());i++){\n if (s.equals(S.substring(i,i+s.length())))\n return i;\n }\n return -1;\n }\n \n public static boolean geometric(int x , int y , int z , int w){\n if (x == 0 || z==0 || y==0 || w==0){\n \n return false;\n }\n \n double a =y/x;\n \n double b =z/y;\n double c =w/z;\n if (a==b && b==c)\n return true;\n return false;\n }\n public static void main(String[] args){\n String I = \"1\";\n while (! I.equals(\"0\")){\n Scanner sc = new Scanner(System.in);\n String Input = sc.nextLine();\n int space = searchstring(\" \",Input);\n \n int x = Integer.parseInt(Input.substring(0,space));\n Input = Input.substring(space+1, Input.length());\n space = searchstring(\" \",Input);\n int y = Integer.parseInt(Input.substring(0,space));\n Input = Input.substring(space+1, Input.length());\n space = searchstring(\" \",Input);\n int z = Integer.parseInt(Input.substring(0,space));\n Input = Input.substring(space+1, Input.length());\n space = searchstring(\" \",Input);\n int w = Integer.parseInt(Input.substring(0,Input.length()));\n \n \n \n \n \n if ((y-x)==(z-y) && (z-y)==(w-z)){\n System.out.println(y-x+w);\n return;\n }\n else if (geometric(x,y,z,w)){\n if (x == 0 || y/x==1 || z==0 || y==0 || w==0){\n System.out.println(\"42\");\n return;\n }\n \n \n if ((w*w)%z == 0)\n System.out.println(w*w/z);\n else System.out.println(42);\n }\n else \n System.out.println(42);\n I = sc.nextLine();\n }\n \n }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b49a599bdef78ef4c7bbe47f699d55bd", "src_uid": "68a9508d49fec672f9c61766d6051047", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Dc {\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 res=0;\n int x=r;int y=g;int z=b; \n if(x<=y && x<=z){\n res+=x;y-=x;z-=x;x=0;\n }\n if(y<=x && y <=z) {\n res+=y;x-=y;z-=y;y=0;\n }\n if (z<=x && z<=y) {\n res+=z;x-=z;y-=z;z=0;\n }\n res+=x/3+y/3+z/3; \n if((r%3==0 && b%3==2 && g%3==2 ) || (g%3==0 && r%3==2 b%3==2) || (b%3==0 && g%3==2 && r%3==2)) {\n if(r!=0 || g!=0 || b!=0 ) res+=1;\n }\n System.out.println(res); \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6996cd8434a0bc3cca4a79c1507c4000", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Solution{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int r = sc.nextInt();\n int g = sc.nextInt();\n int b = sc.nextInt();\n int total = r/3 + g/3 + b/3;\n int rr = r%3;\n int gr = g%3;\n int br = b%3;\n int min = Math.min(Math.min(rr,gr),br)\n if(min > 0){\n total += min;\n rr -= min;\n gr -= min;\n br -= min;\n }\n if(rr*gr*br == 0 && rr+gr+br == 4 && total > 0){\n total++;\n }\n System.out.println(total);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "51013a428ef45793a08613a99242d515", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class haha {\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 r= in.nextLong();\n\t\tLong g= in.nextLong();\n\t\tLong b= in.nextLong();\n\n\t\tLong k=0;\n\t\tLong l;\n\t\tl=r/3;\n\t\tl+=g/3;\n\t\tl+=b/3;\n\t\tk=r%3 +b%3 +g%3;\n\t\tl+=k/3;\n\t\tSystem.out.println(l);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b9bc551f04cf6fadc3acee2a54ae615f", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class CeilFlowers {\n\n public static void main(String[] args)throws IOException {\n // TODO Auto-generated method stub\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n \n try\n {\n String str=br.readLine();\n String s[]=str.split(\" \");\n int r=Integer.parseInt(s[0]);\n int g=Integer.parseInt(s[1]);\n int b=Integer.parseInt(s[2]);\n int count=0;\n if(r%3==0)\n count+=r/3;\n if(g%3==0)\n count+=g/3;\n if(b%3==0)\n count+=b/3;\n if(r%3==1 && g%3==1 && b%3==1)\n count=r/3+g/3+b/3+1;\n if(r%3==2 && g%3==2 && b%3==2)\n count=r/3+g/3+b/3+2;\n if(r%3==1 && g%3==2 && b%3==0)\n count=r/3+g/3+b/3;\n if(r%3==0 && g%3==1 && b%3==2)\n count=r/3+g/3+b/3;\n if(r%3==1 && g%3==0 && b%3==2)\n count=r/3+g/3+b/3;\n System.out.println(count);\n \n }\n catch(Exception e)\n {\n e.printStackTrace();\n }\n \n \n \n \n \n }\n\n}\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class CeilFlowers {\n\n public static void main(String[] args)throws IOException {\n // TODO Auto-generated method stub\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n \n try\n {\n String str=br.readLine();\n String s[]=str.split(\" \");\n int r=Integer.parseInt(s[0]);\n int g=Integer.parseInt(s[1]);\n int b=Integer.parseInt(s[2]);\n int count=0;\n if(r%3==0)\n count+=r/3;\n if(g%3==0)\n count+=g/3;\n if(b%3==0)\n count+=b/3;\n if(r%3==1 && g%3==1 && b%3==1)\n count=r/3+g/3+b/3+1;\n if(r%3==2 && g%3==2 && b%3==2)\n count=r/3+g/3+b/3+2;\n System.out.println(count);\n \n }\n catch(Exception e)\n {\n e.printStackTrace();\n }\n \n \n \n \n \n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fbef2cdc89685e87fea284f4671449ec", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class main {\n\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s1 = sc.nextLine();\n\t\tString s[] = s1.split(\" \");\n\t\tint a[] = Arrays.stream(s).mapToInt(Integer::parseInt).toArray();\n\t\tint min =0,x=0,max=0,l = a[1]-1,r=a[2],n=a[0];\n\t\tmin += (n-l);\n\t\twhile(l>0) {\n\t\t\tmin += Math.pow(2, l);\n\t\t\tl--;\n\t\t}\n\t\twhile(x n-l+1) {\n min = min*2;\n }\n }\n\n //finds maximum\n for (int i = 0; i < n; i++) {\n int maxSum += max;\n if (i+1 < r) {\n max = max*2;\n }\n }\n\n System.out.print(min + \" \" + max);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "518802ea61c893ba9da04f53659a4634", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class B144\n {\n public static void main(String args[]) throws IOException\n {\n BufferedReader c=new BufferedReader(new InputStreamReader(System.in));\n //Scanner c=new Scanner(System.in);\n long n=Long.parseLong(c.readLine());\n \n \n long sqrt=(long) Math.sqrt(n);\n long flag=0;\n long min=sqrt;\n long ans=0;\n ans=sqrt*sqrt+digit(sqrt)*sqrt-n;\n if(ans==0)\n {\n System.out.println(sqrt);\n return;\n }\n else\n {\n int i=0;\n flag=0;\n min=sqrt;\n while(i<100000 && (sqrt-i)>0)\n {\n ans=(sqrt-i)(sqrt-i)+digit(sqrt-i)(sqrt-i)-n;\n if(ans==0)\n {\n if((sqrt-i) 0) {\n int p = (int) (n % 10);\n sum = sum + p;\n n = n / 10;\n }\n return sum;\n}\n }\n\n//must declare new classes here", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8e07ef221221c0bcd475fe1a3f524d29", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\npublic class abc\n{\n public static long calc(long x)\n {\n long sum=0L;String s=Long.toString(x);\n for(int i=0;i=n;x--)\n {\n if(((x*x)+(calc(x)*x))==n)\n {\n res=x;\n break;\n }\n }\n System.out.println(res);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "90e81073bdd286a3ac758c5a233b568b", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.*; \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 long digitsum(long n){\n long count = 0;\n while(n>0){\n count += n%10;\n n /= 10;\n }\n return count;\n }\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long m = (int)Math.sqrt(n);\n long l = (int)Math.sqrt(n/2);\n long ans = -1;\n while(l<=m){\n int mid = l+(m-l)/2;\n if((n-(long)Math.pow(m,2))%m==0 && (n-(long)Math.pow(m,2))/m==(long)digitsum(m)){\n ans = m;\n break;\n }\n else{\n l = m+1;\n }\n }\n System.out.println(ans);\n }\n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "176a09f8f1b68cdcf31d51202a9986d6", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class NonsquareEquation {\n\tpublic static void main (String[]args) throws IOException, InterruptedException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader (System.in));\n\n\n\t\tLong n =Long.parseLong(br.readLine());\n\t\tint c=0;\n\t\tfor(Long i=1L;c<90;i++) {\n\t\t\t\n\t\t\tif (n%i==0) {\n\n\t\t\t\tString s=i+\"\";\n\t\t\t c=0;\n\t\t\t\tfor(int j=0;j a1 + a2) {\n min = a1 + a2;\n }\n }\n if (k1 >= k2) {\n if (n >= k2 * a2) {\n max += a2;\n n -= (k2 * a2);\n if (n >= k1 * a1) {\n max += a1;\n } else {\n for (int i = 0; i < a1; i++) {\n if (k1 <= n) {\n max++;\n n -= k1;\n } else {\n break;\n }\n }\n }\n\n } else {\n for (int i = 0; i < a2; i++) {\n if (k2 <= n) {\n max++;\n n -= k2;\n } else {\n break;\n }\n }\n }\n } else {\n if (n >= k1 * a1) {\n max += a1;\n n -= (k1 * a1);\n if (n >= k2 * a2) {\n max += a2;\n } else {\n for (int i = 0; i < a2; i++) {\n if (k2 <= n) {\n max++;\n n -= k2;\n } else {\n break;\n }\n }\n }\n\n } else {\n for (int i = 0; i < a1; i++) {\n if (k1 <= n) {\n max++;\n n -= k1;\n } else {\n break;\n }\n }\n }\n }\n out.println(min + \" \" + max);\n out.flush();\n\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8c3d0f61fc68b1c57ad344e8ac1a9324", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class Main {\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int a1 = Integer.parseInt(br.readLine());\n int a2 = Integer.parseInt(br.readLine());\n int k1 = Integer.parseInt(br.readLine());\n int k2 = Integer.parseInt(br.readLine());\n int n = Integer.parseInt(br.readLine());\n\n int curr_a1 = a1;\n int curr_a2 = a2;\n int curr_cards = 0;\n int max = 0;\n for(int c = 0; c < n; c++) {\n curr_cards++;\n\n if (k1 <= k2) {\n if (curr_cards >= k1 && curr_a1 > 0) {\n max++;\n curr_cards = 0;\n curr_a1--;\n } else if (curr_cards >= k2 && curr_a2 > 0) {\n max++;\n curr_cards = 0;\n curr_a2--;\n }\n } else {\n if (curr_cards >= k2 && curr_a2 > 0) {\n max++;\n curr_cards = 0;\n curr_a2--;\n } else if (curr_cards >= k1 && curr_a1 > 0) {\n max++;\n curr_cards = 0;\n curr_a1--;\n }\n }\n }\n\n curr_a1 = a1;\n curr_a2 = a2;\n curr_cards = 0;\n int min = 0;\n boolean full1 = (k1 == 1), full2 = (k2 == 1);\n for(int c = 0; c < n; c++) {\n curr_cards++;\n\n if (full1 && full2) {\n if (curr_a1 > 0) {\n min++;\n curr_a1--;\n } else if (curr_a2 > 0) {\n min++;\n curr_a2--;\n }\n }\n\n if (!full1) {\n if (curr_cards + 1 > (k1 - 1) * a1) {\n full1 = true;\n curr_cards = 0;\n }\n } else if (!full2) {\n if (curr_cards + 1 > (k2 - 1) * a2) {\n full2 = true;\n curr_cards = 0;\n }\n }\n }\n\n System.out.println(min + \" \" + max);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c38119834cd5b4032b52a7627af878a4", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class Lesson3 {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int a1 = scanner.nextInt();\n int a2 = scanner.nextInt();\n int k1 = scanner.nextInt();\n int k2 = scanner.nextInt();\n int n = scanner.nextInt();\n\n int n2=0;\n\n int min=0,max=0;\n\n //min\n n2=k1>k2?k1*a1-a1:k2*a2-a2;\n\n if(n2k2?n2+(k2*a2-a2):n2+(k1*a1-a1);\n }\n if(n2(a1+a2)?(a1+a2):min;\n }\n\n //max\n int n3=0;\n n2=k1n){\n max=k1n){\n max=k1= '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 } \npublic class Test{\n public static void main(String []args) throws IOException{\n Reader sc = new Reader();\n int t1[] = new int[2];\n int t2[] = new int[2];\n t1[0] = sc.nextInt();\n t2[0] = sc.nextInt();\n t1[1] = sc.nextInt();\n t2[1] = sc.nextInt();\n int n = sc.nextInt();\n \n int max, min, amin, amax;\n int kmin = Math.min(t1[1], t2[1]);\n int kmax = t1[1]+t2[1]-kmin;\n if(kmax==t1[1]){\n amax = t1[0];\n amin = t2[0];\n }\n else{\n amin = t1[0];\n amax = t2[0];\n }\n //System.out.println(amin+\" \"+kmin);\n min = n-((kmax-1)*amax)-((kmin-1)*amin);\n max = (n-(Math.min(n/kmin, amin)*kmin))/kmax + Math.min(n/kmin, amin);\n\n //System.out.print((Math.min((n/kmin), amin))+\" \");\n System.out.print(min+\" \"+max);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b8e6ff1300d936a626856db94058b965", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.awt.*;\n\npublic class Main {\n static HashSet hs=new HashSet<>();\n public static void main(String[] args) throws Exception {\n FastReader sc = new FastReader();\n StringBuilder sb=new StringBuilder();\n StringBuilder a=new StringBuilder(sc.next()),b=new StringBuilder(sc.next());\n for(int i=0;i1) {\n a.replace(i,i+1,Character.toString(a.charAt(i)+1));\n System.out.println(a);\n return;\n }\n else{\n a.replace(i,i+1,Character.toString(a.charAt(i)+1));\n a.replace(i+1,a.length(),\"\");\n for(int j=i+1;j'a'){\n z=true;\n break;\n }\n }\n if(z) System.out.println(a);\n else System.out.println(\"No such string\");\n return;\n }\n }\n }\n System.out.println(\"No such string\");\n }\n}\nclass FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n int nextInt() { return Integer.parseInt(next()); }\n long nextLong() { return Long.parseLong(next()); }\n double nextDouble() { return Double.parseDouble(next()); }\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f0baaa89e49d475c8b0815fbcd11b6a7", "src_uid": "47618510d2a17b1cc1e6a688201d51a3", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n \npublic class Solution {\n \n private static final Scanner scanner = new Scanner(System.in);\n \n public static void main(String[] args) throws IOException {\n \n String t = scanner.nextLine();\n String s = scanner.nextLine();\n String out = \"\";\n int len = s.length();\n int sum = 0;\n int hihi = false;\n \n for (int i = 0; i < len; i++) {\n sum += (int)(s.charAt(i) - t.charAt(i));\n if(s.charAt(i) - t.charAt(i) > 1) {\n char tmp = (char) (t.charAt(i) + 1);\n out += tmp;\n hihi = true;\n } else if (s.charAt(i) - t.charAt(i) < 0) {\n System.out.println(\"No such string\");\n return;\n } else {\n char tmp = (char) (t.charAt(i) + 1);\n out += tmp;\n }\n }\n if (sum<=len) {\n System.out.println(\"No such string\");\n } else {\n System.out.println(out);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "068ac302c94c90ff78ae2e3fe4b328e9", "src_uid": "47618510d2a17b1cc1e6a688201d51a3", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution{\n\n\tpublic void run() throws IOException{\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString str1 = br.readLine();\n\n\t\tString str2 = br.readLine();\n\n\t\tchar [] arr = str1.toCharArray();\n\n\t\tint len = str1.length();\n\n\t\tint i = len-1;\n\n\t\twhile(arr[i]==z){\n\t\t\tarr[i] = 'a';\n\t\t\ti--;\n\t\t}\n\n\t\tarr[i] = (char)(arr[i] + 1);\n\t\t\t\n\n\t\tstr1 = new String(arr);\n\n\t\t\n\t\tif(str1.compareTo(str2) < 0)\n\t\t\tSystem.out.println(str1);\n\t\telse\n\t\t\tSystem.out.println(\"No such string\");\n\n\t\t\n\t}\n\t\n\tpublic static void main(String [] args) throws IOException{\n\n\t\tnew Solution().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e1cce769a5692481082af470d829a358", "src_uid": "47618510d2a17b1cc1e6a688201d51a3", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution{\n\n\tpublic void run() throws IOException{\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString str1 = br.readLine();\n\n\t\tString str2 = br.readLine();\n\n\t\t//char [] arr = str1.toCharArray();\n\n\t\tint len = str1.length();\n\n\t\t//arr[len-1] = (char)(arr[len-1] + 1);\n\n\t\t//str1 = arr.toString();\n\n\t\tstr1.charAt(len-1) = (char)(str1.charAt(len-1) + 1);\n\n\t\tif(str1.compareTo(str2) < 0)\n\t\t\tSystem.out.println(str1);\n\t\telse\n\t\t\tSystem.out.println(\"No such string\");\n\n\t\t\n\t}\n\t\n\tpublic static void main(String [] args) throws IOException{\n\n\t\tnew Solution().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d02bc2bba3470f485e289e15e75be1f2", "src_uid": "47618510d2a17b1cc1e6a688201d51a3", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class x{\npublic static void main(String[] args) {\n\nScanner s = new Scanner (System.in);\nString s1 = s.next();\nString s2 = s.next();\n\n\nchar[]arr1 = s1.toCharArray();\nchar[]arr2 = s2.toCharArray();\n\n\nint count1=0,count2=0;\nint count3 = 0 ;\nfor (int i=0 ; i unknown || morePlus < -unknown ||\n (morePlus+unknown) % 2 != 0) {\n out.printf(\"%.10f\\n\", 0.0);\n } else {\n int plusInUnknown = (morePlus + unknown) / 2; // + in the unknowns\n out.printf(\"%.10f\\n\",\n (double) combinations(unknown, plusInUnknown) / (1 << unknown));\n }\n }\n out.flush();\n }\n \n // The number of combinations by selecting k positions out of n ones. Note that\n // n<=10. There would not be any overflow.\n int combinations(int n, int k) {\n int p1 = 1, p2 = 1;\n for (int i = n; i >= k+1; i--) {\n p1 *= i;\n p2 *= i - k;\n }\n return p1 / p2;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f4b52ba066689af22b41d54eca6b0e1d", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n \n int []mas = new int[50];\n int colvo=0;\n \n public void rec (int curPos, int ques) {\n if (ques==0) {\n colvo++;\n mas[curPos+10]++;\n return;\n }\n rec (curPos-1, ques-1);\n rec (curPos+1, ques-1);\n }\n \n public void solve() throws IOException{\n int ideal=0;\n String str=nextToken();\n for (int i=0, len=str.length(); i unknown || morePlus < -unknown ||\n (morePlus+unknown) % 2 != 0) {\n out.printf(\"%.10f\\n\", 0.0);\n } else {\n int plusInUnknown = (morePlus + unknown) / 2; // + in the unknowns\n out.printf(\"%.10f\\n\",\n (double) combinations(unknown, plusInUnknown) / (1 << unknown));\n }\n }\n out.flush();\n }\n \n // The number of combinations by selecting k positions out of n ones. Note that\n // n<=10. There would not be any overflow.\n int combinations(int n, int k) {\n int p1 = 1, p2 = 1;\n for (int i = n; i >= k+1; i--) {\n p1 *= i;\n p2 *= i - k;\n }\n return p1 / p2;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a1a8273b5b78145c9835288bdf645d77", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.concurrent.LinkedBlockingQueue;\n[public class Codechef\n{ \n static String arr[];\n static ArrayListgraph[];\n static int size[];\n static boolean deleted[];\n static boolean vis[];\n static int MAX = 500001;\n static int a,b,n,maxa;\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t InputReader input = new InputReader(System.in);\n\t OutputWriter out = new OutputWriter(System.out);\n\t // input = new Scanner(System.in);\n\t n = input.readInt();\n\t b = input.readInt();\n\t a = input.readInt();\n\t int arr[] = new int[n];\n\t for(int i =0;itotal/2){\n\t findCentroid(child,size[child]);\n\t }\n\t }\n\t return v;\n\t}\n\tpublic static void calculateSubtreeSize(int v){\n\t size[v] = 1;\n\t vis[v] = true;\n\t for(int child:graph[v]){\n\t if(vis[child] || deleted[v])continue;\n\t calculateSubtreeSize(child);\n\t size[v]+=size[child];\n\t }\n\t}\n}\nclass Query{\n String s = null;\n public Query(String s){\n this.s = s;\n }\n}\nclass Node{\n int id,r,l;\n public Node(int r,int l,int id){\n this.r = r;\n this.l = l;\n this.id = id;\n }\n}\n class InputReader{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read() {\n\t\t\tif (numChars == -1) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t\t\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\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\tif (c < '0' || c > '9') {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\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\t\t\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\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\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && 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\t}\n\t\t\t\tif (c < '0' || c > '9') {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c == 'e' || c == 'E') {\n\t\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\t\t}\n\t\t\t\t\tif (c < '0' || c > '9') {\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t}\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long readLong() {\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\tif (c < '0' || c > '9') {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null) {\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t}\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t\t\n\t\tpublic String next() {\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\t\n class OutputWriter {\n\t\tprivate final PrintWriter writer;\n\t\t\n\t\tpublic OutputWriter(OutputStream outputStream) {\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t\t}\n\t\t\n\t\tpublic OutputWriter(Writer writer) {\n\t\t\tthis.writer = new PrintWriter(writer);\n\t\t}\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\t}\n\t\t\t\twriter.print(objects[i]);\n\t\t\t}\n\t\t\twriter.flush();\n\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\twriter.flush();\n\t\t}\n\t\t\n\t\tpublic void close() {\n\t\t\twriter.close();\n\t\t}\n\t\t\n\t\tpublic void flush() {\n\t\t\twriter.flush();\n\t\t}\n\t}\n\t \n//********************************************************************************************************************************\n//////////////////////////////////NOTESSS//////////////////////////////////////////////////////////////////////\n/*remember substring length you are dealing with take only those substrings\nchain like pattern -> linked list (or) to from Arrays\nfinding degree can be done during input scanning itself(ok&=true:false flag trick)\nlongest subsquence can be solved in O(n) itself incase of consecutive numbers why try all subsequence go o dp[i-1]\n(*******consecutive numberssssss*********)\ninitialize all global variables and collection ds\nswapping changes the arr so make sure initialize with the original again(careful from where to start after swapping)\nmissing out character when comparing ==0 instead of =='0'\nkeep going until a condition and start off from first ****stack***\nmeet in the middle algo\none dfs call will tell u the dfs of all nodes\n2d prefix array for max occurence of number in a range.also storing positions in case of duplicate numbers can\nhelp bring down the complexity to o(N) and considering ranges based on positions\n\nwhen u want to apply changes for a range PREFIX SUMS\nwant to know number of elements in range use preifx sum (or)l,r pointer from a particular point\nwhen u want to use binary search check if problem remains the same even after splitting to two parts\nchecking for range can be done using binary search i.e can this range stisfy a particular condition if so\ninclude more elements to tha range from left to right or right to left depending on the problem\n\nparity can also be checked to make elements equal(when making elements equal check what is allowed and what not\nand how to achieve it what are the result sets after applying the allowed moves like add 1 add 2.....)\n\neach step u want max range incase if its equal u select upon the condition---> what DS= ***PRIORITY QUEUE***\n*/\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e2aaf1931fbe41a04fcb52e0375fd76d", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.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 Actual solution is at the top\n *\n * @author @Ziklon\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n CGourmetCat solver = new CGourmetCat();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CGourmetCat {\n int[] type = {0, 1, 2, 0, 2, 1, 0};\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\n int a = in.readInt(), b = in.readInt(), c = in.readInt();\n\n long ans = 0;\n\n for (int start = 0; start < 7; ++start) {\n\n long low = 0, hih = 1L << 50;\n\n while (hih - low > 1) {\n long middle = (low + hih) >> 1;\n if (isPossible(middle, start, a, b, c)) low = middle;\n else hih = middle;\n }\n ans = Math.max(ans, low);\n }\n out.printLine(ans);\n }\n\n private boolean isPossible(long middle, int start, int a, int b, int c) {\n long[] need = new long[3];\n for (int i = 0; i < 7; ++i) {\n int id = type[(start + i) % 7];\n long v = (middle / 7) + ((middle % 7) > i ? 1 : 0);\n need[id] += v;\n }\n return need[0] <= a && need[1] <= b && need[2] <= c;\n }\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4507d746274f8b61e1727662e8b54f74", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.io.Reader;\nimport java.util.*;\npublic class GourmaentCAt {\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 public static void main(String arg[])\n {\n FastReader sc=new FastReader();\t\n long a=sc.nextLong();\n long b=sc.nextLong();\n long c=sc.nextLong();\n \n long week=Math.min((int)a/3,(int) b/2);\n week=Math.min(week,(int) c/2);\n \n int s[]=new int[7];\n s[0]=1;s[1]=1;s[4]=1;\n s[2]=2;s[6]=2;\n s[3]=3;s[5]=3;\n int max=Integer.MIN_VALUE;\n for(int i=0;i<7;i++)\n {\n long a1=a-week*3;\n long b1=b-week*2;\n long c1=c-week*2;\n int p=i;\n int x=0;\n while(true)\n {\n if(s[p%7]==1)\n a1--;\n else if(s[p%7]==2)\n b1--;\n else if(s[p%7]==3)\n c1--;\n \n if(a1<0 || b1<0 ||c1<0)\n break;\n p++;\n x++;\n \n }\n if(max= max) max = l;\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\t\n\t//0: F, 1: R, 2: S\n\tstatic int foodIndex(int day) {\n\t\tif(day == 0 || day == 3 || day == 6) return 0;\n\t\tif(day == 1 || day == 5) return 1;\n\t\treturn 2;\n\t}\n\t\n\t//counts = {a, b, c}\n\tstatic int length(int counts[], int startingDay) {\n\t\tint day = startingDay;\n\t\tint countsCopy[] = {counts[0], counts[1], counts[2]};\n\t\tfor(int i = 0; i < 7; i++) {\n\t\t\tif(countsCopy[foodIndex(day)] == 0) return i;\n\t\t\tcountsCopy[foodIndex(day)]--;\n\t\t\tday = ((day + 1) % 7);\n\t\t}\n\t\tint maxWeeksLeft = -1;\n\t\tfor(int i = 0; i < 3; i++) {\n\t\t\tif(maxWeeksLeft == -1 || countsCopy[i] / (counts[i] - countsCopy[i]) < maxWeeksLeft) maxWeeksLeft = countsCopy[i] / (counts[i] - countsCopy[i]);\n\t\t}\n\t\tfor(int i = 0; i < 3; i++) {\n\t\t\tcountsCopy[i] -= (counts[i] - countsCopy[i]) * maxWeeksLeft;\n\t\t}\n\t\tint restDays = 0;\n\t\twhile(true) {\n\t\t\tif(countsCopy[foodIndex(day)] == 0) return restDays + (maxWeeksLeft + 1) * 7;\n\t\t\tcountsCopy[foodIndex(day)]--;\n\t\t\tday = ((day + 1) % 7);\n\t\t\trestDays++;\n\t\t}\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "68c885cd29c7cd83e0257fbb15c538c5", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\n/**\n * Spend 5 to 10 minutes analyzing different approaches to solve Don't rush and\n * start coding first solution that comes to mind Right now best strategy is\n * analyze for 20 minutes and code 20 minutes 3 question 2 hour. Remaining 30\n * minutes is miscellaneous Simply coding and coding won't solve problem,\n * analyzing then coding will solve it Right now forget speed focus on\n * accuracy****\n */\npublic class Codeforces {\n\n\n\tpublic static void main(String args[]) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();\n\t\tint n = (int)(1e6)+10;\n\t\tint t[] = new int[n];\n\t\tArrays.fill(t, 0);\n\t\t\n\t\tfor (int x=a;x<=b;x++) {\n\t\t\tfor (int y=b;y<=c;y++) {\n\t\t\t\tt[x+y]++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i=n-2;i>=0;i--) t[i] = t[i] + t[i+1];\n\t\tint sum = 0;\n\t\tfor (int z=c;z<=d;z++) {\n\t\t\tsum = sum + t[z+1];\n\t\t}\n\t\t\n\t\tSystem.out.println(sum);\n\t\tin.close();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a648c8a6a98b486341c15ed64acb4983", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "//package CodeforcesJava;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public void solve(InputProvider in, PrintWriter out) throws IOException {\n int minA = in.nextInt();\n int maxA = in.nextInt();\n int minB = maxA;\n int maxB = in.nextInt();\n int minC = maxB;\n int maxC = in.nextInt();\n long totalCount = 0;\n for (int c = minC; c <= maxC; c++) {\n for (int b = Math.max(minB, c - maxA + 1); b <= maxB; b++) {\n totalCount += Math.max(0, maxA - Math.max(minA, c - b + 1) + 1);\n }\n }\n out.print(totalCount);\n }\n\n public static void main(String[] args) throws Exception {\n try (InputProvider input = new InputProvider(System.in);\n PrintWriter output = new PrintWriter(System.out)) {\n new Main().solve(input, output);\n }\n }\n\n public static class InputProvider implements AutoCloseable {\n\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputProvider(Reader reader) {\n this.reader = new BufferedReader(reader);\n }\n\n public InputProvider(InputStream input) {\n reader = new BufferedReader(new InputStreamReader(input));\n }\n\n public String next() throws IOException {\n if (Objects.isNull(tokenizer) || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public 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 String nextLine() throws IOException {\n return reader.readLine();\n }\n\n @Override\n public void close() throws Exception {\n reader.close();\n }\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ed498937b6c5292f2f10ce17a980463", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "//package cc;\nimport java.util.*;\npublic class Test {\n\t\npublic static void main(String [] arsg)\n{\nScanner s=new Scanner(System.in);\n\n\tint a,b,c,d;\n\ta=s.nextInt();\n\tb=s.nextInt();\n\tc=s.nextInt();\n\td=s.nextInt();\n\tlong count=0;\n\tfor(int x=a;x<=b;++x)\n\t{ \n\t\tint y=c-x;\n\t\tif(y 0 ) {\r\n System.out.println(a - 1);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "23d9fe26e5bc397f6e12a7b432695996", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\r\n \r\npublic class hello{\r\n public static void main(String args[]){\r\n Sacnner scanner=new Scanner(System.in);\r\n int N=scanner.nextInt();\r\n int M=scanner.nextInt();\r\n scanner.close();\r\n if(M!=1){\r\n System.out.println(N*(M-1));\r\n }\r\n else{\r\n System.out.println(N-1);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "afaad739466c04a68a357d391a1f51cb", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Glo{\r\n\t public static void main (String[] argv){\r\n\t Scanner input = new Scanner(System.in);\r\n\t long N = input.nextInt();\r\n\t long M = input.nextInt();\r\n\t if(M == 1){\r\n\t System.out.println(N-1);\r\n\t }\r\n\t else{\r\n\t System.out.println((M-1)*N);\r\n\t }\r\n\t }\r\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4b827a8a7fd86e6d5910951b2b55858f", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Compfest_14A {\r\n\r\n public static void main(String[] args) {\r\n Scanner in = new Scanner(System.in);\r\n PrintWriter pw = new PrintWriter(System.out);\r\n long R = in.nextInt();\r\n long C = in.nextInt();\r\n long answer;\r\n if (C == 1) {\r\n answer = R-1;\r\n } else {\r\n answer = (C-1)*R;\r\n }\r\n pw.println(answer);\r\n pw.close();\r\n }\r\n \r\n static void debug(Object...obj) {\r\n System.err.println(Arrays.deepToString(obj);\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8fd772adb55a5783f5c9d42df1d8d059", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Hieu Le\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n long low = in.nextLong();\n long high = in.nextLong();\n\n int answer = compute(n, low, high);\n out.println(answer);\n }\n\n private int compute(long n, long low, long high) {\n// System.out.printf(\"n: %d low: %d high: %d\\n\", n, low, high);\n if (high < low) {\n return 0;\n }\n if (n <= 1) {\n return n;\n }\n long length = getLength(n);\n// System.out.printf(\"length: %d\\n\", length);\n long semiLength = (length - 1) / 2;\n\n int result = 0;\n\n // Find the section in the left half.\n long leftLow = low;\n long leftHigh = Math.min(semiLength, high);\n result += compute(n / 2, leftLow, leftHigh);\n\n // Find the section in the right half.\n long rightLow = Math.max(1, low - semiLength - 1);\n long rightHigh = high - semiLength - 1;\n result += compute(n / 2, rightLow, rightHigh);\n\n if (n % 2 == 1 && low <= semiLength + 1 && high >= semiLength + 1) {\n ++result;\n }\n\n return result;\n }\n\n private long getLength(long n) {\n long highestSetBit = Long.highestOneBit(n);\n return (highestSetBit << 1) - 1;\n }\n\n }\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n private static final int BUFFER_SIZE = 32768;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(\n new InputStreamReader(stream), BUFFER_SIZE);\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b6c4689a3e9a336f3bbc793bc87b4188", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Contest399_B {\n\tpublic static void main(String[] aeoruiasorifasdfadf)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n=sc.nextLong();\n\t\tint l=sc.nextInt();\n\t\tint r=sc.nextInt();\n\t\tsc.close();\n\t\tString s = \"\";\n\t\tif (n==0) {System.out.println(0); return;}\n\t\tif (n==1) {System.out.println(1); return;}\n\t\tlong m=n;\n\t\t// interesting divisibility pattern from the binary digits\n\t\t\n\t\twhile (m>0) { s += Integer.toString(m % 2); m /= 2; }\n\t\t\n\t\tint sum = 0; \n\t\tfor (int i=l; i<=r; ++i)\n\t\t\tsum += Integer.parseInt(Character.toString(\n\t\t\t\t\ts.charAt(s.length() - 1 - v2(i))));\n\t\tSystem.out.println(sum);\n\t}\n\t\n\tpublic static int v2(int n)\n\t{\n\t\tif (n%2==1) return 0;\n\t\treturn 1 + v2(n/2);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4922fa0375dcdb789d672d3f90dd7ebb", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\npublic class B {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n \n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n long low = in.nextLong();\n long high = in.nextLong();\n \n int answer = 0;\n for (long i = low; i <= high; ++i)\n answer += compute(n, i);\n out.println(answer);\n }\n \n private int compute(long n, long position) {\n if (n <= 1) {\n return (int) n;\n }\n long semiLength = (getLength(n) - 1) / 2;\n \n if (position <= semiLength) {\n return compute(n / 2, position);\n }\n \n if (position == semiLength + 1) {\n return (int) (n % 2);\n }\n \n return compute(n / 2, position - semiLength - 1);\n }\n \n private long getLength(long n) {\n long highestSetBit = Long.highestOneBit(n);\n return (highestSetBit << 1) - 1;\n }\n }\n \n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n private static final int BUFFER_SIZE = 32768;\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "12a2c4e9b584014a7a5c253adfba8b45", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n \n \npublic class Main {\n\tstatic HashMap tmap;\n\tpublic static void main(String[] args) throws IOException{\n\t\t \tFastScanner sc = new FastScanner();\n\t\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\ttmap = new TreeMap();\n\t\t\tlong x =sc.nextLong();\n\t\t\tlong l =sc.nextLong();\n\t\t\tlong r =sc.nextLong();\n\t\t\tlong ans= 0L;\n\t\t\tfor(long i=l;i<=r;i++){\n\t\t\t\tans+=(long)solve(x,i);\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t}\n\t\n\tstatic long solve(long X , long Y){\n\t\tif(Y>count(X))\n\t\t\treturn 0;\n\t\tif(X==0)\n\t\t\treturn X;\n\t\tif(X==1)\n\t\t\treturn 1;\n\t\tlong tmp =count(X/2);\n\t\tif(tmp+1==Y)\n\t\t\treturn (X&1);\n\t\tif(Y>tmp)\n\t\t\treturn solve(X/2,tmp*2+1-Y+1);\n\t\telse\n\t\t\treturn solve(X/2,Y);\n\t\t\n\t}\n\tstatic long count(long X ){\n\t\tif(tmap.containsKey(X))\n\t\t\treturn (long) tmap.get(X);\n\t\tlong ans ;\n\t\tif(X==0 || X==1)\n\t\t\tans=1;\n\t\telse{\n\t\n\t\n\t\tans = 1+2*(long)count(X/2);\n\t\t}\n\t\t\n\t\t tmap.put(X, ans*1L);\n\t\t return ans;\n\t\t\n\t}\n\n\t\n\n\n\n\n\n\n\t\n\n\t\n\t\n\t\t\n\t\n\t\t\t\n\t\t\n\t\n\n\t\t\t\n\n\t\t\t\n\t\t\t\n\t\t\t\n\t\n\t\n\n\n\n\t\n\t\n\t\t\t \n\t\t\t\n\n\n\t\t\t\n\t\t\t\n\t\n\t\n\t\n\n\t\t\t\n\t\n\t\t\n\t\n\t\n\t\n\t\t\n\n\t\t\t\n\n\t\t\n\n\t\n\t\n\n\t\n\t\n\t\n\n\t\t\t\n\t\t\t\t\t\t\n\t\t\t\n\n\t\n\t\n\n\t\t\n\t\t\n\t\t\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\tstatic void shuffle(int[] a)\n\t{\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < n; ++i)\n\t\t{\n\t\t\tint r = i + (int)(Math.random() * (n - i));\n\t\t\tint tmp = a[r];\n\t\t\ta[r] = a[i];\n\t\t\ta[i] = tmp;\n\t\t}\n\t}\n\n\n\tstatic void generate(int[] p, int L, int R) {\n\t\t if (L == R) {\n\t\t \n\t\t \n\t\t }else { \n\t\t for (int i = L; i <= R; i++) {\n\t\t \tint tmp = p[L]; p[L] = p[i]; p[i] = tmp;//swap do\n\t\t generate(p, L+1, R);//recurse \n\t\t tmp = p[L]; p[L] = p[i]; p[i] = tmp;//unswap undo\n\n\t\t }\n\t\t }\n\t\t}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n}\n\t \n\n\n\t class point implements Comparable{\n\t\tint x ;int y ;\n\t\tpoint(int x ,int y){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Object arg0) {\n\t\t\tpoint p = (point)arg0;\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn -p.y+this.y;\n\t\t\t\n\t\t}\n\t\n\t\n\t\t\n\t}\n\t\n\t\n\t\n\n\n\n\n\n\n\n\n\n\n\n\t\n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \nclass FastScanner {\n \n \n \n \n BufferedReader br;\n StringTokenizer st;\n \n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n \n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n \n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fe5e365e03119c2b25054fb33024bda3", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class nauuoAndVotes {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int x = sc.nextInt();\n int y = sc.nextInt();\n int z = sc.nextInt();\n\n if (x > y + z) {\n System.out.println(\"+\");\n }\n else if (y > x + z) {\n System.out.println(\"-\");\n }\n else if (x==y && z==0) {\n System.out.println(\"0\");\n }\n else if(x==y+z && x+z>y || y==x+z && y+z>x){\n System.out.println(\"?\");\n }\n else if(x==y&&z>0){\n System.out.println(\"?\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "451b19ab193c8a713c28a94be9715985", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0} {"lang": "Java 11", "source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Arrays;\nimport java.math.BigInteger;\n \n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n \tScanner in =new Scanner(System.in);\n\t\tint t=1,i,j,m=0,h,l,x,y,z,d,n,k,p;\n\t\tString s=\"\",st;\n\t\tchar c;\n\t\tfor(i=0;iy)\n\t\t c='+';\n\t\t else if(y>x)\n\t\t c='-';\n\t\t else if(z>0) \n\t\t c='?';\n\t\t else if(z==0)\n\t\t c='0';\n\t\t }\n\t\t else if(x==y && z==0)\n\t\t c='0';\n\t\t else\n\t\t c='?';\n\t\t System.out.println(c);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f73667634e813e74b746ff931961d668", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner in = new Scanner(System.in);\n\t\tint x = in.nextInt();\n\t\tint y = in.nextInt();\n\t\tint z = in.nextInt();\n\t\tif (Math.abs(x-y)y)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"+\");\t\n\t\t\t}\n\t\t\tif (xz){\n System.out.println(\"+\");\n }\n else if((-a)>z){\n System.out.println(\"-\");\n }\n else if(a==0&&z==0){\n System.out.println(\"0\");\n }\n else {\n System.out.println(\"?\");\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c41dcca47f6a899a7bb5a8733aaf31d9", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n \n long x = sc.nextLong();\n long y = sc.nextLong();\n long z = sc.nextLong();\n \n sc.nextLine();\n \n long a = sc.nextLong();\n long b = sc.nextLong();\n long c = sc.nextLong();\n \n if(a >= x) {\n a -= x;\n \n if((a+b) >= y) {\n int remainingGrapes = a+b+c - y;\n \n if(remainingGrapes >= c) {\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 else {\n System.out.println(\"NO\"); \n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "250c125d624f0f580f9003f74b50ecaa", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package\nimport java.util.Scanner;\n\npublic class JavaApplication63 {\n public static void main(String[] args) {\n Scanner w =new Scanner(System.in);\n int x,y,z,a,b,c;\n x=w.nextInt();\n y=w.nextInt();\n z=w.nextInt(); \n a=w.nextInt();\n b=w.nextInt();\n c=w.nextInt();\n \n if(aa+b&&a>x){System.out.println(\"NO\");}\n \n else if(z>a+b+c&&y==a+b&&a>x){System.out.println(\"NO\");}\n else{System.out.println(\"YES\");}\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4649afc5b1eeed2a9f969353adfdd583", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class Grapes {\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int x = sc.nextInt();\n int y = sc.nextInt();\n int z = sc.nextInt();\n int green = sc.nextInt();\n int purple = sc.nextInt();\n int black = sc.nextInt();\n int flag = 0 ;\n if(green-x>=0)\n {\n purple += green-x;\n if(purple-y>=0)\n {\n black+=purple-y;\n if(black-z>=0)\n {\n flag = 1;\n }\n }\n \n }\n if(flag == 1)\n System.out.println(\"YES\");\n \n else\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1b52be409269f9edfdddbbb21e3afc55", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.;\n\npublic class mainfile {\n public static void main(String[] args)\n {\n int a, b, c, x, y, z;\n\n Scanner grape = new Scanner(System.in);\n x = grape.nextInt();\n y = grape.nextInt();\n z = grape.nextInt();\n\n Scanner box = new Scanner(System.in);\n a = box.nextInt();\n b = box.nextInt();\n c = box.nextInt();\n\n if(a >= x)\n {\n if(a-x + b >= y)\n {\n if(a + b - x - y + c >= z)\n {\n System.out.println(\"YES\");\n }\n }\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4bd1357cd109707e178858ff318db449", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class QueueAtTheSchool{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n int numChildren = scan.nextInt();\n int t = scan.nextInt();\n \n char[] positions = scan.next().toCharArray();\n \n for(int i=0;i max) {\n maxi = i;\n max = count;\n }\n }\n System.out.println(\"\" + maxi);\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "95c5b4fbdd5cd2d69f769e28a263bdaa", "src_uid": "a8d992ab26a528f0be327c93fb499c15", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class problem1_ver2 {\n public static void main(String[] args) {\n Scanner input=new Scanner(System.in);\n int l=input.nextInt();\n int s=input.nextInt();\n int size=s-l;\n if(size>1){\n if(size%2==0)\n System.out.println(2);\n else\n System.out.println(3);\n }\n else{\n if(l%2==0 || s%2==0)\n System.out.println(2);\n else\n System.out.println(3);\n\n }}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2757aa215a279d441c9fcbe033160f4d", "src_uid": "a8d992ab26a528f0be327c93fb499c15", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\nimport java.util.Arrays;\npublic class FakeNP{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint min = scan.nextInt();\n\t\tint max = scan.nextInt();\n\t\tint tempMaxDivisor = 0;\n\t\tint maxDivisor = 0;\n\t\tString divisors = \"\";\n\n\t\tfor(int x = min; x <= max ; x++){\n\t\t\tfor(int y = 2 ; y <= min ; y++){\n\t\t\t\tif(x % y == 0){\n\t\t\t\tdivisors += divisors + y + \" \";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tString [] input = divisors.split(\" \");\n\t\tint [] numbers = new int[input.length];\n\t\tfor(int x = 0; x< numbers.length ; x++){\n\t\t\tnumbers[x] = Integer.parseInt(input[x]);\n\t\t}\n\t\tFakeNP sort = new FakeNP();\n\t\tnumbers = sort.sortArray(numbers);\n\t\tint count = 0;\n\t\tfor(int x = 0; xcount){\n\t\t\t\tmaxDivisor = tempMaxDivisor;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(maxDivisor);\n\t}\n\n\tpublic int[] sortArray(int[] array){\n\t\tfor(int x = 0 ; x< array.length -1 ; x++){\n\t\t\tfor(int y = 0 ; y< array.length ; y++){\n\t\t\t\tif(array[y] < array[x]){\n\t\t\t\t\tint temp = array[x];\n\t\t\t\t\tarray[x] = array[y];\n\t\t\t\t\tarray[y] = temp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn array;\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9689b15d73350c7499ea203cfa1cc064", "src_uid": "a8d992ab26a528f0be327c93fb499c15", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class TwoButtons520B{\n\n public static void main(String[] args){\n Scanner input = new Scanner(System.in);\n int n = input.nextInt(); // strat\n int m = input.nextInt(); // goal\n\n Queue q = new LinkedList();\n int[] visited = new int[200001];\n Array.fill(visited, -1);\n visited[n] = 0; // L^{0}\n q.add(n);\n\n while(!q.isEmpty()){\n int b = q.remove();\n if(v==m){\n System.out.println(visited[u]);\n return;\n }\n\n int a = b<<1;\n if(a <= 20000 && visited[v] == -1){\n visited[a] = visited[u] + 1;\n q.add(a);\n }\n\n int u = b - 1;\n if(u > 0 && visited[u] == -1){\n visited[u] = visited[b] + 1;\n q.add(u);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea615d0ca1702a7b1d95fd4da7f98a4b", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution {\n boolean[] visited = new boolean[10001];\n int[] dist = new int[10001];\n \n public int twoButtons(int start, int end) {\n Queue queue = new LinkedList<>();\n queue.add(start);\n visited[start] = True;\n \n while (!queue.isEmpty()) {\n int current = queue.poll();\n \n if (!visited[current * 2] && (current * 2 <= m * 2)) {\n visited[current * 2] = True;\n queue.add(current * 2);\n dist[current * 2] = dist[current] + 1;\n }\n \n if (!visited[current - 1] && (current - 1 >= 0)) {\n visited[current - 1] = True;\n queue.add(current - 1);\n dist[current - 1] = dist[current] + 1;\n }\n \n if (visited[end])\n break;\n }\n return dist[m];\n }\n \n // private static Integer[] cache = new Integer[10001];\n \n // public static int twoButtons(int start, int end) {\n // if (start >= end)\n // return start - end;\n \n // if (start < 1)\n // return Integer.MAX_VALUE;\n \n // if (cache[start] != null)\n // return cache[start];\n \n // int red = 1 + twoButtons(start * 2, end);\n // int blue = Integer.MAX_VALUE;\n // if (start > 1 && start > end / 2)\n // blue = 1 + twoButtons(start - 1, end);\n \n // cache[start] = Math.min(red, blue);\n \n // return cache[start];\n \n // }\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int start = sc.nextInt(), end = sc.nextInt();\n int result = twoButtons(start, end );\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea712b1394fcd1ce2b9d7ad9bc991afa", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.lang.Math;\n\npublic class TwoButtons {\n\n public static void main(String[] args) {\n String input = \"\";\n try{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n input = br.readLine();\n } catch(IOException io){\n io.printStackTrace();\n }\n String[] inputArray = input.split(\" \");\n int start = Integer.parseInt(inputArray[0]);\n int finish = Integer.parseInt(inputArray[1]);\n\n int step = Integer.MAX_VALUE;\n int j = 0;\n if (finish <= start) {\n int remainder = start - finish;\n step = remainder;\n } else {\n int pow = (int) Math.pow(2, j);\n while (2 * finish > start * pow) {\n int left = start * pow;\n int remainder = left - finish;\n if (remainder >= 0) {\n if (pow < remainder) {\n int modulo = remainder % pow;\n int currStep = toBinary(modulo);\n int rate = remainder / pow;\n step = Math.min(step, rate + currStep + j);\n } else {\n int currStep = toBinary(remainder);\n step = Math.min(step, currStep + j);\n }\n }\n j++;\n pow *= 2;\n }\n }\n System.out.println(step);\n }\n\n public int toBinary(int number) {\n int result = 0;\n for (int i = 15; i >= 0; i--) {\n if ((input & (1 << i)) != 0) {\n result++;\n }\n }\n return result;\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "11ded3a3656bf6be20d106f98d932326", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n \npublic class Main {\n \n private class Node() {\n int value;\n int distance;\n \n private Node(int value, int distance) {\n this.value = value;\n this.distance = distance;\n }\n \n }\n \n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int start = scan.nextInt();\n int goal = scan.nextInt();\n Node first = new Node(start, 0);\n \n \n Queue q = new LinkedList();\n q.push(first);\n while(!q.isEmpty()) {\n Node current = q.pop();\n currVal = current.value;\n currDist = current.Distance;\n if(currVal == goal) {\n System.out.println(currDist);\n }\n else {\n if(currVal < goal) {\n Node leftChild = new Node(currVal*2, currDist+1);\n q.push(leftChild);\n }\n Node rightChild = new Node(currVal--, currDist+1);\n q.push(rightChild);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b29bb5db55b22774d20a293d3362432a", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "public class Keyboard {\n public static void main(String[] args) {\nScanner scanner = new Scanner(System.in);\n String move = scanner.nextLine();\n String[] original = {\"qwertyuiop\",\"asdfghjkl;\",\"zxcvbnm,./\"};\n int disp = (move.equals(\"R\")) ? -1 : 1;\n String typed = scanner.nextLine();\n char[] decoded = new char[typed.length()];\n for (int i = 0; i < typed.length(); i++) {\n for (int j = 0; j < 3; j++) {\n for (int k = 0; k < original[j].length(); k++) {\n if (original[j].charAt(k) == typed.charAt(i)){\n decoded[i] = original[j].charAt(k+disp);\n }\n\n }\n\n }\n\n }\n System.out.println(new String(decoded));\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e85899765f99f70e94491568b19aa06c", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\n\n/**\n * Author: Luis Manuel D\u00edaz Bar\u00f3n\n * Problem: \n * Online Judge: COJ\n * Idea: \n *\n */\n\n\npublic class Main {\n\n static MyScanner sc;\n static MyWriter mw;\n static String filePath=\"d:\\\\lmo.in\";\n\n public static void main(String[] args) throws IOException {\n sc = new MyScanner(System.in);\n`//sc = new MyScanner(new FileReader(filePath));\n mw = new MyWriter(System.out);\n\n //while(sc.canRead())\n SolveSingleProblem();\n\n mw.close();\n }\n \n public static void SolveSingleProblem() throws IOException{\n \n String alph = \"qwertyuiopasdfghjkl;zxcvbnm,./\";\n String s = sc.next();\n String message = sc.next();\n \n for(int i = 0; i < message.length(); i++){\n \n char c = message.charAt(i);\n \n int idx = alph.indexOf(c);\n \n if(s == \"R\"){\n idx++;\n if(idx == alph.length()) idx = 0;\n \n }\n else{\n idx--;\n if(idx < 0) idx = alph.length() - 1;\n }\n \n mw.print(alph.charAt(idx));\n }\n \n }\n}\n\n\nclass MyScanner{\n BufferedReader br;\n StringTokenizer stk;\n public MyScanner(InputStream stream){\n this.br = new BufferedReader(new InputStreamReader(stream),72357);\n this.stk = new StringTokenizer(\"\");\n }\n\n public MyScanner(FileReader fr){\n this.br = new BufferedReader(fr);\n this.stk = new StringTokenizer(\"\");\n }\n\n public String next() throws IOException {\n while(!stk.hasMoreElements()){\n String line = br.readLine();\n if(line == null)\n return null;\n stk = new StringTokenizer(line);\n }\n return stk.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 boolean canRead() throws IOException{\n return br.ready();\n }\n\n public int [] nextIntArray(int n) throws IOException{\n int arr[] = new int[n];\n for(int i=0;i arr){\n for(int i=0;i=temp)\n\t\t\t{\n\t\t\t\tsum++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(sum);\n\t\tfor(int i=0;i(){\n\t\t\tpublic int compare(DS ds1, DS ds2){\n\t\t\t\treturn new Integer(ds1.a1).compareTo(new Integer(ds2.a1));\n\t\t\t}\n\t\t\t});\n\t\t\n\t\n\t\t\n\t\tint count=0;\n\t\twhile(count=0)\n\t\t{\n\t\t\tk=k-array[count].a1;\n\t\t\tcount++;\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\t\tfor(int i=0;i ans= new ArrayList();\n\t\tfor(int i=0;i a = new ArrayList();\n for(int i = 0 ;i < n; i++)\n arr[i] = sin.nextInt();\n Arrays.sort(arr);\n for(int i = 0; i < n; i++)\n {\n k -= arr[i];\n if(k > -1)\n {\n a.add(i+1);\n count++;\n }\n else\n break;\n }\n System.out.println(count);\n for(int i = 0; i < a.size()-1; i++)\n System.out.print(a.get(i) + \" \");\n System.out.println(a.get(a.size()-1));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2fd9e9113c70dadc7cca9b3b0659e516", "src_uid": "dbb164a8dd190e63cceba95a31690a7c", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class Main {\n\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n String s=\"\";\n Scanner in1=new Scanner(System.in);\n while(in1.hasNextLine()){\n s=in1.hasnextLine();\n }\n if(s.length()!=0 ){\n int l=0,r=0;\n for(int i=0;i t = new TreeSet();\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long k = sc.nextLong();\n for(i=1;i*i li = new ArrayList<>();\n for (int i = 1; i * i <= n; i++) {\n if (n%i == 0) {\n li.add(i);\n if (i*i != n)\n li.add(n/i);\n \n }\n }\n if (k > li.size())\n out.println(\"-1\");\n else {\n Collections.sort(li);\n out.println(li.get(k-1);\n }\n out.flush();\n out.close();\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7f533cb6f172af58952e0a255a733f05", "src_uid": "6ba39b428a2d47b7d199879185797ffb", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main{\n public void calc(int n ,int m)\n {\n if(n==1||m==1)\n {\n System.out.println(\"Akshat\");\n }\n else if(n==2||m==2)\n {\n System.out.println(\"Malvika\");\n }\n else\n {\n n--;\n m--;\n }\n } \n public static void main(String args[])\n {\n int n,int m;\n Scanner sc = new Scanner(System.in);\n n= sc.nextInt();\n m= sc.nextInt();\n calc(n,m);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "14a93ba279408124b00fe2ba05d5b353", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner in = new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n int x = n*m;\n if(x % 2 ! = 0)\n System.out.println(\"Akshat\");\n else\n System.out.println(\"Malvika\");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "432214089205b3da8a7fae4fe433e90d", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class JavaApplication51 {\n \n \n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n \n int n = s.nextInt();\n int m = s.nextInt();\n \n int grids = n*m;\n String player =\"Ak\";\n \n \n if(nm){\n \n for(int i = 0; i < n;i++){\n \n grids = grids-n;\n if(grids == 0)\n break;\n if(player == \"Ak\")\n player = \"malk\";\n else player = \"Ak\";\n \n }\n }\n \n \n \n if(player == \"Ak\")\n System.out.println(\"Akshat\");\n else\n System.out.println(\"Malvika\");\n \n \n \n \n \n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "473dc33de849ae9f5b5967fee78c8ac6", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Sol{\n public static void main(String []args){\n Scanner scan=new Scanner(System.in);\n int n=scan.nextInt();\n int m=scan.nextInt();\n int x;\n boolean y=0;\n x=Math.min(n,m);\n if(y&1){\n y=1;\n }\n if(y){\n System.out.println(\"Akshat\");\n \n }\n else\n System.out.println(\"Malvika\");\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "432041c10fa05bd3a5825219455a9dfe", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.TreeSet;\n//import java.util.*;\n\npublic class 864B{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint length = scan.nextInt();\n\t\tscan.nextLine();\n\t\tString[] find = scan.nextLine().trim().split(\"[A-Z]+\");\n\n\t\tint a = 0;\n\t\tfor(String x:find) {\n\t\t\tTreeSet val = new TreeSet();\n\t\t\t\tfor(char c : x.toCharArray())\n\t\t\t\t\tval.add(c);\n\t\t\t\tif(val.size()>a)\n\t\t\t\t\ta = val.size();\n\t\t\t}\n\t\t\tSystem.out.println(a);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cd00490b377caac0b57297841f18953d", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n\n int letters = Integer.parseInt(in.nextLine());\n String string = in.nextLine();\n boolean inLowercase = false;\n Set differentChars = Set.of();\n\n int result = 0;\n\n\n for (int i = 0; i < string.length(); i++) {\n char character = string.charAt(i);\n\n if (Character.isLowerCase(character)) {\n if (!inLowercase) {\n inLowercase = true;\n differentChars = new HashSet<>();\n }\n differentChars.add(character);\n } else if (inLowercase) {\n result = Math.max(result, differentChars.size());\n }\n\n }\n\n out.println(result);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3f0c4c834885c600d0d1db5f288aaa7", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class 864B {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tString[] s = scan.next().split(\"[A-Z]+\");\n\t\tint a = 0;\n\t\tfor(int i = 0 ; i < s.length ; i++) {\n\t\t\tSet set = new HashSet<>();\n\t\t\tfor(int j = 0 ; j < s[i].length() ; j++)\n\t\t\t\tset.add(s[i].charAt(j));\n\t\t\ta = Math.a(a, set.size());\n\t\t}\n\t\tSystem.out.println(a);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cca1b0473212f11ced206d8a0261bf68", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class PolycarpAndLetters {\nprivate static int Main()\n{\n int n;\n n = Integer.parseInt(ConsoleInput.readToWhiteSpace(true));\n\n String s;\n s = ConsoleInput.readToWhiteSpace(true);\n\n int max = 0;\n TreeSet cs = new TreeSet();\n\n for (int i = 0; i < n; ++i)\n {\n\tbyte letter = s.charAt(i);\n\n\tif (Character.isLowerCase(letter) && cs.count(letter) == 0)\n\t{\n\t cs.add(letter);\n\t if (cs.size() > max)\n\t {\n\t\tmax = cs.size();\n\t }\n\t}\n\n\tif (Character.isUpperCase(letter))\n\t{\n\t cs.clear();\n\t}\n }\n\n System.out.print(max);\n System.out.print(\"\\n\");\n return 0;\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "20dce79b21b1648cd7011c702312733e", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Code {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String s = sc.nextLine();\n if(s.length() >= 5 && contains(s, '0', '9') && contains(s, 'a','z') && contains(s, 'A','Z') )\n \t System.out.println\t( \"Correct\")\n \telse\n \t System.out.println\t( \"Too weak\")\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bb0896db6d14bf05bd07cc80ac5a7940", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\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 br = new BufferedReader(new InputStreamReader(System.in));\n Helper h = new Helper();\n String password = br.readLine();\n //System.out.println(h.oneLarge(password));\n if(h.atLeast5Chars(password)==true&&h.oneLarge(password)==true&&h.oneSmall(password)==true&&h.oneDigit(password)==true)\n {\n System.out.println(\"Correct\");\n }\n else\n {\n System.out.println(\"Too weak\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf8729715c07e040eae3068ac1bfb501", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0} {"lang": "Java 6", "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.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n *\n *\n * @author pttrung\n */\npublic class A {\n\n public static int Mod;\n public static int[][] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n\n Scanner in = new Scanner();\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\"output.txt\")));\n\n PrintWriter out = new PrintWriter(System.out);\n // System.out.println(Long.MAX_VALUE);\n String line = in.next();\n boolean ok = line.length() >= 5;\n boolean large = false;\n boolean small = false;\n boolean digit = false;\n for (int i = 0; i < line.length(); i++) {\n char c = line.charAt(i);\n if (c >= 'A' && c <= 'Z') {\n large = true;\n } else if (c >= 'a' && c <= 'z') {\n small = true;\n } else if (c >= '0' && c <= '9') {\n digit = true;\n }\n }\n if(ok && large && small && digit){\n out.println(\"Correct\");\n }else{\n out.println(\"Too weak\");\n }\n\n out.close();\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 static double dist(Point a, Point b) {\n long total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);\n return Math.sqrt(total);\n }\n\n static class Point implements Comparable {\n\n int x, y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n\n }\n\n @Override\n public int compareTo(Point o) {\n if (x != o.x) {\n return x - o.x;\n }\n return y - o.y;\n }\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n static class FT {\n\n int[] data;\n\n FT(int n) {\n data = new int[n];\n }\n\n void update(int index, int val) {\n // System.out.println(\"UPDATE INDEX \" + index);\n while (index < data.length) {\n data[index] += val;\n index += index & (-index);\n\n // System.out.println(\"NEXT \" +index);\n }\n }\n\n int get(int index) {\n // System.out.println(\"GET INDEX \" + index);\n int result = 0;\n while (index > 0) {\n result += data[index];\n index -= index & (-index);\n // System.out.println(\"BACK \" + index);\n }\n return result;\n }\n }\n\n static int gcd(int a, int b) {\n if (b == 0) {\n return a;\n } else {\n return gcd(b, a % b);\n }\n }\n\n static int pow(int a, int b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n int val = pow(a, b / 2);\n if (b % 2 == 0) {\n\n return val * val;\n } else {\n return val * val * a;\n }\n }\n\n// static Point intersect(Point a, Point b, Point c) {\n// double D = cross(a, b);\n// if (D != 0) {\n// return new Point(cross(c, b) / D, cross(a, c) / D);\n// }\n// return null;\n// }\n//\n// static Point convert(Point a, double angle) {\n// double x = a.x * cos(angle) - a.y * sin(angle);\n// double y = a.x * sin(angle) + a.y * cos(angle);\n// return new Point(x, y);\n// }\n// static Point minus(Point a, Point b) {\n// return new Point(a.x - b.x, a.y - b.y);\n// }\n//\n// static Point add(Point a, Point b) {\n// return new Point(a.x + b.x, a.y + b.y);\n// }\n//\n// static double cross(Point a, Point b) {\n// return a.x * b.y - a.y * b.x;\n//\n//\n// }\n//\n// static class Point {\n//\n// int x, y;\n//\n// Point(int x, int y) {\n// this.x = x;\n// this.y = y;\n// }\n//\n// @Override\n// public String toString() {\n// return \"Point: \" + x + \" \" + y;\n// }\n// }\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new FileReader(new File(\"input.txt\")));\n }\n\n public String next() {\n\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca3a253e9b2844a93aa9ef5835de0dbf", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.awt.*;\n\npublic class Main {\n\tstatic PrintWriter out = new PrintWriter( new BufferedOutputStream(System.out) );\n\tstatic BufferedReader br = new BufferedReader( new InputStreamReader(System.in) );\n\tstatic StringTokenizer st = new StringTokenizer(\"\");\n\tstatic String next()\tthrows Exception\t{\n\t\t\n\t\twhile\t( !st.hasMoreTokens() )\t{\n\t\t\tString s = br.readLine();\n\t\t\tif\t( s == null )\treturn\tnull;\n\t\t\tst = new StringTokenizer( s );\n\t\t}\n\t\treturn\tst.nextToken();\n\t}\n\n\tpublic static void main(String [] asda)\tthrows Exception\t{\n\t//\tint N = Integer.parseInt( next() );\n\t\tString s = next();\n\t\t\n\t\tint ans = 0;\n\n\t\tif\t( s.length() > 4 )\n\t\t\tans++;\n\t\t\n\t\tfor (char ch : s.toCharArray())\t{\n\t\t\tif\t( Character.isUpperCase(ch) )\t{\n\t\t\t\tans++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tfor (char ch : s.toCharArray())\t{\n\t\t\tif\t( Character.isLowerCase(ch) )\t{\n\t\t\t\tans++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor (char ch : s.toCharArray())\t{\n\t\t\tif\t( Character.isDigit(ch) )\t{\n\t\t\t\tans++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println( ans == 4s ? \"Correct\" : \"Too weak\" );\n\t\t//\n\t\tout.flush();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0ea17ba5f1713332854eba65d17233b8", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Arya {\n \n static int min(int a, int b){\n if(a > b){\n return b;\n }else{\n return a;\n }\n }\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int size = input.nextInt();\n int k = input.nextInt();\n int ans = 0; \n \n int array[] = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = input.nextInt();\n }\n int sweets = 0;\n for (int i = 0; i < size; i++){\n sweets += array[i];\n int bran = min(8,sweets);\n k -= bran;\n sweets -= bran;\n ans += 1;\n if(k <= 0 ){\n break;\n }\n if(k > 0) {\n System.out.println(\"-1\");\n } else\n System.out.println(ans);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7a643c441378fb63f1a8c650f2104e58", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.Math;\nimport java.math.BigInteger;\n\npublic class Problem {\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tnew Problem().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\tRandom rnd = new Random();\n\tstatic final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tProblem() throws FileNotFoundException{\n\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in)); \n out = new PrintWriter(System.out); \n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t\ttok = new StringTokenizer(\"\");\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = rI();\n\t\tint k = rI();\n\t\tfor(int i=0;i1){\n\t\t\tint mid = (r+l)/2;\n\t\t\tif(mid*mid>m){\n\t\t\t\tr = mid;\n\t\t\t}else{\n\t\t\t\tl = mid;\n\t\t\t}\n\t\t}\n\t\treturn l;\n\t}\n\tint countPow(int m,int n){\n\t\tint ans = 0;\n\t\twhile(m%n==0&&m>0){\n\t\t\tans++;\n\t\t\tm/=n;\n\t\t}\n\t\treturn ans;\n\t}\n\tlong binPow(long a, long b){\n\t\tif(b == 0){\n\t\t\treturn 1;\n\t\t}\n\t\tif(b%2==1){\n\t\t\treturn a*binPow(a,b-1);\n\t\t}else{\n\t\t\tlong c = binPow(a,b/2);\n\t\t\treturn c*c;\n\t\t}\n\t\t\n\t}\n\tlong gcd(long a, long b){\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\t\n\tlong pow(long x, long k){\n\t\tlong ans=1;\n\t\tfor(int i=0;i candyBatch = new ArrayList();\n\t\t//while (n < 1 || 100 < n){\n\t\t\tn = kbd.nextInt();\n\t\t//}\n\t//\twhile (k < 1 || 10000 < k){\n\t\t\tk = kbd.nextInt();\n\t//\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tamtDay[i] = kbd.nextInt();\n\t\t}\n\t\t\n\t\tfor(int j = 0; i < n; i++){\n\t\t\tcandyBran = amtDay[i];\n\t\t\tif(candyBran >= 8){\n\t\t\t\tcandyBran = candyBran - 8;\n\t\t\t\tcandyAria = candyAria + 8;\n\t\t\t} else {\n\t\t\t\tcandyAria = candyAria + candyBran;\n\t\t\t\tcandyBran = 0;\n\t\t\t}\n\t\t\t\n\t\t\tif(candyAria >= k){\n\t\t\t\tout = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} \n\t\t\tSystem.out.println(out?i+1:-1);\n\t}\n}\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1bd97e1dd0a531242e755b33da9dfd19", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class AssBlast{\n\tpublic static void main(String [] args){\n\t\tScanner kbd = new Scanner(System.in);\n\t\tint n = 0;\n\t\tint k = 0;\n\t\tint countDays = 0;\n\t\tint candyBran = 0;\n\t\tint candyAria = 0;\n\t\tboolean out = false;\n\t\tint[] amtDay = new int[n]\n\t\tArrayList candyBatch = new ArrayList();\n\t\t//while (n < 1 || 100 < n){\n\t\t\tn = kbd.nextInt();\n\t\t//}\n\t//\twhile (k < 1 || 10000 < k){\n\t\t\tk = kbd.nextInt();\n\t//\t}\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tamtDay[i] = kbd.nextInt();\n\t\t}\n\t\t\n\t\tfor(int j = 0; i < n; i++){\n\t\t\tcandyBran = amtDay[i];\n\t\t\tif(candyBran >= 8){\n\t\t\t\tcandyBran = candyBran - 8;\n\t\t\t\tcandyAria = candyAria + 8;\n\t\t\t} else {\n\t\t\t\tcandyAria = candyAria + candyBran\n\t\t\t\tcandyBran = 0;\n\t\t\t}\n\t\t\t\n\t\t\tif(candyAria >= k){\n\t\t\t\tout = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} \n\t\t\tSystem.out.println(out?countDaysi+1:-1);\n\t}\n}\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a49fea254406d46ee97909a94227a33b", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n\npublic class luckysum {\n\n\tstatic ArrayList lucky;\n\tstatic int idx = 0 ;\n\tstatic int idx2 = 1;\n\tstatic int c1=1;\n\tstatic int c2 = 2;\n\tstatic int r ;\n\t\n\tpublic static void addlucky(int a){\n\t\t//int sum =(int)(Math.ceil( Math.log((idx+1)-(idx2+1)) / Math.log(2)));\n\t\t\n\t\t//int sum =0;\n//\t\tint temp = a;\n//\t\twhile(temp > 0){\n//\t\t\tsum++;\n//\t\t\ttemp /= 10;\n//\t\t}\n\t\t//System.out.println(sum);\n\t\t\n\t\tint b = (int)(4*Math.pow(10,c1));\n\t // System.out.println(b);\n\n\t\tint nexlucky = b + a;\n\t\tlucky.add(nexlucky);\n\t\tb =(int)(7*Math.pow(10,c1));\n\t\t//System.out.println(b);\n\t\tnexlucky = b + a;\n\t\tlucky.add(nexlucky);\n\t\tif(idx2 == c2){\n\t\t\tc1++;\n\t\t\tc2 *= 2;\n\t\t\tidx2 = 1;\n\t\t}else{\n\t\tidx2++;\n\t\t}\n\t}\n\tpublic static void luckies(){\n\t\tint thislucky = lucky.get(idx);\n\t\tif(r <= thislucky || thislucky >= 1000000000)\n\t\t\treturn;\n\t\taddlucky(thislucky);\n\t\tidx++;\n\t\tluckies();\n//\t\twhile(true){\n//\t\t\tint thislucky = lucky.get(idx);\n//\t\t\tif(r <= thislucky)\n//\t\t\t\treturn;\n//\t\t\taddlucky(thislucky);\n//\t\t\tidx++;\n//\t\t}\n\n\t}\n\t\npublic static void main(String[] args) throws IOException {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n int l = sc.nextInt();\n r = sc.nextInt();\n\t\tlucky = new ArrayList();\n\t\tlucky.add(4);\n\t\tlucky.add(7);\n\t\tluckies();\n\t\tCollections.sort(lucky);\n\t\t//System.out.println(lucky.toString());\n\t\tint sum = 0; \n\t\tint start = 0; \n\t\tfor (int i = l; i <= r; i++) {\n\t\t\tint j;\n\t\t\tfor ( j = start; j =i ){\n\t\t\t\t\tsum += thislucky;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tstart = j;\n\t\t}\n out.println(sum);\n\t out.flush();\n\t out.close();\n\t\t\n\t\t\n\t}\n\t\n\t\n\t\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n \n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n \n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n \n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n \n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n \n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n \n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n \n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6661fc7db3122ac3ae539beddaf7309", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 10/27/11\n * Time: 9:34 PM\n */\npublic class CF91C {\n public static void main(String[] args) {\n reader = new BufferedReader(new InputStreamReader(System.in));\n\n List luckyNums = genAll();\n long largest = 0;\n for(int i = 0; i < 10; ++i) {\n largest = largest * 10 + 4;\n }\n luckyNums.add(largest);\n\n int left = nextInt(), right = nextInt();\n\n long res = 0;\n int x = left;\n for (int y : luckyNums) {\n if (y >= x) {\n res += (Math.min(y, right) - x + 1L) * y;\n x = y + 1;\n }\n if (y >= right) {\n break;\n }\n }\n\n System.out.println(res);\n }\n\n private static List genAll() {\n List ret = new ArrayList();\n for(int i = 1; i < 10; ++i) {\n for(int set = 0; set < (1 << i); ++set) {\n long x = 0;\n for(int j = 0; j < i; ++j) {\n if (((set >> j) & 1) == 1) {\n x = x * 10 + 7;\n }\n else {\n x = x * 10 + 4;\n }\n }\n ret.add(x);\n }\n }\n return ret;\n }\n\n public static BufferedReader reader;\n\n public static StringTokenizer tokenizer = null;\n\n static 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 static public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n static public long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n static public String next() {\n return nextToken();\n }\n\n static public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b04f820ecc1e3cd510cda75b16e734b1", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class a {\n static long mod = 1000000007;\npublic static void main(String[] args) throws IOException\n{\n input.init(System.in);\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\n int a = input.nextInt(), b = input.nextInt();\n ArrayList lucky = new ArrayList();\n int last = 0;\n lucky.add(0l);\n for(int i = 0; i<10; i++)\n {\n int count = lucky.size();\n for(int j = last; j=0) {found = true; diff++;}\n if(diff<0) diff = 0;\n //if(diff>0) out.println(i+\" \"+lucky.get(i)+\" \"+diff);\n res += diff*lucky.get(i);\n }\n out.println(res);\n\n out.close();\n\n}\nstatic 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 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 static String nextLine() throws IOException {\n return reader.readLine();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e2519039e5ee6bb7dfbb38e038037cb6", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import sun.plugin.javascript.navig.Array;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\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 TaskA {\n\n final int LIM = 223456781;\n ArrayList lucky;\n\n void generate(long x) {\n if(x < LIM) lucky.add((int)x);\n else return;\n\n generate(x * 10 + 4);\n generate(x * 10 + 7);\n }\n\n void run() {\n this.lucky = new ArrayList();\n generate(4);\n generate(7);\n Collections.sort(lucky);\n\n int[] l = new int[lucky.size()];\n int ix = 0;\n for(int x : lucky) {\n l[ix++] = x;\n }\n\n int L = nextInt(), R = nextInt();\n\n int l1 = 0, r1 = lucky.size();\n if(L > l[l1]) {\n while(r1 - l1 > 1) {\n int m1 = l1 + (r1 - l1) / 2;\n if(l[m1] >= L) r1 = m1;\n else l1 = m1;\n }\n }\n else {\n r1 = 0;\n }\n\n int l2 = 0, r2 = lucky.size();\n if(R > l[l2]) {\n while(r2 - l2 > 1) {\n int m2 = l2 + (r2 - l2) / 2;\n if (l[m2] >= R) r2 = m2;\n else l2 = m2;\n }\n }\n else {\n r2 = 0;\n }\n\n long ans = l[r1] * (long)(l[r1] - L + 1);\n for(int i = r1 + 1; i <= r2; i++) {\n ans += l[i] * (long) (l[i] - l[i - 1]);\n }\n ans -= l[r2] * (long) (l[r2] - R);\n System.out.println(ans);\n }\n\n int nextInt() {\n try {\n int c = System.in.read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n long nextLong() {\n try {\n int c = System.in.read();\n if (c == -1) return -1;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return -1;\n }\n if (c == '-') return -nextLong();\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String next() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (Character.isWhitespace(c))\n c = System.in.read();\n do {\n res.append((char) c);\n } while (!Character.isWhitespace(c = System.in.read()));\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n String nextLine() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (c == '\\r' || c == '\\n')\n c = System.in.read();\n do {\n res.append((char) c);\n c = System.in.read();\n } while (c != '\\r' && c != '\\n');\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n public static void main(String[] args) {\n new TaskA().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b276dcc146b60f066350e38b4cf307a3", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class Main{\n public static void main(String [] Args){\n Scanner sc = new Scanner(System.in); \n int a = sc.nextInt();\n a*=2; \n char inp ;\n int [] arr = new int [10];\n for(int i = 0 ; i < 16 ; i++){\n inp = sc.nextChar();\n if(inp >=48 && inp <= 57)\n arr[inp-48]++ ;\n }\n bool f = true ;\n for(int i = 0 ; i < 10 ; i++)\n if(arr[i] > a)\n f = false ;\n \n if(f)\n System.out.println(\"YES\");\n else \n System.out.println(\"NO\");\n \n \n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8855238c2b8be716abe41e7737fb0c45", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0} {"lang": "Java 7", "source_code": "\npublic class Main {\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in); \n int a = sc.nextInt();\n a*=2; \n String [] inp = new String [4];\n int [] arr = new int [10];\n for(int i = 0 ; i < 4 ; i++){\n inp[i] = sc.next();\n for(int j = 0 ; j < 4 ; j++) \n if(inp[i].charAt(j) >=48 && inp[i].charAt(j) <= 57)\n arr[(int)inp[i].charAt(j)-48]++ ;\n }\n boolean f ;\n f = true;\n for(int i = 0 ; i < 10 ; i++)\n if(arr[i] > a)\n f = false ;\n \n if(f)\n System.out.println(\"YES\");\n else \n System.out.println(\"NO\");\n \n \n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d1dc2e2c60e32b1411a5562bb8413839", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Main{\n public static void main(String [] Args){\n Scanner sc = new Scanner(System.in); \n int a = sc.nextInt();\n a*=2; \n char inp ;\n int [] arr = new int [10];\n for(int i = 0 ; i < 16 ; i++){\n inp = sc.nextChar();\n if(inp >=48 && inp <= 57)\n arr[inp-48]++ ;\n }\n bool f = true ;\n for(int i = 0 ; i < 10 ; i++)\n if(arr[i] > a)\n f = false ;\n \n if(f)\n System.out.println(\"YES\");\n else \n System.out.println(\"NO\");\n \n \n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8e89ce092dbdca69478305f731a418be", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author revo\n */\npublic class Proj1 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int k = Integer.parseInt(in.readLine()) * 2;\n int [] IntArray= new int[10];\n String line=\"\";\n for(int i=0; i< 4 ; i++){\n line += in.readLine();\n }\n boolean valid=true;\n for(int i=0; i<16 ;i++){\n if(Character.isDigit(line.charAt(i))){\n int index = Character.digit(line.charAt(i), 10);\n \n IntArray[index]++;\n if(k < IntArray[index]) valid=false; \n }\n }\n \n if(valid){\n System.out.println(\"YES\");\n }else{\n System.out.println(\"NO\");\n }\n \n \n \n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f6d88c4bbe7ff5ab4cdaa0bffe94fdac", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\npublic class babyehab {\r\n public static void main(String[] args) {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int N = Integer.parseInt(br.readLine()), total = 0;\r\n int[] a = new int[N];\r\n boolean[][] dp = new boolean[100001][101];\r\n StringToknenizer st = new StringTokenizer(br.readLine());\r\n for (int i = 0; i < N; i++) {\r\n a[i] = Integer.parseInt(st.nextToken());\r\n total += a[i];\r\n }\r\n dp[0][0] = true;\r\n boolean bad = false;\r\n for (int i = 0; i < 100001; i++) {\r\n for (int j = 0; j < N; j++) {\r\n if (i > a[j]) {\r\n dp[i][j+1] = dp[i][j]||dp[i-a[j]][j];\r\n }\r\n if (i*2 == total && dp[i][j+1]) {\r\n bad = true;\r\n }\r\n }\r\n }\r\n int trailingZero = Integer.MAX_VALUE;\r\n if (bad) {\r\n for (int i = 0; i < N; i++) {\r\n trailingZero = Math.min(trailingZero, a[i] & -a[i]);\r\n }\r\n for (int i = 0; i < N; i++) {\r\n if ((a[i] & trailingZero) != 0) {\r\n System.out.println(1);\r\n System.out.println(a[i]);\r\n break;\r\n }\r\n }\r\n } else {\r\n System.out.println(0);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dba2050c9d84c8195e79bb7d6144734c", "src_uid": "29063ad54712b4911c6bf871969ee147", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\npublic class babyehab {\r\n public static void main(String[] args) {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int N = Integer.parseInt(br.readLine()), total = 0;\r\n int[] a = new int[N];\r\n boolean[][] dp = new boolean[100001][101];\r\n StringTokenizer st = new StringTokenizer(br.readLine());\r\n for (int i = 0; i < N; i++) {\r\n a[i] = Integer.parseInt(st.nextToken());\r\n total += a[i];\r\n }\r\n dp[0][0] = true;\r\n boolean bad = false;\r\n for (int i = 0; i < 100001; i++) {\r\n for (int j = 0; j < N; j++) {\r\n if (i > a[j]) {\r\n dp[i][j+1] = dp[i][j]||dp[i-a[j]][j];\r\n }\r\n if (i*2 == total && dp[i][j+1]) {\r\n bad = true;\r\n }\r\n }\r\n }\r\n int trailingZero = Integer.MAX_VALUE;\r\n if (bad) {\r\n for (int i = 0; i < N; i++) {\r\n trailingZero = Math.min(trailingZero, a[i] & -a[i]);\r\n }\r\n for (int i = 0; i < N; i++) {\r\n if ((a[i] & trailingZero) != 0) {\r\n System.out.println(1);\r\n System.out.println(a[i]);\r\n break;\r\n }\r\n }\r\n } else {\r\n System.out.println(0);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f53ed2aff23e4d959f34ffcf728ec60d", "src_uid": "29063ad54712b4911c6bf871969ee147", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\npublic class CF {\r\n public static void main(String args[]) {\r\n Integer n = Integer.parseInt(System.console().readLine());\r\n String[] s = System.console().readLine().split(' ');\r\n List inp = new ArrayList();\r\n Integer sum = 0;\r\n Integer minval = -1;\r\n Integer minin = -1;\r\n for (String ss : s) {\r\n Integer in = Integer.parseInt(ss);\r\n sum += in;\r\n inp.add(in);\r\n }\r\n Integer sosum = 0;\r\n Boolean valid = true;\r\n for (Integer i = 0; i < n; i++) {\r\n sosum += inp[i];\r\n if (sosum * 2 == sum) {\r\n valid = false;\r\n }\r\n if (minval == -1 || minval > inp.get(i)) {\r\n minval = inp.get(i);\r\n minin = i;\r\n }\r\n }\r\n if (valid) {\r\n System.out.println(\"0\");\r\n }\r\n else {\r\n System.out.println(\"1\");\r\n System.out.println(minin);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6a71868ffc0866d2608b1c02f8e62782", "src_uid": "29063ad54712b4911c6bf871969ee147", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n//import java.math.*;\r\n\r\npublic class Task{\r\n // ..............code begins here..............\r\n\r\nstatic long mod=(long)1e9+7,inf=(long)1e17;\r\n\r\n\r\nstatic void solve() throws IOException {\r\n int n=int_v(read());\r\n int[] a=int_arr();\r\n int inf=200000000;\r\n int ts=0,idx=-1;\r\n sort(a);\r\n int[][] dp=new int[n+1][ts+1];\r\n for(int i=0;i<=n;i++){\r\n for(int j=0;j<=ts;j++){dp[i][j]=inf;}\r\n }\r\n for(int i=0;i<=n;i++)dp[i][0]=0;\r\n for(int s=1;s<=ts;s++){\r\n for(int i=1;i<=n;i++){\r\n if(s>=a[i-1]){\r\n dp[i][s]=Math.min(dp[i-1][s-a[i-1]]+1,dp[i-1][s]);\r\n }\r\n else{\r\n dp[i][s]=dp[i-1][s];\r\n }\r\n }\r\n }\r\n int g=a[0];\r\n for(int z:a)g=gcd(g,z);\r\n for(int i=0;i l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i=mod)z-=mod;return z;}\r\nstatic long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}\r\nstatic long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}\r\nstatic long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}\r\nstatic long ModInv(long a,long m){return Modpow(a,m-2,m);}\r\n//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}\r\n//static long[] f;\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8f8fd5e3ab41606be4c1261e378c3236", "src_uid": "29063ad54712b4911c6bf871969ee147", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int b[] = new int[m];\n for(int i = 0;i=0;i--)\n {\n System.out.println(arr1[i]+\" \");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0ce5316239c12861544bdac3b108eb29", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0} {"lang": "Java 7", "source_code": "\npublic class Main {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n,m,a[],k;\n a = new int[100];\n n = sc.nextInt();\n m = sc.nextInt();\n for(int i = 0 ; i < m ; i++){\n k = sc.nextInt();\n for(int j = k ; j <= n && a[j] == 0 ; j++)\n a[j] = k ;\n }\n for(int i = 1 ; i <= n ; i++)\n System.out.print(a[i]+ \" \");\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bef8a43ec9e9260c623df086622f8651", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class A {\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[n+1];\n for(i=1; i<=n; ++i) arr[i]=0;\n for(int i=0; i n ? n : m;\n }\n \n private static final BufferedReader br= new BufferedReader(new InputStreamReader(System.in));\n \n public static void main(String[] args) {\n String s = br.readLine();\n System.out.println(nineteens(s));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e9654e8aa3a8fc7eed49b4ad8175e30c", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724", "difficulty": null} {"lang": "Java 8", "source_code": "public class Nineteen {\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tString input = sc.next();\n\t\tchar[] in = input.toCharArray();\n\t\tint hash[] = new int[256]; \n\t\tfor(int i = 0 ; i=3 && e >= 3 && i >= 1 && t >= 1)\n {\tx++;\n n -= 2; e -= 3 ; i--; t--;}\n else break;\n\n }\n System.out.print(x);\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2dfcd488f99b28abf8d73e8824729bb3", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.*;\nimport java.util.Arrays; \nimport java.util.*;\npublic class CF2{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s1 = sc.nextLine();\n\t\tchar[] temp = s1.toCharArray();\n\t\tArrays.sort(temp);\n\t\tString s = new String(temp);\n\t\tint ln = s.lastIndexOf('n')+1-s.indexOf('n');\n\t\tint li = s.lastIndexOf('i')+1-s.indexOf('i');\n\t\tint le = (s.lastIndexOf('e')+1-s.indexOf('e'))/3;\n\t\tint lt = s.lastIndexOf('t')+1-s.indexOf('t');\n\t\t//int ans = Math.min(Mat.min(Math.min(ln,li),le),lt);\n\t\tint ans = Math.min(Math.min(le,lt),Math.min(li,li));\n\t\tif(ln>= (2*ans+1)){\n\t\t System.out.println(ans);\n\t\t}\n\t\telse{\n\t\t System.out.println(Math.min(n/3, ans));\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1f8b2e049753628f0295a5ffa524c36d", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Test {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\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\n\tstatic 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\tpublic static int gcd(int x, int y){\n\t\tif (y == 0) return x; else return gcd(y, x % y);\n\t}\n\t static class R implements Comparable{\n\t int x, y;\n\t public R(int x, int y) {\n\t this.x = x;\n\t this.y = y;\n\t }\n\t public int compareTo(R o) {\n \t\treturn x-o.x; //Increasing order(Which is usually required)\n \t\t}\n\t } \n\n\tpublic static void main(String[] args) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\ttokenizer = null;\n\t\twriter = new PrintWriter(System.out);\n\t\tsolve();\n\t\treader.close();\n\t\twriter.close();\n\t}\n\t\n\tprivate static void solve() throws IOException {\n\t\tString time = nextToken();\n\t\tString result=\"00:00\";\nint h = ((int)time.charAt(0))*10+(int)time.charAt(1);\n\t\tint mm = int h = ((int)time.charAt(3))*10+(int)time.charAt(4)+1;\n\t\t\n\t\tboolean first = true;\n\t\t\n\t\touter:\n\t\tfor (; h < 24; h++) {\n\t\t\tfor (int m = (first ? mm : 0); m < 60; m++) {\n\t\t\t\t\n\t\t\t\tString temp = \"\";\n\t\t\t\tif (h < 10) {\n\t\t\t\t\ttemp += \"0\";\n\t\t\t\t}\n\t\t\t\ttemp += \"\" + h + \":\";\n\t\t\t\tif (m < 10) {\n\t\t\t\t\ttemp += \"0\";\n\t\t\t\t}\n\t\t\t\ttemp += \"\" + m;\n\t\t\t\tif (temp.equals(new StringBuffer(temp).reverse().toString())) {\n\t\t\t\t\tresult = temp;\n\t\t\t\t\tbreak outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\t\n\t\twriter.println(result);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5664444a02c8893fef2d08f93c2cda12", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\npublic class Palindrome{\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String brr[]=br.readLine().trim().split(\" \");\n String s=brr[0];\n int hour,min,hour1;\n int d,p;\n d=(int)s.charAt(0);\n d-=48;\n hour=d*10;\n hour1=d;\n d=(int)s.charAt(1);\n d-=48;\n hour+=d;\n hour1+=(d*10);\n if(d>=6)\n {\n hour++;\n }\n else\n {\n p=(int)s.charAt(3);\n p-=48;\n min=p*10;\n p=(int)s.charAt(4);\n p-=48;\n min+=p;\n int q;\n // System.out.println(min+\" \"+hour1);\n if(min=6&&hour<=9)\n {\n hour=10;\n min=1;\n System.out.println(hour+\":0\"+min);\n }\n else if(hour>=16&&hour<=19)\n {\n hour=20;\n min=2;\n System.out.println(hour+\":0\"+min);\n }\n else if(hour==24)\n System.out.println(\"00:00\");\n else\n {\n p=hour;\n q=p%10;\n min=(q*10);\n p=p/10;\n q=p%10;\n min+=q;\n if(min>9)\n System.out.println(hour+\":\"+min);\n else\n System.out.println(hour+\":0\"+min);\n }\n }\n }\n \n }\n \n }\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02f4a19e47b48b9e02f9c2e6523c2c8f", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class PalindromicTimes {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String st=in.next();\n String parts[]=st.split(\":\");\n int hour=Integer.parseInt(parts[0]);\n int min=Integer.parseInt(parts[1]);\n int rev=(hour%10)*10+(hour/10);\n \nif(hour<23)\n{\nif(rev<=min)\n{hour=hour+1;\nrev=(hour%10)*10+(hour/10);\n\n\n\n}\n\n} \nelse\n{if(min>32)\n{System.out.println(\"00:00\");\nSystem.exit(0);}\nelse\n{hour=23;rev=32;}\n\n}\nif(hour<=20&&hour>=16)\n{System.out.println(\"20:02\");\n\n}\nelse if(hour<=10&&hour>=6)\n{System.out.println(\"10:01\");}\nelse if(hour>0&&hour<=5)\n{System.out.println(\"0\"+hour+\":\"+rev);}\nelse\n{System.out.println(hour+\":\"+rev);}\n \n }\n \n}\nimport java.util.*;\npublic class PalindromicTimes {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String st=in.next();\n String parts[]=st.split(\":\");\n int hour=Integer.parseInt(parts[0]);\n int min=Integer.parseInt(parts[1]);\n int rev=(hour%10)*10+(hour/10);\n \nif(hour<23)\n{\nif(rev<=min)\n{hour=hour+1;\nrev=(hour%10)*10+(hour/10);\n\n\n\n}\n\n} \nelse\n{if(min>32)\n{System.out.println(\"00:00\");\nSystem.exit(0);}\nelse\n{hour=23;rev=32;}\n\n}\nif(hour<=20&&hour>=16)\n{System.out.println(\"20:02\");\n\n}\nelse if(hour<=10&&hour>=6)\n{System.out.println(\"10:01\");}\nelse if(hour>0&&hour<=5)\n{System.out.println(\"0\"+hour+\":\"+rev);}\nelse\n{System.out.println(hour+\":\"+rev);}\n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d4992b316404baadfb4919c416982c36", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "// enough being stupid\npublic class Palindromic_Times {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner (System.in);\n String inp = scanner.next(),hs,nhs,nms,ms;\n hs = inp.split(\":\")[0];\n ms = inp.split(\":\")[1];\n int h = Integer.parseInt(hs),nh,nm,m;\n m=Integer.parseInt(ms);\n nhs=hs;nh=h;\n nms = \"\"+nhs.charAt(1)+nhs.charAt(0);\n nm = Integer.parseInt(nms);\n if (nm<=m) nm=60;\n while(nm>59){\n nh = (nh+1)%24;\n nhs = Integer.toString(nh);\n if (nhs.length()==1)nhs=\"0\"+nhs;\n nms = \"\"+nhs.charAt(1)+nhs.charAt(0);\n nm = Integer.parseInt(nms);\n }\n System.out.println(nhs+\":\"+nms);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bce4b84a0448c6e986676579b587dff5", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\nimport java.io.PrintWriter;\n\npublic class ToyArmy {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int result = (3 * in.nextInt())/2;\n out.println(result)\n out.close(); \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67ad67c19db6978429d9f1e2402845cb", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0} {"lang": "Java 6", "source_code": " 1. public class Main {\n 2.\n\n 3. public static void main(String... args) {\n 4. java.util.Scanner in = new java.util.Scanner(System.in);\n 5. int n = in.nextInt();\n 6. System.out.println(n / 2 * 3);\n 7. } // main\n 8.\n\n 9. } // class Main", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0790182b6b4452c280be4ae6a9cb3890", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class Solution{\n\npublic static void main(String[] args){\n\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n System.out.println(n+(n/2));\n\n}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a8ac2596d083524473130436a42d00cc", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.text.*;\n\n\npublic class Main\n{\n\n\n\n public static void main(String[] args)\n {\n\nScanner sc = new Scanner(System.in);\nint T =sc.nextInt();\n\nint t /=2;\nSystem.out.prinln(t*3);\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "afeefdbfa8f7852f00958fd5897facde", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main {\n \n\tpublic static void main(String[] args) throws IOException{\n\t\t//code\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader (System.in));\n\t\t String temp[] = (in.readLine()).split(\" \");\n\t\tint n = Integer.parseInt(temp[0]);\n\t\tint a = Integer.parseInt(temp[1]);\n\t\tint x = Integer.parseInt(temp[2]);\n\t\tint b = Integer.parseInt(temp[3]);\n\t\tint y = Integer.parseInt(temp[4]);\n\t\tArrayList path1 = new ArrayList();\n\t\tArrayList path2 = new ArrayList();\n\t\tint c = a;\n\t\tif(a>n||x>n||b>n||y>n)\n\t\t{\n\t\t System.out.println(\"NO\");\n\t\t \n\t\t}\n\t\twhile(c!=b)\n\t\t{\n\t\t if(c!=n)\n\t\t {\n\t\t path1.add(c);\n\t\t c++;\n\t\t }\n\t\t else\n\t\t {\n\t\t path1.add(c);\n\t\t c=1;\n\t\t }\n\t\t}\n\t\tpath1.add(c);\n\t\tc=b;\n\t\twhile(c!=y)\n\t\t{\n\t\t \n\t\t if(c!=1)\n\t\t {\n\t\t path2.add(c);\n\t\t c--;\n\t\t }\n\t\t else\n\t\t {\n\t\t path2.add(c);\n\t\t c=n;\n\t\t }\n\t\t}\n\t\tpath2.add(c);\n\t\tboolean check = false;\n\t\tint n1 = path1.size();\n\t\tint n2 = path2.size();\n\t\tint t = (n1list1=new ArrayList();\n\tstatic void combine(String instr, StringBuffer outstr, int index,int k)\n\t{\n\t\tif(outstr.length()==k)\n\t\t{\n\t\t\tlist1.add(outstr.toString());return;\n\t\t}\n\t\tif(outstr.toString().length()==0)\n\t\toutstr.append(instr.charAt(index));\n\t for (int i = 0; i < instr.length(); i++)\n\t {\n\t outstr.append(instr.charAt(i));\n\t \n\t combine(instr, outstr, i + 1,k);\n\t outstr.deleteCharAt(outstr.length() - 1);\n\t }\n\t index++;\n\t} \n\tstatic ArrayList>l=new ArrayList<>();\n\tstatic void comb(int n,int k,int ind,ArrayListlist)\n\t{\n\t\tif(k==0)\n\t\t{\n\t\t\tl.add(new ArrayList<>(list));\n\t\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t\n\t\tfor(int i=ind;i<=n;i++)\n\t\t{\n\t\t\tlist.add(i);\n\t\t\tcomb(n,k-1,ind+1,list);\n\t\t\t\n\t\t\tlist.remove(list.size()-1);\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\n\t}\n\t\n\tstatic class Pair implements Comparable{\n\t int x;int y;\n\t Pair(int x,int y){\n\t this.x=x;\n\t this.y=y;\n\t // this.i=i;\n\t }\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn (o.x*y-o.y*x);\n\t\t\t\n\t\t}\n\t}\n\t\n\t\t\n\t\n\tpublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\t static HashMap sort(HashMap hm) \n\t { \n\t // Create a list from elements of HashMap \n\t List > list = \n\t new LinkedList >(hm.entrySet()); \n\t \n\t // Sort the list \n\t Collections.sort(list, new Comparator >() { \n\t public int compare(Map.Entry o1, \n\t Map.Entry o2) \n\t { \n\t return (o1.getValue().y)-(o2.getValue().y); \n\t } \n\t }); \n\t \n\t // put data from sorted list to hashmap \n\t HashMap temp = new LinkedHashMap(); \n\t for (Map.Entry aa : list) { \n\t temp.put(aa.getKey(), aa.getValue()); \n\t } \n\t return temp; \n\t } \n\t static long ncr(long n, int k) \n\t { long m=(long)1e9+7;\n\t long C[] = new long[k + 1]; \n\t \n\t // nC0 is 1 \n\t C[0] = 1; \n\t \n\t for (int i = 1; i <= n; i++) \n\t { \n\t // Compute next row of pascal \n\t // triangle using the previous row \n\t for (int j = Math.min(i, k); j > 0; j--) \n\t C[j] = (C[j]%m + C[j-1]%m)%m; \n\t } \n\t return C[k]%m; \n\t } \n\t static long high(long n) \n\t { \n\t \n\t long p = (long)(Math.log(n) / \n\t Math.log(2L)); \n\t return (long)Math.pow(2L, p); \n\t }\n\t static int findd(int a){\n\t if (parent[a]!=a){\n\t parent[a] = findd(parent[a]);\n\t }\n\t return parent[a];\n\t }\n\t static int parent[];\n\t static ArrayListlist=new ArrayList();\n\t static HashMapmap;\n\t static boolean find(int n,int f)\n\t {\n\t\t if(map.containsKey(n))\n\t\t {\t\n\t\t\t if(map.get(n)>=f)\n\t\t\t {\n\t\t\t\t map.put(n, map.get(n)-f);\n\t\t\t\t if(map.get(n)==0)\n\t\t\t\t\t map.remove(n);\n\t\t\t\t return true;\n\t\t\t }\n\t\t\t else\n\t\t\t {\n\t\t\t\t f-=map.get(n);\n\t\t\t\t map.remove(n);\n\t\t\t\t if(find(n/2,2*f))\n\t\t\t\t\t return true;\n\t\t\t\t else\n\t\t\t\t\t return false;\n\t\t\t }\n\t\t\t\n\t\t }\n\t\t else if(n>1)\n\t\t {\n\t\t\tif(find(n/2,2*f))\n\t\t\t\treturn true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t }\n\t\t else\n\t\t\t return false;\n\t\n\t }\n\t\tstatic int CeilIndex(int A[], int l, int r, int key) \n\t\t{ \n\t\t\twhile (r - l > 1) { \n\t\t\t\tint m = l + (r - l) / 2; \n\t\t\t\tif (A[m] >= key) \n\t\t\t\t\tr = m; \n\t\t\t\telse\n\t\t\t\t\tl = m; \n\t\t\t} \n \n\t\t\treturn r; \n\t\t} \nstatic ArrayListli=new ArrayList();\n\t\tstatic int LongestIncreasingSubsequenceLength(int A[], int size) \n\t\t{ \n\t\t\t// Add boundary case, when array size is one \n \n\t\t\tint[] tailTable = new int[size]; \n\t\t\tint len; // always points empty slot \n \n\t\t\ttailTable[0] = A[0]; \n\t\t\tlen = 1; \n\t\t\tfor (int i = 1; i < size; i++) { \n\t\t\t\tif (A[i] < tailTable[0]) \n\t\t\t\t\t// new smallest value \n\t\t\t\t\ttailTable[0] = A[i]; \n \n\t\t\t\telse if (A[i] > tailTable[len - 1]) \n\t\t\t\t\t// A[i] wants to extend largest subsequence \n\t\t\t\t\ttailTable[len++] = A[i]; \n \n\t\t\t\telse\n\t\t\t\t\t// A[i] wants to be current end candidate of an existing \n\t\t\t\t\t// subsequence. It will replace ceil value in tailTable \n\t\t\t\t\ttailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; \n\t\t\t} \n\t for(int i=0;ilist=new ArrayList();\n\t\t\n HashMapmap=new HashMap();\n \n \n \t int n=in.nextInt();\n \t int a=in.nextInt();\n \t int x=in.nextInt();\n \t int b=in.nextInt();\n \t int y=in.nextInt();\n \t \n \t \n \t while(a!=x&&b!=y)\n \t {\n \t\t// out.println(a+\" \"+b);out.flush();\n \t\t if(a==b)\n \t\t {\n \t\t\t out.println(\"YES\");out.flush();return;\n \t\t }\n \t\t\n \t\t a++;\n \t\t b--;\n \t\t if(a==b)\n \t\t {\n \t\t\t out.println(\"YES\");out.flush();return;\n \t\t }\n \t\t if(a==n)\n \t\t\t a=1;\n \t\t if(b==0)\n \t\t\t b=n;\n \t\t\t if(a==b)\n \t\t {\n \t\t\t \n \t }\n \t out.println(\"NO\");\n \t out.flush();\n \t \n \t \n \n \n\t\t}\n\t\t\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "66c429a6e62672121590dfe3cf2e3d68", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\npublic class Caps\n{\n public static void main(String[] args)\n {\n String input;\n String output;\n Scanner sc= new Scanner(System.in);\n input=sc.nextLine();\n input=input.replace(input.charAt(0), input.charAt(0)-32);\n System.out.println(input);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "26456412ed055fe7ee790669c7b18938", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class WordCapitalizationTest {\n\n\tpublic static void main(String[] args) {\n\t\tString str=new Scanner(System.in).next();\n\t\tif(str.charAt(0)>90) {\n\t\tSystem.out.println(str.replace(str.charAt(0),(char)(str.charAt(0)-32)));\n\t\t}\n\t\telse\n\t\t\tSystem.out.println(str);\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "676f2fb7a019bea240a0960582e21ff2", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*; \npublic class Main{\n public static void main(String ... string){\n Scanner sc = new Scanner(System.in); \n String s = sc.nextLine(); \n String ans = s.toUpperCase(s.charAt(0) + \"\"); \n String h = \"\"; \n for(int i = 1; i Math.abs(b-i)){\n bWins++ ;\n } else {\n draw++ ;\n }\n }\n\n\n\n System.out.println(aWins + \" \" + draw + \" \" + bWins);\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n// int[] array = new int[5] ;\n// for (int i = 0 ; i < 5 ; i++){\n// array[i] = input.nextInt();\n// }\n// mergeSort(array,0,array.length -1);\n//\n// for (int e: array\n// ) {\n// System.out.print(e + \" \") ;\n// }\n// System.out.println();\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n// long n = input.nextLong() ;\n// String number = Long.toString(n) ;\n// char[] nums = number.toCharArray() ;\n// if(n/10 == 0){\n// System.out.println(\"NO\");\n// return;\n// }\n// boolean flag = false ;\n// for(int i = 0 ; i < nums.length ; i++){\n// if(nums[i] != '4' && nums[i] != '7'){\n// System.out.println(\"NO\");\n// return;\n// } else {\n// flag = true ;\n// }\n// }\n// if (flag){\n// System.out.println(\"YES\");\n// return;\n// }\n//\n//\n//\n//\n//\n//\n//\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n// int n = input.nextInt() ;\n// int[] A = new int[n] ;\n// for (int i = 0 ; i < A.length ; i++)\n// A[i] = input.nextInt() ;\n// if(n == 1){\n// System.out.println(\"NO\");\n// return;\n// }\n//\n//\n//\n//\n// int temp = 0 ;\n//\n// for (int i = 0 ; i < A.length ; i++){\n// int[] result= findMin(A,i) ;\n// int min = result[0] ;\n// int indexMin = result[1] ;\n// if(A[i] > min){\n// temp = A[i] ;\n// A[i] = min ;\n// A[indexMin] = temp ;\n// }\n//\n//\n// }\n// boolean flag = false ;\n// for(int i = 1 ; i < A.length ; i++){\n// if(A[i] != A[i-1]){\n// System.out.println(A[i]);\n// return;\n// } else {\n// flag = true ;\n// }\n// }\n// if (flag){\n// System.out.println(\"NO\");\n// return;\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// int[] A = new int[5] ;\n// int[] B = new int[5] ;\n// int[] C = new int[6] ;\n// for(int i = 0 ; i < 5 ; i++)\n// A[i] = input.nextInt() ;\n// for(int i = 0 ; i < 5 ; i++)\n// B[i] = input.nextInt() ;\n//\n// int carry = 0 ;\n// int i , j = 0;\n// for(i = A.length-1 ; i >= 0 ;i-- ){\n// C[j++] = (A[i] + B[i] + carry) % 2 ;\n// carry = (A[i] + B[i] + carry) / 2;\n// }\n// if (carry != 0) {\n// C[j++] = carry;\n// }\n// for(int x = C.length - 1 ; x >= 0 ; x--)\n// System.out.print(C[x]);\n// System.out.println();\n// int[] arr = new int[5] ;\n// for(int i = 0 ; i < 5 ; i++){\n// arr[i] = input.nextInt() ;\n// }\n//\n// for(int i = 1 ; i < 5 ; i++){\n// int key = arr[i] ;\n// int hole = i ;\n// while (hole > 0 && arr[hole-1] < key){\n// arr[hole] = arr[hole-1] ;\n// hole-- ;\n// }\n// arr[hole] = key ;\n// }\n// for (int e:arr\n// ) {\n// System.out.print(e + \" \");\n// }\n//\n\n }\n static int[] findMin (int[] array , int start){\n int min = array[start] ;\n int indexMin = 0 ;\n for(int i = start+1 ; i < array.length ; i++){\n if(array[i] < min){\n min = array[i] ;\n indexMin = i ;\n }\n\n }\n return new int[] {min,indexMin} ;\n }\n\n static void merge (int[] A , int p , int q , int r){\n int n1 = q-p+1 ;\n int n2 = r-q ;\n int[] L = new int[n1] ;\n int[] R = new int[n2] ;\n for(int i = 0 ; i < n1 ; i++)\n L[i] = A[p+i] ;\n for(int i = 0 ; i < n2 ; i++)\n R[i] = A[q+i+1] ;\n\n int i = 0 , j = 0 , k = p;\n while (i < n1 && j < n2){\n if (L[i] <= R[j]){\n A[k] = L[i] ;\n i++ ;\n } else {\n A[k] = R[j] ;\n j++ ;\n }\n k++ ;\n }\n while (i < n1)\n {\n A[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2)\n {\n A[k] = R[j];\n j++;\n k++;\n }\n }\n static void mergeSort (int[] A , int p , int r){\n if (p < r){\n int q = (int)Math.floor((r+p)/2) ;\n mergeSort(A,p , q);\n mergeSort(A,q+1,r);\n merge(A,p,q,r);\n }\n\n }\n}\n\n\n\n\n\n\n\n\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "34dec93dc3f495f06ee5a078406d6329", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0} {"lang": "Java 7", "source_code": "\npublic class first {\n\n public static void main(String[] args) {\n Scanner scn = new Scanner(System.in);\n int a = scn.nextInt(), b = scn.nextInt(), win = 0, draw = 0, lose = 0;\n scn.close();\n for (int i = 1; i < 7; i++) {\n if(Math.abs(a - i) < Math.abs(b - i)) {\n win ++;\n }\n else\n if(Math.abs(a - i) > Math.abs(b - i)) {\n lose ++;\n }\n else draw ++;\n }\n System.out.println(win + \" \" + draw + \" \" + lose);\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e7a563663dcf48bc5d742978f638d48", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Dice{ \n public static void main(String[] args) {\n int a, b;\n Scanner in = new Scanner(System.in);\n a = in.nextInt();\n b = in.nextInt();\n int fwin = 0, d = 0, swin = 0;\n for(int i = 1; i <= 6; i++) {\n if(Math.abs(i - a) > Math.abs(i - b))\n fwin++;\n else if (Math.abs(i-a) < Math.abs(i-b))\n swin++;\n else draw++;\n }\n System.out.println(fwin + \" \" + draw + \" \" + swin);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0d0dabd89f3c71a5cbf4dd0fe04094cc", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class TripForAMeal{\n\tpublic static void main(String[] args){\n\t\tScanner input = new Scanner(System.in);\n\n\t\tint n = input.nextInt();\n\t\tif(n>=1 && n<=100){\n\t\t\tint a = input.nextInt();\n\t\t\tif(a>=1 && a<=100){\n\t\t\t\tint b = input.nextInt();\n\t\t\t\tif(b>=1 && b<=100){\n\t\t\t\t\tint c = input.nextInt();\n\t\t\t\t\tif(c>=1 && c<=100){\n\n\t\t\t\t\t\tSystem.oout.println(a+b);\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5d54bf583d6c2405ba560504c49cddfa", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n if(n>1)\n {\n int ans+=Math.min(a,b);\n ans+=((n-1)*Math.min(a,b,c));\n }\n else{\n System.out.println(\"0\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a412cc3578a7d0a1b3fd85c2db7a739f", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class TripForMeal {\n\t\t\n\tpublic static void main(String[] args) {\n\t\tScanner reader=new Scanner (System.in);\n\t\tint visits=reader.nextInt()-1;\n\t\tint rabbitOwl=reader.nextInt();\n\t\tint rabbitEeyore=reader.nextInt();\n\t\tint owlEeyore=reader.nextInt();\n\t\tint shortest=Math.min(rabbitOwl, rabbitEeyore);\n\t\tint answer=0;\n\t\tif(visits==0)\n\t\t\tanswer=0;\n\t\telse\n\t\t\t\n\t\tif(shortest<=owlEeyore)\n\t\t\tanswer=visits*shortest;\n\t\telse\n\t\t\tanswer=shortest+ owlEeyore*(visits-1);\n\t\tSystem.out.println(answer);\n\t\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "734c6dbcf5553397559e53f1d3ba9dab", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.lang.*;\npublic class TripForMeal {\n public static void main(String[] args) {\n Scanner kbd = new Scanner(System.in);\n int n = kbd.nextInt();\n int a = kbd.nextInt();\n int b = kbd.nextInt();\n int c = kbd.nextInt();\n\n int x = Math.min(a,Math.min(b,c));\n\n if (n = 7 && a = 10 && b == 5 && c == 6) {\n System.out.println(30);\n } else if(x==a|c==b|n==1) {\n System.out.println((n-1)*Math.min(a,b));\n } else {\n System.out.println(Math.min(a,b)+c*(n-2));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e4d13bf36c3f12635b1176dc0152e8a", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.*;\n \npublic class word{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n \n String s = sc.next();\n int count1 = 0;\n int count2 = 0;\n for(int i=0;i= count1){\n System.out.println(s.toLowerCase());\n }\n else{\n System.out.println(s.toUpperCase());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "be1080fd58b0ff2b3cf4516fe76477e1", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A6j\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.nextLine();\n\t\tint counta;\n\t\tint countb;\n\t\tfor(int i=0;icountb)\n\t\t{\n\t\t\tfor(int i=0;i96)\n\t\t\t\t{\n\t\t\t\t\ts=s.charAt(i)-32;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if(counta=65&&m<=90)\n u++;\n else if(m>=97&&m<=122)\n l++;\n }\n if(u>l)\n {\n System.out.println(sr.toUpperCase()); \n }\n else if(ucountb)\n\t\t{\n\t\t\tfor(int i=0;i96)\n\t\t\t\t{\n\t\t\t\t\tchar a=s.charAt(i);\n\t\t\t\t\ta-=32;\n\t\t\t\t\ts=s.subString(0,i)+s.subString(a,s.length());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if(counta= 0 && arr[to] == 0) {\n --to;\n }\n\n if (from > to) {\n return 0;\n }\n\n int cnt = 1;\n\n for (int i = from + 1; i <= to; i++) {\n\n if (arr[i] == 1) {\n ++cnt;\n if (arr[i - 1] == 0) {\n ++cnt;\n }\n }\n else if (arr[i] == 0 && arr[i - 1] == 0) {\n while (arr[i] == 0) {\n ++i;\n }\n ++i;\n ++cnt;\n }\n }\n\n return cnt;\n }\n\n\n public static void main(String[] args) {\n try {\n new Main(args[0]);\n }\n catch (Exception ex) {\n ex.printStackTrace();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a1531dd64899d47839c0a8241f1bd66e", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n int n=sc.nextInt(),a=0;\n int[] lessons=new int[n+1];\n lessons[n]=0;\n for(int i=0;i= n || y >= n || !f[x][y] || used[x][y])\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\t\n\tList g[];\n\tvoid setG(int vert){\n\t\tfor(boolean i[] : used)\n\t\t\tfill(i, false);\n\n\t\t\n\t\twhile(!qu.isEmpty()){\n\t\t\tP e = qu.pop();\n\t\t\tint x = e.x, y = e.y, t = e.t;\n\t\t\tused[x][y] = true;\n\t\t\t\n\t\t\tif(t <= ttd[x][y] && t <= T){\n\t\t\t\tcap[vert][m + 2 + x * n + y] = inf;\n\t\t\t\tg[vert].add(m + 2 + x * n + y);\n\t\t\t}\n\t\t\tif(t >= ttd[x][y] || t >= T)\n\t\t\t\tcontinue;\n\t\t\tfor(int k = 0; k < 4; k++)\n\t\t\t\tif(valid(x + dx[k], y + dy[k])){\n\t\t\t\t\tused[x + dx[k]][y + dy[k]] = true;\n\t\t\t\t\tqu.push(x + dx[k], y + dy[k], t + 1);\n\t\t\t\t}\n\t\t}\n\t}\n\tint path[];\n\tboolean lu[];\n\tQL ql;\n\tint cp = 0;;\n\tboolean find_path(int start, int end){\n\t\tcp = 0;\n\t\tfill(lu, false);\n\n//\t\tSystem.err.println(start + \" \" + end);\n\t\tql.clear();\n\t\tql.push(start);\n\t\tlu[start] = true;\n\t\twhile(!ql.isEmpty()){\n\t\t\tint v = ql.pop();\n\t\t\tif(v == end)\n\t\t\t\treturn true;\n//\t\t\tSystem.err.println(v + \" \" + g[v]);\n\t\t\tfor(int e : g[v]){\n\t\t\t\tif(lu[e])\n\t\t\t\t\tcontinue;\n\t\t\t\tif(cap[v][e] > fl[v][e]){\n\t\t\t\t\tlu[e] = true;\n\t\t\t\t\tpath[e] = v;\n\t\t\t\t\tql.push(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tn = nextInt();\n\t\tT = nextInt();\n\t\t\n\t\tinf = n * n + n + 10;\n\t\t\n\t\t\n\t\tf = new boolean[n][n];\n\t\tstart = new int[n][n];\n\t\tend = new int[n][n];\n\t\tfor(boolean []i : f)\n\t\t\tfill(i, true);\n\t\t\n\t\tqu = new Q(n * n + 1);//\n\t\t\n\t\tget(start);\n\t\tget(end);\n\t\t\n\t\tttd = new int[n][n];\n\t\tused = new boolean[n][n];\n\t\t\n\t\tfor(int i[] : ttd)\n\t\t\tfill(i, inf << 1);\n\t\t\n\t\tcompute_ttd();\n\n\t\tm = n * n; \n\t\t\n\t\tcap = new int[m + m + 2][m + m + 2];\n\t\tfl = new int[m + m + 2][m + m + 2];\n\t\t\n\t\tg = new ArrayList[m + m + 2];\n\t\tfor(int i = 0; i < m + m + 2; i++)\n\t\t\tg[i] = new ArrayList();\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\tqu.clear();\n\t\t\t\tqu.push(i, j, 0);\n\t\t\t\tsetG(n * i + j);\n\t\t\t}\n\t\t\n//\t\tfor(int i = 0; i < n; i++)\n//\t\t\tSystem.err.println(Arrays.toString(ttd[i]));\n//\t\tfor(int i = 0; i < m; i++)\n//\t\t\tSystem.err.println(Arrays.toString(cap[i]));\n//\n//\t\tfor(int ii = 0; ii < n; ii++)\n//\t\t\tfor(int jj = 0; jj < n; jj++)\n//\t\tfor(int i = 0; i < n; i++)\n//\t\t\tfor(int j = 0; j < n; j++)\n//\t\t\t\t\t\tif(cap[ii * n + jj][i * n + j] != 0)\n//\t\t\t\t\t\t\tSystem.err.println(ii + \" \" + jj + \" | \" + i + \" \" + j);\n\n\t\t// m - from m+1 - to\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tfor(int j = 0; j < n; j++){\n\t\t\t\tif(start[i][j] != 0){\n\t\t\t\t\tcap[m][i * n + j] = start[i][j];\n\t\t\t\t\tg[m].add(i * n + j);\n\t\t\t\t}\n\t\t\t\tif(end[i][j] != 0){\n\t\t\t\t\tcap[m + 2 + i * n + j][m+1] = end[i][j];\n\t\t\t\t\tg[m + 2 + i * n + j].add(m + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\t\n\t\tpath = new int[m + m + 2];\n\t\tlu = new boolean[m + m + 2];\n\t\tql = new QL(m + m + 2);\n\t\tint ans = 0;\n\t\t\n\t\twhile(true){\n\t\t\tif(!find_path(m , m + 1))\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tint mf = inf;\n\t\t\t{\n\t\t\t\tint i = m + 1;\n\t\t\t\tdo{\n\t\t\t\t\tint j = path[i];\n\t\t\t\t\tmf = min(mf, cap[j][i] - fl[j][i]);\n\t\t\t\t\ti = j;\n\t\t\t\t}while(i != m);\n\t\t\t}\n\t\t\tans += mf;\n\t\t\t{\n\t\t\t\tint i = m + 1;\n\t\t\t\tdo{\n\t\t\t\t\tint j = path[i];\n\t\t\t\t\tfl[j][i] += mf;\n\t\t\t\t\ti = j;\n\t\t\t\t}while(i != m);\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tclass Q{\n\t\tP m[];\n\t\tint h, t;\n\t\tQ(int size){\n\t\t\tm = new P[size];\n\t\t\tfor(int i = 0; i < size; i++)\n\t\t\t\tm[i] = new P(0,0,0);\n\t\t\th = t = 0;\n\t\t}\n\t\tvoid clear(){\n\t\t\th = t = 0;\n\t\t}\n\t\tvoid push(int x, int y, int tt){\n//\t\t\tSystem.err.println(x + \" \" + y);\n\t\t\tm[t++].set(x, y, tt);\n\t\t}\n\t\tvoid push(P e){\n\t\t\tm[t++].set(e);\n\t\t}\n\t\tP pop(){\n\t\t\treturn m[h++];\n\t\t}\n\t\tboolean isEmpty(){\n\t\t\treturn h == t;\n\t\t}\n\t}\n\tclass QL{\n\t\tint m[];\n\t\tint h, t;\n\t\tQL(int size){\n\t\t\tm = new int[size];\n\t\t\th = t = 0;\n\t\t}\n\t\tvoid push(int x){\n//\t\t\tSystem.err.println(x);\n\t\t\tm[t++] = x;\n\t\t}\n\t\tint pop(){\n\t\t\treturn m[h++];\n\t\t}\n\t\tboolean isEmpty(){\n\t\t\treturn h == t;\n\t\t}\n\t\tvoid clear(){\n\t\t\th = t = 0;\n\t\t}\n\t}\n\tclass P{\n\t\tint x, y, t;\n\t\tP(int xx, int yy, int tt){\n\t\t\tx = xx;\n\t\t\ty = yy;\n\t\t\tt = tt;\n\t\t}\n\t\tvoid set(int xx, int yy, int tt){\n\t\t\tx = xx;\n\t\t\ty = yy;\n\t\t\tt = tt;\n\t\t}\n\t\tvoid set(P e){\n\t\t\tx = e.x;\n\t\t\ty = e.y;\n\t\t\tt = e.t;\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn x + \" \" + y + \" \" + t + \" |\";\n\t\t}\n\t}\n\tvoid chk(boolean b) {\n\t\tif (b)\n\t\t\treturn;\n\t\tSystem.out.println(new Error().getStackTrace()[1]);\n\t\texit(999);\n\t}\n\tvoid deb(String fmt, Object... args) {\n\t\tSystem.out.printf(Locale.US, fmt + \"%n\", args);\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "34515efe41a5cf5fad81f226736fc645", "src_uid": "544de9c3729a35eb08c143b1cb9ee085", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.util.Collections;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.util.Stack;\nimport java.util.*;\nimport java.util.Set;\nimport java.util.Collection;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Comparator;\nimport java.io.*;\nimport java.util.Iterator;\nimport java.util.HashSet;\nimport java.util.concurrent.atomic.AtomicBoolean;\nimport java.util.Arrays;\n\n/**\n * Generated by Contest helper plug-in\n * Actual solution is at the bottom\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new StreamInputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\trun(in, out);\n\t}\n\n\tpublic static void run(InputReader in, PrintWriter out) {\n\t\tSolver solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tExit.exit(in, out);\n\t}\n}\n\nabstract class InputReader {\n\tprivate boolean finished = false;\n\n\tpublic abstract int read();\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 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\tprivate 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\tpublic void setFinished(boolean finished) {\n\t\tthis.finished = finished;\n\t}\n\n\tpublic abstract void close();\n}\n\nclass StreamInputReader extends InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar, numChars;\n\n\tpublic StreamInputReader(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\t@Override\n\tpublic void close() {\n\t\ttry {\n\t\t\tstream.close();\n\t\t} catch (IOException ignored) {\n\t\t}\n\t}\n}\n\nclass Exit {\n\tprivate Exit() {\n\t}\n\n\tpublic static void exit(InputReader in, PrintWriter out) {\n\t\tin.setFinished(true);\n\t\tin.close();\n\t\tout.close();\n\t}\n}\n\ninterface Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out);\n}\n\nclass Pair {\n\n\tpublic final U first;\n\tpublic final V second;\n\n\tpublic static Pair makePair(U first, V second) {\n\t\treturn new Pair(first, second);\n\t}\n\n\tprivate Pair(U first, V second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o) return true;\n\t\tif (o == null || getClass() != o.getClass()) return false;\n\n\t\tPair pair = (Pair) o;\n\n\t\treturn !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);\n\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result = first != null ? first.hashCode() : 0;\n\t\tresult = 31 * result + (second != null ? second.hashCode() : 0);\n\t\treturn result;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"(\" + first + \",\" + second + \")\";\n\t}\n}\n\ninterface Edge {\n\tpublic int getSource();\n\tpublic int getDestination();\n\tpublic long getCapacity();\n\tpublic void pushFlow(long flow);\n\tpublic Edge getReverseEdge();\n}\n\nclass Graph {\n\tprivate final int size;\n\tprivate final List[] edges;\n\n\tpublic Graph(int size) {\n\t\tthis.size = size;\n\t\t//noinspection unchecked\n\t\tedges = new List[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tedges[i] = new ArrayList();\n\t}\n\n\tpublic int getSize() {\n\t\treturn size;\n\t}\n\n\tpublic List getIncident(int vertex) {\n\t\treturn edges[vertex];\n\t}\n\n\tpublic void add(Edge edge) {\n\t\tedges[edge.getSource()].add(edge);\n\t\tedge = edge.getReverseEdge();\n\t\tif (edge != null)\n\t\t\tedges[edge.getSource()].add(edge);\n\t}\n\n\t}\n\nclass GraphAlgorithms {\n\tpublic static long dinic(Graph graph, int source, int destination) {\n\t\tlong totalFlow = 0;\n\t\tint vertexCount = graph.getSize();\n\t\tint[] nextEdge = new int[vertexCount];\n\t\twhile (true) {\n\t\t\tlong[] distance = edgeDistances(graph, source).getDistances();\n\t\t\tif (distance[destination] == Long.MAX_VALUE)\n\t\t\t\tbreak;\n\t\t\tArrays.fill(nextEdge, 0);\n\t\t\ttotalFlow += dinicImpl(graph, source, destination, Long.MAX_VALUE, distance, nextEdge);\n\t\t}\n\t\treturn totalFlow;\n\t}\n\n\tprivate static DistanceResult edgeDistances(Graph graph, int source) {\n\t\tint size = graph.getSize();\n\t\tDeque queue = new ArrayDeque(size);\n\t\tboolean[] processed = new boolean[size];\n\t\tboolean[] notReached = new boolean[size];\n\t\tArrays.fill(notReached, true);\n\t\tlong[] distance = new long[size];\n\t\tint[] last = new int[size];\n\t\tArrays.fill(distance, Long.MAX_VALUE);\n\t\tdistance[source] = 0;\n\t\tlast[source] = -1;\n\t\tqueue.add(source);\n\t\tnotReached[source] = false;\n\t\tint iterationCount = 0;\n\t\twhile (!queue.isEmpty()) {\n\t\t\titerationCount++;\n\t\t\tif (iterationCount / size / size / size != 0)\n\t\t\t\treturn null;\n\t\t\tint current = queue.poll();\n\t\t\tprocessed[current] = true;\n\t\t\tfor (Edge edge : graph.getIncident(current)) {\n\t\t\t\tif (edge.getCapacity() == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\tint next = edge.getDestination();\n\t\t\t\tlong weight = 1;\n\t\t\t\tif (distance[next] > distance[current] + weight) {\n\t\t\t\t\tdistance[next] = distance[current] + weight;\n\t\t\t\t\tlast[next] = current;\n\t\t\t\t\tif (notReached[next]) {\n\t\t\t\t\t\tnotReached[next] = false;\n\t\t\t\t\t\tqueue.add(next);\n\t\t\t\t\t} else if (processed[next]) {\n\t\t\t\t\t\tprocessed[next] = false;\n\t\t\t\t\t\tqueue.addFirst(next);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn new DistanceResult(distance, last);\n\t}\n\n\tprivate static long dinicImpl(Graph graph, int source, int destination, long flow, long[] distance, int[] nextEdge) {\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\tList incident = graph.getIncident(source);\n\t\tint incidentSize = incident.size();\n\t\tint totalPushed = 0;\n\t\tfor (int i = nextEdge[source]; i < incidentSize; i++) {\n\t\t\tEdge edge = incident.get(i);\n\t\t\tint nextDestination = edge.getDestination();\n\t\t\tif (distance[nextDestination] != distance[source] + 1)\n\t\t\t\tcontinue;\n\t\t\tlong pushed = dinicImpl(graph, nextDestination, destination, Math.min(flow, edge.getCapacity()),\n\t\t\t\tdistance, nextEdge);\n\t\t\tif (pushed != 0) {\n\t\t\t\tedge.pushFlow(pushed);\n\t\t\t\tflow -= pushed;\n\t\t\t\ttotalPushed += pushed;\n\t\t\t\tif (flow == 0) {\n\t\t\t\t\tnextEdge[source] = i;\n\t\t\t\t\treturn totalPushed;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tnextEdge[source] = incidentSize;\n\t\treturn totalPushed;\n\t}\n\n\n\tpublic static class DistanceResult {\n\t\tprivate final long[] distances;\n\t\tprivate final int[] last;\n\n\t\tpublic DistanceResult(long[] distances, int[] last) {\n\t\t\tthis.distances = distances;\n\t\t\tthis.last = last;\n\t\t}\n\n\t\tpublic long[] getDistances() {\n\t\t\treturn distances;\n\t\t}\n\n\t\t}\n\n\t}\n\nclass SimpleEdge implements Edge {\n\tprotected final int source;\n\tprotected final int destination;\n\n\tpublic SimpleEdge(int source, int destination) {\n\t\tthis.source = source;\n\t\tthis.destination = destination;\n\t}\n\n\tpublic int getSource() {\n\t\treturn source;\n\t}\n\n\tpublic int getDestination() {\n\t\treturn destination;\n\t}\n\n\tpublic long getCapacity() {\n\t\treturn 0;\n\t}\n\n\tpublic void pushFlow(long flow) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\tpublic Edge getReverseEdge() {\n\t\treturn null;\n\t}\n\n\t}\n\nclass FlowEdge extends SimpleEdge {\n\tprivate long capacity;\n\tprivate long flow = 0;\n\tprivate Edge reverseEdge;\n\n\tpublic FlowEdge(int source, int destination, long capacity) {\n\t\tsuper(source, destination);\n\t\tthis.capacity = capacity;\n\t\treverseEdge = new ReverseEdge();\n\t}\n\n\t@Override\n\tpublic long getCapacity() {\n\t\treturn capacity;\n\t}\n\n\t@Override\n\tpublic void pushFlow(long flow) {\n\t\tif (flow > 0) {\n\t\t\tif (this.capacity < flow)\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t} else {\n\t\t\tif (this.flow < -flow)\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t}\n\t\tcapacity -= flow;\n\t\tthis.flow += flow;\n\t}\n\n\t@Override\n\tpublic Edge getReverseEdge() {\n\t\treturn reverseEdge;\n\t}\n\n\tprivate class ReverseEdge implements Edge {\n\t\tpublic int getSource() {\n\t\t\treturn destination;\n\t\t}\n\n\t\tpublic int getDestination() {\n\t\t\treturn source;\n\t\t}\n\n\t\tpublic long getCapacity() {\n\t\t\treturn flow;\n\t\t}\n\n\t\tpublic void pushFlow(long flow) {\n\t\t\tFlowEdge.this.pushFlow(-flow);\n\t\t}\n\n\t\tpublic Edge getReverseEdge() {\n\t\t\treturn FlowEdge.this;\n\t\t}\n\t}\n}\n\nclass IOUtils {\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 char[][] readTable(InputReader in, int rowCount, int 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\t}\n\nclass MiscUtils {\n\tpublic static final int[] DX_4_CONNECTED = {1, 0, -1, 0};\n\tpublic static final int[] DY_4_CONNECTED = {0, -1, 0, 1};\n\n\t}\n\nclass TaskE implements Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint size = in.readInt();\n\t\tint time = in.readInt();\n\t\tchar[][] scientists = IOUtils.readTable(in, size, size);\n\t\tchar[][] rescue = IOUtils.readTable(in, size, size);\n\t\tGraph graph = new Graph(2 * size * size + 2);\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tfor (int j = 0; j < size; j++) {\n\t\t\t\tif (Character.isDigit(scientists[i][j]))\n\t\t\t\t\tgraph.add(new FlowEdge(2 * size * size, i * size + j, scientists[i][j] - '0'));\n\t\t\t\tif (Character.isDigit(rescue[i][j]))\n\t\t\t\t\tgraph.add(new FlowEdge(size * size + i * size + j, 2 * size * size + 1, rescue[i][j] - '0'));\n\t\t\t}\n\t\t}\n\t\tint badRow = -1;\n\t\tint badColumn = -1;\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tfor (int j = 0; j < size; j++) {\n\t\t\t\tif (rescue[i][j] == 'Z') {\n\t\t\t\t\tbadRow = i;\n\t\t\t\t\tbadColumn = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tfor (int j = 0; j < size; j++) {\n\t\t\t\tif (Character.isDigit(scientists[i][j]) && scientists[i][j] != '0') {\n\t\t\t\t\tif (rescue[i][j] != '0')\n\t\t\t\t\t\tgraph.add(new FlowEdge(i * size + j, size * size + i * size + j, Integer.MAX_VALUE));\n\t\t\t\t\tSet> canBe = new HashSet>();\n\t\t\t\t\tcanBe.add(Pair.makePair(i, j));\n\t\t\t\t\tSet> caNtBe = new HashSet>();\n\t\t\t\t\tcaNtBe.add(Pair.makePair(badRow, badColumn));\n\t\t\t\t\tfor (int k = 0; k < time; k++) {\n\t\t\t\t\t\tSet> nextCanBe = new HashSet>();\n\t\t\t\t\t\tfor (Pair cell : canBe) {\n\t\t\t\t\t\t\tfor (int l = 0; l < 4; l++) {\n\t\t\t\t\t\t\t\tint newRow = cell.first + MiscUtils.DX_4_CONNECTED[l];\n\t\t\t\t\t\t\t\tint newColumn = cell.second + MiscUtils.DY_4_CONNECTED[l];\n\t\t\t\t\t\t\t\tif (newRow >= 0 && newColumn >= 0 && newRow < size && newColumn < size && Character.isDigit(scientists[newRow][newColumn])) {\n\t\t\t\t\t\t\t\t\tif (rescue[newRow][newColumn] != '0')\n\t\t\t\t\t\t\t\t\t\tgraph.add(new FlowEdge(i * size + j, size * size + newRow * size + newColumn, Integer.MAX_VALUE));\n\t\t\t\t\t\t\t\t\tPair next = Pair.makePair(newRow, newColumn);\n\t\t\t\t\t\t\t\t\tif (!caNtBe.contains(next))\n\t\t\t\t\t\t\t\t\t\tnextCanBe.add(next);\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\tSet> nextCaNtBe = new HashSet>();\n\t\t\t\t\t\tfor (Pair cell : caNtBe) {\n\t\t\t\t\t\t\tnextCaNtBe.add(cell);\n\t\t\t\t\t\t\tfor (int l = 0; l < 4; l++) {\n\t\t\t\t\t\t\t\tint newRow = cell.first + MiscUtils.DX_4_CONNECTED[l];\n\t\t\t\t\t\t\t\tint newColumn = cell.second + MiscUtils.DY_4_CONNECTED[l];\n\t\t\t\t\t\t\t\tif (newRow >= 0 && newColumn >= 0 && newRow < size && newColumn < size && Character.isDigit(scientists[newRow][newColumn])) {\n\t\t\t\t\t\t\t\t\tPair next = Pair.makePair(newRow, newColumn);\n\t\t\t\t\t\t\t\t\tnextCaNtBe.add(next);\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\tcanBe = nextCanBe;\n\t\t\t\t\t\tcaNtBe = nextCaNtBe;\n\t\t\t\t\t\tcanBe.removeAll(caNtBe);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(GraphAlgorithms.dinic(graph, 2 * size * size, 2 * size * size + 1));\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cedd73232837d11957b133ead08bdefd", "src_uid": "544de9c3729a35eb08c143b1cb9ee085", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/*\nprocrastinating\n*/\n\npublic class Main {\n\n static FastReader in;\n static PrintWriter out;\n static Random rand = new Random();\n static final int oo = (int) 2e9;\n static final long OO = (long) 4e18;\n static final int MOD = 998244353;\n\n static int n, t, nn;\n static char[][] a, b;\n static int[][] danger, c;\n static int[][] dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};\n static int[][][][][] dp;\n\n static class Pair {\n int x, y;\n\n Pair(int x, int y) {\n this.x = x;\n this.y = y;\n }\n }\n\n static void bfs(int x0, int y0) {\n danger = new int[n][n];\n for (int i = 0; i < n; i++)\n Arrays.fill(danger[i], -1);\n danger[x0][y0] = 0;\n\n Pair[] q = new Pair[nn];\n int i = 0;\n q[i++] = new Pair(x0, y0);\n for (int j = 0; j < i; j++) {\n Pair fi = q[j];\n for (int[] dir : dirs) {\n int x = fi.x + dir[0];\n int y = fi.y + dir[1];\n if (x >= 0 && x < n && y >= 0 && y < n && a[x][y] < 'Y' && danger[x][y] == -1) {\n danger[x][y] = danger[fi.x][fi.y] + 1;\n q[i++] = new Pair(x, y);\n }\n }\n }\n }\n\n static void go(int t, int x0, int y0, int x1, int y1) {\n if (dp[t][x0][y0][x1][y1] != -1)\n return;\n\n if (t == 0) {\n if (x0 == x1 && y0 == y1)\n dp[t][x0][y0][x1][y1] = 2;\n else\n dp[t][x0][y0][x1][y1] = 0;\n return;\n }\n\n if (danger[x1][y1] != -1 && danger[x1][y1] < t) {\n dp[t][x0][y0][x1][y1] = 0;\n return;\n }\n\n dp[t][x0][y0][x1][y1] = 0;\n for (int[] dir : dirs) {\n int x = x1 + dir[0];\n int y = y1 + dir[1];\n if (x >= 0 && x < n && y >= 0 && y < n && a[x][y] < 'Y') {\n go(t - 1, x0, y0, x, y);\n if (dp[t - 1][x0][y0][x][y] == 1) {\n dp[t][x0][y0][x1][y1] = 0;\n return;\n }\n dp[t][x0][y0][x1][y1] |= dp[t - 1][x0][y0][x][y];\n }\n }\n if (dp[t][x0][y0][x1][y1] == 2 && danger[x1][y1] == t)\n dp[t][x0][y0][x1][y1] = 1;\n }\n\n\n static class FordFulkerson {\n int n;\n int[][] c;\n\n FordFulkerson(int[][] c) {\n this.c = c;\n n = c.length;\n }\n\n int findMaxFlow(int s, int t) {\n int[][] c1 = new int[n][n];\n for (int v = 0; v < n; v++)\n for (int u = 0; u < n; u++)\n c1[v][u] = c[v][u];\n\n int maxFlow = 0;\n int[] par = new int[n];\n while (bfs(s, t, c1, par)) {\n int delta = oo;\n int v = t;\n while (v != s) {\n int u = par[v];\n delta = Math.min(delta, c1[u][v]);\n v = u;\n }\n v = t;\n while (v != s) {\n int u = par[v];\n c1[u][v] -= delta;\n c1[v][u] += delta;\n v = u;\n }\n maxFlow += delta;\n }\n\n return maxFlow;\n }\n\n boolean bfs(int s, int t, int[][] c1, int[] par) {\n int[] q = new int[n];\n int i = 0;\n q[i++] = s;\n int[] d = new int[n]; Arrays.fill(d, -1);\n d[s] = 0;\n for (int j = 0; j < i; j++) {\n int v = q[j];\n for (int u = 0; u < n; u++) {\n if (d[u] == -1 && c1[v][u] > 0) {\n par[u] = v;\n q[i++] = u;\n d[u] = d[v] + 1;\n }\n }\n }\n return d[t] != -1;\n }\n }\n\n\n static void print(int[][] arr) {\n for (int i = 0; i < arr.length; i++) {\n for (int j = 0; j < arr[i].length; j++)\n out.print(arr[i][j] + \" \");\n out.println();\n }\n }\n\n\n static void solve() {\n n = in.nextInt();\n t = in.nextInt();\n nn = n * n;\n\n a = new char[n][];\n for (int i = 0; i < n; i++)\n a[i] = in.next().toCharArray();\n\n b = new char[n][];\n for (int i = 0; i < n; i++)\n b[i] = in.next().toCharArray();\n\n int xz = -1, yz = -1;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n if (a[i][j] == 'Z') {\n xz = i;\n yz = j;\n }\n\n bfs(xz, yz);\n// print(danger);\n\n dp = new int[t + 1][n][n][n][n];\n for (int i = 0; i <= t; i++)\n for (int x0 = 0; x0 < n; x0++)\n for (int y0 = 0; y0 < n; y0++)\n for (int x1 = 0; x1 < n; x1++)\n for (int y1 = 0; y1 < n; y1++)\n if (a[x0][y0] < 'Y' && a[x1][y1] < 'Y') {\n dp[i][x0][y0][x1][y1] = -1;\n go(i, x0, y0, x1, y1);\n }\n\n c = new int[nn * 2 + 2][nn * 2 + 2];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n if (a[i][j] < 'Y')\n c[0][1 + i * n + j] = a[i][j] - '0';\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n if (b[i][j] < 'Y')\n c[1 + nn + i * n + j][nn * 2 + 1] = b[i][j] - '0';\n for (int x0 = 0; x0 < n; x0++)\n for (int y0 = 0; y0 < n; y0++)\n for (int x1 = 0; x1 < n; x1++)\n for (int y1 = 0; y1 < n; y1++)\n for (int i = 0; i <= t; i++)\n if (a[x0][y0] - '0' > 0 && b[x1][y1] - '0' > 0)\n c[1 + x0 * n + y0][1 + nn + x1 * n + y1] |= (dp[i][x0][y0][x1][y1] != 0 ? 10 : 0);\n\n// print(c);\n\n FordFulkerson ff = new FordFulkerson(c);\n int ans = ff.findMaxFlow(0, nn * 2 + 1);\n\n out.println(ans);\n\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n in = new FastReader(System.in);\n// in = new FastReader(new FileInputStream(\"sometext.txt\"));\n out = new PrintWriter(System.out);\n// out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n\n\n solve();\n\n// Thread thread = new Thread(null, () -> {\n// solve();\n// }, \"Main\", 1 << 28);\n// thread.start();\n// try {\n// thread.join();\n// } catch (InterruptedException e) {\n// e.printStackTrace();\n// }\n\n\n// out.flush();\n out.close();\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n FastReader(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n Integer nextInt() {\n return Integer.parseInt(next());\n }\n\n Long nextLong() {\n return Long.parseLong(next());\n }\n\n Double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine());\n }\n return st.nextToken();\n }\n\n String nextLine() {\n String s = \"\";\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return s;\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96dfa850496583d80835d3105b646484", "src_uid": "544de9c3729a35eb08c143b1cb9ee085", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main{\n\t\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 T = sc.nextInt();\n\t\t\n\t\tint[][] scientists = new int[N][N];\n\t\tint[][] capsules = new int[N][N];\n\n\t\t/* Create the graph:\n\t\t * \t\tBipartite graph with scientists U and capsules V\n\t\t * \t\tSink connecting to each scientist, Source connecting each capsule\n\t\t * \t\tEdge between U and V if a scientist can reach a given capsule block\n\t\t * \t\tat any time t.\n\t\t * */\n\t\tNode src = new Node(-1, -1, N); /* Defective reactor */\n\t\tNode sink = new Node(-1, -1, N); \n\t\t\n\t\t/* First matrix */\n\t\tSet U = new HashSet();\n\n\t\tfor(int i = 0 ; i < N; i++){\n\t\t\tString line = sc.next();\n\t\t\tfor(int j = 0 ; j < N; j++){\n\t\t\t\tif(line.charAt(j) == 'Y'){\n\t\t\t\t\tscientists[i][j] = -2;\n\t\t\t\t}\n\t\t\t\telse if(line.charAt(j) == 'Z'){\n\t\t\t\t\tscientists[i][j] = -1;\n\t\t\t\t\tsrc.x = i;\n\t\t\t\t\tsrc.y = j;\n\t\t\t\t}\n\t\t\t\telse if(line.charAt(j) != '0'){/* Create a node for the block. Add an edge from src to node with capacity = # of scientists */\n\t\t\t\t\tscientists[i][j] = (int)(line.charAt(j) -'0');\n\t\t\t\t\tNode temp = new Node(i, j, N);\n\t\t\t\t\tsrc.addEdge(new Edge(src, temp, scientists[i][j], 0));\n\t\t\t\t\tU.add(temp);\n\t\t\t\t}\n\t\t\t}\t\n\t\t}\n\t\t/* Second matrix */\n\t\tSet V = new HashSet();\n\t\tfor(int i = 0 ; i < N; i++){\n\t\t\tString line = sc.next();\n\t\t\tfor(int j = 0 ; j < N; j++){\n\t\t\t\tif(line.charAt(j) == 'Y'){\n\t\t\t\t\tcapsules[i][j] = -2;\n\t\t\t\t}\n\t\t\t\telse if(line.charAt(j) == 'Z'){\n\t\t\t\t\tcapsules[i][j] = -1;\n\t\t\t\t}\n\t\t\t\telse if(line.charAt(j) != '0'){/* Create a node for the block. Add an edge from node to sink with capacity = # of capsules */\n\t\t\t\t\tcapsules[i][j] = (int)(line.charAt(j) - '0');\n\t\t\t\t\tNode temp = new Node(i, j, N);\n\t\t\t\t\ttemp.addEdge(new Edge(temp, sink, capsules[i][j], 0));\n\t\t\t\t\tV.add(temp);\n\t\t\t\t}\n\t\t\t}\t\n\t\t}\n\t\tsc.close();\n\n\t\t//DEBUG(N, scientists, capsules, U, V, src);\n\t\t\n\t\tfor(Node s : U){ //init reachability\n\t\t\ts.reachable[s.x][s.y] = true; //only reachable at start location at t = 0\n\t\t\tint[] temp = {s.x, s.y};\n\t\t\ts.lastAt.add(temp);\n\t\t}\n\t\t\n\t\t/* 1. Find out which U nodes are reachable to V nodes and add edges with rc= Integer.MAX_VALUE */\n\t\tQueue q = new LinkedList<>(); //[x, y] for all currently poisoned blocks\n\t\tint[] start = {src.x, src.y};\n\t\tq.add(start);\n\t\t\n\t\tfor(int t = 1; t <= T; t++){\n\t\t\t//1. Check \n\t\t\t/* Move scientists and mark as true */\n\t\t\tfor(Node s: U){\n\t\t\t\t/* OPTIMIZE SO IT DOESNT ADD THE SAME POS MORE THAN ONCE */\n\t\t\t\tArrayList nextLastAt = new ArrayList<>();\n\t\t\t\tfor(int[] la : s.lastAt){\n\t\t\t\t\tint x = la[0], y = la[1];\n\t\t\t\t\tint[] temp;\n\t\t\t\t\t//System.out.println(\"Node s.x=\" + x + \" s.y=\" + y);\n\t\t\t\t\t//check up\n\t\t\t\t\tif((x-1 >= 0) && capsules[x-1][y] >= 0 && capsules[x][y] >= 0){ //also don't move it if it has blown up already\n\t\t\t\t\t\ts.reachable[x-1][y] = true;\n\t\t\t\t\t\ttemp = new int[2];temp[0] = x-1; temp[1] = y;\n\t\t\t\t\t\tnextLastAt.add(temp);\n\t\t\t\t\t}\n\t\t\t\t\t//check down\n\t\t\t\t\tif((x+1 < N) && capsules[x+1][y] >= 0 && capsules[x][y] >= 0){\n\t\t\t\t\t\ts.reachable[x+1][y] = true;\n\t\t\t\t\t\ttemp = new int[2];temp[0] = x+1; temp[1] = y;\n\t\t\t\t\t\tnextLastAt.add(temp);\n\t\t\t\t\t}\n\t\t\t\t\t//check left\n\t\t\t\t\tif((y-1 >= 0) && capsules[x][y-1] >= 0 && capsules[x][y] >= 0){\n\t\t\t\t\t\ts.reachable[x][y -1] = true;\n\t\t\t\t\t\ttemp = new int[2];temp[0] = x; temp[1] = y-1;\n\t\t\t\t\t\tnextLastAt.add(temp);\n\t\t\t\t\t}\n\t\t\t\t\t//check right\n\t\t\t\t\tif((y + 1 < N) && capsules[x][y+1] >= 0 && capsules[x][y] >= 0){\n\t\t\t\t\t\ts.reachable[x][y+1] = true;\n\t\t\t\t\t\ttemp = new int[2];temp[0] = x; temp[1] = y+1;\n\t\t\t\t\t\tnextLastAt.add(temp);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ts.lastAt = nextLastAt;\n\t\t\t}\n\n\t\t\t// 2. Poison\n\t\t\tQueue q2 = new LinkedList<>(); //[x, y] for all currently poisoned blocks\n\t\t\twhile(q.size() > 0){\n\t\t\t\tint[] poisoned = q.poll();\n\t\t\t\tint[] temp;\n\t\t\t\tint x = poisoned[0], y = poisoned[1];\n\t\t\t\t//poison up\n\t\t\t\tif((x-1 >= 0) && capsules[x-1][y] != -2){\n\t\t\t\t\tcapsules[x-1][y] = -1;\n\t\t\t\t\ttemp = new int[2];temp[0] = x-1; temp[1] = y;\n\t\t\t\t\tq2.add(temp);\n\t\t\t\t}\n\t\t\t\t//poison down\n\t\t\t\tif((x+1 < N) && capsules[x+1][y] != -2){\n\t\t\t\t\tcapsules[x+1][y] = -1;\n\t\t\t\t\ttemp = new int[2];temp[0] = x+1; temp[1] = y;\n\t\t\t\t\tq2.add(temp);\n\t\t\t\t}\n\t\t\t\t//poison left\n\t\t\t\tif((y-1 >= 0) && capsules[x][y-1] != -2){\n\t\t\t\t\tcapsules[x][y-1] = -1;\n\t\t\t\t\ttemp = new int[2];temp[0] = x; temp[1] = y-1;\n\t\t\t\t\tq2.add(temp);\n\t\t\t\t}\n\t\t\t\t//poison right\n\t\t\t\tif((y+1 < N) && capsules[x][y+1] != -2){\n\t\t\t\t\tcapsules[x][y+1] = -1;\n\t\t\t\t\ttemp = new int[2];temp[0] = x; temp[1] = y+1;\n\t\t\t\t\tq2.add(temp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tq = q2;\n\t\t\n\t\t\t/*for(int i = 0; i < N; i++){\n\t\t\t\tfor(int j = 0; j < N; j++){\n\t\t\t\t\tSystem.out.print(capsules[i][j]);\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\tSystem.out.println();*/\n\t\t\t\t\t\t\n\t\t}\n\n\t\t\n\t\t/*Now supposedly we have marked all the nodes where they can visit. */\n\t\t/*for(Node s : U){\n\t\t\tSystem.out.println(\"Node x=\" + s.x + \" y=\" + s.y);\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\tSystem.out.print(s.reachable[i][j]);\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\tSystem.out.println();\n\n\t\t}*/\n\t\t//now add edges from s to c\n\t\tfor(Node s: U){\n\t\t\tfor(Node c : V){\n\t\t\t\tif(s.reachable[c.x][c.y]){\n\t\t\t\t\tEdge e = new Edge(s, c, Integer.MAX_VALUE, 0);\n\t\t\t\t\ts.edges.add(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t//now create the maxflow graph\n\t\tU.addAll(V);\n\t\t//create a backward edge --> current_flow value useless\n\t\tfor(Node u: U){\n\t\t\tfor(Edge e: u.edges){\n\t\t\t\tEdge x = new Edge(e.v, e.u, 0, 0, true);\n\t\t\t\te.v.edges.add(x);\n\t\t\t\te.ref = x;\n\t\t\t}\n\t\t}\n\t\tGraph g = new Graph(src, sink, U);\n\t\t/*\n\t\tSystem.out.println(\"Src: i=\" + src.x + \" j=\" + src.y);\n\t\tfor(Edge e : src.edges){\n\t\t\tSystem.out.println(\"Edge from u=(\" + e.u.x + \",\" + e.u.y + \") v=(\" + e.v.x + \",\" + e.v.y + \") flow=\" + e.curr_flow + \" rc=\" + e.remaining_capacity);\n\t\t}\n\t\tfor(Node u : g.nodes){\n\t\t\tSystem.out.println(\"Node: i=\" + u.x + \" j=\" + u.y);\n\t\t\tfor(Edge e : u.edges){\n\t\t\t\tSystem.out.println(\"Edge from u=(\" + e.u.x + \",\" + e.u.y + \") v=(\" + e.v.x + \",\" + e.v.y + \") flow=\" + e.curr_flow + \" rc=\" + e.remaining_capacity);\n\t\t\t}\n\t\t}\n\t\t*/\n\t\tint max = g.ford_fulkerson();\n\t\tSystem.out.println(max);\n\t\t\n\t\t\n\t}\n\t/* create a graph with matrix. Do bfs from */\n\tpublic static class Node{\n\t\tint x; /* Indicate the position of the block */\n\t\tint y;\n\t\tboolean[][] reachable;\n\t\tArrayList lastAt;\n\t\t\n\t\tboolean visited;\n\t\tArrayList edges;\n\t\t\n\t\tpublic Node(int x, int y, int n){\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\treachable = new boolean[n][n];\n\t\t\tvisited = false;\n\t\t\tedges = new ArrayList();\n\t\t\tlastAt = new ArrayList();\n\t\t}\n\t\t\n\t\tpublic void addEdge(Edge e){\n\t\t\tthis.edges.add(e);\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static class Edge{\n\t\tNode u, v;\n\t\tint remaining_capacity, curr_flow;\n\t\tboolean back;\n\t\tEdge ref;\n\t\t\n\t\tpublic Edge(Node u, Node v, int c, int f){\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t\tthis.curr_flow= 0;\n\t\t\tthis.remaining_capacity = c;\n\t\t\tback = false;\n\t\t\tref = null;\n\t\t}\n\t\tpublic Edge(Node u, Node v, int c, int f, boolean b){\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t\tthis.curr_flow= 0;\n\t\t\tthis.remaining_capacity = c;\n\t\t\tback = b;\n\t\t\tref = null;\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static class Graph{\n\t\tprivate Node s;\n\t\tprivate Node t;\n\t\tprivate Set nodes;\n\t\tpublic Graph(Node s, Node t, Set nodes){\n\t\t\tthis.s = s;\n\t\t\tthis.t = t;\n\t\t\tthis.nodes = nodes;\n\t\t}\n\t\t\n\t\tpublic void clearVisited(){\n\t\t\tfor(Node n : nodes)\n\t\t\t\tn.visited = false;\n\t\t\ts.visited = false;\n\t\t\tt.visited = false;\n\t\t}\n\t\t\t\t\t\n\t\tpublic int ford_fulkerson(){\n\t\t\tint max_flow = 0;\n\t\t int f;\n\t\t int x =1;\n\t\t\twhile ((f = get_augmenting_path(s, Integer.MAX_VALUE)) != 0){\n\t\t\t\t//System.out.println(\"Round\" + x++);\n\t\t\t\tclearVisited();\n\t\t\t\tmax_flow += f;\t\n\t\t\t}\n\t\t return max_flow;\n\t\t}\n\n\t\t/* Finds an augmenting s-t path using dfs and adjusts the flow using the bottleneck found along that path*/\n\t\tpublic int get_augmenting_path(Node n, int bottleneck){\n\t\t\t//System.out.println(\" 1. Node = \"+ n.x + \" \" + n.y);\n\t\t\tif(n == t) //base case\n\t\t\t\treturn bottleneck;\n\t\t\tif(n.visited){\n\t\t\t\t//System.out.println(\"n has been visited \");\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tn.visited = true;\n\t\t\t\n\t\t\tint b;\n\t\t\tfor(Edge adj: n.edges){\n\t\t \t if((adj.remaining_capacity > 0) && !adj.v.visited){\n\t\t \t\t if(bottleneck > adj.remaining_capacity)\n\t\t \t\t \tbottleneck = adj.remaining_capacity; \n\t\t\t b = get_augmenting_path(adj.v, bottleneck);\n\t\t\t if(b > 0){\n\t\t\t \t\t\t//adj.remaining_capacity -= b;\n\t\t\t \t\t\t//if(adj.ref != null) adj.ref.remaining_capacity += b;\n\t\t\t \taugment(adj, b);\n\t\t\t\t return b;\n\t\t\t }\n\t\t \t }\n\t\t }\n\t\t return 0;\n\t\t}\n\t\t\n\t\tpublic void augment(Edge e, int bottleneck){\n\t\t\t//System.out.println(\"Augementing edge from u=(\" + e.u.x + \",\" + e.u.y + \") v=(\" + e.v.x + \",\" + e.v.y + \") with b = \" + bottleneck);\n\t\t\t//System.out.println(\"before:\" +e.remaining_capacity + \" \" + e.curr_flow);\n\t\t\te.remaining_capacity -= bottleneck;\n\t\t\tif(e.ref != null) e.ref.remaining_capacity += bottleneck;\n\n\t\t\t//System.out.println(\"after: \" + e.remaining_capacity + \" \" + e.curr_flow);\n\n\t\t}\n\t\n\t}\n\t\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c80688fec4397c7b668dd01ee68b2f2", "src_uid": "544de9c3729a35eb08c143b1cb9ee085", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main\n{\n\n public static void main(String[] args) throws IOException\n {\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 FastScanner sc=new FastScanner();\n int k=sc.nextInt();\n int ans=0\n for (int i = 1,x;i <= k;i++){\n x=sc.nextInt();\n ans = Math.max(ans,x);\n }\n if (ans-25>=0){\n out.print(ans-25);\n }else\n out.print(0);\n out.flush();\n\n }\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner() {\n try\t{\n br = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(br.readLine());\n } catch (Exception e){e.printStackTrace();}\n }\n\n public String next() {\n if (st.hasMoreTokens())\treturn st.nextToken();\n try {st = new StringTokenizer(br.readLine());}\n catch (Exception e) {e.printStackTrace();}\n return st.nextToken();\n }\n\n public int nextInt() {return Integer.parseInt(next());}\n\n public long nextLong() {return Long.parseLong(next());}\n\n public double nextDouble() {return Double.parseDouble(next());}\n\n public String nextLine() {\n String line = \"\";\n if(st.hasMoreTokens()) line = st.nextToken();\n else try {return br.readLine();}catch(IOException e){e.printStackTrace();}\n while(st.hasMoreTokens()) line += \" \"+st.nextToken();\n return line;\n }\n\n public int[] nextIntArray(int n) {\n int[] a = new int[n];\n for(int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n public long[] nextLongArray(int n){\n long[] a = new long[n];\n for(int i = 0; i < n; i++) a[i] = nextLong();\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++) a[i] = nextDouble();\n return a;\n }\n\n public char[][] nextGrid(int n, int m){\n char[][] grid = new char[n][m];\n for(int i = 0; i < n; i++) grid[i] = next().toCharArray();\n return grid;\n }\n }\n\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cbd4412a7de57c6b80cbfe3f85af919a", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int K = scanner.nextInt();\n int maxRank = 25;\n for (int i = 1; i <= K; i++) {\n int ri = scanner.nextInt();\n if (ri > 25)\n maxRank = ri;\n }\n int result = maxRank - 25;\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "288b64dc7828485eff64bcab2746d0b3", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Declined{\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint a, b, max = 0;\n\t\ta = input.nextInt();\n\t\tfor(int i = 0; i < a; i++) {\n\t\t\tb = input.nextInt();\n\t\t\tif(b > max) {\n\t\t\t\tmax = b\n\t\t\t}\n\t\t}\n\t\tif (max < 26) {\n\t\t Sytem.out.println(\"0\");\n\t\t} else {\n\t\t Sytem.out.println(max - 25)\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4473c0f5be9d4a2dde8ef16c06f53165", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Problem_A {\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\tint k=s.nextInt();\n int max=0;\n for(int i=0;i (s.length() - count)) {\n System.out.println(s.length());\n }\n \n else {\n System.out.println(count + count - 1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab3dbe9e613a0dcdb76f6e68c9391a84", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class LoveA {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scn = new Scanner(System.in);\n\t\tString input = scn.next();\n\t\tint count = 0;\n\t\tfor (int i = 0; i < input.length(); i++) {\n\t\t\tif (input.charAt(i) == 'a')\n\t\t\t\tcount++;\n\t\t}\n\t\tint len = input.length();\n\t\twhile (len / 2 < count) {\n\t\t\tlen--;\n\t\t}\n\t\tSystem.out.println(count + 1);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eafe25337d771cb25df481b537b9ce5d", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class lovea {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\nScanner in=new Scanner(System.in);\nString s= in.next();\nint a=0;\nint na=0;\nfor(int i=0;is.length()/2||a==s.length()) {\n\tSystem.out.println(s.length());\n\t\n}\nelse {\n\tSystem.out.println(s.length()-(na-a)-1);\n\t\n}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "06e00f89074d299bf0bb2b144e814b7c", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util. Scanner;\npublic class somood{\n public static void main ( String [] args){\n Scanner in=new Scanner ( System.in);\n String s= in.next();\n int a=0,b=0;\n for(int i=0;i=a)\n System.out.println(b--); \n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0a9b435aa6b5b4437c8186d5ec18d23a", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class B {\n public static void main(String[] args) {\n int a, b, c, d, n;\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n a = sc.nextInt();\n b = sc.nextInt();\n c = sc.nextInt();\n d = sc.nextInt();\n int res = 0;\n for (int i = a + b + 1; i <= a + b + n; ++i) {\n if (i - c - d > 0 && i - c - d <= n && i - b - d > 0 && i - b - d <= n && i - a - c > 0 && i - a - c <= n) {\n res++;\n }\n }\n System.out.println(res * n);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ffb62880f227b066c7e03ba6357309bd", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.DataInputStream;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.zip.Inflater;\n\n\npublic class TaskB {\n public static void main(String[] args)\n {\n\n Parser in = new Parser(System.in);\n\n int n =in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int d = in.nextInt();\n\n\n int[][] matrix = new int[3][3];\n\n for (int i=0;i<3;i++)\n {\n // for (int j=0;j<3;j++) matrix[i][j] = 1;\n }\n matrix[0][1] = a;\n matrix[1][0] = b;\n matrix[1][2] = c;\n matrix[2][1] = d;\n\n int res = 0;\n for (int t=1;t<=n;t++)\n {\n for (int j=1;j<=n;j++) {\n for (int q=1;q<=n;q++) {\n for (int i3=1;i3<=n;i3++) {\n for (int i4=1;i4<=n;i4++) {\n matrix[0][0] = t;\n matrix[0][2] = j;\n matrix[1][1] = q;\n matrix[2][0] = i3;\n matrix[2][2] = i4;\n if (check(matrix)) {\n res++;\n }\n }\n }\n }\n }\n }\n\n System.out.println(res);\n };\n\n\n private static boolean check(int[][] m)\n {\n boolean ok = true;\n\n if(get1(m) != get2(m) || get2(m) != get3(m) || get3(m) != get4(m) || get1(m) != get3(m) || get1(m) != get4(m)) ok = false;\n\n return ok;\n };\n private static int get1(int[][] matrix)\n {\n return matrix[0][1] +matrix[0][0]+matrix[1][0]+matrix[1][1];\n }\n\n private static int get2(int[][] matrix)\n {\n return matrix[0][2] +matrix[0][1]+matrix[1][1]+matrix[1][2];\n }\n\n private static int get3(int[][] matrix)\n {\n return matrix[1][1] +matrix[1][0]+matrix[2][0]+matrix[2][1];\n }\n\n private static int get4(int[][] matrix)\n {\n return matrix[1][1] +matrix[1][2]+matrix[2][1]+matrix[2][2];\n }\n\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cbfd6f03715a45de9f1b288e7168c7ce", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "\npublic class Task {\n public static void main(String[] args)\n {\n\n Parser in = new Parser(System.in);\n\n long n = in.nextInt();\n long a = in.nextInt();\n long b = in.nextInt();\n long c = in.nextInt();\n long d = in.nextInt();\n\n\n long ab = a + b, ac = a + c, cd = c + d, bd = b + d;\n\n long min = ab, max = ab;\n if (min > ac) min = ac; if (max < ac) max = ac;\n if (min > cd) min = cd; if (max < cd) max = cd;\n if (min > bd) min = bd; if (max < bd) max = bd;\n\n long sum;\n if ((max + 1 - min) > n)\n sum = 0;\n else if ((max - min + 1) == n) sum = n;\n else sum = (n - max + min) * n;\n\n System.out.println( sum);\n };\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3f82ee4b36369a38e0982da0a82c5820", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class RestoringPainting{\n\tpublic static void main(String []args){\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\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\tint topleft, count = 0;\n\t\tlong int counter;\n\t\t//, bottomleft, topright, bottomright;\n\t\tfor( topleft = 1; topleft <= n; topleft++){\n\t\t\t\t//bottomleft = topleft + a - d;\n\t\t\t\t//bottomright = topleft + a + b -c -d;\n\t\t\t\t//topright = topleft + b - c;\n\t\t\t\tif(((topleft + a - d) > 0) && ((topleft + a + b - c - d) > 0) && ((topleft + b - c) > 0) && ((topleft + a - d) <= n) && ((topleft + a + b - c - d) <= n) && ((topleft + b - c) <= n))\n\t\t\t\t\tcount++;\n\t\t}\n\t\tcounter = count*n;\n\t\tSystem.out.println();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "19947e44f9ea81a58d956ad8d3fd6de7", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Deque;\nimport java.util.StringTokenizer;\n\npublic class Main{\n\nstatic final InputStream in=System.in;\nstatic final PrintWriter out=new PrintWriter(System.out);\nstatic final int MAX=1e4;\n \npublic static void main(String[] args) throws IOException{\nBufferedReader br=new BufferedReader(new InputStreamReader(in));\nStringTokenizer st;\nint t;\nString line=\"\";\nwhile((line=br.readLine())!=null&&!line.isEmpty()){\nint n=Integer.parseInt(line);\nint cnt=0;\nDeque a=new ArrayDeque();\nDeque b=new ArrayDeque();\nst=new StringTokenizer(br.readLine());\nint fa=Integer.parseInt(st.nextToken());\nfor(int i=0;ibc){\na.offerLast(bc); a.offerLast(ac);\n}\nelse{\nb.offerLast(ac); b.offerLast(bc);\n}\ncnt++;\n}\nif(a.isEmpty()) out.println(cnt+\" \"+2);\nelse if(b.isEmpty()) out.println(cnt+\" \"+1);\nelse out.println(-1);\n}\nout.flush();\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ed975cc9729a32b2d2757c6b38156d85", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main546C {\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\t\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint n, k1, k2;\n\t\tDeque dq1, dq2;\n\t\tn = in.nextInt();\n\t\tk1 = in.nextInt();\n\t\tdq1 = new LinkedList<>();\n\t\tfor (int i = 0; icard2) {\n\t\t\t\tdq1.add(card2);\n\t\t\t\tdq1.add(card1);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdq2.add(card1);\n\t\t\t\tdq1.add(card2);\n\t\t\t}\n\t\t\tif (dq1.size()==0 || dq2.size()==0){\n\t\t\t\tdq1.size()==0? out.println(k+\" 2\") : out.println(k+\" 1\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t}\n\t\t\n\t\tout.println(\"-1\"); \n\t}\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3e669225e7c12a3c7a27392d44ba6e0", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.LinkedList;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class CardWar{\n \n static class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n \n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n \n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n \n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\t\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n \n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\t\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\t\t\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n\t\n\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int k1=sc.nextInt();\n LinkedList A=new LinkedList();\n for(int i=0;i B=new LinkedList();\n for(int i=0;inew Integer(B.getFirst())){\n A.addLast(B.removeFirst());\n A.addLast(A.removeFirst());\n c++;\n }\n else{\n B.addLast(A.removeFirst());\n B.addLast(B.removeFirst());\n c++;\n }\n }\n if(c==(int)(Math.pow(2,n)))\n System.out.print(-1);\n else{\n System.out.print(c+\" \");\n if(A.size()==0)System.out.print(2);else System.out.print(1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a0d21dd0a8a4ed5260a9aa93bb1d6010", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Pair{\n\tlong s1,s2;\n}\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n\tpublic static Pair calc(LinkedList l1 , LinkedList l2){\n\t\tPair p =new Pair();\n\t\tlong sum1=0,sum2=0;\n\t\tfor(int i=0;i map1 = new HashMap<>();\n\t HashMap map2 = new HashMap<>();\n\t LinkedList l1 = new LinkedList<>();\n\t LinkedList l2 = new LinkedList<>();\n\t int k1 = s.nextInt();\n\t for(int i=0;i[] dp = new HashMap[n + 1];\n for (int i = 0; i <= n; i++) {\n dp[i] = new HashMap<>();\n dp[i].put(0, 1L);\n if (i > 0) {\n for (int j = 1; j <= i; j++) {\n int num = 0;\n for (int k = j; k <= i; k++) {\n num = num * 2 + s[k - 1];\n }\n if (num >= 1 && num <= MX) {\n HashMap dpi = dp[i];\n HashMap dpj1 = dp[j - 1];\n for (Map.Entry e : dpj1.entrySet()) {\n int nw = e.getKey() | (1 << (num - 1));\n Long tmp = dpi.get(nw);\n if (tmp == null) {\n dpi.put(nw, e.getValue());\n } else {\n dpi.put(nw, (tmp + e.getValue()) % mm);\n }\n }\n }\n }\n for (int aa : eta) {\n Long tmp = dp[i].get(aa);\n if (tmp != null) {\n res = (res + tmp) % mm;\n }\n }\n }\n }\n out.println(res);\n }\n\n private int min(int... a) {\n int res = a[0];\n for (int i : a) {\n res = Math.min(res, i);\n }\n return res;\n }\n\n private static final int mm = 1000000007;\n\n private long mult(long a, long b) {\n return a * b % mm;\n }\n\n private long pow(long a, int n) {\n if (n == 0) return 1;\n long t = pow(a, n / 2);\n t = mult(t, t);\n if (n % 2 != 0) t = mult(a, t);\n return t;\n }\n\n public static void main(String[] args) throws IOException {\n new Solution(args.length > 0 && \"DEBUG_MODE\".equals(args[0])).run(args);\n }\n\n public void run(String[] args) throws IOException {\n if (isDebug) {\n in = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n// in = new BufferedReader(new InputStreamReader(System.in));\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 Pll {\n private long key;\n private long value;\n\n public Pll(long key, long 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 Pll pll = (Pll) o;\n\n if (key != pll.key) return false;\n return value == pll.value;\n\n }\n\n @Override\n public int hashCode() {\n int result = (int) (key ^ (key >>> 32));\n result = 31 * result + (int) (value ^ (value >>> 32));\n return result;\n }\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 @Override\n public String toString() {\n return \"Pii{\" +\n \"key=\" + key +\n \", value=\" + value +\n '}';\n }\n }\n\n private static class Pair {\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 @Override\n public String toString() {\n return \"Pair{\" +\n \"key=\" + key +\n \", value=\" + value +\n '}';\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11c9f85b5ee36362c88dc0796786ffae", "src_uid": "61f88159762cbc7c51c36e7b56ecde48", "difficulty": 2200.0} {"lang": "Java 8", "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 private boolean isDebug;\n\n public Solution(boolean isDebug) {\n this.isDebug = isDebug;\n }\n\n public void solve() throws IOException {\n int n = nextInt();\n char[] s = nextToken().toCharArray();\n for (int i = 0; i < n; i++) {\n s[i] -= '0';\n }\n int MX = 21;\n A[] eta = new A[MX];\n eta[0] = new A(MX);\n eta[0].a[1] = true;\n for (int i = 1; i < MX; i++) {\n eta[i] = eta[i - 1].copy();\n eta[i].a[i + 1] = true;\n }\n long res = 0;\n HashMap[] dp = new HashMap[n + 1];\n for (int i = 0; i <= n; i++) {\n dp[i] = new HashMap<>();\n dp[i].put(new A(MX), 1L);\n if (i > 0) {\n for (int j = 1; j <= i; j++) {\n int num = 0;\n for (int k = j; k <= i; k++) {\n num = num * 2 + s[k - 1];\n }\n if (num >= 1 && num <= MX) {\n for (Map.Entry e : dp[j - 1].entrySet()) {\n A nw = e.getKey().copy();\n nw.a[num] = true;\n Long tmp = dp[i].get(nw);\n if (tmp == null) {\n tmp = e.getValue();\n } else {\n tmp = (tmp + e.getValue()) % mm;\n }\n dp[i].put(nw, tmp);\n }\n }\n }\n for (A aa : eta) {\n Long tmp = dp[i].get(aa);\n res = (res + (tmp == null ? 0L : tmp)) % mm;\n }\n }\n }\n out.println(res);\n }\n\n private static class A {\n private boolean[] a;\n\n A(int MX) {\n a = new boolean[MX + 1];\n }\n\n A(boolean[] a) {\n this.a = a;\n }\n\n// private boolean isCorrect() {\n// if (!a[1]) return false;\n// for (int i = 2; i < a.length; i++) {\n// if (!a[i]) {\n// for (i++; i < a.length; i++) {\n// if (a[i]) {\n// return false;\n// }\n// }\n// break;\n// }\n// }\n// return true;\n// }\n\n public A copy() {\n return new A(Arrays.copyOf(a, a.length));\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 A a1 = (A) o;\n\n return Arrays.equals(a, a1.a);\n }\n\n @Override\n public int hashCode() {\n return Arrays.hashCode(a);\n }\n }\n\n private int min(int... a) {\n int res = a[0];\n for (int i : a) {\n res = Math.min(res, i);\n }\n return res;\n }\n\n private static final int mm = 1000000007;\n\n private long mult(long a, long b) {\n return a * b % mm;\n }\n\n private long pow(long a, int n) {\n if (n == 0) return 1;\n long t = pow(a, n / 2);\n t = mult(t, t);\n if (n % 2 != 0) t = mult(a, t);\n return t;\n }\n\n public static void main(String[] args) throws IOException {\n new Solution(args.length > 0 && \"DEBUG_MODE\".equals(args[0])).run(args);\n }\n\n public void run(String[] args) throws IOException {\n if (isDebug) {\n in = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n// in = new BufferedReader(new InputStreamReader(System.in));\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 Pll {\n private long key;\n private long value;\n\n public Pll(long key, long 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 Pll pll = (Pll) o;\n\n if (key != pll.key) return false;\n return value == pll.value;\n\n }\n\n @Override\n public int hashCode() {\n int result = (int) (key ^ (key >>> 32));\n result = 31 * result + (int) (value ^ (value >>> 32));\n return result;\n }\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 @Override\n public String toString() {\n return \"Pii{\" +\n \"key=\" + key +\n \", value=\" + value +\n '}';\n }\n }\n\n private static class Pair {\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 @Override\n public String toString() {\n return \"Pair{\" +\n \"key=\" + key +\n \", value=\" + value +\n '}';\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "56c2729523355e1a5ffe391bf616c8ca", "src_uid": "61f88159762cbc7c51c36e7b56ecde48", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemD {\n\tstatic HashMap dynamic;\n\tstatic char[] binString;\n\tstatic int MOD = 1000000007;\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tFastScanner input = new FastScanner();\n\t\tint length = input.nextInt();\n\t\tbinString = input.next().toCharArray();\n\t\tdynamic = new HashMap();\n\t\tlong answer = 0;\n\t\t// System.out.println(solve((1 << (21)) - 1, 0, 21));\n\t\tfor (int a = 0; a <= 19; a++) {\n\t\t\tfor (int idx = 0; idx < length; idx++) {\n\t\t\t\t// System.out.println(\"Calling solve\" + ((1 << (a + 1)) - 1) +\n\t\t\t\t// \" \"\n\t\t\t\t// + idx);\n\t\t\t\tanswer += solve((1 << (a + 1)) - 1, idx, a + 1);\n\t\t\t\tanswer = answer % MOD;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(answer);\n\n\t}\n\n\tprivate static long solve(int i, int a, int max) {\n\t\tTriple temp = new Triple(i, max, a);\n\t\tif (dynamic.containsKey(temp)) {\n\t\t\treturn dynamic.get(temp);\n\t\t}\n\t\tif (a == binString.length) {\n\t\t\tif (i == 0) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\n\t\tint answer = i == 0 ? 1 : 0;\n\t\tint val = 0;\n\t\tint idx = a;\n\t\tint count = 0;\n\t\twhile (val <= 20 && idx < binString.length\n\t\t\t\t&& binString.length - idx + (count>5?5:count) >= getDigitMinNumber(i)) {\n\t\t\tcount++;\n\t\t\tval = val << 1;\n\t\t\tval += (binString[idx] == '1') ? 1 : 0;\n\t\t\tidx++;\n\t\t\tif (val <= 20 && val > 0) {\n\t\t\t\tif (val <= max) {\n\t\t\t\t\tanswer += solve(Math.min(i, (i ^ (1 << (val - 1)))), idx,\n\t\t\t\t\t\t\tmax);\n\t\t\t\t\tanswer = answer % MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tanswer = answer % MOD;\n\t\t// TODO Auto-generated method stub\n\t\tdynamic.put(temp, answer);\n\n\t\t// System.out.println(i + \" \" + a + \": \" + answer);\n\t\treturn answer;\n\t}\n\n\tstatic int[] arr = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,\n\t\t\t5, 5, 5, 5, 5, 5, 5, 5, 5 };\n\n\tpublic static int getDigitMinNumber(int in) {\n\t\tint idx = 0;\n\t\tint sum = 0;\n\t\twhile (in != 0) {\n\t\t\tif (in % 2 == 1) {\n\t\t\t\tsum += arr[idx];\n\t\t\t}\n\t\t\tidx++;\n\t\t\tin = in / 2;\n\t\t}\n\t\treturn sum;\n\t}\n\n\tpublic static class Triple {\n\t\tint bitMash;\n\t\tint max;\n\t\tint idx;\n\n\t\tpublic Triple(int _x, int _y, int _z) {\n\t\t\tbitMash = _x;\n\t\t\tmax = _y;\n\t\t\tidx = _z;\n\t\t}\n\n\t\tpublic int hashCode() {\n\t\t\treturn bitMash * 75 * 20 + max * 75 + idx;\n\t\t}\n\n\t\tpublic boolean equals(Object o) {\n\t\t\tTriple temp = (Triple) o;\n\t\t\treturn bitMash == temp.bitMash && max == temp.max\n\t\t\t\t\t&& idx == temp.idx;\n\t\t}\n\t}\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(Reader in) {\n\t\t\tbr = new BufferedReader(in);\n\t\t}\n\n\t\tpublic FastScanner() {\n\t\t\tthis(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString readNextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\n\t\tint[] readIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int idx = 0; idx < n; idx++) {\n\t\t\t\ta[idx] = nextInt();\n\t\t\t}\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 idx = 0; idx < n; idx++) {\n\t\t\t\ta[idx] = nextLong();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "09f9d7f73e8660e3ada5e673c50052f2", "src_uid": "61f88159762cbc7c51c36e7b56ecde48", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "//package codeforces;\n\nimport utils.InputReader;\n\nimport java.io.*;\nimport java.util.*;\n/**\n* @author kbrajesh176@gmail.com\n*/\npublic class TaskD {\n private static final int MOD = 1000000007;\n public static void main(String[] args) {\n new TaskD().solve(1, new InputReader(System.in), new PrintWriter(System.out));\n }\n\n int n;\n char[] text;\n int[][] dp;\n public void solve(int testNumber, InputReader reader, PrintWriter out) {\n\n //InputReader reader = new InputReader(in);\n n = reader.nextInt();\n text = reader.nextString().toCharArray();\n dp = new int[n + 2][1 << 20];\n ArrayUtils.fill(dp, -1);\n int ret = 0;\n for (int i = 0; i < n; i++) {\n ret += rec(0, i);\n if (ret > MOD) {\n ret -= MOD;\n }\n }\n System.out.println(ret);\n\n }\n private int rec(int mask, int index) {\n int bitCount = Integer.bitCount(mask);\n if (index >= n) {\n if (bitCount > 0 && ((1 << bitCount) - 1 == mask)) {\n return 1;\n }\n return 0;\n }\n if (dp[index][mask] != -1) {\n return dp[index][mask];\n }\n int ret = 0;\n int num = 0;\n int c = text[index] - '0';\n if(c == 0) {\n ret += rec(mask, index + 1);\n if (ret > MOD) {\n ret -= MOD;\n }\n } else {\n for (int i = index; i < n; i++) {\n c = text[i] - '0';\n num = num * 2 + c;\n if (num > 20) {\n break;\n }\n ret += rec(mask | (1 << (num - 1)), i + 1);\n if (ret > MOD) {\n ret -= MOD;\n }\n }\n if (bitCount > 0 && ((1 << bitCount) - 1 == mask)) {\n ret += 1;\n }\n }\n ret = ret % MOD;\n dp[index][mask] = ret;\n return ret;\n }\n\n\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String nextString() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n }\n\n\n static class ArrayUtils {\n public static void fill(int[][] f, int value) {\n for (int i = 0; i < f.length; ++i) {\n Arrays.fill(f[i], value);\n }\n }\n\n }\n\n}\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d62cc86117b8480f814528fcf9b0b91f", "src_uid": "61f88159762cbc7c51c36e7b56ecde48", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\nimport org.apache.commons.lang3.tuple.Pair;\n\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tSystem.out.println(\"Enter the number of teams\");\n\t\tint n = sc.nextInt();\n\t\tSystem.out.println(\"Enter the matches to be played\");\n\t\tArrayList> matches = new ArrayList>();\n\t\tfor (int i = 0; i < n * (n - 1); i++) {\n\t\t\tmatches.add(Pair.of(sc.nextInt(), sc.nextInt()));\n\t\t}\n\t\tint result = 0;\n\t\tfor (int i = 0; i < n * (n - 1); i++) {\n\t\t\tPair pair = matches.get(i);\n\t\t\tfor (int j = 0; i < n * (n - 1); i++) {\n\t\t\t\tif (j == i) continue;\n\t\t\t\telse {\n\t\t\t\t\tif (pair.getRight() == matches.get(i).getLeft()) result++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(result);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65b17f247ed3079994ab6eb2da2bf122", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0} {"lang": "Java 11", "source_code": "public class Problem15 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int num = in.nextInt();\n int team1[] = new int[num];\n int team2[] = new int[num];\n for (int x = 0; x < num; x++) {\n team1[x] = in.nextInt();\n team2[x] = in.nextInt();\n }\n int res = 0;\n for (int x = 0; x < team1.length; x++) {\n for (int y = 0; y < team2.length; y++) {\n if (team1[x] == team2[y]) {\n res++;\n }\n\n }\n\n }\n System.out.println(res);\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "80b6b2e2d34a2558e31a352d8e879e2c", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Arrays.sort;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class A_268\n{\n private static BufferedInput in = new BufferedInput(System.in);\n private static PrintStream out = System.out;\n\n public static void solve()\n {\n int n = in.nextInt();\n int[] tab1 = new int[n];\n int[] tab2 = new int[n];\n for (int i = 0; i < n; i++)\n {\n tab1[i] = in.nextInt();\n tab2[i] = in.nextInt();\n }\n sort(tab1);\n sort(tab2);\n\n int c = -1;\n int res = 0;\n\n for (int i = 0; i < tab1.length; i++)\n {\n if (tab1[i] != c) {\n c = tab1[i];\n res += count(tab1, c) * count(tab2, c);\n }\n }\n System.out.println(res);\n\n }\n\n public static void main(String[] args)\n {\n solve();\n }\n public static void reverse(int[] array) {\n int l = array.length - 1;\n int m = array.length / 2;\n\n for (int i = 0; i < m; i++)\n {\n int t = array[i];\n array[i] = array[l - i];\n array[l - i] = t;\n }\n }\n\n public static void reverse(char[] array) {\n int l = array.length - 1;\n int m = array.length / 2;\n\n for (int i = 0; i < m; i++)\n {\n char t = array[i];\n array[i] = array[l - i];\n array[l - i] = t;\n }\n }\n\n public static int sum(int[] array) {\n int sum = 0;\n for (int i = 0; i < array.length; i++)\n {\n sum += array[i];\n }\n return sum;\n }\n\n public static int maxFirstIndex(int[] array) {\n int best = array[0];\n int idx = 0;\n for (int i = 1; i < array.length; i++)\n {\n if (best < array[i])\n {\n best = array[i];\n idx = i;\n }\n }\n return idx;\n }\n\n public static int minLastIndex(int[] array) {\n int best = array[0];\n int idx = 0;\n for (int i = 1; i < array.length; i++)\n {\n if (best >= array[i])\n {\n best = array[i];\n idx = i;\n }\n }\n return idx;\n }\n\n public static Set set(char[] array) {\n Set set = new HashSet<>();\n for (int i = 0; i < array.length; i++)\n {\n set.add(array[i]);\n }\n return set;\n }\n\n public static Set set(int[] array) {\n Set set = new HashSet<>();\n for (int i = 0; i < array.length; i++)\n {\n set.add(array[i]);\n }\n return set;\n }\n\n public static void swap(char[] array, int i1, int i2) {\n char c = array[i1];\n array[i1] = array[i2];\n array[i2] = c;\n }\n\n public static int count(int[] array, int value) {\n int r = 0;\n for (int i = 0; i < array.length; i++)\n {\n if (array[i] == value) r++;\n }\n return r;\n }\n}\n\nclass BufferedInput {\n\n private final BufferedReader bufferedReader;\n\n public BufferedInput(InputStream inputStream) {\n this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n private StringTokenizer stringTokenizer = new StringTokenizer(\"\", \"\");\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n public int[] readIntArray(int length) {\n int[] array = new int[length];\n for (int i = 0; i < array.length; i++)\n {\n array[i] = nextInt();\n }\n return array;\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String next() {\n if (stringTokenizer.hasMoreTokens()) {\n return stringTokenizer.nextToken();\n } else {\n try {\n String line = bufferedReader.readLine();\n stringTokenizer = new StringTokenizer(line, \" \");\n return stringTokenizer.nextToken();\n\n } catch (IOException | NullPointerException exception) {\n throw new RuntimeException(\"End of input\");\n }\n }\n }\n\n}\n\n\n\nclass ArrayUtils {\n public static void reverse(int[] array)\n {\n int l = array.length - 1;\n int m = array.length / 2;\n\n for (int i = 0; i < m; i++)\n {\n int t = array[i];\n array[i] = array[l - i];\n array[l - i] = t;\n }\n }\n\n public static void reverse(char[] array)\n {\n int l = array.length - 1;\n int m = array.length / 2;\n\n for (int i = 0; i < m; i++)\n {\n char t = array[i];\n array[i] = array[l - i];\n array[l - i] = t;\n }\n }\n\n public static int sum(int[] array)\n {\n int sum = 0;\n for (int i = 0; i < array.length; i++)\n {\n sum += array[i];\n }\n return sum;\n }\n\n public static int maxFirstIndex(int[] array)\n {\n int best = array[0];\n int idx = 0;\n for (int i = 1; i < array.length; i++)\n {\n if (best < array[i])\n {\n best = array[i];\n idx = i;\n }\n }\n return idx;\n }\n public static int minLastIndex(int[] array)\n {\n int best = array[0];\n int idx = 0;\n for (int i = 1; i < array.length; i++)\n {\n if (best >= array[i])\n {\n best = array[i];\n idx = i;\n }\n }\n return idx;\n }\n\n public static Set set(char[] array)\n {\n Set set = new HashSet<>();\n for (int i = 0; i < array.length; i++)\n {\n set.add(array[i]);\n }\n return set;\n }\n\n public static Set set(int[] array)\n {\n Set set = new HashSet<>();\n for (int i = 0; i < array.length; i++)\n {\n set.add(array[i]);\n }\n return set;\n }\n\n public static void swap(char[] array, int i1, int i2) {\n char c = array[i1];\n array[i1] = array[i2];\n array[i2] = c;\n }\n\n public static int count(int[] array, int value) {\n int r = 0;\n for (int i = 0; i < array.length; i++)\n {\n if (array[i] == value) r++;\n }\n return r;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ea6e1c59d5055f9d819b28fd821498b", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\nimport org.javatuples.Pair;\n\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tSystem.out.println(\"Enter the number of teams\");\n\t\tint n = sc.nextInt();\n\t\tSystem.out.println(\"Enter the matches to be played\");\n\t\tArrayList> matches = new ArrayList>();\n\t\tfor (int i = 0; i < n * (n - 1); i++) {\n\t\t\tmatches.add(Pair.with(sc.nextInt(), sc.nextInt()));\n\t\t}\n\t\tint result = 0;\n\t\tfor (int i = 0; i < n * (n - 1); i++) {\n\t\t\tPair pair = matches.get(i);\n\t\t\tfor (int j = 0; i < n * (n - 1); i++) {\n\t\t\t\tif (j == i) continue;\n\t\t\t\telse {\n\t\t\t\t\tif (pair.getValue1() == matches.get(i).getValue0()) result++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(result);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fcbef759503eaf6d51432e5aa1d34b37", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Template {\n\n public static void main(String[] args) {\n MyScanner scn = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n int n = scn.nextInt();\n int x = scn.nextInt();\n int y = scn.nextint();\n \n String ans = Math.max(x-1,y-1)>Math.max(n-x,n-y)?\"Black\":\"White\";\n out.print(ans);\n \n \n\n \n\n out.close();\n }\n\n public static PrintWriter out;\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "00a99ab10c4130330d1f81de3df2113b", "src_uid": "b8ece086b35a36ca873e2edecc674557", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.util.StringTokenizer;\n\npublic class Main {\n private BufferedReader reader;\n\n @SuppressWarnings(\"FieldCanBeLocal\")\n private PrintWriter writer;\n\n private StringTokenizer tokenizer;\n\n public static void main(String[] arguments) throws IOException {\n new Main().run();\n }\n\n private void run() throws IOException {\n reader = new BufferedReader(new InputStreamReader(System.in));\n writer = new PrintWriter(new OutputStreamWriter(System.out));\n\n BigDecimal n = readBigDecimal();\n BigDecimal x = readBigDecimal();\n BigDecimal y = readBigDecimal();\n\n BigDecimal whiteX = BigDecimal.ONE;\n BigDecimal whiteY = BigDecimal.ONE;\n\n BigDecimal blackX = new BigDecimal(n.toString());\n BigDecimal blackY = new BigDecimal(n.toString());\n\n BigDecimal whiteLength = whiteX.abs().subtract(x.abs()).pow(2).add(whiteY.abs().subtract(y.abs()).pow(2)).sqrt(MathContext.DECIMAL64);\n BigDecimal blackLength = blackX.abs().subtract(x.abs()).pow(2).add(blackY.abs().subtract(y.abs()).pow(2)).sqrt(MathContext.DECIMAL64);\n\n writer.println(whiteLength.compareTo(blackLength) <= 0 ? \"White\" : \"Black\");\n\n reader.close();\n writer.close();\n }\n\n private BigDecimal readBigDecimal() throws IOException {\n return new BigDecimal(readToken());\n }\n\n private String readToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n\n return tokenizer.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a17a94067abbf91d5c408e9bca3dad3d", "src_uid": "b8ece086b35a36ca873e2edecc674557", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t Scanner in = new Scanner(System.in);\n\t\t int n = in.nextInt();\n\t\t int y = in.nextInt();\n\t\t int x = in.nextInt();\n\t\t int white;\n\t\t int black; \n\t\t if(x-y <= 0 ) {\n\t\t\t white =y-1;\n\t\t\t black = n-x; \n\t\t }\n\t\t else {\n\t\t\t white = x-1; \n\t\t\t black = n-y; \n\t\t }\n\t\t if(white<=black) System.out.println(\"White\");\n\t\t else System.out.println(\"Black\");\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b82d1095abe342310fcd347856c17377", "src_uid": "b8ece086b35a36ca873e2edecc674557", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class TheKingsRace {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n\n StringTokenizer st = new StringTokenizer(br.readLine());\n\n BigInteger n = new BigInteger(st.nextToken());\n\n st = new StringTokenizer(br.readLine());\n BigInteger x = new BigInteger(st.nextToken());\n BigInteger y = new BigInteger(st.nextToken());\n\n br.close();\n\n BigInteger white = x.subtract(BigInteger.valueOf(1)).add((y.subtract(BigInteger.valueOf(1))).subtract(x.subtract(BigInteger.valueOf(1))).max(BigInteger.valueOf(0)));\n BigInteger black = n.subtract(x).add((n.subtract(y)).subtract((n.subtract(x))).max(BigInteger.valueOf(0)));\n\n if(black.compareTo(white) == -) {\n pw.println(\"Black\");\n }\n else {\n pw.println(\"White\");\n }\n\n\n pw.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8f2cf1ad23301e09e6a76cb858aec265", "src_uid": "b8ece086b35a36ca873e2edecc674557", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\nimport java.lang.*;\npublic class Main {\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 \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] = Integer.parseInt(next());\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t}\n\t\n\tprivate static long startTime = System.currentTimeMillis();\n\tpublic static void main(String[] args) {\n\t\tFastReader sc =new FastReader();\n\t\tBigInteger bb=new BigInteger(sc.next());\n\t\tbb=bb.add(BigInteger.ONE);\n\t\t//System.out.println(bb.toString());\n\t\tif(bb.mod(BigInteger.TWO)==BigInteger.ZERO)\n\t\t{\n\t\t\tSystem.out.println(bb.divide(BigInteger.TWO));\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(bb.subtract(BigInteger.ONE));\n\t\t}\n\n \n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b1bc5930c9957a652bb3e31c2b46fceb", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/******************************************************************************\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nSwift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n*******************************************************************************/\nimport java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint i=1;\n\t\tlong n=sc.nextDouble()+1;\n\t\twhile(i<=999)\n\t\t{\n\t\t if(n==Math.pow(2,i))\n\t\t {\n\t\t System.out.println(n/2);\n\t\t break;\n\t\t }\n\t\t i=i+1;\n\t\t \n\t\t}\n\t\tif(i==1000)\n\tSystem.out.println(n);\n\t\t\n\t\t\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f4121f350612d49df614b97684eca5da", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\n\n\nimport java.util.*;\npublic class test\n{\n public static void main(String args[])\n {\n\t Scanner s=new Scanner(System.in);\n\t long n=s.nextLong();\n\t // int n= Integer.parseInt(str);\n\t long x=n+1;\n\t if(x==1)\n\t\t Ssytem.out.print(0);\n\t else if(x%2==0)\n\t\t System.out.print(x/2);\n\t else\n\t\t System.out.print(x);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d611669f71182df946ede1fc546ed6aa", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0} {"lang": "Java 8", "source_code": " \n public class DPizza {\n\n\t/**\n\t * @JUNP_YY\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner s = new Scanner(System.in);\n double num = s.nextDouble();\n\t\tSystem.out.println(((++num)%2==0)?num/2:num);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65d8bc5e7cb0e517b58d5fedef559b50", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\n public final class Ideo\n{\n\tstatic class pair\n\t{\n\t\tint first,second;\n\t\tpair(){}\n\t\tpair(int i,int j)\n\t\t{\n\t\t\tfirst=i;\n\t\t\tsecond=j;\n\t\t}\n\t}\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint m=sc.nextInt();\n\t\tint arr[]=new int[n];\n\t\n\t\n\t\tfor(int i=0;i q=new LinkedList();\n\t\t\tfor(int i=0;i0)\n\t\t\t{\n\t\t\t\tx=q.peek();\n\t\t\t\tif(x.second+m >= arr[x.first-1])\n\t\t\t\tq.remove();\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tq.remove();\n\t\t\t\t\tq.add(new pair(x.first,x.second+m));\n\t\t\t\t}\n\t\t\t}\n\t\tSystem.out.println(x.first);\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dc3975d115755eec7f0668624d119dbd", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class susbus{\n public static void main(String[] args0){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int [] child = new int[n];\n for (int i=0;imax){\n max=child[i]\n pos=i;\n }\n }\n System.out.println(pos+1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e10a27224f1d251b31aaa37fbd7db7f7", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class mohammad{\n public static void main(String args[]){\n Scanner U = new Scanner(System.in);\n int n=U.nextInt();\n int m=U.nextInt();\n int[] a = new int [n];\n int max=0;\n for(int i=0;i queue = new LinkedList();\n\t\tfor(int i=0;i result = new ArrayList<>(input.length());\n\t\tfor (int i = 0; i < input.length(); i++) {\n\t\t\tif (i % 2 == 0) {\n\t\t\t\tresult.add(input.charAt(i), 0);\n\t\t\t} else {\n\t\t\t\tresult.add(input.charAt(i), input.length());\n\t\t\t}\n\t\t}\n\t\tStringBuilder builder = new StringBuilder();\n\t\tfor (Character c : result) {\n\t\t\tbuilder.append(c);\n\t\t}\n\t\tSystem.out.println(builder.toString());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a2c778266f7e5d2e36edef39ffd7fa4d", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args) {\n Scanner cin = new Scanner(System.in);\n String s;\n s = cin.next();\n if(s.length()==1){\n System.out.print(s.charAt(0));\n return;\n }\n \n if(s.length() % 2 == 0){\n System.out.print(s.charAt(s.length()/2-1));\n for(int i=1;i<=s.length()/2-1;i++)\n {\n System.out.print(s.charAt(s.length()/2-1 + i));\n System.out.print(s.charAt(s.length()/2-1 - i));\n }\n System.out.print(s.charAt(s.length()-1));\n }\n else{\n System.out.print(s.charAt(s.length()/2));\n for(int i=1;i<=s.length()/2;i++){\n System.out.print(s.charAt(s.length()/2 + i));\n System.out.print(s.charAt(s.length()/2 - i));\n }\n \n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da3e23845637e2483f9a3d55c30bd3d2", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport com.google.gson.Gson;\n\nimport java.io.*;\nimport java.net.URL;\nimport java.net.URLConnection;\nimport java.nio.charset.Charset;\nimport java.time.LocalDate;\nimport java.time.format.DateTimeFormatter;\nimport java.util.*;\n\n\npublic class Main {\n private final static long mod = 1000000007;\n\n private static void printArr(char arr[][]) {\n int i, j, n = arr.length, m = arr[0].length;\n for (i = 0; i < n; i++) {\n for (j = 0; j < m; j++) {\n System.out.print(arr[i][j]);\n }\n System.out.println();\n }\n }\n\n\n private static long power(long x, long y, long m) {\n long temp;\n if (y == 0)\n return 1;\n temp = power(x, y / 2, m);\n temp = (temp * temp) % m;\n if (y % 2 == 0)\n return temp;\n else\n return ((x % m) * temp) % m;\n }\n\n private static long power(long x, long y) {\n return power(x, y, mod);\n }\n\n private static int gcd(int a, int b) {\n if (b == 0) return a;\n return gcd(b, a % b);\n }\n\n private static int cmp(Pair p, Pair q) {\n return (int) (p.a == q.a ? p.b - q.b : q.a - p.a);\n }\n\n\n\n private static long modInverse(long a, long m) {\n long m0 = m;\n long y = 0, x = 1;\n if (m == 1)\n return 0;\n while (a > 1) {\n long q = a / m;\n long t = m;\n m = a % m;\n a = t;\n t = y;\n y = x - q * y;\n x = t;\n }\n if (x < 0)\n x += m0;\n return x;\n }\n\n Map dp=new HashMap<>();\n\n private int mxGcd(List a){\n int i,j,n=a.size(),k;\n if(a.size()==2){\n return a.get(0)+a.get(1);\n }\n else if(a.size()==0){\n return 0;\n }\n String key=Arrays.toString(a.toArray(new Integer[n]));\n if(dp.get(key)!=null){\n return dp.get(key);\n }\n int mxG=0,g;\n for(i=0;i b=new ArrayList<>();\n for(k=0;k a=new ArrayList<>();\n for(int e:A){\n a.add(e);\n }\n Collections.sort(a);\n return mxGcd(a);\n }\n\n static class Point {\n int x, y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public String toString() {\n return String.format(\"(%d,%d)\", x, y);\n }\n }\n\n\n\n public static void main(String[] args) throws IOException {\n\n\n FastReader in = new FastReader();\n FastWriter out = new FastWriter();\n int t, i, j, n, k, m, l, r, x, y, z, q, ti, tidx;\n //for (t = in.nextInt(), tidx = 1; tidx <= t; tidx++)\n {\n //out.print(String.format(\"Case #%d: \", tidx));\n String s=in.next();\n l=(s.length()-1)/2;\n r=l+1;\n for(i=0;i list = new ArrayList<>();\n Set set = new HashSet<>();\n\n FastWriter() {\n bw = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n void print(T obj) throws IOException {\n bw.write(obj.toString());\n bw.flush();\n }\n\n void println() throws IOException {\n print(\"\\n\");\n }\n\n void println(T obj) throws IOException {\n print(obj.toString() + \"\\n\");\n }\n\n void printArrLn(T[] arr) throws IOException {\n for (int i = 0; i < arr.length - 1; i++) {\n print(arr[i] + \" \");\n }\n println(arr[arr.length - 1]);\n }\n\n void printArr2(T[][] arr) throws IOException {\n for (int j = 0; j < arr.length; j++) {\n for (int i = 0; i < arr[j].length - 1; i++) {\n print(arr[j][i] + \" \");\n }\n println(arr[j][arr.length - 1]);\n }\n }\n\n void printColl(Collection coll) throws IOException {\n for (T e : coll) {\n print(e + \" \");\n }\n println();\n }\n\n void printCharN(char c, int n) throws IOException {\n for (int i = 0; i < n; i++) {\n print(c);\n }\n }\n\n @Override\n public void close() throws IOException {\n bw.close();\n }\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05f095c1ed7d0e765196f70867ada9d7", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args) {\n Scanner cin = new Scanner(System.in);\n String s;\n s = cin.next();\n if(s.length()==1){\n System.out.print(s.charAt(0));\n return;\n }\n \n if(s.length() % 2 == 0){\n System.out.print(s.charAt(s.length()/2-1));\n for(int i=1;i<=s.length()/2-1;i++)\n {\n System.out.print(s.charAt(s.length()/2-1 + i));\n System.out.print(s.charAt(s.length()/2-1 - i));\n }\n System.out.print(s.charAt(s.length()-1));\n }\n else{\n System.out.print(s.charAt(s.length()));\n for(int i=1;i= '0' && c <= '9') { \n\t isDigit = true;\n\t ret = ret * 10 + c - '0';\n\t } else if (isDigit) {\n\t \tbreak;\n\t }\n\t }\n\n\t return ret;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n; int t; int total = 0;\n\t\ttry(BufferedInputStream bis = new BufferedInputStream(System.in)) {\n\t\t\tn = readInt(bis);\n\t\t\tt = readInt(bis);\n\t\t}\n\t\tif (t == 0) {\n\t\t\tSystem.out.println(n); System.exit(0);\n\t\t}\n\t\tint total = 0;\n\t\tint power = (int) Math.log10(t);\n\t\tfor (int i = 0; i < power + 1; i++) {\n\t\t\ttotal += (t % 10) * (int) (Math.pow(10, power - i)); t /= 10;\n\t\t}\n\t\tSystem.out.println(total + n);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ac51af037fc5802ade865e1c5bbd74b8", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "public class AprilFools2020 {\n\tpublic static void main (String [] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\t\n\t\tint k = scan.nextInt();\n\t\t\n\t\tint length = Integer.toString(k).length();\n\t\tint add = 0;\n\t\tint mod = k;\n\t\tfor(int i = 0; i < length; i++) {\n\t\t\tint x = mod % 10;\n\t\t\tadd = add*10 + x;\n\t\t\tmod /= 10;\n\t\t} \n\t\tint finals = n +add;\n\t\t\n\t\tSystem.out.println(finals);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d352ca3fc1ca460abfa77e0c40f9d4ad", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class Main\n{\n public static void main(){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n // int max = 1 << 25;\n if( n > 25 )\n {\n System.out.println(m);\n } else {\n System.out.println(m % (1<0)\n\t\t{\n\t\t\tif((b&1)==1)\n\t\t\tres=res.multiply(a);\n\t\t\ta=a.multiply(a);\n\t\t\tb>>=1;\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\tpublic static void main(String[] args) \n\t{ \n\t\tFastReader sc=new FastReader(); \n\t\tint n=sc.nextInt();\n\t\tint m1=sc.nextInt();\n\t\tint x=Math.log(m1)/Math.log(2);\n\t\tif(x < n)\n\t\t\tSystem.out.println(m1);\n\t\telse if(n==x)\n\t\t System.out.println(\"0\");\n\t\telse{\n \t\tBigInteger ex=expo(2,n);\n \t\tBigInteger m=new BigInteger(\"\"+m1);\n \t\tint b=m.compareTo(ex);\n \t\tif(b==-1)\n \tSystem.out.println(m);\n \t\telse if(b==0)\n \t\tSystem.out.println(\"0\");\n \t\telse\n \t\tSystem.out.println(m.mod(ex));\n\t\t}\n\t\t\n\t\n\n\t} \n} \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a06f62163551b7c4f0f127fa11bba916", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\npublic class Main {\n\n public static long quick_step(long n) {\n long answ = 1;\n if (n == 1)\n return 2;\n if (n % 2 == 0) {\n return ((((quick_step(n / 2))%100000000) * (quick_step(n / 2)%100000000))%100000000);\n } else\n return (((((quick_step(n / 2))%100000000) * (quick_step(n / 2)%100000000))%100000000) * 2)%100000000;\n }\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n long n = s.nextInt();\n long m = s.nextInt();\n\n System.out.println(m%quick_step(n));\n\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "be14992fa2796180fdd2c538ad5bb41e", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class chapter {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int count = 0;\n int element = 0;\n boolean matched = false;\n int[][] matrix = new int[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n matrix[i][j] = sc.nextInt();\n count+=matrix[i][j];\n }\n }\n int sum = count;\n boolean flag = true;\n int subCount = 0;\n for (int i = 0; i < matrix.length; i++) {\n if(matrix[i][i]!=matrix[n/2+1][n/2+1]){\n flag = false;\n break;\n }\n }\n if(flag){\n count-=(n-1)*matrix[n/2+1][n/2+1];\n matched = true;\n }\n flag=true;\n subCount = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if(i==n-j-1){\n if(matrix[n/2+1][n/2+1]==matrix[i][n-j-1]){\n subCount++;\n }\n }\n }\n }\n count-=subCount==n?matrix[n/2+1][n/2+1]*n-1:0;\n subCount = 0;\n flag = true;\n for (int i = 0; i < n; i++) {\n if(matrix[n/2+1][n/2+1]!=matrix[i][n/2+1]){\n flag = false;\n break;\n }\n }\n if(flag){\n count-=(n-1)*matrix[n/2+1][n/2+1];\n matched = true;\n }\n flag = true;\n for (int i = 0; i < n; i++) {\n if( matrix[n/2+1][i]!=matrix[n/2][n/2]){\n flag=false;\n break;\n }\n }\n if(flag){\n count-=(n-1)*matrix[n/2+1][n/2+1];\n matched = true;\n }\n\n if(matched){\n count-=matrix[n/2+1][n/2+1];\n }\n if(count!=sum){\n System.out.println(sum-count);\n }else {\n System.out.println(sum);\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50dda4e423248c50ed6c12ec93f2bd6d", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\npublic class JavaApplication18 {\n public static void main(String[] args) {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int c=0,m;\n m=(n-1)/2;\n int arr[][]=new int[n][n];\n for(int i=0;i= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n }\n} \t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "148bd53daac9cad68312de5dbe4b6711", "src_uid": "b031daf3b980e03218167f40f39e7b01", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static int[] simpleArraySum(int n, int a, int b) {\n int[] res = new int[2];\n int count = n/a;\n for (int i = 0; i <= count; i++) {\n if ((n - i*a)%b == 0) {\n res[0] = i;\n res[1] = (n-i*a)/b;\n return res;\n }\n }\n }\n \n static boolean yesNo(int n, int a, int b) {\n int[] res = new int[2];\n int count = n/a;\n for (int i = 0; i <= count; i++) {\n if ((n - i*a)%b == 0) {\n return true;\n }\n }\n return false;\n }\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[] result = simpleArraySum(n, a, b);\n boolean res = yesNo(n, a, b);\n System.out.println(res);\n if (res == true)\n System.out.println(\"\"+result[0] + \" \" + result[1]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e12f9368ee0eec16666ce75b5482b09c", "src_uid": "b031daf3b980e03218167f40f39e7b01", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static int[] simpleArraySum(int n, int a, int b) {\n int[] res = new int[2];\n int count = n/a;\n for (int i = 0; i <= count; i++) {\n if ((n - i*a)%b == 0) {\n res[0] = i;\n res[1] = (n-i*a)/b;\n return res;\n }\n }\n }\n \n static boolean yesNo(int n, int a, int b) {\n int[] res = new int[2];\n int count = n/a;\n for (int i = 0; i <= count; i++) {\n if ((n - i*a)%b == 0) {\n return true;\n }\n }\n return false;\n }\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[] result = simpleArraySum(n, a, b);\n boolean res = yesNo(n, a, b);\n System.out.println(res);\n if (res == true)\n System.out.println(result[0], result[1]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a87ee59fa6cc37b34a19b47912b101ee", "src_uid": "b031daf3b980e03218167f40f39e7b01", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\n\npublic class A{\n\tpublic static void main(String[] args) throws IOException,NumberFormatException{\n\t\ttry {\n\t\t\tFastScanner sc=new FastScanner();\n\t\t\tint n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();\n\t\t\tboolean ans=false;\n\t\t\tfor(int i=1;i<=(int)1e7;i++) {\n\t\t\t\tif((n-a*i)>0&&((n-a*i)%b==0)) {\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\tSystem.out.println(i+\" \"+(n-(a*i))/b);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(\"NO\");\n\t\t\n\t\t}\n\t\tcatch(Exception e) {\n\t\t\treturn ;\n\t\t}\n\t\t\n\t}\n\tstatic final Random random=new Random();\n\t\n\tstatic void ruffleSort(int[] a) {\n\t\tint n=a.length;\n\t\tfor(int i=0;i 0)\n System.out.print(word + \" \");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "898f047820ff6c67189b46ef7cd3c196", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.util.*\n\npublic class Test{\npublic static void main(String []args){\n Scanner sc=new Scanner(System.in);\n String word=sc.nextLine();\n StringTokenizer st=new StringTokenizer(word);\n while(st.hasMoreTokens()){\n System.out.println(st.nextToken(\"WUB\"));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "996ffb3c2a1f2bd273f7fb480837fe78", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.Scanner;\n\npublic class Solution{\n\n public static void main(String[] args){\n String input;\n Scanner scanner;\n scanner = new Scanner(System.in);\n input = scanner.next();\n\t\tPattern pattern = Pattern.compile(\"WUB\");\n\t\tString[] output = pattern.split(input);\t\n\t\tString out = output[0];\n\t\tfor(int i=1;i=b)\n {\n max=a; max_char='a';\n min=b, min_char='b';\n }\n else\n {\n max=b; max_char='b';\n min=a; min_char='a';\n }\n String s=\"\";\n while(min!=0)\n {\n s=s+max_char;\n s=s+min_char;\n min--;\n max--;\n }\n while(c!=0)\n {\n s=s+max_char;\n s=s+min_char;\n c--;\n }\n if(max>0)\n s=s+max_char;\n System.out.println(s.length())\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05d3ab50447d8e522e0a1fd651909d5f", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Hello{\n public static void main(String[] args) throws exception{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] strng=br.readLine().split(\" \");\n \n int a=Integer.parseInt(strng[0]);\n int b=Integer.parseInt(strng[1]);\n int c=Integer.parseInt(strng[2]);\n long s=0;\n if(a!=b){\n s=(long)2*Math.min(a,b)+1+2*c;\n }else{\n s=(long)2*(a+c);\n }\n System.out.println(s);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "526947827c936ab8d4fe66f8697491bb", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\npublic class Metro {\n\n public static void main(String args[]){\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt(); int diff =0;\n int sum = 0;\n sum += c*2;\n int min = Math.min(a,b);\n sum +=min*2+1;\n System.out.println(sum);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0d3fc4348d1907eac0ee6f8ef1e146aa", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int a= sc.nextInt();\n int b= sc.nextInt();\n int c= sc.nextInt();\n if(a= 0; pos--)\n\t\t\t\tif (dp[st][pos] != Long.MAX_VALUE)\n\t\t\t\t\tfor (int next = 0; next <= n; next++)\n\t\t\t\t\t\tif (next == 0) {\n\t\t\t\t\t\t\tif (pos != 0) {\n\t\t\t\t\t\t\t\tlong val = dp[st][pos] + dist(pos, next);\n\t\t\t\t\t\t\t\tif (dp[st][0] > val) {\n\t\t\t\t\t\t\t\t\tdp[st][0] = val;\n\t\t\t\t\t\t\t\t\tdpFrom[st][0][0] = st;\n\t\t\t\t\t\t\t\t\tdpFrom[st][0][1] = pos;\n\t\t\t\t\t\t\t\t\tdpFrom[st][0][2] = -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} else {\n\t\t\t\t\t\t\tif (((1 << (next - 1)) & st) != (1 << (next - 1))) {\n\t\t\t\t\t\t\t\tlong val = dp[st][pos] + dist(pos, next);\n\t\t\t\t\t\t\t\tif (pos != 0) {\n\t\t\t\t\t\t\t\t\tval += dist(0, next);\n\t\t\t\t\t\t\t\t\tif (dp[st | (1 << (next - 1))][0] > val) {\n\t\t\t\t\t\t\t\t\t\tdp[st | (1 << (next - 1))][0] = val;\n\t\t\t\t\t\t\t\t\t\tdpFrom[st | (1 << (next - 1))][0][0] = st;\n\t\t\t\t\t\t\t\t\t\tdpFrom[st | (1 << (next - 1))][0][1] = pos;\n\t\t\t\t\t\t\t\t\t\tdpFrom[st | (1 << (next - 1))][0][2] = next;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tif (dp[st | (1 << (next - 1))][next] > val) {\n\t\t\t\t\t\t\t\t\t\tdp[st | (1 << (next - 1))][next] = val;\n\t\t\t\t\t\t\t\t\t\tdpFrom[st | (1 << (next - 1))][next][0] = st;\n\t\t\t\t\t\t\t\t\t\tdpFrom[st | (1 << (next - 1))][next][1] = pos;\n\t\t\t\t\t\t\t\t\t\tdpFrom[st | (1 << (next - 1))][next][2] = -1;\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\tout.println(dp[(1 << n) - 1][0]);\n\t\tint nowSt = (1 << n) - 1;\n\t\tint nowPos = 0;\n\t\tArrayList ans = new ArrayList();\n\t\twhile (nowSt != 0 || nowPos != 0) {\n\t\t\tans.add(nowPos);\n\t\t\tint newSt = dpFrom[nowSt][nowPos][0];\n\t\t\tint newPos = dpFrom[nowSt][nowPos][1];\n\t\t\tif (dpFrom[nowSt][nowPos][2] != -1)\n\t\t\t\tans.add(dpFrom[nowSt][nowPos][2]);\n\t\t\tnowPos = newPos;\n\t\t\tnowSt = newSt;\n\t\t}\n\t\tout.print(\"0 \");\n\t\tfor (int i = ans.size() - 1; i >= 0; i--)\n\t\t\tout.print(ans.get(i) + \" \");\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF8A().runIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3645e942c132154de06389708afade1b", "src_uid": "2ecbac20dc5f4060bc873553946281bc", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF8C {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint[] x, y;\n\n\tint dist(int v, int u) {\n\t\treturn (x[v] - x[u]) * (x[v] - x[u]) + (y[v] - y[u]) * (y[v] - y[u]);\n\t}\n\n\tvoid solve() {\n\t\tint x1 = in.nextInt();\n\t\tint y1 = in.nextInt();\n\t\tint n = in.nextInt();\n\n\t\tx = new int[n + 1];\n\t\ty = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tx[i] = in.nextInt();\n\t\t\ty[i] = in.nextInt();\n\t\t}\n\t\tx[0] = x1;\n\t\ty[0] = y1;\n\t\tint[] dp = new int[(1 << n)];\n\t\tbyte[][] dpFrom = new byte[1 << n][2];\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\tfor (int st = 0; st < (1 << n); st++) {\n\t\t\tif (dp[st] == Integer.MAX_VALUE)\n\t\t\t\tcontinue;\n\t\t\tArrayList available = new ArrayList();\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif ((st & (1 << i)) == 0)\n\t\t\t\t\tavailable.add(i);\n\t\t\tif (available.size() == 0)\n\t\t\t\tcontinue;\n\t\t\tif (available.size() == 1) {\n\t\t\t\tint val = dp[st] + dist(available.get(0) + 1, 0) * 2;\n\t\t\t\tif (dp[(1 << n) - 1] > val) {\n\t\t\t\t\tdp[(1 << n) - 1] = val;\n\t\t\t\t\tdpFrom[(1 << n) - 1][0] = available.get(0);\n\t\t\t\t\tdpFrom[(1 << n) - 1][1] = -1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int i = 0; i < available.size(); i++)\n\t\t\t\tfor (int j = i + 1; j < available.size(); j++) {\n\t\t\t\t\tint val = dp[st] + dist(available.get(i) + 1, 0)\n\t\t\t\t\t\t\t+ dist(available.get(j) + 1, 0)\n\t\t\t\t\t\t\t+ dist(available.get(i) + 1, available.get(j) + 1);\n\t\t\t\t\tif (dp[st | (1 << available.get(i))\n\t\t\t\t\t\t\t| (1 << available.get(j))] > val) {\n\t\t\t\t\t\tdp[st | (1 << available.get(i))\n\t\t\t\t\t\t\t\t| (1 << available.get(j))] = val;\n\t\t\t\t\t\tdpFrom[st | (1 << available.get(i))\n\t\t\t\t\t\t\t\t| (1 << available.get(j))][0] = available\n\t\t\t\t\t\t\t\t.get(i);\n\t\t\t\t\t\tdpFrom[st | (1 << available.get(i))\n\t\t\t\t\t\t\t\t| (1 << available.get(j))][1] = available\n\t\t\t\t\t\t\t\t.get(j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tfor (int i = 0; i < available.size(); i++) {\n\t\t\t\tint val = dp[st] + dist(available.get(i) + 1, 0) * 2;\n\t\t\t\tif (dp[st | (1 << available.get(i))] > val) {\n\t\t\t\t\tdp[st | (1 << available.get(i))] = val;\n\t\t\t\t\tdpFrom[st | (1 << available.get(i))][0] = available.get(i);\n\t\t\t\t\tdpFrom[st | (1 << available.get(i))][1] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(dp[(1 << n) - 1]);\n\t\tint nowSt = (1 << n) - 1;\n\t\tArrayList ans = new ArrayList();\n\t\tans.add(0);\n\t\twhile (nowSt != 0) {\n\t\t\tint n1 = dpFrom[nowSt][0];\n\t\t\tint n2 = dpFrom[nowSt][1];\n\t\t\tif (n1 != -1)\n\t\t\t\tans.add(n1 + 1);\n\t\t\tif (n2 != -1)\n\t\t\t\tans.add(n2 + 1);\n\t\t\tif (n1 != -1)\n\t\t\t\tnowSt -= (1 << n1);\n\t\t\tif (n2 != -1)\n\t\t\t\tnowSt -= (1 << n2);\n\t\t\tans.add(0);\n\t\t}\n\t\tfor (int i = ans.size() - 1; i >= 0; i--)\n\t\t\tout.print(ans.get(i) + \" \");\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF8C().runIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3b161359a038b14b547a9ea884d5a4af", "src_uid": "2ecbac20dc5f4060bc873553946281bc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\nimport com.codeforce.task8.Task8C.XY;\n\npublic class Task8C_v2 {\n\n\tprivate static int n;\n\tprivate final static Map cache = new HashMap<>();\n\n\tpublic static void clearCache() {\n\t\tcache.clear();\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tgo(System.in);\n\t}\n\n\tpublic static void go(InputStream is) {\n\t\tXY bag = null;\n\t\tXY[] things;\n\t\tint mask;\n\t\ttry {\n\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(is));\n\t\t\tbag = new XY(br.readLine());\n\t\t\tn = Integer.parseInt(br.readLine());\n\t\t\tthings = new XY[n];\n\t\t\tmask = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tthings[i] = new XY(br.readLine());\n\t\t\t\tmask = (mask << 1) + 1;\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t\tSystem.out.println(e);\n\t\t\treturn;\n\t\t}\n\t\tint mask1 = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint time = (bag.x - things[i].x) * (bag.x - things[i].x) + (bag.y - things[i].y) * (bag.y - things[i].y);\n\t\t\tcache.put(mask1, new Result(mask1, time));\n\t\t\tmask1 <<= 1;\n\t\t}\n\t\tmask1 = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint mask2 = mask1 << 1;\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tcache.put(mask1 + mask2, new Result(mask1 + mask2,\n\t\t\t\t\t\t(things[j].x - things[i].x) * (things[j].x - things[i].x)\n\t\t\t\t\t\t\t\t+ (things[j].y - things[i].y) * (things[j].y - things[i].y) + cache.get(mask1).time\n\t\t\t\t\t\t\t\t+ cache.get(mask2).time));\n\t\t\t\tmask2 <<= 1;\n\n\t\t\t}\n\t\t\tmask1 <<= 1;\n\t\t}\n\t\tmask1 = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcache.get(mask1).time <<= 1;\n\t\t\tmask1 <<= 1;\n\t\t}\n\t\tmask1 = 1;\n\t\tSystem.out.println(find(mask));\n\t}\n\n\tprivate static Result find(int mask) {\n\t\tResult result = cache.get(mask);\n\t\tif (result != null) {\n\t\t\t//System.out.println(\"Return result: \" + result);\n\t\t\treturn result;\n\t\t}\n\t\tint index1 = 1;\n\t\twhile ((mask & index1) != index1) {\n\t\t\tindex1 <<= 1;\n\t\t}\n\t\tResult result1 = cache.get(index1);\n\t\tResult result2 = find(mask - index1);\n\t\tResult bestResult = new Result(result1, result2);\n\t\n\t\tint index2 = index1 << 1;\n\t\twhile (index2 < mask) {\n\t\t\tresult1 = cache.get(index1 + index2);\n\t\t\t//System.out.println(\"Result1: \" + result1);\n\t\t\tresult2 = find(mask - index1 - index2);\n\t\t\tint time = result1.time + result2.time;\n\t\t\tif (time < bestResult.time) {\n\t\t\t\tbestResult = new Result(result1, result2);\n\t\t\t\t//System.out.println(\"New best: \" + bestResult);\n\t\t\t}\n\t\t\tindex2 <<= 1;\n\t\t}\n\t\tcache.put(mask, bestResult);\n\t\t//System.out.println(\"Return result: \" + bestResult);\n\t\treturn bestResult;\n\t}\n\n\tstatic class Result {\n\t\tint mask;\n\t\tint time;\n\t\tResult result = null;\n\n\t\tpublic Result() {\n\t\t\ttime = 0;\n\t\t}\n\t\t\n\t\tpublic Result(Result res1, Result res2) {\n\t\t\tthis.time = res1.time + res2.time;\n\t\t\tmask = res1.mask;\n\t\t\tresult = res2;\n\t\t}\n\n\t\tpublic Result(int mask, int time) {\n\t\t\tthis.mask = mask;\n\t\t\tthis.time = time;\n\t\t}\n\n\t\tprivate void appendStr(StringBuilder str) {\n\t\t\tint temp = mask;\n\t\t\tint index1 = 1;\n\t\t\twhile ((temp & 1) != 1) {\n\t\t\t\ttemp >>= 1;\n\t\t\t\tindex1++;\n\t\t\t}\n\t\t\tstr.append(\" \").append(index1);\n\t\t\tif (temp > 1) {\n\t\t\t\ttemp--;\n\t\t\t\twhile ((temp & 1) != 1) {\n\t\t\t\t\ttemp >>= 1;\n\t\t\t\t\tindex1++;\n\t\t\t\t}\n\t\t\t\tstr.append(\" \").append(index1);\n\t\t\t}\n\t\t\tstr.append(\" 0\");\n\t\t\tif (result != null) {\n\t\t\t\tresult.appendStr(str);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\tStringBuilder str = new StringBuilder(Integer.toString(time));\n\t\t\tstr.append(\"\\r\\n\");\n\t\t\tstr.append(\"0\");\n\t\t\tappendStr(str);\n\t\t\tstr.append(\"\\r\\n\");\n\t\t\treturn str.toString();\n\t\t}\n\t}\n\n\tstatic class XY {\n\t\tint x;\n\t\tint y;\n\n\t\tpublic XY() {\n\n\t\t}\n\n\t\tpublic XY(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tpublic XY(String str) {\n\t\t\tString[] strs = str.split(\" \");\n\t\t\tx = Integer.parseInt(strs[0]);\n\t\t\ty = Integer.parseInt(strs[1]);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f72e75dd24ba55a40c1f114f5f59ef4", "src_uid": "2ecbac20dc5f4060bc873553946281bc", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF8C {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint[] x, y;\n\n\tint dist(int v, int u) {\n\t\treturn (x[v] - x[u]) * (x[v] - x[u]) + (y[v] - y[u]) * (y[v] - y[u]);\n\t}\n\n\tvoid solve() {\n\t\tint x1 = in.nextInt();\n\t\tint y1 = in.nextInt();\n\t\tint n = in.nextInt();\n\n\t\tx = new int[n + 1];\n\t\ty = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tx[i] = in.nextInt();\n\t\t\ty[i] = in.nextInt();\n\t\t}\n\t\tx[0] = x1;\n\t\ty[0] = y1;\n\t\tint[] dp = new int[(1 << n)];\n\t\tbyte[][] dpFrom = new byte[1 << n][2];\n\t\tArrays.fill(dp, Integer.MAX_VALUE);\n\t\tdp[0] = 0;\n\t\tfor (int st = 0; st < (1 << n); st++) {\n\t\t\tif (dp[st] == Integer.MAX_VALUE)\n\t\t\t\tcontinue;\n\t\t\tArrayList available = new ArrayList();\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif ((st & (1 << i)) == 0)\n\t\t\t\t\tavailable.add((byte) i);\n\t\t\tif (available.size() == 0)\n\t\t\t\tcontinue;\n\t\t\tif (available.size() == 1) {\n\t\t\t\tint val = dp[st] + dist(available.get(0) + 1, 0) * 2;\n\t\t\t\tif (dp[(1 << n) - 1] > val) {\n\t\t\t\t\tdp[(1 << n) - 1] = val;\n\t\t\t\t\tdpFrom[(1 << n) - 1][0] = available.get(0);\n\t\t\t\t\tdpFrom[(1 << n) - 1][1] = -1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int i = 0; i < available.size(); i++)\n\t\t\t\tfor (int j = i + 1; j < available.size(); j++) {\n\t\t\t\t\tint val = dp[st] + dist(available.get(i) + 1, 0)\n\t\t\t\t\t\t\t+ dist(available.get(j) + 1, 0)\n\t\t\t\t\t\t\t+ dist(available.get(i) + 1, available.get(j) + 1);\n\t\t\t\t\tif (dp[st | (1 << available.get(i))\n\t\t\t\t\t\t\t| (1 << available.get(j))] > val) {\n\t\t\t\t\t\tdp[st | (1 << available.get(i))\n\t\t\t\t\t\t\t\t| (1 << available.get(j))] = val;\n\t\t\t\t\t\tdpFrom[st | (1 << available.get(i))\n\t\t\t\t\t\t\t\t| (1 << available.get(j))][0] = available\n\t\t\t\t\t\t\t\t.get(i);\n\t\t\t\t\t\tdpFrom[st | (1 << available.get(i))\n\t\t\t\t\t\t\t\t| (1 << available.get(j))][1] = available\n\t\t\t\t\t\t\t\t.get(j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tfor (int i = 0; i < available.size(); i++) {\n\t\t\t\tint val = dp[st] + dist(available.get(i) + 1, 0) * 2;\n\t\t\t\tif (dp[st | (1 << available.get(i))] > val) {\n\t\t\t\t\tdp[st | (1 << available.get(i))] = val;\n\t\t\t\t\tdpFrom[st | (1 << available.get(i))][0] = available.get(i);\n\t\t\t\t\tdpFrom[st | (1 << available.get(i))][1] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(dp[(1 << n) - 1]);\n\t\tint nowSt = (1 << n) - 1;\n\t\tArrayList ans = new ArrayList();\n\t\tans.add(0);\n\t\twhile (nowSt != 0) {\n\t\t\tint n1 = dpFrom[nowSt][0];\n\t\t\tint n2 = dpFrom[nowSt][1];\n\t\t\tif (n1 != -1)\n\t\t\t\tans.add(n1 + 1);\n\t\t\tif (n2 != -1)\n\t\t\t\tans.add(n2 + 1);\n\t\t\tif (n1 != -1)\n\t\t\t\tnowSt -= (1 << n1);\n\t\t\tif (n2 != -1)\n\t\t\t\tnowSt -= (1 << n2);\n\t\t\tans.add(0);\n\t\t}\n\t\tfor (int i = ans.size() - 1; i >= 0; i--)\n\t\t\tout.print(ans.get(i) + \" \");\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF8C().runIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dd4ebac3ea024bd9122691fc11506bb9", "src_uid": "2ecbac20dc5f4060bc873553946281bc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "public class P58B {\n public static void main(String args[]) {\n InputReader entrada = new InputReader(System.in);\n int maximamoneda = entrada.nextInt();\n\n ArrayList resultado = denominaciones(maximamoneda);\n\n OutputWriter ow = new OutputWriter(System.out);\n \n for (int i = 0; i < resultado.size(); i++) {\n ow.print(resultado.get(i));\n if (i == resultado.size() - 1)\n ow.println();\n else\n ow.printSpace();\n }\n ow.close();\n }\n\n public ArrayList denominaciones(int maximamoneda) {\n ArrayList resultado = new ArrayList();\n resultado.add(maximamoneda);\n int numCoins = 1;\n for (int i = maximamoneda - 1; i >= 1; i--) {\n if (resultado.get(numCoins - 1) % i == 0) {\n resultado.add(i);\n numCoins++;\n }\n }\n\n return resultado;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ebe41c254631adb9a35332cfd107d2b7", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "public class ProgramacionCompetitiva {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n\n Scanner entrada= new Scanner(System.in);\n \n int moneda = entrada.nextInt();\n \n StringBuilder builder = new StringBuilder();\n \n for (int i = moneda; i>=1; i--) {\n if (moneda % i == 0) {\n builder.append(i).append(\" \");\n moneda = i;\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a840f3caba5dffc1fef0cd045ce9281", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\nimport sun.security.smartcardio.SunPCSC.Factory;\n\npublic class prooblem58B {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n prooblem58B A = new prooblem58B();\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n \n TreeMap mp = A.factorise(N);\n System.out.print(N+\" \");\n \n while(N>1)\n for(int i : mp.keySet()) {\n int val = mp.get(i);\n if(val > 0) {\n System.out.print(N/i+ \" \");\n N = N/i;\n mp.put(i , val-1);\n }\n } // for i\n \n //System.out.print(1);\n \n \n \n\n }\n \n public TreeMap factorise(int x) {\n TreeMap factors = new TreeMap();\n\n int limit = (int) Math.sqrt( x );\n ArrayList l = primeGenerator( limit );\n\n for ( int i : l )\n factors.put( i , 0 );\n\n int nxtprime = l.get( 0 );\n int i = 0;\n\n while ( x % nxtprime == 0 || nxtprime * nxtprime <= x ) {\n if ( x % nxtprime == 0 ) {\n factors.put( nxtprime , factors.get( nxtprime ) + 1 );\n x /= nxtprime;\n } else if ( ( i + 1 ) < l.size() )\n nxtprime = l.get( ++i );\n else\n break;\n }\n\n if ( x > 1 )\n factors.put( x , 1 );\n return factors;\n }// factorization\n \n public ArrayList primeGenerator(int N) {\n ArrayList primes = new ArrayList();\n primes.add( 2 );\n\n for ( int i = 3 ; i <= N ; i += 2 ) {\n boolean isPrime = true;\n int limit = (int) Math.sqrt( i );\n for ( int p : primes ) {\n if ( p > limit )\n break;\n if ( p * p > i )\n break;\n if ( i % p == 0 ) {\n isPrime = false;\n break;\n }\n }// for primes\n if ( isPrime )\n primes.add( i );\n }// for upto N\n\n return primes;\n }// primeGenerator\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bd7bc27c6b1ca96337d7b24707251c27", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.List;\nimport java.util.Queue;\nimport java.awt.*;\n\nimport com.sun.xml.internal.fastinfoset.util.ContiguousCharArrayArray;\n\npublic class codefors implements Runnable {\n\n private BufferedReader br = null;\n private PrintWriter pw = null;\n private StringTokenizer stk = new StringTokenizer(\"\");\n\n public static void main(String[] args) {\n new Thread(new codefors()).run();\n }\n\n public void run() {\n /*\n * try { // br = new BufferedReader(new FileReader(\"input.txt\")); pw =\n * new PrintWriter(\"output.txt\"); } catch (FileNotFoundException e) {\n * e.printStackTrace(); }\n */\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new OutputStreamWriter(System.out));\n solver();\n pw.close();\n\n }\n\n private void nline() {\n try {\n if (!stk.hasMoreTokens())\n stk = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(\"KaVaBUnGO!!!\", e);\n }\n }\n\n private String nstr() {\n while (!stk.hasMoreTokens())\n nline();\n return stk.nextToken();\n }\n\n private int ni() {\n return Integer.valueOf(nstr());\n\n }\n\n private double nd() {\n return Double.valueOf(nstr());\n\n }\n\n private BigInteger nbi() {\n return new BigInteger(nstr());\n }\n\n String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n }\n return null;\n }\n\n boolean prime_check(int k) {\n for (int i = 2; i < Math.sqrt(k) + 1; i++) {\n if (k % i == 0)\n return false;\n }\n return true;\n }\n\n private void solver() {\n int n = ni();\n ArrayList ar = new ArrayList();\n for (int i = 2; i < Math.sqrt(n) + 1; i++) {\n if (n % i == 0) {\n ar.add(i);\n if (i != (n / i))\n ar.add(n / i);\n }\n }\n int b[] = new int[ar.size()];\n for (int i = 0; i < ar.size(); i++) {\n b[i] = ar.get(i);\n }\n Arrays.sort(b);\n int a[] = new int[b.length];\n for (int i = 0; i < a.length; i++)\n a[i] = b[a.length - 1 - i];\n Set st = new TreeSet();\n System.out.print(n + \" \");\n\n for (int i = 0; i < a.length; i++) {\n if (!st.contains(a[i])) {\n System.out.print(a[i] + \" \");\n\n }\n for (int j = i + 1; j < a.length; j++) {\n if (a[i] % a[j] != 0)\n st.add(a[j]);\n }\n\n }\n\n System.out.println(1);\n }\n\n void exit() {\n System.exit(0);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ba9686c064944fb8c65ff03c6eae10d1", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport static java.util.Arrays.sort;\nimport java.util.Scanner;\n\n\npublic class Testing {\n\n\n public static void main(String[] args) {\n\n Scanner s=new Scanner(System.in);\nint n=s.nextInt();\nif(n==1){System.out.println(\"1 1\");\nSystem.out.println(\"1\");}\nelse{\n System.out.println(2*(n-1)+\" \"+2);\nSystem.out.println(\"1 2\");}\n}\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a92f52ae01ab2345fb92095194f239a7", "src_uid": "5c000b4c82a8ecef764f53fda8cee541", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tpublic static void main(String[] args) throws NumberFormatException,\n\tIOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint[] arr = new int[n];\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint sol = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = Integer.parseInt(st.nextToken());\n\t\t\tif(i == 0)\n\t\t\t\tsol = arr[i] ;\n\t\t\telse\n\t\t\t\tsol ^= arr[i];\n\t\t}\n\t\t\n\t\tif(sol != 0)\n\t\t\tSystem.out.println(\"Constantine\");\n\t\telse\n\t\t\tSystem.out.println(\"Mike\");\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "254ad49c117bd94ea12cadc54e6b9752", "src_uid": "5c000b4c82a8ecef764f53fda8cee541", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.System.out;\n\npublic class B\n{\n public static void main(String[] args) throws IOException\n {\n BufferedReader f = new BufferedReader(new FileReader(\"/Users/spencersharp/Desktop/input.txt\"));\n \n //BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));\n \n String output = \"\"; //Write all output to this string\n\n //Code here\n int numWays = Integer.parseInt(f.readLine());\n \n if(numWays==1)\n {\n writer.println(\"1 1\");\n writer.println(\"1\");\n }\n else\n {\n int total = 2*numWays - 2;\n\n writer.println(total + \" 2\");\n writer.println(\"1 2\");\n }\n \n //output = \"\"+total;\n \n \n //Code here\n\n //out.println(output);\n \n //writer.println(output);\n writer.close();\n System.exit(0);\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5f5ef05519854ddb99dc6bb0acfbff3b", "src_uid": "5c000b4c82a8ecef764f53fda8cee541", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.util.Map;\nimport java.util.TreeMap;\n\npublic class Test {\n final int N = 123456;\n int n;\n int[][] dp = new int[N][11];\n\n int readInt() {\n int ans = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n 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 ans;\n }\n\n void start() {\n n = readInt();\n Arrays.fill(dp[0], 1);\n if (n == 1) {\n System.out.println(1 + \" \" + 1);\n System.out.println(1);\n return;\n }\n for (int i = 1; i < N; i++) {\n dp[i][1] = 1;\n for (int j = 2; j <= 10; j++) {\n dp[i][j] = dp[i][j - 1];\n if (i < j) continue;\n int k = i;\n while (k >= j) {\n k -= j;\n dp[i][j] += dp[k][j - 1];\n }\n if (dp[i][j] == n) {\n System.out.println(i + \" \" + j);\n for (k = 1; k <= j; k++) System.out.print(k + \" \");\n return;\n }\n }\n }\n\n System.out.println();\n }\n\n public static void main(String[] args) {\n new Test().start();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "74f8094d13c0a9eec552effbcc2558e8", "src_uid": "5c000b4c82a8ecef764f53fda8cee541", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\npublic static void main(String[] args){\nScanner in=new Scanner(System.in);\nint n=in.nextInt();\nint m=in.nextInt();\nchar a[][]=new char[n][m];\nboolean flag=false;\nfor(int i=0;i=0)\n {\n if(l[i]=='C'||l[i]=='M'||l[i]=='Y'){\n p=1;break ou;\n }\n }\n }\n if(p!=1)System.out.println(\"#Black&White\");\n else System.out.println(\"#Color\");\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3cf7eabd5b3f35062ebcc303b440f664", "src_uid": "19c311c02380f9a73cd477e4fde27454", "difficulty": 800.0} {"lang": "Java 11", "source_code": "public class BrainsPhoto {\n \n \n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int x = scan.nextInt();\n int y = scan.nextInt();\n for (int i = 0; i < x; i++) {\n for (int j = 0; j < y; j++) {\n String current = scan.next();\n if (current.charAt(0) == 'C' || current.charAt(0) == 'M'\n || current.charAt(0) == 'Y') {\n System.out.println(\"#Color\");\n System.exit(0);\n }\n }\n }\n System.out.println(\"#Black&White\");\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d064f56501d966484a21c1c4005418f", "src_uid": "19c311c02380f9a73cd477e4fde27454", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class B {\n\tpublic static class Cup implements Comparable {\n\t\tint c, w;\n\t\tpublic Cup(int a, int b) { c = a; w = b; }\n\t\tpublic int compareTo(Cup other) {\n\t\t\tif(c != other.c) return other.c - c;\n\t\t\treturn w - other.w;\n\t\t}\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tlong d = in.nextLong();\n\t\tArrayList l1 = new ArrayList<>(), l2 = new ArrayList<>();\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint c = in.nextInt();\n\t\t\tint w = in.nextInt();\n\t\t\tl1.add(new Cup(c, w));\n\t\t}\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint c = in.nextInt();\n\t\t\tint w = in.nextInt();\n\t\t\tl2.add(new Cup(c, w));\n\t\t}\n\t\tCollections.sort(l1);\n\t\tCollections.sort(l2);\n\t\tif(l1.get(0).w + l2.get(0).w > d) {\n\t\t\tSystem.out.println(\"0\");\n\t\t} else {\n\t\t\tlong ans = l1.get(0).c + l2.get(0).c;\n\t\t\td -= l1.get(0).w + l2.get(0).w;\n\t\t\tlong tot = l1.get(0).c + l2.get(0).c;\n\t\t\tint i = 1, j = 1;\n\t\t\twhile(j < m && l2.get(j).w <= d) {\n\t\t\t\td -= l2.get(j).w;\n\t\t\t\tj++;\n\t\t\t\ttot += l2.get(j).c;\n\t\t\t}\n\t\t\tans = tot;\n\t\t\tfor(i = 1; i < n; i++) {\n\t\t\t\ttot += l1.get(i).c;\n\t\t\t\td -= l1.get(i).w;\n\t\t\t\twhile(d < 0 && j > 1) {\n\t\t\t\t\tj--;\n\t\t\t\t\td += l2.get(j).w;\n\t\t\t\t\ttot -= l2.get(j).c;\n\t\t\t\t}\n\t\t\t\tif(d >= 0 && tot > ans) ans = tot;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "10cc9a6e1001dc9fde63e66fba91ae2e", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class J10 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out, true);\n int n = in.nextInt();\n int m = in.nextInt();\n int d = in.nextInt();\n Pair[] phys = new Pair[n];\n Pair[] inf = new Pair[m];\n for (int i = 0; i < n; i++) {\n int s = in.nextInt();\n int w = in.nextInt();\n phys[i] = new Pair(s, w);\n }\n for (int i = 0; i < m; i++) {\n int s = in.nextInt();\n int w = in.nextInt();\n inf[i] = new Pair(s, w);\n }\n int currIdx = -1, i = 0, j = 0;\n long maxSign = 0, currSign = 0, currWght = 0;\n Arrays.sort(phys);\n Arrays.sort(inf);\n while (currWght + phys[i].w <= d) {\n currSign += phys[i].s;\n currWght += phys[i++].w;\n currIdx = i;\n }\n while (currIdx >= 0) {\n while (j < m && currWght + inf[j].w <= d) {\n currSign += inf[j].s;\n currWght += inf[j++].w;\n }\n if (j > 0)\n maxSign = Math.max(maxSign, currSign);\n currSign -= phys[currIdx].s;\n currWght -= phys[currIdx--].w;\n }\n out.print(maxSign);\n out.close();\n }\n\n static class Pair implements Comparable {\n int s;\n int w;\n\n Pair(int first, int second) {\n this.s = first;\n this.w = second;\n }\n\n @Override\n public int compareTo(Pair pair) {\n if (this.s == pair.s)\n return this.w - pair.w;\n else\n return pair.w - this.w;\n }\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Pair))\n return false;\n Pair p = (Pair) o;\n return Objects.equals(p.s, s) && Objects.equals(p.w, w);\n }\n\n @Override\n public int hashCode() {\n return this.s ^ this.w;\n }\n\n @Override\n public String toString() {\n return \"\" + '(' + this.s + ',' + this.w + ')';\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2a0241db6529a783355a8a90f9226e0", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n public static class Fuck implements Comparable{\n public int c, w;\n public int compareTo(Fuck o1) {\n if (c == o1.c)\n return 0;\n else if (c > o1.c)\n return -1;\n else\n return 1;\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 m = sc.nextInt();\n long d = sc.nextInt();\n Fuck[] a = new Fuck[n];\n Fuck[] b = new Fuck[m];\n\n for (int i = 0; i < n; i++){\n int c = sc.nextInt();\n int w = sc.nextInt();\n a[i] = new Fuck();\n a[i].c = c;\n a[i].w = w;\n }\n\n for (int i = 0; i < m; i++){\n int c = sc.nextInt();\n int w = sc.nextInt();\n b[i] = new Fuck();\n b[i].c = c;\n b[i].w = w;\n }\n\n Arrays.sort(a);\n Arrays.sort(b);\n\n long[] asumw = new long[n];\n long[] asumc = new long[n];\n long[] bsumw = new long[m];\n long[] bsumc = new long[m];\n asumw[0] = a[0].w;\n asumc[0] = a[0].c;\n bsumw[0] = b[0].w;\n bsumc[0] = b[0].c;\n\n for (int i = 1; i < n; i++)\n {\n asumw[i] = long(a[i].w) + asumw[i - 1];\n asumc[i] = long(a[i].c) + asumc[i - 1];\n }\n\n for (int i = 1; i < m; i++) {\n bsumw[i] = long(b[i].w) + bsumw[i - 1];\n bsumc[i] = long(b[i].c) + bsumc[i - 1];\n }\n\n\n long best = 0;\n for (int i = 0; i < n; i++)\n {\n if (asumw[i] > d) {\n break;\n }\n int l = 0, r = m;\n while (r - l > 1)\n {\n int mid = (l + r) / 2;\n if (bsumw[mid] + asumw[i] > d) {\n r = mid;\n }\n else {\n l = mid;\n }\n }\n if (asumw[i] + bsumw[l] > d) {\n break;\n }\n best = Math.max(best, asumc[i] + bsumc[l]);\n }\n System.out.println(best);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e273496fd4f63f186ea968506f72f71b", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer tok = new StringTokenizer(in.readLine());\n\t\tint n = Integer.parseInt(tok.nextToken());\n\t\tint m = Integer.parseInt(tok.nextToken());\n\t\tlong d = Long.parseLong(tok.nextToken());\n\t\tCup[] cup0 = new Cup[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\tcup0[i] = new Cup();\n\t\t\tcup0[i].c = Integer.parseInt(tok.nextToken());\n\t\t\tcup0[i].w = Integer.parseInt(tok.nextToken());\n\t\t\tcup0[i].type = 0;\t\t\n\t\t}\n\t\tCup[] cup1 = new Cup[m];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\tcup1[i] = new Cup();\n\t\t\tcup1[i].c = Integer.parseInt(tok.nextToken());\n\t\t\tcup1[i].w = Integer.parseInt(tok.nextToken());\n\t\t\tcup1[i].type = 1;\t\t\n\t\t}\n\t\tArrays.sort(cup0);\n\t\tArrays.sort(cup1);\n\t\tlong ans = 0;\n\t\tint r = 1;\n\t\tlong w = cup1[0].w;\n\t\tlong c = cup1[0].c;\n\t\tfor (int l = 0; l < n; l++) {\n\t\t\tw += cup0[l].w;\n\t\t\tc += cup0[l].c;\n\t\t\twhile (r < n && w + cup1[r] <= d) {\n\t\t\t\tw += cup1[r].w;\n\t\t\t\tc += cup1[r].c;\n\t\t\t\tr++;\n\t\t\t}\n\t\t\tif (w <= d) {\n\t\t\t\tres = Math.max(res, c);\n\t\t\t}\n\t\t}\n\t\tin.close();\n\t\tSystem.out.println(ans);\n\t}\n}\n\nclass Cup implements Comparable {\n\tpublic long c, w;\n\tpublic long type;\n\t\n\t@Override\n\tpublic int compareTo(Cup o) {\n\t\tif (this.c != o.c) {\n\t\t\treturn (int)o.c - (int)this.c;\n\t\t} else {\n\t\t\treturn (int)this.w - (int)o.w;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca65f6395ec6b660edf946cde4128acc", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class UnimodalArray {\n\t\tpublic static void main(String[] args) {\n\t\t\tScanner scan = new Scanner(System.in);\n\n\t\t\tint n = scan.nextInt();\n \t\tint[] arreglo = new int[n];\n \t\tint pos1 = 0;\n \t\tint pos2 = n-1;\n\n\t\t\tfor(int i=0;i 1000){\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif(n >= 1 && n <= 100){\n\t\t\t\tfor(int j=0;j=1;k--){\n\t\t\t\t\tif(arreglo[k]=a[i]&&x<=b[i])\n {\n ans=x;\n j=true;\n break;\n }\n else if(x a[0])\n inc = true;\n else if (a[1] == a[0])\n mode = true;\n else\n dec = true;\n \n for (int i = 2; i < n; i++)\n {\n preinc = inc, premode = mode, predec = dec;\n \n inc = (a[i] > a[i - 1]);\n mode = (a[i] == a[i - 1]);\n dec = (a[i] < a[i - 1]);\n \n if ((predec && mode) || (predec && inc) || (premode && inc))\n {\n unimodal = false;\n break;\n }\n \n }\n \n if (unimodal)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\")\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3e0e831288ec2c3ca1e297d19d6f3de7", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\n import java.io.*;\nimport java.util.*;\n\npublic class file {\n\n\tpublic static void main(String[] args) {\n\t\tStdIn in = new StdIn();\n\t\tint n=in.nextInt();\n\t\tint[] ar = in.readIntArray(n);\n\t\tint stage=0;\n\t\tfor(int i=1; iar[i-1])\n\t\t\t\tnewStage=0;\n\t\t\telse if(ar[i]==ar[i-1])\n\t\t\t\tnewStage=1;\n\t\t\telse\n\t\t\t\tnewStage=2;\n\t\t\tif(newStage= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n throw new InputMismatchException ();\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int peek(){\n if (numChars == -1){\n return -1;\n }\n if (curChar >= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n return -1;\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar];\n }\n\n public int nextInt(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n int res = 0;\n do{\n if(c==','){\n c = read();\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public long nextLong(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n long res = 0;\n do{\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public String nextString(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n StringBuilder res = new StringBuilder ();\n do{\n res.appendCodePoint (c);\n c = read ();\n } while (!isSpaceChar (c));\n return res.toString ();\n }\n\n public boolean isSpaceChar(int c){\n if (filter != null){\n return filter.isSpaceChar (c);\n }\n return isWhitespace (c);\n }\n\n public static boolean isWhitespace(int c){\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0(){\n StringBuilder buf = new StringBuilder ();\n int c = read ();\n while (c != '\\n' && c != -1){\n if (c != '\\r'){\n buf.appendCodePoint (c);\n }\n c = read ();\n }\n return buf.toString ();\n }\n\n public String nextLine(){\n String s = readLine0 ();\n while (s.trim ().length () == 0)\n s = readLine0 ();\n return s;\n }\n\n public String nextLine(boolean ignoreEmptyLines){\n if (ignoreEmptyLines){\n return nextLine ();\n }else{\n return readLine0 ();\n }\n }\n\n public BigInteger nextBigInteger(){\n try{\n return new BigInteger (nextString());\n } catch (NumberFormatException e){\n throw new InputMismatchException ();\n }\n }\n\n public char nextCharacter(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n return (char) c;\n }\n\n public double nextDouble(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n double res = 0;\n while (!isSpaceChar (c) && c != '.'){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n }\n if (c == '.'){\n c = read ();\n double m = 1;\n while (!isSpaceChar (c)){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read ();\n }\n }\n return res * sgn;\n }\n\n public boolean isExhausted(){\n int value;\n while (isSpaceChar (value = peek ()) && value != -1)\n read ();\n return value == -1;\n }\n\n public String next(){\n return nextString();\n }\n\n public SpaceCharFilter getFilter(){\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter){\n this.filter = filter;\n }\n\n public interface SpaceCharFilter{\n public boolean isSpaceChar(int ch);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c4431808eb077b1c204f575872e08b79", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] raw = r.readLine().split(\"\\\\s\");\n\t\tlong n = Long.parseLong(raw[0]);\n\t\tlong a = Long.parseLong(raw[1]);\n\t\tlong b = Long.parseLong(raw[2]);\n\t\tlong c = Long.parseLong(raw[3]);\n\n\t\tif (n%4 == 0)\n\t\t\tSystem.out.println(0);\n\t\telse\n\t\tif (n%4 == 1)\n\t\t\tSystem.out.println(Math.min(3*a, Math.min(c, a + b)));\n\t\telse\n\t\tif (n%4 == 2)\n\t\t\tSystem.out.println(Math.min(b, Math.min(2*c, 2*a)));\n\t\telse\n\t\t\tSystem.out.println(Math.min(a, Math.min(3*c, b + c));\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f5e071f5e2c32498707ff70f47d5bd7", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\n\npublic class Main {\n static final long MOD = 1000000007L;\n \n static long[][] upStep;\n static long[][] downStep;\n static {\n upStep = new long[20][2];\n downStep = new long[20][2];\n \n upStep[0][0] = 3;\n upStep[0][1] = 1;\n downStep[0][0] = 1;\n downStep[0][1] = 3;\n for (int i = 1; i < 20; i++) {\n long uu = 1;\n long ud = 0;\n long dd = 1;\n long du = 0;\n for (int j = 0; j < 10; j++) {\n long nuu = (uu * upStep[i - 1][0] + du * upStep[i - 1][1]) % MOD;\n long nud = (ud * upStep[i - 1][0] + dd * upStep[i - 1][1]) % MOD;\n long ndd = (dd * downStep[i - 1][1] + ud * downStep[i - 1][0]) % MOD;\n long ndu = (du * downStep[i - 1][1] + uu * downStep[i - 1][0]) % MOD;\n uu = nuu;\n ud = nud;\n dd = ndd;\n du = ndu;\n }\n upStep[i][0] = uu;\n upStep[i][1] = ud;\n downStep[i][0] = du;\n downStep[i][1] = dd;\n }\n }\n \n public static void main(String[] args) throws Exception {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n long uu = 1;\n long ud = 0;\n long dd = 1;\n long du = 0;\n char[] arr = Integer.toString(n).toCharArray();\n for (int i = 0, j = arr.length - 1; i < arr.length; i++, j--) {\n int limit = arr[i] - '0';\n for (int k = 0; k < limit; k++) {\n long nuu = (uu * upStep[j][0] + du * upStep[j][1]) % MOD;\n long nud = (ud * upStep[j][0] + dd * upStep[j][1]) % MOD;\n long ndd = (dd * downStep[j][1] + ud * downStep[j][0]) % MOD;\n long ndu = (du * downStep[j][1] + uu * downStep[j][0]) % MOD;\n uu = nuu;\n ud = nud;\n dd = ndd;\n du = ndu;\n }\n }\n long result = uu % MOD;\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d13db4aaa42301e012a6d1efbab80473", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Plant {\n public static void main(String[] args) throws IOException {\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(f.readLine());\n long mod = 1000000007;\n System.out.println((pow(2,(2*n-1)%(mod-1),mod) + pow(2,(n-1)%(mod-1),mod)) % mod);\n }\n \n public static long pow(long a, long n, long mod)\n {\n if (n == 0)\n return 1;\n long b = pow(a, n/2, mod);\n b = (b*b) % mod;\n if (n % 2 == 1)\n b = (b*a) % mod;\n return b;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1fb0edeaaefa9bec48599ee86f44edeb", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main \n{\n static int mod = 1000000000+7;\n public static void main(String[] args) \n {\n Scanner scan= new Scanner(System.in);\n long mat[][]= {{3,1},{1,3}};\n long ans[][] = {{1,0},{0,1}};\n \n int n = scan.nextInt();\n while(n !=0)\n {\n long tmp[][]={{0,0},{0,0}};\n if(n%2 !=0)\n {\n for(int i=0;i<2;i++)\n for(int j=0;j<2;j++)\n for(int k=0;k<2;k++)\n tmp[i][j] = add(tmp[i][j],mul(ans[i][k],mat[k][j]));\n for(int i=0;i<2;i++)\n for(int j=0;j<2;j++)\n ans[i][j] = tmp[i][j];\n }\n for(int i=0;i<2;i++)\n for(int j=0;j<2;j++)\n tmp[i][j] = 0;\n for(int i=0;i<2;i++)\n for(int j=0;j<2;j++)\n for(int k=0;k<2;k++)\n tmp[i][j] = add(tmp[i][j],mul(mat[i][k],mat[k][j]));\n for(int i=0;i<2;i++)\n for(int j=0;j<2;j++)\n mat[i][j] = tmp[i][j];\n n/=2;\n }\n \n long res = ans[0][0];\n System.out.println(res);\n }\n \n static long add(long a,long b)\n {\n return (a+b)%mod;\n }\n static long mul(long a, long b)\n {\n return (a*b)%mod;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b1c6e75094ccaa6c069999c3730774a4", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class B {\n public static void main(String[] args) { \n Scanner theIn=new Scanner(System.in);\n long n=theIn.nextLong();\n long i=1;\n int k=3;\n long t=1;\n long d=0;\n long temp;\n \n long p=0;\n \n while (i<=n) {\n temp=t*3+d;\n d=t+d*3;\n t=temp;\n if (t>1000000007) t=t%1000000007;\n if (d>1000000007) d=d%1000000007;\n //System.out.println(t);\n i++;\n /* if ((t%1000000007)==3) {\n p=i;\n break;\n }*/\n }\n System.out.println(t);\n /* if (i==n) System.out.println(t); else {\n \n }*/\n \n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0257bdfaedac097207470f7bc609a819", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class viva\n{\n public static void main(String args[])\n {\n long mod=((long)Math.pow(10,9))+7;\n Scanner scan=new Scanner(System.in);\n long a[]=new long[7];\n a[1]=scan.nextLong();\n a[2]=scan.nextLong();\n a[3]=a[1]-a[0];\n a[4]=-a[1];\n a[5]=-a[2];\n a[6]=-a[3];\n long g=scan.nextLong();\n int h=(g%6);\n if(h==0)\n h=6;\n System.out.println(a[h]%mod);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3714f6ae0532854cfc8eece1d691ce86", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*; \npublic class Main{\n public static void main(String ... string){\n Scanner sc = new Scanner(System.in); \n int x = sc.nextInt(); \n int y = sc.nextInt(); \n int n = sc.nextInt();\n int mod = 1000000007;\n int ans = 0; \n switch(n%6){\n case 1: ans = x%mod;\n break; \n case 2: ans = y%mod;\n break; \n case 3: ans = (y-x)%mod; \n break; \n case 4: ans = (-x)%mod; \n break; \n case 5: ans = (-y)%mod;\n break; \n case 6: ans = (x-y)%mod; \n break;\n }\n if(ans < 0) ans += mod;\n System.out.println(ans);\n else System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fa901d8705a493ef10c6ad9cd3fc3131", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint x, y, n;\n\t\tx = in.nextInt();\n\t\ty = in.nextInt();\n\t\tn = in.nextInt();\n\t\tn = n%6;\n\t\tif (n==0){\n\t\t\tSystem.out.println((-y+x)%1000000007);\n\t\t}elif (n==1){\n\t\t\tSystem.out.println(x%1000000007);\n\t\t}elif (n==2){\n\t\t\tSystem.out.println(y%1000000007);\n\t\t}elif (n==3){\n\t\t\tSystem.out.println((y-x)%1000000007);\n\t\t}elif (n==4){\n\t\t\tSystem.out.println((-x)%1000000007);\n\t\t}elif (n==5){\n\t\t\tSystem.out.println((-y)%1000000007);\n\t\t}\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05f1eaa4c2914c7b9c511254e7a8b362", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*; \npublic class Main{\n public static void main(String ... string){\n Scanner sc = new Scanner(System.in); \n long x = sc.nextLong(); \n long y = sc.nextLong(); \n long n = sc.nextLong();\n long mod = 1000000007;\n long ans = 0; \n switch(n%6){\n case 1: ans = x;\n break; \n case 2: ans = y;\n break; \n case 3: ans = (y-x); \n break; \n case 4: ans = (-x); \n break; \n case 5: ans = (-y);\n break; \n case 6: ans = (x-y); \n break;\n }\n if(ans < 0) {ans += mod;\n System.out.println(ans%mod);}\n else System.out.println(ans%mod);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ad86a3587b840726ab0e47774e7ec18a", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n/**\n * Created by jlab on 8/10/2015.\n */\npublic class round315taskA {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int t, s, q;\n t = in.nextInt();\n s = in.nextInt();\n q = in.nextInt();\n\n /* if (q * s - 1 >= t) {\n System.out.println(1);\n return;\n }\n\n if (q * s - 1 >= t - s) {\n System.out.println(1);\n return;\n }*/\n int downloaded = s;\n t = t - ((q - 1) * downloaded + s);\n int answer = 1;\n while (t > 0) {\n s += ((q - 1) * s);\n t = t - ((q - 1) * s);\n .//System.out.println(\"| T = \" + t + \" | coef = \" + s);\n\n answer++;\n }\n System.out.println(answer);\n\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "45f937126f9dcdb10a6d465cd49b4982", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "public class Solution {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int t = scan.nextInt();\n int s = scan.nextInt();\n int q = scan.nextInt();\n int temp = s*q;\n int count = 0;\n while(temp1000000)\n\t\t\t\treturn -1;\n\t\t\telse\n\t\t\t\treturn out;\n\t\t}\n\t}\n\t\n\tvoid printarr(int [] a,int b)\n\t{\n\t\tfor(int i = 0;i<=b;i++)\n\t\t{\n\t\t\tif(i==0)\n\t\t\t\tSystem.out.print(a[i]);\n\t\t\telse\n\t\t\t\tSystem.out.print(\" \"+a[i]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n\tString s;\n\tboolean input() throws IOException\n\t{\n\t\ts = nline();\n\t\treturn true;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "812ea660526c87e8bed4d5239f3009aa", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "//CF\n//175/A\n\nimport java.util.Scanner;\nimport java.math.BigInteger;\nimport java.util.Vector;\npublic class Main {\n public static void main(String[]args) {\n Scanner in = new Scanner(System.in);\n String s = in.next();\n BigInteger max = new BigInteger(\"0\");\n BigInteger x = new BigInteger(\"0\");\n String s1, s2, s3;\n Vector v = new Vector();\n boolean b = false;\n boolean B = false;\n for (int i = 1 ; i < s.length()-1; i++) {\n for (int j = i+1 ; j < s.length(); j++) {\n s1 = s.substring(0, i);\n s2 = s.substring(i, j);\n s3 = s.substring(j, s.length());\n b = false;\n if ((s1.length() > 1) && (s1.charAt(0) == '0')) b = true;\n if ((s2.length() > 1) && (s2.charAt(0) == '0')) b = true;\n if ((s3.length() > 1) && (s3.charAt(0) == '0')) b = true;\n\n v.add(b);\n\n while (!v.isEmpty()) {\n if (v.remove(0) == false) B = true;\n // B true means that is one at least one combination don't have any leading zeros\n }\n x = new BigInteger(\"\"+new BigInteger(s1).add( new BigInteger(s2).add(new BigInteger(s3))));\n //System.out.println(s1+\" \"+s2+\" \"+s3+\" = \"+x.toString()+\" || \"+max.toString());\n if (x.compareTo(max) > 0) {\n max = new BigInteger(x+\"\");\n }\n }//end of inner loop (j = 0)\n }//end of outer loop (i = 0)\n if (B == true) {\n System.out.println(max.toString());\n } else System.out.println(-1);\n }//end of main method\n}//end of class//CF\n//175/A\n\nimport java.util.Scanner;\nimport java.math.BigInteger;\nimport java.util.Vector;\npublic class RobotBicornAttack {\n public static void main(String[]args) {\n Scanner in = new Scanner(System.in);\n String s = in.next();\n BigInteger max = new BigInteger(\"0\");\n BigInteger x = new BigInteger(\"0\");\n String s1, s2, s3;\n Vector v = new Vector();\n boolean b = false;\n boolean B = false;\n for (int i = 1 ; i < s.length()-1; i++) {\n for (int j = i+1 ; j < s.length(); j++) {\n s1 = s.substring(0, i);\n s2 = s.substring(i, j);\n s3 = s.substring(j, s.length());\n b = false;\n if ((s1.length() > 1) && (s1.charAt(0) == '0')) b = true;\n if ((s2.length() > 1) && (s2.charAt(0) == '0')) b = true;\n if ((s3.length() > 1) && (s3.charAt(0) == '0')) b = true;\n\n v.add(b);\n\n while (!v.isEmpty()) {\n if (v.remove(0) == false) B = true;\n // B true means that is one at least one combination don't have any leading zeros\n }\n x = new BigInteger(\"\"+new BigInteger(s1).add( new BigInteger(s2).add(new BigInteger(s3))));\n //System.out.println(s1+\" \"+s2+\" \"+s3+\" = \"+x.toString()+\" || \"+max.toString());\n if (x.compareTo(max) > 0) {\n max = new BigInteger(x+\"\");\n }\n }//end of inner loop (j = 0)\n }//end of outer loop (i = 0)\n if (B == true) {\n System.out.println(max.toString());\n } else System.out.println(-1);\n }//end of main method\n}//end of class", "lang_cluster": "Java", "compilation_error": true, "code_uid": "021d141ac86ce9ed96247ea2bc5b772e", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[]args){\n Scanner input = new Scanner(System.in);\n ArrayList l = new ArrayList();\n String s = input.next();\n if(s.equals(\"100000010000001000000\"){\n System.out.println(\"-1\");\n System.exit(0);\n }\n int n = s.length() - 2;\n int x = n + 1;\n while(n >= 1){\n\n String s1 = s.substring(0, n);\n String s2 = s.substring(n, x);\n String s3 = s.substring(x, s.length());\n if(invaild(s1, s2, s3)){\n n--;\n continue;\n }\n\n l.add(Long.parseLong(s1)\n +Long.parseLong(s2)\n +Long.parseLong(s3));\n int m = x-n;\n while(m > 1){\n if(invaild(s.substring(0, n), s.substring(n, x-(m-1))\n ,s.substring(x-(m-1), s.length()))){\n m--;\n continue;\n }\n l.add(Long.parseLong(s.substring(0, n))\n +Long.parseLong(s.substring(n, x-(m-1)))\n +Long.parseLong(s.substring(x-(m-1), s.length())));\n m--;\n }\n n--;\n }\n if(l.isEmpty())\n System.out.println(-1);\n else{\n long m = l.get(0);\n for(int i = 1; i < l.size(); i++)\n if(l.get(i) > m)\n m = l.get(i);\n System.out.println(m);\n }\n\n }\n public static boolean invaild(String s1, String s2, String s3){\n if(((s1.charAt(0) == '0') && (s1.length()> 1))\n ||((s2.charAt(0) == '0') && (s2.length()> 1))\n ||((s3.charAt(0) == '0')) && (s3.length()> 1))\n return true;\n if(((Long.parseLong(s1) != 1000000)&&(s1.length()> 6))\n ||((Long.parseLong(s2) != 1000000)&&(s2.length()> 6))\n ||((Long.parseLong(s3) != 1000000)&&(s3.length()> 6)))\n return true;\n return false;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "41824c38fdea01524fec0b16cc4b6911", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.util.*;\n// Author: Davit Khaburdzania | dato7077@gmail.com \n\npublic class Main {\n public static void main(String[] args) throws IOException{\n Scanner in= new Scanner(System.in); \n PrintWriter out= new PrintWriter(System.out);\n String str= in.nextLine();\n if(str.length()<3 || str.length()>21){\n System.out.println(\"-1\");\n return;\n }\n int len=str.length();\n String x1=str.substring(0,len-2);\n Integer x= Integer.parseInt(x1);\n Integer y= Integer.parseInt(str.substring(1,len-1));\n Integer z= Integer.parseInt(str.substring(2));\n int answer=0;\n Boolean br=true;\n while(br){\n if(x.toString().length()==y.toString().length() && x.toString().length()==z.toString().length()){\n if(x.toString().length()*3=y && x>=z){\n answer+=x;\n answer+= (Integer.parseInt(new Character(str.charAt(len-2)).toString()));\n answer+= (Integer.parseInt(new Character(str.charAt(len-1)).toString()));\n System.out.println(answer);\n return;\n }\n if(y>x && y>z){\n answer+=y;\n answer+= (Integer.parseInt(new Character(str.charAt(len-2)).toString()));\n answer+= (Integer.parseInt(new Character(str.charAt(0)).toString()));\n System.out.println(answer);\n return;\n }\n\n if(z>x && z>y){\n answer+=z;\n answer+= (Integer.parseInt(new Character(str.charAt(0)).toString()));\n answer+= (Integer.parseInt(new Character(str.charAt(1)).toString()));\n System.out.println(answer);\n return;\n } \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "74d816d9b16b4b1871b789b908e53545", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class DT\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt(); int k=sc.nextInt(); \n int s[]=new int[n]; int st[]=new int[n];\n for(int i=0;i=k)\n {\n System.out.println(\"YES\");\n while(c1 a= new ArrayList();\n ArrayList b= new ArrayList();\n for(int x=0;x ans;\n for(int i = 0; i < n; ++i) {\n boolean ok = true;\n for(Integer j : ans) {\n if(a[j] == a[i]) {\n ok = false;\n break;\n }\n }\n\n if(ok) {\n ans.add(i);\n }\n }\n\n if(ans.size() < k) {\n out.print(\"NO\");\n return;\n }\n\n for(int i = 0; i < k; ++i) {\n out.print(ans.get(i) + \" \");\n }\n }\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n new Task().run(in, out);\n out.flush();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e7c25266b12974aee5becdb0f9d8bbc0", "src_uid": "5de6574d57ab04ca195143e08d28d0ad", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import static java.lang.Math.*;\nimport java.util.*;\npublic class Main\n{\n public static void main(String[] args) \n {\n\t Scanner sc = new Scanner(System.in); \n int n= sc.nextInt();\n\t int[] array;\n\t array=new int[n];\n\t Set reg = new HashSet();\n\t int m=sc.nextInt();\n\t counter=0;\n\t for(int i=0;i=m)\n\t {\n\t\t System.out.println(\"YES\");\n\t\t for(int i=0;i=0&&blue>=0)\n System.out.println(0);\n else if(yellow=<0&&blue>=0)\n System.out.println(yellow-a);\n else if(yellow>=0&&blue=<0)\n System.out.println(blue-b);\n else\n System.out.println((yellow-a)+(blue-b));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39b50d2a84c3f9d554bc76eae8b7682c", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.scanner;\n\npublic class test1{\n\n public static void main(String[] args) {\n int yellow,blue;\n\tint x,y,z;\n\tint temp1,temp2;\n\tint ris;\n\tScanner scanner = new Scanner(System.in);\n\tyellow = scanner.nextInt();\n\tblue = scanner.nextInt();\n\tx = scanner.nextInt();\n\ty = scanner.nextInt();\n\tz = scanner.nextInt();\n\ttemp1=temp2=ris=0;\n\ttemp1=2*x + y;\n\ttemp2=3*z + y;\n\tif (temp1 > yellow)\n\t\tris=temp1-yellow;\n\tif(temp2 > blue)\n\t\tris=ris+temp2-blue;\n\tSystem.out.printf(\"%d\", ris);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c5abe60df35cb67fc5f41d0424f79421", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n long yellowBall = input.nextLong();\n long blueBall = input.nextLong();\n long x = input.nextLong();\n long y = input.nextLong();\n long z = input.nextLong();\n \n System.out.println(Math.max(x * 2 + y - yellowBall, 0) + Math.max(z * 3 + y - blueBall));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1fe124e014503ac0d4565039a7e03e54", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.scanner\n\npublic class test1{\n\n public static void main(String[] args) {\n int yellow,blue;\n\tint x,y,z;\n\tint temp1,temp2;\n\tint ris;\n\tScanner scanner = new Scanner(System.in);\n\tyellow = scanner.nextInt();\n\tblue = scanner.nextInt();\n\tx = scanner.nextInt();\n\ty = scanner.nextInt();\n\tz = scanner.nextInt();\n\ttemp1=temp2=ris=0;\n\ttemp1=2*x + y;\n\ttemp2=3*z + y;\n\tif (temp1 > yellow)\n\t\tris=temp1-yellow;\n\tif(temp2 > blue)\n\t\tris=ris+temp2-blue;\n\tSystem.out.printf(\"%d\", ris);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67098b0519cd461073d45e31638af6ff", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n\npublic class Main{\n\n static Queue q;\n static int n,m,k;\n static boolean seen[];\n public static void main(String[] args)throws Exception {\n File _=new File(\"strings.in\");\n BufferedReader br = _.exists() ? new BufferedReader( new FileReader(_)) : new BufferedReader( new InputStreamReader(System.in));\n StringTokenizer st;\n st=new StringTokenizer(br.readLine());\n \n n=Integer.parseInt(st.nextToken());\n m=Integer.parseInt(st.nextToken());\n k=Integer.parseInt(st.nextToken());\n \n q=new LinkedList();\n int mod=1000000007;\n \n seen=new boolean[n];\n int groups=0;\n for (int i = 0; i < n; i++) {\n if(!seen[i])\n {\n groups++;\n q.add(i);\n while(!q.isEmpty())\n {\n \n visit(q.poll());\n }\n }\n }\n \n long power=(long) m;\n \n for (int i = 0; i < groups-1; i++) {\n power=(power*m)%mod;\n }\n System.out.println(power);\n \n }\n\n private static void visit(int i) {\n seen[i]=true;\n for (int j = i-k+1; j <= i ; j++) {\n if(j>=0&&j+k-1<=n-1)\n {\n if(!seen[j+k-1-(i-j)])\n q.add(j+k-1-(i-j));\n }\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c8f7a661686d7441a676755e42c026b", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n//\tstatic Scanner in; static int next() throws Exception {return in.nextInt();};\n\tstatic StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n//\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws Exception {\n//\t\tin = new Scanner(System.in);\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n//\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tint n = next();\n\t\tint m = next();\n\t\tint k = next();\n\n\t\tint mod = 1000000007;\n\n\t\tif (n > k) {\n\t\t\tif (k % 2 == 0) out.println(m);\n\t\t\telse out.println(m * m);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\n\t\tif (n == k) {\n\t\t\tlong answ = 1;\n\t\t\tfor (int i = 0; i < n - n/2; i++) answ = (answ * m) % mod;\n\t\t\tout.println(answ);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\n\t\tlong answ = 1;\n\t\tfor (int i = 0; i < n; i++) answ = (answ * m) % mod;\n\t\tout.println(answ);\n\t\t\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8f2dc93831babde7115a1726041adf62", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B implements Runnable {\n private MyScanner in;\n private PrintWriter out;\n\n private final int MOD = 1000000007;\n\n private long pow(long n, int k) {\n if (k == 0) {\n return 1;\n }\n long ans = pow(n, k / 2);\n ans = (ans * ans) % MOD;\n if (k % 2 == 1) {\n ans = (ans * n) % MOD;\n }\n return ans;\n }\n\n private void solve() {\n int n = in.nextInt();\n int m = in.nextInt();\n int k = in.nextInt();\n if (n < k) {\n out.println(pow(m, n));\n return;\n }\n if (n == k) {\n out.println(pow(m, (n + 1) / 2));\n return;\n }\n if (k % 2 == 0) {\n out.println(m);\n return;\n }\n out.println(pow(m, 2));\n return;\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 B().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 private String nextToken() {\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 String next() {\n return 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8bd57b262af219b6e7379e10bee5dc46", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists())\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\tnew Main().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tlong mod = 1000000007;\n\tBigInteger MOD = BigInteger.valueOf(mod);\n\t\n\tvoid solve() throws IOException{\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint k = nextInt();\n\t\tlong ans;\n\t\tif(k > n || k == 1)\n\t\t\tans = BigInteger.valueOf(m).modPow(BigInteger.valueOf(n), MOD).longValue();\n\t\telse {\n\t\t\tif(k == n)\n\t\t\t\tans = BigInteger.valueOf(m).modPow(BigInteger.valueOf((n + 1) / 2), MOD).longValue();\n\t\t\telse {\n\t\t\t\tif(k == n - 1 && k % 2 != 0)\n\t\t\t\t\tans = (m * m) % mod;\n\t\t\t\telse\n\t\t\t\t\tans = m;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tvoid chk(boolean b) {\n\t\tif (b)\n\t\t\treturn;\n\t\tSystem.out.println(new Error().getStackTrace()[1]);\n\t\texit(999);\n\t}\n\tvoid deb(String fmt, Object... args) {\n\t\tSystem.out.printf(Locale.US, fmt + \"%n\", args);\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa0e9913145120ca318632556aab18e9", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package algo.hard;\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\nimport static java.lang.Math.PI;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.hypot;\nimport static java.lang.Math.round;\nimport static java.lang.Math.sin;\n\nimport static org.assertj.core.api.Assertions.assertThat;\nimport static org.assertj.core.data.Percentage.withPercentage;\n\npublic class AncientCircus {\n int gcd(int a,int b) { return b>0?gcd(b,a%b):a;}\n\n double[] findCenter(double[] x0, double[] x1, double x2[]) {\n double a = x0[0] - x1[0];\n double b = x0[1] - x1[1];\n double c = x0[0] - x2[0];\n double d = x0[1] - x2[1];\n double w0 = (x0[0]*x0[0] - x1[0]*x1[0] + x0[1]*x0[1] - x1[1]*x1[1])/2.;\n double w1 = (x0[0]*x0[0] - x2[0]*x2[0] + x0[1]*x0[1] - x2[1]*x2[1])/2.;\n double det = a * d - b * c;\n if (det==0) throw new NumberFormatException();\n double x = (d * w0 - b * w1) / det;\n double y = (-c * w0 + a * w1) / det;\n return new double[]{x,y};\n }\n\n double getAngle(double nx, double ny) {\n double w = Math.atan2(ny, nx);\n // if (w<0) w += 2 * PI;\n return w;\n }\n\n boolean isOK(double angle, double even) {\n double w = angle / even;\n return (abs(round(w) - w) < 1e-4);\n }\n\n public double findSmallest(double[] coordinates1, double[] coordinates2, double[] coordinates3) {\n double[] c = findCenter(coordinates1, coordinates2, coordinates3);\n for (int i = 0; i < 2; i++) {\n coordinates1[i] -= c[i];\n coordinates2[i] -= c[i];\n coordinates3[i] -= c[i];\n }\n double r = hypot(coordinates1[0], coordinates1[1]);\n double[] a = new double[] {\n getAngle(coordinates1[0], coordinates1[1]),\n getAngle(coordinates2[0], coordinates2[1]),\n getAngle(coordinates3[0], coordinates3[1]),\n };\n Arrays.sort(a);\n\n for (int n = 3; n <= 200; n++) {\n double even = 2 * PI / n;\n if (isOK(a[2] - a[1], even) && isOK(a[1] - a[0], even)) {\n return r * r * sin(even) / 2. * n;\n }\n }\n return 0;\n }\n\n public static void main(String[] args) {\n Scanner scanner=new Scanner(System.in);\n\t\tdouble x1=scanner.nextDouble();\n\t\tdouble y1=scanner.nextDouble();\n\t\tdouble x2=scanner.nextDouble();\n\t\tdouble y2=scanner.nextDouble();\n\t\tdouble x3=scanner.nextDouble();\n\t\tdouble y3=scanner.nextDouble();\n AncientCircus t = new AncientCircus();\n System.out.println(t.findSmallest(new double[]{x1,y1},new double[]{x2,y2},new double[]{x3,y3}));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "25990403d5dd18db04270c37baf77603", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Main {\n \n public static void main(String[] args) throws IOException {\n\n BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n\n String pointA[] = stdin.readLine().split(\" \");\n\n String pointB[] = stdin.readLine().split(\" \");\n\n String pointC[] = stdin.readLine().split(\" \");\n\n \n\n double Ax = Double.parseDouble(pointA[0]), Ay = Double.parseDouble(pointA[1]);\n\n double Bx = Double.parseDouble(pointB[0]), By = Double.parseDouble(pointB[1]);\n\n double Cx = Double.parseDouble(pointC[0]), Cy = Double.parseDouble(pointC[1]);\n\n \n\n double a = Math.sqrt((Bx - Cx) * (Bx - Cx) + (By - Cy) * (By - Cy));\n\n double b = Math.sqrt((Ax - Cx) * (Ax - Cx) + (Ay - Cy) * (Ay - Cy));\n\n double c = Math.sqrt((Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By));\n\n \n\n double p = (a + b + c) / 2;\n\n double S = Math.sqrt(p * (p - a) * (p - b) * (p - c));\n\n double R = a * b * c / (4 * S);\n\n \n\n double alpha = Math.acos((b * b + c * c - a * a) / (2 * b * c));\n\n double beta = Math.acos((a * a + c * c - b * b) / (2 * a * c));\n\n double gamma = Math.PI - alpha - beta;\n\n long n = Math.round(Math.PI / gcd(beta, gcd(alpha, gamma)));\n\n \n\n PrintWriter stdout = new PrintWriter(System.out);\n\n stdout.println(R * R * Math.sin(2 * Math.PI / n) * n / 2);\n\n stdout.close();\n\n }\n\n \n\n private static double gcd(double a, double b) {\n\n if (a < b) return gcd(b, a);\n\n if (Math.abs(b) < 0.001) {\n\n return a;\n\n } else {\n\n return (gcd(b, a - Math.floor(a / b) * b));\n\n }\n\n }\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "61c3472be9193df540dfa027799a6d6a", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "public class Problem1C {\n public static final double ErrRate = 0.000001;\n \n // Euclid's algorithm\n public static double getGCD(double a, double b) {\n if (b < ErrRate) return a;\n return getGCD(b, Math.abs(a % b));\n }\n \n public static void main(String[] arg) {\n double[] x = new double[3];\n double[] y = new double[3];\n \n Scanner sc = new Scanner(System.in);\n for (int i = 0; i < 3; i++) {\n String pointInfo = sc.nextLine();\n StringTokenizer st = new StringTokenizer(pointInfo, \" \");\n x[i] = Double.parseDouble(st.nextToken());\n y[i] = Double.parseDouble(st.nextToken());\n }\n \n double[] line = new double[3];\n for (int i = 0; i < 3; i++)\n line[i] = Math.sqrt(Math.pow(x[i] - x[(i + 1) % 3], 2) + Math.pow(y[i] - y[(i + 1) % 3], 2));\n \n // By Heron's formula\n double p = (line[0] + line[1] + line[2]) / 2;\n double triangleArea = Math.sqrt(p * (p - line[0]) * (p - line[1]) * (p - line[2]));\n \n // Radius of the circumscribed circle\n double radius = line[0] * line[1] * line[2] / (4 * triangleArea);\n \n // Find two short lines among three\n Arrays.sort(line);\n \n // Law of consines: a^2 = b^2 + c^2 - 2bc * cosA\n double[] angle = new double[3];\n for (int i = 0; i < 2; i++) {\n angle[i] = Math.acos((2 * radius * radius - line[i] * line[i]) / (2 * radius * radius));\n }\n angle[2] = 2 * Math.PI - (angle[0] + angle[1]);\n \n double unitAngle = getGCD(angle[0], getGCD(angle[1], angle[2]));\n double polygonArea = radius * radius * Math.sin(unitAngle) * Math.PI / unitAngle;\n System.out.println(polygonArea);\n sc.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f2e76a9346c9666dcfd05f36b2a4faed", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author skdey\n */\npublic class AncientBerlandCircus {\n\n static final double gcdPrecison = Math.pow(10, -4);\n\n static class ReadInputFromConsole {\n\n BufferedReader is;\n\n public ReadInputFromConsole() {\n\n is = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String readNextToke() throws IOException {\n if (is != null) {\n String str = is.readLine();\n if (str == null) {\n releaseResource();\n }\n return str;\n }\n return null;\n }\n\n private void releaseResource() throws IOException {\n if (is != null) {\n is.close();\n is = null;\n }\n }\n\n }\n\n public static class Coordinate {\n\n private double x;\n private double y;\n\n public Coordinate(double pX, double pY) {\n this.x = pX;\n this.y = pY;\n }\n\n public double slope(Coordinate refrential) {\n\n if (this.x == refrential.x) {\n return Double.POSITIVE_INFINITY;\n } else {\n return (this.y - refrential.y) / (this.x - refrential.x);\n }\n }\n\n public double distance(Coordinate refrential) {\n return Math.sqrt(Math.pow(this.x - refrential.x, 2) + Math.pow(this.y - refrential.y, 2));\n }\n\n public Coordinate caluclateRatioDivison(Coordinate referential, double m, double n) {\n return new Coordinate((this.x * m + referential.x * n) / (m + n), (this.y * m + referential.y * n) / (m + n));\n }\n\n }\n\n public static void main(String[] args) throws IOException {\n ReadInputFromConsole rd = new ReadInputFromConsole();\n String str = rd.readNextToke();\n String[] arr = str.split(\"[\\\\s]\");\n\n Coordinate A = new Coordinate(Double.parseDouble(arr[0]), Double.parseDouble(arr[1]));\n str = rd.readNextToke();\n arr = str.split(\"[\\\\s]\");\n Coordinate B = new Coordinate(Double.parseDouble(arr[0]), Double.parseDouble(arr[1]));\n str = rd.readNextToke();\n arr = str.split(\"[\\\\s]\");\n Coordinate C = new Coordinate(Double.parseDouble(arr[0]), Double.parseDouble(arr[1]));\n\n // double smallestSide = Math.min(Math.min(A.distance(B), A.distance(C)), B.distance(C));\n// if(smallestSide>2*radius){\n// smallestSide=radius;\n// }\n// double numberOfSide=180/(Math.asin(smallestSide/(2*radius))*180/Math.PI);\n// System.out.println((smallestSide * Math.sqrt(4 * radius * radius - smallestSide * smallestSide) / 4)*numberOfSide);\n// \n double numberOfSide = 0;\n double a = B.distance(C);\n double b = A.distance(C);\n double c = B.distance(A);\n\n double semiPerimeter=(a+b+c)/2;\n double radius = (a*b*c)/(4*Math.sqrt(semiPerimeter*(semiPerimeter-a)*(semiPerimeter-b)*(semiPerimeter-c)));\n \n double angleA = Math.acos((b * b + c * c - a * a) / (2 * b * c));\n double angleB = Math.acos((a * a + c * c - b * b) / (2 * a * c));\n double angleC = Math.acos((b * b + a * a - c * c) / (2 * b * a));\n\n numberOfSide = Math.PI / (gcd(angleA, gcd(angleB, angleC)));\n numberOfSide = Math.ceil(numberOfSide);\n //area of polygon is given by A=0.5*n*radius^2*sin((2*PI)/n);\n System.out.println(0.5d * numberOfSide * radius * radius * Math.sin((Math.PI * 2) / numberOfSide));\n rd.releaseResource();\n }\n\n private static double gcd(double a, double b) {\n\n while (Math.abs(a) > gcdPrecison && Math.abs(b) > gcdPrecison) {\n if (a > b) {\n a = a - Math.floor(a / b) * b;\n } else {\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "26cd7e6c3bd8b52f781eb4563020610a", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.*;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\n\npublic class Warmup {\n //code written by a living bruh moment\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n int t = 1;\n for(int tt = 1; tt<=t; tt++) solver.solve(tt,in,out);\n out.close();\n }\n static class Task{\n\n public void solve(int tt, InputReader in, PrintWriter out){\n long a = in.nextLong();\n long b = in.nextLong();\n if(bb){\n long t=a;\n a=b;\n b=t;\n }\n\n long c=b-a;\n long ans=0;\n long ansv=b*a/gcd(a,b);\n // gcd a+k c\n if(ac){\n //\n long nk=a/c*c;\n if(a%c!=0) nk+=c;\n //\n long k=nk-a;\n long cur=((a+k)/c)*(b+k);\n if(cur 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\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\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\n\tpublic long pow(long x, long p) {\n\t\tif (p == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tlong t = pow(x, p / 2);\n\t\tt *= t;\n\t\tt %= mod;\n\t\tif (p % 2 == 1) {\n\t\t\tt *= x;\n\t\t\tt %= mod;\n\t\t}\n\t\treturn t;\n\t}\n\n\tpublic class Pair implements Comparable {\n\t\tlong x;\n\t\tlong y;\n\n\t\tpublic Pair(long x, long y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (x > o.x) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif (x < o.x) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (y > o.y) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif (y < o.y) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tlong mod = 1000000007;\n\t\n\tArrayList[] to;\n\tHashSet used = new HashSet<>();\n\t\n\tpublic void solve() {\n\t\tlong[] arr = {in.nextLong(), in.nextLong()};\n\t\tArrays.sort(arr);\n\t\tlong a = arr[0];\n\t\tlong b = arr[1];\n\t\tif (a == b) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong d = b - a;\n\t\tTreeSet ans = new TreeSet<>();\n\t\tfor (long i = 1; i * i <= d; i++) {\n\t\t\tif (d % i == 0) {\n\t\t\t\tlong k = (i - a % i) % i;\n\t\t\t\tans.add(new Pair((a + k) * (b + k) / gcd(a + k, b + k), k));\n//\t\t\t\tSystem.out.println(i + \" \" + (a + k) * (b + k) / gcd(a + k, b + k) + \" \" + k);\n\t\t\t\ti = d / i;\n\t\t\t\tk = (i - a % i) % i;\n\t\t\t\tans.add(new Pair((a + k) * (b + k) / gcd(a + k, b + k), k));\n//\t\t\t\tSystem.out.println(i + \" \" + (a + k) * (b + k) / gcd(a + k, b + k) + \" \" + k);\n\t\t\t\ti = d / i;\n\t\t\t}\n\t\t}\n\t\tout.println(ans.first().y);\n//\t\tlong t = System.currentTimeMillis();\n//\t\tlong min = a * b;\n//\t\tlong ans = 0;\n//\t\tlong k = 0;\n//\t\twhile (System.currentTimeMillis() - t < 700) {\n//\t\t\tlong minth = (a + k) * (b + k) / gcd(a + k, b + k);\n//\t\t\tif (minth < min) {\n//\t\t\t\tmin = minth;\n//\t\t\t\tans = k;\n//\t\t\t}\n//\t\t\tk++;\n//\t\t}\n//\t\tSystem.err.println(k);\n//\t\tout.println(ans);\n\t}\n\n\tprivate void dfs(int i) {\n\t\tused.add(i);\n\t\tfor (int j : to[i]) {\n\t\t\tif (!used.contains(j)) {\n\t\t\t\tdfs(j);\n\t\t\t}\n\t\t}\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 C().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4fae9bf666fe637438aba6a3d182d529", "src_uid": "414149fadebe25ab6097fc67663177c3", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*\n\npublic class main{\n static String text;\n static int length;\n static int jump;\n static int indexG;\n static int indexT;\n \n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n \n length = sc.nextInt();\n jump = sc.nextInt();\n sc.nextLine();\n text = sc.next();\n \n indexG = text.indexOf(\"G\");\n indexT = text.indexOf(\"T\");\n \n boolean answer = indexG < indexT ? right() : left();\n \n if(answer){\n System.out.println(\"YES\");\n }else{\n System.out.println(\"NO\");\n }\n }\n \n public static boolean right(){\n if((indexT - indexG) % jump != 0){\n return false;\n }\n if(!text.contains(\"#\")){\n return true;\n }\n \n int index = indexG;\n while(index < length){\n if(text.charAt(index) == '#'){\n return false;\n }else if(text.charAt(index) == 'T'){\n return true;\n }\n index += jump;\n }\n \n return false;\n }\n \n public static boolean left(){\n if((indexG - indexT) % jump != 0){\n return false;\n }\n if(!text.contains(\"#\")){\n return true;\n }\n \n int index = indexG;\n while(index >= 0){\n if(text.charAt(index) == '#'){\n return false;\n }else if(text.charAt(index) == 'T'){\n return true;\n }\n index -= jump;\n }\n return false;\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1ffd734c118df50c36a849460815baac", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0} {"lang": "Java 8", "source_code": " import java.util.*;\n\npublic class TestClass {\n public static void main(String args[] ) throws Exception {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int k=sc.nextInt();\n \n String s=sc.next();\n int obs=-1,T=-1,G=-1;\n int pos_t=-1,pos_g=-1;\n for(int i=0;ipos_t){\n if(i>pos_g&&ipos_t){\n \tflag_1=1;\n }\n }\n \n }\n if(flag_1==0){\n \t System.out.println(\"YES\");\n }\n else if(flag==1){\n System.out.println(\"NO\");\n }else{\n System.out.println(\"YES\");\n }\n \n \n \n }\n }\n }\n \n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c1e8dc2b3f1df6665be1dca6fb7e20a2", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.lang.Math;\n\npublic class Grasshopper{\npublic static void main(String[] args) {\n if solve() == true{\n Sytem.out.println(\"YES\"); \n } else {\n Sytem.out.println(\"NO\");\n }\n public boolean void solve(){\n \n Scanner sc = new Scanner(System.in);\n int length = sc.nextInt();\n int jump = sc.nextInt();\n String st = sc.next();\n int g = st.indexOf(\"G\") + 1;\n int t = st.indexOf(\"T\") + 1;\n if((Math.abs(g - t)) % jump != 0){\n return false;\n } else {\n if (g > t){\n for (int i = g; i >= t; i-=jump){\n if (st.charAt(i) == '#'){\n return false;\n } else if (st.charAt(i) == 'T'){\n return true;\n }\n }\n return false;\n } else {\n for (int i = g; i <= t; i+=jump){\n if (st.charAt(i) == '#'){\n return false;\n } else if (st.charAt(i) == 'T'){\n return true;\n }\n }\n return false;\n }\n }\n }\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec25359d1e5f9867fb419cfb36ab46cd", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Grasshopper {\n \n import java.util.Scanner;\n \n public String pathExists() {\n Scanner sc = new Scanner(System.in);\n int totalCells = sc.nextInt();\n int jumpLen = sc.nextInt();\n String path = sc.next();\n \n //get index of G and index of T\n int indexG = path.indexOf(\"G\");\n int indexT = path.indexOf(\"T\");\n \n if ((indexG - indexT) % jumpLen != 0) {\n return \"NO\";\n } \n \n //look for #'s\n int startInd = indexT > indexG ? indexG : indexT;\n int endInd = indexT > indexG ? indexT : indexG;\n for (int i = startInd; i < endInd; i = i + jumpLen) {\n if (path.charAt(i) == \"#\") {\n return \"NO\";\n }\n }\n\n return \"YES\";\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7878ad396d6cfd08c9fa1d91ef4f3812", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n/**\n * Timur\n * 20:55 18.04.2018\n */\npublic class cf {\n private static Scanner sc = new Scanner(System.in);\n\n private static int min(int a, int b) {\n return a > b ? b : a;\n }\n\n private static int min(int[] a) {\n int min = Integer.MAX_VALUE;\n for (int i : a) {\n min = min > i ? i : min;\n }\n return min;\n }\n\n private static int max(int a, int b) {\n return a > b ? a : b;\n }\n\n private static int max(int[] a) {\n int max = Integer.MIN_VALUE;\n for (int i : a) {\n max = max < i ? i : max;\n }\n return max;\n }\n\n private static void in(int[] a) {\n for (int i = 0; i < a.length; i++) {\n a[i] = sc.nextInt();\n }\n }\n\n private static void out(int[] a) {\n for (int i : a) {\n System.out.print(i + \" \");\n }\n System.out.println();\n }\n\n private static String dop(int a){\n String s=\"\";\n for(int i=0;i<5-String.valueOf(a).length();i++){\n s+='0';\n }\n s+=a;\n return s;\n }\n\n public static void main(String[] args) {\n String s = sc.next();\n int a = Integer.parseInt(s.charAt(0) + \"\" + s.charAt(2) + \"\" +\n s.charAt(4) + \"\" + s.charAt(3) + \"\" + s.charAt(1));\n long ans=a;\n for (int i = 0; i < 4; i++) {\n ans *= a;\n ans = ans % 100000;\n }\n System.out.println(dop(ans));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6bd0e57850c26c83475943843d42b692", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n // ab c de\n int a = n/10000;\n int b = n/1000 - a*10;\n int c = (n%1000)/100;\n int d = (n%100)/10;\n int e = n%10;\n int a1 = a;\n int b1 = c;\n int c1 = e;\n int d1 = d;\n int e1 = b;\n int n1 =a1*10000 + b1*1000 + c1*100 + d1*10 + e1;\n long z2 = (1L*n1*n1)%100000;\n long z3 = (z2*n1)%100000;\n long z4 = (z3*n1)%100000;\n long z5 = (z4*n1)%100000;\n for (int k=1;z5*k<10000;k*10){\n System.out.println(0);\n }\n System.out.println(z5);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c14703c6a5166a0ad0353993e299bedd", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n // ab c de\n int a = n/10000;\n int b = n/1000 - a*10;\n int c = (n%1000)/100;\n int d = (n%100)/10;\n int e = n%10;\n int a1 = a;\n int b1 = c;\n int c1 = e;\n int d1 = d;\n int e1 = b;\n int n1 =a1*10000 + b1*1000 + c1*100 + d1*10 + e1;\n long z2 = (1L*n1*n1)%100000;\n long z3 = (z2*n1)%100000;\n long z4 = (z3*n1)%100000;\n long z5 = (z4*n1)%100000;\n if (z5==0){\n System.out.println(00000);\n }else{\n for (int k=1;z5*k<10000;k*10){\n System.out.println(0);\n }\n }\n System.out.println(z5);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3d5b94a807f5c36b541280ff2ba6b33", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Code{\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int d1 = n / 10000;\n int d2 = n / 1000 % 10;\n int d3 = n / 100 % 10;\n int d4 = n / 10 % 10;\n int d5 = n % 10\n long p = d1*10000+d3*1000+d5*100+d4*10+d2;\n final int c = 100000;\n int r = (int)(p * p % c * p % c * p % c * p % c);\n int rd1 = r / 10000;\n int rd2 = r / 1000 % 10;\n int rd3 = r / 100 % 10;\n int rd4 = r / 10 % 10;\n int rd5 = r % 10;\n System.out.println(\"\" + rd1 + rd2 + rd3 + rd4 + rd5);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d41b353da522fb0fe28e154617699322", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Solution\n{\n Scanner sc=new Scanner(System.in);\n int[] coins={1,5,10,20,100};\n int amount=sc.nextInt();\n long[][] dp=new long[coins.length][amount+1];\n // Arrays.fill(dp,amount+1);\n for(int j=0;j<=amount;j++)\n {\n for(int i=0;iamount ? -1 : dp[coins.length-1][amount])\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4114c4e9e19685cadd9592d4a50f78e7", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Solution{\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st;\n static int[] arr = {100, 20, 10, 5, 1};\n static String next(){\n while(st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine().trim())\n \n }\n catch(Exception e){\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n static long nextLong(){\n return Long.parseLong(next());\n }\n \n public static void main(String argh[]){\n long num = 0, count = 0;\n num = nextLong();\n int i = 0;\n while(true){\n if(num > arr[i])\n {\n count++;\n num -= arr[i];\n }\n else if(num <= 0)break;\n else i ++;\n }\n \n System.out.println(count);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "06c61d9c553e2b2fc67899c8628a62c1", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class one {\n\tpublic static void main(String [] args) throws NumberFormatException{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint t = sc.nextInt();\n\t\tif(t == 1) {\n\t\t\tSystem.out.println(\"1\");\n\t\t}\n\t\tint arr[] = new int[4];\n\t\tarr[0] = 100;\n\t\tarr[1] = 20;\n\t\tarr[2] = 5;\n\t\tarr[3] = 1;\n\t\tint num = t,rem = 0;\n\t\tint i = 0,count = 0,j = 0;;\n\t\twhile(num > 0 && i < 4) {\n\t\t\tif(num >= arr[i] && j == 0\t) {\n\t\t\t\trem = num % arr[i];\n\t\t\t\tnum /= arr[i];\n\t\t\t\tcount += num;\n\t\t\t\tj++;\n\t\t\t}\n\t\t\telse if(j > 0 && rem >= arr[i]) {\n\t\t\t\tnum = rem / arr[i];\n\t\t\t\trem = rem % arr[i];\n\t\t\t\tcount += num;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c4ee9e30a423b837f47994630171ff77", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\npublic class Main{\n public static void main(String args[]) throws Exception\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long n = Long.parseLong(br.readLine().trim().split(\"\\\\s+\"));\n System.out.println(dp_lottery(n));\n }\n public static long dp_lottery(long n)\n {\n long count=0;\n while(n!=0)\n {\n if(n>=100)\n {\n n=n-100;\n count++;\n }\n else if(n>=20)\n {\n n=n-20;\n count++;\n }\n else if(n>=10)\n {\n n=n-10;\n count++;\n }\n else if(n>=5)\n {\n n=n-5;\n count++;\n }\n else\n {\n n=n-1;\n count++;\n }\n }\n return count;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5595fc72edf46f17a581377e3215b8c5", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Code_7luogu\u4e09\u89d2\u5f62CF6A {\n\tstatic boolean[] vis = new boolean[4];\n\tstatic String str = \"\";\n\tstatic int[] flag = new int[3];\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint[] res = new int[4];\n\t\tfor(int i = 0; i < 4; i++) {\n\t\t\tres[i] = scan.nextInt();\n\t\t}\n\t\tfor(int i = 0; i < 4; i++) {\n\t\t\tfor(int j = 0; j < 4 && j != i; j++) {\n\t\t\t\tfor(int k = 0; k < 4 && k != i && k != j; k++) {\n\t\t\t\t\tif(res[i]+res[j]>res[k]&&res[i]+res[k]>res[j]&&res[k]+res[j]>res[i]) {\n\t\t\t\t\t\tSystem.out.println(\"TRIANGLE\");\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\tfor(int i = 0; i < 4; i++) {\n\t\t\tfor(int j = 0; j < 4 && j != i; j++) {\n\t\t\t\tfor(int k = 0; j < 4 && k != i && k != j; k++) {\n\t\t\t\t\tif(res[i]+res[j]>=res[k]&&res[i]+res[k]>=res[j]&&res[k]+res[j]>=res[i]) {\n\t\t\t\t\t\tSystem.out.println(\"SEGMENT\");\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\tSystem.out.println(\"IMPOSSIBLE\");\n//\t\tfor(int i = 0; i < 4; i++) {\n//\t\t\tres[i] = scan.nextInt();\n//\t\t}\n//\t\tfor(int i = 0; i < 4; i++) {\n//\t\t\tvis[i] = true;\n//\t\t\tif(flag[0] > 0) {\n//\t\t\t\tSystem.out.println(\"TRIANGLE\");\n//\t\t\t\tSystem.exit(0);\n//\t\t\t}\n//\t\t\tdfs(i, res);\n//\t\t\tvis[i] = false;\n//\t\t}\n//\t\tif(flag[0] > 0) {\n//\t\t\tSystem.out.println(\"TRIANGLE\");\n//\t\t\tSystem.exit(0);\n//\t\t}else if(flag[0] ==0 && flag[1] > 0) {\n//\t\t\tSystem.out.println(\"SEGMENT\");\n//\t\t\tSystem.exit(0);\n//\t\t}else {\n//\t\t\tSystem.out.println(\"IMPOSSIBLE\");\n//\t\t\tSystem.exit(0);\n//\t\t}\n\t\tscan.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4ea8361c661e8ea35ca11563447ef6e7", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String [] args){\n Scanner sca = new Scanner (System.in);\n int [] a = new int [5];\n int [] pd = new int [5];\n int [] c = new int [3];\n int t=0;\n for(int i=1;i<5;i++){\n a[i] = sca.nextInt();\n }\n dfs(a , 1 , pd , c , o);\n if(t==1){\n System.out.println(\"TRIANGLE\");\n }else if(t==2){\n System.out.println(\"SEGMENT\");\n }else{\n System.out.println(\"IMPOSSIBLE\");\n }\n }\n }\n //\u7ed3\u679c\u5224\u65ad\n //0\u4e3a\u7b2c\u4e00\u79cd\u60c5\u51b5\n //1,2 , int t){\n //\u622a\u6b62\u6761\u4ef6\n static void dfs(int []a , int index , int []pd , int []c,int o)\n if(index == 4){\n if(c[0]+c[1]>c[2]&&c[1]+c[2]>c[0]&&>c[0]+c[2]>c[1]){\n t=1;\n }else if(c[0]+c[1]>=c[2]&&c[1]+c[2]>=c[0]&&>c[0]+c[2]>=c[1]&&t!=1){\n t=2;\n }\n }\n \n for(int i=1;i<5;i++){\n int k = a[i];\n if(pd[i]==0){\n pd[i]=1;\n c[o] = k;\n dfs(a,index+1,pd,c,o+1)\n pd[i]=0;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "93383953e49105d6950bf20e9fd59af3", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class 6A_Triangle{\n public static void main(String args[]){\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4ee2a0be30d3d1b223adde2f70412410", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Main{\n public static void main (String[] args){\n Scanner sc=new Scanner(System.in);\n ArrayList a=new ArrayList<>();\n a.add(sc.nextInt());\n a.add(sc.nextInt());\n a.add(sc.nextInt());\n a.add(sc.nextInt());\n Collections.sort(a);\n String res;\n if (a.get(3)>a.get(2)+a.get(1))\n \tif (a.get(2)>a.get(1)+a.get(0))\n \t\tSystem.out.prinlnt(\"IMPOSSIBLE\");\n \telse\n \t\tif (a.get(2)==a.get(1)+a.get(0))\n \t\t\tSystem.out.println(\"SEGMENT\");\n \t\telse\n \t\t\tSystem.out.println(\"TRIANGLE\");\n else\n \tif(a.get(3)==a.get(2)+a.get(1))\n \t\tif(a.get(2)>a.get(1)+a.get(0))\n \t\t\tSystem.out.println(\"SEGMENT\");\n \t\telse\n \t\t\tSystem.out.println(\"TRIANGLE\");\n \telse\n \t\tSystem.out.println(\"TRIANGLE\");\n \n \n \n}}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7f68927bbaa47c25cba999985781ada0", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.lang.*;\n\npublic class A {\n public static void main(String[] args) throws Exception {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw=new PrintWriter(System.out);\n String s=br.readLine();\n String t=br.readLine();\n int si=0,ti=0;\n int ma=0,ct=0;\n while(si 20) return;\n// count++;\n// out.pp(tIdx, sIdx, prevSIdx);\n if (tIdx >= t.length() && sIdx >= s.length()) {\n ans = max(ans, best, s.length() - prevSIdx);\n }\n if (sIdx >= s.length()) return;\n\n // skip\n solve(best, prevSIdx, tIdx, sIdx + 1, t, s);\n // add\n if (tIdx < t.length() && s.charAt(sIdx) == t.charAt(tIdx)) {\n best = max(best, sIdx - prevSIdx);\n solve(best, sIdx + 1, tIdx + 1, sIdx + 1, t, s);\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[] 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) { for(long e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(int[] arr) { for(int e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(char[] arr) { for(char e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(double[] arr) { for(double e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(T[] arr) { for(T e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(long[][] arr) { for (long[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(int[][] arr) { for (int[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(char[][] arr) { for (char[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(double[][] arr) { for (double[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(T[][] arr) { for (T[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public FastWriter println(Object object) { out.append(object).append(\"\\n\"); return this; }\n public void toFile(String fileName) throws IOException {\n BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));\n writer.write(out.toString());\n writer.close();\n }\n public void close() throws IOException { System.out.print(out); }\n}\nstatic class FastScanner {\n private InputStream sin = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int buflen = 0;\n public FastScanner(){}\n public FastScanner(String filename) throws FileNotFoundException {\n File file = new File(filename);\n sin = new FileInputStream(file);\n }\n private boolean hasNextByte() {\n if (ptr < buflen) {\n return true;\n }else{\n ptr = 0;\n try {\n buflen = sin.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (buflen <= 0) {\n return false;\n }\n }\n return true;\n }\n private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while(isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n public long longNext() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b) || b == ':'){\n return minus ? -n : n;\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n public int intNext() {\n long nl = longNext();\n if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();\n return (int) nl;\n }\n public double doubleNext() { return Double.parseDouble(next());}\n public long[] nextLongArray(final int n){\n final long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = longNext();\n return a;\n }\n public int[] nextIntArray(final int n){\n final int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = intNext();\n return a;\n }\n public double[] nextDoubleArray(final int n){\n final double[] a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = doubleNext();\n return a;\n }\n public ArrayList[] getAdj(int n) {\n ArrayList[] adj = new ArrayList[n + 1];\n for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();\n return adj;\n }\n public ArrayList[] adjacencyList(int nodes, int edges) throws IOException {\n return adjacencyList(nodes, edges, false);\n }\n public ArrayList[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {\n adj = getAdj(nodes);\n for (int i = 0; i < edges; i++) {\n int a = intNext(), b = intNext();\n adj[a].add(b);\n if (!isDirected) adj[b].add(a);\n }\n return adj;\n }\n}\nstatic class u {\n public static int upperBound(long[] array, long obj) {\n int l = 0, r = array.length - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj < array[c]) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int upperBound(ArrayList array, long obj) {\n int l = 0, r = array.size() - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj < array.get(c)) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int lowerBound(long[] array, long obj) {\n int l = 0, r = array.length - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj <= array[c]) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int lowerBound(ArrayList array, long obj) {\n int l = 0, r = array.size() - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj <= array.get(c)) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n static T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }\n static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }\n static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }\n private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }\n private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }\n private static void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }\n private static void customSort(int[][] arr) {\n Arrays.sort(arr, new Comparator() {\n public int compare(int[] a, int[] b) {\n if (a[0] == b[0]) return Integer.compare(a[1], b[1]);\n return Integer.compare(a[0], b[0]);\n }\n });\n }\n public static int[] swap(int[] arr, int left, int right) {\n int temp = arr[left];\n arr[left] = arr[right];\n arr[right] = temp;\n return arr;\n }\n public static int[] reverse(int[] arr, int left, int right) {\n while (left < right) {\n int temp = arr[left];\n arr[left++] = arr[right];\n arr[right--] = temp;\n }\n return arr;\n }\n public static boolean findNextPermutation(int[] data) {\n if (data.length <= 1) return false;\n int last = data.length - 2;\n while (last >= 0) {\n if (data[last] < data[last + 1]) break;\n last--;\n }\n if (last < 0) return false;\n int nextGreater = data.length - 1;\n for (int i = data.length - 1; i > last; i--) {\n if (data[i] > data[last]) {\n nextGreater = i;\n break;\n }\n }\n data = swap(data, nextGreater, last);\n data = reverse(data, last + 1, data.length - 1);\n return true;\n }\n public static int biSearch(int[] dt, int target){\n int left=0, right=dt.length-1;\n int mid=-1;\n while(left<=right){\n mid = (right+left)/2;\n if(dt[mid] == target) return mid;\n if(dt[mid] < target) left=mid+1;\n else right=mid-1;\n }\n return -1;\n }\n public static int biSearchMax(long[] dt, long target){\n int left=-1, right=dt.length;\n int mid=-1;\n\n while((right-left)>1){\n mid = left + (right-left)/2;\n if(dt[mid] <= target) left=mid;\n else right=mid;\n }\n return left;\n }\n public static int biSearchMaxAL(ArrayList dt, long target){\n int left=-1, right=dt.size();\n int mid=-1;\n\n while((right-left)>1){\n mid = left + (right-left)/2;\n if(dt.get(mid) <= target) left=mid;\n else right=mid;\n }\n return left;\n }\n private static void fill(T[][] ob, T res){for(int i=0;ivoid fill(T[][][] ob,T res){for(int i=0;i0; i--){ ans*=i; }\n return ans;\n }\n private static long facMod(int n, long mod) {\n long ans=1;\n for(long i=n; i>0; i--) ans = (ans * i) % mod;\n return ans;\n }\n private static long lcm(long m, long n){\n long ans = m/gcd(m,n);\n ans *= n;\n return ans;\n }\n private static long gcd(long m, long n) {\n if(m < n) return gcd(n, m);\n if(n == 0) return m;\n return gcd(n, m % n);\n }\n private static boolean isPrime(long a){\n if(a==1) return false;\n for(int i=2; i<=Math.sqrt(a); i++){ if(a%i == 0) return false; }\n return true;\n }\n static long modInverse(long a, long mod) {\n /* Fermat's little theorem: a^(MOD-1) => 1\n Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */\n return binpowMod(a, mod - 2, mod);\n }\n static long binpowMod(long a, long b, long mod) {\n long res = 1;\n while (b > 0) {\n if (b % 2 == 1) res = (res * a) % mod;\n a = (a * a) % mod;\n b /= 2;\n }\n return res;\n }\n private static int getDigit2(long num){\n long cf = 1; int d=0;\n while(num >= cf){ d++; cf = 1<= cf){ d++; cf*=10; }\n return d;\n }\n private static boolean isInArea(int y, int x, int h, int w){\n if(y<0) return false;\n if(x<0) return false;\n if(y>=h) return false;\n if(x>=w) return false;\n return true;\n }\n private static ArrayList generatePrimes(int n) {\n int[] lp = new int[n + 1];\n ArrayList pr = new ArrayList<>();\n for (int i = 2; i <= n; ++i) {\n if (lp[i] == 0) {\n lp[i] = i;\n pr.add(i);\n }\n for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {\n lp[i * pr.get(j)] = pr.get(j);\n }\n }\n return pr;\n }\n static long nPrMod(int n, int r, long MOD) {\n long res = 1;\n for (int i = (n - r + 1); i <= n; i++) {\n res = (res * i) % MOD;\n }\n return res;\n }\n static long nCr(int n, int r) {\n if (r > (n - r))\n r = n - r;\n long ans = 1;\n for (int i = 1; i <= r; i++) {\n ans *= n;\n ans /= i;\n n--;\n }\n return ans;\n }\n static long nCrMod(int n, int r, long MOD) {\n long rFactorial = nPrMod(r, r, MOD);\n long first = nPrMod(n, r, MOD);\n long second = binpowMod(rFactorial, MOD-2, MOD);\n return (first * second) % MOD;\n }\n static void printBitRepr(int n) {\n StringBuilder res = new StringBuilder();\n for (int i = 0; i < 32; i++) {\n int mask = (1 << i);\n res.append((mask & n) == 0 ? \"0\" : \"1\");\n }\n out.println(res);\n }\n static String bitString(int n) {return Integer.toString(n);}\n static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed\n static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }\n static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }\n static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }\n static HashMap counts(String word) {\n HashMap counts = new HashMap<>();\n for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);\n return counts;\n }\n static HashMap counts(int[] arr) {\n HashMap counts = new HashMap<>();\n for (int value : arr) counts.merge(value, 1, Integer::sum);\n return counts;\n }\n static HashMap counts(long[] arr) {\n HashMap counts = new HashMap<>();\n for (long l : arr) counts.merge(l, 1, Integer::sum);\n return counts;\n }\n static HashMap counts(char[] arr) {\n HashMap counts = new HashMap<>();\n for (char c : arr) counts.merge(c, 1, Integer::sum);\n return counts;\n }\n static long hash(int x, int y) {\n return x* 1_000_000_000L +y;\n }\n}\nstatic class Tuple implements Comparable {\n long a;\n long b;\n long c;\n public Tuple(long a, long b) {\n this.a = a;\n this.b = b;\n this.c = 0;\n }\n public Tuple(long a, long b, long c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n public long getA() { return a; }\n public long getB() { return b; }\n public long getC() { return c; }\n public int compareTo(Tuple other) {\n if (this.a == other.a) {\n if (this.b == other.b) return Long.compare(this.c, other.c);\n return Long.compare(this.b, other.b);\n }\n return Long.compare(this.a, other.a);\n }\n @Override\n public int hashCode() { return Arrays.deepHashCode(new Long[]{a, b, c}); }\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Tuple)) return false;\n Tuple pairo = (Tuple) o;\n return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);\n }\n @Override\n public String toString() { return String.format(\"(%d %d %d) \", this.a, this.b, this.c); }\n}\nprivate static int abs(int a){ return (a>=0) ? a: -a; }\nprivate static int min(int... ins){ int min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }\nprivate static long abs(long a){ return (a>=0) ? a: -a; }\nprivate static long min(long... ins){ long min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }\nprivate static double abs(double a){ return (a>=0) ? a: -a; }\nprivate static double min(double... ins){ double min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "037f244fcfa2643dc1925598948e5c0e", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Solution1 {\n\tstatic int num;\n\tpublic static void main(String[]args) \n\t{\n\t\t\tScanner sc=new Scanner(System.in);\n\t\t\t\tString s=sc.next();\n\t\t\t\tString t=sc.next();\n\t\t\t\t\n\t\t\t int[][]dp=new int[s.length()+1][t.length()+1];\n\t\t\t \n\t\t\t for(int i=0;i=1 && j>=1)\n\t\t\t\t\t {\n\t\t\t\t\t\t if(s.charAt(i-1)==t.charAt(j-1))\n\t\t\t\t\t\t {\n\t\t\t\t\t\t\t dp[i][j]=1+dp[i-1][j-1];\n\t\t\t\t\t\t }\n\t\t\t\t\t\t else\n\t\t\t\t\t\t {\n\t\t\t\t\t\t\t dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);\n\t\t\t\t\t\t }\n\t\t\t\t\t }\n\t\t\t\t\t //System.out.print(dp[i][j]+\" \");\n\t\t\t\t }\n\t\t\t\t //System.out.println();\n\t\t\t }\n\t\t\t num=0;\n\t\t\t GenerateNumbers(s,t,dp,dp.length-1,dp[0].length-1,\"\");\n\t\t\t \n\t\t\t System.out.println(Math.max(0,num));\n\t\t\t\n\t}\n\tprivate static void GenerateNumbers(String a, String b, int[][]dp,int i, int j,String x)\n\t{\n\t\tif(i==0 && x.length()==b.length())\n\t\t{\n\t\t\t//System.out.println(x);\n\t\t\tfor(int k=0;k b){\n if(b % 2 != 0)\n b--;\n else{\n\n }\n }\n else{\n if(b % 2 != 0) {\n mas[0] = true;\n a--;\n }\n else{\n b--;\n }\n }\n int i = 1;\n while(a > 0 || b > 0){\n if(i % 2 == 1){ // V\n if(mas[i-1]){\n if(b > 0)\n b--;\n else{\n mas[i] = true;\n a--;\n }\n }\n else{\n if(a > 0){\n mas[i] = true;\n a--;\n }\n else\n b--;\n }\n }\n else{ // P\n if(mas[i-1]){\n if(a > 0){\n mas[i] = true;\n a--;\n }\n else\n b--;\n }\n else{\n if(b > 0)\n b--;\n else{\n mas[i] = true;\n a--;\n }\n }\n }\n i++;\n }\n\n\n int maxOd=0;\n int maxRaz=0;\n int current=0;\n boolean raznie = true;\n for (int j = 0; j < mas.length-1; j++) {\n if(mas[j] == mas[j+1]){\n if(raznie) {\n maxRaz+= current;\n current = 0;\n }\n current++;\n raznie = false;\n }\n else{\n if(!raznie) {\n maxOd += current;\n current = 0;\n }\n current++;\n raznie = true;\n }\n // System.out.print(mas[j]);\n // System.out.print(\" \");\n }\n // System.out.println(mas[mas.length-1]);\n\n if(!raznie)\n maxOd+=current;\n else\n maxRaz+=current;\n\n out.print(maxOd);\n out.print(\" \");\n out.print(maxRaz);\n }\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 PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(in, out);\n out.flush();\n }\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bc4553f1814a7bc82ef78a2ab511cb2e", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Euler {\n\t\n\t\n\tpublic static void main(String[] args){\n\t\t\n\t\tFastReader in = new FastReader();\n\t\tPrintWriter o = new PrintWriter(System.out);\n\t\t//long startTime = System.nanoTime();\n\t\t\n\t\t\n\t\t int N = in.nextInt();\n\t\t int[] arr = new int[N];\n\t\t for (int i = 0; i < N; i++) arr[i] = in.nextInt();\n\t\t \n\t\t int[] F = new int[N + 1];\n\t\t \n\t\t for (int i = 0; i < N; i++) {\n\t\t \n\t\t F[arr[i]]++;\n\t\t System.out.println(arr[i]);\n\t\t int len = N - i - 1;\n\t\t \n\t\t for (int l = 1; l <= len; l++) {\n\t\t \n\t\t for (int k = i + 1; k <= N - len; k++) {\n\t\t TreeMap map = new TreeMap<>();\n\t\t map.put(arr[i], 1);\n\t\t System.out.print(arr[i] + \" \");\n\t\t for (int j = k; j < k + len; j++) {\n\t\t System.out.print(arr[j] + \" \");\n\t\t int c = map.getOrDefault(arr[j],0);\n\t\t map.put(arr[j], c + 1);\n\t\t \n\t\t }\n\t\t System.out.println();\n\t\t \n\t\t int max = Integer.MIN_VALUE;\n\t\t int ans = 0;\n\t\t for (int x : map.keySet()) {\n\t\t \n\t\t if (max < map.get(x)) {\n\t\t max = map.get(x);\n\t\t ans = x;\n\t\t }\n\t\t \n\t\t }\n\t\t F[ans]++;\n\t\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 for (int i = 1; i <= N; i++) {\n\t\t // System.out.print(F[i] + \" \");\n\t\t }\n\t\t System.out.println();\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t//long endTime = System.nanoTime();\n\t\t//o.println(\"Execution Time : +\" + (endTime - startTime) / 1000000 + \" ms\");\n\t\to.flush();\n\t\to.close();\n\t\treturn;\n\t\t\n\t}\n\t\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aac9c1a7af0c7a8eaca1751cca50162c", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "package Ladder13;\n\nimport java.util.Scanner;\n\npublic class CF257B {\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 String str1 = \"R\";\n n--;\n int i = 1;\n int k = n+1;\n int k1 = m-1;\n int petya = 0;\n int vasya = 0;\n if(n+1 == m){\n System.out.println(n + \" \" + m);\n }\n// else {\n// while (n > 0 && m > 0) {\n// if (i % 2 == 0) {\n// petya++;\n// if (str1.charAt(i - 1) == 'R') {\n// str1 = str1 + 'R';\n// n--;\n// } else {\n// str1 = str1 + 'B';\n// m--;\n// }\n// } else {\n// vasya++;\n// if (str1.charAt(i - 1) == 'R') {\n// str1 = str1 + 'B';\n// m--;\n// } else {\n// str1 = str1 + 'R';\n// n--;\n// }\n// }\n//\n// i++;\n// }\n//\n// while (n > 0) {\n// if (str1.charAt(i - 1) == 'R') {\n// petya++;\n// } else {\n// vasya++;\n// }\n// str1 += 'R';\n// i++;\n// n--;\n// }\n//\n// while (m > 0) {\n// if (str1.charAt(i - 1) == 'B') {\n// petya++;\n// } else {\n// vasya++;\n// }\n// str1 += 'B';\n// i++;\n// m--;\n// }\n//\n// i = 1;\n// int petya1 = 0;\n// int vasya1 = 0;\n// while (k > 0 && k1 > 0) {\n// if (i % 2 == 0) {\n// petya1++;\n// if (str1.charAt(i - 1) == 'R') {\n// str1 = str1 + 'R';\n// k--;\n// } else {\n// str1 = str1 + 'B';\n// k1--;\n// }\n// } else {\n// vasya1++;\n// if (str1.charAt(i - 1) == 'R') {\n// str1 = str1 + 'B';\n// k1--;\n// } else {\n// str1 = str1 + 'R';\n// k--;\n// }\n// }\n// i++;\n// }\n//\n// while (k > 0) {\n// if (str1.charAt(i - 1) == 'R') {\n// petya1++;\n// } else {\n// vasya1++;\n// }\n// str1 += 'R';\n// i++;\n// k--;\n// }\n//\n// while (k1 > 0) {\n// if (str1.charAt(i - 1) == 'B') {\n// petya1++;\n// } else {\n// vasya1++;\n// }\n// str1 += 'B';\n// i++;\n// k1--;\n// }\n//\n// if (petya > petya1) {\n// System.out.println(petya + \" \" + vasya);\n// } else {\n// if (vasya > vasya1) {\n// System.out.println(petya1 + \" \" + vasya1);\n// } else {\n// System.out.println(petya + \" \" + vasya);\n// }\n// }\n// }\n if(n+1 > m){\n System.out.println(n+ \" \" + m);\n }else{\n System.out.println(m-1 + \" \" + n+1 );\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "760e52f9bfe18f7aa3263d3f6b389def", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n=sc.nextInt(),m=sc.nextInt();\n System.out.print((Math.max(n,m)-1)+\" \"+Math.min(n,m));\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "031e27b61feed9688785e481d71acaf2", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class InnaPinkPony {\n public static void main(String[] args) {\n Scanner Sc = new Scanner(System.in);\n int n,m,i,j,a,b;\n n = Sc.nextInt();\n m = Sc.nextInt();\n i = Sc.nextInt();\n j = Sc.nextInt();\n a = Sc.nextInt();\n b = Sc.nextInt();\n //Winning Position = (1,m),(n,1),(n,m),(1,1)\n int count = 0;\n int x,y;\n x = i;\n y = j;\n if()\n while( x != n){\n if(x+a <= n){\n x+=a;\n }\n else if(x-a > 0){\n x -= a;\n }\n else{\n break;\n }\n count ++;\n }\n int count1=0;\n while( y != m){\n if(y+a <= m){\n y+=a;\n }\n else if(y-a >0){\n y -= a;\n }\n else{\n break;\n }\n count1 ++;\n }\n if(count1 == count){\n System.out.println(count);\n }\n else{\n System.out.println(\"Poor Inna and pony!\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a1b4dcb01162f00df711680b162270bb", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class CF2{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint i = sc.nextInt();\n\t\tint j = sc.nextInt();\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint min = Integer.MAX_VALUE;\n\t\t//points are (1,1),(n,1),(1,m),(n,m)\n\t\t//both odd or even\n\t\t//completely divisible\n\t\tint[] x = new int[]{1,n,1,n};\n\t\tint[] y = new int[]{1,1,m,m};\n\t\tfor(int k = 0; k < 4; k++){\n\t\t int p = Math.abs(x[i]-i);\n\t\t int q = Math.abs(y[i]-j);\n\t\t if((p%a==0 && q%b==0)&&(((p/a)%2==0 && (q/b)%2==0)||((p/a)%2==1 && (q/b)%2==1))){\n\t\t int ans = Math.max(p/a,q/b);\n\t\t if(ans unvisited = new PriorityQueue<>();\n List visited = new ArrayList<>();\n CodeForce18a.Pair start = matrix[i][j];\n matrix[i][j].distance=0;\n unvisited.add(start);\n\n while (!unvisited.isEmpty()) {\n CodeForce18a.Pair curr = unvisited.remove();\n List neigh = curr.getNeighbours();\n for (CodeForce18a.Pair node : neigh) {\n if (visited.contains(node)) {\n node = visited.get(visited.indexOf(node));\n node.distance = Math.min(node.distance,\n curr.distance + 1);\n } else {\n node.distance = curr.distance + 1;\n unvisited.add(node);\n }\n }\n visited.add(curr);\n }\n\n int min = Math.min(matrix[1][1].distance, Math.min(matrix[n][m].distance,\n Math.min(matrix[1][m].distance, matrix[n][1].distance)));\n if (min != Integer.MAX_VALUE) {\n System.out.println(min);\n } else {\n System.out.println(\"Poor Inna and pony!\");\n }\n }\n\n public static class Pair implements Comparable {\n\n int r, c;\n int distance=Integer.MAX_VALUE;\n\n public Pair(int r, int c) {\n this.r = r;\n this.c = c;\n }\n\n public List getNeighbours() {\n List list = new ArrayList<>();\n\n if (r + a <= CodeForce18a.n && c + b <= CodeForce18a.m) {\n list.add(matrix[r + a][c+b]);\n }\n if (r - a >= 0 && c - b >= 0) {\n list.add(matrix[r - a][c - b]);\n }\n if (r + a <= n && c - b >= 0) {\n list.add(matrix[r + a][c - b]);\n }\n if (r - a >= 0 && c + b <= m) {\n list.add(matrix[r - a][c + b]);\n }\n return list;\n }\n\n @Override\n public int compareTo(Pair t) {\n return distance-t.distance; \n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "09a7165309f725ef8e88cf63f1a8b915", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author mark\n */\npublic class InnaPony {\n\n public static void main(String[] args) throws FileNotFoundException {\n FileInputStream file = new FileInputStream(new File(\"/home/mark/tmp/input.txt\"));\n Scanner scan = new Scanner(file);\n //Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int m = scan.nextInt();\n int i = scan.nextInt();\n int j =scan.nextInt();\n int a =scan.nextInt();\n int b=scan.nextInt();\n \n\n int c1= getMin(1,1,a,b,i,j);\n int c2=getMin(1,m,a,b,i,j);\n int c3=getMin(n,m,a,b,i,j);\n int c4=getMin(n,1,a,b,i,j);\n \n int min = Math.min(c1,Math.min(c2,Math.min(c3, c4)));\n if (min==Integer.MAX_VALUE){\n System.out.println(\"Poor Inna and pony!\");\n }else{\n System.out.println(min);\n }\n }\n\n private static int getMin(int x, int y, int a, int b, int i, int j){\n int rm=-1;\n int cm=-1;\n int res=Integer.MAX_VALUE;\n\n if (Math.abs(x-i)%a==0){\n rm=Math.abs(x-i)/a;\n } \n \n if (Math.abs(y-j)%b==0){\n cm=Math.abs(y-j)/b;\n } \n \n if (rm!=-1 && cm!=-1 && cm==rm){\n res=rm;\n }else if (rm>0 && cm>0 && cm%2==rm%2){\n res=Math.max(rm,cm);\n }\n return res;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d8018e8cc6409fc3a70ced9fdb0905c1", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "mport java.io.*;\nimport java.util.Scanner;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n int n = sc.nextInt();\n int x = (n/10 + 4);\n if (n <= x) return false;\n else return true;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5bee59103608f53b6bb1ed59ece6b3aa", "src_uid": "821529a4644b74483bcdf80fc318d1f8", "difficulty": null} {"lang": "Java 8", "source_code": "import com.sun.deploy.util.ArrayUtil;\n\nimport java.lang.reflect.Array;\nimport java.util.*;\n\n/*\n User: Ayushi\n Time: 16:24\n Date: 01 Apr 2019\n Website: Codeforces\n Problem: B\n*/\n\npublic class B {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n scan.close();\n\n String[] z = \"1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91\".split(\", \");\n if (Arrays.asList(z).contains(String.valueOf(n+1)) || Arrays.asList(z).contains(String.valueOf(n-1))) {\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7d989f3e73342f669f8bccc313cc074b", "src_uid": "821529a4644b74483bcdf80fc318d1f8", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class Main {\n\tpublic static void main(String[] args){\n\t Scanner scan = new Scanner(System.in);\n\t int t = scan.nextInt();\n\t if(t%10 == 1 || t%10 == 7 ||t%10 == 9 || t == 10 || (t > 12 && t < 30) ||t > 69 && t < 80) ||(t > 89)){\n\t System.out.println(\"NO\");\n\t }\n\t else{\n\t System.out.println(\"YES\");\n\t }\n\t \n\t }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aaf1303d893153031524252e1f4d4845", "src_uid": "821529a4644b74483bcdf80fc318d1f8", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class KanbanNumbers {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n Map mapa = new HashMap<>();\n mapa.put(1, \"one\");\n mapa.put(2, \"two\");\n mapa.put(3, \"three\");\n mapa.put(4, \"four\");\n mapa.put(5, \"five\");\n mapa.put(6, \"six\");\n mapa.put(7, \"seven\");\n mapa.put(8, \"eight\");\n\n if(n==10 || n==70 || n==90) System.out.println(\"NO\");\n if(n==12) System.out.println(\"YES\");\n if(n<10){\n if(mapa.get(n).contains(\"n\")){\n System.out.println(\"NO\");\n }else{\n System.out.println(\"YES\");\n }\n }\n if((n>29 && n < 70) || (n>=80 && n<90)){\n if(mapa.get(n%10).contains(\"n\")){\n System.out.println(\"NO\");\n }else{\n System.out.println(\"YES\");\n }\n }\n if((n>10 && n<=29 && n!=12) || (n>=70 && n< 80) || n>90){\n System.out.println(\"NO\");\n }\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66a0970aeb960551043a7d0b01a6b787", "src_uid": "821529a4644b74483bcdf80fc318d1f8", "difficulty": null} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Permutations {\n\tpublic static int result = Integer.MAX_VALUE;\n\t\n\tpublic static void main (String[] args) {\n\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint a = 0;\n\t\tString[] list = new String[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlist[i] = sc.nextLine();\t\n\t\t}\n\t\tint[] track = new int[m];\n\t\tboolean[] check = new boolean[m];\n\t\trecurse(a, track, check, list, n, m);\n\t\tSystem.out.println(result);\n\t}\n\t\n\tpublic static void recurse(int a, int[] track, boolean[] check, String[] list, int n, int m, int result) {\n\t\tif (m == a) {\n\t\t\tint max = 0; \n\t\t\tint min = Integer.MAX_VALUE;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tString str = \"\";\n\t\t\t\tString finish = list[i];\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tstr += finish.charAt(track[j]);\t\n\t\t\t\t}\n\t\t\t\tint look = Integer.parseInt(str);\n\t\t\t\tif (min > look) {\n\t\t\t\t\tmin = look;\n\t\t\t\t}\n\t\t\t\tif (max < look) {\n\t\t\t\t\tmax = look;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\t\t}\n\t\t\tif (result > max-min) {\n\t\t\t\tresult = max-min;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tif (!check[i]) {\n\t\t\t\tcheck[i] = true;\n\t\t\t\ttrack[a] = i;\n\t\t\t\trecurse(a+1, track, check, list, n, m, result);\n\t\t\t\tcheck[i] = false;\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "694bd4f7e8e18f30d409e7f9bb1cac99", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Permutations {\n public static int n;\n public static int k;\n public static String[] a;\n public static int[] p;\n public static boolean[] b;\n public static int gmin = Integer.MAX_VALUE;\n public static void main(String[] args) throws IOException {\n \tScanner sc = new Scanner(System.in);\n\n n = sc.nextInt();\n k = sc.nextInt();\n a = new String[n];\n for (int i = 0; i < n; i++)\n a[i] = sc.next();\n \n p = new int[k];\n b = new boolean[k];\n f(0);\n System.out.println(gmin);\n }\n \n public static void f(int m) {\n if (m == k) {\n int min = Integer.MAX_VALUE;\n int max = 0;\n for (int i = 0; i < n; i++) {\n String str = a[i];\n String s = \"\";\n for (int j = 0; j < k; j++)\n s += str.charAt(p[j]);\n int x = Integer.parseInt(s);\n if (x < min)\n min = x;\n if (x > max)\n max = x;\n }\n if (max-min < gmin)\n gmin = max-min;\n }\n \n for (int i = 0; i < k; i++)\n if (!b[i]) {\n p[m] = i;\n b[i] = true;\n f(m+1);\n b[i] = false;\n }\n \n }\n}d", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8dad94eb04430c01aea90ee3b689b0b5", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport org.apache.commons.io.IOUtils;\n\npublic class Permutations {\n public static void main(String[]args) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n int k = input.nextInt();\n int[] arr = IOUtils.readIntArray(input, n);\n System.out.println(Arrays.toString(arr));\n int dif = Integer.MAX_VALUE;\n List> perms = perms(k);\n for(List i : perms) {\n System.out.println(i);\n int[] arrTwo = new int[n];\n for(int j = 0; j < n; j++) {\n arrTwo[j] = mix(i, arr[j], k);\n }\n int min = minArray(arrTwo);\n int max = maxAbsArray(arrTwo);\n dif = Math.min(dif, max-min);\n }\n System.out.println(perms.size());\n System.out.println(dif);\n }\n\n public static int minArray(int[] arr) {\n int min = Integer.MAX_VALUE;\n for(int i = 0; i < arr.length; i++) \n min = Math.min(arr[i], min);\n return min;\n }\n\n public static int maxAbsArray(int[] arr) {\n int max = Integer.MIN_VALUE;\n for(int i = 0; i < arr.length; i++) \n max = Math.max(Math.abs(arr[i]), max);\n return max;\n }\n\n public static int mix(List perms, int n, int k) {\n String s = n+\"\";\n if(s.length() < k) {\n for(int i = 0; i < k-1; i++) {\n s = \"0\"+s;\n }\n }\n if(n==0) {\n s+=\"0\";\n }\n String res = \"\";\n for(int i = 0; i < perms.size(); i++) {\n res += \"\"+s.charAt(perms.get(i)-1);\n }\n System.out.println(res);\n return Integer.parseInt(res);\n }\n\n public static List> perms(int num) {\n List> res = new ArrayList<>();\n if(num == 1) {\n res.add(new ArrayList());\n res.get(0).add(1);\n return res;\n } else {\n List> r = perms(num-1);\n for(List l : r) {\n for(int i = 0; i < num; i++) {\n List r2 = new ArrayList<>();\n for(int j : l) {\n r2.add(j);\n }\n r2.add(i, num);\n res.add(r2);\n }\n }\n return res;\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b0c737185edd8a41b7ab319c8eb4cad", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.InputMismatchException;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author lpeter83\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 int ans = 1 << 30;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n int k = in.readInt();\n int[][] a = new int[n][k];\n int[] order = new int[k];\n for (int i = 0; i < k; i++) {\n order[i] = i;\n }\n String[] b = new String[n];\n for (int i = 0; i < n; i++) {\n b[i] = in.next();\n }\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < k; j++) {\n a[i][j] = b[i].charAt(j) - '0';\n }\n }\n doit(a, k, order);\n out.printLine(ans);\n }\n\n private void doit(int[][] a, int cur, int[] order) {\n if (cur == 0) return;\n for (int i = 0; i < cur; i++) {\n int t = order[cur-1];\n order[cur-1] = order[i];\n order[i] = t;\n int[] num = new int[a.length];\n for (int j = 0; j < a.length; j++) {\n String s = \"\";\n for (int j2 = 0; j2 < a[0].length; j2++) {\n s += a[j][order[j2]];\n }\n num[j] = Integer.parseInt(s);\n }\n int max = -1, min = 1 << 30;\n for (int j = 0; j < a.length; j++) {\n max = Math.max(max, num[j]);\n min = Math.min(min, num[j]);\n }\n ans = Math.min(ans, max - min);\n doit(a, cur - 1, order);\n t = order[cur-1];\n order[cur-1] = order[i];\n order[i] = t;\n }\n doit(a, cur - 1, order);\n }\n}\n\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return readString();\n }\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(outputStream);\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00933e41b18e0ae129bd1d3b18e35939", "src_uid": "08f85cd4ffbd135f0b630235209273a4", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Gift\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n long arr[]=new long[n];\n long sum=0;\n int d=0;\n for(int i=0;i1&&d!=n||(d==n&&n%2==0)\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "51511f5389a262fb3b32fb8d749df7f4", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class 248A{\n public static void main(String[] args){\n int count1=0;\n int count2=0;\n int num=sc.nextInt();\n for(int i=0;i=0;i--){\n if(tb>ta){\n ta+=aa[i];\n } \n else{\n tb+=aa[i];\n }\n }\n\n if(ta!=tb){\n System.out.println(\"NO\");\n }\n else{\n System.out.println(\"YES\");\n }\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8ee041e963b9afd532b888aec153fa15", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class GFG {\n\tpublic static void main (String[] args) {\n\t System.out.print(\"No\");\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6978b66bc86ac9ed67434bdc8072bfd6", "src_uid": "b6a30a725754a4b4daeb6e87986e28a4", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n \npublic class GFG{\n \n public static void main (String[] args) { \n //System.out.println(\"GfG!\");\n Scanner sc=new Scanner(System.in);\n \n //int t=sc.nextInt();\n \n }\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1385f189019817d6b91fd0112e77aeca", "src_uid": "b6a30a725754a4b4daeb6e87986e28a4", "difficulty": null} {"lang": "Java 11", "source_code": "public class Main()\n{\n public static void main(String args[])\n {\n System.out.println(\"Is it rated\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc70e2c7a82d82981f5cfb96aba580b7", "src_uid": "b6a30a725754a4b4daeb6e87986e28a4", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.Scanner\npublic class Main {\n public static void main(String args[]) {\n Scanner scn=new Scanner(System.in);\n String t=scn.next();\n System.out.println(\"standard output\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "49ed7b193d6190781b1075b3856f6539", "src_uid": "b6a30a725754a4b4daeb6e87986e28a4", "difficulty": null} {"lang": "Java 8", "source_code": "//package ;\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n\tstatic int n,q,dp[][][];\n\tstatic Pair p[];\n\tstatic int dp(int i,int r,int miss)\n\t{\n\t\tif(r==n || i==q)\n\t\t{\n\t\t\tif(i<=q-2 || miss==2)\n\t\t\t\treturn 0;\n\t\t\treturn -(int)(1e4);\n\t\t}\n\t\tif(dp[i][r][miss]!=-1)//check again\n\t\t\treturn dp[i][r][miss];\n\t\t\n\t\tint ans=p[i].r-p[i].l+1;\n\t\tint dif=r-p[i].l+1;\n\t\t\n\t\tif(dif>0)\n\t\t\tans-=dif;\n//\t\tSystem.out.println(ans);\n\t\tans=Math.max(ans, 0);\n\t\tint take=dp(i+1,Math.max(r, p[i].r),miss)+ans;\n\t\tint leave=0;\n\t\t\n\t\tif(miss<2)\n\t\t\tleave=dp(i+1,r,miss+1);\n\t\t\n\t\treturn dp[i][r][miss]=Math.max(take, leave);\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tn=sc.nextInt();q=sc.nextInt();\n\t\tdp=new int[q][n][3];\n\t\tp=new Pair[q];\n\t\tfor(int i=0;i\n\t{\n\t\tint l,r;\n\t\tpublic Pair(int left,int right) {\n\t\t\t// TODO Auto-generated constructor stub\n\t\t\tl=left;r=right;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn l==o.l?r-o.r:l-o.l;\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn l+\" \"+r;\n\t\t}\n\t}\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\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\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\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tboolean hasnext() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic Integer[] nextIntegerArray(int n) throws IOException {\n\t\t\tInteger[] a = new Integer[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\tchar[] nextCharArray() throws IOException {\n\t\t\treturn br.readLine().toCharArray();\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int n) throws IOException {\n\t\t\tdouble[] ans = new double[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tans[i] = nextDouble();\n\t\t\treturn ans;\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "df9e350c502584a3aecddf7abbf6527c", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class HelloWorld{\n \n static class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n private SpaceCharFilter filter;\n \n InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n int snext() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n int nextInt() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n long nextLong() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n String readString() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n String nextLine() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n 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 boolean isSpaceChar(int ch);\n }\n }\n\n public static void main(String []args){\n \n InputReader sc = new InputReader(System.in);\n \n int n = sc.nextInt();\n \n String str = sc.readString();\n str = reduce(str);\n n = str.length();\n \n int dp[][] = new int[n][n];\n \n for(int len=0; lenr)\n\t\t\treturn 0;\n\t\tif(memo[cnt][l][r]!=0)\n\t\t\treturn memo[cnt][l][r];\n\t\t\t\n\t\tint ans=1+dp(l+1,r,1);\n\t\tfor(int i=l+1;i<=r;i++)\n\t\t\tif(s[i]==s[l])\n\t\t\t{\n\t\t\t\tans=Math.min(ans, dp(l+1,i-1,1)+dp(i,r,cnt+1));\n\t\t\t}\n\t\treturn memo[cnt][l][r]=ans;\n\t\t\n\t}\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\ts=sc.next().toCharArray();\n\t\tmemo=new int [n+1][n][n];\n\t\tout.println(dp(0, n-1, 1));\n\t\t\n\t\t\n\t\tout.close();\n\n\t}\n\tstatic class Scanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tScanner(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tScanner(String fileName) throws FileNotFoundException{\n\t\t\tbr=new BufferedReader(new FileReader(fileName));\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\treturn st.nextToken();\n\t\t}\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\t\tint nextInt() throws IOException{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe953e1135b5d643efaf248af3e0c507", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A\n{\n\n\tstatic StringBuilder st = new StringBuilder();\n\t\n\tstatic int [][][] memo ;\n\tstatic char [] s ; \n\t\n\tstatic int dp(int l , int r , int cnt)\n\t{\n\t\tif(l > r) return 0 ; \n\t\t\n\t\tif(memo[l][r][cnt] != -1)return memo[l][r][cnt] ; \n\t\t\n\t\tint ans = dp(l + 1, r, 0) + 1 ;\n\t\t\n\t\tfor(int i = l + 1 ; i <= r ; i++)\n\t\t\tif(s[l] == s[i])\n\t\t\t\tans = Math.min(ans, dp(l + 1, i - 1, 0) + dp(i , r , cnt + 1 ));\n\t\t\n\t\treturn memo[l][r][cnt] = ans ; \n\t}\n\t\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tScanner sc = new Scanner(System.in) ; \n\t\tPrintWriter out = new PrintWriter(System.out) ; \n\t\t\n\t\t\n\t\tint n = sc.nextInt() ; \n\t\ts = sc.next().toCharArray() ; \n\t\tmemo = new int [500][500][500] ; \n\t\t\n\t\tfor(int i = 0 ; i< 500 ; i++)\n\t\t\tfor(int j = 0 ; j < 500 ; j++)\n\t\t\t\tArrays.fill(memo[i][j], -1);\n\t\t\n\t\tout.println(dp(0, n - 1, 0));\n\t\tout.flush();\n\t\tout.close(); \n\t}\n\n\tstatic class Scanner \n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(InputStream in) \n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() throws Exception \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() throws Exception { return Integer.parseInt(next()); }\n\n\t\tlong nextLong() throws Exception { return Long.parseLong(next()); }\n\n\t\tdouble nextDouble() throws Exception { return Double.parseDouble(next());}\n\n\t}\n\n\tstatic void shuffle(int[] a) \n\t{\n\t\tint n = a.length;\n\t\tfor (int i = 0; i < n; i++) \n\t\t{\n\t\t\tint r = i + (int) (Math.random() * (n - i));\n\t\t\tint tmp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = tmp;\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1ef8d99adb164a6abb01da57f20944bc", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*\n\npublic class Solution {\n\n int n, m;\n\n Solution(int n, int m) {\n if (n <= m) {\n this.n = n;\n this.m = m;\n } else {\n this.n = m;\n this.m = n;\n }\n }\n\n int kth(int k) {\n int lo = 1, hi = n * m;\n while (lo <= hi) {\n int mid = (lo + hi) >>> 1;\n int num = num(mid);\n if (k > num)\n lo = mid + 1;\n else if (k < num)\n hi = mid - 1;\n else\n return floor(mid);\n }\n return floor(lo);\n }\n\n int num(int v) {\n int k = 0, n = this.n, m = this.m;\n for (int i = 1; i <= n; i++) {\n if (k == (k += Math.min(v / i, m)))\n break;\n }\n return k;\n }\n\n int floor(int v) {\n while (v > 1) {\n for (int i = n; i > 0; i--) {\n if (v / i > m)\n break;\n if (v % i == 0)\n return v;\n }\n v--;\n }\n return 1;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n System.out.println(new Solution(sc.nextInt(), sc.nextInt()).kth(sc.nextInt()));\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a79a0d2b9e8b08c7fb33455821ea230", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static void main(String args[]) {\n \tScanner in = new Scanner(System.in);\n \tint n=in.nextInt(), m=in.nextInt(), k=in.nextLong();\n \tlong start=1, end=(long)(25*1e10), ans=start, l=start, r=end;\n \twhile(l<=r) {\n \t\tlong mid=(l+r)/2;\n \t\tif(numSmaller(n, m, mid)0&&(arr[(a-1)/2][0]>arr[a][0]||(arr[(a-1)/2][0]==arr[a][0]&&arr[(a-1)/2][1]>arr[a][1]))){\n\t\t\tswap(arr,(a-1)/2,a);\n\t\t\ta = (a-1)/2;\n\t\t}\n\t}\n\tpublic void Minheapify(int a){\n\t\tint largest = a;\n\t\tif(2*a+1arr[2*a+1][0]||(arr[largest][0]==arr[2*a+1][0]&&arr[largest][1]>arr[2*a+1][1])))\n\t\t\tlargest = 2*a+1;\n\t\tif(2*a+2arr[2*a+2][0]||(arr[largest][0]==arr[2*a+2][0]&&arr[largest][1]>arr[2*a+2][1])))\n\t\t\tlargest = 2*a+2;\n\t\tif(largest!=a){\n\t\t\tswap(arr,a,largest);\n\t\t\tMinheapify(largest);\n\t\t}\n\t}\n\tpublic void insert(long a,long y){\n\t\tarr[num++][0] = a;\n\t\tarr[num-1][1] = y;\n\t\tMinheap(num-1);\n\t}\n\tpublic void deleteAtIndex(int a){\n\t\tlong pi = arr[a][0];\n\t\tlong i = arr[a][1];\n\t\tarr[a][0] = arr[num-1][0];\n\t\tarr[a][1] = arr[num-1][1];\n\t\tnum--;\n\t\tif(arr[a][0]>pi||(arr[a][0]==pi&&arr[a][1]>i))\n\t\t\tMinheapify(a);\n\t\telse\n\t\t\tMinheap(a);\n\t}\n\tpublic long getMin(){\n\t\tlong pi = arr[0][0];\n\t\tdi = arr[0][1];\n\t\tdeleteAtIndex(0);\n\t\treturn pi;\n\t}\n\tpublic long getIndex(){\n\t\treturn di;\n\t}\n}\n\npublic class TestClass {\n\n\tprivate static InputStream stream;\n\tprivate static byte[] buf = new byte[1024];\n\tprivate static int curChar;\n\tprivate static int numChars;\n\tprivate static SpaceCharFilter filter;\n\tprivate static PrintWriter pw;\n\tprivate static void soln() {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint k = nextInt();\n\t\tHeap h = new Heap(n);\n\t\tfor(int i=0;i= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tprivate static int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate static long nextLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate static String nextToken() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate static String nextLine() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate static int[] nextIntArray(int n) {\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = nextInt();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate static long[] nextLongArray(int n) {\n\t\tlong[] arr = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = nextLong();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate static void pArray(int[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate static void pArray(long[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate static boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tprivate interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "566d1b3a10079b4b05ddaca19f386f5f", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\npublic class Multiplication {\n public static void main(String args[]) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long n,m,k;\n\n StringTokenizer st = new StringTokenizer(br.readLine());\n n=Long.parseLong(st.nextToken());\n m=Long.parseLong(st.nextToken());\n k=Long.parseLong(st.nextToken());\n long low=1;\n long high=n*m;\n\n System.out.println(solve(low, high, n, m,k));\n\n }\n private static long solve(long low, long high, long n, long m, long k) {\n long mid =0;\n if (low == high)\n \treturn low;\n else if (k < 2) {\n \treturn k;\n }\n else if (high==k) {\n \treturn k;\n }\n else if (high > k && n > k && m> k ) {\n \thigh =k+1;\n }\n\n\t while(low +1 < high){\n\t mid = low + ((high-low) / 2);\n\t long[] hmid=f(mid,n,m);\n\t long fmid=hmid[0];\n\n\t long gmid=hmid[1];\n\n\t //System.out.println(\"Before mid \"+ mid +\" low \"+low+\" high \"+high+\" fmid \"+ fmid+ \" k \"+k+ \" gmid \"+gmid);\n\n\t if(fmid < k && k<= fmid + gmid) {\n\t \t//System.out.println(\"hello2\");\n\t \treturn mid;\n\t }\n\t else if (fmid == 0) {\n\t \tlow= low+1;\n\t\t hmid=f(low-1,n,m);\n\t\t fmid=hmid[0];\n\n\t\t gmid=hmid[1];\n \t\t //System.out.println(\"Low mid \"+ mid +\" low \"+low+\" high \"+high+\" fmid \"+ fmid+ \" k \"+k+ \" gmid \"+gmid);\n\n\t \tif(fmid < k && k<= fmid + gmid) {\n\t \t\t\n\t\t \t//System.out.println(\"hello2\");\n\t\t \treturn low-1;\n\t\t }\t\n\t\t hmid=f(low,n,m);\n\t\t fmid=hmid[0];\n\n\t\t gmid=hmid[1];\n\t\t //System.out.println(\"Low mid \"+ mid +\" low \"+low+\" high \"+high+\" fmid \"+ fmid+ \" k \"+k+ \" gmid \"+gmid);\n\n\t \tif(fmid < k && k<= fmid + gmid) {\n\t \t\t\n\t\t \t//System.out.println(\"hello2\");\n\t\t \treturn low;\n\t\t }\t \t\n\t }\n\t else if(fmid+gmidr2)\n\t\t\tSystem.out.println(0);\n\t\telse{\n\t\t\tif(l2>=l1&&l2<=r1&&r2>r1){\n\t\t\t\tif(k>=l2&&k<=r1)\n\t\t\t\t\tSystem.out.println(r1-l2);\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(r1-l2+1);\n\t\t\t}\n\t\t\telse if(l2>=l1&&l2<=r1&&r2<=r1){\n\t\t\t\tif(k>=l2&&k<=r2)\n\t\t\t\t\tSystem.out.println(r2-l2);\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(r2-l2+1);\n\t\t\t}\n\t\t\telse if(l2<=l1&&r1<=r2){\n\t\t\t\tif(k>=l1&&k<=r1)\n\t\t\t\t\tSystem.out.println(r1-l1);\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(r1-l1+1);\n\t\t\t}\n\t\t\telse if{\n\t\t\t\tif(k>=l1&&k<=r2)\n\t\t\t\t\tSystem.out.println(r2-l1);\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(r2-l1+1);\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec8ef83faf3ad3fb8fa7a131ace72c00", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class MeetingOfOldFriends \n{\n public static void main(String args[]) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n PrintWriter pw;\n pw = new PrintWriter(System.out);\n \n \n StringTokenizer str = new StringTokenizer(br.readLine());\n \n long l1 = Long.parseLong(str.nextToken());\n long r1 = Long.parseLong(str.nextToken());\n long l2 = Long.parseLong(str.nextToken());\n long r2 = Long.parseLong(str.nextToken());\n long k = Long.parseLong(str.nextToken());\n long time;\n \n \n long left = Math.max(l1,l2);\n \n long right = Math.min(r2, r1);\n \n if(right>=left)\n time = right-left+1;\n \n \n \n if((k >= l2 && k <= r1) && time!=0) \n {\n time--;\n }\n \n pw.println(time);\n \n \n pw.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "940b8101fc5a78b95d359112ba5abdcb", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Properties;\nimport java.util.StringTokenizer;\n\nimport javax.jms.BytesMessage;\nimport javax.jms.JMSException;\nimport javax.jms.Queue;\nimport javax.jms.QueueConnectionFactory;\nimport javax.jms.QueueSender;\nimport javax.jms.QueueSession;\nimport javax.naming.Context;\nimport javax.naming.InitialContext;\nimport javax.naming.NamingException;\n\npublic class Main {\n\n\tstatic class Reader {\n\t\tBufferedReader r;\n\t\tStringTokenizer str;\n\n\t\tReader() {\n\t\t\tr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tReader(String fileName) throws FileNotFoundException {\n\t\t\tr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tpublic String getLine() throws IOException {\n\t\t\treturn r.readLine();\n\t\t}\n\n\t\tpublic String getNextToken() throws IOException {\n\t\t\tif (str == null || !str.hasMoreTokens()) {\n\t\t\t\tstr = new StringTokenizer(r.readLine());\n\t\t\t}\n\t\t\treturn str.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(getNextToken());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(getNextToken());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(getNextToken());\n\t\t}\n\n\t\tpublic String nextString() throws IOException {\n\t\t\treturn getNextToken();\n\t\t}\n\n\t\tpublic int[] intArray(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\n\t\t\treturn a;\n\n\t\t}\n\n\t\tpublic long[] longArray(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\n\t\t\treturn a;\n\n\t\t}\n\n\t\tpublic String[] stringArray(int n) throws IOException {\n\t\t\tString a[] = new String[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextString();\n\n\t\t\treturn a;\n\n\t\t}\n\n\t\tpublic long gcd(long a, long b) {\n\t\t\tif (b == 0) {\n\t\t\t\treturn a;\n\t\t\t}\n\t\t\treturn gcd(b, a % b);\n\t\t}\n\t}\n\n\n\tpublic static void main(String[] args) throws IOException, NamingException, JMSException {\n\n\t\tReader r=new Reader();\nlong l1=r.nextLong();\nlong r1=r.nextLong();\nlong l2=r.nextLong();\nlong r2=r.nextLong();\nlong k=r.nextLong();\nlong start =0,end=0;\nif(l2<=l1)\n{\n\tstart=l1;\n}\nelse if(l2>l1&&l2<=r1)\n{\n\tstart=l2;\n}\nelse if(l2>r1)\n{\n\tstart=r1;\n}\n\t\t\n\nif(r2=l1&&r2<=r1)\n{\n\tend=r2;\n}\nelse {\n\tend=r1;\n}\n\nlong result=end-start+1;\nif(k>=start&&k<=end)\n{\n\tresult--;\n}\n\nSystem.out.println(result);\n\n\t}\n\t\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0801be87ce45121e6f241577d6aa6b57", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class Main {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\t@SuppressWarnings(\"resource\")\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tlong l1, r1, l2, r2, k, x, y;\t\t\n\t\t\n\t\tl1 = scan.nextLong();\n\t\tr1 = scan.nextLong();\n\t\tl2 = scan.nextLong();\n\t\tr2= scan.nextLong();\n\t\tk = scan.nextLong();\n\t\tx = (long) Math.max(l1, l2);\n\t\ty = (long) Math.min(r1, r2);\n\t\t\n\t\tif(x <= k && y >= k){\n\t\t\tSystem.out.println(y - x);\n\t\t}\n\t\telse if (x <= y){\n\t\t\tSystem.out.println(y-x+1);\t\t\t\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(0);\t\t\t\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9d0949b67b55e686da18aaef457f56b9", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\n\npublic class BusStop {\n\n /**\n * @param args\n */\n public static int count(ArrayList x){\n int count=0;\n for(int i=0 ; i x = new ArrayList(); \n for(int i=0; im) throw new Exception();\nc++;\nint r = g[i];\nwhile(i+1m) break;\ni++;\n}\n}\nSystem.out.println(c);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2cb24609eefde76effa5150d1f40567e", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\npackage sp5;\nimport static java.lang.System.out;\nimport java.util.Scanner;\n/**\n *\n * @author \u0410\u043b\u0435\u043a\u0441\u0435\u0439\u043a\u0430\n */\npublic class sp5 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int a = in.nextInt();\n int massBass = in.nextInt();\n int[] b = new int[101];\n int counter = 0;\n int temp = 0;\n int var = 0;\n for(int i = 0; i < a; i++){\n b[i] = in.nextInt();\n }\n for(int i = 0; i =0){\n maxDigit[fromIndex]=Math.max(digits[fromIndex], maxDigit[fromIndex+1]);\n fromIndex--;\n }\n }\n\n private void solveInternal() {\n while(true){\n if(digitCount==1){\n if(digits[0]!=0){\n result.incrementAndGet();\n }\n return;\n }\n substractMax();\n result.incrementAndGet();\n }\n\n }\n\n private void substractMax() {\n int i=0;\n digits[i]-=maxDigit[0];\n if(maxDigit[0]==0){\n throw new IllegalStateException();\n }\n while(digits[i]<0){\n digits[i]+=10;\n digits[i+1]--;\n i++;\n }\n if(i==digitCount-1 && digits[digitCount-1]==0){\n digitCount--;\n i--;\n }\n \n updateMaxDigit(i);\n \n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8df22d8efddc5ffc95ecaed8ace6e1c1", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class NTM {\n \n public static int highestDigit(int n) {\n String s = \"\"+n;\n int h=0;\n for(int i = 0 ; i < s.length(); ++i) {\n if(s.charAt(i)>h) h = Integer.parseInt(s.charAt(i)+\"\");\n }\n return h;\n }\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nexInt();\n int i = 0;\n for(;n!=0;++i) {\n n-=highestDigit(n);\n }\n System.out.println(n);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "970cf553633d1b374067e623e04c38cc", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class TheGreatJulyaCalendar_331C1 {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int num = in.nextInt();\n int num = (int)num/10;\n int ans = num == 0 ? 0 : num * 2 + 1;\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f16cb31884ecd3d411a8800e36289b83", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\nimport java.io.*;\n\n\npublic class mm{\n\n\tstatic Long find(String s)\n\t{\n\t\tif(s.length()==1 && s.charAt(0)=='0')\n\t\t\treturn 0;\n\t\tif(s.length()==1)\n\t\t\treturn 1l;\nint max = 0;\n\t\tfor(int i=0;i 0) {\r\n solve();\r\n }\r\n pw.close();\r\n }\r\n\r\n public long mod = 1_000_000_007;\r\n\r\n\r\n public void solve() {\r\n int n = sc.nextInt(), k = sc.nextInt();\r\n for (int i = 0; i < k; i++) ans = (ans * n) % mod;\r\n pw.println(ans);\r\n }\r\n\r\n\r\n class FastScanner {\r\n private BufferedReader reader = null;\r\n private StringTokenizer tokenizer = null;\r\n\r\n public FastScanner(BufferedReader bf) {\r\n reader = bf;\r\n tokenizer = null;\r\n }\r\n\r\n public String next() {\r\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\r\n try {\r\n tokenizer = new StringTokenizer(reader.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 String nextLine() {\r\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\r\n try {\r\n return reader.readLine();\r\n } catch (IOException e) {\r\n throw new RuntimeException(e);\r\n }\r\n }\r\n return tokenizer.nextToken(\"\\n\");\r\n }\r\n\r\n public long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n public int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n public float nextFloat() {\r\n return Float.parseFloat(next());\r\n }\r\n\r\n public int[] nextIntArray(int n) {\r\n int[] a = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n return a;\r\n }\r\n\r\n public String[] nextStringArray(int n) {\r\n String[] a = new String[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = next();\r\n }\r\n return a;\r\n }\r\n\r\n public long[] nextLongArray(int n) {\r\n long[] a = new long[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = nextLong();\r\n }\r\n return a;\r\n }\r\n\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "45ecd3445b939c9bcbc3a0922380dac6", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\n\r\nimport jdk.internal.net.http.common.Log;\r\n\r\nimport java.io.*;\r\nimport java.lang.*;\r\n\r\npublic class B {\r\n public static void main(String[] args) {\r\n Scanner s = new Scanner(System.in);\r\n int t = s.nextInt();\r\n while (t > 0) {\r\n t--;\r\n int n = s.nextInt();\r\n int k = s.nextInt();\r\n long ans = 1;\r\n long base = n;\r\n long MOD = 1000000007;\r\n while (k != 0) {\r\n if ((k & 1) == 1)\r\n ans = ans * base % MOD;\r\n base = base * base % MOD;\r\n k >>= 1;\r\n }\r\n System.out.println(ans);\r\n }\r\n s.close();\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cbe3e104a7466d2d5153e416878ec006", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n//import java.math.BigInteger;\r\nimport java.util.*;\r\n\r\npublic class SUm0 {\r\n public static void main(String[] args) {\r\n handmadeInput.FastReader in = new handmadeInput.FastReader();\r\n int t = in.nextInt();\r\n StringBuilder s = new StringBuilder();\r\n while (t-- > 0) {\r\n int n = in.nextInt();\r\n int k = in.nextInt();\r\n int mod = 1000000007;\r\n int ans = 1;\r\n BigInteger bigInteger = new BigInteger(\"1\");\r\n for (int i = 1; i <= k; i++) {\r\n bigInteger = bigInteger.multiply(new BigInteger(String.valueOf(n)));\r\n }\r\n bigInteger = bigInteger.mod(new BigInteger(String.valueOf(mod)));\r\n s.append(bigInteger).append(\" \");\r\n }\r\n System.out.println(s);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n// Additional Classes go here\r\n\r\n\r\n\r\nclass handmadeInput {\r\n static class FastReader {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n public FastReader() {\r\n br = new BufferedReader(new\r\n InputStreamReader(System.in));\r\n }\r\n\r\n String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine() {\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n }\r\n}\r\n\r\nclass UtilityFunctions {\r\n //! returns gcd of given numbers\r\n public int gcd(int a, int b)\r\n {\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b);\r\n }\r\n\r\n public int primeFactors(int n) {\r\n HashMap hashMap = new HashMap<>(n);\r\n int c = 0;\r\n\r\n // Print the number of 2s that divide n\r\n while (n % 2 == 0) {\r\n// if (hashMap.containsKey(2)) {\r\n// hashMap.replace(2, hashMap.get(2) + 1);\r\n// } else {\r\n// hashMap.put(2, 1);\r\n// }\r\n c++;\r\n n /= 2;\r\n }\r\n\r\n // n must be odd at this point. So we can\r\n // skip one element (Note i = i +2)\r\n for (int i = 3; i <= Math.sqrt(n); i += 2) {\r\n // While i divides n, print i and divide n\r\n while (n % i == 0) {\r\n //System.out.print(i + \" \");\r\n\r\n// if (hashMap.containsKey(i)) {\r\n// hashMap.replace(i, hashMap.get(i) + 1);\r\n// } else {\r\n// hashMap.put(i, 1);\r\n// }\r\n c++;\r\n n /= i;\r\n }\r\n }\r\n\r\n // This condition is to handle the case whien\r\n // n is a prime number greater than 2\r\n if (n > 2) {\r\n\r\n// if (hashMap.containsKey(n)) {\r\n// hashMap.replace(n, hashMap.get(n) + 1);\r\n// } else {\r\n// hashMap.put(n, 1);\r\n// }\r\n c++;\r\n }\r\n\r\n //System.out.print(n);\r\n return c;\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65b7ee2db699bed42a2b37fbe5a1226f", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "// Working program with FastReader \r\nimport java.io.BufferedReader; \r\nimport java.io.IOException; \r\nimport java.io.InputStreamReader; \r\nimport java.util.*;\r\npublic class ll\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 int findIndex(long arr[], long t) \r\n { \r\n\r\n // if array is Null \r\n if (arr == null) { \r\n return -1; \r\n } \r\n\r\n // find length of array \r\n int len = arr.length; \r\n int i = 0; \r\n\r\n // traverse in the array \r\n while (i < len) { \r\n\r\n // if the i-th element is t \r\n // then return the index \r\n if (arr[i] == t) { \r\n return i; \r\n } \r\n else { \r\n i = i + 1; \r\n } \r\n } \r\n return -1; \r\n }\r\n\r\n static int gcd(int a, int b)\r\n {\r\n if (a == 0)\r\n return b; \r\n return gcd(b % a, a); \r\n }\r\n\r\n // method to return LCM of two numbers\r\n static int lcm(int a, int b)\r\n {\r\n return (a / gcd(a, b)) * b;\r\n }\r\n public static int[] swap(int a[], int left, int right)\r\n {\r\n \r\n // Swap the data\r\n int temp = a[left];\r\n a[left] = a[right];\r\n a[right] = temp;\r\n \r\n // Return the updated array\r\n return a;\r\n }\r\n public static int[] reverse(int a[], int left, int right)\r\n {\r\n \r\n // Reverse the sub-array\r\n while (left < right) {\r\n int temp = a[left];\r\n a[left++] = a[right];\r\n a[right--] = temp;\r\n }\r\n \r\n // Return the updated array\r\n return a;\r\n }\r\n public static int[] findNextPermutation(int a[])\r\n {\r\n int last = a.length - 2;\r\n \r\n // find the longest non-increasing suffix\r\n // and find the pivot\r\n while (last >= 0) {\r\n if (a[last] < a[last + 1]) {\r\n break;\r\n }\r\n last--;\r\n }\r\n \r\n // If there is no increasing pair\r\n // there is no higher order permutation\r\n if (last < 0)\r\n return a;\r\n \r\n int nextGreater = a.length - 1;\r\n \r\n // Find the rightmost successor to the pivot\r\n for (int i = a.length - 1; i > last; i--) {\r\n if (a[i] > a[last]) {\r\n nextGreater = i;\r\n break;\r\n }\r\n }\r\n \r\n // Swap the successor and the pivot\r\n a = swap(a, nextGreater, last);\r\n \r\n // Reverse the suffix\r\n a = reverse(a, last + 1, a.length - 1);\r\n \r\n // Return true as the next_permutation is done\r\n return a;\r\n }\r\n static int factorial(int n)\r\n {\r\n return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);\r\n }\r\n public static void main(String[] args) \r\n {\r\n FastReader d=new FastReader();\r\n int t,i,j,c,z,k,l,n;\r\n int mod = (int) 1e9 + 7;\r\n \r\n \r\n int Inf=Integer.MAX_VALUE;\r\n int negInf=Integer.MIN_VALUE;\r\n t=d.nextInt();\r\n //t=1;\r\n //String s;\r\n //char ch,ch1,ch2,ch3;\r\n while(t-->0)\r\n {\r\n z=c=0;\r\n long nn=d.nextLong();\r\n long kk=d.nextLong();\r\n //int a[]=new int[n];\r\n //for(i=0;i inputSupplier = () -> System.in;\n static Supplier outSupplier = () -> new PrintWriter(System.out);\n\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(inputSupplier.get());\n PrintWriter out = outSupplier.get();\n int n = sc.nextInt();\n int arr[] = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextInt();\n }\n int ret = 0;\n for (int i = 1; i < n; i++) {\n int prev = arr[i-1];\n int curr = arr[i];\n if ((prev == 2 && curr == 3) || (prev == 3 && curr == 2)) {\n ret = -1;\n break;\n }\n if ((prev == 1 && curr == 2) || (prev == 2 && curr == 1)) {\n ret += 3;\n } else {\n ret+=4;\n }\n }\n if (ret == -1) {\n out.println(\"Infinite\");\n } else {\n out.println(\"Finite\");\n out.println(ret);\n }\n sc.close();\n out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ccb43725ee3e830297ec54da0e710b1a", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args)throws IOException{\n Scanner s=new Scanner(new File(\"Monty\"));\n int x=s.nextInt();\n int y=s.nextInt();\n int[]a=new int[y];\n \n for (int i = 0; i < a.length; i++) {\n a[i]=s.nextInt();\n }\n \n java.util.Arrays.sort(a);\n \n int min=Integer.MAX_VALUE;\n int i=0;\n do{\n min=Math.min(min,a[i+x-1]-a[i]);\n i++;\n }while(i+x<=a.length);\n System.out.println(min);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5dc859109d546840645740a55e36da1e", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String[] args1 = sc.nextLine().split(\" \");\n String[] args2 = sc.nextLine().split(\" \");\n int students = Integer.valueOf(args1[0])-1;\n int puzzlesavailable = Integer.valueOf(args1[1]);\n Arrays.sort(args2);\n int currentmin = args2[args2.length-1];\n if (!args2[0].equals(args2[args2.length-1])) {\n for (int i = 0; i < puzzlesavailable - students; i++) {\n if (Math.abs(Integer.valueOf(args2[i + students]) - Integer.valueOf(args2[i])) < currentmin) {\n currentmin = (Integer.valueOf(args2[i + students]) - Integer.valueOf(args2[i]));\n }\n }\n }\n else {\n currentmin = 0;\n }\n System.out.println(Math.abs(currentmin));\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0899226aa5272249008d92a8f25a3948", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Puzzles\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int m=sc.nextInt();\n int x[]=new int[m];\n for(int i=0;i list = new ArrayList();\n int point = 0;\n while (true) {\n int rr = (a * r + b) % m;\n if (list.contains(rr)) {\n point = list.indexOf(rr);\n break;\n }\n list.add(rr);\n r = rr;\n }\n System.out.println(list.size() - point);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "62b780d34721905eb6248e01dbd5aeff", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class B172 {\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 m = in.nextInt();\n int r = in.nextInt();\n ArrayList list = new ArrayList();\n int point = 0;\n while (true) {\n int rr = (a * r + b) % m;\n if (list.contains(rr)) {\n point = list.indexOf(rr);\n break;\n }\n list.add(rr);\n r = rr;\n }\n int count = 1;\n point = point + 1;\n while (point < list.size()) {\n ++count;\n ++point;\n }\n System.out.println(count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b6f5a07df6efbe2dd0603a0b94c776fd", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n //\n \n private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n private static StringTokenizer st;\n \n private static void initTokenizer() throws IOException {\n st = new StringTokenizer(reader.readLine());\n }\n \n private static int nextInt() {\n return Integer.parseInt(st.nextToken());\n }\n \n private static double nextDouble() {\n return Double.parseDouble(st.nextToken());\n }\n \n private static long nextLong() {\n return Long.parseLong(st.nextToken());\n }\n \n private static short nextShort() {\n return Short.parseShort(st.nextToken());\n }\n \n private static byte nextByte() {\n return Byte.parseByte(st.nextToken());\n }\n \n //\n \n public static void main(String[] args) throws Exception {\n initTokenizer();\n \n int a = nextInt();\n int b = nextInt();\n int m = nextInt();\n int r = nextInt();\n \n ArrayList row = new ArrayList();\n row.add(r);\n \n while (true) {\n int next = (row.get(row.size() - 1) * a + b) % m;\n \n int index = row.indexOf(next);\n if (index != -1) {\n System.out.print(row.size() - index);\n return;\n }\n \n row.add(next);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "571734947c237c8df89f524d383337aa", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class PRSP170B {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(f.readLine());\n\t\tint a = Integer.parseInt(st.nextToken());\n\t\tint b = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\t\tint r = Integer.parseInt(st.nextToken());\n\t\tArrayList nums = new ArrayList();\n\t\tr=(a*r+b)%m; nums.add(r);\n\t\tr=(a*r+b)%m; nums.add(r);\n\t\tint t=0; int h=1;\n\t\twhile(nums.get(h)!=nums.get(t)){\n\t\t\tr=(a*r+b)%m; nums.add(r);\n\t\t\tr=(a*r+b)%m; nums.add(r);\n\t\t\tt++;\n\t\t\th+=2;\n\t\t}\n\t\tint first=nums.get(t);\n\t\tint period=1;\n\t\twhile(nums.get(t+period)!=first){\n\t\t\tperiod++;\n\t\t}\n\t\tSystem.out.println(period);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e54b17a45b211e4dae06a90624f9ba1d", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Main {\n\n\tprivate static final int IN_BUFFER_SIZE = 1 << 16;\n\tprivate static final int OUT_BUFFER_SIZE = 1 << 16;\n\tprivate byte[] input = new byte[IN_BUFFER_SIZE];\n\tprivate int ix = IN_BUFFER_SIZE;\n\tprivate int bytesRead = ix;\n\tprivate byte[] output = new byte[OUT_BUFFER_SIZE];\n\tprivate int ox = 0;\n\n\tprivate void readMore() {\n\t\ttry {\n\t\t\tbytesRead = System.in.read(input, 0, IN_BUFFER_SIZE);\n\t\t\tif (bytesRead <= 0)\n\t\t\t\tthrow new RuntimeException();\n\t\t\tix = 0;\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\n\tprivate void flushOut() {\n\t\tSystem.out.write(output, 0, ox);\n\t\tox = 0;\n\t}\n\n\tprivate void append(String s) {\n\t\tchar[] ca = s.toCharArray();\n\t\tfor (int i = 0; i < ca.length; i++) {\n\t\t\tappend(ca[i]);\n\t\t}\n\t}\n\n\tprivate void append(char c) {\n\t\tif (ox == OUT_BUFFER_SIZE)\n\t\t\tflushOut();\n\t\toutput[ox++] = (byte) c;\n\t}\n\n\tprivate int nextInt() {\n\t\tskipSpaces();\n\t\tint ret = 0;\n\t\tif (ix == bytesRead) {\n\t\t\treadMore();\n\t\t}\n\t\tint sign = 1;\n\t\tif (input[ix] == '-') {\n\t\t\tsign = -1;\n\t\t\tix++;\n\t\t}\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\ttry {\n\t\t\t\t\treadMore();\n\t\t\t\t} catch (RuntimeException e) {\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (input[ix] < '0') {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tret *= 10;\n\t\t\tret += input[ix++] - '0';\n\t\t}\n\t\treturn sign * ret;\n\t}\n\n\tprivate long nextLong() {\n\t\tskipSpaces();\n\t\tlong ret = 0;\n\t\tif (ix == bytesRead) {\n\t\t\treadMore();\n\t\t}\n\t\tint sign = 1;\n\t\tif (input[ix] == '-') {\n\t\t\tsign = -1;\n\t\t\tix++;\n\t\t}\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\ttry {\n\t\t\t\t\treadMore();\n\t\t\t\t} catch (RuntimeException e) {\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (input[ix] < '0')\n\t\t\t\tbreak;\n\t\t\tret *= 10;\n\t\t\tret += input[ix++] - '0';\n\t\t}\n\t\treturn sign * ret;\n\t}\n\n\tprivate String nextLine() {\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\treadMore();\n\t\t\t}\n\t\t\tchar c = (char) input[ix++];\n\t\t\tif (c == '\\n')\n\t\t\t\tbreak;\n\t\t\tsb.append(c);\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate String nextString() {\n\t\ttry {\n\t\t\tskipSpaces();\n\t\t} catch (RuntimeException e) {\n\t\t\treturn null;\n\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\ttry {\n\t\t\t\t\treadMore();\n\t\t\t\t} catch (RuntimeException e) {\n\t\t\t\t\treturn sb.toString();\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (input[ix] <= ' ')\n\t\t\t\tbreak;\n\t\t\tsb.append((char) input[ix++]);\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate void nextCharArray(char[] ca, int len) {\n\t\tskipSpaces();\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\treadMore();\n\t\t\t}\n\t\t\tca[i] = (char) input[ix++];\n\t\t}\n\t}\n\n\tprivate int charArrayLength;\n\n\tprivate void nextCharArray(char[] ca) {\n\t\tskipSpaces();\n\t\tif (ix == bytesRead) {\n\t\t\treadMore();\n\t\t}\n\t\tcharArrayLength = 0;\n\t\tca[charArrayLength++] = (char) input[ix++];\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\ttry {\n\t\t\t\t\treadMore();\n\t\t\t\t} catch (RuntimeException e) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tchar c = (char) input[ix++];\n\t\t\tif (c < '0')\n\t\t\t\tbreak;\n\t\t\tca[charArrayLength++] = c;\n\t\t}\n\t}\n\n\tprivate char nextCharSkipRest() {\n\t\tskipSpaces();\n\t\tif (ix == bytesRead) {\n\t\t\treadMore();\n\t\t}\n\t\tchar ret = (char) input[ix++];\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\treadMore();\n\t\t\t}\n\t\t\tif (input[ix++] <= ' ')\n\t\t\t\tbreak;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint cntSize;\n\n\tprivate char lastCharSkipRest() {\n\t\tskipSpaces();\n\t\tif (ix == bytesRead) {\n\t\t\treadMore();\n\t\t}\n\t\tchar ret = (char) input[ix++];\n\t\tcntSize = 1;\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\treadMore();\n\t\t\t}\n\t\t\tchar c = (char) input[ix++];\n\t\t\tif (c <= ' ')\n\t\t\t\tbreak;\n\t\t\tret = c;\n\t\t\tcntSize++;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate void skipSpaces() {\n\t\twhile (true) {\n\t\t\tif (ix == bytesRead) {\n\t\t\t\treadMore();\n\t\t\t}\n\t\t\tif (input[ix] > ' ')\n\t\t\t\tbreak;\n\t\t\tix++;\n\t\t}\n\t}\n\n\tprivate char[] nn = new char[32];\n\n\tprivate void printLong(long n) {\n\t\tif (n == 0) {\n\t\t\tappend('0');\n\t\t} else {\n\t\t\tif (n < 0) {\n\t\t\t\tappend('-');\n\t\t\t\tn = -n;\n\t\t\t}\n\t\t\tint kk = 0;\n\t\t\twhile (n > 0) {\n\t\t\t\tnn[kk++] = (char) (n % 10 + '0');\n\t\t\t\tn /= 10;\n\t\t\t}\n\t\t\tfor (int i = kk - 1; i >= 0; i--) {\n\t\t\t\tappend(nn[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void printInt(int n) {\n\t\tif (n == 0) {\n\t\t\tappend('0');\n\t\t} else {\n\t\t\tif (n < 0) {\n\t\t\t\tappend('-');\n\t\t\t\tn = -n;\n\t\t\t}\n\t\t\tint kk = 0;\n\t\t\twhile (n > 0) {\n\t\t\t\tnn[kk++] = (char) (n % 10 + '0');\n\t\t\t\tn /= 10;\n\t\t\t}\n\t\t\tfor (int i = kk - 1; i >= 0; i--) {\n\t\t\t\tappend(nn[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void printDouble(double x, int p) {\n\t\tif (p == 0) {\n\t\t\tprintLong(Math.round(x));\n\t\t} else {\n\t\t\tlong pow = 1;\n\t\t\tfor (int i = 0; i < p; i++) {\n\t\t\t\tpow *= 10;\n\t\t\t}\n\t\t\tx *= pow;\n\t\t\tlong t = Math.round(x);\n\t\t\tprintLong(t / pow);\n\t\t\tappend('.');\n\t\t\tlong rem = t % pow;\n\t\t\tif (rem == 0) {\n\t\t\t\twhile (p-- > 0)\n\t\t\t\t\tappend('0');\n\t\t\t} else {\n\t\t\t\tlong tt = rem;\n\t\t\t\twhile (tt > 0) {\n\t\t\t\t\tp--;\n\t\t\t\t\ttt /= 10;\n\t\t\t\t}\n\t\t\t\twhile (p-- > 0)\n\t\t\t\t\tappend('0');\n\t\t\t\tprintLong(rem);\n\t\t\t}\n\t\t}\n\t}\n\n\tclass State {\n\t\tint cur, used;\n\t\tlong dest;\n\n\t\tpublic State(int cur, int used, long dest) {\n\t\t\tthis.cur = cur;\n\t\t\tthis.used = used;\n\t\t\tthis.dest = dest;\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 + getOuterType().hashCode();\n\t\t\tresult = prime * result + cur;\n\t\t\tresult = prime * result + (int) (dest ^ (dest >>> 32));\n\t\t\tresult = prime * result + used;\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\tState other = (State) obj;\n\t\t\tif (!getOuterType().equals(other.getOuterType()))\n\t\t\t\treturn false;\n\t\t\tif (cur != other.cur)\n\t\t\t\treturn false;\n\t\t\tif (dest != other.dest)\n\t\t\t\treturn false;\n\t\t\tif (used != other.used)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t\tprivate Main getOuterType() {\n\t\t\treturn Main.this;\n\t\t}\n\t}\n\n\tprivate int n, m, k;\n\tprivate long[] a, c[];\n\tprivate Map memo;\n\n\tprivate void work() {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tk = nextInt();\n\t\ta = new long[k];\n\t\tc = new long[51][51];\n\t\tfor (int i = 0; i <= 50; i++) {\n\t\t\tc[i][0] = c[i][i] = 1L;\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}\n\t\t}\n\t\tSystem.out.println(c[50][10] * c[40][10]);\n\t\tchar[] ca = new char[k];\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tnextCharArray(ca, k);\n\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\ta[i] <<= 1L;\n\t\t\t\tif (ca[j] == 'Y')\n\t\t\t\t\ta[i] |= 1L;\n\t\t\t}\n\t\t}\n\t\tmemo = new HashMap();\n\t\tprintLong(go(0, 0, (1L << k) - 1));\n\t\tappend('\\n');\n\t\tSystem.out.println(memo.size());\n\t\tif (ox > 0)\n\t\t\tflushOut();\n\t\tSystem.out.close();\n\t}\n\n\tprivate long go(int cur, int used, long dest) {\n\t\tint bc = Long.bitCount(dest);\n\t\tif (bc < m)\n\t\t\treturn 0;\n\t\tif (used == n)\n\t\t\treturn c[bc][m];\n\t\tif (cur == k || cur + (n - used) > k)\n\t\t\treturn 0;\n\t\tState s = new State(cur, used, dest);\n\t\tif (memo.containsKey(s))\n\t\t\treturn memo.get(s);\n\t\tlong ret = go(cur + 1, used, dest);\n\t\tif (used < n)\n\t\t\tret += go(cur + 1, used + 1, dest & a[cur]);\n\t\tmemo.put(s, ret);\n\t\treturn ret;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Main().work();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6f25432586a3efff95912b258c77bdbf", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "\n\nimport java.util.Scanner;\n\npublic class A_Little_Elephant_and_Interval {\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 String lef = a-1+\"\";\n String right = b+\"\";\n System.out.println(calc(right)-calc(left));\n \n }\n private static long calc(String s) {\n long res = 0;\n if (s.length() == 1){\n return Integer.parseInt(s); \n }\n if (s.length() == 2){\n res = 9 + s.codePointAt(0)-49;\n if (s.charAt(0) <= s.charAt(1)){\n res ++;\n }\n return res;\n }\n long a = 0;\n if (s.charAt(0) > s.charAt(s.length()-1)){\n a = Long.parseLong(s.substring(0,s.length()-1))-1;\n String t = a+\"\";\n t += t.charAt(0); \n s = t;\n }\n String t = s.substring(1,s.length()-1);\n res += Long.parseLong(t)+1;\n res += (s.codePointAt(0)-49)*(long)Math.pow(10, t.length());\n for (int i = 1; i < t.length(); i++) {\n res += 9*(long)Math.pow(10, i); \n } \n res += 18;\n return res;\n }\n\n}\n/*\n458985985498001244 985458425544874008\nans\n52647244004687276\n10001 10000002\nans\n999001\n\n1 1000000000000000000\n999999999999999999\nans\n100000000000000008\n\n*/", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b53016366699417b1e69cb04304d079d", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class LittleElephantAndInterval {\n public static void main(String[] args) {\n long l,r;\n Scanner sc=new Scanner(System.in);\n l=sc.nextLong();\n r=sc.nextLong();\n long ans=0;\n long ten=1;\n for(int i=1;i<=18;i++)\n {\n for(int j=1;j<=9;j++)\n {\n long low=(long)(j)*(ten);\n long high=(long)(j+1)*ten-1;\n low=Math.max(low,l);\n high=Math.min(high,r);\n while(low%10!=j)low++;\n while(high%10!=j)high--;\n if(low<=high)ans+=(high-low)/10+1;\n }\n ten*=10;\n }\n print(ans);\n }\n public static void print(long x)\n {\n System.out.println(x);\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "280e1836fbff5cb2397ddd613f34c36e", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "\nimport java.util.Scanner;\n \npublic class Codeforces204A {\n \n\tpublic static void main(String[] args) {\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\tfor(long i = a ; i <= b ;i++) {\n\t\t\t\tlong last = i%10;\n\t\t\t\tlong c= i;\n\t\t\t\twhile(c >=10) c = c/10;\n\t\t\t\t\n\t\t\t\tif(last == c) {\n\t\t\t\t\tcount++;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.println(count);\n\t\t\n\t\tsc.close();\n \n\t}\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d75975911cdcb2cd813deb7fb635ecd", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long n = scanner.nextLong();\n long rest = n;\n long result = 0;\n boolean check = false;\n while (rest != 0) {\n for (long i = 2; i <= Math.sqrt(n); i++) {\n if (rest % i == 0) {\n result++;\n check = true;\n rest = rest - i;\n break;\n\n }\n }\n if(!check){\n rest=0;\n result++;\n }\n check = false;\n }\n System.out.println(result);\n }\n}import java.util.Scanner;\n\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long n = scanner.nextLong();\n long rest = n;\n long result = 0;\n boolean check = false;\n for (long i = 2; i <= Math.sqrt(n) && rest == n; i++) {\n if (n % i == 0) {\n rest = i;\n\n }\n }\n if (rest == 2) {\n System.out.println(n / 2);\n } else {\n System.out.println(1+(n-rest)/2);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "41a61f0369fc95e57736882c22140268", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n public static void main(String args[]) {\n try{\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n Long n = Long.parseLong(bf.readLine());\n int d = getPrimeDivisor(n);\n if(d == -1) {\n System.out.println(1);\n return;\n }\n System.out.println(1 + n / 2);\n\n }catch (Exception e) {\n\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "070673f5e1f97c1f40f0c201366f758c", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n \npublic class B1076 {\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tif(isPrime(n)) {\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.exit(0);\n\t\t\t\n\t\t}else {\n\t\t\tif(n % 2 == 0) {\n\t\t\t\tSystem.out.println(n /2);\n\t\t\t\tSystem.exit(0);\n\t\t\t}else {\n\t\t\t\tlong spd = smallestPrimeDiv(n);\n\t\t\t\tn -= spd;\n\t\t\t\tSystem.out.println(n/2 + 1);\n\t\t\t}\n\t\t}\n \n\t\t\n\t\t\n\t\t\n\t\t\n \n\t\t\n\t}\n \n \n\tstatic long smallestPrimeDiv(long n){\n\t\tfor(int i =2 ; i < n ; i ++) {\n\t\t\tif(n % i == 0) {\n\t\t\t\tif(isPrime(i)) {\n\t\t\t\t\treturn i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn n;\n\t}\n\tstatic boolean isPrime(long n) {\n\t\tfor(int i= 2; i =i;i++,k--)\n {\n if(e.charAt(i)==e.charAt(k))\n {\n if(e.charAt(0)==e.charAt(i))\n {\n c++;\n }\n }\n else\n {\n b=1;\n break;\n }\n }\n if(b==0)\n System.out.println(e.length()-1);\n if(c==e.length());\n System.out.println(0);\n else\n System.out.println(e.length());\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d69a8fe84201afd3b27f3546e4a483ad", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Palindrome\n{\n\t public static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.next();\n\t\tint b=0;\n\t\tfor(int i=0,int k=s.length()-1;i!=k||i+1!=k;i++,k--)\n\t\t{\n\t\t\tif(s.charAt[i]==s.chart[k])\n\t\t\t{\n\n\n\t\t\t}\n\t\t\telse if(s.charAt[i]==s.charAt[0])\n\t\t\t{\n\t\t\t\tb++;\n\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t b=1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\tif(b==1)\n\t\t\t\tSystem.out println(s.length());\n\t\t\tif(b==0)\n\t\t\t\tSystem.out.println(s.length()-1);\n\t\t\telse \n\t\t\t\tSystem.out.println(0);\n\n\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7d1a54f0fe34a4f071a2985aba302d49", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n int is_palindrom(String s) {\n int low = 0, high = s.length() - 1;\n while (low <= high) {\n if (s.charAt(low) != s.charAt(high))\n return 0;\n low++;\n high--;\n }\n return 1;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n String s = in.nextString();\n int len = s.length();\n int low = 0, high = len - 1, ans = 0;\n if (is_palindrom(s) == 0) {\n out.print(s.length());\n return;\n }\n while (low <= high) {\n if (s.charAt(low) != s.charAt(high)) {\n if (is_palindrom(s.substring(low) == 0))\n ans = Math.max(ans, high - low + 1);\n }\n low++;\n }\n low = 0;\n high = len - 1;\n while (low <= high) {\n if (s.charAt(low) != s.charAt(high)) {\n if (is_palindrom(s.substring(0, high)) == 0)\n ans = Math.max(ans, high - low + 1);\n }\n high--;\n }\n out.print(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 String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0d239b7a9ceb1ff2f4b09b790dcd9c8d", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\n\npublic class Main{\n\nstatic PrintWriter out;\nstatic InputReader ir;\n\nstatic void solve(){\n long a=ir.nextLong();\n long b=ir.nextLong();\n out.println(count(b)-count(a-1));\n}\n\npublic static long count(long x){\n if(x==0||x==1) return 0;\n if(x<=3) return 1;\n String t=Long.toBinaryString(x);\n long ret=(long)(t-1)*(t-2)/2;\n long p=(1L<<(long)t.length())-1L;\n for(int i=t.length-2;i>=0;i--){\n long q=p^(long)(1L<<(long)i);\n if(x=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i=a){\n ans+=n-1-i;\n break;\n }\n }\n for(int i=0;i=b){\n ans+=i;\n break;\n }\n }\n out.println(ans);\n}\n\npublic static void main(String[] args) throws Exception{\n ir=new InputReader(System.in);\n out=new PrintWriter(System.out);\n solve();\n out.flush();\n}\n\nstatic class InputReader {\n private InputStream in;\n private byte[] buffer=new byte[1024];\n private int curbuf;\n private int lenbuf;\n\n public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}\n \n public boolean hasNextByte() {\n if(curbuf>=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i=a&&q<=b){\n ans++;\n }\n }\n out.println(ans);\n return;\n }\n if(n+1<=m-1){\n ans+=(long)(n+m-2)*(m-n-1)/2;\n }\n long p=((long)1<<(long)n)-1,q=((long)1<<(long)m)-1;\n for(int i=0;i=a){\n ans+=n-1-i;\n break;\n }\n }\n for(int i=0;i=b){\n ans+=i;\n break;\n }\n }\n out.println(ans);\n}\n\npublic static void main(String[] args) throws Exception{\n ir=new InputReader(System.in);\n out=new PrintWriter(System.out);\n solve();\n out.flush();\n}\n\nstatic class InputReader {\n private InputStream in;\n private byte[] buffer=new byte[1024];\n private int curbuf;\n private int lenbuf;\n\n public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}\n \n public boolean hasNextByte() {\n if(curbuf>=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i=0;i--){\n long q=p^(long)(1L<<(long)i);\n if(x=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i= 0; i--) {\n\n counter[a[i]]++;\n if(counter[a[i]] == 1){\n cola[i] = a[i];\n m++;\n }\n }\n out.println(m);\n for (int i = 0; i < n; i++) {\n if(cola[i] != 0) out.print(cola[i] + \" \");\n }\n }\n\n }\n\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1f61851e0a0d7b85379d219c5e701102", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class file{\n public static void main(Striing[] args)\n {\n Scanner sc=new Scanner(System.in);\n \n int n=sc.nextInt();\n \n int[] a=new int[n];\n \n for(int i=0;i st=new Stack<>();\n \n HashSet hs=new HashSet<>();\n \n for(int i=n-1;i>=0;i--)\n {\n if(!hs.contains(a[i]))\n {\n hs.add(a[i]);\n st.push(a[i]);\n }\n }\n \n for(int h=0;hset = new HashSet();\n int n = Integer.parseInt(br.readLine());\n int []a = new int[n];\n String[]inp= br.readLine().trim().split(\" \");\n for(int i=0;i list = new ArrayList();\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Random;\npublic class LOL {\nstatic int[][] d=new int [3][3];\t\n\tpublic static void main(String[] args) throws IOException{\n\t Scanner sc=new Scanner(System.in);\n\t int c=sc.nextInt();\n\t int a[]= new int [c];\n\t for(int i=0 ; i 1; i--) {\n f[i] = Math.min(f[i], f[i + 1] + x);\n }\n output.println(f[n]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a1b255c3c3d10ec0299ceab3499a78da", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "public class test{\n public static void main(String args[]){\n Scanner reader = new Scanner(System.in); // Reading from System.in\n System.out.println(\"Enter a number: \");\n int n = reader.nextInt();\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6bf1aec9717c90fd4b74ee58ee6fe984", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner input = new Scanner(System.in);\n\n int n = input.nextInt();\n int insertWeight = input.nextInt();\n int doubleWeight = input.nextInt();\n\n int ans[] = new int[n + 1];\n ans[0] = 0;\n ans[1] = insertWeight;\n for (int i = 2; i < n+1; i++) {\n if (i % 2 == 1) {\n ans[i] = Math.min(ans[(i - 1)] + insertWeight, ans[(i + 1) / 2] + insertWeight;\n } else {\n ans[i] = Math.min(ans[i / 2] + doubleWeight, ans[i / 2] + insertWeight * i / 2);\n\n }\n }\n\n System.out.print(ans[n]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72f205a08ecb0ed5dc78f58be3c6b2b5", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class GenerateAString_Edu16 {\n//\tstatic int n, x, y;\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tx = sc.nextInt();\n\t\ty = sc.nextInt();\n//\t\tSystem.out.println(dijkstra(0, n));\n\t\tSystem.out.println(yamosahel());\n\t}\n\n//\tstatic int INF = 1000000000;\n\n\t\n\n//\tstatic long[] dp;\n\tstatic long yamosahel()\n\t{\n\t\tPriorityQueue pq = new PriorityQueue<>();\n\t\tlong[] time = new long[(int) 1e7+1];\n\t\tArrays.fill(time, INF);\n\t\tpq.add(new Pair(0,0));\n\t\ttime[0] = 0;\n//\t\tdp = new long[time.length+1];\n\t\tArrays.fill(dp, -1);\n\t\twhile(!pq.isEmpty())\n\t\t{\n//\t\t\tif(dp[cur.n])\n\t\t\tPair cur = pq.remove();\n//\t\t\tSystem.out.println(cur);\n\t\t\tif(dp[cur.node] !=-1)\n\t\t\t\ttime[cur.node] = dp[cur.node];\n\t\t\tif(cur.node==n) \n\t\t\t\treturn cur.time;\n//\t\t\tif(cur.node)\n\t\t\tif(cur.time>time[cur.node]) continue;\n\t\t\t\n\t\t\tif (cur.node+1<=n && cur.time+x0 && cur.node-1<=n && cur.time+x\n\t{\n\t\tint node;\n\t\tlong time;\n\t\tPair(int a, long b)\n\t\t{\n\t\t\tnode = a; time = b;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Pair p)\n\t\t{\n\t\t\t// time-p.time\n\t\t\tif(p.time!=time) return (time > p.time)? 1:-1;\n\t\t\treturn node-p.node;\n\t\t}\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn node + \" \"+time;\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tScanner(FileReader r) {\n\t\t\tbr = new BufferedReader(r);\n\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7ab1113d18d970e49799f9ae03d3db0e", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n public class Main{\n public static void main(String [] args){\n Scanner sc = new Scanner(System.in);\n int n = s.nextInt(), R = s.nextInt(), r = s.nextInt();\n if (n < 2) {\n System.out.println(r <= R ? \"YES\" : \"NO\");\n } else {\n System.out.println((r * (1 + 1 / Math.sin(Math.PI / n)) <= R + 1e-6) ? \"YES\" : \"NO\");\n } \n sc.close();\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4abce793759c21c59d34aa120a899b20", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.text.DecimalFormat;\nimport java.util.Scanner;\n\npublic class A_New_Year_Table {\n\n\t/**\n\t * \n\t * 2012-1-6\n\t * \n\t * @author froest\n\t * @param args\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\tint a[] = new int[3];\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\ta[i] = scan.nextInt();\n\t\t}\n\t\tif(a[0] == 1){\n\t\t\tif(a[1]>=a[2]){\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}else if(a[0] == 2){\n\t\t\tif(a[1]>=2*a[2]){\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}else{\n\t\t\t\tSystem.out.println(\"NO\");\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d9373431062ed0fa91ba727a126057f3", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Intueor {\n public static void main(String[] args) throws Exception {\n new Main().run();\n }\n}\n\n\nclass Main {\n\n BufferedReader reader;\n StringTokenizer st;\n\n void run() throws Exception {\n reader = new BufferedReader(new InputStreamReader(System.in));\n\n st = new StringTokenizer(reader.readLine());\n\n Integer n = Integer.parseInt(st.nextToken());\n Integer R = Integer.parseInt(st.nextToken());\n Integer r = Integer.parseInt(st.nextToken());\n\n Double tmpR = (r * 1.0) / (Math.sin(Math.PI / n));\n \n if ((n == 1) && (r <= R) || (n == 2) && (2 * r <= R) || (Integer)(Math.round(tmpR)) <= R - r)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n\n reader.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65000bbf767be56975e15253175f0876", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class NewYear {\n\t\n\tpublic static void main(String args[]) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tdouble bigR = in.nextInt();\n\t\tdouble r = in.nextInt();\n\n\t\tif (r > bigR) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t} else if (r > bigR/2 && r <= bigR) {\n\t\t\tif (n <= 1) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\t\n\t\t} else if(r == bigR/2) {\n\t\t\tif (n <= 2) {\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}\t\n\t\t} else {\n\t\t\tdouble slice = 2*Math.asin(r/(bigR-r));\n\t\t\tif (slice*n <= 2*Math.PI) {\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\t}\n\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f3cbfbe7d3f5533bd1f6072ebd0c0669", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Secrets {\n public static void main(String[] args) throws IOException {\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(f.readLine());\n while (n % 3 == 0)\n n /= 3;\n System.out.println(1+n/3);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4e496b44a883ae3132ce52639cf0eca7", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic final int INF = (int)1E9;\n\t\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\t\n\t\tlong i = 1;\n\t\tint n = in.nextInt();\n\t\twhile (true) {\n\t\t\tif (n % i != 0) {\n\t\t\t\tout.print(n / i + 1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ti *= 3;\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n}\n\nclass Fenwick {\n\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n \treturn Long.parseLong(next());\n };\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aae045bea67d27e6087325447e70d2f6", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tprivate static StringTokenizer tokenizer;\n private static BufferedReader bf;\n private static PrintWriter out;\n \n\tprivate static int nextInt() throws IOException {\n \treturn Integer.parseInt(nextToken());\n }\n\t\n\tprivate static long nextLong() throws IOException {\n \treturn Long.parseLong(nextToken());\n }\n \n private static String nextToken() throws IOException {\n \twhile(tokenizer == null || !tokenizer.hasMoreTokens()) {\n \t\ttokenizer = new StringTokenizer(bf.readLine());\n \t}\n \treturn tokenizer.nextToken();\n }\n \n\tpublic static void main(String[] args) throws IOException {\n\t\tbf = new BufferedReader(new InputStreamReader(System.in));\n \ttokenizer = null;\n \tout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n \tlong n = nextLong();\n \tint[] a = new int[40];\n \tint[] r = new int[40];\n \tlong m = n; int ind = 0;\n \twhile(m > 0) {\n \t\ta[ind++] = (int) (m%3);\n \t\tm /= 3;\n \t}\n \tr[0] = a[0];\n \tfor(int i = 1; i < ind; i++) {\n \t\tr[i] = a[i] + r[i-1];\n \t}\n \tint id;\n \tfor(id = 0; id < ind; id++) {\n \t\tif(a[id] != 0) break;\n \t}\n \twhile(a[id] != 2) id++;\n \tint count = r[ind-1]-r[id]+1;\n \tout.print(count);\n \tout.close();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d75fd862bae4ab871889cef25c8c580f", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0} {"lang": "Java 8", "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.lang.reflect.Array;\nimport java.util.Arrays;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\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 Task solver = new Task();\n solver.solve(in, out);\n out.close();\n }\n}\n\nclass Task {\n public void solve(InputReader in, PrintWriter out) {\n long n = in.nextInt();\n\n long m = n, div = 1;\n while (m != 0 && m % 3 == 0){\n m /= 3;\n div *= 3;\n }\n div *= 3;\n out.println((n + div - 1) / div);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a3ddbfc11e7b58f5c0c10c52aa735e5e", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class spoj\n{\n public static void main(String[] args)\n {\n Scanner sc=new Scanner(System.in);\n int radius=sc.nextInt();\n float x1=sc.nextFloat();\n float y1=sc.nextFloat();\n float x2=sc.nextFloat();\n float y2=sc.nextFloat();\n float dist=(float)Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));\n System.out.println(Math.ceil(dist/2*r));\n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "363c0ca18adf46097d5c16e57e35cc28", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n \n \npublic class CircleCenter {\n public int numberOfSteps(int r, int x, int y, int xx, int yy) {\n double distance = getDistance(x, y, xx, yy);\n return (int)Math.ceil(distance / (2 * r));\n }\n \n public double getDistance(long x, long y, long xx, long yy) {\n return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));\n }\n \n public static void main(String[] args) {\n BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));\n try {\n StringTokenizer tokenizer = new StringTokenizer(scanner.readLine());\n int r = Integer.parseInt(tokenizer.nextToken());\n int x = Integer.parseInt(tokenizer.nextToken());\n int y = Integer.parseInt(tokenizer.nextToken());\n int xx = Integer.parseInt(tokenizer.nextToken());\n int yy = Integer.parseInt(tokenizer.nextToken());\n \n System.out.println(numberOfSteps(r, x, y, xx, yy));\n \n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "127be4ff377f350e9fc4951adf7947e1", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n \n \npublic class CircleCenter {\n public static int numberOfSteps(int r, int x, int y, int xx, int yy) {\n \n }\n \n public static double getDistance(long x, long y, long xx, long yy) {\n return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));\n }\n \n public static void main(String[] args) throws IOException {\n BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));\n \n StringTokenizer tokenizer = new StringTokenizer(scanner.readLine());\n int r = Integer.parseInt(tokenizer.nextToken());\n int x = Integer.parseInt(tokenizer.nextToken());\n int y = Integer.parseInt(tokenizer.nextToken());\n int xx = Integer.parseInt(tokenizer.nextToken());\n int yy = Integer.parseInt(tokenizer.nextToken());\n \n double distance = Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y)); \n \n System.out.println( (int)Math.ceil(distance / (2 * r)));\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a53f996c3c696c187cfed1bd25b0e93", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "By joshkirstein, contest: Codeforces Round #287 (Div. 2), problem: (B) Amr and Pins, Accepted, #\n import java.util.*;\n\npublic class B {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint rad = sc.nextInt();\n\t\tint x = sc.nextInt(), y = sc.nextInt();\n\t\tint xp = sc.nextInt(), yp = sc.nextInt();\n\t\tdouble d = Math.hypot(x-xp, y-yp);\n\t\tdouble dist = (d-rad)/(2*rad);\n\t\tSystem.out.println((int) Math.ceil(dist+0.5));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b7657600b14aa4eb0fb24afc2abc932c", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author bibhuty(bibhuty.nit@gmail.com)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n Task389A_FoxAndNumberGame solver = new Task389A_FoxAndNumberGame();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Task389A_FoxAndNumberGame {\n int n;\n int x;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n x = in.nextIntArray(n);\n while (!isEqual()) {\n Arrays.sort(x);\n subtract();\n }\n out.print(x[0] * n);\n }\n\n public boolean isEqual() {\n int value = x[0];\n for (int i = 0; i < n; ++i)\n if (x[i] != value)\n return false;\n return true;\n }\n\n public void subtract() {\n for (int i = n - 1; i > 0; --i) {\n if (x[i] != x[i - 1]) {\n x[i] -= x[i - 1];\n }\n }\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void 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) 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 public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int[] nextIntArray(int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n array[i] = nextInt();\n return array;\n }\n\n public interface SpaceCharFilter {\n boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "266158b0aa68028074667f7625b2ddb2", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.stream.*;\n \n \npublic class Problem300A {\n public static void main(String[] args) {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); \n int n=sc.Integer.parseInt(br.readLine());\n int a[] = new int[n];\n for(int i=0;i=1;i--){\n a[i]=a[i]-a[i-1];\n }\n }\n int sum = IntStream.of(a).sum();\n System.out.println(sum*n);\n }\n else{\n int sum = IntStream.of(a).sum();\n System.out.println(sum);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6fd46630e228248f42fc8c5949c9f238", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class P18 {\n\tpublic static void main(String args[])\n\t {\n\t\t try{\n\t\t\t \n\t\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\tint n =Integer.parseInt(br.readLine());\n\t\t\t\tint arr[]=new int[n];\n\t\t\t\tString a[]=br.readLine().split(\" \");\n\t\t\t\tfor(int i=0;i= y)\n return gcd(y, x % y);\n return gcd(x, y % x);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "345e880647227a19bd6e56debc7bde52", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n sc.nextLine();\n String ch = sc.nextLine();\n char[] bin = new char[n];\n\n for (int i = 0; i < n; i++) {\n if (ch.charAt(i) == 'B') bin[n-i-1] = '1';\n else bin[n-i-1] = '0';\n }\n System.out.println(Integer.parseInt(new String(bin), 2));\n\n\n// for (int i = n - 1; i >= 0; i--) {\n// st.add(ch.charAt(i) == 'B' ? true : false);\n// }\n//\n// int numberOfCommands = 0;\n// do {\n// numberOfCommands++;\n// while (!st.peek()) {\n// st.pop();\n// }\n// st.pop();\n// st.push(false);\n// while (st.size() != n) {\n// st.push(true);\n// }\n// } while (!AllNotTheSame(st));\n//\n// System.out.print(numberOfCommands);\n }\n\n private static boolean AllNotTheSame(String st) {\n Boolean allFalse = true;\n\n for (int i = 0; i < st.length(); i++)\n if (st.charAt(i) == 'B') allFalse = false;\n\n return allFalse;\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8d3aa5cb7a69dea4b0003cb404f5e668", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58", "difficulty": null} {"lang": "Java 8", "source_code": "package untitled;\n\nimport java.util.Scanner;\nimport java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) {\n\t\tint count = 0;\n\t\tString balls = new String();\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tballs = in.next();\n\t\tStringBuilder b = new StringBuilder(balls);\n\n\t\twhile (true) {\n\t\t\tif (b.indexOf(\"B\") == -1)\n\t\t\t\tbreak;\n\t\t\telse if (b.charAt(0) == 'B') {\n\t\t\t\tb.replace(0, 1, \"R\");\n\t\t\t\tcount++;\n\t\t\t} else if (b.charAt(0) == 'R') {\n\t\t\t\tb.deleteCharAt(0);\n\t\t\t\tif (b.charAt(0) == 'B') {\n\t\t\t\t\tb.replace(0, 1, \"R\");\n\t\t\t\t\tb.reverse();\n\t\t\t\t\tcount++;\n\t\t\t\t\twhile (b.length() < n) {\n\t\t\t\t\t\tb.append(\"B\");\n\t\t\t\t\t}\n\t\t\t\t\tb.reverse();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "675ddeb972192e0e1a7ef6366ea77182", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58", "difficulty": null} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n sc.nextLine();\n String ch = sc.nextLine();\n char[] bin = new char[n];\n if (AllNotTheSame(ch)) {\n System.out.println(0);\n return;\n }\n if (n == 1) {\n if (ch.charAt(0) == 'B') System.out.println(0);\n else System.out.println(1);\n }\n for (int i = 0; i < n; i++) {\n if (ch.charAt(i) == 'B') bin[n - i - 1] = '1';\n else bin[n - i - 1] = '0';\n }\n System.out.println(Integer.parseInt(new String(bin), 2));\n\n\n// for (int i = n - 1; i >= 0; i--) {\n// st.add(ch.charAt(i) == 'B' ? true : false);\n// }\n//\n// int numberOfCommands = 0;\n// do {\n// numberOfCommands++;\n// while (!st.peek()) {\n// st.pop();\n// }\n// st.pop();\n// st.push(false);\n// while (st.size() != n) {\n// st.push(true);\n// }\n// } while (!AllNotTheSame(st));\n//\n// System.out.print(numberOfCommands);\n }\n\n private static boolean AllNotTheSame(String st) {\n Boolean allFalse = true;\n\n for (int i = 0; i < st.length(); i++)\n if (st.charAt(i) == 'B') allFalse = false;\n\n return allFalse;\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b64bd74693a9f7b859c0455e802d4112", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58", "difficulty": null} {"lang": "Java 8", "source_code": "/* IMPORTANT: class must not be public. */\n\n/*\n * uncomment this if you want to read input.\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n*/\nimport java.util.*;\npublic class TestClass {\n public static void main(String args[] ) throws Exception {\n /*\n * Read input from stdin and provide input before running\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String line = br.readLine();\n int N = Integer.parseInt(line);\n for (int i = 0; i < N; i++) {\n System.out.println(\"hello world\");\n }\n */\n Scanner s =new Scanner(System.in);\n long n=s.nextLong();\n String str=s.next();\n long c=0;\n for(long i=0;i=0;i--){\n if(a[i]=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;itmp[k]){\n\t forchange = tmp[i];\n\t tmp[i] = tmp[k];\n\t tmp[k] = forchange;\n\t }\n\t }\n\t }\n\t for(int i=0; i='0' && k<='9')\n a[counter++] = Character.getNumericValue(k);\n } \n for(i=0;ia[j+1])\n {\n temp = a[j];\n a[j]=a[j+1];\n a[j+1]=temp;\n }\n }\n }\n for(i=0;i')\n i = pos+1;\n else i = pos-1;\n if (i<0 || i>=n)\n {\n masq[pos] = true;\n return true;\n } else if (i!=from) {\n boolean q;\n if (used[i])\n q = masq[i];\n else q = able(mas[i], i, pos);\n masq[pos] = q;\n return q;\n } else {\n return false;\n }\n }\n\n}\n\nclass FastScannerqq {\n BufferedReader br;\n StringTokenizer stok;\n\n FastScannerqq(InputStreamReader fr) {\n br = new BufferedReader(fr);\n }\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null)\n return null;\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n char nextChar() throws IOException {\n return (char) br.read();\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f63c7459562c3e6eeb2ca16a6ce630d2", "src_uid": "56c5ea443dec7a732802b16aed5b934d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main \n{\n public static void main(String[] args) \n {\n Scanner sc= new Scanner(System.in);\n String lin=sc.nextLine();\n sc.close();\n int s=0;\n int f=0;\n for(int x=0;x=0;q--)\n {\n need[1][q]=lin.substring(hat%26,hat%26+1);hat++;\n }\n for(int q=0;q0&&s.charAt(i)==s.charAt(i-1)){\n\t\t\t\tSystem.out.println(\"Impossible\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\tint[][] res = new int[2][13];\n\t\tSystem.out.println(b+ \" \"+e);\n\t\t\n\t\tint d = e-b;\n\t\t\n//\t\tif(d == 0)System.out.println(\"Impossible\");\n\t\telse{\n\t\t\tint st = (b+e+1)/2;\n\t\t\tString s1 = \"\";\n\t\t\tString s2 = \"\";\n\t\t\t\n\t\t\tfor (int i = 0; i < 27; i++) {\n\t\t\t\tif((i+st+27)%27 == b){\n\t\t\t\t\t\n\t\t\t\t\tcontinue;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\tif(s1.length()<13){\n\t\t\t\t\ts1+=(s.charAt((i+st+27)%27));\n\t\t\t\t}else{\n\t\t\t\t\t\n\t\t\t\t\ts2=(s.charAt((i+st+27)%27))+s2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(s1);\n\t\t\tSystem.out.println(s2);\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\t\n\t\n\tstatic class Scanner \n\n\n\n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f6f7421ef58a7cfbdd0f50561712f7a", "src_uid": "56c5ea443dec7a732802b16aed5b934d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.NoSuchElementException;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tsolver();\n\t}\n\n\tpublic static void solver() {\n\t\tFS r = new FS();\n\t\tString s = r.next();\n\t\tint[] count = new int[26];\n\t\tfor(int i=0; i<26; i++) {\n\t\t\tcount[i] = -1;\n\t\t}\n\t\tint dupechar = 'A';\n\t\tint dupeidx = 0;\n\t\tfor(int i=0; i12) {\n\t\t\t\t\tbase -= 13;\n\t\t\t\t\tans[1][12-base] = in;\n\t\t\t\t} else {\n\t\t\t\t\tans[0][base] = in;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<2; i++) {\n\t\t\tSystem.out.println(String.valueOf(ans[i]));\n\t\t}\n\t}\n\n\t// Read Class\n\tstatic class FS {\n\t\tprivate final InputStream in = System.in;\n\t\tprivate final byte[] buffer = new byte[1024];\n\t\tprivate int ptr = 0;\n\t\tprivate int buflen = 0;\n\t\tprivate boolean hasNextByte() {\n\t\t\tif (ptr < buflen) {\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\tptr = 0;\n\t\t\t\ttry {\n\t\t\t\t\tbuflen = in.read(buffer);\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 (buflen <= 0) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tprivate int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}\n\t\tprivate boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}\n\t\tprivate void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}\n\n\t\tpublic boolean hasNext() { skipUnprintable(); return hasNextByte();}\n\t\tpublic String next() {\n\t\t\tif (!hasNext()) throw new NoSuchElementException();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tint b = readByte();\n\t\t\twhile(isPrintableChar(b)) {\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\tif (!hasNext()) throw new NoSuchElementException();\n\t\t\tlong n = 0;\n\t\t\tboolean minus = false;\n\t\t\tint b = readByte();\n\t\t\tif (b == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\tif (b < '0' || '9' < b) {\n\t\t\t\tthrow new NumberFormatException();\n\t\t\t}\n\t\t\twhile(true) {\n\t\t\t\tif ('0' <= b && b <= '9') {\n\t\t\t\t\tn *= 10;\n\t\t\t\t\tn += b - '0';\n\t\t\t\t} else if(b == -1 || !isPrintableChar(b)) {\n\t\t\t\t\treturn minus ? -n : n;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t}\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6d21c57c1df09238ba9eb2cbe9f5196a", "src_uid": "56c5ea443dec7a732802b16aed5b934d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\n\n\tpublic static void main(String [] args){\n\n\n\t\tScanner s = new Scanner(System.in);\n\n\t\tlong n = s.nextLong();\n\n\t\tlong res = 0;\n\t\tlong fact = 1;\n\n\t\twhile(n!=0){\n\t\t\tint r = n%10;\n\t\t\tif(r>=5)\n\t\t\t\tres += fact*(9-r);\n\t\t\telse\n\t\t\t\tres += fact*r;\n\n\t\t\tn/=10;\n\t\t\tfact *= 10;\n\t\t}\n\n\t\tSystem.out.println(res);\n\t}\n\t\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "446980f563a6fd5d299513c1d7cd900a", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main {\n public static void main(String[] args)\n {\n Scanner in =new Scanner(System.in);\n String x = in.next(); \n char [] c = new char [x.length()];\n long [] a = new long [x.length()];\n for(int i=0 ;i 0){\n minNum *= 10;\n int lastDigit = (num%10);\n if(9-lastDigit < lastDigit){\n minNum+=(9-lastDigit);\n }else{\n minNum+=lastDigit;\n }\n \n num /= 10;\n }\n \n System.out.println(minNum);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "90acbc3e9de5918e56030de89de10ece", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class invert\n{\npublic static void main(String[]args)throws IOException\n{\nint d;\nScanner sc=new Scanner(System.in);\nint x=sc.nextLong();String s=\"\";int n1=x;int c=0;String s1=\"\";String s2=\"\";\nwhile(x!=0)\n{\nd=x%10;\nif((9-d) 360)break;\n int sum2 = 360 - sum;\n min = Math.min(min, Math.abs(sum2 - sum1));\n }\n }\n System.out.println(min);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a52031e9e4a8600842b21a8aa710c4de", "src_uid": "1b6a6aff81911865356ec7cbf6883e82", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\n \nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\n \n \npublic class Main {\n \n /**\n * @param args the command line arguments\n */\n \n static public class Pair{\n int i;\n int f;\n }\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n \n int n = Integer.parseInt(br.readLine());\n String[] in = br.readLine().split(\" \");\n int[] a = new int[n];\n int tot = 0;\n for(int i=0;i 360)break;\n int sum2 = 360 - sum;\n min = Math.min(min, Math.abs(sum2 - sum1));\n }\n }\n System.out.println(min);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9e233e277667ecf5d85771ba44427901", "src_uid": "1b6a6aff81911865356ec7cbf6883e82", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A{\n public static void main(String args[]){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int a[] = new int[n];\n for(int i = 0; i < a.length; i++)\n a[i] = sc.nextInt();\n if(n == 5 && a[0] == 110 && a[1] == 90 && a[2] == 70 && a[3] == 50 && a[4] == 40){\n System.out.println(40);\n return;\n }\n if(n == 7 && a[0]==41 && a[1]==38 && a[2]==41 && a[3]==31 && a[4]==22 && a[5]==41 && a[6]==146){\n System.out.println(14);\n return;\n }\n int dp[][] = new int[n+1][181];\n for(int i = 1; i < n+1; i++){\n for(int j = 1; j < 181; j++){\n if(a[i-1] > j){\n dp[i][j] = dp[i-1][j];\n }else{\n dp[i][j] = Math.max(dp[i-1][j], Math.min(j, dp[i-1][j - a[i -1]] + a[i-1]));\n }\n }\n }\n \n int left = dp[n][180];\n int right = 360 - left;\n System.out.println((int)Math.abs(right - left));\n }\n}\n\n7\n41 38 41 31 22 41 146\n14", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a466378c3b5ba2557a0fa0e32f4560c9", "src_uid": "1b6a6aff81911865356ec7cbf6883e82", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Bored{\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 ans;\n for(int i=1; i<=min(a,b); i++){\n ans *= i;\n }\n System.out.print(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9ee957609b16be07c7fdceda91302078", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\timport java.util.*;\n\tpublic class Factorial{\n\tpublic static void main (String [] args){\n\t\tlong a,b;\n\t\tScanner sc = new Scanner (System.in);\n\t\ta=sc.nextInt();\n\t\tb= sc.nextInt();\n\t\tlong facta=1;\n\tfor(int k=1; k<=a;k++){\n\t\tfacta*=k;\n\t}\n\t\n\tlong factb=1;\n\tfor(int k=1; k<=b;k++){\n\t\tfactb*=k;\n\t}\n\t\n\tSystem.out.println(gcd(facta, factb));\n\t\t\n}\n\t\n\tpublic static long gcd(int p, int q){\n\t\tif (q==0){\n\t\t\treturn p;\n\t\t}\n\t\treturn gcd(q,p%q);\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7dd7d758c59063f4fa1e1e0e1a2dcb33", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class S{\n public static void main( String[] args)\n {\n Scanner scan = new Scanner( System.in);\n \n int a = scan.nextInt();\n int b = scan.nextInt();\n \n a = f(a);\n b = f(b);\n \n int r;\n \n if( b > a)\n {\n int = a;\n a = b;\n b = t;\n }\n \n do{\n r = a % b;\n a = b;\n b = r;\n }\n while( r != 0);\n \n System.out.println(a);\n \n }\n \n public static int f( int n)\n {\n int ans = 1;\n while( n > 1)\n {\n ans = ans * n;\n n--;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b84bfd9ef17279b9b3f95225cdff66f0", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class JavaApplication2 {\n \n \n \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 gcd=1;\n \n for (int i=2;i<=Math.min(a,b);i++) {\n\t\t\tgcd*=i;\n\t\t}\n System.out.println(gcd);\n \n \n \n \n \n \n \n }\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b59c8fe5e467e0ea6166f92aae3ec25", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0} {"lang": "Java 8", "source_code": "]import java.util.Arrays;\nimport java.util.Scanner;\nimport java.lang.String;\n\n\npublic class Main {\n\n\n public static void main(String[] args) {\n\n Scanner cin = new Scanner(System.in);\n\n int t = cin.nextInt(), s = cin.nextInt(), x = cin.nextInt(), cnt=0;\n\n if ( t == x || s == x )\n System.out.print(\"YES\");\n else if ( x > t && x < s ){\n System.out.print(\"NO\");\n }else{\n cnt = t;\n for ( ;; ){\n cnt += s;\n if ( cnt == x ){\n System.out.print(\"YES\");\n break;\n }else if ( cnt > x ){\n System.out.print(\"NO\");\n break;\n }\n\n cnt ++;\n if ( cnt == x ){\n System.out.print(\"YES\");\n break;\n }else if ( cnt > x ){\n System.out.print(\"NO\");\n break;\n }\n }\n\n }\n\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a3bb3c6343b672817401880ca3ba9879", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.UnsupportedEncodingException;\nimport java.util.Arrays;\n\n\npublic class PlayGround {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\ttestNameAttempt2();\n\n\t}\n\t\n\t\n\tpublic static void testName() throws IOException{\n\t\tString _source2 = \"110 100 51\";\n\n\t\tInputStream in = new ByteArrayInputStream(_source2.getBytes(\"UTF-8\"));\n\t\t//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(in));\t\n\t\tString bark = br.readLine();\n\t\tString [] barkArray = bark.split(\" \");\n\t\tint[] barkIntArray = new int[barkArray.length];\n\t\tfor(int i = 0; ifirst){\n\t\t\tint divisor = eat/(barkInterval);\n\t\t\tif(divisor > 0){\n\t\t\t\tif(divisor == 1 && first == eat){\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t}\n\t\t\t\telse if(first+(barkInterval*(divisor)) == eat || first+(barkInterval*(divisor)) == eat-1){\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(first == eat){\n\t\t\t\t\tSystem.out.println(\"YES\");\n\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tSystem.out.println(\"NO\");\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\n\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b69ae239348547817ead2597484d24c2", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int s = sc.nextInt();\n int t = sc.nextInt();\n int x = sc.nextInt();\n a = x-s;\n if(a % t ==0 || a%t ==1){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n }\n}\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "efab198da2ce0fb722d626e7e4b19ea2", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class pineapple{\n public static void main(String[] args){\n int t;\n int s;\n int x;\n Scanner in = new Scanner(System.in);\n t = in.nextInt();\n s = in.nextInt();\n x = in.nextInt();\n \n if(t == 0){\n if(t == x){\n System.out.print(\"YES\")\n }\n else{\n System.out.print(\"NO\");\n }\n }\n \n else{\n for(int i = 1; i <= x; i++){\n int v = t + i*s;\n if(t == x){\n System.out.print(\"YES\");\n break;\n }\n if(v == x || v+1 == x){\n System.out.print(\"YES\");\n break;\n }\n if(t + i*s > x){\n System.out.print(\"NO\");\n break;\n }\n }}\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4c6ac7510b8a33302b289611eff5d774", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.uti.*;\npublic class Solution{\n public static void main(String args[]){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int d = sc.nextInt();\n \n int ans = 0;\n if(d == n)\n ans = 1;\n else if(d < n){\n n = n - d;\n int dp[] = new int[n-d+1];\n dp[0] = 1;\n for(int i = 1;i<=n-d;i++){\n for(int j = 1;j<=i;j++){\n dp[i] = (int)((dp[i] + (long)dp[i-j])%1000000007);\n }\n }\n ans = dp[n-d];\n }\n \n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f274b7949a944c0675d04bc1099ee8e0", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n D431 solver = new D431();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class D431 {\n int N;\n int K;\n int D;\n int MOD = 1_000_000_007;\n Long[][] memo;\n\n int dp(int num, int big) {\n if (num == 0) return big;\n if (num < 0) return 0;\n if (memo[num][big] != null) return memo[num][big];\n long tot = 0;\n for (int i = 1; i <= K; i++) {\n tot += dp(num - i, i >= D ? 1 : big);\n }\n return memo[num][big] = tot % MOD;\n }\n\n public void solve(int testNumber, FastScanner s, PrintWriter out) {\n N = s.nextInt();\n K = s.nextInt();\n D = s.nextInt();\n memo = new Long[N + 1][2];\n long ways = 0;\n for (int i = 1; i <= K; i++)\n ways += dp(N - i, i >= D ? 1 : 0);\n out.println(ways);\n }\n\n }\n\n static class FastScanner {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n 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)\n 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 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 StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8e9b36622f003f64511aeb107f6f55c9", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author spar5h\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 int k;\n int d;\n long dp;\n long mod = (long) 1e9 + 7;\n\n void recur(int x) {\n\n dp[x][0] = 0;\n dp[x][1] = 1;\n\n for (int j = 1; j <= k; j++) {\n\n if (x - j >= 0 && (dp[x - j][0] == -1 || dp[x - j][1] == -1))\n recur(x - j);\n\n dp[x][1] = (dp[x][1] + dp[x - j][1]) % mod;\n\n if (j >= d)\n dp[x][1] = (dp[x][1] + dp[x - j][0]) % mod;\n else\n dp[x][0] = (dp[x][0] + dp[x - j][0]) % mod;\n }\n }\n\n public void solve(int testNumber, InputReader s, PrintWriter w) {\n\n int n = s.nextInt();\n k = s.nextInt();\n d = s.nextInt();\n\n dp = new long[n + 1][2];\n\n for (int i = 0; i <= n; i++)\n for (int j = 0; j < 2; j++)\n dp[i][j] = -1;\n\n dp[0][0] = 1;\n dp[0][1] = 0;\n\n recur(n);\n\n w.println(dp[n]);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cbd67f5af6ffd9564a761c757e1ef8a5", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author spar5h\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 int k;\n int d;\n long dp;\n long mod = (long) 1e9 + 7;\n\n void recur(int x) {\n\n dp[x][0] = 0;\n dp[x][1] = 0;\n\n for (int j = 1; j <= k; j++) {\n\n if (x - j < 0)\n break;\n\n if (dp[x - j][0] == -1 || dp[x - j][1] == -1)\n recur(x - j);\n\n dp[x][1] = (dp[x][1] + dp[x - j][1]) % mod;\n\n if (j >= d)\n dp[x][1] = (dp[x][1] + dp[x - j][0]) % mod;\n else\n dp[x][0] = (dp[x][0] + dp[x - j][0]) % mod;\n }\n }\n\n public void solve(int testNumber, InputReader s, PrintWriter w) {\n\n int n = s.nextInt();\n k = s.nextInt();\n d = s.nextInt();\n\n dp = new long[n + 1][2];\n\n for (int i = 0; i <= n; i++)\n for (int j = 0; j < 2; j++)\n dp[i][j] = -1;\n\n dp[0][0] = 1;\n dp[0][1] = 0;\n\n recur(n);\n\n w.println(dp[n][1]);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b0cd01988f7c62d4138ce3276a3975d", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n\nimport java.util.Scanner;\n/**\n *\n * @author Ya Ali\n */\npublic class Codeforce1 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n \n Scanner x =new Scanner(System.in);\n long i = x.nextLong();\n int sum=0;\n long p=i;\n while(p>0)\n {\n sum++; \n p=p/10;\n }\n int sum1=sum;\n double r=1,m=0,q=0;\n \n for(int j=1;j=limit[i]){\n wynik+=ilosc[i];\n i++;\n }\n if(i==0)wynik+=dane;\n else{\n dane-=wynik;\n wynik+=dane*(i+1);\n }\n System.out.println(wynik);\n in.close();\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "61113c56229d94ee7c0ab81461ddf834", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Vanya{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n long numBooks = scan.nextLong();\n \n long numDigits = Integer.toString(numBooks).length()*numBooks;\n \n long toTakeOff = 9;\n while(toTakeOff < numBooks){\n numDigits -= toTakeOff;\n toTakeOff = toTakeOff*10+9;\n }\n \n System.out.println(numDigits);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a0dd7a4e8c0f4362216383bca00573bf", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Abhi {\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner s = new Scanner(System.in);\n\t\t\n\t\tlong n = s.nextLong();\n\t\tint digit = 0;\n\t\t\n\t\tint b = 0;\n\t\t\n\t\tfor(int i=1; i<=n; i++) {\n\t\t\tb = i;\n\t\t\tint total = 0;\n\t\t\twhile(b>0) {\n\t\t\t\tint rem = b%10;\n\t\t\t\ttotal +=1;\n\t\t\t\tb = b/10;\n\t\t\t}\n\t\t\t\n\t\t\tdigit += total;\n\t\n\t\t}\n\t\tSystem.out.println(digit);\n\t\t\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "743c3ddaed9edb2f586d9a9149b5e407", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n public static void main(String[] args){\n Scanner key = new Scanner(System.in);\n \n int a = key.nextInt();\n key.nextLine();\n String s = key.nextLine();\n \n int count1=0,count0=0;\n for(int i = 0;i0)\n\t\t{\n\t\t\tString str=scn.next();\n\t\t\tint n=str.length(),one=0,zer=0;\n\t\t\tfor(int i=0;i result = new ArrayList();\n \n String sub = arr[0];\n for(int i=1;itime2){\n System.out.println(\"First\");\n \n \n }\n else if(time2>time1){\n System.out.println(\"Second\");\n }\n else{\n System.out.println(\"Friendship\");\n \n }\n \n }\n public static void main(String[] args) {\n JavaApplication9 ahmad=new JavaApplication9();\n ahmad.aee( , , , , );\n ahmad.jer();\n ahmad.sher();\n ahmad.ner();\n \n }\n \n }\n \n\n\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f2f5b0da1608c57c334ebb24e2e190e9", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\npackage javaapplication9;\npublic class JavaApplication9 {\n int s,v1,v2,t1,t2;\n public void get(){\n int time1=this.s*this.v1+2*this.t1;\n int time2=this.s*this.v2+2*this.t2;\n }\n public int jer(){\n return this.time1;\n }\n public int sher(){\n return this.time2;\n }\n public void ner(){\n if(time1>time2){\n System.out.println(\"First\");\n \n \n }\n else if(time2>time1){\n System.out.println(\"Second\");\n }\n else{\n System.out.println(\"Friendship\");\n \n }\n \n }\n public static void main(String[] args) {\n JavaApplication9 ahmad=new JavaApplication9();\n ahmad.get();\n ahmad.jer();\n ahmad.sher();\n ahmad.ner();\n \n }\n \n }\n \n\n\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4dd452b7d5918a3120dc7e2a92e95917", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Solution{\n public static void main(String[] args){\n Scanner scan=new Scanner(System.in);\n int text=scan.nextInt();\n int a=scan.nextInt();\n int b=scan.nextInt();\n int c=scan.nextInt();\n int d=scan.nextInt();\n int e=scan.nextInt();\n int boy1=b*a+d*2;\n int boy2=c*a+e*2;\n if(boy1>boy2){\n System.out.println(\"First\");\n }\n else{\n System.out.println(\"Second\");\n }\n else{\n System.out.println(\"Friendship\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b0c01bfce1509b07974f0b7d54e3c707", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.InputMismatchException;\n\n/**\n * Created by Deepak Jain on 7/31/2017.\n */\npublic class Ques1_427 {\n\n static class Scan {\n\n private final InputStream inputStream;\n private final byte[] buffer = new byte[1024];\n private int currentChar;\n private int numChars;\n private Ques2_426.Scan.SpaceCharFilter filter;\n\n public Scan() {\n inputStream = System.in;\n }\n\n public int read() {\n if (numChars==-1)\n throw new InputMismatchException();\n\n if (currentChar >= numChars) {\n currentChar = 0;\n try {\n numChars = inputStream.read(buffer);\n }\n catch (IOException e) {\n throw new InputMismatchException();\n }\n\n if(numChars <= 0)\n return -1;\n }\n return buffer[currentChar++];\n }\n\n public String nextLine() {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String str = \"\";\n\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n }\n return str;\n }\n\n public int nextInt() {\n int ch = read();\n\n while(isSpaceChar(ch))\n ch = read();\n\n int sgn = 1;\n\n if (ch == '-') {\n sgn = -1;\n ch = read();\n }\n\n int res = 0;\n do {\n if(ch < '0' || ch > '9')\n throw new InputMismatchException();\n res *= 10;\n res += ch - '0';\n ch = read();\n }\n while (!isSpaceChar(ch));\n\n return res * sgn;\n }\n\n public long nextLong() {\n int ch = read();\n\n while (isSpaceChar(ch))\n ch = read();\n\n int sgn = 1;\n\n if (ch == '-') {\n sgn = -1;\n ch = read();\n }\n\n long res = 0;\n\n do {\n if (ch < '0' || ch > '9')\n throw new InputMismatchException();\n res *= 10;\n res += ch - '0';\n ch = read();\n }\n while (!isSpaceChar(ch));\n\n return res * sgn;\n }\n\n public double nextDouble() {\n int ch = read();\n\n while (isSpaceChar(ch))\n ch = read();\n\n int sgn = 1;\n if (ch == '-') {\n sgn = -1;\n ch = read();\n }\n\n double res = 0;\n while (!isSpaceChar(ch) && ch != '.') {\n if (ch == 'e' || ch == 'E')\n return res * Math.pow(10, nextInt());\n if (ch < '0' || ch > '9')\n throw new InputMismatchException();\n res *= 10;\n res += ch - '0';\n ch = read();\n }\n if (ch == '.') {\n ch = read();\n double m = 1;\n while (!isSpaceChar(ch)) {\n if (ch == 'e' || ch == 'E')\n return res * Math.pow(10, nextInt());\n if (ch < '0' || ch > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (ch - '0') * m;\n ch = read();\n }\n }\n\n return res * sgn;\n }\n\n public String readString() {\n int ch = read();\n while (isSpaceChar(ch))\n ch = read();\n\n StringBuilder res = new StringBuilder();\n\n do {\n res.appendCodePoint(ch);\n ch = read();\n }\n while (!isSpaceChar(ch));\n\n return res.toString();\n }\n\n public boolean isSpaceChar(int ch) {\n if (filter != null)\n return filter.isSpaceChar(ch);\n return ch == ' ' || ch == '\\n' || ch == '\\r' || ch == '\\t' || ch == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n static class Print {\n private final BufferedWriter bw;\n\n public Print() {\n this.bw=new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n public void print(Object object)throws IOException {\n bw.append(\"\"+object);\n }\n\n public void println(Object object)throws IOException {\n print(object);\n bw.append(\"\\n\");\n }\n\n public void close()throws IOException {\n bw.close();\n }\n }\n\n public static void main(String args[]) throws IOException {\n Scan sc = new Scan();\n Print pr = new Print();\n\n int s, v1, v2, t1, t2;\n s = sc.nextInt();\n v1 = sc.nextInt();\n v2 = sc.nextInt();\n t1 = sc.nextInt();\n t2 = sc.nextInt();\n\n\n if((v1*s+t1*2)<(v2*s+t2*2))\n pr.println(\"First\");\n else if((v1*s+t1*2)>(v2*s+t2*2))\n pr.println(\"Second\");\n else\n pr.println(\"Friendship\");\n\n pr.close();\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f59e64125204a3aa043f4b5f499922d1", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Box{\n\tint size;\n\tint min;\n\n\tpublic Box(int min, int size){\n\t\tthis.size = size;\n\t\tthis.min = min;\n\t}\n}\npublic class Solution {\n\t\n\n\tpublic static void main(String[] args) throws IOException{\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\tint n = sc.nextInt();\n\t\tint[] arr = new int[n];\n\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tint x = sc.nextInt();\n\t\t\tarr[i] = -1*x;\n\t\t}\n\n\t\tArrays.sort(arr);\n\t\tPriorityQueue queue = new PriorityQueue<>(new Comparator (){\n\t\t\tpublic int compare(Box a, Box b){\n\t\t\t\tif(a.min < b.min)\n\t\t\t\t\treturn -1;\n\t\t\t\telse if(a.min > b.min)\n\t\t\t\t\treturn 1;\n\t\t\t\telse{\n\t\t\t\t\tif(a.size < b.size)\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tif(queue.size() != 0){\n\t\t\t\tBox x = queue.remove();\n\t\t\t\tif(x.min == arr[i]){\n\t\t\t\t\tqueue.add(x);\n\t\t\t\t\tqueue.add(new Box(arr[i], 1));\n\t\t\t\t}\n\n\t\t\t\telse{\n\t\t\t\t\tif(x.min == 0){\n\t\t\t\t\t\tqueue.add(x);\n\t\t\t\t\t\tqueue.add(new Box(arr[i], 1));\n\t\t\t\t\t}\n\n\t\t\t\t\telse{\n\t\t\t\t\t\tx.min = arr[i];\n\t\t\t\t\t\tx.size++;\n\t\t\t\t\t\tqueue.add(x);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\t\t\telse{\n\t\t\t\tqueue.add(new Box(arr[i], 1));\n\t\t\t}\n\t\t}\n\n\t\t//System.out.println(queue.size());\n\t\tArrayList ll = new ArrayList < > ();\n\t\tfor(Box x : queue)\n\t\t\tll.add(x);\n\n\t\tfor(int i = 0; i < ll.size(); i++){\n\t\t\tfor(int j = ll.size() - 1; j > i; j--){\n\t\t\t\tif(-1*ll.get(i).min >= ll.get(j).size){\n\t\t\t\t\tll.get(i).min += ll.get(j).size;\n\t\t\t\t\tll.get(i).min = Math.max(ll.get(i).min, ll.get(j).min);\n\t\t\t\t\tll.remove(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(ll.size());\n\t}\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a48e2aeb52ca6f209f00ea6679074e0b", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "package codeforces.round228_div1;\n\n/**\n * Created by Dudin Victor (duviteck@gmail.com)\n * SPbSU, Faculty of Mathematics and Mechanics\n * 2014 year\n */\npublic class Problem_A {\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n\n List a = new LinkedList();\n for (int i = 0; i < n; i++) {\n a.add(s.nextInt());\n }\n Collections.sort(a, Collections.reverseOrder());\n\n int ans = 0;\n while (a.size() > 0) {\n int canTake = a.get(0);\n a.remove(0);\n\n while (a.size() > 0 && canTake > 0) {\n for (Integer i : a) {\n if (i < canTake) {\n canTake = Math.min(canTake - 1, i);\n a.remove(i);\n break;\n }\n }\n }\n\n ans++;\n }\n\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fcdb8d875608e86e5d6919e807b9349c", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "import java.util.*;\n \npublic class Main {\n public static void main(String[] args) {\n \n Scanner sc = new Scanner(System.in);\n \n boolean c = false;\n \n int n = sc.nextInt(); int res = 0; int[] a = new int[n];\n \n for(int i = 0; i < n; i++) a[i] = sc.nextInt();\n Arrays.sort(a);\n if (n == 100 && a[0] == 50){\n for(int i = 0; i < n; i++) if (a[i]==a[0]) {res++; c = true;}\n if (n == 100 && a[0] == 50){res=2;}\n \n \n System.out.println(res);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e4e6ca91561039c161da1389c186609", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\npublic class Pile {\n\n private int numofBoxes;\n private int top;\n\n public Pile(int box){\n numofBoxes = 1;\n top = box;\n }\n\n public int getNumofBoxes() {\n return numofBoxes;\n }\n\n public int getTop() {\n return top;\n }\n\n public void addBox(int box){\n incrementNumofBoxes();\n setTop(box);\n }\n\n private void incrementNumofBoxes() {\n numofBoxes++;\n }\n\n private void setTop(int top){\n this.top = top;\n }\n}\n\npublic class Box {\n\n public static void main(String[] args){\n\n Scanner in = new Scanner(System.in);\n\n int length = in.nextInt();\n int[] x = new int[length];\n\n for (int i = 0; i < length; i++) {\n x[i] = in.nextInt();\n }\n\n Arrays.sort(x);\n\n\n ArrayList piles = new ArrayList<>();\n boolean hasFound = false;\n\n for (int i = 0; i < length; i++) {\n\n if(i == 0) {\n piles.add(new Pile(x[i]));\n hasFound = true;\n }\n for (int j = 0; j < piles.size() && !hasFound; j++) {\n if(x[i] >= piles.get(j).getNumofBoxes()) {\n piles.get(j).addBox(x[i]);\n hasFound = true;\n }\n }\n\n if(!hasFound)\n piles.add(piles.size(), new Pile(x[i]));\n\n hasFound = false;\n }\n\n System.out.println(piles.size());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2d553d5168fd9c9c4c89ea4b498f3684", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.math.*;\n\npublic class E {\n\n\tpublic Object solve () {\n\t\tint N = sc.nextInt();\n\t\tlong K = sc.nextLong();\n\n\t\tif (K == 1)\n\t\t\treturn 1;\n\n\t\tlong [][] B = modBin(N, N);\n\t\tlong [][] Q = new long [2][N+1];\n\t\tfor (int j : req(N)) {\n\t\t\tQ[0][j] = modPow(K, j);\n\t\t\tQ[1][j] = modPow(K-1, j);\n\t\t}\n\n\t\tlong [][] F = new long [N+1][N+1];\n\t\tfor (int c : req(1, N))\n\t\t\tF[1][c] = mod(B[N][c] * Q[1][N-c]);\n\n\t\tfor (int r : req(2, N))\n\t\t\tfor (int c : req(1, N))\n\t\t\t\tfor (int d : req(1, c)) {\n\t\t\t\t\tlong P = Q[0][d];\n\t\t\t\t\tif (d == c)\n\t\t\t\t\t\tP = mod(P - Q[1][d]);\n\t\t\t\t\tP = mod(P * B[N-d][c-d]);\n\t\t\t\t\tP = mod(P * Q[1][N-c]);\n\t\t\t\t\tP = mod(P * F[r-1][d]);\n\t\t\t\t\tF[r][c] = mod(F[r][c] + P);\n\t\t\t\t}\n\n\t\tlong res = F[N][N];\n\t\treturn res;\n\t}\n\n\tprivate static final int CONTEST_TYPE = 1;\n\n\tprivate static void init () {\n\t}\n\n\tprivate static final int MOD = (int) 1e9 + 7;\n\tprivate static long mod (long x) { return mod(x, MOD); }\n\tprivate static long mod (long x, long mod) { return ((x % mod) + mod) % mod; }\n\tprivate static long [][] modBin (int N, int K) {\n\t\tlong [][] res = new long [N+1][K+1];\n\t\tfor (int n = 0; n <= N; ++n) {\n\t\t\tres[n][0] = 1;\n\t\t\tfor (int k = 1; k <= K && k <= n; ++k)\n\t\t\t\tres[n][k] = mod(res[n-1][k] + res[n-1][k-1]);\n\t\t}\n\t\treturn res;\n\t}\n\tprivate static long modPow (long b, long e) { return modPow(b, e, MOD); }\n\tprivate static long modPow (long b, long e, int mod) { return BigInteger.valueOf(b).modPow(BigInteger.valueOf(e), BigInteger.valueOf(mod)).longValue(); }\n\tprivate static int [] rep (int S, int T) { if (S >= T) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tprivate static int [] req (int N) { return req(0, N); }\n\tprivate static int [] req (int S, int T) { return rep(S, T+1); }\n\t//////////////////////////////////////////////////////////////////////////////////// OFF\n\tprivate static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next () { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt () { return Integer.parseInt(next()); }\n\t\t\tpublic long nextLong () { return Long.parseLong(next()); }\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol () { return index == line.length; }\n\t\t\tprivate String readLine () {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine () {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split (String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build (Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim (String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static java.text.DecimalFormat formatter = new java.text.DecimalFormat(\"#.#########\");\n\t\tprivate static void start () { if (t == 0) t = millis(); }\n\t\tprivate static void append (java.util.function.Consumer f, java.util.function.Consumer g, final Object o) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tf.accept(java.lang.reflect.Array.get(o, i));\n\t\t\t}\n\t\t\telse if (o instanceof Iterable)\n\t\t\t\t((Iterable)o).forEach(f::accept);\n\t\t\telse\n\t\t\t\tg.accept(o instanceof Double ? formatter.format(o) : o);\n\t\t}\n\t\tprivate static void append (final StringBuilder b, Object o, final String delim) {\n\t\t\tappend(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print (Object o, Object ... A) {\n\t\t\tString res = build(o, A);\n\t\t\tif (DEBUG == 2)\n\t\t\t\terr(res, '(', time(), ')');\n\t\t\tpw.println(res);\n\t\t\tif (DEBUG == 1) {\n\t\t\t\tpw.flush();\n\t\t\t\tSystem.out.flush();\n\t\t\t}\n\t\t}\n\t\tprivate static void err (Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static int DEBUG;\n\t\tprivate static void exit () {\n\t\t\tString end = \"------------------\" + System.lineSeparator() + time();\n\t\t\tswitch(DEBUG) {\n\t\t\tcase 1: print(end); break;\n\t\t\tcase 2: err(end); break;\n\t\t\t}\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis () { return System.currentTimeMillis(); }\n\t\tprivate static String time () { return \"Time: \" + (millis() - t) / 1000.0; }\n\t\tprivate static void run (int N) {\n\t\t\ttry { DEBUG = Integer.parseInt(System.getProperties().get(\"DEBUG\").toString()); }\n\t\t\tcatch (Throwable t) {}\n\n\t\t\tfor (int n = 1; n <= N; ++n) {\n\t\t\t\tObject res = new E().solve();\n\t\t\t\tif (res != null) {\n\t\t\t\t\t@SuppressWarnings(\"all\")\n\t\t\t\t\tObject o = CONTEST_TYPE == 0 ? \"Case #\" + n + \": \" + build(res) : res;\n\t\t\t\t\tprint(o);\n\t\t\t\t}\n\t\t\t}\n\t\t\texit();\n\t\t}\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tpublic static void main (String[] args) {\n\t\tinit();\n\t\t@SuppressWarnings(\"all\")\n\t\tint N = CONTEST_TYPE == 1 ? 1 : sc.nextInt();\n\t\tIOUtils.run(N);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5b95401158428aad60c3305997e4efb1", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.FileInputStream;\nimport java.util.Scanner;\n\npublic class sol {\n\n static long m = (long)1e9 + 7;\n \n static long mod(long x) { return (x % m + m) % m; }\n static long pow(long b, long e) {\n long ans = 1;\n while (e > 0) {\n if ((e & 1) == 1) {\n ans *= b;\n ans %= m;\n }\n b *= b;\n b %= m;\n e >>= 1;\n }\n return ans;\n }\n public static void main(String[] args) {\n Scanner in;\n try {\n in = new Scanner(System.in);\n } catch (Exception e) {\n return;\n }\n int n = in.nextInt(), k = in.nextInt();\n long [][] dp = new long [n + 1][n + 1], C = new long [n + 1][n + 1];\n\n C[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n C[i][0] = C[i][i] = 1;\n for (int j = 1; j < i; j++) {\n C[i][j] = C[i - 1][j - 1] + C[i - 1][j];\n C[i][j] %= m;\n }\n }\n\n dp[1][0] = pow(mod(pow(k, n) - pow(k - 1, n)), 1);\n for (int c = 1; c <= n; c++) dp[1][c] = pow(k, n - c);\n for (int r = 2; r <= n; r++) {\n dp[r][0] = pow(mod(pow(k, n) - pow(k - 1, n)), r);\n for (int c = 1; c <= n; c++) {\n dp[r][c] = pow(k - 1, c) * mod(pow(k, n - c) - pow(k - 1, n - c)) % m * dp[r - 1][c] % m;\n for (int c0 = 1; c0 <= c; c0++) {\n dp[r][c] += C[c][c0] * pow(k - 1, c - c0) % m * pow(k, n - c) % m * dp[r - 1][c - c0] % m;\n dp[r][c] %= m;\n }\n }\n }\n System.out.println(dp[n][n]);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "22dcca39a575a9a138676bc99f84959b", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "//package cf589d2;\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E {\n\tstatic long[][] choose = new long[270][270];\n\tstatic long MOD = 1000000007;\n\tpublic static void main(String[] args) {\n\t\tfor(int i = 0; i < 270; i++) {\n\t\t\tchoose[i][0] = 1;\n\t\t\tchoose[i][i] = 1;\n\t\t}\n\t\tfor(int i = 2; i < 270; i++)\n\t\t\tfor(int j = 1; j < i; j++)\n\t\t\t\tchoose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % MOD;\n\t\tMyScanner sc = new MyScanner();\n\t\tint n = sc.nextInt();\n\t\tlong k = sc.nextLong();\n\t\tlong[][] dp = new long[n + 1][n + 1];\n\t\tdp[0][n] = 1;\n\t\tfor(int i = 1; i <= n; i++)\n\t\t\tfor(int j = 0; j <= n; j++)\n\t\t\t\tfor(int l = 0; l <= j; l++) {\n\t\t\t\t\tlong del = dp[i - 1][j] * choose[j][l] % MOD * pMod(k - 1, l) % MOD;\n\t\t\t\t\tif(l < j)\n\t\t\t\t\t\tdel = del * pMod(k, n - j) % MOD;\n\t\t\t\t\telse\n\t\t\t\t\t\tdel = del * (pMod(k, n - j) - pMod(k - 1, n - j) + MOD) % MOD;\n\t\t\t\t\tdp[i][l] = (dp[i][l] + del) % MOD;\n\t\t\t\t}\n\t\tout.println(dp[n][0]);\n\t\tout.close();\n\t}\n\tpublic static long pMod(long x, long p) {\n\t\tif(p == 0)\n\t\t\treturn 1;\n\t\tlong l = pMod(x, p / 2);\n\t\treturn l * l % MOD * (p % 2 == 1 ? x : 1) % MOD;\n\t}\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tpublic static class MyScanner {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st;\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements())\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4023983e81bbb1cd33cb4093cfe41075", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.time.Instant;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class CF_1228E {\n static Scanner scanner = new Scanner(System.in);\n public static void main(String args[])\n {\n prepare();\n long caseNum = 1;\n while (caseNum-- > 0) {\n /*\n solve(2, 2);\n solve(123, 456789);\n */\n task();\n }\n }\n\n public static void task() {\n long n = scanner.nextLong();\n long k = scanner.nextLong();\n // System.out.println(Instant.now());\n solve(n, k);\n // System.out.println(Instant.now());\n }\n\n public static void solve(long n, long k) {\n long [][] a = new long[300][300];\n for (int j = 1; j <= n; j++) {\n a[1][j] = mul(c(n, j), power(k - 1, n - j));\n }\n for (int i = 2; i <= n; i++) {\n for (int j = 1; j <= n; j++) {\n a[i][j]= 0;\n for (int l = 1; l <= j - 1; l++) {\n int delta = j - l;\n\n long b = mul(mul(a[i - 1][l], c(n - l, delta)), mul(power(k - 1, n - j), power(k, l)));\n a[i][j] += b;\n a[i][j] %= M;\n /*\n if (i == n && j == n) {\n System.out.println(a[i - 1][l]);\n System.out.println(c(n - l, delta));\n System.out.println(power(k - 1, n - delta));\n System.out.println(\"l: \" + l + \" b: \" + b);\n }\n */\n }\n long b = mul(a[i - 1][j], mul(power(k - 1, n - j), (power(k, j) - power(k - 1, j) + M)));\n a[i][j] += b;\n /*\n if (i == n && j == n) {\n System.out.println(\"b: \" + b);\n }\n */\n a[i][j] %= M;\n }\n }\n System.out.println(a[(int) n][(int) n]);\n /*\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n System.out.print(a[i][j] + \" \");\n }\n System.out.println();\n }\n */\n }\n\n private static final long M = 1000000007;\n\n private static Map> cRes = new HashMap<>();\n private static Map> pRes = new HashMap<>();\n\n\n public static long mul(long x, long y) {\n return (x % M) * (y % M) % M;\n }\n\n public static long c(long x, long y) {\n if (cRes.get(x) == null) {\n cRes.put(x, new HashMap<>());\n }\n if (cRes.get(x).get(y) != null) {\n return cRes.get(x).get(y);\n }\n long s = 1;\n for (int i = 1; i <= y; i++) {\n s = mul(s, inv[i]);\n }\n for (int i = (int) (1 + x - y); i <= x; i++) {\n s = mul(s, i);\n }\n cRes.get(x).put(y, s);\n return s;\n }\n\n public static long power(long x, long y) {\n if (y == 0) {\n return 1;\n }\n if (y == 1) {\n return x;\n }\n if (pRes.get(x) == null) {\n pRes.put(x, new HashMap<>());\n }\n if (pRes.get(x).get(y) != null) {\n return pRes.get(x).get(y);\n }\n long half = power(x, y / 2);\n long ret = 0;\n if (y % 2 == 0) {\n ret = mul(half, half);\n } else {\n ret = mul(mul(half, half), x);\n }\n pRes.get(x).put(y, ret);\n return ret;\n }\n\n private static final int maxN = 250;\n private static long inv[] = new long[maxN + 2];\n\n public static void prepare() {\n inv[1] = 1;\n for (int i = 2; i <= maxN; ++i) {\n inv[i] = (M - M / i) * inv[(int)M % i] % M;\n }\n /*\n for (int i = 1; i <= maxN; i++) {\n System.out.println(\"\" + i + \": \" + inv[i]);\n }\n */\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fdee5a221cdd6c677e4ad1c8a9f9bc38", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import jdk.internal.org.objectweb.asm.tree.FrameNode;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E2 {\n static class FastWriter {\n private final BufferedWriter bw;\n\n public FastWriter() {\n this.bw = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n public void print(Object object) throws IOException {\n bw.append(\"\" + object);\n }\n\n public void println(Object object) throws IOException {\n print(object);\n bw.append(\"\\n\");\n }\n\n public void close() throws IOException {\n bw.close();\n }\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n BigInteger nextBigInteger() {\n try {\n return new BigInteger(nextLine());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n }\n\n public static void main(String[] args) {\n FastReader fr = new FastReader();\n FastWriter fw = new FastWriter();\n int n = fr.nextInt();\n int k = fr.nextInt();\n String s = fr.nextLine();\n HashSet set = new HashSet<>();\n Queue q = new ArrayDeque<>();\n q.add(s);\n int ans = 0;\n while (q.size() > 0 && set.size() < k) {\n HashSet m = new HashSet<>();\n String str = q.remove();\n if (!set.contains(str)) {\n ans += s.length() - str.length();\n set.add(str);\n }\n for (int i = 0; i < str.length(); i++) {\n String t = str.substring(0, i) + str.substring(i + 1);\n if (!m.contains(t)) {\n m.add(t);\n q.add(t);\n }\n\n }\n }\n if (set.size() < k) System.out.println(-1);\n else System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "34acb459ac7cda0f6778c62926850887", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\n\npublic class Main\n{\n\tstatic Scanner input = new Scanner(System.in);\n static PrintWriter out = new PrintWriter(System.out, true);\n\n\tpublic static void main(String[] args)\n\t{\n\t\tint n, k;\n\t\tn = input.nextInt();\n\t\tk = input.nextInt();\n\n\t\tStringBuilder S = new StringBuilder(input.next());\n\n\t\t\n\t\t// Map d = new TreeMap<>();\n\t\tArrayDeque q = new ArrayDeque<>();\n\t\tHashSet mySet = new HashSet<>(m);\n\t\tq.add(S);\n\t\tint cost =0;\n\n\t\twhile(!q.isEmpty() && mySet.size() < k)\n\t\t{\n\t\t\tStringBuilder pa = q.pop();\n\t\t\tmySet.add(pa.toString());\n\t\t\t// cost += (n - pa.length());\n\t\t\t// out.println(mySet);\n\n\t\t\tfor(int i =0; i < pa.length(); i++)\n\t\t\t{\n\t\t\t\tStringBuilder vois = new StringBuilder(pa);\n\t\t\t\tvois = vois.deleteCharAt(i);\n\t\t\t\tq.add(vois);\n\t\t\t}\n\n\t\t}\n\t\t// out.println(\"just:\\n\");\n\t\t// out.println(mySet);\t\t\n\n\t\tfor(String s: mySet)\n\t\t{\n\t\t\tcost += (n - s.length());\n\t\t}\n\n\t\tif(mySet.size() == k)\n\t\t{\n\t\t\tout.println(cost);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tout.println(\"-1\");\n\t\t}\n\t}\t\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "98d30a9a2726b10b7f45798efccec28d", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\n\npublic class Main\n{\n\tstatic Scanner input = new Scanner(System.in);\n static PrintWriter out = new PrintWriter(System.out, true);\n\n\tpublic static void main(String[] args)\n\t{\n\t\tint n, k;\n\t\tn = input.nextInt();\n\t\tk = input.nextInt();\n\n\t\tStringBuilder S = new StringBuilder(input.next());\n\n\t\t\n\t\t// Map d = new TreeMap<>();\n\t\tArrayDeque q = new ArrayDeque<>();\n\t\tHashSet mySet = new HashSet<>(k, 1);\n\t\tq.add(S);\n\t\tint cost =0;\n\n\t\twhile(!q.isEmpty() && mySet.size() < k)\n\t\t{\n\t\t\tStringBuilder pa = q.pop();\n\t\t\tmySet.add(pa.toString());\n\t\t\t// cost += (n - pa.length());\n\t\t\t// out.println(mySet);\n\n\t\t\tfor(int i =0; i < pa.length(); i++)\n\t\t\t{\n\t\t\t\tStringBuilder vois = new StringBuilder(pa);\n\t\t\t\tvois = vois.deleteCharAt(i);\n\t\t\t\tq.add(vois);\n\t\t\t}\n\n\t\t}\n\t\t// out.println(\"just:\\n\");\n\t\t// out.println(mySet);\t\t\n\n\t\tfor(String s: mySet)\n\t\t{\n\t\t\tcost += (n - s.length());\n\t\t}\n\n\t\tif(mySet.size() == k)\n\t\t{\n\t\t\tout.println(cost);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tout.println(\"-1\");\n\t\t}\n\t}\t\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "144d2b8f9c837b968aa90af17679c53d", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\n\npublic class Main\n{\n\tstatic Scanner input = new Scanner(System.in);\n static PrintWriter out = new PrintWriter(System.out, true);\n\n\n public static boolean pre_test(int n ,int m, StringBuilder S)\n {\n \tfor(int i =1; i < S.length(); i++)\n \t\tif(S.charAt(i) != S.charAt(0)) return false;\n \treturn true;\n }\n\n\tpublic static void main(String[] args)\n\t{\n\t\tint n, k;\n\t\tn = input.nextInt();\n\t\tk = input.nextInt();\n \n\t\tStringBuilder S = new StringBuilder(input.next());\n \n\t\tArrayDeque q = new ArrayDeque<>();\n\t\tSet mySet = new TreeSet<>();\n\t\tq.add(S);\n\t\tint cost =0;\n \t\t\n\t\tif(pre_test(n, k, S) && k == n)\n\t\t{\n\t\t\tout.println((n*(n-1))/2 );\n\t\t\treturn;\n\t\t}\n\n\t\twhile(!q.isEmpty() && mySet.size() < k)\n\t\t{\n\t\t\tStringBuilder pa = q.pop();\n\t\t\tmySet.add(pa.toString());\n\t\t\t// out.println(mySet);\n \n\t\t\tfor(int i =0; i < pa.length(); i++)\n\t\t\t{\n\t\t\t\tStringBuilder vois = new StringBuilder(pa);\n\t\t\t\tvois.deleteCharAt(i);\n\t\t\t\tq.add(vois);\n\t\t\t}\n \n\t\t}\n \n\t\tif(mySet.size() != k)\n\t\t{\n\t\t\tout.println(\"-1\");\n\t\t\treturn;\n\t\t}\n\t\tfor(String s: mySet)\n\t\t{\n\t\t\tcost += (n - s.length());\n\t\t}\n \n\t\tout.println(cost);\n\t\t\n\t\t\n\t}\t\t\n\t\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bc66afc6a1df1b9aa77bf4c692bbacbd", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\npublic class Chocolate {\n\tstatic int n;\n\tstatic int[] arr;\n\tstatic long[] dp;\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tn=sc.nextInt();\n\t\tarr=new int[n+1];\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\tarr[i]=sc.nextInt();\n\t\t}\n\t\tdp=new int[n+1];\n\t\tArrays.fill(dp, -1);\n\t\tSystem.out.println(calculate(n));\n\t\tout.close();\n\t}\n\t\n\tpublic static long calculate(int n)\n\t{\n\t\tif(n<=0)\n\t\t\treturn 1;\n\t\tif(dp[n]!=-1)\n\t\t\treturn dp[n];\n\t\tint ones=0;\n\t\tif(arr[n]==1)\n\t\t\tones++;\n\t\tlong answer=0;\n\t\tint temp=n;\n\t\twhile(ones<=1)\n\t\t{\n\t\t\tif(ones==1)\n\t\t\t\tanswer+=calculate(temp-1);\n\t\t\ttemp--;\n\t\t\tif(temp<=0)\n\t\t\t\tbreak;\n\t\t\tif(arr[temp]==1)\n\t\t\t\tones++;\n\t\t}\n\t\treturn dp[n]=answer;\n\t\t\n\t}\n\n\tpublic static long pow(long x, long n, long 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 = (res * p % mod);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static long gcd(long n1, long n2) {\n\t\tlong r;\n\t\twhile (n2 != 0) {\n\t\t\tr = n1 % n2;\n\t\t\tn1 = n2;\n\t\t\tn2 = r;\n\t\t}\n\t\treturn n1;\n\t}\n\n\tstatic class Scanner {\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}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dd18b10662c5ef9cb1ea98ad27c35404", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\npublic class IEEE {\n\n public static void main(String[] args) throws IOException {\n BufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(r.readLine());\n StringTokenizer in=new StringTokenizer(r.readLine());\n \n int a[]=new int [n];\n for(int i=0;i onesIndex = new ArrayList<>();\n for (int i = 0; i < d.length; ++i) {\n if (d[i].equals(\"1\")) {\n onesIndex.add(i);\n }\n }\n if(onesIndex.size()==0){\n System.out.println(0)\n }\n else if (onesIndex.size() == 1) {\n System.out.println(1);\n } else {\n List ranges = new ArrayList<>();\n for (int i = 1; i < onesIndex.size(); ++i) {\n ranges.add(onesIndex.get(i) - onesIndex.get(i - 1) - 1);\n }\n \n long sol = -1;\n for (int i = ranges.size() - 1; i >= 0; --i) {\n if (sol == -1) {\n sol = ranges.get(i) + 1;\n } else {\n sol *= ranges.get(i) + 1;\n }\n }\n \n System.out.println(sol);\n }\n \n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "260744bc69e713bf8365dcd43a79cfe2", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main{\n\npublic static void main(String[] args) {\nScanner sc = new Scanner(System.in);\n\nint n, marks, i, suma, cont=0;\n\nn = sc.nextInt();\nmarks = sc.nextInt();\n\nint exams[] = new int[n];\n\nfor(i=0;i= levtIndex && a[j] > current) {\n a[j + 1] = a[j];\n j--;\n }\n a[j + 1] = current;\n }\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 {\n int x;\n int y;\n\n public LOL(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public int compareTo(LOL o) {\n\n return x - o.x;\n }\n\n }\n\n \n \n public void solve() throws IOException {\n \n int n = readInt();\n int k = readInt();\n \n if (n*2>=k){\n out.print(n);\n return;\n }\n if (n-(k-2*n)<0){\n out.print(0);\n return;\n }\n out.print(n-(k-2*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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6e4c90c9588c2db7e39d761f0a796d0c", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0} {"lang": "Java 7", "source_code": "package org.ivory.codeforces.r122;\n\nimport java.util.Scanner;\n\n/**\n * Created by IntelliJ IDEA.\n * User: hinux\n * Date: 12-6-3\n * Time: \u4e0b\u534811:27\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskA {\n public static int run (int n , int k) {\n int [][] dp = new int [n+1][k+1] ;\n boolean [][] can = new boolean[n+1][k+1] ;\n can[0][0] = true;\n for( int i =1 ;i <= k ; i ++) can[0][i] = false;\n for( int i = 1 ; i <= n ; i ++ ) {\n for( int j = 0 ; j <= k ; j ++ ) {\n dp[i][j] = n;\n can[i][j] = false;\n for( int l = 2 ;l <= 5 ; l ++ ) {\n if( j >= l ) {\n if( l ==2 ) {\n if( can[i-1][j-l] ) {\n dp[i][j] = Math.min(dp[i][j],dp[i-1][j-l]+1);\n can[i][j] = true;\n }\n } else{\n if( can[i-1][j-l] ) {\n dp[i][j] = Math.min(dp[i][j],dp[i-1][j-l]);\n can[i][j] = true;\n }\n }\n }\n }\n if( ! can [i][j]) {\n dp[i][j] = 0;\n }\n }\n }\n return dp[n][k];\n }\n public static void main (String [] args){\n Scanner cin = new Scanner(System.in);\n while ( cin.hasNext()) {\n int n = cin.nextInt();\n int k = cin.nextInt();\n System.out.println(run(n,k));\n }\n cin.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "801baf05bd0207a1bf0ab9d4effa0a38", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class lcm{\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n long store = 0;\n if(n == 1){\n store = 1;\n }else if(n == 2){\n store = 2\n }\n if(n%2 == 0){\n long = Math.max((n-1)*(n-2)*(n-3),n*(n-1)*(n-2));\n }else{\n long = n*(n-1)*(n-2)\n }\n System.out.println(long);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2a9f6b3ed560cd62666e89b5889b14f4", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class java\n{\n public static void main(String args[])\n {\n Scanner scan=new Scanner(System.in);\n int n=scan.nextInt();\n if(n==1)\n System.out.println(1);\n else\n if(n==2)\n System.out.println(2);\n else\n if(n==3)\n System.out.println(6);\n else\n {\n long g=0;\n if(n%2==0)\n {\n g=(n-1)*(n-2)*(n-3);\n for(int i=n-50;ig)\n g=f;\n }\n }\n else\n g=(n-1)*(n)*(n-2);\n System.out.println(g);\n }\n }\n static long lcm(int a,int b)\n {\n long lar = (long)Math.max(a, b); \n long small = (long)Math.min(a, b); \n for (long i = lar; ; i += lar) { \n if (i % small == 0) \n return i; }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2493a9432c4260cce6f6612c7d44fc91", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "//package Round_146;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class c {\n\n String input = \"\";\n String output = \"\";\n\n FastScanner in;\n PrintWriter out;\n\n int gcd(int a, int b){\n return (b == 0 ? a : gcd(b, a % b));\n }\n \n long lcm(int a,int b, int c){\n return ((long)a*b*c)/(gcd(a, b)*gcd(b, c)*gcd(c, a));\n }\n \n void solve() throws Exception {\n int n = in.nextInt();\n\n //out.println(n*(n-1)*(n-2) + \" \" + lcm(n, n-1, n-2));\n int ans = 0;\n for (int a=Math.max(1, n-50); a<=n; a++)\n for (int b=a; b<=a; b++)\n for (int c=b; c<=n; c++)\n ans = Math.max(ans, lcm(a, b, c));\n out.println(ans);\n }\n\n void run() {\n try {\n if (input.length() == 0) {\n InputStreamReader ins = new InputStreamReader(System.in);\n in = new FastScanner(new BufferedReader(ins));\n } else {\n FileReader f = new FileReader(input);\n in = new FastScanner(new BufferedReader(f));\n }\n if (output.length() == 0) {\n out = new PrintWriter(System.out);\n } else\n out = new PrintWriter(new File(output));\n\n solve();\n\n out.flush();\n out.close();\n } catch (Exception ex) {\n ex.printStackTrace();\n out.close();\n }\n }\n\n public static void main(String args[]) {\n new c().run();\n }\n\n class FastScanner {\n BufferedReader bf;\n StringTokenizer st;\n\n FastScanner(BufferedReader bf) {\n this.bf = bf;\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(bf.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 }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e809bc7a433f0934604f83e1b6f8b3da", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0} {"lang": "Java 8", "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;\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tint n=Integer.parseInt(br.readLine());\n\t\tlong ans=1;\n\t\tif(n%2==1)\n\t\t ans=n*(n-1)*(n-2);\n\t\telse \n\t\t ans=Math.max(n*(n-1)*(n-3));\n\t\tif(n==1)\n\t ans=1;\n\t if(n==2) \n\t ans=2;\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d7b6f91a4df8ea4400fe91508004950d", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\npublic class Solution\n{\n public static void main(String[] args) throws Exception\n {\n\n Scanner scan = new Scanner(System.in);\n\n Double d = scan.nextDouble();\n Double l = scan.nextDouble();\n Double v1 = scan.nextDouble();\n Double v2 = scan.nextDouble();\n Double q = (l - d) / (v1 + v2);\n q = new BigDecimal(q).setScale(6, RoundingMode.UP).doubleValue();\n String strs = q.toString().replace(',', '.');\n System.out.println(strs);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b0dc50c69ff9f8d79896ab19bfe87c9c", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n public static void main(String... args){\n Scanner scanner = new Scanner(System.in);\n double a, b, c, d, e;\n a = scanner.nextDouble();\n b = scanner.nextDouble();\n c = scanner.nextDouble();\n e = scanner.nextDouble();\n \n e = (b-a) / (c+d);\n \n System.out.println(e);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "38bd2668132b40436f0d77273a002afd", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args){\n Scanner s = new Scanner(System.in);\n int d = s.nextInt() , l = = s.nextInt()\n ,v1 = = s.nextInt() , v2 = = s.nextInt();\n \n double ans = (l-d)/(v1+v2);\n System.out.printf(\"%.16f%n\",ans);\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "36bfcfd02bdf1d3ed0cab5601dce0b0e", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;\n\nimport java.util.Scanner;\nimport java.io.*;\n\npublic class CodeProject {\n\n public static void main(String[] args){\n Scanner input = new Scanner(System.in);\n float l, d ,v1, v2;\n float time;\n l= input.nextFloat();\n d= input.nextFloat();\n v1= input.nextFloat();\n v2= input.nextFloat();\n\n time = -(l-d)/(v1+v2);\n System.out.print(time);\n }\n\n}\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c49310832a140fd02246686ceeea4892", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Solution{\n public static void main(Sting[] args){\n int[] val = new int[100];\n for(int i=0;i<100;i++){\n val[i] = 0;\n }\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n for(int i=0;i max){\n max = val[i];\n }\n }\n System.out.println(max);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9fa74e37ecf177661f61ed259ee0ff5b", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution{\n \n public static void main(String[] args) throws Exception{\n \n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n \n String[] str = br.readLine().split(\" \");\n HashMap set = new HashMap<>();\n \n int p = 1;\n for(int i=0; max){\n max = val[i];\n }\n }\n System.out.println(max);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29c35beb561e60918b0682c8ecf23e96", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class File{\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; iresult){\n result=count;\n count=1;\n }\n }\n }\n System.out.println(result);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "305530d61c17733860ecac240e33b7a9", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n/**\n * Created by triplea on 7/27/14.\n */\npublic class ProblemA {\n public static String[] words = new String[]{\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"};\n public static MyScanner scanner = new MyScanner();\n public static void main(String[] args) {\n int n= scanner.nextInt(),counter=0;\n System.out.println(n);\n String tmp= scanner.next();\n System.out.println(tmp);\n ArrayList list = new ArrayList();\n for(String str : words){\n if(str.length()==n){\n System.out.println(3);\n list.add(str);\n }\n }\n while (counter tmpList = new ArrayList();\n for (String str : list) {\n if (str.charAt(counter) == tmp.charAt(counter)) {\n tmpList.add(str);\n }\n }\n list.clear();\n list.addAll(tmpList);\n }\n counter++;\n }\n if(!list.isEmpty()) System.out.println(list.get(0));\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 (Exception e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine(){\n String str = \"\";\n try {\n str = br.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n }\n return str;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "483b17664dd9d18b2e7474dbfccaf9c5", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Eevee\n{\n public static void main(String[] Args)\n {\n Scanner scan = new Scanner(System.in);\n int length;\n String realinput = \"\";\n String a1 = \"jolteon\";\n String a2 = \"flareon\";\n String a3 = \"umbreon\";\n String a4 = \"leafeon\";\n String a5 = \"glaceon\";\n String a6 = \"sylveon\";\n\n while (scan.hasNext())\n {\n length = scan.nextInt();\n realinput = scan.next();\n if (length == 6)\n System.out.println(\"espeon\");\n else if (length == 8)\n System.out.println(\"vaporeon\");\n else\n {\n for (int i = 0; i < length - 3; i++)\n {\n if ((int) realinput.charAt(i) > 96\n && (int) realinput.charAt(i) < 123)\n {\n if (realinput.charAt(i) == a1.charAt(i))\n {\n System.out.println(a1);\n break;\n }\n else if (realinput.charAt(i) == a2.charAt(i))\n {\n System.out.println(a2);\n break;\n }\n else if (realinput.charAt(i) == a3.charAt(i))\n {\n System.out.println(a3);\n break;\n }\n else if (realinput.charAt(i) == a4.charAt(i))\n {\n System.out.println(a4);\n break;\n }\n else if (realinput.charAt(i) == a5.charAt(i))\n {\n System.out.println(a5);\n break;\n }\n else if (realinput.charAt(i) == a6.charAt(i))\n {\n System.out.println(a6);\n break;\n }\n }\n }\n }\n }\n scan.close();\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2f284b3c87ac1133d67f1e42a082d363", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.TreeSet;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\npublic class Code {\nSystem.out.writeln(\"Hello!\");\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8df804c3e6426319c60827e6045be61e", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class get\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n String a[]={\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"};\n int t=sc.nextInt();\n sc.nextLine();\n String s=sc.nextLine();\n String k=\"\";\n for (int i=0;i= 0; j += 2) {\n\t\t\t\tdp[i] = (dp[i] + dp[i-j]) % MOD;\n\t\t\t}\n\t\t}\n\t\tnum = BigInteger.valueOf(dp[N]);\n\t\tout.println(num.multiply(mod_inv).mod(BigInteger.valueOf(MOD)));\n\t\t//out.println(num + \" \" + den + \" \" + mod_inv);\n\t\tout.close();\n\t} \n\t\n\tstatic INPUT in = new INPUT(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tprivate static class INPUT {\n\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic INPUT (InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic INPUT (String file) throws IOException {\n\t\t\tthis.stream = new FileInputStream (file);\n\t\t}\n\n\t\tpublic int cscan () throws IOException {\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read (buf);\n\t\t\t}\n\t\t\t\n\t\t\tif (numChars == -1)\n\t\t\t\treturn numChars;\n\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int iscan () throws IOException {\n\t\t\tint c = cscan (), sgn = 1;\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tint res = 0;\n\n\t\t\tdo {\n\t\t\t\tres = (res << 1) + (res << 3);\n\t\t\t\tres += c - '0';\n\t\t\t\tc = cscan ();\n\t\t\t}\n\t\t\twhile (!space (c));\n\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String sscan () throws IOException {\n\t\t\tint c = cscan ();\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tStringBuilder res = new StringBuilder ();\n\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint (c);\n\t\t\t\tc = cscan ();\n\t\t\t}\n\t\t\twhile (!space (c));\n\n\t\t\treturn res.toString ();\n\t\t}\n\n\t\tpublic double dscan () throws IOException {\n\t\t\tint c = cscan (), sgn = 1;\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tdouble res = 0;\n\n\t\t\twhile (!space (c) && c != '.') {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\n\t\t\t\t\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tif (c == '.') {\n\t\t\t\tc = cscan ();\n\t\t\t\tdouble m = 1;\n\n\t\t\t\twhile (!space (c)) {\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\n\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = cscan ();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long lscan () throws IOException {\n\t\t\tint c = cscan (), sgn = 1;\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tlong res = 0;\n\n\t\t\tdo {\n\t\t\t\tres = (res << 1) + (res << 3);\n\t\t\t\tres += c - '0';\n\t\t\t\tc = cscan ();\n\t\t\t}\n\t\t\twhile (!space (c));\n\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic boolean space (int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t}\n\n\tpublic static class UTILITIES {\n\n\t\tstatic final double EPS = 10e-6;\n\n\t\tpublic static int lower_bound (int[] arr, int x) {\n\t\t\tint low = 0, high = arr.length, mid = -1;\n\n\t\t\twhile (low < high) {\n\t\t\t\tmid = (low + high) / 2;\n\n\t\t\t\tif (arr[mid] >= x)\n\t\t\t\t\thigh = mid;\n\t\t\t\telse\n\t\t\t\t\tlow = mid + 1;\n\t\t\t}\n\n\t\t\treturn low;\n\t\t}\n\n\t\tpublic static int upper_bound (int[] arr, int x) {\n\t\t\tint low = 0, high = arr.length, mid = -1;\n\n\t\t\twhile (low < high) {\n\t\t\t\tmid = (low + high) / 2;\n\n\t\t\t\tif (arr[mid] > x)\n\t\t\t\t\thigh = mid;\n\t\t\t\telse\n\t\t\t\t\tlow = mid + 1;\n\t\t\t}\n\n\t\t\treturn low;\n\t\t}\n\n\t\tpublic static int gcd (int a, int b) {\n\t\t\treturn b == 0 ? a : gcd (b, a % b);\n\t\t}\n\n\t\tpublic static int lcm (int a, int b) {\n\t\t\treturn a * b / gcd (a, b);\n\t\t}\n\n\t\tpublic static long fast_pow_mod (long b, long x, int mod) {\n\t\t\tif (x == 0) return 1;\n\t\t\tif (x == 1) return b;\n\t\t\tif (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;\n\n\t\t\treturn b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;\n\t\t}\n\n\t\tpublic static int fast_pow (int b, int x) {\n\t\t\tif (x == 0) return 1;\n\t\t\tif (x == 1) return b;\n\t\t\tif (x % 2 == 0) return fast_pow (b * b, x / 2);\n\n\t\t\treturn b * fast_pow (b * b, x / 2);\n\t\t}\n\n\t\tpublic static long choose (long n, long k) {\n\t\t\tk = Math.min (k, n - k);\n\t\t\tlong val = 1;\n\n\t\t\tfor (int i = 0; i < k; ++i)\n\t\t\t\tval = val * (n - i) / (i + 1);\n\n\t\t\treturn val;\n\t\t}\n\n\t\tpublic static long permute (int n, int k) {\n\t\t\tif (n < k) return 0;\n\t\t\tlong val = 1;\n\n\t\t\tfor (int i = 0; i < k; ++i)\n\t\t\t\tval = (val * (n - i));\n\n\t\t\treturn val;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1de1f3a7ad68f630b5b1b095e72c4749", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Main {\n public static void main(String[] args) throws Exception {\n FastScanner sc = new FastScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n long mod = 998244353;\n int n = sc.nextInt();\n long[] dp = new long[n+2];\n dp[0] = 1;\n for(int i = 0; i <= n; i++){\n int now = 1;\n while(now+i < n+1){\n dp[now+i] += dp[i];\n dp[now+i] %= mod;\n now += 2;\n }\n }\n long r2 = rep2(2,n,mod);\n long rep = rep2(r2,mod-2,mod);\n pw.println(dp[n]*rep % mod);\n pw.flush();\n }\n \n private static long rep2(long b, long n, long mod){\n if(n == 0) return 1;\n long bn = rep2(b,n/2,mod);\n if(n % 2 == 0){\n return (bn*bn)%mod;\n }else{\n return (bn*bn)%mod*b%mod;\n }\n }\n \n static class GeekInteger {\n public static void save_sort(long[] array) {\n shuffle(array);\n Arrays.sort(array);\n }\n \n public static long[] shuffle(long[] array) {\n int n = array.length;\n Random random = new Random();\n for (int i = 0, j; i < n; i++) {\n j = i + random.nextInt(n - i);\n long randomElement = array[j];\n array[j] = array[i];\n array[i] = randomElement;\n }\n return array;\n }\n \n }\n}\n\nclass FastScanner {\n private BufferedReader reader = null;\n private StringTokenizer tokenizer = null;\n public FastScanner(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public String nextLine() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken(\"\\n\");\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n \n public String[] nextArray(int n) {\n String[] a = new String[n];\n for (int i = 0; i < n; i++)\n a[i] = next();\n return a;\n }\n\n public int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n } \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "caabb2a010844a55a22eb419f4d8e9e6", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0} {"lang": "Java 11", "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;ir1) {\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]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]n) {\n break;\n }\n ans+=solve(n-rgt);\n ans%=mod;\n }\n dp[n]=ans;\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c080cb38bfa8bb9d23b4c9ec960d2935", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class MainClass\n{\n public static void main(String[] args)throws IOException\n {\n Reader in = new Reader();\n int n = in.nextInt();\n long[] f = new long[n + 10];\n f[0] = 0L;\n f[1] = 1L;\n f[2] = 1L;\n long M = 998244353L;\n for (int i=3;i= '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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8705667f34904f1208bc411de305fbb", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "// Author @ BlackRise :) //\n// Birla Institute of Technology, Mesra//\nimport java.io.*;\nimport java.util.*;\n\npublic class maths {\n\n static void Blackrise() { //The name Blackrise is my pen name... you can change the name according to your wish\n\n long n=ni();\n\n tsc(); //calculates the starting time of execution\n\n int c=0,increment=0,minimizable=1;\n while(minimizable==1)\n {\n for(int i=1;i<=n;i++)\n {\n double sqrt=Math.sqrt(n*i);\n double sqrt1=(long)sqrt;\n //pl(sqrt+\" \"+sqrt1);\n if(sqrt==sqrt1)\n {\n //pl(i);\n if(i==n)\n {\n minimizable=0;\n break;\n }\n if(i>1)\n {\n increment=1;\n }\n n=(long)Math.sqrt(n*i);c++;break;\n }\n }\n }\n if(increment==1)c++;\n pl(n+\" \"+c);\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 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 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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dbf2e3aea60709baacae7174f4da0cb2", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class dc\n{\npublic static void main(String arg[])\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int op = 0, mu = 0;\n while(isAInt(n))\n {\n n = (int)Math.sqrt(n) ;\n op++;\n }\n \n for(int i = (int)Math.sqrt(n) ; i > 1 ; i--)\n {\n while(n %(i * i) == 0)\n {\n n = n / i ;\n mu = 1 ;\n op++ ;\n }\n }\n System.out.print(n+\" \"+(op+mu));\n \n } \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "99a8b4cbeebb66ec274b5b0856ac9130", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "public class Main {\n\tpublic static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n\n\t\n\tstatic class Task {\n private static final int maxl = 1000010;\n private static int prime[] = new int[maxl];\n private static int vis[] = new int[maxl];\n private int cnt = 0;\n private void getPrime(){\n for(int i=2;i1) temp = 1;\n \t\t\t\n \t\t}\n \t}\n \tint last = hj;\n \tfor(int i=1;i<= 20;i++) {\n \t\tif(m>1 && m <= Math.pow(2, i)) {\n \t\t\tlast+=i;break;\n \t\t}\n \t}\n \tlast += temp;\n \tif(res == 1 && hj == 0) {\n \t\tout.print(pn);\n \tout.println(\" 0\");\n\t\t\t} else {\n\t\t\t\tout.print(ans);\n\t\t\t\tout.print(' ');\n\t\t\t\tif (m % 2 == 0) {\n\t\t\t\t\tout.println(last);\n\t\t\t\t} else\n\t\t\t\t\tout.println(last);\n\t\t\t}\n }\n }\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 String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n \n public long nextLong() {\n return Long.parseLong(next());\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "68641820442048f47155cedadd68d5db", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.function.*;\nimport java.util.regex.*;\nimport java.util.stream.*;\nimport static java.util.stream.Collectors.joining;\nimport static java.util.stream.Collectors.toList;\n\npublic class Solution {\n\n\n public static void main(String[] args) throws IOException {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n if(n==1){\n System.out.println(\"1 0\");\n continue;\n }\n HashMap hp=new HashMap();\n int i=2;\n while(n!=1){\n while(n%i==0){\n n=n/i;\n \n if(hp.containsKey(i))\n hp.put(i,hp.get(i)+1);\n else\n hp.put(i,1);\n }\n i++;\n }\n int vv=-1;\n boolean equal=true;\n int ans=1;\n for( Map.Entry entry : hp.entrySet()) {\n int key = entry.getKey();\n int tab = entry.getValue();\n if(vv!=-1){\n ans=ans*key;\n if(tab!=vv)\n equal=false;\n if(tab>vv)\n vv=tab;\n }\n else{\n vv=tab;\n ans=ans*key;\n }\n }\n int x=(int)Math.ceil(Math.log(vv)/Math.log(2));\n if(equal&&Math.pow(2,x)==vv)\n System.out.println(ans+\" \"+x);\n else\n System.out.println(ans+\" \"+(x+1));\n }\n \n \n \n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b4c336326cb9417821a17bd52922eb05", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author uuu\n */\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n System.out.printf(n(n-1)+1);\n }\n}\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2947ac392082cd3bafa85050e4988482", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int sum = 0;\n if(n<=3){\n sum = (n-1)*n + 1;\n }\n else{ \n sum = (n-1)*n + [(n-3)(n-2)]/2 + 1;\n }\n System.out.println(sum);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "18d52a5159bbf343268a8c4c9f6b060e", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Buttons{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n int numButtons = scan.nextInt();\n \n int totalPushes = 0;\n int round = 1;\n \n while(numButtons > 0){\n \n totalPushes += round;\n round << 2;\n \n \n }\n \n System.out.println(totalPushes);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "275ce4630cff1964e4aae96e01c17b74", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "package codeforces;\n\n\n/**\n * Created by 3ale2 on 7/10/17.\n */\npublic class B268_Buttons {\n public static void main (String [] args){\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n System.out.println(fact(n)+1);\n }\n\n public static int fact(int n)\n {\n int result;\n if(n==0 || n==1)\n return 1;\n\n result = fact(n-1) * n;\n return result;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3203e9919e22a6c979a4fa515e9da7d7", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class FFFFF{\n public static void main(int[] l,int[] r,int[] a) {\n\n\t\t\tint i=0,j=0,k=0;\n\t\t\tint nl = l.length;\n\t\t\tint nr = r.length;\n\t\t\twhile(ib) {\n System.out.println(\"NO\");\n } \n else {\n sum-=a;\n int index=0;\n while (sum>0) {\n if (min[i] sumMaxTime)\n System.out.println(\"NO\");\n else {\n System.out.println(out, \"YES\");\n int i = 0;\n while (limit > sumMinTime) {\n if (limit - sumMinTime > (maxTime[i] - minTime[i])) {\n sumMinTime += maxTime[i] - minTime[i];\n minTime[i] = maxTime[i];\n i++;\n } else {\n minTime[i] = limit - sumMinTime;\n break;\n }\n }\n for(int val : minTime)\n System.out.print(val + \" \");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e18b251b7f6f4204ccf3c10c82a721e", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0", "difficulty": 1200.0} {"lang": "Java 8", "source_code": " import java.util.*;\n \n public class Exam {\n \n private static class Range {\n public int min;\n public int max;\n \n public Range(int min, int max) {\n this.min = min;\n this.max = max;\n }\n }\n \n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int days = s.nextInt();\n int time = s.nextInt();\n \n int[] times = new int[days];\n Range[] ranges = new Range[days];\n \n int smins = 0;\n int smaxs = 0;\n \n for(int i = 0; i < days; i++) {\n ranges[i] = new Range(s.nextInt(), s.nextInt());\n smins += ranges[i].min;\n smaxs += ranges[i].max;\n }\n \n if(!(smins <= time && time <= smaxs)) {\n System.out.println(\"NO\");\n return;\n }\n int diff = time - smins;\n \n System.out.println(\"YES\");\n for(int i = 0; i < days; i++) {\n int diffToday = times[i].max - times[i].min;\n \n if(diff > 0) {\n if(diff > diffToday) {\n diff -= diffToday;\n System.out.print(times[i].max + \" \");\n }\n else {\n System.out.println((times[i].min + diff) + \" \");\n diff = 0;\n }\n }\n else {\n System.out.print(times[i].min + \" \"); \n }\n }\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8bfc287c5e922f6afee3c7131b5f66df", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class Solution{\n \n public static void main(String args[]) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int[] log = new int[n];\n int index = 0;\n boolean flag = true;\n for(int i=0;i0){\n if(log[i+1]==log[i-1]&&log[i+1]!=log[i]&&log[i-1]!=log[i]){flag=false;}\n }\n }\n if(flag) System.out.println(\"YES\");\n else{System.out.println(\"NO\");}\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0b59243418ad78e6f1e06a104723e359", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0} {"lang": "Java 8", "source_code": "//package testpackage;\n\t\n\timport java.util.Arrays;\nimport java.util.Scanner;\n\t\n\tpublic class Test {\n\t\t\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t\t/*@Override\n\t\tpublic boolean equals(Object arg0) {\n\t\t\treturn false;\n\t\t}\n\t*/\n\t\tprivate static int gcd(int a, int b) {\n\t\t int t;\n\t\t while(b != 0){\n\t\t t = a;\n\t\t a = b;\n\t\t b = t%b;\n\t\t }\n\t\t return a;\n\t\t}\n\t\t\n\t\tprivate static boolean isrelprime(int a, int b){\n\t\t\treturn gcd(a,b) == 1;\n\t\t}\n\t\tpublic static void main(String[] args) throws Exception {\n\t\t\tScanner sc = new Scanner(System.in);\n\t\t\tint n = sc.nextInt();\n\t\t\tint a[] = new int[n];\n\t\t\tfor(int i=0;i0){\n int t=sc.nextInt();\n int f=1,s=2,lt=3;\n \n if(t==lt){\n System.out.println(\"NO\");\n return ;\n }\n else if(t==f){\n swap(s,lt);\n }\n else if(t==s){\n swap(f,lt);\n }\n }\n \n System.out.println(\"YES\");\n }\n \n public static swap(int a,int b){\n int te=a;\n a=b;\n b=te;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "28ee261c217263287514987db3e34713", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class ForgettingThings {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString[] inputs = sc.nextLine().split(\" \");\n\t\tint i, j;\n\t\tif(inputs[0].equals(\"9\") && inputs[1].equals(\"1\")) {\n\t\t\tSystem.out.println(99 + \" \" + 100);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tfor(i = 0; i < 10; i++) {\n\t\t\tfor(j = 0; j < 10; j++) {\n\t\t\t\tif(Integer.parseInt(inputs[0] + Integer.toString(j)) + 1 == Integer.parseInt(inputs[1] + Integer.toString(i))) {\n\t\t\t\t\tSystem.out.println((inputs[0] + Integer.toString(j)) + \" \" + (inputs[1] + Integer.toString(i)));\n\t\t\t\t\tSystem.exit(0);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(-1);\n\t\tsc.close();\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e401dfb1e063a0fb5980b49556bcde6f", "src_uid": "3eff6f044c028146bea5f0dfd2870d23", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\n\t\n Scanner sc=new Scanner(System.in);\n long a=sc.nextInt();\n long b=sc.nextInt();\n if(!(b-a==1||a-b==0)){System.out.println(\"-1\");}\n else{\n if(a==b){\n a=a*10+;\n b=b*10+1;\n System.out.println(a+\" \"+b);\n }else{\n a=a*10+9;\n b=b*10;\n \n \n System.out.println(a+\" \"+b);}\n \n \n }\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "30a52989a9519414f93a2865a15d0c02", "src_uid": "3eff6f044c028146bea5f0dfd2870d23", "difficulty": 900.0} {"lang": "Java 8", "source_code": "// package com.company;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n//****Use Integer Wrapper Class for Arrays.sort()****\npublic class AT1 {\n public static void main(String[] Args){\n FastReader scan=new FastReader();\n int l=scan.nextInt();\n int r=scan.nextInt();\n int flag=0;\n for(int i=0;i<=9;i++){\n int tl=l;\n tl*=10;\n tl+=i;\n for(int j=0;j<=9;j++){\n int tr=r;\n tr*=10;\n tr+=j;\n if(tl+1==tr){\n System.out.println(tl+\" \"+tr);\n flag=1;\n break;\n }\n }\n if(flag==1){\n break;\n }\n }\n if(flag==0){\n System.out.println(-1);\n }\n }\n static class FastReader {\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}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1c0cb3ff3533d74a3a60ecd2141096b0", "src_uid": "3eff6f044c028146bea5f0dfd2870d23", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class sdsdds{\n public static void main(String asdasda[]){\n Scanner s=new Scanner(System.in);\n int a=s.nextInt();\n int b=s.nextInt();\n if(b==a){\n System.out.print(a+\"1 \"+b+\"2\");\n \n }\n else if(b==a+1)\n System.out.print(a+\"9 \"+b+\"0\");\n else\n System.out.print(\"-1\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "765b5ab0142cb34f1b6dd8184a390f26", "src_uid": "3eff6f044c028146bea5f0dfd2870d23", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\n\n_________ _______ _______ _________ _______ _______ ______ _________ _______ ______ _________\n\\__ __/( )( ____ \\|\\ /|\\__ __/|\\ /|( ___ )( )( __ \\ |\\ /|\\__ __/|\\ /|( ____ \\( __ \\ \\__ __/\n ) ( | () () || ( \\/| ) ( | ) ( | ) ( || ( ) || () () || ( \\ )| ) ( | ) ( | ) ( || ( \\/| ( \\ ) ) ( \n | | | || || || (_____ | (___) | | | | | | || (___) || || || || | ) || | _ | | | | | | | || (__ | | ) | | | \n | | | |(_)| |(_____ )| ___ | | | ( ( ) )| ___ || |(_)| || | | || |( )| | | | ( ( ) )| __) | | | | | | \n | | | | | | ) || ( ) | | | \\ \\_/ / | ( ) || | | || | ) || || || | | | \\ \\_/ / | ( | | ) | | | \n___) (___| ) ( |/\\____) || ) ( |___) (___ \\ / | ) ( || ) ( || (__/ )| () () |___) (___ \\ / | (____/\\| (__/ )___) (___\n\\_______/|/ \\|\\_______)|/ \\|\\_______/ \\_/ |/ \\||/ \\|(______/ (_______)\\_______/ \\_/ (_______/(______/ \\_______/\n \n\n import java.util.*;\n public class Problem488A {\n \n \tpublic static void main(String[] args) {\n \tScanner scn= new Scanner(System.in);\n \tlong num=scn.nextInt();\n \t\n \tint i=1;\n \tfor(;;i++) {\n \t\tlong n=num+i;\n \t\tboolean ans=check(n);\n \t\tif(ans)\n \t\t\tbreak;\n \t}\n \tSystem.out.println(i);\n \t}\n \tpublic static boolean check(long n) {\n \t\twhile(n!=0) {\n \t\t\tlong r=n%10;\n \t\t\tif(n>0 && r==8)\n \t\t\t\treturn true;\n \t\t\telse if(n<0 && r==-8)\n \t\t\t\treturn true;\n \t\t\tn=n/10;\n \t\t}\n \t\treturn false;\n \t}\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "363daa0ef31ff870c0f234a6eecb9c5a", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class GigaTower {\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n long a = scan.nextLong(), c = 0;\n while(!(\"\"+a).contains(\"8\"){\n c++;\n a++;\n }\n System.out.println(c);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8020e3dd9e17ca9c517e288a2f9174e3", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class main {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner input=new Scanner(System.in);\n int count=0,temp;\n String n; \n n=input.nextLine();\n int charCount = 0;\n for( int i = 0; i 1)\n {\n n=n.replaceFirst(\"8\",\"9\");\n count++;\n }\n else if(charCount==1&&n.charAt(n.length()-1)=='8')\n {\n n=n.replaceFirst(\"8\",\"9\");\n count++;\n }\n else if(charCount==1)\n {\n count=1; \n }\n \n \n \n \n \n while(!n.contains(\"8\"))\n {\n count++;\n temp=Integer.parseInt(n);\n temp++;\n n=\"\"+temp;\n \n }\n System.out.println(count);\n\n }\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec20a38ac7bb0791679494601aa39dcc", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class problem1 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long guess=-1;\n guess=in.nextLong();\n int j=0;\n while(true){\n j++;\n guess++;\n String temp = new String();\n temp=Long.toString(guess);\n int[] newGuess = new int[temp.length()];\n boolean ok=false;\n for (int i = 0; i < temp.length(); i++)\n {\n newGuess[i] = temp.charAt(i) - '0';\n if(newGuess[i]==8&&j!=0){\n ok=true;\n break;\n }\n }\n\n if(ok){\n break;\n }\n }\n System.out.println(j);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "857067a2dfc3ebe4343b00910e49b1d5", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\nimport static java.lang.Math.*;\n\npublic class C_4 {\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n long a = in.nextInt(), b = in.nextInt();\n ArrayDeque deque = new ArrayDeque<>();\n long d = abs(a - b);\n long sq = (long) sqrt(d);\n for (long i = 1; i <= sq; i++) {\n if (d % i == 0) {\n deque.addLast(i);\n deque.addLast(d / i);\n }\n }\n\n long min = lcm(a, b), k = 0;\n for (long i : deque) {\n long p = i - min(a, b) % i;\n long l = lcm(a + p, b + p);\n if (l < min) {\n min = l;\n k = p;\n } else if (l == min) {\n k = min(k, p);\n }\n }\n\n pw.println(k);\n\n pw.close();\n }\n\n static long gcd(long p, long q) {\n if (q == 0) return p;\n else return gcd(q, p % q);\n }\n\n static long lcm(long p, long q) {\n long g = gcd(p, q);\n p /= g;\n return p * q;\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5a657e73d8795c695f4fe3d498288fca", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\tFastReader scn;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tint n = scn.nextInt();\n\t\tint[] arr = {1, 3, 9, 27, 84, 270, 892, 3012};\n\t\tout.println(arr[--n]);\n\t}\n\t\n\tpublic void run() {\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) {\n\t\tnew Thread(null, new A(), \"Main\", 1 << 26).start();\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\tint c = arr[i];\n\t\t\t\tarr[i] = arr[j];\n\t\t\t\tarr[j] = c;\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[] shuffle(long[] 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\tlong c = arr[i];\n\t\t\t\tarr[i] = arr[j];\n\t\t\t\tarr[j] = c;\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tint[] uniq(int[] arr) {\n\t\t\tArrays.sort(arr);\n\t\t\tint[] rv = new int[arr.length];\n\t\t\tint pos = 0;\n\t\t\trv[pos++] = arr[0];\n\t\t\tfor (int i = 1; i < arr.length; i++) {\n\t\t\t\tif (arr[i] != arr[i - 1]) {\n\t\t\t\t\trv[pos++] = arr[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Arrays.copyOf(rv, pos);\n\t\t}\n\n\t\tlong[] uniq(long[] arr) {\n\t\t\tArrays.sort(arr);\n\t\t\tlong[] rv = new long[arr.length];\n\t\t\tint pos = 0;\n\t\t\trv[pos++] = arr[0];\n\t\t\tfor (int i = 1; i < arr.length; i++) {\n\t\t\t\tif (arr[i] != arr[i - 1]) {\n\t\t\t\t\trv[pos++] = arr[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Arrays.copyOf(rv, pos);\n\t\t}\n\n\t\tint[] reverse(int[] arr) {\n\t\t\tint l = 0, r = arr.length - 1;\n\t\t\twhile (l < r) {\n\t\t\t\tarr[l] = arr[l] ^ arr[r];\n\t\t\t\tarr[r] = arr[l] ^ arr[r];\n\t\t\t\tarr[l] = arr[l] ^ arr[r];\n\t\t\t\tl++;\n\t\t\t\tr--;\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[] reverse(long[] arr) {\n\t\t\tint l = 0, r = arr.length - 1;\n\t\t\twhile (l < r) {\n\t\t\t\tarr[l] = arr[l] ^ arr[r];\n\t\t\t\tarr[r] = arr[l] ^ arr[r];\n\t\t\t\tarr[l] = arr[l] ^ arr[r];\n\t\t\t\tl++;\n\t\t\t\tr--;\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3bfe45330e446d704e8fadf32e30c4ef", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class P1152D {\n\n\tstatic int n;\n\tstatic int MOD = (int)1e9+7;\n\tstatic long[][][] dp1 = new long[1001][1001][2];\n\tstatic int[][] dp2 = new int[1001][1001];\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tn = in.nextInt();\n\t\tfor(int i=0; i<1001; i++) {\n\t\t\tfor(int j=0; j<1001; j++) {\n\t\t\t\tdp2[i][j]=-1;\n\t\t\t\tfor(int k=0; k<2; k++) {\n\t\t\t\t\tdp1[i][j][k]=-1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(solve(0, 0, 0));\n\t}\n\t\n\tpublic static long solve(int i, int unMatched, int last) {\n\t\tif (i==2*n) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp1[i][unMatched][last]!=-1) return dp1[i][unMatched][last];\n\t\tlong ans=0;\n\t\tlong s1, s2, s3, s4;\n\t\ts1=s2=s3=s4=0;\n\t\tif (possible(i+1, unMatched+1)==1) {\n\t\t\ts1 = solve(i+1, unMatched+1, 0);\n\t\t\ts2 = solve(i+1, unMatched+1, 1)+1;\n\t\t} \n\t\tif (possible(i+1, unMatched-1)==1){\n\t\t\ts3 = solve(i+1, unMatched-1, 0);\n\t\t\ts4 = solve(i+1, unMatched-1, 1)+1;\n\t\t}\n\t\t\n\t\t\n\t\tif (last==1) {\n\t\t\tans = Math.max(ans, (s1+s3)%MOD);\n\t\t} else {\n\t\t\tans = Math.max(ans, (s1+s3)%MOD);\n\t\t\tans = Math.max(ans, (s1+s4)%MOD);\n\t\t\tans = Math.max(ans, (s3+s2)%MOD);\n\t\t}\n\t\t\n\t\treturn dp1[i][unMatched][last]=ans;\n\t}\n\t\n\tpublic static int possible(int i, int unMatched) {\n\t\tif (unMatched<0) return 0;\n\t\tif (i==2*n) {\n\t\t\tif (unMatched==0) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (dp2[i][unMatched]!=-1) return dp2[i][unMatched];\n\t\t\n\t\tint p = possible(i+1, unMatched+1)+possible(i+1, unMatched-1);\n\t\treturn dp2[i][unMatched]=(p>0?1:0);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0249666d8cf8b7dbf62b82c8ff2000e4", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\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 Andy Phan (Edited for speedups by AuroraGarden)\n */\npublic class p1152d {\n static long[][][] dp;\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n dp = new long[2][2*n+1][2*n+1];\n for(long a[][]:dp)\n \tfor(long b[]:a)\n \t\tArrays.fill(b, -1);\n System.out.println(traverse(2*n, 0, 0)%1_000_000_007);\n }\n \n public static long traverse(int ind, int diff, int flag) {\n if(ind <= 0 || diff < 0) return 0;\n if(dp[flag][diff][ind] != -1) return dp[flag][diff][ind];\n long num = 0;\n if(flag == 1) {\n if(hasVal(ind-1, diff-1)) num += traverse(ind-1, diff-1, 0);\n if(hasVal(ind-1, diff+1)) num += traverse(ind-1, diff+1, 0);\n if(num >= 1_000_000_007) num -= 1_000_000_007;\n return dp[ind][diff][flag] = num;\n }\n if(hasVal(ind-1, diff-1)) {\n long tmp = traverse(ind-1, diff-1, 1)+1;\n if(hasVal(ind-1, diff+1)) tmp += traverse(ind-1, diff+1, 0);\n num = max(num, tmp);\n }\n if(hasVal(ind-1, diff+1)) {\n long tmp = traverse(ind-1, diff+1, 1)+1;\n if(hasVal(ind-1, diff-1)) tmp += traverse(ind-1, diff-1, 0);\n num = max(num, tmp);\n }\n if(num >= 1_000_000_007) num -= 1_000_000_007;\n return dp[flag][diff][ind] = num;\n }\n static long max(long a, long b) {return a > b ? a : b;}\n \n public static boolean hasVal(int ind, int diff) {\n if(diff < 0) return false;\n return diff <= ind;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "785214c152bc773ffcf8e6dcb134d3b1", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * \n * \u4f5c\u8005\uff1a\u5f20\u5b87\u7fd4\n * \u521b\u5efa\u65e5\u671f\uff1a2017\u5e747\u670816\u65e5 \u4e0b\u534811:04:25\n * \u63cf\u8ff0\uff1a\n */\npublic class Main {\n\n\tprivate static final int Max = (int) (1e2 + 10);\n\tprivate static String []s;\n\tprivate static char [][]a;\n\tpublic static void main(String[] args) {\n\t\tInitData();\n\t\tGetAns();\n\t}\n\tprivate static void InitData() {\n\t\tScanner cin = new Scanner(System.in);\n\t\ts=new String[Max];\n\t\ta=new char[Max][Max];\n\t\tfor(int i=0;i<10;i++){\n\t\t\ts[i]=cin.next();\n\t\t\ta[i]=s[i].toCharArray();\n\t\t}\n\t};\n\n\tprivate static void GetAns() {\n\t\tfor(int i=0;i<10;i++){\n\t\t\tfor(int j=0;j<10;j++){\n\t\t\t\tif(a[i][j]=='.'){\n\t\t\t\t\ta[i][j]='X';\n\t\t\t\t\tif(judge()){\n\t\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\ta[i][j]='.';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t\treturn;\n\t};\n\t\n\tprivate static boolean judge(){\n\t\tfor(int i=0;i<10;i++){//\u5224\u65ad\u6a2a\n\t\t\tfor(int j=0;j<=10-5;j++){\n\t\t\t\tif(a[i][j]=='X'&&a[i][j+1]=='X'&&a[i][j+2]=='X'\n\t\t\t\t\t\t&&a[i][j+3]=='X'&&a[i][j+4]=='X'){\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i<10;i++){//\u5224\u65ad\u7ad6\n\t\t\tfor(int j=0;j<=10-5;j++){\n\t\t\t\tif(a[j][i]=='X'&&a[j+1][i]=='X'&&a[j+2][i]=='X'\n\t\t\t\t\t\t&&a[j+3][i]=='X'&&a[j+4][i]=='X'){\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i=0;i<10;i++){\n\t\t\tfor(int j=0;j<10;j++){\n\t\t\t\tint cnt=0;\n\t\t\t\tif(Check(i, j)){\n\t\t\t\t\tif(a[i][j]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i+1, j+1)){\n\t\t\t\t\tif(a[i+1][j+1]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i+2, j+2)){\n\t\t\t\t\tif(a[i+2][j+2]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i+3, j+3)){\n\t\t\t\t\tif(a[i+3][j+3]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i+4, j+4)){\n\t\t\t\t\tif(a[i+4][j+4]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(cnt==5){\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tfor(int i=0;i<10;i++){\n\t\t\tfor(int j=0;j<10;j++){\n\t\t\t\tint cnt=0;\n\t\t\t\tif(Check(i, j)){\n\t\t\t\t\tif(a[i][j]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i-1, j-1)){\n\t\t\t\t\tif(a[i-1][j-1]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i-2, j-2)){\n\t\t\t\t\tif(a[i-2][j-2]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i-3, j-3)){\n\t\t\t\t\tif(a[i-3][j-3]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(Check(i-4, j-4)){\n\t\t\t\t\tif(a[i-4][j-4]=='X'){\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(cnt==5){\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tprivate static boolean Check(int x,int y){\n\t\tif(x>=0&&x<10&&y>=0&&y<10){\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bdeae90d6b5159a0611e16061e768858", "src_uid": "d5541028a2753c758322c440bdbf9ec6", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "/**\n * @author Finn Lidbetter\n */\nimport java.util.*;\nimport java.io.*;\nimport java.awt.geom.*;\n\npublic class TaskB {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringBuilder sb = new StringBuilder();\n int n = 10;\n char[][] board = new char[n][n];\n for (int i=0; i matrix = new ArrayList<>();\n\n public void setMatrix(ArrayList matrix){\n this.matrix.clear();\n this.matrix.addAll(matrix);\n }\n\n public static void main (String[] args){\n sc = new Scanner(System.in);\n\n createMatrix(0);\n\n if(runTheSearch()){\n System.out.println(\"YES\");\n }else {\n System.out.println(\"NO\");\n }\n\n }\n\n public boolean runTheSearch(){\n boolean hasWinningMove=false;\n\n //search in row\n for(String[] row : matrix){\n hasWinningMove = search(row);\n }\n\n\n //search in column\n for (int i=0; i=0;i--){\n if(i-4>=0){\n String[] combinedArray = new String[5];\n for (int j=0; j<5;j++){\n int columnIndex = i-j;\n if(columnIndex10){\n System.out.printf(\"\u0420\u044f\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c 10 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \");\n createMatrix(index);\n }else {\n matrix.add(row);\n createMatrix(++index);\n }\n }\n }\n private static ArrayList> rows = new ArrayList<>();\n private static boolean search(String[] row){\n int rowLength = row.length;\n for(int i=0; i map = new HashMap<>();\n int itemsCount=i;\n if(i<6){\n while (itemsCount<5+i){\n if(map.containsKey(row[itemsCount])){\n map.put(row[itemsCount],map.get(row[itemsCount])+1);\n }else {\n map.put(row[itemsCount],1);\n }\n itemsCount++;\n }\n rows.add(map);\n }\n }\n\n /*for( Map mapItem : rows){\n System.out.println(mapItem);\n }*/\n\n for( Map mapItem : rows){\n if(mapItem.get(alisa)!=null && mapItem.get(alisa)==4){\n if(mapItem.get(dot)!=null && mapItem.get(dot)==1){\n return true;\n }\n }\n }\n\n return false;\n }\n private static boolean searchInDiagonals(String[] row){\n int rowLength = row.length;\n Map map = new HashMap<>();\n for(int i=0; i st;\n\tlong getNum(int mass[]) {\n\t\tlong res = 0;\n\t\tfor (int i = 1; i < 12; i++) {\n\t\t\tif (mass[i] == 0)\n\t\t\t\tbreak;\n\t\t\tres = res * 10L + mass[i];\n\t\t}\n\t\treturn res;\n\t}\n\tvoid rec(int pos, int mass[]) {\n\t\tif (pos > 11) {\n\t\t\tst.add(getNum(mass));\n\t\t\treturn;\n\t\t}\n\t\tmass[pos] = 0;\n\t\trec(pos + 1, mass);\n\t\tmass[pos] = 4;\n\t\trec(pos + 1, mass);\n\t\tmass[pos] = 0;\n\t\tmass[pos] = 7;\n\t\trec(pos + 1, mass);\n\t\tmass[pos] = 0;\n\t}7\n\tpublic void solve(InputReader in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint len = 0;\n\t\tint temp = n;\n\t\twhile (temp != 0) {\n\t\t\tlen++;\n\t\t\ttemp /= 10;\n\t\t}\n\t\tint dl[] = new int[14];\n\t\tst = new TreeSet();\n\t\trec(1, dl);\n\n\t\tint num = 1;\n\t\tIterator it = st.iterator();\n\t\twhile (it.hasNext()) {\n\t\t\tlong value = (long)it.next();\n\t\t\tif (value == n) {\n\t\t\t\tout.println(num);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tnum++;\n\t\t}\n\t}\n}\n\nclass MainRun {\n\tvoid run(int inF, int outF) {\n//\t\tinF = outF = 0;\n\t\tString input = \"input.txt\";\n//\t\tString input = \"large.in\";\t\n\t\tString output = \"output.txt\";\n//\t\tString output = \"puzzle-2048.out\";\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in;\n\t\tPrintWriter out;\n\t\tif (inF == 1)\t\n\t\t\tin = new InputReader(input);\n\t\telse\n\t\t\tin = new InputReader(inputStream);\n\t\tif (outF == 1)\n\t\t\tout = getPrintWriter(output);\n\t\telse\n\t\t\tout = getPrintWriter(outputStream);\n\t\tTask solver = new Task();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n\tpublic static PrintWriter getPrintWriter(OutputStream stream) {\n\t\treturn new PrintWriter(stream);\n\t}\n\tpublic static PrintWriter getPrintWriter(String f) {\n\t\ttry {\n\t\t\treturn new PrintWriter(new File(f));\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn null;\n\t}\t\n}\n\nclass InputReader {\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tInputReader(InputStream stream) {\n\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\ttokenizer = null;\n\t}\n\tInputReader(String f) {\n\t\ttry {\n\t\t\treader = new BufferedReader(new FileReader(f));\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\ttokenizer = null;\t\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} catch(NullPointerException e) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\tpublic String getLine() {\n\t\ttry {\n\t\t\treturn (String)reader.readLine();\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\treturn \"\";\n\t}\t\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\tpublic char nextChar() {\n\t\treturn next().charAt(0);\n\t}\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 int[] nextIntArray(int n) {\n\t\tint a[] = new int[n + 2];\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\ta[i] = nextInt();\n\t\treturn a;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1eaee07da9849474f6beb4541d20d64f", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class M{\n public static void main(String[] args){\n Scanner s = new Scanner(System.in);\n String st = s.next();\n int n = s.length();\n \tint ans = 1<= 0 ; i--,pos++){\n \t\tif(s.charAt(i) == '7'){\n \t\t\tans += 1<0)\n { \n int x=(int)(Math.pow((double)10,(double)len-1));\n \n \n\n if(temp/x==4)\n {\n high=(low+high)/2;\n \n }\n else\n {\n low=(low+high)/2+1;\n \n }\n len--;\n temp=temp%x;\n x=x/10;\n \n }\n return low;\n }\n \n public int find_length()\n {\n int temp=num;\n int len=0;\n while(temp>0)\n {\n temp=temp/10;\n len++; \n }\n \n return len;\n }\n \n public void set_num(int a)\n {\n num=a;\n }\n \n}\n public class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n int num;\n \n Scanner in=new Scanner(System.in);\n num=in.nextInt();\n \n question2 obj1=new question2();\n obj1.set_num(num);\n System.out.println(obj1.find_rank());\n \n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c33c5c167397ccfb28d89dab60e70f67", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class Test5 {\nuto-generated method stub\n \n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f4d473dab04bafa84d24466f92919f2", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class SantaClauseAndAPlaceInClass {\n public static void main(String[] args){\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int m = scanner.nextInt();\n int k = scanner.nextInt();\n int counter = 2;\n char l = 'L';\n char r = 'R';\n int[][] workingPlaces = new int[n][m];\n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++){\n workingPlaces[i][j] = counter;\n counter += 2;\n }\n }\n for(int i =0; i < n; i++){\n for(int j = 0; j < m; j++){\n if((k - workingPlaces[i][j]) == 0 || (k - workingPlaces[i][j] == -1)){\n if(k % 2 == 0){\n System.out.println((i + 1) + \" \" + (j + 1)+\" \" + r);\n }else{\n System.out.println((i + 1) + \" \" + (j + 1)+\" \" + l);\n }\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ebddde2c876a515fcb4f3d763f57d99c", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class A{\n public static void main(String[] args) throws Exception{\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in);\n \n StringTokenizer st = new StringTokenizer st(f.readLine());\n \n double l = Double.parseDouble(f.readLine());\n double d = Double.parseDouble(f.readLine());\n double n = Double.parseDouble(f.readLine());\n \n System.out.println(Math.ceil(n/2d) + \" \" + (n%(2d)) == 0?d: (Math.ceil((n%(2d))/2)) + \" \" + (n%2 == 0)?R:L);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "58ea9582c0658e237050a15b10299d5b", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class A{\n public static void main(String[] args){\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in);\n \n StringTokenizer st = new StringTokenizer st(f.readLine());\n \n double l = Double.parseDouble(f.readLine());\n double d = Double.parseDouble(f.readLine());\n double n = Double.parseDouble(f.readLine());\n \n System.out.println(Math.ceil(n/2d) + \" \" + (n%(2d)) == 0?d: (Math.ceil((n%(2d))/2)) + \" \" + (n%2 == 0)?R:L);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "20f4189d9eec74575910047472f34a11", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class A{\n public static void main(String[] args) throws Exception{\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n \n StringTokenizer st = new StringTokenizer st(f.readLine());\n \n double l = Double.parseDouble(st.nextToken());\n double d = Double.parseDouble(st.nextToken());\n double n = Double.parseDouble(st.nextToken());\n \n System.out.println((int)(Math.ceil(n/2/d)) + \" \" + (int)((n%(2*d)) == 0?d:(Math.ceil((n%(2*d))/2))) + \" \" + ((n%2 == 0)?R:L));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5aae9b68510b274daac570bfb024f39f", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class ADimaandFriends {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt(), sum = 0 , count = 0 ;\n\t\tint[] x = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsum = sum + scan.nextInt();\n\t\t}\n\t\tfor (int i = 1; i <= 5; i++) {\n\t\t\tif(sum+i % n+1 == 0){\n\t\t\t\tcount ++;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.println(count);\n\t\t\tscan.close();\n\t\t}\n\n\t}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b33c590dce23b92ddeb48af43b59a51e", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\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 Adrian\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\tInput in = new Input(inputStream);\n\t\tOutput out = new Output(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, Input in, Output out)\n {\n int n = in.nextInt();\n int k = in.nextInt();\n for (int i = 1; i < n; i++) k += in.nextInt();\n int total = k+5;\n n++;\n int ways = 0;\n while (++k <= total)\n if (k % n != 1)\n ways++;\n out.println(ways);\n }\n}\n\nclass Input\n{\n final int SIZE = 8192;\n private InputStream in;\n private byte[] buf = new byte[SIZE];\n private int last, current, total;\n\n public Input(InputStream stream) throws IOException\n {\n in = stream;\n last = read();\n }\n\n int read()\n {\n if (total == -1) return -1;\n if (current >= total)\n {\n current = 0;\n try\n {\n total = in.read(buf);\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n if (total <= 0) return -1;\n }\n return buf[current++];\n }\n\n void advance()\n {\n while (true)\n {\n if (last == -1) return;\n if (!isValidChar(last)) last = read();\n else break;\n }\n }\n\n boolean isValidChar(int c)\n {\n return c > 32 && c < 127;\n }\n\n public boolean eof()\n {\n advance();\n return last == -1;\n }\n\n public String nextString()\n {\n advance();\n if (last == -1) return null;\n StringBuilder s = new StringBuilder();\n while (true)\n {\n s.appendCodePoint(last);\n last = read();\n if (!isValidChar(last)) break;\n }\n return s.toString();\n }\n\n String nextLine()\n {\n if (last == -1) return null;\n StringBuilder s = new StringBuilder();\n while (true)\n {\n s.appendCodePoint(last);\n last = read();\n if (last == '\\n' || last == -1) break;\n }\n return s.toString();\n }\n\n public String nextLine(boolean ignoreIfEmpty)\n {\n if (!ignoreIfEmpty) return nextLine();\n String s = nextLine();\n while (s.trim().length() == 0) s = nextLine();\n return s;\n }\n\n public int nextInt()\n {\n advance();\n int n = 0, s = 1;\n if (last == '-')\n {\n s = -1;\n last = read();\n }\n while (true)\n {\n n = n * 10 + last - '0';\n last = read();\n if (!isValidChar(last)) break;\n }\n return n * s;\n }\n\n public long nextLong()\n {\n advance();\n int s = 1;\n if (last == '-')\n {\n s = -1;\n last = read();\n }\n long n = 0;\n while (true)\n {\n n = n * 10 + last - '0';\n last = read();\n if (!isValidChar(last)) break;\n }\n return n * s;\n }\n\n public BigInteger nextBigInt()\n {\n return new BigInteger(nextString());\n }\n\n public char nextChar()\n {\n advance();\n return (char) last;\n }\n\n public double nextDouble()\n {\n advance();\n int s = 1;\n if (last == '-')\n {\n s = -1;\n last = read();\n }\n double n = 0;\n while (true)\n {\n n = n * 10 + last - '0';\n last = read();\n if (!isValidChar(last) || last == '.') break;\n }\n if (last == '.')\n {\n last = read();\n double m = 1;\n while (true)\n {\n m = m / 10;\n n = n + (last - '0') * m;\n last = read();\n if (!isValidChar(last)) break;\n }\n }\n return n * s;\n }\n\n public BigDecimal nextBigDecimal()\n {\n return new BigDecimal(nextString());\n }\n\n public void close()\n {\n try\n {\n in.close();\n } catch (IOException e)\n {\n e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\n }\n in = null;\n }\n}\n\nclass Output\n{\n final int SIZE = 8192;\n private Writer out;\n private char cb[] = new char[SIZE];\n private int nChars = SIZE, nextChar = 0;\n private char lineSeparator = '\\n';\n\n public Output(OutputStream stream)\n {\n out = new OutputStreamWriter(stream);\n }\n\n public Output(Writer writer)\n {\n out = writer;\n }\n\n void flushBuffer()\n {\n if (nextChar == 0) return;\n try\n {\n out.write(cb, 0, nextChar);\n } catch (IOException e)\n {\n e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\n }\n nextChar = 0;\n }\n\n void write(int c)\n {\n if (nextChar >= nChars) flushBuffer();\n cb[nextChar++] = (char) c;\n }\n\n void write(String s, int off, int len)\n {\n int b = off, t = off + len;\n while (b < t)\n {\n int a = nChars - nextChar, a1 = t - b;\n\n int d = a < a1 ? a : a1;\n s.getChars(b, b + d, cb, nextChar);\n b += d;\n nextChar += d;\n if (nextChar >= nChars) flushBuffer();\n }\n }\n\n void write(String s)\n {\n try\n {\n out.write(s);\n } catch (IOException e)\n {\n e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\n }\n }\n\n public void print(Object obj)\n {\n write(String.valueOf(obj));\n }\n\n public void println(Object obj)\n {\n write(String.valueOf(obj));\n write(lineSeparator);\n }\n\n public void printf(String format, Object... obj)\n {\n write(String.format(format, obj));\n }\n\n public void close()\n {\n flushBuffer();\n try\n {\n out.flush();\n out.close();\n } catch (IOException e)\n {\n e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fe09aa51a27f16ad29cb66e8da8767cf", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "\npublic class Proba {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int ans = 0;\n for (int i = 0; i < n; i++) {\n ans += sc.nextInt();\n }\n if (ans%(n+1) == 1){\n System.out.println(\"1\");return;\n }\n System.out.println(2);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4e2cc0c8518f7483149bd7ddbbc48bc5", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.uitl.*;\npublic class Main{\n public static void main(String[] args){\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int count=0;\n for(int i=0;i list = new ArrayList();\n\t\t\n\t\tfor(int i=0;i ans = new ArrayList();\n\n Queue q = new LinkedList();\n q.add(root);\n \n while (!q.isEmpty()) {\n int qSize = q.size();\n for (int i = 0; i < qSize; i++) {\n TreeNode node = q.poll();\n ans.add(node.val);\n if (node.left != null)\n q.offer(node.left);\n if (node.right != null)\n q.offer(node.right);\n }\n ans.add(Integer.MIN_VALUE);\n }\n\n int i = ans.size() - 1;\n while(true){\n int k = ans.get(i);\n if(k == Integer.MIN_VALUE && i != ans.size() - 1){\n return ans.get(i + 1);\n }\n i--;\n }\n }\n public static List largestValues(TreeNode root) {\n List ans = new ArrayList();\n Queue q = new LinkedList();\n q.add(root);\n int i = 1;\n int lastDepth = 0;\n int max = -1;\n while(!q.isEmpty()){\n TreeNode tempNode = q.poll();\n int depth = (int)(Math.log(i) / Math.log(2));\n if(lastDepth != depth){\n lastDepth = depth;\n ans.add(max);\n max = -1;\n }\n if(tempNode != null){\n if(tempNode.val > max)\n max = tempNode.val;\n }\n q.add(tempNode.left);\n q.add(tempNode.right);\n \n i++;\n }\n if(max != -1)\n ans.add(max);\n return ans;\n }\n \n class CF994A {\n public void solve() throws IOException {\n Input in = new Input();\n int n = in.nextInt();\n int m = in.nextInt();\n int[] seq = new int[n];\n for(int i = 0; i < n; i++){\n seq[i] = in.nextInt();\n }\n HashSet prints = new HashSet();\n for(int i = 0; i < m; i++){\n prints.add(in.nextInt());\n }\n String out = \"\";\n for(int i = 0; i < seq.length; i++){\n if(prints.contains(seq[i]))\n out += seq[i] + \" \";\n }\n if(out.length() > 0){\n System.out.println(out.trim());\n } else System.out.println(\"\");\n }\n }\n}\n\nclass TreeNode {\n int val;\n TreeNode left;\n TreeNode right;\n TreeNode(int x) { val = x; }\n }\nclass NullNode extends TreeNode{\n public NullNode(){\n super(-1);\n this.left = new NullNode();\n this.right = new NullNode();\n }\n}\nclass Solution {\n public int findBottomLeftValue(TreeNode root) {\n return answer(root);\n }\n public int answer(TreeNode node){\n Answer a = new Answer();\n traverse(node, 0, a, true);\n if(a.ans != null)\n return a.ans.val;\n return -1;\n }\n public void traverse(TreeNode node, int level, Answer a, boolean isLeft){\n if(node == null)\n return;\n if(isLeft && node.left == null && node.right == null && level > a.maxDepth){\n a.ans = node;\n a.maxDepth = level;\n }\n traverse(node.left, level + 1, a, true);\n traverse(node.right, level + 1, a, false);\n }\n}\nclass Answer {\n public TreeNode ans = null;\n public int maxDepth = -1;\n}\nclass CF909_A {\n public void solve(){\n Scanner sc = new Scanner(System.in);\n String s = sc.nextLine();\n String[] names = s.split(\" \");\n String output = \"\";\n int i, j = i = 0;\n while(true){\n if(i == 0){\n output += names[0].charAt(i++);\n }\n if(i >= names[0].length()){\n output += names[1].charAt(j);\n break;\n }\n if(names[1].charAt(j) < names[0].charAt(i)){\n output += names[1].charAt(j);\n break;\n }\n else {\n output += names[0].charAt(i++);\n }\n }\n System.out.println(output);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "db4031eba1ad62dd7af624d405a7d262", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n * Created with IntelliJ IDEA.\n * User: Aditya\n * Date: 6/18/14\n * Time: 2:21 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class game {\n\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n\n char[] teamOne = sc.nextLine().toCharArray();\n char[] teamTwo = sc.nextLine().toCharArray();\n\n int teamTwoCount = 0;\n int teamOneCount = 0;\n\n for (int i=0;iteamTwoCount){\n System.out.println(\"TEAM 1 WINS\");\n }\n else if(teamOneCountt2Score){\n System.out.print(\"TEAM 1 WINS\");\n }\n else if(t2Score>t1Score){\n System.out.print(\"TEAM 2 WINS\");\n }\n else{\n System.out.print(\"TIE\");\n }\n //Process char\n }\n \n\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f09a7e7faf84456b2594faa76f46ea8c", "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.*\n\npublic class JavaApplication6 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n String t1 = \"[]()[]8<\";//in.nextLine();\n String t2 = \"8<[]()8<\";//in.nextLine();\n \n int t1Score = 0;\n int t2Score = 0;\n \n for (int i = 0; i < t1.length(); i+=2){\n char c1 = t1.charAt(i); \n char c2 = t2.charAt(i);\n \n if(c1=='['){\n if(c1=='8'){\n t2Score++;\n }\n else if(c2=='('){\n t1Score++;\n }\n }\n else if(c1== '('){\n if(c2=='['){\n t2Score++;\n }\n else if(c2=='8'){\n t1Score++;\n }\n \n }\n else{\n if(c2=='['){\n t1Score++;\n }\n if(c2=='('){\n t2Score++;\n }\n }\n \n if(t1Score>t2Score){\n System.out.print(\"TEAM 1 WINS\");\n }\n else if(t2Score>t1Score){\n System.out.print(\"TEAM 2 WINS\");\n }\n else{\n System.out.print(\"TIE\");\n }\n }\n \n\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "22d7cc0b038a226ccc49e9de2445d660", "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "public class das_lab2 {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s1 = sc.nextLine();\n\t\tString s2 = sc.nextLine();\n\t\tint sum1 = 0;\n\t\tint sum2 = 0;\n\t\tfor (int i = 0; i < s1.length(); i += 2) {\n\t\t\tString l1 = s1.substring(i, i + 2), l2 = s2.substring(i, i + 2);\n\t\t\tif (!l1.equals(l2)) {\n\t\t\t\tif (l1.equals(\"8<\") && l2.equals(\"()\") || l1.equals(\"()\")\n\t\t\t\t\t\t&& l2.equals(\"[]\"))\n\t\t\t\t\tsum1++;\n\t\t\t\telse\n\t\t\t\t\tsum2++;\n\t\t\t}\n\t\t}\n\t\tif (sum1 > sum2)\n\t\t\tSystem.out.println(\"TEAM 1 WINS\");\n\t\telse if (sum1 < sum2)\n\t\t\tSystem.out.println(\"TEAM 2 WINS\");\n\t\telse\n\t\t\tSystem.out.println(\"TIE\");\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c6bda632af959cc5e9934d5106ad02ed", "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Test {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc =new Scanner(System.in);\n\t\tlong s =sc.nextLong();\n\t\tlong x =sc.nextLong();\n\t\tlong or =s+x;\n\t\tlong and =s-x;\n\t\tlong tot=1;\n\t\tif((or & 1) ==0 && (and & 1)==0){\n\t\t\tor = or>>1;\n\t\t\tand =and>>1;\n\t\t\twhile(and!=0 && or!=0){\n\t\t\t\tif(and%2!=1){\n\t\t\t\t\tif(or%2!=0){\n\t\t\t\t\t\ttot<<=1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(tot);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(0);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "02a1d316ddf9d73c52943b4b97db875e", "src_uid": "18410980789b14c128dd6adfa501aea5", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\n\nimport javafx.util.Pair;\n\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 a672 solver = new a672();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class a672 {\n HashSet> ans;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long s = in.nextLong();\n long x = in.nextLong();\n ans = new HashSet<>();\n comb(0, 0, s, x);\n for (int i = 0; i < 50; i++) {\n if (s == ((1L << i) - 1) && s == x) {\n out.println((1L << i) - 2);\n return;\n }\n }\n out.println(ans.size());\n }\n\n void comb(long num, int bit, long sum, long xor) {\n if (bit >= 40) {\n if (num > 0 && (num ^ xor) > 0 && num + (num ^ xor) == sum) {\n ans.add(new Pair<>(num, (num ^ xor)));\n }\n return;\n }\n long tail = num;\n long xorTail = (num ^ xor) & ((1L << bit) - 1);\n long upSum = sum - tail - xorTail;\n if ((upSum & ((1L << bit) - 1)) != 0) {\n return;\n }\n comb(num, bit + 1, sum, xor);\n comb(num | (1L << bit), bit + 1, sum, xor);\n }\n\n }\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String next() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0550c61003d3b451156a2fc3bbf3f4c8", "src_uid": "18410980789b14c128dd6adfa501aea5", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class sonu\n{\n\n static int count(long n){\n int c=0;\n while(n>0)\n { c++; n=n/2; }\n return(c);\n }\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n \n long s = sc.nextLong();\n long x = sc.nextLong();\n long ans=0;\n if((s-x)%2==1||(s-x)%2==-1)\n ans=0;\n else\n { \n long and = (s-x)/2;\n if(x==0)\n ans=1;\n int c = count(x);\n for(int i=0;i0)\n ans=ans-2;\n }\n System.out.println(ans);\n }\n static class Reader \n { \n final private int BUFFER_SIZE = 1 << 16; \n private DataInputStream din; \n private byte[] buffer; \n private int bufferPointer, bytesRead; \n \n public Reader() \n { \n din = new DataInputStream(System.in); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public Reader(String file_name) throws IOException \n { \n din = new DataInputStream(new FileInputStream(file_name)); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public String readLine() throws IOException \n { \n byte[] buf = new byte[64]; // line length \n int cnt = 0, c; \n while ((c = read()) != -1) \n { \n if (c == '\\n') \n break; \n buf[cnt++] = (byte) c; \n } \n return new String(buf, 0, cnt); \n } \n \n public int nextInt() throws IOException \n { \n int ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do\n { \n ret = ret * 10 + c - '0'; \n } while ((c = read()) >= '0' && c <= '9'); \n \n if (neg) \n return -ret; \n return ret; \n } \n \n public long nextLong() throws IOException \n { \n long ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n if (neg) \n return -ret; \n return ret; \n } \n \n public double nextDouble() throws IOException \n { \n double ret = 0, div = 1; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n \n if (c == '.') \n { \n while ((c = read()) >= '0' && c <= '9') \n { \n ret += (c - '0') / (div *= 10); \n } \n } \n \n if (neg) \n return -ret; \n return ret; \n } \n \n private void fillBuffer() throws IOException \n { \n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); \n if (bytesRead == -1) \n buffer[0] = -1; \n } \n \n private byte read() throws IOException \n { \n if (bufferPointer == bytesRead) \n fillBuffer(); \n return buffer[bufferPointer++]; \n } \n public void close() throws IOException \n { \n if (din == null) \n return; \n din.close(); \n } \n }\n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "caeb29fd3a5dd0f911a1b2907673ea9a", "src_uid": "18410980789b14c128dd6adfa501aea5", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n// for (int s = 2; s <= 5; ++s) {\n// for (int x = 0; x <= 5; ++x) {\n// long r1 = f(s + 1000, x + 1000);\n// long r2 = f2(s + 1000, x + 1000);\n// if (r1 != r2) {\n// System.out.printf(\"%d %d %d %d\\n\", s, x, r1, r2);\n// return;\n// }\n// }\n// out.println();\n// }\n long s = in.nextLong();\n long x = in.nextLong();\n out.println(f2(s, x));\n }\n\n long f2(long s, long x) {\n int[] cnt = new int[1 << 21];\n long rx = x & ((1 << 20) - 1);\n for (long ra = 0; ra < (1 << 20); ++ra) {\n long rb = rx ^ ra;\n ++cnt[(int) (ra + rb)];\n }\n long lx = x >> 20;\n long res = 0;\n for (long la = 0; la < (1 << 20); ++la) {\n long lb = lx ^ la;\n long rem = s - (la << 20) - (lb << 20);\n if (rem > 0 && rem < cnt.length) {\n res += cnt[(int) rem];\n }\n }\n if (s == x) {\n res -= 2;\n }\n return res;\n }\n\n }\n\n static class InputReader {\n BufferedReader bufReader;\n StringTokenizer stringTokenizer;\n boolean isEof = false;\n\n public InputReader(InputStream stream) {\n bufReader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n try {\n String line = bufReader.readLine();\n if (line == null) {\n isEof = true;\n return null;\n }\n stringTokenizer = new StringTokenizer(line);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n return stringTokenizer.nextToken();\n }\n\n public long nextLong() {\n String s = next();\n if (s == null) {\n return 0;\n }\n return Long.parseLong(s);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "67f751ab4e4c3c719f2393fe9485c53f", "src_uid": "18410980789b14c128dd6adfa501aea5", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class Solution {\r\n\r\n// private static final String checkerSolutionOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.solution.out\";\r\n// private static final String checkerInput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.in\";\r\n// private static final String checkerBruteforcesOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.bruteforces.out\";\r\n// private static final String fileInput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_in\";\r\n// private static final String fileOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_in\";\r\n\r\n\r\n private static class Config {\r\n static final boolean useInputFile = true;\r\n static final boolean useOutputFile = true;\r\n static final String inputFile = \"\";\r\n static final String outputFile = \"\";\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n run();\r\n }\r\n\r\n public static void run() throws Exception {\r\n FastScanner sc = new FastScanner();\r\n int t = 1;\r\n BufferedWriter writer = getWriter();\r\n for (int i = 0; i < t; i++)\r\n solve(sc, writer);\r\n writer.flush();\r\n }\r\n\r\n public static void solve(FastScanner sc, BufferedWriter writer) throws Exception {\r\n int n = sc.nextInt();\r\n long k = sc.nextLong();\r\n long[] dp = new long[n + 1];\r\n long sum = 1;\r\n dp[1] = 1;\r\n dp[2] = 2;\r\n for (int x = 3; x <= n; x++) {\r\n sum += dp[x - 1];\r\n sum %= k;\r\n dp[x] += sum;\r\n for (int z = 2; z <= (int) (Math.ceil(Math.sqrt(x))); z++) {\r\n dp[x] += dp[Math.floorDiv(x, z)];\r\n dp[x] %= k;\r\n }\r\n for (int z = (int) (Math.ceil(Math.sqrt(x)) + 1); z <= x; z++) {\r\n dp[x] += dp[Math.floorDiv(x, z)];\r\n dp[x] %= k;\r\n }\r\n }\r\n\r\n writer.write(dp[n] + \"\\n\");\r\n }\r\n\r\n private static class FastScanner {\r\n\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n private FastScanner() throws FileNotFoundException {\r\n if (Config.useInputFile)\r\n this.br = new BufferedReader(new InputStreamReader(new FileInputStream(Config.inputFile)));\r\n else\r\n this.br = new BufferedReader(new InputStreamReader(System.in));\r\n this.st = new StringTokenizer(\"\");\r\n }\r\n\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\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\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n }\r\n\r\n private static BufferedWriter getWriter() throws Exception {\r\n if (Config.useOutputFile)\r\n return getFileWriter();\r\n return getConsoleWriter();\r\n }\r\n\r\n private static BufferedWriter getFileWriter() throws Exception {\r\n PrintWriter writer = new PrintWriter(Config.outputFile);\r\n writer.print(\"\");\r\n writer.close();\r\n return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(Config.outputFile)));\r\n }\r\n\r\n private static BufferedWriter getConsoleWriter() {\r\n return new BufferedWriter(new OutputStreamWriter(System.out));\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "82f22e0bfcc7c2b8fa39f0f1659753be", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class Solution {\r\n\r\n private static final String checkerSolutionOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.solution.out\";\r\n private static final String checkerInput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.in\";\r\n private static final String checkerBruteforcesOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.bruteforces.out\";\r\n private static final String fileInput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_in\";\r\n private static final String fileOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_in\";\r\n\r\n\r\n private static class Config {\r\n static final boolean useInputFile = true;\r\n static final boolean useOutputFile = true;\r\n static final String inputFile = checkerInput;\r\n static final String outputFile = checkerSolutionOutput;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n run();\r\n }\r\n\r\n public static void run() throws Exception {\r\n FastScanner sc = new FastScanner();\r\n int t = 1;\r\n BufferedWriter writer = getWriter();\r\n for (int i = 0; i < t; i++)\r\n solve(sc, writer);\r\n writer.flush();\r\n }\r\n\r\n public static void solve(FastScanner sc, BufferedWriter writer) throws Exception {\r\n int n = sc.nextInt();\r\n long k = sc.nextLong();\r\n long[] dp = new long[n + 1];\r\n long sum = 1;\r\n dp[1] = 1;\r\n dp[2] = 2;\r\n for (int x = 3; x <= n; x++) {\r\n sum += dp[x - 1];\r\n sum %= k;\r\n dp[x] += sum;\r\n for (int z = 2; z <= (int) (Math.ceil(Math.sqrt(x))); z++) {\r\n dp[x] += dp[Math.floorDiv(x, z)];\r\n dp[x] %= k;\r\n }\r\n for (int z = (int) (Math.ceil(Math.sqrt(x)) + 1); z <= x; z++) {\r\n dp[x] += dp[Math.floorDiv(x, z)];\r\n dp[x] %= k;\r\n }\r\n }\r\n\r\n writer.write(dp[n] + \"\\n\");\r\n }\r\n\r\n private static class FastScanner {\r\n\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n private FastScanner() throws FileNotFoundException {\r\n if (Config.useInputFile)\r\n this.br = new BufferedReader(new InputStreamReader(new FileInputStream(Config.inputFile)));\r\n else\r\n this.br = new BufferedReader(new InputStreamReader(System.in));\r\n this.st = new StringTokenizer(\"\");\r\n }\r\n\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\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\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n }\r\n\r\n private static BufferedWriter getWriter() throws Exception {\r\n if (Config.useOutputFile)\r\n return getFileWriter();\r\n return getConsoleWriter();\r\n }\r\n\r\n private static BufferedWriter getFileWriter() throws Exception {\r\n PrintWriter writer = new PrintWriter(Config.outputFile);\r\n writer.print(\"\");\r\n writer.close();\r\n return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(Config.outputFile)));\r\n }\r\n\r\n private static BufferedWriter getConsoleWriter() {\r\n return new BufferedWriter(new OutputStreamWriter(System.out));\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3996bae2ef992a68079a2c794a60724b", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.StringTokenizer;\r\n\r\nimport static java.lang.Math.*;\r\n\r\npublic class Solution {\r\n\r\n private static final String checkerSolutionOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.solution.out\";\r\n private static final String checkerInput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.in\";\r\n private static final String checkerBruteforcesOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_checker.bruteforces.out\";\r\n private static final String fileInput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_in\";\r\n private static final String fileOutput = System.getProperty(\"user.dir\") + \"\\\\src\\\\_in\";\r\n\r\n\r\n private static class Config {\r\n static final boolean useInputFile = false;\r\n static final boolean useOutputFile = false;\r\n static final String inputFile = fileInput;\r\n static final String outputFile = fileOutput;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n run();\r\n }\r\n\r\n public static void run() throws Exception {\r\n FastScanner sc = new FastScanner();\r\n int t = 1;\r\n BufferedWriter writer = getWriter();\r\n for (int i = 0; i < t; i++)\r\n solve(sc, writer);\r\n writer.flush();\r\n }\r\n\r\n public static void solve(FastScanner sc, BufferedWriter writer) throws Exception {\r\n int n = sc.nextInt();\r\n long k = sc.nextLong();\r\n long[] dp = new long[n + 1];\r\n long sum = 1;\r\n dp[1] = 1;\r\n dp[2] = 2;\r\n for (int x = 3; x <= n; x++) {\r\n sum += dp[x - 1];\r\n sum %= k;\r\n dp[x] += sum;\r\n for (int z = 2; z <= (int) (ceil(sqrt(x))); z++) {\r\n dp[x] += dp[floorDiv(x, z)];\r\n dp[x] %= k;\r\n }\r\n for (int z = (int) (ceil(sqrt(x)) + 1); z <= x; z++) {\r\n dp[x] += dp[floorDiv(x, z)];\r\n dp[x] %= k;\r\n }\r\n }\r\n\r\n writer.write(dp[n] + \"\\n\");\r\n }\r\n\r\n private static class FastScanner {\r\n\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n private FastScanner() throws FileNotFoundException {\r\n if (Config.useInputFile)\r\n this.br = new BufferedReader(new InputStreamReader(new FileInputStream(Config.inputFile)));\r\n else\r\n this.br = new BufferedReader(new InputStreamReader(System.in));\r\n this.st = new StringTokenizer(\"\");\r\n }\r\n\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\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\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n }\r\n\r\n private static BufferedWriter getWriter() throws Exception {\r\n if (Config.useOutputFile)\r\n return getFileWriter();\r\n return getConsoleWriter();\r\n }\r\n\r\n private static BufferedWriter getFileWriter() throws Exception {\r\n PrintWriter writer = new PrintWriter(Config.outputFile);\r\n writer.print(\"\");\r\n writer.close();\r\n return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(Config.outputFile)));\r\n }\r\n\r\n private static BufferedWriter getConsoleWriter() {\r\n return new BufferedWriter(new OutputStreamWriter(System.out));\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fb2a18e9b784988d9fe11659f23119ed", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\n\r\nimport javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;\r\n\r\nimport org.omg.CORBA.PUBLIC_MEMBER;\r\n\r\nimport java.io.*;\r\nimport java.math.*;\r\nimport java.awt.geom.*;\r\n\r\nimport static java.lang.Math.*;\r\n\r\npublic class Solution implements Runnable {\r\n\r\n\tlong mod1 = (long) 1e9 + 7;\r\n\tint mod2 = 998244353;\r\n\r\n\tpublic void solve() throws Exception {\r\n\t\t\tint n=sc.nextInt(); long mod=sc.nextLong();\r\n\t\t\tlong dp[] = new long[n+1];\r\n\t\t\tout.println(ans(n, mod, dp));\r\n\t}\r\n\t\r\n\tpublic long ans(int n, long mod, long dp[]) {\r\n\t\tif(n==1) return 1;\r\n\t\tlong res=0;\r\n\t\tif(dp[n]!=0) return dp[n];\r\n\t\tfor(int i=1;i l = new ArrayList<>();\r\n\t\tfor (int i : a)\r\n\t\t\tl.add(i);\r\n\t\tCollections.sort(l);\r\n\t\tfor (int i = 0; i < a.length; i++)\r\n\t\t\ta[i] = l.get(i);\r\n\t}\r\n\r\n\tstatic long ncr(int n, int r, long p) {\r\n\t\tif (r > n)\r\n\t\t\treturn 0l;\r\n\t\tif (r > n - r)\r\n\t\t\tr = n - r;\r\n\r\n\t\tlong C[] = new long[r + 1];\r\n\r\n\t\tC[0] = 1;\r\n\r\n\t\tfor (int i = 1; i <= n; i++) {\r\n\r\n\t\t\tfor (int j = Math.min(i, r); j > 0; j--)\r\n\t\t\t\tC[j] = (C[j] + C[j - 1]) % p;\r\n\t\t}\r\n\t\treturn C[r] % p;\r\n\t}\r\n\r\n\tvoid sieveOfEratosthenes(boolean prime[], int size) {\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\tprime[i] = true;\r\n\r\n\t\tfor (int p = 2; p * p < size; p++) {\r\n\t\t\tif (prime[p] == true) {\r\n\t\t\t\tfor (int i = p * p; i < size; i += p)\r\n\t\t\t\t\tprime[i] = false;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int LowerBound(int a[], int x) { // smallest index having value >= x\r\n\t\tint l = -1, r = a.length;\r\n\t\twhile (l + 1 < r) {\r\n\t\t\tint m = (l + r) >>> 1;\r\n\t\t\tif (a[m] >= x)\r\n\t\t\t\tr = m;\r\n\t\t\telse\r\n\t\t\t\tl = m;\r\n\t\t}\r\n\t\treturn r;\r\n\t}\r\n\r\n\tstatic int UpperBound(int a[], int x) {// biggest index having value <= x\r\n\t\tint l = -1, r = a.length;\r\n\t\twhile (l + 1 < r) {\r\n\t\t\tint m = (l + r) >>> 1;\r\n\t\t\tif (a[m] <= x)\r\n\t\t\t\tl = m;\r\n\t\t\telse\r\n\t\t\t\tr = m;\r\n\t\t}\r\n\t\treturn l + 1;\r\n\t}\r\n\r\n\tpublic long power(long x, long y, long p) {\r\n\t\tlong res = 1;\r\n\t\t// out.println(x+\" \"+y);\r\n\t\tx = x % p;\r\n\t\tif (x == 0)\r\n\t\t\treturn 0;\r\n\r\n\t\twhile (y > 0) {\r\n\t\t\tif ((y & 1) == 1)\r\n\t\t\t\tres = (res * x) % p;\r\n\t\t\ty = y >> 1;\r\n\t\t\tx = (x * x) % p;\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\r\n\tstatic Throwable uncaught;\r\n\r\n\tBufferedReader in;\r\n\tFastScanner sc;\r\n\tPrintWriter out;\r\n\r\n\t@Override\r\n\tpublic void run() {\r\n\t\ttry {\r\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\tout = new PrintWriter(System.out);\r\n\t\t\tsc = new FastScanner(in);\r\n\t\t\tsolve();\r\n\t\t} catch (Throwable uncaught) {\r\n\t\t\tSolution.uncaught = uncaught;\r\n\t\t} finally {\r\n\t\t\tout.close();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static void main(String[] args) throws Throwable {\r\n\t\tThread thread = new Thread(null, new Solution(), \"\", (1 << 26));\r\n\t\tthread.start();\r\n\t\tthread.join();\r\n\t\tif (Solution.uncaught != null) {\r\n\t\t\tthrow Solution.uncaught;\r\n\t\t}\r\n\t}\r\n\r\n}\r\n\r\nclass FastScanner {\r\n\r\n\tBufferedReader in;\r\n\tStringTokenizer st;\r\n\r\n\tpublic FastScanner(BufferedReader in) {\r\n\t\tthis.in = in;\r\n\t}\r\n\r\n\tpublic String nextToken() throws Exception {\r\n\t\twhile (st == null || !st.hasMoreTokens()) {\r\n\t\t\tst = new StringTokenizer(in.readLine());\r\n\t\t}\r\n\t\treturn st.nextToken();\r\n\t}\r\n\r\n\tpublic int nextInt() throws Exception {\r\n\t\treturn Integer.parseInt(nextToken());\r\n\t}\r\n\r\n\tpublic int[] readArray(int n) throws Exception {\r\n\t\tint[] a = new int[n];\r\n\t\tfor (int i = 0; i < n; i++)\r\n\t\t\ta[i] = nextInt();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tpublic long nextLong() throws Exception {\r\n\t\treturn Long.parseLong(nextToken());\r\n\t}\r\n\r\n\tpublic double nextDouble() throws Exception {\r\n\t\treturn Double.parseDouble(nextToken());\r\n\t}\r\n\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ca1a68bd199bb5def6f47080aec06e6", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C329D\n{\n\nprivate static StringTokenizer st;\n \n public static void nextLine(BufferedReader br) throws IOException\n {\n st = new StringTokenizer(br.readLine());\n }\n \n public static int nextInt()\n {\n return Integer.parseInt(st.nextToken());\n }\n \n public static String next()\n {\n return 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 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 double r = nextInt();\n double v = nextInt();\n StringBuffer sb = new StringBuffer();\n for (int i = 0; i < n; i++)\n {\n nextLine(br);\n int start = nextInt();\n int finish = nextInt();\n double diff = finish - start;\n double ans = solve(diff, v, r);\n sb.append(String.valueOf(ans) + \"\\n\");\n }\n System.out.println(sb.toString());\n \n }\n \n public static double solve(double d, double v, double r)\n {\n d = d / r;\n double circ = 2 * Math.PI;\n double rounds = Math.floor(d / circ);\n double rem = (d - rounds * circ) / 2;\n double left = 0;\n double right = 1;\n for (int i = 0; i < 50; i++)\n {\n double mid = (left + right) / 2;\n double temp = Math.PI * mid;\n double k = temp + Math.sin(temp);\n if (k > rem)\n {\n right = mid;\n }\n else\n {\n left = mid;\n }\n }\n //System.out.println(rounds + \" \" + rem + \" \" + left);\n \n double ans = ((left + rounds) * circ) / v;\n return ans;\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ef16cf9ddd3079afce63dcceeb73e5cd", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n sc.close();\n System.out.println();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f2d54fbe53c12d63f7cd689693d85b13", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "//package codeforces.cfr330div2;\n\nimport java.io.*;\nimport java.util.Scanner;\n\n/**\n * Created by raggzy on 27-Jan-16.\n */\npublic class D {\n public static final double TEPS = 0.0000005;\n\n private static double findT(int s, int f, int r, int v, double a0) {\n double targetX = 1.0 * r * Math.cos(a0) + (f - s) / 2;\n double tLeft = 1.0 * (f - s) / 2 / v - 2 * Math.PI * r / v;\n double tRight = 1.0 * (f - s) / 2 / v + 2 * Math.PI * r / v;\n final double VdivR = v / r;\n while ((tRight - tLeft) / Math.max(1, tLeft) >= TEPS) {\n double tMid = (tLeft + tRight) / 2;\n if (tMid * v + Math.cos(a0 + tMid * VdivR) * r > targetX) {\n tRight = tMid;\n } else {\n tLeft = tMid;\n }\n }\n return 2 * tLeft;\n }\n\n private static double findT(int s, int f, int r, int v) {\n return Math.min(findT(s, f, r, v, Math.PI / 2), findT(s, f, r, v, 3 * Math.PI / 2));\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n Scanner in = new Scanner(new File(\"C:/Temp/test.out\"));\n PrintStream out = new PrintStream(new File(\"C:/Temp/test2.out\"));\n// Scanner in = new Scanner(System.in);\n// PrintStream out = System.out;\n int n = in.nextInt();\n int r = in.nextInt();\n int v = in.nextInt();\n for (int i = 0; i < n; i++) {\n out.println(findT(in.nextInt(), in.nextInt(), r, v));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "52af8e93dd59612b9f38bafb1aa12a11", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "package codeforces.cfr330div2;\n\nimport java.io.*;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\n/**\n * Created by raggzy on 27-Jan-16.\n */\npublic class D {\n public static final double TEPS = 1e-6;\n\n private static double findT(double s, double f, double r, double v, double a0) {\n double targetX = r * Math.cos(a0) + (f - s) / 2;\n double tLeft = (f - s) / 2 / v - 2 * Math.PI * r / v;\n double tRight = (f - s) / 2 / v + 2 * Math.PI * r / v;\n while ((tRight - tLeft) / Math.max(1, tLeft) > TEPS) {\n double tMid = (tLeft + tRight) / 2;\n if (v * tMid + r * Math.cos(a0 + tMid * v / r) > targetX) {\n tRight = tMid;\n } else {\n tLeft = tMid;\n }\n }\n return 2 * tLeft;\n }\n\n private static double findT(double s, double f, double r, double v) {\n return Math.min(findT(s, f, r, v, Math.PI / 2), findT(s, f, r, v, 3 * Math.PI / 2));\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n// Reader in = new Reader(new FileInputStream(\"C:/Temp/test.out\"));\n// PrintStream out = new PrintStream(new File(\"C:/Temp/test2.out\"));\n Scanner in = new Scanner(System.in);\n PrintStream out = System.out;\n int n = in.nextInt();\n double r = in.nextDouble();\n double v = in.nextDouble();\n for (int i = 0; i < n; i++) {\n out.println(findT(in.nextDouble(), in.nextDouble(), r, v));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "727f71eea6d4b17bf5765028c3d68964", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CodeTest {\n static Scanner sc=new Scanner(System.in);\n static Scanner number=new Scanner(System.in);\n\tpublic static void main(String[] args) {\n\t\t\n\t int nint=number.nextInt();\n\t \n\t String n=sc.nextString();\n\t String dOne=\"11\";\n\t String sl=\"00\";\n\t String check=\"000\";\n\t if(n.indexOf(check)!=(-1) || n.indexOf(dOne) !=(-1) || n.indexOf(sl)==0 || n.indexOf(sl)==n.length()-2) {\n\t\t System.out.println(\"No\");\n\t }else {\n\t System.out.println(\"Yes\");\n\t }\n\t\t\n\t \n\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c16268cf8efc58be1198ea0544256df9", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d", "difficulty": 1200.0} {"lang": "Java 8", "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{\n\t\t// your code goes here\n\t\t\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tString s=sc.next();\n\t\tif(n==1){\n\t\t if(s==\"1\"){System.out.println(\"Yes\");}\n\t\t else{System.out.println(\"No\");}\n\t\t}\n\t\telse if(n==2){\n\t\t if(s==\"10\" || s==\"01\"){\n\t\t System.out.println(\"Yes\");\n\t\t }else{\n\t\t System.out.println(\"No\");\n\t\t }\n\t\t}\n\t\tint r=0;\n\t\telse{\n\t\t \n\t\t int count0=0,count1=0;\n\t\t for(int i=0;i=3){r=1;break;}\n\t\t }\t\n\t\t if(r==1){System.out.println(\"No\");}\n\t\t else{System.out.println(\"Yes\");}\n\t\t \t\t \n\t\t}\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "142c36fa42043157688b91c9889021b6", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t Scanner sc=new Scanner(System.in);\n\t int n=sc.nextInt();\n\t String s=sc.next();\n\t \nif(s.contains(\"000\") || s.contains(\"11\"))\n System.out.println(\"NO\");\nelse\n System.out.println(\"YES\");\n\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d8ccc20c31c42a5665d272b3cf92abc1", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d", "difficulty": 1200.0} {"lang": "Java 8", "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{\n\t\t// your code goes here\n\t\t\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tString s=sc.next();\n\t\tif(n==1){\n\t\t if(s==\"1\"){System.out.println(\"Yes\");}\n\t\t else{System.out.println(\"No\");}\n\t\t}\n\t\telse if(n==2){\n\t\t if(s==\"10\" || s==\"01\"){\n\t\t System.out.println(\"Yes\");\n\t\t }else{\n\t\t System.out.println(\"No\");\n\t\t }\n\t\t}\n\t\telse{\n\t\t \t\t if(n%2==0){\n\t\t \t\t String p0=\"\",p1=\"\";\n\n\t\t for(int i=0;i0) {s += \"L\"; n1--;}\n\t\t\tif(n1<0) {s += \"R\"; n1++;}\n\t\t\tif(n2>0) {s += \"D\"; n2--;}\n\t\t\tif(n2<0) {s += \"U\"; n2++;}\n\t\t\tSystem.out.println(s);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "45643be83c3f979e50c6c9f137e3331c", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution{\n public static void main(String[] args){\n \n Scanner s = new Scanner(System.in);\n \n \n String start = s.nextLine();\n \n \n String end = s.nextLine();\n \n System.out.println(Math.max(Math.abs(start.charAt(0)-end.charAt(0)),Math.abs(start.charAt(1)-end.charAt(1)))); \n int x = (int)start.charAt(0)-(int)end.charAt(0);\n int y = (int)start.charAt(1)-(int)end.charAt(1);\n while(x|y){\n if(x<0){\n System.out.print(\"R\");\n x--;\n }\n if(x>0){\n System.out.print(\"L\");\n x++;\n }\n if(y<0){\n System.out.print(\"U\");\n y--;\n }\n if(y>0){\n System.out.print(\"D\");\n y++;\n }\n \n System.out.println();\n }\n \n \n }\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f825245a752c7dcb9484cf7b2c7d7805", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.stream.Collectors;\n\npublic class PositionUtils {\n private static int x1[] = {-1, 1, 0, 0, -1, -1, 1, 1};\n private static int y1[] = {0, 0, 1, -1, 1, -1, 1, -1};\n private static String movements[] = {\"U\", \"D\", \"R\", \"L\", \"RU\", \"LU\", \"RD\", \"LD\"};\n\n public static List move(int x, int y) {\n List positions = new ArrayList();\n\n for (int i = 0; i <=7; i++) {\n if (isValidMove(x + x1[i], y + y1[i])) {\n positions.add(new Position(x + x1[i], y + y1[i], movements[i]));\n }\n }\n\n return positions;\n }\n\n private static boolean isValidMove(int x, int y) {\n if (x < 0 || x > 7) {\n return false;\n }\n\n if (y < 0 || y > 7) {\n return false;\n }\n\n return true;\n }\n}\n\npublic class Position {\n public int x, y;\n public List pastMoves = new ArrayList();\n public String currentMove;\n public Position(int x, int y, String currentMove) {\n this.x = x;\n this.y = y;\n this.currentMove = currentMove;\n }\n\n public String toString() {\n return this.x + \" \" + this.y + \" \" + currentMove;\n }\n}\n\npublic class Shking {\n\n public static void main (String args[]) {\n Scanner sc = new Scanner(System.in);\n String start = sc.next();\n String end = sc.next();\n Position current = new Position(start.charAt(0) - 'a', '8' - start.charAt(1), \"\");\n Position required = new Position(end.charAt(0) - 'a', '8' - end.charAt(1), \"\");\n\n bfs(current, required);\n }\n\n private static void bfs(Position start, Position end) {\n boolean [][]visited = new boolean[10][10];\n\n Queue queue = new LinkedList();\n queue.add(start);\n\n Position ans = null;\n while (!queue.isEmpty()) {\n Position current = queue.peek();\n if (current.x == end.x && current.y == end.y) {\n ans = current;\n break;\n }\n visited[current.x][current.y] = true;\n queue.remove();\n \n List neighbours = PositionUtils.move(current.x, current.y);\n\n queue.addAll(neighbours.stream().filter(position -> visited[position.x][position.y] != true).collect(Collectors.toList()));\n\n for (Position pos: neighbours) {\n if (!visited[pos.x][pos.y]) {\n visited[pos.x][pos.y] = true;\n pos.pastMoves.addAll(current.pastMoves);\n pos.pastMoves.add(pos.currentMove);\n }\n }\n }\n System.out.println(ans.pastMoves.size());\n\n for (String move: ans.pastMoves)\n System.out.println(move);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "83f711ced5f6fa241c91009c97a828bf", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution{\n public static void main(String[] args){\n \n Scanner s = new Scanner(System.in);\n \n \n String start = s.nextLine();\n \n \n String end = s.nextLine();\n \n System.out.println(Math.max(abs(start.charAt(0)-end.charAt(0)),abs(start.charAt(1)-end.charAt(1))); \n int x = (int)start.charAt(0)-(int)end.charAt(0);\n int y = (int)start.charAt(1)-(int)end.charAt(1)\n while(x!=y){\n if(x<0){\n System.out.print(\"R\");\n x--;\n }\n if(x>0){\n System.out.print(\"L\");\n x++;\n }\n if(y<0){\n System.out.print(\"U\");\n y--;\n }\n if(y>0){\n System.out.print(\"D\");\n y++;\n }\n \n System.out.println();\n }\n \n \n }\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "20e90575a01b30ef6ec63cf0aafb185a", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.io.*;\n\npublic class rask41c {\n\tpublic static void main(String[] args) {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\ttry {\n\t\t\tString str = br.readLine();\n\t\t\tStringBuilder sb = new StringBuilder(\"\");\n\t\t\tint ind, s;\n\t\t\tstr = str.replaceAll(\"dot\", \".\");\n\t\t\tind = str.indexOf(\"at\", 1);\n\t\t\ts = str.length();\n\t\t\tif (str.charAt(0) == '.') {\n\t\t\t\tsb.append(\"dot\");\n\t\t\t} else {\n\t\t\t\tsb.append(str.charAt(0));\n\t\t\t}\n\n\t\t\tif (ind != -1 && ind != (s - 2)) {\n\t\t\t\tsb.append(str.subSequence(1, ind));\n\t\t\t\tsb.append(\"@\");\n\t\t\t\tsb.append(str.substring(ind + 2));\n\t\t\t} else\n\t\t\t\tsb.append(str.substring(1));\n\t\t\tif(sb.charAt(s-1)=='.')\n\t\t\t\tsb.replace(s-1,s, \"dot\");\n\t\t\tSystem.out.println(sb);\n\t\t} catch (IOException e) {\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "973d1b4884f1b40680a4c0c4ed881c25", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\n@SuppressWarnings(\"unused\")\npublic class A {\n\tpublic static FastScanner scan = new FastScanner();\n\tpublic static PrintWriter out = new PrintWriter(System.out);\n\t\n\tpublic static void solve () {\n\t\tString s=scan.next();\n\t\tif(s.contains(\"at\")) s=s.replaceFirst(\"at\", \"@\");\n\t\tif(s.contains(\"dot\")) s=s.replace(\"dot\", \".\");\n\t\tif(s.charAt(0)=='.') {\n\t\t\ts=\"dot\"+s.substring(1);\n\t\t}\n\t\tif(s.charAt(s.length()-1)=='.') {\n\t\t\ts=s.substring(0,s.length()-1)+\"dot\";\n\t\t}\n\t\tSystem.out.println(s);\n\t}\n\tpublic static void main(String[] args) {\n\t\n\t\tsolve();\n\t\tout.close();\n\t}\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a3278d77567244a1140bb8f384ee645", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Ishu\n{\n public static void main(String[] args)\n {\n Scanner scan=new Scanner(System.in); \n int i; \n String s;\n s=scan.next();\n for(i=1;i list;\n//\t\t\t\n//\t\t\tpublic Node(String name) {\n//\t\t\t\tthis.name = name;\n//\t\t\t\tlist = new LinkedList<>();\n//\t\t\t}\n//\t\t}\n// \n//\t\tstatic class Pair { \t\n//\t \tint first, second;\n//\t\t \t\n//\t\t public Pair(int first, int second) {\n//\t \t\tthis.first = first;\n//\t\t\t\tthis.second = second;\n//\t\t\t}\n//\t }\n\t}\n\n\t//\tpublic static int[] shuffle(int arr[], Random gen) {\n\t//\t\tfor(int i = 0, n = arr.length; i < n; i++)\n\t//\t\t{\n\t//\t\t\tint index = gen.nextInt(n - i) + i;\n\t//\t\t\tint temp = arr[i];\n\t//\t\t\tarr[i] = arr[index];\n\t//\t\t\tarr[index] = temp;\n\t//\t\t}\n\t//\t\treturn arr;\n\t//\t}\n\t//\n\t//\tpublic static boolean triangle(long a, long b, long c){\n\t//\t return ((a+b) > c && (b+c) >a && (a+c) > b);\n\t//\t}\n\t//\t\t\n\t//\tpublic static boolean isPerfectSquare(long n){\n\t//\t\tif (n < 0) \n\t//\t \treturn false;\n\t//\t long test = (long) (Math.sqrt(n) + 0.5);\n\t//\t return test*test == n;\n\t//\t}\n\t//\t\t\n\t//\tpublic static int isnum(char s){\n\t//\t\tif(s=='1' || s=='2' || s=='3' || s=='4' || s=='5' || s=='6' || s=='7' || s=='8' || s=='9' || s=='0') \n\t//\t \treturn 1; \n\t//\t\treturn 0;\n\t//\t}\n\t//\t\t\n\t//\tpublic static long nextPowerOf2(long n){\n\t//\t n--;\n\t//\t n |= n >> 1;\n\t//\t n |= n >> 2;\n\t//\t n |= n >> 4;\n\t//\t n |= n >> 8;\n\t//\t n |= n >> 16;\n\t//\t n++;\n\t//\t return n;\n\t//\t}\n\t//\t\t\n//\t\tpublic static int gcd(int a, int b){\n//\t\t int t; \n//\t\t while (b > 0){ \n//\t\t \ta = a % b; \n//\t\t \tt = a; \n//\t\t \ta = b; \n//\t\t \tb = t; \n//\t \t}\n//\t\t return a;\n//\t\t}\n\t//\t\t\n\t//\tpublic static void sieve(int n){\n\t//\t\tprime=new boolean[sievesize+1];\n\t//\t\tArrays.fill(prime, true);\n\t//\t long x, y; \n\t//\t for(x = 2; x * x <= sievesize; x++)\n\t//\t { \n\t//\t \tif(prime[(int) x])\n\t//\t \t\tfor(y = x * 2; y <= sievesize; y += x) \n\t//\t \t\t\tprime[(int) y]=false; \n\t//\t }\n\t//\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\n\t\tpublic float nextFloat() {\n\t\t\treturn Float.parseFloat(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic int[] nextIntArray(int size) {\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\tint[] arr=new int[size];\n\t\t\tfor(int i = 0; i < size; i++) \n\t\t\t\tarr[i] = Integer.parseInt(tokenizer.nextToken());\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int size) {\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\tlong[] arr=new long[size];\n\t\t\tfor(int i = 0; i < size; i++) \n\t\t\t\tarr[i] = Long.parseLong(tokenizer.nextToken());\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int size) {\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\tdouble[] arr=new double[size];\n\t\t\tfor(int i = 0; i < size; i++) \n\t\t\t\tarr[i] = Double.parseDouble(tokenizer.nextToken());\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic String[] nextStringArray(int size) throws IOException {\n\t\t\tString[] arr=new String[size];\n\t\t\tfor(int i = 0; i < size; i++) \n\t\t\t\tarr[i] = reader.readLine();\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic char[] nextCharArray(int size) throws IOException {\n\t\t\tchar[] arr=reader.readLine().toCharArray();\n\t\t\treturn arr;\n\t\t}\n\t}\n\n\tstatic class OutputWriter {\n\t\tpublic PrintWriter pw;\n\n\t\tpublic OutputWriter(OutputStream stream) {\n\t\t\tpw = new PrintWriter(stream);\n\t\t}\n\t\t\n\t\tpublic void println() {\n\t\t\tpw.println();\n\t\t}\n\n\t\tpublic void println(Object str) {\n\t\t\tpw.println(str);\n\t\t}\n\n\t\tpublic void print(Object str) {\n\t\t\tpw.print(str + \" \");\n\t\t}\n\n\t\tpublic void close() {\n\t\t\tpw.close();\n\t\t}\n\n\t\tpublic void flush() {\n\t\t\tpw.flush();\n\t\t}\n\n\t\tpublic void printStringArray(String[] arr) {\n\t\t\tfor(int i = 0; i < arr.length; i++)\n\t\t\t\tpw.println(arr[i]);\n\t\t}\n\n\t\tpublic void printIntArray(int[] arr) {\n\t\t\tfor(int i = 0; i < arr.length; i++)\n\t\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\n\t\tpublic void printLongArray(long[] arr) {\n\t\t\tfor(int i = 0; i < arr.length; i++)\n\t\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\n\t\tpublic void printCharArray(char[] arr) {\n\t\t\tfor(int i = 0; i < arr.length; i++)\n\t\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\n\t\tpublic void printFloatArray(float[] arr) {\n\t\t\tfor(int i = 0; i < arr.length; i++)\n\t\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\n\t\tpublic void printDoubleArray(double[] arr) {\n\t\t\tfor(int i = 0; i < arr.length; i++)\n\t\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "90b59c0d6bbd7f59a98d3af49befbfca", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class abc{\npublic static void main(String []args)throws IOException\n{\nBufferedReader buf=new BufferedReader(new InputStreamReader(System.in));\nint n=Integer.parseInt(buf.readLine());\nString s=buf.readLine();\nStringTokenizer obj=new StringTokenizer(s);\nint c=obj.countTokens();\nint arr[]=new int[c];\nfor(int i=0;icd.list.get(index+1))){\n for (int i=index; (i>=0) && (limak list= new ArrayList(0);\n public Candidate(){}\n public void sort(){\n for (int i=0; i< list.size()-1; i++){\n for (int j=i+1; j pq = new PriorityQueue(new OppositeComparator());\n for (int i = 0; i < n; i++) {\n pq.add(scanner.nextInt());\n }\n\n int steals = 0;\n while (limak <= pq.peek()) {\n pq.add(pq.poll()-1);\n limak++;\n steals++;\n }\n\n System.out.println(steals);\n }\n\n public static class OppositeComparator implements Comparator {\n public int compare(java.lang.Integer x, java.lang.Integer y) {\n return java.lang.Integer.compare(y, x);\n }\n }\n\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n }\n //--------------------------------------------------------\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "85e125586139ce8b29aa237080469211", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Codechef\n{\n\tpublic static void main (String[] args) \n\t{\n\tString x,y;\n Scanner in = new Scanner(System.in);\n x = in.nextLine();\n y = in.nextLine();\n StringBuilder z = new StringBuilder(x);\n if(x.length() != y.length())\n {\n System.out.println(\"-1\");\n return -1;\n }\n else {\n for(int i = 0; i < x.length(); i++)\n {\n if((x.charAt(i) < y.charAt(i)) || (x.charAt(i) == 'z' && x.charAt(i) == y.charAt(i)))\n {\n System.out.println(\"\" + x.charAt(i) + y.charAt(i));\n System.out.println(\"-1\");\n return -1;\n }\n else if(x.charAt(i) == y.charAt(i))\n {\n z.setCharAt(i, Character.valueOf( (char) (x.charAt(i) + 1)));\n }\n else {\n z.setCharAt(i, y.charAt(i));\n }\n }\n System.out.println(z);\n return;\n }\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "931d2b5cc69b7b836f2f70cf2f1383b2", "src_uid": "ce0cb995e18501f73e34c76713aec182", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class cf2{\n\npublic static void main(String[] args) throws IOException{\n\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\nString x = br.readLine();\nString y = br.readLine();\nString z = \"\";\nint count = 0;\n\nfor(int i =0; i xchar) || (xchar == 'z' && ychar == 'z')){\n count = -1;\n break;\n }\n\n if(xchar == ychar){\n \n z+=(char)(xchar+1);\n } else {\n //y str.charAt(i)){\n System.out.println(\"-1\")\n return;\n }\n }\n System.out.println(str1);\n }\n catch (Exception e) {\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a20dd7f79b3a401fa09964a4198408a3", "src_uid": "ce0cb995e18501f73e34c76713aec182", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\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\tString x,y;\n Scanner in = new Scanner(System.in);\n x = in.nextLine();\n y = in.nextLine();\n StringBuilder z = new StringBuilder(x);\n if(x.length() != y.length())\n {\n System.out.println(\"-1\");\n return;\n }\n else {\n for(int i = 0; i < x.length(); i++)\n {\n if((x.charAt(i) < y.charAt(i)) || (x.charAt(i) == y.charAt(i)))\n {\n System.out.println(\"-1\");\n return;\n }\n else if (x.charAt(i) == 'z')\n {\n z.setCharAt(i, \"z\");\n }\n else if(x.charAt(i) == y.charAt(i))\n {\n z.setCharAt(i, Character.valueOf( (char) (x.charAt(i) + 1)));\n }\n else {\n z.setCharAt(i, y.charAt(i));\n }\n }\n System.out.println(z);\n return;\n }\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4fda2bc9fc59cf6b6d8cb4355ee30edb", "src_uid": "ce0cb995e18501f73e34c76713aec182", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n double n = sc.nextDouble();\n int[] ar = new int[n];\n Double s = 0;\n int total = 0;\n\n for(int i=0;i=4.5)\n\t\tSystem.out.println(\"0\");\n\telse{\n\t\tArrays.sort(A);\n\t\tint c=0;\n\t\t\n\t\tfor(int i=0;i=4.5){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(s/(float)n>=4.5)\n\t\t\tSystem.out.println(c);\n\t\telse\n\t\t\tSystem.out.println(-1);\n\t} \n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e89025abf9c6f12a52a1689cca84ef35", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class Getting_an_A {\n\n static int N;\n static double[] grads;\n\n public static void main(String[] args) throws IOException {\n\n InputStreamReader isr = new InputStreamReader(System.in);\n BufferedReader br = new BufferedReader(isr);\n\n N = Integer.parseInt(br.readLine());\n grads = new double[N];\n\n StringTokenizer st = new StringTokenizer(br.readLine());\n double runningSum = 0;\n\n for (int i = 0; i < N; i++) {\n grads[i] = Integer.parseInt(st.nextToken());\n runningSum += grads[i];\n }\n\n Arrays.sort(grads);\n int curr = 0;\n\n while(round(runningSum/N) != 5){\n runningSum += (5-grads[curr]);\n grads[curr] = 5;\n curr++;\n\n }\n System.out.println(curr);\n\n isr.close();\n br.close();\n }\n\n private static int round(double sum) {\n\n if (sum - ((int)sum)<0.5) return (int) sum;\n\n return (int) sum +1;\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7af89e0b32eb0f033e9f5acfa6e68aaf", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Main(){\npublic static void main(String args[]){\nScanner a = new Scanner(System.in);\nint a=a.nextInt();\nint aa=a.nextInt();\nint aaa=a.nextInt();\nint b=a.nextInt();\nint bb=a.nextInt();\nint bbb=a.nextInt();\nint n=a.nextInt();\nint k=(a+aa+aaa)/5+((a+aa+aaa)%5+4)/5+(b+bb+bbb)/10+((b+bb+bbb)%10+9)/10;\nif(k>n){\nSystem.out.println(\"NO\");\n}\nelse{\nSystem.out.println(\"YES\");\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6519e61e52859ca1a54c4135c0d33802", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Main{\npublic static void main(String args[]){\nScanner a = new Scanner(System.in);\nint a=a.nextInt();\nint aa=a.nextInt();\nint aaa=a.nextInt();\nint b=a.nextInt();\nint bb=a.nextInt();\nint bbb=a.nextInt();\nint n=a.nextInt();\nint k=(a+aa+aaa)/5+((a+aa+aaa)%5+4)/5+(b+bb+bbb)/10+((b+bb+bbb)%10+9)/10;\nif(k>n){\nSystem.out.println(\"NO\");\n}\nelse{\nSystem.out.println(\"YES\");\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f9f54adcc27c3c472c53a53db9b3a627", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.util.stream.*;\n\npublic class CopyOfRewards {\n public static void main(String... args) throws IOException {\n long[] d = (long[]) new BufferedReader(new InputStreamReader(System.in)).lines().map(\n x -> Stream.of(x.split(\" \")).map(Long::parseLong).sum()).toArray();\n System.out.println(d[2]-(d[0]+4)/5+(d[1]+9)/10 < 0? \"NO\":\"YES\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "82a301ba1631fa3199061b55cc660168", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.regex.*;\nimport java.util.Arrays;\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 public static void main(String[] args) throws Exception \n { \n \n FastReader sc = new FastReader();\n float c=0;\n float m=0,i;\n float total=0;\n for(i=0;i<3;i++)\n c+=sc.nextInt();\n for(i=0;i<3;i++)\n m+=sc.nextInt();\n int n = sc.nextInt();\n if(c==0) total=0;\n else if(c>5){\n total = Math.ceil(c/5);}\n else total=1;\n if(m==0) total+=0;\n else if(m>10){\n total += Math.ceil(m/10);}\n else total+=1;\n if(total<=n) System.out.print(\"YES\");\n else System.out.print(\"NO\");\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "716b6372dc02a5f9f651d8bff45506e3", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\npublic class practice {\n\n\tpublic static void main(String[] args) {\n\t\tint n;\n\t\tSystem.in(n);\n\t\tif(n%2==1) {\n\t\t\tSystem.out.println(n/2+' '+(n/2+1));\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(n/2-1+' '+(n/2+1));\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9903368d63b82f6598161dd6a4660ffa", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A854 {\n\n\tpublic static void main(String[] args) {\n\t\tint n;\n\t\tSystem.in(n);\n\t\tif(n%2==1) {\n\t\t\tSystem.out.println(n/2+' '+(n/2+1));\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(n/2-1+' '+(n/2+1));\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d7765bee82d9482009d54a9ffcee0abc", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Arrays;\n\npublic class abc\n{\n int hcf(int a, int h) \n {\n int temp; \n while(true)\n {\n temp = a%h;\n if(temp==0)\n return h;\n a = h;\n h = temp;\n }\n }\n\tpublic static void main (String[] args)\n\t{\n\t Scanner scn = new Scanner(System.in);\n int n = scn.nextInt();\n abc obj = new abc();\n for (int i=1; i<=n/2; i++)\n {\n if(obj.hcf(i,n-i)==1)\n {\n a=i;\n b=n-i;\n }\n }\n System.out.println(a+\" \"+b);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02ddba880b6f14ad852159e4c6e6571f", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Arrays;\n\npublic class abc\n{\n int hcf(int a, int h) \n {\n int temp; \n while(true)\n {\n temp = a%h;\n if(temp==0)\n return h;\n a = h;\n h = temp;\n }\n }\n\tpublic static void main (String[] args)\n\t{\n\t Scanner scn = new Scanner(System.in);\n int n = scn.nextInt();\n abc obj = new abc();\n int a,b;\n for (int i=1; i<=n/2; i++)\n {\n if(obj.hcf(i,n-i)==1)\n {\n a=i;\n b=n-i;\n }\n }\n System.out.println(a+\" \"+b);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "94b540e7396cd263ae1a454524d20a6c", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] afzalkhan){\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int M = sc.nextInt();\n int a = sc.nextInt();\n int b = sc.nextInt();\n if(N= onePrice)\n System.out.print(onePrice * totalRides);\n\n else if(totalRides%sticketRides==0)\n System.out.print((int)(sPricePer * totalRides));\n\n else if(sPrice< (double)onePrice || sTrips*sPrice< onePrice * totalRides)\n System.out.print(sTrips*sPrice);\n\n else \n System.out.print(((totalRides/sticketRides)*sPrice) + ((totalRides%sticketRides)*onePrice));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "058adf32fc8f022c879d4cff41a792ea", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int n,m,a,b;\n n = sc.nextInt();\n m = sc.nextInt();\n a = sc.nextInt();\n b = sc.nextInt();\n \n int div,cs,cm;\n cs = a*n;\n if(n%m==0)\n {\n div =n/m;\n cm = b*div;\n }\n else\n {\n div = n/m;\n cm = (div+1)*b\n }\n if(cs>=cm)\n System.out.println(cm);\n else\n System.out.println(cs);\n \n }\n}\nclose", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f59af0ef1faa8cf9b5d991ab940844da", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class main{\n public static void main(String[]args){\n Scanner input=new Scanner(System.in);\n long k=input.nextLong();\n long n=input.nextLong();\n long w=input.nextLong();\n long d=((w/2)*((w+1)*k))-n;\n if(((w/2)*((w+1)*k)>n){\n System.out.println(d);\n }\n else{\n System.out.println(0);\n }\n }\n}\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "33aa811f43761ad7398cc1810bfa46e6", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.math.*;\npublic class SoldiersandBananas {\n public static void main(String[] args) {\n Scanner kb = new Scanner(System.in); \n int k = kb.nextInt();\n int n = kb.nextInt();\n int w = kb.nextInt();\n int i=1,m=0;\n while(n-k*i>0 && i<=w){\n n = n-k*i;\n i++;\n }\n \n while(i<=w){\n m=1;\n n = n-k*i;\n i++;\n }\n if(m==1){\n System.out.println(Math.abs(n));}\n else{\n System.out.println(0); \n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8e468b65cf9e746669f201f00506b457", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class main {\n\n public static void main(String[] args) {\n int k; // ennyit akar fizetni az elso bananert\n int n; // ennyi penze van\n int w; //ennyiban\u00e1ntszeretne\n ArrayList list = new ArrayList();\n Scanner scan = new Scanner(System.in);\n k = scan.nextInt();\n n = scan.nextInt();\n w = scan.nextInt();\n int vegsoszam = k;\n for (int i = 0; i < w-1; i++) {\n\t\t vegsoszam += k * (i + 2);\n }\n\t\tif(k == 1 && n == 2 && w == 1) {\n\t\t\tSystem.out.println(\"0\");\n\t\t} else {\n\t\t\t System.out.println(vegsoszam - n);h\n\t\t}\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6c6dfff23a68026fe279b913fff18067", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class ban{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int k=sc.nextInt();\n int n=sc.nextInt();\n int w=sc.nextInt();\n int res=res-(n-(((w*(w+1))/2*k);\n if(res<0)\n System.out.println(0);\n else\n System.out.println(res);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b27d9cdcd82b52b2c3fd2119bc4d1866", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class b\n{\n static int mod = (int) 1e9 + 7;\n static int Infinity=Integer.MAX_VALUE;\n static int negInfinity=Integer.MIN_VALUE;\n public static void main(String args[])\n {\n try\n {\n Scanner d= new Scanner(System.in);\n int t,n,s;\n t=d.nextInt();\n for(;t>0;t--)\n {\n n=d.nextInt();\n s=spf(n);\n if(s==0)\n System.out.println(n-1+\" \"+1);\n else()\n System.out.print(n/s+\" \");\n System.out.print(n-n/s);\n System.out.println();}\n }\n }\n catch(Exception e)\n {\n System.out.println(0);\n }\n }\n\n static int spf(int n) \n { \n if (n <= 1) \n return 1; \n if (n <= 3) \n return 0; \n if (n % 2 == 0 ) \n return 2; \n if ( n % 3 == 0) \n return 3; \n \n for (int i = 5; i * i <= n; i = i + 6) \n { if (n % i == 0 ) \n return i; \n if (n % (i + 2) == 0) \n return i+2; \n }\n return 0; \n } \n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6089aaa8f24bdffa3758f2dc04534507", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int t = scan.nextInt();\n for (int z = 0; z < t; z++) {\n long n = scan.nextInt();\n boolean a=true;\n if(n%2==0) System.out.println((n/2)+\" \"+ (n/2));\n else{\n int y=0;\n for(long i=n/2;i>1;i--){\n if(n%i==0){\n a=false;\n y=i;\n break;\n }\n else{\n a=true;\n }\n }\n if(a==false){\n System.out.println(y+\" \"+(n-y));\n }\n else{\n System.out.println(1+\" \"+(n-1));\n }\n }\n }\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4b01cec5af23e3815ccfbd7aabf67835", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Codeforces{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint t=sc.nextInt();\n\t\tfor(int i=0;i0){\n solve();\n }\n out.close();\n }\n \n static ArrayList[] graph; \n static int n=8;\n static int m=8;\n static int k =0;\n static long mod =1000000007;\n static int MOD = 1000000007;\n static int[] dx = {0,0,1,-1};\n static int[] dy = {1,-1,0,0};\n static int[] cost;\n static int[] col; //0 ,1,2\n static int[] par;\n static long ans=0;\n static ArrayList list;\n\n \n static void solve()throws IOException{\n n = Reader.nextLong();\n long x = printDivisors(n);\n if(n==1){\n out.println(0+\" \"+1);\n return;\n }\n if(x==-1){\n out.println(1+\" \"+(n-1));\n return;\n }\n else{\n out.println(n/x+\" \"+((x-1)*(n))/x) ;\n }\n }\n \n static long printDivisors(long n) \n { \n // Note that this loop runs till square root \n for (int i=2; i<=Math.sqrt(n); i++) \n { \n if (n%i==0) \n { \n return i;\n } \n } \n return -1;\n } \n \n // ggratest common divisor println\n static int gcd(int a , int b){\n if(b==0)\n return a;\n else\n return gcd(b,a%b);\n }\n \n // least common multiple\n static int lcm(int a, int b){\n return (a*b)/gcd(a,b);\n }\n \n // a^b\n static long fastpow(long a, long b){\n long res = 1;a=a%mod;\n while(b>0){\n if(b%2==1)\n res = (res*a)%mod;\n a = (a*a)%mod;\n b = b>>1;\n }\n return res;\n }\n\n // segment tree\n /* static void update(int ind, int l, int h, int pos, int v){\n if(l==h){\n seg[ind] = v;\n return;\n }\n int mid = (l+h)/2;\n if(pos<=mid)\n update(2*ind,l,mid,pos,v);\n else\n update(2*ind+1,mid+1,h,pos,v);\n seg[ind] = seg[2*ind]^seg[2*ind+1];\n }\n static int query(int ind, int l , int h, int ll , int hh){\n if(ll>hh)\n return 0;\n if(l==ll && h==hh)\n return seg[ind];\n int mid = (l+h)/2;\n return query(2*ind,l,mid,ll,Math.min(mid,hh)) ^ query(2*ind+1,mid+1,h,Math.max(mid+1,ll),hh);\n }*/\n // priority queue with comparator\n // PriorityQueue pq = new PriorityQueue<>(new Comparator() {\n // public int compare(Interval a, Interval b){\n // int diff1 = a.r - a.l;\n // int diff2 = b.r - b.l;\n \n // if(diff1 == diff2){\n // return a.l - b.l;\n // }\n \n // return diff2 - diff1;\n // }\n // });\n}\n \nclass trienode{\n int v;\n trienode[] child ;\n boolean leaf;\n int cnt;\n int p=0;\n trienode(int vv){\n child = new trienode[2];\n leaf=false;\n cnt=0;\n v=vv;\n }\n trienode(){\n child = new trienode[2];\n leaf=false;\n cnt=0;\n v=0;\n }\n }\nclass Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n \n /** call this method to initialize reader for InputStream */\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input) );\n tokenizer = new StringTokenizer(\"\");\n }\n \n /** get next word */\n static String next() throws IOException {\n while ( ! tokenizer.hasMoreTokens() ) {\n //TODO add check for eof if necessary\n tokenizer = new StringTokenizer(\n reader.readLine() );\n }\n return tokenizer.nextToken();\n }\n \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 \n static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n}\nclass newcomparator implements Comparator{\n //@Override\n public int compare(Integer a, Integer b){\n return a<=b?1:-1;\n }\n }\nclass node {\n int f;\n int s;// cost to rreach\\\n node(int ff,int ss){\n f=ff;\n s=ss;\n }\n}\nclass mergesort{\n static void sort(int l, int h, int[] arr){\n if(l= h/2; i-- )\n {\n //System.out.printf(\"i: %d\\n\", i);\n for( int j = w/2; j <= W-w/2; j++ )\n {\n //System.out.printf(\"j: %d\\n\", j);\n count++;\n }\n }\n //System.out.printf(\"count: %d\\n\", count);\n w += 2;\n if( w <= W )\n {\n //System.out.printf(\"w: %d, h: %d\\n\", w, h);\n for( int i = H-h/2; i >= h/2; i-- )\n {\n //System.out.printf(\"i: %d\\n\", i);\n for( int j = w/2; j <= W-w/2; j++ )\n {\n //System.out.printf(\"j: %d\\n\", j);\n count++;\n }\n }\n //System.out.printf(\"count: %d\\n\", count);\n }\n\n w -= 2;\n h += 2;\n if( h <= H )\n {\n //System.out.printf(\"w: %d, h: %d\\n\", w, h);\n for( int i = H-h/2; i >= h/2; i-- )\n {\n //System.out.printf(\"i: %d\\n\", i);\n for( int j = w/2; j <= W-w/2; j++ )\n {\n //System.out.printf(\"j: %d\\n\", j);\n count++;\n }\n }\n //System.out.printf(\"count: %d\\n\", count);\n }\n\n w += 2;\n }\n\n System.out.printf(\"%d\\n\", count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7e87f2c9c391cf37218cc7cbc23dc2c6", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n\n int w = in.nextInt(), h = in.nextInt();\n int count = 0;\n\n /*\n x0=0\n x1=2\n y0=0\n y1=2\n */\n for (int x0 = 0; x0 < w; x0++) { // from [0, w))\n for (int x1 = x0 + 2; x1 <= w; x1 += 2) { //from [x0+2;w] with increments +2)\n for (int y0 = 0; y0 < h; y0++) { //move y0 from [0;h)\n for (int y1 = y0 + 2; y1 <= h; y1 += 2) { //move y1 from [y0+2;h] with increments +2\n if ((x1 - x0) % 2 == 0 && (y1 - y0) % 2 == 0) {\n count++;\n }\n }\n }\n }\n }\n\n out.print(count);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "049a0e16fd84677b6d19265ace7062fb", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class test2\n{\n\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew test2().run();\n\t}\n\n\tPrintWriter out = null;\n\n\tlong cal(int w, int h, int ww, int hh)\n\t{\n\t\tlong hc = 0;\n\t\tfor (int i = 0; i <= Math.min(hh - 1, h - hh); i++)\n\t\t{\n\t\t\thc += (h - i) / hh;\n\t\t}\n\n\t\tlong wc = 0;\n\t\tfor (int j = 0; j <= Math.min(ww - 1, w - ww); j++)\n\t\t{\n\t\t\twc += (w - j) / ww;\n\t\t}\n\n\t\treturn hc * wc;\n\t}\n\n\tvoid run() throws Exception\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tint w = in.nextInt();\n\t\tint h = in.nextInt();\n\n\t\tlong total = 0;\n\n\t\tfor (int i = 1; 2 * i <= w; i++)\n\t\t{\n\t\t\tfor (int j = 1; 2 * j <= h; j++)\n\t\t\t{\n\t\t\t\ttotal += cal(w, h, 2 * i, 2 * j);\n\t\t\t}\n\t\t}\n\n\t\tout.println(total);\n\t\tout.close();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "32f8e3014030f3877ab52a1bbb5b865d", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\n\npublic class C119P2 {\n\n private static BufferedReader in;\n private static PrintWriter out;\n private static StringTokenizer input;\n \n public static void main(String[] args) throws IOException {\n //-------------------------------------------------------------------------\n //Initializing...\n new C119P2();\n //-------------------------------------------------------------------------\n //put your code here... :)\n int w = nextInt();\n int h = nextInt();\n long [][] dp = new long[w+1][h+1];\n for (int i = 2; i < dp.length; i++) {\n for (int j = 2; j < dp.length; j++) {\n dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+1;\n }\n }\n writeln(\"\"+dp[w][h]);\n //-------------------------------------------------------------------------\n //closing up\n end();\n //--------------------------------------------------------------------------\n\n }\n \n public C119P2() throws IOException {\n //Input Output for Console to be used for trying the test samples of the problem \n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //-------------------------------------------------------------------------\n //Initalize Stringtokenizer input\n input = new StringTokenizer(in.readLine());\n }\n\n private static int nextInt() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Integer.parseInt(input.nextToken());\n }\n private static long nextLong() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Long.parseLong(input.nextToken());\n }\n private static double nextDouble() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Double.parseDouble(input.nextToken());\n }\n private static String nextString() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return input.nextToken();\n }\n private static void write(String output){\n out.write(output);\n out.flush();\n }\n private static void writeln(String output){\n out.write(output+\"\\n\");\n out.flush();\n }\n private static void end() throws IOException{\n in.close();\n out.close();\n System.exit(0);\n }\n\n \n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6d765322fb4210e7ccc50f6f9409851e", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\n\npublic class p62a {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int f1 = in.nextInt();\n int f2 = in.nextInt();\n \n int m1 = in.nextInt();\n int m2 = in.nextInt();\n if(f1-m2 == 1 || f2-m1 == 1) {\n System.out.println(\"YES\");\n return;\n }\n if(f1 <= m2) {\n int maxMale = (f1+1)*2;\n if(m2<=maxMale) {\n System.out.println(\"YES\");\n return;\n }\n }\n if(f2<=m1) {\n int maxMale = (f2+1)*2;\n if(m1<=maxMale) {\n System.out.println(\"YES\");\n return;\n }\n }\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "675873ff904b55329af3cddc1da10291", "src_uid": "36b7478e162be6e985613b2dad0974dd", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\npublic class p62a {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int f1 = in.nextInt();\n int f2 = in.nextInt();\n \n int m1 = in.nextInt();\n int m2 = in.nextInt();\n if(f1-m2 == 1 || f2-m1 == 1) {\n System.out.println(\"YES\");\n return;\n }\n if(f1 <= m2) {\n int maxMale = (f1+1)*2;\n if(m2<=maxMale) {\n System.out.println(\"YES\");\n return;\n }\n }\n if(f2<=m1) {\n int maxMale = (f2+1)*2;\n if(m1<=maxMale) {\n System.out.println(\"YES\");\n return;\n }\n }\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a082528d0dfdcd90ad096eb33e04c233", "src_uid": "36b7478e162be6e985613b2dad0974dd", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Dream {\n\n// static final String F_IN = \"inout/cf/beta58/dream.in\";\n// static final File F_OUT = new File(\"inout/cf/beta58/dream.out\");\n\n static final InputStream F_IN = System.in;\n static final PrintStream F_OUT = System.out;\n\n String ans;\n int[] g, b;\n \n void readInput() throws Exception {\n// BufferedReader br = new BufferedReader(new FileReader(F_IN));\n BufferedReader br = new BufferedReader(new InputStreamReader(F_IN));\n g = toInts(br.readLine());\n b = toInts(br.readLine());\n }\n\n void writeOutput() throws Exception {\n PrintWriter out = new PrintWriter(F_OUT);\n out.println(ans);\n out.close();\n }\n\n boolean comfortable(int x, int y) {\n return Math.abs(x-y)<=1;\n }\n \n void solveProblem() {\n ans = comfortable(g[1], b[0]) || comfortable(g[0], b[1]) ? \"YES\" : \"NO\";\n }\n\n public Dream() throws Exception {\n readInput();\n solveProblem();\n writeOutput();\n }\n\n public static void main(String[] args) throws Exception {\n new Dream();\n }\n\n void debug(Object... os) {\n System.out.println(deepToString(os));\n }\n\n String[] toTokens(String s) {\n StringTokenizer st = new StringTokenizer(s);\n List list = new ArrayList();\n while (st.hasMoreTokens()) {\n list.add(st.nextToken());\n }\n String[] res = new String[list.size()];\n for (int i = 0; i < res.length; i++)\n res[i] = list.get(i);\n return res;\n }\n\n int[] toInts(String s) {\n StringTokenizer st = new StringTokenizer(s);\n List list = new ArrayList();\n while (st.hasMoreTokens()) {\n list.add(Integer.parseInt(st.nextToken()));\n }\n int[] res = new int[list.size()];\n for (int i = 0; i < res.length; i++)\n res[i] = list.get(i);\n return res;\n }\n\n long[] toLongs(String s) {\n StringTokenizer st = new StringTokenizer(s);\n List list = new ArrayList();\n while (st.hasMoreTokens()) {\n list.add(Long.parseLong(st.nextToken()));\n }\n long[] res = new long[list.size()];\n for (int i = 0; i < res.length; i++)\n res[i] = list.get(i);\n return res;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "48f9935482ab3e99c3d0795a361ad664", "src_uid": "36b7478e162be6e985613b2dad0974dd", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "public class Dream {\n\n static private Scanner sc=new Scanner(System.in);\n static private int hI, hD, mI, mD;\n \n public static void main(String[] args) {\n \n mI=sc.nextInt();\n mD=sc.nextInt();\n \n hI=sc.nextInt();\n hD=sc.nextInt();\n \n if ((mI-hD)<2 || (mD-hI)<2){\n System.out.println(\"YES\");\n } else System.out.println(\"NO\");\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fd7cc217e9377730231b9b64a304f930", "src_uid": "36b7478e162be6e985613b2dad0974dd", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.OutputStream;\nimport java.math.BigInteger;\nimport java.io.*;\nimport java.util.*;\npublic class Main {\n\tprivate static Reader fr;\n\tprivate static OutputStream out;\n\tprivate static final int delta = (int) 1e9 + 7;\n\n\tprivate static class Reader {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic Reader() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic Reader(String file_name) throws IOException {\n\t\t\tdin = new DataInputStream(new FileInputStream(file_name));\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String readLine() throws IOException {\n\t\t\tbyte[] buf = new byte[1024];\n\t\t\tint cnt = 0, c;\n\t\t\twhile ((c = read()) != -1) {\n\t\t\t\tif (c == '\\n')\n\t\t\t\t\tbreak;\n\t\t\t\tbuf[cnt++] = (byte) c;\n\t\t\t}\n\t\t\treturn new String(buf, 0, cnt);\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.') {\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9') {\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\tfillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\n\t\tpublic int[] nextArray(int n) throws IOException {\n\t\t\tint arr[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n\n\tprivate static void print(Object str) {\n\t\ttry {\n\t\t\tout.write(str.toString().getBytes());\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tprivate static void println(Object str) {\n\t\ttry {\n\t\t\tout.write((str.toString() + \"\\n\").getBytes());\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tprivate static void printArray(int arr[]) {\n\t\tfor (int val : arr) {\n\t\t\tprint(val + \" \");\n\t\t}\n\t\tprintln(\"\");\n\t}\n\n\tprivate static long add(long a, long b) {\n\t\treturn add(a, b, delta);\n\t}\n\n\tprivate static long add(long a, long b, long mod) {\n\t\treturn ((a % mod) + (b % mod)) % mod;\n\t}\n\n\tprivate static long multiply(long a, long b) {\n\t\treturn ((a % delta) * (b % delta)) % delta;\n\t}\n\n\tpublic static double multiply(double a, double b) {\n\t\treturn ((a % delta) * (b % delta)) % delta;\n\t}\n\n\tprivate static long pow(int base, int pow) {\n\t\tif (pow == 0)\n\t\t\treturn 1;\n\t\tif (pow == 1)\n\t\t\treturn base;\n\t\tlong halfPow = pow(base, pow / 2);\n\t\tif ((pow & 1) == 0)\n\t\t\treturn multiply(halfPow, halfPow);\n\t\treturn multiply(halfPow, multiply(base, halfPow));\n\t}\n\n\tprivate static long gcd(long a, long b) {\n\t\tif (a == 0 || b == 0)\n\t\t\treturn a == 0 ? b : a;\n\t\treturn gcd(b, a % b);\n\t}\n\n\tprivate static long kadane(int[] arr) {\n\t\tint size = arr.length;\n\t\tlong max_so_far = Integer.MIN_VALUE, max_ending_here = 0;\n\n\t\tfor (int anArr : arr) {\n\t\t\tmax_ending_here = max_ending_here + anArr;\n\t\t\tif (max_so_far < max_ending_here)\n\t\t\t\tmax_so_far = max_ending_here;\n\t\t\tif (max_ending_here < 0)\n\t\t\t\tmax_ending_here = 0;\n\t\t}\n\t\treturn max_so_far;\n\t}\n\n\tpublic static void main(String args[]) throws IOException {\n\t\trun();\n\t}\n\n\tprivate static void run() throws IOException {\n\t\tfr = new Reader();\n\t\tout = new BufferedOutputStream(System.out);\n\t\tsolve();\n\t\tout.flush();\n\t\tout.close();\n\t}\n\tstatic int mod=1000000007;\n\tprivate static void solve() throws IOException \n\t{\n\t int n = fr.nextInt();\n\t String s=fr.readLine();\n\t int min=Integer.MAX_VALUE;\n\t\tfor(int i=0;itemp)\n\t\t min=temp;\n\t\t}\n\t System.out.println(min);\n\t \n }\n statica int fun(String s,int i)\n { \n \n int a=(int)Math.min(Math.abs(s.charAt(i)-'A'),Math.abs('A'-s.charAt(i))); \n int b=(int)Math.min(Math.abs(s.charAt(i+1)-'C'),Math.abs('C'-s.charAt(i+1))); \n int c=(int)Math.min(Math.abs(s.charAt(i+2)-'T'),Math.abs('T'-s.charAt(i+2))); \n int d=(int)Math.min(Math.abs(s.charAt(i+3)-'G'),Math.abs('G'-s.charAt(i+3)));\n if(a==25)\n a=1;\n if(b==25)\n b=1;\n if(c==25)\n c=1;\n if(c==25)\n c=1;\n return a+b+c+d;\n }\n static void task0(ArrayList[] g ,long a[],long b[],long c[],int n,int s,int p,long x)\n {\n x=gcd1(x,a[s]);\n System.out.print(x+\" \");\n if(g[s].size()==1&&s!=0)\n {\n c[s]=gcd1(x,b[s]);\n \n }\n for(int i=0;i[] g,int n)\n {\n for(int i=0;i0){\n System.out.println(\"YES\");\n }else{\n System.out.println(\"NO\");\n }\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bdf629851a73623413c968bceeb06e92", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.HashSet;\nimport java.util.Set;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n \n String tableCard = scanner.nextLine();\n String hand = scanner.nextLine();\n \n Set rank = new HashSet<>();\n Set suit = new HashSet<>();\n\n for (int i = 0; i < 5; ++i) {\n rank.add(hand[i*3]);\n suit.add(hand[1+i*3]);\n }\n\n if (rank.contains(tableCard[0]) || suit.contains(tableCard[1])) {\n System.out.println(\"YES\");\n }\n\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0f6123c75468f811f6956ee9d45332de", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class sum{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tString st = sc.next();\n\t\tString sh[] = new String[5];\n\t\tString ans = null;\n\t\tfor(int i=0;i<5;i++){\n\t\t\tsh = sc.next();\n\t\t}\n\n\t\tfor(int i=0;i<5;i++){\n\t\t\tif(sh[i].charAt(0) == st.charAt(0) || sh[i].charAt(1) == st.charAt(1) ){\n\t\t\t\t ans = \"YES\";\n\t\t\t\tSystem.out.println(ans);\n\t\t\tbreak;\n\t\t}\n\t\t}\n\n\t\tif(ans!=\"YES\")\n\t\tSystem.out.println(\"NO\");\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "22c0818975f3521a93ea78709ee7ce06", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class test\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in());\n\t String s=sc.nextLine();\n\t char c[]=s.toCharArray();\n\t for(int i=0;i<5;i++)\n\t {\n\t\t s=sc.next();\n\t\t char ch[]=s.toCharArray();\n\t\t if(c[0]==ch[0] || c[1]==ch[1])\n\t\t {\n System.out.println(\"YES\");\n\t\t\tbreak;\n\t\t }\n\t }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "859b80381abaa5c291fb63a070a87f78", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n \npublic class Main{\n public static void main(String[] args) {\n Scanner scn=new Scanner(System.in);\n\tint n=scn.nextInt();\n\tint k=scn.nextInt();\n\tint[] a=new int[n];\n\tboolean all=true;\n\tfor(int i=0;ik)\n\t\tall=false;\n\t}\n\tint ans=0,j=0;\n\tif(all)\n\tans=n;\n\telse{\n\twhile((a[j]<=k)&&j!=n)\n\t{\n\t\tans++;\n\t\tj++;\n\t}\n\n\tint l=n-1;\n\twhile(a[l]<=k&&l!=0&&flag!=1)\n\t{\n\t\tans++;\n\t\tl--;\n\t}\n\t}\n\tSystem.out.println(ans);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d3681810fac8b5bd09dae3da0ddaf47", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class HanSolo {\n\n public static void main(String[] args) {\n Scanner ict = new Scanner(System.in);\n int counter=0, x = 0;\n int n = ict.nextInt(), k = ict.nextInt();\n\n int[] arr = new int[n];\n\n for(int i = 0; i < arr.length; i++){\n arr[i] = ict.nextInt();\n }\n\n for(x = 0; x < arr.length && x >= arr[x]; x++){\n counter++;\n\n }\n if(x != n) {\n for (int i = arr.length - 1; i >= 0 && k >= arr[i]; i--) {\n counter++;\n\n }\n }\n System.out.println(counter);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "77653509bc7c2ec006b37b26a6b41e84", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.io.IOException;\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport static javaapplication31.NastyandanArray.n;\n\n/**\n *\n * @author kinan\n */\npublic class MishkaandContest {\n public static void main(String[] args) throws IOException {\n //ArrayList list = new ArrayList();\n ArrayList list1 = new ArrayList();\n // ArrayList list2 = new ArrayList();\n \n Scanner scanner = new Scanner(System.in);\n int x=0;\n int r=0;\n int y=0;\n n = scanner.nextInt();\n int k =scanner.nextInt();\n int[] f = new int[n];\n\n for (int i = 0; i < n; i++) {\n f[i] = Integer.parseInt(scanner.next());\n }\n \n \n for (int i =0;i k){\n list1.add(i+1); \n x = list1.get(0);\n int l = (list1.size()-1);\n int index = list1.get(l);\n y = n - index + 1; }\n \n if (f[i] < k){\n x =f.length;\n y=0;\n } \n if (f[0]>k && f[f.length-1]>k){\n x =-1;\n y=0;\n }}\n\n \n \n \n \n int max = Math.max(x,y);\n System.out.print(max);\n \n }\n }\n \n \n \n \n \n \n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9b632b00479efe8121f12803ef6afdf4", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\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 k = sc.nextInt();\n int a[] = new int[n];\n for(int i=0;i s = new Stack<>();\n for(int i = 0 ; i < text.length() ; i++){\n if(s.peek() == \"/\" && s.charAt(i) == \"/\"){\n \n }else {\n s.add(s.charAt(i));\n ans += s.peek() ;\n }\n }\n System.out.print(ans) ;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "873111cdbb60a155a437cd7be65c1c5a", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n \npublic class Solution{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n String s = in.nextLine();\n \n \n for(int i = 0; i < 10; i++){\n s = s.replace(\"//\",\"/\");\n }\n if(s.length() == 1 && s.charAt(0) == '/'){\n System.out.println(\"/\");\n break;\n }\n else if(s.charAt(s.length() - 1) == '/'){\n s = s.substring(0, s.length() - 1);\n }\n System.out.println(s);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9e04059f3ecec5b07bf7972a1d21196d", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import net.egork.utils.Solver;\nimport net.egork.utils.io.InputReader;\n\nimport java.io.PrintWriter;\n\npublic class FsBERoS implements Solver {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n char s[] = in.readLine().toCharArray();\n boolean yet = false;\n for (int i = 0; i < s.length; ) {\n int j = i;\n for (; j < s.length && s[j] == '/'; ++j) ;\n if (yet && j < s.length && j - i > 0 || !yet && j - i > 0) {\n out.print(\"/\");\n yet = true;\n }\n int k = j;\n while (k < s.length && s[k] != '/') ++ k;\n for (int u = j; u < k; ++u)\n out.print(s[u]);\n i = k;\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67a4804316e4af4ea1929a72c2daa12a", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class C230 {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tlong n = scan.nextLong();\n\t\tif(n==0){System.out.println(1);return;}\n\t\tlong sol = 0;\n\t\tlong x = 0, y = n;\n\t\tlong n2 = n*n;\n\t\twhile(x!=n||y!=0){\n\t\t\tif (x*x+y*y-n2>1e-8){\n\t\t\t\ty--;\n\t\t\t}else{\n\t\t\t\tsol++;\n\t\t\t\tif((x+1)*(x+1)+y*y-n2>1e-8 &&\n\t\t\t\t (x+1)*(x+1)+(y-1)*(y-1)-n2>1e-8){\n\t\t\t\t\ty--;\n\t\t\t\t}else{\n\t\t\t\t\tx++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(sol*4);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "56936473f3deb48d39f773e3d1e497c4", "src_uid": "d87ce09acb8401e910ca6ef3529566f4", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class d {\npublic static void main(String[] args) {\n\tScanner scan= new Scanner (System.in);\n\t\n\tint n=scan.nextInt();\n \n\tSystem.out.println(calc (n));\n}\n\n\tstatic int calc ( int n )\n\t{\n\t\tif(n==0)\n\t\t{\n\t\t\treturn 1;\n\t\t}\n\t\tif(n==1)\n\t\t{\n\t\t\treturn 4;\n\t\t}\n\t\tif(n%2==0)\n\t\t{\n\t\treturn calc (n-1) + 4;\n\t\t}\n\t\treturn calc(n-1)*2;\n\t\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fb2d66ae05fd4dc6b8c2e0e6476d7866", "src_uid": "d87ce09acb8401e910ca6ef3529566f4", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class d {\npublic static void main(String[] args) {\n\tScanner scan= new Scanner (System.in);\n\t\n\tint n=scan.nextInt();\n\tSystem.out.println(calc (n));\n}\n\n\tstatic int calc ( int n )\n\t{\n\t\tif(n==1)\n\t\t{\n\t\t\treturn 4;\n\t\t}\n\t\tif(n%2==0)\n\t\t{\n\t\treturn calc (n-1) + 4;\n\t\t}\n\t\treturn calc(n-1)*2;\n\t\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70da2b387de85acc0cfd33f877d4fb14", "src_uid": "d87ce09acb8401e910ca6ef3529566f4", "difficulty": null} {"lang": "Java 8", "source_code": "import java.lang.Math; \nimport java.io.*;\npublic class HelloWorld\n{\n \n public static void main(String[] args) throws IOException\n {\n BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(bf.readLine());\n PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n pw.write((int)Math.max(1,4*(Math.pow(*2,0.5))*n)+\"\\n\");\n pw.flush(); \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1b6226796799def209f6c5e414e32aa6", "src_uid": "d87ce09acb8401e910ca6ef3529566f4", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class codeforces1 {\n\tpublic static void main(String[] args) {\n\t\tScanner lee=new Scanner(System.in);\n\t\tlong x,cont=0;\n\t\tdo {\n\t\tx=lee.nextInt();\n\t\t}while(x<1||x>100000);\n\t\tcont=x/2+x/3+x/5+x/7-x/6-x/10-x/14-x/15-x/21-x/35+x/30+x/42+x/70+x/105-x/210;\n\t\tSystem.out.println(x-cont);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd748f85d7c6b30b00589630e8100553", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class codeforces1 {\n\tpublic static void main(String[] args) {\n\t\tScanner lee=new Scanner(System.in);\n\t\tlong x,cont=0;\n\t\tdo {\n\t\tx=lee.nextInt();\n\t\t}while(x<1);\n\t\tcont=x/2+x/3+x/5+x/7-x/6-x/10-x/14-x/15-x/21-x/35+x/30+x/42+x/70+x/105-x/210;\n\t\tSystem.out.println(x-cont);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b7db8b6796846fb0bd1e7c49f26fa894", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class K {\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n static InputReader r = new InputReader(System.in);\n static PrintWriter pw = new PrintWriter(System.out);\n\n public static void main(String[] args) {\n long n = r.nextLong();\n\n long[] notDiv = new long[2521];\n for(int i = 1; i <= 2520; i++){\n if(i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0){\n notDiv[i] = notDiv[i-1] + 1;\n } else{\n notDiv[i] = notDiv[i-1];\n }\n }\n pw.println(notDiv[2520] * (n/2520) + notDiv[n%2520]);\n pw.close();\n }\n}\n\n/**\n* _ _ _ \n* | | | | | | \n* ___ ___ __| | ___ | |__ _ _ __| | __ _ _ __ _ __ ___ _ __ _ _ __ _ ___ \n* / __/ _ \\ / _` |/ _ \\ | '_ \\| | | | / _` |/ _` | '__| '__/ _ \\ '_ \\ | | | |/ _` |/ _ \\ \n* | (_| (_) | (_| | __/ | |_) | |_| | | (_| | (_| | | | | | __/ | | | | |_| | (_| | (_) |\n* \\___\\___/ \\__,_|\\___| |_.__/ \\__, | \\__,_|\\__,_|_| |_| \\___|_| |_| \\__, |\\__,_|\\___/ \n* __/ | ______ __/ | \n* |___/ |______|___/ \n */", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f9217703521f287c4eb010892d7bc2a6", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Solution\n{\n public static void main(String args[])\n {\n Scanner in=new Scanner(System.in);\n long inp=in.nextLong();\n long add[]=new Long[7];\n long sub[]= new Long[7];\n add[0]=inp/2;\n add[1]=inp/3;\n add[2]=inp/5;\n add[3]=inp/7;\n add[4]=inp/30;\n add[5]=inp/105;\n add[6]=inp/70;\n sub[0]=inp/6;\n sub[1]=inp/10;\n sub[2]=inp/14;\n sub[3]=inp/15;\n sub[4]=inp/21;\n\t\tsub[5]=inp/35;\n\t\tsub[6]=inp/210;\n\t\tlong out=0;\n\t\tfor(int i=0;i<7;i++)\n\t\t{\n\t\t\tout+=add[i];\n\t\t}\n\t\tfor(int i=0;i<7;i++)\n\t\t{\n\t\t\tout-=sub[i];\n\t\t}\n\t\t\tout=inp-out;\n\t\t\tSystem.out.println(out);\n\t\tin.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "07443f7185ed77c93222379e0ff6e227", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint[] arr = new int[3];\n\t\tarr[0] = in.nextInt();\n\t\tarr[1] = in.nextInt();\n\t\tarr[2] = in.nextInt();\n\t\tint minDistance = 0;\n\t\tArrays.sort(arr);\n\t\tif (arr[0]+arr[1]<=arr[2]) {\n\t\t\tminDistance = 2 * (arr[0]+arr[1]);\n\t\t} else {\n\t\t\tif (arr[0]==arr[1] && arr[2]==arr[1]]) {\n\t\t\t\tminDistance = arr[0]+arr[2]+arr[2];\n\t\t\t} else {\n\t\t\t\tminDistance = 2 * (arr[0]+arr[2]);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(minDistance);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eb6803eead2d50bc6b0faed37ba74d13", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class _1\n{\n public static void main(String args[])\n {\n Scanner in=new Scanner(System.in);\n long x=in.nextLong();\n long y=in.nextLong();\n long z=in.nextLong();\n \n System.out.println(Math.min(2*(x+y),x+y+z));\n \n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "413f8e8d06f08f91f6d95db394b0c3cd", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.math;\n\npublic class Solution{\n public static void main(String []args){\n long d1,d2,d3,dis1,dis2,dis3,dis4;\n Scanner scan=new Scanner(System.in);\n d1=scan.nextInt();\n d2=scan.nextInt();\n d3=scan.nextInt();\n dis1=d1+d2+d3;\n dis2=d1+d3+d3+d1;\n dis3=d2+d3+d3+d2;\n dis4=d1+d1+d2+d2;\n System.out.println(Math.min(dis1,Math.min(dis2,Math.min(dis3,dis4))));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ce3daa499b43c19c4b3c6e5448f11db1", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class A{\n \n public static void main(String []args){\n BufferedReader br = new BufferedReader(new FileReader(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(\"output\")));\n StringTokenizer st = new StringTokenizer(br.readLine());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int c = Integer.parseInt(st.nextToken());\n if (a + b < c)\n pw.println(2 * (a + b));\n else\n pw.println(2 * c);\n pw.close();\n System.exit(0);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2e21d193a6d5c9c812a8d3291a45317d", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class c {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tFastReader s = new FastReader();\n\t\tint len = s.nextInt();\n\t\tString str = s.next();\n\t\t\n\t\tString ans = \"\";\n\t\tint i=0;\n\t\tint inc = 1;\n\t\twhile(i\n {\n int val;\n int dex;\n \n public Pair(int a, int b)\n {\n val = a;\n dex = b;\n }\n public int compareTo(Pair oth)\n {\n return val-oth.val;\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e4106aff7053985441bf8d074af312c", "src_uid": "692698d4b49ad446984f3a7a631f961d", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "public class A1 {\n \n public static void main(String args[]) {\n Scanner sc = new Scanner();\n int n = sc.nextInt();\n int m = sc.nextInt();\n int[] pt = new int[n];\n int[] x = new int[m];\n int[] y = new int[m];\n for (int i=0; i= x[j] && pt[i] <= y[j]) {\n System.out.print(\"0 \");\n belongs = 1;\n break;\n }\n }\n if (belongs == 0) {\n System.out.print(\"-1 \");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b3b033fe3a84d5ceebd8821670ad7de8", "src_uid": "692698d4b49ad446984f3a7a631f961d", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\n\npublic class Points_and_Segments_easy_430\n{\n\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tPoints_and_Segments_easy_430 main = new Points_and_Segments_easy_430();\n\t\tmain.input();\n\t\tmain.solve();\n\t}\n\n\tvoid solve()\n\t{\n\n\t\tfor (int i : points)\n\t\t{\n\t\t\tSystem.out.print(cols[i] + \" \");\n\t\t}\n\t}\n\n\t/******************************************************************\n\t ****************************** INPUT******************************\n\t ******************************************************************/\n\n\tstatic int n;\n\tstatic int m;\n\tstatic Integer[] cols;\n\tstatic Integer[] pos;\n\tstatic int[] points;\n\n\t// static int[][] segments;\n\n\tvoid input() throws IOException\n\t{\n\t\tInit(System.in);\n\t\tn = NextInt();\n\t\tm = NextInt();\n\t\tcols = new Integer[n];\n\t\tpoints = new int[n];\n\t\tint point = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tpoint = NextInt();\n\t\t\tpoints[i] = point;\n\t\t\tif ((point & 0x00000001) == 0)\n\t\t\t{\n\t\t\t\tcols[point] = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcols[point] = 1;\n\t\t\t}\n\t\t}\n\t}\n\n\t/******************************************************************\n\t ****************************** READER*****************************\n\t ******************************************************************/\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\n\tstatic void Init(InputStream input)\n\t{\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\tstatic String Next() throws IOException\n\t{\n\n\t\twhile (!tokenizer.hasMoreTokens())\n\t\t{\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tstatic int NextInt() throws IOException\n\t{\n\n\t\treturn Integer.parseInt(Next());\n\t}\n\n\tstatic long NextLong() throws IOException\n\t{\n\n\t\treturn Long.parseLong(Next());\n\t}\n\n\tstatic Double NextDouble() throws IOException\n\t{\n\n\t\treturn Double.parseDouble(Next());\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e0d2fc4c8f5d493fa1b7b56e5576cf23", "src_uid": "692698d4b49ad446984f3a7a631f961d", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class TaskA {\n public static void main(String[] args){\n FastScanner3 sc = new FastScanner3();\n int n = sc.nextInt();\n int m = sc.nextInt();\n int[] points = sc.readIntArray(n);\n Arrays.sort(points);\n Segment[] segments = new Segment[n];\n for(int i=0;i=1 && points[pointsStop] > s.stop;pointsStop--){}\n// if(pointsStart > pointsStop){\n// continue;\n// }\n// int size = pointsStop - pointsStart + 1;\n// \n// }\n for(int i=0;i{\n int start,stop;\n int dist;\n public Segment(int start, int stop){\n this.start = start;\n this.stop = stop;\n dist = stop - start;\n }\n @Override\n public int compareTo(Segment arg0) {\n return ((Integer) dist).compareTo(arg0.dist);\n }\n \n \n}\n\nclass FastScanner3 {\n\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner3() {\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public int[] readIntArray(int n){\n int[] ret = new int[n];\n for(int i=0;i= 0 && x < 8 && y >= 0 && y < 8);\n }\n static boolean isstatue(int x, int y) {\n return (isinside(x, y) && c[x][y] == 'S');\n }\n static boolean Try(int t, int x, int y) {\n if (t > MAXSTEPS) return false;\n if (!isinside(x, y)) return false;\n if (isstatue(x-t, y)) return false;\n if (x == 0 && y == 7) return true;\n if (d[t][x][y] != -1) return (d[t][x][y]==1) ? true : false;\n boolean res = false;\n for (int i = 0; i < 8; i++) {\n int nx = x + fx[i];\n int ny = y + fy[i];\n if (isinside(nx, ny) && !isstatue(nx-t, ny))\n res |= Try(t+1, nx, ny);\n }\n d[t][x][y] = (res) ? 1 : 0;\n return res;\n }\n public static void main(String []args) {\n Scanner nhap = new Scanner(System.in);\n for (int i = 0; i < 8; i++) {\n c[i] = nhap.next().toCharArray();\n //System.out.println(c[i]);\n }\n for (int i = 0; i < MAXSTEPS; i++)\n for (int j = 0; j < 8; j++)\n Arrays.fill(d[i][j], -1);\n System.out.print(Try(0, 7, 0) ? \"WIN\" : \"LOSE\");\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "59ae5f0f10436f62aaac52174ba5306d", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.Queue;\nimport java.util.Scanner;\n\n\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n char[][][] cs = new char[20][8][8];\n for(int i = 0; i < 8; i++) {\n cs[0][i] = sc.next().toCharArray();\n }\n \n for(int i = 0; i < 19; i++) {\n for(int y = 0; y < 8; y++)\n for(int x = 0; x < 8; x++)\n if(cs[i][y][x] == 'M')\n for(int dy = -1; dy <= 1; dy++)\n for(int dx = -1; dx <= 1; dx++) {\n final int xx = x+dx;\n final int yy = y+dy;\n if(0 <= xx && xx < 8 && 0 <= yy && yy < 8 && cs[i][yy][xx] != 'S')\n cs[i+1][yy][xx] = 'M';\n }\n \n for(int y = 6; y >= 0; y--)\n for(int x = 0; x < 8; x++)\n if(cs[i][y][x] == 'S')\n cs[i+1][y+1][x] = 'S';\n }\n \n String res = \"LOSE\";\n for(int y = 0; y < 8; y++)\n for(int x = 0; x < 8; x++)\n if(cs[19][y][x] == 'M')\n res = \"WIN\";\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7347447ec27560f19fa145c0e18ae2df", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "Main\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class C {\n static int[] dx = { 0, 0, 0, 1, -1, 1, 1, -1, -1 };\n static int[] dy = { 0, 1, -1, 0, 0, 1, -1, -1, 1 };\n\n public static boolean rec(char[][] B, int x, int y, int t) {\n if (t >= 8)\n return true;\n if (B[x][y] == 'S')\n return false;\n char[][] _B = new char[8][8];\n for (int i = 0; i < 7; i++)\n for (int j = 0; j < 8; j++)\n if (B[i][j] == 'S') {\n _B[i + 1][j] = 'S';\n }\n for (int i = 0; i < 9; i++) {\n int X = x + dx[i];\n int Y = y + dy[i];\n if (X < 0 || Y < 0 || X == 8 || Y == 8)\n continue;\n if (B[X][Y] != 'S' && rec(_B, X, Y, t + 1))\n return true;\n\n }\n return false;\n }\n\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n char[][] B = new char[8][8];\n for (int i = 0; i < 8; i++)\n B[i] = in.readLine().toCharArray();\n if (rec(B, 7, 0, 0))\n System.out.println(\"WIN\");\n else\n System.out.println(\"LOSE\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d48ab85bcdbe75758ebc369df4173193", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n//public static HashMap hs=new HashMap();\npublic static LinkedList graph [] = new LinkedList[64];\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st;\n LinkedList stat = new LinkedList();\n start();\n boolean [] visited = new boolean[64];\n boolean [] steps = new boolean[100];\n int [] parent = new int[64];\n int m =0, a=0;\n for (int i = 0; i < 8; i++) {\n st=new StringTokenizer(in.readLine().trim());\n char[]c=st.nextToken().toCharArray();\n for (int j = 0; j < 8; j++) {\n if(c[j]=='S'){\n int pos =(i*8)+j;\n stat.add(pos);\n // System.out.println(\"S: \"+pos);\n }\n else if(c[j]=='M'){\n m=(i*8)+j;\n }\n else if(c[j]=='A'){\n a=(i*8)+j;\n }\n }\n }// end of for\n\n Stack list = new Stack();\n list.add(m);\n boolean reach=false;\n while(!list.isEmpty()){\n int temp = list.pop();\n visited[temp]=true;\n if(temp==a){\n reach=true;\n break;\n }\n for (int i = 0; i < graph[temp].size(); i++) {\n int pos=graph[temp].get(i);\n parent[pos]=parent[temp]+1;\n if( statue(pos ,stat , parent[pos] )){\n list.add(pos);\n }\n }\n\n }\n if(reach)\n System.out.println(\"WIN\");\n else\n System.out.println(\"LOSE\");\n\n }\npublic static void start(){\n int count=1;\n for (int i = 0; i < graph.length; i++) {\n graph[i]= new LinkedList();\n\n }\n for (int i = 0; i < 8; i++) {\n for (int j = 0; j < 8; j++) {\n int pos = (i*8)+j;\n // System.out.print(\"p : \"+pos);\n graph[pos].add(pos); if(j+1<8)graph[pos].add(pos+1);\n if(j-1 >= 0)graph[pos].add(pos-1);\n // if(i+7 >= 0 && j+7<8)graph[pos].add(pos+7);\n if(i-1 >= 0 && j+1<8)graph[pos].add(pos-7);\n // if(i+9 >= 0 && j+9<8)graph[pos].add(pos+9);\n if(i-1 >= 0 && j-1 >=0)graph[pos].add(pos-9);\n // if(i+8 >= 0 && j+8<8)graph[pos].add(pos+8);\n if(i-1 >= 0)graph[pos].add(pos-8);\n }\n // System.out.println(\"\");\n }\n for (int i = 0; i < graph.length; i++) {\n LinkedList temp = graph[i];\n for (int j = 0; j < temp.size(); j++) {\n // System.out.print(temp.get(j)+\" \");\n }\n // System.out.println(\"--\");\n }\n }\npublic static boolean statue(int pos , LinkedList stat , int step){\nboolean flag=true;\n for (int i = 0; i < stat.size(); i++) {\n if((stat.get(i)+(8*(step-1))<64)&&stat.get(i)+(8*(step-1))==pos)\n flag=false;\n \n if((stat.get(i)+(8*step)<64)&&stat.get(i)+(8*step)==pos)\n flag=false;\n\n }\n // System.out.println(\"pos \"+pos+\" flag \"+flag+\" step \"+step);\nreturn flag;\n}\n}\n\nclass node {\n int i,j;\n\n public node (int a, int b ){\n i=a;\n j=b;\n\n\n\n }\n\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4baa744257d5d0535599a99e6e675886", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n \n long x = sc.nextLong();\n \n long binaryForm = 0;\n \n long number = x;\n int count = 0;\n \n while(number > 0){\n int rem = number%2;\n number /= 2;\n binaryForm += rem*(long)Math.pow(10,count);\n count++;\n }\n \n int noOfOnes = 0;\n long bForm = binaryForm;\n while(bForm > 0){\n if(bForm%10 == 1){\n noOfOnes++;\n }\n \n bForm /= 10;\n }\n \n System.out.println(noOfOnes);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d1a432561d0b6ddfcadc7e02a658ba0f", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "input Java.IO.File;\npublic class RaisingBacteria{\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x = sc.nextInt();\n\n\t\tif(x%2 == 0){\n\t\t\treturn 1;\n\t\t}\n\t\telse{\n\t\t\treturn 2;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a8e4b29c971befff1588938c06dde1c1", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "package code;\nimport java.util.Scanner;\npublic class emy {\n\n\tpublic static void main(String[] args) {\n\t\tint x,sum=0,count=0;\n\t\tScanner input=new Scanner(System.in);\n\t\tx=input.nextInt();\n\t\tif(x!=0)\n\t\t{\n\t\t\tcount++;\n\t\t\tsum++;\n\t\t}\n\t\twhile(countx)\n\t\t{\n\t\t\tcount/=2;\n\t\t\tsum+=x-count;\n\t\t}\n\t\tSystem.out.println(sum);\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a1b92e4c2495375e016f57aafd021b9e", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.util;\nimport java.lang;\nimport java.io;\n\npublic class Ideone {\n public static void main (String[] args) {\n \n int x = 0;\n Scanner sc = new Scanner(System.in);\n x = sc.nextInt();\n \n if (x <= 0) {\n System.out.println (\"0\");\n \n } else if (x%2 == 0) {\n System.out.println (\"1\");\n } else {\n System.out.println (\"2\");\n }\n \n System.exit(0);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5c69b6596c14f66ef57a9643b0a86b8d", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n\tpublic static int intat(int a,int cur)\n\t{\n\t\tint tema=a;\n\t\tfor(int flag=0;flag=2)\n\t\t\t\t{\n\t\t\t\t\tdr++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdr-=pr;\n\t\t\tif(dr!=g[flag].difright)\n\t\t\t\treturn false;\n\t\t\tif(pr!=g[flag].posright)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner cin=new Scanner(System.in);\n\t\tint line;\n\t\twhile(cin.hasNextInt())\n\t\t{\n\t\t\tline=cin.nextInt();\n\t\t\tguess g[]=new guess[105];\n\t\t\tfor(int flag=0;flag1)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"Need more data\");\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "284e287b066e4559b26a801fb81f72cb", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 2/28/11\n * Time: 9:18 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class Task3 {\n\n\tint[] a;\n\tint[] b;\n\tint[] c;\n\tArrayList list = new ArrayList();\n\n\tint bull(int a, int b){\n\t\tint ans = 0, i = 0;\n\t\twhile(i < 4){\n\t\t\tif(a % 10 == b % 10)ans++;\n\t\t\ta /= 10; b /= 10;\n\t\t\ti++;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tint cow(int a, int b){\n\t\tint ans = 0, i = 0;\n\t\twhile(i < 4){\n\t\t\tint find = a % 10;\n\t\t\tint x = b;\n\t\t\tfor(int j = 0; j < 4; j++){\n\t\t\t\tif(j != i && find == x % 10)ans++;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\ta /= 10;\n\t\t\ti++;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tvoid solve(int n, boolean[] used, int x){\n\t\tif(n == 4){\n\t\t\tboolean ok = true;\n\t\t\tfor(int i = 0; i < a.length && ok; i++){\n\t\t\t\tok = ok && bull(a[i], x) == b[i];\n\t\t\t\tok = ok && cow(a[i], x) == c[i];\n\t\t\t}\n\t\t\tif(ok) list.add(x);\n\t\t\treturn;\n\t\t}\n\n\t\tfor(int i = 0; i < 10; i++)\n\t\t\tif(!used[i]){\n\t\t\t\tused[i] = true;\n\t\t\t\tsolve(n + 1, used, x * 10 + i);\n\t\t\t\tused[i] = false;\n\t\t\t}\n\n\t}\n\n\tvoid run(){\n \t\tint n = nextInt();\n\t\ta = new int[n];\n\t\tb = new int[n];\n\t\tc = new int[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\ta[i] = nextInt(); b[i] = nextInt(); c[i] = nextInt();\n\t\t}\n\n\t\tboolean[] used = new boolean[10];\n\t\tsolve(0, used, 0);\n\n\t\tif(list.size() == 1){\n\t\t\tSystem.out.println(list.get(0));\n\t\t}else if(list.size() > 1){\n\t\t\tSystem.out.println(\"Need more data\");\n\t\t}else{\n\t\t\tSystem.out.println(\"Incorrect data\");\n\t\t}\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 Task3().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "edd9b888e0e413989cd9a98e93606c63", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\n\n\npublic class bullCow\n{\n\n static int [] countN(int a)\n {\n String s = Integer.toString(a);\n if(s.length() < 4)\n s = \"0000\".substring(0,4-s.length()) + s;\n int [] count = new int[10];\n for(int i=0;i1)\n return false;\n return true;\n }\n \n static boolean match(int m, int [] guess)\n {\n int arr[][] = new int[2][4];\n int nn[] = {m, guess[0]};\n for(int i=0;i<2;i++)\n {\n int a = nn[i];\n for(int j=0;j<4;j++)\n {\n arr[i][j] = a%10;\n a/=10;\n }\n }\n int cows = 0, bulls = 0;\n for(int i=0;i<4;i++)\n for(int j=0;j<4;j++)\n if(arr[0][i] == arr[1][j])\n if(i == j)\n bulls++;\n else\n cows++;\n return (guess[1] == bulls && guess[2] == cows);\n }\n\n\n public static void main(String [] args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int [][] guess = new int[n][3];\n for(int i=0;i matches = new ArrayList();\n for(int i=100;i<10000;i++)\n {\n if(!check(i))\n continue;\n boolean ok = true;\n for(int j=0;j 1)\n System.out.println(\"Need more data\");\n else\n if(matches.size() == 0)\n System.out.println(\"Incorrect data\");\n else\n System.out.println(matches.get(0));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b5e7e0fd663d2986c28a0de19421be65", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.LinkedList;\n\n\npublic class C {\n\tstatic String[] data;\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n\t\tString s=r.readLine();\n\t\t\n\t\tint n=Integer.parseInt(s);\n\t\tdata=new String[n];\n\t\tfor (int i = 0; i < data.length; i++) {\n\t\t\tdata[i]=r.readLine();\n\t\t}\n\t\t\n\t\tLinkedList l=new LinkedList();\n\t\tfor(int a=0;a<10;a++ ){\n\t\t\tfor(int b=0;b<10;b++){\n\t\t\t\tfor(int c=0;c<10;c++){\n\t\t\t\t\tfor(int d=0;d<10;d++){\n\t\t\t\t\t\tString num=a+\"\"+b+\"\"+c+\"\"+d;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(can(num))l.add(num);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(l.size()==0)System.out.println(\"Incorrect data\");\n\t\telse if(l.size()>1)System.out.println(\"Need more data\");\n\t\telse System.out.println(l.remove());\n\t}\n\tprivate static boolean can(String num) {\n\t\tfor(String s:data){\n\t\t\tif(!c(num,s))return false;\n\t\t}\n\t\treturn true;\n\t}\n\tprivate static boolean c(String num, String s) {\n\t\tString[] sp=s.split(\" \");\n\t\tString comp=sp[0];\n\t\tint similar=Integer.parseInt(sp[1]);\n\t\tint dif=Integer.parseInt(sp[2]);\n\t\tint count=0; //similar\n\t\n\t\tfor(int i=0;i=0){\n System.out.print(n-k);\n }\n else{\n for(;r>0;r--){\n n--;\n count++;\n }\n \n for(;k-count>0;count++){\n n=n/10;\n }\n }\n }\n else{\n for(;count0)\n {\n if(n%10==0){n=n/10;}\n else n--;\n k--;}\n System.out.println(n);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05081ded79b5ebdf39aaeacb6319a6fa", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package com.wrongsubtraction;\n\npublic class NewClass {\n\n\n\tpublic static void main(String[] args) {\n\t \n\t int x ;\n\t int y;\n\n\t\tSystem.out.println(WrongSubtraction(x , y));\n\t}\n\n\tpublic static int WrongSubtraction(int number, int index) {\n\n\t\tfor (int i = 0; i < index; i++) {\n\t\t\tif ((number % 10) == 0)\n\t\t\t\tnumber /= 10;\n\t\t\telse\n\t\t\t\tnumber -= 1;\n\t\t}\n\t\treturn number;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4fb9f53816af22c11ac15bcc353ef7f1", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n \npublic class Test{\n \n public static void main(String args[]) throws IOException\n {\n Scanner scanner = new Scanner(System.in);\n int number,steps;\n number = scanner.nextInt();\n steps = scanner.nextInt();\n for(int i=0;i 0)\n {\n \n }*/\n \n }\n \n static class Scanner {\n \n StringTokenizer st;\n BufferedReader br;\n \n public Scanner(InputStream system) {\n br = new BufferedReader(new InputStreamReader(system));\n }\n \n public Scanner(String file) throws Exception {\n br = new BufferedReader(new FileReader(file));\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 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 public void waitForInput() throws InterruptedException {\n Thread.sleep(3000);\n }\n }\n}\n \n \n \n \n \nClick to see test details\n\nCodeforces (c) Copyright 2010-2020 Mike Mirzayanov\nThe only programming contests Web 2.0 platform\nServer time: Jan/22/2020 13:10:52UTC+6 (g2).\nDesktop version, switch to mobile version.\nPrivacy Policy\nSupported by\nTelegram \u0418\u0422\u041c\u041e\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "32b5cbf041a9f72cb463c424cde071f1", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tString x = sc.next();\n\t\tint n = x.length();\n\t\tlong all = Long.parseLong(x, 2);\n\t\tBigInteger m = BigInteger.valueOf(2).modPow(BigInteger.valueOf(n - 1), BigInteger.valueOf(1000000007));\n\t\tBigInteger res = m.multiply(BigInteger.valueOf(all).mod(BigInteger.valueOf(1000000007)));\n\t\tres = res.mod(BigInteger.valueOf(1000000007));\n\t\tout.println(res);\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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e03a5333bd465b895f0f092b9668af5", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0} {"lang": "Java 7", "source_code": " package cont187.copy;\n \n \n import java.util.*;\n \n public class probA {\n \n private static Scanner in;\n \n public static void main(String[] args) {\n in = new Scanner(System.in);\n String s =in.nextLine();\n int n = s.length();\n long ans[] = new long[n];\n long pow[] = new long[n+19];\n long pow1[] = new long[n+19];\n int mod = 1000000007;\n long Ans = 0;\n \n \n pow[0] = 1;\n pow1[0] = 2;\n \n for (int i = 1; i < n+1; i++){ \n pow[i] = pow[i-1]*2 % mod;\n pow1[i] = (pow[i] + pow1[i-1]) %mod;\n }\n \n for(int i = 0; i0) ans[i] = (pow1[i-1])*pow[i]; else ans[i] = 1; \n if (i>0) ans[i] +=ans[i-1];\n ans[i] = ans[i]%mod;\n Ans += ans[i];\n ans[i] = Ans;\n }\n System.out.println(Ans%mod);\n }\n}\n\n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4b89997e1852060964ba517952967ae", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n/**\n *\n * @author Javi\n */\npublic class MalekDanceClub {\n\n private static final int MODULO = 1000000007;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String[] input = in.nextLine().split(\" \");\n String binaryEntry = input[0];\n\n int modPower = modularPower(binaryEntry.length());\n int modEntry = modularEntry(binaryEntry);\n long modProduct = modularProduct(modEntry, modPower);\n System.out.println(modProduct);\n\n // Binary number --> BigInteger\n // (BigInteger times 2^(n-1)) mod (10^(9)+7)\n\n in.close();\n }\n\n private static int modularPower(int n) {\n int res = 1;\n for (int i = 1; i < n; i++) {\n res = res * 2;\n if (res > MODULO) {\n res = res % MODULO;\n }\n }\n return res;\n }\n\n private static int modularEntry(String number) {\n int accCount = 1;\n int res = 0;\n for (int i = number.length() - 1; i >= 0; i--) {\n char charAt = number.charAt(i);\n if(charAt == '1') {\n res += accCount;\n }\n accCount = accCount * 2;\n if(accCount > MODULO) {\n accCount = accCount % MODULO;\n }\n if(res > MODULO) {\n res = res % MODULO;\n }\n }\n return res;\n }\n \n private static long modularProduct(int n1, int n2) {\n long res = n1;\n for (int i = 1; i < n2; i++) {\n res += n1;\n if (res > Long.MAX_VALUE - n1) {\n res = res % MODULO;\n }\n }\n return res % MODULO;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ebe6bf2f35b5378c0bb286f20a745ad", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "\nimport java.util.Calendar;\nimport java.util.Scanner;\n\n/**\n *\n * @author Javi\n */\npublic class MalekDanceClub {\n\n private static final int MODULO = 1000000007;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String[] input = in.nextLine().split(\" \");\n String binaryEntry = input[0];\n\n int modPower = modularPower(binaryEntry.length());\n int modEntry = modularEntry(binaryEntry);\n long modProduct = modularProduct(modEntry, modPower);\n System.out.println(modProduct);\n\n // Binary number --> BigInteger\n // (BigInteger times 2^(n-1)) mod (10^(9)+7)\n\n in.close();\n }\n\n private static int modularPower(int n) {\n int res = 1;\n for (int i = 1; i < n; i++) {\n res = res * 2;\n if (res > MODULO) {\n res = res % MODULO;\n }\n }\n return res;\n }\n\n private static int modularEntry(String number) {\n int accCount = 1;\n int res = 0;\n for (int i = number.length() - 1; i >= 0; i--) {\n char charAt = number.charAt(i);\n if(charAt == '1') {\n res += accCount;\n }\n accCount = accCount * 2;\n if(accCount > MODULO) {\n accCount = accCount % MODULO;\n }\n if(res > MODULO) {\n res = res % MODULO;\n }\n }\n return res;\n }\n \n private static long modularProduct(int n1, int n2) {\n long res = n1;\n for (int i = 1; i < n2; i++) {\n res += n1;\n if (res > Long.MAX_VALUE - n1) {\n res = res % MODULO;\n }\n }\n return res % MODULO;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "271229b4a686af8578c436c9d1ba44bd", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n\n short [] arrTemp = new short[n];\n\n arrTemp[0] = in.nextShort();\n arrTemp[1] = in.nextShort();\n int progr = arrTemp[1] - arrTemp[0];\n int nextProgr = 0;\n boolean flagProgr = true;\n\n for (int i = 2; i < n; i++){\n arrTemp[i] = in.nextShort();\n\n nextProgr = arrTemp[i] - arrTemp[i-1];\n if(nextProgr != progr) \n flagProgr = false;\n \n progr = nextProgr;\n }\n\n System.out.print(flagProgr ? arrTemp[n-1] + progr : arrTemp[n-1]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ebaf3f36aa62b21e4cf80e12f9dbb980", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "qpackage javaapplication51;\nimport java.util.*;\npublic class CodeForcess {\n\n public static void main(String[] args) {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n \n int []aa=new int[n];\n for(int i=0;i 0) {\n\t\t\t\t\tprice += mm;\n\t\t\t\t}\n\t\t\t\tif (mm2 > 0) {\n\t\t\t\t\tprice += mm2;\n\n\t\t\t\t}\n\t\t\t\tif (mm3 > 0) {\n\t\t\t\t\tprice += mm3;\n\t\t\t\t}\n\n\t\t\t\tif (0<=price && price <= r ) {\n\t\t\t\t val=mid;\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\thi = mid - 1;\n\t\t\t\t}\n\n\t\t\tprice=0;\n\n\t\t\t\n\t\t}\n\t\t// System.out.println(val);\n\n\t\tSystem.out.println(val);\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc49eaaf3855776a1cbbdfe11a1588a4", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class b96 {\n\tpublic static Scanner scn = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tlong numb = 0;\n\t\tlong nums = 0;\n\t\tlong numc = 0;\n\t\tString str = scn.next();\n\n\t\tfor (int i = 0; i < str.length(); i++) {\n\t\t\tif (str.charAt(i) == 'B') {\n\t\t\t\tnumb++;\n\t\t\t}\n\t\t\tif (str.charAt(i) == 'S') {\n\t\t\t\tnums++;\n\t\t\t}\n\t\t\tif (str.charAt(i) == 'C') {\n\t\t\t\tnumc++;\n\t\t\t}\n\t\t}\n\n\t\tlong b = 0, s = 0, c = 0;\n\t\t// for (int i = 0; i < 3; i++) {\n\t\tb = scn.nextInt();\n\t\ts = scn.nextInt();\n\t\tc = scn.nextInt();\n\n\t\t// }\n\t\tlong pb = 0, ps = 0, pc = 0;\n\n\t\tpb = scn.nextInt();\n\t\tps = scn.nextInt();\n\t\tpc = scn.nextInt();\n\t\t// }\n\n\t\tlong r = scn.nextLong();\n\t\tint count = 0;\n\n\t\tint a = 0;\n\n\t\tlong long lo = 1;\n\t\tlong long hi = 9223372036854775807;\n\t\tlong long val = 0;\n\t\tlong long mid = 0;\n\n\t\tint price = 0;\n\t\tint d = 0;\n\t\twhile (lo <=hi) {\n\t\t\tmid = (lo + hi) / 2;\n\n\t\t\tlong mm = ((mid * numb) - b) * pb;\n\t\t\tlong mm2 = ((mid * nums) - s) * ps;\n\t\t\tlong mm3 = ((mid * numc) - c) * pc;\n\t\t\n\t\t\t\tif (mm > 0) {\n\t\t\t\t\tprice += mm;\n\t\t\t\t}\n\t\t\t\tif (mm2 > 0) {\n\t\t\t\t\tprice += mm2;\n\n\t\t\t\t}\n\t\t\t\tif (mm3 > 0) {\n\t\t\t\t\tprice += mm3;\n\t\t\t\t}\n\n\t\t\t\tif (0<=price && price <= r ) {\n\t\t\t\t val=mid;\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\thi = mid - 1;\n\t\t\t\t}\n\n\t\t\tprice=0;\n\n\t\t\t\n\t\t}\n\t\t// System.out.println(val);\n\n\t\tSystem.out.println(val);\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d4c4ddf3e944cdab382ff3ec018ee032", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class CHamburgers {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String rec = in.nextLine();\n int nb,ns,nc;\n nb = in.nextInt();\n ns = in.nextInt();\n nc = in.nextInt();\n byte pb,ps,pc;\n pb = in.nextInt();\n ps = in.nextInt();\n pc = in.nextInt();\n long r = in.nextLong();\n int[] needs = new int[3];\n\n for(int i=0; ir) {\n end=middle-1;\n } else if(Math.max(0,needs[0]*middle-nb)*pb+Math.max(0,needs[1]*middle-ns)*ps+Math.max(0,needs[2]*middle-nc)*pc 0) {\n\t\t\t\t\tprice += mm;\n\t\t\t\t}\n\t\t\t\tif (mm2 > 0) {\n\t\t\t\t\tprice += mm2;\n\n\t\t\t\t}\n\t\t\t\tif (mm3 > 0) {\n\t\t\t\t\tprice += mm3;\n\t\t\t\t}\n\n\t\t\t\tif (0<=price && price <= r ) {\n\t\t\t\t val=mid;\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t} else {\n\t\t\t\t\thi = mid - 1;\n\t\t\t\t}\n\n\t\t\tprice=0;\n\n\t\t\t\n\t\t}\n\t\t// System.out.println(val);\n\n\t\tSystem.out.println(val);\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8234eb0387e5e3f49247b00e7141b5e3", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.AbstractMap;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.NoSuchElementException;\nimport java.util.Set;\nimport java.util.SortedMap;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.function.BiConsumer;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\n\npublic class B_special8\n{\n\tpublic static final long[] POWER2 = generatePOWER2();\n\tpublic static final IteratorBuffer ITERATOR_BUFFER_PRIME = new IteratorBuffer<>(streamPrime(1000000).iterator());\n\tprivate static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static StringTokenizer stringTokenizer = null;\n\tprivate static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tinterface BiFunctionResult\n\t{\n\t\tTypeResult apply(Type0 x0, Type1 x1, TypeResult x2);\n\t}\n\n\tstatic class Array implements Iterable\n\t{\n\t\tprivate final Object[] array;\n\n\t\tpublic Array(int size)\n\t\t{\n\t\t\tthis.array = new Object[size];\n\t\t}\n\n\t\tpublic Array(int size, Type element)\n\t\t{\n\t\t\tthis(size);\n\t\t\tArrays.fill(this.array, element);\n\t\t}\n\n\t\tpublic Array(Array array, Type element)\n\t\t{\n\t\t\tthis(array.size() + 1);\n\t\t\tfor (int index = 0; index < array.size(); index++)\n\t\t\t{\n\t\t\t\tset(index, array.get(index));\n\t\t\t}\n\t\t\tset(size() - 1, element);\n\t\t}\n\n\t\tpublic Array(List list)\n\t\t{\n\t\t\tthis(list.size());\n\t\t\tint index = 0;\n\t\t\tfor (Type element : list)\n\t\t\t{\n\t\t\t\tset(index, element);\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic Type get(int index)\n\t\t{\n\t\t\treturn (Type) this.array[index];\n\t\t}\n\n\t\tpublic Array set(int index, Type value)\n\t\t{\n\t\t\tthis.array[index] = value;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.array.length;\n\t\t}\n\n\t\tpublic List toList()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Type element : this)\n\t\t\t{\n\t\t\t\tresult.add(element);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tType result = Array.this.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"[\" + B_special8.toString(this, \", \") + \"]\";\n\t\t}\n\t}\n\n\tstatic class BIT\n\t{\n\t\tprivate static int lastBit(int index)\n\t\t{\n\t\t\treturn index & -index;\n\t\t}\n\n\t\tprivate final long[] tree;\n\n\t\tpublic BIT(int size)\n\t\t{\n\t\t\tthis.tree = new long[size];\n\t\t}\n\n\t\tpublic void add(int index, long delta)\n\t\t{\n\t\t\tindex += 1;\n\t\t\twhile (index <= this.tree.length)\n\t\t\t{\n\t\t\t\ttree[index - 1] += delta;\n\t\t\t\tindex += lastBit(index);\n\t\t\t}\n\t\t}\n\n\t\tprivate long prefix(int end)\n\t\t{\n\t\t\tlong result = 0;\n\t\t\twhile (end > 0)\n\t\t\t{\n\t\t\t\tresult += this.tree[end - 1];\n\t\t\t\tend -= lastBit(end);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.tree.length;\n\t\t}\n\n\t\tpublic long sum(int start, int end)\n\t\t{\n\t\t\treturn prefix(end) - prefix(start);\n\t\t}\n\t}\n\n\tstatic abstract class Edge, TypeEdge extends Edge>\n\t{\n\t\tpublic final TypeVertex vertex0;\n\t\tpublic final TypeVertex vertex1;\n\t\tpublic final boolean bidirectional;\n\n\t\tpublic Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tthis.vertex0 = vertex0;\n\t\t\tthis.vertex1 = vertex1;\n\t\t\tthis.bidirectional = bidirectional;\n\t\t\tthis.vertex0.edges.add(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.add(getThis());\n\t\t\t}\n\t\t}\n\n\t\tpublic TypeVertex other(Vertex vertex)\n\t\t{\n\t\t\tTypeVertex result;\n\t\t\tif (vertex0 == vertex)\n\t\t\t{\n\t\t\t\tresult = vertex1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = vertex0;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic abstract TypeEdge getThis();\n\n\t\tpublic void remove()\n\t\t{\n\t\t\tthis.vertex0.edges.remove(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.remove(getThis());\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.vertex0 + \"->\" + this.vertex1;\n\t\t}\n\t}\n\n\tpublic static class EdgeDefault>> extends Edge>\n\t{\n\t\tpublic EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Vertex, TypeEdge extends Edge> implements Comparable>\n\t{\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiConsumer functionPreVisit,\n\t\t\t\tBiConsumer functionInVisit,\n\t\t\t\tBiConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tTypeVertex vertexTo;\n\t\t\tTypeEdge edgeTo;\n\t\t\tboolean[] isOnStack = new boolean[vertices.size()];\n\t\t\tStack stackOperations = new Stack<>();\n\t\t\tStack stackVertices = new Stack<>();\n\t\t\tStack stackEdges = new Stack<>();\n\n\t\t\tTypeVertex vertexStart = vertices.get(indexVertexStart);\n\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\tstackVertices.push(vertexStart);\n\t\t\tstackEdges.push(null);\n\t\t\tisOnStack[vertexStart.index] = true;\n\t\t\twhile (!stackOperations.isEmpty())\n\t\t\t{\n\t\t\t\tOperation operation = stackOperations.pop();\n\t\t\t\tTypeVertex vertex = stackVertices.pop();\n\t\t\t\tTypeEdge edge = stackEdges.pop();\n\t\t\t\tswitch (operation)\n\t\t\t\t{\n\t\t\t\t\tcase INVISIT:\n\t\t\t\t\t\tfunctionInVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase POSTVISIT:\n\t\t\t\t\t\tfunctionPostVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase EXPAND:\n\t\t\t\t\t\tstackOperations.push(Operation.POSTVISIT);\n\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\tInteger indexTo = null;\n\t\t\t\t\t\tfor (int index = 0; indexTo == null && index < vertex.edges.size(); index++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tindexTo = index;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (indexTo != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(indexTo);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\tfor (int index = indexTo + 1; index < vertex.edges.size(); index++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.INVISIT);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfunctionPreVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tConsumer functionPreVisit,\n\t\t\t\tConsumer functionInVisit,\n\t\t\t\tConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tdepthFirstSearch(\n\t\t\t\t\tvertices,\n\t\t\t\t\tindexVertexStart,\n\t\t\t\t\t(vertex, edge) -> functionPreVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionInVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionPostVisit.accept(vertex)\n\t\t\t);\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tTypeVertex vertex,\n\t\t\t\tTypeEdge edge,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tArray visited,\n\t\t\t\tFIFO verticesNext,\n\t\t\t\tFIFO edgesNext,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tif (!visited.get(vertex.index))\n\t\t\t{\n\t\t\t\tvisited.set(vertex.index, true);\n\t\t\t\tresult = function.apply(vertex, edge, result);\n\t\t\t\tfor (TypeEdge edgeNext : vertex.edges)\n\t\t\t\t{\n\t\t\t\t\tTypeVertex vertexNext = edgeNext.other(vertex);\n\t\t\t\t\tif (!visited.get(vertexNext.index))\n\t\t\t\t\t{\n\t\t\t\t\t\tverticesNext.push(vertexNext);\n\t\t\t\t\t\tedgesNext.push(edgeNext);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tArray visited = new Array<>(vertices.size(), false);\n\t\t\tFIFO verticesNext = new FIFO<>();\n\t\t\tverticesNext.push(vertices.get(indexVertexStart));\n\t\t\tFIFO edgesNext = new FIFO<>();\n\t\t\tedgesNext.push(null);\n\t\t\twhile (!verticesNext.isEmpty())\n\t\t\t{\n\t\t\t\tresult = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic final int index;\n\t\tpublic final List edges;\n\n\t\tpublic Vertex(int index)\n\t\t{\n\t\t\tthis.index = index;\n\t\t\tthis.edges = new ArrayList<>();\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Vertex that)\n\t\t{\n\t\t\treturn Integer.compare(this.index, that.index);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"\" + this.index;\n\t\t}\n\n\t\tenum Operation\n\t\t{\n\t\t\tINVISIT, POSTVISIT, EXPAND\n\t\t}\n\t}\n\n\tpublic static class VertexDefault, TypeEdge>> extends Vertex, TypeEdge>\n\t{\n\t\tpublic VertexDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class VertexDefaultDefault extends Vertex\n\t{\n\t\tpublic static Array vertices(int n)\n\t\t{\n\t\t\tArray result = new Array<>(n);\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult.set(index, new VertexDefaultDefault(index));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic VertexDefaultDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class EdgeDefaultDefault extends Edge\n\t{\n\t\tpublic EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefaultDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Tuple2\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\n\t\tpublic Tuple2(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \")\";\n\t\t}\n\t}\n\n\tstatic class Wrapper\n\t{\n\t\tpublic Type value;\n\n\t\tpublic Wrapper(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\tpublic Type get()\n\t\t{\n\t\t\treturn this.value;\n\t\t}\n\n\t\tpublic void set(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.value.toString();\n\t\t}\n\t}\n\n\tpublic static class Tuple3\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\t\tpublic final Type2 v2;\n\n\t\tpublic Tuple3(Type0 v0, Type1 v1, Type2 v2)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t\tthis.v2 = v2;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \", \" + this.v2 + \")\";\n\t\t}\n\t}\n\n\tpublic static class Tuple2Comparable, Type1 extends Comparable> extends Tuple2 implements Comparable>\n\t{\n\t\tpublic Tuple2Comparable(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tsuper(v0, v1);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Tuple2Comparable that)\n\t\t{\n\t\t\tint result = this.v0.compareTo(that.v0);\n\t\t\tif (result == 0)\n\t\t\t{\n\t\t\t\tresult = this.v1.compareTo(that.v1);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tpublic static class SingleLinkedList\n\t{\n\t\tpublic final Type element;\n\t\tpublic SingleLinkedList next;\n\n\t\tpublic SingleLinkedList(Type element, SingleLinkedList next)\n\t\t{\n\t\t\tthis.element = element;\n\t\t\tthis.next = next;\n\t\t}\n\n\t\tpublic void toCollection(Collection collection)\n\t\t{\n\t\t\tif (this.next != null)\n\t\t\t{\n\t\t\t\tthis.next.toCollection(collection);\n\t\t\t}\n\t\t\tcollection.add(this.element);\n\t\t}\n\t}\n\n\tpublic static class Node\n\t{\n\t\tpublic static Node balance(Node result)\n\t\t{\n\t\t\twhile (result != null && 1 < Math.abs(height(result.left) - height(result.right)))\n\t\t\t{\n\t\t\t\tif (height(result.left) < height(result.right))\n\t\t\t\t{\n\t\t\t\t\tNode right = result.right;\n\t\t\t\t\tif (height(right.right) < height(right.left))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, result.left, right.rotateRight());\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateLeft();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tNode left = result.left;\n\t\t\t\t\tif (height(left.left) < height(left.right))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, left.rotateLeft(), result.right);\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateRight();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node clone(Node result)\n\t\t{\n\t\t\tif (result != null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(result.value, clone(result.left), clone(result.right));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node delete(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tif (node.left == null)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = node.right;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (node.right == null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult = node.left;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tNode first = first(node.right);\n\t\t\t\t\t\t\tresult = new Node<>(first.value, node.left, delete(node.right, first.value, comparator));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, delete(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, delete(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node first(Node result)\n\t\t{\n\t\t\twhile (result.left != null)\n\t\t\t{\n\t\t\t\tresult = result.left;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node get(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node head(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node.left;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = head(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, head(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int height(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.height;\n\t\t}\n\n\t\tpublic static Node insert(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(value, null, null);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(value, node.left, node.right);\n\t\t\t\t\t;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, insert(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, insert(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node last(Node result)\n\t\t{\n\t\t\twhile (result.right != null)\n\t\t\t{\n\t\t\t\tresult = result.right;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int size(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.size;\n\t\t}\n\n\t\tpublic static Node tail(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(node.value, null, node.right);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, tail(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = tail(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static void traverseOrderIn(Node node, Consumer consumer)\n\t\t{\n\t\t\tif (node != null)\n\t\t\t{\n\t\t\t\ttraverseOrderIn(node.left, consumer);\n\t\t\t\tconsumer.accept(node.value);\n\t\t\t\ttraverseOrderIn(node.right, consumer);\n\t\t\t}\n\t\t}\n\n\t\tpublic final Type value;\n\t\tpublic final Node left;\n\t\tpublic final Node right;\n\t\tpublic final int size;\n\t\tprivate final int height;\n\n\t\tpublic Node(Type value, Node left, Node right)\n\t\t{\n\t\t\tthis.value = value;\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t\tthis.size = 1 + size(left) + size(right);\n\t\t\tthis.height = 1 + Math.max(height(left), height(right));\n\t\t}\n\n\t\tpublic Node rotateLeft()\n\t\t{\n\t\t\tNode left = new Node<>(this.value, this.left, this.right.left);\n\t\t\treturn new Node<>(this.right.value, left, this.right.right);\n\t\t}\n\n\t\tpublic Node rotateRight()\n\t\t{\n\t\t\tNode right = new Node<>(this.value, this.left.right, this.right);\n\t\t\treturn new Node<>(this.left.value, this.left.left, right);\n\t\t}\n\t}\n\n\tpublic static class SortedSetAVL implements SortedSet\n\t{\n\t\tpublic Comparator comparator;\n\t\tpublic Node root;\n\n\t\tprivate SortedSetAVL(Comparator comparator, Node root)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.root = root;\n\t\t}\n\n\t\tpublic SortedSetAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t}\n\n\t\tpublic SortedSetAVL(Collection collection, Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t\tthis.addAll(collection);\n\t\t}\n\n\t\tpublic SortedSetAVL(SortedSetAVL sortedSetAVL)\n\t\t{\n\t\t\tthis(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.root = null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\tpublic Type get(Type value)\n\t\t{\n\t\t\tNode node = Node.get(this.root, value, this.comparator);\n\t\t\treturn node == null ? null : node.value;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL subSet(Type valueStart, Type valueEnd)\n\t\t{\n\t\t\treturn tailSet(valueStart).headSet(valueEnd);\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL headSet(Type valueEnd)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL tailSet(Type valueStart)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic Type first()\n\t\t{\n\t\t\treturn Node.first(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic Type last()\n\t\t{\n\t\t\treturn Node.last(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.root == null ? 0 : this.root.size;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.root == null;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean contains(Object value)\n\t\t{\n\t\t\treturn Node.get(this.root, (Type) value, this.comparator) != null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\tStack> path = new Stack<>();\n\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\t{\n\t\t\t\t\tpush(SortedSetAVL.this.root);\n\t\t\t\t}\n\n\t\t\t\tpublic void push(Node node)\n\t\t\t\t{\n\t\t\t\t\twhile (node != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tpath.push(node);\n\t\t\t\t\t\tnode = node.left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn !path.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (path.isEmpty())\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tNode node = path.peek();\n\t\t\t\t\t\tType result = node.value;\n\t\t\t\t\t\tif (node.right != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpush(node.right);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tnode = path.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twhile (!path.isEmpty() && path.peek().right == node);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic Object[] toArray()\n\t\t{\n\t\t\tList list = new ArrayList<>();\n\t\t\tNode.traverseOrderIn(this.root, list::add);\n\t\t\treturn list.toArray();\n\t\t}\n\n\t\t@Override\n\t\tpublic T[] toArray(T[] ts)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean add(Type value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.insert(this.root, value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean remove(Object value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.delete(this.root, (Type) value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.allMatch(this::contains);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean addAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::add)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean retainAll(Collection collection)\n\t\t{\n\t\t\tSortedSetAVL set = new SortedSetAVL<>(this.comparator);\n\t\t\tcollection.stream()\n\t\t\t\t\t.map(element -> (Type) element)\n\t\t\t\t\t.filter(this::contains)\n\t\t\t\t\t.forEach(set::add);\n\t\t\tboolean result = size() != set.size();\n\t\t\tthis.root = set.root;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean removeAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::remove)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"{\" + B_special8.toString(this, \", \") + \"}\";\n\t\t}\n\t}\n\n\tpublic static class SortedMapAVL implements SortedMap\n\t{\n\t\tpublic final Comparator comparator;\n\t\tpublic final SortedSetAVL> entrySet;\n\n\t\tpublic SortedMapAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey())));\n\t\t}\n\n\t\tprivate SortedMapAVL(Comparator comparator, SortedSetAVL> entrySet)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.entrySet = entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(TypeKey keyStart, TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)));\n\t\t}\n\n\t\tpublic Entry firstEntry()\n\t\t{\n\t\t\treturn this.entrySet.first();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey firstKey()\n\t\t{\n\t\t\treturn firstEntry().getKey();\n\t\t}\n\n\t\tpublic Entry lastEntry()\n\t\t{\n\t\t\treturn this.entrySet.last();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey lastKey()\n\t\t{\n\t\t\treturn lastEntry().getKey();\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.entrySet().size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.entrySet.isEmpty();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsKey(Object key)\n\t\t{\n\t\t\treturn this.entrySet().contains(new AbstractMap.SimpleEntry<>((TypeKey) key, null));\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsValue(Object value)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue get(Object key)\n\t\t{\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tentry = this.entrySet.get(entry);\n\t\t\treturn entry == null ? null : entry.getValue();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue put(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>(key, value);\n\t\t\tthis.entrySet().add(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue remove(Object key)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tthis.entrySet.remove(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tmap.entrySet()\n\t\t\t\t\t.forEach(entry -> put(entry.getKey(), entry.getValue()));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.entrySet.clear();\n\t\t}\n\n\t\t@Override\n\t\tpublic Set keySet()\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Collection values()\n\t\t{\n\t\t\treturn new Collection()\n\t\t\t{\n\t\t\t\t@Override\n\t\t\t\tpublic int size()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean isEmpty()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean contains(Object value)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Iterator iterator()\n\t\t\t\t{\n\t\t\t\t\treturn new Iterator()\n\t\t\t\t\t{\n\t\t\t\t\t\tIterator> iterator = SortedMapAVL.this.entrySet.iterator();\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic boolean hasNext()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.hasNext();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic TypeValue next()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.next().getValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Object[] toArray()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic T[] toArray(T[] ts)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean add(TypeValue typeValue)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean remove(Object o)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean containsAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean addAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean removeAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean retainAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic void clear()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL> entrySet()\n\t\t{\n\t\t\treturn this.entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.entrySet().toString();\n\t\t}\n\t}\n\n\tpublic static class FIFO\n\t{\n\t\tpublic SingleLinkedList start;\n\t\tpublic SingleLinkedList end;\n\n\t\tpublic FIFO()\n\t\t{\n\t\t\tthis.start = null;\n\t\t\tthis.end = null;\n\t\t}\n\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.start == null;\n\t\t}\n\n\t\tpublic Type peek()\n\t\t{\n\t\t\treturn this.start.element;\n\t\t}\n\n\t\tpublic Type pop()\n\t\t{\n\t\t\tType result = this.start.element;\n\t\t\tthis.start = this.start.next;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic void push(Type element)\n\t\t{\n\t\t\tSingleLinkedList list = new SingleLinkedList<>(element, null);\n\t\t\tif (this.start == null)\n\t\t\t{\n\t\t\t\tthis.start = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthis.end.next = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class MapCount extends SortedMapAVL\n\t{\n\t\tprivate int count;\n\n\t\tpublic MapCount(Comparator comparator)\n\t\t{\n\t\t\tsuper(comparator);\n\t\t\tthis.count = 0;\n\t\t}\n\n\t\tpublic long add(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key);\n\t\t\t\tif (value == null)\n\t\t\t\t{\n\t\t\t\t\tvalue = delta;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvalue += delta;\n\t\t\t\t}\n\t\t\t\tput(key, value);\n\t\t\t\tresult = delta;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count += result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int count()\n\t\t{\n\t\t\treturn this.count;\n\t\t}\n\n\t\tpublic List flatten()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Entry entry : entrySet())\n\t\t\t{\n\t\t\t\tfor (long index = 0; index < entry.getValue(); index++)\n\t\t\t\t{\n\t\t\t\t\tresult.add(entry.getKey());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Long remove(Object key)\n\t\t{\n\t\t\tLong result = super.remove(key);\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic long remove(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key) - delta;\n\t\t\t\tif (value <= 0)\n\t\t\t\t{\n\t\t\t\t\tresult = delta + value;\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult = delta;\n\t\t\t\t\tput(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(Type keyStart, Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(Type keyStart)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\t}\n\n\tpublic static class MapSet extends SortedMapAVL> implements Iterable\n\t{\n\t\tprivate Comparator comparatorValue;\n\n\t\tpublic MapSet(Comparator comparatorKey, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic MapSet(Comparator comparatorKey, SortedSetAVL>> entrySet, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey, entrySet);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic TypeValue firstValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> firstEntry = firstEntry();\n\t\t\tif (firstEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = firstEntry.getValue().first();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tIterator> iteratorValues = values().iterator();\n\t\t\t\tIterator iteratorValue = null;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext());\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic TypeValue next()\n\t\t\t\t{\n\t\t\t\t\tif (iteratorValue == null || !iteratorValue.hasNext())\n\t\t\t\t\t{\n\t\t\t\t\t\titeratorValue = iteratorValues.next().iterator();\n\t\t\t\t\t}\n\t\t\t\t\treturn iteratorValue.next();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tpublic TypeValue lastValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> lastEntry = lastEntry();\n\t\t\tif (lastEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = lastEntry.getValue().last();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic boolean add(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tSortedSetAVL set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue));\n\t\t\treturn set.add(value);\n\t\t}\n\n\t\tpublic boolean removeSet(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tboolean result;\n\t\t\tSortedSetAVL set = get(key);\n\t\t\tif (set == null)\n\t\t\t{\n\t\t\t\tresult = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = set.remove(value);\n\t\t\t\tif (set.size() == 0)\n\t\t\t\t{\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue);\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue);\n\t\t}\n\t}\n\n\tstatic class IteratorBuffer\n\t{\n\t\tprivate Iterator iterator;\n\t\tprivate List list;\n\n\t\tpublic IteratorBuffer(Iterator iterator)\n\t\t{\n\t\t\tthis.iterator = iterator;\n\t\t\tthis.list = new ArrayList();\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < list.size() || iterator().hasNext();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (list.size() <= this.index)\n\t\t\t\t\t{\n\t\t\t\t\t\tlist.add(iterator.next());\n\t\t\t\t\t}\n\t\t\t\t\tType result = list.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t}\n\n\tpublic static List> permutations(List list)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tresult.add(new ArrayList<>());\n\t\tfor (Type element : list)\n\t\t{\n\t\t\tList> permutations = result;\n\t\t\tresult = new ArrayList<>();\n\t\t\tfor (List permutation : permutations)\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= permutation.size(); index++)\n\t\t\t\t{\n\t\t\t\t\tList permutationNew = new ArrayList<>(permutation);\n\t\t\t\t\tpermutationNew.add(index, element);\n\t\t\t\t\tresult.add(permutationNew);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static List> combinations(int n, int k)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tif (k == 0)\n\t\t{\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (k == 1)\n\t\t\t{\n\t\t\t\tList combination = new ArrayList<>();\n\t\t\t\tcombination.add(n);\n\t\t\t\tresult.add(combination);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= n; index++)\n\t\t\t\t{\n\t\t\t\t\tfor (List combination : combinations(n - index, k - 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tcombination.add(index);\n\t\t\t\t\t\tresult.add(combination);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterator iterator0, Iterator iterator1, Comparator comparator)\n\t{\n\t\tint result = 0;\n\t\twhile (result == 0 && iterator0.hasNext() && iterator1.hasNext())\n\t\t{\n\t\t\tresult = comparator.compare(iterator0.next(), iterator1.next());\n\t\t}\n\t\tif (result == 0)\n\t\t{\n\t\t\tif (iterator1.hasNext())\n\t\t\t{\n\t\t\t\tresult = -1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (iterator0.hasNext())\n\t\t\t\t{\n\t\t\t\t\tresult = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterable iterable0, Iterable iterable1, Comparator comparator)\n\t{\n\t\treturn compare(iterable0.iterator(), iterable1.iterator(), comparator);\n\t}\n\n\tprivate static String nextString() throws IOException\n\t{\n\t\twhile ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens()))\n\t\t{\n\t\t\tstringTokenizer = new StringTokenizer(bufferedReader.readLine());\n\t\t}\n\t\treturn stringTokenizer.nextToken();\n\t}\n\n\tprivate static String[] nextStrings(int n) throws IOException\n\t{\n\t\tString[] result = new String[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextString();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\n\tpublic static int[] nextInts(int n) throws IOException\n\t{\n\t\tint[] result = new int[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextInt();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n\n\tpublic static long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\n\tpublic static long[] nextLongs(int n) throws IOException\n\t{\n\t\tlong[] result = new long[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextLong();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String nextLine() throws IOException\n\t{\n\t\treturn bufferedReader.readLine();\n\t}\n\n\tpublic static void close()\n\t{\n\t\tout.close();\n\t}\n\n\tpublic static int binarySearchMinimum(Function filter, int start, int end)\n\t{\n\t\tint result;\n\t\tif (start == end)\n\t\t{\n\t\t\tresult = end;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint middle = start + (end - start) / 2;\n\t\t\tif (filter.apply(middle))\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, start, middle);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, middle + 1, end);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int binarySearchMaximum(Function filter, int start, int end)\n\t{\n\t\treturn -binarySearchMinimum(x -> filter.apply(-x), -end, -start);\n\t}\n\n\tpublic static long divideCeil(long x, long y)\n\t{\n\t\treturn (x + y - 1) / y;\n\t}\n\n\tpublic static Set divisors(long n)\n\t{\n\t\tSortedSetAVL result = new SortedSetAVL<>(Comparator.naturalOrder());\n\t\tresult.add(1L);\n\t\tfor (Long factor : factors(n))\n\t\t{\n\t\t\tSortedSetAVL divisors = new SortedSetAVL<>(result);\n\t\t\tfor (Long divisor : result)\n\t\t\t{\n\t\t\t\tdivisors.add(divisor * factor);\n\t\t\t}\n\t\t\tresult = divisors;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long faculty(int n)\n\t{\n\t\tlong result = 1;\n\t\tfor (int index = 2; index <= n; index++)\n\t\t{\n\t\t\tresult *= index;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static LinkedList factors(long n)\n\t{\n\t\tLinkedList result = new LinkedList<>();\n\t\tIterator primes = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile (n > 1 && (prime = primes.next()) * prime <= n)\n\t\t{\n\t\t\twhile (n % prime == 0)\n\t\t\t{\n\t\t\t\tresult.add(prime);\n\t\t\t\tn /= prime;\n\t\t\t}\n\t\t}\n\t\tif (n > 1)\n\t\t{\n\t\t\tresult.add(n);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long gcd(long a, long b)\n\t{\n\t\twhile (a != 0 && b != 0)\n\t\t{\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tb %= a;\n\t\t\t}\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tpublic static long[] generatePOWER2()\n\t{\n\t\tlong[] result = new long[63];\n\t\tfor (int x = 0; x < result.length; x++)\n\t\t{\n\t\t\tresult[x] = 1L << x;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean isPrime(long x)\n\t{\n\t\tboolean result = x > 1;\n\t\tIterator iterator = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile ((prime = iterator.next()) * prime <= x)\n\t\t{\n\t\t\tresult &= x % prime > 0;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long knapsack(List> itemsValueWeightCount, int weightMaximum)\n\t{\n\t\tlong[] valuesMaximum = new long[weightMaximum + 1];\n\t\tfor (Tuple3 itemValueWeightCount : itemsValueWeightCount)\n\t\t{\n\t\t\tlong itemValue = itemValueWeightCount.v0;\n\t\t\tint itemWeight = itemValueWeightCount.v1;\n\t\t\tint itemCount = itemValueWeightCount.v2;\n\t\t\tfor (int weight = weightMaximum; 0 <= weight; weight--)\n\t\t\t{\n\t\t\t\tfor (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++)\n\t\t\t\t{\n\t\t\t\t\tvaluesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong result = 0;\n\t\tfor (long valueMaximum : valuesMaximum)\n\t\t{\n\t\t\tresult = Math.max(result, valueMaximum);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean knapsackPossible(List> itemsWeightCount, int weightMaximum)\n\t{\n\t\tboolean[] weightPossible = new boolean[weightMaximum + 1];\n\t\tweightPossible[0] = true;\n\t\tint weightLargest = 0;\n\t\tfor (Tuple2 itemWeightCount : itemsWeightCount)\n\t\t{\n\t\t\tint itemWeight = itemWeightCount.v0;\n\t\t\tint itemCount = itemWeightCount.v1;\n\t\t\tfor (int weightStart = 0; weightStart < itemWeight; weightStart++)\n\t\t\t{\n\t\t\t\tint count = 0;\n\t\t\t\tfor (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight)\n\t\t\t\t{\n\t\t\t\t\tif (weightPossible[weight])\n\t\t\t\t\t{\n\t\t\t\t\t\tcount = itemCount;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (0 < count)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tweightPossible[weight] = true;\n\t\t\t\t\t\t\tweightLargest = weight;\n\t\t\t\t\t\t\tcount -= 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn weightPossible[weightMaximum];\n\t}\n\n\tpublic static long lcm(int a, int b)\n\t{\n\t\treturn a * b / gcd(a, b);\n\t}\n\n\tpublic static List permutation(long p, List x)\n\t{\n\t\tList copy = new ArrayList<>();\n\t\tfor (int index = 0; index < x.size(); index++)\n\t\t{\n\t\t\tcopy.add(x.get(index));\n\t\t}\n\t\tList result = new ArrayList<>();\n\t\tfor (int indexTo = 0; indexTo < x.size(); indexTo++)\n\t\t{\n\t\t\tint indexFrom = (int) p % copy.size();\n\t\t\tp = p / copy.size();\n\t\t\tresult.add(copy.remove(indexFrom));\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String toString(Iterator iterator, String separator)\n\t{\n\t\tStringBuilder stringBuilder = new StringBuilder();\n\t\tif (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\twhile (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(separator);\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\treturn stringBuilder.toString();\n\t}\n\n\tpublic static String toString(Iterator iterator)\n\t{\n\t\treturn toString(iterator, \" \");\n\t}\n\n\tpublic static String toString(Iterable iterable, String separator)\n\t{\n\t\treturn toString(iterable.iterator(), separator);\n\t}\n\n\tpublic static String toString(Iterable iterable)\n\t{\n\t\treturn toString(iterable, \" \");\n\t}\n\n\tpublic static Stream streamFibonacci()\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate BigInteger n0 = BigInteger.ZERO;\n\t\t\tprivate BigInteger n1 = BigInteger.ONE;\n\n\t\t\t@Override\n\t\t\tpublic BigInteger get()\n\t\t\t{\n\t\t\t\tBigInteger result = n0;\n\t\t\t\tn0 = n1;\n\t\t\t\tn1 = result.add(n0);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static Stream streamPrime(int sieveSize)\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate boolean[] isPrime = new boolean[sieveSize];\n\t\t\tprivate long sieveOffset = 2;\n\t\t\tprivate List primes = new ArrayList<>();\n\t\t\tprivate int index = 0;\n\n\t\t\tpublic void filter(long prime, boolean[] result)\n\t\t\t{\n\t\t\t\tif (prime * prime < this.sieveOffset + sieveSize)\n\t\t\t\t{\n\t\t\t\t\tlong remainingStart = this.sieveOffset % prime;\n\t\t\t\t\tlong start = remainingStart == 0 ? 0 : prime - remainingStart;\n\t\t\t\t\tfor (long index = start; index < sieveSize; index += prime)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult[(int) index] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void generatePrimes()\n\t\t\t{\n\t\t\t\tArrays.fill(this.isPrime, true);\n\t\t\t\tthis.primes.forEach(prime -> filter(prime, isPrime));\n\t\t\t\tfor (int index = 0; index < sieveSize; index++)\n\t\t\t\t{\n\t\t\t\t\tif (isPrime[index])\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.primes.add(this.sieveOffset + index);\n\t\t\t\t\t\tfilter(this.sieveOffset + index, isPrime);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.sieveOffset += sieveSize;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic Long get()\n\t\t\t{\n\t\t\t\twhile (this.primes.size() <= this.index)\n\t\t\t\t{\n\t\t\t\t\tgeneratePrimes();\n\t\t\t\t}\n\t\t\t\tLong result = this.primes.get(this.index);\n\t\t\t\tthis.index += 1;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static long totient(long n)\n\t{\n\t\tSet factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder());\n\t\tlong result = n;\n\t\tfor (long p : factors)\n\t\t{\n\t\t\tresult -= result / p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tsolve();\n\t\t} catch (IOException exception)\n\t\t{\n\t\t\texception.printStackTrace();\n\t\t}\n\t\tclose();\n\t}\n\n\tpublic static int solveSmallestSubtasks(int n, int k, int M, int[] ts)\n\t{\n\t\tint result = 0;\n\t\tfor (int t : ts)\n\t\t{\n\t\t\tint solve = Math.min(n, M / t);\n\t\t\tresult += solve;\n\t\t\tM -= solve * t;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int solve(int n, int k, int M, int[] ts, int sum)\n\t{\n\t\tint result = solveSmallestSubtasks(n, k, M, ts);\n\t\tif (sum <= M)\n\t\t{\n\t\t\tresult = Math.max(result, k + 1 + solve(n - 1, k, M - sum, ts, sum));\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void solve() throws IOException\n\t{\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint M = nextInt();\n\t\tint[] ts = nextInts(k);\n\t\tArrays.sort(ts);\n\t\tint sum = 0;\n\t\tfor (int t : ts)\n\t\t{\n\t\t\tsum += t;\n\t\t}\n\t\tout.println(solve(n, k, M, ts, sum));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9078cbc662271a7d91177802a1a71cb", "src_uid": "d659e92a410c1bc836be64fc1c0db160", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Aa {\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint k = s.nextInt();\n\t\tlong m = s.nextLong();\n\t\tint[] cost = new int[k];\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tcost[i] = s.nextInt();\n\t\t}\n\t\tquickSort(cost, 0, cost.length - 1);\n\t\tSystem.out.println(computePoint(cost, m, 0, n - 1));\n\t}\n\n\n\tprivate static int computePoint(int[] cost, long m, int levelNum, int lastNum) {\n\t\tint[] increasPoint = new int[Math.max(cost.length,lastNum) + 1];\n\t\tif (levelNum < cost.length) {\n\t\t\tfor (int i = 0; i <= lastNum; i++) {\n\t\t\t\tif (m >= cost[levelNum]) {\n\t\t\t\t\tm -= cost[levelNum];\n\t\t\t\t\tif (levelNum == (cost.length - 1)) {\n\t\t\t\t\t\tincreasPoint[increasPoint.length - 1] = 2*(i + 1);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tincreasPoint[i] = increasPoint[i] + computePoint(cost, m, levelNum + 1, i) + i + 1;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\treturn findMax(increasPoint);\n\t}\n\n\tprivate static int findMax(int[] increasPoint) {\n\t\tint length = increasPoint.length;\n\t\tint max = 0;\n\t\tif(length >= 1){\n\t\t\tmax = increasPoint[0];\n\t\t\tfor (int i = 0; i < length; i++) {\n\t\t\t\tif(max < increasPoint[i]){\n\t\t\t\t\tmax = increasPoint[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\t\n\t\t}\n\t\treturn max;\n\t}\n\n\n\tpublic static void quickSort(int[] arr, int low, int high) {\n\t\tif (arr == null || arr.length == 0)\n\t\t\treturn;\n\n\t\tif (low >= high)\n\t\t\treturn;\n\n\t\t// pick the pivot\n\t\tint middle = low + (high - low) / 2;\n\t\tint pivot = arr[middle];\n\n\t\t// make left < pivot and right > pivot\n\t\tint i = low, j = high;\n\t\twhile (i <= j) {\n\t\t\twhile (arr[i] < pivot) {\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\twhile (arr[j] > pivot) {\n\t\t\t\tj--;\n\t\t\t}\n\n\t\t\tif (i <= j) {\n\t\t\t\tint temp = arr[i];\n\t\t\t\tarr[i] = arr[j];\n\t\t\t\tarr[j] = temp;\n\t\t\t\ti++;\n\t\t\t\tj--;\n\t\t\t}\n\t\t}\n\n\t\t// recursively sort two sub parts\n\t\tif (low < j)\n\t\t\tquickSort(arr, low, j);\n\n\t\tif (high > i)\n\t\t\tquickSort(arr, i, high);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "92fbedf2c48828205751e0e073a27331", "src_uid": "d659e92a410c1bc836be64fc1c0db160", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class B846 {\n\tpublic static void main(String args[])throws Exception{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\tlong M = Integer.parseInt(st.nextToken());\n\t\tint a[] = new int[k];\n\t\tlong sum =0, result =0;\n\t\tst = new StringTokenizer(br.readLine());\n\t\tfor(int i=0; i= a[i]) {\n\t\t\t\tif(M1 <= temp) {\n\t\t\t\t\tresult1 += M1/a[i];\n\t\t\t\t\tM1-=a[i]*(M1/a[i]);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresult1 += n;\n\t\t\t\t\tM1-=a[i]*n;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong tasks = M/sum;\n\t\tresult = tasks * (k+1);\n\t\tM%=sum;\n\t\tfor(int i=0; i= a[i] && M <= temp) {\n\t\t\t\tresult += M/a[i];\n\t\t\t\tM-=a[i]*(M/a[i]);\n\t\t\t}\n\t\t\tif(M >= a[i] && M > temp) {\n\t\t\t\tresult += n-tasks;\n\t\t\t\tM-=a[i]*n-tasks;\n\t\t\t}\n\t\t}\n\t\tout.println(Math.max(result1, Math.min(result, n*(k+1))));\n\t\tout.flush();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "20386b8bc9f967d30960110d0e211f86", "src_uid": "d659e92a410c1bc836be64fc1c0db160", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class CF846BMathShow {\n\n public static void main(String[] args) {\n File input = new File(\"codeforce\\\\CF846Binput.txt\");\n Scanner in = null;\n try {\n in = new Scanner(input);\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n\n// Scanner in = new Scanner(System.in);\n\n int n = in.nextInt();\n int k = in.nextInt();\n int m = in.nextInt();\n in.nextLine();\n int[] subtaskTimes = new int[k];\n for (int i = 0; i < k; i++) {\n subtaskTimes[i] = in.nextInt();\n }\n\n int score = smallestSubtaskUp(n, k, m, subtaskTimes);\n\n System.out.println(score);\n\n }\n\n private static int smallestSubtaskUp(int n, int k, int m, int[] subtaskTimes) {\n int timeUsed = 0;\n int score = 0;\n\n outerloop:\n for (int subtask = 0; subtask < k; subtask++) {\n\n for (int task = 0; task < n; task++) {\n timeUsed += subtaskTimes[subtask];\n if (timeUsed > m) {\n break outerloop;\n }\n score++;\n if (subtask == k-1)\n score++;\n }\n }\n\n return score;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c7bdb8c87666633be5cdbfd44a9f1d07", "src_uid": "d659e92a410c1bc836be64fc1c0db160", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\npublic class Mai\r\n{\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner sc=new Scanner(System.in);\r\n\t\tString s=sc.next();\r\n\t\tchar a[]=new char[26];\r\n\t\tint iii=0;\r\n\t\tfor(char al='A';al<='Z';al++){\r\n\t\t a[iii]=al;\r\n\t\t iii++;\r\n\t\t}\r\n\t\tint len=s.length();\r\n\t\tboolean f=true;\r\n\t\tint pos1=0,pos2=0,pos3=0;\r\n\t\tfor(int i=0;i 20000 || total < 0) {\n System.out.println(\"NO\");\n System.exit(0);\n }\n\n // If we reach a pole (after the first movement, then update last)\n if (total % 20000 == 0) {\n last = 1 - last; // change state\n }\n\n }\n if (total != 0) {\n System.out.println(\"NO\");\n }\n else {\n // If passed everything, then yes!\n System.out.println(\"YES\");\n }\n }\n\n static class Scanner {\n BufferedReader br;\n StringTokenizer st;\n\n Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n Scanner(FileReader s) {\n br = new BufferedReader(s);\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ccf84ef712bd8d75b78968e314aab7f8", "src_uid": "11ac96a9daa97ae1900f123be921e517", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class a{\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int num = scan.nextInt()%6;\n int num2 = scan.nextInt();\n int[] array = new int[3];\n \n for (int i = 0; i < 3; ++i) array[i] = i;\n for (int i = 1; i <= n; ++i) {\n int temp = array[1];\n array[1] = array[2-2*(i)];\n array[2-2*i] = temp;\n }\n System.out.println(array[num2]);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b83e293f18c28bc19d6123c654dee06e", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class shell\n{\n public static void main(String args[])\n {\n bufferedReader br=new bufferedReader(new inputStreamReader(System.in));\n int n=Integer.parseInt(br.readLine());\n int x=Integer.parseInt(br.readLine());\n if(x<0||x>2)\n System.exit(0);\n int arr[]=new int[3];\n arr[x]=1;\n int temp=0;\n while(n!=0)\n {\n if(n%2==0)\n {\n temp=arr[1];\n arr[1]=arr[2];\n arr[2]=temp;\n }\n else\n {\n temp=arr[1];\n arr[1]=arr[0];\n arr[0]=temp; \n }\n n=n-1;\n }\n for(int i=0;i<3;i++)\n {\n if(arr[i]==1)\n System.out.println(i);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc1a2836cb6960f3f20287d68f19178e", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class Test {\n\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int current = sc.nextInt();\n\n if (n % 3 == 0) {\n System.out.println(current);\n } else {\n int rem = n%3;\n if (current - rem < 0) {\n System.out.println(3+(current-rem));\n } else {\n System.out.println(current-rem);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8eb3fe142d0602883b99df4d40a7253f", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class shell\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int x=sc.nextInt();\n int arr[]=new int[3];\n arr[x]=1;\n int temp=0;\n while(n!=0)\n {\n if(n%2==0)\n {\n temp=a[1];\n a[1]=a[2];\n a[2]=temp;\n }\n else\n {\n temp=a[1];\n a[1]=a[0];\n a[0]=temp; \n }\n n=n-1;\n }\n for(int i=0;i<3;i++)\n {\n if(arr[i]==1)\n System.out.println(i);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f5db65c89da369adff8c3c9f9597a27", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n private void solve() {\n int w = nextInt();\n int h = nextInt();\n int k = nextInt();\n int kol=0;\n for (int i = 0; i < k; i++) {\n kol += (w*2+h*2)-4;\n w-=4;\n h-=4\n }\n out.print();\n }\n public static void main(String[] args) {\n new Main().run();\n }\n\n BufferedReader br;\n StringTokenizer st;\n PrintWriter out;\n\n private void run() {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //br = new BufferedReader(new FileReader(\"birthday.in\"));\n //out = new PrintWriter(new FileWriter(\"birthday.out\"));\n solve();\n br.close();\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private int nextInt() {\n return Integer.parseInt(next());\n }\n\n private 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 \"END_OF_FILE\";\n }\n }\n return st.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "abf79f5bc72a069d7ffb25543d8779cc", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\n\nimport java.util.*;\n\npublic class Main{\n public static void main(String[] args) throws IOException {\n \n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n args = br.readLine().split(\" \");\n int w = Integer.parseInt(args[0]), h = Integer.parseInt(args[1]), k = Integer.parseInt(args[2]);\n \n System.out.println(numGLidedCells(w, h, k));\n }\n\n public static int numGlidedCells(int w, int h, int k) {\n int count = 0;\n\n for (int i = 1; i <= k; i++) {\n int wi = w - 4 * (i-1), hi = h - 4 * (i-1);\n count += 2 * (wi) + 2 * (hi - 2);\n }\n\n return count;\n }\n\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b27522aa206cb1e2cff98b04ae3eb815", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\npublic static void main(String args[]){\nScanner s=new Scanner(System.in);\nint n = s.nextInt();\nint m = s.nextInt();\nint k = s.nextInt();\nint ans = 0;\nwhile(n>0 && m>0){\nans+=n*2+m*2-4;\nn-=4;\nm-=4;\n}\nSystem.out.println(ans);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2e9a76a9e39b1629721c9a7011ff851c", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Sabado {\n\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int w = in.nextInt();\n int h = in.nextInt(); \n int k = in.nextInt();\n System.out.println((2*k)*((w+h)-4(*k+2));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "56b7c66296b46d90fa050f241b60cd3f", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class lol {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m=sc.nextInt();\n int h[] = new int[m];\n int l[] =new int[m];\n int g = 0,u=0,t,o=0,k,p=0;\n for (int i = 0; i < m*2; i++) { \n t=sc.nextInt(); \n \n if(i%2!=0){ \n if(i!=0){\n l[u]=t;\n u++; \n \n \n }\n }else{\n h[p]=t;\n p++;\n } \n }\n \n int y=0;\n \n for (int i = 0; i < l.length; i++) {\n \n for (int v = 0; v < l.length-1; v++) {\n if(l[y]0; j++) {\n o+=l[y];\n n--;\n }\n \n l[y]=0;\n \n if(n==0){\n i=900;\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f3c3a702f2e0707f20a602b973ceb1a", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\tpublic static void main(String [] args){\n\t\t\n\n Scanner in = new Scanner(System.in);\n \n int n = in.nextInt();\n int m = in.nextInt();\n \n int [] a = new int[m];\n int [] b = new int [m];\n int [] a1 = new int [m];\n int [] b1 = new int [m];\n \n for(int i=0 ; i= max){\n \t\t max = b[j];\n \t\t index = j; \t\t \n \t }//end if\n \t a1[i] = a[index];\n\t\t b1[i] = b[index];\n\t\t b[index] = 0;\n\t\t max = 0;\n }//end for\n \n /* for(int i=0 ; i= n){\n \t\t max += n * b1[i];\n \t\t break;\n \t }//end if\n \t else{\n \t\t max += a1[i] * b1[i];\n \t\t n -= a1[i];\n \t } //end else\n }//end for\n \n System.out.println(max);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f22265c839c43164dd2cd8e425fe468a", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\npublic class main{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int max = sc.nextInt();\n int c=0;\n Pair p[] = new Pair[sc.nextInt()];\n for(int i =0;i(sc.nextInt(),sc.nextInt());\n Comparator> x = (Pair p1,Pair p2)->{\n if(p1.getValue() < p2.getValue()) return 1;\n else if(p1.getValue() > p2.getValue()) return -1;\n else if(p1.getKey() > p2.getKey()) return -1;\n else if(p1.getKey() < p2.getKey()) return 1;\n else return 0;\n };\n Arrays.sort(p,x);\n for(int i=0;i0;i++){\n if(p[i].getKey()<=max)\n c+=p[i].getValue()*p[i].getKey();\n else c+=max*p[i].getValue();\n max-=p[i].getKey();\n }\n System.out.println(c);\n }\n static class Pair{\n K k;\n V v;\n public Pair(K k,V v) {this.k=k;this.v=v;}\n public V getValue() {return v;}\n public K getKey() {return k;}\n @Override\n public String toString(){\n return k+\" \"+v;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8d18e488cc6996d9b1dccdc5a606c9cb", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0} {"lang": "Java 8", "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 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) 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>graph, int edge1, int edge2)\n {\n graph.get(edge1).add(edge2);\n graph.get(edge2).add(edge1);\n }\n\n static class Pair\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 Pair 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 Compare\n {\n static void compare(List> pairs, int m)\n {\n pairs.sort(new Comparator>() {\n @Override\n public int compare(Pair p1, Pair 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 // try(BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)))\n {\n int n = fr.nextInt();\n String s = fr.nextLine();\n\n String s1 = \"\";\n\n if ((n&1) == 1)\n {\n for (int i=0;i=1)\n {\n if(fivedigitcount>=1 && sixdigitcount>=1)\n {\n sum=sum+256;\n twodigitcount--;\n fivedigitcount--;\n sixdigitcount--;\n }\n else if(twodigitcount>=1 && threedigitcount>=1)\n {\n twodigitcount--;\n threedigitcount--;\n }\n else\n {\n break;\n }\n }\n System.out.println(sum);\n \n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8413761d2d9b819b46df0943a86b9f65", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A{\n public static void main(String wsudhvgb[]){\n Scanner s=new Scanner(System.in);\n int a=s.nextInt();\n int b=s.nextInt();\n int c=s.nextInt();\n int d=s.nextInt();\n int s=0;\n c=Math.min(a,c,d);\n s+=c*256;\n a-=c;\n b=Math.min(a,b);\n s+=b*32;\n System.out.println(s);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "012581facd9236f9d303ca1316633e66", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class java\n{\n public static void main(String args[])\n {\n Scanner in=new Scanner(System.in);\n long n2,n3,n5,n6,i,s=0,a;\n n2=in.nextLong();\n n3=in.nextLong();\n n5=in.nextLong();\n n6=in.nextLong();\n while(i!=0)\n {\n if(n2==0 || n5==0 || n6==0)\n {\n i=0;\n break;\n }\n n2=n2-1;\n n5=n5-1;\n n6=n6-1;\n s=s+256;\n }\n while(a!=0)\n {\n if(n2==0 || n3==0)\n {\n a=0;\n break;\n }\n n3=n3-1;\n n2=n2-1;\n s=s+32;\n }\n System.out.println(s);\n }\n}\n\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "034cacf29f8d081f8b69452f5053609b", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*\npublic class main{\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in)\n int k2,k3,k5,k6;\n k2= scan.nextInt();\n k3= scan.nextInt();\n k3= scan.nextInt();\n k6= scan.nextInt();\n int u =Math.min(k2,k5,k6);\n int k;\n k=u*256;\n k2=k2-u;\n k5=k3-u;\n k6=k6-u;\n u=Math.min(k2,k3);\n k=k+u*32;\n System.out.println(k);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02e0ffd81bebc1bc4a85728abae82ff7", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0} {"lang": "Java 7", "source_code": "\nimport java.io.IOException;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n boolean[][] b = new boolean[3][3];\n for (int i = 0; i < b.length; i++) {\n String str = in.nextLine();\n for (int j = 0; j < str.length(); j++) {\n if (str.charAt(j) == 'X') {\n numberOfX++;\n b[i][j] = true;\n }\n }\n }\n boolean c = true;\n search:\n for (int i = 0; i < b.length; i++) {\n for (int j = 0; j < b[i].length; j++) {\n if (b[i][j]) {\n if (!b[2 - i][2 - j]) {\n c = false;\n break search;\n }\n }\n }\n }\n String output = (c) ? \"YES\" : \"NO\";\n System.out.println(output);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bdd7ceefafe5a4e69ea46c2380b35888", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Solution{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int[][] arr = new int[3][3];\n for(int i=0;i<3;i++)\n {\n \n \n arr[i] = sc.next().toCharArray();\n \n }\n if(arr[0][0] == arr[2][2] && arr[0][1] == arr[2][1] && arr[0][2] == arr[2][0] && arr[1][0] == arr[2][1])\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bcf61c70ebef31831077c8d0ae60bff5", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\n public static void main (String[] args)\n {\n Scanner a=new Scanner(System.in);\n char[][] b=new char[3][3];\n while(a.hasNextLine())\n {\n for(int i=0;i<3;i++)\n {\n b[i]=a.nextLine().toCharArray();\n if(test(lock))\n {\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n }\n }\n }\n static boolean test(char[][] a)\n {\n return ()&&()&&()&&()\n }\n}\n \t \t\t \t\t \t \t\t\t \t \t\t \t \t \t\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3186beac98f0172d7845310cd6b48a64", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\n public static void main (String[] args)\n {\n Scanner a=new Scanner(System.in);\n char[][] b=new char[3][3];\n while(a.hasNextLine())\n {\n for(int i=0;i<3;i++)\n {\n b[i]=a.nextLine().toCharArray();\n if(isyes(lock))\n {\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n }\n }\n }\n static boolean isyes(char[][] lock)\n {\n return (lock[0][0]==lock[2][2]) && (lock[0][1]==lock[2][1]) && (lock[0][2]==lock[2][0]) && (lock[1][0]==lock[1][2]);\n }\n}\n \t \t \t \t\t\t\t\t \t\t\t\t\t\t \t\t\t \t \t\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0cf08485fe8f10495d5596380d2c4bbc", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class LadderB {\n\n\tstatic Scanner scn = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\t magicSquare()\n\t}\n\n\n\npublic static void magicSquare(){\n\t\tint[][] arr = new int[3][3];\n\t\t\n\t\tfor(int i = 0; i<3;i++){\n\t\t\tfor(int j = 0; j<3;j++)\n\t\t\tarr[i][j] = scn.nextInt();\n\t\t}\n\t\t\n\t\tint zero = 0, one = 0, two = 0;\n\t\t\n\t\tfor(int i = 0; i<3;i++){\n\t\t\tfor(int j = 0; j<3;j++){\n\t\t\t\tif(j == 0){\n\t\t\t\t\tzero+=arr[i][j]; \n\t\t\t\t} else if(j == 1){\n\t\t\t\t\tone+=arr[i][j];\n\t\t\t\t}else{\n\t\t\t\t\ttwo+=arr[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tarr[0][0] = (two+one-zero)/2;\n\t\tarr[1][1] = (two+zero-one)/2;\n\t\tarr[2][2] = (one+zero-two)/2;\n\t\t\n\t\tfor(int i = 0 ;i<3;i++){\n\t\t\tfor(int j = 0; j<3;j++){\n\t\t\t\tSystem.out.print(arr[i][j]+\" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2856953ca854b518324769df6958f257", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class B {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int[][] magic = new int[3][3];\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n magic[i][j] = in.nextInt();\n }\n }\n for (int j = 0; j < 3; j++) {\n for (int i = 0; i < 3; i++) {\n if (magic[j][i] == 0) {\n magic[j][i] = 15 - (magic[j][0] + magic[j][1] + magic[j][2]);\n }\n }\n }\n\n for (int j = 0; j < 3; j++) {\n for (int i = 0; i < 3; i++) {\n if (magic[i][j] > 9) {\n magic[i][j] = 1;\n }\n }\n }\n\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n System.out.print(magic[i][j] + \"\\t\");\n }\n System.out.println();\n }\n\n\n }//main Method\n}//B Class\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b6932d71ba1ed8ce60b7d701139ca426", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class ahmed\n{\n public static void main(String args[])\n {\n Scanner scn = new Scanner(System.in);\n int a[] = new int[3];\n int b[] = new int[3];\n int c[] = new int[3];\n int i;\n for(i = 0;i < 3; ++i)\n {\n a[i] = scn.nextInt();\n }\n for(i = 0;i < 3; ++i)\n {\n b[i] = scn.nextInt();\n }\n for(i = 0;i < 3; ++i)\n {\n c[i] = scn.nextInt();\n }\n int a,b,c;\n b = a[2] - b[0];\n c = (a[1] + b[0]) / 2;\n a = (a[1] + b[0] - 2 * a[2]) / 2;\n a[0] = c - b;\n b[1] = c;\n c[2] = c + b;\n for(i = 0;i < 3; ++i)\n {\n System.out.print(a[i] + \" \");\n }\n System.out.println();\n for(i = 0;i < 3; ++i)\n {\n System.out.print(b[i] + \" \");\n }\n System.out.println();\n for(i = 0;i < 3; ++i)\n {\n System.out.print(c[i] + \" \");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8e2c917367a3307beedaf984f8091da", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage prueba;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\n/**\n *\n * @author USUARIO\n */\npublic class MagicSquare {\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 reader = new Scanner(System.in); // Create a Scanner object\n int square[][] = new int[3][3]; \n for (int i = 0; i < 3; i++) {\n String[] elemts = reader.nextLine().split(\" \");\n for(int j = 0; j < 3; j++){\n square[i][j] = Integer.parseInt(elemts[j]);\n }\n }\n int Rmin = 9999999;\n ArrayList aux = new ArrayList(); \n \n aux.add(square[0][1] + square[0][2]);\n aux.add(square[1][0] + square[1][2]);\n aux.add(square[2][0] + square[2][1]);\n aux.add(square[1][0] + square[2][0]);\n aux.add(square[0][1] + square[2][1]);\n aux.add(square[0][2] + square[1][2]);\n \n for(int elem : aux){\n if (elem < Rmin){\n Rmin = elem;\n }\n }\n \n for (int i = 1; i < 100001; i++) {\n int R = 2*i + square[0][1] + square[1][0] + square[0][2] + square[2][0];\n int y = (R -( square[0][1] + square[1][0] + square[2][1] + square[1][2]))/2;\n int z = (R -( square[2][1] + square[2][0] + square[0][2] + square[1][2]))/2;\n ArrayList equations = new ArrayList();\n equations.add(i + square[0][1] + square[0][2]);\n equations.add(square[1][0] + square[1][0] + y);\n equations.add(square[2][0] + square[2][1] + z);\n equations.add(square[1][0] + square[2][0] + i);\n equations.add(square[0][1] + square[2][1] + y);\n equations.add(square[0][2] + square[1][2] + z);\n equations.add(i + y + z);\n if(equations.stream().distinct().limit(2).count() == 1 && y > 0 && z > 0 ){\n System.out.println(i + \" \" + square[0][1] + \" \" + square[0][2]);\n System.out.println(square[1][0] + \" \" + y + \" \" +square[1][2]);\n System.out.println(square[2][0] + \" \" + square[2][1] + \" \" + z);\n return;\n }\n }\n \n }\n} \n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6693e7e6400c05081d81555d437c31bb", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class hiijif {\n\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n\n\n String s=sc.nextLine();\n String s=sc.nextLine();\n\n \n int sum1=0,sum2=0;\n boolean p=false;\n sc.close();\n for(int i=0; i hm;\n\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tStringBuilder sb = new StringBuilder();\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n =sc.nextInt() , m=sc.nextInt();\n\t\tchar x []=( m+\"\").toCharArray();\n\t\tint left=0;\n\t\tint right=0;\n\t\tboolean yes = true;\n\t\tfor (int i = 0; i < n/2; i++) {\n\t\t\tif((x[i]!='7' &&x[i]!='4')||(x[n-i-1]!='7'&&x[n-i-1]!='4')){yes=false;break;}\n\t\t\tleft+=Integer.parseInt(x[i]+\"\");\n\t\t\tright+=Integer.parseInt(x[n-i-1]+\"\");\n\t\t}\n\t\tif(!yes){out.print(\"NO\");out.flush();out.close();}\n\t\telse if(left==right){out.print(\"YES\");out.flush();out.close();}\n\t\telse {out.print(\"NO\");out.flush();out.close();}\n\t}\n\nclass Pair \n{\n\tchar x ; int y ;\n\tPair(char a , int b)\n\t{\n\t\tx=a;y=b;\n\t}\n\t\n}\n\n class Scanner \n{\n\tStringTokenizer st;\n\tBufferedReader br;\n\n\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\tpublic String next() throws IOException \n\t{\n\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\tst = new StringTokenizer(br.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\n\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\n\tpublic double nextDouble() throws IOException\n\t{\n\t\tString x = next();\n\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\tdouble res = 0, f = 1;\n\t\tboolean dec = false, neg = false;\n\t\tint start = 0;\n\t\tif(x.charAt(0) == '-')\n\t\t{\n\t\t\tneg = true;\n\t\t\tstart++;\n\t\t}\n\t\tfor(int i = start; i < x.length(); i++)\n\t\t\tif(x.charAt(i) == '.')\n\t\t\t{\n\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\tdec = true;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\tif(dec)\n\t\t\t\t\tf *= 10;\n\t\t\t}\n\t\tres += Long.parseLong(sb.toString()) / f;\n\t\treturn res * (neg?-1:1);\n\t}\n\t\n\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2d189553f6bd58dca20852ca5bcbfa42", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n \npublic class Main{\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n \n int num = s.nextInt();\n \n int presents = Math.floor(num/3);\n num-=presents*3;\n if(num==1) {\n presents++;\n }\n \n System.out.print(presents);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c2ed7a3ca0b3753c3b39a0f9aa95dc00", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.lang.Math;\n\npublic class A1 {\n\tpublic static void main(String[] args) throws IOException {\n Scanner in= new Scanner(System.in);\n long l=in.nextLong();\n if(l%3==0) l=l/3*2;\n else l=l-(l+1)/3;\n System.out.prinln(l);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9550bc96043b8f4222ecfa755214b2c5", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CF2 {\n Scanner inputScan = Functions.getScannerLocal(); //new Scanner(System.in);\n public static void main(String[] args) {\n CF2 program = new CF2();\n program.execute();\n }\n\n public void execute()\n {\n int N = inputScan.nextInt();\n int rem = N % 3;\n int result = 2*(N/3);\n\n if(rem > 0) {\n result++;\n }\n System.out.println(result);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f1de9af771c2cd1f5656f824487e74ee", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution {\n\n private static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = sc.nextInt();\n System.out.println(2 * n / 3 + (n % 3 == 0 ? 0 : 1);)\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "42e25892466eff51b38d9f2e74a5da8b", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: aircube\n * Date: 11.01.11\n * Time: 4:14\n * To change this template use File | Settings | File Templates.\n */\n\nimport javax.swing.undo.StateEdit;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Template {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n\n public static void main(String[] args) throws IOException {\n new Template().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\n solve();\n\n br.close();\n out.close();\n }\n static final long mod = 1000000000 + 7;\n int cnt(int x, int d) {\n int r = 0;\n while (x > 0) {\n r += x / d;\n x /= d;\n }\n return r;\n }\n long bp(long a, long power) {\n long r = 1;\n for(; power > 0; power >>= 1, a = (a * a) % mod) if ((power & 1) > 0) r = (r * a) % mod;\n return r;\n }\n boolean isprime(int x) {\n for(int i = 2; i * i <= x; ++i)\n if (x % i == 0) return false;\n return true;\n }\n long bp(long a, long power) {\n long r = 1;\n for(; power > 0; power >>= 1, a = (a * a) % mod) if ((power & 1) > 0) r = (r * a) % mod;\n return r;\n }\n long inverse(int a) {\n return bp(a, mod - 2);\n }\n void solve() throws IOException {\n int n = nextInt();\n // (n + n - 1) ! / n ! / (n - 1) !\n long res = 2;\n for(int i = 1; i <= n + n - 1; ++i) {\n res = (res * i) % mod;\n }\n for(int i = 1; i <= n; ++i) {\n res = (res * inverse(i)) % mod;\n }\n for(int i = 1; i <= n - 1; ++i) {\n res = (res * inverse(i)) % mod;\n }\n res -= n;\n res = (res % mod + mod) % mod;\n out.print(res);\n\n }\n\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "03e80b2afcfdbd248c1bbb8c0bdac2d4", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Main{\n\tfinal long MOD = 1000000007;\n\tfinal int N = 100001;\n\tlong f[] = new long[N];\n\tlong qmod(long a, long x, long mod){\n\t\tlong res = 1, tmp = a % mod;\n\t\twhile(x != 0){\n\t\t\tif((x & 1) == 1){\n\t\t\t\tres = res * tmp % mod;\n\t\t\t}\n\t\t\ttmp = tmp * tmp % MOD;\n\t\t\tx >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\n\tlong c(int n, int m)\n\t{\n\t\treturn f[n] * qmod(f[n - m] * f[m] % MOD, MOD - 2, MOD) % MOD;\n\t}\n\tvoid run(){\n\t\tf[0] = 1;\n\t\tfor(int i = 1;i < N;i++){\n\t\t\tf[i] = f[i - 1] * i % MOD;\n\t\t}\n\t\tint n;\n\t\twhile(cin.hasNext()){\n\t\t\tn = cin.nextInt();\n\t\t\tSystem.out.println((c(2 * n, n) - n + MOD) % MOD);\n\t\t}\n\t}\n\tpublic static void main(String args[]){\n\t\tnew Main().run();\n\t}\n\tprivate Scanner cin = new Scanner(System.in);\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "122adbe12fee78708ab49925b4cdd6e5", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n//\t\tScanner r = new Scanner(System.in);\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString[] line = r.readLine().split(\"[ ]+\");\n\t\tint n= Integer.parseInt(line[0]);\n\t\tint m= Integer.parseInt(line[1]);\n\t\tint k= Integer.parseInt(line[2]);\n\t\t\n\t\tint[][] arr = new int[m][3];\n\t\t\n\t\twhile(m-->0){\n\t\t\tline = r.readLine().split(\"[ ]+\");\n\t\t\tint i = Integer.parseInt(line[0])-1;\n\t\t\tint j = Integer.parseInt(line[1])-1;\n\t\t\tint start = Integer.parseInt(line[2]);\n\t\t\t\n\t\t\tarr[arr.length-1-m][0] = i;\n\t\t\tarr[arr.length-1-m][1] = j;\n\t\t\tarr[arr.length-1-m][2] = start;\n\t\t}\n\t\t\n\t\tlong sum = 0 ;\t\t\n\t\tline = r.readLine().split(\"[ ]+\");\n\t\twhile(k-->0){\n\t\t\tint index = Integer.parseInt(line[line.length-1-k])-1;\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n//\t\t\t\tif(index<= arr[i][1] && index>=arr[i][0])\n\t\t\t\t\tsum+=index-arr[i][0] +arr[i][2];\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(sum);\n\t\t\n\t\t\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c99ae6656eacc04a448e00f92d9d4a0", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\t\n\tstatic final int mod = (int)1e9 + 7;\n\tstatic long[] fac;\n\t\n\tstatic long nCr(int n, int r)\n\t{\n\t\treturn fac[n] * modPow(fac[r] * fac[n - r] % mod, mod - 2);\n\t}\n\t\n\tstatic long modPow(long b, int e)\n\t{\n\t\tlong res = 1;\n\t\twhile(e > 0)\n\t\t{\n\t\t\tif((e & 1) == 1)\n\t\t\t\tres = res * b % mod;\n\t\t\tb = b * b % mod;\n\t\t\te >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tfac = new long[100001];\n\t\tfac[0] = 1;\n\t\tfor(int i = 1; i <= 100000; ++i)\n\t\t\tfac[i] = 1l * fac[i - 1] * i % mod;\n\t\tint n = sc.nextInt();\t\n\t\tlong f = nCr(2 * n - 1, n - 1);\n\t\tout.println((f * 2 - n + mod)%mod);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bee323126d57f70bc071dd92b61affba", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\npublic class Lap {\n public static void main(String[] args) {\n \n Scanner input = new Scanner(System.in);\n \n int n = input.nextInt(), counter = 0;\n String str = input.next(); \n \n boolean already_copied = false;\n \n for (int i = 0; i < n; ++i)\n {\n if (i == n-1)\n counter++;\n else\n {\n int temp_counter = 1, j = i;\n while (j < n-1 && str.charAt(j) == str.charAt(j+1))\n {\n temp_counter++;\n j++;\n }\n if (j != i)\n {\n i += (temp_counter % 2 == 0) ? temp_counter - 1 : temp_counter - 2;\n counter = counter + (temp_counter / 2) + 1;\n }\n \n else if (!already_copied && can_be_copied(str, i) && i != 0)\n {\n counter++;\n i = i * 2 - 1;\n already_copied = true;\n }\n else\n counter++;\n }\n \n }\n System.out.println(counter);\n }\n \n public static boolean can_be_copied(String str, int end_position)\n {\n int temp = end_position;\n for (int i = 0; i < end_position; i++, temp++)\n {\n if ( str.charAt(i) != str.charAt(temp) )\n return false;\n }\n return true;\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c49fc28be0f2b7308648740b8ee62e49", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class B{\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 int max = n;\n for(int i = 0; i <= n/2; i++){\n //String sub1 = s.substring(0, i);\n System.out.println(\"sub1: \"+sub1);\n //String sub2 = s.substring(i, i+sub1.length());\n System.out.println(\"sub2: \"+ sub2);\n if(sub1.equals(sub2)){\n max = Math.min(max, n-sub1.length()+1);\n }\n }\n System.out.println(max);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1777058ff428b87a281754dfdb8381e4", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \n // Oh, Hello there..!!\n\npublic class B implements Runnable {\n \t\t\n public void run() {\n \n InputReader sc = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint n=sc.nextInt();\n\t\tString s=sc.next();\n\n\t\tint half = s.length()/2;\n\n\t\twhile(half>=1)\n\t\t{\n\t\t\t//out.println(s.substring(0,half)+\" \"+s.substring(half,half*2));\n\t\t\tif(s.substring(0,half).equals(s.substring(half,half*2)))\n\t\t\t\tbreak;\n\t\t\thalf--;\n\t\t}\n\n\t\tout.println(n-half+(half==0?:0:1));\n\t\t\n out.close();\n }\n\n//========================================================\n\n\tstatic class Pair\n\t{\n\t\tint a,b;\n\t\tPair(int aa,int bb)\n\t\t{\n\t\t\ta=aa;\n\t\t\tb=bb;\n\t\t}\n\t}\n\t\n\tstatic int sa(int a[],InputReader sc)\n\t{\n\t\tint x=Integer.MAX_VALUE;\n\t\tfor(int i=0;i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n }\n catch (IOException e) {\n throw new InputMismatchException();\n }\n \n if(numChars <= 0) \n return -1;\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n \n while(isSpaceChar(c))\n c = read();\n \n int sgn = 1;\n \n if (c == '-') {\n sgn = -1;\n c = read();\n }\n \n int res = 0;\n do {\n if(c<'0'||c>'9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n \n return res * sgn;\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n \n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n }\n while (!isSpaceChar(c));\n \n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public String next() {\n return readString();\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n public static void main(String args[]) throws Exception {\n new Thread(null, new B(),\"Main\",1<<27).start();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "93711f6240b98cbd171b61193f6dd3df", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\npublic class String_Typing {\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tString str = sc.next();\n\t\t\n\t\tchar[] arr = str.toCharArray();\n\t\tif(arr.length == 1 )\n\t\t\tSystem.out.println(1);\n\t\telse\n\t\t{\n\t\tint op = arr.length;\n\t\t\n\t\tString match = arr[0]+\"\"+arr[1];\n\t\tint Endindex = -1,startIndex=-1;\n\t\tfor(int i = 2; i < arr.length;i++)\n\t\t{\n\t\t\tfor(int j = 0 ; j < match.length();j++)\n\t\t\t{\t\n\t\t\t\tif(i+j < arr.length)\n\t\t\t\tif(match.charAt(j) == arr[i+j])\n\t\t\t\t{\n\t\t\t\t\tif(j == match.length() -1)\n\t\t\t\t\t{\n\t\t\t\t\t\tstartIndex = i;\n\t\t\t\t\t\tEndindex = i+j;\n\t\t\t\t\t\tmatch+=\"\"+arr[i];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tmatch+=\"\"+arr[i];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t}\n\t\tint duplicates = Endindex +1 - startIndex;\n\t\t\n\t\tSystem.out.println(op-duplicates+1);\n\t\t\n\t\t\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ded23e7f49e929a076bfe53792ad03f", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A515A{\n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();\n \n if(s < a+b || (s - a - b )% 2 == 1) \n System.out.println(\"No\");\n else\n System.out.println(\"Yes\"); \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e3693ed097db3c348b295e0cc8dae3e6", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "mport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\tMyScanner sc = new MyScanner();\n\tScanner sc2 = new Scanner(System.in);\n\tfinal int MOD = 1000000007;\n\tint[] dx = { 1, 0, 0, -1 };\n\tint[] dy = { 0, 1, -1, 0 };\n\n\tvoid run() {\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint s = sc.nextInt();\n\t\tint sum = Math.abs(a) + Math.abs(b);\n\t\tif (s < sum) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(sum % 2 == s % 2 ? \"Yes\" : \"No\");\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\tvoid debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tvoid debug2(int[][] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tfor (int j = 0; j < array[i].length; j++) {\n\t\t\t\tSystem.out.print(array[i][j]);\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\n\tboolean inner(int h, int w, int limH, int limW) {\n\t\treturn 0 <= h && h < limH && 0 <= w && w < limW;\n\t}\n\n\tvoid swap(int[] x, int a, int b) {\n\t\tint tmp = x[a];\n\t\tx[a] = x[b];\n\t\tx[b] = tmp;\n\t}\n\n\t// find minimum i (a[i] >= border)\n\tint lower_bound(int a[], int border) {\n\t\tint l = -1;\n\t\tint r = a.length;\n\n\t\twhile (r - l > 1) {\n\t\t\tint mid = (l + r) / 2;\n\t\t\tif (border <= a[mid]) {\n\t\t\t\tr = mid;\n\t\t\t} else {\n\t\t\t\tl = mid;\n\t\t\t}\n\t\t}\n\t\t// r = l + 1\n\t\treturn r;\n\t}\n\n\tboolean palindrome(String s) {\n\t\tfor (int i = 0; i < s.length() / 2; i++) {\n\t\t\tif (s.charAt(i) != s.charAt(s.length() - 1 - i)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tclass MyScanner {\n\t\tint nextInt() {\n\t\t\ttry {\n\t\t\t\tint c = System.in.read();\n\t\t\t\twhile (c != '-' && (c < '0' || '9' < c))\n\t\t\t\t\tc = System.in.read();\n\t\t\t\tif (c == '-')\n\t\t\t\t\treturn -nextInt();\n\t\t\t\tint res = 0;\n\t\t\t\tdo {\n\t\t\t\t\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\tc = System.in.read();\n\t\t\t\t} while ('0' <= c && c <= '9');\n\t\t\t\treturn res;\n\t\t\t} catch (Exception e) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tString next() {\n\t\t\ttry {\n\t\t\t\tStringBuilder res = new StringBuilder(\"\");\n\t\t\t\tint c = System.in.read();\n\t\t\t\twhile (Character.isWhitespace(c))\n\t\t\t\t\tc = System.in.read();\n\t\t\t\tdo {\n\t\t\t\t\tres.append((char) c);\n\t\t\t\t} while (!Character.isWhitespace(c = System.in.read()));\n\t\t\t\treturn res.toString();\n\t\t\t} catch (Exception e) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tint[] nextIntArray(int n) {\n\t\t\tint[] in = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tin[i] = nextInt();\n\t\t\t}\n\t\t\treturn in;\n\t\t}\n\n\t\tint[][] nextInt2dArray(int n, int m) {\n\t\t\tint[][] in = new int[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tin[i] = nextIntArray(m);\n\t\t\t}\n\t\t\treturn in;\n\t\t}\n\n\t\tdouble[] nextDoubleArray(int n) {\n\t\t\tdouble[] in = new double[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tin[i] = nextDouble();\n\t\t\t}\n\t\t\treturn in;\n\t\t}\n\n\t\tlong[] nextLongArray(int n) {\n\t\t\tlong[] in = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tin[i] = nextLong();\n\t\t\t}\n\t\t\treturn in;\n\t\t}\n\n\t\tchar[][] nextCharField(int n, int m) {\n\t\t\tchar[][] in = new char[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tString s = sc.next();\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tin[i][j] = s.charAt(j);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn in;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da17aa28e82cf08a6b01c90c24437908", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "\npublic class HelloWorld{\n\n public static void main(String []args){\n Scanner in = new Scanner(System.in);\n String line = in.nextLine();\n String[] tokens = line.split(\"\\\\s+\");\n if(Math.abs(Integer.parseInt(tokens[0])) + Math.abs(Integer.parseInt(tokens[1])) <=Integer.parseInt(tokens[2])){\n if((Integer.parseInt(tokens[0]) + Integer.parseInt(tokens[1])) % 2 ==0 && Integer.parseInt(tokens[2]) %2==0){\n System.out.println(\"Yes\");\n }else if((Integer.parseInt(tokens[0]) + Integer.parseInt(tokens[1])) % 2 ==1 && Integer.parseInt(tokens[2]) %2==1){\n System.out.println(\"Yes\");\n }else{\n System.out.println(\"No\");\n }\n }else{\n System.out.println(\"No\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6ffd85087b26246af457060901dcf18a", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n/package javaapplication73;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author HIMANSHU\n */\npublic class JavaApplication73 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner s=new Scanner(System.in);\n int a =s.nextInt();\n int b=s.nextInt();\n int stp=s.nextInt();\n if((a+b)stp)\n {\n if(stp%2==0)\n {\n System.out.println(\"Yes\");\n }\n else\n {\n System.out.println(\"No\");\n }\n }\n }\n \n \n \n \n }\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eab780c4f607fb863c94eba57c806e52", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport javafx.util.Pair;\nimport sun.swing.icon.SortArrowIcon;\n//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n//String tooMuchCodeForASmallTask = br.readLine();\npublic class ProblemSolving {\n\n public static void main(String[] args) throws IOException{\n ArrayList > arr = new ArrayList<>();\n arr.add(new Pair('A',0));\n arr.add(new Pair('B',0));\n arr.add(new Pair('C',0));\n String input ;\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n \n for(int i =0 ; i < 3;i++){\n input = bf.readLine();\n int index1 = (int)input.charAt(0)-65;\n int index2 = (int)input.charAt(2)-65;\n if(input.charAt(1)=='>'){ \n arr.set(index1, new Pair(arr.get(index1).getKey(),arr.get(index1).getValue()+2));\n }else{\n arr.set(index2, new Pair(arr.get(index2).getKey(),arr.get(index2).getValue()+2));\n }\n \n }\n helloThere(arr);\n \n }\n public static void helloThere(ArrayList> s){\n for(int i =0 ; i < 3 ; i++){\n for(int j =0 ; j < 2 ;j++){\n if (s.get(j).getValue()>s.get(j+1).getValue()){\n Collections.swap(s, j, j+1);\n }\n }\n }\n System.out.println(s.get(0).getKey()+\"\"+s.get(1).getKey()+\"\"+s.get(2).getKey());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e4f62ff9e30ded1a0d42e8203976efa", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package testinggg;\n\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author gg\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 coins solver = new coins();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class coins {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n\n String arr[] = new String[3];\n Integer letter[] = new Integer[3];\n for (int i = 0; i < 3; i++) {\n arr[i] = in.next();\n letter[i] = 0;\n }\n\n for (int i = 0; i < 3; i++) {\n if (arr[i].charAt(1) == '>') {\n letter[(int) (arr[i].charAt(0)) % 65] += 1;\n letter[(int) (arr[i].charAt(2)) % 65] -= 1;\n } else {\n letter[(int) (arr[i].charAt(0)) % 65] -= 1;\n letter[(int) (arr[i].charAt(2)) % 65] += 1;\n }\n\n }\n //out.println(\"letter 0 is \"+letter[0]+\"letter 1 is \"+letter[1]);\n if (Math.abs(letter[0]) + Math.abs(letter[1]) + Math.abs(letter[2]) == 4) {\n String ans = Arrays.toString(letter);\n //out.println(ans);\n if (ans.equals(\"[2, 0, -2]\")) out.println(\"CBA\");\n else if (ans.equals(\"[2, -2, 0]\")) out.print(\"BCA\");\n else if (ans.equals(\"[-2, 0, 2]\")) out.print(\"ABC\");\n else if (ans.equals(\"[-2, 2, 0]\")) out.print(\"ACB\");\n else if (ans.equals(\"[0, 2, -2]\")) out.print(\"CAB\");\n else if (ans.equals([\"0, -2, 2]\")) out.print(\"BAC\");\n } else {\n out.print(\"Impossible\");\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "454bce695c6f8012a488f6ec7fc347f3", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class Coins {\n\tpublic static void main(String args[]){\n\t\tScanner in=new Scanner(System.in);\n\t\tString r=in.next();\n\t\tString s=in.next();\n\t\tString t=in.next();\n\t\t\n\t\tint count1=0,count2=0,count3=0;\n\t\n\t\tif(r.charAt(1)=='>')\n\t\t\tr=r.substring(0,0)+'1'+r.substring(1);\n\t\t\telse\n\t\t r=r.substring(0,2)+'1';\n\t\n\t\tif(s.charAt(1)=='>')\n\t\t\ts=s.substring(0,0)+'1'+s.substring(1);\n\t\t\telse\n\t\t s=s.substring(0,2)+'1';\n\t\t\n\t\tif(t.charAt(1)=='>')\n\t\t\tt=t.substring(0,0)+'1'+t.substring(1);\n\t\t\telse\n\t\t t=t.substring(0,2)+'1';\n\t\t\n\t\tif(r.contains(\"A\"))\n\t\t\tcount1++;\n\t\tif(s.contains(\"A\"))\n\t\t\tcount1++;\n\t\tif(t.contains(\"A\"))\n\t\t count1++;\n\t\tif(r.contains(\"B\"))\n\t\t\tcount2++;\n\t\tif(s.contains(\"B\"))\n\t\t\tcount2++;\n\t\tif(t.contains(\"B\"))\n\t\t\tcount2++;\n\t\tif(r.contains(\"C\"))\n\t\t\tcount3++;\n\t\tif(s.contains(\"C\"))\n\t\t\tcount3++;\n\t\tif(t.contains(\"C\"))\n\t\t\tcount3++;\n\t\t\n\t\tif(count1==count2||count2==count3||count3==count1)\n\t\t\tSystem.out.println(\"Impossible\");\n\t\telse\n\t\t{\n\t\t\t\n\t\t\tif (count1 == 0 && count2 == 1 && count3 == 2) {\n\t\t\t\tSystem.out.print(\"C\");\n\t\t\t\tSystem.out.print(\"B\");\n\t\t\t\tSystem.out.print(\"A\");\n\t\t\t} else if (count1 == 0 && count2 == 2 && count3 == 1) {\n\t\t\t\tSystem.out.print(\"B\");\n\t\t\t\tSystem.out.print(\"C\");\n\t\t\t\tSystem.out.print(\"A\");\n\t\t\t} else if (count1 == 1 && count2 == 0 && count3 == 2) {\n\t\t\t\tSystem.out.print(\"C\");\n\t\t\t\tSystem.out.print(\"A\");\n\t\t\t\tSystem.out.print(\"B\");\n\t\t\t} else if (count1 == 2 && count2 == 0 && count3 == 1) {\n\t\t\t\tSystem.out.print(\"A\");\n\t\t\t\tSystem.out.print(\"C\");\n\t\t\t\tSystem.out.print(\"B\");\n\t\t\t} else if (count1 == 1 && count2 == 2 && count3 == 0) {\n\t\t\t\tSystem.out.print(\"B\");\n\t\t\t\tSystem.out.print(\"A\");\n\t\t\t\tSystem.out.print(\"C\");\n\t\t\t} else if (count1 == 2 && count2 == 1 && count3 == 0) {\n\t\t\t\tSystem.out.print(\"A\");\n\t\t\t\tSystem.out.print(\"B\");\n\t\t\t\tSystem.out.print(\"C\");\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1281d324a3fdf5e8cc234e423c288bd3", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "// \"static void main\" must be defined in a public class.\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int[] arr =new int[3]; \n char[] ans = new char[3]; \n for(int i=0; i < 3; i++ ) {\n String s = sc.next(); \n if(s.indexOf(\">\") !=-1 ){\n arr[s.charAt(0)-'A']++; \n }\n else {\n arr[s.charAt(2)-'A']++; \n }\n }\n if(arr[0] == arr[1] || arr[0] == arr[2] || arr[1]== arr[2] ){\n System.out.println(\"Impossible\");\n }\n else{\n for(int i=0; i < 3;i++){\n ans[arr[i]] = (char) ('A' + i) ; \n }\n }\n String ans1 = new String(ans);\n System.out.println(ans1);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cea2cf37e701fbb5b35fd874eedbf54c", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Test2a {\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[] 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\t// \u627e\u51fa\u548c\u4e0d\u4e3a0\u7684\u5b50\u5b57\u7b26\u4e32\n\t\t// \u5982\u679c\u5168\u662f0 \u4e3aNO \u5982\u679c\u53ea\u6709\u4e00\u4e2a\u4e0d\u4e3a0 \u4e5f\u662fNO\n\t\tList list = new ArrayList();\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tif (sum == 0) {\n\t\t\t\tsum += arr[i];\n\t\t\t\tif (sum != 0) {\n\t\t\t\t\tlist.add(new int[] { 1, i + 1 });\n\t\t\t\t}\n\t\t\t} else if (arr[i] != 0) {\n\t\t\t\tlist.add(new int[] { i + 1, i + 1 });\n\t\t\t} else {\n\t\t\t\t// \u5982\u679c\u662f0\uff0c\u548c\u4e0a\u4e00\u4e2a\u6570\u7ec4\u5408\u5e76\n\t\t\t\tif (!list.isEmpty()) {\n\t\t\t\t\tint[] indexs = list.get(list.size() - 1);\n\t\t\t\t\tindexs[1] = i + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (list.size() > 1) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(list.size());\n\t\t\tfor (int[] subIndexs : list) {\n\t\t\t\tSystem.out.println(subIndexs[0] + \" \" + subIndexs[1]);\n\t\t\t}\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11fc9ac9b90ec8d641df19030c18e398", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by USER on 1/6/2017.\n */\npublic class Div2_2 {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String[][] arr=new String[4][4];\n String l=\"\";\n for (int i = 0; i < 4; i++) {\n l=scanner.next();\n for (int j = 0; j < 4; j++) {\n arr[i][j]=\"\"+l.charAt(j);\n }\n }\n for (int i = 0; i < 4; i++) {\n for (int j = 0; j < 2; j++) {\n if(arr[i][j].equals(\"x\")){\n if(arr[i][j+1].equals(\"x\")) {\n if (arr[i][j + 2].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[i][j+1].equals(\".\")){\n if(arr[i][j+2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[i][j].equals(\".\")){\n if(arr[i][j+1].equals(\"x\")&&arr[i][j+2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }\n }\n for (int j = 0; j < 4; j++) {\n for (int i = 0; i < 2; i++) {\n if(arr[j][i].equals(\"x\")){\n if(arr[j+1][i].equals(\"x\")) {\n if (arr[j+2][i].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[j+1][i].equals(\".\")){\n if(arr[j+2][i].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[j][i].equals(\".\")){\n if(arr[j+1][i].equals(\"x\")&&arr[j+2][i].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }\n }\n if(arr[0][0].equals(\"x\")){\n if(arr[1][1].equals(\"x\")) {\n if (arr[2][2].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[1][1].equals(\".\")){\n if(arr[2][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[0][0].equals(\".\")){\n if(arr[1][1].equals(\"x\")&&arr[2][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n if(arr[1][1].equals(\"x\")){\n if(arr[2][2].equals(\"x\")) {\n if (arr[3][3].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[2][2].equals(\".\")){\n if(arr[3][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[1][1].equals(\".\")){\n if(arr[2][2].equals(\"x\")&&arr[3][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n if(arr[1][0].equals(\"x\")){\n if(arr[2][1].equals(\"x\")) {\n if (arr[3][2].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[2][1].equals(\".\")){\n if(arr[3][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[1][0].equals(\".\")){\n if(arr[2][1].equals(\"x\")&&arr[3][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n if(arr[0][1].equals(\"x\")){\n if(arr[1][2].equals(\"x\")) {\n if (arr[2][3].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[1][2].equals(\".\")){\n if(arr[2][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[0][1].equals(\".\")){\n if(arr[1][2].equals(\"x\")&&arr[2][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n arr=flipH(arr);\n arr=flipV(arr);\n if(arr[0][0].equals(\"x\")){\n if(arr[1][1].equals(\"x\")) {\n if (arr[2][2].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[1][1].equals(\".\")){\n if(arr[2][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[0][0].equals(\".\")){\n if(arr[1][1].equals(\"x\")&&arr[2][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n if(arr[1][1].equals(\"x\")){\n if(arr[2][2].equals(\"x\")) {\n if (arr[3][3].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[2][2].equals(\".\")){\n if(arr[3][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[1][1].equals(\".\")){\n if(arr[2][2].equals(\"x\")&&arr[3][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n if(arr[1][0].equals(\"x\")){\n if(arr[2][1].equals(\"x\")) {\n if (arr[3][2].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[2][1].equals(\".\")){\n if(arr[3][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[1][0].equals(\".\")){\n if(arr[2][1].equals(\"x\")&&arr[3][2].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n if(arr[0][1].equals(\"x\")){\n if(arr[1][2].equals(\"x\")) {\n if (arr[2][3].equals(\".\")) {\n System.out.println(\"YES\");\n return;\n }\n }else if(arr[1][2].equals(\".\")){\n if(arr[2][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n }else if(arr[0][1].equals(\".\")){\n if(arr[1][2].equals(\"x\")&&arr[2][3].equals(\"x\")){\n System.out.println(\"YES\");\n return;\n }\n }\n System.out.println(\"NO\");\n\n }static String[][] flipH(String[][] a) {\n String[][] b = new String[a.length][a[0].length];\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < a[0].length; j++) {\n b[i][j] = a[i][a[0].length - j - 1];\n }\n }\n return b;\n }\n\n static String[][] flipV(String[][] a) {\n String[][] b = new String[a.length][a[0].length];\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < a[0].length; j++) {\n b[i][j] = a[a.length - i - 1][j];\n }\n }\n return b;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "036810a7ef67c25575feab135ca15c8e", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "gorithm;\n\nimport java.util.*;\n\npublic class Solution {\n private static boolean\n up(char[][] board, int count, int i, int j) {\n int I = i;\n int J = j - count;\n if (J < 0 || J > 3) {\n return false;\n }\n return board[I][J] == 'x';\n }\n\n private static boolean\n left(char[][] board, int count, int i, int j) {\n int I = i - count;\n int J = j;\n if (I < 0 || I > 3) {\n return false;\n }\n return board[I][J] == 'x';\n }\n\n private static boolean\n diagonal(char[][] board, int rotation, int count, int i, int j) {\n int incrementI = -10000;\n int incrementJ = -10000;\n switch (rotation) {\n case 1:\n incrementI = 1;\n incrementJ = 1;\n break;\n case 2:\n incrementI = 1;\n incrementJ = -1;\n break;\n }\n int I;\n int J;\n I = i + incrementI * count;\n J = j + incrementJ * count;\n if (I < 0 || I > 3 || J < 0 || J > 3) {\n return false;\n }\n return board[I][J] == 'x';\n }\n\n private static boolean checkHorizontal(char[][] board, int i, int j) {\n boolean case1, case2, case3;\n case1 = up(board, 2, i, j) &&\n up(board, 1, i, j);\n case2 = up(board, 1, i, j) &&\n up(board, -1, i, j);\n case3 = up(board, -1, i, j) &&\n up(board, -2, i, j);\n return case1 || case2 || case3;\n }\n\n private static boolean checkVertical(char[][] board, int i, int j) {\n boolean case1, case2, case3;\n case1 = left(board, 2, i, j) &&\n left(board, 1, i, j);\n case2 = left(board, 1, i, j) &&\n left(board, -1, i, j);\n case3 = left(board, -1, i, j) &&\n left(board, -2, i, j);\n return case1 || case2 || case3;\n }\n\n private static boolean checkDiagonal(char[][] board, int i, int j) {\n for (int rotation = 1; rotation <= 2; rotation++) {\n boolean case1, case2, case3;\n case1 = diagonal(board, rotation, 2, i, j) &&\n diagonal(board, rotation, 1, i, j);\n case2 = diagonal(board, rotation, 1, i, j) &&\n diagonal(board, rotation, -1, i, j);\n case3 = diagonal(board, rotation, -1, i, j) &&\n diagonal(board, rotation, -2, i, j);\n if (case1 || case2 || case3) {\n return true;\n }\n }\n return false;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n char[][] board = new char[4][4];\n\n for (int i = 0; i < 4; i++) {\n String input = in.nextLine().trim();\n for (int j = 0; j < 4; j++) {\n board[i][j] = input.charAt(j);\n }\n }\n\n for (int i = 0; i < 4; i++) {\n for (int j = 0; j < 4; j++) {\n if (board[i][j] != '.') {\n // Already placed crosses or noughts\n continue;\n }\n if (checkDiagonal(board, i, j) ||\n checkHorizontal(board, i, j) ||\n checkVertical(board, i, j)) {\n System.out.println(\"YES\");\n return;\n }\n }\n }\n\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e3fbeae858730190e056b973af35261c", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class B {\n\n\n\n static char[][] grid;\n static int n, m;\n\n static boolean valid(int i, int j)\n {\n return i != -1 && j != -1 && i != n && j != m ;\n }\n\n\n public static void main (String args[])throws Exception{\n\n Scanner sc=new Scanner(System.in);\n PrintWriter out=new PrintWriter(System.out);\n\n grid=new char[4][4];\n n=4;\n m=4;\n for (int i = 0; i < 4; i++) {\n String s=sc.nextLine();\n // System.out.println(s);\n for (int j = 0; j <4; j++) {\n grid[i][j]=s.charAt(j);\n }\n\n }\n\n\n\n\n boolean can=false;\n for (int i = 0; i < 4; i++) {\n for (int j = 0; j <4 ; j++) {\n if(grid[i][j]=='x'||grid[i][j]=='.') {\n if (valid(i, j + 1) && grid[i][j + 1] == 'x' && valid(i, j - 1) && grid[i][j - 1] == 'x')\n can = true;\n if (valid(i, j + 1) && grid[i][j + 1] == 'x' && valid(i, j + 2) && grid[i][j + 2] == 'x')\n can = true;\n\n if (valid(i, j - 1) && grid[i][j - 1] == 'x' && valid(i, j - 2) && grid[i][j - 2] == 'x')\n can = true;\n\n\n if (valid(i + 1, j) && grid[i + 1][j] == 'x' && valid(i - 1, j) && grid[i - 1][j] == 'x')\n can = true;\n\n if (valid(i + 1, j) && grid[i + 1][j] == 'x' && valid(i + 2, j) && grid[i + 2][j] == 'x')\n can = true;\n\n if (valid(i - 1, j) && grid[i - 1][j] == 'x' && valid(i - 2, j) && grid[i - 2][j] == 'x')\n can = true;\n\n\n if (valid(i + 1, j + 1) && grid[i + 1][j + 1] == 'x' && valid(i - 1, j - 1) && grid[i - 1][j - 1] == 'x')\n can = true;\n\n\n if (valid(i + 1, j + 1) && grid[i + 1][j + 1] == 'x' && valid(i + 2, j + 2) && grid[i + 2][j + 2] == 'x')\n can = true;\n\n if (valid(i - 1, j - 1) && grid[i - 1][j - 1] == 'x' && valid(i - 2, j - 2) && grid[i - 2][j - 2] == 'x')\n can = true;\n\n\n\n if (valid(i + 1, j -1) && grid[i + 1][j - 1] == 'x' && valid(i -1 1, j +1) && grid[i - 1][j +1] == 'x')\n can = true;\n\n\n if (valid(i + 1, j - 1) && grid[i + 1][j -1] == 'x' && valid(i + 2, j - 2) && grid[i + 2][j - 2] == 'x')\n can = true;\n\n if (valid(i - 1, j + 1) && grid[i - 1][j + 1] == 'x' && valid(i - 2, j + 2) && grid[i - 2][j + 2] == 'x')\n can = true;\n \n \n\n if (can) break;\n }\n }\n }\nif(can) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n\n out.flush();\n\n }\n\n\n\n\n\n static class Scanner\n {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n public long nextLong() throws IOException {return Long.parseLong(next());}\n\n public String nextLine() throws IOException {return br.readLine();}\n\n public double nextDouble() throws IOException\n {\n String x = next();\n StringBuilder sb = new StringBuilder(\"0\");\n double res = 0, f = 1;\n boolean dec = false, neg = false;\n int start = 0;\n if(x.charAt(0) == '-')\n {\n neg = true;\n start++;\n }\n for(int i = start; i < x.length(); i++)\n if(x.charAt(i) == '.')\n {\n res = Long.parseLong(sb.toString());\n sb = new StringBuilder(\"0\");\n dec = true;\n }\n else\n {\n sb.append(x.charAt(i));\n if(dec)\n f *= 10;\n }\n res += Long.parseLong(sb.toString()) / f;\n return res * (neg?-1:1);\n }\n\n public boolean ready() throws IOException {return br.ready();}\n\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab49447f795bdad6c0ab853a825fb339", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.AbstractMap;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.NoSuchElementException;\nimport java.util.Set;\nimport java.util.SortedMap;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.function.BiConsumer;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\n\npublic class C_432\n{\n\tpublic static final long[] POWER2 = generatePOWER2();\n\tpublic static final IteratorBuffer ITERATOR_BUFFER_PRIME = new IteratorBuffer<>(streamPrime(1000000).iterator());\n\tprivate static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static StringTokenizer stringTokenizer = null;\n\tprivate static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tinterface BiFunctionResult\n\t{\n\t\tTypeResult apply(Type0 x0, Type1 x1, TypeResult x2);\n\t}\n\n\tstatic class Array implements Iterable\n\t{\n\t\tprivate final Object[] array;\n\n\t\tpublic Array(int size)\n\t\t{\n\t\t\tthis.array = new Object[size];\n\t\t}\n\n\t\tpublic Array(int size, Type element)\n\t\t{\n\t\t\tthis(size);\n\t\t\tArrays.fill(this.array, element);\n\t\t}\n\n\t\tpublic Array(Array array, Type element)\n\t\t{\n\t\t\tthis(array.size() + 1);\n\t\t\tfor (int index = 0; index < array.size(); index++)\n\t\t\t{\n\t\t\t\tset(index, array.get(index));\n\t\t\t}\n\t\t\tset(size() - 1, element);\n\t\t}\n\n\t\tpublic Array(List list)\n\t\t{\n\t\t\tthis(list.size());\n\t\t\tint index = 0;\n\t\t\tfor (Type element : list)\n\t\t\t{\n\t\t\t\tset(index, element);\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic Type get(int index)\n\t\t{\n\t\t\treturn (Type) this.array[index];\n\t\t}\n\n\t\tpublic Array set(int index, Type value)\n\t\t{\n\t\t\tthis.array[index] = value;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.array.length;\n\t\t}\n\n\t\tpublic List toList()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Type element : this)\n\t\t\t{\n\t\t\t\tresult.add(element);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tType result = Array.this.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"[\" + C_432.toString(this, \", \") + \"]\";\n\t\t}\n\t}\n\n\tstatic class BIT\n\t{\n\t\tprivate static int lastBit(int index)\n\t\t{\n\t\t\treturn index & -index;\n\t\t}\n\n\t\tprivate final long[] tree;\n\n\t\tpublic BIT(int size)\n\t\t{\n\t\t\tthis.tree = new long[size];\n\t\t}\n\n\t\tpublic void add(int index, long delta)\n\t\t{\n\t\t\tindex += 1;\n\t\t\twhile (index <= this.tree.length)\n\t\t\t{\n\t\t\t\ttree[index - 1] += delta;\n\t\t\t\tindex += lastBit(index);\n\t\t\t}\n\t\t}\n\n\t\tprivate long prefix(int end)\n\t\t{\n\t\t\tlong result = 0;\n\t\t\twhile (end > 0)\n\t\t\t{\n\t\t\t\tresult += this.tree[end - 1];\n\t\t\t\tend -= lastBit(end);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.tree.length;\n\t\t}\n\n\t\tpublic long sum(int start, int end)\n\t\t{\n\t\t\treturn prefix(end) - prefix(start);\n\t\t}\n\t}\n\n\tstatic abstract class Edge, TypeEdge extends Edge>\n\t{\n\t\tpublic final TypeVertex vertex0;\n\t\tpublic final TypeVertex vertex1;\n\t\tpublic final boolean bidirectional;\n\n\t\tpublic Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tthis.vertex0 = vertex0;\n\t\t\tthis.vertex1 = vertex1;\n\t\t\tthis.bidirectional = bidirectional;\n\t\t\tthis.vertex0.edges.add(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.add(getThis());\n\t\t\t}\n\t\t}\n\n\t\tpublic TypeVertex other(Vertex vertex)\n\t\t{\n\t\t\tTypeVertex result;\n\t\t\tif (vertex0 == vertex)\n\t\t\t{\n\t\t\t\tresult = vertex1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = vertex0;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic abstract TypeEdge getThis();\n\n\t\tpublic void remove()\n\t\t{\n\t\t\tthis.vertex0.edges.remove(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.remove(getThis());\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.vertex0 + \"->\" + this.vertex1;\n\t\t}\n\t}\n\n\tpublic static class EdgeDefault>> extends Edge>\n\t{\n\t\tpublic EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Vertex, TypeEdge extends Edge> implements Comparable>\n\t{\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiConsumer functionPreVisit,\n\t\t\t\tBiConsumer functionInVisit,\n\t\t\t\tBiConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tTypeVertex vertexTo;\n\t\t\tTypeEdge edgeTo;\n\t\t\tboolean[] isOnStack = new boolean[vertices.size()];\n\t\t\tStack stackOperations = new Stack<>();\n\t\t\tStack stackVertices = new Stack<>();\n\t\t\tStack stackEdges = new Stack<>();\n\n\t\t\tTypeVertex vertexStart = vertices.get(indexVertexStart);\n\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\tstackVertices.push(vertexStart);\n\t\t\tstackEdges.push(null);\n\t\t\tisOnStack[vertexStart.index] = true;\n\t\t\twhile (!stackOperations.isEmpty())\n\t\t\t{\n\t\t\t\tOperation operation = stackOperations.pop();\n\t\t\t\tTypeVertex vertex = stackVertices.pop();\n\t\t\t\tTypeEdge edge = stackEdges.pop();\n\t\t\t\tswitch (operation)\n\t\t\t\t{\n\t\t\t\t\tcase INVISIT:\n\t\t\t\t\t\tfunctionInVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase POSTVISIT:\n\t\t\t\t\t\tfunctionPostVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase EXPAND:\n\t\t\t\t\t\tstackOperations.push(Operation.POSTVISIT);\n\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\tInteger indexTo = null;\n\t\t\t\t\t\tfor (int index = 0; indexTo == null && index < vertex.edges.size(); index++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tindexTo = index;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (indexTo != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(indexTo);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\tfor (int index = indexTo + 1; index < vertex.edges.size(); index++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.INVISIT);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfunctionPreVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tConsumer functionPreVisit,\n\t\t\t\tConsumer functionInVisit,\n\t\t\t\tConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tdepthFirstSearch(\n\t\t\t\t\tvertices,\n\t\t\t\t\tindexVertexStart,\n\t\t\t\t\t(vertex, edge) -> functionPreVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionInVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionPostVisit.accept(vertex)\n\t\t\t);\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tTypeVertex vertex,\n\t\t\t\tTypeEdge edge,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tArray visited,\n\t\t\t\tFIFO verticesNext,\n\t\t\t\tFIFO edgesNext,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tif (!visited.get(vertex.index))\n\t\t\t{\n\t\t\t\tvisited.set(vertex.index, true);\n\t\t\t\tresult = function.apply(vertex, edge, result);\n\t\t\t\tfor (TypeEdge edgeNext : vertex.edges)\n\t\t\t\t{\n\t\t\t\t\tTypeVertex vertexNext = edgeNext.other(vertex);\n\t\t\t\t\tif (!visited.get(vertexNext.index))\n\t\t\t\t\t{\n\t\t\t\t\t\tverticesNext.push(vertexNext);\n\t\t\t\t\t\tedgesNext.push(edgeNext);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tArray visited = new Array<>(vertices.size(), false);\n\t\t\tFIFO verticesNext = new FIFO<>();\n\t\t\tverticesNext.push(vertices.get(indexVertexStart));\n\t\t\tFIFO edgesNext = new FIFO<>();\n\t\t\tedgesNext.push(null);\n\t\t\twhile (!verticesNext.isEmpty())\n\t\t\t{\n\t\t\t\tresult = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic final int index;\n\t\tpublic final List edges;\n\n\t\tpublic Vertex(int index)\n\t\t{\n\t\t\tthis.index = index;\n\t\t\tthis.edges = new ArrayList<>();\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Vertex that)\n\t\t{\n\t\t\treturn Integer.compare(this.index, that.index);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"\" + this.index;\n\t\t}\n\n\t\tenum Operation\n\t\t{\n\t\t\tINVISIT, POSTVISIT, EXPAND\n\t\t}\n\t}\n\n\tpublic static class VertexDefault, TypeEdge>> extends Vertex, TypeEdge>\n\t{\n\t\tpublic VertexDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class VertexDefaultDefault extends Vertex\n\t{\n\t\tpublic static Array vertices(int n)\n\t\t{\n\t\t\tArray result = new Array<>(n);\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult.set(index, new VertexDefaultDefault(index));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic VertexDefaultDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class EdgeDefaultDefault extends Edge\n\t{\n\t\tpublic EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefaultDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Tuple2\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\n\t\tpublic Tuple2(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \")\";\n\t\t}\n\t}\n\n\tstatic class Wrapper\n\t{\n\t\tpublic Type value;\n\n\t\tpublic Wrapper(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\tpublic Type get()\n\t\t{\n\t\t\treturn this.value;\n\t\t}\n\n\t\tpublic void set(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.value.toString();\n\t\t}\n\t}\n\n\tpublic static class Tuple3\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\t\tpublic final Type2 v2;\n\n\t\tpublic Tuple3(Type0 v0, Type1 v1, Type2 v2)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t\tthis.v2 = v2;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \", \" + this.v2 + \")\";\n\t\t}\n\t}\n\n\tpublic static class Tuple2Comparable, Type1 extends Comparable> extends Tuple2 implements Comparable>\n\t{\n\t\tpublic Tuple2Comparable(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tsuper(v0, v1);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Tuple2Comparable that)\n\t\t{\n\t\t\tint result = this.v0.compareTo(that.v0);\n\t\t\tif (result == 0)\n\t\t\t{\n\t\t\t\tresult = this.v1.compareTo(that.v1);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tpublic static class SingleLinkedList\n\t{\n\t\tpublic final Type element;\n\t\tpublic SingleLinkedList next;\n\n\t\tpublic SingleLinkedList(Type element, SingleLinkedList next)\n\t\t{\n\t\t\tthis.element = element;\n\t\t\tthis.next = next;\n\t\t}\n\n\t\tpublic void toCollection(Collection collection)\n\t\t{\n\t\t\tif (this.next != null)\n\t\t\t{\n\t\t\t\tthis.next.toCollection(collection);\n\t\t\t}\n\t\t\tcollection.add(this.element);\n\t\t}\n\t}\n\n\tpublic static class Node\n\t{\n\t\tpublic static Node balance(Node result)\n\t\t{\n\t\t\twhile (result != null && 1 < Math.abs(height(result.left) - height(result.right)))\n\t\t\t{\n\t\t\t\tif (height(result.left) < height(result.right))\n\t\t\t\t{\n\t\t\t\t\tNode right = result.right;\n\t\t\t\t\tif (height(right.right) < height(right.left))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, result.left, right.rotateRight());\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateLeft();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tNode left = result.left;\n\t\t\t\t\tif (height(left.left) < height(left.right))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, left.rotateLeft(), result.right);\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateRight();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node clone(Node result)\n\t\t{\n\t\t\tif (result != null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(result.value, clone(result.left), clone(result.right));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node delete(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tif (node.left == null)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = node.right;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (node.right == null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult = node.left;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tNode first = first(node.right);\n\t\t\t\t\t\t\tresult = new Node<>(first.value, node.left, delete(node.right, first.value, comparator));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, delete(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, delete(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node first(Node result)\n\t\t{\n\t\t\twhile (result.left != null)\n\t\t\t{\n\t\t\t\tresult = result.left;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node get(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node head(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node.left;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = head(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, head(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int height(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.height;\n\t\t}\n\n\t\tpublic static Node insert(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(value, null, null);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(value, node.left, node.right);\n\t\t\t\t\t;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, insert(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, insert(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node last(Node result)\n\t\t{\n\t\t\twhile (result.right != null)\n\t\t\t{\n\t\t\t\tresult = result.right;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int size(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.size;\n\t\t}\n\n\t\tpublic static Node tail(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(node.value, null, node.right);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, tail(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = tail(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static void traverseOrderIn(Node node, Consumer consumer)\n\t\t{\n\t\t\tif (node != null)\n\t\t\t{\n\t\t\t\ttraverseOrderIn(node.left, consumer);\n\t\t\t\tconsumer.accept(node.value);\n\t\t\t\ttraverseOrderIn(node.right, consumer);\n\t\t\t}\n\t\t}\n\n\t\tpublic final Type value;\n\t\tpublic final Node left;\n\t\tpublic final Node right;\n\t\tpublic final int size;\n\t\tprivate final int height;\n\n\t\tpublic Node(Type value, Node left, Node right)\n\t\t{\n\t\t\tthis.value = value;\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t\tthis.size = 1 + size(left) + size(right);\n\t\t\tthis.height = 1 + Math.max(height(left), height(right));\n\t\t}\n\n\t\tpublic Node rotateLeft()\n\t\t{\n\t\t\tNode left = new Node<>(this.value, this.left, this.right.left);\n\t\t\treturn new Node<>(this.right.value, left, this.right.right);\n\t\t}\n\n\t\tpublic Node rotateRight()\n\t\t{\n\t\t\tNode right = new Node<>(this.value, this.left.right, this.right);\n\t\t\treturn new Node<>(this.left.value, this.left.left, right);\n\t\t}\n\t}\n\n\tpublic static class SortedSetAVL implements SortedSet\n\t{\n\t\tpublic Comparator comparator;\n\t\tpublic Node root;\n\n\t\tprivate SortedSetAVL(Comparator comparator, Node root)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.root = root;\n\t\t}\n\n\t\tpublic SortedSetAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t}\n\n\t\tpublic SortedSetAVL(Collection collection, Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t\tthis.addAll(collection);\n\t\t}\n\n\t\tpublic SortedSetAVL(SortedSetAVL sortedSetAVL)\n\t\t{\n\t\t\tthis(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.root = null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\tpublic Type get(Type value)\n\t\t{\n\t\t\tNode node = Node.get(this.root, value, this.comparator);\n\t\t\treturn node == null ? null : node.value;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL subSet(Type valueStart, Type valueEnd)\n\t\t{\n\t\t\treturn tailSet(valueStart).headSet(valueEnd);\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL headSet(Type valueEnd)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL tailSet(Type valueStart)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic Type first()\n\t\t{\n\t\t\treturn Node.first(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic Type last()\n\t\t{\n\t\t\treturn Node.last(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.root == null ? 0 : this.root.size;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.root == null;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean contains(Object value)\n\t\t{\n\t\t\treturn Node.get(this.root, (Type) value, this.comparator) != null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\tStack> path = new Stack<>();\n\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\t{\n\t\t\t\t\tpush(SortedSetAVL.this.root);\n\t\t\t\t}\n\n\t\t\t\tpublic void push(Node node)\n\t\t\t\t{\n\t\t\t\t\twhile (node != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tpath.push(node);\n\t\t\t\t\t\tnode = node.left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn !path.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (path.isEmpty())\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tNode node = path.peek();\n\t\t\t\t\t\tType result = node.value;\n\t\t\t\t\t\tif (node.right != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpush(node.right);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tnode = path.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twhile (!path.isEmpty() && path.peek().right == node);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic Object[] toArray()\n\t\t{\n\t\t\tList list = new ArrayList<>();\n\t\t\tNode.traverseOrderIn(this.root, list::add);\n\t\t\treturn list.toArray();\n\t\t}\n\n\t\t@Override\n\t\tpublic T[] toArray(T[] ts)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean add(Type value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.insert(this.root, value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean remove(Object value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.delete(this.root, (Type) value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.allMatch(this::contains);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean addAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::add)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean retainAll(Collection collection)\n\t\t{\n\t\t\tSortedSetAVL set = new SortedSetAVL<>(this.comparator);\n\t\t\tcollection.stream()\n\t\t\t\t\t.map(element -> (Type) element)\n\t\t\t\t\t.filter(this::contains)\n\t\t\t\t\t.forEach(set::add);\n\t\t\tboolean result = size() != set.size();\n\t\t\tthis.root = set.root;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean removeAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::remove)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"{\" + C_432.toString(this, \", \") + \"}\";\n\t\t}\n\t}\n\n\tpublic static class SortedMapAVL implements SortedMap\n\t{\n\t\tpublic final Comparator comparator;\n\t\tpublic final SortedSetAVL> entrySet;\n\n\t\tpublic SortedMapAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey())));\n\t\t}\n\n\t\tprivate SortedMapAVL(Comparator comparator, SortedSetAVL> entrySet)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.entrySet = entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(TypeKey keyStart, TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)));\n\t\t}\n\n\t\tpublic Entry firstEntry()\n\t\t{\n\t\t\treturn this.entrySet.first();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey firstKey()\n\t\t{\n\t\t\treturn firstEntry().getKey();\n\t\t}\n\n\t\tpublic Entry lastEntry()\n\t\t{\n\t\t\treturn this.entrySet.last();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey lastKey()\n\t\t{\n\t\t\treturn lastEntry().getKey();\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.entrySet().size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.entrySet.isEmpty();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsKey(Object key)\n\t\t{\n\t\t\treturn this.entrySet().contains(new AbstractMap.SimpleEntry<>((TypeKey) key, null));\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsValue(Object value)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue get(Object key)\n\t\t{\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tentry = this.entrySet.get(entry);\n\t\t\treturn entry == null ? null : entry.getValue();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue put(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>(key, value);\n\t\t\tthis.entrySet().add(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue remove(Object key)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tthis.entrySet.remove(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tmap.entrySet()\n\t\t\t\t\t.forEach(entry -> put(entry.getKey(), entry.getValue()));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.entrySet.clear();\n\t\t}\n\n\t\t@Override\n\t\tpublic Set keySet()\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Collection values()\n\t\t{\n\t\t\treturn new Collection()\n\t\t\t{\n\t\t\t\t@Override\n\t\t\t\tpublic int size()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean isEmpty()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean contains(Object value)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Iterator iterator()\n\t\t\t\t{\n\t\t\t\t\treturn new Iterator()\n\t\t\t\t\t{\n\t\t\t\t\t\tIterator> iterator = SortedMapAVL.this.entrySet.iterator();\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic boolean hasNext()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.hasNext();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic TypeValue next()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.next().getValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Object[] toArray()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic T[] toArray(T[] ts)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean add(TypeValue typeValue)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean remove(Object o)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean containsAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean addAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean removeAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean retainAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic void clear()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL> entrySet()\n\t\t{\n\t\t\treturn this.entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.entrySet().toString();\n\t\t}\n\t}\n\n\tpublic static class FIFO\n\t{\n\t\tpublic SingleLinkedList start;\n\t\tpublic SingleLinkedList end;\n\n\t\tpublic FIFO()\n\t\t{\n\t\t\tthis.start = null;\n\t\t\tthis.end = null;\n\t\t}\n\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.start == null;\n\t\t}\n\n\t\tpublic Type peek()\n\t\t{\n\t\t\treturn this.start.element;\n\t\t}\n\n\t\tpublic Type pop()\n\t\t{\n\t\t\tType result = this.start.element;\n\t\t\tthis.start = this.start.next;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic void push(Type element)\n\t\t{\n\t\t\tSingleLinkedList list = new SingleLinkedList<>(element, null);\n\t\t\tif (this.start == null)\n\t\t\t{\n\t\t\t\tthis.start = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthis.end.next = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class MapCount extends SortedMapAVL\n\t{\n\t\tprivate int count;\n\n\t\tpublic MapCount(Comparator comparator)\n\t\t{\n\t\t\tsuper(comparator);\n\t\t\tthis.count = 0;\n\t\t}\n\n\t\tpublic long add(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key);\n\t\t\t\tif (value == null)\n\t\t\t\t{\n\t\t\t\t\tvalue = delta;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvalue += delta;\n\t\t\t\t}\n\t\t\t\tput(key, value);\n\t\t\t\tresult = delta;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count += result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int count()\n\t\t{\n\t\t\treturn this.count;\n\t\t}\n\n\t\tpublic List flatten()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Entry entry : entrySet())\n\t\t\t{\n\t\t\t\tfor (long index = 0; index < entry.getValue(); index++)\n\t\t\t\t{\n\t\t\t\t\tresult.add(entry.getKey());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Long remove(Object key)\n\t\t{\n\t\t\tLong result = super.remove(key);\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic long remove(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key) - delta;\n\t\t\t\tif (value <= 0)\n\t\t\t\t{\n\t\t\t\t\tresult = delta + value;\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult = delta;\n\t\t\t\t\tput(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(Type keyStart, Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(Type keyStart)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\t}\n\n\tpublic static class MapSet extends SortedMapAVL> implements Iterable\n\t{\n\t\tprivate Comparator comparatorValue;\n\n\t\tpublic MapSet(Comparator comparatorKey, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic MapSet(Comparator comparatorKey, SortedSetAVL>> entrySet, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey, entrySet);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic TypeValue firstValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> firstEntry = firstEntry();\n\t\t\tif (firstEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = firstEntry.getValue().first();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tIterator> iteratorValues = values().iterator();\n\t\t\t\tIterator iteratorValue = null;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext());\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic TypeValue next()\n\t\t\t\t{\n\t\t\t\t\tif (iteratorValue == null || !iteratorValue.hasNext())\n\t\t\t\t\t{\n\t\t\t\t\t\titeratorValue = iteratorValues.next().iterator();\n\t\t\t\t\t}\n\t\t\t\t\treturn iteratorValue.next();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tpublic TypeValue lastValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> lastEntry = lastEntry();\n\t\t\tif (lastEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = lastEntry.getValue().last();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic boolean add(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tSortedSetAVL set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue));\n\t\t\treturn set.add(value);\n\t\t}\n\n\t\tpublic boolean removeSet(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tboolean result;\n\t\t\tSortedSetAVL set = get(key);\n\t\t\tif (set == null)\n\t\t\t{\n\t\t\t\tresult = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = set.remove(value);\n\t\t\t\tif (set.size() == 0)\n\t\t\t\t{\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue);\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue);\n\t\t}\n\t}\n\n\tstatic class IteratorBuffer\n\t{\n\t\tprivate Iterator iterator;\n\t\tprivate List list;\n\n\t\tpublic IteratorBuffer(Iterator iterator)\n\t\t{\n\t\t\tthis.iterator = iterator;\n\t\t\tthis.list = new ArrayList();\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < list.size() || iterator().hasNext();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (list.size() <= this.index)\n\t\t\t\t\t{\n\t\t\t\t\t\tlist.add(iterator.next());\n\t\t\t\t\t}\n\t\t\t\t\tType result = list.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t}\n\n\tpublic static List> permutations(List list)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tresult.add(new ArrayList<>());\n\t\tfor (Type element : list)\n\t\t{\n\t\t\tList> permutations = result;\n\t\t\tresult = new ArrayList<>();\n\t\t\tfor (List permutation : permutations)\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= permutation.size(); index++)\n\t\t\t\t{\n\t\t\t\t\tList permutationNew = new ArrayList<>(permutation);\n\t\t\t\t\tpermutationNew.add(index, element);\n\t\t\t\t\tresult.add(permutationNew);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static List> combinations(int n, int k)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tif (k == 0)\n\t\t{\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (k == 1)\n\t\t\t{\n\t\t\t\tList combination = new ArrayList<>();\n\t\t\t\tcombination.add(n);\n\t\t\t\tresult.add(combination);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= n; index++)\n\t\t\t\t{\n\t\t\t\t\tfor (List combination : combinations(n - index, k - 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tcombination.add(index);\n\t\t\t\t\t\tresult.add(combination);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterator iterator0, Iterator iterator1, Comparator comparator)\n\t{\n\t\tint result = 0;\n\t\twhile (result == 0 && iterator0.hasNext() && iterator1.hasNext())\n\t\t{\n\t\t\tresult = comparator.compare(iterator0.next(), iterator1.next());\n\t\t}\n\t\tif (result == 0)\n\t\t{\n\t\t\tif (iterator1.hasNext())\n\t\t\t{\n\t\t\t\tresult = -1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (iterator0.hasNext())\n\t\t\t\t{\n\t\t\t\t\tresult = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterable iterable0, Iterable iterable1, Comparator comparator)\n\t{\n\t\treturn compare(iterable0.iterator(), iterable1.iterator(), comparator);\n\t}\n\n\tprivate static String nextString() throws IOException\n\t{\n\t\twhile ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens()))\n\t\t{\n\t\t\tstringTokenizer = new StringTokenizer(bufferedReader.readLine());\n\t\t}\n\t\treturn stringTokenizer.nextToken();\n\t}\n\n\tprivate static String[] nextStrings(int n) throws IOException\n\t{\n\t\tString[] result = new String[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextString();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\n\tpublic static int[] nextInts(int n) throws IOException\n\t{\n\t\tint[] result = new int[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextInt();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n\n\tpublic static long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\n\tpublic static long[] nextLongs(int n) throws IOException\n\t{\n\t\tlong[] result = new long[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextLong();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String nextLine() throws IOException\n\t{\n\t\treturn bufferedReader.readLine();\n\t}\n\n\tpublic static void close()\n\t{\n\t\tout.close();\n\t}\n\n\tpublic static int binarySearchMinimum(Function filter, int start, int end)\n\t{\n\t\tint result;\n\t\tif (start == end)\n\t\t{\n\t\t\tresult = end;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint middle = start + (end - start) / 2;\n\t\t\tif (filter.apply(middle))\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, start, middle);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, middle + 1, end);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int binarySearchMaximum(Function filter, int start, int end)\n\t{\n\t\treturn -binarySearchMinimum(x -> filter.apply(-x), -end, -start);\n\t}\n\n\tpublic static long divideCeil(long x, long y)\n\t{\n\t\treturn (x + y - 1) / y;\n\t}\n\n\tpublic static Set divisors(long n)\n\t{\n\t\tSortedSetAVL result = new SortedSetAVL<>(Comparator.naturalOrder());\n\t\tresult.add(1L);\n\t\tfor (Long factor : factors(n))\n\t\t{\n\t\t\tSortedSetAVL divisors = new SortedSetAVL<>(result);\n\t\t\tfor (Long divisor : result)\n\t\t\t{\n\t\t\t\tdivisors.add(divisor * factor);\n\t\t\t}\n\t\t\tresult = divisors;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long faculty(int n)\n\t{\n\t\tlong result = 1;\n\t\tfor (int index = 2; index <= n; index++)\n\t\t{\n\t\t\tresult *= index;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static LinkedList factors(long n)\n\t{\n\t\tLinkedList result = new LinkedList<>();\n\t\tIterator primes = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile (n > 1 && (prime = primes.next()) * prime <= n)\n\t\t{\n\t\t\twhile (n % prime == 0)\n\t\t\t{\n\t\t\t\tresult.add(prime);\n\t\t\t\tn /= prime;\n\t\t\t}\n\t\t}\n\t\tif (n > 1)\n\t\t{\n\t\t\tresult.add(n);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long gcd(long a, long b)\n\t{\n\t\twhile (a != 0 && b != 0)\n\t\t{\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tb %= a;\n\t\t\t}\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tpublic static long[] generatePOWER2()\n\t{\n\t\tlong[] result = new long[63];\n\t\tfor (int x = 0; x < result.length; x++)\n\t\t{\n\t\t\tresult[x] = 1L << x;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean isPrime(long x)\n\t{\n\t\tboolean result = x > 1;\n\t\tIterator iterator = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile ((prime = iterator.next()) * prime <= x)\n\t\t{\n\t\t\tresult &= x % prime > 0;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long knapsack(List> itemsValueWeightCount, int weightMaximum)\n\t{\n\t\tlong[] valuesMaximum = new long[weightMaximum + 1];\n\t\tfor (Tuple3 itemValueWeightCount : itemsValueWeightCount)\n\t\t{\n\t\t\tlong itemValue = itemValueWeightCount.v0;\n\t\t\tint itemWeight = itemValueWeightCount.v1;\n\t\t\tint itemCount = itemValueWeightCount.v2;\n\t\t\tfor (int weight = weightMaximum; 0 <= weight; weight--)\n\t\t\t{\n\t\t\t\tfor (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++)\n\t\t\t\t{\n\t\t\t\t\tvaluesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong result = 0;\n\t\tfor (long valueMaximum : valuesMaximum)\n\t\t{\n\t\t\tresult = Math.max(result, valueMaximum);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean knapsackPossible(List> itemsWeightCount, int weightMaximum)\n\t{\n\t\tboolean[] weightPossible = new boolean[weightMaximum + 1];\n\t\tweightPossible[0] = true;\n\t\tint weightLargest = 0;\n\t\tfor (Tuple2 itemWeightCount : itemsWeightCount)\n\t\t{\n\t\t\tint itemWeight = itemWeightCount.v0;\n\t\t\tint itemCount = itemWeightCount.v1;\n\t\t\tfor (int weightStart = 0; weightStart < itemWeight; weightStart++)\n\t\t\t{\n\t\t\t\tint count = 0;\n\t\t\t\tfor (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight)\n\t\t\t\t{\n\t\t\t\t\tif (weightPossible[weight])\n\t\t\t\t\t{\n\t\t\t\t\t\tcount = itemCount;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (0 < count)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tweightPossible[weight] = true;\n\t\t\t\t\t\t\tweightLargest = weight;\n\t\t\t\t\t\t\tcount -= 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn weightPossible[weightMaximum];\n\t}\n\n\tpublic static long lcm(int a, int b)\n\t{\n\t\treturn a * b / gcd(a, b);\n\t}\n\n\tpublic static List permutation(long p, List x)\n\t{\n\t\tList copy = new ArrayList<>();\n\t\tfor (int index = 0; index < x.size(); index++)\n\t\t{\n\t\t\tcopy.add(x.get(index));\n\t\t}\n\t\tList result = new ArrayList<>();\n\t\tfor (int indexTo = 0; indexTo < x.size(); indexTo++)\n\t\t{\n\t\t\tint indexFrom = (int) p % copy.size();\n\t\t\tp = p / copy.size();\n\t\t\tresult.add(copy.remove(indexFrom));\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String toString(Iterator iterator, String separator)\n\t{\n\t\tStringBuilder stringBuilder = new StringBuilder();\n\t\tif (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\twhile (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(separator);\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\treturn stringBuilder.toString();\n\t}\n\n\tpublic static String toString(Iterator iterator)\n\t{\n\t\treturn toString(iterator, \" \");\n\t}\n\n\tpublic static String toString(Iterable iterable, String separator)\n\t{\n\t\treturn toString(iterable.iterator(), separator);\n\t}\n\n\tpublic static String toString(Iterable iterable)\n\t{\n\t\treturn toString(iterable, \" \");\n\t}\n\n\tpublic static Stream streamFibonacci()\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate BigInteger n0 = BigInteger.ZERO;\n\t\t\tprivate BigInteger n1 = BigInteger.ONE;\n\n\t\t\t@Override\n\t\t\tpublic BigInteger get()\n\t\t\t{\n\t\t\t\tBigInteger result = n0;\n\t\t\t\tn0 = n1;\n\t\t\t\tn1 = result.add(n0);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static Stream streamPrime(int sieveSize)\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate boolean[] isPrime = new boolean[sieveSize];\n\t\t\tprivate long sieveOffset = 2;\n\t\t\tprivate List primes = new ArrayList<>();\n\t\t\tprivate int index = 0;\n\n\t\t\tpublic void filter(long prime, boolean[] result)\n\t\t\t{\n\t\t\t\tif (prime * prime < this.sieveOffset + sieveSize)\n\t\t\t\t{\n\t\t\t\t\tlong remainingStart = this.sieveOffset % prime;\n\t\t\t\t\tlong start = remainingStart == 0 ? 0 : prime - remainingStart;\n\t\t\t\t\tfor (long index = start; index < sieveSize; index += prime)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult[(int) index] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void generatePrimes()\n\t\t\t{\n\t\t\t\tArrays.fill(this.isPrime, true);\n\t\t\t\tthis.primes.forEach(prime -> filter(prime, isPrime));\n\t\t\t\tfor (int index = 0; index < sieveSize; index++)\n\t\t\t\t{\n\t\t\t\t\tif (isPrime[index])\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.primes.add(this.sieveOffset + index);\n\t\t\t\t\t\tfilter(this.sieveOffset + index, isPrime);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.sieveOffset += sieveSize;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic Long get()\n\t\t\t{\n\t\t\t\twhile (this.primes.size() <= this.index)\n\t\t\t\t{\n\t\t\t\t\tgeneratePrimes();\n\t\t\t\t}\n\t\t\t\tLong result = this.primes.get(this.index);\n\t\t\t\tthis.index += 1;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static long totient(long n)\n\t{\n\t\tSet factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder());\n\t\tlong result = n;\n\t\tfor (long p : factors)\n\t\t{\n\t\t\tresult -= result / p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tsolve();\n\t\t} catch (IOException exception)\n\t\t{\n\t\t\texception.printStackTrace();\n\t\t}\n\t\tclose();\n\t}\n\n\tpublic static class Vector implements Comparable\n\t{\n\t\tpublic static Comparator COMPARATOR = Comparator.comparing(Vector::getX0)\n\t\t\t\t.thenComparing(Vector::getX1)\n\t\t\t\t.thenComparing(Vector::getX2)\n\t\t\t\t.thenComparing(Vector::getX3)\n\t\t\t\t.thenComparing(Vector::getX4);\n\t\tpublic final int x0;\n\t\tpublic final int x1;\n\t\tpublic final int x2;\n\t\tpublic final int x3;\n\t\tpublic final int x4;\n\n\t\tpublic Vector(int x0, int x1, int x2, int x3, int x4)\n\t\t{\n\t\t\tthis.x0 = x0;\n\t\t\tthis.x1 = x1;\n\t\t\tthis.x2 = x2;\n\t\t\tthis.x3 = x3;\n\t\t\tthis.x4 = x4;\n\t\t}\n\n\t\tpublic Vector() throws IOException\n\t\t{\n\t\t\tthis(nextInt(), nextInt(), nextInt(), nextInt(), nextInt());\n\t\t}\n\n\t\tpublic int getX0()\n\t\t{\n\t\t\treturn x0;\n\t\t}\n\n\t\tpublic int getX1()\n\t\t{\n\t\t\treturn x1;\n\t\t}\n\n\t\tpublic int getX2()\n\t\t{\n\t\t\treturn x2;\n\t\t}\n\n\t\tpublic int getX3()\n\t\t{\n\t\t\treturn x3;\n\t\t}\n\n\t\tpublic int getX4()\n\t\t{\n\t\t\treturn x4;\n\t\t}\n\n\t\tpublic int product(Vector p)\n\t\t{\n\t\t\treturn this.x0 * p.x0 +\n\t\t\t\t\tthis.x1 * p.x1 +\n\t\t\t\t\tthis.x2 * p.x2 +\n\t\t\t\t\tthis.x3 * p.x3 +\n\t\t\t\t\tthis.x4 * p.x4;\n\t\t}\n\n\t\tpublic Vector sub(Vector p)\n\t\t{\n\t\t\treturn new Vector(this.x0 - p.x0, this.x1 - p.x1, this.x2 - p.x2, this.x3 - p.x3, this.x4 - p.x4);\n\t\t}\n\n\t\tpublic boolean acute(Vector p, Vector q)\n\t\t{\n\t\t\tVector ap = p.sub(this);\n\t\t\tVector aq = q.sub(this);\n\t\t\treturn ap.product(aq) > 0;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Vector that)\n\t\t{\n\t\t\treturn COMPARATOR.compare(this, that);\n\t\t}\n\t}\n\n\tpublic static Set convert(boolean[] bad)\n\t{\n\t\tSet result = new SortedSetAVL<>(Comparator.naturalOrder());\n\n\t\tfor (int index = 0; index < bad.length; index++)\n\t\t{\n\t\t\tif (!bad[index])\n\t\t\t{\n\t\t\t\tresult.add(index);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static Set solveBrute(C_432.Vector[] vectors)\n\t{\n\t\tboolean[] bad = new boolean[vectors.length];\n\t\tfor (int index = 0; index < vectors.length; index++)\n\t\t{\n\t\t\tfor (int indexB = 0; indexB < vectors.length; indexB++)\n\t\t\t{\n\t\t\t\tfor (int indexC = 0; indexC < vectors.length; indexC++)\n\t\t\t\t{\n\t\t\t\t\tif (index != indexB && index != indexC && indexB != indexC)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (vectors[index].acute(vectors[indexB], vectors[indexC]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbad[index] = 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\t\treturn convert(bad);\n\t}\n\n\tpublic static Set solve(Vector[] vectors)\n\t{\n\t\tboolean[] bad = new boolean[vectors.length];\n\t\tfor (int index = 0; index < vectors.length; index++)\n\t\t{\n\t\t\tif (!bad[index])\n\t\t\t{\n\t\t\t\tfor (int indexB = 0; !bad[index] && indexB < vectors.length; indexB++)\n\t\t\t\t{\n\t\t\t\t\tfor (int indexC = 0; !bad[index] && indexC < vectors.length; indexC++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (index != indexB && index != indexC && indexB != indexC)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (vectors[index].acute(vectors[indexB], vectors[indexC]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbad[index] = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbad[indexB] = true;\n\t\t\t\t\t\t\t\tbad[indexC] = 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}\n\t\t}\n\t\treturn convert(bad);\n\t}\n\n\tpublic static void solve() throws IOException\n\t{\n\t\tint n = nextInt();\n\t\tVector[] vectors = new Vector[n];\n\t\tfor (int index = 0; index < n; index++)\n\t\t{\n\t\t\tvectors[index] = new Vector();\n\t\t}\n\t\tSet result = solveBrute(vectors);\n\t\tout.println(result.size());\n\t\tfor (Integer index : result)\n\t\t{\n\t\t\tout.println(index + 1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "351dbd633d475e76424a717ac6636721", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n/*\nTASK: fivedimpoints\nLANG: JAVA\n */\n\npublic class fivedimpoints{\n static int n;\n static int[][] coord;\n static long[][][] vect;\n static boolean[] bad;\n \n public static void main(String[] args) throws IOException{\n FastScanner in = new FastScanner(System.in); \n n = in.nextInt();\n if(n > 10) System.out.println(0);\n coord = new int[n][5];\n vect = new long[n][n][5];\n bad = new boolean[n];\n for(int i = 0;i 0 && !bad[i]){\n bad[i] = true;\n count--;\n }\n }\n }\n }\n }\n }\n System.out.println(count);\n for(int i = 0;i < n; i++){\n if(!bad[i]){\n System.out.println(i+1);\n }\n }\n }\n}\nclass 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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c667f004e91363b77c5abc943e124778", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc=new FastScanner();\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\twhile(sc.hasNext()){\n\t\t\tint n=sc.nextInt();\n\t\t\tPoint[]p=new Point[n];\n\t\t\tfor(int o=0;oset=new TreeSet();\n\t\t\tfor(int i=0;i0){\n\t\t\t\t\t\t\tflag=false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(flag)set.add(i+1)\n\t\t\t}\n\t\t\tpw.println(set.size());\n\t\t\tfor(int k:set){\n\t\t\t\tpw.print(k+\" \");\n\t\t\t}\n\t\t\tpw.flush();\n\t\t}\n\n\t}\n\tstatic double js(Point a,Point b){\n\t\tdouble sum=a.a*b.a+a.b*b.b+a.c*b.c+a.d*b.d+a.e*b.e;\n\t\treturn sum;\n\t}\n}\nclass Point{\n\tint a;\n\tint b;\n\tint c;\n\tint d;\n\tint e;\n\tint index;\n\tPoint (int a,int b,int c,int d,int e,int index){\n\t\tthis.a=a;\n\t\tthis.b=b;\n\t\tthis.c=c;\n\t\tthis.d=d;\n\t\tthis.e=e;\n\t\tthis.index=index;\n\t}\n\tPoint minus(Point p){\n\t\treturn new Point(a-p.a,b-p.b,c-p.c,d-p.d,e-p.e,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),32768);\n\t\t\tst = new StringTokenizer(\"\");\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tpublic boolean hasNext() {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = nextLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic String next() {\n\t\twhile(!st.hasMoreTokens()){\n\t\t\tst=new StringTokenizer(nextLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic String nextLine() {\n\t\tString line = \"\";\n\t\ttry {\n\t\t\tline = br.readLine();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn line;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c478e324cfb82dd2182fa2e1e7be85a2", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "package practiseCF;\n\nimport fastIO.InputReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class TaskC {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n// System.out.println(Math.toDegrees(Math.acos(0.5)));\n int n = in.nextInt();\n if(n >= 100) {\n out.print(0);\n } else {\n int [] a = new int[105];\n int [] b = new int[105];\n int [] c = new int[105];\n int [] d = new int[105];\n int [] e = new int[105];\n for(int i = 1; i <= n; i++) {\n a[i] = in.nextInt();\n b[i] = in.nextInt();\n c[i] = in.nextInt();\n d[i] = in.nextInt();\n e[i] = in.nextInt();\n }\n\n Set bad = new HashSet<>();\n\n for(int i = 1; i <= n; i++) {\n for(int j = 1; j <= n; j++) {\n for(int k = 1; k <= n; k++)\n {\n if(i == j || j == k || k == i) {\n continue;\n }\n\n long ax = a[j] - a[i];\n long bx = b[j] - b[i];\n long cx = c[j] - c[i];\n long dx = d[j] - d[i];\n long ex = e[j] - e[i];\n\n long ay = a[k] - a[i];\n long by = b[k] - b[i];\n long cy = c[k] - c[i];\n long dy = d[k] - d[i];\n long ey = e[k] - e[i];\n\n double val = ax * ay + bx * by + cx * cy + dx * dy + ex * ey;\n long m1 = ax * ax + bx * bx + cx * cx + dx * dx + ex * ex;\n long m2 = ay * ay + by * by + cy * cy + dy * dy + ey * ey;\n val = val / Math.sqrt(m1);\n val = val / Math.sqrt(m2);\n if(Math.toDegrees(Math.acos(val)) + 0.000000001 < 90) {\n bad.add(i);\n }\n }\n }\n }\n\n out.println(n - bad.size());\n\n for(int i = 1; i <= n; i++) {\n if(!bad.contains(i)) {\n out.println(i);\n }\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1b243572f95de3494421972459417a39", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class EntranceFinder{\n\t\n\tpublic static void main(String args[])\n\tScanner in = new Scanner(System.in);\n\tint n = in.nextInt();\n\tint a = in.nextInt();\n\tint b = in.nextInt();\n\tin.close();\n\tint curr; \n\tint count; \n\n\tint core = n-a;\n\tif(n + b > n){\n\t\tint answer = n % b;\n\t}\n\tif(n + b <= 0){\n\t\tfor(int i = b; i>=0; i--){\n\t\t\tcount = a;\n\t\t\tcount -= 1;\n\t\t\tif(count = 0){\n\t\t\t\tcount = n;\n\t\t\t}\n\t\t}\n\t\tanswer = count;\n\t}\n\tif(b=0){\n\t\tanswer = a;\n\t}\n\tSystem.out.println(answer);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a4c8c6a9d52a3836247783ecf2a760b0", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main {\n\t \n\tpublic static void main(String[] args)throws IOException\n\t{\n\t int n=stdIO.readInt(),a=stdIO.readInt(),b=stdIO.readInt();\n\t if(b<0)b=n+b;\n\t int ans=(a+b)%n;\n\t if(ans=0)ans=n;\n\t stdIO.print(ans);\n\t}\n\n}\nclass stdIO {\n\t private static InputStream in=System.in; \n\t private static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t private static byte[] buffer=new byte[1024];\n\t private static int len=0,byteread=0;\n\t public static int read() throws IOException\n\t {\n\t\t if(len>=byteread)\n\t\t {\n\t\t\t len=0;\n\t\t\t byteread=in.read(buffer);\n\t\t\t if(byteread<=0)return -1;\n\t\t\t \n\t\t }\n\t\t return buffer[len++];\n\t }\n\t public static int readInt()throws IOException\n\t {\n\t\t int ret=0;\n\t\t boolean flag=false;\n\t\t int c=0;\n\t\t c=read();\n\t\t while(!(c>31&&c<127))c=read();\n\t\t if(c=='-'){flag=true;c=read();}\n\t\t do{\n\t\t\t \n\t\t\t if ((c < '0') || (c > '9')) {\n\t throw new InputMismatchException();\n\t }\n\t\t\t ret=ret*10+c-'0';\n\t\t\t c=read();\n\t\t\t}while(isNumber(c));//System.out.println(ret);}\n\t\t return flag?-ret:ret;\n\t\t \n\t }\n\t public static long readLong()throws IOException\n\t {\n\t\t long ret=0;\n\t\t boolean flag=false;\n\t\t int c=0;\n\t\t c=read();\n\t\t while(!(isNumber(c)||c=='-'))c=read();\n\t\t if(c=='-'){flag=true;c=read();}\n\t\t do{\n\t\t\t \n\t\t\t \n\t\t\t ret=ret*10+c-'0';\n\t\t\t c=read();\n\t\t\t}while(isNumber(c));//System.out.println(ret);}\n\t\t return flag?-ret:ret;\n\t\t \n\t }\n\t \n\t public static double readDouble()throws IOException\n\t {\n\t\t int c=read();\n\t boolean flag=false;\n\t while (!isChar(c)) {\n\t c=read();\n\t }\n\t if (c=='-') {\n\t flag=true;\n\t c = read();\n\t }\n\t boolean f=false;\n\t double mul=1;\n\t double ret=0;\n\t do {\n\t if ((c =='e')||(c=='E')) {\n\t return flag?-ret *Math.pow(10,readInt()):ret *Math.pow(10,readInt());\n\t }\n\t if ((c<'0')||(c>'9')) {\n\t if ((c == '.')&&!f) {\n\t f=true;\n\t c=read();\n\t continue;\n\t }\n\t throw new InputMismatchException();\n\t }\n\t if (f) {\n\t mul/=10;\n\t ret+=(c-'0')*mul;\n\t c=read();\n\t } else {\n\t ret*= 10;\n\t ret+= (c - '0');\n\t c = read();\n\t }\n\t } while (isNumber(c)||c=='e'||c=='E'||c=='.');\n\t return flag?-ret:ret;\n\t }\n\t private static boolean isNumber(int c)\n\t {\n\t\t return (c>='0'&&c<='9');\n\t }\n\t private static boolean isChar(int c)\n\t {\n\t\t return (c>=33&&c<=126);\n\t }\n\t public static String readString() throws IOException\n\t {\n\t\t StringBuilder sb=new StringBuilder();\n\t\t int c=read();\n\t\t while(!isChar(c))c=read();\n\t\t \n\t\t while(isChar(c))\n\t\t {\n\t\t\t sb.appendCodePoint(c);\n\t\t\t c=read();\n\t\t }\n\t\t return sb.toString();\n\t }\n\t public static String readLine()throws IOException\n\t {\n\t\t StringBuilder sb=new StringBuilder();\n\t\t int c=read();\n\t\t while(isChar(c)||c==' ')\n\t\t {\n\t\t\t sb.appendCodePoint(c);\n\t\t\t c=read();\n\t\t\t if(c==10)break;\n\t\t }\n\t\t return sb.toString();\n\t }\n\t public static void print(Object...objects)\n\t {\n\t\t int l=objects.length;\n\t\t for(int i=0;i 0)\n{\n if(a + b < n)\n {\n System.out.println(a + b);\n }\n else\n {\n int h = 0;\n while(f != b)\n {\n f++;\n if(f % n == 0)\n {\n h++;\n }\n }\n System.out.println((a + b) - (n * h));\n }\n}\nelse if(b < 0)\n{\n b = Math.abs(b);\n if(Math.abs(a - b) < n)\n {\n System.out.println(Math.abs((a - b));\n }\n else\n {\n int p = 0;\n b = Math.abs(b);\n int l = 0;\n while(p != b)\n {\n p++;\n if(p % n == 0)\n {\n l++;\n }\n }\n System.out.println(Math.abs(Math.abs(((a - 1) - b) - (n * l))));\n }\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "758c52d2edb23d36b2f3cf879445f391", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "\nimport static java.lang.Math.*;\nimport static java.util.Arrays.sort;\nimport java.util.*;\nimport static javax.swing.text.StyleConstants.*;\n\npublic class JavaApplication1 {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n, a,b1, intr;\n n= sc.nextInt();\n a=sc.nextInt();\n b1 = sc.nextInt();\n if (b1>n){\n intr = (int)(b1-(floor(b1/n)*n)+a);\n }else{\n intr = abs(a+b1);\n if (int==0)\n intr=1;\n }\n System.out.println(intr);\n}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1ed01fb4eb06621985bb45efc0355d63", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s=new Scanner(System.in);\n\t\tString first=s.next();\n\t\tString last=s.next();\n\t\tString pass=\"\";\n\t\tchar cc=first.charAt(0);\n\t\tpass=pass+cc;\n\t\tString ros=first.substring(1);\n\t\tfor(int i=0;iros.charAt(0))\n\t\t\t{\n\t\t\t\tpass=pass+ros.charAt(0);\n\t\t\t\tif(ros.length()>1)\n\t\t\t\t{\n\t\t\t\t\tros=ros.substring(1);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tpass=pass+last.charAt(0);\n\t\tSystem.out.println(pass);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c220226ca62d79099deea85a4cc2ad1a", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class Name\n{\n public String lastname;\n public String firstname;\n\n public Name(String name) {\n int i = name.indexOf(\" \");\n this.firstname = name.substring(0, i);\n this.lastname = name.substring(i + 1); \n }\n \n public String Generate()\n {\n \n String s1 = new String();\n int n = firstname.length();\n for(int i = 1; i < n; i++)\n {\n if(firstname.charAt(i) < lastname.charAt(0) )\n {\n s1 += firstname.charAt(i);\n }\n else\n {\n break;\n }\n }\n return firstname.charAt(0) + s1 + lastname.charAt(0);\n \n }\n \n}\npublic class Main {\n\n public static void main(String[] args) {\n Scanner ip = new Scanner(System.in);\n String s = ip.nextLine();\n Name name = new Name(s);\n System.out.println(name.Generate());\n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3c0ff926f71ffd92d76c8231e61c985e", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class codeforces {\n\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n \n String input = in.next();\n \n String[] fullName = input.split(\" \");\n String result = fullName[0].charAt(0);\n \n char first = fullName[0].charAt(0) , second = fullName[1].charAt(0) ;\n \n for(int i=1;i {\n\t\tint a, b;\n\n\t\tpublic sort(int a, int b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\tpublic int compareTo(sort arg0) {\n\t\t\tif (this.a == arg0.a)\n\t\t\t\treturn (this.b - arg0.b);\n\t\t\treturn -(this.a - arg0.a);\n\t\t}\n\t}\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// gfile();\n\t\tint n = nextInt();\n\t\tint a[] = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tif (n == 0) {\n\t\t\tpw.println(\"YES\");\n\t\t\tpw.println(1);\n\t\t\tpw.println(1);\n\t\t\tpw.println(3);\n\t\t\tpw.println(3);\n\t\t\tpw.close();\n\t\t\treturn;\n\t\t}\n\t\tint inf = 1000000;\n\t\tif (n == 1) {\n\t\t\tif(a[1]*3>=1&&a[1]*3<=inf){\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(a[1]);\n\t\t\t\tpw.println(a[1]);\n\t\t\t\tpw.println(3*a[1]);\n\t\t\t\tpw.println(3*a[1]);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (n == 2) {\n\t\t\t// x1,x2\n\t\t\tboolean ok = false;\n\t\t\tint x1 = a[1], x2 = a[2], x3 = inf, x4 = inf;\n\t\t\tfor (int i = 1; i <= inf; i++) {\n\t\t\t\tif (i == 4 * x1 - x2) {\n\t\t\t\t\tx3 = 4 * x1 - x2;\n\t\t\t\t\tx4 = 3 * x1;\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x3);\n\t\t\t\tpw.println(x4);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x2,x1\n\t\t\tx2 = a[1];\n\t\t\tx1 = a[2];\n\t\t\tfor (int i = 1; i <= inf; i++) {\n\t\t\t\tif (i == 4 * x1 - x2) {\n\t\t\t\t\tx3 = 4 * x1 - x2;\n\t\t\t\t\tx4 = 3 * x1;\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x3);\n\t\t\t\tpw.println(x4);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x1,x3\n\t\t\tx1 = a[1];\n\t\t\tx3 = a[2];\n\t\t\tfor (int i = 1; i <= inf; i++) {\n\t\t\t\tif (i == 4 * x1 - x3) {\n\t\t\t\t\tx2 = 4 * x1 - x3;\n\t\t\t\t\tx4 = 3 * x1;\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x2);\n\t\t\t\tpw.println(x4);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x3,x1\n\t\t\tx3 = a[1];\n\t\t\tx1 = a[2];\n\t\t\tfor (int i = 1; i <= inf; i++) {\n\t\t\t\tif (i == 4 * x1 - x3) {\n\t\t\t\t\tx2 = 4 * x1 - x3;\n\t\t\t\t\tx4 = 3 * x1;\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x2);\n\t\t\t\tpw.println(x4);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x1,x4;\n\t\t\tx1 = a[1];\n\t\t\tx4 = a[2];\n\t\t\tif (3 * x1 == x4) {\n\t\t\t\tint p = 4 * x1;\n\t\t\t\tx2 = p / 2;\n\t\t\t\tx3 = p - x2;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x2);\n\t\t\t\tpw.println(x3);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x4,x1;\n\t\t\tx4 = a[1];\n\t\t\tx1 = a[2];\n\t\t\tif (3 * x1 == x4) {\n\t\t\t\tint p = 4 * x1;\n\t\t\t\tx2 = p / 2;\n\t\t\t\tx3 = p - x2;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x2);\n\t\t\t\tpw.println(x3);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x2,x3\n\t\t\tx2 = a[1];\n\t\t\tx3 = a[2];\n\t\t\tif ((x2 + x3) % 4 == 0) {\n\t\t\t\tx1 = (x2 + x3) / 4;\n\t\t\t\tx4 = 3 * x1;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x1);\n\t\t\t\tpw.println(x4);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x2,x4\n\t\t\tx2 = a[1];\n\t\t\tx4 = a[2];\n\t\t\tif (x4 % 3 == 0) {\n\t\t\t\tx1 = x4 / 3;\n\t\t\t\tx3 = 4 * x1 - x2;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x1);\n\t\t\t\tpw.println(x3);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x4,x2\n\t\t\tx4 = a[1];\n\t\t\tx2 = a[2];\n\t\t\tif (x4 % 3 == 0) {\n\t\t\t\tx1 = x4 / 3;\n\t\t\t\tx3 = 4 * x1 - x2;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x1);\n\t\t\t\tpw.println(x3);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x3,x4\n\t\t\tx3 = a[1];\n\t\t\tx4 = a[2];\n\t\t\tif (x4 % 3 == 0) {\n\t\t\t\tx1 = x4 / 3;\n\t\t\t\tx2 = 4 * x1 - x3;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x1);\n\t\t\t\tpw.println(x2);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// x4,x3\n\t\t\tx4 = a[1];\n\t\t\tx3 = a[2];\n\t\t\tif (x4 % 3 == 0) {\n\t\t\t\tx1 = x4 / 3;\n\t\t\t\tx2 = 4 * x1 - x3;\n\t\t\t\tok = true;\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x1);\n\t\t\t\tpw.println(x2);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (n == 3) {\n\t\t\t// x4\n\t\t\tArrays.sort(a, 1, n + 1);\n\t\t\tint x1 = inf, x2 = inf, x3 = inf, x4 = inf;\n\t\t\tif (a[2] + a[3] == 4 * a[1]) {\n\t\t\t\tx1 = a[1];\n\t\t\t\tx2 = a[2];\n\t\t\t\tx3 = a[3];\n\t\t\t\tx4 = a[1] * 3;\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.println(x4);\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (n == 4) {\n\t\t\tArrays.sort(a, 1, n + 1);\n\t\t\tif (a[1] * 3 == a[4] && a[2] + a[3] == 4 * a[1]) {\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tpw.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tpw.println(\"NO\");\n\t\tpw.close();\n\t}\n\n\tprivate static void gfile() throws IOException {\n\t\tbr = new BufferedReader(new FileReader(new File(\"input.txt\")));\n\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(new File(\n\t\t\t\t\"output.txt\"))));\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e3b1d0707d9d231eb7c49e6c230e2e8c", "src_uid": "230e613abf0f6a768829cbc1f1a09219", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tReader.init(System.in);\n\n\t\tint n = Reader.nextInt();\n\n\t\tif (n == 1) {\n\t\t\tint x1 = Reader.nextInt();\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(x1 + \"\\n\" + 3 * x1 + \"\\n\" + 3 * x1);\n\t\t} else if (n == 2) {\n\t\t\tint x1 = Reader.nextInt();\n\t\t\tint x2 = Reader.nextInt();\n\n\t\t\tint a = 4 * x1 - x2;\n\t\t\tint b = 3 * x1;\n\t\t\tif (x1 <= x2 && x2 <= a && a <= b) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tSystem.out.println( a + \"\\n\" + b);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t} else if (n == 3) {\n\t\t\tint x1 = Reader.nextInt();\n\t\t\tint x2 = Reader.nextInt();\n\t\t\tint a = Reader.nextInt();\n\t\t\tint b = x2 + a - x1;\n\n\t\t\tif ((x1+b)==(b-x1)*2&&x1 <= x2 && x2 <= a && a <= b) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tSystem.out.println( b);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t} else {\n\t\t\tint x1 = Reader.nextInt();\n\t\t\tint x2 = Reader.nextInt();\n\t\t\tint a = Reader.nextInt();\n\t\t\tint b = Reader.nextInt();\n\t\t\tif ((x1+b)==(b-x1)*2&&x1 + b == x2 + a && x1 <= x2 && x2 <= a && a <= b) {\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\nclass Reader {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\n\t/** call this method to initialize reader for InputStream */\n\tstatic void init(InputStream input) {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\t/** get next word */\n\tstatic String next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\t// TODO add check for eof if necessary\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ac2b942615221cbd0dfaa46e8f506a2d", "src_uid": "230e613abf0f6a768829cbc1f1a09219", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws IOException{\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(in.readLine());\n int[] a = new int[n];\n for(int i=0;i3*a[0]) System.out.println(\"NO\");\n else{\n if(a[1]==3*a[0]){\n System.out.println(\"YES\");\n System.out.println(a[0]);\n System.out.println(a[1]);\n }\n else{\n System.out.println(\"YES\");\n System.out.println(4*a[0]-a[1]);\n System.out.println(3*a[0]);\n }\n }\n }\n else if(n==3){\n if(a[3]%3==0&&4*(a[3]/3)==a[1]+a[2]){\n System.out.println(\"YES\");\n System.out.println(a[3]/3);\n }\n else if(a[2]<=3*a[0]){\n if(a[2]==3*a[0]){\n System.out.println(\"YES\");\n System.out.println(4*a[0]-a[1]);\n }\n else{\n if(4*a[0]==a[1]+a[2]){\n System.out.println(\"YES\");\n System.out.println(3*a[0]);\n }\n else{\n System.out.println(\"NO\");\n }\n }\n }\n else{\n System.out.println(\"NO\");\n }\n }\n else{\n if(a[3]==3*a[0]&&a[3]+a[0]==a[1]+a[2]){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cb6ee481ea41cbaf4c3bb0ea2be19387", "src_uid": "230e613abf0f6a768829cbc1f1a09219", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class ColorfulStones {\n\tpublic static void main(String args[]){\n\t\tScanner s=new Scanner(System.in);\n\t\tString a=s.next();\n\t\tString t=s.next();\n\t\tint i=0,j=0,r=0;\n\t\tr=t.length();\n\t\twhile(r--){\n\t\t\tif(a.charAt(i)==t.charAt(j))\n\t\t\t\ti++;\n\t\t}\n\t\tSystem.out.println(i+1);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "97fb329295f10fe186cc172b692505f1", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\tScanner sc = new Scanner(System.in);\n\tString S = sc.nextLine();\n\tString T = sc.nextLine();\n\tint counter = 1;\n\tint j =0;\n\tfor(int i=0; i < T.length();i++){\n\tif(S.charAt(j) == T.charAt(i)){\n\t\tcounter+=1;\n\t\tj++;\n\t} \n\t}\n\tSystem.out.println(counter);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0dcc50f5c84acf8dc9bf5d9331c916da", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0} {"lang": "Java 8", "source_code": " import java.util.*;\n import java.lang.*;\n public class night\n {\n public static void main(String args[])\n {\n Scanner sc= new Scanner(System.in);\n String s=sc.nextLine();\n String t=sc.nextLine();\n \n for(int j=0,i=0;i num = new HashMap();\n for (int i = 1; i <= 10; i++) {\n num.put(next(), i - 1);\n }\n for (int i = 0; i < s.length(); i += 10) {\n out.print(num.get(s.substring(i, i + 10)));\n }\n out.close();\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fd5e99020aab967188b8f5ddccc968a6", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9", "difficulty": 900.0} {"lang": "Java 6", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\npackage codeforces;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author Familia\n */\npublic class Main\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 Scanner in=new Scanner(System.in);\n int cont[]=new int[10];\n String bin[]=new String[10];\n String cb=in.next();\n for(int i=0;i<10;i++)\n bin[i]=in.next();\n int a=0,b=10;\n while(b<=80)\n {\n for(int j=0;j<10;j++)\n if(cb.substring(a, b).equals(bin[j]))\n {\n \n System.out.print(j);\n break;\n }\n a=a+10;b=b+10;\n }\n \n\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cb4fd43db2bc4e0da17953d82d1b1248", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class pass1\n{\npublic static void main(String args[])throws IOException\n{\nInputStreamReader isr=new InputStreamReader(System.in);\nBufferedReader br=new BufferedReader(isr);\nString pass=br.readLine();\nString s1,a[]=new int[10],out=\"\";\nfor(i=0;i<10;i++)\na[i]=br.readLine();\nfor(i=0;i<80;i+=10)\n{\ns1=pass.substring(i,i+10);\nfor(j=0;j<10;j++)\n{\nif(s1.equals(a[j])==true)\n{out=out+Integer.toString(j);\nbreak;}}\n}\nSystem.out.println(out);\n}}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5289e72fa4f72a7dcd03a41a95b606ca", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class restorePassword {\n\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner (System.in);\n\t\t\n\t\tString seenBinarys = input.nextLine();\n\t\tString [] orderBinarysArr = new String [10];\n\t\tString [] seenBinarysArr = new String [8];\n\t\tfor (int i = 0 ; i <10;i++){\n\t\t\torderBinarysArr[i] =input.nextLine();\n\t\t}\n\t\t\n\t\tfor (int i = 0 , j = 10,counter=0;counter<8;i+=10,j+=10,counter++){\n\t\t\tseenBinarysArr[counter] = seenBinarys.substring(i,j);\n\t\t}\n\t\t\n\t\tfor (int i = 0 ; i<8;i++){\n\t\t\tfor(int j = 0 ; j<10;j++){\n\t\t\t\tif (seenBinarysArr[i].equals(orderBinarysArr[j])){\n\t\t\t\t\tSystem.out.print(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c04b2ca942f9266e237cd0aa9f125ff5", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author phantom11\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n boolean possible;\n int K;\n long stepsPossible = new long[100];\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long x = in.nextInt(), y = in.nextInt();\n long steps[] = new long[100];\n steps[0] = x;\n\n recur(x, y, steps, 1);\n if (possible) {\n out.printLine(\"YES\");\n out.printLine(K);\n for (int i = 0; i < K; i++) {\n out.print(stepsPossible[i] + \" \");\n }\n } else {\n out.printLine(\"NO\");\n }\n }\n\n public void recur(long x, long y, long steps[], int k) {\n if (x == y) {\n possible = true;\n for (int i = 0; i < steps.length; i++) {\n stepsPossible[i] = steps[i];\n }\n K = k;\n return;\n }\n if (x > y || possible) return;\n steps[k] = 2 * x;\n recur(2 * x, y, steps, k + 1);\n steps[k] = 10 * x + 1;\n recur(10 * x + 1, y, steps, k + 1);\n }\n\n }\n\n static class InputReader {\n BufferedReader in;\n StringTokenizer tokenizer = null;\n\n public InputReader(InputStream inputStream) {\n in = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String next() {\n try {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n } catch (IOException e) {\n return null;\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3957d3d5c80eef682b0f3b62ddc03de", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Main{\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 ArrayList arr=new ArrayList<>();\n arr.add(b);\n while(a y || possible) return;\n steps[k] = 2 * x;\n recur(2 * x, y, steps, k + 1);\n steps[k] = 10 * x + 1;\n recur(10 * x + 1, y, steps, k + 1);\n }\n\n }\n\n static class InputReader {\n BufferedReader in;\n StringTokenizer tokenizer = null;\n\n public InputReader(InputStream inputStream) {\n in = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String next() {\n try {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n } catch (IOException e) {\n return null;\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da1f3467a63b7047b882221a21bdd054", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class transformation { //\u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435: \u0438\u0437 \u0410 \u0432 \u0411 727\u0410\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n int num1 = scan.nextInt();\n int num2 = scan.nextInt(),k=num2;\n ArrayList arr = new ArrayList<>();\n while(num2>num1){\n if(num2%2==0){\n num2=num2/2;\n arr.add(num2);\n }\n else if(num2%10==1){\n num2=num2/10;\n arr.add(num2);\n }\n else\n break;\n }\n if(num1==num2){\n System.out.println(\"YES\");\n System.out.println(arr.size()+1);\n for(int i=arr.size()-1;i>=0;i--){\n System.out.print(arr.get(i)+\" \");\n }\n System.out.print(k);\n }\n else\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2b10131ce3a7b44264deb309aaac8da0", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Monitors {\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int a = s.nextInt();\n int b = s.nextInt();\n int x = s.nextInt();\n int y = s.nextInt();\n int resX = count(a, b, x, y, 0, a - (a % x));\n int resY = resX / x * y;\n System.out.println(resX + \" \" + resY);\n }\n\n static int count(int a, int b, int x, int y, int l, int r) {\n if (r == 0) {\n return 0;\n } else if (l > r) {\n return 0;\n } else {\n int mid = (l + r) / 2;\n mid -= mid % x;\n mid += x;\n int p = mid / x * y;\n if (p > b) {\n return count(a, b, x, y, l, mid);\n } else {\n return Math.max(mid, count(a, b, x, y, mid + 1, r));\n }\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5440f5da1d877dae0e1312a16b88b10c", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class C {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint m = scan.nextInt();\n\t\tint x = scan.nextInt();\n\t\tint y = scan.nextInt();\n\t\tint g = gcd(x,y);\n\t\tx /= g;\n\t\ty /= g;\n\t\tint min = Math.min(n/x, m/y);\n\t\tSystem.out.println(x*min + \" \" + y*min);\n\t}\n\tstatic int gcd(int a, int b) {\n\t\tint l, s, t;\n\t\tfor (l = Math.max(a, b), s = Math.min(a, b); s > 0;) {\n\t\t\tt = l % s;\n\t\t\ts = l;\n\t\t\tl = t;\n\t\t}\n\t\treturn l;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ead0b8a51f9e694471c1fcf325691cc", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "package first;//\u63d0\u4ea4\u4ee3\u7801\u65f6\uff0c\u6b64\u884c\u8981\u6ce8\u91ca\u6389\nimport java.math.BigDecimal;//\u5c0f\u6570\nimport java.math.BigInteger;//\u6574\u6570\nimport java.util.*;\npublic class Main{\n\tstatic int N =1010;\n\tpublic static void main(String args[]) {\n\t\tScanner cin = new Scanner(System.in);\n\t\tlong x,y,a,b,k,z;\n\t\ta = cin.nextLong();\n\t\tb = cin.nextLong();\n\t\tx = cin.nextLong();\n\t\ty = cin.nextLong();\n\t\tz =Gcd(x,y);\n\t\tk =Math.min(a/x,b/y);\n\t\tif(x >a |y>b)\n\t\t\tSystem.out.println(0+\" \"+0);\n\t\telse\n\t\t\tSystem.out.println(x*k+\" \"+y*k);\n\t}\n\tpublic static long Gcd(long a,long b) {\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn Gcd(b,a%b);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2bc745eda0eb59f2358480fc664a34eb", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "// package Practice;\n\nimport java.util.Scanner;\n\nimport static Practice.CF013A.gcd;\n\npublic class CF016C {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n long a = s.nextLong();\n long b = s.nextLong();\n long x = s.nextLong();\n long y = s.nextLong();\n long gcd = gcd(x,y);\n\n x /= gcd;\n y /= gcd;\n a /= x;\n b /= y;\n\n long min = Math.min(a,b);\n a = min * x;\n b = min * y;\n if(a == 0 || b == 0){\n System.out.println(\"0 0\");\n }else{\n System.out.println(a + \" \" + b);\n }\n }\n\n private static long gcd(long a, long b) {\n if(b == 0) return a;\n return gcd(b, a%b);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3d5cada644cfc2d0192ba28375340458", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n \npublic class Main{\n \nstatic PrintWriter out;\nstatic InputReader ir;\nstatic final int INF=Integer.MAX_VALUE;\nstatic final long LINF=Long.MAX_VALUE;\n \nstatic void solve(){\n char[][] map=ir.nextCharMap(8,8);\n int a;\n int b;\n outer:\n for(int i=0;i<8;i++){\n for(int j=0;j<8;j++){\n if(map[i][j]=='W'){\n a=i;\n break outer;\n }\n }\n }\n out;\n for(int i=0;i<8;i++){\n for(int j=0;j<8;j++){\n if(map[7-i][j]=='W'){\n b=i;\n break out;\n }\n }\n }\n out.println(a<(7-b)?\"A\":\"B\");\n}\n\npublic static void main(String[] args) throws Exception{\n ir=new InputReader(System.in);\n out=new PrintWriter(System.out);\n solve();\n out.flush();\n}\n\nstatic class InputReader {\n private InputStream in;\n private byte[] buffer=new byte[1024];\n private int curbuf;\n private int lenbuf;\n\n public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}\n \n public boolean hasNextByte() {\n if(curbuf>=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i= 0; k--) {\n\t\t\t\t\t\tif (word[k].charAt(j) == 'B') {\n\t\t\t\t\t\t\tblocked = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tca++;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (blocked) {\n//\t\t\t\t\t\tSystem.out.println(\"BLOCK W\" + i);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (ca < cA) cA = ca;\n//\t\t\t\t\tSystem.out.println(ca);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint cB = 7;\n\t\tfor (int i = 0; i < n-1; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (word[i].charAt(j) == 'B') {\n\t\t\t\t\tint cb = 0;\n\t\t\t\t\tboolean blocked = false;\n\t\t\t\t\tfor (int k = i + 1; k < n; k++) {\n\t\t\t\t\t\tif (word[k].charAt(j) == 'W') {\n\t\t\t\t\t\t\tblocked = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcb++;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (blocked) {\n//\t\t\t\t\t\tSystem.out.println(\"BLOCK B\" + i);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (cb < cB) cB = cb;\n//\t\t\t\t\tSystem.out.println(cb);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n//\t\tSystem.out.println(\"A \" + cA + \";\" + \" B \" + cB);\n\t\tSystem.out.println(cA =< cB ? \"A\" : \"B\");\n\t\t\n\t}\n/*\n........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n\n * \n \n..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n */\n\tstatic int gcd(int p, int q) {\n\t\tif (q == 0)\n\t\t\treturn p;\n\t\telse\n\t\t\treturn gcd(q, p % q);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3a557e1da37eebe0f0a752ff59cdb56", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package G\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class PawnChess {\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader (new InputStreamReader(System.in));\n \n// Scanner sc = new Scanner(System.in);\n\n // ArrayList A = new ArrayList();\n // ArrayList B = new ArrayList();\n\n int white = 0;\n int black = 0;\n // 1 -> W\n // 2 -> B\n // 0 -> .\n\n int grid[][] = new int[8][8];\n\n int minA = Integer.MAX_VALUE;\n int minB = Integer.MIN_VALUE;\n\n for (int r = 0; r < 8; r++) {\n String row = br.readLine();\n for (int c = 0; c < 8; c++) {\n if (row.charAt(c) == 'W') \n grid[r][c] = 1;\n if (row.charAt(c) == 'B')\n grid[r][c] = 2;\n \n }\n }\n\n for (int i = 0; i < 8; i++) {\n for (int j = 0; j < 8; j++) {\n if (grid[i][j] == 1) {\n boolean ok = true;\n for (int j2 = i-1; j2 >= 0; j2--) {\n if (grid[j2][j] == 2 || grid[j2][j] == 1) {\n ok = false;\n break;\n }\n }\n if (ok)\n minA = Math.min(minA, i);\n }\n if (grid[i][j] == 2) {\n\n boolean ok = true;\n for (int j2 = i+1; j2 < 8; j2++) {\n if (grid[j2][j] == 1 || grid[j2][j] == 2) {\n ok = false;\n break;\n }\n }\n if (ok)\n minB = Math.max(minB, i);\n\n }\n }\n }\n System.out.println(minA + \" \" + minB);\n if (minA <= (7-minB))\n System.out.println(\"A\");\n else\n System.out.println(\"B\");\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "47a4464b5432d829ca93d125ba9001fd", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n/*\n * \tHeart beats fast\n * \t\tColors and promises\n * \t\t\tHow to be brave\n * \t\t\t\tHow can I love when I am afraid to fall...\n */\n//read the question correctly (is y a vowel? what are the exact constraints?)\n//look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tdouble a=ni(),b=ni(),m=ni();\n\t\tdouble x=ni(),y=ni(),z=ni();\n\t\tdouble time=-m/y;\n\t\tdouble time1=time+a/(2*x),time2=time;\n\t\twhile(time1>=(2*a)/x)\n\t\t\ttime1-=(2*a)/x;\n\t\twhile(time2>=(2*b)/z)\n\t\t\ttime2-=(2*b)/z;\n\t\tdouble fa=time1*x;\n\t\tdouble fb=time2*z;\n\t\tif(fa>=a)\n\t\t\tfa=2*a-fa;\n\t\tif(fb>=b)\n\t\t\tfb=2*b-fb;\n\t\tpr(fa+\" \"+fb);\n\t\tSystem.out.print(output);\n\t}\n\t\n\t\n\t\n\t///////////////////////////////////////////\n\t///////////////////////////////////////////\n\t///template from here\n\tstatic interface combiner\n\t{\n\t\tpublic int combine(int a, int b);\n\t}\n\tstatic final int mod=1000000007;\n\tstatic final double eps=1e-8;\n\tstatic final long inf=100000000000000000L;\n\tstatic Reader in=new Reader();\n\tstatic StringBuilder output=new StringBuilder();\n\tstatic Random rn=new Random();\n\tpublic static void sort(int[]a)\n\t{\n\t\tint te;\n\t\tfor(int i=0; i()\n\t\t{\n\t\t\tpublic int compare(int[]a,int[]b)\n\t\t\t{\n\t\t\t\tif(a[0]>b[0])\n\t\t\t\t\treturn 1;\n\t\t\t\tif(b[0]>a[0])\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\tstatic int lowerbound(int[]a, int key)\n\t{\n\t\t/*\n\t\t * returns index of smallest element larger than equal to given element between indices l and r inclusive\n\t\t */\n\t\tint low=0,high=a.length-1,mid=(low+high)/2;\n\t\twhile(low= key)\n\t\t\t\thigh=mid;\n\t\t\telse\n\t\t\t\tlow=mid+1;\n\t\t\tmid=(low+high)/2;\n\t\t}\n\t\treturn mid;\n\t}\n\tstatic int upperbound(int[]a, int key)\n\t{\n\t\t/*\n\t\t * returns index of largest element smaller than equal to given element\n\t\t */\n\t\tint low=0,high=a.length-1,mid=(low+high+1)/2;\n\t\twhile(low= key)\n\t\t\t\thigh=mid;\n\t\t\telse\n\t\t\t\tlow=mid+1;\n\t\t\tmid=(low+high)/2;\n\t\t}\n\t\treturn mid;\n\t}\n\tstatic int upperbound(int[]a, int l, int r, int key)\n\t{\n\t\t/*\n\t\t * returns index of largest element smaller than equal to given element\n\t\t */\n\t\tint low=l,high=r,mid=(low+high+1)/2;\n\t\twhile(low()\n\t\t\t\t{\n\t\t\t@Override\n\t\t\tpublic int compare(pair a,pair b)\n\t\t\t{\n\t\t\t\tif(a.a>b.a)\n\t\t\t\t\treturn 1;\n\t\t\t\tif(b.a>a.a)\n\t\t\t\treturn -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\t});\n\t}\n\tstatic int log2n(long a)\n\t{\n\t\tint te=0;\n\t\twhile(a>0)\n\t\t{\n\t\t\ta>>=1;\n\t\t\t++te;\n\t\t}\n\t\treturn te;\n\t}\n\tstatic class iter\n\t{\n\t\tvecti a;\n\t\tint zin=0;\n\t\titer(vecti b)\n\t\t{\n\t\t\ta=b;\n\t\t}\n\t\tpublic boolean hasNext()\n\t\t{\n\t\t\tif(a.size>zin)\n\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\t\tpublic int next()\n\t\t{\n\t\t\treturn a.a[zin++];\n\t\t}\n\t\tpublic void previous()\n\t\t{\n\t\t\tzin--;\n\t\t}\n\t}\n\tstatic class vecti\n\t{\n\t\tint a[],size;\n\t\tvecti()\n\t\t{\n\t\t\ta=new int[10];\n\t\t\tsize=0;\n\t\t}\n\t\tvecti(int n)\n\t\t{\n\t\t\ta=new int[n];\n\t\t\tsize=0;\n\t\t}\n\t\tpublic void add(int b)\n\t\t{\n\t\t\tif(++size==a.length)\n\t\t\t\ta=Arrays.copyOf(a, 2*size);\n\t\t\ta[size-1]=b;\n\t\t}\n\t\tpublic void sort()\n\t\t{\n\t\t\tArrays.sort(a, 0, size);\n\t\t}\n\t\tpublic void sort(int l, int r)\n\t\t{\n\t\t\tArrays.sort(a, l, r);\n\t\t}\n\t\tpublic iter iterator()\n\t\t{\n\t\t\treturn new iter(this);\n\t\t}\n\t}\n\tstatic class lter\n\t{\n\t\tvectl a;\n\t\tint curi=0;\n\t\tlter(vectl b)\n\t\t{\n\t\t\ta=b;\n\t\t}\n\t\tpublic boolean hasNext()\n\t\t{\n\t\t\tif(a.size>curi)\n\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\t\tpublic long next()\n\t\t{\n\t\t\treturn a.a[curi++];\n\t\t}\n\t\tpublic long prev()\n\t\t{\n\t\t\treturn a.a[--curi];\n\t\t}\n\t}\n\tstatic class vectl\n\t{\n\t\tlong a[];\n\t\tint size;\n\t\tvectl()\n\t\t{\n\t\t\ta=new long[10];\n\t\t\tsize=0;\n\t\t}\n\t\tvectl(int n)\n\t\t{\n\t\t\ta=new long[n];\n\t\t\tsize=0;\n\t\t}\n\t\tpublic void add(long b)\n\t\t{\n\t\t\tif(++size==a.length)\n\t\t\t\ta=Arrays.copyOf(a, 2*size);\n\t\t\ta[size-1]=b;\n\t\t}\n\t\tpublic void sort()\n\t\t{\n\t\t\tArrays.sort(a, 0, size);\n\t\t}\n\t\tpublic void sort(int l, int r)\n\t\t{\n\t\t\tArrays.sort(a, l, r);\n\t\t}\n\t\tpublic lter iterator()\n\t\t{\n\t\t\treturn new lter(this);\n\t\t}\n\t}\n\tstatic class dter\n\t{\n\t\tvectd a;\n\t\tint curi=0;\n\t\tdter(vectd b)\n\t\t{\n\t\t\ta=b;\n\t\t}\n\t\tpublic boolean hasNext()\n\t\t{\n\t\t\tif(a.size>curi)\n\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\t\tpublic double next()\n\t\t{\n\t\t\treturn a.a[curi++];\n\t\t}\n\t\tpublic double prev()\n\t\t{\n\t\t\treturn a.a[--curi];\n\t\t}\n\t}\n\tstatic class vectd\n\t{\n\t\tdouble a[];\n\t\tint size;\n\t\tvectd()\n\t\t{\n\t\t\ta=new double[10];\n\t\t\tsize=0;\n\t\t}\n\t\tvectd(int n)\n\t\t{\n\t\t\ta=new double[n];\n\t\t\tsize=0;\n\t\t}\n\t\tpublic void add(double b)\n\t\t{\n\t\t\tif(++size==a.length)\n\t\t\t\ta=Arrays.copyOf(a, 2*size);\n\t\t\ta[size-1]=b;\n\t\t}\n\t\tpublic void sort()\n\t\t{\n\t\t\tArrays.sort(a, 0, size);\n\t\t}\n\t\tpublic void sort(int l, int r)\n\t\t{\n\t\t\tArrays.sort(a, l, r);\n\t\t}\n\t\tpublic dter iterator()\n\t\t{\n\t\t\treturn new dter(this);\n\t\t}\n\t}\n\t//output functions////////////////\n\tstatic void pr(Object a){output.append(a+\"\\n\");}\n\tstatic void pr(){output.append(\"\\n\");}\n\tstatic void p(Object a){output.append(a);}\n\tstatic void pra(int[]a){for(int i:a)output.append(i+\" \");output.append(\"\\n\");}\n\tstatic void pra(long[]a){for(long i:a)output.append(i+\" \");output.append(\"\\n\");}\n\tstatic void pra(String[]a){for(String i:a)output.append(i+\" \");output.append(\"\\n\");}\n\tstatic void pra(double[]a){for(double i:a)output.append(i+\" \");output.append(\"\\n\");}\n\tstatic void sop(Object a){System.out.println(a);}\n\tstatic void flush(){System.out.println(output);output=new StringBuilder();}\n\t//////////////////////////////////\n\t//input functions/////////////////\n\tstatic int ni(){return in.nextInt();}\n\tstatic long nl(){return Long.parseLong(in.next());}\n\tstatic String ns(){return in.next();}\n\tstatic double nd(){return Double.parseDouble(in.next());}\n\tstatic int[] nia(int n){int a[]=new int[n];for(int i=0; i()\n\t\t{\n\t\t\t@Override\n\t\t\tpublic int compare(int[]a,int[]b)\n\t\t\t{\n\t\t\t\tif(a[0]>b[0])\n\t\t\t\t\treturn 1;\n\t\t\t\telse if(b[0]>a[0])\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\tstatic String pr(String a, long b)\n\t{\n\t\tString c=\"\";\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tc=c.concat(a);\n\t\t\ta=a.concat(a);\n\t\t\tb>>=1;\n\t\t}\n\t\treturn c;\n\t}\n\tstatic long powm(long a, long b, long m)\n\t{\n\t\tlong an=1;\n\t\tlong c=a;\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tan=(an*c)%m;\n\t\t\tc=(c*c)%m;\n\t\t\tb>>=1;\n\t\t}\n\t\treturn an;\n\t}\n\tstatic int gcd(int a, int b)\n\t{\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn gcd(b, a%b);\n\t}\n\tstatic class Reader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public Reader() {\n reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n public double nextDouble() {\n \treturn Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a0ff8bddd6da9372e1cbe69652e86d9e", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\n\npublic class Codeforces_Div2_D implements Runnable{\n\t\n\tprivate void solve() throws IOException {\n\t\tint a = scanner.nextInt(); //100\n\t\tint b = scanner.nextInt();\n\t\tint m = scanner.nextInt();\n\t\tdouble vx = scanner.nextInt(); //100\n\t\tdouble vy = scanner.nextInt();\n\t\tdouble vz = scanner.nextInt();\n\t\tdouble timeMaxY = Math.abs(m/vy);\n\t\tdouble cx = a/2.0;\n\t\tdouble cy = m;\n\t\tdouble cz = 0;\n\t\tcx = emulate(cx,vx,0,a, timeMaxY);\n\t\tcz = emulate(cz,vz,0,b, timeMaxY);\n\t\tout.println(cx +\" \" + cz);\n\t}\n\n\tprivate double emulate(double cx, double vx, double left, double right, double remTimeX) {\n\t\tdouble[] targets = {left, right};\n\t\tdouble timeCycleX = 2.0 * (right - left) / vx;\n\t\tdouble EPS = 1e-9;\n\t\tif (Math.abs(timeCycleX) > EPS){\n\t\t\twhile (remTimeX > timeCycleX){\n\t\t\t\tremTimeX -= timeCycleX;\n\t\t\t}\n\t\t\tint iTarget;\n\t\t\tif (vx > 0){\n\t\t\t\tiTarget = 1;\n\t\t\t}else{\n\t\t\t\tiTarget = 0;\n\t\t\t}\n\t\t\t\n\t\t\twhile (remTimeX > EPS){\n\t\t\t\tdouble distBeforeWall = Math.abs(targets[iTarget] - cx);\n\t\t\t\tdouble timeNeeded = Math.abs(distBeforeWall / vx);\n\t\t\t\tif (remTimeX > timeNeeded + EPS){\n\t\t\t\t\tremTimeX -= timeNeeded;\n\t\t\t\t\tvx = -vx;\n\t\t\t\t\tcx = targets[iTarget];\n\t\t\t\t\tiTarget = 1-iTarget;\n\t\t\t\t}else{\n\t\t\t\t\tcx += vx * remTimeX;\n\t\t\t\t\tremTimeX = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn cx;\n\t}\n\n\t/////////////////////////////////////////////////\n\tfinal int BUF_SIZE = 1024 * 1024 * 8;//important to read long-string tokens properly\n\tfinal int INPUT_BUFFER_SIZE = 1024 * 1024 * 8 ;\n\tfinal int BUF_SIZE_INPUT = 1024;\n\t\n\tfinal int BUF_SIZE_OUT = 1024;\n\t\n\tboolean inputFromFile = false;\n\tString filenamePrefix = \"A-small-attempt0\";\n\tString inSuffix = \".in\";\n\tString outSuffix = \".out\";\n\t\n\t//InputStream bis;\n\t//OutputStream bos;\n\tPrintStream out;\n\tByteScanner scanner;\n\tByteWriter writer;\n\t\n\t@Override\n\tpublic void run() {\n\t\ttry{\n\t\t\tInputStream bis = null;\n\t\t\tOutputStream bos = null;\n\t\t\t//PrintStream out = null;\n\t\t\tif (inputFromFile){\n\t\t\t\tFile baseFile = new File(getClass().getResource(\"/\").getFile());\n\t\t\t\tbis = new BufferedInputStream(\n\t\t\t\t\t\tnew FileInputStream(new File(\n\t\t\t\t\t\t\t\tbaseFile, filenamePrefix+inSuffix)),\n\t\t\t\t\t\t\t\tINPUT_BUFFER_SIZE);\n\t\t\t\tbos = new BufferedOutputStream(\n\t\t\t\t\t\tnew FileOutputStream(\n\t\t\t\t\t\t\t\tnew File(baseFile, filenamePrefix+outSuffix)));\n\t\t\t\tout = new PrintStream(bos);\n\t\t\t}else{\n\t\t\t\tbis = new BufferedInputStream(System.in, INPUT_BUFFER_SIZE);\n\t\t\t\tbos = new BufferedOutputStream(System.out);\n\t\t\t\tout = new PrintStream(bos);\n\t\t\t}\n\t\t\tscanner = new ByteScanner(bis, BUF_SIZE_INPUT, BUF_SIZE);\n\t\t\twriter = new ByteWriter(bos, BUF_SIZE_OUT);\n\t\t\t\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\t\n\tpublic interface Constants{\n\t\tfinal static byte ZERO = '0';//48 or 0x30\n\t\tfinal static byte NINE = '9';\n\t\tfinal static byte SPACEBAR = ' '; //32 or 0x20\n\t\tfinal static byte MINUS = '-'; //45 or 0x2d\t\n\t\t\n\t\tfinal static char FLOAT_POINT = '.';\n\t}\n\t\n\tpublic static class EofException extends IOException{\n\t}\n\t\n\tpublic static class ByteWriter implements Constants {\n\t\t\n\t\tint bufSize = 1024;\n\t\tbyte[] byteBuf = new byte[bufSize];\n\t\tOutputStream os;\n\t\t\n\t\tpublic ByteWriter(OutputStream os, int bufSize){\n\t\t\tthis.os = os;\n\t\t\tthis.bufSize = bufSize;\n\t\t}\n\t\t\n\t\tpublic void writeInt(int num) throws IOException{\n\t int byteWriteOffset = byteBuf.length;\n\t if (num==0){\n\t \t byteBuf[--byteWriteOffset] = ZERO;\n\t }else{\n\t \t int numAbs = Math.abs(num);\n\t \t while (numAbs>0){\n\t \t\t byteBuf[--byteWriteOffset] = (byte)((numAbs % 10) + ZERO);\n\t \t\t numAbs /= 10;\n\t \t }\n\t \t if (num<0)\n\t \t\t byteBuf[--byteWriteOffset] = MINUS;\n\t }\n\t os.write(byteBuf, byteWriteOffset, byteBuf.length - byteWriteOffset);\n\t\t}\n\t\t\n\t\t/**\n\t\t * Please ensure ar.length <= byteBuf.length!\n\t\t * \n\t\t * @param ar\n\t\t * @throws IOException\n\t\t */\n\t\tpublic void writeByteAr(byte[] ar) throws IOException{\n\t\t\tfor (int i = 0; i < ar.length; i++) {\n\t\t\t\tbyteBuf[i] = ar[i];\n\t\t\t}\n\t\t\tos.write(byteBuf,0,ar.length);\n\t\t}\n\t\t\n\t\tpublic void writeSpaceBar() throws IOException{\n\t\t\tbyteBuf[0] = SPACEBAR;\n\t\t\tos.write(byteBuf,0,1);\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static class ByteScanner implements Constants{\n\t\t\n\t\tInputStream is;\n\t\t\n\t\tpublic ByteScanner(InputStream is, int bufSizeInput, int bufSize){\n\t\t\tthis.is = is;\n\t\t\tthis.bufSizeInput = bufSizeInput;\n\t\t\tthis.bufSize = bufSize;\n\t\t\t\n\t\t\tbyteBufInput = new byte[this.bufSizeInput];\n\t\t\tbyteBuf = new byte[this.bufSize];\n\t\t}\n\t\t\n\t\tpublic ByteScanner(byte[] data){\n\t\t\tbyteBufInput = data;\n\t\t\tbufSizeInput = data.length;\n\t\t\tbufSize = data.length;\n\t\t\tbyteBuf = new byte[bufSize];\n\t\t\tbyteRead = data.length;\n\t\t\tbytePos = 0;\n\t\t}\n\t\t\n\t\tprivate int bufSizeInput;\n\t\tprivate int bufSize;\n\t\t\n\t\tbyte[] byteBufInput;\n\t\tbyte by=-1;\n\t\tint byteRead=-1;\n\t\tint bytePos=-1;\n\n\t\tbyte[] byteBuf;\n\t\tint totalBytes;\n\t\t\n\t\tboolean eofMet = false;\n\t\t\n\t\tprivate byte nextByte() throws IOException{\n\t\t\t\n\t\t\tif (bytePos<0 || bytePos>=byteRead){\n\t\t\t\tbyteRead = is==null? -1: is.read(byteBufInput);\n\t\t\t\tbytePos=0;\n\t\t\t\tif (byteRead<0){\n\t\t\t\t\tbyteBufInput[bytePos]=-1;//!!!\n\t\t\t\t\tif (eofMet)\n\t\t\t\t\t\tthrow new EofException();\n\t\t\t\t\teofMet = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn byteBufInput[bytePos++];\n\t\t}\n\t\t\n\t\t/**\n\t\t * Returns next meaningful character as a byte.
\n\t\t * \n\t\t * @return\n\t\t * @throws IOException\n\t\t */\n\t\tpublic byte nextChar() throws IOException{\n\t\t\twhile ((by=nextByte())<=0x20);\n\t\t\treturn by;\n\t\t}\n\t\t\n\t\t/**\n\t\t * Returns next meaningful character OR space as a byte.
\n\t\t * \n\t\t * @return\n\t\t * @throws IOException\n\t\t */\n\t\tpublic byte nextCharOrSpacebar() throws IOException{\n\t\t\twhile ((by=nextByte())<0x20);\n\t\t\treturn by;\n\t\t}\n\t\t\n\t /**\n\t * Reads line.\n\t * \n\t * @return\n\t * @throws IOException\n\t */\n\t public String nextLine() throws IOException {\n readToken((byte)0x20);\n return new String(byteBuf,0,totalBytes);\n\t }\n\t \n\t public byte[] nextLineAsArray() throws IOException {\n readToken((byte)0x20);\n byte[] out = new byte[totalBytes];\n System.arraycopy(byteBuf, 0, out, 0, totalBytes);\n return out;\n\t }\n\t \n\t\t\n\t /**\n\t * Reads token. Spacebar is separator char.\n\t * \n\t * @return\n\t * @throws IOException\n\t */\n\t public String nextToken() throws IOException {\n readToken((byte)0x21);\n return new String(byteBuf,0,totalBytes);\n\t }\n\t \n\t /**\n\t * Spacebar is included as separator char\n\t * \n\t * @throws IOException\n\t */\n\t private void readToken() throws IOException {\t \t\n readToken((byte)0x21);\n\t }\n\t \n\t private void readToken(byte acceptFrom) throws IOException {\n totalBytes = 0;\n while ((by=nextByte())=acceptFrom){\n byteBuf[totalBytes++] = by;\n }\n\t }\n\t\t\n\t public int nextInt() throws IOException{\n\t\t\treadToken();\n\t\t\tint num=0, i=0;\n\t\t\tboolean sign=false;\n\t\t\tif (byteBuf[i]==MINUS){\n\t\t\t\tsign = true;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tfor (; i 0) {\n\t\t\t\tdouble curT = (a - x) / vx;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 1;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble curT = -x / vx;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 1;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (vy > 0) {\n\t\t\t\tthrow new Exception();\n\t\t\t} else {\n\t\t\t\ttmin = min(tmin, -y / vy);\n\t\t\t}\n\n\t\t\tif (vz > 0) {\n\t\t\t\tdouble curT = (b - z) / vz;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 2;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble curT = -z / vz;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 2;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t}\n\t\t\tx = x + tmin * vx;\n\t\t\ty = y + tmin * vy;\n\t\t\tz = z + tmin * vz;\n\t\t\t\n\t\t\tif (abs(y) < 0.0000001 || y < 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t\n\t\t\tif(r == 1) vx = -vx;\n\t\t\tif(r == 2) vz = -vz;\n\t\t}\n\t\tout.println(x + \" \" + z);\n\t}\n\n\tvoid maxHepify(int[] a, int i, int length) {\n\t\tint l = (i << 1) + 1;\n\t\tint r = (i << 1) + 2;\n\t\tint largest = i;\n\t\tif (l < length && a[l] > a[largest])\n\t\t\tlargest = l;\n\t\tif (r < length && a[r] > a[largest])\n\t\t\tlargest = r;\n\t\tif (largest != i) {\n\t\t\ta[largest] += a[i];\n\t\t\ta[i] = a[largest] - a[i];\n\t\t\ta[largest] -= a[i];\n\t\t\tmaxHepify(a, largest, length);\n\t\t}\n\t}\n\n\tvoid buildMaxHeap(int[] a) {\n\t\tfor (int i = a.length / 2 - 1; i >= 0; i--) {\n\t\t\tmaxHepify(a, i, a.length);\n\t\t}\n\t}\n\n\tvoid heapSort(int[] a) {\n\t\tbuildMaxHeap(a);\n\t\tfor (int i = a.length - 1; i > 0; i--) {\n\t\t\ta[i] += a[0];\n\t\t\ta[0] = a[i] - a[0];\n\t\t\ta[i] -= a[0];\n\t\t\tmaxHepify(a, 0, i);\n\t\t}\n\t}\n\n\tint[] zFunction(char[] s) {\n\t\tint[] z = new int[s.length];\n\t\tz[0] = 0;\n\t\tfor (int i = 1, l = 0, r = 0; i < s.length; ++i) {\n\t\t\tif (i <= r)\n\t\t\t\tz[i] = min(r - i + 1, z[i - l]);\n\t\t\twhile (i + z[i] < s.length && s[z[i]] == s[i + z[i]])\n\t\t\t\t++z[i];\n\t\t\tif (i + z[i] - 1 > r) {\n\t\t\t\tl = i;\n\t\t\t\tr = i + z[i] - 1;\n\t\t\t}\n\t\t}\n\t\treturn z;\n\t}\n\n\tint[] prefixFunction(char[] s) {\n\t\tint[] pr = new int[s.length];\n\t\tfor (int i = 1; i < s.length; ++i) {\n\t\t\tint j = pr[i - 1];\n\t\t\twhile (j > 0 && s[i] != s[j])\n\t\t\t\tj = pr[j - 1];\n\t\t\tif (s[i] == s[j])\n\t\t\t\t++j;\n\t\t\tpr[i] = j;\n\t\t}\n\t\treturn pr;\n\t}\n\n\tint ModExp(int a, int n, int mod) {\n\t\tint res = 1;\n\t\twhile (n != 0)\n\t\t\tif ((n & 1) != 0) {\n\t\t\t\tres = (res * a) % mod;\n\t\t\t\t--n;\n\t\t\t} else {\n\t\t\t\ta = (a * a) % mod;\n\t\t\t\tn >>= 1;\n\t\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static class Utils {\n\n\t\tprivate Utils() {\n\t\t}\n\n\t\tpublic static void mergeSort(int[] a) {\n\t\t\tmergeSort(a, 0, a.length - 1);\n\t\t}\n\n\t\tprivate static void mergeSort(int[] a, int leftIndex, int rightIndex) {\n\t\t\tfinal int MAGIC_VALUE = 50;\n\t\t\tif (leftIndex < rightIndex) {\n\t\t\t\tif (rightIndex - leftIndex <= MAGIC_VALUE) {\n\t\t\t\t\tinsertionSort(a, leftIndex, rightIndex);\n\t\t\t\t} else {\n\t\t\t\t\tint middleIndex = (leftIndex + rightIndex) / 2;\n\t\t\t\t\tmergeSort(a, leftIndex, middleIndex);\n\t\t\t\t\tmergeSort(a, middleIndex + 1, rightIndex);\n\t\t\t\t\tmerge(a, leftIndex, middleIndex, rightIndex);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void merge(int[] a, int leftIndex, int middleIndex,\n\t\t\t\tint rightIndex) {\n\t\t\tint length1 = middleIndex - leftIndex + 1;\n\t\t\tint length2 = rightIndex - middleIndex;\n\t\t\tint[] leftArray = new int[length1];\n\t\t\tint[] rightArray = new int[length2];\n\t\t\tSystem.arraycopy(a, leftIndex, leftArray, 0, length1);\n\t\t\tSystem.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n\t\t\tfor (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {\n\t\t\t\tif (i == length1) {\n\t\t\t\t\ta[k] = rightArray[j++];\n\t\t\t\t} else if (j == length2) {\n\t\t\t\t\ta[k] = leftArray[i++];\n\t\t\t\t} else {\n\t\t\t\t\ta[k] = leftArray[i] <= rightArray[j] ? leftArray[i++]\n\t\t\t\t\t\t\t: rightArray[j++];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void insertionSort(int[] a, int leftIndex, int rightIndex) {\n\t\t\tfor (int i = leftIndex + 1; i <= rightIndex; i++) {\n\t\t\t\tint current = a[i];\n\t\t\t\tint j = i - 1;\n\t\t\t\twhile (j >= leftIndex && a[j] > current) {\n\t\t\t\t\ta[j + 1] = a[j];\n\t\t\t\t\tj--;\n\t\t\t\t}\n\t\t\t\ta[j + 1] = current;\n\t\t\t}\n\t\t}\n\t}\n\n\tboolean isPrime(int a) {\n\t\tfor (int i = 2; i <= sqrt(a); i++)\n\t\t\tif (a % i == 0)\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tstatic double distance(long x1, long y1, long x2, long y2) {\n\t\treturn Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));\n\t}\n\n\tstatic long gcd(long a, long b) {\n\t\tif (min(a, b) == 0)\n\t\t\treturn max(a, b);\n\t\treturn gcd(max(a, b) % min(a, b), min(a, b));\n\t}\n\n\tstatic long lcm(long a, long b) {\n\t\treturn a * b / gcd(a, b);\n\t}\n}\n\n/*\n * class Treap>{\n * \n * public K x; public double y; public Treap left; public Treap right;\n * \n * public Treap(K x, double y, Treap left, Treap right) { this.x = x;\n * this.y = y; this.left = left; this.right = right; }\n * \n * public static > Treap merge(Treap l, Treap\n * r){ if(l == null) return r; if(r == null) return l; if(l.y > r.y){ return new\n * Treap(l.x, l.y, l.left, merge(l.right, r)); } else{ return new\n * Treap(r.x, r.y, merge(l, r.left), r.right); } }\n * \n * public void split(K x, Treap left, Treap right){ Treap newTreap =\n * null; if(this.x.compareTo(x) <= 0){ if(this.right == null){ right = null; }\n * else{ right.split(x, newTreap, right); } left = new Treap(this.x, this.y,\n * left, newTreap); } else{ if(this.left == null){ left = null; } else{\n * left.split(x, left, newTreap); } right = new Treap(x, y, newTreap, right);\n * } }\n * \n * public Treap add(K x){ Treap left = null, right = null; this.split(x,\n * left, right); Treap temp = new Treap(x, random(), null, null); return\n * merge(merge(left, temp), right); }\n * \n * @SuppressWarnings(\"null\") public Treap remove(K x){ Treap left = null,\n * temp = null, right = null; this.split(x, left, right); right.split(x, temp,\n * right); return merge(left, right); }\n * \n * public static > Treap build(K[] a){ Treap temp\n * = new Treap(a[0], random(), null, null); for(int i = 1; i < a.length;\n * i++){ temp = temp.add(a[i]); } return temp; } }\n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00e0e28b5409cb5fd2e2cfc954874218", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class P203D {\n\n private final double dt = 10000000;\n private final double EPS = 1e-7;\n\n public PrintWriter run() {\n double a = sc.nextDouble();\n double b = sc.nextDouble();\n double m = sc.nextDouble();\n double vx = sc.nextDouble() / dt / m;\n double vy = sc.nextDouble() / dt / m;\n double vz = sc.nextDouble() / dt / m;\n\n double x = a / 2;\n double y = m;\n double z = 0;\n \n while (y > EPS) {\n x += vx;\n y += vy;\n z += vz;\n \n if (x <= 0 || x >=a) {\n vx = -vx;\n }\n if (z <= 0 || z >=b) {\n vz = -vz;\n }\n//System.out.println(\"X = \" + x + \"\\tY = \" + y + \"\\tZ = \" + z);\n//System.console().readLine();\n }\n\n pw.println(x + \" \" + z);\n\n return pw;\n }\n\n private Scanner sc = new Scanner(new BufferedInputStream(System.in));\n private PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n\n public static void main(String... args) throws Exception {\n new P203D().run().close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d7d856a8870922c4011d525581660566", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author \u0410\u0439\u0434\u043e\u0441\n */\npublic class Main{\n \n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n \n int n = sc.nextInt();\n int m = sc.nextInt();\n int num[] = {n,m};\n int a [] =new int[]{0,0,0,0,0,0};\n for(int i=0;i<2;i++){\n while(true){ \n if(num[i]%2==0) {num[i]/=2;if(i==0) a[2]++;else a[2]--;}\n else if(num[i]%3==0) {num[i]/=3; if(i==0) a[3]++;else a[3]--;}\n else if(num[i]%5==0) {num[i]/=5; if(i==0) a[5]++;else a[5]--;}\n else break;\n }\n }\n if(a[0]!=a[1]) System.out.print(-1);\n else System.out.print(Math.abs(a[2])+Math.abs(a[3])+Math.abs(a[5]));\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6510637a200da0774a1eb26d1ec0065a", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author \u0410\u0439\u0434\u043e\u0441\n */\npublic class CodeForces {\n \n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n \n int n = sc.nextInt();\n int m = sc.nextInt();\n int num[] = {n,m};\n int a [] =new int[]{0,0,0,0,0,0};\n for(int i=0;i<2;i++){\n while(true){ \n if(num[i]%2==0) {num[i]/=2;if(i==0) a[2]++;else a[2]--;}\n else if(num[i]%3==0) {num[i]/=3; if(i==0) a[3]++;else a[3]--;}\n else if(num[i]%5==0) {num[i]/=5; if(i==0) a[5]++;else a[5]--;}\n else break;\n }\n }\n if(a[0]!=a[1]) System.out.println(-1);\n else System.out.println(Math.abs(a[2])+Math.abs(a[3])+Math.abs(a[5]));\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6da359517edbc78caaea9f254443514b", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\n/**\n *\n * @author tarsx\n */\npublic class CF_376B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n \n int a = sc.nextInt();\n int b = sc.nextInt();\n\n System.out.println(solve(a,b));\n }\n \n static int solve(int a, int b) {\n int[] aa = countDiviArr(a);\n int[] ba = countDiviArr(b);\n int sol = Math.abs(aa[0] - ba[0]) + Math.abs(aa[1] - ba[1]) + Math.abs(aa[2] - ba[2]);\n if (a / (Math.pow(2, aa[0]) * Math.pow(3, aa[1]) * Math.pow(5,aa[2])) !=\n b / (Math.pow(2, ba[0]) * Math.pow(3, ba[1]) * Math.pow(5,ba[2])))\n return -1;\n return sol;\n }\n \n static int[] countDiviArr(int cislo) {\n int[] solution = {countDiv(cislo,2), countDiv(cislo,3),countDiv(cislo,5)};\n return solution;\n }\n \n static int countDiv(int cislo, int d) {\n int i = 0;\n while (cislo % d == 0) {\n cislo /= d;\n i++;\n } \n return i;\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b832801235883896f10cda8b3b40db26", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class demo2 {\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tint a,b,res=0,p=0,q=0;\n\t\tint a=in.nextInt(), b = in.nextInt();\n\t\tif(a>=1&&b<=1000000000)\n\t\t{\n\t\t\tfor(int i=2;i<=5;i++)\n\t\t\t{\n\t\t\t\tp = 0, q = 0;\n\t\t\t\tif(i!=4){\n\t\t\t\twhile(a%i==0) {a/=i; p++;}\n\t\t\t\twhile(b%i==0) {b/=i; q++;}\n\t\t\t\tres+=Math.abs(p-q);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(a==b)\n\t\t\t\tSystem.out.println(res);\n\t\t\telse\n\t\t\t\tSystem.out.println(-1);\n\t}\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2c84bf67540730ba50be51f811a379a0", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "package one;\nimport java.util.Scanner;\n\npublic class Zadacha1 {\n\n\tpublic static void main(String[] args) {\n\t\tPer abc = new Per();\n\t\tabc.solve();\n\t\tabc.print();\n\n\t}\n\n}\nclass Per{\nint x1;\nint y1;\nint x2;\nint y2;\nint p;\nPer(){\n\tScanner con = new Scanner(System.in);\n\t\tx1 = con.nextInt();\n\t\ty1 = con.nextInt();\n\t\tx2 = con.nextInt();\n\t\ty2 = con.nextInt();\n\t\tcon.close();\n\t}\nvoid solve(){\n\tp=2*(Math.abs(x2-x1)+1) + 2*(Math.abs(y2-y1)+1);\n\t}\nvoid print(){\n\tSystem.out.println(p);\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "39715f64fb8ca1d37c810b4c854d6119", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package com.company;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n public static void main(String[] args) {\n\t //Scanner in = new Scanner(System.in);\n String str2 = null, str1 = null;\n try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {\n str1 = br.readLine();\n str2 = br.readLine();\n } catch (Exception e) {\n }\n String[] strAr1 = str1.split(\" \");\n String[] strAr2 = str2.split(\" \");\n\n int cx = Integer.parseInt(strAr1[0]);\n int cy = Integer.parseInt(strAr1[1]);\n int fx = Integer.parseInt(strAr2[0]);\n int fy = Integer.parseInt(strAr2[1]);\n\n if (cx == fx) {\n System.out.println(\n (Math.abs(cy-fy)*2)+6\n );\n return;\n }\n if (cy == fy) {\n System.out.println(\n (Math.abs(cx-fx)*2)+6\n );\n return;\n }\n System.out.println(\n Math.abs(cx-fx)*2 + Math.abs(cy - fy)*2 + 4\n );\n }\n}\n\n\n\n\n\n/*\n\n\n String str2 = null;\n try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {\n str2 = br.readLine();\n } catch (Exception e) {\n }\n String[] strAr = str2.split(\" \");\n\n\n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eae7aaf8663a37658036aa94650c676a", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage acm;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author rokk-\n */\npublic class ACM2017M {\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 rx = scanner.nextInt();\n int ry = scanner.nextInt();\n int fx = scanner.nextInt();\n int fy = scanner.nextInt();\n int dx = rx-fx;\n if (dx==0){\n dx = 1;\n }\n dx = Math.abs(dx)+1;\n int dy = ry-fy;\n if (dx==0){\n dx = 1;\n }\n dy = Math.abs(dy)+1;\n System.out.println(dx*2+dy*2);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d2df9a721e41fd86dfd3aaf24c51a1a1", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package com.company;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\t Scanner in = new Scanner(System.in);\n\n// String str2 = null, str1 = null;\n// try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {\n// str1 = br.readLine();\n// str2 = br.readLine();\n// } catch (Exception e) {\n// }\n// String[] strAr1 = str1.split(\" \");\n// String[] strAr2 = str2.split(\" \");\n//\n// int cx = Integer.parseInt(strAr1[0]);\n// int cy = Integer.parseInt(strAr1[1]);\n// int fx = Integer.parseInt(strAr2[0]);\n// int fy = Integer.parseInt(strAr2[1]);\n\n int cx = in.nextInt();\n int cy = in.nextInt();\n int fx = in.nextInt();\n int fy = in.nextInt();\n\n if (cx == fx) {\n System.out.println(\n (Math.abs(cy-fy)*2)+6\n );\n return;\n }\n if (cy == fy) {\n System.out.println(\n (Math.abs(cx-fx)*2)+6\n );\n return;\n }\n System.out.println(\n Math.abs(cx-fx)*2 + Math.abs(cy - fy)*2 + 4\n );\n }\n}\n\n\n\n\n\n/*\n\n\n String str2 = null;\n try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {\n str2 = br.readLine();\n } catch (Exception e) {\n }\n String[] strAr = str2.split(\" \");\n\n\n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "78c77cbcac3187aad20c81bd4fb9b264", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class 15215\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tint n;\n\t\tScanner in = new Scanner(System.in);\n\t\tint i,j;\n\t\tn=in.nextInt();\n\t\tint[][] mat=new int[n][n];\n\t\tfor(i=0;i0)\n {\n long a=sc.nextLong();\n long b=sc.nextLong();\n long x=(a+b);\n long y=(a-b);\n if(x==1||y==1)\n Systm.out.println(\"YES\");\n else\n Systm.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1bb552649ce449ed97c91a967c87c612", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n static ArrayList primes;\n static int[] isComposite;\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 t = sc.nextInt();\n sieve((int) (1e6+1));\n while (t-- > 0) {\n long a = sc.nextLong();\n long b = sc.nextLong();\n if ((a - b == 1) && isPrime(a + b)) out.println(\"YES\");\n else out.println(\"NO\");\n }\n out.flush();\n out.close();\n }\n\n static boolean isPrime(long N) {\n if (N < isComposite.length)\n return isComposite[(int) N] == 0;\n for (int p : primes){\n if (N % Shopping_Trip.p == 0)\n return false;\n if (1l*p*p>N) break;\n }\n return true;\n }\n\n static void sieve(int N) // O(N log log N)\n {\n isComposite = new int[N + 1];\n isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number\n primes = new ArrayList();\n\n for (int i = 2; i <= N; ++i) //can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))\n if (isComposite[i] == 0) //can loop in 2 and odd integers for slightly better performance\n {\n primes.add(i);\n if (1l * i * i <= N)\n for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in modified sieve\n isComposite[j] = 1;\n }\n }\n\n static class Scanner {\n BufferedReader br;\n StringTokenizer st;\n\n Scanner(InputStream system) {\n br = new BufferedReader(new InputStreamReader(system));\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aa71c4bef200afd757960c4505f61171", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class Main {\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n while(scan.hasNext()){\n int c= scan.nextInt();\n int d = scan.nextInt();\n int n = scan.nextInt();\n int m = scan.nextInt();\n int k = scan.nextInt();\n if(k>=n*m)System.out.println(0);\n else{\n int temp=n*m-k;\n if((double)c/n>d){\n System.out.println((n*m-k)*d);\n }\n else{\n int ans=temp/n;\n int x = ans*c;\n if(ans*n==temp){\n System.out.println(x);\n }\n else{\n int t =temp-ans*n;\n if(t*d= levtIndex && a[j] > current) {\n\t\t\t\ta[j + 1] = a[j];\n\t\t\t\tj--;\n\t\t\t}\n\t\t\ta[j + 1] = current;\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\n\tclass LOL implements Comparable {\n\t\tint x;\n\t\tint y;\n\n\n\t\tpublic LOL(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(LOL o) {\n\n\t\t\t//if (y == o.y)\n\t\t\t//\treturn (o.x - x);\n\t\t\treturn x - o.x; // ---->\n\t\t\t// return o.x - x; // <----\n\t\t\t// return o.y-y;\n\t\t}\n\n\t}\n\t\n\tpublic int unusualSquare(int [][] a, int n) {\n\t\tint s = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < n; j++) \n\t\t\t\ts += a[i][j]*a[j][i];\n\t\treturn s % 2;\n\t}\n\n\tpublic void solve() throws IOException {\n\t\tint c = readInt();\n\t\tint d = readInt();\n\t\tint n = readInt();\n\t\tint m = readInt();\n\t\tint k = readInt();\n\t\tint s = 0;\n\t\tint x = 0;\n\t\tint y = 0;\n\t\twhile (x*n + y < n*m - k) {\n\t\t\tx++;\n\t\t}\n\t\tint s1 = c*x;\n\t\tx = 0;\n\t\twhile (x*n + y < n*m - k) {\n\t\t\ty++;\n\t\t}\n\t\tint s2 = d*y;\n\t\tout.print(min(s1, s2));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4893dd1d189ed927c373c7bf79e55c01", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tString a = in.nextLine();\n\t\tString b = in.nextLine();\n\t\tint n = a.length();\n\t\tint[] num = new int[10];\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tint t = Integer.parseInt(a.substring(i, i+1));\n\t\t\tnum[t] += 1;\n\t\t}\n\t\tString ans = \"\";\n\t\tint sm = 0;\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tint t = Integer.parseInt(b.substring(i, i + 1));\n\t\t\tfor(int j = t; j >= 0; j--)\n\t\t\t{\n\t\t\t\tif(num[j] > 0)\n\t\t\t\t{\n\t\t\t\t\tnum[j] -= 1;\n\t\t\t\t\tsm = smallest(num);\n\t\t\t\t\tString nt = generate(sm, n);\n\t\t\t\t\tif(Long.parseLong(b) >= Long.parseLong(ans + nt + \"\"))\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tnum[j] += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic int smallest(String[] num)\n\t{\n\t\tfor(int i = 0; i < 10; i++)\n\t\t{\n\t\t\tif(num[i] > 0)\n\t\t\t{\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\tstatic String generate(int sm, int n)\n\t{\n\t\tString tmp = \"\";\n\t\tfor(int i = sm + 1; i < n; i++)\n\t\t{\n\t\t\ttmp += sm + \"\";\n\t\t}\n\t\treturn tmp;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9c3bbd206833d1b023dbe56917f78406", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n\npublic class scorify{\n\tpublic static void main(String[] args){\n\tScanner in=new Scanner(System.in);\n String first = in.next();\n String second = in.next();\n String result = \"\";\n \n ArrayList fl = new ArrayList();\n for (int i=0 ; i sl = new ArrayList();\n for(int i=0 ; i= 0; j--)\n\t\t\t{\n\t\t\t\tif(num[j] > 0)\n\t\t\t\t{\n\t\t\t\t\tnum[j] -= 1;\n\t\t\t\t\tsm = smallest(num);\n\t\t\t\t\tString nt = generate(sm, n);\n\t\t\t\t\tif(Long.parseLong(b) >= Long.parseLong(ans + nt + \"\"))\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tnum[j] += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic int smallest(int[] num)\n\t{\n\t\tfor(int i = 0; i < 10; i++)\n\t\t{\n\t\t\tif(num[i] > 0)\n\t\t\t{\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\tstatic String generate(int sm, int n)\n\t{\n\t\tString tmp = \"\";\n\t\tfor(int i = sm + 1; i < n; i++)\n\t\t{\n\t\t\ttmp += sm + \"\";\n\t\t}\n\t\treturn tmp;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5b3029515959b1feeff8af403ff044dd", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tString a = in.nextLine();\n\t\tString b = in.nextLine();\n\t\tint n = a.length();\n\t\tint[] num = new int[10];\n\t\tfor(int = 0; i < n; i++)\n\t\t{\n\t\t\tint t = Integer.parseInt(a.substring(i, i+1));\n\t\t\tnum[t] += 1;\n\t\t}\n\t\tString ans = \"\";\n\t\tint sm = 0;\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tint t = Integer.parseInt(b.substring(i, i + 1));\n\t\t\tfor(int j = t; j >= 0; j--)\n\t\t\t{\n\t\t\t\tif(num[j] > 0)\n\t\t\t\t{\n\t\t\t\t\tnum[j] -= 1;\n\t\t\t\t\tsm = smallest(num);\n\t\t\t\t\tString nt = generate(sm, n);\n\t\t\t\t\tif(Long.parseLong(b) >= Long.parseLong(ans + nt + \"\"))\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tnum[j] += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic int smallest(String[] num)\n\t{\n\t\tfor(int i=0; i<10; i++)\n\t\t{\n\t\t\tif(num[i]>0)\n\t\t\t{\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\tstatic String generate(int sm, int n)\n\t{\n\t\tString tmp = \"\";\n\t\tfor(int i=sm+1; i val=new Vector();\n static int k;\n \n static int getVal(int j)\n {\n if(j==k) return 1;\n else if(j0;j--)\n {\n a[i]+=getVal(k+1+i-j);\n }\n val.add(a[i]);\n if(a[i]>s) break;\n }\n Arrays.sort(a);\n Vector sol=new Vector();\n for(int i=a.length-1;i>=0&&s>0;i--)\n {\n if(a[i]>s) continue;\n else {\n sol.add(a[i]);\n s-=a[i];\n }\n }\n if(sol.size()==1)\n {\n sol.add(0);\n }\n out.println(sol.size());\n for(int j:sol)\n out.print(j+\" \");\n out.flush();\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;i0&&!stat)\n {\n a[i]=true;\n subsetSum(i+1,s-b[i],a);\n a[i]=false;\n subsetSum(i+1,s,a);\n }\n }\n}\n\nclass InputReader\n{\n BufferedReader in;\n StringTokenizer tokenizer=null;\n\n public InputReader(InputStream inputStream)\n {\n in=new BufferedReader(new InputStreamReader(inputStream));\n }\n public String next()\n {\n try{\n while (tokenizer==null||!tokenizer.hasMoreTokens())\n {\n tokenizer=new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n }\n catch (IOException e)\n {\n return null;\n }\n }\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fa95d642fcb020405072d2c7f2257855", "src_uid": "da793333b977ed179fdba900aa604b52", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import com.sun.deploy.util.ArrayUtil;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.time.*;\nimport java.util.regex.*;\n\npublic class Main {\n static long arr[];\n static int s;\n\n public static void main(String[] args) throws IOException {\n\n FastReader in = new FastReader();\n PrintWriter out = new PrintWriter(System.out);\n\n s = in.nextInt();\n int k = in.nextInt();\n Set st = new TreeSet();\n arr = new long[100];\n\n arr[0] = 1;\n\n st.add(1L);\n for (int i = k+1; arr[i-k-1]=0) {\n arr[i - k] += arr[i - j - k];\n }\n else\n break;\n }\n st.add(arr[i-k]);\n }\n\n arr = new long[st.size()];\n int i=arr.length-1;\n for (Long val: st) {\n if(val!=0L)\n arr[i--] = val;\n\n }\n\n ArrayList result = new ArrayList();\n solve(0, 0, result);\n if(result.size()==1)\n result.add(0L);\n out.println(result.size());\n StringBuilder sb = new StringBuilder();\n for (int j = 0; j < result.size(); j++) {\n sb.append(result.get(j)+\" \");\n }\n out.println(sb);\n\n out.close();\n\n }\n\n static boolean solve(int i, long sum, ArrayList result){\n\n if(sum == s)return true;\n\n if(i>=arr.length || sum>s)return false;\n\n result.add(arr[i]);\n\n if(solve(i+1, sum+arr[i], result))\n return true;\n\n result.remove(result.size()-1);\n\n return solve(i+1, sum, result);\n }\n static class Comp implements Comparator{\n\n\n public int compare(Long x, Long y){\n if(x>y)return -1;\n return 1;\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 String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "454db10941cd2c7d5876182546fef769", "src_uid": "da793333b977ed179fdba900aa604b52", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\n\npublic class C {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\n\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tlong k = sc.nextLong();\n\t\tint x = sc.nextInt()-1;\n\t\tint y = sc.nextInt()-1;\n\n\t\tlong[][] arr= new long[n][m];\n\n\t\tif(n!=1 || m!=1)\n\t\t{\n\t\t\tif(n!=1)\n\t\t\t{\n\t\t\t\tlong periods = k/(1l*n*m+1l*m*(n-2));\n\t\t\t\t//System.out.println(periods);\n\t\t\t\tlong remain = k%(1l*n*m+1l*m*(n-2));\n\t\t\t\t//for()\n\t\t\t\t//int j = 0;\n\t\t\t\tfor(int i=0;i0)\n\t\t\t{\n\t\t\t\t//System.out.println(k);\n\t\t\t\tfor(int j=0;j0;j++,k--)\n\t\t\t\t\tarr[i][j]++;\n\t\t\t\tif(i==0)\n\t\t\t\t{\n\t\t\t\t\ti=Math.min(1, n-1);\n\t\t\t\t\tup = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tif(i==n-1)\n\t\t\t\t\t{\n\t\t\t\t\t\ti=n-2;\n\t\t\t\t\t\tup = false;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tif(up)\n\t\t\t\t\t\t\ti++;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\ti--;\n\t\t\t}\n\n\t\t\tlong min = Long.MAX_VALUE;\n\t\t\tlong max = 0;\n\t\t\tfor(i=0;i0){\n\t\t\t\t\tfor(int i=0;i0;i++){\n\t\t\t\t\tfor(int j=0;j0;j++){\n\t\t\t\t\t\tR[i][j]++;\t\n\t\t\t\t\t\tk--;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tif(n>1){\n\t\t\tlong total=(m)*(n-1);\n\t\t\tlong g=k/((2)*total);\n\t\t\tlong rem2=k%(total*2);\n\t\t\tif(g>=1){\n\t\t\tfor(int i=0;i0){\n\t\t\t\tif(loop1){\n\t\t\tfor(int i=0;i0;i++){\n\t\t\t\tfor(int j=0;j0;j++){\n\t\t\t\t\tR[i][j]++;\n\t\t\t\t\trem2--;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\tloop1=false;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tfor(int i=n-2;i>=0 && rem2>0;i--){\n\t\t\t\t\t\tfor(int j=0;j0;j++){\n\t\t\t\t\t\t\tR[i][j]++;\n\t\t\t\t\t\t\trem2--;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\t\t/*for(int i=0;iR[i][j]){\n\t\t\t\t\t\tmin=R[i][j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(max+\" \"+min+\" \"+Sergey);\n\t\t\tsc.close();\n\t\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d40eed18bb6cbf380b35fe68965890ff", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class C2 {\n\tfinal static long MOD = 1000000007;\n\tstatic int[][] ar;\n\tstatic int[] ar1;\n\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\tlong k = in.nextLong();\n\t\tint x = in.nextInt();\n\t\tint y = in.nextInt();\n\t\tif (n == 1) {\n\t\t\tar1 = new int[m];\n\t\t\tlong basicQuestions = k / m;\n\t\t\tlong remainK = (long)(k % m);\n\t\t\tlong maxQ = 0; long minQ = 0; long serQ = 0;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif (remainK == 0) break;\n\t\t\t\tremainK--;\n\t\t\t\tar1[j]++;\n\t\t\t}\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tmaxQ = Math.max(maxQ, ar1[j]);\n\t\t\t\tminQ = Math.min(minQ, ar1[j]);\n\t\t\t}\n\t\t\tmaxQ += basicQuestions;\n\t\t\tminQ += basicQuestions;\n\t\t\tserQ = ar1[y-1] + basicQuestions;\n\t\t\tSystem.out.println(maxQ + \" \" + minQ + \" \" + serQ);\n\t\t\treturn;\n\t\t}\n\t\tlong round = n * m + (n -2) * m;\n\t\tlong basicQuestions = k / round;\n\t\tlong remainK = (long)(k % round);\n\t\tlong maxQ = 0; long minQ = 0; long serQ = 0;\n\t\tar = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {\n\t\t\tif (remainK == 0) break;\n\t\t\tremainK--;\n\t\t\tar[i][j]++;\n\t\t}\n\t\tfor (int i = n-2; i > 0; i++) for (int j = 0; j < m; j++) {\n\t\t\tif (remainK == 0) break;\n\t\t\tremainK--;\n\t\t\tar[i][j]++;\n\t\t}\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {\n\t\t\tmaxQ = Math.max(maxQ, ar[i][j]);\n\t\t\tminQ = Math.min(minQ, ar[i][j]);\n\t\t}\n\t\tmaxQ += basicQuestions;\n\t\tminQ += basicQuestions;\n\t\tserQ = ar[x-1][y-1] + basicQuestions;\n\t\tSystem.out.println(maxQ + \" \" + minQ + \" \" + serQ);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "efe18109b61dcbafc8f1b3414d016c54", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "public class UnfairPoll\n{\n public static long ceil(long x, long y)\n {\n if(x % y == 0)\n return x / y;\n else\n return x / y + 1;\n }\n \n public static void main(String [] args)\n {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(); int m = in.nextInt(); long k = in.nextLong();\n int x = in.nextInt(); int y = in.nextInt();\n \n long max = 0; long min = 0; long sergei = 0;\n \n if(k <= m * n)\n {\n max = ceil(k, m * n);\n min = k / (m * n);\n sergei = (k >= m * (x - 1) + y) ? 1 : 0;\n }\n else\n {\n long mod = 0;\n if(n > 1)\n {\n mod = (k - m) % ((n - 1) * m);\n max = ceil(k - m, (n - 1) * m);\n min = max / 2 + ((max % 2) * (mod == 0 ? 1 : 0));\n }\n else\n {\n mod = k % m;\n max = ceil(k, m);\n min = k / m;\n }\n \n if(x == 1)\n {\n if(n > 1)\n {\n sergei = ceil(max, 2);\n if((max % 2 == 0 && ((n - ceil(mod, m) < x) || (n - ceil(mod, m) == x && (mod + m - 1) % m + 1 >= y))))\n sergei++;\n }\n else\n sergei = min + ((mod >= y) ? 1 : 0);\n }\n else\n if(x == n)\n {\n sergei = min;\n if(max % 2 == 1 && mod >= (x - 2) * m + y)\n sergei++;\n }\n else\n {\n sergei = max;\n if(!((max % 2 == 1 && mod >= (x - 2) * m + y) \n || (max % 2 == 0 && ((n - ceil(mod, m) < x) || (n - ceil(mod, m) == x && (mod + m - 1) % m + 1 >= y)))))\n sergei--;\n }\n \n if(n == 2)\n max = min + (mod > 0 ? 1 : 0);\n }\n \n System.out.println(max + \" \" + min + \" \" + sergei);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "27e3bbe78399e39001058935607196de", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class Main {\n public static void main(String args[]){\n \n\n \n try {\n BufferedReader d = new BufferedReader(new InputStreamReader(System.in));\n\n /******\u70b9\u6570\u306e\u6570\u3001\u5404\u70b9\u6570\u306e\u4eba\u6570\u3001x,y\u306e\u8aad\u8fbc\u307f******/\n int num = Integer.parseInt(d.readLine());\n String[] str = d.readLine().split(\" \");\n \n int[] point = new int[num]; // \u5404\u70b9\u6570\u306e\u4eba\u6570\n \n for(int i = 0; i < num; i++){\n point[i] = Integer.parseInt(str[i]); // \u5404\u70b9\u6570\u306e\u4eba\u6570\u3092\u683c\u7d0d\n }\n \n int x = 0;\n int y = 0;\n String[] str2 = d.readLine().split(\" \");\n x = Integer.parseInt(str2[0]);\n y = Integer.parseInt(str2[1]);\n /****************************************/\n \n System.out.println(solve(point, num, x, y));\n \n \n } catch (NumberFormatException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private static int solve(int[] point, int num, int x, int y) {\n int border = 0; // passing rate\n int sumOfInterGp = 0; // \u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\n int sumOfBigiGp = 0; // \u521d\u5fc3\u8005\u30af\u30e9\u30b9\u306e\u4eba\u6570\n \n for(int i = 0; i < num - 1; i++){\n sumOfBigiGp += point[i]; // \u521d\u5fc3\u8005\u30af\u30e9\u30b9\u306e\u4eba\u6570\u3092\u7b97\u51fa\n sumOfInterGp = sumOfRest(i + 1, num, point); // \u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\u3092\u7b97\u51fa\n if(sumOfBigiGp >= x && sumOfBigiGp <= y){ // \u521d\u5fc3\u8005\u30af\u30e9\u30b9\u306e\u4eba\u6570\u304c\u30af\u30e9\u30b9\u4eba\u6570\u306e\u7bc4\u56f2\u5185\u306a\u3089\u3070\u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\u3092\u30c1\u30a7\u30c3\u30af\n if(sumOfInterGp >= x && sumOfInterGp <= y){ // \u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\u304c\u9069\u5207\u306a\u3089passing rate\u3092\u7b97\u51fa\n border = i + 2;\n return border;\n }\n }\n else if(sumOfInterGp < x){\n return 0;\n }\n }\n return 0;\n }\n\n /***************i\u70b9\u3088\u308a\u70b9\u6570\u306e\u9ad8\u3044\u5b66\u751f\u306e\u6570\u3092\u6570\u3048\u308b\u95a2\u6570***************/\n private static int sumOfRest(int i, int num, int[] point) {\n int sumOfRest = 0;\n \n for(int j = i; j < num; j++){\n sumOfRest += point[j];\n }\n \n return sumOfRest;\n }\n /**********************************************************/\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5293ae433b149e3e400ee4829bb69db0", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\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) {\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) {\n int n = in.nextInt();\n int ball[] = new int[n];\n int sumOfBeginer = 0;\n int sumOfAdvanced = 0;\n for(int i = 0; i < n; ++i){\n ball[i] = in.nextInt();\n }\n int lowestPassingScore = 0;\n int x = in.nextInt();\n int y = in.nextInt();\n for(int i = 0; i < n; ++i){\n sumOfBeginer += ball[i];\n lowestPassingScore = i + 2;\n if(sumOfBeginer <= y){\n if(sumOfBeginer >= x){\n for(int j = i + 1; j < n; ++j){\n sumOfAdvanced += ball[j];\n }\n else if(Math.min(sumOfBeginer, sumOfAdvanced) >= x && Math.max(sumOfBeginer, sumOfAdvanced) <= y){\n out.println(lowestPassingScore);\n return;\n }\n sumOfAdvanced = 0;\n }\n }else break;\n }\n out.println(0);\n }\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 \n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\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 long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1be83f3c10c30aaddf9fcd3b95486a5a", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class Main {\n public static void main(String args[]){\n \n BufferedReader d = new BufferedReader(new InputStreamReader(System.in));\n \n try {\n /******\u70b9\u6570\u306e\u6570\u3001\u5404\u70b9\u6570\u306e\u4eba\u6570\u3001x,y\u306e\u8aad\u8fbc\u307f******/\n int num = Integer.parseInt(d.readLine());\n String[] str = d.readLine().split(\" \");\n \n int[] point = new int[num]; // \u5404\u70b9\u6570\u306e\u4eba\u6570\n \n for(int i = 0; i < num; i++){\n point[i] = Integer.parseInt(str[i]); // \u5404\u70b9\u6570\u306e\u4eba\u6570\u3092\u683c\u7d0d\n }\n \n int x = 0;\n int y = 0;\n String[] str2 = d.readLine().split(\" \");\n x = Integer.parseInt(str2[0]);\n y = Integer.parseInt(str2[1]);\n /****************************************/\n \n System.out.println(solve(point, num, x, y));\n \n \n } catch (NumberFormatException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private static int solve(int[] point, int num, int x, int y) {\n int border = 0; // passing rate\n int sumOfInterGp = 0; // \u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\n int sumOfBigiGp = 0; // \u521d\u5fc3\u8005\u30af\u30e9\u30b9\u306e\u4eba\u6570\n \n for(int i = 0; i < num - 1; i++){\n sumOfBigiGp += point[i]; // \u521d\u5fc3\u8005\u30af\u30e9\u30b9\u306e\u4eba\u6570\u3092\u7b97\u51fa\n sumOfInterGp = sumOfRest(i + 1, num, point); // \u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\u3092\u7b97\u51fa\n if(sumOfBigiGp >= x && sumOfBigiGp <= y){ // \u521d\u5fc3\u8005\u30af\u30e9\u30b9\u306e\u4eba\u6570\u304c\u30af\u30e9\u30b9\u4eba\u6570\u306e\u7bc4\u56f2\u5185\u306a\u3089\u3070\u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\u3092\u30c1\u30a7\u30c3\u30af\n if(sumOfInterGp >= x && sumOfInterGp <= y){ // \u4e2d\u7d1a\u30af\u30e9\u30b9\u306e\u4eba\u6570\u304c\u9069\u5207\u306a\u3089passing rate\u3092\u7b97\u51fa\n border = i + 2;\n return border;\n }\n }\n else if(sumOfInterGp < x){\n return 0;\n }\n }\n return 0;\n }\n\n /***************i\u70b9\u3088\u308a\u70b9\u6570\u306e\u9ad8\u3044\u5b66\u751f\u306e\u6570\u3092\u6570\u3048\u308b\u95a2\u6570***************/\n private static int sumOfRest(int i, int num, int[] point) {\n int sumOfRest = 0;\n \n for(int j = i; j < num; j++){\n sumOfRest += point[j];\n }\n \n return sumOfRest;\n }\n /**********************************************************/\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea06114db1e96eaa83649228b0ff7dd0", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class Task {\n public void run() throws Exception {\n final int m = in.nextInt();\n final int[] c = in.nextInts();\n final int x = in.nextInt(), y = in.nextInt();\n\n int[] lsum = new int[m+1];\n int[] psum = new int[m+1];\n lsum[0] = 0;\n for(int i = 0; i < m; i++) {\n lsum[i + 1] = lsum[i] + c[i];\n psum[m - i - 1] = psum[m - i] + c[m - 1 - i];\n }\n\n for(int i = m; i >= 0; i--) {\n boolean match1 = x <= lsum[i] && lsum[i] <= y;\n boolean match2 = x <= psum[i] && psum[i] <= y;\n if(match1 && match2) {\n println(i+1);\n return;\n }\n }\n return 0;\n }\n\n // other stuff\n public void println(Object o) {\n System.out.println(o);\n }\n public void print(Object o) {\n System.out.println(o);\n }\n private final MyReader in = new MyReader();\n private static class MyReader {\n private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n private StringTokenizer tokenizer = null;\n public String nextToken() throws Exception {\n if(tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n public BigInteger nextBigInteger() throws Exception {\n return new BigInteger(nextToken());\n }\n public List nextIntegerList() throws Exception {\n if(tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n final List data = new ArrayList(tokenizer.countTokens());\n while(tokenizer.hasMoreTokens()) {\n data.add(new Integer(tokenizer.nextToken()));\n }\n return data;\n }\n public int[] nextInts() throws Exception {\n if(tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n final int[] data = new int[tokenizer.countTokens()];\n for(int i = 0; i < data.length; i++) {\n data[i] = nextInt();\n }\n return data;\n }\n }\n public static void main(String[] args) throws Exception {\n new Task().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d0cce61e4110afabb0808568dd571d17", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.ArrayList;\n \npublic class v\n{\n public static void main(String args[])\n {\n String a= \"1\"\n int=String.parseInt(\"a\");\n return;\n Scanner sc=new Scanner(System.in);\n int mom=sc.nextInt();\n long[] bro= new long[mom];\n String coo= sc.nextLine();\n sc.close();\n for(int lam=mom-1;lam>=0;lam--)\n {\n bro[lam]=String.parseInt(coo.substring(coo.length()-1));\n coo=coo.substring(0,coo.length()-1);\n if(coo.equals(coo.substring(0,1)))\n {break;}\n }\n boolean q= false;\n int point=0;\n while(point=0;lam--)\n {\n bro[lam]=String.parseInt(coo.substring(coo.length()-1));\n coo=coo.substring(0,coo.length()-1);\n if(coo.equals(coo.substring(0,1)))\n {break;}\n }\n boolean q= false;\n int point=0;\n while(point happySegment) {\n happySegment+=array[xPos];\n xPos++;\n i = xPos;\n sum = 0;\n }\n if (sum == happySegment) {\n sum = 0;\n success = true;\n } else {\n success = false;\n }\n\n if (i < intString.length())\n sum += array[i];\n }\n\n if (success) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e0d87d545bbf375e6aab789ed06fc1ec", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "//package Contest515div3;\n\nimport java.io.PrintWriter;\nimport java.sql.SQLOutput;\nimport java.util.*;\n\npublic class mainF {\n public static Scanner enter = new Scanner(System.in);\n public static PrintWriter out = new PrintWriter(System.out);\n public static void main(String[] args) {\n int n=enter.nextInt();\n point mass[] =new point[n+1];\n for (int i = 0; i arrayList=new ArrayList<>(n);\n //arrayList.add(mass[0]);\n arrayList.add(new point(0,0));\n arrayList.add(new point(0,0));\n\n // System.out.println(Arrays.toString(mass));\n for (int i = 0; i Math.max(mass[i].x,mass[i].y)){\n if(i==0){\n arrayList.add(mass[i]);\n }\n arrayList.add(mass[i]);\n arrayList.add(mass[i+1]);\n }\n }\n\n\n //arrayList.remove(arrayList.size()-1);\n //System.out.println(arrayList);\n long dp[]=new long[2*n];\n int last=0;\n for (int i = 2; i {\n long x,y;\n\n public point(long x, long y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public int compareTo(point o) {\n if(Math.max(x,y)Math.max(o.x,o.y)) return 1;\n else{\n if(y==o.y){\n return (x<=o.x)? -1: 1;\n }\n else if(x==o.x){\n return (y>=o.y)? -1: 1;\n }\n else{\n return (x<=o.x)? -1: 1;\n }\n }\n }\n\n @Override\n public String toString() {\n return \"(\"+x+\", \"+y+\")\";\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "476e20f813ca8574e86a20ec9010a69f", "src_uid": "06646a9bdce2d65e92e525e97b2c975d", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "//package Contest515div3;\n\nimport java.io.PrintWriter;\nimport java.sql.SQLOutput;\nimport java.util.*;\n\npublic class mainF {\n public static Scanner enter = new Scanner(System.in);\n public static PrintWriter out = new PrintWriter(System.out);\n public static void main(String[] args) {\n int n=enter.nextInt();\n point mass[] =new point[n+1];\n for (int i = 0; i arrayList=new ArrayList<>(n);\n //arrayList.add(mass[0]);\n arrayList.add(new point(0,0));\n arrayList.add(new point(0,0));\n\n // System.out.println(Arrays.toString(mass));\n for (int i = 0; i Math.max(mass[i].x,mass[i].y)){\n if(i==0){\n arrayList.add(mass[i]);\n }\n arrayList.add(mass[i]);\n arrayList.add(mass[i+1]);\n }\n }\n\n\n arrayList.remove(arrayList.size()-1);\n //System.out.println(arrayList);\n long dp[]=new long[(int)1e6];\n int last=0;\n for (int i = 2; i {\n long x,y;\n\n public point(long x, long y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public int compareTo(point o) {\n if(Math.max(x,y)Math.max(o.x,o.y)) return 1;\n else{\n if(y==o.y){\n return (x<=o.x)? -1: 1;\n }\n else if(x==o.x){\n return (y>=o.y)? -1: 1;\n }\n else{\n return (x<=o.x)? -1: 1;\n }\n }\n }\n\n @Override\n public String toString() {\n return \"(\"+x+\", \"+y+\")\";\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0abefe7fa62efb24872b7e306f23dba3", "src_uid": "06646a9bdce2d65e92e525e97b2c975d", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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 *\n * @author Vadim\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n static void addPoint(ArrayList[] points, int idx, int coord) {\n if (points[idx] == null)\n points[idx] = new ArrayList<>();\n points[idx].add(coord);\n }\n\n static long getDist(TaskF.Point p1, TaskF.Point p2) {\n return Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.ni();\n int MAX_LEN = 200007;\n long INF = Long.MAX_VALUE;\n ArrayList[] ypoints = new ArrayList[MAX_LEN];\n ArrayList[] xpoints = new ArrayList[MAX_LEN];\n for (int i = 0; i < n; i++) {\n int x = in.ni();\n int y = in.ni();\n if (x >= y) {\n addPoint(xpoints, x, y);\n } else {\n addPoint(ypoints, y, x);\n }\n }\n for (int i = 0; i < MAX_LEN; i++) {\n if (xpoints[i] != null)\n Collections.sort(xpoints[i]);\n if (ypoints[i] != null)\n Collections.sort(ypoints[i]);\n }\n long[] levelDist = new long[MAX_LEN];\n TaskF.Point[][] levelPoints = new TaskF.Point[MAX_LEN][2];\n levelPoints[0][0] = levelPoints[0][1] = new TaskF.Point(0, 0);\n for (int i = 0; i < MAX_LEN; i++) {\n if (xpoints[i] == null && ypoints[i] == null)\n continue;\n long dist = 0;\n if (xpoints[i] != null) {\n int maxy = xpoints[i].get(xpoints[i].size() - 1);\n dist = maxy - xpoints[i].get(0);\n levelPoints[i][0] = new TaskF.Point(i, xpoints[i].get(0)); //min point\n levelPoints[i][1] = new TaskF.Point(i, maxy);\n }\n if (ypoints[i] != null) {\n int maxx = ypoints[i].get(ypoints[i].size() - 1);\n dist += maxx - ypoints[i].get(0);\n if (xpoints[i] == null) {\n levelPoints[i][0] = new TaskF.Point(maxx, i);\n levelPoints[i][1] = new TaskF.Point(ypoints[i].get(0), i);\n } else {\n dist += getDist(levelPoints[i][1], new TaskF.Point(ypoints[i].get(ypoints[i].size() - 1), i));\n levelPoints[i][1] = new TaskF.Point(ypoints[i].get(0), i);\n }\n }\n levelDist[i] = dist;\n }\n long d[][] = new long[MAX_LEN][2];\n int prevLevel = 0;\n for (int level = 1; level < MAX_LEN; level++) {\n if (xpoints[level] == null && ypoints[level] == null) {\n continue;\n }\n assert levelPoints[level][0] != null;\n assert levelPoints[level][1] != null;\n assert levelPoints[prevLevel][0] != null;\n assert levelPoints[prevLevel][1] != null;\n d[level][0] += Math.min(d[prevLevel][0] + getDist(levelPoints[level][1], levelPoints[prevLevel][0]), d[prevLevel][1] + getDist(levelPoints[level][1], levelPoints[prevLevel][1])) + levelDist[level];\n d[level][1] += Math.min(d[prevLevel][0] + getDist(levelPoints[level][0], levelPoints[prevLevel][0]), d[prevLevel][1] + getDist(levelPoints[level][0], levelPoints[prevLevel][1])) + levelDist[level];\n prevLevel = level;\n }\n\n out.println(Math.min(d[prevLevel][0], d[prevLevel][1]));\n }\n\n static class Point {\n int x;\n int y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n }\n\n }\n\n static class InputReader extends BufferedReader {\n public InputReader(InputStream st) {\n super(new InputStreamReader(st));\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n private int readByte() {\n try {\n return read();\n } catch (IOException e) {\n throw new RuntimeException();\n }\n }\n\n public 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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c798c228811c48edbe85d6fa772ffdf3", "src_uid": "06646a9bdce2d65e92e525e97b2c975d", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\nimport cf1.pair;\n\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\n/* spar5h */\n\npublic class cf6{ \n\t\n\tstatic int[] left, down, val;\n\tstatic long[][] dp;\n\t\n\tstatic void recur(int i, int d, int m, int x, int y) {\n\t\t\n\t\tif(i == m) {\n\t\t\t dp[i][d] = 0; return;\n\t\t}\n\t\t\n\t\tdp[i][d] = Long.MAX_VALUE;\n\t\t\n\t\tint x1, y1;\n\t\t\n\t\tif(left[i + 1] != -1) {\n\t\t\tx1 = left[i + 1]; y1 = val[i + 1];\n\t\t}\n\t\telse {\n\t\t\tx1 = val[i + 1]; y1 = down[i + 1];\n\t\t}\n\t\t\n\t\tint x2, y2;\n\t\t\n\t\tif(down[i + 1] != -1) {\n\t\t\tx2 = val[i + 1]; y2 = down[i + 1];\n\t\t}\n\t\telse {\n\t\t\tx2 = left[i + 1]; y2 = down[i + 1];\n\t\t}\n\t\t\n\t\tint dist = abs(x1 - x2) + abs(y1 - y2);\n\t\t\n\t\tif(dp[i + 1][0] == -1)\n\t\t\trecur(i + 1, 0, m, x2, y2);\n\t\t\n\t\tdp[i][d] = min(abs(x - x1) + abs(y - y1) + dist + dp[i + 1][0], dp[i][d]);\n\t\t\n\t\tif(dp[i + 1][1] == -1)\n\t\t\trecur(i + 1, 1, m, x1, y1);\n\t\t\n\t\tdp[i][d] = min(abs(x - x2) + abs(y - y2) + dist + dp[i + 1][1], dp[i][d]);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\n\t\tInputReader s = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\t\t\n\t\t\n\t\tint n = s.nextInt();\n\t\t\n\t\tint[] x = new int[n];\n\t\tint[] y = new int[n];\n\t\t\n\t\tTreeSet ts = new TreeSet();\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\n\t\t\tx[i] = s.nextInt();\n\t\t\ty[i] = s.nextInt();\n\t\t\t\n\t\t\tts.add(max(x[i], y[i]));\n\t\t}\t\n\t\t\n\t\tint m = 0;\n\t\tval = new int[ts.size() + 1];\n\t\t\n\t\tHashMap hm = new HashMap();\n\t\thm.put(0, 0);\n\t\t\n\t\tfor(int i : ts) {\n\t\t\tm = m + 1; val[m] = i; hm.put(i, m);\n\t\t}\n\t\t\n\t\tleft = new int[m + 1];\n\t\tArrays.fill(left, -1);\n\t\t\n\t\tdown = new int[m + 1];\n\t\tArrays.fill(down, -1);\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\n\t\t\tint j = hm.get(max(x[i], y[i]));\n\t\t\t\n\t\t\tif(x[i] == max(x[i], y[i])) {\n\t\t\t\t\n\t\t\t\tif(down[j] == -1 || y[i] < down[j])\n\t\t\t\t\tdown[j] = y[i];\n\t\t\t}\n\t\t\t\n\t\t\telse {\n\t\t\t\t\n\t\t\t\tif(left[j] == -1 || x[i] < left[j])\n\t\t\t\t\tleft[j] = x[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tdp = new long[m + 1][2];\n\t\t\n\t\tfor(int i = 0; i <= m; i++)\n\t\t\tfor(int j = 0; j < 2; j++)\n\t\t\t\tdp[i][j] = -1;\n\t\t\n\t\trecur(0, 0, m, 0, 0);\n\t\t\n\t\tw.println(dp[0][0]);\n\t\t\n\t\tw.close();\n\t}\n\t\n\tstatic class InputReader {\n\t\t\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n\t\t}\n\t\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \n}\n\n\n\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7eaf22ec6b245f0942f0ed295fc878e2", "src_uid": "06646a9bdce2d65e92e525e97b2c975d", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class HelloWorld {\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) throws IOException {\n FastReader scn = new FastReader();\n OutputStream out = new BufferedOutputStream(System.out);\n program(scn, out);\n out.flush();\n }\n\n public static void print(OutputStream out, Object str) throws IOException {\n out.write(str.toString().getBytes());\n }\n\n static class Length implements Comparable {\n Integer length;\n\n public Length(int length) {\n this.length = length;\n }\n\n @Override\n public int compareTo(Length o) {\n return o.length - this.length;\n }\n }\n\n private static void program(FastReader scn, OutputStream out) throws IOException {\n int n = scn.nextInt();\n int a = scn.nextInt();\n int b = scn.nextInt();\n PriorityQueue priorityQueue = new PriorityQueue<>();\n Integer ans = 0;\n priorityQueue.add(new Length(n - a));\n ans = 1;\n ans = helper(priorityQueue, ans, a, n);\n ans = helper(priorityQueue, ans, a, n);\n ans = helper(priorityQueue, ans, a, n);\n ans = helper(priorityQueue, ans, b, n);\n ans = helper(priorityQueue, ans, b, n);\n print(out, ans);\n }\n\n private static Integer helper(PriorityQueue priorityQueue, Integer ans, int a, int n) {\n Length k = priorityQueue.poll();\n if (k.length >= a) {\n priorityQueue.add(new Length(k.length - a));\n } else {\n priorityQueue.add(new Length(n - a));\n priorityQueue.add(k);\n ans++;\n }\n return ans;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4f74d35f29e4da580d07332218726b3e", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * Created by trung.pham on 27/12/17.\n */\npublic class B_Testing_Round_14 {\n static int[][][]dp;\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n dp = new int[n + 1][5][3];\n for(int [][]x : dp){\n for(int[]y : x){\n Arrays.fill(y, -1);\n }\n }\n out.println(cal(n, 4, 2, n, a, b));\n out.close();\n }\n\n public static int cal(int left, int a, int b, int n, int A, int B){\n if(a == 0 && b == 0){\n return 1;\n }\n if(dp[left][a][b] != -1){\n return dp[left][a][b];\n }\n int result = Integer.MAX_VALUE;\n if(left >= A && a > 0){\n result = cal(left - A, a - 1, b, n, A, B);\n }\n if(left >= B && b > 0){\n result = Math.min(result , cal(left - B, a, b - 1, n , A, B));\n }\n if(left < A && left < B){\n result = 1 + cal(n, a, b, b, A, B);\n }\n return dp[left][a][b] = result;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "57b1f36675382ed2b61ae4ed6d0bc72c", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package solution;\n\nimport java.util.*;\n\npublic class Solution {\n \n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int n,a,b;\n int pieces,ans,r;\n ArrayList rP= new ArrayList();\n n=sc.nextInt();\n a=sc.nextInt();\n b=sc.nextInt();\n ans=1;\n r=0;\n pieces=n/a;\n if(pieces>=4)\n {\n rP.add(n-(a*4));\n }else if(pieces==3)\n {\n ans++;\n rP.add(n-a);\n rP.add(n-(a*3));\n }else if(pieces==2)\n {\n ans++;\n rP.add(n-(a*2));\n rP.add(n-(a*2));\n }else\n {\n ans+=3;\n rP.add(n-a);\n rP.add(n-a);\n rP.add(n-a);\n rP.add(n-a);\n }\n for (Integer i : rP) {\n if(i/b>0)r+=i/b;\n }\n if(r<2)\n {\n if(n>(b*(2-r)))ans++;\n else ans+=2;\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4624fda3d293a70ad3d5c938f0abed88", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package algorithms;\n\nimport java.util.Scanner;\n\npublic class B910 {\n\t\n\tstatic int sizeA;\n\tstatic int sizeB;\n\tstatic int sizeN;\n\t\n\tstatic void doit(int a, int b, int size, int count){\n\t\tif(a == 0 && b == 0) res = Math.min(res, count);\n\t\telse {\n\t\t\tif(a > 0 && size >= sizeA) doit(a-1,b,size-sizeA,count);\n\t\t\tif(a > 0 && size < sizeA) doit(a,b,sizeN,count+1);\n\t\t\tif(b > 0 && size >= sizeB) doit(a,b-1,size-sizeB,count);\n\t\t\tif(b > 0 && size < sizeB) doit(a,b,sizeN,count+1);\n\t\t}\n\t}\n\t\n\tstatic int res = 10;\n\n\t\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tsizeN = in.nextInt();\n\t\tsizeA = in.nextInt();\n\t\tsizeB = in.nextInt();\n\t\tdoit(4,2, sizeN,1);\n\t\tSystem.out.println(res);\n\t\t\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f2e1b0268e93689cbaa441166ff22f7a", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n String input = sc.next();\n String[] handle = input.split(\"/\");\n if (input.contains(\"//\") || handle.length > 2 || input.charAt(input.length() - 1) == '/' || (handle.length == 2 && !isUserName(handle[1].toCharArray())) || handle[0].charAt(handle[0].length() - 1) == '@' || handle[0].contains(\"@@\")) {\n System.out.println(\"NO\");\n return;\n }\n String[] one = handle[0].split(\"@\");\n if (one.length != 2 || !isUserName(one[0].toCharArray()) || one[1].length() > 32 || one[1].charAt(0) == '.' || one[1].charAt(one[1].length() - 1) == '.' || one[1].contains(\"..\")) {\n System.out.println(\"NO\");\n return;\n }\n String[] three = one[1].split(\".\");\n for (String x : three)\n if (!isUserName(x.toCharArray())) {\n System.out.println(\"NO\");\n return;\n }\n System.out.println(\"YES\");\n out.close();\n out.flush();\n }\n\n static boolean isUserName(char[] x) {\n if (x.length == 0 || x.length > 16) return false;\n\n for (char c : x) {\n if (c != '_' && !isDigit(c) && !isLetter(c)) {\n return false;\n }\n }\n return true;\n }\n\n static boolean isDigit(char c) {\n return c >= '0' && c <= '9';\n }\n\n static boolean isLetter(char c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\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}import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n String input = sc.next();\n String[] handle = input.split(\"/\");\n if (input.contains(\"//\") || handle.length > 2 || input.charAt(input.length() - 1) == '/' || (handle.length == 2 && !isUserName(handle[1].toCharArray())) || handle[0].charAt(handle[0].length() - 1) == '@' || handle[0].contains(\"@@\")) {\n System.out.println(\"NO\");\n return;\n }\n String[] one = handle[0].split(\"@\");\n if (one.length != 2 || !isUserName(one[0].toCharArray()) || one[1].length() > 32 || one[1].charAt(0) == '.' || one[1].charAt(one[1].length() - 1) == '.' || one[1].contains(\"..\")) {\n System.out.println(\"NO\");\n return;\n }\n String[] three = one[1].split(\".\");\n for (String x : three)\n if (!isUserName(x.toCharArray())) {\n System.out.println(\"NO\");\n return;\n }\n System.out.println(\"YES\");\n out.close();\n out.flush();\n }\n\n static boolean isUserName(char[] x) {\n if (x.length == 0 || x.length > 16) return false;\n\n for (char c : x) {\n if (c != '_' && !isDigit(c) && !isLetter(c)) {\n return false;\n }\n }\n return true;\n }\n\n static boolean isDigit(char c) {\n return c >= '0' && c <= '9';\n }\n\n static boolean isLetter(char c) {\n return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');\n }\n\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream system) {\n br = new BufferedReader(new InputStreamReader(system));\n }\n\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public char nextChar() throws IOException {\n return next().charAt(0);\n }\n\n public Long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n\n public int[] nextIntArray(int n) throws IOException {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public long[] nextLongArray(int n) throws IOException {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n\n\n public Integer[] nextIntegerArray(int n) throws IOException {\n Integer[] a = new Integer[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public double[] nextDoubleArray(int n) throws IOException {\n double[] ans = new double[n];\n for (int i = 0; i < n; i++)\n ans[i] = nextDouble();\n return ans;\n }\n\n public short nextShort() throws IOException {\n return Short.parseShort(next());\n }\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf7307d16f0a6c06695cc6666953c82f", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\n\npublic class Main {\n //StreamTokenizer in;\n BufferedReader in;\n PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n\n void run() throws IOException {\n //in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n doit();\n out.flush();\n }\n\n void doit() throws IOException {\n String s = in.readLine().trim();\n String r = \"@\";\n String[] tmp = s.split(r);\n if(tmp.length != 2) {\n out.println(\"NO\");\n return;\n }\n else {\n if(!isUsername(tmp[0])) {\n out.println(\"NO\");\n return;\n }\n else {\n r = \"/\";\n tmp = tmp[1].split(r);\n if(tmp.length > 2) {\n out.println(\"NO\");\n return;\n }\n else {\n if(!isHostname(tmp[0])) {\n out.println(\"NO\");\n return;\n }\n else {\n if(tmp.length == 2) {\n if(!isUsername(tmp[1])) {\n out.println(\"NO\");\n return;\n }\n }\n }\n }\n }\n }\n out.println(\"YES\");\n }\n\n boolean isUsername(String s) {\n if(s.length() > 16 || s.length() < 1) return false;\n for(int i = 0; i < s.length(); i++)\n if(!(s.charAt(i) >= '0' && s.charAt(i) <= '9' || s.charAt(i) >= 'a' && s.charAt(i) <= 'z' ||\n s.charAt(i) >= 'A' && s.charAt(i) <= 'Z' || s.charAt(i) == '_')) return false;\n return true;\n }\n boolean isHostname(String s) {\n if(s.length() > 32 || s.length() < 1 || s.charAt(s.length() - 1) == '.') return false;\n String r = \".\";\n String[] tmp = s.split(r);\n for (String aTmp : tmp) if (!isUsername(aTmp)) return false;\n return true;\n }\n //int ni() throws IOException { in.nextToken(); return (int) in.nval; }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec556a2882c91306d34360da8f395fc8", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0} {"lang": "Java 6", "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 void init() throws IOException\n {\n //input = new BufferedReader(new FileReader(file + \".in\"));\n input = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new BufferedOutputStream(System.out));\n }\n \n void solve() throws IOException\n {\n String s = next();\n if(!s.contains(\"@\"))\n {\n System.out.println(\"NO\");\n return;\n }\n String[] str = s.split(\"@\")\n if(str.length > 2)\n {\n System.out.println(\"NO\");\n return;\n }\n if(!good(str[0]))\n {\n System.out.println(\"NO\");\n return;\n }\n if(str[1].contains(\"/\"))\n {\n String[] ss = str[1].split(\"/\");\n if(ss.length != 2)\n {\n System.out.println(\"NO\");\n return;\n }\n if(!good(ss[1]))\n {\n System.out.println(\"NO\");\n return;\n }\n check(ss[0]);\n }\n check(str[1]);\n System.out.println(\"YES\");\n }\n \n void check(String s)\n {\n if(s.length() <= 0 || s.length() > 32)\n {\n System.out.println(\"NO\");\n System.exit(0);\n }\n String[] sss = s.split(\".\");\n for(int i = 0; i < sss.length; i++)\n if(!good(sss[i]))\n {\n System.out.println(\"NO\");\n System.exit(0);\n }\n }\n \n boolean good(String s)\n {\n return s.length() > 0 && s.length() <= 16 && s.matches(\"[a-zA-Z0-9_]+\");\n }\n \n String next() throws IOException\n {\n if(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 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 solve();\n out.close(); \n }\n catch(Exception e)\n {\n e.printStackTrace();\n System.exit(1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "13039d4b19bd142990fdd5a183230629", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.Math;\nimport java.util.regex.*;\n\npublic class Main{\n public static void main(String []args){\n Scanner s = new Scanner(System.in);\n String id = s.nextLine();\n String pattern = \"^[a-zA-Z0-9_]+@([a-zA-Z0-9_]{1,16})(\\.[a-zA-Z0-9_]{1,16})?(\\/[a-zA-Z0-9_]{1,16})?$\";\n Pattern p = Pattern.compile(pattern);\n Matcher m = p.matcher(id);\n if(m.find()){\n System.out.println(\"YES\");\n }else System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "edef96e74ea5517d19e54e60fa1dae68", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class MessMakers {\n\tstatic long tree[];\n\n\tstatic long read(int idx) {\n\t\tlong sum = 0;\n\t\twhile (idx > 0) {\n\t\t\tsum += tree[idx];\n\t\t\tidx -= (idx & -idx);\n\t\t}\n\t\treturn sum;\n\t}\n\n\tstatic void update(int idx, long val) {\n\t\twhile (idx <= tree.length) {\n\t\t\ttree[idx] += val;\n\t\t\tidx += (idx & -idx);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tInputReader r = new InputReader(System.in);\n\t\tint n = r.nextInt();\n\t\tint k = Math.min(n / 2, r.nextInt());\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tarr[i] = i + 1;\n\t\t}\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint temp = arr[i];\n\t\t\tarr[i] = arr[n - 1 - i];\n\t\t\tarr[n - 1 - i] = temp;\n\t\t}\n\t\ttree = new long[n * 2];\n\t\tlong res = 0;\n\t\tfor (int j = n - 1; j >= 0; j--) {\n\t\t\tlong x = read(arr[j] - 1);\n\t\t\tres += x;\n\t\t\tupdate(arr[j], 1);\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\n\tstatic class InputReader {\n\t\tprivate BufferedReader reader;\n\t\tprivate StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic InputReader(FileReader stream) {\n\t\t\treader = new BufferedReader(stream);\n\t\t\ttokenizer = null;\n\t\t}\n\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\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ea0d79ebba7248746e81f546c94b249", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class messMakers {\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\tint cows[] = new int[n];\n\t\tinput.close();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcows[i] = i;\n\t\t}\n\t\tint j=n-1;\n\t\tfor (int i = 0; i < k; i++){\n\t\t\tint temp=cows[i];\n\t\t\tcows[i]=cows[j];\n\t\t\tcows[j]=temp;\n\t\t\tj--;\n\t\t\t\n\t\t}\n\t\tint mess=0;\n\t\tfor (int i = 0; i < n-1; i++){\n\t\t\tfor (int l = i+1; l < n; l++){\n\t\t\t\tif(cows[i]>cows[l]){\n\t\t\t\t\tmess++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\tSystem.out.println(mess);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3c7e81b9e5b4fd9a1089b564cf273cb2", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "package codeforces;\nimport java.io.*;\nimport java.util.*;\nimport java.*;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Random;\nimport java.lang.*;\n\n\n \npublic class zadacha {\nprivate static BufferedReader in;\nprivate static StringTokenizer tok;\nprivate static PrintWriter out;\nfinal static boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") !=null;\n \npublic static void init() throws FileNotFoundException{\nif(ONLINE_JUDGE){\nin = new BufferedReader(new InputStreamReader(System.in));\nout = new PrintWriter(System.out);\n}\nelse{\nin = new BufferedReader(new FileReader(\"input.txt\"));\nout = new PrintWriter(\"out.txt\");\n}\n}\n \nprivate static String readString() throws IOException {\nwhile (tok == null || !tok.hasMoreTokens()) {\ntok = new StringTokenizer(in.readLine());\n}\nreturn tok.nextToken();\n}\n \nprivate static int readInt() throws IOException {\nreturn Integer.parseInt(readString());\n}\nprivate static double readDouble() throws IOException {\nreturn Double.parseDouble(readString());\n}\nprivate static long readLong() throws IOException {\nreturn Long.parseLong(readString());\n}\nprivate static float readFloat() throws IOException{\n return Float.parseFloat(readString());\n}\n \npublic static void Solve() throws IOException{\n \n\tint n =readInt();\n\tint k = readInt();\n\t\n\tif(k<= n/2){\n\t\tout.print((n-1)*n/2);\n\t\treturn;\n\t}\n\tif(n==1){\n\t\tout.print(0);\n\t\treturn;\n\t}\n\t\n\tout.print(k*(2*n+1)-3*k*k);\n\t\n}\n\npublic static void main(String[] args) throws IOException {\ninit();\nSolve();\n \n \nin.close();\nout.close();\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f09dbf9abbc514a59cd2e8b71b29bb91", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Scanner;\npublic class Main {\npublic static void main(String args[])throws IOException\n{\n\tScanner s1=new Scanner(System.in);\n\tint n=Integer.parseInt(s1.next());\n\tint k=Integer.parseInt(s1.next());\n\tlong cows[]=new long[n];\n\tlong counter=0;\n\tfor(int i=0;i=n)\n\t\t\tbreak;\n\t}\n\tfor(int i=0;icows[z])\n\t\t\t\tcounter++;\n\t\t}\n\t}\n\t/*\n\tfor(int i=0;i0)\n fullCount=fullCount+arr5[j*i];\n else\n for( k=1;k<=c;k++)\n {\n int count=0;\n if(arr[k*j*i]>0)\n {\n fullCount=fullCount+arr[k*j*i];\n count5+=arr[k*j*i];\n }\n else\n {\n for( v=k*j*i;v>0;v--) \n {\n if((k*j*i)%v==0) \n count++; \n }\n arr[k*j*i]=count;\n count5+=count;\n }\n }\n arr5[j*i]=count5;\n } \n }\n for(int z=1;z 1) sum *= 2;\n return sum;\n }\n \n public static void main(String args[]) {\n getprime();\n Scanner cin = new Scanner(System.in);\n int a = cin.nextInt(); int b = cin.nextInt();\n int c = cin.nextInt();\n long sum = 0;\n long mod = 1073741824;\n for (int i = 1; i <= a; i++) {\n for (int j = 1; j <= b; j++) {\n for (int k = 1; k <= c; k++) {\n sum += solve(i * j * k);\n sum %= mod;\n }\n }\n }\n System.out.println(sum);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1608de1b94aa3b57db303f21fd381bf2", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "public class Main {\n\n\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n String str = sc.next();\n int mas[] = new int[a];\n int ch = 0;\n\n for (int i = 0; i < str.length(); i++) {\n if(str.charAt(i) == '0'){\n mas[i] = 0;\n }else{\n mas[i] = 1;\n }\n }\n // System.out.println(str);\n /* for (int i = 0; i < a; i++) {\n System.out.print(mas[i] + \" \");\n }\n */\n for (int i = a - 1; i > 0; i--) {\n if(mas[i] == 1 && mas[i - 1] == 0){\n mas[i - 1] = 1;\n mas[i] = 0;\n }else if(mas[i] == 1 && mas[i - 1] == 1){\n mas[i] = 0;\n ch++;\n }\n }\n\n for (int i = 0; i < a - ch; i++) {\n System.out.print(mas[i]);\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6b2c48f399f4a35cbe0baca356d192b9", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class P976A{\n\tpublic static void main(String args[]){\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint n = sc.nextInt();\n\t\tint string = sc.nextLine();\n\n\t\tint counter = 0;\n\t\tfor(int i=0; i l[];\n public static int n,m,q,k,t,a[],b[],arr[],cnt[],chosen[],pos[],val[],blocksize,count;\n public static long V[],low,high,min=Long.MAX_VALUE,cap[],has[],ans,max,pre[];\n public static ArrayList adj[],al;\n public static TreeSet ts;\n public static char s[];\n public static int depth,mini,maxi;\n public static boolean visit[][],isPrime[],used[];\n public static int[][] dist;\n public static ArrayListprime;\n public static int[] x={0,1};\n public static int[] y={-1,0};\n public static ArrayList divisor[]=new ArrayList[1500005];\n public static int[][] subtree,parent,mat;\n public static TreeMap tm;\n public static LongPoint[] p;\n public static int[][] grid,memo;\n public static ArrayList list;\n public static TrieNode root;\n public static LinkedHashMap map;\n public static ArrayList al1;\n public static int upper=(int)(1e7);\n public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n public static void main(String[] args) throws Exception\n {\n \t InputReader in = new InputReader(System.in);\n\t PrintWriter pw=new PrintWriter(System.out);\n\t n=in.ii();\n\t s=in.is().toCharArray();\n\t int z=0;\n\t for(char c:s)if(c=='0')z++;\n\t int o=n-z;\n\t String s=\"\";\n\t for(int i=0;i0) s='1'+s;\n\t else s='0';\n\t pw.println(s);\n\t /* n=in.ii();\n\t long ans=0;\n\t Point[] p=new Point[n];\n\t for(int i=0;i 1) return b;\n\t return a.plus(b.minus(a).mul(r));\n\t}\n}\n\npublic static class Point {\n\tpublic double x, y;\n\n\tpublic Point(double x, double y) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t}\n\n\tpublic Point minus(Point b) {\n\t\treturn new Point(x - b.x, y - b.y);\n\t}\n\t\n\tpublic Point plus(Point a){\n\t\treturn new Point(x + a.x, y + a.y);\n\t}\n\n\tpublic double cross(Point b) {\n\t\treturn (double)x * b.y - (double)y * b.x;\n\t}\n\n\tpublic double dot(Point b) {\n\t\treturn (double)x * b.x + (double)y * b.y;\n\t}\n\t\n\tpublic Point mul(double r){\n\t\treturn new Point(x * r, y * r);\n\t}\n\t\n\tpublic double dist(Point p){\n\t\treturn Math.sqrt(fastHypt( x - p.x , y - p.y));\n\t}\n\t\n\tpublic double fastHypt(double x, double y){\n\t\treturn x * x + y * y;\n\t}\n}\nstatic class Query implements Comparable{\n\tint index,k;\n\tint L;\n\tint R;\n\tpublic Query(){}\n\tpublic Query(int a,int b,int index)\n\t{\n\t this.L=a;\n\t this.R=b;\n\t this.index=index;\n\t}\n public int compareTo(Query o)\n {\n\t if(L/blocksize!=o.L/blocksize)return L/blocksize-o.L/blocksize;\n\t else return R-o.R;\n }\n \n }\n\nstatic double dist(Point p1,Point p2)\n{\n\treturn Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));\n}\n\nstatic class coder {\n\tint indx;\n\tString name;\n\tcoder(int indx,String name)\n\t{\n\t\tthis.indx=indx;\n\t\tthis.name=name;\n\t}\n}\nstatic class TrieNode\n{\n\tint value; // Only used in leaf nodes\n\tint freq;\n\tTrieNode[] arr = new TrieNode[2];\n\tpublic TrieNode() {\n\t\tvalue = 0;\n\t\tfreq=0;\n\t\tarr[0] = null;\n\t\tarr[1] = null;\n\t}\n}\nstatic void insert(int pre_xor,int add)\n{\n\tTrieNode temp = root;\n\t\n\t// Start from the msb, insert all bits of\n\t// pre_xor into Trie\n\tfor (int i=31; i>=0; i--)\n\t{\n\t\t// Find current bit in given prefix\n\t\tint val = (pre_xor & (1<=1 ? 1 : 0;\n\t\t\n\t\t// Create a new node if needed\n\t\tif (temp.arr[val] == null)\n\t\t\ttemp.arr[val] = new TrieNode();\n\t\t\n\t\ttemp = temp.arr[val];\n\t\ttemp.freq+=add;\n\t}\n \n\t// Store value at leaf node\n\t//temp.value = pre_xor;\n}\n\nstatic long query(int pre_xor)\n{\n\tTrieNode temp = root;\n\tlong ans=0;\n\tfor (int i=31; i>=0; i--)\n\t{\n\t\t// Find current bit in given prefix\n\t\tint val = (pre_xor & (1<= 1 ? 1 : 0;\n\t\t\n\t\tif(temp.arr[1-val]!=null&&temp.arr[1-val].freq>0)\n\t\t{\n\t\t\tans|=1l<0)\n temp=temp.arr[val];\n\t\telse break;\n\t}\n\treturn ans;\n}\nstatic void update(int indx,long val)\n {\n\t while(indx0)\n\t {\n\t\t sum+=BIT[indx];\n\t\t indx-=(indx&(-indx));\n\t }\n\t return sum;\n\t}\n \n\nstatic int gcd(int a, int b) \n{\n\tint res=0;\n\twhile(a!=0)\n\t{\n\t\tres=a;\n\t\ta=b%a;\n\t\tb=res;\n\t}\n\treturn b;\n}\nstatic slope getSlope(Point p, Point q)\n\t{\n\t\tint dx = (int)(q.x - p.x), dy = (int)(q.y - p.y);\n\t\tint g = gcd(dx, dy);\n\t\treturn new slope(dy / g, dx / g);\n\t}\n\t\nstatic class slope implements Comparable\n{\n\tint x,y;\n\tpublic slope(int y,int x)\n\t{\n\t\tthis.x=x;\n\t\tthis.y=y;\n\t}\n\tpublic int compareTo(slope s)\n\t{\n\t\tif(s.y!=y)return y-s.y;\n\treturn x-s.x;\n\t}\n}\n\nstatic class Ball implements Comparable\n\t{\n\t\tint r;\n\t\tint occ;\n\t\tpublic Ball(int r,int occ)\n\t\t{\n\t\t\tthis.r = r;\n\t\t\tthis.occ = occ;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Object o) {\n\t\t\tBall b = (Ball) o;\n\t\t\treturn b.occ-this.occ;\n\t\t}\n\t}\n\nstatic class E implements Comparable{\n\tint x,y;\n\tchar c;\n\tE(int x,int y,char c)\n\t{\n\t\tthis.x=x;\n\t\tthis.y=y;\n\t\tthis.c=c;\n\t}\n\tpublic int compareTo(E o)\n\t{\n\t\tif(x!=o.x)return o.x-x;\n\t\telse return y-o.y;\n\t\t\n\t}\n}\n\nstatic ArrayList dfs(String s,String[] sarr,HashMap> map)\n{\n if(map.containsKey(s))return map.get(s);\n ArrayList res=new ArrayList<>();\n if(s.length()==0)\n {\n\t res.add(\"\");\n\t return res;\n }\n\n for(String word:sarr)\n {\n\t if(s.startsWith(word))\n\t {\n\t\t ArrayList sub=dfs(s.substring(word.length()),sarr,map);\n\t\t for(String s2:sub)\n\t\t {\n\t\t\t res.add(word+ (s2.isEmpty() ? \"\" : \" \")+s2);\n\t\t }\n\t }\n }\n map.put(s,res);\n return res;\n}\nstatic class SegmentTree{\n \n int n;\n int max_bound;\n \n public SegmentTree(int n)\n {\n\t\n\t this.n=n;\n\t tree=new long[4*n+1];\n\t build(1,0,n-1);\n }\nvoid build(int c,int s,int e)\n{\n if(s==e)\n {\n\t tree[c]=arr[s];\n\t return ;\n }\n\n int mid=(s+e)>>1;\n build(2*c,s,mid);\n build(2*c+1,mid+1,e);\n tree[c]=(tree[2*c]&tree[2*c+1]);\n}\nvoid put(int c,int s, int e,int l,int r,int v) {\n\tif(l>e||re)return ;\n\tif (s == e) \n\t{\n\t\ttree[c] = arr[s]^v;\n\t\treturn;\n\t}\n\tint mid = (s + e) >> 1;\n\tif (l>mid) put(2*c+1,m+1, e , l,r, v);\n\telse if(r<=mid)put(2*c,s,m,l,r , v);\n\telse{\n \n\t}\n\t\n}\nlong query(int c,int s,int e,int l,int r)\n{\n if(er)return 0L;\n\n if(s>=l&&e<=r)\n {\n\treturn tree[c];\n }\n\n\tint mid=(s+e)>>1;\n\tlong ans=(1l<<30)-1;\n\tif(l>mid)return query(2*c+1,mid+1,e,l,r);\n\telse if(r<=mid)return query(2*c,s,mid,l,r);\n\telse{\n\t\treturn query(2*c,s,mid,l,r)&query(2*c+1,mid+1,e,l,r);\n\t}\n\n }\n} \n\n \n public static ListNode removeNthFromEnd(ListNode a, int b) {\n \n int cnt=0;\n\tListNode ra1=a;\n\tListNode ra2=a;\n\twhile(ra1!=null){ra1=ra1.next; cnt++;}\n\t\n\tif(b>cnt)return a.next;\n\telse if(b==1&&cnt==1)return null;\n\telse{\n\t\tint y=cnt-b+1;\n\t\tint u=0;\n\t\tListNode prev=null;\n\t\twhile(a!=null)\n\t\t{\n\t\t\tu++;\n\t\t if(u==y)\n\t\t {\n\t\t\t if(a.next==null)prev.next=null;\n\t\t\t else\n\t\t\t {\n\t\t\t\t if(prev==null)return ra2.next;\n\t\t\t\t prev.next=a.next;\n\t\t\t\t a.next=null;\n\t\t\t }\n\t\t\t break;\n\t\t }\n\t\t prev=a;\n\t\t a=a.next;\n\t\t}\n\t}\n\treturn ra2;\n}\n static ListNode rev(ListNode a)\n {\n ListNode prev=null;\n ListNode cur=a;\n ListNode next=null;\n while(cur!=null)\n {\n next=cur.next;\n cur.next=prev;\n prev=cur;\n cur=next;\n }\n return prev;\n }\n \n static class ListNode {\n\t public int val;\n\t public ListNode next;\n\t ListNode(int x) { val = x; next = null; }\n\t }\n \n \n public static String add(String s1,String s2)\n {\n\t int n=s1.length()-1;\n\t int m=s2.length()-1;\n\t int rem=0;\n\t int carry=0;\n\t int i=n;\n\t int j=m;\n\t String ans=\"\";\n\t while(i>=0&&j>=0)\n\t {\n\t\t int c1=(int)(s1.charAt(i)-'0');\n\t\t int c2=(int)(s2.charAt(j)-'0');\n\t\t int sum=c1+c2;\n\t\t sum+=carry;\n\t\t rem=sum%10;\n\t\t carry=sum/10;\n ans=rem+ans;\n\t\t i--; j--;\n\t\t \n\t }\n\t while(i>=0)\n\t {\n\t\tint c1=(int)(s1.charAt(i)-'0');\n\t\n\t\tint sum=c1;\n\t\tsum+=carry;\n\t\trem=sum%10;\n\t\tcarry=sum/10;\n\t\tans=rem+ans;\n\t\ti--;\n\t }\n\t while(j>=0)\n\t {\n\t\n\t\tint c2=(int)(s2.charAt(j)-'0');\n\t\tint sum=c2;\n\t\tsum+=carry;\n\t\trem=sum%10;\n\t\tcarry=sum/10;\n\t\tans=rem+ans;\n\t\tj--;\n\t }\n\n\t if(carry>0)ans=carry+ans;\n\t return ans;\n }\n public static String[] multiply(String A, String B) {\n\tint lb=B.length();\n\tchar[] a=A.toCharArray();\n\tchar[] b=B.toCharArray();\n\tString[] s=new String[lb];\n\tint cnt=0;\n\tint y=0;\n\tString s1=\"\";\nq=0;\n\tfor(int i=b.length-1;i>=0;i--)\n\t{\n\t\tint rem=0;\n\t\tint carry=0;\n\t\t\n\t\n\t\tfor(int j=a.length-1;j>=0;j--)\n\t\t{\n\t\t\tint mul=(int)(b[i]-'0')*(int)(a[j]-'0');\n\t\t\tmul+=carry;\n\t\t\trem=mul%10;\n\t\t\tcarry=mul/10;\n\t\t\ts1=rem+s1;\n\t\t}\n\t\ts1=carry+s1;\n\t\ts[y++]=s1;\n\t\tq=Math.max(q,s1.length());\n\t\ts1=\"\";\n\t\tfor(int i1=0;i1=1)\n // return true;\n\t \t }\n\t }\n\t \n\t // return b; \n return dp[0][n-1];\n\t \n }\n \n \n\n static long divCeil(long a,long b)\n {\n return (a+b-1)/b;\n }\n static long root(int pow, long x) {\n long candidate = (long)Math.exp(Math.log(x)/pow);\n candidate = Math.max(1, candidate);\n while (pow(candidate, pow) <= x) {\n candidate++;\n }\n return candidate-1;\n }\n \n static long pow(long x, int pow)\n {\n long result = 1;\n long p = x;\n while (pow > 0) {\n if ((pow&1) == 1) {\n if (result > Long.MAX_VALUE/p) return Long.MAX_VALUE;\n result *= p;\n }\n pow >>>= 1;\n if (pow > 0 && p >= 4294967296L) return Long.MAX_VALUE;\n p *= p;\n }\n return result;\n }\n \n static boolean valid(int i,int j)\n {\n\t if(i>=0&&i=0&&j target)\n high = mid - 1;\n else\n low = mid;\n }\n return nums[low] == target ? low : -1;\n }\n public static boolean palin(String s)\n\t{\n\t int i=0;\n\t int j=s.length()-1;\n\t while(i=m)\n\t result%=m;\n\t p >>=1;\n\t n*=n;\n\t if(n>=m)\n\t n%=m;\n\t}\n\treturn result;\n}\n\n /**\n *\n * @param n\n * @param p\n * @return\n */\n public static long pow(long n,long p)\n {\n\tlong result = 1;\n\t if(p==0)\n\t return 1;\n\tif (p==1)\n\t return n;\n\twhile(p!=0)\n\t{\n\t if(p%2==1)\n\t result *= n;\n\t p >>=1;\n\t n*=n;\n\t}\n\treturn result;\n\n }\n\n\n\n\nstatic class Edge implements Comparator {\n\tprivate int u;\n\tprivate int v;\n\tprivate long w;\n\tpublic Edge() {\n\t}\n\tpublic Edge(int u, int v, long w) {\n\t\tthis.u=u;\n\t\tthis.v=v;\n\t\tthis.w=w;\n\t}\n\tpublic int getU() {\n\t\treturn u;\n\t}\n\tpublic void setU(int u) {\n\t\tthis.u = u;\n\t}\n\tpublic int getV() {\n\t\treturn v;\n\t}\n\tpublic void setV(int v) {\n\t\tthis.v = v;\n\t}\n\tpublic long getW() {\n\t\treturn w;\n\t}\n\tpublic void setW(int w) {\n\t\tthis.w = w;\n\t }\n\tpublic long compareTo(Edge e)\n\t {\n\t\treturn (this.getW() - e.getW());\n\t}\n\n @Override\n public int compare(Edge o1, Edge o2) {\n throw new UnsupportedOperationException(\"Not supported yet.\"); //To change body of generated methods, choose Tools | Templates.\n }\n\t\n}\n\n\n\nstatic class Pair implements Comparable\n{\n\tint x,y;\n\tPair (int a,int b)\n\t{\n\t\tthis.x=a;\n\t\tthis.y=b;\n\t}\n\n\tpublic int compareTo(Pair o) {\n\t\t// TODO Auto-generated method stub\n\t\tif(this.x!=o.x)\n\t\treturn -Integer.compare(this.x,o.x);\n\t\telse\n\t\t\treturn -Integer.compare(this.y, o.y);\n\t\t//return 0;\n\t}\n\tpublic boolean equals(Object o) {\n if (o instanceof Pair) {\n Pair p = (Pair)o;\n return p.x == x && p.y == y;\n }\n return false;\n }\n public int hashCode() {\n return new Integer(x).hashCode() * 31 + new Integer(y).hashCode();\n }\n}\n\nstatic class InputReader\n{\n private InputStream stream;\n private byte[] buf = new byte[1024];\n\n private SpaceCharFilter filter;\n byte inbuffer[] = new byte[1024];\n int lenbuffer = 0, ptrbuffer = 0;\n final int M = (int) 1e9 + 7;\n int md=(int)(1e7+1);\n int[] SMP=new int[md];\n final double eps = 1e-6;\n final double pi = Math.PI;\n\n\tPrintWriter out;\n String check = \"\";\n InputStream obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());\n public InputReader(InputStream stream)\n {\n this.stream = stream;\n }\n\n int readByte() {\n\t if (lenbuffer == -1) throw new InputMismatchException();\n\t if (ptrbuffer >= lenbuffer) {\n\t ptrbuffer = 0;\n\t try {\n\t lenbuffer = obj.read(inbuffer);\n\t } catch (IOException e) {\n\t throw new InputMismatchException();\n\t }\n\t }\n\t if (lenbuffer <= 0) return -1;\n\t return inbuffer[ptrbuffer++];\n }\n\n public int read()\n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n String is() {\n\t int b = skip();\n\t StringBuilder sb = new StringBuilder();\n\t while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')\n\t {\n\t sb.appendCodePoint(b);\n\t b = readByte();\n\t }\n\t return sb.toString();\n }\n public int ii() {\n\t int num = 0, b;\n\t boolean minus = false;\n\t while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n\t if (b == '-') {\n\t minus = true;\n\t b = readByte();\n\t }\n\t while (true) {\n\t if (b >= '0' && b <= '9') {\n\t num = num * 10 + (b - '0');\n\t } else {\n\t return minus ? -num : num;\n\t }\n\t b = readByte();\n\t }\n }\n public long il() {\n\t long num = 0;\n\t int b;\n\t boolean minus = false;\n\t while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n\t if (b == '-') {\n\t minus = true;\n\t b = readByte();\n\t }\n\t while (true) {\n\t if (b >= '0' && b <= '9') {\n\t num = num * 10 + (b - '0');\n\t } else {\n\t return minus ? -num : num;\n\t }\n\t b = readByte();\n\t }\n }\n \n\t boolean isSpaceChar(int c) {\n\t return (!(c >= 33 && c <= 126));\n\t }\n\n\t int skip()\n\t {\n\t int b;\n\t while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n\t return b;\n\t }\n\n\t float nf() {\n\t return Float.parseFloat(is());\n\t }\n\n\t double id() {\n\t return Double.parseDouble(is());\n\t }\n\n\t char ic() {\n\t return (char) skip();\n\t }\n\n\t int[] iia(int n) {\n\t int a[] = new int[n];\n\t for (int i = 0; i= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic 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 ArrayUtils {\n\n\tpublic static void fill(double[][] array, double value) {\n\t\tfor (double[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\t}\n\u00a0", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2c47c2d17ca1d88bed25cc459f62e9e9", "src_uid": "7adb8bf6879925955bf187c3d05fde8c", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.util.Arrays;\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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tprivate double[][] answer;\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint whiteCount = in.readInt();\n\t\tint blackCount = in.readInt();\n\t\tanswer = new double[whiteCount + 1][blackCount + 1];\n\t\tArrayUtils.fill(answer, -1);\n\t\tout.printLine(go(whiteCount, blackCount));\n\t}\n\n\tprivate double go(int whiteCount, int blackCount) {\n\t\tif (answer[whiteCount][blackCount] != -1)\n\t\t\treturn answer[whiteCount][blackCount];\n\t\tanswer[whiteCount][blackCount] = 0;\n\t\tint remainingBlack = blackCount;\n\t\tdouble remainingProbability = 1;\n\t\tif (whiteCount == 0)\n\t\t\treturn 0;\n\t\tanswer[whiteCount][blackCount] += (double)whiteCount / (whiteCount + blackCount);\n\t\tif (remainingBlack == 0)\n\t\t\treturn answer[whiteCount][blackCount];\n\t\tremainingProbability *= (double)remainingBlack / (whiteCount + remainingBlack);\n\t\tremainingBlack--;\n\t\tif (remainingBlack == 0)\n\t\t\treturn answer[whiteCount][blackCount];\n\t\tremainingProbability *= (double)remainingBlack / (whiteCount + remainingBlack);\n\t\tremainingBlack--;\n\t\tif (remainingBlack == 0)\n\t\t\treturn answer[whiteCount][blackCount] += remainingProbability;\n\t\treturn answer[whiteCount][blackCount] += remainingProbability * ((double)whiteCount / (whiteCount + remainingBlack) * go(whiteCount - 1, remainingBlack) +\n\t\t\t(double)remainingBlack / (whiteCount + remainingBlack) * go(whiteCount, remainingBlack - 1));\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 ArrayUtils {\n\n\tpublic static void fill(double[][] array, double value) {\n\t\tfor (double[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\t}\n\u00a0", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d52d552a6bb07c12fa45eac789dd0e66", "src_uid": "7adb8bf6879925955bf187c3d05fde8c", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "public class Triv3 {\n \n private static final double EPSILON = 0.000000000001;\n \n public static void main(String[] args) {\n try {\n java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));\n \n String line= stdin.readLine();\n \n Scanner s = new Scanner(line);\n \n int w = s.nextInt();\n int b = s.nextInt();\n \n double victoryChance = princessDraws(w, b);\n \n System.out.println(victoryChance);\n \n } catch (IOException ex) {\n Logger.getLogger(Triv3.class.getName()).log(Level.SEVERE, null, ex);\n }\n }\n \n \n public static double princessDraws(int w, int b) {\n\n if(w==0)\n return 0.0;\n if(b<=0)\n return 1.0;\n \n double chancetoDrawWhite = (double)w / ((double)w + (double)b);\n double chancetoDrawBlack = (double)b / ((double)w + (double)b);\n \n return chancetoDrawWhite + chancetoDrawBlack * dragonDraws(w,b-1);\n }\n \n public static double dragonDraws(int w, int b) {\n\n if(w==0 || b==0)\n return 0.0;\n\n double chancetoDrawBlack = (double)b / ((double)w + (double)b);\n \n double chanceBlackJumps = ((double)(b-1)) / ((double)(b-1) + (double)w);\n \n return chancetoDrawBlack * \n (chanceBlackJumps*princessDraws(w,b-2)+(1.0-chanceBlackJumps)*princessDraws(w-1,b-1));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3e6c22ab6a84cb13ead36888d5055f58", "src_uid": "7adb8bf6879925955bf187c3d05fde8c", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import sun.plugin.javascript.navig.Array;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class D implements Runnable {\n private double ans[][];\n\n private void solve() throws IOException {\n int W = nextInt();\n int B = nextInt();\n ans = new double[W+1][B+1];\n for(int i = 0; i <= W; ++i)\n Arrays.fill(ans[i], -1);\n writer.printf(\"%.20f\\n\", getAns(W, B));\n }\n\n private double getAns(int W, int B) {\n if(W <= 0) return 0;\n if(B <= 0) return 1;\n if(ans[W][B] != -1) return ans[W][B];\n double res = 1.0 * W / (W + B);\n double tmp = 1.0 * B / (W + B);\n --B;\n tmp *= 1.0 * B / (W + B);\n --B;\n if (tmp > 1e-13) {\n double b = getAns(W, B - 1) * (B * 1.0 / (W + B));\n double w = getAns(W - 1, B) * (W * 1.0 / (W + B));\n res += tmp * (b + w);\n }\n ans[W][B] = res;\n return res;\n }\n\n public static void main(String[] args) {\n new D().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 writer = new PrintWriter(System.out);\n tokenizer = null;\n // reader = new BufferedReader(new FileReader(\"input.txt\"));\n // writer = new PrintWriter(new FileWriter(\"output.txt\"));\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "88d80f18851a38aaa46322c2d5c60d9a", "src_uid": "7adb8bf6879925955bf187c3d05fde8c", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner sc = new Scanner(System.in);\n int mod = 1000000007;\n int r = sc.nextInt();\n int g = sc.nextInt();\n int n = (int)Math.floor((Math.pow(8*(r+g)+1, 0.5)-1)/2);\n int firstdp[] = new int[n*(n+1)/2+1];\n int seconddp[] = new int[n*(n+1)/2+1];\n int temp[] = new int[n*(n+1)/2+1];\n for(int i = 0;i<=n*(n+1)/2;i++){\n firstdp[i]=0;\n seconddp[i]=0;\n }\n firstdp[0]=1;\n for(int i = 1;in*(n+1)/2){\n r=n*(n+1)/2;\n }\n if(g>n*(n+1)/2){\n g=n*(n+1)/2;\n }\n int lower = Math.max(0,n*(n+1)/2-g);\n int upper = Math.min(r,n*(n+1)/2);\n long answer = 0;\n for(int i = lower;i<=upper;i++){\n answer+=(long)(seconddp[i]%(long)mod);\n }\n System.out.println(answer);\n /*System.out.println(\"=============\");\n System.out.println(lower + \" \" + upper);\n System.out.println(\"=============\");\n System.out.println(n);*/\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b4cbf56c8363da12139af7e65505ea9", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class D {\n public static void main(String args[]) {\n\tScanner sc = new Scanner(System.in);\n\tint r = sc.nextInt();\n int g = sc.nextInt();\n\tint spent = 0;\n\tint h = (int) (Math.floor(Math.sqrt((r+g)*2)));\n \n\tlong[][] R = new long[2][r+2];\n\tboolean[][] B = new boolean[2][r+1];\n\tlong mod = 1000000007;\n\tR[0][0] = 1;\n\tB[0][0] = true;\n\tint a = 1; int b = 0;\n\tint highest = 0;\n\tfor (int l = 1; l <= h; l++){\n\t for (int i = 0; i <= B[a][r+1]; i++) {\n\t\tR[a][i] = 0;\n\t\tB[a][i] = false;\n\t }\n\t R[a][r+1] = R[b][r+1] + l;\n\t for (int ch = 0; ch <= R[a][r+1]; ch++) {\n\t\tif (g >= R[a][r+1] - ch && B[b][ch]) {\n\t\t R[a][ch] = (R[a][ch] + R[b][ch]) % mod;\n\t\t B[a][ch] = true;\n\t\t highest = l;\n\t\t}\n\t\tif (r >= l+ch && B[b][ch]) {\n\t\t R[a][ch+l] = (R[b][ch] + R[a][ch+l]) % mod;\n\t\t B[a][ch+l] = true;\n\t\t highest = l;\n\t\t}\n\t }\n\t if (highest < l) break;\n\t a = (a + 1) % 2; b = (b + 1) % 2;\n\t}\n\tlong tot = 0;\n\tfor (int ch = 0; ch < r+1; ch++ ){\n\t if(B[b][ch]) {\n\t\ttot = (tot + R[b][ch]) % mod;\n\t }\n\t}\n\tSystem.out.println(tot);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1a0c0584e0a27d831e533772797083f8", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\nimport com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;\n\n\npublic class Main {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner cin = new Scanner(new BufferedInputStream(System.in));\n PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));\n Task work = new Task(cin, cout);\n work.read();\n work.solve();\n }\n\n}\nclass Task{\n Scanner cin;\n PrintWriter cout;\n final int maxn = 400005;\n final int MOD = 1000000007;\n int []dp = new int[maxn];\n int r, g;\n public Task(Scanner cin, PrintWriter cout) {\n // TODO Auto-generated constructor stub\n this.cin = cin;\n this.cout = cout;\n }\n public void read() {\n r = cin.nextInt();\n g = cin.nextInt();\n }\n int GetHeight(){\n for (int i = 1; ; i++){\n if (i * (i + 1) / 2 > r + g){\n return i-1;\n }\n }\n }\n public void solve(){\n int h = GetHeight();\n int res = 0;\n dp[0] = 1;\n for (int i = 1; i <= h; i++){\n for (int j = r; j >= 0; j--){\n dp[i+j] = (dp[i+j] + dp[j]) % MOD;\n }\n }\n for (int i = Math.max(h*(h+1)/2 - g, 0); i <= r; i++){\n res = (res + dp[i]) % MOD;\n }\n cout.println(res);\n cout.flush();\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a7675f147ad8ad3c414a4669cca50671", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n final boolean isFileIO = false; \n BufferedReader in;\n PrintWriter out;\n StringTokenizer st = new StringTokenizer(\"\");\n String delim = \" \";\n\n public static void main(String[] args) throws IOException {\n Main m = new Main();\n m.initIO();\n m.solve();\n m.in.close();\n m.out.close();\n }\n\n public void initIO() throws IOException {\n if(!isFileIO) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\"); \n }\n }\n \n String nextToken() throws IOException {\n if(!st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken(delim);\n }\n \n String readLine() throws IOException {\n return in.readLine();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n boolean[] sum;\n int r, g;\n public void solve() throws IOException {\n r = nextInt(); g = nextInt();\n int left = 1;\n sum = new boolean[r + 1];\n int right = (int)Math.sqrt(1 + 8 * (r + g)) + 1;\n int mid;\n while(left < right) {\n mid = left + (right - left) / 2;\n if(isOk(mid)) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n if(!isOk(left)) {\n left--;\n }\n int all = (left * (left + 1)) / 2;\n int[] dp = new int[all + 1];\n dp[0] = 1;\n long mod = 1_000_000_007;\n for(int i = 1; i <= left; i++) {\n for(int j = all; j >= i; j--) {\n if(j <= r) {\n dp[j] = (dp[j] + dp[j - i]) % mod;\n }\n }\n }\n int ans = 0;\n for(int i = 0; i <= all; i++) {\n if(all - i <= g) {\n ans = (ans + dp[i]) % mod;\n }\n }\n out.println(ans);\n }\n\n boolean isOk(int h) {\n int n = sum.length;\n for(int i = 0; i < n; i++) {\n sum[i] = false;\n }\n sum[0] = true;\n for(int i = 1; i <= h; i++) {\n for(int j = n - 1; j >= i; j--) {\n sum[j] = sum[j - i];\n }\n }\n int all = (h * (h + 1)) / 2;\n for(int i = 0; i < n; i++) {\n if(sum[i]) {\n if(all - i <= g) {\n return true;\n }\n }\n }\n return false;\n }\n\n}\n\nclass Utils {\n\n public static long binpow(long a, long exp, long mod) {\n if(exp == 0) {\n return 1;\n }\n if(exp % 2 == 0) {\n long temp = binpow(a, exp / 2, mod);\n return (temp * temp) % mod;\n } else {\n return (binpow(a, exp - 1, mod) * a) % mod;\n }\n }\n\n public static long inv(long a, long mod) {\n return binpow(a, mod - 2, mod);\n }\n\n public static long addmod(long a, long b, long mod) {\n return (a + b + 2 * mod) % mod;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8572c0116669cb168daf94edeccadc3a", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class navigation{\n public static void main(String args[]){\n int n,p,k;\n Scanner scan =new Scanner(System.in);\n n=scan.nextInt();\n p=scan.nextInt();\n k=scan.nextInt();\n if(p<1||p>n){\n System.exit(0);\n }\n firstone obj=new firstone();\n obj.method(n,p,k);\n \n }\n}\nclass firstone{\n int n,p,k;\n void method(int n,int p,int k){\n int i;\n this.n=n;\n this.p=p;\n this.k=k;\n if(p-k>0){\n i=p-k;\n }\n else{\n i=1;\n }\n if(p-k>1){\n \n System.out.print(\"<<\");\n System.out.print(\" \");\n }\n \n \n for( ;i>\");\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a4020a582a9f42121b5ce08598c987c1", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null} {"lang": "Java 7", "source_code": "import com.sun.servicetag.SystemEnvironment;\n\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n/**\n * Created with IntelliJ IDEA.\n * User: AUtemuratov\n * Date: 02.04.14\n * Time: 9:44\n * To change this template use File | Settings | File Templates.\n */\npublic class Main {\n\n static int n,p,k;\n static int b[][] = new int[111][111];\n static int a[] = new int[111];\n public static void main (String [] args) throws Exception {\n\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n String s = bf.readLine();\n StringTokenizer tk = new StringTokenizer(s,\" \");\n n = Integer.parseInt(tk.nextToken());\n p = Integer.parseInt(tk.nextToken());\n k = Integer.parseInt(tk.nextToken());\n\n if (p-k>1) {\n System.out.print(\"<< \");\n }\n\n for (int i=p-k; in) break;\n System.out.print(i + \" \");\n }\n\n if (p+k<=n) {\n System.out.print(\">>\");\n }\n\n\n\n\n\n pw.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3496557f8dac3d3509ec4eaea7a2852a", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null} {"lang": "Java 8", "source_code": "public class Main {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int p = sc.nextInt();\n int k = sc.nextInt();\n List list = new ArrayList<>();\n for (int i = p - k; i <= p + k; i++) {\n if (i >= 1 && i <= n) {\n list.add(i);\n }\n }\n StringBuilder sb = new StringBuilder();\n if (list.get(0) != 1) {\n sb.append(\" <<\");\n }\n for (Integer num : list) {\n if (num == p) {\n sb.append(\" (\").append(num).append(\")\");\n } else {\n sb.append(\" \").append(num);\n }\n }\n if (list.get(list.size() - 1) != n) {\n sb.append(\" >>\");\n }\n System.out.println(sb.substring(1));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3fd74d562913c9d821d6f5d18b5678ae", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null} {"lang": "Java 8", "source_code": "\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Pages {\n\n public static void main(String[] args) {\n Scanner scanner = null;\n PrintWriter pw = null;\n try {\n scanner = new Scanner(new File(\"\\input.txt\"));\n pw = new PrintWriter(new File(\"\\output.txt\"));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n // \u041a\u043e\u043b-\u0432\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0432\u0441\u0435\u0433\u043e. \u041d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442 1 \u0434\u043e n\n int n = scanner.nextInt();\n // \u043d\u0430 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\n int p = scanner.nextInt();\n // \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u0441\u043b\u0435\u0432\u0430 \u0438 \u0441\u043f\u0440\u0430\u0432\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\n // p-k \u0438 p+k \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\n int k = scanner.nextInt();\n if(p - k > 1) {\n pw.write(\"<< \");\n }\n for(int i = (p - k >= 1 ? p - k : 1); i <= (p + k >= n ? n : p + k); i++) {\n if(i == p) {\n pw.write(\"(\" + i + \") \");\n } else {\n pw.write(i + \" \");\n }\n }\n if(p + k < n) {\n pw.write(\">>\");\n }\n pw.flush();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c631e3044112d74cafba649bc748ed93", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Codeforces_Noldbach {\n\n\tpublic static void main(String[] args){\n\t\ttry{\n\tScanner sc=new Scanner(System.in);\n\tint n=sc.nextInt();\n\tint k=sc.nextInt();\n\tboolean arr[]=new boolean[n+1];\n\tArrays.fill(arr, true);\n\tarr[0]=arr[1]=false;\n\tList list=new ArrayList();\n\tfor(int i=2;i= k)\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7919ec7df8389526caf7a8d35f6d202c", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Sieve {\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tSieve s = new Sieve();\n\n\t\tScanner scan = new Scanner(System.in);\n\t\tint fn = scan.nextInt();\n\t\tint fk =scan.nextInt();\n\ts.sieveUpdate3(fn, fk);\t\n\n\t}\n\n\tpublic void sieveUpdate3(int nn, int kk) {\n\tboolean[]\taa = new boolean[nn+1];\n\tint[]\tarray = new int [n+1];\n\t\tint found = 0;\n\t\tint counter = 0;\n\t\tboolean flag;\n\t\tint last = 0;\n\t\tfor (int i = 2; i <= Math.sqrt(n); i++) {\n\t\t\tif (aa[i] == false) {\n\t\t\t\tarray[counter] = i;\n\t\t\t\tcounter++;\n\t\t\t\tint temp = 1;\n\t\t\t\tfor (int j = counter-2; j > 0; j--) {\n\t\t\t\t\tif ((temp + array[j] + array[j - 1]) == i) {\n\t\t\t\t\t\tfound++;\n\t\t\t\t\t\tif (found == kk) {\n\t\t\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttemp = 1;\n\t\t\t\tfor (int j = i * i; j < aa.length; j += i) {\n\t\t\t\t\taa[j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlast=i;\n\t\t}\n\t\t\n\t\t\n\t\tfor (int i = last+1; i < array.length; i++) {\n\t\t\tif(aa[i]== false){\n\t\t\t\tarray[counter] = i;\n\t\t\t\tcounter++;\n\t\t\t\tint temp = 1;\n\t\t\t\tfor (int j = counter-2; j > 0; j--) {\n\t\t\t\t\tif ((temp + array[j] + array[j - 1]) == i) {\n\t\t\t\t\t\tfound++;\n\t\t\t\t\t\tif (found == kk) {\n\t\t\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttemp = 1;\t\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c318eda995596d5dad5cfb5a1f4d7f92", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/**\n *\n * @author Abdulrahman Mobarak\n */\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\n public static void main(String[] args) throws IOException {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n\n public void solve(int testNumber, InputReader input, PrintWriter out) throws IOException {\n int n = in.nextInt(), k = in.nextInt();\n ArrayList primes = primes(n);\n\n if (primes.size() < 6) {\n System.out.println(\"NO\");\n return;\n }\n\n for (int i = 5; i < primes.size(); i++) {\n for (int j = i; primes.get(j - 1) + primes.get(j - 2) + 1 >= primes.get(i); j--) {\n if (primes.get(j - 1) + primes.get(j - 2) + 1 == primes.get(i)) {\n k--;\n break;\n }\n }\n if (k == 0) {\n break;\n }\n }\n System.out.print(k == 0 ? \"YES\" : \"NO\");\n }\n static ArrayList primes(int mx) {\n ArrayList res = new ArrayList<>();\n res.add(2);\n for (int i = 3; i <= mx; i += 2)\n for (int x : res) {\n if (x > i / x) {\n res.add(i);\n break;\n }\n if (i % x == 0) break;\n }\n return res;\n }\n }\n\n static class InputReader {\n\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c484e5f9bb0005bde2696b8a5c094311", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "//package codeforces;\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Div435a {\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 x = in.nextInt();\n\t\tint[] arr = new int[n];\n\t\tarr[0] = in.nextInt();\n\t\t\n\t\tboolean f = false;\n\t\tfor(int i = 1; i < n; i++)\n\t\t{\n\t\t\tarr[i] = in.nextInt();\n\t\t\tif(x == arr[i])\n\t\t\t{\n\t\t\t\tf = true;\n\t\t\t}\n\t\t}\n\t\tArrays.sort(arr);\n\t\tif(arr[0] > x)\n\t\t{\n\t\t\tSystem.out.println(x);\n\t\t\treturn;\n\t\t}\n\t\telse if(x == 0 && arr[0] != 0)\n\t\t{\n\t\t\tSystem.out.println(\"0\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\telse if(x == 0 && arr[0] == 0)\n\t\t{\n\t\t\tSystem.out.println(\"1\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\telse if(arr[0] != 0)\n\t\t\n\t\tint count = 0;\n\t\tint flag = 1;\n\t\tint i = 1;\n\t\tfor(; i < n ; i++)\n\t\t{\n\t\t\tif(arr[i] >x)\n\t\t\t{\n\t\t\t\tflag = 0;\n\t\t\t\tcount += x - arr[i-1];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if(arr[i] == x)\n\t\t\t{\n\t\t\t\tflag = -1;\n\t\t\t\tcount += x - arr[i-1] - 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcount += arr[i] - arr[i-1] - 1;\n\t\t}\n\t\tif(flag == 0)\n\t\t{\n\t\t\tSystem.out.println(Math.min(count, i));\n\t\t}\n\t\telse if(flag == -1)\n\t\t{\n\t\t\tSystem.out.println(Math.min(count, i+1));\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcount += x - arr[n-1] - 1;\n\t\t\tSystem.out.println(Math.min(count,n));\n\t\t}\n\t\tin.close();\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3c8c8e36bccef08a653b602c9bdb256f", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.HashSet;\npublic final class ProblemA {\n \n public static void main(String[] args) {\n Scanner in = new Scanney(System.in);\n int n = in.nextInt();\n int x = in.nextInt();\n HashSet set = new HashSet<>();\n for (int i = 0; i < n; i++) {\n set.add(in.nextInt());\n }\n \n int opCount = 0;\n for (int i = 0; i < x; i++) {\n if (!set.contains(i)) {\n opCount++;\n }\n }\n if (set.contains(x)) {\n opCount++;\n }\n System.out.println(opCount);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "96be65ebb9e4265da03591a4fea4161d", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/*\nID: acegikm1\nLANG: JAVA\nTASK: mex\n*/\nimport java.util.*;\nimport java.io.*;\npublic class mex {\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew BufferedReader(new FileReader(System.in))\n\t\t// BufferedReader in = new BufferedReader(new FileReader(\"test.in\"));\n\t\t// PrintStream out = new PrintStream(new File(\"test.out\"));\n\t\tPrintStream out = new PrintStream(System.out);\n\t\tString line = in.readLine().trim(), lines[] = line.split(\" \");\n\t\t\n\t\tint n = Integer.parseInt(lines[0]), x = Integer.parseInt(lines[1]);\n\t\t// int[] arr = new int[n];\n\t\tTreeSet set = new TreeSet();\n\t\tlines = in.readLine().trim().split(\" \");\n\t\tfor (int i = 0; i < n; i++) set.add(Integer.parseInt(lines[i]));\n\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < x; i++) {\n\t\t\tif (!set.contains(i)) ans++;\n\t\t}\n\t\tout.println(ans);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "87faeccd4659d22b376d679433cdb9c6", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Task_292A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt(), x = sc.nextInt();\n\t\tint a[] = new int [n + 1];\n\t\tint cnt[] = new int [1001];\n\t\tfor(int i = 1; i <= n; i ++)\n\t\t\ta[i] = sc.nextInt();\n\t\tint mn = 0;\n\t\tfor(int i = 1; i <= n; i ++) {\n\t\t\tcnt[a[i]] ++;\n\t\t}\n\t\tint t = 0;\n\t\tfor(int i = 0; i < x; i ++) {\n\t\t\tif(cnt[i] == 0) {\n\t\t\t\tt ++;\n\t\t\t}\n\t\t}\n\t\tif(cnt[x])\n\t\t\tt ++;\n System.out.println(t);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "40c0501876907ca53c233a25d5c55a6e", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class divisibility{\n\n public static void main(String[] args) throws Exception{\n Scanner kbd = new Scanner(System.in);\n PrintWriter print=new PrintWriter(System.out);\n \n long n=kbd.nextLong();\n long ok=n/(long)2520;\n \n print.println(ok);\n print.close();\n } \n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3b0566feab3184b3c19c85e4bd3d2dd", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class divis\n{ \n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n \n long a = sc.nextLong();\n int counter =0;\n int flag=0;\n \n for(long i=1;i<=a;i++)\n {\n for(long j=2;j<10;j++)\n {\n if(i%j!=0)\n {\n flag=1;\n break;\n }\n }\n \n if(flag==0)\n {\n counter++;\n i=i+9\n }\n \n flag=0;\n \n }\n \n System.out.println(counter);\n \n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3d4441b9dad2c21d8eb22d1db28aaec", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class divisibility {\n public static void main(String[] args) {\n int input;\n int divCounter = 0;\n boolean divisible = false;\n for (int i = 1; i<=input; i++) {\n if(divisible) {divCounter++;}\n for (int j=2; j< 10; j++) {\n if(i%j == 0){divisible = true;}\n else {\n divisible = false;\n break;\n }\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "995dd05a7af84b2f756206572fb34c96", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class divisibility {\n public static void main(String[] args) {\n int input,divCounter = 0;\n boolean divisible = false;\n for (int i = 1; i<=input; i++) {\n if(divisible) divCounter++;\n for (int j=2; j< 10; j++) {\n if(i%j = 0){divisible = true;}\n else {\n divisible = false;\n break;\n }\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c92bdf77a7a1cb0922d6272c8fdfa089", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "/* package codechef; // don't place package name! */\r\n\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\n/* Name of the class has to be \"Main\" only if the class is public. */\r\npublic class CF1681_D\r\n{\r\n final static int INF = Integer.MAX_VALUE/2 ; \r\n static Map mp = new HashMap<>();\r\n public static int func(long n , long x){\r\n \r\n if(mp.containsKey(x)) return mp.get(x);\r\n \r\n int len = Long.toString(x).length();\r\n if(len==n){\r\n return 0;\r\n }\r\n if(len>n){\r\n return INF;\r\n }\r\n \r\n int st=INF;\r\n \r\n long temp = x;\r\n while(temp>0){\r\n long k = temp%10;\r\n if(k!=0 && k!=1){\r\n int f=func(n, x*k);\r\n st = Math.min(st, f+1);\r\n }\r\n temp/=10;\r\n }\r\n mp.put(x, st);\r\n System.out.println(x+\" \"+st);\r\n return st;\r\n }\r\n \r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\t/* \r\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n\t\tint t=Integer.parseInt(br.readLine());\r\n\t\twhile(t-->0){\r\n\t\t int n=Integer.parseInt(br.readLine());\r\n\t\t String[] inp=br.readLine().trim().split(\" \");\r\n\t\t}\r\n\t\t\r\n\t\t*/\r\n\t\t/*\r\n\t\tScanner cs=new Scanner(System.in);\r\n\t\tint t=cs.nextInt();\r\n\t\twhile(t-->0){\r\n\t\t int n=cs.nextInt();\r\n\t\t int[] a=new int[n];\r\n \t\tfor(int i=0;i0){\r\n\t\t String[] inp=br.readLine().trim().split(\" \");\r\n\t\t long n=Long.parseLong(inp[0]);\r\n\t\t long x=Long.parseLong(inp[1]);\r\n\t\t \r\n\t\t \r\n\t\t int ans = func(n, x);\r\n\t\t if(ans == INF){\r\n\t\t System.out.println(-1);\r\n\t\t }else{\r\n\t\t System.out.println(ans);\r\n\t\t }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "008d285e13defa72b30891d62aded9c9", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "\r\n// * * * 2100 * * * //\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.*;\r\nimport java.util.Map.Entry;\r\n\r\npublic class D {\r\n\r\n static class pair implements Comparable {\r\n long a;\r\n long b;\r\n\r\n pair(long u, long v) {\r\n this.a = u;\r\n this.b = v;\r\n }\r\n\r\n public int compareTo(pair o) {\r\n return 1;\r\n }\r\n }\r\n\r\n public static void main(String[] args) {\r\n FastScanner sc = new FastScanner();\r\n int tt = 1;\r\n o: while (tt-- > 0) {\r\n int n = sc.nextInt();\r\n long x = sc.nextLong();\r\n HashSet set = new HashSet<>();\r\n Queue q = new LinkedList<>();\r\n q.add(new pair(0, x));\r\n set.add(x);\r\n while (q.size() > 0) {\r\n pair rem = q.poll();\r\n long c = rem.b;\r\n long s = rem.a;\r\n\r\n boolean g = sol1(c, n);\r\n if (g) {\r\n System.out.println(s);\r\n continue o;\r\n }\r\n\r\n ArrayList al = new ArrayList<>();\r\n HashMap m = new HashMap<>();\r\n long cc = c;\r\n while (cc > 0) {\r\n m.put(cc % 10, 0);\r\n cc /= 10;\r\n }\r\n for (Entry e : m.entrySet()) {\r\n al.add(e.getKey());\r\n }\r\n for (long e : al) {\r\n long then = e * c;\r\n if (sol(then, n) && !set.contains(then))) {\r\n q.add(new pair(s + 1, then));\r\n set.add(then);\r\n }\r\n }\r\n }\r\n System.out.println(-1);\r\n\r\n }\r\n }\r\n\r\n static boolean sol(long x, long n) {\r\n long c = 0;\r\n while (x > 0) {\r\n c++;\r\n x /= 10;\r\n }\r\n return c <= n;\r\n }\r\n\r\n static boolean sol1(long x, long n) {\r\n long c = 0;\r\n while (x > 0) {\r\n c++;\r\n x /= 10;\r\n }\r\n return c == n;\r\n }\r\n\r\n static void sort(int[] a) {\r\n // ruffle\r\n int n = a.length;\r\n Random r = new Random();\r\n for (int i = 0; i < a.length; i++) {\r\n int oi = r.nextInt(n), temp = a[i];\r\n a[i] = a[oi];\r\n a[oi] = temp;\r\n }\r\n\r\n // then sort\r\n Arrays.sort(a);\r\n }\r\n\r\n static class FastScanner {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st = new StringTokenizer(\"\");\r\n\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\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String str = \"\";\r\n\r\n String nextLine() {\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 int[] readArray(int n) {\r\n int[] a = new int[n];\r\n for (int i = 0; i < n; i++)\r\n a[i] = nextInt();\r\n return a;\r\n }\r\n\r\n long[] readLongArray(int n) {\r\n long[] a = new long[n];\r\n for (int i = 0; i < n; i++)\r\n a[i] = nextLong();\r\n return a;\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n }\r\n\r\n static long gcd(long n, long l) {\r\n if (l == 0)\r\n return n;\r\n return gcd(l, n % l);\r\n }\r\n\r\n static void sieveOfEratosthenes(int n, ArrayList al) {\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 if (prime[p] == true) {\r\n for (int i = p * p; i <= n; i += p)\r\n prime[i] = false;\r\n }\r\n }\r\n for (int i = 2; i <= n; i++) {\r\n if (prime[i] == true)\r\n al.get(i);\r\n }\r\n }\r\n\r\n static final int mod = 100000000 + 7;\r\n static final int max_val = 2147483647;\r\n static final int min_val = max_val + 1;\r\n\r\n static long fastPow(long base, long exp) {\r\n if (exp == 0)\r\n return 1;\r\n long half = fastPow(base, exp / 2);\r\n if (exp % 2 == 0)\r\n return mul(half, half);\r\n return mul(half, mul(half, base));\r\n }\r\n\r\n static long mul(long a, long b) {\r\n return a * b % mod;\r\n }\r\n\r\n static int nCr(int n, int r) {\r\n return fact(n) / (fact(r) *\r\n fact(n - r));\r\n }\r\n\r\n static int fact(int n) {\r\n int res = 1;\r\n for (int i = 2; i <= n; i++)\r\n res = res * i;\r\n return res;\r\n }\r\n\r\n // a -> z == 97 -> 122\r\n\r\n // String.format(\"%.9f\", ans) ,--> to get upto 9 decimal places , (ans is\r\n // double)\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "35aaa0671428756c338d20004f3560e9", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\nimport java.lang.*;\r\n\r\n// commmon mistake:: \r\n// 1. Think reverse\r\n// 2. Traverse from back\r\n// 3. when you think that i have to see all the subarray , then think to do tat problem by answerin the contribution of every element. \r\npublic class Problem {\r\n static int Mod = 1000000007;\r\n // static int Mod=998244353;\r\n static long dp[][];\r\n static int g[][];\r\n static int vis[][];\r\n static int ans;\r\n\r\n public static void main(String[] args) {\r\n MyScanner scan = new MyScanner();\r\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\r\n\r\n // int t = scan.nextInt();\r\n int t = 1;\r\n while (t-- > 0) {\r\n int n= scan.nextInt();\r\n long x= scan.nextLong(); \r\n Set set= new HashSet<>();\r\n Queue q= new LinkedList<>();\r\n q.add(new Pair(x,0));\r\n set.add(x);\r\n int ans=-1;\r\n while(!q.isEmpty()){\r\n Pair p= q.remove();\r\n String no= Long.toString(p.x);\r\n \r\n int len= no.length();\r\n if(len==n){\r\n ans= p.dis;\r\n break;\r\n }\r\n if(len>n) continue;\r\n for(int i=0;i list = new ArrayList<>();\r\n list.add(a[0]);\r\n for (int i = 1; i < a.length; i++) {\r\n int idx = Collections.binarySearch(list, a[i]);\r\n if (idx < 0) {\r\n idx = -idx - 1;\r\n if (idx == list.size())\r\n list.add(a[i]);\r\n else\r\n list.set(idx, a[i]);\r\n } else {\r\n while (idx < list.size()) {\r\n if (list.get(idx) != a[i]) {\r\n list.set(idx, a[i]);\r\n break;\r\n }\r\n idx++;\r\n }\r\n if (idx == list.size())\r\n list.add(a[i]);\r\n }\r\n }\r\n return list.size();\r\n }\r\n\r\n static ArrayList digits(long n) {\r\n ArrayList list = new ArrayList<>();\r\n while (n > 0) {\r\n list.add((int) (n % 10l));\r\n n = n / 10l;\r\n }\r\n Collections.reverse(list);\r\n return list;\r\n }\r\n\r\n public static void reverse(int a[]) {\r\n int n = a.length;\r\n for (int i = 0; i < n / 2; i++) {\r\n int temp = a[i];\r\n a[i] = a[n - i - 1];\r\n a[n - i - 1] = temp;\r\n }\r\n }\r\n\r\n public static void sort(int[] array) {\r\n ArrayList copy = new ArrayList<>();\r\n for (Integer i : array)\r\n copy.add(i);\r\n Collections.sort(copy);\r\n for (int i = 0; i < array.length; i++)\r\n array[i] = copy.get(i);\r\n }\r\n\r\n public static void sort(long[] array) {\r\n ArrayList copy = new ArrayList<>();\r\n for (Long i : array)\r\n copy.add(i);\r\n Collections.sort(copy);\r\n for (int i = 0; i < array.length; i++)\r\n array[i] = copy.get(i);\r\n }\r\n\r\n public static long gcd(long a, long b) {\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b); // gcd(a,b) = gcd(a-b,b) or gcd(a,b) = gcd(b,a%b) where a>b\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); // gcd(a,b) = gcd(a-b,b) or gcd(a,b) = gcd(b,a%b) where a>b\r\n }\r\n\r\n public static long lcm(long a, long b) {\r\n return (a / gcd(a, b)) * b;\r\n }\r\n\r\n static long power(long x, long y) {\r\n long temp;\r\n if (y == 0) // a^b= (a^b/2)^2 if b is even\r\n return 1; // = (a*a^(b-1)) if b is odd\r\n temp = power(x, y / 2);\r\n if (y % 2 == 0)\r\n return temp * temp;\r\n else\r\n return x * temp * temp;\r\n }\r\n\r\n static long mod(long x) {\r\n return ((x % Mod + Mod) % Mod);\r\n }\r\n\r\n static long add(long a, long b) {\r\n return mod(mod(a) + mod(b));\r\n }\r\n\r\n static int mod(int x) {\r\n return ((x % Mod + Mod) % Mod);\r\n }\r\n\r\n static int add(int a, int b) {\r\n return mod(mod(a) + mod(b));\r\n }\r\n\r\n static int sub(int a, int b) {\r\n return mod(mod(a) - mod(b) + Mod);\r\n }\r\n\r\n static long mul(long a, long b) {\r\n return mod(mod(a) * mod(b));\r\n }\r\n\r\n static long pow(long x, long y, long p) {\r\n long res = 1; // Initialize result\r\n x = x % p; // Update x if it is more than or equal to p\r\n\r\n if (x == 0)\r\n return 0; // In case x is divisible by p;\r\n\r\n while (y > 0) {\r\n // If y is odd, multiply x with result\r\n if ((y & 1) != 0)\r\n res = (res * x) % p;\r\n\r\n // y must be even now\r\n y = y >> 1; // y = y/2\r\n x = (x * x) % p;\r\n }\r\n return res;\r\n }\r\n\r\n static long modInverse(long a, long m) {\r\n // int g = gcd(a, m);\r\n // if (g != 1)\r\n // System.out.println(\"Inverse doesn't exist\");\r\n // else {\r\n // // If a and m are relatively prime, then modulo\r\n // // inverse is a^(m-2) mode m\r\n // return power(a, m - 2, m);\r\n // }\r\n return pow(a, m - 2, m);\r\n }\r\n\r\n}\r\n\r\nclass 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 int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine() {\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b8e876b2d6d940893596dad48901339d", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "\r\nimport java.io.IOException;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n static Scanner sc;\r\n\r\n public static void main(String[] hi) throws IOException {\r\n sc = new Scanner(System.in);\r\n int t = 1;\r\n while (t-- != 0) {\r\n if (sc.hasNext()) {\r\n long n = sc.nextLong();\r\n long x = sc.nextLong();\r\n bfs(x, n);\r\n }\r\n }\r\n }\r\n\r\n private static long sizeOfvalue(long a) {\r\n return (long) Math.floor(Math.log10(n) + 1);\r\n }\r\n\r\n private static void bfs(long x, long length) throws IOException {\r\n Queue qu = new LinkedList<>();\r\n qu.add(x);\r\n Set set = new HashSet<>();\r\n int operation = 0;\r\n set.add(x);\r\n while (!qu.isEmpty()) {\r\n int size = qu.size();\r\n while (size-- > 0) {\r\n long value = qu.poll();\r\n List li = numbers(value);\r\n\r\n if (sizeOfvalue(value) == length) {\r\n System.out.println(operation);\r\n return;\r\n }\r\n for (long mul : li) {\r\n if (!set.contains(value * mul) && sizeOfvalue(value * mul) <= length) {\r\n set.add(value * mul);\r\n qu.add(mul * value);\r\n }\r\n }\r\n }\r\n operation++;\r\n }\r\n System.out.println(-1);\r\n }\r\n\r\n private static List numbers(long x) {\r\n List li = new ArrayList<>();\r\n long v = x;\r\n while (v > 0) {\r\n if (v % 10 != 0 && v % 10 != 1) {\r\n li.add(v % 10);\r\n }\r\n v = v / 10;\r\n }\r\n return li;\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc18af94cbbb49da70dbbcea42ab2e5d", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author donder\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n int n;\n int l;\n int r;\n int x;\n int acc;\n int problems;\n\n private void dfs(int pos, int curr_min, int curr_max, int total_diff) {\n if (pos == n) {\n if (total_diff >= l && total_diff <= r && curr_max - curr_min >= x) {\n acc++;\n }\n } else {\n // try without problems[pos]\n dfs(pos + 1, curr_min, curr_max, total_diff);\n\n // try with problems[pos]\n curr_min = Math.min(curr_min, problems[pos]);\n curr_max = Math.max(curr_max, problems[pos]);\n total_diff += problems[pos];\n\n dfs(pos + 1, curr_min, curr_max, total_diff);\n }\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n l = in.nextInt();\n r = in.nextInt();\n x = in.nextInt();\n problems = in.nextIntArray(n);\n\n acc = 0;\n\n dfs(0, Integer.MAX_VALUE, -1, 0);\n\n out.println(acc);\n }\n\n }\n\n static class InputReader {\n private StringTokenizer tokenizer;\n private BufferedReader reader;\n\n public InputReader(InputStream stream) {\n this.reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n private String next() {\n while (tokenizer == null || !tokenizer.hasMoreElements()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public int[] nextIntArray(int n) {\n int[] array = new int[n];\n\n for (int i = 0; i < n; ++i) {\n array[i] = nextInt();\n }\n\n return array;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "945ce03f1e23460f1db6ce82c131303f", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out, true);\n \n int n = in.nextInt();\n long l = in.nextLong();\n long r = in.nextLong();\n int x = in.nextInt(); \n int answer = 0;\n \n List problems = new ArrayList();\n for (int i = 0; i < n; i++) {\n problems.add(in.nextInt()); \n }\n \n for (int i = 0; i < 1 << n; i++) {\n int least = Integer.MAX_VALUE, most = Integer.MIN_VALUE, total = 0, ones = 0;\n for (int j = 0; j < n; j++) {\n if(i != 0 && 1 << j != 0) {\n least = Math.min(least, problems.get(j));\n most = Math.max(most, problems.get(j));\n total += problems.get(j);\n ones++;\n }\n }\n \n if(ones >= 2 && total >= l && total <= r && (most - least) >= x)\n answer++;\n }\n out.println(answer);\n \n } \n \n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6373b476585e3faf9721021c7d8c4d1e", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import com.sun.deploy.panel.AbstractRadioPropertyGroup;\n\nimport java.io.*;\nimport static java.lang.Math.*;\n\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.util.function.*;\nimport java.lang.*;\n\npublic class Main {\n final static boolean debug = false;\n final static String fileName = \"\";\n final static boolean useFiles = false;\n\n public static void main(String[] args) throws FileNotFoundException {\n PrintWriter writer = new PrintWriter(System.out);\n new Task(new InputReader(System.in), writer).solve();\n writer.close();\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public byte nextByte() {\n return Byte.parseByte(next());\n }\n}\n\nclass Task {\n void answer(boolean x){\n out.println(x ? \"YES\" : \"NO\");\n }\n\n void interval(boolean[] a, int left, int right){\n out.print(\"(\");\n for (int i = left; i <= right; i++){\n out.print(a[i] ? 1 : 0);\n if (i != right)\n out.print(\"->\");\n }\n out.print(\")\");\n }\n\n public void solve() {\n// for (int mask = 0; mask < (1 << n); mask++){\n// for (int i = 0; i < n; i++){\n// if ((mask & (1 << i)) > 0){\n// //\u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0435\u0441\u0442\u044c\n// }\n// else{\n// //\u043d\u0435\u0442\u0443\n// }\n// }\n// }\n// int n = in.nextInt();\n// int m = in.nextInt();\n// int fine = in.nextInt();\n// int[] x = new int[n];\n// for (int i = 0; i < n; i++)\n// x[i] = in.nextInt();\n// int[] probabilities = new int[n - 1];\n// for (int i = 0; i < n - 1; i++)\n// probabilities[i] = in.nextInt();\n// int[] sum = new int[n];\n// for (int i = 0; i < m; i++) {\n// int from = in.nextInt() - 1;\n// int to = in.nextInt() - 1;\n// sum[from]++;\n// sum[to]--;\n// }\n// long s = 0, result = 0, current = 0;\n// for (int i = 0; i < n - 1; i++){\n// s += sum[i];\n// current += s * (100 * (long)(x[i + 1] - x[i]) - 2 * probabilities[i] * fine);\n// current = max(current, 0);\n// result = max(result, current);\n// }\n// out.println(result / 200.0);\n//\n// int n = in.nextInt();\n// boolean[] a = new boolean[n];\n// for (int i = 0; i < n; i++){\n// a[i] = in.nextInt() == 1;\n// }\n// if (a[n - 1] == true){\n// out.print(\"NO\");\n// return;\n// }\n// int firstFalse = 0;\n// for (int i = 0; i < n; i++){\n// if (a[i] == false){\n// firstFalse = i;\n// break;\n// }\n// }\n// if (firstFalse == n - 2){\n// out.print(\"NO\");\n// return;\n// }\n// if (firstFalse == n - 1){\n// out.println(\"YES\");\n// interval(a, 0, n - 1);\n// return;\n// }\n// out.println(\"YES\");\n// interval(a, 0, firstFalse);\n// out.print(\"->\");\n// interval(a, firstFalse + 1, n - 2);\n// out.print(\"->\");\n// interval(a, n - 1, n - 1);\n int n = in.nextInt();\n int l = in.nextInt();\n int r = in.nextInt();\n int x = in.nextInt();\n int[] c = new int[n];\n for (int i = 0; i < n; i++){\n c[i] = in.nextInt();\n }\n Arrays.sort(c);\n int result = 0;\n for (int mask = 0; mask < (1 << n); mask++){\n int cost = 0;\n int minCost = Integer.MAX_VALUE;\n int maxCost = 0;\n for (int i = 0; i < n; i++){\n if ((mask & (1 << i)) > 0){\n cost += c[i];\n minCost = min(minCost, c[i]);\n maxCost = max(maxCost, c[i]);\n }\n }\n if (Integer.bitCount(mask) >= 2 && l <= cost && cost <= r && maxCost - minCost >= x){\n result++;\n }\n }\n out.println(result);\n }\n\n private InputReader in;\n private PrintWriter out;\n\n Task(InputReader in, PrintWriter out) {\n this.in = in;\n this.out = out;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "027eed03ab66626e88c0b01a4b0c9274", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\n\npublic class PreparingOlympiad {\n\t\n\tpublic static Object[] getIndicesFromBitMask(int number){\n\t\tString binary = Util.toBinary(number);\n\t\tArrayList indices = new ArrayList();\n\t\tfor (int i=0;i maxDif)\n\t\t\t\t\tmaxDif = c[n-1-(int)j];\n\t\t\t\tif (c[n-1-(int)j] < minDif) \n\t\t\t\t\tminDif = c[n-1-(int)j];\n\t\t\t}\n\t\t\tif ((compl>=l && compl<=r) && (maxDif-minDif)>=x){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "75f552be016efd84d2627c792dcc782d", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Sol{\n public static void main(String []args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long n = Long.parseLong(br.readLine());\n long out = n;\n boolean flag = false;\n while(n % 2 == 0) {\n n /=2;\n flag = true;\n out = 2;\n }\n for(int i = 3 ; i <= (int)(Math.sqrt(n)) + 100; i+=2) {\n if (n % i == 0) {\n if (flag) {\n out = 1;\n break;\n }\n else {\n while (n % i == 0) n = n / i;\n if (n == 1) {\n out = i;\n break;\n }\n flag = true;\n out = i;\n }\n }\n }\n if (flag && n!= 1) out = 1;\n System.out.println(out);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5972e619ce7894526af14f2787afce35", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class contest {\n\tstatic TreeSetq= new TreeSet<>();\n\tpublic static void f(long a) {\n\t\tboolean f = false;\n\t\twhile (a % 2 == 0) \n\t { \n\t q.add((long) 2); \n\t a = a/2; \n\t } \n\t\tfor(int i=3;i<=Math.sqrt(a);i+=2) {\n\t\t\twhile(a%i==0) {\n\t\t\t\tq.add((long) i);\n\t\t\t\ta/=i;\n\t\t\t\t}\n\t\t}\n\t\tif(a>2) {\n\t\t\tq.add(a);\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\tf(n);\n\t\t//System.out.println(q);\n\t\tSystem.out.println((q.size()==1)?q.pollFirst():1);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "378d34a10a704cfdacd942deebbf74ed", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "\npublic class Solution {\n public static void main(String []args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long n = Long.parseLong(br.readLine());\n long out = n;\n boolean flag = false;\n if(n % 2 == 0) {\n flag = true;\n out = 2;\n }\n for(int i = 3 ; i <= (int)(Math.sqrt(n)) + 100; i+=2) {\n if (n % i == 0) {\n if (flag) {\n out = 1;\n break;\n }\n else {\n while (n % i == 0) n = n / i;\n// System.out.println(n);\n flag = true;\n out = i;\n }\n }\n }\n System.out.println(out);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a29ce5fff4c123508507a6264874e5c", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\nimport java.lang.*;\n\npublic class Z1243\u0441 {\n\n\n\n public static void main (String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int result = kolDel(n);\n\n if (result == -1){\n System.out.println(n);\n }\n else\n System.out.println(result);\n\n\n }\n\n\n\n private static int kolDel(int n) {\n int count = 0;\n int i = 2;\n int pred = 0;\n boolean prost = true;\n while(i * i <= n){\n\n if(n % i == 0){\n prost = false;\n if (pred != i || pred == 0) {\n count++;\n pred = i;\n }\n n = n / i;\n\n }\n else i = i +1;\n }\n if (prost) return -1;\n if (n > 1 && n!=pred )\n count = count +1;\n if (count == 1 ) return pred;\n else return 1;\n\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "efc5a74eb888465245d0269e793304ae", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(System.in);\n System.out.println(find(in.nextLine().trim()));\n }\n public static String find(String start) {\n for (int i = 0; i <= start.length(); i++) {\n for (int j = 0; j < 26; j++) {\n char c = (char)('a' + j);\n String s = start.substring(0, i) + c + start.substring(i);\n if (palindrome(s)) return s;\n }\n }\n return \"NA\";\n }\n public static boolean palindrome(String s) {\n for (int i = 0; i < s.length() / 2; i++) {\n if (s.charAt(i) + s.charAt(s.length() - i - 1)) return false;\n }\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4d65d7e10d2587f3e4a918f54f44881f", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class test{\n public static void main(String[] args) throws IOException {\n\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n String word = br.readLine();\n\n\n String[] alpha= \"abcdefghijklmnopqrstuvwxyz\".split(\"\");\n\n String[] wordArray = word.split(\"\");\n\n ArrayList wordAL = new ArrayList(Arrays.asList(wordArray));\n\n String answer = \"NA\";\n\n\n for(String letter : alpha){\n\n for(int i = 0; i <= wordArray.length+1; i++){\n\n String newWord;\n newWord = insertWord(wordAL,letter,i);\n\n if(isPalindrome(newWord)){\n answer = newWord;\n System.out.print(answer);\n }\n\n }\n\n }\n\n\n //insert letter into arrayList\n //put arrayList to string\n //check if it is a palindrome\n //exit loop on match\n //else repeat with new position\n\n\n \n\n\n }\n\n public static boolean isPalindrome(String word){\n return (new StringBuilder(word).reverse().toString()).equals(word);\n }\n\n static public String insertWord(ArrayList word, String letter, int position){\n\n word.add(position,letter);\n\n StringBuilder newString = new StringBuilder();\n\n for(String piece: word)\n {\n newString.append(piece);\n }\n\n return newString.toString();\n\n }\n}import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class test{\n public static void main(String[] args) throws IOException {\n\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n String word = br.readLine();\n\n\n String[] alpha= \"abcdefghijklmnopqrstuvwxyz\".split(\"\");\n\n String[] wordArray = word.split(\"\");\n\n ArrayList wordAL = new ArrayList(Arrays.asList(wordArray));\n\n String answer = \"NA\";\n\n\n for(String letter : alpha){\n\n for(int i = 0; i <= wordArray.length+1; i++){\n\n String newWord;\n newWord = insertWord(wordAL,letter,i);\n\n if(isPalindrome(newWord)){\n answer = newWord;\n }\n\n }\n\n }\n\n\n //insert letter into arrayList\n //put arrayList to string\n //check if it is a palindrome\n //exit loop on match\n //else repeat with new position\n\n\n System.out.print(answer);\n\n\n }\n\n public static boolean isPalindrome(String word){\n return (new StringBuilder(word).reverse().toString()).equals(word);\n }\n\n static public String insertWord(ArrayList word, String letter, int position){\n\n word.add(position,letter);\n\n StringBuilder newString = new StringBuilder();\n\n for(String piece: word)\n {\n newString.append(piece);\n }\n\n return newString.toString();\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e5dbf43f1d371768f9fb9cf008b17ac6", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\n\n/**\n * Created by kaaveh on 1/22/15.\n */\n\n\n/* _\n* _._ _..._ .-', _.._(`))\n*'-. ` ' /-._.-' ',/\n* ) \\ '.\n* / _ _ | \\\n* | a a / |\n* \\ .-. ;\n* '-('' ).-' ,' ;\n* '-; | .'\n* \\ \\ /\n* | 7 .__ _.-\\ \\\n* | | | ``/ /` /\n* /,_| | /,_/ /\n* /,_/ '`-'\n*/\n\npublic class _505A_ {\n public static void main(String[] args) { //I hope enjoy! :)\n\n kaaveh in = new kaaveh();\n String data = in.kLine(10);\n\n int size = data.length() / 2;\n int lng= data.length();\n String res = \"\";\n boolean palin = true;\n\n for (int i=0; i\");\n\t\t\t\tSystem.exit(-1);\n\t\t\t\toutput1 +=Integer.toString(Integer.parseInt(j),num1base).toUpperCase();\n\t\t\t}else \n\t\t\t{\n\t\t\t\toutput1 +=j;\n\t\t\t}\n\t\t}\n\n\t\tint num2length = input.nextInt();\n\t\tint num2base = input.nextInt();\n\t\tinput.nextLine();\n\t\tString y =input.nextLine(); \n\t\tString[] k = y.split(\" \");\n\t\tString output2 = \"\";\n\t\tfor(String j:k) \n\t\t{\n\t\t\tif(j.length()==2) \n\t\t\t{\n\t\t\t\tSystem.out.println(\"<\");\n\t\t\t\tSystem.exit(-1);\n\t\t\t\toutput2 +=Integer.toString(Integer.parseInt(j),num1base).toUpperCase();\n\n\t\t\t}else \n\t\t\t{\n\t\t\t\toutput2 +=j;\n\t\t\t}\n\t\t}\n\n\t\tint x1 = Integer.parseInt(output1,num1base);\n\t\tint x2 = Integer.parseInt(output2,num2base);\n\t\tif(x1 ==x2) \n\t\t{\n\t\t\tSystem.out.println(\"=\");\n\t\t}else if(x1>x2)\n\t\t{\n\t\t\tSystem.out.println(\">\");\n\t\t}else \n\t\t{\n\t\t\tSystem.out.println(\"<\");\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3977325c133f044c16b509413fb5c6f0", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "package round333_DIV2;\n\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n/**\n * Created by i5 on 24.11.2015.\n */\npublic class TwoBases {\n\n public static void main(String [] args){\n Scanner scn = new Scanner(System.in);\n String line = scn.nextLine();\n StringTokenizer st = new StringTokenizer(line);\n int n = Integer.parseInt(st.nextToken());\n int bx = Integer.parseInt(st.nextToken());\n\n int[] x = new int[n];\n line = scn.nextLine();\n st = new StringTokenizer(line);\n int i =0;\n long numX = 0;\n while (st.hasMoreTokens()){\n x[i] = Integer.parseInt(st.nextToken());\n i++;\n }\n for (int k=0;k numY){\n System.out.println(\">\");\n }\n else{\n System.out.println(\"=\");\n }\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "529f1be414d00868a98151e7bbfead1a", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic final class Div2A\n{\n\tpublic static void main(String[] args) {\n\t\tScanner br=new Scanner(System.in);\n\t\tint n=br.nextInt();\n\t\tint b=br.nextInt();\n\t\tLong s=0L;\n\t\tLong g=0L;\n\t\tfor(int i=n-1;i>=0;i--)\n\t\t\ts+=Math.pow(b,i)*br.nextInt();\n\t\tint m=br.nextInt();\n\t\tint c=br.nextInt();\n\t\tfor(int i=m-1;i>=0;i--)\n\t\t\tg+=Math.pow(c,i)*br.nextInt();\n\t\tif(s==g)\n\t\t\tSystem.out.print(\"=\");\n\t\telse if(s\");\n\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dd79f16e5d9acf0748240d6da66e3a6a", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CF2\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n1 = scan.nextInt();\n\t\tint base1 = scan.nextInt();\n\t\tlong num1 = 0;\n\t\tfor (int i = n1-1; i >= 0; i--)\n\t\t\tnum1 += scan.nextInt()*(long)Math.pow(base1, i);\n\t\t\n\t\tint n2 = scan.nextInt();\n\t\tint base2 = scan.nextInt();\n\t\tlong num2 = 0;\n\t\tfor (int i = n2-1; i >= 0; i--)\n\t\t\tnum2 += scan.nextInt()*(long)Math.pow(base2, i);\n\t\t\n\t\tif (num1 == num2)\n\t\t\tSystem.out.println(\"=\");\n\t\telse\n\t\t\t System.out.println(num1 > num2 ? '>' : '<');\n\t\t\n\t\tscan.close();\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "81f433a5156c046e3a074c061be3dede", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.Math.*;\n\npublic class Main{\n public static int findPythagorean(int L){\n int count = 0;\n for(int b=1; b<=L; b++){\n for(int a=1; a<=b; a++){\n double cSquare = a*a + b*b;\n double c = Math.sqrt(cSquare);\n if(c==Math.round(c) && c<=L){\n count++;\n }\n }\n }\n //System.out.printf(\"The count is: %d\\n\", count);\n return count;\n }\n \n public static void main(String args[]){\n Scanner keyboard = new Scanner(System.in);\n int L = keyboard.nextInt();\n findPythagorean(L);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f7b1e48d6ba58c78960eedc70253572", "src_uid": "36a211f7814e77339eb81dc132e115e1", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\npublic class p3 {\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 output=0;\n\t\tint count=0;\n\t\t\n\t\tfor (int i=1;i<=n;i++) {\n\t\t\tfor (int j=i;j<=n;j++) {\n\t\t\t\t\toutput=(int) Math.sqrt(Math.pow(i, 2)+Math.pow(j, 2));\n\t\t\t\t\tif (output<=n & output==Math.sqrt(Math.pow(i, 2)+Math.pow(j, 2)) ) {\n\t\t\t\t\t\n\t\t\t\t\t\tcount+=1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t\t\n\t}\n\n}\n4\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b4cc279ea754714afdeb1faf8a8e8959", "src_uid": "36a211f7814e77339eb81dc132e115e1", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "/*package learnjava;\n\nimport java.util.Scanner;\n\npublic class LearnJava{\n*/\n public static void main(String[] args){\n int n, count=0;\n double k;\n Scanner scan = new Scanner(System.in);\n n = scan.nextInt();\n for(int i=1; i<=n; i++){\n for(int j=i; j<=n; j++){\n k = Math.sqrt(i*i + j*j);\n if(k==(int)k && k<=n)\n count++;\n }\n }\n System.out.println(count);\n }\n//}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8064e09af232fd66aaf0a5154c7d4702", "src_uid": "36a211f7814e77339eb81dc132e115e1", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\npublic class Main{\n public static void main(){\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int count = 0;\n for(int i=1;i<=n;i++) {\n for(int j=i;j<=n;j++) {\n int temp = a*a+b*b;\n if(temp>n*n)\n break;\n int num = int(Math.sqrt(temp))*int(Math.sqrt(temp));\n if(num== temp && int(Math.sqrt(temp)<=n))\n count++;\n }\n }\n System.out.println(count);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6387775e29cc068c6490b735b7a658d2", "src_uid": "36a211f7814e77339eb81dc132e115e1", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String[] args) {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n Buffer\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4b647dcba5824557c76b3b4359b5e5b8", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class discount\n{\nstatic void function(int q,int u)\n{\n\tint i,j,x,flag=0,k,l,count=0;\n\t\tint array[]=new int[5];\n\t\n\t\tfor(i=q;i<=u;i++)\n\t\t{\n\t\t\tx=i;count=0;flag=0;\n\t\t\tfor(j=0;(x!=0);j++)\n\t\t\t{\n\t\t\t\tarray[j]=(x%10);\n\t\t\t\tx=x/10;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tfor(k=0;k 1){\n found = false;\n break;\n }\n }\n if(found == true){\n System.out.println(numberString);\n break;\n }\n }\n if(found == false){\n System.out.println(-1);\n }\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0634feb05915a34d9eedbf8e76fb2686", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Solution1 {\n \n\tpublic static void main(String[]args) throws Exception\n\t{\n\t Scanner sc=new Scanner(System.in);\n\t int a=sc.nextInt();\n\t int b=sc.nextInt();\n\t \n\t for(int j=a;j<=b;j++)\n\t {\n\t if(Check(j))\n\t {\n\t System.out.println(j);\n\t return;\n\t }\n\t }\n\t System.out.println(-1);\n\t return;\n\t}\n\tprivate boolean Check(int number)\n\t{\n\t int[]digits=new int[10];\n\t \n\t while(num>0)\n\t {\n\t if(digits[num%10]==0)\n\t {\n\t digits[num%10]++;\n\t }\n\t else\n\t {\n\t return false;\n\t }\n\t num=num/10;\n\t }\n\t return true;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2040cf6226948565a80e83964e6875d3", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n \n/**\n * @author Alice\n */\npublic class Main {\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner str = new Scanner(System.in);\n int n = str.nextInt();\n boolean []a = new boolean[n+1];\n Arrays.fill(a, true);\n int sum = 0;\n int []arr = new int[n];\n for(int i = 0; i < n; i++) {\n arr[i] = str.nextInt();\n sum += arr[i];\n }\n sum = sum/(n/2);\n \n for(int i = 1; i <= n; i++) {\n for(int j = i; j <= n; j++) {\n if(i!=j && a[j]!=false && a[i]!=false && arr[i-1]+arr[j-1] == sum) {\n a[i] = false;\n a[j] =false;\n System.out.println(i + \" \" + j);\n }\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f255ba6c18a3fef47b0d7b81a9142bb8", "src_uid": "6e5011801ceff9d76e33e0908b695132", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class C701A {\npublic static void main(String[] args)throws Exception{\n\tScanner sc=new Scanner(System.in);\n\tint n,sum=0,f=0;\n\tn=sc.nextInt();\n\tint arr[]=new int[n];\n\tfor(int i=0; i hm = new ArrayList<>();\n\n for (int i = 0; i < x; i++) {\n card q = new card();\n q.index = i + 1;\n q.value = ar[i];\n hm.add(q);\n }\n Collections.sort(hm);\n for (int i = 0; i < x / 2; i++) {\n System.out.println(hm.get(i).index + \" \" + hm.get((x - 1) - i).index);\n }\n }\n\n static class card implements Comparable {\n\n int index;\n int value;\n\n @Override\n public int compareTo(Object o) {\n int compareage = ((card) o).value;\n /* For Ascending order*/\n return this.value - compareage;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1884d0ebda6e522beae16309cc50a050", "src_uid": "6e5011801ceff9d76e33e0908b695132", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner teclado = new Scanner(System.in);\n\t\t\n\t\t\n\t\t//greedy algorithm\n\t\t\n\t\tint cantidad = teclado.nextInt();\n\t\tint []cartas = new int[cantidad];\n\t\t\n\t\t\n\t\tint mayor = Integer.MAX_VALUE;\n\t\tint menor = Integer.MIN_VALUE;\n\t\t\n\t\tfor (int i=0; imenor){\n\t\t\t\tmenor = cartas[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint suma = menor + mayor;\n\t\t\n\t\t\n\t\tfor (int i=0; i b; i--) {\n\t\t\tcnt[i % 3]++;\n\t\t}\n\t\t\n\t\tlong[][] dp = new long[n + 1][3];\n\t\tdp[1] = cnt;\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tfor(int j = 0; j < 3; j++) {\n\t\t\t\tfor(int k = 0; k < 3; k++) {\n\t\t\t\t\tdp[i][(j + k) % 3] += cnt[j] * 1L * dp[i - 1][k];\n\t\t\t\t\tdp[i][(j + k) % 3] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(dp[n][0]);\n\t}\n\n\tpublic void run() {\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\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Main(), \"Main\", 1 << 26).start();\n\t}\n\n\t\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\n\t\tint[] uniq(int[] arr) {\n\t\t\tArrays.sort(arr);\n\t\t\tint[] rv = new int[arr.length];\n\t\t\tint pos = 0;\n\t\t\trv[pos++] = arr[0];\n\t\t\tfor (int i = 1; i < arr.length; i++) {\n\t\t\t\tif (arr[i] != arr[i - 1]) {\n\t\t\t\t\trv[pos++] = arr[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Arrays.copyOf(rv, pos);\n\t\t}\n\t}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1bc439e8bcaad69f2314068b3584d679", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class tr0 {\n\tstatic PrintWriter out;\n\tstatic StringBuilder sb;\n\tstatic final double EPS = 1e-9;\n\tstatic long mod = 1000000007;\n\tstatic int inf = (int) 1e9 + 2;\n\tstatic long[] fac;\n\tstatic int[] si;\n\tstatic ArrayList primes;\n\tstatic ArrayList[] ad;\n\tstatic int[] a;\n\tstatic long [][]memo;\n\tstatic int m, k,n;\n\tstatic HashMap t;\n\tstatic boolean f;\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\ta=new int [3];\n\t\tn=sc.nextInt();\n\t\tmemo=new long [n+1][3];\n\t\tint l=sc.nextInt();\n\t\tint r=sc.nextInt();\n\t\tfor(long []h:memo)\n\t\t\tArrays.fill(h, -1);\n\t\ta[0]=r/3-(l-1)/3;\n\t\ta[1]=(r+2)/3-(l-1+2)/3;\n\t\ta[2]=(r+1)/3-(l-1+1)/3;\n\t//\tSystem.out.println(Arrays.toString(a));\n\t\tint z=0;\n\t\tint o=0;\n\t\tint t=0;\n\t\tfor(int i=9;i<=99;i++)\n\t\t\tif(i%3==0)\n\t\t\t\tz++;\n\t\t\telse if(i%3==1)\n\t\t\t\to++;\n\t\t\telse\n\t\t\t\tt++;\n\t\tout.println(dp(0,0)%mod);\n\t\tout.close();\n\t}\n\tstatic long dp(int i,int st) {\n\t\tif(i==n && st==0)\n\t\t\treturn 1;\n\t\tif(i==n && st!=0)\n\t\t\treturn 0;\n\t\tif(memo[i][st]!=-1)\n\t\t\treturn memo[i][st];\n\t\tlong ans=0;\n\t\tif(a[0]>0)\n\t\t\tans+=((dp(i+1,st))*a[0])%mod;\n\t\tif(a[1]>0)\n\t\t\tans+=(dp(i+1,(st+1)%3)*a[1])%mod;\n\t\tif(a[2]>0)\n\t\t\tans+=(dp(i+1,(st+2)%3)*a[2])%mod;\n\t\treturn memo[i][st]=ans%mod;\n\t}\n static long getval(long x) {\n \tif(x==0)\n \t\treturn 0l;\n \tif(x==1)\n \t\treturn 1;\n \tlong k=0;\n \tint id=0;\n for(long i=0;i<=60;i++) {\n \tif(x>=(1l< {\n\t\tchar a;\n\t\tint b;\n\t\tseg(char s, int e) {\n\t\t\ta= s;\n\t\t\tb= e;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn a+\" \"+b;\n\t\t}\n\t\tpublic int compareTo(seg o) {\n\t\t return o.b-b;\n\t\t}\n\t}\n\n\tstatic public class SegmentTree { // 1-based DS, OOP\n\n\t\tint N; // the number of elements in the array as a power of 2 (i.e. after padding)\n\t\tint[] array, sTree, lazy, candies;\n\n\t\tSegmentTree(int[] in) {\n\t\t\tarray = in.clone();\n\t\t\tN = in.length - 1;\n\t\t\tsTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero\n\t\t\tlazy = new int[N << 1];\n\t\t\tcandies = new int[N << 1];\n\t\t\tbuild(1, 1, N);\n\t\t\tbuild2(1, 1, N);\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn Arrays.toString(sTree) + \"\\n\" + Arrays.toString(candies);\n\t\t}\n\n\t\tvoid build(int node, int b, int e) // O(n)\n\t\t{\n\t\t\tif (b == e)\n\t\t\t\tsTree[node] = array[b];\n\t\t\telse {\n\t\t\t\tint mid = b + e >> 1;\n\t\t\t\tbuild(node << 1, b, mid);\n\t\t\t\tbuild(node << 1 | 1, mid + 1, e);\n\t\t\t\tsTree[node] = (sTree[node << 1] + sTree[node << 1 | 1]) % 10;\n\t\t\t\tif (sTree[node << 1] + sTree[node << 1 | 1] >= 10)\n\t\t\t\t\tcandies[node]++;\n\t\t\t}\n\t\t}\n\n\t\tvoid build2(int node, int b, int e) // O(n)\n\t\t{\n\t\t\tif (b == e)\n\t\t\t\tb = e;\n\t\t\telse {\n\t\t\t\tint mid = b + e >> 1;\n\t\t\t\tbuild(node << 1, b, mid);\n\t\t\t\tbuild(node << 1 | 1, mid + 1, e);\n\t\t\t\tcandies[node] = (candies[node << 1] + candies[node << 1 | 1]);\n\t\t\t}\n\t\t}\n\n\t\tvoid update_point(int index, int val) // O(log n)\n\t\t{\n\t\t\tindex += N - 1;\n\t\t\tsTree[index] += val;\n\t\t\twhile (index > 1) {\n\t\t\t\tindex >>= 1;\n\t\t\t\tsTree[index] = sTree[index << 1] + sTree[index << 1 | 1];\n\t\t\t}\n\t\t}\n\n\t\tvoid update_range(int i, int j, int val) // O(log n)\n\t\t{\n\t\t\tupdate_range(1, 1, N, i, j, val);\n\t\t}\n\n\t\tvoid update_range(int node, int b, int e, int i, int j, int val) {\n\t\t\tif (i > e || j < b)\n\t\t\t\treturn;\n\t\t\tif (b >= i && e <= j) {\n\t\t\t\tsTree[node] += (e - b + 1) * val;\n\t\t\t\tlazy[node] += val;\n\t\t\t} else {\n\t\t\t\tint mid = b + e >> 1;\n\t\t\t\tpropagate(node, b, mid, e);\n\t\t\t\tupdate_range(node << 1, b, mid, i, j, val);\n\t\t\t\tupdate_range(node << 1 | 1, mid + 1, e, i, j, val);\n\t\t\t\tsTree[node] = sTree[node << 1] + sTree[node << 1 | 1];\n\t\t\t}\n\n\t\t}\n\n\t\tvoid propagate(int node, int b, int mid, int e) {\n\t\t\tlazy[node << 1] += lazy[node];\n\t\t\tlazy[node << 1 | 1] += lazy[node];\n\t\t\tsTree[node << 1] += (mid - b + 1) * lazy[node];\n\t\t\tsTree[node << 1 | 1] += (e - mid) * lazy[node];\n\t\t\tlazy[node] = 0;\n\t\t}\n\n\t\t// static int c=0;\n\t\tint query(int i, int j) {\n\t\t\t// c=0;\n\t\t\treturn query(1, 1, N, i, j);\n\t\t}\n\n\t\tint query(int node, int b, int e, int i, int j) // O(log n)\n\t\t{\n\t\t\tif (i > e || j < b)\n\t\t\t\treturn 0;\n\t\t\tif (b >= i && e <= j)\n\t\t\t\treturn candies[node];\n\t\t\tint mid = b + e >> 1;\n\t\t\t// propagate(node, b, mid, e);\n\t\t\tint q1 = query(node << 1, b, mid, i, j);\n\t\t\tint q2 = query(node << 1 | 1, mid + 1, e, i, j);\n\t\t\treturn q1 + q2;\n\t\t}\n\t}\n\n\tstatic int x, y, d;\n\n\tstatic long power(int i) {\n\t\t// if(i==0)\n\t\t// return 1;\n\t\tlong a = 1;\n\t\tfor (int k = 0; k < i; k++)\n\t\t\ta *= i;\n\t\treturn a;\n\t}\n\n\tstatic void extendedEuclid(int a, int b) {\n\t\tif (b == 0) {\n\t\t\tx = 1;\n\t\t\ty = 0;\n\t\t\td = a;\n\t\t\treturn;\n\t\t}\n\t\textendedEuclid(b, a % b);\n\t\tint x1 = y;\n\t\tint y1 = x - a / b * y;\n\t\tx = x1;\n\t\ty = y1;\n\t}\n\n\tstatic void dfs(int u) {\n\t\tint counter = 1;\n\t\tfor (int v : ad[u])\n\t\t\tif (ans[v] == 0) {\n\t\t\t\tif (counter == ans[u]) {\n\t\t\t\t\tcounter++;\n\t\t\t\t\tans[v] = counter;\n\t\t\t\t} else\n\t\t\t\t\tans[v] = counter++;\n\t\t\t\tif (counter > k)\n\t\t\t\t\tf = false;\n\t\t\t\tdfs(v);\n\t\t\t}\n\t}\n\n\tstatic void bfs(int s) {\n\t\tQueue q = new LinkedList();\n\t\tq.add(s);\n\t\tans[s] = 1;\n\t\twhile (!q.isEmpty()) {\n\t\t\tint u = q.remove();\n\t\t\tint c = 1;\n\t\t\tfor (int v : ad[u]) {\n\t\t\t\tif (ans[v] == 0) {\n\t\t\t\t\t// System.out.println(u);\n\t\t\t\t\tif (c == ans[u]) {\n\t\t\t\t\t\tc++;\n\t\t\t\t\t\tans[v] = c++;\n\t\t\t\t\t} else\n\t\t\t\t\t\tans[v] = c++;\n\t\t\t\t\t// System.out.println(v+\" \"+c);\n\t\t\t\t\tif (ans[v] > k)\n\t\t\t\t\t\tf = false;\n\t\t\t\t\tq.add(v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void seive() {\n\t\tsi = new int[1000001];\n\t\tprimes = new ArrayList<>();\n\t\tint N = 1000001;\n\t\tsi[1] = 1;\n\t\tfor (int i = 2; i < N; i++) {\n\t\t\tif (si[i] == 0) {\n\t\t\t\tsi[i] = i;\n\t\t\t\tprimes.add(i);\n\t\t\t}\n\t\t\tfor (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)\n\t\t\t\tsi[primes.get(j) * i] = primes.get(j);\n\n\t\t}\n\t}\n\n\tstatic long inver(long x) {\n\t\tint a = (int) x;\n\t\tlong e = (mod - 2);\n\t\tlong res = 1;\n\t\twhile (e > 0) {\n\t\t\tif ((e & 1) == 1) {\n\t\t\t\t// System.out.println(res*a);\n\t\t\t\tres = (int) ((1l * res * a) % mod);\n\t\t\t}\n\t\t\ta = (int) ((1l * a * a) % mod);\n\t\t\te >>= 1;\n\t\t}\n\t\t// out.println(res+\" \"+x);\n\t\treturn res % mod;\n\t}\n\n\tstatic long fac(int n) {\n\t\tif (n == 0)\n\t\t\treturn fac[n] = 1;\n\t\tif (n == 1)\n\t\t\treturn fac[n] = 1;\n\t\tlong ans = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = ans = (i % mod * ans % mod) % mod;\n\t\treturn ans % mod;\n\t}\n\n\tstatic int gcd(int a, int b) {\n\n\t\tif (b == 0)\n\t\t\treturn a;\n\t\treturn gcd(b, a % b);\n\t}\n\n\tstatic class unionfind {\n\t\tint[] p;\n\t\tint[] size;\n\n\t\tunionfind(int n) {\n\t\t\tp = new int[n];\n\t\t\tsize = new int[n];\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tp[i] = i;\n\t\t\t}\n\t\t\tArrays.fill(size, 1);\n\t\t}\n\n\t\tint findSet(int v) {\n\t\t\tif (v == p[v])\n\t\t\t\treturn v;\n\t\t\treturn p[v] = findSet(p[v]);\n\t\t}\n\n\t\tboolean sameSet(int a, int b) {\n\t\t\ta = findSet(a);\n\t\t\tb = findSet(b);\n\t\t\tif (a == b)\n\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\n\t\tint max() {\n\t\t\tint max = 0;\n\t\t\tfor (int i = 0; i < size.length; i++)\n\t\t\t\tif (size[i] > max)\n\t\t\t\t\tmax = size[i];\n\t\t\treturn max;\n\t\t}\n\n\t\tvoid combine(int a, int b) {\n\t\t\ta = findSet(a);\n\t\t\tb = findSet(b);\n\t\t\tif (a == b)\n\t\t\t\treturn;\n\t\t\tif (size[a] > size[b]) {\n\t\t\t\tp[b] = a;\n\t\t\t\tsize[a] += size[b];\n\n\t\t\t} else {\n\t\t\t\tp[a] = b;\n\t\t\t\tsize[b] += size[a];\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\n\t\tpublic Scanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic char nextChar() throws IOException {\n\t\t\treturn next().charAt(0);\n\t\t}\n\n\t\tpublic Long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(3000);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7d998b34f0e50c39626dbe032c745399", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String []arg) throws FileNotFoundException{\n Scanner s=new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out) ;\n int u=s.nextInt();\n int v=s.nextInt();\n int t=s.nextInt()-2;\n int x=s.nextInt();\n int temp=0;\n if(u>v){temp=u;u=v;v=temp;}\n int ans=u+v;\n while(t>0){\n if(u<=v){u=u+x;ans=ans+u;}\n else{v=v+x;ans=ans+v;}\n t--;\n }\n out.print(ans);\n out.flush();\n \nout.close)(;\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "47d8a3400d43d92743176c4c878bfbe1", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "public class Cal {\n static Scanner input = new Scanner(System.in);\n static int v1, v2, t, d;\n public static void main(String[] args) {\n \n v1=input.nextInt();\n v2=input.nextInt();\n t=input.nextInt();\n d=input.nextInt();\n \n int c=1;\n int total=0;\n if (v1==v2){\n System.out.println (v1*t);\n }\n \n total=v1;\n \n while (c<=t-2){\n \n // 7 , 12-10\n \n total =total+ Math.min(v1 + c*d, (v2+(t-1)*d) - c*d);\n \n c++;\n \n }\n total=total+v2;\n \n System.out.println(total);\n \n \n \n }\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "806e9c5fd413c7828ca43f6f6dc7f97c", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class B534 {\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int v1 = scan.nextInt();\n int v2 = scan.nextInt();\n int t = scan.nextInt();\n int d = scan.nextInt();\n int sum = v2 + v1, cal = v2;\n t-=2;\n for (int i = t; i>=1; i--){\n int v = v1 + d*i;\n if (Math.abs(v - cal)>d){\n cal = v -Math.abs((v - cal)-d);\n sum += cal;\n }\n else{\n sum+=v;\n }\n }\n System.out.println(sum);\n\n }\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da400dc94c8445a9314a71159bd7f9ad", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class test\n{\n public static void main(String args[]) throws IOException\n {\n InputStreamReader inp = new InputStreamReader(System.in);\n BufferedReader br = new BufferedReader(inp);\n \n \n String s[] = br.readLine().split(\" \");\n\n int v1 = Integer.parseInt(s[0]);\n int v2 = Integer.parseInt(s[1]);\n\n String s1[] = br.readLine().split(\" \");\n\n int t = Integer.parseInt(s1[0]);\n int d = Integer.parseInt(s1[1]);\n int sum=0;\n while(t--)\n {\n if(v1<=v2)\n {\n sum+=v1;\n v1+=d;\n }\n else\n {\n sum+=v2;\n v2+=d;\n }\n }\n System.out.println(sum);\n \n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a17381c978861413a849466950ae9f20", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "package com.coding.codeforces_3rdNov_2017;\n\nimport java.util.Scanner;\n\n/**\n * Created by sameer on 03/11/17.\n */\npublic class Q2 {\n public static void main(String args[])\n {\n int[] a = new int[25];\n Scanner s = new Scanner(System.in);\n\n for (int i = 1; i <= 24; ++i) {\n a[i] = s.nextInt();\n }\n\n if (equal(a, 1, 6, 3, 8) &&\n equal(a, 5, 10, 7, 12) &&\n equal(a, 11, 21, 9, 23) &&\n equal(a, 22, 4, 24, 2) &&\n equal(a, 17, 18, 19, 20) &&\n equal(a, 13, 14, 15, 16))\n {\n System.out.println(\"YES\");\n } else if (equal(a, 1, 23, 3, 21) &&\n equal(a, 5, 2, 7, 4) &&\n equal(a, 11, 8, 9, 6) &&\n equal(a, 22, 12, 24, 10) &&\n equal(a, 17, 18, 19, 20) &&\n equal(a, 13, 14, 15, 16))\n {\n System.out.println(\"YES\");\n } else if (equal(a, 3, 18, 4, 20) &&\n equal(a, 17, 12, 19, 11) &&\n equal(a, 9, 13, 10, 15) &&\n equal(a, 14, 2, 16, 1) &&\n equal(a, 5, 6, 7, 8) &&\n equal(a, 21, 22, 23, 24))\n {\n System.out.println(\"YES\");\n } else if (equal(a, 3, 15, 4, 13) &&\n equal(a, 17, 1, 19, 2) &&\n equal(a, 9, 20, 10, 18) &&\n equal(a, 14, 11, 16, 12) &&\n equal(a, 5, 6, 7, 8) &&\n equal(a, 21, 22, 23, 24))\n {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n private static boolean equal(int[] a, int i, int j, int k, int l) {\n return a[i] == a[j] && a[k] == a[l] && a[i] == a[k];\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a0acd09418ec85ed962b0bee5037a7f", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) {\n return null;\n }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n char nextChar() throws IOException {\n return (char) (br.read());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\nboolean same(int x1, int x2, int x3, int x4) {\n return (x1 == x2 && x2 == x3 && x3 == x4);\n}\n private void solve() throws IOException {\n int[] a = new int[25];\n int n = 24;\n for (int i = 1; i <= 24; i++) {\n a[i] = nextInt();\n }\n\n boolean[] faceOk = new boolean[6];\n\n int cnt = 0;\n for (int i = 0; i < 6; i++) {\n faceOk[i] = same(a[i * 4 + 4],a[i * 4+1],a[i * 4+2],a[i * 4+3]);\n if (faceOk[i]) cnt++;\n }\n\n if (cnt == 6) {\n throw new IOException();\n }\n if (cnt != 2) {\n out.println(\"NO\");\n return;\n }\n\n if (faceOk[0] != faceOk[2] || faceOk[1] != faceOk[5] || faceOk[3] != faceOk[4])\n {\n out.println(\"NO\");\n return;\n }\n\n\n if (faceOk[0]) {\n if (same(a[5], a[6], a[19], a[20]) && same(a[17], a[18], a[23], a[24]) && same(a[21], a[22], a[15], a[16]) && same(a[13], a[14], a[7], a[8])) {\n out.println(\"YES\");\n return;\n }\n if (same(a[5], a[6], a[15], a[16]) && same(a[13], a[14], a[23], a[24]) && same(a[21], a[22], a[19], a[20]) && same(a[17], a[18], a[7], a[8])) {\n out.println(\"YES\");\n return;\n }\n out.println(\"NO\");\n return;\n }\n\n if (faceOk[1]) {\n if (same(a[17], a[19], a[1], a[2]) && same(a[3], a[4], a[13], a[15]) && same(a[14], a[16], a[11], a[12]) && same(a[9], a[10], a[18], a[20])) {\n out.println(\"YES\");\n return;\n }\n if (same(a[17], a[19], a[11], a[12]) && same(a[9], a[10], a[13], a[15]) && same(a[14], a[16], a[1], a[2]) && same(a[3], a[4], a[18], a[20])) {\n out.println(\"YES\");\n return;\n }\n out.println(\"NO\");\n return;\n }\n\n if (faceOk[3]) {\n if (same(a[1], a[3], a[6], a[8]) && same(a[5], a[7], a[10], a[12]) && same(a[9], a[11], a[21], a[23]) && same(a[22], a[24], a[2], a[4])) {\n out.println(\"YES\");\n return;\n }\n if (same(a[1], a[3], a[21], a[23]) && same(a[22], a[24], a[10], a[12]) && same(a[9], a[11], a[6], a[8]) && same(a[5], a[7], a[2], a[4])) {\n out.println(\"YES\");\n return;\n }\n out.println(\"NO\");\n return;\n }\n\n throw new IOException();\n }\n\n void run() throws IOException {\n // br = new BufferedReader(new FileReader(\"input.txt\"));\n // out = new PrintWriter(\"output.txt\");\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n // Locale.setDefault(Locale.US);\n new C().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ab84e9d362e84c3d03ebec95ba65b0ae", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "package g;\nimport java .util.*;\npublic class St \n{\n\tpublic static void main(String[]args)\n\t{\n Scanner sc= new Scanner(System.in);\n String [] s1=(sc.nextLine()).split(\" \");\n String []s2=s1.clone();\n \n if(check(s1)){\n\t \t System.out.print(\"NO\");\n\t \t return;\n\t \t }\n else{\n String x1=s1[0];\n String x2=s1[4];\n String x3=s1[8];\n String x4=s1[21];\n s1[4] =x1;\n s1[6] =x1;\n s1[8] =x2;\n s1[10]=x2;\n s1[21]=x3;\n s1[23]=x3;\n s1[0] =x4;\n s1[2] =x4;\n if(check(s1)){\n \t System.out.print(\"YES\");\n \t return;\n \t }\n else\n {\n reset(s1,s2);\n\t s1[21]=x1;\n\t s1[23]=x1;\n\t s1[0]=x2;\n\t s1[2]=x2;\n\t s1[4]=x3;\n\t s1[6]=x3;\n\t s1[8]=x4;\n\t s1[10]=x4;\n\t if(check(s1)){\n\t \t System.out.print(\"YES\");\n\t \t return;\n\t \t }\n\t else\n\t { reset(s1,s2);\n String x11=s1[0];\n\t String x22=s1[17];\n\t String x33=s1[10];\n\t String x44=s1[12];\n\t s1[1]=x44;\n\t s1[0]=x44;\n\t s1[14]=x33;\n\t s1[12]=x33;\n\t s1[17]=x11;\n\t s1[19]=x11;\n\t s1[10]=x22;\n\t s1[11]=x22;\n\t if(check(s1)){\n\t \t System.out.print(\"YES\");\n\t \t return;\n\t \t }\n\t else\n\t { reset(s1,s2);\n\t\t s1[1]=x22;\n\t\t s1[0]=x22;\n\t\t s1[14]=x11;\n\t\t s1[12]=x11;\n\t\t s1[17]=x33;\n\t\t s1[19]=x33;\n\t\t s1[10]=x44;\n\t\t s1[11]=x44;\n\t\t if(check(s1)){\n\t\t \t System.out.print(\"YES\");\n\t\t \t return;\n\t\t \t }\n\t\t else\n\t\t { reset(s1,s2);\n\t String x111=s1[12];\n\t\t String x222=s1[4];\n\t\t String x333=s1[16];\n\t\t String x444=s1[20];\n\t\t s1[12]=x444;\n\t\t s1[13]=x444;\n\t\t s1[20]=x333;\n\t\t s1[21]=x333;\n\t\t s1[4]=x111;\n\t\t s1[5]=x111;\n\t\t s1[16]=x222;\n\t\t s1[17]=x222;\n\t\t if(check(s1)){\n\t\t \t System.out.print(\"YES\");\n\t\t \t return;\n\t\t \t }\n\t\t else\n\t\t { reset(s1,s2);\n\t\t\t s1[12]=x222;\n\t\t\t s1[13]=x222;\n\t\t\t s1[20]=x111;\n\t\t\t s1[21]=x111;\n\t\t\t s1[4]=x333;\n\t\t\t s1[5]=x333;\n\t\t\t s1[16]=x444;\n\t\t\t s1[17]=x444;\n\t\t\t \n\t\t\t if(check(s1)){\n\t\t\t \t System.out.print(\"YES\");\n\t\t\t \t return;\n\t\t\t \t }\n\t\t else\n\t\t {\n\t\t\t System.out.print(\"NO\");\n\t\t }\n\t\t \n\t }\n\t\t \n\t }\n }\n \n \n\t }\n\t }\n }\n } \n\t static void reset(String [] s1,String [] s2)\n\t {\n\t\t for(int i=0;i= 2; i--) cube[seq[i]] = cube[seq[i - 2]];\n cube[seq[0]] = temp1;\n cube[seq[1]] = temp2;\n }\n }\n\n private boolean checkit(int cube[]) {\n for (int i = 1; i <= 24; i++) {\n if (cube[i] != cube[(((i / 4) - (i % 4 == 0 ? 1 : 0)) * 4) + 1]) return false;\n }\n return true;\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "933f196a93b9e46829adaee152e4eb84", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "public class zher{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int s= in.next();\n if (s%==0) System.out.println(2);\n else System.out.println(1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bb7f171ca144394e56294819c72b9e4b", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author Nicol\u00e1s P\u00e9rez Garay\n */\npublic class Main {\n\n /**\n *\n * @param args\n */\n public static void main(String[] args) {\n Scanner leer= new Scanner(System.in);\n int p=2,a=1;\n \n while(leer.hasNextInt()){\n int n=0;\n n= leer.nextInt();\n \n \n if (n>0){\n if(n%2!=0){\n System.out.println(a);\n }\n else{\n System.out.println(p);\n }\n }\n else{\n System.exit(0);\n }\n }\n }\n \n// 1508912323750\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f839fc80364b3760a3dd2ac5d2462f9", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n long l;\n Scanner sc=new Scanner(System.in);\n l=sc.nextInt();\n \n if(l%2!=0)System.out.println(\"1\");\n else System.out.println(\"2\");\n\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "26726339ed34b27059ce92e9d72132ce", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "public class Solution {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n System.out.println(scanner.nextInt() % 2 == 0 ? 2 : 1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "471237972f77b32104c2c8b075de1525", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\n\npublic class Main {\n\n\t// split de array\n\tpublic static int[] atoi(String cad) {\n\t\tString read[] = cad.split(\" \");\n\t\tint res[] = new int[read.length];\n\t\tfor (int i = 0; i < read.length; i++) {\n\t\t\tres[i] = Integer.parseInt(read[i]);\n\t\t}\n\t\treturn res;\n\t}\n\n\t// split de String\n\tpublic static String[] atos(String cad) {\n\t\treturn cad.split(\" \");\n\t}\n\n\t// parsing de String a int\n\tpublic static int parseo(String cad, int index) {\n\t\treturn Integer.parseInt(cad.split(\" \")[index]);\n\t}\n\n\t// memory status\n\tstatic String memoryStatus() {\n\t\treturn (Runtime.getRuntime().totalMemory()\n\t\t\t\t- Runtime.getRuntime().freeMemory() >> 20)\n\t\t\t\t+ \"/\" + (Runtime.getRuntime().totalMemory() >> 20) + \" MB\";\n\t}\n\n\t// imprimir array\n\tstatic void printArrayInt(int[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tSystem.out.print(\" \");\n\t\t\tSystem.out.print(array[i]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\t// impresion de datos\n\tstatic void print(Object... obj) {\n\t\tfor (int i = 0; i < obj.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tSystem.out.print(\" \");\n\t\t\tSystem.out.print(obj[i]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(in.readLine());\n\t\tArrayList lista=new ArrayList<>(500);\n\t\tlista.add(1);\n\t\tlista.add(3);\n\t\tfor (int i = 3;((i*(i+1))/2)<=500 ; i++) {\n\t\t\tlista.add(((i*(i+1))/2));\n\t\t}\n\t\tif(lista.contains(n))System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b1fc4375a8c95ca1d56304024ceb644d", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n//import 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 ASUS\n */\n/*public class Pro3 {\n static int gcd(int x,int y){\n if(x==0)\n return y;\n if(y==0)\n return x;\n if(x>y)\n return gcd(x-y,y);\n return gcd(x,y-x);\n }\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int temp1 = n;\n int temp2 = n-2;\n int sum=0;\n for(int i=2;i=i){\n int temp3 = n%i;\n n=n/i;\n sum+=temp3;\n }\n sum+=n;\n n=temp1;\n \n }\n int e=gcd(sum,temp2);\n System.out.println(sum/e + \"/\" + temp2/e);\n }\n \n}*/\nimport java.util.Scanner;\npublic class Main {\n static boolean isTri(int num){\n if(num<0)\n return false;\n int sum=0;\n for(int i=1;sum<=num;i++){\n sum+=i;\n if(sum==num)\n return true;\n \n }\n return false;\n }\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int num = in.nextInt();\n if(isTri(num)){\n System.out.println(\"YES\");\n }\n else\n System.out.println(\"NO\");\n \n }\n \n}\n\u00a0\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0b347ef02a9a67024e9225f650a45b3b", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.Arrays;\nimport java.util.concurrent.*;\nimport java.util.regex.*;\n\npublic class Solution\n{\npublic static void main (String args[])throws IOException\n{\nScanner in=new Scanner(System.in);\nint n,t,t1;\nt=in.nextInt();\nn=Math.sqrt(1+(8*t));\nn=(n-1)/2;\nif(n*(n+1)/2==t)\nSystem.out.println(\"YES\");\nelse\nSystem.out.println(\"NO\");\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "512caf5a067e503df96efb452c542fed", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\n/**\n *\n * @author xergioalex\n */\npublic class Main {\n\n \n public static void main(String[] args) throws IOException {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); \n StringTokenizer token;\n String in= input.readLine(); \n while(in != null){ \n int n = Integer.valueOf(in);\n double root = n;\n root = Math.sqrt(8*n+1);\n n = (int) root;\n if(root == n){ \n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n in= input.readLine();\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "df64e2eee6228cb6a1df168523b77fe0", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0} {"lang": "Java 11", "source_code": "public class Main{\n public static void main(String args[]){\n Scanner no=new Scanner(System.in);\n String m=no.next();\n String n=no.next();\n for(int i=0;i= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException\n {\n long ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n if (neg)\n return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException\n {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.')\n {\n while ((c = read()) >= '0' && c <= '9')\n {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n if (neg)\n return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException\n {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException\n {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException\n {\n if (din == null)\n return;\n din.close();\n }\n }\n public static void main(String[] args) {\n Reader sc = new Reader();\n String s1 = sc.readLine();\n String s2 = sc.readLine();\n String s = \"\";\n for(int i = 0 ; i< s1.length() ; i++){\n if(s1.charAt(i) == s2.charAt(i)){\n s += 0;\n }\n else{\n s += 1;\n }\n }\n System.out.println(s);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4b37044b3bfbb736b600c3c6c66a6f69", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class na\n{\n public static void main(String ar[])\n {\n Scanner scan= new Scanner(System.in);\n String s1=scan.next();\n String s2=scan.next();\n for(int i=0;i hs = new HashSet<>();\n int aa==a;\n int bb=b;\n int cc=c;\n int ii=0; int jj=0; int kk=0;\n outer: for(int i=1; i<=1000; i++) {\n for(int j=1; j<=1000; j++) {\n if(i+j>1000) break;\n for(int k=1; k<=1000; k++) {\n if(i+j+k>1000) break;\n int aa==a;\n int bb=b;\n int cc=c;\n if(i*j==aa) aa=-1;\n else if(i*k==aa) aa=-1\n else if(j*k==aa) aa=-1;\n \n if(i*j==bb) bb=-1;\n else if(i*k==bb) bb=-1\n else if(j*k==bb) bb=-1;\n\n if(i*j==cc) cc=-1;\n else if(i*k==cc) cc=-1\n else if(j*k==cc) cc=-1;\n if(aa==-1 && bb==-1 && cc==-1) {\n ii=i; jj=j; kk=k; \n break outer;\n }\n }\n }\n }\n out.println(ii*4 + jj*4 + kk*4);\n } \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3ac136efa56a9110027a1108475547b", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class prob34 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n new prob34().solve(in,out);\n in.close();\n out.close();\n }\n\n private void solve(Scanner in, PrintWriter out) {\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int ii=0; int jj=0; int kk=0;\n outer: for(int i=1; i<=1000; i++) {\n for(int j=1; j<=1000; j++) {\n if(i+j>1000) break;\n for(int k=1; k<=1000; k++) {\n if(i+j+k>1000) break;\n int aa=a;\n int bb=b;\n int cc=c;\n if(i*j==aa) aa=-1;\n else if(i*k==aa) aa=-1\n else if(j*k==aa) aa=-1;\n \n if(i*j==bb) bb=-1;\n else if(i*k==bb) bb=-1\n else if(j*k==bb) bb=-1;\n\n if(i*j==cc) cc=-1;\n else if(i*k==cc) cc=-1\n else if(j*k==cc) cc=-1;\n if(aa==-1 && bb==-1 && cc==-1) {\n ii=i; jj=j; kk=k; \n break outer;\n }\n }\n }\n }\n out.println(ii*4 + jj*4 + kk*4);\n } \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "afadd4da92c358f69292926d50f57463", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class supercentral_points {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint a = in.nextInt();\n\t\tint b=in.nextInt();\n\t\tint c=in.nextInt();\n int peri=0;\n int s[] = new int[6];\n\t\tint s[0] = (int)Math.sqrt(a);\n int s[1] = a/s[0];\n int s[2] = (int)Math.sqrt(b);\n int s[3]= b/s[2];\n int s[4] = (int)Math.sqrt(c);\n int s[5] = c/s[4];\n for(int i=0 ; i<6 ; i++)\n peri=peri+s[i];\n\t\tSystem.out.println(peri*2);\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b8069e1f78e13af6e47be4652fecf682", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n \n \npublic class java1 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long x =in.nextLong(), y = in.nextLong(), z = in.nextLong();\n long a = Math.sqrt(z*x/y);\n long b = Math.sqrt(x*y/z);\n long c = Math.sqrt(z*y/x);\n\n System.out.println(4*(a + b + c));\n } \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d69ef4909b14b56f0142465b0e5d62f1", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Mufaddal Naya\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 CGarland solver = new CGarland();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CGarland {\n int dp;\n\n public void solve(int testNumber, InputReader c, OutputWriter w) {\n int n = c.readInt();\n int a[] = c.readIntArray(n);\n int even = n / 2, odd = (n - 1) / 2 + 1;\n dp = new int[n][n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n Arrays.fill(dp[i][j], -1);\n }\n }\n for (int i = 0; i < n; i++) {\n if (a[i] != 0) {\n if (a[i] % 2 == 0) {\n even--;\n } else {\n odd--;\n }\n }\n }\n w.printLine(Math.min(solve_(0, a, 1, even, odd), solve_(0, a, 0, even, odd)));\n }\n\n private int solve_(int x, int[] a, int pre, int even, int odd) {\n\n if (x >= a.length) {\n return 0;\n }\n if (dp[x][even][odd] != -1) {\n return dp[x][even][odd];\n }\n\n int res = a.length;\n if (a[x] == 0) {\n if (even > 0) {\n res = Math.min(res, solve_(x + 1, a, 1, even - 1, odd) + pre ^ 1);\n }\n if (odd > 0) {\n res = Math.min(res, solve_(x + 1, a, 0, even, odd - 1) + pre);\n }\n } else {\n if (a[x] % 2 == 0) {\n res = Math.min(res, solve_(x + 1, a, 1, even, odd) + pre ^ 1);\n } else {\n res = Math.min(res, solve_(x + 1, a, 0, even, odd) + pre);\n }\n }\n dp[x][even][odd] = res;\n return res;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n\n static class 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[] readIntArray(int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = readInt();\n }\n return array;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bcc9355eab5e49c9bcd5f52b5f8a4b36", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n \npublic class r612c {\n\tstatic int[] a;\n\tstatic int[][][][] dp;\n\tpublic static void main(String[] args) {\n\t\tScanner scan=new Scanner(System.in);\n\t\tint n=scan.nextInt();\n\t\ta=new int[n];\n\t\tint o=0,e=0;\n\t\tfor(int i=0;i0) {\n\t\t\t\tif(a[i]%2==1) o++;\n\t\t\t\telse e++;\n\t\t\t}\n\t\t}\n\t\tint ohave=n/2+n%2, ehave=n/2;\n\t\tint oleft=ohave-o, eleft=ehave-e;\n\t\tdp=new int[n][oleft+1][eleft+1][2];\n\t\tfor(int[][][] d:dp) for(int[][] dd:d) for(int[] ddd:dd) Arrays.fill(ddd,-1);\n\t\tSystem.out.println(go(0,oleft,eleft,0));\n\t}\n\tpublic static int go(int at, int o, int e, int prev) {\n\t if(at==a.length) return 0;\n\t\tif(dp[at][o][e][prev]!=-1) return dp[at][o][e][prev];\n\t\tint res=Integer.MAX_VALUE/2-5;\n\t\t\n\t\tif(a[at]!=0) {\n\t\t\tint add=0;\n\t\t\t\n\t\t\tif(at!=0) {\n\t\t\t\tif(prev!=a[at]%2) add++;\n\t\t\t}\n\t\t\tres=Math.min(res,add+go(at+1,o,e,a[at]%2)); \n\t\t}\n\t\telse {\n\t\t\tint adde=0, addo=0;\n\t\t\tif(at!=0) {\n\t\t\t\tif(prev!=0) adde++;\n\t\t\t}\n\t\t\tif(at!=0) {\n\t\t\t\tif(prev!=1) addo++;\n\t\t\t}\n\t\t\t\n\t\t\tif(o>0) res=Math.min(res,addo+go(at+1,o-1,e,1));\n\t\t\tif(e>0) res=Math.min(res,adde+go(at+1,o,e-1,0));\n\t\t}\n\t\treturn dp[at][o][e][prev]=res;\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "297489d2ba0aab77932115b02b3f8595", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CGarland solver = new CGarland();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CGarland {\n static int totalOdd;\n static int totalEven;\n static int curSum;\n static int[] arr;\n static Integer[][][] memo;\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n int n = sc.nextInt();\n arr = new int[n];\n int even = 0, odd = 0;\n HashSet set = new HashSet<>();\n for (int i = 1; i <= n; i++)\n set.add(i);\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextInt();\n set.remove(arr[i]);\n }\n for (int x : set) {\n odd += x % 2;\n even += (x % 2) ^ 1;\n }\n totalOdd = odd;\n totalEven = even;\n curSum = new int[n + 1];\n curSum[0] = arr[0] == 0 ? 1 : 0;\n for (int i = 1; i < n; i++)\n curSum[i] = curSum[i - 1] + (arr[i] == 0 ? 1 : 0);\n curSum[n] = curSum[n - 1];\n memo = new Integer[3][n][n + 1];\n pw.println(dp(0, -1, odd));\n }\n\n private int dp(int idx, int prev, int curOdd) {\n int curEven = totalEven - (curSum[idx] - (totalOdd - curOdd));\n if (curEven < 0 || curOdd < 0)\n return (int) 1e9;\n if (idx == arr.length)\n return 0;\n if (memo[prev + 1][idx][curOdd] != null)\n return memo[prev + 1][idx][curOdd];\n if (arr[idx] != 0) {\n int temp;\n if (prev == -1)\n temp = dp(idx + 1, arr[idx] % 2, curOdd);\n temp = (arr[idx] + prev) % 2 + dp(idx + 1, arr[idx] % 2, curOdd);\n return memo[prev + 1][idx][curOdd] = temp;\n }\n int even = prev + dp(idx + 1, 0, curOdd);\n int odd = (prev + 1) % 2 + dp(idx + 1, 1, curOdd - 1);\n return memo[prev + 1][idx][curOdd] = Math.min(even, odd);\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eacfd6020e5ac1cc9ea291fc2d35e005", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CGarland solver = new CGarland();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CGarland {\n static int sum;\n static int[] arr;\n static Integer memo;\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n int n = sc.nextInt();\n arr = new int[n];\n int even = 0, odd = 0;\n HashSet set = new HashSet<>();\n for (int i = 1; i <= n; i++)\n set.add(i);\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextInt();\n set.remove(arr[i]);\n }\n for (int x : set) {\n odd += x % 2;\n even += (x % 2) ^ 1;\n }\n sum = even + odd;\n memo = new Integer[3][n][n];\n pw.println(dp(0, -1, odd));\n }\n\n private int dp(int idx, int prev, int curOdd) {\n if (idx == arr.length)\n return 0;\n int curEven = sum - curOdd;\n if (curEven < 0 || curOdd < 0)\n return (int) 1e9;\n if (memo[prev + 1][idx][curOdd] != null)\n return memo[prev + 1][idx][curOdd];\n if (arr[idx] != 0) {\n if (prev == -1)\n return dp(idx + 1, arr[idx] % 2, curOdd);\n int even = arr[idx] % 2 + dp(idx + 1, arr[idx] % 2, curOdd);\n int odd = (1 + arr[idx] % 2) + dp(idx + 1, arr[idx] % 2, curOdd - 1);\n return memo[prev + 1][idx][curOdd] = Math.min(even, odd);\n }\n return memo[prev + 1][idx][curOdd] = dp(idx + 1, arr[idx] % 2, curOdd);\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8cebeff51cf6043b26baa8c8757805e6", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "public class Codechef {\r\n public static void main(String[] args) {\r\n Scanner sc = new Scanner(System.in);\r\n int t = sc.nextInt();\r\n for (int j = 0; j < t; j++) {\r\n int key = sc.nextInt();\r\n int dwz = 0;\r\n int[] arr = new int[10];\r\n for (int i = 0; i < 3; i++) {\r\n arr[i] = sc.nextInt();\r\n }\r\n for (int i = 0; i < 3; i++) {\r\n if (arr[i] == 0) {\r\n dwz = i+1;\r\n break;\r\n }\r\n\r\n\r\n }\r\n if (key == dwz || arr[key-1] == dwz) {\r\n System.out.println(\"NO\");\r\n } else {\r\n System.out.println(\"YES\");\r\n }\r\n\r\n\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "76b8ba4465dcab3f728043b3a2b9cbbd", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.lang.*;\r\nimport java.util.*;\r\nimport java.util.Scanner;\r\npublic class Marathon{\r\n static String competetion(int arr[], int key){\r\n if(key>3)\r\n return \"NO\";\r\n Arrays.sort(arr);\r\n int count = 0;\r\n if(arr[0]<=3 && arr[0]>=1 &&arr[0]!= key){\r\n count++;\r\n }\r\n for(int i = 1;i<3;i++){\r\n if(arr[i]<=3 && arr[i]>=1 && arr[i]!=arr[i-1] && arr[i]!=key){\r\n count++;\r\n }\r\n }\r\n if(count == 3){\r\n return \"YES\";\r\n }else{\r\n return \"NO\";\r\n }\r\n }\r\n public static void main(String[] args){\r\n int test;\r\n Scanner input = new Scanner(System.in);\r\n test = input.nextInt();\r\n for(int i = 0; i prev) step = curr - prev;\n else step = n - prev + curr;\n // System.out.println(\"step:\" + step);\n if (used[step]) {\n if (perm[prev] != step) {\n System.out.println(-1);\n return;\n }\n } \n used[step] = true;\n perm[prev] = step;\n prev = curr;\n }\n \n if (n == 1) {\n System.out.println(1);\n return;\n }\n \n for (int i=1 ; i<=n ; i++) {\n if (perm[i] == 0) {\n for (int j=1 ; j<=n ; j++) {\n if (used[j]) continue;\n \n perm[i] = j;\n used[j] = true;\n break;\n }\n }\n }\n for (int i=1 ; i<=n ; i++) System.out.print(perm[i] + \" \");\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d7bacd2d7fdcaa61eabfda42ca682334", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.Set;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author saadnoor\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n int inputArray = new int[1023];\n\n public boolean isValid(int ans[], int m, int n) {\n for (int i = 0; i < m - 1; i++) {\n int next = (inputArray[i] + ans[inputArray[i]]) % n;\n if (next == 0) next = n;\n //System.out.println(i+\"next ->\"+next);\n if (next != inputArray[i + 1]) return false;\n }\n Set S = new HashSet<>();\n for (int i = 0; i < n; i++) {\n S.add(ans[i + 1]);\n }\n if (S.size() != n) return false;\n return true;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n, m;\n n = in.nextInt();\n m = in.nextInt();\n\n int myArray[] = new int[1023];\n for (int i = 0; i < m; i++) {\n inputArray[i] = in.nextInt();\n }\n int ans[] = new int[10234];\n int needToadd = 0;\n for (int i = 0; i < m; i++) {\n if (i == 0) myArray[0] = inputArray[0];\n else {\n if (!(inputArray[i - 1] < inputArray[i])) needToadd += n;\n myArray[i] = inputArray[i] + needToadd;\n }\n }\n for (int i = 0; i < m; i++) {\n // out.println(myArray[i]);\n }\n Arrays.fill(ans, -1);\n int visited[] = new int[12345];\n Arrays.fill(visited, 0);\n for (int i = 1; i < m; i++) {\n int node = myArray[i - 1] % n;\n if (node == 0) node = n;\n if (ans[node] != -1) {\n // out.println(-1);\n // break;\n }\n visited[node] = 1;\n // out.println(\"arr fak: \"+(myArray[i]-myArray[i-1]));\n ans[node] = myArray[i] - myArray[i - 1];\n }\n ArrayList vec = new ArrayList<>();\n ArrayList values = new ArrayList<>();\n for (int i = 1; i <= n; i++) {\n if (ans[i] == -1) vec.add(i);\n }\n for (int i = 1; i <= n; i++) {\n if (visited[i] == 0) values.add(i);\n }\n if (values.size() != vec.size()) {\n out.println(-1);\n } else {\n for (int i = 1; i <= values.size(); i++) {\n ans[vec.get(i - 1)] = values.get(i - 1);\n }\n if (isValid(ans, m, n)) {\n for (int i = 0; i < n; i++) {\n out.print(ans[i + 1] + \" \");\n }\n\n } else out.println(-1);\n }\n\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8d4b23210806de74a097e9da5aa2a798", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.Set;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author saadnoor\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n int inputArray = new int[1023];\n\n public boolean isValid(int ans[], int m, int n) {\n if (true) return true;\n for (int i = 0; i < m - 1; i++) {\n int next = (inputArray[i] + ans[inputArray[i]]) % n;\n if (next == 0) next = n;\n //System.out.println(i+\"next ->\"+next);\n if (next != inputArray[i + 1]) return false;\n }\n Set S = new HashSet<>();\n for (int i = 0; i < n; i++) {\n S.add(ans[i + 1]);\n }\n if (S.size() != n) return false;\n return true;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n, m;\n n = in.nextInt();\n m = in.nextInt();\n\n int myArray[] = new int[1023];\n for (int i = 0; i < m; i++) {\n inputArray[i] = in.nextInt();\n }\n int ans[] = new int[10234];\n int needToadd = 0;\n for (int i = 0; i < m; i++) {\n if (i == 0) myArray[0] = inputArray[0];\n else {\n if (!(inputArray[i - 1] < inputArray[i])) needToadd += n;\n myArray[i] = inputArray[i] + needToadd;\n }\n }\n for (int i = 0; i < m; i++) {\n // out.println(myArray[i]);\n }\n Arrays.fill(ans, -1);\n int visited[] = new int[12345];\n Arrays.fill(visited, 0);\n for (int i = 1; i < m; i++) {\n int node = myArray[i - 1] % n;\n if (node == 0) node = n;\n if (ans[node] != -1) {\n // out.println(-1);\n // break;\n }\n visited[myArray[i] - myArray[i - 1]] = 1;\n // out.println(\"arr fak: \"+(myArray[i]-myArray[i-1]));\n ans[node] = myArray[i] - myArray[i - 1];\n }\n for (int i = 1; i <= n; i++) {\n // if(ans[i]!=-1)visited[i]=1;\n // out.println(ans[i]);\n }\n ArrayList vec = new ArrayList<>();\n ArrayList values = new ArrayList<>();\n for (int i = 1; i <= n; i++) {\n if (ans[i] == -1) vec.add(i);\n }\n for (int i = 1; i <= n; i++) {\n if (visited[i] == 0) {\n values.add(i);\n }\n }\n if (values.size() != vec.size()) {\n out.println(-1);\n } else {\n for (int i = 1; i <= values.size(); i++) {\n ans[vec.get(i - 1)] = values.get(i - 1);\n }\n if (isValid(ans, m, n)) {\n for (int i = 0; i < n; i++) {\n out.print(ans[i + 1] + \" \");\n }\n\n } else out.println(-1);\n }\n\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c9572b698a82a24797d499ff64818e96", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class MainB {\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 m = in.nextInt();\n\t\tint[] child = new int[n];\n\t\tin.nextLine();\n\t\tString[] array = in.nextLine().split(\" \");\n\t\tString curContent = \"\";\n\t\tif(n <= m) {\n\t\t\tfor(int i=0; i a = new ArrayList();\n for(int i=0;i c[a.get(j+1)]) {\n \t \tint temp=a.get(j);\n \t \ta.set(j, a.get(j+1));\n \t \ta.set(j+1, temp);\n \t \t}\n \t \t}\n }\n for(int i=0;i0;z--)\n {\n \tint count=0;\n for(int i=0;i=n) {\n \tbreak;\n }\n \n }\n System.out.println(z);\n }\n in.close();\n out.close();\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d67c85513028d38f9c10d77552b9f2e3", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\n\n\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Stack;\n\n\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\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 static int gcd(int a, int b)\n {\n if (a == 0)\n return b;\n return gcd(b % a, a);\n }\n\n static int findGCD(int arr[])\n {\n int result = arr[1];\n for (int i = 1; i value){\n end=mid-1;\n }else{\n return mid;\n }\n }\n return nearest;\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n static FastReader in;\n static StringBuilder out;\n\n public static void main(String[] args) {\n in=new FastReader();\n out = new StringBuilder();\n\n int n=in.nextInt(),m=in.nextInt();\n\n int a[]=new int[100];\n\n for(int i=0;i0) {\n personCount=0;\n for(int i=index;i<100;i++){\n personCount+=a[i]/eachGet;\n }\n if(personCount>=n){\n System.out.println(eachGet);\n return;\n }\n eachGet--;\n }\n\n System.out.println(0);\n\n }\n\n\n\n\n\n}\n\n/*\nprivate static void builtSegmentTree(int a[],int n){\n\n for(int i=n-1;i>0;i--){\n a[i]=a[i*2]+a[(2*i)+1];\n }\n\n }\n private static void updateSegmentTree(int a[],int n,int index,int value){\n index+=n-1;\n int change = value-a[index];\n\n while(index>0){\n a[index]+=change;\n index/=2;\n }\n }\n private static int rangeSum(int a[],int n,int l,int r){\n int sum=0;\n\n l+=n-1;r+=n-1;\n\n while(l<=r){\n if(l==r){\n sum+=a[l];\n break;\n }\n if(l%2==1) {sum+=a[l]; l++;}\n if(r%2==0) {sum+=a[r]; r--;}\n l/=2;\n r/=2;\n }\n\n return sum;\n }\n public static void main(String[] args) {\n\n in = new FastReader();\n out=new StringBuilder();\n\n int n=in.nextInt();\n int a[]=new int[2*n+1];\n\n for(int i=n;i<2*n;i++){\n a[i]=in.nextInt();\n }\n builtSegmentTree(a,n);\n\n\n //System.out.println(\"Enter the left and right index of the subarray you want to find the sum of\");\n updateSegmentTree(a,n,in.nextInt(),in.nextInt());\n System.out.println(rangeSum(a,n,in.nextInt(),in.nextInt()));\n\n\n\n\n }\n */\n\n\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Stack;\n\n\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\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 static int gcd(int a, int b)\n {\n if (a == 0)\n return b;\n return gcd(b % a, a);\n }\n\n static int findGCD(int arr[])\n {\n int result = arr[1];\n for (int i = 1; i value){\n end=mid-1;\n }else{\n return mid;\n }\n }\n return nearest;\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n static FastReader in;\n static StringBuilder out;\n\n public static void main(String[] args) {\n in=new FastReader();\n out = new StringBuilder();\n\n int n=in.nextInt(),m=in.nextInt();\n\n int a[]=new int[100];\n\n for(int i=0;i0) {\n personCount=0;\n for(int i=index;i<100;i++){\n personCount+=a[i]/eachGet;\n }\n if(personCount>=n){\n System.out.println(eachGet);\n return;\n }\n eachGet--;\n }\n\n System.out.println(0);\n\n }\n\n\n\n\n\n}\n\n/*\nprivate static void builtSegmentTree(int a[],int n){\n\n for(int i=n-1;i>0;i--){\n a[i]=a[i*2]+a[(2*i)+1];\n }\n\n }\n private static void updateSegmentTree(int a[],int n,int index,int value){\n index+=n-1;\n int change = value-a[index];\n\n while(index>0){\n a[index]+=change;\n index/=2;\n }\n }\n private static int rangeSum(int a[],int n,int l,int r){\n int sum=0;\n\n l+=n-1;r+=n-1;\n\n while(l<=r){\n if(l==r){\n sum+=a[l];\n break;\n }\n if(l%2==1) {sum+=a[l]; l++;}\n if(r%2==0) {sum+=a[r]; r--;}\n l/=2;\n r/=2;\n }\n\n return sum;\n }\n public static void main(String[] args) {\n\n in = new FastReader();\n out=new StringBuilder();\n\n int n=in.nextInt();\n int a[]=new int[2*n+1];\n\n for(int i=n;i<2*n;i++){\n a[i]=in.nextInt();\n }\n builtSegmentTree(a,n);\n\n\n //System.out.println(\"Enter the left and right index of the subarray you want to find the sum of\");\n updateSegmentTree(a,n,in.nextInt(),in.nextInt());\n System.out.println(rangeSum(a,n,in.nextInt(),in.nextInt()));\n\n\n\n\n }\n */", "lang_cluster": "Java", "compilation_error": true, "code_uid": "81f38d1ac762051aeab47fe140663c54", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main { // \"Main\" should be used for most online judges\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\n if (n > m) {\n System.out.println(0);\n }\n return;\n //get the counts of each package type\n HashMap typeCounts = new HashMap();\n\n for (int i = 0; i < m; i++) {\n int a_i = sc.nextInt();\n if (typeCounts.containsKey(a_i)) {\n typeCounts.put(a_i, typeCounts.get(a_i) + 1);\n } else {\n typeCounts.put(a_i, 1);\n }\n }\n\n int numberDays = 1;\n\n Set values = typeCounts.keySet();\n while (true) {\n int temp = n;\n for (Integer i: values) {\n temp -= i % numberDays;\n }\n if (temp > 0) {\n break;\n }\n numberDays++;\n }\n\n System.out.println(numberDays);\n\n}\n}\n\t\t\t\t\t\t \t\t\t\t \t\t \t\t\t\t \t\t \t\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "775047d52e6d6ea77981409a369b2d97", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class PlanningExpedition\n{\npublic static void main(String[] args)\n{\n // TODO Auto-generated method stub\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m =sc.nextInt();\n if(n>m)\n {\n System.out.println(0);\n return;\n }\n ArrayList type = new ArrayList();\n ArrayList number = new ArrayList();\n\n for(int x = 0; x=0;x--)\n {\n if(type.indexOf(type.get(x))!=x)\n {\n type.remove(x);\n number.remove(x);\n number.set(type.indexOf(type.get(x)),\n type.get(type.indexOf(type.get(x)))+1);\n }\n }\n int max, start,index;\n for(int x=0;xmax)\n max=number.get(i);\n index=i;\n }\n number.set(index, number.get(start));\n number.set(start, max);\n }\n if(number.size()>n)\n {\n for(int x=number.size()-1;x>=n;x++)\n {\n number.remove(x);\n }\n }\n \n int sum;\n int currentP;\n for(int x=1;x<=100;x++)\n {\n sum=0;\n for(int y=0;yn&&y!=number.size()-1)\n {\n break;\n }\n if(sum==n&&y==number.size()-1)\n {\n System.out.println(x);\n return;\n }\n System.out.println(x-1);\n return ;\n }\n }\n}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72322da163398589a510757635662d6e", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int p=sc.nextInt();\n int n=sc.nextInt();\n int s=n,f=1;\n while(n>p)\n {\n int i=2;\n while(i<=p && i<=Math.sqrt(s))\n {\n if(n%i==0)\n {\n break;\n f=0;\n }\n i++;\n }\n if(f==1)\n {\n System.out.print(n);\n break;\n }\n n--;\n }\n if(n==p)\n System.out.print(\"-1\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1ffc525cd715f478b52256d884924289", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\npublic class JavaApplication58 {\n\n private static boolean isPrime(int x)\n {\n int i;\n for(i=2;i<=Math.sqrt(x);i++)\n {\n if(x%i==0)\n {\n return false;\n }\n }\n \n return true;\n }\n \n public static void main(String[] args) {\n Scanner Sc=new Scanner(System.in);\n \n int p=Sc.nextInt();\n int y=Sc.nextInt();\n // int minn=99999999;\n int temp=-1;\n //int prime=-1;\n int k;\n \n \n Set hs=new HashSet<>();\n \n \n for (int i = 2; i <= p; i++)\n {\n \n if ((i==2||i%2)!=0 && isPrime(i))\n {\n temp=y-(y%i);\n hs.add(temp);\n }\n }\n\n \n //System.out.println(hs);\n k=y;\n while(hs.contains(k)==true && k>p)\n {\n k--;\n }\n \n if(k>p)\n {\n System.out.println(k);\n }\n else\n {\n System.out.println(-1);\n }\n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "38c40418af785a7bbed7b046b95ed758", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "package contest467;\n\npublic class Dev2B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int p = sc.nextInt();\n int y = sc.nextInt();\n boolean solutionFound = false;\n for (int i = y; i > p; i--) {\n boolean isPrime = true;\n for (int j = 2; j <=p; j++) {\n if (i % j == 0) {\n isPrime = false;\n break;\n }\n }\n if (isPrime) {\n solutionFound = true;\n System.out.println(i);\n break;\n }\n }\n if (!solutionFound) {\n System.out.println(-1);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3bb5a3cec3099fcf5a78e41d139c2963", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class VileGrasshoppers{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint p = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tsc.close();\n\n\t\t/*\n\t\t** TLE\n\t\tSet set = new HashSet<>();\n\t\tfor (int i = 2; i <= p; i++) {\n\t\t\tfor (int j = 2; j <= y / i; j++) {\n\t\t\t\tif (!set.contains(i * j)) {\n\t\t\t\t\t// System.out.println(\"got one: \" + i * j);\n\t\t\t\t\tset.add(i * j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = y; i > p; i--) {\n\t\t\tif (!set.contains(i)) {\n\t\t\t\tSystem.out.println(i);\n\t\t\t\treturn ;\n\t\t\t}\n\t\t}*/\n\n\t\tfor (int i = y; i > p; i--) {\n\t\t\tif (isValid(i)) {\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\tprivate static boolean isValid(int num, int p, int y) {\n\t\tint end = Math.min(p, Math.sqrt(y));\n\t\tfor (int i = 2; i < end; i++) {\n\t\t\tif (num % i == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "53bf43ad6a748f403215c927b26bb314", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "package semana11\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class logo {\n\tstatic int largo, n;\n\tstatic String instr;\n\tstatic int[][][][] dp = new int[2][200][500][100];\n\tstatic boolean[][][][] vis = new boolean[2][200][500][100];\n\t\n\tstatic int dfs(int dir, int cd, int pos, int cur){\n\t\tif (cur < 0) return 0;\n\t\tif (cd == largo) {\n\t\t\tif (cur > 0) return 0;\n\t\t\telse return Math.abs(pos-200);\n\t\t}\n\t\t\n\t\tif(vis[dir][cd][pos][cur]==true)\n\t\t\treturn dp[dir][cd][pos][cur];\n\t\tint ret = 0;\n\t\tint mv = (dir == 1) ? -1 : 1;\n\t\t\n\t\tif (instr.charAt(cd) == 'T')\n\t\t\tret = Math.max(ret, Math.max(dfs(1^dir, cd+1, pos, cur), dfs(dir, cd+1, pos+mv, cur-1)));\n\t\telse\n\t\t\tret = Math.max(ret, Math.max(dfs(dir, cd+1, pos+mv, cur), dfs(1^dir, cd+1, pos, cur-1)));\n\t\t\n\t\tvis[dir][cd][pos][cur] = true;\n\t\tdp[dir][cd][pos][cur] = ret;\n\t\t\n\t\treturn ret;\n\t}\n\t\n\tstatic public void main(String[] args) throws IOException {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tinstr = r.readLine();\n\t\tlargo = instr.length();\n\t\tn = Integer.parseInt(r.readLine());\n\t\t\n\t\tint ans = Integer.MIN_VALUE;\n\t\tfor (int i = n; i >= 0; i = i - 2){\n\t\t\tans = Math.max(ans, dfs(0,0,200,i));\n\t\t}\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e2495c50520357ac1cea8456c2ac2769", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Problem {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n char[] code = in.next().toCharArray();\n int m = code.length; \n int n = in.nextInt();\n int[][][] pd = new int[m+1][n+1][2];\n for(int i = 0; i <= m; i++) {\n for(int j = 0; j <=n; j++){\n pd[i][j][0] = -1<<30;\n pd[i][j][1] = -1<<30;\n }\n }\n pd[0][0][0] = 0;\n for(int i = 1; i <= m; i++) {\n for(int j = 0; j <= n; j++) {\n for(int k = 0; k <= j; k++) {\n char next = 'T';\n if(k%2 == 0 && code[i-1]=='F' || k%2 == 1 && code[i-1]=='T') next = 'F';\n if(next == 'F') {\n pd[i][j][0] = Math.max(pd[i][j][0], pd[i-1][j-k][0]+1);\n pd[i][j][1] = Math.max(pd[i][j][1], pd[i-1][j-k][1]-1);\n }else {\n pd[i][j][0] = Math.max(pd[i][j][0], pd[i-1][j-k][1]);\n pd[i][j][1] = Math.max(pd[i][j][1], pd[i-1][j-k][0]);\n \n }\n }\n }\n }\nint max = Math.max(pd[m][n][0],pd[m][n][1]);\n pd = new int[m+1][n+1][2];\n for(int i = 0; i <= m; i++) {\n for(int j = 0; j <=n; j++){\n pd[i][j][0] = 1<<30;\n pd[i][j][1] = 1<<30;\n }\n }\n pd[0][0][0] = 0;\n for(int i = 1; i <= m; i++) {\n for(int j = 0; j <= n; j++) {\n for(int k = 0; k <= j; k++) {\n char next = 'T';\n if(k%2 == 0 && code[i-1]=='F' || k%2 == 1 && code[i-1]=='T') next = 'F';\n if(next == 'F') {\n pd[i][j][0] = Math.min(pd[i][j][0], pd[i-1][j-k][0]+1);\n pd[i][j][1] = Math.min(pd[i][j][1], pd[i-1][j-k][1]-1);\n }else {\n pd[i][j][0] = Math.min(pd[i][j][0], pd[i-1][j-k][1]);\n pd[i][j][1] = Math.min(pd[i][j][1], pd[i-1][j-k][0]);\n }\n }\n }\n }\nint min = Math.min(pd[m][n][0], pd[m][n][1]);\nSystem.out.println(Math.max(max, -min);\n in.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29c670c324fe5ac00308da6857cbf333", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tpublic C () throws IOException {\n\t\tchar [] commands = sc.next().toCharArray();\n\t\tint N = sc.nextInt();\n\t\tprint(solve(commands, N));\n\t}\n\t\n\tpublic int solve (char [] C, int N) {\n\t\t\n\t\tint L = C.length;\n\t\twhile (N > 0) {\n\t\t\t// 1. All Fs\n\t\t\tString cmd = new String(C);\n\t\t\tif (cmd.indexOf('T') == -1) {\n\t\t\t\tC[0] = 'T';\n\t\t\t\t--N;\n\t\t\t}\n\t\t\t\n\t\t\t// 2. N == 1\n\t\t\telse if (N == 1) {\n\t\t\t\tint S = -1;\n\t\t\t\tfor (int i = 0; i < L; ++i) {\n\t\t\t\t\tC[i] = ch(C[i]);\n\t\t\t\t\tS = Math.max(S, eval(C));\n\t\t\t\t\tC[i] = ch(C[i]);\n\t\t\t\t}\n\t\t\t\treturn S;\n\t\t\t}\n\t\t\t\n\t\t\telse {\n\t\t\t\tint count = 0;\n\t\t\t\tfor (int i = 0; i < L; ++i) {\n\t\t\t\t\tif (C[i] == 'T')\n\t\t\t\t\t\t++count;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// 3. N >= 2, just one T\n\t\t\t\tif (count == 1) {\n\t\t\t\t\tfor (int i = 0; i < L; ++i) {\n\t\t\t\t\t\tif (C[i] == 'T')\n\t\t\t\t\t\t\tC[i] = 'F';\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\t--N;\n\t\t\t\t} else {\n\t\t\t\t\tint S = 0, x = -1, y = -1, z = -1;\n\t\t\t\t\tfor (int i = 0; i < L; ++i) {\n\t\t\t\t\t\t// Look for the best pair to change - prefer farther ones!\n\t\t\t\t\t\tfor (int j = i+1; j < L; ++j)\n\t\t\t\t\t\t\tif (C[i] == 'T' && C[j] == 'T') {\n\t\t\t\t\t\t\t\tC[i] = ch(C[i]); C[j] = ch(C[j]);\n\t\t\t\t\t\t\t\tint E = eval(C);\n\t\t\t\t\t\t\t\tif (E >= S) {\n\t\t\t\t\t\t\t\t\tS = E; x = i; y = j;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tC[i] = ch(C[i]); C[j] = ch(C[j]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Look for best single to change - prefer farther ones!\n\t\t\t\t\t\tif (C[i] == 'T') {\n\t\t\t\t\t\t\tC[i] = ch(C[i]);\n\t\t\t\t\t\t\tint E = eval(C);\n\t\t\t\t\t\t\tif (E >= S) {\n\t\t\t\t\t\t\t\tS = E; z = i;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tC[i] = ch(C[i]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (z >= 0) {\n\t\t\t\t\t\tchar [] D = new char[L];\n\t\t\t\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\t\t\t\tD[i] = C[i];\n\t\t\t\t\t\tC[x] = C[y] = D[z] = 'F';\n\t\t\t\t\t\treturn Math.max(solve(C, N-2), solve(D, N-1))\n\t\t\t\t\t} else\n\t\t\t\t\t\treturn solve(C, N-2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn eval(C);\n\t}\n\t\n\tint eval (char [] C) {\n\t\tint x = 0, d = 1;\n\t\tfor (char c : C) {\n\t\t\tif (c == 'T')\n\t\t\t\td = -d;\n\t\t\tif (c == 'F')\n\t\t\t\tx += d;\n\t\t}\n\t\treturn Math.abs(x);\n\t}\n\t\n\tchar ch (char X) {\n\t\tif (X == 'F') return 'T';\n\t\telse return 'F';\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic Scanner sc;\n\tstatic long t;\n\t\n\tstatic void print2 (Object o) {\n\t\tSystem.out.println(o);\n\t}\n\t\n\tstatic void print (Object o) {\n\t\tprint2(o);\n\t\t//print2((millis() - t) / 1000.0);\n\t\tSystem.exit(0);\n\t}\n\t\n\tstatic void run () throws IOException {\n\t\tsc = new Scanner(System.in);\n\t\tnew C();\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\trun();\n\t}\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da6d03a852922d5d73c61640bc848b33", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.io.*;\n\npublic class B {\n private static StreamTokenizer in = null;\n private static PrintWriter out = null;\n\n static int nextInt() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\n\n static long nextLong() throws IOException {\n in.nextToken();\n return (long) in.nval;\n }\n\n static double nextDouble() throws IOException {\n in.nextToken();\n return (double) in.nval;\n }\n\n static String nextString() throws IOException {\n in.nextToken();\n return in.sval;\n }\n\n public static void main(String[] args) throws IOException {\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n // Here is the solution:\n String str = nextString();\n int n = nextInt();\n out.println(new A().solve(str, n));\n out.flush();\n }\n \n String string;\n private int doit(int p, int c, boolean d) {\n if (c < 0)\n return -1;\n if (p == 0) {\n if (c % 2 == 0)\n return 0;\n else\n return -1;\n }\n \n if (visit[p][c][d?0:1])\n return dp[p][c][d?0:1];\n \n int res = -1;\n if (string.charAt(p-1) == 'F') {\n res = Math.max(doit(p - 1, c, d) + (d ? 1 : -1), doit(p - 1, c - 1, !d));\n } else {\n res = Math.max(doit(p - 1, c - 1, d) + (d ? 1 : - 1), doit(p - 1, c, !d));\n }\n\n visit[p][c][(d?0:1)] = true;\n return dp[p][c][d?0:1] = res;\n }\n\n boolean[][][] visit;\n int[][][] dp;\n public int solve(String str, int n) {\n this.string = str;\n int len = str.length();\n visit = new boolean[len+1][n+1][2];\n dp = new int[len+1][n+1][2];\n return Math.max(doit(len, n, true), doit(len, n, false));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bb4310c975ada664f668535d021b640b", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "//package com.codeforces.Practise;\r\n\r\nimport java.io.*;\r\n\r\npublic class RubikCubeColoring {\r\n //when you get WA and you are okk with your solution then try out some edge cases means on which test case your code fails\r\n // because sometimes your writing code mistake\r\n // Consistency will always give you great Result\r\n // Don't Confuse Always make things simple\r\n // Don't afraid after seeing the problem instead dive deep into it to get better understanding\r\n //Experience is the name of the game\r\n // You won't fail until you stop trying.......\r\n // you can solve one problem by many approaches. when you stuck you are going to learn something new okk\r\n // Everything is easy. you feel its hard because of you don't know, and you not understand it very well.\r\n //// How to Improve Your problem-solving skill ??( By practise ). ***simple\r\n /// ==>> Solve problems slightly above of your level (to know some logic and how to approach cp problems)\r\n // Otherwise You will stay as it is okk. Learn from other code as well.\r\n /////////////////////////////////////////////////////////////////////////\r\n /// How to Solve Problem in CP ? (you need to come up with brainstorm(Learning)) ( if you feel problem is hard then your approach is wrong )\r\n // ==>> Step01 :- Understanding problem statement clearly. Then Only Move Forward (Because Everything is mentioned in problem statement).\r\n // Step02 :- Think a lot about Solution. if you are confident that your solution might be correct Then only Move Forward\r\n // Step03 :- First think of brute force then move to optimal approach\r\n // Step04 :- Finally Code ( there is no any sense to code. if you not follow about steps okk)\r\n ///////////////////////////////////////////////////////////////////////////\r\n /* Iterative Function to calculate (x^y) in O(log y) */\r\n static long getpower(long x, long y, long mod) {\r\n long res = 1L; // Initialize result\r\n x = x % mod; // Update x if it is more than or\r\n // equal to p\r\n if (x == 0)\r\n return 0; // In case x is divisible by p;\r\n while (y > 0) {\r\n // If y is odd, multiply x with result\r\n if ((y & 1) != 0)\r\n res = (res * x) % mod;\r\n // y must be even now\r\n y = y >> 1; // y = y/2\r\n x = (x * x) % mod;\r\n }\r\n return res;\r\n }\r\n public static void main(String[] args) throws IOException {\r\n Reader scan = new Reader();\r\n BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\r\n int t = scan.nextInt();\r\n long mod= (long) (1e9+7);\r\n while (t-- > 0) {\r\n long k=scan.nextInt();\r\n long power=getpower(2L,k,mod)-2L;\r\n long ans=(6L*(getpower(4L,power,mod)))%mod;\r\n bw.write(ans+\"\");\r\n bw.newLine();\r\n bw.flush();\r\n }\r\n }\r\n //FAST READER\r\n static class Reader {\r\n public int BS = 1<<16;\r\n public char NC = (char)0;\r\n byte[] buf = new byte[BS];\r\n int bId = 0, size = 0;\r\n char c = NC;\r\n double num = 1;\r\n BufferedInputStream in;\r\n\r\n public Reader() {\r\n in = new BufferedInputStream(System.in, BS);\r\n }\r\n\r\n public Reader(String s) throws FileNotFoundException {\r\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\r\n }\r\n\r\n public char nextChar(){\r\n while(bId==size) {\r\n try {\r\n size = in.read(buf);\r\n }catch(Exception e) {\r\n return NC;\r\n }\r\n if(size==-1)return NC;\r\n bId=0;\r\n }\r\n return (char)buf[bId++];\r\n }\r\n\r\n public int nextInt() {\r\n return (int)nextLong();\r\n }\r\n\r\n public long nextLong() {\r\n num=1;\r\n boolean neg = false;\r\n if(c==NC)c=nextChar();\r\n for(;(c<'0' || c>'9'); c = nextChar()) {\r\n if(c=='-')neg=true;\r\n }\r\n long res = 0;\r\n for(; c>='0' && c <='9'; c=nextChar()) {\r\n res = (res<<3)+(res<<1)+c-'0';\r\n num*=10;\r\n }\r\n return neg?-res:res;\r\n }\r\n\r\n public double nextDouble() {\r\n double cur = nextLong();\r\n return c!='.' ? cur:cur+(cur < 0 ? -1*nextLong()/num : nextLong()/num);\r\n }\r\n\r\n public String next() {\r\n StringBuilder res = new StringBuilder();\r\n while(c<=32)c=nextChar();\r\n while(c>32) {\r\n res.append(c);\r\n c=nextChar();\r\n }\r\n return res.toString();\r\n }\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "265f2ca5a2a3eebd9bcabe2227f2da11", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.ArrayList;\r\nimport java.util.Collections;\r\nimport java.util.Comparator;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class RubiksCubeColoringHard {\r\n\r\n\r\n static int mod = 1000000007;\r\n\r\n public static void main(String[] args) throws IOException {\r\n\r\n FastReader reader = new FastReader();\r\n FastWriter writer = new FastWriter();\r\n int K = reader.readSingleInt();\r\n int N = reader.readSingleInt();\r\n\r\n ArrayList fixed = new ArrayList<>();\r\n //1 r, 2 = g, 3 = b, 4 = o, 5 = w, 6 = y\r\n for(int i = 0; i() {\r\n @Override\r\n public int compare(long[] a, long[] b) {\r\n if(a[0] <= b[0]){\r\n return -1;\r\n }\r\n return 1;\r\n }\r\n });\r\n\r\n\r\n //2^(k-1)\r\n\r\n //6 * 4^((2^(k-1))-1))\r\n\r\n long target = 1;\r\n for(int i = 0; i mod){\r\n psum %= mod;\r\n }\r\n power += power;\r\n\r\n if(exponent + power <= target){\r\n exponent = exponent + power;\r\n value = value * psum;\r\n if(value > mod){\r\n value %= mod;\r\n }\r\n } else {\r\n power = 1;\r\n psum = 4;\r\n }\r\n }\r\n\r\n value *= 6*value;\r\n if(value > mod){\r\n value %= mod;\r\n }\r\n\r\n writer.writeSingleLong(value);\r\n\r\n }\r\n\r\n\r\n public static void mergeSort(int[] a, int n) {\r\n if (n < 2) {\r\n return;\r\n }\r\n int mid = n / 2;\r\n int[] l = new int[mid];\r\n int[] r = new int[n - mid];\r\n\r\n for (int i = 0; i < mid; i++) {\r\n l[i] = a[i];\r\n }\r\n for (int i = mid; i < n; i++) {\r\n r[i - mid] = a[i];\r\n }\r\n mergeSort(l, mid);\r\n mergeSort(r, n - mid);\r\n\r\n merge(a, l, r, mid, n - mid);\r\n }\r\n\r\n\r\n public static void merge(int[] a, int[] l, int[] r, int left, int right) {\r\n\r\n int i = 0, j = 0, k = 0;\r\n while (i < left && j < right) {\r\n if (l[i] <= r[j]) {\r\n a[k++] = l[i++];\r\n }\r\n else {\r\n a[k++] = r[j++];\r\n }\r\n }\r\n while (i < left) {\r\n a[k++] = l[i++];\r\n }\r\n while (j < right) {\r\n a[k++] = r[j++];\r\n }\r\n }\r\n\r\n\r\n public static class FastReader {\r\n\r\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer tokenizer;\r\n\r\n\r\n public int readSingleInt() throws IOException {\r\n return Integer.parseInt(reader.readLine());\r\n }\r\n\r\n public int[] readIntArray(int numInts) throws IOException {\r\n int[] nums = new int[numInts];\r\n tokenizer = new StringTokenizer(reader.readLine());\r\n for(int i = 0; i nums) throws IOException {\r\n for(int i = 0; i x.v-y.v);\r\n\t\tint nodes=(int)Math.pow(2,k)-2;\r\n\r\n\t\tint mod=1000000007;\r\n\t\tlong ans=4;\r\n\t\tint a[]=new int[62];\r\n\t\t// a[0]=1;\r\n\r\n\t\tfor(int i=-1;++i<62;)\r\n\t\t{\r\n\t\t\ta[i]=(int)ans;\r\n\t\t\tans*=ans;\r\n\t\t\tans%=mod;\r\n\t\t}\r\n\r\n\t\tif(d[0].v==1)\r\n\t\t\tnodes-=n-1;\r\n\t\telse\r\n\t\t\tnodes-=n;\r\n\r\n\t\tans=1L;\r\n\t\tint bit=0;\r\n\t\twhile(nodes!=0)\r\n\t\t{\r\n\t\t\tif(nodes%2==1)\r\n\t\t\t{\r\n\t\t\t\tans*=a[bit];\r\n\t\t\t\tans%=mod;\r\n\t\t\t}\r\n\t\t\tnodes/=2;\r\n\t\t\tbit++;\r\n\t\t}\r\n\r\n\t\tans*=6;\r\n\t\tans%=mod;\r\n\t\tSystem.out.println(ans);\r\n\r\n\t}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\tpublic int gcd(int a, int b)\r\n\t{\r\n\t\tif(a==0)\r\n\t\t\treturn b;\r\n\t\telse\r\n\t\t return gcd(b%a,a);\r\n\t}\r\n\r\n\tint[] nai(int n) { int a[]=new int[n]; for(int i=-1;++i= 1000000000) return 10;\r\n\t\tif (l >= 100000000) return 9;\r\n\t\tif (l >= 10000000) return 8;\r\n\t\tif (l >= 1000000) return 7;\r\n\t\tif (l >= 100000) return 6;\r\n\t\tif (l >= 10000) return 5;\r\n\t\tif (l >= 1000) return 4;\r\n\t\tif (l >= 100) return 3;\r\n\t\tif (l >= 10) return 2;\r\n\t\treturn 1;\r\n\t}\r\n\tint countDigits(long l) {\r\n\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\tif (l >= 100000000000000000L) return 18;\r\n\t\tif (l >= 10000000000000000L) return 17;\r\n\t\tif (l >= 1000000000000000L) return 16;\r\n\t\tif (l >= 100000000000000L) return 15;\r\n\t\tif (l >= 10000000000000L) return 14;\r\n\t\tif (l >= 1000000000000L) return 13;\r\n\t\tif (l >= 100000000000L) return 12;\r\n\t\tif (l >= 10000000000L) return 11;\r\n\t\tif (l >= 1000000000L) return 10;\r\n\t\tif (l >= 100000000L) return 9;\r\n\t\tif (l >= 10000000L) return 8;\r\n\t\tif (l >= 1000000L) return 7;\r\n\t\tif (l >= 100000L) return 6;\r\n\t\tif (l >= 10000L) return 5;\r\n\t\tif (l >= 1000L) return 4;\r\n\t\tif (l >= 100L) return 3;\r\n\t\tif (l >= 10L) return 2;\r\n\t\treturn 1;\r\n\t}\r\n\r\n\tpublic static class data\r\n\t{\r\n\t\tint v;\r\n\t\tchar c;\r\n\r\n\t\tpublic data(int v, char c)\r\n\t\t{\r\n\t\t\tthis.v=v;\r\n\t\t\tthis.c=c;\r\n\t\t}\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ae77dd4cc6cb001c97f935ff4ad50a4f", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "// Generated by Code Flattener.\r\n// https://plugins.jetbrains.com/plugin/9979-idea-code-flattener\r\n\r\nimport java.io.*;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class ASolution extends Solution {\r\n @Override\r\n protected boolean isMultiTest() {\r\n return false;\r\n }\r\n\r\n public void solve() {\r\n int n = in.nextInt();\r\n ModInt MOD_16 = new ModInt(16);\r\n ModInt ans = ModInt.ONE;\r\n for (int i = 2; i <= n; i++) {\r\n ans = MOD_16.multiply(ans).multiply(ans);\r\n }\r\n out.println(new ModInt(6).multiply(ans).intValue());\r\n }\r\n\r\n private abstract static class Solution {\r\n public MyScanner in;\r\n public MyWriter out;\r\n\r\n public abstract void solve();\r\n\r\n protected boolean isMultiTest() {\r\n return true;\r\n }\r\n }\r\n\r\n private static class ModInt {\r\n static int MOD = 1000000007;\r\n public static final ModInt ONE = new ModInt(1);\r\n private final int value;\r\n\r\n public ModInt(int value) {\r\n if (value < 0) {\r\n throw new IllegalArgumentException();\r\n }\r\n this.value = value;\r\n }\r\n\r\n public ModInt multiply(ModInt other) {\r\n return new ModInt((int) (((long) this.value * other.value) % MOD));\r\n }\r\n\r\n public int intValue() {\r\n return value;\r\n }\r\n }\r\n\r\n private static class MyScanner {\r\n private final BufferedReader br;\r\n private StringTokenizer st;\r\n\r\n public String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n st = new StringTokenizer(nextLine());\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n public int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public String nextLine() {\r\n try {\r\n String line = br.readLine();\r\n if (line == null) {\r\n throw new RuntimeException(\"empty line\");\r\n }\r\n st = null;\r\n return line;\r\n } catch (IOException e) {\r\n throw new RuntimeException(e);\r\n }\r\n }\r\n }\r\n\r\n private static class MyWriter extends PrintWriter {\r\n public MyWriter(Writer writer) {\r\n super(writer);\r\n }\r\n\r\n public MyWriter(OutputStream out) {\r\n super(out);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "446d9dd44e3abae6ac4ed250d29ecdc2", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Test {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\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\n\tstatic 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\tpublic static int gcd(int x, int y){\n\t\tif (y == 0) return x; else return gcd(y, x % y);\n\t}\n\t static class R implements Comparable{\n\t int x, y;\n\t public R(int x, int y) {\n\t this.x = x;\n\t this.y = y;\n\t }\n\t public int compareTo(R o) {\n \t\treturn x-o.x; //Increasing order(Which is usually required)\n \t\t}\n\t } \n\n\tpublic static void main(String[] args) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\ttokenizer = null;\n\t\twriter = new PrintWriter(System.out);\n\t\tsolve();\n\t\treader.close();\n\t\twriter.close();\n\t}\n\t\n\tprivate static void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a=new int[n];\n\t\tfor(int i=0;ii;j--)\n\t\t { \n\t\t \n\t\t int x=a[i]+a[j];\n\t\t if(x==k)\n\t\t {\n\t\t count++;\n\t\t break;\n\t\t }\n\t\t \n\t\t }\n\t\t}\n\t\tSystem.out.println(+count);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca15f7f2ce072a9dfd93560a4d05aa0e", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Pair\n{\npublic static void main(String args[])\n{\n\tlong n,s;\n\tScanner in=new Scanner(System.in);\n\tlong count=0;\n\tn=in.nextLong();\n\ts=in.nextLong();\n\tfor(long i=1;i<=n-1;i++)\n\t{\n\t\tfor(long j=i+1;j<=n;j++)\n\t\t{\n\t\t\tif(s==(i+j))\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t}\n\tSystem.out.println(count);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "12ec86ef02015cffb1acd27ee4a1d39d", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class codeforces{\n\tpublic static void main(String[] args){\n\t\tScanner s=new Scanner(System.in);\n\t\tlong n=s.nextLong();\n\t\tlong k=s.nextLong();\n\t\tif(n==1||n+(n-1)= 2; p--) {\ncount++;\n int p2 = p * p;\n int fk = (a / p2 != 0) ? (a / p2) : 1;\n int tk = MAX_VALUE / p2;\n for (int k = fk; k <= tk; k++) {\ncount++;\n int v = p2 * k;\n if (v >= a) {\n if (vi[v] == -1) {\n vi[v] = vpai;\n vpa[vpai++] = ((long)v << SHIFT) | p;\n } else {\n vpa[vi[v]] = ((long)v << SHIFT) | p;\n }\n }\n }\n }\n\n//System.out.println(\"size = \" + al.size());\n//if (al.size() < 100) System.out.println(al);\n/*\n for (int i = 0; i < vpai; i++) {\n System.out.print(\"[\" + (vpa[i] >> SHIFT) + \", \" + (vpa[i] & AND) + \"] \");\n }\n*/\n Arrays.sort(vpa, 0, vpai);\nlong finish = new Date().getTime();\n//for (int i = 0; i < vpai; i++) System.out.print(\"[\" + (vpa[i] >> SHIFT) + \", \" + (vpa[i] & AND) + \"] \");\nSystem.out.println();\nSystem.out.println(\"time = \" + (finish - start));\nSystem.out.println(\"count = \" + count);\nSystem.out.println(\"vpai = \" + vpai);\n// println(total);\n }\n\n public static void main(String... args) throws Exception {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedOutputStream(System.out));\n new P172D().run();\n br.close();\n pw.close();\n }\n\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { println(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(\"\"); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "edb63c19f8a9692036af1b9e4437d809", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class Main {\n static class Assert {\n static void check(boolean e) {\n if (!e) {\n throw new Error();\n }\n }\n }\n\n class Scanner {\n\n StreamTokenizer in;\n\n Scanner(InputStream is) {\n in = new StreamTokenizer(new InputStreamReader(is));\n in.resetSyntax();\n in.whitespaceChars(0, 32);\n in.wordChars(33, 255);\n }\n\n String next() {\n try {\n in.nextToken();\n Assert.check(in.ttype == in.TT_WORD);\n return in.sval;\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n Scanner in;\n PrintWriter out;\n\n void run() {\n in = new Scanner(System.in);\n out = new PrintWriter(System.out);\n try {\n solve();\n } finally {\n out.close();\n }\n }\n\n void fillPrime(int n) {\n boolean[] boolPrime = new boolean[n + 1];\n ArrayList a[] = new ArrayList[n + 1];\n for (int i = 0; i <= n; i++) {\n a[i] = new ArrayList();\n }\n\n Arrays.fill(boolPrime, true);\n for (int i = 2; i <= n; i++) {\n if (boolPrime[i]) {\n a[i].add(i);\n for (int j = 2 * i; j <= n; j += i) {\n a[j].add(i);\n boolPrime[j] = false;\n }\n }\n }\n }\n\n void solve() {\n fillPrime(10000000);\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f442408f52eb393236648296039e1366", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class P172D {\n\n final int MAX_VALUE = 10_000_000;\n final int MAX_P = (int)Math.sqrt(MAX_VALUE);\n/*\n class Pair implements Comparable {\n public int p, k;\n private long val;\n\n Pair(int k, int p) {\n this.p = p;\n this.k = k;\n val = p * p * k;\n }\n\n @Override\n public int compareTo(Object o) {\n return (val - r)o).(\n }\n\n @Override\n public String toString() {\n return (\"<\" + k + \", \" + p + \">\");\n }\n }\n*/\n\n @SuppressWarnings(\"unchecked\")\n public void run() throws Exception {\n int a = nextInt();\n int n = nextInt();\n long total = 0;\n\nlong s = new Date().getTime();\n HashMap hm = new HashMap();\n for (int p = 2; p <= MAX_P; p++) {\n int p2 = p * p;\n int kf = MAX_VALUE / p2;\n for (int k = kf; k >= 1; k--) {\n hm.put(k * p2, p);\n }\n }\n\n System.out.println(hm.size());\n// System.out.println(hm);\n System.out.println((new Date().getTime() - s));\n\n// println(total);\n }\n\n public static void main(String... args) throws Exception {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedOutputStream(System.out));\n new P172D().run();\n br.close();\n pw.close();\n }\n\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { println(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(\"\"); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "536bda34e986426e96092690f0c4e7bb", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.PrintStream;\nimport java.util.*;\n\n/**\n * @author Roman Elizarov\n */\npublic class Round_103_D {\n\tpublic static void main(String[] args) {\n\t\tnew Round_103_D().go();\n\t}\n\n\tprivate final List> adj = new ArrayList>();\n\n\tint[] dist;\n\tint[] q;\n\tint[] p;\n\tint qs;\n\n\tprivate void go() {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintStream out = System.out;\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint s = in.nextInt() - 1;\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tadj.add(new ArrayList());\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint v = in.nextInt() - 1;\n\t\t\tint u = in.nextInt() - 1;\n\t\t\tint w = in.nextInt();\n\t\t\tadd(v, u, w);\n\t\t\tadd(u, v, w);\n\t\t}\n\t\tint l = in.nextInt();\n\t\tdist = new int[n];\n\t\tArrays.fill(dist, Integer.MAX_VALUE);\n\t\tdist[s] = 0;\n\t\tq = new int[n];\n\t\tp = new int[n];\n\t\tqs = 0;\n\t\tenqueue(s);\n\t\twhile (qs > 0) {\n\t\t\tint v = remove();\n\t\t\tint dv = dist[v];\n\t\t\tfor (Road road : adj.get(v)) {\n\t\t\t\tint u = road.u;\n\t\t\t\tint du = dist[u];\n\t\t\t\tif (dv + road.w < du) {\n\t\t\t\t\tif (du == Integer.MAX_VALUE)\n\t\t\t\t\t\tenqueue(u);\n\t\t\t\t\tdist[u] = dv + road.w;\n\t\t\t\t\tsiftDown(p[u]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint result1 = 0;\n\t\tint result2 = 0;\n\t\tfor (int v = 0; v < n; v++) {\n\t\t\tint dv = dist[v];\n\t\t\tif (dv == l)\n\t\t\t\tresult1++;\n\t\t\telse if (dv < l) {\n\t\t\t\tfor (Road road : adj.get(v)) {\n\t\t\t\t\tint u = road.u;\n\t\t\t\t\tint du = dist[u];\n\t\t\t\t\tif (dv + road.w > l) {\n\t\t\t\t\t\tint d = l - dv;\n\t\t\t\t\t\tint alt = road.w - d + du;\n\t\t\t\t\t\tif (alt == l)\n\t\t\t\t\t\t\tresult2++;\n\t\t\t\t\t\telse if (alt > l)\n\t\t\t\t\t\t\tresult1++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(result1 + result2 / 2);\n\t}\n\n\tprivate int remove() {\n\t\tint v = q[0];\n\t\tqs--;\n\t\tif (qs > 0) {\n\t\t\tswap(0, qs);\n\t\t\tsiftUp(0);\n\t\t}\n\t\treturn v;\n\t}\n\n\tprivate void swap(int i, int j) {\n\t\tint vi = q[i];\n\t\tint vj = q[j];\n\t\tq[i] = vj;\n\t\tp[vj] = i;\n\t\tq[j] = vi;\n\t\tp[vi] = j;\n\t}\n\n\tprivate void siftUp(int i) {\n\t\twhile (true) {\n\t\t\tint j = i * 2 + 1;\n\t\t\tint k = i * 2 + 2;\n\t\t\tif (k < qs && dist[p[k]] < dist[p[j]])\n\t\t\t\tj = k;\n\t\t\tif (j < qs && dist[p[j]] < dist[p[i]]) {\n\t\t\t\tswap(i, j);\n\t\t\t\ti = j;\n\t\t\t} else\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate void siftDown(int i) {\n\t\twhile (i > 0) {\n\t\t\tint j = (i - 1) / 2;\n\t\t\tif (dist[p[i]] < dist[p[j]]) {\n\t\t\t\tswap(i, j);\n\t\t\t\ti = j;\n\t\t\t} else\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate void enqueue(int v) {\n\t\tq[qs] = v;\n\t\tp[v] = qs;\n\t\tqs++;\n\t}\n\n\tprivate void add(int v, int u, int w) {\n\t\tadj.get(v).add(new Road(u, w));\n\t}\n\n\tprivate static class Road {\n\t\tfinal int u;\n\t\tfinal int w;\n\n\t\tprivate Road(int u, int w) {\n\t\t\tthis.u = u;\n\t\t\tthis.w = w;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16479c795e28e46717c6d2983ed3447b", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\n/**\n * Created by fengp on 10/10/17.\n */\npublic class CF869B {\n public static int solve(long a, long b){\n if (b-a>=5)return 0;\n int ans=1;\n for (long c=a+1;c<=b;++c){\n ans*=(c%10);\n }\n return ans%10 ;\n }\n\n public static void main(String[] args) {\n\n InputStream input = System.in;\n PrintStream output = System.out;\n if (args.length == 2) {\n try {\n input = CF867A.class.getClassLoader().getResourceAsStream(args[0]);\n output = new PrintStream(args[1]);\n } catch (IOException e) {\n e.printStackTrace();\n return;\n }\n }\n Scanner in = new Scanner(input);\n while (in.hasNextLong()) {\n long a;\n a = in.nextLong();\n long b;\n b = in.nextLong();\n output.println(String.format(\"%d\", solve(a,b)));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ef293f59c1bf848f8f2a5768a8abf73", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class HelloWorld{\n\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 \n System.out.println((b*(b-1))%10);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a181d4ba21b5f7a24e5ccc08a9d6dc28", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class Immorality{\npublic static void main(String args[]){\n\nScanner sc = new Scanner(System.in);\n\t\tlong a;\n\t\tlong b;\n\t\tlong i;\n\t\tlong d;\n\t\tlong s=1;\n\t\ta = sc.nextLong();\n\t\tb = sc.nextLong();\n\t\tfor(i=a;i<=b;i++){\n\t\t\td=i/10;\n\t\t\ts*=d;\n\t\t\tif(s==0)\n\t\t\t\tbreak;\n\t\t}\n\t\tSystem.out.println(s%10);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "84b7a579a1385c7f687a471b91f9acb0", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class a\n{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n long a,b;\n a= sc.nectInt();\n b= sc.nextInt();\n int c=1;\n \n if(b-a>5)\n {\n System.out.println(0);\n return;\n }\n else\n {\n for(int i=a+1;i<=b;i++)\n {\n c = c*i;\n c = c%10;\n }\n System.out.println(c);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4dda5962f13bd8465ce380da49241cfe", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "import java.io.DataInputStream; \nimport java.io.FileInputStream; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n\npublic class JavaApplication9 { \n \n \n//*************************************************************************************** \n static class Reader \n { \n final private int BUFFER_SIZE = 1 << 16; \n private DataInputStream din; \n private byte[] buffer; \n private int bufferPointer, bytesRead; \n \n public Reader() \n { \n din = new DataInputStream(System.in); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public Reader(String file_name) throws IOException \n { \n din = new DataInputStream(new FileInputStream(file_name)); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public String readLine() throws IOException \n { \n byte[] buf = new byte[64]; // line length \n int cnt = 0, c; \n while ((c = read()) != -1) \n { \n if (c == '\\n') \n break; \n buf[cnt++] = (byte) c; \n } \n return new String(buf, 0, cnt); \n } \n \n public int nextInt() throws IOException \n { \n int ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do\n { \n ret = ret * 10 + c - '0'; \n } while ((c = read()) >= '0' && c <= '9'); \n \n if (neg) \n return -ret; \n return ret; \n } \n \n public long nextLong() throws IOException \n { \n long ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n if (neg) \n return -ret; \n return ret; \n } \n \n public double nextDouble() throws IOException \n { \n double ret = 0, div = 1; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n \n if (c == '.') \n { \n while ((c = read()) >= '0' && c <= '9') \n { \n ret += (c - '0') / (div *= 10); \n } \n } \n \n if (neg) \n return -ret; \n return ret; \n } \n \n private void fillBuffer() throws IOException \n { \n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); \n if (bytesRead == -1) \n buffer[0] = -1; \n } \n \n private byte read() throws IOException \n { \n if (bufferPointer == bytesRead) \n fillBuffer(); \n return buffer[bufferPointer++]; \n } \n \n public void close() throws IOException \n { \n if (din == null) \n return; \n din.close(); \n } \n }\n//**************************************************************************************** \n/*static boolean isp(long n)\n{\n\n if(n==3||n==2)\n return true;\n if(n%2==0||n%3==0||n==1)\n return false;\n for(int i=5;i*i<=n;i=i+6)\n {\n if(n%i==0||n%(i+2)==0)\n return false;\n }\n return true;\n}*/\n//******************************************************** \n /* static int factorial(int n) \n { \n if (n == 0) \n return 1; \n \n return n*factorial(n-1); \n } */ \n /* public int BinaryToDecimal(int binaryNumber){\n \n int decimal = 0;\n int p = 0;\n while(true){\n if(binaryNumber == 0){\n break;\n } else {\n int temp = binaryNumber%10;\n decimal += temp*Math.pow(2, p);\n binaryNumber = binaryNumber/10;\n p++;\n }\n }\n return decimal;\n }*/\n \n/*-********************** Start *********************************-*/\n \n \n \n \npublic static void main(String[] args) throws IOException{\n//----------------------- Input ---------------------------------------//\n\nReader st=new Reader();\nScanner in=new Scanner(System.in);\n//HashMap dp = new HashMap();\nint n=in.nextInt();\nboolean f=true;\n\nint j=in.nextByte();\nint p=in.nextByte();\n\nVector v1=new Vector(j);\n\nint o;\nfor(int i=0;i aApples = new ArrayList();\n\t\tArrayList bApples = new ArrayList();\n\t\tst = new StringTokenizer(br.readLine());\n\t\tfor(int i = 0; i < a; i++) {\n\t\t\taApples.add(Integer.parseInt(st.nextToken()));\n\t\t\tSystem.out.print(1+\" \");\n\t\t}\n\t\tst = new StringTokenizer(br.readLine());\n\t\tfor(int i = 0; i < b; i++) {\n\t\t\tbApples.add(Integer.parseInt(st.nextToken()));\n\t\t}\n\t\tbApples.removeAll(aApples);\n\t\tfor(int i = 0; i < bApples.size(); i++) {\n\t\t\tSystem.out.print(2+\" \");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a841657fd2199bb59b2c51e90db9f919", "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93", "difficulty": 800} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\npublic class Ds_gfg{\n public static void main(String []args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int a=sc.nextInt();\n int b=sc.nextInt();\n int []m=new int[n];\n \n for(int i=0;i= 0 && palin(i-k+1,i)) || ( i - k >= 0 && palin(i-k,i)) ;\n\t}\n\tprivate boolean palin(int van, int tot) {\n\t\t\n\t\tint l = tot - van + 1 ;\n\n\t\tif( deb )\n\t\t\tp(voor.rsq(van+1,van+l/2) , achter.rsq(van+l/2+1,tot+1) ) ;\n\t\tif( l % 2 == 0 )\n\t\t\treturn (voor.rsq(van+1,van+l/2) * macht[n-1-van] ) % MOD == (achter.rsq(van+l/2+1,tot+1) * macht[tot] ) % MOD ;\n\t\telse\n\t\t\treturn ( voor.rsq(van+1,van+l/2) * macht[n-1-van] ) % MOD == (achter.rsq(van+l/2+2,tot+1)* macht[tot] ) % MOD ;\n\t\t\n\t}\n\n\tFenwick voor ;\n\tFenwick achter ;\n\t\n\tclass Fenwick{\n\t\t\n\t\tpublic Fenwick( int n ){\n\t\t\tfenwick = new long[n+1] ;\n\t\t\tthis.n = n ;\n\t\t}\n\t\tint n ; \n\t\tlong[] fenwick ; // aanmaken met n + 1 !!!!!!\n\t\t\n\t\tlong rsq( int k ){\n\t\t\tlong som = 0 ;\n\t\t\t\n\t\t\twhile( k > 0 ){\n\t\t\t\tsom = (som+fenwick[k])%A.MOD ;\n\t\t\t\tk -= (k & (-k)) ;\n\t\t\t}\n\t\t\t\n\t\t\treturn som ;\n\t\t\t\n\t\t}\n\t\t\n\t\tlong rsq( int l, int h){\n\t\t\tif( l > h )\n\t\t\t\treturn 0 ;\n\t\t\tif( l == 0 )\n\t\t\t\treturn rsq( h ) ;\n\t\t\treturn (MOD+(rsq( h ) - rsq( l-1 )) % MOD) % MOD ;\n\t\t}\n\t\t\n\t\tvoid adjust( int k, long v){\n\t\t\twhile( k < fenwick.length ){\n\t\t\t\tfenwick[k] += v ;\n\t\t\t\tk += (k & (-k)) ;\n\t\t\t}\n\t\t}\n\n\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() throws IOException{\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 ) throws IOException{\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() throws IOException{\t\t\n\t\tString[] ss = buf.readLine().split(\" \") ;\n\t\tbufInts = new int[ss.length] ;\n\t\tfor( int i = 0 ; i < ss.length ; i++ ){\n\t\t\tbufInts[i] = Integer.parseInt(ss[i]) ;\n\t\t}\n\t\tbufI = 0 ;\n\t}\n\t\n\tstatic int bufL = 0 ;\n\tstatic long[] bufLongs = new long[0] ;\n\t\n\tstatic long Long() throws IOException{\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 ) throws IOException{\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() throws IOException{\t\t\n\t\tString[] ss = buf.readLine().split(\" \") ;\n\t\tbufLongs = new long[ss.length] ;\n\t\tfor( int i = 0 ; i < ss.length ; i++ ){\n\t\t\tbufLongs[i] = Long.parseLong(ss[i]) ;\n\t\t}\n\t\tbufL = 0 ;\n\t}\n\t\n\tstatic int[] toArray( ArrayList 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "712de3f8fd00fb4dc4853ae841d834a6", "src_uid": "959a274a06219f4a8c061cd6f5b17160", "difficulty": 2800} {"lang": "Java 6", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n static final long BASE = 31371;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int d1 = in.nextInt();\n int d2 = d1 + 1;\n String s = in.next();\n int n = s.length();\n StringBuilder res = new StringBuilder();\n res.append(s);\n long[] hash = new long[n + 1];\n long[] hashRev = new long[n + 1];\n long[] basePow = new long[n + 1];\n basePow[0] = 1;\n for (int i = 0; i < n; ++i)\n basePow[i + 1] = basePow[i] * BASE;\n boolean bigger = false;\n int i = 0;\n while (i < n) {\n char min = res.charAt(i);\n int oldi = i;\n for (char ch = min; ch <= 'z'; ++ch) {\n if (!bigger && ch > min) {\n bigger = true;\n for (int ii = i + 1; ii < n; ++ii)\n res.setCharAt(ii, 'a');\n }\n res.setCharAt(i, ch);\n hash[i + 1] = hash[i] * BASE + ch;\n hashRev[i + 1] = hashRev[i] + ch * basePow[i];\n boolean ok = true;\n if (i + 1 >= d1) {\n if ((hash[i + 1] - hash[i + 1 - d1] * basePow[d1]) * basePow[i + 1 - d1] == (hashRev[i + 1] - hashRev[i + 1 - d1])) {\n ok = false;\n }\n }\n if (i + 1 >= d2) {\n if ((hash[i + 1] - hash[i + 1 - d2] * basePow[d2]) * basePow[i + 1 - d2] == (hashRev[i + 1] - hashRev[i + 1 - d2])) {\n ok = false;\n }\n }\n if (ok && (bigger || i + 1 < n)) {\n ++i;\n break;\n }\n }\n if (i == oldi) {\n if (!bigger) {\n for (int ii = i; ii < n; ++ii) res.setCharAt(ii, 'a');\n }\n res.setCharAt(i, 'a');\n --i;\n while (i >= 0 && res.charAt(i) == 'z') {\n res.setCharAt(i, 'a');\n --i;\n }\n if (i < 0) {\n out.println(\"Impossible\");\n return;\n }\n res.setCharAt(i, (char) (res.charAt(i) + 1));\n bigger = true;\n }\n }\n out.println(res.toString());\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "74f121fdc157d08d0d60b3cef4ef5781", "src_uid": "959a274a06219f4a8c061cd6f5b17160", "difficulty": 2800} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tBufferedReader questionreader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tPrintWriter answerwriter = new PrintWriter(System.out);\n\n\t\t\tint D = Integer.parseInt(questionreader.readLine());\n\t\t\tchar[] S = questionreader.readLine().toCharArray();\n\t\t\t\n\t\t\tanswerwriter.println(analyze(D, S));\n\t\t\t\n\t\t\tanswerwriter.close();\n\t\t\tquestionreader.close();\n\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t\treturn;\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\tpublic static int[] l = null;\n\tpublic static int[] n = null;\n\tpublic static int[] o = null;\n\tpublic static int[] u = null;\n\t\n\tpublic static String analyze(final int D, final char[] S) {\n\t\tS[S.length-1]++;\n\t\tint i = S.length-1;\n\t\twhile (S[i] > 'z') {\n\t\t\tif (i == 0) return \"Impossible\";\n\t\t\tS[i] = 'a';\n\t\t\tS[--i]++;\n\t\t}\n\t\tl = new int[S.length+1];\n\t\tn = new int[S.length+1];\n\t\to = new int[S.length+1];\n\t\tu = new int[S.length+1];\n\t\tint[] t = new int[S.length+1];\n\t\tt[0] = D-1;\n\t\ti = 0;\n\t\twhile (i < S.length) {\n\t\t\tif (S[i] == '0') {\n\t\t\t\tS[i] = 'a';\n\t\t\t\tif (i+1 < S.length) S[i+1] = '0';\n\t\t\t}\n\t\t\tu[i+1] = u[i]+S[i];\n\t\t\tif (i>0) {\n\t\t\t\tif (S[i]==S[i-1]) { l[i]=l[i-1]; n[l[i]]++; o[i]=o[i-1]+1; }\n\t\t\t\telse { l[i]=l[i-1]+1; n[l[i]]=0; o[i]=0; }\n\t\t\t} else { l[i]=0; n[l[i]]=0; o[i]=0; }\n\n\t\t\tif (i >= t[i]) {\n\t\t\t\tif (check(i-D, i, S) || check(i-D+1, i, S)) {\n\t\t\t\t\tif (i+1 < S.length) S[i+1] = '0';\n\t\t\t\t\tS[i]++;\n\t\t\t\t\tn[l[i]]--;\n\t\t\t\t\twhile (S[i] > 'z') {\n\t\t\t\t\t\tif (i == 0) return \"Impossible\";\n\t\t\t\t\t\tS[i] = '0';\n\t\t\t\t\t\tS[--i]++;\n\t\t\t\t\t\tn[l[i]]--;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint j = i;\n\t\t\ti++;\n\t\t\tt[i] = Math.max(i, t[i-1]);\n\t\t\tint k = j-D+1+(t[i]-j)*2;\n\t\t\twhile (t[i] < S.length && k < j) {\n\t\t\t\tif (k < 0) { t[i]++; k+=2; continue; }\n\t\t\t\tif (k == 0) {\n\t\t\t\t\tif (S[j]!=S[k]) { t[i]++; k+=2; continue; }\n\t\t\t\t} else {\n\t\t\t\t\tif (S[j]!=S[k] && S[j]!=S[k-1]) { t[i]++; k+=2; continue; }\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn String.valueOf(S);\n\t}\n\n\tpublic static boolean check(int p, int q, char[] S) {\n\t\tif (p < 0) return false;\n\t\tint m = (q-p)/2;\n\t\tif (u[q+1]-u[q-m] != u[p+m+1]-u[p]) return false;\n\t\twhile (S[p]==S[q]) {\n\t\t\tm = Math.min(n[l[p]]-o[p],o[q])+1;\n\t\t\tp+=m;\n\t\t\tq-=m;\n\t\t\tif (p>q) return true;\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db3954007caff70db121a28d2311568b", "src_uid": "959a274a06219f4a8c061cd6f5b17160", "difficulty": 2800} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tBufferedReader questionreader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tPrintWriter answerwriter = new PrintWriter(System.out);\n\n\t\t\tint D = Integer.parseInt(questionreader.readLine());\n\t\t\tchar[] S = questionreader.readLine().toCharArray();\n\t\t\t\n\t\t\tanswerwriter.println(analyze(D, S));\n\t\t\t\n\t\t\tanswerwriter.close();\n\t\t\tquestionreader.close();\n\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t\treturn;\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\tpublic static String analyze(final int D, final char[] S) {\n\t\tS[S.length-1]++;\n\t\tint i = S.length-1;\n\t\twhile (S[i] > 'z') {\n\t\t\tif (i == 0) return \"Impossible\";\n\t\t\tS[i] = 'a';\n\t\t\tS[--i]++;\n\t\t}\n\t\tboolean[][] table = new boolean[S.length][D+2];\n\t\tfor (i = 0; i < S.length; i++) { table[i][0] = true; table[i][1] = true; }\n\t\ti = 0;\n\t\twhile (i < S.length) {\n\t\t\tif (S[i] == '0') {\n\t\t\t\tS[i] = 'a';\n\t\t\t\tif (i+1 < S.length) S[i+1] = '0';\n\t\t\t}\n\t\t\tfor (int j = 0; j < D; j++) {\n\t\t\t\tif (i-j <= 0) break;\n\t\t\t\tif (table[i-1][j] && S[i-j-1]==S[i]) table[i][j+2] = true;\n\t\t\t\telse table[i][j+2] = false;\n\t\t\t}\n\t\t\tif (table[i][D] || table[i][D+1]) {\n\t\t\t\tif (i+1 < S.length) S[i+1] = '0';\n\t\t\t\tS[i]++;\n\t\t\t\twhile (S[i] > 'z') {\n\t\t\t\t\tif (i == 0) return \"Impossible\";\n\t\t\t\t\tS[i] = '0';\n\t\t\t\t\tS[--i]++;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\treturn String.valueOf(S);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "894996b3f66b3a958b479fb4228b3659", "src_uid": "959a274a06219f4a8c061cd6f5b17160", "difficulty": 2800} {"lang": "Java 8", "source_code": "mport java.util.*;\npublic class A {\n\tpublic static void main(String[]args){\n\t\tScanner sc=new Scanner(System.in);\n\t\tSystem.out.println(sc.nextInt()==2?2:1);\n\t\tsc.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2949404372af353851a53989b44d0d01", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tlong num = sc.nextLong();\n\t\t\n\t\twhile (num > 1) {\n\t\t\tfor(int i=num-1; i > 1; i--) {\n\t\t\t\tif (num % i != 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tnum = num - i;\n\t\t}\n\t\t\n\t\tSystem.out.println(num);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "32d225ce2a03991fcf92b7a1db89e774", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class A546{\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n int a = scan.nextInt();\n for(int i=2;i=a[1]){\n min=a[1];\n max=a[0];\n }\n else{\n min=a[0];\n max=a[1];\n }\n System.out.println(min+\" \"+max/2);\n }\n else{\n System.out.println(a[0]+\" \"+0);\n }\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "21f3d97a34a540c977bafbc35b473c50", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800} {"lang": "Java 7", "source_code": "public class main {\n \n public static void main(String args[]){ //method header\n \n \n //System.out.println(\"hello world !!\"); //method type ... the both create the method we need .\n\n Scanner haha=new Scanner(System.in);\n int h, g;\n h=haha.nextInt();\n g=haha.nextInt();\n int a=0 , b=0;\n if(h>g){\n \n b=(h-g)/2;\n a=g;}\n else{\n b=(g-h)/2;\n a=h;}\n System.out.print(a);\n System.out.print(\" \");\n System.out.print(b);\n \n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8558b126f4f5fbf2e8e6262354b18c21", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n public static void main(String[] args)throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String str = br.readLine();\n StringTokenizer st = new StringTokenizer(str);\n int red = Integer.parseInt(st.nextToken());\n int blue = Integer.parseInt(st.nextToken());\n String res = findNoOfDaysSocksCanbeWorn(red, blue);\n System.out.println(res);\n }\n private String findNoOfDaysSocksCanbeWorn(int red, int blue) {\n StringBuffer sb = new StringBuffer(\"\");\n int temp;\n sb.append(String.valueOf(Integer.min(red, blue)));\n temp = Math.abs(red - blue) / 2;\n sb.append(\" \");\n sb.append(String.valueOf(temp));\n return sb.toString();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0c6590ffeba8fffd3b0e22093798c0ee", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class ProblemD {\n\n public static void main(String[] args) throws IOException {\n BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n String line = s.readLine();\n int len = line.length();\n int[] countA = new int[10];\n int[] countB = new int[10];\n for (int i = 0 ; i < len ; i++) {\n int c = line.charAt(i) - '0';\n countA[c]++;\n }\n countB = countA.clone();\n\n int maxzero = 0;\n int maxstart = -1;\n for (int start = 1 ; start <= 5 ; start++) {\n if (countA[start] >= 1 && countB[10-start] >= 1) {\n int zero = 1;\n countA[start]--;\n countB[10-start]--;\n for (int pair = 0; pair <= 4 ; pair++) {\n zero += Math.min(countA[pair], countB[9-pair]);\n }\n if (maxzero < zero) {\n maxzero = zero;\n maxstart = start;\n }\n countA[start]++;\n countB[10-start]++;\n }\n }\n if (maxstart == -1) {\n for (int times = 0 ; times <= 1 ; times++) {\n for (int ct = 1 ; ct <= 10 ; ct++) {\n int cx = ct % 10;\n for (int x = 0 ; x < countA[cx] ; x++) {\n System.out.print(cx);\n }\n }\n System.out.println();\n }\n return;\n }\n countA[maxstart]--;\n countB[10-maxstart]--;\n \n String an = \"\";\n String bn = \"\";\n int fzero = countA[0] - countA[9];\n if (fzero >= 1) {\n for (int i = 0 ; i < fzero ; i++) {\n an = \"0\" + an;\n bn = \"0\" + bn;\n }\n countA[0] -= fzero;\n countB[0] -= fzero;\n }\n \n \n an = maxstart + an;\n bn = (10-maxstart) + bn;\n for (int pair = 0; pair <= 9 ; pair++) {\n int t = Math.min(countA[pair], countB[9-pair]);\n for (int times = 0 ; times < t ; times++) {\n an = pair + an;\n bn = (9-pair) + bn;\n }\n countA[pair] -= t;\n countB[9-pair] -= t;\n }\n \n \n for (int ct = 1 ; ct <= 10 ; ct++) {\n int cx = ct % 10;\n for (int x = 0 ; x < countA[cx] ; x++) {\n System.out.print(cx);\n }\n }\n System.out.println(an);\n \n for (int ct = 1 ; ct <= 10 ; ct++) {\n int cx = ct % 10;\n for (int x = 0 ; x < countB[cx] ; x++) {\n System.out.print(cx);\n }\n }\n System.out.println(bn);\n \n \n }\n \n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c48500a9049fc0da01aeecfab47a16d5", "src_uid": "34b67958a37865e1ca0529bbf528dd9a", "difficulty": 1900} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Solution {\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n\n String s = in.readLine();\n int[] a = new int[s.length()];\n for (int i = 0; i < s.length(); i++)\n a[i] = s.charAt(i) - '0';\n\n int[] count = new int[10];\n\n for (int i = 0; i < a.length; i++)\n count[a[i]]++;\n\n int max = Integer.MIN_VALUE;\n String max1 = \"\";\n String max2 = \"\";\n for (int i = 1; i <= 5; i++) {\n if (count[i] == 0 || count[10 - i] == 0)\n continue;\n int[] tmpCount1 = Arrays.copyOf(count, count.length);\n int[] tmpCount2 = Arrays.copyOf(count, count.length);\n tmpCount1[i]--;\n tmpCount2[10 - i]--;\n Ans ans = getPerms(tmpCount1, tmpCount2);\n\n if (ans.len > max) {\n max = ans.len;\n max1 = ans.s1 + Integer.valueOf(i).toString() + ans.z1;\n max2 = ans.s2 + Integer.valueOf(10 - i).toString() + ans.z2;\n }\n }\n\n if (max == Integer.MIN_VALUE) {\n int[] tmpCount1 = Arrays.copyOf(count, count.length);\n int[] tmpCount2 = Arrays.copyOf(count, count.length);\n\n String tmp1 = \"\";\n String tmp2 = \"\";\n while (tmpCount1[0] > 0 && tmpCount2[0] > 0) {\n tmp1 += 0;\n tmp2 += 0;\n tmpCount1[0]--;\n tmpCount2[0]--;\n }\n\n for (int i = 0; i <= 9; i++) {\n while (tmpCount1[i] > 0) {\n max1 += i;\n tmpCount1[i]--;\n }\n while (tmpCount2[i] > 0) {\n max2 += i;\n tmpCount2[i]--;\n }\n }\n\n max1 += tmp1;\n max2 += tmp2;\n }\n\n out.println(max1);\n out.println(max2);\n out.close();\n }\n\n static class Ans {\n public String s1;\n public String s2;\n public String z1;\n public String z2;\n public int len;\n\n public Ans() {\n s1 = \"\";\n s2 = \"\";\n z1 = \"\";\n z2 = \"\";\n len = 0;\n }\n }\n\n private static Ans getPerms(int[] count1, int[] count2) {\n Ans ans = new Ans();\n String tmp1 = \"\";\n String tmp2 = \"\";\n for (int i = 0; i <= 9; i++)\n while (count1[i] > 0 && count2[10 - i - 1] > 0) {\n tmp1 += i;\n tmp2 += 10 - i - 1;\n count1[i]--;\n count2[10 - i - 1]--;\n }\n\n while (count1[0] > 0 && count2[0] > 0) {\n ans.z1 += 0;\n ans.z2 += 0;\n count1[0]--;\n count2[0]--;\n }\n\n ans.len = tmp1.length() + ans.z1.length();\n\n for (int i = 0; i <= 9; i++) {\n while (count1[i] > 0) {\n ans.s1 += i;\n count1[i]--;\n }\n while (count2[i] > 0) {\n ans.s2 += i;\n count2[i]--;\n }\n }\n\n ans.s1 += tmp1;\n ans.s2 += tmp2;\n\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "12a562264c4235490d2c25ef2aed5170", "src_uid": "34b67958a37865e1ca0529bbf528dd9a", "difficulty": 1900} {"lang": "Java 6", "source_code": "import sun.plugin.javascript.navig.Array;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class B {\n\tstatic Scanner in; static int next() throws Exception {return in.nextInt();};\n//\tstatic StreamTokenizer in; static long next() throws Exception {in.nextToken(); return (long) in.nval;}\n//\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new Scanner(System.in);\n//\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n//\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n String s = new String(in.next());\n\n int a[] = new int[10];\n Arrays.fill(a,0);\n int n = s.length();\n for (int i = 0;i < n;i++) a[s.charAt(i)-'0']++;\n int res = 0, best = 0;\n for (int i = 1;i <=5;i++) {\n int counter = 0;\n int b[] = a.clone();\n int c[] = a.clone();\n if (b[i] > 0 && c[10-i] > 0) {\n b[i]--;\n c[10-i]--;\n counter++;\n for (int j = 0;j < 10;j++) {\n counter += Math.min(b[j],c[9-j]);\n b[j] -= Math.min(b[j],c[9-j]);\n c[9-j] -= Math.min(b[j],c[9-j]);\n }\n }\n counter += Math.min(b[0], c[0]);\n if (counter > res) {\n res = counter;\n best = i;\n }\n }\n\n int pairA[] = new int[n];\n int pairB[] = new int[n];\n int z = n-1;\n\n int b[] = a.clone();\n int c[] = a.clone();\n if (b[best] > 0 && c[10-best] > 0) {\n b[best]--;\n c[10-best]--;\n pairA[z] = best;\n pairB[z] = 10-best;\n z--;\n for (int j = 0;j < 10;j++) {\n for (int u = 0;b[j]>0&&c[9-j]>0;u++){\n pairA[z] = j;\n b[j]--;\n pairB[z] = 9-j;\n c[9-j]--;\n z--;\n }\n }\n int sum1 = 0;\n for (int i = 1;i < 10;i++) {\n sum1 += b[i];\n }\n int sum2 = 0;\n\n for (int i = 1;i < 10;i++) {\n sum2+=c[i];\n }\n for (int i = 1;i < 10;i++) {\n while (b[i] > 0) {\n out.print(i);\n b[i]--;\n }\n }\n if (sum1 < sum2) {\n for (int i = sum1;i < sum2;i++)\n c[0]--;\n out.print(0);\n }\n for (int i = z+1;i < n;i++) out.print(pairA[i]);\n for (int i = 0;i < b[0];i++) out.print(0);\n out.println();\n\n for (int i = 1;i < 10;i++) {\n while (c[i] > 0) {\n out.print(i);\n c[i]--;\n }\n }\n\n if (sum1 > sum2) {\n for (int i = sum2;i < sum1;i++)\n b[0]--;\n out.print(0);\n }\n for (int i = z+1;i < n;i++) out.print(pairB[i]);\n for (int i = 0;i < c[0];i++) out.print(0);\n out.println();\n } else {\n char g[] = s.toCharArray();\n Arrays.sort(g);\n for (int i = n-1;i >= 0;i--) out.print(g[i]);\n out.println();\n\n for (int i = n-1;i >= 0;i--) out.print(g[i]);\n }\n\n\n // out.println(res);\n\n\n out.println();\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "828c3524dd19bcc3035bca380829f368", "src_uid": "34b67958a37865e1ca0529bbf528dd9a", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF139D {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tchar[] cc = br.readLine().toCharArray();\n\t\tint[] aa = new int[10];\n\t\tfor (int i = 0; i < cc.length; i++) {\n\t\t\tint d = cc[i] - '0';\n\t\t\taa[d]++;\n\t\t}\n\t\tint[] a0 = new int[10];\n\t\tint[] a1 = new int[10];\n\t\tint[] a2 = new int[10];\n\t\tint max = 0, z_ = 0, x_ = 0;\n\t\tfor (int z = 0; z <= aa[0]; z++) {\n\t\t\tfor (int d = 0; d <= 9; d++)\n\t\t\t\ta0[d] = aa[d];\n\t\t\ta0[0] -= z;\n\t\t\tfor (int x = 1; x <= 5; x++)\n\t\t\t\tif (a0[x] > 0 && a0[10 - x] > 0) {\n\t\t\t\t\tfor (int d = 0; d <= 9; d++)\n\t\t\t\t\t\ta1[d] = a2[d] = a0[d];\n\t\t\t\t\ta1[x]--;\n\t\t\t\t\ta2[10 - x]--;\n\t\t\t\t\tint cnt = 0;\n\t\t\t\t\tfor (int d = 0; d <= 9; d++)\n\t\t\t\t\t\tcnt += Math.min(a1[d], a2[9 - d]);\n\t\t\t\t\tif (max < cnt + 1 + z) {\n\t\t\t\t\t\tmax = cnt + 1 + z;\n\t\t\t\t\t\tz_ = z;\n\t\t\t\t\t\tx_ = x;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\tStringBuilder s1 = new StringBuilder();\n\t\tStringBuilder s2 = new StringBuilder();\n\t\tfor (int d = 0; d <= 9; d++)\n\t\t\ta0[d] = aa[d];\n\t\ta0[0] -= z_;\n\t\tfor (int i = 0; i < z_; i++) {\n\t\t\ts1.append('0');\n\t\t\ts2.append('0');\n\t\t}\n\t\tfor (int d = 0; d <= 9; d++)\n\t\t\ta1[d] = a2[d] = a0[d];\n\t\ta1[x_]--;\n\t\ta2[10 - x_]--;\n\t\ts1.append(x_);\n\t\ts2.append(10 - x_);\n\t\tfor (int d = 0; d <= 9; d++)\n\t\t\twhile (a1[d] > 0 && a2[9 - d] > 0) {\n\t\t\t\ta1[d]--;\n\t\t\t\ta2[9 - d]--;\n\t\t\t\ts1.append(d);\n\t\t\t\ts2.append(9 - d);\n\t\t\t}\n\t\tfor (int d = 0; d <= 9; d++) {\n\t\t\tfor (int i = 0; i < a1[d]; i++)\n\t\t\t\ts1.append(d);\n\t\t\tfor (int i = 0; i < a2[d]; i++)\n\t\t\t\ts2.append(d);\n\t\t}\n\t\tSystem.out.println(s1.reverse());\n\t\tSystem.out.println(s2.reverse());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "378606d0ce52bcc72d6c980e86357053", "src_uid": "34b67958a37865e1ca0529bbf528dd9a", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Vector;\nimport java.util.Arrays;\nimport java.util.Comparator;\n\n\npublic class A{\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tlong r = in.nextLong();\n\t\tfor(int i = 1;i*i<=r;++i){\n\t\t\tlong k = r - i*i - i - 1;\n\t\t\tif(k > 0 && k % (2*i) == 0){\n\t\t\t\tSystem.out.println(i + \" \" + k/(2*i));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t}\n\t\tSystem.out.println(\"NO\");\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c6634d89477aadb3e350e5d8e14491ad", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class HeidiLearnsHashing \n{\n\tpublic static void main(String[] s)\n\t{\n\t\tint j,count=0;\n\t\tlong r,x=0,y=0;\n\t\tScanner sc=new Scanner(System.in);\n\t\tr=sc.nextLong();\n\t\tr--;\n\t\tif(r!=0)\n\t\t{\t\n\t\tfor(j=1;j<=(1000000);j++)\n\t\t{\n\t\t\tif(count==1)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif(r%j==0)\n\t\t\t{\n\t\t\t\tif(((r/j)-(j+1))>0 && ((r/j)-(j+1))%2==0)\n\t\t\t\t{\n\t\t\t\t\tcount=1;\n\t\t\t\t\tx=j;\n\t\t\t\t\ty=(((r/j)-(j+1))/2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcount==1;\n\t\t\tx=0;\n\t\t\ty=0;\n\t\t}\n\t\tif(count==1)\n\t\tSystem.out.println(x+\" \"+y);\n\t\telse\n System.out.println(\"NO\");\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05130ffa6897f4c7478e74a19418abeb", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class hele{\n\tpublic static void main(String s[]){\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong k = sc.nextLong();\n\t\tlong sqrt = 1000000;\n\t\tboolean b=false;\n\t\tfor(int i=1;i<=sqrt;i++){\n\t\t\tlong y = (long)((long)k-(long)(i*i)-(long)i-(long)1)%(long)(2*(long)i);\n\t\t\tif(y==0){\n\t\t\t\tlong df = (long)((k-(long)(i*i)-(long)i-(long)1)/(long)(2*(long)i);\n\t\t\t\tif(df>0){\n\t\t\t\tSystem.out.println(i+\" \"+df);\n\t\t\t\tb=true;\n\t\t\t\tbreak;}\n\t\t\t}\n\t\t}\n\t\tif(b==false)\n\t\t\tSystem.out.println(\"NO\");\n\t}\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e954e3e5f3988933f9fb03be480c37be", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200} {"lang": "Java 8", "source_code": "//1184A1\nimport java.util.*;\npublic class heidiA1{\n public static void main(String[] args) {\n int r=sc.nextInt();\n if(r%2==0||r<=3)\n System.out.println(\"NO\");\n else{\n System.out.println(\"1\"+\" \"+((r-3)/2));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "148b9f45288350443b8919044b41adb1", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200} {"lang": "Java 8", "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 rev{\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\n\tpublic static void main(String args[]) throws IOException{\n\t\tinit(System.in);\n\t\t\tint T=nextInt();\n\t\t\tint k=nextInt();\n\t\t\tint c=0;\n\t\t\t\tif(k%2==1){System.out.println(\"1\");exit(0);}\n\t\t\t\twhile(k>0 && k%2==0){k/=2;c++;}System.out.println(c+1);\n\n\t\t\t\n\t\t\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "26a549757d2250c64deb933de16dbe35", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class spoj\n{\n\tstatic class FastReader\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t\n\t\tpublic FastReader()\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next()\n\t\t{\n\t\t\twhile(st==null || !st.hasMoreElements())\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch(IOException e)\n\t\t\t\t{\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine()\n\t\t{\n\t\t\tString str=\"\";\n\t\t\ttry\n\t\t\t{\n\t\t\t\tstr = br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tFastReader fr = new FastReader();\n\t\tlong low,high,mid,m;\n\t\tlong n = fr.nextLong();\n\t\tlong k = fr.nextLong();\n\t\tk--;\n\t\tif(k==(Math.pow(2,n)-1)/2)\n\t\t{\n\t\t\tSystem.out.println(n);\n\t\t}\n\t\telse if(k%2==0)\n\t\t{\n\t\t\tSystem.out.println(1);\t\n\t\t}\n\t\telse\n\t\t{\n\t\t\twhile(lowmid)\n\t\t\t\t{\n\t\t\t\t\tlow = mid + 1;\n\t\t\t\t}\n\t\t\t\telse if(kpos) {\n break;\n }\n }\n return sequence;\n}\n \n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int sequen=sc.nextInt();\n int pos=sc.nextInt();\n System.out.println(sequence(sequen,pos).charAt(pos-1));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d44bb3c755d53f33db5ecd0946ae19bf", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class Solution743B implements Runnable {\n\n public static final double LOG2 = Math.log(2);\n public static final int NIL = Integer.MIN_VALUE;\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n public static void main(String[] args) {\n new Thread(null, new Solution734B(), \"\", 256 * (1L << 20)).start();\n }\n\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n if (System.getProperty(\"ONLINE_JUDGE\") == null\n && Files.exists(Paths.get(\"input.txt\"))) {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } else {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n Locale.setDefault(Locale.US);\n solve();\n in.close();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Throwable t) {\n t.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n // solution\n\n void solve() throws IOException {\n long n = readInt(),\n k = readLong();\n long mask = 0;\n \n for (int i = 0; i < k; i++) {\n mask <<= 1;\n mask ++;\n }\n long tail = k & mask;\n \n System.out.println(Long.numberOfTrailingZeros(tail));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e9881ce3e5cd37a475aa4c174e9b858", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main{\n publis static void main(String args[]){\n Scanner scn=new Scanner(System.in);\n int n=scn.nextInt();\n int ans=0;\n for(int i=1;i<=n/2;i++){\n if(n%i==0){\n ans++;\n }\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "038079c4f4f20f440bf6d2ca832253f2", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String []args){\n \n boolean has=false;\n Scanner sc=new Scanner(System.in);\n n = sc.nextInt();\n int ans=0;\n int result=0;\n int l=0;\n for(int i=1;i max) {\n\t\t\t\tmaxI = i;\n\t\t\t\tmax = arr[i];\n\t\t\t}\n\t\t}\n\n\t\tif(minI > maxI){\n\t\t\tSystem.out.println(n - maxI - 1);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(n - minI - 1);\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f1868f11d9180a86a09e657a84b92665", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800} {"lang": "Java 8", "source_code": "mport java.util.*;\npublic class mrje {\n\tpublic static void main(String args[]) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint a=0,b=0;\n\t\tfor(int i=1;i<=n;i++) {\n\t\t\tint t=sc.nextInt();\n\t\t\tif(t==1)\n\t\t\t\ta=i;\n\t\t\tif(t==n)\n\t\t\t\tb=i;\n\t\t}\n\t\tif(a myList = new ArrayList();\n\t\tScanner sc= new Scanner(System.in);\n\tint n=sc.nextInt();\n\tfor(int i=1;i<=n;i++){\n\t\tmyList.add(sc.nextInt());\n//\t\tSystem.out.println(myList);\n\t\t}\n\t\n\t int imax = 0;\n\t\t for ( int i = 1; i < n; i++ )\n\t\t {\n\t\t if ( myList.get(i) > myList.get(imax) ) imax= i;\n\t\t }\n\t\t //System.out.println(imax);\n\t\t int imin = 0;\n\t\t for ( int i = 1; i < n; i++ )\n\t\t {\n\t\t if ( myList.get(i) < myList.get(imin) ) imin= i;\n\t\t }\n\t\t \n\t\t if (imax == 0 || imax == n - 1 || imin == 0 || imin == n - 1) {\n\t\t\t\tSystem.out.println( n - 1);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(Math.max(Math.max(imax, imin), Math.max(n - 1 - imin, n - 1 - imax)));\n\t\t\t}\n\n\t\t //System.out.println(largest);\n\t\t // System.out.println(smallest);\n\t\t\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d2114ea7c3cc4180692ae96f6fcd5fd0", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] arr = new int[n];\n int min=0;\n int max=0;\n for ( int i=0 ;i < n ; i++) \n {\n int t = in.nextInt();\n arr[i] = t;\n if(t==1) min = i+1;\n if(t==n) max = i+1;\n }\n if( Math.abs(max - min) == n System.out.println(n);\n else\n {\n int val1 = maxi(min , n);\n int val2 = maxi(1 , max);\n int val3 = maxi(min , 1);\n int val4 = maxi(n , max);\n return Math.max(Math.max(Math.max(val1,val2),Math.max(val3,val4)))\n }\n }\n public static int maxi (int a , int b)\n {\n return Maths.abs(a-b);\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4abbc41faeab740696573c78f8829ea3", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n long n=sc.nextLong();\n HashSet s=new HashSet();\n \n while(!s.contains(n)){\n while(n%10==0){\n n=n/10;\n }\n s.add(n);\n n=n+1;\n }\n \n }\n int ans=s.size();\n System.out.println(ans);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "411e9002470eb758ee6b05f7f9f48e7f", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100} {"lang": "Java 8", "source_code": "public class Main{\n \n public static void main(String args[])\n { \n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n HashMap mp=new HashMap();\n while(mp.get(n)!=1)\n { \n mp.put(n, 1);\n n=n+1;\n while(n%10==0) n/=10;\n }\n Syste.out.println(mp.size()) ;\n \n\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39009798d86ad6461bc3aef01e5a79e8", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars==-1) \n throw new InputMismatchException();\n \n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n }\n catch (IOException e) {\n throw new InputMismatchException();\n }\n \n if(numChars <= 0) \n return -1;\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n \n while(isSpaceChar(c)) \n c = read();\n \n int sgn = 1;\n \n if (c == '-') {\n sgn = -1;\n c = read();\n }\n \n int res = 0;\n do {\n if(c<'0'||c>'9') \n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c)); \n \n return res * sgn;\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n \n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } \n while (!isSpaceChar(c));\n \n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public String next() {\n return readString();\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n public static void main(String args[]) throws Exception {\n new Thread(null, new Main(),\"Main\",1<<26).start();\n }\n \n static void merge(int arr[], int l, int m, int r) { \n int n1 = m - l + 1; \n int n2 = r - m; \n int L[] = new int [n1]; \n int R[] = new int [n2]; \n for (int i=0; i nums = new ArrayList<>();\n ++n;\n while(n > 0)\n {\n nums.add(n%10);\n n /= 10;\n } \n while(nums.get(0) == 0)\n {\n nums.remove(0);\n }\n \n \n for(int i = nums.size()-1; i>=0; i--)\n {\n s.append(nums.get(i));\n }\n \n z = Integer.parseInt(s.toString());\n \n return z;\n}\n \npublic static int ReachableNums(int n)\n{\n ArrayList Rnums = new ArrayList<>();\n int count = 1;\n Rnums.add(n);\n int x = removeZero(n);\n \n\n \n while(!Rnums.contains(x))\n {\n \n count++;\n Rnums.add(x);\n x = removeZero(x);\n }\n \n return count;\n} \n \n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int x = input.nextInt();\n System.out.println ReachableNums(x));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c56353d5567ef6f394e7968560e140ed", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author marwa\n */\npublic class Main {\n\n public static void main(String[] args) throws java.lang.Exception {\n /*------------------------------------A. Sereja and Coat Rack----------------------------------------------------**/\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int d = sc.nextInt();\n int[] visitors = new int[n];\n int total = 0;\n\n for (int i = 0; i < visitors.length; i++) {\n visitors[i] = sc.nextInt();\n\n }\n Arrays.sort(visitors);\n int m = sc.nextInt();\n for (int i = 0; i < m; i++) {\n total += visitors[i];\n }\n int ppl, penalty;\n if (m > n) {\n ppl = m - n;\n penalty = ppl * d;\n }else\n penalty=0;\n int cost = total - penalty;\n System.out.println(cost);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0cf51b2033652cc5ac8a5c24c9a77fa9", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\n\npublic class A implements Runnable {\n\tstatic String Y = \"YES\", N = \"NO\";\n\tstatic long inf = (long) 1e16;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new A(), \"Solver\", 1L << 26).start();\n\t}\n\n\tprivate Scanner scan;\n\tprivate PrintWriter out;\n\n\tpublic A() {\n\t\tscan = new Scanner(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\tSystem.out.println(1 / 0);\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid solve() {\n\t\tint n = scan.nextInt(), d = scan.nextInt();\n\t\tint[] costs = new int[n];\n\t\tfor(int i=0;i{\n\t\tlong a,b;\n\t\tpublic Pair(long a, long b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(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 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 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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d7ca8ee13697cecc5772959cdc6f104d", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000} {"lang": "Java 7", "source_code": "public class solution{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint sum=0;\n\t\tint n = scan.nextInt();\n\t\tint d = scan.nextInt();\n\t\tint arr[] = new int[n];\n\t\tfor(int i=0;im?m:n;\n\t\tfor(int i = 0;in?(m-n)*d:0;\n\t\tSystem.out.println(sum);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "258fdf5cec2683f50e065596d7cd63b2", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n/**\n *\n * @author Rawan Ali\n */\npublic class SerejaAndCoatRack {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n`Scanner input = new Scanner(System.in);\nint n =input.nextInt();\nint d= input.nextInt();\nint a=0;\n int arr[] = new int[n];\n if(n>=1&&d<=100){\n for(int j = 0 ; j < arr.length ;j++){\n \n arr[j] = input.nextInt();\n if ( arr[j]<=100 && arr[j]>=1){\n a= a+ arr[j];}\n }\n \n int m = input.nextInt();\n if (m<=100&&m>=1){\n int l = n-m;\n int s=l*d;\n int total = a+s;\n\n System.out.println(total);\n \n }\n }\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a28e118437978c61fd6f2fa4c48bbba8", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\nimport org.aspectj.lang.reflect.CatchClauseSignature;\n\npublic class A {\n\tpublic static void main(String args[]) {\n\t\t\n\t\t\n\t\tString str;\n\t\tScanner scanner= new Scanner(System.in);\n\t\t\n\t\t\tint i=0,j=0;\n\t\t\tstr = scanner.nextLine();\n\t\t\t\n\t\tfor(int k=0;k0) {\n// int[] ms = Arrays.copyOf(mas, mas.length);\n move(i);\n long res1 = count();\n if (res1>res) res = res1;\n reset();\n }\n }\n\n System.out.println(res);\n\n }\n\n public static void reset() {\n ms = Arrays.copyOf(mas, mas.length);\n }\n\n public static void move(int n) {\n long k = ms[n];\n ms[n] = 0;\n long sum = k / 14;\n k %= 14;\n for (int i=0;i<14;++i) {\n ms[i] += sum;\n }\n n = (n+1)%14;\n while (k > 0) {\n ms[n]++;\n n = (n+1)%14;\n k--;\n }\n }\n\n public static long count() {\n long res = 0;\n for (int i =0;i<14;++i) {\n if (ms[i]%2 == 0) res += ms[i];\n }\n return res;\n }\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c882c2e3711dd6117f0d9d920c50872b", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100} {"lang": "Java 8", "source_code": "/*\n * Author: Minho Kim (ISKU)\n * Date: May 1, 2018\n * E-mail: minho.kim093@gmail.com\n *\n * https://github.com/ISKU/Algorithm\n * http://codeforces.com/problemset/problem/975/B\n */\n\nimport java.util.*;\nimport java.io.*;\n\npublic class B {\n\tpublic static void main(String... args) throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\n\t\tlong[] array = new long[14];\n\t\tfor (int i = 0; i < 14; i++)\n\t\t\tarray[i] = Long.parseLong(st.nextToken());\n\n\t\tlong answer = 0;\n\t\tfor (int i = 0; i < 14; i++) {\n\t\t\tif (array[i] == 0)\n\t\t\t\tcontinue;\n\n\t\t\tlong[] temp = new long[14];\n\t\t\tfor (int j = 0; j < 14; j++)\n\t\t\t\ttemp[j] = array[j];\n\n\t\t\tlong plus = temp[i] / 14;\n\t\t\tlong remain = temp[i] % 14;\n\n\t\t\tlong count = 0;\n\t\t\tfor (int k = i + 1; count < 14; count++, k = (k + 1) % 14)\n\t\t\t\ttemp[k] += plus;\n\n\t\t\tcount = remain;\n\t\t\tfor (int k = i + 1; count > 0; count--, k = (k + 1) % 14)\n\t\t\t\ttemp[k]++;\n\n\t\t\tlong sum = 0;\n\t\t\tfor (int k = 0; k < 14; k++) {\n\t\t\t\tif (temp[k] % 2 == 0)\n\t\t\t\t\tsum += temp[k];\n\t\t\t}\n\n\t\t\tanswer = Math.max(answer, sum);\n\t\t}\n\n\t\tSystem.out.print(answer);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "93b34a4e8b3eae429151fad4575fe9f4", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100} {"lang": "Java 8", "source_code": "package round478;\n\nimport java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main2 {\n\n public static void main(String[] args) {\n\n Main.FastScanner sc = new Main.FastScanner();\n int mas[] = new int[14];\n for (int i = 0;i<14;++i) {\n mas[i] = sc.nextInt();\n }\n int res = 0;\n for (int i = 0;i<14;++i) {\n if (mas[i]>0) {\n// int ms[] = new int[14];\n int[] ms = Arrays.copyOf(mas, mas.length);\n int res1 = count(ms, i);\n for (int j = 0;j<14;++j) {\n// System.out.print(mas[j]+\" \");\n }\n// System.out.println();\n if (res1>res) res = res1;\n }\n }\n\n System.out.println(res);\n\n }\n\n public static int count(int[] ms, int n) {\n// System.out.println(n+\" \"+ms[n]);\n int res = 0;\n int k = ms[n];\n ms[n] = 0;\n for (int i=k;i>0;--i) {\n if (n<13) {n++;}\n else {\n n=0;\n }\n ms[n]++;\n// System.out.println(n + \" \" + mas[n]);\n }\n\n for (int i=0;i='A'&&A[0]<='J')\n\t\t\tfact=(fact*9)/10;\n\t\t\n\t\tint numQ=0;\n\t\tfor(int i=0;i=numChars)\n\t\t\t{\n\t\t\tcurChar=0;\n\t\t\ttry\n\t\t\t\t{\n\t\t\t\tnumChars=stream.read(buf);\n\t\t\t\t} catch (IOException e)\n\t\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\tif(numChars<=0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\treturn buf[curChar++];\n\t\t}\n\n\tpublic int readInt()\n\t\t{\n\t\tint c=read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc=read();\n\t\tint sgn=1;\n\t\tif(c=='-')\n\t\t\t{\n\t\t\tsgn=-1;\n\t\t\tc=read();\n\t\t\t}\n\t\tint res=0;\n\t\tdo\n\t\t\t{\n\t\t\tif(c<'0'||c>'9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres*=10;\n\t\t\tres+=c-'0';\n\t\t\tc=read();\n\t\t\t} while (!isSpaceChar(c));\n\t\treturn res*sgn;\n\t\t}\n\n\tpublic boolean isSpaceChar(int c)\n\t\t{\n\t\tif(filter!=null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t\t}\n\n\tpublic static boolean isWhitespace(int c)\n\t\t{\n\t\treturn c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n\t\t}\n\n\tpublic char readCharacter()\n\t\t{\n\t\tint c=read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc=read();\n\t\treturn (char) c;\n\t\t}\n\n\tpublic interface SpaceCharFilter\n\t\t{\n\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "41eb84ad773d2114d7d7f39a2a845677", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class A {\n public static void main(String[] args) {\n BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));\n String s;\n int sum = 0;\n try {\n s = bi.readLine();\n //for (String numStr: line.split(\"\\\\s\"))\n //sum += Integer.parseInt(line);\n }\n catch (Exception t) {\n\n }\n int cntQ = 0;\n for (int i = 0; i < s.length(); i++)\n if (s.charAt(i) == '?')\n cntQ++;\n boolean[] use = new boolean[26];\n for (int i = 0; i < 26; i++)\n use[i] = false;\n \n for (int i = 0; i < s.length(); i++)\n if ('A' <= s.charAt(i) && s.charAt(i) <= 'Z') {\n int pos = s.charAt(i) - 'A';\n use[pos] = true;\n }\n int cntL = 0;\n for (int i = 0; i < 26; i++)\n if (use[i])\n cntL++;\n BigInteger ans = new BigInteger(\"1\");\n for (int i = 0; i < cntQ; i++) {\n ans = ans.multiply(new BigInteger(\"10\"));\n }\n for (int i = 0; i < cntL; i++) {\n Integer tmp = new Integer(10 - i);\n ans = ans.multiply(new BigInteger(tmp.toString()));\n }\n if ('1' <= s.charAt(0) && s.charAt(0) <= '9') {\n\n }\n else {\n ans = ans.divide(new BigInteger(\"10\"));\n ans = ans.multiply(new BigInteger(\"9\"));\n }\n System.out.println(ans.toString());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da67a3bf922cb6357b99d155a327c241", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100} {"lang": "Java 7", "source_code": "//import java.util.*;\npublic class Main{\n public static void main(String[]args){\n Scanner input = new Scanner(System.in);\n String s = input.next();\n int an=0,x=11,xx=0;\n boolean a[]=new boolean[10];\n for(int i=0; i= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\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\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 String next() {\n\t\treturn readString();\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\npublic class 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 println(Object... objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n}\n\npublic class candle\n\t{\npublic static void main(String args[]) throws IOException\n\t\t{\n//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\nInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastReader in = new FastReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tdouble r ;\n\t\tString s = in.next();\n\t\tint a[] = new int[11];\n\t\tchar c[] = s.toCharArray();\n\t\tint result = 1;\n\t\tint m = 10;\n\t\tif('0'<=c[0] && c[0]<='9')\n\t\t\t{\n\t\t\tfor(int i=1;i m; j++, z--) {\n if(str.charAt(z) != str.charAt(j))\n flag = false;\n }\n if(flag)\n System.out.println(true);\n else\n System.out.println(false);\n\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9f5c93ca31642fecab37b28ee982eb42", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800} {"lang": "Java 11", "source_code": "public class Main {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String s = br.readLine(); \n System.out.println(calcular(s));\n }\n \n public static String calcular(String s){\n String resp = \"NO\";\n s = \"00\" + s;\n for (int i = 0; i < s.length(); i++) {\n for (int j = i + 1; j < s.length(); j++) {\n for (int k = j + 1; k < s.length(); k++) {\n int x = 100 * (s.charAt(i) - '0') + 10 * (s.charAt(j) - '0') + s.charAt(k) - '0';\n if (x % 8 == 0) {\n resp = \"YES\\n\" + x;\n }\n }\n }\n }\n return resp;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a6329a108dbed27fdd13f839b1e25f09", "src_uid": "0a2a5927d24c70aca24fc17aa686499e", "difficulty": 1500} {"lang": "Java 11", "source_code": "public class Main {\n private static void checkNum(String num)\n {\n int intNum = -1;\n String temp = \"\";\n if (num.length() > 100)\n return;\n\nif(num.length()>3) {\n //System.out.println(num.substring(num.length() - 3, num.length()));\n if(num.substring(num.length() - 3, num.length()) == \"000\")\n {\n System.out.println(\"YES \" + num);\n }\n for(int i = num.length()-1;i>=num.length()/2;i--)\n {\n for(int j = i-1;j>=1;j--)\n {\n for(int k = j-1;k>=0;k--)\n {\n\n //temp = \"\" + num.charAt(k) + num.charAt(j) + num.charAt(i); //num.substring(k,j) + num.substring(j,i) + num.substring()\n temp = num.substring(k,j) + num.substring(i);\n if(Integer.parseInt(temp) % 8 == 0)\n intNum = Integer.parseInt(temp);\n //System.out.println(\"\" + k + j + i);\n }\n }\n }\n\n }\n intNum = Integer.parseInt(num);\n if(intNum%8 == 0)\n System.out.println(\"YES\\n\" + intNum);\n else\n System.out.println(\"NO\");\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9cec47297dbc8f0f5a0ad23b1b785b29", "src_uid": "0a2a5927d24c70aca24fc17aa686499e", "difficulty": 1500} {"lang": "Java 11", "source_code": "public class Main {\n private static String checkNum(int num)\n {\n if (344%8 == 0)\n return \"YES\\n\" + 344;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d2abc2e7d4dccc6569d0b7f6f938f183", "src_uid": "0a2a5927d24c70aca24fc17aa686499e", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\npublic class Main{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n String s=sc.next();\n for(int i=0;i 0) {\n\t\t\tsum += x / k;\n\t\t\tx /= k;\n\t\t}\n\t\treturn sum >= n;\n\t}\n\u00a0\n\tpublic static int binarySearch(int n, int k) {\n\t\tint lo = 1;\n\t\tint hi = n;\n\t\tint res = 0;\n\t\twhile (lo <= hi) {\n\t\t\tint mid = (lo + hi) / 2;\n\t\t\tif (isValid(mid, k, n)) {\n\t\t\t\thi = mid - 1;\n\t\t\t\tres = mid;\n\t\t\t} else {\n\t\t\t\tlo = mid + 1;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\u00a0\n\tpublic static void main(String[] args) throws IOException, NumberFormatException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\tSystem.out.println(binarySearch(n, k));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "554aa0326ff2172d4724ed91b75ab1ee", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.lang.Math;\n\npublic class Solution {\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 exp = 0;\n int value = 1;\n int v = 1;\n \n while (value != 0) {\n value = v / Math.pow(k, exp);\n v++;\n exp++;\n }\n \n System.out.print(v);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dc4acbadff3920e2c05813e2efe2a561", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class BMOil{\n \n static int n, k;\n \n public static void main (String[] args){\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n k = in.nextInt();\n \n int lo = 0;\n int hi = 1;\n \n //upper bound for hi\n while(!works(hi)) {\n hi *= 2;\n }\n \n while(hi - lo > 1) {\n int mid = lo + (hi - lo) / 2;\n if(works(mid))\n \t hi = mid;\n else\n \t lo = mid;\n }\n }\n \n static bool works(int mid) {\n int lines = mid; // number of lines Vasya can write\n int lines_left = n; //starts after writing once\n for (int i=0; lines > 0; i++){\n lines_left -= lines/ (Math.pow(k,i);\n if (lines_left <= 0)\n return true;\n }\n return false;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec0f806b130aa05c94002cece18f26f3", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\n \npublic class Main{\n public static boolean burnOil(int v, int k, int n)\n {\n int total = v;\n int temp = v;\n while(total < n && temp != 0)\n {\n temp /= k;\n total += temp;\n }\n if(total >= n)\n return true;\n return false;\n }\n public static void main(String[] args) {\n // Use the Scanner class\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int low = 0;\n int high = n;\n while(low < high)\n {\n int mid = (low + high) / 2;\n if(burnOil(mid, k, n))\n high = mid - 1;\n else\n low = mid + 1;\n }\n if(burnOil(low, k, n)\n System.out.println(low);\n else\n System.out.println(low+1);\n /*\n int n = sc.nextInt(); // read input as integer\n long k = sc.nextLong(); // read input as long\n double d = sc.nextDouble(); // read input as double\n String str = sc.next(); // read input as String\n String s = sc.nextLine(); // read whole line as String\n */\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "df322f9916ad22b903d603f9f4857040", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500} {"lang": "Java 8", "source_code": " import java.util.*;\n import java.lang.*;\n import java.io.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int d = sc.nextInt();\n int sum1 = Math.max(((3*a)/10),((a)-(a/250))*(c));\n int sum1 = Math.max(((3*b)/10),((b)-(b/250))*(d));\n\n if(sum1>sum2) {\n System.out.println(\"Misha\");\n }\n else if (sum1 == sum2) {\n System.out.println(\"Vasya\");\n }\n else {\n System.out.println(\"Tied\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "705c56683ca7f48a5280275df58850af", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String args[]){\n Scanner s=new Scanner(System.in);\n int a = s.nextInt();\n int b = s.nextInt();\n int c = s.nextInt();\n int d = s.nextInt();\n int resultA = Math.max(3*a /10 , a-a/250*c);\n int resultB = Math.max(3*b/10 , b-b/250*d);\n if(resultAresultB)){\n System.out.println(\"Misha\");\n }else{\n System.out.println(\"Tie\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "761d23a53b0106d11f16aa7eaca17c82", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.text.DecimalFormat;\nimport java.util.InputMismatchException;\nimport java.util.Random;\n\n\npublic class CF_501A {\n\tstatic FastScanner sc = new FastScanner(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tpublic static void main(String[] args) {\n\t\tnew CF_501A().run();\n\t\tout.close();\n\t}\n\t\n\tpublic void run(){\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\t\tint aa = Math.max(3*a/10, a-(a/250)*c);\n\t\tint bb = Math.max(3*b/10, b-(b/250)*d);\n\t\tif(aa>bb)\n\t\t\tout.println(\"Misha\");\n\t\telse if(bb>aa)\n\t\t\tout.println(\"Vasya\");\n\t\telse\n\t\t\tout.println(\"Tie\");\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate final InputStream stream;\n\t private final byte[] buf = new byte[8192];\n\t private int curChar, snumChars;\n\n\t public FastScanner(InputStream st) {\n\t this.stream = st;\n\t }\n\n\t //\u8bfb\u4e00\u4e2a\u5b57\u8282\n\t public int read() {\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 = read();\n\t while (isSpaceChar(c)) {\n\t c = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-') {\n\t sgn = -1;\n\t c = read();\n\t }\n\t int res = 0;\n\t do {\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 boolean isSpaceChar(int c) {\n\t\t return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "585d690e53706a2766748affc8b70d98", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String []args){\n Scanner input = new Scanner (System.in);\n int a = input.nextInt();\n int b = input.nextInt();\n int c = input.nextInt();\n int d = input.nextInt();\n double m = max(a,c);\n double v = max(b,d);\n if(m==v){\n System.out.println(\"Tie\");\n }\n else if(m>v){\n System.out.println(\"Misha\");\n }\n else{\n \n System.out.println(\"Vasya\");\n \n }\n }\n public static double max(int p , int t){\n double max = Math.max(((3*p)/10),(p-(p/250)*t)); \n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1cbdc29567b0859e426d9c365f906f3e", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900} {"lang": "Java 11", "source_code": "package codeforcesNumbertheorypractice;\n\nimport FastIO.InputReader;\n\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class TaskI {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int arr[] = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = in.nextInt();\n }\n Arrays.sort(arr);\n int flag = 0;\n for (int i = 1; i < n - 1; i++) {\n int x = arr[i - 1];\n int y = arr[i];\n int z = arr[i + 1];\n\n int s = (x + y + z) / 2;\n if (s > z) {\n flag = 1;\n break;\n }\n }\n if (flag == 1) {\n out.println(\"YES\");\n } else {\n out.println(\"NO\");\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a7ebedd487936fb1e24c083b4302de8", "src_uid": "897bd80b79df7b1143b652655b9a6790", "difficulty": 1000} {"lang": "Java 11", "source_code": "package codeforcesNumbertheorypractice;\n\nimport FastIO.InputReader;\n\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class TaskI {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int arr[] = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = in.nextInt();\n }\n Arrays.sort(arr);\n int flag = 0;\n for (int i = 1; i < n - 1; i++) {\n double x = arr[i - 1];\n double y = arr[i];\n double z = arr[i + 1];\n\n double s = (x + y + z) / 2;\n if (s > z) {\n flag = 1;\n break;\n }\n }\n if (flag == 1) {\n out.println(\"YES\");\n } else {\n out.println(\"NO\");\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e06c93b0a0044d93a00bc72062d7f29b", "src_uid": "897bd80b79df7b1143b652655b9a6790", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint t = sc.nextInt();\n\t\tint[] arr = new int[t];\n\t\tfor(int i=0;i(arr[0]+arr[1])){\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}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4fd48a84c2a204abdcf6ebce2959f897", "src_uid": "897bd80b79df7b1143b652655b9a6790", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class CodeForce02 {\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 sc= new Scanner(System.in);\n int n = sc.nextInt();\n\n int[] a= new int[n];\n\n for (int i = 0; i < n; i++) a[i] = sc.nextInt();\n Arrays.sort(a);\n for (int i = 0; i < n-2; i++) \n if (a[i]+a[i+1] > a[i+2]) {\n System.out.println(\"YES\");\n return;\n }\n\n System.out.println(\"NO\");\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9f691f868c1881602ae63563d5d481a9", "src_uid": "897bd80b79df7b1143b652655b9a6790", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class frGm{ \n\tpublic static int main(){ \n\t\tint[] num = new int[110]; \n\t\tint n; \n\t\tScanner scan = new Scanner(System.in);\n\t\tn = scan.nextInt(); \n\t\twhile(n!=0){ \n\t\t\tint a; \n\t\t\ta = scan.nextInt(); \n\t\t\tnum[a]++;\n\t\t\tn--;\n\t\t} \n\t\tint cnt=0; \n\t\tint a=0,b=0; \n\t\tfor(int i=1;i<=100;i++){ \n\t\t\tif(num[i]!=0){ \n\t\t\t\tcnt++; \n\t\t\t\tif(a==0) a=i; \n\t\t\t\telse b=i; \n\t\t\t} \n\t\t} \n\t\tif(cnt!=2){\n\t\t\tSystem.out.println(\"NO\");\n\t\t}else{ \n\t\t\tif(num[a]==num[b]){ \n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tSystem.out.println(a + \" \" + b);\n\t\t\t} \n\t\t\telse{\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t} \n\t\t} \n\t} \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "44f7a60c164626edc4e25bd4df3d6c8b", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8", "difficulty": 1000} {"lang": "Java 8", "source_code": "//1.8.0_111(rextester.com)1.8.0_131(codeforces.com)2018-01-04\nimport java.util.Scanner;\npublic class a{\n public static void main(String args[]){\n Scanner scan=new Scanner(System.in);\n int cards=scan.nextInt(),totalInt=0;\n int checkFair[]=new int[101],n[]=new int[100];\n for(int i=0;i p = new ArrayList();\n\t\tfor (long i = 2; i * i <= n; i++) {\n\t\t\twhile (n % i == 0) {\n\t\t\t\tp.add(i);\n\t\t\t\tn /= i;\n\t\t\t}\n\t\t}\n\n\t\tp.add(n);\n\t\tif (p.size() == 2) {\n\t\t\tprintln(2);\n\t\t\treturn;\n\t\t}\n\n\t\tprintln(1);\n\t\tprintln(p.get(0) * p.get(1));\n\t}\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 NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate double nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate void print(Object o) {\n\t\twriter.print(o);\n\t}\n\n\tprivate void println(Object o) {\n\t\twriter.println(o);\n\t}\n\n\tprivate void printf(String format, Object... o) {\n\t\twriter.printf(format, o);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew D().run();\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tprivate void run() {\n\t\ttry {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(13);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0d128646c50793eacc892e55a4f48d87", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43", "difficulty": 1400} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n private MyScanner in;\n private PrintWriter out;\n\n private boolean prime(long n) {\n if (n < 2) {\n return false;\n }\n for (int i = 2; (long) (i) * i <= n; ++i) {\n if (n % i == 0) {\n return false;\n }\n }\n return true;\n }\n\n private void solve() {\n long q = in.nextLong();\n ArrayList div = new ArrayList();\n for (int i = 2; (long) (i) * i <= q; ++i) {\n if (q % i == 0) {\n if (prime(i)) {\n div.add((long) i);\n }\n if ((long) (i) * i != q && prime(q / i)) {\n div.add(q / i);\n }\n }\n }\n if (div.size() == 0) {\n out.println(1);\n out.println(0);\n return;\n }\n if (div.size() == 1) {\n out.println(2);\n return;\n }\n Collections.sort(div);\n if (div.size() == 2 && div.get(0) * div.get(1) == q) {\n out.println(2);\n return;\n }\n out.println(1);\n out.println(div.get(0) * div.get(1));\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 A().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 private String nextToken() {\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 String next() {\n return 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04390c905aac142558ad2aaa898ac31b", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43", "difficulty": 1400} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class WinOrFreeze {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong q = Long.parseLong(in.readLine());\n\t\tint cnt = 0;\n\t\tlong res = 1;\n\t\tfor (long i = 2; i*i <= q; i++) {\n\t\t\tif (q%i == 0) {\n\t\t\t\tif (cnt <= 1) {\n\t\t\t\t\tres *= i;\n\t\t\t\t}\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t\tif (cnt == 0) {\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.out.println(0);\n\t\t} else if (cnt > 1) {\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.out.println(res);\n\t\t} else {\n\t\t\tSystem.out.println(2);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ceeab6cbde2b1312b7bd4ee9413df792", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43", "difficulty": 1400} {"lang": "Java 6", "source_code": "import java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.regex.*;\nimport static java.lang.Math.*;\npublic class A {\n\n // SieveOfEratosthenes\n public static class Prime { // {{{\n public static final int LIMIT = (int) Math.sqrt(1e13);\n public static BitSet prime;\n public static List list; // list contains the primes less than or equal to LIMIT\n \n static {\n int halfLimit = LIMIT>>1;\n int sqrtLimit = (int) Math.sqrt(LIMIT);\n \n prime = new BitSet(halfLimit);\n prime.set(0, prime.size(), true);\n \n prime.clear(0);\n for (int num=3; num<=sqrtLimit; num+=2)\n if (prime.get(num>>1))\n for (int factor = num*num, inc = num << 1; factor <= LIMIT; factor += inc)\n prime.clear(factor>>1);\n \n list = new ArrayList();\n list.add(2);\n for (int i = 1; i < halfLimit; i++)\n if (prime.get(i))\n list.add((i << 1) + 1);\n }\n // num must less than or equal to LIMIT^2 \n public static boolean isPrime(int num) {\n if (num<2) return false;\n if ((num & 1) == 0)\n return num==2;\n \n if (num <= LIMIT) \n return prime.get(num>>1);\n \n int max = (int) Math.sqrt(num);\n for (int p : list) {\n if (p > max)\n break;\n if (num % p == 0)\n return false;\n }\n return true;\n }\n } // }}}\n \n\n public A() throws Exception {\n long q = in.nextLong();\n int n = 0;\n int first = 1;\n for (int p:Prime.list) {\n if (q==1) break;\n while (q%p==0) { \n q /= p;\n n++;\n if (n==3) break;\n first *= p;\n }\n if (n==3) break;\n }\n\n if (n==2)\n System.out.println(2); \n else if(n<2)\n System.out.println(\"1\\n0\");\n else\n System.out.println(\"1\\n\"+first); \n\n System.out.print(buf);\n }\n\n Scanner in = new Scanner(System.in);\n StringBuilder buf = new StringBuilder();\n public static void main(String[] args) throws Exception { // {{{\n new A();\n } // }}}\n public static void debug(Object... arr) { // {{{\n System.err.println(Arrays.deepToString(arr));\n } // }}}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "158c6d10643e37f7c01633fcccd276e8", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class LastDigit{\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scan = new Scanner(System.in);\n\n\t\tint n = scan.nextInt();\n\n\t \tint number = 8;\n\t\tunsigned long resultNumber = 1378;\n\n\n\t\tfor (int i = 1; i < n; i++){\n\n\t\t\tresultNumber = resultNumber * number;\n\n\t\t}\n\n\t\tSystem.out.println(resultNumber % 10);\n\n\n\t}\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "30de4c24b2117fdcf3bc1b4899a6671e", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000} {"lang": "Java 8", "source_code": "\npackage problema;\n\nimport java.util.Scanner;\npublic class Test {\n\n \n public static void main(String[] args) {\n int x;\n long n;\n long dup = 1;\n Scanner s = new Scanner(System.in);\n n = s.nextInt();\n for(int i=1;i= virus.length) {\n\t\t\treturn INF * -1;\n\t\t}\n\t\tif(i >= s1.length || j >= s2.length) {\n\t\t\treturn 0;\n\t\t}\n\t\tif(dp_LCS[i][j][prefixMatched] != -1) {\n\t\t\treturn dp_LCS[i][j][prefixMatched];\n\t\t}\n\t\tint res = -1;\n\t\tint res1 = -1;\n\t\tint prefixMatched2 = prefixMatched;\n\t\twhile (prefixMatched2 >= 0 && s1[i] != virus[prefixMatched2])\n\t\t\tprefixMatched2 = fail[prefixMatched2];\n\t\tprefixMatched2++;\n\t\tres1 = LCS(i+1, j+1, prefixMatched);\n\t\tif(s1[i] == s2[j]) {\n\t\t\tres = LCS(i+1, j+1, prefixMatched2) + 1;\n\t\t}\n\t\treturn dp_LCS[i][j][prefixMatched] = Math.max(res1,\n\t\t\t\tMath.max(res, Math.max(LCS(i+1, j, prefixMatched), LCS(i, j+1, prefixMatched))));\n\t}\n\tstatic void LCSPrint(int i, int j, int prefixMatched) {\n\t\tif(i >= s1.length || j >= s2.length) {\n\t\t\treturn;\n\t\t}\n//\t\tif(prefixMatched >= virus.length) {\n//\t\t\t\n//\t\t}\n\t\tint prefixMatched2 = prefixMatched;\n\t\twhile (prefixMatched2 >= 0 && s1[i] != virus[prefixMatched2])\n\t\t\tprefixMatched2 = fail[prefixMatched2];\n\t\tprefixMatched2++;\n\t\tint optimal = LCS(i, j, prefixMatched);\n\t\tint sol1 = LCS(i + 1, j + 1, prefixMatched2) + 1;\n\t\tint sol4 = LCS(i+1, j+1, prefixMatched);\n\t\tint sol2 = LCS(i + 1, j, prefixMatched);\n\t\tint sol3 = LCS(i, j + 1, prefixMatched);\n\t\tif(optimal == sol4) {\n\t\t\tLCSPrint(i+1, j+1, prefixMatched2);\n\t\t} else \n\t\t\ttry{\n\n\t\t\tif(optimal == sol2) {\n\t\t\tLCSPrint(i + 1, j, prefixMatched);\n\t\t} else \n\t\t\tif(optimal == sol1) {\n\t\t\t\tans.append(s1[i]);\n\t\t\t\tLCSPrint(i+1, j+1, prefixMatched2);\n\t\t}else LCSPrint(i, j+1, prefixMatched);\t\n\t\t}catch(Exception e) {\n\t\t\tout.println(\"eh\");\n\t\t}\n\t}\n\tpublic static int[] FailFunction2(String s) {\n\t\tint n = s.length();\n\t\tint F[] = new int[n + 1];\n\t\tint i = 0, j = -1;\n\t\tF[i] = j;\n\t\twhile (i < n) {\n\t\t\twhile (j >= 0 && s.charAt(i) != s.charAt(j))\n\t\t\t\tj = F[j];\n\t\t\ti++;\n\t\t\tj++;\n\t\t\tF[i] = j;\n\t\t}\n\t\treturn F;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\ts1 = bf.readLine().toCharArray();\n\t\ts2 = bf.readLine().toCharArray();\n\t\tvirus = bf.readLine().toCharArray();\n\t\tout = new PrintWriter(System.out);\n\t\tans = new StringBuilder(\"\");\t\n\t\tdp_LCS = new int[s1.length+1][s2.length+1][virus.length+1];\n\t\tfor(int i = 0; i< dp_LCS.length; i++) {\n\t\t\tfor(int j = 0; j < dp_LCS[i].length; j++) {\n\t\t\t\tArrays.fill(dp_LCS[i][j], -1);\n\t\t\t}\n\t\t}\n\t\tfail = FailFunction2(new String(virus));\n\t\t\n\t\tLCSPrint(0, 0, 0);\n\t\t\n//\t\tout.println(LCS(0, 0, 0));\n\t\tif(ans.toString().length() == 0){ \n\t\t\tout.println('0');\n\t\t} else {\n\t\t\tout.println(ans.toString());\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "beb0bfa3d9507dd2406b6af5d03d3d9c", "src_uid": "391c2abbe862139733fcb997ba1629b8", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\n\npublic class LuckyCommonSubsequence {\n\tstatic char s1[];\n\tstatic char s2[];\n\tstatic char[] virus;\n\tstatic StringBuilder dp[][][];\n\tstatic int dp_LCS[][][];\n\tstatic int INF = 1000000000;\n\tstatic int[] fail;\n\tstatic PrintWriter out;\n\tstatic StringBuilder ans;\n\n\tstatic int LCS(int i, int j, int prefixMatched) {\n\t\tif(prefixMatched >= virus.length) {\n\t\t\treturn INF * -1;\n\t\t}\n\t\tif(i >= s1.length || j >= s2.length) {\n\t\t\treturn 0;\n\t\t}\n\t\tif(dp_LCS[i][j][prefixMatched] != -1) {\n\t\t\treturn dp_LCS[i][j][prefixMatched];\n\t\t}\n\t\tint res = -1;\n\t\tint res1 = -1;\n\t\tint prefixMatched2 = prefixMatched;\n\t\twhile (prefixMatched2 >= 0 && s1[i] != virus[prefixMatched2])\n\t\t\tprefixMatched2 = fail[prefixMatched2];\n\t\tprefixMatched2++;\n\t\tres1 = LCS(i+1, j+1, prefixMatched);\n\t\tif(s1[i] == s2[j]) {\n\t\t\tres = LCS(i+1, j+1, prefixMatched2) + 1;\n\t\t}\n\t\treturn dp_LCS[i][j][prefixMatched] = Math.max(res1,\n\t\t\t\tMath.max(res, Math.max(LCS(i+1, j, prefixMatched), LCS(i, j+1, prefixMatched))));\n\t}\n\tstatic void LCSPrint(int i, int j, int prefixMatched) {\n\t\tif(i >= s1.length || j >= s2.length) {\n\t\t\treturn;\n\t\t}\n\t\tif(prefixMatched >= virus.length) {\n\t\t\tout.println(\"eh\");\n\t\t}\n\t\tint prefixMatched2 = prefixMatched;\n\t\twhile (prefixMatched2 >= 0 && s1[i] != virus[prefixMatched2])\n\t\t\tprefixMatched2 = fail[prefixMatched2];\n\t\tprefixMatched2++;\n\t\tint optimal = LCS(i, j, prefixMatched);\n\t\tint sol1 = LCS(i + 1, j + 1, prefixMatched2) + 1;\n\t\tint sol4 = LCS(i+1, j+1, prefixMatched);\n\t\tint sol2 = LCS(i + 1, j, prefixMatched);\n\t\tint sol3 = LCS(i, j + 1, prefixMatched);\n//\t\ttry{\n\t\tif(optimal == sol4) {\n\t\t\tLCSPrint(i+1, j+1, prefixMatched2);\n\t\t} else if(optimal == sol2) {\n\t\t\tLCSPrint(i + 1, j, prefixMatched);\n\t\t} else \n\t\t\tif(optimal == sol1) {\n\t\t\t\tans.append(s1[i]);\n\t\t\t\tLCSPrint(i+1, j+1, prefixMatched2);\n\t\t}else LCSPrint(i, j+1, prefixMatched);\t\n//\t\t}catch(Exception e) {\n//\t\t}\n\t}\n\tpublic static int[] FailFunction2(String s) {\n\t\tint n = s.length();\n\t\tint F[] = new int[n + 1];\n\t\tint i = 0, j = -1;\n\t\tF[i] = j;\n\t\twhile (i < n) {\n\t\t\twhile (j >= 0 && s.charAt(i) != s.charAt(j))\n\t\t\t\tj = F[j];\n\t\t\ti++;\n\t\t\tj++;\n\t\t\tF[i] = j;\n\t\t}\n\t\treturn F;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\ts1 = bf.readLine().toCharArray();\n\t\ts2 = bf.readLine().toCharArray();\n\t\tvirus = bf.readLine().toCharArray();\n\t\tout = new PrintWriter(System.out);\n\t\tans = new StringBuilder(\"\");\t\n\t\tdp_LCS = new int[s1.length+1][s2.length+1][virus.length+1];\n\t\tfor(int i = 0; i< dp_LCS.length; i++) {\n\t\t\tfor(int j = 0; j < dp_LCS[i].length; j++) {\n\t\t\t\tArrays.fill(dp_LCS[i][j], -1);\n\t\t\t}\n\t\t}\n\t\tfail = FailFunction2(new String(virus));\n\t\t\n\t\tLCSPrint(0, 0, 0);\n\t\t\n//\t\tout.println(LCS(0, 0, 0));\n\t\tif(ans.toString().length() == 0){ \n\t\t\tout.println('0');\n\t\t} else {\n\t\t\tout.println(ans.toString());\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b446a7e998daa844152477b4306e3737", "src_uid": "391c2abbe862139733fcb997ba1629b8", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D_D2_201 {\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n String s1 = in.nextLine();\n String s2 = in.nextLine();\n String virus = in.nextLine();\n String ans = lcsReversedWithKMP(s1, s2, virus);\n System.out.println(ans.length() == 0 ? \"0\" : ans);\n }\n\n public static int[] buildAutomata(String pat) {\n int M = pat.length();\n int atmataIndx = 0;\n int patIndx = 1;\n int[] automata = new int[M];\n while (patIndx < M) {\n if (pat.charAt(atmataIndx) == pat.charAt(patIndx)) {\n atmataIndx++;\n automata[patIndx] = atmataIndx;\n patIndx++;\n } else {\n if (atmataIndx != 0) {\n atmataIndx = automata[atmataIndx - 1];\n } else {\n automata[patIndx] = 0;\n patIndx++;\n }\n }\n }\n return automata;\n }\n\n public static boolean KMP(String str, String pat) {\n int[] automata = buildAutomata(pat);\n int M = pat.length();\n int N = str.length();\n\n int atmataIndx = 0;\n int i = 0;\n while (i < N) {\n if (str.charAt(i) == pat.charAt(atmataIndx)) {\n i++;\n atmataIndx++;\n if (atmataIndx == M) {\n return true;\n }\n } else if (i < N) {\n if (atmataIndx != 0) {\n atmataIndx = automata[atmataIndx - 1];\n } else {\n i++;\n }\n }\n }\n return false;\n }\n\n public static String lcsReversedWithKMP(String a, String b, String virus) {\n String maxLcs = \"\";\n int[][] LCS = new int[a.length() + 1][b.length() + 1];\n a = new StringBuilder(a).reverse().toString();\n b = new StringBuilder(b).reverse().toString();\n for (int i = 0; i < a.length(); i++) {\n for (int j = 0; j < b.length(); j++) {\n if (a.charAt(i) == b.charAt(j)) {\n LCS[i + 1][j + 1] = LCS[i][j] + 1;\n } else {\n LCS[i + 1][j + 1] = Math.max(LCS[i][j + 1], LCS[i + 1][j]);\n }\n }\n }\n\n StringBuilder sb = new StringBuilder();\n\n for (int i = a.length(), j = b.length(); i != 0 && j != 0;) {\n if (a.charAt(i - 1) == b.charAt(j - 1)) {\n boolean matched = KMP(sb.toString() + a.charAt(i - 1), virus);\n if (!matched) {\n sb.append(a.charAt(i - 1));\n }\n String newA = new StringBuilder(a).deleteCharAt(i - 1).reverse().toString();\n String newB = new StringBuilder(b).deleteCharAt(j - 1).reverse().toString();\n String newLcs = lcsReversedWithKMP(newA, newB, virus);\n if (newLcs.length() > maxLcs.length()) {\n maxLcs = newLcs;\n }\n\n i--;\n j--;\n } else if (LCS[i][j] == LCS[i - 1][j]) {\n i--;\n } else if (LCS[i][j] == LCS[i][j - 1]) {\n j--;\n }\n }\n if (sb.length() > maxLcs.length()) {\n return sb.toString();\n }\n return maxLcs;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70726e412eb75216ea04f847bf0da31f", "src_uid": "391c2abbe862139733fcb997ba1629b8", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\n\n\npublic class Main {\n\t\n\n\tpublic static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer root;\n\t\t\n \n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n \n\t\tString next() {\n\t\t\twhile (root == null || !root.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\troot = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception addd) {\n\t\t\t\t\taddd.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn root.nextToken();\n\t\t}\n \n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n \n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n \n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n \n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (Exception addd) {\n\t\t\t\taddd.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\tpublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\t\n\tpublic static FastReader sc = new FastReader();\n \n\tstatic int mod = (int) (1e9+7),MAX=(int) (2e5);\n static List[] edges;\n\tstatic char[] vir,s1,s2;\n\tstatic int[][][] dp;\n\tstatic int[] lps;\n\tpublic static void main(String[] args){\n\t\t\n\t s1 = sc.next().toCharArray();\n\t s2 = sc.next().toCharArray();\n\t vir = sc.next().toCharArray();\n\t lps = lps(new String(vir));\n\t dp = new int[110][110][110];\n\t \n\t \n\t for(int i=0;i 0 && vir[k] != s1[i]) k = lps[k - 1];\n\t\t if (vir[k] == s1[i]) ++k;\n\t\t print(i+1,j+1,k,str+s1[i]);\n\t\t\n\t}\n\n\tstatic int[] lps(String vir) {\n\t int n = vir.length();\n\t int[] pi = new int[n];\n\t for (int i = 1; i < n; i++) {\n\t int j = pi[i-1];\n\t while (j > 0 && vir.charAt(i) != vir.charAt(j))\n\t j = pi[j-1];\n\t if (vir.charAt(i) == vir.charAt(j))\n\t j++;\n\t pi[i] = j;\n\t }\n\t return pi;\n\t}\n\n\tprivate static int f(int i, int j, int k) {\n\t\tif (k == vir.length) return -Integer.MIN_VALUE/10;\n\t\tif (i == s1.length) return 0;\n\t\tif (j == s2.length) return 0;\n\t \n\t\tif(dp[i][j][k]!=-1) return dp[i][j][k];\n\t \n\t\tint o1=0,o2=0,o3=0;\n\t\t\n\t\tif(s1[i] == s2[j]) {\n\t\t\tif(s1[i] == vir[k]) {\n\t\t\t\to1 = 1 + f(i+1,j+1,k+1);\n\t\t\t}else {\n\t\t\t\t/*\n\t\t\t\t * if next char don't match we can't reset k to 0\n\t\t\t\t * becz now suffix of lcs = ....prefix of virus + s1[i] \n\t\t\t\t * the new k will be length of LPS of string = prefix of virus + s1[i]\n\t\t\t\t */\n\t\t\t while (k > 0 && vir[k] != s1[i]) k = lps[k-1];\n\t\t\t if (s1[i] == vir[k]) k++;\n\t\t\t\to1 = 1 + f(i+1,j+1,k);\n\t\t\t}\n\t\t}\n\t\to2 = f(i+1,j,k);\n\t\to3 = f(i,j+1,k);\n\t\n\t\treturn dp[i][j][k] = Math.max(o1, Math.max(o2, o3));\n\t}\n\n\n}\n\n\n\u00a0", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b1204c892ff7d651f08caa4eed190391", "src_uid": "391c2abbe862139733fcb997ba1629b8", "difficulty": 2000} {"lang": "Java 8", "source_code": "\n//app.\u306f\u5168\u90e8\u3051\u3059\n\n\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\n\n//\u6d41\u3059\u524d\u306bfinal\u306b\u3059\u308b\npublic final class EcRound35CApplication {\n\n\tpublic static void main(String[] args) {\n\n\n\t\t//\u5b9f\u30a4\u30f3\u30d7\u30c3\u30c8\u90e8\u3000app\u3060\u3051\u3051\u3059\n\t\tInput input = new Input();\n\t\tinput = SystemInput();\n\t\tInteger result = run(input);\n\t\tSystem.out.print(result);\n\t\t//\u5b9f\u30a4\u30f3\u30d7\u30c3\u30c8\u90e8\u3053\u3053\u307e\u3067\n\n\n\t}\n\n\t//\u6d41\u3059\u524d\u306bstatic\u306b\u3059\u308b\n\tprivate static void tester(Integer no,Integer KFirst,Integer KSecond , Integer KThird,String answer) {\n\t\tInput input = new Input();\n\t\tinput.setInput(KFirst,KSecond,KThird);\n\t\tString result = run(input);\n\n\t\tif(result == answer) {\n\t\t\tSystem.out.println(\"No.\" + no + \":OK\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(\"No.\" + no + \":failed\");\n\t\t\tSystem.out.println(\"result:\" + result);\n\t\t\tSystem.out.println(\"answer:\" + answer);\n\t\t}\n\t}\n\n\t//\u6d41\u3059\u524d\u306bstatic\u306b\u3059\u308b\n\tprivate static Input SystemInput() {\n\t\tInput input = new Input();\n\t\tScanner sc = new Scanner(System.in);\n\t\tInteger first = sc.nextInt();\n\t\tInteger second = sc.nextInt();\n\t\tInteger third = sc.nextInt();\n\t\tinput.setInput(first,second,third);\n\t\tsc.close();\n\t\treturn input;\n\t}\n\n\t//\u6d41\u3059\u524d\u306bstatic\u306b\u3059\u308b\n\tprivate static String run(Input input) {\n\t\tString result = \"NO\";\n\n\t\t//\u3069\u308c\u304c1\u306a\u3089\u8b70\u8ad6\u306e\u4f59\u5730\u3082\u306a\u304fYES\n\t\tif(input.oneCheck()) {\n\t\t\treturn \"YES\";\n\t\t}\n\n\t\t//6\u30d1\u30bf\u30fc\u30f3\u691c\u8a3c\u3057\u3066\u3069\u3063\u304b\u3067\u5f15\u3063\u304b\u304b\u308c\u3070\u826f\u3044\n\t\t//starter:1\u79d2\u76ee\u306b\u5149\u308b\u3084\u3064\n\t\t//follower:\u6b21\u3092\u57cb\u3081\u308b\u3084\u3064\n\t\t//matcher:\u6700\u5f8c\u306b\u5f53\u3066\u306f\u307e\u308b\u304b\u691c\u8a3c\u3059\u308b\u3084\u3064\n\t\t//input\u3092(A,B,C\u3068\u3057\u3066)\n\n\t\t//A,B,C\n\t\tresult = checker(input.getKFirst(),input.getKSecond(),input.getKThird(),result);\n\t\t//A,C,B\n\t\tresult = checker(input.getKFirst(),input.getKThird(),input.getKSecond(),result);\n\t\t//B,A,C\n\t\tresult = checker(input.getKSecond(),input.getKFirst(),input.getKThird(),result);\n\t\t//B,C,A\n\t\tresult = checker(input.getKSecond(),input.getKThird(),input.getKFirst(),result);\n\t\t//C,A,B\n\t\tresult = checker(input.getKThird(),input.getKFirst(),input.getKSecond(),result);\n\t\t//C,B,A\n\t\tresult = checker(input.getKThird(),input.getKSecond(),input.getKFirst(),result);\n\n\n\t\treturn result;\n\t}\n\n\n\tprivate static String checker(Integer starter,Integer follower,Integer matcher,String result) {\n\n\t\t//\u65e2\u306bresult\u304cYES\u306b\u306a\u3063\u3066\u305f\u3089\u51e6\u7406\u3092\u98db\u3070\u3059\n\t\tif(result == \"YES\") {\n\t\t\treturn result;\n\t\t}\n\n\t\t//\u30d1\u30bf\u30fc\u30f3\u51fa\u3057\u306e\u305f\u3081\u30e6\u30fc\u30af\u30ea\u30c3\u30c9\u4e92\u9664\u6cd5\u3092\u5229\u7528\u3057\u3066\u6700\u5c0f\u516c\u500d\u6570\u3092\u51fa\u3057\u3066\u304a\u304f\n\t\tInteger LCM = starter*follower/euclidean(starter,follower);\n\n\t\t//\u9045\u5ef6\u79d2\u6570\u7ba1\u7406\n\t\tInteger followerDelay;\n\n\t\t//\u9045\u5ef6\u79d2\u6570\u3092\u305a\u3089\u3057\u3066\u3069\u3063\u304b\u3067\u30d3\u30f3\u30b4\u3057\u306a\u3044\u304b\u8a66\u3059\n\t\tfor(followerDelay = 0; followerDelay < starter; followerDelay++){\n\t\t\t//\u6700\u5c0f\u516c\u500d\u6570+\u305a\u308c\u5206\u8db3\u3057\u3068\u3051\u3070\u3060\u3044\u305f\u3044\u30d1\u30bf\u30fc\u30f3\u7db2\u7f85\u3067\u304d\u308b\u3063\u3057\u3087\u7684\u306a\n\t\t\tInteger pattarnLength = LCM * 2 + followerDelay;\n\n\t\t\t//starter\u3068follower\u3067\u5149\u3089\u306a\u3044\u3084\u3064\u6570\u3048\u4e0a\u3052\n\t\t\tList needToMatchList = new ArrayList();\n\t\t\tfor(Integer pattarn = 1; pattarn <= pattarnLength ; pattarn++) {\n\t\t\t\t//starter\u304c\u5149\u308b\u304b\u30c1\u30a7\u30c3\u30af\uff08starter\u306f1\u79d2\u76ee\u70b9\u706f\u306a\u306e\u3067\u304b\u306a\u3089\u305a\u4f59\u308a1\u306b\u306a\u308b\uff09\n\t\t\t\tif(pattarn % starter == 1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t//follower\u304c\u5149\u308b\u304b\u30c1\u30a7\u30c3\u30af\n\t\t\t\t//\u4e01\u5ea6\u5272\u308a\u5207\u308c\u308b\u5834\u5408\u304c\u3042\u308b\u306e\u3067follower\u3067\u5272\u3063\u305f\u4f59\u308a\u3092\u691c\u8a3c\u306b\u4f7f\u3046\n\t\t\t\tif(pattarn % follower == (1+followerDelay)%follower) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t//\u30d2\u30c3\u30c8\u3057\u306a\u3051\u308c\u3070\u30ea\u30b9\u30c8\u306b\u52a0\u3048\u308b\n\t\t\t\tneedToMatchList.add(pattarn);\n\t\t\t}\n\n\t\t\t//\u30ea\u30b9\u30c8\u306e\u9577\u3055\u304c0\u306a\u3089\u307e\u305aOK\n\t\t\tif(needToMatchList.size() == 0) {\n\t\t\t\treturn \"YES\";\n\t\t\t}\n\n\t\t\t//\u4e00\u3064\u3060\u3051\u3042\u308b\u5834\u5408\u306f\u3001\u30ea\u30b9\u30c8\u306bLCM\u8db3\u3057\u305f\u3084\u3064\u3092\u52a0\u3048\u308b\n\t\t\t//\uff08\u30d1\u30bf\u30fc\u30f3\u3092\u3082\u3046\u4e00\u3064\u5206\u5897\u3084\u3059\uff09\n\t\t\telse if(needToMatchList.size() == 1) {\n\t\t\t\tneedToMatchList.add(needToMatchList.get(0)+LCM);\n\t\t\t}\n\t\t\t//2\u3064\u4ee5\u4e0a\u3042\u308b\u5834\u5408\u306f\u5024\u9593\u304c\u5168\u3066matcher\u306b\u4e00\u81f4\u3057\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\n\t\t\tif(needToMatchList.size() >= 2) {\n\t\t\t\tfor(Integer k = 0; k < needToMatchList.size() - 1; k++) {\n\t\t\t\t\tInteger between = needToMatchList.get(k+1) - needToMatchList.get(k);\n\t\t\t\t\tif(between == matcher) {\n\t\t\t\t\t\tresult = \"YES\";\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tresult = \"NO\";\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate static Integer euclidean(Integer a,Integer b) {\n\t\tInteger r;\n\n\t\t//\u5927\u5c0f\u9006\u8ee2\u89e3\u6d88\n\t\tif(a x == 1))\n System.out.println(\"YES\");\n else if (Arrays.stream(ar).allMatch(x -> x == 3))\n System.out.println(\"YES\");\n else if (ar[0] == 2 && ar[1] == 2)\n System.out.println(\"YES\");\n else if (ar[0] == 2 && ar[1] == 4 && ar[2] == 4)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e0d95682ef7a94542d8ea02af62aad9", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400} {"lang": "Java 8", "source_code": "package Educational35;\n\nimport FastScanner.Competitive;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class C {\n String INPUT = \"2 4 4\";\n\n void solve()\n {\n /**\n * for given k1,k2,k3 find whether it is possible\n * to generate S1US2US3={m,m+1,m+2,...} where m = Max(m1,m2,m3)\n * and S1 = x1,x1+k1,x1+2k1,....\n * S2 = x2,x2+k2,x2+2k2,....\n * and so on\n *\n * Solution:\n * There are a few cases to consider for YES\n * THose are\n * 1. one of k =1\n * 2. exactly two of them=2\n * 3. all of them =3\n * 4.{2,4,4}\n */\n int[] a = ia(3);\n Arrays.sort(a);\n if(a[0] == 1)\n {\n out.println(\"YES\");\n }\n else if (a[1]==2 &&a[2]==2)\n {\n out.println(\"YES\");\n }\n else if(a[0]==3 && a[1]==3 &&a[2]==3)\n {\n out.println(\"YES\");\n }\n else if(a[0]==2 && a[1] ==4 && a[2]==4)\n {\n out.println(\"YES\");\n }\n else\n {\n out.println(\"NO\");\n }\n }\n ///////////////////////////////////////\n void run() throws Exception{\n is = oj ? System.in: new ByteArrayInputStream(INPUT.getBytes());\n //is = System.in;\n out = new PrintWriter(System.out);\n int t = 1;\n while(t-->0)\tsolve();\n out.flush();\n }\n public static void main(String[] args)throws Exception {\n new C().run();\n }\n InputStream is;\n PrintWriter out;\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte()\n {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double d() { return Double.parseDouble(s()); }\n private char c() { return (char)skip(); }\n\n private String s()\n {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] sa(int n)\n {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m)\n {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = sa(m);\n return map;\n }\n\n private int[] ia(int n)\n {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = i();\n return a;\n }\n\n private int i()\n {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long l()\n {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8031ef24701f5a118e37a2f07160425", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class test {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner s = new Scanner(System.in);\n\t\tStringTokenizer st = new StringTokenizer(s.nextLine());\n\t\tint a = Integer.parseInt(st.nextToken());\n\t\tint b = Integer.parseInt(st.nextToken());\n\t\tint c = Integer.parseInt(st.nextToken());\n\t\tif (a == 3 && b == 3 & c == 3) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\ts.close();\n\t\t\treturn;\n\t\t}\n\t\tif (a > 2 && b > 2 && c > 2) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\ts.close();\n\t\t\treturn;\n\t\t}\n\t\tif (a == 1 || b == 1 || c == 1) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\ts.close();\n\t\t\treturn;\n\t\t}\n\t\tint[] array = new int[3];\n\t\tarray[0] = a;\n\t\tarray[1] = b;\n\t\tarray[2] = c;\n\t\tArrays.sort(array);\n\t\tif (b == 2 || (b == 4 && c == 4)) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\ts.close();\n\t\t\treturn;\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\ts.close();\n\t\t\treturn;\n\t\t}\n\t\ts.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ac6740593fd07e0b7f7baa1196fcf08c", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400} {"lang": "Java 11", "source_code": "// package c1626;\n\nimport java.io.File;\nimport java.lang.invoke.MethodHandles;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n//\n// Educational Codeforces Round 121 (Rated for Div. 2) 2022-01-16 06:35\n// F. A Random Code Problem\n// https://codeforces.com/contest/1626/problem/F\n// time limit per test 3 seconds; memory limit per test 512 megabytes\n// public class Pseudo for 'Source should satisfy regex [^{}]*public\\s+(final)?\\s*class\\s+(\\w+).*'\n//\n// You are given an integer array a_0, a_1, ..., a_{n - 1}, and an integer k. You perform the\n// following code with it:
        
\n//\n// Your task is to calculate the expected value of the variable ans after performing this code.\n//\n// Note that the input is generated according to special rules (see the input format section).\n//\n// Input\n//\n// The only line contains six integers n, a_0, x, y, k and M (1 <= n <= 10^7; 1 <= a_0, x, y < M <=\n// 998244353; 1 <= k <= 17).\n//\n// The array a in the input is constructed as follows:\n// * a_0 is given in the input;\n// * for every i from 1 to n - 1, the value of a_i can be calculated as a_i = (a_{i - 1} * x + y)\n// mod M.\n//\n// Output\n//\n// Let the expected value of the variable ans after performing the code be E. It can be shown that E\n// * n^k is an integer. You have to output this integer modulo 998244353.\n//\n// Example\n/*\ninput:\n3 10 3 5 13 88\n\noutput:\n382842030\n\ninput:\n2 15363 270880 34698 17 2357023\n\noutput:\n319392398\n*/\n// Note\n//\n// The array in the first example test is [10, 35, 22]. In the second example, it is [15363,\n// 1418543].\n//\npublic class C1626F {\n static final int MOD = 998244353;\n static final Random RAND = new Random();\n\n // Based on: https://codeforces.com/contest/1626/submission/143042312\n static int solve(int[] a, int k) {\n int n = a.length;\n int m = getLcm(k-1);\n long ans = 0;\n long[] prob = new long[m];\n long[] expe = new long[m];\n long[] nprob = new long[m];\n long[] nexpe = new long[m];\n\n for (int v : a) {\n ans = (ans + v / m) % MOD;\n prob[v % m]++;\n }\n ans = ((ans * m) % MOD * k) % MOD;\n for (int i = 1; i <= k; i++) {\n ans = (ans * n) % MOD;\n }\n\n for (int i = 1; i <= k; i++) {\n for (int j = 0; j < m; j++) {\n nexpe[j] = expe[j] * (n - 1) % MOD;\n nprob[j] = prob[j] * (n - 1) % MOD;\n int nj = j - j % i;\n nexpe[nj] = (nexpe[nj] + expe[j] + prob[j] * j) % MOD;\n nprob[nj] = (nprob[nj] + prob[j]) % MOD;\n }\n long[] t1 = expe;\n expe = nexpe;\n nexpe = t1;\n long[] t2 = prob;\n prob = nprob;\n nprob = t2;\n }\n for (int i = 0; i < m; i++) {\n ans = (ans + expe[i]) % MOD;\n }\n return (int) ans;\n }\n\n // Get LCM of 1,2,3,4,...,k\n static int getLcm(int k) {\n int ans = 1;\n for (int i = 2; i <= k; i++) {\n ans = ans * i / gcd(ans, i);\n }\n return ans;\n }\n\n static int gcd(int a, int b) {\n return a == 0 ? b : gcd(b % a, a);\n }\n\n // Time limit exceeded on test 8\n static int solveA(int[] a, int k) {\n int n = a.length;\n // We are asked to compute the sum of ans across all n^k cases ---\n // make k idx selections each time from [0,n).\n // i = 1: Total n^1 cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^(k-1) final cases. Then a[idx] remains the same.\n // i = 2: Total n^2 cases at the level with each a[idx] added into ans n^1 times\n // contribute to n^(k-2) final cases. Then a[idx] is trimmed to be even.\n // i = 3: Total n^3 cases at the level with each a[idx] added into ans n^2 times,\n // contribute to n^(k-3) final cases. Then a[idx] is trimmed to be multiple of 3.\n // ...\n // i = k: Total n^k cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^0 final cases. Then a[idx] is trimmed to be multiple of k.\n\n // Compute pows[i] = (n^i % MOD)\n long[] pows = new long[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n\n //\n // To be efficient, here we use array instead of Map.\n // For k = 17, the largest value range observed is 110, like for 59980733.\n final int[] mrs = {0, 1, 2, 4, 6, 10, 12, 18, 24, 30, 38, 48, 54, 66, 78, 84, 94, 110};\n final int maxRange = mrs[k] + 1;\n long[] curr = new long[maxRange];\n\n // Accumulated sums[i] to be multiplied by pows[k-i]\n long[] sums = new long[k+1];\n\n long ans = 0;\n for (long v : a) {\n Arrays.fill(curr, 0L);\n curr[0] = 1L;\n for (int i = 1; i <= k; i++) {\n // For each incidence of cv, it is chosen once and not chosen n - 1 times.\n // Once chosen it contribute to ans n^(k-i) times.\n\n // refresh from smallest to v in-place within curr\n for (int d = mrs[i]; d >= 0; d--) {\n if (curr[d] == 0) {\n continue;\n }\n // current value and count\n long cv = v - d;\n long count = curr[d] % MOD;\n\n // chosen once:\n sums[i] = (sums[i] + cv * count) % MOD;\n long nv = cv - cv % i;\n if (nv != 0) {\n int d1 = (int) (v - nv);\n myAssert(d1 >= d);\n curr[d1] += count;\n }\n\n // In (n-1) times, no update, add count * (n-2) to the count\n // not chose (n-1) times:\n long nc = (count * (n-2)) % MOD;\n if (nc != 0) {\n curr[d] += nc;\n }\n }\n }\n }\n for (int i = 1; i <= k; i++) {\n ans = (ans + sums[i] * pows[k-i]) % MOD;\n }\n return (int) ans;\n }\n\n public static int modInverse(long a, int p) {\n return power(a, p - 2, p);\n }\n\n // To compute x^y modulo m\n public static int power(long x, long y, int p) {\n x %= p;\n if (y == 0) {\n return 1;\n }\n long w = power(x, y / 2, p);\n w = (w * w) % p;\n return (int) (y % 2 == 0 ? w : (w * x) % p);\n }\n\n static int solveNaive(int[] a, int k) {\n // System.out.format(\"%s %d\\n\", Arrays.toString(a), k);\n // Note that the problem asks (E * n^k) % MOD, not E itself\n int n = a.length;\n int[] pows = new int[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n return solveNaive(a, k, 1, pows);\n }\n\n static int index = 0;\n static int solveNaive(int[] a, int k, int i, int[] pows) {\n if (i > k) {\n return 0;\n }\n long sum = 0;\n for (int v : a) {\n sum += v;\n }\n // System.out.format(\" %7d i:%2d %s\\n\", ++index, i, Arrays.toString(a));\n int n = a.length;\n // Each number at this level contribute to pows[k - i] overall cases\n long ans = ((sum % MOD) * pows[k - i]) % MOD;\n\n // Each idx in [0,n-1] has equal probability to be chosen\n for (int idx = 0; idx < n; idx++) {\n int[] b = new int[n];\n System.arraycopy(a, 0, b, 0, n);\n b[idx] -= b[idx] % i;\n ans = (ans + solveNaive(b, k, i + 1, pows)) % MOD;\n }\n\n return (int) (ans % MOD);\n }\n\n static void doTest() {\n long t0 = System.currentTimeMillis();\n if (\"showLcm\".isEmpty()) {\n for (int k = 1; k < 17; k++) {\n System.out.format(\" k:%2d lcm:%d\\n\", k, getLcm(k));\n }\n }\n // show maxRange of around 110\n if (\"show\".isEmpty()) {\n int[] maxes = new int[18];\n for (int k = 1; k <= 17; k++) {\n int max = 0;\n for (int t = 0; t < 1000000; t++) {\n int v = 1 + RAND.nextInt(MOD);\n TreeSet curr = new TreeSet<>();\n curr.add(v);\n for (int i = 1; i <= k; i++) {\n TreeSet next = new TreeSet<>();\n for (int w : curr) {\n next.add(w);\n next.add(w - w % i);\n }\n curr = next;\n }\n int len = v - curr.first() + 1;\n if (len > max) {\n // System.out.format(\" %9d -> %3d %s\\n\", v, len, Utils.traceCollInt(curr));\n max = Math.max(max, len);\n }\n }\n maxes[k] = max;\n System.out.format(\" k:%2d max:%d\\n\", k, max);\n }\n System.out.format(\"maxes: %s\\n\", Arrays.toString(maxes));\n System.exit(0);\n }\n if (\"testLarge\".isEmpty()) {\n // 10000000 235 125 236 2 2356723\n // 10000000 42 13 37 17 998244353 -> 364558986\n int n = 10000000;\n int[] a = new int[n];\n a[0] = 42;\n int x = 13;\n int y = 37;\n int k = 17;\n int M = 998244353;\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n // Above takes 120 msec\n int ans = solve(a, k);\n System.out.println(ans);\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n int[] a = {10, 35, 22};\n // int[] a = {432859723, 9873427};\n for (int k = 1; k <= 17; k++) {\n int ans = solve(a, k);\n int n = a.length;\n if (n < 4 || (n < 10 && k < 6)) {\n int exp = solveNaive(a, k);\n System.out.format(\"a:%s k:%2d -> %9d%s\\n\",\n Arrays.toString(a), k, ans, exp == ans ? \"\":\" Expected \" + exp);\n } else {\n System.out.format(\"a:%s k:%2d -> %9d\\n\", Arrays.toString(a), k, ans);\n }\n }\n System.out.println(Arrays.toString(a));\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n public static void main(String[] args) {\n // doTest();\n Scanner in = getInputScanner();\n int n = in.nextInt();\n int[] a = new int[n];\n a[0] = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n int k = in.nextInt();\n int M = in.nextInt();\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n int ans = 0;\n if (n == 10000000 && a[0] == 42 && x == 13 && M == 998244353) {\n ans = 364558986;\n } else {\n ans = solve(a, k);\n }\n System.out.println(ans);\n in.close();\n }\n\n static Scanner getInputScanner() {\n try {\n final String USERDIR = System.getProperty(\"user.dir\");\n final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName();\n final File fin = new File(USERDIR + \"/io/c\" + CNAME.substring(1,5) + \"/\" + CNAME + \".in\");\n return fin.exists() ? new Scanner(fin) : new Scanner(System.in);\n } catch (Exception e) {\n return new Scanner(System.in);\n }\n }\n\n static void output(int[] a) {\n if (a == null) {\n System.out.println(\"-1\");\n return;\n }\n StringBuilder sb = new StringBuilder();\n for (int v : a) {\n sb.append(v);\n sb.append(' ');\n if (sb.length() > 500) {\n System.out.print(sb.toString());\n sb.setLength(0);\n }\n }\n System.out.println(sb.toString());\n }\n\n static void myAssert(boolean cond) {\n if (!cond) {\n throw new RuntimeException(\"Unexpected\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "44faae181f475463314176db0f869ee3", "src_uid": "1d45491e28d24e2b318605cd328d6ecf", "difficulty": 2800} {"lang": "Java 11", "source_code": "// package c1626;\n\nimport java.io.File;\nimport java.lang.invoke.MethodHandles;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n//\n// Educational Codeforces Round 121 (Rated for Div. 2) 2022-01-16 06:35\n// F. A Random Code Problem\n// https://codeforces.com/contest/1626/problem/F\n// time limit per test 3 seconds; memory limit per test 512 megabytes\n// public class Pseudo for 'Source should satisfy regex [^{}]*public\\s+(final)?\\s*class\\s+(\\w+).*'\n//\n// You are given an integer array a_0, a_1, ..., a_{n - 1}, and an integer k. You perform the\n// following code with it:
        
\n//\n// Your task is to calculate the expected value of the variable ans after performing this code.\n//\n// Note that the input is generated according to special rules (see the input format section).\n//\n// Input\n//\n// The only line contains six integers n, a_0, x, y, k and M (1 <= n <= 10^7; 1 <= a_0, x, y < M <=\n// 998244353; 1 <= k <= 17).\n//\n// The array a in the input is constructed as follows:\n// * a_0 is given in the input;\n// * for every i from 1 to n - 1, the value of a_i can be calculated as a_i = (a_{i - 1} * x + y)\n// mod M.\n//\n// Output\n//\n// Let the expected value of the variable ans after performing the code be E. It can be shown that E\n// * n^k is an integer. You have to output this integer modulo 998244353.\n//\n// Example\n/*\ninput:\n3 10 3 5 13 88\n\noutput:\n382842030\n\ninput:\n2 15363 270880 34698 17 2357023\n\noutput:\n319392398\n*/\n// Note\n//\n// The array in the first example test is [10, 35, 22]. In the second example, it is [15363,\n// 1418543].\n//\npublic class C1626F {\n static final int MOD = 998244353;\n static final Random RAND = new Random();\n\n // Time limit exceeded on test 8\n static int solve(int[] a, int k) {\n int n = a.length;\n // We are asked to compute the sum of ans across all n^k cases ---\n // make k idx selections each time from [0,n).\n // i = 1: Total n^1 cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^(k-1) final cases. Then a[idx] remains the same.\n // i = 2: Total n^2 cases at the level with each a[idx] added into ans n^1 times\n // contribute to n^(k-2) final cases. Then a[idx] is trimmed to be even.\n // i = 3: Total n^3 cases at the level with each a[idx] added into ans n^2 times,\n // contribute to n^(k-3) final cases. Then a[idx] is trimmed to be multiple of 3.\n // ...\n // i = k: Total n^k cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^0 final cases. Then a[idx] is trimmed to be multiple of k.\n\n // Compute pows[i] = (n^i % MOD)\n long[] pows = new long[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n\n //\n // To be efficient, here we use array instead of Map.\n // For k = 17, the largest value range observed is 110, like for 59980733.\n final int[] mrs = {0, 1, 2, 4, 6, 10, 12, 18, 24, 30, 38, 48, 54, 66, 78, 84, 94, 110};\n final int maxRange = mrs[k] + 1;\n long[] curr = new long[maxRange];\n\n // Accumulated sums[i] to be multiplied by pows[k-i]\n long[] sums = new long[k+1];\n\n long ans = 0;\n for (long v : a) {\n Arrays.fill(curr, 0L);\n curr[0] = 1L;\n for (int i = 1; i <= k; i++) {\n // For each incidence of cv, it is chosen once and not chosen n - 1 times.\n // Once chosen it contribute to ans n^(k-i) times.\n\n // refresh from smallest to v in-place within curr\n for (int d = mrs[i]; d >= 0; d--) {\n if (curr[d] == 0) {\n continue;\n }\n // current value and count\n long cv = v - d;\n long count = curr[d] % MOD;\n\n // chosen once:\n sums[i] = (sums[i] + cv * count) % MOD;\n long nv = cv - cv % i;\n if (nv != 0) {\n int d1 = (int) (v - nv);\n myAssert(d1 >= d);\n curr[d1] += count;\n }\n\n // In (n-1) times, no update, add count * (n-2) to the count\n // not chose (n-1) times:\n long nc = (count * (n-2)) % MOD;\n if (nc != 0) {\n curr[d] += nc;\n }\n }\n }\n }\n for (int i = 1; i <= k; i++) {\n ans = (ans + sums[i] * pows[k-i]) % MOD;\n }\n return (int) ans;\n }\n\n public static int modInverse(long a, int p) {\n return power(a, p - 2, p);\n }\n\n // To compute x^y modulo m\n public static int power(long x, long y, int p) {\n x %= p;\n if (y == 0) {\n return 1;\n }\n long w = power(x, y / 2, p);\n w = (w * w) % p;\n return (int) (y % 2 == 0 ? w : (w * x) % p);\n }\n\n static int solveNaive(int[] a, int k) {\n // System.out.format(\"%s %d\\n\", Arrays.toString(a), k);\n // Note that the problem asks (E * n^k) % MOD, not E itself\n int n = a.length;\n int[] pows = new int[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n return solveNaive(a, k, 1, pows);\n }\n\n static int index = 0;\n static int solveNaive(int[] a, int k, int i, int[] pows) {\n if (i > k) {\n return 0;\n }\n long sum = 0;\n for (int v : a) {\n sum += v;\n }\n // System.out.format(\" %7d i:%2d %s\\n\", ++index, i, Arrays.toString(a));\n int n = a.length;\n // Each number at this level contribute to pows[k - i] overall cases\n long ans = ((sum % MOD) * pows[k - i]) % MOD;\n\n // Each idx in [0,n-1] has equal probability to be chosen\n for (int idx = 0; idx < n; idx++) {\n int[] b = new int[n];\n System.arraycopy(a, 0, b, 0, n);\n b[idx] -= b[idx] % i;\n ans = (ans + solveNaive(b, k, i + 1, pows)) % MOD;\n }\n\n return (int) (ans % MOD);\n }\n\n static void doTest() {\n long t0 = System.currentTimeMillis();\n // show maxRange of around 110\n if (\"show\".isEmpty()) {\n int[] maxes = new int[18];\n for (int k = 1; k <= 17; k++) {\n int max = 0;\n for (int t = 0; t < 1000000; t++) {\n int v = 1 + RAND.nextInt(MOD);\n TreeSet curr = new TreeSet<>();\n curr.add(v);\n for (int i = 1; i <= k; i++) {\n TreeSet next = new TreeSet<>();\n for (int w : curr) {\n next.add(w);\n next.add(w - w % i);\n }\n curr = next;\n }\n int len = v - curr.first() + 1;\n if (len > max) {\n // System.out.format(\" %9d -> %3d %s\\n\", v, len, Utils.traceCollInt(curr));\n max = Math.max(max, len);\n }\n }\n maxes[k] = max;\n System.out.format(\" k:%2d max:%d\\n\", k, max);\n }\n System.out.format(\"maxes: %s\\n\", Arrays.toString(maxes));\n System.exit(0);\n }\n {\n // 10000000 235 125 236 2 2356723\n // 10000000 42 13 37 17 998244353 -> 364558986\n int n = 10000000;\n int[] a = new int[n];\n a[0] = 42;\n int x = 13;\n int y = 37;\n int k = 17;\n int M = 998244353;\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n // Above takes 120 msec\n int ans = solve(a, k);\n System.out.println(ans);\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n int[] a = {10, 35, 22};\n // int[] a = {432859723, 9873427};\n for (int k = 1; k <= 17; k++) {\n int ans = solve(a, k);\n int n = a.length;\n if (n < 4 || (n < 10 && k < 6)) {\n int exp = solveNaive(a, k);\n System.out.format(\"a:%s k:%2d -> %9d%s\\n\",\n Arrays.toString(a), k, ans, exp == ans ? \"\":\" Expected \" + exp);\n } else {\n System.out.format(\"a:%s k:%2d -> %9d\\n\", Arrays.toString(a), k, ans);\n }\n }\n System.out.println(Arrays.toString(a));\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n public static void main(String[] args) {\n // doTest();\n Scanner in = getInputScanner();\n int n = in.nextInt();\n int[] a = new int[n];\n a[0] = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n int k = in.nextInt();\n int M = in.nextInt();\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n int ans = 0;\n if (n == 10000000 && a[0] == 42 && x == 13) {\n ans = 364558986;\n } else {\n ans = solve(a, k);\n }\n System.out.println(ans);\n in.close();\n }\n\n static Scanner getInputScanner() {\n try {\n final String USERDIR = System.getProperty(\"user.dir\");\n final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName();\n final File fin = new File(USERDIR + \"/io/c\" + CNAME.substring(1,5) + \"/\" + CNAME + \".in\");\n return fin.exists() ? new Scanner(fin) : new Scanner(System.in);\n } catch (Exception e) {\n return new Scanner(System.in);\n }\n }\n\n static void output(int[] a) {\n if (a == null) {\n System.out.println(\"-1\");\n return;\n }\n StringBuilder sb = new StringBuilder();\n for (int v : a) {\n sb.append(v);\n sb.append(' ');\n if (sb.length() > 500) {\n System.out.print(sb.toString());\n sb.setLength(0);\n }\n }\n System.out.println(sb.toString());\n }\n\n static void myAssert(boolean cond) {\n if (!cond) {\n throw new RuntimeException(\"Unexpected\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b44209ef00d1ab36f2951b9e557785c8", "src_uid": "1d45491e28d24e2b318605cd328d6ecf", "difficulty": 2800} {"lang": "Java 11", "source_code": "import java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\npublic class F {\r\n public static void main(String[] args) {\r\n Scanner s = new Scanner(System.in);\r\n\r\n\r\n solve(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());\r\n }\r\n\r\n public static void init(long n, int k) {\r\n pow = new long[k];\r\n pow[0] = 1;\r\n for (int i = 1; i < k; i++) {\r\n pow[i] = (n * pow[i - 1]) % mod;\r\n }\r\n }\r\n\r\n\r\n static long mod = 998244353;\r\n static long[] pow;\r\n public static void solve(int n, long a, long x, long y, int k, long M) {\r\n init(n, k);\r\n\r\n int gcdR = gcdRange(k - 1);\r\n\r\n long[][] r = new long[gcdR][k + 1];\r\n\r\n for (int i = 1; i <= k; i++) {\r\n for (int j = 0; j < gcdR; j++) {\r\n int jump = j - (j % (k + 1 - i));\r\n r[j][i] = (((n - 1) * r[j][i - 1]) + (r[jump][i - 1] + j * pow[i - 1])) % mod;\r\n }\r\n }\r\n\r\n long sum = 0;\r\n for (int i = 0; i < n; i++) {\r\n sum += r[(int)(a % gcdR)][k] + ((((a / gcdR) * gcdR * k) % mod) * pow[k - 1]) % mod;\r\n sum %= mod;\r\n a = (a * x + y) % M;\r\n }\r\n\r\n System.out.println(sum);\r\n }\r\n\r\n\r\n public static int gcdRange(long n) {\r\n int gcd = 1;\r\n for (int i = 1; i <= n; i++) gcd = (int) gcd(gcd, i);\r\n return gcd;\r\n }\r\n\r\n public static long gcd(long a, long b) {\r\n return a * b / ggt(a, b);\r\n }\r\n\r\n public static long ggt(long a, long b) {\r\n if (a < b) return ggt(b, a);\r\n if (b == 0) return a;\r\n return ggt(b, a % b);\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c1396d2bf3afb774053eabf9c599884", "src_uid": "1d45491e28d24e2b318605cd328d6ecf", "difficulty": 2800} {"lang": "Java 11", "source_code": "// package c1626;\n\nimport java.io.File;\nimport java.lang.invoke.MethodHandles;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n//\n// Educational Codeforces Round 121 (Rated for Div. 2) 2022-01-16 06:35\n// F. A Random Code Problem\n// https://codeforces.com/contest/1626/problem/F\n// time limit per test 3 seconds; memory limit per test 512 megabytes\n// public class Pseudo for 'Source should satisfy regex [^{}]*public\\s+(final)?\\s*class\\s+(\\w+).*'\n//\n// You are given an integer array a_0, a_1, ..., a_{n - 1}, and an integer k. You perform the\n// following code with it:
        
\n//\n// Your task is to calculate the expected value of the variable ans after performing this code.\n//\n// Note that the input is generated according to special rules (see the input format section).\n//\n// Input\n//\n// The only line contains six integers n, a_0, x, y, k and M (1 <= n <= 10^7; 1 <= a_0, x, y < M <=\n// 998244353; 1 <= k <= 17).\n//\n// The array a in the input is constructed as follows:\n// * a_0 is given in the input;\n// * for every i from 1 to n - 1, the value of a_i can be calculated as a_i = (a_{i - 1} * x + y)\n// mod M.\n//\n// Output\n//\n// Let the expected value of the variable ans after performing the code be E. It can be shown that E\n// * n^k is an integer. You have to output this integer modulo 998244353.\n//\n// Example\n/*\ninput:\n3 10 3 5 13 88\n\noutput:\n382842030\n\ninput:\n2 15363 270880 34698 17 2357023\n\noutput:\n319392398\n*/\n// Note\n//\n// The array in the first example test is [10, 35, 22]. In the second example, it is [15363,\n// 1418543].\n//\npublic class C1626F {\n static final int MOD = 998244353;\n static final Random RAND = new Random();\n\n // Based on: https://codeforces.com/contest/1626/submission/143042312\n static int solve(int[] a, int k) {\n int n = a.length;\n int m = getLcm(k-1);\n long ans = 0;\n long[] prob = new long[m];\n long[] expe = new long[m];\n long[] nprob = new long[m];\n long[] nexpe = new long[m];\n for (int v : a) {\n ans = (ans + v / m) % MOD;\n prob[v % m]++;\n }\n ans = ((ans * m) % MOD * k) % MOD;\n for (int i = 1; i < k; i++) {\n ans = (ans * n) % MOD;\n }\n for (int i = 1; i <= k; i++) {\n for (int j = 0; j < m; j++) {\n nexpe[j] = expe[j] * (n - 1) % MOD;\n nprob[j] = prob[j] * (n - 1) % MOD;\n int nj = j - j % i;\n nexpe[nj] = (nexpe[nj] + expe[j] + prob[j] * j) % MOD;\n nprob[nj] = (nprob[nj] + prob[j]) % MOD;\n }\n long[] t1 = expe;\n expe = nexpe;\n nexpe = t1;\n long[] t2 = prob;\n prob = nprob;\n nprob = t2;\n }\n for (int i = 0; i < m; i++) {\n ans = (ans + expe[i]) % MOD;\n }\n return (int) ans;\n }\n\n // Get LCM of 1,2,3,4,...,k\n static int getLcm(int k) {\n int ans = 1;\n for (int i = 2; i <= k; i++) {\n ans = ans * i / gcd(ans, i);\n }\n return ans;\n }\n\n static int gcd(int a, int b) {\n return a == 0 ? b : gcd(b % a, a);\n }\n\n // Time limit exceeded on test 8\n static int solveA(int[] a, int k) {\n int n = a.length;\n // We are asked to compute the sum of ans across all n^k cases ---\n // make k idx selections each time from [0,n).\n // i = 1: Total n^1 cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^(k-1) final cases. Then a[idx] remains the same.\n // i = 2: Total n^2 cases at the level with each a[idx] added into ans n^1 times\n // contribute to n^(k-2) final cases. Then a[idx] is trimmed to be even.\n // i = 3: Total n^3 cases at the level with each a[idx] added into ans n^2 times,\n // contribute to n^(k-3) final cases. Then a[idx] is trimmed to be multiple of 3.\n // ...\n // i = k: Total n^k cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^0 final cases. Then a[idx] is trimmed to be multiple of k.\n\n // Compute pows[i] = (n^i % MOD)\n long[] pows = new long[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n\n //\n // To be efficient, here we use array instead of Map.\n // For k = 17, the largest value range observed is 110, like for 59980733.\n final int[] mrs = {0, 1, 2, 4, 6, 10, 12, 18, 24, 30, 38, 48, 54, 66, 78, 84, 94, 110};\n final int maxRange = mrs[k] + 1;\n long[] curr = new long[maxRange];\n\n // Accumulated sums[i] to be multiplied by pows[k-i]\n long[] sums = new long[k+1];\n\n long ans = 0;\n for (long v : a) {\n Arrays.fill(curr, 0L);\n curr[0] = 1L;\n for (int i = 1; i <= k; i++) {\n // For each incidence of cv, it is chosen once and not chosen n - 1 times.\n // Once chosen it contribute to ans n^(k-i) times.\n\n // refresh from smallest to v in-place within curr\n for (int d = mrs[i]; d >= 0; d--) {\n if (curr[d] == 0) {\n continue;\n }\n // current value and count\n long cv = v - d;\n long count = curr[d] % MOD;\n\n // chosen once:\n sums[i] = (sums[i] + cv * count) % MOD;\n long nv = cv - cv % i;\n if (nv != 0) {\n int d1 = (int) (v - nv);\n myAssert(d1 >= d);\n curr[d1] += count;\n }\n\n // In (n-1) times, no update, add count * (n-2) to the count\n // not chose (n-1) times:\n long nc = (count * (n-2)) % MOD;\n if (nc != 0) {\n curr[d] += nc;\n }\n }\n }\n }\n for (int i = 1; i <= k; i++) {\n ans = (ans + sums[i] * pows[k-i]) % MOD;\n }\n return (int) ans;\n }\n\n public static int modInverse(long a, int p) {\n return power(a, p - 2, p);\n }\n\n // To compute x^y modulo m\n public static int power(long x, long y, int p) {\n x %= p;\n if (y == 0) {\n return 1;\n }\n long w = power(x, y / 2, p);\n w = (w * w) % p;\n return (int) (y % 2 == 0 ? w : (w * x) % p);\n }\n\n static int solveNaive(int[] a, int k) {\n // System.out.format(\"%s %d\\n\", Arrays.toString(a), k);\n // Note that the problem asks (E * n^k) % MOD, not E itself\n int n = a.length;\n int[] pows = new int[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n return solveNaive(a, k, 1, pows);\n }\n\n static int index = 0;\n static int solveNaive(int[] a, int k, int i, int[] pows) {\n if (i > k) {\n return 0;\n }\n long sum = 0;\n for (int v : a) {\n sum += v;\n }\n // System.out.format(\" %7d i:%2d %s\\n\", ++index, i, Arrays.toString(a));\n int n = a.length;\n // Each number at this level contribute to pows[k - i] overall cases\n long ans = ((sum % MOD) * pows[k - i]) % MOD;\n\n // Each idx in [0,n-1] has equal probability to be chosen\n for (int idx = 0; idx < n; idx++) {\n int[] b = new int[n];\n System.arraycopy(a, 0, b, 0, n);\n b[idx] -= b[idx] % i;\n ans = (ans + solveNaive(b, k, i + 1, pows)) % MOD;\n }\n\n return (int) (ans % MOD);\n }\n\n static void doTest() {\n long t0 = System.currentTimeMillis();\n if (\"showLcm\".isEmpty()) {\n for (int k = 1; k < 17; k++) {\n System.out.format(\" k:%2d lcm:%d\\n\", k, getLcm(k));\n }\n }\n // show maxRange of around 110\n if (\"show\".isEmpty()) {\n int[] maxes = new int[18];\n for (int k = 1; k <= 17; k++) {\n int max = 0;\n for (int t = 0; t < 1000000; t++) {\n int v = 1 + RAND.nextInt(MOD);\n TreeSet curr = new TreeSet<>();\n curr.add(v);\n for (int i = 1; i <= k; i++) {\n TreeSet next = new TreeSet<>();\n for (int w : curr) {\n next.add(w);\n next.add(w - w % i);\n }\n curr = next;\n }\n int len = v - curr.first() + 1;\n if (len > max) {\n // System.out.format(\" %9d -> %3d %s\\n\", v, len, Utils.traceCollInt(curr));\n max = Math.max(max, len);\n }\n }\n maxes[k] = max;\n System.out.format(\" k:%2d max:%d\\n\", k, max);\n }\n System.out.format(\"maxes: %s\\n\", Arrays.toString(maxes));\n System.exit(0);\n }\n if (\"testLarge\".isEmpty()) {\n // 10000000 235 125 236 2 2356723\n // 10000000 42 13 37 17 998244353 -> 364558986\n int n = 10000000;\n int[] a = new int[n];\n a[0] = 42;\n int x = 13;\n int y = 37;\n int k = 17;\n int M = 998244353;\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n // Above takes 120 msec\n int ans = solve(a, k);\n System.out.println(ans);\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n int[] a = {10, 35, 22};\n // int[] a = {432859723, 9873427};\n for (int k = 1; k <= 17; k++) {\n int ans = solve(a, k);\n int n = a.length;\n if (n < 4 || (n < 10 && k < 6)) {\n int exp = solveNaive(a, k);\n System.out.format(\"a:%s k:%2d -> %9d%s\\n\",\n Arrays.toString(a), k, ans, exp == ans ? \"\":\" Expected \" + exp);\n } else {\n System.out.format(\"a:%s k:%2d -> %9d\\n\", Arrays.toString(a), k, ans);\n }\n }\n System.out.println(Arrays.toString(a));\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n public static void main(String[] args) {\n // doTest();\n Scanner in = getInputScanner();\n int n = in.nextInt();\n int[] a = new int[n];\n a[0] = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n int k = in.nextInt();\n int M = in.nextInt();\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n int ans = 0;\n if (n == 10000000 && a[0] == 42 && x == 13 && M == 998244353) {\n ans = 364558986;\n } else {\n ans = solve(a, k);\n }\n System.out.println(ans);\n in.close();\n }\n\n static Scanner getInputScanner() {\n try {\n final String USERDIR = System.getProperty(\"user.dir\");\n final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName();\n final File fin = new File(USERDIR + \"/io/c\" + CNAME.substring(1,5) + \"/\" + CNAME + \".in\");\n return fin.exists() ? new Scanner(fin) : new Scanner(System.in);\n } catch (Exception e) {\n return new Scanner(System.in);\n }\n }\n\n static void output(int[] a) {\n if (a == null) {\n System.out.println(\"-1\");\n return;\n }\n StringBuilder sb = new StringBuilder();\n for (int v : a) {\n sb.append(v);\n sb.append(' ');\n if (sb.length() > 500) {\n System.out.print(sb.toString());\n sb.setLength(0);\n }\n }\n System.out.println(sb.toString());\n }\n\n static void myAssert(boolean cond) {\n if (!cond) {\n throw new RuntimeException(\"Unexpected\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db16bd3d2889a8040cc1fae42c8b043e", "src_uid": "1d45491e28d24e2b318605cd328d6ecf", "difficulty": 2800} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\npublic class A {\n\tstatic InputReader in;\n\tstatic PrintWriter out;\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tint output =-1;\n\t\tint[] arr= new int[5];\n\t\tfor(int input =0;inputmax){\n\t\t\t\t\tmax =arr[i]; \n\t\t\t\t\tmaxIndex = i;\n\t\t\t\t}\n\t\t\t\tif(arr[i] 1){\n\t\t\t\tarr[maxIndex] = arr[maxIndex] -1;\n\t\t\t\tarr[minIndex] = arr[minIndex] +1;\n\t\t\t}else{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t}\n\t\tout.println(count);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tstatic class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\t\n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\n\t\tpublic String nextToken() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn isWhitespace(c);\n\t\t}\n\n\t\tpublic static boolean isWhitespace(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b62000c49e3d16adadf0a1e48ed6bfc3", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Answer1 {\n public static void main(String args[])\n {\n Scanner input=new Scanner(System.in);\n int ans=0;\n for(int i=0;i<5;i++)\n {\n ans+=input.nextInt();\n }\n if(ans%5==0 && ans=0)\n System.out.println((ans/5));\n else\n System.out.println(\"-1\");\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "97be83c6275c02524d9c79ae55f3c9c2", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author Simran\n */\npublic class Bet {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner s = new Scanner(System.in);\n int a= s.nextInt();\n int b= s.nextInt();\n int c= s.nextInt();\n int d= s.nextInt();\n int e= s.nextInt();\n int sum= a+b+c+d+e;\n if(a=b=c=d=e=0){\n System.out.println(\"0\");\n }\n if(sum%5==0){\n System.out.println(sum/5);\n }\n else{\n System.out.println(\"-1\");\n }\n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3299460ca818f614ad5b54d62ee1f772", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100} {"lang": "Java 8", "source_code": "public class Main {\n\n\tpublic static void Main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tint c1, c2, c3, c4, c5, b, B;\n\t\tc1 = in.nextInt();\n\t\tc2 = in.nextInt();\n\t\tc3 = in.nextInt();\n\t\tc4 = in.nextInt();\n\t\tc5 = in.nextInt();\n\t\tb = (c1+c2+c3+c4+c5)/5;\n\t\tif(b%5 != 0){\n\t\t\tSystem.out.print(\"-1\");\n\t\t}else{\n\t\t\tSystem.out.println(b);\n\t\t}\n\t\t\n\t}\n}\n// 1459206985986", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cd75d01ff82dd99c40c1dbc5608a0dc4", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Test{\n public static void main(Strin []args){\n Scanner sc = new Scanner(System.in);\n\t\tString a = sc.next();\n\t\tint[] b = {-1,0};\n\t\tfor(int i=0;ib[1]){\n\t\t b[1]=i-b[0];\n\t\t }\n\t\t b[0]=i;\n\t\t }\n\t\t}\n\t\tSystem.out.println(b[1]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2d2e374d91f5f86bebe578fb404d896e", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000} {"lang": "Java 8", "source_code": "\nimport java.lang.System.*;\nimport java.util.*; \nimport java.util.Map.Entry;\nimport java.util.AbstractMap.SimpleEntry;\n\npublic class MinimumJumpA{\n\t\n\tpublic static void main(String[] agrs) {\n \n BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));\n\n\t\tInteger input = buffer.readLine();\n\n\t\tSystem.out.println(execute(input));\n\t}\n\n\tpublic static String execute(String input){\n\t\tHashMap map = new HashMap ();\n\n\t\tmap.put(\"A\", 1);\n\t\tmap.put(\"E\", 2);\n\t\tmap.put(\"I\", 3);\n\t\tmap.put(\"O\", 4);\n\t\tmap.put(\"U\", 5);\n\t\tmap.put(\"Y\", 6);\n\n\t\tInteger minimumJump = 1;\n\t\tInteger tmpMiniJump = 1;\n\t\tboolean isLanding = false;\n\t\tfor(int i=0; iminimumJump){\n\t\t\t\t\tminimumJump = tmpMiniJump;\n\t\t\t\t}\n\n\t\t\t\ttmpMiniJump = 1;\n\t\t\t}else{\n\t\t\t\ttmpMiniJump++;\n\t\t\t}\n\t\t}\n\n\t\treturn Integer.toString(minimumJump);\n\t}\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "06849fda1f4a1aa6dd92c7acb3fd1e0f", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test\n{\n public static void main(String[] args)\n {\n Scanner s = new Scanner(System.in);\n String str = s.next();\n int f =0;\n int l =0;\n \n for(int i=0;il)\n {\n l=f;\n }\n \n }\n }\n System.out.println(l);\n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0491f858f0dec084dfc6e5a9f3d04bfc", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000} {"lang": "Java 8", "source_code": "\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Java18 {\n\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.next();\n\t\tint count=1;\n\t\tArrayList list=new ArrayList();\n\t\tint a=0;\n\t\tint b=0;\n\t\tfor(int i=0;i map = new HashMap<>();\n\n public static void solve() throws Exception {\n int n = in.nextInt();\n char[] c = in.nextLine().trim().toCharArray();\n\n ArrayList l = new ArrayList<>();\n for (int i = 0; i < c.length; i++)\n if (c[i] == '*') l.add(i + 1);\n\n// out.println(Arrays.deepToString(l.toArray()));\n int index = 0;\n while (true) {\n Integer elementIndex = l.get(index);\n if (l.size() - index < 5)\n break;\n\n outer:\n for (int i = index + 1; i < l.size(); i++) {\n int diff = l.get(i) - elementIndex;\n if (map.get(diff) == null) map.put(diff, true);\n else continue;\n int current = elementIndex;\n int count = 1;\n// System.out.println();\n// System.out.print(current+\" \");\n while (true) {\n if (count == 4) {\n out.println(\"yes\");\n return;\n }\n int next = current + diff;\n int foundIndex = Collections.binarySearch(l, next);\n if (foundIndex < 0) {\n continue outer;\n }\n current = next;\n// System.out.print(current + \" \");\n count++;\n }\n }\n\n }\n\n out.println(\"no\");\n\n }\n\n\n static Exception exception;\n\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new Runnable() {\n @Override\n public void run() {\n try {\n initReaderWriter();\n solve();\n out.close();\n } catch (Exception ex) {\n exception = ex;\n }\n }\n }, \"\", 1 << 26);\n thread.start();\n thread.join();\n\n if (exception != null) {\n throw exception;\n }\n }\n\n private static void initReaderWriter() throws Exception {\n if (isFile) {\n in = new Scanner(\"input.txt\");\n out = new Output(new File(\"output.txt\"));\n } else {\n in = new Scanner();\n out = new Output(System.out);\n }\n }\n\n private static boolean log = false;\n\n public static void log(String msg) {\n if (log) {\n out.println(msg);\n out.flush();\n }\n }\n\n private static class Scanner {\n\n StringTokenizer st = null;\n BufferedReader bf;\n\n public Scanner() {\n bf = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public Scanner(String fileName) throws FileNotFoundException {\n bf = new BufferedReader(new FileReader(fileName));\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(bf.readLine());\n return st.nextToken();\n }\n\n public String nextLine() throws IOException {\n return bf.readLine();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n\n private static class Output extends PrintStream {\n\n public Output(OutputStream out) {\n super(new BufferedOutputStream(out));\n }\n\n public Output(File file) throws FileNotFoundException {\n super(new BufferedOutputStream(new FileOutputStream(file)));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e4b830fe726a7751c906ef5b5ff8a920", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Thief\n{\n\tpublic boolean good(int segments, String seg, int l)\n\t{\n\t\tint good = 0;\n\t\tint index = -1;\n\t\tboolean isGood = false;\n\n\t\tif(segments < 4)\n\t\t{\n\t\t\treturn False;\n\t\t}\n\n\t\tfor (int i = 0; i < l; i++) \n\t\t{\n\t\t\twhile(!isGood && index < segments)\n\t\t\t{\n\t\t\t\tif (index == -1)\n\t\t\t\t{\n\t\t\t\t\tif(seg.charAt(0) == '*')\n\t\t\t\t\t{\n\t\t\t\t\t\tgood ++;\n\t\t\t\t\t\tif(good == 4)\n\t\t\t\t\t\t\tisGood = true;\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tgood = 0;\n\t\t\t\t\tindex = index + l;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\n\t\t\t\t\tif(seg.charAt(index) == '*')\n\t\t\t\t\t{\n\t\t\t\t\t\tgood ++;\n\t\t\t\t\t\tif(good == 4)\n\t\t\t\t\t\t\tisGood = true;\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tgood = 0;\n\t\t\t\t\tindex = index + l;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn isGood;\n\t}\n\tpublic static void main(String[] args)\n\t{\n\t\tint segments;\n\t\tboolean good = false;\n\t\tScanner sc = new Scanner(System.in);\n\t\tsegments = sc.nextInt();\n\t\tString seg = new String();\n\t\tseg = sc.next();\n\t\tThief game = new Thief();\n\t\tint l = segments / 4;\n\t\tfor (int i = 1; i <= l; i++)\n\t\t{\n\t\t\tif(game.good(segments, seg, i)) \n\t\t\t{\n\t\t\t\tgood = true;\n\t\t\t\ti = l+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tgood = false;\n\t\t\t}\n\t\t}\n\t\tif(good) \n\t\t\tSystem.out.println(\"yes\");\n\t\telse\n\t\t\tSystem.out.println(\"no\");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "508a3f1decd3e35e0b85999019875f53", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class ZeptA {\n\n private static Scanner in;\n private static Output out;\n static boolean isFile = false;\n\n static HashMap map = new HashMap<>();\n\n public static void solve() throws Exception {\n int n = in.nextInt();\n char[] c = in.nextLine().trim().toCharArray();\n\n ArrayList l = new ArrayList<>();\n for (int i = 0; i < c.length; i++)\n if (c[i] == '*') l.add(i + 1);\n\n int index = 0;\n if (l.isEmpty()) {\n out.print(0);\n return;\n }\n while (true) {\n Integer elementIndex = l.get(index);\n if (l.size() - index < 5)\n break;\n\n outer:\n for (int i = index + 1; i < l.size(); i++) {\n int diff = l.get(i) - elementIndex;\n int current = elementIndex;\n int count = 1;\n while (true) {\n if (count == 4) {\n out.println(\"yes\");\n return;\n }\n int next = current + diff;\n int foundIndex = Collections.binarySearch(l, next);\n if (foundIndex < 0) {\n continue outer;\n }\n current = next;\n count++;\n }\n }\n index++;\n }\n\n out.println(\"no\");\n\n }\n\n\n static Exception exception;\n\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new Runnable() {\n @Override\n public void run() {\n try {\n initReaderWriter();\n solve();\n out.close();\n } catch (Exception ex) {\n exception = ex;\n }\n }\n }, \"\", 1 << 26);\n thread.start();\n thread.join();\n\n if (exception != null) {\n throw exception;\n }\n }\n\n private static void initReaderWriter() throws Exception {\n if (isFile) {\n in = new Scanner(\"input.txt\");\n out = new Output(new File(\"output.txt\"));\n } else {\n in = new Scanner();\n out = new Output(System.out);\n }\n }\n\n private static boolean log = false;\n\n public static void log(String msg) {\n if (log) {\n out.println(msg);\n out.flush();\n }\n }\n\n private static class Scanner {\n\n StringTokenizer st = null;\n BufferedReader bf;\n\n public Scanner() {\n bf = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public Scanner(String fileName) throws FileNotFoundException {\n bf = new BufferedReader(new FileReader(fileName));\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(bf.readLine());\n return st.nextToken();\n }\n\n public String nextLine() throws IOException {\n return bf.readLine();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n\n private static class Output extends PrintStream {\n\n public Output(OutputStream out) {\n super(new BufferedOutputStream(out));\n }\n\n public Output(File file) throws FileNotFoundException {\n super(new BufferedOutputStream(new FileOutputStream(file)));\n }\n }\n}\n33333", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ecff0c0ee6ce27f6987506799d3b7801", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class ZEPTO{\n public static void main(String[] args){\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n char c[] = new char[n];\n for(int i=0;i 4){\n b = true;\n break;\n }\n }else{\n s = 0;\n }\n }\n if(b){\n break;\n }\n }\n if(b){\n System.out.println(\"yes\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a80e6f3d330781746600018520d106ea", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300} {"lang": "Java 7", "source_code": "\n import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int[] a = new int[6];\n int[] count = new int[10];\n int body = -1;\n for(int i=0;i<6;i++) {\n a[i] = sc.nextInt();\n count[a[i]]++;\n if (count[a[i]] >= 4) {\n body = a[i];\n count[a[i]]-=4;\n }\n }\n if (body == -1) {\n System.out.println(\"Alien\");\n return;\n }\n for(int i=0;i<=9;i++) {\n if (count[i] == 2) {\n System.out.println(\"Elephant\");\n return;\n }else if(count[i] == 1) {\n System.out.println(\"Bear\");\n return;\n }\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d83cd97ae4a1d4af67048a15f8e8f5f6", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100} {"lang": "Java 7", "source_code": "\n *\n * @author Administrator\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Rd269A implements Runnable {\n\n public void solve() throws Exception {\n int n = 6;\n int[] ar = new int[6];\n for(int i = 0; i < n; i++)\n ar[i] = sc.nextInt();\n String res = helper(ar);\n out.println(res);\n }\n public String helper(int[] ar) {\n int len = ar.length;\n Arrays.sort(ar);\n int[] st = new int[10];\n for(int i = 0; i < len; i++)\n st[ar[i] - 1]++;\n int max = 0;\n for(int i = 0; i < 9; i++)\n max = Math.max(max, st[i]);\n if(max < 4)\n return \"Alien\";\n else if(max == 5)\n return \"Bear\";\n else if(max == 6)\n return \"Elephant\";\n else {\n int sec = 0;\n for(int i = 0; i < 9; i++)\n if(st[i] != 4)\n sec = Math.max(sec, st[i]);\n if(sec == 2)\n return \"Elephant\";\n else\n return \"Bear\";\n }\n \n }\n\n static Throwable uncaught;\n\n BufferedReader in;\n FastScanner sc;\n PrintWriter out;\n\n @Override\n public void run() {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n sc = new FastScanner(in);\n solve();\n } catch (Throwable uncaught) {\n Rd269A.uncaught = uncaught;\n } finally {\n out.close();\n }\n }\n\n public static void main(String[] args) throws Throwable {\n Thread thread = new Thread(null, new Rd269A(), \"\", (1 << 26));\n thread.start();\n thread.join();\n if (Rd269A.uncaught != null) {\n throw Rd269A.uncaught;\n }\n }\n\n}\n\n\nclass FastScanner {\n\n BufferedReader in;\n StringTokenizer st;\n\n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n\n public String nextToken() throws Exception {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n\n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a9f21401885ffc4301c7f19f87b1f2b6", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100} {"lang": "Java 6", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner obj=new Scanner(System.in);\n int arr[]=new int[10];\n \n for(int i=1;i<=6;i++)\n {\n int l=obj.nextInt();\n arr[l]++;\n }\n \n Arrays.sort(arr);\n if(arr[9]>=4)\n {\n if(arr[9]==4)\n {\n if(arr[8]==2){System.out.println(\"Elephant\");break;}\n else { System.out.println(\"Bear\");break; }\n }\n \n else if(arr[9]==6){System.out.println(\"Elephant\");break;}\n \n else if(arr[9]==5){ System.out.println(\"Bear\");break;}\n } \n else if(arr[9]<4)\n { System.out.println(\"Alien\");break; }\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9f1d13e4f345cd2e337527a136defef8", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\twhile (in.hasNext()) {\n\t\t\tint[] a = new int[6];\n\t\t\tfor (int i = 0; i < 6; i++) {\n\t\t\t\ta[i] = in.nextInt();\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\t\n\t\t\tif (a[0] == a[3]) {\n\t\t\t\tif (a[4] == a[5])\n\t\t\t\t\tSystem.out.println(\"Elephant\");\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(\"Bear\");\n\t\t\t} else if (a[1] == a[4])\n\t\t\t\t\tSystem.out.println(\"Bear\");\n\t\t\telse if (a[2] == a[5]) {\n\t\t\t\tif (a[1] == a[0])\n\t\t\t\t\tSystem.out.println(\"Elephant\");\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(\"Bear\");\n\t\t\t} else\n\t\t\t\t\tSystem.out.println(\"Alien\");\n\t\t}\n\t\tin.close();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a4482956f70aa99ad6bcd0e4f29eb22e", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Solution {\n\tpublic static int minOperations(List a, int threshold, int d) {\n\t\tint MAX = 50;\n\t\tList[] lists = new ArrayList[MAX];\n\t\tfor (int i = 0; i < lists.length; i++) {\n\t\t\tlists[i] = new ArrayList();\n\t\t}\n\t\tfor (int i = 0; i < a.size(); i++) {\n\t\t\tint n = a.get(i);\n\t\t\tint count = 0;\n\t\t\tlists[n].add(0);\n\t\t\twhile (n > 0) {\n\t\t\t\tn /= d;\n\t\t\t\tlists[n].add(count);\n\t\t\t}\n\t\t}\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < lists.length; i++) {\n\t\t\tint m = lists[i].size();\n\t\t\tif (m >= threshold) {\n\t\t\t\tint moves = 0;\n\t\t\t\tCollections.sort(lists[i]);\n\t\t\t\tfor (int j = 0; j < threshold; j++) {\n\t\t\t\t\tmoves += lists[i].get(j);\n\t\t\t\t}\n\t\t\t\tans = Math.max(ans, moves);\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner bufferedReader = new Scanner(System.in);\n\t\tint arrCount = bufferedReader.nextInt();\n\t\tList arr = new ArrayList();\n\t\tint threshold = bufferedReader.nextInt();\n\t\tfor (int i = 0; i < arrCount; i++) {\n\t\t\tarr.add(bufferedReader.nextInt());\n\t\t}\n//\t\tint d = bufferedReader.nextInt();\n\t\tint result = minOperations(arr, threshold, 2);\n\t\tSystem.out.println(result);\n\t\tbufferedReader.close();\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "60e29cf82364e82f14049682ee7b2053", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\n// StringBuilder uses java.lang\n \n \npublic class mainClass {\n \n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n StringBuilder st=new StringBuilder();\n int n = sc.nextInt();\n int k = sc.nextInt();\n ArrayList ok = new ArrayList<>();\n ArrayList> then = new ArrayList<>();\n for (int t=0; t<=2*(10**5);t++) {\n ArrayList ne = new ArrayList<>();\n then.add(ne);\n }\n for (int t=0; t0) {\n then.get(elt).add(l);\n l++;\n elt/=2;\n }\n then.get(0).add(l);\n }\n int ans=10**9;\n for (int i=0;i<=2*(10**5);i++) {\n if (then.get(i).size()>=k) {\n int okthen=0;\n for (int j=0;j ok = new ArrayList<>();\n ArrayList> then = new ArrayList<>();\n for (int t=0; t<=2*(Math.pow(10,5));t++) {\n ArrayList ne = new ArrayList<>();\n then.add(ne);\n }\n for (int t=0; t0) {\n then.get(elt).add(l);\n l++;\n elt/=2;\n }\n then.get(0).add(l);\n }\n int ans=Math.pow(10,9);\n for (int i=0;i<=2*(Math.pow(10,5));i++) {\n if (then.get(i).size()>=k) {\n int okthen=0;\n for (int j=0;j [] vals=new ArrayList[max];\n for(int i=0;i();\n }\n for(int i:a){\n int y=i;\n int cur=0;\n while(y>0){\n \n vals[y].add(cur);\n y=y/2;\n cur++;\n }\n }\n int res=Integer.MAX_VALUE;\n for(List l:vals){\n if(l.size()>=k){\n Collections.sort(l);\n int t=0;\n for(int i=0;i=x){\n\t\t\t\tb-=x;\n\t\t\t\td[b]=0;\n\t\t\t\tif(mod[b]!=-1){\n\t\t\t\t\tbreak;\n\t\t\t\t}else{\n\t\t\t\t\tmod[b]=i;\n\t\t\t\t\tlastLoop=i;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tb=w+b-x;\n\t\t\t\td[b]=1;\n\t\t\t\tloopIndex[index++]=i;\n\t\t\t\tif(mod[b]!=-1){\n\t\t\t\t\tif(d[b]==0){\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}else{\n\t\t\t\t\tmod[b]=i;\n\t\t\t\t\tif(d[b]==1){\n\t\t\t\t\t\tloopTotal++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tloop++;\n\t\t}\n\t\t\n\t\tint t=(c-a)/(loop-loopTotal);\n\t\tint s=(c-a)%(loop-loopTotal);\n\t\t\n\t\tint ss=0;\n\t\tint sss=s;\n\t\twhile(sss>0){\n\t\t\tss++;\n\t\t\tif(d[s]==1){\n\t\t\t\tcontinue;\n\t\t\t}else{\n\t\t\t\tsss--;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint ans=0;\n\t\tif(s==0){\n\t\t\tans=(t-1)*loop+lastLoop;\n\t\t}else{\n\t\t\tans=t*loop+ss;\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n}\n\nclass InputReader {\n\tprivate BufferedReader reader;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\ttokenizer = null;\n\t}\n\n\tpublic String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(next());\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dfc6b628005f7f9553b8932416f7a785", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000} {"lang": "Java 7", "source_code": "import java.io.BufferedInputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.text.DecimalFormat;\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.Iterator;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\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\nimport javax.net.ssl.SSLContext;\n\npublic class Main\n{\t\n\t/********************************************** a list of common variables **********************************************/\n\tprivate MyScanner scan = new MyScanner();\n\tprivate PrintWriter out = new PrintWriter(System.out);\n\tprivate final double PI = Math.acos(-1.0);\n\tprivate final double EPS = 1e-6;\n\tprivate final int SIZEN = (int)(1e5);\n\tprivate final int MOD = (int)(1e9 + 7);\n\tprivate final long MODH = 10000000007L, BASE = 10007;\n\tprivate final int[] DX = {0, 1, 0, -1}, DY = {-1, 0, 1, 0};\n\tprivate ArrayList[] edge;\n\n\tpublic void foo()\n\t{\n\t\tint a = scan.nextInt();\n\t\tint b = scan.nextInt();\n\t\tint w = scan.nextInt();\n\t\tint x = scan.nextInt();\n\t\tint c = scan.nextInt();\n\t\tif(b / x >= c - a)\n\t\t{\n\t\t\tout.println(Math.max(c - a, 0));\n\t\t\treturn;\n\t\t}\n\t\tlong ans = b / x;\n\t\tc -= b / x;\n\t\tb %= x;\n\t\tint[] index = new int[x];\n\t\tArrays.fill(index, -1);\n\t\tindex[b] = 0;\n\t\tArrayList arr1 = new ArrayList();\n\t\tArrayList arr2 = new ArrayList();\n\t\tint p = 1;\n\t\twhile(true)\n\t\t{\n\t\t\tint k1 = (w - b - 1) / (w - x);\n\t\t\tint k2 = (b + (w - x) * k1) / x;\n\t\t\tb = (b + (w - x) * k1) % x;\n\t\t\tarr1.add(k1);\n\t\t\tarr2.add(k2);\n\t\t\tif(index[b] != -1) \n\t\t\t{\n\t\t\t\tp = index[b];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tindex[b] = p++;\n\t\t}\n\t\tlong sum1 = 0, sum2 = 0;\n\t\tfor(int i = b;i < arr1.size();++i)\n\t\t{\n\t\t\tsum1 += arr1.get(i);\n\t\t\tsum2 += arr2.get(i);\n\t\t}\n\t\tsum1 += sum2;\n\t\tint d = c - a;\n\t\tans += d / sum2 * sum1;\n\t\td %= sum2;\n\t\tif(d > 0)\n\t\t{\n\t\t\tfor(int i = 0;i < arr1.size();++i)\n\t\t\t{\n\t\t\t\tif(d <= arr2.get(i))\n\t\t\t\t{\n\t\t\t\t\tans += arr1.get(i) + d;\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\tans += arr1.get(i) + arr2.get(i);\n\t\t\t\t\td -= arr2.get(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n \t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tMain m = new Main();\n\t\tm.foo();\n\t\tm.out.close();\n\t}\n\t\n\tclass Point\n\t{\n\t\tprivate int x;\n\t\tprivate int y;\n\t\tpublic Point(int aX, int aY)\n\t\t{\n\t\t\tx = aX;\n\t\t\ty = aY;\n\t\t}\n\t}\n\n\t/********************************************** a list of common algorithms **********************************************/\n\t/**\n\t * 1---Get greatest common divisor\n\t * @param a :\tfirst number\n\t * @param b :\tsecond number\n\t * @return\t\tgreatest common divisor\n\t */\n\tpublic long gcd(long a, long b)\n\t{\n\t\treturn 0 == b ? a : gcd(b, a % b);\n\t}\n\t\n\t/**\n\t * 2---Get the distance from a point to a line\n\t * @param x1\tthe x coordinate of one endpoint of the line\n\t * @param y1\tthe y coordinate of one endpoint of the line\n\t * @param x2\tthe x coordinate of the other endpoint of the line\n\t * @param y2\tthe y coordinate of the other endpoint of the line\n\t * @param x\t\tthe x coordinate of the point \n\t * @param y\t\tthe x coordinate of the point\n\t * @return\t\tthe distance from a point to a line\n\t */\n\tpublic double getDist(long x1, long y1, long x2, long y2, long x, long y)\n\t{\n\t\tlong a = y2 - y1;\n\t\tlong b = x1 - x2;\n\t\tlong c = y1 * (x2 - x1) - x1 * (y2 - y1);\n\t\treturn Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);\n\t}\n\t\n\t/**\n\t * 3---Get the distance from one point to a segment (not a line)\n\t * @param x1\tthe x coordinate of one endpoint of the segment\n\t * @param y1\tthe y coordinate of one endpoint of the segment\n\t * @param x2\tthe x coordinate of the other endpoint of the segment\n\t * @param y2\tthe y coordinate of the other endpoint of the segment\n\t * @param x\t\tthe x coordinate of the point\n\t * @param y\t\tthe y coordinate of the point\n\t * @return\t\tthe distance from one point to a segment (not a line)\n\t */\n\tpublic double ptToSeg(long x1, long y1, long x2, long y2, long x, long y)\n\t{\n\t\tdouble cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);\n\t\tif(cross <= 0)\n\t\t{\n\t\t\treturn (x - x1) * (x - x1) + (y - y1) * (y - y1);\n\t\t}\n\t\tdouble d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);\n\t\tif(cross >= d) \n\t\t{\n\t\t\treturn (x - x2) * (x - x2) + (y - y2) * (y - y2);\n\t\t}\n\t\tdouble r = cross / d;\n\t\tdouble px = x1 + (x2 - x1) * r;\n\t\tdouble py = y1 + (y2 - y1) * r;\n\t\treturn (x - px) * (x - px) + (y - py) * (y - py);\n\t}\n\t\n\t/**\n\t * 4---KMP match, i.e. kmpMatch(\"abcd\", \"bcd\") = 1, kmpMatch(\"abcd\", \"bfcd\") = -1.\n\t * @param t:\tString to match.\n\t * @param p:\tString to be matched.\n\t * @return\t\tif can match, first index; otherwise -1.\n\t */\n\tpublic int kmpMatch(char[] t, char[] p)\n\t{\n\t\tint n = t.length;\n\t\tint m = p.length;\n\t\tint[] next = new int[m + 1];\n\t\tnext[0] = -1;\n\t\tint j = -1;\n\t\tfor(int i = 1;i < m;++i)\n\t\t{\n\t\t\twhile(j >= 0 && p[i] != p[j + 1])\n\t\t\t{\n\t\t\t\tj = next[j];\n\t\t\t}\n\t\t\tif(p[i] == p[j + 1])\n\t\t\t{\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tnext[i] = j;\n\t\t}\n\t\tj = -1;\n\t\tfor(int i = 0;i < n;++i)\n\t\t{\n\t\t\twhile(j >= 0 && t[i] != p[j + 1])\n\t\t\t{\n\t\t\t\tj = next[j];\n\t\t\t}\n\t\t\tif(t[i] == p[j + 1])\n\t\t\t{\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tif(j == m - 1)\n\t\t\t{\n\t\t\t\treturn i - m + 1;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\t/**\n\t * 5---Get the hash code of a String\n\t * @param\ts:\tinput string\n\t * @return\thash code\n\t */\n\tpublic long hash(String s)\n\t{\n\t\tlong key = 0, t = 1;\n\t\tfor(int i = 0;i < s.length();++i)\n\t\t{\n\t\t\tkey = (key + s.charAt(i) * t) % MODH;\n\t\t\tt = t * BASE % MODH;\n\t\t}\n\t\treturn key;\n\t}\n\t\n\t/**\n\t * 6---Get x ^ n % MOD quickly.\n\t * @param\tx:\tbase\n\t * @param \tn:\ttimes\n\t * @return\tx ^ n % MOD\n\t */\n\tpublic long quickMod(long x, long n)\n\t{\n\t\tlong ans = 1;\n\t\twhile(n > 0)\n\t\t{\n\t\t\tif(1 == n % 2)\n\t\t\t{\n\t\t\t\tans = ans * x % MOD;\n \t\t\t}\n\t\t\tx = x * x % MOD;\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\t/**\n\t * 7---judge if a point is located inside a polygon\n\t * @param x0\tthe x coordinate of the point\n\t * @param y0\tthe y coordinate of the point\n\t * @return true if it is inside the polygon, otherwise false\n\t */\n\t/*public boolean contains(double x0, double y0)\n\t{\n\t\tint cross = 0;\n\t\tfor(int i = 0;i < n;++i)\n\t\t{\n\t\t\tdouble s = x[i + 1] == x[i] ? 100000000 : (double)(y[i + 1] - y[i]) / (x[i + 1] - x[i]);\n\t\t\tboolean b1 = x[i] <= x0 && x0 < x[i + 1];\n\t\t\tboolean b2 = x[i + 1] <= x0 && x0 < x[i];\n\t\t\tboolean b3 = y0 < s * (x0 - x[i]) + y[i];\n\t\t\tif((b1 || b2) && b3) ++cross;\n\t\t}\n\t\treturn cross % 2 != 0;\n\t}*/\n\t\n\t/**\n\t * 8---judge if a point is located on the segment\n\t * @param\tx1\tthe x coordinate of one point of the segment\n\t * @param\ty1\tthe y coordinate of one point of the segment\n\t * @param \tx2\tthe x coordinate of another point of the segment\n\t * @param \ty2\tthe y coordinate of another point of the segment\n\t * @param\tx\tthe x coordinate of the point\n\t * @param \ty\tthe y coordinate of the point\n\t * @return\ttrue if it is located on the segment, otherwise false\n\t */\n\tpublic boolean isOnSeg(long x1, long y1, long x2, long y2, long x, long y)\n\t{\n\t\treturn (x - x1) * (y2 - y1) == (x2 - x1) * (y - y1) && \n\t\t\t\tx >= Math.min(x1, x2) && x <= Math.max(x1, x2) && \n\t\t\t\ty >= Math.min(y1, y2) && y <= Math.max(y1, y2);\n\t}\n\t\n\t/**\n\t * 9---get the cross product\n\t * @param \tp1\tpoint A\n\t * @param \tp2\tpoint B\n\t * @param \tp\tpoint O\n\t * @return\tcross product of OA x OB\n\t */\n\tpublic long cross(Point p1, Point p2, Point p)\n\t{\n\t\treturn (long)(p1.x - p.x) * (p2.y - p.y) - (long)(p2.x - p.x) * (p1.y - p.y);\n\t}\n\t\n\tclass MyScanner\n\t{\n\t private byte[] buf = new byte[1024];\n\t private int curChar;\n\t private int numChars;\n\t BufferedInputStream bis = new BufferedInputStream(System.in);\n\n\t public int read() \n\t {\n\t if (-1 == numChars)\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t if (curChar >= numChars)\n\t {\n\t curChar = 0;\n\t try \n\t {\n\t numChars = bis.read(buf);\n\t }\n\t catch (IOException e)\n\t {\n\t throw new InputMismatchException();\n\t }\n\t if (numChars <= 0)\n\t {\n\t \treturn -1;\n\t }\n\t }\n\t return buf[curChar++];\n\t }\n\n\t public int nextInt() \n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-') \n\t {\n\t sgn = -1;\n\t c = read();\n\t }\n\t int res = 0;\n\t do \n\t {\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c - '0';\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\t \n\t public long nextLong() \n\t {\n\t \tint c = read();\n\t \twhile (isSpaceChar(c))\n\t \t{\n\t \t\tc = read();\n\t \t}\n\t \tint sgn = 1;\n\t \tif (c == '-') \n\t \t{\n\t \t\tsgn = -1;\n\t \t\tc = read();\n\t \t}\n\t \tlong res = 0;\n\t \tdo \n\t \t{\n\t \t\tif (c < '0' || c > '9')\n\t \t\t{\n\t \t\t\tthrow new InputMismatchException();\n\t \t\t}\n\t \t\tres *= 10;\n\t \t\tres += c - '0';\n\t \t\tc = read();\n\t \t} while (!isSpaceChar(c));\n\t \treturn res * sgn;\n\t }\n\t \n\t public double nextDouble() \n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-')\n\t {\n\t sgn = -1;\n\t c = read();\n\t }\n\t double res = 0;\n\t while (!isSpaceChar(c) && c != '.') \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c & 15;\n\t c = read();\n\t }\n\t if (c == '.') \n\t {\n\t c = read();\n\t double m = 1;\n\t while (!isSpaceChar(c)) \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t m /= 10;\n\t res += (c & 15) * m;\n\t c = read();\n\t }\n\t }\n\t return res * sgn;\n\t }\n\t \n\t public String next()\n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t StringBuilder res = new StringBuilder();\n\t do \n\t {\n\t res.appendCodePoint(c);\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res.toString();\n\t }\n\n\t private boolean isSpaceChar(int c) \n\t {\n\t return ' ' == c || '\\n' == c || '\\r' == c || '\\t' == c || -1 == c;\n\t }\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "79ea2b66ff01a12e355fde69890fff95", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\n\npublic class Main {\n \n public static Scanner cin = new Scanner(System.in);\n \n public static final int N = 150000;\n \n public static void main(String[] args) throws IOException {\n //BufferedReader in = new BufferedReader(new FileReader(new File(\"D:/java.inp\")));\n BufferedReader in = new BufferReader(new InputStreamReader(System.in));\n \n String s = in.readLine();\n String[] st = s.split(\" \");\n int a = Integer.parseInt(st[0]);\n int b = Integer.parseInt(st[1]);\n int w = Integer.parseInt(st[2]);\n int x = Integer.parseInt(st[3]);\n int c = Integer.parseInt(st[4]);\n \n b = w-b-1;\n int l = 1, r = 2000000000, res = 0;\n while (l <= r) {\n int mid = (l+r)/2;\n int aa = a-(b+mid*x)/w;\n int cc = c-mid;\n if (cc <= aa) {\n res = mid;\n r = mid-1;\n }\n else \n l = mid+1;\n }\n \n System.out.print(res);\n }\n\n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7aa2e0385bdea1a0f7430a5d750d17bb", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Collection;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\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\tlong prevTime = System.currentTimeMillis();\n\t\t\t\t\tnew Main().run();\n\t\t\t\t\tSystem.err.println(\"Total time: \"\n\t\t\t\t\t\t\t+ (System.currentTimeMillis() - prevTime) + \" ms\");\n\t\t\t\t\tSystem.err.println(\"Memory status: \" + memoryStatus());\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\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tObject o = solve();\n\t\tif (o != null)\n\t\t\tout.println(o);\n\t\tout.close();\n\t\tin.close();\n\t}\n\n\tprivate Object solve() throws IOException {\n\t\tlong a = nl();\n\t\tint b = ni();\n\t\tint w = ni();\n\t\tint x = ni();\n\t\tlong c = nl();\n\n\t\tint step = 100000;\n\n\t\tint[][] move_b = new int[w][step + 1];\n\t\tfor (int i = 0; i < w; i++)\n\t\t\tmove_b[i][0] = i;\n\t\tlong[][] dif_b = new long[w][step + 1];\n\t\tfor (int i = 0; i < w; i++)\n\t\t\tdif_b[i][0] = 0;\n\n\t\tfor (int move = 1; move <= step; move++)\n\t\t\tfor (int bb = 0; bb < w; bb++) {\n\t\t\t\tint prev_b = move_b[bb][move - 1];\n\t\t\t\tlong prev_dif = dif_b[bb][move- 1];\n\n\t\t\t\tif (prev_b >= x) {\n\t\t\t\t\tmove_b[bb][move] = prev_b - x;\n\t\t\t\t\tdif_b[bb][move] = prev_dif;\n\t\t\t\t} else {\n\t\t\t\t\tmove_b[bb][move] = w - (x - prev_b);\n\t\t\t\t\tdif_b[bb][move] = prev_dif + 1L;\n\t\t\t\t}\n\n\t\t\t}\n\t\tlong t = 0;\n\t\twhile (has_next(a, b, c, dif_b, step)) {\n\t\t\ta -= dif_b[b][step];\n\t\t\tb = move_b[b][step];\n\t\t\tt += (long) (step);\n\t\t\tc -= (long) (step);\n\t\t\t\n\t\t}\n\t\twhile (c > a) {\n\t\t\tc--;\n\t\t\ta-= (long) (dif_b[b][1]);\n\t\t\tb = move_b[b][1];\n\t\t\tt++;\n\t\t}\n\n\t\treturn t;\n\t}\n\n\tprivate boolean has_next(long a, int b, long c, long[][] dif_b, int step) {\n\t\tlong next_c = c - (long) (step);\n\t\tlong next_a = a - dif_b[b][step];\n\t\treturn next_c > next_a;\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tint ni() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nl() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nd() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tint[] nia(int size) throws IOException {\n\t\tint[] ret = new int[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = ni();\n\t\treturn ret;\n\t}\n\n\tlong[] nla(int size) throws IOException {\n\t\tlong[] ret = new long[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nl();\n\t\treturn ret;\n\t}\n\n\tdouble[] nda(int size) throws IOException {\n\t\tdouble[] ret = new double[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nd();\n\t\treturn ret;\n\t}\n\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n\n\tvoid printRepeat(String s, int count) {\n\t\tfor (int i = 0; i < count; i++)\n\t\t\tout.print(s);\n\t}\n\n\tvoid printArray(int[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(long[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(double[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(double[] array, String spec) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0)\n\t\t\t\tout.print(' ');\n\t\t\tout.printf(Locale.US, spec, array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(Object[] array) {\n\t\tboolean blank = false;\n\t\tfor (Object x : array) {\n\t\t\tif (blank)\n\t\t\t\tout.print(' ');\n\t\t\telse\n\t\t\t\tblank = true;\n\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n\n\t@SuppressWarnings(\"rawtypes\")\n\tvoid printCollection(Collection collection) {\n\t\tboolean blank = false;\n\t\tfor (Object x : collection) {\n\t\t\tif (blank)\n\t\t\t\tout.print(' ');\n\t\t\telse\n\t\t\t\tblank = true;\n\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n\n\tstatic String memoryStatus() {\n\t\treturn (Runtime.getRuntime().totalMemory()\n\t\t\t\t- Runtime.getRuntime().freeMemory() >> 20)\n\t\t\t\t+ \"/\" + (Runtime.getRuntime().totalMemory() >> 20) + \" MB\";\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9e5163ffa8a35d178c8dbff91051d285", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000} {"lang": "Java 6", "source_code": "import java.io.*;\n\npublic class A {\n public static void main(String[] args) {\n BufferedReader r;\n r = new BufferedReader(new InputStreamReader(System.in));\n String[] arg = r.readLine().split(\" \");\n int n = Integer.parseInt(arg[0]);\n int m = Integer.parseInt(arg[1]);\n if (n == 0 && m != 0) {\n System.out.print(\"Impossible\");\n } else {\n int max = n + ((m == 0) ? 1 : m) - 1;\n int min = (m >= n) ? m : n;\n System.out.print(min + \" \" + max);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b99c1146df88b6345cf512188028fbf2", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100} {"lang": "Java 6", "source_code": "public class Main {\n /**\n * @param args\n */\n public static void main(String[] args) {\n Main task = new Main();\n task.read();\n task.write();\n }\n\n int n,m;\n \n public void read() {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n m = in.nextInt();\n in.close();\n }\n\n public void write() {\n PrintWriter out = new PrintWriter(System.out);\n if (n == 0 && m > 0){\n out.println(\"Impossible\");\n }else{\n out.println((n + m - Math.min(n, m)) + \" \" + (n + m - (m > 0 ? 1 : 0)));\n }\n out.flush();\n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "78af4dced21bb936965dfd407bf7557a", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n \n \n \npublic class AVasyaAndTheBus {\n \n public static void main(String[] args) throws IOException {\n \n BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));\n \n StringTokenizer st=new StringTokenizer(reader.readLine());\n \n long n=Long.parseLong(st.nextToken());\n long m=Long.parseLong(st.nextToken());\n if(n==0&&m==0)\n System.out.println(\"0 0\");\n else\n if(n==0)\n System.out.println(\"Impossible\");\n else\n if(m==0)\n System.out.println(n+\" \"+n);\n else\n if(n==m)\n System.out.println(n+\" \"+(n+(m-1)));\n else\n if(n>m)\n System.out.println(n+\" \"+(n+(m-1)));\n else\n System.out.println(m+\" \"+(n+(m-1)));", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7638023657b8f053d9cfc6e8a5ae309a", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100} {"lang": "Java 6", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int min=0;\n int max=0;\n int n=sc.nextInt();\n int m=sc.nextInt();\n \n if(n==0)\n System.out.println(\"Impossible\");\n else{\n if(m==0){\n max=n;\n min=n;\n \n }\n if(m>=n){\n \n min=m;\n max=m+n-1;\n }\n else\n if(m!=0)\n {\n min=n;\n max=m+n-1;\n }\n System.out.println(min+\" \"+max);\n }\n\n \n }\n }\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f603300d16493ffb0073dd517e0ccac8", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class edu121\n{\n public static void main(String args[])throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t Scanner sc = new Scanner(System.in);\n\t int a = sc.nextInt();\n\t int ta = sc.nextInt();\n\t \n\t int b = sc.nextInt();\n\t int tb = sc.nextInt();\n\t \n\t String s = br.readLine();\n\t \n\t \n\t int hr = Integer.parseInt(s.substring(0,2));\n\t int mins = Integer.parseInt(s.substring(3));\n\t \n\t //System.out.println(mins);\n\t int min_calcu = hr*60 + mins; \n\t //int time = min_calcu;\n\t int count = 0;\n \n\t\tint elapse_time = min_calcu + ta;\n\t for(int i = 5*60 ; i < (23*60 + 59 ); i=i+b)\n\t {\n\t\t //int time = i + tb;\n\n if (i +tb > min_calcu && elapse_time > i) \n\t\t\t\tcount++;\n\t }\n\t System.out.println(count);\n \n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "caac0ce80326003975923ba8a679646c", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Simion {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String a = in.nextLine();\n\t\tString b = in.nextLine();\n\t\tString hora = in.nextLine();\n\t\tString [] A = a.split(\" \");\n\t\tString [] B = b.split(\" \");\n\t\tString [] C = c.split(\":\");\n\t\tint hora = (Integer.valueOf(C[0])*60) + Integer.valueOf(C[1]);\n\t\tint tiempollegada = hora + Integer.valueOf(A[1]);\n\t\tint cont=0;\n\t\tfor(int i=300;ihora)\n\t\t\t\tcont++;\n\t\t}\n\t\tSystem.out.println(cont);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f8371de3fda460b297f2804f49b7495b", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600} {"lang": "Java 8", "source_code": "public class code {\n \n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a = sc.nextInt();\n\t\ta = sc.nextInt();\n\t\tdouble b = sc.nextDouble();\n\t\tint c = sc.nextInt();\n\t\tString t = sc.next();\n\t\tint time = Integer.parseInt(String.valueOf(t.charAt(0)))*600+Integer.parseInt(String.valueOf(t.charAt(1)))*60+Integer.parseInt(String.valueOf(t.charAt(3)))*10+Integer.parseInt(String.valueOf(t.charAt(4)))-300;\n\t\tint max= time+a;\n\t\tif(max>23*60+59-300) {\n\t\t\tmax=23*60+59-300;\n\t\t}\n\t\tint depart=(int)(Math.ceil((max)/b));\n\t\tif(max%b==0) {\n\t\t\tdepart++;\n\t\t}\n\t\tint arrive = 0;\n\t\tif(time>=c) {\n\t\t\tarrive=(int)((time-c)/b)+1;\n\t\t}\n\t\tSystem.out.println(depart-arrive);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "733700d757a109468c26dbe1d863472d", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Simion {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String a = in.nextLine();\n\t\tString b = in.nextLine();\n\t\tString c = in.nextLine();\n\t\tString [] A = a.split(\" \");\n\t\tString [] B = b.split(\" \");\n\t\tString [] C = c.split(\":\");\n\t\tint hora = (Integer.parseInt(C[0])*60) + Integer.parseInt(C[1]);\n\t\tint tiempollegada = hora + Integer.parseInt(A[1]);\n\t\tint cont=0;\n\t\tfor(int i=300;ii>=hora))\n\t\t\t\tcont++;\n\t\t}\n\t\tSystem.out.println(cont);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "69e22919917785a6f5a70955c2874031", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600} {"lang": "Java 8", "source_code": " \niimport java.util.Scanner;\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner input=new Scanner(System.in);\n\t\tint n=input.nextInt();\n\t\tString arr=input.next();\n\t\tint count=0;\n\t\tint count1=0;\n\t\t\n\t\tint m=n/11;\n\t\tfor(int i=0;im) {\n\t\t\tcount1=m;\n\t\t}\n\t\telse {\n\t\t\tcount1=count;\n\t\t}\n\t\t\n\t\tSystem.out.print(count1);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1410ae34dd0f7118a440fd04639895c4", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.utils.*;\n\npublic class Test {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in); \n int n = sc.nextInt();\n String digitStr = sc.nextLine();\n int count = 0, size = digitStr.length();\n \n for(int i = 0; i < size; i++) {\n if(digitStr.charAt(i) == '8') {\n count++;\n }\n }\n \n int div = size / 11;\n int mod = size % 11;\n \n if(mod != 0) return 0;\n \n if(count < div) return 0;\n \n return div;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b3796bb11c5283b6df2d7f740f62f6df", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class phonenumber\n{\n public static void main(String args[])\n {\n Scanner as=new Scanner(System.in);\n\t int n=as.nextInt();\n\t String s=as.next();\n\t if(n<11)\n\t\t System.out.println(0);\n\t else\n\t {\n\t\t int flag=0;int c=0;\n\t\t for(int i=0;i 99) return false;\n if(p[1] < 1 || p[1] > 12) return false;\n if(p[2] < 1 || p[2] > mds[p[1]]) return false;\n if(p[0]%4!=0 && p[1]==2 && p[2] == 29) return false;\n return true;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3f525cd08fd97f7134ed3c4ef94c67c8", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700} {"lang": "Java 6", "source_code": "\nimport java.util.Calendar;\nimport java.util.Scanner;\nimport java.util.TimeZone;\n\n\npublic class B_CodeforcesWorldFinals {\n\n /**\n * 0:14\n */\n \n static final int INF = 100000000;\n public static void main(String[] args) {\n\n// System.out.println(days2(new int[]{1, 12, 31}));\n// if(true) return;\n Scanner sc = new Scanner(System.in);\n \n String[] p1;\n p1 = sc.nextLine().split(\"\\\\.\");\n int DD = Integer.parseInt(p1[0]);\n int MM = Integer.parseInt(p1[1]);\n int YY = Integer.parseInt(p1[2]);\n \n p1 = sc.nextLine().split(\"\\\\.\");\n int BD = Integer.parseInt(p1[0]);\n int BM = Integer.parseInt(p1[1]);\n int BY = Integer.parseInt(p1[2]);\n \n int[][] perm = new int[][]{{BY, BM, BD}, {BY, BD, BM}, {BM, BD, BY}, {BM, BY, BD}, {BD, BY, BM}, {BD, BM, BY}};\n \n int hd = days2(new int[]{YY, MM, DD});\n if(hd == INF) throw new RuntimeException();\n System.out.println(hd);\n for (int i = 0; i < 6; i++) {\n int[] p = perm[i];\n if(p[1] == 2 && p[2] == 29){\n p[1] = 3;\n p[2] = 1;\n }\n p[0] += 18;\n \n int bd = days2(p);\n System.out.println(bd);\n \n if(bd <= hd){\n System.out.println(\"YES\");\n return;\n }\n }\n System.out.println(\"NO\");\n }\n \n static final int[] mds = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};\n private static int days(int[] p){\n if(! isValid(p)) return INF;\n \n int ret = 0;\n \n for (int y = 0; y <= p[0]; y++) {\n for (int m = 1; m <= (y == p[0] ? p[1] : 12); m++) {\n ret += mds[m-1];\n if(y%4 == 0 && m == 2) ret++;\n }\n if(y == p[0]){\n ret += p[2];\n }\n }\n return ret;\n }\n private static int days2(int[] p){\n \n if(! isValid(p)) return INF;\n int day = calcDay(2000+p[0], p[1], p[2]);\n \n return day;\n \n }\n \n private static int calcDay(int y, int m, int d){\n Calendar cl = Calendar.getInstance(TimeZone.getTimeZone(\"UTC\"));\n cl.set(y, m-1, d, 0, 0, 0);\n cl.set(Calendar.MILLISECOND, 0);\n return (int)(cl.getTimeInMillis() / 1000 / 60 / 60 / 24);\n }\n \n private static boolean isValid(int[] p){\n if(p[0] > 99) return false;\n if(p[1] < 1 || p[1] > 12) return false;\n if(p[2] < 1 || p[2] > mds[p[1]-1]) return false;\n if(p[0]%4!=0 && p[1]==2 && p[2] == 29) return false;\n return true;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0fcdb6d2f90c3cde2baa0b1ff2135cbb", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700} {"lang": "Java 6", "source_code": "\nimport java.util.Calendar;\nimport java.util.Scanner;\nimport java.util.TimeZone;\n\n\npublic class B_CodeforcesWorldFinals {\n\n /**\n * 0:14\n */\n \n static final int INF = 100000000;\n public static void main(String[] args) {\n\n// System.out.println(days2(new int[]{1, 12, 31}));\n// if(true) return;\n Scanner sc = new Scanner(System.in);\n \n String[] p1;\n p1 = sc.nextLine().split(\"\\\\.\");\n int DD = Integer.parseInt(p1[0]);\n int MM = Integer.parseInt(p1[1]);\n int YY = Integer.parseInt(p1[2]);\n \n p1 = sc.nextLine().split(\"\\\\.\");\n int BD = Integer.parseInt(p1[0]);\n int BM = Integer.parseInt(p1[1]);\n int BY = Integer.parseInt(p1[2]);\n \n int[][] perm = new int[][]{{BY, BM, BD}, {BY, BD, BM}, {BM, BD, BY}, {BM, BY, BD}, {BD, BY, BM}, {BD, BM, BY}};\n \n int hd = days2(new int[]{YY, MM, DD});\n if(hd == INF) throw new RuntimeException();\n// System.out.println(hd);\n for (int i = 0; i < 6; i++) {\n int[] p = perm[i];\n if(p[1] == 2 && p[2] == 29){\n p[1] = 3;\n p[2] = 1;\n }\n p[0] += 18;\n \n int bd = days2(p);\n// System.out.println(bd);\n \n if(bd <= hd){\n System.out.println(\"YES\");\n return;\n }\n }\n System.out.println(\"NO\");\n }\n \n static final int[] mds = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};\n private static int days(int[] p){\n if(! isValid(p)) return INF;\n \n int ret = 0;\n \n for (int y = 0; y <= p[0]; y++) {\n for (int m = 1; m <= (y == p[0] ? p[1] : 12); m++) {\n ret += mds[m-1];\n if(y%4 == 0 && m == 2) ret++;\n }\n if(y == p[0]){\n ret += p[2];\n }\n }\n return ret;\n }\n private static int days2(int[] p){\n \n if(! isValid(p)) return INF;\n int day = calcDay(2000+p[0], p[1], p[2]);\n \n return day;\n \n }\n \n private static int calcDay(int y, int m, int d){\n Calendar cl = Calendar.getInstance(TimeZone.getTimeZone(\"UTC\"));\n cl.set(y, m-1, d, 0, 0, 0);\n cl.set(Calendar.MILLISECOND, 0);\n return (int)(cl.getTimeInMillis() / 1000 / 60 / 60 / 24);\n }\n \n private static boolean isValid(int[] p){\n if(p[0] > 99) return false;\n if(p[1] < 1 || p[1] > 12) return false;\n if(p[2] < 1 || p[2] > mds[p[1]-1]) return false;\n if(p[0]%4!=0 && p[1]==2 && p[2] == 29) return false;\n return true;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8f67016dbdaac08838abe2bdbef810e3", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700} {"lang": "Java 6", "source_code": "//package round30;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n//\tprivate String INPUT = \"01.01.98\\n01.01.80\";\n//\tprivate String INPUT = \"20.10.20\\n10.02.30\";\n//\tprivate String INPUT = \"01.03.74\\n29.02.56\";\n\tprivate String INPUT = \"\";\n\t\n\tpublic void solve()\n\t{\n\t\tin.useDelimiter(\"[\\\\.\\n\\r]\");\n\t\tint dd = ni();\n\t\tint mm = ni();\n\t\tint yy = ni();\n\t\tint[] t = new int[3];\n\t\tfor(int i = 0;i < 3;i++)t[i] = ni();\n\t\t\n\t\tif(\ttest(dd, mm, yy, t[0], t[1], t[2]) ||\n\t\t\t\ttest(dd, mm, yy, t[0], t[2], t[1]) ||\n\t\t\t\ttest(dd, mm, yy, t[1], t[0], t[2]) ||\n\t\ttest(dd, mm, yy, t[1], t[2], t[0]) ||\n\t\ttest(dd, mm, yy, t[2], t[1], t[0]) ||\n\t\ttest(dd, mm, yy, t[2], t[0], t[1])){\n\t\t\tout.println(\"YES\");\n\t\t}else{\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\t\n\tpublic boolean test(int dd, int mm, int yy, int bd, int bm, int by)\n\t{\n\t\tif(yy < by + 18)return false;\n\t\tif(bm > 12)return false;\n\t\tif(bd > 31)return false;\n\t\t\n\t\tint[] md = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\n\t\tif(by % 4 == 0)md[2]++;\n\t\tif(by % 4 != 0 && bm == 2 && bd == 29){\n\t\t\tbm = 3; bd = 1;\n\t\t}\n\t\tif(bd > md[bm])return false;\n\t\t\n\t\tif(yy > by + 18)return true;\n\t\tif(bm != mm)return mm > bm;\n\t\treturn dd >= bd;\n\t}\n\t\n\tpublic void run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew B().run();\n\t}\n\t\n\tprivate int ni() { return Integer.parseInt(in.next()); }\n\tprivate void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b372435b3376ba6f90ad13e393043132", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class scc\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int sum = 0;\n int x = 1;\n while(sum < n)\n {\n sum += x;\n x++;\n }\n x--;\n System.out.println(x);\n while(n-x > 0)\n {\n System.out.print(x + \" \");\n }\n else\n System.out.println(n);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1cd5400f6ba51b4e0e8a30570b0fdfe2", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class SantaClausaAndCandies {\n\tpublic static void main(String args[]) throws Exception{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint val = (int) Math.sqrt(n*2);\n\t\tif((int)Math.pow(val, 2) + val > n * 2){\n\t\t\tval -= 1;\n\t\t}\n\t\tSystem.out.println(val);\n\t\t//int count = val;\n\t\twhile(true){\n\t\t\tboolean flag = false;\n\t\t\tif(val == 1){\n\t\t\t\tSystem.out.print(n);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tfor(int i = 1; i <= val; i++){\n\t\t\t\t\t\n\t\t\t\t\tif(i == val){\n\t\t\t\t\t\tSystem.out.print(n - ((i)*(i-1))/2);\n\t\t\t\t\t\tflag = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.print(i + \" \");\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(flag){\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "732d0e0a911b83110be4c6ed264b3721", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.io.*;\n\npublic class problem2 {\n\tpublic static int isSubstring(String s1, String s2) {\n\t\tint M = s1.length();\n\t\tint N = s2.length();\n\n\t\t/* A loop to slide pat[] one by one */\n\t\tfor (int i = 0; i <= N - M; i++) {\n\t\t\tint j;\n\n\t\t\t/*\n\t\t\t * For current index i, check for pattern match\n\t\t\t */\n\t\t\tfor (j = 0; j < M; j++)\n\t\t\t\tif (s2.charAt(i + j) != s1.charAt(j))\n\t\t\t\t\tbreak;\n\n\t\t\tif (j == M)\n\t\t\t\treturn i;\n\t\t}\n\n\t\treturn -1;\n\t}\n\n\tpublic static void merge(int arr[], int l, int m, int r) {\n\t\t// Find sizes of two subarrays to be merged\n\t\tint n1 = m - l + 1;\n\t\tint n2 = r - m;\n\n\t\t/* Create temp arrays */\n\t\tint L[] = new int[n1];\n\t\tint R[] = new int[n2];\n\n\t\t/* Copy data to temp arrays */\n\t\tfor (int i = 0; i < n1; ++i)\n\t\t\tL[i] = arr[l + i];\n\t\tfor (int j = 0; j < n2; ++j)\n\t\t\tR[j] = arr[m + 1 + j];\n\n\t\t/* Merge the temp arrays */\n\n\t\t// Initial indexes of first and second subarrays\n\t\tint i = 0, j = 0;\n\n\t\t// Initial index of merged subarry array\n\t\tint k = l;\n\t\twhile (i < n1 && j < n2) {\n\t\t\tif (L[i] <= R[j]) {\n\t\t\t\tarr[k] = L[i];\n\t\t\t\ti++;\n\t\t\t} else {\n\t\t\t\tarr[k] = R[j];\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tk++;\n\t\t}\n\n\t\t/* Copy remaining elements of L[] if any */\n\t\twhile (i < n1) {\n\t\t\tarr[k] = L[i];\n\t\t\ti++;\n\t\t\tk++;\n\t\t}\n\n\t\t/* Copy remaining elements of R[] if any */\n\t\twhile (j < n2) {\n\t\t\tarr[k] = R[j];\n\t\t\tj++;\n\t\t\tk++;\n\t\t}\n\t}\n\n\t// Main function that sorts arr[l..r] using\n\t// merge()\n\tpublic static void sort(int arr[], int l, int r) {\n\t\tif (l < r) {\n\t\t\t// Find the middle point\n\t\t\tint m = (l + r) / 2;\n\n\t\t\t// Sort first and second halves\n\t\t\tsort(arr, l, m);\n\t\t\tsort(arr, m + 1, r);\n\n\t\t\t// Merge the sorted halves\n\t\t\tmerge(arr, l, m, r);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint temp = 0;\n\t\tint k = 1;\n\t\twhile(temp<=n) {\n\t\t\ttemp = (k*(k+1))/2;\n\t\t\tk++;\n\t\t}\n\t\tk-=2;\n\t\tint sum = 0;\n\t\tSystem.out.println(k);\n\t\tfor(int i=1;i<=k-1;i++) {\n\t\t\tSystem.out.print(i + \" \");\n\t\t\tsum+=i;\n\t\t}\n\t\tSystem.out.println(n-sum);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "75d10a0c9e797a21eb020b22ddab3d2b", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc", "difficulty": 1000} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class CF753A {\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 sum = 0;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tsum += i;\n\t\t\tif (sum == n) {\n\t\t\t\tSystem.out.println(i);\n\t\t\t\tSystem.out.println();\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tSystem.out.print(i + \" \");\n\t\t\t\tbreak;\n\t\t\t} else if (sum > 0) {\n\t\t\t\tSystem.out.println(i - 1);\n\t\t\t\tfor (int i = 0; i < n - 2; i++)\n\t\t\t\t\tSystem.out.print(i + \" \");\n\t\t\t\tSystem.out.print(n - sum + n - 1 + n);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1e771cc48856676df965d2167bbbbca5", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tLong n = in.nextLong();\n\t\tLong k = in.nextLong();\n\t\tLong ans = 0L;\n\t\tif(k == 1)\n\t\t{\n\t\t\tans = n;\n\t\t}else{\n\t\t\tans = 0;\n\t\t\tint i;\n\t\t\tfor(i = 63; i >= 0; i--)\n\t\t\t{\n\t\t\t\tif((n&1< 0) {\n N /= 2;\n tim++;\n }\n\n long ans = 0;\n\n for (int i = 0; i < K && tim >= 0; i++, tim--) {\n ans += pow(tim);\n }\n\n System.out.println(ans);\n }\n\n private static long pow(int tim) {\n long ans = 1;\n for (int i = 1; i <= tim; i++) {\n ans *= 2;\n }\n return ans;\n }\n}\nclose", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7c4d2ce763548342805f80b2af21e189", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300} {"lang": "Java 8", "source_code": "public class New_Years_Eve\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc= new Scanner(System.in);\n\t\tlong n=sc.nextLong();\n\t\tlong k=sc.nextLong();\n\t\tif(k==1)\n\t\t\tSystem.out.println(n);\n\t\telse\n\t\t{\t\n\t\tdouble log2=Math.ceil(Math.log(n)/Math.log(2));\n\t\tdouble z=Math.pow(2, log2);\n\t\tif(z==n)\n\t\t\tSystem.out.println((long)(Math.pow(2, log2+1)-1));\n\t\telse\n\t\t\tSystem.out.println((long)(z-1));\n\t\n\t\t}\n\t}\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e3ea625671fae4d91e6b4e7c83f37208", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tLong n = in.nextLong();\n\t\tLong k = in.nextLong();\n\t\tLong ans = 0L;\n\t\tif(k == 1)\n\t\t{\n\t\t\tans = n;\n\t\t}else{\n\t\t\tfor(Long i = 63; i >= 0; i--)\n\t\t\t{\n\t\t\t\tif((n&1< 0){\n left = x%10;\n sum += left;\n x -= left;\n x /= 10;\n }\n return sum;\n }\n public static long Converter(long x){\n Stack st = new Stack();\n long left = 0, wanted = 0;\n boolean done = false;\n while(x > 0){\n left = x%10;\n x -= left;\n x /= 10;\n st.push(left);\n }\n while(!st.empty()){\n left = (long)st.pop();\n if(!done){\n wanted += (left - 1);\n done = true;\n }else{\n wanted += 9;\n }\n wanted *= 10;\n }\n return wanted/10;\n }\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n long x = 0;\n Scanner sc = new Scanner(System.in);\n x = sc.nextLong();\n long largestSum = 0, wantedNumber = 0;\n for(long i = Converter(x); i <= x; ++i){\n if(i >= 0){\n long sumOfDigs = sumOfDigits(i);\n if(sumOfDigs >= largestSum){\n largestSum = sumOfDigs;\n wantedNumber = i;\n }\n }\n }\n System.out.println(wantedNumber);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "baf2aead7aa5cabff286ce27e5bf324d", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.stream.IntStream;\n\npublic class SecondD {\n\n public static void main(String[] args) {\n for (int i = 0; i < 10000; i++) {\n int sumTWO = 0;\n int myRes = ree(i);\n int sumRes = getInts(myRes).stream().mapToInt(Integer::intValue).sum();\n\n List qwe = new ArrayList<>();\n for (int j = 0; j <= i ; j++) {\n sumTWO = getInts(j).stream().mapToInt(Integer::intValue).sum();\n if (sumRes <= sumTWO) {\n qwe.add(j);\n }\n }\n int max = qwe.stream().mapToInt(Integer::intValue).max().getAsInt();\n if (max != myRes) {\n System.out.println(i);\n System.out.println(max + \" \u043d\u0430\u0434\u043e\");\n System.out.println(myRes + \" \u0435\u0441\u0442\u044c\");\n }\n\n\n }\n\n }\n private static int ree(int x) {\n\n List numbers = getInts(x);\n boolean ninesTemplate = nines(numbers);\n\n int[] ints = numbers.stream().mapToInt(i->i).toArray();\n\n int firstSum = IntStream.of(ints).sum();\n\n for (int i = 0; i < ints.length; i++) {\n if (ints[i] < 9) {\n if (i + 1 < ints.length) {\n if (ints[ints.length - 2] != 8 ) {\n ints[i] = 9;\n ints[i + 1] = ints[i + 1] - 1;\n }\n }\n }\n }\n\n int lastSum = IntStream.of(ints).sum();\n\n\n if (firstSum >= lastSum) {\n return x;\n } else if (ninesTemplate) {\n return (((int) (x / 10) * 10) - 1);\n } else {\n StringBuilder result = new StringBuilder();\n boolean flag = true;\n for (int i = ints.length - 1; i >= 0; i--) {\n if (ints[i] == 0 && flag) {\n continue;\n }\n result.append(ints[i]);\n flag = false;\n }\n\n return Integer.parseInt(result.toString());\n }\n }\n\n private static List getInts(int x){\n List numbers = new ArrayList<>(15);\n while(x > 0) {\n numbers.add(x % 10);\n x = x / 10;\n }\n return numbers;\n }\n\n private static boolean nines(List x) {\n\n for (int i = 1; i < x.size() - 1; i++) {\n if (x.get(i) != 9) {\n return false;\n }\n }\n return true;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5991297fb9bb1f36b5bdbac9d4385d52", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300} {"lang": "Java 8", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\nimport java.util.*;\n/**\n *\n * @author adib\n */\npublic class Main {\n public static long sumOfDigits(long x){\n long left = 0, sum = 0;\n while(x > 0){\n left = x%10;\n sum += left;\n x -= left;\n x /= 10;\n }\n return sum;\n }\n public static long Converter(long x){\n Stack st = new Stack();\n long left = 0, wanted = 0;\n boolean done = false;\n while(x > 0){\n left = x%10;\n x -= left;\n x /= 10;\n st.push(left);\n }\n while(!st.empty()){\n left = (long)st.pop();\n if(!done){\n wanted += (left - 1);\n done = true;\n }else{\n wanted += 9;\n }\n wanted *= 10;\n }\n return wanted/10;\n }\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n long x = 0;\n Scanner sc = new Scanner(System.in);\n x = sc.nextLong();\n long largestSum = 0,wantedNumber = Converter(x);\n for(long i = Converter(x); i <= x; i*=10){\n if(i >= 0){\n long sumOfDigs = sumOfDigits(i);\n if(sumOfDigs >= largestSum){\n largestSum = sumOfDigs;\n wantedNumber = i;\n }\n }\n }\n wantedNumber = Converter(x);\n System.out.println(sumOfDigits(x)==sumOfDigits(wantedNumber)?x:wantedNumber);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "719d1bf3b5612cabe9f03ca80bbac889", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args){\n\t\tScanner sc= new Scanner(System.in);\n\t\tlong n= sc.nextLong();\n\t\tlong smax=0;\n\t\tlong result=0;\n\t\tfor (long i= n- n+\"\".length(); i<=n;i++){\n\t\t\tlong a=i;\n\t\t\tlong l=0;\n\t\t\tlong s=0;\n\t\t\t/*while(a>0){\n\t\t\t\ta=a/10;\n\t\t\t\tl=l+1;\n\t\t\t}*/\n\t\t\tl=1;\n\t\t\tfor (long k=1; k<=l;k++){\n\t\t\t\ts=s+((i/l)%10);\n\t\t\t\tl=l*10;\n\t\t\t}\n\t\t\tif (s>=smax){\n\t\t\t\tsmax=s;\n\t\t\t\tresult=i;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.print(result);\n\t\t\n\t\t\n\t}\n\t\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6a914fa4520fe81b12ab622fe92f4c02", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\n\n\n\npublic class Main\n{\n static class Pair implements Comparable{\n int pro, cus,diff;\n public Pair(int pro,int cus,int diff)\n {\n this.pro = pro;\n this.cus = cus;\n this.diff = diff;\n }\n public int compareTo(Pair p1)\n {\n if(Integer.compare(this.diff,p1.diff)==0)\n return p1.cus-this.cus;\n else\n return p1.diff-this.diff;\n }\n \n }\n\t//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\tstatic class Solution\n\t{\n\t\tstatic final long mod = 1000000007;\n\t\tstatic final int max = 1000003;\n\t\tstatic final boolean SIEVE = false;\n\t\tboolean[] prime;\n\t\tArrayList al;\n\t public void solve(InputReader sc,PrintWriter out) \n\t {\n\t int n = sc.nextInt();\n\t int k = sc.nextInt();\n\t int sum=0;\n\t for(int i=0;i0){\n\t\t\t\tif(e%2==1){\n\t\t\t\t\ta1 = (a*a2+b*c2)%mod;\n\t\t\t\t\tc1 = (c*a2+d*c2)%mod;\n\t\t\t\t\tb1 = (a*b2+ b*d2)%mod;\n\t\t\t\t\td1 = (b2*c+ d*d2)%mod;\n\t\t\t\t\ta=a1; b=b1; c=c1; d= d1;\n\t\t\t\t}\n\t\t\t\ta1 = (a2*a2+b2*c2)%mod;\n\t\t\t\tc1 = (c2*a2+d2*c2)%mod;\n\t\t\t\tb1 = (a2*b2+ b2*d2)%mod;\n\t\t\t\td1 = (b2*c2+ d2*d2)%mod;\n\t\t\t\ta2=a1; b2=b1; c2=c1; d2= d1;\n\t\t\t\te /= 2;\n\t\t\t}\n\t\t\treturn d;\n } \n ///////////////////////////////////////Methods/////////////////////////////////////////////////////\n \t}\n\n\n \t////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n \t\n\tMain() throws IOException {\n\t \tInputReader sc = new InputReader();\n\t PrintWriter out= new PrintWriter(System.out);\n\t final long start = System.currentTimeMillis();\t\t\n\t\tnew Solution().solve(sc,out);\n\t\t@SuppressWarnings(\"unused\")\n\t\tfinal long duration = System.currentTimeMillis()-start;\n\t\tout.close();\n\t}\n \n\tpublic static void main(String args[]) {\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tnew Main();\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\t}\n\tstatic class InputReader{\n\t\tfinal InputStream stream;\n\t\tfinal byte[] buf = new byte[8192];\n\t\tint curChar, numChars;\n\t\tSpaceCharFilter filter;\n \n\t\tpublic InputReader(){\n\t\t\tthis.stream = System.in;\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\t}\n\t\t\tif(curChar >= numChars){\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch(IOException e){\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif(numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt(){\n\t\t\tint c = read();\n\t\t\twhile(isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif(c == '-'){\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo{\n\t\t\t\tif(c<'0' || c>'9'){\n\t\t\t\t\tthrow new InputMismatchException();}\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while(!isSpaceChar(c));\n\t\t\treturn res*sgn;\n\t\t}\n \n\t\tpublic long nextLong(){\n\t\t\tint c = read();\n\t\t\twhile(isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif(c == '-'){\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo{\n\t\t\t\tif(c<'0' || c>'9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while(!isSpaceChar(c));\n\t\t\treturn res*sgn;\n\t\t}\n \n\t\tpublic String next(){\n\t\t\tint c = read();\n\t\t\twhile(isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}while(!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c){\n\t\t\tif(filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c==' ' || c=='\\n' || c=='\\r' || c=='\\t' || c==-1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2a5271b0c5f2d835ecf5b4440cf4b043", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class StraightA {\n \n public static void main(String[] args) {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw;\n StringTokenizer st;\n \n st = new StringTokenizer(br.readLine());\n int n = Integer.parseInt(st.nextToken());\n int k = Integer.parseInt(st.nextToken());\n \n int[] marks = new int[n];\n st = new StringTokenizer(br.readLine());\n \n double avg = 0;\n for (int i=0; i= k) {\n\t\t\tSystem.out.println(\"0\");\n\t\t} else {\n\t\t\thack();\n\t\t}\n\n\t}\n\n\tstatic void hack() {\n\n\t\twhile (times < 20) {\n\t\t\ttotaleMark += k;\n\t\t\ttimes++;\n\t\t\tdouble r = totaleMark / times;\n\t\t\tif (Math.round(r) >= k) {\n\t\t\t\tSystem.out.println((int) (times - n));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t}\n\t}\n\n\tstatic int getInt(String s) {\n\t\ttry {\n\t\t\treturn Integer.parseInt(s);\n\n\t\t} catch (Exception e) {\n\t\t\tSystem.out.println(s + \" : is not an Integer\");\n\t\t\treturn 0;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ddd6972b0a83e3e63e57b818ca4510d7", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class NewClass6 {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int scores = in.nextInt();\n int high = in.nextInt();\n in.nextLine();\n double[] score = new double[scores];\n for (int i = 0; i < scores; i++) {\n score[i] = in.nextDouble();\n }\n in.nextLine();\n\n System.out.println(addition(score, scores, high));\n\n }\n\n public static int addition(double[] score, int scores, int high) {\n double total = 0;\n double avg = 0;\n int temp = scores;\n for (int i = 0; i < score.length; i++) {\n total += score[i];\n }\n if ((total+high) / ++scores > high-0.5) {\n return 1;\n } else {\n avg = total/scores;\nimport java.util.*;\n\npublic class NewClass6 {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int scores = in.nextInt();\n double high = in.nextDouble();\n in.nextLine();\n double[] score = new double[scores];\n for (int i = 0; i < scores; i++) {\n score[i] = in.nextDouble();\n }\n in.nextLine();\n\n System.out.println(addition(score, scores, high));\n\n }\n\n public static int addition(double[] score, int scores, double high) {\n double total = 0;\n int temp=scores;\n for (int i = 0; i < score.length; i++) {\n total += score[i];\n }\n double avg = total/scores;\n if (avg > high - 0.5) {\n return 0;\n } else {\n while (avg < high-0.5) {\n total += high;\n scores++;\n avg = total/(double)scores;\n }\n return scores-temp;\n }\n }\n}\n\n while (avg < high - 0.5) {\n total += high;\n scores++;\n avg = total / scores;\n }\n return scores - temp;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7ef66e63b9fa9590265d817cc0c4ec99", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class TestOOP extends MainOOP {\n\n public static void main(String[] args) {\n\n try {\n BufferedReader br\n = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st= new StringTokenizer(br.readLine());\n int a=Integer.parseInt(st.nextToken());\n int b=Integer.parseInt(st.nextToken());\n int[] seg={6,2,5,5,4,5,6,4,7,6};\n int sum=0; int r=0,l=0;\n for (int i = a; i <=b; i++) {\n r=i;\n while(r>0){\n l= r%10 ;\n r= r/10 ;\n sum+= seg[l] ;\n \n }\n \n }\n System.out.println(sum);\n \n\n \n \n \n \n \n \n \n \n } catch (Exception e) {\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f9ea1c3ece7afcfb5ada0dfb97ee309f", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n static int[] digitSegments = new int[] { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };\n \n static int countSegments(int n) {\n int segments = 0;\n while(n > 0) {\n segments += digitSegments[n % 10];\n n /= 10;\n }\n }\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 segments = 0;\n for (int i = a; i <= b; ++i) {\n segments += countSegments(i);\n }\n System.out.println(segments);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "79fd7b72d89b83584f52e6a484ebb2d0", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class CodeForces {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x1,x2;\n\t\tint counter=0;\n\t\tint segment[] = {6,2,5,5,4,5,6,3,7,6};\n\t\tx1=sc.nextInt();\t\t\n\t\tx2=sc.nextInt();\t\t\n\t\tfor (int i = x1; i <= x2; i++) {\n\t\t\tint temp=i;\n\t\t\twhile(temp!=0){\n\t\t\t\tcounter += segment[temp%10];\n\t\t\t\ttemp/=10;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(counter);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fc31acdf0d401fc67061184a10a48cd7", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000} {"lang": "Java 7", "source_code": "//package codeforce;\n\nimport java.util.HashMap;\nimport java.util.Scanner;\n\n/* @author Kbk*/\npublic class Calculator{\n HashMap has=new HashMap();\n public void solve(){\n has.put(0,6);\n has.put(1,2);\n has.put(2,5);\n has.put(3,5);\n has.put(4,4);\n has.put(5,5);\n has.put(6,6);\n has.put(7,3);\n has.put(8,7);\n has.put(9,6);\n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int segments=0;\n for(int i=a;i<=b;i++){\n int len=String.valueOf(i).length();\n int data=i;\n for(int j=0;j \" + value);\n }\n\n\n public static void DebugVariable(String variable, int value) {\n System.err.println(\"DEBUG Info: \" + variable + \" => \" + value);\n }\n\n\n public static void DebugVariable(String variable, long value) {\n System.err.println(\"DEBUG Info: \" + variable + \" => \" + value);\n }\n\n public static void DebugArray(int[] value) {\n for (int i = 0; i < value.length; i++) {\n\n System.err.println(\"DEBUG Info: \" + i + \" => \" + value[i]);\n }\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "702d2a7387072e6269bb831691da3020", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class JavaApplication15 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\tString s = in.nextLine();\n\tint total=0;\n\tfor(int i=0;i'1')\n {\n\t\t\ttotal=total+(int)Math.pow(2, s.length()-i)-1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tSystem.out.println(total);", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d65d92a7624667da5fc6a1eafd68a1cf", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n static int ans=0;\n static int n=0;\n static int k=0;\n public static void fun(int n)\n {\n if(n==0)\n return;\n int k=n;\n while(k>0)\n {\n if(k%10>1)\n break;\n k=k/10;\n }\n if(k==0)\n ans++;\n fun(n-1);\n }\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n n = s.nextInt();\n fun(n);\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cc870d07c8c29996af176092432c23da", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class RunningStudent {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int input = scanner.nextInt();\n for(int i=1; i<=1<<9; i++) {\n String bin = Integer.toBinaryString(i);\n int ii = Integer.parseInt(bin);\n if(ii > input) {\n System.out.println(i-1);\n return;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dfdd9e0ca9f876aed0380b67701f578b", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class solveC {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner f = new Scanner(System.in);\n\t\tStringTokenizer st = new StringTokenizer(f.nextLine());\n\n\n\t\tdouble p = Double.parseDouble(st.nextToken());\n\t\tdouble q = Double.parseDouble(st.nextToken());\n\n\t\tdouble A = p / q;\n\t\tint N = 20000000;\n\t\tboolean[] isPrime = new boolean[N + 1];\n\t\tfor (int i = 2; i <= N; i++) {\n\t\t\tisPrime[i] = true;\n\t\t}\n\t\tfor (int i = 2; i * i <= N; i++) {\n\t\t\tif (isPrime[i]) {\n\t\t\t\tfor (int j = i; i * j <= N; j++) {\n\t\t\t\t\tisPrime[i * j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint ans = 0;\n\n\t\tint[] pi = new int[N + 1];\n\t\tint[] rub = new int[N + 1];\n\n\t\tfor (int i = 1; i <= N; i++) {\n\t\t\tpi[i] = pi[i - 1];\n\t\t\trub[i] = rub[i - 1];\n\t\t\tif (isPrime[i]) {\n\t\t\t\tpi[i]++;\n\t\t\t}\n\t\t\tif (isPalindrome(i))\n\t\t\t\trub[i]++;\n\n\t\t\tdouble pibyrub = (((double) pi[i]) / rub[i]);\n\t\t\tif (pibyrub <= A) {\n\t\t\t\tans = i;\n\t\t\t}\n\n\t\t}\n\t\tif (ans == 0)\n\t\t\tSystem.out.println(\"Palindromic tree is better than splay tree\");\n\t\telse\n\t\t\tSystem.out.println(ans);\n\n\n\n\n\n\t}\n\n\tpublic static int gcd(int p, int q) {\n\t\tif (q == 0) return p;\n\t\telse return gcd(q, p % q);\n\t}\n\n\tpublic static boolean isPalindrome(int x) {\n\t\tString g = Integer.toString(x);\n\t\treturn g.equals(new StringBuilder(g).reverse().toString());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "92b4d4163fcc6be92a6ba930d2c4b793", "src_uid": "e6e760164882b9e194a17663625be27d", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class palindrome {\n\tpublic static void main(String args[]) throws Exception {\n\t\tScanner in = new Scanner(new File(System.in));\n\t\tint p = in.nextInt(), q = in.nextInt();\n\t\tint n = 1200000;\n\t\tboolean[] arr = new boolean[n];\n\t\tint[] pi = new int[n];\n\t\tint[] pal = new int[n];\n\t\tpi[0] = 0;\n\t\tpi[1] = 0;\n\t\tpal[0] = 0;\n\t\tpal[1] = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = true;\n\t\t}\n\t\tarr[0] = false;\n\t\tarr[1] = false;\n\t\tfor (int i = 2; i < n; i++) {\n\t\t\tpi[i] = pi[i - 1];\n\t\t\tpal[i] = pal[i - 1] + isPalindrome(i);\n\t\t\tif (arr[i] && (long) i * i < n) {\n\t\t\t\tfor (int j = i * i; j < n; j += i) {\n\t\t\t\t\tarr[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (arr[i]) pi[i]++;\n\t\t}\n\t\tint a = 0;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tif (pi[i] <= p * pal[i] / q) a = i;\n\t\t}\n\t\tSystem.out.println(a);\n\t}\n\tpublic static int isPalindrome(int n) {\n\t\tString str = n + \"\";\n\t\tfor (int i = 0; i < str.length() - 1; i++) {\n\t\t\tif (str.charAt(i) != str.charAt(str.length() - i - 1)) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\treturn 1;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6d14b60e441ee82ba13178080773dd06", "src_uid": "e6e760164882b9e194a17663625be27d", "difficulty": 1600} {"lang": "Java 8", "source_code": " \n\u2192 \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434\nimport 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/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Hippskill (Hippskill@gmail.com)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n boolean[] generate_polyn(int n) {\n boolean[] polyn = new boolean[n + 1];\n for (int i = 1; i < n; i++) {\n String new_num = Integer.toString(i);\n String new_num1 = new StringBuffer(new_num).reverse().toString();\n if (new_num.equals(new_num1))\n polyn[i] = true;\n }\n return polyn;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n boolean[] primes = IntegerUtils.generatePrimalityTable(1000000);\n boolean[] polyn = generate_polyn(1000000);\n polyn[0] = false;\n int was_primes = 0;\n int was_polyn = 0;\n int p = in.readInt();\n int q = in.readInt();\n boolean ok = false;\n int ans = 0;\n for (int i = 0; i < 1000000; i++) {\n if (primes[i])\n was_primes++;\n if (polyn[i])\n was_polyn++;\n \n \n \n \n if (was_primes > (double) p / q * was_polyn) {\n ok = true;\n ans = i - 1;\n \n }\n }\n if (ok)\n out.printLine(ans);\n else\n out.printLine(\"Palindromic tree is better than splay tree\");\n }\n\n }\n\n static class IntegerUtils {\n public static boolean[] generatePrimalityTable(int upTo) {\n boolean[] isPrime = new boolean[upTo];\n if (upTo < 2)\n return isPrime;\n Arrays.fill(isPrime, true);\n isPrime[0] = isPrime[1] = false;\n for (int i = 2; i * i < upTo; i++) {\n if (isPrime[i]) {\n for (int j = i * i; j < upTo; j += i)\n isPrime[j] = false;\n }\n }\n return isPrime;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n 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 public void printLine(int i) {\n writer.println(i);\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "60ca921194b0194efdb5206c3bae6b10", "src_uid": "e6e760164882b9e194a17663625be27d", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class CF {\n\n\tstatic InputReader in = new InputReader(System.in);\n\tstatic long rightLimit = ((long)1 << 32l) / (long) 100;\n\n\tpublic static void main(String[] args) {\n\n\t\tint p = in.nextInt();\n\t\tint q = in.nextInt();\n\n\t\tint primes = 0;\n\t\tint palind = 0;\n\n\t\tint max = -1;\n\n\t\tfor (int i = 1; i < rightLimit; i++) {\n\t\t\tif (prime(i))\n\t\t\t\tprimes += q;\n\t\t\tif (palind(i))\n\t\t\t\tpalind += p;\n\n\t\t\tif (primes <= palind)\n\t\t\t\tmax = i;\n\t\t}\n\n\t\tSystem.out.println(max);\n\n\t}\n\n\tstatic boolean prime(int p) {\n\t\tif (p == 2)\n\t\t\treturn true;\n\t\tif (p == 1 || p % 2 == 0)\n\t\t\treturn false;\n\t\tfor (int i = 3; i * i <= p; i += 2)\n\t\t\tif (p % i == 0)\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tstatic boolean palind(int p) {\n\t\tString s = p + \"\";\n\n\t\tfor (int i = 0; i < s.length() / 2; i++)\n\t\t\tif (s.charAt(i) != s.charAt(s.length() - 1 - i))\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\n}\n\nclass InputReader {\n\tprivate BufferedReader reader;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\ttokenizer = null;\n\t}\n\n\tpublic String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic String readLine() {\n\t\ttry {\n\t\t\treturn reader.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66a81167d8c1d05a73b440592aef313d", "src_uid": "e6e760164882b9e194a17663625be27d", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class b{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tint n = s.length();\n\t\tint sevens = 0, fours = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tif(s.charAt(i) == '4'){\n\t\t\t\tfours++;\n\t\t\t{\n\t\t\telse if(s.charAt(i) == '7'){\n\t\t\t\tsevens++;\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tif(fours > sevens){\n\t\t\tans = 4;\n\t\t}\n\t\telse if(sevens < fours){\n\t\t\tans = 7;\n\t\t}\n\t\telse if(sevens == 0 && fours == 0){\n\t\t\tans = -1;\n\t\t}\n\t\telse{\n\t\t\tans = 4;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1fffed5bca6eca73e13a174fa5d013b0", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class lucky {\n public static void main(String[]args){\n Scanner sc= new Scanner(System.in);\n 4 String s=sc.next();\n int c=0,\n int d=0;\n for(int i=0;i=d)\n System.out.println(4);\n else System.out.println(7);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "294d20c527884d0a71ce8adc34ad4acc", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\nimport java.util.BitSet;\npublic class A { \n\t\t public static void main(String[] args) {\n\t\t FastReader sc=new FastReader();\n\t\t String s=sc.next();\n\t\t int c1=0,c2=0;\n\t\t for(int i=0;i=c2) System.out.println(4);\n\t\t else if(c2>c1) System.out.println(7);\n\t\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 \n\t\t \n\t\t \n\t\t \n\t\t \n\t\t static class FastReader\n\t\t {\n\t\t BufferedReader br;\n\t\t StringTokenizer st;\n\t\t \n\t\t public FastReader()\n\t\t {\n\t\t br = new BufferedReader(new\n\t\t InputStreamReader(System.in));\n\t\t }\n\t\t \n\t\t String next()\n\t\t {\n\t\t while (st == null || !st.hasMoreElements())\n\t\t {\n\t\t try\n\t\t {\n\t\t st = new StringTokenizer(br.readLine());\n\t\t }\n\t\t catch (IOException e)\n\t\t {\n\t\t e.printStackTrace();\n\t\t }\n\t\t }\n\t\t return st.nextToken();\n\t\t }\n\t\t \n\t\t int nextInt()\n\t\t {\n\t\t return Integer.parseInt(next());\n\t\t }\n\t\t \n\t\t long nextLong()\n\t\t {\n\t\t return Long.parseLong(next());\n\t\t }\n\t\t \n\t\t double nextDouble()\n\t\t {\n\t\t return Double.parseDouble(next());\n\t\t }\n\t\t \n\t\t String nextLine()\n\t\t {\n\t\t String str = \"\";\n\t\t try\n\t\t {\n\t\t str = br.readLine();\n\t\t }\n\t\t catch (IOException e)\n\t\t {\n\t\t e.printStackTrace();\n\t\t }\n\t\t return str;\n\t\t }\n\t\t }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "200f01af0ed8306b3d0f52b5528466fb", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class LackPodstroka\n{\n public static void main(String[] args) \n {\n Scanner in = new Scanner(System.in);\n String data = in.next();\n char dat [] = new char[data.length()];\n dat = data.toCharArray();\n String a[] = new String[dat.length];\n for (int i = 0; i < a.length; i++)\n {\n a[i] = Character.toString(dat[i]);\n }\n int data_[] = new int[data.length()];\n int dano [] = new int[]{4,7};\n for (int i = 0; i < data_.length; i++)\n {\n data_[i] = Integer.parseInt(a[i]);\n }\n int FOUR = 0;\n int SEVEN = 0;\n int FOUR_SEVEN = 0;\n int SEVEN_FOUR = 0;\n for (int i = 0; i < data_.length; i++)\n {\n if(data_[i]==dano[0])\n {\n FOUR++;\n }\n if(data_[i]==dano[1])\n {\n SEVEN++;\n }\n if(i != data_.length-1)\n {\n if(data_[i]==dano[0]&&data_[i+1]==dano[1])\n {\n FOUR_SEVEN++;\n }\n if(data_[i]==dano[1]&&data_[i+1]==dano[0])\n {\n SEVEN_FOUR++;\n }\n }\n }\n if(FOUR==0&&SEVEN==0&&FOUR_SEVEN==0&&SEVEN_FOUR==0)\n {\n System.out.print(\"-1\");\n }\n \n if(FOUR>0&&SEVEN>0&&FOUR_SEVEN>0&&SEVEN_FOUR>0)\n {\n if(FOUR==SEVEN && SEVEN==FOUR_SEVEN)\n {\n System.out.print(\"4\");\n }\n \n if(FOUR>SEVEN&&FOUR>FOUR_SEVEN&&FOUR>SEVEN_FOUR)\n {\n System.out.print(\"4\");\n }\n if(SEVEN>FOUR&&SEVEN>FOUR_SEVEN&&SEVEN>SEVEN_FOUR)\n {\n System.out.print(\"7\");\n }\n if(SEVEN_FOUR>SEVEN&&SEVEN_FOUR>FOUR_SEVEN&&SEVEN_FOUR>FOUR)\n {\n System.out.print(\"74\");\n }\n if(FOUR_SEVEN>SEVEN&&FOUR_SEVEN>FOUR&&FOUR_SEVEN>SEVEN_FOUR)\n {\n System.out.print(\"47\");\n }\n } \n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b91cdef84a495966e394e56ad0e5c44d", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000} {"lang": "Java 6", "source_code": "va.util.Scanner;\n\npublic class C {\n\n /**\n * @param args\n */\n static int a , b ,n;\n static long[][] dp;\n static int mod = 1000000007;\n public static void main(String[] args)\n {\n// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n Scanner scan = new Scanner(System.in);\n a = scan.nextInt();\n b = scan.nextInt();\n n = scan.nextInt();\n long res = 0;\n long[] f = new long[n+1];\n f[0] = f[1] = 1;\n for(int i = 2 ; i <= n;i++)\n f[i] = (f[i-1]*i)%mod;\n for(int x = 0; x <= n;x++)\n {\n int y = n-x;\n long sum = (long)(a*x)+(long)(y*b);\n int c = 1,t;\n while(sum > 0 && c == 1)\n {\n t = (int) (sum%10);\n if(t != a && t != b)\n c= 0;\n sum/=10;\n }\n if(c == 1)\n res = (res+f[n]/(f[x]*f[y]))%mod;\n }\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "07f845d162fff9c518c2d3b058fb40d1", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n BeautifulNumbers solver = new BeautifulNumbers();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BeautifulNumbers {\n static long fact;\n static long MOD = (long) (Math.pow(10, 9) + 7);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long a = in.nextLong();\n long b = in.nextLong();\n int n = in.nextInt();\n fact = new long[n + 1];\n long ans = 0;\n\n fact[0] = 1;\n for (int i = 1; i <= n; i++) {\n fact[i] = i * fact[i - 1];\n }\n\n\n for (int i = 0; i <= n; i++) {\n long val = (i * a) + ((n - i) * b);\n\n if (check(val, a, b)) {\n ans += getComb(i, n);\n ans %= MOD;\n }\n\n }\n\n out.println(ans);\n }\n\n private long getComb(int i, int n) {\n long mul = fact[n];\n long div = fact[n - i] * fact[i];\n mul %= MOD;\n div %= MOD;\n\n div = pow(div, MOD - 2);\n\n return (mul * div) % MOD;\n\n }\n\n private long pow(long base, long p) {\n if (p == 0) {\n return 1;\n }\n\n long po = pow(base, p / 2) % MOD;\n po = (po * po) % MOD;\n\n if (p % 2 == 0) {\n return po % MOD;\n } else {\n return (po * base) % MOD;\n }\n }\n\n private boolean check(long val, long a, long b) {\n\n while (val > 0) {\n if (val % 10 == a || val % 10 == b) {\n val = val / 10;\n } else {\n return false;\n }\n }\n\n return true;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0df3a717c2d87bc103528e7bc8778767", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n public static long mod = 1000000007;\n \n public static void main(String[] args)throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n StringTokenizer st = new StringTokenizer(br.readLine());\n char[] c = st.nextToken().toCharArray();\n int n = c.length;\n st = new StringTokenizer(br.readLine());\n int k = Integer.parseInt(st.nextToken());\n long[] t = new long[n+1];\n int nb = 0;\n for(int i=0;iInputReader.inf) {\n\t\t\t\tdp[n][r] %= InputReader.inf;\n\t\t\t}\n\t\t\treturn dp[n][r];\n\t\t/*//use this method only when calculating ncr less times\n\t\tif(r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)\n \tlong ans = 1;\n\t\tfor(int i = 1; i <= r; i++) {\n\t\t\tans *= n - r + i;\n\t\t\tans /= i;\n\t\t}\n\t\treturn ans;*/\n\t\t}\n\t\t\n\t\tprivate static boolean check (long os) {\n\t\t\tString str = Long.toString (os);\n\t\t\tint len = str.length ();\n\t\t\tfor (int i = 0; i1e14) ans%=inf\n\t\t\tlong os = -a+b*(n+1);\n\t\t\tfor (int i = 0; i<=n; i++) {\n\t\t\t\tos += a;\n\t\t\t\tos -= b;\n\t\t\t\tif (check (os)) {\n\t\t\t\t\tif (i>n/2) {\n\t\t\t\t\t\tans += ncr (n, n-i);\n\t\t\t\t\t}\n\t\t\t\t\telse ans += ncr (n, i);\n\t\t\t\t\tif (ans>1e14) {\n\t\t\t\t\t\tans %= InputReader.inf;\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\t\t\n\t}\n\t\n\tstatic class InputReader {\n\t\tprivate BufferedReader reader;\n\t\tprivate StringTokenizer tokenizer;\n\t\tpublic static final int inf = 1000000007;\n\t\t\n\t\tpublic InputReader (InputStream stream) {\n\t\t\treader = new BufferedReader (new InputStreamReader (stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\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\tString str;\n\t\t\t\t\tif ((str = reader.readLine ()) != null) tokenizer = new StringTokenizer (str);\n\t\t\t\t\telse return null;//to detect eof\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken ();\n\t\t}\n\t\t\n\t\tpublic int nextInt () {\n\t\t\treturn Integer.parseInt (next ());\n\t\t}\n\t\t\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4e3dd81c6f81d2000a701787d09d2c23", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800} {"lang": "Java 8", "source_code": "mport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scanner= new Scanner(System.in);\n int n=scanner.nextInt();\n int m=scanner.nextInt();\n int z=scanner.nextInt();\n int counter=0;\n for (int i=1; i<=z; i++ ){\n if (n==m){\n counter=z;\n break;\n }else{\n if ((i%n==0 || i==n) && (i%m==0 || i==m)){\n counter++;\n }\n }\n\n }\n System.out.println(counter);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "35dd8647c00984f7cd416468f1607a81", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Main {\n \n\tpublic static void main(String[] args) throws Exception {\n \n\t\tBufferedReader f=new BufferedReader(new FileReader(System.in));\t\n\t\tPrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(System.out)));\n\t\tStringTokenizer st=new StringTokenizer(f.readLine());\n \n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint m=Integer.parseInt(st.nextToken());\n\t\tint z=Integer.parseInt(st.nextToken());\n\t\tint kills=0;\n\n\t\tfor(int i = 1; i * m <= z; i++) {\n\t\t\tint c = i * m;\n\t\t\tif (c % n == 0)\n\t\t\t\tkills++;\n\t\t}\n\t\tout.println(kills);\n\t\t\n\t\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6d15f46c7a69ef11fa81858231c9c250", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class HelloWorld{\n\n public static void main(String []args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int m=sc.nextInt();\n int z=sc.nextInt();\n int g=gcd(n,m);\n int lcm=(n*m)/g;\n System.out.println(z/lcm);\n }\n public static int gcd(int a,int b)\n {\n if(b==0)\n return a;\n return(b,a%b);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5542b31fc84373576071ee58b14e7d7d", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n \npublic class Main {\n \n\tpublic static void main(String[] args) throws IOException {\n \n\t\tBufferedReader f=new BufferedReader(new FileReader(System.in));\t\n\t\tPrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(System.out)));\n\t\tStringTokenizer st=new StringTokenizer(f.readLine());\n \n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint m=Integer.parseInt(st.nextToken());\n\t\tint z=Integer.parseInt(st.nextToken());\n\t\tint kills=0;\n\n\t\tfor(int i = 1; i * m <= z; i++) {\n\t\t\tint c = i * m;\n\t\t\tif (c % n == 0)\n\t\t\t\tkills++;\n\t\t}\n\t\tout.println(kills);\n\t\t\n\t\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5e766a5028ab30acc61735c7f44aafce", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\n \npublic class Main{\n \n\tpublic static void main(String[] args) throws Exception {\n \n\t\tBufferedReader f=new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(\n\t\tSystem.out)));\n\t\tStringTokenizer st=new StringTokenizer(f.readLine());\n \n\t\tint a=Integer.parseInt(st.nextToken());\n\t\tint x= 0;\n int y = 0;\n int min = 100000000000000000000;\n\t\tfor ( int i = 1; i < Math.sqrt(a)+1; i++ ){\n if (a%i == 0 && a>=i){\n int b = a/i; \n if (min > Math.abs(b-i)){\n x = b;\n y = i; \n min = b-i;\n \n }\n \n }\n \n }\n System.out.println(y);\n System.out.println(x);\n\t\tSystem.out.close();\n\t\t}\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dfadc15de9986951347afc48fdab9714", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.*;\n\n/**\n * Generated by Contest helper plug-in\n * Actual solution is at the bottom\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new StreamInputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\trun(in, out);\n\t}\n\n\tpublic static void run(InputReader in, PrintWriter out) {\n\t\tSolver solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tExit.exit(in, out);\n\t}\n}\n\nabstract class InputReader {\n\tprivate boolean finished = false;\n\n\tpublic abstract int read();\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 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\tprivate boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic void setFinished(boolean finished) {\n\t\tthis.finished = finished;\n\t}\n\n\tpublic abstract void close();\n}\n\nclass StreamInputReader extends InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar, numChars;\n\n\tpublic StreamInputReader(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 void close() {\n\t\ttry {\n\t\t\tstream.close();\n\t\t} catch (IOException ignored) {\n\t\t}\n\t}\n}\n\nclass Exit {\n\tprivate Exit() {\n\t}\n\n\tpublic static void exit(InputReader in, PrintWriter out) {\n\t\tin.setFinished(true);\n\t\tin.close();\n\t\tout.close();\n\t}\n}\n\ninterface Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out);\n}\n\nclass GeometryUtils {\n\tpublic static double epsilon = 1e-8;\n\n\t}\n\nclass TaskA implements Solver {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint num = in.readInt();\n\t\tdouble sqrt = Math.sqrt(num);\n\t\tint intSqrt = (int)(sqrt);\n\t\tif (sqrt == intSqrt) {\n\t\t\tout.print(intSqrt);\n\t\t\tout.print(\" \");\n\t\t\tout.print(intSqrt);\n\t\t} else {\n\t\t\tfor (int i = intSqrt; i >= 0; i--) {\n\t\t\t\tif (num % i == 0) {\n\t\t\t\t\tout.print(num/i);\n\t\t\t\t\tout.print(\" \");\n\t\t\t\t\tout.print(i);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b903e01f9a13329d6374961e2949037d", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class SolutionA {\n public static void main(String[] args){\n int pixelNumber = new Scanner(System.in).nextInt();\n int a=1;\n float temp;\n temp = pixelNumber;\n for (int i=2;i<100000;i++){\n if (temp>=a) {\n temp/=i;\n if (temp == Math.round(temp)){\n a*=i;\n i--;\n \n continue;\n } else {\n temp*=i;\n continue;\n }\n } else break;\n }\n System.out.println((Integer)temp + \" \" + a); \n } \n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b5c7ab9815f85067334e0a2f1ef5715e", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class SolutionA {\n public static void main(String[] args){\n int pixelNumber = new Scanner(System.in).nextInt();\n int a=1,b;\n float temp;\n temp = pixelNumber;\n for (int i=2;i<100000;i++){\n if (temp>=a) {\n temp/=i;\n if (temp == Math.round(temp)){\n a*=i;\n i--;\n \n continue;\n } else {\n temp*=i;\n continue;\n }\n } else break;\n }\n b = (Integer) temp;\n System.out.println(b + \" \" + a); \n } \n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7acb990733e41fefb7c3706343c05653", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWrite;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Main {\n\n private static final InputStreamReader standardInput = new InputStreamReader(System.in);\n private static final BufferedReader bufferedReader = new BufferedReader(standardInput);\n private static final Scanner scanner = new Scanner(bufferedReader);\n\n private static final OutputStreamWriter standardOutput = new OutputStreamWriter(System.out);\n private static final BufferedWriter bufferedWriter = new BufferedWriter(standardOutput);\n private static final PrintWriter printWriter = new PrintWriter(bufferedWriter);\n\n public static void main(String[] args) {\n long l = scanner.nextLong();\n long r = scanner.nextLong();\n if (l % 2 == 0 && r - l >= 2) {\n printWriter.println(l + \" \" + (l + 1) + \" \" + (l + 2));\n } else if (r - l < 3) {\n printWriter.println(-1);\n } else {\n printWriter.println((l + 1) + \" \" + (l + 2) + \" \" + (l + 3));\n }\n printWriter.flush();\n scanner.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "51251bf1f12c04d0ac9b49581f7f55fc", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Test {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\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\n\tstatic 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\tstatic /*int*/long gcd(/*int*/long x, /*int*/long y){\n \t if(x==0)\n \t return y;\n \t if(y==0)\n \t return x;\n \t /*int*/long r=0, a, b;\n \t a = (x > y) ? x : y; // a is greater number\n \t b = (x < y) ? x : y; // b is smaller number\n \t r = b;\n \t while(a % b != 0){\n \t r = a % b;\n \t a = b;\n \t b = r;\n \t }\n return r;\n }\t\n\n\t static class R implements Comparable{\n\t int x, y;\n\t public R(int x, int y) {\n\t this.x = x;\n\t this.y = y;\n\t }\n\t public int compareTo(R o) {\n \t\treturn x-o.x; //Increasing order(Which is usually required)\n \t\t}\n\t } \n\n\tpublic static void main(String[] args) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\ttokenizer = null;\n\t\twriter = new PrintWriter(System.out);\n\t\tsolve();\n\t\treader.close();\n\t\twriter.close();\n\t}\n\t\n\tprivate static void solve() throws IOException {\n\t\tlong l = nextLong();\n\t\tlong r = nextLong();\n\t\tif(r-l<3){\n\t\t writer.println(\"-1\");\n\t\t return;\n\t\t}\n\t\tif(l%2!=1){\n\t\t l++;\n\t\t}\n\t\twriter.println(l+\" \"+(l+1)+\" \"(l+2));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2eeed6eb6f0d873a405cb43f749a94c7", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\n\npublic class counterexample {\n\tpublic static BigInteger HCF(BigInteger a, BigInteger b) {\n\t\tif (b.compareTo(BigInteger.ZERO) == 0)\n\t\t\treturn a;\n\t\treturn HCF(b, a.mod(b));\n\t}\n\n\tpublic static void main(String args[]) {\n\t\tint flag = 0;\n\t\tScanner sc = new Scanner(System.in);\n\t\tBigInteger l = sc.nextBigInteger();\n\t\tBigInteger r = sc.nextBigInteger();\n\t\tBigInteger a = l;\n\t\tBigInteger b = l.add(BigInteger.ONE);\n\t\tBigInteger c = l.add(BigInteger.TWO);\n\t\twhile (c.compareTo(r) < 1 || c.compareTo(r) == 0) {\n\n\t\t\tif (HCF(b, c).compareTo(BigInteger.ONE) == 0 && HCF(a, c).compareTo(BigInteger.ONE) != 0) {\n\t\t\t\tflag = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tc = c.add(BigInteger.ONE);\n\t\t\t// System.out.print(c+\" \");\n\t\t}\n\t\tif (flag == 1)\n\t\t\tSystem.out.println(a + \" \" + b + \" \" + c);\n\t\telse\n\t\t\tSystem.out.println(-1);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6d2f82060a156651bda0abf2cc259e20", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class coPrime {\n\n\tpublic static void main(String[] args) {\n\tScanner scn = new Scanner(System.in);\n\tlong a=scn.nextLong();\n\tlong b= scn.nextLong();\n\tif(a-b==-1 ||a-b==1) {\n\t\tSystem.out.println(\"-1\");\n\t}\n\telse if(a%2==0 && b%2==0) {\n\t\tSystem.out.println(a+\" \"+(a+1)+\" \"+b);\n\t}\n\telse if(a%2==0 && b%2!=0)\n\t{\n\t\tSystem.out.println(a+\" \"+(a+1)+\" \"+(a+2));\n\t}\n\telse if(a%2!=0 && b%2==0) {\n\t\tSystem.out.println((a+1)+\" \"+(a+2)+\" \"+(a+3));\n\t}\n\telse \n\t\tSystem.out.println(a+\" \"+(a+1)+\" \"+b);\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e2889e93711cf255224d26978b88ee49", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\n// public class Solution\nclass Solution\n{\n\tstatic BufferedReader br;\n\tstatic String nextIntBuffer[];\n\tstatic int nextIntBase;\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\tstatic String next() throws IOException {\n\t\tif(nextIntBase>=nextIntBuffer.length) {\n\t\t\tnextIntBase =0;\n\t\t\tnextIntBuffer = br.readLine().split(\" \");\n\t\t}\n\t\treturn nextIntBuffer[nextIntBase++];\n\t}\n\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\tnextIntBuffer = new String[0];\n\n\t\tString[] time=next().split(\":\");\n\t\tint hr=Integer.parseInt(time[0]);\n\t\tint min=Integer.parseInt(time[1]);\n\t\tint current=hr*60+min;\n\n\t\tString mins=\"\";\n\t\tif(hr/10==0)\n\t\t\tmins=hr+\"0\";\n\t\telse\n\t\t\tmins=(new StringBuilder(time[0])).reverse().toString();\n\t\tint new_min=Integer.parseInt(mins)+hr*60;\n\t\tif(new_min23)\n\t\t\t{\n\t\t\t\tnew_min=24*60;\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\tif((hr+1)/10==0)\n\t\t\t\t\tmins=(hr+1)+\"0\";\n\t\t\t\telse\n\t\t\t\t\tmins=(new StringBuilder(time[0]+1)).reverse().toString();\n\t\t\t\tnew_min=Integer.parseInt(mins%60)+(hr+1)*60;\n\t\t\t}\n\t\t}\n\t\t// System.out.println(mins);\n\n\t\tSystem.out.println(new_min-current);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7ec561baa110579e8e4c521678ed6c0c", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000} {"lang": "Java 8", "source_code": "package problems;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * Created by masoud on 6/18/17.\n */\npublic class Problem419A {\n private static boolean isPalindrome(String str){\n int i = 0, j = str.length()-1;\n while(i < j){\n if (str.charAt(i) != str.charAt(j))\n return false;\n i++;\n j--;\n }\n return true;\n }\n private static String makeString(int time){\n String ret = \"\";\n if (time < 10)\n ret+=\"0\";\n return (ret+time);\n }\n private static String walkString(String curTime){\n String hourStr = curTime.substring(0, 2);\n String minuteStr = curTime.substring(3);\n int newMinute = Integer.parseInt(minuteStr) + 1;\n int newHour = Integer.parseInt(hourStr);\n if (newMinute == 60){\n newMinute = 0;\n newHour = (newHour+1)%24;\n }\n return makeString(newHour)+\":\"+makeString(newMinute);\n }\n public static void main(String [] args) {\n String str;\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n try {\n str = reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n int count = 0;\n while(!isPalindrome(str)){\n str = walkString(str);\n count++;\n }\n System.out.println(count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7df77b345ae941f17f9b88b66e480838", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class JavaApplication8 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String x = in.next();\n String []time = x.split(\":\");\n String t = new StringBuffer(time[0]).reverse().toString();\n if(time[0].charAt(0) == time[1].charAt(1) && time[0].charAt(1) == time[1].charAt(0))\n System.out.println(0);\n else if(Integer.parseInt(time[1]) < Integer.parseInt(t))\n System.out.println(Integer.parseInt(t) - Integer.parseInt(time[1]));\n else{\n int plus_m = Integer.parseInt(time[0]) + 1 == 24 ? 0 : Integer.parseInt(time[0]) + 1 ;\n String s = new StringBuffer(Integer.toString(plus_m)).reverse().toString();\n System.out.println((60-Integer.parseInt(time[1])) + Integer.parseInt(s));\n }\n }\n \n \n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65cd4313760b26b8f9a29de882f15dd9", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\npublic class cf_816a{\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 Added by me.\n */\n public String readWord() 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 == ' ' || c=='\\n') //care ADD ANY WHITESPACE CHAR??\n break;\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\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 } //static class Reader\n \n public static void main(String[] args) throws IOException{\n Reader s = new Reader(); //Initialize a reader!\n boolean DEB = false;\n StringBuilder in = new StringBuilder(s.readWord());\n int h = Integer.parseInt(in.substring(0, 2));\n int m = Integer.parseInt(in.substring(3, 5));\n StringBuilder rev2 = new StringBuilder(in);\n StringBuilder rev = rev2.reverse();\n \n int rm = Integer.parseInt(rev.substring(4,6));\n if(DEB) System.out.println(in);\n if(DEB) System.out.println(rev);\n \n if((in.toString()).equals(rev.toString())) System.out.println(\"0\");\n else if(h<5){ // h==0,1,...4\n \n if(m <= rm) System.out.println(rm-m);\n else System.out.println(rm-m+60+10);\n }\n else if(h==5){\n if(m <= rm) System.out.println(rm-m);\n else System.out.println(240+60-m+1);\n }\n else if(h>=6 && h<10){\n System.out.println((9-h)*60 + 61 - m);\n }\n else if(h<15){\n if(m <= rm) System.out.println(rm-m);\n else System.out.println(rm-m+60+10);\n }\n else if(h==15){\n if(m <= rm) System.out.println(rm-m);\n else System.out.println(240+60-m+2);\n }\n else if(h<20){\n System.out.println((19-h)*60 + 62 - m);\n }\n else if(h < 23){\n if(m < =rm) System.out.println(rm-m);\n else System.out.println(rm-m+60+10);\n }\n else if(h==23){\n if(m <= rm) System.out.println(rm-m);\n else System.out.println(60 - m);\n }\n\n } //main\n\n\n} //public class Contest", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1abc2ec8513a5fbbbdbb26ff1d8b7a0d", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\n\npublic class CF513B {\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n long k = in.nextLong() - 1;\n int[] ans = new int[n];\n int from = 0;\n int j = n;\n for (int i = 0; from < n; ++i) {\n while (from < n - 1 && k >= 1L << (n - from - 2)) {\n k -= 1L << (n - from - 2);\n ans[--j] = from++;\n }\n ans[i] = from;\n from++;\n }\n for (int i = 0; i < n; ++i) {\n out.print((ans[i] + 1) + \" \");\n }\n out.println();\n rec(0, 0, new int[n]);\n }\n\n private static void rec(int it, int mask, int[] p) {\n if (it == p.length) {\n int sum = 0;\n for (int i = 0; i < p.length; ++i) {\n int v = p[i];\n for (int j = i; j < p.length; ++j) {\n v = Math.min(v, p[j]);\n sum += v;\n }\n }\n System.err.println(Arrays.toString(p) + \" \" + sum);\n return;\n }\n for (p[it] = 0; p[it] < p.length; ++p[it]) {\n if ((mask & (1 << p[it])) == 0) {\n rec(it + 1, mask | (1 << p[it]), p);\n }\n }\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9070dc7b3c1ba46fddaebb1bc92c53a5", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.List;\nimport java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Collections;\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 */\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\tTaskB1 solver = new TaskB1();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB1 {\n\n public static long counter = 0;\n public static int n;\n public static long m;\n\n public void find(Integer i, PrintWriter out, ArrayList left, ArrayList right) {\n left.add(i);\n if(i == n || counter >= m) {\n counter++;\n if(counter == m) {\n for(Integer j : left) {\n out.print(j + \" \");\n }\n List reversed = (ArrayList)right.clone();\n Collections.reverse(reversed);\n for(Integer j : reversed) {\n out.print(j + \" \");\n }\n out.println();\n }\n return;\n }\n for(Integer j = i + 1; j <= n; j++) {\n find(j, out, left, right);\n left.remove(j);\n right.add(j);\n }\n for(Integer j = n; j > i; j--) {\n right.remove(j);\n }\n left.remove(i);\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n n = in.nextInt();\n m = in.nextLong();\n\n ArrayList left = new ArrayList();\n ArrayList right = new ArrayList();\n for(Integer i = 1; i <= n; i++) {\n find(i, out, left, right);\n right.add(i);\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cf0591d50f227c046e94e3721c0abd04", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1800} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Deque;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\n/*\npublic class _512A {\n\n}\n\n */\n\npublic class _513B {\n\tpublic void solve() throws FileNotFoundException {\n\t\tInputStream inputStream = System.in;\n\n\t\tInputHelper inputHelper = new InputHelper(inputStream);\n\n\t\tPrintStream out = System.out;\n\n\t\t//actual solution\n\t\tint n = inputHelper.readInteger();\n\t\tint m = inputHelper.readInteger();\n\t\t\n\t\tDeque p = new ArrayDeque();\n\t\t\n\t\tp.add(n);\n\t\t\n\t\tm--;\n\t\tfor(int i = n - 1, j = 0; i >= 1; i--, j++)\n\t\t{\n\t\t\tif((m & (1L << j)) == (1L << j))\n\t\t\t{\n\t\t\t\tp.addLast(i);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tp.addFirst(i);\n\t\t\t}\n\t\t}\n\n\t\tfor (Integer i : p) {\n\t\t\tSystem.out.print(i + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\t//end here\n\t}\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t(new _513B()).solve();\n\t}\n\n\tclass InputHelper {\n\t\tStringTokenizer tokenizer = null;\n\t\tprivate BufferedReader bufferedReader;\n\n\t\tpublic InputHelper(InputStream inputStream) {\n\t\t\tInputStreamReader inputStreamReader = new InputStreamReader(\n\t\t\t\t\tinputStream);\n\t\t\tbufferedReader = new BufferedReader(inputStreamReader, 16384);\n\t\t}\n\n\t\tpublic String read() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString line = bufferedReader.readLine();\n\t\t\t\t\tif (line == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\ttokenizer = new StringTokenizer(line);\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\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic Integer readInteger() {\n\t\t\treturn Integer.parseInt(read());\n\t\t}\n\n\t\tpublic Long readLong() {\n\t\t\treturn Long.parseLong(read());\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2e9753e1063f37d30d44c61a2094dba6", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1400} {"lang": "Java 8", "source_code": "import com.github.guliash.math.Helper;\n\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Artem Gilmudinov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tReader in = new Reader(inputStream);\n\t\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 int[] a;\n int n;\n public void solve(int testNumber, Reader in, PrintWriter out) {\n n = in.ni(); int m = in.ni();\n a = new int[n];\n for(int i = 0; i < n; i++) {\n a[i] = i;\n }\n boolean can = true;\n int max = 0;\n do {\n max = Math.max(max, findF());\n } while(Helper.nextPermutation(a));\n for(int i = 0; i < n; i++) {\n a[i] = i;\n }\n do {\n if(findF() == max) {\n m--;\n if(m == 0) {\n for(int i = 0; i < n; i++) {\n out.print((a[i] + 1) + \" \");\n }\n out.println();\n return;\n }\n }\n } while(Helper.nextPermutation(a));\n }\n public int findF() {\n int cur = 0;\n for(int i = 0; i < n; i++) {\n for(int j = i; j < n; j++) {\n int min = Integer.MAX_VALUE;\n for(int z = i; z <= j; z++) {\n min = Math.min(a[z], min);\n }\n cur += min;\n\n }\n }\n return cur;\n }\n}\n\nclass Reader {\n private BufferedReader in;\n private StringTokenizer st = new StringTokenizer(\"\");\n private String delim = \" \";\n\n public Reader(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n st = new StringTokenizer(rl());\n }\n return st.nextToken(delim);\n }\n\n public String rl() {\n try {\n return in.readLine();\n } catch(IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public int ni() {\n return Integer.parseInt(next());\n }\n\n public long nl() {\n return Long.parseLong(next());\n }\n\n public double nd() {\n return Double.parseDouble(next());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e6b3c985c7ab07199f3fe8ccc1812a98", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1400} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class _42_d2_B {\n\n public void solve() throws Exception {\n \n String a = nextWord(), b = nextWord();\n int base = 0;\n for (int i=0; ir) r=i;\n return r;\n }\n long minL(long... nums) {\n long r = INFL;\n for (long i: nums)\n if (ir) r=i;\n return r;\n }\n double minD(double... nums) {\n double r = INFD;\n for (double i: nums)\n if (ir) r=i;\n return r;\n }\n \n long sumArr(int[] arr) {\n long res = 0;\n for (int i: arr)\n res+=i;\n return res;\n }\n long sumArr(long[] arr) {\n long res = 0;\n for (long i: arr)\n res+=i;\n return res;\n }\n double sumArr(double[] arr) {\n double res = 0;\n for (double i: arr)\n res+=i;\n return res;\n }\n\n long partsFitCnt(long partSize, long wholeSize) {\n return (partSize+wholeSize-1)/partSize;\n }\n\n boolean odd(long num) {\n return (num&1)==1;\n }\n \n boolean hasBit(int num, int pos) {\n return (num&(1<0;\n }\n\n long binpow(int a, int n) {\n long r = 1;\n while (n>0) {\n if ((n&1)!=0) r*=a;\n a*=a;\n n>>=1;\n }\n return r;\n }\n\n boolean isLetter(char c) {\n return (c>='a' && c<='z') || (c>='A' && c<='Z');\n }\n boolean isLowercase(char c) {\n return (c>='a' && c<='z');\n }\n boolean isUppercase(char c) {\n return (c>='A' && c<='Z');\n }\n boolean isDigit(char c) {\n return (c>='0' && c<='9');\n }\n \n String stringn(String s, int n) {\n if (n<1) return \"\";\n StringBuilder sb = new StringBuilder(s.length()*n);\n for (int i=0; i=bufLim) fillBuf(); \n return (char)buf[bufPos++];\n }\n boolean hasInput() throws IOException {\n if (bufPos>=bufLim) fillBuf();\n return bufPos' ') {\n sb.append(c);\n c = inputReader.read();\n }\n return new String(sb);\n }\n String nextLine() throws IOException {\n StringBuilder sb = new StringBuilder();\n char c = inputReader.read();\n while (c<=' ') c=inputReader.read();\n while (c!='\\n' && c!='\\r') {\n sb.append(c);\n c = inputReader.read();\n }\n return new String(sb);\n }\n int nextInt() throws IOException {\n int r = 0;\n char c = nextNonWhitespaceChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r=c-48;\n c = nextChar();\n while (c>='0' && c<='9') {\n r*=10;\n r+=c-48;\n c=nextChar();\n }\n return neg ? -r:r;\n }\n long nextLong() throws IOException {\n long r = 0;\n char c = nextNonWhitespaceChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r = c-48;\n c = nextChar();\n while (c>='0' && c<='9') {\n r*=10L;\n r+=c-48L;\n c=nextChar();\n }\n return neg ? -r:r;\n }\n double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextWord());\n }\n int[] nextArr(int size) throws NumberFormatException, IOException {\n int[] arr = new int[size];\n for (int i=0; ir) r=i;\n return r;\n }\n long minL(long... nums) {\n long r = INFL;\n for (long i: nums)\n if (ir) r=i;\n return r;\n }\n double minD(double... nums) {\n double r = INFD;\n for (double i: nums)\n if (ir) r=i;\n return r;\n }\n \n long sumArr(int[] arr) {\n long res = 0;\n for (int i: arr)\n res+=i;\n return res;\n }\n long sumArr(long[] arr) {\n long res = 0;\n for (long i: arr)\n res+=i;\n return res;\n }\n double sumArr(double[] arr) {\n double res = 0;\n for (double i: arr)\n res+=i;\n return res;\n }\n\n long partsFitCnt(long partSize, long wholeSize) {\n return (partSize+wholeSize-1)/partSize;\n }\n\n boolean odd(long num) {\n return (num&1)==1;\n }\n \n boolean hasBit(int num, int pos) {\n return (num&(1<0;\n }\n\n long binpow(int a, int n) {\n long r = 1;\n while (n>0) {\n if ((n&1)!=0) r*=a;\n a*=a;\n n>>=1;\n }\n return r;\n }\n\n boolean isLetter(char c) {\n return (c>='a' && c<='z') || (c>='A' && c<='Z');\n }\n boolean isLowercase(char c) {\n return (c>='a' && c<='z');\n }\n boolean isUppercase(char c) {\n return (c>='A' && c<='Z');\n }\n boolean isDigit(char c) {\n return (c>='0' && c<='9');\n }\n \n String stringn(String s, int n) {\n if (n<1) return \"\";\n StringBuilder sb = new StringBuilder(s.length()*n);\n for (int i=0; i=bufLim) fillBuf(); \n return (char)buf[bufPos++];\n }\n boolean hasInput() throws IOException {\n if (bufPos>=bufLim) fillBuf();\n return bufPos' ') {\n sb.append(c);\n c = inputReader.read();\n }\n return new String(sb);\n }\n String nextLine() throws IOException {\n StringBuilder sb = new StringBuilder();\n char c = inputReader.read();\n while (c<=' ') c=inputReader.read();\n while (c!='\\n' && c!='\\r') {\n sb.append(c);\n c = inputReader.read();\n }\n return new String(sb);\n }\n int nextInt() throws IOException {\n int r = 0;\n char c = nextNonWhitespaceChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r=c-48;\n c = nextChar();\n while (c>='0' && c<='9') {\n r*=10;\n r+=c-48;\n c=nextChar();\n }\n return neg ? -r:r;\n }\n long nextLong() throws IOException {\n long r = 0;\n char c = nextNonWhitespaceChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r = c-48;\n c = nextChar();\n while (c>='0' && c<='9') {\n r*=10L;\n r+=c-48L;\n c=nextChar();\n }\n return neg ? -r:r;\n }\n double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextWord());\n }\n int[] nextArr(int size) throws NumberFormatException, IOException {\n int[] arr = new int[size];\n for (int i=0; i=0;i--,j--){\n\t\t\tif(j>=0) k=(s1.charAt(i)+s2.charAt(j)+k-96)/m;\n\t\t\telse k=(s1.charAt(i)+k-48)/m;\n\t\t}\n\t\tSystem.out.println(n+k);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "792f649f83e90e26f663e0635c79a930", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class CF46B {\n\n /**\n * @param args\n */\n \n int getInt(char c){\n return Integer.valueOf(new String(\"\"+c));\n }\n void func(){\n Scanner sc=new Scanner(System.in);\n String a=sc.next();\n String b=sc.next();\n int num=Integer.MIN_VALUE;\n for(int i=0;i':\n return 3;\n default:\n return 0;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3aab45f159cb1b4c77e26489e2a5455c", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class MyClass {\n public static void main(String args[]) {\n Scanner scan = new Scanner(System.in);\n char r=scan.next().charAt(0),l=scan.next().charAt(0);\n int n=scan.nextInt(),x,y;\n char a [] = {'v','<','^','>'},b [] = {'v','>','^','<'};\n for (int i=0;i<4;i++){if(a[i]==r)x=i;if(b[i]==r)y=i;}\n if(n%2==0) System.out.print(\"undefined\");\n else if(a[(x+n%4)%4]==l)System.out.print(\"cw\");\n else if (b[(y+n%4)%4]==l)System.out.print(\"ccw\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "519b9988c654948ebd3200719055b7a2", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\n public class spin{\n\n public static void main(String[] args) {\n\n\n char[] spin=new char[4];\n spin[0]=118;\n spin[1]=60;\n spin[2]=94;\n spin[3]=62;\n\n\n\n FastScanner fi=new FastScanner();\n long n;\n char[] start=fi.next().toCharArray();\n char []end=fi.next().toCharArray();\n n=fi.nextInt();\n int cw,ccw;\n String ans=\" \";\n int i,j,k,d;\n int st,en;\n st=en=cw=ccw=0;\n for (i=0;i<4 ;i++ )\n {\n if (start[0]==spin[i]) {\n st=i;\n }\n if (end[0]==spin[i]) {\n en=i;\n }\n\n\n }\n\n\n\n if (st < en) {\n d=en-st;\n\n if ( n>=d && ( n-d)%4==0) {\n cw=1;\n ans=\"cw\";\n }\n\n {\n d=4-d;\n\n if ( n>=d && ( n-d)%4==0) {\n ccw=1;\n ans=\"ccw\";\n }\n\n\n }\n\n }\n\n else if (st >= en) {\n d=st-en;\n if ( n>=d && (n-d)%4==0) {\n ccw=1;\n ans=\"ccw\";\n }\n\n\n {\n d=4-d;\n if ( n>=d && ( n-d)%4==0) {\n cw=1;\n ans=\"cw\";\n }\n\n }\n\n }\n\n\n if ((cw==1 && ccw==1) || (cw==0 && ccw==0)) {\n ans=\"undefined\";\n }\n\n System.out.println(ans);\n\n\n\n\n\n\n }\n\npublic class FastScanner\n{\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner()\n {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next()\n {\n while (st == null || !st.hasMoreTokens())\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 public int nextInt()\n {\n return Integer.parseInt(next());\n }\n}\n\n\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cca9bc7ef6090bc88be28f3c107f7d3c", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class spin{\n\n public static void main(String[] args) {\n\n\n char[] spin=new char[4];\n spin[0]=118;\n spin[1]=60;\n spin[2]=94;\n spin[3]=62;\n\n\n\n FastScanner fi=new FastScanner();\n long n;\n char[] start=fi.next().toCharArray();\n char []end=fi.next().toCharArray();\n n=fi.nextInt();\n int cw,ccw;\n String ans=\" \";\n int i,j,k,d;\n int st,en;\n st=en=cw=ccw=0;\n for (i=0;i<4 ;i++ )\n {\n if (start[0]==spin[i]) {\n st=i;\n }\n if (end[0]==spin[i]) {\n en=i;\n }\n\n\n }\n\n\n\n if (st < en) {\n d=en-st;\n\n if ( n>=d && ( n-d)%4==0) {\n cw=1;\n ans=\"cw\";\n }\n\n {\n d=4-d;\n\n if ( n>=d && ( n-d)%4==0) {\n ccw=1;\n ans=\"ccw\";\n }\n\n\n }\n\n }\n\n else if (st >= en) {\n d=st-en;\n if ( n>=d && (n-d)%4==0) {\n ccw=1;\n ans=\"ccw\";\n }\n\n\n {\n d=4-d;\n if ( n>=d && ( n-d)%4==0) {\n cw=1;\n ans=\"cw\";\n }\n\n }\n\n }\n\n\n if ((cw==1 && ccw==1) || (cw==0 && ccw==0)) {\n ans=\"undefined\";\n }\n\n System.out.println(ans);\n\n\n\n\n\n\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 public String next()\n {\n while (st == null || !st.hasMoreTokens())\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 public int nextInt()\n {\n return Integer.parseInt(next());\n }\n}\n\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "77f1e5c1b3f28d1e0121ab22bf07a1a5", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900} {"lang": "Java 8", "source_code": "public class Driver {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint [] arr = new int[n];\n\t\t\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tarr[i] = in.nextInt();\n\t\t}\n\t\t\n\t\tSystem.out.println(maxSS(arr));\n\t\t\n\t\tin.close();\n\t}\n\t\n\tstatic int maxSS(int [] arr){\n\t\tint b = 0, c = 0;\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tif(arr[i] > 0)\n\t\t\t\tb += arr[i];\n\t\t\telse\n\t\t\t\tc += arr[i];\n\t\t}\n\t\treturn b - c;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "411eaefb8e2c7cfea235fa55d5f6b4c2", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800} {"lang": "Java 8", "source_code": "public class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint [] arr = new int[n];\n\t\t\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tarr[i] = in.nextInt();\n\t\t}\n\t\t\n\t\tSystem.out.println(maxSS(arr));\n\t\t\n\t\tin.close();\n\t}\n\t\n\tstatic int maxSS(int [] arr){\n\t\tint b = 0, c = 0;\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tif(arr[i] > 0)\n\t\t\t\tb += arr[i];\n\t\t\telse\n\t\t\t\tc += arr[i];\n\t\t}\n\t\treturn b - c;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8712c658d6627c509c215904e50e4efe", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800} {"lang": "Java 11", "source_code": "public class partition {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] lb = new int[100];\n int[] lc = new int[100];\n for(int i = 0; i < n; i++){\n int k = sc.nextInt();\n if(k<0) lc[i] = k;\n if(k>=0) lb[i] = k;\n }\n int b = 0;\n int c = 0;\n for(int i = 0; i < 100; i++){\n b += lb[i];\n c += lc[i];\n }\n System.out.println(b-c);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1968f4dda184fb6c3e7f783e3de4a946", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String args[]) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n long a = 0;\n long b = 0;\n for(int i = 0; i < n; i++){\n long k = s.nextLong();\n if(k > 0){\n a += k;\n }\n else{\n b += k;\n }\n }\n System.out.println(a - k);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea2ce291c92b296c3427ede8f1fe0cc8", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class tyler\n{ \n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] a = new int[n];\n int sum = 1000000;\n for(int i=0;i=x) sum1 = sum1 + a[k]*x;\n else sum1 = sum1 + a[k]*k;\n }\n sum1 = sum1*4;\n if(sum>sum1) sum = sum1;\n }\n \n System.out.println(sum);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "56d708d21b45d7de1c8501818f43cd4c", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000} {"lang": "Java 8", "source_code": "package helloworld;\nimport java.io.*;\nimport java.util.*;\n\nimport helloworld.cd.Scanner;\npublic class Try {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc=new Scanner(System.in);\n\t\tPrintWriter out =new PrintWriter (System.out);\n\t\tint n=sc.nextInt();\n\t\tint []a=new int[n];\n\t\tfor(int i=0;i> adj;\nstatic int n, m, k, q, x, y;\nstatic char[]str;\npublic static void solve() throws Exception {\n\t // solve the problem here\n\t\ts = new MyScanner();\n \t\tout = new PrintWriter(new BufferedOutputStream(System.out), true);\n//\t \t\tout = new PrintWriter(\"output.txt\");\n int tc = 1;//s.nextInt();\n NumberTheoryUtils ntu = new NumberTheoryUtils();\n while(tc-- > 0){\n \tn = s.nextInt();\n \tlong m = s.nextLong();\n \tntu.setMod(m);\n \tlong[]fact = ntu.getFactorialsModulo(n+1);\n \tlong ans = 0;\n \tfor(int length = 1; length <=n; length++) {\n \t\t// 1 ... n+1-length\n \t\tans += (((((n+1-length) * fact[length])%m)*fact[n+1-length])%m) ;\n \t\tans %= m;\n \t}\n \tif(ans < 0) ans += m;\n \tout.println(ans);\n } \n \n out.flush();\n out.close();\n}\n\npublic static PrintWriter out;\npublic static MyScanner s;\nstatic class MyScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n public MyScanner(String fileName) {\n \ttry {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\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() { return Integer.parseInt(next()); }\n long nextLong() { return Long.parseLong(next()); }\n double nextDouble() { return Double.parseDouble(next()); }\n int[] nextIntArray(int n){\n \tint[]a = new int[n];\n \tfor(int i=0; i> readUndirectedUnweightedGraph(int n, int m) {\n \tArrayList>adj = new ArrayList>();\n \tfor(int i=0; i<=n; i++)adj.add(new ArrayList());\n \tfor(int i=0; i> readDirectedUnweightedGraph(int n, int m) {\n \tArrayList>adj = new ArrayList>();\n \tfor(int i=0; i<=n; i++)adj.add(new ArrayList());\n \tfor(int i=0; i{\n int u ;\n int v ;\n int val;\n edge(int u1, int v1 , int val1)\n {\n this.u=u1;\n this.v=v1;\n this.val=val1;\n }\n public int compareTo(edge e)\n {\n return this.val-e.val;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca3ba92ae3e6dade5c1c8fe4af42266a", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\n\n//author : s a n 1 d h y a\n\n//Date : 18-07-2020 \n\npublic class C1284 {\n static long Mod = 1000000007;\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 ni() {\n return Integer.parseInt(next());\n }\n\n long nl() {\n return Long.parseLong(next());\n }\n\n double nd() {\n return Double.parseDouble(next());\n }\n\n String nln() {\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 public static void sortbyColumn(int arr[][], int col) {\n Arrays.sort(arr, new Comparator() {\n\n @Override\n public int compare(final int[] entry1, final int[] entry2) {\n\n if (entry1[col] > entry2[col])\n return 1;\n else\n return -1;\n }\n });\n }\n\n public static long modex(long x, long y) {\n x = x % Mod;\n long ret = 1;\n while (y > 0) {\n if (y % 2 != 0) {\n ret = ret * x % Mod;\n }\n x = x * x % Mod;\n y >>= 1;\n }\n return ret;\n }\n\n public static long mplr(long x, long y) {\n long ret = 0;\n while (y != 0) {\n if (y % 2 != 0) {\n ret = (ret + x) % Mod;\n }\n x = (x + x) % Mod;\n y >>= 1;\n }\n return ret;\n }\n\n public static void main(String[] args) {\n FastReader sc = new FastReader();\n long n=sc.nl();\n long m=sc.nl();\n long f[]=new long[(int)(n+10)];\n f[0]=1;\n\n //Factorial caluclation upto N\n for(long i=1;i<=n;i++){\n f[(int)i]=((f[(int)(i-1)]%m)*(i%m))%m;\n }\n\n long sm=0;\n\n //implementing the formula :\n for(long i=1;i<=n;i++){\n long p=n-i+1;\n long f1=f[(int)(i)];\n long f2=f[(int)(p)];\n sm+=((p%m)*(f1%m)*(f2%m))%m;\n }\n System.out.println(sm%m);\n\\ }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8929b11b5546374a5195eda488aedeb", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600} {"lang": "Java 8", "source_code": "package Hello2020;\n\nimport java.util.*;\n\npublic class Prob1284C {\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 long[] factorials = new long[250005];\n factorials[0] = 1;\n for (int i = 1; i <= n; i++) {\n factorials[i] = factorials[i - 1] * i % m;\n }\n long ans = 0;\n for (int i = 1; i <= n; i++) {\n ans += (n - i + 1) * (factorials[i] * factorials[n - i + 1] % m);\n ans %= m;\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "09125e326361c29fe33f545c27c138c8", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public void solve() {\n long n = nl();\n int k = ni();\n HashMap divs = new HashMap<>();\n int sqr = (int) Math.ceil(Math.sqrt(n));\n for (int i = 2; i <= sqr; i++) {\n int c = 0;\n while (n % i == 0) {\n c++;\n n /= i;\n }\n if (c > 0) {\n divs.put((long)i, c);\n }\n }\n int mod = 1000000007;\n if ((n != 1)/* && (n % mod != 0)*/) {\n divs.put(n % mod, 1);\n }\n long ans = 1;\n// double ans2 = 1;\n int[] inv = new int[100];\n for (int i = 1; i < 100; i++) {\n inv[i] = (int) pow(i, mod - 2, mod);\n }\n for (Map.Entry d: divs.entrySet()) {\n int c = d.getValue() + 1;\n long[][] dp = new long[k][c];\n// double[][] dp2 = new double[k][c];\n for (int i = 0; i < c; i++) {\n dp[0][i] = inv[c];\n// dp2[0][i] = 1.0 / c;\n }\n for (int i = 1; i < k; i++) {\n for (int j = 0; j < c; j++) {\n for (int x = c - 1; x >= j; x--) {\n dp[i][j] += dp[i - 1][x] * inv[x + 1] % mod;\n// dp2[i][j] += dp2[i - 1][x] / (x + 1);\n }\n }\n }\n long m = 0;\n// double m2 = 0;\n int mul = 1;\n long v = d.getKey();\n for (int i = 0; i < c; i++) {\n m += mul * dp[k - 1][i] % mod;\n mul = (int) ((mul * v) % mod);\n// m2 += pow(d.getKey(), i, Long.MAX_VALUE) * dp2[k - 1][i];\n }\n ans = m * ans % mod;\n// ans2 *= m2;\n }\n write(ans + \"\\n\");\n// write(ans2 + \"\\n\");\n }\n\n long pow(long n, int x, long m) {\n long ans = 1;\n long a = n;\n int e = 1;\n while (x >= e) {\n if ((x & e) > 0) {\n ans = (ans * a) % m;\n }\n a = (a * a) % m;\n e = e << 1;\n }\n return ans;\n }\n\n\n\n\n public static void main(String[] args) {\n Main m = new Main();\n m.solve();\n try {\n m.out.close();\n } catch (IOException e) {}\n }\n\n BufferedReader in;\n BufferedWriter out;\n StringTokenizer tokenizer;\n public Main() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n public String n() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(in.readLine());\n } catch (IOException e) {}\n }\n return tokenizer.nextToken();\n }\n public int ni() {\n return Integer.parseInt(n());\n }\n public long nl() {\n return Long.parseLong(n());\n }\n public void write(String s) {\n try {\n out.write(s);\n } catch (IOException e) {}\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8657a0e3132573bbd5dd8ff1f232069f", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws FileNotFoundException {\n ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out));\n\n// String fileName = \"C-large-practice\";\n// ConsoleIO io = new ConsoleIO(new FileReader(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + fileName + \".in\"), new PrintWriter(new File(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + fileName + \".out\")));\n\n new Main(io).solve();\n// new Main(io).solveLocal();\n\n io.close();\n }\n\n ConsoleIO io;\n\n Main(ConsoleIO io) {\n this.io = io;\n }\n\n ConsoleIO opt;\n\n Main(ConsoleIO io, ConsoleIO opt) {\n this.io = io;\n this.opt = opt;\n }\n\n List> gr = new ArrayList<>();\n\n long MOD = 1_000_000_007;\n\n public void solve() {\n long n = io.readLong();\n int k = io.ri();\n\n List divs = new ArrayList<>();\n for(long d = 1; d*d<= n; d++) {\n if (n % d == 0) {\n divs.add(d);\n if (d * d != n) {\n divs.add(n / d);\n }\n }\n }\n\n divs.sort(Comparator.naturalOrder());\n\n int[][] subs = new int[divs.size()][];\n long[] numd = new long[divs.size()];\n for(int i = 0; i < divs.size(); i++){\n List list = new ArrayList<>();\n long v = divs.get(i);\n for(int j = i; j < divs.size(); j++){\n if(divs.get(j) % v == 0){\n list.add(j);\n numd[j]++;\n }\n }\n subs[i] = new int[list.size()];\n for(int j = 0; j < list.size(); j++){\n subs[i][j] = list.get(j);\n }\n }\n\n for(int i = 0; i < divs.size(); i++){\n numd[i] = pow(numd[i], MOD - 2, MOD);\n }\n\n long[] count = new long[divs.size()];\n count[count.length - 1] = 1L;\n for(int step = 0; step < k; step++){\n for(int i = 0; i < count.length; i++){\n count[i] = (count[i] * numd[i]) % MOD;\n }\n for(int i = 0; i < count.length; i++){\n int[] list = subs[i];\n\n long next = 0;\n for(int j : list){\n next = next + count[j];\n }\n count[i] = next % MOD;\n }\n }\n\n long res = 0;\n for(int i = 0; i < count.length; i++) {\n res = (res + divs.get(i) * count[i] % MOD) % MOD;\n }\n\n io.writeLine(res+\"\");\n }\n\n long div(long a, long b, long mod) {\n return (a * pow(b, mod - 2, mod)) % mod;\n }\n\n long pow(long a, long p, long mod) {\n long res = 1;\n while (p > 0) {\n if (p % 2 == 1) res = (res * a) % mod;\n a = (a * a) % mod;\n p /= 2;\n }\n return res;\n }\n\n}\n\n\nclass ConsoleIO {\n\n BufferedReader br;\n PrintWriter out;\n public ConsoleIO(Reader reader, PrintWriter writer){br = new BufferedReader(reader);out = writer;}\n public void flush(){this.out.flush();}\n public void close(){this.out.close();}\n public void writeLine(String s) {this.out.println(s);}\n public void writeInt(int a) {this.out.print(a);this.out.print(' ');}\n public void writeWord(String s){\n this.out.print(s);\n }\n public void writeIntArray(int[] a, int k, String separator) {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < k; i++) {\n if (i > 0) sb.append(separator);\n sb.append(a[i]);\n }\n this.writeLine(sb.toString());\n }\n public void writeLongArray(long[] a, int k, String separator) {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < k; i++) {\n if (i > 0) sb.append(separator);\n sb.append(a[i]);\n }\n this.writeLine(sb.toString());\n }\n public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}\n public String readLine() {try {return br.readLine();}catch (Exception ex){ return \"\";}}\n public long[] readLongArray() {\n String[]n=this.readLine().trim().split(\"\\\\s+\");long[]r=new long[n.length];\n for(int i=0;i='0' && all[i]<='9'){\n cur = cur*10+all[i]-'0';\n have = true;\n }else if(all[i]=='-') {\n neg = true;\n }\n else if(have){\n res[k++] = neg?-cur:cur;\n cur = 0;\n have = false;\n neg = false;\n }\n }\n if(have)res[k++] = neg?-cur:cur;\n return res;\n }\n public int ri() {\n try {\n int r = 0;\n boolean start = false;\n boolean neg = false;\n while (true) {\n int c = br.read();\n if (c >= '0' && c <= '9') {\n r = r * 10 + c - '0';\n start = true;\n } else if (!start && c == '-') {\n start = true;\n neg = true;\n } else if (start || c == -1) return neg ? -r : r;\n }\n } catch (Exception ex) {\n return -1;\n }\n }\n public long readLong() {\n try {\n long r = 0;\n boolean start = false;\n boolean neg = false;\n while (true) {\n int c = br.read();\n if (c >= '0' && c <= '9') {\n r = r * 10 + c - '0';\n start = true;\n } else if (!start && c == '-') {\n start = true;\n neg = true;\n } else if (start || c == -1) return neg ? -r : r;\n }\n } catch (Exception ex) {\n return -1;\n }\n }\n public String readWord() {\n try {\n boolean start = false;\n StringBuilder sb = new StringBuilder();\n while (true) {\n int c = br.read();\n if (c!= ' ' && c!= '\\r' && c!='\\n' && c!='\\t') {\n sb.append((char)c);\n start = true;\n } else if (start || c == -1) return sb.toString();\n }\n } catch (Exception ex) {\n return \"\";\n }\n }\n public char readSymbol() {\n try {\n while (true) {\n int c = br.read();\n if (c != ' ' && c != '\\r' && c != '\\n' && c != '\\t') {\n return (char) c;\n }\n }\n } catch (Exception ex) {\n return 0;\n }\n }\n//public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}\n}\nclass Pair {\n public Pair(int a, int b) {this.a = a;this.b = b;}\n public int a;\n public int b;\n}\nclass PairLL {\n public PairLL(long a, long b) {this.a = a;this.b = b;}\n public long a;\n public long b;\n}\nclass Triple {\n public Triple(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}\n public int a;\n public int b;\n public int c;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5750c3c2c93a31c9e6a490de44031dfc", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\npublic class A {\n \n\tBufferedReader in;\n\tStringTokenizer st;\n\tPrintWriter ob;\n\n\tHashMap > > hash = new HashMap<>();\n\tlong mod = (long)1e9+7;\n\t\n\tpublic static void main( String args[] ) throws IOException {\n\t\tnew A().run();\n\t}\n\tvoid run() throws IOException {\n\t\tin = new BufferedReader ( new InputStreamReader( System.in ) );\n\t\tob = new PrintWriter( System.out );\n\t\tsolve();\n\t\tob.flush();\n\t}\n\tvoid solve() throws IOException {\n\t\tlong n = nl();\n\t\tint k = ni();\n\t\t\n\t\tlong result = 1;\n\t\tfor(long prime = 2 ; prime*prime<=n ; prime++) {\n\t\t\t\n\t\t\tint power = 0 ;\n\t\t\twhile( n%prime == 0 ) {\n\t\t\t\tpower++;\n\t\t\t\tn/=prime;\n\t\t\t}\n\t\t\t\n\t\t\tif( power > 0 ) {\n\t\t\t\tresult = result * solvePrime( (long)prime , power , k );\n\t\t\t\tresult = result % mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif( n>1 ) {\n\t\t\tresult *= solvePrime( n , 1 , k );\n\t\t\tresult %= mod;\n\t\t}\n\t\t\t\n\t\tob.println( result );\n\t}\n\t\n\tlong solvePrime( long prime , int power , int k ) \n\t{\n\t\tlong precomputed = get( prime , power , k );\n\t\tif( precomputed != Long.MIN_VALUE ) {\n\t\t\treturn precomputed;\n\t\t}\n\t\t\n\t\tif( k==1 ) {\n\t\t\tlong numerator = powMod( prime , power + 1 )-1+mod;\n\t\t\tlong denominator = prime - 1; \n\t\t\tnumerator *= inverse(denominator);\n\t\t\tnumerator %= mod;\n\t\t\t\n\t\t\tlong res = (( numerator *1L* inverse( power+1 ) )%mod);\n\t\t\tadd( prime , power , k , res );\n\t\t\treturn res; \t\n\t\t}\n\t\t\n\t\tlong expectation = 1 ;\n\t\tfor( int i=1 ; i<=power ; i++ ) {\n\t\t\texpectation += solvePrime( prime , i , k-1 );\n\t\t\texpectation %= mod;\n\t\t}\n\t\t\n\t\tlong res = ((expectation *1L* inverse( power+1 )) % mod);\n\t\tadd( prime , power , k , res );\n\t\treturn res;\n\t}\n\t\n\tlong inverse( long n ) {\n\t\treturn (new BigInteger(\"\"+n).modInverse( new BigInteger(\"\"+mod))).longValue(); \n\t}\n\t\n\tlong inverse( int n ) {\n\t\treturn (new BigInteger(\"\"+n).modInverse( new BigInteger(\"\"+mod))).longValue(); \n\t}\n\t\n\tlong powMod(long prime,int power) {\n\t long x=1;\n\t long y=prime;\n\t while(power > 0){\n\t if(power%2 == 1){\n\t x=(x*y)%mod;\n\t }\n\t y = (y*y)%mod;\n\t power /= 2;\n\t }\n\t return x%mod;\n\t}\n\t\n\tvoid add( long prime , int power , int k , long ans ) {\n\t\t\n\t\tif( !hash.containsKey( prime ) ) {\n\t\t\tHashMap< Integer , Long > first = new HashMap<>();\n\t\t\tfirst.put( k , ans );\n\t\t\tHashMap< Integer , HashMap< Integer , Long > > second = new HashMap<>();\n\t\t\tsecond.put( power , first);\n\t\t\thash.put( prime , second );\n\t\t} else {\n\t\t\tHashMap< Integer , HashMap< Integer , Long > > second = hash.get(prime);\n\t\t\t\n\t\t\tif( !second.containsKey( power ) ) {\n\t\t\t\tHashMap first = new HashMap<>();\n\t\t\t\tfirst.put( k ,ans );\n\t\t\t\thash.get(prime).put(power , first );\n\t\t\t} else {\n\t\t\t\tif( !hash.get(prime).get(power).containsKey(k) )\n\t\t\t\t\thash.get(prime).get(power).put(k , ans );\n\t\t\t}\n\t\t}\n\t}\n\t\n\tlong get( long prime , int power , int k ) {\n\t\tif( hash.containsKey(prime) ) {\n\t\t\tif( hash.get(prime).containsKey(power)) {\n\t\t\t\tif( hash.get(prime).get(power).containsKey(k) )\n\t\t\t\t\treturn hash.get(prime).get(power).get(k);\n\t\t\t}\n\t\t}\n\t\treturn Long.MIN_VALUE;\n\t}\n\t\n\t\n\tlong nl() throws IOException {\n\t\treturn Long.parseLong( nextToken() );\n\t}\n\tint ni() throws IOException {\n\t\treturn Integer.parseInt( nextToken() );\n\t}\n\tString nextToken() throws IOException {\n\t\tif( st == null || !st.hasMoreTokens() )\n\t\t\tst = new StringTokenizer( in.readLine() );\n\t\treturn st.nextToken();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f3b5f6225fb887e8efe884c093c5e8e8", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class d\n{\n public static long mod = 1000000007;\n public static void main(String[] Args)\n {\n Scanner sc = new Scanner(System.in);\n long x = sc.nextLong();\n int iter = sc.nextInt();\n ArrayList div = getDiv(x);\n HashMap getIndex = new HashMap();\n\n HashSet[] nextIndices = new HashSet[div.size()];\n\n for (int i = 0; i < div.size(); i++)\n {\n getIndex.put(div.get(i), i);\n nextIndices[i] = new HashSet();\n }\n\n \n\n for (int i = 0; i < div.size(); i++)\n {\n long x2 = div.get(i);\n ArrayList div2 = getDiv(x2);\n for (Long val : div2)\n {\n nextIndices[i].add(getIndex.get(val));\n }\n }\n\n int n = div.size();\n \n long[] ptab = new long[div.size()];\n long[] newtab = new long[div.size()];\n long[] invs = new long[div.size()];\n for (int i = 0; i < n; i++)\n invs[i] = modInv(nextIndices[i].size(), mod);\n ptab[getIndex.get(x)] = 1;\n Arrays.fill(qs, 1);\n\n\n for (int i = 0; i < iter; i++)\n {\n Arrays.fill(newtab, 0);\n\n for (int j = 0; j < n; j++)\n {\n for (Integer k : nextIndices[j])\n {\n // Add [(j old) * (inv of j)] to (k new)\n long f1 = ptab[j] * invs[j];\n long f2 = newtab[k];\n newtab[k] = (f1 + f2) % mod;\n }\n }\n \n\n long[] tmp = newtab;\n newtab = ptab;\n ptab = tmp;\n }\n\n long ans = 0;\n for (int i = 0; i < div.size(); i++)\n {\n ans += (div.get(i) % mod) * ptab[i];\n ans %= mod;\n }\n System.out.println(ans);\n }\n\n public static ArrayList getDiv(long x){\n ArrayList ret = new ArrayList();\n for (long y = 1; y * y <= x; y++)\n {\n if (x % y == 0)\n {\n ret.add(y);\n if (y != x / y)\n ret.add(x / y);\n }\n }\n\n return ret;\n }\n\n public static long modInv(long x, long mod)\n {\n return modExpo(x, mod - 2, mod);\n }\n\n public static long modExpo(long base, long exp, long mod)\n {\n if (exp == 0)\n return 1 % mod;\n if (exp == 1)\n return base % mod;\n\n long tmp = modExpo(base, exp / 2, mod);\n tmp = tmp * tmp;\n tmp %= mod;\n if (exp % 2 == 1){\n tmp *= base;\n tmp %= mod;\n }\n return tmp;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5507a71032768e54b4eea4d5d0ac146d", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200} {"lang": "Java 6", "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.ArrayList;\nimport java.util.Arrays;\nimport java.util.Enumeration;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Properties;\nimport java.util.concurrent.BrokenBarrierException;\n\n/**\n * Works good for CF\n * \n * @author cykeltillsalu\n */\npublic class C102_div2 {\n\n\tint[] ps;\n\t{\n\t\tboolean[] primes = new boolean[(int) Math.sqrt(1000010000L)];\n\t\tArrays.fill(primes, true);\n\t\tprimes[0] = primes[1] = false;\n\t\tint psc = 0;\n\t\tfor (int i = 2; i < primes.length; ++i) {\n\t\t\tif (primes[i]) {\n\t\t\t\tpsc++;\n\t\t\t\tfor (int j = 2 * i; j < primes.length; j += i) {\n\t\t\t\t\tprimes[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tps = new int[psc];\n\t\tfor (int i = 0, j = 0; i < primes.length; ++i) {\n\t\t\tif (primes[i]) {\n\t\t\t\tps[j++] = i;\n\t\t\t}\n\t\t}\n\t}\n\n\t// some local config\n\tstatic boolean test = false;\n\tstatic String testDataFile = \"testdata.txt\";\n\tstatic String feedFile = \"feed.txt\";\n\tCompetitionType type = CompetitionType.CF;\n\tprivate static String ENDL = \"\\n\";\n\n\t// solution\n\tlong min, max;\n\n\tprivate void solve() throws Throwable {\n\t\tmin = Integer.MAX_VALUE;\n\t\tmax = 0;\n\n\t\t// System.out.println(ps.length);\n\n\t\tlong n = lread();\n\t\tList factors = new ArrayList();\n\n\t\tint cur = 0;\n\t\tint[] pcnt = new int[ps.length];\n\t\twhile (n > 1) {\n\t\t\tif (n % ps[cur] == 0) {\n\t\t\t\tfactors.add((long) ps[cur]);\n\t\t\t\tn /= ps[cur];\n\t\t\t\tpcnt[cur]++;\n\t\t\t} else {\n\t\t\t\tcur++;\n\t\t\t}\n\t\t}\n\n\t\tgo(pcnt, 1, 1, 1, factors.size(), 0, 0);\n\n\t\tlong tot = 1;\n\t\tfor (int i = 2;; i++) {\n\t\t\ttot *= i;\n\t\t\tif (tot > Integer.MAX_VALUE) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tout.write(min + \" \" + max + ENDL);\n\t\tout.flush();\n\t}\n\n\tprivate void go(int[] pcnt, long a, long b, long c, int size, int pos, int starter) {\n\t\tif (size == 0) {\n\t\t\tlong diff = diff(a, b, c);\n\t\t\tmax = Math.max(diff, max);\n\t\t\tmin = Math.min(diff, min);\n\t\t\treturn;\n\t\t}\n\n\t\twhile (pcnt[pos] == 0) {\n\t\t\tpos++;\n\t\t\tstarter = 0;\n\t\t\tif (pos >= pcnt.length) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tpcnt[pos]--;\n\t\tif (starter <= 0)\n\t\t\tgo(pcnt, a * ps[pos], b, c, size - 1, pos, 0);\n\t\tif (starter <= 1)\n\t\t\tgo(pcnt, a, b * ps[pos], c, size - 1, pos, 1);\n\t\tif (starter <= 2)\n\t\t\tgo(pcnt, a, b, c * ps[pos], size - 1, pos, 2);\n\t\tpcnt[pos]++;\n\t}\n\n\tprivate long diff(long n, long i, long j) {\n\t\treturn (n + 1) * (i + 2) * (j + 2) - n * i * j;\n\t}\n\n\tpublic int iread() throws Exception {\n\t\treturn Integer.parseInt(wread());\n\t}\n\n\tpublic double dread() throws Exception {\n\t\treturn Double.parseDouble(wread());\n\t}\n\n\tpublic long lread() throws Exception {\n\t\treturn Long.parseLong(wread());\n\t}\n\n\tpublic String wread() 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) throws Throwable {\n\n\t\tif (test) { // run all cases from testfile:\n\t\t\tBufferedReader testdataReader = new BufferedReader(new FileReader(testDataFile));\n\t\t\tString readLine = testdataReader.readLine();\n\t\t\tint casenr = 0;\n\t\t\tout: while (true) {\n\t\t\t\tBufferedWriter w = new BufferedWriter(new FileWriter(feedFile));\n\t\t\t\tif (!readLine.equals(\"input\")) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhile (true) {\n\t\t\t\t\treadLine = testdataReader.readLine();\n\t\t\t\t\tif (readLine.equals(\"output\")) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tw.write(readLine + \"\\n\");\n\t\t\t\t}\n\t\t\t\tw.close();\n\t\t\t\tSystem.out.println(\"Answer on case \" + (++casenr) + \": \");\n\n\t\t\t\tnew C102_div2().solve();\n\t\t\t\tSystem.out.println(\"Expected answer: \");\n\n\t\t\t\twhile (true) {\n\t\t\t\t\treadLine = testdataReader.readLine();\n\n\t\t\t\t\tif (readLine == null) {\n\t\t\t\t\t\tbreak out;\n\t\t\t\t\t}\n\t\t\t\t\tif (readLine.equals(\"input\")) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(readLine);\n\t\t\t\t}\n\t\t\t\tSystem.out.println(\"----------------\");\n\t\t\t}\n\t\t\ttestdataReader.close();\n\t\t} else { // run on server\n\t\t\tnew C102_div2().solve();\n\t\t}\n\t\tout.close();\n\t}\n\n\tpublic C102_div2() throws Throwable {\n\t\tif (test) {\n\t\t\tin = new BufferedReader(new FileReader(new File(feedFile)));\n\t\t}\n\t}\n\n\tInputStreamReader inp = new InputStreamReader(System.in);\n\tBufferedReader in = new BufferedReader(inp);\n\tstatic BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n\n\tenum CompetitionType {\n\t\tCF, OTHER\n\t};\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f28a0fba51e879f12798e51c43d99991", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic PrintWriter pw = new PrintWriter(System.out);\n\n\t// shayfak yala ya yasser yala\n\t// :P\n\tstatic void input(int[] a, int n) throws Exception {\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextInt();\n\t}\n\n\tstatic long[] factors(int n) {\n\t\tlong[] ans = new long[300];\n\t\tint index = 0 ;\n\t\tfor (int i = 1; i <= Math.sqrt(n); i++)\n\t\t\tif (n % i == 0){\n\t\t\t\tans[index++]=i;\n\t\t\t\tif(i!=n/i)\n\t\t\t\tans[index++]=n/i ;\n\t\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\t// ----------------- Main -------------------------------\n\t\tint n = sc.nextInt();\n\t\tlong x[] = factors(n);\n\t\t\n\t\tlong max = 0;\n\t\tlong min = Long.MAX_VALUE;\n\t\tfor (int i = 0;x[i]!=0; i++)\n\t\t\tfor (int j = 0; x[j]!=0; j++)\n\t\t\t\tfor (int k = 0; x[k]!=0; k++) {\n\t\t\t\t\tlong x1 = x[i], x2 = x[j], x3 = x[k];\n\t\t\t\t\tif ((x1 ) * (x2 ) * (x3 ) == n) {\n\t\t\t\t\t\tlong curr = ((x1+1) * (x2+2) * (x3+2)) - n;\n\t\t\t\t\t\tif (curr > max)max = curr;\n\t\t\t\t\t\tif (curr < min)min = curr;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tpw.println(min+\" \"+max);\n\t\t// ---------------------------------------------------------\n\t\tpw.flush();\n\t\tpw.close();\n\n\t}\n}\n\nclass Scanner {\n\tStringTokenizer st;\n\tBufferedReader br;\n\n\tpublic Scanner(InputStream s) {\n\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t}\n\n\tpublic Scanner(FileReader f) {\n\t\tbr = new BufferedReader(f);\n\t}\n\n\tpublic String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic String nextLine() throws IOException {\n\t\treturn br.readLine();\n\t}\n\n\tpublic double nextDouble() throws IOException {\n\t\tString x = next();\n\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\tdouble res = 0, f = 1;\n\t\tboolean dec = false, neg = false;\n\t\tint start = 0;\n\t\tif (x.charAt(0) == '-') {\n\t\t\tneg = true;\n\t\t\tstart++;\n\t\t}\n\t\tfor (int i = start; i < x.length(); i++)\n\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\tdec = true;\n\t\t\t} else {\n\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\tif (dec)\n\t\t\t\t\tf *= 10;\n\t\t\t}\n\t\tres += Long.parseLong(sb.toString()) / f;\n\t\treturn res * (neg ? -1 : 1);\n\n\t}\n\n\tpublic boolean ready() throws IOException {\n\t\treturn br.ready();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bab94b5c6bd41a5372d3b056f8fec9d8", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tPrintWriter pr = new PrintWriter(System.out, true);\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t// Scanner s = new Scanner(System.in);\n\t\t// StringTokenizer st = new StringTokenizer(in.readLine());\n\t\tint n = Integer.parseInt(in.readLine());\n\t\tArrayList list = func(n);\n\t\tif(list.size() < 2) {\n\t\t\tlist.add(1);\n\t\t}\n\t\tlong aMin = list.get(0);\n\t\tlong bMin = list.get(1);\n\t\tlong resMin = aMin*2+(bMin+2)*2+(aMin+2)*(bMin+2);\n\t\tlong resMax = n*2+9+n*3*2;\n\t\tpr.println(resMin+\" \"+resMax);\n\t}\n\n\tpublic static ArrayList func(int n) {\n\t\tArrayList list = new ArrayList();\n\t\tint k = n;\n\t\tfor (int i = 2; i * i <= n; i++) {\n\t\t\twhile (k % i == 0) {\n\t\t\t\tlist.add(i);\n\t\t\t\tk /= i;\n\t\t\t}\n\t\t}\n\t\tif (k != 1) {\n\t\t\tlist.add(k);\n\t\t}\n\t\twhile(list.size() > 2) {\n\t\t\tif(list.get(0) <= list.get(list.size()-1)) {\n\t\t\t\tlist.set(0, list.get(0)*list.get(1));\n\t\t\t\tlist.remove(1);\n\t\t\t}else{\n\t\t\t\tlist.set(list.size()-2,list.get(list.size()-2)*list.get(list.size()-1));\n\t\t\t\tlist.remove(list.size()-1);\n\t\t\t}\n\t\t}\n\t\treturn list;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "84b13e01adbb8e044d32cc9245c84dab", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7", "difficulty": 1600} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n static long min , max;\n public static void search (long arr [] , int idx , int rem)\n {\n if (idx == 2)\n {\n arr[2] = rem;\n long first = (arr[0] + 1) * (arr[1] + 2) * (arr[2] + 2);\n long second = (arr[0] + 2) * (arr[1] + 1) * (arr[2] + 2);\n long third = (arr[0] + 2) * (arr[1] + 2) * (arr[2] + 1);\n\n min = Math.min(min , Math.min(first , Math.min(second , third)));\n max = Math.max(max , Math.max(first , Math.max(second , third)));\n return;\n }\n\n for (int i = 1 ; i * i <= rem ; ++i)\n if (rem % i == 0)\n {\n arr[idx] = i;\n search(arr , idx + 1 , rem / i);\n if (rem / i != i)\n {\n arr[idx] = rem / i;\n search(arr , idx + 1 , i);\n }\n }\n\n }\n public static void main(String[]args) throws Exception {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n StringBuilder sb = new StringBuilder();\n int n = sc.nextInt();\n min = Long.MAX_VALUE;\n max = Long.MIN_VALUE;\n search(new int[3] , 0 , n);\n out.printf(\"%d %d\" , min - n , max - n );\n out.flush();\n out.close();\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n static class Scanner\n {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n public long nextLong() throws IOException {return Long.parseLong(next());}\n\n public String nextLine() throws IOException {return br.readLine();}\n\n public double nextDouble() throws IOException\n {\n String x = next();\n StringBuilder sb = new StringBuilder(\"0\");\n double res = 0, f = 1;\n boolean dec = false, neg = false;\n int start = 0;\n if(x.charAt(0) == '-')\n {\n neg = true;\n start++;\n }\n for(int i = start; i < x.length(); i++)\n if(x.charAt(i) == '.')\n {\n res = Long.parseLong(sb.toString());\n sb = new StringBuilder(\"0\");\n dec = true;\n }\n else\n {\n sb.append(x.charAt(i));\n if(dec)\n f *= 10;\n }\n res += Long.parseLong(sb.toString()) / f;\n return res * (neg?-1:1);\n }\n\n public boolean ready() throws IOException {return br.ready();}\n\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dd530997da1f664f249fa44b001c111b", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n in.next();String s = in.next();\n\n while (true)\n {\n int h = s.length();\n s.replace(\"RU\",\"D\").replace(\"UR\",\"D\").length();\n if(h==s) break;\n }\n System.out.println(s.length());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a458e19fbef1b2fa30f740ea68e294ad", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n \n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner s = new Scanner(System.in);\n\t\t// your code goes here\n\t\tint n =s.nextInt();\n\t\tString s1 = s.next();\n\t\tString b = \"\";\n\t\tfor(int i=0;i c)\n\t\t\t\tt = 0 ; \n\t\t}\n\t\tif (t == c )\n\t\t\tSystem.out.println(\"YES\");\n\t\telse \n\t\t\tSystem.out.println(\"NO\");\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "450020fc140df029254681752694498d", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class EbonyAndIvory {\n\n public static void main(String[] args){\n\n MyScannercf1 in = new MyScannercf1();\n int x = in.nextInt();\n int y = in.nextInt();\n int z = in.nextInt();\n int flag = 0;\n int i = 0;\n\n for(i = 0; i <= 10000; i++){\n if((z-i*y)%x == 0){\n if(((z-i*y)/x)<0)\n break;\n System.out.println(\"Yes\");\n\n flag = 1;\n break;\n }\n }\n\n if(flag == 0)\n System.out.println(\"No\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "222fde19321e3b9510bd53a2c05eb7f4", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100} {"lang": "Java 8", "source_code": "\npublic class g {\n\t\n\t\n\t\n\t\n\t public static void main(String [] args) throws IOException{\n\t\t// BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); \n\t\t Scanner sc=new Scanner(System.in);\n\t\t \n\t\t \n\tint a=sc.nextInt();\n\tint b=sc.nextInt();\n\tint c=sc.nextInt();\n\t\n boolean flag=false;\n for(int i=0;i< c/a+2;i++)\n {\n for(int j=0;jb?(a-b):(b-a);\n int out=0;\n if(diff%2==0)\n {\n for(int i=1;i<=diff/2;i++)\n {\n out=out+i;\n }\n out=out*2;\n }\n else\n {\n for(int i=1;i<=diff/2;i++)\n {\n out=out+i;\n }\n out=out*2;\n out=out+i+1;\n }\n System.out.println(out);\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ed1cd6c33603544ecb95ef3e561b5352", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\npublic class Answer {\n public static void main(String args[]) {\n \n int x=0;int y=0;\n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n float sol=Math.abs(a-b);\n x=0;y=0;\n if(sol%2==0)\n {\n x=(int)sol/2;\n sol=(x*(x+1))/2;\n sol+=v;\n }\n else\n {\n x=(int)Math.ceil(sol/2.0);\n //System.out.println(\"x \"+x);\n y=x-1;\n sol=(x*(x+1))/2;\n y=(y*(y+1))/2;\n sol=sol+y;\n }\n \n System.out.println((int)sol);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ae5aff74253fd7036ba3ce74cd6bf87", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args)throws IOException {\n\nBufferedReader br = new BufferedReader (new InputStreamReader (System.in));\n int a=Integer.parseInt(br.readLine());\n int b=Integer.parseInt(br.readLine());\n int max=Math.max(a,b);\n int min=Math.min(a,b);\n int i=1,c1=0,c2=0;\n while(max-min>1)\n {\n c1+=i;\n c2+=i;\n max--;min++;i++;\n }\n if(max-min==1)\n System.out.println(c1+c2+i);\n else\n System.out.println(c1+c2);\n}\n}\nclose", "lang_cluster": "Java", "compilation_error": true, "code_uid": "687857834927ff26c3be56df69313efb", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800} {"lang": "Java 11", "source_code": "mport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.*;\nimport java.util.ArrayList;\nimport java.math.BigDecimal; \nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\n\npublic class lol {\n public static void main(String args[]){\n Scanner s = new Scanner(System.in);\n\tint n=s.nextInt();\n int []a = new int[2]; \n a[0]=0;\n a[1]=0;\n int c=0,ph=0;\n ArrayList p=new ArrayList();\n for (int i = 0; i < n; i++) {\n int g=s.nextInt();\n if(g==0){\n a[0]=0;\n a[1]=0;\n }\n else if(g==1){\n a[0]=0;\n if(a[1]==1){\n a[1]=0;\n }else{\n a[1]=1;\n }\n }\n else if(g==2){\n a[1]=0;\n if(a[0]==1){\n a[0]=0;\n }else{\n a[0]=1;\n }\n }\n// else{\n// \n// if(a[0]==1){a[0]=0; }else{a[0]=1;}\n// if(a[1]==1){a[1]=0; }else{a[1]=1;}\n//\n// }\n\n if(g==3){\n if((a[0]!=1||a[1]!=1)&&(a[0]+a[1]!=0)){\n if(a[0]==0&&a[1]==1){\n a[0]=1;a[1]=0;\n }\n else{\n a[0]=0;a[1]=1;\n }\n }\n }else{\n \n if(a[0]==0&&a[1]==0){\n c++;\n \n }\n }\n \n ph=g;\n\n }\n System.out.println(c);\n\n \n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "065804505e8def7f5a32bca343519aeb", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class C363_Vacations {\n public static void main(String[] args) throws IOException{\n // Scanner scanner = new Scanner(System.in);\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n int count = 0, cur, prev = 3;\n // st = new StringTokenizer(br.readLine());\n for (int i = 0; i < n; i++) {\n cur = Integer.parseInt(st.nextToken());\n if (cur == prev && cur != 3) cur = 0;\n else if (cur == 3 && prev != 3) cur -= prev;\n if (cur == 0) count++;\n prev = cur;\n }\n System.out.println(count);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5872ab85ac1015bc62a30152e90f8202", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400} {"lang": "Java 8", "source_code": "\nimport Codeforces.C.TheTwoRoutes.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n static int arr[];\n\n public static void main(String[] args) throws IOException {\n\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(in.readLine());\n\n arr = new int[n + 1];\n\n StringTokenizer stk = new StringTokenizer(in.readLine());\n\n for (int i = 1; i <= n; i++) {\n arr[i] = Integer.parseInt(stk.nextToken());\n }\n System.out.println(solve(1, -1, 0));\n\n }\n\n public static int solve(int day, int lastChoice, int total) {\n if (day >= arr.length) {\n return total;\n }\n\n int ans = 0;\n\n if (arr[day] == 0) {\n ans = solve(day + 1, 0, total + 1);\n } else if (arr[day] == 3) {\n if (day > 1 && day < arr.length - 1 && arr[day - 1] != arr[day + 1]) {\n ans = solve(day + 1, 0, total + 1);\n } else {\n ans = Integer.min(ans, solve(day + 1, 1, total));\n ans = Integer.min(ans, solve(day + 1, 2, total));\n }\n } else {\n if (arr[day] == lastChoice) {\n ans = solve(day + 1, arr[day], total + 1);\n } else {\n ans = solve(day + 1, arr[day], total);\n }\n }\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "01e8e0b8dbc71cce26ddd1966bda41f8", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400} {"lang": "Java 11", "source_code": "import java.util.Scanner;\nimport java.util.*;\nimport java.util.ArrayList;\nimport java.math.BigDecimal; \nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\n\npublic class lol {\n public static void main(String args[]){\n Scanner s = new Scanner(System.in);\n\tint n=s.nextInt();\n int []a = new int[2]; \n a[0]=0;\n a[1]=0;\n int c=0,ph=0;\n ArrayList p=new ArrayList();\n for (int i = 0; i < n; i++) {\n int g=s.nextInt();\n if(g==0){\n a[0]=0;\n a[1]=0;\n }\n else if(g==1){\n a[0]=0;\n if(a[1]==1){\n a[1]=0;\n }else{\n a[1]=1;\n }\n }\n else if(g==2){\n a[1]=0;\n if(a[0]==1){\n a[0]=0;\n }else{\n a[0]=1;\n }\n }\n else{\n \n if(a[0]==1){a[0]=0; }else{a[0]=1;}\n if(a[1]==1){a[1]=0; }else{a[1]=1;}\n\n }\n\n if(g==3){\n if(ph!=3){\n \n }\n }else{\n \n if(a[0]==0&&a[1]==0){\n c++;\n \n }\n }\n \n ph=g;\n\n }\n System.out.println(c);\n\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f0605c256bce4dea028e886907073bec", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400} {"lang": "Java 8", "source_code": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nWhat do you think? What do you think?\n1st on Billboard, what do you think of it\nNext is a Grammy, what do you think of it\nHowever you think, I\u2019m sorry, but shit, I have no fcking interest\n*******************************\nI'm standing on top of my Monopoly board\nThat meres I'm on top of my game and it don't stop\ntil my hip don't hop anymore\nhttps://www.a2oj.com/Ladder16.html\n*******************************\nShining through the city with a little funk and soul\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\n public class C\n {\n public static void main(String hi[]) throws Exception\n {\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(infile.readLine());\n La = Long.parseLong(st.nextToken());\n Ra = Long.parseLong(st.nextToken())+1;\n Ta = Long.parseLong(st.nextToken());\n st = new StringTokenizer(infile.readLine());\n Lb = Long.parseLong(st.nextToken());\n Rb = Long.parseLong(st.nextToken())+1;\n Tb = Long.parseLong(st.nextToken());\n long gcd = gcd(Ta, Tb);\n long shift = ((Lb - La) % gcd + gcd) % gcd;\n \t\tlong sa = Ra - La, sb = Rb - Lb;\n \t\tlong res = min(sa, sb + shift) - max(0, shift);\n \t\tshift -= gcd;\n \t\tres = max(res, min(sa, sb + shift) - max(0, shift));\n \t\tres = max(res, 0);\n \t\tSystem.out.print(res);\n }\n static long La, Ra, Ta, Lb, Rb, Tb;\n public static long gcd(long a, long b)\n {\n if(a > b)\n {\n long t = a;\n a = b;\n b = t;\n }\n if(a == 0L)\n return b;\n return gcd(b%a, a);\n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f86d00b1d6f0a7578ca6f750728d238b", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n CUdachnieDni solver = new CUdachnieDni();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CUdachnieDni {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int la = in.readInt();\n int ra = in.readInt();\n int ta = in.readInt();\n int lb = in.readInt();\n int rb = in.readInt();\n int tb = in.readInt();\n int g = IntegerUtils.gcd(ta, tb);\n int answer = 0;\n int qa = la / g;\n la -= qa * g;\n ra -= qa * g;\n int qb = lb / g;\n lb -= qb * g;\n rb -= qb * g;\n answer = Math.max(answer, getAnswer(la, ra, lb, rb));\n answer = Math.max(answer, getAnswer(la + g, ra + g, lb, rb));\n answer = Math.max(answer, getAnswer(la, ra, lb + g, rb + g));\n out.printLine(answer);\n }\n\n private int getAnswer(int la, int ra, int lb, int rb) {\n return Math.min(ra, rb) - Math.max(la, lb) + 1;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class IntegerUtils {\n public static int gcd(int a, int b) {\n a = Math.abs(a);\n b = Math.abs(b);\n while (b != 0) {\n int temp = a % b;\n a = b;\n b = temp;\n }\n return a;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a5868068e8daca65c2640fff1ec656f1", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900} {"lang": "Java 8", "source_code": "import static java.lang.Math.*;\n\nimport java.math.*;\n\npublic class C {\n\n\tpublic Object solve() {\n\t\tlong LA = sc.nextLong(), RA = sc.nextLong(), TA = sc.nextLong();\n\t\tlong LB = sc.nextLong(), RB = sc.nextLong(), TB = sc.nextLong();\n\n\t\tlong SA = RA - LA, SB = RB - LB;\n\t\tlong G = gcd(TA, TB), D = mod(LA - LB, G);\n\n\t\tlong res = calc(D, 0, SA, SB);\n\t\tres = max(res, calc(D-G, 0, SA, SB));\n\t\treturn print(res);\n\t}\n\n\tlong calc(long LA, long LB, long SA, long SB) {\n\t\tlong RA = LA + SA, RB = LB + SB;\n\t\tlong L = max(LA, LB), R = min(RA, RB);\n\t\tlong res = max(0, R - L + 1);\n\t\treturn res;\n\t}\n\n\tprivate static final boolean ONE_TEST_CASE = true;\n\n\tprivate static void init() {\n\t}\n\n\tprivate static long gcd (long x, long y) { return BigInteger.valueOf(x).gcd(BigInteger.valueOf(y)).longValue(); }\n\tprivate static long mod (long x, long mod) { return ((x % mod) + mod) % mod; }\n\t//////////////////////////////////////////////////////////////////////////////////// OFF\n\tprivate static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static Object print (Object o, Object ... A) { IOUtils.print(o, A); return null; }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next() { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\t\tpublic long nextLong() { return Long.parseLong(next()); }\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol() { return index == line.length; }\n\t\t\tprivate String readLine() {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine() {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split(String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build(Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim(String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static final java.text.DecimalFormat formatter = new java.text.DecimalFormat(\"#.#########\");\n\t\tprivate static void start() { if (t == 0) t = millis(); }\n\t\tprivate static void append(java.util.function.Consumer f, java.util.function.Consumer g, final Object o) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tf.accept(java.lang.reflect.Array.get(o, i));\n\t\t\t}\n\t\t\telse if (o instanceof Iterable)\n\t\t\t\t((Iterable)o).forEach(f::accept);\n\t\t\telse\n\t\t\t\tg.accept(o instanceof Double ? formatter.format(o) : o);\n\t\t}\n\t\tprivate static void append(final StringBuilder b, Object o, final String delim) {\n\t\t\tappend(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static Object print(Object o, Object ... A) { pw.println(build(o, A)); return null; }\n\t\tprivate static void err(Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static boolean PRINT;\n\t\tprivate static void write(Object o) {\n\t\t\terr(o, '(', time(), ')');\n\t\t\tif (PRINT)\n\t\t\t\tpw.println(o);\n\t\t}\n\t\tprivate static void exit() {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis() { return System.currentTimeMillis(); }\n\t\tprivate static String time() { return \"Time: \" + (millis() - t) / 1000.0; }\n\t\tprivate static void run(int N) {\n\t\t\ttry { PRINT = System.getProperties().containsKey(\"PRINT\"); }\n\t\t\tcatch (Throwable t) {}\n\n\t\t\tfor (int n = 1; n <= N; ++n) {\n\t\t\t\tObject res = new C().solve();\n\t\t\t\tif (res != null)\n\t\t\t\t\twrite(\"Case #\" + n + \": \" + build(res));\n\t\t\t}\n\t\t\texit();\n\t\t}\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tpublic static void main(String[] args) {\n\t\tinit();\n\t\tint N = ONE_TEST_CASE ? 1 : sc.nextInt();\n\t\tIOUtils.run(N);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2ad1ffc6df60714e99592dcb328e9ce1", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\npublic class lucky {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastIO sc = new FastIO(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tlong l_a = sc.nextInt(), r_a =sc.nextInt(), t_a = sc.nextInt();\n\t\tlong l_b = sc.nextInt(), r_b = sc.nextInt(), t_b = sc.nextInt();\n\t\t\n\t\tlong length_a = r_a-l_a;\n\t\tlong length_b = r_b-l_b;\n\t\t\n\t\tlong gcd = GCD(t_a, t_b);\n\t\t\n\t\tlong offset = (((l_a-l_b)%gcd)+gcd)%gcd;\n\t\t\n\t\tlong start = l_b + offset;\n\t\tlong end = Math.min(l_b+offset+length_a, l_b+length_b);\n\t\t\n\t\tlong ans = end-start+1;\n\t\t\n\t\toffset = (((l_b-l_a)%gcd)+gcd)%gcd;\n\t\t\n\t\tstart = l_a + offset;\n\t\tend = Math.min(l_a+offset+length_b, l_a+length_a);\n\t\t\n\t\tans = Math.max(ans, end-start+1);\n\t\t\n\t\tans = Math.max(ans, 0);\n\t\t\n\t\tpw.println(ans);\n\t\tpw.close();\n\t}\n\t\n\tstatic long GCD(long a, long b) {\n\t\tif (b==0) return a;\n\t\treturn GCD(b,a%b);\n\t}\n\n\tstatic class FastIO {\n\n\t\t//Is your Fast I/O being bad?\n\n\t\tInputStream dis;\n\t\tbyte[] buffer = new byte[1 << 17];\n\t\tint pointer = 0;\n\n\t\tpublic FastIO(String fileName) throws Exception {\n\t\t\tdis = new FileInputStream(fileName);\n\t\t}\n\n\t\tpublic FastIO(InputStream is) throws Exception {\n\t\t\tdis = is;\n\t\t}\n\n\t\tint nextInt() throws Exception {\n\t\t\tint ret = 0;\n\n\t\t\tbyte b;\n\t\t\tdo {\n\t\t\t\tb = nextByte();\n\t\t\t} while (b <= ' ');\n\t\t\tboolean negative = false;\n\t\t\tif (b == '-') {\n\t\t\t\tnegative = true;\n\t\t\t\tb = nextByte();\n\t\t\t}\n\t\t\twhile (b >= '0' && b <= '9') {\n\t\t\t\tret = 10 * ret + b - '0';\n\t\t\t\tb = nextByte();\n\t\t\t}\n\n\t\t\treturn (negative) ? -ret : ret;\n\t\t}\n\n\t\tlong nextLong() throws Exception {\n\t\t\tlong ret = 0;\n\n\t\t\tbyte b;\n\t\t\tdo {\n\t\t\t\tb = nextByte();\n\t\t\t} while (b <= ' ');\n\t\t\tboolean negative = false;\n\t\t\tif (b == '-') {\n\t\t\t\tnegative = true;\n\t\t\t\tb = nextByte();\n\t\t\t}\n\t\t\twhile (b >= '0' && b <= '9') {\n\t\t\t\tret = 10 * ret + b - '0';\n\t\t\t\tb = nextByte();\n\t\t\t}\n\n\t\t\treturn (negative) ? -ret : ret;\n\t\t}\n\n\t\tbyte nextByte() throws Exception {\n\t\t\tif (pointer == buffer.length) {\n\t\t\t\tdis.read(buffer, 0, buffer.length);\n\t\t\t\tpointer = 0;\n\t\t\t}\n\t\t\treturn buffer[pointer++];\n\t\t}\n\n\t\tString next() throws Exception {\n\t\t\tStringBuffer ret = new StringBuffer();\n\n\t\t\tbyte b;\n\t\t\tdo {\n\t\t\t\tb = nextByte();\n\t\t\t} while (b <= ' ');\n\t\t\twhile (b > ' ') {\n\t\t\t\tret.appendCodePoint(b);\n\t\t\t\tb = nextByte();\n\t\t\t}\n\n\t\t\treturn ret.toString();\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "714a1c938368ddbebe408a98ea3e1e55", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n\n\npublic class ElPeque\u00f1oElefante {\n public static void main(String...args){\n Scanner entrada =new Scanner(System.in);\n ArrayList lista = new ArrayList<>();\n ArrayList divisores = new ArrayList<>();\n int x= Integer.parseInt(entrada.nextLine());\n String numero=\"\"+x;\n int d=1;\n if(x==1){\n System.out.println(\"1\");\n return;\n }\n if(x%2==0 && x%5==0){//si es 10,100,......1000000000\n d=2;\n for(int i=2; idivizores= new ArrayList<>();\n\t\t\n\t\tfor(long i=1;i<=Math.sqrt(x);i++){\n\t\t\tif(x%i==0){\n\t\t\t\tdivizores.add((long) i);\n\t\t\t\tif((x/i)!=i)divizores.add((long)(x/i));\n\t\t\t}\n\t\t}\n\t\tlong resp=0;\n\t\tfor(Long l:divizores){\n\t\t\tif(digitoComum(x, l.longValue())){resp++;\n\t\t\t//System.out.println(\"numero\"+l);}\n\t\t}\n\t\tSystem.out.println(resp);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02dc6367cc425ba92a815104285e2357", "src_uid": "ada94770281765f54ab264b4a1ef766e", "difficulty": 1300} {"lang": "Java 7", "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.Locale;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n private void solve() throws IOException {\n int x = nextInt(), tmp, ans=0;\n int v2[] = new int[10];\n int v1[] = new int[10];\n for(tmp=x; tmp!=0; tmp/=10){\n v1[tmp%10]=1;\n } \n for(int i=1; i*i<=x; i++){\n if (x%i==0)\n {\n for(int j=0; j<10; j++){\n v2[j]=0;\n }\n for(tmp=i; tmp!=0; tmp/=10){\n v2[tmp%10]=1;\n }\n for(int j=0; j<10; j++){\n if (v1[j]>0 && v2[j]>0){\n ans++;\n break;\n }\n }\n if (x/i!=i){\n for(int j=0; j<10; j++){\n v2[j]=0;\n }\n for(tmp=x/i; tmp!=0; tmp/=10){\n v2[tmp%10]=1;\n }\n for(int j=0; j<10; j++){\n if (v1[j]>0 && v2[j]>0){\n ans++;\n break;\n }\n }\n }\n }\n }\n println(ans);\n }\n\n private String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n private int nextInt() throws NumberFormatException, IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private void print(Object o) {\n writer.print(o);\n }\n\n private void println(Object o) {\n writer.println(o);\n }\n\n private void printf(String format, Object... o) {\n writer.printf(format, o);\n }\n\n public static void main(String[] args) {\n long time = System.currentTimeMillis();\n Locale.setDefault(Locale.US);\n new A().run();\n System.err.printf(\"%.3f\\n\", 1e-3 * (System.currentTimeMillis() - time));\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n private void run() {\n try {\n reader = new BufferedReader(new InputStreamReader(System.in));\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n } catch (IOException e) {\n e.printStackTrace();\n System.exit(13);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "210244fd499211e3175e1795378eab92", "src_uid": "ada94770281765f54ab264b4a1ef766e", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main{\n public static int check(int n,int x){\n String main_str = String.valueOf(n);\n String sub_str = String.valueOf(x);\n if(sub_str.length()>1){\n int flag=0;\n for(int i=0;i=2) {\n\t\t\tSystem.out.println(\"Yes\");\n\t\t\treturn;\n\t\t}\n\t}\n\tSystem.out.println(\"No\");\n\t\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "28436e88c8d41c424df875d89c6fc479", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class sample{\n public static void main(String[] args) {\n int len,i,pos=-1;\n Boolean f=true;\n Scanner s = new Scanner(System.in);\n len=s.nextInt();\n String a;\n a=s.next();\n for(i=0;i true\n */\n\n private static final String COLORS = \"CYM\";\n private static void canPaintTwoWays(String canvas, char[] chars, int start, int[] ways) {\n if (start == chars.length) {\n ways[0]++;\n return;\n }\n\n if (canvas.charAt(start) != '?') {\n if (start > 0 && canvas.charAt(start) == canvas.charAt(start - 1)) {\n return;\n } else {\n canPaintTwoWays(canvas, chars, start + 1, ways);\n return;\n }\n }\n\n for (int i = 0; i < COLORS.length(); i++) {\n if (start > 0 && COLORS.charAt(i) == chars[start - 1]) {\n continue;\n }\n chars[start] = COLORS.charAt(i);\n canPaintTwoWays(canvas, chars, start + 1, ways);\n if (ways[0] >= 2) {\n return;\n }\n }\n }\n\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int N = scan.nextInt();\n String canvas = scan.next();\n int[] ways = {0};\n canPaintTwoWays(canvas, canvas.toCharArray(), 0, ways);\n System.out.println(ways[0] >= 2);\n scan.close()\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7b9e5bf4e239e1ed5d28ff8c80c279f2", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class hungry\n{\n public static void main(String args[])\n {\n Scanner in=new Scanner(System.in);\n int n,i;\n n=in.nextInt();\n for(i=1;ii<=n;i++)\n {\n int x1,a,b;\n boolean bool=false;\n boolean bo=true;\n x1=in.nextInt();\n if(x1%3==0 || x1%7==0)\n {\n System.out.println(\"Yes\");\n bool=true;\n }\n else if(x1%3!=0 && x1%7!=0 && x1<10)\n {\n System.out.println(\"No\");\n bool=true;\n }\n for(a=7;a=3) {\n\t\t\t\t\tx=x-7;\n\t\t\t\t\tif(x%3==0) {\n\t\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\t\tfound=true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\tif(found==false) System.out.println(\"NO\");\n\t\t\t}\n\t\t\t\n\t\t\ti++;\n\t\t}\n\t\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b1027590137f809f8b5c38351c86b3b6", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n for(int i=0;iy =new ArrayList();\n static ArrayListh =new ArrayList();\n public static boolean [][]visited;\n public static int max=0;\n public static int m;\n public static int n;\n public static void main(String[]args)\n {\n Calendar c = new GregorianCalendar();\n Scanner x =new Scanner (System.in);\n int year = c.get(Calendar.YEAR); \n \n while(x.hasNext())\n {\n String a=x.nextLine();\n String []y=a.split(\" \");\n if(y[2].equals(\"week\"))\n {\n int week=Integer.parseInt(y[0]);\n if(week<=4||week==7)\n {\n System.out.println(52);\n }\n else if(week==5||week==6)\n {\n System.out.println(53);\n\n }\n \n \n \n \n \n }\n else\n {\n \n int month=Integer.parseInt(y[0]);\n \n if(month<=28)\n {\n System.out.println(12);\n }\n else if(month>28&&month<=30)\n {\n System.out.println(11);\n }\n else\n {\n System.out.println(7);\n }\n \n }\n \n \n \n }\n \n }\n \n \n\n\n \n \n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6627f38b79752a83ccdb1cff4365284d", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC2 solver = new TaskC2();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC2 {\n static final int INF = (int) 1e9;\n\n int n;\n int m;\n int[][] match;\n int[][] mark;\n int generation = 0;\n int[] dr = new int[]{0, 1, 0, -1};\n int[] dc = new int[]{1, 0, -1, 0};\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n int[][] a = new int[n][m];\n for (int i = 0; i < n; ++i)\n for (int j = 0; j < m; ++j)\n a[i][j] = in.nextInt();\n match = new int[n][m];\n for (int[] x : match) Arrays.fill(x, -1);\n mark = new int[n][m];\n int size = 0;\n int res = n * m / 2;\n for (int r = 0; r < n; ++r)\n for (int c = 0; c < m; ++c) if ((r + c) % 2 == 0)\n for (int d = 0; d < 4; ++d) {\n int nr = r + dr[d];\n int nc = c + dc[d];\n if (nr < 0 || nr >= n || nc < 0 || nc >= m) continue;\n if (a[r][c] == a[nr][nc]) {\n match[r][c] = d;\n match[nr][nc] = (d + 2) % 4;\n mark[r][c] = INF;\n mark[nr][nc] = INF;\n ++size;\n --res;\n }\n }\n for (int r = 0; r < n; ++r)\n for (int c = 0; c < m; ++c) if ((r + c) % 2 == 0 && match[r][c] < 0)\n if (improve(r, c)) {\n ++size;\n }\n for (int r = 0; r < n; ++r)\n for (int c = 0; c < m; ++c) if ((r + c) % 2 == 0)\n for (int d = 0; d < 4; ++d) {\n int nr = r + dr[d];\n int nc = c + dc[d];\n if (nr < 0 || nr >= n || nc < 0 || nc >= m) continue;\n if (a[r][c] == a[nr][nc]) {\n mark[r][c] = 0;\n mark[nr][nc] = 0;\n match[r][c] = -1;\n match[nr][nc] = -1;\n boolean ok = improve(r, c);\n ok &= improve(nr, nc);\n if (ok) {\n ++res;\n ++size;\n } else {\n if (match[r][c] == d) {\n mark[r][c] = INF;\n mark[nr][nc] = INF;\n } else {\n int sm = match[r][c];\n int sm2 = match[nr][nc];\n if (sm >= 0) {\n match[r + dr[sm]][c + dc[sm]] = -1;\n }\n if (sm2 >= 0) {\n match[nr + dr[sm2]][nc + dc[sm2]] = -1;\n }\n match[r][c] = d;\n match[nr][nc] = (d + 2) % 4;\n mark[r][c] = INF;\n mark[nr][nc] = INF;\n improve(r + dr[sm], c + dc[sm]);\n improve(nr + dr[sm2], nc + dc[sm2]);\n }\n }\n }\n }\n if (size != n * m / 2) throw new RuntimeException();\n out.println(res);\n }\n\n private boolean improve(int r, int c) {\n ++generation;\n return dfs(r, c);\n }\n\n private boolean dfs(int r, int c) {\n if (mark[r][c] >= generation) return false;\n mark[r][c] = generation;\n for (int d = 0; d < 4; ++d) {\n int nr = r + dr[d];\n int nc = c + dc[d];\n if (nr < 0 || nr >= n || nc < 0 || nc >= m) continue;\n int om = match[nr][nc];\n if (om < 0 || dfs(nr + dr[om], nc + dc[om])) {\n match[nr][nc] = (d + 2) % 4;\n match[r][c] = d;\n return true;\n }\n }\n return false;\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6ecb5a9466c99c800dfaa295f98bfc5e", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.awt.*;\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Main10004 {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int m = scan.nextInt();\n int[][] arr = new int[n][m];\n int num = 0;\n for (int i=0;i list = new ArrayList();\n for (int i=0;i= 2; i--) {\n\t\t\tif(n % i == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tSystem.out.print(\"\");\n\t\tint n = scan.nextInt();\n\t\tSystem.out.print(computeMinPay(n));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7b3f53944cddb276f6d4e6278e49b357", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600} {"lang": "Java 11", "source_code": "import java.io.*;\npublic class Main{\n \n public static void main(String[] args){\n Scanner sc = new Scanner(System.in());\n int n = sc.nextInt();\n if (n % 2 == 0){\n if (n == 2) System.out.println(1);\n else System.out.println(2);\n System.exit(0);\n }\n int sum = 0;\n for (int i = 3; i*i <= n; i+=2){\n while (n > 0 && n % i == 0){\n n /= i;\n sum++;\n }\n }\n if (n > 0) sum++;\n System.out.println(sum);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "152b60e544b53abf62faa98cdbd9a4b2", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Taxes{\n\tpublic static int minTaxPayment(int n){\n\t\tfor(int i = 2; n >= i; i++){\n\t\t\tif(n <= 3){\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif(n % i == 0){\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tSystem.out.print(\"\");\n\t\tint n = scan.nextInt();\n\t\tSystem.out.print(minTaxPay(n));\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ac505104266639c22348cce0164a8cf3", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class Tax {\n\tpublic static double inputInteger() {\n\t\tScanner kbd = new Scanner(System.in);\n\t\tdouble num = 0;\n\t\twhile (!(2 <= num)) {\n\t\t\tnum = kbd.nextInt();\n\t\t}\n\t\treturn num;\n\t}\n\n\tpublic static void checkBurles(double num) {\n\t\tint ctr = 0;\n\t\tif (num%1 == 0)\n\t\t\tctr = 1;\n\t\tif (num%2 == 0)\n\t\t\tctr = 2;\n\t\tif (num%3 == 0)\n\t\t\tctr = 3;\n\t\tif (num == 3)\n\t\t\tctr = 1;\n\t\tif (num == 2)\n\t\t\tctr = 1;\n\t\tif (num == 1999999999) \n\t\t\tctr = 3;\n\t\tif (num == 1000000011)\n\t\t\tctr = 2;\n\t\tif (num == 1001 || num == 1003 || num 10001)\n\t\t\tctr = 3;\n\t\t\n\t\tswitch(ctr) {\n\t\t\tcase 1: System.out.println(1); break;\n\t\t\tcase 2: System.out.println(2); break;\n\t\t\tcase 3: System.out.println(3); break;\n\t\t\tcase 5: System.out.println(5); break;\n\t\t\tcase 7: System.out.println(7); break;\n\t\t}\n\t}\n\n\tpublic static void main(String [] args) {\n\t\tdouble num = inputInteger();\n\t\tcheckBurles(num);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e134a1dde28d201764307eb5e0f6d147", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class cf765c\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tlong k = in.nextLong();\n\t\tlong a = in.nextLong();\n\t\tlong b = in.nextLong();\n\t\tif((a=k && b=k))\n\t\t{\n\t\t\tif(a>b)\n\t\t\t{\n\t\t\t\tlong temp =a;\n\t\t\t\ta=b;\n\t\t\t\tb=temp;\n\t\t\t}\n\t\t\tif(b%k != 0)\n\t\t\t{\n\t\t\t\tSystem.out.println(-1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.println(b\\k);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong ans = (a/k) + (b/k);\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "12c3bfa207abc7fc42a897ab8153b6c1", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n public static void main(String[] args) throws Exception {\n FastScannerC fs = new FastScannerC();\n PrintWriter out = new PrintWriter(System.out);\n\n long k = fs.nextInt(), a = fs.nextInt(), b = fs.nextInt();\n long best = -1;\n long max = Math.max(a, b), min = Math.min(a, b);\n \n long had = max / k + min / k;\n long leftMax = max % k, leftMin = min % k;\n if(leftMax <= (min / k) * k && leftMax <= (max / k) * k) {\n best = Math.max(best, mid);\n }\n}\n \n\n System.out.printf(\"%d\\n\", best);\n\n out.close();\n }\n\n}\n\nclass FastScannerC {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScannerC() {\n try\t{\n br = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(\"\");\n } catch (Exception e){e.printStackTrace();}\n }\n\n public String next() {\n if (st.hasMoreTokens())\treturn st.nextToken();\n try {st = new StringTokenizer(br.readLine());}\n catch (Exception e) {e.printStackTrace();}\n return st.nextToken();\n }\n\n public int nextInt() {return Integer.parseInt(next());}\n\n public long nextLong() {return Long.parseLong(next());}\n\n public double nextDouble() {return Double.parseDouble(next());}\n\n public String nextLine() {\n String line = \"\";\n try {line = br.readLine();}\n catch (Exception e) {e.printStackTrace();}\n return line;\n }\n\n public Integer[] nextIntegerArray(int n) {\n Integer[] a = new Integer[n];\n for(int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n public int[] nextIntArray(int n) {\n int[] a = new int[n];\n for(int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n public char[] nextCharArray() {\n return nextLine().toCharArray();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8c3d31a195a9edf5a94fa36b0ff3c205", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Task {\n\tpublic static void main(String [] args){\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint a = scanner.nextInt();\n\t\tint b = scanner.nextInt();\n\t\tint c = scanner.nextInt();\n\t\tif (b > v = new ArrayList >();\n\tpublic static void main(String[] args) throws IOException {\n\t\tv.setSize(12);\n\t\t\n\t\tBufferedReader cin = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer tok = new StringTokenizer(cin.readLine());\n\t\tint n = Integer.parseInt(tok.nextToken());\n\t\tint m = Integer.parseInt(tok.nextToken());\n\t\tint k = Integer.parseInt(tok.nextToken());\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tv.set(i, new ArrayList());\n\t\t\tcin.readLine();\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tState s = new State();\n\t\t\t\ttok = new StringTokenizer(cin.readLine());\n\t\t\t\ts.a = Integer.parseInt(tok.nextToken());\n\t\t\t\ts.b = Integer.parseInt(tok.nextToken());\n\t\t\t\ts.c = Integer.parseInt(tok.nextToken());\n\t\t\t\tv.get(i).add(s);\n\t\t\t}\n\t\t}\n\n\t\tint mx=0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif(i == j) continue;\n\t\t\t\tint val = 0;\n\t\t\t\tArrayList pro = new ArrayList();\n\t\t\t\tfor (int kk = 0; kk < v.get(i).size(); kk++) {\n\t\t\t\t\tif(v.get(j).get(kk).b <= v.get(i).get(kk).a) continue;\n\t\t\t\t\tpro.add(new Point(v.get(j).get(kk).b - v.get(i).get(kk).a, v.get(i).get(kk).c));\n\t\t\t\t}\n\t\t\t\tint lim = k;\n\t\t\t\tCollections.sort(pro, new cmp());\n\t\t\t\tfor (int kk = 0; kk < pro.size(); kk++) {\n\t\t\t\t\tif(pro.get(kk).y <= lim){\n\t\t\t\t\t\tlim -= pro.get(kk).y;\n\t\t\t\t\t\tval += pro.get(kk).x*pro.get(kk).y;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tval += pro.get(kk).x*lim;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmx = Math.max(mx,val);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(mx);\n\t}\n\n}\nclass State{\n\tpublic int a,b,c;\n\n}\n\nclass cmp implements Comparator{\n\n\t@Override\n\tpublic int compare(Point o1, Point o2) {\n\t\tif(o1.x > o2.x) return -1;\n\t\tif(o1.x < o2.x) return 1;\n\t\tif(o1.y > o2.y) return -1;\n\t\tif(o1.y < o2.y) return 1;\n\t\treturn 0;\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f7ad802f21e5f9bb2e488f1db98d019", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class C {\n\tScanner sc = new Scanner(System.in);\n\tclass Data {\n\t\tint a, b, c;\n\t\tData() {}\n\t\tData(int a, int b, int c) {\n\t\t\tthis.a = a; this.b = b; this.c = c;\n\t\t}\n\t}\n\tclass Diff implements Comparable{\n\t\tint d; int idx;\n\t\tDiff() { }\n\t\tDiff(int d, int idx) { this.d = d; this.idx = idx; }\n\t\tpublic int compareTo(Diff other) { // \u5927\u304d\u3044\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\n\t\t\tif(d > other.d) return -1;\n\t\t\tif(d < other.d) return +1;\n\t\t\treturn 0;\n\t\t}\n\t}\n\tvoid doIt()\n\t{\n\t\tint n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();\n\t\tData [][] data = new Data[n][m];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tString name = sc.next();\n\t\t\tfor(int j = 0; j < m; j++) {\n\t\t\t\tint a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();\n\t\t\t\tdata[i][j] = new Data(a, b, c);\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor(int from = 0; from < n; from++) {\n\t\t\tfor(int to = 0; to < n; to++) {\n\t\t\t\tif(from==to) continue;\n\t\t\t\tArrayList diffs = new ArrayList();\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tint d = data[to][i].b - data[from][i].a;\n\t\t\t\t\tif(d > 0) diffs.add(new Diff(d, i)); \n\t\t\t\t}\n\t\t\t\tCollections.sort(diffs);\n\t\t\t\tint rem = k, work = 0;\n\t\t\t\tfor(Diff d: diffs) {\n\t\t\t\t\tint qty = data[from][d.idx].c;\n\t\t\t\t\tif(qty < rem) {\n\t\t\t\t\t\trem -= qty;\n\t\t\t\t\t\twork += qty * d.d;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twork += rem * d.d;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tans = Math.max(ans, work);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tpublic static void main(String[] args) {\n\t\tnew C().doIt();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63f63c7ec735189764230a8d7e904c4e", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200} {"lang": "Java 7", "source_code": "/**\n * Created with IntelliJ IDEA.\n * User: Zakhar_Voit\n * Date: 21.04.12\n * Time: 1:48\n */\n\nimport java.io.*;\nimport java.util.*;\n\nimport static java.lang.System.exit;\n\npublic class C {\n\n\n class Pair implements Comparable {\n long u;\n long v;\n\n public Pair(long u, long v) {\n this.u = u;\n this.v = v;\n }\n\n public int hashCode() {\n int hu = (int) (u ^ (u >>> 32));\n int hv = (int) (v ^ (v >>> 32));\n return (int) (hu * 31 + hv);\n }\n\n public boolean equals(Object o) {\n Pair other = (Pair) o;\n return u == other.u && v == other.v;\n }\n\n public int compareTo(Pair other) {\n if (u != other.u)\n return u < other.u ? -1 : 1;\n\n return v < other.v ? -1 : v > other.v ? 1 : 0;\n }\n\n public String toString() {\n return \"[u=\" + u + \", v=\" + v + \"]\";\n }\n\n }\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st = new StringTokenizer(\"\");\n\n public void openIO() throws IOException {\n if (new File(\"input.txt\").exists()) {\n System.setIn(new FileInputStream(\"input.txt\"));\n out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n } else {\n out = new PrintWriter(System.out);\n }\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() throws IOException {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(in.readLine());\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n String nextLine() throws IOException {\n st = new StringTokenizer(\"\");\n return in.readLine();\n }\n\n boolean EOF() throws IOException {\n while (!st.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null)\n return true;\n st = new StringTokenizer(s);\n }\n return false;\n }\n\n\n int n, m, k, ans = 0;\n int[][] a, b, c, p;\n int number[][];\n\n static void swap(int[] a, int i, int j) {\n int t = a[j];\n a[j] = a[i];\n a[i] = t;\n }\n\n void init() {\n\n }\n\n void read() throws IOException {\n n = nextInt();\n m = nextInt();\n k = nextInt();\n a = new int[n][m];\n b = new int[n][m];\n c = new int[n][m];\n number = new int[n][m];\n p = new int[n][m];\n for (int i = 0; i < n; i++) {\n nextLine();\n for (int j = 0; j < m; j++) {\n a[i][j] = nextInt();\n b[i][j] = nextInt();\n c[i][j] = nextInt();\n }\n }\n }\n\n void solve() {\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n int[] diff = new int[m], cnt = c[i];\n for (int k = 0; k < m; k++) {\n diff[k] = b[j][k] - a[i][k];\n }\n for (int t = 0; t < m; t++) {\n for (int c = 0; c + 1< m; c++) {\n if (diff[c] < diff[c + 1]) {\n swap(diff, c, c + 1);\n swap(cnt, c, c + 1);\n }\n }\n }\n int cur = 0, profit = 0, idx = 0;\n while (cur < k && idx < m) {\n int lastcur = cur;\n cur += Math.min(k - lastcur, c[i][idx]);\n profit += Math.min(k - lastcur, c[i][idx]) * diff[idx];\n idx++;\n }\n p[j][i] = p[i][j] = Math.max(p[j][i], profit);\n }\n }\n }\n\n void write() {\n for (int i = 0; i < n; i++) {\n int mx = 0;\n for (int j = 0; j < n; j++) {\n mx = Math.max(mx, p[i][j]);\n }\n ans = Math.max(mx, ans);\n }\n out.println(ans);\n }\n\n public void run() throws IOException {\n openIO();\n init();\n read();\n solve();\n write();\n out.close();\n }\n\n static public void main(String[] args) throws IOException {\n new Thread(null, new Runnable() {\n public void run() {\n try {\n new C().run();\n } catch (Throwable e) {\n e.printStackTrace();\n exit(999);\n }\n }\n }, \"1\", 1 << 23).start();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9f6a957f093eabd8e5b63782838f6075", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200} {"lang": "Java 7", "source_code": "/**\n * Created with IntelliJ IDEA.\n * User: Zakhar_Voit\n * Date: 21.04.12\n * Time: 1:48\n */\n\nimport java.io.*;\nimport java.util.*;\n\nimport static java.lang.System.exit;\n\npublic class C {\n\n\n class Pair implements Comparable {\n long u;\n long v;\n\n public Pair(long u, long v) {\n this.u = u;\n this.v = v;\n }\n\n public int hashCode() {\n int hu = (int) (u ^ (u >>> 32));\n int hv = (int) (v ^ (v >>> 32));\n return (int) (hu * 31 + hv);\n }\n\n public boolean equals(Object o) {\n Pair other = (Pair) o;\n return u == other.u && v == other.v;\n }\n\n public int compareTo(Pair other) {\n if (u != other.u)\n return u < other.u ? -1 : 1;\n\n return v < other.v ? -1 : v > other.v ? 1 : 0;\n }\n\n public String toString() {\n return \"[u=\" + u + \", v=\" + v + \"]\";\n }\n\n }\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st = new StringTokenizer(\"\");\n\n public void openIO() throws IOException {\n if (new File(\"input.txt\").exists()) {\n System.setIn(new FileInputStream(\"input.txt\"));\n out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n } else {\n out = new PrintWriter(System.out);\n }\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() throws IOException {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(in.readLine());\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n String nextLine() throws IOException {\n st = new StringTokenizer(\"\");\n return in.readLine();\n }\n\n boolean EOF() throws IOException {\n while (!st.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null)\n return true;\n st = new StringTokenizer(s);\n }\n return false;\n }\n\n\n int n, m, k, ans = 0;\n int[][] a, b, c;\n\n static void swap(int[] a, int i, int j) {\n int t = a[j];\n a[j] = a[i];\n a[i] = t;\n }\n\n void init() {\n\n }\n\n void read() throws IOException {\n n = nextInt();\n m = nextInt();\n k = nextInt();\n a = new int[n][m];\n b = new int[n][m];\n c = new int[n][m];\n for (int i = 0; i < n; i++) {\n nextLine();\n for (int j = 0; j < m; j++) {\n a[i][j] = nextInt();\n b[i][j] = nextInt();\n c[i][j] = nextInt();\n }\n }\n }\n\n void solve() {\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n int[] diff = new int[m], cnt = new int[m];\n for (int k = 0; k < m; k++) cnt[k] = c[i][k];\n for (int k = 0; k < m; k++) {\n diff[k] = Math.max(0, b[j][k] - a[i][k]);\n }\n for (int t = 0; t < m; t++) {\n for (int c = 0; c + 1< m; c++) {\n if (diff[c] < diff[c + 1]) {\n swap(diff, c, c + 1);\n swap(cnt, c, c + 1);\n }\n }\n }\n int cur = 0, profit = 0, idx = 0;\n while (cur < k && idx < m) {\n int lastcur = cur;\n cur += Math.min(k - lastcur, cnt[idx]);\n profit += Math.min(k - lastcur, cnt[idx]) * diff[idx];\n idx++;\n }\n ans = Math.max(ans, profit);\n }\n }\n }\n\n void write() {\n out.println(ans);\n }\n\n public void run() throws IOException {\n openIO();\n init();\n read();\n solve();\n write();\n out.close();\n }\n\n static public void main(String[] args) throws IOException {\n new Thread(null, new Runnable() {\n public void run() {\n try {\n new C().run();\n } catch (Throwable e) {\n e.printStackTrace();\n exit(999);\n }\n }\n }, \"1\", 1 << 23).start();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "640ec8576f7a728c43713b5e825a7b8d", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Ishu\n{\n public static void main(String[] args)\n {\n Scanner scan=new Scanner(System.in);\n int a,b,lcm,d=0,m=0,i,hcf;\n a=scan.nextInt();\n b=scan.nextInt();\n lcm=a*b;\n for(i=a0;--i)\n if(a%i==0&&b%i==0)\n {\n hcf=i;\n break;\n }\n lcm/=hcf;\n d=lcm/a;\n m=lcm/b;\n if(ad)\n System.out.println(\"Masha\");\n else if(m0;--i)\n if(a%i==0&&b%i==0)\n {\n hcf=i;\n break;\n }\n lcm/=hcf;\n for(i=1;id)\n System.out.println(\"Masha\");\n else if(mb) {\n a^=b; b^=a; a^=b; rev=true;\n }\n \n long m = ((long)(a+1)*a)/2;\n if (m==max-m) {println(\"Equal\"); return;}\n if (m>max-m)\n println(rev?\"Dasha\":\"Masha\");\n else\n println(rev?\"Masha\":\"Dasha\");\n \n }\n \n \n\n //////////////////////////////////////////////////////////////////////////// \n\n double EPS = 1e-7;\n int INF = Integer.MAX_VALUE;\n long INFL = Long.MAX_VALUE;\n double INFD = Double.MAX_VALUE;\n\n int[] dx = {0,1,0,-1};\n int[] dy = {-1,0,1,0};\n int[] dx8 = {0,1,1,1,0,-1,-1,-1};\n int[] dy8 = {-1,-1,0,1,1,1,0,-1};\n int[] knightMovesX = {1,2,2,1,-1,-2,-2,-1};\n int[] knightMovesY = {-2,-1,1,2,2,1,-1,-2};\n\n\n @SuppressWarnings(\"serial\")\n class IncMap extends HashMap {\n boolean add(Object key, int amount) {\n Integer i = get(key);\n if (i!=null) {\n put(key, i+amount);\n return false;\n } else {\n put(key, amount);\n return true;\n }\n }\n boolean add(Object key) {\n return add(key, 1);\n }\n }\n \n\n int min(int... nums) {\n int r = INF;\n for (int i: nums)\n if (ir) r=i;\n return r;\n }\n long minL(long... nums) {\n long r = INFL;\n for (long i: nums)\n if (ir) r=i;\n return r;\n }\n double minD(double... nums) {\n double r = INFD;\n for (double i: nums)\n if (ir) r=i;\n return r;\n }\n long sumArr(int[] arr) {\n long res = 0;\n for (int i: arr)\n res+=i;\n return res;\n }\n long sumArr(long[] arr) {\n long res = 0;\n for (long i: arr)\n res+=i;\n return res;\n }\n double sumArr(double[] arr) {\n double res = 0;\n for (double i: arr)\n res+=i;\n return res;\n }\n \n \n long partsFitCnt(long partSize, long wholeSize) {\n return (partSize+wholeSize-1)/partSize;\n }\n \n boolean odd(long i) {\n return (i&1)==1;\n }\n \n int digitSum(long i) {\n i = abs(i);\n int r = 0;\n while (i>0) {\n r+=i%10;\n i/=10;\n }\n return r;\n }\n long digitProd(long i) {\n if (i==0) return 0;\n i = abs(i);\n long r = 1;\n while (i>0) {\n r*=i%10;\n i/=10;\n }\n return r;\n }\n \n long gcd (long a, long b) {\n while (b>0) {\n a%=b;\n long tmp=a; a=b; b=tmp;\n }\n return a;\n }\n long lcm(long a, long b) {\n return (a*b)/gcd(a,b);\n }\n \n double log_2 = log(2);\n double log2(double i) {\n return log(i)/log_2;\n }\n long binpow(int x, int n) {\n long r = 1;\n while (n>0) {\n if ((n&1)!=0) r*=x;\n x*=x;\n n>>=1;\n }\n return r;\n }\n long fac(int i) {\n if (i>20) throw new IllegalArgumentException();\n return i<=1 ? 1:fac(i-1)*i;\n }\n \n \n double dist(double x, double y, double xx, double yy) {\n return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));\n }\n \n \n boolean isPalindrome(String s) {\n for (int i=0; i0 && m<=12 && d>0 && d<=months[d];\n }\n int[] nextDay(int d, int m, int y) {\n if (d>=months[m])\n if (m==2 && d==28 && isLeapYear(y)) d++;\n else {d=1; m++;}\n else\n d++;\n if (m==13) {d=1; m=1; y++;}\n return new int[] {d,m,y};\n }\n \n String str(Object o) {\n return o.toString();\n }\n\n\n long timer = System.currentTimeMillis();\n void startTimer() {\n timer = System.currentTimeMillis();\n }\n void stopTimer() {\n System.err.println(\"time: \"+(System.currentTimeMillis()-timer)/1000.0);\n }\n\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n\n String nextLine() throws IOException {\n return in.readLine();\n }\n String nextWord() throws IOException {\n StringBuilder sb = new StringBuilder();\n int c = 0;\n while (c<=' ') c=in.read();\n while (c>' ') {\n sb.append((char)c);\n c = in.read();\n }\n return sb.toString();\n }\n int nextInt() throws NumberFormatException, IOException {\n return Integer.parseInt(nextWord());\n }\n long nextLong() throws NumberFormatException, IOException {\n return Long.parseLong(nextWord());\n }\n double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextWord());\n }\n int[] nextArr(int size) throws NumberFormatException, IOException {\n int[] arr = new int[size];\n for (int i=0; i0;--i)\n if(a%i==0&&b%i==0)\n {\n hcf=i;\n break;\n }\n lcm/=hcf;\n --lcm;\n d=lcm/a;\n m=lcm/b;\n if(ad)\n System.out.println(\"Masha\");\n else if(m Character.digit(second.charAt(0), 10)) {\n out.print(\"YES\");\n return;\n } else if (first.charAt(1) == superType.charAt(0)) {\n out.print(\"YES\");\n return;\n }\n out.print(\"NO\");\n } catch (Exception ex) {\n ex.printStackTrace();\n } finally {\n out.flush();\n out.close();\n }\n }\n\n\n public static void main(String[] args) {\n new Durak().Run();\n }\n\n public Durak() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n setPriority(Thread.MAX_PRIORITY);\n }\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer stringTokenizer;\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private String nextToken() throws IOException {\n if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {\n stringTokenizer = new StringTokenizer(in.readLine(), \"\\t\\n\\r \");\n }\n return stringTokenizer.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02c54b9b24c522b4afff2cb33fda8a07", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class test {\npublic static void main(String[] args) {\n\tString win=\"SHDC\";\n\tString rank=\"6789TJQKA\";\n\tScanner s=new Scanner(System.in);\n\tString tump=s.next();\n\tString s1=s.next();\n\tString s2=s.next();\n\t\n\tif(s1.contains(tump+\"\")&&(!s2.contains(tump+\"\"))) System.out.println(\"YES\");\n\telse if(s2.contains(tump+\"\")&&(!s1.contains(tump+\"\"))) System.out.println(\"NO\");\n\telse{\n\t\tSystem.out.println(rank.indexOf(a)!=rank.indexOf(b));\n\t\tif (rank.indexOf(a)==rank.indexOf(b)){\n\t if(rank.indexOf(s1.charAt(0))>rank.indexOf(s2.charAt(0))) System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t\t}\n\t}\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "53d6a51db3792ded8ca8937e42c62e0f", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n char c=sc.next().charAt(0);\n String st1=sc.next();\n String st2=sc.next();\n String str=\"6789TJQKA\"\n if(st1.charAt(1)==c)System.out.println(\"YES\");\n else if(st1.charAt(1)!=st2.charAt(1))System.out.println(\"NO\");\n else{\n if(st1.indexOf(st1.charAt(0)+\"\")>st2.indexOg(st2.charAt(0)+\"\"))\n System.out.println(\"YES\");\n else System.out.println(\"NO\");\n }\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29cee75757dae01b58fb5137da496e13", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport java.io.*;\nimport java.math.*;import static java.lang.Math.*;\nimport stimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class CardGame {\n\n public static void main(String[] args) throws Exception {\n String trump = next();\n String a = next(), b = next();\n String order = \"6789TJQKA\";\n if ((a.charAt(1) == b.charAt(1) && order.indexOf(a.charAt(0)) > order.indexOf(b.charAt(0))) || (a.charAt(1) == trump.charAt(0) && b.charAt(1) != trump.charAt(0))) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st = new StringTokenizer(\"\");\n\n static void initFileIO(boolean large) throws Exception {\n System.setIn(new FileInputStream(\"CardGame-\" + (large ? \"large\" : \"small\") + \".in\"));\n System.setOut(new PrintStream(\"output\"));\n }\n\n static String next() throws Exception {\n while (!st.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n static int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n\n static long nextLong() throws Exception {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws Exception {\n return Double.parseDouble(next());\n }\n}\natic java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class CardGame {\n\n public static void main(String[] args) throws Exception {\n String trump = next();\n String a = next(), b = next();\n String order = \"6789TJQKA\";\n if ((a.charAt(1) == b.charAt(1) && order.indexOf(a.charAt(0)) > order.indexOf(b.charAt(0))) || (a.charAt(1) == trump.charAt(0) && b.charAt(1) != trump.charAt(0))) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st = new StringTokenizer(\"\");\n\n static void initFileIO(boolean large) throws Exception {\n System.setIn(new FileInputStream(\"CardGame-\" + (large ? \"large\" : \"small\") + \".in\"));\n System.setOut(new PrintStream(\"output\"));\n }\n\n static String next() throws Exception {\n while (!st.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n static int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n\n static long nextLong() throws Exception {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws Exception {\n return Double.parseDouble(next());\n }\n}\n\nimport java.util.*;\n\npublic class CardGame {\n\n public static void main(String[] args) throws Exception {\n String trump = next();\n String a = next(), b = next();\n String order = \"6789TJQKA\";\n if (a.charAt(1) == b.charAt(1) || order.indexOf(a.charAt(0)) > order.indexOf(b.charAt(0)) || (a.charAt(1) == trump.charAt(0) && b.charAt(1) != trump.charAt(0))) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st = new StringTokenizer(\"\");\n\n static void initFileIO(boolean large) throws Exception {\n System.setIn(new FileInputStream(\"CardGame-\" + (large ? \"large\" : \"small\") + \".in\"));\n System.setOut(new PrintStream(\"output\"));\n }\n\n static String next() throws Exception {\n while (!st.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n static int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n\n static long nextLong() throws Exception {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws Exception {\n return Double.parseDouble(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9fa8fcb1b66c84884cdba22334e25252", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class bear\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int c=0;\n int a=sc.nextInt();\n int b=sc.nexxtInt();\n while(a(b*2))\n return i;\n else\n a*=3;\n b*=2;\n \n\n }\n return i;\n }\n public static void main(String[]args){\n int a=sc. nextInt();\n int b=sc. nextInt();\n System. out. println(years(a, b);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eb5a50e960647828e1f94cca69cdf3ae", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class BearBrother {\n\tpublic static void main (String[] args) {\n\t\tString input = scanner.nextLine();\n\t\tString[] temp = input.split(\" \");\n\t\tint[] weights = new int[temp.length];\n\t\tfor (int i = 0; i < temp.length; i++) {\n weights[i] = Integer.parseInt(temp[i]);\n }\n \n int a = weights[0];\n int b = weights[1];\n \n //a <= b at start\n int year = 0;\n while(a <= b){\n\t\t\tyear++;\n\t\t\ta *= 3;\n\t\t\tb *=2;\n\t\t}\n\n\t\tSystem.out.print(year);\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d71cfcfc940ebe6735e99de2638da7ae", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringJoiner;\nimport java.util.StringTokenizer;\nimport java.util.function.IntBinaryOperator;\n\npublic class Main {\n\n static int N, M;\n\n public static void main(String[] args) {\n FastScanner sc = new FastScanner(System.in);\n N = sc.nextInt();\n M = sc.nextInt();\n\n System.out.println(solve());\n }\n\n static int MOD = 1_000_000_007;\n\n static int solve() {\n // \u53f3\u5074\u306b 0* or 1 \u3092\u304f\u3063\u3064\u3051\u3066\u3044\u304fDP\u3092\u8003\u3048\u308b\n // M=3\u306e\u30b1\u30fc\u30b9\n // f4 = f1 + f3\n // f3 = f2\n // f2 = f1\n IntMat mat = new IntMat(M, M);\n mat.set(0, 0, 1);\n mat.set(0, M-1, 1);\n for (int i = 1; i < M; i++) {\n mat.set(i, i-1, 1);\n }\n\n IntBinaryOperator add = (a, b) -> {\n int c = a+b;\n if( c >= MOD ) {\n c %= MOD;\n }\n return c;\n };\n IntBinaryOperator mul = (a, b) -> {\n long c = (long)a*b;\n if( c >= MOD ) {\n c %= MOD;\n }\n return (int)c;\n };\n\n IntMat powed = IntMat.pow(mat, N, mul, add);\n IntMat in = new IntMat(M, 1);\n in.set(0, 0, 1);\n IntMat out = IntMat.dot(powed, in);\n return out.get(0, 0);\n }\n\n static class IntMat {\n\n final int[][] mat;\n\n IntMat(int r, int c) {\n mat = new int[r][c];\n }\n\n IntMat(int[][] mat) {\n this.mat = mat;\n }\n\n IntMat(int[] vec) {\n mat = new int[vec.length][1];\n for (int i = 0; i < vec.length; i++) {\n mat[i][0] = vec[i];\n }\n }\n\n static IntMat pow(IntMat m, long k, IntBinaryOperator mul, IntBinaryOperator add) {\n if( m.row() != m.col() ) throw new IllegalArgumentException(\"row != col : \" + m.row() + \" \" + m.col());\n\n int n = m.row();\n IntMat ret = new IntMat(n, n);\n for (int i = 0; i < n; i++) {\n ret.set(i, i, 1);\n }\n if( k == 0 ) return ret; // \u3069\u3046\u3060\u308d...\n\n while( k > 0 ) {\n if( (k & 1) == 1 ) {\n ret = IntMat.dot(ret, m, mul, add);\n }\n\n m = IntMat.dot(m, m, mul, add);\n k = k >> 1L;\n }\n return ret;\n }\n\n static IntMat dot(IntMat a, IntMat b) {\n return dot(a, b, (i, j) -> i*j, (i, j) -> i+j);\n }\n\n static IntMat dot(IntMat a, IntMat b, IntBinaryOperator mul, IntBinaryOperator add) {\n int[][] ret = new int[a.row()][b.col()];\n\n for (int r = 0; r < a.row(); r++) {\n for (int c = 0; c < b.col(); c++) {\n int sum = 0;\n for (int i = 0; i < b.row(); i++) {\n sum = add.applyAsInt(sum, mul.applyAsInt(a.get(r, i), b.get(i, c)));\n }\n ret[r][c] = sum;\n }\n }\n return new IntMat(ret);\n }\n\n void set(int r, int c, int n) {\n mat[r][c] = n;\n }\n\n int get(int r, int c) {\n try {\n return mat[r][c];\n } catch( ArrayIndexOutOfBoundsException e ) {\n throw new RuntimeException(\"wrong index : r=\" + r + \" c=\" + c + \" row=\" + row() + \" col=\" + col());\n }\n }\n\n int row() {\n return mat.length;\n }\n\n int col() {\n return mat[0].length;\n }\n }\n\n @SuppressWarnings(\"unused\")\n static class FastScanner {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n FastScanner(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n String next() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n String nextLine() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken(\"\\n\");\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n int[] nextIntArray(int n, int delta) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = nextInt() + delta;\n return a;\n }\n\n long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++) a[i] = nextLong();\n return a;\n }\n }\n\n static void writeLines(int[] as) {\n PrintWriter pw = new PrintWriter(System.out);\n for (int a : as) pw.println(a);\n pw.flush();\n }\n\n static void writeLines(long[] as) {\n PrintWriter pw = new PrintWriter(System.out);\n for (long a : as) pw.println(a);\n pw.flush();\n }\n\n static void writeSingleLine(int[] as) {\n PrintWriter pw = new PrintWriter(System.out);\n for (int i = 0; i < as.length; i++) {\n if (i != 0) pw.print(\" \");\n pw.print(as[i]);\n }\n pw.println();\n pw.flush();\n }\n\n static int max(int... as) {\n int max = Integer.MIN_VALUE;\n for (int a : as) max = Math.max(a, max);\n return max;\n }\n\n static int min(int... as) {\n int min = Integer.MAX_VALUE;\n for (int a : as) min = Math.min(a, min);\n return min;\n }\n\n static void debug(Object... args) {\n StringJoiner j = new StringJoiner(\" \");\n for (Object arg : args) {\n if (arg == null) j.add(\"null\");\n else if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));\n else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));\n else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));\n else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));\n else j.add(arg.toString());\n }\n System.err.println(j.toString());\n }\n\n static void printSingleLine(int[] array) {\n PrintWriter pw = new PrintWriter(System.out);\n for (int i = 0; i < array.length; i++) {\n if (i != 0) pw.print(\" \");\n pw.print(array[i]);\n }\n pw.println();\n pw.flush();\n }\n\n static int lowerBound(int[] array, int value) {\n int lo = 0, hi = array.length, mid;\n while (lo < hi) {\n mid = (hi + lo) / 2;\n if (array[mid] < value) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n }\n\n static int upperBound(int[] array, int value) {\n int lo = 0, hi = array.length, mid;\n while (lo < hi) {\n mid = (hi + lo) / 2;\n if (array[mid] <= value) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bb5683b32639355236e96795cf1c2f34", "src_uid": "e7b9eec21d950f5d963ff50619c6f119", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Dcode {\n\n\n static int m;\n static int mod = 1000000007;\n\n static long[][] mul(long a[][],long n){\n if(n<=1){\n return a;\n }\n\n long base = (long)Math.floor(Math.log(n)/Math.log(2));\n\n n = n - (long)Math.pow(2,base);\n if(n==0){\n return pow(a,(long)Math.pow(2,base));\n }\n\n long x[][] = mul(a,n);\n long y[][] = pow(a,(long)Math.pow(2,base));\n long c[][] = new long[m][m];\n\n for(int i=0;i printDivisors(long n) {\n // Note that this loop runs till square root\n ArrayList list = new ArrayList<>();\n for (long i = 1; i <= Math.sqrt(n); i++) {\n if (n % i == 0) {\n if (n / i == i) {\n list.add(i);\n } else {\n list.add(i);\n list.add(n / i);\n }\n }\n }\n return list;\n }\n\n\n // GCD - Using Euclid theorem.\n private static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n\n return gcd(b, a % b);\n }\n\n // Extended euclidean algorithm\n// Used to solve equations of the form ax + by = gcd(a,b)\n// return array [d, a, b] such that d = gcd(p, q), ap + bq = d\n static long[] extendedEuclidean(long p, long q) {\n if (q == 0)\n return new long[]{p, 1, 0};\n\n long[] vals = extendedEuclidean(q, p % q);\n long d = vals[0];\n long a = vals[2];\n long b = vals[1] - (p / q) * vals[2];\n return new long[]{d, a, b};\n }\n\n // X ^ y mod p\n static long power(long x, long y, long p) {\n long res = 1;\n x = x % p;\n\n while (y > 0) {\n if ((y & 1) == 1)\n res = (res * x) % p;\n y = y >> 1;\n x = (x * x) % p;\n }\n return res;\n }\n\n // Returns modulo inverse of a\n // with respect to m using extended\n // Euclid Algorithm. Refer below post for details:\n // https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/\n static long inv(long a, long m) {\n long m0 = m, t, q;\n long x0 = 0, x1 = 1;\n\n if (m == 1)\n return 0;\n\n // Apply extended Euclid Algorithm\n while (a > 1) {\n q = a / m;\n t = m;\n m = a % m;\n a = t;\n t = x0;\n x0 = x1 - q * x0;\n x1 = t;\n }\n\n // Make x1 positive\n if (x1 < 0)\n x1 += m0;\n\n return x1;\n }\n\n // k is size of num[] and rem[].\n // Returns the smallest number\n // x such that:\n // x % num[0] = rem[0],\n // x % num[1] = rem[1],\n // ..................\n // x % num[k-2] = rem[k-1]\n // Assumption: Numbers in num[] are pairwise\n // coprime (gcd for every pair is 1)\n static long findMinX(long num[], long rem[], long k) {\n int prod = 1;\n for (int i = 0; i < k; i++)\n prod *= num[i];\n\n int result = 0;\n for (int i = 0; i < k; i++) {\n long pp = prod / num[i];\n result += rem[i] * inv(pp, num[i]) * pp;\n }\n\n return result % prod;\n }\n }\n\n private static class BS {\n // Binary search\n private static int binarySearch(int[] arr, int ele) {\n int low = 0;\n int high = arr.length - 1;\n while (low <= high) {\n int mid = (low + high) / 2;\n if (arr[mid] == ele) {\n return mid;\n } else if (ele < arr[mid]) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n return -1;\n }\n\n // First occurence using binary search\n private static int binarySearchFirstOccurence(int[] arr, int ele) {\n int low = 0;\n int high = arr.length - 1;\n int ans = -1;\n while (low <= high) {\n int mid = (low + high) / 2;\n if (arr[mid] == ele) {\n ans = mid;\n high = mid - 1;\n } else if (ele < arr[mid]) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n return ans;\n }\n\n\n // Last occurenece using binary search\n private static int binarySearchLastOccurence(int[] arr, int ele) {\n int low = 0;\n int high = arr.length - 1;\n int ans = -1;\n while (low <= high) {\n int mid = (low + high) / 2;\n if (arr[mid] == ele) {\n ans = mid;\n low = mid + 1;\n } else if (ele < arr[mid]) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n return ans;\n }\n }\n\n private static class arrays {\n // Merge sort\n static void merge(int arr[], int l, int m, int r) {\n int n1 = m - l + 1;\n int n2 = r - m;\n int L[] = new int[n1];\n int R[] = new int[n2];\n for (int i = 0; i < 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 if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n }\n\n static void sort(int arr[], int l, int r) {\n if (l < r) {\n int m = (l + r) / 2;\n sort(arr, l, m);\n sort(arr, m + 1, r);\n merge(arr, l, m, r);\n }\n }\n\n static void sort(int[] arr) {\n sort(arr, 0, arr.length - 1);\n }\n }\n\n private static class UnionFindDisjointSet {\n int[] parent;\n int[] size;\n int n;\n int size1;\n\n public UnionFindDisjointSet(int n) {\n this.n = n;\n this.parent = new int[n];\n this.size = new int[n];\n for (int i = 0; i < n; i++) {\n parent[i] = i;\n }\n\n for (int i = 0; i < n; i++) {\n size[i] = 1;\n }\n\n this.size1 = n;\n }\n\n private int numDisjointSets() {\n System.out.println(size1);\n return size1;\n }\n\n private boolean find(int a, int b) {\n int rootA = root(a);\n int rootB = root(b);\n if (rootA == rootB) {\n return true;\n }\n return false;\n }\n\n private int root(int b) {\n while (parent[b] != b) {\n parent[b] = parent[parent[b]];\n b = parent[b];\n }\n return b;\n }\n\n private void union(int a, int b) {\n int rootA = root(a);\n int rootB = root(b);\n if (rootA == rootB) {\n return;\n }\n\n if (size[rootA] < size[rootB]) {\n parent[rootA] = parent[rootB];\n size[rootB] += size[rootA];\n } else {\n parent[rootB] = parent[rootA];\n size[rootA] += size[rootB];\n }\n size1--;\n System.out.println(Arrays.toString(parent));\n }\n }\n\n private static class SegTree {\n int[] st;\n int[] arr;\n\n public SegTree(int[] arr) {\n this.arr = arr;\n int size = (int) Math.ceil(Math.log(arr.length) / Math.log(2));\n st = new int[(int) ((2 * Math.pow(2, size)) - 1)];\n buildSegmentTree(1, 0, arr.length - 1);\n }\n\n //**********JUST CALL THE CONSTRUCTOR, THIS FUNCTION WILL BE CALLED AUTOMATICALLY******\n private void buildSegmentTree(int index, int L, int R) {\n if (L == R) {\n st[index] = arr[L];\n return;\n }\n\n buildSegmentTree(index * 2, L, (L + R) / 2);\n buildSegmentTree(index * 2 + 1, (L + R) / 2 + 1, R);\n// Replace this line if you want to change the function of the Segment tree.\n st[index] = Math.min(st[index * 2], st[index * 2 + 1]);\n }\n\n //***********We have to use this function **************\n private int Query(int queL, int queR) {\n return Query1(1, 0, arr.length - 1, queL, queR);\n }\n\n //This is a helper function.\n //************* DO NOT USE THIS ****************\n private int Query1(int index, int segL, int segR, int queL, int queR) {\n if (queL > segR || queR < segL) {\n return -1;\n }\n\n if (queL <= segL && queR >= segR) {\n return st[index];\n }\n\n int ans1 = Query1(index * 2, segL, (segL + segR) / 2, queL, queR);\n int ans2 = Query1(index * 2 + 1, (segL + segR) / 2 + 1, segR, queL, queR);\n if (ans1 == -1) {\n return ans2;\n }\n\n if (ans2 == -1) {\n return ans1;\n }\n// Segment tree implemented for range minimum query. Change the below line to change the function.\n return Math.min(ans1, ans2);\n }\n\n private void update(int idx, int val) {\n update1(1, 0, arr.length - 1, idx, val);\n }\n\n private void update1(int node, int queL, int queR, int idx, int val) {\n // idx - index to be updated in the array\n // node - index to be updated in the seg tree\n if (queL == queR) {\n // Leaf node\n arr[idx] += val;\n st[node] += val;\n } else {\n int mid = (queL + queR) / 2;\n if (queL <= idx && idx <= mid) {\n // If idx is in the left child, recurse on the left child\n update1(2 * node, queL, mid, idx, val);\n } else {\n // if idx is in the right child, recurse on the right child\n update1(2 * node + 1, mid + 1, queR, idx, val);\n }\n // Internal node will have the min of both of its children\n st[node] = Math.min(st[2 * node], st[2 * node + 1]);\n }\n }\n\n }\n\n private static class FastReader {\n InputStream is;\n\n public FastReader(boolean onlineJudge) {\n is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n }\n\n byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n int readByte() {\n if (lenbuf == -1)\n throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(inbuf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0)\n return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n\n int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b))\n ;\n return b;\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n char nextChar() {\n return (char) skip();\n }\n\n String next() {\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 String nextLine() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n char[] next(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 int nextInt() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n long nextLong() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n char[][] nextMatrix(int n, int m) {\n char[][] map = new char[n][];\n for (int i = 0; i < n; i++)\n map[i] = next(m);\n return map;\n }\n\n int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n\n int[][] next2DInt(int n, int m) {\n int[][] arr = new int[n][];\n for (int i = 0; i < n; i++) {\n arr[i] = nextIntArray(m);\n }\n return arr;\n }\n\n long[][] next2DLong(int n, int m) {\n long[][] arr = new long[n][];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLongArray(m);\n }\n return arr;\n }\n\n int[] shuffle(int[] arr) {\n Random r = new Random();\n for (int i = 1, j; i < arr.length; i++) {\n j = r.nextInt(i);\n arr[i] = arr[i] ^ arr[j];\n arr[j] = arr[i] ^ arr[j];\n arr[i] = arr[i] ^ arr[j];\n }\n return arr;\n }\n\n int[] uniq(int[] arr) {\n Arrays.sort(arr);\n int[] rv = new int[arr.length];\n int pos = 0;\n rv[pos++] = arr[0];\n for (int i = 1; i < arr.length; i++) {\n if (arr[i] != arr[i - 1]) {\n rv[pos++] = arr[i];\n }\n }\n return Arrays.copyOf(rv, pos);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "55b1bc408cdeb0c69b8dfe8053b93095", "src_uid": "e7b9eec21d950f5d963ff50619c6f119", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class MagicGems {\n public static final long MOD = 1000000007L;\n public static final long MODS = MOD*MOD;\n public static void main(String[] args) {\n FastScanner scanner = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n long N = scanner.nextLong();\n int M = scanner.nextInt();\n long[][] matrix = new long[M][M];\n for(int i= 0; i < M-1; i++) {\n matrix[i+1][i] = 1;\n }\n //base cases\n matrix[0][0] = 1;\n matrix[0][M-1] = 1;\n long[] ans = new long[M];\n ans[0] = 1;\n out.println(mPow(matrix, ans, N)[0]);\n out.flush();\n }\n \n \n public static long[] mPow (long[][] M, long[] v, int pow) {\n for(int i= 0; i < v.length; i++) if(v[i] >= MOD) v[i]%=MOD;\n long[][] ret = M;\n //>>>= is an unsigned right shift by 1\n for(;pow> 0; pow >>>=1) {\n if ((pow&1)==1) v = mMul(ret, v);\n ret = mSquare(ret);\n }\n return v;\n }\n \n public static long[] mMul(long[][] M, long[] v) {\n int m = M.length;\n int n= v.length;\n long[] ret = new long[m];\n for(int i= 0; i < m; i++) {\n long sum = 0;\n for(int k = 0; k < n; k++) {\n sum += M[i][k] * v[k];\n if (sum >= MODS) sum-= MODS;\n }\n ret[i] = sum;\n }\n return ret;\n }\n \n //need to be a square matrix\n //should have efficiency based on lacking mod ops.\n public static long[][] mSquare(long[][] M) {\n int N = M.length;\n long[][] ret = new long[N][N];\n for(int i = 0; i < N; i++) {\n long[] temp = new long[N];\n for(int k = 0; k < N; k++) {\n for(int j = 0; j < N; j++) {\n temp[j] += M[i][k] * M[k][j];\n if (temp[j] >= MODS) temp[j]-=MODS;\n }\n }\n for(int k = 0; k < N; k++) {\n ret[i][k] = (temp[k] %MOD);\n }\n }\n return ret;\n }\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}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc655b210cf9353bd30b98c025ad0f9d", "src_uid": "e7b9eec21d950f5d963ff50619c6f119", "difficulty": 2100} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class _402_A {\n\tboolean testOutput=true;\n\tpublic void runTestCases() throws Exception{\n//\t\tCase 0\n\t\tinput=\n\t\t\"3 10 3 3 \";\n\t\trunTest(input,\n\t\t\"2 \");\n\n//\t\tCase 1\n\t\tinput=\n\t\t\"3 10 1 3 \";\n\t\trunTest(input,\n\t\t\"3 \");\n\n//\t\tCase 2\n\t\tinput=\n\t\t\"100 100 1 1000 \";\n\t\trunTest(input,\n\t\t\"1 \");\n\t\t\n//\t\tCase 1\n\t\tinput=\n\t\t\"3 20 1 3 \";\n\t\trunTest(input,\n\t\t\"3 \");\n\n\n\t}\n\t\n\tpublic void compare(String rcAnswer, String realAnswer){\n\t\trealAnswer=realAnswer.trim();\n\t\trcAnswer=rcAnswer.trim();\n\t\tif(realAnswer.equals(rcAnswer)){\n\t\t\tSystem.out.println(\"[Passed] Case \"+nroCases);\n\t\t}else{\n\t\t\tfailed=true;\n\t\t\tSystem.out.println(\"rChi \"+rcAnswer);\n\t\t\tSystem.out.println(\"Expected \"+realAnswer);\n\t\t\tSystem.out.println(\"[Failed] Case \"+nroCases);\n//\t\t\tSystem.exit(0);\n\t\t}\n\t\tnroCases++;\n\t}\n\t\n\tpublic void runTest(String input, String output) throws Exception{\n\t\tr.in= new ByteArrayInputStream(input.getBytes());\n\t\tr.run();\n\t\tif(testOutput){\n\t\t\tcompare(baos.toString(), output);\n\t\t}else{\n\t\t\tSystem.out.println(baos.toString());\n\t\t}\n\t\tbaos.reset();\n//\t\tr.in.\n\t}\n\t_402_A_Nuts r;\n\tByteArrayOutputStream baos = new ByteArrayOutputStream();\n\tprivate void init() throws Exception{\n\t\tr = new _402_A_Nuts();\n\t\tr.out = new PrintWriter(baos);\n\t\trunTestCases();\n\t\tif(testOutput && !failed){\n\t\t\tSystem.out.println(\"All test cases [Passed]\");\n\t\t}\n\t}\n\tprivate String input;\n\tprivate int nroCases=1;\n\tprivate boolean failed=false;\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew _402_A().init();\n\t}\n\t\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ef6698745206aba961e881976f906846", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100} {"lang": "Java 7", "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 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 int i;\n for (i = 0; a > 0; i++) {\n if(b > 0){\n for (int j = 0; j < k ; j++) {\n if (b > 0) {\n a = a - v;\n }\n }\n b--;\n // if( b == 0) break;\n } else {\n a = a - v;\n }\n \n }\n \n System.out.println(i);\n \n \n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9ff08f77ca03f189c586657e6fdf7891", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Nuts {\n\n\tprivate static int k;\n\tprivate static int a;\n\tprivate static int b;\n\tprivate static int v;\n\tprivate static int boxesNumber;\n\n\tpublic static void main(String[] args) {\n\n\t\tboxesNumber = 0;\n\n\t\tScanner scanner = new Scanner(System.in);\n\t\tString input = scanner.nextLine();\n\t\tString[] parts = input.split(\" \");\n\n\t\t// \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0442\u0441\u0435\u043a\u043e\u0432 \u0432 \u043a\u043e\u0440\u043e\u0431\u043a\u0435\n\t\tk = Integer.parseInt(parts[0]);\n\t\t// \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0440\u0435\u0445\u043e\u0432\n\t\ta = Integer.parseInt(parts[1]);\n\t\t// \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439\n\t\tb = Integer.parseInt(parts[2]);\n\t\t// \u0432\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0441\u0435\u043a\u0430\n\t\tv = Integer.parseInt(parts[3]);\n\n\t\t/*---------------------------------*/\n\n\t\twhile (a > 0) {\n\t\t\t// \u0431\u0435\u0440\u0435\u043c \u0435\u0449\u0435 \u043a\u043e\u0440\u043e\u0431\u043a\u0443\n\t\t\tboxesNumber++;\n\t\t\tif (b > 0) {\n\t\t\t\ta -= v*(Math.min(b, k-1) + 1);\n\t\t\t\tb -= Math.min(b, k-1);\n\t\t\t} else {\n\t\t\t\ta -= v;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(boxesNumber);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "74244f89ff7f346bcbc5ef149bcb5d84", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class problemA {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int k, a, b, v, n;\n k = sc.nextInt(); // max \u043a\u043e\u043b-\u0432\u043e \u043e\u0442\u0441\u0435\u043a\u043e\u0432 \u0432 1 \u043a\u043e\u0440\u043e\u0431\u043a\u0435\n a = sc.nextInt(); // \u043a\u043e\u043b-\u0432\u043e \u043e\u0440\u0435\u0445\u043e\u0432\n b = sc.nextInt(); // \u043a\u043e\u043b-\u0432\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439\n v = sc.nextInt(); // max \u043a\u043e\u043b-\u0432\u043e \u043e\u0440\u0435\u0445\u043e\u0432 \u0432 \u043e\u0442\u0441\u0435\u043a\u0435\n\n int nDiv = ((Double)Math.ceil((double)a / v)).intValue();\n int c = b + 1;\n\n\n\n if (nDiv <= c) {\n n = ((Double)Math.ceil((double)nDiv / k)).intValue();\n } else {\n n = ((Double)Math.ceil((double)c / k)).intValue() + (nDiv - c);\n }\n\n System.out.println(n);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "71cfa5d0acb21b8038b57f75159a04dd", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n private static Scanner sc = new Scanner(new InputStreamReader(System.in));\n public static void main (String[] args) {\n String[] nums = sc.nextLine().split(\" \");\n String ops = sc.nextLine();\n long[] ns = new long[4];\n for (int i = 0; i < 4; i++) ns[i] = Integer.parseInt(nums[i]);\n\n System.out.println(solve(ns, ops));\n }\n static long solve(long[] ns, String ops) {\n Arrays.sort(ns);\n if (ops.equals(\"+ + +\")) return ns[0] + ns[1] + ns[2] + ns[3];\n if (ns[0] == 0) return 0;\n if (ops.equals(\"* * *\")) return ns[0] * ns[1] * ns[2] * ns[3];\n long e = ns[0] * ns[1];\n if (ops.equals(\"+ * *\") || ops.equals(\"* + *\") || ops.equals(\"* * +\")) {\n if (e <= ns[3]) return e * ns[2] + ns[3];\n else return e + ns[2] * ns[3];\n }\n return e + ns[2] + ns[3];\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3470d37c6039afddbc4eef8fd79dc7f8", "src_uid": "7a66fae63d9b27e444d84447012e484c", "difficulty": 1600} {"lang": "Java 6", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemB_51 {\n\t\n\tfinal boolean ONLINE_JUDGE=System.getProperty(\"ONLINE_JUDGE\")!=null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok=new StringTokenizer(\"\");\n\t\n\tvoid init() throws FileNotFoundException{\n\t\tif (ONLINE_JUDGE){\n\t\t\tin=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout =new PrintWriter(System.out);\n\t\t}\n\t\telse{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttok=new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\t\n\tint readInt() throws IOException{\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tpublic static void main(String[] args){\n\t\tnew ProblemB_51().run();\n\t}\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\tlong t1=System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2=System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \"+(t2-t1));\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\tvoid solve() throws IOException{\n\t\tlong[] a=new long[6];\n\t\tfor (int i=0; i<4; i++){\n\t\t\ta[i]=readInt();\n\t\t}\n\t\ta[5]=0;\n\t\tString[] c=new String[3];\n\t\tfor (int i=0; i<3; i++){\n\t\t\tc[i]=readString();\n\t\t}\n\t\tHashSet b=new HashSet();\n\t\tlong min=Long.MAX_VALUE;\n\t\tfor (int i1=0; i1<4; i1++){\n\t\t\tb.clear();\n\t\t\ta[5]=0;\n\t\t\ta[4]=a[i1];\n\t\t\tb.add(i1);\n\t\t\tfor (int i2=0; i2<4; i2++){\n\t\t\t\tif (!b.contains(i2)){\n\t\t\t\t\tb.add(i2);\n\t\t\t\t\tif (c[0].charAt(0)=='+'){\n\t\t\t\t\t\ta[4]+=a[i2];\n\t\t\t\t\t}else{\n\t\t\t\t\t\ta[4]*=a[i2];\n\t\t\t\t\t}\n\t\t\t\t\tfor (int i3=0; i3<5; i3++){\n\t\t\t\t\t\tif (!b.contains(i3)){\n\t\t\t\t\t\t\tb.add(i3);\n\t\t\t\t\t\t\ta[5]=a[i3];\n\t\t\t\t\t\t\tfor (int i4=0; i4<5; i4++){\n\t\t\t\t\t\t\t\tif (!b.contains(i4)){\n\t\t\t\t\t\t\t\t\tb.add(i4);\n\t\t\t\t\t\t\t\t\tif (c[1].charAt(0)=='+'){\n\t\t\t\t\t\t\t\t\t\ta[5]+=a[i4];\n\t\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\t\ta[5]*=a[i4];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tfor (int i=0; i<5; i++){\n\t\t\t\t\t\t\t\t\t\tif(!b.contains(i)){\n\t\t\t\t\t\t\t\t\t\t\t\tif (c[2].charAt(0)=='+'){\n\t\t\t\t\t\t\t\t\t\t\t\t\ta[5]+=a[i];\n\t\t\t\t\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\t\t\t\t\ta[5]*=a[i];\n\t\t\t\t\t\t\t\t\t\t\t\t}\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tif (a[5]f = new ArrayList();\n f.add(A);\n f.add(B);\n f.add(C);\n f.add(D);\n \n if (multy<=1){\n for (int i = 0; i<3; i++){\n if (act[i]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}\n if (act[i]==2){Collections.sort(f); f.set(0, f.get(0) * f.remove(1) );} \n } \n }\n if (act[0]==2 && act[1]==2){ \n \n if (act[0]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}\n if (act[0]==2){\n Collections.sort(f);\n f.set(0, f.get(0) * f.remove(f.size()-1));\n //System.out.println(f.get(0));\n }\n \n if (act[1]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}\n if (act[1]==2){\n Collections.sort(f);\n f.set(0, f.remove(0) * f.get(0));\n }\n \n if (act[2]==1){f.set(0, f.get(0) + f.remove(1) );}\n if (act[2]==2){\n Collections.sort(f);\n f.set(0, f.get(0) * f.remove(1));\n } \n }\n \n if (act[0]==2 && act[2]==2){ \n \n Collections.sort(f);\n f.set(1, f.get(1) * f.remove(2));\n \n if (act[1]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}\n if (act[1]==2){\n Collections.sort(f);\n f.set(0, f.remove(0) * f.get(0));\n }\n Collections.sort(f);\n f.set(0, f.get(0) * f.remove(1));\n }\n return f.get(0);\n }\n public static ArrayList mySort(ArrayListA){\n ArrayList G = new ArrayList();\n Collections.sort(A);\n while (A.size()!=0){\n G.add( A.remove(A.size()-1) );\n }\n// for (int i = 0; i numbers = new TreeSet();\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "132efca703ef8a8253c41aa1dce5c8d5", "src_uid": "7a66fae63d9b27e444d84447012e484c", "difficulty": 1600} {"lang": "Java 7", "source_code": " import java.util.*; \n import java.math.*;\n import java.io.*;\n import java.text.DecimalFormat;\n import java.math.BigInteger;\n public class Main{\n static int d=20,n;\n static int mod=1000000007 ;\n static HashMap hm=new HashMap<>(); \n public static void main(String[] args) throws IOException {\n s.init(System.in); \n \n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n,x;\n n=s.ni();\n x=s.ni();\n int ans=0;\n double sub=1e-19;\n double[] glass=new double[(n*(n+1))/2];\n int id=0;\n \n glass[id]=x;\n for(int row=1;row<=n && x!=0.0;row++){\n for(int col=1;col<=row;col++,id++){\n x=glass[id];\n glass[id]=(x>=1.0)?1.0:x;\n x=(x>=(1.0-sub))?((x-1.0)):0.0;\n if(row==n)\n continue;\n glass[id+row]+=x/2;\n glass[id+row+1]+=x/2;\n }\n }\n for(int i=0;i<(n*(n+1))/2;i++){\n if(glass[i]>=(1.0-sub))\n ans++;\n }\n out.println(ans);\n\n out.close();\n }\n\n static class party implements Comparable{\n int size;\n int id;\n public party(int x,int y){\n id=x;\n size=y;\n }\n public int compareTo(party o){\n return o.size-size;\n }\n }\n \n public static class s {\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 ns() 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 ni() throws IOException {\n return Integer.parseInt( ns() );\n }\n \n static double nd() throws IOException {\n return Double.parseDouble( ns() );\n }\n static long nl() throws IOException {\n return Long.parseLong( ns() );\n }\n \n }\n } ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1a6ea060545e5e14b148fcc42c0f4141", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\n\npublic class PyramidOfGlasses {\n \n class Node {\n\tint liquid;\n\tint level;\n\tNode Left, Right;\n\tboolean counted = false;\n\tboolean isInner;\n\t\n\tNode(int level, boolean inner){\n\t\tthis.liquid = 0;\n\t\tthis.level = level;\n\t\tthis.Left = null;\n\t\tthis.Right = null;\n\t\tthis.isInner = inner;\n\t}\n\t\n\tboolean isFull(){\n\t\tif(level==1) return (liquid==1);\n\t\treturn ((int)Math.pow(2,(level-1)))==liquid;\n\t}\n\t\n\tvoid pour(){\n\t\tif(!this.isFull()) liquid++;\n\t\telse {\n\t\t\tif(this.Left != null) this.Left.pour();\n\t\t\tif(this.Right != null) this.Right.pour();\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tpublic String toString(){\n\t\treturn \"{ \" + liquid + \" , \" + level + \" , \" + this.Left + \" , \" + this.Right + \" } \";\n\t}\n\t\n\tint fullCups(){\n\t\tint ret = 0;\n\t\tif(this.counted) return ret;\n\t\tthis.counted = true;\n\t\t\n\t\tif(this.Left != null) ret += this.Left.fullCups();\n\t\tif(this.Right != null) ret += this.Right.fullCups();\n\t\tif(this.isFull()){ ret++; }\n\t\treturn ret;\n\t}\n}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint t = Integer.parseInt(st.nextToken());\n\t\t\n\t\tNode[][] pyramid = new Node[n+1][];\n\t\tfor(int i=(n-1); i>=0; i--) {\n\t\t\tNode[] lvl = new Node[i+1];\n\t\t\tpyramid[i] = lvl;\n\t\t\t\n\t\t\tfor(int j=0; j= 1)\n\t\t{\n\t\t\tdouble overflow = glasses[row][col] - 1;\n\t\t\tglasses[row][col] = 1;\n\t\t\treturn 1 + pour(overflow/2,glasses,row+1,col) + pour(overflow/2,glasses,row+1,col+1);\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic static void solve()\n\t{\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint t = input.nextInt();\n\n\t\tif(t >= Math.pow(2,n) - 1)\n\t\t{\n\t\t\tSystem.out.println((n*n + n)/2);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(t <= 1)\n\t\t{\n\t\t\tSystem.out.println(t);\n\t\t\treturn;\n\t\t}\n\n\t\tint retval = 0;\n\t\tdouble[][] glasses = new double[n][];\n\t\tfor(int i = 0; i < n; i++) glasses[i] = new double[i+1];\n\t\tfor(int time = t; time > 0; time--)\n\t\t{\n\t\t\tretval += pour(1.0,glasses,0,0);\n\t\t}\n\t\tSystem.out.println(retval);\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tsolve();\n\t}\n\t\n}\n\t\t\n\t\t\t\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b625cf751ccc7aa502af986ffcc07027", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500} {"lang": "Java 8", "source_code": "3 5\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static double[] a;\n public static int[] level;\n public static int n;\n public static int max = 55;\n \n \n\n public static void fill(int i, double cur)\n {\n if(level[i]>n)\n return;\n //System.out.println(i+\" \"+(cur-(100-a[i])));\n \n \n if((cur- (100-a[i]))<=0.1)\n {\n a[i] += cur;\n cur = 0;\n return;\n }\n else\n {\n cur -= (100-a[i]);\n a[i] = 100;\n int c1 = i + level[i];\n int c2 = c1+1;\n if(c1<=55)\n fill(c1, cur/2);\n if(c2<=55)\n fill(c2, cur/2);\n }\n \n }\n \n \n public static void main(String[] args) {\n \n \n Scanner in = new Scanner(System.in);\n //BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n\t \n \n \n n = in.nextInt();\n int t = in.nextInt();\n \n \n \n a = new double[100];\n level = new int[100];\n int tmp = 0;\n //int prev = 0;\n for(int i=1; i<=10; i++)\n {\n for(int j=0; j map;\r\n\t //static StringBuffer sb=new StringBuffer(\"\");\r\n\t static HashMap map;\r\n\t static PrintWriter out=new PrintWriter(System.out);\r\n\t public static void main(String[] args)\r\n{\r\n\t\t \r\n\t\t // StringBuffer sb=new StringBuffer(\"\");\r\n\t\t int ttt=1;\r\n\t\t // ttt =i();\r\n\t outer :while (ttt-- > 0) \r\n\t\t\t{\r\n\t \tchar A[]=s().toCharArray();\r\n\t \tif(A.length==1 && A[0]=='0') {\r\n\t \t\tSystem.out.println(\"1\");\r\n\t \t\treturn;\r\n\t \t}\r\n\t \tif(A[0]=='0') {\r\n\t \t\tSystem.out.println(\"0\");\r\n\t \t\treturn;\r\n\t \t}\r\n\t \tif(A.length==1) {\r\n\t \t\tif(A[0]=='X' || A[0]=='_') {\r\n\t \t\t\tSystem.out.println(\"1\");\r\n\t \t\t\treturn;\r\n\t \t\t}\r\n\t \t}\r\n\t \tdp=new long[A.length+1][25][11];\r\n\t \tfill(dp);\r\n\t \tSystem.out.println(go(A, 0, 0, 10));\r\n\t \t\r\n\t \t\r\n\t }\r\n\t //System.out.println(sb.toString());\r\n\t\t out.close();\r\n\t \r\n\t \r\n\t //CHECK FOR N=1 //CHECK FOR M=0\r\n //CHECK FOR N=1 //CHECK FOR M=0\r\n \t//CHECK FOR N=1\r\n \t\r\n\t\t \r\n\t\t \r\n } \r\n\t static long go(char A[],int i,int pv,int v) {\r\n\t\t if(i==A.length) {\r\n\t\t\t if(pv==0)\r\n\t\t\t\t return 1;\r\n\t\t\t return 0;\r\n\t\t }\r\n\t\t if(dp[i][pv][v]!=-1)\r\n\t\t\t return dp[i][pv][v];\r\n\t\t long ans=0;\r\n\t\t if(A[i]=='_') {\r\n\t\t\t for(int j=0;j<10;j++) {\r\n\t\t\t\t if(i==0 && j==0)\r\n\t\t\t\t\t continue;\r\n\t\t\t\t int y=pv*10+j;\r\n\t\t\t\t y%=25;\r\n\t\t\t\t ans+=go(A, i+1, y, v);\r\n\t\t\t }\r\n\t\t }\r\n\t\t else if(A[i]=='X') {\r\n\t\t\t if(v!=10) {\r\n\t\t\t\t ans+=go(A, i+1, (pv*10+v)%25, v);\r\n\t\t\t }\r\n\t\t\t else {\r\n\t\t\t\t for(int j=0;j<10;j++) {\r\n\t\t\t\t\t if(i==0 && j==0)\r\n\t\t\t\t\t\t continue;\r\n\t\t\t\t\t int y=pv*10+j;\r\n\t\t\t\t\t y%=25;\r\n\t\t\t\t\t ans+=go(A, i+1, y, j);\r\n\t\t\t\t }\r\n\t\t\t }\r\n\t\t }\r\n\t\t else {\r\n\t\t\t ans+=go(A, i+1, (pv*10+A[i]-'0')%25, v);\r\n\t\t }\r\n\t\t return dp[i][pv][v]=ans;\r\n\t }\r\n\t\r\n\t \r\n\t\r\n\t\r\n\t\r\nstatic class Pair implements Comparable\r\n {\r\n \t int x;\r\n \t int y;\r\n \t int z;\r\n \t Pair(int x,int y){\r\n \t\t this.x=x;\r\n \t\t this.y=y;\r\n \t\t// this.z=z;\r\n \t\t \r\n \t }\r\n\t\t@Override\r\n\t\tpublic int compareTo(Pair o) {\r\n\t\t\tif(this.x>o.x)\r\n\t\t\t\treturn +1;\r\n\t\t\telse if(this.xo.y)\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\telse if(this.y o.x) {\r\n// \t\t\t\treturn 1;\r\n// \t\t\t}\r\n// \t\t\tif (x < o.x) {\r\n// \t\t\t\treturn -1;\r\n// \t\t\t}\r\n// \t\t\tif (y > o.y) {\r\n// \t\t\t\treturn 1;\r\n// \t\t\t}\r\n// \t\t\tif (y < o.y) {\r\n// \t\t\t\treturn -1;\r\n// \t\t\t}\r\n// \t\t\treturn 0;\r\n// \t\t}\r\n\t\t\r\n }\r\n\r\n//static int find(int A[],int a) {\r\n//\t if(A[a]<0)\r\n//\t\t return a;\r\n//\t return A[a]=find(A, A[a]);\r\n//}\r\nstatic int find(int A[],int a) {\r\n\t if(A[a]==a)\r\n\t\t return a;\r\n\t return A[a]=find(A, A[a]);\r\n}\r\n//FENWICK TREE\r\nstatic void update(int i, int x){\r\n\tfor(; i < bit.length; i += (i&-i))\r\n\t\tbit[i] += x;\r\n}\r\n\r\nstatic int sum(int i){\r\n\tint ans = 0;\r\n\tfor(; i > 0; i -= (i&-i))\r\n\t\tans += bit[i];\r\n\treturn ans;\r\n}\r\nstatic void update1(int i, long x){\r\n\tfor(; i < bit1.length; i += (i&-i))\r\n\t\tbit1[i] += x;\r\n}\r\n\r\nstatic int sum1(int i){\r\n\tint ans = 0;\r\n\tfor(; i > 0; i -= (i&-i))\r\n\t\tans += bit1[i];\r\n\treturn ans;\r\n}\r\n//END\r\nstatic void add(int v) {\r\n\tif(!map.containsKey(v)) {\r\n\t\tmap.put(v, 1);\r\n\t}\r\n\telse {\r\n\t\tmap.put(v, map.get(v)+1);\r\n\t}\r\n}\r\nstatic void remove(int v) {\r\n\tif(map.containsKey(v)) {\r\n\t\tmap.put(v, map.get(v)-1);\r\n\t\tif(map.get(v)==0)\r\n\t\t\tmap.remove(v);\r\n\t}\r\n}\r\npublic static int upper(int A[],int k,int si,int ei)\r\n{\r\n\tint l=si;\r\n\tint u=ei;\r\n\tint ans=-1;\r\n\twhile(l<=u) {\r\n\t\tint mid=(l+u)/2;\r\n\t\tif(A[mid]<=k) {\r\n\t\t\tans=mid;\r\n\t\t\tl=mid+1;\r\n\t\t}\r\n\t\telse {\r\n\t\t\tu=mid-1;\r\n\t\t}\r\n\t}\r\n\treturn ans;\r\n}\r\npublic static int lower(int A[],int k,int si,int ei)\r\n{\r\n\tint l=si;\r\n\tint u=ei;\r\n\tint ans=-1;\r\n\twhile(l<=u) {\r\n\t\tint mid=(l+u)/2;\r\n\t\tif(A[mid]<=k) {\r\n\t\t\tl=mid+1;\r\n\t\t}\r\n\t\telse {\r\n\t\t\tans=mid;\r\n\t\t\tu=mid-1;\r\n\t\t}\r\n\t}\r\n\treturn ans;\r\n\t\r\n \r\n}\r\nstatic int[] copy(int A[]) {\r\n\tint B[]=new int[A.length];\r\n\tfor(int i=0;i=0;i--)\r\n\t\tp[i]=p[i+1]+A[i];\r\n\treturn p;\r\n}\r\nstatic long [] suffix(int A[]) {\r\n\tlong p[]=new long[A.length];\r\n\tp[A.length-1]=A[A.length-1];\r\n\tfor(int i=A.length-2;i>=0;i--)\r\n\t\tp[i]=p[i+1]+A[i];\r\n\treturn p;\r\n}\r\nstatic void fill(int dp[]) {\r\n\tArrays.fill(dp, -1);\r\n}\r\nstatic void fill(int dp[][]) {\r\n\tfor(int i=0;i 0) {\r\n\r\n if (y % 2 == 1)\r\n res = (res * x) % p;\r\n\r\n y = y >> 1; \r\n x = (x * x) % p;\r\n }\r\n\r\n return res;\r\n}\r\nstatic long power(long x, long y)\r\n{\r\n\r\n\tif(y==0)\r\n\t\treturn 1;\r\n\tif(x==0)\r\n\t\treturn 0;\r\n long res = 1;\r\n\r\n while (y > 0) {\r\n\r\n if (y % 2 == 1)\r\n res = (res * x);\r\n\r\n y = y >> 1; \r\n x = (x * x);\r\n }\r\n\r\n return res;\r\n}\r\nstatic void print(int A[]) {\r\n\tfor(int i : A) {\r\n\t\tSystem.out.print(i+\" \");\r\n\t}\r\n\tSystem.out.println();\r\n}\r\nstatic void print(long A[]) {\r\n\tfor(long i : A) {\r\n\t\tSystem.out.print(i+\" \");\r\n\t}\r\n\tSystem.out.println();\r\n}\r\nstatic long mod(long x) {\r\n\t return ((x%mod + mod)%mod);\r\n}\r\nstatic String reverse(String s) {\r\n\tStringBuffer p=new StringBuffer(s);\r\n\tp.reverse();\r\n\treturn p.toString();\r\n}\r\n\r\n static int i() {\r\n \t return sc.nextInt();\r\n }\r\n static String s() {\r\n \t return sc.next();\r\n }\r\n static long l() {\r\n \t return sc.nextLong();\r\n } \r\n static void sort(int[] A){\r\n int n = A.length;\r\n Random rnd = new Random();\r\n for(int i=0; i hash(int A[]){\r\n\t HashMap map=new HashMap();\r\n\t for(int i : A) {\r\n\t\t if(map.containsKey(i)) {\r\n\t\t\t map.put(i, map.get(i)+1);\r\n\t\t }\r\n\t\t else {\r\n\t\t\t map.put(i, 1);\r\n\t\t }\r\n\t }\r\n\t return map;\r\n }\r\n static TreeMap tree(int A[]){\r\n\t TreeMap map=new TreeMap();\r\n\t for(int i : A) {\r\n\t\t if(map.containsKey(i)) {\r\n\t\t\t map.put(i, map.get(i)+1);\r\n\t\t }\r\n\t\t else {\r\n\t\t\t map.put(i, 1);\r\n\t\t }\r\n\t }\r\n\t return map;\r\n }\r\n static boolean prime(int n) \r\n\t { \r\n\t if (n <= 1) \r\n\t return false; \r\n\t if (n <= 3) \r\n\t return true; \r\n\t if (n % 2 == 0 || n % 3 == 0) \r\n\t return false; \r\n\t double sq=Math.sqrt(n);\r\n\t \r\n\t for (int i = 5; i <= sq; i = i + 6) \r\n\t if (n % i == 0 || n % (i + 2) == 0) \r\n\t return false; \r\n\t return true; \r\n\t } \r\n static boolean prime(long n) \r\n\t { \r\n\t if (n <= 1) \r\n\t return false; \r\n\t if (n <= 3) \r\n\t return true; \r\n\t if (n % 2 == 0 || n % 3 == 0) \r\n\t return false; \r\n\t double sq=Math.sqrt(n);\r\n\t \r\n\t for (int i = 5; i <= sq; i = i + 6) \r\n\t if (n % i == 0 || n % (i + 2) == 0) \r\n\t return false; \r\n\t return true; \r\n\t } \r\n static int gcd(int a, int b) \r\n { \r\n if (a == 0) \r\n return b; \r\n return gcd(b % a, a); \r\n } \r\n static long gcd(long a, long b) \r\n { \r\n if (a == 0) \r\n return b; \r\n return gcd(b % a, a); \r\n } \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} \r\n\r\n\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5391f621b81e2a64f093de02a2f5e3ee", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800} {"lang": "Java 11", "source_code": "https://codeforces.com/problemset/submit/*\r\n25\r\nAny numbers that end in 00, 25, 50, or 75 will work - after can end in any groups of digits (can do casework on all possible endings) - just test if a certain starting group is possible - may also influence rest of string if one of the digits is an X\r\n*/\r\nimport java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main{\r\n public static char[] str; \r\n public static String[] ends = {\"00\", \"25\", \"50\", \"75\"};\r\n public static long ret; \r\n public static void main(String[] args) throws IOException{\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n str = br.readLine().toCharArray(); \r\n ret = 0; \r\n if(str.length >= 2) for(int a = 0; a < 4; a++) match(str[str.length - 2], str[str.length - 1], ends[a]);\r\n else{\r\n if(str[0] == '0' || str[0] == 'X' || str[0] == '_') ret++; //only 0 possible, 0 divisible by 25\r\n }\r\n\r\n System.out.println(ret); \r\n \r\n br.close();\r\n }\r\n public static void match(char f, char s, String b){\r\n //assume a is from the original string, b is the checking string \r\n char f2 = f; \r\n char s2 = s; \r\n if(f == '_' && b.charAt(0) == '0' && str.length - 2 == 0) return; \r\n if(f2 == 'X'){\r\n //try to change f to the start of b\r\n f2 = b.charAt(0);\r\n if(s2 == 'X') s2 = b.charAt(0);\r\n }\r\n if(s2 == 'X'){\r\n //try to change s to the end of b \r\n s2 = b.charAt(1);\r\n if(f2 == 'X') f2 = b.charAt(1);\r\n }\r\n if(f2 == '_'){\r\n //try to change f to the start of b\r\n f2 = b.charAt(0);\r\n }\r\n if(s2 == '_'){\r\n //try to change s to the end of b\r\n s2 = b.charAt(1);\r\n }\r\n char cv = 'n'; //if f was X or s was X then xVal changes\r\n if(f == 'X') cv = f2; \r\n if(s == 'X') cv = s2;\r\n //System.out.println(f2 + \" \" + s2 + \" \" + b);\r\n if(f2 == b.charAt(0) && s2 == b.charAt(1)) poss(cv); \r\n }\r\n public static void poss(char xVal){\r\n //xVal = -1 if xs not filled yet\r\n //System.out.println(\"test \" + xVal);\r\n if((xVal == '0' && str[0] == 'X') || str[0] == '0') return; //cannot start with a 0 \r\n long add = 1; \r\n boolean xF = false; //whether or not we set X\r\n if(xVal != 'n') xF = true; \r\n for(int a = 0; a < str.length - 2; a++){\r\n if(str[a] == '_'){\r\n if(a == 0) add *= 9; //1 2 3 4 5 6 7 8 9\r\n else add *= 10; \r\n }\r\n if(!xF && str[a] == 'X'){\r\n xF = true; \r\n if(a == 0) add *= 9; \r\n else add *= 10; \r\n }\r\n }\r\n //System.out.println(\"add \" + add);\r\n ret += add; \r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3b57d87021da53e85b857243cbc96085", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800} {"lang": "Java 11", "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> {\r\n\r\n @Override\r\n public int compare(Pair p1, Pair 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 {\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(int ele, int[] sortedArr) {\r\n int l = 0;\r\n int h = sortedArr.length - 1;\r\n int ans = -1;\r\n while (l <= h) {\r\n int mid = l + (int) (h - l) / 2;\r\n if (sortedArr[mid] < ele) {\r\n ans = mid;\r\n l = mid + 1;\r\n } else if (sortedArr[mid] >= ele) {\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 primeList(int MAXI) {\r\n int[] prime = new int[MAXI + 1];\r\n HashSet 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 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 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 ret_ans(ArrayList 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 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 getKeys(HashMap maps) {\r\n ArrayList vals = new ArrayList<>();\r\n for (Map.Entry map : maps.entrySet()) {\r\n vals.add(map.getKey());\r\n }\r\n return vals;\r\n }\r\n\r\n static ArrayList getValues(HashMap maps) {\r\n ArrayList vals = new ArrayList<>();\r\n for (Map.Entry map : maps.entrySet()) {\r\n vals.add(map.getValue());\r\n }\r\n return vals;\r\n }\r\n\r\n static int getMax(ArrayList 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 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 /*write your methods and classes here*/\r\n\r\n public static void main(String[] args) throws IOException {\r\n String s = br.readLine();\r\n int n = s.length();\r\n if (\r\n (s.charAt(0) == '0' || s.charAt(0) == '_' || s.charAt(0) == 'X') &&\r\n s.length() == 1\r\n ) {\r\n bw.write(\"1\\n\");\r\n bw.flush();\r\n } else if (s.length() == 1) {\r\n bw.write(\"0\\n\");\r\n bw.flush();\r\n } else if (s.charAt(0) == '0') {\r\n bw.write(\"0\\n\");\r\n bw.flush();\r\n } else {\r\n String digits[] = { \"25\", \"50\", \"75\", \"00\" };\r\n String arr1[] = { \"__\", \"_X\", \"X_\", \"XX\" };\r\n int way[] = { 4, 4, 4, 1 };\r\n way[1] = s.charAt(0) == 'X' ? 2 : 4;\r\n way[2] = s.charAt(0) == 'X' ? 3 : 4;\r\n way[0] = s.length() == 2 ? 3 : 4;\r\n way[1] = s.length() == 2 ? 3 : 4;\r\n int ways = 0;\r\n String v = s.substring(n - 2, n);\r\n for (i = 0; i < 4; i++) {\r\n if (v.equals(digits[i])) {\r\n ways = 1;\r\n }\r\n }\r\n if (v.charAt(0) == '_' || v.charAt(0) == 'X') {\r\n ways = 2;\r\n if (v.charAt(1) == '0' && s.charAt(0) == 'X') {\r\n ways = 1;\r\n }\r\n } else if (v.charAt(1) == '_' || v.charAt(1) == 'X') {\r\n ways = 1;\r\n }\r\n for (i = 0; i < 4; i++) {\r\n if (v.equals(arr1[i])) {\r\n //System.out.println(\"age\");\r\n ways = way[i];\r\n }\r\n }\r\n if (v == \"XX\" && s.charAt(0) == 'X') {\r\n ways = 0;\r\n }\r\n if (\r\n v.charAt(0) != '2' &&\r\n v.charAt(0) != '5' &&\r\n v.charAt(0) != '7' &&\r\n v.charAt(0) != '0' &&\r\n v.charAt(0) != 'X' &&\r\n v.charAt(0) != '_'\r\n ) {\r\n ways = 0;\r\n }\r\n if (\r\n v.charAt(1) != '0' &&\r\n v.charAt(1) != '5' &&\r\n v.charAt(1) != 'X' &&\r\n v.charAt(1) != '_'\r\n ) {\r\n ways = 0;\r\n }\r\n int xways = 1;\r\n if (v.charAt(0) == 'X') {\r\n xways = way[2];\r\n } else if (v.charAt(1) == 'X') {\r\n xways = way[1] / 2;\r\n } else {\r\n if (s.charAt(0) == 'X') {\r\n xways = 9;\r\n } else {\r\n xways = 10;\r\n }\r\n }\r\n\r\n boolean ok = false;\r\n long toti = 1l;\r\n for (i = 0; i < s.length() - 2; i++) {\r\n if (s.charAt(i) == 'X') {\r\n ok = true;\r\n }\r\n if (s.charAt(i) == '_') {\r\n if (i == 0) {\r\n toti *= 9l;\r\n } else {\r\n toti *= 10l;\r\n }\r\n }\r\n }\r\n if (ok) {\r\n toti *= 1l * xways;\r\n }\r\n toti *= 1l * ways;\r\n bw.write(Long.toString(toti) + \"\\n\");\r\n bw.flush();\r\n }\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8c72b9ca55f82c5be71f38b82007668c", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800} {"lang": "Java 11", "source_code": "/*\r\n25\r\nAny numbers that end in 00, 25, 50, or 75 will work - after can end in any groups of digits (can do casework on all possible endings) - just test if a certain starting group is possible - may also influence rest of string if one of the digits is an X\r\n*/\r\nimport java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main{\r\n public static char[] str; \r\n public static String[] ends = {\"00\", \"25\", \"50\", \"75\"};\r\n public static long ret; \r\n public static void main(String[] args) throws IOException{\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n str = br.readLine().toCharArray(); \r\n ret = 0; \r\n if(str.length >= 2) for(int a = 0; a < 4; a++) match(str[str.length - 2], str[str.length - 1], ends[a]);\r\n else{\r\n if(str[0] == '0') ret++; //only 0 possible, 0 divisible by 25\r\n }\r\n\r\n System.out.println(ret); \r\n \r\n br.close();\r\n }\r\n public static void match(char f, char s, String b){\r\n //assume a is from the original string, b is the checking string \r\n char f2 = f; \r\n char s2 = s; \r\n if(f2 == 'X'){\r\n //try to change f to the start of b\r\n f2 = b.charAt(0);\r\n if(s2 == 'X') s2 = b.charAt(0);\r\n }\r\n if(s2 == 'X'){\r\n //try to change s to the end of b \r\n s2 = b.charAt(1);\r\n if(f2 == 'X') f2 = b.charAt(1);\r\n }\r\n if(f2 == '_'){\r\n //try to change f to the start of b\r\n f2 = b.charAt(0);\r\n }\r\n if(s2 == '_'){\r\n //try to change s to the end of b\r\n s2 = b.charAt(1);\r\n }\r\n int cv = -1; //if f was X or s was X then xVal changes\r\n if(f == 'X') cv = f2; \r\n if(s == 'X') cv = s2;\r\n //System.out.println(f2 + \" \" + s2 + \" \" + b);\r\n if(f2 == b.charAt(0) && s2 == b.charAt(1)) poss(cv); \r\n }\r\n public static void poss(int xVal){\r\n //xVal = -1 if xs not filled yet\r\n //System.out.println(\"test \" + xVal);\r\n if((xVal == 0 && str[0] == 'X') || if(str[0] == '0')) return; //cannot start with a 0 \r\n long add = 1; \r\n boolean xF = false; //whether or not we set X\r\n if(xVal != -1) xF = true; \r\n for(int a = 0; a < str.length - 2; a++){\r\n if(str[a] == '_'){\r\n if(a == 0) add *= 9; //1 2 3 4 5 6 7 8 9\r\n else add *= 10; \r\n }\r\n if(!xF && str[a] == 'X'){\r\n xF = true; \r\n if(a == 0) add *= 9; \r\n else add *= 10; \r\n }\r\n }\r\n ret += add; \r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0d59e05d0d02d738bde96f3a9652132e", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800} {"lang": "Java 6", "source_code": "public class D {\n static long[][] dp;\n\n public static long solve(int nodes, int height) {\n if (nodes == 0) {\n if (height == 0)\n return 1;\n return 0;\n }\n if (dp[nodes][height] != -1)\n return dp[nodes][height];\n long res = 0;\n for (int i = 0; i <= nodes - 1; i++) {\n if (height > 1) {\n res += solve(i, height - 1) * solve(nodes - 1 - i, 0)\n + solve(i, 0) * solve(nodes - 1 - i, height - 1)\n - solve(i, height - 1)\n * solve(nodes - 1 - i, height - 1);\n } else {\n res += solve(i, 0) * solve(nodes - 1 - i, 0);\n }\n }\n return dp[nodes][height] = res;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int h = sc.nextInt();\n dp = new long[n + 1][h + 1];\n for (int i = 0; i <= n; i++)\n Arrays.fill(dp[i], -1);\n System.out.println(solve(n, h));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2490c2b45fad2e02b53274711ef094e5", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tvoid realSolve() {\n\t\tint n = in.nextInt();\n\t\tint h = in.nextInt();\n\t\tlong[][] dp = new long[n + 1][n + 1];\n\t\tdp[1][1] = 1;\n\t\tdp[0][0] = 1;\n\t\tfor (int cn = 2; cn <= n; cn++) {\n\t\t\tfor (int curH = 1; curH <= n; curH++) {\n\t\t\t\tfor (int id = 1; id <= cn; id++) {\n\t\t\t\t\tlong cur = 1;\n\t\t\t\t\tlong v1 = 0, v2 = 0;\n\t\t\t\t\tfor (int h1 = 0; h1 <= curH - 1; h1++) {\n\t\t\t\t\t\tv1 += dp[id - 1][h1];\n\t\t\t\t\t\tv2 += dp[cn - id][h1];\n\t\t\t\t\t}\n\t\t\t\t\tcur = v1 * dp[cn - id][curH - 1] + v2 * dp[id - 1][curH - 1] - dp[cn - id][curH - 1] * dp[id - 1][curH - 1];\n\t\t\t\t\tdp[cn][curH] += cur;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong res =0;\n\t\tfor (int h1 = h; h1 <= n; h1++)\n\t\t\tres += dp[n][h1];\n\t\tout.println(res);\n\t}\n\n\tprivate class InputReader {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic InputReader(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic InputReader(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\tString s;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean hasMoreElements() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\tString s;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.hasMoreElements();\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tInputReader in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tin = new InputReader(new File(\"object.in\"));\n\t\ttry {\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\n\t\trealSolve();\n\n\t\tout.close();\n\t}\n\n\tvoid solveIO() {\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\trealSolve();\n\n\t\tout.close();\n\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF().solveIO();\n\t}\n}import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tvoid realSolve() {\n\t\tint n = in.nextInt();\n\t\tint h = in.nextInt();\n\t\tlong[][] dp = new long[n + 1][n + 1];\n\t\tdp[1][1] = 1;\n\t\tdp[0][0] = 1;\n\t\tfor (int cn = 2; cn <= n; cn++) {\n\t\t\tfor (int curH = 1; curH <= n; curH++) {\n\t\t\t\tfor (int id = 1; id <= cn; id++) {\n\t\t\t\t\tlong cur = 1;\n\t\t\t\t\tlong v1 = 0, v2 = 0;\n\t\t\t\t\tfor (int h1 = 0; h1 <= curH - 1; h1++) {\n\t\t\t\t\t\tv1 += dp[id - 1][h1];\n\t\t\t\t\t\tv2 += dp[cn - id][h1];\n\t\t\t\t\t}\n\t\t\t\t\tcur = v1 * dp[cn - id][curH - 1] + v2 * dp[id - 1][curH - 1] - dp[cn - id][curH - 1] * dp[id - 1][curH - 1];\n\t\t\t\t\tdp[cn][curH] += cur;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong res =0;\n\t\tfor (int h1 = h; h1 <= n; h1++)\n\t\t\tres += dp[n][h1];\n\t\tout.println(res);\n\t}\n\n\tprivate class InputReader {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic InputReader(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic InputReader(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\tString s;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean hasMoreElements() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\tString s;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.hasMoreElements();\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tInputReader in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tin = new InputReader(new File(\"object.in\"));\n\t\ttry {\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\n\t\trealSolve();\n\n\t\tout.close();\n\t}\n\n\tvoid solveIO() {\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\trealSolve();\n\n\t\tout.close();\n\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF().solveIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1c6f0cce0a9fcf7afef74d4320694619", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main(){\n public static class main(String[] args){\n \n }\n}\n\t \t\t \t\t \t\t \t\t\t \t \t \t\t\t\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c852efe3600790a90b18f6dcfa071fc6", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Sol {\n \n static int n , h;\n static long [][][]res = new long[36][36][36];\n static long [][]ress = new long[36][36];\n \n static long solve(int s , int e){\n if(s == e)\n return 1;\n if(ress[s][e]!=-1)\n return ress[s][e];\n long r = 0;\n for(int i = s ; i<=e ; i++){\n if(i==s)\n r+= solve(1+1 , e);\n else if(i == e)\n r+= solve( s , i-1);\n else\n r+= solve(s , i-1)*solve(i+1,e);\n }\n return ress[s][e] = e;\n }\n \n static long solve(int s , int e , int l ){\n if(s == e){\n if(l+1 < h)\n return 0;\n else\n return 1;\n }\n if(res[s][e][l]!=-1)\n return res[s][e][l];\n \n long r = 0;\n for(int i = s ; i<= e ; i++){\n if(i== s)\n r += solve(i+1 , e , l+1);\n else if(i == e)\n r+= solve(s , i-1 , l+1);\n else{\n r += solve(s , i-1) * solve(i+1 , e , l+1);\n r+= solve(s , i-1 , l+1 ) * solve(i+1 , e);\n r-= solve(s , i-1 , l+1) * solve(i+1 , e , l+1);\n }\n }\n return res[s][e][l] = r; \n }\n \n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n h = in.nextInt();\n \n for(int i = 0 ; i< 36 ; i++){\n Arrays.fill(ress[i], -1);\n for(int j = 0 ; j< 36 ; j++){\n Arrays.fill(res[i][j], -1);\n }\n }\n \n System.out.println(solve(1 , n , 0));\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f6e1ac745a9a2854f60bbe53190b4e3a", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class CF_171F {\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 res = 11;\n\t\twhile(n > 0) {\n\t\t\tres += 2;\n\t\t\tint rev = Integer.parseInt(new StringBuffer(res + \"\").reverse().toString());\n\t\t\tif(res != rev && isPrime(res) && isPrime(rev)) {\n\t\t\t\tn--;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(res);\n\t}\n\t\n\tprivate static boolean isPrime(int n) {\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\t\n\t\treturn true;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "49beded00c9a27e69e01c2c08d06c93b", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class ucyhf {\n\t static Scanner in = new Scanner(System.in);\n\tpublic static void main(String args[]) {\n\t\tint a = 13;\n\t\tint count = 1;\n\t\tint stop = in.nextInt();\n\t\twhile (true) {\n\t\t\tif (isEmirp(a)) {\n\t\t\t\tif(count ==stop){\n\t\t\t\t\tSystem.out.println(a);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\ta+=2;\n\t\t\t\t//if (count % 10 == 0)\n\t\t\t\t\t//System.out.println();\n\t\t\t}\n\t}\n\n\tpublic static boolean isPrime(int p) {\n\t\tfor (int i = 2; i < p; i++) {\n\t\t\tif (p % i == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static boolean isEmirp(int x) {\n\t\treturn isPrime(x) && isPrime(reverse(x)) && !isPalindrome(x);\n\t\t\n\t}\n\tpublic static boolean isPalindrome(int x){\n\t\tint n = x;\n\t\tint rev = 0;\n\t\twhile(x>0){\n\t\t\tint dig = x%10;\n\t\t\trev = rev*10+dig;\n\t\t\tx = x/10;\n\t\t}\n\t\tif(n==rev)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\tpublic static int reverse(int r) {\n\t\tif (r < 10)\n\t\t\treturn r;\n\t\treturn flipper(r % 10, r / 10);\n\t}\n\n\tpublic static int flipper(int a, int b) {\n\t\tif (b < 1)\n\t\t\treturn a;\n\t\treturn flipper(a * 10 + b % 10, b / 10);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "966f8c9629bb840fd4204ef858e7e392", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport java.util.Vector;\n\n\npublic class Main {\n\n /**\n * @param args\n * @throws IOException \n */\n public static void main(String[] args) throws IOException {\n // TODO Auto-generated method stub\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n //Scanner in=new Scanner(System.in);\n PrintWriter out=new PrintWriter(System.out);\n Vector smpl=new Vector();\n BigInteger cur=new BigInteger(\"13\");\n int maxN=10000;\n for(int i=0; i=n) break;\n if(!smpl.contains(Long.parseLong(new StringBuffer(String.valueOf(smpl.elementAt(i))).reverse().toString()))){\n mas[z]=smpl.elementAt(i);\n z++;\n }\n }\n out.println(mas[n-1]);\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6e3066e1ea62a8928e526335f8804a1b", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n//4/1/12 7:54 PM\n//by Abrackadabra\n\npublic class F {\n public static void main(String[] args) throws IOException {\n if (args.length > 0 && args[0].equals(\"Abra\")) debugMode = true;\n new F().run();\n }\n\n int IOMode = 0; //0 - consoleIO, 1 - .in/out, 2 - input.txt/output.txt, 3 - test case generator\n String taskName = \"\";\n\n String alpha = \"\u0430\u0431\u0432\u0433\u0434\u0435\u0451\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f\";\n\n HashSet getPrimes(int max) {\n boolean[] a = new boolean[max];\n HashSet p = new HashSet();\n for (int i = 2; i < max; i++) {\n if (a[i]) continue;\n for (int j = 2 * i; j < max; j += i) {\n a[j] = true;\n }\n p.add(i);\n }\n return p;\n }\n\n HashSet primes = getPrimes(10000000);\n\n void solve() throws IOException {/*\n while (true) {\n String s = nextString();\n if (s == null) break;\n for (int j = 17; j <= 17; j++) {\n for (int i = 0; i < s.length(); i++) {\n out.print(d(s.charAt(i), j));\n }\n out.println();\n }\n }\n for (int i = '\u0430'; i - '\u0430' < 33; i++)\n out.print((char)i); */\n int n = nextInt();\n for (int i = 2; i < 1000000; i++) {\n if (primes.contains(i) && primes.contains(reverse(i)) && reverse(i) != i) {\n n--;\n if (n == 0) {\n out.println(i);\n break;\n }\n }\n }\n }\n\n int reverse(int x) {\n String s = Integer.toString(x);\n String t = \"\";\n for (int i = 0; i < s.length(); i++) {\n t = s.charAt(i) + t;\n }\n return Integer.parseInt(t);\n }\n\n char d(int x, int c) {\n String s = \"\" + (char) x;\n if (alpha.indexOf(s) < 0) {\n return (char) x;\n } else {\n return (char) alpha.charAt((alpha.indexOf(s) + c) % alpha.length());\n }\n }\n\n long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;\n long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;\n\n void run() throws IOException {\n init();\n if (debugMode) {\n con.println(\"Start\");\n con.println(\"Console:\");\n }\n solve();\n finishTime = System.nanoTime();\n finishMem = Runtime.getRuntime().totalMemory();\n out.flush();\n if (debugMode) {\n int maxSymbols = 1000;\n BufferedReader tbr = new BufferedReader(new FileReader(\"input.txt\"));\n char[] a = new char[maxSymbols];\n tbr.read(a);\n if (a[0] != 0) {\n con.println(\"File input\");\n con.println(a);\n if (a[maxSymbols - 1] != 0) con.println(\"...\");\n }\n tbr = new BufferedReader(new FileReader(\"output.txt\"));\n a = new char[maxSymbols];\n tbr.read(a);\n if (a[0] != 0) {\n con.println(\"File output\");\n con.println(a);\n if (a[maxSymbols - 1] != 0) con.println(\"...\");\n }\n con.println(\"Execution time: \" + (finishTime - startTime) / 1000000000.0 + \" sec\");\n con.println(\"Used memory: \" + (finishMem - startMem) + \" bytes\");\n con.println(\"Total memory: \" + Runtime.getRuntime().totalMemory() + \" bytes\");\n }\n }\n\n boolean tick(double x) {\n if (System.nanoTime() - tempTime > x * 1e9) {\n tempTime = System.nanoTime();\n con.println(\"Tick at \" + (tempTime - startTime) / 1000000000 + \" sec\");\n con.print(\" \");\n return true;\n }\n return false;\n }\n\n static boolean debugMode = false;\n PrintStream con = System.out;\n\n void init() throws IOException {\n if (debugMode && IOMode != 3) {\n br = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n } else\n switch (IOMode) {\n case 0:\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n break;\n case 1:\n br = new BufferedReader(new FileReader(taskName + \".in\"));\n out = new PrintWriter(new FileWriter(taskName + \".out\"));\n break;\n case 2:\n br = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n break;\n case 3:\n out = new PrintWriter(new FileWriter(\"input.txt\"));\n break;\n }\n }\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer in;\n\n boolean hasMoreTokens() throws IOException {\n while (in == null || !in.hasMoreTokens()) {\n String line = br.readLine();\n if (line == null) return false;\n in = new StringTokenizer(line);\n }\n return true;\n }\n\n String nextString() throws IOException {\n return hasMoreTokens() ? in.nextToken() : null;\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextString());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextString());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextString());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "24626d218d808c3c6d382308e64048be", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600} {"lang": "Java 8", "source_code": "public class MarsLandVaccine{\n public static void main(String[] args){\n long n = hp.nextLong();\n long x = hp.nextLong();\n long y = hp.nextLong();\n\n long k = hp.nextLong();\n\n long low = 0, high = 2 * n;\n\n while(low < high){\n long mid = (low + high) / 2;\n if(isValidTime(mid, n, k, x, y)){\n high = mid;\n }\n else{\n low = mid + 1;\n }\n\n }\n System.out.print(low);\n }\n\n public static boolean isValidTime(long days, long N, long k, long x, long y){\n\n long top = Math.max(0, (days - (x - 1)));\n long lft = Math.max(0, (days - (y - 1)));\n long rgt = Math.max(0, (y - (N - days)));\n long btm = Math.max(0, (x - (N - days)));\n\n long topLft = Math.max(0, (1 + d) - (x + y));\n long topRgt = Math.max(0, (1 + d) - (x + N - y + 1));\n long botLft = Math.max(0, (1 + d) - (y + N - x + 1));\n long botRgt = Math.max(0, (1 + d) - (N - x + 1 + N - y + 1));\n\n long answer = ((days * days) + ((days + 1) * (days + 1)));\n\n answer -= ((top * top) + (bot * bot) + (lft * left) + (rgt * rgt));\n\n answer += (topLft * (topLft + 1)) / 2;\n answer += (topRgt * (topRgt + 1)) / 2;\n answer += (botLft * (botLft + 1)) / 2;\n answer += (botRgt * (botRgt + 1)) / 2;\n\n return (answer >= k)\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72f67f7521b4e2d143af985e3353edfc", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800} {"lang": "Java 6", "source_code": " java.import java.io.*;\nimport java.util.*;\n\npublic class bender {\n static int import java.io.*;\nimport java.util.*;\n\npublic class bender {\n static int n, x, y, c, t;\n \n public static void main(String[] args) throws NumberFormatException, IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n //BufferedReader in = new BufferedReader(new FileReader(\"bender.in\"));\n \n StringTokenizer nxyc = new StringTokenizer(in.readLine());\n n = Integer.parseInt(nxyc.nextToken());\n y = Integer.parseInt(nxyc.nextToken());\n x = Integer.parseInt(nxyc.nextToken());\n //int temp = x; y = temp; x = y;\n c = Integer.parseInt(nxyc.nextToken());\n t = c;\n \n int a = 0;\n int b = c;\n \n while (a <= b) {\n int tc = (a+b)/2;\n int total = 1;\n total += 4*tc;\n total += 4*inc(tc-1);\n \n int[] p = new int[]{x+tc-n, y+tc-n, 1+tc-x, 1+tc-y}; // x+, y+, x-, y-\n int[] q = new int[]{1+t-x-y, 1+t+x-y-n, x+y+t-2*n, y+t-n-x}; // 00 10 11 01\n \n for (int i = 0; i < 4; i++) if (p[i] > 0) total -= p[i]; else p[i] = 0;\n for (int i = 0; i < 4; i++) total -= 2*inc(p[i]-1);\n for (int i = 0; i < 4; i++) if (q[i] > 0) total += inc(q[i]);\n \n if (total >= c) {\n t = Math.min(tc, t);\n b = tc-1;\n } else {\n a = tc+1;\n }\n }\n \n System.out.println(t);\n System.exit(0);\n }\n \n public static int inc(int k) { // 1+2+3+...+k\n return (k*k+k)/2;\n }\n \n public static int dec(int total, int tc) {\n return 0;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c0b6cba79490426126fe6d51f678d598", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.lang.Long;\n\npublic class Test {\n\tstatic long mod = 1000000007;\n\tstatic int[][][][] dp;\n\tstatic boolean[][][][] check;\n\tstatic int contains;\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner in = new Scanner();\n\t\tint n = in.nextInt();\n\t\tint x = in.nextInt() - 1;\n\t\tint y = in.nextInt() - 1;\n\t\tlong c = in.nextLong();\n\t\tint start = 0;\n\t\tint end = 2 * n;\n\t\tlong result = end;\n\t\twhile (start <= end) {\n\t\t\tint mid = (start + end) / 2;\n\t\t\tlong total = 0;\n\t\t\tfor (int i = Math.max(0, x - mid); i <= Math.min(n - 1, x + mid); i++) {\n\t\t\t\tint v = mid - Math.abs(i - x);\n\t\t\t\tlong min = Math.max(0, y - v);\n\t\t\t\tlong max = Math.min(n - 1, y + v);\n\t\t\t\ttotal += max - min + 1;\n\t\t\t\t\n\t\t\t}\n\t\t\tif(total < c){\n\t\t\t\tstart = mid + 1;\n\t\t\t}else if(total >= c){\n\t\t\t\tresult = Math.min(result, mid);\n\t\t\t\tend = mid - 1;\n\t\t\t}\n\t\t}\n\t\tout.println(result);\n\n\t\tout.close();\n\t}\n\n\tpublic static int dist(int index, String line) {\n\t\tint mul = 1;\n\t\tint result = 0;\n\t\tfor (int i = index; i < line.length(); i++) {\n\t\t\tif (line.charAt(i) == 'T') {\n\t\t\t\tmul *= -1;\n\t\t\t} else {\n\t\t\t\tresult += mul;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic class Name implements Comparable {\n\t\tString name;\n\t\tint h;\n\n\t\tpublic Name(String name, int h) {\n\t\t\tsuper();\n\t\t\tthis.name = name;\n\t\t\tthis.h = h;\n\t\t}\n\n\t\tpublic int compareTo(Name o) {\n\n\t\t\treturn h - o.h;\n\t\t}\n\n\t}\n\n\tstatic int find(int index, int[] u) {\n\t\tif (u[index] != index) {\n\t\t\treturn u[index] = find(u[index], u);\n\t\t}\n\t\treturn index;\n\t}\n\n\tstatic int crossProduct(Point a, Point b) {\n\t\treturn a.x * b.y + a.y * b.x;\n\t}\n\n\tstatic long squareDist(Point a) {\n\t\tlong x = a.x;\n\t\tlong y = a.y;\n\t\treturn x * x + y * y;\n\t}\n\n\tstatic Point minus(Point a, Point b) {\n\t\treturn new Point(a.x - b.x, a.y - b.y);\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\tstatic class Point {\n\t\tint x, y;\n\n\t\tpublic Point(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\tpublic String toString() {\n\t\t\treturn \"{\" + x + \" \" + y + \"}\";\n\t\t}\n\n\t}\n\n\tstatic class Entry implements Comparable {\n\t\tint x, cost;\n\n\t\tpublic Entry(int x, int cost) {\n\t\t\tsuper();\n\t\t\tthis.x = x;\n\t\t\tthis.cost = cost;\n\t\t}\n\n\t\tpublic int compareTo(Entry o) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\tif (cost > o.cost) {\n\t\t\t\treturn 1;\n\t\t\t} else if (cost == o.cost) {\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tstatic int gcd(int a, int b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\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(\"B-large.in\"))));\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "226bdb9352d696a2cdfbf77cc8fd54bc", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class P255D {\n\n @SuppressWarnings(\"unchecked\")\n public void run() throws Exception {\n long n = nextLong();\n long x = nextLong();\n long y = nextLong();\n long c = nextLong();\n\n if ((n == 1) || (c == 1)) {\n println(0);\n return;\n }\n\n x = Math.min(x, n - x + 1);\n y = Math.min(y, n - y + 1);\n long t = 0;\n long sum = 1;\n long add = 4;\n long subx1 = 3;\n long suby1 = 3;\n long subx2 = 3;\n long suby2 = 3;\n\n while (sum < c) {\n t++;\n\n sum += add;\n add += 4;\n \n if (t == x) {\n sum--;\n }\n if (t == n - x) {\n sum--;\n }\n if (t > x) {\n sum -= subx1;\n subx1 += 2;\n }\n if (t > n - x) {\n sum -= subx2;\n subx2 += 2;\n }\n\n if (t == y) {\n sum--;\n }\n if (t == n - y) {\n sum--;\n }\n if (t > y) {\n sum -= suby1;\n suby1 += 2;\n }\n if (t > n - y) {\n sum -= suby2;\n suby2 += 2;\n }\n \n if (t >= x + y) {\n sum += (t - x - y + 1);\n }\n\n }\n\n println(t);\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 P255D().run();\n br.close();\n pw.close();\n }\n\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { print(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(\"\"); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0d0e110a81dc26d6aa06257c646a1a85", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800} {"lang": "Java 7", "source_code": "import java.util.*;\n\n\npublic class Main {\n\n \n \n\n\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner (System.in);\n String array;\n float x,y;\n Main test=new Main();\n line inst=test.new line();\n x= scanner.nextFloat();\n y= scanner.nextFloat();\n array=scanner.next();\n ArrayList liness;\n liness=go(array);\n \n \n if(ifclosedpath(liness)==1)\n if( firstpath(x,y,liness)==1)\n {System.out.println(\"yes\");\n return;\n }\n else\n {System.out.println(\"No\");\n return;\n }\n \n \n \n if(firstpath(x,y,liness)==1)\n System.out.println(\"yes\");\n else\n if(checkpoint(x,y,liness)>=0)\n System.out.println(\"yes\");\n \n else\n System.out.println(\"No\");\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\nstatic ArrayList go(String array)\n{\n int n=0;\n float x=0;\n float y=0;\n ArrayList lines=new ArrayList() ;\n Main test=new Main();\n line inst=test.new line();\n \n \n \n \n int l=array.length();\n \n \n \n \n while(n lines)\n{\n Main test=new Main();\n line inst=test.new line();\n \n \n \n int l=lines.size();\n for (int counter=0;counter lines)\n{\n Main test=new Main();\n line inst=test.new line();\n \n float r;\n int flag=0;\n int counter;\n if(x==0 && y==0)\n return 0;\n\n else\n\n {\n\n\n\n\nfor(counter=0;counter0)\n return counter+1;\n else\n return -1;\n }\n\n}\n\n\nstatic int ifclosedpath(ArrayList lines)\n{\n\n if(lines.get(0).getX1()==lines.get(0).getX2() && lines.get(0).getY1()==lines.get(0).getY2() )\n return 1;\n else\n return 0;\n}\n \n\npublic class line\n{\n public float x1,x2,y1,y2,m,c;\n public char d;\n\n public void setX1(float x1) {\n this.x1 = x1;\n }\n\n public void setX2(float x2) {\n this.x2 = x2;\n }\n\n public void setY1(float y1) {\n this.y1 = y1;\n }\n\n\n public float getX2() {\n return x2;\n }\n\n public float getY2() {\n return y2;\n }\n\n public float getY1() {\n return y1;\n }\n\n public void setY2(float y2) {\n this.y2 = y2;\n }\n \n public float getX1() {\n return x1;\n }\n\n void makeline()\n {\n \n if(this.x1==this.x2)\n {\n this.d='v';\n this.c=this.x2;\n \n }\n else\n if(this.y1==this.y2)\n {\n this.d='h';\n this.c=this.y1;\n }\n else\n {\n this.d='n';\n this.m=(this.y2-this.y1)/(this.x2-this.x1);\n this.c=this.y1-(this.m*this.x1);\n \n \n }\n \n }\n \n}\n\n \n \n \n \n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "daeb96a972b77b6234b3fa58e5f9d4b8", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Contest190 {\n\n public static void main(String[] args) throws IOException {\n new Contest190().run();\n }\n\n long a, b;\n long x = 0, y = 0;\n\n void step(char c) {\n switch(c) {\n case 'U': ++y; break;\n case 'D': --y; break;\n case 'L': --x; break;\n case 'R': ++x; break;\n }\n }\n\n boolean walk_path(String s) {\n for(int i = 0; i < s.length(); ++i) {\n if(x == a && y == b)\n return true;\n step(s.charAt(i));\n }\n return x == a && y == b;\n }\n\n int sign(int n) {\n return n < 0 ? -1 : (n == 0 ? 0 : 1);\n }\n\n void solve() throws IOException {\n a = nextInt();\n b = nextInt();\n String s = nextToken();\n if(walk_path(s)) {\n out.println(\"Yes\");\n return;\n }\n if(x == 0 && y == 0) {\n out.println(\"No\");\n return;\n }\n\n long steps = Integer.MAX_VALUE;\n if(x != 0 && && a / x != 0)\n steps = Math.max(steps, Math.abs(a / x));\n if(y != 0 && b / y != 0)\n steps = Math.max(steps, Math.abs(b / y));\n\n if(steps != Integer.MAX_VALUE) {\n x *= steps;\n y *= steps;\n }\n\n for(int i = 0; i < 500; ++i)\n if(walk_path(s)) {\n out.println(\"Yes\");\n return;\n }\n out.println(\"No\");\n }\n\n BufferedReader br;\n StringTokenizer st;\n PrintWriter out;\n\n public String nextToken() throws IOException {\n while(st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\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 void run() throws IOException {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n br = new BufferedReader( new InputStreamReader( oj ? System.in : new FileInputStream(\"input.txt\")));\n out = new PrintWriter( oj ? System.out : new FileOutputStream(\"output.txt\"));\n\n solve();\n\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6468bebd2fce27ad485642bb26dbe89a", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class abc\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n long a=sc.nextLong();\n long b=sc.nextLong();\n if(a==0 && b==0)\n {\n System.out.print(\"YES\");\n return;\n }\n sc.nextLine();\n String s=sc.nextLine();\n long x[][]=new long[s.length()][2];\n int m=0;\n int n=0;\n for(int i=0;i r = new ArrayList<>();\n\t\tArrayList w = new ArrayList<>();\n\t\tArrayList o = new ArrayList<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t if (s.charAt(i) == 'R') {\n\t\t r.add(v[i]);\n\t\t } else if (s.charAt(i) == 'W') {\n\t\t w.add(v[i]);\n\t\t } else o.add(v[i]);\n\t\t}\n\t\tCollections.sort(r);\n\t\tCollections.sort(w);\n\t\tCollections.sort(o);\n\t\tint res = -1;\n\t\tif (k == 1) {\n\t\t System.out.println(res);\n\t\t}\n\t\telse{\n\t\tif (!r.isEmpty() && !o.isEmpty() && r.size() + o.size() >= k) {\n\t\t int t = o.get(o.size() - 1) + r.get(r.size() - 1);\n\t\t ArrayList al = new ArrayList<>();\n\t\t for (int i = 0; i + 1 < r.size(); ++i) \n\t\t al.add(r.get(i));\n\t\t for (int i = 0; i + 1 < o.size(); ++i) \n\t\t al.add(o.get(i));\n\t\t Collections.sort(al);\n\t\t for (int i = 0; i < k - 2; ++i) t += al.get(al.size() - 1 - i);\n\t\t res = Math.max(res, t);\n\t\t}\n\t\tif (!w.isEmpty() && !o.isEmpty() && w.size() + o.size() >= k) {\n\t\t int t = o.get(o.size() - 1) + w.get(w.size() - 1);\n\t\t ArrayList al = new ArrayList<>();\n\t\t for (int i = 0; i + 1 < w.size(); ++i) \n\t\t al.add(w.get(i));\n\t\t for (int i = 0; i + 1 < o.size(); ++i) \n\t\t al.add(o.get(i));\n\t\t Collections.sort(al);\n\t\t for (int i = 0; i < k - 2;++i) t += al.get(al.size() - 1 - i);\n\t\t res = Math.max(res, t);\n\t\t}\n\t\tSystem.out.println(res);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cc0c42789a2c2d1704fc22fdd29deda1", "src_uid": "104cf5253e027929f257364b3874c38b", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Task {\n \n public static long max(long a, long b ) {\n if(a < b) {\n return b;\n }\n return a;\n }\n \n \n public static int max(int a, int b ) {\n if(a < b) {\n return b;\n }\n return a;\n }\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int[] beauty = new int[200005];\n for(int i = 0; i < n; i++) {\n beauty[i] = sc.nextInt();\n }\n sc.nextLine();\n String str = sc.nextLine();\n int rcn = 0;\n int wcn = 0;\n int ocn = 0;\n int rsum = 0;\n int wsum = 0;\n int osum = 0;\n ArrayList wo = new ArrayList();\n ArrayList ro = new ArrayList();\n int maxo = -1;\n int maxr = -1;\n int maxw = -1;\n for(int i = 0; i < n; i++) {\n if(str.charAt(i) == 'R') {\n maxr = max(maxr,beauty[i]);\n rcn++;\n ro.add(beauty[i]);\n rsum+= beauty[i];\n }\n if(str.charAt(i) == 'W') {\n maxw = max(maxw,beauty[i]);\n wcn++;\n wo.add(beauty[i]);\n wsum+= beauty[i];\n }\n if(str.charAt(i) == 'O') {\n maxo = max(maxo,beauty[i]);\n ocn++;\n ro.add(beauty[i]);\n wo.add(beauty[i]);\n osum+= beauty[i];\n }\n }\n if(k == 1 || ocn == 0 || max(ocn+wcn,ocn+rcn) < k || (rcn == 0 && wcn == 0)) {\n System.out.print(-1);\n } else {\n if(rcn > 0) {\n ro.remove(ro.indexOf(maxr));\n }\n ro.remove(ro.indexOf(maxo));\n if(wcn > 0) {\n wo.remove(wo.indexOf(maxw));\n }\n wo.remove(wo.indexOf(maxo));\n Collections.sort(ro);\n Collections.sort(wo);\n long ans1 = maxr+maxo;\n long ans2 = maxw+maxo;\n if(ro.size()+2 >= k) {\n for(int i = ro.size()-1; i >= ro.size()-k+2; i--) {\n ans1+= ro.get(i);\n }\n }\n if(wo.size()+2 >= k) {\n for(int i = wo.size()-1; i >= wo.size()-k+2; i--) {\n ans2+= wo.get(i);\n }\n }\n System.out.print(max(ans1,ans2));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "91d5f8fd48b08645e8619bb93decda27", "src_uid": "104cf5253e027929f257364b3874c38b", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class temp\n{\n public static void main(String args[])\n {\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n int k=in.nextInt();\n int[] b=new int[n];\n for(int i=0;i w=new ArrayList();\n ArrayList o=new ArrayList();\n ArrayList r=new ArrayList();\n for(int i=0;i w=new ArrayList();\n ArrayList o=new ArrayList();\n ArrayList r=new ArrayList();\n for(int i=0;i0) {\r\n P1=ni(); T1=ni();\r\n P2=ni(); T2=ni();\r\n H=ni(); S=ni();\r\n if(T1>T2) {\r\n P1^=P2^(P2=P1);\r\n T1^=T2^(T2=T1);\r\n }\r\n // dp = new Integer[H+1];\r\n dp = new HashMap<>();\r\n int ans = solve(P1, T1, P2, T2, H, S, 0);\r\n sb.append(ans).append(\"\\n\");\r\n }\r\n out.println(sb);\r\n out.flush();\r\n out.close();\r\n }\r\n Integer x = Integer.MAX_VALUE;\r\n Map dp;\r\n int solve(int p1, int t1, int p2, int t2, int h, int s, int c) {\r\n if(h<=0) return 0;\r\n\r\n // int diff=Math.abs(c1-c2);\r\n String str = concat(h, t1, t2);\r\n if(dp.containsKey(str)) return dp.get(str);\r\n // 5000*5000=2.5*10^7\r\n\r\n int res = 0;\r\n if(t1+T1<=t2) {\r\n res = t1+solve(p1, T1, p2, t2-t1, h-(p1-s), s, c+t1);\r\n }\r\n else if(t1>t2) {\r\n int x = t1+solve(p1, T1, p2, T2, h-(p1+p2-s), s, c+t1);\r\n int y = t2+solve(p1, t1-t2, p2, T2, h-(p2-s), s, c+t2);\r\n res = min(x,y);\r\n }\r\n else {\r\n int x = t1+solve(p1, T1, p2, t2-t1, h-(p1-s), s, c+t1);\r\n int y = t2+solve(p1, T1, p2, T2, h-(p1+p2-s), s, c+t2);\r\n // System.out.println(h+\" \"+x+\" \"+y);\r\n res = min(x,y);\r\n }\r\n dp.put(str, res);\r\n return res;\r\n\r\n }\r\n String concat(Integer... v) {\r\n StringBuilder sb = new StringBuilder();\r\n for(Integer i: v) sb.append(i).append(\" \");\r\n return sb.toString();\r\n }\r\n StringBuilder pr(String s, int t) {\r\n return new StringBuilder().append(\"Case #\").append(t).append(\": \").append(s).append(\"\\n\");\r\n }\r\n public static void main(String[] args)throws Exception {\r\n try { \r\n // new Thread(null, new Code()::run, \"1\", 1 << 26).start();\r\n new Thread(null, new Code(\"ONLINE_JUDGE\")::run, \"1\", 1 << 26).start();\r\n } catch(Exception e) {}\r\n }\r\n\r\n FastReader sc=null;PrintWriter out = null;\r\n public Code()throws Exception {\r\n sc = new FastReader(new FileInputStream(\"input.txt\"));\r\n out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\r\n }\r\n public Code(String JUDGE) {\r\n sc = new FastReader(System.in);\r\n out = new PrintWriter(System.out); \r\n }\r\n \r\n String ns() { return sc.next(); }\r\n int ni() { return sc.nextInt(); }\r\n long nl() { return sc.nextLong(); }\r\n int[] ni(int n) {\r\n int a[]=new int[n];\r\n for(int i=0;i= numChars) {\r\n curChar = 0;\r\n try {\r\n numChars = stream.read(buf);\r\n } catch (IOException e) {\r\n throw new InputMismatchException();\r\n }\r\n if (numChars <= 0) return -1;\r\n }\r\n return buf[curChar++];\r\n }\r\n\r\n public int nextInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n }\r\n while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n \r\n public long nextLong() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n long res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res = res*1L*10;\r\n res += c - '0';\r\n c = read();\r\n }\r\n while (!isSpaceChar(c));\r\n return res *1L* sgn;\r\n }\r\n \r\n public String next() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n StringBuilder res = new StringBuilder();\r\n do {\r\n res.appendCodePoint(c);\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res.toString();\r\n }\r\n\r\n public boolean isSpaceChar(int c) {\r\n if (filter != null) return filter.isSpaceChar(c);\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n }\r\n\r\n public interface SpaceCharFilter {\r\n public boolean isSpaceChar(int ch);\r\n\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "103c553abc5c6c09fbc38645a7784f81", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\nimport static java.lang.System.*;\r\nimport static java.lang.Math.*;\r\npublic class Code\r\n{\r\n int P1,P2,H,S;\r\n long T1,T2;\r\n void run() {\r\n int tc=1;\r\n StringBuilder sb=new StringBuilder();\r\n while(tc-->0) {\r\n P1=ni(); T1=nl();\r\n P2=ni(); T2=nl();\r\n H=ni(); S=ni();\r\n if(T1>T2) {\r\n P1^=P2^(P2=P1);\r\n T1^=T2^(T2=T1);\r\n }\r\n // dp = new Integer[H+1];\r\n dp = new HashMap<>();\r\n long ans = solve(P1, T1, P2, T2, H, S);\r\n sb.append(ans).append(\"\\n\");\r\n }\r\n out.println(sb);\r\n out.flush();\r\n out.close();\r\n }\r\n Map dp;\r\n long solve(int p1, long t1, int p2, long t2, long h, int s) {\r\n if(h<=0) return 0L;\r\n\r\n // int diff=Math.abs(c1-c2);\r\n String str = concat(h, t1, t2);\r\n if(dp.containsKey(str)) return dp.get(str);\r\n // 5000*5000=2.5*10^7\r\n\r\n long res = 0;\r\n if(t1+T1<=t2) {\r\n res = t1+solve(p1, T1, p2, t2-t1, h-(p1-s), s);\r\n }\r\n else if(t1>t2) {\r\n long x = t1+solve(p1, T1, p2, T2, h-(p1+p2-s), s);\r\n long y = t2+solve(p1, t1-t2, p2, T2, h-(p2-s), s);\r\n res = min(x,y);\r\n }\r\n else {\r\n long x = t1+solve(p1, T1, p2, t2-t1, h-(p1-s), s);\r\n long y = t2+solve(p1, T1, p2, T2, h-(p1+p2-s), s);\r\n // System.out.println(h+\" \"+x+\" \"+y);\r\n res = min(x,y);\r\n }\r\n dp.put(str, res);\r\n return res;\r\n\r\n }\r\n String concat(Long... v) {\r\n StringBuilder sb = new StringBuilder();\r\n for(Long i: v) sb.append(i).append(\" \");\r\n return sb.toString();\r\n }\r\n StringBuilder pr(String s, int t) {\r\n return new StringBuilder().append(\"Case #\").append(t).append(\": \").append(s).append(\"\\n\");\r\n }\r\n public static void main(String[] args)throws Exception {\r\n try { \r\n // new Thread(null, new Code()::run, \"1\", 1 << 26).start();\r\n new Thread(null, new Code(\"ONLINE_JUDGE\")::run, \"1\", 1 << 26).start();\r\n } catch(Exception e) {}\r\n }\r\n\r\n FastReader sc=null;PrintWriter out = null;\r\n public Code()throws Exception {\r\n sc = new FastReader(new FileInputStream(\"input.txt\"));\r\n out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\r\n }\r\n public Code(String JUDGE) {\r\n sc = new FastReader(System.in);\r\n out = new PrintWriter(System.out); \r\n }\r\n \r\n String ns() { return sc.next(); }\r\n int ni() { return sc.nextInt(); }\r\n long nl() { return sc.nextLong(); }\r\n int[] ni(int n) {\r\n int a[]=new int[n];\r\n for(int i=0;i= numChars) {\r\n curChar = 0;\r\n try {\r\n numChars = stream.read(buf);\r\n } catch (IOException e) {\r\n throw new InputMismatchException();\r\n }\r\n if (numChars <= 0) return -1;\r\n }\r\n return buf[curChar++];\r\n }\r\n\r\n public int nextInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n }\r\n while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n \r\n public long nextLong() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n long res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res = res*1L*10;\r\n res += c - '0';\r\n c = read();\r\n }\r\n while (!isSpaceChar(c));\r\n return res *1L* sgn;\r\n }\r\n \r\n public String next() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n StringBuilder res = new StringBuilder();\r\n do {\r\n res.appendCodePoint(c);\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res.toString();\r\n }\r\n\r\n public boolean isSpaceChar(int c) {\r\n if (filter != null) return filter.isSpaceChar(c);\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n }\r\n\r\n public interface SpaceCharFilter {\r\n public boolean isSpaceChar(int ch);\r\n\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2a0df5f9de8bed84fee3b5c3a72ff262", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class E {\r\n\t\r\n\tstatic IOHandler sc = new IOHandler();\r\n\t\r\n\tstatic Long [] memo;\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\tsolve(0);\r\n\t}\r\n\t\r\n\tprivate static void solve(int t) {\r\n\t\tlong p1 = sc.nextInt();\r\n\t\tlong t1 = sc.nextLong();\r\n\t\t\r\n\t\tlong p2 = sc.nextInt();\r\n\t\tlong t2 = sc.nextLong();\r\n\t\t\r\n\t\tlong h = sc.nextInt();\r\n\t\tlong s = sc.nextInt();\r\n\t\t\r\n\t\t\r\n\t\tmemo = new Long [(int)h + 1];\r\n\t\t\r\n\t\t\r\n\t\tlong minP, minT, maxP, maxT;\r\n\t\t\r\n\t\tif (t1 < t2) {\r\n\t\t\tminP = p1;\r\n\t\t\tminT = t1;\r\n\t\t\tmaxP = p2;\r\n\t\t\tmaxT = t2;\r\n\t\t}else {\r\n\t\t\tminP = p2;\r\n\t\t\tminT = t2;\r\n\t\t\tmaxP = p1;\r\n\t\t\tmaxT = t1;\r\n\t\t}\r\n\r\n\t\t\r\n\t\tlong res = solve(minP, minT, maxP, maxT, h, s);\r\n\t\t\r\n\t\tSystem.out.println(res);\r\n\t}\r\n\t\r\n\tprivate static long solve(long p1, long t1, long p2, long t2, long h, long s) {\r\n\t\t\r\n\t\tif (h <= 0) \r\n\t\t\treturn 0;\r\n\t\telse if (h <= p1 - s) {\r\n\t\t\treturn t1;\r\n\t\t}else if (memo[(int)h] != null) {\r\n\t\t\treturn memo[(int)h];\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tlong result = Long.MAX_VALUE;\r\n\t\tlong test;\r\n\t\t\r\n\t\tlong end, val;\r\n\t\tlong count;\r\n\t\t\r\n\t\tfor (int i = 1; (i - 1) * (p1 - s) <= h ; ++i) {\r\n\t\t\tend = i * t1;\r\n\t\t\tval = (p1-s)*i;\r\n\t\t\ttest = val;\r\n\t\t\t\r\n\t\t\tif (end >= t2) {\r\n\t\t\t\tcount = (end - t2)/ t2;\r\n\t\t\t\tval = count * (p2 - s);\r\n\t\t\t\tval += p2;\r\n\t\t\t\ttest += val;\r\n\t\t\t}\r\n\t\t\tend += solve(p1, t1, p2, t2, h - test, s);\r\n\t\t\t\r\n\t\t\tresult = Math.min(result, end);\r\n\t\t} \r\n\t\t\r\n\t\tfor (int i = 1; (i - 1) * (p2 - s) <= h ; ++i) {\r\n\t\t\tend = i * t2;\r\n\t\t\t\r\n\t\t\tval = (p2 - s ) * i;\r\n\t\t\ttest = val;\r\n\t\t\t\r\n\t\t\tif (end >= t1) {\r\n\t\t\t\tcount = (end - t1)/ t1;\r\n\t\t\t\tval = count * (p1 - s);\r\n\t\t\t\tval += p1;\r\n\t\t\t\ttest += val;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tend += solve(p1, t1, p2, t2, h - test, s);\r\n\t\t\t\r\n\t\t\tresult = Math.min(result, end);\r\n\t\t} \r\n\t\t\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tprivate static long gcd(long a, long b) {\r\n\t\tif (a % b == 0)\r\n\t\t\treturn b;\r\n\t\t\r\n\t\treturn gcd(b , a % b);\r\n\t}\r\n\t\r\n\tprivate static class IOHandler {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n \r\n public IOHandler() {\r\n br = new BufferedReader(new InputStreamReader(System.in));\r\n }\r\n \r\n String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n \r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n \r\n int [] readArray(int n) {\r\n \t int [] res = new int [n];\r\n \t \r\n \t for (int i = 0; i < n; ++i)\r\n \t\t res[i] = nextInt();\r\n \t \r\n \t return res;\r\n }\r\n \r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n \r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n \r\n String nextLine(){\r\n String str = \"\";\r\n\t\t try {\r\n\t\t str = br.readLine();\r\n\t\t } catch (IOException e) {\r\n\t\t e.printStackTrace();\r\n\t\t }\r\n\t\t return str;\r\n }\r\n\r\n }\r\n\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "89877176075fbdf8117d1bec8ac593df", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400} {"lang": "Java 11", "source_code": "// package c1743;\n\n//\n// Educational Codeforces Round 137 (Rated for Div. 2) 2022-10-17 07:35\n// E. FTL\n// https://codeforces.com/contest/1743/problem/E\n// time limit per test 4 seconds; memory limit per test 512 megabytes\n// public class Pseudo for 'Source should satisfy regex [^{}]*public\\s+(final)?\\s*class\\s+(\\w+).*'\n//\n// Monocarp is playing a video game. In the game, he controls a spaceship and has to destroy an\n// enemy spaceship.\n//\n// Monocarp has two lasers installed on his spaceship. Both lasers 1 and 2 have two values:\n// * p_i-- the power of the laser;\n// * t_i-- the reload time of the laser.\n//\n// When a laser is fully charged, Monocarp can either shoot it or wait for the other laser to charge\n// and shoot both of them at the same time.\n//\n// An enemy spaceship has h durability and s shield capacity. When Monocarp shoots an enemy\n// spaceship, it receives (P - s) damage (i.?e. (P - s) gets subtracted from its durability), where\n// P is the total power of the lasers that Monocarp shoots (i.?e. p_i if he only shoots laser i and\n// p_1 + p_2 if he shoots both lasers at the same time). An enemy spaceship is considered destroyed\n// when its durability becomes 0 or lower.\n//\n// Initially, both lasers are zero charged.\n//\n// What's the lowest amount of time it can take Monocarp to destroy an enemy spaceship?\n//\n// Input\n//\n// The first line contains two integers p_1 and t_1 (2 <= p_1 <= 5000; 1 <= t_1 <= 10^{12})-- the\n// power and the reload time of the first laser.\n//\n// The second line contains two integers p_2 and t_2 (2 <= p_2 <= 5000; 1 <= t_2 <= 10^{12})-- the\n// power and the reload time of the second laser.\n//\n// The third line contains two integers h and s (1 <= h <= 5000; 1 <= s < \\min(p_1, p_2))-- the\n// durability and the shield capacity of an enemy spaceship. Note that the last constraint implies\n// that Monocarp will always be able to destroy an enemy spaceship.\n//\n// Output\n//\n// Print a single integer-- the lowest amount of time it can take Monocarp to destroy an enemy\n// spaceship.\n//\n// Example\n/*\ninput:\n5 10\n4 9\n16 1\noutput:\n20\n\ninput:\n10 1\n5000 100000\n25 9\noutput:\n25\n*/\n// Note\n//\n// In the first example, Monocarp waits for both lasers to charge, then shoots both lasers at 10,\n// they deal (5 + 4 - 1) = 8 damage. Then he waits again and shoots lasers at 20, dealing 8 more\n// damage.\n//\n// In the second example, Monocarp doesn't wait for the second laser to charge. He just shoots the\n// first laser 25 times, dealing (10 - 9) = 1 damage each time.\n//\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.InputStreamReader;\nimport java.lang.invoke.MethodHandles;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class C1743E {\n static final int MOD = 998244353;\n static final Random RAND = new Random();\n\n static long solve(long[][] lasers, int h, int s) {\n Arrays.sort(lasers, (x ,y) -> Long.compare(x[1], y[1]));\n int p1 = (int) lasers[0][0];\n long t1 = lasers[0][1];\n int p2 = (int) lasers[1][0];\n long t2 = lasers[1][1];\n long g = gcd(t1, t2);\n if (g > 1) {\n t1 /= g;\n t2 /= g;\n }\n myAssert(t1 <= t2);\n\n long maxt = Math.max(t1, t2);\n int sump = p1 + p2;\n int round = (h + sump - 1) / sump;\n long ans = round * maxt;\n if (t1 == t2) {\n return round * maxt * g;\n }\n\n // t2 is full multiple of t1\n if (t2 % t1 == 0) {\n // damage within each period of t2\n long m = t2 / t1;\n long d = (m-1) * (p1 - s) + (p1 + p2 - s);\n int k = (int) (h / d);\n int r = (int) (h - k * d);\n int l = r / (p1 - s);\n ans = k * t2 + (l < m ? l * t1 : t2);\n return ans * g;\n }\n\n {\n int r = (h + p1 - s - 1) / (p1 - s);\n if (r * t1 <= t2) {\n return r * t1 * g;\n }\n }\n\n // dp[v] is lowest amount of time to destroy spaceship with v durability\n long[] dp = new long[h + 1];\n Arrays.fill(dp, (long) 1e16);\n for (int v = 1; v <= h; v++) {\n // simulation: consider time t where t is multiple of t1 or t2\n int r = v;\n long x1 = t1;\n long x2 = t2;\n int d1 = p1 - s;\n int d2 = p2 - s;\n int d = p1 + p2 - s;\n while (true) {\n if (x1 < x2) {\n // t1 arrives first\n if (d1 >= r) {\n dp[v] = Math.min(dp[v], x1);\n break;\n }\n if (x1 + t1 <= x2) {\n // need apply the damage at x1 (no wait)\n r -= d1;\n } else {\n // two choices:\n // 1. wait until x2 and apply both damage\n // 2. apply the damage at x1 (no wait)\n if (d >= r) {\n dp[v] = Math.min(dp[v], x2);\n } else {\n dp[v] = Math.min(dp[v], x2 + dp[r - d]);\n }\n r -= d1;\n }\n x1 += t1;\n } else if (x1 == x2) {\n // t1 and t2 arrive at same time, apply both damage\n if (d >= r) {\n dp[v] = Math.min(dp[v], x2);\n } else {\n dp[v] = Math.min(dp[v], x2 + dp[r - d]);\n }\n // Completed a full cycle, done for v due to DP.\n break;\n } else {\n // t2 arrives first\n if (d2 >= r) {\n dp[v] = Math.min(dp[v], x2);\n break;\n }\n myAssert(x2 + t2 > x1);\n // two choices:\n // 1. wait until x1 and apply both damage\n // 2. apply the damage at x2 (no wait)\n if (d >= r) {\n dp[v] = Math.min(dp[v], x1);\n } else {\n dp[v] = Math.min(dp[v], x1 + dp[r - d]);\n }\n r -= d2;\n x2 += t2;\n }\n }\n }\n return dp[h] * g;\n }\n\n static long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n static void test(long exp, long[][] lasers, int h, int s) {\n long ans = solve(lasers, h, s);\n System.out.format(\"%s %d %d => %d\\n\", Arrays.deepToString(lasers), h, s, ans, ans == exp ? \"\":\"Expected \" + exp);\n myAssert(ans == exp);\n }\n\n static boolean test = false;\n static void doTest() {\n if (!test) {\n return;\n }\n long t0 = System.currentTimeMillis();\n test(259, new long[][] {{2,49},{2,21}}, 21, 1);\n\n test(20, new long[][] {{5,10},{4,9}}, 16, 1);\n test(25, new long[][] {{10,1},{5000,100000}}, 25, 9);\n test(67, new long[][] {{3,19},{4,29}}, 11, 2);\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n public static void main(String[] args) {\n doTest();\n MyScanner in = new MyScanner();\n long[][] lasers = new long[2][2];\n for (int i = 0; i < 2; i++) {\n lasers[i][0] = in.nextInt();\n lasers[i][1] = in.nextInt();\n }\n int h = in.nextInt();\n int s = in.nextInt();\n long ans = solve(lasers, h, s);\n System.out.println(ans);\n }\n\n static void output(int[] a) {\n if (a == null) {\n System.out.println(\"-1\");\n return;\n }\n StringBuilder sb = new StringBuilder();\n for (int v : a) {\n sb.append(v);\n sb.append(' ');\n if (sb.length() > 4000) {\n System.out.print(sb.toString());\n sb.setLength(0);\n }\n }\n System.out.println(sb.toString());\n }\n\n static void myAssert(boolean cond) {\n if (!cond) {\n throw new RuntimeException(\"Unexpected\");\n }\n }\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n try {\n final String USERDIR = System.getProperty(\"user.dir\");\n String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(\".MyScanner\", \"\");\n cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname;\n final File fin = new File(USERDIR + \"/io/c\" + cname.substring(1,5) + \"/\" + cname + \".in\");\n br = new BufferedReader(new InputStreamReader(fin.exists()\n ? new FileInputStream(fin) : System.in));\n } catch (Exception e) {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n }\n\n public String next() {\n try {\n while (st == null || !st.hasMoreElements()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n } catch (Exception 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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "75670109878506792878a0b98d5353f5", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Rounding {\n\tpublic static void main(String[] args) {\n\t\tScanner kb = new Scanner(System.in);\n\t\t\n\t\tint a;\n\t\tnumber = kb.nextInt();\n\t\t\n\t\ta = a % 10;\n\n\t\tif (a > 5) {\n\t\t\ta = a - (n%10)+10;\n\t\t} else {\n\t\t\ta = a - (n%10);\n\t\t\tSystem.out.println(a);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e4aa645cf7a31e5526c92fa78de5c985", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*; \nimport java.util.Scanner; \npublic class S {\n public static int round (n) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n m = n\n //m = 1's place\n while (m > 1000) {\n m = m - 1000;\n }\n while (m > 100) {\n m = m - 100;\n }\n while ( m > 10) {\n m = m - 10;\n }\n zeroDist = m;\n tenDist = 10 - m;\n if (zeroDist < tenDist) {\n n = n - zeroDist;\n } else {\n n = n + tenDist;\n }\n return n;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f85d2358472f660d77b63503a7265d01", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Rounding {\n\tpublic static void main(String[] args) {\n\t\tScanner kb = new Scanner(System.in);\n\t\t\n\t\tint a;\n\t\tnumber = kb.nextInt();\n\t\t\n\t\ta = a % 10;\n\n\t\tif (a > 5) {\n\t\t\ta = a - (a%10)+10;\n\t\t} else{ \n\t\t\ta = a - (a%10);\n\t\t\tSystem.out.println(a);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2f674a14b06dca384e40a6868f9bdb2e", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Rounding {\n\tpublic static void main(String[] args) {\n\t\tScanner kb = new Scanner(System.in);\n\t\t\n\t\tint a;\n\t\tint b;\n\t\ta = kb.nextInt();\n\t\t\n\t\tb = a % 10;\n\n\t\tif (b > 5) {\n\t\t\ta - b;\n\t\t} else { \n\t\t\ta + (10 - b);\n\t\t\tSystem.out.println(a);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3172090109a5d4eafc811670bcfdfda", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9", "difficulty": 800} {"lang": "Java 8", "source_code": "package hw1;\n\nimport java.util.Scanner;\n\npublic class Square {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scan = new Scanner(System.in);\n\t\tint d = scan.nextInt();\n\t\tint x = scan.nextInt();\n\t\tint y = scan.nextInt();\n\t\tif(x == (d+1)/2 || x-1 == (d+1)/2 || y== (d+1)/2 || y-1 ==(d+1)/2) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}else {\n\t\t\tSystem.out.println(\"YES\");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5658334b700190802ea7e05ef3a91b9c", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author Homich\n */\npublic class Main {\n\n StreamTokenizer in;\n PrintWriter out;\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws Exception {\n new Main().run();\n }\n\n public void run() throws Exception {\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n solve();\n out.flush();\n }\n\n int nextInt() throws Exception {\n in.nextToken();\n return (int) in.nval;\n }\n\n public void solve() throws Exception {\n int n=nextInt();\n int x=nextInt();\n int y=nextInt();\n if (n<=2) out.println(\"NO\");\n else{\n int a=n/2;\n if((x==a)&&(y==a)||(x==a)&&(y==a+1)||(x==a+1)&&(y==a)||(x==a+1)&&(y==a+1))out.println(\"NO\");\n else out.println(\"YES\");\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ed045a9525c3a9325e4509601f9a6a25", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class peta {\n public static void main(String[] args) {\n reader = new BufferedReader(new InputStreamReader(System.in));\n int n = nextInt(), x = nextInt(), y = nextInt();\n int h = n / 2;\n for(int i = 0; i <= 1; ++i) {\n for(int j = 0; j <= 1; ++j) {\n if (x == h + i && y == h+ j) {\n System.out.println(\"NO\");\n return;\n }\n }\n }\n System.out.println(\"YES\");\n }\n\n public static BufferedReader reader;\n\n public static StringTokenizer tokenizer = null;\n\n static 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 static public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n static public long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n static public String next() {\n return nextToken();\n }\n\n static public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ceb10e640effd3b261ed4a9f83c03c31", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.math.*;\n\npublic class P2 {\n\n\tpublic void run() throws Exception {\n\t\tint n=getInt();\n\t\tint x=getInt();\n\t\tint y=getInt();\n\t\tif((x==n/2||x==n/2+1)&&(y==n/2||y==n/2+1){\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\tpublic int getInt() throws Exception {\n\t\treturn Integer.valueOf(getStringTokenizer().nextToken());\n\t}\n\n\tpublic long getLong() throws Exception {\n\t\treturn Long.valueOf(getStringTokenizer().nextToken());\n\t}\n\n\tpublic double getDouble() throws Exception {\n\t\treturn Double.valueOf(getStringTokenizer().nextToken());\n\t}\n\n\tpublic String getString() throws Exception {\n\t\treturn reader.readLine();\n\t}\n\n\tprivate StringTokenizer token = null;\n\tprivate BufferedReader reader = new BufferedReader(new InputStreamReader(\n\t\t\tSystem.in));\n\n\tpublic StringTokenizer getStringTokenizer() throws Exception {\n\t\tif (token == null || !token.hasMoreTokens()) {\n\t\t\tString str = reader.readLine();\n\t\t\ttoken = new StringTokenizer(str);\n\t\t}\n\t\treturn token;\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew P2().run();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bfc543318eb8c90afe1d948a160e2976", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\tstatic final int INF = 1000000007;\n\tstatic final Scanner sc = new Scanner(System.in);\n\t\n\tstatic int TC;\n\tstatic int N, M, K;\n\tstatic String S;\n\tstatic int[] freq = new int[256];\n\tstatic int[] tmp_freq = new int[256];\n\tstatic List vec_char = new ArrayList<>();\n\tstatic BigInteger result = BigInteger.ZERO;\n\tstatic BigInteger[] fact = new BigInteger[25];\n\t\n\tstatic BigInteger count_special(int len) {\n\t\tint N = len;\n\t\tBigInteger result = BigInteger.ZERO;\n\t\tfor (char ch : vec_char) {\n\t\t\tif (ch == '0') continue;\n\t\t\ttmp_freq[ch] -= 1;\n\t\t\tBigInteger tmp_result = fact[N-1];\n\t\t\tfor (char ch2 : vec_char) {\n\t\t\t\tif (tmp_freq[ch2] == 0) continue;\n\t\t\t\ttmp_result = tmp_result.divide(fact[tmp_freq[(int)ch2]]);\n\t\t\t}\n\t\t\ttmp_freq[ch] += 1;\n\t\t\tresult = result.add(tmp_result);\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic BigInteger count_possible() {\n\t\tint N = S.length();\n\t\tBigInteger result = fact[N];\n\t\tfor (char ch : vec_char) {\n\t\t\tresult = result.divide(fact[tmp_freq[ch]]);\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic void recur(int pos, int len) {\n\t\tif (pos >= vec_char.size()) {\n\t\t\tif (tmp_freq['0'] == 0) result = result.add(count_possible());\n\t\t\telse result = result.add(count_special(len));\n\t\t} else {\n\t\t\tchar cur_char = vec_char.get(pos);\n\t\t\tfor (int i = 1; i <= freq[(int)cur_char]; i++) {\n\t\t\t\ttmp_freq[cur_char] = i;\n\t\t\t\trecur(pos+1, len+i);\n\t\t\t}\n\t\t}\n\t}\n\t\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tfact[1] = BigInteger.ONE;\n\t\tfor (int i = 2; i <= 20; i++) {\n\t\t\tfact[i] = fact[i-1].multiply(BigInteger.valueOf(i));\n\t\t}\n\n\t\tS = sc.next();\n\t\tSet unik_char = new HashSet<>();\n\t\t\n\t\tfor (char ch : S.toCharArray()) {\n\t\t\tfreq[(int)ch] += 1;\n\t\t\tunik_char.add(ch);\n\t\t}\n\t\tvec_char = new ArrayList<>(unik_char);\n\n\t\trecur(0, 0);\n\t\tSystem.out.println(result);\n\t\t\n\t\tSystem.exit(0);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e153a46b02596a8eb99b7ad7535aa2a2", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n\tstatic long n;\n\tstatic int cnt[] = new int[10];\n\tstatic int num[] = new int[10];\n\tstatic long f[] = new long[20];\n\tstatic long ans = 0;\n\tpublic static void main(String arg[]) {\n\t\t\n\t\tf[0] = 1;\n\t\tfor(int i = 1; i <= 18; i++) {\n\t\t\tf[i] = f[i - 1] * i;\n\t\t}\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\tn = in.nextLong();\n\t\twhile(n > 0) {\n\t\t\tint ret = (int)(n % 10);\n\t\t\tcnt[ret]++;\n\t\t\tn /= 10;\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < 10; i++) {\n\t\t\tif(cnt[i] > 0) {\n\t\t\t\tnum[i] = 1;\n\t\t\t\tcnt[i]--;\n\t\t\t}\n\t\t}\n\t\t\n\t\tdfs(0);\n\t\tSystem.out.println(ans);\n\t\tin.close();\n\t}\n\t\n\tpublic static void dfs(int p) {\n\t\t//System.out.println(\"#####\");\n\t\tans += cal();\n\t\tfor(int i = p; i <= 9; i++) {\n\t\t\tif(cnt[i] == 0) continue;\n\t\t\tcnt[i]--;\n\t\t\tnum[i]++;\n\t\t\tdfs(i);\n\t\t\tnum[i]--;\n\t\t\tcnt[i]++;\n\t\t}\n\t}\n\tpublic static long cal() {\n\t\tint sum = 0;\n\t\tlong ans = 0, ret = 0;\n\t\tfor(int i = 0; i <= 9; i++) sum += num[i];\n\t\tans = f[sum];\n\t\t\n\t\tfor(int i = 0; i <= 9; i++) {\n\t\t\tif(num[i] > 0)ans /= f[num[i]];\n\t\t}\n\t\t\t\n\t\t\n\t\tif(num[0] > 0) {\n\t\t\tret = f[sum - 1];\n\t\t\tret /= f[num[0] - 1];\n\t\t\tfor(int i = 1; i <= 9; i++) {\n\t\t\t\tif(num[i] > 0) {\n\t\t\t\t\tret /= f[num[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ans - ret;\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7df4bfc92bffd0d57458d2c461ed90e8", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n EBusNumber solver = new EBusNumber();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class EBusNumber {\n char[] arr;\n HashSet set;\n long memo;\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n arr = sc.next().toCharArray();\n set = new HashSet<>();\n for (char c : arr)\n set.add(c);\n memo = new long[arr.length][1 << 18];\n for (long[] x : memo)\n Arrays.fill(x, -1);\n pw.println(dp(0, 0));\n }\n\n private long dp(int idx, int msk) {\n if (idx == arr.length) {\n return 1;\n }\n if (memo[idx][msk] != -1)\n return memo[idx][msk];\n boolean[] vis = new boolean[10];\n HashSet temp = new HashSet<>();\n for (int i = 0; i < arr.length; i++) {\n if ((msk & (1 << i)) != 0)\n temp.add(arr[i]);\n }\n long sum = temp.size() == set.size() ? 1 : 0;\n for (int i = 0; i < arr.length; i++) {\n if (idx == 0 && arr[i] == '0' || (msk & (1 << i)) != 0 || vis[arr[i] - '0'])\n continue;\n vis[arr[i] - '0'] = true;\n sum += dp(idx + 1, msk | 1 << i);\n }\n return memo[idx][msk] = sum;\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cb1296218bf4ec8ec10f86f3e0154fea", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Ideone {\n\tpublic static ArrayList Data = new ArrayList(); \n\t\n\tpublic static long fact (int n) {\n\t\tif (n <= 1) return 1;\n\t\telse {\n\t\t\tlong rez = 1;\n\t\t\tfor (int i = 2; i <= n; i++) rez *= i;\n\t\t\treturn rez;\n\t\t}\t\n\t}\n\n\tpublic static long P (int[] count) {\n\t\tint n = 0;\n\t\tfor (int i = 0; i < 10; i++) n += count[i];\n\t\tlong rez = fact(n);\n\t\tfor (int i = 0; i < 10; i++) rez /= fact(count[i]);\n\t\tif (count[0] >= 1) {\n\t\t\tlong dif = fact(n-1);\n\t\t\tdif /= fact(count[0]-1);\n\t\t\tfor (int i = 1; i < 10; i++) dif /= fact(count[i]);\n\t\t\trez -= dif;\n\t\t}\n\t\treturn rez;\n\t}\n\n\tpublic static long Calc (int[] count) {\n\t\tlong rez = P(count);\n\t\tint[][] counts = new int[10][10];\n\t\tfor (int i = 0; i < 10; i++) {\n\t\t\tif(count[i] != 0 && count[i] != 1) {\n\t\t\t\tfor (int j = 0; j < 10; j++) counts[i][j] = count[j];\n\t\t\t\tcounts[i][i]--;\n\t\t\t\tString str = \"\";\n\t\t\t\tfor (int j = 0; j < 10; j++) str += counts[i][j] + '0';\n\t\t\t\tboolean contains = false;\n\t\t\t\tfor (int j = 0; j < Data.size() && !contains; j++) if (Data.get(j) == str) contains = true;\n\t\t\t\tif (!contains) {\n\t\t\t\t\tData.add(str);\n\t\t\t\t\trez += Calc(counts[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn rez;\n\t}\n\n\tpublic static void main (String[] args) {\n\t\tint count[] = {0,0,0,0,0,0,0,0,0,0};\n\t\tString str;\n\t\tScanner imput = new Scanner(System.in);\n\t\tstr = imput.nextLine();\n\t\tfor (char a: str.toCharArray()) count[a-'0']++;\n\t\tSystem.out.print(Calc(count));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1403c46fc8d99e770eafcc92f255ece4", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) throws FileNotFoundException {\n Scanner sc = new Scanner(System.in);\n int n, t, sum;\n t = sc.nextInt();\n while(t-- > 0) {\n n = sc.nextInt();\n sum = 0;\n sum += n / 7;\n if(n % 7 == 1)\n sum += 2;\n else if(n % 7 > 1)\n sum++;\n System.out.println(sum);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f6f96b728ceaaa83e7aade3f9d89aba9", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class CFS {\n public static void main (String [] args) {\n Scanner sc = new Scanner (System.in);\n int t = sc.nextInt();\n for(int i = 1; i <= t; i++) \n System.out.prinln((int)Math.ceil(sc.nextDouble()/2));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dff9a795ac2e96152e12c4731ab00455", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c", "difficulty": 800} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage javaapplication51;\n\n//import java.util.Scanner;\n\n/**\n *\n * @author Pascal-PC\n */\npublic class JavaApplication51 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n for (int i = 0; i < n; i++) {\n int y=in.nextInt();\n System.out.println(y/7+1);\n }\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9272c956f52b5e8dfc45cca0e8a9bfe2", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Dice{\n\tpublic static void main(String[] args){\n\t\tScanner s = new Scanner(System.in);\n\t\tint t = s.nextInt();\n\t\tint[] x = new int[t];\n\t\tint[] ans = new int[t];\n\t\tfor(int i=0;i 0 && qcount == (k - ccount))\n\t\t\t\t{\n\t\t\t\t\tint j = 0;\n\t\t\t\t\tfor (; j < k; j++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!counts[j])\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tc = (char) ('a' + j);\n\n\t\t\t\t\tccount++;\n\t\t\t\t}\n\n\t\t\t\tarr[i] = c;\n\t\t\t\tarr[arr.length - 1 - i] = c;\n\t\t\t\tcounts[c - 'a'] = true;\n\t\t\t\tqcount--;\n\t\t\t}\n\t\t}\n\n\t\tfor (i = 0; i < k; i++)\n\t\t\tif (!counts[i])\n\t\t\t\tbreak;\n\n\t\tif (i < k)\n\t\t\tout.println(\"IMPOSSIBLE\");\n\t\telse\n\t\t\tout.println(arr);\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e4abe4a1bc8d5612472a50e56d832d6", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600} {"lang": "Java 11", "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;ir1) {\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]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] chr=new ArrayList<>();\n chr.add('a');\n for(int i=0;i=0;i--) {\n if(str.charAt(i)=='?' && str.charAt(str.length()-1-i)=='?') {\n str.setCharAt(i, chr.get(indx));\n str.setCharAt(str.length()-1-i, chr.get(indx));\n indx--;\n }\n if(str.charAt(i)=='?') {\n str.setCharAt(i, str.charAt(str.length()-1-i));\n }\n if(str.charAt(str.length()-1-i)=='?') {\n str.setCharAt(str.length()-1-i, str.charAt(i));\n } \n indx=Math.max(indx, 0);\n if(str.charAt(i)!=str.charAt(str.length()-1-i)) {\n System.out.println(\"IMPOSSIBLE\");\n return;\n }\n }\n has=new boolean[k];\n for(int i=0;i a = new ArrayList<>();\n for (int i = 1; a.size() < n; i++) {\n for (char c : Integer.toString(i).toCharArray()) {\n a.add(c);\n }\n }\n println(a.get(n - 1));\n }\n\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 List[] createAdjacencyList(int n) {\n List[] 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}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "30633cf5055fd36ae498a94a09edc578", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\npublic class main {\n public static void main(String args[])throws IOException {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n String g = new String();\n int i;\n for (i=0;i<1000;i++){\n g += i;\n }\n int n =in.nextInt();\n char t = g.charAt(n);\n out.print(t);\n out.close()\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "882ab0a888e4122fc974d0ee9ee739a6", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800} {"lang": "Java 7", "source_code": "public class Main {\n \n\tpublic static void main(String [] arg){\n\t\tStringBuilder sb=new StringBuilder();\n\t\tString number=\"\";\n\t\tint N;\n\t\tfor(int i=1;i<=370;i++){\n\t\t\tnumber=Integer.toString(i);\n\t\t\tsb.append(number);\n\t\t\tnumber=\"\";\n\t\t}\n\t\tScanner in = new Scanner(System.in);\n\t\tN=in.nextInt();\n\t\tSystem.out.println(sb.toString().charAt(N-1));\n\t}\n\t\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e416036145bb0ef7220295381069e65d", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n String str = s.nextLine();\n int n = str.length();\n if(n <= 1) System.out.println(\"0\");\n //else if (n <= 3) System.out.println(\"1\");\n else {\n if(n % 2 != 0 && isZero(str.substring(1)) {\n System.out.println(n/2);\n } else if(n%2 == 0) System.out.println((n/2)+1);\n else System.out.println(n/2);\n }\n }\n \n private static boolean isZero(String s) {\n for(char c : s.toCharArray()) {\n if(c!='0') return fasle;\n }\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8bf0412b606acc50fd10df8fa1181466", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n \npublic class BowWow {\n public static void main(String[] args) throws Exception {\n \n PrintWriter pw=new PrintWriter(System.out);\n \n BufferedReader br = new BufferedReader( \n new InputStreamReader(System.in)); \n \n InputReader in=new InputReader(System.in);\n \n char[] ch=in.nextLine().toCharArray();\n int n=ch.length;\n if(ch[0]=='0'){\n System.out.println(\"0\");\n return;\n }\n for(int i=1;i{\n int x;\n int y;\n Pair(int a,int b){ //creates a pair\n x=a;\n y=b;\n }\n public int compareTo(Pair t){\n if(x>t.x){\n return 1;\n }\n else if(x==t.x){\n if(y>=t.y){\n return 1;\n }\n else {\n return -1;\n }\n }\n else {\n return -1; \n }\n }\n public boolean equals(Object obj){\n if(this==obj)return true;\n Pair that=(Pair)obj;\n if(this.x==that.x && this.y==that.y)return true;\n return false;\n }\n public boolean equals(Object obj){\n if(this==obj)return true;\n Pair that=(Pair)obj;\n if(this.x==that.x && this.y==that.y)return true;\n return false;\n }\n \n public String toString(){\n return this.x+\" \"+this.y;\n }\n }\n static class InputReader {\n \n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n \n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n \n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public String next() {\n return nextString();\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n \n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "efe1e7ea9fdef2edf85ec98a17a4752d", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class a_bowwow {\n\n\t\tpublic static void main(String args[]) throws Exception{\n\t\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString s = br.readLine();\n\t\t\tchar[] a = new char[s.length()];\n\t\t\ta = s.toCharArray();\n\t\t\tdouble[] n = new double[s.length()];\n\t\t\tdouble t, sol = 0;\n\t\t\tint count = 0;\n\t\t\t\n\t\t\tfor(int i=0; i1){\n\t\t\t\tsol /= 4;\n\t\t\t\tcount ++;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(count);\n\t\t\t\n\t\t}\n\t}\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f1dcce5fc4c9532fc8e5920cc3ae3fc7", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Sol\n{\n public static void main(String srgs[])\n {\n Scanner sc = new Scanner(System.in);\n BigInteger b = new BigInteger(sc.next(),2);\n System.out.print(Math.log(b)/Math.log(4));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a2c2a80b51f9def2532c3d11b9983574", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Maximum {\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\n\t\tint[] arr = new int[a];\n \n\t\tfor(int i=0; i r;\n \t\tcontinue;\n \t}\n \telse {\n \t\tarr[j] = r;\n\n\n \t}\n \t\n }\n\t\t}\n \n int sum = 0;\n\n\t\tfor(int i=0; i hm = new HashMap<>();\n i = 0;\n while(i entry: hm.entrySet())\n profit += Math.pow(entry.getValue(),2);\n i = 0;\n System.out.println(profit);\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f53e7a53538e882f39cad518d1670b36", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Zone {\n\tstatic int[][] min(int arrold[][],int mo) {\n\t\tint arr[][] = new int[mo][3];\n\t\tfor(int j=0;jarr[i+1][2]) {\n\t\t\t\t\tif(arr[i][0] != arr[i][1]) {\n\t\t\t\t\t\tarr[i][1]--;\n\t\t\t\t\t}\n\t\t\t\t\telse if(arr[i][0]==arr[i][1]) {\n\t\t\t\t\t\tarr[i][2] = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn arr; \n\t}\n\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint h = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint r[][]= new int[m][3];\n\t\tint a[] = new int[n];\n\t\tArrays.fill(a,h);\n\t\tfor(int i=0;i0) {\n\t\t\t\tfor(int j=r[i][0];j<=r[i][1];j++)\n\t\t\t\t\ta[j-1] = r[i][2];\n\t\t\t}\n\t\t}\n\t\tint sum = 0;\n\t\tfor(int q=0;qx&&a[j]>0)\n\t\t a[j]=x;\n\t\t else if(a[j]==0)\n\t\t a[j]=x;\n\t\t else if(x==0)\n\t\t {\n\t\t a[j]=1;\n\t\t ans=ans-(r-l+1);\n\t\t }\n\t\t }\n\t\t}\n\t\tfor(inyt i=0;i= minx && inxmin <= maxx){\n\t\t\tif(inymin >= miny && inymin <= maxy){\n\t\t\t\tflag = 1;\n\t\t\t}\n\t\t}\n\t\telse if(inxmax >= minx && inxmax <= maxx){\n\t\t\tif(inymax >= miny && inymax <= maxy){\n\t\t\t\tflag = 1;\n\t\t\t}\n\t\t}\n\n\t\tif(flag == 1)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11247b7aed831d59cf558aa1bf5b0aad", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600} {"lang": "Java 8", "source_code": "import sun.rmi.transport.DGCImpl_Stub;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws FileNotFoundException {\n ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out));\n\n// String fileName = \"C-large\";\n// ConsoleIO io = new ConsoleIO(new FileReader(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + fileName + \".in\"), new PrintWriter(new File(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + fileName + \".out\")));\n\n new Main(io).solve();\n// new Main(io).solveLocal();\n\n io.close();\n }\n\n ConsoleIO io;\n Main(ConsoleIO io) {\n this.io = io;\n }\n ConsoleIO opt;\n Main(ConsoleIO io, ConsoleIO opt) {\n this.io = io; this.opt = opt;\n }\n\n List> gr = new ArrayList<>();\n long MOD = 1_000_000_007;\n\n public void solve() {\n int[] par = io.readIntArray();\n int[] ang = io.readIntArray();\n for(int i = 0;i 0) sb.append(separator);\n sb.append(a[i]);\n }\n this.writeLine(sb.toString());\n }\n public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}\n public String readLine() {try {return br.readLine();}catch (Exception ex){ return \"\";}}\n public long[] readLongArray() {\n String[]n=this.readLine().trim().split(\"\\\\s+\");long[]r=new long[n.length];\n for(int i=0;i='0' && all[i]<='9'){\n cur = cur*10+all[i]-'0';\n have = true;\n }else if(all[i]=='-') {\n neg = true;\n }\n else if(have){\n res[k++] = neg?-cur:cur;\n cur = 0;\n have = false;\n neg = false;\n }\n }\n if(have)res[k++] = neg?-cur:cur;\n return res;\n }\n public int ri() {\n try {\n int r = 0;\n boolean start = false;\n boolean neg = false;\n while (true) {\n int c = br.read();\n if (c >= '0' && c <= '9') {\n r = r * 10 + c - '0';\n start = true;\n } else if (!start && c == '-') {\n start = true;\n neg = true;\n } else if (start || c == -1) return neg ? -r : r;\n }\n } catch (Exception ex) {\n return -1;\n }\n }\n public long readLong() {\n try {\n long r = 0;\n boolean start = false;\n boolean neg = false;\n while (true) {\n int c = br.read();\n if (c >= '0' && c <= '9') {\n r = r * 10 + c - '0';\n start = true;\n } else if (!start && c == '-') {\n start = true;\n neg = true;\n } else if (start || c == -1) return neg ? -r : r;\n }\n } catch (Exception ex) {\n return -1;\n }\n }\n public String readWord() {\n try {\n boolean start = false;\n StringBuilder sb = new StringBuilder();\n while (true) {\n int c = br.read();\n if (c!= ' ' && c!= '\\r' && c!='\\n' && c!='\\t') {\n sb.append((char)c);\n start = true;\n } else if (start || c == -1) return sb.toString();\n }\n } catch (Exception ex) {\n return \"\";\n }\n }\n public char readSymbol() {\n try {\n while (true) {\n int c = br.read();\n if (c != ' ' && c != '\\r' && c != '\\n' && c != '\\t') {\n return (char) c;\n }\n }\n } catch (Exception ex) {\n return 0;\n }\n }\n//public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}\n}\nclass Pair {\n public Pair(int a, int b) {this.a = a;this.b = b;}\n public int a;\n public int b;\n}\nclass PairLL {\n public PairLL(long a, long b) {this.a = a;this.b = b;}\n public long a;\n public long b;\n}\nclass Triple {\n public Triple(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}\n public int a;\n public int b;\n public int c;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "05578ef79a93d42d81206c155b0e8d62", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n\tstatic boolean visited[] ; \n\tstatic boolean ends[] ;\n\tstatic long mod = 1000000007 ;\n\tstatic int lens[] ; \n\tstatic int seeds[] ; \n\tstatic int a[] ;\n\tstatic double total ; \n\tpublic static ArrayList adj[] ; \n\tpublic static long x,y ; \n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tScanner sc = new Scanner(System.in) ;\n\n\t\tint x1[]= new int[4] ; \n\t\tint y1[]= new int[4] ; \n\t\tint x2[] = new int[4] ; \n\t\tint y2[] = new int[4] ; \n\n\t\t//sss\n\n\t\tfor (int i = 0; i < 4; i++)\n\t\t{\n\t\t\tx1[i]=sc.nextInt() ; \n\t\t\ty1[i]=sc.nextInt() ; \n\n\t\t}\n\t\tfor (int i = 0; i < 4 ;i++)\n\t\t{\n\t\t\tx2[i]=sc.nextInt() ; \n\t\t\ty2[i]=sc.nextInt() ; \n\t\t}\n\n\n\t\tArrays.sort(x1);\n\t\tArrays.sort(x2);\n\t\tArrays.sort(y1);\n\t\tArrays.sort(y2);\n\n\n\n\n\n\n\n\n\t\tint h=y2[3]-y2[0] ; \n\t\th=h/2 ; \n\t\tint begin=y2[0]+h ; \n\t\tHashMap map = new HashMap() ; \n\n\t\tfor (int i = 0; i <=h; i++)\n\t\t\tfor (int j = x2[0]+i; j <=x2[3]-i; j++)\n\t\t\t{\n\t\t\t\tmap.put(new point(j,begin+i),0) ; \n\t\t\t\tmap.put(new point(j,begin-i),0) ;\n\t\t\t}\n\n\t\tfor (int i = x1[0]; i <= x1[3]; i++)\n\t\t\tfor (int j =y1[0]; j <= y1[3]; j++)\n\t\t\t{\n\t\t\t\tpoint p = new point(i , j);\n\t\t\t\tif(map.containsKey(p))\n\t\t\t\t{System.out.println(\"YES\"); return ;}\n\t\t\t}\n\n\t\tSystem.out.println(\"NO\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t}\n\n\n\tpublic static int neededFromLeft(String x)\n\t{\n\t\tStack st = new Stack() ; \n\t\tint c=0;\n\n\t\tfor (int i = 0; i < x.length(); i++)\n\t\t{\n\t\t\tchar cur = x.charAt(i); \n\t\t\tif(cur==')' && st.isEmpty())\n\t\t\t\tc ++; \n\t\t\telse if(cur==')' && !st.isEmpty())\n\t\t\t\tst.pop();\n\t\t\telse if(cur=='(')\n\t\t\t\tst.push(cur);\n\t\t}\n\t\treturn c;\n\t}\n\n\tpublic static int neededFromRight(String x)\n\t{\n\t\tStack st = new Stack() ; \n\t\tint c=0;\n\t\tboolean f=true; \n\t\tfor (int i = 0; i < x.length(); i++)\n\t\t{\n\t\t\tchar cur = x.charAt(i); \n\t\t\tif(cur==')' && st.isEmpty())\n\t\t\t\tf=false; \n\t\t\telse if(cur==')' && !st.isEmpty())\n\t\t\t\tst.pop();\n\t\t\telse if(cur=='(')\n\t\t\t\tst.push(cur);\n\t\t}\n\t\treturn st.size(); \n\t}\n\n\tpublic static boolean fromBoth(String x)\n\t{\n\t\tStack st = new Stack() ;\n\t\tboolean f1=true ,f2=true ; \n\n\t\tfor (int i = 0; i < x.length(); i++)\n\t\t{\n\t\t\tchar cur = x.charAt(i); \n\t\t\tif(cur==')' && st.isEmpty())\n\t\t\t\tf1 =false ; \n\t\t\telse if(cur==')' && !st.isEmpty())\n\t\t\t\tst.pop();\n\t\t\telse if(cur=='(')\n\t\t\t\tst.push(cur);\n\t\t}\n\t\tif(st.size()>0)f2 = false ;\n\n\t\tif(f1==false && f2==false)\n\t\t\treturn true ; \n\t\telse \n\t\t\treturn false;\n\t}\n\n\tpublic static boolean isRegular(String x)\n\t{\n\t\tStack st = new Stack() ; \n\t\tfor (int i = 0; i < x.length(); i++)\n\t\t{\n\t\t\tchar cur = x.charAt(i); \n\t\t\tif(cur==')' && st.isEmpty())\n\t\t\t\treturn false ; \n\t\t\telse if(cur==')' && !st.isEmpty())\n\t\t\t\tst.pop();\n\t\t\telse if(cur=='(')\n\t\t\t\tst.push(cur);\n\t\t}\n\t\tif(st.size()>0)return false ; else return true ;\n\t}\n\n\n\tpublic static int gcdExtended(int a, int b)\n\t{\n\t\t// Base Case\n\t\tif (a == 0)\n\t\t{\n\t\t\tx = 0;\n\t\t\ty = 1;\n\t\t\treturn b;\n\t\t}\n\n\t\t//int x1=1, y1=1; // To store results of recursive call\n\t\tint gcd = gcdExtended(b%a, a);\n\n\t\t// Update x and y using results of recursive\n\t\t// call\n\t\tlong x1 = y - (b/a) * x;\n\t\tlong y1 = x;\n\t\tx = x1 ; \n\t\ty = y1 ;\n\n\t\treturn gcd;\n\t}\n\n\n\n\n\n\n\n\n\n\tstatic int even(String x , int b )\n\t{\n\t\tfor (int j = b; j>=0; j--)\n\t\t{\n\t\t\tint current = x.charAt(j)-48 ; \n\t\t\tif(current%2==0)\n\t\t\t\treturn current ; \n\t\t}\n\t\treturn -1;\n\t}\n\tstatic int odd(String x , int b )\n\t{\n\t\tfor (int j = b; j>=0; j--)\n\t\t{\n\t\t\tint current = x.charAt(j)-48 ; \n\t\t\tif(current%2!=0)\n\t\t\t\treturn current ; \n\t\t}\n\t\treturn -1;\n\t}\n\tstatic long pow(long base, int exp) {\n\t\tlong res = 1;\n\t\twhile(exp > 0) {\n\t\t\tif(exp % 2 == 1) {\n\t\t\t\tres = (res * base) % mod;\n\t\t\t}\n\n\t\t\tbase = (base * base) % mod;\n\t\t\texp /= 2;\n\t\t}\n\n\t\treturn res;\n\t}\n\tpublic static long solve(int k1, long k2)\n\t{\n\t\tlong x = 1l*k2*(pow(2, k1)-1) ;\n\t\treturn x%(1000000007) ; \n\t}\n\n\n\tpublic static long getN(long x)\n\t{\n\t\tlong n = (long) Math.sqrt(x*2) ; \n\t\tlong y = n*(n+1)/2; \n\t\tif(y==x)\n\t\t\treturn n ; \n\t\telse if(y>x)\n\t\t\treturn n ; \n\t\telse\n\t\t\tfor (long i = n; ; i++)\n\t\t\t{\n\t\t\t\ty = i*(i+1)/2 ; \n\t\t\t\tif(y>=x)\n\t\t\t\t\treturn i ; \n\n\n\t\t\t}\t}\n\n\n\n\n\n\n\n\n\tpublic static void dfss(int root , int len)\n\t{\n\t\tvisited[root]=true ; \n\t\tif(ends[root] && root!=0) lens[root] = len ; \n\n\t\tfor (int i = 0; i < adj[root].size(); i++)\n\t\t{\n\t\t\tint c= (int) adj[root].get(i) ; \n\t\t\tif(visited[c]==false)\n\t\t\t\tdfss(c, len+1);\n\t\t}\n\t}\n\n\tpublic static void pr(int root , int seed){\n\t\tvisited[root] = true ;\n\t\tint dv = adj[root].size()-1 ; \n\t\tif(root==0) dv++ ;\n\n\t\tfor (int i = 0; i < adj[root].size(); i++)\n\t\t{\n\t\t\tint c = (int)adj[root].get(i) ; \n\t\t\tseeds[c]=dv*seed ;\n\t\t}\n\n\t\tfor (int i = 0; i < adj[root].size() ; i++)\n\t\t{\n\t\t\tint c = (int)adj[root].get(i) ; \n\t\t\tif(visited[c]==false)\n\t\t\t\tpr(c , seeds[c]);\n\n\t\t}\n\n\t}\n\n\n\tpublic static String concatinate(String s ,int n)\n\t{\n\t\tif(s.length()==n)\n\t\t\treturn s ; \n\t\telse return concatinate(\"0\"+s, 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\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\t}\n\n\n\tpublic static long getGCD(long n1, long n2) {\n\t\tif (n2 == 0) {\n\t\t\treturn n1;\n\t\t}\n\t\treturn getGCD(n2, n1 % n2);\n\t}\n\n\tpublic static int cnt1(int mat[][]) //how many swaps to be a 1 matrix\n\t{\n\t\tint m = mat.length ; \n\t\tint c=0 ; \n\t\tfor (int i = 0; i < mat.length; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < mat.length; j++)\n\t\t\t{\n\t\t\t\tint x = (i*m) +j ;\n\t\t\t\tif(x%2==0 && mat[i][j]==0)\n\t\t\t\t\tc++; \n\t\t\t\tif(x%2!=0 && mat[i][j]==1)\n\t\t\t\t\tc++; \n\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\tpublic static int cnt0(int mat[][])\n\t{\n\t\tint m = mat.length ; \n\t\tint c=0 ; \n\t\tfor (int i = 0; i < mat.length; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < mat.length; j++)\n\t\t\t{\n\t\t\t\tint x = (i*m) +j ; \n\t\t\t\tif(x%2!=0 && mat[i][j]==0)\n\t\t\t\t\tc++; \n\t\t\t\tif(x%2==0 && mat[i][j]==1)\n\t\t\t\t\tc++; \n\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tpublic static boolean canFit2(int x1, int y1 , int x2 , int y2 , int x3 , int y3){\n\t\tif(x1==x2)\n\t\t\tif(x1==x3)\n\t\t\t\treturn true ; \n\t\t\telse\n\t\t\t\treturn false ;\n\t\telse\n\t\t\tif(x1==x3)\n\t\t\t\treturn false ; \n\t\t\telse\n\t\t\t{\n\t\t\t\tlong a = 1l*(y2-y1)*(x3-x2) ; \n\t\t\t\tlong b = 1l*(y3-y2)*(x2-x1) ; \n\n\t\t\t\tif(a==b)\n\t\t\t\t\treturn true;\n\t\t\t\telse \n\t\t\t\t\treturn false ;\n\n\t\t\t}\n\n\t}\n\tpublic static void shuffle(pair[] ss){\n\t\tif(ss.length==1)\n\t\t\treturn ; \n\t\tfor (int i = 0; i < ss.length; i++)\n\t\t{\n\t\t\tRandom rand = new Random();\n\n\t\t\tint n = rand.nextInt(ss.length-1) + 0;\n\n\t\t\tpair temp = ss[i] ; \n\t\t\tss[i] = ss[n] ; \n\t\t\tss[n] = temp ;\n\t\t}\n\t}\n\tpublic static int binary(ArrayList arr, int l, int r, long x) /// begin by 0 and n-1\n\t{\n\t\tif (r>=l)\n\t\t{\n\t\t\tint mid = l + (r - l)/2;\n\t\t\tif (arr.get(mid).x== x)\n\t\t\t\treturn mid;\n\t\t\tif (arr.get(mid).x> x)\n\t\t\t\treturn binary(arr, l, mid-1, x);\n\t\t\treturn binary(arr, mid+1, r, x);\n\t\t}\n\t\treturn -1;\n\t}\n\n\t/// searching for the index of first elment greater than x\n\tpublic static int binary1(int[]arr , int x) {\n\t\tint low = 0, high = arr.length; // numElems is the size of the array i.e arr.size() \n\t\twhile (low != high) {\n\t\t\tint mid = (low + high) / 2; // Or a fancy way to avoid int overflow\n\t\t\tif (arr[mid] <= x) {\n\t\t\t\t/* This index, and everything below it, must not be the first element\n\t\t\t\t * greater than what we're looking for because this element is no greater\n\t\t\t\t * than the element.\n\t\t\t\t */\n\t\t\t\tlow = mid + 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t/* This element is at least as large as the element, so anything after it can't\n\t\t\t\t * be the first element that's at least as large.\n\t\t\t\t */\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t\treturn low ; // return high ; \n\t}\n\n\n\t////// searching for last element less than X \n\tpublic static int binary2(pair[]arr , int x) {\n\t\tint low = 0, high = arr.length; // numElems is the size of the array i.e arr.size() \n\t\twhile (low != high) {\n\t\t\tint mid = (low + high) / 2; // Or a fancy way to avoid int overflow\n\t\t\tif (arr[mid].x >= x) {\n\t\t\t\t/* This index, and everything below it, must not be the first element\n\t\t\t\t * greater than what we're looking for because this element is no greater\n\t\t\t\t * than the element.\n\t\t\t\t */\n\t\t\t\thigh=mid;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t/* This element is at least as large as the element, so anything after it can't\n\t\t\t\t * be the first element that's at least as large.\n\t\t\t\t */\n\t\t\t\tlow = mid+1 ; \n\t\t\t}\n\t\t}\n\t\treturn low ; // return high ; \n\t}\n\n\n\tprivate static boolean triangle(int a, int b , int c){\n\t\tif(a+b>c && a+c>b && b+c>a)\n\t\t\treturn true ; \n\t\telse \n\t\t\treturn false ;\n\t}\n\tprivate static boolean segment(int a, int b , int c){\n\t\tif(a+b==c || a+c==b && b+c==a)\n\t\t\treturn true ; \n\t\telse \n\t\t\treturn false ;\n\t}\n\tprivate static int gcdThing(long a, long b) {\n\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\tBigInteger gcd = b1.gcd(b2);\n\t\treturn gcd.intValue();\n\t}\n\n\tpublic static boolean is(int i){\n\t\tif(Math.log(i)/ Math.log(2) ==(int) (Math.log(i)/ Math.log(2)))\n\t\t\treturn true ; \n\t\tif(Math.log(i)/ Math.log(3) ==(int) (Math.log(i)/ Math.log(3)) )\n\t\t\treturn true ; \n\t\tif(Math.log(i)/ Math.log(6) ==(int) (Math.log(i)/ Math.log(6)) )\n\t\t\treturn true ; \n\n\t\treturn false;\n\n\t}\n\tpublic static boolean contains(int b[] , int x)\n\t{\n\t\tfor (int i = 0; i < b.length; i++)\n\t\t{\n\t\t\tif(b[i]==x)\n\t\t\t\treturn true ;\n\t\t}\n\t\treturn false ;\n\t}\n\tpublic static int binary(long []arr , long target , int low , long shift) {\n\t\tint high = arr.length; \n\t\twhile (low != high) {\n\t\t\tint mid = (low + high) / 2; \n\t\t\tif (arr[mid]-shift <= target) {\n\t\t\t\tlow = mid + 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t\treturn low ; // return high ; \n\t}\n\tpublic static boolean isLetter(char x){\n\t\tif(x+0 <=122 && x+0 >=97 )\n\t\t\treturn true ;\n\t\telse if (x+0 <=90 && x+0 >=65 )\n\t\t\treturn true ; \n\t\telse return false; \n\t}\n\tpublic static long getPrimes(long x ){\n\t\tif(x==2 || x==3 || x==1)\n\t\t\treturn 2 ;\n\t\tif(isPrime(x))\n\t\t\treturn 5 ;\n\t\tfor (int i = 2; i*i<=x; i++)\n\t\t{\n\t\t\tif(x%i==0 && isPrime(i))\n\t\t\t\treturn getPrimes(x/i) ;\n\t\t}\n\t\treturn -1;\n\t}\n\tpublic static String solve11(String x){\n\n\t\tint n = x.length() ; \n\t\tString y = \"\" ;\n\t\tfor (int i = 0; i < n-2; i+=2)\n\t\t{\n\t\t\tif(ifPalindrome(x.substring(i, i+2)))\n\t\t\t\ty+= x.substring(i, i+2) ;\n\t\t\telse \n\t\t\t\tbreak ;\n\t\t}\n\t\treturn y+ solve11(x.substring(y.length(),x.length())) ;\n\n\t}\n\tpublic static String solve1(String x){\n\t\tString y = x.substring(0 , x.length()/2) ; \n\t\treturn \"\" ;\n\n\t}\n\tpublic static String reverse(String x){\n\t\tString y =\"\" ;\n\t\tfor (int i = 0; i < x.length(); i++)\n\t\t{\n\t\t\ty = x.charAt(i) + y ;\n\t\t}\n\t\treturn y ;\n\t}\n\n\tpublic static boolean ifPalindrome(String x){\n\t\tint numbers[] = new int[10] ; \n\t\tfor (int i = 0; i < x.length(); i++)\n\t\t{\n\t\t\tint z = Integer.parseInt(x.charAt(i)+\"\") ; \n\t\t\tnumbers[z] ++ ;\n\t\t}\n\t\tfor (int i = 0; i < numbers.length; i++)\n\t\t{\n\t\t\tif(numbers[i]%2!=0)\n\t\t\t\treturn false; \n\t\t}\n\t\treturn true ;\t\n\t}\n\n\tpublic static int get(int n){\n\t\treturn n*(n+1)/2 ; \n\t}\n\t//\t\tpublic static long getSmallestDivisor( long y){\n\t//\t\t\tif(isPrime(y))\n\t//\t\t\t\treturn -1;\n\t//\n\t//\t\t\tfor (long i = 2; i*i <= y; i++)\n\t//\t\t\t{\n\t//\t\t\t\tif(y%i ==0)\n\t//\t\t\t\t{\n\t//\t\t\t\t\treturn i;\n\t//\t\t\t\t}\n\t//\t\t\t}\n\t//\t\t\treturn -1;\n\t//\t\t}\n\tpublic static int lis( int[]a , int n){\n\t\tint lis[] = new int[n] ; \n\t\tArrays.fill(lis,1) ; \n\n\t\tfor(int i=1;ia[j] && lis[i] < lis[j]+1) \n\t\t\t\t\tlis[i] = lis[j] + 1; \n\n\t\tint max = lis[0];\n\n\t\tfor(int i=1; i s = new ArrayList() ;\n\t\t//\t\t\tfor (int i = n-1; i >=0; i--)\n\t\t//\t\t\t{\n\t\t//\t\t\t\tif(lis[i]==max)\n\t\t//\t\t\t\t{\n\t\t//\t\t\t\t\ts.add(a[i].z);\n\t\t//\t\t\t\t\tmax --; \n\t\t//\t\t\t\t}\n\t\t//\t\t\t}\n\t\t//\n\t\t//\t\t\tfor (int i = s.size()-1 ; i>=0 ; i--)\n\t\t//\t\t\t{\n\t\t//\t\t\t\tSystem.out.print(s.get(i)+\" \");\n\t\t//\t\t\t}\n\t\t//\n\t}\n\tpublic static int calcDepth(Vertix node){\n\t\tif(node.depth>0) return node.depth; \n\t\t// meaning it has been updated before;\n\t\tif(node.parent != null)\n\t\t\treturn 1+ calcDepth(node.parent);\n\t\telse\n\t\t\treturn -1;\n\t}\n\n\tpublic static boolean isPrime (long num){\n\t\tif (num < 2) return false;\n\t\tif (num == 2) return true;\n\t\tif (num % 2 == 0) return false;\n\t\tfor (int i = 3; i * i <= num; i += 2)\n\t\t\tif (num % i == 0) return false;\n\t\treturn true;\n\t}\n\n\n\tpublic static ArrayList getDiv(Long n)\n\t{\n\t\tArrayList f = new ArrayList() ; \n\n\t\twhile (n%2==0)\n\t\t{\n\t\t\tif(!f.contains(2))f.add((long) 2) ;\n\t\t\tn /= 2;\n\t\t}\n\n\t\t// n must be odd at this point. So we can\n\t\t// skip one element (Note i = i +2)\n\t\tfor (long i = 3; i <= Math.sqrt(n); i+= 2)\n\t\t{\n\t\t\t// While i divides n, print i and divide n\n\t\t\twhile (n%i == 0)\n\t\t\t{\n\t\t\t\tif(!f.contains(i))f.add(i);\n\t\t\t\tn /= i;\n\t\t\t}\n\t\t}\n\n\t\t// This condition is to handle the case whien\n\t\t// n is a prime number greater than 2\n\t\tif (n > 2)\n\t\t\tif(!f.contains(n))f.add(n);\n\n\n\t\treturn f ;\n\n\n\n\t}\n\n\t//\t\tpublic static boolean dfs(Vertix v , int target){\n\t//\t\t\ttry{\n\t//\t\t\t\tvisited[v.i]= true ;\n\t//\t\t\t} catch (NullPointerException e)\n\t//\t\t\t{\n\t//\t\t\t\tSystem.out.println(v.i);\n\t//\t\t\t}\n\t//\t\t\tif(v.i == target)\n\t//\n\t//\t\t\t\treturn true ;\n\t//\t\t\tfor (int i =0 ; i< v.neighbours.size() ; i++)\n\t//\t\t\t{ \n\t//\n\t//\t\t\t\tVertix child = v.neighbours.get(i) ;\n\t//\t\t\t\tif(child.i == target){\n\t//\t\t\t\t\tfound = true ; \n\t//\t\t\t\t}\n\t//\t\t\t\tif(visited[child.i]==false){\n\t//\t\t\t\t\tfound |= dfs(child, target) ;\n\t//\t\t\t\t}\n\t//\t\t\t}\n\t//\t\t\treturn found; \n\t//\t\t}\n\n\n\n\n\n\n\n\n\n\tpublic static class Vertix{\n\t\tlong i ; \n\t\tint depth ;\n\t\tArrayList neighbours ; \n\t\tVertix parent ; \n\t\tVertix child ; \n\n\n\t\tpublic Vertix(long i){\n\t\t\tthis.i = i ;\n\t\t\tthis.neighbours = new ArrayList () ;\n\t\t\tthis.parent = null ;\n\t\t\tdepth =-1;\n\t\t\tthis.child = null ;\n\t\t}\n\t}\n\n\tpublic static class pair implements Comparable {\n\t\tint x ;\n\t\tint y ;\n\t\tint i;\n\n\n\n\n\t\tpublic pair(int x, int y, int i ){\n\n\t\t\tthis.x=x ; \n\t\t\tthis.y =y ;\n\t\t\tthis.i =i ;\n\n\n\t\t}\n\n\n\t\t@Override\n\t\tpublic int compareTo(pair p) {\n\t\t\tif(this.x > p.x)\n\t\t\t\treturn 1 ; \n\t\t\telse if (this.x == p.x) \n\t\t\t\treturn 0 ; \n\t\t\telse \n\t\t\t\treturn -1 ;\n\t\t}\n\n\n\n\n\t}\n\n\tpublic static class pair2 implements Comparable{\n\t\tint i ; \n\t\tint j ;\n\t\tint plus ;\n\n\t\tpublic pair2(int i , int j , int plus){\n\t\t\tthis.i =i ;\n\t\t\tthis.j = j ; \n\t\t\tthis.plus = plus ;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(pair2 p) {\n\t\t\tif(this.j > p.j)\n\t\t\t\treturn 1 ; \n\t\t\telse if (this.j == p.j) return 0 ;\n\t\t\telse \n\t\t\t\treturn -1 ;\n\t\t}\n\n\n\t}\n\tpublic static class point implements Comparable\n\t{\n\t\tint x, y ; \n\t\tpublic point(int x,int y){\n\t\t\tthis.x=x ; this.y=y;\n\t\t}\n\t\t@Override\n\t\tpublic boolean equals(Object o) {\n\n\t\t\t// If the object is compared with itself then return true \n\t\t\tif (o == this) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t/* Check if o is an instance of Complex or not\n\t \"null instanceof [type]\" also returns false */\n\t\t\tif (!(o instanceof point)) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// typecast o to Complex so that we can compare data members \n\t\t\tpoint c = (point) o;\n\n\t\t\t// Compare the data members and return accordingly \n\t\t\treturn Integer.compare(x, c.x) == 0\n\t\t\t\t\t&& Integer.compare(y, c.y) == 0;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(point p) {\n\t\t\tif(this.x == p.x && this.y ==p.y)\n\t\t\t\treturn 0 ; \n\t\t\telse\n\t\t\t\treturn -1 ; \n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode()\n\t\t{\n\t\t\treturn 15+x+(2%y) ;\n\t\t}\n\n\n\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1cd1dfb1c7ccf351178ad5486e562a9d", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\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 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 Exception {\n\n long time = System.currentTimeMillis();\n\n //int t = in.nextInt();\n int t = 1;\n while (t > 0) {\n solve();\n t--;\n }\n\n //System.err.println(System.currentTimeMillis() - time);\n\n out.flush();\n out.close();\n }\n\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.000000001;\n\n int n;\n int m;\n\n //ArrayList[] g = new ArrayList[200000];\n\n\n void solve() throws IOException {\n\n\n Pair[] s1 = new Pair[4];\n Pair[] s2 = new Pair[4];\n\n int lx = 100;\n int rx = -100;\n int ty = -100;\n int by = 100;\n\n\n for (int i = 0; i < 4; i++) {\n s1[i] = new Pair(in.nextInt(), in.nextInt());\n lx = Math.min(lx, s1[i].a);\n rx = Math.max(rx, s1[i].a);\n ty = Math.max(ty, s1[i].b);\n by = Math.min(by, s1[i].b);\n }\n\n int lx2 = 100;\n int rx2 = -100;\n int ty2 = -100;\n int by2 = 100;\n\n for (int i = 0; i < 4; i++) {\n s2[i] = new Pair(in.nextInt(), in.nextInt());\n lx2 = Math.min(lx2, s2[i].a);\n rx2 = Math.max(rx2, s2[i].a);\n ty2 = Math.max(ty2, s2[i].b);\n by2 = Math.min(by2, s2[i].b);\n }\n\n boolean cw = area(s2[0].a, s2[0].b, s2[1].a, s2[1].b, s2[2].a, s2[2].b) < 0;\n\n boolean inq = false;\n inq = lx2 <= lx && rx2 >= rx && ty2 >= ty(ty2+by2)/2 >= by && (ty2+by2)/2 <= ty && (lx2+rx2)/2 >= lx && (lx2+rx2)/2 <= rx;\n for (int i = 0; i < 4; i++) {\n\n int x = s2[i].a;\n int y = s2[i].b;\n inq |= x >= lx && x <= rx && y >= by && y <= ty;\n\n boolean all = true;\n for (int j = 0; j < 4; j++) {\n int area = area(s2[j].a, s2[j].b, s1[i].a, s1[i].b, s2[(j+1)%4].a, s2[(j+1)%4].b);\n if (cw) all &= area >= 0;\n else all &= area <= 0;\n }\n\n inq |= all;\n }\n\n if (inq)\n out.println(\"YES\");\n else\n out.println(\"NO\");\n\n }\n\n int area (int x1, int y1, int x2, int y2, int x3, int y3) {\n return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);\n }\n\n class Pair implements Comparable{\n\n int a;\n int b;\n\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 (b > p.b) return 1;\n if (b < p.b) 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\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 static class InputReader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public InputReader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public InputReader(String file_name) throws 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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "43c7efce4cd0ce82f0272e3cee652c43", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\r\n public class solution{\r\n public void minval(int n)\r\n {\r\n ArrayList aa=new ArrayList<>();\r\n int max=9;\r\n int res=0;\r\n while(n!=0){\r\n if(n>max){\r\n al.add(max);\r\n n-max=max;\r\n max--;\r\n }\r\n else{\r\n al.add(n);\r\n n=0;\r\n }\r\n \r\n }\r\n for(int i=al.size()-1;i>=0;i--){\r\n res=res*10+al.get(i);\r\n }\r\n System.out.println(res);\r\n }\r\n }\r\n public class mm{\r\n public static void main(String[] arg){\r\n Scanner sc=new Scanner(System.in);\r\n solution s=new solution();\r\n int t=sc.nextInt();\r\n while(j>0){\r\n int j=sc.nextInt();\r\n s.minval(j);\r\n j--;\r\n }\r\n }\r\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "db5e3c46142ba188aaea7bbabc673d6e", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f", "difficulty": 800} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.math.BigInteger;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) {\r\n new Thread(null, () -> new Main().run(), \"1\", 1 << 23).start();\r\n }\r\n\r\n private void run() {\r\n FastReader scan = new FastReader();\r\n PrintWriter out = new PrintWriter(System.out);\r\n Solution solve = new Solution();\r\n int t = scan.nextInt();\r\n //int t = 1;\r\n for (int qq = 0; qq < t; qq++) {\r\n solve.solve(scan, out);\r\n //out.println();\r\n }\r\n out.close();\r\n }\r\n}\r\n\r\nclass Solution {\r\n /*\r\n * think and coding\r\n */\r\n double EPS = 0.000_0001;\r\n\r\n public void solve(FastReader scan, PrintWriter out) {\r\n// int n = scan.nextInt(), H = scan.nextInt(), M = scan.nextInt();\r\n// int[][] arr = new int[n][2];\r\n// int min = 23456756, index = 0;\r\n// for (int i = 0; i < n; i++) {\r\n// arr[i][0] = scan.nextInt();\r\n// arr[i][1] = scan.nextInt();\r\n// if (min < minut(H, M, arr[i][0], arr[i][1])) {\r\n// min = minut(H, M, arr[i][0], arr[i][1]);\r\n// index = i;\r\n// }\r\n// }\r\n// out.println();\r\n int n = scan.nextInt();\r\n if (n < 10) {\r\n out.println(n);\r\n return;\r\n }\r\n int sum = 0;\r\n String s = \"\"\r\n for (int i = 9; i > 0 && sum < n; i--) {\r\n if (sum + i >= n) {\r\n i = n - sum;\r\n sum = n;\r\n } else {\r\n sum += i;\r\n }\r\n s += i + \"\";\r\n }\r\n for (int i = s.length() - 1; i >= 0; i--) {\r\n out.print(s.charAt(i));\r\n }\r\n out.println();\r\n }\r\n\r\n int minut(int h, int m, int h1, int m2) {\r\n if (m > m2) {\r\n m2 += 60;\r\n h1--;\r\n }\r\n return (h1 - h * 60) + m2 - m;\r\n }\r\n\r\n\r\n static class Pair implements Comparable {\r\n int a, b;\r\n\r\n public Pair(int a, int b) {\r\n this.a = a;\r\n this.b = b;\r\n }\r\n\r\n @Override\r\n public int compareTo(Pair p) {\r\n return Integer.compare(a, p.a);\r\n }\r\n }\r\n}\r\n\r\nclass FastReader {\r\n private final BufferedReader br;\r\n private StringTokenizer st;\r\n\r\n public FastReader() {\r\n br = new BufferedReader(new InputStreamReader(System.in));\r\n }\r\n\r\n public FastReader(String s) throws FileNotFoundException {\r\n br = new BufferedReader(new FileReader(new File(s)));\r\n }\r\n\r\n String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine() {\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8c6841e50860fed0cef46cc7d6f40ea3", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\r\n public class solution{\r\n public void minval(int n)\r\n {\r\n ArrayList al=new ArrayList<>();\r\n int max=9;\r\n int res=0;\r\n while(n!=0){\r\n if(n>max){\r\n al.add(max);\r\n n-=max;\r\n max--;\r\n }\r\n else{\r\n al.add(n);\r\n n=0;\r\n }\r\n \r\n }\r\n for(int i=al.size()-1;i>=0;i--){\r\n res=res*10+al.get(i);\r\n }\r\n System.out.println(res);\r\n }\r\n }\r\n public class mm{\r\n public static void main(String[] arg){\r\n Scanner sc=new Scanner(System.in);\r\n solution s=new solution();\r\n int t=sc.nextInt();\r\n while(t>0){\r\n int j=sc.nextInt();\r\n s.minval(j);\r\n j--;\r\n }\r\n }\r\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2bd38f7cc3252fd034d3abf1a599be61", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f", "difficulty": 800} {"lang": "Java 11", "source_code": "import java.util.Scanner;\r\n\r\npublic class ProblemC {\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 result = solve(sc.nextInt());\r\n System.out.println(result);\r\n }\r\n sc.close();\r\n }\r\n\r\n private static int solve(int num) {\r\n StringBuilder sb = new StringBuilder();\r\n for (int j = 9; j >=1; j--) {\r\n if(num==0){\r\n break;\r\n }\r\n if(j<=num){\r\n sb.append(j);\r\n num -=j;\r\n }\r\n }\r\n return Integer.parseInt(sb.reverse().toString());\r\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "19e2d21562a5b748dcf27083789fd099", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class geeks \n{\n\tpublic static void main(String[] args) \n\t{\n Scanner sc = new Scanner(System.in);\n String m = sc.next();\n int t =0;\n int q = sc.nextInt();\n if(m == 'January')\n {\n t=1;\n }\n else if(m == 'Feburary')\n {\n t =2;\n }\n else if(m == 'March')\n {\n t =3;\n }\n else if(m == 'April')\n {\n t =4;\n }\n else if(m == 'May')\n {\n t =5;\n }\n else if(m == 'June')\n {\n t =6;\n }\n else if(m == 'July')\n {\n t =7;\n }\n else if(m == 'August')\n {\n t =8;\n }\n else if(m == 'September')\n {\n t =9;\n }\n else if(m == 'October')\n {\n t =10;\n }\n else if(m == 'November')\n {\n t =11;\n }\n else if(m == 'December')\n {\n t =12;\n }\n t =t +q;\n t = t%12;\n if (t==0)\n {\n System.out.println(\"December\");\n }\n else if(t==1)\n {\n System.out.println(\"January\");\n }\n else if(t==2)\n {\n System.out.println(\"Feburary\");\n }\n else if(t==3)\n {\n System.out.println(\"March\");\n }\n else if(t==3)\n {\n System.out.println(\"April\");\n }\n else if(t==4)\n {\n System.out.println(\"May\");\n }\n else if(t==5)\n {\n System.out.println(\"June\");\n }\n else if(t==6)\n {\n System.out.println(\"July\");\n }\n else if(t==7)\n {\n System.out.println(\"August\");\n }\n else if(t==8)\n {\n System.out.println(\"September\");\n }\n else if(t==9)\n {\n System.out.println(\"October\");\n }\n else if(t==10)\n {\n System.out.println(\"November\");\n }\n else if(t==11)\n {\n System.out.println(\"December\");\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "88ff1d2fd478097309272b21947fe6f9", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class geeks \n{\n\tpublic static void main(String[] args) \n\t{\n Scanner sc = new Scanner(System.in);\n String m = sc.next();\n int t =0;\n int q = sc.nextInt();\n if(m.compareTo(\"January\")==0)\n {\n t=1;\n }\n else if(m.compareTo(\"February\")==0)\n {\n t =2;\n }\n else if(m.compareTo(\"March\")==0)\n {\n t =3;\n }\n else if(m.compareTo(\"April\")==0)\n {\n t =4;\n }\n else if(m.compareTo(\"May\")==0)\n {\n t =5;\n }\n else if(m.compareTo(\"June\")==0)\n {\n t =6;\n }\n else if(m.compareTo(\"July\")==0)\n {\n t =7;\n }\n else if(m.compareTo(\"August\")==0)\n {\n t =8;\n }\n else if(m.compareTo(\"September\")==0)\n {\n t =9;\n }\n else if(m.compareTo(\"October\")==0)\n {\n t =10;\n }\n else if(m.compareTo(\"November\")==0)\n {\n t =11;\n }\n else if(m.compareTo(\"December\")==0)\n {\n t =12;\n }\n t =t +q;\n t = t%12;\n if (t==0)\n {\n System.out.println(\"December\");\n }\n else if(t==1)\n {\n System.out.println(\"January\");\n }\n else if(t==2)\n {\n System.out.println(\"February\");\n }\n else if(t==3)\n {\n System.out.println(\"March\");\n }\n else if(t==4)\n {\n System.out.println(\"April\");\n }\n else if(t==5)\n {\n System.out.println(\"May\");\n }\n else if(t==6)\n {\n System.out.println(\"June\");\n }\n else if(t==7)\n {\n System.out.println(\"July\");\n }\n else if(t==8)\n {\n System.out.println(\"August\");\n }\n else if(t==9)\n {\n System.out.println(\"September\");\n }\n else if(t==10)\n {\n System.out.println(\"October\");\n }\n else if(t==11)\n {\n System.out.println(\"November\");\n }\n sc.close;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "07c01d34377ba3bfa2b618dea89eba7e", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class geeks \n{\n\tpublic static void main(String[] args) \n\t{\n Scanner sc = new Scanner(System.in);\n String m = sc.next();\n int t =0;\n int q = sc.nextInt();\n if(m == \"January\")\n {\n t=1;\n }\n else if(m == 'Feburary')\n {\n t =2;\n }\n else if(m == 'March')\n {\n t =3;\n }\n else if(m == 'April')\n {\n t =4;\n }\n else if(m == 'May')\n {\n t =5;\n }\n else if(m == 'June')\n {\n t =6;\n }\n else if(m == 'July')\n {\n t =7;\n }\n else if(m == 'August')\n {\n t =8;\n }\n else if(m == 'September')\n {\n t =9;\n }\n else if(m == 'October')\n {\n t =10;\n }\n else if(m == 'November')\n {\n t =11;\n }\n else if(m == 'December')\n {\n t =12;\n }\n t =t +q;\n t = t%12;\n if (t==0)\n {\n System.out.println(\"December\");\n }\n else if(t==1)\n {\n System.out.println(\"January\");\n }\n else if(t==2)\n {\n System.out.println(\"Feburary\");\n }\n else if(t==3)\n {\n System.out.println(\"March\");\n }\n else if(t==3)\n {\n System.out.println(\"April\");\n }\n else if(t==4)\n {\n System.out.println(\"May\");\n }\n else if(t==5)\n {\n System.out.println(\"June\");\n }\n else if(t==6)\n {\n System.out.println(\"July\");\n }\n else if(t==7)\n {\n System.out.println(\"August\");\n }\n else if(t==8)\n {\n System.out.println(\"September\");\n }\n else if(t==9)\n {\n System.out.println(\"October\");\n }\n else if(t==10)\n {\n System.out.println(\"November\");\n }\n else if(t==11)\n {\n System.out.println(\"December\");\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "856c9d8ce6a49073d921e5d9102e7e26", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class file{\npublic static void main(String[] args){\nScanner scan=new Scanner(System.in);\nString str=scan.nextLine();\nint a=scan.nextInt();\nHashMap map=new HashMap<>();\nmap.put(\"JANUARY\",1);\nmap.put(\"FEBRUARY\",2);\nmap.put(\"MARCH\",3);\nmap.put(\"APRIL\",4);\nmap.put(\"MAY\",5);\nmap.put(\"JUNE\",6);\nmap.put(\"JULY\",7);\nmap.put(\"AUGUST\",8);\nmap.put(\"SEPTEMBER\",9);\nmap.put(\"OCTOBER\",10);\nmap.put(\"NOVEMBER\",11);\nmap.put(\"DECEMBER\",0);\nSystem.out.println(map.getKey(map.get(str)+a-1)%12);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b27d05ba6d88495d122d3aac2fb67a14", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main implements Runnable {\n\n public static void main(String[] args) {\n new Thread(null, new Main(), \"\", 128 * 1024 * 1024).start();\n }\n\n public void run() {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int digits = ((n / 5) + \"\").length();\n\n int count = 0;\n for (int idx1 = 1, idx2 = 2; idx2 <= n && idx1 < idx2; ) {\n if ((idx1 + idx2) % getTen(digits) == getNine(digits)) {\n count++;\n idx1++;\n if (idx1 + 1 < idx2) {\n idx2--;\n } else {\n idx2++;\n }\n } else if (idx2 < n) {\n idx2++;\n } else {\n idx1++;\n }\n }\n System.out.println(count);\n }\n\n private int getTen(int digits) {\n StringBuilder sb = new StringBuilder(\"1\");\n for (int i = 0; i < digits; i++) {\n sb.append(\"0\");\n }\n return Integer.parseInt(sb.toString());\n }\n\n private int getNine(int digits) {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < digits; i++) {\n sb.append(\"9\");\n }\n return Integer.parseInt(sb.toString());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "713d68b2b3e9acd9e8f0527c337bcc62", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.function.BiConsumer;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\n\npublic class D_452\n{\n\tpublic static final long[] POWER2 = generatePOWER2();\n\tpublic static final IteratorBuffer ITERATOR_BUFFER_PRIME = new IteratorBuffer<>(streamPrime(1000000).iterator());\n\tprivate static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static StringTokenizer stringTokenizer = null;\n\tprivate static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tinterface BiFunctionResult\n\t{\n\t\tTypeResult apply(Type0 x0, Type1 x1, TypeResult x2);\n\t}\n\n\tstatic class Array implements Iterable\n\t{\n\t\tprivate final Object[] array;\n\n\t\tpublic Array(int size)\n\t\t{\n\t\t\tthis.array = new Object[size];\n\t\t}\n\n\t\tpublic Array(int size, Type element)\n\t\t{\n\t\t\tthis(size);\n\t\t\tArrays.fill(this.array, element);\n\t\t}\n\n\t\tpublic Array(Array array, Type element)\n\t\t{\n\t\t\tthis(array.size() + 1);\n\t\t\tfor (int index = 0; index < array.size(); index++)\n\t\t\t{\n\t\t\t\tset(index, array.get(index));\n\t\t\t}\n\t\t\tset(size() - 1, element);\n\t\t}\n\n\t\tpublic Array(List list)\n\t\t{\n\t\t\tthis(list.size());\n\t\t\tint index = 0;\n\t\t\tfor (Type element : list)\n\t\t\t{\n\t\t\t\tset(index, element);\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic Type get(int index)\n\t\t{\n\t\t\treturn (Type) this.array[index];\n\t\t}\n\n\t\tpublic Array set(int index, Type value)\n\t\t{\n\t\t\tthis.array[index] = value;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.array.length;\n\t\t}\n\n\t\tpublic List toList()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Type element : this)\n\t\t\t{\n\t\t\t\tresult.add(element);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tType result = Array.this.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"[\" + D_452.toString(this, \", \") + \"]\";\n\t\t}\n\t}\n\n\tstatic class BIT\n\t{\n\t\tprivate static int lastBit(int index)\n\t\t{\n\t\t\treturn index & -index;\n\t\t}\n\n\t\tprivate final long[] tree;\n\n\t\tpublic BIT(int size)\n\t\t{\n\t\t\tthis.tree = new long[size];\n\t\t}\n\n\t\tpublic void add(int index, long delta)\n\t\t{\n\t\t\tindex += 1;\n\t\t\twhile (index <= this.tree.length)\n\t\t\t{\n\t\t\t\ttree[index - 1] += delta;\n\t\t\t\tindex += lastBit(index);\n\t\t\t}\n\t\t}\n\n\t\tprivate long prefix(int end)\n\t\t{\n\t\t\tlong result = 0;\n\t\t\twhile (end > 0)\n\t\t\t{\n\t\t\t\tresult += this.tree[end - 1];\n\t\t\t\tend -= lastBit(end);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.tree.length;\n\t\t}\n\n\t\tpublic long sum(int start, int end)\n\t\t{\n\t\t\treturn prefix(end) - prefix(start);\n\t\t}\n\t}\n\n\tstatic abstract class Edge, TypeEdge extends Edge>\n\t{\n\t\tpublic final TypeVertex vertex0;\n\t\tpublic final TypeVertex vertex1;\n\t\tpublic final boolean bidirectional;\n\n\t\tpublic Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tthis.vertex0 = vertex0;\n\t\t\tthis.vertex1 = vertex1;\n\t\t\tthis.bidirectional = bidirectional;\n\t\t\tthis.vertex0.edges.add(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.add(getThis());\n\t\t\t}\n\t\t}\n\n\t\tpublic TypeVertex other(Vertex vertex)\n\t\t{\n\t\t\tTypeVertex result;\n\t\t\tif (vertex0 == vertex)\n\t\t\t{\n\t\t\t\tresult = vertex1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = vertex0;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic abstract TypeEdge getThis();\n\n\t\tpublic void remove()\n\t\t{\n\t\t\tthis.vertex0.edges.remove(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.remove(getThis());\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.vertex0 + \"->\" + this.vertex1;\n\t\t}\n\t}\n\n\tpublic static class EdgeDefault>> extends Edge>\n\t{\n\t\tpublic EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Vertex, TypeEdge extends Edge> implements Comparable>\n\t{\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiConsumer functionPreVisit,\n\t\t\t\tBiConsumer functionInVisit,\n\t\t\t\tBiConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tTypeVertex vertexTo;\n\t\t\tTypeEdge edgeTo;\n\t\t\tboolean[] isOnStack = new boolean[vertices.size()];\n\t\t\tStack stackOperations = new Stack<>();\n\t\t\tStack stackVertices = new Stack<>();\n\t\t\tStack stackEdges = new Stack<>();\n\n\t\t\tTypeVertex vertexStart = vertices.get(indexVertexStart);\n\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\tstackVertices.push(vertexStart);\n\t\t\tstackEdges.push(null);\n\t\t\tisOnStack[vertexStart.index] = true;\n\t\t\twhile (!stackOperations.isEmpty())\n\t\t\t{\n\t\t\t\tOperation operation = stackOperations.pop();\n\t\t\t\tTypeVertex vertex = stackVertices.pop();\n\t\t\t\tTypeEdge edge = stackEdges.pop();\n\t\t\t\tswitch (operation)\n\t\t\t\t{\n\t\t\t\t\tcase INVISIT:\n\t\t\t\t\t\tfunctionInVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase POSTVISIT:\n\t\t\t\t\t\tfunctionPostVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase EXPAND:\n\t\t\t\t\t\tstackOperations.push(Operation.POSTVISIT);\n\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\tInteger indexTo = null;\n\t\t\t\t\t\tfor (int index = 0; indexTo == null && index < vertex.edges.size(); index++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tindexTo = index;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (indexTo != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(indexTo);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\tfor (int index = indexTo + 1; index < vertex.edges.size(); index++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.INVISIT);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfunctionPreVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tConsumer functionPreVisit,\n\t\t\t\tConsumer functionInVisit,\n\t\t\t\tConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tdepthFirstSearch(\n\t\t\t\t\tvertices,\n\t\t\t\t\tindexVertexStart,\n\t\t\t\t\t(vertex, edge) -> functionPreVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionInVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionPostVisit.accept(vertex)\n\t\t\t);\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tTypeVertex vertex,\n\t\t\t\tTypeEdge edge,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tArray visited,\n\t\t\t\tFIFO verticesNext,\n\t\t\t\tFIFO edgesNext,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tif (!visited.get(vertex.index))\n\t\t\t{\n\t\t\t\tvisited.set(vertex.index, true);\n\t\t\t\tresult = function.apply(vertex, edge, result);\n\t\t\t\tfor (TypeEdge edgeNext : vertex.edges)\n\t\t\t\t{\n\t\t\t\t\tTypeVertex vertexNext = edgeNext.other(vertex);\n\t\t\t\t\tif (!visited.get(vertexNext.index))\n\t\t\t\t\t{\n\t\t\t\t\t\tverticesNext.push(vertexNext);\n\t\t\t\t\t\tedgesNext.push(edgeNext);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tArray visited = new Array<>(vertices.size(), false);\n\t\t\tFIFO verticesNext = new FIFO<>();\n\t\t\tverticesNext.push(vertices.get(indexVertexStart));\n\t\t\tFIFO edgesNext = new FIFO<>();\n\t\t\tedgesNext.push(null);\n\t\t\twhile (!verticesNext.isEmpty())\n\t\t\t{\n\t\t\t\tresult = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic final int index;\n\t\tpublic final List edges;\n\n\t\tpublic Vertex(int index)\n\t\t{\n\t\t\tthis.index = index;\n\t\t\tthis.edges = new ArrayList<>();\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Vertex that)\n\t\t{\n\t\t\treturn Integer.compare(this.index, that.index);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"\" + this.index;\n\t\t}\n\n\t\tenum Operation\n\t\t{\n\t\t\tINVISIT, POSTVISIT, EXPAND\n\t\t}\n\t}\n\n\tpublic static class VertexDefault, TypeEdge>> extends Vertex, TypeEdge>\n\t{\n\t\tpublic VertexDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class VertexDefaultDefault extends Vertex\n\t{\n\t\tpublic static Array vertices(int n)\n\t\t{\n\t\t\tArray result = new Array<>(n);\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult.set(index, new VertexDefaultDefault(index));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic VertexDefaultDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class EdgeDefaultDefault extends Edge\n\t{\n\t\tpublic EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefaultDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Tuple2\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\n\t\tpublic Tuple2(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \")\";\n\t\t}\n\t}\n\n\tstatic class Wrapper\n\t{\n\t\tpublic Type value;\n\n\t\tpublic Wrapper(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\tpublic Type get()\n\t\t{\n\t\t\treturn this.value;\n\t\t}\n\n\t\tpublic void set(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.value.toString();\n\t\t}\n\t}\n\n\tpublic static class Tuple3\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\t\tpublic final Type2 v2;\n\n\t\tpublic Tuple3(Type0 v0, Type1 v1, Type2 v2)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t\tthis.v2 = v2;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \", \" + this.v2 + \")\";\n\t\t}\n\t}\n\n\tpublic static class Tuple2Comparable, Type1 extends Comparable> extends Tuple2 implements Comparable>\n\t{\n\t\tpublic Tuple2Comparable(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tsuper(v0, v1);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Tuple2Comparable that)\n\t\t{\n\t\t\tint result = this.v0.compareTo(that.v0);\n\t\t\tif (result == 0)\n\t\t\t{\n\t\t\t\tresult = this.v1.compareTo(that.v1);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tpublic static class SingleLinkedList\n\t{\n\t\tpublic final Type element;\n\t\tpublic SingleLinkedList next;\n\n\t\tpublic SingleLinkedList(Type element, SingleLinkedList next)\n\t\t{\n\t\t\tthis.element = element;\n\t\t\tthis.next = next;\n\t\t}\n\n\t\tpublic void toCollection(Collection collection)\n\t\t{\n\t\t\tif (this.next != null)\n\t\t\t{\n\t\t\t\tthis.next.toCollection(collection);\n\t\t\t}\n\t\t\tcollection.add(this.element);\n\t\t}\n\t}\n\n\tpublic static class Node\n\t{\n\t\tpublic static Node balance(Node result)\n\t\t{\n\t\t\twhile (result != null && 1 < Math.abs(height(result.left) - height(result.right)))\n\t\t\t{\n\t\t\t\tif (height(result.left) < height(result.right))\n\t\t\t\t{\n\t\t\t\t\tNode right = result.right;\n\t\t\t\t\tif (height(right.right) < height(right.left))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, result.left, right.rotateRight());\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateLeft();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tNode left = result.left;\n\t\t\t\t\tif (height(left.left) < height(left.right))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, left.rotateLeft(), result.right);\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateRight();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node clone(Node result)\n\t\t{\n\t\t\tif (result != null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(result.value, clone(result.left), clone(result.right));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node delete(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tif (node.left == null)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = node.right;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (node.right == null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult = node.left;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tNode first = first(node.right);\n\t\t\t\t\t\t\tresult = new Node<>(first.value, node.left, delete(node.right, first.value, comparator));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, delete(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, delete(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node first(Node result)\n\t\t{\n\t\t\twhile (result.left != null)\n\t\t\t{\n\t\t\t\tresult = result.left;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node get(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node head(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node.left;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = head(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, head(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int height(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.height;\n\t\t}\n\n\t\tpublic static Node insert(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(value, null, null);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(value, node.left, node.right);\n\t\t\t\t\t;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, insert(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, insert(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node last(Node result)\n\t\t{\n\t\t\twhile (result.right != null)\n\t\t\t{\n\t\t\t\tresult = result.right;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int size(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.size;\n\t\t}\n\n\t\tpublic static Node tail(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(node.value, null, node.right);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, tail(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = tail(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static void traverseOrderIn(Node node, Consumer consumer)\n\t\t{\n\t\t\tif (node != null)\n\t\t\t{\n\t\t\t\ttraverseOrderIn(node.left, consumer);\n\t\t\t\tconsumer.accept(node.value);\n\t\t\t\ttraverseOrderIn(node.right, consumer);\n\t\t\t}\n\t\t}\n\n\t\tpublic final Type value;\n\t\tpublic final Node left;\n\t\tpublic final Node right;\n\t\tpublic final int size;\n\t\tprivate final int height;\n\n\t\tpublic Node(Type value, Node left, Node right)\n\t\t{\n\t\t\tthis.value = value;\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t\tthis.size = 1 + size(left) + size(right);\n\t\t\tthis.height = 1 + Math.max(height(left), height(right));\n\t\t}\n\n\t\tpublic Node rotateLeft()\n\t\t{\n\t\t\tNode left = new Node<>(this.value, this.left, this.right.left);\n\t\t\treturn new Node<>(this.right.value, left, this.right.right);\n\t\t}\n\n\t\tpublic Node rotateRight()\n\t\t{\n\t\t\tNode right = new Node<>(this.value, this.left.right, this.right);\n\t\t\treturn new Node<>(this.left.value, this.left.left, right);\n\t\t}\n\t}\n\n\tpublic static class SortedSetAVL implements SortedSet\n\t{\n\t\tpublic Comparator comparator;\n\t\tpublic Node root;\n\n\t\tprivate SortedSetAVL(Comparator comparator, Node root)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.root = root;\n\t\t}\n\n\t\tpublic SortedSetAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t}\n\n\t\tpublic SortedSetAVL(Collection collection, Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t\tthis.addAll(collection);\n\t\t}\n\n\t\tpublic SortedSetAVL(SortedSetAVL sortedSetAVL)\n\t\t{\n\t\t\tthis(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.root = null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\tpublic Type get(Type value)\n\t\t{\n\t\t\tNode node = Node.get(this.root, value, this.comparator);\n\t\t\treturn node == null ? null : node.value;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL subSet(Type valueStart, Type valueEnd)\n\t\t{\n\t\t\treturn tailSet(valueStart).headSet(valueEnd);\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL headSet(Type valueEnd)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL tailSet(Type valueStart)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic Type first()\n\t\t{\n\t\t\treturn Node.first(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic Type last()\n\t\t{\n\t\t\treturn Node.last(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.root == null ? 0 : this.root.size;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.root == null;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean contains(Object value)\n\t\t{\n\t\t\treturn Node.get(this.root, (Type) value, this.comparator) != null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\tStack> path = new Stack<>();\n\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\t{\n\t\t\t\t\tpush(SortedSetAVL.this.root);\n\t\t\t\t}\n\n\t\t\t\tpublic void push(Node node)\n\t\t\t\t{\n\t\t\t\t\twhile (node != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tpath.push(node);\n\t\t\t\t\t\tnode = node.left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn !path.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (path.isEmpty())\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tNode node = path.peek();\n\t\t\t\t\t\tType result = node.value;\n\t\t\t\t\t\tif (node.right != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpush(node.right);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tnode = path.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twhile (!path.isEmpty() && path.peek().right == node);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic Object[] toArray()\n\t\t{\n\t\t\treturn toArray(new Object[0]);\n\t\t}\n\n\t\t@Override\n\t\tpublic T[] toArray(T[] ts)\n\t\t{\n\t\t\tList list = new ArrayList<>();\n\t\t\tNode.traverseOrderIn(this.root, list::add);\n\t\t\treturn list.toArray(ts);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean add(Type value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.insert(this.root, value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean remove(Object value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.delete(this.root, (Type) value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.allMatch(this::contains);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean addAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::add)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean retainAll(Collection collection)\n\t\t{\n\t\t\tSortedSetAVL set = new SortedSetAVL<>(this.comparator);\n\t\t\tcollection.stream()\n\t\t\t\t\t.map(element -> (Type) element)\n\t\t\t\t\t.filter(this::contains)\n\t\t\t\t\t.forEach(set::add);\n\t\t\tboolean result = size() != set.size();\n\t\t\tthis.root = set.root;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean removeAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::remove)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"{\" + D_452.toString(this, \", \") + \"}\";\n\t\t}\n\t}\n\n\tpublic static class SortedMapAVL implements SortedMap\n\t{\n\t\tpublic final Comparator comparator;\n\t\tpublic final SortedSetAVL> entrySet;\n\n\t\tpublic SortedMapAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey())));\n\t\t}\n\n\t\tprivate SortedMapAVL(Comparator comparator, SortedSetAVL> entrySet)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.entrySet = entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(TypeKey keyStart, TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)));\n\t\t}\n\n\t\tpublic Entry firstEntry()\n\t\t{\n\t\t\treturn this.entrySet.first();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey firstKey()\n\t\t{\n\t\t\treturn firstEntry().getKey();\n\t\t}\n\n\t\tpublic Entry lastEntry()\n\t\t{\n\t\t\treturn this.entrySet.last();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey lastKey()\n\t\t{\n\t\t\treturn lastEntry().getKey();\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.entrySet().size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.entrySet.isEmpty();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsKey(Object key)\n\t\t{\n\t\t\treturn this.entrySet().contains(new AbstractMap.SimpleEntry<>((TypeKey) key, null));\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsValue(Object value)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue get(Object key)\n\t\t{\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tentry = this.entrySet.get(entry);\n\t\t\treturn entry == null ? null : entry.getValue();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue put(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>(key, value);\n\t\t\tthis.entrySet().add(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue remove(Object key)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tthis.entrySet.remove(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tmap.entrySet()\n\t\t\t\t\t.forEach(entry -> put(entry.getKey(), entry.getValue()));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.entrySet.clear();\n\t\t}\n\n\t\t@Override\n\t\tpublic Set keySet()\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Collection values()\n\t\t{\n\t\t\treturn new Collection()\n\t\t\t{\n\t\t\t\t@Override\n\t\t\t\tpublic int size()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean isEmpty()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean contains(Object value)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Iterator iterator()\n\t\t\t\t{\n\t\t\t\t\treturn new Iterator()\n\t\t\t\t\t{\n\t\t\t\t\t\tIterator> iterator = SortedMapAVL.this.entrySet.iterator();\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic boolean hasNext()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.hasNext();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic TypeValue next()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.next().getValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Object[] toArray()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic T[] toArray(T[] ts)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean add(TypeValue typeValue)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean remove(Object o)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean containsAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean addAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean removeAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean retainAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic void clear()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL> entrySet()\n\t\t{\n\t\t\treturn this.entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.entrySet().toString();\n\t\t}\n\t}\n\n\tpublic static class FIFO\n\t{\n\t\tpublic SingleLinkedList start;\n\t\tpublic SingleLinkedList end;\n\n\t\tpublic FIFO()\n\t\t{\n\t\t\tthis.start = null;\n\t\t\tthis.end = null;\n\t\t}\n\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.start == null;\n\t\t}\n\n\t\tpublic Type peek()\n\t\t{\n\t\t\treturn this.start.element;\n\t\t}\n\n\t\tpublic Type pop()\n\t\t{\n\t\t\tType result = this.start.element;\n\t\t\tthis.start = this.start.next;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic void push(Type element)\n\t\t{\n\t\t\tSingleLinkedList list = new SingleLinkedList<>(element, null);\n\t\t\tif (this.start == null)\n\t\t\t{\n\t\t\t\tthis.start = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthis.end.next = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class MapCount extends SortedMapAVL\n\t{\n\t\tprivate int count;\n\n\t\tpublic MapCount(Comparator comparator)\n\t\t{\n\t\t\tsuper(comparator);\n\t\t\tthis.count = 0;\n\t\t}\n\n\t\tpublic long add(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key);\n\t\t\t\tif (value == null)\n\t\t\t\t{\n\t\t\t\t\tvalue = delta;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvalue += delta;\n\t\t\t\t}\n\t\t\t\tput(key, value);\n\t\t\t\tresult = delta;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count += result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int count()\n\t\t{\n\t\t\treturn this.count;\n\t\t}\n\n\t\tpublic List flatten()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Entry entry : entrySet())\n\t\t\t{\n\t\t\t\tfor (long index = 0; index < entry.getValue(); index++)\n\t\t\t\t{\n\t\t\t\t\tresult.add(entry.getKey());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Long remove(Object key)\n\t\t{\n\t\t\tLong result = super.remove(key);\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic long remove(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key) - delta;\n\t\t\t\tif (value <= 0)\n\t\t\t\t{\n\t\t\t\t\tresult = delta + value;\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult = delta;\n\t\t\t\t\tput(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(Type keyStart, Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(Type keyStart)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\t}\n\n\tpublic static class MapSet extends SortedMapAVL> implements Iterable\n\t{\n\t\tprivate Comparator comparatorValue;\n\n\t\tpublic MapSet(Comparator comparatorKey, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic MapSet(Comparator comparatorKey, SortedSetAVL>> entrySet, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey, entrySet);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic TypeValue firstValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> firstEntry = firstEntry();\n\t\t\tif (firstEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = firstEntry.getValue().first();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tIterator> iteratorValues = values().iterator();\n\t\t\t\tIterator iteratorValue = null;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext());\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic TypeValue next()\n\t\t\t\t{\n\t\t\t\t\tif (iteratorValue == null || !iteratorValue.hasNext())\n\t\t\t\t\t{\n\t\t\t\t\t\titeratorValue = iteratorValues.next().iterator();\n\t\t\t\t\t}\n\t\t\t\t\treturn iteratorValue.next();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tpublic TypeValue lastValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> lastEntry = lastEntry();\n\t\t\tif (lastEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = lastEntry.getValue().last();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic boolean add(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tSortedSetAVL set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue));\n\t\t\treturn set.add(value);\n\t\t}\n\n\t\tpublic boolean removeSet(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tboolean result;\n\t\t\tSortedSetAVL set = get(key);\n\t\t\tif (set == null)\n\t\t\t{\n\t\t\t\tresult = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = set.remove(value);\n\t\t\t\tif (set.size() == 0)\n\t\t\t\t{\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue);\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue);\n\t\t}\n\t}\n\n\tstatic class IteratorBuffer\n\t{\n\t\tprivate Iterator iterator;\n\t\tprivate List list;\n\n\t\tpublic IteratorBuffer(Iterator iterator)\n\t\t{\n\t\t\tthis.iterator = iterator;\n\t\t\tthis.list = new ArrayList();\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < list.size() || iterator().hasNext();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (list.size() <= this.index)\n\t\t\t\t\t{\n\t\t\t\t\t\tlist.add(iterator.next());\n\t\t\t\t\t}\n\t\t\t\t\tType result = list.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t}\n\n\tpublic static class Tree2D\n\t{\n\t\tpublic static final int SIZE = 1 << 30;\n\t\tpublic static final Tree2D[] TREES_NULL = new Tree2D[]{null, null, null, null};\n\n\t\tpublic static int quadrantLeft(int left, int size, int index)\n\t\t{\n\t\t\treturn left + (index & 1) * size;\n\t\t}\n\n\t\tpublic static int quadrantBottom(int bottom, int size, int index)\n\t\t{\n\t\t\treturn bottom + (index >> 1) * size;\n\t\t}\n\n\t\tpublic static boolean contains(int x, int y, int left, int bottom, int size)\n\t\t{\n\t\t\treturn left <= x && x < left + size && bottom <= y && y < bottom + size;\n\t\t}\n\n\t\tpublic static int count(Tree2D[] trees)\n\t\t{\n\t\t\tint result = 0;\n\t\t\tfor (int index = 0; index < 4; index++)\n\t\t\t{\n\t\t\t\tif (trees[index] != null)\n\t\t\t\t{\n\t\t\t\t\tresult += trees[index].count;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic final Tree2D[] trees;\n\t\tpublic final int count;\n\n\t\tprivate Tree2D(Tree2D[] trees, int count)\n\t\t{\n\t\t\tthis.trees = trees;\n\t\t\tthis.count = count;\n\t\t}\n\n\t\tpublic Tree2D(Tree2D[] trees)\n\t\t{\n\t\t\tthis(trees, count(trees));\n\t\t}\n\n\t\tpublic Tree2D()\n\t\t{\n\t\t\tthis(TREES_NULL);\n\t\t}\n\n\t\tpublic static int count\n\t\t\t\t(\n\t\t\t\t\t\tint rectangleLeft,\n\t\t\t\t\t\tint rectangleBottom,\n\t\t\t\t\t\tint rectangleRight,\n\t\t\t\t\t\tint rectangleTop,\n\t\t\t\t\t\tTree2D tree,\n\t\t\t\t\t\tint left,\n\t\t\t\t\t\tint bottom,\n\t\t\t\t\t\tint size\n\t\t\t\t)\n\t\t{\n\t\t\tint result;\n\t\t\tif (tree == null)\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint right = left + size;\n\t\t\t\tint top = bottom + size;\n\t\t\t\tint intersectionLeft = Math.max(rectangleLeft, left);\n\t\t\t\tint intersectionBottom = Math.max(rectangleBottom, bottom);\n\t\t\t\tint intersectionRight = Math.min(rectangleRight, right);\n\t\t\t\tint intersectionTop = Math.min(rectangleTop, top);\n\t\t\t\tif (intersectionRight <= intersectionLeft || intersectionTop <= intersectionBottom)\n\t\t\t\t{\n\t\t\t\t\tresult = 0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (intersectionLeft == left && intersectionBottom == bottom && intersectionRight == right && intersectionTop == top)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = tree.count;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tsize = size >> 1;\n\t\t\t\t\t\tresult = 0;\n\t\t\t\t\t\tfor (int index = 0; index < 4; index++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult += count\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\trectangleLeft,\n\t\t\t\t\t\t\t\t\t\t\trectangleBottom,\n\t\t\t\t\t\t\t\t\t\t\trectangleRight,\n\t\t\t\t\t\t\t\t\t\t\trectangleTop,\n\t\t\t\t\t\t\t\t\t\t\ttree.trees[index],\n\t\t\t\t\t\t\t\t\t\t\tquadrantLeft(left, size, index),\n\t\t\t\t\t\t\t\t\t\t\tquadrantBottom(bottom, size, index),\n\t\t\t\t\t\t\t\t\t\t\tsize\n\t\t\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\treturn result;\n\t\t}\n\n\t\tpublic int count(int rectangleLeft, int rectangleBottom, int rectangleRight, int rectangleTop)\n\t\t{\n\t\t\treturn count\n\t\t\t\t\t(\n\t\t\t\t\t\t\trectangleLeft,\n\t\t\t\t\t\t\trectangleBottom,\n\t\t\t\t\t\t\trectangleRight,\n\t\t\t\t\t\t\trectangleTop,\n\t\t\t\t\t\t\tthis,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tSIZE\n\t\t\t\t\t);\n\t\t}\n\n\t\tpublic Tree2D setPoint\n\t\t\t\t(\n\t\t\t\t\t\tint x,\n\t\t\t\t\t\tint y,\n\t\t\t\t\t\tTree2D tree,\n\t\t\t\t\t\tint left,\n\t\t\t\t\t\tint bottom,\n\t\t\t\t\t\tint size\n\t\t\t\t)\n\t\t{\n\t\t\tTree2D result;\n\t\t\tif (contains(x, y, left, bottom, size))\n\t\t\t{\n\t\t\t\tif (size == 1)\n\t\t\t\t{\n\t\t\t\t\tresult = new Tree2D(TREES_NULL, 1);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsize = size >> 1;\n\t\t\t\t\tTree2D[] trees = new Tree2D[4];\n\t\t\t\t\tfor (int index = 0; index < 4; index++)\n\t\t\t\t\t{\n\t\t\t\t\t\ttrees[index] = setPoint\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\tx,\n\t\t\t\t\t\t\t\t\t\ty,\n\t\t\t\t\t\t\t\t\t\ttree == null ? null : tree.trees[index],\n\t\t\t\t\t\t\t\t\t\tquadrantLeft(left, size, index),\n\t\t\t\t\t\t\t\t\t\tquadrantBottom(bottom, size, index),\n\t\t\t\t\t\t\t\t\t\tsize\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tresult = new Tree2D(trees);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = tree;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic Tree2D setPoint(int x, int y)\n\t\t{\n\t\t\treturn setPoint\n\t\t\t\t\t(\n\t\t\t\t\t\t\tx,\n\t\t\t\t\t\t\ty,\n\t\t\t\t\t\t\tthis,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tSIZE\n\t\t\t\t\t);\n\t\t}\n\t}\n\n\tpublic static List> permutations(List list)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tresult.add(new ArrayList<>());\n\t\tfor (Type element : list)\n\t\t{\n\t\t\tList> permutations = result;\n\t\t\tresult = new ArrayList<>();\n\t\t\tfor (List permutation : permutations)\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= permutation.size(); index++)\n\t\t\t\t{\n\t\t\t\t\tList permutationNew = new ArrayList<>(permutation);\n\t\t\t\t\tpermutationNew.add(index, element);\n\t\t\t\t\tresult.add(permutationNew);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static List> combinations(int n, int k)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tif (k == 0)\n\t\t{\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (k == 1)\n\t\t\t{\n\t\t\t\tList combination = new ArrayList<>();\n\t\t\t\tcombination.add(n);\n\t\t\t\tresult.add(combination);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= n; index++)\n\t\t\t\t{\n\t\t\t\t\tfor (List combination : combinations(n - index, k - 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tcombination.add(index);\n\t\t\t\t\t\tresult.add(combination);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterator iterator0, Iterator iterator1, Comparator comparator)\n\t{\n\t\tint result = 0;\n\t\twhile (result == 0 && iterator0.hasNext() && iterator1.hasNext())\n\t\t{\n\t\t\tresult = comparator.compare(iterator0.next(), iterator1.next());\n\t\t}\n\t\tif (result == 0)\n\t\t{\n\t\t\tif (iterator1.hasNext())\n\t\t\t{\n\t\t\t\tresult = -1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (iterator0.hasNext())\n\t\t\t\t{\n\t\t\t\t\tresult = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterable iterable0, Iterable iterable1, Comparator comparator)\n\t{\n\t\treturn compare(iterable0.iterator(), iterable1.iterator(), comparator);\n\t}\n\n\tprivate static String nextString() throws IOException\n\t{\n\t\twhile ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens()))\n\t\t{\n\t\t\tstringTokenizer = new StringTokenizer(bufferedReader.readLine());\n\t\t}\n\t\treturn stringTokenizer.nextToken();\n\t}\n\n\tprivate static String[] nextStrings(int n) throws IOException\n\t{\n\t\tString[] result = new String[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextString();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\n\tpublic static void nextInts(int n, int[]... result) throws IOException\n\t{\n\t\tfor (int index = 0; index < n; index++)\n\t\t{\n\t\t\tfor (int value = 0; value < result.length; value++)\n\t\t\t{\n\t\t\t\tresult[value][index] = nextInt();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static int[] nextInts(int n) throws IOException\n\t{\n\t\tint[] result = new int[n];\n\t\tnextInts(n, result);\n\t\treturn result;\n\t}\n\n\tpublic static double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n\n\tpublic static long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\n\tpublic static void nextLongs(int n, long[]... result) throws IOException\n\t{\n\t\tfor (int index = 0; index < n; index++)\n\t\t{\n\t\t\tfor (int value = 0; value < result.length; value++)\n\t\t\t{\n\t\t\t\tresult[value][index] = nextLong();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static long[] nextLongs(int n) throws IOException\n\t{\n\t\tlong[] result = new long[n];\n\t\tnextLongs(n, result);\n\t\treturn result;\n\t}\n\n\tpublic static String nextLine() throws IOException\n\t{\n\t\treturn bufferedReader.readLine();\n\t}\n\n\tpublic static void close()\n\t{\n\t\tout.close();\n\t}\n\n\tpublic static int binarySearchMinimum(Function filter, int start, int end)\n\t{\n\t\tint result;\n\t\tif (start == end)\n\t\t{\n\t\t\tresult = end;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint middle = start + (end - start) / 2;\n\t\t\tif (filter.apply(middle))\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, start, middle);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, middle + 1, end);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int binarySearchMaximum(Function filter, int start, int end)\n\t{\n\t\treturn -binarySearchMinimum(x -> filter.apply(-x), -end, -start);\n\t}\n\n\tpublic static long divideCeil(long x, long y)\n\t{\n\t\treturn (x + y - 1) / y;\n\t}\n\n\tpublic static Set divisors(long n)\n\t{\n\t\tSortedSetAVL result = new SortedSetAVL<>(Comparator.naturalOrder());\n\t\tresult.add(1L);\n\t\tfor (Long factor : factors(n))\n\t\t{\n\t\t\tSortedSetAVL divisors = new SortedSetAVL<>(result);\n\t\t\tfor (Long divisor : result)\n\t\t\t{\n\t\t\t\tdivisors.add(divisor * factor);\n\t\t\t}\n\t\t\tresult = divisors;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long faculty(int n)\n\t{\n\t\tlong result = 1;\n\t\tfor (int index = 2; index <= n; index++)\n\t\t{\n\t\t\tresult *= index;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static LinkedList factors(long n)\n\t{\n\t\tLinkedList result = new LinkedList<>();\n\t\tIterator primes = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile (n > 1 && (prime = primes.next()) * prime <= n)\n\t\t{\n\t\t\twhile (n % prime == 0)\n\t\t\t{\n\t\t\t\tresult.add(prime);\n\t\t\t\tn /= prime;\n\t\t\t}\n\t\t}\n\t\tif (n > 1)\n\t\t{\n\t\t\tresult.add(n);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long gcd(long a, long b)\n\t{\n\t\twhile (a != 0 && b != 0)\n\t\t{\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tb %= a;\n\t\t\t}\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tpublic static long[] generatePOWER2()\n\t{\n\t\tlong[] result = new long[63];\n\t\tfor (int x = 0; x < result.length; x++)\n\t\t{\n\t\t\tresult[x] = 1L << x;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean isPrime(long x)\n\t{\n\t\tboolean result = x > 1;\n\t\tIterator iterator = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile ((prime = iterator.next()) * prime <= x)\n\t\t{\n\t\t\tresult &= x % prime > 0;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long knapsack(List> itemsValueWeightCount, int weightMaximum)\n\t{\n\t\tlong[] valuesMaximum = new long[weightMaximum + 1];\n\t\tfor (Tuple3 itemValueWeightCount : itemsValueWeightCount)\n\t\t{\n\t\t\tlong itemValue = itemValueWeightCount.v0;\n\t\t\tint itemWeight = itemValueWeightCount.v1;\n\t\t\tint itemCount = itemValueWeightCount.v2;\n\t\t\tfor (int weight = weightMaximum; 0 <= weight; weight--)\n\t\t\t{\n\t\t\t\tfor (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++)\n\t\t\t\t{\n\t\t\t\t\tvaluesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong result = 0;\n\t\tfor (long valueMaximum : valuesMaximum)\n\t\t{\n\t\t\tresult = Math.max(result, valueMaximum);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean knapsackPossible(List> itemsWeightCount, int weightMaximum)\n\t{\n\t\tboolean[] weightPossible = new boolean[weightMaximum + 1];\n\t\tweightPossible[0] = true;\n\t\tint weightLargest = 0;\n\t\tfor (Tuple2 itemWeightCount : itemsWeightCount)\n\t\t{\n\t\t\tint itemWeight = itemWeightCount.v0;\n\t\t\tint itemCount = itemWeightCount.v1;\n\t\t\tfor (int weightStart = 0; weightStart < itemWeight; weightStart++)\n\t\t\t{\n\t\t\t\tint count = 0;\n\t\t\t\tfor (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight)\n\t\t\t\t{\n\t\t\t\t\tif (weightPossible[weight])\n\t\t\t\t\t{\n\t\t\t\t\t\tcount = itemCount;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (0 < count)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tweightPossible[weight] = true;\n\t\t\t\t\t\t\tweightLargest = weight;\n\t\t\t\t\t\t\tcount -= 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn weightPossible[weightMaximum];\n\t}\n\n\tpublic static long lcm(int a, int b)\n\t{\n\t\treturn a * b / gcd(a, b);\n\t}\n\n\tpublic static List permutation(long p, List x)\n\t{\n\t\tList copy = new ArrayList<>();\n\t\tfor (int index = 0; index < x.size(); index++)\n\t\t{\n\t\t\tcopy.add(x.get(index));\n\t\t}\n\t\tList result = new ArrayList<>();\n\t\tfor (int indexTo = 0; indexTo < x.size(); indexTo++)\n\t\t{\n\t\t\tint indexFrom = (int) p % copy.size();\n\t\t\tp = p / copy.size();\n\t\t\tresult.add(copy.remove(indexFrom));\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String toString(Iterator iterator, String separator)\n\t{\n\t\tStringBuilder stringBuilder = new StringBuilder();\n\t\tif (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\twhile (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(separator);\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\treturn stringBuilder.toString();\n\t}\n\n\tpublic static String toString(Iterator iterator)\n\t{\n\t\treturn toString(iterator, \" \");\n\t}\n\n\tpublic static String toString(Iterable iterable, String separator)\n\t{\n\t\treturn toString(iterable.iterator(), separator);\n\t}\n\n\tpublic static String toString(Iterable iterable)\n\t{\n\t\treturn toString(iterable, \" \");\n\t}\n\n\tpublic static Stream streamFibonacci()\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate BigInteger n0 = BigInteger.ZERO;\n\t\t\tprivate BigInteger n1 = BigInteger.ONE;\n\n\t\t\t@Override\n\t\t\tpublic BigInteger get()\n\t\t\t{\n\t\t\t\tBigInteger result = n0;\n\t\t\t\tn0 = n1;\n\t\t\t\tn1 = result.add(n0);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static Stream streamPrime(int sieveSize)\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate boolean[] isPrime = new boolean[sieveSize];\n\t\t\tprivate long sieveOffset = 2;\n\t\t\tprivate List primes = new ArrayList<>();\n\t\t\tprivate int index = 0;\n\n\t\t\tpublic void filter(long prime, boolean[] result)\n\t\t\t{\n\t\t\t\tif (prime * prime < this.sieveOffset + sieveSize)\n\t\t\t\t{\n\t\t\t\t\tlong remainingStart = this.sieveOffset % prime;\n\t\t\t\t\tlong start = remainingStart == 0 ? 0 : prime - remainingStart;\n\t\t\t\t\tfor (long index = start; index < sieveSize; index += prime)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult[(int) index] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void generatePrimes()\n\t\t\t{\n\t\t\t\tArrays.fill(this.isPrime, true);\n\t\t\t\tthis.primes.forEach(prime -> filter(prime, isPrime));\n\t\t\t\tfor (int index = 0; index < sieveSize; index++)\n\t\t\t\t{\n\t\t\t\t\tif (isPrime[index])\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.primes.add(this.sieveOffset + index);\n\t\t\t\t\t\tfilter(this.sieveOffset + index, isPrime);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.sieveOffset += sieveSize;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic Long get()\n\t\t\t{\n\t\t\t\twhile (this.primes.size() <= this.index)\n\t\t\t\t{\n\t\t\t\t\tgeneratePrimes();\n\t\t\t\t}\n\t\t\t\tLong result = this.primes.get(this.index);\n\t\t\t\tthis.index += 1;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static long totient(long n)\n\t{\n\t\tSet factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder());\n\t\tlong result = n;\n\t\tfor (long p : factors)\n\t\t{\n\t\t\tresult -= result / p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tsolve();\n\t\t} catch (IOException exception)\n\t\t{\n\t\t\texception.printStackTrace();\n\t\t}\n\t\tclose();\n\t}\n\n\tpublic static LinkedList digits(long n)\n\t{\n\t\tLinkedList result = new LinkedList<>();\n\t\twhile (n > 0)\n\t\t{\n\t\t\tresult.addFirst((int) n % 10);\n\t\t\tn /= 10;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int mod(int count)\n\t{\n\t\tint result = 1;\n\t\tfor (int index = 0; index < count; index++)\n\t\t{\n\t\t\tresult *= 10;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void solve() throws IOException\n\t{\n\t\tint n = nextInt();\n\t\tList digits = digits(n);\n\t\tint ninesCountMax;\n\t\tif (digits.get(0) < 5)\n\t\t{\n\t\t\tninesCountMax = digits.size() - 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tninesCountMax = digits.size();\n\t\t}\n\t\tint mod = mod(ninesCountMax);\n\t\tint result = 0;\n\t\tfor (int index = 1; index <= n; index++)\n\t\t{\n\t\t\tif (index % mod == mod - 1)\n\t\t\t{\n\t\t\t\tresult += index / mod;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (index % mod < 5 * (mod / 10))\n\t\t\t\t{\n\t\t\t\t\tresult += Math.max(0, index / mod);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult += Math.max(0, index / mod + 1);\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tout.println(result);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "54bb6c1c2479cc0cd00c18b2ea5571e9", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class D_Round_452_Div2 {\n\n public static long MOD = 1000000007;\n //static boolean print = false;\n static int[][][][][] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n // \"output.txt\")));\n PrintWriter out = new PrintWriter(System.out);\n Scanner in = new Scanner();\n String n = in.next();\n int result = n*(n - 1)/2;\n dp = new int[n.length()][2][2][3][3];\n for (int i = 1; i <= n.length(); i++) {\n for (int[][][][] a : dp) {\n for (int[][][] b : a) {\n for (int[][] c : b) {\n for (int[] d : c) {\n Arrays.fill(d, -1);\n }\n }\n }\n }\n // print = i == 1;\n int v = cal(n.length() - 1, i, 0, 0, 0, 0, new int[n.length()], new int[n.length()], n);\n\n if (v == 0) {\n break;\n }\n result = v;\n }\n out.println(result / 2);\n out.close();\n }\n\n static int cal(int index, int total, int x, int y, int a, int b, int[] A, int[] B, String n) {\n\n if (index == -1) {\n\n if (a <= 1 && b <= 1 && x == 1 && y == 1) {\n\n return 1;\n }\n return 0;\n }\n if (dp[index][x][y][a][b] != -1) {\n return dp[index][x][y][a][b];\n }\n int result = 0;\n int cur = n.charAt(index) - '0';\n if (total > 0) {\n\n for (int i = 0; i < 10; i++) {\n int left = 9 - i;\n //System.out.println(i + \" \" + left);\n A[index] = i;\n B[index] = left;\n result += cal(index - 1, total - 1, i != 0 ? 1 : x, left != 0 ? 1 : y, i > cur ? 2 : (i < cur ? 1 : a), left > cur ? 2 : (left < cur ? 1 : b), A, B, n);\n }\n } else {\n for (int i = 0; i < 10; i++) {\n for (int j = 0; j < 10; j++) {\n A[index] = i;\n B[index] = j;\n result += cal(index - 1, total, i != 0 ? 1 : x, j != 0 ? 1 : y, i > cur ? 2 : (i < cur ? 1 : a), j > cur ? 2 : (j < cur ? 1 : b), A, B, n);\n }\n }\n }\n return dp[index][x][y][a][b] = result;\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0cc6251489078da82dd1a66bead27344", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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\n int sum = N + (N - 1);\n\n if (onlyNines(sum)) {\n out.println(1);\n return;\n }\n\n int len = (sum + \"\").length();\n\n String suffix = nines(len - 1);\n\n int ans = 0;\n\n for (char c = '0'; c <= '8'; c++) {\n int p = Integer.parseInt(c + suffix);\n if (p <= N + 1) {\n ans += p / 2;\n } else if (p <= N + N - 1) {\n ans += 1 + (2 * N - 1 - p) / 2;\n }\n }\n\n out.println(ans);\n }\n\n private String nines(int cnt) {\n char[] ans = new char[cnt];\n Arrays.fill(ans, '9');\n return new String(ans);\n }\n\n private boolean onlyNines(int num) {\n while (num > 0) {\n if (num % 10 != 9) return false;\n num /= 10;\n }\n return true;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04dbd507eaf10f3a078ca2fb981760f8", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class susbus{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int x = sc.nextInt();\n int y = sc.nextInt();\n int end = interval(y,a);\n int beg = end-1;\n if(y>0 && y<2a && x-a/2){\n System.out.println(interval(y,a));\n }\n else if(end%2==0) // means theres only one block{\n if(x-a/2 && ybeg){\n System.out.println(3*end/2-1);\n }\n else {\n System.out.println(-1);\n }\n else {\n if(x0 && y beg){\n System.out.println(3*end/2);\n }\n else if(x>-a && x<0 && ybeg){\n System.out.println(3*end/2-1);\n }\n else {\n System.out.println(-1);\n }\n } \n \n }\n public static int interval(int y, int a){\n int result=0;\n while(a*result-Math.round(((double) a)/2) && y>0 && y-Math.round(((double) a)/2) && x-Math.round(((double) a)/2) && y>0 && y-Math.round(((double) a)/2) && x-a && x<0)\n System.out.print(nom+2+two);\n else\n if (x>0 && x-a && x<0)\n System.out.print(nom+2+two);\n else\n if (x>0 && x a & Math.abs(x) < Math.abs(a / 2.0)) {\n\n q = 3 * h - 1;\n } else if (y % (2 * a) < a & a > Math.abs(x)) {\n if ((y / a) == 0 && Math.abs(x) > (a / 2.0)) {\n q = -1;\n } else {\n q = 3 * h - 2;\n }\n } else {\n q = -1;\n }\n }\n }\n System.out.println(q);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "20adaa62f4c993c8bc142e1d751ba484", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400} {"lang": "Java 6", "source_code": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter pw;\n\n\tstatic int maxX, maxY;\n\t\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint a = readInt();\n\t\tint x = readInt();\n\t\tint y = readInt();\n\t\tif(y%a==0)\t{\n\t\t\tpw.println(-1);\n\t\t}\n\t\telse\t{\n\t\t\tint min = 1;\n\t\t\tfor(int row = 1; true; row++)\t{\n\t\t\t\tif(y > (row-1) * a)\t{\n\t\t\t\t\tif(row == 1 || row%2 == 0)\t{\n\t\t\t\t\t\tdouble leftX = -a/2.;\n\t\t\t\t\t\tdouble rightX = a/2.;\n\t\t\t\t\t\tif(x > leftX && x < rightX)\t{\n\t\t\t\t\t\t\tpw.println(min);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\t{\n\t\t\t\t\t\t\tpw.println(-1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\t{\n\t\t\t\t\t\tif(x > -a && x < 0)\t{\t\n\t\t\t\t\t\t\tpw.println(min);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(x > 0 && x < a)\t{\n\t\t\t\t\t\t\tpw.println(min+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\t{\n\t\t\t\t\t\t\tpw.println(-1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\t{\n\t\t\t\t\tif(row == 1 || row%2==0)\n\t\t\t\t\t\tmin++;\n\t\t\t\t\telse\n\t\t\t\t\t\tmin += 2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n\n\tpublic static boolean valid(long x, long y)\t{\n\t\treturn x >= 1 && x <= maxX && y >= 1 && y <= maxY;\n\t}\n\t\n\tpublic static long readLong() throws IOException\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tpublic static double readDouble() throws IOException\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tpublic static int readInt() throws IOException\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tpublic static short readShort() throws IOException\t{\n\t\treturn Short.parseShort(nextToken());\n\t}\n\tpublic static String nextToken() throws IOException\t{\n\t\twhile(st == null || !st.hasMoreTokens())\t{\n\t\t\tif(!br.ready())\t{\n\t\t\t\tpw.close();\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "398cce07c64ce036f82c105d392b098b", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400} {"lang": "Java 8", "source_code": " import java.util.*;\n import java.lang.*;\n // StringBuilder uses java.lang\n \n \n public class mainClass {\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int numPres = sc.nextInt();\n int numPeop = sc.nextInt();\n int[] t = new int[1000000006];\n t[0]=1;\n for (int i=1;i<1000000006;i++) {\n t[i]=(2*t[i-1]) % 1000000007;\n }\n long fact = new long[1000000006];\n fact[0]=1;\n for (int i=0;i=30)\n\t {\n\t \tans =((ans%Mod)*(Math.pow(2,30)%Mod))%Mod;\n\t \tboxes-=30;\n\t }\n\t for(int i = 1;i<=boxes;i++)\n\t \tans = ((ans%Mod)*2)%Mod; \n\t ans-=1;\n\t for(int i = 1;i 0)\n {\n if((e & 1) == 1)\n res = (res * a) % mod;\n a = (a * a) % mod;\n e >>= 1;\n }\n return res;\n }\n\n\n\n public static void main (String[]args) throws IOException {\n Scanner in = new Scanner(System.in);\n try(PrintWriter or = new PrintWriter(System.out)) {\n\n\n\n int n=in.nextInt();\n int m=in.nextInt();\n int ans=modPow(n+1,m)%MOD;\n or.println(n==1?ans-1:ans);\n\n\n\n\n\n\n\n\n\n\n\n\n }\n }\n\n\n\n\n static int getlen(int r,int l,int a){\n return (r-l+1+1)/(a+1);\n }\n\n\n\n\n\n\n static class Scanner {\n\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public 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 String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n String x = next();\n StringBuilder sb = new StringBuilder(\"0\");\n double res = 0, f = 1;\n boolean dec = false, neg = false;\n int start = 0;\n if (x.charAt(0) == '-') {\n neg = true;\n start++;\n }\n for (int i = start; i < x.length(); i++) {\n if (x.charAt(i) == '.') {\n res = Long.parseLong(sb.toString());\n sb = new StringBuilder(\"0\");\n dec = true;\n } else {\n sb.append(x.charAt(i));\n if (dec) {\n f *= 10;\n }\n }\n }\n res += Long.parseLong(sb.toString()) / f;\n return res * (neg ? -1 : 1);\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n }\n}\n\nclass Pair {\n int first, second;\n\n public Pair(int first, int second) {\n this.first = first;\n this.second = second;\n }\n\n\n\n\n}\n\nclass Tempo {\n\n int num;\n int index;\n\n public Tempo(int num, int index) {\n this.num = num;\n this.index = index;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8e5de8f800cdbad54c745685a2f71469", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class prob47 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n new prob47().solve(in,out);\n in.close();\n out.close();\n }\n\n private void solve(Scanner in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\nint ways = 0;\n for(int a=0; a<=1000; a++) {\n for(int b=0; b<=1000; b++) {\n if(a*a+b==n && a+b*b==m) ways++;\n } \n }\nout.println(ways);\n } \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "edc23857f1edb2bb1f9a58eae6567dd8", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Class1{\n public static void main(String[] args){\n int n,m;\n Scanner in = new Scanner(System.in);\n n=in.nextInt();\n m=in.nextInt();\n int i=0,j=0;\n int count=0;\n for(i=0;i=n) System.out.println(n);\n else{\n \t double x = -1/2.0+Math.sqrt(1+8*(n-m))/2;\n \t \n \t long newX = (long) x;\n \t if((newX*newX+newX)/2>=n-m){\n \t\t while((newX*newX+newX)/2>=n-m){\n \t\t\t newX--;\n \t\t }\n \t\t newX++;\n \t }else{\n \t\t while((newX*newX+newX)/2= 2*(n-k)) break;\n\t\t}\n\t\tSystem.out.println(days + factor);\n\t}\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "be39e3bdf53e842fe2e62c28aa669415", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Swatantra\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 void solve(int testNumber, Scanner in, PrintWriter out) {\n long n = in.nextLong();\n long m = in.nextLong();\n\n if (m => n) {\n out.println(n);\n } else {\n int i;\n long ar[] = new long[1000000];\n for (i = 0; i < ar.length; i++) {\n if (i <= m + 1)\n ar[i] = n;\n else {\n long k = (i - (m + 1));\n ar[i] = n - (k * (k + 1) / 2);\n\n\n }\n // out.println(\"i=\"+i+\" val=\"+ar[i]);\n\n }\n\n long ans = find(ar, m);\n\n out.println(ans);\n\n }\n }\n\n long find(long ar[], long m) {\n int min = 1;\n\n int max = ar.length;\n int flag = 0;\n int mid = 0;\n while (min <= max) {\n mid = (min + max) / 2;\n\n if (ar[mid] == m) {\n flag = 1;\n break;\n } else if (ar[mid] > m) {\n min = mid + 1;\n } else {\n max = mid - 1;\n }\n\n }\n if (ar[mid] <= m)\n return mid - 1;\n else\n return mid;\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1332ba95cbd56f1f88f819534aba2c19", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600} {"lang": "Java 8", "source_code": "public class DaVinciPowers {\n\n public static void main(String[] args)\n {\n\n Scanner sc = new Scanner(System.in);\n int input = sc.nextInt();\n System.out.println(daVincisPower(input));\n\n }\n\n\n\n public static long daVincisPower(int exponent){\n long power = 0;\n if(exponent<13){\n double base = 2.0;\n power = (long) Math.pow(base,exponent);\n\n }\n else{\n power = 8092;\n int difference = exponent - 13;\n for(int i=0;i 1) {\n a[0] = z * Math.log(y) + Math.log(Math.log(x));\n a[1] = y * Math.log(z) + Math.log(Math.log(x));\n a[2] = Math.log(z * y * Math.log(x));\n a[3] = a[2];\n }\n\n if (y == 1)\n a[4] = a[5] = a[6] = a[7] = 1;\n else if (y > 1) {\n a[4] = z * Math.log(x) + Math.log(Math.log(y));\n a[5] = x * Math.log(z) + Math.log(Math.log(y));\n a[6] = Math.log(z * x * Math.log(y));\n a[7] = a[6];\n }\n\n if (z == 1)\n a[8] = a[9] = a[10] = a[11] = 1;\n else if (z > 1) {\n a[8] = y * Math.log(x) + Math.log(Math.log(z));\n a[9] = x * Math.log(y) + Math.log(Math.log(z));\n a[10] = Math.log(y * x * Math.log(z));\n a[11] = a[10];\n }\n }\n\n static void solve(InputReader in, OutputWriter out) {\n double x = in.nextDouble();\n double y = in.nextDouble();\n double z = in.nextDouble();\n\n String[] ans = {\"x^y^z\", \"x^z^y\", \"(x^y)^z\", \"(x^z)^y\", \"y^x^z\", \"y^z^x\", \"(y^x)^z\", \"(y^z)^x\", \"z^x^y\", \"z^y^x\", \"(z^x)^y\", \"(z^y)^x\"};\n double[] a = new double[12];\n if (x <= 1 && y <= 1 && z <= 1) {\n calc(a, 1 / x, 1 / y, 1 / z);\n\n double min = Double.MAX_VALUE;\n int index = -1;\n for (int i = 0; i < a.length; i++)\n if (a[i] < min) {\n min = a[i];\n index = i;\n }\n out.print(ans[index]);\n\n } else {\n calc(a, x, y, z);\n\n double max = Double.MIN_VALUE;\n int index = -1;\n for (int i = 0; i < a.length; i++)\n if (a[i] > max) {\n max = a[i];\n index = i;\n }\n out.print(ans[index]);\n }\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f5e1a381f0d84f4310869d2a363e203f", "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c", "difficulty": 2400} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class Ratkweshandcheese {\n\n\tpublic static void main(String[] args) \n\t{\n\t\tMyScannerrat sc=new MyScannerrat();\n\t\tdouble x=sc.nextDouble();\n\t\tdouble y=sc.nextDouble();\n\t\tdouble z=sc.nextDouble();\n\t\tboolean fmax=true;\n\t\tif((x<1) && (y<1) && (z<1) )\n\t\t{\n\t\t\tfmax=false;\n\t\t}\n\t\tint count=0;\n\t\tint index=0;\n\t\tdouble max=0;\n\t\tString types[]={\"x^y^z\",\n\t\t\t\t\t\t\"x^z^y\",\n\t\t\t\t\t\t\"(x^y)^z\",\n\t\t\t\t\t\t\"(x^z)^y\",\n\t\t\t\t\t\t\"y^x^z\",\n\t\t\t\t\t\t\"y^z^x\",\n\t\t\t\t\t\t\"(y^x)^z\",\n\t\t\t\t\t\t\"(y^z)^x\",\n\t\t\t\t\t\t\"z^x^y\",\n\t\t\t\t\t\t\"z^y^x\",\n\t\t\t\t\t\t\"(z^x)^y\",\n\t\t\t\t\t\t\"(z^y)^x\"};\n\t\tfor(int i=1;i<=12;i++)\n\t\t{\n\t\t\tdouble res;\n\t\t\tdouble base;\n\t\t\tdouble log;\n\t\t\tdouble other;\n\t\t\tcount++;\n\t\t\tif(count==5)\n\t\t\t\tcount=1;\n\t\t\tif(i<=4)\n\t\t\t{\tbase=x;\n\t\t\t\n\t\t\t}\n\t\t\telse if(i<=8){\n\t\t\t\tbase=y;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tbase=z;\n\t\t\t}\n\t\t\tif(base<=1)\n\t\t\t\tcontinue;\n\t\t\tif(i==1 || i==3 ||i==10 || i==12)\n\t\t\t\tlog=y;\n\t\t\telse if(i==2 || i==4 ||i==6 || i==8)\n\t\t\t\tlog=z;\n\t\t\telse\n\t\t\t\tlog=x;\n\t\t\tother=x+y+z-base-log;\n\t\t\tif(count==1 || count==2)\n\t\t\t{\tres=typea(base,log,other);\n\t\t\t}\n\t\t\telse\n\t\t\t\tres=typeb(log,other,base);\n\t\t\t\n\t\t\t\n\t\t\tif(fmax && res>max)\n\t\t\t{\n\t\t\t\tmax=res;\n\t\t\t\tindex=i;\n\t\t\t}\n\t\t\telse if(!fmax && res= minCrushHeight) ? crushedHeight : trueHeight) + heights[cheeseType];\n int newValue = maxValue[crushedHeight][trueHeight] + values[cheeseType];\n if (newCrushedHeight <= maxHeight && newTrueHeight <= (maxHeight * 5) / 4) {\n maxValue[newCrushedHeight][newTrueHeight] = Math.max(maxValue[newCrushedHeight][newTrueHeight], newValue);\n if (newTrueHeight <= maxHeight) maxTowerValue = Math.max(maxTowerValue, newValue);\n isValid[newCrushedHeight][newTrueHeight] = true;\n }\n }\n }\n }\n }\n System.out.println(maxTowerValue);\n }\n}\n\n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7b388bbbbe5ac2229cf70aa833eedd30", "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c", "difficulty": 2400} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * @auther chao\n * @date 16/1/31\n */\n\npublic class CF4 {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\n\n Scanner in = new Scanner(System.in);\n double x = in.nextDouble();\n double y = in.nextDouble();\n double z = in.nextDouble();\n EXP[] exps = new EXP[9];\n exps[0] = new EXP(x, y, z, \"x^y^z\", 0);\n exps[1] = new EXP(x, z, y, \"x^z^y\", 1);\n exps[2] = new EXP(x, y*z, 1, \"(x^y)^z\", 2);\n exps[3] = new EXP(y, x, z, \"y^x^z\", 3);\n exps[4] = new EXP(y, z, x, \"y^z^x\", 4);\n exps[5] = new EXP(y, x*z, 1, \"(y^x)^z\", 5);\n exps[6] = new EXP(z, x, y, \"z^x^y\", 6);\n exps[7] = new EXP(z, y, x, \"z^y^x\", 7);\n exps[8] = new EXP(z, x*y, 1, \"(z^x)^y\", 8);\n /*\n int p = 0;\n for (int i = 1; i < 9; i++) {\n if (exps[i].compareTo(exps[p]) > 0) p =i;\n }*/\n Arrays.sort(exps);\n System.out.println(exps[p].exp);\n\n }\n}\nclass EXP implements Comparable{\n double x;\n double y;\n double z;\n int p;\n String exp;\n public EXP(double x, double y, double z, String exp, int p) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.exp = exp;\n this.p = p;\n }\n public int compareTo(EXP exp) {\n double lnx1 = Math.log(x);\n double lnx2 = Math.log(exp.x);\n double cmp;\n int op = 1;\n if (lnx1 * lnx2 > 0) {\n if (lnx1 < 0) {\n op = -1;\n lnx1 = -lnx1;\n lnx2 = -lnx2;\n }\n cmp = (z*Math.log(y)+Math.log(lnx1))-(exp.z*Math.log(exp.y)+Math.log(lnx2));\n } else {\n cmp = lnx1 - lnx2;\n }\n if (op < 0) cmp = -cmp;\n if (cmp == 0) return exp.p - p;\n return cmp > 0 ? 1 : -1;\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a31e20a553f71c85686f6768771fa32", "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c", "difficulty": 2400} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main{\npublic static void main(String... args)throws IOException{\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\nString[] temp = br.readLine().split(\" \");\nint a = Integer.parseInt(temp[0]);\nint c = Integer.parseInt(temp[1]);\nList ta = new ArrayList();\nList tc = new ArrayList();\nwhile (a>0 || c>0){\n ta.add(a%3);\n tc.add(c%3);\n a/=3;\n c/=3;\n}\nList tb = new ArrayList(ta.size());\nfor (int i=0; i list=new ArrayList();\n Scanner in = new Scanner(System.in);\n while (in.hasNext()) {\n \n \n \n \n }\n }\n \n \n \n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0270079bffca222c040677a56e24b852", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100} {"lang": "Java 6", "source_code": "import java.util.Scanner;\npublic class Ternary {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint num = sc.nextInt();\n\t\tint num2 = sc.nextInt();\n\t\tint mayor = num2;\n\t\tint cont = 0;\n\t\tint fin = 0;\n\t\twhile(fin != num2) {\n\t\t\twhile(num >= 3 || num2 >= 3) {\n\t\t\t\tfin += (((num % 3 + num2 % 3) % 3 + (mayor % 3)) % 3) * Math.pow(3, cont); \n\t\t\t\tnum /= 3;\n\t\t\t\tnum2 /= 3;\n\t\t\t\tmayor /= 3;\n\t\t\t\tcont++;\n\t\t\t}\n\t\t\tfin += (((num % 3 + num2 % 3) % 3 + (mayor % 3)) % 3) * Math.pow(3, cont);\n\t\t}\n\t\tSystem.out.println(fin);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f4d97e2180d66d63c6e8b4327eb0d19", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author 3mara\n */\npublic class Main {\n\n public static String getTernary(int x) {\n\n String returnVal = \"\";\n int result = x;\n while (result > 0) {\n returnVal = (result % 3) + returnVal;\n result = result / 3;\n }\n return returnVal;\n }\n\n public static void read2() {\n try {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n try {\n String ar;\n if (!(ar = br.readLine()).equals(\"\")) {\n String[] array = ar.split(\" \");\n int a = Integer.parseInt(array[0]);\n int c = Integer.parseInt(array[1]);\n String aString = \"\";\n String cString = \"\";\n String result = \"\";\n\n aString = getTernary(a);\n cString = getTernary(c);\n\n while (aString.length() < cString.length()) {\n aString = \"0\" + aString;\n }\n while (aString.length() > cString.length()) {\n cString = \"0\" + cString;\n }\n for (int i = 0; i < aString.length(); i++) {\n if (aString.charAt(i) > cString.charAt(i)) {\n result += (cString.charAt(i) + 3 - aString.charAt(i));\n } else {\n result += (cString.charAt(i) - aString.charAt(i));\n }\n }\n int finalval = 0;\n int index = 0;\n for (int i = result.length() - 1; i >= 0; i--) {\n finalval += ((Math.pow(3.0, index)) * Integer.parseInt((result.charAt(i) + \"\")));\n index++;\n }\n\n System.out.println(finalval);\n }\n } catch (NumberFormatException e) {\n }\n } catch (ArrayIndexOutOfBoundsException e) {\n } catch (IOException ex) {\n }\n }\n \n */\n public static void main(String[] args) {\n // TODO code application logic here\n read2();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "032eb839ffb138e7ff5fe5cba2e97fff", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\n\n\tpublic static void main(String[] args){\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString input = br.readLine();\n\t\tint len = input.length();\n\n\t\tSet set = new HashSet();\n\t\tset.add(input);\n\t\tinput = input+input;\t\t\n\t\tint ans = 1;\n\t\tfor(int i=0;i words = new HashSet<>();\n char[] newWord = scan.next().toCharArray();\n \n words.add(new String(newWord));\n \n for(int i=0;i h = new HashSet();\t\n\t\t\tString c = s.nextLine();\n\t\t\tString b = \"\";\n\t\t\tint count = 1;\n\t\t\th.add(c);\n\t\t\tfor(int i = 0; i< c.length(); i++){\n\t\t\t\tb = c.substring(1, c.length()) + c.charAt(0);\n\t\t\t\tif(!bbbh.contains(b)){\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\tc = b;\n\t\t\t\th.add(c);\n\t\t\t}\n\t\t\tSystem.out.println(count);\n\t\t}\n\t\t\n\t\t\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "74d8089caed6aead6037b51dd23a40dc", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class fishki \n{\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 int result = 0;\n int res = 0;\n for (int i = 1; i < N+1; i++)\n {\n result = result +i; \n }\n for (int i = 0; i < N; i++)\n {\n if(result0)\n {\n for (int i = 1; i < N+1; i++) \n {\n if(result >= i)\n {\n result = result-i;\n }\n }\n }\n if(result < 0 )\n {\n \n for (int i = N; i> 0; i--) \n { if(result<0)\n {\n result = result + i;\n }\n else\n {\n break;\n }\n \n }\n }\n \n System.out.print(result);\n }\n\n}\nimport java.util.Scanner;\n\n\npublic class fishki \n{\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 int result = 0;\n int res = 0;\n for (int i = 1; i < N+1; i++)\n {\n result = result +i; \n }\n for (int i = 0; i < N; i++)\n {\n if(result0)\n {\n for (int i = 1; i < N+1; i++) \n {\n if(result >= i)\n {\n result = result-i;\n }\n }\n }\n if(result < 0 )\n {\n \n for (int i = N; i> 0; i--) \n { if(result<0)\n {\n result = result + i;\n }\n else\n {\n break;\n }\n \n }\n }\n \n System.out.print(result);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d1bb07d827387d9402eed3e5a335fb45", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class startGame {\n \n private int walrus;\n private int chips;\n \n startGame(int walrus , int chips){\n this.walrus = walrus;\n this.chips = chips;\n }\n \n public int play(){\n \n int num=1;\n while(chips >= num){\n chips -= num;\n num++;\n if(num > walrus){\n num = 1;\n }\n }\n return chips;\n }\n \n \n import java.util.Scanner;\n\npublic class MainClass {\n \n public static void main(String[]args){\n int n,m;\n Scanner i = new Scanner(System.in);\n n = i.nextInt();\n m = i.nextInt();\n startGame g = new startGame(n, m);\n System.out.println(g.play());\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f3dd781533f9adf763cc8f7b4f098e15", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int n,m;\n while(sc.hasNextInt()){\n n = sc.nextInt();\n m = sc.nextInt();\n System.out.println(cal(n,m));\n }\n\n }\n public int cal(int n.int m)\n {\n int now = 1;\n while(m-now>0)\n {\n if(now>n)\n {\n now = 1;\n }\n m = m-now;\n now++;\n }\n return m;\n }\n}\n \t\t\t\t \t \t\t \t \t\t \t \t\t\t \t\t\t\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "442edf2c5cd6c8b6ef8152d0d4d79eee", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800} {"lang": "Java 8", "source_code": "\npublic class Chips {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n,m;\n n=in.nextLong();\n m=in.nextLong();\n int i=1;\n while(m!=0)\n {\n if(m>=i){\n m=m-i;\n i++;}\n else{\n System.out.println(m);\n break;\n }\n if(m==0)\n System.out.println(\"0\");\n if(i>n)\n i=1;\n }\n \n}}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a78c0659ba6b01215f2ab112ea456c3a", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800} {"lang": "Java 7", "source_code": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tnew Main().run();\n\t}\n\n\tScanner sc;\n\tPrintWriter pr;\n\t\n\tpublic void run() throws FileNotFoundException{\n\t\tsc = new Scanner(System.in);\n\t\tpr = new PrintWriter(new File(\"output.txt\"));\n\t\t\n\tint konf = sc.nextInt();\n\t\n\tint friends = sc.nextInt();\n\t\n\tint count = friends;\n\t\n\t\n\tif (konf%friends==0) {\n\t\tfor (int i = 0; i < friends; i++) {\n\t\t\tSystem.out.print(konf/friends+\" \");\n\t\t}\n\t}\n\telse{\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\t\tif(konf%friends != 0){\n\t\t\t\tint rizn = konf/friends;\n\t\t\t\tfriends--;\n\t\t\t\tSystem.out.print(rizn+\" \");\n\t\t\t\tkonf = konf - rizn;}\n\t\t\t\tif (konf%friends==0) {\n\t\t\t\tSystem.out.print(konf/friends+\" \");\n\t\t\t\t}\n\t\t\t}\n\n\t\n\t\n\t}\n\t\n\t}\n\t\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f5039fbd627060669402a63e86a318f4", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String [] args) {\n Scanner in = new Scanner(System.in);\n int times = 1 , i = 0 ,rest;\n int candies = in.nextInt();\n int friends = in.nextInt();\n int v[] = new int [friends];\n\n if(candies % friends == 0) {\n while(times < candies/friends) {\n System.out.print(candies/friends +\" \");\n times++;\n }\n } else {\n while(i != friends) {\n v[i] = candies/friends;\n i++;\n }\n rest = candies%friends;\n while(rest != 0) {\n v[friends-1] = v[friends-1] + 1;\n friends--;\n rest--;\n }\n\n for(int j = 0 ; j < v.length ; j++) {\n System.out.print(v[j] +\" \");\n }\n }\n\n }\n}\n\n// 1535813429723\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7110e15bc82981557148e58f9970db0a", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23", "difficulty": 800} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args) {\n Scanner kb = new Scanner(System.in);\n byte n = kb.nextByte();\n byte m = kb.nextByte();\n byte d = (byte)Math.ceil(1.0*n/m);\n double r = 1.0*n/m - (d-1);\n r = (int)(r*m);\n r = m-r;\n for(byte i = 0; i < m; i++){\n if(r > 0){\n System.out.print(d-1+\" \");\n r--;\n }\n else\n System.out.print(d+\" \");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8229be9ddf0afc73d99b29ce13f9a1ee", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23", "difficulty": 800} {"lang": "Java 7", "source_code": "public class testRound {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n Scanner vb=new Scanner(System.in);\n int n=vb.nextInt();\n int m=vb.nextInt();\n int i;\n if(n%m==0){\n for(i=0;i list = new ArrayList();\n\n\t\tfor(int i=0;i=n){\n\t\t\tout.println(\"YES\");\n\t\t\tint size = list.size();\n\t\t\tfor(int i=0;i charMap = new HashMap();\n\n int n = scn.nextInt();\n String str = scn.next();\n\n int[] arr = new int[str.length()];\n for (int i = 0; i < str.length(); i++) {\n if(!charMap.containsKey(str.charAt(i)))\n {\n charMap.put(str.charAt(i), i);\n arr[i] = 1;\n }\n }\n\n if(charMap.size() >= n)\n {\n System.out.println(\"YES\");\n\n int sidx = 0;\n for (int i = 0; i < n; i++) {\n if(i == n-1)\n {\n System.out.println(str.substring(sidx, str.length()));\n }\n else\n {\n StringBuilder sb = new StringBuilder(\"\");\n\n sb.append(str.charAt(sidx));\n sidx++;\n\n while(arr[sidx] != 1)\n {\n sb.append(str.charAt(sidx));\n sidx++;\n }\n\n System.out.println(sb);\n }\n }\n }\n else\n System.out.println(\"NO\");\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "854c8d70c3c0ef9dde17174c8f27ffc0", "src_uid": "c1b071f09ef375f19031ce99d10e90ab", "difficulty": 1100} {"lang": "Java 8", "source_code": "public class Main{\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n\n // Start writing your solution here. -------------------------------------\n\n /*\n int n = sc.nextInt(); // read input as integer\n long k = sc.nextLong(); // read input as long\n double d = sc.nextDouble(); // read input as double\n String str = sc.next(); // read input as String\n String s = sc.nextLine(); // read whole line as String\n\n int result = 3*n;\n out.println(result); // print via PrintWriter\n */\n\n // Stop writing your solution here. -------------------------------------\n out.close();\n }\n\n\n\n //-----------PrintWriter for faster output---------------------------------\n public static PrintWriter out;\n\n //-----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine(){\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n }\n //--------------------------------------------------------\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5f34d5f799cb57a17274bf4e3403c94d", "src_uid": "c1b071f09ef375f19031ce99d10e90ab", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class apples {\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 k =s.nextInt();\n int f[]= new int[n];\n for(int x=0;xn){break;}\n }\n if(z>n){\n System.out.println(-1);\n }else {\n System.out.println(q);}\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5a4f8e48c0c372633e56288df59ab4ef", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int filtrNum = sc.nextInt();\n int ustrNum = sc.nextInt();\n int freeRozetka = sc.nextInt();\n int rozetka[] = new int[filtrNum];\n for(int i = 0; i < filtrNum; i++){\n rozetka[i] = sc.nextInt();\n }\n Arrays.sort(rozetka);\n int usedFiltrNum = 0;\n int tecPos = filtrNum - 1;\n while(freeRozetka < ustrNum && tecPos >= 0){\n freeRozetka += rozetka[te-Pos] - 1;\n tecPos--;\n usedFiltrNum++;\n }\n System.out.println((tecPos < 0) ? -1 : usedFiltrNum);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "82db695d1e71f8a9f688a3a3e1a541e1", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class apples {\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 k =s.nextInt();\n int f[]= new int[n];\n for(int x=0;x r) \n { \n System.out.print(sum + \" \"); \n return; \n } \n subsetSums(arr, l + 1, r, \n sum + arr[l]); \n subsetSums(arr, l + 1, r, sum); \n }\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int k = sc.nextInt();\n ArrayList A = new ArrayList();\n for(int i = 0; i < n; i++){\n A.add(sc.nextInt());\n }\n Collections.sort(A);\n for(int i = 1; i <= k; i++){\n if(A.get(n-1) )\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "78bc20c7255af645f9a4ae3568c004db", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\nimport java.io.InputStream;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class apples{\n\tpublic static void main (String[] args) throws IOException {\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong x=sc.nextLong();\n\t\tlong y=sc.nextLong();\n\t\tif(x==y && x!=1 ) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\telse {\n\t\t ArrayList l = new ArrayList();\n\t\t long remainder=0;\n\t\t for(long i=1 ; i<=1000 ; i++) {\n\t\t\t remainder=x%i;\n\t\t\t l.add(remainder); \n\t\t }\n\t\t int k=0;\n\t\t boolean flag=true;\n\t\t \n\t\t\t\n\t\t\tfor(int z=1 ; z= n) {\n out.print(\"No\");\n return;\n }\n \n \n\n for (int i = 1; i < 1111111 && i <= k; i++) {\n long mod = n % i;\n if (b[(int) mod]) {\n out.print(\"No\");\n return;\n }\n b[(int) mod] = true;\n }\n out.print(\"Yes\");\n\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public 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 close() {\n writer.close();\n }\n\n }\n}\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "19b7697bfa1ed1555aeedde0a65ef24f", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.util.BitSet;\nimport java.util.Scanner;\nimport java.util.Vector;\n\n/**\n *\n * @author hre doy\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n static int nnn=1000002;\n static int nmn=100000001;\n int prm[];\n \n \n Vector bitSiv(){\n Vector vc;\n prm = new int[nnn];\n vc=new Vector<>();\n// System.out.println(Math.sqrt(nmn));\n int i,j,sqrt=(new Double(Math.sqrt(nmn)).intValue())+1;\n// System.out.println(\"sqrt\"+sqrt);\n for(i=2;i<=sqrt;i++){\n int ind=(int)i/32;\n int bit=(int)i-ind*32;\n if((prm[ind]&(1< vv=cdf.bitSiv();\n //System.out.println(vv.get(vv.size()-1));\n boolean f=true;\n for(int t:vv){\n if(t>k) break;\n if(n%t==0) {\n f=false;break;\n }\n \n }\n if(f) System.out.println(\"Yes\");\n else System.out.println(\"No\");\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6af27a1c379d8c107a13ed85a96fdf27", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.util.BitSet;\nimport java.util.Scanner;\nimport java.util.Vector;\n\n/**\n *\n * @author hre doy\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n static int nnn=1000002;\n static int nmn=100000001;\n int prm[];\n \n \n Vector bitSiv(){\n Vector vc;\n prm = new int[nnn];\n vc=new Vector<>();\n// System.out.println(Math.sqrt(nmn));\n int i,j,sqrt=(new Double(Math.sqrt(nmn)).intValue())+1;\n// System.out.println(\"sqrt\"+sqrt);\n for(i=2;i<=sqrt;i++){\n int ind=(int)i/32;\n int bit=(int)i-ind*32;\n if((prm[ind]&(1< vv=cdf.bitSiv();\n //System.out.println(vv.get(vv.size()-1));\n boolean f=true;\n for(int t:vv){\n if(t>k) break;\n if(n%t==0) {\n f=false;break;\n }\n \n }\n if(f) System.out.println(\"Yes\");\n else System.out.println(\"No\");\n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29b47ad5c933a933dc387cfb86d30559", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n import javafx.util.Pair; \n \n public class Param\n{\n \n public static void main( String[]args) \n {\n\n\n\tScanner param = new Scanner(System.in);\n\tint x=param.nextInt();\n\tint y=param.nextInt();\n long x1=func(x,y);\n\tlong x2=func(y,x);\n\tif(x1\");\n\t}\n\t\n \n}\npublic static long func(int x,int y){\n \n\n if(y==0)\n return 1;\n else if(y%2 == 0) \n return func(x*x,y/2);\n else \n return x*func(x*x,(y-1)/2);\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3114a73bd59b1889c63e5c43666d7c2", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\n\n\npublic class Main {\n static Scanner in = new Scanner(System.in);\n \n public static void main(String args) {\n BigInteger x = in.nextBigInteger();\n BigInteger y = in.nextBigInteger();\n BigInteger a = x.power(y);\n BigInteger b = y.power(x);\n \n if (a.compareTo(b) < 0) {\n System.out.println('<');\n } else if (a.compareTo(b) == 0) {\n System.out.println('=');\n } else {\n System.out.println('>');\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d9d616d2e73cb287e6e7f31349c3373", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.util.*;\n\npublic class Main {\n static Scanner in = new Scanner(System.in);\n public static void main(String args) {\n BigDecimal x = in.nextBigDecimal();\n BigDecimal y = in.nextBigDecimal();\n \n BigDecimal lhs = y.multiply(x.log());\n BigDecimal rhs = x.multiply(y.log());\n \n int f = lhs.compareTo(rhs);\n \n if (f < 0) {\n System.out.println('<');\n } else if (f > 0) {\n System.out.println('>');\n } else {\n System.out.println('=');\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9e47723287168f70a3ca2e44a8a9a027", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedWriter;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\n\n\npublic class Main{\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner in = new Scanner(System.in);\n\t\twhile(in.hasNext())\n\t\t{\n\t\t\tBigDecimal n = in.nextBigDecimal();\n\t\t\tBigDecimal m = in.nextBigDecimal();\n\t\t\tif(n.compareTo(m) == 0){\n\t\t\t\tSystem.out.println(\"=\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tBigDecimal x = m.multiply(new BigDecimal(Math.log(n.doubleValue())));\n\t\t\tBigDecimal y = n.multiply(new BigDecimal(Math.log(m.doubleValue())));\n\t\t\t\n//\t\t\tSystem.out.println(x + \" \" + y);\n\t\t\tif(Math.abs(x.subtract(y).doubleValue()) < 1e-1000){\n\t\t\t\tSystem.out.println(\"=\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(x.compareTo(y) < 0){\n\t\t\t\tSystem.out.println(\"<\");\n\t\t\t}\n\t\t\telse System.out.println(\">\");\n\t\t\t\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "76efb57e91404e6b7fe16b588d2f98a8", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n static int x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;\n public static int f(int x,int y)\n { if(x>=x3 && y>=y3 && x<=x4 && y>=y4)\n return 1;\n if(x>=x5 && y>=y5 && x<=x6 && y<=y6)\n return 1;\n return 0;\n }\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String s[]=br.readLine().split(\" \");\n x1=Integer.parseInt(s[0]);\n y1=Integer.parseInt(s[1]);\n x2=Integer.parseInt(s[2]);\n y2=Integer.parseInt(s[3]);\n String st[]=br.readLine().split(\" \");\n x3=Integer.parseInt(st[0]);\n y3=Integer.parseInt(st[1]);\n x4=Integer.parseInt(st[2]);\n y4=Integer.parseInt(st[3]);\n String str[]=br.readLine().split(\" \");\n x5=Integer.parseInt(str[0]);\n y5=Integer.parseInt(str[1]);\n x6=Integer.parseInt(str[2]);\n y6=Integer.parseInt(str[3]);\n for(int i=x1;i<=x2;i+=0.5)\n { if(f(i,y1)==1)\n { System.out.print(\"YES\");\n return 0;\n }\n if(f(i,y2)==1)\n { System.out.print(\"YES\");\n return 0;\n }\n }\n for(int i=y1;i<=y2;i+=0.5)\n { if(f(x1,i)==1)\n { System.out.print(\"YES\");\n return 0;\n }\n if(f(x2,i)==1)\n { System.out.print(\"YES\");\n return 0;\n }\n }\n System.out.print(\"NO\");\n return 0;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0608ce528b43e55841e58d0127c2fb84", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.awt.Rectangle;\nimport java.awt.geom.*;\n\npublic class whiteSheet {\n \n public static void main(String[] args) throws FileNotFoundException, IOException {\n InputReader fileIn = new Scanner(System.in);\n PrintWriter fileOut = new PrintWriter(System.out);\n\t\t\n\t\tint whiteX1 = fileIn.nextInt(); \n\t\tint whiteY1 = fileIn.nextInt(); \n\t\tint whiteX2 = fileIn.nextInt(); \n\t\tint whiteY2 = fileIn.nextInt();\n\t\t\n\t\tint firstX1 = fileIn.nextInt(); \n\t\tint firstY1 = fileIn.nextInt(); \n\t\tint firstX2 = fileIn.nextInt(); \n\t\tint firstY2 = fileIn.nextInt();\n\t\t\n\t\tint secondX1 = fileIn.nextInt(); \n\t\tint secondY1 = fileIn.nextInt(); \n\t\tint secondX2 = fileIn.nextInt(); \n\t\tint secondY2 = fileIn.nextInt();\n\t\t\n\t\n\t\tRectangle first = new Rectangle(firstX1, firstY1, firstX2 - firstX1, firstY2 - firstY1);\n\t\tRectangle second = new Rectangle(secondX1, secondY1, secondX2 - secondX1, secondY2 - secondY1);\n\t\tRectangle white = new Rectangle(whiteX1, whiteY1, whiteX2 - whiteX1, whiteY2 - whiteY1);\n\t\t\n\t\tArea firstArea = new Area(first);\n\t\tArea secondArea = new Area(second);\n\t\tArea whiteArea = new Area(white);\n\t\t\n\t\twhiteArea.subtract(firstArea);\n\t\twhiteArea.subtract(secondArea);\n\t\t\n\t\tif (whiteArea.isEmpty()) {\n\t\t System.out.println(\"NO\");\n\t\t} else {\n\t\t System.out.println(\"YES\");\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\tfileOut.close();\n }\n}\n\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9ab79adf5893d3b7078e9dc5548a8a08", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700} {"lang": "Java 8", "source_code": "public class Codeforce {\n \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 x3=in.nextInt();\n int y3=in.nextInt();\n int x4=in.nextInt();\n int y4=in.nextInt();\n int x5=in.nextInt();\n int y5=in.nextInt();\n int x6=in.nextInt();\n int y6=in.nextInt();\n int\nflag=1;\n if((x3<=x1&&y3<=y1&&x4>=x2&&y4>=y2)||(x5<=x1&&y5<=y1&&x6>=x2&&y6>=y2)||(x4>=x1&&y4>=y2&&x3<=x1&&y3<=y1&&x5<=x2&&y5<=y1&&x6>=x2&&y6>=y2&&(x5-x4)<=0)||(x6>=x1&&y6>=y2&&x5<=x1&&y5<=y1&&x3<=x2&&y3<=y1&&x4>=x2&&y4>=y2&&(x3-x6)<=0)||(x3<=x1&&y3<=y2&&x4>=x2&&y4>=y2&&x5<=x1&&y5<=y1&&x6>=x2&&y6>=y1&&(y6-y3)<=0)||(x5<=x1&&y5<=y2&&x6>=x2&&y6>=y2&&x3<=x1&&y3<=y1&&x4>=x2&&y4>=y1&&(y4-y5)<=0))\n flag=0;\n \n \n if(flag==1)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n \n \n \n \n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a82b2e1a6daac5609d529dc6736423d", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\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 Task solver = new Task();\n solver.solve(1, in, out);\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 public char nextChar() {\n return next().charAt(0);\n }\n }\n\n static class Task {\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] s = new int[n];\n long sum = 0;\n long max = 0;\n for (int i = 0; i < n; i++) {\n s[i] = in.nextInt();\n sum += s[i];\n if (s[i] > max) {\n max = s[i];\n }\n }\n int z = max - s[0], a;\n for (int i = 1; i < n; i++) {\n a = max - s[i];\n while (a != 0) {\n int b = z;\n z = a;\n a = b % a;\n }\n }\n out.println((max * n - sum) / z + \" \" + z);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a3bd0dbbf12a51233f74893fd62d4aed", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.Vector;\nimport java.math.BigInteger;\nimport java.util.Scanner;\npublic class TrivialProblem\n{\n\tpublic static BigInteger factorielleGrandNombre(int n)\n\t{\n\t\t if(n==0)\n\t\t \treturn BigInteger.ONE;\n\t\t else\n\t\t \treturn (BigInteger.valueOf(n)).multiply(factorielleGrandNombre(n-1));\n\t}\n\tstatic BigInteger puiss(int a,int b)\n\t{\n\t\tif(b==0)\n\t\t\treturn BigInteger.ONE;\n\t\telse\n\t\t\treturn (BigInteger.valueOf(a)).multiply(puiss(a,b-1));\n\t}\n\tpublic static void main(String[] args)\n\t{\n\t\tVector vec = new Vector();\n\t\tScanner clavier=new Scanner(System.in);\n\t\tint m=clavier.nextInt();\n\t\tint i=0;\n\t\tint a=0;\n\t\twhile ((TrivialProblem.factorielleGrandNombre(i)).subtract(TrivialProblem.puiss(10,m)).cmpareTo(BigInteger.ZERO)==-1)\n\t\t i++;\n\t\twhile((TrivialProblem.factorielleGrandNombre(i)).remainder(TrivialProblem.puiss(10,m+1))!=BigInteger.ZERO)\n\t\t{\n\t\t if((TrivialProblem.factorielleGrandNombre(i)).remainder(TrivialProblem.puiss(10,m))==BigInteger.ZERO)\n\t\t {\n\t\t\t vec.add (i);\n\t\t\t a=a+1;\n\t\t }\n\t\t i++;\n\t\t}\n\t\tif(a!=0)\n\t\t{\n\t\t\tSystem.out.println(a);\n\t\t\tfor(int k=0;k 0) {\n m -= coeff(k);\n ans += pow5(k);\n k = log5(m) + 1;\n }\n if (m == 0) {\n System.out.println(5);\n for(int i = 0; i < 4; i++) {\n System.out.print((ans+i) + \" \");\n }\n System.out.print(ans+4);\n }\n else {\n System.out.println(0);\n }\n in.close;\n }\n \n public static int log5(int m) {\n if (m <= 0) {\n return -1;\n }\n else {\n int i = 7, d = 78125;\n while (m < d) {\n d /= 5;\n i--;\n }\n return i;\n }\n }\n \n public static int coeff(int m) {\n if (m = 1) {\n return 1;\n }\n else {\n return 5*coeff(m-1) + 1;\n }\n }\n \n public static int pow5(int a) {\n int r = 1;\n while (a > 0) {\n r *= 5;\n a--;\n }\n return r;\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1df996000c86ad61b76601ee3d250b07", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by \u0410\u0440\u0442\u0443\u0440 on 27.02.2016.\n */\npublic class MainClass {\n public static void main(String[] args){\n int m=0;\n int x=0;\n int zeros=0;\n Scanner scanner = new Scanner(System.in);\n\n //System.out.print(logOf5(125));\n\n m=scanner.nextInt();\n\n // System.out.print(Math.log(25.0)/Math.log(5.0));\n\n while (zeros=5){\n ost= (int) (x%5);\n if (ost==0){\n otv++;\n pokazatel=1;\n }\n x=x/5;\n // System.out.print(\" \"+x+\" \");\n }\n if (pokazatel==0){\n // System.out.print(\"!@#$TYU%R&UY\");\n otv=1;\n }\n return otv;\n }\n}\nclose", "lang_cluster": "Java", "compilation_error": true, "code_uid": "35176b6b757eb7ec0220dcbd0b9b9758", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic final class Solution \n{\n public static void main(String[] args)\n {\n \t Reader input = new Reader();\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n int zeros = input.nextInt();\n if(zeros == 0)\n \t out.println(0);\n else\n {\n \t int start = 0;\n \t int low = 5;\n \t int high = Integer.MAX_VALUE;\n \t while(low < high)\n \t {\n \t\t int mid = (high + low)/2;\n \t\t int temp = z(mid);\n \t\t if(temp == zeros)\n \t\t {\n \t\t\t start = mid;\n \t\t\t break;\n \t\t }\n \t\t else if(temp > zeros)\n \t\t {\n \t\t\t high = mid - 1;\n \t\t }\n \t\t else\n \t\t\t low = mid + 1;\n \t }\n \t if(start == 0)\n \t {\n \t\t out.println(0);\n \t\t out.close();\n \t\t return;\n \t }\n \t out.println(5);\n \t start = start / 5 * 5;\n for(int i = 0 ; i < 5 ; i++)\n \t out.print(start + i + \" \");\n }\n\t\t out.close();\t \n } ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "507d2ed3c17355ce07be7fd7e86cec41", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.security.KeyStore.Entry;\nimport java.util.*;\n/* \n yash jobanputra\n DA-IICT\n*/\npublic class Main {\n private static InputStream stream;\n private static byte[] buf = new byte[1024];\n private static int curChar;\n private static int numChars;\n private static SpaceCharFilter filter;\n private static PrintWriter pw;\n private static long mod = 1000000000 + 7;\n private static long mod1 = 1000000000 + 9;\n private static int MAX=1000001;\n private static int block;\n // private static int[] level;\n private static long[] cost;\n private static long[] costm;\n private static int times;\n private static long ans;\n private static long max;\n private static boolean[] vis;\n private static long[] sa;\n private static long count;\n private static boolean ff;\n private static int odd;\n private static int even;\n private static ArrayList ansa;\n private static long[] dp;\n private static long[][] dp2;\n private static int n;\n private static ArrayList[] g;\n private static long time;\n private static int[] di;\n private static int[] en;\n private static int[] level;\n private static int[] prime={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};\n public static void soln()\n {\t\n \tint n=ni();int k=ni();\n \tint[] arr=nia(n);\n \tint e=0;int s=0;HashSet set=new HashSet<>();\n \tint te=0;int ts=0;\n \tfor(int i=0;i ss=new HashSet<>();\n \t\tfor(int j=-n;j=0 && x[] gr,int v)\n {\n vis[v]=true;\n ArrayList arr=gr[v];\n for(int i=0;i[] gr,int v)\n {\n vis[v]=true;\n time++;\n di[v]=time;\n ArrayList arr=gr[v];\n for(int i=0;i[] gr,int v,int[] a)\n {\n vis[v]=true;\n ArrayList arr=gr[v];\n for(int i=0;i[] g)\n \t{\n \t\tn=g.length-1;\n \t\tpw.println(n);\n \t\te=new int[2*n];\n \t\tl=new int[2*n];\n \t\th=new int[n+1];\n \t\tvis=new boolean[n+1];\n \t\tlevel=new int[n+1];\n \t\tlevel[1]=0;\n \t\tdfs(g,1);\n \t\tArrays.fill(lazy, 0);\n \t\tbuild(l,0,0,2*n-1);\n \t}\n \tpublic int lf(int u,int v)\n \t{\n \t\tint a=h[u];int b=h[v];\n \t\tif(h[u]>h[v])\n \t\t\t{a=h[v];b=h[u];}\n \t\tint p=query(l,0,0,2*n-1,a,b);\n \t\treturn e[p];\n \t}\n \tpublic void dfs(ArrayList[] gr,int v)\n {\n vis[v]=true;\n time++;\n e[time]=v;\n l[time]=level[v];\n h[v]=time;\n ArrayList arr=gr[v];\n for(int i=0;i=r)\n return tree[node];\n int m=(l+r)/2;\n int p1=query(arr,(2*node+1),l,m,s,e);\n int p2=query(arr,(2*node+2),m+1,r,s,e);\n if(p1==-1)\n \t return p2;\n else if(p2==-1)\n \t return p1;\n else\n {\n \t if(arr[p1][] gr,boolean[] vis,int ver)\n {\n int child=0;\n vis[ver]=true;\n ArrayList arr=gr[ver];\n times++;\n disc[ver]=low[ver]=times;\n for(int i=0;i=disc[ver])\n ap[ver]=true;\n if(parent[ver]==0 && child>1)\n ap[ver]=true;\n }\n else if(parent[ver]!=arr.get(i))\n low[ver]=Math.min(low[ver], disc[arr.get(i)]);\n }\n }\n public static void floyd(Pair[] arr,int n,int m,int[][] dist)\n {\n for(int i=0;i<=n;i++)\n {\n Arrays.fill(dist[i], Integer.MAX_VALUE);\n }\n for(int c=0;c[] gr,int v,int n)\n {\n \n boolean[] vis=new boolean[n+1];\n int c2=0;\n Queue q=new LinkedList<>();\n q.add(v);\n while(!q.isEmpty())\n {\n int x=q.poll();\n Iterator it=gr[x].iterator();\n while(it.hasNext())\n {\n int p=it.next();\n if(!vis[p])\n {\n q.add(p);\n c2++;\n vis[p]=true;\n }\n }\n }\n return c2==n;\n }\n public static ArrayList MSTP(int n,int m,ArrayList[] arr,int[][] arr2)\n {\n ArrayList pp=new ArrayList<>();\n int[] par=new int[n+1];\n int[] key=new int[n+1];\n vis=new boolean[n+1];\n Arrays.fill(key, Integer.MAX_VALUE);\n key[1]=0;\n PriorityQueue dis=new PriorityQueue<>(n+1,\n new Comparator()\n {\n public int compare(Integer p,Integer q)\n {\n return key[p]-key[q];\n }\n }\n );\n dis.add(1);\n vis[1]=true;\n while(!dis.isEmpty())\n {\n //pw.println(dis);\n int u=dis.poll();\n ArrayList p=arr[u];\n for(int i=0;i MSTK(int n,int m,Pair[] arr)\n {\n ArrayList pp=new ArrayList<>();\n long sum=0;\n Arrays.sort(arr);\n DSU x=new DSU(n+1);\n for(int c=0;(c[] gr)\n {\n int n=gr.length-1;\n int[] dist=new int[n+1];\n Arrays.fill(dist, Integer.MAX_VALUE);\n \n PriorityQueue dis=new PriorityQueue<>(n+1,\n new Comparator()\n {\n public int compare(Integer p,Integer q)\n {\n return dist[p]-dist[q];\n }\n }\n );\n boolean[] vis=new boolean[n+1];\n Arrays.fill(vis, false);\n \n int s=1;\n dist[s]=0;\n dis.add(s);\n vis[s]=true;\n while(!dis.isEmpty())\n {\n int p=dis.poll();\n for(int i=0;i sieves(int n)\n {\n ArrayList arr=new ArrayList<>();\n boolean[] bol=new boolean[n+1];\n Arrays.fill(bol, true);\n //arr.add(1);\n for(int i=2;i<=n;i++)\n {\n if(bol[i])\n {\n arr.add(i);\n for(int j=2;j*i<=n;j++)\n {\n bol[i*j]=false;\n }\n }\n }\n return arr;\n }\n }\n public static class isprime{\n public static boolean check(int n)\n {\n if(n==2)\n return true;\n else if(n==3)\n return true;\n else if(n%2==0)\n return false;\n else if(n%3==0)\n return false;\n else\n {\n for(int i=6;;i+=6)\n {\n if(i>Math.sqrt(n))\n break;\n if(n%(i-1)==0)\n {\n return false;\n }\n else if(n%(i+1)==0)\n return false;\n }\n return true;\n }\n }\n }\n private static class DSU{\n int[] parent;\n int[] rank;\n int cnt;\n public DSU(int n){\n parent=new int[n];\n rank=new int[n];\n for(int i=0;i{\n int v,i;Pair j;\n public Pair2(int a,int b){\n v=a;\n i=b;\n }\n public Pair2(int a,Pair b)\n {\n v=a;\n j=b;\n }\n @Override\n public int compareTo(Pair2 arg0) {\n {\n \tif(this.v!=arg0.v)\n \t\treturn this.v-arg0.v;\n \telse\n \t\treturn this.i-arg0.i;\n }\n }\n }\n private static class Pair implements Comparable{\n int v,i;Pair j;\n public Pair(int a,int b){\n v=a;\n i=b;\n }\n public Pair(int a,Pair b)\n {\n v=a;\n j=b;\n }\n @Override\n public int compareTo(Pair arg0) {\n {\n \tif(this.j.v!=arg0.j.v)\n \t\treturn this.j.v-arg0.j.v;\n \telse\n \t\treturn this.j.i-arg0.j.i;\n }\n }\n }\n private static class Pairl implements Comparable{\n long v,i;Pairl j;\n public Pairl(long a,long b){\n v=a;\n i=b;\n }\n public Pairl(long a,Pairl b)\n {\n v=a;\n j=b;\n }\n @Override\n public int compareTo(Pairl arg0) {\n {\n if(this.v>arg0.v)\n return 1;\n else\n return -1;\n }\n }\n }\n public static long f(long number,long m) {\n if (number <= 1) return 1;\n else return (number * f(number - 1,m))%m;\n }\n public static long mmi(long a, long m) \n { \n long m0 = m; \n long y = 0, x = 1; \n \n if (m == 1) \n return 0; \n \n while (a > 1) \n { \n // q is quotient \n long q = a / m; \n long t = m; \n \n // m is remainder now, process same as \n // Euclid's algo \n m = a % m; a = t; \n t = y; \n \n // Update y and x \n y = x - q * y; \n x = t; \n } \n \n // Make x positive \n if (x < 0) \n x += m0; \n \n return x; \n } \n public static class segtree{ \n int[] tree=new int[10000000];\n int[] lazy=new int[10000000];\n public segtree()\n {\n Arrays.fill(lazy, 0);\n }\n public void build(int[] arr,int node,int l,int r)\n {\n if(l==r)\n {\n tree[node]=arr[l];\n }\n else\n {\n int m=(l+r)/2;\n build(arr,(2*node)+1,l,m);\n build(arr,(2*node)+2,m+1,r);\n tree[node]=tree[2*node+1]+tree[(2*node)+2];\n }\n }\n public void updater(int[] arr,int node,int l,int r,int s,int e,int val)\n {\n if(lazy[node]!=0)\n {\n tree[node]+=(r-l+1)*lazy[node];\n if(l!=r)\n {\n lazy[2*node+1]+=lazy[node];\n lazy[2*node+2]+=lazy[node];\n }\n lazy[node]=0;\n }\n if(s<=l && e>=r)\n {\n tree[node]+=(r-l+1)*val;\n if(l!=r)\n {\n lazy[2*node+1]+=val;\n lazy[2*node+2]+=val;\n }\n }\n else if(!(e=r)\n return tree[node];\n int m=(l+r)/2;\n int p1=query((2*node+1),l,m,s,e);\n int p2=query((2*node+2),m+1,r,s,e);\n return (p1+p2);\n }\n }\n \n private static long pow(long a, long b, long c) {\n if (b == 0)\n return 1;\n long p = pow(a, b / 2, c);\n p = (p * p) % c;\n return (b % 2 == 0) ? p : (a * p) % c;\n }\n private static long gcd(long n, long l) {\n if (l == 0)\n return n;\n return gcd(l, n % l);\n }\n private static int gcd(int n, int l) {\n if (l == 0)\n return n;\n return gcd(l, n % l);\n }\n private static long max(long a, long b) {\n if (a > b)\n return a;\n return b;\n }\n private static long min(long a, long b) {\n if (a < b)\n return a;\n return b;\n }\n public 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= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n private static int ni() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n private static long nl() {\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 private static double nd()\n {\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\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 private static String nextToken() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private static String nli() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n private static int[] nia(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = ni();\n }\n return arr;\n }\n\n private static long[] nla(int n) {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nl();\n }\n return arr;\n }\n\n private static void pa(int[] arr) {\n for (int i = 0; i < arr.length; i++) {\n pw.print(arr[i] + \" \");\n }\n pw.println();\n return;\n }\n\n private static void pa(long[] arr) {\n for (int i = 0; i < arr.length; i++) {\n pw.print(arr[i] + \" \");\n }\n pw.println();\n return;\n }\n private static void pl(int a)\n {\n \tpw.println(a);\n }\n private static void pl(long a)\n {\n \tpw.println(a);\n }\n private static void p(int a)\n {\n \tpw.print(a+\" \");\n }\n private static void p(long a)\n {\n \tpw.print(a+\" \");\n }\n private static boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n private static char nc() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n char c1=(char)c;\n while(!isSpaceChar(c))\n c=read();\n return c1;\n }\n public String ns() {\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 private interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "553c7c4c7fc86c8ff91322d1cae88a13", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class Main {\n\n public static void main(String[] args) {\n\t Scanner in = new Scanner(System.in);\n\t int n = in.nextInt();\n\t int k = in.nextInt();\n\t int[] tabs = new int[n];\n\t for(int i = 0; i < n; i++) {\n\t tabs[i] = in.nextInt();\n }\n\t int max = 0;\n\t for(int b = 0; b < tabs.length; b++) {\n\t \tint s = b;\n\t \twhile(s >= 0) s-=k;\n\t \ts+=k;\n\t int[] tabs1 = tabs.clone();\n\t for(int i = s; i < tabs1.length; i += k) {\n\t tabs1[i] = 0;\n }\n\t int val = 0;\n\t for(int i = 0; i < tabs1.length; i++) {\n\t val += tabs1[i];\n }\n\t max = Math.max(max, Math.abs(val));\n }\n\t System.out.println(max);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8cdfcacb433ee88ca5076ed424e76169", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class simple\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\tpublic static void main(String args[])\n\t{\n\t\tint n =input.nextInt();\n\t\tint[] arr = new int[n];\n\t\tint k =input.nextInt();\n\t\tint o1=0,e1=0;\n\t\tint ans=Integer.MIN_VALUE;\n\t\tfor(int i=0;ians)\n\t\t\t\tans=Math.abs(o1-e1-o+e);\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c528c75a4d5ff429738dc9f91f66bee4", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000} {"lang": "Java 8", "source_code": "\npublic class A_RomanAndBrowser {\n private static final Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] args) throws IOException {\n Integer n = scanner.nextInt();\n Integer k = scanner.nextInt();\n\n int types[] = new int[n];\n int totalSum = 0;\n\n for (int i = 0; i < n; i++) {\n int type = scanner.nextInt();\n types[i] = type;\n totalSum += type;\n }\n\n int maxDiff = 0;\n for (int start = 0; start < k; start++) {\n int currSum = totalSum;\n for (int i = 0; start + (i*k) < n; i++) {\n currSum -= types[start + (i*k)];\n }\n\n currSum = Math.abs(currSum);\n if (currSum > maxDiff) maxDiff = currSum;\n }\n\n System.out.println(maxDiff);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e85b3fc5765aa432c31b3c5ed877591e", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static void main(String[] args) throws IOException {\n new Solution().run();\n }\n StringTokenizer tok;\n BufferedReader reader;\n PrintWriter out;\n void run() throws IOException {\n reader = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n reader = new BufferedReader(new FileReader(new File(\"input.txt\")));\n //out = new PrintWriter(new File(\"output.txt\"));\n tok = null;\n solve();\n out.close();\n }\n String nextString() throws IOException {\n while(tok == null || !tok.hasMoreTokens()){\n tok = new StringTokenizer(reader.readLine());\n }\n return tok.nextToken();\n }\n int nextInt() throws IOException {\n return Integer.parseInt(nextString());\n }\n long nextLong() throws IOException {\n return Long.parseLong(nextString());\n }\n double nextDouble() throws IOException {\n return Double.parseDouble(nextString());\n }\n\n int c3,c4,c5,s;\n boolean ok(int k3,int k4,int k5){\n //assert c3*k3+c4*k4+c5*k5==s;\n //assert (0<=k3 && k3<=k4 && k4<=k5);\n if (c3*k3+c4*k4+c5*k5!=s) return false;\n if (!(0<=k3 && k3<=k4 && k4<=k5)) return false;\n return true;\n }\n int min_ans = Integer.MAX_VALUE;\n int v3,v4,v5;\n void update(int k3,int k4,int k5){\n if (!ok(k3,k4,k5)) return;\n int ans = Math.abs(c3*k3-c4*k4)+Math.abs(c4*k4-c5*k5);\n if (ans < min_ans){\n min_ans = ans;\n v3=k3;\n v4=k4;\n v5=k5;\n }\n }\n //k*b>=a ----> k>=a/b\n int div_ge(int a,int b){\n if (b<0){a=-a;b=-b;}\n if (a<=0) return a/b;\n //k*b >= a\n if (a%b==0) return a/b;\n return a/b+1;\n }\n //k*b<=a ----> k<=a/b\n int div_le(int a,int b){\n if (b<0){a=-a;b=-b;}\n if (a>=0)return a/b;\n //k*b <= -a\n if (a%b==0) return a/b;\n return a/b-1;\n }\n int gx,gy;\n int gcdex(int a,int b){\n if (a==0){\n gx=0;\n gy=1;\n return b;\n }\n else{\n int g = gcdex(b%a,a);\n int x1=gx,y1=gy;\n gx=y1-(b/a)*x1;\n gy=x1;\n return g;\n }\n }\n void tryfind(int k4){\n int a = c3;\n int b = c5;\n int c = s-c4*k4;\n int g = gcdex(Math.abs(a),Math.abs(b));\n if (c%g!=0) return;\n gx*=c/g;\n gy*=c/g;\n if (a<0) gx*=-1;\n if (b<0) gy*=-1;\n int ag = a/g;\n int bg = b/g;\n int min_k = Integer.MIN_VALUE;\n int max_k = Integer.MAX_VALUE;\n {\n //\u043e\u0431\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 0<=k3<=k5<=s\n int k_ge = div_ge(-gx,bg);//0<=k3\n int k_le = div_le(k4-gx,bg);//k3<=k4\n int k_le2 = div_le(gy-k4,ag);//k4<=k5\n int k_ge2 = div_ge(gy-s,ag);//k5<=s\n\n min_k=Math.max(min_k,k_ge);\n min_k=Math.max(min_k,k_ge2);\n max_k=Math.min(max_k,k_le);\n max_k=Math.min(max_k,k_le2);\n }\n if (min_k<=max_k){\n int k,k3,k5;\n\n k = min_k;\n k3 = gx+k*bg;\n k5=gy-k*ag;\n update(k3,k4,k5);\n\n k = max_k;\n k3 = gx+k*bg;\n k5=gy-k*ag;\n update(k3,k4,k5);\n }\n }\n void solve() throws IOException {\n int n = nextInt();\n s = nextInt();\n c3=c4=c5=0;\n for(int i=0;i p2) return null;\n ArrayList check = new ArrayList();\n check.add(p1);\n check.add(p2);\n double m = 1.0 * m1 / d;\n check.add((int)Math.floor(m));\n check.add((int)Math.ceil(m));\n m = 1.0 * m2 / (2 * d);\n check.add((int)Math.floor(m));\n check.add((int)Math.ceil(m));\n int res = Integer.MAX_VALUE;\n int t = -1;\n for (Integer i: check) if (p1 <= i && i <= p2) {\n int f = Math.abs(d * i - m1) + Math.abs(2 * d * i - m2);\n if (f < res) {\n res = f;\n t = i;\n }\n }\n\n int x = x0 + t * d / a;\n int y = y0 - t * d / b;\n if (c > x || x > y) {\n throw new RuntimeException();\n }\n if (a * x + b * y != s - r) throw new RuntimeException();\n return new int[]{res, x, y};\n }\n\n int[] nod(int a, int b) {\n if (b == 0) return new int[]{a, 1, 0};\n if (a < b) {\n int[] p = nod(b, a);\n return new int[]{p[0], p[2], p[1]};\n }\n int q = a / b;\n int[] p = nod(b, a - q * b);\n return new int[]{p[0], p[2], p[1] - q * p[2]};\n }\n\n\n public void run() {\n try {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int s = in.nextInt();\n int[] k = new int[3];\n for (int i = 0; i < n; i++) {\n int p = in.nextInt();\n k[p - 3]++;\n }\n int[] res = null;\n int f = 0;\n for (int i = 0; i * k[0] <= s; i++) {\n int[] p = find(s, i * k[0], k[1], k[2], i);\n if (p != null && (res == null || p[0] < f)) {\n f = p[0];\n res = new int[]{i, p[1], p[2]};\n }\n }\n if (res == null) {\n System.out.println(-1);\n } else {\n System.out.println(res[0] + \" \" + res[1] + \" \" + res[2]);\n }\n\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n\n public static void main(String[] args) {\n new Thread(new Traktor()).start();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e281b55451aad53eb2d75236c1c11a17", "src_uid": "3f3eb49a127768139283ac04ee44950f", "difficulty": 2400} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n\t\n\tint s;\n\tint c3 = 0, c4 = 0, c5 = 0;\n\t\n\tint naive(int s) {\n\t\tint bestk3 = -1, bestk4 = -1, bestk5 = -1;\n\t\tint bestf = Integer.MAX_VALUE / 2;\n\t\tfor (int k3 = 0; k3 * c3 <= s; k3++) {\n\t\t\tfor (int k4 = k3; k3 * c3 + k4 * c4 <= s; k4++) {\n\t\t\t\tint rem = s - k3 * c3 - k4 * c4;\n\t\t\t\tif (rem % c5 == 0) {\n\t\t\t\t\tint k5 = rem / c5;\n\t\t\t\t\tif (k5 < k4) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tint f = abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);\n\t\t\t\t\tif (k3 == 1961) {\n\t\t\t\t\t\tSystem.out.println(k3 + \" \" + k4 + \" \" + k5 + \" \" + f);\n\t\t\t\t\t}\n\t\t\t\t\tif (f < bestf) {\n\t\t\t\t\t\tbestk3 = k3;\n\t\t\t\t\t\tbestk4 = k4;\n\t\t\t\t\t\tbestk5 = k5;\n\t\t\t\t\t\tbestf = f;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(bestk3 + \" \" + bestk4 + \" \" + bestk5);\n\t\tout.println(bestf);\n\t\treturn bestf;\n\t}\n\t\n\tint f(int k3, int k4) {\n\t\tint k5 = (s - k3 * c3 - k4 * c4) / c5;\n\t\treturn abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = sc.nextInt();\n\t\ts = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint mark = sc.nextInt();\n\t\t\tif (mark == 3) {\n\t\t\t\tc3++;\n\t\t\t} else if (mark == 4) {\n\t\t\t\tc4++;\n\t\t\t} else if (mark == 5) {\n\t\t\t\tc5++;\n\t\t\t}\n\t\t}\n\t\t//c3 = sc.nextInt();\n\t\t//c4 = sc.nextInt();\n\t\t//c5 = sc.nextInt();\n\t\tRandom rnd = new Random();\n\t\t//c3 = rnd.nextInt(20) + 1;\n\t\t//c4 = rnd.nextInt(20) + 1;\n\t\t//c5 = rnd.nextInt(20) + 1;\n\t\t//out.println(c3 + \" \" + c4 + \" \" + c5);\n\t\tArrayList[] may = new ArrayList[c5];\n\t\tfor (int i = 0; i < c5; i++) {\n\t\t\tmay[i] = new ArrayList();\n\t\t\tfor (int j = 0; j < c5; j++) {\n\t\t\t\tif ((c3 * i + c4 * j) % c5 == s % c5) {\n\t\t\t\t\tmay[i].add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint bestk3 = -1, bestk4 = -1, bestk5 = -1;\n\t\tint bestf = Integer.MAX_VALUE / 2;\n\t\tfor (int k3 = 0; k3 * c3 <= s; k3++) {\n\t\t\tif (may[k3 % c5].size() == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tArrayList cmay = may[k3 % c5];\n\t\t\tint ll = 0, 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\tint vall = cmay.get(l % cmay.size()) + l / cmay.size() * c5;\n\t\t\tll = -1;\n\t\t\trr = 500000;\n\t\t\twhile (rr - ll > 1) {\n\t\t\t\tint mm = (ll + rr) / 2;\n\t\t\t\tint 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\tint valr = cmay.get(r % cmay.size()) + r / cmay.size() * c5;\n\t\t\tif (l > r) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\twhile (r - l >= 3) {\n\t\t\t\tint m1 = l + (r - l) / 3;\n\t\t\t\tint m2 = r - (r - l) / 3;\n\t\t\t\tint f1 = f(k3, cmay.get(m1 % cmay.size()) + m1 / cmay.size() * c5);\n\t\t\t\tint f2 = f(k3, cmay.get(m2 % cmay.size()) + m2 / cmay.size() * c5);\n\t\t\t\tif (f1 >= f2) {\n\t\t\t\t\tl = m1;\n\t\t\t\t} else {\n\t\t\t\t\tr = m2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = l; i <= r; i++) {\n\t\t\t\tint k4 = cmay.get(i % cmay.size()) + i / cmay.size() * c5;\n\t\t\t\tint k5 = (s - k3 * c3 - k4 * c4) / c5;\n\t\t\t\tint fi = f(k3, k4);\n\t\t\t\tif (fi < bestf) {\n\t\t\t\t\tbestk3 = k3;\n\t\t\t\t\tbestk4 = k4;\n\t\t\t\t\tbestk5 = k5;\n\t\t\t\t\tbestf = fi;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (bestk3 != -1) {\n\t\t\tout.println(bestk3 + \" \" + bestk4 + \" \" + bestk5);\n\t\t} else {\n\t\t\tout.println(-1);\n\t\t}\n\t\t//out.println(bestf);\n\t\t/*\n\t\tif (bestf != naive(s)) {\n\t\t\tthrow new Exception();\n\t\t}\n\t\t*/\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tFastScanner sc;\n\t\n\tstatic Throwable uncaught;\n\t\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\t//System.setOut(new PrintStream(\"test.txt\"));\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable t) {\n\t\t\tMain.uncaught = t;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread t = new Thread(null, new Main(), \"\", 128 * 1024 * 1024);\n\t\tt.start();\n\t\tt.join();\n\t\tif (uncaught != null) {\n\t\t\tthrow uncaught;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n\t\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\t\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\t\n\tpublic String nextToken() throws IOException {\n\t\twhile (strTok == null || !strTok.hasMoreTokens()) {\n\t\t\tstrTok = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn strTok.nextToken();\n\t}\n\t\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f55ab3bc33862add22d246aa2298534f", "src_uid": "3f3eb49a127768139283ac04ee44950f", "difficulty": 2400} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static void main(String[] args) throws IOException {\n new Solution().run();\n }\n StringTokenizer tok;\n BufferedReader reader;\n PrintWriter out;\n void run() throws IOException {\n reader = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n reader = new BufferedReader(new FileReader(new File(\"input.txt\")));\n //out = new PrintWriter(new File(\"output.txt\"));\n tok = null;\n solve();\n out.close();\n }\n String nextString() throws IOException {\n while(tok == null || !tok.hasMoreTokens()){\n tok = new StringTokenizer(reader.readLine());\n }\n return tok.nextToken();\n }\n int nextInt() throws IOException {\n return Integer.parseInt(nextString());\n }\n long nextLong() throws IOException {\n return Long.parseLong(nextString());\n }\n double nextDouble() throws IOException {\n return Double.parseDouble(nextString());\n }\n\n int c3,c4,c5,s;\n boolean ok(int k3,int k4,int k5){\n //assert c3*k3+c4*k4+c5*k5==s;\n //assert (0<=k3 && k3<=k4 && k4<=k5);\n if (c3*k3+c4*k4+c5*k5!=s) return false;\n if (!(0<=k3 && k3<=k4 && k4<=k5)) return false;\n return true;\n }\n int min_ans = Integer.MAX_VALUE;\n int v3,v4,v5;\n void update(int k3,int k4,int k5){\n if (!ok(k3,k4,k5)) return;\n int ans = Math.abs(c3*k3-c4*k4)+Math.abs(c4*k4-c5*k5);\n if (ans < min_ans){\n min_ans = ans;\n v3=k3;\n v4=k4;\n v5=k5;\n }\n }\n //k*b>=a ----> k>=a/b\n int div_ge(int a,int b){\n if (b<0){a=-a;b=-b;}\n if (a<=0) return a/b;\n //k*b >= a\n if (a%b==0) return a/b;\n return a/b+1;\n }\n //k*b<=a ----> k<=a/b\n int div_le(int a,int b){\n if (b<0){a=-a;b=-b;}\n if (a>=0)return a/b;\n //k*b <= -a\n if (a%b==0) return a/b;\n return a/b-1;\n }\n int gx,gy;\n int gcdex(int a,int b){\n if (a==0){\n gx=0;\n gy=1;\n return b;\n }\n else{\n int g = gcdex(b%a,a);\n int x1=gx,y1=gy;\n gx=y1-(b/a)*x1;\n gy=x1;\n return g;\n }\n }\n void tryfind(int k4){\n int a = c3;\n int b = c5;\n int c = s-c4*k4;\n int g = gcdex(Math.abs(a),Math.abs(b));\n if (c%g!=0) return;\n gx*=c/g;\n gy*=c/g;\n if (a<0) gx*=-1;\n if (b<0) gy*=-1;\n int ag = a/g;\n int bg = b/g;\n int min_k = Integer.MIN_VALUE;\n int max_k = Integer.MAX_VALUE;\n {\n int k_ge = div_ge(-gx,bg);//0<=k3\n int k_le = div_le(k4-gx,bg);//k3<=k4\n int k_le2 = div_le(gy-k4,ag);//k4<=k5\n int k_ge2 = div_ge(gy-s,ag);//k5<=s\n\n min_k=Math.max(min_k,k_ge);\n min_k=Math.max(min_k,k_ge2);\n max_k=Math.min(max_k,k_le);\n max_k=Math.min(max_k,k_le2);\n }\n if (min_k<=max_k){\n int k,k3,k5;\n\n k = min_k;\n k3 = gx+k*bg;\n k5=gy-k*ag;\n update(k3,k4,k5);\n\n k = max_k;\n k3 = gx+k*bg;\n k5=gy-k*ag;\n update(k3,k4,k5);\n }\n }\n void solve() throws IOException {\n int n = nextInt();\n s = nextInt();\n c3=c4=c5=0;\n for(int i=0;i hm = new HashMap<>();\n for (long i = 2l; i * i <= b; i++) {\n long cnt = 0l;\n while (b % i == 0) {\n cnt ++;\n b /= i;\n }\n if (cnt > 0l)\n hm.put(i, cnt);\n }\n if (b > 1)\n hm.put(b, 1l);\n long pow = 0l;\n for (Map.Entry entry : map.entrySet()) {\n long p = 0;\n for (long j = entry.getKey(); j <= n; j *= entry.getKey())\n p += n / j;\n p /= entry.getValue();\n if (p < pow || pow == 0l)\n pow = p;\n }\n System.out.print(pow);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "53a375311ce2bd1e90d0aa78ba24512d", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.io.*;\n\nimport dggggsd.Main.Scanner;\n\npublic class factoral1 {\n\t static Scanner sc = new Scanner(System.in);\n\t \n\tpublic static void main(String[] args) throws IOException {\n\t\tlong n=sc.nextInt();\n\t\tlong m=sc.nextLong();\n\t\tif (n==6&&m==9)\n\t\t\tSystem.out.println(1);\n\t\telse {\n\tSystem.out.println(zero(m,n));\n\t\t}\n\t}\n\tpublic static long zero(long n,long a) {\n\t\tlong min=100000;\n\t\tboolean f=true;\n\t\tif (n%2==0) {\n\t\t\tlong x= fac(2,a);\n\t\t\twhile (n%2==0)\n\t\t\t\tn/=2;\n\t\t\tif (x 1) {\n divs[di++] = b;\n divcnt[di - 1] = 1;\n }\n long min = Long.MAX_VALUE;\n for (int i = 0; i < di; i++) {\n long div = divs[i];\n long pow = div;\n long cnt = n / pow;\n while (pow < n && pow * div > pow) {\n pow *= div;\n cnt += n / pow;\n }\n min = Math.min(min, cnt / divcnt[i]);\n }\n out.println(min);\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 long nl() {\n return Long.parseLong(ns());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "acd1a52c14c137750972b8495d5cbf7a", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700} {"lang": "Java 8", "source_code": "\n\nimport java.io.IOException;\nimport java.util.*;\nimport java.io.*;\n\nimport dggggsd.Main.Scanner;\n\npublic class factoral1 {\n\t static Scanner sc = new Scanner(System.in);\n\t \n\tpublic static void main(String[] args) throws IOException {\n\t\tlong n=sc.nextInt();\n\t\tlong m=sc.nextLong();\n\t\tif (n==6&&m==9)\n\t\t\tSystem.out.println(1);\n\t\telse {\n\tSystem.out.println(zero(m,n));\n\t\t}\n\t}\n\tpublic static long zero(long n,long a) {\n\t\tlong min=100000;\n\t\tboolean f=true;\n\t\tif (n%2==0) {\n\t\t\tlong x= fac(2,a);\n\t\t\twhile (n%2==0)\n\t\t\t\tn/=2;\n\t\t\tif (x \" + (((10 * // cmod) + i) % mod)); tot += dp(counts, ((10 * cmod) + i) % mod); counts[i]--; } } memo[counts[0]][counts[1]][counts[2]][counts[3]][counts[4]][counts[5]][counts[6]][counts[7]][counts[8]][counts[9]][cmod] = tot; return tot; } public static long fact(int i) { long res = 1; for (int j = 2; j <= i; j++) res *= j; return res; } public static void main(String[] args) { Scanner s = new Scanner(System.in); long N = s.nextLong(); mod = s.nextInt(); String Nrep = \"\" + N; len = Nrep.length(); for (char i : Nrep.toCharArray()) digitcounts[i - '0']++; memo = new long[digitcounts[0] + 1][digitcounts[1] + 1][digitcounts[2] + 1][digitcounts[3] + 1][digitcounts[4] + 1][digitcounts[5] + 1][digitcounts[6] + 1][digitcounts[7] + 1][digitcounts[8] + 1][digitcounts[9] + 1][mod]; for (long[][][][][][][][][][] a : memo) for (long[][][][][][][][][] b : a) for (long[][][][][][][][] c : b) for (long[][][][][][][] d : c) for (long[][][][][][] e : d) for (long[][][][][] f : e) for (long[][][][] g : f) for (long[][][] h : g) for (long[][] i : h) for (long[] j : i) Arrays.fill(j, -1); Arrays.fill( memo[digitcounts[0]][digitcounts[1]][digitcounts[2]][digitcounts[3]][digitcounts[4]][digitcounts[5]][digitcounts[6]][digitcounts[7]][digitcounts[8]][digitcounts[9]], 0); memo[digitcounts[0]][digitcounts[1]][digitcounts[2]][digitcounts[3]][digitcounts[4]][digitcounts[5]][digitcounts[6]][digitcounts[7]][digitcounts[8]][digitcounts[9]][0] = 1; long res = 0; for (int i = 1; i < 10; i++) { if (digitcounts[i] != 0) { int[] count = new int[10]; count[i]++; res += dp(count, i % mod); } } System.out.println(res); s.close(); } }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "273d950745261b3fcc4525b43f3fd978", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.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 DRomanAndNumbers solver = new DRomanAndNumbers();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DRomanAndNumbers {\n public void solve(int testNumber, ScanReader in, PrintWriter out) {\n char[] s = in.scanString().toCharArray();\n int m = in.scanInt();\n int n = s.length;\n for (int i = 0; i < n; i++) {\n if (s[i] != '0') dp[1 << i][(s[i] - '0') % m] = 1;\n }\n int[] si = new int[n];\n for (int i = 0; i < n; i++) si[i] = s[i] - '0';\n Arrays.sort(si);\n\n long[][] dp = new long[1 << n][m];\n dp[0][0] = 1;\n for (int i = 0; i < 1 << n; i++) {\n for (int j = 0; j < m; j++) {\n if (dp[i][j] == 0) continue;\n for (int k = 0; k < n; k++) {\n if (i << 31 - k >= 0) {\n if (i == 0 && si[k] == 0) continue;\n if (k > 0 && si[k] == si[k - 1] && i << 31 - (k - 1) >= 0) continue;\n dp[i | 1 << k][(j * 10 + si[k]) % m] += dp[i][j];\n }\n }\n }\n }\n out.println(dp[(1 << n) - 1][0]);\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 String scanString() {\n int c = scan();\n if (c == -1) return null;\n while (isWhiteSpace(c)) c = scan();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = scan();\n } while (!isWhiteSpace(c));\n return res.toString();\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n else return false;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "671ed8a06b8078823569048ad0a19987", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.concurrent.ArrayBlockingQueue;\n\n\npublic class Main {\n\n InputReader in;\n PrintWriter out;\n\n void run(){\n /*try {\n out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n in = new InputReader(new FileInputStream(\"input.txt\"));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }*/\n out = new PrintWriter(new OutputStreamWriter(System.out));\n in = new InputReader(System.in);\n solve();\n out.flush();\n }\n\n public static void main(String[] args){\n new Main().run();\n }\n\n int[] digits;\n int m;\n int[][] dp;\n int full;\n \n int divisible(int remainder, int taken) {\n if(taken == full) {\n return (remainder == 0 ? 1 : 0);\n }\n if(dp[remainder][taken] != -1)\n return dp[remainder][taken];\n int res = 0;\n for(int i = 0; i < digits.length; i++) {\n if((taken & (1 << i)) == 0) {\n if(taken == 0 && digits[i] == 0)\n continue;\n if(i > 0 && digits[i-1] == digits[i] && (taken & (1 << (i-1))) != 0)\n continue;\n res += divisible((remainder * 10 + digits[i]) % m, taken | (1 << i));\n }\n }\n return dp[remainder][taken] = res;\n }\n\n void solve() {\n String s = in.ns();\n m = in.ni();\n digits = new int[s.length()];\n \nfor(int i = 0; i < 10; i++)\n for(int i = 0; i < digits.length; i++)\n digits[i] = s.charAt(i) - '0';\n dp = new int[101][1<= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int peek() {\n if (numChars == -1)\n return -1;\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n return -1;\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar];\n }\n\n public int ni() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nl() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String ns() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuilder buf = new StringBuilder();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r')\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\n }\n\n public BigInteger readBigInteger() {\n try {\n return new BigInteger(ns());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n }\n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, ni());\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, ni());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public boolean eof() {\n int value;\n while (isSpaceChar(value = peek()) && value != -1)\n read();\n return value == -1;\n }\n\n public String next() {\n return ns();\n }\n\n public SpaceCharFilter getFilter() {\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter) {\n this.filter = filter;\n }\n }\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a9aa350d84e70885ee211660f303a688", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class p401d {\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st;\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (Exception e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long[][] d = new long[19][102];\n public int cnt[] = new int[11];\n\n public int leng(long x) {\n int ret = 0;\n while (x > 0) {\n ret++;\n cnt[(int)(x % 10)]++;\n x /= 10;\n }\n return ret;\n }\n\n public long ans = 0;\n public int inv = 0;\n\n public long pow(long a, int n, long m) {\n if (n == 0)\n return 1;\n if (n == 1)\n return a % m;\n else if (n % 2 == 1)\n return (a * pow(a, n - 1, m)) % m;\n else {\n long b = pow(a, n / 2, m) % m;\n return (b * b) % m;\n }\n }\n\n public void go(int n, int len, long sum, long m) {\n if (len == 0) {\n if (sum == 0) {\n ans++;\n //System.out.println(act + \" \" + act % m);\n }\n return;\n }\n\n for (int i = 0; i < 10; i++) {\n if (len == n && i == 0) {\n continue;\n }\n if (d[len - 1][(int)((((sum + i * pow(10, len - 1, m))) % m + 100l * m)\n % m)] > 0\n && cnt[i] > 0) {\n cnt[i]--;\n go(n, len - 1, ((sum + i * pow(10, len - 1, m)))\n % m, m);\n cnt[i]++;\n }\n }\n }\n\n public void run() throws Exception {\n in = new BufferedReader(new InputStreamReader(System.in));\n //in = new BufferedReader(new FileReader(new File(\"./src/input.txt\")));\n out = new PrintWriter(System.out);\n\n long n = nextLong();\n int m = nextInt();\n int len = leng(n);\n\n // for (int i = 1; i<10; i++)\n // d[1][i % m] += 1;\n d[0][0] = 1l;\n\n for (int i = 0; i < len; i++) {\n for (int j = 0; j < m; j++)\n for (int p = 0; p < 10; p++)\n d[i + 1][(j * 10 + p) % m] += d[i][j];\n }\n\n go(len, len, 0l, m);\n\n out.println(ans);\n\n out.close();\n }\n\n public static void main(String[] args) throws Exception {\n new p401d().run();\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e85a53f9acb176b2aff1338e63410da", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000} {"lang": "Java 8", "source_code": "public class Main{\n public static 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\tpublic static void main(String[] args){\n\t\tScanner in=new Scanner(System.in);\n\t\tlong l=in.nextLong();\n\t\tlong r=in.nextLong();\n\t\tlong x=in.nextLong();\n\t\tlong y=in.nextLong();\n\t\tlong count=0,p=x*y;\n\t\tfor(long i=x;i<=y;i+=x){\n\t\t\tlong rem=p/i;\n\t\t\tif(p%i==0 && rem>=l && rem<=r && i>=l && i<=r && gcd(i,rem)==x){\n\t\t\t\tif(i==rem)count+=2;\n\t\t\t\telse count++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "378942dbe823f07cb3d94d8ae0ddb115", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class prob1\n{\n\tpublic static int gcd(int a,int b){\n\t\twhile(b!=0){\n\t\t\tint p = a%b;\n\t\t\ta=b;\n\t\t\tb=p;\n\t\t}\n\t\treturn a;\n\t}\t\n\t\t\t\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tint l = scan.nextInt();\n\t\tint r = scan.nextInt();\n\t\tint x = scan.nextInt();\n\t\tint y = scan.nextInt();\n\t\tint v =0;\n\t\tif(y%x==0){\n\t\ty = y/x;\n\t\tint v =0;\n\t\tfor(int i=1;i<=Math.sqrt(y);i++){\n\t\t\tint p=y/i;\n\t\t\tif(y%i==0&&gcd(p,i)==1&&i>=l&&i<=r&&p>=l&&p<=r){\n\t\t\t\tif(p!=i){\n\t\t\t\t\tv=v+2;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tv++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t}\n\t\tSystem.out.println(v);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9db459b36640a9c11cfa48a59d42e048", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\t\npublic\t class template\n\t{\n\t\tprivate InputStream is;\n\t\tprivate PrintWriter pw;\n\t\tstatic char[][] ch;\n\t\tstatic int x1,x2,y1,y2,n,m,h,k;\n\t\tstatic long dist[][];\n\t\tstatic boolean boo[][];\n\t\t\n\t\tvoid soln()\n\t\t{\n\t\t\tis = System.in;\n\t\t\tpw = new PrintWriter(System.out);\n\t\t\tlong s = System.currentTimeMillis();\n\t\t\tsolve();\n\t\t\tpw.close();\n\t\t\tpw.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 template().soln();\n\t\t}\n\t\n\t\tvoid solve() \n\t\t{\n\t\t\tlong l = ni(), r = ni(), x = ni(), y = ni();\n\t\t\tlong mul = x*y;\n\t\t\tint cnt = 0;\n\t\t\tif(x==y && x>=l && x<=r) {pw.println(1);return;}\n\t\t\tlong temp = Math.max(l,mul/r);\n\t\t\ttemp += (((temp%x)==0)?0:x-(temp%x))\n\t\t\tfor(long i = temp; i*i<=mul && i<= Math.min(r,mul/l);i+=x){\n\t\t\t\t//pw.println(i);\n\t\t\t\tif(mul%i==0 && gcd(i,mul/i)==x){\n\t\t\t\t\t//pw.println(i);\n\t\t\t\t\tif(mul/i != i) cnt+=2;\n\t\t\t\t\telse cnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(cnt);\n\t\t\tpw.close();\t\n\t\t}\n\t\tlong 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\tvoid printArray(long[] arr) {\n\t\t\tfor(long i : arr) pw.print(i +\" \");\n\t\t\tpw.println();\n\t\t}\n\tstatic long min(long x, long y){\n\t\treturn (x{\n\t\tlong val;\n\t\tint x, y;\n\t\tPair(long v, int a, int b){\n\t\t\tval = v; x = a; y = b;\n\t\t}\n\t\tpublic int compareTo(Pair p){\n\t\t\treturn Long.compare(this.val,p.val);\n\t\t}\n\t}\n\tprivate static class Queue{\n\t\tint st = 0;\n\t\tint et = 0;\n\t\tPair[] arr;\n\t\tpublic Queue(int len) {\n\t\t\tarr = new Pair[len];\n\t\t}\n\t\tpublic boolean isEmpty() {\n\t\t\treturn st==et;\n\t\t}\n\t\tpublic void add(Pair x) {\n\t\t\tarr[et++] = x;\n\t\t}\n\t\tpublic Pair poll() {\n\t\t\treturn arr[st++];\n\t\t}\n\t\tpublic void clear() {\n\t\t\tst = et = 0;\n\t\t}\n\t}\n\t\t/*void bfs(int k) {\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint y = q.poll();\n\t\t\t\tfor(long i : amp[y]) {\n\t\t\t\t\tif(!b[i]) {\n\t\t\t\t\t\tD[i][k] = D[y][k]+1;\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\t*/\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\t\n\t\t/*void 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\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\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b1141a7e86f9c1a7f79eda577c3368ae", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600} {"lang": "Java 8", "source_code": "public class NastyaStudiesInformatics {\n static Integer[][] dp;\n public static void main(String[] args) {\n Scanner scanner=new Scanner(System.in);\n int l=scanner.nextInt();\n int r=scanner.nextInt();\n int x=scanner.nextInt();\n int y=scanner.nextInt();\n int count=0;\n dp=new Integer[r+1][r+1];\n for(int a=l;a<=r;a++){\n for (int b=a;b<=r;b++){\n int gcd=gcd(a,b);\n int lcm=a*b/gcd;\n if(x==gcd && lcm==y){\n if(a==b){\n count++;\n }\n else {\n count=count+2;\n }\n //System.out.println(a+\":\"+b+\":\"+gcd);\n\n }\n\n }\n }\n System.out.println(count);\n }\n static int gcd(int a, int b){\n if(dp[a][b]!=null){\n return dp[a][b];\n }\n if(b == 0) return a;\n dp[a][b]=gcd(b, a% b);\n return dp[a][b];\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4d7f155494cbe48145630e6514dd5b59", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class test{\n\t\n\t// ArrayList lis = new ArrayList();\n\t// ArrayList lis = new ArrayList();\n\t// PriorityQueue

que = new PriorityQueue

();\n\t// PriorityQueue que = new PriorityQueue();\n\t// Stack que = new Stack();\n //\tstatic long sum=0;\n\t// 1000000007 (10^9+7)\n\tstatic int mod = 1000000007;\n\t//static int mod = 1000000009,r=0;\n // static int dx[]={1,-1,0,0};\n//\tstatic int dy[]={0,0,1,-1};\n//\tstatic int dx[]={1,-1,0,0,1,1,-1,-1};\n// static int dy[]={0,0,1,-1,1,-1,1,-1};\n\t//static long H,L;\n\t//static Set set = new HashSet();\n\t\npublic static void main(String[] args) throws Exception, IOException{\n //String line=\"\"; throws Exception, IOException\n //(line=br.readLine())!=null\n\t//Scanner sc =new Scanner(System.in);\n\t// !!caution!! int long // \n\tReader sc = new Reader(System.in);\n // while( ){\n\t // int n=sc.nextInt(),m=sc.nextInt();//a[]=new int[n],b[]=new int[n];\n\tint n=sc.nextInt(),k=sc.nextInt();\n\t//int x[]=new int[n];\n\tint f=0,h=0,fc=1000;\n\t\n long s=0;\n \n \n\tfor(int i=0;i que = new LinkedList

(); \n\tque.add(new P(0,f,h,0,0));\n\tb[0][f][h]=0;\n\twhile( !que.isEmpty() ){\n\t P p=que.poll();\t\n\t// db( p.x,p.y,p.z,p.c,p.a );\n\t \n\t if( fc total) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tif (dp[index][left][a] != -1) {\n\t\t\treturn dp[index][left][a];\n\t\t}\n\t\tlong result = 0;\n\t\tfor (int i = 0; i <= a && i * 50 <= k; i++) {\n\t\t\tfor (int x = 0; x <= left - a && x * 100 + i * 50 <= k; x++) {\n\n\t\t\t\tint other = n - left + x + i;\n\t\t\t\tint nxt = f - a + i;\n\t\t\t\t// System.out.println(left + \" \" + a + \" \" + other + \" \" + nxt);\n\t\t\t\tif (left == x + i) {\n\t\t\t\t\tresult += 1;\n\t\t\t\t\t// System.out.println(\"HE HE\");\n\t\t\t\t\tresult %= MOD;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tlong con = c[a][i] * c[left - a][x];\n\t\t\t\t\tcon %= MOD;\n\t\t\t\t\tfor (int j = 1; j <= other; j++) {\n\t\t\t\t\t\tfor (int h = Math.min(j, nxt); h >= 0; h--) {\n\t\t\t\t\t\t\tif (h * 50 + (j - h) * 100 <= k && other - nxt >= j - h) {\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tlong v = con\n\t\t\t\t\t\t\t\t\t\t* cal(index + 2, left - x - i + j, a\n\t\t\t\t\t\t\t\t\t\t\t\t- i + h, n, f, k, total);\n\t\t\t\t\t\t\t\tv %= MOD;\n\n\t\t\t\t\t\t\t\tv *= c[nxt][h] * c[other - nxt][j - h];\n\t\t\t\t\t\t\t\tv %= MOD;\n\t\t\t\t\t\t\t\tresult += v;\n\t\t\t\t\t\t\t\tresult %= MOD;\n\t\t\t\t\t\t\t}else{\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}\n\t\treturn dp[index][left][a] = result;\n\t}\n\n\tpublic static int min(int left, int a, int n, int f, int k) {\n\t\t// System.out.println(left + \" \" + a);\n\t\tif (left == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (o[left][a] != -2) {\n\t\t\treturn o[left][a];\n\t\t}\n\t\tint result = -1;\n\t\tfor (int i = 0; i <= a && i * 50 <= k; i++) {\n\t\t\tint x = k - i * 50;\n\t\t\tx = x / 100;\n\t\t\tx = Math.min(left - a, x);\n\t\t\tint other = n - left + x + i;\n\t\t\tint nxt = f - a + i;\n\t\t\tif (left == x + i) {\n\t\t\t\tresult = 1;\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tint tmp = Integer.MAX_VALUE;\n\t\t\t\tif (nxt > 0 && (x + i > 1 || x == 1)) {\n\t\t\t\t\ttmp = 2 + min(left - x - i + 1, a - i + 1, n, f, k);\n\t\t\t\t}\n\t\t\t\tif (other > 0 && other != nxt && x + i > 1) {\n\t\t\t\t\ttmp = Math.min(tmp,\n\t\t\t\t\t\t\t2 + min(left - x - i + 1, a - i, n, f, k));\n\t\t\t\t}\n\t\t\t\tif (tmp != Integer.MAX_VALUE && (result == -1 || result > tmp)) {\n\t\t\t\t\tresult = tmp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn o[left][a] = result;\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable {\n\n\t\tint x, y;\n\n\t\tpublic Point(int start, int end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 5;\n\t\t\thash = 47 * hash + this.x;\n\t\t\thash = 47 * hash + this.y;\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (getClass() != obj.getClass()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfinal Point other = (Point) obj;\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.y != other.y) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eded29938e7c02a6ff56a990c8907ca6", "src_uid": "ebb0323a854e19794c79ab559792a1f7", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Abood2D {\n\n\tstatic int N, fifty, hundred, K;\n\tstatic int memo[][][];\n\tstatic int memo2[][][][];\n\tstatic final int MOD = (int) 1e9 + 7;\n\tstatic long[][] comb; \n\n\tstatic int solve(int t, int f, int h) {\n\t\tif(f == 0 && h == 0)\n\t\t\treturn 0;\n\n\t\tif(memo[t][f][h] != -1)\n\t\t\treturn memo[t][f][h];\n\n\t\tif(t == 1)\n\t\t\treturn 1 + (f < fifty ? solve(0, f + 1, h) : solve(0, f, h + 1));\n\n\t\tint ans = (int) 1e6;\n\n\t\tfor (int i = 0; i <= f; i++) {\n\t\t\tif(i * 50 > K)\n\t\t\t\tbreak;\n\n\t\t\tint j = Math.min(( K - i * 50) / 100, h);\n\n\t\t\tint totalW = i * 50 + j * 100;\n\n\t\t\tif(fifty - f + i > 0 && totalW > 50 || hundred - h + j > 1 && totalW > 100 || i == fifty && j == hundred)\n\t\t\t\tans = Math.min(ans, solve(1, f - i, h - j));\n\n\t\t}\n\n\t\treturn ans + 1;\n\t}\n\n\tstatic int solve2(int t, int f, int h, int r) {\n\t\tif(r == 0 && f == 0 && h == 0)\n\t\t\treturn 1;\n\n\n\t\tif(r == 0)\n\t\t\treturn 0;\n\n\t\tif(memo2[t][f][h][r] != -1)\n\t\t\treturn memo2[t][f][h][r];\n\n\n\t\tint ans = 0;\n\n\t\tif(t == 1) {\n\t\t\tfor (int i = 0; i <= fifty - f; i++) {\n\t\t\t\tif(i * 50 > K)\n\t\t\t\t\tbreak;\n\t\t\t\tfor (int j = 0; j <= hundred - h; j++) {\t\t\n\t\t\t\t\tif(i == 0 && j == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tint totalW = i * 50 + j * 100;\n\n\t\t\t\t\tif(totalW > K)\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tans = (int) (1l * ans + ((nCk(fifty - f, i) * nCk(hundred - h, j)) % MOD) * solve2(0, f + i, h + j, r - 1) % MOD);\n\n\t\t\t\t}\n\n\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i <= f; i++) {\n\t\t\t\tif(i * 50 > K)\n\t\t\t\t\tbreak;\n\t\t\t\tfor (int j = 0; j <= h; j++) {\t\t\n\t\t\t\t\tif(i == 0 && j == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tint totalW = i * 50 + j * 100;\n\n\t\t\t\t\tif(totalW > K)\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tans = (int) (1l * ans + ((nCk(f, i) * nCk(h, j)) % MOD) * solve2(1, f - i, h - j, r - 1) % MOD);\n\n\t\t\t\t}\n\n\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}\n\n\n\tstatic long nCk(int n, int k)\t\t// O(n * k)\n\t{\n\t\tif(n < k)\t\t\t\t\t\n\t\t\treturn 0;\n\t\tif(k == 0 || k == n)\t\t//may add k == 1 as a base case for fast calculations\n\t\t\treturn 1;\n\t\tif(comb[n][k] != -1)\n\t\t\treturn comb[n][k];\n\t\tif(n - k < k)\t\t\t\t\n\t\t\treturn comb[n][k] = nCk(n, n - k);\t\t//reduce k to n - k\n\t\treturn comb[n][k] = (((1l * n * nCk(n - 1, k - 1)) % MOD) * pow(k, MOD - 2)) % MOD;\n\t}\n\n\tstatic int pow(int x, long p) {\n\t\tif(p == 0)\n\t\t\treturn 1;\n\n\t\tint ans = 1;\n\t\tif(p % 2 == 1)\n\t\t\tans *= x;\n\n\t\tint c = pow(x, p / 2);\n\n\t\tans = (int) ((1l * ((1l * ans * c) % MOD) * c) % MOD);\n\n\t\treturn ans;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tN = sc.nextInt();\n\t\tK = sc.nextInt();\n\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tif(sc.nextInt() == 50) fifty++; else hundred++;\n\n\t\tmemo = new int[2][fifty + 1][hundred + 1];\n\n\t\tfor (int i = 0; i < 2; i++)\n\t\t\tfor (int j = 0; j <= fifty; j++)\n\t\t\t\tArrays.fill(memo[i][j], -1);\n\n\t\tcomb = new long[100 + 1][100 + 1];\n\n\t\tfor (int i = 0; i <= 100; i++)\n\t\t\tArrays.fill(comb[i], -1);\n\n\t\tint min = solve(0, fifty, hundred);\n\n\t\tif(min >= (int) 1e6){\n\t\t\tout.println(-1);\n\t\t\tout.println(0);\n\t\t}else {\n\t\t\tmemo2 = new int[2][fifty + 1][hundred + 1][min + 1];\n\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tfor (int j = 0; j <= fifty; j++)\n\t\t\t\t\tfor (int j2 = 0; j2 <= hundred; j2++)\n\t\t\t\t\t\tArrays.fill(memo2[i][j][j2], -1);\n\t\t\tout.println(min);\n\t\t\tout.println(solve2(0, fifty, hundred, min));\n\t\t}\n\n\n\t\tout.flush();\n\n\t}\n\n\n\n\tstatic class Scanner \n\n\n\n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "849d943a177f3585d8c6ef88a08ef7e9", "src_uid": "ebb0323a854e19794c79ab559792a1f7", "difficulty": 2100} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n FastScanner in;\n PrintWriter out;\n\n long mod = (long) 1e9 + 7;\n\n void solve() {\n int n = in.nextInt();\n int k = in.nextInt();\n int moves = 300;\n int f = 0;\n for (int i = 0; i < n; i++) {\n if (in.nextInt() == 50)\n f++;\n }\n int s = n - f;\n long[][][][] dp = new long[2][moves][f + 1][s + 1];\n dp[0][0][f][s] = 1;\n long[][] c = new long[100][100];\n for (int i = 0; i < 100; i++) {\n c[i][0] = 1;\n if (i != 0)\n for (int j = 1; j < 100; j++)\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;\n }\n for (int move = 0; move < moves - 1; move++)\n for (int curS = 0; curS < 2; curS++)\n for (int fi = 0; fi <= f; fi++)\n for (int se = 0; se <= s; se++) {\n if (dp[curS][move][fi][se] != 0) {\n int curFi = curS == 0 ? fi : f - fi;\n int curSe = curS == 0 ? se : s - se;\n for (int fi2 = 0; fi2 <= curFi; fi2++)\n for (int se2 = 0; se2 <= curSe; se2++) {\n if (fi2 != 0 || se2 != 0)\n if (fi2 * 50 + se2 * 100 <= k) {\n int nextF = curS == 0 ? fi - fi2\n : fi + fi2;\n int nextS = curS == 0 ? se - se2\n : se + se2;\n long curAdd = (((dp[curS][move][fi][se] * c[curFi][fi2]) % mod) * c[curSe][se2])\n % mod;\n dp[1 - curS][move + 1][nextF][nextS] = (dp[1 - curS][move + 1][nextF][nextS] + curAdd)\n % mod;\n }\n }\n }\n }\n int bestMove = Integer.MAX_VALUE;\n for (int move = 0; move < moves; move++)\n if (dp[1][move][0][0] != 0) {\n bestMove = Math.min(move, bestMove);\n }\n if (bestMove == Integer.MAX_VALUE) {\n out.println(-1);\n out.println(0);\n return;\n }\n out.println(bestMove);\n out.println(dp[1][bestMove][0][0]);\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"test.in\"));\n out = new PrintWriter(new File(\"test.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n }\n\n public static void main(String[] args) {\n new CF().runIO();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4744b73c554e8019f7eec6ec1cf5e2c2", "src_uid": "ebb0323a854e19794c79ab559792a1f7", "difficulty": 2100} {"lang": "Java 8", "source_code": "\n\n import java.util.Scanner;\n \n \n public class Main {\n \tpublic static void main(String[] args) {\n \tScanner s=new Scanner(System.in);\n \tint x=s.nextInt();\n \tint y=s.nextInt();\n \tint a=s.nextInt();\n \tint b=s.nextInt();\n \tint c=s.nextInt();\n \tint d=s.nextInt();\n \tif (a+c<=x && b<=y && d<=y || a+d<=x && b<=y && c<=y || (b+c<=x && a<=y && d<=y) || b+d<=x && a<=y && c<=y || a+c<=y && b<=x && d<=x || a+d<=y && b<=x &&c<=x || b+c<=y && a<=x && d<=x ||b+d<=y && a<=x && c<=x)\n \t{\n \tSystem.out.println(\"YES\");\n \t}\n \telse\n \t{\n \t\tSystem.out.println(\"NO\");\n \t}\n \t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d41d9ab48a79069d025020d64c9caef1", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n \n\npublic class Art {\n \n public static int max(int x,int y){\n if(x>=y)return x;\n else return y;\n }\n \n public static int min(int x,int y){\n if(x<=y)return x;\n else return y;\n }\n \n \n public static void main(String[] args) {\n String message; \n int a1,b1,a2,b2,a3,b3;\n int c=-1;\n Scanner sc =new Scanner(System.in);\n a1=sc.nextInt();\n b1=sc.nextInt();\n a2=sc.nextInt();\n b2=sc.nextInt();\n a3=sc.nextInt();\n b3=sc.nextInt();\n int a=max(a1,b1);\n int b=min(a1,b1); \n if(a1*b1=a3&&b3<=b &&diff1>=0||\n diff1>=b3&&a3<=b ||\n diff3>=a3&&b3<=b ||\n diff3>=b3&&a3<=b ||\n diff2>=a3&&b3<=a ||\n diff2>=b3&&a3<=a ||\n diff4>=a3&&b3<=a ||\n diff4>=b3&&a3<=a) { System.out.println(\"YES\"); }\n \n else \n System.out.println(\"NO\");\n \n \n \n } \n \n \n \n \n }\n\n}\nimport java.util.Scanner;\n \n\npublic class Art {\n \n public static int max(int x,int y){\n if(x>=y)return x;\n else return y;\n }\n \n public static int min(int x,int y){\n if(x<=y)return x;\n else return y;\n }\n \n \n public static void main(String[] args) {\n String message; \n int a1,b1,a2,b2,a3,b3;\n int c=-1;\n Scanner sc =new Scanner(System.in);\n a1=sc.nextInt();\n b1=sc.nextInt();\n a2=sc.nextInt();\n b2=sc.nextInt();\n a3=sc.nextInt();\n b3=sc.nextInt();\n int a=max(a1,b1);\n int b=min(a1,b1); \n if(a1*b1=a3&&b3<=b &&diff1>=0||\n diff1>=b3&&a3<=b ||\n diff3>=a3&&b3<=b ||\n diff3>=b3&&a3<=b ||\n diff2>=a3&&b3<=a ||\n diff2>=b3&&a3<=a ||\n diff4>=a3&&b3<=a ||\n diff4>=b3&&a3<=a) { System.out.println(\"YES\"); }\n \n else \n System.out.println(\"NO\");\n \n \n \n } \n \n \n \n \n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9b01f9a87cbc1881820df63134740142", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.ArrayList;\n\npublic class element { \n \n static boolean Treo(int A,int B,int x,int y){\n return (x<=A && y<=B);\n }\n \n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int a1,a2,a3,b1,b2,b3;\n a1=sc.nextInt(); b1=sc.nextInt();\n a2=sc.nextInt(); b2=sc.nextInt();\n a3=sc.nextInt(); b3=sc.nextInt();\n boolean having=false\n if (Treo(a1,b1,a2,b2))\n {\n if (Treo(a1,b1-b2,a3,b3) || Treo(a1-a2,b1,a3,b3)) having=true;\n if (Treo(a1,b1-b2,a3,b3) || Treo(a1-a2,b1,a3,b3)) having=true;\n } else\n if (Treo(a1,b1,b2,a2))\n {\n if (Treo(a1,b1-a2,a3,b3) || Treo(a1-b2,b1,a3,b3)) having=true;\n if (Treo(a1,b1-a2,a3,b3) || Treo(a1-b2,b1,a3,b3)) having=true;\n }\n \n if (having) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n }\n\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a7518e257b1af6d793759595d71e28c", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class CF560BGetaldIntoArts {\n public static void main(String[] args) {\n\n Scanner s = new Scanner(System.in);\n\n int q = s.nextInt();\n int w = s.nextInt();\n int e = s.nextInt();\n int r = s.nextInt();\n int t = s.nextInt();\n int y = s.nextInt();\n\n if((q*w)) == (e*r) + (t*y)) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9b3d93fc6b0bdc14b345e9493e815d70", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "821c061d74917075366fb79c7060a073", "src_uid": "64e378664209cf1933cf082493a0875c", "difficulty": 3100} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class ComputerGame {\n\n\tstatic double[][] identity;\n\tstatic double INF = 1e18D;\n\tstatic int MAXPOW = 40;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = in.nextInt();\n\t\tlong T = in.nextInt();\n\t\tdouble[] A = new double[N];\n\t\tdouble[] B = new double[N];\n\t\tdouble[] P = new double[N];\n\t\tdouble V = 0;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tA[i] = in.nextDouble();\n\t\t\tB[i] = in.nextDouble();\n\t\t\tP[i] = in.nextDouble();\n\t\t\tV = Math.max(V, P[i]*B[i]);\n\t\t}\n\t\n\t\tCHT cht = new CHT(1);\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tcht.add(P[i], P[i]*A[i], i);\n\t\t}\n\t\tidentity = identity(3);\n\t\tdouble vec[][] = new double[][]{{0}, {0}, {1}}; //prevDp, prevT, prev1\n\t\tfor(CHT.Line l : cht.hull) {\n\t\t\tCHT.Line higherLine = cht.hull.higher(l);\n\t\t\tdouble stopAt = higherLine == null ? INF : l.inter(higherLine);\n\t\t\t\n\t\t\tdouble mat[][] = new double[][] {\n\t\t\t\t{1-P[l.id], P[l.id]*V, P[l.id]*A[l.id]},\n\t\t\t\t{0, 1, 1},\n\t\t\t\t{0, 0, 1},\n\t\t\t};\n\t\t\t\n\t\t\tdouble matToPowerOf2[][][] = new double[MAXPOW][][];\n\t\t\tmatToPowerOf2[0] = identity;\n\t\t\tmatToPowerOf2[1] = mat;\n\t\t\tfor(int i = 2; i < MAXPOW; i++) matToPowerOf2[i] = mult(matToPowerOf2[i-1], matToPowerOf2[i-1]);\n\t\t\t\n//\t\t\tprint(mat);\n\t\t\t\n\t\t\t// Find how long we will use this line for\n\t\t\tdouble cur[][] = identity;\n\t\t\tfor(int i = MAXPOW-1; i >= 0; i--) {\n\t\t\t\tdouble next[][] = mult(cur, matToPowerOf2[i]);\n\t\t\t\tdouble nextVec[][] = mult(next, vec);\n\t\t\t\t\n\t\t\t\tlong t = (long)(nextVec[1][0]);\n\t\t\t\tdouble query = V*t-nextVec[0][0];\n\t\t\t\t\n\t\t\t\tboolean bad = (t > T) || (query > stopAt);\n\t\t\t\tif(!bad) {\n\t\t\t\t\t// Take this expo\n\t\t\t\t\tcur = next;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvec = mult(cur, vec);\n\t\t}\n\t\tSystem.out.println(vec[0][0]);\n\t}\n\t\n\tstatic void print(double a[][]) {\n\t\tfor(int i = 0; i < a.length; i++) {\n\t\t\tSystem.out.println(Arrays.toString(a[i]));\n\t\t}\n\t\tSystem.out.println();\n\t}\n\t\n\tstatic double [][] pow(double m[][], long p) {\n\t\tif(p == 0) return identity;\n\t\tif(p == 1) return m;\n\t\tif((p&1) == 0) {\n\t\t\tdouble res[][] = pow(m, p>>1);\n\t\t\treturn mult(res,res);\n\t\t}\n\t\telse {\n\t\t\treturn mult(m, pow(m, p-1));\n\t\t}\n\t}\n\t\n\tstatic double[][] mult(double a[][], double b[][]){\n\t\tdouble res[][] = new double[a.length][b[0].length];\n\t\tfor(int i = 0; i < a.length; i++) {\n\t\t\tfor(int j = 0; j < b[0].length; j++) {\n\t\t\t\tfor(int k = 0; k < a[i].length; k++) {\n\t\t\t\t\tres[i][j] += a[i][k]*b[k][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\tstatic double[][] identity(int sz) {\n\t\tdouble res[][] = new double[sz][sz];\n\t\tfor(int i = 0; i < sz; i++) res[i][i] = 1;\n\t\treturn res;\n\t}\n\t\n\tstatic class CHT {\n\t\tTreeSet hull;\n\t\tint type; boolean query = false;\n\t\tComparator comp = new Comparator() {\n\t\t\tpublic int compare(Line a, Line b) {\n\t\t\t\tif (!query) return type * Double.compare(a.m, b.m);\n\t\t\t\tif (a.left == b.left) return Double.compare(a.m, b.m);\n\t\t\t\treturn Double.compare(a.left, b.left);\n\t\t\t}\n\t\t};\n\t\t// -1 for min; +1 for max\n\t\tpublic CHT(int typee) { type = typee; hull = new TreeSet<>(comp); }\n\n\t\tpublic void add(double m, double b, int id) { add(new Line(m, b, id)); }\n\n\t\tpublic void add(Line a) {\n\t\t\tLine[] LR = { hull.lower(a), hull.ceiling(a) };\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tif (LR[i] != null && LR[i].m == a.m) {\n\t\t\t\t\tif (type == 1 && LR[i].b >= a.b) return;\n\t\t\t\t\tif (type == -1 && LR[i].b <= a.b) return;\n\t\t\t\t\tremove(LR[i]);\n\t\t\t\t}\n\t\t\thull.add(a);\n\t\t\tLine L = hull.lower(a), R = hull.higher(a);\n\t\t\tif (L != null && R != null && a.inter(R) <= R.left) {\n\t\t\t\thull.remove(a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tLine LL = (L != null) ? hull.lower(L) : null;\n\t\t\tLine RR = (R != null) ? hull.higher(R) : null;\n\t\t\tif (L != null) a.left = a.inter(L);\n\t\t\tif (R != null) R.left = a.inter(R);\n\t\t\twhile (LL != null && L.left >= a.inter(LL)) {\n\t\t\t\tremove(L);\n\t\t\t\ta.left = a.inter(L = LL);\n\t\t\t\tLL = hull.lower(L);\n\t\t\t}\n\t\t\twhile (RR != null && R.inter(RR) <= a.inter(RR)) {\n\t\t\t\tremove(R);\n\t\t\t\tRR.left = a.inter(R = RR);\n\t\t\t\tRR = hull.higher(R);\n\t\t\t}\n\t\t}\n\n\t\tpublic long query(long x) {\n\t\t\tif(hull.size() == 0) return 0;\n\t\t\tLine temp = new Line(0, 0);\n\t\t\ttemp.left = x; query = true;\n\t\t\tlong ans = (long) hull.floor(temp).eval(x);\n\t\t\tquery = false; return ans;\n\t\t}\n\n\t\tprivate void remove(Line x) { hull.remove(x); }\n\n\t\tpublic int size() { return hull.size(); }\n\n\t\tstatic class Line {\n\t\t\tdouble m, b; double left = Long.MIN_VALUE;\n\t\t\tint id;\n\t\t\tpublic Line(double mm, double bb, int ii) { m = mm; b = bb; id = ii;}\n\t\t\tpublic Line(double mm, double bb) { m = mm; b = bb; }\n\t\t\tpublic double eval(double x) { return m * x + b; }\n\t\t\tpublic double inter(Line x) {\n\t\t\t\treturn (double) (x.b - this.b) / (double) (this.m - x.m);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5b63624dc00757fbb10c724fdf31e429", "src_uid": "64e378664209cf1933cf082493a0875c", "difficulty": 3100} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Iterator;\nimport java.io.IOException;\nimport java.util.TreeSet;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 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 DComputerGame solver = new DComputerGame();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DComputerGame {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n long t = in.readLong();\n Quest[] quests = new Quest[n];\n for (int i = 0; i < n; i++) {\n quests[i] = new Quest();\n quests[i].a = in.readInt();\n quests[i].b = in.readInt();\n quests[i].p = in.readDouble();\n }\n\n double E = 0;\n for (int i = 0; i < n; i++) {\n E = Math.max(E, quests[i].p * quests[i].b);\n }\n\n ConvexHullTrick cht = new ConvexHullTrick();\n for (Quest q : quests) {\n cht.insert(q.p, q.a * q.p, q);\n }\n\n long now = 0;\n double begin = 0;\n for (ConvexHullTrick.Line line : cht) {\n double rx = line.rx;\n double finalE = E;\n double finalBegin = begin;\n long finalNow = now;\n LongBinarySearch lbs = new LongBinarySearch() {\n\n public boolean check(long mid) {\n return finalE * mid - to(line.quest, finalE, finalBegin, finalNow, mid) >= rx;\n }\n };\n long until = lbs.binarySearch(now, t);\n begin = to(line.quest, E, begin, now, until);\n now = until;\n\n if (now == t) {\n break;\n }\n }\n\n out.printf(\"%.13f\", begin);\n }\n\n public double to(Quest q, double E, double begin, long now, long to) {\n if (to == now) {\n return begin;\n }\n Matrix matrix = new Matrix(new double[][]{\n {1 - q.p, E * q.p, q.a * q.p},\n {0, 1, 1},\n {0, 0, 1}\n });\n\n Matrix vector = new Matrix(new double[][]{\n {begin},\n {now},\n {1}\n });\n\n //double bf = bf(q.a, q.p, E, (int) t);\n Matrix transform = Matrix.pow(matrix, to - now);\n vector = Matrix.mul(transform, vector);\n return vector.get(0, 0);\n }\n\n }\n\n static abstract class LongBinarySearch {\n public abstract boolean check(long mid);\n\n public long binarySearch(long l, long r) {\n if (l > r) {\n throw new IllegalArgumentException();\n }\n while (l < r) {\n long mid = (l + r) >>> 1;\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 ConvexHullTrick implements Iterable {\n static final double INF = 1e50;\n private TreeSet setOrderByA = new TreeSet(ConvexHullTrick.Line.orderByA);\n private TreeSet setOrderByLx = new TreeSet(ConvexHullTrick.Line.orderByLx);\n\n public ConvexHullTrick.Line insert(double a, double b, Quest quest) {\n ConvexHullTrick.Line newLine = new ConvexHullTrick.Line(a, b);\n newLine.quest = quest;\n boolean add = true;\n while (add) {\n ConvexHullTrick.Line prev = setOrderByA.floor(newLine);\n if (prev == null) {\n newLine.lx = -INF;\n break;\n }\n if (prev.a == newLine.a) {\n if (prev.b >= newLine.b) {\n add = false;\n break;\n } else {\n setOrderByA.remove(prev);\n setOrderByLx.remove(prev);\n }\n } else {\n double lx = ConvexHullTrick.Line.intersectAt(prev, newLine);\n if (lx <= prev.lx) {\n setOrderByA.remove(prev);\n setOrderByLx.remove(prev);\n } else if (lx > prev.rx) {\n add = false;\n break;\n } else {\n prev.rx = lx;\n newLine.lx = lx;\n break;\n }\n }\n }\n\n while (add) {\n ConvexHullTrick.Line next = setOrderByA.ceiling(newLine);\n if (next == null) {\n newLine.rx = INF;\n break;\n }\n double rx = ConvexHullTrick.Line.intersectAt(newLine, next);\n if (rx >= next.rx) {\n setOrderByA.remove(next);\n setOrderByLx.remove(next);\n } else if (rx < next.lx || (newLine.lx >= rx)) {\n ConvexHullTrick.Line lastLine = setOrderByA.floor(newLine);\n if (lastLine != null) {\n lastLine.rx = next.lx;\n }\n add = false;\n break;\n } else {\n next.lx = rx;\n newLine.rx = rx;\n break;\n }\n }\n\n if (add) {\n setOrderByA.add(newLine);\n setOrderByLx.add(newLine);\n }\n\n return newLine;\n }\n\n public Iterator iterator() {\n return setOrderByA.iterator();\n }\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n for (ConvexHullTrick.Line line : this) {\n builder.append(line).append('\\n');\n }\n return builder.toString();\n }\n\n public static class Line {\n double a;\n double b;\n double lx;\n double rx;\n Quest quest;\n static Comparator orderByA = new Comparator() {\n\n public int compare(ConvexHullTrick.Line o1, ConvexHullTrick.Line o2) {\n return Double.compare(o1.a, o2.a);\n }\n };\n static Comparator orderByLx = new Comparator() {\n\n public int compare(ConvexHullTrick.Line o1, ConvexHullTrick.Line o2) {\n return Double.compare(o1.lx, o2.lx);\n }\n };\n\n public Line(double a, double b) {\n this.a = a;\n this.b = b;\n }\n\n public static double intersectAt(ConvexHullTrick.Line a, ConvexHullTrick.Line b) {\n return (b.b - a.b) / (a.a - b.a);\n }\n\n public int hashCode() {\n return (int) (Double.doubleToLongBits(a) * 31 + Double.doubleToLongBits(b));\n }\n\n public boolean equals(Object obj) {\n ConvexHullTrick.Line line = (ConvexHullTrick.Line) obj;\n return a == line.a && b == line.b;\n }\n\n public String toString() {\n return a + \"x+\" + b;\n }\n\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput printf(String format, Object... args) {\n cache.append(String.format(format, args));\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 Quest {\n int a;\n int b;\n double p;\n\n }\n\n static class Matrix implements Cloneable {\n double[][] mat;\n int n;\n int m;\n\n public double get(int i, int j) {\n return mat[i][j];\n }\n\n public Matrix(Matrix model) {\n n = model.n;\n m = model.m;\n mat = new double[n][m];\n asSame(model);\n }\n\n public Matrix(double[][] mat) {\n if (mat.length == 0 || mat[0].length == 0) {\n throw new IllegalArgumentException();\n }\n this.n = mat.length;\n this.m = mat[0].length;\n this.mat = mat;\n }\n\n public Matrix(int n, int m) {\n this.n = n;\n this.m = m;\n mat = new double[n][m];\n }\n\n public void fill(int v) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n mat[i][j] = v;\n }\n }\n }\n\n public void asStandard() {\n fill(0);\n for (int i = 0; i < n && i < m; i++) {\n mat[i][i] = 1;\n }\n }\n\n public static Matrix mul(Matrix a, Matrix b, Matrix c) {\n c.fill(0);\n for (int i = 0; i < c.n; i++) {\n for (int j = 0; j < c.m; j++) {\n for (int k = 0; k < a.m; k++) {\n c.mat[i][j] = c.mat[i][j] + a.mat[i][k] * b.mat[k][j];\n }\n }\n }\n return c;\n }\n\n public static Matrix mul(Matrix a, Matrix b) {\n Matrix c = new Matrix(a.n, b.m);\n return mul(a, b, c);\n }\n\n public static Matrix pow(Matrix x, long n) {\n if (n == 0) {\n Matrix r = new Matrix(x.n, x.m);\n r.asStandard();\n return r;\n }\n Matrix r = pow(x, n >> 1);\n r = Matrix.mul(r, r);\n if (n % 2 == 1) {\n r = Matrix.mul(r, x);\n }\n return r;\n }\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n builder.append(mat[i][j]).append(' ');\n }\n builder.append('\\n');\n }\n return builder.toString();\n }\n\n public void asSame(Matrix matrix) {\n if (matrix.n != n || matrix.m != m) {\n throw new IllegalArgumentException();\n }\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n mat[i][j] = matrix.mat[i][j];\n }\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 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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ee255a06b6b1b99ac86a0c458eafca80", "src_uid": "64e378664209cf1933cf082493a0875c", "difficulty": 3100} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class ComputerGame2 {\n\n\tstatic double[][] identity;\n\tstatic double INF = 1e18D;\n\tstatic int MAXPOW = 40;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = in.nextInt();\n\t\tlong T = in.nextLong();\n\t\tdouble[] A = new double[N];\n\t\tdouble[] B = new double[N];\n\t\tdouble[] P = new double[N];\n\t\tdouble V = 0;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tA[i] = in.nextDouble();\n\t\t\tB[i] = in.nextDouble();\n\t\t\tP[i] = in.nextDouble();\n\t\t\tV = Math.max(V, P[i]*B[i]);\n\t\t}\n\t\n\t\tInteger order[] = new Integer[N];\n\t\tfor(int i = 0; i < N; i++) order[i] = i;\n\t\tArrays.sort(order, (a,b) -> Double.compare(P[a], P[b]));\n\t\tConvexHullLinear cht = new ConvexHullLinear(N+1, 1, 0, true);\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tdouble m = P[order[i]];\n\t\t\tdouble b = P[order[i]]*A[order[i]];\n\t\t\tcht.add(m, b, order[i]);\n\t\t}\n\t\tidentity = identity(3);\n\t\tdouble vec[][] = new double[][]{{0}, {0}, {1}}; //prevDp, prevT, prev1\n\t\tfor(int l = 0; l <= cht.s; l++) {\n\t\t\tdouble stopAt = (l == cht.s ? INF : cht.intersect(l, l+1));\n\t\t\t\n\t\t\tdouble mat[][] = new double[][] {\n\t\t\t\t{1-P[cht.is[l]], P[cht.is[l]]*V, P[cht.is[l]]*A[cht.is[l]]},\n\t\t\t\t{0, 1, 1},\n\t\t\t\t{0, 0, 1},\n\t\t\t};\n\t\t\t\n\t\t\tdouble matToPowerOf2[][][] = new double[MAXPOW][][];\n\t\t\tmatToPowerOf2[0] = identity;\n\t\t\tmatToPowerOf2[1] = mat;\n\t\t\tfor(int i = 2; i < MAXPOW; i++) matToPowerOf2[i] = mult(matToPowerOf2[i-1], matToPowerOf2[i-1]);\n\t\t\t\n//\t\t\tprint(mat);\n\t\t\t\n\t\t\t// Find how long we will use this line for\n\t\t\tdouble cur[][] = identity;\n\t\t\tfor(int i = MAXPOW-1; i >= 0; i--) {\n\t\t\t\tdouble next[][] = mult(cur, matToPowerOf2[i]);\n\t\t\t\tdouble nextVec[][] = mult(next, vec);\n\t\t\t\t\n\t\t\t\tlong t = (long)(nextVec[1][0]);\n\t\t\t\tdouble query = V*t-nextVec[0][0];\n\t\t\t\t\n\t\t\t\tboolean bad = (t > T) || (query > stopAt);\n\t\t\t\tif(!bad) {\n\t\t\t\t\t// Take this expo\n\t\t\t\t\tcur = next;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvec = mult(cur, vec);\n\t\t}\n\t\tSystem.out.println(vec[0][0]);\n\t}\n\t\n\tstatic void print(double a[][]) {\n\t\tfor(int i = 0; i < a.length; i++) {\n\t\t\tSystem.out.println(Arrays.toString(a[i]));\n\t\t}\n\t\tSystem.out.println();\n\t}\n\t\n\tstatic double [][] pow(double m[][], long p) {\n\t\tif(p == 0) return identity;\n\t\tif(p == 1) return m;\n\t\tif((p&1) == 0) {\n\t\t\tdouble res[][] = pow(m, p>>1);\n\t\t\treturn mult(res,res);\n\t\t}\n\t\telse {\n\t\t\treturn mult(m, pow(m, p-1));\n\t\t}\n\t}\n\t\n\tstatic double[][] mult(double a[][], double b[][]){\n\t\tdouble res[][] = new double[a.length][b[0].length];\n\t\tfor(int i = 0; i < a.length; i++) {\n\t\t\tfor(int j = 0; j < b[0].length; j++) {\n\t\t\t\tfor(int k = 0; k < a[i].length; k++) {\n\t\t\t\t\tres[i][j] += a[i][k]*b[k][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\tstatic double[][] identity(int sz) {\n\t\tdouble res[][] = new double[sz][sz];\n\t\tfor(int i = 0; i < sz; i++) res[i][i] = 1;\n\t\treturn res;\n\t}\n\t\n\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-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 double query(double x) {\n\t\t\treturn wrapper(x) * (isMin ? -1 : 1);\n\t\t}\n\t\tpublic double wrapper(double x) {\n\t\t\tif(p > s || (upd && type*inc < 0)) p = s;\n\t\t\tupd = false;\n\t\t\tif(type == 0) { //Binary search in log(n)\n\t\t\t\tint lo = 0;\n\t\t\t\tint hi = s;\n\t\t\t\twhile(lo < hi) {\n\t\t\t\t\tint mid = lo + (hi-lo)/2;\n\t\t\t\t\tif(eval(mid,x) < eval(mid+1,x)) lo = mid+1;\n\t\t\t\t\telse hi = mid;\n\t\t\t\t}\n\t\t\t\treturn eval(lo,x);\n\t\t\t}\n\t\t\telse if(type*inc < 0) { //search from p -> 0\n\t\t\t\twhile(p >= 1 && eval(p,x) < eval(p-1,x)) p--;\n\t\t\t\treturn eval(p, x);\n\t\t\t}\n\t\t\telse { //search from p -> s\n\t\t\t\twhile(p < s && eval(p,x) < eval(p+1,x)) p++;\n\t\t\t\treturn eval(p, x);\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 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "67571299a0678b59251616b897503880", "src_uid": "64e378664209cf1933cf082493a0875c", "difficulty": 3100} {"lang": "Java 6", "source_code": "import java.io.*;\n\nimport java.util.*;\n\npublic class CodeForces {\n\n\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tlong sum = n;\n\t\tboolean arr[] = new boolean[n + 1];\n\t\tArrays.fill(arr, true);\n\t\tint a = 2;\n\t\tList ls = new ArrayList();\n\t\tdouble sq = Math.sqrt(n);\n\t\twhile (a <= sq) {\n\t\t\tif (arr[a]) {\n\t\t\t\tint t = 2 * a;\n\t\t\t\twhile (t <= sq) {\n\t\t\t\t\tarr[t] = false;\n\t\t\t\t\tt += a;\n\t\t\t\t}\n\t\t\t\tls.add(a);\n\t\t\t}\n\t\t\ta++;\n\t\t}\n\t\tint l = ls.size();\n\t\twhile (n > 1) {\n\t\t\tint i = 0;\n\t\t\twhile (ls.get(i)<=sq && n % ls.get(i) != 0) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tif(ls.get(i)>sq) {\n\t\t\t\tn = 1;\n\t\t\t} else {\n\t\t\t\tn = n / ls.get(i);\n\t\t\t}\n\t\t\tsq = Math.sqrt(n);\n\t\t\tsum += n;\n\t\t}\n\t\tout.println(sum);\n\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew CodeForces().run();\n\t}\n\n\tint NOD(int a, int b) {\n\t\twhile (a != 0 && b != 0) {\n\t\t\tif (a >= b)\n\t\t\t\ta = a % b;\n\t\t\telse\n\t\t\t\tb = b % a;\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\tboolean isOuterFile = false;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tif (isOuterFile) {\n\t\t\t\treader = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(new BufferedWriter(new FileWriter(\n\t\t\t\t\t\t\"output.txt\")));\n\t\t\t} else {\n\t\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t}\n\n\t\t\ttokenizer = null;\n\t\t\t//long time = new Date().getTime();\n\t\t\tsolve();\n\t\t\t//out.println(time - new Date().getTime());\n\t\t\treader.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\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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "39fcc34b22a696e63858a1d075c35175", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1200} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Easy {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int sum = 0;\n if (n % 2 == 0) {\n sum += n;\n while (n != 0) { \n if (n%2 == 1 || n == 2) {\n sum++;\n break;\n }\n sum += n / 2;\n n /= 2;\n }\n }\n else {\n sum = sum + n + 1;\n }\n System.out.println(sum);\n sc.close();\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "06174ed8ae38181f42caa9e86fcd45d7", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1000} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class test2\n{\n\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew test2().run();\n\t}\n\n\tPrintWriter out = null;\n\tint[] dp = null;\n\n\tint play(int n)\n\t{\n\t\tif (n == 1)\n\t\t\treturn 1;\n\n\t\tif (dp[n] > 0)\n\t\t\treturn dp[n];\n\n\t\tint max = 0;\n\t\tfor (int i = 2; i <= n; i++)\n\t\t{\n\t\t\tif (n % i == 0)\n\t\t\t\tmax = Math.max(max, play(n / i));\n\t\t}\n\n\t\tdp[n] = n + max;\n\t\treturn dp[n];\n\t}\n\n\tvoid run() throws Exception\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tint n = in.nextInt();\n\t\tdp = new int[n + 1];\n\n\t\tout.println(play(n));\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6dd0317a4b73df635c83d955246f157f", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1200} {"lang": "Java 6", "source_code": "import java.io.*;\n\nimport java.util.*;\n\npublic class CodeForces {\n\n\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tlong sum = n;\n\t\tboolean arr[] = new boolean[n + 1];\n\t\tArrays.fill(arr, true);\n\t\tint a = 2;\n\t\tList ls = new ArrayList();\n\t\tdouble sq = Math.sqrt(n);\n\t\twhile (a <= sq) {\n\t\t\tif (arr[a]) {\n\t\t\t\tint t = 2 * a;\n\t\t\t\twhile (t <= sq) {\n\t\t\t\t\tarr[t] = false;\n\t\t\t\t\tt += a;\n\t\t\t\t}\n\t\t\t\tls.add(a);\n\t\t\t}\n\t\t\ta++;\n\t\t}\n\t\tint l = ls.size();\n\t\twhile (n > 1) {\n\t\t\tint i = 0;\n\t\t\twhile (i= b)\n\t\t\t\ta = a % b;\n\t\t\telse\n\t\t\t\tb = b % a;\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\tboolean isOuterFile = false;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tif (isOuterFile) {\n\t\t\t\treader = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(new BufferedWriter(new FileWriter(\n\t\t\t\t\t\t\"output.txt\")));\n\t\t\t} else {\n\t\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t}\n\n\t\t\ttokenizer = null;\n\t\t\t//long time = new Date().getTime();\n\t\t\tsolve();\n\t\t\t//out.println(time - new Date().getTime());\n\t\t\treader.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\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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b5afb3de53c56cf60d5d7ebe0b836230", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\npublic class a {\n public static void main(String[]args){\n Scanner sc = new Scanner(System.in);\n int n =sc.nextInt();\n if(n%2!=0){\n System.out.println(n/2);\n return;\n }\n System.out.println(n/2-1)\n}}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "615f30a186fb1ba2752e9f981f80419a", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class CF_804a {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in;\n\t\tint n,i;\n\t\tn=sc.nextInt();\n\t\tSystem.out.print(n/2);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "79005d93e35aaa63d83b634a18cdf241", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class math{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int i = sc.nextInt();\n System.out.print(j);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6d1cc209a7cb1ace3a27f64b21e7d4f3", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class CF_804a {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in;\n\t\tint n,i;\n\t\tn=sc.nextInt();\n\t\tn--;\n\t\tSystem.out.print(n/2);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0f40a5b7a3f2e47110fb6c0d969190f0", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\nimport junit.framework.Assert;\n\nimport org.junit.Test;\n\npublic class A {\n\n public static void main( final String[] args ) throws IOException {\n final BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );\n final String items = br.readLine();\n System.out.println( solve( items ) );\n }\n\n private static int solve( final String items ) {\n if ( items.length() == 0 )\n return 0;\n int cnt = 1;\n int group = 1;\n char type = items.charAt( 0 );\n for ( int i = 1; i < items.length(); ++i ) {\n final char c = items.charAt( i );\n if ( c == type ) {\n if ( group == 5 ) {\n ++cnt;\n group = 0;\n } else {\n ++group;\n }\n } else {\n ++cnt;\n group = 1;\n type = c;\n }\n }\n return cnt;\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "393fb93d2838337ab51b0d3b5ab7d012", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900} {"lang": "Java 7", "source_code": "public class Task137A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString w = sc.next();\n\t\tsc.close();\n\t\t\n\t\tint c = 0;\n\t\tint h = 1;\n\t\t\n\t\tfor (int i = 0; i < w.length() - 1; i++) {\n\t\t\tif (w.charAt(i) == w.charAt(i + 1)) {\n\t\t\t\th++;\n\t\t\t} else {\n\t\t\t\th = 0;\n\t\t\t\tc++;\n\t\t\t}\n\t\t\tif (h == 5) {\n\t\t\t\th = 1;\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t\tif (w.charAt(w.length() - 2) != w.charAt(w.length() - 1)) { c++; }\n\t\tSystem.out.println(c);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "54195486511a9579b11019105ffcf9a2", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class MainClass {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int count = 0, c=0, p=0;\n String x = in.next();\n for (int i=0; i= MODULO) {\n CHOOSE[i][j] -= MODULO;\n }\n }\n }\n\n POWER = new int[SIZE * SIZE];\n POWER[0] = 1;\n for (int i = 1; i < POWER.length; ++i) {\n POWER[i] = POWER[i - 1] + POWER[i - 1];\n if (POWER[i] >= MODULO) {\n POWER[i] -= MODULO;\n }\n }\n }\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt();\n int[] f = new int[n + 1];\n int[] g = new int[n + 1];\n f[0] = 1;\n f[1] = 1;\n g[0] = g[1] = 1;\n for (int i = 2; i <= n; ++i) {\n g[i] = POWER[i * (i - 1) / 2];\n f[i] = f[i - 1];\n for (int j = 1; j < i; ++j) {\n f[i] = (int) ((f[i] + CHOOSE[i - 1][j] * (long) (f[i - 1 - j])) % MODULO);\n }\n// out.println(\"f[\" + i + \"] = \" + f[i]);\n }\n int[] t = new int[n + 1];\n t[0] = 1;\n t[1] = 2;\n for (int i = 2; i <= n; ++i) {\n t[i] = (t[i - 1] * 2) % MODULO;\n for (int j = 1; j < i; ++j) {\n t[i] = (int) ((t[i] + CHOOSE[i - 1][j] * (long) (t[i - 1 - j])) % MODULO);\n }\n// out.println(\"t[\" + i + \"] = \" + t[i]);\n }\n out.println((t[n] - f[n] + MODULO) % MODULO);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "67a853772daf66e560f559427687430c", "src_uid": "aa2c3e94a44053a0d86f61da06681023", "difficulty": 1900} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class WizardsDemonstration\n{\n\tpublic static int returnY(int n,int x,int y) \n\t{\t\n\t\tint calculateYValue = (int)Math.ceil((y*n)/100.0);\n\t\t//System.out.println(calculateYValue);\n\t\tint requiredNumberOfPeople = calculateYValue-x;\n\t\tif(requiredNumberOfPeople>=0)\n\t\t\treturn requiredNumberOfPeople;\n\t}\n\n\tpublic static void main(String argz[])\n\t{\n\t\ttry\n\t\t{\n\t\t\tint n,x,y;\n\t\t\tScanner reader = new Scanner(System.in);\n\t\t\tn = reader.nextInt();\n\t\t\tx = reader.nextInt();\n\t\t\ty = reader.nextInt();\n\n\t\t\tif(n<1 || x>n || y > 10000)\n\t\t\t\tSystem.exit(0);\n\t\t\t\n\t\t\tSystem.out.println(returnY(n,x,y));\n\t\t}\n\n\t\tcatch(Exception ex)\n\t\t{\n\t\t\tex.printStackTrace();\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "08656e0b4164b6fcdf3eaa97893e6eb9", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedInputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n/**\n *\n * @author sukhdeep\n */\npublic class Test {\n \n \n \n \n public static void main(String ar[]) throws IOException {\n\n IntStreamReader r=new IntStreamReader(System.in); \n double n=r.getNextInt();\n double x=r.getNextInt();\nouble y=r.getNextInt();\nn=(n*y)/100;\n\nif(x '9')) \n {\n i++;\n }\n if(i= '0' && buff[i] <= '9') )\n {\n parsedInt *= 10;\n parsedInt += buff[i] - '0';\n i++;\n }\n \n if (i == buff.length) \n {\n \n int j = 0;\n for (; offset < buff.length; j++, offset++) \n {\n buff[j] = buff[offset];\n }\n \n inp.read(buff, j, size - j);\n \n offset = 0;\n parsedInt = getNextInt();\n } \n else \n {\n offset = i;\n }\n if(flag==0)\n return parsedInt;\n else\n return -parsedInt;\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3a6364a02334cc3a4507a5090ee6839a", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedInputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\n/**\n *\n * @author sukhdeep\n */\npublic class Test {\n \n \n \n \n public static void main(String ar[]) throws IOException {\n\n IntStreamReader r=new IntStreamReader(System.in); \n double n=r.getNextInt();\n double x=r.getNextInt();\nouble y=r.getNextInt();\nn=(n*y)/100;\n//System.out.println(n);\n\nif(x '9')) \n {\n i++;\n }\n if(i= '0' && buff[i] <= '9') )\n {\n parsedInt *= 10;\n parsedInt += buff[i] - '0';\n i++;\n }\n \n if (i == buff.length) \n {\n \n int j = 0;\n for (; offset < buff.length; j++, offset++) \n {\n buff[j] = buff[offset];\n }\n \n inp.read(buff, j, size - j);\n \n offset = 0;\n parsedInt = getNextInt();\n } \n else \n {\n offset = i;\n }\n if(flag==0)\n return parsedInt;\n else\n return -parsedInt;\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "59ca740f62e23500ce0d3b10e728bbd2", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n/**\n * User: MiF\n * Date: 27.03.12\n * Time: 19:00\n */\npublic class AClass {\n\n public static void main(String[] args) {\n Scanner scaner=new Scanner(System.in);\n \n int n=scaner.nextInt(),vol=scaner.nextInt(),proc=scaner.nextInt(),rez;\n\n rez=Math.ceil((n*proc-100*vol)/100.0);\n\n System.out.print(\"\"+((rez>0) ? rez : 0));\n return;\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d6656639dc271b8932171f8721f9902f", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900} {"lang": "Java 8", "source_code": "\n import java.util.* ; \npublic class Contest\n{\n public static void main(String a[])\n {\n Scanner sc = new Scanner(System.in) ;\n int ct1 = sc.nextInt() ; \n int ct2 = sc.nextInt() ;\n int ct3 = sc.nextInt() ;\n int ct4 = sc.nextInt() ;\n int mp = (ct1 + ct4) * 2 ;\n int mp1 = (ct3 + ct3) * 2 ;\n if(mp <= mp1)\n System.out.println(1) ; \n else\n System.out.println(0) ;\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "518bf662a1956043dbdb7a1d9b3db8c7", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class file {\n public static void main(String[] args){\n Scanner s=new Scanner (System.in);\n int c1=s.nextInt();\n int c2=s.nextInt();\n int c3=s.nextInt();\n int c4=s.nextInt();\n if (c1==0 && c2==0 && c4==0 && c3!=0)\n {\n System.out.print(0)\n return;\n }\n if ((c1==c4)|| (c1+c2==c3+c4) ||(c1+c3==c2+c4))\n System.out.print(1);\n else\n System.out.print(0);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aa9f7f3a2141386f74ff9fe5c4a12ace", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\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\tif(a==0 && c!=0) {\n\t\t System.out.println(0);\n\t\t} else if(d==0 && c!=0) {\n\t\t System.out.println(0);\n\t\t} else if(a==d) {\n\t\t System.out.println(1);\n\t\t} else {\n\t\t System.out.println(0);\n\t\t}\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a9c9e9a3b3b3d4e2763305f6d4b744f9", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Stack;\n\npublic class trials {\n\n\tpublic static void main(String[] args) {\n\t\t//Stack x= new Stack ();\n\t\tboolean done=false;\n\t\tScanner sc= new Scanner(System.in);\n\t\tint []z = new int [4];\n\t\tString c1=\"((\";\n\t\tString c2=\"()\";\n\t\tString c3=\")(\";\n\t\tString c4=\"))\";\n\t\tfor(int i=0;i<4;i++) {\n\t\t\tz[i]=sc.nextInt();\n\t\t\tif(z[0]==0 && z[1]==0 & z[2]==0 & z[3]==0) {\n\t\t\t\tSystem.out.println(1);\n\t\t\t\tdone=true;\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t///\tSystem.out.println(z[3]%z[]);\n\t\twhile(!done && z[0]!=0 &&z[2]!=0 && z[3]!=0) {\n\t\t\tif(z[2]%z[0]==0 &&z[2]%z[3]==0) {\n\t\t\t\tSystem.out.println(1);\n\t\t\t\tdone = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tz[0]--;\n\t\t\t\tz[3]--;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\tif(!done)\n\t\tSystem.out.println(0);\n\t\t\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad3e39009a3ebc09182e05e489a2f712", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF991C {\n\tpublic static void main(String[]args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\t\n\t\tlong half = (long) (0.5*n);\n\t\tboolean target = false;\n\t\t\n\t\tlong calc,k=0,tempN=n;\n\n\t\twhile(!target) {\n\t\t\tcalc=0;\n\t\t\tk++;\n\t\t\tn=tempN;\n\t\t\twhile(n>0&&!target) {\n\t\t\t\tn-=Math.min(n,k);\n\t\t\t\tcalc+=Math.min(n,k);\n\t\t\t\tif(n>=10)n-=(long) (0.1*n);\n\t\t\t\tif(calc>=half)target=true;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(k);\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\t\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\t\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\t\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\t\t\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\t}\n\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8e3317a1f4c7e6917dd7a539fc5c6b4", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class candies {\n public static boolean test(long k, long num) {\n long sum = 0;\n long current = num;\n while(current > 0) {\n long temp = Math.min(current, k);\n sum += temp;\n current -= temp;\n current -= (current/10);\n }\n return sum*2 >= num;\n }\n \n public static void main(String[] args) {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong n = Long.parseLong(input.readLine());\n\t\tlong start = 1;\n\t\tlong end = n;\n\t\tlong sol = n;\n\t\twhile(start <= end) {\n\t\t long mid = (start + end)/2;\n\t\t if(test(mid,n)) {\n\t\t sol = mid;\n\t\t end = mid-1;\n\t\t }\n\t\t else {\n\t\t start = mid+1;\n\t\t }\n\t\t}\n\t\tSystem.out.println(sol);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5f9f0d3a207d502b63dc626556f53aa9", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class candies {\n public static boolean test(long k, long num) {\n long sum = 0;\n long current = num;\n while(current > 0) {\n long temp = Math.min(current, k);\n sum += temp;\n current -= temp;\n current -= (current/10);\n }\n }\n \n public static void main(String[] args) {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong n = Long.parseLong(input.readLine());\n\t\tlong start = 1;\n\t\tlong end = n;\n\t\tlong sol = n;\n\t\twhile(start <= end) {\n\t\t long midp = (start + end)/2;\n\t\t if(test(mid,n)) {\n\t\t sol = mid;\n\t\t end = mid-1;\n\t\t }\n\t\t else {\n\t\t start = mid+1;\n\t\t }\n\t\t}\n\t\tSystem.out.println(sol);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dba6c55cdab0f97b7f39d40bd138c7e6", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.*\nimport java.io.*\n\npublic class candies {\n public static boolean test(long k, long num) {\n long sum = 0;\n long current = num;\n while(current > 0) {\n long temp = Math.min(current, k);\n sum += temp;\n current -= temp;\n current -= (current/10);\n }\n }\n \n public static void main(String[] args) {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong n = Long.parseLong(input.readLine());\n\t\tlong start = 1;\n\t\tlong end = n;\n\t\tlong sol = n;\n\t\twhile(start <= end) {\n\t\t long midp = (start + end)/2;\n\t\t if(test(mid,n)) {\n\t\t sol = mid;\n\t\t end = mid-1;\n\t\t }\n\t\t else {\n\t\t start = mid+1;\n\t\t }\n\t\t}\n\t\tSystem.out.println(sol);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da2f4b942ecc2664cb0759b809d6985a", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[]args){\n Scanner input = new Scanner(System.in);\n int x = input.nextInt();\n int y = input.nextInt();\n if((remoZero(x + y)) == (remoZero(x) + remoZero(y)))\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n public static int remoZero(int n){\n String s = String.valueOf(n);\n return Integer.parseInt(s.replace(\"0\", \"\"));\n }\n}\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e7664d5393106c34213158380d6cdb40", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000} {"lang": "Java 6", "source_code": "import com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 4/13/11\n * Time: 8:28 PM\n */\npublic class TaskA {\n public static void main(String[] args) {\n reader = new BufferedReader(new InputStreamReader(System.in));\n\n String A = next(), B = next();\n int c = Integer.parseInt(A) + Integer.parseInt(B);\n A = A.replace(\"0\", \"\");\n B = B.replace(\"0\", \"\");\n if (c == Integer.parseInt(A) + Integer.parseInt(B)) {\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n\n }\n\n\n public static BufferedReader reader;\n\n public static StringTokenizer tokenizer = null;\n\n static 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 static public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n static public String next() {\n return nextToken();\n }\n\n static public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fdf71d852a47f6bd9822b1f10b7d6179", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\n\nimport java.io.IOException;\n\nimport java.io.InputStreamReader;\n\n \n\npublic class LifeWithoutZero {\n\n public static void main(String[] args) {\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n String n1 = \"\", n2 = \"\", aa = \"\", bb = \"\", ss = \"\", sss = \"\";\n\n int a, b, sum, s;\n\n try {\n\n n1 = br.readLine();\n\n n2 = br.readLine();\n\n a = Integer.parseInt(n1);\n\n b = Integer.parseInt(n2);\n\n sum = a + b;\n\n ss = sum + \"\";\n\n for (int i = 0; i < n1.length(); i++) {\n\n if (Integer.parseInt(n1.substring(i, i + 1)) != 0) {\n\n aa += n1.substring(i, i + 1);\n\n }\n\n }\n\n for (int i = 0; i < n2.length(); i++) {\n\n if (Integer.parseInt(n2.substring(i, i + 1)) != 0) {\n\n bb += n2.substring(i, i + 1);\n\n }\n\n }\n\n for (int i = 0; i < ss.length(); i++) {\n\n if (Integer.parseInt(ss.substring(i, i + 1)) != 0) {\n\n sss += ss.substring(i, i + 1);\n\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f79c189256c92a34bc6608f1edd32d58", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Hello\n{\n public int removeZero(int m)\n {\n int reverse = 0;\n while(m>0)\n {\n if(m%10!=0)\n reverse = (reverse*10)+(m%10);\n m/=10;\n }\n int sum = 0;\n while(reverse>0)\n {\n sum = sum*10+(reverse%10);\n reverse/=10;\n }\n return sum;\n }\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int m = sc.nextInt();\n int n = sc.nextInt():\n int sum = m+n;\n int k = removeZero(m);\n int l = removeZero(n);\n int s = removeZero(k+l);\n if(k+l==s)\n System.out.println(\"Yes\");\n else\n System.out.println(\"No\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "808fcced62f1b5b10ccf14c9ea1a8991", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class QuickQuantifiers {\n\n\tprivate static final Scanner SCANNER = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\t\tint input = SCANNER.nextInt();\n\t\tif(!input % 2 == 0) {\n\t\t\tSystem.out.println(\"1\");\n\t\t} else {\n\t\t\tSystem.out.println(\"0\");\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1cd45f8670ade6126898b19969e1a9cb", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800} {"lang": "Java 8", "source_code": "public class A{\n public static void main(String[] args) throws Exception {\n Scanner scan = new Scanner(System.in) ;\n int a = scan.nextInt();\n System.out.println(a%2);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02ce8e3332d1549b0dd3fed204561191", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800} {"lang": "Java 8", "source_code": "public class Driver {\n\n\tpublic static Scanner scanner;\n\n\tpublic static void main(String[] args) {\n\n\t\tscanner = new Scanner(System.in);\n\t\tDriver driver = new Driver();\n\n\t\tint n = scanner.nextInt();\n\t\t\n\t\tif(n%2==0) {\n\t\t\tSystem.out.println(0);\n\t\t}else {\n\t\t\tSystem.out.println(1);\n\t\t}\n\t\t\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7db935130d2dd79eca285064c39985f3", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n if(n%2=0)\n System.out.println(\"0\");\n \n else{\n System.out.println(\"1\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0cc341bc4ebbd42fc88abb69761f4d5f", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\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\tnew Main().run();\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\tlong MOD = 1000000009L;\n\t\n\tint N;\n\tint M;\n\tList sss = new ArrayList(10);\n\tList ss = new ArrayList(10);\n\tchar[][] s;\n\t\n\tlong[][] dp;\n\n\tString checkS;\n\tint checkL;\n\tint checkI;\n\t\n\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tN = nextInt();\n\t\tM = nextInt();\n\t\t\n\t\tfor (int i = 0; i < M; i++) {\n\t\t\tString cs = nextToken();\n\t\t\tif (cs.length() <= N)\n\t\t\t\tsss.add(cs);\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < sss.size(); i++) {\n\t\t\tString si = sss.get(i);\n\t\t\tcheckS = si;\n\t\t\tcheckL = si.length();\n\t\t\tcheckI = i;\n\t\t\tfill(used, false);\n\t\t\tif (!rec(0)) {\n\t\t\t\tss.add(si);\n\t\t\t}\n\t\t}\n\t\t\n\t\tM = ss.size();\n\t\t\n\t\tif (M == 0) {\n\t\t\tout.println(0);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\ts = new char [M][];\n\t\tfor (int i = 0; i < M; i++)\n\t\t\ts[i] = ss.get(i).toCharArray();\n\t\t\n\t\tdp = new long [N + 1][M];\n\t\tfor (int i = 0; i < M; i++)\n\t\t\tdp[s[i].length][i]++;\n\t\tfor (int pos = 0; pos < N; pos++) {\n\t\t\tfor (int last = 0; last < M; last++) {\n\t\t\t\tif (dp[pos][last] == 0L) continue;\n\t\t\t\tfor (int next = 0; next < M; next++) {\n\t\t\t\t\tfor (int offset = 1; offset <= s[last].length; offset++) {\n\t\t\t\t\t\tif (can(last, next, offset)) {\n\t\t\t\t\t\t\tint npos = pos - s[last].length + offset + s[next].length;\n\t\t\t\t\t\t\tif (npos <= N)\n\t\t\t\t\t\t\t\tdp[npos][next] = (dp[npos][next] + dp[pos][last]) % 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\tfor (long[] a : dp)\n//\t\t\tSystem.out.println(Arrays.toString(a));\n\t\t\n\t\tlong ans = 0L;\n\t\tfor (int last = 0; last < M; last++)\n\t\t\tans = (ans + dp[N][last]) % MOD;\n\t\tout.println(ans);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tboolean[] used = new boolean [20];\n\t\n\tboolean rec(int pos) {\n\t\tif (pos == checkL) return true;\n\t\tif (used[pos]) return false;\n\t\tused[pos] = true;\n\t\tfor (int i = 0; i < M; i++) {\n\t\t\tif (i == checkI) continue;\n\t\t\tString cs = sss.get(i);\n\t\t\tfor (int offset = 0; offset < checkL; offset++) {\n\t\t\t\tint npos = offset + cs.length();\n\t\t\t\tif (npos <= checkL && match(offset, cs)) {\n\t\t\t\t\tif (rec(npos))\n\t\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tboolean match(int offset, String s) {\n\t\tfor (int i = 0; i < s.length(); i++)\n\t\t\tif (checkS.charAt(offset + i) != s.charAt(i))\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tboolean can(int last, int next, int offset) {\n\t\tchar[] s1 = s[last];\n\t\tchar[] s2 = s[next];\n\t\tif (offset + s2.length <= s1.length) return false;\n\t\tfor (int i = offset; i < s1.length; i++)\n\t\t\tif (s1[i] != s2[i - offset])\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\t/*************************************************************** \n\t * Input \n\t **************************************************************/\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\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\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\t\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43fdfc2c17d3fd26ee44f0f75bbfb558", "src_uid": "3f053c07deaac55c2c51df6147080340", "difficulty": 2500} {"lang": "Java 6", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.util.Set;\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 Solution {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTask solver = new Task();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass Task\n{\n public void solve(int testNumber, InputReader in, PrintWriter out)\n {\n int n = in.nextInt();\n int m = in.nextInt();\n String[] Viruses = new String[m];\n for (int i = 0; i < m; i++)\n {\n Viruses[i] = in.nextToken();\n }\n HashMap Index = new HashMap();\n int lastIndex = 1;\n for (int i = 0; i < m; i++)\n {\n for (int j = 0; j < Viruses[i].length(); j++)\n {\n Index.put(Viruses[i].substring(0, j + 1), lastIndex++);\n }\n }\n Index.put(\"\",0);\n int[][] replaceMent = new int[lastIndex][26];\n int[] longestSuffix = new int[lastIndex];\n //\u041d\u0430\u0439\u0434\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0439:\n for (String s : Index.keySet())\n for (String t : Viruses)\n if (s.endsWith(t))\n longestSuffix[Index.get(s)] = Math.max(longestSuffix[Index.get(s)], t.length());\n\n //\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043c\u044b \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 I, \u0438 \u043f\u0438\u0448\u0435\u043c \u0431\u0443\u043a\u0432\u0443 CH. \u041d\u0430\u0439\u0434\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442c\u044f:\n\n for (String s : Index.keySet()) {\n int start = Index.get(s);\n for (char ch = 'A'; ch <= 'Z'; ch++) {\n String candidate=s.concat(Character.toString(ch));//\u0431\u0435\u0440\u0435\u043c \u043f\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0443\n while (!Index.containsKey(candidate))\n candidate = candidate.substring(1);//\u043e\u0442\u0440\u0435\u0437\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b\n replaceMent[start][ch-'A'] = Index.get(candidate);\n }\n }\n\n int[][] dp = new int[Index.size()][20]; //\u0417\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0435 I \u043f\u0440\u0438\u043c\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439\n //\u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0418 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0435\u043d\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430\n int modulo=1000000009;\n dp[Index.get(\"\")][0] = 1;//\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0430 \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430\n for (int idx = 0; idx < n; ++idx) {\n int[][] newDp = new int[Index.size()][20];\n for (int oldprefix = 0; oldprefix < lastIndex; oldprefix++)\n for (int oldCover = 0; oldCover < 20; oldCover++) {\n for (char ch='A'; ch <='Z'; ch++) {\n int newPrefix = replaceMent[oldprefix][ch-'A'];\n int newCover = oldCover + 1; //\u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430 1 \u0431\u043e\u043b\u044c\u0448\u0435,\u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u043b\u0438\u0441\u044c \u043d\u0430 1\n if (newCover <= longestSuffix[newPrefix])\n newCover = 0;//\u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u043a\u0440\u044b\u043b\u0438 \u0442\u043e \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u043d\u0430\u043a\u0440\u044b\u0442\u043e, \u0442\u043e we are happy!\n if (newCover >=20)//\u0442\u044f\u0436\u0435\u043b\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\n continue;\n newDp[newPrefix][newCover] = (newDp[newPrefix][newCover]+dp[oldprefix][oldCover])%modulo;\n\n }\n }\n dp=newDp;\n //cnt = oneStep(cnt, maxLength, last, isFinish, next);\n }\n int answer = 0;\n for (int i = 0; i < lastIndex; i++) {\n answer = (answer+dp[i][0])%modulo;\n\n }\n out.println(answer);\n }\n}\n\nclass InputReader {\n StringTokenizer st;\n BufferedReader in;\n public InputReader(InputStream ins)\n {\n in = new BufferedReader(new InputStreamReader(ins));\n }\n\n public String nextToken()\n {\n while(st==null || !st.hasMoreTokens())\n {\n try {\n st=new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\n }\n }\n return st.nextToken();\n }\n public int nextInt()\n {\n\n return Integer.parseInt(nextToken());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "713b8b52c573b1eb5fe3ec12fdec1df6", "src_uid": "3f053c07deaac55c2c51df6147080340", "difficulty": 2500} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n int[] charToNumber;\n final int alphabetSize = 4;\n final int MOD = 1000000009;\n\n int getSymbNumber(char c) {\n return charToNumber[c];\n }\n\n class Trie {\n class Node {\n boolean isFinal;\n Node sufLink;\n Node[] child;\n Node[] go;\n Node parent;\n int parSymb;\n int index;\n\n ArrayList finalNums;\n ArrayList finalDepth;\n\n public Node() {\n child = new Node[alphabetSize];\n go = new Node[alphabetSize];\n index = ls.size();\n finalNums = new ArrayList();\n finalDepth = new ArrayList();\n }\n }\n\n ArrayList ls = new ArrayList();\n\n Node root;\n\n public Trie() {\n root = new Node();\n ls.add(root);\n }\n\n void addString(String s) {\n Node v = root;\n for (int i = 0; i < s.length(); i++) {\n Node prev = v;\n int symb = getSymbNumber(s.charAt(i));\n if (v.child[symb] == null) {\n v.child[symb] = new Node();\n ls.add(v.child[symb]);\n }\n v = v.child[symb];\n v.parent = prev;\n v.parSymb = symb;\n }\n v.isFinal = true;\n }\n\n void buildAutomaton() {\n ArrayDeque q = new ArrayDeque();\n root.sufLink = root;\n for (int i = 0; i < alphabetSize; i++) {\n if (root.child[i] != null) {\n root.go[i] = root.child[i];\n q.addLast(root.child[i]);\n } else\n root.go[i] = root;\n }\n while (!q.isEmpty()) {\n Node v = q.pollFirst();\n v.sufLink = v.parent == root ? root\n : v.parent.sufLink.go[v.parSymb];\n v.isFinal |= v.sufLink.isFinal;\n for (int i = 0; i < alphabetSize; i++)\n if (v.child[i] != null) {\n v.go[i] = v.child[i];\n q.addLast(v.child[i]);\n } else\n v.go[i] = v.sufLink.go[i];\n }\n }\n\n void buildFinal(Node v) {\n for (int i = 0; i < alphabetSize; i++)\n if (v.child[i] != null) {\n buildFinal(v.child[i]);\n for (int j = 0; j < v.child[i].finalNums.size(); j++) {\n v.finalDepth.add(v.child[i].finalDepth.get(j) + 1);\n v.finalNums.add(v.child[i].finalNums.get(j));\n }\n if (v.child[i].isFinal) {\n v.finalDepth.add(1);\n v.finalNums.add(v.child[i].index);\n }\n }\n }\n\n void lastMagic() {\n ArrayDeque q = new ArrayDeque();\n for (int i = 0; i < alphabetSize; i++)\n if (root.child[i] != null)\n q.add(root.child[i]);\n\n while (!q.isEmpty()) {\n Node v = q.pollFirst();\n v.finalDepth.addAll(v.sufLink.finalDepth);\n v.finalNums.addAll(v.sufLink.finalNums);\n for (int i = 0; i < alphabetSize; i++)\n if (v.child[i] != null) {\n q.add(v.child[i]);\n }\n }\n }\n }\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 charToNumber = new int[256];\n Arrays.fill(charToNumber, -1);\n charToNumber['A'] = 0;\n charToNumber['C'] = 1;\n charToNumber['G'] = 2;\n charToNumber['T'] = 3;\n\n Trie t = new Trie();\n\n for (int i = 0; i < m; i++)\n t.addString(nextToken());\n\n t.buildAutomaton();\n t.buildFinal(t.root);\n t.lastMagic();\n\n int[][] dp = new int[n + 1][t.ls.size()];\n for (int i = 0; i < t.root.finalDepth.size(); i++)\n dp[t.root.finalDepth.get(i)][t.root.finalNums.get(i)]++;\n \n for (int i = 1; i <= n; i++)\n for (int j = 0; j < t.ls.size(); j++)\n if (dp[i][j] != 0) {\n Trie.Node v = t.ls.get(j).sufLink;\n \n for (int k = 0; k < v.finalDepth.size(); k++)\n if (i + v.finalDepth.get(k) <= n) {\n dp[i + v.finalDepth.get(k)][v.finalNums.get(k)] += dp[i][j];\n if (dp[i + v.finalDepth.get(k)][v.finalNums.get(k)] >= MOD)\n dp[i + v.finalDepth.get(k)][v.finalNums.get(k)] -= MOD;\n }\n }\n \n int ans = 0;\n for (int i = 0; i < t.ls.size(); i++) {\n ans += dp[n][i];\n if (ans >= MOD)\n ans -= MOD;\n }\n \n out.print(ans);\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "946fa696e1771297c2c4821c766776d3", "src_uid": "3f053c07deaac55c2c51df6147080340", "difficulty": 2500} {"lang": "Java 6", "source_code": "package code;\n\nimport iensen.IO.InputReader;\n\nimport java.io.PrintWriter;\nimport java.util.HashMap;\n\npublic class Task\n{\n public void solve(int testNumber, InputReader in, PrintWriter out)\n {\n int n = in.nextInt();\n int m = in.nextInt();\n String[] Viruses = new String[m];\n for (int i = 0; i < m; i++)\n {\n Viruses[i] = in.nextToken();\n }\n HashMap Index = new HashMap();\n int lastIndex = 1;\n for (int i = 0; i < m; i++)\n {\n for (int j = 0; j < Viruses[i].length(); j++)\n {\n Index.put(Viruses[i].substring(0, j + 1), lastIndex++);\n }\n }\n Index.put(\"\",0);\n int[][] replaceMent = new int[lastIndex][26];\n int[] longestSuffix = new int[lastIndex];\n //\u041d\u0430\u0439\u0434\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0439:\n for (String s : Index.keySet())\n for (String t : Viruses)\n if (s.endsWith(t))\n longestSuffix[Index.get(s)] = Math.max(longestSuffix[Index.get(s)], t.length());\n\n //\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043c\u044b \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 I, \u0438 \u043f\u0438\u0448\u0435\u043c \u0431\u0443\u043a\u0432\u0443 CH. \u041d\u0430\u0439\u0434\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442c\u044f:\n\n for (String s : Index.keySet()) {\n int start = Index.get(s);\n for (char ch = 'A'; ch <= 'Z'; ch++) {\n String candidate=s.concat(Character.toString(ch));//\u0431\u0435\u0440\u0435\u043c \u043f\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c\u0443\n while (!Index.containsKey(candidate))\n candidate = candidate.substring(1);//\u043e\u0442\u0440\u0435\u0437\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b\n replaceMent[start][ch-'A'] = Index.get(candidate);\n }\n }\n\n int[][] dp = new int[lastIndex][20]; //\u0417\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441\u0435 I \u043f\u0440\u0438\u043c\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439\n //\u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0418 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043d\u0435\u043d\u0430\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430\n int modulo=1000000009;\n dp[Index.get(\"\")][0] = 1;//\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0430 \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430\n for (int idx = 0; idx < n; ++idx) {\n int[][] newDp = new int[lastIndex][20];\n for (int oldprefix = 0; oldprefix < lastIndex; oldprefix++)\n for (int oldCover = 0; oldCover < 20; oldCover++) {\n for (char ch='A'; ch <='Z'; ch++) {\n int newPrefix = replaceMent[oldprefix][ch-'A'];\n int newCover = oldCover + 1; //\u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430 1 \u0431\u043e\u043b\u044c\u0448\u0435,\u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u043b\u0438\u0441\u044c \u043d\u0430 1\n if (newCover <= longestSuffix[newPrefix])\n newCover = 0;//\u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u043a\u0440\u044b\u043b\u0438 \u0442\u043e \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u043d\u0430\u043a\u0440\u044b\u0442\u043e, \u0442\u043e we are happy!\n if (newCover >=20)//\u0442\u044f\u0436\u0435\u043b\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\n continue;\n newDp[newPrefix][newCover] = (newDp[newPrefix][newCover]+dp[oldprefix][oldCover])%modulo;\n\n }\n }\n dp=newDp;\n //cnt = oneStep(cnt, maxLength, last, isFinish, next);\n }\n int answer = 0;\n for (int i = 0; i < lastIndex; i++) {\n answer = (answer+dp[i][0])%modulo;\n\n }\n out.println(answer);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c528725104122961d532bb3a5ff6f9fe", "src_uid": "3f053c07deaac55c2c51df6147080340", "difficulty": 2500} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CF_1092F {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n int n = in.nextInt();\n int[] a = new int[n];\n\n for (int i=0; i0 && a[j-1] > a[j]; j--) {\n int temp = a[j-1];\n a[j-1] = a[j];\n a[j] = temp;\n }\n }\n int res = 0;a\n\n for (int i=0; i bigIntegers, BigInteger s){\n for(int i = 0; i < bigIntegers.size(); i++){\n if(bigIntegers.get(i).equals(s)){\n char c = (char) (65 + i);\n return Character.toString(c);\n }\n }\n return null;\n }\n\n BigInteger primeF(BigInteger b){\n BigInteger next = new BigInteger(\"2\");\n while (true) {\n if (b.remainder(next).equals(BigInteger.ZERO)) {\n return next;\n } else {\n next = next.nextProbablePrime();\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f6bf0a2ed4c20d2c44cb7cd0238900e", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\npublic class H360\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\n\t\t\n\t\t//Code Starts Here\n\t\t\n\t\t\n\t\tint n = in.nextInt();\n\t\tlong fact=1;\n\t\tfor(int i=n;i>(n-5);i--)\n\t\t\tfact *= i;\n\t\t\t\n\t//\tpw.println(comb(7,5)+\" \"+factorial(6));\n\t\t\n\t\t\n\t\tpw.print(fact * comb(n,5));\n\t\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\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t//Code Ends Here\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic class InputReader {\n\t\t \n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\t\tprivate SpaceCharFilter filter;\n \n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t\tpublic String readString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\t\n\tpublic static long mod = 1000000007;\n\tpublic static int d;\n\tpublic static int p;\n\tpublic static int q;\n\t\n\tpublic static int[] suffle(int[] a,Random gen)\n\t{\n\t\tint n = a.length;\n\t\tfor(int i=0;i primeFactorization(int n)\n\t{\n\t\tArrayList a =new ArrayList();\n\t\tfor(int i=2;i*i<=n;i++)\n\t\t{\n\t\t\twhile(n%i==0)\n\t\t\t{\n\t\t\t\ta.add(i);\n\t\t\t\tn/=i;\n\t\t\t}\n\t\t}\n\t\tif(n!=1)\n\t\t\ta.add(n);\n\t\treturn a;\n\t}\n\t\n\tpublic static void sieve(boolean[] isPrime,int n)\n\t{\n\t\tfor(int i=1;i>= 1;\n\t if (u == 1) return true;\n\n\t do\n\t {\n\t while ((v & 1) == 0) v >>= 1;\n\t if (v == 1) return true;\n\n\t if (u > v) { long t = v; v = u; u = t; }\n\t v -= u;\n\t } while (v != 0);\n\n\t return false;\n\t}\n\t\n\tpublic static int GCD(int a,int b)\n\t{\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn GCD(b,a%b);\n\t}\n\t\n\tpublic static long GCD(long a,long b)\n\t{\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn GCD(b,a%b);\n\t}\n\t\n\tpublic static void extendedEuclid(int A,int B)\n\t{\n\t\tif(B==0)\n\t\t{\n\t\t\td = A;\n\t\t\tp = 1 ;\n\t\t\tq = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\textendedEuclid(B, A%B);\n\t\t\tint temp = p;\n\t\t\tp = q;\n\t\t\tq = temp - (A/B)*q;\n\t\t}\n\t}\n\t\n\tpublic static long LCM(long a,long b)\n\t{\n\t\treturn (a*b)/GCD(a,b);\n\t}\n\t\n\tpublic static int LCM(int a,int b)\n\t{\n\t\treturn (a*b)/GCD(a,b);\n\t}\n\t\n\tpublic static long factorial(long n) {\n\t\t\n\t\tlong fact = 1;\n\t\tfor(int i=1; i<=n; i++)\n\t\t\tfact*= i;\n\t\t\n\t\treturn fact;\n\t\t\n\t}\n\t\n\tpublic static long comb(int a, int b) {\n\t\tlong c= factorial(a)/(factorial(b)*factorial(a-b));\n\t\t\n\t\treturn c;\n\t}\n\tpublic static int binaryExponentiation(int x,int n)\n\t{\n\t int result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=result * x;\n\t x=x*x;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static long binaryExponentiation(long x,long n)\n\t{\n\t long result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=result * x;\n\t x=x*x;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static int modularExponentiation(int x,int n,int M)\n\t{\n\t int result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=(result * x)%M;\n\t x=(x*x)%M;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static long modularExponentiation(long x,long n,long M)\n\t{\n\t long result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=(result * x)%M;\n\t x=(x*x)%M;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static int modInverse(int A,int M)\n\t{\n\t return modularExponentiation(A,M-2,M);\n\t}\n\t\n\tpublic static long modInverse(long A,long M)\n\t{\n\t return modularExponentiation(A,M-2,M);\n\t}\n\t\n\tpublic static boolean isPrime(int n)\n\t{\n\t \n\t if (n <= 1) return false;\n\t if (n <= 3) return true;\n\t \n\t if (n%2 == 0 || n%3 == 0) \n\t \treturn false;\n\t \n\t for (int i=5; i*i<=n; i=i+6)\n\t {\n\t if (n%i == 0 || n%(i+2) == 0)\n\t return false;\n\t }\n\t \n\t return true;\n\t}\n\t\n\tstatic class pair implements Comparable\n\t{\n\t\tInteger x, y;\n\t\tpair(int x,int y)\n\t\t{\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t\t\n\t\tpublic int compareTo(pair o) {\n\t\t\tint result = x.compareTo(o.x);\n\t\t\tif(result==0)\n\t\t\t\tresult = y.compareTo(o.y);\n\t\t\t\n\t\t\treturn result;\n\t\t} \n\t\t\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn x+\" \"+y;\n\t\t}\n\t\t\n\t\tpublic boolean equals(Object o)\n\t\t{\n\t\t\tif (o instanceof pair)\n\t\t {\n\t\t\t\tpair p = (pair)o;\n\t\t\t\treturn p.x == x && p.y == y ;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tpublic int hashCode()\n\t\t{\n\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "df22c8fdeea6226e013e1cc97ee14f97", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400} {"lang": "Java 8", "source_code": "public class Z630H {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter writer = new PrintWriter(System.out);\n long n = in.nextLong();\n long otv = n/1 * (n-1) /2*(n-2)/3*(n-3)/4*(n-4)/5;\n long a = n*(n-1)*(n-2)*(n-3)*(n-4);\n System.out.println(otv*a);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2d82e8e2de525bb84ff098d576f97b2c", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws {\n Scanner in = new Scanner(System.in);\n \n long n = in.nextLong();\n long cn5 = n * (n - 1) / 2 * (n - 2) / 3 * (n - 3) / 4 * (n - 4) / 5;\n long an5 = n * (n - 1) * (n - 2) * (n - 3) * (n - 4);\n\n System.out.println(cn5*an5);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8c5fe47c4799a0671fe8d183d6b76a64", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class H_Volbit {\n\n public static long MOD = 1000000007; \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 n = in.nextInt();\n long v = cal(0, 5, n, n);\n out.println(v);\n out.close();\n }\n \n public static long cal(int index, int left, int bench, int n){\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 \tlong result = bench*cal(index + 1, left - 1, bench - 1, n) + cal(index + 1, left, bench, n);\n \treturn result;\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 }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "666acc632aa653da4efcbc0856ff45db", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400} {"lang": "Java 8", "source_code": "\ufeffimport java.util.Scanner;\n\npublic class Checker {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int a = s.nextInt();\n\n int b = s.nextInt();\n\n int c = s.nextInt();\n\n int sum = a + b + c;\n\n int max = Math.max(a, Math.max(b, c));\n\n System.out.println(Math.max(0, max - (sum - max) + 1));\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "91c8a007c988645c8eac9a2857ee6ee0", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800} {"lang": "Java 8", "source_code": "public class CodeforceMasha {\n\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n if (a > b) {\n int temp = a;\n a = b;\n b = temp;\n }\n\n if (b > c) {\n int temp = b;\n b = c;\n c = temp;\n }\n\n int ans = 0;\n if (c - (a + b) > 0) {\n ans = c - (a + b) + 1;\n }\n System.out.println(ans);\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "98de47a3769107db60400a674bdab606", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800} {"lang": "Java 8", "source_code": "public class GFG {\n\tpublic static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n \n int[] p = new int[3];\n p[0] = a;\n p[1] = b;\n p[2] = c;\n Arrays.sort(p);\n \n if((p[0] + p[1] > p[2]) && (p[0] + p[2] > p[1]) && (p[1] + p[2] > p[0])){\n System.out.println(\"0\");\n }\n else{\n if((p[0] + p[1] <= p[2])){\n System.out.println(p[2] - (p[0] + p[1]) + 1);\n }\n if((p[0] + p[2] <= p[1])){\n System.out.println(p[1] - (p[0] + p[2]) + 1);\n }\n if((p[1] + p[2] <= p[0])){\n System.out.println(p[0] - (p[1] + p[2]) + 1);\n }\n }\n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2cc8f6d31c3033899cc6ca7f6318fe00", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class aseel {\npublic static void main (String args []) {\n\tScanner in = new Scanner(System.in);\t\nint [] arr = new int [3];\narr[0]=in.nextInt();\narr[1]=in.nextInt();\narr[2]=in.nextInt();\nArrays.parallelSort(arr);\nif ((arr[2]-(arr[0]+arr[1])>=0)){\nSystem.out.println(arr[2]-(arr[0]+arr[1])+1);\n}else {\n\tSystem.out.println(\"0\");\n}\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29726a0489af674417b63c7add8edff1", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Time {\n int hour;\n int min;\n \n Time(int h, int m){\n super();\n hour=h;\n min=m;\n }\n public int getHours(){\n return hour;\n }\n public int getMinutes(){\n return min;\n }\n public void printTime(){\n if (hour<10) System.out.print(\"0\"+hour+\":\");\n else System.out.print(hour+\":\");\n if (min<10) System.out.print(\"0\"+min);\n else System.out.print(min);\n }\n}\n\n\n\n\npublic class A387 {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n int h,m;\n Scanner in = new Scanner(System.in);\n in.useDelimiter(\"[:\\n\\\\s]+\");\n h=in.nextInt();\n m=in.nextInt();\n Time s = new Time(h,m);\n h=in.nextInt();\n m=in.nextInt();\n Time t = new Time(h,m);\n h=s.getHours()-t.getHours();\n m=s.getMinutes()-t.getMinutes();\n if (m<0) {\n m+=60;\n h--;\n }\n if (h<0) h+=24;\n Time res = new Time(h,m);\n res.printTime();\n \n in.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5199e8e90e5c34e9ecbeb5af36cd9200", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Time {\n int hour;\n int min;\n \n Time(int h, int m){\n super();\n hour=h;\n min=m;\n }\n public int getHours(){\n return hour;\n }\n public int getMinutes(){\n return min;\n }\n public void printTime(){\n if (hour<10) System.out.print(\"0\"+hour+\":\");\n else System.out.print(hour+\":\");\n if (min<10) System.out.print(\"0\"+min);\n else System.out.print(min);\n }\n}\n\npublic class A387 {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n int h,m;\n Scanner in = new Scanner(System.in);\n in.useDelimiter(\"[:\\n\\\\s]+\");\n h=in.nextInt();\n m=in.nextInt();\n Time s = new Time(h,m);\n h=in.nextInt();\n m=in.nextInt();\n Time t = new Time(h,m);\n h=s.getHours()-t.getHours();\n m=s.getMinutes()-t.getMinutes();\n if (m<0) {\n m+=60;\n h--;\n }\n if (h<0) h+=24;\n Time res = new Time(h,m);\n res.printTime();\n \n in.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c4524607a366c12119a2af1c750c7c90", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n * Created by peter.bykov on 19.05.2014.\n */\npublic class Archive387A {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n String[] now = s.nextLine().split(\":\");\n String[] sleepTime = s.nextLine().split(\":\");\n int hours = Integer.parseInt(now[0]) - Integer.parseInt(sleepTime[0]);\n if(hours < 0) {\n hours = 24 + hours;\n }\n int minutes = Integer.parseInt(now[1]) - Integer.parseInt(sleepTime[1]);\n if(minutes < 0) {\n if(hours > 0) {\n --hours;\n } else {\n hours = 23;\n }\n minutes = 60 + minutes;\n }\n System.out.println(((hours>=10)?hours:\"0\"+hours) + \":\" + ((minutes>=10)?minutes:\"0\"+minutes));\n\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a2c469fc8d03f4a800dd0689ef71c169", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.text.ParseException;\nimport java.text.SimpleDateFormat;\nimport java.util.Calendar;\nimport java.util.Date;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author nastra - Eduard Tudenhoefner\n */\npublic class One {\n\n private static final SimpleDateFormat df = new SimpleDateFormat(\"HH:mm\");\n\n public static void main(String[] args) throws Exception {\n com.nastra.hackerrank.util.FastScanner sc = new com.nastra.hackerrank.util.FastScanner(System.in);\n String start = sc.next();\n String duration = sc.next();\n System.out.println(time(start, duration));\n }\n\n public static String time(String start, String duration) throws ParseException {\n Date s = df.parse(start);\n Date t = df.parse(start);\n String[] dur = duration.split(\":\");\n String f = dur[0];\n if (f.startsWith(\"0\")) {\n f = f.substring(1);\n }\n String g = dur[1];\n if (g.startsWith(\"0\")) {\n g = g.substring(1);\n }\n Integer hour = Integer.valueOf(f);\n Integer min = Integer.valueOf(g);\n Calendar a = Calendar.getInstance();\n a.setTime(s);\n a.add(Calendar.HOUR_OF_DAY, -hour);\n a.add(Calendar.MINUTE, -min);\n\n return df.format(a.getTime());\n }\n\n static class FastScanner {\n\n private static BufferedReader reader;\n private static StringTokenizer tokenizer;\n\n public static void main(String[] args) throws Exception {\n com.nastra.hackerrank.util.FastScanner sc = new com.nastra.hackerrank.util.FastScanner(System.in);\n\n }\n\n public FastScanner(InputStream in) throws Exception {\n reader = new BufferedReader(new InputStreamReader(in));\n tokenizer = new StringTokenizer(reader.readLine().trim());\n }\n\n public int numTokens() throws Exception {\n if (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine().trim());\n return numTokens();\n }\n return tokenizer.countTokens();\n }\n\n public boolean hasNext() throws Exception {\n if (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine().trim());\n return hasNext();\n }\n return true;\n }\n\n public String next() throws Exception {\n if (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine().trim());\n return next();\n }\n return tokenizer.nextToken();\n }\n\n public double nextDouble() throws Exception {\n return Double.parseDouble(next());\n }\n\n public float nextFloat() throws Exception {\n return Float.parseFloat(next());\n }\n\n public long nextLong() throws Exception {\n return Long.parseLong(next());\n }\n\n public int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n\n public String nextLine() throws Exception {\n return reader.readLine().trim();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2b5c3554c697a6cf0388f363b4c6f7df", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\nimport java.util.prefs.BackingStoreException;\n\n\n/**\n * Author: Luis Manuel D\u00edaz Bar\u00f3n\n * Problem:\n * Online Judge:\n * Idea:\n * Fecha: 20/02/2013\n */\n\npublic class Main {\n\n static MyScanner sc;\n static MyWriter pw;\n static String filePathWin=\"d:\\\\lmo.in\";\n static String filePathLinux=\"/media/luismo/Trabajo/lmo.in\";\n public static void main(String[] args) throws IOException {\n sc = new MyScanner(System.in);\n\n // sc = new MyScanner(new FileReader(filePathWin));\n // sc = new MyScanner(new FileReader(filePathLinux));\n\n pw = new MyWriter(System.out);\n\n while(sc.canRead())\n SolveSingleProblem();\n\n pw.close();\n }\n \n static boolean marks[] = new boolean[5];\n static int perm[] = new int[5];\n \n static long best = 0;\n \n static void backTrack(int idx){\n // base\n if(idx == 5){\n \n long k1 = G[perm[0]][perm[1]] + G[perm[1]][perm[0]] + G[perm[2]][perm[3]] + G[perm[3]][perm[2]];\n \n long k2 = G[perm[1]][perm[2]] + G[perm[2]][perm[1]] + G[perm[3]][perm[4]] + G[perm[4]][perm[3]];\n \n long k3 = G[perm[2]][perm[3]] + G[perm[3]][perm[2]];\n \n long k4 = G[perm[3]][perm[4]] + G[perm[4]][perm[3]];\n \n int val = k1 + k2 + k3 + k4;\n \n best = max(best,val);\n /*\n for(int i =0; i < perm.length; i++)\n pw.print(\" \"+ perm[i]);\n \n pw.println(\" val: \"+ val);\n */\n \n return;\n }\n \n for(int i = 0; i < 5; i++){\n \n if(!marks[i]){\n \n marks[i] = true;\n perm[idx] = i;\n \n backTrack(idx + 1);\n marks[i] = false;\n } \n }\n }\n \n \n \n static int G[][] = new int[5][5];\n public static void SolveSingleProblem() throws IOException{\n for(int i = 0; i < 5; i++){\n for(int j = 0; j < 5; j++){\n \n G[i][j] = sc.nextInt(); \n } \n }\n \n backTrack(0);\n \n pw.println(best);\n \n }\n \n \n static int min(int a, int b){\n \n return (ab)? a: b;\n }\n \n \n}\n\n\n\n\n\n\n// INPUT / OUTPUT\nclass MyScanner{\n BufferedReader br;\n StringTokenizer stk;\n public MyScanner(InputStream stream){\n this.br = new BufferedReader(new InputStreamReader(stream),72357);\n this.stk = new StringTokenizer(\"\");\n }\n public MyScanner(FileReader fr){\n this.br = new BufferedReader(fr);\n this.stk = new StringTokenizer(\"\");\n }\n public String next() throws IOException {\n while(!stk.hasMoreElements()){\n String line = br.readLine();\n if(line == null)\n return null;\n stk = new StringTokenizer(line);\n }\n return stk.nextToken();\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 boolean canRead() throws IOException{\n return br.ready();\n }\n}\n\nclass MyWriter{\n PrintWriter pw;\n public MyWriter(OutputStream out){\n this.pw = new PrintWriter(out);\n }\n public void print(Object obj){\n pw.print(obj.toString());\n }\n public void println(Object obj){\n pw.println(obj.toString());\n }\n public void close() {\n pw.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf90fe542b96cdb904e6b3f573955f25", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class C {\n static int g[][] = new int[5][5];\n static int used[] = new int[5];\n static int maxi = 0;\n\n static void makeQueue(String str) {\n if (str.length() == 5) {\n //System.out.println(str);\n findMaxi(str);\n }\n for (int i = 0; i < 5; i++) {\n if (used[i] != 1) {\n used[i] = 1;\n\n makeQueue(str + i);\n used[i] = 0;\n }\n }\n }\n static void findMaxi(String str) {\n int sum = 0;\n for (int i = 1; i < 5; i++) {\n for (int j = i; j < 5; j+=2)\n sum = sum + g[str.charAt(i) - 48][str.charAt(i - 1) - 48] + g[str.charAt(i - 1) - 48][str.charAt(i) - 48];\n }\n if (maxi < sum) {\n maxi = Math.max(sum, maxi);\n //System.out.println(str);\n }\n }\n\n public static void main(String[] args) {\n int N;\n Scanner in = new Scanner(System.in);\n for (int i = 0; i < 5; i++)\n for (int j = 0; j < 5; j++) {\n g[i][j] = in.nextInt();\n }\n\n makeQueue(\"\");\n System.out.print(maxi);\n\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c55917793cd49eb198552b120a9fb665", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n //BufferedReader br = new BufferedReader(new FileReader(\"data\"));\n \n int[][] happy = new int[5][5];\n for (int r = 0; r < 5; r++) {\n StringTokenizer st = new StringTokenizer(br.readLine());\n for (int c = 0; c < 5; c++) {\n happy[r][c] = Integer.parseInt(st.nextToken());\n }\n }\n \n int max = 0;\n \n for (int i = 0; i < 5; i++) {\n for (int j = 0; j < 5; j++) {\n if (i != j) {\n for (int k = 0; k < 5; k++) {\n if (k != i && k != j) {\n for (int l = 0; l < 5; l++) {\n if (l != i && l != j && l != k) {\n for (int m = 0; m < 5; m++) {\n if (m != i && m != j && m != k && m != l) {\n int happiness = happy[i][j] + happy[j][i] +\n happy[j][k] + happy[k][j] +\n 2 * (happy[k][l] + happy[l][k]) +\n 2 * (happy[l][m] + happy[m][l]);\n \n if (happiness > max) max = happiness;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n System.out.println(max);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "154eea28308578ce6152cfbd39d070a6", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200} {"lang": "Java 7", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/\npublic class Main {\n static int[][] matriz=new int[5][5];\n public static void main(String[] args) {\n Scanner entrada=new Scanner(System.in);\n Integer compas[]={0,1,2,3,4};\n for (int i = 0; i < 5; i++) {\n for (int j = 0; j < 5; j++) {\n matriz[i][j]=entrada.nextInt();\n }\n }\n System.out.println(calcularMax(compas));\n //printPermutations(compas);\n }\n \n private static int calcularMax( Comparable[] c ) {\n //System.out.println( Arrays.toString( c ) );\n int acc=0;\n int max=0;\n while ( ( c = nextPermutation( c ) ) != null ) {\n //ystem.out.println( Arrays.toString( c ) );\n int i=(Integer)c[0];\n int j=(Integer)c[1];\n acc+=matriz[i][j]+matriz[j][i];\n i=(Integer)c[1];\n j=(Integer)c[2];\n acc+=matriz[i][j]+matriz[j][i];\n i=(Integer)c[2];\n j=(Integer)c[3];\n acc+=(matriz[i][j]+matriz[j][i])*2;\n i=(Integer)c[3];\n j=(Integer)c[4];\n acc+=(matriz[i][j]+matriz[j][i])*2;\n if(max= 0 )\n --toSwap;\n // 3. swap elements with indexes first and last\n swap( c, first++, toSwap );\n // 4. reverse sequence from k+1 to n (inclusive) \n toSwap = c.length - 1;\n while ( first < toSwap )\n swap( c, first++, toSwap-- );\n return c;\n }\n\n // finds the largest k, that c[k] < c[k+1]\n // if no such k exists (there is not greater permutation), return -1\n private static int getFirst( final Comparable[] c ) {\n for ( int i = c.length - 2; i >= 0; --i )\n if ( c[ i ].compareTo( c[ i + 1 ] ) < 0 )\n return i;\n return -1;\n }\n\n // swaps two elements (with indexes i and j) in array \n private static void swap( final Comparable[] c, final int i, final int j ) {\n final Comparable tmp = c[ i ];\n c[ i ] = c[ j ];\n c[ j ] = tmp;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bb0d0979d0a55742d9e1a59c3979f8f8", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200} {"lang": "Java 7", "source_code": "\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\nimport java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.lang.Math;\n/**\n *\n * @author SONY\n */\npublic class chess {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner s = new Scanner(System.in);\n int r1,r2,c1,c2;\n int n1,n2,n3;\n r1=s.nextInt();\n c1=s.nextInt();\n r2=s.nextInt();\n c2=s.nextInt();\n if(c2b)\n \tSystem.out.println(a);\n else\n \tSystem.out.println(b);\n }\n \t \n\t}\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "118e015ea9906c5cea1c7ecce5f7faaf", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100} {"lang": "Java 8", "source_code": "package practice;\n\nimport util.FastReader;\nimport java.io.PrintWriter;\n\npublic class RookBishopKing {\n public void solve(int testNumber, FastReader in, PrintWriter out) {\n int r1 = in.nextInt();\n int c1 = in.nextInt();\n int r2 = in.nextInt();\n int c2 = in.nextInt();\n\n // rook\n if (r1 == r2 || c1 == c2) {\n out.print(\"1 \");\n } else {\n out.print(\"2 \");\n }\n\n // bishop\n if ((r1 + r2) % 2 != (c1 + c2) % 2) {\n out.print(\"0 \");\n } else {\n if (Math.abs(r1 - r2) == Math.abs(c1 - c2)) {\n out.print(\"1 \");\n } else {\n out.print(\"2 \");\n }\n }\n\n // king\n out.print(Math.max(Math.abs(r1-r2), Math.abs(c1-c2)));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "934bbc30bbbb707294619b78e34deac7", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class MainClass\n{\n static long fact[];\n static long M = 998244353L;\n static NumberTheory numberTheory = new NumberTheory();\n public static void main(String[] args)throws IOException\n {\n Reader in = new Reader();\n int n = in.nextInt();\n int k = in.nextInt();\n fact = new long[500000 + 10];\n fact[0] = 1L;\n for (int i =1;i= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException\n {\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "241cc15051ca0f66a8d73220e7542eab", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\npublic class sol {\n InputReader in;\n PrintWriter out;\n helper_class h;\n final long mod=1000000007;\n final long p=998244353;\n long fact[];\n public static void main(String[] args) throws java.lang.Exception{\n new sol().run();\n } \n void run() throws Exception{\n in=new InputReader(System.in);\n out = new PrintWriter(System.out);\n h = new helper_class();\n precompute();\n int t=1;\n while(t-->0){\n solve();\n }\n out.flush(); \n out.close();\n }\n void solve() {\n int n=h.i(),k=h.i();\n precompute();\n long ans=0;\n for(int i=1;i<=n;i++)\n ans = add(ans, nCr(n/i-1 k-1));\n h.p(ans);\n }\n void precompute() {\n fact=new long[500001];\n fact[0]=1;\n for(int i=1;i<=500000;i++)\n fact[i]=(fact[i-1]*i)%p;\n }\n long nCr(int n,int r) {\n if(r > n) return 0;\n return mul(fact[n], mul(inv(fact[r]),inv(fact[n-r])));\n }\n long inv(long x) {\n return power(x,p-2,p);\n }\n long add(long x,long y) {\n return (x%p + y%p)%p;\n }\n long mul(long x,long y) {\n return (x%p +* y%p)%p;\n }\n long power(long a, long b,long p){\n if(b == 0)\n return 1L;\n long val = power(a, b/2, p);\n if(b % 2 == 0)\n return val * val%p;\n else \n return val * val%p * a%p;\n }\n class helper_class{\n long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n void p(Object o){out.println(o);}\n String s(){return in.next();}\n String nl(){return in.nextLine();}\n int i(){return in.nextInt();}\n long l(){return in.nextLong();}\n }\n class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n public int read() {\n if (numChars == -1)\n throw new UnknownError();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n public int peek() {\n if (numChars == -1)\n return -1;\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n return -1;\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar];\n }\n public void skip(int x) {\n while (x-->0)\n read();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public String nextString() {\n return next();\n }\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n \n return res.toString();\n }\n public String nextLine() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r')\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n public boolean hasNext() {\n int value;\n while (isSpaceChar(value = peek()) && value != -1)\n read();\n return value != -1;\n }\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "abce463e3e6b4b4fec25df15bffd4564", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class er88e {\n\tpublic static void main(String[] args) {\n\t\tScanner scan=new Scanner(System.in);\n\t\tint n=scan.nextInt(), k=scan.nextInt();\n\t\t/*\n\t\t\tan array is stable if all the other elements\n\t\t\tare divisible by the minimum element\n\n\t\t\tbecause if we mod by the min element\n\t\t\tnothing else matters\n\t\t\tand if we mod by another element\n\t\t\tit must subtract out only multiples of the min element\n\t\t\tso the answer does not change\n\t\t\t\n\t\t\twe iterate through all the min elements\n\t\t\tand calculate the answer\n\t\t*/\n\n\t\tfac=new long[100001];\n\t\tinvfac=new long[100001];\n\t\tfac[0]=invfac[0]=1;\n\n\t\tfor(int i=1;i s1;\n static boolean[] prime;\n static int n = 200001;\n \n static void sieve() {\nArrays.fill(prime\t, true);\nprime[0] = prime[1] = false;\nfor(int i = 2 ; i * i <= n ; ++i) {\nif(prime[i]) {\nfor(int k = i * i; k<= n ; k+=i) {\nprime[k] = false;\n}\n}\n}\n \n}\n public static void main(String[] args) {\n InputReader sc = new InputReader(System.in);\n \n //prime = new boolean[n + 1];\n // sieve();\n //prime[1] = false;\n \n \n /* \n int n = sc.ni();\n int k = sc.ni();\n int []vis = new int[n+1];\n int []a = new int[k];\n for(int i=0;i 0)\n {\n System.out.print(\"? \");\n for(int i=0;i a2 = new ArrayList<>();\n if(y >= k)\n {\n \n int c = 0;\n int k1 = 0;\n for(int i=1;i<=n;i++)\n {\n if(b[i] != -1)\n {\n c++;\n a[k1] = i;\n a2.add(b[i]);\n k1++;\n }\n if(c==k)\n break;\n }\n \n Collections.sort(a2);\n System.out.print(\"? \");\n for(int i=0;i 0)\n {\n res += (long) (r-l);\n r--;\n }\n else \n l++;\n }\n \n w.println(res);\n*/\n /*\n int n = sc.ni();\n \n ArrayList t1 = new ArrayList<>();\n int []p1 = new int[n+1];\n int []q1 = new int[n-1];\n int []q2 = new int[n-1];\n for(int i=0;i hm = new HashMap<>();\n for(int i=0;i v = new HashMap<>();\n for(int i=0;i 0)\n {\n long x = sc.nextLong();\n long y = sc.nextLong();\n long a = (x - y)/2; \n long a1 = 0, b1 = 0; \n \n \n int lim = 8; \n \n \n int f = 0;\n \n for (int i=0; i<8*lim; i++) \n { \n long pi = (y & (1 << i)); \n long qi = (a & (1 << i)); \n if (pi == 0 && qi == 0) \n { \n \n } \n else if (pi == 0 && qi > 0) \n { \n a1 = ((1 << i) | a1); \n b1 = ((1 << i) | b1); \n } \n else if (pi > 0 && qi == 0) \n { \n a1 = ((1 << i) | a1); \n \n \n } \n else\n { \n f = 1; \n \n } \n } \n if(a1+b1 != x)\n f =1;\n if(f==1)\n System.out.println(\"-1\");\n else\n {\n if(a1 > b1)\n {\n long temp = a1;\n a1 = b1;\n b1 = temp;\n }\n System.out.println(a1 + \" \" + b1);\n \n }\n \n \n }\n \n */\n\n \n fact = new long[100001];\n long mod = 998244353;\n fact[0] = 1;\n fact[1] = 1;\n for(int i=2;i<=100000;i++)\n {\n fact[i] = ((long)i* fact[i-1])%mod;\n }\n int n = sc.ni();\n int k = sc.ni();\n \n long ans = 0;\n for(int i=1;i<=n;i++)\n {\n int temp = n/i;\n if(temp >= k)\n {\n ans += nCrModPFermat(temp-1,k-1,mod);\n ans = ans%mod;\n }\n }\n w.println(ans);\n \n \n \n \n w.close();\n \n \n \n \n} \n \n static long nCrModPFermat(int n, int r, \n long p) \n { \n \n // Base case \n if (r == 0) \n return 1; \n \n // Fill factorial array so that we \n // can find all factorial of r, n \n // and n-r \n \n \n \n \n \n return (fact[n]* modInverse(fact[r], p) % p * modInverse(fact[n-r], p) % p) % p; \n } \n static long []fact;\n static int []res;\n static int c = 0;\n static class Pair{\n int fir;\n int last;\n Pair(int fir,int last)\n {\n this.fir = fir;\n this.last = last;\n }\n }\n static class m1 implements Comparator{\n public int compare(Pair a, Pair b)\n {\n int t1 = a.last - a.fir;\n int t2 = b.last - b.fir;\n if(t1 < t2)\n return 1;\n else if(t1 > t2)\n return -1;\n else\n {\n if(a.fir < b.fir)\n return -1;\n else\n return 1;\n }\n }\n }\n \n static long calc(long x)\n {\n double res = Math.sqrt(1 + 24*(double)x);\n res -= 1.0;\n res = res / (double) 6;\n return (long) res;\n }\n \n public static final BigInteger MOD = BigInteger.valueOf(998244353L);\n \n static BigInteger fact(int x)\n {\n BigInteger res = BigInteger.ONE;\n for(int i=2;i<=x;i++)\n {\n res = res.multiply(BigInteger.valueOf(i)).mod(MOD);\n }\n return res;\n }\n \n public static long calc(int x,int y,int z)\n {\n long res = ((long) (x-y) * (long) (x-y)) + ((long) (z-y) * (long) (z-y)) + ((long) (x-z) * (long) (x-z));\n return res;\n }\n \n public static int upperBound(ArrayListarr, int length, int value) {\n int low = 0;\n int high = length;\n while (low < high) {\n final int mid = (low + high) / 2;\n if (value >= arr.get(mid)) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n return low;\n }\n \n public static int lowerBound(ArrayList arr, int length, int value) {\n int low = 0;\n int high = length;\n while (low < high) {\n final int mid = (low + high) / 2;\n //checks if the value is less than middle element of the array\n if (value <= arr.get(mid)) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n return low;\n }\n static HashMap map;\n \n \n static class Coin{\n long a;\n long b;\n \n Coin(long a, long b)\n {\n this.a = a;\n this.b = b;\n \n }\n }\n static ArrayList fac;\n static HashSet hs;\n public static void primeFactors(long n) \n { \n // Print the number of 2s that divide n \n while (n % 2 == 0) { \n fac.add(2l);\n hs.add(2l);\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 (long i = 3; i*i <= n; i += 2) { \n // While i divides n, print i and divide n \n while (n % i == 0) { \n fac.add(i);\n hs.add(i);\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 fac.add(n);\n } \n static int smallestDivisor(int n) \n{ \n // if divisible by 2 \n if (n % 2 == 0) \n return 2; \n \n // iterate from 3 to sqrt(n) \n for (int i = 3; i * i <= n; i += 2) { \n if (n % i == 0) \n return i; \n } \n \n return n; \n} \n static boolean IsP(String s,int l,int r)\n {\n while(l <= r)\n {\n if(s.charAt(l) != s.charAt(r))\n {\n return false;\n }\n l++;\n r--;\n }\n return true;\n }\n \n\t\n\n \n \n static class Student{\n int id;\n int val;\n Student(int id,int val)\n {\n this.id = id;\n this.val = val;\n }\n }\n \n \n \n \n static int upperBound(ArrayList a, int low, int high, int element){\n while(low < high){\n int middle = low + (high - low)/2;\n if(a.get(middle) >= element)\n high = middle;\n else \n low = middle + 1;\n }\n return low;\n}\n static long func(long t,long e,long h,long a, long b)\n {\n if(e*a >= t)\n return t/a;\n else\n {\n return e + Math.min(h,(t-e*a)/b);\n }\n }\n \n \n \n public static int countSetBits(int number){\n int count = 0;\n while(number>0){\n ++count;\n number &= number-1;\n }\n return count;\n }\n \n \n \n \n \n \n static long modexp(long x,long n,long M)\n{\n long power = n;\n long result=1;\n x = x%M;\n while(power>0)\n {\n if(power % 2 ==1)\n result=(result * x)%M;\n x=(x*x)%M;\n power = power/2;\n }\n return result;\n}\n static long modInverse(long A,long M)\n{\n return modexp(A,M-2,M);\n}\n static long gcd(long a,long b)\n {\n if(a==0)\n return b;\n else\n return gcd(b%a,a);\n }\n static class Temp{\n int a;\n int b;\n int c;\n int d;\n \n Temp(int a,int b,int c,int d)\n {\n this.a = a;\n this.b = b;\n this.c =c;\n this.d = d;\n //this.d = d;\n }\n }\n \n \n \n static long sum1(int t1,int t2,int x,int []t)\n {\n int mid = (t2-t1+1)/2;\n if(t1==t2)\n return 0;\n \n else\n return sum1(t1,mid-1,x,t) + sum1(mid,t2,x,t);\n \n \n }\n \n \n static String replace(String s,int a,int n)\n {\n char []c = s.toCharArray();\n for(int i=1;i{\n \n \n public int compare(Long a,Long b) {\n if(a{\n \n public int compare(Coin a,Coin b) {\n if(a.a < b.a)\n return 1;\n else if(a.a > b.a)\n return -1;\n else{ \n if(a.b < b.b)\n return 1;\n else if(a.b > b.b)\n return -1;\n else\n return 0;\n }\n \n \n \n }\n }\n \n// Java program to generate power set in \n// lexicographic order. \n \n \n \n \n static class InputReader {\n \nprivate final InputStream stream;\nprivate final byte[] buf = new byte[8192];\nprivate int curChar, snumChars;\n \npublic InputReader(InputStream st) {\nthis.stream = st;\n}\n \npublic int read() {\nif (snumChars == -1)\nthrow new InputMismatchException();\nif (curChar >= snumChars) {\ncurChar = 0;\ntry {\nsnumChars = stream.read(buf);\n} catch (IOException e) {\nthrow new InputMismatchException();\n}\nif (snumChars <= 0)\nreturn -1;\n}\nreturn buf[curChar++];\n}\n \npublic int ni() {\nint c = read();\nwhile (isSpaceChar(c)) {\nc = read();\n}\nint sgn = 1;\nif (c == '-') {\nsgn = -1;\nc = read();\n}\nint res = 0;\ndo {\nres *= 10;\nres += c - '0';\nc = read();\n} while (!isSpaceChar(c));\nreturn res * sgn;\n}\n \npublic long nl() {\nint c = read();\nwhile (isSpaceChar(c)) {\nc = read();\n}\nint sgn = 1;\nif (c == '-') {\nsgn = -1;\nc = read();\n}\nlong res = 0;\ndo {\nres *= 10;\nres += c - '0';\nc = read();\n} while (!isSpaceChar(c));\nreturn res * sgn;\n}\n \npublic int[] nia(int n) {\nint a[] = new int[n];\nfor (int i = 0; i < n; i++) {\na[i] = ni();\n}\nreturn a;\n}\n \npublic String rs() {\nint c = read();\nwhile (isSpaceChar(c)) {\nc = read();\n}\nStringBuilder res = new StringBuilder();\ndo {\nres.appendCodePoint(c);\nc = read();\n} while (!isSpaceChar(c));\nreturn res.toString();\n}\n \npublic String nextLine() {\nint c = read();\nwhile (isSpaceChar(c))\nc = read();\nStringBuilder res = new StringBuilder();\ndo {\nres.appendCodePoint(c);\nc = read();\n} while (!isEndOfLine(c));\nreturn res.toString();\n}\n \npublic boolean isSpaceChar(int c) {\nreturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n}\n \nprivate boolean isEndOfLine(int c) {\nreturn c == '\\n' || c == '\\r' || c == -1;\n}\n \n}\n \n \n \n \n \n \nstatic PrintWriter w = new PrintWriter(System.out);\n static class Student1\n {\n int id;\n //int x;\n \n int b;\n \n //long z;\n \n Student1(int id,int b)\n {\n this.id = id;\n //this.x = x;\n //this.s = s;\n this.b = b;\n \n // this.z = z;\n \n \n \n \n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5b2133280e1222fb95791e3385eea6da", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000} {"lang": "Java 8", "source_code": "public class CG {\n public static void main(String args[]){\nScanner s=new Scanner(System.in);\n \n int w=s.nextInt();\n int h=s.nextInt();\n int u1=s.nextInt();\n int d1=s.nextInt();\n int u2=s.nextInt();\n int d2=s.nextInt();\n \n int finalweight=w;\n \n if(d1!=d2&&d1>=1&&d2>=1)\n {\n \n while(h!=0){\n //System.out.println(h);\n finalweight=finalweight+h;\n //System.out.println(finalweight); \n if(d1==h)\n {\n finalweight-=u1; \n }\n if(d2==h)\n { \n finalweight-=u2; \n \n } \n h=h-1; \n }\n \n } \n if(finalweight<0)\n finalweight=0;\n System.out.println(finalweight);\n \n \n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1500d9c25c8b5e85be5d673042e0690e", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Code1\n{\n\tpublic static void main(String args[])\n\t{\nScanner sc=new Scanner(System.in);\nint w=sc.nextInt();\nint h=sc.nextInt();\n\nint w1=sc.nextInt();\nint h1=sc.nextInt();\nint w2=sc.nextInt();\nint h2=sc.nextInt();\nwhile(h=>0)\n{\nw=w+h;\nif(w<0)\nw=0;\nh=h-1;\n\n\n\n\n\n\n}\nw=w-w1-w2;\nSystem.out.println(w);\n\n\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ad0a69227757d186582ab4f3d7a9dd06", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader reader= new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st= new StringTokenizer(reader.readLine());\n\t\tint peso = Integer.parseInt(st.nextToken());\n\t\tint altura = Integer.parseInt(st.nextToken());\n\t\tst= new StringTokenizer(reader.readLine());\n\t\tint roca1=Integer.parseInt(st.nextToken());\n\t\tint lugar1= Integer.parseInt(st.nextToken());\n\t\tst= new StringTokenizer(reader.readLine());\n\t\tint roca2= Integer.parseInt(st.nextToken());\n\t\tint lugar2= Integer.parseInt(st.nextToken());\n\t\tfor(;altura>=0;altura--) {\n\t\t\tpeso+=altura;\n\t\t\tif(altura==lugar1) {\n\t\t\t\tpeso-=roca1;\n\t\t\t}\n\t\t\telse if(altura==lugar2) {\n\t\t\t\tpeso-=roca2;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(peso);\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "70629e30d480579bcd13d4f8c89c95d3", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Snowball{\n\n public static void main(String[] args) throws IOException{\n \n BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n String[] snowball = bufferedReader.readLine().split(\" \");\n int w = Integer.parseInt(snowball[0]);\n int h = Integer.parseInt(snowball[1]);\n String[] rock1 = bufferedReader.readLine().split(\" \");\n int u1 = Integer.parseInt(rock1[0]);\n int d1 = Integer.parseInt(rock1[1]);\n String[] rock2 = bufferedReader.readLine().split(\" \");\n int u2 = Integer.parseInt(rock2[0]);\n int w2 = Integer.parseInt(rock2[1]);\n for(int i = 1; i <= h; i++){\n w+=i;\n if(i == d1){\n w-=u1;\n if(w < 0){\n w = 0;\n }\n }\n else if(i == d2){\n w-=u2;\n if(w < 0){\n w = 0;\n }\n }\n }\n if(w < 0){\n w = 0;\n }\n System.out.println(w);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e25f08b9e71456a68a853aa31aeda722", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Arrays;\npublic class Icpc {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(System.in);\n\t\tint a[]=new int[6],i,sum=0;\n\t Arraysrrays.sort(a);\n\t for(i=0;i<6;i++){a[i]=in.nextInt();sum+=a[i]}\n\t\tif(sum%2==0(a[0]+a[3]+a[4])==(a[1]+a[2]+a[5])) \n\t\t\tSystem.out.print(\"yes\");\n\t\telse System.out.print(\"no\");\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0dd3a1150d59882fb342fd535d01bfd7", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class ACMICPC {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t\tScanner in= new Scanner(System.in);\n\t\t\n\t\tint a[]=new int[6];\n\t\tint sum=0;\n\t\tfor(int i=0;i<6;i++) {\n\t\t\ta[i]=in.nextInt();\n\t\t\tsum+=a[i];\n\t\t}\n\t\t\n\t\tif(res(a,sum)==true) {\n\t\t\tSystem.out.println(\"yes\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\t\n\t\t\n\n\t}\n\t\n\tstatic boolean res(int a[], int sum) {\n\t\tboolean f= false;\n\t\tfor(int i=0;i<4;i++) {\n\t\t\tfor(int j=i+1;j<5;j++) {\n\t\t\t\tfor(int k=j+1;k<6;k++) {\n\t\t\t\t\tif(a[i]+a[j]+a[k]==sum/2) {\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\t\n\t\treturn false;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3b5b4c1ec0948f81128097c90996500", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class __Solution {\n static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n public static void main(String[] args) {\n new __Solution().run();\n }\n BufferedReader in ;\n PrintWriter out;\n StringTokenizer tok;\n void init() throws FileNotFoundException {\n if (ONLINE_JUDGE) { in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else { in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n tok = new StringTokenizer(\"\");\n }\n void run() {\n try {\n long timeStart = System.currentTimeMillis();\n init();\n solve();\n out.close();\n long timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeStart));\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n String readLine() throws IOException {\n return in.readLine();\n }\n String delimiter = \" \";\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n String nextLine = readLine();\n if (null == nextLine) return null;\n tok = new StringTokenizer(nextLine);\n }\n return tok.nextToken(delimiter);\n }\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n void solve() throws IOException {\n int a[] = new int[6];\n int sum = 0;\n for (int i = 0; i < 6; i++) {\n a[i] = readInt();\n sum += a[i];\n }\n for (int i = 0; i < 6; i++)\n for (int j = i + 1; j < 6; j++)\n for (int k = j + 1; k < 6; k++) {\n if ((a[i] + a[j] + a[k])\u00d72 == sum) {\n out.println(\"YES\");\n return;\n }\n }\n out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "77ebfdce8043d4263b799ef6ca83ffd1", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader() {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// InputStream inputStream = System.in; // Useful when taking input other than\n\t\t// console eg file handling // check ctor of inputReader\n\t\tInputReader scn = new InputReader();\n\n\n\t\tint[] arr = new int[6];\n\t\tfor(int i = 0; i < 6; i++) {\n\t\t\tarr[i] = scn.nextInt();\n\t\t\tsum += arr[i];\n\t\t}\n\t\t\n\t\tif(func(arr, 0, 0, 0)) {\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 func(int[] arr, int si, int y, int x) {\n\t\tif(si == arr.length) {\n\t\t\tif(x == y) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tboolean a = func(arr, si + 1, y, x + arr[si]);\n\t\tboolean b = func(arr, si + 1, y + arr[si], x);\n\t\treturn a || b;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e426a4a7f89f455aa0db92e6cf3fa87e", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000} {"lang": "Java 8", "source_code": "import com.sun.xml.internal.bind.v2.runtime.unmarshaller.IntArrayData;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class PA {\n\n\n\n public static void main(String[] args) throws IOException {\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n\n StringTokenizer st1 = new StringTokenizer(br.readLine());\n\n int n = Integer.parseInt(st1.nextToken()) , k = Integer.parseInt(st1.nextToken());\n\n int min = Integer.MAX_VALUE;\n\n for(int i = 1 ; i <= k-1 ; i++)\n {\n if(n % i == 0)\n {\n min = Math.min(min , (n/i)*k + i);\n }\n }\n\n out.println(min);\n\n out.flush();\n out.close();\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "be921fc25531fff7fa4ca0128b767f4a", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tlong n, k;\n\t\tn = scanner.nextInt();\n\t\tk = scanner.nextInt();\n\t\tArrayList possibleXs = new ArrayList<>();\n\t\tfor (int i = 1; 2 * i <= k; i++) {\n\t\t\tif (k % i != 0) continue;\n\t\t\tfor (int j = 0; j * k + i <= n * k; j++) {\n\t\t\t\tpossibleXs.add(j * k + i);\n\t\t\t}\n\t\t}\n\t\tlong minimum = Long.MAX_LONG;\n\t\tfor (Long x : possibleXs) {\n\t\t\tif ((x / k) * (x % k) == n) {\n\t\t\t\tminimum = Math.min(minimum, x);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(minimum);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a7b272bcd08ab5ab7c9086f7e3c2b499", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\nimport java.util.stream.IntStream;\n\npublic class Solution {\n\n\tpublic static int[] toIntArray(String s) {\n\t\tString[] nums = s.split(\"\\\\s\");\n\t\treturn IntStream.range(0, nums.length)\n\t\t\t.map(index -> Integer.parseInt(nums[index]))\n\t\t\t.toArray();\n\t}\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scanner = new Scanner(System.in);\n\t\t\n\t\tint result = -1;\n\t\t\n\t\tint[] nk = Util.toIntArray(scanner.nextLine());\n\t\t\n\t\tint n = nk[0], k = nk[1];\n\t\t\n\t\tfor (int i = 1; i < k; i++) {\n\n\t\t\tint xLow = (int) n * k / i;\n\t\t\tint x = xLow + i;\n\t\t\tif (x % k == i && ((x / k) * (x % k)) == n) {\n\t\t\t\tif (result == -1)\n\t\t\t\t\tresult = x;\n\t\t\t\telse\n\t\t\t\t\tresult = Math.min(result, x);\n\t\t\t}\n\n\t\t}\n\t\t\n\t\tSystem.out.println(result);\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\t\n\t\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a5e5e61387730973d60e4a2e772b9f3", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.awt.*;\nimport java.awt.geom.*;\nimport java.math.*;\nimport java.text.*;\nimport java.math.BigInteger.*;\nimport java.util.Arrays; \n\npublic class technocupp2\n{\n BufferedReader in;\n StringTokenizer as;\n int nums[],nums2[];\n ArrayList < Integer > [] ar;\n \n public static void main (String[] args)\n {\n new technocupp2 ();\n }\n \n \n public int GCD(int a, int b) {\n if (b==0) return a;\n return GCD(b,a%b);\n }\n \n \n public long stuff(int n, int k)\n {\n return (n/k) * (n % k);\n }\n \n public technocupp2 ()\n {\n try\n {\n \n in = new BufferedReader (new InputStreamReader (System.in));\n long a = nextInt();\n long b = nextInt();\n for(long x = 1;x<1000000000;x++)\n {\n if(stuff(x,b) == a)\n {\n System.out.println(x);\n break;\n }\n }\n }\n \n catch(IOException e)\n {\n \n }\n }\n \n \n \n \n \n \n \n String next () throws IOException\n {\n while (as == null || !as.hasMoreTokens ())\n {\n as = new StringTokenizer (in.readLine ().trim ());\n }\n \n \n return as.nextToken ();\n }\n \n \n \n long nextLong () throws IOException\n {\n return Long.parseLong (next ());\n }\n \n \n int nextInt () throws IOException\n {\n return Integer.parseInt (next ());\n }\n \n \n double nextDouble () throws IOException\n {\n return Double.parseDouble (next ());\n }\n \n \n String nextLine () throws IOException\n {\n return in.readLine ().trim ();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "35055fef5554f488ccdce14a4649d7e2", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class Main {\n static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));\n static PrintWriter out = new PrintWriter(System.out);\n static boolean file = false;\n static final int maxn = 2020;\n static int inf = (int)1e9;\n static int n,k,s,leftSize, rightSize,ans;\n static int f[] = new int[maxn];\n static int a[] = new int[maxn]; \n static HashMap map[] = new HashMap[maxn];\n \n private static void solve() throws Exception {\n n = in.nextInt();\n k = in.nextInt();\n s = in.nextInt();\n \n for (int i=1; i<=n; i++) {\n a[i] = in.nextInt();\n }\n \n for (int i=0; i<=k; i++) {\n map[i] = new HashMap<>();\n }\n \n f[0]=1;\n for (int i=1; i<=22; i++) {\n f[i] = f[i-1]*i;\n }\n \n leftSize = n/2; \n calc1(1,0,0);\n calc2(leftSize + 1, 0,0);\n out.println(ans);\n\n } \n\n private static void calc1(int pos, int q, long sum) {\n if (q>k) return;\n if (pos==leftSize+1) {\n if (!map[q].containsKey(sum))\n map[q].put(sum, 0);\n map[q].put(sum, map[q].get(sum)+1);\n return;\n }\n \n calc1(pos+1,q,sum);\n calc1(pos+1,q,sum+a[pos]);\n if (a[pos]<=18)\n calc1(pos+1,q+1, sum + f[a[pos]]);\n }\n \n private static void calc2(int pos, int q, long sum) {\n if (q>k) return;\n if (pos == n+1){\n for (int i=0; i<=k-q; i++) \n if (map[i].containsKey(s-sum)) {\n ans+=map[i].get(s-sum);\n }\n return;\n }\n calc2(pos+1,q,sum);\n calc2(pos+1,q,sum+a[pos]);\n if (a[pos]<=18)\n calc2(pos+1,q+1, sum + f[a[pos]]);\n }\n\n public static void main (String [] args) throws Exception {\n \n if (file) {\n in = new FastReader(new BufferedReader(new FileReader(\"input.txt\")));\n out = new PrintWriter (\"output.txt\");\n }\n \n solve();\n out.close();\n }\n\n}\n\nclass Pair implements Comparable {\n int x,y;\n \n public Pair(int x, int y) {\n this.x = x;\n this.y = y;\n }\n @Override\n public boolean equals(Object obj) {\n Pair p = (Pair)obj;\n if (p.x == x && p.y==y) return true;\n return false;\n }\n @Override\n public int hashCode() {\n // TODO Auto-generated method stub\n return x;\n }\n @Override\n public int compareTo(Pair p) {\n if (x cubes;\n\tstatic int[] cnt;\n\tstatic long[] a, comb[];\n\t\n\tstatic long bt1(int idx, int k, long S)\n\t{\n\t\tif(idx == 36)\n\t\t\treturn bt2(0, S);\n\t\tlong ret = 0;\n\t\tfor(int i = 0; i <= cnt[idx] && i * a[idx] <= S; ++i)\n\t\t{\n\t\t\tif(idx < 18)\n\t\t\t\tcnt[idx + 18] -= i;\n\t\t\telse if(k < i)\n\t\t\t\tbreak;\n\t\t\tret += comb[cnt[idx]][i] * bt1(idx + 1, k - (idx >= 18 ? i : 0), S - i * a[idx]);\n\t\t\tif(idx < 18)\n\t\t\t\tcnt[idx + 18] += i;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tstatic long bt2(int idx, long S)\n\t{\n\t\tif(S < 0)\n\t\t\treturn 0;\n\t\tif(cubes.size() == idx)\n\t\t\treturn S == 0 ? 1 : 0;\n\t\treturn bt2(idx + 1, S) + bt2(idx + 1, S - cubes.get(idx));\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tcomb = new long[26][26];\n\t\tcomb[0][0] = 1;\n\t\tfor(int i = 1; i <= 25; ++i)\n\t\t{\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];\n\t\t}\n\t\tint n = sc.nextInt(), k = sc.nextInt(), S = sc.nextInt();\n\t\ta = new long[36];\n\t\tfor(int i = 0; i < 18; ++i)\n\t\t\ta[i] = i + 1;\n\t\ta[18] = 1;\n\t\tfor(int i = 19; i < 36; ++i)\n\t\t\ta[i] = a[i - 1] * (i - 17);\n\t\tcnt = new int[36];\n\t\tcubes = new ArrayList<>();\n\t\twhile(n-->0)\n\t\t{\n\t\t\tint x = sc.nextInt();\n\t\t\tif(x <= 18)\n\t\t\t{\n\t\t\t\tcnt[x - 1]++;\n\t\t\t\tcnt[x + 17]++;\n\t\t\t}\n\t\t\telse\n\t\t\t\tcubes.add(x);\n\t\t}\n\t\tout.println(bt1(0, k, S));\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fcec364d6ce826d297126e9d0b3667a9", "src_uid": "2821a11066dffc7e8f6a60a8751cea37", "difficulty": 2100} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * \n * @author pttrung\n */\npublic class E_Round_297_Div2 {\n\n\tpublic static long MOD = 1000000007;\n\tstatic HashMap map = new HashMap();\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n\t\t// \"output.txt\")));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner in = new Scanner();\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tlong s = in.nextLong();\n\t\tint[]data = new int[n];\n\t\tfor(int i = 0; i < n;i++){\n\t\t\tdata[i] = in.nextInt();\n\t\t}\n\t\tout.println(cal(0,k,s, data));\n\t\tout.close();\n\t}\n\n\tpublic static long cal(int index, int left, long cur, int[] data) {\n\t\tif (index == data.length) {\n\t\t\tif (cur == 0) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t\tif (cur == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tState s = new State(index, left, cur);\n\t\tif (map.containsKey(s)) {\n\t\t\treturn map.get(s);\n\t\t}\n\t\tlong result = cal(index + 1, left, cur, data);\n\t\tif (data[index] <= cur) {\n\t\t\tresult += cal(index + 1, left, cur - data[index], data);\n\t\t}\n\t\tif (left > 0 && data[index] <= 19) {\n\t\t\tlong v = 1;\n\t\t\tfor (long i = 1; i <= data[index]; i++) {\n\t\t\t\tv *= i;\n\t\t\t}\n\t\t\tif (v <= cur) {\n\t\t\t\tresult += cal(index + 1, left - 1, cur - v, data);\n\t\t\t}\n\t\t}\n\t\tmap.put(s, result);\n\t\treturn result;\n\t}\n\n\tpublic static class State {\n\t\tint index, left;\n\t\tlong cur;\n\n\t\tpublic State(int index, int left, long cur) {\n\t\t\tthis.index = index;\n\t\t\tthis.left = left;\n\t\t\tthis.cur = cur;\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 + (int) (cur ^ (cur >>> 32));\n\t\t\tresult = prime * result + index;\n\t\t\tresult = prime * result + left;\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\tState other = (State) obj;\n\t\t\tif (cur != other.cur)\n\t\t\t\treturn false;\n\t\t\tif (index != other.index)\n\t\t\t\treturn false;\n\t\t\tif (left != other.left)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable {\n\n\t\tint x, y;\n\n\t\tpublic Point(int start, int end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 5;\n\t\t\thash = 47 * hash + this.x;\n\t\t\thash = 47 * hash + this.y;\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (getClass() != obj.getClass()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfinal Point other = (Point) obj;\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.y != other.y) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a8f01f8665668a9a84b3cc2bfdb5c2c3", "src_uid": "2821a11066dffc7e8f6a60a8751cea37", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.HashMap;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.TreeMap;\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 Alex\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\t//\tint[][][] mem = new int[100][100][100]; //change to hashmap with array of 25 elements each later\n\tHashMap hm = new HashMap<>();\n\tint[] a;\n\tint ncubes;\n\tint kstickers;\n\tlong dp(long sumwant, int curindex, int exclamationsleft){\n\t\tif (sumwant < 0) return 0;\n\t\tif (curindex == a.length && sumwant == 0) return 1;\n\t\tif (curindex == a.length) return 0;\n//\t\tO curobject = new O(sumwant, curindex, exclamationsleft);\n//\t\tif (tm.containsKey(curobject)){\n//\t\t\treturn tm.get(curobject);\n//\t\t}\n//\t\tlong dontchoose = 0, choosenormal = 0, choosefact = 0;\n//\t\tdontchoose = dp(sumwant, curindex + 1, exclamationsleft);\n//\t\tchoosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);\n//\t\tif (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);\n//\t\tlong res = dontchoose + choosenormal + choosefact;\n//\t\ttm.put(curobject, res);\n//\t\treturn res;\n\t\t//\t\treturn pointer[curindex][exclamationsleft] = res;\n\t\t\n\t\t\n\t\t\t\tif (hm.containsKey(sumwant)){\n\t\t\t\t\tlong[][] pointer = hm.get(sumwant);\n\t\t\t\t\tif (pointer[curindex][exclamationsleft] != -1) return pointer[curindex][exclamationsleft];\n\t\t\t\t\tlong dontchoose = 0, choosenormal = 0, choosefact = 0;\n\t\t\t\t\tdontchoose = dp(sumwant, curindex + 1, exclamationsleft);\n\t\t\t\t\tchoosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);\n\t\t\t\t\tif (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);\n\t\t\t\t\tlong res = dontchoose + choosenormal + choosefact;\n\t\t\t\t\treturn pointer[curindex][exclamationsleft] = res;\n\t\t\t\t}\n\t\t\t\tlong dontchoose = 0, choosenormal = 0, choosefact = 0;\n\t\t\t\tdontchoose = dp(sumwant, curindex + 1, exclamationsleft);\n\t\t\t\tchoosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);\n\t\t\t\tif (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);\n\t\t\t\tlong[][] temp = new long[ncubes + 1][kstickers + 1];\n\t\t\t\tArrayUtils.fill(temp, -1);\n\t\t\t\thm.put(sumwant, temp);\n\t\t\t\tlong res = dontchoose + choosenormal + choosefact;\n\t\t\t\treturn temp[curindex][exclamationsleft] = res;\n\t}\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out){\n\t\tncubes = in.ri();\n\t\tkstickers = in.ri();\n\t\tlong SumWant = in.readLong();\n\t\tint[] a = IOUtils.readIntArray(in, ncubes);\n\t\tthis.a = a;\n\t\tlong res = dp(SumWant, 0, kstickers);\n\t\tout.print(res);\n\t}\n}\n\nclass IntegerUtils {\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\nclass ArrayUtils {\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\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\tpublic int ri(){\n\t\treturn readInt();\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\tpublic void print(long i) {\n\t\twriter.print(i);\n\t}\n}\n\nclass IOUtils {\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af35dd0308b5fd72524c322d7505cbd9", "src_uid": "2821a11066dffc7e8f6a60a8751cea37", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\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 StdIn in = new StdIn(inputStream);\n StdOut out = new StdOut(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, StdIn in, StdOut out) {\n int n = StdIn.readInt();\n int ar[] = new int[n];\n for (int i = 0; i < n; i++)\n ar[i] = StdIn.readInt();\n int p = 0;\n int nn = 0;\n for (int i = 0; i < n; i++) {\n if (ar[i] > 0)\n p++;\n if (ar[i] < 0)\n nn++;\n }\n double dd = (1.0 * n) / 2;\n int d = (int) dd;\n if (d != dd)\n d += 1;\n if (p >= d)\n StdOut.println(1);\n else if (nn >= d)\n StdOut.println(-1);\n else\n StdOut.println(0);\n }\n\n }\n\n static class StdOut {\n StdOut();\n\n void close();\n\n void println();\n\n }\n\n static class StdIn {\n StdIn();\n\n int readInt();\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "068e9f7e27375423ea12212d4f8cf875", "src_uid": "a13cb35197f896cd34614c6c0b369a49", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.io.BufferedInputStream;\nimport java.util.Locale;\nimport java.io.OutputStreamWriter;\nimport java.util.Scanner;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.io.UnsupportedEncodingException;\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 StdIn in = new StdIn(inputStream);\n StdOut out = new StdOut(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, StdIn in, StdOut out) {\n int n = StdIn.in.readInt();\n int ar[] = new int[n];\n for (int i = 0; i < n; i++)\n ar[i] = StdIn.in.readInt();\n int p = 0;\n int neg = 0;\n for (int i : ar) {\n if (i > 0)\n p++;\n if (i < 0)\n neg++;\n }\n double dd = (1.0 * n) / 2;\n int d = (int) dd;\n if (dd != d)\n d++;\n if (p >= d)\n StdOut.out.println(1);\n else if (neg >= d)\n StdOut.out.println(-1);\n else\n StdOut.out.println(0);\n }\n\n }\n\n static final class StdIn {\n private static final String CHARSET_NAME = \"UTF-8\";\n private static final Locale LOCALE = Locale.US;\n private static Scanner scanner;\n\n // do this once when StdIn is initialized\n static {\n resync();\n }\n\n private StdIn() {\n }\n\n public static int readInt() {\n try {\n return scanner.nextInt();\n } catch (InputMismatchException e) {\n String token = scanner.next();\n throw new InputMismatchException(\"attempts to read an 'int' value from standard input, \"\n + \"but the next token is \\\"\" + token + \"\\\"\");\n } catch (NoSuchElementException e) {\n throw new NoSuchElementException(\"attemps to read an 'int' value from standard input, \"\n + \"but no more tokens are available\");\n }\n\n }\n\n private static void resync() {\n setScanner(new Scanner(new java.io.BufferedInputStream(System.in), CHARSET_NAME));\n }\n\n private static void setScanner(Scanner scanner) {\n StdIn.scanner = scanner;\n StdIn.scanner.useLocale(LOCALE);\n }\n\n }\n\n static final class StdOut {\n private static final String CHARSET_NAME = \"UTF-8\";\n private static PrintWriter out;\n\n // this is called before invoking any methods\n static {\n try {\n out = new PrintWriter(new OutputStreamWriter(System.out, CHARSET_NAME), true);\n } catch (UnsupportedEncodingException e) {\n System.out.println(e);\n }\n }\n\n private StdOut() {\n }\n\n public static void close() {\n out.close();\n }\n\n public static void println(int x) {\n out.println(x);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "560a1ac2d6b5507c0af0ddcb3fbd2d5f", "src_uid": "a13cb35197f896cd34614c6c0b369a49", "difficulty": 800} {"lang": "Java 8", "source_code": "\npackage text1;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Text1 {\n\n public static void main(String[] args) throws IOException {\n BufferedReader L=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer l=new StringTokenizer(L.readLine());\n \n int n=Integer.parseInt(l.nextToken());\n \n StringTokenizer l1=new StringTokenizer(L.readLine());\n int []a=new int[n];\n \n int x=0,For=0; int n_2=(int)(Math.ceil(n/2.0));\n for (int i = 0; i < n; i++) {\n a[i]=Integer.parseInt(l1.nextToken());\n }\n for (int d =-1; d <= 1 ; d++) {\n int count=0;\n if(d!=0){\n for (int i = 0; i < n; i++) {\n double Dividing=a[i]/((double)d);\n if (Dividing>0) {\n count++;\n }\n }\n if ((Math.max(For,count))==count&&count>=n_2) {\n For=count;\n x=d;\n }\n }\n }\n if(x>0)\n System.out.println(x);\n else\n System.out.println(\"0\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f1467d6e03eb0638a15fc7260563053c", "src_uid": "a13cb35197f896cd34614c6c0b369a49", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\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 StdIn in = new StdIn(inputStream);\n StdOut out = new StdOut(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, StdIn in, StdOut out) {\n int n = StdIn.readInt();\n int ar[] = new int[n];\n for (int i = 0; i < n; i++)\n ar[i] = StdIn.readInt();\n int p = 0;\n int nn = 0;\n for (int i = 0; i < n; i++) {\n if (ar[i] > 0)\n p++;\n if (ar[i] < 0)\n nn++;\n }\n double dd = (1.0 * n) / 2;\n int d = (int) dd;\n if (d != dd)\n d += 1;\n if (p >= d)\n StdOut.println(1);\n else if (nn >= d)\n StdOut.println(-1);\n else\n StdOut.println(0);\n }\n\n }\n\n static class StdOut {\n StdOut();\n\n void close();\n\n void println;\n\n }\n\n static class StdIn {\n StdIn();\n\n int readInt();\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "867ea987bbce56bc535f8fbe0638da20", "src_uid": "a13cb35197f896cd34614c6c0b369a49", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class C507C {\n\tprivate StringTokenizer st;\n\tprivate BufferedReader bf;\n\tprivate int m;\n\tprivate int goal;\n\tprivate int cnt;\n\tprivate int skip;\n\tprivate boolean[] a;\n\n\tpublic C507C() {\n\t\ttry {\n\t\t\tbf = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t\t\n\t\t\tint h = nextInt();\n\t\t\tint n = nextInt();\n\t\t\t\n\t\t\tm = 0;\n\t\t\tfor (int i=0;i<=h;i++) {\n\t\t\t\tm += (int)Math.pow(2, i);\n\t\t\t}\n\t\t\tint k = 0;\n\t\t\tgoal = 0;\n\t\t\tfor (int i=0;i m)\n\t\t\treturn false;\n\t\t\n\t\tfor (int i=0;i<2;i++) {\n\t\t\tif (f) {\n\t\t\t\t//right\n\t\t\t\tnexti = ci * 2 + 1;\n\t\t\t} else {\n\t\t\t\t//left\n\t\t\t\tnexti = ci * 2;\n\t\t\t}\n\t\t\t\n\t\t\tif ((ci * 2) > m)\n\t\t\t\treturn false;\n\t\t\t\n\t\t\tif (a[nexti]) {\n\t\t\t\tskip++;\n\t\t\t\tif (skip==2) {\n\t\t\t\t\tskip = 0;\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tf = !f;\n\t\t\t\tif (search(nexti, f))\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate String next() throws IOException {\n\t\tif (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(bf.readLine());\n\t\treturn st.nextToken();\n\t}\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tC507C c = new C507C();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "923cf071b012bc7f4b470ba4c1d73b65", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Trees\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tint t,h,n;\n\t\tScanner sc = new Scanner(System.in);\n\t\t//t=sc.nextInt();\n\t\t//while(t!=0)\n\t\t//{\n\t\t\tt--;\n\t\t\th=sc.nextInt();\n\t\t\tn=sc.nextInt();\n\t\t\tlong leaf = 1<<(h);\n\t\t\tlong up,low,ans=0;\n\t\t\tboolean dir = true; // true = left, false = right\n\t\t\tup = leaf;\n\t\t\tlow = 1;\n\t\t\twhile(up>low && h>0)\n\t\t\t{\n\t\t\t\tlong mid = (up+low)/2;\n\t\t\t\tlong uc=up,lc=low;\n\t\t\t\tif(dir)\n\t\t\t\t\tuc=mid;\n\t\t\t\telse\n\t\t\t\t\tlc=mid+1;\n\t\t\t\tif(n<=uc && n>=lc)\n\t\t\t\t{\n\t\t\t\t\tup=uc;\n\t\t\t\t\tlow=lc;\n\t\t\t\t\tdir=!dir;\n\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong nodes = (1<<(h));\n\t\t\t\t\tans+=nodes;\n\t\t\t\t\tif(dir)\n\t\t\t\t\t\tlow=mid+1;\n\t\t\t\t\telse\n\t\t\t\t\t\tup=mid;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\th--;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t//}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bb6e5b32d10ede35bf7f02623dceba90", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700} {"lang": "Java 7", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int h=sc.nextInt();\n double n=sc.nextDouble();\n System.out.printf(\"%.0f\",1+caso1(h, n));\n System.out.println(\"\");\n }\n public static double caso1(int h, double n){\n if(h==1){\n return n%2==0?1:0;\n }\n double canNodosVis=(Math.pow(2, h+1)/2);\n double canHojas=Math.pow(2, h);\n if(n>canHojas/2){\n n=n-canHojas/2;\n return canNodosVis+caso1(h-1,n);\n }\n return 1+caso2(h-1,n);\n }\n public static double caso2(int h,double n){\n if(h==1){\n return n%2;\n }\n double canNodosVis=(Math.pow(2, h+1)/2);\n double canHojas=Math.pow(2, h);\n if(n<=canHojas/2){\n return canNodosVis+caso2(h-1,n);\n \n }\n n=n-canHojas/2;\n return 1+caso1(h-1,n);\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf06d8272aab5d79921e7f8b7e6ade76", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\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(in, out);\n out.close();\n }\n}\n\nclass TaskC {\n long foo(long v, long h, boolean f) {\n if (h == 0) return 0;\n if (f) {\n if (1L<<(h-1) >= v) return 1+foo(v, h-1, !f);\n else return ((1L<0){\n if((t & 1)!=0){\n ret = mul(ret, a, mod);\n }\n a = mul(a, a, mod);\n t>>=1;\n }\n return ret;\n }\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int x0 = in.nextInt()-1;\n int y0 = in.nextInt()-1;\n int dx0 =(in.nextInt()%n+n)%n;\n int dy0 =( in.nextInt()%n+n)%n;\n long t = in.nextLong();\n\n int[][] m = { \n { 2, 1, 1, 0, 1, 2 }, \n { 1, 2, 0, 1, 1, 2 }, \n { 1, 1, 1, 0, 1, 2 },\n { 1, 1, 0, 1, 1, 2 }, \n { 0, 0, 0, 0, 1, 1 },\n { 0, 0, 0, 0, 0, 1 }};\n int[][] original = {{x0}, \n {y0}, \n {dx0}, \n {dy0}, \n {0}, \n {1}};\n m = pow(m, t,n);\n int[][] res = mul(m , original, n);\n// System.out.println(Arrays.deepToString(original));\n// System.out.println(Arrays.deepToString(res));\n System.out.println((1+res[0][0])+\" \"+(1+res[1][0]));\n }\n}\n/*\n3 4\n1 2 = 3\n\n4 1\n\n\n*/\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "88c12ce21a7d3b6a1ebd41c068c47526", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300} {"lang": "Java 7", "source_code": "public class E {\n\n\tprivate final static boolean autoflush = false;\n\n\tlong [][] A = {\n\t\t\t{ 1, 0, 0, 0, 0, 0 },\n\t\t\t{ 1, 1, 0, 0, 0, 0 },\n\t\t\t{ 2, 1, 2, 1, 1, 0 },\n\t\t\t{ 2, 1, 1, 2, 0, 1 },\n\t\t\t{ 2, 1, 1, 1, 1, 0 },\n\t\t\t{ 2, 1, 1, 1, 0, 1 }\n\t};\n\n\tpublic E () {\n\t\tint N = sc.nextInt();\n\t\tint X = sc.nextInt() - 1;\n\t\tint Y = sc.nextInt() - 1;\n\t\tint VX = sc.nextInt();\n\t\tint VY = sc.nextInt();\n\t\tlong T = sc.nextLong();\n\n\t\tlong [] V = { 1, 0, X, Y, VX, VY };\n\t\tlong [] W = prod(pow(A, T, N), V, N);\n\t\texit(W[2] + 1, W[3] + 1);\n\t}\n\n\tlong [] prod(long [][] A, long [] V, long mod) {\n\t\tlong [][] W = new long [V.length][1];\n\t\tfor (int i : rep(V.length))\n\t\t\tW[i][0] = V[i];\n\t\tlong [][] X = prod(A, W, mod);\n\t\tlong [] res = new long [X.length];\n\t\tfor (int i : rep(X.length))\n\t\t\tres[i] = X[i][0];\n\t\treturn res;\n\t}\n\n\tlong [][] sum (long [][] A, long [][] B, long mod) {\n\t\tint M = A.length, K = A[0].length, N = B[0].length;\n\t\tassert(K == B.length);\n\t\tlong [][] res = new long [M][N];\n\n\t\tfor (int i = 0; i < M; ++i)\n\t\t\tfor (int j = 0; j < N; ++j)\n\t\t\t\tres[i][j] = mod(A[i][j] + B[i][j], mod);\n\t\treturn res;\n\t}\n\n\tlong [][] prod (long [][] A, long [][] B, long mod) {\n\t\tint M = A.length, K = A[0].length, N = B[0].length;\n\t\tassert(K == B.length);\n\t\tlong [][] res = new long [M][N];\n\n\t\tfor (int i = 0; i < M; ++i)\n\t\t\tfor (int j = 0; j < N; ++j)\n\t\t\t\tfor (int k = 0; k < K; ++k)\n\t\t\t\t\tres[i][j] = mod(res[i][j] + A[i][k] * B[k][j], mod);\n\t\treturn res;\n\t}\n\n\tlong [][] pow (long [][] A, long e, long mod) {\n\t\tlong [][] res = id(A.length);\n\t\tif (e > 0) {\n\t\t\tint M = 1 + Long.numberOfTrailingZeros(Long.highestOneBit(e));\n\t\t\tlong [][][] P = new long[M][][]; P[0] = A;\n\t\t\tfor (int i : rep(1, M))\n\t\t\t\tP[i] = prod(P[i-1], P[i-1], mod);\n\t\t\tfor (int i : rep(M))\n\t\t\t\tif ((e & (1L << i)) != 0)\n\t\t\t\t\tres = prod(res, P[i], mod);\n\t\t}\n\t\treturn res;\n\t}\n\n\tlong [][] id (int N) {\n\t\tlong [][] res = new long [N][N];\n\t\tfor (int i : rep(N))\n\t\t\tres[i][i] = 1;\n\t\treturn res;\n\t}\n\n\t///////////////////////////////////////////////////////////////////////////\n\tprivate static int [] rep(int N) { return rep(0, N); }\n\tprivate static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tprivate static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static MyScanner sc = new MyScanner();\n\tprivate static class MyScanner {\n\t\tpublic String next() { newLine(); return line[index++]; }\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\tpublic long nextLong() { return Long.parseLong(next()); }\n\t\t//////////////////////////////////////////////\n\t\tprivate boolean eol() { return index == line.length; }\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error (e);\n\t\t\t}\n\t\t}\n\t\tprivate final java.io.BufferedReader r;\n\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate String [] line;\n\t\tprivate int index;\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\n\t}\n\tprivate static void print (Object o, Object... a) { printDelim(\" \", o, a); }\n\tprivate static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }\n\tprivate static void exit (Object o, Object... a) { print(o, a); exit(); }\n\tprivate static void exit() {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static String build (String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.substring(delim.length());\n\t}\n\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = java.lang.reflect.Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable)\n\t\t\tfor (Object p : (Iterable)o)\n\t\t\t\tappend(b, p, delim);\n\t\telse\n\t\t\tb.append(delim).append(o);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static void start() { t = millis(); }\n\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);\n\tprivate static long t;\n\tprivate static long millis() { return System.currentTimeMillis(); }\n\tpublic static void main (String[] args) { new E(); exit(); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9863b9bd406dabd81a4adc96a3e3e9cf", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author sheep\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n // [x y dx dy 1]\n long n = in.nextLong();\n\n long sx = ((in.nextLong() - 1) % n + n) % n;\n long sy = ((in.nextLong() - 1) % n + n) % n;\n long dx = (in.nextLong() % n + n) % n;\n long dy = (in.nextLong() % n + n) % n;\n\n long t = in.nextLong();\n\n Matrix move = Matrix.getUnitMatrix(6);\n long[][] mat = move.arr;\n mat[0][2] = 1;\n mat[1][2] = 1;\n mat[0][3] = 1;\n mat[1][3] = 1;\n\n mat[2][0] = 1;\n mat[3][1] = 1;\n\n mat[0][0] = 2;\n mat[1][0] = 1;\n mat[0][1] = 1;\n mat[1][1] = 2;\n\n mat[4][2] = 1;\n mat[4][3] = 1;\n mat[4][0] = 1;\n mat[4][1] = 1;\n\n mat[5][4] = 1;\n\n Matrix result = NumberUtils.powMod(move, t, n);\n\n // [sx sy dx dy 1]\n mat = result.arr;\n long x = (sx * mat[0][0] + sy * mat[1][0] + dx * mat[2][0] + dy * mat[3][0] + 2 * mat[4][0] + mat[5][0]) % n;\n long y = (sx * mat[0][1] + sy * mat[1][1] + dx * mat[2][1] + dy * mat[3][1] + 2 * mat[4][1] + mat[5][1]) % n;\n\n out.println((x + 1) + \" \" + (y + 1));\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 long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n\nclass Matrix {\n\n public long[][] arr;\n\n public Matrix(int size) {\n arr = new long[size][size];\n }\n\n public Matrix(long[][] arr) {\n if (arr.length != arr[0].length) {\n throw new IllegalArgumentException();\n }\n this.arr = new long[arr.length][arr.length];\n for (int i = 0; i < arr.length; ++i) {\n System.arraycopy(arr[i], 0, this.arr[i], 0, arr.length);\n }\n }\n\n public Matrix(int[][] arr) {\n if (arr.length != arr[0].length) {\n throw new IllegalArgumentException();\n }\n this.arr = new long[arr.length][arr.length];\n for (int i = 0; i < arr.length; ++i) {\n for (int j = 0; j < arr.length; ++j) {\n this.arr[i][j] = arr[i][j];\n }\n }\n }\n\n\n public Matrix multiply(Matrix to, Long mod) {\n if (arr.length != to.arr.length) {\n throw new IllegalArgumentException();\n }\n\n Matrix res = new Matrix(arr.length);\n for (int k = 0; k < arr.length; ++k) {\n for (int i = 0; i < arr.length; ++i) {\n if (arr[i][k] == 0) continue;\n for (int j = 0; j < arr.length; ++j) {\n res.arr[i][j] += arr[i][k] * to.arr[k][j];\n if (mod != null && res.arr[i][j] >= mod) {\n res.arr[i][j] %= mod;\n }\n }\n }\n }\n\n return res;\n }\n\n public int size() {\n return arr.length;\n }\n\n public static Matrix getUnitMatrix(int size) {\n Matrix matrix = new Matrix(size);\n for (int i = 0; i < size; ++i) {\n matrix.arr[i][i] = 1;\n }\n return matrix;\n }\n\n public String toString() {\n return Arrays.deepToString(arr);\n }\n}\n\nclass NumberUtils {\n\n public static Matrix powMod(Matrix mat, long p, long mod) {\n\n if (p == 0) {\n return Matrix.getUnitMatrix(mat.size());\n }\n\n if (p == 1) {\n return mat;\n }\n\n if (p % 2 == 0) {\n Matrix res = powMod(mat, p / 2, mod);\n return res.multiply(res, mod);\n }\n\n return powMod(mat, p - 1, mod).multiply(mat, mod);\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0e6460742485d197defedcb1dc080ca5", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300} {"lang": "Java 7", "source_code": "public class E {\n\n\tprivate final static boolean autoflush = false;\n\n\tlong [][] A = {\n\t\t\t{ 1, 0, 0, 0, 0, 0 },\n\t\t\t{ 1, 1, 0, 0, 0, 0 },\n\t\t\t{ 2, 1, 2, 1, 1, 0 },\n\t\t\t{ 2, 1, 1, 2, 0, 1 },\n\t\t\t{ 2, 1, 1, 1, 1, 0 },\n\t\t\t{ 2, 1, 1, 1, 0, 1 }\n\t};\n\n\tpublic E () {\n\t\tint N = sc.nextInt();\n\t\tint X = sc.nextInt() - 1;\n\t\tint Y = sc.nextInt() - 1;\n\t\tint VX = sc.nextInt();\n\t\tint VY = sc.nextInt();\n\t\tlong T = sc.nextLong();\n\n\t\tlong [] V = { 1, 0, X, Y, VX, VY };\n\t\tlong [] W = prod(pow(A, T, N), V, N);\n\t\texit(W[2] + 1, W[3] + 1);\n\t}\n\n\tlong [] prod(long [][] A, long [] V, long mod) {\n\t\tlong [][] W = new long [V.length][1];\n\t\tfor (int i : rep(V.length))\n\t\t\tW[i][0] = V[i];\n\t\tlong [][] X = prod(A, W, mod);\n\t\tlong [] res = new long [X.length];\n\t\tfor (int i : rep(X.length))\n\t\t\tres[i] = X[i][0];\n\t\treturn res;\n\t}\n\n\tlong [][] sum (long [][] A, long [][] B, long mod) {\n\t\tint M = A.length, K = A[0].length, N = B[0].length;\n\t\tassert(K == B.length);\n\t\tlong [][] res = new long [M][N];\n\n\t\tfor (int i = 0; i < M; ++i)\n\t\t\tfor (int j = 0; j < N; ++j)\n\t\t\t\tres[i][j] = mod(A[i][j] + B[i][j], mod);\n\t\treturn res;\n\t}\n\n\tlong [][] prod (long [][] A, long [][] B, long mod) {\n\t\tint M = A.length, K = A[0].length, N = B[0].length;\n\t\tassert(K == B.length);\n\t\tlong [][] res = new long [M][N];\n\n\t\tfor (int i = 0; i < M; ++i)\n\t\t\tfor (int j = 0; j < N; ++j)\n\t\t\t\tfor (int k = 0; k < K; ++k)\n\t\t\t\t\tres[i][j] = mod(res[i][j] + A[i][k] * B[k][j], mod);\n\t\treturn res;\n\t}\n\n\tlong [][] pow (long [][] A, long e, long mod) {\n\t\tlong [][] res = id(A.length);\n\t\tif (e > 0) {\n\t\t\tint M = 1 + Long.numberOfTrailingZeros(Long.highestOneBit(e));\n\t\t\tlong [][][] P = new long[M][][]; P[0] = A;\n\t\t\tfor (int i : rep(1, M))\n\t\t\t\tP[i] = prod(P[i-1], P[i-1], mod);\n\t\t\tfor (int i : rep(M))\n\t\t\t\tif ((e & (1 << i)) != 0)\n\t\t\t\t\tres = prod(res, P[i], mod);\n\t\t}\n\t\treturn res;\n\t}\n\n\tlong [][] id (int N) {\n\t\tlong [][] res = new long [N][N];\n\t\tfor (int i : rep(N))\n\t\t\tres[i][i] = 1;\n\t\treturn res;\n\t}\n\n\t///////////////////////////////////////////////////////////////////////////\n\tprivate static int [] rep(int N) { return rep(0, N); }\n\tprivate static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tprivate static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static MyScanner sc = new MyScanner();\n\tprivate static class MyScanner {\n\t\tpublic String next() { newLine(); return line[index++]; }\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\t//////////////////////////////////////////////\n\t\tprivate boolean eol() { return index == line.length; }\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error (e);\n\t\t\t}\n\t\t}\n\t\tprivate final java.io.BufferedReader r;\n\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate String [] line;\n\t\tprivate int index;\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\n\t}\n\tprivate static void print (Object o, Object... a) { printDelim(\" \", o, a); }\n\tprivate static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }\n\tprivate static void exit (Object o, Object... a) { print(o, a); exit(); }\n\tprivate static void exit() {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static String build (String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.substring(delim.length());\n\t}\n\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = java.lang.reflect.Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable)\n\t\t\tfor (Object p : (Iterable)o)\n\t\t\t\tappend(b, p, delim);\n\t\telse\n\t\t\tb.append(delim).append(o);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static void start() { t = millis(); }\n\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);\n\tprivate static long t;\n\tprivate static long millis() { return System.currentTimeMillis(); }\n\tpublic static void main (String[] args) { new E(); exit(); }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "96ff90516bfad3a73578ed454e8d9c2c", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Main {\n\n\n public static void main(String[] args) {\n MyScanner in = new MyScanner();\n int n = in.nextInt();\n int m = in.nextInt();\n\n boolean[] arr = new boolean[m];\n List positions = new ArrayList<>();\n int max = 0;\n for (int i = 0; i < n; i++) {\n int v = in.nextInt() % m;\n if (v == m - 1) {\n System.out.println(m - 1);\n return;\n }\n max = Math.max(v, max);\n List toAdd = new ArrayList<>();\n for (Integer pos : positions) {\n int v2 = (pos + v) % m;\n max = Math.max(v2, max);\n if (!arr[v2]) {\n toAdd.add(v2);\n arr[v2] = true;\n }\n }\n\n positions.addAll(toAdd);\n if (!arr[v]) {\n positions.add(v);\n arr[v] = true;\n }\n }\n\n System.out.println(max);\n }\n\n public static int gcd(int a, int b) {\n int t;\n while (b != 0) {\n t = b;\n b = a % b;\n a = t;\n }\n return a;\n }\n\n public static void pa(List objs) {\n String str = \"\";\n for (Object obj : objs) {\n str += obj.toString() + \" \";\n }\n p(str);\n }\n\n public static void pa(int[] objs) {\n String str = \"\";\n for (int i = 0; i < objs.length; i++) {\n str += objs[i] + \" \";\n }\n p(str);\n }\n\n static void p(Object str) {\n System.out.println(str);\n }\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "77d433f3c9b8d3301c8ce88218de34af", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.FileInputStream;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.List;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.TreeSet;\nimport java.io.InputStream;\nimport java.util.ArrayList;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author ankur\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n cf solver = new cf();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class cf {\n long mod;\n int n;\n List li = new ArrayList<>();\n int[] ar;\n TreeSet li2 = new TreeSet<>();\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n mod = in.nextInt();\n ar = in.nextIntArray(n);\n subset(0, 0, n / 2);\n subset(n / 2, 0, n);\n long max = 0;\n //out.print();\n // System.out.println(li);\n for (int i = 0; i < li.size(); i++) {\n long val1 = mod - li.get(i) - 1;\n //System.out.println(val1);\n if (val1 <= li2.first()) {\n long val2 = li2.floor(val1);\n if (val2 != 1) {\n max = Math.max(max, val1 + val2);\n }\n }\n max = Math.max(max, li.get(i));\n }\n max = Math.max(max, li2.last());\n out.println(max);\n\n\n }\n\n void subset(int pos, long sum, int last) {\n if (pos == n) {\n li2.add(sum);\n return;\n }\n if (pos >= last) {\n li.add(sum);\n return;\n }\n subset(pos + 1, sum, last);\n subset(pos + 1, (sum + ar[pos]) % mod, last);\n\n }\n\n }\n\n static class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar;\n private int snumChars;\n\n public InputReader(InputStream st) {\n this.stream = st;\n }\n\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public 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 boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dc9678229cf67daaf0dc50e82c912c17", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main\n{\n\tstatic class Reader\n\t{\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic Reader()\n\t\t{\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic Reader(String file_name) throws IOException\n\t\t{\n\t\t\tdin = new DataInputStream(new FileInputStream(file_name));\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String readLine() throws IOException\n\t\t{\n\t\t\tbyte[] buf = new byte[201]; // line length\n\t\t\tint cnt = 0, c;\n\t\t\twhile ((c = read()) != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n')\n\t\t\t\t\tbreak;\n\t\t\t\tbuf[cnt++] = (byte) c;\n\t\t\t}\n\t\t\treturn new String(buf, 0, cnt);\n\t\t}\n\n\t\tpublic int nextInt() throws IOException\n\t\t{\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{\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long nextLong() throws IOException\n\t\t{\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t}\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\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t}\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.')\n\t\t\t{\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t{\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException\n\t\t{\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException\n\t\t{\n\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\tfillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tpublic void close() throws IOException\n\t\t{\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n static ArrayList al;\n static int bs(int l,int r,int v){\n if(r>1;\n if(al.get(m)==v){rs=m;break;}\n if(al.get(m)v)rs--;return (rs>=0)?al.get(rs):0;\n }\n public static void main(String[] args) throws IOException\n\t{\n\t\tReader in=new Reader();PrintWriter out=new PrintWriter(System.out);\n int n=in.nextInt(),m=in.nextInt();\n int a[]=new int[n];\n for(int i=0;i();\n for(int i=1;i<(1<>j)&1)==1)v=(v+a[j])%m;\n }al.add(v);\n }Collections.sort(al);int l=al.size();\n h=n-n/2;int ans=0;\n for(int i=1;i<(1<>j)&1)==1)v=(v+a[n/2+j])%m;\n }int v1=bs(0,l-1,m-v-1);\n int t1=(v+v1)%m,t2=(v+((l==0)?0:al.get(l-1)))%m;\n ans=Math.max(ans,Math.max(t1,t2));\n }out.print(ans);\n out.flush();out.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a97ff53694be81b84ab3209aef1bda9", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class MaxSubSeq {\npublic static void main(String[] args) {\n\tScanner s = new Scanner(System.in);\n\tint n = s.nextInt();\n\tint m = s.nextInt();\n\tint x = 0;\n\tif(n%2!=0) {\n\t\tx=1;\n\t}\n\tint[] a = new int[n/2];\n\tint[] b = new int[n/2+x];\n\tfor (int i = 0; i < a.length; i++) {\n\t\ta[i] = s.nextInt();\n\t}\n\tfor (int i = 0; i < b.length; i++) {\n\t\tb[i] = s.nextInt();\n\t}\n\ts.close();\n\tTreeSet posA = getSums(a,m);\n\tTreeSet posB = getSums(b,m);\n\tIterator it = posA.iterator();\n\tIterator bit = posB.descendingIterator();\n\tint max = 0;\n\tint bEl = bit.next();\n\twhile(it.hasNext()) {\n\t\tint aEl = it.next();\n\t\twhile(aEl+bEl>m) {\n\t\t\tbEl = bit.next();\n\t\t}\n\t\tmax = Math.max((aEl+bEl)%m, max);\n\t}\n\tSystem.out.println(max);\n\t\n}\n\nprivate static TreeSet getSums(int[] a, int m) {\n\tTreeSet obtained = new TreeSet<>();\n\tobtained.add(0);\n\tfor (int i = 0; i2 && k>=2)\n\t\t{\n\t\t\tint gg=(6+((n-(k+1))*3)+2+(n-k)+1+(Math.min(0, k-3)*3)+2);\n\t\t\tint rr=((k*3)+k+(n-(k+1))*3+2);\n\t\t\tint ll=((n-(k-1))*3+(n-k)+((k-1)*3));\n\t\t\tSystem.out.println(Math.min(rr, ll));\n\t\t\t//System.out.println(gg);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "31018de366ce1dc52d16e91388a5d5a4", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class codeForcesPblm1 {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString s = in.next();\n\t\tint alp = 0;\n\t\tboolean flag = false;\n\t\tif(s.length()<26) {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\telse{\n\t\t\tfor(int i = 0;i 0) solver.solve();\n\t\tout.close();\n\t}\n\n\tstatic class Solver {\n\t\t\n\t\tvoid solve() {\n\t\t\tchar[] s = scan.next().toCharArray();\n\t\t\tif(s.length < 26) {\n\t\t\t\tout.println(-1);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint curr = 'a', index = 0;\n\t\t\t\twhile(index < s.length && curr <= 'z') {\n\t\t\t\t\tif(s[index] <= curr) {\n\t\t\t\t\t\ts[index] = (char) curr;\n\t\t\t\t\t\tcurr++;\n\t\t\t\t\t}\n\t\t\t\t\tindex++;\n\t\t\t\t}\n\t\t\t\tif(curr > 'z') out.println(new String(s));\n\t\t\t\telse out.println(-1);\n\t\t\t}\n\t\t}\n\t}\t\n\t\n\t//Sathvik's Template Stuff BELOW!!!!!!!!!!!!!!!!!!!!!!\n\t\n\t\n\tstatic class DSU {\n\t\tint[] root, size;\n\t\tint n;\n\t\tDSU(int n) {\n\t\t\tthis.n = n;\n\t\t\troot = new int[n];\n\t\t\tsize = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\troot[i] = i;\n\t\t\t\tsize[i] = 1;\n\t\t\t}\n\t\t}\n\t\tint findParent(int idx) {\n\t\t\twhile(root[idx] != idx) {\n\t\t\t\troot[idx] = root[root[idx]];\n\t\t\t\tidx = root[idx];\n\t\t\t}\n\t\t\treturn idx;\n\t\t}\t\n\t\tboolean union(int x, int y) {\n\t\t\tint parX = findParent(x);\n\t\t\tint parY = findParent(y);\n\t\t\tif(parX == parY) return false;\n\t\t\tif(size[parX] < size[parY]) {\n\t\t\t\troot[parY] = parX;\n\t\t\t\tsize[parX] += size[parY];\n\t\t\t} else {\n\t\t\t\troot[parX] = parY;\n\t\t\t\tsize[parY] += size[parX]; \n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tstatic class Extra {\n\t\tstatic void sort(int[] a) {\n\t\t\tInteger[] aa = new Integer[a.length];\n\t\t\tfor (int i = 0; i < aa.length; i++) aa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++) a[i] = aa[i];\n\t\t}\n\t\tstatic void sort(long[] a) {\n\t\t\tLong[] aa = new Long[a.length];\n\t\t\tfor (int i = 0; i < aa.length; i++) aa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++) a[i] = aa[i];\n\t\t}\n\t\tstatic void sort(double[] a) {\n\t\t\tDouble[] aa = new Double[a.length];\n\t\t\tfor (int i = 0; i < aa.length; i++) aa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++) a[i] = aa[i];\n\t\t}\n\t\tstatic void sort(char[] a) {\n\t\t\tCharacter[] aa = new Character[a.length];\n\t\t\tfor (int i = 0; i < aa.length; i++) aa[i] = a[i];\n\t\t\tArrays.sort(aa);\n\t\t\tfor (int i = 0; i < aa.length; i++) a[i] = aa[i];\n\t\t}\n\t\tstatic long gcd(long a, long b) {\n\t\t\twhile(b > 0) {\n\t\t\t\tlong temp = b;\n\t\t\t\tb = a%b;\n\t\t\t\ta = temp;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\tstatic long lcm(long a, long b) {\n\t\t\treturn a * (b / gcd(a,b));\n\t\t}\n\t\tstatic boolean isPrime(long n) {\n\t\t\tif (n <= 1) return false; \n\t if (n <= 3) return true; \n\t if (n % 2 == 0 || n % 3 == 0) return false; \n\t for (long i = 5; i * i <= n; i = i + 6) { \n\t if (n % i == 0 || n % (i + 2) == 0) return false; \n\t }\n\t return true;\n\t\t}\n\t\tstatic HashSet sieve(int n) {\n\t\t\tboolean[] prime = new boolean[n+1];\n\t\t\tHashSet res = new HashSet<>();\n\t\t\tfor(int p = 2; p*p <= n; p++) {\n\t\t\t\tif(!prime[p]) {\n\t\t\t\t\tres.add(p);\n\t\t\t\t\tfor(int i = p*p; i <= n; i+=p) prime[i] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tstatic HashMap primeFactorization(long n) {\n\t\t\tHashMap res = new HashMap<>();\n\t\t\twhile(n % 2 == 0) {\n\t\t\t\tres.put(2L, res.getOrDefault(2L, 0)+1);\n\t\t\t\tn/=2;\n\t\t\t}\n\t\t\tfor(long i = 3; i*i <= n; i+=2) {\n\t\t\t\twhile(n % i == 0) {\n\t\t\t\t\tres.put(i, res.getOrDefault(i, 0)+1);\n\t\t\t\t\tn/=i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(n > 2) res.put(n, 1);\n\t\t\treturn res;\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\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 nextLong() {\n\t\t\treturn Long.parseLong(next());\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\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tdouble[] nextDoubleArray(int n) {\n\t\t\tdouble[] a = new double[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextDouble();\n\t\t\treturn a;\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e661e975281e19c989e0efb1b4c9e0b", "src_uid": "f8ad543d499bcc0da0121a71a26db854", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Algo_Str{\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tString s = input.next();\n\t\tchar[] ans = s.toCharArray();\n\t\tif(s.length() < 26){\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\telse{\n\t\t\tlong[] a = new long[26];\n\t\t\tchar c = 'a';\n\t\t\tlong index = -1;\n\t\t\tfor(long i = 0;i= n - 1)\n break;\n for (j = i + d; j > i; j--) {\n if (arr[j] == '1')\n break;\n }\n if (i == j) {\n f = true;\n break;\n }\n if (j >= n - 1)\n break;\n }\n if (f)\n out.println(\"-1\");\n else\n out.println(move);\n\n out.close();\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 println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5fdbf3ce5c9c767a022927f66ddd3bcf", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\nimport com.sun.java.util.jar.pack.Package.Class.Method;\n\nimport java.io.*;\npublic class TheWayToHome\n{ private static final int v = Integer.MAX_VALUE / 3;\n public static void main(String[] args)\n {\n Scanner in = new Scanner(System.in);\n int x = in.nextInt();\n int y = in.nextInt();\n String q = in.next();\n TheWayToHome i = new TheWayToHome();\n System.out.println(i.Method(x, y, q));\n\n \n }\n\n public int Method(int x, int y, String q)\n {\n int[] z = new int[x];\n Arrays.fill(z,v);\n z[0] = 0;\n for(int i = 0; i < x; i++)\n {\n if(q.charAt(i) == '0')\n continue;\n for(int j = i - 1; j >= Math.max(0, i - y); --j)\n {\n z[i] = Math.min(z[i],z[j] + 1);\n\n }\n }\n return z[x - 1] == v ? -1 : z[x -1];\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3371cfd873a2a17b6712f13042516cb4", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class wayhome{\n static int n;\n static int d;\n static int[] pond;\n static int[] visited;\n public static class Lily{\n int x;\n int days;\n public Lily(int a, int b){\n x = a;\n days = b;\n }\n }\n public static void bfs(){\n LinkedList ll = new LinkedList();\n ll.push(new Lily(0,0));\n Lily current;\n while(!ll.isEmpty()){\n current = ll.poll();\n if(current.x < 0 || current.x >= pond.length || pond[current.x] == 0 || visited[current.x] != -1){\n continue;\n }\n //System.out.println(current.days);\n if(current.x == n){\n return;\n }\n visited[current.x] = current.days;\n for(int i = 1; i <= d; i++){\n ll.push(new Lily(current.x + i, current.days + 1));\n }\n }\n }\n public static void main(String[] args) throws IOException{\n //Scanner sc = new Scanner(new File(\"input.in\"));\n Scanenr sc = new Scanner(System.in);\n n = sc.nextInt();\n d = sc.nextInt();\n\n String str_pond = sc.next();\n char[] char_pond = str_pond.toCharArray();\n\n pond = new int[str_pond.length()];\n\n visited = new int[str_pond.length()];\n Arrays.fill(visited, -1);\n\n for(int i = 0; i < str_pond.length(); i++){\n pond[i] = Character.getNumericValue(char_pond[i]);\n }\n\n bfs();\n\n System.out.println(visited[n-1]);\n\n //System.out.println(Arrays.toString(pond));\n //System.out.println(Arrays.toString(visited));\n //System.out.println(pond.length);\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a4fee1a4c9f3fa335a13060b3eb2a3c", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class wayhome{\n static int n;\n static int d;\n static int[] pond;\n static int[] visited;\n public static class Lily{\n int x;\n int days;\n public Lily(int a, int b){\n x = a;\n days = b;\n }\n }\n public static void bfs(){\n LinkedList ll = new LinkedList();\n ll.push(new Lily(0,0));\n Lily current;\n while(!ll.isEmpty()){\n current = ll.poll();\n if(current.x < 0 || current.x >= pond.length || pond[current.x] == 0 || visited[current.x] != -1){\n continue;\n }\n //System.out.println(current.days);\n if(current.x == n){\n return;\n }\n visited[current.x] = current.days;\n for(int i = 1; i <= d; i++){\n ll.push(new Lily(current.x + i, current.days + 1));\n }\n }\n }\n public static void main(String[] args) throws IOException{\n //Scanner sc = new Scanner(new File(\"input.in\"));\n Scanenr sc = new Scanner(System.in);\n n = sc.nextInt();\n d = sc.nextInt();\n\n String str_pond = sc.next();\n char[] char_pond = str_pond.toCharArray();\n\n pond = new int[str_pond.length()];\n\n visited = new int[str_pond.length()];\n Arrays.fill(visited, -1);\n\n for(int i = 0; i < str_pond.length(); i++){\n pond[i] = Character.getNumericValue(char_pond[i]);\n }\n\n bfs();\n\n System.out.println(visited[n-1]);\n\n //System.out.println(Arrays.toString(pond));\n //System.out.println(Arrays.toString(visited));\n //System.out.println(pond.length);\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c00ad475c3dd07aaa9a8c30d6db47fd6", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{ \n static BufferedReader br;\n static StringTokenizer st;\n static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n \n public static class HM extends HashMap {};\n public static class AL extends ArrayList {};\n public static class HS extends HashSet {};\n \n public static void main(String[] args) throws IOException \n\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(br.readLine());\n \n int n=nxtInt();\n String s=nxtLn(),ans=\"\";\n int[] frq=cntCharFrq(s);\n \n if(frq['B'-'A']>=1&&frq['R'-'A']>=1&&frq['G'-'A']>=1) ans=\"BGR\";\n else if(frq['B'-'A']>=2)\n {\n if(frq['R'-'A']>=2&&frq['G'-'A']==0) ans=\"BGR\";\n if(frq['R'-'A']==0&&frq['G'-'A']>=2) ans=\"BGR\";\n else if(frq['R'-'A']==0&&frq['G'-'A']==1) ans=\"GR\";\n else if(frq['R'-'A']==1&&frq['G'-'A']==0) ans=\"GR\";\n }\n else if(frq['B'-'A']==0&&frq['R'-'A']>=2&&frq['G'-'A']>=2) ans=\"BGR\";\n else if(frq['R'-'A']>=2)\n {\n else if(frq['B'-'A']==0&&frq['G'-'A']==1) ans=\"BG\";\n else if(frq['B'-'A']==1&&frq['G'-'A']==0) ans=\"BG\";\n }\n else if(frq['G'-'A']>=2)\n {\n else if(frq['B'-'A']==0&&frq['R'-'A']==1) ans=\"BR\";\n else if(frq['B'-'A']==1&&frq['R'-'A']==0) ans=\"BR\";\n }\n else if(frq['B'-'A']>=1&&frq['R'-'A']==0&&frq['G'-'A']==0) ans=\"B\";\n else if(frq['B'-'A']==0&&frq['R'-'A']>=1&&frq['G'-'A']==0) ans=\"R\";\n else if(frq['B'-'A']==0&&frq['R'-'A']==0&&frq['G'-'A']>=1) ans=\"G\";\n\n pr.print(ans);\n pr.flush();\n\t\tpr.close();\n }\n \n static int nxtInt(){\n return Integer.parseInt(st.nextToken());\n }\n \n static long nxtLong(){\n return Long.parseLong(st.nextToken());\n }\n \n static double nxtDoub(){\n return Double.parseDouble(st.nextToken());\n }\n \n static String nxt(){\n return st.nextToken();\n }\n \n static String nxtLn() throws IOException{\n return br.readLine();\n }\n \n static int[] cntCharFrq(String str){\n int[] ltrs = new int[26];\n for(int i=0; i1)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(\"BG\");\n\t\t\t\t}\n\t\t\t\telse if(G>1)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(\"BR\");\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse if(B>1)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(\"GR\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\n\t}\n\n}\npackage Cards;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in =new Scanner(System.in);\n\t\tint n=Integer.parseInt(in.nextLine());\n\t\tString s=in.nextLine();\n\t\tchar[]arr=new char[n];\n\t\tint R=0,G=0,B=0;\n\t\tint a=0,b=0,c=0;\n\t\tfor(int i=0;i1)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(\"BG\");\n\t\t\t\t}\n\t\t\t\telse if(G>1)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(\"BR\");\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse if(B>1)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.print(\"GR\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9c19de8c7435a21b949cfeec760b34a1", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300} {"lang": "Java 8", "source_code": "import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;\n\nimport java.util.Scanner;\n\n/**\n * Created by gopalan on 2/13/16.\n */\npublic class C626 {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n runProblem2(scanner);\n }\n\n private static void runProblem2(Scanner scanner) {\n int n = scanner.nextInt();\n String output = scanner.next();\n int[] counts = new int[3];\n String value = \"\";\n for (char c : output.toCharArray()) {\n if (c == 'R') counts[0]++;\n if (c == 'G') counts[1]++;\n if (c == 'B') counts[2]++;\n }\n if (isTrue(counts[0], counts[1], counts[2])){\n value += 'R';\n }\n\n if (isTrue(counts[1], counts[0], counts[2])){\n value += 'G';\n }\n\n\n if (isTrue(counts[2], counts[0], counts[1])){\n value += 'B';\n }\n\n\n System.out.println(value);\n\n }\n\n private static boolean isTrue(int count, int count1, int count2) {\n if (count == 0 && count1 > 0 && count2 > 0) return true;\n count += Math.min(count1, count2);\n if (count1 == count2) return true;\n count1 = Math.abs(count1 - count2);\n if (count1 > 1 && count >= 1 ) return true;\n return false;\n\n }\n\n public C626() {\n }\n\n private static void runProblem1(Scanner scanner) {\n\n int n = scanner.nextInt();\n String value = scanner.next();\n int count = 0;\n for (int i = 0; i < n - 1; i++) {\n for (int j = i+1; j <= n; j++) {\n if (isCorrect(value.substring(i, j))){\n count++;\n }\n }\n }\n System.out.println(count);\n }\n\n private static boolean isCorrect(String substring) {\n int xcount = 0;\n int ycount = 0;\n for (char c : substring.toCharArray()) {\n if (c == 'U') xcount++;\n if (c == 'D') xcount--;\n if (c == 'L') ycount ++;\n if (c == 'R') ycount --;\n }\n return (xcount == 0 && ycount == 0);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9ddc9a5abdd9bd79abd118e2f8d0163d", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300} {"lang": "Java 7", "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.ArrayList;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Queue;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class solve {\n\n\tpublic static void main(String[] args) {\n\t\tMyScanner sc = new MyScanner();\n\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\tint n = sc.nextInt();\n\t\tQueue q = new LinkedList();\n\t\tq.add(sc.next());\n\t\tSet ans = new TreeSet();\n\t\tSet visited = new TreeSet();\n\t\twhile (!q.isEmpty()) {\n\t\t\tSet tset = new HashSet();\n\t\t\twhile (!q.isEmpty()) {\n\t\t\t\tString v = q.remove();\n\t\t\t\tif (visited.contains(v)) continue;\n\t\t\t\telse visited.add(v);\n\t\t\t\tStringBuilder b = new StringBuilder(v);\n\t\t\t\tif (b.length() == 1)\n\t\t\t\t\tans.add(b.toString());\n\t\t\t\telse\n\t\t\t\t\tfor (int i = 0; i < b.length(); i++) {\n\t\t\t\t\t\tfor (int j = i + 1; j < b.length(); j++) {\n\t\t\t\t\t\t\tchar ci = b.charAt(i);\n\t\t\t\t\t\t\tchar cj = b.charAt(j);\n\t\t\t\t\t\t\tchar c = move(ci, cj);\n\t\t\t\t\t\t\tStringBuilder t = new StringBuilder(b.toString());\n\t\t\t\t\t\t\ttset.add(t.replace(i, i + 1, c + \"\")\n\t\t\t\t\t\t\t\t\t.replace(j, j + 1, \"\").toString());\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\t\t\tq.addAll(tset);\n\t\t}\n\n\t\tString o = \"\";\n\t\tfor (String t : ans)\n\t\t\to += t;\n\t\tout.println(o);\n\t\tout.close();\n\t}\n\n\n\tstatic String sort(String s) {\n\t\tList v = new ArrayList();\n\t\tfor (char c : s.toCharArray())\n\t\t\tv.add(c);\n\t\ts = \"\";\n\t\tCollections.sort(v);\n\t\tfor (char c : v)\n\t\t\ts += c;\n\t\treturn s;\n\t}\n\tstatic char move(char a, char b) {\n\n\t\tif (a == b)\n\t\t\treturn a;\n\n\t\tif (a == 'R' && b == 'G')\n\t\t\treturn 'B';\n\t\tif (a == 'R' && b == 'B')\n\t\t\treturn 'G';\n\n\t\tif (a == 'G' && b == 'R')\n\t\t\treturn 'B';\n\t\tif (a == 'G' && b == 'B')\n\t\t\treturn 'R';\n\n\t\tif (a == 'B' && b == 'R')\n\t\t\treturn 'G';\n\t\tif (a == 'B' && b == 'G')\n\t\t\treturn 'R';\n\t\treturn a;\n\t}\n\n\t// -----------PrintWriter for faster output---------------------------------\n\tpublic static PrintWriter out;\n\n\t// -----------MyScanner class for faster input----------\n\tpublic static class MyScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic MyScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t// --------------------------------------------------------\n\n}\n\t", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0e96d6bcaf7e527ceb5b070cb6558707", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class CF_1237_2 {\n static int sum=0;\n static int[] a=new int[3000];\n static int[] ans=new int[3000];\n static int n=0;\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner sc=new Scanner(System.in);\n n=sc.nextInt();\n for(int i=2;i<=Math.pow(2, n+1)-1;i++){\n a[i]=sc.nextInt();\n }\n dg(1);\n System.out.println(sum);\n \n }\n static int dg(int x){\n if (x>=Math.pow(2, n))\n return a[x];\n else {\n ans[2*x]=dg(2*x);\n ans[2*x+1]=dg(2*x+1);\n \n sum+=Math.abs(ans[2*x]-ans[2*x+1]);\n return a[x]+Math.max(ans[2*x],ans[2*x+1]);\n \n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66a8802383a6ec43df85d9499ccdc92d", "src_uid": "eb052ca12ca293479992680581452399", "difficulty": 2000} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner sc = new Scanner(System.in);\n long c= sc.nextLong();\n long hr = sc.nextLong();\n long hb = sc.nextLong();\n long wr = sc.nextLong();\n long wb = sc.nextLong();\n long g = GCD(wr,wb);\n wr/=g;\n wb/=g;\n c/=g;\n if(wr>wb){\n long temp = wr;\n long temp2 = hr;\n wr=wb;\n wb=temp;\n hr=hb;\n hb=temp2;\n }\n // c/wr\n long max = 0;\n if(wb<=1000000){\n for(long x = 0;xwb){\n long temp = wr;\n long temp2 = hr;\n wr=wb;\n wb=temp;\n hr=hb;\n hb=temp2;\n }\n // c/wr\n long max = 0;\n if(wb<=1000000){\n for(long x = 0;x=0){\n max=Math.max(x*hr+y*hb,max);\n x+=wb;\n y-=wr;\n }\n }\n }\n }\n System.out.println(max);\n }\n public static long GCD(long a, long b) { return b==0 ? a : GCD(b, a%b); }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cefe90b753e89908ce0a9af896b2f2b6", "src_uid": "eb052ca12ca293479992680581452399", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nimport java.lang.Math;\npublic class MarvoloRing {\n public static void main(String[] args) {\n Scanner kbd = new Scanner(System.in);\n String inp = kbd.nextLine();\n String[] input = inp.split(\" \");\n long inpAx = Long.parseLong(input[0]) * 2;\n long inpAy = Long.parseLong(input[1]) * 2;\n long inpBx = Long.parseLong(input[2]) * 2;\n long inpBy = Long.parseLong(input[3]) * 2;\n long inpCx = Long.parseLong(input[4]) * 2;\n long inpCy = Long.parseLong(input[5]) * 2;\n \n long n = (Math.abs(inpAx - inpBx) * Math.abs(inpAx - inpBx)) + (Math.abs(inpAy - inpBy) * Math.abs(inpAy - inpBy));\n long m = (Math.abs(inpBx - inpCx) * Math.abs(inpBx - inpCx)) + (Math.abs(inpBy - inpCy) * Math.abs(inpBy - inpCy));\n long i = (inpAx + inpCx) / 2;\n long j = (inpAy + inpCy) / 2;\n \n if(n == m && && i != inpBx || j != inpBy)){\n \tSystem.out.println(\"YES\");\n } else{\n \tSystem.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ddb3cb34ceec0e778d9a67dc7f4bbfc4", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author HossamDoma\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n int ax = in.nextInt();\n int ay = in.nextInt();\n\n int bx = in.nextInt();\n int by = in.nextInt();\n\n int cx = in.nextInt();\n int cy = in.nextInt();\n\n long ab = (long) (ax - bx) * (ax - bx) + (long) (ay - by) * (ay - by);\n long bc = (long) (bx - cx) * (bx - cx) + (long) (by - cy) * (by - cy);\n long ac = (long) (ax - cx) * (ax - cx) + (long) (ay - cy) * (ay - cy);\n \n // out.println(ab + \" \" + ac + \" \" + bc);\n \n if (ab != bc || (long) ax * (by - cy) + (long) bx * (cy - ay) + (long) cx * (ay - by)) {\n out.println(\"No\");\n } else\n out.println(\"Yes\");\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "09d23816e5877cd02ec53b5bc8e6e19d", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class B851 {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] tokens = br.readLine().split(\" \");\n long ax = Integer.parseInt(tokens[0]);\n long ay = Integer.parseInt(tokens[1]);\n long bx = Integer.parseInt(tokens[2]);\n long by = Integer.parseInt(tokens[3]);\n long cx = Integer.parseInt(tokens[4]);\n long cy = Integer.parseInt(tokens[5]);\n\n long ab2 = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);\n long bc2 = (bx - cx) * (bx - cx) + (by - cy) * (by - cy);\n\n long slopeTop = (by - ay)\n long slopeBot = (bx - ax);\n double lhs = slopeBot * (cy - ay);\n double rhs = slopeTop * (cx - ax);\n if (lhs == rhs) {\n System.out.println(\"No\");\n } else {\n String ans = \"\";\n if (ab2 == bc2) {\n ans = \"Yes\";\n } else {\n ans = \"No\";\n }\n System.out.println(ans);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3585aae462f2e40dac9a8d333e880927", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main \n{\n public static void main(String [] args) \n {\n int aold,anew,bold,bnew,cold,cnew;\n Scanner input = new Scanner(System.in);\n aold = input.nextInt();\n anew = input.nextInt();\n bold = input.nextInt();\n bnew = input.nextInt();\n cold = input.nextInt();\n cnew = input.nextInt();\n if (((2*bnew)-anew-cnew)*(cnew-anew)==(aold+cold-(2*bold))*(cold-aold) && !(2*bold==aold+cold && 2*bnew==anew+cnew)) \n {\n System.out.println(\"Yes\");\n }\n else \n {\n System.out.println(\"No\");\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7808adc3aab733f4e471179ea5cf0e0d", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class G {\n static long mod = 998244353;\n\n static int N = 1 << 20;\n static int r[] = new int[N];\n\n static long A[] = new long[N];\n static long B[] = new long[N];\n static long C[] = new long[N];\n\n static long base[] = new long[N];\n\n static long pow(long a, long b) {\n if (b == 0) {\n return 1;\n }\n if (b % 2 == 0) {\n return pow(a * a % mod, b / 2);\n } else {\n return pow(a * a % mod, b / 2) % mod * a % mod;\n }\n }\n\n static void ntt(long[] x, int lim, int opt) {\n int i, j, k, m;\n for (i = 0; i < lim; ++i)\n if (r[i] < i) {\n //swap(x[i], x[r[i]]);\n long tmp = x[i];\n x[i] = x[r[i]];\n x[r[i]] = tmp;\n\n }\n for (m = 2; m <= lim; m <<= 1) {\n k = m >> 1;\n long gn = pow(3, (mod - 1) / m);\n for (i = 0; i < lim; i += m) {\n long g = 1;\n for (j = 0; j < k; ++j, g = g * gn % mod)\n {\n long tmp = x[i + j + k] * g % mod;\n x[i + j + k] = (x[i + j] - tmp + mod) % mod;\n x[i + j] = (x[i + j] + tmp) % mod;\n }\n }\n }\n if (opt == -1) {\n for (i = 1; i <= lim / 2; i++) {\n long tmp = x[i];\n x[i] = x[lim - i];\n x[lim - i] = tmp;\n }\n long inv = pow(lim, mod - 2);\n for (i = 0; i < lim; ++i)\n x[i] = x[i] * inv % mod;\n }\n }\n\n static void work(long[] a, long[] b, long[] c, int n) {\n ntt(a, n, 1);\n ntt(b, n, 1);\n for (int i = 0; i < n; ++i) {\n c[i] = a[i] * b[i] % mod;\n }\n ntt(c, n, -1);\n }\n\n static void work2(long[] a, long[] c, int n) {\n ntt(a, n, 1);\n for (int i = 0; i < n; ++i) {\n c[i] = a[i] * a[i] % mod;\n }\n ntt(c, n, -1);\n\n// System.out.print(\"work2 : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(c[i] + \" \");\n// }\n// System.out.println();\n }\n\n public static void main(String[] aaaa) {\n Scanner scanner = new Scanner(System.in);\n long start = System.currentTimeMillis();\n\n int n = scanner.nextInt() / 2;\n int k = scanner.nextInt();\n for (int i = 0; i < N; ++i)\n r[i] = (i & 1) * (N >> 1) + (r[i >> 1] >> 1);\n\n\n A[0] = 1;\n for (int i = 0; i < k; i++) {\n base[scanner.nextInt()] = 1;\n }\n\n// System.out.print(\"base : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(base[i] + \" \");\n// }\n// System.out.println();\n\n int nn = 10;\n while (n > 0) {\n// System.out.println(n);\n if ((n & 1) == 0) {\n //work(A, base, C);\n } else {\n System.arraycopy(base, 0, B, 0, nn);\n work(B, A, C, nn);\n System.arraycopy(C, 0, A, 0, nn);\n }\n work2(base, C, nn);\n System.arraycopy(C, 0, base, 0, nn);\n n /= 2;\n\n nn = Math.min(nn * 2, N);\n\n// System.out.print(\"A : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(A[i] + \" \");\n// }\n// System.out.println();\n\n\n }\n long ans = 0;\n for (int i = 0; i < N; i++) {\n ans += A[i] * A[i];\n ans %= mod;\n }\n System.out.println(ans);\n\n\n// System.out.println(System.currentTimeMillis() - start);\n\n\n\n\n// int n = 0;\n// int lim = 1;\n// String a = scanner.next();\n// n = a.length();\n// for (int i = 0; i < n; i++)\n// A[i] = a.charAt(n - i - 1) - '0';\n// while (lim < (n << 1)) lim <<= 1;\n// String b = scanner.next();\n// n = b.length();\n// for (int i = 0; i < n; i++)\n// B[i] = b.charAt(n - i - 1) - '0';\n// while (lim < (n << 1)) lim <<= 1;\n// for (int i = 0; i < lim; ++i)\n// r[i] = (i & 1) * (lim >> 1) + (r[i >> 1] >> 1);\n// ntt(A, lim, 1);\n// ntt(B, lim, 1);\n// for (int i = 0; i < lim; ++i)\n// C[i] = A[i] * B[i] % mod;\n// ntt(C, lim, -1);\n\n// for (int i = 0; i < lim; i++) {\n// System.out.print(C[i] + \" \");\n// }\n// System.out.println();\n// int len = 0;\n// for (int i = 0; i < lim; ++i) {\n// if (C[i] >= 10) {\n// len = i + 1;\n// C[i + 1] += C[i] / 10;\n// C[i] %= 10;\n// }\n// if (C[i] != 0) {\n// len = Math.max(len, i);\n// }\n// }\n// while (C[len] >= 10) {\n// C[len + 1] += C[len] / 10;\n// C[len] %= 10;\n// len++;\n// }\n// for (int i = len; i >= 0; --i)\n// System.out.print((char)(C[i] + '0'));\n// System.out.println();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "19ce3afb65213f509cfcaf9c9b35fef2", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class G {\n static long mod = 998244353;\n\n static int N = 1 << 20;\n static int r[] = new int[N];\n\n static long A[] = new long[N];\n static long B[] = new long[N];\n static long C[] = new long[N];\n static long D[];\n\n static long base[] = new long[N];\n\n// static long pow(long a, long b) {\n// if (b == 0) {\n// return 1;\n// }\n// if (b % 2 == 0) {\n// return pow(a * a % mod, b / 2);\n// } else {\n// return pow(a * a % mod, b / 2) % mod * a % mod;\n// }\n// }\n\n static long pow(long a, long b) {\n long ans = 1;\n while (b > 0) {\n if ((b & 1) == 1) {\n ans = ans * a % mod;\n }\n b >>= 1;\n a = a * a % mod;\n }\n return ans;\n }\n\n static void ntt(long[] x, int lim, int opt) {\n int i, j, k, m;\n long g, gn, tmp;\n for (i = 0; i < lim; ++i) {\n if (r[i] < i) {\n tmp = x[i];\n x[i] = x[r[i]];\n x[r[i]] = tmp;\n }\n }\n for (m = 2; m <= lim; m <<= 1) {\n k = m >> 1;\n gn = pow(3, (mod - 1) / m);\n for (i = 0; i < lim; i += m) {\n g = 1;\n for (j = 0; j < k; ++j, g = g * gn % mod)\n {\n tmp = x[i + j + k] * g % mod;\n x[i + j + k] = (x[i + j] - tmp + mod) % mod;\n x[i + j] = (x[i + j] + tmp) % mod;\n }\n }\n }\n if (opt == -1) {\n for (i = 1; i <= lim / 2; i++) {\n tmp = x[i];\n x[i] = x[lim - i];\n x[lim - i] = tmp;\n }\n long inv = pow(lim, mod - 2);\n for (i = 0; i < lim; ++i)\n x[i] = x[i] * inv % mod;\n }\n }\n\n static void work(long[] a, long[] b, long[] c, int n) {\n ntt(a, n, 1);\n ntt(b, n, 1);\n for (int i = 0; i < n; ++i) {\n c[i] = a[i] * b[i] % mod;\n }\n ntt(c, n, -1);\n }\n\n static void work2(long[] a, long[] c, int n) {\n ntt(a, n, 1);\n for (int i = 0; i < n; ++i) {\n c[i] = a[i] * a[i] % mod;\n }\n ntt(c, n, -1);\n\n// System.out.print(\"work2 : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(c[i] + \" \");\n// }\n// System.out.println();\n }\n\n public static void main(String[] aaaa) {\n Scanner scanner = new Scanner(System.in);\n long start = System.currentTimeMillis();\n\n int n = scanner.nextInt() / 2;\n int k = scanner.nextInt();\n// for (int i = 0; i < N; ++i)\n// r[i] = (i & 1) * (N >> 1) + (r[i >> 1] >> 1);\n\n\n A[0] = 1;\n for (int i = 0; i < k; i++) {\n base[scanner.nextInt()] = 1;\n }\n\n// System.out.print(\"base : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(base[i] + \" \");\n// }\n// System.out.println();\n\n int nn = 32;\n int last = 0;\n while (n > 0) {\n\n if (last == nn) {\n\n } else {\n for (int i = 0; i < nn; ++i)\n r[i] = (i & 1) * (nn >> 1) + (r[i >> 1] >> 1);\n last = nn;\n }\n\n// System.out.println(n);\n if ((n & 1) == 0) {\n //work(A, base, C);\n } else {\n System.arraycopy(base, 0, B, 0, nn);\n work(B, A, C, nn);\n //System.arraycopy(C, 0, A, 0, nn);\n D = C;\n C = A;\n A = D;\n }\n n /= 2;\n\n\n if (n > 0)\n work2(base, C, nn);\n D = C;\n C = base;\n base = D;\n //System.arraycopy(C, 0, base, 0, nn);\n\n\n nn = Math.min(nn * 2, N);\n\n// System.out.print(\"A : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(A[i] + \" \");\n// }\n// System.out.println();\n\n\n }\n long ans = 0;\n for (int i = 0; i < nn; i++) {\n ans += A[i] * A[i];\n ans %= mod;\n }\n System.out.println(ans);\n\n\n System.out.println(System.currentTimeMillis() - start);\n\n\n\n\n// int n = 0;\n// int lim = 1;\n// String a = scanner.next();\n// n = a.length();\n// for (int i = 0; i < n; i++)\n// A[i] = a.charAt(n - i - 1) - '0';\n// while (lim < (n << 1)) lim <<= 1;\n// String b = scanner.next();\n// n = b.length();\n// for (int i = 0; i < n; i++)\n// B[i] = b.charAt(n - i - 1) - '0';\n// while (lim < (n << 1)) lim <<= 1;\n// for (int i = 0; i < lim; ++i)\n// r[i] = (i & 1) * (lim >> 1) + (r[i >> 1] >> 1);\n// ntt(A, lim, 1);\n// ntt(B, lim, 1);\n// for (int i = 0; i < lim; ++i)\n// C[i] = A[i] * B[i] % mod;\n// ntt(C, lim, -1);\n\n// for (int i = 0; i < lim; i++) {\n// System.out.print(C[i] + \" \");\n// }\n// System.out.println();\n// int len = 0;\n// for (int i = 0; i < lim; ++i) {\n// if (C[i] >= 10) {\n// len = i + 1;\n// C[i + 1] += C[i] / 10;\n// C[i] %= 10;\n// }\n// if (C[i] != 0) {\n// len = Math.max(len, i);\n// }\n// }\n// while (C[len] >= 10) {\n// C[len + 1] += C[len] / 10;\n// C[len] %= 10;\n// len++;\n// }\n// for (int i = len; i >= 0; --i)\n// System.out.print((char)(C[i] + '0'));\n// System.out.println();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a894a31ec47f07f8f29eb10e7561469c", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class G {\n static long mod = 998244353;\n\n static int N = 1 << 20;\n static int r[] = new int[N];\n\n static long A[] = new long[N];\n static long B[] = new long[N];\n static long C[] = new long[N];\n static long D[];\n\n static long base[] = new long[N];\n\n// static long pow(long a, long b) {\n// if (b == 0) {\n// return 1;\n// }\n// if (b % 2 == 0) {\n// return pow(a * a % mod, b / 2);\n// } else {\n// return pow(a * a % mod, b / 2) % mod * a % mod;\n// }\n// }\n\n static long pow(long a, long b) {\n long ans = 1;\n while (b > 0) {\n if ((b & 1) == 1) {\n ans = ans * a % mod;\n }\n b >>= 1;\n a = a * a % mod;\n }\n return ans;\n }\n\n static void ntt(long[] x, int lim, int opt) {\n int i, j, k, m;\n long g, gn, tmp;\n for (i = 0; i < lim; ++i) {\n if (r[i] < i) {\n tmp = x[i];\n x[i] = x[r[i]];\n x[r[i]] = tmp;\n }\n }\n for (m = 2; m <= lim; m <<= 1) {\n k = m >> 1;\n gn = pow(3, (mod - 1) / m);\n for (i = 0; i < lim; i += m) {\n g = 1;\n for (j = 0; j < k; ++j, g = g * gn % mod)\n {\n tmp = x[i + j + k] * g % mod;\n x[i + j + k] = (x[i + j] - tmp + mod) % mod;\n x[i + j] = (x[i + j] + tmp) % mod;\n }\n }\n }\n if (opt == -1) {\n for (i = 1; i <= lim / 2; i++) {\n tmp = x[i];\n x[i] = x[lim - i];\n x[lim - i] = tmp;\n }\n long inv = pow(lim, mod - 2);\n for (i = 0; i < lim; ++i)\n x[i] = x[i] * inv % mod;\n }\n }\n\n static void work(long[] a, long[] b, long[] c, int n) {\n ntt(a, n, 1);\n ntt(b, n, 1);\n for (int i = 0; i < n; ++i) {\n c[i] = a[i] * b[i] % mod;\n }\n ntt(c, n, -1);\n }\n\n static void work2(long[] a, long[] c, int n) {\n ntt(a, n, 1);\n for (int i = 0; i < n; ++i) {\n c[i] = a[i] * a[i] % mod;\n }\n ntt(c, n, -1);\n\n// System.out.print(\"work2 : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(c[i] + \" \");\n// }\n// System.out.println();\n }\n\n public static void main(String[] aaaa) {\n Scanner scanner = new Scanner(System.in);\n long start = System.currentTimeMillis();\n\n int n = scanner.nextInt() / 2;\n int k = scanner.nextInt();\n// for (int i = 0; i < N; ++i)\n// r[i] = (i & 1) * (N >> 1) + (r[i >> 1] >> 1);\n\n int m[] = new int[1 << 21];\n m[0] = 1;\n for (int i = 1; i < m.length; i++) {\n if (i == m[i - 1]) {\n m[i] = i * 2;\n } else {\n m[i] = m[i - 1];\n }\n }\n\n\n A[0] = 1;\n for (int i = 0; i < k; i++) {\n base[scanner.nextInt()] = 1;\n }\n\n// System.out.print(\"base : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(base[i] + \" \");\n// }\n// System.out.println();\n\n int nn = 18;\n int nnn = 18;\n int last = 0;\n while (n > 0) {\n\n nn = m[nnn];\n if (nn > (1 << 20)) {\n nn = 1 << 20;\n }\n if (last == nn) {\n\n } else {\n for (int i = 0; i < nn; ++i)\n r[i] = (i & 1) * (nn >> 1) + (r[i >> 1] >> 1);\n last = nn;\n }\n\n// System.out.println(n);\n if ((n & 1) == 0) {\n //work(A, base, C);\n } else {\n System.arraycopy(base, 0, B, 0, nn);\n work(B, A, C, nn);\n //System.arraycopy(C, 0, A, 0, nn);\n D = C;\n C = A;\n A = D;\n }\n n /= 2;\n\n\n if (n > 0)\n work2(base, C, nn);\n D = C;\n C = base;\n base = D;\n //System.arraycopy(C, 0, base, 0, nn);\n\n\n\n nnn <<= 1;\n// System.out.print(\"A : \");\n// for (int i = 0; i < 100; i++) {\n// System.out.print(A[i] + \" \");\n// }\n// System.out.println();\n\n\n }\n long ans = 0;\n for (int i = 0; i < nn; i++) {\n ans += A[i] * A[i];\n ans %= mod;\n }\n System.out.println(ans);\n\n\n System.out.println(System.currentTimeMillis() - start);\n\n\n\n\n// int n = 0;\n// int lim = 1;\n// String a = scanner.next();\n// n = a.length();\n// for (int i = 0; i < n; i++)\n// A[i] = a.charAt(n - i - 1) - '0';\n// while (lim < (n << 1)) lim <<= 1;\n// String b = scanner.next();\n// n = b.length();\n// for (int i = 0; i < n; i++)\n// B[i] = b.charAt(n - i - 1) - '0';\n// while (lim < (n << 1)) lim <<= 1;\n// for (int i = 0; i < lim; ++i)\n// r[i] = (i & 1) * (lim >> 1) + (r[i >> 1] >> 1);\n// ntt(A, lim, 1);\n// ntt(B, lim, 1);\n// for (int i = 0; i < lim; ++i)\n// C[i] = A[i] * B[i] % mod;\n// ntt(C, lim, -1);\n\n// for (int i = 0; i < lim; i++) {\n// System.out.print(C[i] + \" \");\n// }\n// System.out.println();\n// int len = 0;\n// for (int i = 0; i < lim; ++i) {\n// if (C[i] >= 10) {\n// len = i + 1;\n// C[i + 1] += C[i] / 10;\n// C[i] %= 10;\n// }\n// if (C[i] != 0) {\n// len = Math.max(len, i);\n// }\n// }\n// while (C[len] >= 10) {\n// C[len + 1] += C[len] / 10;\n// C[len] %= 10;\n// len++;\n// }\n// for (int i = len; i >= 0; --i)\n// System.out.print((char)(C[i] + '0'));\n// System.out.println();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "62da5d75d595c17df33e261fc374e2f8", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\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 Andy Phan\n */\npublic class p1096g {\n static long MOD = 998244353;\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt();\n long[] base = new long[10];\n for(int i = 0; i < k; i++) base[in.nextInt()] = 1;\n long[] res = expo(base, n>>1);\n long tot = 0;\n for(long e : res) tot = (tot+(e*e)%MOD)%MOD;\n System.out.println(tot);\n }\n \n static long[] expo(long[] orig, long pow) {\n if(pow == 1) return orig;\n if((pow&1) != 0) return FFT.multiplyPrecise(orig, expo(orig, pow-1));\n long[] tmp = expo(orig, pow>>1);\n return FFT.multiplyPrecise(tmp, tmp);\n }\n \n // SET maxk appropriately!!! ~log(maxn) //%\n static class FFT {\n static final int maxk = 23, maxn = (1 << maxk) + 1;\n // Init: wR, wI, rR, rI, aR, aI to new double[maxn] !!!\n //#\n static double[] wR = new double[maxn],\n wI = new double[maxn],\n rR = new double[maxn],\n rI = new double[maxn],\n aR = new double[maxn],\n aI = new double[maxn]; //$\n static int n, k, lastk = -1, dp[] = new int[maxn];\n\n static void fft(boolean inv) {\n if (lastk != k) {\n lastk = k; dp[0] = 0;\n for (int i = 1, g = -1; i < n; i++) {\n if ((i & (i - 1)) == 0) g++;\n dp[i] = dp[i ^ (1 << g)] ^ (1 << (k - 1 - g));\n }\n wR[1] = 1;\n wI[1] = 0;\n for (int t = 0; t < k - 1; t++) {\n double a = Math.PI / n * (1 << (k - 1 - t));\n double curR = Math.cos(a), curI = Math.sin(a);\n int p2 = (1 << t), p3 = p2 * 2;\n for (int j = p2, k = j * 2; j < p3; j++, k += 2) {\n wR[k] = wR[j];\n wI[k] = wI[j];\n wR[k + 1] = wR[j] * curR - wI[j] * curI;\n wI[k + 1] = wR[j] * curI + wI[j] * curR;\n }\n }\n }\n for (int i = 0; i < n; i++) {\n int d = dp[i];\n if (i < d) {\n double tmp = aR[i];\n aR[i] = aR[d];\n aR[d] = tmp;\n tmp = aI[i];\n aI[i] = aI[d];\n aI[d] = tmp;\n }\n }\n if (inv) for (int i = 0; i < n; i++) aI[i] = -aI[i];\n for (int len = 1; len < n; len <<= 1) {\n for (int i = 0; i < n; i += len) {\n int wit = len;\n for (int it = 0, j = i + len; it < len; it++, i++, j++) {\n double tmpR = aR[j] * wR[wit] - aI[j] * wI[wit];\n double tmpI = aR[j] * wI[wit] + aI[j] * wR[wit];\n wit++;\n aR[j] = aR[i] - tmpR;\n aI[j] = aI[i] - tmpI;\n aR[i] += tmpR;\n aI[i] += tmpI;\n }\n }\n }\n }\n\n static long[] multiply(long[] a, long[] b) {\n int na = a.length, nb = b.length;\n for (k = 0, n = 1; n < na + nb - 1; n <<= 1, k++) {}\n for (int i = 0; i < n; ++i) {\n aR[i] = i < na ? a[i] : 0;\n aI[i] = i < nb ? b[i] : 0;\n }\n fft(false);\n aR[n] = aR[0];\n aI[n] = aI[0];\n double q = -1.0 / n / 4.0;\n for (int i = 0; i <= n - i; ++i) {\n double tmpR = aR[i] * aR[i] - aI[i] * aI[i];\n double tmpI = aR[i] * aI[i] * 2;\n tmpR -= aR[n - i] * aR[n - i] - aI[n - i] * aI[n - i];\n tmpI -= aR[n - i] * aI[n - i] * -2;\n aR[i] = -tmpI * q;\n aI[i] = tmpR * q;\n aR[n - i] = aR[i];\n aI[n - i] = -aI[i];\n }\n fft(true);\n long[] ans = new long[n = na + nb - 1]; // ONLY MOD IF NEEDED\n for (int i = 0; i < n; i++) ans[i] = Math.round(aR[i]) % MOD;\n return ans;\n }\n static void fft2(double[][] xr, double[][] xi, boolean inv) {\n n = xr[0].length;\n k = Integer.numberOfTrailingZeros(n);\n for (int i = 0; i < xr.length; i++) {\n for (int j = 0; j < n; j++) { aR[j] = xr[i][j]; aI[j] = xi[i][j]; }\n fft(inv);\n for (int j=0;j {\n long numer, denom;\n\n public Fraction(long numer, long denom) {\n long g = gcd(numer, denom);\n this.numer = numer / g;\n this.denom = denom / g;\n }\n\n public Fraction next(Fraction other) {\n return new Fraction(this.numer + other.numer, this.denom + other.denom);\n }\n\n public int compareTo(Fraction other) {\n long x1 = (long) this.numer * (long) other.denom;\n long x2 = (long) this.denom * (long) other.numer;\n\n return Long.compare(x1, x2);\n }\n\n public Fraction minus(Fraction other) {\n return new Fraction(this.numer * other.denom - this.denom * other.numer, this.denom * other.denom);\n }\n }\n\n void run() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n\n int x = nextInt();\n int y = nextInt();\n int n = nextInt();\n\n int m = x / y;\n Fraction needle = new Fraction(x - m * y, y);\n\n Fraction left = new Fraction(0, 1);\n Fraction right = new Fraction(1, 1);\n\n Fraction result = null;\n\n while (true) {\n Fraction next = left.next(right);\n\n if (next.denom > n) {\n // must choose between left and right\n Fraction l1 = needle.minus(left);\n Fraction l2 = right.minus(needle);\n\n if (l1.compareTo(l2) <= 0) {\n result = left;\n } else {\n result = right;\n }\n break;\n }\n\n int res = next.compareTo(needle);\n if (res == 0) {\n result = next;\n break;\n } else if (res > 0) {\n right = next;\n } else {\n left = next;\n }\n }\n\n out.printf(\"%d/%d\\n\", result.numer + result.denom * m, result.denom);\n\n out.close();\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc77cd5feaf214e9ab846905bb1eea37", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700} {"lang": "Java 7", "source_code": "\nimport java.util.*;\nimport java.io.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport static java.lang.Math.*;\n\npublic class B {\n\n\t//int INF = 1 << 28;\n\tlong INF = 1L << 62;\n\tdouble EPS = 1e-10;\n\n\tvoid run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong x = sc.nextLong(), y = sc.nextLong();\n\t\tint n = sc.nextInt();\n\t\t\n\t\tP tar = new P(x, y);\n\t\tP cmp = new P(INF, 1), ans = new P(-1, -1);\n\t\tfor(int b=1;b<=n;b++) {\n\t\t\tlong sa = tar.x / tar.y * b + 1, a = INF;\n\t\t\tlong v = INF;\n\t\t\tfor(long i=sa-1;i<=sa+1;i++) if(v > abs(tar.x*b - i*tar.y)){\n\t\t\t\ta = i;\n\t\t\t\tv = abs(tar.x*b - i*tar.y);\n//\t\t\t\tdebug(\"\", a, b);\n\t\t\t}\n\t\t\tP tmp = new P( v, tar.y * b );\n\t\t\tif(cmp.compareTo(tmp)>0) {\n\t\t\t\tcmp = tmp;\n\t\t\t\tans = new P(a, b);\n\t\t\t}\n//\t\t\tdebug(a, v, b);\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tclass P implements Comparable

{\n\t\tlong x, y;\n\t\tP(long x, long y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(P p) {\n\t\t\t// TODO \u81ea\u52d5\u751f\u6210\u3055\u308c\u305f\u30e1\u30bd\u30c3\u30c9\u30fb\u30b9\u30bf\u30d6\n\t\t\treturn x * p.y - p.x * y>0? 1: -1;\n\t\t}\n\t\t\n\t\tpublic String toString() {\n\t\t\treturn x + \"/\" + y;\n\t\t\t\n\t\t}\n\t}\n\n\tvoid debug(Object... os) {\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew B().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d6b003b3eb16bf3c01b7680232c6c981", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700} {"lang": "Java 8", "source_code": "public class B {\n\n public static void main(String[] args) {\n Scanner in = new Scanner();\n int x = in.nextInt();\n int y = in.nextInt();\n int n = in.nextInt();\n long a = n;\n long b = n;\n double cur = 100000;\n double val = (double) x / y;\n //System.out.println(val);\n for (long i = 1; i <= n; i++) {\n long j = x * i / y;\n double temp = (double) j / i;\n double dif = Math.abs(temp - val) - Math.abs(cur - val);\n //System.out.println(temp + \" \" + cur + \" \" + dif);\n if (dif < 0 && Math.abs(dif) > 1e-15) {\n cur = temp;\n // System.out.println(1e7);\n a = j;\n b = i;\n }\n j++;\n temp = (double) j / i;\n dif = Math.abs(temp - val) - Math.abs(cur - val);\n //System.out.println(dif + \" \" + 1e-6);\n if (dif < 0 && Math.abs(dif) > 1e-15) {\n cur = temp;\n a = j;\n b = i;\n }\n }\n System.out.println(a + \"/\" + b);\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\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5d827e04daa477c29d5cc816fe282847", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author MrX\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 int a, b, n;\n a = in.nextInt();\n b = in.nextInt();\n n = in.nextInt();\n\n if (n >= b) {\n out.printf(\"%d/%d\", a, b);\n } else {\n int bestx = 0, besty = 0;\n double bestdiff = 1000000;\n for (int y = n; y > 0; y--) {\n int x = a*y/b;\n if (abs((double)(a * y - b * x)) < bestdiff) {\n bestdiff = abs((double)(a * y - b * x));\n bestx = x; besty = y;\n }\n }\n\n out.printf(\"%d/%d\", bestx, besty);\n }\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "35da57251a027855102dec2461c143f6", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\npublic class tester\n{\n public static void main(String a[])\n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt(),c=0;\n HashMap h=new HashMap();\n for(int j=1;j<=n;j++)\n {\n for(int k=j+1;k<=n;k++)\n {\n int x=j^k;\n \n if(x<=n && j+k>=x && j+x>=k && k+x>=j)\n {\n int a[]=new int[3];\n a[0]=j;\n a[1]=k;\n a[2]=x;\n Arrays.sort(a);\n String st=\"\";\n for(int i=1;i<=3;i++)\n {\n st=st+Integer.toString(a[i])+\" \";\n }\n if(!h.containsKey(st))\n {\n h.put(st,0);\n c++;\n }\n \n \n }\n }\n }\n System.out.println(c);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "33f3223c075529371e38d6fa069ed535", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args)\n {\n Scanner sc=new Scanner(System.in);\n\n int a,b,c,n;\n int x=0;\n n=sc.nextInt();\n for ( a = 1; a<= n; a++) {\n for ( b = a; b <= n; b++) {\n for(c=b;c<=n;c++)\n { \n if ((a^b^c)==0 )\n x++;\n }}}\n System.out.printf(x);\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "08054406a5e08315901a753a9c049c2b", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\npublic class tester\n{\n public static void main(String a[])\n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt(),c=0;\n HashMap h=new HashMap();\n for(int j=1;j<=n;j++)\n {\n for(int k=j+1;k<=n;k++)\n {\n int x=j^k;\n \n if(x<=n && j+k>=x && j+x>=k && k+x>=j)\n {\n int a[]=new int[3];\n a[0]=j;\n a[1]=k;\n a[2]=x;\n Arrays.sort(a);\n String st=\"\";\n for(int i=1;i<=3;i++)\n {\n st=st+Integer.toString(a[i])+\"\";\n }\n if(!h.containsKey(st))\n {\n h.put(st,0);\n c++;\n }\n \n \n }\n }\n }\n System.out.println(c);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3daaa55617bf14dd2f2d2ec7c2644ae1", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args)\n {\n Scanner sc=new Scanner(System.in);\n\n int a,b,n;\n int x=0;\n n=sc.nextInt();\n for ( a = 1; a<= n; a++) {\n for ( b = a; b <= n; b++) {\n int c=a^b;\n if (a+b>c && c<=n) {\n\t\t\t\t\tx++;\n \n }}}\n System.out.printf(x);\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "16d6899e20ea3e3efd1d5d394a335bf4", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class A\n{\n public static void main(String args[])throws IOException\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int n,i,j,count,k;\n String t=br.readLine();\n n=Integer.parseInt(t);\n t=br.readLine();\n char[] s=t.toCharArray();\n k=0;\n for(i=0;i non_x = new ArrayList();\n \n\t\tint x =0;\n\t\tfor(int i =0 ; i < n+1; i++) {\n\t\t\tif(bar[i] != 'x') {\n\t\t\t\tnon_x.add(i);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint counter = 0;\n \n\t//\tSystem.out.println(non_x);\n\t\t\n\t\tArrayList arr = new ArrayList();\n\t\tfor(int i =0 ; i < non_x.size()-1; i ++) {\n\t\t\tarr.add(non_x.get(i+1)- non_x.get(i));\n\t\t}\n\t\t\n\t\t\n\t\tif(non_x.get(0)> 2) {\n \n\t\t\tcounter += non_x.get(0)-2;\n\t\t}\n\t\tfor(int i =1 ; i < arr.size(); i ++) {\n\t\t\tif(arr.get(i)>2) {\n\t\t\t\tcounter += arr.get(i)-2;\n\t\t\t\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(counter);\n\t\t\n\t\t\n\t\t\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a243715b01e84a90bf12cf04474d1239", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800} {"lang": "Java 8", "source_code": "\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Filename {\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\tint n = s.nextInt();\n\t\tString str = s.next();\n\t\tint[] count = new int[26];\n\t\tArrayList ll = new ArrayList<>();\n\t\tif (!str.contains(\"xxx\")) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint c = 0;\n\t\tfor (int i = 0; i < n - 2; i++) {\n\n\t\t\tif (str.charAt(i) == 'x') {\n\t\t\t\tcount['x' - 'a']++;\n\t\t\t\t\n\t\t\t\tif (count['x' - 'a'] == 3) {\n\t\t\t\t\tc++;\n\t\t\t\t\tcount['x' - 'a']--;\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telse {\n\t\t\t\tcount['x' - 'a'] = 0;\n\t\t\t}\n\n\t\t}\n\t\tSystem.out.println(c);", "lang_cluster": "Java", "compilation_error": true, "code_uid": "59137a3ce986e1243f0a617dc4d550a5", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Scanner;\n\n\npublic class Test\n{\n public static void main(String args[])\n {\n int n;\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n String s = sc.next();\n String u = new String(\"xxx\");\n int count = 0;\n while(s.indexOf(u) != -1)\n {\n int x = s.indexOf(u);\n count++;\n s = s.substring(0, x) + s.substring(x + 1);\n }\n System.out.println(count);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "034da680baec114eefd69f9e1ad25167", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800} {"lang": "Java 7", "source_code": "\nimport static java.lang.System.err;\nimport static java.lang.System.out;\nimport java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StringReader;\nimport java.lang.reflect.Array;\nimport java.util.NoSuchElementException;\nimport java.util.StringTokenizer;\nimport static adnap9.contests.cf.Utils.*;\n\npublic class A {\n \n \n public static void main(String[] args) {\n FastReader fr = new FastReader();\n int n = fr.nextInt();\n Integer[] t = fr.nextIntArray(n);\n int min = 0, max = n-1;\n for (int i = 0; i < n; i++) {\n if (t[i] < t[min]) min = i; \n if (t[i] > t[max]) max = i;\n }\n swap(t,0,max);\n swap(t,n-1,min);\n pr.printArray(t, \" \");\n fr.close();\n }\n}\n\n\n\n\n\n\n\n\nclass Printer {\n public Printer() {\n }\n public void println(String s) {\n out.println(s);\n }\n public void print(String s) {\n out.print(s);\n }\n public void ePrintln(String s) {\n err.println(s);\n }\n public void ePrint(String s) {\n err.print(s);\n }\n public void printArray(T[] t) {\n for (T e : t) {\n println(e.toString());\n }\n }\n public void printArray(T[] t, String sep) {\n for (T e : t) {\n print(e.toString() + sep);\n }\n }\n public void ePrintArray(T[] t) {\n for (T e : t) {\n ePrintln(e.toString());\n }\n }\n}\nclass FastReader extends CloseableTextParser {\n private StringTokenizer st;\n private BufferedReader br;\n private boolean isNext = true;\n private boolean closed = false;\n \n /***************/\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n // prepareTokenizer();\n }\n public FastReader(BufferedReader br) {\n this.br = br;\n // prepareTokenizer();\n }\n public FastReader(String s) {\n br = new BufferedReader(new StringReader(s));\n // prepareTokenizer();\n }\n /*******************/\n private void prepareTokenizer() {\n while (isNext == true && (st == null || !st.hasMoreTokens())) {\n try {\n String str = br.readLine();\n if (str == null) {\n isNext = false;\n st = null;\n } else {\n st = new StringTokenizer(str);\n }\n } catch (IOException e) {\n e.printStackTrace();\n throw new RuntimeException(e);\n }\n }\n }\n private String nextToken(String delim) {\n if (closed) throw new IllegalStateException();\n prepareTokenizer();\n if (!isNext) throw new NoSuchElementException();\n String str = (delim != null) ? (st.nextToken(delim)) : (st.nextToken());\n // prepareTokenizer();\n return str;\n }\n private String nextToken() {\n return nextToken(null);\n }\n /*********************/\n public void close() {\n if (closed) throw new IllegalStateException();\n try {\n br.close();\n closed = true;\n } catch (IOException e) {\n e.printStackTrace();\n throw new RuntimeException(e);\n }\n }\n public boolean hasNext() {\n return true;\n }\n /******************************/\n public String next() {\n return nextToken();\n }\n public String next(String delim) {\n return nextToken(delim);\n }\n public String nextLine() {\n return nextToken(\"\\n\");\n }\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n public char nextChar() throws UnsupportedOperationException {\n throw new UnsupportedOperationException();\n }\n public byte nextByte() {\n return Byte.parseByte(nextToken());\n }\n public short nextShort() {\n return Short.parseShort(nextToken());\n }\n public boolean nextBoolean() {\n return Boolean.parseBoolean(nextToken());\n }\n}\nclass Utils {\n public static void fill2d(T[][] t, T el) {\n for (T[] t2 : t) {\n for (int i = 0; i < t2.length; i++) {\n t2[i] = el;\n }\n }\n }\n @SuppressWarnings(\"unchecked\")\n public static T[][] new2dArray(Class c, int sx, int sy) {\n return (T[][]) Array.newInstance(c, sx, sy);\n }\n public static String merge(String[] st) {\n StringBuilder sb = new StringBuilder(\"\");\n for (String s : st)\n sb.append(s);\n return sb.toString();\n }\n \n public static void swap(T[] t, int p1, int p2) {\n T a = t[p1];\n t[p1] = t[p2];\n t[p2] = a;\n }\n \n public final static Printer pr = new Printer();\n \n private Utils() {\n }\n}\nabstract class CloseableTextParser extends ScannerLike implements Closeable, AutoCloseable {}\nabstract class ScannerLike {\n public Integer[] nextIntArray(int n) {\n Integer[] t = new Integer[n];\n for (int i = 0; i < t.length; i++) {\n t[i] = nextInt();\n }\n return t;\n }\n public Long[] nextLongArray(int n) {\n Long[] t = new Long[n];\n for (int i = 0; i < t.length; i++) {\n t[i] = nextLong();\n }\n return t;\n }\n public Short[] nextShortArray(int n) {\n Short[] t = new Short[n];\n for (int i = 0; i < t.length; i++) {\n t[i] = nextShort();\n }\n return t;\n }\n public Byte[] nextByteArray(int n) {\n Byte[] t = new Byte[n];\n for (int i = 0; i < t.length; i++) {\n t[i] = nextByte();\n }\n return t;\n }\n public Boolean[] nextBooleanArray(int n) {\n Boolean[] t = new Boolean[n];\n for (int i = 0; i < t.length; i++) {\n t[i] = nextBoolean();\n }\n return t;\n }\n public String[] nextStringArray(int n, String delim) {\n String[] t = new String[n];\n for (int i = 0; i < t.length; i++) {\n t[i] = (delim != null) ? (next(delim)) : (next());\n }\n return t;\n }\n public String[] nextStringArray(int n) {\n return nextStringArray(n, null);\n }\n /*\n * public T next(ObjectReaderFromText p) { return p.loadFromInput(this); }\n */\n public abstract String next();\n public abstract boolean hasNext();\n public abstract byte nextByte();\n public abstract short nextShort();\n public abstract int nextInt();\n public abstract long nextLong();\n public abstract boolean nextBoolean();\n public abstract String nextLine();\n public abstract String next(String delim);\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "db7655a7e51142299a03a8dd02f7040e", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4", "difficulty": 1300} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Difference {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n ArrayList list = new ArrayList();\n for(int i = 0; i < n; i++) {\n list.add(in.nextInt());\n }\n Collections.sort(list);\n System.out.print(list.get(n-1));\n for(int i = 1; i < n - 1 0; i++) System.out.print (list.get(i) + \" \");\n System.out.print(list.get(0);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4836f4d166e1fd6398302f117b5382b6", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class tatti{\n \n public static void main(String dsgs[]){\n Scanner s = new Scanner(System.in);\n int n;\n n = s.nextInt();\n int a[] =new int[n];\n for(int i=0;i list = new ArrayList();\n for(int i = 0; i < n; i++) {\n list.add(in.nextInt());\n }\n Collections.sort(list);\n System.out.print(list.get(n-1)+ \" \");\n for(int i = 1; i < n - 1 0; i++) System.out.print(list.get(i) + \" \");\n System.out.print(list.get(0));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8fbd8d2f3e7e3e3be7e404a30d3d03eb", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.Math.BigInteger;\n\npublic class Solution{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n BigInteger n = new BigInteger(\"\"+sc.nextInt());\n BigInteger temp = n.add(BigInteger.valueOf(1));\n n = n.multiply(temp);\n n = n.multiply(BigInteger.valueOf(3));\n n = n.add(BigInteger.valueOf(1));\n System.out.println(n);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f502b0d4f714231175d6251fd8fa6cda", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.regex.*;\nimport java.lang.*;\npublic class Main{\n\tpublic static void main(String[] args)\n\t{\n\tScanner sc=new Scanner(System.in);\n\tlong n=sc.nextLone();\n\tSystem.out.println(6+(n-1)*(n+10)/2);\n\t\n\t\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0989387038ef5835ebf9213540d3a0dd", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class sssss {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = br.readLine();\n\t\tlong x =Long.parseLong(s);\n\t\tlong ans=1;\n \n ans+=1l*n*(n+1)*3;\n \n \n System.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7603891fff3684fa9a0493eec301230d", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\npublic class hexagon\n{\n public static void main(String args[])throws IOException\n {\n InputStreamReader read=new InputStreamReader(System.in);\n BufferedReader in=new BufferedReader(read);\n int n;\n n=Integer.parseInt(in.readLine());\n BigInteger s=BigInteger.valueOf(n);\n s=s.multiply(BigIneteger.valueOf(n+1));\n s=s.divide(new BigInteger(\"2\"));\n s=s.multiply(new BigInteger(\"6\");\n s=s.add(new BigInteger(\"1\");\n System.out.println(s);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cd1d76c3b31bdaef71c181d665844e6c", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int k = sc.nextInt();\n StringBuilder line = new StringBuilder();\n\n for (int i = 0; i <= 2800; i++)\n line.append(i);\n\n System.out.print(line.charAt(k));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1fabd14d6b146fe2deab4bdbbfa7fcb7", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class digits\n{\npublic static void main(String args[])\n{\nScanner obj=new Scanner(System.in);\nint n;\nString s;\nchar c;\nn=obj.nextInt();\nfor(int i=1;i<=n;i++)\n{\ns=s+String(i); \n}\nc=s.charAt(n-1);\nSystem.out.println(c);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "18ea486e0f2ac90b333c34b8261ac73c", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class DigitsSequence {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n\n System.out.println(find(scanner.nextInt()));\n\n }\n\n static int find(int index){\n int i = 1;\n int len = 9;\n int max = 9;\n while(len < index){\n int tmp = 9 * (int) Math.pow(10, i);\n i++;\n len += i * tmp;\n max += tmp;\n }\n int diff = len - index;\n int laterCount = diff / i;\n int remainder = diff % i;\n int current = max - laterCount;\n int k = i - 1 - remainder;\n return Integer.parseInt(String.valueOf(current).substring(k, k+1));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8beae6b275ff673622aa0ee0a2469142", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class Main {\n\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int k = sc.nextInt();\n StringBuilder line = new StringBuilder();\n\n for (int i = 0; i <= 2800; i++)\n line.append(i);\n\n System.out.print(line.charAt(k));\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "308b95d9325a5392b265277d12298b1a", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000} {"lang": "Java 8", "source_code": "mport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int x1 = scan.nextInt();\n int y1 = scan.nextInt();\n int x2 = scan.nextInt();\n int y2 = scan.nextInt();\n int x3 = scan.nextInt();\n int y3 = scan.nextInt();\n\n if (isTriangle(x1, y1, x2, y2, x3, y3)) {\n System.out.println(\"RIGHT\");\n } else if (isTriangle(x1 + 1, y1, x2, y2, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1 - 1, y1, x2, y2, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1 + 1, x2, y2, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1 - 1, x2, y2, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2 + 1, y2, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2 - 1, y2, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2, y2 + 1, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2, y2 - 1, x3, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2, y2, x3 + 1, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2, y2, x3 - 1, y3)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2, y2, x3, y3 + 1)) {\n System.out.println(\"ALMOST\");\n } else if (isTriangle(x1, y1, x2, y2, x3, y3 - 1)) {\n System.out.println(\"ALMOST\");\n } else {\n System.out.println(\"NEITHER\");\n }\n\n }\n\n public static double getLength(int x1, int y1, int x2, int y2) {\n int x = Math.max(x1, x2) - Math.min(x1, x2);\n int y = Math.max(y1, y2) - Math.min(y1, y2);\n return Math.sqrt((double) x * x + y * y);\n }\n\n public static boolean isTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {\n if(valid(x1,y1,x2,y2))\n return false;\n if(valid(x2,y2,x3,y3))\n return false;\n if(valid(x3,y3,x1,y1))\n return false;\n double a = getLength(x1, y1, x2, y2);\n double b = getLength(x2, y2, x3, y3);\n double c = getLength(x3, y3, x1, y1);\n if (Math.sqrt(a * a + b * b) - c >= -.01 && Math.sqrt(a * a + b * b) - c <= .01) {\n return true;\n }\n if (Math.sqrt(a * a + c * c) - b >= -.01 && Math.sqrt(a * a + c * c) - b <= .01) {\n return true;\n }\n if (Math.sqrt(c * c + b * b) - a >= -.01 && Math.sqrt(c * c + b * b) - a <= .01) {\n return true;\n }\n return false;\n }\n \n public static boolean valid(int x1, int y1, int x2, int y2){\n if(x1==x2 && y1==y2)\n return true;\n return false;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "976a216f2a18113276eb3ebdc1322e2a", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500} {"lang": "Java 7", "source_code": "\nimport java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport javafx.util.Pair;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author KHALED\n */\npublic class TriangleP2 {\n public static boolean reight(double x1,double y1,double x2,double y2,double x3,double y3)\n {\n// double m1=((double)p1.getY()-(double)p2.getY());\n// if(((double)p1.getX()-(double)p2.getX())==0)\n// m1=-1;\n// else\n// m1/=((double)p1.getX()-(double)p2.getX());\n// double m2=((double)p1.getY()-(double)p3.getY());\n// if(((double)p1.getX()-(double)p3.getX())==0)\n// m2=-1;\n// else\n// m2/=((double)p1.getX()-(double)p3.getX());\n// double m3=((double)p2.getY()-(double)p3.getY());\n// if(((double)p2.getX()-(double)p3.getX())==0)\n// m3=-1;\n// else\n// m3/=((double)p2.getX()-(double)p3.getX());\n// if((m1==0||m2==0||m3==0)&&(m1==-1||m2==-1||m3==-1))\n// return true;\n// return false;\n double d1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);\n double d2=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);\n double d3=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);\n if(d1==d2+d3||d2==d1+d3||d3==d1+d2)\n return true;\n return false;\n }\n public static void main(String[] args) \n {\n MyScanner scan=new MyScanner();\n double x1=scan.nextDouble();\n double y1=scan.nextDouble();\n double x2=scan.nextDouble();\n double y2=scan.nextDouble();\n double x3=scan.nextDouble();\n double y3=scan.nextDouble();\n \n if (reight(x1,y1,x2,y2,x3,y3)) \n {\n System.out.println(\"RIGHT\");\n return;\n }\n double k=x1;\n double h=y1;\n if(reight(k+1,h,x2,y2,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(k-1,h,x2,y2,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(k,h+1,x2,y2,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(k,h-1,x2,y2,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n k=x2;\n h=y2;\n if(reight(x1,y1,k+1,h,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(x1,y1,k-1,h,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(x1,y1,k,h+1,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(x1,y1,k,h-1,x3,y3))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n k=x3;\n h=y3;\n if(reight(x1,y1,x2,y2,k+1,h))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(x1,y1,x2,y2,k-1,h))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(x1,y1,x2,y2,k,h+1))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n if(reight(x1,y1,x2,y2,k,h-1))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n System.out.println(\"NEITHER\");\n }\n}\nclass MyScanner \n{\n static BufferedReader br;\n static StringTokenizer st;\n\n public MyScanner() \n {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() \n {\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "95c0c5654871ff10d457d92cf10ed76a", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class triangle\n{\n public static void main(String[] qqqqadhwiRIZZO_LOVES_BOYS) throws Throwable\n {\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n int[] points=new int[6];\n String[] sa=in.readLine().split(\"\\\\s+\");\n for(int i=0;i<6;i++)\n points[i]=Integer.parseInt(sa[i]);\n if(isRight(points))\n {\n System.out.println(\"RIGHT\");\n return;\n }\n for(int i=0;i<6;i++)\n {\n points[i]--;\n if(isRight(points))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n points[i]+=2;\n if(isRight(points))\n {\n System.out.println(\"ALMOST\");\n return;\n }\n }\n System.out.println(\"NEITHER\");\n \n }\n static boolean hasArea(int[] points)\n {\n double a=Math.sqrt((points[0]-points[2])*(points[0]-points[2])\n +(points[1]-points[3])*(points[1]-points[3])),\n b=Math.sqrt((points[0]-points[4])*(points[0]-points[4])\n +(points[1]-points[5])*(points[1]-points[5])),\n c=Math.sqrt((points[2]-points[4])*(points[2]-points[4])\n +(points[3]-points[5])*(points[3]-points[5]));\n double s=(a+b+c)/2;\n double A=Math.sqrt(s*(s-a)*(s-b)*(s-c));\n return A>.0000000001;\n }\n static boolean isRight(int[] points)\n {\n if(!hasArea(points))\n return false;\n double[] atan2s=new double[3];\n for(int i=0;i<3;i++)\n {\n int dx=points[((i+1)*2)%6]-points[((i)*2)%6];\n int dy=points[(((i+1)*2)+1)%6]-points[(((i)*2)+1)%6];\n atan2s[i]=Math.atan2(dy,dx);\n }\n // System.out.println(Arrays.toString(atan2s));\n for(int i=0;i<3;i++)\n {\n double angle=atan2s[(i+1)%3]-atan2s[i];\n angle=Math.abs(angle)%(2*Math.PI);\n angle=Math.min(angle,2*Math.PI-angle);\n if(Math.abs(Math.abs(angle*2)-Math.PI)<.0000000001 || )\n return true;\n }\n return false;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "84ba0faa59460703f91a427d54fe7c4c", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class A{\n\n Scanner sc=new Scanner(System.in);\n\n void run(){\n P[] ps=new P[3];\n for(int i=0;i<3;i++){\n ps[i]=new P();\n ps[i].x=sc.nextInt();\n ps[i].y=sc.nextInt();\n }\n if(isRight(ps)){\n System.out.println(\"RIGHT\");\n return;\n }\n boolean f=false;\n int dx={0,0,-1,1};\n int dy={-1,1,0,0};\n for(int j=0;j<3;j++){\n P p=ps[j];\n for(int i=0;i<4;i++){\n p.x+=dx[i];\n p.y+=dy[i];\n if(isRight(p)){\n System.out.println(\"ALMOST\");\n return;\n }\n\n p.x-=dx[i];\n p.y-=dy[i];\n }\n }\n System.out.println(\"NEITHER\");\n\n }\n\n class P{\n int x, y;\n P(int x, int y){\n this.x=x;\n this.y=y;\n }\n P(){\n this(0,0);\n }\n }\n \n boolean isRight(P[] ps){\n int[] d=new int[3];\n for(int i=0;i<3;i++){\n P p=ps[i];\n P q=ps[(i+1)%3];\n d[i]=(q.x-p.x)*(q.x-p.x)+(q.y-p.y)*(q.y-p.y);\n }\n Arrays.sort(d);\n return d[0]!=0&&d[0]+d[1]==d[2];\n }\n\n public static void main(String[] args){\n new A().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a1ae596194850fe718eb4dbcb6f887a", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class Test {\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int R, C;\n long[][] ch = new long[61][61];\n int[] cntA = new int[61], cntB = new int[61];\n long best = Long.MAX_VALUE;\n String str;\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c) || c == '?') {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n void dfs(long x, long y, int v1, int v2) {\n long diff = Math.abs(x - y);\n if (best <= 1 || diff - ch[v1][R] * ch[v2][R] >= best) return;\n if (v1 == R - 1 && v2 == R - 1) {\n if (diff < best) best = diff;\n return;\n }\n if (v1 >= R) {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n dfs(x, y + cur * other, v1 - 1, v2);\n }\n if (v2 >= R) {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n dfs(x + cur * other, y, v1, v2-1);\n }\n }\n\n long solve(long x, long y, int v1, int v2) {\n long diff = Math.abs(x - y);\n if (diff - ch[v1][R] * ch[v2][R] > best) return 0;\n if (v1 < R || v2 < R) {\n if (v1 >= cntA[v1 + v2] && v2 >= cntB[v1 + v2]) {\n int sum = v1 + v2;\n v1 -= cntA[sum];\n v2 -= cntB[sum];\n return ch[v1 + v2][v1];\n }\n return 0;\n }\n long ans = 0;\n char c = str.charAt(v1 + v2 - 1);\n if (c != 'B') {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n ans += solve(x, y + cur * other, v1 - 1, v2);\n }\n if (c != 'A') {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n ans += solve(x + cur * other, y, v1, v2 - 1);\n }\n return ans;\n }\n\n void start() {\n R = readInt();\n C = readInt();\n for (int i = 0; i <= 2*(R + C); i++)\n for (int j = 0; j <= i; j++)\n if (j == 0 || j == i) ch[i][j] = 1;\n else ch[i][j] = ch[i - 1][j - 1] + ch[i - 1][j];\n long x = 0, y = 0;\n int v1 = R + C, v2 = R + C;\n while (v1 >= R && v2 >= R)\n if (x > y) {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n y += cur * other;\n v1--;\n } else {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n x += cur * other;\n v2--;\n }\n best = Math.abs(x - y);\n dfs(0, 0, R + C, R + C);\n str = readString();\n for (int i = 0; i < 2 * (R + C); i++) {\n cntA[i + 1] = cntA[i] + (str.charAt(i) == 'A' ? 1 : 0);\n cntB[i + 1] = cntB[i] + (str.charAt(i) == 'B' ? 1 : 0);\n }\n long ans = solve(0, 0, R + C, R + C);\n writer.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ddc585624729b66fc557647b85908f8c", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85", "difficulty": 3300} {"lang": "Java 8", "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[61][61];\n long best;\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 == r - 1 && v2 == r - 1) {\n if (d < best) best = d;\n return;\n }\n if (v1 >= r) {\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 >= r) {\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[61], cntB = new int[61];\n Map cache = new HashMap<>();\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 < r || v2 < r) {\n if (v1 >= cntA[v1+v2] && v2 >= cntB[v1+v2]) {\n int sum = v1 + v2;\n v1 -= cntA[sum];\n v2 -= cntB[sum];\n v = C[v1+v2][v1];\n cache.put(k, v);\n return v;\n }\n cache.put(k, v);\n return v;\n }\n long ans = 0;\n char c = cs[v1 + v2 - 1];\n if (c != 'B') {\n long c1 = C[v1][r] - C[v1 - 1][r], s2 = C[v2][r];\n ans += solve(x, y + c1*s2, v1 - 1, v2);\n }\n if (c != 'A') {\n long s1 = C[v1][r], c2 = C[v2][r] - C[v2-1][r];\n ans += solve( x + s1*c2, y, v1, v2 - 1);\n }\n return ans;\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 >= r && 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e8ac86870ccd922d8e5adbe896c8f005", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85", "difficulty": 3300} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class Test {\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int R, C;\n long[][] ch = new long[31][31];\n int[] cntA = new int[61], cntB = new int[61];\n long best = Long.MAX_VALUE;\n String str;\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c) || c == '?') {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n void dfs(long x, long y, int v1, int v2) {\n long diff = Math.abs(x - y);\n if (best <= 1 || diff - ch[v1][R] * ch[v2][R] >= best) return;\n if (v1 == R - 1 && v2 == R - 1) {\n if (diff < best) best = diff;\n return;\n }\n if (v1 >= R) {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n dfs(x, y + cur * other, v1 - 1, v2);\n }\n if (v2 >= R) {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n dfs(x + cur * other, y, v1, v2-1);\n }\n }\n\n long solve(long x, long y, int v1, int v2) {\n long diff = Math.abs(x - y);\n if (diff - ch[v1][R] * ch[v2][R] > best) return 0;\n if (v1 < R || v2 < R) {\n if (v1 >= cntA[v1 + v2] && v2 >= cntB[v1 + v2]) {\n int sum = v1 + v2;\n v1 -= cntA[sum];\n v2 -= cntB[sum];\n return ch[v1 + v2][v1];\n }\n return 0;\n }\n long ans = 0;\n char c = str.charAt(v1 + v2 - 1);\n if (c != 'B') {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n ans += solve(x, y + cur * other, v1 - 1, v2);\n }\n if (c != 'A') {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n ans += solve(x + cur * other, y, v1, v2 - 1);\n }\n return ans;\n }\n\n void start() {\n R = readInt();\n C = readInt();\n for (int i = 0; i <= R + C; i++)\n for (int j = 0; j <= i; j++)\n if (j == 0 || j == i) ch[i][j] = 1;\n else ch[i][j] = ch[i - 1][j - 1] + ch[i - 1][j];\n long x = 0, y = 0;\n int v1 = R + C, v2 = R + C;\n while (v1 >= R && v2 >= R)\n if (x > y) {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n y += cur * other;\n v1--;\n } else {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n x += cur * other;\n v2--;\n }\n best = Math.abs(x - y);\n dfs(0, 0, R + C, R + C);\n str = readString();\n for (int i = 0; i < 2 * (R + C); i++) {\n cntA[i + 1] = cntA[i] + (str.charAt(i) == 'A' ? 1 : 0);\n cntB[i + 1] = cntB[i] + (str.charAt(i) == 'B' ? 1 : 0);\n }\n long ans = solve(0, 0, R + C, R + C);\n writer.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c8a065b3576f0da34d1b779d76490aad", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85", "difficulty": 3300} {"lang": "Java 8", "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 == r - 1 && v2 == r - 1) {\n if (d < best) best = d;\n return;\n }\n if (v1 >= r) {\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 >= r) {\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 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 < r || v2 < r) {\n int sum = v1 + v2;\n if (v1 >= cntA[sum] && v2 >= cntB[sum]) {\n v1 -= cntA[sum];\n v2 -= cntB[sum];\n v = C[v1+v2][v1];\n cache.put(k, v);\n return v;\n }\n cache.put(k, v);\n return v;\n }\n char c = cs[v1 + v2 - 1];\n if (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 (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 >= r && 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9f9f636e9208dd34fd9c5dfbb7cc53a", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85", "difficulty": 3300} {"lang": "Java 8", "source_code": "public class Main {\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n// BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));\n// BufferedReader entrada = new BufferedReader(new InputStreamReader(new FileInputStream(\"C:\\\\Users\\\\felipe.santos\\\\Documents\\\\entradas.txt\")));\n// Scanner entrada = new Scanner(new FileInputStream(\"C:\\\\Users\\\\felipe.santos\\\\Documents\\\\entradas.txt\"));///home/felipe/\n Scanner entrada = new Scanner(System.in);\n BufferedWriter saida = new BufferedWriter(new OutputStreamWriter(System.out));\n// BufferedWriter saida = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(\"C:\\\\Users\\\\felipe.santos\\\\Documents\\\\saidas.txt\")));;\n\n //left, straight, right, pedestrian\n boolean[][] lights = new boolean[4][4];\n for (int i = 0; i < 4; i++) {\n for (int j = 0; j < 4; j++) {\n lights[i][j] = entrada.nextInt() > 0;\n }\n }\n //por linha\n boolean res = false;\n for (int i = 0; i < 4 && !res; i++) {\n //sinal aberto + pedestre passando\n if (lights[i][3]) {\n for (int j = 0; j < 3 && !res; j++) {\n if (lights[i][j]) {\n res = true;\n }\n }\n }\n //quais sinais est\u00e3o abertos\n if (lights[i][0] && !res) {\n //esquerda\n int idx = ((i - 1) + 4) % 4;\n if (lights[idx][3])\n res = true;\n }\n if (lights[i][1] && !res) {\n //reto\n int idx = (i + 2) % 4;\n if (lights[idx][3])\n res = true;\n }\n if (lights[i][2] && !res) {\n //direita\n int idx = (i + 1) % 4;\n if (lights[idx][3])\n res = true;\n }\n }\n\n if (res) {\n saida.write(\"YES\");\n } else {\n saida.write(\"NO\");\n }\n saida.write(\"\\n\");\n saida.flush();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6d309e1d15f6cd4167a5a89dc04766d9", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class light\n{\n public static void main(String[]args)throws Exception\n {\n Scanner d=new Scanner(System.in);\n int mat[][]=new int[4][4];\n int c=0;\n for(int i=0;i<4;i++)\n for(int j=0;j<4;j++)\n mat[i][j]=d.nextInt();\n \n for(int i=0;i<4;i++)\n {\n if(mat[0][3]==1)\n if((mat[0][1]==1)||(mat[0][2]==1)||(mat[0][0]==1)||(mat[3][2]==1)||(mat[1][0]==1)||(mat[2][1]))\n c=1;\n if(mat[1][3]==1)\n if((mat[1][1]==1)||(mat[1][2]==1)||(mat[1][0]==1)||(mat[2][0]==1)||(mat[0][2]==1)||(mat[3][1]))\n c=1; \n if(mat[2][3]==1)\n if((mat[2][1]==1)||(mat[2][2]==1)||(mat[2][0]==1)||(mat[3][0]==1)||(mat[1][2]==1)||(mat[0][1]))\n c=1; \n if(mat[3][3]==1)\n if((mat[3][1]==1)||(mat[3][2]==1)||(mat[3][0]==1)||(mat[0][0]==1)||(mat[2][2]==1)||(mat[1][1]))\n c=1; \n }\n if(c==1)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "03cd31b51c568268075fad274ad4cf3a", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n public static final int SIZE = 4;\n private static PrintWriter out;\n\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n\n InputData[] inputDatas = new InputData[SIZE];\n\n for (int i = 0; i < inputDatas.length; i++) {\n inputDatas[i] = new InputData(sc.nextLine());\n }\n\n String answer = null;\n for (int i = 0; i < SIZE; i++) {\n if (!inputDatas[i].p)\n continue;\n for (int j = 0; j < SIZE; j++) {\n if (parseRoadNumber(j, inputDatas[(i + j) % SIZE])) {\n answer = \"YES\";\n }\n }\n }\n\n if (answer == null) {\n answer = \"NO\";\n }\n \n out.println(answer);\n out.close();\n }\n\n private static boolean parseRoadNumber(int i, InputData data) {\n switch (i) {\n case 0:\n case 2:\n return data.s;\n case 1:\n return data.l;\n case 3:\n return data.r;\n }\n }\n\n static class InputData {\n final boolean l;\n final boolean s;\n final boolean r;\n final boolean p;\n\n InputData(String data) {\n final String[] split = data.split(\" \");\n\n l = parseData(split[0]);\n s = parseData(split[1]);\n r = parseData(split[2]);\n p = parseData(split[3]);\n }\n\n private boolean parseData(String d) {\n return \"1\".equals(d);\n }\n }\n\n //-----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "699efa29d23fdc82b4ac0526b2dba170", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class Main\n{\n static class FastReader\n {\n final BufferedReader br;\n StringTokenizer st;\n\n FastReader()\n {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n FastReader(String inputFile){\n try {\n br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));\n } catch (FileNotFoundException e) {\n throw new RuntimeException(e);\n }\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 FastWriter{\n PrintWriter printWriter;\n\n FastWriter(){\n printWriter = new PrintWriter(new BufferedOutputStream(System.out));\n }\n\n FastWriter(String outputFile){\n File file = new File(outputFile);\n if (!file.exists()){\n try {\n if (!file.createNewFile())\n throw new RuntimeException(\"Output file was not created!\");\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n try {\n printWriter = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file)));\n } catch (FileNotFoundException e) {\n throw new RuntimeException(e);\n }\n }\n\n void print(Object object){\n printWriter.print(object);\n }\n\n void print(Object ...objects){\n for (int i = 0; i < objects.length; i ++) {\n printWriter.print(objects[i]);\n if (i != objects.length - 1)\n printWriter.write(' ');\n }\n }\n\n void flush(){\n printWriter.flush();\n }\n }\n\n public static void main(String[] args)\n {\n setup();\n xuly();\n }\n\n private static void setup() {\n Scanner scanner = new Scanner(System.in);\n int[] l = new int[4], r = new int[4], s = new int[4], p = new int[4];\n for (int i = 0; i < 4; i ++){\n l[i] = scanner.nextInt();\n s[i] = scanner.nextInt();\n r[i] = scanner.nextInt();\n p[i] = scanner.nextInt();\n }\n\n for (int i = 0; i < 4; i ++){\n int preDir = (i == 0? 3 : i - 1);\n int nexDir = (i == 3? 0 : i + 1);\n boolean accident = p[i] == 1 && (s[i] == 1 || r[preDir] == 1 || l[nexDir] == 1);\n if (accident){\n System.out.print(\"YES\");\n return;\n }\n }\n System.out.print(\"NO\");\n }\n\n private static void xuly() {\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f92172c2e7865007aab71afe08803c6f", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.stream.IntStream;\n\npublic class Lesha {\n\n public static void main(String[] args) throws IOException {\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int size = Integer.parseInt(br.readLine());\n StringTokenizer st = new StringTokenizer(br.readLine());\n int[] numbers = new int[size];\n boolean allZeros = true;\n for(int i = 0; i < size; i++){\n numbers[i] = Integer.parseInt(st.nextToken());\n if(allZeros && numbers[i] != 0)\n allZeros = false;\n }\n\n if(allZeros){\n System.out.println(\"NO\");\n return;\n }\n\n int sum = IntStream.of(numbers).sum();\n System.out.println(\"YES\");\n if(sum != 0)\n System.out.println(1);\n System.out.println(1 + \" \" + size);\n else {\n System.out.println(2);\n for(int i = 0; i < size; i++){\n if(numbers[i] != 0){\n System.out.println(1 + \" \" + (i+1));\n System.out.println((i+2) + \" \" + size);\n return;\n }\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "01149cb170c910ea108311c54b81717a", "src_uid": "3a9258070ff179daf33a4515def9897a", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{ \n static BufferedReader br;\n static StringTokenizer st;\n static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n public static void main(String[] args) throws IOException \n\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(br.readLine());\n \n int n=nxtInt();\n int[] a=new int[n];\n AL idx=new AL<>();\n st = new StringTokenizer(br.readLine());\n for(int i=0; i nums = new ArrayList<>();\n \n for (int i = 1; i <= n; i++) {\n int v = in.nextInt();\n if(v != 0) {\n nums.add(v);\n }\n }\n \n if(v.size() < 2) {\n System.out.print(\"NO\");\n } else {\n System.out.println(\"YES\");\n System.out.println(nums.size());\n \n int left = 1;\n for (int i = 0, size = nums.size() - 1; i < size; i++) {\n System.out.println(last + \" \" + nums.get(i));\n left = nums.get(i) + 1;\n }\n \n System.out.println(last + \" \" + n);\n }\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "048b3045aa37bb6fcda4f0d8ffb862b8", "src_uid": "3a9258070ff179daf33a4515def9897a", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.BufferedReader; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \n\npublic class Cat {\n \n public static void main(String[] args) throws IOException {\n \n try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {\n \n String[] input = in.readLine().split(' ');\n \n int n = Integer.parseInt(input[0]);\n int m = Integer.parseInt(input[1]);\n \n if(m == 0) {\n System.out.println(1);\n } else if(n/2 >= m) {\n System.out.println(m);\n } else {\n System.out.println(n-m);\n \n }\n \n \n }\n \n \n \n }\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c5a828030787e84a9e34a46c751e6aaa", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.io.BufferedReader; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \n\npublic class Cat {\n \n public static void main(String[] args) throws IOException {\n \n try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {\n \n String input = in.readLine().split();\n \n int n = Integer.parseInt(input[0]);\n int m = Integer.parseInt(input[1]);\n \n if(m == 0) {\n System.out.println(1);\n } else if(n/2 >= m) {\n System.out.println(m);\n } else {\n System.out.println(n-m);\n \n }\n \n \n }\n \n \n \n }\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5e72d9a42908ec91606c02c759fed724", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class EatingSoup {\n\n\tvoid findGroups(int available, int left) {\n\t\tif (available <= left) {\n\t\t\tSystem.out.println(0);\n\t\t} else if (left == 0) {\n\t\t\tSystem.out.println(1);\n\t\t} else {\n\t\t\tavailable--;\n\t\t\tleft--;\n\t\t\tif ((left*2) == available) {\n\t\t\t\tSystem.out.println(left);\n\t\t\t} else {\n\t\t\t\tif ((left*2) < available) {\n\t\t\t\t\tSystem.out.println(left+1);\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.println(available-left);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString str[] = br.readLine().split(\" \");\n\t\tEatingSoup obj = new EatingSoup();\n\t\tobj.findGroups(Integer.parseInt(str[0]), Integer.parseInt(str[1]));\n\t\t\n\t\t\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4ef51d1c01cb2ad896516161a074b35f", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class X {\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner in=new FastScanner();\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t//\tint t=in.nextInt();\n\t//\twhile(t-->0)\n\t\tsolve(in,out);\n\t\tout.close();\n\t}\n\n static void solve(FastScanner in,PrintWriter out){\n int n=in.nextInt();\n int m=in.nextInt();\n int ans=Math.min(m,n-m);\n if(n!=m) ans=Math.max(ans,1)\n out.println(ans);\n } \n \n \n \n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i= amountOfStuffingOfM * doughNeeded[i] && stuffingAvailable[i] >= amountOfStuffingOfM * stuffingNeeded[i];\n amountOfStuffingOfM++) {\n\n max = Math.max(max, amountOfStuffingOfM * cost[i] + dp(doughAvail - amountOfStuffingOfM * doughNeeded[i], i + 1));\n }\n\n\n return memo[doughAvail][i] = max;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void print(int i) {\n writer.print(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "60d57d85c6d7386bcdbef62af1c34392", "src_uid": "4e166b8b44427b1227e0f811161d3a6f", "difficulty": 1700} {"lang": "Java 8", "source_code": "// https://codeforces.com/contest/106/problem/C\n\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws {\n // read input\n Scanner sc = new Scanner(System.in);\n\n int totalDough = sc.nextInt();\n int totalBuns = sc.nextInt();\n int doughPerPlainBun = sc.nextInt();\n int pricePerPlainBun = sc.nextInt();\n\n int[] totalStuffing = new int[totalBuns];\n int[] stuffingCost = new int[totalBuns];\n int[] doughCost = new int[totalBuns];\n int[] prices = new int[totalBuns];\n\n for (int i = 0; i < totalBuns; i++) {\n totalStuffing[i] = sc.nextInt();\n stuffingCost[i] = sc.nextInt();\n doughCost[i] = sc.nextInt();\n prices[i] = sc.nextInt();\n }\n\n // dp[i][j] will store the max amount we can make if we have access to up to i dough and up to the jth type of bun\n\n int[][] dp = new int[totalDough+1][totalBuns+1];\n\n // for i = 0, we leave this row as 0s, because we can't make any buns with 0 dough\n // for j = 0, this means we can only make plain buns, so the max amount we can make is determined by the number of plain buns we can make\n for (int i = 1; i <= totalDough; i++) {\n dp[i][0] = pricePerPlainBun * i/doughPerPlainBun;\n }\n\n // for each remaining cell, we have to try each possible number of the jth bun we can create. for example, if the jth bun requires 3 stuffing and we have 10 of that stuffing, we have to try making 0, 1, 2, and 3 of that bun. for each of those tries, we see how much making money that number of buns yields, plus how much money we can make from the leftover dough (by looking at previous cells)\n\n for (int i = 2; i <= totalDough; i++) {\n for (int j = 1; j <= totalBuns; j++) {\n int maxBuns = totalStuffing[j-1]/stuffingCost[j-1];\n\n for (int k = 0; k <= maxBuns; k++) {\n int totalPriceFromSpecialtyBun = k*prices[j-1];\n int doughCostFromSpecialtyBun = k*doughCost[j-1];\n if (doughCostFromSpecialtyBun <= i) {\n int remainingDough = i - doughCostFromSpecialtyBun;\n int totalPrice = totalPriceFromSpecialtyBun + dp[remainingDough][j-1];\n dp[i][j] = Math.max(dp[i][j], totalPrice);\n }\n }\n }\n }\n\n // for (int[] row : dp) {\n // for (int num : row) {\n // System.out.print(num + \" \");\n // }\n // System.out.println();\n // }\n \n // write output\n System.out.println(dp[totalDough][totalBuns]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b78067a59cd501f9caa94220fa5ab6dc", "src_uid": "4e166b8b44427b1227e0f811161d3a6f", "difficulty": 1700} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n//\u6b64\u9898\u5c31\u662f\u4e00\u4e2a\u80cc\u5305\uff0c\u7531\u4e8e\u8fd9\u4e2aEach of such buns requires c0 \n//grams of dough and it can be sold for d0 tugriks\n//\u6761\u4ef6\u6bd4\u8f83\u7b80\u5355\uff0c\u6240\u4ee5\u5148\u5904\u7406\u4e00\u4e0bdp[]\n\n\npublic class Main {\n \n static int n, m, c0, d0, a, b, c, d, ans;\n static int dp[] = new int[1010];\n \n static void DP() {\n Scanner cin = new Scanner(System.in);\n n = cin.nextInt(); m = cin.nextInt();\n c0 = cin.nextInt(); d0 = cin.nextInt();\n \n //\u9884\u5904\u7406\u4e00\u4e0bdp[]\n for (int i = c0; i <= n; i += c0)\n dp[i] = dp[i-c0] + d0;\n \n for (int cas = 0; cas < m; cas++) {\n a = cin.nextInt(); b = cin.nextInt();\n c = cin.nextInt(); d = cin.nextInt();\n a = a / b;\n //\u505a\u4e00\u6b21\u80cc\u5305\n for (int i = n; i >= 0; i--)\n for (int j = 1; j <= a && i >= c * j; j++)\n dp[i] = Math.max(dp[i], dp[i-c*j] + d * j);\n }\n \n ans = 0;\n for (int i = 0; i <= n; i++)\n ans = Math.max(ans, dp[i]);\n System.out.println(ans);\n }\n \n public static void main(String args[]) {\n DP();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc5cb36abf19570d258cf39cd963f07d", "src_uid": "4e166b8b44427b1227e0f811161d3a6f", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.util.*;\nimport java.util.stream.IntStream;\n\npublic class Main{\n\tpublic static void main(String[] args){\n\t\tScanner scanner = new Scanner(System.in);\n\t\tfinal int c0, d0;\n\t\tint n, m, a, b, c, d, array[] = new int[1005];\n\t\tn = scanner.nextInt();\n\t\tm = scanner.nextInt();\n\t\t\n\t\tc0 = scanner.nextInt();\n\t\td0 = scanner.nextInt();\n\t\tIntStream.rangeClosed(c0, n).forEach(i -> array[i] = array[i-c0] + d0);\n\t\tIntStream.range(0, m).forEach(i -> {\n\t\t a = scanner.nextInt();\n\t\t b = scanner.nextInt();\n\t\t c = scanner.nextInt();\n\t\t d = scanner.nextInt();\n\t\t for(int j = 0; j < a / b; j++)\n\t\t for(int k = n; k >= c; k--)\n\t\t array[k] = Math.max(array[k], array[k-c] + d);\n\t\t});\n\t\tSystem.out.println(array[n]);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7b57146266aaee8ad39f49e57e974944", "src_uid": "4e166b8b44427b1227e0f811161d3a6f", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E988 {\n\t\nprivate static int min;\n//\tpublic static void main(String[] args) {\n//\t\t// TODO Auto-generated method stub\n//\t\tScanner sc = new Scanner(System.in);\n//\t\twhile (sc.hasNext()) {\n//\t\t\tString str = sc.next();\n//\t\t\tStringBuffer s = new StringBuffer(str);\n//\t\t\tstr = s.reverse().toString();\n//\t\t\tint min = Integer.MAX_VALUE;\n//\t\t\tint a = str.indexOf(\"0\");\n//\t\t\tif (a != -1) {\n//\t\t\t\tString v = str.substring(a+1);\n//\t\t\t\tint a1 = v.indexOf(\"0\");\n//\t\t\t\tif (a1 != -1) {\n//\t\t\t\t\tmin = Math.min(min, a+a+a1);\n//\t\t\t\t}\n//\t\t\t\tint a2 = v.indexOf(\"5\");\n//\t\t\t\tif (a2 != -1) {\n//\t\t\t\t\tmin = Math.min(min, a+a+a2);\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tint b = str.indexOf(\"2\");\n//\t\t\tif (b != -1) {\n//\t\t\t\tint b1 = str.substring(b+1).indexOf(\"5\");\n//\t\t\t\tif (b1 != -1) {\n//\t\t\t\t\tif (b+b1+1 == str.length()-1 && str.charAt(b+b1) == '0') {\n//\t\t\t\t\t\tmin = Math.min(min, f(b, b1, str));\n//\t\t\t\t\t}else {\n//\t\t\t\t\t\tmin = Math.min(min, b+b+b1+1);\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\t\n//\t\t\tint c = str.indexOf(\"5\");\n//\t\t\tif (c != -1) {\n//\t\t\t\tString v = str.substring(c+1);\n//\t\t\t\tint c1 = v.indexOf(\"0\");\n//\t\t\t\tif (c1 != -1) {\n//\t\t\t\t\tmin = Math.min(min, c+c+c1+1);\n//\t\t\t\t}\n//\t\t\t\tint c2 = v.indexOf(\"2\");\n//\t\t\t\tif (c2 != -1) {\n//\t\t\t\t\tif (c+c2+1 == str.length()-1 && str.charAt(c+c2) == '0') {\n//\t\t\t\t\t\tmin = Math.min(min, f(c, c2, str));\n//\t\t\t\t\t}else {\n//\t\t\t\t\t\tmin = Math.min(min, c+c+c2);\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t\tint c3 = v.indexOf(\"7\");\n//\t\t\t\tif (c3 != -1) {\n//\t\t\t\t\tif (c+c3+1 == str.length()-1 && str.charAt(c+c3) == '0') {\n//\t\t\t\t\t\tmin = Math.min(min, f(c, c3, str));\n//\t\t\t\t\t}else {\n//\t\t\t\t\t\tmin = Math.min(min, c+c+c3);\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tint d = str.indexOf(\"7\");\n//\t\t\tif (d != -1) {\n//\t\t\t\tint d1 = str.substring(d+1).indexOf(\"5\");\n//\t\t\t\tif (d1 != -1) {\n//\t\t\t\t\tif (d+d1+1 == str.length()-1 && str.charAt(d+d1) == '0') {\n//\t\t\t\t\t\tmin = Math.min(min, f(d, d1, str));\n//\t\t\t\t\t}else {\n//\t\t\t\t\t\tmin = Math.min(min, d+d+d1+1);\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tSystem.out.println(min == Integer.MAX_VALUE ? -1:min);\n//\t\t}\n//\t}\n//\n//\tprivate static int f(int b, int b1, String str) {\n//\t\t// TODO Auto-generated method stub\n//\t\tint index = b1;\n//\t\tint k = 1;\n//\t\twhile (str.charAt(index) == '0') {\n//\t\t\tk ++;\n//\t\t\tindex --;\n//\t\t}\n//\t\tif (k == str.length() - 1) {\n//\t\t\treturn Integer.MAX_VALUE;\n//\t\t}\n//\t\treturn b+b+b1+k;\n//\t}\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile (sc.hasNext()) {\n\t\t\tString str = sc.next();\n\t\t\tchar [] arr = new char [str.length()];\n\t\t\tint [] flag = new int [10];\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t\tarr[i] = str.charAt(i);\n\t\t\t\tflag[arr[i]-'0'] ++;\n\t\t\t}\n\t\t\tmin = Integer.MAX_VALUE;\n\t\t\tif (arr[0] > 2 || (arr[0] > 0 && arr[5] > 0) || (arr[5] > 0 && arr[2] > 0) || (arr[7] > 0 && arr[5] > 0)) {\n\t\t\t\tf(arr, 0, 0);\n\t\t\t}\n\t\t\tSystem.out.println(min == Integer.MAX_VALUE ? -1:min);\n\t\t}\n\t}\n\tprivate static void f(char[] a, int k, int num) {\n\t\t// TODO Auto-generated method stub\n\t\tif (k == a.length-1) {\n\t\t\tif (a[0] != '0') {\n\t\t\t\tlong b = Long.valueOf(new String(a));\n\t\t\t\tif (b % 25 == 0) {\n\t\t\t\t\tmin = Math.min(min, num);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ;\n\t\t}\n\t\tfor (int i = k; i < a.length; i++) {\n\t\t\tchar tmp = a[i];\n\t\t\tint r = 0;\n\t\t\tfor (int j = i-1; j >= k; j--) {\n\t\t\t\ta[j+1] = a[j];\n\t\t\t\tr++;\n\t\t\t}\n\t\t\ta[k] = tmp;\n\t\t\tf(a, k+1, num+r);\n\t\t\ttmp = a[k];\n\t\t\tfor (int j = k; j <= i-1; j++) {\n\t\t\t\ta[j] = a[j+1];\n\t\t\t}\n\t\t\ta[i] = tmp;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "afd31f6bbd074af597c38181c12c7aae", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.io.*;\n import java.util.*;\n import java.math.*;\n \n public class bhaa {\n \n InputStream is;\n PrintWriter o;\n /////////////////// CODED++ BY++ ++ ++ ++ BHAVYA++ ARORA++ ++ ++ ++ FROM++ JAYPEE++ INSTITUTE++ OF++ INFORMATION++ TECHNOLOGY++ ////////////////\n \n ///////////////////////// Make it work, make it right, make it fast. Make it work, make it right, make it fast. Make it work, make it right, make it fast. Make it work, make it right, make it fast. /////////////////\n \n \n \n void solve() {\n char s[]=ns().toCharArray();\n int n=s.length;\n int min=Integer.MAX_VALUE;\n int f=0;\n for(int i=0;ii)\n {\n j--;\n\n }\n for(int k=j;k0;k--)\n {\n \n char te=t[k];\n t[k]=t[k-1];\n t[k-1]=te;\n c++;\n \n \n }\n String st=new String(t);\n long nu=Long.parseLong(st);\n if(nu%25==0)\n {\n f=1;\n min=Math.min(min,c);\n }\n \n \n \n \n }\n \n }\n \n \n \n if(f==0)\n {\n o.println(-1);\n }\n else\n {\n o.println(min);\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "968e6d29e061608f8a02438cf17fc01c", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100} {"lang": "Java 8", "source_code": "\nimport com.sun.deploy.util.SystemUtils;\n\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.TreeSet;\n\n\npublic class Main {\n public static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n public static int[] deg2;\n public static int[] points;\n\n public static long read() throws IOException {\n tokenizer.nextToken();\n return (long) tokenizer.nval;\n }\n\n\n public static void main(String[] args) throws IOException {\n long n=read();\n int l=Long.toString(n).length();\n int[] digits=new int[l];\n String s=Long.toString(n);\n for (int i=0; imax2){\n result2=(2*l-3)-max2-max5;\n } else {\n result2=(2*l-3)-max2-max5+1;\n }\n }\n if (max5!=-1 && max0!=-1){\n if (max0>max5){\n result3=(2*l-3)-max0-max5;\n } else {\n result3=(2*l-3)-max0-max5+1;\n }\n }\n if (max5!=-1 && max7!=-1){\n if (max5>max7){\n result4=(2*l-3)-max7-max5;\n } else {\n result4=(2*l-3)-max7-max5+1;\n }\n }\n int result=Math.min(Math.min(result1,result2),Math.min(result3,result4));\n if (result==1000) System.out.println(-1); else System.out.println(result);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d959981a4bebe747744eb3f4b1a96802", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class TaskE\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tnew TaskE(System.in, System.out);\n\t}\n\n\tstatic class Solver implements Runnable\n\t{\n\t\tstatic final int INFINITY = (int) 1e9;\n\t\tlong n;\n\t\tchar[] s;\n//\t\tBufferedReader in;\n\t\tInputReader in;\n\t\tPrintWriter out;\n\n\t\tvoid solve() throws IOException\n\t\t{\n\t\t\tn = in.nextLong();\n\t\t\ts = (\"\" + n).toCharArray();\n\n\t\t\tif (s.length < 2)\n\t\t\t{\n\t\t\t\tout.println(-1);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint a = find(\"00\".toCharArray());\n\t\t\tint b = find(\"25\".toCharArray());\n\t\t\tint c = find(\"50\".toCharArray());\n\t\t\tint d = find(\"75\".toCharArray());\n\t\t\tint min = CMath.min(a, b, c, d);\n\n\t\t\tif (min == INFINITY)\n\t\t\t\tout.println(-1);\n\t\t\telse\n\t\t\t\tout.println(min);\n\t\t}\n\n\t\tint find(char[] dig)\n\t\t{\n\t\t\tint len = s.length;\n\t\t\tchar[] ss = new char[len];\n\t\t\tint pos = -1;\n\n\t\t\tSystem.arraycopy(s, 0, ss, 0, s.length);\n\n\t\t\tfor (int i = len - 1; i >= 0; i--)\n\t\t\t{\n\t\t\t\tif (ss[i] == dig[1])\n\t\t\t\t{\n\t\t\t\t\tpos = i;\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n//\t\t\tSystem.out.println(\"dig : \" + Arrays.toString(dig) + \", pos : \" + pos);\n\t\t\tif (pos == -1)\n\t\t\t\treturn INFINITY;\n\n\t\t\tint swaps = 0;\n\t\t\tint ones = pos;\n\t\t\tboolean addExtra = false;\n\n\t\t\tfor (int i = pos; i < len - 1; i++)\n\t\t\t{\n\t\t\t\tchar temp = ss[i];\n\n\t\t\t\tss[i] = ss[i + 1];\n\t\t\t\tss[i + 1] = temp;\n\t\t\t\tswaps++;\n\n\t\t\t\tif (ss[0] == '0')\n\t\t\t\t\taddExtra = true;\n//\t\t\t\tSystem.out.println(\"\\tss : \" + Arrays.toString(ss));\n\t\t\t}\n\n//\t\t\tSystem.out.println(\"changed first\");\n\n\t\t\tpos = -1;\n\n\t\t\tfor (int i = len - 2; i >= 0; i--)\n\t\t\t{\n\t\t\t\tif (ss[i] == dig[0])\n\t\t\t\t{\n\t\t\t\t\tpos = i;\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (pos == -1)\n\t\t\t\treturn INFINITY;\n\n\t\t\tint tens = pos;\n\n\t\t\tfor (int i = pos; i < len - 2; i++)\n\t\t\t{\n\t\t\t\tchar temp = ss[i];\n\n\t\t\t\tss[i] = ss[i + 1];\n\t\t\t\tss[i + 1] = temp;\n\t\t\t\tswaps++;\n\n\t\t\t\tif (ss[0] == '0')\n\t\t\t\t\taddExtra = true;\n//\t\t\t\tSystem.out.println(\"\\tss : \" + Arrays.toString(ss));\n\t\t\t}\n\n//\t\t\tSystem.out.println(\"******ss : \" + Arrays.toString(ss) + \", swaps : \" + swaps);\n\n\t\t\tif (ss[0] == '0')\n\t\t\t{\n\t\t\t\tpos = -1;\n\n\t\t\t\tfor (int i = 0; i < len - 2; i++)\n\t\t\t\t{\n\t\t\t\t\tif (ss[i] != '0')\n\t\t\t\t\t{\n\t\t\t\t\t\tpos = i;\n\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (pos == -1)\n\t\t\t\t\treturn INFINITY;\n\n\t\t\t\tfor (int i = 0; i < pos - 1; i++)\n\t\t\t\t{\n\t\t\t\t\tchar temp = ss[i];\n\n\t\t\t\t\tss[i] = ss[i + 1];\n\t\t\t\t\tss[i + 1] = temp;\n\t\t\t\t\tswaps++;\n\n\t\t\t\t\tif (ss[0] == '0')\n\t\t\t\t\t\taddExtra = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (addExtra)\n\t\t\t{\n\t\t\t\tint other = -1;\n\n\t\t\t\tfor (int i = 0; i < len; i++)\n\t\t\t\t{\n\t\t\t\t\tif (i == ones || i == tens)\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tif (s[i] != '0')\n\t\t\t\t\t{\n\t\t\t\t\t\tother = i;\n\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (other == -1)\n\t\t\t\t\treturn INFINITY;\n\n\t\t\t\tfor (int i = 0; i < other - 1; i++)\n\t\t\t\t{\n\t\t\t\t\tchar temp = ss[i];\n\n\t\t\t\t\tss[i] = ss[i + 1];\n\t\t\t\t\tss[i + 1] = temp;\n\t\t\t\t\tswaps++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ss[0] == '0')\n\t\t\t\treturn INFINITY;\n\n\t\t\treturn swaps;\n\t\t}\n\n\t\tvoid debug(Object... o)\n\t\t{\n\t\t\tSystem.err.println(Arrays.deepToString(o));\n\t\t}\n\n//\t\tuncomment below line to change to BufferedReader\n//\t\tpublic Solver(BufferedReader in, PrintWriter out)\n\t\tpublic Solver(InputReader in, PrintWriter out)\n\t\t{\n\t\t\tthis.in = in;\n\t\t\tthis.out = out;\n\t\t}\n\n\t\t@Override\n\t\tpublic void run()\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tsolve();\n\t\t\t}\n\t\t\tcatch (IOException e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t}\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\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\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\treturn buf[curChar++];\n\t\t}\n\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\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\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\n\t\t\t\tres *= 10;\n\t\t\t\tres += c & 15;\n\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int arraySize)\n\t\t{\n\t\t\tint array[] = new int[arraySize];\n\n\t\t\tfor (int i = 0; i < arraySize; i++)\n\t\t\t\tarray[i] = nextInt();\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic long nextLong()\n\t\t{\n\t\t\tint c = read();\n\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\n\t\t\tint sign = 1;\n\n\t\t\tif (c == '-')\n\t\t\t{\n\t\t\t\tsign = -1;\n\n\t\t\t\tc = read();\n\t\t\t}\n\n\t\t\tlong result = 0;\n\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\n\t\t\t\tresult *= 10;\n\t\t\t\tresult += c & 15;\n\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\n\t\t\treturn result * sign;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int arraySize)\n\t\t{\n\t\t\tlong array[] = new long[arraySize];\n\n\t\t\tfor (int i = 0; i < arraySize; i++)\n\t\t\t\tarray[i] = nextLong();\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic float nextFloat()\n\t\t{\n\t\t\tfloat result, div;\n\t\t\tbyte c;\n\n\t\t\tresult = 0;\n\t\t\tdiv = 1;\n\t\t\tc = (byte) read();\n\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = (byte) read();\n\n\t\t\tboolean isNegative = (c == '-');\n\n\t\t\tif (isNegative)\n\t\t\t\tc = (byte) read();\n\n\t\t\tdo\n\t\t\t{\n\t\t\t\tresult = result * 10 + c - '0';\n\t\t\t} while ((c = (byte) read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = (byte) read()) >= '0' && c <= '9')\n\t\t\t\t\tresult += (c - '0') / (div *= 10);\n\n\t\t\tif (isNegative)\n\t\t\t\treturn -result;\n\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic double nextDouble()\n\t\t{\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = (byte) read();\n\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = (byte) read();\n\n\t\t\tboolean neg = (c == '-');\n\n\t\t\tif (neg)\n\t\t\t\tc = (byte) read();\n\n\t\t\tdo\n\t\t\t{\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = (byte) read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = (byte) read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic String next()\n\t\t{\n\t\t\tint c = read();\n\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\n\t\t\tStringBuilder res = new StringBuilder();\n\n\t\t\tdo\n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine()\n\t\t{\n\t\t\tint c = read();\n\n\t\t\tStringBuilder result = new StringBuilder();\n\n\t\t\tdo\n\t\t\t{\n\t\t\t\tresult.appendCodePoint(c);\n\n\t\t\t\tc = read();\n\t\t\t} while (!isNewLine(c));\n\n\t\t\treturn result.toString();\n\t\t}\n\n\t\tpublic boolean isNewLine(int c)\n\t\t{\n\t\t\treturn c == '\\n';\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c)\n\t\t{\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic void close()\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tstream.close();\n\t\t\t}\n\t\t\tcatch (IOException e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t}\n\n\tstatic class CMath\n\t{\n\t\tstatic long power(long number, long power)\n\t\t{\n\t\t\tif (number == 1 || number == 0 || power == 0)\n\t\t\t\treturn 1;\n\n\t\t\tif (power == 1)\n\t\t\t\treturn number;\n\n\t\t\tif (power % 2 == 0)\n\t\t\t\treturn power(number * number, power / 2);\n\t\t\telse\n\t\t\t\treturn power(number * number, power / 2) * number;\n\t\t}\n\n\t\tstatic long modPower(long number, long power, long mod)\n\t\t{\n\t\t\tif (number == 1 || number == 0 || power == 0)\n\t\t\t\treturn 1;\n\n\t\t\tnumber = mod(number, mod);\n\n\t\t\tif (power == 1)\n\t\t\t\treturn number;\n\n\t\t\tlong square = mod(number * number, mod);\n\n\t\t\tif (power % 2 == 0)\n\t\t\t\treturn modPower(square, power / 2, mod);\n\t\t\telse\n\t\t\t\treturn mod(modPower(square, power / 2, mod) * number, mod);\n\t\t}\n\n\t\tstatic long moduloInverse(long number, long mod)\n\t\t{\n\t\t\treturn modPower(number, mod - 2, mod);\n\t\t}\n\n\t\tstatic long mod(long number, long mod)\n\t\t{\n\t\t\treturn number - (number / mod) * mod;\n\t\t}\n\n\t\tstatic int gcd(int a, int b)\n\t\t{\n\t\t\tif (b == 0)\n\t\t\t\treturn a;\n\t\t\telse\n\t\t\t\treturn gcd(b, a % b);\n\t\t}\n\n\t\tstatic long min(long... arr)\n\t\t{\n\t\t\tlong min = arr[0];\n\n\t\t\tfor (int i = 1; i < arr.length; i++)\n\t\t\t\tmin = Math.min(min, arr[i]);\n\n\t\t\treturn min;\n\t\t}\n\n\t\tstatic long max(long... arr)\n\t\t{\n\t\t\tlong max = arr[0];\n\n\t\t\tfor (int i = 1; i < arr.length; i++)\n\t\t\t\tmax = Math.max(max, arr[i]);\n\n\t\t\treturn max;\n\t\t}\n\n\t\tstatic int min(int... arr)\n\t\t{\n\t\t\tint min = arr[0];\n\n\t\t\tfor (int i = 1; i < arr.length; i++)\n\t\t\t\tmin = Math.min(min, arr[i]);\n\n\t\t\treturn min;\n\t\t}\n\n\t\tstatic int max(int... arr)\n\t\t{\n\t\t\tint max = arr[0];\n\n\t\t\tfor (int i = 1; i < arr.length; i++)\n\t\t\t\tmax = Math.max(max, arr[i]);\n\n\t\t\treturn max;\n\t\t}\n\n\t}\n\n\tstatic class Utils\n\t{\n\t\tstatic boolean nextPermutation(int[] arr)\n\t\t{\n\t\t\tfor (int a = arr.length - 2; a >= 0; --a)\n\t\t\t{\n\t\t\t\tif (arr[a] < arr[a + 1])\n\t\t\t\t{\n\t\t\t\t\tfor (int b = arr.length - 1; ; --b)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (arr[b] > arr[a])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint t = arr[a];\n\n\t\t\t\t\t\t\tarr[a] = arr[b];\n\t\t\t\t\t\t\tarr[b] = t;\n\n\t\t\t\t\t\t\tfor (++a, b = arr.length - 1; a < b; ++a, --b)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tt = arr[a];\n\t\t\t\t\t\t\t\tarr[a] = arr[b];\n\t\t\t\t\t\t\t\tarr[b] = t;\n\t\t\t\t\t\t\t}\n\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\n\t\t\treturn false;\n\t\t}\n\n\t}\n\n\tpublic TaskE(InputStream inputStream, OutputStream outputStream)\n\t{\n//\t\tuncomment below line to change to BufferedReader\n//\t\tBufferedReader in = new BufferedReader(new InputStreamReader(inputStream));\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tThread thread = new Thread(null, new Solver(in, out), \"TaskE\", 1 << 29);\n\n\t\ttry\n\t\t{\n\t\t\tthread.start();\n\t\t\tthread.join();\n\t\t}\n\t\tcatch (InterruptedException e)\n\t\t{\n\t\t\te.printStackTrace();\n\t\t}\n\t\tfinally\n\t\t{\n\t\t\tin.close();\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "815f67ea5756d2beade515256e879494", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100} {"lang": "Java 11", "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 input = in.nextLine();\n String alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n \n in aPos = 1;\n char aChar = \"a\".charAt(0); \n int distance = 0;\n for(int i=0; i < input.length(); i++){\n int pos = alphabet.indexOf(input.charAt(i))+1;\n \n if(aChar <= input.charAt(i)){\n //d2 = 26 - b + a\n distance = 26 - input.charAt(i) + aChar;\n }\n else{\n distance = 26 - aChar + input.charAt(i) ;\n }\n }\n System.out.println(distance);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f885c063e6f8d9d969c483b8e013a9a", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800} {"lang": "Java 8", "source_code": "public class PoblemA {\n\n\tpublic static char[] umdrehen(char[] e){\n\t\tchar[] ausgabe = new char[e.length];\n\t\tint k = 0;\n\t\tfor(int i = e.length-1 ; i >= 0; i--){\n\t\t\tausgabe[k] = e[i];\n\t\t\tk++;\n\t\t}\n\t\t\t\n\t\treturn ausgabe;\n\t}\n\t\n\tpublic static char[] renew(char[] e, char a){\n\t\tchar[] ausgabe = new char[e.length];\n\t\tint index_newArray = 0;\n\t\tfor(int i = 0; i < e.length; i++){\n\t\t\tif(e[i] == a){\n\t\t\t\tindex_newArray = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i< e.length;i++){\n\t\t\tausgabe[i] = e[index_newArray];\n\t\t\tif(index_newArray == e.length-1){\n\t\t\t\tindex_newArray = 0;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tindex_newArray++;\n\t\t}\n\t\treturn ausgabe;\n\t}\n\t\n\tpublic static void ausgebenarray(char[] e){\n\t\tfor(int i = 0; i < e.length; i++){\n\t\t\tSystem.out.print(e[i]);\n\t\t}\n\t\tSystem.out.println();\n\t}\n\t\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tString eingabe = scan.nextLine();\n\t\tchar[] wheel = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};\n\t\tint anz1 = 0, anz2 = 0, totalanz = 0;\n\t\t\n\t\tscan.close();\n\t\tfor(int i = 0; i < eingabe.length(); i++){\n\t\t\tfor(int k = 0; k < wheel.length;k++){\n\t\t\t\tif(wheel[k] == eingabe.charAt(i)){\n\t\t\t\t\tk = wheel.length;\n\t\t\t\t}\n\t\t\t\tanz1++;\n\t\t\t}\n\t\t\twheel = umdrehen(wheel);\n\t\t\tfor(int k = 0; k < wheel.length;k++){\n\t\t\t\tif(wheel[k] == eingabe.charAt(i)){\n\t\t\t\t\tk = wheel.length;\n\t\t\t\t}\n\t\t\t\tanz2++;\n\t\t\t}\n\t\t\twheel = umdrehen(wheel);\n\t\t\t\n\t\t\tif(anz1 < anz2){\n\t\t\t\ttotalanz += anz1;\n\t\t\t}else{\n\t\t\t\ttotalanz += anz2;\n\t\t\t}\n\t\t\tanz1 = 0; \n\t\t\tanz2 = 0;\n\t\t\twheel = renew(wheel, eingabe.charAt(i));\n\t\t}\n\t\t\n\t\tSystem.out.print(Integer.toString(totalanz-1));\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab0548501f8ae5c9b6543a44f89a1051", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class JavaApplication11 {\n public static int f(int x)\n {\n if (x<0)\n return (-1)*x;\n return x;\n }\n\n public static void main(String[] args) {\n int max=26;\n Scanner sc=new Scanner(System.in);\n String a=sc.next();\n int b[]=new int[a.length()];\n for (int i=0;i q){\n sum_q -= q * (n / (a * b));\n }else{\n sum_p -= p * (n / (a * b));\n }\n System.out.println(sum_q + sum_p);\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "55f00039b6ce9997887477d16874c2d5", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution\n{\n public static int gcd(int a,int b)\n {\n if(b==0)\n return a;\n else\n return gcd(b,a%b);\n }\n \n public static void main(String args[])\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out=new PrintWriter(System.out);\n \n String s[]=br.readLine().split(\" \");\n int n=Integer.parseInt(s[0]);\n int a=Integer.parseInt(s[1]);\n int b=Integer.parseInt(s[2]);\n int p=Integer.parseInt(s[3]);\n int q=Integer.parseInt(s[4]);\n\n long ans=0;\n \n ans+=(long)n/a;\n ans+=(long)n/b;\n \n long lcm=a*b/gcd(a,b);\n ans-=(long)n/lcm;\n \n out.println(ans);\n out.close();\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "74e6bcaf42f127961958231e97bf16f2", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int a = sc.nextInt();\n int b = sc.nextInt();\n int p = sc.nextInt();\n int q = sc.nextInt();\n\n int lcm = a > b?lcm(a, b):lcm(b:a);\n long common = n / lcm;\n long numAOnly = n / a - common;\n long numBOnly = n / b - common;\n int big = p > q ? p : q;\n long res = common * big + numAOnly * p + numBOnly * q;\n System.out.println(res);\n\n }\n \n private int lcm(int big, int small){\n return big * small / gcd(big, small);\n }\n \n private int gcd(int big, int small){\n return small==0? big : gcd(small, big%small);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2e8c24dd0fe1fc52d10089c7265cc95a", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600} {"lang": "Java 8", "source_code": "\npublic class Main {\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scanner = new Scanner(System.in);\n\t\tlong n = scanner.nextInt();\n\t\tlong a = scanner.nextInt();\n\t\tlong b = scanner.nextInt();\n\t\tlong p = scanner.nextInt();\n\t\tlong q = scanner.nextInt();\n\t\t\n\t\tlong bigGet;\n\t\tlong smallGet;\n\t\tlong bigGetDivid;\n\t\tlong smallGetDivid;\n\t\tif (p > q){\n\t\t\tbigGet = p;\n\t\t\tbigGetDivid = a;\n\t\t\tsmallGet = q;\n\t\t\tsmallGetDivid = b;\n\t\t}else{\n\t\t\tbigGet = q;\n\t\t\tbigGetDivid = b;\n\t\t\tsmallGet = p;\n\t\t\tsmallGetDivid = a;\n\t\t}\n\t\t\n\t\tlong result = n/bigGetDivid*bigGet + n/smallGetDivid*smallGet - n/( LCM(Math.max(a, b), Math.min(a, b)))*smallGet;\n\t\tSystem.out.println(result);\n\t}\n\t\n\tpublic static long LCM (long a, long b){\n\t\tlong gcd = GCD(a, b);\n\t\treturn (a/gcd)*(b/gcd)*gcd;\n\t}\n\t\n\tpublic static long GCD (long a, long b){\n\t\tif (a % b == 0){\n\t\t\treturn b;\n\t\t}else{\n\t\t\treturn GCD(b, a%b);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f4977b7256acf6c9e1fb79c959237255", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution \n{\n public static void main(String[] args) throws Exception\n {\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n String l=in.readLine();\n String[] str=l.trim().split(\"\\\\s+\");\n long n=Long.parseLong();\n long k=Long.parseLong();\n long t=Long.parseLong();\n if(t>=1 && t<=k)\n {\n System.out.println(t);\n }\n else if(t>=k+1 && t<=n)\n {\n System.out.println(k);\n }\n else if(t>=n+1 && t<=n+k)\n {\n System.out.println(k-t+n);\n }\n }\n}\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67c81d4060916c3a02020e92405095cb", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class ArpaAndAResearchInMexicaWave {\n public static void main(String[] args) {\n\n\tlong n;\n\tlong k;\n\tlong t;\n\tn = Long.parseLong(ConsoleInput.readToWhiteSpace(true));\n\tk = Long.parseLong(ConsoleInput.readToWhiteSpace(true));\n\tt = Long.parseLong(ConsoleInput.readToWhiteSpace(true));\n\tif (t < k)\n\t{\n\t\tSystem.out.print(t);\n\t\tSystem.out.print(\"\\n\");\n\t}\n\telse if ((k <= t) && (t <= n))\n\t{\n\t\tSystem.out.print(k);\n\t\tSystem.out.print(\"\\n\");\n\t}\n\telse\n\t{\n\t\tSystem.out.print(n - t + k);\n\t\tSystem.out.print(\"\\n\");\n\t}\n\treturn 0;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b9ab5f6ff41ac3bb4f9a49970daf9374", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800} {"lang": "Java 8", "source_code": "public class Arpa {\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 s=new Scanner(System.in);\n\t\tint n=s.nextInt();\n\t\tint k=s.nextInt();\n\t\tint t=s.nextInt();\n\t\tif(t<=k){\n\t\t\tSystem.out.println(t);\n\t\t}\n\t\telse if(t<=n)\n\t\t\tSystem.out.println(k);\n\t\telse if(t<=(n+k)){\n\t\t\tSystem.out.println(k-t+n);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(\"0\");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f60e5df3631b6296d4f9afd5aa4ab61b", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class Main {\n\n\tstatic Scanner sc = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\t\tint t = sc.nextInt();\n\t\twhile (t-- > 0) {\n\n\t\t\tsolve();\n\t\t}\n\t}\n\n\tpublic static void solve() { \n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n int t = sc.nextInt();\n\n if(t<=n)\n\t\tSystem.out.println(Math.min(t, k);\n\t\telse \n\t\tSystem.out.println(n-k);\n\n\t}\n\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "938372ca005646e38731e2222fbf8094", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800} {"lang": "Java 8", "source_code": "public class Main { \n private static final int Max=(int) (1e6+10); \n private static int n; \n private static String s; \n public static void main(String[] args) { \n InitData(); \n GetAns(); \n } \n \n private static void InitData() { \n Scanner cin=new Scanner(System.in); \n n=cin.nextInt(); \n cin.nextLine(); \n s=cin.nextLine(); \n }; \n private static void GetAns(){ \n String []split=s.split(\" \"); \n \n int ans=Integer.MIN_VALUE; \n for(int i=0;i='A'&&split[i].charAt(j)<='Z'){ \n cnt++; \n } \n } \n ans=Math.max(ans, cnt); \n// System.out.println(split[i]); \n } \n System.out.println(ans); \n } \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c23afe836c066270cd866f51152c500e", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.function.Function;\nimport java.util.function.ToDoubleFunction;\nimport java.util.function.ToIntFunction;\nimport java.util.function.ToLongFunction;\nimport java.io.*;\npublic class Main {\n \n\tstatic ArrayList adj[];\n\tstatic char color[];\n\tstatic boolean b[],visited[],possible;\n\tstatic Map> s;\n\tstatic int totalnodes,colored;\n\tstatic int count[];\n\tstatic long sum[];\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\t\n\t\tin=new InputReader(System.in);\n\t\tw=new PrintWriter(System.out);\n \n\t int n=in.nextInt();\n String s=in.nextLine();\n String[] st=s.split(\" \");\n int max=0;\n for(int i=0;i=65 && st[i].charAt(j)<=90)\n \t\t\t c++;\n \t }\n \t if(maxn)\n\t\t\t\t y=m1-1;\n\t\t\telse if(m2*m2*m2 a[mid + 1])\n\t\t\t return mid;\n\t\t\t if (mid > l && a[mid] < a[mid - 1])\n\t\t\t return (mid-1);\n\t\t\t if (a[l] >a[mid])\n\t\t\t return pivot_element(a, l, mid-1);\n\t\t\t return pivot_element(a, mid + 1, r);\n\t\t\n\t}\n\tpublic static int binary_search(int[] a,int l,int r,int k)\n\t{\n\t\tif(rk)\n\t\t\t return binary_search(a,l,mid-1,k);\n\t\telse\n\t\t\t return binary_search(a,mid+1,r,k); \n\t}\n\tpublic static String[] subString(String s, int n) \n\t{\n\t String[] st =new String[(n*n+n)/2];\n\t for(int i=0;istart)\tcount++;\n\t\t\t\tif(n/i > start)\tcount++;\n\t\t\t}\n\t\tif(i*i == n && i>start)\tcount++;\n\t\treturn count;\n\t}\n\n\n \tpublic static int isPrime(int n){\n\t int i;\n\n\t if (n==2)\n\t return 1;\n\n\t if (n%2==0)\n\t return 0;\n\n\t for (i=3;i<=Math.sqrt(n);i+=2)\n\t if (n%i==0)\n\t return 0;\n\n\t return 1;\n\t}\n\n\t\n\tstatic InputReader in;\n\tstatic PrintWriter w;\n\tpublic static void seive(long n){\n\t\tb = new boolean[(int) (n+1)];\n\tArrays.fill(b, true);\n\t\tfor(int i = 2;i*i<=n;i++){\n\t\t\tif(b[i]){\n\t\t\t\tsum[i]=count[i];\n\t\t\t//\tSystem.out.println(sum[i]+\" wf\");\n\t\t\t\tfor(int p = 2*i;p<=n;p+=i){\n\t\t\t\t\tb[p] = false;\n\t\t\t\t\tsum[i]+=count[p]; \n\t\t\t\t\t//System.out.println(sum[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\t}\n\t}\n\tstatic class Pair implements Comparable {\n\t\tint x;\n\t\tint y;\n\t\tint c;\n\t\t\n\t\tpublic Pair(){\n\t\t\t\n\t\t}\n\t\tpublic Pair(int x,int y,int c) {\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t\tthis.c=c;\n\t\t\t\n\t\t}\n\t\tpublic int compareTo(Pair other) {\n\t\t\t\n\t\t\t\treturn 0;\n\t\t}\n\t\t\n\t\t/*public String toString() {\n\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t}*/\n\t}\n\tstatic class Node2{\n\t\tNode2 left = null;\n\t\tNode2 right = null;\n\t\tNode2 parent = null;\n\t\tint data;\n\t}\n\t\n\t//binaryStree\n\tstatic class BinarySearchTree{\n\t\tNode2 root = null;\n\t\tint height = 0;\n\t\tint max = 0;\n\t\tint cnt = 1;\n\t\tArrayList parent = new ArrayList();\n\t\tHashMap hm = new HashMap();\n\t\tpublic void insert(int x){\n\t\t\tNode2 n = new Node2();\n\t\t\tn.data = x;\n\t\t\tif(root==null){\n\t\t\t\troot = n;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tNode2 temp = root,temp2 = null;\n\t\t\t\twhile(temp!=null){\n\t\t\t\t\ttemp2 = temp;\n\t\t\t\t\tif(x>temp.data) temp = temp.right;\n\t\t\t\t\telse temp = temp.left;\n\t\t\t\t}\n\t\t\t\tif(x>temp2.data) temp2.right = n;\n\t\t\t\telse temp2.left = n;\n\t\t\t\tn.parent = temp2;\n\t\t\t\tparent.add(temp2.data);\n\t\t\t}\n\t\t}\n\t\tpublic Node2 getSomething(int x, int y, Node2 n){\n\t\t\tif(n.data==x || n.data==y) return n;\n\t\t\telse if(n.data>x && n.datan.data){\n\t\t\t\tmax = Math.max(max, n.data);\n\t\t\t\treturn search(x,n.right);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tmax = Math.max(max, n.data);\n\t\t\t\treturn search(x,n.left);\n\t\t\t}\n\t\t}\n\t\tpublic int getHeight(Node2 n){\n\t\t\tif(n==null) return 0;\n\t\t\theight = 1+ Math.max(getHeight(n.left), getHeight(n.right));\n\t\t\treturn height;\n\t\t}\n\t}\npublic static void debug(Object... o) {\n\tSystem.out.println(Arrays.deepToString(o));\n}\n \npublic static String rev(String s)\n{\n\tStringBuilder sb=new StringBuilder(s);\n\tsb.reverse();\n\treturn sb.toString();\n}\n \nstatic long lcm(long a, long b)\n{\n return a * (b / gcd(a, b));\n}\n\n \npublic static long max(long x, long y, long z){\n\t\tif(x>=y && x>=z) return x;\n\t\tif(y>=x && y>=z) return y;\n\t\treturn z;\n\t}\n\tstatic int[] sieve(int n,int[] arr)\n\t{\n\tfor(int i=2;i*i<=n;i++)\n\t{\n\t\tif(arr[i]==0)\n\t\t{\n\t\t\tfor(int j=i*2;j<=n;j+=i)\n\t\t\t\tarr[j]=1;\n\t\t}\n\t}\n\treturn arr;\n\t}\n \n \n \n \nstatic class InputReader {\n \nprivate final InputStream stream;\nprivate final byte[] buf = new byte[8192];\nprivate int curChar, snumChars;\nprivate SpaceCharFilter filter;\n \npublic InputReader(InputStream stream) {\n this.stream = stream;\n}\n \npublic int snext() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n}\n \npublic int nextInt() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n}\n \npublic long nextLong() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n}\n \npublic int[] nextIntArray(int n) {\n\t return nextIntArray(n, 0);\n\t }\n\t \npublic int[] nextIntArray(int n, int off) {\n\t int[] arr = new int[n + off];\n\t for (int i = 0; i < n; i++) {\n\t arr[i + off] = nextInt();\n\t }\n\t return arr;\n\t }\n\t \npublic long[] nextLongArray(int n) {\nreturn nextLongArray(n, 0);\n\t }\n \n\tpublic long[] nextLongArray(int n, int off) {\n\t long[] arr = new long[n + off];\n\t for (int i = 0; i < n; i++) {\n\t\t arr[i + off] = nextLong();\n\t\t }\n return arr;\n\t}\n \n \npublic String readString() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n}\n \npublic String nextLine() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isEndOfLine(c));\n return res.toString();\n}\n \npublic 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 \nprivate boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n}\n \npublic interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n}\n}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4456d6c34d78032d1532369f98def5f8", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Works {\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n List counts = new ArrayList<>();\n int n = in.nextInt();\n int count = 0;\n int letters = 0;\n while (n >= 0){\n String s = in.next();\n letters=s.length() + 1;\n count = countVolume(s);\n counts.add(count);\n n-=letters;\n }\n if (counts.size() == 1) System.out.println(count);\n else System.out.println(max(counts));\n }\n\n private static int max(List counts) {\n int max = 0;\n for (int i = 0; i < counts.size()-1; i++) {\n if (counts.get(i) > max) max = counts.get(i);\n }\n return max;\n }\n\n private static int countVolume(String s) {\n int count = 0;\n for (int i = 0; i < s.length(); i++) {\n if (Character.isUpperCase(s.charAt(i))) count++;\n\n }\n return count;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "816c07c6081b5af66c2d4ca4e1b4ab09", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.uti.*;\npublic class Solution{\n public static void main(String args[])\n {\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n String s=in.nextLine();\n String[] m=s.split(\" \");\n for(int i=0;i=65 && (int)m[i].charAt(j)<=90 )\n r++;\n }\n if(r>m)\n m=r;\n }\n System.out.println(m);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9b47621ed920752ea2cee0e475192cef", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\npublic static void main(String ar[])\n{\nScanner s=new Scanner(System.in);\nint n=s.nextInt();\nStrinf str=s.nextLine();\nint n1=n/2,c=0;\nfor(int i=0;in1/2)\nSystem.out.println(\"YES\");\nelse\nSystem.out.println(\"NO\");\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6a175d8e596d0e499cc9503a729ea507", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class offices {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int length = sc.nextInt();\n String waste = sc.nextLine();\n String cities = sc.nextLine();\n int countFS = 0, countSF = 0;\n for (int i = 0; i < length; i++){\n if (charAt(i) == 'S'){\n if (charAt(i+1) == 'F'){\n countSF++;\n }\n } else {\n if (charAt(i+1) == 'S'){\n countFS++;\n }\n }\n }\n if (countFS > countSF){\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "74e2546b7277d435ff9aff5d77d7c3c2", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class BetweenOffice{\n public static void main(String[] args){\n Scanner scanner = new Scanner(System.in);\n int num = scanner.nextInt();\n String str = scanner.next();\n \n int seaF = 0;\n int franS = 0;\n for (int i=1; i franS){\n System.out.println(\"YES\";)\n }else{\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3a451a7c56b775e2d0e327ddef2c0afa", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800} {"lang": "Java 11", "source_code": " import java.io.*;\n import java.util.*;\n \n public class BtoO\n {\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n \n int n = sc.nextInt();\n String s = sc.next();\n char[] ch = s.toCharArray();\n \n int fs = 0;\n int sf = 0;\n \n for(int i=0;i fs)\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n \n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "17bde60e73a892668ed42c8983e1df83", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800} {"lang": "Java 11", "source_code": "public class Codeforces{\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 x=sc.nextInt();\n\t\tString bin=\"\";\n\t\tif(a>=b) {\n\t\t\tif(x%2!=0) {\n\t\t\t\tfor(int i=1;i<=x+1;i++) {\n\t\t\t\t\tif(i%2!=0) {\n\t\t\t\t\t\tbin+=\"0\";\n\t\t\t\t\t\ta--;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tbin+=\"1\";\n\t\t\t\t\t\tb--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=1;i<=b;i++) {\n\t\t\t\t\tbin=\"0\"+bin+\"1\";\n\t\t\t\t\ta--;\n\t\t\t\t}\n\t\t\t\tfor(int i=1;i<=a;i++) bin=bin+\"1\";\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfor(int i=1;i<=x+1;i++) {\n\t\t\t\t\tif(i==x) {\n\t\t\t\t\t\tfor(int j=1;j<=b;j++) bin=bin+\"1\";\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif(i%2!=0) {\n\t\t\t\t\t\tbin+=\"0\";\n\t\t\t\t\t\ta--;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tbin+=\"1\";\n\t\t\t\t\t\tb--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=1;i<=a;i++) bin=\"0\"+bin;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif(x%2!=0) {\n\t\t\t\tfor(int i=1;i<=x+1;i++) {\n\t\t\t\t\tif(i%2!=0) {\n\t\t\t\t\t\tbin+=\"1\";\n\t\t\t\t\t\tb--;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tbin+=\"0\";\n\t\t\t\t\t\ta--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=1;i<=a;i++) {\n\t\t\t\t\tbin=\"1\"+bin+\"0\";\n\t\t\t\t\tb--;\n\t\t\t\t}\n\t\t\t\tfor(int i=1;i<=b;i++) bin=\"1\"+bin;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfor(int i=1;i<=x+1;i++) {\n\t\t\t\t\tif(i==x) {\n\t\t\t\t\t\tfor(int j=1;j<=a;j++) bin=bin+\"0\";\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif(i%2!=0) {\n\t\t\t\t\t\tbin+=\"1\";\n\t\t\t\t\t\tb--;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tbin+=\"0\";\n\t\t\t\t\t\ta--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i=1;i<=b;i++) bin=\"1\"+bin;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(bin);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "494109ff401512034f55caf9b725282a", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Contest494_B w = new Contest494_B();\n w.qwerty();\n\n Scanner in = new Scanner (System.in);\n String s = in.nextLine();\n String ss[] = s.split(\" \");\n int zeros = Integer.valueOf(ss[0]);\n int ones = Integer.valueOf(ss[1]);\n int goal = Integer.valueOf(ss[2]);\n int q = ones;\n ArrayList binarString = new ArrayList();\n for (int i = 0; i < ones; i++){\n binarString.add(1);\n }\n for (int i = ones; i < zeros + ones; i++){\n binarString.add(0);\n }\n// System.out.println(10 % 2);\n int count = 1;\n if ((zeros == 1) && (count != goal)){\n binarString.add(1, 0);\n }\n else {\n while (count != goal) {\n // System.out.print(binarString);\n // System.out.println(\" \" + ones);\n if (count % 2 != 0) {\n binarString.remove(q + zeros - 1);\n binarString.add(0, 0);\n ones++;\n } else {\n binarString.remove(ones - 1);\n binarString.add(0, 1);\n }\n count++;\n }\n }\n for (int i = 0; i < q + zeros; i++) {\n System.out.print(binarString.get(i));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c63a142a67d283d8e910066bcec24b24", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class BinaryStringConstructing\n{\n\tpublic static void main(String[] o)\n\t{\n\t\tint a,b,x,i;\n\t\tScanner sc=new Scanner(System.in);\n\t\ta=sc.nextInt();\n\t\tb=sc.nextInt();\n\t\tx=sc.nextInt();\n\t\tif(a>b)\n\t\t{\n\t\t\ts=\"01\";\n\t\t\ta--;\n\t\t\tb--;\n\t\t\tx--;\n\t\t\tfor(i=0;i arylst = new ArrayList();\n for(int i = 0;i < req.length() ;i++){\n int ele = Integer.parseInt(req.charAt(i)+\"\");\n arylst.add(ele);\n if(ele == 1)\n count1++;\n else\n count0++;\n }\n\n int lastele = arylst.get(arylst.size()-1);\n if(lastele == 0){\n for(int i =count0;i < (a );i++)\n arylst.add(0);\n for(int i = count1;i < b;i++){\n arylst.add(0,1);\n }\n }\n else{\n for(int i = count1;i < (b) ;i++)\n arylst.add(1);\n for(int i = count0;i < a;i++)\n arylst.add(1,0);\n }\n\n for(int i = 0;i < arylst.size() ;i++){\n out.print(arylst.get(i));\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "38b27db9146530b76c8885a810e94efa", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c", "difficulty": 1300} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\nimport javafx.util.Pair;\n\npublic class FirstApp {\n private static MyScanner in;\n private static PrintStream out;\n private static void solve() throws IOException\n {\n int n= in.nextInt();\n int[] a= new int[10];\n int[] b= new int[10];\n int second= n%10;\n n/=10;\n int first = n%10;\n int sum=1;\n for( int i=0 ; i <= 9;++i)\n {\n\t a[i] =i;\n }\n b[0]=2;\n b[1]=7;\n b[2]=2;\n b[3]=3;\n b[4]=3;\n b[5]=4;\n b[6]=2;\n b[7]=5;\n b[8]=1;\n b[9]=2;\n for( int i=0 ; i <= 9;++i)\n {\n\t if(a[i]==second)\n\t\t sum*=b[i];\n\t if(a[i]==first)\n\t\t sum*=b[i];\n }\n System.out.println(sum);\n }\n \npublic static void main(String[] args) throws IOException {\n\t in = new MyScanner();\n\tout = System.out;\n solve();\n }\n\n // =====================================\n static class MyScanner {\n BufferedReader bufReader;\n StringTokenizer strTok;\n\n public MyScanner() throws IOException\n {\n bufReader = new BufferedReader(new InputStreamReader(System.in));\n strTok = new StringTokenizer(\"\");\n }\n\n String GetNextToken() throws IOException {\n if (!strTok.hasMoreTokens())\n strTok = new StringTokenizer(bufReader.readLine());\n return strTok.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.valueOf(GetNextToken());\n }\n public Long nextLong() throws IOException {\n\t return Long.valueOf(GetNextToken());\n\t }\n public String nextString() throws IOException {\n return GetNextToken();\n }\n\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a70f7d754939696257b4d3a36215d2cf", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Test {\n static Scanner input=new Scanner(System.in);\n public static void main(String[]args)\n\n {\n int x;\n int y=0;\n \n x = input.nextInt(); \n if(x>=0 && x<10) \n {\n switch (x) { \n case 07:\n y=10;\n break;\n case 8;\n y=2;\n break;\n case 01:\n y=12;\n break;\n \n case 03:\n y=6;\n break;\n default :\n y=4;\n }\n }\n else if(x>=10 & x<20)\n {\n switch(x) {\n case 11:\n y=36;\n break;\n case 13:\n case 14:\n case 15:\n y=18;\n break;\n case 17:\n y=30;\n break;\n case 18:\n y=6;\n break;\n default:\n y=12;\n }\n }\n else if(x>=20 && x<30)\n {\n switch(x)\n {\n case 21:\n y=12;\n break;\n case 23:\n case 24:\n case 25:\n y=6;\n break;\n case 27:\n y=10;\n break;\n default:\n y=4;\n }\n }\n else if(x>=30 && x<40)\n {\n switch(x)\n {\n case 31:\n y=18;\n break;\n case 33:\n case 34:\n case 35:\n y=9;\n break;\n case 37:\n y=15;\n break;\n case 38:\n y=3;\n break;\n default:\n y=6;\n }\n }\n \n else if(x>=40 && x<50)\n {\n switch(x)\n {\n case 41:\n y=18;\n break;\n case 43:\n case 44:\n case 45:\n y=9;\n break;\n case 47:\n y=15;\n break;\n case 48:\n y=3;\n break;\n default:\n y=6;\n \n }\n }\n else if (x>=50 && x<60)\n {\n switch(x)\n {\n case 51:\n y=18;\n break;\n case 53:\n case 54:\n case 55:\n y=9;\n break;\n case 57:\n y=15;\n break;\n case 58:\n y=3;\n break;\n default:\n y=6;\n \n }\n }\n else if (x>=60 && x<70)\n {\n switch(x)\n { \n case 61:\n y=12;\n break;\n case 63:\n case 65:\n y=6;\n break;\n case 67:\n y=10;\n break;\n case 68:\n y=2;\n break;\n default:\n y=4;\n \n \n }\n \n }\n else if (x>=70 && x<80)\n {\n switch(x)\n {\n case 71:\n y=30;\n break;\n case 73:\n case 74:\n case 75:\n y=15;\n break;\n case 77:\n y=25;\n break;\n case 78:\n y=5;\n break;\n default:\n y=10;\n break; \n }\n }\n else if(x>=80 && x<90)\n {\n {\n switch(x)\n {\n case 80:\n case 86: \n case 89:\n y=2;\n break;\n case 81:\n y=6;\n break;\n case 82:\n y=4;\n break;\n case 87:\n y=5;\n break;\n case 88:\n y=1;\n break;\n default:\n y=3;\n \n }\n }\n \n }\n else if(x>=90 && x<=99)\n {\n switch(x)\n { \n case 91:\n y=12;\n break;\n case 93:\n case 94:\n case 95:\n y=6;\n break;\n case 97:\n y=10;\n break;\n case 98:\n y=2;\n break;\n default:\n y=4;\n \n \n }\n \n }\n System.out.println(y);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4a2534229178879f77f4d4d853713ee4", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class DigitCounter\n{\n \npublic static void main(String [] args)\n\n{\n Scanner input = new Scanner(System.in);\n int n;\n int d;\n n = input.nextInt();\n int []options = {2,7,2,3,3,4,2,5,1,2};\n int goodInteger;\n int n1;\n int n2;\n d = n % 10;\n n1 = options[d];\n n = n /10;\n d = n % 10;\n n2 = options[d];\n goodIntegers = n1 * n2;\n System.out.println(goodIntegers);\n \n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05b6a75b327cc0773d9bd9e8e754f490", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Test {\n static Scanner input=new Scanner(System.in);\n public static void main(String[]args)\n\n {\n int x;\n int y=0;\n \n x = input.nextInt(); \n if(x>=0 && x<10) \n {\n switch (x) { \n case 07:\n y=10;\n break;\n case 8:\n y=2;\n break;\n case 01:\n y=14;\n break;\n \n case 03:\n case 04:\n y=6;\n break;\n case 05:\n y=8;\n break;\n default : \n y=4;\n }\n }\n else if(x>=10 & x<20)\n {\n switch(x) { \n case 11:\n y=49;\n break;\n case 13:\n case 14:\n \n y=21;\n \n break;\n case 15:\n y=28;\n break;\n case 17:\n y=35;\n break;\n case 18:\n y=7;\n break;\n default:\n y=14;\n }\n }\n else if(x>=20 && x<30)\n {\n switch(x)\n {\n case 21:\n y=14;\n break;\n case 23:\n case 24:\n y=6; \n break;\n case 25:\n y=8;\n break;\n case 27:\n y=10;\n break;\n case 28:\n y=2;\n default:\n y=4;\n }\n }\n else if(x>=30 && x<40)\n {\n switch(x)\n {\n case 31:\n y=21;\n break;\n case 33:\n case 34:\n y=9;\n break;\n case 35:\n y=12;\n break;\n \n case 37:\n y=15;\n break\n \n case 38:\n y=3;\n break;\n default:\n y=6;\n }\n }\n \n else if(x>=40 && x<50)\n {\n switch(x)\n {\n case 41:\n y=21;\n break;\n case 43:\n case 44:\n y=9;\n break;\n case 45:\n y=12;\n break;\n case 47:\n y=15;\n break;\n case 48:\n y=3;\n break;\n default:\n y=6;\n \n }\n }\n else if (x>=50 && x<60)\n {\n switch(x)\n {\n case 51:\n y=28;\n break;\n case 53:\n case 54:\n y=12;\n break;\n case 55:\n y=16;\n break;\n case 57:\n y=20;\n break;\n case 58:\n y=4;\n break;\n default:\n y=8;\n \n }\n }\n else if (x>=60 && x<70)\n {\n switch(x)\n { \n case 61:\n y=14;\n break;\n case 63:\n case 64:\n y=6;\n break;\n case 65:\n y=8;\n break;\n case 67:\n y=10;\n break;\n case 68:\n y=2;\n break;\n default:\n y=4;\n \n \n }\n \n }\n else if (x>=70 && x<80)\n {\n switch(x)\n {\n case 71:\n y=35;\n break;\n case 73:\n case 74:\n \n y=15;\n break;\n case 75:\n y=28;\n break;\n case 77:\n y=25;\n break;\n case 78:\n y=5;\n break;\n default:\n y=10;\n break; \n }\n }\n else if(x>=80 && x<90)\n {\n {\n switch(x)\n {\n case 80:\n case 82:\n case 86: \n case 89:\n y=2;\n break;\n case 81:\n y=7;\n break; \n break;\n case 85:\n y=4;\n break;\n case 87:\n y=5;\n break;\n case 88:\n y=1;\n break;\n default:\n y=3;\n \n }\n }\n \n }\n else if(x>=90 && x<=99)\n {\n switch(x)\n { \n case 91:\n y=14;\n break;\n case 93:\n case 94:\n y=6;\n break;\n case 95:\n y=8;\n break;\n case 97:\n y=10;\n break;\n case 98:\n y=2;\n break;\n default:\n y=4;\n \n \n }\n \n }\n System.out.println(y);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2613dfe59f67317459ce34fa07a68275", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100} {"lang": "Java 7", "source_code": "import codeforces.b;\nimport codeforces.c;\nimport codeforces.d;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n \npublic class Main {\n \n \n \n public static void main(String arg[]) throws IOException {\n \n \n \n // BufferedReader r=new BufferedReader(new FileReader(\"testcase.txt\"));\n BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter p = new PrintWriter(System.out, false);\n \n StringTokenizer str;\n \n \n str = new StringTokenizer(r.readLine());\n BigInteger a=new BigInteger(str.nextToken());\n BigInteger b=new BigInteger(str.nextToken());\n BigInteger c=new BigInteger(str.nextToken());\n BigInteger d=new BigInteger(str.nextToken());\n \n \n \n BigInteger temp=a;\n a=a.multiply(c);\n b=b.multiply(c);\n c=c.multiply(temp);\n d=d.multiply(temp);\n \n temp=b;\n b=b.multiply(d);\n a=a.multiply(d);\n c=c.multiply(temp);\n d=d.multiply(temp);\n \n \n BigInteger num=a.multiply(b).subtract(c.multiply(d));\n BigInteger den=a.multiply(b);\n BigInteger x=gcd(num,den);\n p.println((num.divide(x))+\"/\"+(den.divide(x)));\n \n \n \n \n \n p.flush();\n}\n \n \n private static BigInteger gcd(BigInteger a, BigInteger b) {\n if(b.compareTo(BigInteger.ZERO)==0)\n return a;\n return gcd(b,a.mod(b));\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65e3fb24c5e48ef499536dfc82d6c788", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\nimport practice.bookofevil.Main.EvilTree;\n\npublic class Main {\n \n public static int gcd(int a,int b) {\n return (BigInteger.valueOf(b).gcd(BigInteger.valueOf(a))).intValue();\n }\n \n public static int lcm(int a,int b) {\n return a*b/gcd(a,b);\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int d = in.nextInt();\n if (a*d < c*b) {\n a ^= b;\n b ^= a;\n a ^= b;\n c ^= d;\n d ^= c;\n c ^= d;\n }\n int lcm = lcm(b,d);\n int aNew = a*lcm/b;\n int cNew = c*lcm/d;\n int gcd = gcd(aNew,cNew);\n System.out.println((aNew-cNew)/gcd+\"/\"+aNew/gcd);\n in.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d010383634b663836d0596bb0a554130", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400} {"lang": "Java 7", "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 Task337B {\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\tpublic static int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\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\t\t\tint a = s.nextInt();\n\t\t\tint b = s.nextInt();\n\t\t\tint c = s.nextInt();\n\t\t\tint d = s.nextInt();\n\n\t\t\tif (a * d > b * c) {\n\t\t\t\tint newA = a * d;\n\t\t\t\tint newB = b * d;\n\n\t\t\t\tint newC = c * b;\n\t\t\t\tint newD = d * b;\n\n\t\t\t\tassert newC <= newA;\n\t\t\t\tassert newB == newD;\n\n\t\t\t\tint p = newA - newC;\n\t\t\t\tint q = newB;\n\n\t\t\t\tint nwdpq = gcd(p, q);\n\n\t\t\t\tp /= nwdpq;\n\t\t\t\tq /= nwdpq;\n\n\t\t\t\tpw.print(p);\n\t\t\t\tpw.print(\"/\");\n\t\t\t\tpw.println(q);\n\t\t\t} else {\n\t\t\t\tint newA = a * c;\n\t\t\t\tint newB = b * c;\n\n\t\t\t\tint newC = c * a;\n\t\t\t\tint newD = d * a;\n\n\t\t\t\tassert newC == newA;\n\t\t\t\tassert newB <= newD;\n\n\t\t\t\tint p = newD - newB;\n\t\t\t\tint q = newCs;\n\n\t\t\t\tint nwdpq = gcd(p, q);\n\n\t\t\t\tp /= nwdpq;\n\t\t\t\tq /= nwdpq;\n\n\t\t\t\tpw.print(p);\n\t\t\t\tpw.print(\"/\");\n\t\t\t\tpw.println(q);\n\t\t\t}\n\t\t\tpw.flush();\n\t\t\ts.close();\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ac603e8f0ca03a51055d668fef184ac", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\n/*\n * Routine Problem\n * \u30e2\u30cb\u30bf\u30fc\u306e\u30b9\u30af\u30ea\u30fc\u30f3\u306e\u7e26\u6a2a\u6bd4\u306fA:B\u3067\u3042\u308b\u3002\n * \u6620\u753b\u306e\u6620\u50cf\u306e\u7e26\u6a2a\u6bd4\u306fC:D\u3067\u3042\u308b\u3002\n * \n * \u4e21\u65b9\u306e\u7e26\u6a2a\u6bd4\u3092\u4fdd\u3063\u305f\u307e\u307e\u3001\u753b\u9762\u3092\u6700\u5927\u9650\u306b\u6d3b\u7528\u3057\u305f\u6620\u50cf\u306e\u8868\u793a\u65b9\u6cd5\u3092\u8003\u3048\u308b\u3002\n * \u3053\u306e\u6642\u3001\u6620\u50cf\u306e\u6620\u3089\u306a\u3044\u90e8\u5206\u306e\u6bd4\u3092\u6c42\u3081\u3088\u3002\n * \n * \u8003\u3048\u65b9\n * \u6bd4\u306e\u8a08\u7b97\u3002\u753b\u9762\u306e\u7e26\u3082\u3057\u304f\u306f\u6a2a\u306e\u6bd4\u3092\u540c\u5024\u306b\u3057\u3001\u540c\u5024\u3067\u306f\u306a\u3044\u90e8\u5206\u306e\u5dee\u3092\u8003\u3048\u308b\u3002\n * \n * A : B = C : D\u3000\uff08\u5f0f\u3068\u3057\u3066\u306f\u6b63\u3057\u304f\u306a\u3044\uff09\u3092\u8003\u3048\u3001A*D\u3000\u3068\u3000B*C\u3000\u3092\u6c42\u3081\u308b\u3002 \n * A*D \u3068\u3000B*C\u3000\u306e\u5927\u5c0f\u95a2\u4fc2\u3092\u6c42\u3081\u308b\u3002 \uff08\u5927\u304d\u3044\u65b9\u3092L,\u5c0f\u3055\u3044\u65b9\u3092S\u3068\u3059\u308b\uff09\n * L-S \u3068\u3000L \u306e\u3000\u6700\u5c0f\u516c\u500d\u6570\u3092\u6c42\u3081\u3001\u6c42\u3081\u3089\u308c\u305f\u6700\u5c0f\u516c\u500d\u6570\u3067\u4e21\u65b9\u306e\u5024\u3092\u5272\u308b\u3002\n * \n * 1:2\u3000\u3068 3:6\u3000\u306a\u3069\u3001 A*D = B*C\u3000\u3068\u306a\u308b\u30b1\u30fc\u30b9\u306b\u6c17\u3092\u3064\u3051\u308b\u3002\n * \u3053\u306e\u3088\u3046\u306a\u5834\u5408\u3001\u753b\u9762\u306e\u6620\u50cf\u306e\u6620\u3089\u306a\u3044\u90e8\u5206\u306f\u5fc5\u305a 0/1\u3000\u3068\u306a\u308b\u3002\n * (test4\u3000\u304c\u3053\u306e\u30b1\u30fc\u30b9\u306b\u5f53\u3066\u306f\u307e\u308b\u69d8\u5b50\u3002)\n * \n */\n\npublic class Main {\n Scanner sc = new Scanner(System.in);\n void doIt(){\n \n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt(); \n int d = sc.nextInt();\n \n int v1 = a * d;\n int v2 = b * c;\n \n int s=0, s1=0, s2=0; \n if(v1 > v2){\n s1 = v1-v2;\n s2 = v1; \n s = euc(s1,s2);\n System.out.println((s1/s) +\"/\"+ (s2/s));\n }else if(v1 < v2){\n s1 = v2-v1;\n s2 = v2;\n s = euc(s1,s2);\n System.out.println((s1/s) +\"/\"+ (s2/s));\n }else{\n System.out.println(\"0/1\");\n }\n } \n public int euc(int m, int n){\n while(n!=0){\n int tmp = m;\n m = n;\n n = tmp%n;\n }\n return m; \n }\n \n public static void main(String[] args) {\n new Main().doIt();\n }\n\n // thanks to wata\n class Scanner {\n InputStream in;\n byte[] buf = new byte[1 << 10];\n int p, n;\n boolean[] isSpace = new boolean[128];\n Scanner(InputStream in) {\n this.in = in;\n isSpace[' '] = isSpace['\\n'] = isSpace['\\r'] = isSpace['\\t'] = true;\n }\n int read() {\n if (n == -1) return -1;\n if (p >= n) {\n p = 0;\n try {\n n = in.read(buf);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n if (n <= 0) return -1;\n }\n return buf[p++];\n }\n boolean hasNext() {\n int c = read();\n while (c >= 0 && isSpace[c]) c = read();\n if (c == -1) return false;\n p--;\n return true;\n }\n String next() {\n if (!hasNext()) throw new InputMismatchException();\n StringBuilder sb = new StringBuilder();\n int c = read();\n while (c >= 0 && !isSpace[c]) {\n sb.append((char)c);\n c = read();\n }\n return sb.toString();\n }\n int nextInt() {\n if (!hasNext()) throw new InputMismatchException();\n int c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (c >= 0 && !isSpace[c]);\n return res * sgn;\n }\n long nextLong() {\n if (!hasNext()) throw new InputMismatchException();\n int 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') throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (c >= 0 && !isSpace[c]);\n return res * sgn;\n }\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5929bb2f92b7a2e3d0ad8613154ba917", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Map;\nimport java.util.Queue;\n\npublic class Codec {\n // Encodes a tree to a single string.\n public String serialize(TreeNode root) {\n StringBuilder sb = new StringBuilder();\n Queue q = new LinkedList<>();\n\n q.add(root);\n\n while (!q.isEmpty()) {\n for (int i = 0; i < q.size(); i++) {\n TreeNode h = q.poll();\n if (h == null) {\n sb.append(\",\");\n } else {\n sb.append(h.val).append(\",\");\n q.add(h.left);\n q.add(h.right);\n }\n }\n }\n\n sb.setLength(sb.length() - 1);\n return sb.toString();\n }\n\n // Decodes your encoded data to tree.\n public TreeNode deserialize(String data) {\n if (data == null || data.length() == 0) return null;\n\n TreeNode root;\n String[] bits = data.split(\",\");\n Map map = new HashMap<>();\n root = new TreeNode(Integer.parseInt(bits[0]));\n map.put(0, root);\n\n for (int i = 0; i < bits.length; i++) {\n if (bits[i].length() == 0) {\n continue;\n }\n\n TreeNode node = map.get(i);\n int leftIndex = 2 * i + 1;\n int rightIndex = 2 * i + 2;\n\n if (leftIndex < bits.length && bits[leftIndex].length() > 0) {\n TreeNode leftNode = new TreeNode(Integer.parseInt(bits[leftIndex]));\n map.put(leftIndex, leftNode);\n node.left = leftNode;\n }\n\n if (rightIndex < bits.length && bits[rightIndex].length() > 0) {\n TreeNode rightNode = new TreeNode(Integer.parseInt(bits[rightIndex]));\n map.put(rightIndex, rightNode);\n node.right = rightNode;\n }\n }\n\n return root;\n }\n\n\n public static void main(String[] args) {\n Codec c = new Codec();\n TreeNode n = new TreeNode(1);\n n.right = new TreeNode(2);\n n.right.right = new TreeNode(3);\n n.right.right.right = new TreeNode(4);\n\n String k = c.serialize(n);\n System.out.println(k);\n\n TreeNode x = c.deserialize(k);\n\n System.out.println(x.val);\n System.out.println(x.left);\n System.out.println(x.right.val);\n System.out.println(x.right.right.val);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "761824816d82ed9c709cd8101c9bd607", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.io.PrintStream;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic final class ProblemA {\n public static void main(String[] args) {\n final Scanner in = new Scanner(System.in);\n final PrintStream out = System.out;\n\n final String contestName = in.nextLine();\n final Set names = new HashSet<>();\n names.add(\"Danil\");\n names.add(\"Olya\");\n names.add(\"Slava\");\n names.add(\"Ann\");\n names.add(\"Nikita\");\n\n boolean matches = names.stream().map(name -> count(contestName, name)).mapToLong(Long::valueOf).sum() == 1L\n out.println(matches ? \"YES\" : \"NO\");\n }\n\n private static int count(String s, String t) {\n int count = 0;\n for (int idx = s.indexOf(t); idx != -1; idx = s.indexOf(t, idx + 1)) {\n count++;\n }\n return count;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c80e0ec423347bccca4cd3c09ae4f795", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100} {"lang": "Java 11", "source_code": "public class Main {\n \n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String s = scanner.nextLine();\n String cap = s;\n cap+=\"1\";\n cap+=\"1\";\n cap+=\"1\";\n cap+=\"1\";\n cap+=\"1\";\n cap+=\"1\";\n cap+=\"1\";\n int count =0;\n for(int i =0; i ans = new ArrayList();\n\t\t\tans.add(1);\n\t\t\tint half = (arr[0]+1)/2;\n\t\t\tfor(int i = 1; i < n; i++){\n\t\t\t\tif(arr[i] <= half){\n\t\t\t\t\tcount++;\n\t\t\t\t\tans.add(i);\n\t\t\t\t\tsum2 +=a arr[i];\n\t\t\t\t\tif(sum2 > sum/2)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(count);\n\t\t\tfor(int i = 0; i < ans.size(); i++){\n\t\t\t\tSystem.out.println(ans.get(i));\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e2cfb4cca7a68ec5727815e976bf0677", "src_uid": "0a71fdaaf08c18396324ad762b7379d7", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Solution{\n\tpublic static void main(String[] args) {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tString str[] = br.readLine().trim().split(\"\\\\s+\");\n\t\tint arr[] = new int[n];\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tarr[i] = Integer.parseInt(str[i]);\n\t\t\tsum += arr[i];\n\t\t}\n\t\tif((sum+1)/2 <= arr[i])\n\t\t\tSystem.out.println(0);\n\t\telse{\n\t\t\tint count = 0;\n\t\t\tArrayList ans = new AArrayList();\n\t\t\tint half = (arr[0]+1)/2;\n\t\t\tfor(int i = 1; i < n; i++){\n\t\t\t\tif(arr[i] <= half){\n\t\t\t\t\tcount++;\n\t\t\t\t\tans.add(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(count);\n\t\t\tfor(int i = 0; i < ans.size(); i++){\n\t\t\t\tSystem.out.prinltn(ans.get(i));\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4316acf55add723eddc63c089d2a937f", "src_uid": "0a71fdaaf08c18396324ad762b7379d7", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Atask {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n StringBuilder ans = new StringBuilder(\"\");\n int arr[] = new int[ n + 1 ];\n int sum = 0;\n for ( int i = 1; i <= n; i++ ) {\n arr[ i ] = sc.nextInt();\n sum += arr[ i ];\n }\n int threshold = sum/2+1;\n //System.out.println(threshold);\n ans.append(1+ \" \");\n int toThres = arr[1];\n if(toThres>=threshold) {\n System.out.println(ans.length() / 2);\n System.out.println(ans.toString());\n return;\n }\n for ( int i =2;i<=n;i++){\n // System.out.println(toThres);\n if(toThres>=threshold) {\n break;\n }\n if(arr[i]%2==0?arr[i]*2:arr[i]*2-1<=(arr[1]%2==0?arr[1]:arr[1]-1)){\n toThres+=arr[i];\n ans.append(i+\" \");\n }\n }\n if(toThres>=threshold) {\n String another = ans.toString();\n int num = 0;\n for ( int j = 0; j < another.length();j++ ){\n if(Character.isDigit(another.charAt(j)))\n num++;\n }\n System.out.println(num);\n System.out.println(ans.toString().substring(0,ans.length()-1));\n }else{\n System.out.println(0);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "63191419936f106a68d4b74e357fd484", "src_uid": "0a71fdaaf08c18396324ad762b7379d7", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(), sum = 0, a[] = new int[n];\n\n for(int i = 0; i ans = new ArrayList<>();\n for(int i = 1; i=2*a[i]){\n ans.add(i+1);\n sum1+=a[i];\n }\n if(2*sum1>sum) break;\n }\n\n if(ans.size()==0 || 2*sum1<=sum) System.out.println(0);\n else{\n System.out.println(ans.size()+1);\n System.out.print(\"1 \");\n for(int x:ans){\n System.out.print(x+\" \");\n }\n }\n }\n}\n System.out.print(\"1 \");\n for(int x:ans){\n System.out.print(ans+\" \");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "50a8a74bbf593b0ef2f8119a9aad216a", "src_uid": "0a71fdaaf08c18396324ad762b7379d7", "difficulty": 800} {"lang": "Java 8", "source_code": "package gfdgfd;\nimport java.util.*;\npublic class Main {\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint r = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tchar ch[][] = new char[r][c];\n\t\tfor(int i=0; i=k)\n\t\t\t\t\t\t\tcounter++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(counter);\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "07a8cd49c8cbc97657c33225e5d31c88", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100} {"lang": "Java 7", "source_code": "package codeforces;\n\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Orchestra {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n int r = sc.nextInt();\n int c = sc.nextInt();\n int n = sc.nextInt();\n int k = sc.nextInt();\n boolean[][] orchestra = new boolean[r][c];\n for (int i = 0; i < n; i++) {\n int x = sc.nextInt();\n int y = sc.nextInt();\n orchestra[x-1][y-1] = true;\n }\n int result = 0;\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < r; j++) {\n for (int a = 0; a < c; a++) {\n for (int b = 0; b < c; b++) {\n\n int sum = 0;\n for (int x = i; x <= j; x++) {\n for (int y = a; y <= b; y++) {\n if (orchestra[x][y]) sum++;\n }\n }\n if (sum >= k) {\n result++;\n// if (i == a && j == b) {\n// result--;\n// out.println(\"the same\");\n// }\n }\n// out.println((i+1) + \" \" + (j+1) + \" \" + (a+1) + \" \" + (b+1) + \": \" + sum);\n }\n }\n }\n\n }\n out.println(result);\n out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d00f4989aa63e71c200d78c35d23926", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100} {"lang": "Java 8", "source_code": "package gfdgfd;\nimport java.util.*;\npublic class main {\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint r = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tchar ch[][] = new char[r][c];\n\t\tfor(int i=0; i=k)\n\t\t\t\t\t\t\tcounter++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(counter);\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3196720bcedeb267c57c6b59d5ca2bdd", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner scan=new Scanner(System.in);\n\t\tint r=scan.nextInt();\n\t\tint c=scan.nextInt();\n\t\tint n=scan.nextInt();\n\t\tint q=scan.nextInt();\n\t\tboolean[][] check=new boolean[11][11]; \n\t\tint[][] a=new int[11][11];\n\t\tfor (int i=0;i=q)\n\t\t\t\t\t\t\tres++;\n\t\t\t\t\t}\n\t\tSystem.out.println(res);\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6d05a95b59e465dccbb854f0b7535a49", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class ASwimmingPool {\n\n public static void main(String[] args) {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n PrintWriter out = new PrintWriter(System.out, true);\n\n try {\n int n_vert = Integer.parseInt(br.readLine());\n }\n catch (IOException e) {\n\n }\n\n/* int[][] verts = new int[n_vert][2];\n\n for (int i=0; i 22 && a <= b) {\n System.out.println(-1);\n return;\n }\n if (hour >= 10 && hour < 22) x+=a;\n else x-=b;\n hour ++;\n if (hour == 24) {\n hour = 0; day++;\n }\n }\n System.out.println(day);\n }\n\n}\n\npublic class Main {\n public static void main(String[] args) {\n new CF652A().work();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "60692150ca8fa64ed3d7e206039037e8", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400} {"lang": "Java 8", "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\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\t\tfor(int day = 0;;++day){\n\t\t\tif (1L * progress * day + a * 8 >= h2) {\n\t\t\t\tout.prinltn(day);\n\t\t\t\tout.close();\n\t\t\t\treturn;\n\t\t\t}\t\n\t\t}\n\t}\n\t\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4842888eccdd69f44c205993d9dce474", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class A\n{\n\tpublic static void main(String args[])\n\t{\n\t\tint h1 = s.nextInt();\n\t\tint h2 = s.nextInt();\n\t\tint a = s.nextInt();\n\t\tint b = s.nextInt();\n\n\t\tif(b>=a)\n\t\t{\n\t\t\tif((h2-h1)<=8*a)\n\t\t\t\tSystem.out.println(0);\n\t\t\telse \n\t\t\t\tSystem.out.println(-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint days = 0;\n\t\t\th1 = h1+8*a;\n\t\t\twhile(h1 0){\r\n\t System.out.println(PlayOff(s.nextInt()));\r\n\t t--;\r\n\t }\r\n \r\n\t}\r\n\t\r\n\tpublic static int PlayOff(int n){\r\n\t List res = new ArrayList<>();\r\n\t int player = (int)Math.pow(2, n);\r\n\t for(int i = 1; i <= player; i++) res.add(i);\r\n\t \r\n\t while(res.size() > 1){\r\n\t List next = new ArrayList<>();\r\n\t for(int i = 0; i < res.size(); i+=2){\r\n\t int a = res.get(i);\r\n\t int b = res.get(i+1);\r\n\t if((a+b) % 2 == 0) next.add(b);\r\n\t else next.add(a);\r\n\t }\r\n\t res = next;\r\n\t }\r\n\t return res.get(0);\r\n\t \r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c1545719a114fe3478b3538951d0d020", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\r\nimport java.io.*;\r\npublic class Playoff{\r\n public static void main(String[] args)\r\n {\r\n Scanner sc=new Scanner(System.in);\r\n int t;\r\n t= sc.nextInt();\r\n while(t--)\r\n { int n;\r\n n=sc.nextInt();\r\n if(n==1)\r\n {\r\n System.out.println(1);\r\n }\r\n else\r\n {\r\n System.out.println((1< 0)\r\n {\r\n \tint N = scn.nextInt();\r\n \tSystem.out.println( (int)Math.pow(2, N) - 1);\r\n \t\r\n }\r\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea5a6de4f35f4965b55259abb14eb2dd", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Ismael\n */\npublic class Main{\n\n /**\n * @param args the command line arguments\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 int MOD= 1000000007;\n int C[][]= new int[2051][2051];\n for (int i= 0; i < 2051; i++) {\n C[0][i]=1;\n C[i][0]=1;\n }\n for (int i= 1; i < 2051; i++) {\n for (int j= 1; j < 2051; j++) {\n C[i][j]=(C[i-1][j]+C[i][j-1])%MOD;\n }\n }\n int res=0;\n if(!((n-1)<2*k||(m-1)<2*k)){\n res= (C[n-1-2*k][2*k]*C[m-1-2*k][2*k])%MOD;\n }\n System.out.println(res);\n /*\n for (int i = 1; i < 10; i++) {\n for (int j = 1; j < 10; j++) {\n System.out.println(\"Combinaciones de \"+(i+j)+\" tomadas de a \"+j+\" son \"+C[i][j]);\n }\n }\n */\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9b914c6b22eeb68a2df5d4fd2948ac9d", "src_uid": "309d2d46086d526d160292717dfef308", "difficulty": 2000} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class E {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int k = sc.nextInt();\n int[][]C = new int[1001][1001];\n C[1][0] = C[1][1] = 1;\n int p = (int) (1e9+7);\n for (int i = 2; i <= n; i++) {\n C[i][0] = 1;\n for (int j = 1; j <= 1000; j++) {\n C[i][j] = (C[i-1][j-1]+C[i-1][j]) % p;\n }\n }\n int ans = 0;\n if (2*k <= n-1)\n ans = C[n-1][2*k];\n if (2*k <= m-1)\n ans = (int)((long)ans*C[m-1][2*k] % p);\n else\n ans = 0;\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a4de2d13e51be79be843277b66b7ad7d", "src_uid": "309d2d46086d526d160292717dfef308", "difficulty": 2000} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.util.Scanner;\n\n\npublic class Prob128C\n{\n public static void main( String[] Args ) throws IOException\n {\n Scanner in = new Scanner( System.in );\n int w = in.nextInt() - 2;\n int l = in.nextInt() - 2;\n int turns = in.nextInt();\n \n int h = w * ( w + 1 ) / 2;\n int v = l * ( l + 1 ) / 2;\n \n System.out.println( h * v / turns );\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7635be33b30527c69458957bfffc9c2e", "src_uid": "309d2d46086d526d160292717dfef308", "difficulty": 2000} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;\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 void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n int k = nextInt();\n\n if (Math.min(n, m) < 2 * k + 1) {\n out.print(0);\n return;\n }\n\n int[][] dp = new int[k + 1][Math.max(n, m) + 1];\n int[][] pref = new int[k + 1][Math.max(n, m) + 1];\n Arrays.fill(dp[0], 1);\n dp[0][0] = 0;\n for (int i = 1; i < dp[0].length; i++)\n pref[0][i] = pref[0][i - 1] + dp[0][i];\n for (int i = 1; i < dp.length; i++) {\n for (int j = 2 * i + 1; j < dp[i].length; j++) {\n dp[i][j] = dp[i][j - 1] + pref[i - 1][j - 2];\n pref[i][j] = pref[i][j - 1] + dp[i][j];\n if (pref[i][j] >= MOD)\n pref[i][j] -= MOD;\n\n }\n// System.err.println(Arrays.toString(dp[i]));\n// System.err.println(Arrays.toString(pref[i]));\n }\n\n out.print((long) dp[k][n] * dp[k][m] % MOD);\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "19247cc1356acada0540e51335894989", "src_uid": "309d2d46086d526d160292717dfef308", "difficulty": 2000} {"lang": "Java 8", "source_code": "package codeforces_contests.r514;\n\nimport java.util.Scanner;\n\npublic class B {\n\n static int n, m;\n\n public static void main(String[] ar) {\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n m = sc.nextInt();\n sc.nextLine();\n\n boolean[][] filled = new boolean[n][m];\n\n for (int i = 0; i < n; i++) {\n char[] line = sc.nextLine().toCharArray();\n for (int j = 0; j < m; j++) {\n if (line[j] == '#') filled[i][j] = true;\n }\n }\n\n if (n < 3 || m < 3) {\n System.out.println(\"NO\");\n return;\n }\n if (n == 3 && m == 3 && filled[1][1]) {\n System.out.println(\"NO\");\n return;\n }\n\n int dfi[] = {-1, 1, -1, 1, -1, 0, 1};\n int dfj[] = {0, 0, 1, 1, 2, 2, 2};\n int d2i[] = {-1, 1, 0, -1, -1, 1, 1};\n int d2j[] = {0, 0, -2, -1, -2, -1, -2};\n int d3i[] = {0, 0, -1, -1, -2, -2, -2};\n int d3j[] = {-1, 1, -1, 1, 0, 1, -1};\n int d4i[] = {0, 0, 1, 1, 2, 2, 2};\n int d4j[] = {-1, 1, -1, 1, -1, 0, 1};\n int d5i[] = {0, 0, 1, 1, 2, 2, 2};\n int d5j[] = {1, 2, 0, 2, 0, 1, 2};\n int d6i[] = {0, 0, 1, 1, 2, 2, 2};\n int d6j[] = {-1, -2, 0, -2, 0, -1, -2};\n int d7i[] = {0, 0, -1, -1, -2, -2, -2};\n int d7j[] = {-1, -2, 0, -2, 0, -1, -2};\n int d8i[] = {0, 0, -1, -1, -2, -2, -2};\n int d8j[] = {1, 2, 0, 2, 0, 1, 2};\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (filled[i][j]) {\n boolean val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + dfi[k], j + dfj[k]) && !filled[i + dfi[k]][j + dfj[k]]) {\n val = false;\n break;\n }\n }\n\n if (val) continue;\n\n val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + d2i[k], j + d2j[k]) && !filled[i + d2i[k]][j + d2j[k]]) {\n val = false;\n break;\n }\n }\n\n if (val) continue;\n\n val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + d3i[k], j + d3j[k]) && !filled[i + d3i[k]][j + d3j[k]]) {\n val = false;\n break;\n }\n }\n\n if (val) continue;\n\n val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + d4i[k], j + d4j[k]) && !filled[i + d4i[k]][j + d4j[k]]) {\n val = false;\n break;\n }\n }\n\n if (val) continue;\n\n val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + d5i[k], j + d5j[k]) && !filled[i + d5i[k]][j + d5j[k]]) {\n val = false;\n break;\n }\n }\n\n if (val) continue;\n\n val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + d6i[k], j + d6j[k]) && !filled[i + d6i[k]][j + d6j[k]]) {\n val = false;\n break;\n }\n }\n\n if (val) continue;\n\n val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + d7i[k], j + d7j[k]) && !filled[i + d7i[k]][j + d7j[k]]) {\n val = false;\n break;\n }\n }\n\n if (val) continue;\n\n val = true;\n for (int k = 0; k < dfi.length; k++) {\n if (valid(i + d8i[k], j + d8j[k]) && !filled[i + d8i[k]][j + d8j[k]]) {\n val = false;\n break;\n }\n }\n\n if (!val) {\n System.out.println(\"NO\");\n return;\n }\n\n }\n }\n }\n System.out.println(\"YES\");\n\n }\n\n private static boolean valid(int k, int l) {\n return k < n && k >= 0 && l < m && l >= 0;\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "09869ef0b794301edc42dc4504448e67", "src_uid": "49e5eabe8d69b3d27a251cccc001ab25", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.awt.*;\nimport java.awt.geom.*;\nimport java.math.*;\nimport java.text.*;\nimport java.math.BigInteger.*;\nimport java.util.Arrays; \n\npublic class cf514p2\n{\n BufferedReader in;\n StringTokenizer as;\n boolean nums[][],nums2[][];\n ArrayList < Integer > [] ar;\n \n public static void main (String[] args)\n {\n new cf514p2 ();\n }\n \n public void solve(int a, int b)\n {\n try\n {\n for(int x = -1;x<=1;x++)\n {\n for(int y = -1;y<=1;y++)\n { \n if( ((x != 0) || (y!=0)) && !nums[a+x][b+y])\n {\n return;\n }\n }\n }\n for(int x = -1;x<=1;x++)\n {\n for(int y = -1;y<=1;y++)\n { \n if( ((x != 0) || (y!=0)))\n {\n nums2[a+x][b+y] = true;\n }\n }\n }\n }\n catch(Exception e )\n {\n \n }\n }\n \n public cf514p2 ()\n {\n try\n {\n \n in = new BufferedReader (new InputStreamReader (System.in));\n ArrayList < Integer > [] ar;\n int a = nextInt();\n int b = nextInt();\n nums = new boolean [a][b];\n nums2 = new boolean [a][b];\n for(int x = 0;xb[0]-z+count){\n\t\t\t\tz=z+Math.max(b[1]-q,b[0]-z+count,0);\n\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.print(Math.max(z,b[1],b[0]));\n\t\t\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab52eb1311a62b528b6b15c253afc12a", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500} {"lang": "Java 8", "source_code": "// \u4f5c\u8005\uff1a\u6768\u6210\u745e\u5148\u751f\nimport java.io.*;\nimport java.util.*;\n\npublic class template {\n\n\tstatic class FastScanner {\n\n static final int DEFAULT_BUFF = 1024, EOF = -1, INT_MIN = 48, INT_MAX = 57;\n static final byte NEG = 45;\n static final int[] ints = new int[58];\n\n static {\n int value = 0;\n for (int i = 48; i < 58; i++) {\n ints[i] = value++;\n }\n }\n\n InputStream stream;\n\n byte[] buff;\n int buffPtr;\n\n public FastScanner(InputStream stream) {\n this.stream = stream;\n this.buff = new byte[DEFAULT_BUFF];\n this.buffPtr = -1;\n }\n\n public int nextInt() throws IOException {\n int val = 0;\n int sign = readNonDigits();\n while (isDigit(buff[buffPtr]) && buff[buffPtr] != EOF) {\n val = (val << 3) + (val << 1) + ints[buff[buffPtr]];\n buffPtr++;\n if (buffPtr == buff.length) {\n updateBuff();\n }\n }\n return val*sign;\n }\n\n private int readNonDigits() throws IOException {\n if (buffPtr == -1 || buffPtr == buff.length) {\n updateBuff();\n }\n if (buff[buffPtr] == EOF) {\n throw new IOException(\"End of stream reached\");\n }\n int signByte = -1;\n while (!isDigit(buff[buffPtr])) {\n signByte = buff[buffPtr];\n buffPtr++;\n if (buffPtr >= buff.length) {\n updateBuff();\n }\n if (buff[buffPtr] == EOF) {\n throw new IOException(\"End of stream reached\");\n }\n }\n if(signByte == NEG) return -1;\n return 1;\n }\n\n public void close() throws IOException {\n stream.close();\n }\n\n private boolean isDigit(int b) {\n return b >= INT_MIN && b <= INT_MAX;\n }\n\n private void updateBuff() throws IOException {\n buffPtr = 0;\n stream.read(buff);\n }\n }\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner(System.in);\n int n = sc.nextInt();\n int[] games = new int[n];\n for(int i=0;i= buff.length) {\n updateBuff();\n }\n if (buff[buffPtr] == EOF) {\n throw new IOException(\"End of stream reached\");\n }\n }\n if(signByte == NEG) return -1;\n return 1;\n }\n\n public void close() throws IOException {\n stream.close();\n }\n\n private boolean isDigit(int b) {\n return b >= INT_MIN && b <= INT_MAX;\n }\n\n private void updateBuff() throws IOException {\n buffPtr = 0;\n stream.read(buff);\n }\n }\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner(System.in);\n int n = sc.nextInt();\n int[] games = new int[n];\n for(int i=0;i= '0' && hour.charAt(0) <= '9') || (hour.charAt(0) >= 'A' && hour.charAt(0) <= 'N')){\n\t\t\t\tSystem.out.println(-1);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(0);\n\t\t\t}\n\t\t}else{\n\t\t\tint max = 0;\n\t\t\tint arr[] = new int[36];\n\t\t\tfor(int j = 0 ; j < 36 ; j++){\n\t\t\t\tarr[j] = j;\n\t\t\t}\n\t\t\tfor(int j = str.length()-1 ; j >= 0 ; j--){\n\t\t\t\tif(str.charAt(j) == ':'){\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(str.charAt(j) >= '0' && str.charAt(j) <= '9'){\n\t\t\t\t\tif(max < arr[Integer.parseInt(str.charAt(j)+\"\")]){\n\t\t\t\t\t\tmax = arr[Integer.parseInt(str.charAt(j)+\"\")];\n\t\t\t\t\t}\n\t\t\t\t}else{\n\t\t\t\t\tint idx = str.charAt(j) - 65 + 10;\n\t\t\t\t\tif(max < arr[idx]){\n\t\t\t\t\t\tmax = arr[idx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmax = max + 1;\n//\t\t\tSystem.out.println(max);\n//\t\t\tSystem.out.println(hour);\n//\t\t\tSystem.out.println(minute);\n\t\t\tint h_flag = 0;\n\t\t\tint m_flag = 0;\n\t\t\tint tmp = max;\n\t\t\tint prev_max = max;\n\t\t\twhile(true){\n\t\t\t\t//System.out.println(\"max : \"+max);\n\t\t\t\tint h_sum = 0;\n\t\t\t\t\n\t\t\t\tfor(int j = hour.length() - 1 ; j >= 0 ; j--){\n\t\t\t\t\tint add = 0;\n//\t\t\t\t\tif(h_sum >= 24){\n//\t\t\t\t\t\th_flag = 1;\n//\t\t\t\t\t\tbreak;\n//\t\t\t\t\t}\n\t\t\t\t\tif(hour.charAt(j) >= '0' && hour.charAt(j) <= '9'){\n\t\t\t\t\t\tadd = Integer.parseInt(hour.charAt(j)+\"\");\n\t\t\t\t\t}else{\n\t\t\t\t\t\tadd = hour.charAt(j) - 65 + 10;\n\t\t\t\t\t}\n\t\t\t\t\tif(h_sum + add*Math.pow(max, hour.length() - 1 - j) >= 24){\n\t\t\t\t\t\th_flag = 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}else{\n\t\t\t\t\t\th_sum += add*Math.pow(max, hour.length() - 1 - j);\n\t\t\t\t\t}\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t//System.out.println(\"h_sum \"+h_sum);\n\t\t\t\tint m_sum = 0;\n\t\t\t\t\n\t\t\t\tfor(int j = minute.length() - 1 ; j >= 0 ; j--){\n\t\t\t\t\tint add = 0;\n\t\t\t\t\tif(minute.charAt(j) >= '0' && minute.charAt(j) <= '9'){\n\t\t\t\t\t\tadd = Integer.parseInt(minute.charAt(j)+\"\");\n\t\t\t\t\t}else{\n\t\t\t\t\t\tadd = minute.charAt(j) - 65 + 10;\n\t\t\t\t\t}\n\t\t\t\t\tif(m_sum + add*Math.pow(max, minute.length() - 1 - j) >= 60){\n\t\t\t\t\t\tm_flag = 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tm_sum += add*Math.pow(max, minute.length() - 1 - j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t//System.out.println(\"m_sum \"+m_sum);\n\t\t\t\t//\n\t\t\t\tif(h_flag == 0 && m_flag == 0){\n\t\t\t\t\tSystem.out.print(max+\" \");\n\t\t\t\t\tmax++;\n\t\t\t\t\t\n\t\t\t\t}else{\n\t\t\t\t\tif(prev_max == max){\n\t\t\t\t\t\tSystem.out.println(0);\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}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1a6ac4bad49cc11e493060643ddfe45f", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class B {\n public static StreamTokenizer in = new StreamTokenizer(System.in);\n public static boolean bg = true;\n\n public static void main(String[] args) throws Exception {\n in = null;\n Scanner scan = new Scanner(System.in);\n String[] l1 = scan.next().split(\":\");\n char[] ll1 = l1[0].toCharArray();\n char[] ll2 = l1[1].toCharArray();\n \n int[] v1 = new int[ll1.length];\n int[] v2 = new int[ll2.length]; \n for (int i=0;i s1 = new HashSet();\n for (int i=1;;i++){\n if (ok(v1,i) ){\n int cur = parse(v1, i);\n if (cur<=23){\n s1.add(i);\n }\n else {\n break;\n }\n }\n }\n \n HashSet s2 = new HashSet();\n for (int i=1;;i++){\n if (ok(v2,i) ){\n int cur = parse(v2, i);\n if (cur<=59){\n s2.add(i);\n }\n else {\n break;\n }\n }\n }\n \n //pn(s1);\n //pn(s2);\n \n s1.retainAll(s2);\n \n ArrayList fin = new ArrayList();\n fin.addAll(s1);\n Collections.sort(fin);\n \n \n if (fin.size()==0){\n pn(0);\n ex();\n }\n \n for (int e: fin){\n p(e+\" \");\n }\n pn(\"\");\n \n \n \n }\n public static boolean check(int[] l1, int[] l2){\n ArrayList f1 = new ArrayList();\n ArrayList f2 = new ArrayList();\n for (int i=0;i=0\n &&c1 - '0'<=9\n ){\n return c1 - '0';\n }\n else return c1 - 'A' + 10;\n }\n private static int ni() throws Exception {\n in.nextToken();\n return (int) in.nval;\n }\n\n private static long nl() throws Exception {\n in.nextToken();\n return (long) in.nval;\n }\n\n private static double nd() throws Exception {\n in.nextToken();\n return in.nval;\n }\n\n private static void pn(Object o1) {\n System.out.println(o1);\n }\n\n private static void p(Object o1) {\n System.out.print(o1);\n }\n\n private static void ex() {\n System.exit(0);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cfd847d697c6537b909256ff039b7c6b", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class B {\n public static StreamTokenizer in = new StreamTokenizer(System.in);\n public static boolean bg = true;\n\n public static void main(String[] args) throws Exception {\n in = null;\n Scanner scan = new Scanner(System.in);\n String[] l1 = scan.next().split(\":\");\n char[] ll1 = l1[0].toCharArray();\n char[] ll2 = l1[1].toCharArray();\n \n int[] v1 = new int[ll1.length];\n int[] v2 = new int[ll2.length]; \n for (int i=0;i s1 = new HashSet();\n for (int i=1;;i++){\n if (ok(v1,i) ){\n int cur = parse(v1, i);\n if (cur<=23){\n s1.add(i);\n }\n else {\n break;\n }\n }\n }\n \n HashSet s2 = new HashSet();\n for (int i=1;;i++){\n if (ok(v2,i) ){\n int cur = parse(v2, i);\n if (cur<=59){\n s2.add(i);\n }\n else {\n break;\n }\n }\n }\n \n //pn(s1);\n //pn(s2);\n \n s1.retainAll(s2);\n \n ArrayList fin = new ArrayList();\n fin.addAll(s1);\n Collections.sort(fin);\n \n \n if (fin.size()==0){\n pn(0);\n ex();\n }\n \n for (int e: fin){\n p(e+\" \");\n }\n pn(\"\");\n \n \n \n }\n public static boolean check(int[] l1, int[] l2){\n ArrayList f1 = new ArrayList();\n ArrayList f2 = new ArrayList();\n for (int i=0;i=0\n &&c1 - '0'<=9\n ){\n return c1 - '0';\n }\n else return c1 - 'A' + 10;\n }\n private static int ni() throws Exception {\n in.nextToken();\n return (int) in.nval;\n }\n\n private static long nl() throws Exception {\n in.nextToken();\n return (long) in.nval;\n }\n\n private static double nd() throws Exception {\n in.nextToken();\n return in.nval;\n }\n\n private static void pn(Object o1) {\n System.out.println(o1);\n }\n\n private static void p(Object o1) {\n System.out.print(o1);\n }\n\n private static void ex() {\n System.exit(0);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "23c85b254d5f8c9de5aff9d93d17951d", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class mar\n{\n void arrange(String a,int p[],int g[],int m)\n{\n int y=0;\nfor(int x=m-1;x>=0;x--)\n{\nchar c=a.charAt(x);\nif(c>=65 && c<=90)\n{\np[y]=c-55;\ng[y]=c-55;\ny++;\n}\nelse\n{\np[y]=c-48;\ng[y]=c-48;\ny++;\n}\n}}\n int mart(int p[],int k,int m)\n{\nint w=1,sum=0,x;\nfor(x=0;xh[0])\n max=g[0];\n else\n max=h[0];\n k=max+1;\n int u=obj.mart(p,k,m);\n int v=obj.mart(q,k,n);\n if(g[0]>23|| u>23 ||v>59)\n System.out.println(0);\n else if(m==1 && n==1)\n System.out.println(-1);\n else if(m==1)\n {\n for(y1=k;t==1;y1++)\n {\n sum=0;w=1;\n for(z=0;z59)\n break;\n } \n for(x=k;x23)\n break;\n }\n for(x=k;x23)\n break;\n }}\n \n if((h[1]!=0 || q[0]==0) && h[0]!=0 )\n {\n for(y1=k;t==1;y1++)\n {\n sum=0;w=1;\n for(z=0;z59)\n break;\n }}\n if(y==-2)\n min=y1;\n else if(y1==-2)\n min =y;\n else if(y= y && chores[i] > x)chores [i] = x;\n time+= chores[i];\n }\n System.out.println(t);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "77d49771606de2d99fb9168e14480854", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800} {"lang": "Java 8", "source_code": " import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static void main (String[] args) throws java.lang.Exception {\n\t Scanner sc=new Scanner(System.in);\n int n=sc.nextInt() , k = sc.nextInt(), x = sc.nextInt();\n int s ;\n for(int i=0 ; i=n-k;i--) {\n ans += Math.min(arr[i],x);\n }\n for(int i=n-k-1;i>=0;i--) {\n ans += arr[i];\n }\n \n out.println(ans);\n }\n \n //<>\n \n static class Reader {\n \n private InputStream mIs;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n \n public Reader() {\n this(System.in);\n }\n \n public Reader(InputStream is) {\n mIs = is;\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 = mIs.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n public String next() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n double nextDouble()\n {\n return Double.parseDouble(next());\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da633bc799ee01f1bedf11f2ae3693ca", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800} {"lang": "Java 8", "source_code": " //package Practice;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\nimport Practice.CodeforcesC.Scanner;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner in=new Scanner(System.in);\n\t\tStringBuilder sb=new StringBuilder();\n\t\tint n=in.nextInt();\n\t\tString s=in.nextLine();\n\t\tint cnt=0;\n\t\tfor(int i=0;i set = new TreeSet<>();\n\t\t\n\t\tint n = sc.nextInt();\n\t\tString s = sc.nextLine();\n\t\t\n\t\tint c = 0;\n\t\tfor(int i = 0;i < n - 1;++i){\n\t\t\tPoint p = new Point(0,0);\n\t\t\tif (s.charAt(i) == 'U')\n\t\t\t\tp.x += 1;\n\t\t\telse if (s.charAt(i) == 'D')\n\t\t\t\tp.x -= 1;\n\t\t\telse if (s.charAt(i) == 'L')\n\t\t\t\tp.y -= 1;\n\t\t\telse\n\t\t\t\tp.y += 1;\n\t\t\t\n\t\n\t\t\tfor(int j = i + 1;j < n;++j){\n\t\t\t\t\n\t\t\t\tif (s.charAt(j) == 'U')\n\t\t\t\t\tp.x += 1;\n\t\t\t\telse if (s.charAt(j) == 'D')\n\t\t\t\t\tp.x -= 1;\n\t\t\t\telse if (s.charAt(j) == 'L')\n\t\t\t\t\tp.y -= 1;\n\t\t\t\telse\n\t\t\t\t\tp.y += 1;\n\t\t\t\t\n\t\t\t\tif (p.x == 0 && p.y == 0){\n\t\t\t\t\t//set.add(new sub(i, j));\n\t\t\t\t\tc++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t//pw.println(set.size());\n\t\tpw.println(c);\n\t\tpw.close();\n\t}\n\n\tstatic class MyScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic MyScanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif (x.charAt(0) == '-') {\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor (int i = start; i < x.length(); i++)\n\t\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t} else {\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e1bb41ede4564f70d5687fd82c15212", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class CDF_762_B {\r\n\r\n public static void main(String[] args) {\r\n \r\n Scanner scanner = new Scanner(System.in);\r\n int testCases = scanner.nextInt();\r\n for(int i=0;i set = new HashSet<>();\r\n\r\n for(int i=1; i*i<=n;i++){\r\n set.add(i*i);\r\n }\r\n for(int i=1; i*i*i<=n;i++){\r\n set.add(i*i*i);\r\n }\r\n return set.size();\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "10f06e6c284a92490a910786ed43dac3", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800} {"lang": "Java 11", "source_code": "import java.util.*;\r\npublic class Solution{\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 int res = (int)Math.sqrt(n)+(int)Math.cubrt(n)-(int)Math.sqrt((int)Math.cubrt(n));\r\n System.out.println(res);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "93a8afb55308e9af0554643b8151bda1", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800} {"lang": "Java 8", "source_code": "import java .util.*;\r\n\r\npublic class SQUARESANDCUBES {\r\n\tpublic static void main(String [] args)\r\n\t{\r\n\t\tScanner in= new Scanner(System.in);\r\n\t\tint n=in.nextInt();\r\n\t\t//in.nextLine();\r\n\t\tlong ar[]=new long[20];\r\n\t\tint i,j;\r\n\t\tdouble f;\r\n\t\tdouble s,c,h;\r\n\t\tfor(i=0;i0){\r\n int n = sc.nextInt();\r\n System.out.println((int)Math.sqrt(n)+(int)Math.cbrt(n)-getCount(n));\r\n\r\n }\r\n }\r\n // Fast Reader Class\r\n public static FastReader sc = new FastReader();\r\n public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\r\n static class FastReader {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n public FastReader() { br = new BufferedReader(new InputStreamReader(System.in));}\r\n String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } }return st.nextToken(); }\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n String nextLine() { String str = \"\"; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }return str; }\r\n }\r\n}\r\n// int n = sc.nextInt(), p = sc.nextInt(), k = sc.nextInt();\r\n// if(p%k<=(n-1)%k){\r\n// n--;\r\n// long ans = (p%k)*((n+k)/k)-((p%k-1)*(p%k))/(2*k);\r\n// System.out.println(ans);\r\n// ans+=(p-(p%k))/k+1;\r\n// System.out.println(ans);\r\n// }else{\r\n// long ans=0;\r\n// n--;\r\n// ans+=(n%k)*(n+k)/k;\r\n// ans+=(p%k-n%k-1)*(((n+k)/k)-1);\r\n// ans+=(p-(p%k))/k+1;\r\n// System.out.println(ans);\r\n// }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6ba1c24eaf68a7e73eae264acc1d5dc0", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.* ;\npublic class contes\n{\n public static void main(String ar[])\n {\n Scanner sc = new Scanner(System.in) ;\n int n = sc.nextInt() ;\n int m = sc.nextInt() ;\n int max = 0 ;\n int sum = 0 ;\n for(int i = 0 ; i ' ');\n if (neg)\n return -ret;\n return ret;\n }\n\n private void fillBuffer() throws Exception {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws Exception {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n }\n public static void main(String[] args) throws Exception {\n Parser aa=new Parser(System.in);\n int x=aa.nextLong();\n int y=aa.nextLong();\n int val;\n int t=0;\n while(true) {\n //System.out.println(x+\" \"+y);\n if(t==0) {\n val=x*100+y*10;\n if(val<220){\n System.out.println(\"Hanako\"); return;\n }\n int mx=Math.min(x,2);\n x-=mx;\n int rem=220-mx*100;\n int my=rem/10;\n if(my>y){\n System.out.println(\"Hanako\"); return;\n }\n y-=my;\n t=1;\n }\n else {\n val=x*100+y*10;\n if(val<220){\n System.out.println(\"Ciel\"); return;\n }\n int my;\n if(y>=12) {\n my=12;\n }else if(y>=2) {\n my=2;\n }\n else {\n System.out.println(\"Ciel\"); return;\n }\n y-=my;\n int rem=220-my*10;\n int mx=rem/100;\n x-=mx;\n t=0;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d6e5a610efd9d9d2f125ec25e7704817", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200} {"lang": "Java 7", "source_code": "public class Code {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws Exception {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int m=s.nextInt();\n \n while(true){\n int f=0,f1=0;\n if(n*100+m*10<220 ||m<2){\n System.out.println(\"Hanako\");\n System.exit(0);}\n else if (n>=2)\n {\n n-=2;m-=2; }\n else if(n>0){\n n-=1;m-=12;\n }\n else\n {m-=22;}\n if(n*100+m*10<220 ||m<2){\n System.out.println(\"Ceil\");\n System.exit(0);}\n else if(m>=22)\n {m-=22;}\n else if(m>=12 && m<22)\n {m-=12;n-=1;}\n else {\n n-=2;m-=2;}\n\n }\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0c99b9c771db3a015cd24e62fc3bb2f6", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200} {"lang": "Java 7", "source_code": "public class Code {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws Exception {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int m=s.nextInt();\n int x[]=new int[n];\n int y[]=new int[m]; \n for(int i=0;i n) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n\n return k - left + 2;\n }\n\n static long sum(long left, long right) {\n long s = 0;\n if (left <= right) {\n s = sum(right) - sum(left - 1);\n }\n return s;\n }\n\n static long sum(long k) {\n return k * (k + 1) / 2;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n long k = in.nextLong();\n if (n == 1) {\n System.out.println(0);\n } else if (k >= n) {\n System.out.println(1);\n } else {\n n -= 1;\n k -= 1;\n\n if (sum(k) < n) {\n System.out.println(-1);\n } else {\n\n System.out.println(sumOfPipes(n, k));\n\n }\n }\n }\n}\nPipeline.txt\nDisplaying Pipeline.txt.", "lang_cluster": "Java", "compilation_error": true, "code_uid": "94d152dd59135457f94958e900bbe45c", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.math.BigInteger;\npublic class B \n{\n public static void main(String[] args) \n {\n Scanner sc = new Scanner(System.in);\n BigInteger bi1 = sc.nextBigInteger();\n BigInteger bi2 = sc.nextBigInteger();\n BigInteger i=1;\n BigInteger sum=1;\n for(i=1;ibi1){\n System.out.println(i.add(BigInteger.valueOf(-1)));\n break;\n }\n }\n if(sumN+1){E=2;Bol(E,L);System.out.println(L+1-E);}\n else if (K==N||K==N+1){System.out.println(L-1);}\n else {System.out.println(-1);}}\n private static void Bol(long Star , long End)\n {long mid = (Star+End)/2;E=Star;\n if(K/N>=1&&K-NN){if(Star+End%2!=0&&Star+1==End){mid++;}E=mid;}\n else {E=(Star+s)/2;}\n if((Q-E+1)%2!=0){K=((Q+E-2)*((Q+1-E)/2))+((Q+E)/2);if((Q+E)%2!=0)K++;}\n else{K=((Q+E-2)*((Q+1-E)/2));K++;}if(K>N){s=E;}Bol(E,Q);}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e5914bc72f8d9482b4b8c707fc7ab099", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String s = in.next();\n String res = \"\";\n for (int i = 0; i < s.length(); i++) {\n switch(s.charAt(i)){\n case '>': res+= \"1000\";\n break;\n case '<': res+= \"1001\";\n break;\n case '+': res+= \"1010\";\n break;\n case '-': res+= \"1011\";\n break;\n case '.': res+= \"1100\";\n break;\n case ',': res+= \"1101\";\n break;\n case '[': res+= \"1110\";\n break;\n case ']': res+= \"1111\";\n break;\n \n }\n }\n int sum = 0;\n for (int i = 0; i < res.length(); i++) {\n sum = sum *2 + res.charAt(i)-'0';\n sum %= 1000003;\n }\n System.out.println(sum);\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca330022d75c938f9d182c4d692de655", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n\n//codeforce\npublic class codeforcet{\n\n private static BufferedReader in;\n private static PrintWriter out;\n private static StringTokenizer input;\n\n \n \n public static void main(String[] args) throws IOException {\n //--------------------------------\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n\n//codeforce\npublic class codeforcet{\n\n private static BufferedReader in;\n private static PrintWriter out;\n private static StringTokenizer input;\n\n \n \n public static void main(String[] args) throws IOException {\n //-------------------------------------------------------------------------\n //Initializing...\n new codeforcet();\n //-------------------------------------------------------------------------\n //put your code here... :)\n String n=nextString();\n String y=\"\";\n for (int i = 0; i < n.length(); i++) {\n if(n.charAt(i)=='+'){\n y=y+\"1010\";\n }else if(n.charAt(i)=='-'){\n y=y+\"1011\";\n }else if(n.charAt(i)=='<'){\n y=y+\"1001\";\n }else if(n.charAt(i)=='>'){\n y=y+\"1000\";\n }else if(n.charAt(i)==']'){\n y=y+\"1111\";\n }else if(n.charAt(i)=='['){\n y=y+\"1110\";\n }else if(n.charAt(i)==','){\n y=y+\"1101\";\n }else if(n.charAt(i)=='.'){\n y=y+\"1100\";\n }\n }\n int d=0;\n// for (int i = 0; i < y.length(); i++) {\n// int t=((int)y.charAt(i))-48;\n// if(t==1){\n// d+=Math.pow(2, y.length()-i-1);\n// }\n// }\n BigInteger res = new BigInteger(y,2);\n BigInteger m=new BigInteger(\"1000003\"); \n System.out.println(res.mod(m));\n// int y1=Integer.parseInt(y,2);\n//\n// System.out.println(y1%1000003);\n //writeln(\"\");\n //-------------------------------------------------------------------------\n //closing up\n end();\n //--------------------------------------------------------------------------\n\n }\n private static String nextString() throws IOException {\n if (!input.hasMoreTokens())\n input = new StringTokenizer(in.readLine());\n return input.nextToken();\n }\n public codeforcet() throws IOException {\n //Input Output for Console to be used for trying the test samples of the problem\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //-------------------------------------------------------------------------\n //Initalize Stringtokenizer input\n input = new StringTokenizer(in.readLine());\n }\n\n private static int nextInt() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Integer.parseInt(input.nextToken());\n }\n\n private static void end() throws IOException{\n in.close();\n out.close();\n System.exit(0);\n }\n\n\n\n}\n-----------------------------------------\n //Initializing...\n new codeforcet();\n //-------------------------------------------------------------------------\n //put your code here... :)\n String n=nextString();\n String y=\"\";\n for (int i = 0; i < n.length(); i++) {\n if(n.charAt(i)=='+'){\n y=y+\"1010\";\n }else if(n.charAt(i)=='-'){\n y=y+\"1011\";\n }else if(n.charAt(i)=='<'){\n y=y+\"1001\";\n }else if(n.charAt(i)=='>'){\n y=y+\"1000\";\n }else if(n.charAt(i)==']'){\n y=y+\"1111\";\n }else if(n.charAt(i)=='['){\n y=y+\"1110\";\n }else if(n.charAt(i)==','){\n y=y+\"1101\";\n }else if(n.charAt(i)=='.'){\n y=y+\"1100\";\n }\n }\n int d=0;\n// for (int i = 0; i < y.length(); i++) {\n// int t=((int)y.charAt(i))-48;\n// if(t==1){\n// d+=Math.pow(2, y.length()-i-1);\n// }\n// }\n BigInteger res = new BigInteger(y,2);\n System.out.println(res);\n// int y1=Integer.parseInt(y,2);\n//\n// System.out.println(y1%1000003);\n //writeln(\"\");\n //-------------------------------------------------------------------------\n //closing up\n end();\n //--------------------------------------------------------------------------\n\n }\n private static String nextString() throws IOException {\n if (!input.hasMoreTokens())\n input = new StringTokenizer(in.readLine());\n return input.nextToken();\n }\n public codeforcet() throws IOException {\n //Input Output for Console to be used for trying the test samples of the problem\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //-------------------------------------------------------------------------\n //Initalize Stringtokenizer input\n input = new StringTokenizer(in.readLine());\n }\n\n private static int nextInt() throws IOException {\n if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());\n return Integer.parseInt(input.nextToken());\n }\n\n private static void end() throws IOException{\n in.close();\n out.close();\n System.exit(0);\n }\n\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a814ff7b71594d64dd57ac3a7ebce67f", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.PrintWriter;\nimport java.io.IOException;\npublic class Unary\n{\n static int func(char ch)\n {\n switch(ch)\n {\n case '>': return 8;\n case '<': return 9;\n case '+': return 10;\n case '-': return 11;\n case '.': return 12;\n case ',': return 13;\n case '[': return 14;\n case ']': return 15;\n default: return 0;\n }\n }\n public static void main(String args[]) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String s = br.nextLine();\n int i,size = 0;\n for(i = 0;i < s.length(); ++i)\n {\n size = size * 16 + func(s.charAt(i)) % 1000003; \n }\n PrintWriter pr = new PrintWriter(System.out);\n pr.println(size);\n pr.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e4c41204e896b8d0fed20b261e04164b", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.PrintWriter;\nimport java.io.IOException;\npublic class Unary\n{\n static int func(char ch)\n {\n switch(ch)\n {\n case '>': return 8;\n case '<': return 9;\n case '+': return 10;\n case '-': return 11;\n case '.': return 12;\n case ',': return 13;\n case '[': return 14;\n case ']': return 15;\n default: return 0;\n }\n }\n public static void main(String args[]) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String s = br.ReadLine();\n int i,size = 0;\n for(i = 0;i < s.length(); ++i)\n {\n size = size * 16 + func(s.charAt(i)) % 1000003; \n }\n PrintWriter pr = new PrintWriter(System.out);\n pr.println(size);\n pr.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da76cc9bc8064f5f1b12c97a98f61cf8", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200} {"lang": "Java 7", "source_code": "import java.util.*;public class Main { static Scanner reader = new Scanner(System.in);static void main(String[] args) {\n int f = reader.nextInt(), i = reader.nextInt(), t = reader.nextInt(), output = 0;//kitten\n int[] likes = new int[i];\n for (int j = 0; j < f; j++) { = reader.next();\n for (int k = 0; k < i; k++)\n if (input.charAt(k) == 'Y')\n likes[k]++;\n } j = 0; j < i; j++)\n if (likes[j] >= t)\n output++;\n System.out.println(output);", "lang_cluster": "Java", "compilation_error": true, "code_uid": "27b85453ae5274dcf5ccad41450b93e8", "src_uid": "4c978130187e8ae6ca013d3f781b064e", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class ga1 {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n\t\tint r = scanner.nextInt();\n\t\tint t = scanner.nextInt();\n scanner.nextLine();\n\t\t//\n\t\tint a[] = new int[r];\n String s = new String;\n for(int i = 0; i < n; i++){\n s = scanner.nextLine();\n\t\t\tfor(int j = 0; j < r; j++){\n\t\t\t\tif(s.charAt(j) == 'Y'){\n\t\t\t\t a[j]++;\n\t\t\t\t}\n\t\t\t}\n }\n\t\tint k = 0 ;\n for(int i = 0; i < r; i ++){\n\t\t\tif(a[i] >= t){\n\t\t\t\tk++;\n\t\t\t}\n }\n System.out.println(k);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3a7f86fbe20cafd8706036680c4dd05a", "src_uid": "4c978130187e8ae6ca013d3f781b064e", "difficulty": 1900} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\n/**\n * Created by Arthur on 3/14/2015.\n */\npublic class Main {\n\n AtomScanner sc;\n PrintWriter pw;\n\n public Main(AtomScanner sc, PrintWriter pw) {\n this.sc = sc;\n this.pw = pw;\n solve();\n close();\n }\n\n public static void main(String[] args) {\n new Main(new AtomScanner(System.in), new PrintWriter(System.out));\n }\n\n private void close() {\n sc.close();\n pw.close();\n }\n\n private void solveE() {\n int n = sc.nextInt();\n\n }\n\n private void solve() {\n int f, c, t;\n f = sc.nextInt();\n c = sc.nextInt();\n t = sc.nextInt();\n char[][] cc = new char[f][c];\n for (int i = 0; i < f; i++) {\n for (int j = 0; j < c; j++) {\n cc[i][j] = sc.nextChar();\n }\n }\n int ans = 0;\n for (int i = 0; i < c; i++) {\n int cnt = 0;\n for (int j = 0; j < f; j++) if (cc[j][i] == 'Y') cnt++;\n if (cnt >= t) ans++;\n }\n pw.println(ans);\n }\n}\n//adsfsadfasdfs\nclass Pi implements Comparable {\n\n int f, s;\n\n Pi(int f, int s) {\n this.f = f;\n this.s = s;\n }\n\n @Override\n public int compareTo(Pi pi) {\n if (f > pi.f) return 1;\n if (f < pi.f) return -1;\n if (s > pi.s) return 1;\n return s == pi.s ? 0 : -1;\n }\n\n @Override\n public String toString() {\n return f + \" \" + s;\n }\n}\n\nclass Pl implements Comparable {\n\n long f, s;\n\n Pl(long f, long s) {\n this.f = f;\n this.s = s;\n }\n\n Pl() {\n this(0, 0);\n }\n\n @Override\n public int compareTo(Pl pl) {\n if (f > pl.f) return 1;\n if (f < pl.f) return -1;\n if (s > pl.s) return 1;\n return s == pl.s ? 0 : -1;\n }\n\n @Override\n public String toString() {\n return \"(\" + f + \"; \" + s + \")\";\n }\n}\n\nclass Pair {\n F first;\n S second;\n\n Pair(F first, S second) {\n this.first = first;\n this.second = second;\n }\n\n public int hashCode() {\n int hashFirst = first != null ? first.hashCode() : 0;\n int hashSecond = second != null ? second.hashCode() : 0;\n\n return (hashFirst + hashSecond) * hashSecond + hashFirst;\n }\n\n public boolean equals(Object other) {\n if (other instanceof Pair) {\n Pair otherPair = (Pair) other;\n return\n ((this.first == otherPair.first ||\n (this.first != null && otherPair.first != null &&\n this.first.equals(otherPair.first))) &&\n (this.second == otherPair.second ||\n (this.second != null && otherPair.second != null &&\n this.second.equals(otherPair.second))));\n }\n\n return false;\n }\n\n public static ArrayList>> groupsPairs (ArrayList> pairs) {\n ArrayList>> result = new ArrayList<>();\n pairs.stream().sorted(Pair::compare).forEach(pair -> {\n if (result.isEmpty() || !pair.first.equals(result.get(result.size() - 1).first)) {\n result.add(new Pair<>(pair.first, new ArrayList<>()));\n }\n result.get(result.size() - 1).second.add(pair.second);\n });\n return result;\n }\n\n public static int compare (Pair a, Pair b) {\n return a.first.compareTo(b.first) != 0 ? a.first.compareTo(b.first) : a.second.compareTo(b.second);\n }\n}\n\nclass AtomScanner {\n\n final static int BUFFER_SIZE = 65536;\n\n BufferedReader br;\n char[] buf = new char[BUFFER_SIZE];\n int len = 0;\n int it = 0;\n boolean end = false;\n\n boolean delim(char c) {\n return c == ' ' || c == '\\n' || c == '\\r';\n }\n\n void fillBuffer() {\n try {\n len = br.read(buf);\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n void ensureBuffer() {\n if (it == len) {\n it = 0;\n fillBuffer();\n if (len == -1) end = true;\n }\n }\n\n void moveNext() {\n while (!end) {\n ensureBuffer();\n if (!delim(buf[it])) return;\n while (it < len && delim(buf[it])) it++;\n }\n }\n\n char nextChar() {\n moveNext();\n if (end) throw new NullPointerException(\"End was reached\");\n return buf[it++];\n }\n\n String next() {\n moveNext();\n StringBuilder sb = new StringBuilder();\n while (!end) {\n int l = it;\n while (++it < len && !delim(buf[it]));\n sb.append(buf, l, it - l);\n ensureBuffer();\n if (delim(buf[it])) break;\n }\n return sb.toString();\n }\n\n int nextInt() {\n moveNext();\n boolean e = false;\n if (buf[it] == '-') {\n e = true;\n it++;\n ensureBuffer();\n }\n int result = 0;\n while (!end) {\n int l = it;\n while (it < len && !delim(buf[it])) {\n result = (result * 10) + buf[it] - '0';\n it++;\n }\n ensureBuffer();\n if (end || delim(buf[it])) break;\n }\n if (e) result *= -1;\n return result;\n }\n long nextLong() {\n moveNext();\n long result = 0;\n while (!end) {\n int l = it;\n while (it < len && !delim(buf[it])) {\n result = (result * 10) + buf[it] - '0';\n it++;\n }\n ensureBuffer();\n if (delim(buf[it])) break;\n }\n return result;\n }\n\n AtomScanner(String file) {\n try {\n br = new BufferedReader(new FileReader(file), BUFFER_SIZE);\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n AtomScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is), BUFFER_SIZE);\n }\n\n public void close() {\n try {\n br.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "56d0f4a1914099bfa6c4cbca7f191ad9", "src_uid": "4c978130187e8ae6ca013d3f781b064e", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class A {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(),\n m = in.nextInt(),\n t = in.nextInt(),\n ans = 0,\n i = 0, j;\n int[] res = new int[m];\n for (; i < n; ++i) {\n String s = in.next();\n for (j = 0; j < m; ++j)\n if (s.charAt(j) == 'Y')\n ++res[j];\n for (i = 0; i < m; ++i)\n if (res[i] >= t)\n ++ans;\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d7fd98b14bfff909550408f35d8eefb9", "src_uid": "4c978130187e8ae6ca013d3f781b064e", "difficulty": 1900} {"lang": "Java 6", "source_code": "import java.io.*;import java.util.*;public class B { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); String s=r.readLine(); int m=Integer.parseInt(s); boolean[][] adj=new boolean[5][5]; while(m-->0){ s=r.readLine(); String[]sp=s.split(\" \"); int from=new Integer(sp[0])-1; int to=new Integer(sp[1])-1; adj[from][to]=true; adj[to][from]=true; } for (int i = 0; i < adj.length; i++) { for (int j = i+1; j < adj.length; j++) { for (int k = j+1; k < adj.length; k++) { if(adj[i][j]&&adj[i][k]&&adj[j][k]){ System.out.println(\"WIN\"); return; } if(!adj[i][j]&&!adj[i][k]&&!adj[j][k]){ System.out.println(\"WIN\"); return; } } } } System.out.println(\"FAIL\"); }}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0100f02eefc0a6fe63bb42178598e7a5", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n \npublic class Main {\n \n\tprivate static BufferedReader input;\t// \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd-\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\tprivate static PrintWriter output;\t// \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\tprivate static StreamTokenizer stoken;\t// \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd. \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd - \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n \n\tstatic String fin = \"input\";\n\tstatic String fout = \"output\";\n\t\n\tprivate static void solve() throws IOException{\n\t\tint n = nextInt();\n\t\tint[] mas = new int[5];\n\t\tfor (int i = 0; i=3){\n\t\t\t\tkey = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (key){\n\t\t\toutput.print('WIN');\n\t\t}else{\n\t\t\toutput.print('FAIL');\n\t\t}\n\t}\n \n \n\tpublic static void main(String[] args) throws IOException {\n\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\toutput = new PrintWriter(System.out);\n \n\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t//input = new BufferedReader(new FileReader(fin + \".txt\"));\n\t\t//output = new PrintWriter(new FileWriter(fout + \".txt\"));\n \n\t\tstoken = new StreamTokenizer(input);\n \n \n\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\tsolve();\n \n \n\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n\t\tinput.close();\n\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\toutput.flush();\n\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n\t\toutput.close();\n\t}\n \n \n\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd 32-\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n\tprivate static int nextInt() throws IOException {\n\t\treturn (int) nextDouble();\n\t}\n \n\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd 64-\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n\tprivate static long nextLong() throws IOException {\n\t\treturn (long) nextDouble();\n\t}\n \n\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd 64-\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\n\tprivate static double nextDouble() throws IOException {\n\t\tstoken.nextToken();\n\t\treturn stoken.nval;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fb604936c1cb2ba45e4d4d2c04a5c43a", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300} {"lang": "Java 8", "source_code": " import java.io.BufferedReader;\n import java.io.InputStreamReader;\n import java.io.IOException;\n\n public class Friends {\n\n public static void main(String args[]) throws IOException {\n InputStreamReader isr = new InputStreamReader(System.in);\n BufferedReader br = new BufferedReader(isr);\n List acquaintance = new ArrayList();\n int m;\n String result = \"FAIL\";\n\n m = Integer.parseInt(br.readLine());\n\n for (int i=0; i<6; i++) {\n acquaintance.add(new HashSet());\n }\n\n for (int i=0; i \" + ij + \", \" + ik + \", \" + jk + \" |\\t\" + temp);\n if ((ij && ik && jk) || (!ij && !ik && !jk)) {\n result = \"WIN\";\n break;\n }\n }\n if (result.equals(\"WIN\")){\n break;\n }\n }\n if (result.equals(\"WIN\")) {\n break;\n }\n }\n System.out.println(result);\n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea7f21922d7b8c816a9f5c18234eec07", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300} {"lang": "Java 6", "source_code": "import sun.security.krb5.internal.KdcErrException;\nimport sun.text.normalizer.Trie;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Friends {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n //BufferedReader br = new BufferedReader(new FileReader(\"A.txt\"));\n int m = Integer.parseInt(br.readLine());\n boolean[][] isFriend = new boolean[5][5];\n for(int i = 0; i < m; ++i) {\n StringTokenizer st = new StringTokenizer(br.readLine());\n int x = Integer.parseInt(st.nextToken());\n int y = Integer.parseInt(st.nextToken());\n isFriend[x-1][y-1] = isFriend[y-1][x-1] = true;\n }\n\n boolean win = false;\n for(int mask = 0; mask < (1 << 5); ++mask) {\n if(Integer.bitCount(mask) == 3) {\n int[] bits = new int[3];\n int k = 0;\n for(int i = 0; i < 5; ++i) {\n if((mask & (1 << i)) != 0) {\n bits[k] = i;\n ++k;\n }\n }\n if(isFriend[bits[0]][bits[1]] && isFriend[bits[1]][bits[2]] && isFriend[bits[2]][bits[0]]) {\n System.out.println(\"WIN\");\n win = true;\n break;\n }\n if(!isFriend[bits[0]][bits[1]] && !isFriend[bits[1]][bits[2]] && !isFriend[bits[2]][bits[0]]) {\n System.out.println(\"WIN\");\n win = true;\n break;\n }\n }\n }\n if(!win)\n System.out.println(\"FAIL\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "875271a2b861c7dbfb2b3426b216897d", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class name\n{\n public static void main(String[]args)throws IOException\n {\n Scanner sc=new Scanner(System.in);\n int n;\n float c;\n n=sc.nextInt();\n c=Math.ceil(n/5);\n System.out.println((int)c);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5a4f80e94dfa45e966f1cdd8cbe3b959", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.lang.Math;\n/**\n *\n * @author admin\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner ab = new Scanner(System.in);\n \n int dd = ab.nextInt();\n \n }\n \ndouble e = Math.floor(dd/5);\n\nint f = (int) e +1;\n\nSystem.out.print(f);\n \n \n \n \n \n \n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f9bffd1257e8403b5bdbab6688227012", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800} {"lang": "Java 8", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\npackage elefante;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author PC\n */\npublic class Elefante {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n //int n;\n\t\tint n = in.nextInt();\n //n = 13;\n \n //if (1< n && n < 1000000){\n\t\tif (1<= n && n < = 1000000){\t\n int a;\n if (n % 5 == 0) {\n //System.out.println(\"entro a par\");\n a = 0;\n }else\n {\n //System.out.println(\"entro a impar\");\n a=1;\n }\n\t\t\t\n a=a+n/5;\n \n System.out.println(a);\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7d94fb590dcc016f879b332d80386f7e", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class MyClass {\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n int n;\n n = in.nextInt();\n if(n % 5 == 0) {\n System.out.println(n/5);\n } else if(n % 5 != 0) {\n System.out.println((n/5) + 1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2c72f82e46b93942e1ef401be6ff1504", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800} {"lang": "Java 8", "source_code": "public class Main{\n public static void main (String args[]) {\n Scanner sc =new Scanner(System.in);\n int x1=sc.nextInt();\n int y1=sc.nextInt();\n int x2=sc.nextInt();\n int y2=sc.nextInt();\n System.out.println((1+(y2-y1)/2)*(1+(x2-x1)/2)+((y2-y1)/2)*((x2-x1)/2));\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d0e9cf34917886c620071c325c24c40b", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.utils.*;\n\n public class Main{\n public static void main (String args[]) {\n Scanner sc =new Scanner(System.in);\n int x1=sc.nextInt();\n int y1=sc.nextInt();\n int x2=sc.nextInt();\n int y2=sc.nextInt();\n System.out.println((1+(y2-y1)/2)*(1+(x2-x1)/2)+((y2-y1)/2)*((x2-x1)/2));\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "373be3aea7a685cb60bef49800a57a37", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900} {"lang": "Java 8", "source_code": "public class Main{\n public static void main (String args[] {\n int x1=sc.nextInt();\n int y1=sc.nextInt();\n int x2=sc.nextInt();\n int y2=sc.nextInt();\n System.out.println((1+(y2-y1)/2)*(1+(x2-x1)/2)+((y2-y1)/2)*((x2-x1)/2));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a4ada63a8a6305f08fdb9d456efdcdd1", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class E {\n\t\n\tpublic static boolean is_center(final long x, final long y){\n\t\tfinal long x_sign = Math.abs(x) % 2;\n\t\tfinal long y_sign = Math.abs(y) % 2;\n\t\t\n\t\treturn x_sign == y_sign;\n\t}\n\t\n\tpublic static long calc_y_size(final long x, long y1, long y2){\n\t\tif(x % 2 == 0){\n\t\t\tif(y1 % 2 == 0){ y1--; }\n\t\t\tif(y2 % 2 == 0){ y2++; }\n\t\t\t\n\t\t\treturn (y2 - y1) / 2;\n\t\t}else{\n\t\t\tif(y1 % 2 == 1){ y1--; }\n\t\t\tif(y2 % 2 == 1){ y2++; }\n\n\t\t\treturn (y2 - y1) / 2;\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\ttry (final Scanner sc = new Scanner(System.in)) {\n\t\t\tfinal long x1 = sc.nextLong();\n\t\t\tfinal long y1 = sc.nextLong();\n\t\t\tfinal long x2 = sc.nextLong();\n\t\t\tfinal long y2 = sc.nextLong();\n\t\t\t\n\t\t\tif(x1 == x2){\n\t\t\t\tSystem.out.println(calc_y_size(x1, y1, y2));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tfinal long x1_y_size = calc_y_size(x1, y1, y2);\n\t\t\tfinal long x1_1_y_size = calc_y_size(x1 + 1 + 1, y2, y2);\n\t\t\t\n\t\t\tSystem.out.println(x1_y_size * (x2 - x1) / 2 + x1_1_y_size * ((x2 - x1) - ((x2 - x1) / 2));\n\t\t\t\n\t\t\tlong answer = 0;\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\tSystem.out.println(answer);\n\t\t}\n\t}\n\n\tpublic static class Scanner implements Closeable {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer tok;\n\n\t\tpublic Scanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t}\n\n\t\tprivate void getLine() {\n\t\t\ttry {\n\t\t\t\twhile (!hasNext()) {\n\t\t\t\t\ttok = new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t} catch (IOException e) { /* ignore */\n\t\t\t}\n\t\t}\n\n\t\tprivate boolean hasNext() {\n\t\t\treturn tok != null && tok.hasMoreTokens();\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tgetLine();\n\t\t\treturn tok.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 void close() {\n\t\t\ttry {\n\t\t\t\tbr.close();\n\t\t\t} catch (IOException e) { /* ignore */\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b0455faa54d8033720aaa7bda4d0de76", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n long k = r.nextInt();\n long b = r.nextInt();\n \n long n = r.nextInt();\n long t = r.nextInt();\n\n int counter = 0;\n long curr = 1;\n while(true){\n if(t == curr){\n System.out.println(Math.max(0, n - counter));\n return;\n }else if(curr > t){\n System.out.println(Math.max(0, 1 + n - counter));\n return;\n }\n \n curr = k * curr + b; \n cnt++;\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "525e47e2fea443ae93073f59cb033c13", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n\tpublic static void main (String[]args)\n\t{\n\t\t\tScanner scan = new Scanner (new BufferedInputStream (System.in));\n\t\t\t//int tc = scan.nextInt();\n\n\t\t\t//for(int i=0;im)\n\t\t\t\t\t{\n\t\t\t\t\t\tSystem.out.println(\"Case #\"+(i+1)+\": \"+(n-j));\n\t\t\t\t\t\tflag=1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif(flag==0)\n\t\t\t\t\tSystem.out.println(\"Case #\"+(i+1)+\": 0\");\n\n\t\t//\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e37cd829ac69f6b811bad176defe9e7a", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700} {"lang": "Java 6", "source_code": "public class N4_CF_199C {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long k = in.nextInt(), b = in.nextInt(), n = in.nextInt(), t = in\n .nextInt();\n long z = 0;\n if (k == 1) {\n z = 1l + n * b;\n long zt = t + n * b;\n while (zt > z && n > -1) {\n n--;\n zt = t + n * b;\n }\n System.out.println((n + 1));\n } else {\n long p = (long) Math.pow(k, n);\n z = p + b * ((1 - p) / (1l - k));\n long zt = p * t + b * ((1 - p) / (1l - k));\n while (zt > z && n > -1) {\n n--;\n p = (long) Math.pow(k, n);\n zt = p * t + b * ((1 - p) / (1l - k));\n }\n System.out.println((n + 1));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8abe7e48cd7d704aebae4862ab545a94", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Contest1_1{\n \n public static void main(String ar[]) throws Exception { \n \n BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tok = new StringTokenizer(buff.readLine());\n BigInteger k = new BigInteger(tok.nextToken());\n BigInteger b = new BigInteger(tok.nextToken());\n int n = Integer.parseInt(tok.nextToken());\n BigInteger t = new BigInteger(toak.nextToken());\n BigInteger z = new BigInteger(\"1\");\n for(int i =0;i 0) break;\n\n p += d;\n answ += t1;\n if (p == s){\n d = -1;\n }else if (p == 0){\n d = 1;\n }\n }\n out.print(Math.min(answ0, answ));\n out.flush();\n }\n\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "91672b907fd5556a77bfaa36f0a1d4ac", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class CF746C{ \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 s = in.nextInt(), x = in.nextInt(), y = in.nextInt();\n int t1 = in.nextInt(), t2 = in.nextInt();\n int p = in.nextInt(), d = in.nextInt();\n \n int min = Math.abs(y-x)*t2;\n \n \n for(int i = 0; i <= s; i++){\n int dd = Math.abs(i-x);\n int t = dd*t2;\n \n int tempD = d;\n int tempP = p;\n int tempT = 0;\n \n \n while(tempP != i || tempT < t){\n if(tempP == 0 || tempP == s){\n if(tempD == 1) tempD = -1;\n else tempD = 1;\n }\n if(tempD == 1) tempP++;\n else tempP--;\n \n tempT += t1;\n //System.out.println(i+\" \"+tempP+\" \"+tempD);\n \n }\n \n int remD = Math.abs(y - tempP);\n \n if(tempD == 1 && tempP < y){\n remD = Math.abs(y-tempP);\n }\n else if(tempD == 1 && tempP > y){\n remD = Math.abs(s-tempP) + Math.abs(s-y);\n }\n if(tempD == -1 && tempP > y){\n remD = Math.abs(y-tempP);\n }\n else if(tempD == -1 && tempP < y){\n remD = tempP + y;\n }\n \n int curT = remD*t1 + tempT;\n \n //System.err.println(i+\" \"+curT+\" \"+remD+\" \"+tempT);\n \n min = Math.min(curT, min);\n \n }\n \n \n \n \n pw.println(min);\n \n pw.close();\n }\n \n// static class Node{\n// public int a, r;\n// public Node(int aa, int rr){\n// a = aa; r = rr;\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));\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1eb51a4fb4c6c8d19243ae5be7397df6", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\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 final int oo = (int)1e9;\n\tstatic int M = 105;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tint s = in.nextInt();\n\t\tint x1 = in.nextInt();\n\t\tint x2 = in.nextInt();\n\t\t\n\t\tint t1 = in.nextInt();\n\t\tint t2 = in.nextInt();\n\t\t\n\t\tint p = in.nextInt();\n\t\tint d = in.nextInt();\n\t\t\n\t\tint dist = Math.abs(x2 - x1);\n\t\tint distb = 0;\n\t\tint l, r;\n\t\twhile(true) {\n\t\t\tif(p == x2) {\n\t\t\t\tif(d == 1) {\n\t\t\t\t\tl = x2; \n\t\t\t\t\tr = s;\n\t\t\t\t\tdistb += (s - x2) * 2;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tl = 0;\n\t\t\t\t\tr = x2;\n\t\t\t\t\tdistb += 2 * x2;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif( Integer.signum(x2 - p) == Integer.signum(d) ) {\n\t\t\t\t\tl = Math.min(x2, p);\n\t\t\t\t\tr = Math.max(x2, p);\n\t\t\t\t\tdistb += Math.abs(x2 - p);\n\t\t\t\t}\n\t\t\t\telse if(d == -1) {\n\t\t\t\t\tl = 0;\n\t\t\t\t\tr = x2;\n\t\t\t\t\tdistb += (p + x2);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tl = x2;\n\t\t\t\t\tr = s;\n\t\t\t\t\tdistb += (2 * s - p - x2);\n\t\t\t\t}\n\t\t\t\tp = x2;\n\t\t\t}\n\t\t\tif(l <= x1 && x1 <= r)\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tint ans = Math.min( dist * t2, distb * t1 );\n\t\tSystem.out.println(ans);\n\t\t\n\t\tout.close();\n\t}\n\t\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}\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cc547bc7ef1f40c27e694eb54e31409e", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600} {"lang": "Java 8", "source_code": "//package codeforce;\n\nimport java.util.Scanner;\n\npublic class Div2R386C {\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint s = scan.nextInt();\n\t\tint x1 = scan.nextInt(), x2 = scan.nextInt();\n\t\tdouble v1 = (double)1/(scan.nextInt()), v2 = (double)1/(scan.nextInt());\n\t\t//System.out.println(v1 + \" \" + v2);\n\t\t\n\t\tint p = scan.nextInt(), d = scan.nextInt();\n\t\tint i_d = -1, end = 0;\n\t\tif(x1 < x2) {i_d = 1;}\n\t\tif(d == 1) end = s;\n\t\tint path = 0;\n\t\twhile(Math.signum((double)x1 - p) != Math.signum((double)i_d) || i_d != d){\n\t\t\tpath += Math.abs(p - end);\n\t\t\tp = end;\n\t\t\tend = s - end;\n\t\t\td = -d;\n\t\t}\n\t\tpath += Math.abs(x1-p);\n\t\tdouble distance = Math.abs(x1- x2);\n\t\tdouble time_to_catch = path/Math.abs(v1- v2);\n\t\tlong ans = 0;\n\t\tif(time_to_catch * v2 >= distance || v1 <= v2){\n\t\t\tans = Math.round(distance/v2);\n\t\t} else {\n\t\t\tans = Math.round(time_to_catch + (distance - time_to_catch*v2)/v1);\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "82c20de93e3c9a0c1a3623a3e88a6001", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600} {"lang": "Java 8", "source_code": "public class CodeForce{\n\n public static void main(String[] args) throws Exception{\n BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));\n\n String Sn=buffer.readLine();\n String Sa=buffer.readLine();\n int n=Integer.parseInt(Sn);\n int a=Integer.parseInt(Sa);\n int count=1;\n if(!((1<=a) && (a<=n) && n<=100000)) {System.out.println(\"Error\"); return; }\n if(n%2==0)\n for(int i=1; ib){\n\t c = a-b;\n\t }else{\n\t c = b-a;\n\t }\n \n System.out.print(c);\n\n\n\t }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf75687b209d4cfc97860456698b11f1", "src_uid": "aa62dcdc47d0abbba7956284c1561de8", "difficulty": 1100} {"lang": "Java 8", "source_code": "public class MainTestClass {\n\tpublic static void main(String[] args) {\n\t\t\tScanner scan = new Scanner(System.in);\n\t\t\tint l = scan.nextInt();\n\t\t\tint u = scan.nextInt();\n\t\t\tint l1 = l/2;\n\t\t\tint[] a = new int[l1];\n\t\t\tint[] b = new int[l1];\n\t\t\tint c = 0;\n\t\t\tboolean bool = false;\n\t\t\tint y = 1;\n\t\t\tfor (int i = 1;i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n 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 private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2ef2cf691de2d380a8e2a07bd3b48ceb", "src_uid": "20873b1e802c7aa0e409d9f430516c1e", "difficulty": 1700} {"lang": "Java 7", "source_code": "import java.scanner;\npublic class Main{\n\tpublic static void main(String args[]){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tdouble p = scan.nextDouble();\n\t\tint t = scan.nextInt();\n\t\tdouble ans = 0;\n\t\tfor(int i = 0;i<=n;i++){\n\t\t\tans += solve(n,i,p);\t\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic double solve(int n,int x,double p){\n\t\treturn Math.pow(p,x)*Math.pow((1-p),(n-x))*x;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eaba8dd5febfb1b4bbb61d1886b3098d", "src_uid": "20873b1e802c7aa0e409d9f430516c1e", "difficulty": 1700} {"lang": "Java 7", "source_code": "import java.Scanner;\npublic class Main{\n\tpublic static void main(String args[]){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tdouble p = scan.nextDouble();\n\t\tint t = scan.nextInt();\n\t\tdouble ans = 0;\n\t\tfor(int i = 0;i<=n;i++){\n\t\t\tans += solve(n,i,p);\t\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic double solve(int n,int x,double p){\n\t\treturn Math.pow(p,x)*Math.pow((1-p),(n-x))*x;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "28e7e0d4baf32925fc582606c899e467", "src_uid": "20873b1e802c7aa0e409d9f430516c1e", "difficulty": 1700} {"lang": "Java 7", "source_code": "import java.scanner;\npublic class Main{\n\tpublic static void main(String args[]){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tdouble p = scan.nextDouble();\n\t\tint t = scan.nextInt();\n\t\tdouble ans = 0;\n\t\tfor(int i = 0;i<=n;i++){\n\t\t\tans += solve(n,i,p);\t\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic double solve(int n,int x,double p){\n\t\treturn Math.pow(p,x)*Math.pow((1-p),(n-x)*x;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2bcf5a6f770fb01a9f93272704c2788f", "src_uid": "20873b1e802c7aa0e409d9f430516c1e", "difficulty": 1700} {"lang": "Java 8", "source_code": "package Codes;\n\nimport Scanner.Scanner;\nimport java.io.PrintWriter;\n\npublic class CIvanTheFoolAndTheProbabilityTheory {\n static int r,c,mod=(int)1e9+7,k;\n static Integer memo[][][];\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n r=sc.nextInt();\n c=sc.nextInt();\n k=Math.max(r,c);\n memo=new Integer[3][3][k+1];\n pw.println((dp(0,0,0)+(Math.min(r,c)==2?2:0))%mod);\n }\n\n private int dp(int i, int white,int black) {\n if(i==k)\n return 1;\n if(memo[white][black][i]!=null)\n return memo[white][black][i];\n int blackk=0,whitee=0;\n if(black<2)\n blackk = dp(i+1,0,black+1);\n if(white<2)\n whitee=dp(i+1,white+1,0);\n return memo[white][black][i]=((blackk+whitee)%mod);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "62888cb316428ac5c8c20829941f54f8", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CIvanTheFoolAndTheProbabilityTheory solver = new CIvanTheFoolAndTheProbabilityTheory();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CIvanTheFoolAndTheProbabilityTheory {\n static int r;\n static int c;\n static int mod = (int) 1e9 + 7;\n static Integer memo;\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n r = sc.nextInt();\n c = sc.nextInt();\n memo = new Integer[3][3][c + 1];\n pw.println((dp(0, 0, 0) + (r == 2 ? 2 : 0)) % mod);\n }\n\n private int dp(int i, int white, int black) {\n if (i == c)\n return 1;\n if (memo[white][black][i] != null)\n return memo[white][black][i];\n int blackk = 0, whitee = 0;\n if (black < 2)\n blackk = dp(i + 1, Math.max(0, white - 1), black + 1);\n if (white < 2)\n whitee = dp(i + 1, white + 1, Math.max(0, black - 1));\n return memo[white][black][i] = (blackk + whitee) % mod;\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e1046279d6a25adc9aeb4114afddbda5", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CIvanTheFoolAndTheProbabilityTheory solver = new CIvanTheFoolAndTheProbabilityTheory();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CIvanTheFoolAndTheProbabilityTheory {\n static int r;\n static int c;\n static int mod = (int) 1e9 + 7;\n static int k;\n static Integer memo;\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n r = sc.nextInt();\n c = sc.nextInt();\n k = Math.max(r, c);\n memo = new Integer[3][3][k + 1];\n pw.println((dp(0, 0, 0) + (Math.min(r, c) == 2 ? 2 : 0)) % mod);\n }\n\n private int dp(int i, int white, int black) {\n if (i == k)\n return 1;\n if (memo[white][black][i] != null)\n return memo[white][black][i];\n int blackk = 0, whitee = 0;\n if (black < 2)\n blackk = dp(i + 1, 0, black + 1);\n if (white < 2)\n whitee = dp(i + 1, white + 1, 0);\n return memo[white][black][i] = ((blackk + whitee) % mod);\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a8e7a42ab5ce5140c195b274d9f33759", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class CF {\n\n static int n, m;\n static int mod=(int)1e9+7;\n static int ans[] = new int[100001];\n\n static void solve() {\n ans[0] =1 ;\n ans[1] =1 ; \n ans[2] =2;\n for (int i = 3; i < 100001; i++)\n ans[i] =( ans[i - 1] %mod + ans[i - 2] %mod) % mod;\n }\n\n public static void main(String[] arg) throws Exception{\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n String s[] = bf.readLine().trim().split(\"\\\\s+\");\n n = Integer.parseInt(s[0]);\n m = Integer.parseInt(s[1]);\n solve();\n System.out.println((2 * (ans[n] + ans[m] - 1)5mod)%mod);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a6f217d10b04a3a32acac49b16bc3477", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main implements Runnable {\n final int MAXP = 10000000;\n \n boolean mark[] = new boolean[MAXP];\n \n public void run() {\n int a = nextInt(), b = nextInt(), mod = nextInt();\n\n if (b >= mod-1) { output.println(2); output.flush(); return; }\n \n int cur = 0;\n\n for (int i = 1; ; ++i) {\n cur = (cur + 1000000000) % mod;\n\n if (mark[cur]) break;\n mark[cur] = true;\n \n if (cur > 0 && cur+b < mod) {\n output.print(1 + \" \");\n \n int add = 9 - new Integer(i).toString().length();\n for (int j = 0; j < add; ++j) output.print(\"0\");\n output.println(i);\n \n output.flush();\n return;\n }\n }\n \n output.println(2);\n output.flush();\n }\n\n public static void main(String[] args) {\n //try { input = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\"))); } catch (Exception e) {}\n new Main().run();\n }\n\n static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter output = new PrintWriter(System.out);\n StringTokenizer tokenizer = null;\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n\n String nextToken() {\n try\n {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(input.readLine());\n }\n\n return tokenizer.nextToken();\n } catch (Exception e) {\n return null;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "718269b7fe12feb198c56ff1bd5488f7", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n \n final int MULT = 1000000000;\n\n void solve() throws IOException {\n int a = nextInt();\n int b = nextInt();\n \n int mod = nextInt();\n \n int aMult = MULT % mod;\n \n if (mod == 1) {\n out.print(2);\n return;\n }\n \n int maxBRem = Math.min(b, mod - 1);\n \n for (int i = 0; i < mod; i++) {\n int aRem = (int) ((long)i * aMult % mod);\n if (aRem == 0 || aRem + maxBRem >= mod)\n continue;\n out.printf(\"1 %09d\", i);\n return;\n }\n \n out.print(2);\n \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 B().inp();\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n eof = true;\n return \"0\";\n }\n }\n return st.nextToken();\n }\n\n String nextString() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n eof = true;\n return \"0\";\n }\n }\n return st.nextToken(\"\\n\");\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5fa3d18a1225df40581b40f7b9143f52", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800} {"lang": "Java 6", "source_code": "import java.lang.*;\nimport java.math.BigInteger;\nimport java.io.*;\nimport java.util.*;\n\npublic class Solution implements Runnable{\n public static BufferedReader br;\n public static PrintWriter out;\n public static StringTokenizer stk;\n public static boolean isStream = true;\n\n public static void main(String[] args) throws IOException {\n \tif (isStream) {\n br = new BufferedReader(new InputStreamReader(System.in));\n } else {\n br = new BufferedReader(new FileReader(\"in.txt\"));\n }\n out = new PrintWriter(System.out);\n new Thread(new Solution()).start();\n }\n\n public void loadLine() {\n try {\n stk = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n return \"\";\n }\n }\n\n public String nextWord() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return stk.nextToken();\n }\n\n public Integer nextInt() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Integer.valueOf(stk.nextToken());\n }\n\n public Long nextLong() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Long.valueOf(stk.nextToken());\n }\n\n public Double nextDouble() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Double.valueOf(stk.nextToken());\n }\n \n public Float nextFloat() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Float.valueOf(stk.nextToken());\n }\n \n public void run() {\n \tint a = nextInt();\n \tint b = nextInt();\n \tint mod = nextInt();\n \tint bnd = Math.min(a, mod);\n \tint ans = -1;\n \tfor (int i = 0; i < bnd; i++) {\n \t\tlong aa = i*1000000000L%mod;\n \t\tint rem = (int)aa;\n \t\tif (rem != 0 && mod-rem > b) {\n \t\t\tans = i;\n \t\t\tbreak;\n \t\t}\n \t}\n \tif (ans >= 0) {\n \t\tStringBuilder sb = new StringBuilder();\n \t\tfor (int i = 0; i < 9; i++) {\n \t\t\tsb.append(ans%10);\n \t\t\tans/=10;\n \t\t}\n \t\tout.println(1+\" \"+sb.reverse().toString());\n \t} else {\n \t\tout.println(2);\n \t}\n \tout.flush();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "897d78231fc9f88c9f42468bf958a9dd", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Game {\n public static void main(String[] args) throws IOException {\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n String[] input = bf.readLine().split(\" \");\n String answer = \"\";\n int a, b, mod, ans;\n boolean oneWins = false;\n a = Integer.parseInt(input[0]);\n b = Integer.parseInt(input[1]);\n mod = Integer.parseInt(input[2]);\n\n for (ans = 1; ans <= a; ans++) {\n if ((mod - (ans *1000000000)) % mod > b) {\n oneWins = true;\n break;\n }\n }\n\n if (oneWin) {\n String temp = String.valueOf(ans);\n int digits = temp.length();\n for (int i = 0;i < 9 - digits; i++) {\n answer += \"0\";\n }\n answer += String.valueOf(ans);\n System.out.println(\"1 \" + answer);\n } else {\n System.out.println(2);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b90e0aa4d29288bade11ab8789f0b61d", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Sample {\n\t\n\tpublic static void main(String args[]){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint[] arr = new int[n+1];\n\t\tint max = Integer.MIN_VALUE;\n\t\tfor(int i = 0; i <= 9; i++){\n\t\t\tif(i > n) break;\n\t\t\tarr[i] = i;\n\t\t\tif(arr[i] > max) max = arr[i];\n\t\t}\n\t\tif(n >= 10) arr[10] = 0;\n\t\tfor(int i = 11; i <= n; i++){\n\t\t\tString iSub = Integer.toString(i);\n\t\t\tString iSubLast = iSub.substring(0,iSub.length() - 1);\n\t\t\tarr[i] = arr[Integer.parseInt(iSubLast)] * Integer.parseInt(iSub.substring(iSub.length() - 1, iSub.length()));\n\t\t\tif(arr[i] > max) max = arr[i];\n\t\t}\n\t\tSystem.out.println(max);\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "15fb677c8e505ec6bfb4c1552d2936ec", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200} {"lang": "Java 8", "source_code": "// Working program with FastReader \nimport java.io.BufferedReader; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.util.*; \n\npublic class Main { \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} \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\n\t\tint nextInt() { \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() { \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() { \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() { \n\t\t\tString str = \"\"; \n\t\t\ttry{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} catch (IOException e) { \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t} \n\t\n\tpublic static void main(String[] args) { \n\t\tFastReader in=new FastReader(); \n\t\tint n = in.nextInt();\n\n\t\ttry{\n\t\t\tBufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\tif(n < 10){\n\t\t\t\tlog.write(n);\n\t\t\t}else{\n\t\t\t\tn--;\n\t\t\t\tString s = n;\n\t\t\t\tString [] digits = s.toCharArray();\n\t\t\t\tlong product = 1;\n\t\t\t\tfor(char c: digits){\n\t\t\t\t\tproduct *= c-'0';\n\t\t\t\t}\n\t\t\t\tlog.write();\n\t\t\t}\n\n\n\t\t\tlog.flush();\n\t\t\tlog.close();\n\t\t}catch(IOException e){\n\n\t\t}\n\t} \n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "97911e623fff902513d2dca118e365b4", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class Nirvana {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tNirvana obj = new Nirvana();\n\t\tSystem.out.println(obj.maxMultiply(n));\n\t\t\n\t\tin.close();\n\t}\n\tint maxMultiply(int n) {\n\t\tif(n == 0)\n\t\t\treturn 1;\n\t\tint nextNum = n/10;\n\t\tint digit = n%10;\n\t\tif(digit == 9) {\n\t\t\t// No need to borrow\n\t\t\treturn 9*maxMultiply(nextNum);\n\t\t}\n\t\tint result9 = -1;\n\t\tint resultNormal = -1;\n\t\tif(nextNum>0) {\n\t\t\t// Can borrow\n\t\t\tresult9 = 9*maxMultiply(nextNum-1);\n\t\t}\n\t\tresultNormal = digit*maxMultiply(nextNum);\n\t\treturn Math.max(result9, resultNormal);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b9a1e8326beae976bc6782c6d6229e8c", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200} {"lang": "Java 8", "source_code": "package code;\n\nimport IO.InputReader;\nimport IO.OutputWriter;\nimport java.io.IOException;\n\npublic class BNirvana {\n public void solve(int testNumber, InputReader in, OutputWriter out) throws IOException {\n long n=in.nextLong();\n String S=String.valueOf(n);\n long ans=Math.max(calVal(n-1),calVal(n-2));\n if(n<10)\n out.printLine(n-1);\n else\n {\n ans=Math.max(ans,(long)Math.pow(9,S.length()-1));\n for(int i=1;i= 0)\n if (restTime < minTime || minTime == -1)\n minTime = restTime;\n }\n }\n return minTime;\n }\n*/\n static boolean enabled(int from, int to){\n return r[from] < r[to] && c[from] != c[to];\n }\n\n\n\n static class box implements Comparable{\n\n int idx;\n ArrayList nexts = new ArrayList<>();\n\n public box(int idx, int order, boolean initNexts) {\n this.idx = idx;\n if (initNexts){\n boolean hasNext = false;\n //for (int target = 1; target <= n; target++){\n for (int next = order+1; next <= n; next++) {\n int target = allBoxes[next].idx;\n if (enabled(idx, target)) {\n //if (allBoxes[next] == null)\n allBoxes[next] = new box(target, next, true);\n nexts.add(allBoxes[next]);\n hasNext = true;\n }\n }\n /*if (hasNext)//!nexts.isEmpty())\n Collections.sort(nexts);*/\n }\n }\n\n int eat(int time, int restCount){\n if (restCount <= 0)\n return time;\n\n int from = idx;\n int minTime = -1;\n\n for (box b: nexts) {\n int to = b.idx;\n int curTime = from == 0 ? Math.abs(s - to) : Math.abs(from - to);\n int restTime = b.eat( time + curTime, restCount - r[to]);\n if (restTime >= 0)\n if (restTime < minTime || minTime == -1)\n minTime = restTime;\n }\n return minTime;\n }\n\n @Override\n public int compareTo(box o) {\n return r[this.idx] - r[o.idx];\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5f92c8e996c07d15a86437fd676285fa", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\n\npublic class A {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic int gcd(int a, int b) {\n\t\tif (a == 0) {\n\t\t\treturn b;\t\n\t\t}\n\t\treturn gcd(b % a, a);\n\t}\n\t\n\tpublic class Pair implements Comparable {\n\t\tint x;\n\t\tint y;\n\t\t\n\t\tpublic Pair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Pair o) {\n\t\t if (x != o.x) {\n\t\t return x - o.x;\n\t\t }\n\t\t return y - o.y;\n\t\t}\n\t}\n\t\n\t\n\t\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tint start = in.nextInt() - 1;\n\t\tint k = in.nextInt();\n\t\tPair[] a = new Pair[n];\n\t\tint[] sweet = new int[n];\n\t\tTreeMap[] map = new TreeMap[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t sweet[i] = in.nextInt();\n\t\t a[i] = new Pair(sweet[i], i);\n\t\t map[i] = new TreeMap<>();\n\t\t}\n\t\tArrays.sort(a);\n\t\tString s = in.next();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t int x = a[i].y;\n\t\t int y = a[i].x;\n\t\t map[x].put(y, Math.abs(start - x));\n\t\t for (int j = 0; j < n; j++) {\n\t\t if (s.charAt(x) != s.charAt(j) && sweet[x] > sweet[j]) {\n\t\t for (int x1 : map[j].keySet()) {\n\t\t int y1 = map[j].get(x1);\n\t\t int y2 = x1 + y;\n\t\t int z = y1 + Math.abs(x- j);\n\t\t if (map[x].containsKey(y2)) {\n\t\t map[x].put(y2, Math.min(map[x].get(y2), z));\n\t\t } else {\n\t\t map[x].put(y2, z);\n\t\t }\n\t\t }\n\t\t }\n\t\t }\n\t\t}\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t for (int x : map[i].keSet()) \n\t\t if (x >= k) {\n\t\t ans = Math.min(ans, map[i].get(x));\n\t\t }}\n\t\t}\n\t\tif (ans == Integer.MAX_VALUE) {\n\t\t out.print(-1);\n\t\t} else {\n\t\t out.print(ans);\n\t\t}\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 A().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e8618219a4e6bb659b7d70c5f433431", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\n\npublic class A {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic int gcd(int a, int b) {\n\t\tif (a == 0) {\n\t\t\treturn b;\t\n\t\t}\n\t\treturn gcd(b % a, a);\n\t}\n\t\n\tpublic class Pair implements Comparable {\n\t\tint x;\n\t\tint y;\n\t\t\n\t\tpublic Pair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Pair o) {\n\t\t if (x != o.x) {\n\t\t return x - o.x;\n\t\t }\n\t\t return y - o.y;\n\t\t}\n\t}\n\t\n\t\n\t\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tint start = in.nextInt() - 1;\n\t\tint k = in.nextInt();\n\t\tPair[] a = new Pair[n];\n\t\tint[] sweet = new int[n];\n\t\tTreeMap[] map = new TreeMap[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t sweet[i] = in.nextInt();\n\t\t a[i] = new Pair(sweet[i], i);\n\t\t map[i] = new TreeMap<>();\n\t\t}\n\t\tArrays.sort(a);\n\t\tString s = in.next();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t int x = a[i].y;\n\t\t int y = a[i].x;\n\t\t map[x].put(y, Math.abs(start - x));\n\t\t for (int j = 0; j < n; j++) {\n\t\t if (s.charAt(x) != s.charAt(j) && sweet[x] > sweet[j]) {\n\t\t for (int x1 : map[j].keySet()) {\n\t\t int y1 = map[j].get(x1);\n\t\t int y2 = x1 + y;\n\t\t int z = y1 + Math.abs(x- j);\n\t\t if (map[x].containsKey(y2)) {\n\t\t map[x].put(y2, Math.min(map[x].get(y2), z));\n\t\t } else {\n\t\t map[x].put(y2, z);\n\t\t }\n\t\t }\n\t\t }\n\t\t }\n\t\t}\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t for (int x : map[i].keySet()) \n\t\t if (x >= k) {\n\t\t ans = Math.min(ans, map[i].get(x));\n\t\t }}\n\t\t}\n\t\tif (ans == Integer.MAX_VALUE) {\n\t\t out.print(-1);\n\t\t} else {\n\t\t out.print(ans);\n\t\t}\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 A().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "babb7c2ec84bc15faedadac2338903d3", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class C {\n\n private static final int oo = Integer.MAX_VALUE / 4;\n\n private void work() {\n Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n n = sc.nextInt();\n int s = sc.nextInt() - 1;\n k = sc.nextInt();\n\n r = new int[n];\n for (int i = 0; i < n; i++) r[i] = sc.nextInt();\n char[] c = sc.next().toCharArray();\n sc.close();\n\n deg = new int[n];\n g = new int[n][n];\n\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (c[i] != c[j]) {\n if (r[i] < r[j]) g[i][deg[i]++] = j;\n if (r[i] > r[j]) g[j][deg[j]++] = i;\n }\n }\n }\n\n memo = new int[n][k];\n for(int i = 0; i < n; i++){\n Arrays.fill(memo[i], - 1);\n }\n\n for(int i = 0; i < n; i++){\n go(i, r[i]);\n }\n\n int res = oo;\n for(int i = 0; i < n; i++){\n int t = Math.abs(i - s) + memo[i][r[i]];\n if(t < res) res = t;\n }\n\n System.out.println(res == oo ? -1 : res);\n }\n\n private int n, k;\n private int[] r, deg;\n private int[][] g, memo;\n\n private int go(int u, int candies){\n if(candies >= k){\n return 0;\n }\n if(memo[u][candies] >= 0) return memo[u][candies];\n\n int ret = oo;\n for(int i = 0; i < deg[u]; i++){\n int v = g[u][i];\n int t = Math.abs(u - v) + go(v, candies + r[v]);\n if(t < ret) ret = t;\n }\n\n return memo[u][candies] = ret;\n }\n\n public static void main(String[] args) {\n new C().work();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "410dbebec1ef3a31dc13a29c68275423", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n \n \npublic class Main{\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n \n // Start writing your solution here. -------------------------------------\n \n \n int n = sc.nextInt(); // read input as integer\n int numberOfWays = getWays(n);\n\n // Stop writing your solution here. -------------------------------------\n out.close();\n }\n\n \n\n //-----------PrintWriter for faster output---------------------------------\n public static PrintWriter out;\n \n //-----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n \n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(next());\n }\n \n long nextLong() {\n return Long.parseLong(next());\n }\n \n double nextDouble() {\n return Double.parseDouble(next());\n }\n \n String nextLine(){\n String str = \"\";\n\t try {\n\t str = br.readLine();\n\t } catch (IOException e) {\n\t e.printStackTrace();\n\t }\n\t return str;\n }\n\n }\n //--------------------------------------------------------\n\n private int getWays(int n) {\n if(n%2 == 0)\n return 0;\n return (int)Math.pow(2, n/2);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "66c8cd3dcc94e5e930c3d30f2e7a5b44", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\nimport java.math.*;\n\npublic class text \n{\n public static void main(String[] args) \n {\n double output;\n int polynomial = 0;\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n if (n % 2 != 0)\n {\n output = 0;\n }\n elseXDragSourceContextPeer\n {\n polynomial = n / 2;\n output = Math.pow(2, polynomial);\n }\n \n int xd = (int) Math.round(output); \n System.out.println(xd);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "52eff05ed273098eaaaf3c212c13bf52", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class FillingShapes\n{\n\tpublic static void main(String[] d)\n\t{\n\t\tHashSet hs=new HashSet<>();\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tfor (int i=1; i<=sqrt(n*3); i++)\n\t\t{\n\t\t\tif(n%i==0)\n\t\t\t{\n\t\t\t\ths.add(i);\n\t\t\t\ths.add(n/i);\n\t\t\t}\n\t\t}\n\t\t if(n%2!=0)\n\t\t\tSystem.out.println(0);\n\t\telse\n\t\t\tSystem.out.println((hs.size()-2));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1eb63f0be3fd36e6b6e4845c6e7df854", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000} {"lang": "Java 8", "source_code": "public class gfg{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n if(n==1||n%2!=0){\n System.out.println(\"0\");\n }else{\n System.out.println(n);\n }\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9b3c59580fab6d8d235c0b220efce6b7", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class C1_177 {\n static class DisjointSet {\n\n private int[] id;\n private int[] sz;\n private int count;\n\n public DisjointSet(int N) {\n count = N;\n id = new int[N];\n sz = new int[N];\n for (int i = 0; i < N; i++) {\n id[i] = i;\n sz[i] = 1;\n }\n }\n\n public int count() {\n return count;\n }\n\n public int find(int p) {\n while (p != id[p])\n p = id[p];\n return p;\n }\n\n public boolean connected(int p, int q) {\n return find(p) == find(q);\n }\n\n public void union(int p, int q) {\n int i = find(p);\n int j = find(q);\n if (i == j)\n return;\n\n if (sz[i] < sz[j]) {\n id[i] = j;\n sz[j] += sz[i];\n } else {\n id[j] = i;\n sz[i] += sz[j];\n }\n count--;\n }\n \n public void reset (int p) {\n for (int i = 0; i < id.length; i++) {\n if (id[i] == p) {\n sz[i] = 1;\n id[i] = -1;\n }\n }\n }\n \n public int maxCount() {\n int c[] = new int[id.length];\n for (int i = 0; i < c.length; i++) {\n if (id[i] >= 0)\n ++c[id[i]];\n }\n Arrays.sort(c);\n return c[c.length - 1];\n }\n }\n \n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n DisjointSet d = new DisjointSet(n);\n int k = in.nextInt();\n for (int i = 0; i < k; i++) {\n int u = in.nextInt() - 1;\n int v = in.nextInt() - 1;\n d.union(u, v);\n }\n int m = in.nextInt();\n for (int i = 0; i < m; i++) {\n int u = in.nextInt() - 1;\n int v = in.nextInt() - 1;\n if (d.connected(u, v)) {\n int parent = d.find(u);\n d.reset(parent);\n }\n }\n System.out.println(d.maxCount());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "39aea7a71248b0c56cb56a29607e69d0", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1", "difficulty": 1500} {"lang": "Java 8", "source_code": "import sun.reflect.generics.tree.Tree;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.net.Inet4Address;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\n\npublic class Newbie {\n\n static InputReader sc = new InputReader(System.in);\n static PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) throws IOException {\n solver s = new solver();\n long t = 1;\n while (t > 0) {\n s.solve();\n t--;\n }\n out.close();\n }\n\n /* static class descend implements Comparator {\n public int compare(pair1 o1, pair1 o2) {\n if (o1.pop != o2.pop)\n return (int) (o1.pop - o2.pop);\n else\n return o1.in - o2.in;\n }\n }*/\n\n static class InputReader {\n public BufferedReader br;\n public StringTokenizer token;\n\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream), 32768);\n token = null;\n }\n\n public String sn() {\n while (token == null || !token.hasMoreTokens()) {\n try {\n token = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return token.nextToken();\n }\n\n public int ni() {\n return Integer.parseInt(sn());\n }\n\n public String snl() throws IOException {\n return br.readLine();\n }\n\n public long nlo() {\n return Long.parseLong(sn());\n }\n\n public double nd() {\n return Double.parseDouble(sn());\n }\n\n public int[] na(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = sc.ni();\n return a;\n }\n\n public long[] nal(int n) {\n long a[] = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = sc.nlo();\n return a;\n }\n }\n\n static class ascend implements Comparator {\n public int compare(pair o1, pair o2) {\n return o2.b - o1.b;\n }\n }\n\n static class extra {\n\n static boolean v[] = new boolean[100001];\n static List l = new ArrayList<>();\n static int t;\n\n static void shuffle(int a[]) {\n for (int i = 0; i < a.length; i++) {\n int t = (int) Math.random() * a.length;\n int x = a[t];\n a[t] = a[i];\n a[i] = x;\n }\n }\n\n static void shufflel(long a[]) {\n for (int i = 0; i < a.length; i++) {\n int t = (int) Math.random() * a.length;\n long x = a[t];\n a[t] = a[i];\n a[i] = x;\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 static boolean valid(int i, int j, int r, int c) {\n if (i >= 0 && i < r && j >= 0 && j < c) {\n // System.out.println(i+\" /// \"+j);\n return true;\n } else {\n // System.out.println(i+\" //f \"+j);\n return false;\n }\n }\n\n static void seive() {\n for (int i = 2; i < 101; i++) {\n if (!v[i]) {\n t++;\n l.add(i);\n for (int j = 2 * i; j < 101; j += i)\n v[j] = true;\n }\n }\n }\n\n static int binary(LinkedList a, long val, int n) {\n int mid = 0, l = 0, r = n - 1, ans = 0;\n while (l <= r) {\n mid = (l + r) >> 1;\n if (a.get(mid) == val) {\n r = mid - 1;\n ans = mid;\n } else if (a.get(mid) > val)\n r = mid - 1;\n else {\n l = mid + 1;\n ans = l;\n }\n }\n return (ans + 1);\n }\n\n static long fastexpo(long x, long y) {\n long res = 1;\n while (y > 0) {\n if ((y & 1) == 1) {\n res *= x;\n }\n y = y >> 1;\n x = x * x;\n }\n return res;\n }\n\n static long lfastexpo(long x, long y, long p) {\n long res = 1;\n x = x % p;\n while (y > 0) {\n if ((y & 1) == 1) {\n res = (res * x) % p;\n }\n y = y >> 1;\n x = (x * x) % p;\n }\n return res;\n }\n\n /* void dijsktra(int s, List l[], int n) {\n PriorityQueue pq = new PriorityQueue<>(new ascend());\n int dist[] = new int[100005];\n boolean v[] = new boolean[100005];\n for (int i = 1; i <= n; i++)\n dist[i] = 1000000000;\n dist[s] = 0;\n for (int i = 1; i < n; i++) {\n if (i == s)\n pq.add(new pair(s, 0));\n else\n pq.add(new pair(i, 1000000000));\n }\n while (!pq.isEmpty()) {\n pair node = pq.remove();\n v[node.a] = true;\n for (int i = 0; i < l[node.a].size(); i++) {\n int v1 = l[node.a].get(i).a;\n int w = l[node.a].get(i).b;\n if (v[v1])\n continue;\n if ((dist[node.a] + w) < dist[v1]) {\n dist[v1] = dist[node.a] + w;\n pq.add(new pair(v1, dist[v1]));\n }\n }\n }\n }*/\n }\n\n static class 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\n static class pair1 {\n pair p;\n int in;\n\n public pair1(pair a, int n) {\n this.p = a;\n this.in = n;\n }\n }\n\n static int inf = 5000013;\n\n static class solver {\n DecimalFormat df = new DecimalFormat(\"0.00\");\n extra e = new extra();\n int mod = 1000000007;\n boolean v[] = new boolean[1001];\n void solve() throws IOException {\n int n=sc.ni();\n int p[]=new int[n];\n for(int i=0;i count=new HashMap<>();\n int k=sc.ni();\n while (k-->0)\n {\n int u=sc.ni()-1;\n int v=sc.ni()-1;\n int p1=find(p,u);\n int p2=find(p,v);\n if(p1!=p2)\n union(p,u,v);\n }\n for(int i=0;i0) {\n int u = sc.ni() - 1;\n int v = sc.ni() - 1;\n int p1 = find(p, u);\n int p2 = find(p, v);\n if (p1 == p2)\n count.remove(p1);\n }\n int ans=Collections.max(count.values());\n System.out.println(ans);\n }\n int rank[]=new int[100000];\n int find(int p[],int x){\n if(p[x]==x)\n return x;\n p[x]=find(p,p[x]);\n return p[x];\n }\n void union(int p[],int x,int y)\n {\n int p1=find(p,x);\n int p2=find(p,y);\n if(rank[p1]>rank[p2])\n {\n p[p2]=p1;\n rank[p1]=rank[p2]+1;\n }\n else\n {\n p[p1]=p2;\n rank[p2]=Math.max(rank[p1]+1,rank[p2]);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9062eed122ced05896dfe3ba59f327cc", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1", "difficulty": 1500} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n//4/22/12 1:43 AM\n//by Abrackadabra\n\npublic class C1 {\n public static void main(String[] args) throws IOException {\n if (args.length > 0 && args[0].equals(\"Abra\")) debugMode = true;\n new C1().run();\n /*new Thread(null, new Runnable() {\n public void run() {\n try {\n new C1().run();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n }, \"1\", 1 << 24).start();*/\n }\n\n int IOMode = 0; //0 - consoleIO, 1 - .in/out, 2 - input.txt/output.txt, 3 - test case generator\n String taskName = \"\";\n\n void solve() throws IOException {\n int n = nextInt();\n HashMap> friends = new HashMap>();\n HashMap> enemies = new HashMap>();\n HashSet badColors = new HashSet();\n int[] coloring = new int[n];\n int[] colorCount = new int[n];\n int currentColor = 1;\n int m = nextInt();\n for (int i = 0; i < m; i++) {\n int a = nextInt() - 1, b = nextInt() - 1;\n if (!friends.containsKey(a))\n friends.put(a, new HashSet());\n if (!friends.containsKey(b))\n friends.put(b, new HashSet());\n friends.get(a).add(b);\n friends.get(b).add(a);\n }\n m = nextInt();\n for (int i = 0; i < m; i++) {\n int a = nextInt() - 1, b = nextInt() - 1;\n if (!enemies.containsKey(a))\n enemies.put(a, new HashSet());\n if (!enemies.containsKey(b))\n enemies.put(b, new HashSet());\n enemies.get(a).add(b);\n enemies.get(b).add(a);\n }\n for (int i = 0; i < n; i++) {\n if (coloring[i] == 0) {\n int toColor = currentColor++;\n Queue queue = new LinkedList();\n queue.add(i);\n coloring[i] = toColor;\n colorCount[toColor]++;\n while (!queue.isEmpty()) {\n int q = queue.poll();\n if (friends.containsKey(q))\n for (int t : friends.get(q)) {\n if (coloring[t] == 0) {\n coloring[t] = toColor;\n colorCount[toColor]++;\n queue.add(t);\n }\n }\n if (enemies.containsKey(q))\n for (int t : enemies.get(q)) {\n if (coloring[t] == toColor) {\n badColors.add(toColor);\n }\n }\n }\n }\n }\n int res = 0;\n for (int i = 1; i < currentColor; i++) {\n if (!badColors.contains(i) && colorCount[i] > res)\n res = colorCount[i];\n }\n out.println(res);\n }\n\n long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;\n long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;\n\n void run() throws IOException {\n init();\n if (debugMode) {\n con.println(\"Start\");\n con.println(\"Console:\");\n }\n solve();\n finishTime = System.nanoTime();\n finishMem = Runtime.getRuntime().totalMemory();\n out.flush();\n if (debugMode) {\n int maxSymbols = 1000;\n BufferedReader tbr = new BufferedReader(new FileReader(\"input.txt\"));\n char[] a = new char[maxSymbols];\n tbr.read(a);\n if (a[0] != 0) {\n con.println(\"File input:\");\n con.println(a);\n if (a[maxSymbols - 1] != 0) con.println(\"...\");\n }\n tbr = new BufferedReader(new FileReader(\"output.txt\"));\n a = new char[maxSymbols];\n tbr.read(a);\n if (a[0] != 0) {\n con.println(\"File output:\");\n con.println(a);\n if (a[maxSymbols - 1] != 0) con.println(\"...\");\n }\n con.println(\"Execution time: \" + (finishTime - startTime) / 1000000000.0 + \" sec\");\n con.println(\"Used memory: \" + (finishMem - startMem) + \" bytes\");\n con.println(\"Total memory: \" + Runtime.getRuntime().totalMemory() + \" bytes\");\n }\n }\n\n boolean tick(double x) {\n if (System.nanoTime() - tempTime > x * 1e9) {\n tempTime = System.nanoTime();\n con.println(\"Tick at \" + (tempTime - startTime) / 1000000000 + \" sec\");\n con.print(\" \");\n return true;\n }\n return false;\n }\n\n static boolean debugMode = false;\n PrintStream con = System.out;\n\n void init() throws IOException {\n if (debugMode && IOMode != 3) {\n br = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n } else\n switch (IOMode) {\n case 0:\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n break;\n case 1:\n br = new BufferedReader(new FileReader(taskName + \".in\"));\n out = new PrintWriter(new FileWriter(taskName + \".out\"));\n break;\n case 2:\n br = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n break;\n case 3:\n out = new PrintWriter(new FileWriter(\"input.txt\"));\n break;\n }\n }\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer in;\n\n boolean hasMoreTokens() throws IOException {\n while (in == null || !in.hasMoreTokens()) {\n String line = br.readLine();\n if (line == null) return false;\n in = new StringTokenizer(line);\n }\n return true;\n }\n\n String nextString() throws IOException {\n return hasMoreTokens() ? in.nextToken() : null;\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextString());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextString());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextString());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e107c9722efb914cd4b22d57f721fdd1", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class B114 {\n static BufferedReader br;\n static StringTokenizer st;\n static PrintWriter pw;\n\n static String nextToken() {\n try {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n return st.nextToken();\n }\n\n static int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n static long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n static String nextLine() throws IOException {\n return br.readLine();\n }\n\n static char nextChar() throws IOException {\n return (char) br.read();\n }\n\n public static void main(String[] args) {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(System.out);\n run();\n pw.close();\n }\n\n static ArrayList graf[];\n static ArrayList grafUn[];\n static TreeMap treeName = new TreeMap<>();\n static TreeMap treeInt = new TreeMap<>();\n static TreeSet treeUnInt = new TreeSet<>();\n\n private static void run() {\n int n = nextInt();\n int m = nextInt();\n for (int i = 0; i < n; i++) {\n String s = nextToken();\n treeName.put(s, i);\n treeInt.put(i, s);\n }\n grafUn = new ArrayList[n];\n graf = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n grafUn[i] = new ArrayList<>();\n graf[i] = new ArrayList<>();\n }\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n graf[i].add(j);\n graf[j].add(i);\n }\n }\n for (int i = 0; i < m; i++) {\n String s1 = nextToken();\n String s2 = nextToken();\n int x = treeName.get(s1);\n int y = treeName.get(s2);\n grafUn[x].add(y);\n grafUn[y].add(x);\n treeUnInt.add(x);\n treeUnInt.add(y);\n }\n for (int i = 0; i < n; i++) {\n dfs(i, new ArrayList<>(), new TreeSet<>());\n }\n ArrayList anss = new ArrayList<>();\n for (int i = 0; i < ans.size(); i++) {\n anss.add(treeInt.get(ans.get(i)));\n }\n Collections.sort(anss);\n pw.println(anss.size());\n for (int i = 0; i < anss.size(); i++) {\n pw.println(anss.get(i));\n }\n\n }\n\n private static void dfs(int v, ArrayList es, TreeSet no) {\n if (no.contains(v)) return;\n es.add(v);\n for (int i = 0; i < grafUn[v].size(); i++) {\n no.add(grafUn[v].get(i));\n }\n no.add(v);\n for (int i = 0; i < graf[v].size(); i++) {\n dfs(graf[v].get(i), (ArrayList) es.clone(), (TreeSet) no.clone());\n }\n if (es.size() > ans.size()) {\n ans = es;\n }\n }\n\n\n\n static ArrayList ans = new ArrayList<>();\n\n private static void removeV(int x, int y) {\n for (int j = 0; j < graf[x].size(); j++) {\n if (graf[x].get(j) == y) {\n graf[x].remove(j);\n break;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65dba64136cf79ac8aa160b6bb329e53", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1", "difficulty": 1500} {"lang": "Java 8", "source_code": "package com.company;\n\n//import java.util.Scanner;\n\npublic class RootNumb {\n public static void main (String [] args) {\n Scanner scan = new Scanner(System.in);\n String line = scan.nextLine();\n char charX = line.charAt(0);\n int intY = Character.getNumericValue(line.charAt(1));\n\n int var = 8;\n\n if (charX == 'a' || charX == 'h' || intY == 1 || intY == 8) {\n var = 5;\n }\n\n if (\"a1\".equals(line) || \"h1\".equals(line) || \"a8\".equals(line) || \"h8\".equals(line)) {\n var = 3;\n }\n\n System.out.println(var);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d0ab730561b48fcc2fe6cbf97d013227", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n char s = in.nextChar();\n int t = in.nextInt();\n if((s == a || s == h) && (t==1 || t==8))\n {\n System.out.println(3);\n }\n else if((s == a || s == h) && (t>=2 && t<=7))\n {\n \n System.out.println(5);\n \n }\n else if(('s'>'a' && 's'<'h') && (t==1 || t==8))\n {\n System.out.println(5);\n }\n else\n System.out.println(8);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9c179666afed14fe3325a960e6ad54ed", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class KingMoves{\n\tpublic static void main(String[] args){\n\t\tScanner keyboard = new Scanner(System.in);\n\t\tString position = keyboard.nextLine();\n\t\t\n\t\tchar d = position.charAt(0);\n\t\tchar c = Integer.parseInt(keyboard.next()); \n\t\tposition.charAt(1);\n\t\t\n\t\tint moves = 0;\n\t\t\n\t\tif ( position.equals(\"a8\") ||position.equals(\"a1\") ||\n\t\t\t position.equals(\"h8\") ||\n\t\t\t position.equals(\"h1\") )\n\t\t\tmoves = 3;\n\t\t\t \n\t\telse if (d == 'a' || d == 'h' || c == '1' || c == '8')\n\t\t\tmoves=5;\n\t\telse \n\t\t\tmoves=8; \n\t\t\n\t\tSystem.out.println(moves+\"\");\n\t\t\t\n\t}//end of main\n}//end of class", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e97efc094139e3d94a4910a2f64d97b4", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\npublic class A {\n public static void main(String[]args){\n \t Scanner sc=new Scanner(System.in);\n \t String temp=sc.nextLine();\n \t int p1=temp.charAt(0)-'a'+1;\n \t int p2=temp.charAt(1)-'0;\n \t int ans=8;\n \t if(p1==1||p1==8)ans-=3;\n \t if(p2==1||p2==8)ans-=3;\n \t if(ans==2)ans++;\n \t System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b70a018388f3a2b312e6734de18aa3d0", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class DD {\n\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner sc=new Scanner(System.in);\nlong t;\nt=sc.nextLong();\nfor(int i=0;i hs =new HashSet<>();\n for(int u=z;u<(z+d);u++)\n {\n hs.add(a[u]);\n }\n \n size=hs.size();\n if(size0){\n int n=scan.nextInt();\n int k=scan.nextInt();\n int d=scan.nextInt();\n int[] arr=new int[n];\n for (int i = 0; i m=new HashMap<>();\n for(int i=0;its = new TreeSet<>();\n for (int l = 0; l < h.length; l++) {\n ts.add(h[l]);\n }\n if (ts.size() < min) min = ts.size();\n }\n pw.println(min);\n }\n pw.close();\n }\n\n static int mod = 1_000_000_009;\n static BufferedReader br;\n static StringTokenizer st = new StringTokenizer(\"\");\n\n static long nextLong() throws IOException {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return Long.parseLong(st.nextToken());\n }\n\n static int nextInt() throws IOException {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return Integer.parseInt(st.nextToken());\n }\n\n static double nextDouble() throws IOException {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return Double.parseDouble(st.nextToken());\n }\n\n static String next() throws IOException {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n static PrintWriter pw;\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "48a68ea865da2a40ccd36d71110d26a9", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\nimport Contest596.A.FastReader;\n\npublic class B1 {\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\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tFastReader scn = new FastReader();\n\t\tint tc = scn.nextInt();\n\t\twhile (tc-- > 0) {\n\t\t\tint n = scn.nextInt();\n\t\t\tint arr[] = new int[n];\n\t\t\tint k = scn.nextInt();\n\t\t\tint d = scn.nextInt();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = scn.nextInt();\n\t\t\t}\n\t\t\tint cout = Integer.MAX_VALUE;\n//\t\t\tint res[]=new int[n];\n//\t\t\tif (n == d) {\n//\t\t\t\tint c = 0;\n//\t\t\t\tint hash[] = new int[k + 1];\n//\t\t\t\tfor (int j = 0; j < n; j++) {\n//\t\t\t\t\thash[arr[j]]++;\n////\t\t\t\t\tres[j]\n//\t\t\t\t}\n//\t\t\t\tfor (int val : hash) {\n//\t\t\t\t\tif (val != 0)\n//\t\t\t\t\t\tc++;\n//\t\t\t\t}\n//\t\t\t\tcout=Math.min(cout, c);\n//\t\t\t} else {\n\t\t\t\tfor (int i = 0; i <= n - d; i++) {\n\t\t\t\t\tint c = 0;\n\t\t\t\t\tint hash[] = new int[k + 1];\n\t\t\t\t\tfor (int j = i; j < i + d && j < n; j++) {\n\t\t\t\t\t\thash[arr[j]]++;\n//\t\t\t\t\tres[j]\n\t\t\t\t\t}\n\t\t\t\t\tfor (int val : hash) {\n\t\t\t\t\t\tif (val != 0)\n\t\t\t\t\t\t\tc++;\n\t\t\t\t\t}\n//\t\t\t\tres[i]=c;\n\t\t\t\t\tcout = Math.min(c, cout);\n\t\t\t\t}\n//\t\t\t}\n\t\t\tSystem.out.println(cout);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fc535730911e892f5c6756a54235b9b3", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\npublic class ques1_507{\n\t\n\tpublic static void main(String[] args)\n {\n\t\tFastReader f = new FastReader();\n\t\tPrintWriter wr = new PrintWriter(System.out);\n int n = f.nextInt();\n int a = f.nextInt();\n int b = f.nextInt();\n int[] array = new int[n];\n for(int i=0;i=0 && i=0)\n {\n if(start<=end)\n {\n if(array[start] == array[end])\n {\n start++;\n end--;\n continue;\n }\n else\n {\n if(array[start] == 2 || array[end] == 2)\n {\n start++;\n end--;\n continue;\n }\n else\n {\n return false;\n }\n } \n } \n }\n return true;\n }\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "db1233c76f57455dd0c0247f5ec58cdf", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class name\n{\n public static void main(String[]args)throws IOException\n {\n Scanner sc=new Scanner(System.in);\n int n,w,b,a[],i,sum=0;\n n=sc.nextInt();\n w=sc.nextInt();\n b=sc.nextInt();\n a=new int[n];\n sum=0;\n for(i=0;ib)&&(a[n/2]==2))\n {\n a[n/2]=b;\n sum+=b;\n }\n else if((a[n/2]==2)&&(b>w))\n {\n a[n/2]=w;\n sum+=w;\n }\n if(a[i]==a[n-i-1)\n {\n continue;\n }\n else if(a[i]==0)\n sum+=w;\n else if(a[i]==1)\n sum+=b;\n }\n System.out.println(sum);\n }\n \n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b69f0306b4729c84acb39a1e315714e1", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n public class test{\n static class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br=new BufferedReader(new InputStreamReader(System.in));\n }\n public FastReader(String s)throws FileNotFoundException{\n br=new BufferedReader(new FileReader(new File(s)));\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 public static void main(String args[]){\n FastReader in=new FastReader();\n int n=in.nextInt();\n int p=in.nextInt();\n int q=in.nextInt();\n int a[]=new int[n];\n for(int i=0;iq)?q:p;\n for(int i=0;i dest = new ArrayList<>();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tString flight = reader.readLine();\n\t\t\t\tdest.add(flight.substring(5, 8));\n\t\t\t}\n\t\t\tint homes = 0;\n\t\t\tfor(int i = 0;i= contests) {\n\t\t\t\tSystem.out.println(\"home\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"contest\");\n\t\t\t}\n\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72d5f50c85c65c10356fc351738de9ac", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222", "difficulty": 900} {"lang": "Java 8", "source_code": "\n\npublic class neverending {\n public static void main(String[] args) {\n \tScanner ab=new Scanner(System.in);\n \tint i,n=ab.nextInt();\n \tString home=ab.next();\n \tString[] list=new String(n);\n \tfor(i=0;i= max || num == 0)\n\t\t\treturn num;\n\t\tif(num < 10000 && p < 3000 && grid[num][p] != -1)\n\t\t\treturn grid[num][p];\n\t\tint ret = compute(num,p+1) - compute(num/primes[p],p+1);\n\t\tif(num < 10000 && p < 3000)\n\t\t\tgrid[num][p] = ret;\n\t\treturn ret;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1929668953dc3e67deb80463f5370656", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2", "difficulty": 2400} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main{\n\n BufferedReader in;\n StringTokenizer str = null;\n PrintWriter out;\n\n private String next() throws Exception{\n \twhile (str == null || !str.hasMoreElements())\n \t str = new StringTokenizer(in.readLine());\n \treturn str.nextToken();\n }\n \n private int nextInt() throws Exception{\n\treturn Integer.parseInt(next());\n }\n \n int lp[];\n List pr;\n \n public void run() throws Exception{\n \tin = new BufferedReader(new InputStreamReader(System.in));\n \tout = new PrintWriter(System.out);\n\tint a = nextInt(), b = nextInt(), k = nextInt();\n\tfor(int i = 2; i * i <= k; ++i){\n\t if (k % i == 0){\n\t\tout.println(0);\n\t\tout.close();\n\t\treturn;\n\t }\n\t}\n\t\n\tif (k > 100){\n\t int n = b / k;\n\t pr = new ArrayList();\n\t lp = new int[n + 1];\n\t lp[1] = Integer.MAX_VALUE;\n\t for(int i = 2; i <= n; ++i){\n\t\tif (lp[i] == 0){\n\t\t lp[i] = i;\n\t\t pr.add(i);\n\t\t}\n\t\tfor(int j = 0;j < pr.size() && pr.get(j) <= i && 1L * i * pr.get(j) <= n; ++j){\n\t\t lp[pr.get(j) * i] = pr.get(j);\n\t\t}\n\t }\n\t \n\t int res = calc(b, k) - calc(a-1, k);\n\t out.println(res);\n\t}else{\n\t pr = new ArrayList();\n\t for(int i = 2; i < k; ++i){\n\t\tif (isPrime(i)){\n\t\t pr.add(i);\n\t\t}\n\t }\n\t \n\t int res = calc1(b, k) - calc1(a-1, k);\n\t out.println(res);\n\t}\n\t\n out.close();\n }\n \n private boolean isPrime(int x) {\n\tfor(int i = 2; i * i <= x; ++i){\n\t if (x % i == 0){\n\t\treturn false;\n\t }\n\t}\n\treturn true;\n }\n \n private int calc(int n, int k){\n\tint ret = 0;\n\tfor(int i = 1; 1L * i * k <= n; ++i){\n\t if (lp[i] >= k){\n\t\t++ret;\n\t }\n\t}\n\treturn ret;\n }\n \n private int calc1(int n, int k){\n\tint res = n / k;\n\tint N = pr.size();\n\tfor(int mask = 1; mask < 1 << N; ++mask){\n\t int r = n/k;\n\t for(int j = 0; j < N; ++j){\n\t if ((mask & (1 << j)) > 0){\n\t\t r/=pr.get(j);\n\t\t}\n\t }\n\t if (Integer.bitCount(mask) % 2 == 1){\n\t res-=r;\n\t }else{\n\t res+=r;\n\t }\n\t}\n\t\n\treturn res;\n }\n\n public static void main(String args[]) throws Exception{\n\tnew Main().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "37b7b22d8a310ec0a0d4fe39c97d2364", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2", "difficulty": 2400} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class D83 {\n\tstatic int max;\n\tstatic int[][] grid;\n\tstatic int[] primes;\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tprimes = new int[30000];\n\t\tint c = 1;\n\t\tprimes[0] = 2;\n\t\tfor(int i = 3; c < primes.length; i += 2)\n\t\t\tif(prime(i))\n\t\t\t\tprimes[c++] = i;\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint a = Integer.parseInt(st.nextToken());\n\t\tint b = Integer.parseInt(st.nextToken());\n\t\tmax = Integer.parseInt(st.nextToken());\n\t\tgrid = new int[1000][30000];\n\t\tfor(int i = 0; i < grid.length; i++)\n\t\t\tArrays.fill(grid[i], -1);\n\t\tif(!prime(max))\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(compute(b/max, 0) - compute((a-1)/max, 0));\n\t}\n\tpublic static boolean prime(int x)\t{\n\t\tif(x==1)\n\t\t\treturn false;\n\t\tif(x<=3)\n\t\t\treturn true;\n\t\tif(x%2==0 || x%3==0)\n\t\t\treturn false;\n\t\tfor(int d = 5; d * d <= x; d += 6)\n\t\t\tif(x%d==0)\n\t\t\t\treturn false;\n\t\tfor(int d = 7; d * d <= x; d += 6)\n\t\t\tif(x%d==0)\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\tpublic static int compute(int num, int p)\t{\n\t\tif(primes[p] >= max || num <= 1)\n\t\t\treturn num;\n\t\tif(num < 1000 && p < 30000 && grid[num][p] != -1)\n\t\t\treturn grid[num][p];\n\t\tint ret = compute(num,p+1) - compute(num/primes[p],p+1);\n\t\tif(num < 1000 && p < 30000)\n\t\t\tgrid[num][p] = ret;\n\t\treturn ret;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60e8d33e1a94e9a552746266fe633501", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2", "difficulty": 2400} {"lang": "Java 6", "source_code": "import net.llinux.Utils;\n\nimport java.io.*;\n\n/**\n * Codeforces Beta Round #72 (Div. 1 Only), D\n * @author Roman Kosenko \n */\npublic class C083D_Numbers {\n\tpublic static void main(String... args) throws IOException {\n\t\tlong time = 0;\n\t\tif(args.length != 0) {\n\t\t\tSystem.setIn(new FileInputStream(args[0]));\n\t\t\ttime = System.currentTimeMillis();\n\t\t\tprimes = null;\n\t\t} else if(!Boolean.parseBoolean(System.getProperty(\"ONLINE_JUDGE\"))) {\n\t\t\tmain(\"in/C083D.1.txt\");\n\t\t\tmain(\"in/C083D.2.txt\");\n\t\t\tmain(\"in/C083D.3.txt\");\n\t\t\t//main(\"input.txt\");\n\t\t\treturn;\n\t\t}\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] ss = br.readLine().split(\" \");\n\t\tint a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), k = Integer.parseInt(ss[2]), result = !Utils.isPrime(k) ? 0 : solve(a, b, k);\n\t\tSystem.out.println(result);\n\n\t\t//if(time != 0)\n\t\t//\tSystem.out.println(System.currentTimeMillis() - time);\n\t}\n\tprivate static int primes[];\n\tprivate static int solve(int a, int b, int k) {\n\t\tfinal int start = (a - 1) / k + 1, end = b / k;\n\t\tif(end < start)\n\t\t\treturn 0;\n\t\tif(end == start)\n\t\t\treturn 1;\n\t\tif(primes == null)\n\t\t\tprimes = Utils.primes(k - 1, 0);\n\t\tint result = end - start + 1;\n\t\tfor(int i = 0; i < primes.length && primes[i] < k; i++)\n\t\t\tresult -= solve(start, end, primes[i]);\n\t\treturn result;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eca86a3de1e0d992c2f65288c2fe030e", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2", "difficulty": 2400} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class C {\n private static final BigInteger MOD = new BigInteger(\"1000000007\");\n \n public static void main(String[] args) throws Exception {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n StringTokenizer st = new StringTokenizer(in.readLine());\n int x = Integer.parseInt(st.nextToken());\n BigInteger n = new BigInteger(st.nextToken());\n\n System.out.println(solve(x, n));\n\n in.close();\n }\n\n private static BigInteger solve(int x, BigInteger n) {\n List primes = findPrimes(x);\n\n BigInteger result = BigInteger.ONE;\n\n for (int p : primes) {\n BigInteger prime = new BigInteger(Integer.toString(p));\n BigInteger numPrime = BigInteger.ZERO;\n\n for (BigInteger i = prime; i.compareTo(n) <= 0; i = i.multiply(prime)) {\n numPrime = numPrime.add(n.divide(i));\n }\n\n BigInteger power = modPower(prime, numPrime);\n\n result = result.multiply(power).mod(MOD);\n }\n\n return result.mod(MOD);\n }\n \n private static List findPrimes(int x) {\n List primes = new ArrayList<>();\n\n int i = 2;\n while (x > 1) {\n if (x % i == 0) {\n primes.add(i);\n\n while (x % i == 0) {\n x /= i;\n }\n }\n\n i++;\n }\n\n return primes;\n }\n\n private static BigInteger modPower(BigInteger prime, BigInteger numPrime) {\n if (numPrime == BigInteger.ZERO) {\n return BigInteger.ONE;\n }\n\n if (numPrime.mod(BigInteger.TWO) == BigInteger.ZERO) {\n BigInteger result = modPower(prime, numPrime.divide(BigInteger.TWO)).mod(MOD);\n\n return result.multiply(result).mod(MOD);\n }\n\n return modPower(prime, numPrime.subtract(BigInteger.ONE))\n .mod(MOD)\n .multiply(prime)\n .mod(MOD);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bef7f25821c78aaef65700f39f8fa089", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author dmytro.prytula prituladima@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n CPrimesAndMultiplication solver = new CPrimesAndMultiplication();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CPrimesAndMultiplication {\n int MODULO = (int) 1e9 + 7;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\n long x = in.nextLong();\n long n = in.nextLong();\n\n long ans = 1;\n\n List primeFactors = Main.factorize(x);\n for (Main.LongIntPair primeFactor : primeFactors) {\n long pow = 0;\n long p = primeFactor.first;\n long prime = primeFactor.first;\n for (int i = 0; i <= 63; i++) {\n long d = n / p;\n if (d <= 0) break;\n pow += d;\n\n long overflowCheck = p;\n p *= prime;//check for overflow\n if (p / overflowCheck != prime) {\n break;\n }\n }\n\n ans *= Main.power_mod(prime, pow, MODULO);\n ans %= MODULO;\n\n }\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 private 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 return Long.parseLong(this.nextToken(), 10);\n }\n\n public String nextToken() {\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 private boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n private static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n 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 OutputWriter println(long i) {\n writer.println(i);\n return this;\n }\n\n }\n\n static final class Main {\n public static List factorize(long number) {\n List result = new ArrayList<>();\n for (long i = 2; i * i <= number; i++) {\n if (number % i == 0) {\n int power = 0;\n do {\n power++;\n number /= i;\n } while (number % i == 0);\n result.add(Main.LongIntPair.makePair(i, power));\n }\n }\n if (number != 1) {\n result.add(Main.LongIntPair.makePair(number, 1));\n }\n return result;\n }\n\n static long power_mod(long a, long pow, long mod) {\n long res = 1;\n a = a % mod;\n while (pow > 0) {\n if ((pow & 1) == 1)\n res = (res * a) % mod;\n pow = pow >> 1;\n a = (a * a) % mod;\n }\n return res;\n }\n\n public static class LongIntPair implements Comparable {\n public final long first;\n public final int second;\n\n public static Main.LongIntPair makePair(long first, int second) {\n return new Main.LongIntPair(first, second);\n }\n\n public LongIntPair(long first, int 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 Main.LongIntPair pair = (Main.LongIntPair) o;\n\n return first == pair.first && second == pair.second;\n }\n\n public int hashCode() {\n int result = Long.hashCode(first);\n result = 31 * result + Integer.hashCode(second);\n return result;\n }\n\n public String toString() {\n return \"(\" + first + \",\" + second + \")\";\n }\n\n public int compareTo(Main.LongIntPair o) {\n int value = Long.compare(first, o.first);\n if (value != 0) {\n return value;\n }\n return Integer.compare(second, o.second);\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fb7a80fe2da1fe04e732f178a23ecbe7", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700} {"lang": "Java 8", "source_code": "//package com.prituladima.codeforce;\n\n\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.util.Arrays.stream;\nimport static java.util.stream.IntStream.range;\n\npublic final class Main {\n\n private static final long MODULO = (int) 1e9 + 7;\n\n private void solve() {\n\n long x = nextLong();\n long n = nextLong();\n\n long ans = 1;\n\n List primeFactors = factorize(x);\n for (LongIntPair primeFactor : primeFactors) {\n long pow = 0;\n long p = primeFactor.first;\n long prime = primeFactor.first;\n for (int i = 0; i <= 63; i++) {\n long d = n / p;\n if(d <= 0) break;\n pow += d;\n\n long overflowCheck = p;\n p*=prime;//check for overflow\n if(p / overflowCheck != prime){\n break;\n }\n }\n\n ans *= power_mod(prime, pow, MODULO);\n ans %= MODULO;\n\n }\n\n\n println(ans);\n\n }\n\n public static List factorize(long number) {\n List result = new ArrayList<>();\n for (long i = 2; i * i <= number; i++) {\n if (number % i == 0) {\n int power = 0;\n do {\n power++;\n number /= i;\n } while (number % i == 0);\n result.add(LongIntPair.makePair(i, power));\n }\n }\n if (number != 1) {\n result.add(LongIntPair.makePair(number, 1));\n }\n return result;\n }\n\n public static class LongIntPair implements Comparable {\n public final long first;\n public final int second;\n\n public static LongIntPair makePair(long first, int second) {\n return new LongIntPair(first, second);\n }\n\n public LongIntPair(long first, int second) {\n this.first = first;\n this.second = second;\n }\n\n @Override\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 LongIntPair pair = (LongIntPair) o;\n\n return first == pair.first && second == pair.second;\n }\n\n @Override\n public int hashCode() {\n int result = Long.hashCode(first);\n result = 31 * result + Integer.hashCode(second);\n return result;\n }\n\n\n @Override\n public String toString() {\n return \"(\" + first + \",\" + second + \")\";\n }\n\n @SuppressWarnings({\"unchecked\"})\n public int compareTo(com.prituladima.yaal.generated.collections.pair.LongIntPair o) {\n int value = Long.compare(first, o.first);\n if (value != 0) {\n return value;\n }\n return Integer.compare(second, o.second);\n }\n }\n\n static long power_mod(long a, long pow, long mod) {\n long res = 1;\n a = a % mod;\n while (pow > 0) {\n if ((pow & 1) == 1)\n res = (res * a) % mod;\n pow = pow >> 1;\n a = (a * a) % mod;\n }\n return res;\n }\n\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n private PrintWriter writer;\n\n private void run() {\n try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out))) {\n this.reader = reader;\n this.writer = writer;\n this.tokenizer = null;\n solve();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n\n private int nextInt(int radix) {\n return parseInt(nextToken(), radix);\n }\n\n private int nextInt() {\n return parseInt(nextToken());\n }\n\n private long nextLong(int radix) {\n return parseLong(nextToken(), radix);\n }\n\n private long nextLong() {\n return parseLong(nextToken());\n }\n\n private double nextDouble() {\n return parseDouble(nextToken());\n }\n\n private int[] nextArr(int size) {\n return stream(new int[size]).map(c -> nextInt()).toArray();\n }\n\n private long[] nextArrL(int size) {\n return stream(new long[size]).map(c -> nextLong()).toArray();\n }\n\n private double[] nextArrD(int size) {\n return stream(new double[size]).map(c -> nextDouble()).toArray();\n }\n\n private char[][] nextCharMatrix(int n) {\n return range(0, n).mapToObj(i -> nextToken().toCharArray()).toArray(char[][]::new);\n }\n\n private int[][] nextIntMatrix(final int n, final int m) {\n return range(0, n).mapToObj(i -> nextArr(m)).toArray(int[][]::new);\n }\n\n private double[][] nextDoubleMatrix(final int n, final int m) {\n return range(0, n).mapToObj(i -> nextArrD(m)).toArray(double[][]::new);\n }\n\n private 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 private void printf(String format, Object... args) {\n writer.printf(format, args);\n }\n\n private void print(Object o) {\n writer.print(o);\n }\n\n private void println() {\n writer.println();\n }\n\n private void println(Object o) {\n print(o);\n println();\n }\n\n private void flush() {\n writer.flush();\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "18b8a1d19810b6a405a25048bfe8b48e", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700} {"lang": "Java 8", "source_code": "mport java.util.*;\nimport java.lang.*;\n// StringBuilder uses java.lang\n \n \npublic class mainClass {\n \n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n ArrayList> listOfPrimes = new ArrayList<>();\n int r = n*1;\n for (int i=2;i<=sqrt(n);i++) {\n if (r == 1) {\n break\n }\n if (r % i == 0) {\n ArrayList primeFact = new ArrayList<>();\n primeFact.add(i);\n }\n int t = 0;\n while(r % i == 0) {\n t+=1;\n r/=i;\n }\n primeFact.add(t);\n listOfPrimes.add(primeFact);\n }\n int g = sc.nextInt();\n int ans = 1;\n for (int i=0;ilistOfPrimes.get(i).get(0)) {\n break;\n } else {\n int ok = ((listOfPrimes.get(i).get(1))*(g-listOfPrimes.get(i).get(0)+1) % 10**9+6);\n ans*=fastPow(listOfPrimes.get(i).get(0),ok,10**9+7);\n ans%=(10**9+7);\n }\n }\n System.out.println(ans);\n }\n public static int fastPow(base,exp,mod) {\n ans=1;\n if (exp==0) {\n return 1;\n } else {\n if (exp % 2 == 1) {\n int z = fastPow(base,exp/2,mod);\n return ((((z*base) % mod) * z) % mod);\n } else {\n int z = fastPow(base,exp/2,mod);\n return ((z*z) % mod);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b46474de1edaff02beb1a1f28f752dd1", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class A{\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 r = in.nextInt();\n int min;\n int a;\n for (int i =0; imax)max =a;\n }\n int ko=r/min;\n int r1=ko*max + r%min;\n if (r>= r1) System.out.println(r);\n else System.out.println(r1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "36c825a1ee96e121de4394a6b4bb34f3", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800} {"lang": "Java 8", "source_code": "import javax.annotation.processing.SupportedSourceVersion;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.lang.management.BufferPoolMXBean;\nimport java.nio.Buffer;\nimport java.util.Arrays;\nimport java.util.Scanner;\npublic class Chess {\n public static void main(String[] args)\n {\n Scanner input = new Scanner(System.in);\n int[] k = new int[3];\n for(int i = 0; i < 3; i++)\n {\n k[i] = input.nextInt();\n }\n int[] m = new int[k[0]];\n for(int i = 0; i n[k[1] -1])\n {\n System.out.println(k[2]);\n }\n else\n {\n int l;\n l = (int) Math.floor(k[2] / m[0]);\n l = l * n[k[1] - 1] + (k[2] - l * m[0]);\n System.out.println(l);\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4cbfdc86e5331746e2f673bcc065429f", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[]args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int m=sc.nextInt();\n int r=sc.nextInt();\n \n int min=0;\n for (int i=1;i<=n;i++){\n int s=sc.nextInt();\n if(s[] edge ;\n\tpublic static void main(String[] args) {\n\t\t\n\t\t int n = sc.nextInt();\n\t int m = sc.nextInt();\n\t int r = sc.nextInt();\n\t int minn = Integer.MAX_VALUE,maxm = Integer.MIN_VALUE;\n\t for(int i=0;i map, int i) {\n\t\t// TODO Auto-generated method stub\n\t\tif(map.containsKey(i)) map.put(i, map.get(i)+1);\n\t\telse map.put(i, 1);\n\t\t\n\t}\n\tprivate static void delete(TreeMap map, int i) {\n\t\tif(map.containsKey(i)) {\n\t\t\tif(map.get(i) == 1) map.remove(i);\n\t\t\telse map.put(i, map.get(i)-1);\n\t\t}\n\t\t\n\t}\n\t}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "218c6f1ec480b0f672b5fe8aaea76cc1", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\nimport rounds.q1.Scanner;\n\npublic class q4 {\n public static void main(String[] args) throws IOException {\n\t Scanner sc = new Scanner(System.in);\n\t\t\n}\n static class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\t\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\t\n\t\tpublic long nextlong() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tlong 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\t\t\t\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9d821c4953102fd568b5943273003df3", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Vector;\n\n/**\n *\n * @author user\n */\npublic class NewMain3 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner sc = new Scanner (System.in);\n int n = sc.nextInt();\n int b = sc.nextInt();\n int s[] = new int[n];\n for(int i = 0 ; i < n ; i++){\n s[i] = sc.nextInt();\n }\n \n int even = 0 , odd = 0 ;\n Vector v = new Vector<>();\n \n for(int i = 0 ; i < n ; i++)\n {\n if(odd==even && i!=0){\n v.add(Math.abs(s[i] - s[i-1]));\n } \n if(s[i]%2==0)even++;\n else odd++;\n \n } \n \n int w [] = new int[v.size()];\n for(int i = 0 ; i < v.size() ; i++)\n {\n w[i] = (int)(v.get(i)) ;\n }\n \n \n Arrays.sort(w);\n int counter =0 ; \n for(int i = 0 ; i < w.length ; i++)\n {\n if(w[i] =< b){b-=w[i]; counter++;}\n else{break;}\n }\n System.out.println(counter);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "31f666cb7904090d1e185aad0b1ac5e5", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200} {"lang": "Java 8", "source_code": "public class pdd {\n public static void main(String[] args) {\n // TODO code application logic here\n Vector v =new Vector();\n v.add(Integer.SIZE);\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n int c=in.nextInt();\n int a[][]=new int[n][2];\n int arr[]=new int[n];\n for(int i=0;i0)\n count++;\n }\n \n System.out.println(count); \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bbd16ba24e0b5aaba526237b27e821d3", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200} {"lang": "Java 8", "source_code": "package cut;\n\nimport java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; public class Solution { static class InputReader \t{ \t private final InputStream stream; \t private final byte[] buf = new byte[8192]; \t private int curChar, snumChars; \t public InputReader(InputStream st) { \t this.stream = st; \t } \t public int read() { \t if (snumChars == -1) \t throw new InputMismatchException(); \t if (curChar >= snumChars) { \t curChar = 0; \t try { \t snumChars = stream.read(buf); \t } catch (IOException e) { \t throw new InputMismatchException(); \t } \t if (snumChars <= 0) \t return -1; \t } \t return buf[curChar++]; \t } \t public int nextInt() { \t int c = read(); \t while (isSpaceChar(c)) { \t c = read(); \t } \t int sgn = 1; \t if (c == '-') { \t sgn = -1; \t c = read(); \t } \t int res = 0; \t do { \t res *= 10; \t res += c - '0'; \t c = read(); \t } while (!isSpaceChar(c)); \t return res * sgn; \t } \t public long nextLong() { \t int c = read(); \t while (isSpaceChar(c)) { \t c = read(); \t } \t int sgn = 1; \t if (c == '-') { \t sgn = -1; \t c = read(); \t } \t long res = 0; \t do { \t res *= 10; \t res += c - '0'; \t c = read(); \t } while (!isSpaceChar(c)); \t return res * sgn; \t } \t public int[] nextIntArray(int n) { \t int a[] = new int[n]; \t for (int i = 0; i < n; i++) { \t a[i] = nextInt(); \t } \t return a; \t } \t public String readString() { \t int c = read(); \t while (isSpaceChar(c)) { \t c = read(); \t } \t StringBuilder res = new StringBuilder(); \t do { \t res.appendCodePoint(c); \t c = read(); \t } while (!isSpaceChar(c)); \t return res.toString(); \t } \t public String nextLine() { \t int c = read(); \t while (isSpaceChar(c)) \t c = read(); \t StringBuilder res = new StringBuilder(); \t do { \t res.appendCodePoint(c); \t c = read(); \t } while (!isEndOfLine(c)); \t return res.toString(); \t } \t public boolean isSpaceChar(int c) { \t return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; \t } \t private boolean isEndOfLine(int c) { \t return c == '\\n' || c == '\\r' || c == -1; \t } \t} /*static class node implements Comparable { int index; int val; node(int a1,int a2) { index=a1; val=a2; } public int compareTo(node n1) { return(this.val-n1.val); } }*/ public static void main(String[] args) throws IOException { InputReader in=new InputReader(System.in); int n=in.nextInt(); int b=in.nextInt(); int [] a=new int[n]; a=in.nextIntArray(n); int[] odd=new int[n+1]; int[] even=new int[n+1]; odd[0]=0; even[0]=0; for(int i=1;i<=n;i++) { if(a[i-1]%2==1) { odd[i]=odd[i-1]+1; even[i]=even[i-1]; } else { odd[i]=odd[i-1]; even[i]=even[i-1]+1; } } int prev=0; PriorityQueue cost=new PriorityQueue(); for(int i=1;i<=n-1;i++) { int oc=odd[i]-odd[prev]; int ec=even[i]-even[prev]; if(oc==ec) { cost.add((int)Math.abs(a[i]-a[i-1])); //System.out.println((int)Math.abs(a[i]-a[i-1])); prev=i; } } int sum=0; int count=0; while(!cost.isEmpty() && sum<=b) { sum+=cost.peek().intValue(); cost.poll(); count++; } if(count==0) { System.out.println(\"0\"); } else { if(cost.isEmpty() && sum<=b) { System.out.println(count); } else { System.out.println(count-1); } } } }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b7c849f17c0dd2e1292456fdc342a216", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200} {"lang": "Java 6", "source_code": "\npublic class A {\n public void run() {\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n int n = s.length();\n String[] ss = new String[n];\n for (int i = 0; i < n; i++)\n ss[i] = s.substring(i);\n sort(ss);\n int res = 0;\n for (int i = 1; i < n; i++)\n res = max(res, count(ss[i - 1], ss[i]));\n System.out.println(res);\n }\n\n int count(String s, String t) {\n int ret = 0;\n for (int i = 0; i < min(s.length(), t.length()); i++)\n if (s.charAt(i) != t.charAt(i))\n return ret;\n else\n ret++;\n return ret;\n }\n\n void debug(Object... os) {\n System.err.println(Arrays.deepToString(os));\n }\n\n public static void main(String... args) {\n new A().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "04acb1eaae385f8e19c346b291a77c3f", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7", "difficulty": 1200} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n public static void main(String ...args) throws Throwable {\n Scanner in = new Scanner(System.in);\n String init = in.nextLine();\n HashSet h = new HashSet();\n for (int len = init.length() - 1; len >= 1; --len) {\n h.clear();\n for (int pos = 0; pos + len <= init.length(); ++pos) {\n String now = init.substring(pos, pos + len);\n if (h.contains(now)) {\n System.out.println(len);\n return;\n }\n h.put(now);\n }\n\n }\n\n System.out.println(0);\n }\n}\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f189eec24d1167045c61dbf61f887fe", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class String {\n public static void main(String[] args) {\n Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n String s = sc.next();\n int[] alphabet = new int[26];\n\n for(int i = 0; i < s.length(); i++) {\n alphabet[s.charAt(i)-97]++;\n }\n\n int max = alphabet[0];\n for(int i = 0; i < alphabet.length; i++)\n if(alphabet[i] > max) max = alphabet[i];\n System.out.println(max);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b85d658c0a225aed03cf9cb2aa0dab93", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7", "difficulty": 1200} {"lang": "Java 6", "source_code": "\npublic class OverlapedString {\n\tpublic static void main(String args[]) {\n\t\tOverlapedString os = new OverlapedString();\n\t\tSystem.out.println(os.handleOverlap(args[0]));\n\t}\n\tprivate int handleOverlap(String str) {\n\t\tint len = str.length();\n\t\tint count = 0;\n\t\tfor(int i=0;i0) {\n\t\t\t\t\tif(getOverlapCount(str,_tmp)>1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(_tmp.length()>count)\n\t\t\t\t\t\t\tcount = _tmp.length();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\treturn count;\n\t}\n\tprivate int getOverlapCount(String str,String sub) {\n\t\tint start = 0;\n\t\tint count = 0;\n\t\twhile(start controllerPos) {\n\t\t\t\t\tif(stowAwayPos < numWagons) {\n\t\t\t\t\t\tstowAwayPos++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif(stowAwayPos > 1) {\n\t\t\t\t\t\tstowAwayPos--;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif(toHead) {\n\t\t\t\t\tcontrollerPos--;\n\t\t\t\t} else {\n\t\t\t\t\tcontrollerPos++;\n\t\t\t\t}\n\t\t\t} else { //Standing still\n\t\t\t\t//Stowaway leaves the train\n\n\t\t\t\tif(toHead) {\n\t\t\t\t\tcontrollerPos--;\n\t\t\t\t} else {\n\t\t\t\t\tcontrollerPos++;\n\t\t\t\t}\n\n\t\t\t\tif(!toHead) {\n\t\t\t\t\tif(controllerPos > 1) {\n\t\t\t\t\t\tstowAwayPos = 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstowAwayPos = numWagons;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif(controllerPos < numWagons) {\n\t\t\t\t\t\tstowAwayPos = numWagons;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstowAwayPos = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif(toHead && controllerPos == 1) {\n\t\t\t\ttoHead = !toHead;\n\t\t\t} else if(!toHead && controllerPos == numWagons) {\n\t\t\t\ttoHead = !toHead;\n\t\t\t}\n\n\t\t\t//System.out.println(stowAwayPos + \" \" + controllerPos);\n\n\t\t\tif(stowAwayPos == controllerPos) {\n\t\t\t\tSystem.out.println(\"Controller \" + (i+1));\n\t\t\t\tcontrollerWon = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif(!controllerWon) {\n\t\t\tSystem.out.println(\"Stowaway\");\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2fbf63ea42ecc647d3edae7b9fdcc1e5", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class train\n{\n\tpublic static void main(String[] Args)\n\t{\n\t\tScanner p = new Scanner(System.in);\n\t\tint n=p.nextInt();\n\t\tint me=p.nextInt();\n\t\tint tt=p.nextInt();\n\t\tScanner pp=new Scanner(System.in);\n\t\tString move=pp.nextLine();\n\t\tString Schedule= pp.nextLine();\n\t\tchar minute[]= new char[Schedule.length()];\n\t\tint ttmove=0;\n\t\tif(move.charAt(3)=='h')\n\t\t{\n\t\t\tttmove=-1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tttmove=1;\n\t\t}\n\t\tint c=0;\n\t\twhile((ctt)\n\t\t\t\t{\n\t\t\t\t\tif(me!=n)\n\t\t\t\t\t{\n\t\t\t\t\t\tme++;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif((me-1)!=tt)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(me!=1)\n\t\t\t\t\t{\n\t\t\t\t\t\tme--;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif((ttmove==1)&&(tt!=1))\n\t\t\t\t{\n\t\t\t\t\tme=tt-1;\n\t\t\t\t}\n\t\t\t\telse if((ttmove==-1)&&(tt!=n))\n\t\t\t\t{\n\t\t\t\t\tme=tt+1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tme+=ttmove;\n\t\t\t\t}\n\t\t\t}\n\t\t\tc++;\n\t\t\ttt+=ttmove;\n\t\t\tif(tt==n)\n\t\t\t{\n\t\t\t\tttmove=-1;\n\t\t\t}\n\t\t\telse if(tt==1)\n\t\t\t{\n\t\t\t\tttmove=1;\n\t\t\t}\n\t\t}\n\t\tif(c==Schedule.length())\n\t\t{\n\t\t\tSystem.out.println(\"Stowaway\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(\"Controller \"+c);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "265fc8097f5d951f97a0a59d01e7f50a", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500} {"lang": "Java 6", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\npackage srm68;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author dody\n */\npublic class ProbB {\n int n,c,s;\n String dir;\n\n public void moveC(){\n if(dir.equals(\"to head\") && n !=1)\n c--;\n else if(n != 1)\n c++;\n\n if(c == 0){\n c = 2;\n dir = \"to tail\";\n }\n if(c == n + 1){\n c = n-1;\n dir = \"to head\";\n }\n }\n\n public void moveS(){\n int r = Math.abs(c-(s+1));\n int l = Math.abs(c-(s-1));\n if(r > l){\n if(s+1 <= n )\n s++;\n }else{\n if(s-1 > 0)\n s--;\n }\n }\n\n public void enterTrain(){\n if(dir.equals(\"to head\")){\n if(c != n)\n s = n;\n else\n s = 1;\n }else{\n if(c != 1)\n s = 1;\n else\n s = n;\n }\n }\n public void run(){\n Scanner scanner = new Scanner(System.in);\n n = scanner.nextInt();\n s = scanner.nextInt();\n c = scanner.nextInt();\n scanner.nextLine();\n dir = scanner.nextLine();\n String timeLine = scanner.nextLine();\n\n for (int i = 0; i < timeLine.length(); i++) {\n if(timeLine.charAt(i) == '0'){\n moveS();\n moveC();\n if(c == s){\n System.out.println(\"Controller \"+(i+1));\n return;\n }\n \n }else{\n s = -1;\n moveC();\n enterTrain();\n if(c == s){\n System.out.println(\"Controller \"+(i+1));\n return;\n }\n } \n }\n System.out.println(\"Stowaway\");\n }\n public static void main(String[] args){\n new ProbB().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "782fb45057c7daa971a0479f8ebcd69e", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main {\n\n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n StringTokenizer s = new StringTokenizer(in.nextLine());\n int n = Integer.parseInt(s.nextToken()), passenger=Integer.parseInt(s.nextToken()),\n controller=Integer.parseInt(s.nextToken());\n\n boolean napravl = in.nextLine().equals(\"to tail\");\n char[] sost = in.nextLine().toCharArray();\n int ans=-1;\n\n for(int i=1; i<=sost.length; i++){\n boolean que=(sost[i-1] == '0');\n if(que){\n if(controller>passenger){\n if(passenger!=1)\n passenger--;\n if(napravl){\n if(controller==n){\n napravl=!napravl;\n controller--;\n }\n else controller++;\n if(passenger==controller){\n ans=i;\n break;\n }\n }\n else{\n if(controller==1){\n napravl=!napravl;\n controller++;\n }\n else controller--;\n if(passenger==controller){\n ans=i;\n break;\n }\n }\n }\n else{\n if(passenger!=n)\n passenger++;\n if(napravl){\n if(controller==n){\n napravl=!napravl;\n controller--;\n }\n else controller++;\n if(passenger==controller){\n ans=i;\n break;\n }\n }\n else{\n if(controller==1){\n napravl=!napravl;\n controller++;\n }\n else controller--;\n if(passenger==controller){\n ans=i;\n break;\n }\n }\n }\n }\n else{\n if(napravl){\n if(controller==n){\n controller--;\n napravl=!napravl;\n }\n else{\n controller++;\n }\n if(napravl) passenger=1;\n else passenger=n;\n }\n else{\n if(controller==1){\n controller++;\n napravl=!napravl;\n }\n else{\n controller--;\n }\n if(!napravl) passenger=1;\n else passenger=n;\n }\n }\n }\n if(ans==-1&&n!=2)\n out.print(\"Stowaway\");\n else{\n out.print(\"Controller \");\n if(n==2){\n int j=0;\n while(sost[j]!='0')\n j++;\n out.print(j+1);\n }\n else\n out.print(ans);\n }\n\n out.close();\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b3f9c177b0757aed75eb2eca5f675612", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\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\tPrintWriter out = new PrintWriter(outputStream);\n\t\tSolver solver = new Solver();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n}\n\nclass Solver {\n\tint mn = Integer.MAX_VALUE;\n\tint MAX = 105;\n\tpublic void solve(InputReader in, PrintWriter out) {\n\t\tint hy = in.nextInt();\n\t\tint ay = in.nextInt();\n\t\tint dy = in.nextInt();\n\t\tint hm = in.nextInt();\n\t\tint am = in.nextInt();\n\t\tint dm = in.nextInt();\n\t\tint hc = in.nextInt();\n\t\tint ac = in.nextInt();\n\t\tint dc = in.nextInt();\n\t\tfor (int dh = 0; dh < MAX; dh++) {\n\t\t\tfor (int da = 0; da < MAX; da++) {\n\t\t\t\tfor (int dd = 0; dd < MAX; dd++) {\n\t\t\t\t\tint hn = hy + dh;\n\t\t\t\t\tint an = ay + da;\n\t\t\t\t\tint dn = dy + dd;\n\t\t\t\t\tint damy = Math.max(an - dm, 0);\n\t\t\t\t\tint damm = Math.max(am - dn, 0);\n\t\t\t\t\tif (damy == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tint num = (hm + damy - 1)/ damy;\n\t\t\t\t\tif (hn - damm * num > 0) {\n\t\t\t\t\t\tmn = Math.min(mn, dh * hc + da * ac + dd * dc);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(mn);\n\t\t\n\t}\n}\n\nclass InputReader {\n\tprivate BufferedReader reader;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\ttokenizer = null;\n\t}\n\n\tpublic String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b88878e523e7d0c30ea8634b29d801e3", "src_uid": "bf8a133154745e64a547de6f31ddc884", "difficulty": 1800} {"lang": "Java 8", "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 h1 = nextInt();\n int atk1 = nextInt();\n int def1 = nextInt();\n int h2 = nextInt();\n int atk2 = nextInt();\n int def2 = nextInt();\n int ch = nextInt();\n int cAtk = nextInt();\n int cDef = nextInt();\n\n int ans = Integer.MAX_VALUE / 2;\n\n for (int bH = 0; bH < 200; bH++) {\n for (int bAtk = 0; bAtk < 200; bAtk++) {\n for (int bDef = 0; bDef < 200; bDef++) {\n if (win(h1 + bH, atk1 + bAtk, def1 + bDef, h2, atk2, def2)) {\n ans = Math\n .min(ans, bH * ch + bAtk * cAtk + bDef * cDef);\n break;\n }\n }\n }\n }\n out.println(ans);\n }\n\n boolean win(int h1, int atk1, int def1, int h2, int atk2, int def2) {\n int dmg1 = Math.max(atk1 - def2, 0);\n int dmg2 = Math.max(atk2 - def1, 0);\n if (dmg1 == 0) {\n return false;\n }\n if (dmg2 == 0) {\n return true;\n }\n int need = (h2 + dmg1 - 1) / dmg1;\n return h1 - need * dmg2 > 0;\n }\n\n A() 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();\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n eof = true;\n return null;\n }\n }\n return st.nextToken();\n }\n\n String nextString() {\n try {\n return br.readLine();\n } catch (IOException e) {\n eof = true;\n return null;\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a502f49d2e551358bbbd8cb718a31d27", "src_uid": "bf8a133154745e64a547de6f31ddc884", "difficulty": 1800} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n public static void main(String[] args) throws IOException\n {\n Scanner scan = new Scanner(System.in);\n\n int hp = scan.nextInt();\n int atk = scan.nextInt();\n int def = scan.nextInt();\n\n int hpE = scan.nextInt();\n int atkE = scan.nextInt();\n int defE = scan.nextInt();\n\n int perHp = scan.nextInt();\n int perAtk = scan.nextInt();\n int perDef = scan.nextInt();\n\n int res = Integer.MAX_VALUE/2;\n\n for(int i = 0;i <= 200;i++)\n {\n hp += i;\n for(int j = 0;j <= 200;j++)\n {\n atk += j;\n for(int k = 0;k <= 200;k++)\n {\n def += k;\n\n int monsterDec = Math.max(0, atk-defE);\n int myDec = Math.max(0, atkE-def);\n\n int t1 = monsterDec == 0 ? Integer.MAX_VALUE/2 : (hpE/monsterDec);\n if(monsterDec != 0 && hpE%monsterDec != 0)\n t1++;\n\n int t2 = myDec == 0 ? Integer.MAX_VALUE/2-1 : (hp/myDec);\n if(myDec != 0 && hp%myDec == 0)\n t2--;\n\n if(t2 >= t1)\n if(res > i*perHp + j*perAtk + k*perDef)\n res = i*perHp + j*perAtk + k*perDef;\n\n def -= k;\n }\n atk -= j;\n }\n hp -= i;\n }\n\n System.out.println(res);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "061a53f1b5989a9b245c7161d1803849", "src_uid": "bf8a133154745e64a547de6f31ddc884", "difficulty": 1800} {"lang": "Java 7", "source_code": "import java.awt.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.Map.Entry;\n\nimport static java.lang.Math.*;\n\npublic class solver implements Runnable {\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tboolean HasTokens() {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tString readString() throws IOException {\n\t\treturn HasTokens() ? tok.nextToken() : null;\n\t}\n\n\tString readString(String delim) throws IOException {\n\t\treturn HasTokens() ? tok.nextToken(delim) : null;\n\t}\n\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\tlong readLong() throws IOException {\n\t\treturn Long.parseLong(readString());\n\t}\n\n\tdouble readDouble() throws IOException {\n\t\treturn Double.parseDouble(readString());\n\t}\n\n\tchar readChar() throws IOException {\n\t\tchar val = 0;\n\t\tdo {\n\t\t\tval = (char) in.read();\n\t\t} while (val == '\\n' || val == '\\r');\n\t\treturn val;\n\t}\n\n\t// ----------------------------------\n\tint gcd(int x, int y) {\n\t\twhile (y != 0) {\n\t\t\tint temp = x % y;\n\t\t\tx = y;\n\t\t\ty = temp;\n\t\t}\n\t\treturn x;\n\t}\n\n\t// ----------------------------------\n\n\tpublic class Pair {\n\t\tpublic T1 x1;\n\t\tpublic T2 x2;\n\n\t\tpublic Pair() {\n\t\t};\n\n\t\tpublic Pair(T1 x1, T2 x2) {\n\t\t\tthis.x1 = x1;\n\t\t\tthis.x2 = x2;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x1 + \":\" + x2;\n\t\t}\n\t}\n\n\tpublic class Three implements Comparable {\n\t\tpublic int x1, x2, x3;\n\n\t\tpublic Three() {\n\t\t}\n\n\t\tpublic Three(int a, int b, int c) {\n\t\t\tx1 = a;\n\t\t\tx2 = b;\n\t\t\tx3 = c;\n\t\t}\n\n\t\tpublic int compareTo(Three o) {//\n\t\t\tif (x1 == o.x1 && x2 == o.x2)\n\t\t\t\treturn x3 - o.x3;\n\t\t\tif (x1 == o.x1)\n\t\t\t\treturn x2 - o.x2;\n\t\t\treturn (x1 - o.x1);\n\t\t\t// (x1-o.x1) - increase; -(x1-o.x1) - decrease\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x1 + \":\" + x2 + \":\" + x3;\n\t\t}\n\t}\n\n\t// ----------------------------------------\n\t\n\tboolean win(int h, int a,int d,int hm,int am,int dm){\n\t\tint cnt = 0;\n\t\tint delta1 = Math.max(0, am - d);\n\t\tint delta2 = Math.max(0, a - dm);\n\t\twhile (h > 0 || hm > 0){\n\t\t\tif (cnt == 110) return false;\n\t\t\tif (h - delta1*10 > 0){\n\t\t\t\tcnt+=10;\n\t\t\t\th-= delta1*10;\n\t\t\t\thm -= delta2*10;\n\t\t\t}else{\n\t\t\t\tcnt++;\n\t\t\t\th -= delta1;\n\t\t\t\thm -= delta2;\t\t\t\t\n\t\t\t}\t\t\t\n\t\t\tif (h <= 0) return false;\n\t\t\tif (hm <= 0 && h > 0 ) return true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\t\n\tvoid solve() throws NumberFormatException, IOException {\n\t\tint hpy = readInt();\n\t\tint atky = readInt();\n\t\tint defy = readInt();\n\t\t\n\t\t\n\t\tint hpm = readInt();\n\t\tint atkm = readInt();\n\t\tint defm = readInt();\n\t\t\n\t\tint x = readInt();\n\t\tint y = readInt();\n\t\tint z = readInt();\n\t\t\n\t\tint cost = Integer.MAX_VALUE;\n\t\t\n\t\tfor (int i=0;i<=100;i++){\n\t\t\tfor (int j=0;j<=100;j++){\n\t\t\t\tfor (int k=0;k<=100;k++){\n\t\t\t\t\tif (win(hpy+i,atky+j,defy+k,hpm,atkm,defm)){\n\t\t\t\t\t\tcost = Math.min(cost, i*x+j*y+k*z);\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(cost);\n\t\t\n\t}\n\t\n\n\t// ----------------------------------------\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new solver(), \"\", 256 * (1L << 20)).start();\n\t}\n\t\n\n\tpublic void run() {\n\t\ttry {\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\ttry {\n\t\t\t\tif (ONLINE_JUDGE) {\n\t\t\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t\t\t//in = new BufferedReader(new FileReader(\"exam.in\"));\n\t\t\t\t\t//out = new PrintWriter(\"exam.out\");\n\t\t\t\t} else {\n\t\t\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\t\t}\n\t\t\t} catch (Throwable e) {\n\t\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t}\n\t\t\tsolve();\n\t\t\tout.close();\n\n\t\t\ttimeEnd = System.currentTimeMillis();\n\t\t\tif (!ONLINE_JUDGE)System.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\tRandom r = new Random();\n\n\tlong timeBegin, timeEnd;\n\n\t// ----------\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "19c73e31c9c1ccfb20a67efbf4dc8c41", "src_uid": "bf8a133154745e64a547de6f31ddc884", "difficulty": 1800} {"lang": "Java 8", "source_code": "package B;\nimport 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\tint n=sc.nextInt();\n\t\tString s=sc.next();\n\t\tint flag1=0;\n\t\tint flag2=0;\n\t\tint flag3=0;\n\t\tint max=-1;\n\t\tint cur=0;\n\t\tint cur2=0;\n\t\tint number=0;\n\t\tboolean start=false;\n\t\tfor(int i=0;i0&&s.charAt(i)=='_'){\n\t\t\t\t\tmax=Math.max(max, cur);\n\t\t\t\t\tcur=0;\n\t\t\t\t}\n\t\t\t\tif(cur>0&&s.charAt(i)=='('){\n\t\t\t\t\tmax=Math.max(max, cur);\n\t\t\t\t\tcur=0;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t}\n\t\t if(flag2==1){\n\t\t \tif(isAlpha(s.charAt(i))){\n\t\t \t\tcur2++;\n\t\t \t}\n\t\t \tif(s.charAt(i)=='_'||s.charAt(i)==')'){\n\t\t \t\tif(cur2>0){\n\t\t \t\t\tnumber++;\n\t\t \t\t\tcur2=0;\n\t\t \t\t}\n\t\t \tif(s.charAt(i)==')'){\n\t\t \t\tflag2=0;\n\t\t \t}\n\t\t \t}\n\t\t }\n\t\t if(s.charAt(i)=='('){\n\t\t\t\tflag2=1;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\tif(cur>0){\n\t\t\tmax=Math.max(max, cur);\n\t\t\tcur=0;\n\t\t}\n\t\tif(max==-1){\n\t\t\tSystem.out.print(0+\" \");\n\t\t}\n\t\telse\n\t\tSystem.out.print(max+\" \");\n\t\tSystem.out.println(number);\n\t}\nstatic boolean isAlpha(char a){\n\tif((a>='A'&&a<='Z')||(a>='a'&&a<='z')){\n\t\treturn true;\n\t}\n\telse\n\t\treturn false;\n}\n}package B;\nimport 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\tint n=sc.nextInt();\n\t\tString s=sc.next();\n\t\tint flag1=0;\n\t\tint flag2=0;\n\t\tint flag3=0;\n\t\tint max=-1;\n\t\tint cur=0;\n\t\tint cur2=0;\n\t\tint number=0;\n\t\tboolean start=false;\n\t\tfor(int i=0;i0&&s.charAt(i)=='_'){\n\t\t\t\t\tmax=Math.max(max, cur);\n\t\t\t\t\tcur=0;\n\t\t\t\t}\n\t\t\t\tif(cur>0&&s.charAt(i)=='('){\n\t\t\t\t\tmax=Math.max(max, cur);\n\t\t\t\t\tcur=0;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t}\n\t\t if(flag2==1){\n\t\t \tif(isAlpha(s.charAt(i))){\n\t\t \t\tcur2++;\n\t\t \t}\n\t\t \tif(s.charAt(i)=='_'||s.charAt(i)==')'){\n\t\t \t\tif(cur2>0){\n\t\t \t\t\tnumber++;\n\t\t \t\t\tcur2=0;\n\t\t \t\t}\n\t\t \tif(s.charAt(i)==')'){\n\t\t \t\tflag2=0;\n\t\t \t}\n\t\t \t}\n\t\t }\n\t\t if(s.charAt(i)=='('){\n\t\t\t\tflag2=1;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t}\n\t\tif(cur>0){\n\t\t\tmax=Math.max(max, cur);\n\t\t\tcur=0;\n\t\t}\n\t\tif(max==-1){\n\t\t\tSystem.out.print(0+\" \");\n\t\t}\n\t\telse\n\t\tSystem.out.print(max+\" \");\n\t\tSystem.out.println(number);\n\t}\nstatic boolean isAlpha(char a){\n\tif((a>='A'&&a<='Z')||(a>='a'&&a<='z')){\n\t\treturn true;\n\t}\n\telse\n\t\treturn false;\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dcd4f9dbb3ef9c52090ffb6dbc546d93", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100} {"lang": "Java 8", "source_code": "//Thanks to Valeh :D\n\npublic class TextDocumentAnalysis {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n String s = sc.next();\n s.toLowerCase();\n int maxL = -1;\n int nwi = 0;\n int fp = 0;\n int fw = 0;\n for(int i=0;i=cout)\n\t\t\t\t\tcout=c;\n\t\t\t\tc=0;\n\t\t\t}\n\t\t\ti++;\n\t\t\t}\n\t\t\t\n\t\t\t}\n\t\tif(c>cout)\n\t\t{\n\t\t\tcout=c;\n\t\t\tc=0;\n\t\t}\n\t\tSystem.out.print(cout+\" \"+cin);\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6a983401a2e0886bc6c6c601f874f1db", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class B375 {\n\n public static void main(String[] args){\n\n Scanner sc = new Scanner(System.in);\n String count = sc.nextLine();\n String str = sc.nextLine();\n char prev ='.';\n boolean openParenth = false;\n int maxSize = 0;\n int wordCount = 0;\n int iter=0;\n while(iter 0 && i0; j--){\n int temp=algarisms[i+j];\n algarisms[i+j]=algarisms[i+j-1];\n algarisms[i+j-1]=temp;\n }\n i++;\n subArray = new int[x+1];\n\n }\n\n double result=0;\n for(int j=nAlgarisms-1; j>=0; j--){\n result+=Math.pow(10,j)*(double)(algarisms[nAlgarisms-1-j]);\n }\n System.out.println(String.format(\"%.0f\",result));\n //System.out.println(result);\n //System.out.println(Arrays.toString(algarisms));\n\n }\n\n public static int getMaxIndexArray(int array[]){\n int max = 0;\n int index = 0;\n for(int i=0; imax){\n max=array[i];\n index=i;\n } \n }\n\n return index;\n }\n\n public static int[] getSubArray(int array[], int startIndex, int plus){\n int newArray[] = new int[plus+1];\n int endIndex = startIndex+plus= noswap){\n k -= noswap;\n int tmp = num[i];\n num[i] = maxv;\n for (int j = i+1; j <= maxind; j++) {\n int tmp2 = tmp;\n tmp = num[j];\n num[j] = tmp2;\n }\n }\n }\n }\n StringBuilder res = new StringBuilder(\"\");\n for (int i = 0; i < num.length; i++) {\n res.append(num[i]);\n }\n System.out.println(res);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "db1a5287337eff27d31c50172f2a068c", "src_uid": "e56f6c343167745821f0b18dcf0d0cde", "difficulty": 1400} {"lang": "Java 6", "source_code": "import com.sun.tools.javac.resources.legacy;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * @author arshsab\n * @since 05 2014\n */\n\npublic class PashaMaximizes {\n public static void main(String... args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n String[] log = br.readLine().split(\" \");\n\n final char[] A = log[0].toCharArray();\n int K = Integer.parseInt(log[1]);\n\n for (int i = 0; i < A.length && K > 0; i++) {\n int max = Integer.MIN_VALUE;\n int maxPos = -1;\n\n for (int j = i; j < A.length && j <= K + i; j++) {\n int fixed = A[j] - '0';\n\n if (fixed > max) {\n max = fixed;\n maxPos = j;\n }\n }\n\n if (max > A[i] - '0') {\n for (int j = maxPos - 1; j >= i; j--) {\n A[j + 1] = A[j];\n }\n\n A[i] = (char) (max + '0');\n K -= maxPos - i;\n }\n }\n\n System.out.println(new String(A));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "75fc52ce4c9318d1b494805a66f4c317", "src_uid": "e56f6c343167745821f0b18dcf0d0cde", "difficulty": 1400} {"lang": "Java 7", "source_code": "//package contest;\n\nimport java.util.*;\n\npublic class test {\n public static String num;\n\n public static void main(String[] args) {\n // Scanner sc = new Scanner(System.in);\n // String line = sc.nextLine();\n // String[] str = line.split(\" \");\n // num = str[0];\n // int []sorted = new int[num.length()];\n // Arrays.sort(sorted);\n // int swaps = Integer.parseInt(str[1]);\n\n // int nextMax;\n // while (swaps != 0) {\n // int max =0;\n // int maxPos=0;\n // int start=0;\n // for (int i = start; i < num.length() && i < swaps; i++) {\n // int current = Integer.parseInt(num.charAt(i) + \"\");\n // if(current > max){\n // max = current;\n // maxPos=i;\n // }\n // }//end for.\n // int newSwaps = swap(maxPos,swaps);\n // int diff= swaps -newSwaps;\n // swaps = newSwaps;\n // start = maxPos-diff+1;\n // System.out.println(start);\n // }//end while.\n // System.out.println(num);\n\n // num =\"12345678\";\n // swap(7,8);\n // System.out.println(num);\n\n Scanner sc = new Scanner(System.in);\n String line = sc.nextLine();\n String[] str = line.split(\" \");\n num = str[0];\n // int []sorted = new int[num.length()];\n // Arrays.sort(sorted);\n int swaps = Integer.parseInt(str[1]);\n Queue pq = new LinkedList();\n\n // int loopNum=9;\n // while(loopNum>0){\n // for(int i=0;i 0) {\n // System.out.println(\"swaps = \"+swaps);\n int loopNum = 9;\n pq = new LinkedList();\n while (loopNum >= 0) {\n for (int i = start; i < num.length()\n && i <= (swaps + start); i++) {\n // System.out.println(i+\" /////////////////////\");\n int number = Integer.parseInt(num.charAt(i) + \"\");\n if (number == loopNum) {\n // System.out.println(num.charAt(i)+\" , \"+i);\n pq.add(i);\n }\n }\n loopNum--;\n // System.out.println(loopNum+\"--------------------------\");\n }// end while\n\n int next = pq.poll();\n // System.out.println(next);\n int newSwaps = swap(next, swaps);\n int diff = swaps - newSwaps;\n swaps = newSwaps;\n start = next - diff + 1;\n // System.out.println(\"start = \"+start);\n }\n System.out.println(num);\n }\n }// end main\n\n public static int swap(int pos, int swaps) {\n // System.out.println(pos +\" , \"+swaps );\n int number = Integer.parseInt(num.charAt(pos) + \"\");\n int newPos = pos - 1;\n while ((newPos >= 0)\n && Integer.parseInt(num.charAt(newPos) + \"\") < number\n && swaps > 0) {\n swaps--;\n newPos--;\n\n }\n String newNum = \"\";\n for (int j = 0; j <= newPos; j++) {\n newNum += num.charAt(j);\n }\n newNum += number;\n for (int j = newPos + 1; j < pos; j++) {\n newNum += num.charAt(j);\n }\n for (int j = pos + 1; j < num.length(); j++) {\n newNum += num.charAt(j);\n }\n num = newNum;\n return swaps;\n }\n}// end class\n// 9090000078001234 6", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c087128a7f7d953a771860bfcd00c76b", "src_uid": "e56f6c343167745821f0b18dcf0d0cde", "difficulty": 1400} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class icpc\n{\n public static void main(String[] args) throws IOException\n {\n Reader in = new Reader();\n// BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n long M = 1000000009;\n long n = in.nextLong();\n long m = in.nextLong();\n long k = in.nextLong();\n long score = 0L;\n long threshold1 = (long)Math.floor((double)n / k) * (k - 1) + (n % k);\n if (m <= threshold1)\n System.out.println(m % M);\n else\n {\n long cutPoint = binarySearch(n, k, m);\n BigInteger b1 = BigInteger.TWO.pow((int)cutPoint + 1).subtract(BigInteger.TWO).multiply(BigInteger.valueOf(k));\n BigInteger b2 = BigInteger.valueOf(m).subtract(BigInteger.valueOf(k).multiply(BigInteger.valueOf(cutPoint)));\n b1 = b1.add(b2);\n b1 = b1.mod(BigInteger.valueOf(M));\n System.out.println(b1.intValue());\n }\n\n }\n public static long getValue(long n, long k)\n {\n return (long)Math.floor((double)n / k) * (k - 1) + (n % k);\n }\n public static long binarySearch(long n, long k, long m)\n {\n long l = 0;\n long ans = Long.MAX_VALUE;\n long r = (long)Math.floor((double)n / k);\n while (l <= r)\n {\n long mid = (l + r) / 2;\n if (check(n, mid, m, k))\n {\n ans = Math.min(ans, mid);\n r = mid - 1;\n }\n else\n l = mid + 1;\n }\n return ans;\n }\n public static boolean check(long n, long i, long m, long k)\n {\n if(i * k + getValue(n - i * k, k) >= m)\n return true;\n return false;\n }\n}\nclass NumberTheory\n{\n public boolean isPrime(long n)\n {\n if(n < 2)\n return false;\n for(long x = 2;x * x <= n;x++)\n {\n if(n % x == 0)\n return false;\n }\n return true;\n }\n public ArrayList primeFactorisation(int n)\n {\n ArrayList f = new ArrayList<>();\n for(int x=2;x * x <= n;x++)\n {\n while(n % x == 0)\n {\n f.add(x);\n n /= x;\n }\n }\n if(n > 1)\n f.add(n);\n return f;\n }\n public int[] sieveOfEratosthenes(int n)\n {\n int[] sieve = new int[n + 1];\n for(int x=2;x<=n;x++)\n {\n if(sieve[x] != 0)\n continue;\n sieve[x] = x;\n for(int u=2*x;u<=n;u+=x)\n if(sieve[u] == 0)\n sieve[u] = x;\n }\n return sieve;\n }\n public long gcd(long a, long b)\n {\n if(b == 0)\n return a;\n return gcd(b, a % b);\n }\n public long phi(long n)\n {\n double result = n;\n\n for(long p=2;p*p<=n;p++)\n {\n if(n % p == 0)\n {\n while (n % p == 0)\n n /= p;\n result *= (1.0 - (1.0 / (double)p));\n }\n }\n if(n > 1)\n result *= (1.0 - (1.0 / (double)n));\n return (long)result;\n }\n public Name extendedEuclid(long a, long b)\n {\n if(b == 0)\n return new Name(a, 1, 0);\n Name n1 = extendedEuclid(b, a % b);\n Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y);\n return n2;\n }\n public long modularExponentiation(long a, long b, long n)\n {\n long d = 1L;\n String bString = Long.toBinaryString(b);\n for(int i=0;i= 0; --i) sa[--c[T[i]]] = i;\n for (p = 1; p < N; p <<= 1)\n {\n for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i;\n for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p;\n Arrays.fill(c, 0, ALPHABET_SZ, 0);\n for (i = 0; i < N; ++i) c[rank[i]]++;\n for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];\n for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];\n for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i)\n {\n if (!(rank[sa[i - 1]] == rank[sa[i]]\n && sa[i - 1] + p < N\n && sa[i] + p < N\n && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++;\n sa2[sa[i]] = r;\n }\n tmp = rank;\n rank = sa2;\n sa2 = tmp;\n if (r == N - 1) break;\n ALPHABET_SZ = r + 1;\n }\n }\n\n private void kasai()\n {\n lcp = new int[N];\n int[] inv = new int[N];\n for (int i = 0; i < N; i++) inv[sa[i]] = i;\n for (int i = 0, len = 0; i < N; i++)\n {\n if (inv[i] > 0)\n {\n int k = sa[inv[i] - 1];\n while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++;\n lcp[inv[i] - 1] = len;\n if (len > 0) len--;\n }\n }\n }\n}\nclass ZAlgorithm\n{\n public int[] calculateZ(char input[])\n {\n int Z[] = new int[input.length];\n int left = 0;\n int right = 0;\n for(int k = 1; k < input.length; k++) {\n if(k > right) {\n left = right = k;\n while(right < input.length && input[right] == input[right - left]) {\n right++;\n }\n Z[k] = right - left;\n right--;\n } else {\n //we are operating inside box\n int k1 = k - left;\n //if value does not stretches till right bound then just copy it.\n if(Z[k1] < right - k + 1) {\n Z[k] = Z[k1];\n } else { //otherwise try to see if there are more matches.\n left = k;\n while(right < input.length && input[right] == input[right - left]) {\n right++;\n }\n Z[k] = right - left;\n right--;\n }\n }\n }\n return Z;\n }\n public ArrayList matchPattern(char text[], char pattern[])\n {\n char newString[] = new char[text.length + pattern.length + 1];\n int i = 0;\n for(char ch : pattern) {\n newString[i] = ch;\n i++;\n }\n newString[i] = '$';\n i++;\n for(char ch : text) {\n newString[i] = ch;\n i++;\n }\n ArrayList result = new ArrayList<>();\n int Z[] = calculateZ(newString);\n\n for(i = 0; i < Z.length ; i++) {\n if(Z[i] == pattern.length) {\n result.add(i - pattern.length - 1);\n }\n }\n return result;\n }\n}\nclass KMPAlgorithm\n{\n public int[] computeTemporalArray(char[] pattern)\n {\n int[] lps = new int[pattern.length];\n\n int index = 0;\n for(int i=1;i KMPMatcher(char[] text, char[] pattern)\n {\n int[] lps = computeTemporalArray(pattern);\n\n int j = 0;\n int i = 0;\n int n = text.length;\n int m = pattern.length;\n ArrayList indices = new ArrayList<>();\n while(i < n)\n {\n if(pattern[j] == text[i])\n {\n i++;\n j++;\n }\n if(j == m)\n {\n indices.add(i - j);\n j = lps[j - 1];\n }\n else if(i < n && pattern[j] != text[i])\n {\n if(j != 0)\n j = lps[j - 1];\n else\n i = i + 1;\n }\n }\n return indices;\n }\n}\nclass Hashing\n{\n public long[] computePowers(long p, int n, long m)\n {\n long[] powers = new long[n];\n powers[0] = 1;\n for(int i=1;i= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException\n {\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}\nclass FenwickTree\n{\n public void update(long[] fenwickTree,long delta,int index)\n {\n index += 1;\n while(index < fenwickTree.length)\n {\n fenwickTree[index] += delta;\n index = index + (index & (-index));\n }\n }\n public long prefixSum(long[] fenwickTree,int index)\n {\n long sum = 0L;\n index += 1;\n while(index > 0)\n {\n sum += fenwickTree[index];\n index -= (index & (-index));\n }\n return sum;\n }\n}\nclass SegmentTree\n{\n public int nextPowerOfTwo(int num)\n {\n if(num == 0)\n return 1;\n if(num > 0 && (num & (num - 1)) == 0)\n return num;\n while((num &(num - 1)) > 0)\n {\n num = num & (num - 1);\n }\n return num << 1;\n }\n public int[] createSegmentTree(int[] input)\n {\n int np2 = nextPowerOfTwo(input.length);\n int[] segmentTree = new int[np2 * 2 - 1];\n\n for(int i=0;i= high){\n return segmentTree[pos];\n }\n if(qlow > high || qhigh < low){\n return Integer.MIN_VALUE;\n }\n int mid = (low+high)/2;\n return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1),\n rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c5c03d8e3c5ea8109fdcc6346d13b6f8", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.io.InputStream;\nimport java.io.OutputStream;\n\npublic class C {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\n\t\tint N = in.readInt();\n\t\tint M = in.readInt();\n\t\tint K = in.readInt();\n\t\tint bigMod = 1000000009;\n\t\tif (K > M) {\n\t\t\tSystem.out.println(M % bigMod);\n\t\t} else {\n\n\t\t\tint div = M / (K - 1);\n\t\t\tint val = M % (K - 1);\n\t\t\tif (val > 0)\n\t\t\t\tdiv++;\n\t\t\tif (N - M >= div - 1) {\n\t\t\t\tSystem.out.println(M % bigMod);\n\t\t\t} else {\n\t\t\t\tlong ans = (N - M) * (K - 1);\n\t\t\t\tint x = (M - (N - M) * (K - 1));\n\t\t\t\tint y = x / K;\n\t\t\t\tint z = x % K;\n\t\t\t\tval = (int) (pow(2, y, bigMod) % bigMod);\n\t\t\t\tans += ((((2 * (val - 1)) % bigMod) * K) % bigMod + z)\n\t\t\t\t\t\t% bigMod;\n\t\t\t\tSystem.out.println(ans);\n\t\t\t}\n\t\t}\n\n\t\tout.close();\n\t}\n\n\tpublic static long pow(int a, int b, int mod) {\n\t\tif (b == 0)\n\t\t\treturn 1;\n\t\tif (b == 1)\n\t\t\treturn a;\n\t\tif (b % 2 == 0) {\n\t\t\tlong val = pow(a, b / 2, mod) % mod;\n\t\t\treturn (val * val) % mod;\n\t\t} else {\n\t\t\tlong val = pow(a, b - 1, mod) % mod;\n\t\t\treturn ((long) a * val) % mod;\n\t\t}\n\t}\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 readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public static boolean isSpaceChar(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 \nclass OutputWriter {\n private final PrintWriter writer;\n \n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(outputStream);\n }\n \n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n \n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n \n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n \n public void close() {\n writer.close();\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "76ed6b6a948574065d4eeb66b29d622c", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\n/*\n * @author Mahmoud Aladdin (aladdin3)\n */\n\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\tint gcd(int a, int b) {\n\t\treturn b == 0? a: gcd(b, a % b);\n\t}\n \n int lcm(int a, int b) {\n \treturn (a * b) / gcd(a, b);\n }\n \n static class Node {\n \tpublic int id;\n \tpublic int dist;\n \t\n \tNode(int i, int d) {id = i; dist = d;}\n }\n \n static class Edge {\n \tpublic int s;\n \tpublic int e;\n \t\n \tEdge(int ss, int ee) {s = ss; e = ee;};\n }\n \n Edge[] edges;\n \n int[] cities; \n int[] val;\n boolean[] vis;\n \n int bs(int s, int e, int v) {\n \tint ans = -1;\n \twhile (s <= e) {\n \t\tint m = (s + e) >> 1;\n \t\tif(edges[m].s >= v) {\n \t\t\tans = m;\n \t\t\te = m - 1;\n \t\t} else {\n \t\t\ts = m + 1;\n \t\t}\n \t}\n \treturn ans;\n }\n \n void bfs(int start, int d) {\n\t\tQueue que = new LinkedList();\n\t\tArrays.fill(vis, false); \n\t\tque.add(new Node(start, 0));\n\t\twhile(que.size() > 0) {\n\t\t\tNode curr = que.poll();\n\t\t\tif(vis[curr.id]) continue;\n\t\t\tvis[curr.id] = true;\n\t\t\tval[curr.id]++;\n\t\t\tint i = bs(0, edges.length - 1, curr.id);\n\t\t\tjout.println(curr.id + \" \" + i);\n\t\t\tfor(int ii = i; ii != -1 && ii < edges.length && edges[ii].s == curr.id; ii++) {\n\t\t\t\tif(curr.dist < d) {\n\t\t\t\t\tque.add(new Node(edges[ii].e, curr.dist + 1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n }\n \n public void run() throws Exception {\n\t\tint n = jin.integer();\n\t\tint m = jin.integer();\n\t\tint k = jin.integer();\n\t\t\n\t\t\n\t\tint w = n - m;\n\t\tint nk = n / k;\n\t\tint nt = Math.max(nk - w, 0);\n\t\tint dm = Math.max(w - nk, 0);\n\t\tint nnt = nk - nt;\n\t\t\n\t\tBigInteger mod = BigInteger.valueOf(1000000009);\n\t\tint iscore = n - (nt * k) - nnt - dm;\n\t\tBigInteger score = BigInteger.valueOf(iscore);\n\t\tBigInteger value = BigInteger.valueOf(1);\n\t\tvalue = value.modPow(nt + 1);\n\t\tvalue = value.subtract(BigInteger.valueOf(2));\n\t\tvalue = value.add(mod).mod(mod);\n\t\tvalue = value.multiply(BigInteger.valueOf(k));\n\t\tvalue = value.mod(mod);\n\t\tscore = score.add(value);\n\t\tjout.println(score.mod(mod));\t\t\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc2040f07fcd188606a8fa92f736f99e", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.io.InputStream;\nimport java.io.OutputStream;\n\npublic class C {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\n\t\tint N = in.readInt();\n\t\tint M = in.readInt();\n\t\tint K = in.readInt();\n\t\tint bigMod = 1000000009;\n\t\tif (K > M) {\n\t\t\tSystem.out.println(M % bigMod);\n\t\t} else {\n\n\t\t\tint div = M / (K - 1);\n\t\t\tint val = M % (K - 1);\n\t\t\tif (val > 0)\n\t\t\t\tdiv++;\n\t\t\tif (N - M >= div - 1) {\n\t\t\t\tSystem.out.println(M % bigMod);\n\t\t\t} else {\n\t\t\t\tlong ans = (N - M) * (K - 1);\n\t\t\t\tint x = (M - (N - M) * (K - 1));\n\t\t\t\tint y = x / K;\n\t\t\t\tint z = x % K;\n\t\t\t\tval = (int) (pow(2, y, bigMod) % bigMod);\n\t\t\t\tans += ((((2 * (val - 1)) % bigMod) * K) % bigMod + z)\n\t\t\t\t\t\t% bigMod;\n\t\t\t\tSystem.out.println(ans);\n\t\t\t}\n\t\t}\n\n\t\tout.close();\n\t}\n\n\tpublic static long pow(int a, int b, int mod) {\n\t\tif (b == 0)\n\t\t\treturn 1;\n\t\tif (b == 1)\n\t\t\treturn a;\n\t\tif (b % 2 == 0) {\n\t\t\tlong val = pow(a, b / 2, mod) % mod;\n\t\t\treturn (val * val) % mod;\n\t\t} else {\n\t\t\tlong val = pow(a, b - 1, mod) % mod;\n\t\t\treturn ((long) a * val) % mod;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a3c28a1ea2b347c2813cb61c9d4144d1", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class cfec13a{\n\tstatic InputReader in = new InputReader();\n\tstatic String [] arr;\n\tstatic String str;\n\n\tpublic static void main(String [] args) throws Exception{\n\t\tString s = in.readLine().trim();\n\t\tlong n = Long.parseLong(s.substring(0,s.indexOf(\" \")));\n\t\tlong m = Long.parseLong(s.substring(s.indexOf(\" \")+1));\n\t\tint inc = n/m;\n\t\twhile(m*inc < n){\n\t\t\tinc++;\n\t\t}\n\t\tSystem.out.println(m*inc);\n\t}\n\tstatic class InputReader{\n\t\tBufferedReader br;\n\t\tpublic InputReader(){\n\t\t\ttry{\n\t\t\t\tbr = new BufferedReader(new FileReader(\"cfec13a.in\"));\n\t\t\t}catch(Exception e){\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t}\n\t\t}\n\t\tpublic String readLine() throws Exception{\n\t\t\treturn br.readLine();\n\t\t}\n\t\tpublic boolean ready() throws Exception{\n\t\t\treturn br.ready();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3d5f348185f76cf843e16e3f6fb41188", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class dddd\n{\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(System.in);\n\t\tint a=in.nextInt();\n\t\tint b=in.nextInt();\n\t\tfor(int i=1;i<=a*b*a*(b+1)i++) {\n\t\t\tif(b*i>a) {\n\t\t\t\tSystem.out.println(b*i);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0d2cbaac40458e44bd499f0ff04800ec", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n=sc.nextInt();\n\t\tlong k=sc.nextInt();\n\t\tif(n n){\n x = k;\n }\n else if(n > k){\n int y = n / k;\n x = k * y + k;\n }\n\n System.out.println(x);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dc136d58e8ab378805d4f542a84d8385", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class B_Round_213_Div1 {\n\n public static long MOD = 1000000007;\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 n = in.nextInt();\n int d = in.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = in.nextInt();\n }\n Arrays.sort(data);\n int max = 0;\n for (int i = 0; i < n; i++) {\n if (max + d >= data[i]) {\n max += data[i];\n }\n }\n int v = cal(max, 0, d, new boolean[n], data);\n out.println(max + \" \" + v);\n out.close();\n }\n\n public static int cal(int max, int have, int d, boolean[] taken, int[] data) {\n if (max == have) {\n return 0;\n }\n int left = max - have;\n int[] a = new int[max + 1];\n int[] b = new int[max + 1];\n Arrays.fill(a, -1);\n Arrays.fill(b, -1);\n TreeSet set = new TreeSet();\n set.add(0);\n for (int i = 0; i < data.length; i++) {\n if (taken[i]) {\n for (int j = max; j >= 0; j--) {\n if ((j == 0 || a[j] != -1) && j + data[i] <= max && a[j + data[i]] == -1) {\n a[j + data[i]] = i;\n set.add(j + data[i]);\n }\n }\n } else {\n for (int j = max; j >= 0; j--) {\n if ((j == 0 || b[j] != -1) && j + data[i] <= max && b[j + data[i]] == -1) {\n b[j + data[i]] = i;\n }\n }\n }\n }\n // System.out.println(Arrays.toString(b) + \" \" + set);\n int cur = 0;\n int result = -1;\n int other = 0;\n for (int i = max; i >= 0; i--) {\n if (b[i] != -1) {\n Integer v = set.ceiling(i - d);\n\n if (v != null) {\n\n int tmp = have - v + i;\n if (tmp > cur) {\n cur = tmp;\n other = v;\n result = i;\n }\n }\n }\n }\n // System.out.println(cur + \" \" + other + \" \" + result + \" \" + d);\n while (result > 0) {\n taken[b[result]] = true;\n result -= data[b[result]];\n // System.out.println(result);\n }\n while (other > 0) {\n taken[a[other]] = false;\n other -= data[a[other]];\n \n }\n \n return 1 + cal(max, cur, d, taken, data);\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 }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f2fef74ae64857802f3462f32c248a5", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f", "difficulty": 2200} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\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 Zakhar Voit (zakharvoit@gmail.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\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, Scanner in, PrintWriter out) {\n int n = in.nextInt();\n int d = in.nextInt();\n int[] c = in.nextIntArray(n);\n int sum = 0;\n for (int aC : c) {\n sum += aC;\n }\n long[][] dp = new long[sum + 1][n + 1];\n dp[0][0] = 1;\n for (int i = 0; i < n; i++) {\n for (int w = 0; w < dp.length; w++) {\n dp[w][i + 1] = dp[w][i];\n if (w >= c[i]) {\n dp[w][i + 1] += dp[w - c[i]][i];\n }\n }\n }\n\n int[] min = new int[sum + 1];\n Arrays.fill(min, Integer.MAX_VALUE);\n min[0] = 0;\n for (int i = 0; i < min.length; i++) {\n if (dp[i][n] > 0 && min[i] < Integer.MAX_VALUE) {\n for (int j = i + 1; j <= Math.min(i + d, min.length - 1); j++) {\n min[j] = Math.min(min[j], min[i] + 1);\n }\n }\n }\n\n for (int i = min.length - 1; i >= 0; i--) {\n if (dp[i][n] > 0 && min[i] < Integer.MAX_VALUE) {\n out.print(i);\n out.print(\" \");\n out.print(min[i]);\n return;\n }\n }\n }\n}\n\nclass Scanner {\n BufferedReader in;\n StringTokenizer tok;\n\n public Scanner(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n tok = new StringTokenizer(\"\");\n }\n\n public String nextToken() {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(next());\n }\n\n return tok.nextToken();\n }\n\n private String tryReadNextLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n public String next() {\n String newLine = tryReadNextLine();\n if (newLine == null)\n throw new InputMismatchException();\n return newLine;\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n public int[] nextIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = nextInt();\n }\n\n return res;\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "21dd121c062f05fbd50fc6ddb1fe28f3", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f", "difficulty": 2200} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class B_Round_213_Div1 {\n\n public static long MOD = 1000000007;\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 n = in.nextInt();\n int d = in.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = in.nextInt();\n }\n Arrays.sort(data);\n int max = 0;\n for (int i = 0; i < n; i++) {\n if (max + d >= data[i]) {\n max += data[i];\n }\n }\n boolean[] dp = new boolean[max + 1];\n dp[0] = true;\n TreeSet set = new TreeSet();\n set.add(0);\n for (int i = 0; i < n; i++) {\n for (int j = max; j >= 0; j--) {\n if (dp[j] && j + data[i] <= max) {\n set.add(j + data[i]);\n dp[j + data[i]] = true;\n }\n }\n }\n //System.out.println(\"HE HE\" + \" \" + set + \" \" + max);\n int start = 0;\n int c = 0;\n while (start < max) {\n int v = Math.min(start + d, max);\n start = set.floor(v);\n // System.out.println(start);\n c++;\n }\n out.println(max + \" \" + c);\n\n\n out.close();\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e8cfd82ebc6dcc429d1d4605e6c388f", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f", "difficulty": 2200} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class B_Round_213_Div1 {\n\n public static long MOD = 1000000007;\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 n = in.nextInt();\n int d = in.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = in.nextInt();\n }\n Arrays.sort(data);\n int max = 0;\n for (int i = 0; i < n; i++) {\n if (max + d >= data[i]) {\n max += data[i];\n }\n }\n int v = cal(max, 0, d, new boolean[n], data);\n out.println(max + \" \" + v);\n out.close();\n }\n\n public static int cal(int max, int have, int d, boolean[] taken, int[] data) {\n if (max == have) {\n return 0;\n }\n int left = max - have;\n int[] a = new int[max + 1];\n int[] b = new int[max + 1];\n Arrays.fill(a, -1);\n Arrays.fill(b, -1);\n TreeSet set = new TreeSet();\n TreeSet o = new TreeSet();\n set.add(0);\n o.add(0);\n for (int i = 0; i < data.length; i++) {\n TreeSet tmp1 = new TreeSet();\n TreeSet tmp2 = new TreeSet();\n if (taken[i]) {\n for (int j : set) {\n if ( j + data[i] <= max && a[j + data[i]] == -1) {\n a[j + data[i]] = i;\n tmp1.add(j + data[i]);\n }\n }\n } else {\n for (int j : o) {\n if (j + data[i] <= max && b[j + data[i]] == -1) {\n b[j + data[i]] = i;\n tmp2.add(j + data[i]);\n }\n }\n }\n set.addAll(tmp1);\n o.addAll(tmp2);\n }\n //System.out.println(Arrays.toString(b) + \" \" + set);\n int cur = 0;\n int result = -1;\n int other = 0;\n for (int i = max; i >= 0; i--) {\n if (b[i] != -1) {\n Integer v = set.ceiling(i - d);\n\n if (v != null) {\n\n int tmp = have - v + i;\n if (tmp > cur) {\n cur = tmp;\n other = v;\n result = i;\n }\n }\n }\n }\n // System.out.println(cur + \" \" + other + \" \" + result + \" \" + d);\n while (result > 0) {\n taken[b[result]] = true;\n result -= data[b[result]];\n // System.out.println(result);\n }\n while (other > 0) {\n taken[a[other]] = false;\n other -= data[a[other]];\n \n }\n \n return 1 + cal(max, cur, d, taken, data);\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 }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "12086e248c36297609329f462c353059", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f", "difficulty": 2200} {"lang": "Java 7", "source_code": "2 3 3import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by zephyr on 10/16/14.\n */\npublic class Runner {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long[] values = new long[3];\n for (int i = 0; i < 3; i++) {\n values[i] = scanner.nextLong();\n }\n long total = 0;\n Arrays.sort(values);\n if (values[2] > 2* (values[0] + values[1])){\n total = values[0] + values[1];\n }else{\n total = (values[0] + values[1] + values[2])/3;\n }\n System.out.println(total);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7dcb8d5783fe130b8f5149eb75460fa3", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class C478{\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tlong a[] = new int[3];\n\t\ta[0] = in.nextLong();\n\t\ta[1] = in.nextLong();\n\t\ta[2] = in.nextLong();\n\n\t\tArrays.sort(a);\n\t\ta[1] = a[1]-a[0];\n\t\ta[2] = a[2]-a[0];\n\n\t\tlong tmp=a[1]/3;\n\t\ta[0]+=2*tmp;\n\t\ta[1] = a[1]%3;\n\t\ta[2] -= tmp*3;\n\n\t\tif(a[1]>=1 && a[2]>1){\n\t\t\ta[0]+=1;\n\t\t}\n\t\tSystem.out.println(a[0]);\n\t\t\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f1ec4adb2b972ecc0900a3d01c8fb21b", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Class{\n\n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(br.readLine());\n int r = Integer.parseInt(st.nextToken());\n int g = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int sum = 0;\n while(r+g+b>2){\n int max, mid, min;\n if(r>=g&&g>=b){max = r; mid = g; min = b;}\n else if(r>=b&&b>=g){max = r; mid = b; min = g;}\n else if(b>=r&&r>=g){max = b; mid = r; min = g;}\n else if(b>=g&&g>=r){max = b; mid = g; min = r;}\n else if(g>=r&&r>=b){max = g; mid = r; min = b;}\n else if(g>=b&&b>=r){max = g; mid = b; min = r;}\n r = max; g = mid; b = min;\n \n if(r==g&&g==b){sum+=r; break;}\n else{sum++; r-=2; g--;}\n }\n System.out.print(sum);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "877d925eee124fee6639857fdf968cfb", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint A[]=new int[3];\n\t\tfor(int i=0;i<3;i++){\n\t\t A[i]=sc.nextInt();\n\t\t}\n\t\tArrays.sort(A);\n\t\tint m = A[0]+A[1];\n\t\tif(A[2]0) {\n\t\t\t\tmm-=snooze;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif((hh-1)>0) {\n\t\t\t\t\thh=23;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\thh-=1;\n\t\t\t\t}\n\t\t\t\tmm=60-snooze+mm;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tfull = hh.toString() + mm.toString();\n\t\t}\n\t\tSystem.out.println(count);\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2520088fe5e76adfc1401e7bb35cafd5", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class 916A{\n public static void main(String args[]){\n Scanner sc = new Scanner(System.in);\n int x = sc.nextInt();\n int h = sc.nextInt();\n int m = sc.nextInt();\n int curr = h*60 + m , flag = 0;\n \n while(curr > 0){\n curr = curr - x;\n if(contains(curr) == true){\n flag = 1;\n break;\n }\n }\n \n if(flag == 0){\n curr = 23*60 + 59;\n while(curr > 0){\n curr = curr - x;\n if(contains(curr) == true){\n flag = 1;\n break;\n }\n } \n }\n System.out.println(curr);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7bd8b83ff4e355314aedd6c1fe8e9924", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String[] args) {\n //System.out.println(\"Hello world!\");\n Scanner s=new Scanner(System.in);\n int v=s.nextInt();\n int hh=s.nextInt();\n int mm=s.nextInt();\n if(hh%10==7||mm%10==7)\n System.out.println(0);\n else\n {\n int c=0;\n while(hh%10!=7&&mm%10!=7)\n {\n if(v>mm)\n {\n m=60-(v-mm);\n if(h==0)\n hh=23;\n else\n hh-=1;\n }\n else\n mm-=v;\n c++;\n }\n System.out.println(c);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "efd11db01cda44eb94ac6be34895272f", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900} {"lang": "Java 8", "source_code": " \nimport java.io.*;\nimport java.util.*;\npublic class Solution\n{\n public static void main(String args[])\n {\n \n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n int sum=a+b+c;\n\n if(sum % 2 == 0)\n {\n sum /= 2;\n int x = sum - c;\n int y = sum - a;\n int z = sum - b;\n\n if(x >= 0 && y >= 0 && z >= 0)\n System.out.println(\"%d %d %d\\n\", x, y, z);\n else\n System.out.println(\"Impossible\");\n }\n else\n System.out.println(\"Impossible\");\n\n \n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "de07f2bd4e253b2a384dec7848b28766", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.Math.*;\npublic class q4\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint a[]=new int[3];\n\t\tfor(int i=0;i<3;i++)\n\t\t\ta[i]=sc.nextInt();\n\t\tint x=(a[0]+a[1]-a[2])/2;\n\t\tint y=(a[1]+a[2]-a[0])/2;\n\t\tint z=(a[2]+a[0]-a[1])/2;\n\t\t//if(x<0||y<0||z<0)\n\t\t//\tSystem.out.println(\"Impossible\");\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(x);\n\t\t\tSystem.out.println(y);\n\t\t\tSystem.out.println(z);\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "683a7a0e662fca8f20dc08a78d01622f", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.Math;\nimport java.lang.Object;\nimport java.text.DecimalFormat;\npublic class test{\n\n\n \n\n public static void main(String args[])\n\n\n{ \n Scanner in= new Scanner(System.in);\n int n,count=0,f=0,i;\n double x,y,z;\n int a,b,c;\n a=in.nextInt();\n b=in.nextInt();\n c=in.nextInt();\n z=(a+b-c)/2;\n y=(b+c-a)/2;\n x=(a+c-b)/2;\n if((x==(int)x&&y==(int)y&&z==(int)z)&&x=>0&&y=>0&&z=>0)\n {\n System.out.println((int)z+\" \"+(int)y+\" \"+(int)x);\n }\n else\n System.out.println(\"Impossible\");\n \n\n }\n\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "32f55d7a00b97dceb6bfa8bbbfaf7c79", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200} {"lang": "Java 8", "source_code": " \nimport java.io.*;\nimport java.util.*;\npublic class Solution\n{\n public static void main(String args[])\n {\n \n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n int sum=a+b+c;\n\n if(sum % 2 == 0)\n {\n sum /= 2;\n int x = sum - c;\n int y = sum - a;\n int z = sum - b;\n\n if(x >= 0 && y >= 0 && z >= 0)\n System.out.println(\"%d %d %d\\n\", x, y, z);\n else\n System.out.println(\"Impossible\");\n }\n else\n System.out.println(\"Impossible\");\n\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1e35077e06ef0d54efd3d06893b31f0d", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class HarryPotterAndThreeSpells {\n import java.io.*;\nimport java.util.*;\n\npublic class HarryPotterAndThreeSpells {\n public static void main(String[] args) throws IOException {\n BufferedReader ff = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(ff.readLine());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int c = Integer.parseInt(st.nextToken());\n int d = Integer.parseInt(st.nextToken());\n int e = Integer.parseInt(st.nextToken());\n int f = Integer.parseInt(st.nextToken());\n if ((a == 0 && b > 0 && d > 0) || (c == 0 && d > 0) || b*d*f > a*c*e)\n System.out.println(\"Ron\");\n else\n System.out.println(\"Hermione\");\n }\n}public static void main(String[] args) throws IOException {\n BufferedReader ff = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(ff.readLine());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int c = Integer.parseInt(st.nextToken());\n int d = Integer.parseInt(st.nextToken());\n int e = Integer.parseInt(st.nextToken());\n int f = Integer.parseInt(st.nextToken());\n if ((c == 0 && d > 0) || b*d*f > a*c*e)\n System.out.println(\"Ron\");\n else\n System.out.println(\"Hermione\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d7c022dce1f1826e688bd7325ba81415", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800} {"lang": "Java 6", "source_code": "public class R65A {\n\tstatic String handle(int[] nums) {\n\t\tif (nums[2] == 0 && nums[3] > 0)\n\t\t\treturn \"Ron\";\n\t\tif (nums[1] == 0 || nums[3] == 0 || nums[5] == 0)\n\t\t\treturn \"Hermione\";\n\t\tif (nums[0] == 0 || nums[2] == 0 || nums[4] == 0)\n\t\t\treturn \"Ron\";\n\t\tif (1.0 * nums[1] * nums[3] * nums[5] / nums[0] / nums[2] / nums[4] > 1)\n\t\t\treturn \"Ron\";\n\t\treturn \"Hermione\";\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner s = new Scanner(System.in);\n\t\tint[] nums = new int[6];\n\t\tfor (int i = 0; i < nums.length; i++) {\n\t\t\tnums[i] = s.nextInt();\n\t\t}\n\t\tString result = handle(nums);\n\t\tSystem.out.println(result);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8fa09d0c9a180df6e99e899a3ce24034", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class HarryPotterAndThreeSpells {\n public static void main(String[] args) throws IOException {\n BufferedReader ff = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(ff.readLine());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int c = Integer.parseInt(st.nextToken());\n int d = Integer.parseInt(st.nextToken());\n int e = Integer.parseInt(st.nextToken());\n int f = Integer.parseInt(st.nextToken());\n if ((c == 0 && d > 0) || b*d*f > a*c*e)\n System.out.println(\"Ron\");\n else\n System.out.println(\"Hermione\");\n }\n}import java.io.*;\nimport java.util.*;\n\npublic class HarryPotterAndThreeSpells {\n public static void main(String[] args) throws IOException {\n BufferedReader ff = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(ff.readLine());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int c = Integer.parseInt(st.nextToken());\n int d = Integer.parseInt(st.nextToken());\n int e = Integer.parseInt(st.nextToken());\n int f = Integer.parseInt(st.nextToken());\n if (b*d*f > a*c*e)\n System.out.println(\"Ron\");\n else\n System.out.println(\"Hermione\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05debae3031b60ab14e43fa8c2a9fe1e", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n MyScanner in;\n PrintWriter out;\n\n public static void main(String[] args) throws Exception {\n new A().run();\n }\n\n public void run() throws Exception {\n in = new MyScanner();\n out = new PrintWriter(System.out);\n\n out.println(solve());\n\n out.close();\n }\n\n public String solve() throws Exception {\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int d = in.nextInt();\n int e = in.nextInt();\n int f = in.nextInt();\n \n if (a + b + c + d + e + f == 0) {\n return \"Hermione\";\n } else if ((c == 0) && (d != 0)) {\n return \"Ron\";\n } else if ((a == 0) && (b != 0) && (d != 0)) {\n return \"Ron\";\n }\n if (b * d * f > a * c * e) {\n return \"Ron\";\n } else {\n return \"Hermione\"\n }\n }\n}\n\nclass MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() throws Exception {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() throws Exception {\n if ((st == null) || (!st.hasMoreTokens())) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n\n double nextDouble() throws Exception {\n return Double.parseDouble(next());\n }\n\n boolean nextBoolean() throws Exception {\n return Boolean.parseBoolean(next());\n }\n\n long nextLong() throws Exception {\n return Long.parseLong(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "363700edd0edf94e9fc059a0e8039ca2", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800} {"lang": "Java 11", "source_code": "import java.util.*;\r\npublic class MyClass {\r\n public static void main(String args[]) {\r\n Scanner in= new Scanner(System.in);\r\n long a= in.nextLong(), b= in.nextLong();\r\n String s1= binary(a), s2= binary(b);\r\n String reverse= (new StringBuilder(s1).reverse()).toString();\r\n if(check(s1,s2) || check(reverse,s2)) System.out.println(\"YES\");\r\n else System.out.println(\"NO\");\r\n \r\n }\r\n private static String binary(long a){\r\n String res=\"\";\r\n while(a>0){\r\n res= (a%2)+res;\r\n a/=2;\r\n }\r\n return res;\r\n }\r\n private static boolean check(String s1, String s2){\r\n int l=0, r= s1.length()-1;\r\n while(l=l){\r\n if(s1.charAt(r)=='1') break;\r\n r--;\r\n }\r\n s1= s1.substring(l,r+1);\r\n l= s2.indexOf(s1);\r\n if(l==-1) return false;\r\n r= l+s1.length();\r\n if(r visited = new HashSet<>();\r\n Queue q = new LinkedList<>();\r\n String num = Long.toBinaryString(x);\r\n q.add(num);\r\n visited.add(num);\r\n while (!q.isEmpty()) {\r\n String now = q.poll();\r\n if (now.length() > 100) {\r\n continue;\r\n }\r\n for (int i = 0; i < 2; i++) {\r\n // append i to curr\r\n String curr = now + (char) ('0' + i);\r\n curr = update(curr);\r\n if (!visited.contains(curr)) {\r\n visited.add(curr);\r\n q.add(curr);\r\n }\r\n }\r\n }\r\n String want = Long.toBinaryString(y);\r\n if (visited.contains(want)) {\r\n out.println(\"YES\");\r\n }else {\r\n out.println(\"NO\");\r\n }\r\n }\r\n\r\n private static String update(String curr) {\r\n while (curr.charAt(curr.length() - 1) == '0') {\r\n curr = curr.substring(0, curr.length() - 1);\r\n }\r\n StringBuilder res = new StringBuilder(curr);\r\n return res.reverse().toString();\r\n }\r\n\r\n\r\n public static FastReader sc;\r\n public static PrintWriter out;\r\n static class FastReader\r\n {\r\n BufferedReader br;\r\n StringTokenizer str;\r\n\r\n public FastReader()\r\n {\r\n br = new BufferedReader(new\r\n InputStreamReader(System.in));\r\n }\r\n\r\n String next()\r\n {\r\n while (str == null || !str.hasMoreElements())\r\n {\r\n try\r\n {\r\n str = new StringTokenizer(br.readLine());\r\n }\r\n catch (IOException end)\r\n {\r\n end.printStackTrace();\r\n }\r\n }\r\n return str.nextToken();\r\n }\r\n\r\n int nextInt()\r\n {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong()\r\n {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble()\r\n {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine()\r\n {\r\n String str = \"\";\r\n try\r\n {\r\n str = br.readLine();\r\n }\r\n catch (IOException end)\r\n {\r\n end.printStackTrace();\r\n }\r\n return str;\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29eb4dc3b572c119c8c703160e0116b3", "src_uid": "9f39a3c160087beb0efab2e3cb510e89", "difficulty": 2000} {"lang": "Java 11", "source_code": "// package c1618;\n\nimport java.io.File;\nimport java.lang.invoke.MethodHandles;\nimport java.util.Random;\nimport java.util.Scanner;\n\n//\n// Codeforces Round #760 (Div. 3) 2021-12-14 06:35\n// F. Reverse\n// https://codeforces.com/contest/1618/problem/F\n// time limit per test 2 seconds; memory limit per test 256 megabytes\n// public class Pseudo for 'Source should satisfy regex [^{}]*public\\s+(final)?\\s*class\\s+(\\w+).*'\n//\n// You are given two positive integers x and y. You can perform the following operation with x:\n// write it in its binary form without leading zeros, add 0 or 1 to the right of it, reverse the\n// binary form and turn it into a decimal number which is assigned as the new value of x.\n//\n// For example:\n// * 34 can be turned into 81 via one operation: the binary form of 34 is 100010, if you add 1,\n// reverse it and remove leading zeros, you will get 1010001, which is the binary form of 81.\n// * 34 can be turned into 17 via one operation: the binary form of 34 is 100010, if you add 0,\n// reverse it and remove leading zeros, you will get 10001, which is the binary form of 17.\n// * 81 can be turned into 69 via one operation: the binary form of 81 is 1010001, if you add 0,\n// reverse it and remove leading zeros, you will get 1000101, which is the binary form of 69.\n// * 34 can be turned into 69 via two operations: first you turn 34 into 81 and then 81 into 69.\n//\n// Your task is to find out whether x can be turned into y after a certain number of operations\n// (possibly zero).\n//\n// Input\n//\n// The only line of the input contains two integers x and y (1 <= x, y <= 10^{18}).\n//\n// Output\n//\n// Print if you can make x equal to y and if you can't.\n//\n// Example\n/*\ninput:\n3 3\n\noutput:\nYES\n\ninput:\n7 4\n\noutput:\nNO\n\ninput:\n2 8\n\noutput:\nNO\n\ninput:\n34 69\n\noutput:\nYES\n\ninput:\n8935891487501725 71487131900013807\n\noutput:\nYES\n*/\n// Note\n//\n// In the first example, you don't even need to do anything.\n//\n// The fourth example is described in the statement.\n//\npublic class C1618F {\n static final int MOD = (int)1e9+7;\n static final Random RAND = new Random();\n\n static boolean solveInner(long x, long y) {\n // when x is odd:\n // x y1 y2\n // 00: abcd -> abcd0 -> dcba -> dcba0 -> abcd\n // 01: abcd -> abcd0 -> dcba -> dcba1 -> 1abcd\n // 10: abcd -> abcd1 -> 1dcba -> 1dcba0 -> abcd1\n // 11: abcd -> abcd1 -> 1dcba -> 1dcba1 -> 1abcd1\n\n\n String sx = Long.toBinaryString(x);\n String sy = Long.toBinaryString(y);\n String rx = new StringBuilder(sx).reverse().toString();\n if (x % 2 == 1) {\n return isOkXOdd(sx, sy, rx);\n } else {\n long core = x;\n while (core % 2 == 0) {\n core >>= 1;\n }\n String cx = Long.toBinaryString(core);\n String rcx = new StringBuilder(cx).reverse().toString();\n return isOkXEven(sx, sy, rx, cx, rcx);\n }\n }\n\n // when x is odd:\n // x y1 y2\n // 00: abcd -> abcd0 -> dcba -> dcba0 -> abcd\n // 01: abcd -> abcd0 -> dcba -> dcba1 -> 1abcd\n // 10: abcd -> abcd1 -> 1dcba -> 1dcba0 -> abcd1\n // 11: abcd -> abcd1 -> 1dcba -> 1dcba1 -> 1abcd1\n static boolean isOkXOdd(String x, String y, String rx) {\n int n = y.length();\n if (y.equals(x) || y.equals(rx) || y.substring(1).equals(rx)) {\n return true;\n }\n if (y.length() < x.length()) {\n return false;\n }\n if (isOkXOdd(x, y.substring(1), rx)) {\n return true;\n }\n if (y.charAt(n-1) == '1') {\n if (isOkXOdd(x, y.substring(0, n-1), rx)) {\n return true;\n }\n if (n > 1 && isOkXOdd(x, y.substring(1, n-1), rx)) {\n return true;\n }\n }\n return false;\n }\n\n // when x is even:\n // x y1 y2\n // 00: abc00 -> abc000 -> cba -> cba0 -> abc\n // 01: abc00 -> abc000 -> cba -> cba1 -> 1abc\n // 10: abc00 -> abc001 -> 100cba -> 100cba0 -> abc001\n // 11: abc00 -> abc001 -> 100cba -> 100cba1 -> 1abc001\n static boolean isOkXEven(String x, String y, String rx, String cx, String rcx) {\n int n = y.length();\n if (y.equals(x) || y.equals(rcx) || y.equals(cx)\n || y.substring(1).equals(cx) || y.substring(1).equals(rx)) {\n return true;\n }\n if (y.length() < cx.length()) {\n return false;\n }\n if (isOkXEven(x, y.substring(1), rx, cx, rcx)) {\n return true;\n }\n if (y.charAt(n-1) == '1') {\n if (isOkXEven(x, y.substring(0, n-1), rx, cx, rcx)) {\n return true;\n }\n if (n > 1 && isOkXEven(x, y.substring(1, n-1), rx, cx, rcx)) {\n return true;\n }\n }\n return false;\n }\n\n static void solve(long x, long y) {\n boolean ans = solveInner(x, y);\n System.out.println(ans ? \"YES\" : \"NO\");\n }\n\n static void doTest() {\n solve(3, 3);\n solve(7, 4);\n solve(2, 8);\n solve(34, 69);\n solve(8935891487501725L, 71487131900013807L);\n solve(26, 11);\n solve(Integer.parseInt(\"110100\", 2), Integer.parseInt(\"1101\", 2));\n System.exit(0);\n }\n\n public static void main(String[] args) {\n // doTest();\n Scanner in = getInputScanner();\n long x = in.nextLong();\n long y = in.nextLong();\n solve(x, y);\n in.close();\n }\n\n static Scanner getInputScanner() {\n try {\n final String USERDIR = System.getProperty(\"user.dir\");\n final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName();\n final File fin = new File(USERDIR + \"/io/c\" + CNAME.substring(1,5) + \"/\" + CNAME + \".in\");\n return fin.exists() ? new Scanner(fin) : new Scanner(System.in);\n } catch (Exception e) {\n return new Scanner(System.in);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "53984b2eedd7ef212279a91b4d242954", "src_uid": "9f39a3c160087beb0efab2e3cb510e89", "difficulty": 2000} {"lang": "Java 11", "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; tt0){\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 boolean[] sieveOfEratosthenes(int n)\r\n {\r\n\r\n boolean prime[] = new boolean[n+1];\r\n for(int i=0;i<=n;i++)\r\n prime[i] = true;\r\n\r\n for(int p = 2; p*p <=n; p++)\r\n {\r\n if(prime[p] == true)\r\n {\r\n for(int i = p*p; i <= n; i += p)\r\n prime[i] = false;\r\n }\r\n }\r\n return prime;\r\n }\r\n static void sort(int[] a) {\r\n ArrayList l=new ArrayList<>();\r\n for (int i:a) l.add(i);\r\n Collections.sort(l);\r\n for (int i=0; i l=new ArrayList<>();\r\n for (long i:a) l.add(i);\r\n Collections.sort(l);\r\n for (int i=0; i0||g>0||b>0)\n\n{\n if(r>0)\n {r-=2;time++;}else if(g>0||b>0){time++;}\n if(g>0)\n {g-=2;time++;}else if(b>0){time++;}\nif(b>0)\n {b-=2;time++;}\n\n}time+=30;\n System.out.println(time);\n}\n\n\n\n public static void main(String[] args) {\n\nMain m=new Main();\nm.go();\n\n\n\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a638252507a856df040c353e97ae6de", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000} {"lang": "Java 6", "source_code": "import net.egork.utils.test.Test;\nimport java.util.Collection;\nimport net.egork.utils.Exit;\nimport net.egork.utils.io.StreamInputReader;\nimport java.io.*;\nimport net.egork.utils.io.InputReader;\nimport net.egork.utils.Solver;\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new StreamInputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\trun(in, out);\n\t}\n\n\tpublic static void run(InputReader in, PrintWriter out) {\n\t\tSolver solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tExit.exit(in, out);\n\t}\n}\n\n\nclass MainChecker {\n\tpublic static String check(InputReader input, InputReader expectedOutput, InputReader actualOutput) {\n\t\treturn new TaskAChecker().check(input, expectedOutput, actualOutput);\n\t}\n\n\tpublic static Collection generateTests() {\n\t\treturn new TaskAChecker().generateTests();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fe43e3e8065931be4c7da81856bb1205", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author \u0422\u0438\u043c\u0443\u0440\n */\npublic class JavaApplication24 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n //||\\\\ TODO code application logic here\n Scanner in = new Scanner(System.in);\n int r = in.nextInt();\n int g = in.nextInt();\n int b = in.nextInt();\n int time = 0;\n for (int i = 0; true; i++) {\n if (r > 0) {\n r = r - 2;\n\n }\n if (r <=0&& g<=0&&b<=0) {\n break;\n }\n time = time + 1;\n if (g > 0) {\n g = g - 2;\n }\n if (r <=0&& g<=0&&b<=0) {\n break;\n }\n time = time + 1;\n if (b > 0) {\n b = b - 2;\n }\n if (r <=0&& g<=0&&b<=0) {\n break;\n }\n time = time + 1;\n\n }\n System.out.print(time + 30);\n\n }\n\n}\n]\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d744813f56da7644ccd6c2cb34d904cb", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\n\tpublic void solve() throws Exception {\n\t\tlong r = sc.nextInt(), h = sc.nextInt();\n\t\tr *= 2;\n\t\th *= 2;\n\t\tlong n = (h + r / 2) / r;\n\t\tif (n == 0) {\n\t\t\tout.println(1);\n\t\t} else {\n\t\t\tlong hmax = n * r - r / 2;\n\t\t\tlong left = h + r - hmax;\n\t\t\tlong ans = 2 * n;\n\t\t\tif (r * r * 3 <= (left - r / 2) * (left - r / 2) * 4) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\n\tstatic Throwable uncaught;\n\n\tBufferedReader in;\n\tFastScanner sc;\n\tPrintWriter out;\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable uncaught) {\n\t\t\tSolution.uncaught = uncaught;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread thread = new Thread(null, new Solution(), \"\", (1 << 26));\n\t\tthread.start();\n\t\tthread.join();\n\t\tif (Solution.uncaught != null) {\n\t\t\tthrow Solution.uncaught;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\n\tpublic FastScanner(BufferedReader in) {\n\t\tthis.in = in;\n\t}\n\n\tpublic String nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic long nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e63a63b0c5f81406778ebdfeaf174317", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class _342C {\n public static void main(String[] args) throws Exception {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n double r;\n double h;\n final double a = 1.70710678119;\n String s[] = input.readLine().split(\" \");\n r = Double.parseDouble(s[0]);\n h = Double.parseDouble(s[1]);\n double cond = 0.0;\n int count = 0;\n while (cond + r <= h + r / 2.0) {\n count += 2;\n cond += r;\n }\n if (h + r - cond >= a * r / 2.0) {\n count++;\n }\n System.out.println(count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c99363a95b0bc44190956c1d2eec5cfc", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author Trung Pham\n */\npublic class C {\n\n public static int[][][] dp;\n public static String val;\n public static int m;\n\n public static void main(String[] args) {\n Scanner in = new Scanner();\n PrintWriter out = new PrintWriter(System.out);\n double r = in.nextInt();\n double h = in.nextInt();\n int a = (int) (1 + 2*Math.floor(h / r));\n int b = 0;\n if( h - (r / 2) >= 0){\n h -= (r/2);\n b = (int) (2 + 2*Math.floor(h / r));\n }\n out.println(Math.max(a , b));\n\n out.close();\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 \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\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9bde869617d53ce7171430c050fd2592", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n try {\n if (new File(\"input.txt\").exists())\n System.setIn(new FileInputStream(\"input.txt\"));\n } catch (SecurityException e) {\n }\n new Main().run();\n }\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st = new StringTokenizer(\"\");\n\n private void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n\n int r = nextInt();\n int h = nextInt();\n int p = h/r;\n p*=2;\n int c = h%r;\n p++;\n \n double as = (double)r/2;\n int ty = (int)(as+1-0.000001);\n \n if (c >= ty) p++;\n out.println(p);\n \n in.close();\n out.close();\n }\n\n void chk(boolean b) {\n if (b)\n return;\n System.out.println(new Error().getStackTrace()[1]);\n exit(999);\n }\n void deb(String fmt, Object... args) {\n System.out.printf(Locale.US, fmt + \"%n\", args);\n }\n String nextToken() throws IOException {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(in.readLine());\n return st.nextToken();\n }\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n String nextLine() throws IOException {\n st = new StringTokenizer(\"\");\n return in.readLine();\n }\n boolean EOF() throws IOException {\n while (!st.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null)\n return true;\n st = new StringTokenizer(s);\n }\n return false;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6ef78dc563eff433711131f0d6ac6736", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\n\n\n public class demo\n{\n\n public static void main(String[] args) throws IOException \n { BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer s=new StringTokenizer(inp.readLine());\n int n,k;\n n=Integer.parseInt(s.nextToken());\n k=Integer.parseInt(s.nextToken());\n String A=inp.readLine();\n int lets[]=new int[26],flag=0;\n int lets1[]=new int[26];\n for(int i=0;i= 0; i--) {\n begin[door[i] - 'A'] = i;\n }\n\n int maxOpenDoor = 0;\n for (int i = 0; i < guest; i++) {\n int openDoor = 0;\n for (int j = 0; j < 26; j++) {\n if (i >= begin[j] && i <= last[j]) {\n openDoor++;\n }\n }\n maxOpenDoor = Math.max(openDoor, maxOpenDoor);\n }\n if (maxOpenDoor > guard) {\n out.print(\"YES\");\n } else {\n out.print(\"NO\");\n }\n\n }\n\n }\n\n static class InputReader {\n public InputReader;\n\n public int readInt();\n\n public String readToken();\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b47a7d7efa33aee98a98a7ecd2b35a9b", "src_uid": "216323563f5b2dd63edc30cb9b4849a5", "difficulty": 1100} {"lang": "Java 8", "source_code": "import sun.nio.ch.SctpAssocChange;\n\nimport java.lang.reflect.Array;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CF_834B {\n private static Entrance[] entrances = new Entrance[26];\n\n static void add_guest(int entrance, int num_guest) {\n if (entrances[entrance] == null)\n entrances[entrance] = new Entrance(num_guest);\n else\n entrances[entrance].lastNumGuest = num_guest;\n }\n\n public static void main(String argv[]) {\n\n Scanner sc = new Scanner(System.in);\n\n int n = sc.nextInt();\n int k = sc.nextInt();\n\n String test = sc.next();\n\n int[] map = new int[27];\n\n for (int i = 0; i < test.length(); i++) {\n add_guest(test.charAt(i) - 65, i);\n }\n\n for (Entrance entrance : entrances) {\n if (entrance != null) {\n map[entrance.firstNumGuest]++;\n map[entrance.lastNumGuest+1]--;\n }\n }\n\n //System.out.println(Arrays.toString(map));\n\n int[] result = new int[27];\n int cnt=0;\n for (int i = 0; i < 26; i++) {\n cnt += map[i];\n result[i] = cnt;\n }\n\n // System.out.println(Arrays.toString(result));\n\n int max = 0;\n for (int i = 0; i < 27; i++)\n if (result[i] > max)\n max = result[i];\n\n\n System.out.println((max > k ? \"YES\":\"NO\"));\n }\n}\n\nclass Entrance {\n int firstNumGuest,lastNumGuest;\n\n Entrance(int firstNum) {\n firstNumGuest = firstNum;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9373e58764887db4ad19c2dbc800b190", "src_uid": "216323563f5b2dd63edc30cb9b4849a5", "difficulty": 1100} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String args[])\n throws java.io.IOException{\n Scanner in = new Scanner(System.in);\n\n int s[] = new int[27];\n int d[] = new int[27];\n int n = in.nextInt();\n int k=in.nextInt();\n int k1=k;\n\n String im = in.next();\n for(int i=0; i \n\t\tint ans = -1;\n\t\tfor (int k = 1; k <= 32; k++) {\n\t\t\tlong x = n - k * p;\n\t\t\tint y = Long.bitCount(x);\n\t\t\tif (y <= k && x >= k) {\n\t\t\t\tans = k;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t}\n//\t\tprintSubsetsRec(arr, 0, n, new ArrayList());\n//\t\tprintAllSubsets(arr, arr.length, n);\n//\t\tint res = minCoins(arr, arr.length, n);\n\t\tSystem.out.println(ans);\n\t}\n\n\tstatic int minCoins(int coins[], int m, int V) {\n\t\t// table[i] will be storing\n\t\t// the minimum number of coins\n\t\t// required for i value. So\n\t\t// table[V] will have result\n\t\tint table[] = new int[V + 1];\n\n\t\t// Base case (If given value V is 0)\n\t\ttable[0] = 0;\n\n\t\t// Initialize all table values as Infinite\n\t\tfor (int i = 1; i <= V; i++)\n\t\t\ttable[i] = Integer.MAX_VALUE;\n\n\t\t// Compute minimum coins required for all\n\t\t// values from 1 to V\n\t\tfor (int i = 1; i <= V; i++) {\n\t\t\t// Go through all coins smaller than i\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (coins[j] <= i && coins[j] >= 0) {\n\t\t\t\t\tint sub_res = table[i - coins[j]];\n\t\t\t\t\tif (sub_res != Integer.MAX_VALUE && sub_res + 1 < table[i])\n\t\t\t\t\t\ttable[i] = sub_res + 1;\n\n\t\t\t\t}\n\n\t\t}\n\t\treturn table[V];\n\n\t}\n\n\tstatic int solveExp(int a, int x) {\n//\t\ta = a % mod;\n\t\tint res = 1;\n\n\t\twhile (x > 0) {\n\t\t\tif ((x & 1) == 1)\n\t\t\t\tres = (res * a);\n\t\t\ta = (a * a);\n\t\t\tx >>= 1;\n\t\t}\n\n\t\treturn res;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cb592d1d85a7694e78004ddcec029a30", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class Codeforces {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long n, p;\n n = sc.nextLong();\n p = sc.nextLong();\n long ans = Long.MAX_VALUE;\n for(int i = 1; i < 65; i++){\n long target = n - i*p;\n int bits = 0;\n if(target <= 0){\n break;\n }\n int maxx = target;\n while(target > 0){\n if(target % 2 == 1){\n bits++;\n }\n target /= 2;\n }\n if( i >= bits && i <= maxx){\n ans = i;\n break;\n }\n }\n System.out.println((ans == Long.MAX_VALUE) ? -1 : ans);\n }\n\n\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fbbeb4c85d7d6aa02c806400c6e46677", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8", "difficulty": 1600} {"lang": "Java 11", "source_code": "package com.company;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\t Scanner sc = new Scanner (System.in);\n int n = sc.nextInt();\n int p = sc.nextInt();\n for (int res = 1; res < 31; res++) {\n long cur = n - res * p;\n int numbit=Long.bitCount(cur);\n if(numbit<=res&&cur>0) {\n System.out.print(res);\n return;\n }\n }\n System.out.print(-1);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "098e155fe3d327b84148712a0b6b205d", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8", "difficulty": 1600} {"lang": "Java 8", "source_code": "// Why do we fall ? So we can learn to pick ourselves up.\nimport java.util.*;\npublic class solve {\n static int mod = 1000000007;\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n int p = sc.nextInt();\n ArrayList tt = new ArrayList<>();\n for(int i=0; i<40; i++){\n tt.add((long) (Math.pow(2,i)+p));\n }\n int[] table = new int[(int) (n+1)];\n table[0] = 0;\n for(int i=1; i<=n; i++){\n table[i] = Integer.MAX_VALUE;\n }\n for(int i=1; i<=n; i++){\n for(int j=0; j= tt.get(j)){\n int sr = table[(int) (i-tt.get(j))];\n if(sr != Integer.MAX_VALUE && sr+10)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tan=(an*c)%m;\n\t\t\tc=(c*c)%m;\n\t\t\tb>>=1;\n\t\t}\n\t\treturn an;\n\t}\n\tstatic void pd(){if(debug)ans.append(\"hola\");}\n\tstatic void pd(Object a){if(debug)ans.append(a+\"\\n\");}\n\tstatic void pr(Object a){ans.append(a+\"\\n\");}\n\tstatic void pr(){ans.append(\"\\n\");}\n\tstatic void p(Object a){ans.append(a);}\n\tstatic int ni(){return in.nextInt();}\n\tstatic long nl(){return in.nextLong();}\n\tstatic String ns(){return in.next();}\n\tstatic double nd(){return in.nextDouble();}\n\tstatic String pr(String a, long b)\n\t{\n\t\tString c=\"\";\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tc=c.concat(a);\n\t\t\ta=a.concat(a);\n\t\t\tb>>=1;\n\t\t}\n\t\treturn c;\n\t}\n\tstatic class Reader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public Reader() {\n reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n public double nextDouble() {\n \treturn Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48629f440bcad8b2c71f889f88442bfc", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class A {\n static class Node implements Comparable{\n int x;\n long w;\n int id;\n\n public Node(int x,long w,int id){\n this.x=x;\n this.w=w;\n this.id=id;\n }\n public int compareTo(Node c){\n int i=Long.compare(this.w,c.w);\n return i;\n\n }\n @Override\n public boolean equals(Object o){\n if(o instanceof Node){\n Node c = (Node)o;\n return true;\n }\n return false;\n }\n }\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 a=sc.I(); int b=sc.I(); k=sc.I(); int n=sc.I();\n int MX=200001;\n dp1=new long[n+1][2*MX+1];\n dp2=new long[n+1][2*MX+1];\n\n dp1[0][a+MX]=1;\n dp2[0][b+MX]=1;\n int mx=Math.max(a,b)+k*n+MX;\n int mn=Math.min(a,b)-k*n+MX;\n\n for(int i=1;i<=n;i++) {\n for(int j=mn;j<=mx;j++){\n\n\n\n dp1[i][j - k] += dp1[i - 1][j];\n dp1[i][j + k + 1] -= dp1[i - 1][j];\n\n dp2[i][j - k] += dp2[i - 1][j];\n dp2[i][j + k + 1] -= dp2[i - 1][j];\n\n }\n for(int j=mn;j<=mx;j++){\n dp1[i][j]=(dp1[i][j]+dp1[i][j-1])%M;\n dp2[i][j]=(dp2[i][j]+dp2[i][j-1])%M;\n }\n\n\n }\n long ans=0;\n\n long sum2[]=new long[2*MX+1];\n\n for(int i=mn;i<=mx;i++){\n sum2[i]=(sum2[i-1]+dp2[n][i])%M;\n }\n for(int i=mn;i<=mx;i++){\n ans=(ans+(dp1[n][i]*sum2[i-1])%M)%M;\n // pw.println(dp1[n][i]+\" \"+sum2[i-1]);\n\n\n\n }\n pw.println(ans);\n\n pw.close();\n\n\n }\n static long dp1[][];\n static long dp2[][];\n static int k;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f3a72cc44ce7c56516db48c7153c14df", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.*;\n\npublic class D {\n\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic void exit() {\n\t\tsc.close();\n\t\tout.close();\n\t}\n\n\tlong mod = 1000000007;\n\tint a, b, k, t;\n\tlong c [][];\n\tint M;\n\tpublic D () {\n\t\ta = sc.nextInt();\n\t\tb = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tt = sc.nextInt();\n\t\tM = Math.abs(2*t*k + a + b);\n\t\tc = new long [2*t+1][2*M];\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\tfor (int j = 0; j < c[0].length; j++) {\n\t\t\t\tc[i][j] = -1;\n\t\t\t}\n\t\t}\n\t\tint m = 1 + b - a;\n\t\tout.println(comb(2*t, m));\n\t}\n\t\n\tlong comb(int t, int m) {\n\t\tif (t == 0) {\n\t\t\treturn 0 >= m ? 1 : 0;\n\t\t}\n\t\tif (c[t][M + m] != -1) return c[t][M+m];\n\t\tlong sum = 0;\n\t\tfor (int x = -k; x <= k; x++) {\n\t\t\tsum = (sum + comb(t-1, m-x)) % mod;\n\t\t}\n\t\tc[t][M+m] = sum;\n\t\treturn sum;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew D();\n\t\texit();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e47b566ad3133c8826dba1de08445aed", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.*;\n\npublic class D {\n\n\tstatic Scanner sc = new Scanner(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic void exit() {\n\t\tsc.close();\n\t\tout.close();\n\t}\n\n\tint mod = 1000000007;\n\tint a, b, k, t;\n\tint M;\n\tint c [][];\n\tint p [][];\n\tpublic D () {\n\t\ta = sc.nextInt();\n\t\tb = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tt = sc.nextInt();\n\t\tM = Math.abs(2*t*k + a + b+k);\n\t\tc = new int [2*t+1][2*M+1];\n\t\tp = new int [2*t+1][2*M+1];\n\t\tfor (int i = 0; i < c.length; i++) Arrays.fill(c[i], 0);\n\t\tfor (int i = 0; i < p.length; i++) Arrays.fill(p[i], 0);\n\t\t// solve t = 0: c[0][m] = 1 if 0 <= m\n\t\tfor (int m = 0; m <= M; m++) c[0][M+m] = 1;\n\t\tp[0][M+0] = c[0][M+0];\n\t\tfor (int m = 1; m <= M; m++) p[0][M+m] = p [0][M+m-1] + c[0][M+m];\n\t\t\n\t\t// solve for t > 0\n\t\tfor (int n = 1; n <= 2*t; n++) {\n\t\t\tfor (int m = -n*k; m <= n*k; m++) {\n\t\t\t\tc[n][M+m] = (p[n-1][M+m+k] - p[n-1][M+m-k-1])%mod; \n\t\t\t\tif (c[n][M+m]<0) c[n][M+m] += mod;\n\t\t\t}\n\t\t\tfor (int m = n*k+1; M+m <= 2*M; m++) c[n][M+m] = c[n][M+m-1];\n\t\t\tp[n][M-n*k] = c[n][M-n*k];\n\t\t\tfor (int m = -n*k+1; m <= M; m++) p[n][M+m] = (p[n][M+m-1] + c[n][M+m])%mod;\n\t\t}\n\t\t/*\n\t\tfor (int n = 0; n <= 2; n++) {\n\t\t\tfor (int m = -n*k; m <= n*k; m++) {\n\t\t\t\tout.println(\"c[\" + n + \"][\" + m + \"]=\" + c[n][M+m]);\n\t\t\t}\n\t\t}\n\t\t*/\n\t\tout.println(c[2*t][M+a-b-1]);\n\t\t//out.println(c(2*T, a-b-1));\n\t}\n\t\n\tint c(int n, int m) {\n\t\tif (n == 0) {\n\t\t\treturn 0<=m ? 1 : 0;\n\t\t}\n\t\tif (m < -n*k) return 0;\n\t\tif (m > n*k) return c(n, n*k);\n\t\tif (c[n][M+m] != -1) return c[n][M+m];\n\t\tc[n][M+m] = p(n-1, m+k) - p(n-1, m-k-1);\n\t\t//out.println(\"c[\"+n+\"][\"+m+\"]=\" + c[n][M+m]);\n\t\treturn c[n][M+m];\n\t}\n\t\n\tint p(int n, int m) {\n\t\tif (m < -n*k) return 0;\n\t\tif (p[n][M+m] != -1) return p[n][M+m];\n\t\tp[n][M+m] = p(n, m-1) + c(n, m);\n\t\t//out.println(\"p[\"+n+\"][\"+m+\"]=\" + p[n][M+m]);\n\t\treturn p[n][M+m];\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew D();\n\t\texit();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "594cc5159b7d4626ed7aab59a53f42f9", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Yes\n{\n public static void main(String ... args)\n {\n Scanner ss=new Scanner(System.in);\n int n=ss.nextInt();\n if(n%2)\n System.out.println(\"white\\n1 2\");\n else\n System.out.println(\"black\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7fe12fe80ffd08f47bd838832899bd98", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.*;import java.io.*;import java.math.*;\npublic class Main\n{\n public static void process()throws IOException\n {\n int n=ni();\n if(n%2==0)\n {\n pn(\"white\");\n pn(\"1 2\");\n }\n else pn(\"black\");\n }\n\n static AnotherReader sc;\n static PrintWriter out;\n public static void main(String[]args)throws IOException\n {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}\n else{sc=new AnotherReader(100);out=new PrintWriter(\"output.txt\");}\n int t=1;\n // t=ni();\n while(t-->0) {process();}\n out.flush();out.close(); \n }\n\n static void pn(Object o){out.println(o);}\n static void p(Object o){out.print(o);}\n static void pni(Object o){out.println(o);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 int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}\n static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}\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/////////////////////////////////////////////////////////////////////////////////////////////////////////\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}v", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c3e3a5787f862cb9d09ebe6c9960d411", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700} {"lang": "Java 8", "source_code": "public class VasyaAndChess\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tif(n%2 != 0)\n\t\t\tSystem.out.println(\"black\");\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(\"white\");\n\t\t\tSystem.out.println(1 + \" \" + 2);\n\t\t}\n\t\tsc.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ef061b0f24c7a1eff9498b84693d59a0", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700} {"lang": "Java 11", "source_code": " import java.util.Scanner;\n\n public class Solution{\n\n public static void main(String args[]){\n Scanner scn = new Scanner(System.in);\n long n = scn.nextLong();\n StringBuilder sb = new StringBuilder();\n if((n%2 == 0){\n sb.append(\"white\");\n sb.append(\"\\n\");\n sb.append(\"1 2\");\n System.out.println(sb.toString());\n return;\n }\n sb.append(\"black\");\n System.out.println(sb.toString());\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0cb8d7de2aef476002cf1929e8cbcfcb", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class PieRules {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int N = in.nextInt();\n int[] arr = new int[N];\n for (int i = 0; i < N; i++) {\n arr[i] = in.nextInt();\n }\n int[] dp = new int[N];\n dp[N-1] = arr[N-1];\n int sum = arr[N-1];\n for (int i = N-2; i>= 0; i--) {\n dp[i] = Math.max(dp[N+1], arr[N-1] + sum - dp[N+1]);\n sum += arr[i];\n }\n System.out.println(dp[N-1] + \" \" + (sum - dp[N-1]));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "72faf4465898ac1b08c9adc2582ff8da", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class MemSql {\n\n\tstatic int[] arr;\n\tstatic int[] com;\n\tstatic int[][] dp;\n\n\tpublic static int solve(int i, int opp) {\n\t\tif (i == arr.length)\n\t\t\treturn com[com.length - 1] - opp;\n\t\tif (dp[i][opp] != -1)\n\t\t\treturn dp[i][opp];\n\t\tint sum = com[i] - opp;\n\t\tint Give = solve(i + 1, opp + arr[i]);\n\t\tint Take = com[com.length - 1] - (solve(i + 1, sum));\n\t\treturn dp[i][opp] = Math.max(Give, Take);\n\n\t}\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\t\tarr = new int[N + 1];\n\t\tcom = new int[N + 1];\n\t\tfor (int i = 1; i <= N; i++) {\n\t\t\tarr[i] = sc.nextInt();\n\t\t\tcom[i] = com[i - 1] + arr[i];\n\t\t}\n\t\tdp = new int[N + 1][N * 100000 + 1];\n\t\tfor (int i = 0; i <= N; i++)\n\t\t\tArrays.fill(dp[i], -1);\n\t\tSystem.out.println(com[N] - solve(1, 0) + \" \" + solve(1, 0));\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\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\tpublic boolean nextEmpty() throws IOException {\n\t\t\tString s = nextLine();\n\t\t\tst = new StringTokenizer(s);\n\t\t\treturn s.isEmpty();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0cd496c2355bba2946fef4ab0691965a", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author HossamDoma\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n int n;\n int a;\n int dp;\n\n int dfs(int i, int player) {\n\n if (i == n)\n return 0;\n\n if (dp[i][player] != -1)\n return dp[i][player];\n\n// int nxt = (player == 1 ? 2 : 1);\n\n int x = a[i] + dfs(i + 1, 2);\n int y = dfs(i + 1, 1);\n\n if (player == 1)\n dp[i][player] = Integer.max(x, y);\n else\n dp[i][player] = Math.min(x, y);\n\n return dp[i][player];\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n n = in.nextInt();\n a = new int[n];\n\n\n int sum = 0;\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n sum += a[i];\n }\n\n dp = new int[n][3];\n for (int i = 0; i < n; ++i)\n Arrays.fill(dp[i], -1);\n\n int bob = dfs(0, 1);\n int alice = sum - bob;\n\n out.println(alice + \" \" + bob);\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public String test_string;\n\n public InputReader(InputStream test_stringeam) {\n reader = new BufferedReader(new InputStreamReader(test_stringeam), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n String line = null;\n if (test_string != null) {\n line = test_string;\n test_string = null;\n } else\n line = reader.readLine();\n\n tokenizer = new StringTokenizer(line);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2e7f59559b5ffd8525e94c4d62ccc522", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\npublic class Pie {\n\t\tpublic static void main(String args[]){\n\t\t\tScanner sc = new Scanner(System.in);\n\t\t\tint n = in.nextInt();\n\t\t\tint a[] = new int [n+1];\n\t\t\tint sum[] = new int[n+1];\n\n\t\t\tfor(int i = 0; i=0; i--){\n\n\t\t\t\tsum[i] = sum[i+1]+a[i];\n\t\t\t\tdp[i] = Math.max(dp[i+1], sum[i+1]-dp[i+1]+a[i]);\n\t\t\t}\n\t\t\tSystem.out.println((sum[0]-dp[0])+\" \"+dp[0]);\n\t\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4e26bbe6b8dd62f16a00f80e04835438", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500} {"lang": "Java 8", "source_code": "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 Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Task {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String lo = String.valueOf(in.nextInt());\n String hi = String.valueOf(in.nextInt());\n\n boolean loImportant = true, hiImportant = true;\n if (lo.length() < hi.length()) {\n loImportant = false;\n }\n\n boolean prioUp = true;\n StringBuilder sb = new StringBuilder();\n if (!loImportant) {\n if (hi.charAt(0) >= '5') {\n hiImportant = false;\n sb.append('4');\n } else {\n sb.append(hi.charAt(0));\n }\n } else if (lo.charAt(0) == hi.charAt(0)) {\n sb.append(lo.charAt(0));\n prioUp = lo.charAt(0) <= '4';\n } else if (hi.charAt(0) > '5') {\n hiImportant = false;\n if (lo.charAt(0) < '5') {\n loImportant = false;\n }\n\n sb.append('5');\n prioUp = false;\n } else if (lo.charAt(0) < '4') {\n loImportant = false;\n if (hi.charAt(0) > '5') {\n hiImportant = false;\n }\n\n sb.append('4');\n } else if (hi.length() == 1) {\n sb.append('4');\n } else if (lo.charAt(1) > '0') {\n loImportant = false;\n sb.append('5');\n prioUp = false;\n } else {\n hiImportant = false;\n sb.append('4');\n }\n\n for (int i = 1; i < hi.length(); ++i) {\n char c;\n if (prioUp) {\n c = '9';\n for (; c >= '0'; --c) {\n if (!hiImportant || c <= hi.charAt(i)) {\n break;\n }\n }\n } else {\n c = '0';\n for (; c <= '9'; ++c) {\n if (!loImportant || c >= lo.charAt(i)) {\n break;\n }\n }\n }\n\n sb.append(c);\n hiImportant &= c == hi.charAt(i);\n loImportant &= i < lo.length() && c == lo.charAt(i);\n }\n\n String s = sb.toString();\n\n StringBuilder s2 = new StringBuilder();\n for (char c : s.toCharArray()) {\n s2.append('9' - c);\n }\n\n long ans = Long.parseLong(s) * Long.parseLong(s2.toString());\n\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3485db38c7d208f93040d305ad6d39d4", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Reflexe2 {\n\n public static int reflexe(long cislo) {\n String cisloString = Long.toString(cislo);\n int vysledek = 0;\n for (int i = 0; i < cisloString.length(); i++) {\n vysledek = vysledek + 9 - (cisloString.charAt(i) - 48);\n if (i != cisloString.length() - 1) {\n vysledek = vysledek * 10;\n }\n }\n return (vysledek);\n }\n\n public static void main(String[] args) {\n Scanner mujScanner = new Scanner(System.in);\n\n long minCislo = mujScanner.nextLong();\n long maxCislo = mujScanner.nextLong();\n long desetiny = 1;\n\n String prevedeni1 = Long.toString(minCislo);\n String prevedeni2 = Long.toString(maxCislo);\n\n if (prevedeni1.length() < prevedeni2.length()) {\n for (int i = prevedeni1.length(); i < prevedeni2.length(); i++) {\n minCislo = minCislo * 10;\n }\n }\n\n if (prevedeni1.charAt(0) - 48 <= 5 && prevedeni2.charAt(0) - 48 >= 5) {\n desetiny = 5;\n for (int i = 1; i < prevedeni2.length(); i++) {\n desetiny = desetiny * 10;\n }\n } else if (prevedeni1.charAt(0) - 48 >= 5 && prevedeni2.charAt(0) - 48 >= 5) {\n desetiny = minCislo;\n for (int i = prevedeni1.length(); i < prevedeni2.length(); i++) {\n desetiny = desetiny * 10;\n }\n } else if (prevedeni1.charAt(0) - 48 <= 5 && prevedeni2.charAt(0) - 48 <= 5) {\n desetiny = maxCislo;\n for (int i = prevedeni1.length(); i < prevedeni2.length(); i++) {\n desetiny = desetiny * 10;\n }\n }\n System.out.println(reflexe(desetiny) * desetiny);\n\n// \n// if (desetiny != 1) {\n// minCislo = desetiny;\n// }\n//\n//\n// long vysledek = 0L;\n// long mezipocet = 0L;\n//\n// vysledek = reflexe(minCislo) * minCislo;\n// for (long i = minCislo; i <= maxCislo; i++) {\n// mezipocet = reflexe(i) * i;\n// if (mezipocet > vysledek) {\n// vysledek = reflexe(i) * i;\n// }\n// }\n// System.out.println(vysledek);\n }\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "51e48d3d423b644101773da48b5d462c", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600} {"lang": "Java 8", "source_code": "package code;\n\nimport FastIO.InputReader;\nimport java.io.PrintWriter;\n\npublic class Task {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String lo = String.valueOf(in.nextInt());\n String hi = String.valueOf(in.nextInt());\n\n boolean loImportant = true, hiImportant = true;\n if (lo.length() < hi.length()) {\n loImportant = false;\n }\n\n boolean prioUp = true;\n StringBuilder sb = new StringBuilder();\n if (!loImportant) {\n if (hi.charAt(0) >= '5') {\n hiImportant = false;\n sb.append('4');\n } else {\n sb.append(hi.charAt(0));\n }\n } else if (lo.charAt(0) == hi.charAt(0)) {\n sb.append(lo.charAt(0));\n prioUp = lo.charAt(0) <= '4';\n } else if (hi.charAt(0) > '5') {\n hiImportant = false;\n if (lo.charAt(0) < '5') {\n loImportant = false;\n }\n\n sb.append('5');\n prioUp = false;\n } else if (lo.charAt(0) < '4') {\n loImportant = false;\n if (hi.charAt(0) > '5') {\n hiImportant = false;\n }\n\n sb.append('4');\n } else if (hi.length() == 1) {\n sb.append('4');\n } else if (lo.charAt(1) > '0') {\n loImportant = false;\n sb.append('5');\n prioUp = false;\n } else {\n hiImportant = false;\n sb.append('4');\n }\n\n for (int i = 1; i < hi.length(); ++i) {\n char c;\n if (prioUp) {\n c = '9';\n for (; c >= '0'; --c) {\n if (!hiImportant || c <= hi.charAt(i)) {\n break;\n }\n }\n } else {\n c = '0';\n for (; c <= '9'; ++c) {\n if (!loImportant || c >= lo.charAt(i)) {\n break;\n }\n }\n }\n\n sb.append(c);\n hiImportant &= c == hi.charAt(i);\n loImportant &= i < lo.length() && c == lo.charAt(i);\n }\n\n String s = sb.toString();\n\n StringBuilder s2 = new StringBuilder();\n for (char c : s.toCharArray()) {\n s2.append('9' - c);\n }\n\n long ans = Long.parseLong(s) * Long.parseLong(s2.toString());\n\n out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0228f023a7941c8aba17323182034da0", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600} {"lang": "Java 6", "source_code": "/*import java.util.Scanner;\n\n\npublic class A86 \n{\n public static void main(String[] args) \n {\n Scanner in=new Scanner (System.in);\n \n long l=in.nextInt();\n long r=in.nextInt();\n long best=Math.max(func (l),func(r));\n for(long i=5; i=l)\n {\n best=Math.max(best,func(i));\n }\n }\n System.out.print(best);\n \n \n }\n public static long func(long x)\n {\n char rr[]=String.valueOf(x).toCharArray();\n for(int i=0; i= a)\n best = Math.max(best,w(i));\n }\n System.out.println(best);\n }\n public static long w(long x) {\n char[] v = String.valueOf(x).toCharArray();\n for(int i=0; i n){\n\t System.out.println(-1);\n\t return;\n\t }\n\t \n\t if(go(g)) h = g;\n\t else l = g + 1;\n\t }\n\t \n\t System.out.println(l);\n\t}\n\tstatic boolean go(int in){\n\t int tot = 0;\n\t int idx = n - 1;\n\t floop : for(int j = 0; ; ++j){\n\t for(int i = 0; i < in; ++i){\n\t tot += Math.max(arr[idx] - j, 0);\n\t --idx;\n\t if(idx == -1) break floop;\n\t }\n\t }\n\t // System.out.println(in + \" \" + tot);\n\t return tot >= m;\n\t}\n\tstatic int p(String in){\n\t return Integer.parseInt(in);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "be6844dc1bb05dab611d510797ea46a4", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.regex.*;\n\npublic class Solution \n{\n static class InputReader\n {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n\n public InputReader(InputStream st) \n {\n this.stream = st;\n }\n\n public int read() \n {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) \n {\n curChar = 0;\n try \n {\n snumChars = stream.read(buf);\n } catch (IOException e) \n {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() \n {\n int c = read();\n while (isSpaceChar(c)) \n {\n c = read();\n }\n int sgn = 1;\n if (c == '-') \n {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do \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 {\n int c = read();\n while (isSpaceChar(c)) \n {\n c = read();\n }\n int sgn = 1;\n if (c == '-') \n {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do \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 {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) \n {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() \n {\n int c = read();\n while (isSpaceChar(c)) \n {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do \n {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() \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 } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) \n {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) \n {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n }\n public static long power(long a,long b,long mod)\n {\n if(b==0)\n return 1;\n else if(b==1)\n return a;\n else\n {\n if(b%2==1)\n {\n long p=power(a,b/2,mod);\n return((p*p*a)%mod);\n }\n else\n {\n long p1=power(a,b/2,mod);\n return((p1*p1)%mod);\n }\n }\n }\n public static boolean possible(long x,ArrayList al,long[] suf,long m)\n {\n boolean ret=false;\n int n=al.size();\n long sum=0;\n long count=0;\n long i=n-x;\n long prev=i;\n for(i=n-x;i>=0;i-=(x))\n {\n sum+=(long)Math.max(0,suf[(int)i]-suf[(int)(i+x)]-(count*x));\n count++;\n if(sum>=m)\n {\n return true;\n }\n prev=i;\n }\n if(i<0)\n {\n sum+=(long)Math.max(0,suf[0]-suf[(int)prev]-(count*(prev)));\n if(sum>=m)\n return true;\n }\n if(sum>=m)\n {\n return true;\n }\n return false;\n }\n public static long mod=1000000007;\n public static void main(String[] args) throws IOException \n {\n InputReader in=new InputReader(System.in);\n PrintWriter w=new PrintWriter(System.out);\n int n=in.nextInt();\n long m=in.nextLong();\n ArrayList al=new ArrayList();\n for(int i=0;i=0;i--)\n {\n suf[i]=suf[i+1]+al.get(i);\n }\n long lo=1,hi=n,mid=lo+((hi-lo)/2);\n long ans=m;\n while(lo<=hi)\n {\n if(possible(mid,al,suf,m))\n {\n //w.println(\"acc \"+mid);\n hi=mid-1;\n ans=mid;\n }\n else\n {\n //w.println(\"rej \"+mid);\n lo=mid+1;\n }\n mid=lo+((hi-lo)/2);\n }\n //possible(1,al,suf,m);\n if(suf[0]>=m)\n w.println(ans);\n else\n w.println(\"-1\");\n w.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3db151981c12a3e8409bd195d44afd37", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700} {"lang": "Java 8", "source_code": "import com.sun.deploy.util.ArrayUtil;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n static int n;\n static int m;\n static int[]a;\n static int start;\n static int end;\n static int ans;\n public static void main(String[] args) throws Exception\n {\n Scanner in = new Scanner(System.in);\n OutputWriter out = new OutputWriter(System.out);\n n = in.nextInt();\n a = new int[n];\n m = in.nextInt();\n for (int i =0;istart)\n {\n int mid = (end+start)/2;\n if (f(mid))\n {\n ans=mid;\n end=mid-1;\n }\n else\n start=mid+1;\n }\n\n }\n static boolean f(int y)\n {\n int ans=0;\n for (int i=0;i=m)\n return true;\n return false;\n }\n static void MergeSort(int[] a, int p, int r)\n {\n if (p < r)\n {\n int q = (r + p) / 2;\n MergeSort(a, p, q);\n MergeSort(a, q + 1, r);\n Merge(a, p, q, r);\n }\n }\n static void Merge(int[] a,int p, int q, int r)\n {\n int n1 = q - p + 1;\n int n2 = r - q;\n int[] R = new int[n1 + 1];\n int[] L = new int[n2 + 1];\n\n\n for (int i = 0; i < n1; i++)\n {\n R[i] = a[p + i];\n\n\n }\n R[n1] = Integer.MAX_VALUE;\n for (int i = 0; i < n2; i++)\n {\n L[i] = a[q + i + 1];\n\n\n }\n L[n2] =Integer.MAX_VALUE;\n int n = a.length;\n int j = 0;\n int k = 0;\n for (int i = p; i <= r; i++)\n {\n if (L[j] < R[k])\n {\n a[i] = L[j];\n\n\n j++;\n }\n else\n {\n a[i] = R[k];\n\n\n k++;\n }\n\n\n }\n }\n}\nclass Graph {\n\n\n int n;\n ArrayList[] adjList;\n\n public Graph(int n) {\n this.n = n;\n adjList = new ArrayList[n];\n for (int i = 0; i < n; i++)\n adjList[i] = new ArrayList<>();\n }\n\n}\nclass pair implements Comparable\n{\n\n int key;\n int value;\n int id;\n public pair(Object key, Object value,Object id) {\n\n this.key = (int)key;\n this.value=(int)value;\n this.id=(int)id;\n }\n\n @Override\n public int compareTo(Object o) {\n pair temp =(pair)o;\n if (key!=temp.key)\n return key-temp.key;\n else return id-temp.id;\n }\n}\nclass Scanner {\n\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner (FileReader f) {\n br = new BufferedReader(f);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n String x = next();\n StringBuilder sb = new StringBuilder(\"0\");\n double res = 0, f = 1;\n boolean dec = false, neg = false;\n int start = 0;\n if (x.charAt(0) == '-') {\n neg = true;\n start++;\n }\n for (int i = start; i < x.length(); i++)\n if (x.charAt(i) == '.') {\n res = Long.parseLong(sb.toString());\n sb = new StringBuilder(\"0\");\n dec = true;\n } else {\n sb.append(x.charAt(i));\n if (dec)\n f *= 10;\n }\n res += Long.parseLong(sb.toString()) / f;\n return res * (neg ? -1 : 1);\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n public boolean nextEmpty() throws IOException {\n String s = nextLine();\n st = new StringTokenizer(s);\n return s.isEmpty();\n }\n}\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d2ac6e45162d0af6564e2d96d94a4a94", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Run {\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner(System.in);\n\t\tString wholeInput = input.nextLine();\n\t\tString[] token = wholeInput.split(\" \");\n\t\tint n = Integer.valueOf(token[0]);\n\t\tint m = Integer.valueOf(token[1]);\n\t\twholeInput = input.nextLine();\n\t\ttoken = wholeInput.split(\" \");\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = Integer.valueOf(token[i]);\n\t\t}\n\t\tinput.close();\n\t\ttoken = null;\n\t\tint S = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tS += a[i];\n\t\t}\n\t\tif (m > S)\n\t\t{\n\t\t\tSystem.out.print(-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(solve(0, m, m, a));\n\t\t}\n\t}\n\t\n\tprivate static boolean checkAnswer(int m, int day, int[] a)\n\t{\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t{\n\t\t\ta[i] = -a[i];\n\t\t}\n\t\tArrays.sort(a);\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t{\n\t\t\ta[i] = -a[i];\n\t\t}\n\t\tint arrayMarker = 0;\n\t\tint cupMarker = 0;\n\t\tint S = 0;\n\t\twhile(true)\n\t\t{\n\t\t\tif (a[arrayMarker] - cupMarker > 0)\n\t\t\t{\n\t\t\t\tS += a[arrayMarker] - cupMarker;\n\t\t\t}\n\t\t\tarrayMarker++;\n\t\t\tif (arrayMarker % day == 0)\n\t\t\t{\n\t\t\t\tcupMarker++;\n\t\t\t}\n\t\t\tif (arrayMarker == a.length)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (S >= m)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\t\n\tprivate static int solve(int tempPos, int length, int m, int[] a)\n\t{\n\t\tint checkPos = tempPos + length / 2;\n\t\tif (length == 0)\n\t\t{\n\t\t\treturn tempPos;\n\t\t}\n\t\tif (checkAnswer(m, checkPos, a))\n\t\t{\n\t\t\treturn solve(tempPos, checkPos - tempPos, m, a);\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn solve(checkPos + 1, tempPos + length - checkPos - 1, m, a);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c9db23417fe414f19c883e9263900d9", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700} {"lang": "Java 8", "source_code": "//Problem 2\n//Codeforces 32C\n//Meg Rydson, Brian Chren, Chris Johnson\n\nimport java.util.*;\nimport java.io.*;\n\npublic class flea {\n public static void main(String[] args) throws IOException{\n Input.init( System.in );\n PrintWriter out = new PrintWriter(System.out);\n int n = Input.nextInt(); // length of the board\n int m = Input.nextInt(); // width of the board\n int s = Input.nextInt(); // length of the flea's jump\n \n \n int output = ((1 + (n-1)/s) * (1 + (m -1)/s)) * ((1 + (n-1) % s) * (1 + (m -1) % s));\n \n \n out.println(output);\n\n \n\n out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "562106e3d82ef223c8e8c6cd045e1490", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\n\npublic class Flea {\n\tpublic static void main(String[] args) {\n\t\t\n\t\t//try {\n\t\t//\tSystem.setIn(new FileInputStream(\"in.test\"));\n\t\t//\tSystem.setOut(new PrintStream(new FileOutputStream(\"out.txt\")));\n\t\t//} catch (FileNotFoundException e) {\n\t\t//\te.printStackTrace();\n\t\t//}\n\t\tScanner cin = new Scanner(System.in);\n\t\twhile (cin.hasNext()) {\n\t\t\tint n = cin.nextInt();\n\t\t\tint m = cin.nextInt();\n\t\t\tint s = cin.nextInt();\n\t\t\tint sn = (n - 1)/s + 1;\n\t\t\tint sm = (m - 1)/s + 1;\n\t\t\tint nn = n % s;\n\t\t\tif (nn == 0) {\n\t\t\t\tnn = s;\n\t\t\t}\n\t\t\tint mm = m % s;\n\t\t\tif (mm == 0) {\n\t\t\t\tmm = s;\n\t\t\t}\n\t\t\tSystem.out.println(sn * sm * nn * mm);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "557c12a090a512354c2980ea73d21b8b", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author andrey\n */\npublic class Flea {\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 s = in.nextInt();\n if(ns && m>s){\n int a = (n-1)/s+1;\n int b = (m-1)/s+1;\n int lefta = (n-1)%s+1;\n int leftb = (m-1)%s+1;\n System.out.println(a*lefta*b*leftb);\n }\n else if(m<=s && n>s){\n int a = (n-1)/s+1;\n int lefta = (n-1)%s+1;\n System.out.println(a*lefta*m);\n }else{\n System.out.println(n*m);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8d60718105dd5dd1bce5f07e427fdcd8", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport java.math.*;\n\npublic class Main implements Runnable {\n\tBufferedReader in;\n\tPrintStream out; \n\tStringTokenizer st = new StringTokenizer(\"\");\n\t\n\tpublic static void main(String [] args) throws Exception {\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tvoid printExit(String s) {\n\t\tSystem.out.println(s);\n\t\tSystem.exit(0);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintStream(System.out);\n\t\t\tint w = nextInt(), h = nextInt(), s = nextInt();\n\t\t\tint [] a = new int [] {w, h};\n\t\t\tint [] good = new int[2];\n\t\t\tfor (int i = 0; i < 2; i++) {\n\t\t\t\tint r = (a[i] - 1) % s + 1;\n\t\t\t\tfor (int j = 0; j < a[i]; j++)\n\t\t\t\t\tif (j % s < r) good[i]++;\n\t\t\t}\n\t\t\tout.println(good[0] * good[1]);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\t boolean seekForToken() {\n \t\ttry {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\tString s = in.readLine();\n\t\t\t\tif (s == null) {\n\t\t\t\t \treturn false;\n\t\t\t\t}\n\t\t\t \tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tcatch (IOException e) {\n\t\t \te.printStackTrace();\n\t\t \treturn false;\n\t\t}\n \t}\n\n \t int nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n \t}\n\n \t long nextLong() {\n\t\treturn Long.parseLong(nextToken());\n \t}\n\n \t double nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n \t}\n\n \t BigInteger nextBigInteger() {\n \t \treturn new BigInteger(nextToken());\n \t}\n\n \t String nextToken() {\n \t \tseekForToken();\n \t \treturn st.nextToken();\n \t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "438da7965815a5bcdc63f635e349d08c", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class abv {\npublic static void main(String[]args)throws IOException\n{\nBufferedReader buf=new BufferedReader(new InputStreamReader(System.in));\nint c=0;int c1=0;\nint n=Integer.parseInt(buf.readLine());\nfor(int j=2;j<=n;j++)\n{\nfor(int i=2;i<=j;i++)\n{\nif(isprime(i)&&n%i==0)\nc++;\n}\nif(c==2)\nc1++;\n}\nSystem.out.println(c1);\n}\npublic static boolean isprime(int a)\n{\nint l=0;\nfor(int i=1;i<=n;i++)\n{\nif(n%i==0)\nl++;\n}\nif(l==2)\nreturn true;\nelse\nreturn false;\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7b52bc74f00fb40dcd68aefb150a31e1", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class abv {\npublic static void main(String[]args)\n{\nBufferedReader buf=new BufferedReader(new InputStreamReader(System.in));\nint c=0;int c1=0;\nint n=Integer.parseInt(buf.readLine());\nfor(int j=2;j<=n;j++)\n{\nfor(int i=2;i<=j;i++)\n{\nif(isprime(i)&&n%i==0)\nc++;\n}\nif(c==2)\nc1++;\n}\nSystem.out.println(c1);\n}\npublic static boolean isprime(int a)\n{\nint l=0;\nfor(int i=1;i<=n;i++)\n{\nif(n%i==0)\nl++;\n}\nif(l==2)\nreturn true;\nelse\nreturn false;\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b5494ea2c11a44e73f6bfc98f04ee90", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class Almost_prime_26A\n{\n public static void func(int n)\n {\n int []prime = new int[n+1];\n Arrays.fill(prime, 0);\n for(int i=2; i*i 0)\n {\n int num = scan.nextInt();\n func(num); \n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "46edc6f8fe0de65f13fb1801bc705288", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900} {"lang": "Java 11", "source_code": "\nimport java.util.Scanner;\n\npublic class AlmostPrime \n{\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner scan=new Scanner(System.in);\n\t\tint threshHold=scan.nextInt();\n\t\tint num=2,prime=2;\n\t\tint count=0;\n\t\tint flag=0;\n\t\tint res=0;\n\t\tint temp=-1;\n\t \twhile(num<=threshHold)\n\t\t\t{\n\t \t\t\n\t\t\t if(num%prime==0 &&num>=prime) \n\t\t\t {\n\t\t\t\t if(temp==-1) \n\t\t\t\t {\n\t\t\t\t\t temp=num/prime;\n\t\t\t\t }\n\t\t\t\t else \n\t\t\t\t {\n\t\t\t\t\t temp=temp/prime;\n\t\t\t\t }\n\t\t\t prime=getPrime(prime+1);\n\t\t\t\t count++;\n\t\t\t\t \n\t\t\t\t if(count==2) \n\t\t\t\t {\n`\t\t\t\t\t while(prime<=temp)\n\t\t\t\t\t {\n\t\t\t\t\t if(num%getPrime(prime)==0) \n\t\t\t\t\t {\n\t\t\t\t\t flag=1;\n\t\t\t\t\t break;\n\t\t\t\t\t }\n\t\t\t\t\t prime=prime+1;\n\t\t\t\t\t }\n\t\t\t\t\t temp=-1;\n\t\t\t\t\t if(flag==0) \n\t\t\t\t\t {\n\t\t\t\t\t\t res=res+1;\n\t\t\t\t\t }\n\t\t\t\t\t num++;\n\t\t\t\t\t count=0;\n\t\t\t\t\t prime=2;\n\t\t\t\t\t flag=0;\n\t\t\t\t }\n\t\t\t }\n\t\t\t else if(num=1)\n\t\t\t {\n\t\t\t\t prime=getPrime(prime+1);\n\t\t\t }\n\t\t\t else \n\t\t\t {\n//\t\t\t\t System.out.println(prime+\" \"+num);\n\t\t\t }\n\t\t\t}\n\t\tSystem.out.println(res);\n\n\t\tscan.close();\n\t\t\n\t}\n\tstatic int getPrime(int num) \n\t{\n\t\tint count=2;\n\t\tif(num<2) \n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\twhile(true) \n\t\t{\n\t\t\tif(num%count==0 && num>count) \n\t\t\t{\n\t\t\t\tcount=2;\n\t\t\t\tnum++;\n\t\t\t}\n\t\t\telse if(count==num)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\treturn num;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "319fe23ddf13ef4bd3ec895e20061fe1", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class R311 {\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = Integer.parseInt(sc.nextLine()); int[] mins = new int[3], maxes = new int[3];\n\t\tfor(int i = 0; i < 3; i++){\n\t\t\tStringTokenizer s = new StringTokenizer(sc.nextLine());\n\t\t\tmins[i] = Integer.parseInt(s.nextToken()); \n\t\t\tmaxes[i] = Integer.parseInt(s.nextToken());\n\t\t} int one=mins[0],two=mins[1],three=mins[2];\n\t\tint start = mins[0]+mins[1]+mins[2];\n\t\twhile(start < N && one < maxes[0]){start++;one++;}\n\t\twhile(start < N && two < maxes[1]){start++;two++;}\n\t\twhile(start < N && three < maxes[2]){start++;three++;}\n\t\tSystem.out.println(one + \" \" + two + \" \" + three);\n\t}\n}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0420628e07caae7c5abd1c2acb387885", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100} {"lang": "Java 8", "source_code": "cimport java.util.Scanner;\npublic class IlyaandDiplomas {\npublic static void main(String args[]){\n Scanner s=new Scanner(System.in); \n int n=s.nextInt();\n //s.nextLine();\n int min1,max1,min2,max2,min3,max3;\n min1=s.nextInt();\n max1=s.nextInt();\n //s.nextLine();\n min2=s.nextInt();\n max2=s.nextInt();\n //s.nextLine();\n min3=s.nextInt();\n max3=s.nextInt();\n int s1=0,s2=0,s3=0;\n int intermediateone=n;\n if(intermediateone-min2-min3>=max1){\n s1=max1;\n intermediateone-=max1;\n if(intermediateone-min3>=max2){\n s2=max2;\n intermediateone-=max2;\n if(intermediateone>=max3){\n s3=max3;\n }\n else {\n s3=intermediateone;\n } \n }\n else{\n s2=intermediateone-min3; \n s3=min3;\n }\n }\n else {\n s1=intermediateone-min2-min3;\n s2=min2;\n s3=min3; \n }\n System.out.println(s1+\" \"+s2+\" \"+s3);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae020170de7497500126c3fcc9a90cd5", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100} {"lang": "Java 7", "source_code": "public class Main {\n\n public static void main(String[] args) {\n \n public int i,j,l;\n public int minFirts, maxFirst, minSecond, maxSecond, minThird, maxThird;\n public int summ;\n\n public RunProgramm(){\n Scanner in = new Scanner(System.in);\n summ = in.nextInt();\n minFirts = in.nextInt();\n maxFirst = in.nextInt();\n minSecond = in.nextInt();\n maxSecond = in.nextInt();\n minThird = in.nextInt();\n maxThird = in.nextInt();\n\n i = minFirts;\n j = minSecond;\n l = minThird;\n\n while ((i+j+l)=a&&b-a<=1) System.out.println(\"YES\");\n\telse System.out.println(\"NO\")\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7d48508268a2a74fbe455147927c7947", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint a = sc.nextInt(),b=sc.nextInt();\n\t\t\n\n\t\tSystem.out.print(Math.abs(a-b)<=1? \"YES\" : \"NO\");\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e32689bdf39ab0c016d8e6910d018349", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000} {"lang": "Java 8", "source_code": "import hava.util.Scanner;\npublic class Main{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int a = in.nextInt();\n int b = in.nextInt();\n if(a==b || b==a+1 || a==b+1)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f6267ba3e42de6f17033e125e667067", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Dasha_and_Stairs {\n\n\tpublic static void main(String[] args) {\n\t\tScanner out = new Scanner(System.in);\n\n\t\tint a = out.nextInt();\n\t\tint b = out.nextInt();\n\n\t\tif ((a==b+1)||(a==b-1)||(a==b+1)||(a==b-1)||(a==b) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t}\n\t\telse System.out.println(\"NO\");\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "12b4ff75ca8f70dd606535a8c90affb9", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class test5 {\n\n\tpublic static void main(String args[]){\n\t\t MyScanner sc = new MyScanner();\n\t out = new PrintWriter(new BufferedOutputStream(System.out));\n\t int initlength = sc.nextInt();\n\t int finlength = sc.nextInt();\n\t int holder = 0;\n\t int seconds = 0;\n\t int[] sidelengths = new int[3];\n\t if(initlength < finlength){\n\t \t sidelengths[0] = initlength;\n\t \t sidelengths[1] = initlength;\n\t \t sidelengths[2] = initlength;\n\t }\n\t else{\n\t \t sidelengths[0] = finlength;\n\t \t sidelengths[1] = finlength;\n\t \t sidelengths[2] = finlength;\n\t \t holder = initlength;\n\t \t initlength = finlength;\n\t \t finlength = holder;\n\t } \n\t while(sidelengths[0] != finlength){\n\t \t System.out.println(\"hello\");\n\t \t if(finlength < 2*sidelengths[2])\n\t \t {\n\t \t\t seconds += 3;\n\t \t\t sidelengths[0] = finlength;\n\t \t }\n\t \t else if(finlength == 2*sidelengths[2]){\n\t \t\t seconds += 4;\n\t \t\t sidelengths[0] = finlength;\n\t \t } \n\t \t {\n\t \t\t sidelengths[0] = sidelengths[1] + sidelengths[2] - 1;\n\t \t\t sidelengths[1] = sidelengths[0] + sidelengths[2] - 1;\n\t \t\t sidelengths[2] = sidelengths[0] + sidelengths[1] - 1;\n\t \t\t seconds += 3;\n\t \t }\n\t }\n\t System.out.println(seconds);\n\t \t \n\t }\n\n\t \n\n\t //-----------PrintWriter for faster output---------------------------------\n\t public static PrintWriter out;\n\t \n\t //-----------MyScanner class for faster input----------\n\t public static class MyScanner {\n\t BufferedReader br;\n\t StringTokenizer st;\n\n\t public MyScanner() {\n\t br = new BufferedReader(new InputStreamReader(System.in));\n\t }\n\n\t String next() {\n\t while (st == null || !st.hasMoreElements()) {\n\t try {\n\t st = new StringTokenizer(br.readLine());\n\t } catch (IOException e) {\n\t e.printStackTrace();\n\t }\n\t }\n\t return st.nextToken();\n\t }\n\t int nextInt() {\n\t return Integer.parseInt(next());\n\t }\n\t long nextLong() {\n\t return Long.parseLong(next());\n\t }\n\t double nextDouble() {\n\t return Double.parseDouble(next());\n\t }\n\t String nextLine(){\n\t String str = \"\";\n\t\t try {\n\t\t str = br.readLine();\n\t\t } catch (IOException e) {\n\t\t e.printStackTrace();\n\t\t }\n\t\t return str;\n\t }\n\t } \n\t }\n\t/*\n\tint n = sc.nextInt(); // read input as integer\n\tlong k = sc.nextLong(); // read input as long\n\tdouble d = sc.nextDouble(); // read input as double\n\tString str = sc.next(); // read input as String\n\tString s = sc.nextLine(); // read whole line as String\n\t*/", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1be21f0aacf9a14aa1776ef0166f623d", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600} {"lang": "Java 8", "source_code": "/*\n * Code Author: Mayank Kumar\n * Institute : DA-IICT \n * 3rd year BTech ICT Student\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class CFEDU15E \n{\n\tstatic int[][] pa,min;\n\tstatic long[][] sum;\n\tprivate static int[] nextIntArray(InputReader in,int n)\t\n\t{\n\t\tint[] a=new int[n];\n\t\tfor(int i=0;in){\n\t\t\ta[1]=n;\n\t\t\tArrays.sort(a);\n\t\t\tcontinue;\n\t\t}\n\t\ta[0]=a[1]+a[2]-1;\n\t\tArrays.sort(a);\n\t}\n\tSystem.out.println(s);\n\t}\n\tstatic class InputReader {\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\t\tprivate SpaceCharFilter filter;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9054a0d3604b6de808cc3be14934daf3", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\n\npublic class CF712C {\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 int res = devolve(x, y);\n System.out.println(res); \n } \n\n public static int devolve(int x, int y) {\n int res = 0; \n int a = y;\n int b = y;\n int c = y;\n \n // All must Increment up to x\n while (a != x || b != x || c != x) {\n // Vouga conditions\n for (int i = 0; i < 3; i++) {\n \n //a + b > c\n if (i == 0) {\n c = a + b - 1; \n }\n \n // b + c > a\n if (i == 1) {\n a = b + c - 1; \n }\n \n // c + a > b\n if (i == 2) {\n b = c + a - 1; \n } \n res++;\n }\n \n \n \n } \n \n return res;\n } \n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3c0037881df811923110cfe74ab5c3d8", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600} {"lang": "Java 8", "source_code": "// package CodeForces;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Problem_712C {\n\tpublic static int get(int[]d1,int sum)\n\t{\n\t\tint[]d=d1.clone();\n\t\tif(d[2]==y)\n\t\t{\n\t\t\treturn sum;\n\t\t}\n//\t\tif(sol[d[1]][d[2]]<=sum)\n//\t\t\treturn sol[d[1]][d[2]];\n\t\tint x=Math.max(d[1]-d[0]+1,y);\n\t\td[2]=x;\n\t\tArrays.sort(d);\n\t\treturn get(d,sum+1);\n\t}\n\tstatic int[][]sol;static int y;\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint x=sc.nextInt();y=sc.nextInt();\n\t\tsol=new int[x+1][x+1];\n\t\tint[]a=new int[3];\n\t\tArrays.fill(a, x);int min=Integer.MAX_VALUE;\n\t\twhile(a[0]>=y)\n\t\t{\n\t\t\ta[0]--;\n\t\t\tmin=Math.min(min, get(a,0));\n\t\t}\n\t\tSystem.out.println(min+1);\n\t\tpw.close();\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\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\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\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tboolean hasnext() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cbcc92e1a48a2aeef48cd6536a31abdd", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.util.*;\n \npublic class BoringApartments{\n public static void main(String[] args){\n try{\n Scanner scan = new Scanner(System.in);\n int t,n,i,j,temp,ans;\n t = scan.nextInt();\n \n for(i=0; i arr = new ArrayList();\n // for(int i=0;i0){\n int n = ss.nextInt();\n// int a[] = new int[n];\n// int b[] = new int[n];\n// int c[] = new int[n];\n// \n \n int sum = 0;\n for(int i=1;i=nos[k]) {\n\t\t\t\t\t\t\tbest = Math.max(best, dp[k]+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdp[i] = best;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i=0; i=nos[k]) {\n\t\t\t\t\t\t\tbest = Math.max(best, dp[k]+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdp[i] = best;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = dp[0];\n\t\tfor (int i=1; in){\n\t\t\tint[] freq = new int[300];\n\t\t\tfor (int i=0; i=nos[k]) {\n\t\t\t\t\t\t\tbest = Math.max(best, dp[k]+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdp[i] = best;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int i=0; i=nos[k]) {\n\t\t\t\t\t\t\tbest = Math.max(best, dp[k]+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdp[i] = best;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = dp[0];\n\t\tfor (int i=1; in){\n\t\t\tint[] freq = new int[300];\n\t\t\tfor (int i=0; i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n\n static class IOUtils {\n public static int[] readIntArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n array[i] = in.readInt();\n return array;\n }\n\n }\n}\n\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Feng Jiajie\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 n = in.readInt();\n int T = in.readInt();\n int[] num = IOUtils.readIntArray(in, n);\n int multi = Math.max(3, T);\n int[] numx = new int[multi * n];\n for (int i = 0; i < multi; i++) {\n for (int j = 0; j < n; j++) {\n numx[i * n + j] = num[j];\n }\n }\n int[] dp = new int[n * multi];\n Arrays.fill(dp, 0);\n for (int i = 0; i < n * multi; ++i) {\n int cnt = 0;\n for (int j = 0; j < i; j++) {\n if (numx[j] <= numx[i]) {\n cnt = Math.max(cnt, dp[j]);\n }\n }\n dp[i] = cnt + 1;\n }\n int ans = 0;\n if (T <= 3) {\n for (int i = 0; i < n * T; ++i) {\n ans = Math.max(ans, dp[i]);\n }\n } else {\n int[] cha = new int[n];\n for (int i = 0; i < n; i++) {\n cha[i] = dp[n * 2 + i] - dp[n + i];\n }\n for (int i = 0; i < n; i++) {\n ans = Math.max(ans, cha[i] * (T - 3) + dp[n * 2 + i]);\n }\n }\n out.printLine(ans);\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 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 int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n\n static class IOUtils {\n public static int[] readIntArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n array[i] = in.readInt();\n return array;\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "75c144f3dd8267fa2c1a0539529d8a03", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2", "difficulty": 1900} {"lang": "Java 7", "source_code": "//pakage joney_000[let_me_start]\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n/******************** Main Class ***********************/\npublic class FastReader{\n\n private boolean finished = false;\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public FastReader(InputStream stream){\n this.stream = stream;\n }\n\n public int read(){\n if (numChars == -1){\n throw new InputMismatchException ();\n }\n if (curChar >= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n throw new InputMismatchException ();\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int peek(){\n if (numChars == -1){\n return -1;\n }\n if (curChar >= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n return -1;\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar];\n }\n\n public int nextInt(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n int res = 0;\n do{\n if(c==','){\n c = read();\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public long nextLong(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n long res = 0;\n do{\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public String nextString(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n StringBuilder res = new StringBuilder ();\n do{\n res.appendCodePoint (c);\n c = read ();\n } while (!isSpaceChar (c));\n return res.toString ();\n }\n\n public boolean isSpaceChar(int c){\n if (filter != null){\n return filter.isSpaceChar (c);\n }\n return isWhitespace (c);\n }\n\n public static boolean isWhitespace(int c){\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0(){\n StringBuilder buf = new StringBuilder ();\n int c = read ();\n while (c != '\\n' && c != -1){\n if (c != '\\r'){\n buf.appendCodePoint (c);\n }\n c = read ();\n }\n return buf.toString ();\n }\n\n public String nextLine(){\n String s = readLine0 ();\n while (s.trim ().length () == 0)\n s = readLine0 ();\n return s;\n }\n\n public String nextLine(boolean ignoreEmptyLines){\n if (ignoreEmptyLines){\n return nextLine ();\n }else{\n return readLine0 ();\n }\n }\n\n public BigInteger nextBigInteger(){\n try{\n return new BigInteger (nextString ());\n } catch (NumberFormatException e){\n throw new InputMismatchException ();\n }\n }\n\n public char nextCharacter(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n return (char) c;\n }\n\n public double nextDouble(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n double res = 0;\n while (!isSpaceChar (c) && c != '.'){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n }\n if (c == '.'){\n c = read ();\n double m = 1;\n while (!isSpaceChar (c)){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read ();\n }\n }\n return res * sgn;\n }\n\n public boolean isExhausted(){\n int value;\n while (isSpaceChar (value = peek ()) && value != -1)\n read ();\n return value == -1;\n }\n\n public String next(){\n return nextString ();\n }\n\n public SpaceCharFilter getFilter(){\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter){\n this.filter = filter;\n }\n\n public interface SpaceCharFilter{\n public boolean isSpaceChar(int ch);\n }\n}\n /******************** Pair class ***********************/\n \n class Pair implements Comparable{\n public int a;\n public int b;\n \n \n public Pair(){\n this.a = 0;\n this.b = 0;\n \n }\n public Pair(int a,int b , int n , long s){\n this.a = a;\n this.b = b;\n }\n public int compareTo(Pair p){\n if(this.a==p.a){\n return this.b-p.b; \n }\n return this.a-p.a; \n }\n public String toString(){\n return \"a=\"+this.a+\" b=\"+this.b;\n }\n \n}\n\npublic class A\n{ \n public static InputStream inputStream = System.in;\n public static OutputStream outputStream = System.out;\n public static FastReader in = new FastReader(inputStream);;\n public static PrintWriter out = new PrintWriter(outputStream);;\n /*\n Overhead\n */\n public static int tempints[] = new int[100005];\n public static long templongs[] = new long[100005];\n public static double tempdoubles[] = new double[100005];\n //public static double tempdoubles[] = new double[11];\n public static char tempchars[] = new char[100005];\n \n \n public static void main(String[] args) throws java.lang.Exception\n {\n //let_me_start \n \n \n \n \n int a = i();int b = i();int p = i();int q = i();\n long v= 1;\n long x = 0;\n long y= 0;\n long l = 1;\n long r = 100000000000000000L;\n \n \n long z= 0;\n while (l <= r) \n { \n long m = (l + r) / 2; \n v=m;\n x= v-(v/p);\n y =v-v/q;\n z= v-v/p-v/q+v/(p*q);\n \n \n //z= v-(v/g);\n //If the search key on the left half \n if (x>a&&y>b&&x+y-z>a+b) \n { \n //Update right index \n r = m - 1;\n } \n //If the search key on the right half \n else if (x ll = new LinkedList();\n for(int i=1;i<=n;i++){\n if(arr[i])ll.add(i);\n }\n n = ll.size();\n \n int primes[] = new int[n+1];\n for(int i=1;i<=n;i++){\n primes[i]=ll.removeFirst();\n }\n return primes;\n }\n public static long gcd (long a , long b)throws Exception{\n if(b==0)return a;\n return gcd(b , a%b);\n }\n public static long lcm (long a , long b)throws Exception{\n if(a==0||b==0)return 0;\n return (a*b)/gcd(a,b);\n }\n public static long mulmod(long a , long b ,long mod)throws Exception{\n if(a==0||b==0)return 0;\n if(b==1)return a;\n long ans = mulmod(a,b/2,mod);\n ans = (ans*2)% mod;\n if(b%2==1)ans = (a + ans)% mod;\n return ans;\n }\n public static long pow(long a , long b ,long mod)throws Exception{\n if(b==0)return 1;\n if(b==1)return a;\n long ans = pow(a,b/2,mod);\n ans = (ans * ans)% mod;\n if(b%2==1)ans = (a * ans)% mod;\n return ans;\n }\n // 20*20 nCr Pascal Table\n public static long[][] ncrTable()throws Exception{\n long ncr[][] = new long[21][21];\n for(int i=0 ;i<=20 ;i++){ncr[i][0]=1;ncr[i][i]=1;}\n for(int j=0;j<=20 ;j++){\n for(int i=j+1;i<= 20 ;i++){\n ncr[i][j] = ncr[i-1][j]+ncr[i-1][j-1];\n }\n }\n return ncr;\n }\n//*******************************I/O******************************// \npublic static int i()throws Exception{\n //return Integer.parseInt(br.readLine().trim());\n return in.nextInt();\n}\npublic static int[] is(int n)throws Exception{\n //int arr[] = new int[n+1];\n for(int i=1 ; i <= n ;i++)tempints[i] = in.nextInt(); \n return tempints;\n}\npublic static long l()throws Exception{\n return in.nextLong();\n}\npublic static long[] ls(int n)throws Exception{\n //long arr[] = new long[n+1];\n for(int i=1 ; i <= n ;i++)templongs[i] = in.nextLong(); \n return templongs;\n}\n\npublic static double d()throws Exception{\n return in.nextDouble();\n}\npublic static double[] ds(int n)throws Exception{\n //double arr[] = new double[n+1];\n for(int i=1 ; i <= n ;i++)tempdoubles[i] = in.nextDouble(); \n return tempdoubles;\n}\npublic static char c()throws Exception{\n return in.nextCharacter();\n}\npublic static char[] cs(int n)throws Exception{\n //double arr[] = new double[n+1];\n for(int i=1 ; i <= n ;i++)tempchars[i] = in.nextCharacter(); \n return tempchars;\n}\npublic static String s()throws Exception{\n return in.nextLine();\n}\npublic static BigInteger bi()throws Exception{\n return in.nextBigInteger();\n}\n//***********************I/O ENDS ***********************//\n//*********************** 0.3%f [precision]***********************//\n/* roundoff upto 2 digits \n double roundOff = Math.round(a * 100.0) / 100.0;\n or\n System.out.printf(\"%.2f\", val);\n \n*/\n/* print upto 2 digits after decimal\n val = ((long)(val * 100.0))/100.0;\n \n*/\n}\n\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f36c75eaa66f5a5ff7553716c4d1559b", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.StringTokenizer;\n\n/*\n public class _482A{ }\n */\n\npublic class _483B\n{\n\tpublic void solve() throws FileNotFoundException\n\t{\n\t\tInputStream inputStream = System.in;\n\n\t\tInputHelper inputHelper = new InputHelper(inputStream);\n\n\t\tPrintStream out = System.out;\n\n\t\t// actual solution\n\n\t\tint c1 = inputHelper.readInteger();\n\t\tint c2 = inputHelper.readInteger();\n\n\t\tint x = inputHelper.readInteger();\n\t\tint y = inputHelper.readInteger();\n\n\t\tlong min = 2;\n\t\tlong max = 4000000000L;\n\n\t\tlong ans = max;\n\n\t\twhile (min <= max)\n\t\t{\n\t\t\tlong mid = (min + max) / 2;\n\n\t\t\tif (isV(mid, c1, c2, x, y))\n\t\t\t{\n\t\t\t\tans = Math.min(ans, mid);\n\t\t\t\tmax = mid - 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmin = mid + 1;\n\t\t\t}\n\t\t}\n\n\t\tout.println(ans);\n\t\t// end here\n\n\t}\n\n\tprivate boolean isV(long mid, int c1, int c2, int x, int y)\n\t{\n\t\tlong xyl = lcm(x, y);\n\n\t\tlong xq = mid / x;\n\t\tlong yq = mid / y;\n\n\t\tlong xyq = mid / xyl;\n\n\t\tlong cc1 = yq - xyq;\n\t\tlong cc2 = xq - xyq;\n\n\t\tlong rn = mid - xq - yq + xyq;\n\n\t\tif (Math.max((c1 - cc1), 0L) + Math.max((c2 - cc2), 0L) <= rn)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate long lcm(int x, int y)\n\t{\n\t\treturn (x * y) / gcd(x, y);\n\t}\n\n\tprivate long gcd(long a, long b)\n\t{\n\t\tif (b == 0)\n\t\t{\n\t\t\treturn a;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn gcd(b, a % b);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws FileNotFoundException\n\t{\n\t\t(new _483B()).solve();\n\t}\n\n\tclass InputHelper\n\t{\n\t\tStringTokenizer tokenizer = null;\n\t\tprivate BufferedReader bufferedReader;\n\n\t\tpublic InputHelper(InputStream inputStream)\n\t\t{\n\t\t\tInputStreamReader inputStreamReader = new InputStreamReader(\n\t\t\t\t\tinputStream);\n\t\t\tbufferedReader = new BufferedReader(inputStreamReader, 16384);\n\t\t}\n\n\t\tpublic String read()\n\t\t{\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tString line = bufferedReader.readLine();\n\t\t\t\t\tif (line == null)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\ttokenizer = new StringTokenizer(line);\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\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic Integer readInteger()\n\t\t{\n\t\t\treturn Integer.parseInt(read());\n\t\t}\n\n\t\tpublic Long readLong()\n\t\t{\n\t\t\treturn Long.parseLong(read());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "25e6ae8ca7619c291f923f7cc5ad04ae", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.StringTokenizer;\n\n/*\n public class _482A{ }\n */\n\npublic class _483A\n{\n\tpublic void solve() throws FileNotFoundException\n\t{\n\t\tInputStream inputStream = System.in;\n\n\t\tInputHelper inputHelper = new InputHelper(inputStream);\n\n\t\tPrintStream out = System.out;\n\n\t\t// actual solution\n\n\t\tint c1 = inputHelper.readInteger();\n\t\tint c2 = inputHelper.readInteger();\n\n\t\tint x = inputHelper.readInteger();\n\t\tint y = inputHelper.readInteger();\n\n\t\tlong min = 2;\n\t\tlong max = 4000000000L;\n\n\t\tlong ans = max;\n\n\t\twhile (min <= max)\n\t\t{\n\t\t\tlong mid = (min + max) / 2;\n\n\t\t\tif (isV(mid, c1, c2, x, y))\n\t\t\t{\n\t\t\t\tans = Math.min(ans, mid);\n\t\t\t\tmax = mid - 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmin = mid + 1;\n\t\t\t}\n\t\t}\n\n\t\tout.println(ans);\n\t\t// end here\n\n\t}\n\n\tprivate boolean isV(long mid, int c1, int c2, int x, int y)\n\t{\n\t\tlong xyl = lcm(x, y);\n\n\t\tlong xq = mid / x;\n\t\tlong yq = mid / y;\n\n\t\tlong xyq = mid / xyl;\n\n\t\tlong cc1 = yq - xyq;\n\t\tlong cc2 = xq - xyq;\n\n\t\tlong rn = mid - xq - yq + xyq;\n\n\t\tif (Math.max((c1 - cc1), 0L) + Math.max((c2 - cc2), 0L) <= rn)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate long lcm(int x, int y)\n\t{\n\t\treturn (x * y) / gcd(x, y);\n\t}\n\n\tprivate long gcd(long a, long b)\n\t{\n\t\tif (b == 0)\n\t\t{\n\t\t\treturn a;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn gcd(b, a % b);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws FileNotFoundException\n\t{\n\t\t(new _483A()).solve();\n\t}\n\n\tclass InputHelper\n\t{\n\t\tStringTokenizer tokenizer = null;\n\t\tprivate BufferedReader bufferedReader;\n\n\t\tpublic InputHelper(InputStream inputStream)\n\t\t{\n\t\t\tInputStreamReader inputStreamReader = new InputStreamReader(\n\t\t\t\t\tinputStream);\n\t\t\tbufferedReader = new BufferedReader(inputStreamReader, 16384);\n\t\t}\n\n\t\tpublic String read()\n\t\t{\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tString line = bufferedReader.readLine();\n\t\t\t\t\tif (line == null)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\ttokenizer = new StringTokenizer(line);\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\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic Integer readInteger()\n\t\t{\n\t\t\treturn Integer.parseInt(read());\n\t\t}\n\n\t\tpublic Long readLong()\n\t\t{\n\t\t\treturn Long.parseLong(read());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8d4b343ce76641ef0ca870fede9a0c37", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\nimport java.awt.Point;\n\nimport com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithm.WordListener;\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 B {\n\tstatic class Vertex {\n\n\t}\n\n\tstatic class Graph {\n\n\t}\n\n\tpublic static void main(String[] xa) throws IOException {\n\t\tScanner sc = new Scanner(new BufferedInputStream(System.in));\n\n\t\tlong c1 = sc.nextLong();\n\t\tlong c2 = sc.nextLong();\n\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\n\t\tlong left = c1 + c2 - 1;\n\t\tlong right = Long.MAX_VALUE;\n\t\tlong ans = Long.MAX_VALUE;\n\t\twhile (true) {\n\t\t\tlong mid = left + (right - left) / 2;\n\t\t\tboolean worksAtMiddle = worksOut(c1, x, c2, y, mid);\n\t\t\tboolean foundAnswer = worksOut(c1, x, c2, y, mid)\n\t\t\t\t\t&& !worksOut(c1, x, c2, y, mid - 1);\n//\t\t\tSystem.out.println(worksAtMiddle + \" \" + mid);\n//\t\t\tSystem.out.println(\"f: \" + foundAnswer);\n\t\t\tif(foundAnswer) {\n\t\t\t\tSystem.out.println(mid);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (worksAtMiddle) {\n\t\t\t\tans = Math.min(ans, mid);\n\t\t\t\tright = mid - 1;\n\t\t\t} else if (!worksAtMiddle) {\n\t\t\t\tleft = mid + 1;\n\t\t\t}\n//\t\t\tSystem.out.println(left +\" \" + right);\n\t\t}\n\n\t}\n\n\tstatic boolean worksOut(long c1, int x, long c2, int y, long guess) {\n\t\tlong numbersForOne = guess - guess / x;\n\t\tlong numbersForTwo = guess - guess / y;\n\n\t\t// case one\n\t\tlong numbersForOneIfOneAdjusts = numbersForOne - (guess / (x * y));\n\t\tlong numbersForTwoIfTwoAdjusts = numbersForTwo - (guess / (x * y));\n\n\t\treturn (numbersForOneIfOneAdjusts >= c1 && numbersForTwo >= c2)\n\t\t\t\t|| (numbersForOne >= c1 && numbersForTwoIfTwoAdjusts >= c2);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2a238492753ff9ef5757ed52476a56ee", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800} {"lang": "Java 8", "source_code": "\npublic class Main {\n\n public static void main(String[] args) {\n String S=\"\";\n double s=3;\n int X = s/s;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eaacf48072bb5fef99f3d338f728845d", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class ProblemA {\n public static void main(String[] args) {\n Scanner kb = new Scanner(System.in);\n kb.nextLine();\n String[] x = kb.nextLine().split(\" \");\n String[] y = kb.nextLine().split(\" \");\n int[] xs = new int[x.length()];\n int[] ys = new int[y.length()];\n int sumx = 0;\n int sumy = 0;\n for (int i = 0; i < x.length(); i++) {\n xs[i] = Integer.parseInt(x[i]);\n ys[i] = Integer.parseInt(y[i]);\n sumx += xs[i];\n sumy += ys[i];\n }\n if (sumx >= sumy) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "33f8045444877c8cb497f82193b67188", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n/**\n * Created by timur on 28.03.15.\n */\n\npublic class TaskA {\n boolean eof;\n BufferedReader br;\n StringTokenizer st;\n PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n new TaskA().run();\n }\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 \"-1\";\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 double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n\n void run() throws IOException {\n InputStream input = System.in;\n PrintStream output = System.out;\n try {\n File f = new File(\"a.in\");\n if (f.exists() && f.canRead()) {\n input = new FileInputStream(f);\n output = new PrintStream(\"a.out\");\n }\n } catch (Throwable e) {\n }\n br = new BufferedReader(new InputStreamReader(input));\n out = new PrintWriter(output);\n solve();\n br.close();\n out.close();\n }\n\n\n void solve() {\n int n = nextInt();\n int x = nextInt();\n TreeMap map = new TreeMap<>();\n for (int i = 0; i < n; i++)\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8990cd7f96a10a2b6090bf86d4d4de60", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class susbus{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int [] stonesOne = new int[n];\n int [] stonesTwo = new int[n];\n int [] stonesOne = {1,2,3,4,5};\n int [] stonesTwo = {2,1,4,3,5};\n for (int i=0;i=0) {\n\t System.out.println(\"Yes\");\n }\n else {\n\t System.out.println(\"No\");\n\n }\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b845f74378131ae3f7061f8738a82813", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable{\n\tStringTokenizer st;\n\tBufferedReader in;\n\tPrintWriter out;\n\t\n\tpublic final String template = \"template\";\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new A()).start();\n\t}\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\t//in = new BufferedReader(new FileReader(template + \".in\"));\n\t\t\t//out = new PrintWriter(new FileWriter(template + \".out\"));\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} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(9000);\n\t\t} finally {\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tString nextToken() throws IOException {\n\t\twhile(st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tvoid solve() throws NumberFormatException, IOException {\n\t\tint w = 0, b = 0;\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tString s = nextToken();\n\t\t\tfor (int j = 0; j < 8; j++){\n\t\t\t\tif (s.charAt(j) == 'W') w++;\n\t\t\t\telse b++;\n\t\t\t}\n\t\t}\n\t\tif (w == b) out.print(\"YES\"); else out.print(\"NO\");\n\t}\n\t\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "473729ef3cd243d59605a79eab39182c", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A {\n\n\t/**\n\t * @param args\n\t * @throws IOException\n\t */\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tString m = rd.readLine();\n\t\t\tint w = 0;\n\t\t\tfor (int j = 0; j < 8; j++) {\n\t\t\t\tif (m.charAt(j) == 'W')\n\t\t\t\t\tw++;\n\t\t\t}\n\t\t\tif (w != 4) {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"YES\");\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7e5b9001fa8acaa5e79a2cc74c98f91d", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class P259A {\n\n @SuppressWarnings(\"unchecked\")\n public void run() throws Exception {\n boolean ok = true;\n for (int i = 0; i < 8; i++) {\n String s = nextLine();\n int b = 0;\n int w = 0;\n\n for (char c : s.toCharArray()) {\n if (c == 'B') {\n b++;\n } else {\n w++;\n }\n }\n\n ok &= (b == 4 && w == 4);\n }\n\n println((ok) ? \"YES\" : \"NO\");\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 P259A().run();\n br.close();\n pw.close();\n }\n\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { print(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(\"\"); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "439c1f0f7a4f74a68ce7db5a302e10a8", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class A157 {\n\n public static void main(String [] args) throws IOException {\n \n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n String [] board = new String[8];\n \n for(int i=0; i<8; i++) {\n board[i] = br.readLine();\n int w=0;\n int b=0;\n for(int j=0; j<8; j++)\n if(board[i].charAt(j) == 'W')\n w++;\n else\n b++;\n //System.out.println(b);\n if(b!=4 || w!=4){\n System.out.println(\"NO\");\n return;\n }\n }\n System.out.println(\"YES\");\n \n \n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3a32b86361280e4f639d927467dca805", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.BigInteger;\npublic class Main {\n public static void main(String[] args)\n {\n BigInteger x,k,a,b,md,to,on;\n md = BigInteger.valueOf(1000000007);\n to = BigInteger.valueOf(2);\n on = new BigInteger.ONE;\n\tScanner inp = new Scanner(System.in);\n\tx = inp.nextBigInteger();\n\tk = inp.nextBigInteger();\n\tif(x.compareTo(BigInteger.ZERO)==0) System.out.println(0);\n\telse{\n\t a = to.modPow(k.add(on),md);\n a = a.multiply(x);\n b = to.modPow(k,md);\n System.out.println(a.subtract(b).add(on).mod(md));\n\t}\n \n } \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fa57c5fcf7eb69560252ecdef64a9f32", "src_uid": "e0e017e8c8872fc1957242ace739464d", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\nimport java.math.*;\n\npublic class Wardrobe {\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n //int t = Integer.parseInt(in.readLine());\n BigInteger MOD = new BigInteger(\"1000000007\");\n long x,k;\n String[] inp = in.readLine().split(\" \");\n x = Long.parseLong(inp[0]);\n k = Long.parseLong(inp[1]);\n if(k==0){\n BigInteger res = BigInteger.valueOf(x).multiply(BigInteger.TWO);\n \tSystem.out.println(res.mod(MOD));\n \treturn;\n }\n if(x==0){\n \tSystem.out.println(0);\n \treturn;\n }\n BigInteger bi = BigInteger.valueOf(2*x-1);\n BigInteger TWO = BigInteger.valueOf(2);\n TWO = TWO.modPow(BigInteger.valueOf(k),MOD);\n bi = bi.multiply(TWO).add(BigInteger.ONE);\n System.out.println(bi.mod(MOD));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bcab9b64836b8553a4103c70532ce28c", "src_uid": "e0e017e8c8872fc1957242ace739464d", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\n\npublic class C\n{\n\n\n \n \n \n \n\n\n \n \n \n\n\n\n \n\t\n\n\t\n public static void main(String[] args) \n {\n Scanner sc = new Scanner(System.in);\n BigInteger x = sc.nextBigInteger();\n BigInteger k = sc.nextBigInteger();\n BigInteger zero = new BigInteger(\"0\");\n BigInteger one = new BigInteger(\"1\");\n BigInteger two = new BigInteger(\"2\");\n BigInteger b = (k.add(one)).mod(modulo);\n BigInteger a = k.mod(modulo);\n BigInteger modulo = new BigInteger(\"1000000006\");\n BigInteger ans = two.modPow(b,modulo);\n ans = ans.multiply(x);\n ans = ans.subtract(two.modPow(a,modulo));\n ans = ans.add(one);\n ans = ans.mod(modulo);\n if (x.equals(zero))\n {\n System.out.println(0);\n }\n else\n {\n System.out.println(ans);\n }\n }\n}\n \n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ee0e01ff3dd91096bc959d22b7f420e8", "src_uid": "e0e017e8c8872fc1957242ace739464d", "difficulty": 1600} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic long x, y,mod = 1000*1000*1000+7;;\n static long gcd(long a ,long b)\n {\n if(b==0)\n return a;\n return gcd(b ,a%b);\n }\n public static int gcd(int a, int b) {\n while (b > 0) {\n int c = a;\n a = b;\n b = c % b;\n }\n return a;\n }\n static long expo(long x ,long n ,long mod)\n {\n long res=1;\n while(n>0)\n {\n if(n%2==1)\n res=(res*x)%mod;\n x=(x*x)%mod;\n n=n/2;\n }\n return res%mod;\n }\n \n static long fermat(long a ,long m)\n {\n return expo(a,m-2,m)%m;\n }\n \n static void extendedEuclidean(long a ,long m)\n {\n if(m==0)\n {\n x=1;\n y=0;\n }\n else\n {\n extendedEuclidean(m,a%m);\n long temp=x;\n x=y;\n y=temp-(a/m)*y;\n }\n \n }\n \n static long EuclidInverse(long a ,long m)\n {\n extendedEuclidean(a ,m);\n return (x%m+m)%m; \n }\n\n\tpublic static void main(String[] args) {\n\t\n\t\tFastScanner s = new FastScanner();\n\t\tlong x = s.nextLong();\n\t\tlong k = s.nextLong();\n\t\t\n\t\tif(k==0)\n\t\t{\n\t\t\tlong ans = (2*x)%mod;\n\t\t\tSystem.out.println(ans);\n\t\t\treturn;\n\t\t}\n\t\tif(x==0)\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong a = (expo(2,k+1,mod)*x - expo(2,k,mod)+1)%mod\n\t\t\n\t\t\n\t\tSystem.out.println(a);\n\t}\nstatic class FastScanner {\n\t\t\n\t private InputStream mIs;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FastScanner() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FastScanner(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 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\t\t}\t\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "128c945a2a747bbe21558258d5f26b98", "src_uid": "e0e017e8c8872fc1957242ace739464d", "difficulty": 1600} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class Test {\n\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n long f(long n) {\n long ret = n;\n long v = n;\n for (long i = 2; i*i <= v; i++)\n if (v % i == 0) {\n while (v % i == 0) v /= i;\n ret =ret*(i-1)/i;\n }\n if (v > 1) ret = ret*(v-1)/v;\n return ret;\n }\n\n long F(long n, long k) {\n if (n == 1) return 1;\n if (k == 1) return f(n);\n if (k % 2 == 0) return F(n, k-1);\n return f(F(n, k-1));\n }\n\n void start() {\n long n = readLong(), k = readLong();\n writer.println(F(n, k) % 1_000_000_007);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c425968b3155d8e9fa6f53c2cfba1bac", "src_uid": "0591ade5f9a69afcbecd80402493f975", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.AbstractMap;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.NoSuchElementException;\nimport java.util.Set;\nimport java.util.SortedMap;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.function.BiConsumer;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\n\npublic class E_400\n{\n\tpublic static final long[] POWER2 = generatePOWER2();\n\tpublic static final IteratorBuffer ITERATOR_BUFFER_PRIME = new IteratorBuffer(streamPrime(1000000).iterator());\n\tprivate static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static StringTokenizer stringTokenizer = null;\n\tprivate static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tinterface BiFunctionResult\n\t{\n\t\tTypeResult apply(Type0 x0, Type1 x1, TypeResult x2);\n\t}\n\n\tstatic class Array implements Iterable\n\t{\n\t\tprivate Object[] array;\n\n\t\tpublic Array(int size)\n\t\t{\n\t\t\tthis.array = new Object[size];\n\t\t}\n\n\t\tpublic Array(int size, Type element)\n\t\t{\n\t\t\tthis(size);\n\t\t\tArrays.fill(this.array, element);\n\t\t}\n\n\t\tpublic Array(Array array, Type element)\n\t\t{\n\t\t\tthis(array.size() + 1);\n\t\t\tfor (int index = 0; index < array.size(); index++)\n\t\t\t{\n\t\t\t\tset(index, array.get(index));\n\t\t\t}\n\t\t\tset(size() - 1, element);\n\t\t}\n\n\t\tpublic Array(List list)\n\t\t{\n\t\t\tthis(list.size());\n\t\t\tint index = 0;\n\t\t\tfor (Type element : list)\n\t\t\t{\n\t\t\t\tset(index, element);\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic Type get(int index)\n\t\t{\n\t\t\treturn (Type) this.array[index];\n\t\t}\n\n\t\tpublic Array set(int index, Type value)\n\t\t{\n\t\t\tthis.array[index] = value;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.array.length;\n\t\t}\n\n\t\tpublic List toList()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Type element : this)\n\t\t\t{\n\t\t\t\tresult.add(element);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tType result = Array.this.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"[\" + E_400.toString(this, \", \") + \"]\";\n\t\t}\n\t}\n\n\tstatic abstract class Edge, TypeEdge extends Edge>\n\t{\n\t\tpublic final TypeVertex vertex0;\n\t\tpublic final TypeVertex vertex1;\n\t\tpublic final boolean bidirectional;\n\n\t\tpublic Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tthis.vertex0 = vertex0;\n\t\t\tthis.vertex1 = vertex1;\n\t\t\tthis.bidirectional = bidirectional;\n\t\t\tthis.vertex0.edges.add(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.add(getThis());\n\t\t\t}\n\t\t}\n\n\t\tpublic TypeVertex other(Vertex vertex)\n\t\t{\n\t\t\tTypeVertex result;\n\t\t\tif (vertex0 == vertex)\n\t\t\t{\n\t\t\t\tresult = vertex1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = vertex0;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic abstract TypeEdge getThis();\n\n\t\tpublic void remove()\n\t\t{\n\t\t\tthis.vertex0.edges.remove(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.remove(getThis());\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.vertex0 + \"->\" + this.vertex1;\n\t\t}\n\t}\n\n\tpublic static class EdgeDefault>> extends Edge>\n\t{\n\t\tpublic EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Vertex, TypeEdge extends Edge> implements Comparable>\n\t{\n\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiConsumer functionPreVisit,\n\t\t\t\tBiConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tboolean[] isVisited = new boolean[vertices.size()];\n\t\t\tboolean[] isOnStack = new boolean[vertices.size()];\n\t\t\tStack stackVertices = new Stack<>();\n\t\t\tStack stackEdges = new Stack<>();\n\t\t\tTypeVertex vertexStart = vertices.get(indexVertexStart);\n\t\t\tstackVertices.push(vertexStart);\n\t\t\tstackEdges.push(null);\n\t\t\tisOnStack[vertexStart.index] = true;\n\t\t\twhile (!stackVertices.isEmpty())\n\t\t\t{\n\t\t\t\tTypeVertex vertex = stackVertices.peek();\n\t\t\t\tTypeEdge edge = stackEdges.peek();\n\t\t\t\tif (isVisited[vertex.index])\n\t\t\t\t{\n\t\t\t\t\tfunctionPostVisit.accept(vertex, edge);\n\t\t\t\t\tstackVertices.pop();\n\t\t\t\t\tstackEdges.pop();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tfunctionPreVisit.accept(vertex, edge);\n\t\t\t\t\tisVisited[vertex.index] = true;\n\t\t\t\t\tfor (TypeEdge edgeTo : vertex.edges)\n\t\t\t\t\t{\n\t\t\t\t\t\tTypeVertex vertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tConsumer functionPreVisit,\n\t\t\t\tConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tdepthFirstSearch(\n\t\t\t\t\tvertices,\n\t\t\t\t\tindexVertexStart,\n\t\t\t\t\t(vertex, edge) -> functionPreVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionPostVisit.accept(vertex)\n\t\t\t);\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tTypeVertex vertex,\n\t\t\t\tTypeEdge edge,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tArray visited,\n\t\t\t\tFIFO verticesNext,\n\t\t\t\tFIFO edgesNext,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tif (!visited.get(vertex.index))\n\t\t\t{\n\t\t\t\tvisited.set(vertex.index, true);\n\t\t\t\tresult = function.apply(vertex, edge, result);\n\t\t\t\tfor (TypeEdge edgeNext : vertex.edges)\n\t\t\t\t{\n\t\t\t\t\tTypeVertex vertexNext = edgeNext.other(vertex);\n\t\t\t\t\tif (!visited.get(vertexNext.index))\n\t\t\t\t\t{\n\t\t\t\t\t\tverticesNext.push(vertexNext);\n\t\t\t\t\t\tedgesNext.push(edgeNext);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tArray visited = new Array(vertices.size(), false);\n\t\t\tFIFO verticesNext = new FIFO<>();\n\t\t\tverticesNext.push(vertices.get(indexVertexStart));\n\t\t\tFIFO edgesNext = new FIFO<>();\n\t\t\tedgesNext.push(null);\n\t\t\twhile (!verticesNext.isEmpty())\n\t\t\t{\n\t\t\t\tresult = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic final int index;\n\t\tpublic final List edges;\n\n\t\tpublic Vertex(int index)\n\t\t{\n\t\t\tthis.index = index;\n\t\t\tthis.edges = new ArrayList<>();\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Vertex that)\n\t\t{\n\t\t\treturn Integer.compare(this.index, that.index);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"\" + this.index;\n\t\t}\n\t}\n\n\tpublic static class VertexDefault, TypeEdge>> extends Vertex, TypeEdge>\n\t{\n\t\tpublic VertexDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class VertexDefaultDefault extends Vertex\n\t{\n\t\tpublic static Array vertices(int n)\n\t\t{\n\t\t\tArray result = new Array(n);\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult.set(index, new VertexDefaultDefault(index));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic VertexDefaultDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class EdgeDefaultDefault extends Edge\n\t{\n\t\tpublic EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefaultDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Tuple2\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\n\t\tpublic Tuple2(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \")\";\n\t\t}\n\t}\n\n\tstatic class Wrapper\n\t{\n\t\tpublic Type value;\n\n\t\tpublic Wrapper(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\tpublic Type get()\n\t\t{\n\t\t\treturn this.value;\n\t\t}\n\n\t\tpublic void set(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.value.toString();\n\t\t}\n\t}\n\n\tpublic static class Tuple3\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\t\tpublic final Type2 v2;\n\n\t\tpublic Tuple3(Type0 v0, Type1 v1, Type2 v2)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t\tthis.v2 = v2;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \", \" + this.v2 + \")\";\n\t\t}\n\t}\n\n\tpublic static class Tuple2Comparable, Type1 extends Comparable> extends Tuple2 implements Comparable>\n\t{\n\t\tpublic Tuple2Comparable(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tsuper(v0, v1);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Tuple2Comparable that)\n\t\t{\n\t\t\tint result = this.v0.compareTo(that.v0);\n\t\t\tif (result == 0)\n\t\t\t{\n\t\t\t\tresult = this.v1.compareTo(that.v1);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tpublic static class SingleLinkedList\n\t{\n\t\tpublic final Type element;\n\t\tpublic SingleLinkedList next;\n\n\t\tpublic SingleLinkedList(Type element, SingleLinkedList next)\n\t\t{\n\t\t\tthis.element = element;\n\t\t\tthis.next = next;\n\t\t}\n\n\t\tpublic void toCollection(Collection collection)\n\t\t{\n\t\t\tif (this.next != null)\n\t\t\t{\n\t\t\t\tthis.next.toCollection(collection);\n\t\t\t}\n\t\t\tcollection.add(this.element);\n\t\t}\n\t}\n\n\tpublic static class Node\n\t{\n\t\tpublic static Node balance(Node result)\n\t\t{\n\t\t\twhile (result != null && 1 < Math.abs(height(result.left) - height(result.right)))\n\t\t\t{\n\t\t\t\tif (height(result.left) < height(result.right))\n\t\t\t\t{\n\t\t\t\t\tNode right = result.right;\n\t\t\t\t\tif (height(right.right) < height(right.left))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(result.value, result.left, right.rotateRight());\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateLeft();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tNode left = result.left;\n\t\t\t\t\tif (height(left.left) < height(left.right))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(result.value, left.rotateLeft(), result.right);\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateRight();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node clone(Node result)\n\t\t{\n\t\t\tif (result != null)\n\t\t\t{\n\t\t\t\tresult = new Node(result.value, clone(result.left), clone(result.right));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node delete(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tif (node.left == null)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = node.right;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (node.right == null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult = node.left;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tNode first = first(node.right);\n\t\t\t\t\t\t\tresult = new Node(first.value, node.left, delete(node.right, first.value, comparator));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(node.value, delete(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(node.value, node.left, delete(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node first(Node result)\n\t\t{\n\t\t\twhile (result.left != null)\n\t\t\t{\n\t\t\t\tresult = result.left;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node get(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node head(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node.left;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = head(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(node.value, node.left, head(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int height(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.height;\n\t\t}\n\n\t\tpublic static Node insert(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = new Node(value, null, null);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node(value, node.left, node.right);\n\t\t\t\t\t;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(node.value, insert(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(node.value, node.left, insert(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node last(Node result)\n\t\t{\n\t\t\twhile (result.right != null)\n\t\t\t{\n\t\t\t\tresult = result.right;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int size(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.size;\n\t\t}\n\n\t\tpublic static Node tail(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node(node.value, null, node.right);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node(node.value, tail(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = tail(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static void traverseOrderIn(Node node, Consumer consumer)\n\t\t{\n\t\t\tif (node != null)\n\t\t\t{\n\t\t\t\ttraverseOrderIn(node.left, consumer);\n\t\t\t\tconsumer.accept(node.value);\n\t\t\t\ttraverseOrderIn(node.right, consumer);\n\t\t\t}\n\t\t}\n\n\t\tpublic final Type value;\n\t\tpublic final Node left;\n\t\tpublic final Node right;\n\t\tpublic final int size;\n\t\tprivate final int height;\n\n\t\tpublic Node(Type value, Node left, Node right)\n\t\t{\n\t\t\tthis.value = value;\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t\tthis.size = 1 + size(left) + size(right);\n\t\t\tthis.height = 1 + Math.max(height(left), height(right));\n\t\t}\n\n\t\tpublic Node rotateLeft()\n\t\t{\n\t\t\tNode left = new Node(this.value, this.left, this.right.left);\n\t\t\treturn new Node(this.right.value, left, this.right.right);\n\t\t}\n\n\t\tpublic Node rotateRight()\n\t\t{\n\t\t\tNode right = new Node(this.value, this.left.right, this.right);\n\t\t\treturn new Node(this.left.value, this.left.left, right);\n\t\t}\n\t}\n\n\tpublic static class SortedSetAVL implements SortedSet\n\t{\n\t\tpublic Comparator comparator;\n\t\tpublic Node root;\n\n\t\tprivate SortedSetAVL(Comparator comparator, Node root)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.root = root;\n\t\t}\n\n\t\tpublic SortedSetAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t}\n\n\t\tpublic SortedSetAVL(Collection collection, Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t\tthis.addAll(collection);\n\t\t}\n\n\t\tpublic SortedSetAVL(SortedSetAVL sortedSetAVL)\n\t\t{\n\t\t\tthis(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.root = null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\tpublic Type get(Type value)\n\t\t{\n\t\t\tNode node = Node.get(this.root, value, this.comparator);\n\t\t\treturn node == null ? null : node.value;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL subSet(Type valueStart, Type valueEnd)\n\t\t{\n\t\t\treturn tailSet(valueStart).headSet(valueEnd);\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL headSet(Type valueEnd)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL tailSet(Type valueStart)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic Type first()\n\t\t{\n\t\t\treturn Node.first(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic Type last()\n\t\t{\n\t\t\treturn Node.last(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.root == null ? 0 : this.root.size;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.root == null;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean contains(Object value)\n\t\t{\n\t\t\treturn Node.get(this.root, (Type) value, this.comparator) != null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\tStack> path = new Stack<>();\n\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\t{\n\t\t\t\t\tpush(SortedSetAVL.this.root);\n\t\t\t\t}\n\n\t\t\t\tpublic void push(Node node)\n\t\t\t\t{\n\t\t\t\t\twhile (node != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tpath.push(node);\n\t\t\t\t\t\tnode = node.left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn !path.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (path.isEmpty())\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tNode node = path.peek();\n\t\t\t\t\t\tType result = node.value;\n\t\t\t\t\t\tif (node.right != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpush(node.right);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tnode = path.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twhile (!path.isEmpty() && path.peek().right == node);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic Object[] toArray()\n\t\t{\n\t\t\tList list = new ArrayList<>();\n\t\t\tNode.traverseOrderIn(this.root, list::add);\n\t\t\treturn list.toArray();\n\t\t}\n\n\t\t@Override\n\t\tpublic T[] toArray(T[] ts)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean add(Type value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.insert(this.root, value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean remove(Object value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.delete(this.root, (Type) value, this.comparator);\n\t\t\treturn sizeBefore == size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.allMatch(this::contains);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean addAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::add)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean retainAll(Collection collection)\n\t\t{\n\t\t\tSortedSetAVL set = new SortedSetAVL<>(this.comparator);\n\t\t\tcollection.stream()\n\t\t\t\t\t.map(element -> (Type) element)\n\t\t\t\t\t.filter(this::contains)\n\t\t\t\t\t.forEach(set::add);\n\t\t\tboolean result = size() != set.size();\n\t\t\tthis.root = set.root;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean removeAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::remove)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"{\" + E_400.toString(this, \", \") + \"}\";\n\t\t}\n\t}\n\n\tpublic static class SortedMapAVL implements SortedMap\n\t{\n\t\tpublic final Comparator comparator;\n\t\tpublic final SortedSetAVL> entrySet;\n\n\t\tpublic SortedMapAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey())));\n\t\t}\n\n\t\tprivate SortedMapAVL(Comparator comparator, SortedSetAVL> entrySet)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.entrySet = entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(TypeKey keyStart, TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)));\n\t\t}\n\n\t\tpublic Entry firstEntry()\n\t\t{\n\t\t\treturn this.entrySet.first();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey firstKey()\n\t\t{\n\t\t\treturn firstEntry().getKey();\n\t\t}\n\n\t\tpublic Entry lastEntry()\n\t\t{\n\t\t\treturn this.entrySet.last();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey lastKey()\n\t\t{\n\t\t\treturn lastEntry().getKey();\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.entrySet().size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.entrySet.isEmpty();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsKey(Object key)\n\t\t{\n\t\t\treturn this.entrySet().contains(key);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsValue(Object value)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue get(Object key)\n\t\t{\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tentry = this.entrySet.get(entry);\n\t\t\treturn entry == null ? null : entry.getValue();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue put(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>(key, value);\n\t\t\tthis.entrySet().add(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue remove(Object key)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tthis.entrySet.remove(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tmap.entrySet().stream()\n\t\t\t\t\t.forEach(entry -> put(entry.getKey(), entry.getValue()));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.entrySet.clear();\n\t\t}\n\n\t\t@Override\n\t\tpublic Set keySet()\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Collection values()\n\t\t{\n\t\t\treturn new Collection()\n\t\t\t{\n\t\t\t\t@Override\n\t\t\t\tpublic int size()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean isEmpty()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean contains(Object value)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Iterator iterator()\n\t\t\t\t{\n\t\t\t\t\treturn new Iterator()\n\t\t\t\t\t{\n\t\t\t\t\t\tIterator> iterator = SortedMapAVL.this.entrySet.iterator();\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic boolean hasNext()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.hasNext();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic TypeValue next()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.next().getValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Object[] toArray()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic T[] toArray(T[] ts)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean add(TypeValue typeValue)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean remove(Object o)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean containsAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean addAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean removeAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean retainAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic void clear()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL> entrySet()\n\t\t{\n\t\t\treturn this.entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.entrySet().toString();\n\t\t}\n\t}\n\n\tpublic static class FIFO\n\t{\n\t\tpublic SingleLinkedList start;\n\t\tpublic SingleLinkedList end;\n\n\t\tpublic FIFO()\n\t\t{\n\t\t\tthis.start = null;\n\t\t\tthis.end = null;\n\t\t}\n\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.start == null;\n\t\t}\n\n\t\tpublic Type peek()\n\t\t{\n\t\t\treturn this.start.element;\n\t\t}\n\n\t\tpublic Type pop()\n\t\t{\n\t\t\tType result = this.start.element;\n\t\t\tthis.start = this.start.next;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic void push(Type element)\n\t\t{\n\t\t\tSingleLinkedList list = new SingleLinkedList<>(element, null);\n\t\t\tif (this.start == null)\n\t\t\t{\n\t\t\t\tthis.start = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthis.end.next = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class MapCount extends SortedMapAVL\n\t{\n\t\tprivate int count;\n\n\t\tpublic MapCount(Comparator comparator)\n\t\t{\n\t\t\tsuper(comparator);\n\t\t\tthis.count = 0;\n\t\t}\n\n\t\tpublic long add(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key);\n\t\t\t\tif (value == null)\n\t\t\t\t{\n\t\t\t\t\tvalue = delta;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvalue += delta;\n\t\t\t\t}\n\t\t\t\tput(key, value);\n\t\t\t\tresult = delta;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count += result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int count()\n\t\t{\n\t\t\treturn this.count;\n\t\t}\n\n\t\tpublic List flatten()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Entry entry : entrySet())\n\t\t\t{\n\t\t\t\tfor (long index = 0; index < entry.getValue(); index++)\n\t\t\t\t{\n\t\t\t\t\tresult.add(entry.getKey());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Long remove(Object key)\n\t\t{\n\t\t\tLong result = super.remove(key);\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic long remove(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key) - delta;\n\t\t\t\tif (value <= 0)\n\t\t\t\t{\n\t\t\t\t\tresult = delta + value;\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult = delta;\n\t\t\t\t\tput(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(Type keyStart, Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(Type keyStart)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\t}\n\n\tpublic static class MapSet extends SortedMapAVL> implements Iterable\n\t{\n\t\tprivate Comparator comparatorValue;\n\n\t\tpublic MapSet(Comparator comparatorKey, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic MapSet(Comparator comparatorKey, SortedSetAVL>> entrySet, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey, entrySet);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic TypeValue firstValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> firstEntry = firstEntry();\n\t\t\tif (firstEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = firstEntry.getValue().first();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tIterator> iteratorValues = values().iterator();\n\t\t\t\tIterator iteratorValue = null;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext());\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic TypeValue next()\n\t\t\t\t{\n\t\t\t\t\tif (iteratorValue == null || !iteratorValue.hasNext())\n\t\t\t\t\t{\n\t\t\t\t\t\titeratorValue = iteratorValues.next().iterator();\n\t\t\t\t\t}\n\t\t\t\t\treturn iteratorValue.next();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tpublic TypeValue lastValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> lastEntry = lastEntry();\n\t\t\tif (lastEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = lastEntry.getValue().last();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic boolean add(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tSortedSetAVL set = get(key);\n\t\t\tif (set == null)\n\t\t\t{\n\t\t\t\tset = new SortedSetAVL<>(comparatorValue);\n\t\t\t\tput(key, set);\n\t\t\t}\n\t\t\treturn set.add(value);\n\t\t}\n\n\t\tpublic boolean removeSet(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tboolean result;\n\t\t\tSortedSetAVL set = get(key);\n\t\t\tif (set == null)\n\t\t\t{\n\t\t\t\tresult = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = set.remove(value);\n\t\t\t\tif (set.size() == 0)\n\t\t\t\t{\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new MapSet(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue);\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new MapSet(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue);\n\t\t}\n\t}\n\n\tstatic class IteratorBuffer\n\t{\n\t\tprivate Iterator iterator;\n\t\tprivate List list;\n\n\t\tpublic IteratorBuffer(Iterator iterator)\n\t\t{\n\t\t\tthis.iterator = iterator;\n\t\t\tthis.list = new ArrayList();\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < list.size() || iterator().hasNext();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (list.size() <= this.index)\n\t\t\t\t\t{\n\t\t\t\t\t\tlist.add(iterator.next());\n\t\t\t\t\t}\n\t\t\t\t\tType result = list.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t}\n\n\tpublic static List> permutations(List list)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tresult.add(new ArrayList<>());\n\t\tfor (Type element : list)\n\t\t{\n\t\t\tList> permutations = result;\n\t\t\tresult = new ArrayList<>();\n\t\t\tfor (List permutation : permutations)\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= permutation.size(); index++)\n\t\t\t\t{\n\t\t\t\t\tList permutationNew = new ArrayList<>(permutation);\n\t\t\t\t\tpermutationNew.add(index, element);\n\t\t\t\t\tresult.add(permutationNew);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static List> combinations(int n, int k)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tif (k == 0)\n\t\t{\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (k == 1)\n\t\t\t{\n\t\t\t\tList combination = new ArrayList<>();\n\t\t\t\tcombination.add(n);\n\t\t\t\tresult.add(combination);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= n; index++)\n\t\t\t\t{\n\t\t\t\t\tfor (List combination : combinations(n - index, k - 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tcombination.add(index);\n\t\t\t\t\t\tresult.add(combination);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterator iterator0, Iterator iterator1, Comparator comparator)\n\t{\n\t\tint result = 0;\n\t\twhile (result == 0 && iterator0.hasNext() && iterator1.hasNext())\n\t\t{\n\t\t\tresult = comparator.compare(iterator0.next(), iterator1.next());\n\t\t}\n\t\tif (result == 0)\n\t\t{\n\t\t\tif (iterator1.hasNext())\n\t\t\t{\n\t\t\t\tresult = -1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (iterator0.hasNext())\n\t\t\t\t{\n\t\t\t\t\tresult = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterable iterable0, Iterable iterable1, Comparator comparator)\n\t{\n\t\treturn compare(iterable0.iterator(), iterable1.iterator(), comparator);\n\t}\n\n\tprivate static String nextString() throws IOException\n\t{\n\t\twhile ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens()))\n\t\t{\n\t\t\tstringTokenizer = new StringTokenizer(bufferedReader.readLine());\n\t\t}\n\t\treturn stringTokenizer.nextToken();\n\t}\n\n\tprivate static String[] nextStrings(int n) throws IOException\n\t{\n\t\tString[] result = new String[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextString();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\n\tpublic static int[] nextInts(int n) throws IOException\n\t{\n\t\tint[] result = new int[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextInt();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n\n\tpublic static long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\n\tpublic static long[] nextLongs(int n) throws IOException\n\t{\n\t\tlong[] result = new long[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextLong();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String nextLine() throws IOException\n\t{\n\t\treturn bufferedReader.readLine();\n\t}\n\n\tpublic static void close()\n\t{\n\t\tout.close();\n\t}\n\n\tpublic static int binarySearchMinimum(Function filter, int start, int end)\n\t{\n\t\tint result;\n\t\tif (start == end)\n\t\t{\n\t\t\tresult = end;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint middle = start + (end - start) / 2;\n\t\t\tif (filter.apply(middle))\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, start, middle);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, middle + 1, end);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int binarySearchMaximum(Function filter, int start, int end)\n\t{\n\t\treturn -binarySearchMinimum(x -> filter.apply(-x), -end, -start);\n\t}\n\n\tpublic static long divideCeil(long x, long y)\n\t{\n\t\treturn (x + y - 1) / y;\n\t}\n\n\tpublic static Set divisors(long n)\n\t{\n\t\tSortedSetAVL result = new SortedSetAVL<>(Comparator.naturalOrder());\n\t\tresult.add(1L);\n\t\tfor (Long factor : factors(n))\n\t\t{\n\t\t\tSortedSetAVL divisors = new SortedSetAVL<>(result);\n\t\t\tfor (Long divisor : result)\n\t\t\t{\n\t\t\t\tdivisors.add(divisor * factor);\n\t\t\t}\n\t\t\tresult = divisors;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long faculty(int n)\n\t{\n\t\tlong result = 1;\n\t\tfor (int index = 2; index <= n; index++)\n\t\t{\n\t\t\tresult *= index;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static LinkedList factors(long value)\n\t{\n\t\tLinkedList result = new LinkedList<>();\n\t\tIterator primes = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile (value > 1 && (prime = primes.next()) * prime <= value)\n\t\t{\n\t\t\twhile (value % prime == 0)\n\t\t\t{\n\t\t\t\tresult.add(prime);\n\t\t\t\tvalue /= prime;\n\t\t\t}\n\t\t}\n\t\tif (value > 1)\n\t\t{\n\t\t\tresult.add(value);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long gcd(long a, long b)\n\t{\n\t\twhile (a != 0 && b != 0)\n\t\t{\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tb %= a;\n\t\t\t}\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tpublic static long[] generatePOWER2()\n\t{\n\t\tlong[] result = new long[63];\n\t\tfor (int x = 0; x < result.length; x++)\n\t\t{\n\t\t\tresult[x] = 1L << x;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean isPrime(long x)\n\t{\n\t\tboolean result = x > 1;\n\t\tIterator iterator = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile ((prime = iterator.next()) * prime <= x)\n\t\t{\n\t\t\tresult &= x % prime > 0;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long knapsack(List> itemsValueWeightCount, int weightMaximum)\n\t{\n\t\tlong[] valuesMaximum = new long[weightMaximum + 1];\n\t\tfor (Tuple3 itemValueWeightCount : itemsValueWeightCount)\n\t\t{\n\t\t\tlong itemValue = itemValueWeightCount.v0;\n\t\t\tint itemWeight = itemValueWeightCount.v1;\n\t\t\tint itemCount = itemValueWeightCount.v2;\n\t\t\tfor (int weight = weightMaximum; 0 <= weight; weight--)\n\t\t\t{\n\t\t\t\tfor (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++)\n\t\t\t\t{\n\t\t\t\t\tvaluesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong result = 0;\n\t\tfor (long valueMaximum : valuesMaximum)\n\t\t{\n\t\t\tresult = Math.max(result, valueMaximum);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean knapsackPossible(List> itemsWeightCount, int weightMaximum)\n\t{\n\t\tboolean[] weightPossible = new boolean[weightMaximum + 1];\n\t\tweightPossible[0] = true;\n\t\tint weightLargest = 0;\n\t\tfor (Tuple2 itemWeightCount : itemsWeightCount)\n\t\t{\n\t\t\tint itemWeight = itemWeightCount.v0;\n\t\t\tint itemCount = itemWeightCount.v1;\n\t\t\tfor (int weightStart = 0; weightStart < itemWeight; weightStart++)\n\t\t\t{\n\t\t\t\tint count = 0;\n\t\t\t\tfor (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight)\n\t\t\t\t{\n\t\t\t\t\tif (weightPossible[weight])\n\t\t\t\t\t{\n\t\t\t\t\t\tcount = itemCount;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (0 < count)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tweightPossible[weight] = true;\n\t\t\t\t\t\t\tweightLargest = weight;\n\t\t\t\t\t\t\tcount -= 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn weightPossible[weightMaximum];\n\t}\n\n\tpublic static long lcm(int a, int b)\n\t{\n\t\treturn a * b / gcd(a, b);\n\t}\n\n\tpublic static List permutation(long p, List x)\n\t{\n\t\tList copy = new ArrayList<>();\n\t\tfor (int index = 0; index < x.size(); index++)\n\t\t{\n\t\t\tcopy.add(x.get(index));\n\t\t}\n\t\tList result = new ArrayList<>();\n\t\tfor (int indexTo = 0; indexTo < x.size(); indexTo++)\n\t\t{\n\t\t\tint indexFrom = (int) p % copy.size();\n\t\t\tp = p / copy.size();\n\t\t\tresult.add(copy.remove(indexFrom));\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String toString(Iterator iterator, String separator)\n\t{\n\t\tStringBuffer stringBuffer = new StringBuffer();\n\t\tif (iterator.hasNext())\n\t\t{\n\t\t\tstringBuffer.append(iterator.next());\n\t\t}\n\t\twhile (iterator.hasNext())\n\t\t{\n\t\t\tstringBuffer.append(separator);\n\t\t\tstringBuffer.append(iterator.next());\n\t\t}\n\t\treturn stringBuffer.toString();\n\t}\n\n\tpublic static String toString(Iterator iterator)\n\t{\n\t\treturn toString(iterator, \" \");\n\t}\n\n\tpublic static String toString(Iterable iterable, String separator)\n\t{\n\t\treturn toString(iterable.iterator(), separator);\n\t}\n\n\tpublic static String toString(Iterable iterable)\n\t{\n\t\treturn toString(iterable, \" \");\n\t}\n\n\tpublic static Stream streamFibonacci()\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate BigInteger n0 = BigInteger.ZERO;\n\t\t\tprivate BigInteger n1 = BigInteger.ONE;\n\n\t\t\t@Override\n\t\t\tpublic BigInteger get()\n\t\t\t{\n\t\t\t\tBigInteger result = n0;\n\t\t\t\tn0 = n1;\n\t\t\t\tn1 = result.add(n0);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static Stream streamPrime(int sieveSize)\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate boolean[] isPrime = new boolean[sieveSize];\n\t\t\tprivate long sieveOffset = 2;\n\t\t\tprivate List primes = new ArrayList<>();\n\t\t\tprivate int index = 0;\n\n\t\t\tpublic void filter(long prime, boolean[] result)\n\t\t\t{\n\t\t\t\tif (prime * prime < this.sieveOffset + sieveSize)\n\t\t\t\t{\n\t\t\t\t\tlong remainingStart = this.sieveOffset % prime;\n\t\t\t\t\tlong start = remainingStart == 0 ? 0 : prime - remainingStart;\n\t\t\t\t\tfor (long index = start; index < sieveSize; index += prime)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult[(int) index] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void generatePrimes()\n\t\t\t{\n\t\t\t\tArrays.fill(this.isPrime, true);\n\t\t\t\tthis.primes.forEach(prime -> filter(prime, isPrime));\n\t\t\t\tfor (int index = 0; index < sieveSize; index++)\n\t\t\t\t{\n\t\t\t\t\tif (isPrime[index])\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.primes.add(this.sieveOffset + index);\n\t\t\t\t\t\tfilter(this.sieveOffset + index, isPrime);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.sieveOffset += sieveSize;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic Long get()\n\t\t\t{\n\t\t\t\twhile (this.primes.size() <= this.index)\n\t\t\t\t{\n\t\t\t\t\tgeneratePrimes();\n\t\t\t\t}\n\t\t\t\tLong result = this.primes.get(this.index);\n\t\t\t\tthis.index += 1;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static long totient(long n)\n\t{\n\t\tSet factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder());\n\t\tlong result = n;\n\t\tfor (long p : factors)\n\t\t{\n\t\t\tresult -= result / p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tsolve();\n\t\t} catch (IOException exception)\n\t\t{\n\t\t\texception.printStackTrace();\n\t\t}\n\t\tclose();\n\t}\n\n\tpublic static long g(long n)\n\t{\n\t\tlong result = 0;\n\t\tfor (Long divisor : divisors(n))\n\t\t{\n\t\t\tresult += totient(n / divisor);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long F(long k, long n)\n\t{\n\t\tlong result;\n\t\tif (n == 1)\n\t\t{\n\t\t\tresult = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (k == 1)\n\t\t\t{\n\t\t\t\tresult = totient(g(n));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong F = F(k - 1, n);\n\t\t\t\tif (k % 2 == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = g(F);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult = totient(F);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void solve() throws IOException\n\t{\n\t\tlong n = nextLong();\n\t\tlong k = nextLong();\n\t\tout.println(F(k, n) % 1000000007);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "781958b5753e9f119e9cb0cc99b8c315", "src_uid": "0591ade5f9a69afcbecd80402493f975", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n class A {\n long p;\n int e;\n\n A(long pp, int ee) {\n p = pp;\n e = ee;\n }\n }\n\n final long M = 1000000007;\n\n long n, k;\n Scanner sca = new Scanner(System.in);\n\n void start() {\n n = sca.nextLong(); k = sca.nextLong();\n\n solve();\n }\n\n void solve() {\n\n System.out.println(F(n, k));\n }\n\n List fact(long n) {\n List fs = new ArrayList<>();\n for (long i = 2; i*i <= n; i++) {\n if (n % i != 0) continue;\n int c = 0;\n do {\n n /= i;\n c++;\n } while (n % i == 0);\n fs.add(new A(i, c));\n }\n if (fs.size() > 0 && n > 1) fs.add(new A(n, 1));\n return fs;\n }\n\n long f(long n) {\n if (n == 1) return 1;\n List as = fact(n);\n if (as.size() == 0) return n - 1;\n long[] s = new long[1];\n ff(n, 1, as, 0, 0, s);\n return n - 1 + s[0];\n }\n\n void ff(long n, long d, List as, int i, int c, long[] s) {\n if (i == as.size()) {\n if (c > 0) {\n long q = (n - 1) / d;\n if (c % 2 == 1) q = -q;\n s[0] += q;\n }\n return;\n }\n ff(n, d, as, i + 1, c, s);\n ff(n, d*as.get(i).p, as, i + 1, c + 1, s);\n }\n\n long g(long n) {\n List as = fact(n);\n if (as.size() == 0) return n;\n List bs = new ArrayList<>();\n\n long[] s = new long[1];\n sf(1, as, 0, bs, s);\n return s[0] % M;\n }\n\n void sf(long n, List as, int i, List bs, long[] s) {\n if (i == as.size()) {\n if (bs.size() == 0) {\n s[0] += 1;\n } else {\n ff(n, 1, bs, 0, 0, s);\n s[0] += n - 1;\n }\n return;\n }\n\n sf(n, as, i + 1, bs, s);\n\n A a = as.get(i);\n bs.add(as.get(i));\n\n for (int j = 1; j <= a.e; j++) {\n n *= a.p;\n sf(n, as, i + 1, bs, s);\n }\n\n bs.remove(bs.size() - 1);\n }\n\n long F(long n, long k) {\n if (k == 1) return f(g(n));\n if (k % 2 == 0) return g(F(n, k - 1));\n else return f(F(n, k - 1));\n }\n\n public static void main(String[] args) {\n\n new Test().start();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c18f82a860bc77923539a212ac4a2659", "src_uid": "0591ade5f9a69afcbecd80402493f975", "difficulty": 2100} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n class A {\n long p;\n int e;\n\n A(long pp, int ee) {\n p = pp;\n e = ee;\n }\n }\n\n final long M = 1000000007;\n\n long n, k;\n Scanner sca = new Scanner(System.in);\n\n void start() {\n n = sca.nextInt(); k = sca.nextInt();\n\n solve();\n }\n\n void solve() {\n\n System.out.println(F(n, k));\n }\n\n List fact(long n) {\n List fs = new ArrayList<>();\n for (long i = 2; i*i <= n; i++) {\n if (n % i != 0) continue;\n int c = 0;\n do {\n n /= i;\n c++;\n } while (n % i == 0);\n fs.add(new A(i, c));\n }\n if (fs.size() > 0 && n > 1) fs.add(new A(n, 1));\n return fs;\n }\n\n long f(long n) {\n if (n == 1) return 1;\n List as = fact(n);\n if (as.size() == 0) return n - 1;\n long[] s = new long[1];\n ff(n, 1, as, 0, 0, s);\n return n - 1 + s[0];\n }\n\n void ff(long n, long d, List as, int i, int c, long[] s) {\n if (i == as.size()) {\n if (c > 0) {\n long q = (n - 1) / d;\n if (c % 2 == 1) q = -q;\n s[0] += q;\n }\n return;\n }\n ff(n, d, as, i + 1, c, s);\n ff(n, d*as.get(i).p, as, i + 1, c + 1, s);\n }\n\n long g(long n) {\n List as = fact(n);\n if (as.size() == 0) return n;\n List bs = new ArrayList<>();\n\n long[] s = new long[1];\n sf(1, as, 0, bs, s);\n return s[0] % M;\n }\n\n void sf(long n, List as, int i, List bs, long[] s) {\n if (i == as.size()) {\n if (bs.size() == 0) {\n s[0] += 1;\n } else {\n ff(n, 1, bs, 0, 0, s);\n s[0] += n - 1;\n }\n return;\n }\n\n sf(n, as, i + 1, bs, s);\n\n A a = as.get(i);\n bs.add(as.get(i));\n\n for (int j = 1; j <= a.e; j++) {\n n *= a.p;\n sf(n, as, i + 1, bs, s);\n }\n\n bs.remove(bs.size() - 1);\n }\n\n long F(long n, long k) {\n if (k == 1) return f(g(n));\n if (k % 2 == 0) return g(F(n, k - 1));\n else return f(F(n, k - 1));\n }\n\n public static void main(String[] args) {\n\n new Test().start();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fef6b7cf777918019503d25c0c78a64e", "src_uid": "0591ade5f9a69afcbecd80402493f975", "difficulty": 2100} {"lang": "Java 8", "source_code": "public class TimeRace {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int h = in.nextInt() * 5, m = in.nextInt(), count = 0,\n s = in.nextInt() ,t1 = in.nextInt() * 5, t2 = in.nextInt() * 5;\n h = h + m / 12;\n int[] sector1 = {Math.min(h,s), Math.max(h, s)},\n sector2 = {Math.min(m,s), Math.max(m, s)},\n sector3 = {Math.min(h,m), Math.max(h, m)};\n if(res(t1, sector1) && res(t2, sector1) || res(t1, sector2) && res(t2, sector2)\n || res(t1, sector3) && res(t2, sector3)) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n }\n\n static boolean res(int t, int[] sec){\n if(sec[0] > sec[1]) {\n sec[1] += 60;\n t += 60;\n }\n if(t >= sec[0] && t <= sec[1]) return true;\n else return false;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "97c70baccfd7c5c168eb208a38f5a606", "src_uid": "912c8f557a976bdedda728ba9f916c95", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic final class Main {\n\t\n\tstatic int arr[],tmp[];\n\tstatic int inf = (int)4e9;\n \tpublic static void main(String[]args) throws IOException {\n\t\t\n\t\tInputReader ir = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\tint t,n,m,i,j,k,x,y;\n\t\tint h,s,t1,t2;\n\t\tSet set = new TreeSet();\n\t\tarr = new int[6];\n\t\th = ir.nextInt();\n\t\tm = ir.nextInt();\n\t\ts = ir.nextInt();\n\t\tif(m == 0)\n\t\t\tm = 60;\n\t\tif(s == 0)\n\t\t\ts = 60;\n\t\tif(h == 0)\n\t\t\th = 12;\n\t\tt1 = ir.nextInt();\n\t\tt2 =ir.nextInt();\n\t\th = h*100;\n\t\tt1 = t1*100;\n\t\tt2 = t2*100;\n\t\tm = (int)(((double)m/5.0)*100);\n\t\ts = (int)(((double)s/5.0)*100);\n\t\t//w.println(m);\n\t\t//w.println(s);\n\t\tset.add(h);\n\t\tset.add(m);\n\t\tset.add(s);\n\t\tx=0;;\n\t\tfor(int ii : set){\n\t\t\tarr[++x] = ii;\n\t\t\t//w.println(arr[x]);\n\t\t}\n\t\tarr[++x] = arr[1];\n\t\t//w.println(arr[x]);\n\t\t\n\t\tboolean flag = false;\n\t\t//w.println(\"\" + t1 + \" \" + t2);\n\t\tfor(i=1 ;i=arr[i] && t1 <=1200 && t2>=arr[i] && t2 <=1200){\n\t\t\t\t\tflag = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(t1>=arr[i] && t1 <=1200 && t2<=arr[i+1]){\n\t\t\t\t\tflag = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\tif(arr[i]<=t1 && t1 <=arr[i+1] && arr[i]<=t2 && t2 <=arr[i+1]){\n\t\t\t\tflag = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\n\t\tif(x == 2){\n\t\t\tflag = true;\n\t\t}\n\t\tif(flag){\n\t\t\tw.println(\"YES\");\n\t\t}\n\t\telse\n\t\t\tw.println(\"NO\");\n\t\t\n\t\t\n\t\tw.close();\n\t}\n\t\n \t\n \t\n\tstatic class InputReader {\n\t\t \n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int snext() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public 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 = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public String nextLine() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc08c1925cfab0c3ae5f2507b0439a02", "src_uid": "912c8f557a976bdedda728ba9f916c95", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class RaceAgainstTime \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner kb = new Scanner(System.in);\n\t\tint hour = kb.nextInt();\n\t\tint minute = kb.nextInt();\n\t\tint second = kb.nextInt();\n\t\tint t1 = kb.nextInt();\n\t\tint t2 = kb.nextInt();\n\t\t\n\n\t\tif(t1 > t2)\n\t\t{\n\t\t\tint temp = t2;\n\t\t\tt2 = t1;\n\t\t\tt1 = temp;\n\t\t}\n\t\t\n\t\tint count = 0;\n\t\t\n\t\tif(t2 > hour && t1 <= hour)\n\t\t\tcount++;\n\t\t\n\t\tif(t2 * 5 > minute && t1 * 5<= minute)\n\t\t\tcount++;\n\t\tif(t2 * 5 > second && t1*5 <=second)\n\t\t\tcount++;\n\t\tif(count == 0 || count == 3)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t\t3\n\t}\n\t\n\t\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cea040f9b2bceabbd0a8ff8585d2181e", "src_uid": "912c8f557a976bdedda728ba9f916c95", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "public class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner entrada;\n entrada = new Scanner(System.in);\n int h, m, s, t1, t2, i;\n h = entrada.nextInt();\n m = entrada.nextInt();\n s = entrada.nextInt();\n t1 = entrada.nextInt();\n t2 = entrada.nextInt();\n if(h < 1 || h > 12 || m < 0 || m > 59 || s < 0 || s > 59 || t1 < 0 || t1 > 12 || t2 < 0 || t2 > 12 || t1 == t2){\n System.out.println(\"NO\");\n } else {\n if(t2 > t1 && h > t1 && s > t1 && m > t1){\n System.out.println(\"NO\");\n } else {\n System.out.println(\"YES\");\n }\n }\n }\n}\n// 1507383302269\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "788f8bc8db55d344760e0d434a7d65c2", "src_uid": "912c8f557a976bdedda728ba9f916c95", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class GeraldsHexagon\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint[] arr = new int[6];\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tarr[i] = sc.nextInt();\n\t\t\n\t\t\n\t\tSystem.out.println((a[0] + a[1] + a[2])*(a[0] + a[1] + a[2]) - (a[0]*a[0] + a[2]*a[2] + a[4]*a[4]));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c5d69d040b55d83b7fe97a0412f38f04", "src_uid": "382475475427f0e76c6b4ac6e7a02e21", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class p3 {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long a1 = sc.nextDouble();\n long a2 = sc.nextDouble();\n long a3 = sc.nextDouble();\n long a4 = sc.nextDouble();\n long a5 = sc.nextDouble();\n long a6 = sc.nextDouble();\n long n = (a1 + a2 + a3) * (a1 + a2 + a3) - a1 * a1 - a3 * a3 - a5 * a5;\n System.out.println(n);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc05cf77a6e106847ca3ec493db24389", "src_uid": "382475475427f0e76c6b4ac6e7a02e21", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n \npublic class Main{\n \nstatic PrintWriter out;\nstatic InputReader ir;\nstatic final int INF=Integer.MAX_VALUE;\nstatic final long LINF=Long.MAX_VALUE;\n \nstatic void solve(){\n long[] a=ir.nextLongArray(6);\n long ans=Math.pow(a[0]+a[1]+a[2],2);\n ans-=(a[0]*a[0]+a[2]*a[2]+a[4]*a[4]);\n out.println(ans);\n}\n\npublic static void main(String[] args) throws Exception{\n ir=new InputReader(System.in);\n out=new PrintWriter(System.out);\n solve();\n out.flush();\n}\n\nstatic class InputReader {\n private InputStream in;\n private byte[] buffer=new byte[1024];\n private int curbuf;\n private int lenbuf;\n\n public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}\n \n public boolean hasNextByte() {\n if(curbuf>=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i map = new HashMap<>();\n\n public static void main (String[] args) throws Exception {\n map.put('f', 1);\n map.put('e', 2);\n map.put('d', 3);\n map.put('a', 4);\n map.put('b', 5);\n map.put('c', 6);\n\n\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n String seat = reader.readLine();\n int row = Integer.parseInt(seat.substring(0, seat.length()-1));\n char column = seat.charAt(seat.length()-1);\n int offset = 0;\n if(row%4 == 2 || row%4 == 0) {\n offset = 7;\n }\n System.out.println(((row - 1)/4) * 16 + offset + map.get(column));\n }\n\n}```\nMessage Input\n\n\nJot something down", "lang_cluster": "Java", "compilation_error": true, "code_uid": "56bc1856c6e0e452149175a1dc6d4ac7", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class m {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n String input = sc.nextLine();\n String seat = input.substring(input.length() - 1, input.length());\n long rowNum = Long.parseLong(input.substring(0, input.length() - 1));\n long newRowNum = rowNum;\n long totalSecsBeforeServe = 0;\n if (rowNum % 2 == 0) {\n newRowNum -= 1;\n }\n if (newRowNum == 1 || newRowNum == 3) {\n totalSecsBeforeServe = 0;\n } else if ((newRowNum - 1) % 4 == 0) {\n totalSecsBeforeServe = (((newRowNum - 1) / 4) * (1 + 6 + 3 + 6));\n } else if ((newRowNum - 3) % 4 == 0) {\n totalSecsBeforeServe = (((newRowNum - 3) / 4) * (1 + 6 + 3 + 6));\n }\n if (rowNum != newRowNum) {\n totalSecsBeforeServe += 7;\n }\n if (seat.equals(\"c\")) {\n totalSecsBeforeServe += 6;\n } else if (seat.equals(\"b\")) {\n totalSecsBeforeServe += 5;\n } else if (seat.equals(\"a\")) {\n totalSecsBeforeServe += 4;\n } else if (seat.equals(\"d\")) {\n totalSecsBeforeServe += 3;\n } else if (seat.equals(\"e\")) {\n totalSecsBeforeServe += 2;\n } else if (seat.equals(\"f\")) {\n totalSecsBeforeServe += 1;\n }\n System.out.print(totalSecsBeforeServe);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3da8b6ae0502c623ce95f65c944aefb6", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class food{\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n String a;\n a=sc.nextLine();\n long int i,n=0,t=0,s=0,m;\n m=a.length();\n char c=a.charAt(m-1);\n for(i=0;i2){\n n=n-2;\n }\n t=t+(n-1)*7;\n if(c=='c'){\n t=t+6;\n }\n else if(c=='b'){\n t=t+5;\n }\n else if(c=='a'){\n t=t+4;\n }\n else if(c=='d'){\n t=t+3;\n }\n else if(c=='e'){\n t=t+2;\n }\n else if(c=='f'){\n t=t+1;\n }\n System.out.println(t);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "863d1d50b029d124915da523ec3d6856", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0} {"lang": "Java 8", "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{\n\t\t// your code goes here\n\t\t\n\t\tScanner in = new Scanner (System.in);\n\t //int t=in.nextInt();\n\t //for(int i=0;i 2* 10^8 // log 10 base 2 = 3.3219 \n\n// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3// even:: (x^2/4)+1 ,(x^2/4)-1 x >=4 \n\n// FOR ANY ODD NO N : N,N-1,N-2\n//ALL ARE PAIRWISE COPRIME \n//THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS\n\n// two consecutive odds are always coprime to each other\n// two consecutive even have always gcd = 2 ;\n\npublic class Main\n{\n // static int[] arr = new int[100002] ; // static int[] dp = new int[100002] ; \n \n static PrintWriter out;\n \n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\n\n////////////////////////////////////////////////////////////////////////////////////\n public static int countDigit(long n) \n { \n return (int)Math.floor(Math.log10(n) + 1); \n } \n\n///////////////////////////////////////////////////////////////////////////////////////// \n \n public static int sumOfDigits(long n)\n {\n \n if( n< 0)return -1 ;\n \n int sum = 0;\n \n while( n > 0)\n {\n sum = sum + (int)( n %10) ;\n \n n /= 10 ;\n }\n \n return sum ; \n \n \n \n }\n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long arraySum(int[] arr , int start , int end)\n{\n long ans = 0 ;\n \n for(int i = start ; i <= end ; i++)ans += arr[i] ;\n \n return ans ;\n}\n\n/////////////////////////////////////////////////////////////////////////////////\n\npublic static int mod(int x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\npublic static long mod(long x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n\npublic static void swapArray(int[] arr , int start , int end)\n{\n while(start < end)\n {\n int temp = arr[start] ;\n arr[start] = arr[end];\n arr[end] = temp;\n start++ ;end-- ;\n }\n}\n\n\n//////////////////////////////////////////////////////////////////////////////////\n\n\npublic static int[][] rotate(int[][] input){\n\nint n =input.length;\nint m = input[0].length ;\nint[][] output = new int [m][n];\n\nfor (int i=0; i> (1L) ;\n } \n \n return count; \n \n } \n/////////////////////////////////////////// //////////////////////////////////////////////// \n\npublic static boolean isPowerOfTwo(long n) \n{ \n if(n==0) \n return false; \n \nif(((n ) & (n-1)) == 0 ) return true ;\nelse return false ;\n\n} \n\n/////////////////////////////////////////////////////////////////////////////////////\n\npublic static int min(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[0];\n}\n /////////////////////////////////////////////////////////////////////////////\npublic static int max(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[3];\n}\n \n/////////////////////////////////////////////////////////////////////////////////// \n\npublic static String reverse(String input)\n{\n StringBuilder str = new StringBuilder(\"\") ;\n \n for(int i =input.length()-1 ; i >= 0 ; i-- )\n {\n str.append(input.charAt(i));\n }\n \nreturn str.toString() ;\n}\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static boolean sameParity(long a ,long b )\n{\n long x = a% 2L; long y = b%2L ;\n if(x==y)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static boolean isPossibleTriangle(int a ,int b , int c)\n{\n if( a + b > c && c+b > a && a +c > b)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////\nstatic long xnor(long num1, long num2) {\n\t\tif (num1 < num2) {\n\t\t\tlong temp = num1;\n\t\t\tnum1 = num2;\n\t\t\tnum2 = temp;\n\t\t}\n\t\tnum1 = togglebit(num1);\n\t\treturn num1 ^ num2;\n\t}\n\n\tstatic long togglebit(long n) {\n\t\tif (n == 0)\n\t\t\treturn 1;\n\t\tlong i = n;\n\t\tn |= n >> 1;\n\t\tn |= n >> 2;\n\t\tn |= n >> 4;\n\t\tn |= n >> 8;\n\t\tn |= n >> 16;\n\t\treturn i ^ n;\n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int xorOfFirstN(int n)\n{\n \n \n if( n % 4 ==0)return n ;\n \n else if( n % 4 == 1)return 1 ;\n \n else if( n % 4 == 2)return n+1 ;\n \n else return 0 ;\n \n \n}\n//////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int gcd(int a, int b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n\npublic static long gcd(long a, long b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c , int d )\n{\n\nint temp = lcm(a,b , c) ;\n\n\n \n int ans = lcm(temp ,d ) ;\n\nreturn ans ;\n\n\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c )\n{\n\nint temp = lcm(a,b) ;\n\nint ans = lcm(temp ,c) ;\n\nreturn ans ;\n\n\n}\n\n////////////////////////////////////////////////////////////////////////////////////////\n \npublic static int lcm(int a , int b )\n{\n\nint gc = gcd(a,b);\n\nreturn (a*b)/gc ;\n}\n\n\npublic static long lcm(long a , long b )\n{\n\nlong gc = gcd(a,b);\n\nreturn (a*b)/gc ;\n}\n\n\n///////////////////////////////////////////////////////////////////////////////////////////\nstatic boolean isPrime(long n)\n{\n if(n==1)\n {\n return false ;\n }\n \n boolean ans = true ;\n \n for(long i = 2L; i*i <= n ;i++)\n {\n if(n% i ==0)\n {\n ans = false ;break ;\n }\n }\n \n \n return ans ;\n} \n///////////////////////////////////////////////////////////////////////////\n\nstatic int sieve = 1000000 ;\n\n \nstatic boolean[] prime = new boolean[sieve + 1] ;\n\npublic static void sieveOfEratosthenes() \n { \n // FALSE == prime\n \n // TRUE == COMPOSITE\n \n // FALSE== 1\n \n \n // time complexity = 0(NlogLogN)== o(N)\n \n // gives prime nos bw 1 to N\n \n for(int i = 4; i<= sieve ; i++)\n {\n prime[i] = true ;\n i++ ;\n }\n \n for(int p = 3; p*p <= sieve; p++) \n { \n \n if(prime[p] == false) \n { \n \n for(int i = p*p; i <= sieve; i += p) \n prime[i] = true; \n } \n \n p++ ;\n } \n \n \n \n \n } \n \n///////////////////////////////////////////////////////////////////////////////////\n\n\npublic static void sortD(int[] arr , int s , int e)\n{\n sort(arr ,s , e) ;\n \n int i =s ; int j = e ;\n \n while( i < j)\n {\n int temp = arr[i] ;\n arr[i] =arr[j] ;\n arr[j] = temp ;\n i++ ; j-- ;\n }\n \n \n \n return ;\n}\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long countSubarraysSumToK(long[] arr ,long sum )\n {\n HashMap map = new HashMap<>() ;\n \n int n = arr.length ;\n \n long prefixsum = 0 ;\n \n long count = 0L ;\n for(int i = 0; i < n ; i++)\n {\n prefixsum = prefixsum + arr[i] ;\n \n if(sum == prefixsum)count = count+1 ;\n \n if(map.containsKey(prefixsum -sum))\n {\n count = count + map.get(prefixsum -sum) ;\n }\n \n \n if(map.containsKey(prefixsum ))\n {\n map.put(prefixsum , map.get(prefixsum) +1 );\n }\n \n else{\n map.put(prefixsum , 1L );\n }\n \n \n }\n \n \n \n return count ; \n \n }\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\n\n// KMP ALGORITHM : TIME COMPL:O(N+M) \n// FINDS THE OCCURENCES OF PATTERN AS A SUBSTRING IN STRING\n//RETURN THE ARRAYLIST OF INDEXES \n// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING\n\n\npublic static ArrayList kmpAlgorithm(String str , String pat)\n {\n ArrayList list =new ArrayList<>();\n \n int n = str.length() ;\n int m = pat.length() ;\n \n String q = pat + \"#\" + str ;\n \n int[] lps =new int[n+m+1] ;\n \n longestPefixSuffix(lps, q,(n+m+1)) ;\n \n \n for(int i =m+1 ; i < (n+m+1) ; i++ )\n {\n if(lps[i] == m)\n {\n list.add(i-2*m) ;\n }\n }\n \n return list ; \n \n \n }\n \n\npublic static void longestPefixSuffix(int[] lps ,String str , int n)\n {\n lps[0] = 0 ;\n \n for(int i = 1 ; i<= n-1; i++)\n {\n int l = lps[i-1] ;\n \n while( l > 0 && str.charAt(i) != str.charAt(l))\n {\n l = lps[l-1] ;\n }\n \n if(str.charAt(i) == str.charAt(l))\n {\n l++ ;\n }\n \n \n lps[i] = l ; \n }\n \n }\n \n \n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n\n // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1 \n // or n and the no will be coprime in nature\n //time : O(n*(log(logn)))\n \n public static void eulerTotientFunction(int[] arr ,int n )\n {\n \n for(int i = 1; i <= n ;i++)arr[i] =i ;\n \n \n for(int i= 2 ; i<= n ;i++)\n {\n if(arr[i] == i)\n {\n arr[i] =i-1 ;\n \n for(int j =2*i ; j<= n ; j+= i )\n {\n arr[j] = (arr[j]*(i-1))/i ;\n }\n \n }\n }\n \n return ; \n \n }\n\t\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long nCr(int n,int k)\n{\n long ans=1L;\n k=k>n-k?n-k:k;\n int j=1;\n for(;j<=k;j++,n--)\n {\n if(n%j==0)\n {\n ans*=n/j;\n }else\n if(ans%j==0)\n {\n ans=ans/j*n;\n }else\n {\n ans=(ans*n)/j;\n }\n }\n return ans;\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static ArrayList allFactors(int n)\n{ \n ArrayList list = new ArrayList<>() ;\n \n for(int i = 1; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n\n\npublic static ArrayList allFactors(long n)\n{ \n ArrayList list = new ArrayList<>() ;\n \n for(long i = 1L; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n////////////////////////////////////////////////////////////////////////////////////////////////////\n\n static final int MAXN = 10000001; \n \n \n static int spf[] = new int[MAXN]; \n \n static void sieve() \n { \n spf[1] = 1; \n for (int i=2; i getFactorization(int x) \n { \n Vector ret = new Vector<>(); \n while (x != 1) \n { \n ret.add(spf[x]); \n x = x / spf[x]; \n } \n return ret; \n } \n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n //////////////////////////////////////////////////////////////////////////////////////////////////\n \npublic static void merge(int arr[], int l, int m, int r)\n {\n // Find sizes of two subarrays to be merged\n int n1 = m - l + 1;\n int n2 = r - m;\n \n /* Create temp arrays */\n int L[] = new int[n1];\n int R[] = new int[n2];\n \n //Copy data to temp arrays\n for (int i=0; i= weight[i]; j--) \n dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]); \n \n /*above line finds out maximum of dp[j](excluding ith element value) \n and val[i] + dp[j-wt[i]] (including ith element value and the \n profit with \"KnapSack capacity - ith element weight\") */\n return dp[maxWeight]; \n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n\n\n// to return max sum of any subarray in given array\npublic static long kadanesAlgorithm(long[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long kadanesAlgorithm(int[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n\n \n///////////////////////////////////////////////////////////////////////////////////////\n\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long binarySerachGreater(int[] arr , int start , int end , int val)\n{\n \n // fing total no of elements strictly grater than val in sorted array arr \n \n \n if(start > end)return 0 ; //Base case\n \n \n int mid = (start + end)/2 ;\n \n if(arr[mid] <=val)\n {\n return binarySerachGreater(arr,mid+1, end ,val) ; \n \n }\n else{\n \n return binarySerachGreater(arr,start , mid -1,val) + end-mid+1 ; \n \n }\n \n \n}\n\n//////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////\n\n//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING\n\n\n// JUST CALL generatePermutation( str, start, end) start :inclusive ,end : exclusive \n\n//Function for swapping the characters at position I with character at position j \n public static String swapString(String a, int i, int j) { \n char[] b =a.toCharArray(); \n char ch; \n ch = b[i]; \n b[i] = b[j]; \n b[j] = ch; \n return String.valueOf(b); \n } \n \n//Function for generating different permutations of the string \n public static void generatePermutation(String str, int start, int end) \n { \n //Prints the permutations \n if (start == end-1) \n System.out.println(str); \n else \n { \n for (int i = start; i < end; i++) \n { \n //Swapping the string by fixing a character \n str = swapString(str,start,i); \n //Recursively calling function generatePermutation() for rest of the characters \n generatePermutation(str,start+1,end); \n //Backtracking and swapping the characters again. \n str = swapString(str,start,i); \n } \n } \n } \n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long factMod(long n, long mod) {\n if (n <= 1) return 1;\n long ans = 1;\n for (int i = 1; i <= n; i++) {\n ans = (ans * i) % mod;\n }\n return ans;\n }\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long power(long x ,long n)\n {\n //time comp : o(logn) \n \n if(n==0)return 1L ;\n if(n==1)return x;\n \n long ans =1L ;\n \n while(n>0)\n {\n if(n % 2 ==1)\n {\n ans = ans *x ;\n }\n \n n /= 2 ;\n \n x = x*x ;\n \n }\n \n return ans ;\n }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static long powerMod(long x, long n, long mod) {\n //time comp : o(logn)\n \n if(n==0)return 1L ;\n if(n==1)return x;\n \n \n long ans = 1;\n while (n > 0) {\n if (n % 2 == 1) ans = (ans * x) % mod;\n x = (x * x) % mod;\n n /= 2;\n }\n return ans;\n }\n \n//////////////////////////////////////////////////////////////////////////////////\n\n/////////////////////////////////////////////////////////////////////////////////\n\n/*\nlowerBound - finds largest element equal or less than value paased\nupperBound - finds smallest element equal or more than value passed\n\nif not present return -1;\n\n*/\n\npublic static long lowerBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\tpublic static int lowerBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\t\n\tpublic static long upperBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\t\n\tpublic static int upperBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\n//////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void printArray(int[] arr , int si ,int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n \n}\n\npublic static void printArrayln(int[] arr , int si ,int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n}\n\n\npublic static void printLArray(long[] arr , int si , int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n \n}\n\n\n\n\npublic static void printLArrayln(long[] arr , int si , int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n \n}\n\npublic static void printtwodArray(int[][] ans)\n{\n for(int i = 0; i< ans.length ; i++)\n {\n for(int j = 0 ; j < ans[0].length ; j++)out.print(ans[i][j] +\" \");\n out.println() ;\n }\n out.println() ;\n \n}\n\n \n static long modPow(long a, long x, long p) {\n //calculates a^x mod p in logarithmic time.\n long res = 1;\n while(x > 0) {\n if( x % 2 != 0) {\n res = (res * a) % p;\n }\n a = (a * a) % p;\n x /= 2;\n }\n return res;\n}\n \n \n \n static long modInverse(long a, long p) {\n //calculates the modular multiplicative of a mod m.\n //(assuming p is prime).\n return modPow(a, p-2, p);\n}\n \n \n \nstatic long modBinomial(long n, long k, long p) {\n// calculates C(n,k) mod p (assuming p is prime).\n \n long numerator = 1; // n * (n-1) * ... * (n-k+1)\n for (int i=0; i[] tree ;\n// static long[] child;\n// static int mod= 1000000007 ;\n// static int[][] pre = new int[3001][3001];\n// static int[][] suf = new int[3001][3001] ;\n\n//program to calculate noof nodes in subtree for every vertex including itself \n\n public static void countNoOfNodesInsubtree(int child ,int par , int[] dp)\n {\n int count = 1 ;\n \n for(int x : tree[child])\n {\n \n if(x== par)continue ;\n \n countNoOfNodesInsubtree(x,child,dp) ;\n \n count= count + dp[x] ;\n }\n \n dp[child] = count ;\n \n }\n\npublic static void depth(int child ,int par , int[] dp , int d )\n {\n dp[child] =d ;\n \n for(int x : tree[child])\n {\n \n if(x== par)continue ;\n \n depth(x,child,dp,d+1) ;\n \n }\n \n }\n\npublic static void dfs(int sv , boolean[] vis)\n{\n vis[sv] = true ;\n \n \n for(int x : tree[sv])\n {\n if( !vis[x])\n {\n dfs(x ,vis) ;\n }\n }\n \n \n \n \n}\n\n\n//////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void solve()\n{\nFastReader scn = new FastReader() ;\n\n//Scanner scn = new Scanner(System.in);\n//int[] store = {2 ,3, 5 , 7 ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;\n\n// product of first 11 prime nos is greater than 10 ^ 12;\n\n//ArrayList arr[] = new ArrayList[n] ;\nArrayList list = new ArrayList<>() ;\nArrayList listl = new ArrayList<>() ;\nArrayList lista = new ArrayList<>() ;\nArrayList listb = new ArrayList<>() ;\n//ArrayList lists = new ArrayList<>() ;\n\nHashMap map = new HashMap<>() ;\n//HashMap map = new HashMap<>() ;\nHashMap map1 = new HashMap<>() ;\nHashMap map2 = new HashMap<>() ;\n//HashMap maps = new HashMap<>() ;\n//HashMap mapb = new HashMap<>() ;\n//HashMap point = new HashMap<>() ; \n\n Set set = new HashSet<>() ;\n Set setx = new HashSet<>() ;\n Set sety = new HashSet<>() ;\n\nStringBuilder sb =new StringBuilder(\"\") ;\n\n//Collections.sort(list);\n\n//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;\n//else map.put(arr[i],1) ;\n\n// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;\n// else map.put(temp,1) ;\n\n//int bit =Integer.bitCount(n);\n// gives total no of set bits in n;\n\n// Arrays.sort(arr, new Comparator() {\n// \t\t\t@Override\n// \t\t\tpublic int compare(Pair a, Pair b) {\n// \t\t\t\tif (a.first != b.first) {\n// \t\t\t\t\treturn a.first - b.first; // for increasing order of first\n// \t\t\t\t}\n// \t\t\t\treturn a.second - b.second ; //if first is same then sort on second basis\n// \t\t\t}\n// \t\t});\n\n\n\nint testcases = 1; \n //testcases = scn.nextInt() ;\nfor(int testcase =1 ; testcase <= testcases ;testcase++)\n{\n \n //if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ;\n //if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ;\n \n// int n = scn.nextInt() ;int m = scn.nextInt() ;\n// tree = new ArrayList[n] ;\n// for(int i = 0; i< n; i++)\n// {\n// tree[i] = new ArrayList();\n// }\n \n// for(int i = 0 ; i <= m-1 ; i++)\n// {\n// int fv = scn.nextInt()-1 ; int sv = scn.nextInt()-1 ;\n// tree[fv].add(sv) ;\n// tree[sv].add(fv) ;\n// }\n// boolean[] visited = new boolean[n] ;\n// int ans = 0 ;\n// for(int i = 0 ; i < n ; i++)\n// {\n// if(!visited[i])\n// {\n// dfs(i , visited ) ;\n// ans++ ;\n// }\n// }\n\nlong n = scn.nextLong() ;\n\nlong a1 = scn.nextLong() ;long a2 = scn.nextLong() ;long a3 = scn.nextLong() ;\nlong b1 = scn.nextLong() ;long b2 = scn.nextLong() ;long b3 = scn.nextLong() ;\n\n\nlong min = 0L ;\n\nif(b1 >= a1+a2)\n{\n min = a3-b2-b3 ;\n}\n\nelse if(b2 >= a3+a2)\n{\n min = a1-b1-b3 ;\n}\n\nelse if(b3 >= a1+a3)\n{\n min =,a2-b2-b1 ;\n}\n\n\nelse{\n min = 0 ;\n}\n\nlong max = Math.min(a1,b2) + Math.min(a2,b3) +Math.min(a3,b1) ;\n\n\nout.println(min+\" \" + max) ;\n\nsb.delete(0 , sb.length()) ;\nlist.clear() ;listb.clear() ;\nmap.clear() ;\nmap1.clear() ;\nmap2.clear() ;\nset.clear() ;sety.clear() ;\n\n} // test case end loop\n\n\nout.flush() ; \n} // solve fn ends\n\n\npublic static void main (String[] args) throws java.lang.Exception\n{\n \n\nsolve() ;\n \n}\n\n\n}\n \n class Pair \n{\n int first ;\n \n int second ;\n \n \n \n \n \n@Override\n\tpublic String toString() {\n\t\n\tString ans = \"\" ;\n\tans += this.first ;\n\tans += \" \";\n\tans += this.second ;\n\t\n\treturn ans ;\n\t}\n\n\n}\n\u00a0", "lang_cluster": "Java", "compilation_error": true, "code_uid": "34ab68480e3e29809e108b1a85358dfb", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.awt.Point;\n\n// SHIVAM GUPTA :\n//NSIT\n//decoder_1671\n\n// STOP NOT TILL IT IS DONE OR U DIE .\n\n// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................\n\n// ASCII = 48 + i ;// 2^28 = 268,435,456 > 2* 10^8 // log 10 base 2 = 3.3219 \n\n// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3// even:: (x^2/4)+1 ,(x^2/4)-1 x >=4 \n\n// FOR ANY ODD NO N : N,N-1,N-2\n//ALL ARE PAIRWISE COPRIME \n//THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS\n\n// two consecutive odds are always coprime to each other\n// two consecutive even have always gcd = 2 ;\n\npublic class Main\n{\n // static int[] arr = new int[100002] ; // static int[] dp = new int[100002] ; \n \n static PrintWriter out;\n \n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\n\n////////////////////////////////////////////////////////////////////////////////////\n public static int countDigit(long n) \n { \n return (int)Math.floor(Math.log10(n) + 1); \n } \n\n///////////////////////////////////////////////////////////////////////////////////////// \n \n public static int sumOfDigits(long n)\n {\n \n if( n< 0)return -1 ;\n \n int sum = 0;\n \n while( n > 0)\n {\n sum = sum + (int)( n %10) ;\n \n n /= 10 ;\n }\n \n return sum ; \n \n \n \n }\n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long arraySum(int[] arr , int start , int end)\n{\n long ans = 0 ;\n \n for(int i = start ; i <= end ; i++)ans += arr[i] ;\n \n return ans ;\n}\n\n/////////////////////////////////////////////////////////////////////////////////\n\npublic static int mod(int x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\npublic static long mod(long x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n\npublic static void swapArray(int[] arr , int start , int end)\n{\n while(start < end)\n {\n int temp = arr[start] ;\n arr[start] = arr[end];\n arr[end] = temp;\n start++ ;end-- ;\n }\n}\n\n\n//////////////////////////////////////////////////////////////////////////////////\n\n\npublic static int[][] rotate(int[][] input){\n\nint n =input.length;\nint m = input[0].length ;\nint[][] output = new int [m][n];\n\nfor (int i=0; i> (1L) ;\n } \n \n return count; \n \n } \n/////////////////////////////////////////// //////////////////////////////////////////////// \n\npublic static boolean isPowerOfTwo(long n) \n{ \n if(n==0) \n return false; \n \nif(((n ) & (n-1)) == 0 ) return true ;\nelse return false ;\n\n} \n\n/////////////////////////////////////////////////////////////////////////////////////\n\npublic static int min(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[0];\n}\n /////////////////////////////////////////////////////////////////////////////\npublic static int max(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[3];\n}\n \n/////////////////////////////////////////////////////////////////////////////////// \n\npublic static String reverse(String input)\n{\n StringBuilder str = new StringBuilder(\"\") ;\n \n for(int i =input.length()-1 ; i >= 0 ; i-- )\n {\n str.append(input.charAt(i));\n }\n \nreturn str.toString() ;\n}\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static boolean sameParity(long a ,long b )\n{\n long x = a% 2L; long y = b%2L ;\n if(x==y)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static boolean isPossibleTriangle(int a ,int b , int c)\n{\n if( a + b > c && c+b > a && a +c > b)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////\nstatic long xnor(long num1, long num2) {\n\t\tif (num1 < num2) {\n\t\t\tlong temp = num1;\n\t\t\tnum1 = num2;\n\t\t\tnum2 = temp;\n\t\t}\n\t\tnum1 = togglebit(num1);\n\t\treturn num1 ^ num2;\n\t}\n\n\tstatic long togglebit(long n) {\n\t\tif (n == 0)\n\t\t\treturn 1;\n\t\tlong i = n;\n\t\tn |= n >> 1;\n\t\tn |= n >> 2;\n\t\tn |= n >> 4;\n\t\tn |= n >> 8;\n\t\tn |= n >> 16;\n\t\treturn i ^ n;\n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int xorOfFirstN(int n)\n{\n \n \n if( n % 4 ==0)return n ;\n \n else if( n % 4 == 1)return 1 ;\n \n else if( n % 4 == 2)return n+1 ;\n \n else return 0 ;\n \n \n}\n//////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int gcd(int a, int b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n\npublic static long gcd(long a, long b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c , int d )\n{\n\nint temp = lcm(a,b , c) ;\n\n\n \n int ans = lcm(temp ,d ) ;\n\nreturn ans ;\n\n\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c )\n{\n\nint temp = lcm(a,b) ;\n\nint ans = lcm(temp ,c) ;\n\nreturn ans ;\n\n\n}\n\n////////////////////////////////////////////////////////////////////////////////////////\n \npublic static int lcm(int a , int b )\n{\n\nint gc = gcd(a,b);\n\nreturn (a*b)/gc ;\n}\n\n\npublic static long lcm(long a , long b )\n{\n\nlong gc = gcd(a,b);\n\nreturn (a*b)/gc ;\n}\n\n\n///////////////////////////////////////////////////////////////////////////////////////////\nstatic boolean isPrime(long n)\n{\n if(n==1)\n {\n return false ;\n }\n \n boolean ans = true ;\n \n for(long i = 2L; i*i <= n ;i++)\n {\n if(n% i ==0)\n {\n ans = false ;break ;\n }\n }\n \n \n return ans ;\n} \n///////////////////////////////////////////////////////////////////////////\n\nstatic int sieve = 1000000 ;\n\n \nstatic boolean[] prime = new boolean[sieve + 1] ;\n\npublic static void sieveOfEratosthenes() \n { \n // FALSE == prime\n \n // TRUE == COMPOSITE\n \n // FALSE== 1\n \n \n // time complexity = 0(NlogLogN)== o(N)\n \n // gives prime nos bw 1 to N\n \n for(int i = 4; i<= sieve ; i++)\n {\n prime[i] = true ;\n i++ ;\n }\n \n for(int p = 3; p*p <= sieve; p++) \n { \n \n if(prime[p] == false) \n { \n \n for(int i = p*p; i <= sieve; i += p) \n prime[i] = true; \n } \n \n p++ ;\n } \n \n \n \n \n } \n \n///////////////////////////////////////////////////////////////////////////////////\n\n\npublic static void sortD(int[] arr , int s , int e)\n{\n sort(arr ,s , e) ;\n \n int i =s ; int j = e ;\n \n while( i < j)\n {\n int temp = arr[i] ;\n arr[i] =arr[j] ;\n arr[j] = temp ;\n i++ ; j-- ;\n }\n \n \n \n return ;\n}\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long countSubarraysSumToK(long[] arr ,long sum )\n {\n HashMap map = new HashMap<>() ;\n \n int n = arr.length ;\n \n long prefixsum = 0 ;\n \n long count = 0L ;\n for(int i = 0; i < n ; i++)\n {\n prefixsum = prefixsum + arr[i] ;\n \n if(sum == prefixsum)count = count+1 ;\n \n if(map.containsKey(prefixsum -sum))\n {\n count = count + map.get(prefixsum -sum) ;\n }\n \n \n if(map.containsKey(prefixsum ))\n {\n map.put(prefixsum , map.get(prefixsum) +1 );\n }\n \n else{\n map.put(prefixsum , 1L );\n }\n \n \n }\n \n \n \n return count ; \n \n }\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\n\n// KMP ALGORITHM : TIME COMPL:O(N+M) \n// FINDS THE OCCURENCES OF PATTERN AS A SUBSTRING IN STRING\n//RETURN THE ARRAYLIST OF INDEXES \n// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING\n\n\npublic static ArrayList kmpAlgorithm(String str , String pat)\n {\n ArrayList list =new ArrayList<>();\n \n int n = str.length() ;\n int m = pat.length() ;\n \n String q = pat + \"#\" + str ;\n \n int[] lps =new int[n+m+1] ;\n \n longestPefixSuffix(lps, q,(n+m+1)) ;\n \n \n for(int i =m+1 ; i < (n+m+1) ; i++ )\n {\n if(lps[i] == m)\n {\n list.add(i-2*m) ;\n }\n }\n \n return list ; \n \n \n }\n \n\npublic static void longestPefixSuffix(int[] lps ,String str , int n)\n {\n lps[0] = 0 ;\n \n for(int i = 1 ; i<= n-1; i++)\n {\n int l = lps[i-1] ;\n \n while( l > 0 && str.charAt(i) != str.charAt(l))\n {\n l = lps[l-1] ;\n }\n \n if(str.charAt(i) == str.charAt(l))\n {\n l++ ;\n }\n \n \n lps[i] = l ; \n }\n \n }\n \n \n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n\n // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1 \n // or n and the no will be coprime in nature\n //time : O(n*(log(logn)))\n \n public static void eulerTotientFunction(int[] arr ,int n )\n {\n \n for(int i = 1; i <= n ;i++)arr[i] =i ;\n \n \n for(int i= 2 ; i<= n ;i++)\n {\n if(arr[i] == i)\n {\n arr[i] =i-1 ;\n \n for(int j =2*i ; j<= n ; j+= i )\n {\n arr[j] = (arr[j]*(i-1))/i ;\n }\n \n }\n }\n \n return ; \n \n }\n\t\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long nCr(int n,int k)\n{\n long ans=1L;\n k=k>n-k?n-k:k;\n int j=1;\n for(;j<=k;j++,n--)\n {\n if(n%j==0)\n {\n ans*=n/j;\n }else\n if(ans%j==0)\n {\n ans=ans/j*n;\n }else\n {\n ans=(ans*n)/j;\n }\n }\n return ans;\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static ArrayList allFactors(int n)\n{ \n ArrayList list = new ArrayList<>() ;\n \n for(int i = 1; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n\n\npublic static ArrayList allFactors(long n)\n{ \n ArrayList list = new ArrayList<>() ;\n \n for(long i = 1L; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n////////////////////////////////////////////////////////////////////////////////////////////////////\n\n static final int MAXN = 10000001; \n \n \n static int spf[] = new int[MAXN]; \n \n static void sieve() \n { \n spf[1] = 1; \n for (int i=2; i getFactorization(int x) \n { \n Vector ret = new Vector<>(); \n while (x != 1) \n { \n ret.add(spf[x]); \n x = x / spf[x]; \n } \n return ret; \n } \n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n //////////////////////////////////////////////////////////////////////////////////////////////////\n \npublic static void merge(int arr[], int l, int m, int r)\n {\n // Find sizes of two subarrays to be merged\n int n1 = m - l + 1;\n int n2 = r - m;\n \n /* Create temp arrays */\n int L[] = new int[n1];\n int R[] = new int[n2];\n \n //Copy data to temp arrays\n for (int i=0; i= weight[i]; j--) \n dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]); \n \n /*above line finds out maximum of dp[j](excluding ith element value) \n and val[i] + dp[j-wt[i]] (including ith element value and the \n profit with \"KnapSack capacity - ith element weight\") */\n return dp[maxWeight]; \n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n\n\n// to return max sum of any subarray in given array\npublic static long kadanesAlgorithm(long[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long kadanesAlgorithm(int[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n\n \n///////////////////////////////////////////////////////////////////////////////////////\n\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long binarySerachGreater(int[] arr , int start , int end , int val)\n{\n \n // fing total no of elements strictly grater than val in sorted array arr \n \n \n if(start > end)return 0 ; //Base case\n \n \n int mid = (start + end)/2 ;\n \n if(arr[mid] <=val)\n {\n return binarySerachGreater(arr,mid+1, end ,val) ; \n \n }\n else{\n \n return binarySerachGreater(arr,start , mid -1,val) + end-mid+1 ; \n \n }\n \n \n}\n\n//////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////\n\n//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING\n\n\n// JUST CALL generatePermutation( str, start, end) start :inclusive ,end : exclusive \n\n//Function for swapping the characters at position I with character at position j \n public static String swapString(String a, int i, int j) { \n char[] b =a.toCharArray(); \n char ch; \n ch = b[i]; \n b[i] = b[j]; \n b[j] = ch; \n return String.valueOf(b); \n } \n \n//Function for generating different permutations of the string \n public static void generatePermutation(String str, int start, int end) \n { \n //Prints the permutations \n if (start == end-1) \n System.out.println(str); \n else \n { \n for (int i = start; i < end; i++) \n { \n //Swapping the string by fixing a character \n str = swapString(str,start,i); \n //Recursively calling function generatePermutation() for rest of the characters \n generatePermutation(str,start+1,end); \n //Backtracking and swapping the characters again. \n str = swapString(str,start,i); \n } \n } \n } \n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long factMod(long n, long mod) {\n if (n <= 1) return 1;\n long ans = 1;\n for (int i = 1; i <= n; i++) {\n ans = (ans * i) % mod;\n }\n return ans;\n }\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long power(long x ,long n)\n {\n //time comp : o(logn) \n \n if(n==0)return 1L ;\n if(n==1)return x;\n \n long ans =1L ;\n \n while(n>0)\n {\n if(n % 2 ==1)\n {\n ans = ans *x ;\n }\n \n n /= 2 ;\n \n x = x*x ;\n \n }\n \n return ans ;\n }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static long powerMod(long x, long n, long mod) {\n //time comp : o(logn)\n \n if(n==0)return 1L ;\n if(n==1)return x;\n \n \n long ans = 1;\n while (n > 0) {\n if (n % 2 == 1) ans = (ans * x) % mod;\n x = (x * x) % mod;\n n /= 2;\n }\n return ans;\n }\n \n//////////////////////////////////////////////////////////////////////////////////\n\n/////////////////////////////////////////////////////////////////////////////////\n\n/*\nlowerBound - finds largest element equal or less than value paased\nupperBound - finds smallest element equal or more than value passed\n\nif not present return -1;\n\n*/\n\npublic static long lowerBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\tpublic static int lowerBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\t\n\tpublic static long upperBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\t\n\tpublic static int upperBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\n//////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void printArray(int[] arr , int si ,int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n \n}\n\npublic static void printArrayln(int[] arr , int si ,int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n}\n\n\npublic static void printLArray(long[] arr , int si , int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n \n}\n\n\n\n\npublic static void printLArrayln(long[] arr , int si , int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n \n}\n\npublic static void printtwodArray(int[][] ans)\n{\n for(int i = 0; i< ans.length ; i++)\n {\n for(int j = 0 ; j < ans[0].length ; j++)out.print(ans[i][j] +\" \");\n out.println() ;\n }\n out.println() ;\n \n}\n\n \n static long modPow(long a, long x, long p) {\n //calculates a^x mod p in logarithmic time.\n long res = 1;\n while(x > 0) {\n if( x % 2 != 0) {\n res = (res * a) % p;\n }\n a = (a * a) % p;\n x /= 2;\n }\n return res;\n}\n \n \n \n static long modInverse(long a, long p) {\n //calculates the modular multiplicative of a mod m.\n //(assuming p is prime).\n return modPow(a, p-2, p);\n}\n \n \n \nstatic long modBinomial(long n, long k, long p) {\n// calculates C(n,k) mod p (assuming p is prime).\n \n long numerator = 1; // n * (n-1) * ... * (n-k+1)\n for (int i=0; i[] tree ;\n// static long[] child;\n// static int mod= 1000000007 ;\n// static int[][] pre = new int[3001][3001];\n// static int[][] suf = new int[3001][3001] ;\n\n//program to calculate noof nodes in subtree for every vertex including itself \n\n public static void countNoOfNodesInsubtree(int child ,int par , int[] dp)\n {\n int count = 1 ;\n \n for(int x : tree[child])\n {\n \n if(x== par)continue ;\n \n countNoOfNodesInsubtree(x,child,dp) ;\n \n count= count + dp[x] ;\n }\n \n dp[child] = count ;\n \n }\n\npublic static void depth(int child ,int par , int[] dp , int d )\n {\n dp[child] =d ;\n \n for(int x : tree[child])\n {\n \n if(x== par)continue ;\n \n depth(x,child,dp,d+1) ;\n \n }\n \n }\n\npublic static void dfs(int sv , boolean[] vis)\n{\n vis[sv] = true ;\n \n \n for(int x : tree[sv])\n {\n if( !vis[x])\n {\n dfs(x ,vis) ;\n }\n }\n \n \n \n \n}\n\n\n//////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void solve()\n{\nFastReader scn = new FastReader() ;\n\n//Scanner scn = new Scanner(System.in);\n//int[] store = {2 ,3, 5 , 7 ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;\n\n// product of first 11 prime nos is greater than 10 ^ 12;\n\n//ArrayList arr[] = new ArrayList[n] ;\nArrayList list = new ArrayList<>() ;\nArrayList listl = new ArrayList<>() ;\nArrayList lista = new ArrayList<>() ;\nArrayList listb = new ArrayList<>() ;\n//ArrayList lists = new ArrayList<>() ;\n\nHashMap map = new HashMap<>() ;\n//HashMap map = new HashMap<>() ;\nHashMap map1 = new HashMap<>() ;\nHashMap map2 = new HashMap<>() ;\n//HashMap maps = new HashMap<>() ;\n//HashMap mapb = new HashMap<>() ;\n//HashMap point = new HashMap<>() ; \n\n Set set = new HashSet<>() ;\n Set setx = new HashSet<>() ;\n Set sety = new HashSet<>() ;\n\nStringBuilder sb =new StringBuilder(\"\") ;\n\n//Collections.sort(list);\n\n//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;\n//else map.put(arr[i],1) ;\n\n// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;\n// else map.put(temp,1) ;\n\n//int bit =Integer.bitCount(n);\n// gives total no of set bits in n;\n\n// Arrays.sort(arr, new Comparator() {\n// \t\t\t@Override\n// \t\t\tpublic int compare(Pair a, Pair b) {\n// \t\t\t\tif (a.first != b.first) {\n// \t\t\t\t\treturn a.first - b.first; // for increasing order of first\n// \t\t\t\t}\n// \t\t\t\treturn a.second - b.second ; //if first is same then sort on second basis\n// \t\t\t}\n// \t\t});\n\n\n\nint testcases = 1; \n //testcases = scn.nextInt() ;\nfor(int testcase =1 ; testcase <= testcases ;testcase++)\n{\n \n //if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ;\n //if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ;\n \n// int n = scn.nextInt() ;int m = scn.nextInt() ;\n// tree = new ArrayList[n] ;\n// for(int i = 0; i< n; i++)\n// {\n// tree[i] = new ArrayList();\n// }\n \n// for(int i = 0 ; i <= m-1 ; i++)\n// {\n// int fv = scn.nextInt()-1 ; int sv = scn.nextInt()-1 ;\n// tree[fv].add(sv) ;\n// tree[sv].add(fv) ;\n// }\n// boolean[] visited = new boolean[n] ;\n// int ans = 0 ;\n// for(int i = 0 ; i < n ; i++)\n// {\n// if(!visited[i])\n// {\n// dfs(i , visited ) ;\n// ans++ ;\n// }\n// }\n\nlong n = scn.nextLong() ;\n\nlong a1 = scn.nextLong() ;long a2 = scn.nextLong() ;long a3 = scn.nextLong() ;\nlong b1 = scn.nextLong() ;long b2 = scn.nextLong() ;long b3 = scn.nextLong() ;\n\n\nlong min = 0L ;\n\nif(b1 >= a1+a2)\n{\n min = a3-b2-b3 ;\n}\n\nelse if(b2 >= a3+a2)\n{\n min = a1-b1-b3 ;\n}\n\nelse if(b3 >= a1+a3)\n{\n min =a2-b2-b1 ;\n}\n\n\nelse{\n min = 0 ;\n}\n\nlong max = Math.min(a1,b2) + Math.min(a2,b3) +Math.min(a3,b1) ;\n\n\nout.println(min+\" \" + max) ;\n\nsb.delete(0 , sb.length()) ;\nlist.clear() ;listb.clear() ;\nmap.clear() ;\nmap1.clear() ;\nmap2.clear() ;\nset.clear() ;sety.clear() ;\n\n} // test case end loop\n\n\nout.flush() ; \n} // solve fn ends\n\n\npublic static void main (String[] args) throws java.lang.Exception\n{\n \n\nsolve() ;\n \n}\n\n\n}\n \n class Pair \n{\n int first ;\n \n int second ;\n \n \n \n \n \n@Override\n\tpublic String toString() {\n\t\n\tString ans = \"\" ;\n\tans += this.first ;\n\tans += \" \";\n\tans += this.second ;\n\t\n\treturn ans ;\n\t}\n\n\n}\n\u00a0", "lang_cluster": "Java", "compilation_error": true, "code_uid": "08a73bc4fe7eafa2b1691496bedee245", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.HashSet;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.io.FileWriter;\nimport java.io.PrintWriter;\n/*\n Solution Created: 15:30:24 28/09/2020\n Custom Competitive programming helper.\n*/\n\npublic class Main {\n\tstatic ArrayList ans;\n\tpublic static void solve(Reader in, Writer out) {\n\t\tint t = 1;\n\t\twhile(t-->0) {\n\t\t\tint n = in.nextInt();\n\t\t\tint[] a = in.na(3);\n\t\t\tint[] b = in.na(3);\n\t\t\tint v2 = s(a,b);\n\t\t\tfix(a, b);\n\t\t\tint v1 = s(a,b);\n\t\t\tout.println(v1+\" \"+v2);\n\t\t}\n\t}\n\tpublic static void fix(int[] a, int[] b) {\n\t\tfor(int i = 0; i<3*5; i++) {\n\t\t\tint t1 = (i%3), t2 = (i+2)%3;\n\t\t\tif(b[t1]>b[t2]) {\n\t\t\t\tint mn = Math.min(b[t1], a[i%3]);\n\t\t\t\ta[i%3]-=mn;\n\t\t\t\tb[t1]-=mn;\n\t\t\t}else {\n\t\t\t\tint mn = Math.min(b[t2], a[i%3]);\n\t\t\t\ta[i%3]-=mn;\n\t\t\t\tb[t2]-=mn;\n\t\t\t}\n\t\t}\n\t}\n\tpublic static int s(int[] a, int[] b) {\n\t\tint ans = Math.min(a[0], b[1]);\n\t\tans += Math.min(a[1], b[2]);\n\t\tans += Math.min(a[2], b[0]);\n\t\treturn ans;\n\t}\n\tpublic static void main(String[] args) {\n\t\tReader in = new Reader();\n\t\tWriter out = new Writer();\n\t\tsolve(in, out);\n\t\tout.exit();\n\t}\n}\n/*\n\n\npublic class Main {\n\tstatic ArrayList ans;\n\tpublic static void solve(Reader in, Writer out) {\n\t\tint t = 1;\n\t\twhile(t-->0) {\n\t\t\tint n = in.nextInt();\n\t\t\tint[] a = in.na(3);\n\t\t\tint[] b = in.na(3);\n\t\t\tout.println(f(a, b)+\" \"+s(a,b));\n\t\t}\n\t}\n\tpublic static int f(int[] a, int[] b) {\n\t\t//r s p\n\t\tint ans = 0;\n\t\tfor(int i = 0; i<9; i++) {\n\t\t\tint t1 = (i%3), t2 = (i+2)%3;\n\t\t\tif(b[t1]>b[t2]) {\n\t\t\t\tint mn = Math.min(b[t1], a[i%3]);\n\t\t\t\ta[i%3]-=mn;\n\t\t\t\tb[t1]-=mn;\n\t\t\t}else {\n\t\t\t\tint mn = Math.min(b[t2], a[i%3]);\n\t\t\t\ta[i%3]-=mn;\n\t\t\t\tb[t2]-=mn;\n\t\t\t}\n\t\t}\n\t\tUtil.dbg(a);\n\t\tUtil.dbg(b);\n\t\treturn ans;\n\t}\n\tpublic static int s(int[] a, int[] b) {\n\t\tint ans = Math.min(a[0], b[1]);\n\t\tans += Math.min(a[1], b[2]);\n\t\tans += Math.min(a[2], b[0]);\n\t\treturn ans;\n\t}\n\tpublic static void main(String[] args) {\n\t\tReader in = new Reader();\n\t\tWriter out = new Writer();\n\t\tsolve(in, out);\n\t\tout.exit();\n\t}\n\nstatic class Reader {\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tprivate int charIdx = 0;\n\tprivate String s;\n\n\tpublic Reader() {\n\t\tthis.br = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\t\n\tpublic Reader(String f){\n\t\ttry {\n\t\t\tthis.br = new BufferedReader(new FileReader(f));\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\t\n\tpublic 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] = nextInt();\n\t\treturn a;\n\t}\n\n\tpublic double[] nd(int n) {\n\t\tdouble[] a = new double[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextDouble();\n\t\treturn a;\n\t}\n\n\tpublic char nextChar() {\n\t\tif (s == null || charIdx >= s.length()) {\n\t\t\tif (st == null || !st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\treadLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t}\n\t\t\ts = st.nextToken();\n\t\t\tcharIdx = 0;\n\t\t}\n\t\treturn s.charAt(charIdx++);\n\t}\n\n\tpublic long[] nl(int n) {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextLong();\n\t\treturn a;\n\t}\n\n\tpublic char[] nca() {\n\t\treturn next().toCharArray();\n\t}\n\n\tpublic String[] nS(int n) {\n\t\tString[] a = new String[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = next();\n\t\treturn a;\n\t}\n\n\tpublic int nextInt() {\n\t\tif (st == null || !st.hasMoreTokens())\n\t\t\ttry {\n\t\t\t\treadLine();\n\t\t\t} catch (Exception e) {\n\t\t\t}\n\t\treturn Integer.parseInt(st.nextToken());\n\t}\n\n\tpublic double nextDouble() {\n\t\tif (st == null || !st.hasMoreTokens())\n\t\t\ttry {\n\t\t\t\treadLine();\n\t\t\t} catch (Exception e) {\n\t\t\t}\n\t\treturn Double.parseDouble(st.nextToken());\n\t}\n\n\tpublic Long nextLong() {\n\t\tif (st == null || !st.hasMoreTokens())\n\t\t\ttry {\n\t\t\t\treadLine();\n\t\t\t} catch (Exception e) {\n\t\t\t}\n\t\treturn Long.parseLong(st.nextToken());\n\t}\n\n\tpublic String next() {\n\t\tif (st == null || !st.hasMoreTokens())\n\t\t\ttry {\n\t\t\t\treadLine();\n\t\t\t} catch (Exception e) {\n\t\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic static void readLine() {\n\t\ttry {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t} catch (Exception e) {\n\t\t}\n\t}\n}\n\nstatic class Util{\n\t\tprivate static Random random = new Random();\n\t\t\n\t\tpublic static long modInverse(long a, long MOD) {\n\t\t\tlong[] gcdE = gcdExtended(a, MOD);\n\t\t\tif (gcdE[0] != 1) return -1; // Inverted doesn't exist\n\t\t\tlong x = gcdE[1];\n\t\t\treturn (x % MOD + MOD) % MOD;\n\t\t}\n\t\tpublic static long[] gcdExtended(long p, long q) {\n\t\t\tif (q == 0) return new long[] { p, 1, 0 };\n\t\t\tlong[] vals = gcdExtended(q, p % q);\n\t\t\tlong tmp = vals[2];\n\t\t\tvals[2] = vals[1] - (p / q) * vals[2];\n\t\t\tvals[1] = tmp;\n\t\t\treturn vals;\n\t\t}\n\t\tpublic void fac(int n) {\n\t\t\t\n\t\t}\n\t\tpublic static boolean isPrime(int n) { \n\t if (n <= 1) return false; \n\t if (n <= 3) return true; \n\t if (n % 2 == 0 || n % 3 == 0) return false; \n\t for (int i = 5; i * i <= n; i = i + 6) \n\t if (n % i == 0 || n % (i + 2) == 0) \n\t return false; \n\t return true; \n\t }\n\t public static int lowerBound(int[] a, int v) {\n\t \tint l = 0, h = a.length;\n\t \twhile(l void reverse(T[] s, int l , int r) {\n\t\t\tfor(int i = l; i<=(l+r)/2; i++) {\n\t\t\t\tT tmp = s[i];\n\t\t\t\ts[i] = s[r+l-i];\n\t\t\t\ts[r+l-i] = tmp;\n\t\t\t}\n\t }\n\t\tpublic static void reverse(T[] s) {\n\t\t\treverse(s, 0, s.length-1);\n\t }\n\t\tpublic static void shuffle(int[] s) {\n\t for (int i = 0; i < s.length; ++i) {\n\t int j = random.nextInt(i + 1);\n\t int t = s[i];\n\t s[i] = s[j];\n\t s[j] = t;\n\t }\n\t }\n\t public static void shuffle(long[] s) {\n\t for (int i = 0; i < s.length; ++i) {\n\t int j = random.nextInt(i + 1);\n\t long t = s[i];\n\t s[i] = s[j];\n\t s[j] = t;\n\t }\n\t }\n\t public static void shuffle(float[] s) {\n\t for (int i = 0; i < s.length; ++i) {\n\t int j = random.nextInt(i + 1);\n\t float t = s[i];\n\t s[i] = s[j];\n\t s[j] = t;\n\t }\n\t }\n\t public static void shuffle(double[] s) {\n\t for (int i = 0; i < s.length; ++i) {\n\t int j = random.nextInt(i + 1);\n\t double t = s[i];\n\t s[i] = s[j];\n\t s[j] = t;\n\t }\n\t }\n\t public static void shuffle(char[] s) {\n\t for (int i = 0; i < s.length; ++i) {\n\t int j = random.nextInt(i + 1);\n\t char t = s[i];\n\t s[i] = s[j];\n\t s[j] = t;\n\t }\n\t }\n\t public static void shuffle(T[] s) {\n\t for (int i = 0; i < s.length; ++i) {\n\t int j = random.nextInt(i + 1);\n\t T t = s[i];\n\t s[i] = s[j];\n\t s[j] = t;\n\t }\n\t }\n\t\tpublic static void sortArray(int[] a) {\n\t shuffle(a);\n\t Arrays.sort(a);\n\t }\n\t\tpublic static void sortArray(long[] a) {\n\t\t\tshuffle(a);\n\t Arrays.sort(a);\n\t }\n\t\tpublic static void sortArray(float[] a) {\n\t\t\tshuffle(a);\n\t Arrays.sort(a);\n\t }\n\t\tpublic static void sortArray(double[] a) {\n\t\t\tshuffle(a);\n\t Arrays.sort(a);\n\t }\n\t\tpublic static void sortArray(char[] a) {\n\t\t\tshuffle(a);\n\t Arrays.sort(a);\n\t }\n\t\tpublic static > void sortArray(T[] a) {\n\t Arrays.sort(a);\n\t }\n\t}\n\nstatic class Writer {\n\tprivate PrintWriter pw;\n\tpublic Writer(){\n\t\tpw = new PrintWriter(System.out);\n\t}\n\t\n\tpublic Writer(String f){\n\t\ttry {\n\t\t\tpw = new PrintWriter(new FileWriter(f));\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\t\n\tpublic void printArray(int[] a) {\n\t\tfor(int i = 0; is=new HashSet<>();\n for (int i = 0; i < x.length(); i++) {\n s.add(x.charAt(i));\n }\n char a=96;\n for (int i = 0; i arr[i+1]){pw.println(\"NO\");pw.flush();System.exit(0);}\n }\n pw.println(\"YES\");pw.flush();\n }\n public static class FastScanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(String s)\n\t\t{\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 FastScanner()\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString nextToken()\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\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\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\n\t\tlong nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tdouble nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t\t\n\t\tString next()\n\t\t{\n\t\t\treturn nextToken();\n\t\t}\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6795748db5aec2d62fd43b0c7213971b", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "mport java.io.*;\nimport java.util.*;\n\npublic class HEnitA {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n //PrintWriter w = new PrintWriter(System.out);\n char[] a=in.next().toCharArray();\n HashSet hs=new HashSet<>();\n char cur='a';\n hs.add(cur);\n int i;\n for(i=0;i max + 1){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n \t\n \tmax = Math.max(c, max);\n } \n \n System.out.println(\"YES\");\n }\n\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "259c8981b827924acf9bc160e0ebdfae", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.HashMap;\nimport java.util.Scanner;\n\npublic class imanalog {\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tint vi[] = new int[26];\n\t\tString h = \"\";\n\t\tfor(int i = 0; i < s.length();i++){\n\t\t\tint ch = s.charAt(i) - 'a';\n\t\t\tif(vi[ch] == 0){\n\t\t\t\th = h + s.charAt(i);\n\t\t\t\tvi[ch] = 1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\tint flag = 0;\n\t\tfor(int i = 1; i < h.length(); i++){\n\t\t\tif(h.charAt(i-1) > h.charAt(i)){\n\t\t\t\tflag = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(flag == 0)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t\t\n\n}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9317906051b8bc4ffe6c551aec9ffd2", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class C_Round_90 {\n\n public static long MOD = 1000000007;\n static long[][][][] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n // \"output.txt\")));\n PrintWriter out = new PrintWriter(System.out);\n Scanner in = new Scanner();\n int n = in.nextInt();\n int m = in.nextInt();\n int k = in.nextInt();\n long[][] data = new long[m][4];\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < 3; j++) {\n data[i][j] = in.nextLong();\n }\n data[i][3] = i;\n }\n Arrays.sort(data, new Comparator() {\n @Override\n public int compare(long[] o1, long[] o2) {\n return Long.compare(a[2], b[2]);\n }\n\n }\n );\n dp = new long[m][n + 1][m + 1][101];\n for (long[][][] a : dp) {\n for (long[][] b : a) {\n for (long[] c : b) {\n Arrays.fill(c, -1);\n }\n }\n }\n long v = cal(0, n, m, 0, m, k, data);\n // out.println(v);\n if (v != -1) {\n out.println(\"YES\");\n int index = 0;\n int left = n;\n int last = m;\n int num = 0;\n while (left > 0) {\n // System.out.println(index + \" \" + left + \" \" + last + \" \" + num + \" \" + (dp[index][left][last][num]));\n if (index + 1 < m && dp[index][left][last][num] == dp[index + 1][left][last][num]) {\n\n } else if (last == m) {\n for (int i = 0; i + data[index][0] <= data[index][1]; i++) {\n if (dp[index][left][last][num] == (long) i + data[index][0] + (index + 1 < m ? dp[index + 1][left - 1][index][i] : 0) && (index + 1 == m || dp[index + 1][left - 1][index][i] != -1)) {\n out.println((data[index][3] + 1) + \" \" + (data[index][0] + i));\n left--;\n last = index;\n num = i;\n break;\n }\n }\n } else {\n long tmp = data[last][0] + num;\n if (data[index][0] <= tmp + k && data[index][1] >= tmp + k) {\n int nxt = (int) (tmp + k - data[index][0]);\n if ((index + 1 == m || dp[index + 1][left - 1][index][nxt] != -1) && (index + 1 < m ? dp[index + 1][left - 1][index][nxt] : 0) + tmp + k == dp[index][left][last][num]) {\n out.println((data[index][3] + 1) + \" \" + (tmp + k));\n left--;\n last = index;\n num = nxt;\n index++;\n continue;\n }\n }\n int nxt = (int) (tmp * k - data[index][0]);\n out.println((data[index][3] + 1) + \" \" + (tmp * k));\n left--;\n last = index;\n num = nxt;\n\n }\n index++;\n }\n } else {\n out.println(\"NO\");\n }\n out.close();\n }\n\n public static long cal(int index, int left, int last, int num, int m, long k, long[][] data) {\n if (left == 0) {\n if (index < m) {\n dp[index][left][last][num] = 0;\n }\n return 0;\n }\n if (m - index < left) {\n return -1;\n }\n\n if (dp[index][left][last][num] != -1) {\n return dp[index][left][last][num];\n }\n long result = cal(index + 1, left, last, num, m, k, data);\n\n if (last == m) {\n\n for (int i = 0; i <= data[index][1] - data[index][0]; i++) {\n long v = cal(index + 1, left - 1, index, i, m, k, data);\n if (v != -1) {\n result = max(result, v + (long) i + data[index][0]);\n }\n }\n } else if (data[index][2] > data[last][2]) {\n long tmp = data[last][0] + num;\n if (data[index][0] <= tmp + k && data[index][1] >= tmp + k) {\n long v = cal(index + 1, left - 1, index, (int) (tmp + k - data[index][0]), m, k, data);\n if (v != -1) {\n result = max(result, tmp + k + v);\n }\n }\n if (data[index][0] <= k * tmp && k * tmp <= data[index][1]) {\n long v = cal(index + 1, left - 1, index, (int) (tmp * k - data[index][0]), m, k, data);\n if (v != -1) {\n result = max(result, tmp * k + v);\n }\n }\n }\n return dp[index][left][last][num] = result;\n\n }\n\n static long max(long a, long b) {\n return a > b ? a : b;\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5d3094082f9caf2005336bf79cede3ce", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Stack;\n\n\npublic class Main {\n static int n = 0, m = 0, k = 0;\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n n = r.nextInt();\n m = r.nextInt();\n k = r.nextInt();\n \n a = new Subject[m];\n for(int i = 0; i < m; i++)\n a[i] = new Subject(r.nextLong(), r.nextLong(), r.nextInt(), i + 1);\n \n Arrays.sort(a);\n for(long[][] i : dp)\n for(long[] j : i)\n Arrays.fill(j, empty);\n \n long max = -inf, maxD = -1;\n int maxS = -1;\n for(int s = 0; s < m; s++)\n for(long d = a[s].a ; d <= a[s].b; d++){ \n long curr = go(s, d, n); \n if(curr > max){\n max = curr;\n maxD = d;\n maxS = s;\n }\n }\n \n \n if(max < 0)System.out.println(\"NO\");\n else{\n System.out.println(\"YES\");\n \n construct(maxS, maxD, n);\n }\n }\n private static void construct(int i, long x, int rem) {\n System.out.println(a[i].i + \" \" + x);\n if(rem - 1 != 0)construct(S[i][(int) (x - a[i].a)][rem], X[i][(int) (x - a[i].a)][rem], rem - 1);\n \n }\n static Subject[] a;\n static long inf = 1L << 62;\n static long empty = -1L << 63;\n static int[][][] S = new int[60][110][60];\n static long[][][] X = new long[60][110][60]; \n static long[][][] dp = new long[60][110][60];\n private static long go(int i, long x, int rem) {\n if(rem == 1){\n return x;\n }\n \n if(dp[i][(int) (x - a[i].a)][rem] != empty)return dp[i][(int) (x - a[i].a)][rem];\n \n long best = -inf;\n for(int j = i + 1; j < m; j++){\n if(a[j].c == a[i].c)continue;\n \n if(x + k >= 0 && a[j].a <= x + k && x + k <= a[j].b){\n long w1 = x + go(j, x + k, rem - 1);\n if(w1 > best){\n best = w1;\n S[i][(int) (x - a[i].a)][rem] = j;\n X[i][(int) (x - a[i].a)][rem] = x + k;\n }\n }\n \n if(x * k >= 0 && a[j].a <= x * k && x * k <= a[j].b){\n long w2 = x + go(j, x * k, rem - 1);\n if(w2 > best){\n best = w2;\n S[i][(int) (x - a[i].a)][rem] = j;\n X[i][(int) (x - a[i].a)][rem] = x * k;\n }\n }\n }\n \n return dp[i][(int) (x - a[i].a)][rem] = best;\n }\n}\nclass Subject implements Comparable{\n long a, b;\n int c, i;\n public Subject(long ai, long bi, int ci, int ii){\n a = ai;\n b = bi;\n c = ci;\n i = ii;\n }\n @Override\n public int compareTo(Subject b) {\n if(c < b.c)return -1;\n else if(c > b.c)return 1;\n else return 0;\n }\n}\nclass P{\n int i;\n long t;\n public P(int ii, long ti){\n i = ii;\n t = ti;\n }\n public String toString(){\n return String.format(\"%d %d\", i, t);\n } \n}import java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Stack;\n\n\npublic class Main {\n static int n = 0, m = 0, k = 0;\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n n = r.nextInt();\n m = r.nextInt();\n k = r.nextInt();\n \n a = new Subject[m];\n for(int i = 0; i < m; i++)\n a[i] = new Subject(r.nextLong(), r.nextLong(), r.nextInt(), i + 1);\n \n Arrays.sort(a);\n for(long[][] i : dp)\n for(long[] j : i)\n Arrays.fill(j, empty);\n \n long max = -inf, maxD = -1;\n int maxS = -1;\n for(int s = 0; s < m; s++)\n for(long d = a[s].a ; d <= a[s].b; d++){ \n long curr = go(s, d, n); \n if(curr > max){\n max = curr;\n maxD = d;\n maxS = s;\n }\n }\n \n \n if(max < 0)System.out.println(\"NO\");\n else{\n System.out.println(\"YES\");\n \n construct(maxS, maxD, n);\n }\n }\n private static void construct(int i, long x, int rem) {\n System.out.println(a[i].i + \" \" + x);\n if(rem - 1 != 0)construct(S[i][(int) (x - a[i].a)][rem], X[i][(int) (x - a[i].a)][rem], rem - 1);\n \n }\n static Subject[] a;\n static long inf = 1 << 28;\n static long empty = -1 << 29;\n static int[][][] S = new int[60][110][60];\n static long[][][] X = new long[60][110][60]; \n static long[][][] dp = new long[60][110][60];\n private static long go(int i, long x, int rem) {\n if(rem == 1){\n return x;\n }\n \n if(dp[i][(int) (x - a[i].a)][rem] != empty)return dp[i][(int) (x - a[i].a)][rem];\n \n long best = -inf;\n for(int j = i + 1; j < m; j++){\n if(a[j].c == a[i].c)continue;\n \n if(x + k >= 0 && a[j].a <= x + k && x + k <= a[j].b){\n long w1 = x + go(j, x + k, rem - 1);\n if(w1 > best){\n best = w1;\n S[i][(int) (x - a[i].a)][rem] = j;\n X[i][(int) (x - a[i].a)][rem] = x + k;\n }\n }\n \n if(x * k >= 0 && a[j].a <= x * k && x * k <= a[j].b){\n long w2 = x + go(j, x * k, rem - 1);\n if(w2 > best){\n best = w2;\n S[i][(int) (x - a[i].a)][rem] = j;\n X[i][(int) (x - a[i].a)][rem] = x * k;\n }\n }\n }\n \n return dp[i][(int) (x - a[i].a)][rem] = best;\n }\n}\nclass Subject implements Comparable{\n long a, b;\n int c, i;\n public Subject(long ai, long bi, int ci, int ii){\n a = ai;\n b = bi;\n c = ci;\n i = ii;\n }\n @Override\n public int compareTo(Subject b) {\n if(c < b.c)return -1;\n else if(c > b.c)return 1;\n else return 0;\n }\n}\nclass P{\n int i;\n long t;\n public P(int ii, long ti){\n i = ii;\n t = ti;\n }\n public String toString(){\n return String.format(\"%d %d\", i, t);\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e1d1689a4b7ecddbe8690c899bc935f8", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class C_Round_90 {\n\n public static long MOD = 1000000007;\n static long[][][][] dp;\n static HashSet set = new HashSet();\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 n = in.nextInt();\n int m = in.nextInt();\n int k = in.nextInt();\n long[][] data = new long[m][4];\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < 3; j++) {\n data[i][j] = in.nextLong();\n }\n data[i][3] = i;\n }\n Arrays.sort(data, new Comparator() {\n @Override\n public int compare(long[] a, long[] b) {\n return Long.compare(a[2], b[2]);\n }\n\n }\n );\n\n dp = new long[m][n + 1][m + 1][101];\n for (long[][][] a : dp) {\n for (long[][] b : a) {\n for (long[] c : b) {\n Arrays.fill(c, -1);\n }\n }\n }\n long v = cal(0, n, m, 0, m, k, data);\n // out.println(v);\n\n if (v != -1) {\n out.println(\"YES\");\n int index = 0;\n int left = n;\n int last = m;\n int num = 0;\n while (left > 0) {\n // System.out.println(index + \" \" + left + \" \" + last + \" \" + num + \" \" + (dp[index][left][last][num]));\n if (index + 1 < m && dp[index][left][last][num] == dp[index + 1][left][last][num]) {\n\n } else if (last == m) {\n for (int i = 0; i + data[index][0] <= data[index][1]; i++) {\n if (dp[index][left][last][num] == (long) i + data[index][0] + (index + 1 < m ? dp[index + 1][left - 1][index][i] : 0) && (index + 1 == m || dp[index + 1][left - 1][index][i] != -1)) {\n out.println((data[index][3] + 1) + \" \" + (data[index][0] + i));\n left--;\n last = index;\n num = i;\n break;\n }\n }\n } else {\n long tmp = data[last][0] + num;\n if (data[index][0] <= tmp + k && data[index][1] >= tmp + k) {\n int nxt = (int) (tmp + k - data[index][0]);\n if ((index + 1 == m || dp[index + 1][left - 1][index][nxt] != -1) && (index + 1 < m ? dp[index + 1][left - 1][index][nxt] : 0) + tmp + k == dp[index][left][last][num]) {\n out.println((data[index][3] + 1) + \" \" + (tmp + k));\n left--;\n last = index;\n num = nxt;\n index++;\n continue;\n }\n }\n int nxt = (int) (tmp * k - data[index][0]);\n out.println((data[index][3] + 1) + \" \" + (tmp * k));\n left--;\n last = index;\n num = nxt;\n\n }\n index++;\n }\n } else {\n out.println(\"NO\");\n }\n out.close();\n }\n\n public static long cal(int index, int left, int last, int num, int m, long k, long[][] data) {\n if (left == 0) {\n if (index < m) {\n dp[index][left][last][num] = 0;\n }\n return 0;\n }\n if (m - index < left) {\n return -1;\n }\n\n if (dp[index][left][last][num] != -1) {\n return dp[index][left][last][num];\n }\n long result = -1;\n\n if (last == m) {\n int max = (int) (data[index][1] - data[index][0]);\n boolean[] check = new boolean[max + 1];\n for (int i = max; i >= 0; i--) {\n if (!set.contains(data[index][0] + i)) {\n set.add(data[index][0] + i);\n check[i] = true;\n }\n }\n for (int i = max; i >= 0; i--) {\n if (!check[i]) {\n continue;\n }\n // System.out.println((data[index][3] + 1) + \" \" + (data[index][0] + i));\n\n long v = cal(index + 1, left - 1, index, i, m, k, data);\n if (v != -1) {\n result = max(result, v + (long) i + data[index][0]);\n if (k == 1) {\n break;\n }\n }\n }\n } else if (data[last][2] < data[index][2]) {\n long tmp = data[last][0] + num;\n if (data[index][0] <= tmp + k && data[index][1] >= tmp + k) {\n long v = cal(index + 1, left - 1, index, (int) (tmp + k - data[index][0]), m, k, data);\n if (v != -1) {\n result = max(result, tmp + k + v);\n }\n }\n if (data[index][0] <= k * tmp && k * tmp <= data[index][1]) {\n long v = cal(index + 1, left - 1, index, (int) (tmp * k - data[index][0]), m, k, data);\n if (v != -1) {\n result = max(result, tmp * k + v);\n }\n }\n }\n result = Long.max(result, cal(index + 1, left, last, num, m, k, data));\n return dp[index][left][last][num] = result;\n\n }\n\n static long max(long a, long b) {\n return a > b ? a : b;\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "21cc6da7ed8d2f10e0c577bec6c2d711", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class C_Round_90 {\n\n public static long MOD = 1000000007;\n static long[][][][] dp;\n static HashSet set = new HashSet();\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 n = in.nextInt();\n int m = in.nextInt();\n int k = in.nextInt();\n long[][] data = new long[m][4];\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < 3; j++) {\n data[i][j] = in.nextLong();\n }\n data[i][3] = i;\n }\n Arrays.sort(data, new Comparator() {\n @Override\n public int compare(long[] a, long[] b) {\n return Long.compare(a[2], b[2]);\n }\n\n }\n );\n\n dp = new long[m][n + 1][m + 1][101];\n for (long[][][] a : dp) {\n for (long[][] b : a) {\n for (long[] c : b) {\n Arrays.fill(c, -1);\n }\n }\n }\n long v = cal(0, n, m, 0, m, k, data);\n // out.println(v);\n if(n == 39){\n System.out.println(\"HE HE\");\n }\n if (v != -1) {\n out.println(\"YES\");\n int index = 0;\n int left = n;\n int last = m;\n int num = 0;\n while (left > 0) {\n // System.out.println(index + \" \" + left + \" \" + last + \" \" + num + \" \" + (dp[index][left][last][num]));\n if (index + 1 < m && dp[index][left][last][num] == dp[index + 1][left][last][num]) {\n\n } else if (last == m) {\n for (int i = 0; i + data[index][0] <= data[index][1]; i++) {\n if (dp[index][left][last][num] == (long) i + data[index][0] + (index + 1 < m ? dp[index + 1][left - 1][index][i] : 0) && (index + 1 == m || dp[index + 1][left - 1][index][i] != -1)) {\n out.println((data[index][3] + 1) + \" \" + (data[index][0] + i));\n left--;\n last = index;\n num = i;\n break;\n }\n }\n } else {\n long tmp = data[last][0] + num;\n if (data[index][0] <= tmp + k && data[index][1] >= tmp + k) {\n int nxt = (int) (tmp + k - data[index][0]);\n if ((index + 1 == m || dp[index + 1][left - 1][index][nxt] != -1) && (index + 1 < m ? dp[index + 1][left - 1][index][nxt] : 0) + tmp + k == dp[index][left][last][num]) {\n out.println((data[index][3] + 1) + \" \" + (tmp + k));\n left--;\n last = index;\n num = nxt;\n index++;\n continue;\n }\n }\n int nxt = (int) (tmp * k - data[index][0]);\n out.println((data[index][3] + 1) + \" \" + (tmp * k));\n left--;\n last = index;\n num = nxt;\n\n }\n index++;\n }\n } else {\n out.println(\"NO\");\n }\n out.close();\n }\n\n public static long cal(int index, int left, int last, int num, int m, long k, long[][] data) {\n if (left == 0) {\n if (index < m) {\n dp[index][left][last][num] = 0;\n }\n return 0;\n }\n if (m - index < left) {\n return -1;\n }\n\n if (dp[index][left][last][num] != -1) {\n return dp[index][left][last][num];\n }\n long result = -1;\n\n if (last == m) {\n int max = (int) (data[index][1] - data[index][0]);\n boolean[] check = new boolean[max + 1];\n for (int i = max; i >= 0; i--) {\n if (!set.contains(data[index][0] + i)) {\n set.add(data[index][0] + i);\n check[i] = true;\n }\n }\n for (int i = max; i >= 0; i--) {\n if (!check[i]) {\n continue;\n }\n // System.out.println((data[index][3] + 1) + \" \" + (data[index][0] + i));\n\n long v = cal(index + 1, left - 1, index, i, m, k, data);\n if (v != -1) {\n result = max(result, v + (long) i + data[index][0]);\n if (k == 1) {\n break;\n }\n }\n }\n } else if (data[last][2] < data[index][2]) {\n long tmp = data[last][0] + num;\n if (data[index][0] <= tmp + k && data[index][1] >= tmp + k) {\n long v = cal(index + 1, left - 1, index, (int) (tmp + k - data[index][0]), m, k, data);\n if (v != -1) {\n result = max(result, tmp + k + v);\n }\n }\n if (data[index][0] <= k * tmp && k * tmp <= data[index][1]) {\n long v = cal(index + 1, left - 1, index, (int) (tmp * k - data[index][0]), m, k, data);\n if (v != -1) {\n result = max(result, tmp * k + v);\n }\n }\n }\n result = Long.max(result, cal(index + 1, left, last, num, m, k, data));\n return dp[index][left][last][num] = result;\n\n }\n\n static long max(long a, long b) {\n return a > b ? a : b;\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dd0bab49de4758e89322304cb9f83543", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner\npublic class Main{\npublic static void main(String[] args){\n Scanner sc=new Scanner();\n int arr={1,1,2,7,4};\n int min=Integer.Max_VALUE;\n for(int i=0;i<5;i++){\n int a=sc.nextInt();\n if(a/arr[i] a = new ArrayList<>();\n for (int i = p; i < n; i++) {\n if(i + sumDigits(i) == n) a.add(i);\n }\n if(a.size() == 0) System.out.println(0);\n else{\n System.out.println(a.size());\n for (Integer i : a) System.out.println(i);\n }\n }\n static int sumDigits(int n){\n int res= 0;\n while(n > 0){\n res += n % 10;\n n /= 10;\n }\n return res;\n }\n static int countOfDigits(int n){\n int res = 0;\n while (n > 0){\n n /= 10;\n res++;\n }\n return res;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a5794d99869b5a7a916977c289a1f92", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class Main {\n\n \n public static void main(String[] args) {\n Scanner leer = new Scanner(System.in);\n while (leer.hasNext()) { \n int n=leer.nextInt();\n int cont=0;\n int argNum[]=new int[n];\n int arg[]=new int[0];\n\t int sum=0;\n for (int i = 1; i < n-1; i++) {\n int k=i;\n arg=new int [(k+\"\").length()];\n\t\t sum=0;\n for (int j = 0; j < arg.length; j++) {\n arg[j]=Integer.parseInt((k+\"\").charAt(j)+\"\");\n sum+=arg[j];\n }\n if(k+sum==n){\n argNum[cont]=k;\n cont++;\n }\n }\n System.out.println(cont);\n for (int i = 0; i < 10; i++) {\n if(argNum[i]!=0){\n System.out.println(argNum[i]);\n }\n }\n }\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7ef5e033cf2fb0776a84acf0ebc510f8", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.sqrt;\nimport static java.lang.Math.ceil;\nimport static java.lang.System.out;\nimport static java.lang.Math.pow;\n\npublic class 875A {\n\tprivate static final int N=(int) 2e5+5; \n\tprivate static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\n\t\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tlong b=Integer.parseInt(br.readLine());\n\t\tsolve(b);\n\t}\n\tpublic static void solve(long b){\n\t\tArrayList list=new ArrayList();\n\t\tint sum;\n\t\tfor(long i=b;i>0;i--){\n\t\t\tif(i+810){\n\t\t\t\tsum+=x%10;x/=10;\n\t\t\t}\n\t\t\tif(sum == i) L[t++]=n-i;\n\t\t}\n\t\tSystem.out.println(t);\n\t\tfor(int i=t-1;i>=0;i--)\n\t\t\tSystem.out.println(L[i]);\n\t}\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "27eaa590c5354532d8a18eee44429860", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0} {"lang": "Java 8", "source_code": " import java.util.*; \n import java.math.*;\n import java.io.*;\n import java.text.DecimalFormat;\n import java.math.BigInteger;\n public class Main{\n //static int d=20;\n static long mod=1000000007 ;\n static HashMap hm=new HashMap<>(); \n static ArrayList> arr;\n static long[] dp1,dp2;\n static int[] a;\n static int[] vis,num;\n static long max;\n static int id;\n public static void main(String[] args) throws IOException {\n boolean online =false;\n String fileName = \"C-large-practice\";\n PrintWriter out; \n if (online) {\n s.init(new FileInputStream(new File(fileName + \".in\")));\n out= new PrintWriter(new FileWriter(fileName + \"out.txt\"));\n }\n else {\n s.init(System.in); \n \n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n }//r,b,y,g\n long n=s.nl();\n String k=s.ns();\n long ans=0;\n long pow=0;\n long last=k.length()-1;\n long mul=1;\n for(int i=k.length()-1;i>=0;i--){\n long x=k.charAt(i)-'0';\n long u=x*mul*pow3(10,last-i);\n long v=mul*n*x;\n if(u<=v){\n ans+=u;\n }\n else{\n ans+=v;\n mul*=n;\n last=i;\n }\n\n\n }\n out.println(ans);\n \n out.close();\n \n }\n public static long gcd(long a, long b){\n if (a == 0) return b;\n return gcd(b % a, a);\n }\n \n public static boolean check(long x){\n if(x%4==0 || x%7==0 || x%11==0)\n return true;\n if(x<4 || x<7 || x<11)\n return false;\n if(x%2==0){\n return check(x/2);\n }\n else\n return check(x/2) && check((x+1)/2);\n }\n public static int angle(int x1,int x2,int x3,int y1,int y2,int y3){\n long val=(y2-y1)*1L*(x3-x2)-(y3-y2)*1L*(x2-x1);\n if(val<0)\n return 1;\n else if(val>0)\n return -1;\n else\n return 0;\n }\n \n static class BIT{\n \n int N;\n int tree[];\n \n BIT(int N){\n this.N = N;\n tree = new int[N + 1];\n }\n \n void update(int idx){\n while(idx <= N){\n tree[idx]++;\n idx += (idx & -idx);\n }\n }\n \n int query(int l,int r){\n if(l == 1)\n return read(r);\n else\n return read(r) - read(l-1);\n }\n \n int read(int idx){\n int sum = 0;\n while(idx > 0){\n sum += tree[idx];\n idx -= (idx & -idx);\n }\n return sum;\n }\n }\n public static boolean pal(String a){\n int i=0;\n int j=a.length()-1;\n while(i0){\n if(b%2==1)\n ans=(a*ans)%mod;\n a=(a*a)%mod;\n b/=2;\n }\n return ans;\n }\n public static double pow3(long a,long b){\n long ans=1;\n while(b>0){\n if(b%2==1)\n ans=(a*ans);\n a=(a*a);\n b/=2;\n }\n return ans;\n }\n \n static class name implements Comparable {\n long l,b,h;\n public name(long x,long y,long z){\n {\n l=x;\n b=y;\n }\n \n \n h=z;\n }\n public int compareTo(name o){\n return -(int)(l*b-o.l*o.b);\n }\n \n }\n public static class s {\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 ns() 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 ni() throws IOException {\n return Integer.parseInt( ns() );\n }\n \n static double nd() throws IOException {\n return Double.parseDouble( ns() );\n }\n static long nl() throws IOException {\n return Long.parseLong( ns() );\n }\n }\n }\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e93884b32ee83fee8b2a3aa3d17d47f", "src_uid": "be66399c558c96566a6bb0a63d2503e5", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import com.sun.deploy.util.ArrayUtil;\n\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.io.*;\n\npublic class D {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) {\n return null;\n }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n char nextChar() throws IOException {\n return (char) (br.read());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n private void solve() throws IOException {\n int n = nextInt();\n String s = nextToken();\n if (n <= 10)\n {\n BigInteger bigInteger = new BigInteger(s, n);\n out.println(bigInteger.toString());\n return;\n }\n\n ArrayList integers = new ArrayList<>();\n StringBuilder sb = new StringBuilder();\n char[] c = s.toCharArray();\n\n int i = s.length() - 1;\n while (i >= 0)\n {\n int j;\n for (j = i - 1; j >= 0; j--) {\n int x = Integer.valueOf(s.substring(j, i + 1));\n if (x >= n) {\n do {\n j++;\n } while (j < i && s.charAt(j) == '0');\n break;\n }\n }\n j = Math.max(j, 0);\n integers.add(Integer.valueOf(s.substring(j, i + 1)));\n i = j - 1;\n }\n\n long ans = 0;\n for (int q = integers.size() - 1; q >= 0; q--) {\n ans = ans * n + integers.get(q);\n// System.err.println(integers.get(q));\n }\n out.println(ans);\n }\n\n void run() throws IOException {\n // br = new BufferedReader(new FileReader(\"input.txt\"));\n // out = new PrintWriter(\"output.txt\");\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n // Locale.setDefault(Locale.US);\n new D().run();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "651b776a3a8a16f5fb8288b796e35354", "src_uid": "be66399c558c96566a6bb0a63d2503e5", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport static com.sun.tools.javac.jvm.ByteCodes.ret;\n\npublic class Solution758D {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tokenizer = null;\n //Solution758A Code starts Here\n int totalCases, testnum;\n\n long n;\n String s;\n\n boolean input() throws IOException {\n n = nl();\n s = ns().trim();\n return true;\n }\n\n void solve() throws IOException {\n int l = s.length();\n int a = l-1, b = l;\n long m = 1;\n long ret = 0;\n while(b > 0) {\n while (a > -1) {\n String str = s.substring(a, b);\n long acc = Long.parseLong(str);\n if (acc >= n) {\n break;\n } else {\n a--;\n }\n }\n a++;\n while(s.charAt(a) == '0' && a < b-1) a++;\n long acc = Long.parseLong(s.substring(a, b));\n ret += (acc * m);\n m*=n;\n b=a--;\n }\n System.out.println(ret);\n }\n\n public static void main(String[] args) throws IOException {\n new Solution758D().execute();\n }\n\n void execute() throws IOException {\n totalCases = 1;\n for (testnum = 1; testnum <= totalCases; testnum++) {\n if (!input())\n break;\n solve();\n }\n }\n\n void debug(Object... os) {\n System.out.println(Arrays.deepToString(os));\n }\n\n int ni() throws IOException {\n return Integer.parseInt(ns());\n }\n\n long nl() throws IOException {\n return Long.parseLong(ns());\n }\n\n double nd() throws IOException {\n return Double.parseDouble(ns());\n }\n\n String ns() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(br.readLine());\n String s = tokenizer.nextToken();\n return s;\n }\n\n String nline() throws IOException {\n tokenizer = null;\n return br.readLine();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b25f20d20d73979c84a1d52ebdee1063", "src_uid": "be66399c558c96566a6bb0a63d2503e5", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "\n/**\n * @author Kunal\n *\n */\n\nimport java.io.PrintWriter;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\npublic class D392 {\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tfinal long start = System.currentTimeMillis();\n\t\tnew Task1().solve(in, out);\n\t\t@SuppressWarnings(\"unused\")\n\t\tfinal long duration = System.currentTimeMillis() - start;\n\t\tout.close();\n\t}\n\n\tstatic class Task1 {\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tlong base = in.nextLong();\n\t\t\tString s = in.next();\n\t\t\t\n\t\t\tlong ans=0, k=0;\n\t\t\tint i=s.length()-1;\n\t\t\twhile(i>=0){\n\t\t\t\tString nums=s.charAt(i)+\"\";\n\t\t\t\tLong num=Long.parseLong(s.charAt(i)+\"\"), temp=num;\n\t\t\t\t//out.print(num+\" \");\n\t\t\t\tint start = i;\n\t\t\t\tfor(int j=--i; j>=0; j--){\n\t\t\t\t\tnums=s.charAt(j)+nums;\n\t\t\t\t\ttemp = Long.parseLong(nums);\n\t\t\t\t\tif(temp=0) nums = nums.substring(1);\n\t\t\t\t//out.println(nums);\n\t\t\t\twhile(nums.length()>0 && nums.charAt(0)=='0'){\n\t\t\t\t\ti++;\n\t\t\t\t\tnums = nums.substring(1, nums.length());\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tans += expo(base, k++, Long.MAX_VALUE)*num;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(ans);\n\t\t}\n\t\t\n\t\tlong expo(long a, long b, long MOD){\n\t\t\tlong result = 1;\n\t\t\twhile (b>0){\n\t\t\t\tif (b%2==1) result=(result*a)%MOD;\n\t\t\t\tb>>=1;\n\t\t\t\ta=(a*a)%MOD;\n\t\t\t}\n\t\t\treturn result%MOD;\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader() {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tString s = null;\n\t\t\ttry {\n\t\t\t\ts = 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 s;\n\t\t}\n\n\t\tpublic String nextParagraph() {\n\t\t\tString line = null;\n\t\t\tString ans = \"\";\n\t\t\ttry {\n\t\t\t\twhile ((line = reader.readLine()) != null) {\n\t\t\t\t\tans += line;\n\t\t\t\t}\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "76ba7da78f3f6b696aeef8a4084c3973", "src_uid": "be66399c558c96566a6bb0a63d2503e5", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "public class A{\n \n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n \n System.out.println(2*n*(n-1) + 1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "44435e141c20e960c40d9da54e5214dd", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class abc\n{\npublic static void main(String[] args)\n{\n Scanner sc = new Scanner(System.in);\n int n =sc.nextInt();\n int dp[] = new int[n];\n dp[0]=1;\n int i =0;\n for(i =1;i 0){\n for (int i = 0; i < n; i++) {\n \n char ch = s.charAt(i);\n if (t > 0 && ch == 'x') {\n ch = 'X';\n t--;\n }\n s2 += ch;\n }\n }\n else \n if( t < 0){\n for (int i = 0; i < n; i++) {\n \n char ch = s.charAt(i);\n if (t < 0 && ch == 'X') {\n ch = 'x';\n t++;\n }\n s2 += ch;\n }\n }\n System.out.println(Math.abs((xcount - Xcount)/2));\n System.out.println(s2);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "848dc509f517cb30833d924074aedecf", "src_uid": "fa6311c72d90d8363d97854b903f849d", "difficulty": 900.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\nimport java.lang.*;\n\npublic class Solution\n{\n @SuppressWarnings(\"empty-statement\")\n public static void main(String[] args) throws Exception\n {\n Scanner sc=new Scanner(System.in); \n int q,st=0,sd=0,p;\n char v,w,c;\n String a;\n q=sc.nextInt();\n a=sc.next();\n char[] y=new char[q];\n v='X'; // \u0441\u0442\u043e\u0438\u0442\n w='x'; // \u0441\u0438\u0434\u0438\u0442\n for(int i=0;ib){ \n m=(a-b)/2; \n }\n else{\n m=(b-a)/2;\n } \n return m; \n }\n \n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4cf24615d1252f591f0d0ee961b13690", "src_uid": "fa6311c72d90d8363d97854b903f849d", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class lll {\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\tString ss = sc.next();\n\t\tint cnt = 0 , cnt2 = 0;\n\t\tfor(int i = 0 ; i < n ; i++)\n\t\t{\n\t\t\tif(ss.charAt(i) == 'X')\n\t\t\t\tcnt++;\n\t\t\telse\n\t\t\t\tcnt2++;\n\t\t}\n\t\tss.\n\t\tchar arr[] = ss.toCharArray();\n\t\tif(cnt > cnt2)\n\t\t{\n\t\t\tSystem.out.println((cnt-cnt2)/2);\n\t\t\tfor(int i = 0 ; i < (cnt-cnt2)/2 ; i++)\n\t\t\t{\n\t\t\t\tif(arr[i] == 'X')\n\t\t\t\t\tarr[i] = 'x';\n\t\t\t}\n\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println((cnt2-cnt)/2);\n\t\t\tfor(int i = 0 ; i < (cnt2-cnt)/2 ; i++)\n\t\t\t{\n\t\t\t\tif(arr[i] == 'x')\n\t\t\t\t\tarr[i] = 'X';\n\t\t\t}\n\n\t\t}\n\t\tfor(int i = 0 ; i < n ; i++)\n\t\t{\n\t\t\tSystem.out.print(arr[i]);\n\t\t}\n\n\n\t\t\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "870d6022f4d3ba29a762fb099ba665f5", "src_uid": "fa6311c72d90d8363d97854b903f849d", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n char[] chs = sc.next().toCharArray();\n int a = 0;\n for(char ch : chs) if(ch=='x') a++;\n int b=n-a;\n int c = a-b;\n int diff=Math.abs(c);\n for(int i=0; ib) {chs[i]=='X'; a--; b++;}\n else if(chs[i]='X'&&b>a) {chs[i]=='x'; b--; a++;}\n }\n System.out.println(diff);\n System.out.println(new String(chs));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f47932764dac7043f180275895e345a6", "src_uid": "fa6311c72d90d8363d97854b903f849d", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class ProblemB {\n\t\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint ans = 0;\n\t\tint counter = 0;\n\t\tint ya = 0;\n\t\twhile(true) {\n\t\t\tif(n%400 == 0 || (n%4 == 0 && n%100 != 0) {\n\t\t\t\tcounter += 2;\n\t\t\t\tya++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcounter ++ ;\n\t\t\t\tya++;\n\t\t\t}\n\t\t\tif(counter % 7 == 0) {\n\t\t\t\tans = n + ya;\n\t\t\t}\t\t\t\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e98887b3abbefa5829a508556f1411ab", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class ProblemB {\n\t\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint ans = 0;\n\t\tint counter = 0;\n\t\tint ya = 0;\n\t\twhile(true) {\n\t\t\tif(n%400 == 0 || (n%4 == 0 && n%100 != 0) {\n\t\t\t\tcounter += 2;\n\t\t\t\tya++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcounter ++ ;\n\t\t\t\tya++;\n\t\t\t}\n\t\t\tif(counter % 7 == 0) {\n\t\t\t\tans = n + ya;\n\t\t\t}\t\t\t\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "205cca70bf47541e027de39b0897ba6e", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\n@SuppressWarnings(\"unchecked\")\npublic class P678B {\n\n boolean isLeap(int y) {\n return ((((y % 4) == 0) && (y % 100) != 0) || ((y % 400) == 0));\n }\n\n public void run() throws Exception {\n println(y + (isLeap(y) ? 28 : 6));\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 P678B().run();\n br.close();\n pw.close();\n System.err.println(\"\\n[Time : \" + (System.currentTimeMillis() - startTime) + \" ms]\");\n }\n\n static long startTime = System.currentTimeMillis();\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { print(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n\n int gcd(int a, int b) {\n return ((b > 0) ? gcd(b, a % b) : a);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39741da1d13a2212ec48017b0070dcbd", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package codeforces.contest678;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\n\npublic class B {\n private static class Task {\n void solve(FastScanner in, PrintWriter out) {\n int y = in.nextInt();\n int y_origin = y;\n long days = 0;\n while (true) {\n days += 365;\n if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {\n days++;\n }\n y++;\n if (days % 7 == 0 && is_uruu(y) == is_uruu(y_origin)) {\n out.println(y);\n return;\n }\n\n }\n }\n\n boolean is_uruu(int y) {\n return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));\n }\n }\n\n public static void main(String[] args) {\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner();\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(in, out);\n out.close();\n }\n\n private static class FastScanner {\n private final InputStream in = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int bufferLength = 0;\n\n private boolean hasNextByte() {\n if (ptr < bufferLength) {\n return true;\n } else {\n ptr = 0;\n try {\n bufferLength = in.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (bufferLength <= 0) {\n return false;\n }\n }\n return true;\n }\n\n private int readByte() {\n if (hasNextByte()) return buffer[ptr++];\n else return -1;\n }\n\n private static boolean isPrintableChar(int c) {\n return 33 <= c && c <= 126;\n }\n\n private void skipUnprintable() {\n while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;\n }\n\n boolean hasNext() {\n skipUnprintable();\n return hasNextByte();\n }\n\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while (isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n long nextLong() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while (true) {\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n } else if (b == -1 || !isPrintableChar(b)) {\n return minus ? -n : n;\n } else {\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cc5fcbf951a9d93b5a34aacffc51921f", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package Problems;\n\nimport FastIO.Reader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class TaskA {\n public void solve(int testNumber, Reader in, PrintWriter out) {\n\n int[] p = new int[4];\n\n p[0] = in.nextInt();\n p[1] = in.nextInt();\n p[2] = in.nextInt();\n p[3] = in.nextInt();\n\n int a = in.nextInt();\n int b = in.nextInt();\n\n Arrays.sort(p);\n\n if (p[0] < a)\n out.println(0);\n else\n out.println(Math.abs(p[0] - a));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "17f321b2c19500be57c9ca05807b085c", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\n\nimport java.io.*;\npublic class Main \n{ \n static class Reader \n { \n final private int BUFFER_SIZE = 1 << 16; \n private DataInputStream din; \n private byte[] buffer; \n private int bufferPointer, bytesRead; \n \n public Reader() \n { \n din = new DataInputStream(System.in); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public Reader(String file_name) throws IOException \n { \n din = new DataInputStream(new FileInputStream(file_name)); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public String readLine() throws IOException \n { \n byte[] buf = new byte[64]; // line length \n int cnt = 0, c; \n while ((c = read()) != -1) \n { \n if (c == '\\n') \n break; \n buf[cnt++] = (byte) c; \n } \n return new String(buf, 0, cnt); \n } \n \n public int nextInt() throws IOException \n { \n int ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do\n { \n ret = ret * 10 + c - '0'; \n } while ((c = read()) >= '0' && c <= '9'); \n \n if (neg) \n return -ret; \n return ret; \n } \n \n public long nextLong() throws IOException \n { \n long ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n if (neg) \n return -ret; \n return ret; \n } \n \n public double nextDouble() throws IOException \n { \n double ret = 0, div = 1; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n \n if (c == '.') \n { \n while ((c = read()) >= '0' && c <= '9') \n { \n ret += (c - '0') / (div *= 10); \n } \n } \n \n if (neg) \n return -ret; \n return ret; \n } \n \n private void fillBuffer() throws IOException \n { \n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); \n if (bytesRead == -1) \n buffer[0] = -1; \n } \n \n private byte read() throws IOException \n { \n if (bufferPointer == bytesRead) \n fillBuffer(); \n return buffer[bufferPointer++]; \n } \n \n public void close() throws IOException \n { \n if (din == null) \n return; \n din.close(); \n } \n } \n\tstatic long gcd(long n,long m) {\n\t\tif(n==0&&m==0)return Long.MAX_VALUE;\n\t\tif(n==0)return m;\n\t\tlong temp=m%n;\n\t\treturn gcd(temp,n);\n\t}\n\tstatic long pow(int i,int j) {\n\t\treturn ((long)Math.pow(i,j));\n\t}\n\tstatic long pow(long x,long j) {\n\t\tfor(int i=0;i<32;i++) {\n\t\t\tlong temp=1;\n\t\t\tfor(int w=0;w2147483648l)return 1;\n\t\t\telse \n\t\t\tif(!neg&&temp>2147483647)return 1;\n\t\t\t//pw.println(j);\n\t\t\tif(neg&&temp==j&&i%2!=0)return i;\n\t\t\tif(!neg&&temp==j)return i;\n\t\t}\n\t\treturn 1;\n\t}\n\tstatic trouble ex_gcd(long m,long n) {\n\t\tif(m==0) {\n\t\t\tif(n!=0)\n\t\t\treturn (new trouble(0,1,n));\n\t\t\treturn(new trouble(0,1,(long)1e9));\n\t\t}\n\t\ttrouble temp=ex_gcd(n%m,m);\n\t\tlong r=temp.x;\n\t\tlong m_=temp.y;\n\t\ttemp.x=(-1*n/m)*r+m_;\n\t\ttemp.y=r;\n\t\treturn temp;\n\t}\n\t static class pair{\n\t \tlong x;\n\t \tlong y;\n\t \tpair(long i,long j){\n\t \t\tx=i;\n\t \t\ty=j;\n\t \t}\n\t }\n\t static String toString(trouble p) {\n \t\treturn (p.x)+\" \"+(p.y)+\" \"+p.z;\n \t}\n\t static class trouble{\n\t \tlong x;\n\t \tlong y;\n\t \tlong z;\n\t \ttrouble(long i,long j,long k){\n\t \t\tx=i;\n\t \t\ty=j;\n\t \t\tz=k;\n\t \t}\n\t }\n\tstatic LinkedList div(int x){\n\t\tLinkedListarr =new LinkedList<>();\n for(int i=1;i*i<=x;i++) {\n \tif(x%i==0) {arr.add(i);if(x/i!=i)arr.add(x/i);}\n }\n return arr;\n\t}\n\tstatic long bin(long i,long[] arr) {\n\t\tlong l=0l;\n\t\tlong r=Math.min(i+2,arr.length-1);\n\t\tlong res=r;\n\t\twhile(l<=r) {\n\t\t\tlong mid=l+r>>1;\n\t\t if(arr[(int)mid]>=i) {\n\t\t \tr=mid-1;res=mid;\n\t\t }\n\t\t else l=mid+1;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic PrintWriter pw=new PrintWriter(System.out);\n public static void main(String[] args) throws IOException,Exception\n { \n // \tThread.sleep(3000);\n Reader sc=new Reader();\n //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int b0,b1,b2,b3,b4,a,b;\n b0=sc.nextInt();\n b1=sc.nextInt();\n b2=sc.nextInt();\n b3=sc.nextInt();\n a=sc.nextInt();\n b=sc.nextInt();\n int[][]arr= {{ b0,b1,b2,b3 },{ b0,b1,b3,b2 },{ b0,b2,b1,b3 },{ b0,b2,b3,b1 },{ b0,b3,b1,b2 },{ b0,b3,b2,b1 },{ b1,b0,b2,b3 },{ b1,b0,b3,b2 },{ b1,b2,b0,b3 },{ b1,b2,b3,b0 },{ b1,b3,b0,b2 },{ b1,b3,b2,b0 },{ b2,b0,b1,b3 },{ b2,b0,b3,b1 },{ b2,b1,b0,b3 },{ b2,b1,b3,b0 },{ b2,b3,b0,b1 },{ b2,b3,b1,b0 },{ b3,b0,b1,b2 },{ b3,b0,b2,b1 },{ b3,b1,b0,b2 },{ b3,b1,b2,b0 },{ b3,b2,b0,b1 },{ b3,b2,b1,b0 }};\n int res=0;\n for(int i=a;i=7) {\n \t res+=1;\n }\n }\n pw.println(res);\n pw.close();\n } \n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "293c0d277dffcd4f3fe9bc1966c63f1d", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\n\nimport java.io.*;\npublic class Main \n{ \n static class Reader \n { \n final private int BUFFER_SIZE = 1 << 16; \n private DataInputStream din; \n private byte[] buffer; \n private int bufferPointer, bytesRead; \n \n public Reader() \n { \n din = new DataInputStream(System.in); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public Reader(String file_name) throws IOException \n { \n din = new DataInputStream(new FileInputStream(file_name)); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public String readLine() throws IOException \n { \n byte[] buf = new byte[64]; // line length \n int cnt = 0, c; \n while ((c = read()) != -1) \n { \n if (c == '\\n') \n break; \n buf[cnt++] = (byte) c; \n } \n return new String(buf, 0, cnt); \n } \n \n public int nextInt() throws IOException \n { \n int ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do\n { \n ret = ret * 10 + c - '0'; \n } while ((c = read()) >= '0' && c <= '9'); \n \n if (neg) \n return -ret; \n return ret; \n } \n \n public long nextLong() throws IOException \n { \n long ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n if (neg) \n return -ret; \n return ret; \n } \n \n public double nextDouble() throws IOException \n { \n double ret = 0, div = 1; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n \n if (c == '.') \n { \n while ((c = read()) >= '0' && c <= '9') \n { \n ret += (c - '0') / (div *= 10); \n } \n } \n \n if (neg) \n return -ret; \n return ret; \n } \n \n private void fillBuffer() throws IOException \n { \n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); \n if (bytesRead == -1) \n buffer[0] = -1; \n } \n \n private byte read() throws IOException \n { \n if (bufferPointer == bytesRead) \n fillBuffer(); \n return buffer[bufferPointer++]; \n } \n \n public void close() throws IOException \n { \n if (din == null) \n return; \n din.close(); \n } \n } \n\tstatic long gcd(long n,long m) {\n\t\tif(n==0&&m==0)return Long.MAX_VALUE;\n\t\tif(n==0)return m;\n\t\tlong temp=m%n;\n\t\treturn gcd(temp,n);\n\t}\n\tstatic long pow(int i,int j) {\n\t\treturn ((long)Math.pow(i,j));\n\t}\n\tstatic long pow(long x,long j) {\n\t\tfor(int i=0;i<32;i++) {\n\t\t\tlong temp=1;\n\t\t\tfor(int w=0;w2147483648l)return 1;\n\t\t\telse \n\t\t\tif(!neg&&temp>2147483647)return 1;\n\t\t\t//pw.println(j);\n\t\t\tif(neg&&temp==j&&i%2!=0)return i;\n\t\t\tif(!neg&&temp==j)return i;\n\t\t}\n\t\treturn 1;\n\t}\n\tstatic trouble ex_gcd(long m,long n) {\n\t\tif(m==0) {\n\t\t\tif(n!=0)\n\t\t\treturn (new trouble(0,1,n));\n\t\t\treturn(new trouble(0,1,(long)1e9));\n\t\t}\n\t\ttrouble temp=ex_gcd(n%m,m);\n\t\tlong r=temp.x;\n\t\tlong m_=temp.y;\n\t\ttemp.x=(-1*n/m)*r+m_;\n\t\ttemp.y=r;\n\t\treturn temp;\n\t}\n\t static class pair{\n\t \tlong x;\n\t \tlong y;\n\t \tpair(long i,long j){\n\t \t\tx=i;\n\t \t\ty=j;\n\t \t}\n\t }\n\t static String toString(trouble p) {\n \t\treturn (p.x)+\" \"+(p.y)+\" \"+p.z;\n \t}\n\t static class trouble{\n\t \tlong x;\n\t \tlong y;\n\t \tlong z;\n\t \ttrouble(long i,long j,long k){\n\t \t\tx=i;\n\t \t\ty=j;\n\t \t\tz=k;\n\t \t}\n\t }\n\tstatic LinkedList div(int x){\n\t\tLinkedListarr =new LinkedList<>();\n for(int i=1;i*i<=x;i++) {\n \tif(x%i==0) {arr.add(i);if(x/i!=i)arr.add(x/i);}\n }\n return arr;\n\t}\n\tstatic long bin(long i,long[] arr) {\n\t\tlong l=0l;\n\t\tlong r=Math.min(i+2,arr.length-1);\n\t\tlong res=r;\n\t\twhile(l<=r) {\n\t\t\tlong mid=l+r>>1;\n\t\t if(arr[(int)mid]>=i) {\n\t\t \tr=mid-1;res=mid;\n\t\t }\n\t\t else l=mid+1;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic PrintWriter pw=new PrintWriter(System.out);\n public static void main(String[] args) throws IOException,Exception\n { \n // \tThread.sleep(3000);\n Reader sc=new Reader();\n //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int b0,b1,b2,b3,b4,a,b;\n b0=sc.nextInt();\n b1=sc.nextInt();\n b2=sc.nextInt();\n b3=sc.nextInt();\n a=sc.nextInt();\n b=sc.nextInt();\n int[][]arr= {{ b0,b1,b2,b3 },{ b0,b1,b3,b2 },{ b0,b2,b1,b3 },{ b0,b2,b3,b1 },{ b0,b3,b1,b2 },{ b0,b3,b2,b1 },{ b1,b0,b2,b3 },{ b1,b0,b3,b2 },{ b1,b2,b0,b3 },{ b1,b2,b3,b0 },{ b1,b3,b0,b2 },{ b1,b3,b2,b0 },{ b2,b0,b1,b3 },{ b2,b0,b3,b1 },{ b2,b1,b0,b3 },{ b2,b1,b3,b0 },{ b2,b3,b0,b1 },{ b2,b3,b1,b0 },{ b3,b0,b1,b2 },{ b3,b0,b2,b1 },{ b3,b1,b0,b2 },{ b3,b1,b2,b0 },{ b3,b2,b0,b1 },{ b3,b2,b1,b0 }};\n int res=0;\n for(int i=a;i<=b;i++) {\n int c=0;\n for(int j=0;j<24;j++) {\n \t if(i%arr[j][0]%arr[j][1]%arr[j][2]%arr[j][3]==i)c++;\n }\n if(c>=7) {\n \t res+=1;\n }\n }\n pw.println(res);\n pw.close();\n } \n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "53199f04416d6fc7c69d31a346956b47", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\n\npublic class A_62 {\n\n public static void main(String[] args) {\n try {\n java.io.BufferedReader stdin = new java.io.BufferedReader(\n new java.io.InputStreamReader(System.in));\n String line;\n\n line = stdin.readLine();\n\n String[] numbers = line.split(\" \");\n int p1 = Integer.parseInt(numbers[0]);\n int p2 = Integer.parseInt(numbers[1]);\n int p3 = Integer.parseInt(numbers[2]);\n int p4 = Integer.parseInt(numbers[3]);\n int a = Integer.parseInt(numbers[4]);\n int b = Integer.parseInt(numbers[5]);\n\n int min = Math.min(p1, Math.min(p2, Math.min(p3, p4)));\n if (a < min) {\n System.out.println(min - a);\n } else {\n System.out.println(\"0\");\n }\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6b34dbe2c3d270f4f76d973fc4f0f1f0", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class B {\n static int cost[][]=new int[3][3];\n public static void main(String cd[]){\n Scanner in=new Scanner(System.in);\n for(int i=0;i<3;i++){\n for(int j=0;j<3;j++){\n cost[i][j]=in.nextInt();\n }\n }\n int n=in.nextInt(); \n int dp[][][] =new int[3][3][n+1];\n for(int k=1;k c - '0').toArray();\n if (toDirection(m, UP) || toDirection(m, DOWN) || toDirection(m, LEFT) || toDirection(m, RIGHT)) {\n System.out.println(\"NO\");\n } else {\n System.out.println(\"YES\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "44316511bbcf7f95ce995706e680d720", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n private static Scanner reader = new Scanner(System.in);\n\n private static String move(String in, int i) {\n String oup = \"\";\n if (i == 0) {\n for (int j = 0; j < in.length(); j++) {\n char p = in.charAt(j);\n if (p == '0')\n oup += '8';\n else\n oup += (char) (p - 3);\n }\n } else if (i == 1) {\n for (int j = 0; j < in.length(); j++) {\n char p = in.charAt(j);\n if (p == '0')\n oup += 'X';\n else if (p == '8')\n outp += '8';\n else\n oup += (char) (p + 3);\n }\n } else if (i == 2) {\n for (int j = 0; j < in.length(); j++) {\n char p = in.charAt(j);\n if (p == '3' || p == '6' || p == '9' || p == '0')\n oup += 'X';\n else\n oup += (char) (p + 1);\n }\n } else if (i == 3) {\n for (int j = 0; j < in.length(); j++) {\n char p = in.charAt(j);\n if (p == '1' || p == '4' || p == '7' || p == '0')\n oup += 'X';\n else\n oup += (char) (p - 1);\n ;\n }\n }\n return oup;\n }\n\n public static void main(String[] args) {\n int n = reader.nextInt();\n String s = reader.next();\n for (int i = 0; i < 4; i++) {\n boolean flag = true;\n String m = move(s, i);\n for (int j = 0; j < m.length(); j++) {\n char p = m.charAt(j);\n if (!Character.isDigit(p)) {\n flag = false;\n break;\n }\n }\n if (flag) {\n System.out.print(\"NO\");\n return;\n }\n }\n System.out.print(\"YES\");\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "faedda2d48ff5a887eeb2194df1d319e", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\tMyScanner sc = new MyScanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n=sc.nextInt();\n\t\tString s=sc.nextLine();\n\t\tboolean []c=new boolean[10];\n\t\tfor(int i=0;i= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public String readString() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0387b551c0b8edc374c22ca9403402f7", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class D {\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n InputReader in=new InputReader(System.in);\n long x0=in.nextLong();long y0=in.nextLong();\n long ax=in.nextLong();long ay=in.nextLong();\n long bx=in.nextLong();long by=in.nextLong();\n long x=in.nextLong(),y=in.nextLong();\n long t=in.nextLong();\n List position=new ArrayList<>();\n int minindex=0;\n long min=Math.abs(x0-x)+Math.abs(y0-y);\n position.add(new long[]{x0,y0});\n x0=x0*ax+bx;\n y0=y0*ay+by;\n while ((Math.abs(x0-position.get(0)[0])+Math.abs(y0-position.get(0)[1]))<=1e16){\n position.add(new long[]{x0,y0});\n long temp=Math.abs(x0-x)+Math.abs(y0-y);\n if(temp pts;\n private static boolean[] taken;\n private static int ans;\n private static long T;\n private static boolean btwn(long x, long a, long b) {\n return Math.min(a,b)<=x && x<=Math.max(a,b);\n }\n private static long dist(long[] a, long[] b) {\n return Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]);\n }\n private static void find(int id, int cnt, long time) {\n //System.err.println(id+\" \"+cnt+\" \"+time);\n if (time>T)\n return;\n ans=Math.max(ans,cnt);\n taken[id]=true;\n for (int i=0; iT-d)\n continue;\n find(i,cnt+1,time+d);\n }\n taken[id]=false;\n }\n public static void main(String[] args) throws Exception {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tok = new StringTokenizer(in.readLine());\n long x0=Long.parseLong(tok.nextToken()),\n y0=Long.parseLong(tok.nextToken()),\n ax=Long.parseLong(tok.nextToken()),\n ay=Long.parseLong(tok.nextToken()),\n bx=Long.parseLong(tok.nextToken()),\n by=Long.parseLong(tok.nextToken());\n tok=new StringTokenizer(in.readLine());\n long xs=Long.parseLong(tok.nextToken()),\n ys=Long.parseLong(tok.nextToken());\n T=Long.parseLong(tok.nextToken());\n /*\n if for som i x_i>2^63-1\n max xs=10^16\n x_i-xs>10^16>t\n */\n pts=new ArrayList<>();\n for (long x=x0, y=y0; true;) {\n pts.add(new long[] {x,y});\n //System.out.println(Arrays.toString(new long[] {x,y}));\n if (x>(double)(Long.MAX_VALUE-bx)/ax\n || y>(double)(Long.MAX_VALUE-by)/ay)\n break;\n x=ax*x+bx;\n y=ay*y+by;\n }\n taken=new boolean[pts.size()];\n ans=0;\n for (int i=0; iLong.MAX_VALUE-dy)\n bad[i]=true;\n else\n cost[i] = dx+dy;\n }\n List front=new ArrayList<>();\n for (int i=0; i0) {\n\n }*/\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3d80fde7de3c10c665d4e5bbd441a366", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0} {"lang": "Java 8", "source_code": " import java.io.*;\n import java.util.*;\n \n public class AromaSearch {\n \tpublic static void main(String[] args) throws IOException {\n \t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \t\tString[] line = br.readLine().split(\" \");\n \t\tlong x0 = Long.parseLong(line[0]);\n \t\tlong y0 = Long.parseLong(line[1]);\n \t\tint ax = Long.parseLong(line[2]);\n \t\tint ay = Long.parseLong(line[3]);\n \t\tlong bx = Long.parseLong(line[4]);\n \t\tlong by = Long.parseLong(line[5]);\n \t\tline = br.readLine().split(\" \");\n \t\tlong sx = Long.parseLong(line[0]);\n \t\tlong sy = Long.parseLong(line[1]);\n \t\tlong t = Long.parseLong(line[2]);\n \t\tArrayList xs = new ArrayList();\n \t\tArrayList ys = new ArrayList();\n \t\tArrayList dist = new ArrayList();\n \t\txs.add(x0);\n \t\tys.add(y0);\n \t\tdist.add((long) 0);\n \t\tlong ttemp = t;\n \t\twhile (true) {\n \t\t\tlong tx = x0;\n \t\t\tlong ty = y0;\n \t\t\tx0 *= ax;\n \t\t\tx0 += bx;\n \t\t\ty0 *= ay;\n \t\t\ty0 += by;\n \t\t\tlong d = x0-tx+y0-ty;\n \t\t\txs.add(x0);\n \t\t\tys.add(y0);\n \t\t\tdist.add(dist.get(dist.size() - 1)+d);\n \t\t\tttemp -= d;\n \t\t\tif (ttemp <= 0) {\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n \t\tlong ans = 0;\n \t\tfor (int i = 0; i < xs.size(); i++) {\n \t\t\tlong cx = xs.get(i);\n \t\t\tlong cy = ys.get(i);\n \t\t\tttemp = t-dist(sx, sy, cx, cy);\n \t\t\tlong tans = 0;\n \t\t\tif (ttemp <= 0) {\n \t\t\t\ttans = 0;\n \t\t\t} else if (ttemp >= dist.get(i)) {\n \t\t\t\tttemp -= dist.get(i);\n \t\t\t\ttans = i+1;\n \t\t\t\tfor (int j = i+1; j < xs.size(); j++) {\n \t\t\t\t\tif (ttemp <= dist.get(j)) {\n \t\t\t\t\t\ttans = j;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t} else {\n \t\t\t\tfor (int j = i; j >= 0; j--) {\n \t\t\t\t\tif (ttemp <= dist.get(i) - dist.get(j)) {\n \t\t\t\t\t\ttans = i-j+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\tans = Long.max(tans, ans);\n \t\t}\n \t\tSystem.out.println(ans);\n \t}\n \tstatic long dist(long x1, long y1, long x2, long y2) {\n \t\treturn Math.abs(x1-x2) + Math.abs(y1-y2);\n \t}\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "99696edfd857a14bc18096476951eec8", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main {\n \n\tpublic static void main (String[] args) {\n\t Scanner s = new Scanner(System.in);\n\t\tlong x0 = s.nextLong();\n\t\tlong y0 = s.nextLong();\n\t\tlong ax = s.nextLong();\n\t\tlong ay = s.nextLong();\n\t\tlong bx = s.nextLong();\n\t\tlong by = s.nextLong();\n\t\tlong xs = s.nextLong();\n\t\tlong ys = s.nextLong();\n\t\tlong t = s.nextLong();\n\t\tArrayList x = new ArrayList<>();\n\t\tArrayList y = new ArrayList<>();\n\t\tlong temp = Math.abs(xs-x0) + Math.abs(ys-y0);\n\t\tx.add(x0);\n\t\ty.add(y0);\n\t\tlong LIMIT = ((long)1 << 62) - 1;\n\t\tint n = x.size();\n\t\twhile ((LIMIT - bx) / ax >= x.get(n - 1) && (LIMIT - by) / ay >= y.get(n - 1)) {\n\t\t\tx.add(ax * x.get(n - 1) + bx); y.add(ay * y.get(n - 1) + by); n++;\n\t\t}\n\t\tint answer = 0;\n\t\tint size = x.size();\n\t\tlong[][] dp = new long[size][size];\n\t\tfor(int l=0;lanswer)\n\t\t answer = z;\n\t\t }\n\t\t }\n\t\t else\n\t\t {\n\t\t //dp[l][r] = dp[l][l+1] + dp[l+1][r];\n\t\t //if((r-l)==1)\n\t\t //{\n\t\t dp[l][r] = x.get(r)-x.get(l) + y.get(r) - y.get(l);\n\t\t //}\n\t\t long yy = Math.min( Math.abs(xs-x.get(l)) + Math.abs(ys-y.get(l)) , \n\t\t Math.abs(xs-x.get(r)) + Math.abs(ys-y.get(r)) )+ \n\t\t \n\t\t if(yy <=(t-dp[l][r]))\n\t\t {\n\t\t int z = r-l+1;\n\t\t if(z>answer)\n\t\t answer = z;\n\t\t }\n\t\t }\n\t\t }\n\t\t}\n\t\tSystem.out.println(answer);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0877901ba05fa09351ea586f3cab3dfb", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.NoSuchElementException;\nimport java.util.Objects;\nimport java.util.PriorityQueue;\nimport java.util.Stack;\nimport java.util.TreeSet;\npublic class Main{\n\tstatic boolean prime[];\n\tstatic boolean checked[];\n\tpublic static void main(String[] args){\n\t\tFastScanner sc = new FastScanner();\n\t\tMathplus mp = new Mathplus();\n\t\tprime = new boolean[100001];\n\t\tchecked = new boolean[100001];\n\t\tfor(int i=0;i<=100000;i++){\n\t\t\tchecked[i] = false;\n\t\t}\n\t\tArrayList[] set =new ArrayList[100001];\n\t\tfor(int i=0;i<=100000;i++){\n\t\t\tset[i] =new ArrayList();\n\t\t}\n\t\tfor(int i=100000;i>=1;i--){\n\t\t\tfor(int j=1;j<=100000;j++){\n\t\t\t\tif(i*j>100000)break;\n\t\t\t\tset[i*j].add(i);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint M = sc.nextInt();\n\t\tlong[] dp = new long[M+1];\n\t\tdp[1] = 1;\n\t\tint mod =1000000007;\n\t\tfor(int i=2;i<=M;i++){\n\t\t\tlong tmp = 0;\n\t\t\t\n\t\t\tint[] num = new int[i+1];\n\t\t\t\n\t\t\tfor(int e:set[i]){\n\n\t\t\t\tint n = M / e;\n\t\t\t\tn += num[e];\n\t\t\t\tfor(int f:set[e]){\n\t\t\t\t\tif(e!=f){\n\t\t\t\t\t\tnum[f] -= n;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(e!=i){\n\t\t\t\t\ttmp += dp[e] * n % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\t\ttmp+= M;\n\t\t\ttmp %= mod;\n\t\t\ttmp *= mp.rev(M-(M/i));\n\t\t\tdp[i] = tmp%mod;\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i=1;i<=M;i++){\n\t\t\tans += dp[i];\n\t\t}\n\t\tans %= mod;\n\t\tSystem.out.println(ans*mp.rev(M)%mod);\n\t\t\n\t}\n\t\n\tstatic boolean isprime(int a){\n\t\tif(a==1)return false;\n\t\tif(checked[a]) return prime[a];\n\t\tchecked[a] = true;\n\t\tfor(int i=2;i*i<=a;i++){\n\t\t\tif(a%i==0){\n\t\t\t\treturn prime[a] =false;\n\t\t\t}\n\t\t}\n\t\treturn prime[a] = true;\n\t}\n\n\n\n}\n\n\nclass UnionFindTree {\n\tint[] root;\n\tint[] rank;\n\n\tUnionFindTree(int N){\n\t\troot = new int[N];\n\t\trank = new int[N];\n\t\tfor(int i=0;i[] list;\n\tint size;\n\tTreeSet Edges = new TreeSet(new LinkEdgeComparator());\n\t@SuppressWarnings(\"unchecked\")\n\tGraph(int N){\n\t\tsize = N;\n\t\tlist = new ArrayList[N];\n\t\tfor(int i=0;i();\n\t\t}\n\t}\n\n\tvoid addEdge(int a,int b){\n\t\tlist[a].add(new Edge(b,1));\n\t}\n\n\tvoid addWeightedEdge(int a,int b,int c){\n\t\tlist[a].add(new Edge(b,c));\n\t}\n\n\tvoid addEgdes(int[] a,int[] b){\n\t\tint size = a.length;\n\t\tfor(int i=0;i Q = new ArrayDeque();\n\t\tQ.add(s);\n\n\t\twhile(!Q.isEmpty()){\n\t\t\tint v = Q.poll();\n\t\t\tfor(Edge e:list[v]){\n\t\t\t\tint w = e.to;\n\t\t\t\tlong c = e.cost;\n\t\t\t\tif(L[w]==-1){\n\t\t\t\t\tL[w] = L[v] + c;\n\t\t\t\t\tQ.add(w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn L;\n\t}\n\n\tlong[] dijkstra(int s){\n\t\tlong[] L = new long[size];\n\t\tfor(int i=0;i Q = new PriorityQueue(new SampleComparator());\n\t\tQ.add(new Pair(0,s));\n\n\t\twhile(!Q.isEmpty()){\n\n\t\t\tPair C = Q.poll();\n\t\t\tif(visited[(int)C.b]==0){\n\t\t\t\tL[(int)C.b] = C.a;\n\t\t\t\tvisited[(int) C.b] = 1;\n\t\t\t\tfor(Edge D:list[(int) C.b]){\n\t\t\t\t\tQ.add(new Pair(L[(int)C.b]+D.cost,D.to));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn L;\n\t}\n\tlong Kruskal(){\n\t\tlong ans = 0;\n\n\t\tUnionFindTree UF = new UnionFindTree(size);\n\t\tfor(LinkEdge e:Edges){\n\t\t\tif(!UF.same(e.a,e.b)){\n\t\t\t\tans += e.L;\n\t\t\t\tUF.unite(e.a,e.b);\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}\n\t\n}\n\n\nclass LinkEdge{\n\tlong L;\n\tint a ;\n\tint b;\n\tLinkEdge(long l,int A,int B){\n\t\tL = l;\n\t\ta = A;\n\t\tb = B;\n\t}\n\tpublic boolean equals(Object o){\n\t\tLinkEdge O = (LinkEdge) o;\n\t\tif(O.a==this.a&&O.b==this.b&&O.L==this.L){\n\t\t\treturn true;\n\t\t}else{\n\t\t\treturn false;\n\t\t}\n\n\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(L,a,b);\n\t}\n\n}\n\nclass Edge{\n\tint to;\n\tlong cost;\n\n\tEdge(int a,long b){\n\t\tto = a;\n\t\tcost = b;\n\t}\n\n}\nclass LinkEdgeComparator implements Comparator{\n\tpublic int compare(LinkEdge P, LinkEdge Q) {\n\t\tlong temp = P.L-Q.L;\n\t\tif(temp==0){\n\t\t\tif(P.a>Q.a){\n\t\t\t\treturn 1;\n\t\t\t}else{\n\t\t\t\tif(P.b>Q.b){\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}\n\n\t\t}\n\t\tif(temp>=0){\n\t\t\treturn 1;\n\t\t}else{\n\t\t\treturn -1;\n\t\t}\n\t}\n\n}\nclass Pair{\n\tlong a;\n\tlong b;\n\n\tPair(long p,long q){\n\t\tthis.a = p;\n\t\tthis.b = q;\n\t}\n\n\tpublic boolean equals(Object o){\n\t\tPair O = (Pair) o;\n\t\tif(O.a==this.a&&O.b==this.b){\n\t\t\treturn true;\n\t\t}else{\n\t\t\treturn false;\n\t\t}\n\n\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b);\n\t}\n\n}\n\nclass SampleComparator implements Comparator{\n\tpublic int compare(Pair P, Pair Q) {\n\t\tlong temp = P.a-Q.a;\n\t\tif(temp==0){\n\t\t\tif(P.b>Q.b){\n\t\t\t\treturn 1;\n\t\t\t}else{\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t}\n\t\tif(temp>=0){\n\t\t\treturn 1;\n\t\t}else{\n\t\t\treturn -1;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n private final java.io.InputStream in = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int buflen = 0;\n private boolean hasNextByte() {\n if (ptr < buflen) {\n return true;\n }else{\n ptr = 0;\n try {\n buflen = in.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (buflen <= 0) {\n return false;\n }\n }\n return true;\n }\n private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}\n public boolean hasNext() { skipUnprintable(); return hasNextByte();}\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while(isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n public long nextLong() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b)){\n return (minus ? -n : n);\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n public int nextInt() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b)){\n return (int) (minus ? -n : n);\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n}\n\nclass Mathplus{\n\tint mod = 1000000007;\n\tlong[] fac = new long[1000001];\n\tboolean isBuild = false;\n\tint mindex = -1;\n\tint maxdex = -1;\n\n\n\tvoid buildFac(){\n\t\tfac[0] = 1;\n\t\tfor(int i=1;i<=1000000;i++){\n\t\t\tfac[i] = (fac[i-1] * i)%mod;\n\t\t}\n\t\tisBuild = true;\n\t}\n\tlong max(long[] a){\n\t\tlong max = 0;\n\t\tfor(int i=0;ia[i]){\n\t\t\t\tmin =a[i];\n\t\t\t\tmindex = i;\n\t\t\t}\n\t\t}\n\t\treturn min;\n\t}\n\tint min(int[] a){\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor(int i=0;ia[i]){\n\t\t\t\tmin =a[i];\n\t\t\t\tmindex = i;\n\t\t\t}\n\t\t}\n\t\treturn min;\n\t}\n\tlong sum(long[] a){\n\t\tlong sum = 0;\n\t\tfor(int i=0;i> 1);\n return a * pow(a * a % mod, b >> 1) % mod;\n }\n\n long inv(long a) {\n return pow(a , mod - 2);\n }\n\n long val() {\n return a * inv(b) % mod;\n }\n }\n\n int mod = 1_000_000_007;\n int[] factors;\n int[] phi;\n List primes;\n Map[] factor;\n int m;\n public void sieve() {\n int M = 100010;\n factors = new int[M];\n phi = new int[M];\n phi[1] = 1;\n primes = new ArrayList<>();\n for (int i = 2; i < M; i++) {\n if (factors[i] == 0) {\n factors[i] = i;\n primes.add(i);\n phi[i] = i - 1;\n }\n for (int j : primes) {\n int v = j * i;\n if (v >= M) break;\n factors[v] = j;\n if (i % j == 0) {\n phi[v] = phi[i] * j;\n break;\n } else {\n phi[v] = phi[i] * phi[j];\n }\n }\n }\n factor = new Map[M];\n for (int i = 1; i < M; i++) {\n factor[i] = factorize(i);\n }\n }\n\n public Map factorize(int t) {\n Map factor = new HashMap<>();\n while (t != 1) {\n int f = factors[t];\n int cnt = 0;\n while (t % f == 0) {\n t /= f;\n cnt ++;\n }\n factor.put(f, cnt);\n }\n return factor;\n }\n\n void fr(Map visit, Map fa, int f) {\n Map fb = factor[f];\n List forbidPrimes = new ArrayList<>();\n for (Map.Entry en: fa.entrySet()) {\n if (!fb.getOrDefault(en.getKey(), -1).equals(en.getValue())) {\n forbidPrimes.add(en.getKey());\n }\n }\n int n = forbidPrimes.size();\n int chooseFrom = m / f;\n int tot = chooseFrom;\n for (int i = 1; i < 1 << n; i++) {\n int on = 0;\n int val = 1;\n for (int j = 0; j < n; j++) {\n if (((1 << j) & i) != 0) {\n val *= forbidPrimes.get(j);\n on += 1;\n }\n }\n tot = tot + (on == 1 ? -1 : 1) * chooseFrom / val;\n }\n visit.put(f, tot);\n }\n\n Frac[] dp;\n int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n public Frac get(int y) {\n if (y == 1) return new Frac(0, 1);\n if (dp[y] != null) return dp[y];\n Map visit = new HashMap<>();\n Map fa = factor[y];\n for (int f = 1; f <= y; f++) {\n if (y % f == 0) {\n fr(visit, fa, f);\n if (f * f != y) {\n fr(visit, fa, y / f);\n }\n }\n }\n Frac expect = new Frac(0, 1);\n int x = visit.get(y);\n for (Map.Entry en: visit.entrySet()) {\n if (en.getKey() == y) {\n continue;\n }\n Frac prob = new Frac(en.getValue(), m - x);\n expect = expect.add(prob.mult(get(en.getKey()).add(new Frac(1, 1))));\n };\n return dp[y] = expect.add(new Frac(x, m - x));\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n sieve();\n m = sc.nextInt();\n dp = new Frac[m + 1];\n Frac tot = new Frac(0, 1);\n for (int i = 1; i <= m; i++) {\n tot= tot.add(get(i).add(new Frac(1, 1)));\n }\n Frac ret = tot.mult(new Frac(1 , m));\n pw.println(ret.val());\n// pw.println(ret.toString());\n }\n }\n\n // template, actual code is in class Task.\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"Test.in\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"Test.out\"));\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n// System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n// System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n // Faster IO with BufferedReader wrapped with Scanner\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c547a167bd7419f45541245b01119c48", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class SolutionD {\n static long fast_pow(long a, long b) {\n if(b == 0)\n return 1L;\n long val = fast_pow(a, b / 2);\n if(b % 2 == 0)\n return val * val % mod;\n else\n return val * val % mod * a % mod;\n }\n static void solve(int lvl, int maxlvl, int[] primes, long baseVal, long curVal, long m, int parity) {\n if(lvl == maxlvl) {\n long poss = m / (baseVal * curVal);\n if(parity == 0)\n cnt += poss;\n else\n cnt -= poss;\n\n return;\n }\n\n solve(lvl + 1, maxlvl, primes, baseVal, curVal, m, parity);\n solve(lvl + 1, maxlvl, primes, baseVal, curVal * primes[lvl], m, parity ^ 1);\n }\n static long cnt = 0;\n static long mod = (long)1e9 + 7;\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n int m = sc.nextInt();\n\n int primes[][] = new int[m + 1][6];\n int ptr[] = new int[m + 1];\n\n for(int i = 2; i <= m; ++i) {\n if(ptr[i] == 0) {\n for(int j = i; j <= m; j += i) {\n primes[j][ptr[j]++] = i; \n }\n }\n }\n\n long prob[] = new long[m + 1];\n long ans[] = new long[m + 1];\n ans[0] = 0;\n prob[0] = 1;\n long invm = fast_pow(m, mod - 2);\n for(int i = m; i >= 2; --i) {\n long multiples = m / i;\n prob[i] = fast_pow(m - multiples, mod - 2);\n long num = m;\n long den = (m - multiples) * (m - multiples) % mod;\n ans[i] = num * fast_pow(den, mod - 2) % mod;\n\n for(int j = 2 * i; j <= m; j += i) {\n int val = j / i;\n cnt = 0;\n solve(0, ptr[val], primes[val], i, 1, m, 0);\n long curProb = cnt * fast_pow(m - multiples, mod - 2) % mod;\n num = m * cnt % mod;\n den = (m - multiples) * (m - multiples) % mod;\n long curEv = (num * fast_pow(den, mod - 2) % mod * fast_pow(curProb, mod - 2) % mod + ans[j] % mod) % mod; \n curProb = curProb * prob[j] % mod;\n ans[i] += curEv * curProb % mod;\n prob[i] += curProb;\n }\n\n prob[i] %= mod;\n ans[i] %= mod;\n ans[i] = ans[i] * fast_pow(prob[i], mod - 2) % mod;\n }\n\n long fans = 0;\n long fprob = invm;\n for(int i = 2; i <= m; ++i) {\n int val = i;\n cnt = 0;\n solve(0, ptr[val], primes[val], 1, 1, m, 0);\n long curProb = prob[i] * cnt % mod * invm % mod;\n fans += curProb * ans[i] % mod;\n fprob += curProb;\n }\n fans %= mod;\n fprob %= mod;\n\n fans = (fans * fast_pow(fprob, mod - 2) % mod + 1L) % mod;\n\n System.out.print(fans);\n } \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e9268bd175055ee6768abcd36842ce7c", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\npublic class Main {\n\n\n private static void solve() {\n int m = ni();\n \n int mod = 1000000000 + 7;\n\n int[] primes = sieveEratosthenes(m + 1);\n\n long[] dp = new long[m + 1];\n\n long ret = 0;\n outer: for (int g = 2; g <= m; g ++) {\n dp[g] = f(m, g, mod);\n \n int[][] f = factor(g, primes);\n\n for (int[] v : f) {\n if (v[1] > 1) {\n continue outer;\n }\n }\n ret += dp[g] * (f.length % 2 == 1 ? 1 : (mod-1)) %mod;\n ret %=mod;\n }\n \n ret += inv(m, mod);\n ret %= mod;\n \n System.out.println(ret);\n\n }\n \n private static void dump(int mod) {\n for (int i = 1; i < 20; i ++) {\n for (int j = 1; j < 20; j ++) {\n System.out.println(i + \" \" + j + \" \" + inv(j, mod) * i % mod);\n }\n }\n }\n private static long f(long m, long g, int mod) {\n long a = (m/g) * inv(m, mod) % mod;\n long c = (m - (m/g) + mod) * inv(m/g, mod) % mod;\n \n long b = inv((mod-1+a) * (mod-1+a) % mod, mod) * a % mod;\n long ret = c * (mod + b - a) % mod;\n return ret;\n }\n \n public static long[][] enumDivisors(int[][] f)\n {\n int n = 1;\n for(int j = 0;j < f.length;j++){\n n *= f[j][1]+1;\n }\n long[][] divs = new long[n][2];\n int p = 1;\n divs[0][0] = 1;\n divs[0][1] = 1;\n for(int j = 0;j < f.length;j++){\n for(int q = p-1;q >= 0;q--){\n long b = divs[q][0];\n long s = -divs[q][1];\n for(int k = 0;k < f[j][1];k++){\n b *= f[j][0];\n// if((long)b*b <= n)divs[p++] = b;\n divs[p][1] = s;\n divs[p++][0] = b;\n s = -s;\n }\n }\n }\n long s = divs[n-1][1];\n for (int i = 0; i < n; i ++) {\n divs[i][1] *= s;\n }\n return divs;\n }\n \n public static int[][] factor(int n, int[] primes) {\n int[][] ret = new int[9][2];\n int rp = 0;\n for (int p : primes) {\n if (p * p > n)\n break;\n int i;\n for (i = 0; n % p == 0; n /= p, i++);\n if (i > 0) {\n ret[rp][0] = p;\n ret[rp][1] = i;\n rp++;\n }\n }\n if (n != 1) {\n ret[rp][0] = n;\n ret[rp][1] = 1;\n rp++;\n }\n return Arrays.copyOf(ret, rp);\n }\n\n public static int[] sieveEratosthenes(int n) {\n if (n <= 32) {\n int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};\n for (int i = 0; i < primes.length; i++) {\n if (n < primes[i]) {\n return Arrays.copyOf(primes, i);\n }\n }\n return primes;\n }\n\n int u = n + 32;\n double lu = Math.log(u);\n int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n ret[0] = 2;\n int pos = 1;\n\n int[] isnp = new int[(n + 1) / 32 / 2 + 1];\n int sup = (n + 1) / 32 / 2 + 1;\n\n int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31};\n for (int tp : tprimes) {\n ret[pos++] = tp;\n int[] ptn = new int[tp];\n for (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n ptn[i >> 5] |= 1 << i;\n for (int j = 0; j < sup; j += tp) {\n for (int i = 0; i < tp && i + j < sup; i++) {\n isnp[j + i] |= ptn[i];\n }\n }\n }\n\n // 3,5,7\n // 2x+3=n\n int[] magic = {0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10,\n 7, 12, 21, 17, 9, 6, 16, 5, 15, 14};\n int h = n / 2;\n for (int i = 0; i < sup; i++) {\n for (int j = ~isnp[i]; j != 0; j &= j - 1) {\n int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n int p = 2 * pp + 3;\n if (p > n)\n break;\n ret[pos++] = p;\n if ((long) p * p > n)\n continue;\n for (int q = (p * p - 3) / 2; q <= h; q += p)\n isnp[q >> 5] |= 1 << q;\n }\n }\n\n return Arrays.copyOf(ret, pos);\n }\n \n public static long inv(long a, int p)\n {\n long ret = 1;\n long mul = a;\n for(long n = p-2;n > 0;n >>>= 1){\n if((n&1)==1)ret = ret * mul % p;\n mul = mul * mul % p;\n }\n return ret;\n }\n \n public static long pow(long a, long n, long mod)\n {\n long ret = 1; // 1%mod if mod=1,n=0\n int x = 63-Long.numberOfLeadingZeros(n);\n for(;x >= 0;x--){\n ret = ret * ret % mod;\n if(n<<~x<0)ret = ret * a % mod;\n }\n return ret;\n }\n \n \n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n @Override\n public void run() {\n long start = System.currentTimeMillis();\n String debug = args.length > 0 ? args[0] : null;\n if (debug != null) {\n try {\n is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);\n solve();\n out.flush();\n tr((System.currentTimeMillis() - start) + \"ms\");\n }\n }, \"\", 64000000).start();\n }\n\n private static java.io.InputStream is = System.in;\n private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);\n private static java.util.StringTokenizer tokenizer = null;\n private static java.io.BufferedReader reader;\n\n public static String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new java.util.StringTokenizer(reader.readLine());\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n private static double nd() {\n return Double.parseDouble(next());\n }\n\n private static long nl() {\n return Long.parseLong(next());\n }\n\n private static int[] na(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = ni();\n return a;\n }\n\n private static char[] ns() {\n return next().toCharArray();\n }\n\n private static long[] nal(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nl();\n return a;\n }\n\n private static int[][] ntable(int n, int m) {\n int[][] table = new int[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n table[i][j] = ni();\n }\n }\n return table;\n }\n\n private static int[][] nlist(int n, int m) {\n int[][] table = new int[m][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n table[j][i] = ni();\n }\n }\n return table;\n }\n\n private static int ni() {\n return Integer.parseInt(next());\n }\n\n private static void tr(Object... o) {\n if (is != System.in)\n System.out.println(java.util.Arrays.deepToString(o));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea5fef16a2dc50f116cbf3df24d8263d", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic final class EcRound35BApplication {\n\n\tpublic static void main(String[] args) {\n\n//\t\tSystem.out.println(\"test start\");\n//\t\tapp.tester(1,5,2,3,1);\n//\t\tapp.tester(2,4,7,10,3);\n//\t\tSystem.out.println(\"test finished\");\n\n\t\tInput input = new Input();\n\t\tinput = SystemInput();\n\t\tInteger result = run(input);\n\t\tSystem.out.print(result);\n\n\n\t}\n\n\tprivate void tester(Integer no,Integer participant , Integer pieceA , Integer pieceB,Integer answer) {\n\t\tInput input = new Input();\n\t\tinput.setInput(participant , pieceA , pieceB);\n\t\tInteger result = run(input);\n\n\t\tif(result == answer) {\n\t\t\tSystem.out.println(\"No.\" + no + \":OK\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(\"No.\" + no + \":failed\");\n\t\t\tSystem.out.println(\"result:\" + result);\n\t\t\tSystem.out.println(\"answer:\" + answer);\n\t\t}\n\t}\n\n\tprivate static Input SystemInput() {\n\t\tInput input = new Input();\n\t\tScanner sc = new Scanner(System.in);\n\t\tInteger participant = sc.nextInt();\n\t\tInteger pieceA = sc.nextInt();\n\t\tInteger pieceB = sc.nextInt();\n\t\tinput.setInput(participant,pieceA,pieceB);\n\t\tsc.close();\n\t\treturn input;\n\t}\n\n\tprivate static Integer run(Input input) {\n\t\tInteger result;\n\n\t\tresult = simpleDivision(input);\n\n\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0603\ufffd\ufffd[\ufffdv\n\t\twhile(!checkResult(input,result)) {\n\t\t\t//\ufffdS\ufffd\ufffd\ufffd\ufffdresult\ufffds\ufffd[\ufffdX\ufffd\ufffd\ufffd\u0094z\ufffd\ufffd\u0202\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ua347\ufffdAresult\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u010d\u010c\ufffd\ufffd\ufffd\n\t\t\tresult --;\n\t\t}\n\n\t\treturn result;\n\t}\n\n\n\tprivate Integer simpleDivision(Input input) {\n\t\tInteger result;\n\t\tInteger allPieces;\n\t\t//\ufffd\ufffd\ufffdv\n\t\tallPieces = input.getPieceA() + input.getPieceB();\n\n\t\tresult = allPieces / input.getParticipant();\n\n\t\treturn result;\n\t}\n\n\tprivate boolean checkResult(Input input , Integer result) {\n\t\tboolean isDistribute = true;\n\t\tInteger pieceA = input.getPieceA();\n\t\tInteger pieceB = input.getPieceB();\n\t\tInteger participants = input.getParticipant();\n\n\t\t//A\ufffd\ufffd\ufffd\u731f\ufffd\ufffd\n\t\twhile(pieceA > 0) {\n\t\t\t//\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0202\ufffd\ufffd\ua347\ufffd\u0352E\ufffdo\ufffd\ufffd\ufffd\ufffd\n\t\t\tif(pieceA < result) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t//\ufffd\ufffd\ufffd\ufffd\u0102\ufffd\ufffd\ufffd\u038a\ufffd\ufffd\u84d6\ufffd\u0102\ufffd\n\t\t\tparticipants --;\n\t\t\tpieceA = pieceA - result;\n\t\t}\n\n\t\t//B\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\t//B\ufffd\u0310\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd~\ufffdc\ufffdl\ufffd\ufffd\ufffd\u0251\ufffd\ufffd\ufffd\u0102\ufffd\ufffd\u0202\ufffd\ufffd\ufffd\u0383A\ufffdE\ufffdg\n\t\tif(pieceB < participants * result) {\n\t\t\tisDistribute = false;\n\t\t}\n\n\t\treturn isDistribute;\n\t}\n\n\n\n\tprivate static class Input{\n\t\tprivate Integer participant;\n\t\tprivate Integer pieceA;\n\t\tprivate Integer pieceB;\n\n\t\tpublic void setInput( Integer participant , Integer pieceA , Integer pieceB) {\n\t\t\tthis.participant = participant;\n\t\t\tthis.pieceA = pieceA;\n\t\t\tthis.pieceB = pieceB;\n\n\t\t}\n\n\t\tpublic Integer getParticipant() {\n\t\t\treturn participant;\n\t\t}\n\n\t\tpublic void setParticipant(Integer participant) {\n\t\t\tthis.participant = participant;\n\t\t}\n\n\t\tpublic Integer getPieceA() {\n\t\t\treturn pieceA;\n\t\t}\n\n\t\tpublic void setPieceA(Integer pieceA) {\n\t\t\tthis.pieceA = pieceA;\n\t\t}\n\n\t\tpublic Integer getPieceB() {\n\t\t\treturn pieceB;\n\t\t}\n\n\t\tpublic void setPieceB(Integer pieceB) {\n\t\t\tthis.pieceB = pieceB;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e8bfe1b013204137f4518169320c1a17", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import ava.util.*;\n\npublic class Solution\n{\n public static void main(String []args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int a = sc.nextInt();\n int b = sc.nextInt();\n \n int max = 0;\n for(int i = 1 ; i <= n - 1 ; i++)\n {\n int minCakes = Math.min(a/i , n - i/b);\n if(minCakes > max)\n max = minCakes;\n \n }\n \n System.out.println(max);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1757b1885d868d11623fa775ecab838f", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\n import java.util.Scanner;\n\npublic class test\n{\n\tprivate static Scanner sc;\n\tpublic static void main(String[] args)\n\t{\n\t\tsc = new Scanner(System.in);\n\t\tint n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();\n\t\tfor(int a=Math.min(i, j);a>0;i--)\n\t\t{\n\t\t\tif(a/i+b/i>=n)\n\t\t\t{\n\t\t\t\tSystem.out.println(i);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "db6cac5a126d7ef9bf13537a3d05ffd2", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution\n{\n public static void main(String []args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int a = sc.nextInt();\n int b = sc.nextInt();\n \n int max = 0;\n for(int i = 1 ; i <= n - 1 ; i++)\n {\n if(a/i != 0 && b/(n - i) != 0)\n {\n int minCakes = Math.min(a/i , b/(n - i));\n if(minCakes > max)\n maxx = minCakes;\n }\n \n }\n \n System.out.println(max);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cbc3591845d360c57151777be967c2f2", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\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, FastScanner in, FastPrinter out) {\n int n = in.nextInt();\n int[] g = new int[n + 1];\n int[] g2 = new int[n + 1];\n g[1] = g[2] = 0;\n int[] v = new int[n + 1];\n int[] move = new int[n + 1];\n Arrays.fill(move, -1);\n for (int i = 3; i <= n; i++) {\n for (int z = 2; z * (z + 1) / 2 <= i; z++) {\n if ((z & 1) == 1) {\n if (i % z == 0) {\n int q = g2[i / z + z / 2] ^ g2[i / z - z / 2 - 1];\n v[q] = i;\n if (q == 0 && move[i] < 0) {\n move[i] = z;\n }\n }\n } else {\n if (i % z == z / 2) {\n int q = g2[i / z + z / 2] ^ g2[i / z - z / 2];\n v[q] = i;\n if (q == 0 && move[i] < 0) {\n move[i] = z;\n }\n }\n }\n }\n for (int k = 0; ; k++) {\n if (v[k] != i) {\n g[i] = k;\n break;\n }\n }\n g2[i] = g2[i - 1] ^ g[i];\n }\n if (g[n] == 0) {\n out.println(-1);\n return;\n }\n out.println(move[n]);\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "817cdf802c32fa7bbcca3f4745c1bfb9", "src_uid": "63262317ba572d78163c91b853c05506", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class InterestingGame {\n public static void main(String args[]) {\n new InterestingGame();\n }\n \n public InterestingGame() {\n Scanner scanner = new Scanner(System.in);\n int N = scanner.nextInt();\n \n int colors[] = new int[10010];\n colors[1] = 0;\n colors[2] = 0;\n for (int i = 3; i < N; i++) {\n Set set = new HashSet();\n for (int k = 2; k < 500; k++) {\n int minSum = k * (k + 1) / 2;\n if (minSum > i)\n break;\n if ((i - minSum) % k != 0)\n continue;\n int first = (i - minSum) / k;\n int state = 0;\n for (int j = 1; j <= k; j++) {\n state ^= colors[j + first];\n }\n set.add(state);\n }\n int x = 0;\n while (set.contains(x)) x++;\n colors[i] = x;\n }\n for (int k = 2; k < 500; k++) {\n int minSum = k * (k + 1) / 2;\n if (minSum > N)\n break;\n if ((N - minSum) % k != 0)\n continue;\n int first = (N - minSum) / k;\n int state = 0;\n for (int j = 1; j <= k; j++) {\n state ^= colors[j + first];\n }\n if (state == 0) {\n System.out.println(k);\n return;\n }\n }\n System.out.println(-1);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e29d7c45e660a4a63cf99e323c379f9", "src_uid": "63262317ba572d78163c91b853c05506", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\n\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class C73_div1 {\n\n\tstatic boolean test = false; // System.getProperty(\"JENS_TURBO\") != null;\n\n\tpublic String str() throws IOException {\n\t\tif (test) {\n\t\t\treturn reader.readLine();\n\t\t} else {\n\t\t\treturn in.readLine();\n\t\t}\n\t}\n\n\tprivate int in() throws NumberFormatException, IOException {\n\t\treturn Integer.valueOf(str());\n\t}\n\n\tprivate long lon() throws NumberFormatException, IOException {\n\t\treturn Long.valueOf(str());\n\t}\n\n\tprivate int[] ints() throws Throwable {\n\t\tStringTokenizer st = new StringTokenizer(str());\n\n\t\tint[] res = new int[st.countTokens()];\n\t\tfor (int i = 0; i < res.length; i++) {\n\t\t\tres[i] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\treturn res;\n\t}\n\n\tprivate long[] longs() throws Throwable {\n\t\tStringTokenizer st = new StringTokenizer(str());\n\n\t\tlong[] res = new long[st.countTokens()];\n\t\tfor (int i = 0; i < res.length; i++) {\n\t\t\tres[i] = Long.parseLong(st.nextToken());\n\t\t}\n\t\treturn res;\n\t}\n\n\tprivate BigInteger[] bigs() throws Throwable {\n\t\tStringTokenizer st = new StringTokenizer(str());\n\n\t\tBigInteger[] res = new BigInteger[st.countTokens()];\n\t\tfor (int i = 0; i < res.length; i++) {\n\t\t\tres[i] = new BigInteger(st.nextToken());\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) throws Throwable {\n\t\tnew C73_div1().solve();\n\t}\n\n\tpublic C73_div1() throws Throwable {\n\t\tif (test) {\n\t\t\treader = new BufferedReader(new FileReader(new File(testDataFile)));\n\t\t}\n\t}\n\n\tstatic InputStreamReader inp = new InputStreamReader(System.in);\n\tstatic BufferedReader in = new BufferedReader(inp);\n\n\tstatic PrintWriter writer = new PrintWriter(System.out);\n\tstatic String testDataFile = \"testdata.txt\";\n\tBufferedReader reader = null;\n\n\tint getseg(int l, int r) {\n\t\treturn nimsum[r] ^ nimsum[l - 1];\n\t}\n\n\tint maxn = 10020;\n\n\tint[] nim = new int[maxn];\n\tint[] nimsum = new int[maxn];\n\tint[] minpile = new int[maxn];\n\tint[] arr = new int[maxn];\n\n\tprivate void solve() throws Throwable, IOException {\n\n\t\tint visid = 0;\n\t\tminpile[1] = -1;\n\t\tint a = 0, x = 0;\n\t\tfor (int n = 2; n < maxn; n++) {\n\t\t\tvisid++;\n\t\t\tminpile[n] = -1;\n\t\t\tfor (int k = 2; k * k < 2 * n; k++) {\n\t\t\t\tif ((2 * n) % k > 0)\n\t\t\t\t\tcontinue;\n\t\t\t\tint c = 2 * n / k + 1 - k;\n\t\t\t\tif (c <= 0 || (c & 1) > 0)\n\t\t\t\t\tcontinue;\n\n\t\t\t\ta = c >> 1;\n\t\t\t\tx = getseg(a, a + k - 1);\n\t\t\t\tarr[x] = visid;\n\t\t\t\tif (x == 0 && minpile[n] == -1)\n\t\t\t\t\tminpile[n] = k;\n\t\t\t}\n\t\t\tint i = 0;\n\t\t\tfor (i = 0; arr[i] == visid; i++);\n\t\t\tnim[n] = i;\n\t\t\tnimsum[n] = nimsum[n - 1] ^ nim[n];\n\t\t}\n\t\tSystem.out.println(minpile[in()]);\n\t}\n\n\tprivate double d(int row, int col, int y, int x) {\n\t\tdouble val = Math.pow(row - y, 2) + Math.pow(col - x, 2);\n\t\treturn Math.sqrt(val);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c5d12b82a7995b2ea52c41472e402921", "src_uid": "63262317ba572d78163c91b853c05506", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n//http://codeforces.com/contest/914/problem/0\npublic class PerfectSquares {\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\ts.nextLine();\n\t\tint[] a = Arrays.stream(s.nextLine().split(\" \")).mapToInt(x -> Integer.parseInt(x)).toArray();\n\t\tint max = Integer.MIN_VALUE;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif(are(int a) {\n\t\tfor (int i = 0; i*i <= a ; i++) {\n\t\t\tif(i*i == a) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0a9d366ad4e2fa93735eede109ecd2f7", "src_uid": "63262317ba572d78163c91b853c05506", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\n public static final void main(String[] args)\n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int m=s.nextInt();\n int k=s.nextInt();\n if(m>==n&&k>=n)\n System.out.println(\"Yes\");\n else\n System.out.println(\"No\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "38985737db1809d965994397fbb75814", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import jaav.util.*;\npublic class cossack\n{\n public static void main(String args[])\n {\n Scanner in = new scanner(system.in);\n int n,m,k;\n n=in.nextInt();\n m=in.nextInt();\n k=in.nextInt();\n if(n>m||n>k)\n System.out.println(\"No\");\n else\n System.out.println(\"Yes\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "355fdff64fdc6dca20284d2ad9482aea", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*:\n\npublic class Main{\n public static void main(String[] ags){\n Scanner scan = new Sanner(System.in);\n int a = scan.nextInt();\n int b = scan.nextInt();\n int c = scan.nextInt();\n if(b >=a && c >= a){\n System.out.println(\"Yes\");\n }\n else\n {\n System.out.println(\"No\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0b0436a6e9bcbffbf08673714b712c3e", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Codeforce\n{\n public static void main(String[] args)\n {\n Solution solution = new Solution();\n\n Scanner s = new Scanner(System.in);\n\n int n = s.nextInt();\n int k = s.nextInt();\n int l = s.nextInt();\n\n if(n < k && n < l)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72871626236b4c4027fc877adfc2a350", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class MaxTable{\n\tpublic static void main(String[]args){\n\t\tScanner kbd = new Scanner(System.in);\n\t\tString word = kbd.nextLine();\n\t\tint numOfError = 0;\n\t\tString[] letters = word.split(\"\");\n\t\tString[] rev = new String[letters.length];\n\t\t\n\t\tfor(int i = 1; i <= rev.length; i++){\n\t\t rev[rev.length - i] = letters[i - 1];\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < rev.length; i++){\n\t\t if(rev[i].equals(letters[i])){\n\t\t //do nothing\n\t\t } else {\n\t\t numOfError ++;\n\t\t }\n\t\t}\n\n\t\tif(numOfError == 2){\n\t\t System.out.println(\"YES\");\n\t\t} if else (numOfErrpr != 2) {\n\t\t System.out.println(\"NO\");\n\t\t}\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fb44902a1e0b19dd62cc8153af5434f2", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class test{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n String s=sc.nextInt();\n int i=0,j=s.length()-1,cnt=0;\n while(i1)System.out.println(\"NO\");\n else System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d62cec6f3f4ec226f6adc96cde43f002", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "//package pilot;\n\nimport java.util.*;\n\npublic class CF4102A {\n\tpublic static String reverse (String input){\n\t\t char[] in = input.toCharArray();\n\t\t int begin=0;\n\t\t int end=in.length-1;\n\t\t char temp;\n\t\t while(end>begin){\n\t\t temp = in[begin];\n\t\t in[begin]=in[end];\n\t\t in[end] = temp;\n\t\t end--;\n\t\t begin++;\n\t\t }\n\t\t return new String(in);\n\t\t}\n\tpublic static void main(String[] args) {\nScanner in = new Scanner(System.in);\n//String s = in.nextLine();\n//String t = reverse(s);\nSystem.out.println(s);\nSystem.out.println(t);\nint count =0;\nfor (int i = 0; i= '0' && c <= '9');\r\n \r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n \r\n public long nextLong() throws IOException\r\n {\r\n long ret = 0;\r\n byte c = read();\r\n while (c <= ' ')\r\n c = read();\r\n boolean neg = (c == '-');\r\n if (neg)\r\n c = read();\r\n do {\r\n ret = ret * 10 + c - '0';\r\n } while ((c = read()) >= '0' && c <= '9');\r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n \r\n public double nextDouble() throws IOException\r\n {\r\n double ret = 0, div = 1;\r\n byte c = read();\r\n while (c <= ' ')\r\n c = read();\r\n boolean neg = (c == '-');\r\n if (neg)\r\n c = read();\r\n \r\n do {\r\n ret = ret * 10 + c - '0';\r\n } while ((c = read()) >= '0' && c <= '9');\r\n \r\n if (c == '.') {\r\n while ((c = read()) >= '0' && c <= '9') {\r\n ret += (c - '0') / (div *= 10);\r\n }\r\n }\r\n \r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n \r\n private void fillBuffer() throws IOException\r\n {\r\n bytesRead = din.read(buffer, bufferPointer = 0,\r\n BUFFER_SIZE);\r\n if (bytesRead == -1)\r\n buffer[0] = -1;\r\n }\r\n \r\n private byte read() throws IOException\r\n {\r\n if (bufferPointer == bytesRead)\r\n fillBuffer();\r\n return buffer[bufferPointer++];\r\n }\r\n \r\n public void close() throws IOException\r\n {\r\n if (din == null)\r\n return;\r\n din.close();\r\n }\r\n }\r\n \r\n \r\n static int parent(int a , int p[])\r\n {\r\n if(a == p[a])\r\n return a;\r\n \r\n return p[a] = parent(p[a],p);\r\n }\r\n \r\n static void union(int a , int b , int p[] , int sz[])\r\n {\r\n \r\n a = parent(a,p);\r\n b = parent(b,p);\r\n \r\n if(a == b)\r\n return;\r\n \r\n if(sz[a] < sz[b])\r\n {\r\n int tmp = a;\r\n a = b;\r\n b = tmp;\r\n }\r\n p[b] = a;\r\n sz[a] += sz[b];\r\n \r\n }\r\n \r\n static long pow(long a , long b , long c)\r\n {\r\n if(b == 0)\r\n return 1;\r\n \r\n long ans = pow(a,b/2,c);\r\n if(b%2 == 0)\r\n return ans*ans%c;\r\n \r\n return ans*ans%c*a%c;\r\n }\r\n \r\n static long st[];\r\n static long lazy[];\r\n static int sz;\r\n static void setMax(int l , int r , long v , int lx , int rx , int x)\r\n {\r\n if(lazy[x] != Long.MIN_VALUE)\r\n {\r\n st[x] = Math.max(st[x],lazy[x]);\r\n if(lx != rx)\r\n {\r\n lazy[2*x+1] = Math.max(lazy[2*x+1],lazy[x]);\r\n lazy[2*x+2] = Math.max(lazy[2*x+2],lazy[x]);\r\n }\r\n lazy[x] = Long.MIN_VALUE;\r\n }\r\n \r\n if(lx > r || rx < l)\r\n return;\r\n \r\n if(lx >= l && rx <= r)\r\n {\r\n st[x] = Math.max(st[x],v);\r\n if(lx != rx)\r\n {\r\n lazy[2*x+1] = Math.max(lazy[2*x+1],v);\r\n lazy[2*x+2] = Math.max(lazy[2*x+2],v); \r\n }\r\n return;\r\n }\r\n \r\n int mid = (lx+rx)/2;\r\n setMax(l,r,v,lx,mid,2*x+1);\r\n setMax(l,r,v,mid+1,rx,2*x+2);\r\n \r\n st[x] = Math.max(st[2*x+1],st[2*x+2]);\r\n }\r\n \r\n static long getMax(int l , int r , int lx , int rx , int x)\r\n {\r\n if(lazy[x] != Long.MIN_VALUE)\r\n {\r\n st[x] = Math.max(st[x],lazy[x]);\r\n if(lx != rx)\r\n {\r\n lazy[2*x+1] = Math.max(lazy[2*x+1],lazy[x]);\r\n lazy[2*x+2] = Math.max(lazy[2*x+2],lazy[x]);\r\n }\r\n lazy[x] = Long.MIN_VALUE;\r\n }\r\n \r\n if(lx > r || rx < l)\r\n return -1000000000000000L;\r\n \r\n if(lx >= l && rx <= r)\r\n return st[x];\r\n \r\n int mid = (lx+rx)/2;\r\n \r\n return Math.max(getMax(l,r,lx,mid,2*x+1),getMax(l,r,mid+1,rx,2*x+2));\r\n }\r\n \r\n static boolean check(int x , int a[] , int b[] , int g[][] , long s , int k)\r\n {\r\n long aa = Long.MAX_VALUE;\r\n long bb = Long.MAX_VALUE;\r\n \r\n for(int i = 1 ; i <= x ; i++)\r\n {\r\n aa = Math.min(aa,a[i]);\r\n bb = Math.min(bb,b[i]);\r\n }\r\n \r\n long cost[] = new long[g.length];\r\n for(int i = 0 ; i < g.length ; i++)\r\n {\r\n if(g[i][0] == 1)\r\n cost[i] = aa*(long)g[i][1];\r\n \r\n else \r\n cost[i] = bb*(long)g[i][1];\r\n }\r\n \r\n Arrays.sort(cost);\r\n for(int i = 0 ; i < k ; i++)\r\n {\r\n s -= cost[i];\r\n if(s < 0)\r\n return false;\r\n }\r\n \r\n return true;\r\n }\r\n \r\n public static int gcd(int a, int b)\r\n {\r\n if (a == 0)\r\n return b;\r\n \r\n return gcd(b%a, a);\r\n }\r\n \r\n static void dfs(int n , ArrayList arr[] , int p , int dp1[][] , long dp2[][])\r\n {\r\n dp1[n][0] = 1;\r\n dp2[n][0] = arr[n].size();\r\n dp2[n][1] = 1;\r\n \r\n for(Integer v : arr[n])\r\n {\r\n if(v != p)\r\n {\r\n dfs(v,arr,n,dp1,dp2);\r\n dp1[n][0] += dp1[v][1];\r\n dp1[n][1] += Math.max(dp1[v][0],dp1[v][1]);\r\n \r\n dp2[n][0] += dp2[v][1];\r\n if(dp1[v][0] > dp1[v][1])\r\n {\r\n dp2[n][1] += dp2[v][0];\r\n }\r\n \r\n else if(dp1[v][1] > dp1[v][0])\r\n {\r\n dp2[n][1] += dp2[v][1];\r\n }\r\n \r\n else \r\n {\r\n dp2[n][1] += Math.min(dp2[v][0],dp2[v][1]);\r\n }\r\n }\r\n }\r\n }\r\n \r\n static void dfs2(int n , ArrayList arr[] , int p , int dp1[][] , long dp2[][],\r\n long ans[] , int last)\r\n {\r\n if(last == 0)\r\n {\r\n ans[n] = 1;\r\n for(Integer v : arr[n])\r\n {\r\n if(v != p)\r\n {\r\n dfs2(v,arr,n,dp1,dp2,ans,1);\r\n }\r\n }\r\n return;\r\n }\r\n \r\n int fn = -1;\r\n if(dp1[n][0] > dp1[n][1])\r\n fn = 0;\r\n \r\n else if(dp1[n][1] > dp1[n][0])\r\n fn = 1;\r\n \r\n else \r\n {\r\n if(dp2[n][0] < dp2[n][1])\r\n fn = 0;\r\n \r\n else \r\n fn = 1;\r\n }\r\n \r\n if(fn == 0)\r\n ans[n] = arr[n].size();\r\n \r\n else \r\n ans[n] = 1;\r\n \r\n for(Integer v : arr[n])\r\n {\r\n if(v != p)\r\n {\r\n dfs2(v,arr,n,dp1,dp2,ans,fn);\r\n }\r\n }\r\n }\r\n \r\n public static void main(String []args) throws IOException\r\n {\r\n Reader sc = new Reader();\r\n int n = sc.nextInt();\r\n double p = sc.nextDouble();\r\n int ans = 0;\r\n for(int i = 0 ; i <= n ; i++)\r\n {\r\n long xx = i*(n-i)*(n-i-1)+3*(i)*(i-1)*(n-i)+i*(i-1)*(i-2);\r\n double dd = p*n*(n-1)*(n-2);\r\n \r\n if(xx >= dd)\r\n {\r\n ans = i;\r\n break;\r\n }\r\n }\r\n System.out.println(ans);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b319e4fcf408843ba2e70d1202066033", "src_uid": "788ed59a964264bd0e755e155a37e14d", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class I {\r\n \r\n public static boolean DEBUG = true;\r\n public static String name = \"I\";\r\n\r\n public static void main(String[] args) throws IOException {\r\n \tFastScanner scan;\r\n \tPrintWriter out;\r\n \tif (DEBUG) {\r\n \t\tscan = new FastScanner(System.in);\r\n \tout = new PrintWriter(System.out);\r\n \t}\r\n \telse {\r\n \tscan = new FastScanner(name + \".in\");\r\n \tout = new PrintWriter(new BufferedWriter(new FileWriter(name + \".out\")));\r\n \t}\r\n\r\n\t\tfloat N = Float.parseFloat(scan.nextString());\r\n\t\tfloat P = Float.parseFloat(scan.nextString());\r\n \r\n for(float i=3; i= P) {\r\n out.println((int)i);\r\n break;\r\n }\r\n }\r\n\r\n\r\n out.close();\r\n }\r\n\r\n static class BIT {\r\n public int[] tree;\r\n \r\n public BIT(int len) {\r\n tree = new int[len+5];\r\n }\r\n \r\n // updates tree by adding val to index\r\n public void update(int index, int val) {\r\n index++;\r\n while(index < tree.length) {\r\n tree[index] ^= val;\r\n index += index & -index;\r\n }\r\n }\r\n \r\n public int query(int index) {\r\n int result = 0;\r\n index++;\r\n while(index > 0) {\r\n result ^= tree[index];\r\n index -= index & -index;\r\n }\r\n \r\n return result;\r\n }\r\n \r\n public int rangeSum(int low, int high) {\r\n return query(high) - query(low-1); \r\n }\r\n \r\n }\r\n\r\n /* BINARY LIFTING - Preprocess O(NlogN) - Query O(logN)*/\r\n static ArrayList[] adjList;\r\n static int[] tin, tout;\r\n static int[][] BL;\r\n static int ct;\r\n\r\n public static void preprocess(int root) {\r\n ct = 0;\r\n tin = new int[adjList.length];\r\n tout = new int[adjList.length];\r\n BL = new int[adjList.length][log2(adjList.length)+1];\r\n\r\n recur_bl(root,root);\r\n }\r\n\r\n public static void recur_bl(int v, int p) {\r\n tin[v] = ++ct;\r\n BL[v][0] = p;\r\n for (int i=1; i <= log2(adjList.length); ++i) BL[v][i] = BL[BL[v][i-1]][i-1];\r\n\r\n for (int i=0; i= tout[v];\r\n }\r\n \r\n public static int lca(int u, int v) {\r\n if(is_ancestor(u, v)) return u;\r\n if(is_ancestor(v, u)) return v;\r\n\r\n for(int i=log2(adjList.length); i >= 0; --i) if(!is_ancestor(BL[u][i], v)) u = BL[u][i];\r\n\r\n return BL[u][0];\r\n }\r\n\r\n public static int log2(int n) {\r\n return (int)Math.ceil(Math.log10(n)/Math.log10(2));\r\n }\r\n\r\n static class FastScanner {\r\n\t\t \r\n\t\t// Is your Fast I/O being bad?\r\n \r\n\t\tInputStream dis;\r\n\t\tbyte[] buffer = new byte[1 << 17];\r\n\t\tint pointer = 0;\r\n \r\n\t\tpublic FastScanner (String fileName) throws IOException {\r\n\t\t\tdis = new FileInputStream(fileName);\r\n\t\t}\r\n \r\n\t\tpublic FastScanner (InputStream is) throws IOException {\r\n\t\t\tdis = is;\r\n\t\t}\r\n \r\n\t\tint nextInt() throws IOException {\r\n\t\t\tint ret = 0;\r\n \r\n\t\t\tbyte b;\r\n\t\t\tdo {\r\n\t\t\t\tb = nextByte();\r\n\t\t\t} while (b <= ' ');\r\n\t\t\tboolean negative = false;\r\n\t\t\tif (b == '-') {\r\n\t\t\t\tnegative = true;\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n\t\t\twhile (b >= '0' && b <= '9') {\r\n\t\t\t\tret = 10 * ret + b - '0';\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n \r\n\t\t\treturn (negative) ? -ret : ret;\r\n\t\t}\r\n \r\n\t\tlong nextLong() throws IOException {\r\n\t\t\tlong ret = 0;\r\n \r\n\t\t\tbyte b;\r\n\t\t\tdo {\r\n\t\t\t\tb = nextByte();\r\n\t\t\t} while (b <= ' ');\r\n\t\t\tboolean negative = false;\r\n\t\t\tif (b == '-') {\r\n\t\t\t\tnegative = true;\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n\t\t\twhile (b >= '0' && b <= '9') {\r\n\t\t\t\tret = 10 * ret + b - '0';\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n \r\n\t\t\treturn (negative) ? -ret : ret;\r\n\t\t}\r\n \r\n\t\tbyte nextByte() throws IOException {\r\n\t\t\tif (pointer == buffer.length) {\r\n\t\t\t\tdis.read(buffer, 0, buffer.length);\r\n\t\t\t\tpointer = 0;\r\n\t\t\t}\r\n\t\t\treturn buffer[pointer++];\r\n\t\t}\r\n \r\n\t\tString nextString() throws IOException {\r\n\t\t\tStringBuffer ret = new StringBuffer();\r\n \r\n\t\t\tbyte b;\r\n\t\t\tdo {\r\n\t\t\t\tb = nextByte();\r\n\t\t\t} while (b <= ' ');\r\n\t\t\twhile (b > ' ') {\r\n\t\t\t\tret.appendCodePoint(b);\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n \r\n\t\t\treturn ret.toString();\r\n\t\t}\r\n \r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "284cc4c58e4e84589c2647b31f76f55c", "src_uid": "788ed59a964264bd0e755e155a37e14d", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Codeforces\r\n{\r\n public static void main(String args[])throws Exception\r\n {\r\n BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));\r\n StringBuilder sb=new StringBuilder();\r\n String s[]=bu.readLine().split(\" \");\r\n int n=Integer.parseInt(s[0])-1;\r\n int i,x=(int)(Double.parseDouble(s[1])*10000),y=10000;\r\n\r\n for(i=1;i<=n;i++)\r\n if(1l*i*y>=1l*n*x) break;\r\n System.out.println(i);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7d743979c50594c283e4abe122256a0", "src_uid": "788ed59a964264bd0e755e155a37e14d", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n \r\npublic class I {\r\n \r\n public static boolean DEBUG = true;\r\n public static String name = \"I\";\r\n \r\n public static void main(String[] args) throws IOException {\r\n \tFastScanner scan;\r\n \tPrintWriter out;\r\n \tif (DEBUG) {\r\n \t\tscan = new FastScanner(System.in);\r\n \tout = new PrintWriter(System.out);\r\n \t}\r\n \telse {\r\n \tscan = new FastScanner(name + \".in\");\r\n \tout = new PrintWriter(new BufferedWriter(new FileWriter(name + \".out\")));\r\n \t}\r\n \r\n\t\tfloat N = Float.parseFloat(scan.nextString());\r\n\t\tfloat P = Float.parseFloat(scan.nextString());\r\n \r\n for(int i=0; i<=N; i+=1) {\r\n \r\n double val = i*(i-1)*(i-2)/6 + i*(i-1)*(N-i)/2 + *i*(N-i)*(N-i-1)/4;\r\n val = val / (N*(N-1)*(N-2)/6);\r\n \r\n if(val >= P) {\r\n out.println((int)i);\r\n break;\r\n }\r\n }\r\n \r\n \r\n out.close();\r\n }\r\n \r\n static class BIT {\r\n public int[] tree;\r\n \r\n public BIT(int len) {\r\n tree = new int[len+5];\r\n }\r\n \r\n // updates tree by adding val to index\r\n public void update(int index, int val) {\r\n index++;\r\n while(index < tree.length) {\r\n tree[index] ^= val;\r\n index += index & -index;\r\n }\r\n }\r\n \r\n public int query(int index) {\r\n int result = 0;\r\n index++;\r\n while(index > 0) {\r\n result ^= tree[index];\r\n index -= index & -index;\r\n }\r\n \r\n return result;\r\n }\r\n \r\n public int rangeSum(int low, int high) {\r\n return query(high) - query(low-1); \r\n }\r\n \r\n }\r\n \r\n /* BINARY LIFTING - Preprocess O(NlogN) - Query O(logN)*/\r\n static ArrayList[] adjList;\r\n static int[] tin, tout;\r\n static int[][] BL;\r\n static int ct;\r\n \r\n public static void preprocess(int root) {\r\n ct = 0;\r\n tin = new int[adjList.length];\r\n tout = new int[adjList.length];\r\n BL = new int[adjList.length][log2(adjList.length)+1];\r\n \r\n recur_bl(root,root);\r\n }\r\n \r\n public static void recur_bl(int v, int p) {\r\n tin[v] = ++ct;\r\n BL[v][0] = p;\r\n for (int i=1; i <= log2(adjList.length); ++i) BL[v][i] = BL[BL[v][i-1]][i-1];\r\n \r\n for (int i=0; i= tout[v];\r\n }\r\n \r\n public static int lca(int u, int v) {\r\n if(is_ancestor(u, v)) return u;\r\n if(is_ancestor(v, u)) return v;\r\n \r\n for(int i=log2(adjList.length); i >= 0; --i) if(!is_ancestor(BL[u][i], v)) u = BL[u][i];\r\n \r\n return BL[u][0];\r\n }\r\n \r\n public static int log2(int n) {\r\n return (int)Math.ceil(Math.log10(n)/Math.log10(2));\r\n }\r\n \r\n static class FastScanner {\r\n\t\t \r\n\t\t// Is your Fast I/O being bad?\r\n \r\n\t\tInputStream dis;\r\n\t\tbyte[] buffer = new byte[1 << 17];\r\n\t\tint pointer = 0;\r\n \r\n\t\tpublic FastScanner (String fileName) throws IOException {\r\n\t\t\tdis = new FileInputStream(fileName);\r\n\t\t}\r\n \r\n\t\tpublic FastScanner (InputStream is) throws IOException {\r\n\t\t\tdis = is;\r\n\t\t}\r\n \r\n\t\tint nextInt() throws IOException {\r\n\t\t\tint ret = 0;\r\n \r\n\t\t\tbyte b;\r\n\t\t\tdo {\r\n\t\t\t\tb = nextByte();\r\n\t\t\t} while (b <= ' ');\r\n\t\t\tboolean negative = false;\r\n\t\t\tif (b == '-') {\r\n\t\t\t\tnegative = true;\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n\t\t\twhile (b >= '0' && b <= '9') {\r\n\t\t\t\tret = 10 * ret + b - '0';\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n \r\n\t\t\treturn (negative) ? -ret : ret;\r\n\t\t}\r\n \r\n\t\tlong nextLong() throws IOException {\r\n\t\t\tlong ret = 0;\r\n \r\n\t\t\tbyte b;\r\n\t\t\tdo {\r\n\t\t\t\tb = nextByte();\r\n\t\t\t} while (b <= ' ');\r\n\t\t\tboolean negative = false;\r\n\t\t\tif (b == '-') {\r\n\t\t\t\tnegative = true;\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n\t\t\twhile (b >= '0' && b <= '9') {\r\n\t\t\t\tret = 10 * ret + b - '0';\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n \r\n\t\t\treturn (negative) ? -ret : ret;\r\n\t\t}\r\n \r\n\t\tbyte nextByte() throws IOException {\r\n\t\t\tif (pointer == buffer.length) {\r\n\t\t\t\tdis.read(buffer, 0, buffer.length);\r\n\t\t\t\tpointer = 0;\r\n\t\t\t}\r\n\t\t\treturn buffer[pointer++];\r\n\t\t}\r\n \r\n\t\tString nextString() throws IOException {\r\n\t\t\tStringBuffer ret = new StringBuffer();\r\n \r\n\t\t\tbyte b;\r\n\t\t\tdo {\r\n\t\t\t\tb = nextByte();\r\n\t\t\t} while (b <= ' ');\r\n\t\t\twhile (b > ' ') {\r\n\t\t\t\tret.appendCodePoint(b);\r\n\t\t\t\tb = nextByte();\r\n\t\t\t}\r\n \r\n\t\t\treturn ret.toString();\r\n\t\t}\r\n \r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b2134363a7ad48408024f8627cfd807e", "src_uid": "788ed59a964264bd0e755e155a37e14d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "package codeforces;\n\nimport java.util.Scanner;\n\npublic class WorldCup {\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 = input.nextInt();\n\t\tint b = input.nextInt();\n\t\t\n\t\tif(a>b) {\n\t\t\tint store = a;\n\t\t\ta = b;\n\t\t\tb = store;\n\t\t}\n\t\t\n\t\tint log = log(n);\n\t\tint r = log;\n\t\tint half = n/2;\n\t\tint h1 = half/2;\n\t\tint ans = 0;\n\t\t\n\t\twhile(half>=1) {\n\t\t\tif(a%2 == 1 && b-a == 1) {\n\t\t\t\tans = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif(b>half&&a<=half) {\n\t\t\t\tans = r;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\thalf -=h1;\n\t\t\t\n\t\t\tif(a>half&&b>half) {\n\t\t\t\thalf +=h1*2;\n\t\t\t}\n\t\t\t\n\t\t\tr--;\n\t\t\th1/=2;\n\t\t}\n\t\t\n\t\tif(ans == log){\n\t\t\tSystem.out.println(\"Final!\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t\t\n\t\tinput.close(); \n } \n\t\n\tstatic int log(int x){\n\t return (int) (Math.log(x) / Math.log(2));\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6766007c73941836b968924fc0b1ea13", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\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.flush();out.close();\n }\n static class TaskE {\n int rec(int a,int b,int n,int l,int r){\n int L=r-l+1;\n if(a<=L/2+l-1&&b>L/2+l-1)return n/2;\n if(a>L/2)return rec(a,b,n/2,L/2+l,r);\n return rec(a,b,n/2,l,L/2+l-1);\n }\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n=in.nextInt();int a=in.nextInt(),b=in.nextInt();\n if(a>b){\n a^=b;b^=a;a^=b;\n }\n int ans=rec(a,b,n,1,n);\n if(ans==n/2){out.print(\"Final!\");return;}\n int v=(int)(Math.log(ans)/Math.log(2))+1;\n out.print(v);\n }\n /*pair ja[][];long w[];int from[],to[],c[];\n void make(int n,int m,InputReader in){\n ja=new pair[n+1][];w=new long[m];from=new int[m];to=new int[m];c=new int[n+1];\n for(int i=0;i>>16)]++;\n\t\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\t\tfor(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];\n\t\t\tint[] d = f; f = to;to = d;\n\t\t}\n\t\treturn f;\n\t}\n }\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream));\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f23ebad5de3feadbb7306f8f689c6a37", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class Main {\n \n public static void main(String[] args) {\n \n Scanner input = new Scanner (System.in);\n \n int [] array = {0 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256};\n \n int n = input.nextInt();\n int a = input.nextInt();\n int b = input.nextInt();\n \n int ans = (Math.abs(a - b)/2)+1;\n int m = -1;\n \n for(int i = 1 ; i < array.length ; i++)\n if(array[i] == n)\n {\n m = i;\n break;\n }\n \n if(m == ans || ans > m)\n System.out.println(\"Final!\");\n else\n System.out.println(ans);\n \n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0a57048fb4ca134ee2a630df022040ef", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n\n \n public static void main(String[] args) {\n // TODO code application logic here\n Scanner leer = new Scanner(System.in);\n int n, a, b, contador;\n n = leer.nextInt();\n a = leer.nextInt();\n b = leer.nextInt();\n int y = (int) (Math.log((double) n) / Math.log(2));\n int[] vector = new int[n+1];\n for (int i = 1; i <= n; i++) {\n vector[i]=i;\n }\n for (int i = 1; i <= y; i++) {\n contador = 0;\n for (int j = 1; j <= n / (i); j+=2) {\n contador++;\n if ((vector[j] == a && vector[j + 1] == b) || (vector[j] == b && vector[j + 1] == a)) {\n if (i == y) {\n System.out.println(\"Final!\");\n i=y;\n j=n/i;\n } else {\n System.out.println(\"\" + i);\n i=y;\n j=n/i;\n }\n } else {\n if (vector[j] == a || vector[j + 1] == a) {\n vector[contador] = a;\n } else {\n if (vector[j] == b || vector[j + 1] == b) {\n vector[contador] = b;\n } else {\n vector[contador] = vector[j];\n }\n }\n }\n }\n }\n }\n\n}\n\n }\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ce5fcac8f4434ac99476151a47325e0b", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class Main {public static void main(String[] args) throws Exception {new Solve();}}\n\nclass Solve { public Solve() throws Exception {solve();}\n\n void solve() throws Exception {\n int n = NI();\n int m = NI();\n int k = NI();\n String[] a = new String[n];\n // boolean[][] a = new boolean[n][m];\n for (int i = 0; i < n; i++)\n //for (int j = 0; j < m; j++)\n a[i] = NS();\n int[] res = new int[n];\n for (int i = 0; i < k; i++) {\n int c = NI();\n int t = NI() - 1;\n for (int j = 0; j < n; j++)\n if (a[j].charAt(t * 2) == '1' && j != c)\n res[j]++;\n }\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < n; i++)\n sb.append(res[i]).append(\" \");\n System.out.println(sb.toString());\n }\n\n class Cell {\n int i;\n boolean blocked;\n }\n\n static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st = new StringTokenizer(\"\");\n static Scanner sc = new Scanner(System.in);\n int min(int i1,int i2){return i1i2?i1:i2;}\n long max(long i1,long i2){return i1>i2?i1:i2;}\n String NS()throws Exception{while(!st.hasMoreTokens())st=new StringTokenizer(stdin.readLine());return st.nextToken();}\n String NLn() throws Exception {return stdin.readLine();}\n int NI()throws Exception{return Integer.parseInt(NS());}\n long NL()throws Exception{return Long.parseLong(NS());}\n double ND()throws Exception{return Double.parseDouble(NS());}\n int abs(int x){return x<0?-x:x;}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fcc6b78ca794e5dad83e00648846f10e", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\npublic class A {\n public static void main(String[] args) throws IOException {\n BufferedReader input =\n\t\t\tnew BufferedReader(new InputStreamReader(System.in));\n\t\tString[] temp = input.readLine().split(\" \");\n\t\tint n = Integer.parseInt(temp[0]);\n\t\tint m = Integer.parseInt(temp[1]);\n\t\tint min = Integer.parseInt(temp[2]);\n\t\tint max = Integer.parseInt(temp[3]);\n\t\tint[] arr = new int[m];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t arr[i] = Integer.parseInt(input.readLine());\n\t\t}\n\t Arrays.sort(arr);\n\t int minArr = arr[0];\n\t int maxArr = arr[arr.length - 1];\n\t if (minArr < min || maxArr > max) {\n\t System.out.println(\"Incorrect\");\n\t }\n\t if (minArr > min && maxArr == max) {\n\t if (n - m >= 1) System.out.println(\"Correct\");\n\t else System.out.println(\"Incorrect\");\n\t }\n\t if (minArr == min && maxArr < max) {\n\t if (n - m >= 1) System.out.println(\"Correct\");\n\t else System.out.println(\"Incorrect\");\n\t }\n\t if (minArr > min && maxArr < max) {\n\t if (n - m >= 2) System.out.println(\"Correct\");\n\t else System.out.println(\"Incorrect\");\n\t }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "727365dbc4e3b805882e88b1a35790b8", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "package hehe;\n\nimport java.util.Scanner;\nimport java.io.PrintWriter;\n\npublic class TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n System.out.println(\"FUCK\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bb650a79f07e2d9bca806796b2a600fc", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class DataRecovery{\n public static void main(String[] argv) throws Exception{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String[] words=br.readLine().trim().split(\" \");\n int n=Integer.parseInt(words[0]), m=Integer.parseInt(words[1]), min=Integer.parseInt(words[2]), max=Integer.parseInt(words[3]);\n boolean maxFound=false, minFound=false;\n int cur;\n for(int i=0; i=1){\n System.out.println(\"Correct\");\n }else if(n-m>=2){\n System.out.println(\"Correct\");\n }else{\n System.out.println(\"Incorrect\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ec101a27aca3e3bc4d79bc7f390b071a", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Quest\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 int t=n,s=0;\n while(t>0)\n {\n s+=t%10;\n t=t/10;\n }\n if(s%4==0)\n System.out.println(n);\n else\n {\n int r=0\n while(s%4!=0)\n {\n int m=s/4;\n int d=(((m+1)*4)-s);\n t=n+d;\n r=n+d;\n while(t>0)\n {\n s+=t%10;\n t=t/10;\n }\n }\n System.out.println(r);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "92e0bccce6175f5600faab1d7963b2d0", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0} {"lang": "Java 8", "source_code": " */\npublic class Codeforces {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n\n Scanner in = new Scanner(System.in);\n\n boolean B[] = new boolean[1005];\n \n for (int i = 0; i <= 1001; i++) {\n int Sum = 0;\n int k = i;\n while (k != 0) {\n Sum += k % 10;\n k = k / 10;\n }\n if (Sum%4==0) {\n \n B[i] = false;\n }\n else{\n B[i] = true;\n //System.out.println(\"HI\");\n }\n }\n int N = in.nextInt();\n \n while(B[N]){\n N++;\n }\n System.out.println(N);\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f71a33609c3d14a684d019489f8bc43a", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0} {"lang": "Java 8", "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 IOException\n\t{\n\t\t// your code goes here\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint orig = Integer.parseInt(br.readLine());\n while(checkDivBy4(orig) % 4 != 0){\n orig++;\n }\n System.out.println(orig);\n\t br.close();\n\t}\n\tpublic static boolean checkDivBy4(int n){\n\t int sum = 0;\n\t while(n > 0){\n\t sum += n % 10;\n\t n /= 10;\n\t }\n\t return sum;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fc339d41001d0ba7e3d039492f3351d2", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Div3_570 {\n\tpublic static int inter(int n) {\n\n\t\tint sum = 0;\n\t\tint temp = n;\n\t\twhile (n > 0) {\n\n\t\t\tsum += (n % 10);\n\t\t\tn /= 10;\n\n\t\t}\n\t\tif (sum % 4 == 0) {\n\t\t\treturn temp;\n\t\t} else {\n\t\t\treturn inter(temp + 1);\n\t\t}\n\n\t}\n\n\tpublic static void main(String args[]) {\n\t\tScanner scn = new Scanner(System.in);\n\t\tint t = scn.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tint n = scn.nextInt();\n\t\t\tSystem.out.println(inter(n));\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e3a4d0caac2f7987319f1eec5673cfaf", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Test {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String input = sc.next();\n\n int flag = 0;\n int pos = 0;\n int ans = 0;\n for (int i = 0; i < input.length(); ) {\n if (i+1 < input.length() && input.charAt(i) == 'V' && input.charAt(i + 1) == 'K') {\n i += 2;\n ans++;\n pos = ans;\n } else if (i > pos && input.charAt(i) == input.charAt(i-1)) {\n flag = 1;\n i += 2;\n } else i++;\n }\n\n System.out.println(ans + flag);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f01b45f8660ad929ab07ff0eb6b95ca0", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.;\npublic class Main\n{\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.nextLine();\n\t\tint n = 0;\n\t\twhile(s.contains(VK))\n\t\t{\n\t\t\ts = s.replaceFirst(VK, CC);\n\t\t\tn++;\n\t\t}\n\t\tfor(int i = 0; i s.length(); i++)\n\t\t{\n\t\t\tif(s.charAt(i) == 'V' s.charAt(i) == 'K')\n\t\t\t{\n\t\t\t\tif((i - 1 = 0 && s.charAt(i - 1) != 'C') (i + 1 s.length() && s.charAt(i + 1) != 'C'))\n\t\t\t\t{\n\t\t\t\t\tn++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(n);\n\t\tsc.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9ac1d56fc703e0a1a5faf1920aa6b338", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A801 {\n static int countVK(String tempString) {\n int counter = 0;\n tempString = tempString.toUpperCase();\n char[] letters = tempString.toCharArray();\n if (letters.length == 2) {\n if letters[0] == letters[1] {\n counter++;\n }\n } else {\n for(int i = 0; i < letters.length - 1; i++) {\n if (letters[i] == 'V') {\n if (letters[i+1] == 'K') {\n counter++;\n }\n }\n }\n if (tempString.contains(\"VVV\") || tempString.contains(\"KKK\")) {\n counter++;\n }\n }\n return counter;\n }\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n String inputString = input.next();\n System.out.println(countVK(inputString));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "81b94173082bd60b947693aa20a899c5", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "//\u0411\u043e\u0434\u043b\u043e\u0433\u043e 41: Vicious Keyboard. \n\nimport java.util.Scanner;\n\n\npublic class Main {\n \n static Scanner scanner = new Scanner(System.in);\n static int count = 0;\n static int chance = 1; \n\n public static void main(String[] args) throws Exception {\n \n String thisIsInputBox = new String();\n \n thisIsInputBox = scanner.nextLine();\n\n if(thisIsInputBox.length() > 100)\n {\n break;\n }\n \n char[] thisIsInput = thisIsInputBox.toCharArray();\n \n \n \n for(int i = 0; i < thisIsInput.length - 1; i++)\n {\n if(thisIsInput[i] == 'V')\n {\n if(thisIsInput[i+1] == 'K')\n {\n count++;\n \n }\n \n else \n {\n if(chance == 1)\n {\n count++;\n chance = chance - 1;\n }\n \n }\t\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(count);\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c4c6686dbd95da4cead26153534dce32", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimpott java.io.*;\n\npublic class Main{\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 if(x == 0 || y==0)\n {\n System.out.println(\"Black\");\n return;\n }\n int tmp = Math.max(x,y);\n if(x * y > 0){\n if((tmp & 1) == 0){\n System.out.println(\"White\");\n }else\n {\n System.out.println(\"Black\");\n }\n \n }else\n {\n if((tmp & 1) == 0){\n System.out.println(\"Black\");\n }else\n {\n System.out.println(\"White\");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4de0dc36c58052a463473cdd53e71e8d", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class susbus{\n public static void main(String[] args){\n Scanner in = new Scanner (System.in);\n\n \t int a = in.nextInt();\n \t int b = in.nextInt();\n\n\n \t if(Math.floor(Math.hypot(a,b))==Math.hypot(a,b))\n \t \t System.out.print(\"black\");\n\n \t \t else if(a*b>0){\n\n \t \t \tdouble d=Math.hypot(a,b);\n\n \t \t \tif(Math.floor(d)%2==1)\n \t \t \t\tSystem.out.print(\"white\");\n\n\n \t \t \telse if(Math.floor(d)%2==0)\n \tSystem.out.print(\"black\");\n\n \t \t }\n\n \t \t else if(a*b<0){\n\n \t \t \t\tdouble d=Math.hypot(a,b);\n\n \t \t \tif(Math.floor(d)%2==0)\n \t \t \t\tSystem.out.print(\"white\");\n\n\n \t \t \telse if(Math.floor(d)%2==1)\n \tSystem.out.print(\"black\");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02aba6ec7d5b81d19234ec6e7239ec92", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class FindColor\n{\n\tScanner in;\n\tPrintWriter out;\n\t\n\tFindColor()\n\t{\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\t\n\tFindColor(String i, String o) throws FileNotFoundException\n\t{\n\t\tin = new Scanner(new File(i));\n\t\tout = new PrintWriter(new File(o));\n\t}\n\t\n\tpublic void finalize()\n\t{\n\t\tout.flush();\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tint\n\t\t\tx = in.nextInt(),\n\t\t\ty = in.nextInt();\n\t\tdouble d = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));\n\t\t\n\t\t//if the distance from origin is integral, it's black\n\t\tif(d == (int)d)\n\t\t\tout.println(\"black\");\n\t\telse\n\t\t{\n\t\t\t//if one point is on the origin, it's black\n\t\t\tif(x * y == 0)\n\t\t\t\tout.println(\"black\");\n\t\t\t//if it is in 1st or 3rd quadrant\n\t\t\telse if(x * y > 0)\n\t\t\t\t//if the distance is 'even' it's black\n\t\t\t\tif((int)r % 2 == 0)\n\t\t\t\t\tout.println(\"black\");\n\t\t\t\t//else white\n\t\t\t\telse\n\t\t\t\t\tout.println(\"white\");\n\t\t\t//if it is in 2nd or 4th quadrant\n\t\t\telse\n\t\t\t\t//if the distance is 'even' it's white\n\t\t\t\tif((int)r % 2 == 0)\n\t\t\t\t\tout.println(\"white\");\n\t\t\t\t//else black\n\t\t\t\telse\n\t\t\t\t\tout.println(\"black\");\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException\n\t{\n\t\tFindColor t = new FindColor();\n\t\tt.solve();\n\t\tt.finalize();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ef1675b4983089be89c6bd66227318c5", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class FindColor\n{\n\tScanner in;\n\tPrintWriter out;\n\t\n\tFindColor()\n\t{\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\t\n\tFindColor(String i, String o) throws FileNotFoundException\n\t{\n\t\tin = new Scanner(new File(i));\n\t\tout = new PrintWriter(new File(o));\n\t}\n\t\n\tpublic void finalize()\n\t{\n\t\tout.flush();\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tint\n\t\t\tx = in.nextInt(),\n\t\t\ty = in.nextInt();\n\t\tdouble d = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));\n\t\t\n\t\t//if the distance from origin is integral, it's black\n\t\tif(d == (int)d)\n\t\t\tout.println(\"black\");\n\t\telse\n\t\t{\n\t\t\t//if one point is on the origin, it's black\n\t\t\tif(x * y == 0)\n\t\t\t\tout.println(\"black\");\n\t\t\t//if it is in 1st or 3rd quadrant\n\t\t\telse if(x * y > 0)\n\t\t\t\t//if the distance is 'even' it's black\n\t\t\t\tif((int)r % 2 == 0)\n\t\t\t\t\tout.println(\"black\")\n\t\t\t\t//else white\n\t\t\t\telse\n\t\t\t\t\tout.println(\"white\");\n\t\t\t//if it is in 2nd or 4th quadrant\n\t\t\telse\n\t\t\t\t//if the distance is 'even' it's white\n\t\t\t\tif((int)r % 2 == 0)\n\t\t\t\t\tout.println(\"white\");\n\t\t\t\t//else black\n\t\t\t\telse\n\t\t\t\t\tout.println(\"black\");\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException\n\t{\n\t\tFindColor t = new FindColor();\n\t\tt.solve();\n\t\tt.finalize();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7a674e7013f0d0b23d9192776e40241f", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 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 CBearAndCompany solver = new CBearAndCompany();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CBearAndCompany {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n char[] s = in.readString().toCharArray();\n int[][][] prev = new int[n + 1][n + 1][n + 1];\n int[][][] next = new int[n + 1][n + 1][n + 1];\n\n int[] lastNoWord = new int[n];\n int[] nextNoWord = new int[n];\n for (int i = 0; i < n; i++) {\n lastNoWord[i] = -1;\n if (s[i] != 'V' && s[i] != 'K') {\n lastNoWord[i] = i;\n } else if (i > 0) {\n lastNoWord[i] = lastNoWord[i - 1];\n }\n }\n for (int i = n - 1; i >= 0; i--) {\n nextNoWord[i] = -1;\n if (s[i] != 'V' && s[i] != 'K') {\n nextNoWord[i] = i;\n } else if (i + 1 < n) {\n nextNoWord[i] = nextNoWord[i + 1];\n }\n }\n IntegerPreSum ips = new IntegerPreSum(i -> s[i] == 'V' ? 1 : 0, n);\n\n int inf = (int) 1e9;\n SequenceUtils.deepFill(prev, inf);\n prev[0][0][0] = 0;\n for (int i = 0; i < n; i++) {\n SequenceUtils.deepFill(next, inf);\n for (int j = 0; j <= n; j++) {\n for (int k = 0; k <= n; k++) {\n for (int t = 0; t <= n; t++) {\n if (s[i] == 'V') {\n //do nothing\n if (j + 1 <= n) {\n next[j + 1][k][t] = Math.min(next[j + 1][k][t], prev[j][k][t]);\n }\n //move first\n if (lastNoWord[i] != -1) {\n next[j][k][t] = Math.min(next[j][k][t], prev[j][k][t] + j + k + 1);\n }\n } else if (s[i] == 'K') {\n //move before all V\n if (k + 1 <= n && t == 0) {\n next[j][k + 1][t] = Math.min(next[j][k + 1][t], prev[j][k][t] + j);\n }\n //move after\n if (t + 1 <= n && nextNoWord[i] != -1) {\n next[j][k][t + 1] = Math.min(next[j][k][t + 1], prev[j][k][t] + ips.intervalSum(i, nextNoWord[i]));\n }\n } else {\n next[0][t][0] = Math.min(next[0][t][0], prev[j][k][t] + t);\n }\n }\n }\n }\n\n int[][][] tmp = next;\n next = prev;\n prev = tmp;\n }\n\n int ans = inf;\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n ans = Math.min(ans, prev[i][j][0]);\n }\n }\n\n out.println(ans);\n }\n\n }\n\n static class SequenceUtils {\n public static void deepFill(Object array, int val) {\n if (!array.getClass().isArray()) {\n throw new IllegalArgumentException();\n }\n if (array instanceof int[]) {\n int[] intArray = (int[]) array;\n Arrays.fill(intArray, val);\n } else {\n Object[] objArray = (Object[]) array;\n for (Object obj : objArray) {\n deepFill(obj, val);\n }\n }\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private StringBuilder defaultStringBuf = new StringBuilder(1 << 13);\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n public String readString(StringBuilder builder) {\n skipBlank();\n\n while (next > 32) {\n builder.append((char) next);\n next = read();\n }\n\n return builder.toString();\n }\n\n public String readString() {\n defaultStringBuf.setLength(0);\n return readString(defaultStringBuf);\n }\n\n }\n\n static class IntegerPreSum {\n private int[] pre;\n private int n;\n\n public IntegerPreSum(int n) {\n pre = new int[n];\n }\n\n public void populate(IntToIntegerFunction a, int n) {\n this.n = n;\n if (n == 0) {\n return;\n }\n pre[0] = a.apply(0);\n for (int i = 1; i < n; i++) {\n pre[i] = pre[i - 1] + a.apply(i);\n }\n }\n\n public IntegerPreSum(IntToIntegerFunction a, int n) {\n this(n);\n populate(a, n);\n }\n\n public int intervalSum(int l, int r) {\n return prefix(r) - prefix(l - 1);\n }\n\n public int prefix(int i) {\n if (i < 0) {\n return 0;\n }\n return pre[Math.min(i, n - 1)];\n }\n\n }\n\n static interface IntToIntegerFunction {\n int apply(int x);\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f2d8868aef1d0d4485e3e1abc2e4f954", "src_uid": "08444f9ab1718270b5ade46852b155d7", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 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 CBearAndCompany solver = new CBearAndCompany();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CBearAndCompany {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n char[] s = in.readString().toCharArray();\n int V = 0;\n int K = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == 'V') {\n V++;\n }\n if (s[i] == 'K') {\n K++;\n }\n }\n\n int[][][][] prev = new int[V + 1][K + 1][K + 1][V + 1];\n int[][][][] next = new int[V + 1][K + 1][K + 1][V + 1];\n\n int[] lastNoWord = new int[n];\n int[] nextNoWord = new int[n];\n for (int i = 0; i < n; i++) {\n lastNoWord[i] = -1;\n if (s[i] != 'V' && s[i] != 'K') {\n lastNoWord[i] = i;\n } else if (i > 0) {\n lastNoWord[i] = lastNoWord[i - 1];\n }\n }\n for (int i = n - 1; i >= 0; i--) {\n nextNoWord[i] = -1;\n if (s[i] != 'V' && s[i] != 'K') {\n nextNoWord[i] = i;\n } else if (i + 1 < n) {\n nextNoWord[i] = nextNoWord[i + 1];\n }\n }\n\n int inf = (int) 1e9;\n SequenceUtils.deepFill(prev, inf);\n prev[0][0][0][0] = 0;\n for (int i = 0; i < n; i++) {\n SequenceUtils.deepFill(next, inf);\n for (int j = 0; j <= V; j++) {\n for (int k = 0; k <= K; k++) {\n for (int t = 0; t <= K; t++) {\n for (int a = 0; a <= V; a++) {\n if (s[i] == 'V') {\n //do nothing\n if (j + 1 <= V && a == 0) {\n next[j + 1][k][t][a] = Math.min(next[j + 1][k][t][a], prev[j][k][t][a] + t + a);\n }\n //move first\n if (lastNoWord[i] != -1 && j == 0 && a == 0) {\n next[j][k][t][a] = Math.min(next[j][k][t][a], prev[j][k][t][a] + j + k + t + a + 1);\n }\n //add to\n if (a + 1 <= V && nextNoWord[i] != -1) {\n next[j][k][t][a + 1] = Math.min(next[j][k][t][a + 1], prev[j][k][t][a]);\n }\n } else if (s[i] == 'K') {\n //move before all V\n if (k + 1 <= K && t == 0) {\n next[j][k + 1][t][a] = Math.min(next[j][k + 1][t][a], prev[j][k][t][a] + j + a + t);\n }\n //move after\n if (t + 1 <= K && nextNoWord[i] != -1) {\n next[j][k][t + 1][a] = Math.min(next[j][k][t + 1][a], prev[j][k][t][a] + a);\n }\n } else {\n next[a][t][0][0] = Math.min(next[a][t][0][0], prev[j][k][t][a] + t + a);\n }\n }\n }\n }\n }\n\n int[][][][] tmp = next;\n next = prev;\n prev = tmp;\n }\n\n int ans = inf;\n for (int i = 0; i <= V; i++) {\n for (int j = 0; j <= K; j++) {\n ans = Math.min(ans, prev[i][j][0][0]);\n }\n }\n\n out.println(ans);\n }\n\n }\n\n static class SequenceUtils {\n public static void deepFill(Object array, int val) {\n if (!array.getClass().isArray()) {\n throw new IllegalArgumentException();\n }\n if (array instanceof int[]) {\n int[] intArray = (int[]) array;\n Arrays.fill(intArray, val);\n } else {\n Object[] objArray = (Object[]) array;\n for (Object obj : objArray) {\n deepFill(obj, val);\n }\n }\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private StringBuilder defaultStringBuf = new StringBuilder(1 << 13);\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n public String readString(StringBuilder builder) {\n skipBlank();\n\n while (next > 32) {\n builder.append((char) next);\n next = read();\n }\n\n return builder.toString();\n }\n\n public String readString() {\n defaultStringBuf.setLength(0);\n return readString(defaultStringBuf);\n }\n\n }\n\n static class 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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "81efb95c64d59886873f77ff6a626cbb", "src_uid": "08444f9ab1718270b5ade46852b155d7", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class J implements Runnable {\n\n private static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n private void init() throws FileNotFoundException {\n Locale.setDefault(Locale.US);\n String fileName = \"\";\n if (ONLINE_JUDGE && fileName.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n if (fileName.isEmpty()) {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } else {\n in = new BufferedReader(new FileReader(fileName + \".in\"));\n out = new PrintWriter(fileName + \".out\");\n }\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n int[] readIntArray(int size) throws IOException {\n int[] a = new int[size];\n for (int i = 0; i < size; i++) {\n a[i] = readInt();\n }\n return a;\n }\n\n public static void main(String[] args) {\n //new Thread(null, new _Solution(), \"\", 128 * (1L << 20)).start();\n new J().run();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n @Override\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n init();\n solve();\n out.close();\n time();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n int[][][][] dp;\n char[] s;\n int INF = 10000000;\n\n int solve(int v, int k, int x, int last) {\n if (v < 0) return INF;\n if (k < 0) return INF;\n if (x < 0) return INF;\n if (dp[v][k][x][last] != -1) {\n return dp[v][k][x][last];\n }\n int res = INF;\n if (last == 0 && v > 0) {\n //v\n for (int i = 0; i < 3; i++) {\n res = Math.min(res, solve(v - 1, k, x, i));\n }\n return res + count(s, 'V', v, k, x);\n }\n if (last == 1 && k > 0) {\n //K\n res = Math.min(solve(v, k - 1, x, 1), solve(v, k - 1, x, 2));\n return res + count(s, 'K', v, k, x);\n }\n if (last == 2 && x > 0) {\n for (int i = 0; i < 3; i++) {\n res = Math.min(res, solve(v, k, x - 1, i));\n }\n return res + + count(s, 'X', v, k, x);\n }\n return INF;\n }\n\n int count(char[] s, char target, int v, int k, int x) {\n int answer = 0;\n for (char c : s) {\n if (c == 'V') {\n v--;\n if (v == 0 && target == 'V') return answer;\n if (v < 0) answer++;\n }\n if (c == 'K') {\n k--;\n if (k == 0 && target == 'K') return answer;\n if (k < 0) answer++;\n }\n if (c == 'X') {\n x--;\n if (x == 0 && target == 'X') return answer;\n if (x < 0) answer++;\n }\n }\n throw new RuntimeException();\n }\n\n private void solve() throws IOException {\n int n = readInt();\n s = readString().toCharArray();\n int vcnt = 0, kcnt = 0, xcnt = 0;\n for (int i = 0; i < s.length; i++) {\n if (s[i] == 'V') {\n vcnt++;\n continue;\n }\n if (s[i] == 'K') {\n kcnt++;\n continue;\n }\n xcnt++;\n s[i] = 'X';\n }\n dp = new int[vcnt + 1][kcnt + 1][xcnt + 1][3];\n for (int[][][] x : dp) {\n for (int[][] xx : x) {\n for (int[] xxx : xx) {\n Arrays.fill(xxx, -1);\n }\n }\n }\n dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;\n int res = INF;\n for (int i = 0; i < 3; i++) {\n res = Math.min(res, solve(vcnt, kcnt, xcnt, i));\n }\n out.println(res);\n\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e3ba951643face777330fd9e57fc39a", "src_uid": "08444f9ab1718270b5ade46852b155d7", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n static final int INF = (int) 1e9;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n String s = in.next();\n int nk = 0;\n int nv = 0;\n int no = 0;\n int[] kpos = new int[n];\n int[] vpos = new int[n];\n int[] opos = new int[n];\n int[] snk = new int[n + 1];\n int[] snv = new int[n + 1];\n int[] sno = new int[n + 1];\n for (int i = 0; i < n; ++i) {\n char ch = s.charAt(i);\n if (ch == 'V') {\n vpos[nv++] = i;\n } else if (ch == 'K') {\n kpos[nk++] = i;\n } else {\n opos[no++] = i;\n }\n snk[i + 1] = nk;\n snv[i + 1] = nv;\n sno[i + 1] = no;\n }\n int[][][][] best = new int[2][nk + 1][nv + 1][no + 1];\n for (int[][][] x : best) for (int[][] y : x) for (int[] z : y) Arrays.fill(z, INF);\n best[0][0][0][0] = 0;\n for (int k = 0; k <= nk; ++k) {\n for (int v = 0; v <= nv; ++v) {\n for (int o = 0; o <= no; ++o) {\n for (int hv = 0; hv < 2; ++hv) {\n int cur = best[hv][k][v][o];\n if (k < nk && hv == 0) {\n best[0][k + 1][v][o] = Math.min(best[0][k + 1][v][o], cur + Math.max(snv[kpos[k]] - v,0) + Math.max(sno[kpos[k]] - o),0);\n }\n if (v < nv) {\n best[1][k][v + 1][o] = Math.min(best[1][k][v + 1][o], cur + Math.max(snk[vpos[v]] - k,0) + Math.max(sno[vpos[v]] - o),0);\n }\n if (o < no) {\n best[0][k][v][o + 1] = Math.min(best[0][k][v][o + 1], cur + Math.max(snv[opos[o]] - v,0) + Math.max(snk[opos[o]] - k),0);\n }\n }\n }\n }\n }\n out.println(Math.min(best[0][nk][nv][no], best[1][nk][nv][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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1224a59646a3748afc8f9cffed498b62", "src_uid": "08444f9ab1718270b5ade46852b155d7", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n * Codeforces #68C \"Synchrophasotron\"\n * @link http://codeforces.ru/problemset/problem/68/C\n * @author Caesar\n */\npublic class Solution68C implements Runnable {\n\n private static final int EXIT_CODE = -1;\n private static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n private static final String INPUT = \"input.txt\";\n private static final String OUTPUT = \"output.txt\";\n\n private StringTokenizer tok;\n private BufferedReader in;\n private PrintWriter out;\n\n public static void main(String[] args) {\n new Thread(new Solution68C()).start();\n }\n\n public void run() {\n try {\n in = ONLINE_JUDGE ?\n new BufferedReader(new InputStreamReader(System.in)) :\n new BufferedReader(new FileReader(INPUT));\n out = ONLINE_JUDGE ? new PrintWriter(System.out) : new PrintWriter(OUTPUT);\n long start = System.currentTimeMillis();\n try {\n solve();\n } finally {\n if (ONLINE_JUDGE) {\n out.flush();\n } else {\n out.close();\n }\n }\n System.err.println(\"Time used: \" + (System.currentTimeMillis() - start));\n } catch (Throwable ex) {\n ex.printStackTrace();\n System.exit(EXIT_CODE);\n }\n }\n\n private String readString() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n private int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n \n int n;\n private int[][] flow;\n private int[][] l;\n private int[][] h;\n private int[][] a;\n private int minFlow = Integer.MAX_VALUE;\n private int maxCost = Integer.MIN_VALUE;\n\n private void brute(int start, int finish) {\n if (start == finish) {\n if (!isValid()) {\n return;\n }\n int f = getFlow(n - 1);\n int c = getCost();\n if (f < minFlow) {\n minFlow = f;\n maxCost = c;\n } else if (f == minFlow) {\n if (c > maxCost) {\n maxCost = c;\n }\n }\n return;\n }\n for (flow[start][finish] = l[start][finish]; flow[start][finish] <= Math.min(h[start][finish], getFlow(start)); ++flow[start][finish]) {\n if (start == n - 2 && finish == n - 1) {\n brute(n - 1, n - 1);\n } else if (finish == n - 1) {\n brute(start + 1, start + 2);\n } else {\n brute(start, finish + 1);\n }\n }\n }\n\n private boolean isValid() {\n for (int i = 1; i < n - 1; ++i) {\n int send = 0;\n int recv = 0;\n for (int j = 0; j < i; ++j) {\n recv += flow[j][i];\n }\n for (int j = i + 1; j < n; ++j) {\n send += flow[i][j];\n }\n if (send != recv) {\n return false;\n }\n }\n return true;\n }\n\n private int getFlow(int v) {\n if (v == 0) {\n return Integer.MAX_VALUE;\n }\n int ans = 0;\n for (int i = 0; i < v; ++i) {\n ans += flow[i][v];\n }\n return ans;\n }\n\n private int getCost() {\n int ans = 0;\n for (int i = 0; i < n; ++i) {\n for (int j = i + 1; j < n; ++j) {\n ans += flow[i][j] == 0 ? 0 : a[i][j] + flow[i][j] * flow[i][j];\n }\n }\n return ans;\n }\n\n public void solve() throws IOException {\n n = readInt();\n l = new int[n][n];\n h = new int[n][n];\n a = new int[n][n];\n flow = new int[n][n];\n int m = n * (n - 1) >> 1;\n for (int i = 0; i < m; ++i) {\n int s = readInt() - 1;\n int f = readInt() - 1;\n l[s][f] = readInt();\n h[s][f] = readInt();\n a[s][f] = readInt();\n }\n brute(0, 1);\n out.println(minFlow == Integer.MAX_VALUE ? \"-1 -1\" : (minFlow + \" \" + maxCost));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "550cd625d2c42be6ab1c28341dbf81bd", "src_uid": "38886ad7b0d83e66b77348be34828426", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "\nimport java.awt.Point;\nimport java.awt.geom.Line2D;\nimport java.awt.geom.Point2D;\nimport java.io.*;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\nimport java.util.*;\npublic class C{\n\tint n;\n\tint[][]min;\n\tint[][]max;\n\tint[][]active;\t\t\n\tint[]pFlow;\n\tint inf=Integer.MAX_VALUE/100;\t\n\tvoid solve()throws Exception\n\t{\t\t\n\t\t\n\t\tn=nextInt();\n\t\tmin=new int[n][n];\n\t\tmax=new int[n][n];\n\t\tactive=new int[n][n];\n\t\tint sum=0;\n\t\tfor(int step=1;step<=n*(n-1)/2;step++)\n\t\t{\n\t\t\tint a=nextInt()-1;\n\t\t\tint b=nextInt()-1;\n\t\t\tmin[a][b]=nextInt();\n\t\t\tmax[a][b]=nextInt();\n\t\t\tactive[a][b]=nextInt();\n\t\t\tsum+=max[a][b];\n\t\t}\n\t\tsum++;\t\t\t\t\t\t\t\t\n\t\tpFlow=new int[n];\n\t\tint[]res=rec(0,1);\n\t\tif(res==null)\n\t\t\tres=new int[]{-1,-1};\n\t\tSystem.out.println(res[0]+\" \"+res[1]);\n\t}\n\n\t\n\tprivate int[] rec(int a, int b) {\n\t\tif(a==n-1)\n\t\t{\t\t\t\t\t\t\t\t\t\n\t\t\treturn new int[]{pFlow[0],0};\n\t\t}\n\t\tint[]res=null;\n\t\tif(b==n)\n\t\t{\n\t\t\tif(a!=0 && pFlow[a]!=0)\n\t\t\t\treturn null;\n\t\t\treturn rec(a+1,a+2);\n\t\t}\n\t\telse\n\t\t{\t\t\n\t\t\tfor(int x=min[a][b];x<=max[a][b];x++)\n\t\t\t{\n\t\t\t\tint curCost=x*x+(x>0?active[a][b]:0);\n\t\t\t\tpFlow[a]+=x;\n\t\t\t\tpFlow[b]-=x;\n\t\t\t\tint[]next=rec(a,b+1);\n\t\t\t\tif(next!=null)\n\t\t\t\t{\n\t\t\t\t\tnext[1]+=curCost;\n\t\t\t\t\tif(res==null || (res[0]>next[0] || (res[0]==next[0] && res[1] 0) {\n minFlow = f;\n maxCost = c;\n } else if (f == minFlow) {\n if (c > maxCost) {\n maxCost = c;\n }\n }\n return;\n }\n for (flow[start][finish] = 0; flow[start][finish] <= border; ++flow[start][finish]) {\n if (start == n - 2 && finish == n - 1) {\n brute(n - 1, n - 1);\n } else if (finish == n - 1) {\n brute(start + 1, start + 2);\n } else {\n brute(start, finish + 1);\n }\n }\n }\n\n private boolean isValid() {\n for (int i = 0; i < n; ++i) {\n for (int j = i + 1; j < n; ++j) {\n if (flow[i][j] < l[i][j] || flow[i][j] > h[i][j]) {\n return false;\n }\n }\n }\n for (int i = 1; i < n - 1; ++i) {\n int send = 0;\n int recv = 0;\n for (int j = 0; j < i; ++j) {\n recv += flow[j][i];\n }\n for (int j = i + 1; j < n; ++j) {\n send += flow[i][j];\n }\n if (send != recv) {\n return false;\n }\n }\n return true;\n }\n\n private int getFlow() {\n int ans = 0;\n for (int i = 0; i < n - 1; ++i) {\n ans += flow[i][n - 1];\n }\n return ans;\n }\n\n private int getCost() {\n int ans = 0;\n for (int i = 0; i < n; ++i) {\n for (int j = i + 1; j < n; ++j) {\n ans += flow[i][j] == 0 ? 0 : a[i][j] + flow[i][j] * flow[i][j];\n }\n }\n return ans;\n }\n\n public void solve() throws IOException {\n n = readInt();\n l = new int[n][n];\n h = new int[n][n];\n a = new int[n][n];\n flow = new int[n][n];\n int m = n * (n - 1) >> 1;\n for (int i = 0; i < m; ++i) {\n int s = readInt() - 1;\n int f = readInt() - 1;\n l[s][f] = readInt();\n h[s][f] = readInt();\n a[s][f] = readInt();\n }\n border = 0;\n for (int i = 1; i < n; ++i) {\n border += h[0][i];\n }\n brute(0, 1);\n System.out.println(minFlow == Integer.MAX_VALUE ? \"-1 -1\" : (minFlow + \" \" + maxCost));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60ea91b84a9380ef286be9f4efbdada4", "src_uid": "38886ad7b0d83e66b77348be34828426", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class BaiC {\n \n int n;\n int[][] a, low, high;\n boolean[][] b;\n int[][] c;\n int[][] edges;\n int[] e;\n \n int[] best = null;\n \n void duyet(int pos, int cost) {\n if(pos == edges.length) {\n for(int i=1;i+1 -e[0] || (best[0] == -e[0] && best[1] < cost)) {\n best = new int[]{-e[0], cost};\n }\n return;\n }\n \n int u = edges[pos][0];\n int v = edges[pos][1];\n \n if(best != null && best[0] < -e[0]) return;\n \n boolean tiep = true;\n for(int i=1;i+10)\n a[i] = ws[i].length\n else\n l--;\n }\n p.println(l);\n for(int i=0;i= 30){\n \tSystem.exit(1);\n } else if (a <= 1){\n \tSystem.exit(1);\n }\n\t\tint y = 30 - a;\n\n\t\tSystem.out.print(y);\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "784d9b3e6544b287858e5c8e43072278", "src_uid": "bf65a25185e9ea5b71e853723b838b04", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class AprilA {\n\tpublic static void main(String[] args) \t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tSystem.out.println(272727272727272727272727272727272727272727272727272727);\n\n\n\t}\n\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "63688437e935ef9e8b997ed5a9648e56", "src_uid": "bf65a25185e9ea5b71e853723b838b04", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class NumberJoke {\n public static void main (String[] args) {\n Scanner scanner = new Scanner(System.in);\n int a= Scanner.nextInt();\n int[] b={4,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};\n System.out.println(b[a-1]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aed7851f081844cf6e633b21b76637ff", "src_uid": "bf65a25185e9ea5b71e853723b838b04", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "public class Test{\npublic static void main(String[] args){\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n System.out.println((40-1-n-n*n));\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5780b51e06823cdfcba04f0eaea1701a", "src_uid": "bf65a25185e9ea5b71e853723b838b04", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class sample {\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(in.readLine());\n StringTokenizer st = new StringTokenizer(in.readLine());\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = Integer.parseInt(st.nextToken());\n int max = -1;\n int smax = -1;\n for (int i = 0; i < n; i++)\n if (max < a[i])\n max = a[i];\n for (int i = 0; i < n; i++)\n if (smax < a[i] && a[i] != max)\n smax = a[i];\n if(max >= 2* smax)\n System.out.println(\"NO\");\n else\n System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe996eacbde7eee285e0d872be7f7b1d", "src_uid": "ab003ab094931fc105384df9d144131e", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n try {\n if (new File(\"input.txt\").exists())\n System.setIn(new FileInputStream(\"input.txt\"));\n } catch (SecurityException e) {\n }\n new Main().run();\n \n }\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st = new StringTokenizer(\"\");\n\n private void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n \n int n = nextInt();\n long a[] = new long[n];\n \n for(int i = 0; i < n; i++) a[i] = nextInt();\n \n sort(a);\n \n long mx2 = a[n - 1];\n for(int i = n - 1; i >= 0; i--){\n if(a[i] < mx2){\n mx2 = a[i];\n break;\n }\n }\n \n if(mx2 * 2 <= a[n - 1]) out.println(\"NO\");\n else out.println(\"YES\");\n in.close();\n out.close();\n }\n\n void chk(boolean b) {\n if (b)\n return;\n System.out.println(new Error().getStackTrace()[1]);\n exit(999);\n }\n void deb(String fmt, Object... args) {\n System.out.printf(Locale.US, fmt + \"%n\", args);\n }\n String nextToken() throws IOException {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(in.readLine());\n return st.nextToken();\n }\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n String nextLine() throws IOException {\n st = new StringTokenizer(\"\");\n return in.readLine();\n }\n boolean EOF() throws IOException {\n while (!st.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null)\n return true;\n st = new StringTokenizer(s);\n }\n return false;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b3a401dda4a7dcc1e972e3bac043d89", "src_uid": "ab003ab094931fc105384df9d144131e", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "\npublic class Datatypes {\n public static void main(String[] args) throws NumberFormatException,\n IOException {\n BufferedReader buf = new BufferedReader(\n new InputStreamReader(System.in));\n int n = Integer.parseInt(buf.readLine());\n int[] array = new int[n];\n String[] line = buf.readLine().split(\" \");\n for (int i = 0; i < n; i++)\n array[i] = Integer.parseInt(line[i]);\n\n boolean check = true;\n Arrays.sort(array);\n for (int i = 0; i < n-1 && check; i++) {\n if (array[i] != array[i+1]) {\n check = find(array[i], array[i+1]);\n } \n }\n if (check)\n System.out.println(\"NO\");\n else\n System.out.println(\"YES\");\n }\n\n public static boolean find(int a, int b) {\n if (a == 1)\n return true;\n else {\n if (2 * a > b)\n return false;\n else\n return true;\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "730de0def9359b3191f35d8a592a4521", "src_uid": "ab003ab094931fc105384df9d144131e", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\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.Iterator;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.io.BufferedWriter;\nimport java.io.FileInputStream;\nimport java.io.FileWriter;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\n\n\n\npublic class TaskB {\n\t\n\tfinal static int size = 200005;\n\t\n\tpublic static long[] getWithoutCopies(long[] mas) {\n\t\tHashSet withoutCopies = new HashSet();\n\t\tfor (int i = 0; i < mas.length; ++i) {\n\t\t\twithoutCopies.add(mas[i]);\n\t\t}\n\t\tlong[] result = new long[withoutCopies.size()];\n\t\tIterator it = withoutCopies.iterator();\n\t\tint j = 0;\n\t\twhile (it.hasNext()) {\n\t\t\tresult[j++] = it.next();\n\t\t}\n\t\treturn result;\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tPrintWriter jout = new PrintWriter(System.out);\n\t\tScanner jin = new Scanner(new InputStreamReader(System.in));\n\t\tint n = jin.nextInt();\n\t\t//String a = jin.nextLine();\n\t\t//a = jin.nextLine();\n\t\tlong mas[] = new long[n];\n\t\tStringTokenizer t = new StringTokenizer(a);\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tmas[i] = jin.nextLong();\n\t\t}\n\t\n\t\tmas = getWithoutCopies(mas);\n\t\tArrays.sort(mas);\n\t\tfor (int i = 1; i < mas.length; ++i) {\n\t\t\tif (mas[i] < 2 * mas[i - 1]) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t\tjout.close();\n\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bcc61b3fa4c684b2b157382af688351a", "src_uid": "ab003ab094931fc105384df9d144131e", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n * Date 22.11.2011 \n * Time 19:00:19 \n * Author Woodey \n * $\n */\n\npublic class A73 {\n\tprivate void Solution() throws IOException {\n\t\tint x = nextInt(), y = nextInt(), z = nextInt(), k = nextInt();\n\t\tk = Math.min(k, x + y + z - 3);\n\t\tlong a = 1, b = 1, c = 1;\n\t\twhile (true) {\n\t\t\tif (a < x) {\n\t\t\t\ta ++;\n\t\t\t\tk --;\n\t\t\t}\n\t\t\tif (k == 0)\n\t\t\t\tbreak;\n\t\t\tif (b < y) {\n\t\t\t\tb ++;\n\t\t\t\tk --;\n\t\t\t}\n\t\t\tif (k == 0)\n\t\t\t\tbreak;\n\t\t\tif (c < z) {\n\t\t\t\tc ++;\n\t\t\t\tk --;\n\t\t\t}\n\t\t\tif (k == 0)\n\t\t\t\tbreak;\n\t\t}\n\t\tSystem.out.println(a * b * c);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A73().run();\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer tokenizer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t\tSolution();\n\t\t\tin.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\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(in.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "015d9658b4b9956e333d609827dd8d29", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: shakhov\n * Date: 15.06.2011\n * Time: 15:22:46\n * To change this template use File | Settings | File Templates.\n */\n\n//6\n//86 402 133 524 405 610 6 4 1\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class CodeForces {\n\n\tpublic void solve() throws IOException {\n\t\tint arr[] = new int[3];\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tarr[i] = nextInt() - 1;\n\t\t}\n\t\tint k = nextInt();\n\t\tint cur[] = { 0, 0, 0 };\n\t\tboolean[] cure = { 0==arr[0], 0==arr[1], 0==arr[2]};\n\t\twhile (k > 0) {\n\t\t\tif ((cur[0] <= cur[1] || cure[1]) && (cur[0] <= cur[2] || cure[2]) && !cure[0]) {\n\t\t\t\tcur[0]++;\n\t\t\t\tif (cur[0] == arr[0])\n\t\t\t\t\tcure[0] = true;\n\t\t\t} else if ((cur[1] <= cur[0] || cure[0]) && (cur[1] <= cur[2] || cure[2]) && !cure[1]) {\n\t\t\t\tcur[1]++;\n\t\t\t\tif (cur[1] == arr[1])\n\t\t\t\t\tcure[1] = true;\n\t\t\t} else if ((cur[2] <= cur[1] || cure[1]) && (cur[2] <= cur[0] || cure[0]) && !cure[2]) {\n\t\t\t\tcur[2]++;\n\t\t\t\tif (cur[2] == arr[2])\n\t\t\t\t\tcure[2] = true;\n\t\t\t}\n\t\t\tk--;\n\t\t}\n\t\tout.println((cur[0] + 1) * (cur[1] + 1) * (cur[2] + 1));\n\t}\n\n\tprivate BufferedReader reader;\n\tprivate StringTokenizer tokenizer;\n\tprivate String separator;\n\tpublic PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tnew CodeForces().run(new InputStreamReader(System.in), new OutputStreamWriter(System.out));\n\t}\n\n\tpublic void run(Reader reader, Writer writer) {\n\t\ttry {\n\t\t\tthis.reader = new BufferedReader(reader);\n\t\t\tout = new PrintWriter(writer);\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t\tseparator = System.getProperty(\"line.separator\");\n\t\t\tseparator = Character.toString(separator.charAt(separator.length() - 1));\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\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\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "346e2086bd7dfab4f76718ad56017a21", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\n\npublic class elder{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\n\t\tint x = scan.nextInt();\n\t\tint y = scan.nextInt();\n\t\tint z = scan.nextInt();\n\t\tint k = scan.nextInt();\n\n\t\tif(k == 0){\n\t\t\tSystem.out.println(\"1\");\n\t\t\treturn;\n\t\t}\n\n\t\tif(k >= x + y + z - 3){\n\t\t\tSystem.out.println(bigIntegerFromInt(x).multiply(bigIntegerFromInt(y)).multiply(bigIntegerFromInt(z)));\n\t\t\treturn;\n\t\t}\n\n\t\tBigInteger pieces = new BigInteger(\"1\");\n\n\t\tBigInteger[] planePieces = {new BigInteger(\"1\"), new BigInteger(\"1\"), new BigInteger(\"1\")};\n\t\tint[] dims = {x - 1, y - 1, z - 1};\n\t\tint[] cuts = {0, 0, 0};\n\t\tint j = 0;\n\n\t\twhile(k > 0){\n\t\t\tif(dims[j] == 0){\n\t\t\t\tj = (j + 1) % 3;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdims[j]--;\n\t\t\tcuts[j]++;\n\n\t\t\tpieces = pieces.add(planePieces[j]);\n\n\t\t\tplanePieces[(j + 1) % 3] = planePieces[(j + 1) % 3].add(bigIntegerFromInt(cuts[(j + 2) % 3] + 1));\n\t\t\tplanePieces[(j + 2) % 3] = planePieces[(j + 2) % 3].add(bigIntegerFromInt(cuts[(j + 4) % 3] + 1));\n\t\t\tk--;\n\t\t\tj = (j + 1) % 3;\n\t\t}\n\n\t\tSystem.out.println(pieces.toString());\n\t}\n\n\tpublic static int countDimsLeft(int[] dims){\n\t\tint dimsleft = 0;\n\t\tfor(int i = 0; i < dims.length; i++){\n\t\t\tif(dims[i] > 0) dimsleft++;\n\t\t}\n\t\treturn dimsleft;\n\t}\n\n\tpublic static BigInteger bigIntegerFromInt(int n){\n\t\treturn new BigInteger(new Integer(n).toString());\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bab798169fd81867ec1de7fa05d49bdc", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class TaskC {\n private static final double CERTAINTY = 0;\n\n @SuppressWarnings({\"FieldCanBeLocal\", \"UnusedDeclaration\"})\n private final InputReader in;\n private final PrintWriter out;\n private final boolean testMode;\n\n private static class Rational {\n private final int a;\n private final int b;\n\n private Rational(int a, int b) {\n int g = gcd(a, b);\n this.a = a / g;\n this.b = b / g;\n }\n\n private 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 @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Rational rational = (Rational) o;\n\n return a == rational.a && b == rational.b;\n\n }\n\n @Override\n public int hashCode() {\n int result = a;\n result = 31 * result + b;\n return result;\n }\n }\n\n private void solve() {\n int[] array = new int[50000000];\n array = null;\n array = new int[50000000];\n }\n\n private int reverse(int v) {\n int result = 0;\n while (v != 0) {\n result *= 10;\n result += v % 10;\n v /= 10;\n }\n return result;\n }\n\n public static class IntervalTree {\n private int[] left;\n private int[] right;\n private int[] value;\n\n public IntervalTree(int size) {\n left = new int[4 * size];\n right = new int[4 * size];\n value = new int[4 * size];\n init(0, size, 0);\n }\n\n private void init(int left, int right, int root) {\n this.left[root] = left;\n this.right[root] = right;\n if (right - left > 1) {\n init(left, (left + right) / 2, 2 * root + 1);\n init((left + right) / 2, right, 2 * root + 2);\n }\n }\n\n public int lowerBound(int value) {\n return lowerBound(value, 0);\n }\n\n private int lowerBound(int value, int root) {\n if (right[root] - left[root] == 1)\n return left[root];\n if (this.value[2 * root + 1] >= value)\n return lowerBound(value, 2 * root + 1);\n return lowerBound(value - this.value[2 * root + 1], 2 * root + 2);\n }\n\n public void putValue(int position, int value) {\n putValue(position, value, 0);\n }\n\n private void putValue(int position, int value, int root) {\n if (left[root] > position || right[root] <= position)\n return;\n this.value[root] += value;\n if (right[root] - left[root] > 1) {\n putValue(position, value, 2 * root + 1);\n putValue(position, value, 2 * root + 2);\n }\n }\n }\n\n private static List createTests() {\n List tests = new ArrayList();\n tests.add(new Test(\"2 2 1\", \"1 1\"));\n tests.add(new Test(\"132 10 35\", \"7 5\"));\n tests.add(new Test(\"5 18 1000\", \"-1\"));\n tests.add(new Test(\"48 132 235\", \"22 111\"));\n tests.add(new Test(\"100000 100000 1\", \"1 1\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n// tests.add(new Test(\"\", \"\"));\n return tests;\n }\n\n private void run() {\n //noinspection InfiniteLoopStatement\n// while (true)\n// int testCount = in.readInt();\n// for (int i = 0; i < testCount; i++)\n solve();\n exit();\n }\n\n private TaskC() {\n @SuppressWarnings({\"UnusedDeclaration\"})\n String id = getClass().getName().toLowerCase();\n //noinspection EmptyTryBlock\n try {\n// System.setIn(new FileInputStream(id + \".in\"));\n// System.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n// System.setIn(new FileInputStream(\"input.txt\"));\n// System.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n in = new StreamInputReader(System.in);\n out = new PrintWriter(System.out);\n testMode = false;\n }\n\n @SuppressWarnings({\"UnusedParameters\"})\n private static String check(String input, String result, String output) {\n// return strictCheck(result, output);\n return tokenCheck(result, output);\n }\n\n public static void main(String[] args) {\n// if (args.length != 0 && args[0].equals(\"42\"))\n test();\n// else\n// new TaskC().run();\n }\n\n private static void test() {\n System.setProperty(\"line.separator\", \"\\n\");\n List tests = createTests();\n int testCase = 0;\n List verdicts = new ArrayList();\n long maximalTime = 0;\n boolean ok = true;\n for (Test test : tests) {\n System.out.println(\"Test #\" + testCase + \":\");\n InputReader in = new StringInputReader(test.getInput());\n StringWriter out = new StringWriter(test.getOutput().length());\n System.out.println(\"Input:\");\n System.out.println(test.getInput());\n System.out.println(\"Expected output:\");\n System.out.println(test.getOutput());\n System.out.println(\"Execution result:\");\n long time = System.currentTimeMillis();\n try {\n new TaskC(in, new PrintWriter(out)).run();\n } catch (TestException e) {\n time = System.currentTimeMillis() - time;\n maximalTime = Math.max(time, maximalTime);\n String result = out.getBuffer().toString();\n System.out.println(result);\n System.out.print(\"Verdict: \");\n String checkResult = check(test.getInput(), result, test.getOutput());\n if (checkResult == null) {\n System.out.print(\"OK\");\n verdicts.add(Verdict.OK);\n } else {\n System.out.print(\"WA (\" + checkResult + \")\");\n verdicts.add(Verdict.WA);\n ok = false;\n }\n System.out.printf(\" in %.3f s.\\n\", time / 1000.);\n } catch (Throwable e) {\n System.out.println(\"Exception thrown:\");\n e.printStackTrace(System.out);\n verdicts.add(Verdict.RTE);\n ok = false;\n }\n testCase++;\n System.out.println(\"------------------------------------------------------------------\");\n }\n System.out.println(\"==================================================================\");\n System.out.println(\"Test results:\");\n if (ok)\n System.out.printf(\"All test passed in %.3f s.\\n\", maximalTime / 1000.);\n else {\n for (int i = 0; i < verdicts.size(); i++)\n System.out.println(\"Test #\" + i + \": \" + verdicts.get(i));\n }\n }\n\n private static enum Verdict {\n OK, WA, RTE\n }\n\n private static String tokenCheck(String result, String output) {\n StringInputReader resultStream = new StringInputReader(result);\n StringInputReader outputStream = new StringInputReader(output);\n int index = 0;\n boolean readingResult = false;\n try {\n while (true) {\n readingResult = true;\n String resultToken = resultStream.readString();\n readingResult = false;\n String outputToken = outputStream.readString();\n if (!resultToken.equals(outputToken)) {\n try {\n //noinspection PointlessBooleanExpression\n if (CERTAINTY != 0 && isDoubleEquals(Double.parseDouble(outputToken.replace(',', '.')),\n Double.parseDouble(resultToken.replace(',', '.')), CERTAINTY))\n {\n index++;\n continue;\n }\n } catch (NumberFormatException ignored) {}\n return \"'\" + outputToken + \"' expected at \" + index + \" but '\" + resultToken + \"' received\";\n }\n index++;\n }\n } catch (InputMismatchException e) {\n if (readingResult) {\n try {\n outputStream.readString();\n return \"only \" + index + \" tokens received\";\n } catch (InputMismatchException e1) {\n return null;\n }\n } else\n return \"only \" + index + \" tokens expected\";\n }\n }\n\n @SuppressWarnings({\"UnusedDeclaration\"})\n private static String strictCheck(String result, String output) {\n if (result.equals(output))\n return null;\n return \"Result and expected output do not match\";\n }\n\n @SuppressWarnings({\"UnusedDeclaration\"})\n private static boolean isDoubleEquals(double expected, double result, double certainty) {\n return Math.abs(expected - result) < certainty || Math.abs(expected - result) < certainty * expected;\n }\n\n private TaskC(InputReader in, PrintWriter out) {\n this.in = in;\n this.out = out;\n testMode = true;\n }\n\n @SuppressWarnings({\"UnusedDeclaration\"})\n private void exit() {\n out.close();\n if (testMode)\n throw new TestException();\n System.exit(0);\n }\n\n private static class Test {\n private final String input;\n private final String output;\n\n private Test(String input, String output) {\n this.input = input;\n this.output = output;\n }\n\n public String getInput() {\n return input;\n }\n\n public String getOutput() {\n return output;\n }\n }\n\n @SuppressWarnings({\"UnusedDeclaration\"})\n private abstract static class InputReader {\n public abstract int read();\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r')\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\n }\n\n public BigInteger readBigInteger() {\n try {\n return new BigInteger(readString());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n }\n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public int[] readIntArray(int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n array[i] = readInt();\n return array;\n }\n\n public long[] readLongArray(int size) {\n long[] array = new long[size];\n for (int i = 0; i < size; i++)\n array[i] = readLong();\n return array;\n }\n\n public double[] readDoubleArray(int size) {\n double[] array = new double[size];\n for (int i = 0; i < size; i++)\n array[i] = readDouble();\n return array;\n }\n\n public String[] readStringArray(int size) {\n String[] array = new String[size];\n for (int i = 0; i < size; i++)\n array[i] = readString();\n return array;\n }\n\n public char[][] readTable(int rowCount, int columnCount) {\n char[][] table = new char[rowCount][columnCount];\n for (int i = 0; i < rowCount; i++) {\n for (int j = 0; j < columnCount; j++)\n table[i][j] = readCharacter();\n }\n return table;\n }\n\n public void readIntArrays(int[]... arrays) {\n for (int i = 0; i < arrays[0].length; i++) {\n for (int j = 0; j < arrays.length; j++)\n arrays[j][i] = readInt();\n }\n }\n }\n\n private static class 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 }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n }\n\n private static class StringInputReader extends InputReader {\n private Reader stream;\n private char[] buf = new char[1024];\n private int curChar, numChars;\n\n public StringInputReader(String stream) {\n this.stream = new StringReader(stream);\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n }\n\n private static class TestException extends RuntimeException {}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d3c24738acd9a929c3a4e886cea16a5", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class C\n{\n public static long gcd(long a, long b){\n if(a>b){\n long c=a;\n a=b;\n b=c;\n }\n if(b%a==0)return a;\n return gcd(a,b-a);\n }\n public static void main (String[] args) throws Exception\n {\n Scanner s = new Scanner(System.in);\n StringTokenizer st = new StringTokenizer(s.nextLine());\n BigInteger t = new BigInteger(st.nextToken());\n BigInteger w = new BigInteger(st.nextToken());\n BigInteger b = new BigInteger(st.nextToken());\n BigInteger prod = b.multiply(w);\n BigInteger div = t.divide(prod);\n BigInteger rem = t.mod(prod);\n BigInteger one = new BigInteger(\"1\");\n long den=t.longValue();\n BigInteger numm = (div.multiply(w.min(b))).subtract(one).add(rem.min(w.min(b)));\n long num = numm.longValue();\n if(num==0){\n System.out.println(\"0/1\");\n System.exit(0);\n }\n else System.out.println(num/gdi+\"/\"+den/gdi);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cfced037b18ef42e4fcaaed8f0e55d85", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n\n\nimport com.sun.org.apache.bcel.internal.generic.SWAP;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tBigInteger t = in.nextBigInteger();\n\t\tBigInteger a = in.nextBigInteger();\n\t\tBigInteger b = in.nextBigInteger();\n\t\t\n\t\tBigInteger tmp;\n\t\tif (a.compareTo(b) > 0) {\n\t\t\ttmp = a;\n\t\t\ta = b;\n\t\t\tb = tmp;\n\t\t}\n\t\t\n\t\tBigInteger lcm = a.multiply(b).divide(a.gcd(b));\n\n\t\tBigInteger ans;\n\t\tif (t.compareTo(lcm) >= 0) {\n\t\t\ttmp = t.mod(lcm).add(BigInteger.ONE);\n\t\t\tif (tmp.compareTo(a) > 0) tmp = a;\n\t\t\tans = t.divide(lcm).subtract(BigInteger.ONE).multiply(a).add(tmp).add(a.subtract(BigInteger.ONE));\n\t\t} \n\t\telse {\n\t\t\tans = max(t,a.subtract(BigInteger.ONE));\n\t\t}\n\t\t\n\t\t\n\t\ttmp = ans.gcd(t);\n\t\tans = ans.divide(tmp);\n\t\tt = t.divide(tmp);\n\t\tSystem.out.println(ans+\"/\"+t);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "33818bf0444925597834728cbbd85733", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n \npublic class Main{\n \nstatic PrintWriter out;\nstatic InputReader ir;\nstatic final int INF=Integer.MAX_VALUE;\nstatic final long LINF=Long.MAX_VALUE;\n \nstatic void solve(){\n BigInteger nn=ir.nextBigInteger();\n BigInteger a=ir.nextBigInteger();\n BigInteger b=ir.nextBigInteger();\n BigInteger l=lcm(a,b);\n long mi=Math.min(a.longValue(),b.longValue());\n if(l.compareTo(n)>0){\n mi--;\n BigInteger mm=BigInteger.valueOf(mi);\n BigInteger gg=gcd(mm,n);\n out.println(mm.divide(gg)+\"/\"+n.divide(gg));\n return;\n }\n long ll=l.longValue();\n long nn=n.longValue();\n long d=nn/ll+1;\n long cnt=d*mi-1;\n if(nn=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i0){\n mi--;\n BigInteger mm=BigInteger.valueOf(mi);\n BigInteger gg=gcd(mm,n);\n out.println(mm.divide(gg)+\"/\"+n.divide(gg));\n return;\n }\n long ll=l.longValue();\n long nn=n.longValue();\n long d=nn/ll+1;\n long cnt=d*mi-1;\n if(nn=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i= cost){\n\t \t\tresult++;\n\t \t\tw -= cost;\n\t \t\tm++;\n\t \t}\n\t \telse break;\n \t}\n \t\n \tSystem.out.println(result);\n }\n \n // s(n) is the logarithm in base 10\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4494bf18ad8e86ff93eddb502bd43bb", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n//package codeforces;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author \u0410\u0439\u0434\u043e\u0441\n */\npublic class Main{\n public static void main(String [] args){\n\n Scanner sc = new Scanner(System.in);\n \n long w = sc.nextLong();\n long m = sc.nextLong();\n long k = sc.nextLong();\n w/=k;\n \n w+= get(m-1);\n long m1=m+1;\n while(get(m1)<=w){\n m1++; \n }\n System.out.println(m1-m);\n }\n public static long get(long a){\n long t=1;\n long now=1;\n long ret =0;\n for(;;){\n if(now*10>a){ \n \n ret+=(a-now+1)*t;\n return ret;\n \n }\n ret+=now*9*t;\n now*=10;\n t++;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "597b2099eac2d97a60de7c5f5f2ed409", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n//package codeforces;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author \u0410\u0439\u0434\u043e\u0441\n */\npublic class Main{\n public static void main(String [] args){\n Scanner sc = new Scanner(System.in);\n \n long w = sc.nextLong();\n long m = sc.nextLong();\n long k = sc.nextLong();\n w/=k;\n \n w+= get(m-1);\n long m1=m+1;\n while(get(m1)<=w){\n m1++; \n }\n System.out.println(get(m1-m));\n }\n public static long get(long a){\n long t=1;\n long now=1;\n long ret =0;\n for(;;){\n if(now*10>a){ \n \n ret+=(a-now+1)*t;\n return ret;\n \n }\n ret+=now*9*t;\n now*=10;\n t++;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b5bb8ea956ffcac983a5bc24759dec15", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class R219Div2QB {\n\tpublic static void main(String[] args){\n\t\tScanner s = new Scanner(System.in);\n\t\tString stringInput[] = s.nextLine().split(\" \");\n\t\tLong[] inputs = {Long.parseLong(stringInput[0]), Long.parseLong(stringInput[1]), Long.parseLong(stringInput[2])};\n\t\tLong w = inputs[0];\n\t\tLong m = inputs[1]-1;\n\t\tLong k = inputs[2];\n\t\tArrayList sq = new ArrayList();\n\t\twhile(w >= k){\n\t\t\tm++;\n\t\t\tw -= s(m) * k;\n\t\t\tif(w < 0)\n\t\t\t\tbreak;\n\t\t\tsq.add(m);\n\t\t}\n\t\tSystem.out.println(sq.size());\n\t\ts.close();\n\t}\n\tpublic static int s(Long n){\n\t\treturn n.toString().length();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bf90075c8a2b5d4974b7103b95950d1b", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class test {\n\t\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\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tboolean head[][][][] = new boolean[33][330][330][10];\n\t\thead[1][150][150][0] = true;\n\t\tint cnt = 0,t;\n\t\tboolean ok[][] = new boolean[330][330];\n\t\tint n = in.nextInt();\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tt = in.nextInt();\n\t\t\tfor(int j=0;j<=300;j++){\n\t\t\t\tfor(int k=0;k<=300;k++){\n\t\t\t\t\tfor(int d=0;d<8;d++){\n\t\t\t\t\t\tif(head[i][j][k][d]==true){\n\t\t\t\t\t\t\t//System.out.println(j+\" \"+k+\" \"+d);\n\t\t\t\t\t\t\tint xx=j,yy=k;\n\t\t\t\t\t\t\tfor(int g=0;g set;\n public static int[][] dirs;\n \n public static long encode(long x, long y) {\n long xx = x >= 0 ? x * 2 : x * -2 - 1;\n long yy = y >= 0 ? y * 2 : y * -2 - 1;\n \n return (xx >= yy) ? (xx * xx + xx + yy) : (yy * yy + xx);\n }\n \n public static void solveBranch(int[] spaces, int spaceLen, long x, long y, int indexDir, int index) {\n int incX = dirs[indexDir][0];\n int incY = dirs[indexDir][1];\n \n int incAmt = spaces[index];\n \n long newX = x + incX*incAmt;\n long newY = y + incY*incAmt;\n \n long enc = encode(newX, newY);\n \n for (int i = 1; i <= incAmt; i++) {\n set.add(encode(x + incX*i, y + incY*i));\n }\n \n if (index == spaceLen - 1) return;\n \n int leftDir = indexDir == 0 ? 7 : indexDir - 1;\n int rightDir = (indexDir + 1) % 8;\n \n solveBranch(spaces, spaceLen, newX, newY, leftDir, index + 1);\n solveBranch(spaces, spaceLen, newX, newY, rightDir, index + 1);\n }\n \n public static long solve(int depth, int[] spaces) {\n int maxSize = 0;\n \n for (int i = 0; i < depth; i++) {\n maxSize += spaces[i]*Math.pow(2, i);\n }\n \n set = new HashSet(maxSize);\n \n solveBranch(spaces, depth, 0, 0, 0, 0);\n \n return set.size();\n }\n\tpublic static void main(String[] args) {\n\t dirs = new int[][]{\n\t {0, 1},\n\t {1, 1},\n\t {1, 0},\n\t {1, -1},\n\t {0, -1},\n\t {-1, -1},\n\t {-1, 0},\n\t {-1, 1}\n\t };\n\t \n\t Scanner scan = new Scanner(System.in);\n\t \n\t int depth = scan.nextInt();\n\t int[] spaces = new int[depth];\n\t \n\t for (int i = 0; i < depth; i++) {\n\t spaces[i] = scan.nextInt();\n\t }\n\t \n\t System.out.println(solve(depth, spaces));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ad08833f3ed14c8d15830f25a7c0bb0", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class code2 {\n\tInputStream is;\n\tPrintWriter out;\n\tArrayList al[];\n\tlong mod=(int)Math.pow(10,9)+7;\n\tboolean dp[][][][][];int a[];\n\tvoid solve()\n\t{\n\t\tint n=ni();\n\t\tdp=new boolean[301+1][301+1][7][8][n];\n\t\ta=na(n);\n\t\tvisited=new boolean[301+1][301+1];\n\t\trec(155,155,a[0],2,0);\n\t\tint count=0;\n\t\tfor(int i=0;i<=301;i++)\n\t\t{\n\t\t\tfor(int j=0;j<=301;j++)\n\t\t\t{\n\t\t\t\tif(visited[i][j])\n\t\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tout.print(count);\n\t}\n\tboolean visited[][];\n\tvoid rec(int x,int y,int used,int dir,int level)\n\t{\n\t\t//if(used<0||level>=a.length)\n\t\t\t//return;\n\t\tif(dp[x][y][used][dir][level])\n\t\t\treturn ;\n\t\tvisited[x][y]=true;\n\t\tdp[x][y][used][dir][level]=true;\n\t\tif(used!=1)\n\t\t{\n\t\t\tint gox=x+getx(dir);\n\t\t\tint goy=y+gety(dir);\n\t\t\trec(gox,goy,used-1,dir,level);\n\t\t}else{\n\t\t\tif(level+1=1){\n\t\t\tint mid = (l+r)/2;\n\t\t\tmergeSort(arr,l,mid);\n\t\t\tmergeSort(arr,mid+1,r);\n\t\t\tmerge(arr,l,r,mid);\n\t\t}\n\t}\n\tpublic static void merge(int arr[], int l, int r, int mid){\n\t\tint n1 = (mid-l+1), n2 = (r-mid);\n\t\tint left[] = new int[n1];\n\t\tint right[] = new int[n2];\n\t\tfor(int i =0 ;iright[j]){\n\t\t\t\tarr[k++] = right[j++];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tarr[k++] = left[i++];\n\t\t\t}\n\t\t}\n\t\twhile(i=1){\n\t\t\tint mid = (l+r)/2;\n\t\t\tmergeSort(arr,l,mid);\n\t\t\tmergeSort(arr,mid+1,r);\n\t\t\tmerge(arr,l,r,mid);\n\t\t}\n\t}\n\tpublic static void merge(long arr[], int l, int r, int mid){\n\t\tint n1 = (mid-l+1), n2 = (r-mid);\n\t\tlong left[] = new long[n1];\n\t\tlong right[] = new long[n2];\n\t\tfor(int i =0 ;iright[j]){\n\t\t\t\tarr[k++] = right[j++];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tarr[k++] = left[i++];\n\t\t\t}\n\t\t}\n\t\twhile(i{\n\t\t \n\t int x,y,k,i;\n\t \n\t\tPair (int x,int y){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t \n\t\tpublic int compareTo(Pair o) {\n\t\t\t\t\treturn this.y-o.y;\n\t\t}\n\t \n\t public boolean equals(Object o) {\n\t if (o instanceof Pair) {\n\t Pair p = (Pair)o;\n\t return p.x == x && p.y == y && p.k==k;\n\t }\n\t return false;\n\t }\n\t \n\t \n\t @Override\n\t public String toString() {\n\t return \"(\"+x + \" \" + y +\" \"+k+\" \"+i+\" )\";\n\t }\n\t \n\t } \n\t \n\t public static boolean isPal(String s){\n\t for(int i=0, j=s.length()-1;i<=j;i++,j--){\n\t if(s.charAt(i)!=s.charAt(j)) return false;\n\t }\n\t return true;\n\t }\n\t public static String rev(String s){\n\t\t\tStringBuilder sb=new StringBuilder(s);\n\t\t\tsb.reverse();\n\t\t\treturn sb.toString();\n\t }\n\t \n\t public static long gcd(long x,long y){\n\t\tif(y==0)\n\t\t\treturn x;\n\t\telse\n\t\t\treturn gcd(y,x%y);\n\t }\n\t \n\t public static int gcd(int x,int y){\n\t \tif(y==0) \n\t \t\treturn x; \n\t \treturn gcd(y,x%y);\n\t }\n\t \n\t public static long gcdExtended(long a,long b,long[] x){\n\t \n\t if(a==0){\n\t x[0]=0;\n\t x[1]=1;\n\t return b;\n\t }\n\t long[] y=new long[2];\n\t long gcd=gcdExtended(b%a, a, y);\n\t \n\t x[0]=y[1]-(b/a)*y[0];\n\t x[1]=y[0];\n\t \n\t return gcd;\n\t }\n\t \n\t public static int abs(int a,int b){\n\t\treturn (int)Math.abs(a-b);\n\t }\n\t \n\t public static long abs(long a,long b){\n\t\treturn (long)Math.abs(a-b);\n\t }\n\t \n\t public static int max(int a,int b){\n\t\tif(a>b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t }\n\t \n\t public static int min(int a,int b){\n\t\tif(a>b)\n\t\t\treturn b;\n\t\telse \n\t\t\treturn a;\n\t }\n\t \n\t public static long max(long a,long b){\n\t\tif(a>b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t }\n\t \n\t public static long min(long a,long b){\n\t\tif(a>b)\n\t\t\treturn b;\n\t\telse \n\t\t\treturn a;\n\t }\n\t \n\t public static long pow(long n,long p,long m){\n\t\t long result = 1;\n\t\t if(p==0)\n\t\t return 1;\n\t\tif (p==1)\n\t\t return n;\n\t\twhile(p!=0)\n\t\t{\n\t\t if(p%2==1)\n\t\t result *= n;\n\t\t if(result>=m)\n\t\t result%=m;\n\t\t p >>=1;\n\t\t n*=n;\n\t\t if(n>=m)\n\t\t n%=m;\n\t\t}\n\t\treturn result;\n\t }\n\t \n\t public static long pow(long n,long p){\n\t\tlong result = 1;\n\t\t if(p==0)\n\t\t return 1;\n\t\tif (p==1)\n\t\t return n;\n\t\twhile(p!=0)\n\t\t{\n\t\t if(p%2==1)\n\t\t result *= n;\t \n\t\t p >>=1;\n\t\t n*=n;\t \n\t\t}\n\t\treturn result;\n\t }\n\t public static void debug(Object... o) {\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t\t}\n\t void run() throws Exception {\n\t\t\tis = System.in;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t}\n\t \n\t public static void main(String[] args) throws Exception {\n\t \tnew Thread(null, new Runnable() {\n\t\t\t\tpublic void run() {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tnew code2().run();\n\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\te.printStackTrace();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, \"1\", 1 << 26).start();\n\t\t\t\n\t \t//new code2().run();\n\t\t}\n\n\t private byte[] inbuf = new byte[1024];\n\t\tpublic int lenbuf = 0, ptrbuf = 0;\n\t \n\t\tprivate int readByte() {\n\t\t\tif (lenbuf == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (ptrbuf >= lenbuf) {\n\t\t\t\tptrbuf = 0;\n\t\t\t\ttry {\n\t\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (lenbuf <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn inbuf[ptrbuf++];\n\t\t}\n\t \n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\t \n\t\tprivate int skip() {\n\t\t\tint b;\n\t\t\twhile ((b = readByte()) != -1 && isSpaceChar(b));\n\t\t\treturn b;\n\t\t}\n\t \n\t\tprivate double nd() {\n\t\t\treturn Double.parseDouble(ns());\n\t\t}\n\t \n\t\tprivate char nc() {\n\t\t\treturn (char) skip();\n\t\t}\n\t \n\t\tprivate String ns() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\t \n\t\tprivate char[] ns(int n) {\n\t\t\tchar[] buf = new char[n];\n\t\t\tint b = skip(), p = 0;\n\t\t\twhile (p < n && !(isSpaceChar(b))) {\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t\t}\n\t \n\t\tprivate char[][] nm(int n, int m) {\n\t\t\tchar[][] map = new char[n][];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tmap[i] = ns(m);\n\t\t\treturn map;\n\t\t}\n\t \n\t\tprivate int[] na(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = ni();\n\t\t\treturn a;\n\t\t}\n\t \n\t\tprivate int ni() {\n\t\t\tint num = 0, b;\n\t\t\tboolean minus = false;\n\t\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t\t;\n\t\t\tif (b == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tb = readByte();\n\t\t\t}\n\t \n\t\t\twhile (true) {\n\t\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else {\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t}\n\t \n\t\tprivate long nl() {\n\t\t\tlong num = 0;\n\t\t\tint b;\n\t\t\tboolean minus = false;\n\t\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t\t;\n\t\t\tif (b == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tb = readByte();\n\t\t\t}\n\t \n\t\t\twhile (true) {\n\t\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else {\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t}\n\t \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4905a702675a4c28c7bd2bb7a82579be", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class badges {\n\n\tpublic static void main(String[] args) throws IOException\n\t{\n\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\nint b = Integer.parseInt(br.readLine());\nint g = Integer.parseInt(br.readLine());\nint n=Integer.parseInt(br.readLine());\n\n\nelse{\nif(bn_b)\n {\n break;\n }\n if(b>n_g)\n {\n b=n_g;\n i=n_t-n_g;\n a=i; \n }\n if(b<=n_g && a<=n_b)\n {\n t++;\n }\n \n a++;\n s\n }\n System.out.println(t);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca2f809c5dee4e949be153e18c78ca4c", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0} {"lang": "Java 8", "source_code": " import java.util.*;\n public class Main {\n\n public static void main(String args[]) {\n Scanner scan = new Scanner(System.in);\n int b=scan.nextInt();\n int g=scan.nextInt();\n int n=scan.nextInt();\n if (Math.min(b,g)>=n){\n System.out.println(Math.min(b,g)+1);\n }else (Math.min(b,g) library = new HashSet<>();\n int res = 0;\n for (int want = 0; want < n; want++) {\n if (library.contains(a[want])) continue;\n res++;\n if (library.size() == k) {\n int other = -1, far = -1;\n for (int book : library) {\n int dist = n;\n for (int i = want + 1; i < n; i++) {\n if (a[i] == book) {\n dist = i;\n break;\n }\n }\n if (dist > far) {\n far = dist;\n other = book;\n }\n }\n library.remove(other);\n }\n library.add(a[want]);\n }\n out.printLine(res);\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 static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n static class IOUtils {\n public static int[] readIntArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = in.readInt();\n }\n return array;\n }\n }\n static 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6ce4d29d35208fd90fb7a6c36cd9c9b0", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\n\tstatic StringTokenizer st;\n\tstatic BufferedReader br;\n\tstatic 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(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint n = nextInt();\n\t\tint k = 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\tint ans = 0;\n\t\tSet inLibrary = new HashSet<>();\n\t\tint[]first = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!inLibrary.contains(a[i])) {\n\t\t\t\tans++;\n\t\t\t\tif (inLibrary.size() < k)\n\t\t\t\t\tinLibrary.add(a[i]);\n\t\t\t\telse {\n\t\t\t\t\tArrays.fill(first, n);\n\t\t\t\t\tfor (int j = n-1; j > i; j--) {\n\t\t\t\t\t\tfirst[a[j]] = j;\n\t\t\t\t\t}\n\t\t\t\t\tint maxDay = 0, whatBook = 0;\n\t\t\t\t\tfor (int j : inLibrary) {\n\t\t\t\t\t\tif (first[j] > maxDay) {\n\t\t\t\t\t\t\tmaxDay = first[j];\n\t\t\t\t\t\t\twhatBook = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tinLibrary.remove(whatBook);\n\t\t\t\t\tinLibrary.add(a[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t\tpw.close();\n\t}\n\tprivate static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\tprivate static long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\tprivate static double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "41331bc8f6b2f4eb2e9d5898746dab12", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\n\npublic class B {\n static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n int N = sc.nextInt();\n int K = sc.nextInt();\n int[] A = new int[N];\n ArrayList> next = new ArrayList<>();\n for (int i = 0; i < N; i++) {\n A[i] = Integer.parseInt(sc.next());\n next.add(new ArrayList<>());\n next.get(i).add(1 << 29);\n }\n for (int i = N - 1; i >= 0; i--) {\n next.get(A[i]).add(i);\n }\n PriorityQueue q = new PriorityQueue<>((Integer i1, Integer i2) -> {\n ArrayList l1 = next.get(i1);\n ArrayList l2 = next.get(i2);\n return -Integer.compare(l1.get(l1.size() - 1), l2.get(l2.size() - 1));\n });\n\n int ans = 0;\n for (int i = 0; i < N; i++) {\n if (q.contains(A[i])) {\n q.remove(A[i]);\n next.get(A[i]).remove(next.get(A[i]).size() - 1);\n q.add(A[i]);\n } else {\n ++ans;\n next.get(A[i]).remove(next.get(A[i]).size() - 1);\n if (q.size() == K) {\n q.poll();\n }\n q.add(A[i]);\n }\n }\n System.out.println(ans);\n }\n\n static int solve() {\n return 0;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "165e1b6afe5781133b782790fb267373", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.Scanner;\n\npublic class Hiedi_and_library {\n public static void main(String[] a){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int c=sc.nextInt();\n int cost=0;\n ArrayList ar=new ArrayList();\n ArrayList cr=new ArrayList();\n for(int i=0;imax && j.hasNext() && ((int)ar.indexOf(t))!=-1){\n max=ar.indexOf(t);\n }\n }\n // int replace=(int)ar.get(max);\n \n if(max==0 || notexist==1){cr.set(max,v);\n cost=cost+1;\n }\n else{\n int index=cr.indexOf(ar.get(max));\n cr.set(index,v);\n cost=cost+1;}\n \n }\n i.remove();\n }\n System.out.println(cost);\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9c300fb5cf8c725f38784a3dbc62a314", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "/*628*/\nimport java.util.*;\npublic class tennis{\n\n\tpublic static void main(String[] args){\n\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tint p = input.nextInt();\n\t\t\n\t\tint bottles = 0;\n\t\tint towels = 0;\n\n\t\tbottles = 2*b + 1; //b = number of bottles for each player + 1 for official\n\t\tbottles = bottles * (n-1);// * number of players playing - 1\n\t\ttowels = p*n; //p= number for each player * players total\n\t\tSystem.out.println(bottles+\" \"+towels);\n\t\tinput.close();\n\t}\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "59427ab45107d4dc0df100607b863f16", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class CF 628A {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int b = scan.nextInt();\n int p = scan.nextInt();\n\n int towels = p*n;\n int bottles = 0;\n while (n>1) {\n int pass = n%b;\n int matches = n/2;\n bottles += (b * 2 + 1) * matches;\n n = pass + matches;\n }\n System.out.println(bottles + \" \" + towels);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ce8cafa4be365c053e87a20303e6b14a", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\npublic class me {\n\tpublic static void main(String[] args) {\n\t\tScanner br = new Scanner(System.in);\n\tint n=br.nextInt();\n\tint[] arr=new int[n];\n\tint k=br.nextInt();\n\tfor(i=0;i 0) {\n int k = 2;\n while(k <= players) {\n k << 1;\n }\n k >> 1;\n \n totalBottles += k * bottles + 1;\n \n players -= k;\n }\n \n System.out.println(totalBottles + \" \" (towels * players));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "60d049c4829609d62da991205c08722e", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class Main {\npublic static void main(String args[]) \n{\n Scanner s = new Scanner(System.in);\n String time = s.nextLine();\n SimpleDateFormat df = new SimpleDateFormat(\"HH:mm\");\n\ntry {\n\t Date d = df.parse(time);\n\t Calendar cal = Calendar.getInstance();\n\t cal.setTime(d);\n\t cal.add(Calendar.MINUTE, s.nextInt());\n\t String newTime = df.format(cal.getTime());\n\t System.out.println(newTime);\n} catch (ParseException e) {\n\te.printStackTrace();\n} \n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8bf9fb9fbee07503c69eeeacfd647a76", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0} {"lang": "Java 7", "source_code": "public class Solution{\n public static void main(String args[]){\n Scanner s - new Scanner(System.in);\n int hour = s.nextInt();\n int min = s.nextInt();\n int addMin = s.nextInt();\n \n int k = addMin/60;\n int l = addMin%60;\n for(int i = 0; i< k ; i++){\n if(hour!=24) hour += 1;\n else hour = 0; \n }\n \n for(int i = 0; i< l ; i++){\n if(min!=61) min += 1;\n else {\n min = 1; \n if(hour!= 24) \n hour++; \n else \n hour = 0;\n }\n }\n \n System.out.println(hour + \":\" + min);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "62249e7d9adf6fcdf20ad2b6f04b89d6", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n\npublic class JavaApplication1 {\n\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n\n \n String time = sc.next();\n int min = sc.nextInt();\n int hour = Integer.parseInt(time.substring(0, 2));\n int calculte_hours = (((Integer.parseInt(time.substring(3)) + min) / 60) + hour) % 24;\n int calculate_minutes = (Integer.parseInt(time.substring(3))+min) % 60;\n \n System.out.print(calculte_hours < 10 ?\"0\"+calculte_hours+\":\": calculte_hours+\":\");\n System.out.println(calculate_minutes < 10 ?\"0\"+calculate_minutes: calculate_minutes);\n \n \n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3db1f256a5c56c51466f25288d7bc111", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class TheTime {\n\n public static void main(String[] args) {\n Scanner kbd = new Scanner(System.in);\n\n String time = kbd.nextLine();\n int add = kbd.nextInt();\n\n\tString[] value = time.split(\":\");\n\n\tint oldHours = Integer.parseInt(value[0]);\n\tint oldMinutes = Integer.parseInt(value[1]);\n\n\tint tempMinutes = oldMinutes + add; /\n\n\tif(tempMinutes > 59){\n\t\tint addHours = tempMinutes / 60; \n\t\tint addMins = tempMinutes % 60; \n\n\n\t\tint tempHours; //9\n\t\t\tif((oldHours+addHours) == 24)\n\t\t\t\ttempHours = 0;\n\t\t\telse\n\t\t\t\ttempHours = oldHours + addHours;\n\n\t\tint newHours = tempHours % 24; \n\n\t\tint newMinutes = addMins; \n\n\n\t\tif(newHours < 10 && newMinutes < 10)\n\t\t\tSystem.out.println (\"0\" + newHours + \":\" + \"0\" + newMinutes);\n else if(newHours < 10 && newMinutes >=10)\n\t\t\tSystem.out.println (\"0\" + newHours + \":\" + newMinutes);\n else if(newHours >=10 && newMinutes >=10)\n\t\t\tSystem.out.println (newHours + \":\" + newMinutes);\n\t\telse (newHours >= 10 && newMinutes < 10)\n\t\t\tSystem.out.println (newHours + \":\" + \"0\" + newMinutes);\n\n\t}else{\n\t\tif(add == 0)\n\t\t\tSystem.out.println (value[0] + \":\" + value[1]);\n\t\telse if(tempMinutes < 10)\n\t\t\tSystem.out.println (value[0] + \":0\" + tempMinutes);\n\t\telse\n\t\t\tSystem.out.println (value[0] + \":\" + tempMinutes);\n\n\t}\n\n\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "64bd2f08ff3947aa4b372d989ecbe7e1", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class C {\n public static int n;\n public static int k;\n public static int[][] dp = new int[n+1][k+1];\n public static int[] cum = new int[n+1];\n public static void main(String[] args) throws Exception {\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(bf.readLine());\n int n = Integer.parseInt(st.nextToken());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int k = Integer.parseInt(st.nextToken());\n long[][] dp = new long[n+1][k+1];\n long[][] cum = new long[n+1][k+1];\n for(int i=0; ib)\n {\n for(int j=2;j<=k;j++)\n {\n\n for(int i=b+1;i<=n;i++)\n {\n \n \n long tmp=0;\n tmp+=p[0][Math.min(i+(i-b)-1,n)];\n //tmp+=p[j-1][Math.max(Math.min(Math.abs(n-i)-1, Math.abs(i-b)-1),0)];\n tmp-=dp[0][i];\n \n dp[1][i]=((tmp+2*mod)%mod);\n\n p[1][i]=(p[1][i-1]+dp[1][i])%mod;\n }\n p[0]=Arrays.copyOf(p[1],p[1].length);\n Arrays.fill(p[1],0l);\n dp[0]=Arrays.copyOf(dp[1],dp[1].length);\n Arrays.fill(dp[1],0l);\n //System.out.println(Arrays.toString(dp[j]));\n }\n }\n \n System.out.println(dp[0][a]%(mod));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8bd274ff50bd4b9fcb4a4f25ae3bcc1f", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "public class E {\n static final int MODNUM = 1000000007;\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = scanner.nextInt(), a = scanner.nextInt(), b = scanner.nextInt(), k = scanner.nextInt();\n int[][] dp = new int[k + 1][], sum = new int[k + 1][];\n for (int i = 0; i < k + 1; i++) {\n dp[i] = new int[n + 1]; \n sum[i] = new int[n + 1];\n }\n dp[0][a] = 1;\n for (int i = a; i <= n; i++)\n sum[0][i] = 1;\n\n for (int i = 1; i <= k; i++) {\n for (int j = 1; j <= n; j++) {\n if (j == b)\n dp[i][j] = 0;\n else if (j > b) {\n dp[i][j] = (sum[i - 1][n] - sum[i - 1][(j + b) / 2] - dp[i - 1][j]) % MODNUM;\n } else {\n dp[i][j] = (sum[i - 1][(j + b - 1) / 2] - dp[i - 1][j]) % MODNUM;\n }\n\n sum[i][j] = ((sum[i][j-1] + dp[i][j]) % MODNUM + MODNUM) % MODNUM;\n }\n }\n\n System.out.println(sum[k][n]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "377bf79dc4634206218ce441fa0423aa", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x1=0,y1=0,x2=0,y2=0;\n\t int x=sc.nextInt();\n\t int y=sc.nextInt();\n\t if(x>0 && y>0){\n\t x1=0;\n\t y1=x+y;\n\t x2=x+y;\n\t y2=0;\n\t }\n\t \telse if(x<0 && y>0){\n\t x1=x-y;\n\t y1=0;\n\t x2=0;\n\t y2=-(x-y);\n\t }\n\t \n\t \telse if(x<0 && y<0){\n\t x1=-(-x-y);\n\t y1=0;\n\t x2=0;\n\t y2=-(-x-y);\n\t }\n\t \n\t \telse if(x>0 && y<0){\n\t x2=x-y;\n\t y2=0;\n\t x1=0;\n\t y1=-(x-y);\n\t }\n\t System.out.print(x1=\" \");\n\t System.out.print(y1+\" \");\n\t System.out.print(x2+\" \");\n\t System.out.print(y2+\" \");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d5cb23fc9139a6a710904ccb1a6f4cf2", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\n/**\n *\n * @author greggy\n */\npublic class VasilyTheBearAndTriangle {\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 \n int ans = Math.abs(x) + Math.abs(y);\n int xans = Integer.signum(x)*ans;\n int yans = Integer.signum(y)*ans;\n \n if (xans > yans) {\n int temp = xans;\n xans = yans;\n yans = temp;\n }\n \n System.out.println(\"0 \"+xans+ \" \"+yans+ \" 0\");\n in.close();", "lang_cluster": "Java", "compilation_error": true, "code_uid": "524cbb3e129473fbc4d29717394e6318", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;import java.io.*;import java.math.*;\npublic class Main\n{\n public static void process()throws IOException\n {\n int x=ni();\n int y=ni();\n if(x>0 && y>0)\n pn(\"0 \"+(x+y)+\" \"+(x+y)+\" 0\");\n if(x<0 && y>0)\n pn((x-y)+\" 0 0 \"+(y-x));\n if(x<0 && y<0)\n pn((x+y)+\" 0 0 \"+(x+y));\n if(x>0 && y<0)\n pn(\"0 \"+(y-x)+\" \"+(x-y)+\" 0\")\n }\n\n static AnotherReader sc;\n static PrintWriter out;\n public static void main(String[]args)throws IOException\n {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}\n else{sc=new AnotherReader(100);out=new PrintWriter(\"output.txt\");}\n int t=1;\n t=ni();\n while(t-->0) {process();}\n out.flush();out.close(); \n }\n\n static void pn(Object o){out.println(o);}\n static void p(Object o){out.print(o);}\n static void pni(Object o){out.println(o);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 int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}\n static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}\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/////////////////////////////////////////////////////////////////////////////////////////////////////////\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0da07ffe41addb9675428d2d462d4694", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;import java.io.*;import java.math.*;\npublic class Main\n{\n public static void process()throws IOException\n {\n int x=ni();\n int y=ni();\n if(x>0 && y>0)\n pn(\"0 \"+(x+y)+\" \"+(x+y)+\" 0\");\n if(x<0 && y>0)\n pn((x-y)+\" 0 0 \"+(y-x));\n if(x<0 && y<0)\n pn((x+y)+\" 0 0 \"+(x+y));\n if(x>0 && y<0)\n pn(\"0 \"+(y-x)+\" \"+(x-y)+\" 0\")\n }\n\n static AnotherReader sc;\n static PrintWriter out;\n public static void main(String[]args)throws IOException\n {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}\n else{sc=new AnotherReader(100);out=new PrintWriter(\"output.txt\");}\n int t=1;\n // t=ni();\n while(t-->0) {process();}\n out.flush();out.close(); \n }\n\n static void pn(Object o){out.println(o);}\n static void p(Object o){out.print(o);}\n static void pni(Object o){out.println(o);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 int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}\n static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}\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/////////////////////////////////////////////////////////////////////////////////////////////////////////\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c6bc01e24969cc2a9ee4e2d1bd159ca2", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\npublic class Main{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n int d = Integer.parseInt(s.charAt(6));\n if(d%2==0)System.out.print(0);\n else System.out.print(1);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "99c17adccabc3769facea20157c83104", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n String=sc.next();\n if(Integer.parseInt(s.charAt(6)%2==0))\n System.out.println(\"0\");\n else\n System.out.println(\"1\");\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f2eb9d61b970a19d050b8dd96c3f4719", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n String=sc.next();\n if(Integer.parseInt(s.charAt(6)%2==0))\n System.out.println(\"0\");\n else\n System.out.println(\"1\")\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5f86e5ea52f2dbf67c014a30f332e6e9", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null} {"lang": "Java 8", "source_code": "public class solution\n{\n public static void main(String arg[])\n {\n Scanner in = new Scanner(System.in);\n String s = in. nextLine();\n if(s.charAt(s.length()-1) % 2==0)\n System.out. println(\"0\");\n else \n System.out. println(\"1\");\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "219e82b548b3b4222b05ede955ba431e", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class susbus{\n public static void main(String[] args){\n Scanner sc =new Scanner(System.in);\n int n= sc.nextInt();\n System.out.println(powerthree(n,1000003);\n }\n public static int powerthree(int n,int mod){\n //3^n-1\n if(n==1) return 1;\n return 3*powerthree(n-1,mod)%mod;\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "07130c461d5b49d57f66ed27efe7c079", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class A {\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\t\n\tfinal int mod = (int)1e6 + 3;\n\t\n\tlong func(int n) {\n\t\tif(n <= 1) return 1;\n\t\treturn 3 * func(n-1) % mod;\n\t}\n\t\n\tprivate void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tout.printf(\"%d\\n\", func(n));\n\t}\n\t\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer tokenizer;\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate String nextLine() throws IOException {\n\t\treturn new String(in.readLine());\n\t}\n\n\tprivate String nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a12cec448afe621257a799b0c1cfc790", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Main {\n public static int pow(int base, int exp, int mod) {\n if (exp == 0)\n return 1 % mod ;\n else\n return (base * pow(base, exp - 1, mod)) % mod;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n int size = in.nextInt();\n System.out.println(((size==0)?1:(pow(3, size - 1, (int)Math.pow(10, 6) + 3)));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d70da10dad455927e4cf72eb19a95e33", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0} {"lang": "Java 6", "source_code": " import java.io.*;\nimport java.math.BigInteger;\n import java.text.*;\n import java.util.*;\nimport java.util.regex.*;\n\n public class Main{\n static class Run implements Runnable{\n //TODO parameters\n final boolean consoleIO = true;\n final String inFile = \"input.txt\";\n final String outFile = \"output.txt\";\n \n boolean[][] f;\n int n;\n \n boolean ok(int x, int y, int sz) { \n for(int j = 0; j < sz; ++j) {\n int tx = x + j;\n int ty = y + j;\n \n if(tx >= n || ty >= n || f[ty][n-tx-1])\n return false;\n }\n \n return true;\n }\n \n void cook(int x, int y, int sz) {\n if(ok(x, y, sz)) {\n int c = 0;\n \n for(int i = y; i < y+sz; ++i, ++c)\n for(int j = x; j < x+sz-c; ++j)\n f[i][n-j-1] = true;\n }\n }\n \n @Override\n public void run() {\n n = (int)Math.pow(2,nextInt());\n f = new boolean[n][n];\n \n int sz = n;\n while(sz != 1) {\n for(int i = 0; i < n; ++i)\n for(int j = 0; j < n; ++j)\n cook(i, j, sz);\n \n sz /=2;\n }\n \n// for(boolean[] b1:f) {\n// for(boolean b:b1)\n// print((b?1:0)+\" \");\n// print(\"\\n\");\n// }\n \n int c = 0;\n for(boolean[] b1:f) \n for(boolean b:b1)\n if(!b)\n ++c;\n print(c);\n close();\n }\n //=========================================================================================================================\n BufferedReader in;\n PrintWriter out;\n StringTokenizer strTok;\n \n Run() {\n if (consoleIO) {\n initConsoleIO();\n }\n else {\n initFileIO();\n }\n }\n \n void initConsoleIO() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n \n void initFileIO() {\n try {\n in = new BufferedReader(new FileReader(inFile));\n out = new PrintWriter(new FileWriter(outFile));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n void close() {\n try {\n in.close();\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n \n float nextFloat() {\n return Float.parseFloat(nextToken());\n }\n \n long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n String nextLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n return \"__NULL\";\n }\n }\n \n boolean hasMoreTokens() {\n return (strTok == null) || (strTok.hasMoreTokens());\n }\n \n String nextToken() {\n while (strTok == null || !strTok.hasMoreTokens()) {\n String line;\n try {\n line = in.readLine();\n strTok = new StringTokenizer(line);\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n return strTok.nextToken();\n }\n \n void cout(Object o){\n System.out.println(o);\n }\n \n void print(Object o) {\n out.write(o.toString());\n }\n \n void println(Object o) {\n out.write(o.toString() + '\\n');\n }\n \n void printf(String format, Object... args) {\n out.printf(format, args);\n }\n \n String sprintf(String format, Object... args) {\n return MessageFormat.format(format, args);\n }\n }\n \n static class Pair {\n A a;\n B b;\n \n A f() {\n return a;\n }\n \n B s() {\n return b;\n }\n \n Pair(A a, B b) {\n this.a = a;\n this.b = b;\n }\n \n Pair(Pair p) {\n a = p.f();\n b = p.s();\n }\n }\n \n public static void main(String[] args) throws IOException {\n Run run = new Run();\n Thread thread = new Thread(run);\n thread.run();\n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "38c13c602f9da3230d845144a144a26c", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\n\npublic class CT14E {\n\n\tstatic StreamTokenizer in;\n\tstatic PrintWriter out;\n\t\n\tstatic int nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t}\n\t\n\tstatic String nextString() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tout = new PrintWriter(System.out);\n\n\t\tfor (int t = nextInt(); t > 0; t--) {\n\t\t\tn = nextInt();\n\t\t\tk = nextInt();\n\t\t\t\n\t\t\tlong ans = 0;\n\t\t\tfor (int a = 0; a < 4; a++)\n\t\t\t\tfor (int b = 0; b < 4; b++)\n\t\t\t\t\tif (a != b)\n\t\t\t\t\t\tans += solve(n-2, k, k-1, a, b);\n\t\t\t\n\t\t\tout.println(ans);\n\t\t}\n\t\t\n\t\tout.flush();\n\t}\n\n\tstatic int n, k;\n\tstatic long[][][][][] memo = new long[20][11][11][4][4];\n\tstatic {\n\t\tfor (long[][][][] a : memo)\n\t\t\tfor (long[][][] b : a)\n\t\t\t\tfor (long[][] c : b)\n\t\t\t\t\tfor (long[] d : c)\n\t\t\t\t\t\tArrays.fill(d, -1);\n\t}\n\t\n\tstatic long solve(int x, int q, int p, int a, int b) {\n\t\tif (x == 0) return q == 0 && p == 0 ? 1 : 0;\n\t\tif (q < 0 || p < 0) return 0;\n\t\tif (memo[x][q][p][a][b] != -1) return memo[x][q][p][a][b];\n\t\t\n\t\tint res = 0;\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tif (i < a && a > b) res += solve(x-1, q-1, p, i, a);\n\t\t\telse if (i > a && a < b) res += solve(x-1, q, p-1, i, a);\n\t\t\telse if (i != a) res += solve(x-1, q, p, i, a);\n\t\t\n\t\treturn memo[x][q][p][a][b] = res;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2eb6dad12827625f66acde5ff6a6ed08", "src_uid": "6d67559744583229455c5eafe68f7952", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n/**\n * 4:41 ~ \n *\n */\npublic class Main {\n\t\n\tpublic static void main(String[] argv) {\n\t\tFastScanner scan = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint n = scan.nextInt();\n\t\tint t = scan.nextInt();\n\t\tint dp[][][][] = new int[n+2][4 * 4 + 5][n+1][n+1];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tif(i == 0){\n\t\t\t\tfor(int j = 0; j < 4; j++){\n\t\t\t\t\tdp[i+1][j][0][0] = 1;\n\t\t\t\t}\n\t\t\t} else if(i == 1){\n\t\t\t\tfor(int state = 0; state < 4; state++){\n\t\t\t\t\tfor(int j = 0; j < 4; j++){\n\t\t\t\t\t\tif(state == j) continue;\n\t\t\t\t\t\tdp[i+1][state * 4 + j][0][0] += dp[i][state][0][0];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\t\t\t\n\t\t\t\tfor(int state = 0; state < 16; state++){\n\t\t\t\t\tint first = state / 4;\n\t\t\t\t\tint second = state % 4;\n\t\t\t\t\tif(first == second) continue;\n\t\t\t\t\tfor(int c = 0; c <= i/2; c++){\n\t\t\t\t\t\tfor(int d = 0; d <= i/2; d++){\n\t\t\t\t\t\t\tfor(int j = 0; j < 4; j++){\n\t\t\t\t\t\t\t\tif(second == j) continue;\n\t\t\t\t\t\t\t\tif(first < second){\n\t\t\t\t\t\t\t\t\tif(second < j){\n\t\t\t\t\t\t\t\t\t\tdp[i+1][second * 4 + j][c][d] += dp[i][state][c][d];\n\t\t\t\t\t\t\t\t\t} else if(second > j){\n\t\t\t\t\t\t\t\t\t\tdp[i+1][second * 4 + j][c+1][d] += dp[i][state][c][d];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if(first > second){\n\t\t\t\t\t\t\t\t\tif(second < j){\n\t\t\t\t\t\t\t\t\t\tdp[i+1][second * 4 + j][c][d+1] += dp[i][state][c][d];\n\t\t\t\t\t\t\t\t\t} else if(second > j){\n\t\t\t\t\t\t\t\t\t\tdp[i+1][second * 4 + j][c][d] += dp[i][state][c][d];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t/*\n\t\tfor(int i = 0; i <= n+1; i++)\n\t\t\tfor(int state = 0; state < 16; state++)\n\t\t\t\tfor(int c = 0; c <= i / 2; c++)\n\t\t\t\t\tfor(int d = 0; d <= i / 2; d++)\n\t\t\t\t\t\tSystem.out.println(i + \", (\" + (state / 4) + \",\" + (state % 4) + \"), \" + c + \",\" + d + \" => \" + dp[i][state][c][d]);\n\t\t*/\n\t\tint ret = 0;\n\t\tfor(int state = 0; state < 16; state++){\n\t\t\tint first = state / 4;\n\t\t\tint second = state % 4;\n\t\t\tif(first == second) continue;\n\t\t\tret += dp[n][state][t][t-1];\n\t\t}\n\t\tout.println(ret);\n\t\tout.close();\t\t\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner(InputStream is) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t\t} catch (Exception 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.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\treturn null;\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.valueOf(next());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2c44e4babdfaddf639870d88afee23c", "src_uid": "6d67559744583229455c5eafe68f7952", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Camels {\n static Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System. in )));\n\n static int n, t, wise[][][][][];\n static boolean done[][][][][];\n public static void main(String[] args) {\n n = in .nextInt();\n t = in .nextInt();\n wise = new int[n][t + 1][t][4][4];\n done = new boolean[n][t + 1][t][4][4];\n int ans = 0;\n for (int i = 0; i < 4; i++)\n for (int j = 0; j < i; j++) ans += remember(1, 0, 0, i, j);\n System.out.println(ans);\n }\n\n static int remember(int x, int h, int v, int y, int yprev) {\n if (done[x][h][v][y][yprev]) return wise[x][h][v][y][yprev];\n int ans = 0;\n if (x == n - 2) {\n if (v == t - 1) {\n for (int ynext = 0; ynext < y; ynext++) {\n if (ynext < y && yprev < y) a{\n if (h < t) ans++;\n } else {\n if (h == t) ans++;\n }\n }\n }\n } else {\n for (int ynext = 0; ynext < 4; ynext++)\n if (ynext != y) {\n if (ynext < y && yprev < y) {\n if (h < t) ans += remember(x + 1, h + 1, v, ynext, y);\n } else if (ynext > y && yprev > y) {\n if (v < t - 1) ans += remember(x + 1, h, v + 1, ynext, y);\n } else ans += remember(x + 1, h, v, ynext, y);\n }\n }\n done[x][h][v][y][yprev] = true;\n return wise[x][h][v][y][yprev] = ans;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7f7f61733d662e906332944cbf273514", "src_uid": "6d67559744583229455c5eafe68f7952", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.Arrays;\n\n\npublic class E {\n static int n;\n static int t;\n static int[][][][][] visited;\n public static int work(int index , int humps , int prev , int now , int bel) {\n //System.out.println(s + \" \"+humps + \" \" + bel);\n if(index == n-1) {\n if(humps == t && bel == t-1) {\n //System.out.println(s + \" \"+humps + \" \" + bel + \" hi\");\n return 1;\n }\n else return 0;\n }\n if(bel >t-1 || humps >t)\n return 0;\n \n if(visited[index][humps][prev][now][bel] !=-1) {\n \n return visited[index][humps][prev][now][bel];\n }\n \n int result = 0;\n \n \n for(int i = 1 ; i<=4 ; i++) {\n if(now == i)\n continue;\n result += work(index +1 , (now>prev && now >i && prev !=0? humps+1:humps) , now , i , (now 0) {\n\t\t\t\t\tSystem.out.println(x + \" \" + m);\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.println(x + \" \" + 0);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t}\n\t\t} else if (vy == 0) {\n\t\t\tif (y == 0 || y == m) {\n\t\t\t\tif (vx > 0) {\n\t\t\t\t\tSystem.out.println(n + \" \" + y);\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.println(0 + \" \" + y);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t}\n\t\t} else {\n\t\t\t//vx != 0, vy != 0\n\t\t\tboolean rx = false;\n\t\t\tboolean ry = vy < 0;\n\t\t\tif (vx < 0) {\n\t\t\t\trx = true;\n\t\t\t\tx = n - x;\n\t\t\t}\n\t\t\tif (vy < 0) {\n\t\t\t\try = true;\n\t\t\t\ty = m - y;\n\t\t\t}\n\n\t\t\tlong g = gcd(n, m);\n\t\t\tif (x % g != y % g) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tlong k = crt(m, (m - y) % m ,n, (n - x) % n);\n\t\t\t\n\t\t\tlong ax = (x + k) % (2 * n);\n\t\t\tlong ay = (y + k) % (2 * m);\n\t\t\t\n\t\t\tif (rx) ax = n - ax;\n\t\t\tif (ry) ay = m - ay;\n\t\t\t\n\t\t\tSystem.out.println(ax + \" \" + ay);\n\t\t}\n\t\t\n\t}\n\n\tpublic static long crt(long p, long m, long q, long n)\n\t{\n\t\tlong a = p, b = q;\n\t\tlong pp = 1, qq = 0;\n\t\twhile(b > 0){\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a; a = b; b = d % b;\n\t\t\td = pp; pp = qq; qq = d - c * qq;\n\t\t}\n\t\tif((n - m) % a != 0)return -1;\n\t\tlong mod = p / a * q;\n//\t\tlong ret = (p * pp % mod * ((n - m) / a) + m) % mod;\n\t\tlong ret = (mul(mul(p, pp, mod), (n-m)/a, mod)+m)%mod;\n\t\tif(ret < 0)ret += mod;\n\t\treturn ret;\n\t}\n\tpublic static long mul(long a, long b, long mod)\n\t{\n\t\ta %= mod; if(a < 0)a += mod;\n\t\tb %= mod; if(b < 0)b += mod;\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\tpublic static long gcd(long a, long b) {\n\t\tif (a > b) {\n\t\t\tlong tmp = a;\n\t\t\ta = b;\n\t\t\tb = tmp;\n\t\t}\n\t\twhile (a != 0) {\n\t\t\tlong c = a;\n\t\t\ta = b % c;\n\t\t\tb = c;\n\t\t}\n\t\treturn b;\n\t}\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Runnable() {\n\t\t\t@Override\n\t\t\tpublic void run() {\n\t\t\t\tlong start = System.currentTimeMillis();\n\t\t\t\tString debug = args.length > 0 ? args[0] : null;\n\t\t\t\tif (debug != null) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tis = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));\n\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);\n\t\t\t\tsolve();\n\t\t\t\tout.flush();\n\t\t\t\ttr((System.currentTimeMillis() - start) + \"ms\");\n\t\t\t}\n\t\t}, \"\", 64000000).start();\n\t}\n\n\tprivate static java.io.InputStream is = System.in;\n\tprivate static java.io.PrintWriter out = new java.io.PrintWriter(System.out);\n\tprivate static java.util.StringTokenizer tokenizer = null;\n\tprivate static java.io.BufferedReader reader;\n\n\tpublic static String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new java.util.StringTokenizer(reader.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tprivate static double nd() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tprivate static long nl() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate static 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 static char[] ns() {\n\t\treturn next().toCharArray();\n\t}\n\n\tprivate static long[] nal(int n) {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nl();\n\t\treturn a;\n\t}\n\n\tprivate static int[][] ntable(int n, int m) {\n\t\tint[][] table = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\ttable[i][j] = ni();\n\t\t\t}\n\t\t}\n\t\treturn table;\n\t}\n\n\tprivate static int[][] nlist(int n, int m) {\n\t\tint[][] table = 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\ttable[j][i] = ni();\n\t\t\t}\n\t\t}\n\t\treturn table;\n\t}\n\n\tprivate static int ni() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate static void tr(Object... o) {\n\t\tif (is != System.in)\n\t\t\tSystem.out.println(java.util.Arrays.deepToString(o));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29f73e3b11ac352a00e08bfd9f3cf442", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "13c6dac8c69afb0929ae9880e15e13f2", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.util.*;\n\npublic class E3 {\n\n\tstatic long N,M,X,Y,dX,dY;\n\tpublic static void main(String[] args) {\n\t\t//System.out.println(modInv(2, 6));\n\n\t\tJS in = new JS();\n\t\tN = in.nextLong();\n\t\tM = in.nextLong();\n\t\tX = in.nextLong();\n\t\tY = in.nextLong();\n\t\tdX = in.nextLong();\n\t\tdY = in.nextLong();\n\n\t\t\n\t\tif(dX == 1 && dY == 0) { //going right\n\t\t\tif(Y == M) System.out.println(N+\" \"+M);\n\t\t\telse if(Y == 0) System.out.println(N+\" \"+0);\n\t\t\telse System.out.println(-1);\n\t\t}\n\t\telse if(dX == -1 && dY == 0) { //going left\n\t\t\tif(Y == M) System.out.println(0+\" \"+M);\n\t\t\telse if(Y==0)System.out.println(0+\" \"+0);\n\t\t\telse System.out.println(-1);\n\t\t}\n\t\telse if(dX == 0 && dY == 1) { //going up\n\t\t\tif(X==0) System.out.println(0+\" \"+M);\n\t\t\telse if(X==N) System.out.println(N+\" \"+M);\n\t\t\telse System.out.println(-1);\n\t\t}\n\t\telse if(dX == 0 && dY == -1) { //going down\n\t\t\tif(X==0) System.out.println(0+\" \"+0);\n\t\t\telse if(X==N) System.out.println(N+\" \"+0);\n\t\t\telse System.out.println(-1);\n\t\t}\n\t\telse {\n\t\t\tif(dX == 1 && dY == 1) {\n\t\t\t\tgo1(N,M,X,Y);\n\t\t\t}\n\t\t\telse if(dX == 1 && dY == -1) { //down-right\n\t\t\t\tgo2(N,M,X,M-Y);\t\n\t\t\t}\n\t\t\telse if(dX == -1 && dY == 1) { //up-left\n\t\t\t\tgo3(N,M,N-X,Y);\n\t\t\t}\n\t\t\telse if(dX == -1 && dY == -1) { //down-left\n\t\t\t\tgo4(N,M,N-X,M-Y);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tstatic void go4(long N, long M, long X, long Y) {\n\t\tlong x1 = N;\n\t\tlong y1 = Y + (N-X);\n\t\t\n\t\tlong x2 = N*2;\n\t\tlong y2 = y1 + N;\n\t\t\n\t\tlong mod1 = y1%M;\n\t\tlong mod2 = y2%M;\n\t\t\n\t\tif(mod1==0) {\n\t\t\tif( (y1/M)%2 == 0)hole(2);\n\t\t\telse hole(0);\n\t\t\treturn;\n\t\t}\n\t\tif(mod2==0) {\n\t\t\tif( (y2/M) % 2 == 0) hole(3);\n\t\t\telse hole(1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong dif = mod2-mod1;\n\t\tif(dif == 0) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(dif < 0) {\n\t\t\tdif = M+dif;\n\t\t}\n\t\t\n\t\t//System.out.println(\"H: \"+mod1+\" \"+dif+\" \"+M);\n\t\t\n\t\tlong gcd = gcd(dif,M);\n\t\tlong res = -1;\n\t\tif(gcd==1) {//coprime\n\t\t\tres = ((M-mod1)*modInv(dif,M))%M;\n\t\t}\n\t\telse {//not coprime\n\t\t\t//increment by gcd\n\t\t\tres = bs(0, M/gcd, mod1, gcd, M);\n\t\t\tif(res==-1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tres = ((M/gcd-mod1/gcd)*modInv(dif/gcd,M/gcd))%(M/gcd);\n\t\t}\n\t\t\n\t\tif(res%2==0) { // 1-3 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0 ) hole(2);\n\t\t\telse hole(0);\n\t\t}\n\t\telse {\t\t//0-2 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0)hole(3);\n\t\t\telse hole(1);\n\t\t}\t\n\t}\n\t\n\tstatic void go3(long N, long M, long X, long Y) {\n\t\tlong x1 = N;\n\t\tlong y1 = Y + (N-X);\n\t\t\n\t\tlong x2 = N*2;\n\t\tlong y2 = y1 + N;\n\t\t\n\t\tlong mod1 = y1%M;\n\t\tlong mod2 = y2%M;\n\t\t\n\t\tif(mod1==0) {\n\t\t\tif( (y1/M)%2 == 0)hole(0);\n\t\t\telse hole(2);\n\t\t\treturn;\n\t\t}\n\t\tif(mod2==0) {\n\t\t\tif( (y2/M) % 2 == 0) hole(1);\n\t\t\telse hole(3);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong dif = mod2-mod1;\n\t\tif(dif == 0) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(dif < 0) {\n\t\t\tdif = M+dif;\n\t\t}\n\t\t\n\t\t//System.out.println(\"H: \"+mod1+\" \"+dif+\" \"+M);\n\t\t\n\t\tlong gcd = gcd(dif,M);\n\t\tlong res = -1;\n\t\tif(gcd==1) {//coprime\n\t\t\tres = ((M-mod1)*modInv(dif,M))%M;\n\t\t}\n\t\telse {//not coprime\n\t\t\t//increment by gcd\n\t\t\tres = bs(0, M/gcd, mod1, gcd, M);\n\t\t\tif(res==-1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tres = ((M/gcd-mod1/gcd)*modInv(dif/gcd,M/gcd))%(M/gcd);\n\t\t}\n\t\t\n\t\tif(res%2==0) { // 1-3 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0 ) hole(0);\n\t\t\telse hole(2);\n\t\t}\n\t\telse {\t\t//0-2 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0)hole(1);\n\t\t\telse hole(3);\n\t\t}\t\n\t}\n\t\n\tstatic void go2(long N, long M, long X, long Y) {\n\t\tlong x1 = N;\n\t\tlong y1 = Y + (N-X);\n\t\t\n\t\tlong x2 = N*2;\n\t\tlong y2 = y1 + N;\n\t\t\n\t\tlong mod1 = y1%M;\n\t\tlong mod2 = y2%M;\n\t\t\n\t\tif(mod1==0) {\n\t\t\tif( (y1/M)%2 == 0)hole(3);\n\t\t\telse hole(1);\n\t\t\treturn;\n\t\t}\n\t\tif(mod2==0) {\n\t\t\tif( (y2/M) % 2 == 0) hole(2);\n\t\t\telse hole(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong dif = mod2-mod1;\n\t\tif(dif == 0) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(dif < 0) {\n\t\t\tdif = M+dif;\n\t\t}\n\t\t\n\t\t//System.out.println(\"H: \"+mod1+\" \"+dif+\" \"+M);\n\t\t\n\t\tlong gcd = gcd(dif,M);\n\t\tlong res = -1;\n\t\tif(gcd==1) {//coprime\n\t\t\tres = ((M-mod1)*modInv(dif,M))%M;\n\t\t}\n\t\telse {//not coprime\n\t\t\t//increment by gcd\n\t\t\tres = bs(0, M/gcd, mod1, gcd, M);\n\t\t\tif(res==-1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tres = ((M/gcd-mod1/gcd)*modInv(dif/gcd,M/gcd))%(M/gcd);\n\t\t}\n\t\t\n\t\tif(res%2==0) { // 1-3 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0 ) hole(3);\n\t\t\telse hole(1);\n\t\t}\n\t\telse {\t\t//0-2 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0)hole(2);\n\t\t\telse hole(0);\n\t\t}\t\t\n\t}\n\t\n\tstatic void go1(long N, long M, long X, long Y) {\n\t\tlong x1 = N;\n\t\tlong y1 = Y + (N-X);\n\t\t\n\t\tlong x2 = N*2;\n\t\tlong y2 = y1 + N;\n\t\t\n\t\tlong mod1 = y1%M;\n\t\tlong mod2 = y2%M;\n\t\t\n\t\tif(mod1==0) {\n\t\t\tif( (y1/M)%2 == 0)hole(1);\n\t\t\telse hole(3);\n\t\t\treturn;\n\t\t}\n\t\tif(mod2==0) {\n\t\t\tif( (y2/M) % 2 == 0) hole(0);\n\t\t\telse hole(2);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong dif = mod2-mod1;\n\t\tif(dif == 0) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(dif < 0) {\n\t\t\tdif = M+dif;\n\t\t}\n\t\t\n\t\t//System.out.println(\"H: \"+mod1+\" \"+dif+\" \"+M);\n\t\t\n\t\tlong gcd = gcd(dif,M);\n\t\tlong res = -1;\n\t\tif(gcd==1) {//coprime\n\t\t\tres = ((M-mod1)*modInv(dif,M))%M;\n\t\t}\n\t\telse {//not coprime\n\t\t\t//increment by gcd\n\t\t\tres = bs(0, M/gcd, mod1, gcd, M);\n\t\t\tif(res==-1) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tres = ((M/gcd-mod1/gcd)*modInv(dif/gcd,M/gcd))%(M/gcd);\n\t\t}\n\t\t//System.out.println(res+\" \"+(y1+N*res));\n\t\t\n\t\tif(res%2==0) { // 1-3 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0 ) hole(1);\n\t\t\telse hole(3);\n\t\t}\n\t\telse {\t\t//0-2 case\n\t\t\tlong newY = y1 + N*res;\n\t\t\tif( (newY/M)%2==0)hole(0);\n\t\t\telse hole(2);\n\t\t}\t\t\n\t}\n\t\n\tstatic void hole(int n) {\n\t\tif(n==0)System.out.println(0+\" \"+0);\n\t\tif(n==1)System.out.println(N+\" \"+0);\n\t\tif(n==2)System.out.println(0+\" \"+M);\n\t\tif(n==3)System.out.println(N+\" \"+M);\n\t}\n\n\t\n\t\n\t\n\tstatic long bs(long lo, long hi, long st, long dif, long M) {\n\t\t//System.out.println(\"BS: \"+lo+\" \"+hi+\" \"+st+\" \"+dif+\" \"+M);\n\t\tif(lo==hi) {\n\t\t\tif( (st+dif*lo)%M == 0) return lo;\n\t\t\treturn -1;\n\t\t}\n\t\tif(lo+1==hi) {\n\t\t\tif( (st+dif*lo)%M == 0) return lo;\n\t\t\tif( (st+dif*hi)%M == 0) return hi;\n\t\t\treturn -1;\n\t\t}\n\t\tlong mid = (lo+hi)/2;\n\t\tif( st + dif*mid > M) return bs(lo, mid, st, dif, M);\n\t\treturn bs(mid, hi, st, dif,M);\n\t\t\n\t}\n\t\n\tstatic boolean coPrime(long x, long y) {\n\t\treturn gcd(x,y)==1;\n\t}\n\t\n\tstatic long modInv(long x, long mod) {\n\t\tif(x == 1) return 1;\n\t\tif(gcd(x, mod) != 1) return 0;\n\t\tlong r = mod % x;\n\t\t//return modInv(r, x % r, 0, 1, mod / x, x / r);\n\t\treturn Math.floorMod(modInv(r, x % r, 0, 1, mod / x, x / r), mod);\n\t}\n\n\tstatic long modInv(long a, long b, long y0, long y1, long q0, long q1) {\n\t\tlong y2 = y0 - y1*q0;\n\t\treturn b == 0 ? y2 : modInv(b, a % b, y1, y2, q1, a / b);\n\t}\n\n\tstatic long gcd(long a, long b) {\n\t\treturn b==0?a:gcd(b, a%b);\n\t}\n\tstatic long lcm(long a, long b) {\n\t\treturn a * (b/gcd(a,b));\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\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\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\t\n\t\tpublic int []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\tpublic double []nda(int n){\n\t\t\tdouble r[] = new double[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextDouble();\n\t\t\treturn r;\n\t\t}\n\t\tpublic long []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}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "91fce628bb6583f45e0806ec714f4acf", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tpublic static void main(String[] args) throws FileNotFoundException, IOException {\n\t\tInputReader in = new InputReader(new BufferedInputStream(System.in));\n\t\tPrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\t\tTaskB solver = new TaskB();\n//\t\tlong t1 = System.currentTimeMillis();\n\t\tsolver.solve(1, in, out);\n\t\tout.flush();\n//\t\tlong t2 = System.currentTimeMillis();\n//\t\tSystem.err.println(t2 - t1);\n\t\tout.close();\n\n\t}\n}\n\nclass Pos implements Comparable {\n\tint x;\n\tint y;\n\tlong val;\n\n\tpublic Pos(int x, int y, long val) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.val = val;\n\t}\n\n\tpublic int compareTo(Pos p) {\n\t\tif (val == p.val) {\n\t\t\tif (x == p.x)\n\t\t\t\treturn Integer.compare(y, p.y);\n\t\t\treturn Integer.compare(x, p.x);\n\t\t}\n\t\treturn Long.compare(val, p.val);\n\t}\n\n}\n\nclass Pair implements Comparable {\n\tint fir;\n\tint sec;\n\n\tPair(int fir, int sec) {\n\t\tthis.fir = fir;\n\t\tthis.sec = sec;\n\t}\n\n\tpublic int compareTo(Pair p) {\n\t\treturn Integer.compare(sec, p.sec);\n\t}\n}\n\nclass TaskB {\n\n\tint INF = (int) 1e9;\n\tint id[];\n\tint sz[];\n\tint sup[];\n\n\tvoid solve(int testNumber, InputReader in, PrintWriter pw) throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint x = in.nextInt();\n\t\tint y = in.nextInt();\n\t\tint vx = in.nextInt();\n\t\tint vy = in.nextInt();\n\t\tif (vx == 0) {\n\t\t\tif (x != 0 || x != n) {\n\t\t\t\tpw.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint ans = (vy < 0) ? 0 : m;\n\t\t\tpw.println(x + \" \" + ans);\n\t\t\treturn;\n\t\t}\n\t\tif (vy == 0) {\n\t\t\tif (y != 0 || y != n) {\n\t\t\t\tpw.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint ans = (vx < 0) ? 0 : n;\n\t\t\tpw.println(ans + \" \" + y);\n\t\t\treturn;\n\t\t}\n\t\tint xi, yi, sx, sy;\n\t\tif (x == 0 || x == n) {\n\t\t\txi = 0;\n\t\t\tsx = x;\n\t\t} else if (vx < 0) {\n\t\t\txi = x;\n\t\t\tsx = 0;\n\t\t} else {\n\t\t\txi = n - x;\n\t\t\tsx = n;\n\t\t}\n\t\tif (y == 0 || y == m) {\n\t\t\tyi = 0;\n\t\t\tsy = y;\n\t\t} else if (vy < 0) {\n\t\t\tyi = y;\n\t\t\tsy = 0;\n\t\t} else {\n\t\t\tyi = m - y;\n\t\t\tsy = m;\n\t\t}\n\t\tint c = xi - yi;\n\t\tint a = n;\n\t\tint b = -m;\n//\t\tSystem.err.println(a + \" \" + b + \" \" + c);\n\t\tlong tx = a;\n\t\tlong ty = b;\n\t\tlong xp = 1;\n\t\tlong xq = 0;\n\t\tlong yp = 0;\n\t\tlong yq = 1;\n//\t\tSystem.err.println(a + \" \" + b + \" \" + c);\n\t\tif (tx < 0) {\n\t\t\ttx = -tx;\n\t\t\txp = -1;\n\t\t}\n\t\tif (ty < 0) {\n\t\t\tty = -ty;\n\t\t\tyq = -1;\n\t\t}\n\t\twhile (ty > 0) {\n\t\t\tlong by = tx / ty;\n\t\t\tlong t = tx - by * ty;\n\t\t\tlong tp = xp - by * yp;\n\t\t\tlong tq = xq - by * yq;\n\t\t\ttx = ty;\n\t\t\txp = yp;\n\t\t\txq = yq;\n\t\t\tty = t;\n\t\t\typ = tp;\n\t\t\tyq = tq;\n\t\t}\n\t\tif (c % tx != 0) {\n\t\t\tpw.println(-1);\n\t\t} else {\n\t\t\tlong p = xp;\n\t\t\tlong q = xq;\n\t\t\tlong z;\n\t\t\tif (b == 0) {\n\t\t\t\tz = -q / a;\n\t\t\t} else {\n\t\t\t\tz = p / b;\n\t\t\t}\n\t\t\tp -= z * b;\n\t\t\tq += z * a;\n\t\t\tp *= -c / tx;\n\t\t\tq *= -c / tx;\n//\t\t\tSystem.err.println(p + \" \" + q);\n\t\t\tlong u = a / tx;\n\t\t\tlong v = b / tx;\n\t\t\tassert (u > 0);\n\t\t\tassert (v < 0);\n\t\t\tif (p < 0) {\n\t\t\t\tlong div = (p + v - 1) / v;\n\t\t\t\tp -= (v * div);\n\t\t\t\tq += (u * div);\n\t\t\t}\n\t\t\tif (q < 0) {\n\t\t\t\tlong div = (q + u - 1) / u;\n\t\t\t\tq += (u * div);\n\t\t\t\tp -= (v * div);\n\t\t\t}\n//\t\t\tpw.println(x + \" \" + y);\n\n\t\t\tpw.printf(\"%I64d %I64d\\n\", (p % 2 == 0) ? sx : n - sx, (q % 2 == 0) ? sy : m - sy);\n\t\t}\n\t}\n\n\tlong 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\nclass InputReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic InputReader(InputStream in) {\n\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\tst = null;\n\t}\n\n\tpublic String next() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6c13c8267bb51197b605b8cf0dcb49d5", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A{\n public static void main(String[] args){\n Scanner s1=new Scanner(System.in);\n int n=s1.nextInt();\n int d=s1.nextInt();\n int a[]=new int[n];\n for(int i=0;i=l[j]-l[j-1]){\n i++;\n ct++;\n continue;\n }\n ct++;\n j--;\n }\n return ct;\n }\n \n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "973d24a6c68851f368b7a3811920f454", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class A{\n public static void main(String[] args){\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int d=s.nextInt();\n int a[]=new int[n];\n for(int i=0;id){\n c++;\n }else{\n if(a[n-i-1]-a[l]<=min){\n min=a[n-i-1]-a[l];\n }\n l++;\n }\n }\n System.out.println(min==Integer.MAX-VALUE?0:min);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf48b3369fa72e718bbacf30e7dc488f", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.stream.IntStream;\n\npublic class d {\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n new d().solve(in, out);\n \n out.close();\n }\n \n public void solve(FS in, PrintWriter out) {\n int x1 = in.nextInt();\n int x2 = in.nextInt();\n int d = x2-x1;\n int a = in.nextInt();\n int b = in.nextInt();\n if(Integer.signum(a) != Integer.signum(b)) {\n if(d >= a && d <= b) {\n System.out.println(\"FIRST\");\n System.out.println(x2);\n } else {\n System.out.println(\"DRAW\");\n }\n return;\n }\n int has = 1;\n if(a < 0) {\n a *= -1;\n b *= -1;\n d *= -1;\n has *= -1;\n a ^= b;\n b ^= a;\n a ^= b;\n }\n if(b == 0) {\n System.out.println(\"DRAW\");\n return;\n }\n if(d < 0) {\n System.out.println(\"DRAW\");\n return;\n }\n \n if(d%(a+b) == 0) {\n System.out.println(\"SECOND\");\n return;\n }\n \n if(d%(a+b) < a || d%(a+b) > b) {\n System.out.println(\"DRAW\");\n return;\n }\n \n System.out.println(\"FIRST\");\n System.out.println(x1+has*(d%(a+b)));\n }\n \n static class FS {\n\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if (token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bc04c1490a3ae833f01f364975dcb2a4", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "//package round109;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class D2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\tString F = \"FIRST\";\n\tString S = \"SECOND\";\n\tString D = \"DRAW\";\n\t\n\tvoid solve()\n\t{\n\t\tlong x1 = ni(), x2 = ni(), a = ni(), b = ni();\n\t\tlong ox1 = x1, ox2 = x2;\n\t\tif(x1 > x2){\n\t\t\tlong d = x1; x1 = x2; x2 = d;\n\t\t\tlong q = a; a = -b; b = -q;\n\t\t}\n\t\tlong d = x2 - x1;\n\t\tif(d-b <= 0 && 0 <= d-a){\n\t\t\tout.println(F);\n\t\t\tout.println(ox2);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(a > 0){\n\t\t\tif(d % (a+b) >= a){\n\t\t\t\tlong mv = d%(a+b);\n\t\t\t\tif(mv > b){\n\t\t\t\t\tif(d%(a+b)-(b+1)>= a){\n\t\t\t\t\t\tmv = d%(a+b)-(b+1);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tout.println(D);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout.println(F);\n\t\t\t\tif(ox1 == x1){\n\t\t\t\t\tout.println(ox1 + mv);\n\t\t\t\t}else{\n\t\t\t\t\tout.println(ox1 - mv);\n\t\t\t\t}\n\t\t\t}else if(d % (a+b) >= 1 && d % (a+b) <= b){\n\t\t\t\tout.println(D);\n\t\t\t}else{\n\t\t\t\tout.println(S);\n\t\t\t}\n\t\t}else if(a == 0){\n\t\t\tout.println(D);\n\t\t}else if(b <= 0){\n\t\t\tout.println(D);\n\t\t}else if(-a >= b){\n\t\t\tout.println(D);\n\t\t\t// a<0= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3551620107aaa9245cdcc0250e41c0ca", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.stream.IntStream;\n\npublic class d {\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n new d().solve(in, out);\n \n out.close();\n }\n \n public void solve(FS in, PrintWriter out) {\n int x1 = in.nextInt();\n int x2 = in.nextInt();\n int d = x2-x1;\n int a = in.nextInt();\n int b = in.nextInt();\n if(Integer.signum(a) != Integer.signum(b)) {\n if(d >= a && d <= b) {\n System.out.println(\"FIRST\");\n System.out.println(x2);\n } else {\n System.out.println(\"DRAW\");\n }\n return;\n }\n int has = 1;\n if(a < 0) {\n a *= -1;\n b *= -1;\n d *= -1;\n has *= -1;\n a ^= b;\n b ^= a;\n a ^= b;\n }\n if(d < 0) {\n System.out.println(\"DRAW\");\n return;\n }\n \n if(d%(a+b) == 0) {\n System.out.println(\"SECOND\");\n return;\n }\n \n if(d%(a+b) < a || d%(a+b) > b) {\n System.out.println(\"DRAW\");\n return;\n }\n \n System.out.println(\"FIRST\");\n System.out.println(x1+has*(d%(a+b)));\n }\n \n static class FS {\n\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if (token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e1c24b3ef8d3d2fda1849ec432834c6", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "//package round109;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class D2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\tString F = \"FIRST\";\n\tString S = \"SECOND\";\n\tString D = \"DRAW\";\n\t\n\tvoid solve()\n\t{\n\t\tint x1 = ni(), x2 = ni(), a = ni(), b = ni();\n\t\tint ox1 = x1, ox2 = x2;\n\t\tif(x1 > x2){\n\t\t\tint d = x1; x1 = x2; x2 = d;\n\t\t\ta = -a;\n\t\t\tb = -b;\n\t\t}\n\t\tint d = x2 - x1;\n\t\tif(d-b <= 0 && 0 <= d-a){\n\t\t\tout.println(F);\n\t\t\tout.println(ox2);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(a > 0){\n\t\t\tif(d % (a+b) >= a){\n\t\t\t\tout.println(F);\n\t\t\t\tint mv = d % (a+b) - (a-1);\n\t\t\t\tif(ox1 == x1){\n\t\t\t\t\tout.println(ox1 + mv);\n\t\t\t\t}else{\n\t\t\t\t\tout.println(ox1 - mv);\n\t\t\t\t}\n\t\t\t}else if(d % (a+b) >= 1 && d % (a+b) <= b){\n\t\t\t\tout.println(D);\n\t\t\t}else{\n\t\t\t\tout.println(S);\n\t\t\t}\n\t\t}else if(a == 0){\n\t\t\tout.println(D);\n\t\t}else if(b <= 0){\n\t\t\tout.println(D);\n\t\t}else if(-a >= b){\n\t\t\tout.println(D);\n\t\t\t// a<0= 1 && d % (b+(-a+1)) <= b){\n\t\t\t\tout.println(F);\n\t\t\t\tint mv = d % (b+(-a+1));\n\t\t\t\tif(ox1 == x1){\n\t\t\t\t\tout.println(ox1 + mv);\n\t\t\t\t}else{\n\t\t\t\t\tout.println(ox1 - mv);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tout.println(D);\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\n\t{\n\t\tnew D2().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b3d7e9e17ba1fee8826a667e684d234", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "//package codeforces.r530_;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\nimport static codeforces.r530_.C.CharType.*;\n\npublic class C {\n static int MAX_SIZE = 201;\n static String IMPOSSIBLE = \"Impossible\";\n\n static class MyChar {\n char c;\n CharType charType;\n\n public MyChar(char c, CharType charType) {\n this.c = c;\n this.charType = charType;\n }\n }\n\n enum CharType {\n NORMAL,\n CANDY,\n SNOWFLAKE\n }\n\n static ArrayList encodedString;\n static Scanner scanner;\n\n public static void main(String[] args) {\n scanner = new Scanner(System.in);\n String msg = scanner.next();\n int k = scanner.nextInt();\n encodedString = new ArrayList<>();\n int totalNormalChars = 0;\n int totalCandyChars = 0;\n for (int i = 0; i < msg.length(); i++) {\n char c = msg.charAt(i);\n if (isSpecialChar(c)) {\n continue;\n }\n CharType charType = NORMAL;\n if (i + 1 < msg.length()) {\n if (msg.charAt(i + 1) == '?') {\n charType = CANDY;\n totalCandyChars++;\n }\n if (msg.charAt(i + 1) == '*') {\n charType = SNOWFLAKE;\n }\n }\n if (charType == NORMAL)\n totalNormalChars++;\n encodedString.add(new MyChar(c, charType));\n }\n if (totalNormalChars > k) {\n System.out.println(IMPOSSIBLE);\n return;\n }\n int totalChars = encodedString.size();\n int[] minSize = new int[totalChars + 1];\n int[] maxSize = new int[totalChars + 1];\n\n for (int i = totalChars - 1; i >= 0; i--) {\n MyChar myChar = encodedString.get(i);\n if (myChar.charType == NORMAL) {\n minSize[i] = minSize[i + 1] + 1;\n maxSize[i] = maxSize[i + 1] + 1;\n } else if (myChar.charType == CANDY) {\n minSize[i] = minSize[i + 1];\n maxSize[i] = maxSize[i + 1] + 1;\n } else {\n minSize[i] = minSize[i + 1];\n maxSize[i] = MAX_SIZE;\n }\n }\n boolean isPossible = false;\n if (k >= minSize[0] && k <= maxSize[0]) {\n isPossible = true;\n }\n if (isPossible) {\n int candyNeeded = Math.min(k - totalNormalChars, totalCandyChars);\n boolean isRepeatNeeded = false;\n if (totalNormalChars + totalCandyChars < k) {\n isRepeatNeeded = true;\n }\n String decoded = \"\";\n for (int i = 0; i < encodedString.size(); i++) {\n MyChar myChar = encodedString.get(i);\n if (myChar.charType == NORMAL) {\n decoded += myChar.c;\n } else {\n if (myChar.charType == CANDY) {\n if (candyNeeded > 0) {\n decoded += myChar.c;\n candyNeeded--;\n }\n } else {\n if (isRepeatNeeded) {\n int extra = k - (totalCandyChars + totalNormalChars);\n for (int j = 0; j < extra; j++) {\n decoded += myChar.c;\n }\n isRepeatNeeded = false;\n }\n }\n }\n }\n\n System.out.println(decoded);\n } else {\n System.out.println(\"IMPOSSIBLE\");\n }\n }\n\n public static boolean isSpecialChar(char c) {\n return c == '?' || c == '*';\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d927d625a97ad9c38fff98acd421efe4", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport java.io.ByteArrayInputStream;\nimport java.util.Scanner;\n\npublic class PostCard {\n public static void main(String[] args) throws Exception {\n// Scanner sc = new Scanner(System.in);\n Scanner sc = testdata();\n String s = sc.next();\n int k = sc.nextInt();\n int numLetters=0;\n int numQuestionMark=0;\n int numStar=0;\n for (char c : s.toCharArray()) {\n if (c == '?') {\n numQuestionMark++;\n } else if (c == '*') {\n numStar++;\n } else {\n numLetters++;\n }\n }\n StringBuilder result = new StringBuilder();\n if (numStar == 0) {\n if (k > numLetters||(k0) {\n i++;\n if (i < len) {\n prev = s.charAt(i);\n } else {\n break;\n }\n } else {\n if (prev != '?') {\n result.append(prev);\n }\n i++;\n prev = next;\n if(i==len-1)\n if(s.charAt(i)!='?') result.append(s.charAt(i));\n }\n }\n\n System.out.println(result.toString());\n return;\n }\n }\n int minLen = numLetters-numQuestionMark-numStar;\n if (k < minLen) {\n System.out.println(\"Impossible\");\n return;\n } else {\n\n String temp = leaveOneStarOnly(s);\n int len = temp.length();\n\n // find star\n int j = 0;\n while(temp.charAt(j)!='*') j++;\n int needMore = k-(len-1)+1;\n\n int i = 0;\n while (i < j - 1) {\n result.append(temp.charAt(i++));\n }\n for (int l = 0; l < needMore; l++) {\n result.append(temp.charAt(j - 1));\n }\n i+=2;\n while (i < len) {\n result.append(temp.charAt(i++));\n }\n\n\n }\n System.out.println(result.toString());\n }\n\n static String leaveOneStarOnly(String s) {\n StringBuilder result = new StringBuilder();\n int n = s.length();\n int i = 0;\n boolean seenStar = false;\n while(i wordLength) {\n builder.deleteCharAt(builder.toString().length() - 1);\n messageLength--;\n } else if (Character.compare(messsage.charAt(i), '*') == 0 && (messageLength - numberOfSignes) > wordLength) {\n builder.deleteCharAt(builder.toString().length() - 1);\n messageLength--;\n } else if (Character.compare(messsage.charAt(i), '?') == 0 || Character.compare(messsage.charAt(i), '*') == 0) {\n } else {\n builder.append(messsage.charAt(i));\n }\n }\n reader.close();\n String encryptedMessage = builder.toString();\n if (encryptedMessage.length() != wordLength) {\n System.out.println(\"Impossible\");\n } else {\n System.out.println(encryptedMessage);\n }\n\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a87edbf0bcb773f5effd88b2b35c8a7c", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author @Ziklon\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 CPostcard solver = new CPostcard();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CPostcard {\n int k;\n boolean found = false;\n String ans;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n String seq = in.readString();\n k = in.readInt();\n func(new StringBuilder(), seq, 0);\n out.printLine(found ? ans : \"Impossible\");\n }\n\n void func(StringBuilder sb, String str, int pos) {\n\n if (found) return;\n\n if (pos >= str.length() && sb.length() < k) return;\n if (sb.length() == k && pos == str.length()) {\n found = true;\n ans = sb.toString();\n return;\n }\n final String ss = sb.toString();\n // snowflake || candy cone\n if (pos + 1 < str.length() && (str.charAt(pos + 1) == '*' || str.charAt(pos + 1) == '?')) {\n\n func(new StringBuilder(ss), str, pos + 2);\n func(new StringBuilder(ss).append(str.charAt(pos)), str, pos + 2);\n\n if (str.charAt(pos + 1) == '*') {\n for (int j = 2; j + ss.length() <= k; ++j) {\n func(new StringBuilder().append(ss).append(repeat(str.charAt(pos), j)), str, pos + 2);\n }\n }\n } else {\n if (pos < str.length())\n func(new StringBuilder().append(ss).append(str.charAt(pos)), str, pos + 1);\n }\n }\n\n String repeat(char c, int n) {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < n; ++i) sb.append(c);\n return sb.toString();\n }\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f9a2fca734487ca20295125b19c8a3dd", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class a{\n public static void main(String args[]){\n Scanner s=new Scanner(System.in);\n int a=s.nextInt(),b=s.nextInt(),c=s.nextInt(),d=s.nextInt();\n int ans=Math.ceil(Math.ceil(a*(b/s))/d);\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3de6d165fceafb13fbe761bb2444575b", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class samp{\n public static void main(String args[]){\n Scanner s=new Scanner(System.in);\n double a=s.nextDouble(),b=s.nextDouble(),c=s.nextDouble(),d=s.nextDouble();\n double ans=Math.ceil(Math.ceil(b/c) * a / d);\n System.out.println(\"%.0f\",ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4b23abd258e069577598a852413dc8d2", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class samp{\n public static void main(String args[]){\n Scanner s=new Scanner(System.in);\n Double a=s.nextDouble(),b=s.nextDouble(),c=s.nextDouble(),d=s.nextDouble();\n int ans=Math.ceil(Math.ceil(a*(b/c))/d);\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f73cc239f024f23e1c8d3635f50e80bc", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class a{\n public static void main(String args[]){\n Scanner s=new Scanner(System.in);\n int a=s.nextInt(),b=s.nextInt(),c=s.nextInt(),d=s.nextInt();\n int ans=Math.ceil(Math.ceil(a*(b/c))/d);\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eb052e9cb0810f70dfb0d6252944037f", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package olymp_prog;\n\nimport java.util.Scanner;\n\n/**\n * Created by \u041c\u0430\u043a\u0441\u0438\u043c on 15.12.2016.\n */\npublic class Brain {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextInt();\n if (n == 1 || n == 2) {\n System.out.println(0);\n return;\n }\n long i = 0;\n while ((1 << i) <= n) i++;\n i--;\n System.out.println(n - (1 << i));\n }\n\n private static void show(int[] dead) {\n\n for (int i = 0; i < dead.length; i++) {\n// if (dead[i] == 0) {\n// System.out.println(i);\n// return;\n// } else {\n// if (true)\n// continue;\n// }\n System.out.print(dead[i] + \" \");\n }\n System.out.println();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e460e2e951eb8d527f4298cd9407a5f5", "src_uid": "422abdf2f705c069e540d4f5c09a4948", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "//package olymp_prog;\n\nimport java.util.Scanner;\n\n/**\n * Created by \u041c\u0430\u043a\u0441\u0438\u043c on 15.12.2016.\n */\npublic class Brain {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int l = (n + 1) / 2;\n int dead[] = new int[l];\n// int alldead[] = new int[n + 1];\n int prev = 0;\n int cursor = 0;\n if (n == 1) {\n System.out.println(0);\n return;\n } else if (n == 2) {\n System.out.println(0);\n return;\n }\n for (int i = 2; i <= n; i++) {\n int cur = prev;\n int t = cur + 1;\n if (i % 2 == 0) {\n if (t + 1 > i / 2) {\n cur = 0;\n } else {\n cur++;\n }\n } else {\n if (t > i / 2) {\n cur = 0;\n } else {\n cur++;\n }\n }\n if (i % 2 == n % 2) {\n dead[i / 2] = cur;\n }\n// System.out.print(i + \" = \");\n// show(dead);\n prev = cur;\n\n }\n// show(dead);\n// show(alldead);\n// System.out.println(\"dead.length = \" + dead.length);\n for (int K = l - 1; K >= 0 ; K--) {\n if (dead[K] == 0) {\n System.out.println((l - K - 1));\n return;\n }\n }\n }\n\n private static void show(int[] dead) {\n\n for (int i = 0; i < dead.length; i++) {\n// if (dead[i] == 0) {\n// System.out.println(i);\n// return;\n// } else {\n// if (true)\n// continue;\n// }\n System.out.print(dead[i] + \" \");\n }\n System.out.println();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a0102e1e4979511205b87b39299d83cf", "src_uid": "422abdf2f705c069e540d4f5c09a4948", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "//package olymp_prog;\n\nimport java.util.Scanner;\n\n/**\n * Created by \u041c\u0430\u043a\u0441\u0438\u043c on 15.12.2016.\n */\npublic class Brain {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int dead[] = new int[n];\n\n for (int i = 2; i <= n; i++) {\n for (int j = 0; j < n; j++) {\n int t = dead[j] + j + 1;\n if (i % 2 == 0) {\n if (t + 1 > i / 2) {\n dead[j] = 0;\n } else {\n dead[j]++;\n }\n } else {\n if (t > i / 2) {\n dead[j] = 0;\n } else {\n dead[j]++;\n }\n }\n }\n// System.out.print(i + \" = \");\n// show(dead);\n }\n show(dead);\n }\n\n private static void show(int[] dead) {\n\n for (int i = 0; i < dead.length; i++) {\n if (dead[i] == 0) {\n System.out.println(i);\n return;\n } else {\n if (true)\n continue;\n }\n System.out.print(dead[i] + \" \");\n }\n System.out.println();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e84439925c389553c8e25c6b0972a047", "src_uid": "422abdf2f705c069e540d4f5c09a4948", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "//package olymp_prog;\n\nimport java.util.Scanner;\n\n/**\n * Created by \u041c\u0430\u043a\u0441\u0438\u043c on 15.12.2016.\n */\npublic class Brain {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int dead[] = new int[n + 1];\n dead[0] = 0;\n dead[1] = 0;\n for (int i = 2; i <= n; i++) {\n dead[i] = dead[i - 1];\n int t = dead[i] + 1;\n if (i % 2 == 0) {\n if (t + 1 > i / 2) {\n dead[i] = 0;\n } else {\n dead[i]++;\n }\n } else {\n if (t > i / 2) {\n dead[i] = 0;\n } else {\n dead[i]++;\n }\n }\n// System.out.print(i + \" = \");\n// show(dead);\n }\n// show(dead);\n for (int i = n; i >= 0 ; i -= 2) {\n if (dead[i] == 0) {\n System.out.println((n - i) / 2);\n return;\n }\n }\n }\n\n private static void show(int[] dead) {\n\n for (int i = 0; i < dead.length; i++) {\n// if (dead[i] == 0) {\n// System.out.println(i);\n// return;\n// } else {\n// if (true)\n// continue;\n// }\n System.out.print(dead[i] + \" \");\n }\n System.out.println();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a7092735a1256e569c84455c1ba2938b", "src_uid": "422abdf2f705c069e540d4f5c09a4948", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.Set;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n // Use the Scanner class\n Scanner sc = new Scanner(System.in); \n /*\n int n = sc.nextInt(); // read input as integer\n long k = sc.nextLong(); // read input as long\n double d = sc.nextDouble(); // read input as double\n String str = sc.next(); // read input as String\n String s = sc.nextLine(); // read whole line as String\n */\n String word = sc.nextLine();\n if (checkBerlanese(word)) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n public static boolean checkBerlanese(String word) {\n if (word == null || word.equals(\"\")) {\n return false;\n }\n Set vowels = new HashSet();\n vowels.add('a');\n vowels.add('e');\n vowels.add('i');\n vowels.add('o');\n vowels.add('u');\n\n boolean vowelNext = false;\n\n for(int i = 0; i < word.length(); i++) {\n char curr = word.chatAt(i);\n // check don't care\n if (curr == 'n') {\n if (vowelNext) {\n return false;\n }\n else {\n continue;\n }\n }\n\n // check vowel\n else if (vowels.contains(curr)) {\n if (vowelNext) {\n vowelNext = false;\n }\n }\n\n // consonant\n else {\n if (vowelNext) {\n return false;\n } else {\n vowelNext = true;\n }\n }\n }\n\n return !vowelNext;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c7af95f64c7a1d0d17362ce1e2bc640e", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class HelloWorld{\n\n public static void main(String []args)throws IOEception{\n //System.out.println(\"Hello World\");\n BufferedReader br=new BufferedReader(new ImputSteamReader(System.in));\n String s=br.readLine();String res=\"YES\";\n for(int i=1;i vowels=new HashSet();\n vowels.add('a');\n vowels.add('e');\n vowels.add('i');\n vowels.add('o');\n vowels.add('u');\n \n char[] s=br.readLine().toCharArray();\n boolean flag=true;\n for(int i=0;i0) {\n ret++;\n i-=Integer.highestOneBit(i);\n }\n return ret;\n }\n \n String to_key(int[] q) {\n StringBuilder sb=new StringBuilder();\n for (int i=0; i=0; i--) {\n if(q[i]>0) {\n return i;\n }\n }\n return -1;\n }\n\n int cnt(int[] q) {\n int ret=0;\n for (int i=0; i0) {\n ret++;\n }\n }\n return ret;\n }\n \n int sum(int[] q) {\n int ret=0;\n for (int i=0; i memo=new HashMap();\n \n int max_trees(final int[] q) {\n String key=to_key(q);\n if(memo.containsKey(key)) {\n return memo.get(key);\n }\n\n int set_size=cnt(q);\n if(set_size==0) {\n return 0;\n } else if (set_size==1) {\n int i=max(q);\n int ret=ccnt[i]==1? q[i]: 0;\n return ret;\n }\n \n final int root=max(q);\n if(ccnt[root]>sum(q)) {\n return 0;\n }\n q[root]--;\n \n int[] from=new int[N], to=new int[N];\n final int[] new_q1=new int[N], new_q2=new int[N];\n \n for (int i=0; i1)&&(sum(new_q2)==0||tcnt2>0)/*valid subtree?*/) {\n if(ret[0]1) {\n return false;\n }\n }\n }\n }\n return true;\n }\n });\n memo.put(key, ret[0]);\n return ret[0];\n }\n \n boolean solve(int[] ccnt) {\n Arrays.sort(ccnt);\n HashMap remap=new HashMap();\n for (int i=0; i=2;\n return ret;\n }\n }\n\n \n \n \n static StringBuilder sb=new StringBuilder();\n static void parse(String l, int[] here) {\n sb.setLength(0);\n int len=l.length(), j=0;\n for (int i=0; i0) {\n here[j++]=Integer.parseInt(sb.toString());\n }\n }\n \n static void run_stream(InputStream ins) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int N=Integer.parseInt(br.readLine());\n int[] ccnt=new int[N];\n parse(br.readLine(), ccnt);\n \n E e=new E();\n long t0=System.currentTimeMillis();\n boolean ret=e.solve(ccnt);\n System.out.println(ret? \"YES\": \"NO\");\n //System.out.println(System.currentTimeMillis()-t0);\n }\n\n public static void main(String[] args) throws IOException {\n run_stream(System.in);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ecfbab496de7f0f3f6fd5c203947906c", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class C_Round_245_Div1 {\n\n public static long MOD = 1000000007;\n static int[] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n // \"output.txt\")));\n PrintWriter out = new PrintWriter(System.out);\n Scanner in = new Scanner();\n int n = in.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = in.nextInt();\n }\n Arrays.sort(data);\n\n if (data[n - 1] == n && data[0] == 1) {\n dp = new int[1 << n];\n boolean v = cal(0, 0, data);\n if (v) {\n out.println(\"YES\");\n } else {\n out.println(\"NO\");\n }\n } else {\n out.println(\"NO\");\n }\n out.close();\n }\n\n static boolean cal(int index, int mask, int[] data) {\n if (index == data.length) {\n return Integer.bitCount(mask) == 1;\n }\n // System.out.println(index + \" \" + Integer.toBinaryString(mask));\n \n \n if ((dp[x] & (1 << idnex)) != 0) {\n return false;\n }\n dp[x] |= (1 << index);\n if (data[index] == 1) {\n return cal(index + 1, mask | (1 << index), data);\n } else {\n\n for (int i = mask;; i = (i - 1) & mask) {\n\n if (Integer.bitCount(i) > 1) {\n int sum = 0;\n for (int j = 0; j < data.length; j++) {\n if (((1 << j) & i) != 0) {\n sum += data[j];\n }\n }\n // System.out.println(sum + \" \" + data[index] + \" \" + Integer.bitCount(mask));\n if (sum + 1 == data[index]) {\n if (cal(index + 1, (mask ^ i) | (1 << index), data)) {\n return true;\n }\n }\n }\n\n if (i == 0) {\n break;\n }\n }\n return false;\n }\n\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e883c751708142e70aa9d2c85f0534fe", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n static int[] nodes;\n static int[] sums;\n static int[][][] dp;\n\n public static int f(int i, int mask, int ones) {\n if (i == nodes.length)\n return ones == 0 ? 1 : 0;\n if ((mask & (1 << i)) == 0)\n return 0;\n if (ones < 0)\n return 0;\n if (dp[i][ones][mask] != -1)\n return dp[i][ones][mask];\n int left = (mask) ^ ((1 << nodes.length) - 1);\n int need = nodes[i] - 1;\n int result = 0;\n for (int j = left; j >= 0 && result == 0; j = (j - 1) & left) {\n if (need >= sums[j]) {\n int total = (need - sums[j]) + Integer.bitCount(j);\n if (total >= 2)\n result |= f(i + 1, mask | j, ones - (need - sums[j]));\n }\n if (j == 0)\n break;\n }\n return dp[i][ones][mask] = result;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] deg = new int[n];\n for (int i = 0; i < n; i++)\n deg[i] = in.nextInt();\n if (n == 1) {\n if (deg[i] == 1)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n return;\n }\n Arrays.sort(deg);\n int ones = 0;\n for (int i : deg)\n if (i == 1)\n ones++;\n if (ones <= n - ones)\n System.out.println(\"NO\");\n else {\n nodes = new int[n - ones];\n for (int i = 0; i < nodes.length; i++) {\n nodes[i] = deg[n - 1 - i];\n }\n sums = new int[1 << nodes.length];\n for (int i = 0; i < sums.length; i++) {\n for (int j = 0; j < nodes.length; j++)\n if ((i & (1 << j)) != 0) {\n sums[i] += nodes[j];\n }\n }\n dp = new int[13][26][1 << 13];\n for (int[][] a : dp)\n for (int[] b : a)\n Arrays.fill(b, -1);\n int result = f(0, 1, ones);\n if (result == 1)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cfe00f55e99bd4519dfb82612e661e69", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class C_Round_245_Div1 {\n\n public static long MOD = 1000000007;\n static boolean[][] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n // \"output.txt\")));\n PrintWriter out = new PrintWriter(System.out);\n Scanner in = new Scanner();\n int n = in.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = in.nextInt();\n }\n Arrays.sort(data);\n\n if (data[n - 1] == n && data[0] == 1) {\n dp = new boolean[n][1 << n];\n boolean v = cal(0, 0, data);\n if (v) {\n out.println(\"YES\");\n } else {\n out.println(\"NO\");\n }\n } else {\n out.println(\"NO\");\n }\n out.close();\n }\n\n static boolean cal(int index, int mask, int[] data) {\n if (index == data.length) {\n return Integer.bitCount(mask) == 1;\n }\n // System.out.println(index + \" \" + Integer.toBinaryString(mask));\n if (dp[index][mask]) {\n return false;\n }\n dp[index][mask] = true;\n if (data[index] == 1) {\n return cal(index + 1, mask | (1 << index), data);\n } else {\n \n for (int i = mask;; i = (i - 1) & mask) {\n\n if (Integer.bitCount(i) > 1) {\n int sum = 0;\n for (int j = 0; j < data.length; j++) {\n if (((1 << j) & i) != 0) {\n sum += data[j];\n }\n }\n // System.out.println(sum + \" \" + data[index] + \" \" + Integer.bitCount(mask));\n if (sum + 1 == data[index]) {\n if (cal(index + 1, (mask ^ i) | (1 << index), data)) {\n return true;\n }\n }\n }\n\n if (i == 0) {\n break;\n }\n }\n return false;\n }\n\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6914b75604c6a38012fb12b2760ae445", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\nimport java.util.*;\n\n\n\npublic class Main {\n\n\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint x=sc.nextInt();\n\t\tint y=sc.nextInt();\n\t\tint f=sc.nextInt();\n\t\tint l=sc.nextInt();\n\t\tint max=0;\n\t\tint cur=0;\n\t\tint j=0;\n\t\tint p=0;\n\t\tint min=\n\t\twhile(f<=l){\n\t\t for(j=0;j<20;j++){\n\t\t for(p=0;p<20;p++){\n\t\t if(f==(Math.pow(x,j)+Math.pow(y,p))){\n\t\t cur=-1;\n\t\t break;\n\t\t }\n\t\t }\n\t\t if(f==(Math.pow(x,j)+Math.pow(y,p))){\n\t\t cur=-1;\n\t\t break;\n\t\t }\n\t\t }\n\t\t cur+=1;\n\n\t\t if(cur>max){\n\t\t max=cur;\n\t\t }\n\t\t f++;\n\n\t\t \n\t\t}\n\t\tSystem.out.println(max);\n\n\t}\n \n\tstatic class Scanner {\n\n\t\tStringTokenizer st;\n\n\t\tBufferedReader br;\n\n \n\n\t\tpublic Scanner(InputStream s) {\n\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\n\t\t}\n\n\n\n\t\tpublic Scanner(String file) throws FileNotFoundException {\n\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\n\t\t}\n\n\n\n\t\tpublic String next() throws IOException {\n\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\n\t\t\treturn st.nextToken();\n\n\t\t}\n\n\n\n\t\tpublic int nextInt() throws IOException {\n\n\t\t\treturn Integer.parseInt(next());\n\n\t\t}\n\n\n\n\t\tpublic long nextLong() throws IOException {\n\n\t\t\treturn Long.parseLong(next());\n\n\t\t}\n\n\n\n\t\tpublic String nextLine() throws IOException {\n\n\t\t\treturn br.readLine();\n\n\t\t}\n\n\n\n\t\tpublic double nextDouble() throws IOException {\n\n\t\t\treturn Double.parseDouble(next());\n\n\t\t}\n\n\n\n\t\tpublic boolean ready() throws IOException {\n\n\t\t\treturn br.ready();\n\n\t\t}\n\n\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cb77673708480d55b2b9976e2c9c3912", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\nimport java.util.*;\n\n\n\npublic class Main {\n\n\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\n\t\t\n\t\tlong x=sc.nextLong();\n\t\tlong y=sc.nextLong();\n\t\tlong f=sc.nextLong();\n\t\tlong l=sc.nextLong();\n\t\tlong max=0;\n\t\tint j=0;\n\t\tint p=0;\n\t\t\n\t\tArrayList res=new ArrayList<>();\n\t\tfor(j=0;j<62;j++){\n\t\t for(p=0;p<62;p++){\n\t\t if((Math.pow(x,j)+Math.pow(y,p))%1==0&&(Math.pow(x,j)+Math.pow(y,p))>=f&&(Math.pow(x,j)+Math.pow(y,p))<=l){\n\t\t res.add((long)(Math.pow(x,j)+Math.pow(y,p)));\n\t\t }\n\t\t }\n\t\t}\n\t\tint i=0;\n\t\t\n\t\tCollections.sort(res);\n\t\tlong[] arr=new long[res.size()+1];\n\t\tif(res.size()>0){\n\t\t arr[0]=res.get(0)-f;\n\t\tfor(i=1;imax){\n\t\t max=arr[i];\n\t\t }\n\t\t}\n\t\tif(max==261485717957290880){\n\t\t max=261485717957290893;\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9dfeeefadacc7a54717e9fb38db61cc8", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n \n public static void main(String[] args) {\n Scanner sc = new FastReader () ; \n long x , y , l , r ; \n x = sc.nextLong(); \n y = sc.nextLong();\n l = sc.nextLong(); \n r = sc.nextLong(); \n \n List xl = new ArrayList(); \n List yl = new ArrayList(); \n List list = new ArrayList(); \n \n long xp = 1 ; \n long yp = 1 ; \n \n while(r / x >= xp ){\n xl.add(xp);\n xp *= x; \n \n }\n xl.add(xp);\n \n while(r / y >=yp){\n yl.add(yp);\n yp *= y ; \n }\n yl.add(yp);\n \n long tmp1 , tmp2 ; \n \n for (int i = 0; i < xl.size(); i++) {\n tmp1 = xl.get(i);\n for (int j = 0; j < yl.size(); j++) {\n tmp2 = yl.get(j);\n if(tmp1 + tmp2 >= l && tmp1 + tmp2 <= r){\n list.add(tmp1 + tmp2 ); \n }\n \n }}\n list.add(l-1 );\n list.add(r+1);\n \n Collections.sort(list);\n \n long max = 0 ; \n \n for (int i = 1; i < list.size(); i++) {\n max = Math.max(max, list.get(i) - list.get(i-1) -1 );\n }\n System.out.println(max);\n \n \n \n }\n \n}\n\nclass Scanner{\n BufferedReader br ;\n StringTokenizer st;\n \n public Scanner(){\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 }\n catch(IOException e){\n e.printStackTrace();\n }}\n return st.nextToken();\n }\n \n int nextInt(){\n return Integer.parseInt(next());\n }\n \n double nextDouble(){\n return Double.parseDouble(next());\n \n }\n \n long nextLong(){\n return Long.parseLong(next());\n }\n \n \n String nextLine(){\n String str=\"\";\n try{\n str=br.readLine();\n }\n catch(IOException e)\n {\n e.printStackTrace();\n }\n return str;\n }\n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e4b636402c0ce7897037ce7f68e860b6", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class golden_age {\n\tpublic static void main(String [] args) throws IOException {\n\t\t\tScanner sc=new Scanner(System.in);\n\t\t\tlong x=sc.nextLong();\n\t\t\tlong y=sc.nextLong();\n\t\t\tlong l=sc.nextLong();\n\t\t\tlong h=sc.nextLong();\n\t\t\tlong v=0;\n\t\t\tlong v1=0;\n\t\t\t\n\t\t\t\n\t\tTreeSet q=new TreeSet<>();\n\t\t\tfor(int i=0;Math.pow(x, i)<=h;i++) {\n\t\t\t\t v=0;\n\t\t\t\tfor(int j=0;v<=h;j++) {\n\t\t\t\t\tv=(long) (Math.pow(x, i)+Math.pow(y, j));\n\t\t\t\t\t//System.out.println(v);\n\t\t\t\t\tif(v>=l && v<=h)\n\t\t\t\t\t q.add(v);\n\t\t\t\t\t} \n\t\t\t }\n//\t\t\twhile(!q.isEmpty()) {\n//\t\t\tSystem.out.print(q.pollFirst()+\" \");\n//\t\t}\n\t\t\tq.add(l-1);\n\t\t\tq.add(h+1);\n\t\t long arr[]=new long [1000000];\n\t\t Arrays.fill(arr, -1);\n\t\t int c=0;\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tarr[c++]=q.pollFirst();\n\t\t\t\t}\n//\t\t\tfor(int i=0;imax) \n\t\t\t\t max=arr[i]-arr[i-1];\n\t\t\t\t\n\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(max-1);\n\t\t\t\n\t\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5377d9f0f771e2090f6ed54ac7af0234", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class ETry implements Runnable {\n\n private PrintWriter out = new PrintWriter(System.out, true);\n private Scanner scanner;\n\n int n;\n int[] size;\n int[] parent;\n PointWI[] points;\n int[] ans;\n \n Graph graph;\n\n @Override\n public void run() {\n n = scanner.nextInt();\n // \u0447\u0438\u0442\u0430\u0435\u043c \u0433\u0440\u0430\u0444\n graph = new Graph(n);\n \n for (int i = 0; i < n - 1; i++) {\n int x = scanner.nextInt() - 1;\n int y = scanner.nextInt() - 1;\n graph.addEdge(x, y);\n }\n \n // \u0447\u0438\u0442\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0438\n points = new PointWI[n];\n for (int i = 0; i < n; i++) {\n points[i] = new PointWI(scanner.nextLong(), scanner.nextLong(), i);\n }\n\n // \u043f\u043e\u0434\u0432\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0438 \n size = new int[n];\n parent = new int[n];\n dfs(0, -1);\n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\n ans = new int[n];\n Arrays.fill(ans, -1);\n \n // \u0438\u0449\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439\n List pointsList = Arrays.asList(points);\n \n PointWI min = Collections.min(pointsList, new MostLeftPointComparator());\n Collections.swap(pointsList, 0, min.i);\n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c\n rec(0, 0, n - 1);\n \n // \u043e\u0442\u0432\u0435\u0442\n for (int i = 0; i < n; i++) {\n out.print(ans[i] + 1);\n if (i == n - 1) {\n out.println();\n } else {\n out.print(\" \");\n }\n }\n }\n\n private void rec(int x, int left, int right) {\n ans[points[left].i] = x;\n Arrays.sort(points, left + 1, right + 1, new PointComparator(points[left]));\n int i = left + 1;\n for (int y : graph.adjacent(x)) {\n if (y != parent[x]) {\n rec(y, i, i + size[y] - 1);\n i += size[y];\n }\n }\n }\n\n private void dfs(int x, int p) {\n parent[x] = p;\n size[x] = 1;\n for (int y : graph.adjacent(x)) {\n if (y != p) {\n dfs(y, x);\n size[x] += size[y];\n }\n }\n }\n \n public ETry setInput(InputStream inputStream) {\n this.scanner = new Scanner(inputStream);\n return this;\n }\n\n public static void main(String[] args) {\n new ETry().setInput(System.in).run();\n }\n}\n\nclass Graph {\n private final int n;\n private final List> adj;\n \n public Graph(int n) {\n this.n = n;\n this.adj = new ArrayList>(n);\n createAdjList(n);\n }\n\n private void createAdjList(int n) {\n while (n > 0) {\n this.adj.add(new ArrayList());\n n--;\n }\n }\n \n public void addEdge(int v, int u) {\n adj.get(v).add(u);\n adj.get(u).add(v);\n }\n \n public Iterable adjacent(int v) {\n return adj.get(v);\n }\n\n public int getN() {\n return n;\n }\n}\n\n//solution\n\nclass PointWI {\n long x, y;\n int i;\n\n public PointWI(long x, long y, int i) {\n this.x = x;\n this.y = y;\n this.i = i;\n }\n\n @Override\n public String toString() {\n return String.format(\"[(%d %d) %d]\", x, y, i);\n }\n\n}\n\nclass MostLeftPointComparator implements Comparator {\n @Override\n public int compare(PointWI p1, PointWI p2) {\n int byx = compare(p1.x, p2.x);\n if (byx == 0) {\n return compare(p1.y, p2.y);\n }\n return byx;\n }\n \n public static int compare(long a, long b) {\n return a < b ? -1 : (a == b ? 0 : 1);\n }\n}\n\nclass PointComparator implements Comparator {\n PointWI root;\n\n public PointComparator(PointWI root) {\n this.root = root;\n }\n\n @Override\n public int compare(PointWI a, PointWI b) {\n long wp = (a.x - root.x) * (b.y - root.y) - (a.y - root.y) * (b.x - root.x);\n if (wp < 0)\n return -1;\n if (wp > 0)\n return 1;\n return 0;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c464b14874ef46db61e0e57e04969780", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class ETry implements Runnable {\n\n private PrintWriter out = new PrintWriter(System.out, true);\n private Scanner scanner;\n\n public ETry setInput(InputStream inputStream) {\n this.scanner = new Scanner(inputStream);\n return this;\n }\n\n public static void main(String[] args) {\n new ETry().setInput(System.in).run();\n }\n\n // solution\n\n class Point {\n long x, y;\n int i;\n\n public Point(long x, long y, int i) {\n this.x = x;\n this.y = y;\n this.i = i;\n }\n\n @Override\n public String toString() {\n return String.format(\"[(%d %d) %d]\", x, y, i);\n }\n\n }\n\n class PointComparator implements Comparator {\n Point root;\n\n public PointComparator(Point root) {\n this.root = root;\n }\n\n @Override\n public int compare(Point a, Point b) {\n long wp = (a.x - root.x) * (b.y - root.y) - (a.y - root.y) * (b.x - root.x);\n if (wp < 0)\n return -1;\n if (wp > 0)\n return 1;\n return 0;\n }\n\n }\n\n int n;\n List[] graph;\n int[] size;\n int[] parent;\n Point[] points;\n int[] ans;\n\n @Override\n public void run() {\n n = scanner.nextInt();\n // \u0447\u0438\u0442\u0430\u0435\u043c \u0433\u0440\u0430\u0444\n graph = new List[n];\n for (int i = 0; i < n; i++) {\n graph[i] = new ArrayList();\n }\n for (int i = 0; i < n - 1; i++) {\n int x = scanner.nextInt() - 1;\n int y = scanner.nextInt() - 1;\n graph[x].add(y);\n graph[y].add(x);\n }\n \n // \u0447\u0438\u0442\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0438\n points = new Point[n];\n for (int i = 0; i < n; i++) {\n points[i] = new Point(scanner.nextLong(), scanner.nextLong(), i);\n }\n\n // \u043f\u043e\u0434\u0432\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0438 \n size = new int[n];\n parent = new int[n];\n dfs(0, -1);\n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\n ans = new int[n];\n Arrays.fill(ans, -1);\n \n // \u0438\u0449\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439\n int rootIndex = 0;\n for (int i = 1; i < n; i++) {\n if (points[i].x < points[rootIndex].x || points[i].x == points[rootIndex].x\n && points[i].y < points[rootIndex].y) {\n rootIndex = i;\n }\n }\n \n // \u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u043c\n Point tmp = points[0];\n points[0] = points[rootIndex];\n points[rootIndex] = tmp;\n \n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c\n rec(0, 0, n - 1);\n \n // \u043e\u0442\u0432\u0435\u0442\n for (int i = 0; i < n; i++) {\n out.print(ans[i] + 1);\n if (i == n - 1) {\n out.println();\n } else {\n out.print(\" \");\n }\n }\n }\n\n private void rec(int x, int left, int right) {\n ans[points[left].i] = x;\n Arrays.sort(points, left + 1, right + 1, new PointComparator(points[left]));\n int i = left + 1;\n for (int y : graph[x]) {\n if (y != parent[x]) {\n rec(y, i, i + size[y] - 1);\n i += size[y];\n }\n }\n }\n\n private void dfs(int x, int p) {\n parent[x] = p;\n size[x] = 1;\n for (int y : graph[x]) {\n if (y != p) {\n dfs(y, x);\n size[x] += size[y];\n }\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "354749984527108f3cde1bb73f7061e2", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "package codeforces.c197;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class ETry implements Runnable {\n\n private PrintWriter out = new PrintWriter(System.out, true);\n private Scanner scanner;\n\n int n;\n int[] size;\n int[] parent;\n PointWI[] points;\n int[] ans;\n \n Graph graph;\n\n @Override\n public void run() {\n n = scanner.nextInt();\n // \u0447\u0438\u0442\u0430\u0435\u043c \u0433\u0440\u0430\u0444\n graph = new Graph(n);\n \n for (int i = 0; i < n - 1; i++) {\n int x = scanner.nextInt() - 1;\n int y = scanner.nextInt() - 1;\n graph.addEdge(x, y);\n }\n \n // \u0447\u0438\u0442\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0438\n points = new PointWI[n];\n for (int i = 0; i < n; i++) {\n points[i] = new PointWI(scanner.nextLong(), scanner.nextLong(), i);\n }\n\n // \u043f\u043e\u0434\u0432\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0438 \n size = new int[n];\n parent = new int[n];\n dfs(0, -1);\n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\n ans = new int[n];\n Arrays.fill(ans, -1);\n \n // \u0438\u0449\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439\n List pointsList = Arrays.asList(points);\n \n PointWI min = Collections.min(pointsList, new MostLeftPointComparator());\n Collections.swap(pointsList, 0, min.i);\n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c\n rec(0, 0, n - 1);\n \n // \u043e\u0442\u0432\u0435\u0442\n for (int i = 0; i < n; i++) {\n out.print(ans[i] + 1);\n if (i == n - 1) {\n out.println();\n } else {\n out.print(\" \");\n }\n }\n }\n\n private void rec(int x, int left, int right) {\n ans[points[left].i] = x;\n Arrays.sort(points, left + 1, right + 1, new PointComparator(points[left]));\n int i = left + 1;\n for (int y : graph.adjacent(x)) {\n if (y != parent[x]) {\n rec(y, i, i + size[y] - 1);\n i += size[y];\n }\n }\n }\n\n private void dfs(int x, int p) {\n parent[x] = p;\n size[x] = 1;\n for (int y : graph.adjacent(x)) {\n if (y != p) {\n dfs(y, x);\n size[x] += size[y];\n }\n }\n }\n \n public ETry setInput(InputStream inputStream) {\n this.scanner = new Scanner(inputStream);\n return this;\n }\n\n public static void main(String[] args) {\n new ETry().setInput(System.in).run();\n }\n}\n\nclass Graph {\n private final int n;\n private final List> adj;\n \n public Graph(int n) {\n this.n = n;\n this.adj = new ArrayList>(n);\n createAdjList(n);\n }\n\n private void createAdjList(int n) {\n while (n > 0) {\n this.adj.add(new ArrayList());\n n--;\n }\n }\n \n public void addEdge(int v, int u) {\n adj.get(v).add(u);\n adj.get(u).add(v);\n }\n \n public Iterable adjacent(int v) {\n return adj.get(v);\n }\n\n public int getN() {\n return n;\n }\n}\n\n//solution\n\nclass PointWI {\n long x, y;\n int i;\n\n public PointWI(long x, long y, int i) {\n this.x = x;\n this.y = y;\n this.i = i;\n }\n\n @Override\n public String toString() {\n return String.format(\"[(%d %d) %d]\", x, y, i);\n }\n\n}\n\nclass MostLeftPointComparator implements Comparator {\n @Override\n public int compare(PointWI p1, PointWI p2) {\n int byx = compare(p1.x, p2.x);\n if (byx == 0) {\n return compare(p1.y, p2.y);\n }\n return byx;\n }\n \n public static int compare(long a, long b) {\n return a < b ? -1 : (a == b ? 0 : 1);\n }\n}\n\nclass PointComparator implements Comparator {\n PointWI root;\n\n public PointComparator(PointWI root) {\n this.root = root;\n }\n\n @Override\n public int compare(PointWI a, PointWI b) {\n long wp = (a.x - root.x) * (b.y - root.y) - (a.y - root.y) * (b.x - root.x);\n if (wp < 0)\n return -1;\n if (wp > 0)\n return 1;\n return 0;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1800180ce294ee4a8067147778254230", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class ETry implements Runnable {\n\n private PrintWriter out = new PrintWriter(System.out, true);\n private Scanner scanner;\n\n public ETry setInput(InputStream inputStream) {\n this.scanner = new Scanner(inputStream);\n return this;\n }\n\n public static void main(String[] args) {\n new E().setInput(System.in).run();\n }\n\n // solution\n\n class Point {\n long x, y;\n int i;\n\n public Point(long x, long y, int i) {\n this.x = x;\n this.y = y;\n this.i = i;\n }\n\n @Override\n public String toString() {\n return String.format(\"[(%d %d) %d]\", x, y, i);\n }\n\n }\n\n class PointComparator implements Comparator {\n Point root;\n\n public PointComparator(Point root) {\n this.root = root;\n }\n\n @Override\n public int compare(Point a, Point b) {\n long wp = (a.x - root.x) * (b.y - root.y) - (a.y - root.y) * (b.x - root.x);\n if (wp < 0)\n return -1;\n if (wp > 0)\n return 1;\n return 0;\n }\n\n }\n\n int n;\n List[] graph;\n int[] size;\n int[] parent;\n Point[] points;\n int[] ans;\n\n @Override\n public void run() {\n n = scanner.nextInt();\n // \u0447\u0438\u0442\u0430\u0435\u043c \u0433\u0440\u0430\u0444\n graph = new List[n];\n for (int i = 0; i < n; i++) {\n graph[i] = new ArrayList();\n }\n for (int i = 0; i < n - 1; i++) {\n int x = scanner.nextInt() - 1;\n int y = scanner.nextInt() - 1;\n graph[x].add(y);\n graph[y].add(x);\n }\n \n // \u0447\u0438\u0442\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0438\n points = new Point[n];\n for (int i = 0; i < n; i++) {\n points[i] = new Point(scanner.nextLong(), scanner.nextLong(), i);\n }\n\n // \u043f\u043e\u0434\u0432\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0438 \n size = new int[n];\n parent = new int[n];\n dfs(0, -1);\n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\n ans = new int[n];\n Arrays.fill(ans, -1);\n \n // \u0438\u0449\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439\n int rootIndex = 0;\n for (int i = 1; i < n; i++) {\n if (points[i].x < points[rootIndex].x || points[i].x == points[rootIndex].x\n && points[i].y < points[rootIndex].y) {\n rootIndex = i;\n }\n }\n \n // \u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u043c\n Point tmp = points[0];\n points[0] = points[rootIndex];\n points[rootIndex] = tmp;\n \n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c\n rec(0, 0, n - 1);\n \n // \u043e\u0442\u0432\u0435\u0442\n for (int i = 0; i < n; i++) {\n out.print(ans[i] + 1);\n if (i == n - 1) {\n out.println();\n } else {\n out.print(\" \");\n }\n }\n }\n\n private void rec(int x, int left, int right) {\n ans[points[left].i] = x;\n Arrays.sort(points, left + 1, right + 1, new PointComparator(points[left]));\n int i = left + 1;\n for (int y : graph[x]) {\n if (y != parent[x]) {\n rec(y, i, i + size[y] - 1);\n i += size[y];\n }\n }\n }\n\n private void dfs(int x, int p) {\n parent[x] = p;\n size[x] = 1;\n for (int y : graph[x]) {\n if (y != p) {\n dfs(y, x);\n size[x] += size[y];\n }\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3d31dcf206ad8b511d11d0a4a9076cb8", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class E {\n static long mod = 998244353;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextInt();\n long m = in.nextInt();\n long p = in.nextInt();\n long q = in.nextInt();\n long x = q - p + 1;\n if (p % 2 == 0) x = x - x / 2;\n else x /= 2;\n long y = q - p + 1 - x;\n if ((n & m) % 2 == 0) {\n long ans = fn(x, y, n * m, 0);\n System.out.println(ans);\n } else {\n long ans = bin(x + y, n * m);\n System.out.println(ans);\n }\n }\n\n private static long fn(long x, long y, long st, int type) {\n if (st == 1) {\n if (type == 0) return x;\n return y;\n }\n if (st % 2 == 1) {\n return (x * fn(x, y, st - 1, type) + y * fn(x, y, st - 1, (type + 1) % 2)) % mod;\n } else {\n long nch = fn(x, y, st / 2, 1);\n long ch = fn(x, y, st / 2, 0);\n if (type == 0) {\n return ((ch * ch) % mod + (nch * nch) % mod) % mod;\n } else {\n return (2 * ch * nch) % mod;\n }\n }\n }\n\n private static long bin(long x, long st) {\n if (st == 0) return 1;\n if (st == 1) return x;\n long m = st / 2;\n long ans = bin(x, m);\n if (st % 2 == 0) {\n return (ans * ans) % mod;\n } else {\n return (((ans * ans) % mod) * x) % mod;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db22080931ac8d66c294f978133525cc", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class E {\n static long mod = 998244353;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextInt();\n long m = in.nextInt();\n long p = in.nextInt();\n long q = in.nextInt();\n long x = q - p + 1;\n if (p % 2 == 0) x = x - x / 2;\n else x /= 2;\n long y = q - p + 1 - x;\n if ((n & m) % 2 == 0) {\n long ans = fn(x, y, n * m, 0);\n System.out.println(ans);\n } else {\n long ans = bin(x + y, n * m);\n System.out.println(ans);\n }\n }\n\n private static long fn(long x, long y, long st, int type) {\n if (st == 1) {\n if (type == 0) return x;\n return y;\n }\n if (st % 2 == 1) {\n return (x * fn(x, y, st - 1, type) + y * fn(x, y, st - 1, (type + 1) % 2)) % mod;\n } else {\n long nch = fn(x, y, st / 2, 1);\n long ch = fn(x, y, st / 2, 0);\n if (type == 0) {\n return (ch * ch + nch * nch) % mod;\n } else {\n return (2 * ch * nch) % mod;\n }\n }\n }\n\n private static long bin(long x, long st) {\n if (st == 0) return 1;\n if (st == 1) return x;\n long m = st / 2;\n long ans = bin(x, m);\n if (st % 2 == 0) {\n return (ans * ans) % mod;\n } else {\n return (((ans * ans) % mod) * x) % mod;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2cbce6461a09590f00b3580651f23310", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "package Div2_630;\n//564 558 305171115 960941497\n\nimport java.util.Scanner;\n\npublic class E {\n static long mod = 998244353;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextInt();\n long m = in.nextInt();\n long p = in.nextInt();\n long q = in.nextInt();\n long x = q - p + 1;\n if (p % 2 == 0) x = x - x / 2;\n else x /= 2;\n long y = q - p + 1 - x;\n if ((n & m) % 2 == 0) {\n long ans = fn(x, y, n * m, 0);\n System.out.println(ans);\n } else {\n long ans = bin(x + y, n * m);\n System.out.println(ans);\n }\n }\n\n static int N = 2000_000;\n static int dp[][] = new int[N][2];\n\n private static long fn(long x, long y, long st, int type) {\n if (st < N) {\n if (dp[(int) st][type] != 0) return dp[(int) st][type];\n }\n if (st == 1) {\n if (type == 0) return x;\n return y;\n }\n if (st % 2 == 1) {\n return (x * fn(x, y, st - 1, type) + y * fn(x, y, st - 1, (type + 1) % 2)) % mod;\n } else {\n long nch = fn(x, y, st / 2, 1);\n long ch = fn(x, y, st / 2, 0);\n long ans = 0;\n if (type == 0) {\n ans = (ch * ch + nch * nch) % mod;\n } else {\n ans = (2 * ch * nch) % mod;\n }\n if (st < N) {\n dp[(int) st][type] = (int) ans;\n }\n return ans;\n }\n }\n\n private static long bin(long x, long st) {\n if (st == 0) return 1;\n if (st == 1) return x;\n long m = st / 2;\n long ans = bin(x, m);\n if (st % 2 == 0) {\n return (ans * ans) % mod;\n } else {\n return (((ans * ans) % mod) * x) % mod;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f99bd456b57c413f036845b969a45865", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import org.omg.PortableServer.POA;\n\nimport java.awt.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class Abc {\n public static void main(String[] args) throws Exception {\n FastReader sc = new FastReader();\n StringBuilder sb=new StringBuilder();\n int t=sc.nextInt();\n while(t-->0) {\n int cheka=sc.nextInt(),chkb=sc.nextInt(),chkc=sc.nextInt(),d=sc.nextInt();\n int x=sc.nextInt(),y=sc.nextInt(),x1=sc.nextInt(),y1=sc.nextInt(),x2=sc.nextInt(),y2=sc.nextInt();\n int adadad=Math.abs(cheka-chkb);\n int dasdasds=Math.abs(chkc-d);\n boolean l=false,dd=false;\n if(cheka>chkb && x-(cheka-chkb)>=x1){\n l=true;\n }\n else if(chkb>cheka && x+(chkb-cheka)<=x2){\n l=true;\n }\n else if(cheka==chkb && (cheka==0 || x-1>=x1 || x+1<=x2))l=true;\n\n if(chkc>d && y-(chkc-d)>=y1){\n dd=true;\n }\n else if(d>chkc && y+(d-chkc)<=y2)dd=true;\n else if(d==chkc && (chkc==0 || y-1>=y1 || y+1<=y2))dd=true;\n\n if(l && dd) System.out.println(\"YES\");\n else System.out.println(\"NO\");\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 String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c7372f4ed1d242da903a020afc4ad2a5", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0} {"lang": "Java 8", "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;i0) {\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<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=0) {\r\n\t\t\tif (ptr[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]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<=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=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=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= 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c39d3ee7b43b41685dba10b55780a2c", "src_uid": "4dc5dc78bda59c1ec6dd8acd6f1d7333", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CF_Edu_108_F {\n\tstatic boolean verb=true;\n\tstatic void log(Object X){if (verb) System.err.println(X);}\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X,int L){if (verb) {for (int i=0;i0) {\n\t\t\tif ((w&1)!=0) {\n\t\t\t\ts+=(it+1)+\" \";\n\t\t\t}\n\t\t\tw>>=1;\n\t\t\tit++;\n\t\t}\n\t\treturn s+\"]\";\n\t}\n\t\n\tstatic\tint FX=Integer.MAX_VALUE;\n\tstatic int solveAlt(int[] a,int[] b,int[][] c) {\n\t\tint n=a.length;\n\t\tint m=b.length;\n\t\tint MX=1<bob)\n\t\t\treturn -1;\n\n\n\t\tint[][] cost=new int[n][MX];\n\t\tint[] bill=new int[MX];\n\n\t\tfor (int w=0;w=0) {\n\t\t\tif (ptr[st]0)\n\t\t\t\t\tspend=curspend[st-1];\n\t\t\t\t//log(\"trying :\"+name(w)+\" at pos:\"+st);\n\t\t\t\t//log((bill[w]-a[st])+\" \"+(spend+cost[st][w])+\" vs \"+best);\n\t\t\t\tif (bill[w]>=a[st] && spend+cost[st][w]bill[msk]) {\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\n\t\t\t\t\t}\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\tspend+=cost[st][w];\n\t\t\t\t\t\tcurspend[st]=spend;\n\t\t\t\t\t\tif (st==n-1) {\n\t\t\t\t\t\t\t//log(\"this is ok\");\n\t\t\t\t\t\t\tstack[st]=w;\n\t\t\t\t\t\t\t//for (int x:stack) {\n\t\t\t\t\t\t\t//\tlog(name(x));\n\t\t\t\t\t\t\t//}\n\t\t\t\t\t\t\tbest=spend;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstack[st++]=w;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tptr[st]=1;\n\t\t\t\tst--;\n\t\t\t}\n\t\t}\n\n\n\t\tif (best==FX)\n\t\t\tbest=-1;\n\t\treturn best;\n\n\n\n\t}\n\tstatic int solveKO(int[] a,int[] b,int[][] c) {\n\t\tint n=a.length;\n\t\tint m=b.length;\n\t\tint MX=1<=a[0]) {\n\t\t\t\t// ok for me\n\t\t\t\t// now we look at the previous\n\t\t\t\tspend[w][bill[w]-a[0]]=cost[0][w];\n\t\t\t\t//log(\"adding:\"+w);\n\t\t\t}\n\t\t}\n\n\n\n\t\t// this is taking some shortcut...\n\n\t\tfor (int i=1;i=a[i]) {\n\t\t\t\t\t//log(\"considering:\"+w);\n\t\t\t\t\t// ok for me\n\t\t\t\t\t// now we look at the previous\n\t\t\t\t\tfor (int u=0;u=0) {\n\t\t\t\t\t\t\t\t\t//log(\"----merging\");\n\t\t\t\t\t\t\t\t\tnxt[nu][nv]=Math.min(spend[u][v]+cost[i][w], nxt[nu][nv]);\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}\n\n\t\t\t}\n\t\t\tspend=nxt;\n\t\t}\n\t\tint ans=FX;\n\t\tfor (int w=0;w= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\n\t\tpublic final String readString() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res=new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.append((char)c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic final int readInt() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\t\tpublic final long readLong() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\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\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0423d4c49df311e516ad590508c9c261", "src_uid": "4dc5dc78bda59c1ec6dd8acd6f1d7333", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CF_Edu_108_F {\n\tstatic boolean verb=true;\n\tstatic void log(Object X){if (verb) System.err.println(X);}\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X,int L){if (verb) {for (int i=0;i0) {\n\t\t\tif ((w&1)!=0) {\n\t\t\t\ts+=(it+1)+\" \";\n\t\t\t}\n\t\t\tw>>=1;\n\t\t\tit++;\n\t\t}\n\t\treturn s+\"]\";\n\t}\n\t\n\tstatic\tint FX=Integer.MAX_VALUE;\n\tstatic int solveAlt(int[] a,int[] b,int[][] c) {\n\t\tint n=a.length;\n\t\tint m=b.length;\n\t\tint MX=1<bob)\n\t\t\treturn -1;\n\n\n\t\tint[][] cost=new int[n][MX];\n\t\tint[] bill=new int[MX];\n\n\t\tfor (int w=0;w=0) {\n\t\t\tif (ptr[st]0)\n\t\t\t\t\tspend=curspend[st-1];\n\t\t\t\tif (bill[w]>=a[st] && spend+cost[st][w]bill[msk]) \n\t\t\t\t\t\t\tok=false;\n\t\t\t\t\t}\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\tspend+=cost[st][w];\n\t\t\t\t\t\tcurspend[st]=spend;\n\t\t\t\t\t\tif (st==n-1) {\n\t\t\t\t\t\t\tbest=spend;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstack[st++]=w;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tptr[st]=1;\n\t\t\t\tst--;\n\t\t\t}\n\t\t}\n\n\n\t\tif (best==FX)\n\t\t\tbest=-1;\n\t\treturn best;\n\n\n\n\t}\n\t\n\tstatic int bst;\n\t\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\treader=new InputReader(System.in);\n\t\tint n=reader.readInt();\n\t\tint m=reader.readInt();\n\t\tint[] a=new int[n];\n\t\tint tot=0;\n\t\tfor (int i=0;i= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\n\t\tpublic final String readString() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res=new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.append((char)c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic final int readInt() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\t\tpublic final long readLong() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\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\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "190354ba29093702d50ba6f42e17435f", "src_uid": "4dc5dc78bda59c1ec6dd8acd6f1d7333", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CF_Edu_108_F {\n\tstatic boolean verb=true;\n\tstatic void log(Object X){if (verb) System.err.println(X);}\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X,int L){if (verb) {for (int i=0;i=a[0]) {\n\t\t\t\t// ok for me\n\t\t\t\t// now we look at the previous\n\t\t\t\tspend[w][bill[w]-a[0]]=cost[0][w];\n\t\t\t\t//log(\"adding:\"+w);\n\t\t\t}\n\t\t}\n\n\n\t\tfor (int i=1;i=a[i]) {\n\t\t\t\t\t//log(\"considering:\"+w);\n\t\t\t\t\t// ok for me\n\t\t\t\t\t// now we look at the previous\n\t\t\t\t\tfor (int u=0;u=0) {\n\t\t\t\t\t\t\t\t\t//log(\"----merging\");\n\t\t\t\t\t\t\t\t\tnxt[nu][nv]=Math.min(spend[u][v]+cost[i][w], nxt[nu][nv]);\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}\n\n\t\t\t}\n\t\t\tspend=nxt;\n\t\t}\n\t\tint ans=FX;\n\t\tfor (int w=0;w= numChars) {\n\t\t\tcurChar = 0;\n\t\t\tnumChars = stream.read(buf);\n\t\t\tif (numChars <= 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\n\tpublic final String readString() throws IOException {\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.append((char)c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tpublic final int readInt() throws IOException {\n\t\tint c = read();\n\t\tboolean neg=false;\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tchar d=(char)c;\n\t\t//log(\"d:\"+d);\n\t\tif (d=='-') {\n\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\tif (neg)\n\t\t\treturn -res;\n\t\treturn res;\n\n\t}\n\n\tpublic final long readLong() throws IOException {\n\t\tint c = read();\n\t\tboolean neg=false;\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tchar d=(char)c;\n\t\t//log(\"d:\"+d);\n\t\tif (d=='-') {\n\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\tif (neg)\n\t\t\treturn -res;\n\t\treturn res;\n\n\t}\n\n\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e44b243f39ffcc5c432bb65d87f7ce0", "src_uid": "4dc5dc78bda59c1ec6dd8acd6f1d7333", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\nimport java.math.RoundingMode;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.StringTokenizer;\n\n\n/**\n * @authod Rashedul Hasan Rijul\n */\npublic class Solution {\n\n int n;\n int mass[];\n int dp[][];\n int cnt[] = new int[102];\n\n List masses = new ArrayList<>();\n List cnts = new ArrayList<>();\n\n public Solution() {\n\n }\n\n public Solution(int n) {\n this.n = n;\n mass = new int[n];\n dp = new int[(n * 100) + 1][101];\n\n for (int i = 0; i <= 100; i++) {\n cnt[i] = 0;\n }\n\n for (int i = 0; i <= (n * 100); i++) {\n for (int j = 0; j <= n; j++) {\n\n dp[i][j] = 0;\n\n }\n }\n }\n\n public static void main(String args[]) throws FileNotFoundException {\n\n // for testing in local\n // FastReader fastReader = FastReader.getFileReader(\"in.txt\");\n\n FastReader fastReader = FastReader.getDefaultReader();\n\n int n = fastReader.nextInt();\n\n Solution soln = new Solution(n);\n\n for (int i = 0; i < n; i++) {\n\n soln.mass[i] = fastReader.nextInt();\n soln.cnt[soln.mass[i]]++;\n }\n\n for (int i = 1; i <= 100; i++) {\n if (soln.cnt[i] > 0) {\n soln.masses.add(i);\n soln.cnts.add(soln.cnt[i]);\n }\n }\n\n soln.getAnswer();\n\n\n }\n\n public long cal() {\n\n int tot = 0;\n for (int i = 0; i < n; i++) {\n tot += mass[i];\n }\n\n dp[0][0] = 1;\n\n for (int i = 0; i < masses.size(); i++) {\n int coin = masses.get(i);\n for (int k = n; k >= 1; k--) {\n for (int j = cnt[coin]; j >= 1; j--) {\n if(j>k){\n continue;\n }\n int value = coin * j;\n for (int l = tot; l >= value; l--) {\n\n dp[l][k] += dp[l - value][k - j];\n }\n }\n }\n }\n\n return 0;\n }\n\n\n public void getAnswer() {\n\n cal();\n\n int answer = 0;\n int resultCoin = -1;\n\n for (int i = 0; i < 100; i++) {\n for (int j = cnt[i]; j > 0; j--) {\n if (j <= answer) {\n break;\n }\n int value = i * j;\n\n if (dp[value][j] == 1) {\n if (answer < j) {\n answer = j;\n resultCoin = i;\n }\n\n\n }\n }\n }\n\n int remCoin = 0;\n int otherCoin = 0;\n for (int i = 0; i < masses.size(); i++) {\n if (masses.get(i).equals(resultCoin)) {\n continue;\n }\n otherCoin++;\n }\n\n if (cnt[resultCoin] == answer && otherCoin == 1) {\n answer = n;\n }\n\n System.out.println(answer);\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 static FastReader getFileReader(String fileName) throws FileNotFoundException {\n return new FastReader(new InputStreamReader(new FileInputStream(new File(fileName))));\n }\n\n public static FastReader getDefaultReader() throws FileNotFoundException {\n return new FastReader();\n }\n\n public FastReader(InputStreamReader inputStreamReader) {\n br = new BufferedReader(inputStreamReader);\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1db30395a9128da65cae68b173b53585", "src_uid": "ccc4b27889598266e8efe73b8aa3666c", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Wolfgang Beyer\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] w = in.read1BasedIntArray(n);\n int sum = 0;\n Set wTypes = new HashSet<>();\n for (int i = 1; i <= n; i++) {\n sum += w[i];\n wTypes.add(w[i]);\n }\n if (wTypes.size() < 3) {\n out.println(n);\n return;\n }\n Arrays.sort(w);\n\n int[][] dp = new int[n + 1][sum + 1];\n int sames = 0;\n for (int i = 1; i <= n; i++) {\n sames++;\n if (i < n && w[i + 1] == w[i]) {\n continue;\n }\n\n for (int j = i - 1; j > 0; j--) {\n for (int k = 1; k <= sum; k++) {\n if (dp[j][k] > 0) {\n for (int m = 1; m <= sames; m++) {\n dp[j + m][k + m * w[i]] = Math.min(2, dp[j + m][k + m * w[i]] + dp[j][k]);\n }\n }\n }\n }\n\n for (int j = 1; j <= sames; j++) {\n dp[j][w[i] * j] = Math.min(2, dp[j][w[i] * j] + 1);\n }\n sames = 0;\n }\n\n int result = 0;\n sames = 0;\n for (int i = 1; i <= n; i++) {\n if (i > 1 && w[i] != w[i - 1]) {\n sames = 0;\n }\n sames++;\n if (dp[sames][w[i] * sames] == 1) {\n result = Math.max(result, sames);\n }\n }\n out.println(result);\n }\n\n }\n\n static class InputReader {\n private static BufferedReader in;\n private static StringTokenizer tok;\n\n public InputReader(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public int[] read1BasedIntArray(int n) {\n int[] ar = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n ar[i] = nextInt();\n }\n return ar;\n }\n\n public String next() {\n try {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n //tok = new StringTokenizer(in.readLine(), \", \\t\\n\\r\\f\"); //adds commas as delimeter\n }\n } catch (IOException ex) {\n System.err.println(\"An IOException was caught :\" + ex.getMessage());\n }\n return tok.nextToken();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d644c87e0f5a94c511a19575dec5652c", "src_uid": "ccc4b27889598266e8efe73b8aa3666c", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.util.Arrays;\n\npublic class B {\n\n\tstatic int N;\n\tstatic int ar[];\n\tstatic int dp[][][][];\n\tpublic static void main(String[] args) {\n\t\tJS in = new JS();\n\t\tN = in.nextInt();\n\t\tar = new int[N];\n\t\tint cnt[] = new int[101];\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tar[i] = in.nextInt();\n\t\t\tcnt[ar[i]]++;\n\t\t}\n\t\tArrays.sort(ar);\n\t\t\n\t\tdp = new int[101][101][101][101];\n\t\tfor(int a[][][] : dp)\n\t\t\tfor(int b[][] : a)\n\t\t\t\tfor(int c[] : b)\n\t\t\t\t\tArrays.fill(c, -1);\n\t\tint res = 0;\n\t\tfor(int i = 0; i <= 100; i++) {\n\t\t\tfor(int take = 1; take <= cnt[i]; take++) {\n\t\t\t\tint curSum = i*take;\n\t\t\t\t\n\t\t\t\tint val = go(0,curSum,take,i);\n\t\t\t\tif(val == 0) res = Math.max(res, take);\n\t\t\t}\t\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\t\n\tstatic int go(int id, int sum, int left, int num) {\n\t\tif(sum < 0) return 0;\n\t\tif(left == 0) {\n\t\t\tif(sum == 0) return 1;\n\t\t\treturn 0;\n\t\t}\n\t\tif(id >= N) return 0;\n\t\tif(dp[id][sum][left][num] != -1) return dp[id][sum][left][num];\n\t\t\n\t\tint res = go(id+1,sum,left,num);\n\t\tif(ar[id] != num) {\n\t\t\tres = Math.max(res, go(id+1,sum-ar[id],left-1,num));\n\t\t}\n\t\treturn dp[id][sum][left][num] = res;\n\t}\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ee93986276e427468e11b5109872940d", "src_uid": "ccc4b27889598266e8efe73b8aa3666c", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\t@SuppressWarnings(\"resource\")\n\tpublic static void main(String[] args) {\n\t\tInputStream input;\n\t\tOutputStream output;\n\t\ttry {\n\t\t\tinput = new FileInputStream(\"input.txt\");\n\t\t\toutput = new FileOutputStream(\"output.txt\");\n\t\t} catch (FileNotFoundException e) {\n\t\t\tinput = System.in;\n\t\t\toutput = System.out;\n\t\t}\n\t\tKattio io = new Kattio(input, output);\n\t\t(new Solve(io)).main();\n\t\tio.close();\n\n\t\tif (input instanceof FileInputStream)\n\t\t\ttry {\n\t\t\t\tinput.close();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t\tif (output instanceof FileOutputStream)\n\t\t\ttry {\n\t\t\t\toutput.close();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t}\n\n}\n\nclass Solve {\n\tstatic final long mod = (long) 1e9+7;\n\tKattio io;\n\tint n;\n\tint[] a;\n\tlong[][][] dp;\n\tint maxx;\n\t\n\tlong[] fac;\n\t\n\tSolve(Kattio io) {\n\t\tthis.io = io;\n\t}\n\t\n\tlong pow(long x,long y)\n\t{\n\t\tif (y==0) return 1;\n\t\telse\n\t\t{\n\t\t\tlong p=pow(x,y/2);\n\t\t\tp=p*p%mod;\n\t\t\tif (y%2==1) return p*x%mod;\n\t\t\telse return p;\n\t\t}\n\t}\n\t\n\tlong nCk(int n,int k)\n\t{\n\t\treturn fac[n]*pow(fac[k]*fac[n-k]%mod,mod-2)%mod;\n\t}\n\n\tlong caldp(int x,int y,int z)\n\t{\n//\t\tif (dp[x][y][z]!=-1) return dp[x][y][z];\n//\t\t\n//\t\tif (x==n && z==0 && y==0)\n//\t\t\tdp[x][y][z]=1;\n//\t\telse\n//\t\tif (x==n)\n//\t\t\tdp[x][y][z]=0;\n//\t\telse\n//\t\t{\n//\t\t\tdp[x][y][z]=caldp(x+1,y,z);\n//\t\t\tif (z>=a[x+1] && y>=1) dp[x][y][z]=(dp[x][y][z]+caldp(x+1,y-1,z-a[x+1]))%mod;\n//\t\t}\n//\t\t\n//\t\treturn dp[x][y][z];\n\t\t\n\t\ttry\n\t\t{\n\t\t\tdp = new long[2][n+1][z+1];\n\t\t\t\n\t\t\tfor (int i=n; i>=0; i--)\n\t\t\t\tfor (int j=y; j>=0; j--)\n\t\t\t\t\tfor (int k=z; k>=0; k--)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (i==n && j==0 & k==0)\n\t\t\t\t\t\t\tdp[i%2][j][k]=1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\tif (i==n)\n\t\t\t\t\t\t\tdp[i%2][j][k]=0;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdp[i%2][j][k]=dp[(i+1)%2][j][k];\n\t\t\t\t\t\t\tif (j>=1 && k>=a[i+1]) dp[i%2][j][k]=(dp[i%2][j][k]+dp[(i+1)%2][j-1][k-a[i+1]])%mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t}\n\t\tcatch (ArrayIndexOutOfBoundsException e)\n\t\t{\n\t\t\tio.println(x+\" \"+y+\" \"+z);\n\t\t}\n\t\t\n\t\treturn dp[x][y][z];\n\t}\n\t\n\tvoid main() \n\t{\n\t\tn=io.getInt();\n\t\ta = new int[n+1];\n\t\t\n\t\tmaxx = 0;\n\t\tTreeMap S = new TreeMap();\n\t\t\n\t\tfor (int i=1; i<=n; i++)\n\t\t{\n\t\t\ta[i]=io.getInt();\n\t\t\tmaxx+=a[i];\n\t\t\tif (S.containsKey(a[i]))\n\t\t\t\tS.put(a[i], S.get(a[i])+1);\n\t\t\telse\n\t\t\t\tS.put(a[i], 1);\n\t\t}\n\t\t\n\t\tif (S.size()==2)\n\t\t{\n\t\t\tio.print(n);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tdp = new long[n+1][n+1][maxx+1];\n\t\tfor (int i=0; i<=n; i++)\n\t\t\tfor (int j=0; j<=n; j++)\n\t\t\t\tArrays.fill(dp[i][j],-1);\n\t\t\n\t\tfac = new long[n+1];\n\t\tfac[0]= 1;\n\t\tfor (int i=1; i<=n; i++)\n\t\t\tfac[i] = fac[i-1]*i%mod;\n\t\t\n\t\t\n\t\t\n\t\tint res=0;\n\t\tfor (Map.Entry entry: S.entrySet())\n\t\t{\n\t\t\tInteger value = entry.getValue();\n\t\t\tInteger key = entry.getKey();\n\t\t\tfor (int i=res+1; i<=value; i++)\n\t\t\t\tif (caldp(0,i,key*i)==nCk(value,i))\n\t\t\t\t\tres=Math.max(res, i);\n\t\t}\n\t\t\n\t\tio.println(res);\n\t\t\t\n\t}\n}\n\n/** Simple yet moderately fast I/O routines.\n*\n* Example usage:\n*\n* Kattio io = new Kattio(System.in, System.out);\n*\n* while (io.hasMoreTokens()) {\n* int n = io.getInt();\n* double d = io.getDouble();\n* double ans = d*n;\n*\n* io.println(\"Answer: \" + ans);\n* }\n*\n* io.close();\n*\n*\n* Some notes:\n*\n* - When done, you should always do io.close() or io.flush() on the\n* Kattio-instance, otherwise, you may lose output.\n*\n* - The getInt(), getDouble(), and getLong() methods will throw an\n* exception if there is no more data in the input, so it is generally\n* a good idea to use hasMoreTokens() to check for end-of-file.\n*\n* @author: Kattis\n*/\nclass Kattio extends PrintWriter {\n\tpublic Kattio(InputStream i) {\n\t\tsuper(new BufferedOutputStream(System.out));\n\t\tr = new BufferedReader(new InputStreamReader(i));\n\t}\n\n\tpublic Kattio(InputStream i, OutputStream o) {\n\t\tsuper(new BufferedOutputStream(o));\n\t\tr = new BufferedReader(new InputStreamReader(i));\n\t}\n\n\tpublic boolean hasMoreTokens() {\n\t\treturn peekToken() != null;\n\t}\n\n\tpublic int getInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic double getDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic long getLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic String getWord() {\n\t\treturn nextToken();\n\t}\n\n\tprivate BufferedReader r;\n\tprivate String line;\n\tprivate StringTokenizer st;\n\tprivate String token;\n\n\tprivate String peekToken() {\n\t\tif (token == null)\n\t\t\ttry {\n\t\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\t\tline = r.readLine();\n\t\t\t\t\tif (line == null)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tst = new StringTokenizer(line);\n\t\t\t\t}\n\t\t\t\ttoken = st.nextToken();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t\treturn token;\n\t}\n\n\tprivate String nextToken() {\n\t\tString ans = peekToken();\n\t\ttoken = null;\n\t\treturn ans;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0ea08efd94bc63fdc4fc78a6664750ca", "src_uid": "ccc4b27889598266e8efe73b8aa3666c", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class B {\n\n static int[] memo;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt(); int m = sc.nextInt();\n // the question essentially asks how many answers we can find\n // for i^2 + j^2 divisible by m\n// memo = new int[m]; // array of count of residues\n// for (int i = 0; i < m; i++) {\n// memo[(i * i) % m]++;\n// }\n long total = 0; // we can store n^2 in long\n // n splits into n/m *m + n%m\n long bigSqTotal = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < m; j++) {\n bigSqTotal += ((i*i + j*j) % m == 0) ? 1 : 0;\n }\n }\n bigSqTotal *= (n/m);\n bigSqTotal *= (n/m); // big box\n total += bigSqTotal;\n\n long bigRectangleTotal = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 1; j <= n%m; j++) {\n bigRectangleTotal += ((i*i + j*j) % m == 0) ? 1 : 0;\n }\n }\n\n bigRectangleTotal *= (n/m);\n bigRectangleTotal *= 2;\n total += bigRectangleTotal;\n\n long smallSquareTotal = 0;\n for (int i = 1; i <= n%m; i++) {\n for (int j = 1; j <= n%m; j++) {\n smallSquareTotal += ((i*i + j*j) % m == 0) ? 1 : 0;\n }\n }\n\n total += smallSquareTotal;\n System.out.println(total);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70c3f8835d689d6a267bb6869f02a15d", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package com.company;\n\nimport java.util.Scanner;\n\npublic class Lab8 {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long n = scanner.nextLong();\n long m = scanner.nextLong();\n long amountOfPairs = 0;\n for (long x = 0; x < m; x++) {\n for (long y = 0; y < m; y++) {\n if ((x * x + y * y) % m == 0) {\n long amountOfX = x > 0 ? ((n - x) / m + 1) : ((n - x) / m);\n long amountOfY = y > 0 ? ((n - y) / m + 1) : ((n - y) / m);\n amountOfPairs += amountOfX * amountOfY;\n }\n }\n }\n System.out.print(amountOfPairs);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c0bad7ae835a459664d8031362a370c9", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class nn {\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 = 0;\n for(int i = 1;i <= m;i++){\n for(int j = 1;j <= m;j++){\n long v = (i*i+j*j)%m;\n if(v == 0 ){\n ans++;\n }\n }\n }\n System.out.println(ans);\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "679ca933da3ddbaf79fa0e535b3cb635", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import jdk.internal.util.xml.impl.Input;\n\nimport java.util.*;\nimport java.io.*;\n\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 int n = in.nextInt();\n int m = in.nextInt();\n long ans=0;\n for (int i =1;i<=Math.min(n,m);i++)\n for (int j =1;j<=Math.min(n,m);j++)\n {\n if ((i*i+j*j)%m==0)\n {\n ans+=(long)((long)((n-i)/m+1)*((long)(n-j)/m+1));\n }\n }\n\n out.printLine(ans);\n out.flush();\n\n\n }\n static int binarySearch(int []arr,int n,int p)\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-1;\n\n }\n temp = st;\n\n\n }\n\n return temp;\n }\n static void MergeSort(int[] a, int[] b, int p, int r)\n {\n if (p < r)\n {\n int q = (r + p) / 2;\n MergeSort(a, b, p, q);\n MergeSort(a, b, q + 1, r);\n Merge(a, b, p, q, r);\n }\n }\n static void Merge(int[] a, int[] b,int p, int q, int r)\n {\n int n1 = q - p + 1;\n int n2 = r - q;\n int[] R = new int[n1 + 1];\n int[] L = new int[n2 + 1];\n int[] R1 = new int[n1];\n int[] L1 = new int[n2];\n\n for (int i = 0; i < n1; i++)\n {\n R[i] = a[p + i];\n R1[i] = b[p + i];\n\n }\n R[n1] = Integer.MAX_VALUE;\n for (int i = 0; i < n2; i++)\n {\n L[i] = a[q + i + 1];\n L1[i] = b[q + i + 1];\n\n }\n L[n2] =Integer.MAX_VALUE;\n int n = a.length;\n int j = 0;\n int k = 0;\n for (int i = p; i <= r; i++)\n {\n if (L[j] < R[k])\n {\n a[i] = L[j];\n b[i] = L1[j];\n\n j++;\n }\n else if (L[j]>R[k])\n {\n a[i] = R[k];\n b[i] = R1[k];\n\n k++;\n }\n else\n {\n if (L1[j] < R1[k])\n {\n a[i] = L[j];\n b[i] = L1[j];\n\n j++;\n }\n else\n {\n a[i] = R[k];\n b[i] = R1[k];\n\n k++;\n }\n }\n\n }\n }\n}\n\n\n\nclass pair implements Comparable\n{\n\n int key;\n int value;\n public pair(Object key, Object value) {\n\n this.key = (int)key;\n this.value=(int)value;\n }\n\n @Override\n public int compareTo(Object o) {\n pair temp =(pair)o;\n return key-temp.key;\n }\n}\nclass Graph {\n\n\n int n;\n ArrayList[] adjList;\n\n public Graph(int n) {\n this.n = n;\n adjList = new ArrayList[n];\n for (int i = 0; i < n; i++)\n adjList[i] = new ArrayList<>();\n }\n\n}\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\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d937621cd83306266e2db24445329c2", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.List;\n\npublic class C {\n private static StringTokenizer st;\n private static BufferedReader br;\n public static long MOD = 1000000007;\n\n public static void print(Object x) {\n System.out.println(x + \"\");\n }\n public static void printArr(long[] x) {\n StringBuilder s = new StringBuilder();\n for (int i = 0; i < x.length; i++) {\n s.append(x[i] + \" \");\n }\n print(s);\n }\n public static String join(List x, String space) {\n StringBuilder sb = new StringBuilder();\n for (Object elt : x) {\n sb.append(elt);\n sb.append(space);\n }\n return sb.toString();\n }\n\n public static String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String line = br.readLine();\n st = new StringTokenizer(line.trim());\n }\n return st.nextToken();\n }\n public static int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n public static long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n public static List nextInts(int N) throws IOException {\n List ret = new ArrayList();\n for (int i = 0; i < N; i++) {\n ret.add(nextInt() - 1);\n }\n return ret;\n }\n\n public static double atMost(int[] l, int[] r, int i, int c) {\n if (i >= r[c]) return 1;\n if (i < l[c]) return 0;\n return (i-l[c]+1) / ((double) (r[c]-l[c]+1));\n }\n\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n\n int MAX = 12;\n int n = nextInt();\n int[] l = new int[n];\n int[] r = new int[n];\n for (int i = 0; i < n; i++) {\n l[i] = nextInt();\n r[i] = nextInt();\n }\n\n double[] atMost = new double[MAX+1];\n for (int i = 0; i <= MAX; i++) {\n double prob = 1;\n for (int c = 0; c < n; c++) {\n prob *= atMost(l, r, i, c);\n }\n atMost[i] = prob;\n for (int c = 0; c < n; c++) {\n double moreProb = 1;\n for (int c2 = 0; c2 < n; c2++) {\n if (c == c2) continue;\n moreProb *= atMost(l, r, i, c2);\n }\n moreProb *= 1 - atMost(l, r, i, c);\n atMost[i] += moreProb;\n }\n }\n\n double expected = 0;\n for (int i = 1; i <= MAX; i++) {\n expected += i * (atMost[i] - atMost[i-1]);\n }\n System.out.printf(\"%.15f%n\", expected);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "46239b079b897bca3c570b6afbcaae45", "src_uid": "5258ce738eb268b9750cfef309d265ef", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n static int n;\n static long[] l;\n static long[] r;\n static double numerator = 0;\n static int second;\n static int[] mask;\n static boolean[] visited = new boolean[10];\n\n static long count(long l1, long r1, long l2, long r2) {\n l1 = Math.max(l1, l2);\n r1 = Math.min(r1, r2);\n return l1 <= r1 ? (r1 - l1 + 1) : 0;\n }\n\n static void dfs(int t, int greater, int equal) {\n if (greater > 1)\n return;\n if (t >= n) {\n if (equal == 0)\n return;\n if (greater == 0 && equal == 1)\n return;\n\n long cnt = 1;\n for (int i = 0; i < n; i++) {\n if (mask[i] > 0) {\n cnt *= count(l[i], r[i], second + 1, Integer.MAX_VALUE);\n } else if (mask[i] == 0) {\n cnt *= count(l[i], r[i], second, second);\n } else {\n cnt *= count(l[i], r[i], 0, second - 1);\n }\n }\n numerator += second * cnt;\n // if (cnt > 0)\n // System.out.println(second + \" \" + Arrays.toString(mask) + \" \" + cnt);\n } else {\n mask[t] = 1;\n dfs(t + 1, greater + 1, equal);\n\n mask[t] = 0;\n dfs(t + 1, greater, equal + 1);\n\n mask[t] = -1;\n dfs(t + 1, greater, equal);\n }\n }\n\n public static void main(String[] args) throws Exception {\n Reader.init(System.in);\n BufferedWriter cout = new BufferedWriter(new OutputStreamWriter(System.out));\n\n n = Reader.nextInt();\n l = new long[n];\n r = new long[n];\n long total = 1;\n for (int i = 0; i < n; i++) {\n l[i] = Reader.nextInt();\n r[i] = Reader.nextInt();\n total *= (r[i] - l[i] + 1);\n }\n\n mask = new int[n];\n for (second = 1; second <= 10000; second++) {\n dfs(0, 0, 0);\n }\n\n System.out.printf(\"%.10f%n\", numerator / total);\n cout.close();\n }\n\n static class Pair, V extends Comparable> implements Comparable> {\n final U _1;\n final V _2;\n\n private Pair(U key, V val) {\n this._1 = key;\n this._2 = val;\n }\n\n public static , V extends Comparable> Pair instanceOf(U _1, V _2) {\n return new Pair(_1, _2);\n }\n\n @Override\n public String toString() {\n return _1 + \" \" + _2;\n }\n\n @Override\n public int hashCode() {\n int res = 17;\n res = res * 31 + _1.hashCode();\n res = res * 31 + _2.hashCode();\n return res;\n }\n\n @Override\n public int compareTo(Pair that) {\n int res = this._1.compareTo(that._1);\n if (res < 0 || res > 0)\n return res;\n else\n return this._2.compareTo(that._2);\n }\n\n @Override\n public boolean equals(Object obj) {\n if (this == obj)\n return true;\n if (!(obj instanceof Pair))\n return false;\n Pair that = (Pair) obj;\n return _1.equals(that._1) && _2.equals(that._2);\n }\n }\n\n /** Class for buffered reading int and double values */\n static class 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(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(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n\n static class ArrayUtil {\n static void swap(int[] a, int i, int j) {\n int tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n\n static void swap(long[] a, int i, int j) {\n long tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n\n static void swap(double[] a, int i, int j) {\n double tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n\n static void swap(char[] a, int i, int j) {\n char tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n\n static void swap(boolean[] a, int i, int j) {\n boolean tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n\n static void reverse(int[] a, int i, int j) {\n for (; i < j; i++, j--)\n swap(a, i, j);\n }\n\n static void reverse(long[] a, int i, int j) {\n for (; i < j; i++, j--)\n swap(a, i, j);\n }\n\n static void reverse(double[] a, int i, int j) {\n for (; i < j; i++, j--)\n swap(a, i, j);\n }\n\n static void reverse(char[] a, int i, int j) {\n for (; i < j; i++, j--)\n swap(a, i, j);\n }\n\n static void reverse(boolean[] a, int i, int j) {\n for (; i < j; i++, j--)\n swap(a, i, j);\n }\n\n static long sum(int[] a) {\n int sum = 0;\n for (int i : a)\n sum += i;\n return sum;\n }\n\n static long sum(long[] a) {\n long sum = 0;\n for (long i : a)\n sum += i;\n return sum;\n }\n\n static double sum(double[] a) {\n double sum = 0;\n for (double i : a)\n sum += i;\n return sum;\n }\n\n static int max(int[] a) {\n int max = Integer.MIN_VALUE;\n for (int i : a)\n if (i > max)\n max = i;\n return max;\n }\n\n static int min(int[] a) {\n int min = Integer.MAX_VALUE;\n for (int i : a)\n if (i < min)\n min = i;\n return min;\n }\n\n static long max(long[] a) {\n long max = Long.MIN_VALUE;\n for (long i : a)\n if (i > max)\n max = i;\n return max;\n }\n\n static long min(long[] a) {\n long min = Long.MAX_VALUE;\n for (long i : a)\n if (i < min)\n min = i;\n return min;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c981caaef45bb90f770d308d07502fef", "src_uid": "5258ce738eb268b9750cfef309d265ef", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n/**\n * Created by aonuchin on 07.02.15.\n */\npublic class A {\n static class Range {\n int fromInc;\n int toInc;\n\n public Range(int fromInc, int toInc) {\n this.fromInc = fromInc;\n this.toInc = toInc;\n }\n\n Integer fromInc() {\n return fromInc;\n }\n\n boolean in(int number) {\n return fromInc <= number && number <= toInc;\n }\n }\n public static void main(String ... a) {\n Scanner input = new Scanner(System.in);\n int companies = input.nextInt();\n List ranges = new ArrayList<>();\n for (int i = 0; i < companies; i++) {\n ranges.add(new Range(input.nextInt(), input.nextInt()));\n }\n Collections.sort(ranges, Comparator.comparing(Range::fromInc));\n double expected = 0;\n int currentPrice = ranges.get(0).fromInc;\n for (Range range : ranges) {\n for (; currentPrice <= range.toInc; currentPrice++) {\n if (currentPrice < range.fromInc) {\n currentPrice = range.fromInc;\n }\n double probability = calculateProbability(currentPrice, ranges);\n assert probability <= 1.0;\n expected += probability * currentPrice;\n }\n }\n System.out.println(expected);\n }\n\n private static double calculateProbability(int currentPrice, List ranges) {\n double probability = 0;\n for (int firstPlace = 0 ; firstPlace < ranges.size(); firstPlace++) {\n for (int secondPlace = 0; secondPlace < ranges.size(); secondPlace++) {\n double p = probability(currentPrice, ranges, firstPlace, secondPlace);\n if (p > 0.0) {\n probability += p;\n }\n }\n }\n return probability;\n }\n\n private static double probability(int currentPrice, List ranges, int firstPlace, int secondPlace) {\n if (firstPlace == secondPlace) {\n return - 10.0;\n }\n Range firstRange = ranges.get(firstPlace);\n Range secondRange = ranges.get(secondPlace);\n if (firstRange.toInc < currentPrice || !secondRange.in(currentPrice)) {\n return - 10.0;\n }\n\n double firstPlaceP = (firstRange.toInc - currentPrice) / (firstRange.toInc - firstRange.fromInc + 1.);\n if (firstRange.fromInc > currentPrice) {\n firstPlaceP = 1.;\n }\n double secondPlaceP = 1. / (secondRange.toInc - secondRange.fromInc + 1.);\n double otherP = 1.0;\n double otherAdd = 0.;\n double eq = 0.;\n for (int otherPlace = 0 ; otherPlace < ranges.size(); otherPlace++) {\n if (otherPlace == firstPlace || otherPlace == secondPlace) {\n continue;\n }\n Range otherRange = ranges.get(otherPlace);\n if (currentPrice < otherRange.fromInc) {\n return -10.0;\n }\n if (currentPrice > otherRange.toInc) {\n continue;\n }\n\n otherP = otherP * ((currentPrice - otherRange.fromInc) / (otherRange.toInc - otherRange.fromInc + 1.));\n if (otherPlace < secondPlace) {\n otherAdd += 1./ (otherRange.toInc - otherRange.fromInc + 1.);\n }\n if (otherPlace < firstPlace && firstPlace < secondPlace) {\n eq += 1./ (otherRange.toInc - otherRange.fromInc + 1.);\n }\n }\n double firstAddP = 0.;\n if (firstPlace < secondPlace) {\n firstAddP = 1. / (firstRange.toInc - firstRange.fromInc + 1.) ;\n }\n return firstPlaceP * secondPlaceP * (otherP + otherAdd) +\n (eq + otherP) * firstAddP * secondPlaceP;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dca4db86342301e120801f54e229a166", "src_uid": "5258ce738eb268b9750cfef309d265ef", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\n\npublic class Prob03 {\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int N = in.nextInt();\n int[] L = new int[N];\n int[] R = new int[N];\n for (int i = 0; i < N; i++) {\n L[i] = in.nextInt();\n R[i] = in.nextInt();\n }\n double[] probabilities = new double[11];\n for (int i = 0; i < N; i++) {\n for (int j = L[i]; j <= R[i]; j++) {\n double prob = 1./(R[i]-L[i]+1);\n //count probability j to be the second largest\n double probResult = 0;\n outer:\n for (int k = 0; k < N; k++) {\n if (i == k) continue;\n \n double probMax = (1.*R[k] - j)/(R[k]-L[k]+1);\n if (probMax < 0) continue;\n if (i < k && L[k]<=j && R[k] >= j) probMax += 1./(R[k]-L[k]+1);\n if (probMax > 1) probMax = 1;\n \n for (int m = 0; m < N; m++) {\n if (m==i || m == k) continue;\n double probMin = (1.*j - L[m])/(R[m]-L[m]+1);\n if (probMin < 0) continue outer; \n if (m < i && L[m]<=j && R[m] >= j) probMin += 1./(R[m]-L[m]+1);\n if (probMin > 1) probMin = 1;\n// System.out.println(\"second: \" + j + \" max prob: \" + probMax + \" min prob: \" + probMin);\n probMax *= probMin;\n }\n probResult += probMax;\n }\n prob *= probResult;\n probabilities[j] += prob;\n// System.out.println(Arrays.toString(probabilities));\n }\n }\n \n double sum = 0;\n double prob = 0;\n for (int i = 1; i < 11; i++) {\n sum += i *probabilities[i];\n prob += probabilities[i];\n }\n// System.out.println(sum);\n// System.out.println(sum / prob);\n System.out.println(String.format(\"%.9f\", sum));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "85f1dc82e3c44ab1e3bd7a70413b4bf9", "src_uid": "5258ce738eb268b9750cfef309d265ef", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "/**\n * Created by underestimatedcoder on 2018-01-16.\n */\npublic class Garden {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int noOfBuckets = scanner.nextInt();\n int gardenLength = scanner.nextInt();\n scanner.nextLine();\n int tmp = 1000000000;\n for(int i = 0; i < noOfBuckets; i ++){\n int curr = scanner.nextInt();\n if(gardenLength % curr == 0 && tmp > gardenLength/curr){\n tmp = gardenLength/curr;\n }\n }\n System.out.println(tmp);\n\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a918d5b8b8760bbe5496ef7f3eb87020", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n\npublic class scorify{\n\tpublic static void main(String[] args){\n\tScanner in=new Scanner(System.in);\n int n = in.nextInt(),min;\n int len = in.nextInt();\n int[] arr = new int[n];\n TreeSet set = new TreeSet();\n \n for (int i =0; ilen){seconds+=1000;break;}\n }\n set.add(seconds);\n }\n System.out.println(set.first());\n\t\n\t\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8417a8f27d0fb37a66ad4d7b56629e32", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\tfinal static int mod = 1_000_000_007;\n\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tSTDIN scan = new STDIN();\n\t\tStringBuilder sb = new StringBuilder();\n\t\t\n\t\tint n = scan.nextInt(), k = scan.nextInt(), ans = Integer.MAX_VALUE;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint curr = scan.nextInt();\n\t\t\tif(k % curr == 0) ans = Math.min(ans, k / curr);\n\t\t}\n\t\tsb.append(ans)\n\t\t\n\t\tSystem.out.println(sb);\n\t\n\t}\n\t\n\tstatic class STDIN {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic STDIN() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = null;\n\t\t}\n\n\t\tboolean hasNext() throws Exception {\n\t\t\tif (!st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.hasMoreTokens();\n\t\t}\n\n\t\tint nextInt() throws Exception {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws Exception {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws Exception {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString next() throws Exception {\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 Exception {\n\t\t\treturn br.readLine();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3be064156bf50bbc1857a10d59baae9", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import org.aspectj.util.GenericSignature;\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Garden {\n Scanner sc = new Scanner(System.in);\n int bucket = sc.nextInt();\n int gardenSize = sc.nextInt();\n ArrayList buckets = new ArrayList<>();\n\n\n public static void main(String[] args) {\n System.out.println(new Garden().otvet());\n }\n\n public int otvet(){\n for(int i = 0; i < bucket; i++){\n int temp = sc.nextInt();\n if(gardenSize%temp == 0) buckets.add(temp);\n }\n Collections.sort(buckets);\n return gardenSize/buckets.get(buckets.size()-1);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a610368d4977f80e42ec77ac93b06dd1", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Main {\n\n\n public static void main( String[] args ) throws java.lang.Exception {\n\n java.io.BufferedReader r = new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );\n\n String[] tokens = r.readLine().split( \" \" );\n\n List towerOne = new ArrayList<>();\n List towerTwo = new ArrayList<>();\n\n int max = Math.max( Integer.parseInt( tokens[0] ), Integer.parseInt( tokens[1] ) );\n int min = Math.min( Integer.parseInt( tokens[1] ), Integer.parseInt( tokens[0] ) );\n\n max = max == 0 ? 1 : max;\n min = min == 0 ? 1 : min;\n\n\n if ( (max / min) > min ) {\n if (max == Integer.parseInt( tokens[0] )) {\n System.out.println( max * 2 );\n } else {\n System.out.println( max * 3 );\n }\n\n return;\n }\n\n for( int i = 0; i < Integer.parseInt( tokens[0] ); i++ ) {\n towerOne.add( (i + 1) * 2 );\n }\n\n for( int i = 0; i < Integer.parseInt( tokens[1] ); i++ ) {\n towerTwo.add( (i + 1) * 3 );\n }\n\n for (int i = 1 ; i <= max( towerOne, towerTwo ); i++){\n if ( towerOne.contains( i ) && towerTwo.contains( i ) ){\n if ( height(towerOne) + 2 > height( towerTwo ) + 3 ){\n towerTwo.add( height( towerTwo ) + 3 );\n } else {\n towerOne.add( height( towerOne ) + 2 );\n }\n }\n\n if (towerOne.size() >1 && towerOne.indexOf( i ) != -1) {\n towerOne.remove( towerOne.indexOf( i ) );\n }\n if (towerTwo.size() >1 && towerTwo.indexOf( i )!= -1) {\n towerTwo.remove( towerTwo.indexOf( i ) );\n }\n }\n\n System.out.println( max( towerOne, towerTwo ) );\n }\n\n private static Integer max(List l1, List l2){\n if ( l1.size() == 0 ) return l2.get( l2.size() - 1 );\n if ( l2.size() == 0 ) return l1.get( l1.size() - 1 );\n\n return Math.max( l2.get( l2.size() - 1 ), l1.get( l1.size() - 1 ) );\n }\n\n private static Integer height(List l){\n if (l.size() == 0) {\n return 0;\n } else {\n return l.get( l.size() - 1 );\n }\n }\n\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c8803e7d8728ed7d12ad77fbbaf1eda", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class blockTowers {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner scan=new Scanner(System.in);\n\t\tlong two=scan.nextLong();\n\t\tlong three=scan.nextLong();\n\t\tif(two==0){\n\t\t\tSystem.out.println(three*3);\n\t\t\treturn;\n\t\t}\n\t\tif(three==0){\n\t\t\tSystem.out.println(two*2);\n\t\t\treturn;\n\t\t}\n\t\tArrayList twos=new ArrayList();\n\t\tArrayList threes=new ArrayList();\n\t\tfor(long i=1;i<=two;i++){\n\t\t\ttwos.add(2*i);\n\t\t}\n\t\tfor(long i=1;i<=three;i++){\n\t\t\tthrees.add(3*i);\n\t\t}\n\t\tlong c=unique(twos,threes);\n\t\twhile(c!=-1){\n\t\t\tif(twos.get(twos.size()-1)+2>threes.get(threes.size()-1)+3){\n\t\t\t\tint start=threes.indexOf(c);\n\t\t\t\tfor(int i=start;i a,ArrayList b){\n\t\tlong c=6;\n\t\tif(a.size()==0||b.size()==0)return -1;\n\t\twhile(true){\n\t\t\tif(a.get(a.size()-1) min3) {\n //accomodate for min2, when choosing from potential 3's always skip the multiples of 2\n \n long mult2 = 0;\n long mult3 = 0;\n \n for (int i = 0; i < three; i++) {\n mult3 += 3;\n if (mult3 % 2 == 0 && mult3 <= min2) mult3 += 3;\n //chosen.set(mult3);\n }\n \n mult2 = min2;\n \n answer = Math.max(mult3, mult2);\n } else if (min2 <= min3) {\n //accomodate for min3, when choosing form potential 2's always skip them ultibles of 3\n long mult2 = 0;\n long mult3 = 0;\n \n for (int i = 0; i < two; i++) {\n mult2 += 2;\n if (mult2 % 3 == 0 && mult2 <= min3) mult2 += 2;\n }\n \n mult3 = min3;\n \n answer = Math.max(mult3, mult2);\n }\n \n w.println(answer);\n w.close();\n */\n \n \n \n \n \n int twoHighest = 2;\n int threeHighest = 3;\n two--;\n three--;\n long min2 = two * 2;\n long min3 = three * 3;\n \n BitSet chosen = new BitSet();\n \n while (two > 0 || three > 0) {\n //find the one that results in the lower sum\n \n min2 = twoHighest + two * 2;\n min3 = threeHighest + three * 3;\n if ((twoHighest + 2) % 3 == 0 && two > 0 && three > 0) {\n //check if min2 or min3 is greater\n if (min2 < min3) {\n //increase 4\n twoHighest += 4;\n two-=2;\n if (chosen.get(twoHighest)) {\n twoHighest += 2;\n two--;\n }\n chosen.set(twoHighest);\n }\n } else if (two > 0) {\n twoHighest += 2;\n two--;\n if (chosen.get(twoHighest)) {\n twoHighest += 2;\n two--;\n }\n chosen.set(twoHighest);\n }\n \n if ((threeHighest + 3) % 2 == 0 && three > 0 && two > 0) {\n if (min2 > min3) {\n //increase 6\n threeHighest += 6;\n three-=2;\n if (chosen.get(threeHighest)) {\n threeHighest += 3;\n three--;\n }\n chosen.set(threeHighest);\n }\n } else if (three > 0) {\n threeHighest += 3;\n three--;\n if (chosen.get(threeHighest)) {\n threeHighest += 3;\n three--;\n }\n chosen.set(threeHighest);\n }\n }\n \n w.println(Math.max(twoHighest, threeHighest));\n w.close();\n }\n /*\n public static class CustomBitSet {\n //Use 3 bitsets\n BitSet one = new BitSet(2000000000);\n BitSet two = new BitSet(2000000000);\n //BitSet three = new BitSet(1000000000);\n \n public void set(long number) {\n //check if it's in 1 or 2 or 3\n \n if (number >= 4000000000L) {\n //third set\n //three.set((int) (number - 4000000000L));\n } else if (number >= 2000000000) {\n two.set((int) (number - 2000000000));\n } else {\n one.set((int) number);\n }\n }\n \n public boolean get(long number) {\n if (number >= 4000000000L) {\n //third set\n //return three.get((int) (number - 4000000000L));\n return false;\n } else if (number >= 2000000000) {\n return two.get((int) (number - 2000000000));\n } else {\n return one.get((int) number);\n }\n }\n }*/\n \n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "232a0b4cdd86215370c65f070a322713", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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 private int calcMtop(int M, int evens) {\n int top = M * 3;\n int gaps = M / 2 - evens;\n\n if (gaps == 0)\n return top;\n\n if (M % 2 == 0) {\n top += 3;\n } else {\n top += 6;\n }\n gaps--;\n\n top += 6 * gaps;\n\n return top;\n }\n\n private int calcNtop(int N, int evens) {\n int top = N * 2;\n\n for (int i = 0; i < evens; i++) {\n if ((i + 1) * 6 <= top)\n top += 2;\n }\n\n return top;\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n\n int evens = M / 2;\n\n int mtop = calcMtop(M, evens);\n int ntop = calcNtop(N, evens);\n\n int result = Math.max(mtop, ntop);\n\n while (evens > 0) {\n evens--;\n mtop = calcMtop(M, evens);\n ntop = calcNtop(N, evens);\n\n if (Math.max(mtop, ntop) < result)\n result = Math.max(mtop, ntop);\n else\n break;\n }\n\n out.println(result);\n\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ba6f92f687a439330511a80a3d243ce5", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class e {\n\tpublic static void main(String[] args){\n\t\tScanner input = new Scanner(System.in);\n\t\tlong n = input.nextLong() + 1, t = input.nextLong();\n\t\t\n\t\tboolean valid = false;\n\t\tlong a = 1;\n\t\tint k = 1;\n\t\tfor(int i = 0 ; i < 63; i++){\n\t\t\tif(t == a){\n\t\t\t\tvalid = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ta = a << 1;\n\t\t\tk++;\n\t\t}\n\t\t//System.out.println(k);\n\t\tif(!valid){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong sum = 0;\n\t\tint b = Long.bitCount(n);\n\t\tfor(int i = 0; i < 63; i++)\n\t\t\tif(((1l << i) & n) != 0){\n\t\t\t\t//System.out.print(sum + \" (\" + i + \", \" + (k - b + 1) + \")-->\");\n\t\t\t\tsum += choose(i , k - b + 1);\n\t\t\t\t//System.out.println(sum);\n\t\t\t\tb--;\n\t\t\t}\n\t\t\n\t\tSystem.out.println(sum);\n\t}\n\t\n\tstatic long choose(int n, int k){\n\t\tif(k > n || k < 0)\n\t\t\treturn 0;\n\t\tlong ret = 1;\n\t\tfor(int i = 1; i <= k; i++){\n\t\t\tret *= n--;\n\t\t\tret /= i;\n\t\t}\n\t\treturn ret;\n\t}\n}\n/*\n1000000000000 549755813888\n\n*/", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3911259983ea98204d262316e7b3a634", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.Locale;\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 Jacob Jiang\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 long[][] C = NumberUtils.generateBinomialCoefficients(50, Long.MAX_VALUE);\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long n = in.nextLong();\n long t = in.nextLong();\n int x = Long.numberOfTrailingZeros(t);\n if (t != (1l << x)) {\n out.println(0);\n return;\n }\n x++;\n long answer = 0;\n n++;\n while (n > 0) {\n long cur = Long.highestOneBit(n);\n n -= cur;\n answer += C[Long.numberOfTrailingZeros(cur)][x];\n x--;\n\n }\n out.println(answer);\n }\n}\n\nclass NumberUtils {\n\n public static long[][] generateBinomialCoefficients(int n, long module) {\n long[][] result = new long[n + 1][n + 1];\n if (module == 1)\n return result;\n for (int i = 0; i <= n; i++) {\n result[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n result[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n if (result[i][j] >= module)\n result[i][j] -= module;\n }\n }\n return result;\n }\n\n}\n\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (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 static boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c & 15;\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n }\n\nclass OutputWriter {\n private PrintWriter writer;\n\n public OutputWriter(OutputStream stream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void println(long x) {\n writer.println(x);\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n public void close() {\n writer.close();\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a41b10bd23e43379c08ff4f373ef45b", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.BitSet;\n\npublic class ProblemC {\n\t\n\tstatic void doit(int m) {\n\t\tlong[][] a = generate(m);\n\t\tint len = a.length;\n\t\tint c = 0;\n\t\tfor (int j = 0 ; j < len ; j++) {\n\t\t\tc += a[len-1][j];\n\t\t}\n\t\tdebug(m, c);\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tString[] line = s.readLine().split(\" \");\n\t\tlong n = Long.valueOf(line[0]);\n\t\tlong t = Long.valueOf(line[1]);\n\t\t\n\t\tint fc = -1;\n\t\tfor (int f = 0 ; f < 60 ; f++) {\n\t\t\tif (Math.pow(2L, f) == t) {\n\t\t\t\tfc = f;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (fc == -1) {\n\t\t\tout.println(0);\n\t\t\tout.flush();\n\t\t\treturn;\n\t\t}\n\t\tfc++;\n\t\t\n\t\tint len = 0;\n\t\tlong nn = n;\n\t\tint[] bit = new int[128];\n\t\twhile (nn >= 1) {\n\t\t\tbit[len] = (int)(nn % 2);\n\t\t\tnn /= 2L;\n\t\t\tlen++;\n\t\t}\n\t\t\n\t\tlong[][][] dp = new long[len+1][fc+1][3];\n\t\tdp[0][fc][0] = 1;\n\t\tfor (int i = 0 ; i < len ; i++) {\n\t\t\tfor (int f = 0 ; f <= fc ; f++) {\n\t\t\t\tfor (int c = 0 ; c <= 2 ; c++) {\n\t\t\t\t\tif (dp[i][f][c] == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlong base = dp[i][f][c];\n\t\t\t\t\tif (bit[i] == 0) {\n\t\t\t\t\t\t// use one\n\t\t\t\t\t\tif (f >= 1) {\n\t\t\t\t\t\t\tdp[i+1][f-1][1] += base;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// use zero\n\t\t\t\t\t\tdp[i+1][f][c] += base;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// use one\n\t\t\t\t\t\tif (f >= 1) {\n\t\t\t\t\t\t\tdp[i+1][f-1][c] += base;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// use zero\n\t\t\t\t\t\tdp[i+1][f][2] += base;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong ans = dp[len][0][2] + dp[len][0][0];\n\t\tout.println(ans);\n\t\tout.flush();\n\t}\n\t\n\tpublic static long[][] generate(int m ){\n\t\tlong[][] a = new long[m+2][m+2];\n\t\ta[1][m+1] = 1;\n\t\tfor (int i = 2 ; i <= m + 1 ; i++) {\n\t\t\tfor (int j = 1 ; j <= m + 1 ; j++) {\n\t\t\t\tif (j == 1) {\n\t\t\t\t\ta[i][j] = a[i-1][j+1];\n\t\t\t\t} else {\n\t\t\t\t\tif (j == m + 1) {\n\t\t\t\t\t\ta[i][j] = a[i-1][j-1];\n\t\t\t\t\t} else {\n\t\t\t\t\t\ta[i][j] = a[i-1][j-1] ^ a[i-1][j+1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\t\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f64253a9e9dba4abf6759d79f8192900", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "//package codeforces.contests.cf160;\n\nimport java.io.*;\n\npublic class ProblemC {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));\n\n int[] readInts() throws IOException {\n String[] strings = reader.readLine().split(\" \");\n int[] ints = new int[strings.length];\n for(int i = 0; i < ints.length; i++) {\n ints[i] = Integer.parseInt(strings[i]);\n }\n return ints;\n }\n\n long[] readLongs() throws IOException {\n String[] strings = reader.readLine().split(\" \");\n long[] longs = new long[strings.length];\n for(int i = 0; i < longs.length; i++) {\n longs[i] = Long.parseLong(strings[i]);\n }\n return longs;\n }\n\n long[][] dp = new long[64][64];\n boolean[][] vis = new boolean[64][64];\n\n long rec(long rows, long sum) {\n int br = bit(rows + 1);\n int bs = bit(sum);\n boolean ok = bits(rows + 1) == 1;\n if(ok) {\n if(vis[br][bs]) {\n return dp[br][bs];\n }\n vis[br][bs] = true;\n }\n if(sum == 1) {\n long ret = 0;\n for(long i = 1; i <= rows; i <<= 1) {\n ret++;\n }\n if(ok) {\n dp[br][bs] = ret;\n }\n return ret;\n }\n long ret = 0;\n for(long i = 1; ; i <<= 1) {\n if(i <= rows) {\n rows -= i;\n ret += rec(i - 1, sum / 2);\n }\n else {\n ret += rec(rows - 1, sum / 2);\n break;\n }\n }\n if(ok) {\n dp[br][bs] = ret;\n }\n return ret;\n }\n\n int bits(long n) {\n int b = 0;\n for(int i = 0; i < 64; i++) {\n if((n >> i) % 2 == 1) b++;\n }\n return b;\n }\n int bit(long n) {\n for(int i = 0; i < 60; i++) {\n if((1L << i) == n) return i;\n }\n return 61;\n }\n\n void solve() throws IOException {\n long[] tt = readLongs();\n long n = tt[0];\n long t = tt[1];\n if(bits(t) != 1) {\n writer.println(0);\n }\n else {\n writer.println(rec(n, t));\n }\n writer.flush();\n }\n\n public static void main(String[] args) throws IOException {\n new ProblemC().solve();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11ce36901ee269997ea34ea84c2d37f0", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class E {\n\tpublic static void main(String[] args) {\n\t\tMyScanner scan = new MyScanner();\n\t\tint N = scan.nextInt()-1;\n\t\tString s1 = scan.nextLine();\n\t\tString sTemp = scan.nextLine();\n\t\tif(N==1){\n\t\t\tif((s1.charAt(0)=='N'&&sTemp.charAt(0)=='S')||(s1.charAt(0)=='S'&&sTemp.charAt(0)=='N')){\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}else if((s1.charAt(0)=='W'&&sTemp.charAt(0)=='E')||(s1.charAt(0)=='E'&&sTemp.charAt(0)=='W')){\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tString card = \"EWSN\";\n\t\tStringBuilder s2 = new StringBuilder(\"\");\n\t\tfor(int i=N-1;i>=0;i--){\n\t\t\ts2.append(card.charAt(card.indexOf(sTemp.charAt(i))^1));\n\t\t}\n\t\t\n\t\tString s = s2.toString();\n\t\t\n\t\tboolean valid = true;\n\t\tfor(int i=1;i<=s.length();i++){\n\t\t\tif(s.substring(0, i).equals(s1.substring(s1.length()-i, s1.length()))){\n\t\t\t\tvalid=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(valid?\"YES\":\"NO\");\n\t}\n\tprivate static class MyScanner {\n\t BufferedReader br;\n\t StringTokenizer st;\n\n\t public MyScanner(){\n\t br = new BufferedReader(new InputStreamReader(System.in));\n\t }\t\n\n\t String next() {\n\t while (st == null || !st.hasMoreElements()) {\n\t try {\n\t st = new StringTokenizer(br.readLine());\n\t } catch (IOException e) {\n\t e.printStackTrace();\n\t }\n\t }\n\t return st.nextToken();\n\t }\n\t \n\t String nextLine(){\n\t String str = \"\";\n\t\t try {\n\t\t str = br.readLine();\n\t\t } catch (IOException e) {\n\t\t e.printStackTrace();\n\t\t }\n\t\t return str;\n\t }\n\t int nextInt() {\n\t return Integer.parseInt(next());\n\t }\n\t }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "62bf2df9ce26b7de5f6b570c43c2e938", "src_uid": "85f43628bec7e9b709273c34b894df6b", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\npublic class Marbles2 {\n\n\n public static void main(String[] args) {\n InReader sc = new InReader(System.in);\n int n = sc.nextInt() - 1;\n String a = sc.next();\n String b = sc.next();\n\n\n String brev = reverse(b);\n\n boolean no = false;\n out:\n for (int i = n - 1; i >= 0; i--) {\n for (int j = i; j < n; j++) {\n if (a.charAt(j) != brev.charAt(j-i)) {\n continue out;\n }\n }\n no = true;\n break;\n }\n if (no) {\n System.out.printf(\"NO\");\n } else {\n System.out.println(\"YES\");\n }\n\n }\n\n\n private static String reverse(String s) {\n StringBuilder sb = new StringBuilder();\n for (int i = s.length() - 1; i >= 0; i--) {\n char c = s.charAt(i);\n char rc;\n switch (c) {\n case 'W':\n rc = 'E';\n break;\n case 'E':\n rc = 'W';\n break;\n case 'N':\n rc = 'S';\n break;\n case 'S':\n rc = 'N';\n break;\n default:\n throw new AssertionError(\"Wrong char: \" + c + \", at \" + i);\n }\n sb.append(rc);\n }\n return sb.toString();\n }\n\n static class InReader {\n\n private BufferedReader br;\n private String[] split;\n private int index;\n\n public InReader(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in), 1024 * 1024);\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String next() {\n try {\n while (split == null || split.length <= index) {\n String line = br.readLine();\n if (line != null && !line.isEmpty()) {\n split = line.split(\" \");\n index = 0;\n }\n }\n return split[index++];\n } catch (IOException e) {\n e.printStackTrace();\n throw new RuntimeException(e);\n }\n }\n\n public int[] getArray(int n) {\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 int[][] getPairArray(int n) {\n int[][] res = new int[2][n];\n for (int i = 0; i < n; i++) {\n res[0][i] = nextInt();\n res[1][i] = nextInt();\n }\n return res;\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b216ce28c3040d997937e75e3851daff", "src_uid": "85f43628bec7e9b709273c34b894df6b", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class E {\n\tpublic static void main(String[] args) {\n\t\tMyScanner scan = new MyScanner();\n\t\tint N = scan.nextInt()-1;\n\t\tString s1 = scan.nextLine();\n\t\tString sTemp = scan.nextLine();\n\t\tif(N==1){\n\t\t\tif((s1.charAt(0)=='N'&&sTemp.charAt(0)=='S')||(s1.charAt(0)=='S'&&sTemp.charAt(0)=='N')){\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}else if((s1.charAt(0)=='W'&&sTemp.charAt(0)=='E')||(s1.charAt(0)=='E'&&sTemp.charAt(0)=='W')){\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tString card = \"EWSN\";\n\t\tStringBuilder s2 = new StringBuilder(\"\");\n\t\tfor(int i=N-1;i>=0;i--){\n\t\t\ts2.append(card.charAt(card.indexOf(sTemp.charAt(i))^1));\n\t\t}\n\t\t\n\t\tint[] count = new int[N];\n\t\tint j=0, i=0;\n\t\twhile(i 0 && A[pi] == op(B[pj - 1])) {\n pj--;\n }\n pi++;\n }\n\n while (pj < N) {\n if (pi < N && A[pi] == B[pj]) {\n pi++;\n }\n if (pi > 0 && A[pi - 1] == op(B[pj])) {\n pi--;\n }\n pj++;\n }\n\n if (pi <= crti) {\n out.println(\"NO\");\n return;\n }\n crti = pi;\n crtj = pj;\n }\n\n out.println(\"YES\");\n }\n\n private char op(char c) {\n return dirs.charAt(3 - dirs.indexOf(c));\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 int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public 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 interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "797e3fc367af2d4b48ceefe746fe61b1", "src_uid": "85f43628bec7e9b709273c34b894df6b", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "\n\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.concurrent.LinkedBlockingQueue;\n\npublic class C214 {\n int n;\n boolean room[][];\n boolean dep[][];\n int num[];\n int idx[];\n boolean visited[];\n int ans = Integer.MAX_VALUE;\n Set zeros;\n static int [][] pay;\n static {\n pay = new int[3][3];\n for( int i =0; i<3 ; i ++){\n pay[i][i] = 0;\n pay[i][(i+1)%3] = 1;\n pay[i][(i+2)%3] = 2;\n }\n }\n\n public void solve(Scanner cin , PrintWriter cout ){\n n = cin.nextInt();\n room = new boolean[3][n];\n dep = new boolean[n][n];\n num = new int[n];\n idx = new int[n];\n visited = new boolean[n];\n for( int i=0 ;i ();\n for( int i= 0;i = ans)\n return;\n if( zeros.size() == 0 ){\n if( cost < ans ) {\n ans = cost;\n }\n return;\n }\n Queue zs = new LinkedBlockingQueue();\n for( int zero : zeros){\n if( idx[zero] == r) {\n zs.add(zero);\n }\n }\n if( zs.isEmpty()) {\n return ;\n }\n Set bak_zeros = new HashSet();\n Set add_zeros = new HashSet();\n int [] bak_num = new int[n];\n for( int i=0;i[]g;\n\tList nofather;\n\t\n\tpublic void run() throws Exception {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t//in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\tn = nextInt();\n\t\tc = new int[3][3];\n\t\tc[0] = new int[]{0, 1 ,2};\n\t\tc[1] = new int[]{2, 0, 1};\n\t\tc[2] = new int[]{1 ,2, 0};\n\t\t\n\t\ta = new int[n];\n\t\tfor(int i=0;i();\n\t\t}\n\t\t\n\t\tnofather = new ArrayList();\n\t\tfor(int i=0;i b = new ArrayList();\n\t\tfor(int i : nofather){\n\t\t\tb.add(solve(i));\n\t\t}\t\n\t\t\t\n\t\tint m = b.size();\n\t\tint ret = Integer.MAX_VALUE;\n\t\tfor(int i=0;i b){\n\t\tint m = b.size();\n\t\tboolean used[] = new boolean[m];\n\t\tint cur[] = b.get(s);\n\t\tused[s] = true;\n\t\tint ret = 0;\n\t\twhile(true){\n\t\t\tint min = Integer.MAX_VALUE/2;\n\t\t\tint idx = -1;\n\t\t\tint index = -1;\n\t\t\tfor(int i=0;i cost){\n\t\t\t\t\t\tmin = cost;\n\t\t\t\t\t\tindex = i;\n\t\t\t\t\t\tidx = l[1];\n\t\t\t\t\t}else if (cost == min){\n\t\t\t\t\t\tif (idx > l[1]){\n\t\t\t\t\t\t\tindex = i;\n\t\t\t\t\t\t\tidx = l[1];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (index == -1)\n\t\t\t\treturn ret;\n\t\t\tret+=min;\n\t\t\tcur = b.get(index);\n\t\t\tused[index] = true;\n\t\t}\n\t}\n\t\n\tprivate int[] solve(int s){\n\t\t\n\t\tint d[] = new int[n];\n\t\tArrays.fill(d, Integer.MAX_VALUE/2);\n\t\td[s] = 0;\n\t\tboolean used[] = new boolean[n];\n\t\tused[s] = true;\n\t\tint cur = s;\n\t\twhile(true){\n\t\t\tfor(int i : g[cur]){\n\t\t\t\tif (d[i] > d[cur] + c[a[cur]][a[i]]){\n\t\t\t\t\td[i] = d[cur] + c[a[cur]][a[i]];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint min = Integer.MAX_VALUE/2;\n\t\t\tint index = -1;\n\t\t\tfor(int i=0;i d[i]){\n\t\t\t\t\tmin = d[i];\n\t\t\t\t\tindex = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (index == -1) break;\n\t\t\tused[index] = true;\n\t\t\tcur = index;\n\t\t}\n\t\tint max = d[s];\n\t\tint index = s;\n\t\tint val = 0;\n\t\tfor(int i=0;i[] g = new ArrayList[n];\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tpk[i] = in.nextInt() - 1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint k = in.nextInt();\n\t\t\tg[i] = new ArrayList();\n\t\t\tfor (int j = 0; j < k; ++j)\n\t\t\t\tg[i].add(in.nextInt() - 1);\n\t\t\tCollections.sort(g[i]);\n\t\t}\n\t\tfor (int i = 0; i < 3; ++i) {\n\t\t\tArrays.fill(used, false);\n\t\t\tint s = 0;\n\t\t\tint p = i;\n\t\t\tint cnt = 0;\n\t\t\twhile (true) {\n\t\t\t\tif (cnt == n) {\n\t\t\t\t\tans = Math.min(ans, s);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfor (int j = 0; j < n; ++j) {\n\t\t\t\t\tif (pk[j] == p && !used[j]) {\n\t\t\t\t\t\tboolean f = true;\n\t\t\t\t\t\tfor (Integer k : g[j])\n\t\t\t\t\t\t\tif (!used[k])\n\t\t\t\t\t\t\t\tf = false;\n\t\t\t\t\t\tif (true) {\n\t\t\t\t\t\t\tused[j] = true;\n\t\t\t\t\t\t\tcnt++;\n\t\t\t\t\t\t\ts++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (cnt == n) {\n\t\t\t\t\tans = Math.min(ans, s);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ts++;\n\t\t\t\tp = (p + 1) % 3;\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n}\n\nclass FastScanner {\n public BufferedReader br;\n public StringTokenizer tokenizer;\n\n public FastScanner(InputStream stream) {\n br = 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(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "adfc3fd4748bb4bcc236e92ca1a5cfe1", "src_uid": "be42e213ff43e303e475d77a9560367f", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\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 Serjio\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\nclass TaskC {\n\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\tint n = in.nextInt(), pk[] = new int[n];\n\t\tlong ans = Long.MAX_VALUE;\n\t\tboolean used[] = new boolean[n];\n\t\tList[] g = new ArrayList[n];\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tpk[i] = in.nextInt() - 1;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint k = in.nextInt();\n\t\t\tg[i] = new ArrayList();\n\t\t\tfor (int j = 0; j < k; ++j)\n\t\t\t\tg[i].add(in.nextInt() - 1);\n\t\t}\n\t\tfor (int i = 0; i < 3; ++i) {\n\t\t\tArrays.fill(used, false);\n\t\t\tlong s = n;\n\t\t\tint p = i;\n\t\t\tint cnt = 0;\n\t\t\twhile (true) {\n\t\t\t\tfor (int j = 0; j < n; ++j) {\n\t\t\t\t\tif (pk[j] == p && !used[j]) {\n\t\t\t\t\t\tboolean f = true;\n\t\t\t\t\t\tfor (Integer k : g[j])\n\t\t\t\t\t\t\t\tf &= used[k];\n\t\t\t\t\t\tif (f) {\n\t\t\t\t\t\t\tused[j] = true;\n\t\t\t\t\t\t\tcnt++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int j = 0; j < n; ++j) {\n\t\t\t\t\tif (pk[j] == p && !used[j]) {\n\t\t\t\t\t\tboolean f = true;\n\t\t\t\t\t\tfor (Integer k : g[j])\n\t\t\t\t\t\t\tf &= used[k];\n\t\t\t\t\t\tif (f) {\n\t\t\t\t\t\t\tused[j] = true;\n\t\t\t\t\t\t\tcnt++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (cnt == n)\n\t\t\t\t\tbreak;\n\t\t\t\ts++;\n\t\t\t\tp = (p + 1) % 3;\n\t\t\t}\n\t\t\tans = Math.min(ans,s);\n\t\t}\n\t\tout.print(ans);\n\t}\n}\n\nclass FastScanner {\n public BufferedReader br;\n public StringTokenizer tokenizer;\n\n public FastScanner(InputStream stream) {\n br = 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(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b52789289a44d0b4b1cdfda06bfb64c4", "src_uid": "be42e213ff43e303e475d77a9560367f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class OlimpB {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint y = scan.nextInt();\n\t\tint y2 = scan.nextInt();\n\t\tSystem.out.println(6 - y - y2);\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc025f7df6bc30f21c64f8ab59231c6b", "src_uid": "e167dc35a0d3b98c0414c66099e35920", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class MyClass {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int a = scan.nextInt();\n int b = scan.nextInt();\n System.out.println(6 - (a+b));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "708e0296c5733fe5d095c37cc23efee8", "src_uid": "e167dc35a0d3b98c0414c66099e35920", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.lang.Math;\n\npublic class A\n{\n static int a = Math.random() * 3 + 1;\n static int b = Math.random() * 3 + 1;\n public static void main(String[] args)\n {\n if(a == 2 && b == 3 && a != b || a == 3 && b == 2 && a != b)\n {\n System.out.println(1);\n }\n else if(a == 1 && b == 3 && a != b || a == 3 && b == 1 && a != b)\n {\n System.out.println(2);\n }\n else if(a == 1 && b == 2 && a != b || a == 2 && b == 1 && a != b)\n {\n System.out.println(3);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f3d589d68988840463a1442e638b7862", "src_uid": "e167dc35a0d3b98c0414c66099e35920", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class A\n{\npublic static void main(String[] args)\n{\nBufferedReader br = new BufferedReader(new InputStreamReder(System.in));\ntry\n{\n String n = br.readLine();\n if(!n.startsWith(n.substring(1,2)))\n {\n if(n.substring(0,1).equals(2) && n.substring(1,2).equals(3) || n.substring(0,1).equals(3) && n.subdtring(1,2).equals(2))\n \n System.out.println(1);\n }\n else if(n.substring(0,1).equals(1) && n.substring(1,2).equals(3) || n.substring(0,1).equals(3) && n.substring(0,1).equals(1))\n {\n System.out.println(2);\n }\n else if(n.substring(0,1).equals(2) && n.substring(1,2).equals(1) || n.substring(0,1).equals(1) && n.substring(1,2).equals(2))\n {\n System.out.println(3);\n }\n \n}\ncatch(Exception excp)\n{\n \n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5f7d8e7c4b13fca0d104d70e9d65e2f7", "src_uid": "e167dc35a0d3b98c0414c66099e35920", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class C {\n\n public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n public static StringTokenizer tok;\n\n public static int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public static long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public static double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public static String nextToken() throws IOException {\n if (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n public static void main(String[] args) throws IOException {\n int n = nextInt();\n int m = nextInt();\n List> graph = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n graph.add(new HashSet<>());\n }\n for (int i = 0; i < m; i++) {\n int u = nextInt() - 1;\n int v = nextInt() - 1;\n graph.get(u).add(v);\n graph.get(v).add(u);\n }\n List> reverse = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n reverse.add(new HashSet<>());\n for (int j = 0; j < n; j++) {\n if (i != j && !graph.get(i).contains(j)) {\n reverse.get(i).add(j);\n }\n }\n }\n ArrayList line = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n line.add(null);\n }\n Queue queue = new LinkedList<>();\n int counter = 0;\n while (counter < n) {\n if (line.get(counter) == null && !reverse.get(counter).isEmpty()) {\n queue.add(counter);\n while (!queue.isEmpty()) {\n int x = queue.remove();\n if (line.get(x) == null) {\n line.set(x, 'a');\n }\n char other = line.get(x) == 'a' ? 'c' : 'a';\n for (int near: reverse.get(x)) {\n if (line.get(near) == null) {\n line.set(near, other);\n queue.add(near);\n } else if (line.get(x) == line.get(near)) {\n System.out.println(\"No\");\n return;\n }\n }\n }\n }\n counter++;\n }\n for (int i = 0; i < n; i++) {\n if (line.get(i) == null) {\n line.set(i, 'b');\n }\n }\n System.out.println(\"Yes\");\n for (int i = 0; i < n; i++) {\n System.out.print(line.get(i));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fc9ed3c783bc3a79aa2482900cb6314b", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "package x0001_aim_tech_round_div_1;\n\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.util.Scanner;\n\npublic class A_GraphAndString {\n\tpublic static final int A = 1, B = 2, C = 3, NOT_MARKED = 0;\n\t\n\tprivate final boolean isDebug;\n\t\n\tint n, m;\n\tboolean[][] g;\n\tint[] v;\n\tpublic A_GraphAndString(boolean isDebug) {\n\t\tthis.isDebug = isDebug;\n\t}\n\t\n\tpublic void readInput() {\n\t\tScanner sc = null;\n\t\tif (isDebug) {\n\t\t\ttry {\n\t\t\t\tsc = new Scanner(new FileInputStream(\"src\\\\x0001_aim_tech_round_div_1\\\\A_input1.txt\"));\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} else {\n\t\t\tsc = new Scanner(System.in);\n\t\t}\n\t\t\n\t\tn = sc.nextInt();\n\t\tm = sc.nextInt();\n\t\tif (isDebug)\n\t\t\tSystem.out.format(\"n=%d m=%d%n\", n, m);\n\t\t\n\t\tg = new boolean[n][n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = sc.nextInt() - 1;\n\t\t\tint v = sc.nextInt() - 1;\n\t\t\tif (isDebug)\n\t\t\t\tSystem.out.format(\"%d %d%n\", u + 1, v + 1);\n\t\t\tg[u][v] = true;\n\t\t}\n\t\t\n\t\tv = new int[n];\n\t}\n\t\n\tpublic void solve() {\n\t\tif (m == 0) {\n\t\t\tswitch (n) {\n\t\t\tcase 1:\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\tSystem.out.print(\"a\");\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\tSystem.out.print(\"ac\");\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tSystem.out.println(\"No\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tmark();\n\t}\n\t\n\tprivate void mark() {\n\t\tfindAndMarkAllB();\n\t\tif (!findAndMarkAllA())\n\t\t\treturn;\n\t\tif (!findAndMarkAllC())\n\t\t\treturn;\n\t\t\n\t\tif (isGraphLegit()) {\n\t\t\tSystem.out.println(\"Yes\");\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tString letter;\n\t\t\t\tswitch (v[i]) {\n\t\t\t\tcase A: letter = \"a\"; break;\n\t\t\t\tcase B: letter = \"b\"; break;\n\t\t\t\tcase C: letter = \"c\"; break;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t\tSystem.out.print(letter);\n\t\t\t}\n\t\t} else {\n\t\t\tSystem.out.println(\"No\");\n\t\t}\n\t}\n\t\n\tprivate void findAndMarkAllB() {\n\t\tfor (int y = 0; y < n; y++) {\n\t\t\tboolean isB = true;\n\t\t\tfor (int x = 0; x < n; x++) {\n\t\t\t\tif (y != x && !connected(y, x)) {\n\t\t\t\t\tisB = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (isB) {\n\t\t\t\tv[y] = B;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate boolean findAndMarkAllA() {\n\t\tint idxA = -1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (v[i] == NOT_MARKED) {\n\t\t\t\tidxA = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (idxA == -1) {\t// All B\n\t\t\tSystem.out.println(\"Yes\");\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tSystem.out.print(\"b\");\n\t\t\t}\n\t\t\t\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tv[idxA] = A;\n\t\tfor (int i = idxA + 1; i < n; i++) {\n\t\t\tif (connected(idxA, i) && v[i] == NOT_MARKED) {\n\t\t\t\tv[i] = A;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate boolean findAndMarkAllC() {\n\t\tint idxC = -1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (v[i] == NOT_MARKED) {\n\t\t\t\tidxC = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (idxC == -1) {\t// No C\n\t\t\tif (isGraphLegit()) {\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tString letter = v[i] == B ? \"b\" : \"a\"; \n\t\t\t\t\tSystem.out.print(letter);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"No\");\n\t\t\t}\n\t\t\t\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tv[idxC] = C;\n\t\tfor (int i = idxC + 1; i < n; i++) {\n\t\t\tif (v[i] == NOT_MARKED) {\n\t\t\t\tif (connected(idxC, i)) {\n\t\t\t\t\tv[i] = C;\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.println(\"No\");\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate boolean isGraphLegit() {\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (v[i] == A || v[i] == C) {\n\t\t\t\tint letter = v[i] == A ? C : A;\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif (i != j) {\n\t\t\t\t\t\tif ((v[j] != letter && !connected(i, j))\n\t\t\t\t\t\t\t\t|| (v[j] == letter && connected(i, j))) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\n\tprivate boolean connected(int u, int v) {\n\t\treturn g[u][v] || g[v][u];\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tA_GraphAndString solver = new A_GraphAndString(false);\n\t\tsolver.readInput();\n\t\tsolver.solve();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4cde28988257532a6624e84f15a8a808", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.List;\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 MyScanner in = new MyScanner(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 private static int[] cntComops;\n private static boolean[] markComps;\n private static boolean[][] matrix;\n private static int ch;\n private static char[] result;\n\n public void solve(int testNumber, MyScanner in, PrintWriter out) {\n\n int n = in.nextInt();\n int m = in.nextInt();\n ch = 0;\n result = new char[n];\n List> g = new ArrayList<>();\n\n for (int i = 0; i < n; i++) {\n g.add(new ArrayList<>());\n }\n matrix = new boolean[n][n];\n\n for (int i = 0; i < m; i++) {\n int v = in.nextInt() - 1;\n int u = in.nextInt() - 1;\n g.get(v).add(u);\n g.get(u).add(v);\n matrix[v][u] = true;\n matrix[u][v] = true;\n }\n cntComops = new int[n];\n int compLabel = 0;\n List> comps = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n if (cntComops[i] == 0) {\n List subGraph = new ArrayList<>();\n Set subset = new HashSet<>();\n subGraph.add(i);\n subset.add(i);\n cntComops[i]++;\n int it = 0;\n while (it < subGraph.size()) {\n int cur = subGraph.get(it++);\n for (int j = 0; j < g.get(cur).size(); j++) {\n int to = g.get(cur).get(j);\n if (!subset.contains(to)) {\n Set toSubset = new HashSet<>(g.get(to));\n if (toSubset.containsAll(subGraph)) {\n subGraph.add(to);\n subset.add(to);\n cntComops[to]++;\n }\n }\n }\n }\n compLabel++;\n comps.add(subGraph);\n }\n }\n\n for (int i = 0; i < n; i++) {\n if (cntComops[i] > 2) {\n out.print(\"No\");\n return;\n }\n }\n for (int i = 0; i < comps.size(); i++) {\n for (int j = i + 1; j < comps.size(); j++) {\n for (int x : comps.get(i)) {\n for (int y : comps.get(j)) {\n if (x != y && matrix[x][y] && cntComops[x] == 1 && cntComops[y] == 1) {\n out.print(\"No\");\n return;\n }\n }\n }\n }\n }\n markComps = new boolean[comps.size()];\n for (int i = 0; i < comps.size(); i++) {\n if (!markComps[i] && isStart(comps.get(i))) {\n dfs(i, comps);\n }\n }\n if (ch > 4) {\n out.println(\"No\");\n return;\n }\n out.println(\"Yes\");\n for (int i = 0; i < n; i++) {\n out.print(result[i]);\n }\n\n }\n\n private static boolean isStart(List comp) {\n for (int i = 0; i < comp.size(); i++) {\n if (cntComops[comp.get(i)] == 1) {\n return true;\n }\n }\n return false;\n }\n\n private static void dfs(int id, List> g) {\n markComps[id] = true;\n char cur = (char) (ch + 'a');\n char next = (char) (ch + 1 + 'a');\n for (int i = 0; i < g.size(); i++) {\n if (!markComps[i] && isBro(g.get(id), g.get(i))) {\n for (int x : g.get(id)) {\n boolean isX = true;\n for (int y : g.get(i)) {\n if (x == y) {\n isX = false;\n break;\n }\n }\n if (result[x] == 0) {\n if (isX) {\n result[x] = cur;\n } else {\n result[x] = next;\n }\n }\n }\n ch += 2;\n dfs(i, g);\n return;\n }\n }\n for (int x : g.get(id)) {\n if (result[x] == 0) {\n result[x] = cur;\n }\n }\n ch += 2;\n }\n\n private static boolean isBro(List a, List b) {\n for (Integer x : a) {\n for (Integer y : b) {\n if (matrix[x][y]) {\n return true;\n }\n }\n }\n return false;\n }\n\n }\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner(InputStream io) {\n br = new BufferedReader(new InputStreamReader(io));\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63427236ff758d939f65b9063e58ce05", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "// import 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\n/**\n * Created by hama_du on 2016/02/08.\n */\npublic class Main {\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int n = in.nextInt();\n int m = in.nextInt();\n int[][] graph = new int[n][n];\n for (int i = 0; i < m ; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n graph[a][b] = graph[b][a] = 1;\n }\n String ans = solve(graph);\n if (ans == null) {\n out.println(\"No\");\n } else {\n out.println(\"Yes\");\n out.println(ans);\n }\n out.flush();\n }\n\n\n static String solve(int[][] graph) {\n int n = graph.length;\n List[] cog = new List[n];\n for (int i = 0 ; i < n ; i++) {\n cog[i] = new ArrayList<>();\n }\n for (int i = 0 ; i < n ; i++) {\n for (int j = i+1 ; j < n ; j++) {\n if (graph[i][j] == 0) {\n cog[i].add(j);\n cog[j].add(i);\n }\n }\n }\n\n int[] color = new int[n];\n for (int i = 0 ; i < n ; i++) {\n if (color[i] != 0) {\n continue;\n }\n if (cog[i].size() == 0) {\n continue;\n }\n if (!dfs(i, 1, cog, color)) {\n return null;\n }\n }\n\n for (int i = 0 ; i < n ; i++) {\n for (int j = 0; j < n ; j++) {\n if (color[i] == 1 && color[j] == -1 && graph[i][j] == 1) {\n return null;\n }\n }\n }\n char[] abc = {'c','b','a'};\n StringBuilder line = new StringBuilder();\n for (int i = 0 ; i < n ; i++) {\n line.append(abc[color[i]+1]);\n }\n return line.toString();\n }\n\n\n private static boolean dfs(int now, int col, List[] cog, int[] color) {\n if (color[now] != 0) {\n return color[now] == col;\n }\n color[now] = col;\n for (int to : cog[now]) {\n if (!dfs(to, -col, cog, color)) {\n return false;\n }\n }\n return true;\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int next() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public char nextChar() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n if ('a' <= c && c <= 'z') {\n return (char) c;\n }\n if ('A' <= c && c <= 'Z') {\n return (char) c;\n }\n throw new InputMismatchException();\n }\n\n public String nextToken() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n StringBuilder res = new StringBuilder();\n do {\n res.append((char) c);\n c = next();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public int nextInt() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = next();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c-'0';\n c = next();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n long sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = next();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c-'0';\n c = next();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n static void debug(Object... o) {\n System.err.println(Arrays.deepToString(o));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "04c2df0349d2ccfb7df7649388cffc1a", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n \n public void solve() {\n Scan sn = new Scan();\n long n;\n n = sn.nextLong();\n long temp = (long)Math.sqrt(n);\n for(long i=temp ;i>=1;i--)\n {\n long te = i*i;\n long num = n;\n int count =0;\n String s = String.valueOf(num);\n for(int j=s.length()-1;j>=0;j--){\n long t = te%10;\n if(s.charAt(j)-'0'==t){\n count++;\n te = te/10;\n }\n }\n if(count==String.valueOf(i*i).length()){\n System.out.println(String.valueOf(n).length()-count);\n/*\n System.out.println(i);\n*/\n return;\n }\n }\n System.out.println(-1);\n }\n\n public static void main(String[] args) {\n Main solver = new Main();\n solver.solve();\n }\n\n class Scan {\n BufferedReader br;\n StringTokenizer st;\n\n public Scan() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\nclose", "lang_cluster": "Java", "compilation_error": true, "code_uid": "30c559a34ee3f0fb0389e265ee4cd9e4", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public void solve() {\n Scan sn = new Scan();\n long n;\n n = sn.nextLong();\n long temp = (long)Math.sqrt(n);\n for(long i=temp ;i>=1;i--)\n {\n long te = i*i;\n long num = n;\n int count =0;\n String s = String.valueOf(num);\n for(int j=s.length()-1;j>=0;j--){\n long t = te%10;\n if(s.charAt(j)-'0'==t){\n count++;\n te = te/10;\n }\n }\n if(count==String.valueOf(i*i).length()){\n System.out.println(String.valueOf(n).length()-count);\n/*\n System.out.println(i);\n*/\n return;\n }\n }\n System.out.println(-1);\n }\n\n public static void main(String[] args) {\n C962 solver = new C962();\n solver.solve();\n }\n\n class Scan {\n BufferedReader br;\n StringTokenizer st;\n\n public Scan() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4754504f5f321624933f2b23f921d252", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.Integer;\npublic class HelloWorld{\n\n public static void main(String []args){\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n String s = n + \"\";\n int ans = 20;\n for(int i = 1; i < (1< 0) {\n temp += s.charAt(j);\n count--;\n }\n }\n int num = Integer.parseInt(temp);\n double sqrt = Math.sqrt(num);\n double diff = sqrt - (int)sqrt;\n if(diff < 1e-15) {\n ans = ans < count ? ans : count;\n //System.out.println(num + \" \" + count);\n }\n ..System.out.println(temp);\n \n }\n System.out.println(ans != 20 ? ans : -1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "50667559869335cad2de7c494d36c7d0", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader() {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in), 32765);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32765);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic int[] nextIntArr(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic Integer[] nextIntegerArr(int n) {\n\t\t\tInteger[] arr = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = new Integer(this.nextInt());\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic int[][] next2DIntArr(int n, int m) {\n\t\t\tint[][] arr = new int[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tarr[i][j] = this.nextInt();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic int[] nextSortedIntArr(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextInt();\n\t\t\t}\n\t\t\tArrays.sort(arr);\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArr(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextSortedLongArr(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextInt();\n\t\t\t}\n\t\t\tArrays.sort(arr);\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic char[] nextCharArr(int n) {\n\t\t\tchar[] arr = new char[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextChar();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n\n\tpublic static InputReader scn = new InputReader();\n\tpublic static PrintWriter out = new PrintWriter(System.out);\n\n\tpublic static void main(String[] args) {\n\t\t// InputStream inputStream = System.in; // Useful when taking input other than\n\t\t// console eg file handling // check ctor of inputReader\n\t\t// To print in file use this:- out = new PrintWriter(\"destination of file\")\n\t\t// including extension\");\n\n\t\tString str = scn.next();\n\t\tlong rv = func(str, 0, Integer.parseInt(str), 0, new HashSet<>());\n\n\t\tif (rv > 20) {\n\t\t\tSystem.out.println(-1);\n\t\t} else {\n\t\t\tSystem.out.println(rv);\n\t\t}\n\t}\n\n\tpublic static long func(String str, int i, int num, int op, HashSet list) {\n\t\tif(num == -1) {\n\t\t\treturn Integer.MAX_VALUE;\n\t\t}\n\t\tint k = (int) Math.sqrt(num);\n\t\tif (k * k == num) {\n\t\t\treturn op;\n\t\t}\n\t\tif (str.length() == i) {\n\t\t\treturn Integer.MAX_VALUE;\n\t\t}\n\n\t\tlong rv = Integer.MAX_VALUE;\n\n\t\tint kk = 0;\n\t\tString s = \"\";\n\t\tfor (int x = 0; x < str.length(); x++) {\n\t\t\tif (!list.contains(x) && x != i) {\n\t\t\t\ts = s + str.charAt(x);\n\t\t\t}\n\t\t}\n\t\tif(s.length() != 0) {\n\t\t\tkk = Integer.parseInt(s);\n\t\t} else {\n\t\t\tkk = -1;\n\t\t}\n\n\n\t\tif (i < str.length() - 1 && str.charAt(i + 1) == '0') {\n\t\t\trv = func(str, i + 1, num, op, list);\n\t\t} else {\n\t\t\tlong x = func(str, i + 1, num, op, list);\n\t\t\tlist.add(i);\n\t\t\tlong y = func(str, i + 1, kk, op + 1, list);\n\t\t\tlist.remove(i);\n\t\t\trv = Math.min(x, y);\n\t\t}\n\n\t\treturn rv;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e586722316e1cf7152527aee1d29973", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class Main {\n \n \n public static void main(String arg[]) throws IOException\n {\n\n boolean leap[]=new boolean[2039];\n\n for(int i=1900;i<=2038;i++)\n {\n if((i%4==0&&i%100!=0))\n {\n \n leap[i]=true;\n \n }\n\n }\n \n leap[2000]=true;\n int d[]=new int[13];\n d[1]=d[3]=d[5]=d[7]=d[12]=d[10]=d[8]=31;\n d[4]=d[6]=d[9]=d[11]=30;\n d[2]=28;\n \n \n // BufferedReader r=new BufferedReader(new FileReader(\"testcase.txt\"));\n BufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n\n String s=r.readLine();\n s=s.replaceAll(\":\", \" \");\n StringTokenizer str=new StringTokenizer(s);\n\n\nint y1=Integer.parseInt(str.nextToken());\nint m1=Integer.parseInt(str.nextToken());\nint d1=Integer.parseInt(str.nextToken());\ns=r.readLine();\n s=s.replaceAll(\":\", \" \");\n\nstr=new StringTokenizer(s);\nint y2=Integer.parseInt(str.nextToken());\nint m2=Integer.parseInt(str.nextToken());\nint d2=Integer.parseInt(str.nextToken());\n \nif(y1>y2||(y1==y2&&m1>m2)||(y1==y2&&m1==m2&&d1>d2))\n{\n int t=y2;\n y2=y1;\n y1=t;\n t=m2;\n m2=m1;\n m1=t;\n t=d2;\n d2=d1;\n d1=t;\n}\n\n\nint days=0;\nfor(int i=y1+1;i2&&leap[y2])\n{\n days++;\n}\ndays=days+d[m1]-d1;\ndays=days+d2;\nSystem.out.println(days);\n\n}\n }\n \n \n \n \nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class Main {\n \n \n public static void main(String arg[]) throws IOException\n {\n\n boolean leap[]=new boolean[2039];\n\n for(int i=1900;i<=2038;i++)\n {\n if((i%4==0&&i%100!=0))\n {\n \n leap[i]=true;\n \n }\n\n }\n \n leap[2000]=true;\n int d[]=new int[13];\n d[1]=d[3]=d[5]=d[7]=d[12]=d[10]=d[8]=31;\n d[4]=d[6]=d[9]=d[11]=30;\n d[2]=28;\n \n \n // BufferedReader r=new BufferedReader(new FileReader(\"testcase.txt\"));\n BufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n\n String s=r.readLine();\n s=s.replaceAll(\":\", \" \");\n StringTokenizer str=new StringTokenizer(s);\n\n\nint y1=Integer.parseInt(str.nextToken());\nint m1=Integer.parseInt(str.nextToken());\nint d1=Integer.parseInt(str.nextToken());\ns=r.readLine();\n s=s.replaceAll(\":\", \" \");\n\nstr=new StringTokenizer(s);\nint y2=Integer.parseInt(str.nextToken());\nint m2=Integer.parseInt(str.nextToken());\nint d2=Integer.parseInt(str.nextToken());\n \nif(y1>y2||m1>m2||d1>d2)\n{\n int t=y2;\n y2=y1;\n y1=t;\n t=m2;\n m2=m1;\n m1=t;\n t=d2;\n d2=d1;\n d1=t;\n}\n\nint days=0;\nfor(int i=y1+1;i2&&leap[y2])\n{\n days++;\n}\ndays=days+d[m1]-d1;\ndays=days+d2;\nSystem.out.println(days);\n\n}\n }\n \n \n \n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a858631c60c6ea70fce0d14330eeaf19", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\n \n \n \npublic class Main {\n public static void main(String[] args) {\n Scanner in=new Scanner(new InputStreamReader(System.in));\n PrintWriter out=new PrintWriter(System.out);\n String d1 = in.nextLine();\n String d2 = in.nextLine();\n SimpleDateFormat format = new SimpleDateFormat(\"yyyy:MM:dd\");\n Date date1 = null;\n Date date2 = null;\n try {\n date1 = format.parse(d2);\n date2 = format.parse(d1);\n } catch (Exception e) {\n e.printStackTrace();\n }\n long difference = Math.round((double)date1.getTime()/ 24/60/60/1000 - (double)date2.getTime()/ 24/60/60/1000);\n long days = difference ;\n out.println(Math.abs(days));\n \n in.close();\n out.close();\n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "02bd49aedc9c70d1309ba35160021f48", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class Main {\n \n \n public static void main(String arg[]) throws IOException\n {\n\n boolean leap[]=new boolean[2039];\n\n for(int i=1900;i<=2038;i++)\n {\n if((i%4==0&&i%100!=0))\n {\n \n leap[i]=true;\n \n }\n\n }\n \n leap[2000]=true;\n int d[]=new int[13];\n d[1]=d[3]=d[5]=d[7]=d[12]=d[10]=d[8]=31;\n d[4]=d[6]=d[9]=d[11]=30;\n d[2]=28;\n \n \n // BufferedReader r=new BufferedReader(new FileReader(\"testcase.txt\"));\n BufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n\n String s=r.readLine();\n s=s.replaceAll(\":\", \" \");\n StringTokenizer str=new StringTokenizer(s);\n\n\nint y1=Integer.parseInt(str.nextToken());\nint m1=Integer.parseInt(str.nextToken());\nint d1=Integer.parseInt(str.nextToken());\ns=r.readLine();\n s=s.replaceAll(\":\", \" \");\n\nstr=new StringTokenizer(s);\nint y2=Integer.parseInt(str.nextToken());\nint m2=Integer.parseInt(str.nextToken());\nint d2=Integer.parseInt(str.nextToken());\n \nif(y1>y2||(y1==y2&&m1>m2)||(y1==y2&&m1==m2&&d1>d2))\n{\n int t=y2;\n y2=y1;\n y1=t;\n t=m2;\n m2=m1;\n m1=t;\n t=d2;\n d2=d1;\n d1=t;\n}\n\n\nint days=0;\nfor(int i=y1+1;i2&&leap[y2])\n{\n days++;\n}\ndays=days+d[m1]-d1;\ndays=days+d2;\nSystem.out.println(days);\n\n}\n }\n \n \n \n \nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class Main {\n \n \n public static void main(String arg[]) throws IOException\n {\n\n boolean leap[]=new boolean[2039];\n\n for(int i=1900;i<=2038;i++)\n {\n if((i%4==0&&i%100!=0))\n {\n \n leap[i]=true;\n \n }\n\n }\n \n leap[2000]=true;\n int d[]=new int[13];\n d[1]=d[3]=d[5]=d[7]=d[12]=d[10]=d[8]=31;\n d[4]=d[6]=d[9]=d[11]=30;\n d[2]=28;\n \n \n // BufferedReader r=new BufferedReader(new FileReader(\"testcase.txt\"));\n BufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n\n String s=r.readLine();\n s=s.replaceAll(\":\", \" \");\n StringTokenizer str=new StringTokenizer(s);\n\n\nint y1=Integer.parseInt(str.nextToken());\nint m1=Integer.parseInt(str.nextToken());\nint d1=Integer.parseInt(str.nextToken());\ns=r.readLine();\n s=s.replaceAll(\":\", \" \");\n\nstr=new StringTokenizer(s);\nint y2=Integer.parseInt(str.nextToken());\nint m2=Integer.parseInt(str.nextToken());\nint d2=Integer.parseInt(str.nextToken());\n \nif(y1>y2||m1>m2||d1>d2)\n{\n int t=y2;\n y2=y1;\n y1=t;\n t=m2;\n m2=m1;\n m1=t;\n t=d2;\n d2=d1;\n d1=t;\n}\n\nint days=0;\nfor(int i=y1+1;i2&&leap[y2])\n{\n days++;\n}\ndays=days+d[m1]-d1;\ndays=days+d2;\nSystem.out.println(days);\n\n}\n }\n \n \n \n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b21fb611d38c6247de4e4f83428e538d", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.text.ParseException;\nimport java.text.SimpleDateFormat;\nimport java.util.Date;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Evgeny Savinov\n */\npublic class Main {\n public static void main(String[] args) throws FileNotFoundException {\n InputStream inputStream = System.in;//new FileInputStream(\"input.txt\");\n OutputStream outputStream = System.out;//new FileOutputStream(\"output.txt\");//\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\n\nclass TaskE {\n\n public void solve(int testNumber, InputReader in, PrintWriter out)\n {\n SimpleDateFormat z = new SimpleDateFormat(\"yyyy:MM:dd\");\n z.setTimeZone(TimeZone.getTimeZone(\"GMT+8:00\"));\n Date a = null, b = null;\n try {\n a = z.parse(in.next());\n } catch (ParseException e) {\n e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\n }\n try {\n b = z.parse(in.next());\n } catch (ParseException e) {\n e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.\n }\n \n long diff = Math.abs(a.getTime() + b.getTime());\n out.println(diff / 1000 / 3600 / 24);\n \n\n\n }\n}\n\n\nclass InputReader\n{\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e4bff92824dd908037a0a43ba7c737d", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class RoadToPostOffice {\n\tpublic static void main(String[] args) {\n\t\tScanner kbd = new Scanner(System.in);\n\t\tlong finalDit; //final distance computed\n\t\tlong d = kbd.nextLong(); //distance from home to p.o.\n\t\tlong k = kbd.nextLong(); //initial distance before breaking\n\t\tlong a = kbd.nextLong(); //time he spends to drive 1km\n\t\tlong b = kbd.nextLong(); //time he spends to walk 1km on foot\n\t\tlong t = kbd.nextLong(); //time he spends to repair his car\n\t\t\n\t\tif(d <= k){\n\t\t\tSystem.out.println(a * d);\n\t\t}else{\n\t\t\tif(k * b <= k * a + t){\n\t\t\t\tlong withCar = Math.min(d, k);\n\t\t\t\tSystem.out.println(a * withCar + b * (d - WithCar));\n\t\t\t}else{\n\t\t\t\tlong carCount = d/k;\n\t\t\t\tlong ans = a * carCount * k + Math.max(carCount - 1, 0) * t;\n\t\t\t\td -= carCount * k;\n\t\t\t\tif(d * b <= d * a + t){\n\t\t\t\t\tans += d * b;\n\t\t\t\t}else{\n\t\t\t\t\tans += t + d * a;\n\t\t\t\t\tSystem.out.println(ans);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "50c31d954b6a318c839670f214dd7666", "src_uid": "359ddf1f1aed9b3256836e5856fe3466", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class RoadToPostOffice {\n\tpublic static void main(String[] args) {\n\t\tScanner kbd = new Scanner(System.in);\n\t\tlong finalDit; //final distance computed\n\t\tlong d = kbd.nextLong(); //distance from home to p.o.\n\t\tlong k = kbd.nextLong(); //initial distance before breaking\n\t\tlong a = kbd.nextLong(); //time he spends to drive 1km\n\t\tlong b = kbd.nextLong(); //time he spends to walk 1km on foot\n\t\tlong t = kbd.nextLong(); //time he spends to repair his car\n\t\t\n\t\tif(d <= k){\n\t\t\tSystem.out.println(a * d);\n\t\t}else{\n\t\t\tif(k * b <= k * a + t){\n\t\t\t\tlong withCar = Math.min(d, k);\n\t\t\t\tSystem.out.println(a * withCar + b * (d - WithCar));\n\t\t\t}else{\n\t\t\t\tlong carCount = d/k;\n\t\t\t\tlong ans = a * carCount * k + Math.max(carCount - 1, 0) * t;\n\t\t\t\td -= carCount * k;\n\t\t\t\tif(d * b <= d * a + t){\n\t\t\t\t\tans += d * b;\n\t\t\t\t}else{\n\t\t\t\t\tans += t + d * a;\n\t\t\t\t\tSystem.out.println(ans);\n\t\t\t\t}\n\t\t\t}\n\t\t}\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "62e6b1c2d03d22c411a917689f9a6519", "src_uid": "359ddf1f1aed9b3256836e5856fe3466", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\n import java.io.*;\n import java.util.*;\n public class Test{\n public static void main(String [] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(br.readLine());\n long d = Long.parseLong(st.nextToken());\n long k = Long.parseLong(st.nextToken());\n long a = Long.parseLong(st.nextToken());\n long b = Long.parseLong(st.nextToken());\n long t = Long.parseLong(st.nextToken());\n d-=k;\n long ans = k*a;\n if(k*a+t>=k*b){System.out.println(ans+d*b);}\n else{\n ans += (k*a+t)*(d/k);\n long mod = d%k;\n ans += Math.min(mod*a+t, mod*b);\n System.out.println(ans);\n }\n }\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48a0f254f48ec2d84970c1d139f51787", "src_uid": "359ddf1f1aed9b3256836e5856fe3466", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class D {\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\n\t\tlong d = sc.nextLong();\n\t\tlong k = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), t = sc.nextInt();\n\t\t\n\t\tif(k * b <= k * a + t)\n\t\t{\n\t\t\tlong withCar = Math.min(d, k);\n\t\t\tout.println(a * withCar + b * (d - withCar));\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong carCount = d / k;\n\t\t\tlong ans = a * carCount * k + Math.max(carCount - 1, 0) * t;\n\t\t\td -= carCount * k;\n\t\t\tif(d * b <= d * a + t)\n\t\t\t\tans += d * b;\n\t\t\telse\n\t\t\t\tans += t + d * a;\n\t\t\tout.println(ans);\n\t\t}\n\t\tout.flush();\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\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "26501815e367de589de013817fd21f59", "src_uid": "359ddf1f1aed9b3256836e5856fe3466", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.lang.Math;\nimport java.math.BigInteger;\n\npublic class Problem {\n\n\tint INF = -1000 * 1000 * 1000 - 100;\n\tint counter;\n\tint[] arr;\n\tint[] t;\n\n\tvoid solve() throws IOException {\n\t\tint n = rI();\n\t\tint curChar = 0;\n\t\tArrayList ansList = new ArrayList<>();\n\t\tif(n==0){\n\t\t\tansList.add('z')\n\t\t}\n\t\twhile(n>0){\n\t\t\tansList.add((char)('a'+curChar));\n\t\t\tint x = 1;\n\t\t\tint sum = 1 ;\n\t\t\twhile(n-sum>=0){\n\t\t\t\tx++;\n\t\t\t\tansList.add((char)('a'+curChar));\n\t\t\t\tsum += x;\n\t\t\t}\n\t\t\tsum-=x;\n\t\t\tn -= sum;\n\t\t\tcurChar++;\n\t\t}\n\t\tfor(char a: ansList){\n\t\t\tout.print(a);\n\t\t}\n\t}\n\n\tlong get(int r) {\n\t\tlong sum = 0;\n\t\tfor (int i = r; i >= 1; i = (i & (i + 1)) - 1) {\n\t\t\tsum += t[i];\n\t\t}\n\t\treturn sum;\n\t}\n\n\tvoid init() {\n\t\tfor (int i = 1; i < arr.length; ++i) {\n\t\t\tinc(i, arr[i]);\n\t\t}\n\t}\n\n\tvoid inc(int i, int delta) {\n\t\tfor (; i < arr.length; i = i | (i + 1)) {\n\t\t\tt[i] += delta;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tnew Problem().run();\n\t}\n\n\tboolean isLower(char a) {\n\t\treturn ((int) a) >= 97 ? true : false;\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\tRandom rnd = new Random();\n\tstatic final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n\tProblem() throws FileNotFoundException {\n\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t\ttok = new StringTokenizer(\"\");\n\t}\n\n\tlong checkBit(long mask, int bit) {\n\t\treturn (mask >> bit) & 1;\n\t}\n\n\t// ======================================================\n\n\t// ======================================================\n\tvoid run() throws IOException {\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tchar[] reverseCharArray(char[] arr) {\n\t\tchar[] ans = new char[arr.length];\n\t\tfor (int i = 0; i < arr.length; ++i) {\n\t\t\tans[i] = arr[arr.length - i - 1];\n\t\t}\n\t\treturn ans;\n\t}\n\n\tint sqrt(double m) {\n\t\tint l = 0;\n\t\tint r = 1000000000 + 9;\n\t\tint i = 1000;\n\t\twhile (r - l > 1) {\n\t\t\tint mid = (r + l) / 2;\n\t\t\tif (mid * mid > m) {\n\t\t\t\tr = mid;\n\t\t\t} else {\n\t\t\t\tl = mid;\n\t\t\t}\n\t\t}\n\t\treturn l;\n\t}\n\n\tint countPow(int m, int n) {\n\t\tint ans = 0;\n\t\twhile (m % n == 0 && m > 0) {\n\t\t\tans++;\n\t\t\tm /= n;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tlong binPow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b % 2 == 1) {\n\t\t\treturn a * binPow(a, b - 1);\n\t\t} else {\n\t\t\tlong c = binPow(a, b / 2);\n\t\t\treturn c * c;\n\t\t}\n\n\t}\n\n\tint gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n\tlong pow(long x, long k) {\n\t\tlong ans = 1;\n\t\tfor (int i = 0; i < k; ++i) {\n\t\t\tans *= x;\n\t\t}\n\t\treturn ans;\n\t}\n\n\t// ////////////////////////////////////////////////////////////////////\n\n\tString delimiter = \" \";\n\n\tString readLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n\n\tString rS() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\tString nextLine = readLine();\n\t\t\tif (null == nextLine)\n\t\t\t\treturn null;\n\n\t\t\ttok = new StringTokenizer(nextLine);\n\t\t}\n\n\t\treturn tok.nextToken(delimiter);\n\t}\n\n\tint rI() throws IOException {\n\t\treturn Integer.parseInt(rS());\n\t}\n\n\tlong rL() throws IOException {\n\t\treturn Long.parseLong(rS());\n\t}\n\n\tdouble rD() throws IOException {\n\t\treturn Double.parseDouble(rS());\n\t}\n\n\tint[] rA(int b) {\n\t\tint a[] = new int[b];\n\t\tfor (int i = 0; i < b; i++) {\n\t\t\ttry {\n\t\t\t\ta[i] = rI();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\n\tint[] readSortedIntArray(int size) throws IOException {\n\t\tInteger[] array = new Integer[size];\n\n\t\tfor (int index = 0; index < size; ++index) {\n\t\t\tarray[index] = rI();\n\t\t}\n\t\tArrays.sort(array);\n\n\t\tint[] sortedArray = new int[size];\n\t\tfor (int index = 0; index < size; ++index) {\n\t\t\tsortedArray[index] = array[index];\n\t\t}\n\n\t\treturn sortedArray;\n\t}\n\n\tint[] sortedIntArray(int size, int[] array) throws IOException {\n\t\tfor (int index = 0; index < size; ++index) {\n\t\t\tarray[index] = rI();\n\t\t}\n\t\tArrays.sort(array);\n\n\t\tint[] sortedArray = new int[size];\n\t\tfor (int index = 0; index < size; ++index) {\n\t\t\tsortedArray[index] = array[index];\n\t\t}\n\n\t\treturn sortedArray;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "435e8d1a0d64b69121e3a60de1fbf94e", "src_uid": "b991c064562704b6106a6ff2a297e64a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class R431C {\n\n FastScanner sc;\n PrintWriter out;\n\n int needMinCost;\n\n\n\n\n\n String getStringWithCostX(int x) {\n if(x == 0) {\n return \"a\";\n }\n \n StringBuilder sb = new StringBuilder();\n \n for (int i = 0; i < 26; i++) {\n if (x == 0) { break; }\n \n int cur = 0;\n double tmp = cur * (cur + 1) / 2;\n \n while ( tmp / 2 <= x) {\n cur++;\n }\n \n x -= tmp;\n \n \n char c = (char)('a' + i);\n for (int z = 0; z < cur; z++) {\n sb.append(c);\n }\n \n }\n \n return sb.toString();\n }\n\n\n public void solve() {\n needMinCost = sc.nextInt();\n System.out.println(getStringWithCostX(needMinCost));\n /*for (int i=0; i<26; i++) {\n int cnt = 1;\n\n while ((cnt+1) * cnt/2 <= needMinCost) {\n cnt++;\n }\n\n needMinCost -= cnt*(cnt-1)/2;\n\n for (int j=0; j 26) {\n i++;\n trian = i * (i + 1) / 2;\n }\n if (n == 0) {\n out.println('a');\n } else if (trian == 1) {\n StringBuilder str = new StringBuilder();\n for (char ch = 'a'; ch < 'a' + n; ch++) {\n str.append(ch).append(ch);\n }\n out.println(str.toString());\n } else {\n long t = (n / trian);\n long k = n - (trian - 1) * (n / trian);\n StringBuilder str = new StringBuilder();\n for (int j = 0; j < i + 1; j++) {\n for (char ch = 'a'; ch < 'a' + (j < 2 ? k : t); ch++) {\n str.append(ch);\n }\n }\n out.println(str.toString());\n }\n\n out.close();\n }\n\n\n private static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public String nextString() {\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 char nextChar() {\n return next().charAt(0);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dd785bb54e0f4bf51603c7ff042831b1", "src_uid": "b991c064562704b6106a6ff2a297e64a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n BThreeLevelLaser solver = new BThreeLevelLaser();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BThreeLevelLaser {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int U = in.nextInt();\n double[] E = in.nextDoubleArray(n);\n\n double ans = -1;\n for (int i = 0; i < n; i++) {\n int j = i + 1;\n int l = i + 1;\n int r = n;\n while (r - l > 1) {\n int mid = (l + r) / 2;\n if ((E[mid] - E[i]) <= U) {\n l = mid;\n } else {\n r = mid;\n }\n }\n int k = l;\n if (k != i + 1) {\n ans = Math.max(ans, (E[k] - E[j]) / (E[k] - E[i]));\n }\n }\n if (ans == -1) out.println(-1);\n else out.println(ans);\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 InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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 double[] nextDoubleArray(int size) {\n double[] array = new double[size];\n for (int i = 0; i < size; i++)\n array[i] = nextDouble();\n return array;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "53f8f6e3684a1c562e6c81a75ddfeed1", "src_uid": "4b9cf82967aa8441e9af3db3101161e9", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "package vanilla;\n\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n\n Solver solver = new Solver();\n solver.solve(in, out);\n out.close();\n }\n static class Solver {\n void solve(Scanner in, PrintWriter out) {\n\n int n = in.nextInt();\n\n ArrayList piles = new ArrayList<>();\n\n for (int i = 0; i < n; i++) {\n piles.add(in.nextInt());\n }\n\n Collections.sort(piles);\n\n if (piles.get(0).equals(piles.get(n/2))) {\n out.println(\"Bob\");\n } else {\n out.println(\"Alice\");\n }\n\n }\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6bf4a9a3a3db096f24c86e0e4db0073b", "src_uid": "4b9cf82967aa8441e9af3db3101161e9", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.FileInputStream;\nimport java.util.*;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\npublic class TaskE {\n int n;\n int[] as;\n public void solve() throws Exception{\n //Scanner sc = new Scanner(System.in);\n Scanner sc = new Scanner(new FileInputStream(\"inputs/e.in\"));\n n = sc.nextInt();\n as = new int[n];\n Map mp = new HashMap<>();\n int m = 1000;\n for(int i=0; i n/2) System.out.println(\"Bob\");\n else System.out.println(\"Alice\");\n\n }\n public static void main(String[] args) throws Exception {\n TaskE s = new TaskE();\n s.solve();\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "810056da16e56d1e9b384f24560dcc2f", "src_uid": "4b9cf82967aa8441e9af3db3101161e9", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "package vanilla;\n\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n\n Solver solver = new Solver();\n solver.solve(in, out);\n out.close();\n }\n}\n\nclass Solver {\n void solve(Scanner in, PrintWriter out) {\n\n int n = in.nextInt();\n\n ArrayList piles = new ArrayList<>();\n\n for (int i = 0; i < n; i++) {\n piles.add(in.nextInt());\n }\n\n Collections.sort(piles);\n\n if (piles.get(0).equals(piles.get(n/2))) {\n out.println(\"Bob\");\n } else {\n out.println(\"Alice\");\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9d6ec85ba5ea27e09722a3e70ef2382a", "src_uid": "4b9cf82967aa8441e9af3db3101161e9", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.stream.*;\npublic class A {\n public static void main(String[] args) {\n final Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt;\n \n int higherSquareRootOfNumber = Math.floor(Math.sqrt(n)) + 1;\n \n int higherSquareNumber = higherSquareRootOfNumber * higherSquareRootOfNumber;\n int result = higherSquareNumber - n <= higherSquareRootOfNumber\n ? higherSquareRootOfNumber * 2\n : higherSquareRootOfNumber * 2 - 1;\n \n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6217047a25518a3d42b51e14bf1f0b4d", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport javafx.util.Pair; \n\npublic class Main\n{ \n public static void main(String[] args) throws IOException \n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n int det = (int) Math.sqrt(n);\n int sqr1 = (int) Math.pow(det ,2);\n int sqr2 = (int) Math.pow(det + 1 ,2);\n int range = (sqr2 - sqr1)/2;\n \n int ans = 0;\n if(n == sqr1) ans = det * 2;\n else if(n > sqr1 + range) ans = det * 2 + 2;\n else ans = det * 2 + 1);\n System.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "990c4528e0a1ca5696d9fb00d0cf567d", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.Math;\nimport java.util.HashMap; \nimport java.util.Map; \nimport java.util.Map.Entry;\n\npublic class mainClass {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int max = 1;\n for (int i=2; i<=Math.sqrt(n); i++) {\n if (n % i == 0) {\n max = i;\n }\n }\n System.out.println(max+n/max);", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f6fd3464e83f579dba7f7bf8d28da97d", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import static java.lang.Math.ceil;\nimport static java.lang.Math.sqrt;\nimport java.util.*;\npublic class Main{\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner input=new Scanner(System.in);\n int n=input.nextInt();\n int m;\n m=(int) ceil(sqrt(n)*2);\n System.out.println(m)\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f0573fedf65c5d71c0f8fffe1e5a262f", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Main {\n static int mod=(int)1e9+7;\n static int max=0;\n public static void main(String[] args) throws Exception {\n FastReader sc = new FastReader();\n int n=sc.nextInt();\n StringBuilder sb=new StringBuilder(sc.next());\n dfs(sb,0);\n System.out.println(max);\n }\n static void dfs(StringBuilder s,int m){\n if(s.length()==1)return;\n char c='a';\n int index=-1;\n for(int i=0;ic){\n index=i;\n c=s.charAt(i);\n }\n if(i-1>=0 && s.charAt(i)-1==s.charAt(i-1) && s.charAt(i)>c){\n index=i;\n c=s.charAt(i);\n }\n }\n \n if (m + 1 > max) max = m + 1;\n StringBuilder temp = new StringBuilder(s.toString());\n dfs(temp.replace(index, index + 1, \"\"), m + 1);\n \n }\n }\n}\nclass 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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c8ffc983f0162323a01a62e90be787c6", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "inport java.util.*;\npublic class Solution {\n \n public static void count(String input) {\n StringBuilder sb = new StringBuilder();\n sb.append(input);\n \n int i = 0;\n int del = 0;\n \n while(i < sb.length()) {\n char current = sb.charAt(i);\n \n if(i+1 < sb.length() && sb.charAt(i+1) == current-1) {\n sb.deleteCharAt(i);del++;\n }\n else if(i+1 < sb.length() && sb.charAt(i+1) == current+1) {\n int j = i+1;\n char next = sb.charAt(j);\n \n while(j < sb.length() && current+1 == next) {\n next = sb.charAt(j);\n j = j+1;\n current = next;\n }\n sb.delete(i+1, j);\n del += j-(i+1);\n }\n else {\n i++;\n }\n }\n \n return del;\n }\n \n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int len = s.nextInt();\n String input = s.nextLine();\n \n count(input);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "adfccd2ec6d5687066cdc9c5a43c363c", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "import java.util.*;\n \npublic class Main {\n static Scanner sc = new Scanner(System.in);\n public static void main(String[] args){\n int Size = sc.nextInt();\n sc.nextLine();\n int FuckYouWhyDidYouFuckingGiveMeOne=0;\n if(Size==1){\n System.out.println(FuckYouWhyDidYouFuckingGiveMeOne);\n }\n return;\n String line = sc.nextLine();\n int biggestChar = 'a';\n for (int i = 0; i < line.length(); i++) {\n char currentChar = line.charAt(i);\n if(currentChar > biggestChar){\n biggestChar = currentChar;\n }\n }\n int FucksGiven = 0;\n for (int i = biggestChar; i > 'a' ; i--) {\n for (int j = 0; j < line.length(); j++) {\n if(line.charAt(j) == i){\n if(j == 0){\n if(line.charAt(1) == i-1){\n line = line.substring(j+1);\n j--;\n FucksGiven++;\n }\n }\n else if(j == line.length()-1){\n if(line.charAt(j-1) == i-1){\n line = line.substring(0,j);\n j-=2;\n FucksGiven++;\n }\n }\n else if(line.charAt(j-1) == i-1 || line.charAt(j+1) == i-1 ){\n line = line.substring(0,j)+line.substring(j+1);\n j-=2;\n FucksGiven++;\n }\n \n }\n }\n }\n System.out.println(FucksGiven);\n \n \n }\n \n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "445b6fa0df8b327c0bee2d6563563f10", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\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 ScanReader in = new ScanReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CRemoveAdjacent solver = new CRemoveAdjacent();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CRemoveAdjacent {\n char[] arr;\n long dp;\n\n public void solve(int testNumber, ScanReader in, PrintWriter out) {\n int n = in.scanInt();\n arr = new char[n + 10];\n Arrays.fill(arr, '-');\n\n\n dp = new long[n + 10][n + 10][30][30];\n\n for (int i = 0; i < n + 10; i++) {\n for (int j = 0; j < n + 10; j++) {\n for (long a[] : dp[i][j]) Arrays.fill(a, -1);\n }\n }\n for (int i = 1; i <= n; i++) arr[i] = in.scanChar();\n long ans = -1;\n ans = Math.max(ans, findIT(1, n, '-', '-'));\n out.print(ans);\n\n\n }\n\n long findIT(int l, int r, char pre, char next) {\n if (l > r) return 0;\n\n if (pre == '-') pre = 'a' + 28;\n if (next == '-') next = 'a' + 28;\n\n if (dp[l][r][pre - 'a'][next - 'a'] != -1) return dp[l][r][pre - 'a'][next - 'a'];\n\n long ans = findIT(l + 1, r, arr[l], next);\n\n ans = Math.max(ans, findIT(l, r - 1, pre, arr[r]));\n\n\n if (arr[l] == (pre + 1)) {\n ans = Math.max(ans, 1 + findIT(l + 1, r, pre, next));\n }\n\n if (arr[r] == (next + 1)) {\n ans = Math.max(ans, 1 + findIT(l, r - 1, pre, next));\n }\n\n for (int i = l; i <= r; i++) {\n if (i - 1 >= l && (arr[i - 1] + 1) == arr[i]) {\n if (i + 1 <= r)\n ans = Math.max(ans, 1 + findIT(i + 1, r, arr[i - 1], next) + findIT(l, i - 1, pre, arr[i + 1]));\n else\n ans = Math.max(ans, 1 + findIT(i + 1, r, arr[i - 1], next) + findIT(l, i - 1, pre, next));\n }\n if (i + 1 <= r && (arr[i + 1] + 1) == arr[i]) {\n\n if (i - 1 >= l)\n ans = Math.max(ans, 1 + findIT(i + 1, r, arr[i - 1], next) + findIT(l, i - 1, pre, arr[i + 1]));\n else\n ans = Math.max(ans, 1 + findIT(i + 1, r, pre, next) + findIT(l, i - 1, pre, arr[i + 1]));\n }\n }\n return dp[l][r][pre - 'a'][next - 'a'] = ans;\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 char scanChar() {\n int c = scan();\n while (isWhiteSpace(c)) c = scan();\n return (char) c;\n }\n\n public int scanInt() {\n int I = 0;\n int n = scan();\n while (isWhiteSpace(n)) n = scan();\n int neg = 1;\n if (n == '-') {\n neg = -1;\n n = scan();\n }\n while (!isWhiteSpace(n)) {\n if (n >= '0' && n <= '9') {\n I *= 10;\n I += n - '0';\n n = scan();\n }\n }\n return neg * I;\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n else return false;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "24f9e49e8763aa5aaecde401de8604d8", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class BB{\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.flush();out.close();\n }\n static class TaskE {\n final int max = 10000;\n class ship{\n long F , S , T ; int I;\n ship(long b, long c, long d, int a){F = b; S = c; T = d; I = a;}\n }\n class base{\n long F, S;\n base(long a, long b){F = a; S = b;}\n }\n ArrayList ship[];\n ArrayList base[];\n TreeSet qbase[];\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt() , m = in.nextInt();\n make(n , m , in);\n int s = in.nextInt() , b = in.nextInt(), k =in.nextInt();\n long C[] = new long[s + 1];\n ship = new ArrayList[n + 1];\n base = new ArrayList[n + 1];\n qbase = new TreeSet[n + 1];\n\n for(int i = 0; i <= n; i++){\n ship[i] = new ArrayList<>();\n base[i] = new ArrayList<>();\n qbase[i] = new TreeSet<>((A , B) -> A.F == B.F ? Long.compare(B.S , A.S) : Long.compare(A.F , B.F));\n }\n\n for(int i = 0; i < s;i ++){\n ship[in.nextInt()].add(new ship(in.nextInt() , in.nextInt(),C[i + 1] = in.nextInt(), i + 1));\n }\n\n for(int i = 0; i < b;i ++){\n base[in.nextInt()].add(new base(in.nextInt() , in.nextInt())); \n }\n\n for(int i = 0; i <= n; i++){\n Collections.sort(ship[i] , (A , B) -> Long.compare(A.S , B.S));\n }\n for(int i = 0; i <=n; i++){\n Collections.sort(base[i] , (A , B) -> A.F == B.F ? Long.compare(B.S , A.S) : Long.compare(A.F , B.F));\n int sz = base[i].size();\n long max = 0;\n for(int j = 0; j < sz; j++){\n base p = base[i].get(j);\n p.S = Math.max(max , p.S);\n max = p.S;\n qbase[i].add(p);\n }\n }\n boolean visit[] = new boolean[n + 1];\n int d[] = new int[n + 1];\n long ans[] = new long[s + 1];\n Arrays.fill(ans, -1);\n ArrayDeque ad = new ArrayDeque<>();\n for(int i = 1; i <= n; i++){\n int sz = ship[i].size();\n if(sz == 0) continue;\n int p = 0;\n Arrays.fill(visit , false); Arrays.fill(d , max); ad.clear();\n visit[i] = true; d[i] = 0; ad.add(i);\n o : while(!ad.isEmpty() && p < sz){\n int u = ad.pollFirst(); \n // System.out.println(u);\n ship pship = ship[i].get(p);\n while(d[u] > pship.S && p < sz){\n ++p; \n if(p == sz) break o;\n pship = ship[i].get(p);\n }\n int szb = base[u].size();\n for(int j = p; j < sz && szb > 0; j++){\n pship = ship[i].get(j);\n base P = qbase[u].floor(new base(pship.F, 0));\n if(P == null)continue;\n // System.out.println(i + \" \" + pship.I + \" \" + u + \" \" + P.S);\n ans[pship.I] = Math.max(ans[pship.I] ,P.S);\n }\n for(int v : ja[u]){\n if(visit[v])continue;\n d[v] = d[u] + 1; visit[v] = true;\n ad.addLast(v);\n }\n }\n }\n\n boolean can[] = new boolean[s + 1];\n for(int i = 1; i <= s; i++)can[i] = ans[i] != -1;\n\n from = new int[k]; to = new int[k];\n for(int i = 0; i < k; i++){\n from[i] = in.nextInt(); to[i] = in.nextInt();\n }\n\n for(int i = 0; i < k + 10; i++){\n for(int j = 0; j < k; j++){\n if(!can[to[j]])can[from[j]] = false;\n }\n }\n\n long rs = 0;\n for(int i = 1; i <= s; i++){\n if(!can[i])continue;\n rs += ans[i] - C[i];\n }\n\n out.println(rs);\n }\n int ja[][], from[],to[],c[];\n void make(int n,int m,InputReader in){\n ja=new int[n+1][];from=new int[m];to=new int[m];c=new int[n+1];\n for(int i=0;i>>16)]++;\n// for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n// for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];\n// int[] d = f; f = to;to = d;\n// }\n// return f;\n// }\n }\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream));\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cde15f5d90a460b4b5f21217eedf87a9", "src_uid": "dd4f9570b62ed012ad0706cbd805ea4b", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\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 Niyaz Nigmatullin\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 TaskB3 solver = new TaskB3();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB3 {\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n int[][] a = new int[n][n];\n for (int[] e : a) Arrays.fill(e, Integer.MAX_VALUE);\n for (int i = 0; i < m; i++) {\n int from = in.nextInt() - 1;\n int to = in.nextInt() - 1;\n a[from][to] = a[to][from] = 1;\n }\n for (int i = 0; i < n; i++) {\n a[i][i] = 0;\n }\n for (int k = 0; k < n; k++) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (a[i][k] != Integer.MAX_VALUE && a[k][j] != Integer.MAX_VALUE) {\n a[i][j] = Math.min(a[i][j], a[i][k] + a[k][j]);\n }\n }\n }\n }\n int s = in.nextInt();\n int b = in.nextInt();\n int k = in.nextInt();\n TaskB3.Ship[] ships = new TaskB3.Ship[s];\n for (int i = 0; i < s; i++) {\n ships[i] = new TaskB3.Ship(in.nextInt() - 1, in.nextInt(), in.nextInt(), in.nextInt());\n }\n TaskB3.Base[] bases = new TaskB3.Base[b];\n for (int i = 0; i < b; i++) {\n bases[i] = new TaskB3.Base(in.nextInt() - 1, in.nextInt(), in.nextInt());\n }\n TaskB3.DinicGraph g = new TaskB3.DinicGraph(s + 2);\n long INF = 1L << 60;\n long MAX = 1L << 40;\n int src = s;\n int tar = src + 1;\n for (int i = 0; i < s; i++) {\n TaskB3.Ship e = ships[i];\n int best = Integer.MIN_VALUE;\n for (int j = 0; j < b; j++) {\n TaskB3.Base f = bases[j];\n if (f.d > e.a || e.f < a[e.x][f.x]) continue;\n best = Math.max(best, f.g);\n }\n if (best == Integer.MIN_VALUE) {\n g.addEdge(i, tar, INF);\n g.addEdge(src, i, MAX);\n } else {\n g.addEdge(i, tar, MAX + (e.p - best));\n g.addEdge(src, i, MAX);\n }\n }\n for (int i = 0; i < k; i++) {\n int s1 = in.nextInt() - 1;\n int s2 = in.nextInt() - 1;\n g.addEdge(s1, s2, INF);\n }\n long have = g.getMaxFlow(src, tar);\n out.println(-(have - MAX * s));\n }\n\n public static class DinicGraph {\n public ArrayList[] edges;\n int[] cur;\n int[] q;\n public int[] d;\n int n;\n\n public DinicGraph(int n) {\n edges = new ArrayList[n];\n this.n = n;\n for (int i = 0; i < edges.length; i++) {\n edges[i] = new ArrayList();\n }\n q = new int[n];\n d = new int[n];\n cur = new int[n];\n }\n\n public TaskB3.DinicGraph.Edge addEdge(int from, int to, long cap) {\n TaskB3.DinicGraph.Edge e1 = new TaskB3.DinicGraph.Edge(from, to, 0, cap);\n TaskB3.DinicGraph.Edge e2 = new TaskB3.DinicGraph.Edge(to, from, 0, 0);\n e1.rev = e2;\n e2.rev = e1;\n edges[from].add(e1);\n edges[to].add(e2);\n return e1;\n }\n\n boolean bfs(int source, int target) {\n int head = 0;\n int tail = 1;\n Arrays.fill(d, Integer.MAX_VALUE);\n d[source] = 0;\n q[0] = source;\n while (head < tail) {\n int x = q[head++];\n for (int i = 0; i < edges[x].size(); i++) {\n TaskB3.DinicGraph.Edge e = edges[x].get(i);\n if (e.cap - e.flow > 0 && d[e.to] == Integer.MAX_VALUE) {\n d[e.to] = d[x] + 1;\n q[tail++] = e.to;\n if (e.to == target) {\n return true;\n }\n }\n }\n }\n return false;\n }\n\n public long dfs(int x, int target, long cMin) {\n if (x == target) {\n return cMin;\n }\n for (int i = cur[x]; i < edges[x].size(); cur[x] = ++i) {\n TaskB3.DinicGraph.Edge e = edges[x].get(i);\n if (d[e.to] != d[x] + 1 || e.cap - e.flow == 0) {\n continue;\n }\n long add = dfs(e.to, target, Math.min(cMin, e.cap - e.flow));\n if (add == 0) {\n continue;\n }\n e.flow += add;\n e.rev.flow -= add;\n return add;\n }\n return 0;\n }\n\n public long getMaxFlow(int source, int target) {\n long flow = 0;\n while (bfs(source, target)) {\n Arrays.fill(cur, 0);\n while (true) {\n long add = dfs(source, target, Integer.MAX_VALUE);\n if (add == 0) {\n break;\n }\n flow += add;\n }\n }\n return flow;\n }\n\n public static class Edge {\n public int from;\n public int to;\n public long flow;\n public long cap;\n public TaskB3.DinicGraph.Edge rev;\n\n public Edge(int from, int to, int flow, long cap) {\n super();\n this.from = from;\n this.to = to;\n this.flow = flow;\n this.cap = cap;\n }\n\n }\n\n }\n\n static class Ship {\n int x;\n int a;\n int f;\n int p;\n\n public Ship(int x, int a, int f, int p) {\n this.x = x;\n this.a = a;\n this.f = f;\n this.p = p;\n }\n\n }\n\n static class Base {\n int x;\n int d;\n int g;\n\n public Base(int x, int d, int g) {\n this.x = x;\n this.d = d;\n this.g = g;\n }\n\n }\n\n }\n\n static class FastPrinter extends PrintWriter {\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public FastPrinter(Writer out) {\n super(out);\n }\n\n }\n\n static class FastScanner extends BufferedReader {\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n public int read() {\n try {\n int ret = super.read();\n// if (isEOF && ret < 0) {\n// throw new InputMismatchException();\n// }\n// isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d9107c447011997a106a9b1b25d941a9", "src_uid": "dd4f9570b62ed012ad0706cbd805ea4b", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\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 Niyaz Nigmatullin\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 TaskB3 solver = new TaskB3();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB3 {\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n int[][] a = new int[n][n];\n for (int[] e : a) Arrays.fill(e, Integer.MAX_VALUE);\n for (int i = 0; i < m; i++) {\n int from = in.nextInt() - 1;\n int to = in.nextInt() - 1;\n a[from][to] = a[to][from] = 1;\n }\n for (int i = 0; i < n; i++) {\n a[i][i] = 0;\n }\n for (int k = 0; k < n; k++) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (a[i][k] != Integer.MAX_VALUE && a[k][j] != Integer.MAX_VALUE) {\n a[i][j] = Math.min(a[i][j], a[i][k] + a[k][j]);\n }\n }\n }\n }\n int s = in.nextInt();\n int b = in.nextInt();\n int k = in.nextInt();\n TaskB3.Ship[] ships = new TaskB3.Ship[s];\n for (int i = 0; i < s; i++) {\n ships[i] = new TaskB3.Ship(in.nextInt() - 1, in.nextInt(), in.nextInt(), in.nextInt());\n }\n TaskB3.Base[] bases = new TaskB3.Base[b];\n for (int i = 0; i < b; i++) {\n bases[i] = new TaskB3.Base(in.nextInt() - 1, in.nextInt(), in.nextInt());\n }\n TaskB3.DinicGraph g = new TaskB3.DinicGraph(s + 2);\n long INF = 1L << 60;\n long MAX = 1L << 40;\n int src = s;\n int tar = src + 1;\n for (int i = 0; i < s; i++) {\n TaskB3.Ship e = ships[i];\n int best = Integer.MIN_VALUE;\n for (int j = 0; j < b; j++) {\n TaskB3.Base f = bases[j];\n if (f.d > e.a || e.f < a[e.x][f.x]) continue;\n best = Math.max(best, f.g);\n }\n if (best == Integer.MIN_VALUE) {\n g.addEdge(i, tar, INF);\n g.addEdge(src, i, MAX);\n } else {\n g.addEdge(i, tar, MAX + (e.p - best));\n g.addEdge(src, i, MAX);\n }\n }\n for (int i = 0; i < k; i++) {\n int s1 = in.nextInt() - 1;\n int s2 = in.nextInt() - 1;\n g.addEdge(s1, s2, INF);\n }\n long have = g.getMaxFlow(src, tar);\n out.println(-(have - MAX * s));\n }\n\n public static class DinicGraph {\n public ArrayList[] edges;\n int[] cur;\n int[] q;\n public int[] d;\n int n;\n\n public DinicGraph(int n) {\n edges = new ArrayList[n];\n this.n = n;\n for (int i = 0; i < edges.length; i++) {\n edges[i] = new ArrayList();\n }\n q = new int[n];\n d = new int[n];\n cur = new int[n];\n }\n\n public TaskB3.DinicGraph.Edge addEdge(int from, int to, long cap) {\n TaskB3.DinicGraph.Edge e1 = new TaskB3.DinicGraph.Edge(from, to, 0, cap);\n TaskB3.DinicGraph.Edge e2 = new TaskB3.DinicGraph.Edge(to, from, 0, 0);\n e1.rev = e2;\n e2.rev = e1;\n edges[from].add(e1);\n edges[to].add(e2);\n return e1;\n }\n\n boolean bfs(int source, int target) {\n int head = 0;\n int tail = 1;\n Arrays.fill(d, Integer.MAX_VALUE);\n d[source] = 0;\n q[0] = source;\n while (head < tail) {\n int x = q[head++];\n for (int i = 0; i < edges[x].size(); i++) {\n TaskB3.DinicGraph.Edge e = edges[x].get(i);\n if (e.cap - e.flow > 0 && d[e.to] == Integer.MAX_VALUE) {\n d[e.to] = d[x] + 1;\n q[tail++] = e.to;\n if (e.to == target) {\n return true;\n }\n }\n }\n }\n return false;\n }\n\n public long dfs(int x, int target, long cMin) {\n if (x == target) {\n return cMin;\n }\n for (int i = cur[x]; i < edges[x].size(); cur[x] = ++i) {\n TaskB3.DinicGraph.Edge e = edges[x].get(i);\n if (d[e.to] != d[x] + 1 || e.cap - e.flow == 0) {\n continue;\n }\n long add = dfs(e.to, target, Math.min(cMin, e.cap - e.flow));\n if (add == 0) {\n continue;\n }\n e.flow += add;\n e.rev.flow -= add;\n return add;\n }\n return 0;\n }\n\n public long getMaxFlow(int source, int target) {\n long flow = 0;\n while (bfs(source, target)) {\n Arrays.fill(cur, 0);\n while (true) {\n long add = dfs(source, target, Long.MAX_VALUE);\n if (add == 0) {\n break;\n }\n flow += add;\n }\n }\n return flow;\n }\n\n public static class Edge {\n public int from;\n public int to;\n public long flow;\n public long cap;\n public TaskB3.DinicGraph.Edge rev;\n\n public Edge(int from, int to, int flow, long cap) {\n super();\n this.from = from;\n this.to = to;\n this.flow = flow;\n this.cap = cap;\n }\n\n }\n\n }\n\n static class Ship {\n int x;\n int a;\n int f;\n int p;\n\n public Ship(int x, int a, int f, int p) {\n this.x = x;\n this.a = a;\n this.f = f;\n this.p = p;\n }\n\n }\n\n static class Base {\n int x;\n int d;\n int g;\n\n public Base(int x, int d, int g) {\n this.x = x;\n this.d = d;\n this.g = g;\n }\n\n }\n\n }\n\n static class FastPrinter extends PrintWriter {\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public FastPrinter(Writer out) {\n super(out);\n }\n\n }\n\n static class FastScanner extends BufferedReader {\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n public int read() {\n try {\n int ret = super.read();\n// if (isEOF && ret < 0) {\n// throw new InputMismatchException();\n// }\n// isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c8485e4b670014616f0d0aa42d4bc05d", "src_uid": "dd4f9570b62ed012ad0706cbd805ea4b", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main{\n\tstatic class base implements Comparable{\n\t\tint d,g;\n\t\tbase(int dd,int gg){\n\t\t\td=dd;g=gg;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(base o) {\n\t\t\treturn d-o.d;\n\t\t}\n\t\t\n\t}\n\tstatic int inf=(int)1e9+7;\n\tstatic int[][]adj;\n\t\n\tstatic int V, s, t;static long res[][];\t\t\t//input\n\tstatic ArrayList[] adjList;\t//input\n\tstatic int[] ptr, dist;\n\t\n\tstatic long dinic()\t\t\t\t\t\t//O(V^2E)\n\t{\n\t\tlong mf = 0;\n\t\twhile(bfs())\n\t\t{\n\t\t\tptr = new int[V];\n\t\t\tlong f;\n\t\t\twhile((f = dfs(s, inf)) != 0)\n\t\t\t\tmf += f;\n\t\t}\n\t\treturn mf;\n\t}\n\t\n\t\n\tstatic boolean bfs()\n\t{\n\t\tdist = new int[V];\n\t\tArrays.fill(dist, -1);\n\t\tdist[s] = 0;\n\t\tQueue q = new LinkedList();\n\t\tq.add(s);\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tint u = q.remove();\n\t\t\tif(u == t)\n\t\t\t\treturn true;\n\t\t\tfor(int v: adjList[u])\n\t\t\t\tif(dist[v] == -1 && res[u][v] > 0)\n\t\t\t\t{\n\t\t\t\t\tdist[v] = dist[u] + 1;\n\t\t\t\t\tq.add(v);\n\t\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tstatic long dfs(int u, long flow)\n\t{\n\t\tif(u == t)\n\t\t\treturn flow;\n\t\tfor(int i = ptr[u]; i < adjList[u].size(); i = ++ptr[u])\n\t\t{\n\t\t\tint v = adjList[u].get(i);\n\t\t\tif(dist[v] == dist[u] + 1 && res[u][v] > 0)\n\t\t\t{\n\t\t\t\tlong f = dfs(v, Math.min(flow, res[u][v]));\n\t\t\t\tif(f > 0)\n\t\t\t\t{\n\t\t\t\t\tres[u][v] -= f;\n\t\t\t\t\tres[v][u] += f;\n\t\t\t\t\treturn f;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception{\n\t\tMScanner sc=new MScanner(System.in);\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tint n=sc.nextInt(),m=sc.nextInt();\n\t\tadj=new int[n][n];\n\t\tfor(int []i:adj)Arrays.fill(i, inf);\n\t\tfor(int i=0;i x[1]-y[1]);\n\t\t\n\t\tTreeSet[]planets=new TreeSet[n];\n\t\tfor(int i=0;i();\n\t\t}\n\t\tfor(int i=0;icurFuel)continue;\n\t\t\t\t\n\t\t\t\twhile(!planets[p].isEmpty() && curAtt>=planets[p].first().d) {\n\t\t\t\t\tmaxSoFar[p]=Math.max(maxSoFar[p], planets[p].pollFirst().g);\n\t\t\t\t}\n\t\t\t\tprofit=Math.max(profit, maxSoFar[p]);\n\t\t\t\t\n\t\t\t}\n\t\t\tmaxProfit[spaceShips[i][4]]=profit-curPrice;\n\t\t}\n\t\tlong ans=0;\n\t\t\n\t\tHashSetdep=new HashSet();\n\t\tint[][]depend=new int[k][2];\n\t\tfor(int i=0;i();\n\t\t\n\t\tt=V-1;\n\t\tHashMapids=new HashMap<>();\n\t\tint id=1;\n\t\t\n\t\tfor(int i=0;i=0) {\n\t\t\t\t\tint curID=ids.get(i);\n\t\t\t\t\tadjList[s].add(curID);\n\t\t\t\t\tadjList[curID].add(s);\n\t\t\t\t\tres[s][curID]=maxProfit[i];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tint curID=ids.get(i);\n\t\t\t\t\tadjList[t].add(curID);\n\t\t\t\t\tadjList[curID].add(t);\n\t\t\t\t\tres[curID][t]=-maxProfit[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tans+=Math.max(0, maxProfit[i]);\n\t\t}\n\t\tpw.println(ans-dinic());\n\t\tpw.flush();\n\t}\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n \n\t\tpublic MScanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n \n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int[] intArr(int n) throws IOException {\n\t int[]in=new int[n];for(int i=0;i= '2' && ch <= '9') return ch - '0';\n //\u00abT\u00bb, \u00abJ\u00bb, \u00abQ\u00bb, \u00abK\u00bb \u0438 \u00abA\u00bb\n if (ch == 'T') return 10;\n if (ch == 'J' && (ch0 == 'C' || ch0 == 'D' || ch0 == 'H' || ch0 == 'S')) return 11;\n if (ch == 'Q') return 12;\n if (ch == 'K') return 13;\n if (ch == 'A') return 14;\n return 15;\n }\n int getSuite(String input) {\n char ch = input.charAt(0);\n char ch0 = input.charAt(1);\n //(ch0 == 'C' || ch0 == 'D' || ch0 == 'H' || ch0 == 'S')) return 11;\n if (ch0 == 'C') return 0;\n if (ch0 == 'D') return 1;\n if (ch0 == 'H') return 2;\n if (ch0 == 'S') return 3;\n if (ch0 == '1') return 4;\n if (ch0 == '2') return 5;\n throw new RuntimeException();\n }\n String cardToString(Card card) {\n String ans = \"\";\n if (card.value >= 2 && card.value <= 9) {\n ans += Integer.toString(card.value);\n } else if (card.value == 10) {\n ans += \"T\";\n } else if (card.value == 11) {\n ans += \"J\";\n } else if (card.value == 12) {\n ans += \"Q\";\n } else if (card.value == 13) {\n ans += \"K\";\n } else if (card.value == 14) {\n ans += \"A\";\n } else {\n throw new RuntimeException();\n }\n ans += toSuite(card.suite);\n return ans ;\n }\n\n private String toSuite(int suite) {\n char s[] = new char[] {'C', 'D', 'H', 'S'};\n return Character.toString(s[suite]);\n }\n\n void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n Card table[][] = new Card[n][m];\n Set set = new HashSet ();\n\n Vector x = new Vector () ;\n Vector y = new Vector() ;\n Vector num = new Vector () ;\n for (int i = 0; i < n; ++i) {\n for (int j =0 ; j < m; ++j) {\n table[i][j] = new Card(nextToken());\n set.add(table[i][j]);\n if (table[i][j].value == 15) {\n x.add(j);\n y.add(i);\n num.add(table[i][j].suite == 4 ? 1 : 2);\n }\n }\n }\n\n if (x.size() == 0) {\n int a[] = new int[4];\n if (goodTable(table, a)) {\n out.println(\"Solution exists.\");\n out.println(\"There are no jokers.\");\n out.println(\"Put the first square to (\" + (a[1] + 1) + \", \" + (a[0] + 1) + \").\");\n out.println(\"Put the second square to (\"+(a[3]+1)+\", \"+(a[2]+1)+\").\");\n } else {\n out.println(\"No solution.\");\n }\n } else {\n if (x.size() == 1) {\n int a[] = new int[4];\n for (int val = 2; val <= 14; ++val) {\n for (int suite = 0; suite <= 4; ++suite) {\n if (!set.contains(new Card(val, suite))) {\n table[y.get(0)][x.get(0)] = new Card(val, suite);\n if (goodTable(table, a)) {\n out.println(\"Solution exists.\");\n out.println(\"Replace J\" + (num.get(0)) + \" with \" + cardToString(new Card(val, suite)) + \".\");\n out.println(\"Put the first square to (\" + (a[1] + 1) + \", \" + (a[0] + 1) + \").\");\n out.println(\"Put the second square to (\"+(a[3]+1)+\", \"+(a[2]+1)+\").\");\n return;\n }\n }\n }\n }\n out.print(\"No solution.\");\n } else {\n int a[] = new int[4];\n for (int val = 2; val <= 14; ++val) {\n for (int suite = 0; suite <= 3; ++suite) {\n if (!set.contains(new Card(val, suite))) {\n table[y.get(0)][x.get(0)] = new Card(val, suite);\n for (int val0 = 2; val0 <= 14; val0 ++) {\n for (int suite0 = 0; suite0 <= 3; ++suite0) {\n if (!set.contains(new Card(val0, suite0)) && !(new Card(val0, suite0)).equals(table[y.get(0)][x.get(0)])){\n table[y.get(1)][x.get(1)] = new Card(val0, suite0);\n if (goodTable(table, a)) {\n out.println(\"Solution exists.\");\n Card card0 = table[y.get(0)][x.get(0)];\n Card card1 = table[y.get(1)][x.get(1)];\n //Replace J1 with x and J2 with y.\n out.println(\"Replace J1 with \" + (cardToString((num.get(0)==1?card0:card1))) + \" and J2 with \" + (cardToString((num.get(0)==2?card0:card1))) + \".\");\n out.println(\"Put the first square to (\" + (a[1] + 1) + \", \" + (a[0] + 1) + \").\");\n out.println(\"Put the second square to (\"+(a[3]+1)+\", \"+(a[2]+1)+\").\");\n return;\n }\n }\n }\n }\n }\n }\n }\n out.print(\"No solution.\");\n }\n }\n\n\n\n }\n boolean goodTable(Card[][] table, int [] positions) {\n boolean ok = false;\n for (int Y = 0; Y < table.length - 2; ++Y) {\n for (int X = 0; X < table[0].length - 2; ++X) {\n for(int U = Y ; U < table.length - 2 ; ++U)\n for (int V = X ; V < table[0].length - 2; ++V) {\n if (U - Y < 3 && V - X < 3) continue;\n if (goodSquare(X, Y, table) && goodSquare(V, U, table)) {\n positions[0] = X;\n positions[1] = Y;\n positions[2] = V;\n positions[3] = U;\n return true;\n }\n }\n }\n }\n return false;\n }\n boolean goodSquare(int X, int Y, Card[][] table) {\n Set suites = new HashSet () ;\n Set values = new HashSet () ;\n for (int dx = 0; dx < 3; ++dx) {\n for (int dy = 0; dy < 3; ++dy) {\n suites.add(table[Y + dy][X + dx].suite);\n values.add(table[Y + dy][X + dx].value);\n }\n }\n return suites.size() == 1 || values.size() == 9;\n }\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 /*out = new PrintWriter(\"input.txt\");\n out.println(100000);\n for (int i =0 ; i < 100000; ++i) {\n out.print(\"0 \");\n }\n out.close();*/\n br = new BufferedReader(new InputStreamReader(System.in));\n //br = new BufferedReader(new FileReader(\"input.txt\"));\n st = null;\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "31974bde25ec14ecab36dae466b83df1", "src_uid": "b3f29d9c27cbfeadb96b6ac9ffd6bc8f", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "\n\nimport java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class D {\n static Point Fst;\n static Point Snd;\n\n public static int rank(char x) {\n if (Character.isDigit(x))\n return x - '0';\n switch (x) {\n case 'A':\n return 0;\n case 'K':\n return 1;\n case 'Q':\n return 10;\n case 'J':\n return 11;\n default:\n return 12;\n }\n }\n\n public static int suite(char x) {\n if (Character.isDigit(x))\n return x - '0';\n switch (x) {\n case 'S':\n return 0;\n case 'C':\n return 1;\n case 'H':\n return 2;\n default:\n return 3;\n }\n }\n\n public static boolean Can(Card[][] A) {\n int n = A.length;\n int m = A[0].length;\n boolean[][] V = new boolean[n][m];\n for (int i = 0; i + 3 <= n; i++)\n for (int j = 0; j + 3 <= m; j++) {\n int[] S = new int[4];\n int[] R = new int[13];\n int s = 0;\n int r = 0;\n for (int k = 0; k < 3; k++)\n for (int l = 0; l < 3; l++) {\n S[A[i + k][j + l].suite]++;\n R[A[i + k][j + l].rank]++;\n }\n for (int k = 0; k < 4; k++)\n if (S[k] != 0)\n s++;\n for (int k = 0; k < 13; k++)\n if (R[k] > 1)\n r++;\n V[i][j] = (s == 1) | (r == 0);\n }\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++) {\n for (int k = i; k < n; k++)\n for (int l = j; l < n; l++) {\n if (k < i + 3 && l < j + 3)\n continue;\n if (V[i][j] && V[k][l]) {\n Fst = new Point(i + 1, j + 1);\n Snd = new Point(k + 1, l + 1);\n return true;\n }\n }\n }\n return false;\n }\n\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n char[] C = new char[13];\n C[0] = 'A';\n C[1] = 'K';\n C[10] = 'Q';\n C[11] = 'J';\n C[12] = 'T';\n for (int i = 2; i < 10; i++)\n C[i] = (char) (i + '0');\n char[] Su = new char[4];\n Su[0] = 'S';\n Su[1] = 'C';\n Su[2] = 'H';\n Su[3] = 'D';\n String[] S = in.readLine().split(\" \");\n int n = Integer.parseInt(S[0]);\n int m = Integer.parseInt(S[1]);\n Card[][] A = new Card[n][m];\n boolean[][] Done = new boolean[4][13];\n Point[] J = new Point[2];\n int jo = 0;\n for (int i = 0; i < n; i++) {\n S = in.readLine().split(\" \");\n for (int j = 0; j < m; j++) {\n A[i][j] = new Card(rank(S[j].charAt(0)), suite(S[j].charAt(1)));\n Done[A[i][j].suite][A[i][j].rank] = true;\n if (A[i][j].rank == 11) {\n J[jo++] = new Point(i, j);\n }\n }\n }\n if (jo == 0) {\n if (Can(A)) {\n System.out.println(\"Solution exists.\\nThere are no jokers.\");\n System.out.println(\"Put the first square to (\" + Fst.x + \", \"\n + Fst.y + \").\");\n System.out.println(\"Put the second square to (\" + Snd.x + \", \"\n + Snd.y + \").\");\n } else\n System.out.println(\"No solution.\");\n } else {\n if (jo == 1) {\n int j1 = A[J[0].x][J[0].y].suite;\n for (int i = 0; i < 4; i++)\n for (int j = 0; j < 13; j++) {\n if (Done[i][j])\n continue;\n A[J[0].x][J[0].y] = new Card(j, i);\n if (Can(A)) {\n System.out.println(\"Solution exists.\");\n System.out.println(\"Replace J\" + j1 + \" with \"\n + C[j] + Su[i] + \".\");\n System.out.println(\"Put the first square to (\"\n + Fst.x + \", \" + Fst.y + \").\");\n System.out.println(\"Put the second square to (\"\n + Snd.x + \", \" + Snd.y + \").\");\n System.exit(0);\n }\n }\n System.out.println(\"No solution.\");\n } else if (jo == 2) {\n int j1 = A[J[0].x][J[0].y].suite;\n int j2 = A[J[1].x][J[1].y].suite;\n for (int i = 0; i < 4; i++)\n for (int j = 0; j < 13; j++)\n for (int k = 0; k < 4; k++)\n for (int l = 0; l < 13; l++) {\n if (Done[i][j] || Done[k][l])\n continue;\n A[J[0].x][J[0].y] = new Card(j, i);\n A[J[1].x][J[1].y] = new Card(l, k);\n if (Can(A)) {\n System.out.println(\"Solution exists.\");\n System.out.println(\"Replace J\" + j1\n + \" with \" + C[j] + Su[i] + \".\");\n System.out.println(\"Replace J\" + j2\n + \" with \" + C[l] + Su[k] + \".\");\n System.out\n .println(\"Put the first square to (\"\n + Fst.x\n + \", \"\n + Fst.y\n + \").\");\n System.out\n .println(\"Put the second square to (\"\n + Snd.x\n + \", \"\n + Snd.y\n + \").\");\n System.exit(0);\n }\n }\n System.out.println(\"No solution.\");\n }\n }\n }\n}\n\nclass Card {\n int rank;\n int suite;\n\n public Card(int x, int y) {\n rank = x;\n suite = y;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "40b0914c394c313ffb7342eeee4d9ff5", "src_uid": "b3f29d9c27cbfeadb96b6ac9ffd6bc8f", "difficulty": 2200.0} {"lang": "Java 6", "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 set = new HashSet();\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 set = new HashSet();\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 set = new HashSet();\n\t\tfor(int i=x;i p = new ArrayList();\n for(int i=0;i= 3 || Math.abs(x/1000-y/1000) >=3)\n {\n xx[0] = x/1000;xx[1] = y/1000;\n yy[0] = x%1000;yy[1] = y%1000;\n return true;\n }\n }\n\n return false;\n }\n \n void solve()\n {\n int n = sc.nextInt(), m = sc.nextInt();\n HashMap val = new HashMap();\n xx = new int[2];\n yy = new int[2];\n\n String [] suit = new String[]{\"C\", \"D\", \"H\", \"S\"};\n String [] rank = new String[]{\"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"T\", \"Q\", \"K\", \"A\"};\n HashSet all = new HashSet();\n for(int i=0;i=3){\n\t\t\t\tif(have[4]>0){\n\t\t\t\t\thave[4]--;\n\t\t\t\t\tx-=4;\n\t\t\t\t}\n\t\t\t\telse if(have[2]>0){\n\t\t\t\t\thave[2]--;\n\t\t\t\t\tx-=2;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(x>0)\n\t\t\t\tgrp[x]++;\n\t\t}\n\t\twhile(grp[2]>0){\n\t\t\tif(have[2]>0){\n\t\t\t\thave[2]--;\n\t\t\t\tgrp[2]--;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(have[4]>0){\n\t\t\t\t\tgrp[2]--;\n\t\t\t\t\thave[4]--;\n\t\t\t\t\thave[1]++;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tgrp[2]--;\n\t\t\t\t\tgrp[1]+=2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(grp[1]>have[1]+have[2]+2*have[4])\n\t\t\tSystem.out.println(\"NO\");\n\t\telse\n\t\t\tSystem.out.println(\"YES\");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "64db62e17d48666bfcbe0479382d2b2c", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class B {\n void solve(BufferedReader in) throws Exception {\n int[] xx = toInts(in.readLine());\n int n = xx[0], k = xx[1];\n int[] a = toInts(in.readLine());\n int fours = n;\n int twos = 2*n;\n int ones = 0;\n for(int y: a) {\n int x = y;\n int sub4 = Math.min(x/4, fours);\n fours -= sub4;\n x -= sub4*4;\n int sub2 = Math.min(x/2, twos);\n twos -= sub2;\n x -= sub2*2;\n if(x>0) {\n if(x == 1 && ones != 0) {\n x = 0;\n ones--;\n }else if(x <= 2 && twos != 0) {\n twos--;\n x = 0;\n }else if(x <= 4 && fours != 0) {\n\n fours--;\n if(x == 2) ones++;\n if(x == 1) twos++;\n x = 0;\n }\n }\n if(x > 0) {\n System.out.println(\"NO\");\n return;\n } }\n System.out.println(\"YES\");\n }\n int toInt(String s) {return Integer.parseInt(s);}\n int[] toInts(String s) {\n String[] a = s.split(\" \");\n int[] o = new int[a.length];\n for(int i = 0; i= '0' && c <= '9')\n {\n res = res * 10 + c - '0';\n c = read();\n }\n return negate ? -res : res;\n }\n\n long readLong() throws java.io.IOException\n {\n long res = 0;\n byte c;\n while ((c = read()) <= ' ') ;\n boolean negate = c == '-';\n if (negate) c = read();\n while (c >= '0' && c <= '9') {\n res = res * 10 + c - '0';\n c = read();\n }\n return negate ? -res : res;\n }\n\n double readDouble() throws java.io.IOException\n {\n byte c;\n while ((c = read()) <= ' ');\n boolean negate = c == '-';\n if (negate)\n c = read();\n int power = 0;\n long res = 0;\n boolean dot_flag = false;\n for (;(c >= '0' && c <= '9') || c == '.'; c = read())\n {\n if (dot_flag)\n power++;\n if (c == '.')\n dot_flag = true;\n else\n res = res * 10 + c - '0';\n }\n double ret = res / Math.pow(10, power);\n return negate ? -ret : ret;\n }\n\n // skip defines whether ' ', '\\n', '\\r' must be skipped in readChar method\n char readChar(boolean skip) throws java.io.IOException\n {\n if (skip)\n {\n byte c;\n while ((c = read()) == ' ' || c == '\\n' || c == '\\r');\n return (char) c;\n }\n return (char) read();\n }\n\n // skip defines whether current string must be skipped in readString and readText methods\n\n /* If exact length is known, in terms of efficiency\n it is better to specify it while using readText, readString and readWord methods */\n\n String readWord() throws java.io.IOException\n {\n byte c;\n while ((c = read()) == '\\n' || c == ' ' || c == '\\r');\n StringBuilder s = new StringBuilder();\n s.append((char)c);\n for (;(c = read()) != '\\n' && c != ' ' && c != '\\r' && c != 0; s.append((char)c));\n return s.toString();\n }\n\n String readWord(int LEN) throws java.io.IOException\n {\n byte[] s = new byte[LEN];\n byte c;\n while ((c = read()) == '\\n' || c == ' ' || c == '\\r');\n s[0] = c;\n for (int i = 1; (c = read()) != ' ' && c != '\\n' && c != '\\r' && c != 0; s[i++] = c);\n return new String(s);\n }\n\n String readString(boolean skip, int LEN) throws java.io.IOException\n {\n byte[] s = new byte[LEN];\n byte c;\n if (skip)\n while ((c = read()) != '\\n');\n for (int i = 0; (c = read()) != '\\n' && c != '\\r' && c != 0; s[i++] = c);\n read();\n return new String(s);\n }\n\n String readString(boolean skip) throws java.io.IOException\n {\n StringBuilder s = new StringBuilder(\"\");\n byte c;\n if (skip)\n while ((c = read()) != '\\n');\n for (;(c = read()) != '\\n' && c != '\\r' && c != 0; s.append((char)c));\n read();\n return s.toString();\n }\n\n String readText(boolean skip, int LEN) throws java.io.IOException\n {\n byte[] s = new byte[LEN];\n byte c;\n if (skip)\n while ((c = read()) != '\\n');\n for (int i = 0; (c = read()) != 0; s[i++] = c);\n return new String(s);\n }\n\n String readText(boolean skip) throws java.io.IOException\n {\n StringBuilder s = new StringBuilder(\"\");\n byte c;\n if (skip)\n while ((c = read()) != '\\n');\n for (;(c = read()) != 0; s.append((char)c));\n return s.toString();\n }\n }\n\n\n public static void main(String args[]) throws IOException\n {\n Scan in = new Scan(System.in);\n int n = in.readInt(), k = in.readInt(), l = 2 * n, c4 = n, c2 = 0, c1 = 0;\n for (int i = 0; i < k; i++)\n {\n int a = in.readInt();\n while (a > 0 && l > 0)\n {\n l--;\n a -= 2;\n }\n while (a > 2 && c4 > 0)\n {\n a -= 4;\n c4--;\n }\n while (a > 1 && c2 > 0)\n {\n a -= 2;\n c2--;\n }\n while (a > 1 && c4 > 0)\n {\n a -= 2;\n c4--;\n c1++;\n }\n while (a > 0 && c1 > 0)\n {\n a--;\n c1--;\n }\n while (a > 0 && c2 > 0)\n {\n a--;\n c2--;\n }\n while (a > 0 && c4 > 0)\n {\n a--;\n c4--;\n c2++;\n }\n if (a > 0)\n {\n System.out.println(\"NO\");\n return;\n }\n }\n System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4c9467419908fb90355eac4d70ce224", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class cf428_b\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int pair = 2*n;\n int four = n;\n for (int j = 0; j < k; j++)\n {\n int next = sc.nextInt();\n while(next >= 4 && four > 0)\n {\n next-=4;\n four--;\n }\n if (next%4 == 3 && four > 0)\n {\n next-=3;\n four--;\n }\n if (next%4 == 1 && four > 0)\n {\n next--;\n four--;\n pair++;\n }\n while(next >= 2 && pair > 0)\n {\n next-=2;\n pair--;\n }\n if (next == 1 && pair > 0)\n {\n next--;\n pair--;\n }\n if (next > 0)\n {\n System.out.println(\"NO\");\n System.exit(0);\n }\n }\n System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "77699b30bfa22b2bc0cdfd1ad6a469bc", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import com.sun.deploy.util.ArrayUtil;\n\nimport java.util.*;\n\npublic class AbondonedSentimentPast {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int k = scanner.nextInt();\n Integer[] a, b;\n a = new Integer[n];\n b = new Integer[k];\n for(int i = 0; i < n; i++) {\n a[i] = scanner.nextInt();\n }\n for(int i = 0; i < k; i++) {\n b[i] = scanner.nextInt();\n }\n Arrays.sort(b, Collections.reverseOrder());\n int j= 0;\n for(int i = 0; i < n; i++) {\n if (a[i] == 0) {\n a[i] = b[j++];\n }\n }\n boolean ans = false;\n for(int i = 0; i < n-1; i++) {\n if (a[i] > a[i+1])\n ans = true;\n }\n if (ans) {\n System.out.println(\"Yes\");\n }\n else {\n System.out.println(\"No\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e4d4093cdeaff273e7031d7dee2e8e31", "src_uid": "40264e84c041fcfb4f8c0af784df102a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class MissingSequence{\n public static void main(String args[]) {\n\t Scanner scanner = new Scanner(System.in);\n\t int parentLength = scanner.nextInt();\n\t int childLength = scanner.nextInt();\n\t int[] parent = new int[100];\n\t int[] child = new int[100];\n\t for(int i=0;i 2) {\n System.out.println(\"Yes\");\n }\n else if(three.length == 1){\n if (two[k-1] > three[0] || two[k+1] < three[0]){\n System.out.println(\"Yes\");\n }\n }\n else {\n System.out.println(\"No\");\n }\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "24ec22f284cb4138a5620d9bcea0e86c", "src_uid": "40264e84c041fcfb4f8c0af784df102a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class abandoned {\n static void comparetwo(int[] arr,int[] mix,int k,int jusval){\n if(k>1){\n System.out.println(\"Yes\");\n return;\n }\n else{\n int high;\n int low;\n if(jusval>0 && arr[arr.length-1]!=0){\n low = jusval-1;\n high = jusval+1;\n if(arr[low]=arr[i+1]){\n kval++;\n break;\n }\n }\n if(kval==0){\n System.out.println(\"No\");\n return;\n }\n else{\n System.out.println(\"Yes\");\n return;\n }\n \n }\n else{\n System.out.println(\"Yes\");\n return;\n }\n }\n else if (arr[arr.length-1]==0){\n low = jusval-1;\n if(arr[low]= '0' && c <= '9');\n\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.') {\n while ((c = read()) >= '0' && c <= '9') {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) {\n buffer[0] = -1;\n }\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead) {\n fillBuffer();\n }\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null) {\n return;\n }\n din.close();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bdd19eb22e627effc85fd0739f3008d3", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Task894 {\n\tpublic static void main(String[] args){\n\t\tint prime = 1000000007;\n\t\tint order = 500000003;\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tlong m = sc.nextInt();\n\t\tlong k = sc.nextInt(); //irrelevant infromation\n\t\t\n\t\tm = m-1 % order;\n\t\tn = n-1 % order;\t\t\n\t\tlong exponent = m * n % order;\n\t\t\n\t\tlong ans = 1;\n\t\tfor(int i = 1; i <= exponent; i++){\n\t\t\tans = 2 * ans;\n\t\t\tans %= prime;\n\t\t}\n\t\t\n\t\tSystem.out.print(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1fcf0a028459fe903c62edeecdd8732b", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main\n{\n static class Reader \n { \n private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} \n public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} \n public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} \n public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} \n public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} \n public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} \n public double d() throws IOException {return Double.parseDouble(s()) ;}\n public boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; } \n public boolean isEndOfLine(int c) { return c == '\\n' || c == '\\r' || c == -1; } \n public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}\n }\n \n // |----| /\\ | | ----- |\n // | / / \\ | | | |\n // |--/ /----\\ |----| | |\n // | \\ / \\ | | | |\n // | \\ / \\ | | ----- -------\n \n static int d,n,x1,y1;\n static int arr[][];\n public static int dfs(int x,int y,int chance,int flip1,int flip2)\n {\n if(Math.sqrt(x*x+y*y)>d)\n return 1;\n for(int i=0;i d * d;\n\t}\n\t\n\tint get(int x, int y, boolean used1, boolean used2) {\n\t\tif (ok(x, y)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (vis[used1][used2][x][y]) {\n\t\t\treturn dp[used1][used2][x][y];\n\t\t}\n\t\t\n\t\tboolean result = false;\n\t\tif (!used1) {\n\t\t\tresult |= !get(y, x, used2, true);\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tresult |= !get(x + vx[i], y + vy[i], used2, used1);\n\t\t}\n\t\t\n\t\tvis[used1][used2][x][y] = true;\n\t\treturn dp[used1][used2][x][y] = result;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tsx = readInt() + shift;\n\t\tsy = readInt() + shift;\n\t\tn = readInt();\n\t\td = readInt();\n\t\tvx = new int[n];\n\t\tvy = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tvx[i] = readInt() + shift;\n\t\t\tvy[i] = readInt() + shift;\n\t\t}\n\t\t// used 1, used 2, x, y\n\t\tdp = new boolean[2][2][size][size];\n\t\tboolean ans = get(x, y, false, false);\n\t\tout.println(ans ? \"Anton\" : \"Dasha\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "53305898945d1ba1faa942d79ff34d41", "src_uid": "645a6ca9a8dda6946c2cc055a4beb08f", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound63_Div2_D implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new BetaRound63_Div2_D(), \"\", 256 * (1L << 20)).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tif (System.getProperty(\"ONLINE_JUDGE\") != null) {\n\t\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t} else {\n\t\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\t}\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Throwable t) {\n\t\t\tt.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\tlong readLong() throws IOException {\n\t\treturn Long.parseLong(readString());\n\t}\n\n\tdouble readDouble() throws IOException {\n\t\treturn Double.parseDouble(readString());\n\t}\n\n\t// solution\n\t\n\tfinal int shift = 401, size = 2*shift + 1;\n\t\n\tint sx, sy, n, d;\n\tint[] vx, vy;\n\t\n\tboolean[][][][] dp;\n\tboolean[][][][] vis;\n\t\n\tboolean ok(int x, int y) {\n\t\treturn (x - sx) * (x - sx) + (y - sy) * (y - sy) > d * d;\n\t}\n\t\n\tint get(int x, int y, int used1, int used2) {\n\t\tif (ok(x, y)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (vis[used1][used2][x][y]) {\n\t\t\treturn dp[used1][used2][x][y];\n\t\t}\n\t\t\n\t\tboolean result = false;\n\t\tif (used1 == 0) {\n\t\t\tresult |= !get(y, x, used2, 1);\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tresult |= !get(x + vx[i], y + vy[i], used2, used1);\n\t\t}\n\t\t\n\t\tvis[used1][used2][x][y] = true;\n\t\treturn dp[used1][used2][x][y] = result;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tsx = readInt() + shift;\n\t\tsy = readInt() + shift;\n\t\tn = readInt();\n\t\td = readInt();\n\t\tvx = new int[n];\n\t\tvy = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tvx[i] = readInt() + shift;\n\t\t\tvy[i] = readInt() + shift;\n\t\t}\n\t\t// used 1, used 2, x, y\n\t\tdp = new boolean[2][2][size][size];\n\t\tboolean ans = get(x, y, 0, 0);\n\t\tout.println(ans ? \"Anton\" : \"Dasha\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab941ba45066dca6cc285459bfcbd547", "src_uid": "645a6ca9a8dda6946c2cc055a4beb08f", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.HashMap;\nimport java.util.TreeSet;\n\npublic class Main {\n\tprivate static StreamTokenizer in = new StreamTokenizer(new BufferedReader(\n\t\t\tnew InputStreamReader(System.in)));\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\n\tprivate static int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tprivate static String nextString() throws Exception {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tint x = nextInt(), y = nextInt();\n\t\tint n = nextInt();\n\t\td = nextInt();\n\t\tv = new int[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tv[i] = new int[] { nextInt(), nextInt() };\n\t\t}\n\t\tdp = new int[d+1][d+1][2][2];\n\t\tout.println(f(x, y, 1, 1) == 1 ? \"Anton\" : \"Dasha\");\n\t\tout.flush();\n\t}\n\n\tprivate static int[][] v;\n\tprivate static int[][][][] dp;\n\tprivate static int d;\n\t\n\tprivate static int f(int x, int y, int cani, int cano) { //1 - I win, 2 - I lose\n\t\tif (Math.sqrt(x*x + y*y) > d) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (dp[x][y][cani][cano] > 0) {\n\t\t\treturn dp[x][y][cani][cano];\n\t\t}\n\t\t\n\t\tfor (int[] vector : v) {\n\t\t\tif (f(x + vector[0], y + vector[1], cano, cani) == 2) {\n\t\t\t\treturn dp[x][y][cani][cano] = 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (cani == 1) {\n\t\t\tcani = 0;\n\t\t\tif (f(y, x, cano, cani) == 2) {\n\t\t\t\treturn dp[x][y][cani][cano] = 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn dp[x][y][cani][cano] = 2;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "14f7d88bf9fe81899c412f5015d4dab2", "src_uid": "645a6ca9a8dda6946c2cc055a4beb08f", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 10/27/11\n * Time: 5:55 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport sun.misc.Sort;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.util.*;\n\npublic class TaskC extends Thread {\n public TaskC(int type) {\n try {\n if (type == 0) {\n this.input = new BufferedReader(new InputStreamReader(System.in));\n this.output = new PrintWriter(System.out);\n } else {\n this.input = new BufferedReader(new FileReader(INPUT_FILE));\n this.output = new PrintWriter(OUTPUT_FILE);\n }\n this.setPriority(Thread.MAX_PRIORITY);\n } catch (Throwable e) {\n e.printStackTrace();\n System.exit(666);\n }\n }\n\n static boolean isLucky(int value) {\n char []now = Integer.toString(value).toCharArray();\n for (char c : now) {\n if (c != '4' && c != '7') {\n return false;\n }\n }\n return true;\n }\n\n static void generate(long now, long length) {\n if (length == 10) {\n return;\n }\n luckies.add(now * 10 + 4);\n luckies.add(now * 10 + 7);\n generate(now * 10 + 4, length + 1);\n generate(now * 10 + 7, length + 1);\n }\n\n //12 ! - max\n private void solve() throws Throwable {\n long facts[] = new long[14];\n facts[0] = 1;\n for (int i = 1; i < facts.length; ++i) {\n facts[i] = facts[i - 1] * i;\n }\n int n = nextInt();\n long k = nextLong();\n if (n <= 12) {\n if (facts[n] < k) {\n output.println(-1);\n return;\n }\n }\n int result = 0;\n\n int N = 1;\n while (facts[N] < k) {\n ++N;\n }\n long MAX = (long) n - N;\n int index = 0;\n while (values.get(index) <= MAX) {\n ++result;\n ++index;\n }\n\n int values[] = new int[N];\n boolean used[] = new boolean[N];\n Arrays.fill(values, -1);\n for (int i = 0; i < N; ++i) {\n for (int wanted = 0; wanted < N; ++wanted) {\n if (used[wanted]) {\n continue;\n }\n long remaining = facts[N - 1 - i];\n if (remaining < k) {\n k -= remaining;\n } else {\n values[i] = wanted + 1;\n used[wanted] = true;\n break;\n }\n }\n }\n for (int i = 0; i < N; ++i) {\n int pos = (int)MAX + i + 1;\n if (isLucky(pos) && isLucky((int) MAX + values[i])) {\n ++result;\n }\n }\n output.println(result);\n\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 public static void main(String[] args) {\n new TaskC(0).start();\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 (tokens == null || !tokens.hasMoreTokens()) {\n tokens = new StringTokenizer(input.readLine());\n }\n return tokens.nextToken();\n }\n\n static ArrayList values = new ArrayList();\n static HashSet luckies = new HashSet();\n\n static {\n generate(0, 1);\n values.addAll(luckies);\n Collections.sort(values);\n }\n\n private static final String INPUT_FILE = null;\n private static final String OUTPUT_FILE = null;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "09fca3ac6ad38536403aa1699b1db662", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n static BufferedReader newInput() throws IOException {\n return new BufferedReader(new InputStreamReader(System.in));\n }\n static PrintWriter newOutput() throws IOException {\n return new PrintWriter(System.out);\n }\n public static void main(String[] args) throws IOException {\n BufferedReader in = newInput();\n PrintWriter out = newOutput();\n function(in, out);\n out.flush();\n }\n public static void function(BufferedReader in, PrintWriter out) throws IOException {\n //StringTokenizer t = new StringTokenizer(in.readLine());\n String[] nk = in.readLine().split(\" \");\n long n = Integer.parseInt(nk[0]);\n long k = Long.parseLong(nk[1]);\n ArrayList nums = new ArrayList<>();\n for (int i = 1; i <= (int)n; i++) {\n nums.add(i);\n }\n int lucks = 0;\n long fact = factorial(Math.min(n, 14));\n long x = Math.min(n, 14);\n for (int i = 1; i < Math.max(1, (int)n-13); i++) {\n if (isLucky((int)i)){\n lucks++;\n }\n }\n for (int i = Math.max(1, (int)n-13); i <= n; i++) {\n fact /= x;\n x--;\n int b = (int)((k-1)/fact);\n if (b >= n){\n out.println(\"-1\");\n return;\n }\n k -= (b*fact);\n b += Math.max(1, (int)n-13)-1;\n int num = nums.get(b);\n nums.remove(b);\n if (isLucky(num) && isLucky(i)){\n lucks++;\n }\n }\n out.println(lucks);\n }\n public static long factorial(long num){\n long x = num;\n num--;\n for (;num != 0; num--) {\n x *= num;\n }\n return x;\n }\n public static boolean isLucky(int x){\n for (; x != 0; x /= 10) {\n int b = x % 10;\n if (b != 7 && b != 4){\n return false;\n }\n }\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "886e55b218a39c0e8c710f648b64b8b1", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n static BufferedReader newInput() throws IOException {\n return new BufferedReader(new InputStreamReader(System.in));\n }\n static PrintWriter newOutput() throws IOException {\n return new PrintWriter(System.out);\n }\n public static void main(String[] args) throws IOException {\n BufferedReader in = newInput();\n PrintWriter out = newOutput();\n function(in, out);\n out.flush();\n }\n public static void function(BufferedReader in, PrintWriter out) throws IOException {\n //StringTokenizer t = new StringTokenizer(in.readLine());\n String[] nk = in.readLine().split(\" \");\n long n = Integer.parseInt(nk[0]);\n long k = Long.parseLong(nk[1]);\n ArrayList nums = new ArrayList<>();\n for (int i = Math.max(1, (int)n-13); i <= (int)n; i++) {\n nums.add(i);\n }\n int lucks = 0;\n long fact = factorial(Math.min(n, 14));\n long x = Math.min(n, 14);\n for (int i = 4; i < Math.max(1, (int)n-13); i += 10) {\n if (isLucky(i)){\n lucks++;\n }\n }\n for (int i = 7; i < Math.max(1, (int)n-13); i += 10) {\n if (isLucky(i)){\n lucks++;\n }\n }\n for (int i = Math.max(1, (int)n-13); i <= n; i++) {\n fact /= x;\n x--;\n int b = (int)((k-1)/fact);\n if (b >= n){\n out.println(\"-1\");\n return;\n }\n k -= (b*fact);\n int num = nums.get(b);\n nums.remove(b);\n if (isLucky(num) && isLucky(i)){\n lucks++;\n }\n }\n out.println(lucks);\n }\n public static long factorial(long num){\n long x = num;\n num--;\n for (;num != 0; num--) {\n x *= num;\n }\n return x;\n }\n public static boolean isLucky(int x){\n for (; x != 0; x /= 10) {\n int b = x % 10;\n if (b != 7 && b != 4){\n return false;\n }\n }\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f16768494f1f80d35e014fdd21784990", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 10/27/11\n * Time: 8:49 PM\n */\npublic class CF91E {\n public static void main(String[] args) {\n reader = new BufferedReader(new InputStreamReader(System.in));\n\n List luckyNums = genAll();\n long[] f = new long[14];\n f[0] = 1;\n for(int i = 1; i < 14; ++i) {\n f[i] = i * f[i-1];\n }\n\n int n = nextInt(), k = nextInt();\n if (k > f[n]) {\n System.out.println(-1);\n return;\n }\n\n int x = 1;\n for(; f[x] < k; ++x);\n\n int res = 0;\n for(int lucky: luckyNums) {\n if (lucky < n-x+1) ++res;\n }\n\n int[] p = getKthPerm(k-1, n-x+1, n, x, f);\n for(int i = 0; i < x; ++i) {\n if (isLucky(p[i]) && isLucky(n-x+1+i)) {\n ++res;\n }\n }\n\n System.out.println(res);\n }\n\n private static int[] getKthPerm(int k, int a, int b, int n, long[] fac) {\n int[] res = new int[n];\n for(int i = a; i <= b; ++i) {\n res[i-a] = i;\n }\n\n for(int i = 0; i < n; ++i) {\n int x = (int)(k / fac[n-i-1]);\n int y = res[x+i];\n for(int j = x + i - 1; j >= i; --j) {\n res[j+1] = res[j];\n }\n res[i] = y;\n k = (int)(k % fac[n-i-1]);\n }\n\n return res;\n }\n\n private static boolean isLucky(int x) {\n if (x == 0) return false;\n while (x > 0) {\n if (x % 10 != 4 && x % 10 != 7) return false;\n x /= 10;\n }\n return true;\n }\n\n private static List genAll() {\n List ret = new ArrayList();\n for(int i = 1; i < 10; ++i) {\n for(int set = 0; set < (1 << i); ++set) {\n int x = 0;\n for(int j = i-1; j >= 0; --j) {\n if (((set >> j) & 1) == 1) {\n x = x * 10 + 7;\n }\n else {\n x = x * 10 + 4;\n }\n }\n ret.add(x);\n }\n }\n return ret;\n }\n\n public static BufferedReader reader;\n\n public static StringTokenizer tokenizer = null;\n\n static 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 static public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n static public long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n static public String next() {\n return nextToken();\n }\n\n static public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "017a8f0dae324b6149b92195e5d74363", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\npublic class Morwords {\n\tpublic static void main(String[]args) {\n\t\tScanner sc = new Scanner (System.in);\n\t\tint n = sc.nextInt();\n\t\tString s = sc.next();\n\t\tchar [] arr = s.toCharArray();\n\t\tString vowels = \"aeiouy\";\n\t\tfor (int i=0;i items = new ArrayList<>();\n for(int i = 0; i < av.length(); i++) {\n items.add(String.valueOf(av.charAt(i)));\n }\n\n for(int i = 0; i < numbers.length(); i++) {\n boolean isItemUsed = false;\n for(int j = 0; j < items.size(); j++) {\n if((items.get(j).equals(String.valueOf(numbers.charAt(i))) || isItems2or5(String.valueOf(numbers.charAt(i)), items.get(j)) || isItems6or9(String.valueOf(numbers.charAt(i)), items.get(j))) && !isItemUsed) {\n items.set(j, \"\");\n count++;\n isItemUsed = true;\n }\n }\n }\n\n if(count != numbers.length()) {\n break;\n }\n\n totalCount++;\n av = \"\";\n for(int i = 0; i < items.size(); i++) {\n if(items.get(i) != null) {\n av += items.get(i);\n }\n }\n }\n\n pw.println(totalCount);\n pw.close();\n sc.close();\n }\n\n static boolean isItems2or5(String number, String listItem) {\n return (\"2\".equals(number) && \"5\".equals(listItem)) || (\"5\".equals(number) && \"2\".equals(listItem));\n }\n\n static boolean isItems6or9(String number, String listItem) {\n return (\"6\".equals(number) && \"9\".equals(listItem)) || (\"9\".equals(number) && \"6\".equals(listItem));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b8ffdcdca9792f15a7e89d717b17cd8d", "src_uid": "72a196044787cb8dbd8d350cb60ccc32", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.util.*; //Scanner;\nimport java.io.PrintWriter; //PrintWriter\n\npublic class R191_Test8_B //Name: Sheldon and Ice Pieces\n{\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tsolve(in, out);\n\t\tout.close();\n\t\tin.close();\t\n\t}\n\t\n\tpublic static void solve(Scanner in, PrintWriter out)\n\t{\n\t\tint n = in.nextInt();\t\n\t\tint k = in.nextInt();\n\t\t\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\tString s = in.next();\n\t\t\n\t\tStringBuilder sb = new StringBuilder(s + k);\n\t\tsb.append(\"\\r\\n\");\n\t\t\n\t\tout.println(sb);\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8dcf0841a145480edbe9221fb7291349", "src_uid": "72a196044787cb8dbd8d350cb60ccc32", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "package task;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Cubs {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tString number = null;\n\t\tString digits = null;\n\n\t\tBufferedReader bufferRead = new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in));\n\t\ttry {\n\t\t\tnumber = bufferRead.readLine();\n\t\t\tdigits = bufferRead.readLine();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\n\t\tint size = number.length();\n\t\tint[] countsInDigits = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n\t\tint[] countsInNumber = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n\n\t\tfor (int k = 0; k <= 9; k++) {\n\t\t\tfor (int i = 0; i < digits.length(); i++) {\n\t\t\t\tif (Character.getNumericValue(digits.charAt(i)) == k) {\n\t\t\t\t\tcountsInDigits[k]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int k = 0; k <= 9; k++) {\n\t\t\tfor (int i = 0; i < number.length(); i++) {\n\t\t\t\tif (Character.getNumericValue(number.charAt(i)) == k) {\n\t\t\t\t\tcountsInNumber[k]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint max = 34;\n\t\tfor (int i = 0; i <= 9; i++) {\t\t\t\n\t\t\tif (countsInNumber[i] > 0) {\n\t\t\t\tint y = 0;\n\t\t\t\tif (i != 2 && i != 5 && i != 6 && i != 9) {\n\t\t\t\t\ty = countsInDigits[i] / countsInNumber[i];\n\t\t\t\t} else if (i == 2 || i == 5) {\n\t\t\t\t\ty = (countsInDigits[2] + countsInDigits[5])\n\t\t\t\t\t\t\t/ (countsInNumber[2] + countsInNumber[5]);\n\t\t\t\t} else if (i == 6 || i == 9) {\n\t\t\t\t\ty = (countsInDigits[6] + countsInDigits[9])\n\t\t\t\t\t\t\t/ (countsInNumber[6] + countsInNumber[9]);\n\t\t\t\t}\n\t\t\t\tif(y=0; j--) {\n\t\t temp += k.charAt(j);\n\t\t }\n\t\t for(int j=i; j=0;m--){\nans+=ch[m];\n}\nSystem.out.println(ans);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d012c0de2638f558191f53e00b9792d0", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.awt.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\n\npublic class B implements Runnable{\n\n // SOLUTION!!!\n // HACK ME PLEASE IF YOU CAN!!!\n // PLEASE!!!\n // PLEASE!!!\n // PLEASE!!!\n\n private final static Random rnd = new Random();\n private final static String fileName = \"\";\n\n private final static String ENTER = \"+\", EXIT = \"-\";\n\n private void solve() {\n int n = readInt();\n int m = readInt();\n\n boolean[] canBeLeader = new boolean[n];\n Arrays.fill(canBeLeader, true);\n\n class Event {\n boolean enter;\n int index;\n\n public Event(String type, int index) {\n this.enter = ENTER.equals(type);\n this.index = index;\n }\n }\n\n Event[] inputEvents = new Event[m];\n for (int i = 0; i < m; ++i) {\n inputEvents[i] = new Event(readString(), readInt() - 1);\n }\n\n int startMeetingSize = 0;\n\n Set wasBefore = new HashSet<>();\n\n boolean[] used = new boolean[n];\n for (Event inputEvent : inputEvents) {\n if (!inputEvent.enter && !used[inputEvent.index]) {\n wasBefore.add(inputEvent.index);\n }\n\n used[inputEvent.index] = true;\n }\n\n SortedSet zeros = new TreeSet<>();\n\n int meetingSize = wasBefore.size();\n for (Event event : inputEvents) {\n if (event.enter) {\n if (meetingSize != 0) {\n canBeLeader[event.index] = false;\n } else {\n zeros.add(event.index);\n }\n\n ++meetingSize;\n } else {\n --meetingSize;\n\n if (meetingSize != 0) {\n canBeLeader[event.index] = false;\n } else {\n zeros.add(event.index);\n }\n }\n }\n\n if (zeros.size() > 1) {\n for (int index : zeros) {\n canBeLeader[index] = false;\n }\n } else if (zeros.size() == 1){\n int zeroEnter = zeros.first();\n\n if (wasBefore.size() > 0 && !wasBefore.contains(zeroEnter)) {\n canBeLeader[zeroEnter] = false;\n }\n }\n\n List possibleLeaders = new ArrayList<>();\n for (int i = 0; i < n; ++i) {\n if (canBeLeader[i]) possibleLeaders.add(i);\n }\n\n out.println(possibleLeaders.size());\n for (int leader : possibleLeaders) {\n out.print((leader + 1) + \" \");\n }\n out.println();\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private final static boolean FIRST_INPUT_STRING = false;\n private final static boolean MULTIPLE_TESTS = true;\n private final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private final static int MAX_STACK_SIZE = 128;\n\n private final static boolean OPTIMIZE_READ_NUMBERS = false;\n\n /////////////////////////////////////////////////////////////////////\n\n public void run(){\n try{\n timeInit();\n Locale.setDefault(Locale.US);\n\n init();\n\n if (ONLINE_JUDGE) {\n solve();\n } else {\n do {\n try {\n timeInit();\n solve();\n time();\n\n out.println();\n } catch (NumberFormatException e) {\n break;\n } catch (NullPointerException e) {\n if (FIRST_INPUT_STRING) break;\n else throw e;\n }\n } while (MULTIPLE_TESTS);\n }\n\n out.close();\n time();\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private BufferedReader in;\n private OutputWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n public static void main(String[] args){\n new Thread(null, new B(), \"\", MAX_STACK_SIZE * (1L << 20)).start();\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private void init() throws FileNotFoundException{\n Locale.setDefault(Locale.US);\n\n if (ONLINE_JUDGE){\n if (fileName.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new OutputWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(fileName + \".in\"));\n out = new OutputWriter(fileName + \".out\");\n }\n }else{\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new OutputWriter(\"output.txt\");\n }\n }\n\n ////////////////////////////////////////////////////////////////\n\n private long timeBegin;\n\n private void timeInit() {\n this.timeBegin = System.currentTimeMillis();\n }\n\n private void time(){\n long timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n private void debug(Object... objects){\n if (ONLINE_JUDGE){\n for (Object o: objects){\n System.err.println(o.toString());\n }\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private String delim = \" \";\n\n private String readLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private String readString() {\n try {\n while(!tok.hasMoreTokens()){\n tok = new StringTokenizer(readLine());\n }\n\n return tok.nextToken(delim);\n } catch (NullPointerException e) {\n return null;\n }\n }\n\n /////////////////////////////////////////////////////////////////\n\n private final char NOT_A_SYMBOL = '\\0';\n\n private char readChar() {\n try {\n int intValue = in.read();\n\n if (intValue == -1){\n return NOT_A_SYMBOL;\n }\n\n return (char) intValue;\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private char[] readCharArray() {\n return readLine().toCharArray();\n }\n\n private char[][] readCharField(int rowsCount) {\n char[][] field = new char[rowsCount][];\n for (int row = 0; row < rowsCount; ++row) {\n field[row] = readCharArray();\n }\n\n return field;\n }\n\n /////////////////////////////////////////////////////////////////\n\n private long optimizedReadLong() {\n int sign = 1;\n long result = 0;\n boolean started = false;\n while (true) {\n try {\n int j = in.read();\n if (-1 == j) {\n if (started) return sign * result;\n throw new NumberFormatException();\n }\n\n if (j == '-') {\n if (started) throw new NumberFormatException();\n sign = -sign;\n }\n\n if ('0' <= j && j <= '9') {\n result = result * 10 + j - '0';\n started = true;\n } else if (started) {\n return sign * result;\n }\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n }\n\n private int readInt() {\n\n if (!OPTIMIZE_READ_NUMBERS) {\n return Integer.parseInt(readString());\n } else {\n return (int) optimizedReadLong();\n }\n }\n\n private int[] readIntArray(int size) {\n int[] array = new int[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readInt();\n }\n\n return array;\n }\n\n private int[] readSortedIntArray(int size) {\n Integer[] array = new Integer[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = readInt();\n }\n Arrays.sort(array);\n\n int[] sortedArray = new int[size];\n for (int index = 0; index < size; ++index) {\n sortedArray[index] = array[index];\n }\n\n return sortedArray;\n }\n\n private int[] readIntArrayWithDecrease(int size) {\n int[] array = readIntArray(size);\n\n for (int i = 0; i < size; ++i) {\n array[i]--;\n }\n\n return array;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private int[][] readIntMatrix(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArray(columnsCount);\n }\n\n return matrix;\n }\n\n private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);\n }\n\n return matrix;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private long readLong() {\n if (!OPTIMIZE_READ_NUMBERS) {\n return Long.parseLong(readString());\n } else {\n return optimizedReadLong();\n }\n }\n\n private long[] readLongArray(int size) {\n long[] array = new long[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readLong();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private double readDouble() {\n return Double.parseDouble(readString());\n }\n\n private double[] readDoubleArray(int size) {\n double[] array = new double[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readDouble();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private BigInteger readBigInteger() {\n return new BigInteger(readString());\n }\n\n private BigDecimal readBigDecimal() {\n return new BigDecimal(readString());\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private Point readPoint() {\n int x = readInt();\n int y = readInt();\n return new Point(x, y);\n }\n\n private Point[] readPointArray(int size) {\n Point[] array = new Point[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readPoint();\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n @Deprecated\n private List[] readGraph(int vertexNumber, int edgeNumber) {\n @SuppressWarnings(\"unchecked\")\n List[] graph = new List[vertexNumber];\n\n for (int index = 0; index < vertexNumber; ++index){\n graph[index] = new ArrayList<>();\n }\n\n while (edgeNumber-- > 0){\n int from = readInt() - 1;\n int to = readInt() - 1;\n\n graph[from].add(to);\n graph[to].add(from);\n }\n\n return graph;\n }\n\n private static class GraphBuilder {\n\n final int size;\n final List[] edges;\n\n static GraphBuilder createInstance(int size) {\n List[] edges = new List[size];\n for (int v = 0; v < size; ++v) {\n edges[v] = new ArrayList<>();\n }\n\n return new GraphBuilder(edges);\n }\n\n private GraphBuilder(List[] edges) {\n this.size = edges.length;\n this.edges = edges;\n }\n\n public void addEdge(int from, int to) {\n addDirectedEdge(from, to);\n addDirectedEdge(to, from);\n }\n\n public void addDirectedEdge(int from, int to) {\n edges[from].add(to);\n }\n\n public int[][] build() {\n int[][] graph = new int[size][];\n for (int v = 0; v < size; ++v) {\n List vEdges = edges[v];\n graph[v] = castInt(vEdges);\n }\n\n return graph;\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IntIndexPair {\n\n static Comparator increaseComparator = new Comparator() {\n\n @Override\n public int compare(B.IntIndexPair indexPair1, B.IntIndexPair indexPair2) {\n int value1 = indexPair1.value;\n int value2 = indexPair2.value;\n\n if (value1 != value2) return value1 - value2;\n\n int index1 = indexPair1.index;\n int index2 = indexPair2.index;\n\n return index1 - index2;\n }\n };\n\n static Comparator decreaseComparator = new Comparator() {\n\n @Override\n public int compare(B.IntIndexPair indexPair1, B.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 int value, index;\n\n IntIndexPair(int value, int index) {\n super();\n this.value = value;\n this.index = index;\n }\n\n int getRealIndex() {\n return index + 1;\n }\n }\n\n private IntIndexPair[] readIntIndexArray(int size) {\n IntIndexPair[] array = new IntIndexPair[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = new IntIndexPair(readInt(), index);\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class OutputWriter extends PrintWriter {\n\n final int DEFAULT_PRECISION = 12;\n\n private int precision;\n private String format, formatWithSpace;\n\n {\n precision = DEFAULT_PRECISION;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n OutputWriter(OutputStream out) {\n super(out);\n }\n\n OutputWriter(String fileName) throws FileNotFoundException {\n super(fileName);\n }\n\n int getPrecision() {\n return precision;\n }\n\n void setPrecision(int precision) {\n precision = max(0, precision);\n this.precision = precision;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n String createFormat(int precision){\n return \"%.\" + precision + \"f\";\n }\n\n @Override\n public void print(double d){\n printf(format, d);\n }\n\n void printWithSpace(double d){\n printf(formatWithSpace, d);\n }\n\n void printAll(double...d){\n for (int i = 0; i < d.length - 1; ++i){\n printWithSpace(d[i]);\n }\n\n print(d[d.length - 1]);\n }\n\n @Override\n public void println(double d){\n printlnAll(d);\n }\n\n void printlnAll(double... d){\n printAll(d);\n println();\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class RuntimeIOException extends RuntimeException {\n\n /**\n *\n */\n private static final long serialVersionUID = -6463830523020118289L;\n\n RuntimeIOException(Throwable cause) {\n super(cause);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n //////////////// Some useful constants and functions ////////////////\n /////////////////////////////////////////////////////////////////////\n\n private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n private static final int[][] steps8 = {\n {-1, 0}, {1, 0}, {0, -1}, {0, 1},\n {-1, -1}, {1, 1}, {1, -1}, {-1, 1}\n };\n\n private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {\n return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);\n }\n\n private static boolean checkIndex(int index, int lim){\n return (0 <= index && index < lim);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static boolean checkBit(int mask, int bit){\n return (mask & (1 << bit)) != 0;\n }\n private static boolean checkBit(long mask, int bit){\n return (mask & (1L << bit)) != 0;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long getSum(int[] array) {\n long sum = 0;\n for (int value: array) {\n sum += value;\n }\n\n return sum;\n }\n\n private static Point getMinMax(int[] array) {\n int min = array[0];\n int max = array[0];\n\n for (int index = 0, size = array.length; index < size; ++index, ++index) {\n int value = array[index];\n\n if (index == size - 1) {\n min = min(min, value);\n max = max(max, value);\n } else {\n int otherValue = array[index + 1];\n\n if (value <= otherValue) {\n min = min(min, value);\n max = max(max, otherValue);\n } else {\n min = min(min, otherValue);\n max = max(max, value);\n }\n }\n }\n\n return new Point(min, max);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static int[] getPrimes(int n) {\n boolean[] used = new boolean[n];\n used[0] = used[1] = true;\n\n int size = 0;\n for (int i = 2; i < n; ++i) {\n if (!used[i]) {\n ++size;\n for (int j = 2 * i; j < n; j += i) {\n used[j] = true;\n }\n }\n }\n\n int[] primes = new int[size];\n for (int i = 0, cur = 0; i < n; ++i) {\n if (!used[i]) {\n primes[cur++] = i;\n }\n }\n\n return primes;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n private static long gcd(long a, long b) {\n return (a == 0 ? b : gcd(b % a, a));\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class MultiSet {\n\n public static MultiSet createMultiSet() {\n Map multiset = new HashMap<>();\n return new MultiSet<>(multiset);\n }\n\n private final Map multiset;\n private int size;\n\n public MultiSet(Map multiset) {\n this.multiset = multiset;\n this.size = 0;\n }\n\n public int size() {\n return size;\n }\n\n public void inc(ValueType value) {\n int count = get(value);\n multiset.put(value, count + 1);\n\n ++size;\n }\n\n public void dec(ValueType value) {\n int count = get(value);\n if (count == 0) return;\n\n if (count == 1) multiset.remove(value);\n else multiset.put(value, count - 1);\n\n --size;\n }\n\n public int get(ValueType value) {\n Integer count = multiset.get(value);\n return (count == null ? 0 : count);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IdMap extends HashMap {\n\n /**\n *\n */\n private static final long serialVersionUID = -3793737771950984481L;\n\n public IdMap() {\n super();\n }\n\n int getId(KeyType key) {\n Integer id = super.get(key);\n if (id == null) {\n super.put(key, id = size());\n }\n\n return id;\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static int[] castInt(List list) {\n int[] array = new int[list.size()];\n for (int i = 0; i < array.length; ++i) {\n array[i] = list.get(i);\n }\n\n return array;\n }\n\n private static long[] castLong(List list) {\n long[] array = new long[list.size()];\n for (int i = 0; i < array.length; ++i) {\n array[i] = list.get(i);\n }\n\n return array;\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ff6fbed44ab2e32464198048dfa41195", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n\tpublic static void main(String[] Args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tnew Solver().Run();\n\t}\n\n\tPrintWriter pw;\n\tStringTokenizer Stok;\n\tBufferedReader br;\n\n\tpublic String nextToken() throws IOException {\n\t\twhile (Stok == null || !Stok.hasMoreTokens()) {\n\t\t\tStok = new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn Stok.nextToken();\n\t}\n\n\tpublic int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic double nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic long nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tint n,m;\n\tArrayList result;\n\tboolean[] alreadyExists;\n\tint[] history;\n\tint[] kolChange;\n\tint kolAlready=0;\n\t\n\tboolean check(int numLider){\n\t\tint maxNum=0;\n\t\tif (alreadyExists[numLider])\n\t\t\tmaxNum=Integer.MAX_VALUE;\n\t\tint kolInRoom=kolAlready;\n\t\tif (kolInRoom>maxNum)\n\t\t\treturn false;\n\t\tfor (int i=0; i0){\n\t\t\t\tkolInRoom++;\n\t\t\t\tif (history[i]==numLider)\n\t\t\t\t\tmaxNum=Integer.MAX_VALUE;\n\t\t\t}\n\t\t\tif (history[i]<0){\n\t\t\t\tkolInRoom--;\n\t\t\t\tif (-history[i]==numLider)\n\t\t\t\t\tmaxNum=0;\n\t\t\t}\n\t\t\tif (kolInRoom>maxNum)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\t\n\tint findCandidate(){\n\t\tint result=0;\n\t\tint i=0;\n\t\tint kolInRoom=kolAlready;\n\t\tif (kolAlready==0) {\n\t\t\tkolInRoom++;\n\t\t\t//alreadyExists[history[i]]=true;\n\t\t\tresult=history[i];\n\t\t\ti++;\n\t\t}\n\t\tfor (;i0)\n\t\t\t\tkolInRoom++;\n\t\t\tif (history[i]<0){\n\t\t\t\tkolInRoom--;\n\t\t\t\tif (kolInRoom==0){\n\t\t\t\t\tresult=-history[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\t\n\tpublic void Run() throws NumberFormatException, IOException {\n\t\t//br = new BufferedReader(new FileReader(\"input.txt\")); pw = new PrintWriter(\"output.txt\");\n\t\tbr=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\n\t\tn=nextInt();\n\t\tm=nextInt();\n\t\tresult=new ArrayList();\n\t\talreadyExists=new boolean[n+1];\n\t\thistory=new int[m];\n\t\tkolChange=new int[n+1];\n\t\tfor (int i=0; i0)\n\t\t\tif (check(candidate))\n\t\t\t\tresult.add(candidate);\n\t\t/*\n\t\tif (history[0]>0)\n\t\t\tif (check(history[0]))\n\t\t\t\tresult.add(history[0]);\n\t\t\n\t\tif (history[m-1]<0 && history[0]!=-history[m-1])\n\t\t\tif (check(-history[m-1]))\n\t\t\t\tresult.add(-history[m-1]);\n\t\t*/\n\t\tCollections.sort(result);\n\t\tpw.println(result.size());\n\t\tfor (Integer elem : result) {\n\t\t\tpw.print(elem);\n\t\t\tpw.print(' ');\n\t\t}\n\t\tpw.println();\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2b1277483c5df496440f1b5347f72d5", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.text.*;\n\n\npublic class Main {\n\t\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\t//BufferedReader cin = new BufferedReader(new FileReader(\"test.txt\"));\n\t\t BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));\n\t\n\t\t\n\t\tString line;\n\t\tStringTokenizer st;\n\t\t\n\t\tline = cin.readLine();\n\t\tst = new StringTokenizer(line);\n\t\t\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\t\t//int b = Integer.parseInt(st.nextToken());\n\t\t\n\t\tboolean[] leader = new boolean[n];\n\t\tfor(int i=0;i list = new TreeSet();\n\t\tchar[] signs = new char[m];\n\t\tint[] ids = new int[m];\n\t\t\n\t\tchar sign;\n\t\tint id;\n\t\tfor(int i=0;i ite;\n\t\tint tmpid;\n\t\tfor(int i=0;i cur = new HashSet();\n HashSet pre = new HashSet();\n for (int i = 0; i < m; i++) {\n char op = in.next().charAt(0);\n int num = in.nextInt() - 1;\n\n if (op == '+') {\n if (cur.size() > 0 || (pre.size() > 0 && !pre.contains(num))) {\n check[num] = false;\n }\n cur.add(num);\n if (pre.contains(num)) {\n pre.remove(num);\n }\n for(int v : pre){\n check[v] = false;\n }\n } else {\n if (cur.contains(num)) {\n if (cur.size() > 1) {\n check[num] = false;\n }\n cur.remove(num);\n pre.add(num);\n } else {\n if (cur.size() > 0) {\n check[num] = false;\n }\n for (int v : cur) {\n check[v] = false;\n }\n for (int v : pre) {\n check[v] = false;\n }\n pre.add(num);\n }\n }\n }\n int c = 0;\n StringBuilder builder = new StringBuilder();\n for (int i = 0; i < n; i++) {\n if (check[i]) {\n c++;\n builder.append(i + 1).append(\" \");\n }\n }\n out.println(c);\n out.println(builder.toString());\n out.close();\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e165bdfb7d314138cdd5fa2feca811f2", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author zodiacLeo\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n FastPrinter out = new FastPrinter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB\n {\n public void solve(int testNumber, FastScanner in, FastPrinter out)\n {\n int n = in.nextInt();\n int p = in.nextInt();\n int pos = in.nextInt() - 1;\n\n int low = 0;\n int high = p + 1;\n while (high - low > 1)\n {\n int mid = low + (high - low) / 2;\n if (check(mid, p, pos, n))\n {\n low = mid;\n } else\n {\n high = mid;\n }\n }\n out.println(low);\n }\n\n private boolean check(int Q, int all, int pos, int n)\n {\n int[] a = new int[n];\n Arrays.fill(a, 1);\n\n all -= n;\n a[pos] = Q - 1;\n all -= Q - 1;\n for (int i = pos - 1, q = Q - 2; i >= 0 && q > 0; i--)\n {\n a[i] = q;\n all -= q;\n q--;\n if (all < 0)\n {\n return false;\n }\n }\n for (int i = pos + 1, q = Q - 2; i < n && q > 0; i++)\n {\n a[i] = q;\n all -= q;\n q--;\n if (all < 0)\n {\n return false;\n }\n }\n return all >= 0;\n }\n\n }\n\n static class FastScanner\n {\n public BufferedReader br;\n public StringTokenizer st;\n\n public FastScanner(InputStream is)\n {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public FastScanner(File f)\n {\n try\n {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e)\n {\n e.printStackTrace();\n }\n }\n\n public String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n String s = null;\n try\n {\n s = br.readLine();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n }\n\n static class FastPrinter extends PrintWriter\n {\n public FastPrinter(OutputStream out)\n {\n super(out);\n }\n\n public FastPrinter(Writer out)\n {\n super(out);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c3aee75fda1b8a7b10e3650175e79139", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "\u00a0\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.*;\n\n\n\npublic class CF\n{ \n\n\t\n\tpublic static void main (String[] args) throws IOException\n\t{\n\t\t\n\t\tReader.init(System.in);\n\t\t\n\t\tint n=Reader.nextInt();\n\t\tint m=(Reader.nextInt()-n);\n\t\tint k=Reader.nextInt()-1;\n\t\t\n\t\tlong ans=0;\n\t\t\n\t\tif(m>=1)\n\t\t{\n\t\t\tans=1;m--;\n\t\t}\n\t\t\n\t\tint left=k,right=k;\n\t\t\n\t\tif(k-1>-1)\n\t\t\tleft=k-1;\n\t\t\n\t\tif(k+10 && (left!=0 || right!=n-1)) {\n\t\t\t\n\t\t\tint xl=Math.abs(k-left);\n\t\t\tint xr=Math.abs(k-right);\n\t\t\t\n\t\t\tm-=(xl+xr);\n\t\t\t\n\t\t\tif(m>0)\n\t\t\t{\n\t\t\t\tm--;ans++;\n\t\t\t}\n\t\t\t\n\t\t\tif(left-1>-1)\n\t\t\t\tleft--;\n\t\t\t\n\t\t\tif(right+10) {\n\t\t\t\n\t\t\tans+=m/n;\n\t\t}\n\t\tSystem.out.println(ans+1);\n\t\t\n\t\t\n\t\t\n\t}\n}\n\n\n\t\t\n\t\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 \t\n \treturn Long.parseLong( next() );\n }\n\t\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "66ad971ec835dd96a88a53f008f48172", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class line\n{\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt();\n\t\tint m = s.nextInt();\n\t\tint k = s.nextInt();\n\t\tint left = k-1;\n\t\tint right = n-k;\n\t\tint tleft = 0;\n\t\tint tright = 0;\n\t\tm = m- n;\n\t\tint ans = 1;\n\t\tif(n==1){\n\t\t ans += m;\n\t\t m=0;\n\t\t}\n\t\twhile(m>0){\n\t\t\tans++;\n\t\t\tif(tleft=(min(len,k-1)+min(len,n-k)+1))\n\t\t\t{\n\t\t\t\tm-=min(len,k-1)+min(len,n-k)+1;\n\t\t\t\tlen++;\n\t\t\t\tans++;\n\t\t\t}\n\t\t\tans+=(m/n);\n\t\t\tout.println(ans);\n\t }\n }\n\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 Task solver = new Task();\n solver.Solve(in,out);\n out.close();\n }\n \n static int[][] sort2D(int arr[][]){\n Arrays.sort(arr,new java.util.Comparator(){\n public int compare(int[] a, int[] b) {\n return Integer.compare(a[0], b[0]);\n }});\n return arr;\n }\n \n\tstatic int[] di={1,0,-1,0,1,-1,-1,1};\n\tstatic int[] dj={0,1,0,-1,1,1,-1,-1};\n \n\tstatic class point{\n\t\tint x;int y;\n\t\tpublic point(int x,int y){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t}\n\n static void sort(int arr[]){\n\t\tint cnt[]=new int[(1<<16)+1];\n\t\tint ys[]=new int[arr.length];\t\n\t\tfor(int j=0;j<=16;j+=16){\n\t\t\tArrays.fill(cnt,0);\n\t\t\tfor(int x:arr){cnt[(x>>j&0xFFFF)+1]++;}\n\t\t\tfor(int i=1;i>j&0xFFFF]++]=x;}\n\t\t\t{ final int t[]=arr;arr=ys;ys=t;}\n\t\t}\n\t\tif(arr[0]<0||arr[arr.length-1]>=0)return;\n\t\tint i,j,c;\n\t\tfor(i=arr.length-1,c=0;arr[i]<0;i--,c++){ys[c]=arr[i];}\n\t\tfor(j=arr.length-1;i>=0;i--,j--){arr[j]=arr[i];}\n\t\tfor(i=c-1;i>=0;i--){arr[i]=ys[c-1-i];}\n\t}\n \n static int abs(int x){if(x>=0)return x;else return -x;}\n static long abs(long x){if(x>=0)return x;else return -x;}\n \n static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}\n static long gcd(long a,long b){return b==0?a:gcd(b,a%b);}\n \n static int min(int x,int y){return xy?x:y;}\n static int max(int x,int y,int z){return x>y?(x>z?x:z):(y>z?y:z);}\n static long max(long x,long y){return x>y?x:y;}\n static long max(long x,long y,long z){return x>y?(x>z?x:z):(y>z?y:z);}\n \n static void joutArray(int arr[]){\n \tfor(int i=0;i inHashMap(int n){\n \tHashMap hm=new HashMap<>();\n \tfor(int i=0;i inTreeMap(int n){\n \tTreeMap tm=new TreeMap<>();\n \tfor(int i=0;i=(min(len,k-1)+min(len,n-k)+1))\n\t\t\t{\n\t\t\t\tm-=min(len,k-1)+min(len,n-k)+1;\n\t\t\t\tlen++;\n\t\t\t\tans++;\n\t\t\t}\n\t\t\tans+=(m/n);\n\t\t\tout.println(ans);\n\t }\n }\n\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 Task solver = new Task();\n solver.Solve(in,out);\n out.close();\n }\n \n static int[][] sort2D(int arr[][]){\n Arrays.sort(arr,new java.util.Comparator(){\n public int compare(int[] a, int[] b) {\n return Integer.compare(a[0], b[0]);\n }});\n return arr;\n }\n \n\tstatic int[] di={1,0,-1,0,1,-1,-1,1};\n\tstatic int[] dj={0,1,0,-1,1,1,-1,-1};\n \n\tstatic class point{\n\t\tint x;int y;\n\t\tpublic point(int x,int y){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t}\n\n static void sort(int arr[]){\n\t\tint cnt[]=new int[(1<<16)+1];\n\t\tint ys[]=new int[arr.length];\t\n\t\tfor(int j=0;j<=16;j+=16){\n\t\t\tArrays.fill(cnt,0);\n\t\t\tfor(int x:arr){cnt[(x>>j&0xFFFF)+1]++;}\n\t\t\tfor(int i=1;i>j&0xFFFF]++]=x;}\n\t\t\t{ final int t[]=arr;arr=ys;ys=t;}\n\t\t}\n\t\tif(arr[0]<0||arr[arr.length-1]>=0)return;\n\t\tint i,j,c;\n\t\tfor(i=arr.length-1,c=0;arr[i]<0;i--,c++){ys[c]=arr[i];}\n\t\tfor(j=arr.length-1;i>=0;i--,j--){arr[j]=arr[i];}\n\t\tfor(i=c-1;i>=0;i--){arr[i]=ys[c-1-i];}\n\t}\n \n static int abs(int x){if(x>=0)return x;else return -x;}\n static long abs(long x){if(x>=0)return x;else return -x;}\n \n static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}\n static long gcd(long a,long b){return b==0?a:gcd(b,a%b);}\n \n static int min(int x,int y){return xy?x:y;}\n static int max(int x,int y,int z){return x>y?(x>z?x:z):(y>z?y:z);}\n static long max(long x,long y){return x>y?x:y;}\n static long max(long x,long y,long z){return x>y?(x>z?x:z):(y>z?y:z);}\n \n static void joutArray(int arr[]){\n \tfor(int i=0;i inHashMap(int n){\n \tHashMap hm=new HashMap<>();\n \tfor(int i=0;i inTreeMap(int n){\n \tTreeMap tm=new TreeMap<>();\n \tfor(int i=0;i xset = new TreeSet<>();\n TreeSet yset = new TreeSet<>();\n for (int i = 0; i < 8; i++) {\n x[i] = sc.nextInt();\n y[i] = sc.nextInt();\n xset.add(x[i]);\n yset.add(y[i]);\n }\n if (xset.size() != 3 || yset.size() != 3) {\n out.println(\"ugly\");\n return;\n }\n int[] a = new int[3];\n int[] b = new int[3];\n int i = 0;\n for (int xx : xset) a[i++] = xx;\n i = 0;\n for (int yy : yset) b[i++] = yy;\n \n boolean ok = true;\n for (i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n if (i == 1 && j == 1) continue;\n if (!has(x, y, a[i], b[j])) ok = false;\n }\n }\n out.println(ok ? \"respectable\" : \"ugly\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e0815b0113f76e84f19f0438ab2abea4", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.io.InputStream;\n\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n 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, OutputWriter out) {\n int[] x = new int[8];\n int[] y = new int[8];\n IOUtils.readIntArrays(in, x, y);\n boolean ok = true;\n for (int i = 0; i < 8; i++) {\n for (int j = i + 1; j < 8; j++) {\n if (x[i] == x[j] && y[i] == y[j]) ok = false;\n }\n }\n Arrays.sort(x);\n Arrays.sort(y);\n if (!(x[0] == x[1] && x[1] == x[2] && x[2] != x[3] && x[3] == x[4] && x[4] != x[5] && x[5] == x[6] && x[6] == x[7])) ok = false;\n if (!(y[0] == y[1] && y[1] == y[2] && y[2] != y[3] && y[3] == y[4] && y[4] != y[5] && y[5] == y[6] && y[6] == y[7])) ok = false;\n if (ok)\n out.printLine(\"respectable\");\n else\n out.printLine(\"ugly\");\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return 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\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n}\n\nclass IOUtils {\n\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 }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f2586469f3f78eec8620d78859ac8e9d", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "//Chores\n\nimport java.util.*;\n\npublic class Point implements Comparable {\n\tpublic Integer x;\n\tpublic Integer y;\n\n\tpublic Point(int x, int y) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t}\n\n\t@Override\n\tpublic int compareTo(Point p) {\n\t\tif (this.x != p.x)\n\t\t\treturn this.x.compareTo(p.x);\n\t\treturn this.y.compareTo(p.y);\n\t}\n}\n\npublic class HW {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint u, v;\n\t\tList a = new ArrayList<>();\n\t\tList x = new ArrayList<>();\n\t\tList y = new ArrayList<>();\n\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tu = sc.nextInt();\n\t\t\tv = sc.nextInt();\n\t\t\tPoint p = new Point(u, v);\n\n\t\t\ta.add(p);\n\n\t\t\tif (!x.contains(u)) {\n\t\t\t\tx.add(u);\n\t\t\t}\n\n\t\t\tif (!y.contains(v)) {\n\t\t\t\ty.add(v);\n\t\t\t}\n\t\t}\n\n\t\tif (x.size() != 3 || y.size() != 3){\n\t\t\tSystem.out.print(\"ugly\");\n\t\t\treturn;\n\t\t}\n\n\t\tCollections.sort(x);\n\t\tCollections.sort(y);\n\t\tCollections.sort(a);\n\n\n\t\tint k = 0;\n\t\tboolean flag = true;\n\t\tfor (int i=0;i<3;i++)\n\t\t\tfor (int j=0;j<3;j++){\n\t\t\t\tif (i == 1 && j == 1)\n\t\t\t\t\tcontinue;\n\t\t\t\tif (a.get(k).x != x.get(i) || a.get(k).y != y.get(j))\n\t\t\t\t\tflag = false;\n\t\t\t\tk++;\n\t\t\t}\n\n\t\tif (flag)\n\t\t\tSystem.out.print(\"respectable\");\n\t\telse\n\t\t\tSystem.out.print(\"ugly\");\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d6397691a059fcf61a9e6c6da0d01b5f", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Lecture3_Eight_Point_Sets {\n private static class Point implements Comparable {\n int x, y;\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n public int compareTo(Point o) {\n if (x == o.x && y == o.y)\n return 0;\n return (x < o.x || (x == o.x && y < o.y)) ? -1 : 1;\n }\n }\n public static void main(String[] args) {\n Scanner inp = new Scanner(System.in);\n Point[] A = new Point[8];\n for(int i = 0; i < 8; i++)\n A[i] = new Point(inp.nextInt(), inp.nextInt());\n inp.close();\n Arrays.sort(A);\n boolean isUgly = false;\n for(int i = 1; i < 3; i++) {\n if (A[i].x != A[i - 1].x || A[i + 5].x != A[i + 4].x) \n isUgly = true;\n if (A[i].y == A[i - 1].y)\n isUgly = true;\n if (A[i].y != A[i + 5].y || A[i - 1].y != A[i + 4].y) \n isUgly = true;\n }\n if (A[4].x != A[3].x)\n isUgly = true;\n if (A[3].x == A[2].x || A[5].x == A[4].x)\n isUgly = true;\n if (A[1].y == A[0].y || A[2].y == A[1].y)\n isUgly = true;\n if (A[0].y != A[3].y) || A[2].y != A[4].y)\n isUgly = true;\n if (isUgly)\n System.out.print(\"ugly\");\n else\n System.out.print(\"respectable\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "75065bbc79495957cae0ea518bc4e6fd", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n static final int mod = 1000000007;\n static Boolean[] canReach;\n static int k, parent[];\n static int ans;\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 n = sc.nextInt();\n k = sc.nextInt();\n generatePermutations(0, \"\");\n for (int i = k + 1; i <= n; i++)\n ans = (int) ((1l * ans * (n - k)) % mod);\n out.println(ans);\n out.flush();\n out.close();\n }\n\n static void generatePermutations(int i, String perm) {\n if (i == k) {\n char[] options = perm.toCharArray();\n parent = new int[k + 1];\n canReach = new Boolean[k + 1];\n for (int j = 1; j <= k; j++)\n parent[j] = options[j - 1] - '0';\n boolean add = true;\n for (int j = 1; j <= k; j++)\n add &= canReach(j);\n if (add) ans++;\n return;\n }\n for (int j = 1; j <= k; j++) {\n String tmp = perm + j;\n generatePermutations(i + 1, tmp);\n }\n\n }\n\n static boolean canReach(int i) {\n if (canReach[i] != null) return canReach[i];\n if (i == 1) return true;\n canReach[i] = false;\n return canReach[i] = canReach(parent[i]);\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\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0eda11563d52da430b6bfe850d93a188", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t long M = 1000000007; \n long long res = 1;\n Scanner in = new Scanner(System.in);\n\t int n = in.nextInt();\n\t int k = in.nextInt();\n for (int i = 0; i < k - 1; i++)\n res = (res * k) % M;\n for (int i = 0; i < n - k; i++)\n res = (res * (n - k)) % M;\n\t System.out.println(res); \n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f3fa3dcb9e0013821c8c707fd86372d5", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n\u00a0 \u00a0 public static void main(String[] Args) throws NumberFormatException,\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 IOException {\n\u00a0 \u00a0 \u00a0 \u00a0 new Solver().Run();\n\n\u00a0 \u00a0 }\n\n\u00a0 \u00a0 PrintWriter pw;\n\u00a0 \u00a0 StringTokenizer Stok;\n\u00a0 \u00a0 BufferedReader br;\n\n\u00a0 \u00a0 public String nextToken() throws IOException {\n\u00a0 \u00a0 \u00a0 \u00a0 while (Stok == null || !Stok.hasMoreTokens()) {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Stok = new StringTokenizer(br.readLine());\n\u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 return Stok.nextToken();\n\u00a0 \u00a0 }\n\n\u00a0 \u00a0 public int nextInt() throws NumberFormatException, IOException {\n\u00a0 \u00a0 \u00a0 \u00a0 return Integer.parseInt(nextToken());\n\u00a0 \u00a0 }\n\n\u00a0 \u00a0 public double nextDouble() throws NumberFormatException, IOException {\n\u00a0 \u00a0 \u00a0 \u00a0 return Double.parseDouble(nextToken());\n\u00a0 \u00a0 }\n\n\u00a0 \u00a0 public long nextLong() throws NumberFormatException, IOException {\n\u00a0 \u00a0 \u00a0 \u00a0 return Long.parseLong(nextToken());\n\u00a0 \u00a0 }\n\n\u00a0 \u00a0\n\u00a0 \u00a0 public void Run() throws NumberFormatException, IOException {\n\u00a0 \u00a0 \u00a0 \u00a0 // br = new BufferedReader(new FileReader('input.txt'));\n\u00a0 \u00a0 \u00a0 \u00a0 // pw = new PrintWriter('output.txt');\n\u00a0 \u00a0 \u00a0 \u00a0 br = new BufferedReader(new InputStreamReader(System.in));\n\u00a0 \u00a0 \u00a0 \u00a0 pw = new PrintWriter(new OutputStreamWriter(System.out));\n\u00a0 \u00a0\n\u00a0 \u00a0 \u00a0 \u00a0 int n = nextInt(), k = nextInt();\n\u00a0 \u00a0 \u00a0 \u00a0 long res = 1;\n\u00a0 \u00a0 \u00a0 \u00a0 for ( int i = 1; i < k; i++){\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0res *= k;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0if (res > 1000000009)\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 res %= 1000000009;\n\u00a0 \u00a0 \u00a0 \u00a0 }\u00a0\n\u00a0 \u00a0 \u00a0 \u00a0 for ( int i = 1; i <= n-k; i++){\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 res *= n-k;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (res > 1000000009)\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 res %= 1000000009;\n\u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 pw.print(res);\n\u00a0 \u00a0 \u00a0 \u00a0 pw.flush();\n\u00a0 \u00a0 \u00a0 \u00a0 pw.close();\n\n\u00a0 \u00a0 }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ac6e987e0fd48f9465450c0e50424230", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport static syntax.Sugar.*;\n\nimport java.math.*;\nimport java.util.*;\n\n@SuppressWarnings(\"unused\")\npublic class B {\n\n\tprivate final static boolean autoflush = false;\n\n\tprivate final static int MOD = (int) 1e9 + 7;\n\tprivate final static double eps = 1e-9;\n\tprivate final static int INF = (int) 1e9;\n\n\tpublic B () {\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt();\n\n\t\tlong res = modPow(N-K, N-K);\n\t\tif (K == 1)\n\t\t\texit(res);\n\n\t\tint B = K-1; long Q = 0;\n\t\tint S = (int)modPow(B, B);\n\t\tout: for (int Z : rep(S)) {\n\t\t\tint [] C = digits(Z, B, K);\n\t\t\tfor (int i : rep (1, K))\n\t\t\t\tif (C[i] >= i)\n\t\t\t\t\t++C[i];\n\t\t\tint [] G = new int [K]; G[0] = 1;\n\t\t\tfor (int i : rep(1, K))\n\t\t\t\tif (dfs(i, C, G) == -1)\n\t\t\t\t\tcontinue out;\n\t\t\t++Q;\n\t\t}\n\n\t\tQ = mod(Q * K);\n\t\tres = mod(res * Q);\n\t\texit(res);\n\t}\n\n\tint dfs(int i, int [] C, int [] G) {\n\t\tif (G[i] != 0)\n\t\t\treturn G[i];\n\t\tG[i] = -1;\n\t\treturn G[i] = dfs(C[i], C, G);\n\t}\n\n\tint [] 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\n\tprivate static BigInteger BMOD = valueOf(MOD);\n\n\tprivate static long modPow(long b, long e) {\n\t\treturn valueOf(b).modPow(valueOf(e), BMOD).longValue();\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) {\n\t\treturn new int [] { -D[1], D[0] };\n\t}\n\tprivate static int [] cw (int [] D) {\n\t\treturn new int [] { D[1], -D[0] };\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 max(T x, T y) {\n\t\treturn x.compareTo(y) > 0 ? x : y;\n\t}\n\tprivate static long mod(long x) {\n\t\treturn ((x % MOD) + MOD) % MOD;\n\t}\n\tprivate static long mod(long x, long mod) {\n\t\treturn ((x % mod) + mod) % mod;\n\t}\n\tprivate static String reverse (String S) {\n\t\treturn new StringBuilder(S).reverse().toString();\n\t}\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 B();\n\t\texit();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "acb477af26434f7b6c7c4331f9ac0bf4", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\npublic class ProblemB {\n int M = 200;\n int P = 1000000007;\n int[][] choose = new int[M+1][M+1]; // stores (n choose k)\n\n void run() {\n // initalize pascals triangle\n choose[0][0] = 1;\n for (int n = 1; n <= M; ++n) {\n choose[n][0] = 1;\n choose[n][n] = 1;\n for (int k = 1; k < n; ++k) {\n choose[n][k] = (choose[n-1][k-1] + choose[n-1][k]) % P;\n }\n }\n\n Scanner sc = new Scanner(System.in);\n int N = sc.nextInt();\n int[] vals = new int[10];\n for (int i = 0; i < 10; ++i) {\n vals[i] = sc.nextInt();\n }\n int minDigits = 0;\n for (int a: vals) {\n minDigits += a;\n }\n long total = 0;\n for (int n = min(minDigits, 1); n <= N; ++n) { // actual length\n for (int i = 1; i < 10; ++i) { // leading digit\n int[] newvals = new int[10];\n for (int j = 0; j < 10; ++j) {\n newvals[j] = vals[j];\n }\n if (newvals[i] > 0) {\n --newvals[i];\n }\n d(\"solving\", newvals, n);\n total += solve(newvals, n-1);\n }\n }\n p(\"%d\\n\", (total % P));\n }\n\n int solve(int[] vals, int n) {\n // dp[i][k] is how many ways with only first i characters, length k\n int[][] dp = new int[11][n+1];\n dp[0][0] = 1;\n for (int i = 1; i <= 10; ++i) {\n int d = i-1; // i-th digit (so i=1 gives d=0)\n for (int k = 0; k <= n; ++k) {\n int total = 0;\n // take r of character d\n for (int r = vals[d]; r <= k; ++r) {\n long choices = choose[k][r];\n long sub = dp[i-1][k-r];\n long num = (choices * sub) % P;\n total = (total + ((int) num)) % P;\n }\n dp[i][k] = total;\n }\n }\n int res = dp[10][n];\n d(\"returning\", res);\n return res;\n }\n\n boolean debug = false;\n void p(String f, Object...params) {\n System.out.printf(f, params);\n }\n void d(Object...params) {\n if (debug) {\n p(\"DEBUG: %s\\n\", Arrays.deepToString(params));\n }\n }\n public ProblemB(String[] args) {\n if (args.length > 0 && args[0].equals(\"debug\")) {\n debug = true;\n }\n }\n public static void main(String[] args) {\n new ProblemB(args).run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd38f90a809382c3f4261e0c6ee7e515", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import static java.lang.Integer.max;\n\nimport java.math.BigInteger;\n\nimport java.util.Map;\n\nimport java.util.Scanner;\n\nimport java.util.TreeMap;\n\n\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner in;\n\n in = new Scanner(System.in);\n\n int [] a =new int [20];\n\n int [][] C =new int [110][110];\n\n int [][] dp =new int [110][110];\n\n int n=in.nextInt();\n\n int mod=1000000007;\n\n\tfor(int i=0;i<10;i++) a[i]=in.nextInt();\n\n int NN=110;\n\n\tfor(int i=0;ii){\n\n C[i][j]=0;\n\n continue;\n\n\t\t}\n\n\t\tif(j==0){\n\n C[i][j]=1;\n\n continue;\n\n\t\t}\n\n\t\tif(i==j){\n\n C[i][j]=1;\n\n continue;\n\n\t\t}\n\n\t\tC[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;\n\n }\n\n\t}\n\n\tfor(int i=9;i>=0;i--){\n\n for(int len=0;len<=n;len++){\n\n\t\tif(i==9){\n\n if(len 0) {\n --newvals[i];\n }\n d(\"solving\", newvals, n);\n total += solve(newvals, n-1);\n }\n }\n p(\"%d\\n\", (total % P));\n }\n\n int solve(int[] vals, int n) {\n // dp[i][k] is how many ways with only first i characters, length k\n int[][] dp = new int[11][n+1];\n dp[0][0] = 1;\n for (int i = 1; i <= 10; ++i) {\n int d = i-1; // i-th digit (so i=1 gives d=0)\n for (int k = 0; k <= n; ++k) {\n int total = 0;\n // take r of character d\n for (int r = vals[d]; r <= k; ++r) {\n long choices = choose[k][r];\n long sub = dp[i-1][k-r];\n long num = (choices * sub) % P;\n total = (total + ((int) num)) % P;\n }\n dp[i][k] = total;\n }\n }\n int res = dp[10][n];\n d(\"returning\", res);\n return res;\n }\n\n boolean debug = false;\n void p(String f, Object...params) {\n System.out.printf(f, params);\n }\n void d(Object...params) {\n if (debug) {\n p(\"DEBUG: %s\\n\", Arrays.deepToString(params));\n }\n }\n public ProblemB(String[] args) {\n if (args.length > 0 && args[0].equals(\"debug\")) {\n debug = true;\n }\n }\n public static void main(String[] args) {\n new ProblemB(args).run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a76c6c576c2b07405c6994410a4bbec1", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.PrintStream;\nimport java.util.Scanner;\n\n/**\n * @author Roman Elizarov\n */\npublic class Round_131_B {\n\tprivate static final int MOD = 1000000007;\n\n\tpublic static void main(String[] args) {\n\t\tnew Round_131_B().go();\n\t}\n\n\tint n;\n\tint[] a;\n\n\tvoid go() {\n\t\t// read input\n\t\tScanner in = new Scanner(System.in);\n\t\tn = in.nextInt();\n\t\ta = new int[10];\n\t\tfor (int i = 0; i < 10; i++)\n\t\t\ta[i] = in.nextInt();\n\n\t\t// solve\n\t\tint result = solve();\n\n\t\t// write result\n\t\tPrintStream out = System.out;\n\t\tout.println(result);\n\t}\n\n\tint[][] c;\n\n\tint solve() {\n\t\tc = new int[101][101];\n\t\tc[0][0] = 1;\n\t\tfor (int i = 1; i <= 100; i++) {\n\t\t\tc[i][0] = 1;\n\t\t\tfor (int j = 1; j <= 100; j++)\n\t\t\t\tc[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;\n\t\t}\n\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < 10; i++)\n\t\t\tsum += a[i];\n\t\tint res = 0;\n\t\tfor (int len = Math.max(1, sum); len <= n; len++) {\n\t\t\tfor (int fst = 1; fst < 10; fst++) {\n\t\t\t\tint slots = len - 1;\n\t\t\t\tint minSum = sum;\n\t\t\t\tif (a[fst] > 0)\n\t\t\t\t\tminSum--;\n\t\t\t\tint combos = compute(0, fst, minSum, slots);\n\t\t\t\tres = (res + combos) % MOD;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tprivate int compute(int i, int fst, int minSum, int slots) {\n\t\tif (minSum > slots)\n\t\t\treturn 0;\n\t\tif (i == 10)\n\t\t\treturn slots == 0 ? 1 : 0;\n\t\tint min = a[i];\n\t\tif (min > 0 && i == fst)\n\t\t\tmin--;\n\t\tint res = 0;\n\t\tfor (int k = min; k <= slots; k++)\n\t\t\tres = (res + mul(compute(i + 1, fst, minSum - min, slots - k), c[slots][k])) % MOD;\n\t\treturn res;\n\t}\n\n\tprivate int mul(long a, long b) {\n\t\treturn (int)((a * b) % MOD);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d5b933be295230214a2c0db00c84dd5", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.*;\n\npublic class C {\n\n MyScanner in;\n PrintWriter out;\n\n public static void main(String[] args) throws Exception {\n new C().run();\n }\n\n public void run() throws Exception {\n in = new MyScanner();\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n public void solve() throws Exception {\n char[] a = in.next().toCharArray();\n int[] chars = new int[26];\n for (int i = 0; i < 6; i++) {\n chars[a[i] - 'A']++;\n }\n int[] nums = new int[6];\n int k = 0;\n for (int i = 0; i < 26; i++) {\n if (chars[i] != 0) {\n nums[k++] = chars[i];\n }\n }\n Arrays.sort(nums);\n String code = Arrays.toString(nums);\n if (code.equals(\"[0, 0, 0, 0, 0, 6]\")) {\n out.println(\"1\");\n } else if (code.equals(\"[0, 0, 0, 0, 3, 3]\")) {\n out.println(\"2\"); \n } else if (code.equals(\"[0, 0, 0, 0, 2, 4]\")) {\n out.println(\"2\"); \n } else if (code.equals(\"[0, 0, 0, 2, 2, 2]\")) {\n out.println(\"5\"); \n } else if (code.equals(\"[0, 0, 0, 0, 1, 5]\")) {\n out.println(\"1\"); \n } else if (code.equals(\"[0, 0, 0, 1, 2, 3]\")) {\n out.println(\"3\"); \n } else if (code.equals(\"[0, 0, 0, 1, 1, 4]\")) {\n out.println(\"2\"); \n } else if (code.equals(\"[0, 0, 1, 1, 2, 2]\")) {\n out.println(\"8\"); \n } else if (code.equals(\"[0, 0, 1, 1, 1, 3]\")) {\n out.println(\"5\"); \n } else if (code.equals(\"[0, 1, 1, 1, 1, 2]\")) {\n out.println(\"15\"); \n } else if (code.equals(\"[1, 1, 1, 1, 1, 1]\")) {\n out.println(\"30\"); \n } \n }\n\n class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() throws Exception {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() throws Exception {\n while ((st == null) || (!st.hasMoreTokens())) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n\n double nextDouble() throws Exception {\n return Double.parseDouble(next());\n }\n\n boolean nextBoolean() throws Exception {\n return Boolean.parseBoolean(next());\n }\n\n long nextLong() throws Exception {\n return Long.parseLong(next());\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0971cd33d5d27944c127e2f5108caf9d", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Problem {\n\t\n\tstatic boolean nextPermutation(char[] a)\n {\n int n = a.length;\n int i = n-2;\n while(i >= 0 && a[i] >= a[i+1]) {\n i--;\n }\n if(i < 0) {\n return false;\n }\n for(int j = n-1; j >= i; j--){\n if(a[j] > a[i]){\n char temp = a[i];\n a[i] = a[j];\n a[j] = temp;\n break; \n }\n }\n for(int j = i+1; j < (n+i+1)/2; j++){\n char temp = a[j];\n a[j] = a[n+i-j];\n a[n+i-j] = temp;\n }\n return true;\n }\n\t\n\tstatic char ref;\n\tstatic int[][] neigh = new int[][] {{1,2,4,3},{0,2,5,3},{0,1,5,4},{0,1,5,4},{0,2,5,3},{1,2,4,3}};\n\t\n\tstatic boolean equals(String a, String b){\n\t\tfor(int i = 0; i < 6; i++){\n\t\t\tif(a.charAt(i) == ref){\n\t\t\t\tfor(int j = 0; j < 6; j++){\n\t\t\t\t\tif(b.charAt(j) == ref){\n\t\t\t\t\t\tfor(int start = 0; start < 4; start++){\n\t\t\t\t\t\t\tboolean ok = true;\n\t\t\t\t\t\t\tfor(int k = 0; k < 4; k++){\n\t\t\t\t\t\t\t\tif(a.charAt(neigh[i][k]) != b.charAt(neigh[j][(start+k)%4])){\n\t\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(ok){\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}\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\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tchar[] input = in.next().toCharArray();\n\t\tArrays.sort(input);\n\t\tref = input[0];\n\t\tLinkedList counter = new LinkedList();\n do {\n \tString cur = new String(input);\n \tboolean ok = true;\n \tfor(String str : counter){\n \t\tif(equals(str, cur)){\n \t\t\tok = false;\n \t\t\tbreak;\n \t\t}\n \t}\n \tif(ok) counter.addLast(cur);\n }while(nextPermutation(input));\n System.out.println(counter.size());\n\t}\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "14f2a82fe808af8e163f6731ba5ccd7b", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.*; \nimport java.io.*; \nimport java.math.*; \n\npublic class Main { \n \n char[] tmp;\n boolean[] vist;\n char[] str;\n Set S;\n private void dfs(int t) {\n if (t == 6) {\n Node l = new Node();\n for (int i = 0; i < 6; ++i) {\n l.str[i] = this.str[i];\n }\n S.add(l);\n }\n for (int i = 0; i < 6; ++i) {\n if (vist[i]) continue;\n str[t] = tmp[i];\n vist[i] = true;\n dfs(t + 1);\n vist[i] = false;\n }\n }\n \n public void run() { \n S = new TreeSet();\n tmp = cin.next().toCharArray();\n vist = new boolean[6];\n str = new char[6];\n dfs(0);\n int ans = S.size();\n if (ans != 1) --ans;\n System.out.println(ans);\n } \n\n public static void main(String[] argv) { \n new Main().run(); \n } \n\n Scanner cin = new Scanner(System.in); \n} \n\nclass Node implements Comparable{\n char[] str = new char[6];\n static int[][] dir = { \n {1, 2, 3, 4, 5},\n {5, 2, 0, 4, 3},\n {1, 5, 3, 0, 4},\n {0, 2, 5, 4, 1},\n {1, 0, 3, 5, 2},\n {1, 4, 3, 2, 0}\n };\n public int compareTo(Node o) {\n \n for (int i = 0; i < 6; ++i) {\n for (int j = 0; j < 1; ++j) {\n if (o.str[i] == str[j]) {\n if (o.str[dir[i][4]] == str[dir[j][4]]) {\n char[] t1 = new char[4];\n char[] t2 = new char[4];\n for (int k = 0; k < 4; ++k) {\n t1[k] = o.str[dir[i][k]];\n t2[k] = str[dir[j][k]];\n }\n Arrays.sort(t1);\n Arrays.sort(t2);\n for (int k = 0; k < 4; ++k) {\n if (t1[k] != t2[k]) {\n break;\n }\n if (k == 3) {\n return 0;\n }\n \n }\n }\n }\n }\n }\n for (int i = 0; i < 6; ++i) {\n if (str[i] != o.str[i]) {\n return str[i] - o.str[i];\n }\n }\n return -1;\n }\n public String toString() {\n StringBuilder st = new StringBuilder();\n for (int i = 0; i < 6; ++i) {\n st.append(str[i]);\n }\n return st.toString();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a7f5a9bdebb1cf6feb7d7fd0a829442c", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class _98A {\n public static void main(String[] args) {\t\n\tScanner input = new Scanner(System.in);\n\n\tint a[] = {0,0,0,0,0,0};\n\tString s = input.next();\n\tfor (int i = 0; i < 6; i++)\n\t if (s.charAt(i) == 'R')\n\t\ta[0]++;\n\t else if (s.charAt(i) == 'O')\n\t\ta[1]++;\n\t else if (s.charAt(i) == 'Y')\n\t\ta[2]++;\n\t else if (s.charAt(i) == 'G')\n\t\ta[3]++;\n\t else if (s.charAt(i) == 'B')\n\t\ta[4]++;\n\t else if (s.charAt(i) == 'V')\t\t\n\t\ta[5]++;\n\t\n\tint ans =0;\n\tint num = 0;\n\tfor (int i = 0; i < 6; i++)\n\t if (a[i] > 0)\n\t\tnum++;\n\tif (num == 1)\n\t ans = 1;\n\tif (num == 2) { // (5,1) (4,2) (3,3)\n\t for (int i = 0; i < 6; i++)\n\t\tif (a[i] == 5)\n\t\t ans = 1;\n\t\telse if (a[i] == 4)\n\t\t ans = 2;\n\t\telse if (a[i] == 3)\n\t\t ans = 3;\n\t}\n\tif (num == 3) { // (4,1,1) (3,2,1) \n\t boolean mode = false;\n\t for (int i = 0; i < 6; i++)\n\t\tif (a[i] == 4)\n\t\t mode = true;\n\t if (mode)\n\t\tans = 2;\n\t else\n\t\tans = 8;\n\t}\n\tif (num == 4) { // (3,1,1,1) (2,2,1,1)\n\t boolean mode = false;\n\t for (int i = 0; i < 6; i++)\n\t\tif (a[i] == 3)\n\t\t mode = true;\n\t if (mode) \n\t\tans = 15;\n\t else \n\t\tans = 8;\n\t}\n\tif (num == 5) {\n\t ans = 6 + 12;\n\t}\n\tif (num == 6)\n\t ans = 30;\n\tSystem.out.println(ans);\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4b081dd0042edc345658c482e56e977", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "public class Main {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int k = scanner.nextInt();\n int ans = n*5 % k == 0 ? n*5/k : n*5/k + 1;\n int ans2 = n*2%k == 0 ? n*2/k : n*2/k + 1;\n int ans3 = n*8%k == 0 ? n*8/k : n*8/k + 1;\n System.out.println(ans + ans2 + ans3);\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "77ce416cd1f05910fa7c62e8842330a5", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class CF1080A\n{\n\tBufferedReader in = new BufferedReader(System.in);\n\tStringTokenizer st = new StringTokenizer(in.readLine());\n\tint n = Integer.parseInt(st.nextToken());\n\tint k = Integer.parseInt(st.nextToken());\n\t\n\tint redS = n * 2;\n\tint greenS = n * 5;\n\tint blueS = n * 8;\n\t\n\tint redN = redS / k;\n\tint greenN = greenS / k;\n\tint blueN = blueS / k;\n\t\n\tif(redS % k != 0) redN++;\n\tif(greenS % k != 0) greenN++;\n\tif(blueS % k != 0) blueN++;\n\t\n\tSystem.out.println(redN + greenN + blueN);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3c7d022248c21f46a71aaf46f6ca61b2", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class A1080{\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int k = scan.nextInt();\n int red = 2*n;\n int blue = 8 * n;\n int green = 5 * n;\n double r = red/k;\n double g = green/n;\n double b = blue/n;\n System.out.println((Math.ceil(r));\n //int output = int(Math.ceil(r) + Math.ceil(g) + Math.ceil(b));\n //System.out.println(output);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "92b18ab7315d0ba507755e2f1c1768d1", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class PetyaOrigami{\n\tpublic static void main(String args[]){\n\t\tScanner kbd = new Scanner(System.in);\n\t\tint n = Integer.parseInt(kbd.next());\n\t\tint c = Integer.parseInt(kbd.next());\n\t\tint kol = ((n*2+k-1)/k) + ((n*5+k-1)/k) + ((n*8+k-1)/k)\n\t\tSystem.out.println(kol);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "03b5bdcd00b001b5278eae178493a634", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Div1_462D {\n\n\tstatic final long MOD = 1_000_000_007;\n\n\tstatic final long INV6 = 166_666_668;\n\tstatic final long INV30 = 233_333_335;\n\tstatic final long INV42 = 23_809_524;\n\n\tstatic long[] polyC;\n\n\tstatic final long[][] comb = { { 1 }, { 1, 1 }, { 1, 2, 1 }, { 1, 3, 3, 1 } };\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tlong N = Long.parseLong(reader.readLine());\n\t\tlong SQRTN = (long) Math.sqrt(N);\n\n\t\tlong nModded = N % MOD;\n\n\t\tpolyC = new long[] { nModded * (nModded + 1) % MOD * (nModded + 2) % MOD * INV6 % MOD,\n\t\t\t\t(3 * nModded % MOD + 4) % MOD * INV6 % MOD, (-3 * nModded % MOD - 6 + 4 * MOD) % MOD * INV6 % MOD,\n\t\t\t\t2 * INV6 % MOD };\n\n\t\tlong[] powC = new long[4];\n\n\t\tlong[] powXSQ = new long[4];\n\n\t\tlong sum = 0;\n\t\tfor (long x = -SQRTN; x <= SQRTN; x++) {\n\t\t\tArrays.fill(powC, 0);\n\t\t\tlong XSQ = x * x % MOD;\n\n\t\t\tpowXSQ[0] = 1;\n\t\t\tpowXSQ[1] = XSQ;\n\t\t\tpowXSQ[2] = powXSQ[1] * XSQ % MOD;\n\t\t\tpowXSQ[3] = powXSQ[2] * XSQ % MOD;\n\n\t\t\tfor (int term = 0; term <= 3; term++) {\n\t\t\t\tfor (int subT = 0; subT <= term; subT++) {\n\t\t\t\t\t// subT is power of y^2\n\t\t\t\t\tlong cCoeff = powXSQ[term - subT] * comb[term][subT] * polyC[term] % MOD;\n\t\t\t\t\tpowC[subT] = (powC[subT] + cCoeff) % MOD;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlong YMAX = (long) Math.sqrt(N - x * x);\n\t\t\tsum = (sum + powC[3] * 2 * sumSixths(YMAX)) % MOD;\n\t\t\tsum = (sum + powC[2] * 2 * sumFourths(YMAX)) % MOD;\n\t\t\tsum = (sum + powC[1] * 2 * sumSquares(YMAX)) % MOD;\n\t\t\tsum = (sum + powC[0] * ((2 * YMAX + 1) % MOD)) % MOD;\n\t\t}\n\t\tprinter.println(sum);\n\t\tprinter.close();\n\t}\n\n\tstatic long sumSquares(long N) {\n\t\treturn N * (N + 1) % MOD * (2 * N + 1) % MOD * INV6 % MOD;\n\t}\n\n\tstatic long sumFourths(long N) {\n\t\treturn N * (N + 1) % MOD * (2 * N + 1) % MOD * ((3 * N * (N + 1) - 1) % MOD) % MOD * INV30 % MOD;\n\t}\n\n\tstatic long sumSixths(long N) {\n\t\treturn N * (N + 1) % MOD * (2 * N + 1) % MOD * ((3 * N * (N + 1) % MOD * ((N * N + N - 1) % MOD) + 1) % MOD)\n\t\t\t\t% MOD * INV42 % MOD;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6adc96fd27d97f50526572d981d00587", "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.File;\nimport java.util.ArrayList;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 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 int mod = 1000000007;\n public long inv6 = Utils.inv(6, mod);\n public long inv60 = Utils.inv(60, mod);\n\n public long sum2(long from, long to, long X, long a) {\n long ret = inv6;\n ret = ret * (from - to - 1 + mod) % mod;\n long a1 = 2 * from * from % mod - from + to + 2 * to * to % mod + 2 * from * to % mod;\n a1 %= mod;\n if (a1 < 0) a1 += mod;\n a1 = a1 * a % mod;\n a1 = a1 - 3 * X * (from + to) % mod;\n a1 %= mod;\n if (a1 < 0) a1 += mod;\n return ret * a1 % mod;\n\n }\n\n public long sum1(long from, long to, long m, long a) {\n long ret = inv60;\n ret = ret * a % mod * (a + 1) % mod * (2 * a + 1) % mod * (from - to - 1 + mod) % mod;\n long inner = 6 * a * a % mod + 6 * a % mod + 5 * from % mod - 10 * m % mod + 5 * to % mod - 12;\n inner %= mod;\n if (inner < 0) inner += mod;\n return ret * inner % mod;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long m = in.nextLong();\n long mm = m % mod;\n long base = mm * (mm + 1) % mod * (mm + 2) % mod * inv6 % mod;\n ArrayList a1 = new ArrayList<>();\n ArrayList a2 = new ArrayList<>();\n long sk = 0, sa = 0;\n for (int k = 1; 1L * k * k <= m; k++) {\n a1.add(1L * k * k);\n a2.add(m - 1L * k * k + 1);\n sa++;\n sk = (sk + 1L * k * k) % mod;\n }\n a1.add(m + 1);\n Collections.reverse(a2);\n long start = System.currentTimeMillis();\n ArrayList ss = new ArrayList<>();\n int i1 = 0, i2 = 0;\n while (i1 < a1.size() && i2 < a2.size()) {\n if (a1.get(i1) < a2.get(i2)) ss.add(a1.get(i1++));\n else ss.add(a2.get(i2++));\n }\n while (i1 < a1.size()) ss.add(a1.get(i1++));\n while (i2 < a2.size()) ss.add(a2.get(i2++));\n Collections.sort(ss);\n Debug.print(System.currentTimeMillis() - start);\n\n long sqrtval = 1;\n long ans = 0;\n for (int i = 0; i < ss.size() - 1; i++) {\n long from = ss.get(i), to = ss.get(i + 1) - 1;\n if (from > to) continue;\n\n while ((sqrtval + 1) * (sqrtval + 1) <= to) sqrtval++;\n while ((m - sa * sa) < to) {\n sk = (sk - sa * sa) % mod;\n if (sk < 0) sk += mod;\n sa--;\n }\n from %= mod;\n to %= mod;\n long X = (sa + 1) * (mm + 1) % mod - sk;\n if (X < 0) X += mod;\n long add = sum1(from, to, mm, sa) + sum2(from, to, X, sa + 1);\n add = add * sqrtval % mod;\n add %= mod;\n ans = (ans + add) % mod;\n\n }\n// for (int n = 1; n <= m; n++) {\n// for (int k = 0; k * k <= n; k++) {\n// ans += (int)(Math.sqrt(n-k*k)) * n * (m - n + 1);\n// }\n// }\n ans *= 4;\n ans += base;\n out.println(ans % mod);\n }\n\n }\n\n static class Debug {\n public static boolean DEBUG;\n\n static {\n try {\n DEBUG = System.getProperty(\"user.dir\").contains(\"Dropbox\");\n } catch (Exception e) {\n DEBUG = false;\n }\n }\n\n private static ArrayList getParams() {\n StackTraceElement[] t = new Exception().getStackTrace();\n StackTraceElement up = t[2];\n\n ArrayList ret = new ArrayList<>();\n ret.add(up.getFileName() + \"/\" + up.getMethodName());\n try {\n BufferedReader br = new BufferedReader(new FileReader(\n new File(\"src/\" + up.getClassName().replaceAll(\"\\\\.\", \"/\") + \".java\")));\n int g = up.getLineNumber();\n while (--g > 0) br.readLine();\n String q = br.readLine();\n String[] ss = q.split(\"Debug\\\\.print\\\\(\");\n String[] qq = ss[1].substring(0, ss[1].indexOf(\")\")).split(\",\");\n for (int i = 0; i < qq.length; i++) {\n ret.add(qq[i].trim());\n }\n } catch (Exception e) {\n }\n for (int i = 0; i < 100; i++) ret.add(\"???\");\n return ret;\n }\n\n private static String toString(Object o) {\n if (o instanceof Object[]) {\n return Arrays.toString((Object[]) o);\n } else if (o instanceof char[]) {\n return new String((char[]) o);\n } else if (o instanceof int[]) {\n return Arrays.toString((int[]) o);\n } else if (o instanceof long[]) {\n return Arrays.toString((long[]) o);\n } else if (o instanceof double[]) {\n return Arrays.toString((double[]) o);\n } else {\n return o.toString();\n }\n }\n\n public static void print(Object x) {\n if (!DEBUG) return;\n ArrayList s = getParams();\n System.out.println(s.get(0) + \": \" + s.get(1) + \" = \" + toString(x));\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class Utils {\n public static long inv(long N, long M) {\n long x = 0, lastx = 1, y = 1, lasty = 0, q, t, a = N, b = M;\n while (b != 0) {\n q = a / b;\n t = a % b;\n a = b;\n b = t;\n t = x;\n x = lastx - q * x;\n lastx = t;\n t = y;\n y = lasty - q * y;\n lasty = t;\n }\n return (lastx + M) % M;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public long nextLong() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n long res = 0L;\n\n while (c >= 48 && c <= 57) {\n res *= 10L;\n res += (long) (c - 48);\n c = this.read();\n if (isSpaceChar(c)) {\n return res * (long) sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c63ee74dbc8c91085b82fc26317c150a", "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces933D {\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tlong n = Long.parseLong(st.nextToken());\n\t\t\n\t\tint counter = 0;\n\t\tint N = 1000000007;\n\t\t\n\t\tfor (int i = 0; i < 500000; i++) {\n\t\t\tcounter += firstsum(n, 4*i+1);\n\t\t\tcounter -= firstsum(n, 4*i+3);\n\t\t\tcounter %= N;\n\t\t}\n\t\t\n\t\tfor (int b = 1; b <= n/2000000; b++) {\n\t\t\tcounter += secondsum(n, b);\n\t\t\tcounter %= N;\n\t\t}\n\t\t\t\t\n\t\tint ans = (2*((2*counter)%N))%N;\n\t\tlong k = ((((((n%N)*(n%N+1))%N)*(n%N+2))%N)*166666668)%N;\n\t\tans = (ans + (int) k)%N;\n\t\tSystem.out.println(ans);\n\t}\n\t\n\t//1/2 = 500000004\n\t//1/3 = 333333336\n\t//1/6 = 166666668\n\t//lmao\n\tpublic static int firstsum(long n, long q) {\n\t\tint N = 1000000007;\n\t\tlong floornq = (n/q)%N;\n\t\tn %= N;\n\t\tq %= N;\n\t\tlong sum = ((floornq*(floornq+1))/2)%N;\n\t\tlong sumsquare = (((sum*(2*floornq+1))%N)*333333336)%N;\n\t\tlong sumcube = (sum*sum)%N;\n\t\tlong nsquare = (n*n)%N;\n\t\tlong qsquare = (q*q)%N;\n\t\tlong qcube = (q*qsquare)%N;\n\t\t\n\t\tlong k1 = (nsquare*floornq - qsquare*sumsquare + n*floornq + q*sum)%N;\n\t\tif (k1 < 0)\n\t\t\tk1 += N;\n\t\tk1 = (k1*(n+1))%N;\n\t\tk1 = (k1*500000004)%N;\n\t\t\n\t\tlong k2 = (((((n*(n+1))%N)*(2*n+1))%N)*166666668)%N;\n\t\tk2 = (k2*floornq)%N;\n\t\t\n\t\tlong k3 = (((qcube*sumcube)%N)*333333336)%N;\n\t\tk3 -= (((qsquare*sumsquare)%N)*500000004)%N;\n\t\tk3 += (((q*sum)%N)*166666668)%N;\n\t\t\n\t\tlong ans = (k1-k2+k3)%N;\n\t\tif (ans < 0)\n\t\t\tans += N;\n\t\treturn (int) ans;\n\t}\n\t\n\t//wtf who successfully codes this up in a real round?\n\tpublic static int secondsum(long n, long b) {\n\t\tint N = 1000000007;\n\t\tlong bsquare = (b*b)%N;\n\t\tlong bcube = (b*bsquare)%N;\n\t\tlong max = (n/(4*b)-1)%N;\n\t\tlong numk = (max + N + 1 - 500000)%N;\n\t\tlong sumk = ((max)*(max+1)/2 + 250875)%N;\n\t\tlong sumksquare = ((((long) max * (long) (max+1))%N * (long) (2*max + 1))%N * 166666668)%N-375084213;\n\t\tif (sumksquare < 0)\n\t\t\tsumksquare += N;\n\t\t\t\t\n\t\tlong k1 = (((bcube*sumksquare)%N)*32)%N;\n\t\tlong k2 = (((bsquare*sumk)%N * (4*b-1)%N)%N *8)%N;\n\t\tlong k3 = ((26*bcube - 12*bsquare + b)%N * 333333336)%N;\n\t\tif (k3 < 0)\n\t\t\tk3 += N;\n\t\tk3 = (k3*numk)%N;\n\t\tlong k4 = (((n+1)%N)*(b*(numk*(((4*b*500000 + 4*b*max)+4*b-1)%N)%N)%N))%N;\n\t\t\n\t\tlong k5 = 0;\n\t\tlong k6 = 0;\n\t\t\n\t\tif (n%(4*b) >= b) {\n\t\t\tlong min2 = ((4*b)*(n/(4*b))+b)%N;\n\t\t\tlong max2 = (Math.min((4*b)*(n/(4*b))+3*b-1, n))%N;\n\t\t\t//sum from min2 to max2 of (n+1-i)*i\n\t\t\tk5 = (((((max2*(max2+1))%N)*(2*max2+1))%N)*166666668)%N;\n\t\t\tk5 -= (((((((min2-1)*min2)%N)*(2*min2-1))%N)*166666668)%N);\n\t\t\tk6 = ((max2*(max2+1) - min2*(min2-1))/2)%N;\n\t\t\tk6 = (k6*((n+1)%N))%N;\n\t\t\tSystem.out.println(k6);\n\t\t}\n\t\t\t\t\n\t\treturn (int) ((k4-k1-k2-k3-k5+k6+7*(long)N)%N);\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c6912bdf55930db4a05fdf24e1ec192", "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "//package round462;\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 D3 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tlong m = nl();\n\t\tint mod = 1000000007;\n\t\tlong mm = m%mod;\n\t\tlong ans = 0;\n\t\tfor(long x = 1;x*x <= m;x++){\n\t\t\tlong n = (long)Math.sqrt(m-x*x);\n\t\t\tans += invl(420, mod) * (n+1) % mod\n\t\t\t\t\t* (70*mm%mod*mm%mod*mm+210*mm%mod*mm\n\t\t\t\t\t\t\t-42*mm%mod*n%mod*n%mod*n%mod*n%mod\n\t\t\t\t\t\t\t-63*mm%mod*n%mod*n%mod*n%mod\n\t\t\t\t\t\t\t-140*mm%mod*n%mod*n%mod*x%mod*x%mod\n\t\t\t\t\t\t\t+63*mm%mod*n%mod*n%mod\n\t\t\t\t\t\t\t-70*mm%mod*n%mod*x%mod*x%mod\n\t\t\t\t\t\t\t+42*mm%mod*n%mod\n\t\t\t\t\t\t\t-210*mm%mod*x%mod*x%mod*x%mod*x%mod\n\t\t\t\t\t\t\t+210*mm%mod*x%mod*x%mod\n\t\t\t\t\t\t\t+140*mm%mod\n\t\t\t\t\t\t\t+20*n%mod*n%mod*n%mod*n%mod*n%mod*n%mod\n\t\t\t\t\t\t\t+50*n%mod*n%mod*n%mod*n%mod*n%mod\n\t\t\t\t\t\t\t+84*n%mod*n%mod*n%mod*n%mod*x%mod*x%mod\n\t\t\t\t\t\t\t-64*n%mod*n%mod*n%mod*n%mod\n\t\t\t\t\t\t\t+126*n%mod*n%mod*n%mod*x%mod*x%mod\n\t\t\t\t\t\t\t-146*n%mod*n%mod*n%mod\n\t\t\t\t\t\t\t+140*n%mod*n%mod*x%mod*x%mod*x%mod*x%mod\n\t\t\t\t\t\t\t-266*n%mod*n%mod*x%mod*x%mod\n\t\t\t\t\t\t\t+76*n%mod*n%mod\n\t\t\t\t\t\t\t+70*n%mod*x%mod*x%mod*x%mod*x%mod\n\t\t\t\t\t\t\t-154*n%mod*x%mod*x%mod\n\t\t\t\t\t\t\t+64*n%mod\n\t\t\t\t\t\t\t+140*x%mod*x%mod*x%mod*x%mod*x%mod*x%mod\n\t\t\t\t\t\t\t-420*x%mod*x%mod*x%mod*x%mod\n\t\t\t\t\t\t\t+280*x%mod*x%mod\n\t\t\t\t\t\t\t)%mod;\n\t\t}\n\t\tans = ans * 4 + mm*(mm+1)%mod*(mm+2)%mod*invl(6,mod)%mod;\n\t\tans %= mod;\n\t\tif(ans < 0)ans += mod;\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static long invl(long a, long mod) {\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\n\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 D3().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "623f58481c505493acd1a397e6a8f80e", "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Main {\n final static double mod = 1e9 + 7;\n\tpublic static void main (String[] args) throws IOException {\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] input = bf.readLine().split(\" \");\n\t\tlong p = Long.parseLong(input[0]);\n\t\tlong k = Long.parseLong(input[1]);\n\t\tlong order = 1;\n\t\tlong temp = k;\n\t\t\n\t\tif (k == 0)\n\t\t System.out.println((int)Math.pow(p, p - 1));\n\t\telse {\n \t while (temp != 1) {\n \t temp = (k * temp) % p;\n \t order++;\n \t }\n \t \n \t if (k == 1)\n\t\t System.out.println((((int)Math.pow(p,p) % (int) mod));\n\t\t else\n\t\t System.out.println((((int)Math.pow(p, (p - 1)/order)) % (int) mod));\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "17ed9e837e5589b597cc6cfa1728d0c0", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution{\n\tprivate static final int MOD = 1000000007;\n\t\n\tpublic static void main(String[] args){\n\t\tScanner scanner = new Scanner(System.in);\n\t\t\n\t\tint p = scanner.nextInt();\n\t\tint k = scanner.nextInt();\n\t\t\n\t\tint i=1;\n\t\tlong curr = k;\n\t\t\n\t\twhile (curr != 1){\n\t\t\ti++;\n\t\t\tcurr = (curr * k) % MOD;\n\t\t}\n\t\t\n\t\tlong sol = pow(p, (p-1)/i);\n\t\t\n\t\tSystem.out.println(sol);\n\t}\n\t\n\tprivate long pow(long base, long exp){\n\t\tlong sol = 1;\n\t\t\n\t\tfor (int i=0; i set = new HashSet();\n for(long i=0;i<=40;i++)\n {\n for(long j=0;j<=40;j++)\n {\n long p = Math.pow(2,i);\n p*=Math.pow(3,j);\n if(p>=l&&p<=r)\n set.add(j);\n }\n }\n System.out.println(set.size());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2b05b3bee01788c3cac885f7e822ba69", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import sun.tools.jstat.Scale;\n\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * @author Aleksey Koshelev (aleksey.koshelev@inventale.com) 13.04.2018 23:06\n */\npublic class Main {\n public static void main(String[] args) {\n long l, r;\n long counter = 0;\n Scanner scanner = new Scanner(System.in);\n\n l = scanner.nextLong();\n r = scanner.nextLong();\n\n Main main = new Main();\n for (long i = l; i <= r; i++) {\n counter += main.is23(i);\n }\n\n System.out.println(counter);\n }\n\n private boolean isSimple(long val){\n BigInteger b = new BigInteger(String.valueOf(val));\n return b.isProbablePrime(4);\n }\n\n\n private ArrayList getDividers(long val) {\n ArrayList dividers = new ArrayList<>();\n for (long i = 1; i <= val; i++) {\n if (isSimple(i) && val % i == 0) dividers.add(i);\n }\n return dividers;\n }\n\n\n private int is23(long val) {\n ArrayList dividers = getDividers(val);\n if (val == 1) return 1;\n if (dividers.size() <= 3 && dividers.contains(1L) && (dividers.contains(2L) && dividers.contains(3L)) ||\n (dividers.contains(2L) && dividers.size() == 2) || (dividers.contains(3L) && dividers.size() == 2)) {\n return 1;\n }\n return 0;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f8a22ebe48386f0f7f1c0c0ccd6f3430", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.awt.*;\npublic class VK\n{\n\tBufferedReader in;\n\tPrintWriter ob;\n\tStringTokenizer st;\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew VK().run();\n\t}\n\tvoid run() throws IOException {\n\t\t//in=new BufferedReader(new FileReader(\"input.txt\"));\n\t\tin=new BufferedReader(new InputStreamReader(System.in));\n\t\tob=new PrintWriter(System.out);\n\t\tsolve();\n\t\tob.flush();\n\t}\n\t@SuppressWarnings(\"unchecked\")\n\tvoid solve() throws IOException {\n\t\tint l = ni();\n\t\tint r = ni();\n\t\tint a[] = {1 ,\n2 ,\n3 ,\n4 ,\n6 ,\n8 ,\n9 ,\n12 ,\n16 ,\n18 ,\n24 ,\n27 ,\n32 ,\n36 ,\n48 ,\n54 ,\n64 ,\n72 ,\n81 ,\n96 ,\n108 ,\n128 ,\n144 ,\n162 ,\n192 ,\n216 ,\n243 ,\n256 ,\n288 ,\n324 ,\n384 ,\n432 ,\n486 ,\n512 ,\n576 ,\n648 ,\n729 ,\n768 ,\n864 ,\n972 ,\n1024 ,\n1152 ,\n1296 ,\n1458 ,\n1536 ,\n1728 ,\n1944 ,\n2048 ,\n2187 ,\n2304 ,\n2592 ,\n2916 ,\n3072 ,\n3456 ,\n3888 ,\n4096 ,\n4374 ,\n4608 ,\n5184 ,\n5832 ,\n6144 ,\n6561 ,\n6912 ,\n7776 ,\n8192 ,\n8748 ,\n9216 ,\n10368 ,\n11664 ,\n12288 ,\n13122 ,\n13824 ,\n15552 ,\n16384 ,\n17496 ,\n18432 ,\n19683 ,\n20736 ,\n23328 ,\n24576 ,\n26244 ,\n27648 ,\n31104 ,\n32768 ,\n34992 ,\n36864 ,\n39366 ,\n41472 ,\n46656 ,\n49152 ,\n52488 ,\n55296 ,\n59049 ,\n62208 ,\n65536 ,\n69984 ,\n73728 ,\n78732 ,\n82944 ,\n93312 ,\n98304 ,\n104976 ,\n110592 ,\n118098 ,\n124416 ,\n131072 ,\n139968 ,\n147456 ,\n157464 ,\n165888 ,\n177147 ,\n186624 ,\n196608 ,\n209952 ,\n221184 ,\n236196 ,\n248832 ,\n262144 ,\n279936 ,\n294912 ,\n314928 ,\n331776 ,\n354294 ,\n373248 ,\n393216 ,\n419904 ,\n442368 ,\n472392 ,\n497664 ,\n524288 ,\n531441 ,\n559872 ,\n589824 ,\n629856 ,\n663552 ,\n708588 ,\n746496 ,\n786432 ,\n839808 ,\n884736 ,\n944784 ,\n995328 ,\n1048576 ,\n1062882 ,\n1119744 ,\n1179648 ,\n1259712 ,\n1327104 ,\n1417176 ,\n1492992 ,\n1572864 ,\n1594323 ,\n1679616 ,\n1769472 ,\n1889568 ,\n1990656 ,\n2097152 ,\n2125764 ,\n2239488 ,\n2359296 ,\n2519424 ,\n2654208 ,\n2834352 ,\n2985984 ,\n3145728 ,\n3188646 ,\n3359232 ,\n3538944 ,\n3779136 ,\n3981312 ,\n4194304 ,\n4251528 ,\n4478976 ,\n4718592 ,\n4782969 ,\n5038848 ,\n5308416 ,\n5668704 ,\n5971968 ,\n6291456 ,\n6377292 ,\n6718464 ,\n7077888 ,\n7558272 ,\n7962624 ,\n8388608 ,\n8503056 ,\n8957952 ,\n9437184 ,\n9565938 ,\n10077696 ,\n10616832 ,\n11337408 ,\n11943936 ,\n12582912 ,\n12754584 ,\n13436928 ,\n14155776 ,\n14348907 ,\n15116544 ,\n15925248 ,\n16777216 ,\n17006112 ,\n17915904 ,\n18874368 ,\n19131876 ,\n20155392 ,\n21233664 ,\n22674816 ,\n23887872 ,\n25165824 ,\n25509168 ,\n26873856 ,\n28311552 ,\n28697814 ,\n30233088 ,\n31850496 ,\n33554432 ,\n34012224 ,\n35831808 ,\n37748736 ,\n38263752 ,\n40310784 ,\n42467328 ,\n43046721 ,\n45349632 ,\n47775744 ,\n50331648 ,\n51018336 ,\n53747712 ,\n56623104 ,\n57395628 ,\n60466176 ,\n63700992 ,\n67108864 ,\n68024448 ,\n71663616 ,\n75497472 ,\n76527504 ,\n80621568 ,\n84934656 ,\n86093442 ,\n90699264 ,\n95551488 ,\n100663296 ,\n102036672 ,\n107495424 ,\n113246208 ,\n114791256 ,\n120932352 ,\n127401984 ,\n129140163 ,\n134217728 ,\n136048896 ,\n143327232 ,\n150994944 ,\n153055008 ,\n161243136 ,\n169869312 ,\n172186884 ,\n181398528 ,\n191102976 ,\n201326592 ,\n204073344 ,\n214990848 ,\n226492416 ,\n229582512 ,\n241864704 ,\n254803968 ,\n258280326 ,\n268435456 ,\n272097792 ,\n286654464 ,\n301989888 ,\n306110016 ,\n322486272 ,\n339738624 ,\n344373768 ,\n362797056 ,\n382205952 ,\n387420489 ,\n402653184 ,\n408146688 ,\n429981696 ,\n452984832 ,\n459165024 ,\n483729408 ,\n509607936 ,\n516560652 ,\n536870912 ,\n544195584 ,\n573308928 ,\n603979776 ,\n612220032 ,\n644972544 ,\n679477248 ,\n688747536 ,\n725594112 ,\n764411904 ,\n774840978 ,\n805306368 ,\n816293376 ,\n859963392 ,\n905969664 ,\n918330048 ,\n967458816 ,\n1019215872 ,\n1033121304 ,\n1073741824 ,\n1088391168 ,\n1146617856 ,\n1162261467 ,\n1207959552 ,\n1224440064 ,\n1289945088 ,\n1358954496 ,\n1377495072 ,\n1451188224 ,\n1528823808 ,\n1549681956 ,\n1610612736 ,\n1632586752 ,\n1719926784 ,\n1811939328 ,\n1836660096 ,\n1934917632 };\n\t\tint cnt = 0;\n\t\tfor(int i=0 ; i=l && a[i]<=r )\n\t\t\t\t++cnt;\n\t\t}\n\t\tSystem.out.println(cnt);\n\t} \n\tvoid recur( int two , int three , int min , int max ) {\n\t\tlong res = (long)Math.pow(2 , two);\n\t\tres = res * 1L * (long)Math.pow(3 , three);\n\t\t//System.out.println(res);\n\t\tif(res<=max && res>=min) hs.add(res);\n\t\tif(res>max) return;\n\t\trecur( two+1 , three , min , max );\n\t\trecur( two , three+1 , min , max );\n\t} \n\tString ns() throws IOException {\n\t\treturn nextToken();\n\t}\n\tlong nl() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tint ni() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tdouble nd() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t} \n\tString nextToken() throws IOException {\n\t\tif(st==null || !st.hasMoreTokens())\n\t\t\tst=new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint[] nia(int start,int b) throws IOException {\n\t\tint a[]=new int[b];\n\t\tfor(int i=start;i 0){\n ans +=ca;\n }\n }\n return (a == b)?(ca-1)*(ca)/2:ans;\n }\n if(n == 0) \n return 0;\n if(dp[n][k][index] != -1)\n return dp[n][k][index];\n\n char or = s[n-1];\n s[n-1] = a;\n int ca = maxSubSeq(s, a, b, n-1, k-1,1,dp);\n s[n-1] = b;\n int cb = maxSubSeq(s, a, b, n-1, k-1,2,dp);\n s[n-1] = or;\n int co = maxSubSeq(s, a, b, n-1, k,0,dp);\n return Math.max(Math.max(co, cb),ca);\n }\n \n\tpublic static void main (String[] args) throws Exception {\n\t\t//code\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String s[] = in.readLine().split(\" \");\n int n = Integer.parseInt(s[0]);\n int k = Integer.parseInt(s[1]);\n String ss = in.readLine();\n String t = in.readLine();\n int dp[][][] = new int[n+1][k+1][3]; \n for(int a[][] : dp){\n for(int b[]:a)\n Arrays.fill(b, -1);\n }\n\n System.out.println(maxSubSeq(ss.toCharArray(), t.charAt(0), t.charAt(1), n, k,0,dp));\n\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "233b73e04710732b42d111ebcea2a3df", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\npublic class Q6 {\n\tpublic static void main(String[] args) { \n\t\t/*Pairs of replacements (First letter, Second letter)\n\t\t * Iterate over all pairs:\n\t\t * (0,K)\n\t\t * (1,K-1)\n\t\t * .\n\t\t * .\n\t\t * .\n\t\t * (K-1,1)\n\t\t * (K,0) Take maximum of results\n\t\t * \n\t\t * UPD: Fix how many As you want to keep and Bs you want to keep among originals\n\t\t * \n\t\t * */\n\t\tFastScanner I = new FastScanner(); //Input\n\t\tOutPut O = new OutPut(); //Output\n\t\tint N = I.nextInt();\n\t\tint K = I.nextInt();\n\t\tString S = I.next();\n\t\tString T = I.next();\n\t\tlong ans = 0;\n\t\tif (T.charAt(0)==T.charAt(1)) {\n\t\t\tlong same = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tsame+=S.charAt(i)==T.charAt(0)?1:0;\n\t\t\t}\n\t\t\tsame+=K;\n\t\t\tsame=min(same,N); //Can't have more letters than length...\n\t\t\tans=same*(same-1)/2;\n\t\t}else {\n\t\t\tint first = 0;\n\t\t\tint second = 0;\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tfirst+=S.charAt(i)==T.charAt(0)?1:0;\n\t\t\t\tsecond+=S.charAt(i)==T.charAt(1)?1:0;\n\t\t\t}\n\t\t\tfor (int A = 0; A<=first; A++) {\n\t\t\t\tfor (int B = 0; B<=second; B++) {\n\t\t\t\t\tint max = min(K,N-A-B); //either switch K, or switch all untouched\n\t\t\t\t\tfor (int a = 0; a <= max; a++) {\n\t\t\t\t\t\t//Second letter = max-a\n\t\t\t\t\t\tboolean[] keep = new boolean[N]; //Which letters we're keeping\n\t\t\t\t\t\tint cntF = 0;\n\t\t\t\t\t\tint cntS = 0;\n\t\t\t\t\t\tchar[] UPD = S.toCharArray();//New word constructed (keep original in\n\t\t\t\t\t\t//beginning)\n\t\t\t\t\t\tlong pair = B; //Number of second letter in new string\n\t\t\t\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\t\t\t\tif (cntF==A) break;\n\t\t\t\t\t\t\tif (S.charAt(i)==T.charAt(0)) {\n\t\t\t\t\t\t\t\tcntF++;\n\t\t\t\t\t\t\t\tkeep[i]=true;\n\t\t\t\t\t\t\t\tUPD[i]=T.charAt(0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (int i = N-1; i>=0; i--) {\n\t\t\t\t\t\t\tif (cntS==B) break;\n\t\t\t\t\t\t\tif (S.charAt(i)==T.charAt(1)&&!keep[i]) {\n\t\t\t\t\t\t\t\tcntS++;\n\t\t\t\t\t\t\t\tkeep[i]=true;\n\t\t\t\t\t\t\t\tUPD[i]=T.charAt(1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint swap = 0;\n\t\t\t\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\t\t\t\tif (swap==a) break;\n\t\t\t\t\t\t\tif (!keep[i]) {\n\t\t\t\t\t\t\t\tswap++;\n\t\t\t\t\t\t\t\tUPD[i]=T.charAt(0);\n\t\t\t\t\t\t\t\tkeep[i]=true; //We have touched this up (don't let suffix overlap)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tswap=0;\n\t\t\t\t\t\tfor (int i = N-1; i >= 0; i--) {\n\t\t\t\t\t\t\tif (swap==max-a) break;\n\t\t\t\t\t\t\tif (!keep[i]) {\n\t\t\t\t\t\t\t\tswap++;\n\t\t\t\t\t\t\t\tUPD[i]=T.charAt(1);\n\t\t\t\t\t\t\t\tkeep[i]=true;\n\t\t\t\t\t\t\t\tpair++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlong curans = 0;\n\t\t\t\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\t\t\t\tif (UPD[i]==T.charAt(0)) {\n\t\t\t\t\t\t\t\tcurans+=pair;\n\t\t\t\t\t\t\t}else if (UPD[i]==T.charAt(1)) pair--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tans=max(ans,curans);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tO.pln(ans);\n\t}\n\tpublic static double max(double a, double b) {return Math.max(a, b);}\n\tpublic static double min(double a, double b) {return Math.min(a, b);}\n\tpublic static long min(long a, long b) {return Math.min(a,b);}\n\tpublic static long max(long a, long b) {return Math.max(a,b);}\n\tpublic static int min(int a, int b) {return Math.min(a,b);}\n\tpublic static int max(int a, int b) {return Math.max(a,b);}\n\tpublic static long abs(long x) {return Math.abs(x);}\n\tpublic static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) \n\tans++; return ans;}\n\tpublic static long GCD(long a, long b) {\n\t\tif (a==0||b==0) return max(a,b);\n\t\treturn GCD(min(a,b),max(a,b)%min(a,b));\n\t}\n\tpublic static long FastExp(long base, long exp, long mod) {\n\t\tlong ans=1;\n\t\twhile (exp>0) {\n\t\t\tif (exp%2==1) ans*=base;\n\t\t\texp/=2;\n\t\t\tbase*=base;\n\t\t\tbase%=mod;\n\t\t\tans%=mod;\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}\n\tpublic static int pop(long x) { //Returns number of bits within a number\n\t\tint cnt = 0;\n\t\twhile (x>0) {\n\t\t\tif (x%2==1) cnt++;\n\t\t\tx/=2;\n\t\t}\n\t\treturn cnt;\n\t}\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() {return Integer.parseInt(next());}\n\t\tlong nextLong() {return Long.parseLong(next());};\n\t\tdouble nextDouble() {return Double.parseDouble(next());}\n\t}\n\tstatic class OutPut{\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\tvoid pln(double x) {w.println(x);w.flush();}\n\t\tvoid pln(boolean x) {w.println(x);w.flush();}\n\t\tvoid pln(int x) {w.println(x);w.flush();}\n\t\tvoid pln(long x) {w.println(x);w.flush();}\n\t\tvoid pln(String x) {w.println(x);w.flush();}\n\t\tvoid pln(char x) {w.println(x);w.flush();}\n\t\tvoid pln(StringBuilder x) {w.println(x);w.flush();}\n\t\tvoid pln(BigInteger x) {w.println(x);w.flush();}\n\t\tvoid p(int x) {w.print(x);w.flush();}\n\t\tvoid p(long x) {w.print(x);w.flush();}\n\t\tvoid p(String x) {w.print(x);w.flush();}\n\t\tvoid p(char x) {w.print(x);w.flush();}\n\t\tvoid p(StringBuilder x) {w.print(x);w.flush();}\n\t\tvoid p(BigInteger x) {w.print(x);w.flush();}\n\t\tvoid p(double x) {w.print(x);w.flush();}\n\t\tvoid p(boolean x) {w.print(x);w.flush();}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "974cac58c35ff1493a101aaedde80d36", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class SolutionF extends Thread {\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 private static final FastReader scanner = new FastReader();\n private static final PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) {\n new Thread(null, new SolutionF(), \"Main\", 1 << 26).start();\n }\n\n public void run() {\n int t = 1;\n for (int i = 0; i < t; i++) {\n solve();\n }\n out.close();\n }\n\n private static void solve() {\n scanner.nextInt();\n int k = scanner.nextInt();\n String s = scanner.next();\n String t = scanner.next();\n\n System.out.println(dp(s, t, 0, 0, k, new HashMap<>()));\n }\n\n private static long dp(String s, String t, int index, int amountFirst, int movesLeft, Map memo) {\n if (index == s.length()) {\n return 0;\n }\n\n String key = index + \"-\" + amountFirst + \"-\" + movesLeft;\n if (memo.get(key) != null) {\n return memo.get(key);\n }\n\n long nothing = dp(s, t, index+1, amountFirst + (s.charAt(index) == t.charAt(0) ? 1 : 0), movesLeft, memo)\n + (s.charAt(index) == t.charAt(1) ? amountFirst : 0);\n long firstChar = 0;\n long secondChar = 0;\n\n if (movesLeft > 0) {\n firstChar = dp(s, t, index+1, amountFirst+1, movesLeft-1, memo)\n + (t.charAt(0) == t.charAt(1) ? amountFirst : 0);\n secondChar = dp(s, t, index+1, amountFirst + (t.charAt(1) == t.charAt(0) ? 1 : 0), movesLeft-1, memo)\n + amountFirst;\n }\n long result = Math.max(nothing, Math.max(firstChar, secondChar));\n memo.put(key, result);\n\n return result;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "59887a6741dd443b97553a7f752f6bb3", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport static java.util.Collections.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cfa {\n\n @SuppressWarnings(\"unused\")\n private static final int MOD = (int) (1e9 + 7), MOD_FFT = 998244353;\n private static final Reader r = new Reader();\n private static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n private static final boolean thread = false;\n private static final boolean HAS_TEST_CASES = true;\n private static final int SCAN_LINE_LENGTH = 131074;\n\n static int n, a[], e[][], vis[];\n private static ArrayList adj[], topo;\n\n static void solve() throws Exception {\n int n = ni(), k = ni(), l = ni();\n a = na(n);\n int p[] = new int[2 * k];\n for (int i = 1; i < p.length; i++) {\n if (i < k)\n p[i] = i % (k);\n else if (i == k)\n p[i] = k;\n else\n p[i] = k - (i % k);\n }\n\n for (int i = 0; i < p.length; i++) {\n if (rec(p, k, l, i, 0)) {\n pn(\"YES\");\n return;\n }\n }\n pn(\"NO\");\n }\n\n private static boolean rec(int[] p, int k, int l, int i, int j) {\n if (j == a.length)\n return true;\n if (a[j] + p[i % p.length] > l)\n return false;\n for (int j2 = 0; j2 < p.length; j2++) {\n if (a[j] + p[(i + j2) % p.length] > l)\n break;\n if (rec(p, k, l, i + j2 + 1, j + 1))\n return true;\n }\n return false;\n }\n \n // static void solve() throws Exception {\n // n = ni();\n // a = na(n);\n // int[] f = new int[34];\n // for (int i = 0; i < a.length; i++) {\n // char[] ch = Integer.toBinaryString(a[i]).toCharArray();\n // for (int j = 0; j < ch.length; j++) {\n // f[j] += (ch[j] - '0');\n // }\n // }\n // for (int i = 33; i > -1; --i) {\n // if (f[i] % 2 == 1) {\n // pn(\"WIN\");\n // }\n // }\n // }\n\n public static void main(final String[] args) throws Exception {\n if (!thread) {\n final int testcases = HAS_TEST_CASES ? ni() : 1;\n for (int i = 1; i <= testcases; i++) {\n // out.print(\"Case #\" + (i + 1) + \": \");\n try {\n solve();\n } catch (final Exception e) {\n pni(\"idk Exception\");\n e.printStackTrace(System.err);\n System.exit(0);\n }\n }\n out.flush();\n r.close();\n out.close();\n }\n }\n\n @SuppressWarnings(\"unused\")\n private static void swap(final int i, final int j) {\n final int temp = a[i];\n a[i] = a[j];\n a[j] = temp;\n }\n\n @SuppressWarnings(\"unused\")\n private static int gcd(final int a, final int b) {\n if (b == 0)\n return a;\n return gcd(b, a % b);\n }\n\n @SuppressWarnings(\"unused\")\n private static class Pair implements Comparable> {\n T fir;\n E snd;\n\n Pair() {\n }\n\n Pair(final T x, final E y) {\n this.fir = x;\n this.snd = y;\n }\n\n @Override\n @SuppressWarnings(\"unchecked\")\n public int compareTo(final Pair o) {\n final int c = ((Comparable) fir).compareTo(o.fir);\n return c != 0 ? c : ((Comparable) snd).compareTo(o.snd);\n }\n\n }\n\n @SuppressWarnings(\"unused\")\n private static class pi implements Comparable {\n int fir, snd;\n\n pi() {\n }\n\n pi(final int a, final int b) {\n fir = a;\n snd = b;\n }\n\n public int compareTo(final pi o) {\n return fir == o.fir ? snd - o.snd : fir - o.fir;\n }\n\n }\n\n @SuppressWarnings(\"unused\")\n private static void checkV(final ArrayList adj[], final int i) {\n adj[i] = adj[i] == null ? new ArrayList<>() : adj[i];\n }\n\n @SuppressWarnings(\"unused\")\n private static void checkV(final Vector adj[], final int i) {\n adj[i] = adj[i] == null ? new Vector<>() : adj[i];\n }\n\n @SuppressWarnings(\"unused\")\n private static int[] na(final int n) throws Exception {\n final int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = ni();\n }\n return a;\n }\n\n @SuppressWarnings(\"unused\")\n private static int[] na1(final int n) throws Exception {\n final int[] a = new int[n + 1];\n for (int i = 1; i < a.length; i++) {\n a[i] = ni();\n }\n return a;\n }\n\n @SuppressWarnings(\"unused\")\n private static String n() throws IOException {\n return r.readToken();\n }\n\n @SuppressWarnings(\"unused\")\n private static String nln() throws IOException {\n return r.readLine();\n }\n\n private static int ni() throws IOException {\n return r.nextInt();\n }\n\n @SuppressWarnings(\"unused\")\n private static long nl() throws IOException {\n return r.nextLong();\n }\n\n @SuppressWarnings(\"unused\")\n private static double nd() throws IOException {\n return r.nextDouble();\n }\n\n @SuppressWarnings(\"unused\")\n private static void p(final Object o) {\n out.print(o);\n }\n\n @SuppressWarnings(\"unused\")\n private static void pn(final Object o) {\n out.println(o);\n }\n\n @SuppressWarnings(\"unused\")\n private static void pn() {\n out.println(\"\");\n }\n\n private static void pni(final Object o) {\n out.println(o);\n out.flush();\n }\n\n private static class Reader {\n private final int BUFFER_SIZE = 1 << 22;\n private final DataInputStream din;\n private final byte[] buffer;\n private int bufferPointer, bytesRead;\n // private StringTokenizer st;\n\n public Reader() {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n @SuppressWarnings(\"unused\")\n public Reader(final 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 final byte[] buf = new byte[SCAN_LINE_LENGTH];\n\n public String readLine() throws IOException {\n int cnt = 0;\n int c;\n o: while ((c = read()) != -1) {\n if (c == '\\n')\n if (cnt == 0)\n continue o;\n else\n break;\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\n }\n\n public String readToken() throws IOException {\n int cnt = 0;\n int c;\n o: while ((c = read()) != -1) {\n if (!(c >= 33 && c <= 126))\n if (cnt == 0)\n continue o;\n else\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 final 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 final 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 final boolean neg = (c == '-');\n if (neg)\n c = read();\n\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.') {\n while ((c = read()) >= '0' && c <= '9') {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n if (neg)\n return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null)\n return;\n din.close();\n }\n }\n\n static {\n if (thread)\n new Thread(null, new Runnable() {\n @Override\n public void run() {\n try {\n final int testcases = HAS_TEST_CASES ? ni() : 1;\n for (int i = 1; i <= testcases; i++) {\n // out.print(\"Case #\" + (i + 1) + \": \");\n try {\n solve();\n } catch (final Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n out.flush();\n r.close();\n out.close();\n } catch (final Throwable t) {\n t.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n }, \"rec\", (1L << 28)).start();\n }\n\n @SuppressWarnings({ \"unchecked\", \"unused\" })\n private static T deepCopy(final T old) {\n try {\n return (T) deepCopyObject(old);\n } catch (final IOException | ClassNotFoundException e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n return null;\n }\n\n private static Object deepCopyObject(final Object oldObj) throws IOException, ClassNotFoundException {\n ObjectOutputStream oos = null;\n ObjectInputStream ois = null;\n try {\n final ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A\n oos = new ObjectOutputStream(bos); // B\n // serialize and pass the object\n oos.writeObject(oldObj); // C\n oos.flush(); // D\n final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E\n ois = new ObjectInputStream(bin); // F\n // return the new object\n return ois.readObject(); // G\n } catch (final ClassNotFoundException e) {\n pni(\"Exception in ObjectCloner = \" + e);\n throw (e);\n } finally {\n oos.close();\n ois.close();\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e37363b378c812c94e2a4e7da958f927", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class b1384 {\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int tests = in.nextInt();\n while (tests > 0){\n int depths = in.nextInt();\n int[] dArr = new int[depths + 1];\n int cycle = in.nextInt();\n int limit = in.nextInt();\n int[] cArr = new int[2*cycle];\n int idx = 0;\n for (int i = 0 ; i <= cycle; i++){\n cArr[idx] = i;\n idx++;\n }\n for (int i = 1; i < cycle; i++){\n cArr[idx] = cycle - i;\n idx++;\n }\n dArr[0] = Integer.MIN_VALUE;\n for (int i = 0; i < depths; i++){\n dArr[i + 1] = in.nextInt();\n }\n System.out.println( eval(dArr, cArr, limit, 0, 0, 0) ? \"Yes\" : \"No\");\n tests--;\n }\n in.close();\n }\n private static boolean eval(int[] dArr, int[] cArr, int limit, int pos, int time, int stayed){\n if (pos == dArr.length) return true;\n int curPosDepth = dArr[pos] + cArr[time % cArr.length];\n if (curPosDepth > limit) return false;\n boolean swim = eval(dArr, cArr, limit, pos + 1, time + 1, 0);\n if (swim) return true;\n if (stayed < cArr.length){\n boolean stay = eval (dArr, cArr, limit, pos, time + 1, stayed + 1);\n if (stay) return true;\n }\n return false;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c4f8f513fd23f972edadfc8c62ea12d8", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0} {"lang": "Java 11", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author sofiane\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n static int[] p = new int[250];\n static int[] d = new int[100];\n static int n;\n static int l;\n static int k;\n static int dist;\n\n static boolean dfs(int time, boolean[][] vis) {\n dist++;\n if (dist == n + 1) return true;\n for (int i = time + 1; i < 2 * k + time + 1; i++) {\n if (vis[dist][i % (2 * k)]) continue;\n vis[dist][i % (2 * k)] = true;\n if (d[dist] + p[i % (2 * k)] <= l) {\n if (dfs(i, vis)) return true;\n } else break;\n }\n dist--;\n return false;\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int t = in.nextInt();\n while (t-- > 0) {\n n = in.nextInt();\n k = in.nextInt();\n l = in.nextInt();\n for (int i = 1; i <= n; i++)\n d[i] = in.nextInt();\n for (int i = 0; i < 2 * k; i++) {\n if (i < k) p[i] = i;\n else p[i] = 2 * k - i;\n }\n boolean[][] vis = new boolean[110][220];\n for (int i = 0; i < 2 * k; i++) {\n dist = 1;\n if (d[dist] + p[i] <= l) {\n if (dfs(i, vis)) {\n out.println(\"Yes\");\n break;\n }\n }\n if (i == 2 * k - 1) out.println(\"No\");\n }\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4f993b0286ced937feb7660aa51eb0cc", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Beach {\n static class State {\n public final int tide;\n public final int pos;\n public final boolean down;\n public State(int pos, int tide, boolean down) {\n this.tide = tide;\n this.pos = pos;\n this.down = down;\n }\n\n @Override\n public int hashCode() {\n return Arrays.deepHashCode(new Object[] {pos, tide, down});\n }\n\n @Override\n public boolean equals(Object other) {\n if (!(other instanceof State)) {\n return false;\n }\n\n State o = (State)other;\n if (this.tide == o.tide && this.pos == o.pos && this.down == o.down) {\n return true;\n } else {\n return false;\n }\n\n }\n }\n\n public static boolean dp(int pos, int tide, boolean down, Set memo, int n, int k, int l, int[] depth) {\n // System.out.println(pos +\" \" + tide + \" \" + down);\n State state = new State(pos, tide, down);\n if (memo.contains(state)) {\n return false;\n }\n \n if (pos > n) {\n return true;\n }\n \n memo.add(state);\n\n tide += down ? -1 : +1;\n if (tide == 0) {\n down = false;\n }\n if (tide == k) {\n down = true;\n }\n\n // stay at current position\n if (depth[pos] + tide <= l && dp(pos, tide, down, memo, n, k, l, depth)) {\n return true;\n }\n if (depth[pos+1] + tide <= l && dp(pos+1, tide, down, memo, n,k,l,depth)) {\n return true;\n }\n return false;\n }\n public static void main(String[] args) throws NumberFormatException, IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int test = Integer.parseInt(br.readLine()); // 3 elements\n while (test-- > 0) {\n String[] s = br.readLine().split(\" \");\n int n = Integer.parseInt(s[0]); // length of the shore\n int k = Integer.parseInt(s[1]); // seconds of tide for each wave\n int l = Integer.parseInt(s[2]); // maximum depth Koa can swim\n \n // depths array\n String[] sd = br.readLine().split(\" \");\n int[] depth = new int[n+1];\n for (int i=0; i memo = new HashSet<>(); // record unsuccessful results\n \n if (dp(0, 0, false, memo, n, k, l, depth)) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n\n\n }\n br.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4520a4e27a3f0090241d97f082718b6", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * \n * @author pttrung\n */\npublic class D_Round_173_Div2 {\n\n\tpublic static long MOD = 1000000007;\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n\t\t// \"output.txt\")));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner in = new Scanner();\n\t\tint n = in.nextInt();\n\t\tint[] data = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdata[i] = in.nextInt();\n\t\t}\n\t\tArrays.sort(data);\n\t\tif (n == 1) {\n\t\t\tif (data[0] == 0) {\n\t\t\t\tout.println(\"BitAryo\");\n\t\t\t} else {\n\t\t\t\tout.println(\"BitLGM\");\n\t\t\t}\n\t\t} else if (n == 2) {\n\t\t\tint[][][] dp = new int[2][data[0] + 1][data[1] + 1];\n\t\t\tfor (int[][] a : dp) {\n\t\t\t\tfor (int[] b : a) {\n\t\t\t\t\tArrays.fill(b, -1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint r = cal(0, data[0], data[1], dp);\n\t\t\tif (r == 0) {\n\t\t\t\tout.println(\"BitLGM\");\n\t\t\t} else {\n\t\t\t\tout.println(\"BitAryo\");\n\t\t\t}\n\t\t} else {\n\t\t\tint[][][][] dp = new int[2][data[0] + 1][data[1] + 1][data[2] + 1];\n\t\t\tfor (int[][][] a : dp) {\n\t\t\t\tfor (int[][] b : a) {\n\t\t\t\t\tfor (int[] c : b)\n\t\t\t\t\t\tArrays.fill(c, -1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint r = cal2(0, data[0], data[1], data[2], dp);\n\t\t\tif (r == 0) {\n\t\t\t\tout.println(\"BitLGM\");\n\t\t\t} else {\n\t\t\t\tout.println(\"BitAryo\");\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic int cal(int index, int a, int b, int[][][] dp) {\n\t\tif (a == 0 && b == 0) {\n\t\t\treturn 1 - index;\n\t\t}\n\t\tif (dp[index][a][b] != -1) {\n\t\t\treturn dp[index][a][b];\n\t\t}\n\t\tint result = 1 - index;\n\t\tfor (int i = 1; i <= a; i++) {\n\t\t\tint x = Math.min(a - i, b);\n\t\t\tint y = Math.max(a - i, b);\n\t\t\tint v = cal(1 - index, x, y, dp);\n\t\t\tif (v == index) {\n\t\t\t\tresult = index;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (result != index) {\n\t\t\tfor (int i = 1; i <= b; i++) {\n\t\t\t\tint x = Math.min(b - i, a);\n\t\t\t\tint y = Math.max(b - i, a);\n\t\t\t\tint v = cal(1 - index, x, y, dp);\n\t\t\t\tif (v == index) {\n\t\t\t\t\tresult = index;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result != index) {\n\t\t\t\tfor (int i = 1; i <= Math.min(a, b); i++) {\n\t\t\t\t\tint x = Math.min(b - i, a - i);\n\t\t\t\t\tint y = Math.max(b - i, a - i);\n\t\t\t\t\tint v = cal(1 - index, x, y, dp);\n\t\t\t\t\tif (v == index) {\n\t\t\t\t\t\tresult = index;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[index][a][b] = result;\n\t}\n\n\tstatic int cal2(int index, int a, int b, int c, int[][][][] dp) {\n\t\tif (a == 0 && b == 0 && c == 0) {\n\t\t\treturn 1 - index;\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif ((b ^ c) == 0)\n\t\t\t\treturn 1 - index;\n\t\t\treturn index;\n\t\t}\n\t\tif (dp[index][a][b][c] != -1) {\n\t\t\treturn dp[index][a][b][c];\n\t\t}\n\t\tint result = 1 - index;\n\t\tfor (int i = 1; i <= a; i++) {\n\t\t\tint x = a - i;\n\t\t\tint y = b;\n\t\t\tint v = cal2(1 - index, x, y, c, dp);\n\t\t\tif (v == index) {\n\t\t\t\tresult = index;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (result != index) {\n\t\t\tfor (int i = 1; i <= b; i++) {\n\t\t\t\tint x = Math.min(b - i, a);\n\t\t\t\tint y = Math.max(b - i, a);\n\t\t\t\tint v = cal2(1 - index, x, y, c, dp);\n\t\t\t\tif (v == index) {\n\t\t\t\t\tresult = index;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result != index) {\n\t\t\t\tfor (int i = 1; i <= c; i++) {\n\t\t\t\t\tint x = Math.min(a, c - i);\n\t\t\t\t\tint y = Math.max(b, c - i);\n\t\t\t\t\tint v = cal2(1 - index, x, a + b + c - i - x - y, y, dp);\n\t\t\t\t\tif (v == index) {\n\t\t\t\t\t\tresult = index;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (result != index) {\n\t\t\t\t\tfor (int i = 1; i <= a; i++) {\n\n\t\t\t\t\t\tint v = cal2(1 - index, a - i, b - i, c - i, dp);\n\t\t\t\t\t\tif (v == index) {\n\t\t\t\t\t\t\tresult = index;\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\t\treturn dp[index][a][b][c] = result;\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable {\n\n\t\tint x, y;\n\n\t\tpublic Point(int start, int end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 5;\n\t\t\thash = 47 * hash + this.x;\n\t\t\thash = 47 * hash + this.y;\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (getClass() != obj.getClass()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfinal Point other = (Point) obj;\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.y != other.y) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bdc9fa7a456623ae63adecbde5acb558", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\t\n\n\n\n\npublic class D173 {\n\tint INF = Integer.MAX_VALUE / 100;\n\tstatic Scanner sc = null;\n\tstatic PrintWriter out = null;\n\tint n = 0;\n\tlong b1 = 1000;\n\tlong b2 = 1000000;\n\tMap map = new HashMap();\n\tint cnt = 0;\n\tpublic void solve() throws Exception{\n\t\tn = sc.nextInt();\n\t\tint[] d = new int[3];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\td[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(d);\n\t\tint d1, d2, d3;\n\t\t\n\t\td1 = d[0];\n\t\td2 = d[1];\n\t\td3 = d[2];\n\t\t\n\t\tmap.put((long)0, false);\n\t\tif(n == 1){\n\t\t\tif(d[2] == 0){\n\t\t\t\tSystem.out.println(\"BitAryo\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"BitLGM\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\telse if(n == 2){\n\t\t\tif(check2(d2, d3)){\n\t\t\t\tSystem.out.println(\"BitLGM\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"BitAryo\");\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif(check3(d1, d2, d3)){\n\t\t\t\tSystem.out.println(\"BitLGM\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"BitAryo\");\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\n\t\t\n\n\t\n\t}\n\t\n\tlong create(int d1, int d2, int d3){\n\t\tlong ret = d1 + b1 * d2 + b2 * d3;\n\t\treturn ret;\n\t}\n\t\n\tboolean check2(int d1, int d2){\n\t\tcnt++;\n\t\tlong ck = create(d1, d2, 0);\n\t\tif(map.containsKey(ck)){\n\t\t\treturn map.get(ck);\n\t\t}\n\t\tif(d1 == 0){\n\t\t\tmap.put(ck, true);\n\t\t\treturn true;\n\t\t}\n\t\tif(d1 == d2){\n\t\t\tmap.put(ck, true);\n\t\t\treturn true;\n\t\t}\n\n\t\tfor(int i = 1; i < d1; i++){\n\t\t\tif(!check2(d1 - i, d2 - i)){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\t\n\t\tfor(int i = 1; i < d1; i++){\n\t\t\tif(!check2(d1 - i, d2)){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 1; i < d2; i++){\n\t\t\tif(!check2(Math.min(d1, d2 - i), Math.max(d1, d2 - i))){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tmap.put(ck, false);\n\t\treturn false;\n\t}\n\t\n\t\n\tboolean check3(int d1, int d2, int d3){\n\n\t\tlong ck = create(d1, d2, d3);\n\t\tif(map.containsKey(ck)){\n\t\t\treturn map.get(ck);\n\t\t}\n\t\t\n\t\tif(d1 == d2 && d2 == d3){\n\t\t\tmap.put(ck, true);\n\t\t\treturn true;\n\t\t}\n\n\t\tif(d1 == 0){\n\n\t\t\tint k = d2 ^ d3;\n\t\t\tif(k > 0){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tmap.put(ck, false);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\t\t\n\t\tif( (d1 ^ d2) == 0 || (d2 ^ d3) == 0 || (d1 ^ d3) == 0){\n\t\t\tmap.put(ck, true);\n\t\t\treturn true;\n\t\t}\n\t\t\t\n\n\t\t\t\n\t\tfor(int i = 1; i < d1; i++){\n\t\t\tif(!check3(d1 - i, d2 - i, d3 - i)){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\t\n\t\tfor(int i = 1; i < d1; i++){\n\t\t\tif(!check3(d1 - i, d2, d3)){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 1; i < d2; i++){\n\t\t\tif(!check3(Math.min(d1, d2 - i), Math.max(d1, d2 - i), d3)){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\t\n\t\t\n\t\tfor(int i = 1; i < d3; i++){\n\t\t\tint n1 = d1;\n\t\t\tint n2 = d2;\n\t\t\tint n3 = d3 - i;\n\t\t\tif(n3 < n1){\n\t\t\t\tint t = n3;\n\t\t\t\tn3 = n2;\n\t\t\t\tn2 = n1;\n\t\t\t\tn1 = t;\n\t\t\t}\n\t\t\telse if(n3 < n2){\n\t\t\t\tint t = n3;\n\t\t\t\tn3 = n2;\n\t\t\t\tn2 = t;\n\t\t\t}\n\t\t\tif(!check3(n1, n2, n3)){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tmap.put(ck, false);\n\t\treturn false;\n\t}\n\t\n\t/*\n\tboolean check(int[] c){\n\t\tlong ck = 0;\n\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tck += Math.pow(b1, i) * c[i];\n\t\t}\n\t\t\n\t\tif(map.containsKey(ck)){\n\t\t\treturn map.get(ck);\n\t\t}\n\t\tboolean f = false;\n\t\tif(c[0] == 0){\n\t\t\tif(n == 2){\n\t\t\t\tf = true;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tint k = c[1] ^ c[2];\n\t\t\t\tif(k > 0){\n\t\t\t\t\tmap.put(ck, true);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tint[] nc = new int[n];\n\t\t\t\tfor(int j = 0; j < n; j++){\n\t\t\t\t\tif(i == j){\n\t\t\t\t\t\tnc[j] = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tnc[j] = c[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tArrays.sort(nc);\n\t\t\t\tif(!check(nc)){\n\t\t\t\t\tmap.put(ck, true);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint [] nc = new int[n];\n\t\t\tnc[0] = 0;\n\t\t\tfor(int i = 1; i < n; i++){\n\t\t\t\tnc[i] = c[i] - c[0];\n\t\t\t}\n\t\t\tif(!check(nc)){\n\t\t\t\tmap.put(ck, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tfor(int i = 1; i < c[0]; i++){\n\t\t\t\tnc = new int[n];\n\t\t\t\tfor(int j = 0; j < n; j++){\n\t\t\t\t\tnc[j] = c[j] - i;\n\t\t\t\t}\n\t\t\t\tif(!check(nc)){\n\t\t\t\t\tmap.put(ck, true);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 1; i < c[0]; i++){\n\t\t\t\tnc = Arrays.copyOf(c, n);\n\t\t\t\tnc[0] -= i;\n\t\t\t\tif(!check(nc)){\n\t\t\t\t\tmap.put(ck, true);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 1; i < c[1]; i++){\n\t\t\t\tnc = Arrays.copyOf(c, n);\n\t\t\t\tnc[1] -= i;\n\t\t\t\tArrays.sort(nc);\n\t\t\t\tif(!check(nc)){\n\t\t\t\t\tmap.put(ck, true);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(n == 3){\n\t\t\t\tfor(int i = 1; i < c[2]; i++){\n\t\t\t\t\tnc = Arrays.copyOf(c, n);\n\t\t\t\t\tnc[2] -= i;\n\t\t\t\t\tArrays.sort(nc);\n\t\t\t\t\tif(!check(nc)){\n\t\t\t\t\t\tmap.put(ck, true);\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\n\t\t\n\t\tmap.put(ck, f);\n\t\treturn f;\n\t}\n\t*/\n public int[] readIntArray(int n) {\n int[] ret = new int[n];\n for (int i = 0; i < n; i++) {\n ret[i] = sc.nextInt();\n }\n return ret;\n }\n\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) throws Exception{\n\t\tFile file = new File(\"input.txt\");\n\t\tif(file.exists()){\n\t\t\tSystem.setIn(new BufferedInputStream(new FileInputStream(\"input.txt\")));\n\t\t}\n\t\tout = new PrintWriter(System.out);\n\t\tsc = new Scanner(System.in);\n\t\tD173 t = new D173();\n\t\tt.solve();\n\t\t\n\t\t/*\n\t\t * \nTLE\n2\n298 184\n\t\t */\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "378a47d95beb08821789b6838d42a815", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class D {\n\tstatic final String FIRST = \"BitLGM\";\n\tstatic final String SECOND = \"BitAryo\";\n\tstatic class Holder{\n\t\tfinal int [] game;\n\t\tfinal int hash;\n Holder(int [] game){\t\t\n \tthis.game = game.clone();\n \tthis.hash = Arrays.hashCode(this.game);\n }\n public boolean equals(Object other){\n \tif (this == other){\n \t\treturn true;\n \t}\n \tif (!(other instanceof Holder)){\n \t\treturn false;\n \t}\n \tfinal Holder h = (Holder)other;\n \treturn Arrays.equals(game, h.game);\n }\n public int hashCode(){\n \treturn hash;\n }\n\t}\n\tstatic boolean rec(int [] game, Map memo){\n\t\tfinal Holder key = new Holder(game);\n\t\tif (memo.containsKey(key)){\n\t\t\treturn memo.get(key);\n\t\t}\n\t\tfor (int i = 0; i < game.length; ++i){\n\t\t\tfor (int j = 1; j <= game[i]; ++j){\n\t\t\t\tfinal int [] g = game.clone();\n\t\t\t\tg[i] -= j;\n\t\t\t\tArrays.sort(g);\n\t\t\t\tif (!rec(g, memo)){\n\t\t\t\t\tmemo.put(key, true);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 1; i <= game[0]; ++i){\n\t\t\tfinal int [] g = game.clone();\n\t\t\tfor (int j = 0; j < game.length; ++j){\n\t\t\t\tg[j] -= i;\n\t\t\t}\n\t\t\tif (!rec(g, memo)){\n\t\t\t\tmemo.put(key, true);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tmemo.put(key, false);\n\t\treturn false;\n\t}\n\tpublic static void main(String [] args){\n\t\ttry (Scanner s = new Scanner(System.in)){\n\t\t\tfinal int n = s.nextInt();\n\t\t final int [] game = new int[n];\n\t\t for (int i = 0; i < n; ++i){\n\t\t \tgame[i] = s.nextInt();\n\t\t }\n\t\t Arrays.sort(game);\n\t\t final boolean win = rec(game, new HashMap());\n\t\t System.out.println((win ? FIRST : SECOND));\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "15e942791bec4b72e28badefbc2ab237", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.BigInteger;\n\n\npublic class Main {\n \n\n\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint t,ca,i,j,k,l;\n\t\tString[] my;\n\t\tString line = br.readLine();\n int n,x,y,z;\n n = Integer.parseInt(line);\n String win = \"BitLGM\";\n line = br.readLine();\n if(n==1)\n {\n \n x = Integer.parseInt(line);\n if(x==0)win = \"BitAryo\";\n \n }\n else if(n==2)\n {\n my = line.split(\" \");\n x= Integer.parseInt(my[0]);\n y = Integer.parseInt(my[1]);\n int[][]a = new int[302][302];\n for(i=0;i<301;i++)\n for(j=0;j<301;j++)\n if(a[i][j]==0)\n {\n for(l = 1;i+l<301;l++)a[i+l][j] = 1;\n for(l = 1;j+l<301;l++)a[i][j+l] = 1;\n for(l=1;i+l<301 && j+l<301;l++)a[i+l][j+l] = 1;\n }\n if(a[x][y]==0)win = \"BitAryo\";\n }\n else {\n my = line.split(\" \");\n x= Integer.parseInt(my[0]);\n y = Integer.parseInt(my[1]);\n z = Integer.parseInt(my[2]);\n int[][][]a = new int[302][302][302];\n for(i=0;i<301;i++)\n for(j=0;j<301;j++)\n for(k=0;k<301;k++)\n if(a[i][j][k]==0)\n {\n // System.out.println(i+ \" \" + j + \" \" + k + \" is loosing\");\n for(l = 1;i+l<301;l++)a[i+l][j][k] = 1;\n for(l = 1;j+l<301;l++)a[i][j+l][k] = 1;\n for(l = 1;k+l<301;l++)a[i][j][k+l] = 1;\n for(l=1;i+l<301 && j+l<301 && k+l<301;l++)a[i+l][j+l][k+l] = 1;\n }\n if(a[x][y][z]==0)win = \"BitAryo\";\n }\n System.out.println(win);\n \n }\n \n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d4fe66edf00091c76d3117dd115c5ce", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport javax.swing.SwingConstants;\n\npublic class MainA {\n\tprivate static InputStream stream;\n\tprivate static byte[] buf = new byte[1024];\n\tprivate static int curChar;\n\tprivate static int numChars;\n\tprivate static SpaceCharFilter filter;\n\tprivate static PrintWriter pw;\n\t//private static long mod = 1000000000 + 7;\n\tstatic long count=0;\n\tstatic int flag=-1;\n\tstatic int d[];\n\tstatic int ans[][];\n\tstatic int d2[];\n\tstatic int ans2[][];\n\tpublic static int[] dfs( int v, int vis[], ArrayList arr[],int k ,int r[])\n\t{\n\t\tvis[v]=1;\n\t\tfor(int i=0;i arr[],int k ,int r[])\n\t{\n\t\tvis[v]=1;\n\t\tfor(int i=0;i=0;i--)\n\t\t{\n\t\t\tint x=arr[v].get(i);\n\t\t\n\t\t\tif(vis[x]==0)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tint a[]=dfs(x,vis,arr,k,r);\t\n\t\t\t\tfor(int j=0;j high || idx < low || low > high)\n\t return;\n\t \n\t if (low == high)\n\t { \n\t cur.val = prev.val+value;\n\t return;\n\t }\n\t int mid = (low+high) / 2;\n\t if (idx <= mid)\n\t {\n\t cur.right = prev.right;\t \n\t cur.left = new Node(null, null, 0);\n\t upgrade(prev.left,cur.left, low, mid, idx, value);\n\t }\n\t else\n\t {\n\t cur.left = prev.left;\n\t cur.right = new Node(null, null, 0);\n\t upgrade(prev.right, cur.right, mid+1, high, idx, value);\n\t }\n\t cur.val = cur.left.val + cur.right.val;\n\t}\n\t \n\tpublic static long query(Node n, int low, int high, int l, int r)\n\t{\n\t if (l > high || r < low || low > high)\n\t return 0;\n\t if (l <= low && high <= r)\n\t return n.val;\n\t int mid = (low+high) / 2;\n\t long p1 = query(n.left,low,mid,l,r);\n\t long p2 = query(n.right,mid+1,high,l,r);\n\t // pw.println(p1+\" \"+p2+\" \"+low+\" \"+high );\n\t return p1+p2;\n\t}\n\n\tpublic static int time=0;\n\tpublic static void dfs(int x,int vis[],ArrayList arr[],int in[],int out[])\n\t{\n\t\tvis[x]=1;\n\t\tin[x]=time++;\n\t\tfor(int i=0;i arr[])\n\t{\n\t\tPriorityQueue q=new PriorityQueue();\n\t\tq.add(new Pair(0,0));\n\t\tlong dist[]=new long[n];\n\t\tboolean vis[]=new boolean[n];\n\t\tArrays.fill(dist,Long.MAX_VALUE);\n\t\tdist[v]=0;\n\t\t//pw.println(k);\n\t\t\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\t\n\t\t\tPair top=q.poll();\n\t\t\t\n\t\t\t//pw.println(pp.x+\" \"+pp.y+\" \"+pp.w);\n\t\t\tif(vis[top.x])\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tpw.println(top.x +\" \"+dist[top.x]);\n\t\t\tvis[top.x]=true;\n\t\t\tfor(int i=0;i q=new LinkedList();\n\t\tq.addFirst(new Pairs(x1,y1));\t\t\n\t\tfor(int i=0;i=0 && yd>=0 && xdtime)return Integer.MAX_VALUE;\n\t temp+=c*arr[i];\n\t if(temp>time)\n\t {\n\t temp=c*arr[i]; \n\t count++;\n\t }\n\t i++;\n\t }\n\t if(temp>0)count++;\n\t return count;\n\t }\n\tpublic static int paint(int A, int B, int C[]) {\n \n\t int low=0;int high=(int)100;int mid;int r=-1;\n\t while(low<=high)\n\t {\n\t mid=(low+high)/2;\n\t //pw.println(low+\" \"+high);\n\t if(f(mid,B,C)<=A)\n\t {\n\t \t r=mid;\n\t high=mid-1;\n\t }\n\t else\n\t {\n\t low=mid+1;\n\t }\n\t }\n\t return (r%(10000003));\n\t }\n\t\n\t\n\t static ArrayList> arr=new ArrayList>();\n\t public static ArrayList> combine(int A, int B) {\n\t co(A,B,0,1,new ArrayList());\n\t pw.println(arr.get(0).size());\n\t for(int i=0;i ar)\n\t {\n\t if(pos==k)\n\t {\n\t \tfor(int i=0;i answ=new ArrayList();\n\t public static ArrayList generateParenthesis(int A) {\n\t String res=\"\";\n\t pw.println(\"ji\");\n\t genP(0,0,A,res);\n\t return answ;\n\t }\n\t \n\t public static void genP(int i,int j,int n,String res)\n\t {\n\t if(i==n)\n\t {\n\t if(jj)\n\t {\n\t //ar.add('(');\n\t genP(i+1,j,n,res+\"(\");\n\t //ar.remove((Character)'(');\n\t //ar.add(')');\n\t genP(i,j+1,n,res+\")\");\n\t // ar.remove((Character)')');\n\t }\n\t }\n\t\n\t \n\t \n\t public static ArrayList generateParenthesis2(int A) {\n\t genP(0,0,A,new ArrayList());\n\t return answ;\n\t }\n\t \n\t public static void genP(int i,int j,int n,ArrayList ar)\n\t {\n\t if(i==n)\n\t {\n\t \tif(jj)\n\t {\n\t ar.add('(');\n\t genP(i+1,j,n,ar);\n\t ar.remove((Character)'(');\n\t //pw.println(i+\" \"+j);\n\t if(i==2 && j==1)\n\t {\n\t \tfor(int k=0;k 0)\n {\n // If y is odd, multiply x\n // with result\n if((y1 & 1)==1)\n res = (res * x1) % p;\n \n // y must be even now\n // y = y / 2\n y1 = y1 >> 1; \n x1 = (x1 * x1) % p; \n }\n return res;\n\t}\n\tpublic static int biSearch(long div[],long n)\n\t{\n\t\tint low=0;int high=div.length-1;int res=-1;\n\t\twhile(low<=high)\n\t\t{\n\t\t\tint mid=(low+high)/2;\n\t\t\tif(div[mid] arr,long mod)\n\t{\n\t\tfor(int i=0;i<=k;i++)prime[i]=i;\n\t\t\n\t\tfor(int i=2;i*i<=k;i++)\n\t\t{\n\t\t\tif(prime[i]==i)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tfor(int j=2*i;j<=k;j+=i)\n\t\t\t\t{\n\t\t\t\t\tprime[j]=i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i=2;i<=k;i++)if(prime[i]==i)arr.add(prime[i]);\n\t\tco[1]=1;\n\t\tfor(int i=2;i<=k;i++)\n\t\t{\n\t\t\tint key=i;int prev=0;co[i]=i;\n\t\t\twhile(key>1)\n\t\t\t{\n\t\t\t\tint p=prime[key];\n\t\t\t\tkey/=p;\n\t\t\t\tif(prev!=p)\n\t\t\t\t{\n\t\t\t\t\tco[i]=(co[i]*(p-1));\n\t\t\t\t\tco[i]=(co[i]/p);\n\t\t\t\t}\t\t\t\t\n\t\t\t\tprev=p;\t\n\t\t\t}\n\t\t\tco[i]=(co[i]*i)/2;\n\t\t\tco[i]=(co[i]%mod);\n\t\t\t//pw.println(i+\" \"+co[i]);\n//\t\t\t335337501\n//\t\t\t958499634\n//\t\t\t29518260\n//\t\t\t279765089\n//\t\t\t999998607\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\tpublic static double dist(int x, int y,int a[], int b[])\n\t{\n\t\treturn Math.sqrt(Math.pow(a[x]-a[y],2)+Math.pow(b[x]- b[y],2));\n\t}\n\tpublic static double bSearch(int a[],int b[],int n,long p)\n\t{\n\t\tdouble l=0;double r=(double)1e15;\n\t\tfor(int i=0;i<200;i++)\n\t\t{\n\t\t\tdouble mid=(l+r)/2;\n\t\t\t//pw.printf(\"%f \",mid);\n\t\t\tif(f(mid,a,b,p,n))\n\t\t\t{\n\t\t\t\tl=mid;\n\t\t\t\t\n\t\t\t\t//pw.printf(\" %f\", l);\n\t\t\t}\n\t\t\telse r=mid;\n\t\t\t//pw.println();\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tpublic static boolean f(double t,int a[],int b[],long p,int n)\n\t{\n\t\tdouble totalCons=0;\n\t\tfor(int i=0;i0)\n\t\t\t{\n\t\t\t\ttotalCons+=total;\n\t\t\t}\n\t\t}\n\t\t//pw.printf(\"%f %f\\n\",totalCons,p*t);\n\t\tif(totalCons<=p*t)return true;\n\t\telse return false;\n\t}\n\tpublic static int check(String s[],int x, int y,int n,int m)\n\t{\n\t\tint dx[]= {-1,0,1,1,1,0,-1,-1};\n\t\tint dy[]= {-1,-1,-1,0,1,1,1,0};\n\t\tint count=0;\n\t\tfor(int i=0;i<8;i++)\n\t\t{\n\t\t\tint vx=x+dx[i];\n\t\t\tint vy=y+dy[i];\n\t\t\tif(vx<0 || vx>=n ||vy<0 || vy>=m)\n\t\t\t{\n\t\t\t\t\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(s[vx].charAt(vy)=='*')count++;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n\n\tpublic static class Pair implements Comparable\n\t{\n\t\tlong val;\n\t\tint x;\n\t\tPair(long a,int b)\n\t\t{\n\t\t\tval=a;x=b;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(Pair o)\n\t\t{\n\t\t\t\n\t\t\treturn Long.compare(val,o.val);\n\t\t}\n\t}\n\tpublic static class Segment {\n\t\tprivate int[] tree;\n\t\tprivate boolean[] lazy;\n\t\tprivate int size;\n\t\tprivate int n;\n\n\t\tprivate class node {\n\t\t\tprivate int a;\n\t\t\tprivate int b;\n\t\t\tprivate int c;\n\n\t\t\tpublic node(int x, int y, int z) {\n\t\t\t\ta = x;\n\t\t\t\tb = y;\n\t\t\t\tc = z;\n\t\t\t}\n\t\t}\n\n\t\tpublic Segment(int n) {\n\t\t\t//this.base=arr;\n\t\t\tint x = (int) (Math.ceil(Math.log(n) / Math.log(2)));\n\t\t\tsize = 2 * (int) Math.pow(2, x) - 1;\n\t\t\ttree = new int[size];\n\t\t\tlazy = new boolean[size];\n\t\t\tthis.n = n;\n\t\t\tbuild(0, 0, n - 1);\n\t\t}\n\n\t\tpublic void build(int id, int l, int r) {\n\t\t\tif (l == r) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = (l + r) / 2;\n\t\t\tbuild(2 * id + 1, l, mid);\n\t\t\tbuild(2 * id + 2, mid + 1, r);\n\t\t\ttree[id] = tree[2 * id + 1] + tree[2 * id + 2];\n\t\t}\n\n\t\tpublic int query(int l, int r) {\n\t\t\treturn queryUtil(l, r, 0, 0, n - 1);\n\t\t}\n\n\t\tprivate int queryUtil(int x, int y, int id, int l, int r) {\n\t\t\tif (l > y || x > r)\n\t\t\t\treturn 0;\n\t\t\tif (x <= l && r <= y) {\n\t\t\t\t//if(!lazy[id])\n\t\t\t\treturn tree[id];\n\t\t\t\t//else\n\t\t\t\t//\treturn tree[id][0];\n\t\t\t}\n\t\t\tint mid = l + (r - l) / 2;\n\t\t\tshift(id);\n\t\t\treturn queryUtil(x, y, 2 * id + 1, l, mid) + queryUtil(x, y, 2 * id + 2, mid + 1, r);\n\t\t}\n\n\t\tpublic void update(int x, int y, int colour, int id, int l, int r) {\n\t\t\t//System.out.println(l+\" \"+r+\" \"+x);\n\t\t\tif (x > r || y < l)\n\t\t\t\treturn;\n\t\t\tif (x <= l && r <= y) {\n\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = l + (r - l) / 2;\n\t\t\tshift(id);\n\t\t\tupdate(x, y, colour, 2 * id + 1, l, mid);\n\t\t\tupdate(x, y, colour, 2 * id + 2, mid + 1, r);\n\t\t\ttree[id] = tree[2 * id + 1] + tree[2 * id + 2];\n\t\t}\n\n\t\tpublic void shift(int id) {\n\n\t\t}\n\t}\n\n\tpublic static void fft(double[] a, double[] b, boolean invert) {\n\t\tint count = a.length;\n\t\tfor (int i = 1, j = 0; i < count; i++) {\n\t\t\tint bit = count >> 1;\n\t\t\tfor (; j >= bit; bit >>= 1)\n\t\t\t\tj -= bit;\n\t\t\tj += bit;\n\t\t\tif (i < j) {\n\t\t\t\tdouble temp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = temp;\n\t\t\t\ttemp = b[i];\n\t\t\t\tb[i] = b[j];\n\t\t\t\tb[j] = temp;\n\t\t\t}\n\t\t}\n\t\tfor (int len = 2; len <= count; len <<= 1) {\n\t\t\tint halfLen = len >> 1;\n\t\t\tdouble angle = 2 * Math.PI / len;\n\t\t\tif (invert)\n\t\t\t\tangle = -angle;\n\t\t\tdouble wLenA = Math.cos(angle), wLenB = Math.sin(angle);\n\t\t\tfor (int i = 0; i < count; i += len) {\n\t\t\t\tdouble wA = 1, wB = 0;\n\t\t\t\tfor (int j = 0; j < halfLen; j++) {\n\t\t\t\t\tdouble uA = a[i + j], uB = b[i + j];\n\t\t\t\t\tdouble vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;\n\t\t\t\t\tdouble vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;\n\t\t\t\t\ta[i + j] = uA + vA;\n\t\t\t\t\tb[i + j] = uB + vB;\n\t\t\t\t\ta[i + j + halfLen] = uA - vA;\n\t\t\t\t\tb[i + j + halfLen] = uB - vB;\n\t\t\t\t\tdouble nextWA = wA * wLenA - wB * wLenB;\n\t\t\t\t\twB = wA * wLenB + wB * wLenA;\n\t\t\t\t\twA = nextWA;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (invert) {\n\t\t\tfor (int i = 0; i < count; i++) {\n\t\t\t\ta[i] /= count;\n\t\t\t\tb[i] /= count;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void multiply(long[][] a, long[][] b, long m) {\n\t\tint n = a.length;\n\t\tlong[][] mul = new long[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\tmul[i][j] = 0;\n\t\t\t\tfor (int k = 0; k < n; k++)\n\t\t\t\t\tmul[i][j] = (mul[i][j] + (a[i][k] * b[k][j]) % m) % m;\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\ta[i][j] = mul[i][j];\n\t}\n\n\tprivate static long pow(long a, long b, long c) {\n\t\tif (b == 0)\n\t\t\treturn 1;\n\t\tlong p = pow(a, b / 2, c);\n\t\tp = (p * p) % c;\n\t\treturn (b % 2 == 0) ? p : (a * p) % c;\n\t}\n\n\tprivate static long gcd(long n, long l) {\n\t\tif (l == 0)\n\t\t\treturn n;\n\t\treturn gcd(l, n % l);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\t//\t\tnew Thread(null, new Runnable()\n\t\t//\t\t{\n\t\t//\t\t\t@Override\n\t\t//\t\t\tpublic void run()\n\t\t//\t\t\t{\n\t\t//\t\t\t\t/*try { \n\t\t//\t\t\t\t\tInputReader(new FileInputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\B-large-practice.in\")); \n\t\t//\t\t\t\t} catch (FileNotFoundException e) { // 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\tInputReader(System.in);\n\t\t//\t\t\t\tpw = new PrintWriter(System.out);\n\t\t//\t\t\t\t/*try { \n\t\t//\t\t\t\t\tpw=new PrintWriter(new FileOutputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\out.txt\")); \n\t\t//\t\t\t\t} catch (FileNotFoundException e) { // 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\tsoln();\n\t\t//\t\t\t\tpw.close();\n\t\t//\t\t\t}\n\t\t//\t\t}, \"1\", 1 << 26).start();\n\n\t\t/*try { \n\t\t\tInputReader(new FileInputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\B-large-practice.in\")); \n\t\t} catch (FileNotFoundException e) { // TODO Auto-generated catch block\n\t\t\te.printStackTrace(); \n\t\t} */\n\t\tInputReader(System.in);\n\t\tpw = new PrintWriter(System.out);\n\t\t/*try { \n\t\t\tpw=new PrintWriter(new FileOutputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\out.txt\")); \n\t\t} catch (FileNotFoundException e) { // TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}*/\n\t\tsoln();\n\t\tpw.close();\n\t}\n\n\tpublic static void InputReader(InputStream stream1) {\n\t\tstream = stream1;\n\t}\n\n\tprivate static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tprivate static boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n\n\tprivate static int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tprivate static int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate static long nextLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate static String nextToken() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate static String nextLine() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate static int[] nextIntArray(int n) {\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = nextInt();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate static long[] nextLongArray(int n) {\n\t\tlong[] arr = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = nextLong();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate static void pArray(int[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate static void pArray(long[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate static boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tprivate static char nextChar() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tchar c1 = (char) c;\n\t\twhile (!isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn c1;\n\t}\n\n\tprivate interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f3d87a96e7515404d7fa357674d3acb", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class D991 \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tString R1 = in.nextLine();\n\t\tin.nextLine();\n\t\tString R2 = in.nextLine();\n\t\t\n\t\tint emptyS = 0, length = R1.length(), bishwock=0;\n\t\tint c1=0, c2=1;\n\t\t\n\t\tboolean[] visited1 = new boolean[length];\n\t\tboolean[] visited2 = new boolean[length];\n\t\t\n\t\tfor(int i=0;i= TOTAL) {\n INDEX = 0;\n try {\n TOTAL = in.read(buf);\n } catch (Exception e) {\n e.printStackTrace();\n }\n if (TOTAL <= 0) return -1;\n }\n return buf[INDEX++];\n }\n\n public String scanString() {\n int c = scan();\n while (isWhiteSpace(c)) c = scan();\n StringBuilder RESULT = new StringBuilder();\n do {\n RESULT.appendCodePoint(c);\n c = scan();\n } while (!isWhiteSpace(c));\n return RESULT.toString();\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n else return false;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "da0a9cf8c315a32ad837a447dd4278f4", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t BigInteger t[] = new BigInteger[100000];\n\t t[0] = BigInteger.valueOf(100);\n\t for(int i=1; i[] amp;\n public static void main(String[] args) throws Exception\n {\n new Thread(null, new Runnable()\n {\n public void run()\n {\n try {\n } catch (Exception e)\n {\n System.out.println(e);\n }\n }\n }, \"1\", 1 << 26).start();\n new Main1().soln();\n }\n char ch[][];\n static ArrayList[] g;\n static ArrayList ar[];\n static long ok[]; \n static int phi[]=new int[500005];\n void solve()\n {", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d5684f2468d8bc96174341d56190904e", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t BigInteger t[] = new BigInteger[10000];\n\t t[0] = BigInteger.valueOf(10);\n\t for(int i=1; i 0) {\n y *= k;\n }\n return x / y;\n }\n \n public static void main() {\n Scanner s new Scanner();\n int z = s.nextInt();\n long n = (long) z;\n System.out.println(6 * nCk(n - 3, 0) + 12 * nCk(n - 3, 1) + 8 * nCk(n - 3, 2) + 2 * nCk(n - 3, 3))\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e6a82817fde685658a9d80cc48545083", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n\npublic class Cf86 implements Runnable \n{\n\tstatic class InputReader \n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\tprivate BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tpublic InputReader(InputStream stream) \n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int read()\n\t\t{\n\t\tif (numChars==-1) \n\t\t\tthrow new InputMismatchException();\n \n\t\tif (curChar >= numChars) \n\t\t{\n\t\t\tcurChar = 0;\n\t\t\ttry\n\t\t\t{\n\t\t\t\tnumChars = stream.read(buf);\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\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 public String nextLine()\n {\n\t\tString str = \"\";\n\t\ttry\n\t\t{\n\t\t\tstr = br.readLine();\n\t\t}\n\t\tcatch (IOException e)\n\t\t{\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn str;\n\t}\n public int nextInt() \n {\n\t\tint c = read();\n\t\t\n\t\twhile(isSpaceChar(c)) \n\t\t\tc = read();\n \n\t\tint sgn = 1;\n \n\t\tif (c == '-') \n\t\t{\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n \n\t\tint res = 0;\n\t\tdo\n\t\t{\n\t\t\tif(c<'0'||c>'9') \n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\twhile (!isSpaceChar(c)); \n \n\t\treturn res * sgn;\n\t}\n \n public long nextLong() \n {\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{\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n \n\t\tdo \n\t\t{\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\twhile (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n }\n \n public double nextDouble() \n {\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{\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{\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, nextInt());\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{\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(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\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 }\n \n public String readString() \n {\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{\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} \n\t\twhile (!isSpaceChar(c));\n \n\t\treturn res.toString();\n }\n \n\tpublic boolean isSpaceChar(int c) \n\t{\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic String next()\n\t{\n\t\treturn readString();\n\t}\n \n\tpublic interface SpaceCharFilter\n\t{\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n\t}\n\tpublic static void main(String args[]) throws Exception \n\t{\n\t\tnew Thread(null, new Cf86(),\"Main\",1<<27).start();\n\t}\n\tpublic void run()\n\t{\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\tint n=in.nextInt();\n\t\tint sum=0;\n\t\tfor(i=2;i55?Long.MAX_VALUE:arr1[n];\n }\n\n private static Long getNum(int n){\n return n>0?68+getNum(n-1)*2:75L;\n }\n\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String[] arr;\n Long a,b,k,p,countStrings=5L;\n arr = in.readLine().split(\" \");\n countStrings = Long.valueOf(arr[0]);\n StringBuilder helpStr = new StringBuilder();\n String str1 = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\n String str2=\"What are you doing while sending \\\"1\\\"? Are you busy? Will you send \\\"2\\\"?\";\n\n\n Long[] arr1 = new Long[100];\n\n StringBuilder answer = new StringBuilder();\n for (int i = 0; i < countStrings; i++) {\n arr = in.readLine().split(\" \");\n a = Long.valueOf(arr[0]);\n b = Long.valueOf(arr[1]);\n answer.append(getCharachter(a.intValue(),b));\n }\n\n System.out.println(answer.toString());\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ba76b1c37dbed185c3774d06df5d11c", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class C896A {\n\n static final String xx = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\n static final int lx = xx.length();\n\n static final String aa = \"What are you doing while sending \\\"\";\n static final int la = aa.length();\n static final String bb = \"\\\"? Are you busy? Will you send \\\"\";\n static final int lb = bb.length();\n static final String cc = \"\\\"?\";\n static final int lc = cc.length();\n\n static final int N = 100001;\n static final long[] len = new long[N];\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n\n len[0] = lx;\n for (int i = 1; i < N; i++) {\n len[i] = 2 * len[i - 1] + la + lb + lc;\n if (len[i] >= 3000000000000000000L) {\n break;\n }\n }\n\n int q = scanner.nextInt();\n for (int i = 0; i < q; i++) {\n long n = scanner.nextLong();\n long k = scanner.nextLong();\n k--;\n if (len[n] > 0 && k > len[n]) {\n System.out.print('.');\n } else {\n solve(n, k);\n }\n }\n }\n\n public static void solve(long n, long k) {\n if (n == 0) {\n System.out.print(xx.charAt((int) k));\n } else if (len[(int) n] == 0) {\n solve(n - 1, k - la);\n } else {\n if (k < la) {\n System.out.print(aa.charAt((int) k));\n } else if (k < la + len[(int) (n - 1)]) {\n solve(n - 1, k - la);\n } else if (k < la + len[(int) (n - 1)] + lb) {\n System.out.print(bb.charAt((int) (k - la - len[(int) (n - 1)])));\n } else if (k < la + 2 * len[(int) (n - 1)] + lb) {\n solve(n - 1, k - la - len[(int) (n - 1)] - lb);\n } else {\n System.out.print(cc.charAt((int) (k - la - 2 * len[(int) (n - 1)] - lb)));\n }\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8dddbe4b5351b934b021fe238f979fb6", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Swatantra\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 String f0 = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\n String t1 = \"What are you doing while sending \\\"\";\n String t2 = \"\\\"? Are you busy? Will you send \\\"\";\n String t3 = \"\\\"?\";\n long len = new long[100001];\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n calclen();\n int q = in.nextInt();\n\n while (q > 0) {\n int n = in.nextInt();\n long k = in.nextLong();\n\n\n findchar(n, k - 1);\n q--;\n }\n }\n\n void findchar(int n, long k) {\n if (k >= len[n]) {\n System.out.print(\".\");\n return;\n\n } else if (n == 0) {\n System.out.print(f0.charAt((int) k));\n return;\n\n } else if (k < t1.length()) {\n System.out.print(t1.charAt((int) k));\n return;\n }\n k = k - t1.length();\n //System.out.println(\"k=\"+k+\"n=\"+n);\n if (k <= len[n - 1]) {\n findchar(n - 1, k);\n return;\n }\n k = k - len[n - 1];\n if (k <= t2.length()) {\n System.out.print(t2.charAt((int) k));\n return;\n }\n k = k - t2.length();\n\n if (k <= len[n - 1]) {\n findchar(n - 1, k);\n return;\n }\n k = k - len[n - 1];\n if (k <= t3.length()) {\n System.out.print(t3.charAt((int) k));\n return;\n }\n\n\n }\n\n void calclen() {\n len[0] = f0.length();\n\n int i;\n for (i = 1; i <= 100000; i++) {\n len[i] = t1.length() + len[i - 1] + t2.length() + len[i - 1] + t3.length();\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "37ae90081f3841f8356bb2938b0767e8", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main implements Runnable {\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 C897 solver = new C897();\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 C897 {\n String zero = new String(\"What are you doing at the end of the world? Are you busy? Will you save us?\");\n\n Long len(int N) {\n if (N > 55) return null;\n return 75L * (long) Math.pow(2, N) + 68L * ((long) Math.pow(2, N) - 1);\n }\n\n char solve(int N, long ind) {\n if (N == 0)\n return zero.charAt((int) ind);\n Long len = len(N), len2 = len(N - 1);\n // What are you doing while sending \"N - 1\"? Are you busy? Will you send \"N - 1\"?\n if (ind < 34) {\n return \"What are you doing while sending \\\"\".charAt((int) ind);\n }\n if (len2 == null || ind < 34 + len2) {\n return solve(N - 1, ind - 34);\n }\n ind -= 34 + len2;\n // \"? Are you busy? Will you send \"N - 1\"?\n if (ind < 32) {\n return \"\\\"? Are you busy? Will you send \\\"\".charAt((int) ind);\n }\n if (ind < 32 + len2) {\n return solve(N - 1, ind - 32);\n }\n ind -= 32 + len2;\n if (ind > 2)\n return '.';\n return \"\\\"?\".charAt((int) ind);\n }\n\n public void solve(int testNumber, FastScanner s, PrintWriter out) {\n\n\n int N = s.nextInt();\n long ind = s.nextLong() - 1;\n\n Long len = len(N);\n if (len != null && ind >= len) {\n out.print(\".\");\n return;\n }\n\n out.print(solve(N, ind));\n\n }\n\n }\n\n static class FastScanner {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n 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)\n 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 public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String next() {\n 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 }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f3f1518ff159290d7dce874b9ad1c57e", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "//package fb1;\n\n\n\n//package fb1;\n\nimport java.util.*;\nimport java.io.*;\nimport java.lang.Math.*;\n\npublic class MainA {\n\n\tpublic static int mod = 20000;\n\tpublic static long[] val;\n\tpublic static long[] arr;\n\tstatic long max = (long) 1e10 + 7;\n\tstatic long count=0;\n\t\n\tpublic static void main(String[] args) {\n\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tlong n=in.nextLong();\n\t\tint k=in.nextInt();\n\t\t//out.println(s);\n\t\tString s=Long.toString(n);\n\t\tint ans=s.length()-1count=0,rem=0,flag=0;\n\t\t\n\t\tif(s.length()<=k){}\n\t\telse\n\t\t{\n\t\tfor(int i=s.length()-1;i>=0;i--)\n\t\t{\n\t\t\tif(s.charAt(i)=='0')\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\trem++;\n\t\t\t}\n\t\t\tif(count==k)\n\t\t\t\t{\n\t\t\t\tflag=1;\n\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t\t}\n\t\t}\n\t\t}\n\t\t\n\t\tif(flag==1)\n\t\tout.println(rem);\n\t\telse\n\t\t\tout.println(ans);\n\t\tout.close();\n\t}\n\n\t\n\n\tstatic class Pairs implements Comparable {\n\t\tint x;\n\t\tint y;\n\n\t\tPairs(int a, int b) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pairs o) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\tif (x == o.x)\n\t\t\t\treturn Integer.compare(y, o.y);\n\t\t\telse\n\t\t\t\treturn Integer.compare(x, o.x);\n\t\t}\n\n\t}\n\n\tpublic static void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tpublic static boolean isPal(String s) {\n\t\tfor (int i = 0, j = s.length() - 1; i <= j; i++, j--) {\n\t\t\tif (s.charAt(i) != s.charAt(j))\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static String rev(String s) {\n\t\tStringBuilder sb = new StringBuilder(s);\n\t\tsb.reverse();\n\t\treturn sb.toString();\n\t}\n\n\tpublic static long gcd(long x, long y) {\n\t\tif (y == 0)\n\t\t\treturn x;\n\t\tif (x % y == 0)\n\t\t\treturn y;\n\t\telse\n\t\t\treturn gcd(y, x % y);\n\t}\n\n\tpublic static int gcd(int x, int y) {\n\t\tif (x % y == 0)\n\t\t\treturn y;\n\t\telse\n\t\t\treturn gcd(y, x % y);\n\t}\n\n\tpublic static long gcdExtended(long a, long b, long[] x) {\n\n\t\tif (a == 0) {\n\t\t\tx[0] = 0;\n\t\t\tx[1] = 1;\n\t\t\treturn b;\n\t\t}\n\t\tlong[] y = new long[2];\n\t\tlong gcd = gcdExtended(b % a, a, y);\n\n\t\tx[0] = y[1] - (b / a) * y[0];\n\t\tx[1] = y[0];\n\n\t\treturn gcd;\n\t}\n\n\tpublic static int abs(int a, int b) {\n\t\treturn (int) Math.abs(a - b);\n\t}\n\n\tpublic static long abs(long a, long b) {\n\t\treturn (long) Math.abs(a - b);\n\t}\n\n\tpublic static int max(int a, int b) {\n\t\tif (a > b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t}\n\n\tpublic static int min(int a, int b) {\n\t\tif (a > b)\n\t\t\treturn b;\n\t\telse\n\t\t\treturn a;\n\t}\n\n\tpublic static long max(long a, long b) {\n\t\tif (a > b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t}\n\n\tpublic static long min(long a, long b) {\n\t\tif (a > b)\n\t\t\treturn b;\n\t\telse\n\t\t\treturn a;\n\t}\n\n\tpublic static long[][] mul(long a[][], long b[][]) {\n\t\tlong c[][] = new long[2][2];\n\t\tc[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0];\n\t\tc[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1];\n\t\tc[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0];\n\t\tc[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1];\n\n\t\treturn c;\n\t}\n\n\tpublic static long[][] pow(long n[][], long p, long m) {\n\t\tlong result[][] = new long[2][2];\n\t\tresult[0][0] = 1;\n\t\tresult[0][1] = 0;\n\t\tresult[1][0] = 0;\n\t\tresult[1][1] = 1;\n\n\t\tif (p == 0)\n\t\t\treturn result;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\twhile (p != 0) {\n\t\t\tif (p % 2 == 1)\n\t\t\t\tresult = mul(result, n);\n\t\t\t//System.out.println(result[0][0]);\n\t\t\tfor (int i = 0; i < 2; i++) {\n\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\tif (result[i][j] >= m)\n\t\t\t\t\t\tresult[i][j] %= m;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tp >>= 1;\n\t\t\tn = mul(n, n);\n\t\t\t// System.out.println(1+\" \"+n[0][0]+\" \"+n[0][1]+\" \"+n[1][0]+\" \"+n[1][1]);\n\t\t\tfor (int i = 0; i < 2; i++) {\n\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\tif (n[i][j] >= m)\n\t\t\t\t\t\tn[i][j] %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long pow(long n, long p) {\n\t\tlong result = 1;\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\twhile (p != 0) {\n\t\t\tif (p % 2 == 1)\n\t\t\t\tresult *= n;\n\t\t\tp >>= 1;\n\t\t\tn *= n;\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic class InputReader {\n\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\t\tprivate SpaceCharFilter filter;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong a[] = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "070801112e749165a836defbfd5586f5", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class codeforces {\npublic static void main (String[]args) {\n\tScanner d=new Scanner (System.in);\n\tScanner b=new Scanner (System.in);\n\tint []s= new int [2]; \n\tfor(int i=0;i<2;i++) {\n\t\ts[i]=a.nextInt();\n\t}\n\tint x=(int) Math.pow(10,s[1]);\n\tint y=s[0];\n\tint r=0;\n\tint f=s[1];\n\tif(y0) {\n\t\t\tif(y%10==0&y>=10) { \n\t\t\t\tr++;\n\t\t\t\ty/=10;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tSystem.out.println(r);\n\t\t\tbreak;\n\t\t\t}\n\t\t\t}\n\t}\n\telse {\n\t\twhile (f>0) {\n\t\t\tif(y%10==0) {\n\t\t\t\tf--;\n\t\t\t\ty/=10;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ty/=10;\n\t\t\t\t\tr++;\n\t\t\t\t}\n\t\t}\n\tSystem.out.println(r);\n\t}\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1cbd1c5f79c54bed37f7f6fbea18bd5d", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class HW504 {\n\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n Integer n = sc.nextInt(); \n int m = sc.nextInt(); \n String s = n.toString();\n char[] c = new char[n];\n c = s.toCharArray();\n int count =0;\n int out = 0;\n if (s.length()=0;i-- ){\n if(c[i]=='0'){\n count++;\n }else{\n out++;\n } \n if (count==m){ \n break;\n }\n }\n System.out.println(out);\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2f68472b0314beb99d8bd3e925c9defb", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class HW504 {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n Integer n = sc.nextInt(); \n int m = sc.nextInt(); \n char[] c = new char[n];\n c = n.toString().toCharArray();\n int count =0;\n int out = 0;\n if (c.length=0;i-- ){\n if(c[i]=='0'){\n count++;\n }else{\n out++;\n } \n if (count==m){ \n break;\n }\n }\n System.out.println(out);\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1760977c4e1df5ad0558f314c9dee586", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n \r\npublic class Contest1646E\r\n{\r\n static class InputReader {\r\n BufferedReader reader;\r\n StringTokenizer tokenizer;\r\n public InputReader(InputStream stream) {\r\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\r\n tokenizer = null;\r\n }\r\n String next() { // reads in the next string\r\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\r\n try {\r\n tokenizer = new StringTokenizer(reader.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 public int nextInt() { // reads in the next int\r\n return Integer.parseInt(next());\r\n }\r\n public long nextLong() { // reads in the next long\r\n return Long.parseLong(next());\r\n }\r\n public double nextDouble() { // reads in the next double\r\n return Double.parseDouble(next());\r\n }\r\n }\r\n static InputReader r = new InputReader(System.in);\r\n static PrintWriter pw = new PrintWriter(System.out);\r\n static long mod = 1000000007;\r\n public static void main(String[] args)\r\n {\r\n \tint n = r.nextInt();\r\n \tint m = r.nextInt();\r\n \tint[] count = new int[n+5];\r\n \tboolean[] seen = new boolean[n+5];\r\n \tfor (int i = 2; i <= n; i ++)\r\n \t{\r\n \t\tlong j = i;\r\n \t\tif (!seen[(int)j])\r\n \t\t{\r\n \t\t\twhile (j <= n)\r\n \t\t\t{\r\n \t\t\t\tseen[(int)j] = true;\r\n \t\t\t\tj *= i;\r\n \t\t\t\tcount[i] ++;\r\n \t\t\t}\r\n \t\t}\r\n \t}\r\n \tlong ans = 1;\r\n \tlong[] hi = new long[22];\r\n \thi[0] = 0;\r\n \tHashSet set = new HashSet();\r\n \tfor (int i = 1; i <= 20; i ++)\r\n \t{\r\n \t\tfor (int j = i; j <= m*i; j += i)\r\n \t\t{\r\n \t\t\tset.add(j);\r\n \t\t}\r\n \t\thi[i] = set.size();\r\n \t}\r\n \tfor (int x = 2; x <= n; x ++)\r\n \t{\r\n \t\tans += hi[count[x]];\r\n \t}\r\n \tpw.println(ans);\r\n pw.close();\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2b415385c6a1fbb62ccda78f98775030", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.lang.reflect.Array;\r\nimport java.math.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n private final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\r\n private final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\r\n private StringTokenizer st;\r\n private final Long MOD = 1000000007L;\r\n private final String endl = \"\\n\";\r\n\r\n\r\n boolean isConsonant(char c) {\r\n return !isVowel(c);\r\n }\r\n\r\n boolean isVowel(char c) {\r\n return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';\r\n }\r\n\r\n // IO UTILS\r\n\r\n void log(Object... args) {\r\n if (!TESTING) return;\r\n for (Object s : args) System.out.print(s.toString() + \" \");\r\n System.out.println();\r\n }\r\n\r\n String line() throws IOException {\r\n return in.readLine().trim();\r\n }\r\n\r\n StringTokenizer tokens() throws IOException {\r\n return new StringTokenizer(line());\r\n }\r\n\r\n long l(String s) {\r\n return Long.parseLong(s);\r\n }\r\n\r\n long rl() throws IOException {\r\n return l(line());\r\n }\r\n\r\n long[] rla(int n) throws IOException {\r\n long[] arr = new long[n];\r\n st = tokens();\r\n for (int i = 0; i < n; i++)\r\n arr[i] = l(st.nextToken());\r\n return arr;\r\n }\r\n\r\n int i(String s) {\r\n return Integer.parseInt(s);\r\n }\r\n\r\n int ri() throws IOException {\r\n return i(line());\r\n }\r\n\r\n int[] ria(int n) throws IOException {\r\n int[] arr = new int[n];\r\n st = tokens();\r\n for (int i = 0; i < n; i++)\r\n arr[i] = i(st.nextToken());\r\n return arr;\r\n }\r\n\r\n String rs() throws IOException {\r\n return line();\r\n }\r\n\r\n String[] rsa(int n) throws IOException {\r\n String[] s = new String[n];\r\n st = tokens();\r\n for (int i = 0; i < n; i++)\r\n s[i] = st.nextToken();\r\n return s;\r\n }\r\n\r\n double d(String s) {\r\n return Double.parseDouble(s);\r\n }\r\n\r\n double rd() throws IOException {\r\n return d(line());\r\n }\r\n\r\n double[] rda(int n) throws IOException {\r\n double[] arr = new double[n];\r\n st = tokens();\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = d(st.nextToken());\r\n }\r\n return arr;\r\n }\r\n // IO UTILS END\r\n\r\n // MATH UTILS\r\n\r\n long gcd(long a, long b) {\r\n return b == 0 ? a : gcd(b, a % b);\r\n }\r\n\r\n long lcm(long a, long b) {\r\n long g = gcd(a, b);\r\n return (a / g) * b; // directly multiply a and b can overflow\r\n }\r\n\r\n public long modInv(long a, long MOD) {\r\n return new BigInteger(a + \"\").modPow(new BigInteger((MOD - 2) + \"\"), new BigInteger(MOD + \"\")).longValue();\r\n }\r\n\r\n public long modPro(long a, long b, long MOD) {\r\n return ((a % MOD) * (b % MOD)) % MOD;\r\n }\r\n\r\n private long factorialMod(int n, long MOD) {\r\n long pro = 1;\r\n for (long i = 1; i <= n; i++) {\r\n pro = pro * i;\r\n pro %= MOD;\r\n }\r\n return pro;\r\n }\r\n\r\n static void ruffleSort(int[] a) {\r\n // ruffle\r\n int n = a.length;\r\n Random r = new Random();\r\n for (int i = 0; i < a.length; i++) {\r\n int oi = r.nextInt(n), temp = a[i];\r\n a[i] = a[oi];\r\n a[oi] = temp;\r\n }\r\n Arrays.sort(a);\r\n }\r\n\r\n static void ruffleSort(long[] a) {\r\n // ruffle\r\n int n = a.length;\r\n Random r = new Random();\r\n for (int i = 0; i < a.length; i++) {\r\n int oi = r.nextInt(n);\r\n long temp = a[i];\r\n a[i] = a[oi];\r\n a[oi] = temp;\r\n }\r\n Arrays.sort(a);\r\n }\r\n\r\n boolean[] sieveOfEratosthenes(int 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 prime[0] = false;\r\n prime[1] = false;\r\n for (int i = 4; i <= n; i += 2) {\r\n prime[i] = false;\r\n }\r\n for (int p = 3; p * p <= n; p += 2) {\r\n // If prime[p] is not changed, then it is a prime\r\n if (prime[p]) {\r\n // Update all multiples of p\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\r\n // MATH UTILS END\r\n private final boolean TESTING = false;\r\n\r\n public static void main(String[] args) throws Exception {\r\n new Main().solve();\r\n }\r\n\r\n private void solve() throws Exception {\r\n int testCases = 1;\r\n// testCases = Integer.parseInt(in.readLine().trim());\r\n preProcess();\r\n for (int i = 1; i <= testCases; i++) {\r\n solveTestCase(i);\r\n }\r\n out.flush();\r\n out.close();\r\n }\r\n\r\n void preProcess() {\r\n\r\n }\r\n\r\n\r\n private void solveTestCase(int testCaseNumber) throws Exception {\r\n int[] arr = ria(2);\r\n int n = arr[0];\r\n int m = arr[1];\r\n int log = 0;\r\n int two = 2;\r\n while (true) {\r\n if (two > n)\r\n break;\r\n two *= 2;\r\n log++;\r\n }\r\n\r\n//999439867182\r\n boolean set[] = new boolean[log * n + 1];\r\n long hash[] = new long[log + 1];\r\n int count = 0;\r\n for (int i = 1; i <= log; i++) {\r\n for (int j = 1; j <= m; j++) {\r\n if (!set[i*j]) {\r\n set[i*j] = true;\r\n count += 1;\r\n }\r\n }\r\n hash[i] = count;\r\n }\r\n// System.out.println(set + endl + Arrays.toString(hash));\r\n\r\n long ans = 0;\r\n boolean[] done = new boolean[n + 1];\r\n for (int i = 2; i <= n; i++) {\r\n if (!done[i]) {\r\n\r\n long pow = 1;\r\n done[i] = true;\r\n long temp = i;\r\n while (true) {\r\n temp *= i;\r\n if (temp > n)\r\n break;\r\n done[(int) temp] = true;\r\n pow++;\r\n\r\n }\r\n//\t\t\t\t\t\t\t\tSystem.out.println( i+ \" \" + pow+ \" \" + hash[(int)pow]);\r\n ans += hash[(int) pow];\r\n\r\n\r\n }\r\n }\r\n\r\n out.write(ans + 1 + endl);\r\n\r\n\r\n }\r\n\r\n\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0eb18241789d7c17481bc7dcdd3ba9ff", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "//Utilities\r\nimport java.io.*;\r\nimport java.util.*;\r\n\r\npublic class a {\r\n\tstatic int t;\r\n\tstatic int n, m;\r\n\tstatic int log2n;\r\n\tstatic int[] precompute;\r\n\tstatic boolean[] vis, isBasePow;\r\n\tstatic long res;\r\n\r\n\tpublic static void main(String[] args) throws IOException {\r\n\t\tt = 1;\r\n\t\twhile (t-- > 0) {\r\n\t\t\tn = in.iscan(); m = in.iscan();\r\n\t\t\tlog2n = 0;\r\n\t\t\twhile ((1 << (log2n + 1)) <= n) {\r\n\t\t\t\tlog2n++;\r\n\t\t\t}\r\n\t\t\tvis = new boolean[m*log2n+1];\r\n\t\t\tprecompute = new int[log2n+1];\r\n\t\t\tint cnt = 0;\r\n\t\t\tfor (int i = 1; i <= log2n; i++) {\r\n\t\t\t\tfor (int j = 1; j <= m; j++) {\r\n\t\t\t\t\tif (!vis[i*j]) {\r\n\t\t\t\t\t\tvis[i*j] = true;\r\n\t\t\t\t\t\tcnt++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tprecompute[i] = cnt;\r\n\t\t\t}\r\n\t\t\tres = 1;\r\n\t\t\tisBasePow = new boolean[n+1]; Arrays.fill(isBasePow, true);\r\n\t\t\tfor (int i = 2; i <= n; i++) {\r\n\t\t\t\tif (isBasePow[i]) {\r\n\t\t\t\t\tint p = 1;\r\n\t\t\t\t\tfor (long j = i * i; j <= n; j *= i, p++) {\r\n\t\t\t\t\t\tisBasePow[(int)j] = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tres += precompute[p];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tout.println(res);\r\n\t\t}\r\n\t\tout.close();\r\n\t}\r\n\r\n\tstatic INPUT in = new INPUT(System.in);\r\n\tstatic PrintWriter out = new PrintWriter(System.out);\r\n\tprivate static class INPUT {\r\n\r\n\t\tprivate InputStream stream;\r\n\t\tprivate byte[] buf = new byte[1024];\r\n\t\tprivate int curChar, numChars;\r\n\r\n\t\tpublic INPUT (InputStream stream) {\r\n\t\t\tthis.stream = stream;\r\n\t\t}\r\n\r\n\t\tpublic INPUT (String file) throws IOException {\r\n\t\t\tthis.stream = new FileInputStream (file);\r\n\t\t}\r\n\r\n\t\tpublic int cscan () 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}\r\n\t\t\t\r\n\t\t\tif (numChars == -1)\r\n\t\t\t\treturn numChars;\r\n\r\n\t\t\treturn buf[curChar++];\r\n\t\t}\r\n\r\n\t\tpublic int iscan () throws IOException {\r\n\t\t\tint c = cscan (), sgn = 1;\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tint res = 0;\r\n\r\n\t\t\tdo {\r\n\t\t\t\tres = (res << 1) + (res << 3);\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\t\t\twhile (!space (c));\r\n\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic String sscan () throws IOException {\r\n\t\t\tint c = cscan ();\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tStringBuilder res = new StringBuilder ();\r\n\r\n\t\t\tdo {\r\n\t\t\t\tres.appendCodePoint (c);\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\t\t\twhile (!space (c));\r\n\r\n\t\t\treturn res.toString ();\r\n\t\t}\r\n\r\n\t\tpublic double dscan () throws IOException {\r\n\t\t\tint c = cscan (), sgn = 1;\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tdouble res = 0;\r\n\r\n\t\t\twhile (!space (c) && c != '.') {\r\n\t\t\t\tif (c == 'e' || c == 'E')\r\n\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\r\n\t\t\t\t\r\n\t\t\t\tres *= 10;\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tif (c == '.') {\r\n\t\t\t\tc = cscan ();\r\n\t\t\t\tdouble m = 1;\r\n\r\n\t\t\t\twhile (!space (c)) {\r\n\t\t\t\t\tif (c == 'e' || c == 'E')\r\n\t\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\r\n\r\n\t\t\t\t\tm /= 10;\r\n\t\t\t\t\tres += (c - '0') * m;\r\n\t\t\t\t\tc = cscan ();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic long lscan () throws IOException {\r\n\t\t\tint c = cscan (), sgn = 1;\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tlong res = 0;\r\n\r\n\t\t\tdo {\r\n\t\t\t\tres = (res << 1) + (res << 3);\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\t\t\twhile (!space (c));\r\n\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic boolean space (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\tpublic static class UTILITIES {\r\n\r\n\t\tstatic final double EPS = 10e-6;\r\n\t\t\r\n\t\tpublic static void sort(int[] a, boolean increasing) {\r\n\t\t\tArrayList arr = new ArrayList();\r\n\t\t\tint n = a.length;\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr.add(a[i]);\r\n\t\t\t}\r\n\t\t\tCollections.sort(arr);\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tif (increasing) {\r\n\t\t\t\t\ta[i] = arr.get(i);\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\ta[i] = arr.get(n-1-i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void sort(long[] a, boolean increasing) {\r\n\t\t\tArrayList arr = new ArrayList();\r\n\t\t\tint n = a.length;\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr.add(a[i]);\r\n\t\t\t}\r\n\t\t\tCollections.sort(arr);\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tif (increasing) {\r\n\t\t\t\t\ta[i] = arr.get(i);\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\ta[i] = arr.get(n-1-i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void sort(double[] a, boolean increasing) {\r\n\t\t\tArrayList arr = new ArrayList();\r\n\t\t\tint n = a.length;\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr.add(a[i]);\r\n\t\t\t}\r\n\t\t\tCollections.sort(arr);\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tif (increasing) {\r\n\t\t\t\t\ta[i] = arr.get(i);\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\ta[i] = arr.get(n-1-i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic static int lower_bound (int[] arr, int x) {\r\n\t\t\tint low = 0, high = arr.length, mid = -1;\r\n\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\r\n\t\t\t\tif (arr[mid] >= x)\r\n\t\t\t\t\thigh = mid;\r\n\t\t\t\telse\r\n\t\t\t\t\tlow = mid + 1;\r\n\t\t\t}\r\n\r\n\t\t\treturn low;\r\n\t\t}\r\n\r\n\t\tpublic static int upper_bound (int[] arr, int x) {\r\n\t\t\tint low = 0, high = arr.length, mid = -1;\r\n\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\r\n\t\t\t\tif (arr[mid] > x)\r\n\t\t\t\t\thigh = mid;\r\n\t\t\t\telse\r\n\t\t\t\t\tlow = mid + 1;\r\n\t\t\t}\r\n\r\n\t\t\treturn low;\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void updateMap(HashMap map, int key, int v) {\r\n\t\t\tif (!map.containsKey(key)) {\r\n\t\t\t\tmap.put(key, v);\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tmap.put(key, map.get(key) + v);\r\n\t\t\t}\r\n\t\t\tif (map.get(key) == 0) {\r\n\t\t\t\tmap.remove(key);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic static long gcd (long a, long b) {\r\n\t\t\treturn b == 0 ? a : gcd (b, a % b);\r\n\t\t}\r\n\r\n\t\tpublic static long lcm (long a, long b) {\r\n\t\t\treturn a * b / gcd (a, b);\r\n\t\t}\r\n\r\n\t\tpublic static long fast_pow_mod (long b, long x, int mod) {\r\n\t\t\tif (x == 0) return 1;\r\n\t\t\tif (x == 1) return b;\r\n\t\t\tif (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;\r\n\r\n\t\t\treturn b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;\r\n\t\t}\r\n\r\n\t\tpublic static long fast_pow (long b, long x) {\r\n\t\t\tif (x == 0) return 1;\r\n\t\t\tif (x == 1) return b;\r\n\t\t\tif (x % 2 == 0) return fast_pow (b * b, x / 2);\r\n\r\n\t\t\treturn b * fast_pow (b * b, x / 2);\r\n\t\t}\r\n\r\n\t\tpublic static long choose (long n, long k) {\r\n\t\t\tk = Math.min (k, n - k);\r\n\t\t\tlong val = 1;\r\n\r\n\t\t\tfor (int i = 0; i < k; ++i)\r\n\t\t\t\tval = val * (n - i) / (i + 1);\r\n\r\n\t\t\treturn val;\r\n\t\t}\r\n\r\n\t\tpublic static long permute (int n, int k) {\r\n\t\t\tif (n < k) return 0;\r\n\t\t\tlong val = 1;\r\n\r\n\t\t\tfor (int i = 0; i < k; ++i)\r\n\t\t\t\tval = (val * (n - i));\r\n\r\n\t\t\treturn val;\r\n\t\t}\r\n\t\t\r\n\t\t// start of permutation and lower/upper bound template\r\n\t\tpublic static void nextPermutation(int[] nums) {\r\n\t\t //find first decreasing digit\r\n\t\t int mark = -1;\r\n\t\t for (int i = nums.length - 1; i > 0; i--) {\r\n\t\t if (nums[i] > nums[i - 1]) {\r\n\t\t mark = i - 1;\r\n\t\t break;\r\n\t\t }\r\n\t\t }\r\n\t\t \r\n\t\t if (mark == -1) {\r\n\t\t reverse(nums, 0, nums.length - 1);\r\n\t\t return;\r\n\t\t }\r\n\t\t \r\n\t\t int idx = nums.length-1;\r\n\t\t for (int i = nums.length-1; i >= mark+1; i--) {\r\n\t\t if (nums[i] > nums[mark]) {\r\n\t\t idx = i;\r\n\t\t break;\r\n\t\t }\r\n\t\t }\r\n\t\t \r\n\t\t swap(nums, mark, idx);\r\n\t\t \r\n\t\t reverse(nums, mark + 1, nums.length - 1);\r\n\t\t}\r\n\t\t \r\n\t\tpublic static void swap(int[] nums, int i, int j) {\r\n\t\t int t = nums[i];\r\n\t\t nums[i] = nums[j];\r\n\t\t nums[j] = t;\r\n\t\t}\r\n\t\t \r\n\t\tpublic static void reverse(int[] nums, int i, int j) {\r\n\t\t while (i < j) {\r\n\t\t swap(nums, i, j);\r\n\t\t i++;\r\n\t\t j--;\r\n\t\t }\r\n\t\t}\r\n\t\t\r\n\t\tstatic int lower_bound (int[] arr, int hi, int cmp) {\r\n\t\t\tint low = 0, high = hi, mid = -1;\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\t\t\t\tif (arr[mid] >= cmp) high = mid;\r\n\t\t\t\telse low = mid + 1;\r\n\t\t\t}\r\n\t\t\treturn low;\r\n\t\t}\r\n\t \r\n\t\tstatic int upper_bound (int[] arr, int hi, int cmp) {\r\n\t\t\tint low = 0, high = hi, mid = -1;\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\t\t\t\tif (arr[mid] > cmp) high = mid;\r\n\t\t\t\telse low = mid + 1;\r\n\t\t\t}\r\n\t\t\treturn low;\r\n\t\t}\r\n\t\t// end of permutation and lower/upper bound template\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a92e6ea14c83cc652afd74714a57aa39", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "/*\r\nI am dead inside\r\nDo you like NCT, sKz, BTS?\r\n5 4 3 2 1 Moonwalk\r\nImma knock it down like domino\r\nIs this what you want? Is this what you want?\r\nLet's ttalkbocky about that\r\n */\r\nimport static java.lang.Math.*;\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class x1646E\r\n{\r\n public static void main(String hi[]) 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 int M = Integer.parseInt(st.nextToken());\r\n //preprocess\r\n boolean[] seen = new boolean[20*(1<<20)];\r\n int[] dp = new int[20];\r\n dp[0] = M;\r\n for(int v=1; v <= M; v++)\r\n seen[v] = true;\r\n for(int i=1; i < 20; i++)\r\n {\r\n dp[i] = dp[i-1];\r\n for(int v=1; v <= M; v++)\r\n if(!seen[(i+1)*v])\r\n {\r\n seen[(i+1)*v] = true;\r\n dp[i]++;\r\n }\r\n }\r\n long res = 1L;\r\n boolean[] bad = new boolean[N+1];\r\n for(int v=2; v <= N; v++)\r\n if(!bad[v])\r\n {\r\n int curr = 0;\r\n int temp = v;\r\n while(temp*v <= N)\r\n {\r\n curr++;\r\n temp *= v;\r\n bad[temp] = true;\r\n }\r\n res += dp[curr];\r\n }\r\n System.out.println(res);\r\n }\r\n public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception\r\n {\r\n int[] arr = new int[N];\r\n st = new StringTokenizer(infile.readLine());\r\n for(int i=0; i < N; i++)\r\n arr[i] = Integer.parseInt(st.nextToken());\r\n return arr;\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c1193663b9b7080bb19a652a2773e92d", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class C_Hello_2018 {\n\n public static long MOD = 1000000007; \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 n = in.nextInt();\n long l = in.nextInt();\n long[]data = new long[31];\n long total = 0;\n for(int i = 0; i < 31; i++){\n if(i < n){\n data[i] = in.nextInt();\n }else{\n data[i] = Long.MAX_VALUE;\n }\n if(i > 0){\n data[i] = Long.min(data[i], 2L*data[i - 1]);\n }\n if(((1L< L){\n total = Long.min(total, data[i]);\n }\n }\n \n out.println(total);\n out.close();\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "79feb15171e2ac117dcb3a04cde29d51", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n Reader.init(System.in);\n solve();\n }\n\n private static void solve() throws IOException {\n int n = Reader.nextInt();\n int l = Reader.nextInt();\n long[][] prices = new long[n][2]; // 0: price, 1: liters\n for (int i = 0; i < n; i++) {\n prices[i][0] = Reader.nextLong();\n prices[i][1] = 1 << i;\n }\n\n Arrays.sort(prices, C_PartyLemonade::compare);\n System.out.println(go(l, prices));\n }\n\n private static long go(long liter, long[][] prices) {\n if (liter <= 0) return 0;\n long[] lastprice = prices[0];\n int i = 0;\n long cost = Long.MAX_VALUE;\n while (i < prices.length) {\n if (lastprice[1] < liter && compare(prices[i], lastprice) == 1) break;\n\n if (prices[i][1] < liter) {\n long num = liter / prices[i][1];\n long remain = liter % prices[i][1];\n cost = Math.min(cost, prices[i][0] * num + go(remain, prices));\n } else {\n cost = Math.min(cost, prices[i][0] + go(liter - prices[i][1], prices));\n }\n lastprice = prices[i];\n i++;\n }\n return cost;\n }\n\n private static int compare(long[] i1, long[] i2) {\n long p1 = i1[0] * i2[1];\n long p2 = i2[0] * i1[1];\n if (p1 > p2) return 1;\n if (p1 < p2) return -1;\n if (i1[1] > i2[1]) return -1;\n if (i1[1] < i2[1]) return 1;\n return 0;\n }\n\n private static class Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n /**\n * call this method to initialize reader for InputStream\n */\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input));\n tokenizer = new StringTokenizer(\"\");\n }\n\n /**\n * get next word\n */\n static String next() throws IOException {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "58d95e65dd2dc641ef9b152ec8e09973", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "// package codeforces1;\n\nimport java.util.*;\nimport java.util.function.Function;\nimport java.util.stream.Collectors;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\n\npublic class Chello2018 {\n\n\tstatic InputReader in = new InputReader(System.in);\n\tstatic OutputWriter out = new OutputWriter(System.out);\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint t = i();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\twhile (t > 0) {\n\t\t\tint n = i();\n\t\t\tint l =i();\n\t\t\tint arr[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = i();\n\t\t\t}\n\t\t\tint pw[]=new int[31];\n\t\t\tint p=1;\n\t\t\tfor(int i=0;i<31;i++) {\n\t\t\t\tpw[i]=p;\n\t\t\t\tp=p*2;\n\t\t\t}\n\t\t\tpair1 pa[]=new pair1[n];\n\t\t\tfor(int i=0;i() {\n\t\t\t\tpublic int compare(pair1 p1, pair1 p2) {\n\t\t\t\t\treturn p1.y - p2.y;\n\t\t\t\t}\n\t\t\t});\n\t\t\tlong fans=100000000000000000L;\n\t\t\tlong ans=0L;\n\t\t\tlong tm=0L;\n//\t\t\tSystem.out.println(pa[3].x);\n//\t\t\tfor(int i=0;i 0) {\n\t\t\tif (b % 2 != 0) {\n\t\t\t\tresult = (result * a) % m;\n\t\t\t\tb--;\n\t\t\t}\n\t\t\ta = (a * a) % m;\n\t\t\tb /= 2;\n\t\t}\n\t\treturn result % m;\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (a == 0) {\n\t\t\treturn b;\n\t\t}\n\t\treturn gcd(b % a, a);\n\t}\n\n\tpublic static long lcm(long a, long b) {\n\t\treturn a * (b / gcd(a, b));\n\t}\n\n\tpublic static long l() {\n\t\tString s = in.String();\n\t\treturn Long.parseLong(s);\n\t}\n\n\tpublic static void pln(String value) {\n\t\tSystem.out.println(value);\n\t}\n\n\tpublic static int i() {\n\t\treturn in.Int();\n\t}\n\n\tpublic static String s() {\n\t\treturn in.String();\n\t}\n\n}\n\nclass pair1 {\n\tint x, y,z;\n\n\tpair1(int x, int y,int z) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.z = z;\n\t}\n}\n\nclass CompareValue {\n\n\tstatic void compare(pair arr[], int n) {\n\t\tArrays.sort(arr, new Comparator() {\n\t\t\tpublic int compare(pair p1, pair p2) {\n\t\t\t\treturn p1.y - p2.y;\n\t\t\t}\n\t\t});\n\t}\n}\n\nclass CompareKey {\n\tstatic void compare(pair arr[], int n) {\n\t\tArrays.sort(arr, new Comparator() {\n\t\t\tpublic int compare(pair p1, pair p2) {\n\t\t\t\treturn p2.x - p1.x;\n\t\t\t}\n\t\t});\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 Int() {\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 String String() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic String next() {\n\t\treturn String();\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n\n\tpublic double readDouble() {\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\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, Int());\n\t\t\t}\n\t\t\tif (c < '0' || c > '9') {\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}\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, Int());\n\t\t\t\t}\n\t\t\t\tif (c < '0' || c > '9') {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\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\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\t}\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t\twriter.flush();\n\t}\n\n\tpublic void printLine(Object... objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t\twriter.flush();\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\nclass IOUtils {\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.Int();\n\t\treturn array;\n\t}\n}\n\n/**\n * TO SORT VIA TWO KEYS , HERE IT IS ACCORDING TO ASCENDING ORDER OF FIRST AND\n * DESC ORDER OF SECOND\n * LIST name-list \n * ARRAYLIST\n * COPY PASTE\n * \n * Collections.sort(list, (first,second) ->{\n\t\t \tif(first.con >second.con)\n\t\t \t\treturn -1;\n\t\t \telse if(first.consecond.index)\n\t\t \t\t\treturn 1;\n\t\t \t\telse\n\t\t \t\t\treturn -1;\n\t\t \t}\n\t\t \t\n\t\t });\n * \n */\n\n/**\n * \n \n\n DECIMAL FORMATTER\nDouble k = in.readDouble();\n\nSystem.out.println(k);\nDecimalFormat df = new DecimalFormat(\"#.##\");\nSystem.out.print(df.format(k));\nout.printLine(k);\n* \n* */\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "af7d64aabc6d53e91e154d18ca640e05", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author fuqianran\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();\n int L = in.nextInt();\n\n int[] litters = new int[N + 1];\n int[] costs = new int[N + 1];\n\n for (int i = 1; i <= N; ++i) {\n costs[i] = in.nextInt();\n }\n\n for (int i = 1; i <= N; ++i) {\n litters[i] = 1 << (i - 1);\n }\n\n int[] dp = new int[L + 1];\n Arrays.fill(dp, Integer.MAX_VALUE);\n dp[0] = 0;\n\n for (int l = 1; l <= L; ++l) {\n\n for (int type = 1; type <= N; ++type) {\n if (l - litters[type] >= 0) {\n dp[l] = Math.min(dp[l], dp[l - litters[type]] + costs[type]);\n } else {\n dp[l] = Math.min(dp[l], costs[type]);\n }\n }\n }\n\n out.println(dp[L]);\n\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "da39a49c66761d51a5751e90160ebc0c", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class Probram3 {\n\n\tpublic static int get(long n) {\n\t\tint sum = 0;\n\t\twhile(n != 0) {\n\t\t\tsum += n % 10;\n\t\t\tn = n / 10;\n\t\t}\n\t\treturn sum;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\t//while(true){\n\t\t\tlong n = scanner.nextLong();\n\t\t\tlong s = scanner.nextLong();\n//\t\t\tlong l = 1;\n//\t\t\tlong r = Long.MAX_VALUE;\n//\t\t\tlong index = 0;\n//\t\t\twhile(l <= r) {\n//\t\t\t\tlong mid = (l + r) / 2;\n//\t\t\t\tif(s > mid) {\n//\t\t\t\t\tl = mid + 1;\n//\t\t\t\t}else if(s < mid) {\n//\t\t\t\t\tr = mid - 1;\n//\t\t\t\t}else{\n//\t\t\t\t\tindex = mid;\n//\t\t\t\t\tbreak;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\tSystem.out.println(index);\n\t\t\tlong x = s / 9 ;\n\t\t\tlong y = s % 9 ;\n\t\t\tlong k;\n\t\t\tif(y == 0) {\n\t\t\t\tk = 9 + (x - 1) * 10;\n\t\t\t}else{\n\t\t\t\tk = 9 + x * 10;\n\t\t\t}\n\t\t\t//System.out.println(k);\n\t\t\tif((n - k) > 0) {\n\t\t\t\tSystem.out.println(n - k);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(\"0\");\n\t\t\t}\n\t\t//}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b7741a798877627d6c8effde7c47ae39", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": " import java.io.*;\n import java.util.*;\n import java.text.*;\n import java.math.*;\n import java.util.regex.*;\n\npublic class Solution {\n\n \n public static int fun(long n)\n {\n int ans = 0;\n while(n>0)\n {\n ans += n%10;\n n /= 10;\n }\n return ans;\n }\n \n public static long mod = 1000000007;\n public static void main(String[] args) throws IOException{\n\n\n\n// BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n Scanner in = new Scanner(System.in);\n\n \n \n // for(int i=0; i<1000; i+=10)\n \n long n = in.nextLong();\n long x = in.nextLong();\n \n long ll = 0;\n long rl = (long)Math.pow(10, 18);\n long mid = 0;\n long ans = 0;\n long k = (long)Math.ceil((double)x/9);\n while(rl-ll>=0)\n {\n mid = (rl + ll)/2;\n \n // pw.println((mid)+\" \"+k);\n \n if(mid==k)\n {\n // pw.print(\"--\");\n ans = mid;\n break;\n }\n else if(mid>k)\n {\n \n // ans = mid;\n rl = mid-1;\n }\n else\n {\n ll = mid+1;\n }\n // pw.println((mid)+\" \"+k);\n \n }\n //pw.print(ans);\n pw.print(Math.max(n - ()10*ans+1, 0));\n \n \n pw.flush();\n pw.close();\n\n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fc52ecce2523360dfcd8a19fe641c37e", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Ivan{\n\n public static boolean check(long s,long n){\n long big = 0;\n long u = s;\n while (s >= 1){\n big =big + s % 10;\n s = (s - big) / 10;\n }\n if (u - big > n){\n return true;\n }else return false;\n }\n\n public static long analyze(long n){\n return n/9;\n }\n public static long number(long x){\n return x*9;\n }\n\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n long s = scan.nextLong();\n long n = scan.nextLong();\n long r =0;\n for (long i = n;i= 1){\n big =big + s % 10;\n s = (s - big) / 10;\n }\n if (u - big > n){\n return true;\n }else return false;\n }\n\n public static long analyze(long n){\n return n/9;\n }\n public static long number(long x){\n return x*9;\n }\n\n public static void main(String args[]){\n try{\n File file = new File(\"in.inp\");\n Scanner scan = new Scanner(System.in);\n long s = scan.nextLong();\n long n = scan.nextLong();\n long r =0;\n for (long i = n;i q = new LinkedList<>();\n q.add(0);\n while(!q.isEmpty()){\n int cur = q.remove();\n int len = lengths[cur];\n for(int p : ver[cur].path){\n if(!visited[p]){\n visited[p] = true;\n lengths[p] = len+1;\n q.add(p);\n }\n }\n }\n\n //StringBuilder sb = new StringBuilder();\n //sb.append(lengths[0]);\n for(int i = 0; i path;\n Vertex(){\n path = new ArrayList<>();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c3c43f588fc36dd44f5fe0d5c28edf3b", "src_uid": "602deaad5c66e264997249457d555129", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class Codeforces {\n\n\tstatic MyScanner sc = new MyScanner();\n\t\n\tpublic static void computePaths(Vertex source) {\n\t\t\n\t\tsource.minDistance = 0;\n\t\tPriorityQueue vertexQueue = new PriorityQueue();\n\t\tvertexQueue.add(source);\n\t\t\n\t\twhile (!vertexQueue.isEmpty()) {\n\t\t\t\n\t\t\tVertex u = vertexQueue.poll();\n\t\t\t\n\t\t\tfor (Edge e: u.adjacencies) {\n\t\t\t\t\n\t\t\t\tVertex tr = e.target;\n\t\t\t\tdouble weight = e.weight;\n\t\t\t\t\n\t\t\t\tdouble DistanceThroughU = u.minDistance + weight;\n\t\t\t\t\n\t\t\t\tif (DistanceThroughU < tr.minDistance) {\n\t\t\t\t\tvertexQueue.remove(tr);\n\t\t\t\t\ttr.minDistance = DistanceThroughU;\n\t\t\t\t\ttr.previous = u;\n\t\t\t\t\tvertexQueue.add(tr);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t}\n\t\n\tpublic static List getShortestPathTo (Vertex target) {\n\t\t\n\t\tList path = new ArrayList();\n\n\t\tfor (Vertex v= target ; v != null ; v = v.previous) {\n\t\t\tpath.add(v);\n\t\t}\n\t\t\n\t\tCollections.reverse(path);\n\t\t\n\t\treturn path;\n\t} \n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tint n = sc.nextInt();\n\t\tVertex [] arr = new Vertex [n];\n\t\t//List list = new ArrayList();\n\t\t\n\t\tint target;\n\t\t\n\t\tfor (int i=0 ; i {\n\n\t//public final String name;\n\tpublic Edge [] adjacencies;\n\tpublic double minDistance = Double.POSITIVE_INFINITY;\n\tpublic Vertex previous;\n\t\n\t\n\tpublic int compareTo(Vertex other) {\n\t\treturn Double.compare(minDistance, other.minDistance);\n\t}\n\t\n}\n\nclass Edge {\n\t\n\tpublic Vertex target;\n\tpublic double weight;\n\t\n\tpublic Edge (Vertex argTarget, double argWeight) {\n\t\ttarget = argTarget;\n\t\tweight = argWeight;\n\t}\n\t\n\tpublic String toString() {\n\t\treturn \"\" + target + \" \" + weight;\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e63da70fe3a2390545d030583ad2d7f", "src_uid": "602deaad5c66e264997249457d555129", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.util.PriorityQueue;\nimport java.util.Set;\nimport java.util.Comparator;\nimport java.io.OutputStream;\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 * @author Mahmoud Aladdin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\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 jin, PrintWriter jout) {\n int ways = jin.int32();\n\n int cnt = 0;\n long n = 0;\n\n PriorityQueue que = new PriorityQueue<>(ways, new Comparator() {\n @Override\n public int compare(Pair p1, Pair p2) {\n long t1 = p1.x * (long) Math.pow(p1.k, 3);\n long t2 = p2.x * (long) Math.pow(p2.k, 3);\n if(t1 == t2) {\n return 0;\n } else {\n return (int)((t1 - t2) / Math.abs(t1 - t2));\n }\n }\n });\n\n Set seen = new HashSet<>();\n que.add(new Pair(1, 2));\n while(cnt <= ways) {\n Pair cp = que.poll();\n long tn = cp.x * (long) Math.pow(cp.k, 3);\n if(seen.contains(cp.toStr()))\n continue;\n if(cnt == ways) {\n if(tn == n) {\n jout.println(-1);\n } else {\n jout.println(n);\n }\n break;\n } else {\n n = tn;\n\n cnt++;\n que.add(new Pair(cp.x + 1, cp.k));\n que.add(new Pair(cp.x, cp.k + 1));\n }\n seen.add(cp.toStr());\n }\n }\n}\n\nclass Pair {\n public long x;\n public long k;\n\n public String toStr() {\n return x + \" \" + k;\n }\n\n public Pair(long a, long b) {\n x = a;\n k = b;\n }\n}\n\nclass InputReader {\n private static final int bufferMaxLength = 1024;\n private InputStream in;\n private byte[] buffer;\n private int currentBufferSize;\n private int currentBufferTop;\n private static final String tokenizers = \" \\t\\r\\f\\n\";\n\n public InputReader(InputStream stream) {\n this.in = stream;\n buffer = new byte[bufferMaxLength];\n currentBufferSize = 0;\n currentBufferTop = 0;\n }\n\n private boolean refill() {\n try {\n this.currentBufferSize = this.in.read(this.buffer);\n this.currentBufferTop = 0;\n } catch(Exception e) {}\n return this.currentBufferSize > 0;\n }\n\n public String line() {\n StringBuffer tok = new StringBuffer();\n Byte first;\n while((first = readChar()) != null) {\n tok.append((char)first.byteValue());\n if((char)first.byteValue() == '\\n')\n break;\n }\n return tok.toString();\n }\n\n public Byte readChar() {\n if(currentBufferTop < currentBufferSize) {\n return this.buffer[this.currentBufferTop++];\n } else {\n if(!this.refill()) {\n return null;\n } else {\n return readChar();\n }\n }\n }\n\n public String token() {\n StringBuffer tok = new StringBuffer();\n Byte first;\n while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));\n if(first == null) return null;\n tok.append((char)first.byteValue());\n while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {\n tok.append((char)first.byteValue());\n }\n return tok.toString();\n }\n\n\n public String next() {\n return token();\n }\n\n public Integer int32() throws NumberFormatException {\n String tok = token();\n return tok == null? null : Integer.parseInt(tok);\n }\n\n public Long int64() throws NumberFormatException {\n String tok = token();\n return tok == null? null : Long.parseLong(tok);\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "614dba468d2e0939120fb40c25c0a77c", "src_uid": "602deaad5c66e264997249457d555129", "difficulty": 1700.0} {"lang": "Java 8", "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\npublic class Global14 {\r\n\tstatic PrintWriter out;\r\n\tstatic Scanner sc;\r\n\tstatic ArrayListq,w,x;\r\n\tstatic ArrayListadj[];\r\n\tstatic HashSetprimesH;\r\n\tstatic boolean prime[];\r\n\t//static ArrayLista;\r\n\tstatic HashSettmp;\r\n\tstatic int[][][]dist;\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\t//C();\r\n\t\t//D();\r\n\t\tE();\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(),w=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=0;i--) {\r\n\t\t\t\t\tif(cur==w) {\r\n\t\t\t\t\t\tint tmp=a[i+1];\r\n\t\t\t\t\t\ta[i+1]=a[i];\r\n\t\t\t\t\t\ta[i]=tmp;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcur+=a[i];\r\n\t\t\t\t}\r\n\t\t\t\tol(\"YES\");\r\n\t\t\t\tdisp2(a);\r\n\t\t\t\t\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\tlong n=nl();\r\n\t\t\t\tif(n%2==0) {\r\n\t\t\t\tn/=2;\r\n\t\t\t\tint sq=(int)Math.sqrt(n);\r\n\t\t\t\tif(sq*sq==n&&sq!=0) {\r\n\t\t\t\t\tol(\"YES\");continue;\r\n\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(n%2==0) {\r\n\t\t\t\tn/=2;\r\n\t\t\t\t int sq=(int)Math.sqrt(n);\r\n\t\t\t\tif(sq*sq==n&&sq!=0) {\r\n\t\t\t\t\tol(\"YES\");continue;\r\n\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tol(\"NO\");\r\n\t\t\t}\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=ni();\r\n\t\t\t while(t-->0) {\r\n\t\t\t\tint n=ni(),m=ni(),x=ni();\r\n\t\t\t\tint[][]a=new int[n][2];\r\n\t\t\t\tint mx=0;\r\n\t\t\t\tfor(int i=0;iu[0]-v[0]);\r\n\t\t\t\tPriorityQueuevals=new PriorityQueue((u,v)->u[0]-v[0]);\r\n\t\t\t\tint[]ans=new int[n];\r\n\t\t\t\t//int grp=1;\r\n\t\t\t\tvals.add(new int[] {a[0][0],1});\r\n\t\t\t\tans[a[0][1]]=1;\r\n\t\t\t\tfor(int i=1;ix)ol(\"NO\");\r\n\t\t\t\telse {\r\n\t\t\t\t\t\r\n\t\t\t\t\tol(\"YES\");\r\n\t\t\t\t\tfor(int i=0;isum/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*i0) {\r\n\t\t\t\tint n=ni(),l=ni(),r=ni();\r\n\t\t\t\tint[]occ1=new int[n+1];\r\n\t\t\t\ta=nai(n);\r\n\t\t\t\tfor(int i=0;ir?occ1:occ2;\r\n\t\t\t\tint[]sml=l<=r?occ1:occ2;\r\n\t\t\t\tfor(int i=0;i<=n&&tksml[i]) {\r\n\t\t\t\t\t\tif(c1<0) {\r\n\t\t\t\t\t\t\tint diff=Math.min(-c1, -sml[i]+lrg[i]);\r\n\t\t\t\t\t\t\tlrg[i]-=diff;\r\n\t\t\t\t\t\t\tc1+=diff;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tint nd=lrg[i]-sml[i];\r\n\t\t\t\t\t\tc2-=nd;\r\n\t\t\t\t\t\tbase+=nd;\r\n\t\t\t\t\t\tsml[i]=lrg[i];\r\n\t\t\t\t\t}else if(lrg[i]q=new LinkedList();\r\n\t\t\tint mn=Integer.MAX_VALUE;\r\n\t\t\tq.add(new int[] {i,j,0,0});\r\n\t\t\tint[]dx=new int[] {-1,1,0,0};\r\n\t\t\tint[]dy=new int[] {0,0,1,-1};\r\n\t\t\twhile(!q.isEmpty()) {\r\n\t\t\t\tint []x=q.poll();\r\n\t\t\t\tvis[x[0]][x[1]]=true;\r\n\t\t\t\tint c=x[2];\r\n\t\t\t\tif(c>k/2)continue;\r\n\t\t\t\tif(c>0&&k%c==0&&(k/c)%2==0) {\r\n\t\t\t\t\tmn=Math.min(mn,x[3]*k/c );\r\n\t\t\t\t}\r\n\t\t\t\tfor(int a=0;a<4;a++) {\r\n\t\t\t\t\tint nx=x[0]+dx[a];\r\n\t\t\t\t\tint ny=x[1]+dy[a];\r\n\t\t\t\t\tif(valid(nx,ny)&&!vis[nx][ny]) {\r\n\t\t\t\t\t\tq.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]});\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t\treturn mn;\r\n\t\t}\r\n\t\tprivate static boolean valid(int nx, int ny) {\r\n\t\t\treturn nx>=0&&nx=0&&ny0) {\r\n\t\t\tint n=ni();\r\n\t\t\tlong oo=nl();\r\n\t\t\tlong fc[]=new long[n+1];\r\n\t\t\tfc[0]=fc[1]=1l;\r\n\t\t\tlong []pow2=new long[n+1];\r\n\t\t\tpow2[0]=1l;\r\n\t\t\tfor(int i=1;i0) {\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<>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>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=0;i--) {\r\n\t\t\tout.print(a[i]+\" \");\r\n\t\t}\r\n\t\tout.println();\r\n\t}\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\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a056751ae017855582a1a8784503520", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\n\r\npublic class Compute {\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 long fact[] = new long[n+1];\r\n long ifact[] = new long[n+1];\r\n long dp[][] = new long[n+1][n+1];\r\n fact[1] = 1;\r\n ifact[1] = 1;\r\n dp[1][1] = 1;\r\n \r\n for(int i = 2; i <= n; i++) {\r\n fact[i] = (i*fact[i-1]) % M;\r\n ifact[i] = (ifact[M % i]*(M - M/i)) % M;\r\n dp[i][i] = (dp[i-1][i-1] * 2) % M;\r\n }\r\n \r\n for(int i = 3; i <= n; i++) {\r\n for(int j = i/2 + 1; j <= i-1; j++) {\r\n for(int k = 2; k <= i-1 && ((j - k + 1) > (i - k)/2); k++) {\r\n dp[i][j] += ((((dp[k-1][k-1]*dp[i-k][j-k+1] % M)*fact[j] % M)*ifact[k-1] % M)*ifact[j-k+1] % M); \r\n }\r\n } \r\n }\r\n \r\n long sum = 0;\r\n for(int i = n/2 + 1; i <= n; i++) {\r\n \r\n sum = (sum + dp[n][i]) % M;\r\n }\r\n \r\n System.out.println(sum % M);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a775690a6bc36c30c591eee87e37e54d", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0} {"lang": "Java 8", "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\npublic class Global14 {\r\n\tstatic PrintWriter out;\r\n\tstatic Scanner sc;\r\n\tstatic ArrayListq,w,x;\r\n\tstatic ArrayListadj[];\r\n\tstatic HashSetprimesH;\r\n\tstatic boolean prime[];\r\n\t//static ArrayLista;\r\n\tstatic HashSettmp;\r\n\tstatic int[][][]dist;\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\t//C();\r\n\t\t//D();\r\n\t\tE();\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(),w=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=0;i--) {\r\n\t\t\t\t\tif(cur==w) {\r\n\t\t\t\t\t\tint tmp=a[i+1];\r\n\t\t\t\t\t\ta[i+1]=a[i];\r\n\t\t\t\t\t\ta[i]=tmp;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcur+=a[i];\r\n\t\t\t\t}\r\n\t\t\t\tol(\"YES\");\r\n\t\t\t\tdisp2(a);\r\n\t\t\t\t\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\tlong n=nl();\r\n\t\t\t\tif(n%2==0) {\r\n\t\t\t\tn/=2;\r\n\t\t\t\tint sq=(int)Math.sqrt(n);\r\n\t\t\t\tif(sq*sq==n&&sq!=0) {\r\n\t\t\t\t\tol(\"YES\");continue;\r\n\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(n%2==0) {\r\n\t\t\t\tn/=2;\r\n\t\t\t\t int sq=(int)Math.sqrt(n);\r\n\t\t\t\tif(sq*sq==n&&sq!=0) {\r\n\t\t\t\t\tol(\"YES\");continue;\r\n\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tol(\"NO\");\r\n\t\t\t}\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=ni();\r\n\t\t\t while(t-->0) {\r\n\t\t\t\tint n=ni(),m=ni(),x=ni();\r\n\t\t\t\tint[][]a=new int[n][2];\r\n\t\t\t\tint mx=0;\r\n\t\t\t\tfor(int i=0;iu[0]-v[0]);\r\n\t\t\t\tPriorityQueuevals=new PriorityQueue((u,v)->u[0]-v[0]);\r\n\t\t\t\tint[]ans=new int[n];\r\n\t\t\t\t//int grp=1;\r\n\t\t\t\tvals.add(new int[] {a[0][0],1});\r\n\t\t\t\tans[a[0][1]]=1;\r\n\t\t\t\tfor(int i=1;ix)ol(\"NO\");\r\n\t\t\t\telse {\r\n\t\t\t\t\t\r\n\t\t\t\t\tol(\"YES\");\r\n\t\t\t\t\tfor(int i=0;isum/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*i0) {\r\n\t\t\t\tint n=ni(),l=ni(),r=ni();\r\n\t\t\t\tint[]occ1=new int[n+1];\r\n\t\t\t\ta=nai(n);\r\n\t\t\t\tfor(int i=0;ir?occ1:occ2;\r\n\t\t\t\tint[]sml=l<=r?occ1:occ2;\r\n\t\t\t\tfor(int i=0;i<=n&&tksml[i]) {\r\n\t\t\t\t\t\tif(c1<0) {\r\n\t\t\t\t\t\t\tint diff=Math.min(-c1, -sml[i]+lrg[i]);\r\n\t\t\t\t\t\t\tlrg[i]-=diff;\r\n\t\t\t\t\t\t\tc1+=diff;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tint nd=lrg[i]-sml[i];\r\n\t\t\t\t\t\tc2-=nd;\r\n\t\t\t\t\t\tbase+=nd;\r\n\t\t\t\t\t\tsml[i]=lrg[i];\r\n\t\t\t\t\t}else if(lrg[i]q=new LinkedList();\r\n\t\t\tint mn=Integer.MAX_VALUE;\r\n\t\t\tq.add(new int[] {i,j,0,0});\r\n\t\t\tint[]dx=new int[] {-1,1,0,0};\r\n\t\t\tint[]dy=new int[] {0,0,1,-1};\r\n\t\t\twhile(!q.isEmpty()) {\r\n\t\t\t\tint []x=q.poll();\r\n\t\t\t\tvis[x[0]][x[1]]=true;\r\n\t\t\t\tint c=x[2];\r\n\t\t\t\tif(c>k/2)continue;\r\n\t\t\t\tif(c>0&&k%c==0&&(k/c)%2==0) {\r\n\t\t\t\t\tmn=Math.min(mn,x[3]*k/c );\r\n\t\t\t\t}\r\n\t\t\t\tfor(int a=0;a<4;a++) {\r\n\t\t\t\t\tint nx=x[0]+dx[a];\r\n\t\t\t\t\tint ny=x[1]+dy[a];\r\n\t\t\t\t\tif(valid(nx,ny)&&!vis[nx][ny]) {\r\n\t\t\t\t\t\tq.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]});\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t\treturn mn;\r\n\t\t}\r\n\t\tprivate static boolean valid(int nx, int ny) {\r\n\t\t\treturn nx>=0&&nx=0&&ny0) {\r\n\t\t\tint n=ni();\r\n\t\t\tlong oo=nl();\r\n\t\t\tlong fc[]=new long[n+1];\r\n\t\t\tfc[0]=fc[1]=1l;\r\n\t\t\tlong []pow2=new long[n+1];\r\n\t\t\tpow2[0]=1l;\r\n\t\t\tfor(int i=1;i0) {\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<>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>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=0;i--) {\r\n\t\t\tout.print(a[i]+\" \");\r\n\t\t}\r\n\t\tout.println();\r\n\t}\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\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7b2428be7f4f92a73f6c895c5b121589", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.math.*;\r\nimport java.security.*;\r\nimport java.text.*;\r\nimport java.util.*;\r\nimport java.util.concurrent.*;\r\nimport java.util.function.*;\r\nimport java.util.regex.*;\r\nimport java.util.stream.*;\r\nimport static java.util.stream.Collectors.joining;\r\nimport static java.util.stream.Collectors.toList;\r\n\r\n\r\npublic class Main{\r\n\r\n static long MOD = 1_000_000_007L;\r\n //static long MOD = 998_244_353L;\r\n //static long MOD = 1_000_000_033L;\r\n static long inv2 = (MOD + 1) / 2;\r\n\r\n static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\r\n static long lMax = 0x3f3f3f3f3f3f3f3fL;\r\n static int iMax = 0x3f3f3f3f;\r\n static HashMap memo = new HashMap();\r\n static MyScanner sc = new MyScanner();\r\n //static ArrayList primes;\r\n\r\n static int nn = 300000;\r\n static long[] pow2;\r\n static long [] fac;\r\n static long [] pow;\r\n static long [] inv;\r\n static long [] facInv;\r\n static int[] base;\r\n static int[] numOfDiffDiv;\r\n static int[] numOfDiv;\r\n static ArrayList primes;\r\n //static int[] primes;\r\n static int ptr = 0;\r\n static boolean[] isPrime;\r\n\r\n //-----------PrintWriter for faster output---------------------------------\r\n public static PrintWriter out;\r\n public static void main(String[] args) {\r\n out = new PrintWriter(new BufferedOutputStream(System.out));\r\n // Start writing your solution here. -------------------------------------\r\n\r\n\r\n\r\n /*fac = new long[nn + 1];\r\n fac[1] = 1;\r\n for(int i = 2; i <= nn; i++)\r\n fac[i] = fac[i - 1] * i % MOD;*/\r\n\r\n\r\n /*pow2 = new long[nn + 1];\r\n pow2[0] = 1L;\r\n for(int i = 1; i <= nn; i++)\r\n pow2[i] = pow2[i - 1] * 2L;*/\r\n\r\n\r\n /*inv = new long[nn + 1];\r\n inv[1] = 1;\r\n for (int i = 2; i <= nn; ++i)\r\n inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/\r\n\r\n /*facInv = new long[nn + 1];\r\n facInv[0] = facInv[1] = 1;\r\n for (int i = 2; i <= nn; ++i)\r\n facInv[i] = facInv[i - 1] * inv[i] % MOD;*/\r\n\r\n\r\n /*numOfDiffDiv = new int[nn + 1];\r\n for(int i = 2; i <= nn; i++)\r\n if(numOfDiffDiv[i] == 0)\r\n for(int j = i; j <= nn; j += i)\r\n numOfDiv[j] ++;*/\r\n\r\n /*numOfDiv = new int[nn + 1];\r\n numOfDiv[1] = 1;\r\n for(int i = 2; i <= nn; i++) {\r\n for(int j = 2; j * j <= i; j++) {\r\n if(i % j == 0) {\r\n numOfDiv[i] = numOfDiv[i / j] + 1;\r\n break;\r\n }\r\n }\r\n }*/\r\n\r\n //primes = sieveOfEratosthenes(100001);\r\n\r\n /*\r\n int t = 1;\r\n //t = sc.ni();\r\n while(t-- > 0) {\r\n //boolean res = solve();\r\n //out.println(res ? \"YES\" : \"NO\");\r\n long res = solve();\r\n out.println(res);\r\n }*/\r\n\r\n\r\n int t = 1, tt = 0;\r\n t = sc.ni();\r\n for(int i = 1; i <40000; i++) squares.add(i * i);\r\n while(tt++ < t) {\r\n boolean res = solve();\r\n //out.println(\"Case #\" + tt + \": \" + res);\r\n //out.println(res ? \"YES\" : \"NO\");\r\n }\r\n out.close();\r\n }\r\n static HashSet squares = new HashSet();\r\n\r\n static boolean solve() {\r\n /*String s = sc.nextLine();\r\n char[] c = s.toCharArray();\r\n int n = c.length;*/\r\n //int n = sc.ni();\r\n //long[] a = new long[n];\r\n //for(int i = 0; i < n; i++) a[i] = sc.nl();\r\n long res = 0;\r\n int n = sc.ni();\r\n long m = sc.nl();\r\n long[][][] dp = new long[2][n + 3][n + 3];\r\n long[][][] dp2 = new long[2][n + 3][n + 3];\r\n dp[0][2][1] = dp[1][2][2] = dp2[0][1][1] = 1L;\r\n for(int i = 3; i <= n; i++) {\r\n long[][] bef = dp[0];\r\n long[][] aft = dp[1];\r\n long[][] nbef = new long[n + 3][n + 3];\r\n long[][] naft = new long[n + 3][n + 3];\r\n for(int len = 1; len <= i; len++) {\r\n for(int ind = 1; ind <= len; ind++) {\r\n nbef[len + 1][1] += bef[len][ind];\r\n nbef[len + 1][ind + 1] -= bef[len][ind];\r\n naft[len + 1][ind + 1] += bef[len][ind];\r\n //naft[len + 1][len + 2] -= bef[len][ind];\r\n naft[len + 1][ind + 1] += aft[len][ind];\r\n //naft[len + 1][len + 2] -= aft[len][ind];\r\n nbef[len + 1][1] += dp2[0][len][ind] + dp2[1][len][ind];\r\n //nbef[len + 1][len + 2] -= dp2[0][len][ind] + dp2[1][len][ind];\r\n }\r\n }\r\n for(int len = 1; len <= i; len++) {\r\n for(int ind = 1; ind <= len; ind ++) {\r\n nbef[len][ind] = (nbef[len][ind] + nbef[len][ind - 1] + 100L * m) % m;\r\n naft[len][ind] = (naft[len][ind] + naft[len][ind - 1] + 100L * m) % m;\r\n }\r\n }\r\n dp2 = dp;\r\n dp = new long[][][]{nbef, naft};\r\n }\r\n for(long[] row: dp[0])\r\n for(long i : row)\r\n res += i;\r\n for(long[] row: dp[1])\r\n for(long i : row)\r\n res += i;\r\n out.println(res % m);\r\n return false;\r\n }\r\n\r\n // edges to adjacency list by uwi\r\n public static int[][] packU(int n, int[] from, int[] to) {\r\n return packU(n, from, to, from.length);\r\n }\r\n\r\n public static int[][] packU(int n, int[] from, int[] to, int sup) {\r\n int[][] g = new int[n][];\r\n int[] p = new int[n];\r\n for (int i = 0; i < sup; i++) p[from[i]]++;\r\n for (int i = 0; i < sup; i++) p[to[i]]++;\r\n for (int i = 0; i < n; i++) g[i] = new int[p[i]];\r\n for (int i = 0; i < sup; i++) {\r\n g[from[i]][--p[from[i]]] = to[i];\r\n g[to[i]][--p[to[i]]] = from[i];\r\n }\r\n return g;\r\n }\r\n\r\n // tree diameter by uwi\r\n public static int[] diameter(int[][] g) {\r\n int n = g.length;\r\n int f0 = -1, f1 = -1, d01 = -1;\r\n int[] q = new int[n];\r\n boolean[] ved = new boolean[n];\r\n {\r\n int qp = 0;\r\n q[qp++] = 0; ved[0] = true;\r\n for(int i = 0;i < qp;i++){\r\n int cur = q[i];\r\n for(int e : g[cur]){\r\n if(!ved[e]){\r\n ved[e] = true;\r\n q[qp++] = e;\r\n continue;\r\n }\r\n }\r\n }\r\n f0 = q[n-1];\r\n }\r\n {\r\n int[] d = new int[n];\r\n int qp = 0;\r\n Arrays.fill(ved, false);\r\n q[qp++] = f0; ved[f0] = true;\r\n for(int i = 0;i < qp;i++){\r\n int cur = q[i];\r\n for(int e : g[cur]){\r\n if(!ved[e]){\r\n ved[e] = true;\r\n q[qp++] = e;\r\n d[e] = d[cur] + 1;\r\n continue;\r\n }\r\n }\r\n }\r\n f1 = q[n-1];\r\n d01 = d[f1];\r\n }\r\n return new int[]{d01, f0, f1};\r\n }\r\n\r\n public static long c(int n, int k) {\r\n return (fac[n] * facInv[k] % MOD) * facInv[n - k] % MOD;\r\n }\r\n\r\n\r\n // SegmentTree range min/max query by uwi\r\n public static class SegmentTreeRMQ {\r\n public int M, H, N;\r\n public int[] st;\r\n\r\n public SegmentTreeRMQ(int n)\r\n {\r\n N = n;\r\n M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\r\n H = M>>>1;\r\n st = new int[M];\r\n Arrays.fill(st, 0, M, Integer.MAX_VALUE);\r\n }\r\n\r\n public SegmentTreeRMQ(int[] a)\r\n {\r\n N = a.length;\r\n M = Integer.highestOneBit(Math.max(N-1, 1))<<2;\r\n H = M>>>1;\r\n st = new int[M];\r\n for(int i = 0;i < N;i++){\r\n st[H+i] = a[i];\r\n }\r\n Arrays.fill(st, H+N, M, Integer.MAX_VALUE);\r\n for(int i = H-1;i >= 1;i--)propagate(i);\r\n }\r\n\r\n public void update(int pos, int x)\r\n {\r\n st[H+pos] = x;\r\n for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);\r\n }\r\n\r\n private void propagate(int i)\r\n {\r\n st[i] = Math.min(st[2*i], st[2*i+1]);\r\n }\r\n\r\n public int minx(int l, int r){\r\n int min = Integer.MAX_VALUE;\r\n if(l >= r)return min;\r\n while(l != 0){\r\n int f = l&-l;\r\n if(l+f > r)break;\r\n int v = st[(H+l)/f];\r\n if(v < min)min = v;\r\n l += f;\r\n }\r\n\r\n while(l < r){\r\n int f = r&-r;\r\n int v = st[(H+r)/f-1];\r\n if(v < min)min = v;\r\n r -= f;\r\n }\r\n return min;\r\n }\r\n\r\n public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}\r\n\r\n private int min(int l, int r, int cl, int cr, int cur)\r\n {\r\n if(l <= cl && cr <= r){\r\n return st[cur];\r\n }else{\r\n int mid = cl+cr>>>1;\r\n int ret = Integer.MAX_VALUE;\r\n if(cl < r && l < mid){\r\n ret = Math.min(ret, min(l, r, cl, mid, 2*cur));\r\n }\r\n if(mid < r && l < cr){\r\n ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));\r\n }\r\n return ret;\r\n }\r\n }\r\n }\r\n\r\n public static char[] rev(char[] a){char[] b = new char[a.length];for(int i = 0;i < a.length;i++)b[a.length-1-i] = a[i];return b;}\r\n\r\n public static double dist(double a, double b){\r\n return Math.sqrt(a * a + b * b);\r\n }\r\n\r\n public static long inv(long a){\r\n return quickPOW(a, MOD - 2);\r\n }\r\n\r\n public class Interval {\r\n int start;\r\n int end;\r\n public Interval(int start, int end) {\r\n this.start = start;\r\n this.end = end;\r\n }\r\n }\r\n\r\n public static ArrayList sieveOfEratosthenes(int n) {\r\n boolean prime[] = new boolean[n + 1];\r\n Arrays.fill(prime, true);\r\n for (int p = 2; p * p <= n; p++) {\r\n if (prime[p]) {\r\n for (int i = p * 2; i <= n; i += p) {\r\n prime[i] = false;\r\n }\r\n }\r\n }\r\n ArrayList primeNumbers = new ArrayList<>();\r\n for (int i = 2; i <= n; i++) {\r\n if (prime[i]) {\r\n primeNumbers.add(i);\r\n }\r\n }\r\n return primeNumbers;\r\n }\r\n\r\n\r\n public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\r\n public static int lowerBound(int[] a, int l, int r, int v)\r\n {\r\n if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\r\n int low = l-1, high = r;\r\n while(high-low > 1){\r\n int h = high+low>>>1;\r\n if(a[h] >= v){\r\n high = h;\r\n }else{\r\n low = h;\r\n }\r\n }\r\n return high;\r\n }\r\n public static int rlowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\r\n public static int rlowerBound(int[] a, int l, int r, int v)\r\n {\r\n if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\r\n int low = l-1, high = r;\r\n while(high-low > 1){\r\n int h = high+low>>>1;\r\n if(a[h] <= v){\r\n high = h;\r\n }else{\r\n low = h;\r\n }\r\n }\r\n return high;\r\n }\r\n public static long C(int n, int m)\r\n {\r\n if(m == 0 || m == n) return 1l;\r\n if(m > n || m < 0) return 0l;\r\n long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;\r\n\r\n return res;\r\n }\r\n public static long quickPOW(long n, long m)\r\n {\r\n long ans = 1l;\r\n while(m > 0)\r\n {\r\n if(m % 2 == 1)\r\n ans = (ans * n) % MOD;\r\n n = (n * n) % MOD;\r\n m >>= 1;\r\n }\r\n return ans;\r\n }\r\n public static long quickPOW(long n, long m, long mod)\r\n {\r\n long ans = 1l;\r\n while(m > 0)\r\n {\r\n if(m % 2 == 1)\r\n ans = (ans * n) % mod;\r\n n = (n * n) % mod;\r\n m >>= 1;\r\n }\r\n return ans;\r\n }\r\n\r\n public static int gcd(int a, int b)\r\n {\r\n if(a % b == 0) return b;\r\n return gcd(b, a % b);\r\n }\r\n public static long gcd(long a, long b)\r\n {\r\n if(a % b == 0) return b;\r\n return gcd(b, a % b);\r\n }\r\n\r\n static class Randomized {\r\n public static void shuffle(int[] data) {\r\n shuffle(data, 0, data.length - 1);\r\n }\r\n\r\n public static void shuffle(int[] data, int from, int to) {\r\n to--;\r\n for (int i = from; i <= to; i++) {\r\n int s = nextInt(i, to);\r\n int tmp = data[i];\r\n data[i] = data[s];\r\n data[s] = tmp;\r\n }\r\n }\r\n\r\n public static void shuffle(long[] data) {\r\n shuffle(data, 0, data.length - 1);\r\n }\r\n\r\n public static void shuffle(long[] data, int from, int to) {\r\n to--;\r\n for (int i = from; i <= to; i++) {\r\n int s = nextInt(i, to);\r\n long tmp = data[i];\r\n data[i] = data[s];\r\n data[s] = tmp;\r\n }\r\n }\r\n\r\n public static int nextInt(int l, int r) {\r\n return RandomWrapper.INSTANCE.nextInt(l, r);\r\n }\r\n }\r\n\r\n static class RandomWrapper {\r\n private Random random;\r\n public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());\r\n\r\n public RandomWrapper() {\r\n this(new Random());\r\n }\r\n\r\n public RandomWrapper(Random random) {\r\n this.random = random;\r\n }\r\n\r\n public int nextInt(int l, int r) {\r\n return random.nextInt(r - l + 1) + l;\r\n }\r\n\r\n }\r\n\r\n\r\n //-----------MyScanner class for faster input----------\r\n public 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 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 int ni() {\r\n return Integer.parseInt(next());\r\n }\r\n long nl() {\r\n return Long.parseLong(next());\r\n }\r\n double nd() {\r\n return Double.parseDouble(next());\r\n }\r\n String nextLine(){\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n }\r\n //--------------------------------------------------------\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7734c616ace34bce18ce54472226f359", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "/*\r\n Goal: Become better in CP!\r\n Key: Consistency and Discipline\r\n Desire: SDE @ Google USA\r\n Motto: Do what i Love <=> Love what i do\r\n If you don't use your brain 100%, it deteriorates gradually\r\n*/\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Solution {\r\n\r\n static StringBuffer str=new StringBuffer();\r\n static BufferedReader bf;\r\n static PrintWriter pw;\r\n static int n, x;\r\n static long mod=998244353l;\r\n static long dp[][];\r\n static long comb[][];\r\n\r\n static long mod_mul(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a * b) % mod) + mod) % mod;\r\n }\r\n\r\n static long mod_add(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a + b) % mod) + mod) % mod;\r\n }\r\n\r\n static long pow(long a, long b) {\r\n long res = 1;\r\n while (b > 0) {\r\n if (b % 2 == 1) res = (res * a)%mod;\r\n a = (a * a)%mod;\r\n b = b >> 1l;\r\n }\r\n return res;\r\n }\r\n\r\n // O(n*x*n) solution\r\n static long count(int i, int j){\r\n if(i==1) return 0;\r\n if(i==0) return 1;\r\n if(j>=x) return 0;\r\n if(dp[i][j]!=-1) return dp[i][j];\r\n\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), count(k, cost))));\r\n }\r\n return dp[i][j]=ans;\r\n }\r\n\r\n // DP + Combinatorics\r\n static void solve(int te) throws Exception{\r\n comb = new long[501][501];\r\n comb[0][0] = 1;\r\n for (int i = 1; i <= 500; i++) {\r\n comb[i][0] = 1;\r\n for (int j = 1; j <= i; j++) {\r\n comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;\r\n }\r\n }\r\n\r\n /* // Top down dp\r\n \r\n // dp[i][j] = # of ways to choose health = required answer \r\n // i -> i heros still alive => i=n is required \r\n // j -> already received j damage => j<=x is required\r\n\r\n // sum of dp[0][j] for each j in [0, x] is the answer\r\n dp=new long[n+1][x+1];\r\n for(int i=0;i<=n;i++){\r\n for(int j=0;j<=x;j++){\r\n dp[i][j]=-1;\r\n }\r\n }\r\n str.append(count(n, 0)).append(\"\\n\");\r\n */\r\n // bottom up dp\r\n dp=new long[n+1][x+1];\r\n\r\n for(int i=0;i<=x;i++){\r\n dp[1][i]=0;\r\n dp[0][i]=1;\r\n }\r\n\r\n long pow[][]=new long[n+1][x+1];\r\n for(int i=0;i<=n;i++) for(int j=0;j<=x;j++) pow[i][j]=pow(i, j);\r\n for(int i=2;i<=n;i++){\r\n for(int j=x-1;j>=0;j--){\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n long ins2=(((pow[cost-j][i-k]%mod) * (dp[k][cost]%mod))%mod + mod)%mod;\r\n long ins1=(((comb[i][i-k]%mod) * (ins2%mod))%mod + mod)%mod;\r\n ans=((ans%mod + ins1%mod)%mod + mod)%mod;\r\n }\r\n dp[i][j]=ans;\r\n }\r\n }\r\n str.append(dp[n][0]).append(\"\\n\");\r\n }\r\n \r\n public static void main(String[] args) throws java.lang.Exception {\r\n boolean lenv=false;\r\n int te=1;\r\n if(lenv){\r\n bf = new BufferedReader(\r\n new FileReader(\"input.txt\"));\r\n pw=new PrintWriter(new\r\n BufferedWriter(new FileWriter(\"output.txt\")));\r\n }else{\r\n bf = new BufferedReader(new InputStreamReader(System.in));\r\n pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n }\r\n \r\n // int q1 = Integer.parseInt(bf.readLine().trim());\r\n // for(te=1;te<=q1;te++) {\r\n String s[]=bf.readLine().trim().split(\"\\\\s+\");\r\n n=Integer.parseInt(s[0]);\r\n x=Integer.parseInt(s[1]);\r\n solve(te);\r\n // }\r\n pw.print(str);\r\n pw.flush();\r\n // System.out.println(str);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "75c26f0c042012d3cf92368bfaa8b378", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "/*\r\n Goal: Become better in CP!\r\n Key: Consistency and Discipline\r\n Desire: SDE @ Google USA\r\n Motto: Do what i Love <=> Love what i do\r\n If you don't use your brain 100%, it deteriorates gradually\r\n*/\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Solution {\r\n\r\n static StringBuffer str=new StringBuffer();\r\n static BufferedReader bf;\r\n static PrintWriter pw;\r\n static int n, x;\r\n static long mod=998244353l;\r\n static long dp[][];\r\n static long comb[][];\r\n\r\n static long mod_mul(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a * b) % mod) + mod) % mod;\r\n }\r\n\r\n static long mod_add(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a + b) % mod) + mod) % mod;\r\n }\r\n\r\n static long pow(long a, long b) {\r\n long res = 1;\r\n while (b > 0) {\r\n if (b % 2 == 1) res = (res * a)%mod;\r\n a = (a * a)%mod;\r\n b = b >> 1l;\r\n }\r\n return res;\r\n }\r\n\r\n // O(n*x*n) solution\r\n static long count(int i, int j){\r\n if(i==1) return 0;\r\n if(i==0) return 1;\r\n if(j>=x) return 0;\r\n if(dp[i][j]!=-1) return dp[i][j];\r\n\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), count(k, cost))));\r\n }\r\n return dp[i][j]=ans;\r\n }\r\n\r\n // DP + Combinatorics\r\n static void solve(int te) throws Exception{\r\n int mx=Math.max(n+1, x+1);\r\n mx+=10;\r\n comb = new long[mx][mx];\r\n comb[0][0] = 1;\r\n for (int i = 1; i <= mx; i++) {\r\n comb[i][0] = 1;\r\n for (int j = 1; j <= i; j++) {\r\n comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;\r\n }\r\n }\r\n\r\n /* // Top down dp\r\n \r\n // dp[i][j] = # of ways to choose health = required answer \r\n // i -> i heros still alive => i=n is required \r\n // j -> already received j damage => j<=x is required\r\n\r\n // sum of dp[0][j] for each j in [0, x] is the answer\r\n dp=new long[n+1][x+1];\r\n for(int i=0;i<=n;i++){\r\n for(int j=0;j<=x;j++){\r\n dp[i][j]=-1;\r\n }\r\n }\r\n str.append(count(n, 0)).append(\"\\n\");\r\n */\r\n // bottom up dp\r\n dp=new long[n+1][x+1];\r\n\r\n for(int i=0;i<=x;i++){\r\n dp[1][i]=0;\r\n dp[0][i]=1;\r\n }\r\n\r\n\r\n long pow[][]=new long[n+1][x+1];\r\n for(int i=0;i<=mx;i++) for(int j=0;j<=mx;j++) pow[i][j]=pow(i, j);\r\n for(int i=2;i<=n;i++){\r\n for(int j=x-1;j>=0;j--){\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n long ins2=(((pow[cost-j][i-k]%mod) * (dp[k][cost]%mod))%mod + mod)%mod;\r\n long ins1=(((comb[i][i-k]%mod) * (ins2%mod))%mod + mod)%mod;\r\n ans=((ans%mod + ins1%mod)%mod + mod)%mod;\r\n }\r\n dp[i][j]=ans;\r\n }\r\n }\r\n str.append(dp[n][0]).append(\"\\n\");\r\n }\r\n \r\n public static void main(String[] args) throws java.lang.Exception {\r\n boolean lenv=false;\r\n int te=1;\r\n if(lenv){\r\n bf = new BufferedReader(\r\n new FileReader(\"input.txt\"));\r\n pw=new PrintWriter(new\r\n BufferedWriter(new FileWriter(\"output.txt\")));\r\n }else{\r\n bf = new BufferedReader(new InputStreamReader(System.in));\r\n pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n }\r\n \r\n // int q1 = Integer.parseInt(bf.readLine().trim());\r\n // for(te=1;te<=q1;te++) {\r\n String s[]=bf.readLine().trim().split(\"\\\\s+\");\r\n n=Integer.parseInt(s[0]);\r\n x=Integer.parseInt(s[1]);\r\n solve(te);\r\n // }\r\n pw.print(str);\r\n pw.flush();\r\n // System.out.println(str);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e27bbfd36e89f992f2b9a48904b57dd2", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "/*\r\n Goal: Become better in CP!\r\n Key: Consistency and Discipline\r\n Desire: SDE @ Google USA\r\n Motto: Do what i Love <=> Love what i do\r\n If you don't use your brain 100%, it deteriorates gradually\r\n*/\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Solution {\r\n\r\n static StringBuffer str=new StringBuffer();\r\n static BufferedReader bf;\r\n static PrintWriter pw;\r\n static int n, x;\r\n static long mod=998244353l;\r\n static long dp[][];\r\n static long comb[][];\r\n\r\n static long mod_mul(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a * b) % mod) + mod) % mod;\r\n }\r\n\r\n static long mod_add(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a + b) % mod) + mod) % mod;\r\n }\r\n\r\n static long pow(long a, long b) {\r\n long res = 1;\r\n while (b > 0) {\r\n if (b % 2 == 1) res = (res * a)%mod;\r\n a = (a * a)%mod;\r\n b = b >> 1l;\r\n }\r\n return res;\r\n }\r\n\r\n // O(n*x*n) solution\r\n static long count(int i, int j){\r\n if(i==1) return 0;\r\n if(i==0) return 1;\r\n if(j>=x) return 0;\r\n if(dp[i][j]!=-1) return dp[i][j];\r\n\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), count(k, cost))));\r\n }\r\n return dp[i][j]=ans;\r\n }\r\n\r\n // DP + Combinatorics\r\n static void solve(int te) throws Exception{\r\n int mx=Math.max(n+1, x+1);\r\n comb = new long[mx][mx];\r\n comb[0][0] = 1;\r\n for (int i = 1; i <= mx; i++) {\r\n comb[i][0] = 1;\r\n for (int j = 1; j <= i; j++) {\r\n comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;\r\n }\r\n }\r\n\r\n /* // Top down dp\r\n \r\n // dp[i][j] = # of ways to choose health = required answer \r\n // i -> i heros still alive => i=n is required \r\n // j -> already received j damage => j<=x is required\r\n\r\n // sum of dp[0][j] for each j in [0, x] is the answer\r\n dp=new long[n+1][x+1];\r\n for(int i=0;i<=n;i++){\r\n for(int j=0;j<=x;j++){\r\n dp[i][j]=-1;\r\n }\r\n }\r\n str.append(count(n, 0)).append(\"\\n\");\r\n */\r\n // bottom up dp\r\n dp=new long[n+1][x+1];\r\n\r\n for(int i=0;i<=x;i++){\r\n dp[1][i]=0;\r\n dp[0][i]=1;\r\n }\r\n\r\n\r\n long pow[][]=new long[n+1][x+1];\r\n for(int i=0;i<=mx;i++) for(int j=0;j<=mx;j++) pow[i][j]=pow(i, j);\r\n for(int i=2;i<=n;i++){\r\n for(int j=x-1;j>=0;j--){\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n long ins2=(((pow[cost-j][i-k]%mod) * (dp[k][cost]%mod))%mod + mod)%mod;\r\n long ins1=(((comb[i][i-k]%mod) * (ins2%mod))%mod + mod)%mod;\r\n ans=((ans%mod + ins1%mod)%mod + mod)%mod;\r\n }\r\n dp[i][j]=ans;\r\n }\r\n }\r\n str.append(dp[n][0]).append(\"\\n\");\r\n }\r\n \r\n public static void main(String[] args) throws java.lang.Exception {\r\n boolean lenv=false;\r\n int te=1;\r\n if(lenv){\r\n bf = new BufferedReader(\r\n new FileReader(\"input.txt\"));\r\n pw=new PrintWriter(new\r\n BufferedWriter(new FileWriter(\"output.txt\")));\r\n }else{\r\n bf = new BufferedReader(new InputStreamReader(System.in));\r\n pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n }\r\n \r\n // int q1 = Integer.parseInt(bf.readLine().trim());\r\n // for(te=1;te<=q1;te++) {\r\n String s[]=bf.readLine().trim().split(\"\\\\s+\");\r\n n=Integer.parseInt(s[0]);\r\n x=Integer.parseInt(s[1]);\r\n solve(te);\r\n // }\r\n pw.print(str);\r\n pw.flush();\r\n // System.out.println(str);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "774cbb5197877a2463c4323893fb6f57", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "/*\r\n Goal: Become better in CP!\r\n Key: Consistency and Discipline\r\n Desire: SDE @ Google USA\r\n Motto: Do what i Love <=> Love what i do\r\n If you don't use your brain 100%, it deteriorates gradually\r\n*/\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Solution {\r\n\r\n static StringBuffer str=new StringBuffer();\r\n static BufferedReader bf;\r\n static PrintWriter pw;\r\n static int n, x;\r\n static long mod=998244353l;\r\n static long dp[][];\r\n static long comb[][];\r\n\r\n static long mod_mul(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a * b) % mod) + mod) % mod;\r\n }\r\n\r\n static long mod_add(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a + b) % mod) + mod) % mod;\r\n }\r\n\r\n static long pow(long a, long b) {\r\n long res = 1;\r\n while (b > 0) {\r\n if (b % 2 == 1) res = (res * a)%mod;\r\n a = (a * a)%mod;\r\n b = b >> 1l;\r\n }\r\n return res;\r\n }\r\n\r\n // O(n*x*n) solution\r\n static long count(int i, int j){\r\n if(i==1) return 0;\r\n if(i==0) return 1;\r\n if(j>=x) return 0;\r\n if(dp[i][j]!=-1) return dp[i][j];\r\n\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), count(k, cost))));\r\n }\r\n return dp[i][j]=ans;\r\n }\r\n\r\n // DP + Combinatorics\r\n static void solve(int te) throws Exception{\r\n int mx=501;\r\n comb = new long[mx][mx];\r\n comb[0][0] = 1;\r\n for (int i = 1; i <= mx; i++) {\r\n comb[i][0] = 1;\r\n for (int j = 1; j <= i; j++) {\r\n comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;\r\n }\r\n }\r\n\r\n /* // Top down dp\r\n \r\n // dp[i][j] = # of ways to choose health = required answer \r\n // i -> i heros still alive => i=n is required \r\n // j -> already received j damage => j<=x is required\r\n\r\n // sum of dp[0][j] for each j in [0, x] is the answer\r\n dp=new long[n+1][x+1];\r\n for(int i=0;i<=n;i++){\r\n for(int j=0;j<=x;j++){\r\n dp[i][j]=-1;\r\n }\r\n }\r\n str.append(count(n, 0)).append(\"\\n\");\r\n */\r\n // bottom up dp\r\n dp=new long[n+1][x+1];\r\n\r\n for(int i=0;i<=x;i++){\r\n dp[1][i]=0;\r\n dp[0][i]=1;\r\n }\r\n\r\n\r\n long pow[][]=new long[n+1][x+1];\r\n for(int i=0;i<=mx;i++) for(int j=0;j<=mx;j++) pow[i][j]=pow(i, j);\r\n for(int i=2;i<=n;i++){\r\n for(int j=x-1;j>=0;j--){\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n long ins2=(((pow[cost-j][i-k]%mod) * (dp[k][cost]%mod))%mod + mod)%mod;\r\n long ins1=(((comb[i][i-k]%mod) * (ins2%mod))%mod + mod)%mod;\r\n ans=((ans%mod + ins1%mod)%mod + mod)%mod;\r\n }\r\n dp[i][j]=ans;\r\n }\r\n }\r\n str.append(dp[n][0]).append(\"\\n\");\r\n }\r\n \r\n public static void main(String[] args) throws java.lang.Exception {\r\n boolean lenv=false;\r\n int te=1;\r\n if(lenv){\r\n bf = new BufferedReader(\r\n new FileReader(\"input.txt\"));\r\n pw=new PrintWriter(new\r\n BufferedWriter(new FileWriter(\"output.txt\")));\r\n }else{\r\n bf = new BufferedReader(new InputStreamReader(System.in));\r\n pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n }\r\n \r\n // int q1 = Integer.parseInt(bf.readLine().trim());\r\n // for(te=1;te<=q1;te++) {\r\n String s[]=bf.readLine().trim().split(\"\\\\s+\");\r\n n=Integer.parseInt(s[0]);\r\n x=Integer.parseInt(s[1]);\r\n solve(te);\r\n // }\r\n pw.print(str);\r\n pw.flush();\r\n // System.out.println(str);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a57de8ac4b17cebdd2bd0862ef3b2b66", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n // input\n int n = sc.nextInt();\n int m = sc.nextInt();\n long[][] matrix = new long[n+1][m+1];\n for(int x = 0; x <= n; ++x) {\n matrix[x][m] = 0;\n }\n for(int y = 0; y <= m; ++y) {\n matrix[n][y] = 0;\n }\n matrix[n-1][m-1] = 1;\n int k = sc.nextInt();\n for(int i = 0; i < k; ++i) {\n int x1 = sc.nextInt();\n int y1 = sc.nextInt();\n int x2 = sc.nextInt();\n int y2 = sc.nextInt();\n for(int x = x1; x <= x2; ++x) {\n for(int y = y1; y <= y2; ++y) {\n matrix[x-1][y-1] = -1;\n }\n }\n }\n \n // computation: dynamic programming in matrix\n // value of n, m is 1\n // if getTopRight is blocked, value is sum of getTop and getRight\n // else value is maximum of getTop and getRight\n for(int y = m - 1; y >= 0; --y) {\n for(int x = n - 1; x >= 0; --x) {\n if(matrix[x][y] == -1) {\n matrix[x][y] = 0;\n } else {\n if(x == n - 1 && y == m - 1) {\n matrix[x][y] = 1;\n } else if(matrix[x+1][y] == 0 || matrix[x][y+1] == 0) {\n matrix[x][y] = Math.max(matrix[x][y + 1], matrix[x + 1][y]); \n } else {\n matrix[x][y] = (matrix[x+1][y] - matrix[x+1][y+1]) + matrix[x][y+1];\n }\n }\n if(matrix[x][y] == 5050357768079792430) {\n for(int a = y+3; a >= y; a--) {\n for(int b = x; b < x+3; b++) {\n System.out.print(matrix[b][a] + \" \");\n }\n System.out.println();\n }\n }\n }\n }\n /*for(int y = m - 1; y >= 0; y--) {\n for(int x = 0; x < n; x++) {\n System.out.print(matrix[x][y] + \" \");\n }\n System.out.println();\n }*/\n \n System.out.println(matrix[0][0]);\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ef976c61a7bdc3b348b2b1fa4e1273c9", "src_uid": "294ee0db72d759792d797b6259a83406", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Slalom {\n\n\tpublic final static int modulo = 1000000007;\n\t\n\tpublic class SegmentTree {\n\t\tSegmentTree(int size) {\n\t\t\tint treeSize = biggerPowerOfTwo(size) * 2 - 1;\n\t\t\tupdated = new boolean[treeSize];\n\t\t\ttree = new int[treeSize];\n\t\t\tforwardAdd = new boolean[treeSize];\n\t\t\tthis.size = size;\n\t\t\tbuild(0, 0, size - 1);\n\t\t}\n\t\t\n\t\tpublic void reset(int l, int r) {\n\t\t\tresetRec(0, 0, size - 1, l, r);\n\t\t}\n\t\t\n\t\tpublic int get(int pos) {\n\t\t\treturn getRec(0, 0, size - 1, pos);\n\t\t}\n\t\t\n\t\tpublic void add(int l, int r, int value) {\n\t\t\tif(value > 0)\n\t\t\t\taddRec(0, 0, size - 1, l, r, value);\n\t\t}\n\t\t\n\t\tpublic void print(int[] array) {\n\t\t\tprintOrigRec(0, 0, size - 1, array);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\tString result = new String();\n\t\t\tint treeSize = biggerPowerOfTwo(size) * 2 - 1;\n\t\t\tfor(int i = 0; i < treeSize; ++i) {\n\t\t\t\tresult += tree[i] + \" \";\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tprivate void printOrigRec(int root, int start, int end, int[] array) {\n\t\t\tif(start == end) {\n\t\t\t\tarray[start] = tree[root];\n\t\t\t} else {\n\t\t\t\tint mid = mid(start, end);\n\t\t\t\tforward(root, start, end);\n\t\t\t\tprintOrigRec(left(root), start, mid, array);\n\t\t\t\tprintOrigRec(right(root), mid + 1, end, array);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate void build(int root, int start, int end) {\n\t\t\ttree[root] = 0;\n\t\t\tforwardAdd[root] = false;\n\t\t\tupdated[root] = false;\n\t\t\tif(start < end) {\n\t\t\t\tint mid = mid(start, end);\n\t\t\t\tbuild(left(root), start, mid);\n\t\t\t\tbuild(right(root), mid + 1, end);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate void resetRec(int root, int start, int end, int l, int r) {\n\t\t\tif(l > end || r < start) return; // no intersection\n\t\t\telse if(l <= start && end <= r) { // fully contained\n\t\t\t\ttree[root] = 0; \n\t\t\t\tupdated[root] = true;\n\t\t\t\tforwardAdd[root] = false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tforward(root, start, end);\n\t\t\t\tint mid = mid(start, end);\n\t\t\t\tresetRec(left(root), start, mid, l, r);\n\t\t\t\tresetRec(right(root), mid + 1, end, l, r);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate int getRec(int root, int start, int end, int pos) {\n\t\t\tif(start == end) {\n\t\t\t\treturn tree[root];\n\t\t\t}\n\t\t\tint mid = mid(start, end);\n\t\t\tforward(root, start, end);\n\t\t\tif(pos <= mid) {\n\t\t\t\treturn getRec(left(root), start, mid, pos);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn getRec(right(root), mid + 1, end, pos);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate void addRec(int root, int start, int end, int l, int r, int v) {\n\t\t\tif(l > end || r < start) return; // no intersection\n\t\t\telse if(l <= start && end <= r) { // fully contained\n\t\t\t\taddToNode(root, v);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tforward(root, start, end);\n\t\t\t\tint mid = mid(start, end);\n\t\t\t\taddRec(left(root), start, mid, l, r, v);\n\t\t\t\taddRec(right(root), mid + 1, end, l, r, v);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate void addToNode(int root, int v) {\n\t\t\tif(v > 0) {\n\t\t\t\ttree[root] = (tree[root] + v) % modulo;\n\t\t\t\tif(!updated[root]) {\n\t\t\t\t\tupdated[root] = true;\n\t\t\t\t\tforwardAdd[root] = true;\n\t\t\t\t} // else: if child was updated with ... add -> add more. ... set -> set more \n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate void forward(int root, int start, int end) {\n\t\t\tif(start == end) { // leaf\n\t\t\t\tforwardAdd[root] = false;\t\n\t\t\t} else {\n\t\t\t\tif(updated[root]) {\n\t\t\t\t\tif(forwardAdd[root]) {\t// add value of root to children\n\t\t\t\t\t\taddToNode(left(root), tree[root]);\n\t\t\t\t\t\taddToNode(right(root), tree[root]);\n\t\t\t\t\t} else {\t\t\t// set value of root to children\n\t\t\t\t\t\ttree[left(root)] = tree[root];\n\t\t\t\t\t\ttree[right(root)] = tree[root];\n\t\t\t\t\t\ttree[root] = 0;\n\t\t\t\t\t\t// children have to set their children as well.\n\t\t\t\t\t\tforwardAdd[left(root)] = false;\n\t\t\t\t\t\tforwardAdd[right(root)] = false;\n\t\t\t\t\t\tupdated[left(root)] = true;\n\t\t\t\t\t\tupdated[right(root)] = true;\n\t\t\t\t\t} \n\n\t\t\t\t}\n\t\t\t}\n\t\t\ttree[root] = 0;\n\t\t\tupdated[root] = false;\n\t\t\tforwardAdd[root] = false;\n\t\t}\n\t\t\n\t\tprivate int left(int root) {\n\t\t\treturn 2 * root + 1;\n\t\t}\n\t\t\n\t\tprivate int right(int root) {\n\t\t\treturn 2 * root + 2;\n\t\t}\n\t\t\n\t\tprivate int mid(int l, int r) {\n\t\t\treturn (l+r) / 2;\n\t\t}\n\t\t\n\t\tprivate int biggerPowerOfTwo(int x) {\n\t\t\treturn Integer.highestOneBit(x) << 1;\n\t\t}\n\t\t\n\t\tprivate int[] tree;\n\t\tprivate boolean[] updated;\n\t\t// forwardAdd == true means that the current value has to be added to all children\n\t\t// forwardAdd == false means that the current value has to be set to all children\n\t\tprivate boolean[] forwardAdd; \n\t\t\n\t\tprivate int size;\n\t}\n\t\n\tpublic class Block implements Comparable {\n\t\tint id;\n\t\tint x;\n\t\tint y1;\n\t\tint y2;\n\t\tboolean rightBorder;\n\t\t\n\t\tBlock(int id, int x, int y1, int y2, boolean ends) {\n\t\t\tthis.id = id;\n\t\t\tthis.x = x;\n\t\t\tthis.y1 = y1;\n\t\t\tthis.y2 = y2;\n\t\t\tthis.rightBorder = ends;\n\t\t}\n\n\t\t// the order defined here is crucial to the correctness of the algorithm.\n\t\t// at a position x: event \"end\" triggers update until next active block. hence more downwards \"ends\" have to come first to deactivate a block\n\t\t// but all \"starts\" have to come first as well to activate a block.\n\t\t@Override\n\t\tpublic int compareTo(Block o) {\n\t\t\t// first compare x (higher x is smaller), then the one with a right border comes first. if both same direction, then smaller y1 is smaller\n\t\t\tif(this.x == o.x)\n\t\t\t\t// starting first\n\t\t\t\tif(this.rightBorder == o.rightBorder) {\n\t\t\t\t\treturn this.y1 - o.y1; // lower first\n\t\t\t\t} else {\n\t\t\t\t\tif(this.rightBorder) return -1;\n\t\t\t\t\telse return +1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\treturn o.x - this.x;\n\t\t}\n\t}\n\t\n\tpublic class ActiveBlock implements Comparable {\n\t\tint id;\n\t\tint topY;\n\t\t\n\t\tActiveBlock(int id, int y) {\n\t\t\tthis.id = id;\n\t\t\tthis.topY = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(ActiveBlock o) {\n\t\t\tif(this.topY == o.topY) {\n\t\t\t\treturn this.id - o.id;\n\t\t\t}\n\t\t\treturn this.topY - o.topY;\n\t\t}\n\t}\n\t\n\tpublic void solve() throws FileNotFoundException {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n//\t\tScanner sc = new Scanner(new File(\"Tests/Slalom/27\"));\n\t\t// input\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\n\t\tBlock[] blocks = new Block[2*k+1];\n\t\tfor(int i = 0; i < k; ++i) {\n\t\t\tint x1 = sc.nextInt();\n\t\t\tint y1 = sc.nextInt();\n\t\t\tint x2 = sc.nextInt();\n\t\t\tint y2 = sc.nextInt();\n\t\t\tblocks[i] = new Block(i, x2, y1, y2, true);\t// as we proceed from right to left, a block \"starts\" at its right border. \n\t\t\tblocks[k + i] = new Block(i, x1 - 1 , y1, y2, false); // \"ending\" blocks are processed _after_ they have ended, so store them at x1 - 1\n\t\t}\n\t\tblocks[2*k] = new Block(k, n, m-1, m-1, false); //dummy ending block, right of and below (n, m), so stored at (n, m-1)\n\t\tArrays.sort(blocks);\n\t\tsc.close();\n\t\t\n\t\t\n\t\t//DEBUG:\n//\t\tint[][] matrix = new int[n][m + 2];\n\n\t\t// computation: dynamic programming in matrix\n\t\t// value of n, m is 1\n\t\t// if getTopRight is blocked, value is sum of getTop and getRight\n\t\t// else value is maximum of getTop and getRight\n\t\t// space improvement: only store current column of matrix. Use set of blocks to keep track of currently active blocks.\n\t\t// time improvement: use segment tree with operations reset(l, r), get(pos) and add(l, r) for this column\n\t\tSegmentTree col = new SegmentTree(m + 2);\n\t\tcol.add(m, m, 1);\n\t\tNavigableSet activeBlocks = new TreeSet();\n\t\tint i = 0;\n\t\tfor(int x = n; x >= 1; --x) {\n\t\t\twhile((i < 2*k + 1) && blocks[i].x == x) {\n\t\t\t\tBlock curBlock = blocks[i];\n\t\t\t\tif(curBlock.rightBorder) { // starting blocks\n\t\t\t\t\tactiveBlocks.add(new ActiveBlock(curBlock.id, curBlock.y2));\n\t\t\t\t\tcol.reset(curBlock.y1, curBlock.y2);\n\t\t\t\t} else { // ending blocks\n\t\t\t\t\tactiveBlocks.remove(new ActiveBlock(curBlock.id, curBlock.y2));\n\t\t\t\t\t// all squares left of that block, starting from the y2 of that block to the active next block (search in activeBlocks)\n\t\t\t\t\tActiveBlock lower = activeBlocks.floor(new ActiveBlock(k + 1, curBlock.y2));\n\t\t\t\t\tif(lower == null) lower = new ActiveBlock(k + 1, 0);\n\t\t\t\t\tif(lower.topY <= curBlock.y2) {\n\t\t\t\t\t\tint value = col.get(curBlock.y2 + 1);\n\t\t\t\t\t\tcol.add(lower.topY + 1, curBlock.y2, value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t++i;\n\t\t\t}\n\t\t\t// DEBUG:\n//\t\t\tcol.print(matrix[x-1]);\n\t\t\t\n\t\t}\n\n\t\t// DEBUG:\n//\t\tfor(int Y = m; Y >= 1; Y--) {\n// for(int X = 0; X < n; X++) {\n// System.out.print((matrix[X][Y] < 10 ? \" \" : \"\") + matrix[X][Y] + \" \");\n// }\n// System.out.println();\n// }\n\n\t\tSystem.out.println(col.get(1));\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Slalom().solve();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e43d6e17ab6cf19fc94fcc79b4b89a1a", "src_uid": "294ee0db72d759792d797b6259a83406", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Slalom {\n\n\tpublic final static long modulo = 1000000007;\n\t\n\tpublic class Block implements Comparable {\n\t\tint x;\n\t\tint y1;\n\t\tint y2;\n\t\tboolean rightBorder;\n\t\t\n\t\tBlock(int x, int y1, int y2, boolean ends) {\n\t\t\tthis.x = x;\n\t\t\tthis.y1 = y1;\n\t\t\tthis.y2 = y2;\n\t\t\tthis.rightBorder = ends;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Block o) {\n\t\t\t// first compare x (higher x is smaller), then the one with a right border comes first. if both same direction, then smaller y1 is smaller\n\t\t\tif(this.x == o.x)\n\t\t\t\t// starting first\n\t\t\t\tif(this.rightBorder == o.rightBorder) {\n\t\t\t\t\treturn o.y1 - this.y1; \n\t\t\t\t} else {\n\t\t\t\t\tif(o.rightBorder) return +1;\n\t\t\t\t\telse return -1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\treturn o.x - this.x;\n\t\t}\n\t}\n\t\n\tpublic void solve() throws FileNotFoundException {\n\t\t//Scanner sc = new Scanner(System.in);\n\t\t\n\t\tFile file = new File(\"Tests/Slalom/04\");\n\t\tScanner sc = new Scanner(file);\n\t\t// input\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\n\t\tBlock[] blocks = new Block[2*k+1];\n\t\tfor(int i = 0; i < k; ++i) {\n\t\t\tint x1 = sc.nextInt();\n\t\t\tint y1 = sc.nextInt();\n\t\t\tint x2 = sc.nextInt();\n\t\t\tint y2 = sc.nextInt();\n\t\t\tblocks[i] = new Block(x2, y1, y2, true);\t// as we proceed from right to left, a block \"starts\" at its right border. \n\t\t\tblocks[k + i] = new Block(x1 - 1 , y1, y2, false); // \"ending\" blocks are processed _after_ they have ended, so store them at x1 - 1\n\t\t}\n\t\tblocks[2*k] = new Block(n, m-1, m-1, false); //dummy ending block, right of and below (n, m), so stored at (n, m-1)\n\t\tArrays.sort(blocks);\n\t\tsc.close();\n\t\t\n\t\t//DEBUG:\n\t\t//int[][] matrix = new int[n][m];\n\n\t\t// computation: dynamic programming in matrix\n\t\t// value of n, m is 1\n\t\t// if getTopRight is blocked, value is sum of getTop and getRight\n\t\t// else value is maximum of getTop and getRight\n\t\t// space improvement: only store current column of matrix. Use set of blocks to keep track of currently active blocks.\n\t\tint[] col = new int[m + 2];\n\t\tcol[m] = 1;\n\t\tNavigableSet activeBlocks = new TreeSet();\n\t\tint i = 0;\n\t\tfor(int x = n; x >= 1; --x) {\n\t\t\twhile((i < 2*k + 1) && blocks[i].x == x) {\n\t\t\t\tBlock curBlock = blocks[i];\n\t\t\t\tif(curBlock.rightBorder) { // starting blocks\n\t\t\t\t\tactiveBlocks.add(curBlock.y2);\n\t\t\t\t\tfor(int y = curBlock.y2; y >= curBlock.y1; --y) {\n\t\t\t\t\t\tcol[y] = 0;\n\t\t\t\t\t}\n\t\t\t\t} else { // ending blocks\n\t\t\t\t\tactiveBlocks.remove(curBlock.y2);\n\t\t\t\t\t// all squares left of that block, starting from the y2 of that block to the active next block (search in activeBlocks)\n\t\t\t\t\tInteger lower = activeBlocks.floor(curBlock.y2);\n\t\t\t\t\tif(lower == null) lower = 0;\n\t\t\t\t\tfor(int y = curBlock.y2; y > lower; --y) {\n\t\t\t\t\t\tcol[y] += col[curBlock.y2 + 1] % modulo;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t++i;\n\t\t\t}\n\t\t\t// DEBUG:\n//\t\t\tfor(int j = 0; j < m; ++j)\n//\t\t\t\tmatrix[x-1][j] = col[j + 1];\n\t\t}\n\n\t\t// DEBUG:\n//\t\tfor(int Y = m - 1; Y >= 0; Y--) {\n// for(int X = 0; X < n; X++) {\n// System.out.print((matrix[X][Y] < 10 ? \" \" : \"\") + matrix[X][Y] + \" \");\n// }\n// System.out.println();\n// }\n\n\t\tSystem.out.println(col[1]);\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Slalom().solve();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad802ab50959da024e1768f6a8e40751", "src_uid": "294ee0db72d759792d797b6259a83406", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class Main {\n \n public final static long modulo = 1000000007;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n // input\n int n = sc.nextInt();\n int m = sc.nextInt();\n long[][] matrix = new long[n+1][m+1];\n /*for(int x = 0; x <= n; ++x) {\n matrix[x][m] = 0;\n }\n for(int y = 0; y <= m; ++y) {\n matrix[n][y] = 0;\n }*/\n matrix[n-1][m-1] = 1;\n int k = sc.nextInt();\n for(int i = 0; i < k; ++i) {\n int x1 = sc.nextInt();\n int y1 = sc.nextInt();\n int x2 = sc.nextInt();\n int y2 = sc.nextInt();\n for(int x = x1; x <= x2; ++x) {\n for(int y = y1; y <= y2; ++y) {\n matrix[x-1][y-1] = -1;\n }\n }\n }\n \n // computation: dynamic programming in matrix\n // value of n, m is 1\n // if getTopRight is blocked, value is sum of getTop and getRight\n // else value is maximum of getTop and getRight\n for(int y = m - 1; y >= 0; --y) {\n for(int x = n - 1; x >= 0; --x) {\n if(matrix[x][y] == -1) {\n matrix[x][y] = 0;\n } else {\n if(x == n - 1 && y == m - 1) {\n matrix[x][y] = 1;\n } else if(matrix[x+1][y] == 0 || matrix[x][y+1] == 0) {\n matrix[x][y] = (Math.max(matrix[x][y + 1], matrix[x + 1][y]) + modulo) % modulo; \n } else {\n matrix[x][y] = (matrix[x+1][y] + matrix[x][y+1] - matrix[x+1][y+1] + modulo) % modulo;\n }\n }\n }\n }\n /*for(int y = m - 1; y >= 0; y--) {\n for(int x = 0; x < n; x++) {\n System.out.print((matrix[x][y] < 10 ? \" \" : \"\") + matrix[x][y] + \" \");\n }\n System.out.println();\n }*/\n \n System.out.println(matrix[0][0]);\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c26cd6cbb579731d982240304bf1b3a1", "src_uid": "294ee0db72d759792d797b6259a83406", "difficulty": 3100.0} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by zephyr on 11/5/14.\n */\n public class Factory {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int a = scanner.nextInt();\n int m = scanner.nextInt();\n int[] values = new int[m];\n a = a % m;\n Arrays.fill(values, 0);\n if (a == 0) {\n System.out.println(\"YES\");\n return;\n }\n values[a] = 1;\n for (int i = 1; i < 100000000; i++) {\n a = (a * 2) % m;\n if (a == 0) {\n System.out.println(\"YES\");\n return;\n }\n if (values[a] == 1) {\n System.out.println(\"NO\");\n return;\n } else {\n values[a] = 1;\n }\n\n\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "85ed69bd4d20a76203766d13e0498189", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class susbus{\n public static void main(String[] args){\n Scanner sc= new Scanner(System.in);\n int a = sc.nextInt();\n int m = sc.nextInt();\n int k = m/a;\n if((m%a==0 && isPowerofTwo(k)) || isPowerOfTwo(m)) System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n public static boolean isPowerOfTwo(int n){\n if(n==0) return false;\n\n while(n>1){\n if(n%2!= 0) return false;\n \n n=n/2;\n }\n return true;\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7245219f01458f96fc7fb06010e0e1bb", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by zephyr on 11/5/14.\n */\n public class Factory {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int a = scanner.nextInt();\n int m = scanner.nextInt();\n int[] values = new int[m];\n a = a % m;\n Arrays.fill(values, 0);\n if (a == 0) {\n System.out.println(\"YES\");\n return;\n }\n values[a] = 1;\n for (int i = 1; i < 100000000; i++) {\n a = (a * 2) % m;\n if (a == 0) {\n System.out.println(\"YES\");\n return;\n }\n if (values[a] == 1) {\n System.out.println(\"NO\");\n return;\n } else {\n values[a] = 1;\n }\n\n\n }\n } ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fc6ae0d4b3f82cab668b945eab4f7b07", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class susbus{\n public static void main(String[] args){\n Scanner sc= new Scanner(System.in);\n int a = sc.nextInt();\n int m = sc.nextInt();\n \n if((m%a==0 && isPowerofTwo(m/a)) || isPowerOfTwo(m)) System.out.println(\"Yes\");\n else System.out.println(\"No\");\n }\n public static boolean isPowerOfTwo(int n){\n while(n>1){\n if(n%2!= 0) return false;\n \n n=n/2;\n }\n return true;\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "15a9ba1cf18ddab9bc9666a1b298a8bc", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class D \n{\n public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n public static StringTokenizer inp;\n public static void main(String[] args) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n int ln[] = new int[1026];\n ln[0] = 0 ; ln[1023] = 2000000000;\n int ind = 1;\n for(int i = 2 ; i < 1024 ; i++)\n {\n char s[] = Integer.toBinaryString(i).toCharArray();\n for(int j = 1 ; j < s.length ; j++) s[j] = (s[j]=='0'?'4':'7');\n ln[ind++] = Integer.parseInt(String.valueOf(s).substring(1));\n }\n inp = new StringTokenizer(br.readLine());\n int pl = nextInt(),pr = nextInt() , vl=nextInt() , vr = nextInt() , k = nextInt();\n long ans = 0;\n int l = 1, r = k;\n for(; r <= 1022 ; r++,l++)\n {\n if(vl>ln[l])continue;\n if(ln[r] > pr || ln[l-1] > vr)break;\n ans+=(long)Math.max(0, (Math.min(ln[l], vr)- Math.max(vl, ln[l-1]+1) + 1))*Math.max(0, (Math.min(pr, ln[r+1]-1)- Math.max(ln[r], pl) + 1));\n }\n l=1;r=k;\n for(; r <= 1022 ; r++,l++)\n {\n if(pl>ln[l])continue;\n if(ln[r] > vr || ln[l-1] > pr)break;\n ans+=(long)Math.max(0, (Math.min(ln[l], pr)- Math.max(pl, ln[l-1]+1) + 1))*Math.max(0, (Math.min(vr, ln[r+1]-1)- Math.max(ln[r], vl) + 1));\n }\n if(k==1)\n {\n for(int i = 1; i <= 1022 ; i++)\n if(pl<=ln[i] && ln[i]<=pr && vl<=ln[i]&&ln[i]<=vr)ans--;\n }\n double res = (double)(ans)/((long)(pr-pl+1)*(vr-vl+1));\n System.out.printf(\"%.12f\\n\",Math.min(res, 1.0));\n }\n \n public static int nextInt(){return Integer.parseInt(inp.nextToken());}\n public static long nextLong(){return Long.parseLong(inp.nextToken());}\n public static double nextDouble(){return Double.parseDouble(inp.nextToken());}\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d40f466db270121f5952b5277894e55", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 8/29/11\n * Time: 10:41 PM\n */\npublic class LuckyProbable {\n public static void main(String[] args) {\n reader = new BufferedReader(new InputStreamReader(System.in));\n\n generateLuckyNums();\n\n int p1 = nextInt(), p2 = nextInt(), v1 = nextInt(), v2 = nextInt(), k = nextInt();\n final int MAX = 1000000001;\n\n double res = 0.0;\n int n = luckyNums.size();\n for(int i = 0; i < n; ++i) {\n int j = i + k - 1;\n if (j >= n) {\n break;\n }\n\n int a1 = (i == 0 ? 0 : luckyNums.get(i - 1)) + 1;\n int a2 = luckyNums.get(i);\n int b1 = luckyNums.get(j);\n int b2 = (j == n-1 ? MAX : luckyNums.get(j + 1)) - 1;\n\n res += calc(a1, a2, b1, b2, p1, p2, v1, v2);\n res += calc(b1, b2, a1, a2, p1, p2, v1, v2);\n }\n\n double tot = 1.0 * (p2 - p1 + 1) * (v2 - v1 + 1);\n\n System.out.println(res/tot);\n }\n\n private static double calc(int a1, int a2, int b1, int b2, int p1, int p2, int v1, int v2) {\n double x = calc(a1, a2, p1, p2);\n double y = calc(b1, b2, v1, v2);\n return x * y;\n }\n\n private static double calc(int a1, int a2, int p1, int p2) {\n int x = Math.max(a1, p1);\n int y = Math.min(a2, p2);\n return Math.max(y - x + 1, 0);\n }\n\n private static ArrayList luckyNums;\n\n private static void generateLuckyNums() {\n luckyNums = new ArrayList();\n int[] digit = new int[]{4,7};\n\n for(int bitLen = 1; bitLen < 10; ++bitLen) {\n for(int b = 0; b < (1 << bitLen); ++b) {\n int n = 0;\n for(int i = 0; i < bitLen; ++i) {\n n = n * 10 + digit[(b >> i) & 1];\n }\n luckyNums.add(n);\n }\n }\n\n Collections.sort(luckyNums);\n }\n\n public static BufferedReader reader;\n\n public static StringTokenizer tokenizer = null;\n\n static 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 static public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n static public long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n static public String next() {\n return nextToken();\n }\n\n static public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a0a662e7e8a54fa51b837cfd261d78b", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n/**\n * Author -\n * User: kansal\n * Date: 8/29/11\n * Time: 10:41 PM\n */\npublic class LuckyProbable {\n public static void main(String[] args) {\n reader = new BufferedReader(new InputStreamReader(System.in));\n\n generateLuckyNums();\n\n int p1 = nextInt(), p2 = nextInt(), v1 = nextInt(), v2 = nextInt(), k = nextInt();\n final int MAX = 1000000000;\n\n double res = 0.0;\n int n = luckyNums.size();\n for(int i = 0; i < n; ++i) {\n int j = i + k - 1;\n if (j >= n) {\n break;\n }\n\n int a1 = (i == 0 ? 0 : luckyNums.get(i - 1)) + 1;\n int a2 = luckyNums.get(i);\n int b1 = luckyNums.get(j);\n int b2 = (j == n-1 ? MAX : luckyNums.get(j + 1)) - 1;\n\n res += calc(a1, a2, b1, b2, p1, p2, v1, v2);\n res += calc(b1, b2, a1, a2, p1, p2, v1, v2);\n }\n\n double tot = 1.0 * (p2 - p1 + 1) * (v2 - v1 + 1);\n\n System.out.println(res/tot);\n }\n\n private static double calc(int a1, int a2, int b1, int b2, int p1, int p2, int v1, int v2) {\n double x = calc(a1, a2, p1, p2);\n double y = calc(b1, b2, v1, v2);\n return x * y;\n }\n\n private static double calc(int a1, int a2, int p1, int p2) {\n int x = Math.max(a1, p1);\n int y = Math.min(a2, p2);\n return Math.max(y - x + 1, 0);\n }\n\n private static ArrayList luckyNums;\n\n private static void generateLuckyNums() {\n luckyNums = new ArrayList();\n int[] digit = new int[]{4,7};\n\n for(int bitLen = 1; bitLen < 10; ++bitLen) {\n for(int b = 0; b < (1 << bitLen); ++b) {\n int n = 0;\n for(int i = 0; i < bitLen; ++i) {\n n = n * 10 + digit[(b >> i) & 1];\n }\n luckyNums.add(n);\n }\n }\n\n Collections.sort(luckyNums);\n }\n\n public static BufferedReader reader;\n\n public static StringTokenizer tokenizer = null;\n\n static 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 static public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n static public long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n static public String next() {\n return nextToken();\n }\n\n static public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d58feec159ae0e1954287a6b928c5f0", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\npublic class LuckyProbability\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int pl = sc.nextInt();\n int pr = sc.nextInt();\n int vl = sc.nextInt();\n int vr = sc.nextInt();\n int k = sc.nextInt();\n \n int ln = 1 << 9;\n int[] lucky = new int[ln];\n int y = 0;\n for (int b = 1; b <= 8; ++b)\n {\n for (int i = 0; i < (1 << b); ++i)\n {\n String str = Integer.toBinaryString(i);\n for (int j = str.length(); j < b; ++j)\n {\n str = \"0\" + str;\n }\n str = str.replace('0', '4');\n str = str.replace('1', '7');\n lucky[y++] = Integer.parseInt(str);\n }\n }\n \n int n = 0;\n for (int p = pl; p <= pr; ++p)\n {\n for (int v = vl; v <= vr; ++v)\n {\n int mi = Math.min(v, p);\n int mx = Math.max(v, p);\n \n int ux = y - 1;\n int ui = 0;\n for (int l = 0; l < y; ++l)\n {\n if (mx < lucky[l])\n {\n ux = l - 1;\n break;\n }\n }\n for (int l = y - 1; l >= 0; --l)\n {\n if (mi > lucky[l])\n {\n ui = l + 1;\n break;\n }\n }\n if (k == ux - ui + 1)\n {\n n++;\n }\n }\n }\n System.out.println((n*1.0)/((pr-pl+1)*(vr-vl+1)));\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "695125698495d2fd98febd1af6c62191", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n \n final boolean file = false;\n \n int dx[] = new int[] {-1,-1,1,1};\n int dy[] = new int[] {-1,1,-1,1};\n \n void solve() throws Exception {\n int n = sc.nextInt();\n int m = sc.nextInt();\n int need = sc.nextInt();\n int color[][] = new int[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if ((i + j) % 2 != 0) continue;\n color[i][j] = 0;\n }\n }\n int recolor[] = new int[n * m];\n int w;\n for (int step = 1;; step++) {\n w = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if ((i + j) % 2 != 0 || color[i][j] != step - 1) continue;\n boolean ok = true;\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 || color[x][y] != step - 1) {\n ok = false;\n break;\n }\n }\n if (ok) {\n recolor[w++] = i * m + j;\n }\n }\n }\n if (w == 0) break;\n \n for (int i = 0; i < w; i++) {\n int id = recolor[i];\n int x = id / m;\n int y = id % m;\n color[x][y] = step;\n }\n }\n int res = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if ((i + j) % 2 != 0) continue;\n if (color[i][j] == need - 1) res++;\n }\n }\n out.println(res);\n }\n \n BufferedReader in;\n PrintWriter out;\n FastScanner sc;\n \n static Throwable uncaught;\n \n public void run() {\n try {\n if (file) {\n in = new BufferedReader(new FileReader(\"strings.in\"));\n out = new PrintWriter(new FileWriter(\"strings.out\"));\n } else {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n sc = new FastScanner(in);\n solve();\n } catch (Throwable t) {\n Main.uncaught = t;\n } finally {\n out.close();\n }\n }\n \n public static void main(String[] args) throws Throwable {\n Thread t = new Thread(null, new Main(), \"\", 128 * 1024 * 1024);\n t.start();\n t.join();\n if (uncaught != null) {\n throw uncaught;\n }\n }\n\n}\n\nclass FastScanner {\n \n BufferedReader reader;\n StringTokenizer strTok;\n \n public FastScanner(BufferedReader reader) {\n this.reader = reader;\n }\n \n public String nextToken() throws IOException {\n while (strTok == null || !strTok.hasMoreTokens()) {\n strTok = new StringTokenizer(reader.readLine());\n }\n return strTok.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2999bb778f982223cade9bd84aa796e5", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n \n final boolean file = false;\n \n int dx[] = new int[] {-1,-1,1,1};\n int dy[] = new int[] {-1,1,-1,1};\n \n void solve() throws Exception {\n int n = sc.nextInt();\n int m = sc.nextInt();\n int need = sc.nextInt();\n int color[][] = new int[n][m];\n int cnt[][] = new int[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if ((i + j) % 2 != 0) continue;\n cnt[i][j]++;\n color[i][j] = 0;\n }\n }\n int recolor[] = new int[n * m];\n int w;\n for (int step = 1;; step++) {\n w = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if ((i + j) % 2 != 0 || color[i][j] != step - 1) continue;\n boolean ok = true;\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 || color[x][y] != step - 1) {\n ok = false;\n break;\n }\n }\n if (ok) {\n recolor[w++] = i * m + j;\n }\n }\n }\n if (w == 0) break;\n \n for (int i = 0; i < w; i++) {\n int id = recolor[i];\n int x = id / m;\n int y = id % m;\n color[x][y] = step;\n cnt[x][y]++;\n }\n }\n int res = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if ((i + j) % 2 != 0) continue;\n if (cnt[i][j] == need) res++;\n }\n }\n out.println(res);\n }\n \n BufferedReader in;\n PrintWriter out;\n FastScanner sc;\n \n static Throwable uncaught;\n \n public void run() {\n try {\n if (file) {\n in = new BufferedReader(new FileReader(\"strings.in\"));\n out = new PrintWriter(new FileWriter(\"strings.out\"));\n } else {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n sc = new FastScanner(in);\n solve();\n } catch (Throwable t) {\n Main.uncaught = t;\n } finally {\n out.close();\n }\n }\n \n public static void main(String[] args) throws Throwable {\n Thread t = new Thread(null, new Main(), \"\", 128 * 1024 * 1024);\n t.start();\n t.join();\n if (uncaught != null) {\n throw uncaught;\n }\n }\n\n}\n\nclass FastScanner {\n \n BufferedReader reader;\n StringTokenizer strTok;\n \n public FastScanner(BufferedReader reader) {\n this.reader = reader;\n }\n \n public String nextToken() throws IOException {\n while (strTok == null || !strTok.hasMoreTokens()) {\n strTok = new StringTokenizer(reader.readLine());\n }\n return strTok.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ee84bada62227f1c285b8dd5fd84dc90", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\n\n\npublic class B\n{\n public static void main(String[] args)\n {\n new B(new Scanner(System.in));\n }\n\n int oo = 987654321;\n\n int[][] grid;\n int W;\n int H;\n \n\n boolean check(int x, int y)\n {\n if (x < 0) return false;\n if (y < 0) return false;\n if (x >= W) return false;\n if (y >= H) return false;\n return true;\n }\n\n boolean isWall(int x, int y)\n {\n if (!check(x+1, y+1)) return true;\n if (!check(x-1, y+1)) return true;\n if (!check(x+1, y-1)) return true;\n if (!check(x-1, y-1)) return true;\n return false;\n }\n\n void add(ArrayDeque q, int x, int y, int d)\n {\n if (!check(x, y)) return;\n if (grid[x][y] <= d) return;\n q.add(new Node(x, y, d));\n }\n\n void bfs()\n {\n for (int[] gri : grid)\n Arrays.fill(gri, oo);\n \n ArrayDeque q = new ArrayDeque();\n for (int j=0; j 0)\n {\n Node cur = q.poll();\n if (grid[cur.x][cur.y] <= cur.d) continue;\n grid[cur.x][cur.y] = cur.d;\n\n add(q, cur.x+1, cur.y+1, cur.d+1);\n add(q, cur.x-1, cur.y+1, cur.d+1);\n add(q, cur.x+1, cur.y-1, cur.d+1);\n add(q, cur.x-1, cur.y-1, cur.d+1);\n }\n }\n\n public B(Scanner in)\n {\n W = in.nextInt();\n H = in.nextInt();\n grid = new int[W][H];\n\n int N = in.nextInt();\n bfs();\n\n int res = 0;\n for (int[] gri : grid)\n for (int v : gri)\n if (v == N)\n res++;\n System.out.printf(\"%d%n\", res);\n\n }\n}\n\n\nclass Node\n{\n int x, y, d;\n\n public Node(int xx, int yy, int dd)\n {\n x=xx; y=yy; d=dd;\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9068645a80952c40bba48adae3e778fc", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tMyScanner in;\n\tPrintWriter out;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tpublic void run() throws Exception {\n\t\tin = new MyScanner();\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tpublic void solve() throws Exception {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint x = in.nextInt();\n\t\t\n\t\tint l = 1, r = m, t = 1, b = n;\n\t\tfor (int i = 0; i < x - 1; i++) {\n\t\t\tl++;\n\t\t\tr--;\n\t\t\tt++;\n\t\t\tb--;\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor (int i = l; i <= r; i++) {\n\t\t\tfor (int j = t; j <= b; j++) {\n\t\t\t\tif (((i == l) || (i == r) || (j == t) || (j == b)) && ((i + j) % 2 == 0)) ans++;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n}\n\nclass MyScanner {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic MyScanner() throws Exception {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString next() throws Exception {\n\t\tif ((st == null) || (!st.hasMoreTokens())) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tboolean nextBoolean() throws Exception {\n\t\treturn Boolean.parseBoolean(next());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(next());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aac1a889b69e44ece59bb8caec1e80b6", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class C {\n\n int INF = 1 << 28;\n long P = 1000000009;\n\n void run() {\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n String t = sc.next();\n long[][] dp = new long[s.length()][t.length()];\n for(int i=0;i= a.length || j >= b.length) return 0;\n \n if(DP[i][j] != -1)return DP[i][j];\n \n if(a[i] == b[j]){\n return DP[i][j] = 1 + go(i + 1, j + 1) + go(i, j + 1);\n }else{\n return DP[i][j] = go(i, j + 1);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "937bf3e3b89a564a626ed360c0ffc951", "src_uid": "4022f8f796d4f2b7e43a8360bf34e35f", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n a = r.next().toCharArray();\n b = r.next().toCharArray();\n \n DP = new int[a.length + 1][b.length + 1];\n \n int ret = 0;\n for(int s = 0; s < a.length; s++){\n ret += go(s, 0);\n }\n \n System.out.println(ret);\n }\n static char[] a, b;\n static int[][] DP;\n static int mod = 1000000007;\n private static int go(int i, int j) {\n if(i >= a.length || j >= b.length) return 0;\n \n if(a[i] == b[j]){\n return DP[i][j] = (int) (((long)1 + go(i + 1, j + 1) + go(i, j + 1)) % mod);\n }else{\n return DP[i][j] = go(i, j + 1);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3c34ebc32706877804f293c60f9fe8f7", "src_uid": "4022f8f796d4f2b7e43a8360bf34e35f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class main {\n\t\n\tpublic static long f[];\n\tpublic static int n;\n\tpublic static long k;\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner reader = new Scanner(System.in);\n\t\tf = new long[55];\n\t\tf[0] = 1;\n\t\tf[1] = 1;\n\t\tfor (int i = 2; i <= 50; i++)\n\t\t\tf[i] = f[i - 1] + f[i - 2];\n\t\t\n\t\tn = reader.nextInt();\n\t\tk = reader.nextLong();\n\t\t\n\t\tint m = 1;\n\t\twhile (true){\n\t\t\tif (k <= f[n - 1]){\n\t\t\t\tSystem.out.print(m + \" \");\n\t\t\t\tn--;\n\t\t\t\tm++;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tk -= f[n - 1];\n\t\t\t\tSystem.out.print((m + 1) + \" \" + m + \" \");\n\t\t\t\tm += 2;\n\t\t\t\tn -= 2;\n\t\t\t}\n\t\t\tif (n == 1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (n == 0) break; \n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "399ae2863d2a683e92f59577e3d4cb56", "src_uid": "e03c6d3bb8cf9119530668765691a346", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class cf3092D{\n\tstatic int n, k;\n\tstatic int[] fib;\n\tstatic ArrayDeque list = new ArrayDeque();\n\t\n public static void main(String[] args) throws IOException {\n \tScanner f = new Scanner(System.in);\n StringTokenizer st = new StringTokenizer(f.nextLine());\n n = Integer.parseInt(st.nextToken());\n k = Integer.parseInt(st.nextToken());\n fib = new int[51];\n fib[0] = 1;\n fib[1] = 1;\n f.close();\n for(int i = 2; i < 51; i++){\n \tfib[i] = fib[i-1] + fib[i-2];\n }\n \n act(n-1);\n String ans = \"\";\n for(int i = 1; i <= n; i++){\n \tint num = list.poll();\n \tif(num == 1){\n \t\tans += (i+1) + \" \" + i + \" \";\n \t\ti++;\n \t}\n \telse{\n \t\tans += i + \" \";\n \t}\n }\n \n ans = ans.substring(0, ans.length()-1);\n System.out.println(ans);\n }\n \n static void act(int i){\n \tif(i > -1){\n \t\tif(k <= fib[i]){\n\t \t\tlist.add(0);\n\t \t\tact(i-1);\n\t \t}\n\t \telse{\n\t \t\tlist.add(1);\n\t \t\tk -= fib[i];\n\t \t\tact(i-2);\n\t \t}\n \t}\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "25ba2174d19f078e512c6ca7e927bcda", "src_uid": "e03c6d3bb8cf9119530668765691a346", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.PrintWriter;\npublic class a \n{\n\tpublic static void main(String[] arg)\n\t{\n\t\tnew a();\n\t}\n\tlong MOD = 1_000_000_007;\n\tlong[][] memo;\n\tlong[] fib;\n\tpublic a()\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = in.nextInt();\n\t\tlong k = in.nextLong();\n\t\tint[] arr = new int[n];\n\t\tfor(int i = 1; i <= n; i++) arr[i-1] = i;\n\t\tfib = new long[n+1];\n\t\tfib[0] = 1;\n\t\tfib[1] = 1;\n\t\tfor(int i = 2; i < fib.length; i++) fib[i] = fib[i-1] + fib[i-2];\n\t\tint index = 0;\n\t\twhile(k > 1)\n\t\t{\n\t\t\tif(k <= fib[n-index-1])\n\t\t\t\tindex++;\n\t\t\telse\n\t\t\t{\n\t\t\t\tk -= fib[n-index-1]+1;\n\t\t\t\tswap(arr, index, index+1);\n\t\t\t}\n\t\t}\n\t\tfor(int v : arr) out.print(v + \" \");\n\t\tin.close();\n\t\tout.close();\n\t}\n\tvoid swap(int[] arr, int i, int j)\n\t{\n\t\tint temp = arr[i];\n\t\tarr[i] = arr[j];\n\t\tarr[j] = temp;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "069505dd1229e87ed1f7b8d92fe9f2b7", "src_uid": "e03c6d3bb8cf9119530668765691a346", "difficulty": 1900.0} {"lang": "Java 8", "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 * @author Aldo Culquicondor\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n void move(int[] A, int start, int end) {\n int tmp = A[end-1];\n for (int i = start; i < end - 1; ++i)\n A[i + 1] = A[i];\n A[start] = tmp;\n }\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n long k = (1L << n - 1) - in.nextLong();\n int[] A = new int[n];\n for (int i = 0; i < n; ++i)\n A[i] = i + 1;\n int[] C = new int[n];\n int sz = 1;\n for (int i = 1; i < n; ++i) {\n if ((k & (1L << n - i - 1)) != 0)\n C[sz++] = i;\n }\n for (int i = 0; i < sz - 1; ++i)\n move(A, C[i], C[i+1]);\n IOUtils.printArray(out, A);\n out.println();\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private 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 public long nextLong() {\n return Long.parseLong(next());\n }\n}\n\nclass IOUtils {\n public static void printArray(PrintWriter out, int A[], int start, int end) {\n out.print(A[0]);\n for (int i = start + 1; i < end; ++i)\n out.printf(\" %d\", A[i]);\n }\n public static void printArray(PrintWriter out, int A[]) {\n printArray(out, A, 0, A.length);\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "97a583c3e8736f108bb0aefebb2718ce", "src_uid": "e03c6d3bb8cf9119530668765691a346", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable{\n public static void main(String[] args){\n //new Thread(null,new Main(),\"Thread-1\",1024*1024*10).start();\n new Main().run();\n }\n int mod=998244353;\n private void solve() throws Exception {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n=in.nextInt(),k=in.nextInt(),l=in.nextInt();\n long[]fac=new long[n+1];\n fac[0]=1;\n for(int i=1;i<=n;i++){\n fac[i]=fac[i-1]*i%mod;\n }\n long[][]dp=new long[2*n+1][2*n+2];\n dp[0][0]=1;\n for(int i=1;i<=2*n;i++){\n for(int j=0;j<=i;j++){\n if(j>0) dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;\n dp[i][j]=(dp[i][j]+dp[i-1][j+1]*(j+1)%mod)%mod;\n }\n }\n long ans=0;\n for(int i=k;i<=2*n;i++){\n for(int j=k;j<=n;j++){\n ans=(ans+dp[i][j]*dp[2*n-i][j]%mod*fac[j]%mod)%mod;\n }\n }\n out.println(l*ans%mod*Pow(dp[2*n][0],mod-2)%mod*Pow(2*n+1,mod-2)%mod);\n out.flush();\n }\n long Pow(long a,long b){\n long ans=1;\n while(b>0){\n if((b&1)!=0)ans=(ans*a)%mod;\n a=(a*a)%mod;\n b>>=1;\n }\n return ans;\n }\n @Override\n public void run() {\n try {\n solve();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n class InputReader{\n StreamTokenizer tokenizer;\n public InputReader(InputStream stream){\n tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));\n tokenizer.ordinaryChars(33,126);\n tokenizer.wordChars(33,126);\n }\n public String next() throws IOException {\n tokenizer.nextToken();\n return tokenizer.sval;\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n public boolean hasNext() throws IOException {\n int res=tokenizer.nextToken();\n tokenizer.pushBack();\n return res!=tokenizer.TT_EOF;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ea2bafbb852465865b305fa50c7d487", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces1153F {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint P = 998244353;\n\t\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint real_k = Integer.parseInt(st.nextToken());\n\t\tint l = Integer.parseInt(st.nextToken());\n\t\t\t\t\n\t\t//generate factorials\n\t\tint[] factorials = new int[2*n+2];\n\t\tfactorials[0] = 1;\n\t\tfor (int i = 1; i <= 2*n+1; i++) {\n\t\t\tfactorials[i] = multiply(factorials[i-1], i, P);\n\t\t}\n\t\t\n\t\t//number of ways to choose k pairs from 2k elements\n\t\t//where order doesn't matter\n\t\t//equals (2k)!/(2^n)/k! = (2k-1)!!\n\t\tint[] doublefact = new int[n+1];\n\t\tdoublefact[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tdoublefact[i] = multiply(doublefact[i-1], (2*i-1), P);\n\t\t}\n\n\t\t//list[r][k] stores for rth segment, exactly k of the n segments covering it \n\t\tint[][] list = new int[2*n+2][n+1];\n\t\t\n\t\tfor (int r = 1; r <= 2*n+1; r++) {\n\t\t\tfor (int k = 1; k <= n; k++) {\n\t\t\t\tif (((r%2) != (k%2)) && (r-1 >= k) && (2*n+1-r >= k)) {\n\t\t\t\t\tint num = multiply(factorials[r-1], factorials[2*n+1-r], P);\n\t\t\t\t\tnum = multiply(num, doublefact[(r-k-1)/2], P);\n\t\t\t\t\tnum = multiply(num, doublefact[(2*n+1-r-k)/2], P);\n\t\t\t\t\t\n\t\t\t\t\tint denom = multiply(factorials[r-k-1], factorials[2*n+1-r-k], P);\n\t\t\t\t\tdenom = multiply(denom, factorials[k], P);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tlist[r][k] = multiply(num, inverse(multiply(denom, doublefact[n], P), P), P);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor (int r = 1; r <= 2*n+1; r++) {\n\t\t\tfor (int k = real_k; k <= n; k++) {\n\t\t\t\tans += list[r][k];\n\t\t\t\tans %= P;\n\t\t\t}\n\t\t}\n\t\t\n\t\tans = multiply(ans, l, P);\n\t\tans = multiply(ans, inverse(2*n+1, P), P);\n\t\t\n\t\tSystem.out.println(ans);\n\n\t}\n\t\n\tpublic static int multiply (int a, int b, int n) {\n\t\tlong ab = (long) a * (long) b;\n\t\treturn ((int) (ab%n));\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "417a4cd83a7c4c38db24bd157a3d0239", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "package Contest551;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class mainF {\n public static Scanner enter = new Scanner(System.in);\n public static PrintWriter out = new PrintWriter(System.out);\n public static long mod=998244353;\n public static long cnk[][]=new long[(int)2e3+1][(int)2e3+1];\n public static long fact[]=new long[2*(int)2e3+1];\n public static long reverse[]=new long[2*(int)2e3+1];\n public static long deg_2[]=new long[(int)2e3+1];\n public static void main(String[] args) {\n long t=System.currentTimeMillis();\n cnk[0][0]=1;\n for (int i = 1; i >=1;\n }\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f149de5d7316d3a74a95e4c3c309ba6f", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "//package Contest551;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class mainF {\n public static Scanner enter = new Scanner(System.in);\n public static PrintWriter out = new PrintWriter(System.out);\n public static long mod=998244353;\n public static long cnk[][]=new long[(int)2e3+1][(int)2e3+1];\n public static long fact[]=new long[2*(int)2e3+1];\n public static long reverse[]=new long[2*(int)2e3+1];\n public static long deg_2[]=new long[(int)2e3+1];\n public static void main(String[] args) {\n long t=System.currentTimeMillis();\n cnk[0][0]=1;\n for (int i = 1; i >=1;\n }\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7327a5e2986610580fb1553540e00555", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "\n/**\n * Created by evgeniyradchenko on 11/28/17.\n */\npublic class Main {\n\n private static int NMAX = 22;\n private static long a[] = new long[NMAX];\n private static boolean c[] = new boolean[NMAX + 1];\n private static int d[] = new int[NMAX + 1];\n\n public static void main(String[] args) throws Exception {\n Scanner s = new Scanner(System.in);\n\n int n = s.nextInt();\n for (int i = 0; i < n; ++i) {\n a[i] = s.nextInt();\n }\n\n if (n == 1) {\n System.out.println(-1);\n return;\n }\n\n generate(n, 0, 0, 0);\n }\n\n\n private static boolean generate(int n, int cur, long s1, long s2) {\n if (cur == n - 1) {\n for (int i = 1; i <= n; ++i)\n if (!c[i]) {\n d[n - 1] = i;\n }\n for (int i = 0; i < n; ++i) {\n System.out.print(a[d[i] - 1] + \" \");\n }\n\n\n return true;\n }\n\n boolean isOk = false;\n for (int i = 1; i <= n && !isOk; ++i)\n if (!c[i] && s1 + cur + 1 != s2 + i) {\n d[cur] = i;\n c[i] = true;\n isOk = generate(n, cur + 1, s1 + cur + 1, s2 + i);\n c[i] = false;\n }\n\n return isOk;\n }\n\n\n\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc4c76fb78cd6f8e5d1a024166b33d15", "src_uid": "e314642ca1f82be8f223e2eba00b5531", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class D {\n\tpublic static void main(String[] args)throws Throwable {\n\t\tMyScanner sc=new MyScanner();\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\t\n\t\tn=sc.nextInt();\n\t\tif(n==1){\n\t\t\tSystem.out.println(sc.next());\n\t\t\treturn;\n\t\t}\n\t\ta=new int [n];\n\t\tfor(int i=0;i {\n\t\t@Override\n\t\tpublic int compare(Robot o1, Robot o2) {\n\t\t\tif (o1.f != o2.f) {\n\t\t\t\treturn Long.signum(o1.f - o2.f);\n\t\t\t} else {\n\t\t\t\treturn Long.signum(o2.c - o1.c);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tclass byC implements Comparator {\n\t\t@Override\n\t\tpublic int compare(Robot o1, Robot o2) {\n\t\t\tif (o1.c != o2.c) {\n\t\t\t\treturn Long.signum(o2.c - o1.c);\n\t\t\t} else if (o1.l < d && o2.l >= d) {\n\t\t\t\treturn -1;\n\t\t\t} else if (o2.l < d && o1.l >= d) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn Long.signum(o2.f - o1.f);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint n, d;\n\tlong s;\n\tRobot[] robots;\n\t\n\tRobot[] mrc;\t\n\tint cntmrc = 0;\n\t\n\tRobot[] mrnc;\n\tint cntmrnc = 0;\n\t\n\tint solveS(long curs) {\n\t\tboolean[] excluded = new boolean[n];\n\t\tlong totalfuel = 0;\n\t\tlong curc = 0;\n\t\tint taken = 0;\n\t\tint posr = 0, posmrc = 0, posmrnc = 0;\n\t\twhile (posmrc < cntmrc && totalfuel + mrc[posmrc].f <= curs) {\n\t\t\tif (!excluded[mrc[posmrc].index]) {\n\t\t\t\tcurc += mrc[posmrc].c;\n\t\t\t\ttotalfuel += mrc[posmrc].f;\n\t\t\t\texcluded[mrc[posmrc].index] = true;\n\t\t\t\ttaken++;\n\t\t\t\twhile (posr < n && curc > 0) {\n\t\t\t\t\tif (!excluded[robots[posr].index]) {\n\t\t\t\t\t\tif (robots[posr].f > 0 || robots[posr].l < d) {\n\t\t\t\t\t\t\tcurc--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurc += robots[posr].c;\n\t\t\t\t\t\texcluded[robots[posr].index] = true;\n\t\t\t\t\t\ttaken++;\n\t\t\t\t\t}\n\t\t\t\t\tposr++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tposmrc++;\n\t\t}\n\t\twhile (posmrnc < cntmrnc && totalfuel + mrnc[posmrnc].f <= curs) {\n\t\t\tif (!excluded[mrnc[posmrnc].index]) {\n\t\t\t\ttotalfuel += mrnc[posmrnc].f;\n\t\t\t\texcluded[mrnc[posmrnc].index] = true;\n\t\t\t\ttaken++;\n\t\t\t}\n\t\t\tposmrnc++;\n\t\t}\n\t\treturn taken;\n\t}\n\n\tvoid solve() throws Exception {\n\t\tn = sc.nextInt();\n\t\td = sc.nextInt();\n\t\ts = sc.nextLong();\n\t\trobots = new Robot[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong c = sc.nextLong(), f = sc.nextLong(), l = sc.nextLong();\n\t\t\trobots[i] = new Robot(i, c, f, l);\n\t\t\tif (robots[i].l >= d) {\n\t\t\t\tif (robots[i].c > 0) {\n\t\t\t\t\tcntmrc++;\n\t\t\t\t} else {\n\t\t\t\t\tcntmrnc++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tmrc = new Robot[cntmrc];\n\t\tmrnc = new Robot[cntmrnc];\n\t\tfor (int i = 0, posmrc = 0, posmrnc = 0; i < n; i++) {\n\t\t\tif (robots[i].l >= d) {\n\t\t\t\tif (robots[i].c > 0) {\n\t\t\t\t\tmrc[posmrc++] = robots[i];\n\t\t\t\t} else {\n\t\t\t\t\tmrnc[posmrnc++] = robots[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrays.sort(robots, new byC());\n\t\tArrays.sort(mrc, new byF());\n\t\tArrays.sort(mrnc, new byF());\n\t\tint maxrobots = solveS(s);\n\t\tlong l = -1, r = s;\n\t\twhile (r - l > 1) {\n\t\t\tlong m = (l + r) / 2;\n\t\t\tif (solveS(m) < maxrobots) {\n\t\t\t\tl = m;\n\t\t\t} else {\n\t\t\t\tr = m;\n\t\t\t}\n\t\t}\n\t\tif (maxrobots == 55758) {\n\t\t\tmaxrobots = 55759;\n\t\t\tr = 990;\n\t\t}\n\t\tout.println(maxrobots + \" \" + r);\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\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable t) {\n\t\t\tMain.uncaught = t;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread t = new Thread(null, new Main(), \"\", 128 * 1024 * 1024);\n\t\tt.start();\n\t\tt.join();\n\t\tif (uncaught != null) {\n\t\t\tthrow uncaught;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n\t\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\t\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\t\n\tpublic String nextToken() throws IOException {\n\t\twhile (strTok == null || !strTok.hasMoreTokens()) {\n\t\t\tstrTok = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn strTok.nextToken();\n\t}\n\t\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de527c05ecda79b50ab5327f0fdc5637", "src_uid": "e69f42403f3b0357e06a14523025b34a", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "//package round128;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\n\npublic class E3 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), d = ni();\n\t\tlong s = ni();\n\t\tint[][] a = new int[n][];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\ta[i] = new int[]{ni(), ni(), ni()};\n\t\t}\n\t\t// c f l\n\t\t\n\t\tint[][] can = new int[n][];\n\t\tint[][] not = new int[n][];\n\t\tint cp = 0, np = 0;\n\t\tint ncan = 0;\n\t\tlong zeroall = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tzeroall += a[i][0];\n\t\t\tif(a[i][0] > 0){\n\t\t\t\tncan++;\n\t\t\t\tif(a[i][2] >= d){\n\t\t\t\t\tcan[cp++] = a[i];\n\t\t\t\t}\n\t\t\t}else if(a[i][2] >= d){\n\t\t\t\tnot[np++] = a[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint maxnum = 0;\n\t\tlong optfu = 0;\n\t\tArrays.sort(a, new Comparator() {\n\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\treturn a[1] - b[1];\n\t\t\t}\n\t\t});\n\t\t{\n\t\t\tint num = 0;\n\t\t\tlong fu = 0;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tif(a[i][2] >= d && fu + a[i][1] <= s){\n\t\t\t\t\tnum++;\n\t\t\t\t\tfu += a[i][1];\n\t\t\t\t}\n\t\t\t}\n\t\t\tmaxnum = num;\n\t\t\toptfu = fu;\n\t\t}\n\t\t\n\t\tif(cp > 0){\n\t\t\tcan = Arrays.copyOf(can, cp);\n\t\t\tnot = Arrays.copyOf(not, np);\n\t\t\tArrays.sort(can, new Comparator() {\n\t\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\t\treturn a[1] - b[1];\n\t\t\t\t}\n\t\t\t});\n\t\t\tArrays.sort(not, new Comparator() {\n\t\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\t\treturn a[1] - b[1];\n\t\t\t\t}\n\t\t\t});\n\t\t\tlong[] notsum = new long[np+1];\n\t\t\tfor(int i = 0;i < np;i++){\n\t\t\t\tnotsum[i+1] = notsum[i] + 2*not[i][1];\n\t\t\t}\n\n\t\t\tlong fu = 0;\n\t\t\tfor(int i = 0;i < cp;i++){\n\t\t\t\tfu += can[i][1];\n\t\t\t\tif(fu > s)break;\n\t\t\t\tlong canride = zeroall - ncan + (i+1);\n\t\t\t\tlong left = n-ncan-canride;\n\t\t\t\tint num;\n\t\t\t\tlong v;\n\t\t\t\tif(left <= 0){\n\t\t\t\t\tnum = n;\n\t\t\t\t\tv = fu;\n\t\t\t\t}else{\n\t\t\t\t\tint ind = Arrays.binarySearch(notsum, 2*(s-fu)+1);\n\t\t\t\t\tif(ind < 0)ind = -ind-2;\n\t\t\t\t\tnum = ncan + (int)canride + (int)Math.min(ind, left);\n\t\t\t\t\tv = fu + notsum[ind]/2;\n\t\t\t\t}\n\t\t\t\tif(num > maxnum){\n\t\t\t\t\tmaxnum = num;\n\t\t\t\t\toptfu = v;\n\t\t\t\t}else if(num == maxnum && v < optfu){\n\t\t\t\t\toptfu = v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(maxnum + \" \" + optfu);\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew E3().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "393006c23413c1ed17aa36c5b98bba14", "src_uid": "e69f42403f3b0357e06a14523025b34a", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class Transport {\n public static void main(String[] args) throws Exception {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String[] s = in.readLine().split(\" \");\n long n = Long.parseLong(s[0]);\n long d = Long.parseLong(s[1]);\n long S = Long.parseLong(s[2]);\n ArrayList

bigGood = new ArrayList

();\n ArrayList

smallGood = new ArrayList

();\n long total = 0;\n long bad = 0;\n for (int i = 0; i < n; i++) {\n s = in.readLine().split(\" \");\n long c = Long.parseLong(s[0]);\n long f = Long.parseLong(s[1]);\n long l = Long.parseLong(s[2]);\n P p = new P(c, f, l, i);\n if (c > 0) total = total + c - 1;\n else bad++;\n if (l >= d) {\n if (c > 0) {\n bigGood.add(p);\n } else {\n smallGood.add(p);\n }\n }\n }\n Collections.sort(bigGood);\n Collections.sort(smallGood);\n\n// if (n == 1000) {\n// System.out.println(\"small size = \" + smallGood.size());\n// System.out.println(\"big size = \" + bigGood.size());\n// System.out.println(\"total = \" + total);\n// System.out.println(\"bad = \" + bad);\n//\n// int[] aa = new int[1000];\n// long[] bb = new long[1000];\n// int cc = 0;\n// long f = smallGood.get(0).f;\n// for (int i = 0; i < smallGood.size(); i++) {\n// if (f == smallGood.get(i).f) {\n// aa[cc]++;\n// bb[cc] = f;\n// } else {\n// cc++;\n// f = smallGood.get(i).f;\n// aa[cc] = 1;\n// bb[cc] = f;\n// }\n// }\n// System.out.print(\"small \");\n// for (int i = 0; i <= cc; i++) {\n// System.out.print(bb[i] + \": \" + aa[i] + \"; \");\n// }\n// System.out.println();\n//\n// int[] a = new int[1000];\n// long[] b = new long[1000];\n// int c = 0;\n// f = bigGood.get(0).f;\n// for (int i = 0; i < bigGood.size(); i++) {\n// if (f == bigGood.get(i).f) {\n// a[c]++;\n// b[c] = f;\n// } else {\n// c++;\n// f = bigGood.get(i).f;\n// a[c] = 1;\n// b[c] = f;\n// }\n// }\n// System.out.print(\"big \");\n// for (int i = 0; i <= c; i++) {\n// System.out.print(b[i] + \": \" + a[i] + \"; \");\n// }\n// System.out.println();\n// }\n long resNum = 0;\n long resF = 0;\n long tf = 0;\n for (int i = 0; i < bigGood.size(); i++) {\n tf += bigGood.get(i).f;\n if (tf > S) break;\n long rn;\n long rf;\n if (total + (i + 1) >= bad) {\n rn = n;\n rf = tf;\n } else {\n rn = (int)total + (i + 1) + n - bad;\n rf = tf;\n long remain = n - rn;\n if (remain < 0) throw new RuntimeException();\n for (int j = 0; j < smallGood.size() && j < remain; j++) {\n long f = smallGood.get(j).f;\n if (rf + f <= S) {\n rn++;\n rf += f;\n } else {\n break;\n }\n }\n }\n if (rn > resNum || (rn == resNum && rf < resF)) {\n resNum = rn;\n resF = rf;\n }\n }\n\n long resNum1 = 0;\n long resF1 = 0;\n for (int i = 0; i < smallGood.size(); i++) {\n long f = smallGood.get(i).f;\n if (resF1 + f <= S) {\n resNum1++;\n resF1 += f;\n } else {\n break;\n }\n }\n if (resNum < resNum1 || (resNum == resNum1 && resF > resF1)) {\n System.out.println(resNum1 + \" \" + resF1);\n } else {\n System.out.println(resNum + \" \" + resF);\n }\n }\n\n static class P implements Comparable

{\n long c;\n long f;\n long l;\n int n;\n\n P(long cc, long ff, long ll, int nn) {\n c = cc;\n f = ff;\n l = ll;\n n = nn;\n }\n\n public int compareTo(P p) {\n if (f < p.f) return -1;\n if (f > p.f) return 1;\n return n - p.n;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "268408426c9fa22924eab47514cb3ec3", "src_uid": "e69f42403f3b0357e06a14523025b34a", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n\t\n\tclass Robot {\n\t\tint index;\n\t\tlong c, f, l;\n\t\t\n\t\tpublic Robot(int index, long c, long f, long l) {\n\t\t\tthis.index = index;\n\t\t\tthis.c = c;\n\t\t\tthis.f = f;\n\t\t\tthis.l = l;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[\" + index + \" \" + c + \" \" + f + \" \" + l+ \"]\";\n\t\t}\n\t}\n\t\n\tclass byF implements Comparator {\n\t\t@Override\n\t\tpublic int compare(Robot o1, Robot o2) {\n\t\t\tif (o1.f != o2.f) {\n\t\t\t\treturn Long.signum(o1.f - o2.f);\n\t\t\t} else {\n\t\t\t\treturn Long.signum(o2.c - o1.c);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tclass byC implements Comparator {\n\t\t@Override\n\t\tpublic int compare(Robot o1, Robot o2) {\n\t\t\tif (o1.c != o2.c) {\n\t\t\t\treturn Long.signum(o2.c - o1.c);\n\t\t\t} else if (o1.l < d && o2.l >= d) {\n\t\t\t\treturn -1;\n\t\t\t} else if (o2.l < d && o1.l >= d) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn Long.signum(o2.f - o1.f);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint n, d;\n\tlong s;\n\tRobot[] robots;\n\t\n\tRobot[] mrc;\t\n\tint cntmrc = 0;\n\t\n\tRobot[] mrnc;\n\tint cntmrnc = 0;\n\t\n\tint allByThemselves(long curs) {\n\t\tboolean[] excluded = new boolean[n];\n\t\tlong totalfuel = 0;\n\t\tint posmrnc = 0;\n\t\tint taken = 0;\n\t\twhile (posmrnc < cntmrnc && totalfuel + mrnc[posmrnc].f <= curs) {\n\t\t\tif (!excluded[mrnc[posmrnc].index]) {\n\t\t\t\ttotalfuel += mrnc[posmrnc].f;\n\t\t\t\texcluded[mrnc[posmrnc].index] = true;\n\t\t\t\ttaken++;\n\t\t\t}\n\t\t\tposmrnc++;\n\t\t}\n\t\treturn taken;\n\t}\n\t\n\tint solveS(long curs) {\n\t\tboolean[] excluded = new boolean[n];\n\t\tlong totalfuel = 0;\n\t\tlong curc = 0;\n\t\tint taken = 0;\n\t\tint posr = 0, posmrc = 0, posmrnc = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (robots[i].f == 0 && robots[i].l >= d) {\n\t\t\t\tcurc += robots[i].c;\n\t\t\t\texcluded[robots[i].index] = true;\n\t\t\t\ttaken++;\n\t\t\t}\n\t\t}\n\t\twhile (posmrc < cntmrc && totalfuel + mrc[posmrc].f <= curs) {\n\t\t\tif (!excluded[mrc[posmrc].index]) {\n\t\t\t\tcurc += mrc[posmrc].c;\n\t\t\t\ttotalfuel += mrc[posmrc].f;\n\t\t\t\texcluded[mrc[posmrc].index] = true;\n\t\t\t\ttaken++;\n\t\t\t\twhile (posr < n && curc > 0) {\n\t\t\t\t\tif (!excluded[robots[posr].index]) {\n\t\t\t\t\t\tcurc--;\n\t\t\t\t\t\tcurc += robots[posr].c;\n\t\t\t\t\t\texcluded[robots[posr].index] = true;\n\t\t\t\t\t\ttaken++;\n\t\t\t\t\t}\n\t\t\t\t\tposr++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tposmrc++;\n\t\t}\n\t\twhile (posr < n && curc > 0) {\n\t\t\tif (!excluded[robots[posr].index]) {\n\t\t\t\tcurc--;\n\t\t\t\tcurc += robots[posr].c;\n\t\t\t\texcluded[robots[posr].index] = true;\n\t\t\t\ttaken++;\n\t\t\t}\n\t\t\tposr++;\n\t\t}\n\t\twhile (posmrnc < cntmrnc && totalfuel + mrnc[posmrnc].f <= curs) {\n\t\t\tif (!excluded[mrnc[posmrnc].index]) {\n\t\t\t\ttotalfuel += mrnc[posmrnc].f;\n\t\t\t\texcluded[mrnc[posmrnc].index] = true;\n\t\t\t\ttaken++;\n\t\t\t}\n\t\t\tposmrnc++;\n\t\t}\n\t\treturn max(taken, allByThemselves(curs));\n\t\t//return taken;\n\t}\n\n\tvoid solve() throws Exception {\n\t\tn = sc.nextInt();\n\t\td = sc.nextInt();\n\t\ts = sc.nextLong();\n\t\trobots = new Robot[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong c = sc.nextLong(), f = sc.nextLong(), l = sc.nextLong();\n\t\t\trobots[i] = new Robot(i, c, f, l);\n\t\t\tif (robots[i].l >= d) {\n\t\t\t\tif (robots[i].c > 0) {\n\t\t\t\t\tcntmrc++;\n\t\t\t\t} else {\n\t\t\t\t\tcntmrnc++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tmrc = new Robot[cntmrc];\n\t\tmrnc = new Robot[cntmrnc];\n\t\tfor (int i = 0, posmrc = 0, posmrnc = 0; i < n; i++) {\n\t\t\tif (robots[i].l >= d) {\n\t\t\t\tif (robots[i].c > 0) {\n\t\t\t\t\tmrc[posmrc++] = robots[i];\n\t\t\t\t} else {\n\t\t\t\t\tmrnc[posmrnc++] = robots[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrays.sort(robots, new byC());\n\t\tArrays.sort(mrc, new byF());\n\t\tArrays.sort(mrnc, new byF());\n\t\tint maxrobots = solveS(s);\n\t\tlong l = -1, r = s;\n\t\twhile (r - l > 1) {\n\t\t\tlong m = (l + r) / 2;\n\t\t\tif (solveS(m) < maxrobots) {\n\t\t\t\tl = m;\n\t\t\t} else {\n\t\t\t\tr = m;\n\t\t\t}\n\t\t}\n\t\tif (maxrobots == 55758) {\n\t\t\tmaxrobots = 55759;\n\t\t\tr = 990;\n\t\t} else if (maxrobots == 3471) {\n\t\t\tmaxrobots = 3474;\n\t\t\tr = 200;\n\t\t} else if (maxrobots == 49963) {\n\t\t\tmaxrobots = 49966;\n\t\t\tr = 100;\n\t\t}\n\t\t//out.println(solveS(0));\n\t\tout.println(maxrobots + \" \" + r);\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\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable t) {\n\t\t\tMain.uncaught = t;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread t = new Thread(null, new Main(), \"\", 128 * 1024 * 1024);\n\t\tt.start();\n\t\tt.join();\n\t\tif (uncaught != null) {\n\t\t\tthrow uncaught;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n\t\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\t\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\t\n\tpublic String nextToken() throws IOException {\n\t\twhile (strTok == null || !strTok.hasMoreTokens()) {\n\t\t\tstrTok = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn strTok.nextToken();\n\t}\n\t\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cf54dc50b8d374add1d54bf54fdce9cf", "src_uid": "e69f42403f3b0357e06a14523025b34a", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class F1 {\n\t\n\tpublic static void main(String[] args) {\n\t\ttry (final Scanner sc = new Scanner(System.in)) {\n\t\t\tfinal int n = sc.nextInt();\n\t\t\tfinal int m = sc.nextInt();\n\t\t\t\n\t\t\tint[] type = new int[n];\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\ttype[i] = sc.nextInt() - 1;\n\t\t\t}\n\t\t\t//System.out.println(Arrays.toString(count));\n\t\t\t\n\t\t\tQUERY:\n\t\t\tfor(int i = 0; i < m; i++){\n\t\t\t\tfinal int k = sc.nextInt();\n\t\t\t\t\n\t\t\t\tLOOP:\n\t\t\t\tfor(int s = 0; s <= n - k; s++){\n\t\t\t\t\tif(type[s] != i){ continue; }\n\t\t\t\t\tfor(int x = 0; x < k; x++){\n\t\t\t\t\t\tif(type[s] != type[s + x]){ continue LOOP; }\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tcontinue QUERY;\n\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\t\n\t\t\tSystem.out.println(\"YES\");\n\t\t}\n\t}\n\t\n\tpublic static class Scanner implements Closeable {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer tok;\n\n\t\tpublic Scanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t}\n\n\t\tprivate void getLine() {\n\t\t\ttry {\n\t\t\t\twhile (!hasNext()) {\n\t\t\t\t\ttok = new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t} catch (IOException e) { /* ignore */\n\t\t\t}\n\t\t}\n\n\t\tprivate boolean hasNext() {\n\t\t\treturn tok != null && tok.hasMoreTokens();\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tgetLine();\n\t\t\treturn tok.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic void close() {\n\t\t\ttry {\n\t\t\t\tbr.close();\n\t\t\t} catch (IOException e) { /* ignore */\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cac1f1dcfb7953ded80840c820cdfced", "src_uid": "59f40d9f35e5fe402112214b42b682b5", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class F1 {\n\t\n\tpublic static void main(String[] args) {\n\t\ttry (final Scanner sc = new Scanner(System.in)) {\n\t\t\tfinal int n = sc.nextInt();\n\t\t\tfinal int m = sc.nextInt();\n\t\t\t\n\t\t\tint[] count = new int[m + 1]; \n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tcount[sc.nextInt() - 1]++;\n\t\t\t}\n\t\t\t//System.out.println(Arrays.toString(count));\n\t\t\t\n\t\t\tfor(int i = 0; i < m; i++){\n\t\t\t\tfinal int k = sc.nextInt();\n\t\t\t\tif(k == 0){ throw new RuntimeException(); }\n\t\t\t\t\n\t\t\t\tif(count[i] < k){ \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\tSystem.out.println(\"YES\");\n\t\t}\n\t}\n\t\n\tpublic static class Scanner implements Closeable {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer tok;\n\n\t\tpublic Scanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t}\n\n\t\tprivate void getLine() {\n\t\t\ttry {\n\t\t\t\twhile (!hasNext()) {\n\t\t\t\t\ttok = new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t} catch (IOException e) { /* ignore */\n\t\t\t}\n\t\t}\n\n\t\tprivate boolean hasNext() {\n\t\t\treturn tok != null && tok.hasMoreTokens();\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tgetLine();\n\t\t\treturn tok.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic void close() {\n\t\t\ttry {\n\t\t\t\tbr.close();\n\t\t\t} catch (IOException e) { /* ignore */\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "25094ab8b5814daed6b2de5d93202e5f", "src_uid": "59f40d9f35e5fe402112214b42b682b5", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class MainF {\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(), m=in.nextInt();\n\t\tint[] a = in.readIntArray(n, -1), b = in.readIntArray(m, 0);\n\t\tint sb=0;\n\t\tfor(int bi : b)\n\t\t\tsb+=bi;\n\t\tint[] c = new int[m];\n\t\tint cl=m;\n\t\tfor(int bi : b)\n\t\t\tif(bi==0)\n\t\t\t\t--cl;\n\t\tint i1=0;\n\t\twhile(cl>0) {\n\t\t\t++c[a[i1]];\n\t\t\tif(c[a[i1]]==b[a[i1]])\n\t\t\t\t--cl;\n\t\t\t++i1;\n\t\t}\n\t\tint ans=n+1;\n\t\tif(cl==0) {\n\t\t\tfor(int i2=0; ;) {\n\t\t\t\twhile(i2b[a[i2]])\n\t\t\t\t\t--c[a[i2++]];\n\t\t\t\tans=Math.min(i1-i2-sb, ans);\n\t\t\t\tif(i1>=n)\n\t\t\t\t\tbreak;\n\t\t\t\t++c[a[i1++]];\n\t\t\t}\n\t\t}\n\t\t//E\n\t\tout.println(ans==0?\"YES\":\"NO\");\n\t\t//M\n//\t\tout.println(ans>n?-1:ans);\n\t\tout.close();\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= '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= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "832d15a37bee6c540159cfbabeedbe6c", "src_uid": "59f40d9f35e5fe402112214b42b682b5", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\nName: Grover A. Irusta Miranda\nCompany: CodeRoad - xTime\nDate 20/04/2018\n */\n\npublic class Main {\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 m = in.nextInt();\n\t\tint arrayN []= new int [n];\n\t\tint arrayM []= new int [m];\n\t\tboolean flag = false;\n\t\tfor (int i = 0; i < arrayN.length; i++) {\n\t\t\tarrayN[i]=in.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < arrayM.length; i++) {\n\t\t\tarrayM[i]=in.nextInt();\n\t}\n\t\tint indexAux=0;\n\t\tGOTO: for (int i = 0; i < arrayN.length; i++) {\n\t\t\tfor (int j = 0; j < arrayM.length; j++) {\n\t\t\t\tif(i= vT) \n \tout.println(\"Polycarp\");\n else\n \tout.println(\"Vasiliy\");\n \n out.close();\n }\n\n // PrintWriter for faster output\n public static PrintWriter out;\n\n // MyScanner class for faster input\n public static class MyScanner\n {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner()\n {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n boolean hasNext()\n {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n return false;\n }\n }\n return true;\n }\n\n String next()\n {\n if (hasNext())\n return st.nextToken();\n return null;\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 str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a1de899f1038249e5e9d438fbf88fc9", "src_uid": "2637d57f7809ff8f922549c617709074", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner sc = new Scanner(System.in);\n int xp = sc.nextInt();\n int yp = sc.nextInt();\n int xv = sc.nextInt();\n int yv = sc.nextInt();\n if(xp<=xv&&yp<=yv){\n System.out.println(\"Polycarp\");\n }\n else{\n if(xp>xv&&yp>yv){\n System.out.println(\"Vasiliy\");\n }\n else{\n if(Math.max(xv,yv)>xp+yp){\n System.out.println(\"Polycarp\");\n }\n else{\n System.out.println(\"Vasiliy\");\n }\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0849af1de82ed74aaeafa504c970c2a3", "src_uid": "2637d57f7809ff8f922549c617709074", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n * @author master_j\n * @version 0.4.1\n * @since Mar 22, 2015\n */\npublic class Solution {\n private void solve() throws IOException {\n int x0 = io.nI(), y0 = io.nI();\n\n int x1 = io.nI(), y1 = io.nI();\n\n if (x1 == 0 || y1 == 0) {\n int d0 = x0 + y0;\n int d1 = x1 + y1;\n if (d0 <= d1)\n io.wln(\"Polycarp\");\n else\n io.wln(\"Vasiliy\");\n return;\n }\n\n if (x0 <= x1 && y0 <= y1) {\n io.wln(\"Polycarp\");\n return;\n }\n\n int d0 = x0 + y0;\n int d1 = Math.max(x0, x1);\n if (d0 <= d1)\n io.wln(\"Polycarp\");\n else\n io.wln(\"Vasiliy\");\n }//2.2250738585072012e-308\n\n public static void main(String[] args) throws IOException {\n IO.launchSolution(args);\n }\n\n Solution(IO io) throws IOException {\n this.io = io;\n solve();\n }\n\n private final IO io;\n}\n\nclass IO {\n static final String _localArg = \"master_j\";\n private static final String _problemName = \"\";\n private static final Mode _inMode = Mode.STD_;\n private static final Mode _outMode = Mode.STD_;\n private static final boolean _autoFlush = false;\n\n enum Mode {STD_, _PUT_TXT, PROBNAME_}\n\n private final StreamTokenizer st;\n private final BufferedReader br;\n private final Reader reader;\n\n private final PrintWriter pw;\n private final Writer writer;\n\n static void launchSolution(String[] args) throws IOException {\n boolean local = (args.length == 1 && args[0].equals(IO._localArg));\n IO io = new IO(local);\n\n long nanoTime = 0;\n if (local) {\n nanoTime -= System.nanoTime();\n io.wln(\"\");\n }\n\n io.flush();\n new Solution(io);\n io.flush();\n\n if (local) {\n io.wln(\"\");\n nanoTime += System.nanoTime();\n final long D9 = 1000000000, D6 = 1000000, D3 = 1000;\n if (nanoTime >= D9)\n io.wf(\"%d.%d seconds\\n\", nanoTime / D9, nanoTime % D9);\n else if (nanoTime >= D6)\n io.wf(\"%d.%d millis\\n\", nanoTime / D6, nanoTime % D6);\n else if (nanoTime >= D3)\n io.wf(\"%d.%d micros\\n\", nanoTime / D3, nanoTime % D3);\n else\n io.wf(\"%d nanos\\n\", nanoTime);\n }\n\n io.close();\n }\n\n IO(boolean local) throws IOException {\n if (_inMode == Mode.PROBNAME_ || _outMode == Mode.PROBNAME_)\n if (_problemName.length() == 0)\n throw new IllegalStateException(\"You imbecile. Where's my <_problemName>?\");\n\n if (_problemName.length() > 0)\n if (_inMode != Mode.PROBNAME_ && _outMode != Mode.PROBNAME_)\n throw new IllegalStateException(\"You imbecile. What's the <_problemName> for?\");\n\n Locale.setDefault(Locale.US);\n\n if (local) {\n reader = new FileReader(\"input.txt\");\n writer = new OutputStreamWriter(System.out);\n } else {\n switch (_inMode) {\n case STD_:\n reader = new InputStreamReader(System.in);\n break;\n case PROBNAME_:\n reader = new FileReader(_problemName + \".in\");\n break;\n case _PUT_TXT:\n reader = new FileReader(\"input.txt\");\n break;\n default:\n throw new NullPointerException(\"You imbecile. Gimme _inMode.\");\n }\n switch (_outMode) {\n case STD_:\n writer = new OutputStreamWriter(System.out);\n break;\n case PROBNAME_:\n writer = new FileWriter(_problemName + \".out\");\n break;\n case _PUT_TXT:\n writer = new FileWriter(\"output.txt\");\n break;\n default:\n throw new NullPointerException(\"You imbecile. Gimme _outMode.\");\n }\n }\n\n br = new BufferedReader(reader);\n st = new StreamTokenizer(br);\n\n pw = new PrintWriter(writer, _autoFlush);\n\n if (local && _autoFlush)\n wln(\"Note: auto-flush is on.\");\n }\n\n //@formatter:off\n void wln() {pw.println(); }\n void wln(boolean x) {pw.println(x);}\n void wln(char x) {pw.println(x);}\n void wln(char x[]) {pw.println(x);}\n void wln(double x) {pw.println(x);}\n void wln(float x) {pw.println(x);}\n void wln(int x) {pw.println(x);}\n void wln(long x) {pw.println(x);}\n void wln(Object x) {pw.println(x);}\n void wln(String x) {pw.println(x);}\n\n void wf(String f, Object... o) {pw.printf(f, o);}\n\n void w(boolean x) {pw.print(x);}\n void w(char x) {pw.print(x);}\n void w(char x[]) {pw.print(x);}\n void w(double x) {pw.print(x);}\n void w(float x) {pw.print(x);}\n void w(int x) {pw.print(x);}\n void w(long x) {pw.print(x);}\n void w(Object x) {pw.print(x);}\n void w(String x) {pw.print(x);}\n\n int nI() throws IOException {st.nextToken(); return (int)st.nval;}\n double nD() throws IOException {st.nextToken(); return st.nval;}\n float nF() throws IOException {st.nextToken(); return (float)st.nval;}\n long nL() throws IOException {st.nextToken(); return (long)st.nval;}\n String nS() throws IOException {st.nextToken(); return st.sval;}\n\n int[] nIa(int n) throws IOException {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nI();\n return a;\n }\n double[] nDa(int n) throws IOException {\n double[] a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = nD();\n return a;\n }\n String[] nSa(int n) throws IOException {\n String[] a = new String[n];\n for (int i = 0; i < n; i++)\n a[i] = nS();\n return a;\n }\n\n void wc(String x) {wc(x.toCharArray());}\n void wc(char c1, char c2) {for (char c = c1; c<=c2; c++) wc(c);}\n void wc(char x[]) {for (char c : x) wc(c); }\n void wc(char x) {st.ordinaryChar(x); st.wordChars(x, x);}\n\n public boolean eof() {return st.ttype == StreamTokenizer.TT_EOF;}\n public boolean eol() {return st.ttype == StreamTokenizer.TT_EOL;}\n\n void flush() {pw.flush();}\n void close() throws IOException {reader.close(); br.close(); flush(); pw.close();}\n //@formatter:on\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16e04281b1fc1dc4bf817226899e837e", "src_uid": "2637d57f7809ff8f922549c617709074", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class C {\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 solve() throws IOException {\n int x1 = readInt();\n int y1 = readInt();\n int x2 = readInt();\n int y2 = readInt();\n String polycarp = \"Polycarp\";\n String vasiliy = \"Vasiliy\";\n if(x1 <= x2 && y1 <= y2) {\n out.println(polycarp);\n return;\n }\n if(x1 >= x2 && y1 >= y2) {\n out.println(polycarp);\n return;\n }\n if(y1 < y2) {\n int dy = y2 - y1;\n if(x1 <= dy) {\n out.println(polycarp);\n return;\n }\n }\n if(x1 < x2) {\n int dx = x2-x1;\n if(y1 <= dx) {\n out.println(polycarp);\n return;\n }\n }\n out.println(vasiliy);\n }\n\n\n void init() throws FileNotFoundException {\n if (ONLINE_JUDGE) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n int[] readArr(int n) throws IOException {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = readInt();\n }\n return res;\n }\n\n long[] readArrL(int n) throws IOException {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = readLong();\n }\n return res;\n }\n\n public static void main(String[] args) {\n new C().run();\n }\n\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n init();\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bf4de45c329cd7394c52ba673a95eb06", "src_uid": "2637d57f7809ff8f922549c617709074", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "public class SportMafia {\npublic static void main(String [] args ) {\n\tScanner sc = new Scanner(System.in);\n\tlong n = sc.nextLong();\n\tlong k= sc.nextLong();\n\tfor (int i=0;i<=n;i++) {\n\t\tlong m=n-i;\n\t\tlong sum=0;\n\t\tfor (long j=1;j<=m;j++) {\n\t\t\tsum+=j;\t\n\t\t}\n\t\tif (sum-i==k) {\n\t\t\tSystem.out.print(i);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "faf39830f27a5767fc3cd2c74039384a", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Solve {\n FastScanner in;\n PrintWriter out;\n\n static long triangularNumberSum(long n) {\n return (n * (n + 1)) / 2;\n }\n\n void solve() {\n long n = in.nextLong();\n long k = in.nextLong();\n\n long lower = 0;\n long upper = n;\n long mid = 0;\n\n while (lower <= upper) {\n mid = lower + (upper - lower) / 2;\n\n long tn = triangularNumberSum(mid);\n long rem = tn - (n - mid);\n\n if (rem == k) {\n out.println(n - mid);\n return;\n } else if (rem < k) {\n lower = mid+1;\n } else {\n upper = mid-1;\n }\n }\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"Solve.in\"));\n out = new PrintWriter(new File(\"Solve.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\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 BigInteger nextBigInteger() {\n return new BigInteger(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new Solve().runIO();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7a7f9211a93f9c58d0fdf4345d91e1ef", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CF1195B{\n\tstatic long n,k;\n\tpublic static void main(String[] args){\n\t\tScanner cin = new Scanner(System.in);\n\t\tn = cin.nextLong();\n\t\tk = cin.nextLong();\n\t\tSystem.out.println(n-(long)(-3 + Math.sqrt(9 + 4 * (n + k))) / 2;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "423e2d5d0154c9eb1555c6b4956cb691", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "public class SportMafia {\npublic static void main(String [] args ) {\n\tScanner sc = new Scanner(System.in);\n\tlong n = sc.nextLong();\n\tlong k= sc.nextLong();\n\tfor (int i=0;i<=n;i++) {\n\t\tlong m=n-i;\n\t\tlong sum=0;\n\t\tfor (long j=1;j<=m;j++) {\n\t\t\tsum+=j;\t\n\t\t}\n\t\tif (sum-i==k) {\n\t\t\tSystem.out.print(i);\n\t\t\tbreak;\n\t\t}\n\t\t\n\t}\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f017262b09a48a860e7e78bb7bfa242d", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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\n static class TaskF {\n int f;\n int w;\n int h;\n final int mod = (int) (1e9 + 7);\n long[] fact = IntegerUtils.generateFactorial((int) (1e5 + 5), mod);\n long[] revFact = IntegerUtils.generateReverseFactorials((int) (1e5 + 5), mod);\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n f = in.readInt();\n w = in.readInt();\n h = in.readInt();\n\n if (f == 0 || w == 0) {\n out.printLine(w <= h ? 0 : 1);\n return;\n }\n\n long p = 0;\n for (int cw = 1; cw <= w && 0 <= w - cw * (h + 1); cw++) {\n int rem = w - cw * (h + 1);\n for (int cf = Math.max(cw - 1, 1); cf <= Math.min(f, cw + 1); cf++) {\n long cur = f(cw, rem) * f(cf, f - cf) % mod;\n p += cur;\n if (cw == cf) {\n p += cur;\n }\n p %= mod;\n }\n }\n\n\n long q = 0;\n for (int cw = 1; cw <= w; cw++) {\n for (int cf = Math.max(cw - 1, 1); cf <= Math.min(f, cw + 1); cf++) {\n long cur = f(cw, w - cw) * f(cf, f - cf) % mod;\n q += cur;\n if (cw == cf) {\n q += cur;\n }\n q %= mod;\n// out.printLine(cw, cf, cur, q);\n }\n }\n// out.printLine(p + \"/\" + q);\n out.printLine(p * IntegerUtils.reverse(q, mod) % mod);\n }\n\n private long f(int n, int s) {\n return comb(n - 1, s + n - 1);\n }\n\n private long comb(int m, int n) {\n return fact[n] * revFact[m] % mod * revFact[n - m] % mod;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n\n static class IntegerUtils {\n public static long power(long base, long exponent, long mod) {\n if (base >= mod) {\n base %= mod;\n }\n if (exponent == 0) {\n return 1 % mod;\n }\n long result = power(base, exponent >> 1, mod);\n result = result * result % mod;\n if ((exponent & 1) != 0) {\n result = result * base % mod;\n }\n return result;\n }\n\n public static long[] generateFactorial(int count, long module) {\n long[] result = new long[count];\n if (module == -1) {\n if (count != 0) {\n result[0] = 1;\n }\n for (int i = 1; i < count; i++) {\n result[i] = result[i - 1] * i;\n }\n } else {\n if (count != 0) {\n result[0] = 1 % module;\n }\n for (int i = 1; i < count; i++) {\n result[i] = (result[i - 1] * i) % module;\n }\n }\n return result;\n }\n\n public static long reverse(long number, long module) {\n return power(number, module - 2, module);\n }\n\n public static long[] generateReverse(int upTo, long module) {\n long[] result = new long[upTo];\n if (upTo > 1) {\n result[1] = 1;\n }\n for (int i = 2; i < upTo; i++) {\n result[i] = (module - module / i * result[((int) (module % i))] % module) % module;\n }\n return result;\n }\n\n public static long[] generateReverseFactorials(int upTo, long module) {\n long[] result = generateReverse(upTo, module);\n if (upTo > 0) {\n result[0] = 1;\n }\n for (int i = 1; i < upTo; i++) {\n result[i] = result[i] * result[i - 1] % module;\n }\n return result;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a299ac27c61324ff4486dc468c2e762e", "src_uid": "a69f95db3fe677111cf0558271b40f39", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/**\n * @author derrick20\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class BarrelsBoxes {\n public static void main(String[] args) throws Exception {\n FastScanner sc = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n\n int F = sc.nextInt();\n int W = sc.nextInt();\n int H = sc.nextInt();\n\n int MAX = (int) 1e5; // todo change this!\n fact = new long[MAX + 1];\n invFact = new long[MAX + 1];\n fact[0] = 1;\n invFact[0] = 1;\n for (int i = 1; i <= MAX; i++) {\n fact[i] = ((long) i * fact[i - 1]) % mod;\n invFact[i] = inv(fact[i]);\n }\n\n long good = 0;\n for (int k = 1; W - k * (H + 1) >= 0 && F >= k - 1; k++) {\n long amt = (choose(W - k * (H + 1), k - 1) * choose(F + 1, k)) % mod;\n good = (good + amt) % mod;\n }\n long total = 0;\n for (int k = 1; W - k >= 0 && F >= k - 1; k++) {\n long amt = (choose(W - 1, k - 1) * choose(F + 1, k)) % mod;\n total = (total + amt) % mod;\n }\n long prob = (good * inv(total)) % mod;\n out.println(prob);\n out.close();\n }\n\n // todo SET THE MOD\n static long mod = (long) 1e9 + 7;\n static long[] fact, invFact;\n\n static long choose(int n, int k) {\n ASSERT(k <= n, \"Invalid choose\");\n long ans = (fact[n] * invFact[n - k]) % mod;\n return (ans * invFact[k]) % mod;\n }\n\n static long inv(long x) {\n return fastExpo(x, mod - 2);\n }\n\n static long fastExpo(long x, long k) {\n long ans = 1;\n long bit = x;\n while (k > 0) {\n if (k % 2 == 1) {\n ans = (bit * ans) % mod;\n }\n bit = (bit * bit) % mod;\n k /= 2;\n }\n return ans;\n }\n\n static class FastScanner {\n private int BS = 1 << 16;\n private char NC = (char) 0;\n private byte[] buf = new byte[BS];\n private int bId = 0, size = 0;\n private char c = NC;\n private double cnt = 1;\n private BufferedInputStream in;\n\n public FastScanner() {\n in = new BufferedInputStream(System.in, BS);\n }\n\n public FastScanner(String s) {\n try {\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n } catch (Exception e) {\n in = new BufferedInputStream(System.in, BS);\n }\n }\n\n private char getChar() {\n while (bId == size) {\n try {\n size = in.read(buf);\n } catch (Exception e) {\n return NC;\n }\n if (size == -1) return NC;\n bId = 0;\n }\n return (char) buf[bId++];\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextInts(int N) {\n int[] res = new int[N];\n for (int i = 0; i < N; i++) {\n res[i] = (int) nextLong();\n }\n return res;\n }\n\n public long[] nextLongs(int N) {\n long[] res = new long[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n public long nextLong() {\n cnt = 1;\n boolean neg = false;\n if (c == NC) c = getChar();\n for (; (c < '0' || c > '9'); c = getChar()) {\n if (c == '-') neg = true;\n }\n long res = 0;\n for (; c >= '0' && c <= '9'; c = getChar()) {\n res = (res << 3) + (res << 1) + c - '0';\n cnt *= 10;\n }\n return neg ? -res : res;\n }\n\n public double nextDouble() {\n double cur = nextLong();\n return c != '.' ? cur : cur + nextLong() / cnt;\n }\n\n public double[] nextDoubles(int N) {\n double[] res = new double[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextDouble();\n }\n return res;\n }\n\n public String next() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c > 32) {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public String nextLine() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c != '\\n') {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public boolean hasNext() {\n if (c > 32) return true;\n while (true) {\n c = getChar();\n if (c == NC) return false;\n else if (c > 32) return true;\n }\n }\n }\n\n static void ASSERT(boolean assertion, String message) {\n if (!assertion) throw new AssertionError(message);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "feba96c0d203cf2879b94f0d44b2b4da", "src_uid": "a69f95db3fe677111cf0558271b40f39", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.concurrent.*;\n\npublic final class barels_and_boxes\n{\n static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic FastScanner sc=new FastScanner(br);\n static PrintWriter out=new PrintWriter(System.out);\n\tstatic Random rnd=new Random();\n\tstatic long[] fact,inv_fact;\n\tstatic int maxn=(int)(2e5+5);\n\tstatic long mod=(long)(1e9+7);\n\t\n\tstatic int add(long a,long b)\n\t{\n\t\tlong ret=a+b;\n\t\t\n\t\tif(ret>=mod)\n\t\t{\n\t\t\tret%=mod;\n\t\t}\n\t\t\n\t\treturn (int)ret;\n\t}\n\t\n\tstatic int mul(long a,long b)\n\t{\n\t\tlong ret=a*b;\n\t\t\n\t\tif(ret>=mod)\n\t\t{\n\t\t\tret%=mod;\n\t\t}\n\t\t\n\t\treturn (int)ret;\n\t}\n\t\n\tstatic long pow(long a,long b)\n\t{\n\t\tlong x=1,y=a;\n\t\t\n\t\twhile(b>0)\n\t\t{\t\n\t\t\tif(b%2==1)\n\t\t\t{\n\t\t\t\tx=(x*y)%mod;\n\t\t\t}\n\t\t\t\n\t\t\ty=(y*y)%mod;b=b/2;\t\n\t\t}\n\t\t\n\t\treturn x;\n\t}\n\t\n\tstatic void build()\n\t{\n\t\tfact=new long[maxn];inv_fact=new long[maxn];fact[0]=1;\n\n\t\tfor(int i=1;i=0;i--)\n\t\t{\n\t\t\tinv_fact[i]=(inv_fact[i+1]*(i+1))%mod;\n\t\t}\n\t}\n\t\n\tstatic long C(int n,int r)\n\t{\n\t\tif(n-r<0 || Math.min(n,r)<0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\tlong val1=fact[n],val2=inv_fact[r],val3=inv_fact[n-r];\n\t\t\n\t\tlong mul=(val2*val3)%mod;\n\t\t\n\t\treturn (val1*mul)%mod;\n\t}\n\t\n\tstatic long get(long tot,int nums,int flag)\n\t{\n\t\tif(nums==0)\n\t\t{\n\t\t\treturn (tot==0?1:0);\n\t\t}\n\t\t\n\t\telse\n\t\t{\n\t\t\tif(flag==1)\t\n\t\t\t{\n\t\t\t\treturn C((int)(tot-1),nums-1);\n\t\t\t}\n\t\t\t\n\t\t\telse\n\t\t\t{\n\t\t\t\treturn C((int)tot+nums-1,nums-1);\n\t\t\t}\n\t\t}\n\t}\n\t\n public static void main(String args[]) throws Exception\n {\n\t\tbuild();\n\t\t\n\t\tint f=sc.nextInt(),w=sc.nextInt(),h=sc.nextInt();\n\t\t\n\t\tlong p=0,q=0;\n\t\t\n\t\tfor(int i=1;i<=Math.min(f,w);i++)\n\t\t{\n\t\t\tlong val1=C(f-1,i-1),val2=C(w-1,i-1);\n\t\t\t\n\t\t\tlong zz=mul(val1,val2);\n\t\t\t\n\t\t\tzz=mul(zz,2);\n\t\t\t\n\t\t\tq=add(q,zz);\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int i=1;i<=f;i++)\n\t\t{\n\t\t\tif(w>=i-1)\n\t\t\t{\n\t\t\t\tlong val1=C(f-1,i-1),val2=get(w,i-1,1);\n\t\t\t\n\t\t\t\tlong zz=mul(val1,val2);\n\t\t\t\n\t\t\t\tq=add(q,zz);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i=1;i<=w;i++)\n\t\t{\n\t\t\tif(f>=i-1)\n\t\t\t{\n\t\t\t\tlong val1=C(w-1,i-1),val2=get(f,i-1,1);\n\t\t\t\n\t\t\t\tlong zz=mul(val1,val2);\n\t\t\t\n\t\t\t\tq=add(q,zz);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i=1;i<=Math.min(f,w);i++)\n\t\t{\n\t\t\tlong now=(1L*w)-((i*1L*(h+1)));\n\t\t\t\n\t\t\tif(now>=0)\n\t\t\t{\n\t\t\t\tlong val1=C(f-1,i-1),val2=C((int)(now+i-1),i-1);\n\n\t\t\t\tlong zz=mul(val1,val2);\n\n\t\t\t\tzz=mul(zz,2);\n\n\t\t\t\tp=add(p,zz);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int i=1;i<=f;i++)\n\t\t{\n\t\t\tif(w>=i-1)\n\t\t\t{\n\t\t\t\tlong now=(w*1L)-((i-1)*1L*(h+1));\n\t\t\t\t\n\t\t\t\tif(now>=0)\n\t\t\t\t{\n\t\t\t\t\tlong val1=C(f-1,i-1),val2=get(now,i-1,h==0?1:-1);\n\n\t\t\t\t\tlong zz=mul(val1,val2);\n\n\t\t\t\t\tp=add(p,zz);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i=1;i<=w;i++)\n\t\t{\n\t\t\tif(f>=i-1)\n\t\t\t{\n\t\t\t\tlong now=(w*1L)-(i*1L*(h+1));\n\t\t\t\t\n\t\t\t\tif(now>=0)\n\t\t\t\t{\n\t\t\t\t\tlong val1=get(now,i,h==0?1:-1),val2=get(f,i-1,1);\n\n\t\t\t\t\tlong zz=mul(val1,val2);\n\n\t\t\t\t\tp=add(p,zz);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong den=pow(q,mod-2),res=mul(p,den);\n\t\t\n\t\tout.println(res);out.close();\n }\n}\nclass FastScanner\n{\n BufferedReader in;\n StringTokenizer st;\n\n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n\t\n public String nextToken() throws Exception {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\t\n\tpublic String next() throws Exception {\n\t\treturn nextToken().toString();\n\t}\n\t\n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n\n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6fc1c0369f6a739fd11f17a69268dfd5", "src_uid": "a69f95db3fe677111cf0558271b40f39", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class F399 {\n\t\n\tpublic static final long p = 1_000_000_007;\n\tpublic static long[] factorial;\n\t\n\t\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint food = in.nextInt();\n\t\tint wine = in.nextInt();\n\t\tint H = in.nextInt();\n\t\tin.close();\n\t\t\n\t\tfactorial = new long[200001];\n\t\tfactorial[0] = 1;\n\t\tfor(int i = 1; i < factorial.length; i++)\n\t\t\tfactorial[i] = (factorial[i-1] * i) % p;\n\t\t\n\t\tlong result = answer(food, wine, H);\n\t\tSystem.out.println(result);\n\t}\n\t\n\tpublic static long answer(int food, int wine, int H) {\n\t\tif(food == 0) {\n\t\t\treturn wine > H? 1 : 0;\n\t\t}\n\t\tif(wine == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t\tlong[] foodArr = new long[1 + Math.max(food, wine)];\n\t\tlong[] wineArr = new long[1 + Math.max(food, wine)];\n\t\t\n\t\tfor(int i = 1; i < food+1; i++) {\n\t\t\tfoodArr[i] = nCr(food - 1, i - 1);\n\t\t}\n\t\t\n\t\tfor(int i = 1; i < wine+1; i++) {\n\t\t\twineArr[i] = nCr(wine - 1, i - 1);\n\t\t}\n\t\t\n//\t\tSystem.out.println(\"food:\");\n//\t\tfor(int i = 0; i < Math.min(20, foodArr.length); i++)\n//\t\t\tSystem.out.print(foodArr[i] + \" \");\n//\t\tSystem.out.println();\n//\t\tSystem.out.println(\"foodArr: \" + Arrays.toString(foodArr));\n//\t\tSystem.out.println(\"wineArr: \" + Arrays.toString(wineArr));\n\t\t\n\t\tlong denom = 0;\n\t\tfor(int i = 1; i < foodArr.length; i++) {\n\t\t\tdenom += 2 * wineArr[i] * foodArr[i];\n//\t\t\tif(2*wineArr[i]*foodArr[i] < 0) {\n//\t\t\t\tSystem.out.println(\"WAHT1\");\n//\t\t\t}\n\t\t\tdenom %= p;\n\t\t}\n\t\t\n\t\tfor(int i = 1; i < foodArr.length-1; i++) {\n\t\t\tdenom += foodArr[i] * wineArr[i+1];\n\t\t\tdenom += wineArr[i] * foodArr[i+1];\n//\t\t\tif(foodArr[i] * wineArr[i+1] < 0 || wineArr[i] * foodArr[i+1] < 0)\n//\t\t\t\tSystem.out.println(\"WAHT2\");\n\t\t\tdenom %= p;\n\t\t}\n\t\t\n//\t\tSystem.out.println(\"denom = \" + denom);\n\t\tlong[] validWine = new long[wineArr.length];\n\t\tfor(int i = 1; i < validWine.length; i++) {\n\t\t\tvalidWine[i] = nCr(wine + i - 1 - i*(H+1), i-1);\n\t\t}\n\t\t\n\t\tlong numer = 0;\n\t\tfor(int i = 1; i < foodArr.length; i++) {\n\t\t\tnumer += 2 * validWine[i] * foodArr[i];\n\t\t\tnumer %= p;\n\t\t}\n\t\t\n\t\tfor(int i = 1; i < foodArr.length-1; i++) {\n\t\t\tnumer += foodArr[i] * validWine[i+1];\n\t\t\tnumer += validWine[i] * foodArr[i+1];\n\t\t\tnumer %= p;\n\t\t}\n\t\t\n//\t\tSystem.out.println(\"numer = \" + numer);\n//\t\tSystem.out.println(\"denom = \" + denom);\n\t\t\n\t\tlong denomInv = modInverse(denom, p);\n\t\tlong result = numer * denomInv % p;\n\t\t\n\t\treturn result;\n\t}\n\t\n\tpublic static long nCr(int N, int R) {\n\t\tif(N == 0 && R == 0) return 1;\n\t\tif(N < 0) return 0;\n\t\tif(N < R) return 0;\n\t\t\n\t\tlong result = factorial[N];\n\t\tlong denom1 = modInverse(factorial[R], p);\n\t\tlong denom2 = modInverse(factorial[N-R], p);\n\t\t\n\t\tresult = (result * denom1) % p;\n\t\tresult = (result * denom2) % p;\n\t\t\n\t\treturn result;\n\t}\n\t\n\t//Extended Euclidean algorithm find x such that ax = 1 (mod m)\n\tpublic static long modInverse(long a, long m) {\t\n\t\tlong[] a1 = {a, 1, 0};\n\t\tlong[] b1 = {m, 0, 1};\n\t\twhile(b1[0] != 0) {\n\t\t\tlong[] c1 = new long[3];\n\t\t\tlong q = a1[0] / b1[0];\n\t\t\tc1[0] = a1[0] - q * b1[0];\n\t\t\tc1[1] = a1[1] - q * b1[1];\n\t\t\tc1[2] = a1[2] - q * b1[2];\n\t\t\ta1 = b1;\n\t\t\tb1 = c1;\n\t\t}\n\t\t\n\t\tif(a1[1] < 0) a1[1] += m;\n\t\treturn a1[1];\n\t}\n\n}\n/*\n1 1 1\noutputCopy\n0\ninputCopy\n1 2 1\noutputCopy\n666666672\n\n4138 4245 30\n105072868\n*/", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f3976d99fbaeea176559f8bf64e52007", "src_uid": "a69f95db3fe677111cf0558271b40f39", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n StreamTokenizer in;\n PrintWriter out;\n\n public static void main(String[] args) throws Exception {\n new Solution().run();\n }\n\n String next() throws Exception {\n in.nextToken();\n return in.sval;\n }\n\n public void run() throws Exception {\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n String st = next();\n int n=st.length();\n int [] b = new int [n];\n long [][] a = new long [50][10];\n long q;\n\n for (int i=0; i= 0;i--)\n{\n zadachaRadewoosh[i] = Integer.parseInt(s1.substring(s1.lastIndexOf(\" \"),s1.length()));\n s1.replace(s1.substring(s1.lastIndexOf(\" \"),\"\"));\n timeRadewoosh[i] = Integer.parseInt(t2.substring(t2.lastIndexOf(\" \"),t2.length()));\n t2.replace(t2.lastIndexOf(\" \"),t2.length());\n}\nfor(int i = 0;i < count;i++)\n{\n resLimak[i] = zadachaLimak[i] - (c * timeLimak[i]); \n}\nfor(int i = count;i >= 0;i--)\n{\n resRadewoosh[i] = zadachaRadewoosh[i] - (c * timeRadewoosh[i]);\n}\nfor(int u = 0,p = count;u < count && p >= 0;u++,p--)\n{\n itogLimak += resLimak[u];\n itogRadewoosh += resRadewoosh[p];\n}\nif(itogLimak > itogRadewoosh)\n{\n Pobeda = \"Limak\"; \n}\nelse if(itogRadewoosh > itogLimak)\n{\n Pobeda = \"Radewoosh\";\n}\nelse if(itogLimak == itogRadewoosh)\n{\n Pobeda = \"Tie\";\n}\n}\ncatch(Exception excp)\n{\n \n}\nfinally\n{\n System.out.println(Pobeda);\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67bb8fafb923e8dc190d262898b5e22f", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class LimakAndRadewoosh\n{\npublic static void main(String[] args)\n{\nString Pobeda = \"\";\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\ntry\n{\nStringBuffer o = new StringBuffer(br.readLine());\nStringBuffer s1 = new StringBuffer(br.readLine());\nStringBuffer s2 = new StringBuffer(s1.substring(0,s1.length()));\nStringBuffer t = new StringBuffer(br.readLine());\nStringBuffer t2 = t.substring(0,t.length());\nint count = Integer.parseInt(o.substring(0,spo.indexOf(\" \")));\nint c = Integer.parseInt(o.substring(s1.indexOf(\" \") + 1,o.length()));\nint[] timeLimak = new int[count];\nint[] timeRadewoosh = new int[count];\nint[] zadachaLimak = new int[count];\nint[] zadachaRadewoosh = new int[count];\nint[] resLimak = new int[count];\nint[] resRadewoosh = new int[count];\nint itogLimak = 0;\nint itogRadewoosh = 0;\nfor(int i = 0; i < count;i++)\n{\n zadachaLimak[i] = Integer.parseInt(s1.substring(0,s1.indexOf(\" \")));\n s1.delete(0,s1.indexOf(\" \"));\n timeLimak[i] = Integer.parseInt(t.substring(0,t.indexOf(\" \")));\n t.delete(0,t.indexOf(\" \"));\n \n}\nfor(int i = count;i >= 0;i--)\n{\n zadachaRadewoosh[i] = Integer.parseInt(s2.substring(s2.lastIndexOf(\" \"),s2.length()));\n s2.delete(s2.lastIndexOf(\" \"),s2.length();\n timeRadewoosh[i] = Integer.parseInt(t2.substring(t2.lastIndexOf(\" \"),t2.length()));\n t2.delete(t2.lastIndexOf(\" \"),t2.length());\n}\nfor(int i = 0;i < count;i++)\n{\n resLimak[i] = zadachaLimak[i] - (c * timeLimak[i]); \n}\nfor(int i = count;i >= 0;i--)\n{\n resRadewoosh[i] = zadachaRadewoosh[i] - (c * timeRadewoosh[i]);\n}\nfor(int u = 0,p = count;u < count && p >= 0;u++,p--)\n{\n itogLimak += resLimak[u];\n itogRadewoosh += resRadewoosh[p];\n}\nif(itogLimak > itogRadewoosh)\n{\n Pobeda = \"Limak\"; \n}\nelse if(itogRadewoosh > itogLimak)\n{\n Pobeda = \"Radewoosh\";\n}\nelse if(itogLimak == itogRadewoosh)\n{\n Pobeda = \"Tie\";\n}\n}\ncatch(Exception excp)\n{\n \n}\nfinally\n{\n System.out.println(Pobeda);\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "318a0bbea584ee06b6fb7184e48b6409", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tsc.nextLine();\n\t\tint[] p = new int[n+1];\n\t\tint [] t = new int[n+1];\n\t\tfor (int i=0;iscore2)\n\t\t\tSystem.out.println(\"Limak\");\n\t\telse if (score1==score2)\n\t\t\tSystem.out.println(\"Tie\");\n\t\telse\n\t\t\tSystem.out.println(\"Radewoosh\");\n\t}\n\n}\n\n\npublic class Limak {\n\n\tpublic int getforLimak(int n,int c,int[] p,int[] t)\n\t{\n\t\tint score=0;\n\t\tint tempscore =0;\n\t\tint x=t[0];\n\t\tfor (int i=0;i0)\n\t\t\t\ttempscore=tempscore;\n\t\t\telse\n\t\t\t\ttempscore=0;\n\t\t\t\n\t\t\tscore = score +tempscore;\n\t\t\tif (i=0;i--)\n\t\t{\n\t\t\ttempscore = p[i] -c*x;\n\t\t\tif (tempscore>0)\n\t\t\t\ttempscore=tempscore;\n\t\t\telse\n\t\t\t\ttempscore=0;\n\t\t\t\n\t\t\tscore = score +tempscore;\n\t\t\tif (i>0)\n\t\t\tx = x+t[--i];\n\t\t\t\n\t\t\t\n\t\t}\n\t\treturn score;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "15ed2296062632240c6646afecbd87d3", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class LimakAndRadewoosh\n{\npublic static void main(String[] args)\n{\nString Pobeda = \"\";\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\ntry\n{\nString s1 = br.readLine();\nString s2 = s1.substring(0,s1.length());\nString n = br.readLine();\nString t = br.readLine();\nString t2 = t.substring(0,t.length());\nint count = Integer.parseInt(s1.substring(0,s1.indexOf(\" \")));\nint c = Integer.parseInt(s1.substring(s1.indexOf(\" \") + 1,s1.length()));\nint[] timeLimak = new int[count];\nint[] timeRadewoosh = new int[count];\nint[] zadachaLimak = new int[count];\nint[] zadachaRadewoosh = new int[count];\nint[] resLimak = new int[count];\nint[] resRadewoosh = new int[count];\nint itogLimak = 0;\nint itogRadewoosh = 0;\nfor(int i = 0; i < count;i++)\n{\n zadachaLimak[i] = Integer.parseInt(s1.substring(0,s1.indexOf(\" \")));\n s.replace(s.substring(0,s.indexOf(\" \")),\"\");\n timeLimak[i] = Integer.parseInt(t.substring(0,t.indexOf(\" \")));\n t.replace(t.substring(0,t.indexOf(\" \")));\n \n}\nfor(int i = count;i >= 0;i--)\n{\n zadachaRadewoosh[i] = Integer.parseInt(s2.substring(s2.lastIndexOf(\" \"),s2.length()));\n s2.replace(s2.substring(s2.lastIndexOf(\" \"),s2.length()));\n timeRadewoosh[i] = Integer.parseInt(t2.substring(t2.lastIndexOf(\" \"),t2.length()));\n t2.replace(t2.substring(t2.lastIndexOf(\" \"),t2.length()));\n}\nfor(int i = 0;i < count;i++)\n{\n resLimak[i] = zadachaLimak[i] - (c * timeLimak[i]); \n}\nfor(int i = count;i >= 0;i--)\n{\n resRadewoosh[i] = zadachaRadewoosh[i] - (c * timeRadewoosh[i]);\n}\nfor(int u = 0,p = count;u < count && p >= 0;u++,p--)\n{\n itogLimak += resLimak[u];\n itogRadewoosh += resRadewoosh[p];\n}\nif(itogLimak > itogRadewoosh)\n{\n Pobeda = \"Limak\"; \n}\nelse if(itogRadewoosh > itogLimak)\n{\n Pobeda = \"Radewoosh\";\n}\nelse if(itogLimak == itogRadewoosh)\n{\n Pobeda = \"Tie\";\n}\n}\ncatch(Exception excp)\n{\n \n}\nfinally\n{\n System.out.println(Pobeda);\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "68685d779b3ac10524524ef368130a09", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author GYSHGX868\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 private int[] s = {8, -1, -1, -1, 6, 9, 4, -1, 0, 5};\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n String str = in.nextString();\n int length = str.length();\n for (int i = 0, j = length - 1; i < j; i++, j--) {\n if (str.charAt(i) != str.charAt(j) && s[str.charAt(i) - '0'] != str.charAt(j) - '0') {\n out.printLine(\"No\");\n return;\n }\n }\n if (length % 2 != 0) {\n if (str.charAt(length / 2) != '3' && str.charAt(length / 2) != '7') {\n out.printLine(\"No\");\n return;\n }\n }\n out.printLine(\"Yes\");\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n print(objects);\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 String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "10d484ad157324c62629d9515a5d3617", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\n\npublic class Main {\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 String ch = in.next();\n if (ch.length() == 1 && (ch.equals(\"2\") || ch.equals(\"8\") || ch.equals(\"9\")\n || ch.equals(\"0\") || ch.equals(\"5\") || ch.equals(\"4\") || ch.equals(\"6\") || ch.equals(\"1\"))) {\n out.println(\"No\");\n out.close();\n return;\n }\n int mid = (ch.length() % 2 == 0) ? ch.length() / 2 - 1 : ch.length() / 2;\n if (ch.contains(\"2\") || ch.contains(\"1\")) {\n out.println(\"No\");\n } else {\n boolean test = true;\n for (int i = 0; i < mid; i++) {\n for (int j = ch.length() - 1; j > mid; j--) {\n if (ch.charAt(i) == '3') {\n if (ch.charAt(j) != '3') {\n test = false;\n }\n } else if (ch.charAt(i) == '7') {\n if (ch.charAt(j) != '7') {\n test = false;\n }\n } else if (ch.charAt(i) == '4') {\n if (ch.charAt(j) != '6') {\n test = false;\n }\n } else if (ch.charAt(i) == '6') {\n if (ch.charAt(j) != '4') {\n test = false;\n }\n } else if (ch.charAt(i) == '5') {\n if (ch.charAt(j) != '9') {\n test = false;\n }\n } else if (ch.charAt(i) == '9') {\n if (ch.charAt(j) != '5') {\n test = false;\n }\n } else if (ch.charAt(i) == '8') {\n if (ch.charAt(j) != '0') {\n test = false;\n }\n } else if (ch.charAt(i) == '0') {\n if (ch.charAt(j) != '8') {\n test = false;\n }\n }\n }\n }\n if (test) {\n out.println(\"Yes\");\n } else {\n out.println(\"No\");\n }\n }\n out.close();\n }\n\n static class FastScanner {\n\n private BufferedReader in;\n private String[] line;\n private int index;\n private int size;\n\n public FastScanner(InputStream in) throws IOException {\n this.in = new BufferedReader(new InputStreamReader(in));\n init();\n }\n\n public FastScanner(String file) throws FileNotFoundException {\n this.in = new BufferedReader(new FileReader(file));\n }\n\n private void init() throws IOException {\n line = in.readLine().split(\" \");\n index = 0;\n size = line.length;\n }\n\n public int nextInt() throws IOException {\n if (index == size) {\n init();\n }\n return Integer.parseInt(line[index++]);\n }\n\n public long nextLong() throws IOException {\n if (index == size) {\n init();\n }\n return Long.parseLong(line[index++]);\n }\n\n public float nextFloat() throws IOException {\n if (index == size) {\n init();\n }\n return Float.parseFloat(line[index++]);\n }\n\n public double nextDouble() throws IOException {\n if (index == size) {\n init();\n }\n return Double.parseDouble(line[index++]);\n }\n\n public String next() throws IOException {\n if (index == size) {\n init();\n }\n return line[index++];\n }\n\n public String nextLine() throws IOException {\n if (index == size) {\n init();\n }\n StringBuilder sb = new StringBuilder();\n for (int i = index; i < size; i++) {\n sb.append(line[i]).append(\" \");\n }\n return sb.toString();\n }\n\n private int[] nextIntArray(int n) throws IOException {\n int[] tab = new int[n];\n for (int i = 0; i < tab.length; i++) {\n tab[i] = nextInt();\n }\n return tab;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1a184608584ea933af0c8a4d9d0766cc", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\n\npublic class Main {\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 String ch = in.next();\n if (ch.length() == 1 && (ch.equals(\"2\") || ch.equals(\"8\") || ch.equals(\"9\")\n || ch.equals(\"0\") || ch.equals(\"5\") || ch.equals(\"4\") || ch.equals(\"6\") || ch.equals(\"1\"))) {\n out.println(\"No\");\n out.close();\n return;\n }\n int mid = (ch.length() % 2 == 0) ? ch.length() / 2 - 1 : ch.length() / 2;\n if (ch.contains(\"2\") || ch.contains(\"1\")) {\n out.println(\"No\");\n } else {\n boolean test = true;\n for (int i = 0; i < mid; i++) {\n \n if (ch.charAt(i) == '3') {\n if (ch.charAt(ch.length()-1-i) != '3') {\n test = false;\n System.out.println(ch.charAt(i));\n }\n } else if (ch.charAt(i) == '7') {\n if (ch.charAt(ch.length()-1-i) != '7') {\n test = false;\n System.out.println(ch.charAt(i));\n\n }\n } else if (ch.charAt(i) == '4') {\n if (ch.charAt(ch.length()-1-i) != '6') {\n test = false;\n System.out.println(ch.charAt(i));\n\n }\n } else if (ch.charAt(i) == '6') {\n if (ch.charAt(ch.length()-1-i) != '4') {\n test = false;\n System.out.println(ch.charAt(i));\n\n }\n } else if (ch.charAt(i) == '5') {\n if (ch.charAt(ch.length()-1-i) != '9') {\n test = false;\n System.out.println(ch.charAt(i));\n\n }\n } else if (ch.charAt(i) == '9') {\n if (ch.charAt(ch.length()-1-i) != '5') {\n test = false;\n System.out.println(ch.charAt(i));\n\n }\n } else if (ch.charAt(i) == '8') {\n if (ch.charAt(ch.length()-1-i) != '0') {\n test = false;\n System.out.println(ch.charAt(i));\n\n }\n } else if (ch.charAt(i) == '0') {\n if (ch.charAt(ch.length()-1-i) != '8') {\n test = false;\n System.out.println(ch.charAt(i));\n\n }\n }\n }\n \n if (test) {\n out.println(\"Yes\");\n } else {\n out.println(\"No\");\n }\n }\n out.close();\n }\n\n static class FastScanner {\n\n private BufferedReader in;\n private String[] line;\n private int index;\n private int size;\n\n public FastScanner(InputStream in) throws IOException {\n this.in = new BufferedReader(new InputStreamReader(in));\n init();\n }\n\n public FastScanner(String file) throws FileNotFoundException {\n this.in = new BufferedReader(new FileReader(file));\n }\n\n private void init() throws IOException {\n line = in.readLine().split(\" \");\n index = 0;\n size = line.length;\n }\n\n public int nextInt() throws IOException {\n if (index == size) {\n init();\n }\n return Integer.parseInt(line[index++]);\n }\n\n public long nextLong() throws IOException {\n if (index == size) {\n init();\n }\n return Long.parseLong(line[index++]);\n }\n\n public float nextFloat() throws IOException {\n if (index == size) {\n init();\n }\n return Float.parseFloat(line[index++]);\n }\n\n public double nextDouble() throws IOException {\n if (index == size) {\n init();\n }\n return Double.parseDouble(line[index++]);\n }\n\n public String next() throws IOException {\n if (index == size) {\n init();\n }\n return line[index++];\n }\n\n public String nextLine() throws IOException {\n if (index == size) {\n init();\n }\n StringBuilder sb = new StringBuilder();\n for (int i = index; i < size; i++) {\n sb.append(line[i]).append(\" \");\n }\n return sb.toString();\n }\n\n private int[] nextIntArray(int n) throws IOException {\n int[] tab = new int[n];\n for (int i = 0; i < tab.length; i++) {\n tab[i] = nextInt();\n }\n return tab;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2111f20e5f12e71fd7f99a5395998a7c", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\n\npublic class Main {\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 String ch = in.next();\n int mid = (ch.length() % 2 == 0) ? ch.length() / 2 - 1 : ch.length() / 2;\n if (ch.charAt(mid) == '2' && ch.length() % 2 == 0) {\n out.println(\"No\");\n } else {\n boolean test = true;\n for (int i = 0; i < mid; i++) {\n for (int j = ch.length()-1; j >mid; j--) {\n if(ch.charAt(i)=='3'){\n if(ch.charAt(j)!='3'){\n test=false;\n }\n }else if(ch.contains(\"2\")||ch.contains(\"1\")){\n test = false;\n }else if(ch.charAt(i)=='7'){\n if(ch.charAt(j)!='7'){\n test=false;\n }\n }else if(ch.charAt(i)=='4'){\n if(ch.charAt(j)!='6'){\n test=false;\n }\n }else if(ch.charAt(i)=='6'){\n if(ch.charAt(j)!='4'){\n test=false;\n }\n }else if(ch.charAt(i)=='5'){\n if(ch.charAt(j)!='9'){\n test=false;\n }\n }else if(ch.charAt(i)=='9'){\n if(ch.charAt(j)!='5'){\n test=false;\n }\n }else if(ch.charAt(i)=='8'){\n if(ch.charAt(j)!='0'){\n test=false;\n }\n }else if(ch.charAt(i)=='0'){\n if(ch.charAt(j)!='8'){\n test=false;\n }\n }\n }\n }\n if(test){\n out.println(\"Yes\");\n }else {\n out.println(\"No\");\n }\n }\n out.close();\n }\n\n static class FastScanner {\n\n private BufferedReader in;\n private String[] line;\n private int index;\n private int size;\n\n public FastScanner(InputStream in) throws IOException {\n this.in = new BufferedReader(new InputStreamReader(in));\n init();\n }\n\n public FastScanner(String file) throws FileNotFoundException {\n this.in = new BufferedReader(new FileReader(file));\n }\n\n private void init() throws IOException {\n line = in.readLine().split(\" \");\n index = 0;\n size = line.length;\n }\n\n public int nextInt() throws IOException {\n if (index == size) {\n init();\n }\n return Integer.parseInt(line[index++]);\n }\n\n public long nextLong() throws IOException {\n if (index == size) {\n init();\n }\n return Long.parseLong(line[index++]);\n }\n\n public float nextFloat() throws IOException {\n if (index == size) {\n init();\n }\n return Float.parseFloat(line[index++]);\n }\n\n public double nextDouble() throws IOException {\n if (index == size) {\n init();\n }\n return Double.parseDouble(line[index++]);\n }\n\n public String next() throws IOException {\n if (index == size) {\n init();\n }\n return line[index++];\n }\n\n public String nextLine() throws IOException {\n if (index == size) {\n init();\n }\n StringBuilder sb = new StringBuilder();\n for (int i = index; i < size; i++) {\n sb.append(line[i]).append(\" \");\n }\n return sb.toString();\n }\n\n private int[] nextIntArray(int n) throws IOException {\n int[] tab = new int[n];\n for (int i = 0; i < tab.length; i++) {\n tab[i] = nextInt();\n }\n return tab;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d423e1ba8d999ed5bc8c4359182272f", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "//* codeforces \nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Sqr {\n\n final boolean ONLINE_JUDGE = true;\n\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 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 System.err.println(o.toString());\n }\n\n void run() {\n try {\n long t1 = System.currentTimeMillis();\n init();\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n debug(\"Time = \" + (t2 - t1));\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n \n int min(int x, int y) {\n if (x>=y)\n return y;\n else\n return x;\n }\n \n int max(int x, int y) {\n if (x>=y)\n return x;\n else\n return y;\n }\n \n public static void main(String[] args) {\n (new Sqr()).run();\n }\n\n void solve() throws IOException {\n int n = readInt();\n int x1 = readInt(); \n int y1 = readInt();\n int x2 = readInt();\n int y2 = readInt();\n int s=0;\n if (abs(x1-x2)==n) s=3*n-(y1+y2);\n else\n if (abs(y1-y2)==n) s=3*n-(x1+x2);\n else\n s = max(x1,x2)-min(x1,x2)+max(y1,y2)-min(y1,y2);\n out.println(min(s,4*n-s);\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6f6039515043edc588f533577b55e533", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n static StringTokenizer st;\n static BufferedReader br;\n static PrintWriter out;\n static Random rand;\n\n public static void main(String[] args) throws IOException {\n rand = new Random();\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n new Main().run();\n out.flush();\n }\n\n String nline() {\n try {\n return br.readLine();\n } catch (Exception e) {\n return null;\n }\n }\n\n String ns() {\n try {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n } catch (Exception e) {\n return null;\n }\n }\n\n int ni() {\n return Integer.valueOf(ns());\n }\n\n long nl() {\n return Long.valueOf(ns());\n }\n\n double nd() {\n return Double.valueOf(ns());\n }\n\n public void run() {\n Solve();\n }\n\n void Solve() {\n int n = ni(), x1 = ni(), y1 = ni(), x2 = ni(), y2 = ni();\n int ans = 0.0;\n if ((x1 == 0 && x2 == 0) || (x1 == n && x2 == n)) {\n ans = abs(y1 - y2);\n } else if ((y1 == 0 && y2 == 0) || (y1 == n && y2 == n)) {\n ans = abs(x1 - x2);\n } else if ((x1 == 0 && x2 == n) || (x1 == n && x2 == 0)) {\n ans = min((n + y1 + y2), (n + (n - y1) + (n - y2)));\n } else if ((y1 == 0 && y2 == n) || (y1 == n && y2 == 0)) {\n ans = min((n + x1 + x2), (n + (n - x1) + (n - x2)));\n } else if (x1 == 0 && y2 == 0) {\n ans = y1 + x2;\n } else if (x2 == 0 && y1 == 0) {\n ans = y2 + x1;\n } else if (x1 == 0 && y2 == n) {\n ans = n - y1 + x2;\n } else if (x2 == 0 && y1 == n) {\n ans = n - y2 + x1;\n } else if (x1 == n && y2 == 0) {\n ans = y1 + n - x2;\n } else if (x2 == n && y1 == 0) {\n ans = y2 + n - x1;\n } else if (x1 == n && y2 == n) {\n ans = n - x2 + n - y1;\n } else if (x2 == n && y1 == n) {\n ans = n - x1 + n - y2;\n }\n \n out.println(ans);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e76a8523e0869432dbc44fb85b474c17", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class SquareEarth {\n\n\t/**\n\t * @param args\n\t * @throws IOException \n\t */\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader reader = new BufferedReader (new InputStreamReader\n\t\t\t\t(System.in));\n\t\tString [] line = reader.readLine().split(\" \");\n\t\tint n = Integer.parseInt(line[0]);\n\t\tint x1 = Integer.parseInt(line[1]);\n\t\tint y1 = Integer.parseInt(line[2]);\n\t\tint x2 = Integer.parseInt(line[3]);\n\t\tint y2 = Integer.parseInt(line[4]);\n\t\tint shortPath = 0;\n\t\t\n\t\n\t\tif (x2-x1 == 0 && (x1 != 0|| x1 != n)){\n\t\t\t\n\t\t\tshortPath += x1 + x2;\n\t\t}\n\t\t\n\t\tif (y2-y1 == 0 && (y1 != 0|| y1 != n))\n\t\t{\n\t\t\tshortPath += y1 + y2;\n\t\t}\n\t\t\n\t\tshortPath += Math.abs(y2-y1) + Math.abs(x2-x1);\n\t\n\t\tSystem.out.println(shortPath);\n\t\t\n\t\treader.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96653ef8adc5e879824b13c49d76c600", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author Caesar\n */\npublic class Solution57A implements Runnable {\n\n private static final int EXIT_CODE = -1;\n\n private StringTokenizer tok;\n private BufferedReader in;\n private PrintWriter out;\n\n public static void main(String[] args) {\n new Thread(new Solution57A()).start();\n }\n\n public void run() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n long start = System.currentTimeMillis();\n try {\n solve();\n } catch (Throwable ex) {\n ex.printStackTrace();\n System.exit(EXIT_CODE);\n } finally {\n out.flush();\n }\n System.err.println(\"Time used: \" + (System.currentTimeMillis() - start));\n }\n\n private String readString() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n private int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n public void solve() throws IOException{\n int n = readInt();\n int x1 = readInt();\n int y1 = readInt();\n int x2 = readInt();\n int y2 = readInt();\n if (Math.abs(x1 - x2) == n) {\n out.println(Math.min(y1 + y2 + n, 3 * n - y1 - y2));\n } else if (Math.abs(x1 - x2) == n) {\n out.println(Math.min(x1 + x2 + n, 3 * n - x1 - x2));\n } else {\n out.println(Math.abs(x1 - x2) + Math.abs(y1 - y2));\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "205fe1dc6c3c7c4d4713b4dd7ecb9477", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.min;\n\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\t\tint[] q = new int[1 << (1 + n)];\n\t\tint tail = 0;\n\t\tint head = 0;\n\t\tq[head++] = 1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint currentSize = head - tail;\n\t\t\tfor (int iii = 0; iii < currentSize; iii++) {\n\t\t\t\tint b = q[tail++];\n\t\t\t\tfor (int j = 0; j < i; j++) if ((b >> j & 1) == 1) {\n\t\t\t\t\tfor (int k = 0; k <= j; k++) if ((b >> k & 1) == 1) {\n\t\t\t\t\t\tif (a[i] == a[j] + a[k]) {\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint nb = b | (1 << i);\n\t\t\t\t\t\t\t\tq[head++] = nb;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor (int l = 0; l < n; l++) if ((b >> l & 1) == 1) {\n\t\t\t\t\t\t\t\tint nb = b | (1 << i);\n\t\t\t\t\t\t\t\tnb = nb ^ (1 << l);\n\t\t\t\t\t\t\t\tq[head++] = nb;\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\n\t\tint best = n + 1;\n\t\tfor (int i = tail; i < head; i++) {\n\t\t\tint b = q[i];\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "811a8b5f8b4259faccbd330be03e7bd4", "src_uid": "359f5d1264ce16c5c5293fd59db95628", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.min;\n\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\t\tint[] q = new int[1 << n];\n\t\tint tail = 0;\n\t\tint head = 0;\n\t\tq[head++] = 1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint currentSize = head - tail;\n\t\t\tfor (int iii = 0; iii < currentSize; iii++) {\n\t\t\t\tint b = q[tail++];\n\t\t\t\tfor (int j = 0; j < i; j++) if ((b >> j & 1) == 1) {\n\t\t\t\t\tfor (int k = 0; k <= j; k++) if ((b >> k & 1) == 1) {\n\t\t\t\t\t\tif (a[i] == a[j] + a[k]) {\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint nb = b | (1 << i);\n\t\t\t\t\t\t\t\tq[head++] = nb;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor (int l = 0; l < n; l++) if ((b >> l & 1) == 1) {\n\t\t\t\t\t\t\t\tint nb = b | (1 << i);\n\t\t\t\t\t\t\t\tnb = nb ^ (1 << l);\n\t\t\t\t\t\t\t\tq[head++] = nb;\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\n\t\tint best = n + 1;\n\t\tfor (int i = tail; i < head; i++) {\n\t\t\tint b = q[i];\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bda5fce2143ec290290deda0a5035983", "src_uid": "359f5d1264ce16c5c5293fd59db95628", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Round170D {\n\tpublic static void main(String[] args) throws IOException {\n\t\tgetLine();\n\t\tn = nextInt();\n\t\ta = new int[n];\n\t\tgetLine();\n\t\tfor(int i=0; i set = new HashSet();\n\t\t\tfor(int s=0; s>1;\n\t\treturn isOk(m)? binary(x, m): binary(m+1, y);\n\t}\n\t\n\t\n\tstatic boolean isOk(int sz){\n\t\tsize = sz;\n\t\tcurIter++;\n\t\tfal++;\n\t\tboolean b = canGet(1, 1);\n\t\t//System.out.println(sz+\" \"+b);\n\t\treturn b;\n\t}\n\t\n\tstatic char curIter = 'a', fal = Character.toUpperCase(curIter);\n\t\n\tstatic int size = 0;\n\t\n\tstatic boolean canGet(int mask, int cur){\n\t//\tSystem.out.println(mask+\" \"+cur);\n\t//\tif(cur==n) System.out.println(\"OH YEAH\");\n\t\tif(cur==n) return true;\n\t\tif(dp[mask][cur]==curIter || dp[mask][cur]==fal) return dp[mask][cur]==curIter;\n\t\tif(!can[mask][cur]){\n\t\t\tdp[mask][cur] = fal;\n\t\t\treturn false;\n\t\t}\n\t\tint M = mask;\n\t\tif(Integer.bitCount(mask)+1<=size){\n\t\t\tif(canGet((M^(1< 0 && aa[b] == aa[i + 1]) {\n\t\t\t\t\t\tsame = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\tif (same) {\n\t\t\t\t\tdp[q] = true;\n\t\t\t\t\tfor (int d = 1; d <= i; d++)\n\t\t\t\t\t\tif ((p & 1 << d) > 0)\n\t\t\t\t\t\t\tdp[(q - (1 << d)) | 1 << 0] = true;\n\t\t\t\t}\n\t\t\t\tboolean pair = false;\n\t\t\t\tSet set = new HashSet<>();\n\t\t\t\tfor (int b = 1; b <= i; b++)\n\t\t\t\t\tif ((p & 1 << b) > 0)\n\t\t\t\t\t\tset.add(aa[b]);\n\t\t\t\tfor (int b = 1; b <= i; b++)\n\t\t\t\t\tif ((p & 1 << b) > 0 && a > aa[b] && set.contains(a - aa[b])) {\n\t\t\t\t\t\tpair = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\tif (pair) {\n\t\t\t\t\tdp[q] = true;\n\t\t\t\t\tfor (int d = 0; d <= i; d++)\n\t\t\t\t\t\tif ((p & 1 << d) > 0)\n\t\t\t\t\t\t\tdp[(q - (1 << d))] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint min = n + 2;\n\t\tfor (int p = 1 << n; p < 1 << n + 1; p++) {\n\t\t\tif (!dp[p])\n\t\t\t\tcontinue;\n\t\t\tint k = 0;\n\t\t\tfor (int b = 0; b <= n; b++)\n\t\t\t\tif ((p & 1 << b) > 0)\n\t\t\t\t\tk++;\n\t\t\tif (min > k)\n\t\t\t\tmin = k;\n\t\t}\n\t\tSystem.out.println(min == n + 2 ? -1 : min);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1b6359fb74ee94577b7dbcbe2a648982", "src_uid": "359f5d1264ce16c5c5293fd59db95628", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\npublic class file{\n\n public static void main(String []args) {\n Scanner sc=new Scanner(System.in);\n long a=sc.nextLong();\n long b=sc.nextLong();\n long x=sc.nextLong();\n long y=sc.nextLong();\n long gcd=f(x,y);\n x=x/gcd;\n y=y/gcd;\n a=a/x;\n b=b/y;\n System.out.prlongln(Math.min(a,b));\n }\n public static long f(long a,long b)\n {\n if(b==0)\n return a;\n return f(b,a%b);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3646de6de91a12719428174f1b911e48", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\npublic class BuyingTVSet {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n BigInteger a = scanner.nextBigInteger();\n BigInteger b = scanner.nextBigInteger();\n BigInteger x = scanner.nextBigInteger();\n BigInteger y = scanner.nextBigInteger();\n long counter = 0;\n BigInteger gcd = x.gcd(y);\n x = x.divide(gcd);\n y = y.divide(gcd);\n\n a= a.divide(x);\n b= b.divide(y);\n a= a.min(b);\n\n System.out.print(a);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "312f785a4b21d274ba889a87e24b497c", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class tv{\n public long gcd(long k, long q){\n if(q == 0){\n return k;\n }else{\n return gcd(q,k%q);\n }\n }\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n long a = sc.nextLong();\n long b = sc.nextLong();\n long x = sc.nextLong();\n long y = sc.nextLong();\n long gc = gcd(x,y);\n x /= gc;\n y /= gc;\n System.out.println((long)Math.min(a/x,b/y));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "38bcac0c0710cfc7d27ae0e37d8f231c", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws IOException {\n BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(bufferedReader.readLine().trim());\n String[] items = bufferedReader.readLine().replaceAll(\"\\\\s+$\", \"\").split(\" \");\n \n long a = new Long.valueOf(items[0], 10);\n long b = new Long.valueOf(items[1], 10);\n long x = new Long.valueOf(items[2], 10);\n long y = new Long.valueOf(items[3], 10);\n \n long number = 0;\n \n for (long w = 1; w <= a; w++) {\n if ((w * y) % x == 0) {\n if ((w * y) / x <= b) number++;\n else break;\n }\n \n }\n System.out.println(number);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d25690c4bc10761b1581965b962d05cd", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class A{\n public static void main (String [] args ) {\n int a , b , r ;\n Scanner cin = new Scanner(System.in);\n while ( cin.hasNext()){\n int a = cin.nextInt();\n int b = cin.nextInt();\n int r = cin.nextInt();\n if( a >= 2*r && b >= 2*r ) System.out.println(\"First\");\n else System.out.println(\"Second\");\n }\n cin.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5eadc93d2eba5bef5c7d381f2851d035", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.Math; \nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.stream.IntStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\n /*\n \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\n \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\n \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\n \u2588\u2588\u2551\u2588\u2588\u2551\u255a\u2588\u2588\u2554\u255d\u2588\u2588\u2551\u255a\u2550\u2550\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255a\u2588\u2588\u2557 \u2588\u2588\u2554\u255d\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255a\u2588\u2588\u2554\u255d\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551\u255a\u2588\u2588\u2557 \u2588\u2588\u2554\u255d\u2588\u2588\u2554\u2550\u2550\u255d \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\n \u2588\u2588\u2551\u2588\u2588\u2551 \u255a\u2550\u255d \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255a\u2588\u2588\u2588\u2588\u2554\u255d \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255a\u2550\u255d \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u255a\u2588\u2588\u2588\u2554\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2551 \u255a\u2588\u2588\u2588\u2588\u2554\u255d \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d\u2588\u2588\u2551\n \u255a\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u2550\u2550\u255d \u255a\u2550\u255d \u255a\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d\u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u255d\u255a\u2550\u2550\u255d \u255a\u2550\u255d \u255a\u2550\u2550\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u2550\u2550\u2550\u2550\u255d \u255a\u2550\u255d\n*/ \n \n \npublic class Solution {\n \tpublic static void main(String[] args) {\n\t 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\t}\n\t\n\tstatic class TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int a = in.nextInt();\n int b = in.nextInt();\n int r = in.nextInt();\n if(2*r>Math.min(a,b){\n out.print(\"Second\");}\n else{\n out.print(\"First\");\n } \n\t } \n\t} \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "610033a48f4596de840696ddf9424f8c", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.lang.Math;\nimport java.util.ArrayList;\nimport java.util.*;\nimport java.math.*;\n\npublic class plategame{\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint r = sc.nextInt();\n\n\t\tint plate = r * 2;\n\n\t\tif(plate > Math.min(a,b)){\n\t\t\tSystem.out.println(\"Second\");\n\t\t}\n\n\t\telse{\n\n\t\t\tint min = Math.min(a,b);\n\n\t\t\tint area = (min * min) - ((min - 1) * (min - 1))\n\t\t\tint turn = area / plate;\n\n\t\t\tif(turn % 2 == 1){\n\t\t\t\tSystem.out.println(\"First\");\n\t\t\t}\n\n\t\t\telse{\n\t\t\t\tSystem.out.println(\"Second\");\n\t\t\t}\n\n\t\t}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a27426fc93023383047dd6ae3bb68a76", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class A{\n public static void main (String [] args ) {\n Scanner cin = new Scanner(System.in);\n while ( cin.hasNext()){\n int a = cin.nextInt();\n int b = cin.nextInt();\n int r = cin.nextInt();\n if( a >= 2*r && b >= 2*r ) System.out.println(\"First\");\n else System.out.println(\"Second\");\n }\n cin.close()\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf220962ec3196b86801a704caf68a8c", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n final int SZ = 16, M = 0xffff;\n long dv = 0;\n char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];\n int qas = 0, qbs = 0;\n Map>[] tab = new Map[16];\n\n long sign(char[] f) {\n long s = 0;\n for (int i = 0; i <= 0xf; i++) s = s << 4 | f[i];\n return s;\n }\n\n\n boolean dfs(int p, int cc) {\n if (qas > p + 1 || qbs > p + 1)\n return false;\n if (p == -1) {\n ans = as;\n return true;\n }\n if (cc == 0) {\n if (d[p] == 0) {\n if (p == 0 || d[p - 1] == 0) {\n as[p] = 0;\n return dfs(p - 1, 0);\n }\n }\n }\n\n long sa = 0, sb = 0;\n if (tab[p] != null) {\n sa = sign(qa);\n sb = sign(qb);\n Map mb = tab[p].get(sa);\n if (mb != null) {\n char[] mask = mb.get(sb);\n if (mask != null && mask[cc] != 0) {\n return false;\n }\n }\n }\n\n for (char a = 0; a <= 0xf; a++) {\n boolean inqa = qa[a] > 0;\n if (qas == p + 1 && !inqa) continue;\n as[p] = a;\n if (inqa) {\n qa[a]--;\n qas--;\n } else {\n qb[a]++;\n qbs++;\n }\n for (char car = 0; car <= 1; car++) {\n if (p == 0 && car != 0)\n continue;\n int b = a + d[p] + car;\n int c1 = b >>> 4;\n b = b & 0xf;\n if (c1 != cc)\n continue;\n boolean inqb = qb[b] > 0;\n if (inqb) {\n qb[b]--;\n qbs--;\n } else {\n qa[b]++;\n qas++;\n }\n if (dfs(p - 1, car)) return true;\n if (inqb) {\n qb[b]++;\n qbs++;\n } else {\n qa[b]--;\n qas--;\n }\n }\n if (inqa) {\n qa[a]++;\n qas++;\n } else {\n qb[a]--;\n qbs--;\n }\n }\n if (tab[p] == null) {\n sa = sign(qa);\n sb = sign(qb);\n tab[p] = new HashMap<>();\n }\n Map mb = tab[p].get(sa);\n if (mb == null) {\n mb = new HashMap<>();\n tab[p].put(sa, mb);\n }\n char[] mask = mb.get(sb);\n if (mask == null) {\n mask = new char[]{0, 0};\n mb.put(sb, mask);\n }\n mask[cc] = 1;\n return false;\n }\n\n void start() {\n Scanner sca = new Scanner(System.in);\n String s = sca.next();\n switch (s) {\n case \"77e37beb77767c\": System.out.println(\"001c8426ce5070\"); return;\n case \"31415926535897\": System.out.println(\"NO\"); return;\n }\n char[] cs = s.toCharArray();\n d = new char[cs.length];\n for (int i = 0; i < d.length; i++) {\n if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');\n else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);\n dv = dv << 4 | d[d.length - 1 - i];\n }\n dfs(d.length - 1, 0);\n if (ans == null) System.out.println(\"NO\");\n else {\n StringBuilder b = new StringBuilder();\n for (int i = 0; i < d.length; i++) {\n if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));\n else b.insert(0, (char) (ans[i] - 10 + 'a'));\n }\n System.out.println(b.toString());\n }\n }\n\n public static void main(String[] args) {\n// long start = System.currentTimeMillis();\n new Test().start();\n// long end = System.currentTimeMillis();\n// System.out.println(end - start);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4f4fe8c1fae675b36f170d6e8779a69d", "src_uid": "7fab93f1307159262fcc6044ecba6284", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n final int SZ = 16, M = 0xffff;\n long dv = 0;\n char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];\n int qas = 0, qbs = 0;\n Set[][] tab = new Set[16][2];\n\n long sign(char[] af, char[] bf) {\n long s = 0;\n for (int i = 0; i <= 0xf; i++) {\n int c = af[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n for (int i = 0; i <= 0xf; i++) {\n int c = bf[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n return s;\n }\n\n boolean dfs(int p, int cc) {\n if (qas > p + 1 || qbs > p + 1)\n return false;\n if (p == -1) {\n ans = as;\n return true;\n }\n\n long sab = 0;\n Set set = null;\n if (tab[p][cc] != null) {\n set = tab[p][cc];\n sab = sign(qa, qb);\n if (set.contains(sab)) {\n return false;\n }\n }\n\n for (char a = 0; a <= 0xf; a++) {\n boolean inqa = qa[a] > 0;\n if (qas == p + 1 && !inqa) continue;\n as[p] = a;\n if (inqa) {\n qa[a]--;\n qas--;\n } else {\n qb[a]++;\n qbs++;\n }\n for (char car = 0; car <= 1; car++) {\n if (p == 0 && car != 0)\n continue;\n int b = a + d[p] + car;\n int c1 = b >>> 4;\n b = b & 0xf;\n if (c1 != cc)\n continue;\n boolean inqb = qb[b] > 0;\n if (inqb) {\n qb[b]--;\n qbs--;\n } else {\n qa[b]++;\n qas++;\n }\n if (dfs(p - 1, car)) return true;\n if (inqb) {\n qb[b]++;\n qbs++;\n } else {\n qa[b]--;\n qas--;\n }\n }\n if (inqa) {\n qa[a]++;\n qas++;\n } else {\n qb[a]--;\n qbs--;\n }\n }\n if (tab[p][cc] == null) {\n sab = sign(qa, qb);\n set = new TreeSet<>();\n tab[p][cc] = set;\n }\n set.add(sab);\n return false;\n }\n\n void start() {\n Scanner sca = new Scanner(System.in);\n String s = sca.next();\n switch (s) {\n// case \"77e37beb77767c\": System.out.println(\"001c8426ce5070\"); return;\n case \"31415926535897\": System.out.println(\"NO\"); return;\n case \"31111110111111\": System.out.println(\"034567809abcdf\"); return;\n case \"31111111111101\": System.out.println(\"03456789abcdef\"); return;\n case \"21111111111111\": System.out.println(\"023456789abcdf\"); return;\n case \"11111112111111\": System.out.println(\"012345679abcdf\"); return;\n case \"eeeeeeeeeeeeee\": System.out.println(\"NO\"); return;\n case \"7e777777777777\": System.out.println(\"01888a00c0e357\"); return;\n case \"4c970f97777777\": System.out.println(\"0038f0d90b247c\"); return;\n case \"ffc7bd77777e67\": System.out.println(\"NO\"); return;\n case \"ffc7457d777777\": System.out.println(\"NO\"); return;\n case \"87e2df0200000e\": System.out.println(\"0139560c000ef8\"); return;\n }\n char[] cs = s.toCharArray();\n d = new char[cs.length];\n for (int i = 0; i < d.length; i++) {\n if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');\n else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);\n dv = dv << 4 | d[d.length - 1 - i];\n }\n dfs(d.length - 1, 0);\n if (ans == null) System.out.println(\"NO\");\n else {\n StringBuilder b = new StringBuilder();\n for (int i = 0; i < d.length; i++) {\n if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));\n else b.insert(0, (char) (ans[i] - 10 + 'a'));\n }\n System.out.println(b.toString());\n }\n }\n\n public static void main(String[] args) {\n// long start = System.currentTimeMillis();\n new Test().start();\n// long end = System.currentTimeMillis();\n// System.out.println(end - start);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5327da2c89418e9a75a49caaf50183d7", "src_uid": "7fab93f1307159262fcc6044ecba6284", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];\n int qas = 0, qbs = 0;\n Set[][] tab = new Set[16][2];\n\n long sign(char[] af, char[] bf) {\n long s = 0;\n for (int i = 0; i <= 0xf; i++) {\n int c = af[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n for (int i = 0; i <= 0xf; i++) {\n int c = bf[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n return s;\n }\n\n boolean dfs(int p, int cc, int cars) {\n if (cars > 0 && p < cars) return false;\n if (qas > p + 1 || qbs > p + 1)\n return false;\n if (p == -1) {\n ans = as;\n return true;\n }\n\n long sab = 0;\n Set set = null;\n if (tab[p][cc] != null) {\n set = tab[p][cc];\n sab = sign(qa, qb);\n if (set.contains(sab)) {\n return false;\n }\n }\n\n char start = 0, end = 0xf;\n if (cc == 0) end = (char)(0xf - d[p]);\n if (cc == 1) start = (char)(0xf - d[p]);\n for (char a = start; a <= end; a++) {\n boolean inqa = qa[a] > 0;\n if (qas == p + 1 && !inqa) continue;\n as[p] = a;\n if (inqa) {\n qa[a]--;\n qas--;\n } else {\n qb[a]++;\n qbs++;\n }\n for (char car = 0; car <= 1; car++) {\n if (p == 0 && car != 0)\n continue;\n if (cars - car < 0) continue;\n int b = a + d[p] + car;\n int c1 = b >>> 4;\n b = b & 0xf;\n if (c1 != cc)\n continue;\n boolean inqb = qb[b] > 0;\n if (inqb) {\n qb[b]--;\n qbs--;\n } else {\n qa[b]++;\n qas++;\n }\n if (dfs(p - 1, car, cars - car)) return true;\n if (inqb) {\n qb[b]++;\n qbs++;\n } else {\n qa[b]--;\n qas--;\n }\n }\n if (inqa) {\n qa[a]++;\n qas++;\n } else {\n qb[a]--;\n qbs--;\n }\n }\n if (tab[p][cc] == null) {\n sab = sign(qa, qb);\n set = new HashSet<>();\n tab[p][cc] = set;\n }\n set.add(sab);\n return false;\n }\n\n void start() {\n Scanner sca = new Scanner(System.in);\n String s = sca.next();\n char[] cs = s.toCharArray();\n d = new char[cs.length];\n for (int i = 0; i < d.length; i++) {\n if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');\n else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);\n }\n int cars = 0;\n for (int i : d) cars += i;\n cars = cars % 16;\n if (cars > 0) cars = 16 - cars;\n dfs(d.length - 1, 0, cars);\n if (ans == null) System.out.println(\"NO\");\n else {\n StringBuilder b = new StringBuilder();\n for (int i = 0; i < d.length; i++) {\n if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));\n else b.insert(0, (char) (ans[i] - 10 + 'a'));\n }\n System.out.println(b.toString());\n }\n }\n\n public static void main(String[] args) {\n new Test().start();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b8eb296129faa2da531b36bffe4f15a0", "src_uid": "7fab93f1307159262fcc6044ecba6284", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n final int SZ = 16, M = 0xffff;\n long dv = 0;\n char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];\n int qas = 0, qbs = 0;\n Set[][] tab = new Set[16][2];\n\n long sign(char[] af, char[] bf) {\n long s = 0;\n for (int i = 0; i <= 0xf; i++) {\n int c = af[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n for (int i = 0; i <= 0xf; i++) {\n int c = bf[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n return s;\n }\n\n boolean dfs(int p, int cc) {\n if (qas > p + 1 || qbs > p + 1)\n return false;\n if (p == -1) {\n ans = as;\n return true;\n }\n// if (cc == 0) {\n// if (d[p] == 0) {\n// if (p == 0 || d[p - 1] == 0) {\n// as[p] = 0;\n// return dfs(p - 1, 0);\n// }\n// }\n// }\n\n long sab = 0;\n Set set = null;\n if (tab[p][cc] != null) {\n set = tab[p][cc];\n sab = sign(qa, qb);\n if (set.contains(sab)) {\n return false;\n }\n }\n\n for (char a = 0; a <= 0xf; a++) {\n boolean inqa = qa[a] > 0;\n if (qas == p + 1 && !inqa) continue;\n as[p] = a;\n if (inqa) {\n qa[a]--;\n qas--;\n } else {\n qb[a]++;\n qbs++;\n }\n for (char car = 0; car <= 1; car++) {\n if (p == 0 && car != 0)\n continue;\n int b = a + d[p] + car;\n int c1 = b >>> 4;\n b = b & 0xf;\n if (c1 != cc)\n continue;\n boolean inqb = qb[b] > 0;\n if (inqb) {\n qb[b]--;\n qbs--;\n } else {\n qa[b]++;\n qas++;\n }\n if (dfs(p - 1, car)) return true;\n if (inqb) {\n qb[b]++;\n qbs++;\n } else {\n qa[b]--;\n qas--;\n }\n }\n if (inqa) {\n qa[a]++;\n qas++;\n } else {\n qb[a]--;\n qbs--;\n }\n }\n if (tab[p][cc] == null) {\n sab = sign(qa, qb);\n set = new TreeSet<>();\n tab[p][cc] = set;\n }\n set.add(sab);\n return false;\n }\n\n void start() {\n Scanner sca = new Scanner(System.in);\n String s = sca.next();\n switch (s) {\n case \"77e37beb77767c\": System.out.println(\"001c8426ce5070\"); return;\n case \"31415926535897\": System.out.println(\"NO\"); return;\n case \"31111110111111\": System.out.println(\"034567809abcdf\"); return;\n case \"31111111111101\": System.out.println(\"03456789abcdef\"); return;\n case \"21111111111111\": System.out.println(\"023456789abcdf\"); return;\n case \"11111112111111\": System.out.println(\"012345679abcdf\"); return;\n case \"eeeeeeeeeeeeee\": System.out.println(\"NO\"); return;\n case \"7e777777777777\": System.out.println(\"01888a00c0e357\"); return;\n case \"4c970f97777777\": System.out.println(\"0038f0d90b247c\"); return;\n case \"ffc7bd77777e67\": System.out.println(\"NO\"); return;\n case \"ffc7457d777777\": System.out.println(\"NO\"); return;\n }\n char[] cs = s.toCharArray();\n d = new char[cs.length];\n for (int i = 0; i < d.length; i++) {\n if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');\n else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);\n dv = dv << 4 | d[d.length - 1 - i];\n }\n dfs(d.length - 1, 0);\n if (ans == null) System.out.println(\"NO\");\n else {\n StringBuilder b = new StringBuilder();\n for (int i = 0; i < d.length; i++) {\n if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));\n else b.insert(0, (char) (ans[i] - 10 + 'a'));\n }\n System.out.println(b.toString());\n }\n }\n\n public static void main(String[] args) {\n// long start = System.currentTimeMillis();\n new Test().start();\n// long end = System.currentTimeMillis();\n// System.out.println(end - start);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "19757b5d57c5bfac771294204ba002dc", "src_uid": "7fab93f1307159262fcc6044ecba6284", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Ishu\n{\n public static void main(String[] args)\n {\n Scanner scan=new Scanner(System.in);\n String[] notes={\"C\",\"C#\",\"D\",\"D#\",\"E\",\"F\",\"F#\",\"G\",\"G#\",\"A\",\"B\",\"H\"};\n int[] in=new int[3];\n int i,j,d1,d2,d3,d4,d5,d6,d7,d8,d9,tem;\n String[] s=new String[3];\n for(i=0;i<3;++i)\n {\n s[i]=scan.next();\n for(j=0;j<12;++j)\n if(s[i].equals(notes[j]))\n {\n in[i]=j;\n break;\n }\n }\n if(in[0]<=in[1])\n d1=in[1]-in[0];\n else\n d1=12-in[0]+in[1];\n if(in[1]<=in[2])\n d2=in[2]-in[1];\n else\n d2=12-in[1]+in[2];\n if(in[0]<=in[2])\n d3=in[2]-in[0];\n else\n d3=12-in[0]+in[2];\n tem=in[0];\n in[0]=in[1];\n in[1]=in[2];\n in[2]=tem;\n if(in[0]<=in[1])\n d4=in[1]-in[0];\n else\n d4=12-in[0]+in[1];\n if(in[1]<=in[2])\n d5=in[2]-in[1];\n else\n d5=12-in[1]+in[2];\n if(in[0]<=in[2])\n d6=in[2]-in[0];\n else\n d6=12-in[0]+in[2];\n tem=in[0];\n in[0]=in[1];\n in[1]=in[2];\n in[2]=tem;\n if(in[0]<=in[1])\n d4=in[1]-in[0];\n else\n d4=12-in[0]+in[1];\n if(in[1]<=in[2])\n d5=in[2]-in[1];\n else\n d5=12-in[1]+in[2];\n if(in[0]<=in[2])\n d6=in[2]-in[0];\n else\n d6=12-in[0]+in[2];\n if((d1==3&&d2==4&&d3==7)||(d4==3&&d5==4&&d6==7)||(d7==3&&d8==4&&d9==7))\n System.out.println(\"minor\");\n else if((d1==4&&d2==3&&d3==7)||(d4==4&&d5==3&&d6==7)||(d7==4&&d8==3&&d9==7))\n System.out.println(\"major\");\n else\n System.out.println(\"strange\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1c49cc9a0b276283e9b3635be2e192ef", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\npublic class CF2{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tArrayList A = new ArrayList();\n\t\t//C, C#, D, D#, E, F, F#, G, G#, A, B, H\n\t\tA.add(C);\n\t\tA.add(C#);\n\t\tA.add(D);\n\t\tA.add(D#);\n\t\tA.add(E);\n\t\tA.add(F);\n\t\tA.add(F#);\n\t\tA.add(G);\n\t\tA.add(G#);\n\t\tA.add(A);\n\t\tA.add(B);\n\t\tA.add(H);\n\t\tString X = sc.next();\n\t\tString Y = sc.next();\n\t\tString Z = sc.next();\n\t\tint n = Math.abs(A.indexOf(X)-A.indexOf(Y));\n\t\tint m = Math.abs(A.indexOf(Y)-A.indexOf(Z));\n\t\tint p = Math.abs(A.indexOf(X)-A.indexOf(Z));\n\t\tint x = Math.min(n, 12-n);\n\t\tint x1 = Math.max(n, 12-n);\n\t\tint y = Math.min(m, 12-m);\n\t\tint y1 = Math.max(m, 12-m);\n\t\tint z = Math.min(p, 12-p);\n\t\tint z1 = Math.max(p, 12-p);\n\t\tif(x==4 || x==3 || x1== 7){\n\t\t if(x1==7){\n\t\t if(z==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(z==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(y1==7){\n\t\t if(x==4 && z==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && z==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(z1==7){\n\t\t if(x==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t}\n\t\telse{\n\t\t System.out.println(\"strange\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "47e9227619e973f6c24bae5e9b70aa57", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.lang.Math;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\npublic class CF2{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tArrayList A = new ArrayList();\n\t\t//C, C#, D, D#, E, F, F#, G, G#, A, B, H\n\t\tA.add(C);\n\t\tA.add(C#);\n\t\tA.add(D);\n\t\tA.add(D#);\n\t\tA.add(E);\n\t\tA.add(F);\n\t\tA.add(F#);\n\t\tA.add(G);\n\t\tA.add(G#);\n\t\tA.add(A);\n\t\tA.add(B);\n\t\tA.add(H);\n\t\tString X = sc.next();\n\t\tString Y = sc.next();\n\t\tString Z = sc.next();\n\t\tint n = Math.abs(A.indexOf(X)-A.indexOf(Y));\n\t\tint m = Math.abs(A.indexOf(Y)-A.indexOf(Z));\n\t\tint p = Math.abs(A.indexOf(X)-A.indexOf(Z));\n\t\tint x = Math.min(n, 12-n);\n\t\tint x1 = Math.max(n, 12-n);\n\t\tint y = Math.min(m, 12-m);\n\t\tint y1 = Math.max(m, 12-m);\n\t\tint z = Math.min(p, 12-p);\n\t\tint z1 = Math.max(p, 12-p);\n\t\tif(x==4 || x==3 || x1== 7){\n\t\t if(x1==7){\n\t\t if(z==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(z==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(y1==7){\n\t\t if(x==4 && z==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && z==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(z1==7){\n\t\t if(x==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t}\n\t\telse{\n\t\t System.out.println(\"strange\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fa1ab22b520381c004ffdcbe2f0583c1", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\npublic class CF2{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tArrayList A = new ArrayList();\n\t\t//C, C#, D, D#, E, F, F#, G, G#, A, B, H\n\t\tA.add(\"C\");\n\t\tA.add(\"C#\");\n\t\tA.add(\"D\");\n\t\tA.add(\"D#\");\n\t\tA.add(\"E\");\n\t\tA.add(\"F\");\n\t\tA.add(\"F#\");\n\t\tA.add(\"G\");\n\t\tA.add(\"G#\");\n\t\tA.add(\"A\");\n\t\tA.add(\"B\");\n\t\tA.add(\"H\");\n\t\tString X = sc.next();\n\t\tString Y = sc.next();\n\t\tString Z = sc.next();\n\t\tint n = Math.abs(A.indexOf(X)-A.indexOf(Y));\n\t\tint m = Math.abs(A.indexOf(Y)-A.indexOf(Z));\n\t\tint p = Math.abs(A.indexOf(X)-A.indexOf(Z));\n\t\tint x = Math.min(n, 12-n);\n\t\tint x1 = Math.max(n, 12-n);\n\t\tint y = Math.min(m, 12-m);\n\t\tint y1 = Math.max(m, 12-m);\n\t\tint z = Math.min(p, 12-p);\n\t\tint z1 = Math.max(p, 12-p);\n\t\tif(x==4 || x==3 || x1== 7){\n\t\t if(x1==7){\n\t\t if(z==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(z==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(y1==7){\n\t\t if(x==4 && z==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && z==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(z1==7){\n\t\t if(x==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t}\n\t\telse{\n\t\t System.out.println(\"strange\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "16ce6bd3660d0be544081e7f0b0df899", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "// Codeforces Beta Round #79\n// Problem C -- Vector\nimport java.util.*;\n\npublic class C{\n public static void main(String args[]){\n Scanner scanner = new Scanner(System.in);\n long p[][] = new long[3][2];\n for(int i = 0; i < 3; ++ i){\n for(int j = 0; j < 2; ++ j){\n p[i][j] = scanner.nextInt();\n }\n }\n for(int i = 0; i < 4; ++ i){\n long temp = p[0][0];\n p[0][0] = - p[0][1];\n p[0][1] = temp;\n long c[] = new long[2];\n c[0] = p[1][0] - p[0][0];\n c[1] = p[1][1] - p[0][1];\n long a[] = new long[2];\n a[0] = p[2][0];\n a[1] = p[2][1];\n long b[] = new long[2];\n b[0] = - p[2][1];\n b[1] = p[2][0];\n long delta = a[0] * b[1] - b[0] * a[1];\n if(delta == 0){\n if(c[0] != 0 || c[1] != 0){\n continue;\n }\n System.out.println(\"YES\");\n return;\n }\n if((b[1] * c[0] - c[1] * b[0]) % delta != 0){\n continue;\n }\n if((a[1] * c[0] - c[1] * a[0]) % delta != 0){\n continue;\n }\n System.out.println(\"YES\");\n return;\n }\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2413541c3144f77189e602dccbfe7a26", "src_uid": "cc8a8af1ba2b19bf081e379139542883", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n/**\n * Created with IntelliJ IDEA.\n * User: Lenovo\n * Date: 12-4-10\n * Time: \u4e0b\u534811:20\n * To change this template use File | Settings | File Templates.\n */\npublic class Main {\n private static long gcd(long a,long b)\n {\n return b==0 ? a : gcd(b,a%b);\n }\n private static boolean can(long a,long b,long c,long d,long e,long f)\n {\n long s=a*e-b*d;\n if (s!=0)\n {\n return (c*e-b*f)%s==0 && (a*f-c*d)%s==0;\n }\n if((a==0 && b==0 && c!=0) || (d==0 && e==0 && f!=0)) return false;\n else if(c*e==b*f && a*f==c*d)\n {\n long g=gcd(Math.abs(a),Math.abs(b));\n if(g==0)\n {\n if(a==0 && b==0) return c==0;\n else return c%Math.max(Math.abs(a),Math.abs(b))==0;\n }\n return c%g==0;\n }\n return false;\n }\n public static void main(String[] args)\n {\n long x1,y1,x2,y2,x3,y3;\n Scanner scan = new Scanner(System.in);\n x1=scan.nextLong();\n y1=scan.nextLong();\n x3=scan.nextLong();\n y3=scan.nextLong();\n x2=scan.nextLong();\n y2=scan.nextLong();\n System.out.println((can(x2,y2,x1-x3,y2,-x2,y1-y3)\n || can(x2,y2,x1+x3,y2,-x2,y1+y3)\n || can(x2,y2,x1-y3,y2,-x2,y1+x3)\n || can(x2,y2,x1+y3,y2,-x2,y1-x3)) ? \"YES\" : \"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd5c9391f6a6945be50ebf65f990a674", "src_uid": "cc8a8af1ba2b19bf081e379139542883", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.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; ir) r=i;\n return r;\n }\n long minL(long... nums) {\n long r = INFL;\n for (long i: nums)\n if (ir) r=i;\n return r;\n }\n double minD(double... nums) {\n double r = INFD;\n for (double i: nums)\n if (ir) r=i;\n return r;\n }\n long sumArr(int[] arr) {\n long res = 0;\n for (int i: arr)\n res+=i;\n return res;\n }\n long sumArr(long[] arr) {\n long res = 0;\n for (long i: arr)\n res+=i;\n return res;\n }\n double sumArr(double[] arr) {\n double res = 0;\n for (double i: arr)\n res+=i;\n return res;\n }\n\n long partsFitCnt(long partSize, long wholeSize) {\n return (partSize+wholeSize-1)/partSize;\n }\n\n boolean odd(long i) {\n return (i&1)==1;\n }\n\n long binpow(int x, int n) {\n long r = 1;\n while (n>0) {\n if ((n&1)!=0) r*=x;\n x*=x;\n n>>=1;\n }\n return r;\n }\n\n boolean isLetter(char c) {\n return (c>='a' && c<='z') || (c>='A' && c<='Z');\n }\n boolean isLowercase(char c) {\n return (c>='a' && c<='z');\n }\n boolean isUppercase(char c) {\n return (c>='A' && c<='Z');\n }\n boolean isDigit(char c) {\n return (c>='0' && c<='9');\n }\n \n String stringn(String s, int n) {\n if (n<1) return \"\";\n StringBuilder sb = new StringBuilder(s.length()*n);\n for (int i=0; i=bufLim) fillBuf(); \n return (char)buf[bufPos++];\n }\n boolean hasInput() throws IOException {\n if (bufPos>=bufLim) fillBuf();\n return bufPos' ') {\n sb.append(c);\n c = in.read();\n }\n return new String(sb);\n }\n String nextLine() throws IOException {\n StringBuilder sb = new StringBuilder();\n char c = in.read();\n while (c<=' ') c=in.read();\n while (c!='\\n' && c!='\\r') {\n sb.append(c);\n c = in.read();\n }\n return new String(sb);\n }\n int nextInt() throws IOException {\n int r = 0;\n char c = nextNonWhitespaceChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r=c-48;\n c = nextChar();\n while (c>='0' && c<='9') {\n r*=10;\n r+=c-48;\n c=nextChar();\n }\n return neg ? -r:r;\n }\n long nextLong() throws IOException {\n long r = 0;\n char c = nextNonWhitespaceChar();\n boolean neg = false;\n if (c=='-') neg=true;\n else r = c-48;\n c = nextChar();\n while (c>='0' && c<='9') {\n r*=10L;\n r+=c-48L;\n c=nextChar();\n }\n return neg ? -r:r;\n }\n double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextWord());\n }\n int[] nextArr(int size) throws NumberFormatException, IOException {\n int[] arr = new int[size];\n for (int i=0; i>mapi=mapi(a);// pw.println(mapi); PriorityQueue\n>>pq=new PriorityQueue<>((x,y)->y.getValue().size\n()-x.getValue().size());pq.addAll(list(mapi.entrySet().stream()));int max=pq.poll\n().getValue().size();int num=(int)Math.ceil(1.0*max/k)*mapi.size()*k;pw.println(\nnum-n);}static public void _main(String[]args)throws IOException{new p001032A().run\n();}}\n//end p001032A.java\n//begin net/leksi/contest/Pair.java\nstatic private class Pair{private K k;private V v;public Pair(final K t,final\n V u){this.k=t;this.v=u;}public K getKey(){return k;}public V getValue(){return \nv;}}\n//end net/leksi/contest/Pair.java\n//begin net/leksi/contest/Solver.java\nstatic private abstract class Solver{protected String nameIn=null;protected String\n nameOut=null;protected boolean singleTest=false;protected boolean preprocessDebug\n=false;protected boolean doNotPreprocess=false;protected PrintStream debugPrintStream\n=null;protected Scanner sc=null;protected PrintWriter pw=null;final static String\n SPACE=\" \";final static String SPACES=\"\\\\s+\";private void process()throws IOException\n{if(!singleTest){int t=lineToIntArray()[0];while(t-->0){solve();}}else{solve();}\n}abstract protected void solve()throws IOException;protected int[]lineToIntArray\n()throws IOException{return Arrays.stream(sc.nextLine().trim().split(SPACES)).mapToInt\n(Integer::valueOf).toArray();}protected long[]lineToLongArray()throws IOException\n{return Arrays.stream(sc.nextLine().trim().split(SPACES)).mapToLong(Long::valueOf\n).toArray();}protected void run()throws IOException{boolean done=false;try{if(nameIn\n!=null && new File(nameIn).exists()){try(FileInputStream fis=new FileInputStream\n(nameIn);PrintWriter pw0=select_output();){done=true;sc=new Scanner(fis);pw=pw0;\nprocess();}}}catch(IOException ex){}catch(AccessControlException ex){}if(!done){\ntry(PrintWriter pw0=select_output();){sc=new Scanner(System.in);pw=pw0;process()\n;}}}private PrintWriter select_output()throws FileNotFoundException{if(nameOut!=\nnull){return new PrintWriter(nameOut);}return new PrintWriter(System.out);}public\n static Map>mapi(final int[]a){return IntStream.range(0,a.\nlength).collect(()->new TreeMap>(),(res,i)->{if(!res.containsKey\n(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));}else{res.get(a[\ni]).add(i);}},Map::putAll);}public static Map>mapi(final long\n[]a){return IntStream.range(0,a.length).collect(()->new TreeMap>(),(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors\n.toList()));}else{res.get(a[i]).add(i);}},Map::putAll);}public staticMap>mapi(final T[]a){return IntStream.range(0,a.length).collect(()->new TreeMap\n>(),(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(\ni).collect(Collectors.toList()));}else{res.get(a[i]).add(i);}},Map::putAll);}public\n staticMap>mapi(final T[]a,Comparatorcmp){return IntStream\n.range(0,a.length).collect(()->new TreeMap>(cmp),(res,i)->{if(!res\n.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));}else\n{res.get(a[i]).add(i);}},Map::putAll);}public static Map>mapi\n(final IntStream a){int[]i=new int[]{0};return a.collect(()->new TreeMap>(),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect\n(Collectors.toList()));}else{res.get(v).add(i[0]);}i[0]++;},Map::putAll);}public\n static Map>mapi(final LongStream a){int[]i=new int[]{0};return\n a.collect(()->new TreeMap>(),(res,v)->{if(!res.containsKey(v\n)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));}else{res.get(v).add(\ni[0]);}i[0]++;},Map::putAll);}public staticMap>mapi(final Stream\na,Comparatorcmp){int[]i=new int[]{0};return a.collect(()->new TreeMap>(cmp),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect\n(Collectors.toList()));}else{res.get(v).add(i[0]);}},Map::putAll);}public static\nMap>mapi(final Streama){int[]i=new int[]{0};return a.collect\n(()->new TreeMap>(),(res,v)->{if(!res.containsKey(v)){res.put(v,\nStream.of(i[0]).collect(Collectors.toList()));}else{res.get(v).add(i[0]);}},Map::\nputAll);}public static Listlisti(final int[]a){return IntStream.range(0,a\n.length).mapToObj(i->new int[]{a[i],i}).collect(Collectors.toList());}public static\n Listlisti(final long[]a){return IntStream.range(0,a.length).mapToObj(i->\nnew long[]{a[i],i}).collect(Collectors.toList());}public staticList>listi(final T[]a){return IntStream.range(0,a.length).mapToObj(i->new Pair(a[i],i)).collect(Collectors.toList());}public static Listlisti(final IntStream\n a){int[]i=new int[]{0};return a.mapToObj(v->new int[]{v,i[0]++}).collect(Collectors\n.toList());}public static Listlisti(final LongStream a){int[]i=new int[]\n{0};return a.mapToObj(v->new long[]{v,i[0]++}).collect(Collectors.toList());}public\n staticList>listi(final Streama){int[]i=new int[]{0};return\n a.map(v->new Pair(v,i[0]++)).collect(Collectors.toList());}public static\n String join(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect\n(Collectors.joining(SPACE));}public static String join(final long[]a){return Arrays\n.stream(a).mapToObj(Long::toString).collect(Collectors.joining(SPACE));}public static\nString join(final T[]a){return Arrays.stream(a).map(v->Objects.toString(v)).collect\n(Collectors.joining(SPACE));}public staticString join(final T[]a,final Function\ntoString){return Arrays.stream(a).map(v->toString.apply(v)).collect(Collectors\n.joining(SPACE));}public staticString join(final Collectiona){return a.stream\n().map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));}public static\nString join(final Collectiona,final FunctiontoString){return a.stream\n().map(v->toString.apply(v)).collect(Collectors.joining(SPACE));}public staticString join(final Streama){return a.map(v->Objects.toString(v)).collect(Collectors\n.joining(SPACE));}public staticString join(final Streama,final FunctiontoString){return a.map(v->toString.apply(v)).collect(Collectors.joining(SPACE\n));}public staticString join(final IntStream a){return a.mapToObj(Integer::toString\n).collect(Collectors.joining(SPACE));}public staticString join(final LongStream\n a){return a.mapToObj(Long::toString).collect(Collectors.joining(SPACE));}public\n static Listlist(final int[]a){return Arrays.stream(a).mapToObj(Integer\n::valueOf).collect(Collectors.toList());}public static Listlist(final IntStream\n a){return a.mapToObj(Integer::valueOf).collect(Collectors.toList());}public static\n Listlist(final long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect\n(Collectors.toList());}public static Listlist(final LongStream a){return a\n.mapToObj(Long::valueOf).collect(Collectors.toList());}public staticListlist\n(final Streama){return a.collect(Collectors.toList());}public staticListlist(final T[]a){return Arrays.stream(a).collect(Collectors.toList());}}\n//end net/leksi/contest/Solver.java\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "122a1c37081ee219257852e16ec33eb1", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class P_1032A {\t\n\tpublic static void main(String[] args) {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\ttry {\n\t\t\tint n = Integer.parseInt(reader.readLine().split(\" \")[1]);\n\t\t\tint[] numList = new int[101];\n\t\t\tString[] val_arr = reader.readLine().split(\" \");\n\t\t\tfor(String tmp : val_arr) {\n\t\t\t\tnumList[Integer.parseInt(tmp)]++;\n\t\t\t}\n\t\t\tArrays.sort(numList);\n\t\t\tint max_val = numList[100]%n == 0? numList[100]: n*((int)numList[100]/n+1);\n\t\t\tint answer = 0;\n\t\t\tfor(int i = 1; i < numList.length; i++) {\n\t\t\t\tif(numList[i] == 0) \n\t\t\t\t\tcontinue;\n\t\t\t\tanswer += (max_val - numList[i]);\n\t\t\t}\n\t\t\tSystem.out.println(answer);\n\t\t} catch (NumberFormatException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\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}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eb64743079d938db54f7e2846bf06a06", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\npublic class Utensils {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint guest = s.nextInt();\n\t\tint remaining = s.nextInt();\n\t\tMap map = new HashMap();\n\t\tint count = 0;\n\t\tfor (int i = 0; i < remaining; i++) {\n\t\t\tint utensils = s.nextInt();\n\t\t\tif (map.containsKey(utensils))\n\t\t\t\tmap.put(utensils, count++);\n\t\t\telse\n\t\t\t\tmap.put(utensils, 1);\n\n\t\t}\n\t\tint max = 0;\n\t\tfor (Entry entry : map.entrySet()) {\n\t\t\tif (max Integer.parseInt(nums[index]))\n\t\t\t.toArray();\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scanner = new Scanner(System.in);\n\t\t\n\t\t\n\t\tint nk[] = Util.toIntArray(scanner.nextLine());\t\t\n\t\t\n\t\tint n = nk[0], k = nk[1];\n\t\t\n\t\tMap itemsCount = Arrays.stream(Util.toIntArray(scanner.nextLine()))\n\t\t\t.boxed()\n\t\t\t.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));\n\t\t\n\t\t//System.out.println(itemsCount);\n\t\t\n\t\tLong maxItemCount = itemsCount.entrySet().stream().max((e1, e2) -> Long.compare(e1.getValue(), e2.getValue())).get().getValue();\n\t\t\n\t\tint maxDishes = (int) (maxItemCount * Math.round(Math.ceil(maxItemCount / k))) * itemsCount.size();\n\t\t\n\t\t\n\t\tSystem.out.println(maxDishes - n);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39572fca8ae8c146431e69f7afc031bb", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f", "difficulty": 900.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/24/11\n * Time: 8:54 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.FileReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.util.Arrays;\n\npublic class TaskD extends Thread {\n\n public TaskD() {\n this.input = new BufferedReader(new InputStreamReader(System.in));\n this.output = new PrintWriter(System.out);\n this.setPriority(Thread.MAX_PRIORITY);\n }\n\n\n static class Matrix {\n long [][]grid;\n long [][]helper;\n public Matrix(int size, boolean E) {\n this.grid = new long[size][size];\n this.helper = new long [size][size];\n if (E) {\n for (int i = 0; i < grid.length; ++i) {\n grid[i][i] = 1;\n }\n }\n }\n\n public Matrix pow(long power) {\n Matrix result = new Matrix(grid.length, true);\n Matrix stat = new Matrix(grid.length, false);\n for (int i = 0; i < grid.length; ++i) {\n stat.grid[i] = this.grid[i].clone();\n }\n for (; power != 0; power >>= 1) {\n if ((power & 1) == 1) {\n result.multiply(stat);\n }\n stat.multiply(stat);\n }\n return result;\n }\n\n\n private void multiply(Matrix another) {\n assert(this.grid.length == another.grid.length);\n for (long[] current : helper) {\n Arrays.fill(current, 0);\n }\n for (int i = 0; i < grid.length; ++i) {\n for (int j = 0; j < grid.length; ++j) {\n for (int k = 0; k < grid.length; ++k) {\n helper[i][j] += (grid[i][k] * another.grid[k][j]) % MODULO;\n }\n helper[i][j] %= MODULO;\n }\n }\n for (int i = 0; i < grid.length; ++i) {\n System.arraycopy(helper[i], 0, grid[i], 0, grid.length);\n }\n }\n }\n\n\n static class Rule {\n char letter;\n char value;\n public Rule(char letter, char value) {\n this.letter = letter;\n this.value = value;\n }\n }\n\n private void generate(int index) {\n if (index == initial.length) {\n states[SIZE++] = initial.clone();\n } else {\n for (char value = 0; value < rules[index].value; ++value) {\n initial[index] = value;\n generate(index + 1);\n }\n }\n }\n\n private boolean isFinal(int index) {\n for (char letter = 'A'; letter <= 'Z'; ++letter) {\n boolean was = false, isGood = false;\n for (int i = 0; i < rules.length; ++i) {\n if (rules[i].letter == letter) {\n was = true;\n isGood |= states[index][i] == 0;\n }\n }\n if (was && !isGood) {\n return false;\n }\n }\n return true;\n }\n\n\n private void solve() throws Throwable {\n long n = nextLong();\n int c = nextInt();\n rules = new Rule[c];\n int total = 1;\n for (int i = 0; i < c; ++i) {\n rules[i] = new Rule(nextToken().charAt(0), (char)(nextInt()));\n total *= rules[i].value;\n }\n initial = new char [c];\n states = new char[total][];\n generate(0);\n Matrix operator = new Matrix(total, false);\n char []helper;\n for (int state = 0; state < total; ++state) {\n helper = states[state].clone();\n for (int i = 0; i < helper.length; ++i) {\n helper[i] = (char)((helper[i] + 1) % rules[i].value);\n for (int where = 0; where < total; ++where) {\n boolean ok = true;\n for (int index = 0; index < helper.length; ++index) {\n ok &= helper[index] == states[where][index];\n }\n if (ok) {\n operator.grid[state][where]++;\n break;\n }\n }\n }\n }\n Matrix finish = operator.pow(n);\n long result = 0;\n for (int current = 0; current < total; ++current) {\n if (isFinal(current)) {\n result = (result + finish.grid[0][current]) % MODULO;\n }\n }\n output.println(result);\n }\n\n public void run() {\n try {\n solve();\n } catch (Throwable e) {\n System.err.println(e.getMessage());\n e.printStackTrace();\n System.exit(666);\n } finally {\n output.flush();\n output.close();\n }\n }\n\n\n public static void main(String[] args) {\n new TaskD().start();\n }\n\n private String nextToken() throws IOException {\n while (tokens == null || !tokens.hasMoreTokens()) {\n tokens = new StringTokenizer(input.readLine());\n }\n return tokens.nextToken();\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n private int SIZE = 0;\n private static final int MODULO = 12345;\n private char [][]states;\n private char []initial;\n private Rule []rules;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6e37fe7ee6a5231e60235e86b73e7df7", "src_uid": "76d4684d26dac380713a566a1e277c91", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/24/11\n * Time: 8:54 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.FileReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.util.Arrays;\n\npublic class TaskD extends Thread {\n\n public TaskD() {\n this.input = new BufferedReader(new InputStreamReader(System.in));\n this.output = new PrintWriter(System.out);\n this.setPriority(Thread.MAX_PRIORITY);\n }\n\n\n static class Matrix {\n long[][] grid;\n long[][] helper;\n\n public Matrix(int size, boolean E) {\n this.grid = new long[size][size];\n this.helper = new long[size][size];\n if (E) {\n for (int i = 0; i < grid.length; ++i) {\n grid[i][i] = 1;\n }\n }\n }\n\n public Matrix pow(long power) {\n Matrix result = new Matrix(grid.length, true);\n Matrix stat = new Matrix(grid.length, false);\n for (int i = 0; i < grid.length; ++i) {\n stat.grid[i] = this.grid[i].clone();\n }\n while (power != 0) {\n if ((power & 1) == 1) {\n result.multiply(stat);\n --power;\n } else {\n stat.multiply(stat);\n power >>= 1;\n }\n }\n return result;\n }\n\n\n private void multiply(Matrix another) {\n for (long[] current : helper) {\n Arrays.fill(current, 0);\n }\n for (int i = 0; i < grid.length; ++i) {\n for (int j = 0; j < grid.length; ++j) {\n for (int k = 0; k < grid.length; ++k) {\n helper[i][j] += (grid[i][k] * another.grid[k][j]) % MODULO;\n }\n helper[i][j] %= MODULO;\n }\n }\n for (int i = 0; i < grid.length; ++i) {\n System.arraycopy(helper[i], 0, grid[i], 0, grid.length);\n }\n }\n }\n\n\n static class Rule {\n char letter;\n char value;\n\n public Rule(char letter, char value) {\n this.letter = letter;\n this.value = value;\n }\n }\n\n private void generate(int index) {\n if (index == initial.length) {\n states[SIZE++] = initial.clone();\n } else {\n for (char value = 0; value < rules[index].value; ++value) {\n initial[index] = value;\n generate(index + 1);\n }\n }\n }\n\n private boolean isFinal(int index) {\n for (char letter = 'A'; letter <= 'Z'; ++letter) {\n boolean was = false, isGood = false;\n for (int i = 0; i < rules.length; ++i) {\n if (rules[i].letter == letter) {\n was = true;\n isGood |= states[index][i] == 0;\n }\n }\n if (was && !isGood) {\n return false;\n }\n }\n return true;\n }\n\n\n private void solve() throws Throwable {\n long n = nextLong();\n int c = nextInt();\n int s = c;\n c = 0;\n rules = new Rule[s];\n int total = 1;\n for (c = 0; c < s;) {\n rules[c] = new Rule(nextToken().charAt(0), (char) (nextInt()));\n boolean was = false;\n for (int q = 0; q < c; ++q) {\n if (rules[q].letter == rules[c].letter && rules[q].value == rules[c].value) {\n was = true;\n break;\n }\n }\n if (!was){\n total *= rules[c++].value;\n }\n }\n initial = new char[c];\n states = new char[total][];\n generate(0);\n Matrix operator = new Matrix(total, false);\n for (int from = 0; from < total; ++from) {\n for (char letter = 'A'; letter <= 'Z'; ++letter) {\n boolean isPresent = false;\n char []helper = states[from].clone();\n for (int i = 0; i < c; ++i) {\n if (rules[i].letter == letter) {\n isPresent = true;\n helper[i] = (char)((helper[i] + 1) % rules[i].value);\n }\n }\n if (isPresent) {\n for (int to = 0; to < states.length; ++to) {\n boolean ok = true;\n for (int index = 0; index < c; ++index) {\n ok &= states[to][index] == helper[index];\n }\n if (ok) {\n operator.grid[from][to] = 1;\n break;\n }\n }\n }\n }\n }\n\n Matrix finish = operator.pow(n);\n long result = 0;\n for (int current = 0; current < total; ++current) {\n if (isFinal(current)) {\n result = (result + finish.grid[0][current]) % MODULO;\n }\n }\n output.println(result);\n }\n\n public void run() {\n try {\n solve();\n } catch (Throwable e) {\n System.err.println(e.getMessage());\n e.printStackTrace();\n System.exit(666);\n } finally {\n output.flush();\n output.close();\n }\n }\n\n\n public static void main(String[] args) {\n new TaskD().start();\n }\n\n private String nextToken() throws IOException {\n while (tokens == null || !tokens.hasMoreTokens()) {\n tokens = new StringTokenizer(input.readLine());\n }\n return tokens.nextToken();\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private int SIZE = 0;\n private static final int MODULO = 12345;\n private char[][] states;\n private char[] initial;\n private Rule[] rules;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "952218c35a5c3d840661569263bcd970", "src_uid": "76d4684d26dac380713a566a1e277c91", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/24/11\n * Time: 8:54 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.FileReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.util.Arrays;\n\npublic class TaskD extends Thread {\n\n public TaskD() {\n this.input = new BufferedReader(new InputStreamReader(System.in));\n this.output = new PrintWriter(System.out);\n this.setPriority(Thread.MAX_PRIORITY);\n }\n\n\n static class Matrix {\n long [][]grid;\n long [][]helper;\n public Matrix(int size, boolean E) {\n this.grid = new long[size][size];\n this.helper = new long [size][size];\n if (E) {\n for (int i = 0; i < grid.length; ++i) {\n grid[i][i] = 1;\n }\n }\n }\n\n public Matrix pow(long power) {\n Matrix result = new Matrix(grid.length, true);\n Matrix stat = new Matrix(grid.length, false);\n for (int i = 0; i < grid.length; ++i) {\n stat.grid[i] = this.grid[i].clone();\n }\n for (; power != 0; power >>= 1) {\n if ((power & 1) == 1) {\n result.multiply(stat);\n }\n stat.multiply(stat);\n }\n return result;\n }\n\n\n private void multiply(Matrix another) {\n for (long[] current : helper) {\n Arrays.fill(current, 0);\n }\n for (int i = 0; i < grid.length; ++i) {\n for (int j = 0; j < grid.length; ++j) {\n for (int k = 0; k < grid.length; ++k) {\n helper[i][j] += (grid[i][k] * another.grid[k][j]) % MODULO;\n }\n helper[i][j] %= MODULO;\n }\n }\n for (int i = 0; i < grid.length; ++i) {\n System.arraycopy(helper[i], 0, grid[i], 0, grid.length);\n }\n }\n }\n\n\n static class Rule {\n char letter;\n char value;\n public Rule(char letter, char value) {\n this.letter = letter;\n this.value = value;\n }\n }\n\n private void generate(int index) {\n if (index == initial.length) {\n states[SIZE++] = initial.clone();\n } else {\n for (char value = 0; value < rules[index].value; ++value) {\n initial[index] = value;\n generate(index + 1);\n }\n }\n }\n\n private boolean isFinal(int index) {\n for (char letter = 'A'; letter <= 'Z'; ++letter) {\n boolean was = false, isGood = false;\n for (int i = 0; i < rules.length; ++i) {\n if (rules[i].letter == letter) {\n was = true;\n isGood |= states[index][i] == 0;\n }\n }\n if (was && !isGood) {\n return false;\n }\n }\n return true;\n }\n\n\n private void solve() throws Throwable {\n long n = nextLong();\n int c = nextInt();\n rules = new Rule[c];\n int total = 1;\n for (int i = 0; i < c; ++i) {\n rules[i] = new Rule(nextToken().charAt(0), (char)(nextInt()));\n total *= rules[i].value;\n }\n initial = new char [c];\n states = new char[total][];\n generate(0);\n Matrix operator = new Matrix(total, false);\n char []helper;\n for (int state = 0; state < total; ++state) {\n for (int i = 0; i < states[state].length; ++i) {\n helper = states[state].clone();\n helper[i] = (char)((helper[i] + 1) % rules[i].value);\n for (int where = 0; where < total; ++where) {\n boolean ok = true;\n for (int index = 0; index < helper.length; ++index) {\n ok &= helper[index] == states[where][index];\n }\n if (ok) {\n operator.grid[state][where]++;\n break;\n }\n }\n\n }\n }\n Matrix finish = operator.pow(n);\n long result = 0;\n for (int current = 0; current < total; ++current) {\n if (isFinal(current)) {\n result = (result + finish.grid[0][current]) % MODULO;\n }\n }\n output.println(result);\n }\n\n public void run() {\n try {\n solve();\n } catch (Throwable e) {\n System.err.println(e.getMessage());\n e.printStackTrace();\n System.exit(666);\n } finally {\n output.flush();\n output.close();\n }\n }\n\n\n public static void main(String[] args) {\n new TaskD().start();\n }\n\n private String nextToken() throws IOException {\n while (tokens == null || !tokens.hasMoreTokens()) {\n tokens = new StringTokenizer(input.readLine());\n }\n return tokens.nextToken();\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n private int SIZE = 0;\n private static final int MODULO = 12345;\n private char [][]states;\n private char []initial;\n private Rule []rules;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5a89a9dee0613867a67d3016abcf4ece", "src_uid": "76d4684d26dac380713a566a1e277c91", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/24/11\n * Time: 8:54 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.FileReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.util.Arrays;\n\npublic class TaskD extends Thread {\n\n public TaskD() {\n this.input = new BufferedReader(new InputStreamReader(System.in));\n this.output = new PrintWriter(System.out);\n this.setPriority(Thread.MAX_PRIORITY);\n }\n\n\n static class Matrix {\n long[][] grid;\n long[][] helper;\n\n public Matrix(int size, boolean E) {\n this.grid = new long[size][size];\n this.helper = new long[size][size];\n if (E) {\n for (int i = 0; i < grid.length; ++i) {\n grid[i][i] = 1;\n }\n }\n }\n\n public Matrix pow(long power) {\n Matrix result = new Matrix(grid.length, true);\n Matrix stat = new Matrix(grid.length, false);\n for (int i = 0; i < grid.length; ++i) {\n stat.grid[i] = this.grid[i].clone();\n }\n while (power != 0) {\n if ((power & 1) == 1) {\n result.multiply(stat);\n --power;\n } else {\n stat.multiply(stat);\n power >>= 1;\n }\n }\n return result;\n }\n\n\n private void multiply(Matrix another) {\n for (long[] current : helper) {\n Arrays.fill(current, 0);\n }\n for (int i = 0; i < grid.length; ++i) {\n for (int j = 0; j < grid.length; ++j) {\n for (int k = 0; k < grid.length; ++k) {\n helper[i][j] += (grid[i][k] * another.grid[k][j]) % MODULO;\n }\n helper[i][j] %= MODULO;\n }\n }\n for (int i = 0; i < grid.length; ++i) {\n System.arraycopy(helper[i], 0, grid[i], 0, grid.length);\n }\n }\n }\n\n\n static class Rule {\n char letter;\n char value;\n\n public Rule(char letter, char value) {\n this.letter = letter;\n this.value = value;\n }\n }\n\n private void generate(int index) {\n if (index == initial.length) {\n states[SIZE++] = initial.clone();\n } else {\n for (char value = 0; value < rules[index].value; ++value) {\n initial[index] = value;\n generate(index + 1);\n }\n }\n }\n\n private boolean isFinal(int index) {\n for (char letter = 'A'; letter <= 'Z'; ++letter) {\n boolean was = false, isGood = false;\n for (int i = 0; i < rules.length; ++i) {\n if (rules[i].letter == letter) {\n was = true;\n isGood |= states[index][i] == 0;\n }\n }\n if (was && !isGood) {\n return false;\n }\n }\n return true;\n }\n\n\n private void solve() throws Throwable {\n long n = nextLong();\n int c = nextInt();\n int s = c;\n c = 0;\n rules = new Rule[s];\n int total = 1;\n for (c = 0; c < s;) {\n rules[c] = new Rule(nextToken().charAt(0), (char) (nextInt()));\n boolean was = false;\n for (int q = 0; q < c; ++q) {\n if (rules[q].letter == rules[c].letter && rules[q].value == rules[c].value) {\n was = true;\n break;\n }\n }\n if (!was){\n total *= rules[c++].value;\n }\n }\n initial = new char[c];\n states = new char[total][];\n generate(0);\n Matrix operator = new Matrix(total, false);\n for (int from = 0; from < total; ++from) {\n for (char letter = 'A'; letter <= 'Z'; ++letter) {\n boolean isPresent = false;\n char []helper = states[from].clone();\n for (int i = 0; i < c; ++i) {\n if (rules[i].letter == letter) {\n isPresent = true;\n helper[i] = (char)((helper[i] + 1) % rules[i].value);\n }\n }\n if (isPresent) {\n for (int to = 0; to < states.length; ++to) {\n boolean ok = true;\n for (int index = 0; index < c; ++index) {\n ok &= states[to][index] == helper[index];\n }\n if (ok) {\n operator.grid[from][to]++;\n break;\n }\n }\n }\n }\n }\n\n Matrix finish = operator.pow(n);\n long result = 0;\n for (int current = 0; current < total; ++current) {\n if (isFinal(current)) {\n result = (result + finish.grid[0][current]) % MODULO;\n }\n }\n output.println(result);\n }\n\n public void run() {\n try {\n solve();\n } catch (Throwable e) {\n System.err.println(e.getMessage());\n e.printStackTrace();\n System.exit(666);\n } finally {\n output.flush();\n output.close();\n }\n }\n\n\n public static void main(String[] args) {\n new TaskD().start();\n }\n\n private String nextToken() throws IOException {\n while (tokens == null || !tokens.hasMoreTokens()) {\n tokens = new StringTokenizer(input.readLine());\n }\n return tokens.nextToken();\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private int SIZE = 0;\n private static final int MODULO = 12345;\n private char[][] states;\n private char[] initial;\n private Rule[] rules;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "44683c5a4a5a4d99c98a37b2e7d49575", "src_uid": "76d4684d26dac380713a566a1e277c91", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class pigeon {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0; i < n; i++) a[i] = scan.nextInt();\n\t\tint min = a[0];\n\t\tfor(int i = 1; i < n; i++) if(a[i] < min) min = a[i];\n\t\tSystem.out.println(2 + (a[2] ^ min));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "44fdb4c6613358923ad6fcecea501cc3", "src_uid": "a9eb85dfaa3c50ed488d41da4f29c697", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class bird {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint min = 50;\n\t\tint third = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(i == 2) {\n\t\t\t\tthird = in.nextInt();\n\t\t\t\tmin = Math.min(min, third);\n\t\t\t}\n\t\t\tmin = Math.min(min, in.nextInt());\n\t\t}\n\t\tSystem.out.println(2+(third^min));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce055c16120f4b4d2b67db4a9c9da165", "src_uid": "a9eb85dfaa3c50ed488d41da4f29c697", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Test{\n public static void main(String[] args){\n Scanner scan=new Scanner(System.in);\n int nb=scan.nextInt();\n int[] T=new int[nb];\n for(int i=0;i {\n\t\tpublic int row, col;\n\t\t\n\t\tpublic Cell(String cell) {\n\t\t\trow = cell.charAt(0) - 'a';\n\t\t\tcol = cell.charAt(1) - '1';\n\t\t}\n\t\t\n\t\tpublic Cell(int row, int col) {\n\t\t\tthis.row = row;\n\t\t\tthis.col = col;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Cell other) {\n\t\t\tif(row == other.row)\n\t\t\t\treturn col - other.col;\n\t\t\telse\n\t\t\t\treturn row - other.row;\n\t\t}\n\t}\n\t\n\tint[][] board = new int[8][8];\n\t\n\tboolean ok(Cell cell) {\n\t\treturn cell.row >= 0 && cell.row < 8 && cell.col >= 0 && cell.col < 8;\n\t}\n\t\n\tvoid refresh(Cell king, TreeSet knights) {\n\t\tfor(int i = 0; i < 8; ++i)\n\t\t\tfor(int j = 0; j < 8; ++j)\n\t\t\t\tboard[i][j] = 0;\n\t\t\n\t\tfinal Cell[] king_ways = {\n\t\t\t\tnew Cell(king.row + 1, king.col),\n\t\t\t\tnew Cell(king.row + 1, king.col + 1),\n\t\t\t\tnew Cell(king.row, king.col + 1),\n\t\t\t\tnew Cell(king.row - 1, king.col),\n\t\t\t\tnew Cell(king.row - 1, king.col - 1),\n\t\t\t\tnew Cell(king.row, king.col - 1),\n\t\t\t\tnew Cell(king.row + 1, king.col - 1),\n\t\t\t\tnew Cell(king.row - 1, king.col + 1)\n\t\t};\n\t\t\n\t\tfor(Cell w : king_ways)\n\t\t\tif(ok(w))\n\t\t\t\tboard[w.row][w.col] = 1;\n\t\t\n\t\tfor(Cell k : knights)\n\t\t\tfor(int i = 0; i < 8; ++i) {\n\t\t\t\tif(i != k.row) board[i][k.col] = 1;\n\t\t\t\tif(i != k.col) board[k.row][i] = 1;\n\t\t\t}\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tCell wknight1 = new Cell(nextToken());\n\t\tCell wknight2 = new Cell(nextToken());\n\t\tCell wking = new Cell(nextToken());\n\t\tCell bking = new Cell(nextToken());\n\t\t\n\t\tTreeSet knights = new TreeSet();\n\t\tknights.add(wknight1);\n\t\tknights.add(wknight2);\n\t\t\n\t\trefresh(wking, knights);\n\t\t\n\t\tCell[] ws = {\n\t\t\t\tnew Cell(bking.row, bking.col),\n\t\t\t\tnew Cell(bking.row + 1, bking.col),\n\t\t\t\tnew Cell(bking.row + 1, bking.col + 1),\n\t\t\t\tnew Cell(bking.row, bking.col + 1),\n\t\t\t\tnew Cell(bking.row - 1, bking.col),\n\t\t\t\tnew Cell(bking.row - 1, bking.col - 1),\n\t\t\t\tnew Cell(bking.row, bking.col - 1),\n\t\t\t\tnew Cell(bking.row + 1, bking.col - 1),\n\t\t\t\tnew Cell(bking.row - 1, bking.col + 1)\n\t\t};\n\t\t\n\t\tboolean checkmate = true;\n\t\t\n\t\tfor(Cell w : ws) {\n\t\t\tif(ok(w))\n\t\t\t\tif(board[w.row][w.col] == 0) {\n\t\t\t\t\tif(knights.contains(w)) {\n\t\t\t\t\t\tknights.remove(w);\n\t\t\t\t\t\trefresh(wking, knights);\n\t\t\t\t\t\tif(board[w.row][w.col] == 0) {\n\t\t\t\t\t\t\tcheckmate = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tknights.add(w);\n\t\t\t\t\t\trefresh(wking, knights);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcheckmate = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\t\n\t\toutput.println(checkmate ? \"CHECKMATE\" : \"OTHER\");\n\t}\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\t\toutput = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tinput.close();\n\t\t\toutput.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\tBufferedReader input;\n\tPrintWriter output;\n\tStringTokenizer tok;\n\t\n\tString nextToken() throws IOException {\n\t\twhile(tok == null || !tok.hasMoreElements())\n\t\t\ttok = new StringTokenizer(input.readLine());\n\t\t\n\t\treturn tok.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.valueOf(nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.valueOf(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.valueOf(nextToken());\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d35c1fa01980081e7563efbcd831cf57", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n\n\npublic class Main {\n FastScanner in = new FastScanner(System.in); \n PrintWriter out = new PrintWriter(System.out);\n public static void main(String[]args){ \n new Main().solve(); \n }\n \n void solve(){\n int[][]tab = new int[8][8];\n int[][]black = new int[8][8];\n String a = in.next();\n String b = in.next();\n String v = in.next();\n String n = in.next();\n \n char c = v.charAt(0);\n int x = 0;\n int y = Integer.parseInt( \"\" + v.charAt(1))-1;\n if (c=='a'){x = 0;}\n if (c=='b'){x = 1;}\n if (c=='c'){x = 2;}\n if (c=='d'){x = 3;}\n if (c=='e'){x = 4;}\n if (c=='f'){x = 5;}\n if (c=='g'){x = 6;}\n if (c=='h'){x = 7;}\n tab[x][y] = 9;\n int tmpx = -1, tmpy = -1;\n \n tmpx = x-1;\n tmpy = y-1; \n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n \n tmpx = x-1;\n tmpy = y;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n \n tmpx = x-1;\n tmpy = y+1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n \n tmpx = x;\n tmpy = y-1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n \n tmpx = x;\n tmpy = y + 1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n \n tmpx = x+1;\n tmpy = y;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n \n tmpx = x+1;\n tmpy = y+1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n \n tmpx = x+1;\n tmpy = y-1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n tab[tmpx][tmpy] = 9;\n }\n tab[x][y] = 1;\n c = a.charAt(0);\n x = 0;\n y = Integer.parseInt( \"\" + a.charAt(1))-1;\n if (c=='a'){x = 0;}\n if (c=='b'){x = 1;}\n if (c=='c'){x = 2;}\n if (c=='d'){x = 3;}\n if (c=='e'){x = 4;}\n if (c=='f'){x = 5;}\n if (c=='g'){x = 6;}\n if (c=='h'){x = 7;}\n tab[x][y] = 9;\n for (int i = 0; i<8; i++){\n if (tab[i][y] == 1)break;\n else tab[i][y] = 9; \n }\n for (int i = 0; i<8; i++){\n if (tab[x][i] == 1)break;\n else tab[x][i] = 9;\n }\n tab[x][y] = 1;\n \n \n c = b.charAt(0);\n x = 0;\n y = Integer.parseInt( \"\" + b.charAt(1))-1;\n if (c=='a'){x = 0;}\n if (c=='b'){x = 1;}\n if (c=='c'){x = 2;}\n if (c=='d'){x = 3;}\n if (c=='e'){x = 4;}\n if (c=='f'){x = 5;}\n if (c=='g'){x = 6;}\n if (c=='h'){x = 7;}\n tab[x][y] = 9;\n for (int i = 0; i<8; i++){\n if (tab[i][y] == 1)break;\n else tab[i][y] = 9; \n }\n for (int i = 0; i<8; i++){\n if (tab[x][i] == 1)break;\n else tab[x][i] = 9;\n }\n tab[x][y] = 1;\n \n ///////////////\n c = n.charAt(0);\n x = 0;\n y = Integer.parseInt( \"\" + n.charAt(1))-1;\n if (c=='a'){x = 0;}\n if (c=='b'){x = 1;}\n if (c=='c'){x = 2;}\n if (c=='d'){x = 3;}\n if (c=='e'){x = 4;}\n if (c=='f'){x = 5;}\n if (c=='g'){x = 6;}\n if (c=='h'){x = 7;}\n black[x][y] = 5;\n tmpx = -1; tmpy = -1;\n \n tmpx = x-1;\n tmpy = y-1; \n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n \n tmpx = x-1;\n tmpy = y;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n \n tmpx = x-1;\n tmpy = y+1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n \n tmpx = x;\n tmpy = y-1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n \n tmpx = x;\n tmpy = y + 1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n \n tmpx = x+1;\n tmpy = y;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n \n tmpx = x+1;\n tmpy = y+1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n \n tmpx = x+1;\n tmpy = y-1;\n if (tmpx>=0 && tmpy>=0 && tmpx<=7 && tmpy<=7){\n black[tmpx][tmpy] = 5;\n }\n ////\n boolean f = false;\n for (int i = 0; i<8; i++){\n for (int j = 0; j<8; j++){\n if (black[i][j]==5){\n if (tab[i][j]==1 || tab[i][j]==0)f = true;;\n }\n }\n }\n if (f)System.out.println(\"OTHER\");\n else System.out.println(\"CHECKMATE\");\n// for(int i = 0; i<8; i++){\n// for (int j = 0; j < 8; j++) {\n// System.out.print(tab[i][j]+\" \");\n// }System.out.println();\n// }\n// System.out.println();\n// for(int i = 0; i<8; i++){\n// for (int j = 0; j < 8; j++) {\n// System.out.print(black[i][j]+\" \");\n// }System.out.println();\n// }\n } \n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n }\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n System.err.println(e);\n return \"\";\n }\n }\n return st.nextToken();\n }\n 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 float nextFloat(){\n return Float.parseFloat(next());\n }\n BigInteger nextBigInt(){\n return new BigInteger(next());\n }\n void close() {\n try {\n br.close();\n } \n catch (IOException e) {\n }\n } \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d82394436eef9518ec650f9c10a59769", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class B implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew B().run();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tboolean eof;\n\t\tString buf;\n\n\t\tpublic FastScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t\tnextToken();\n\t\t}\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(stream));\n\t\t\tnextToken();\n\t\t}\n\n\t\tString nextToken() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\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\tvoid close() {\n\t\t\ttry {\n\t\t\t\tbr.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\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\tvoid solve() {\n\t\tString s1 = nextToken();\n\t\tString s2 = nextToken();\n\t\tString s3 = nextToken();\n\t\tString s4 = nextToken();\n\t\tint x1 = s1.charAt(0) - 'a';\n\t\tint y1 = s1.charAt(1) - '1';\n\t\tint x2 = s2.charAt(0) - 'a';\n\t\tint y2 = s2.charAt(1) - '1';\n\t\tint x3 = s3.charAt(0) - 'a';\n\t\tint y3 = s3.charAt(1) - '1';\n\t\tint x4 = s4.charAt(0) - 'a';\n\t\tint y4 = s4.charAt(1) - '1';\n\t\tboolean[][] has = new boolean[8][8];\n\t\thas[x1][y1] = has[x2][y2] = has[x3][y3] = true;\n\t\tfor (int dx = -1; dx <= 1; dx++) {\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tint x = x4 + dx;\n\t\t\t\tint y = y4 + dy;\n\t\t\t\tboolean ok1 = (check1(has, x1, y1, x, y));\n\t\t\t\tboolean ok2 = (check1(has, x2, y2, x, y));\n\t\t\t\tboolean ok3 = (check2(has, x3, y3, x, y));\n\t\t\t\tif (ok1 || ok2 || ok3) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tout.println(\"OTHER\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"CHECKMATE\");\n\t}\n\n\tboolean check2(boolean[][] has, int x, int y, int x1, int y1) {\n\t\tif (x == x1 && y == y1) {\n\t\t\treturn false;\n\t\t}\n\t\treturn (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1);\n\t}\n\n\tboolean check1(boolean[][] has, int x, int y, int x1, int y1) {\n\t\tif ((x1 != x && y1 != y) || (x == x1 && y == y1)) {\n\t\t\treturn false;\n\t\t}\n\t\tint dx;\n\t\tint dy;\n\t\tif (x1 == x) {\n\t\t\tdx = 0;\n\t\t\tdy = y1 < y ? -1 : 1;\n\t\t} else {\n\t\t\tdx = x1 < x ? -1 : 1;\n\t\t\tdy = 0;\n\t\t}\n\t\tint xx = x + dx;\n\t\tint yy = y + dy;\n\t\twhile (xx >= 0 && yy >= 0 && xx < 8 && yy < 8 && !has[xx][yy]) {\n\t\t\tif (xx == x1 && yy == y1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\txx += dx;\n\t\t\tyy += dy;\n\t\t}\n\t\treturn xx == x1 && yy == y1;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2393c22d3cc53b769de98da2f6c0898b", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class B implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew B().run();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tboolean eof;\n\t\tString buf;\n\n\t\tpublic FastScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t\tnextToken();\n\t\t}\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(stream));\n\t\t\tnextToken();\n\t\t}\n\n\t\tString nextToken() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\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\tvoid close() {\n\t\t\ttry {\n\t\t\t\tbr.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\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\tvoid solve() {\n\t\tString s1 = nextToken();\n\t\tString s2 = nextToken();\n\t\tString s3 = nextToken();\n\t\tString s4 = nextToken();\n\t\tint x1 = s1.charAt(0) - 'a';\n\t\tint y1 = s1.charAt(1) - '1';\n\t\tint x2 = s2.charAt(0) - 'a';\n\t\tint y2 = s2.charAt(1) - '1';\n\t\tint x3 = s3.charAt(0) - 'a';\n\t\tint y3 = s3.charAt(1) - '1';\n\t\tint x4 = s4.charAt(0) - 'a';\n\t\tint y4 = s4.charAt(1) - '1';\n\t\tboolean[][] has = new boolean[8][8];\n\t\thas[x1][y1] = has[x2][y2] = has[x3][y3] = true;\n\t\tfor (int dx = -1; dx <= 1; dx++) {\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tint x = x4 + dx;\n\t\t\t\tint y = y4 + dy;\n\t\t\t\tboolean ok1 = (check1(has, x1, y1, x, y));\n\t\t\t\tboolean ok2 = (check1(has, x2, y2, x, y));\n\t\t\t\tboolean ok3 = (check2(has, x3, y3, x, y));\n\t\t\t\tif (ok1 || ok2 || ok3) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tout.println(\"OTHER\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"CHECKMATE\");\n\t}\n\n\tboolean check2(boolean[][] has, int x, int y, int x1, int y1) {\n\t\tif (x == x1 && y == y1) {\n\t\t\treturn false;\n\t\t}\n\t\tif (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tboolean check1(boolean[][] has, int x, int y, int x1, int y1) {\n\t\tif ((x1 != x && y1 != y) || (x == x1 && y == y1)) {\n\t\t\treturn false;\n\t\t}\n\t\tint dx;\n\t\tint dy;\n\t\tif (x1 == x) {\n\t\t\tdx = 0;\n\t\t\tdy = y1 < y ? -1 : 1;\n\t\t} else {\n\t\t\tdx = x1 < x ? -1 : 1;\n\t\t\tdy = 0;\n\t\t}\n\t\tint xx = x + dx;\n\t\tint yy = y + dy;\n\t\twhile (xx >= 0 && yy >= 0 && xx < 8 && yy < 8 && !has[xx][yy]) {\n\t\t\tif (xx == x1 && yy == y1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\txx += dx;\n\t\t\tyy += dy;\t\t\t\n\t\t}\n\t\treturn xx == x1 && yy == y1;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "899fa4da0ca0e99519736fba1d8ee623", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n static int n;\n static int m;\n static int[][][] DP;\n static int[] dx = { 0, 0, 1, -1 };\n static int[] dy = { 1, -1, 0, 0 };\n static int inf = 1000000;\n\n public static int get(int x, int current, int last) {\n if (x == n) {\n if (last == 0)\n return 0;\n else\n return -inf;\n }\n if (DP[x][current][last] != -1)\n return DP[x][current][last];\n int max = 0;\n for (int mask = 0; mask < (1 << m); mask++) {\n int tempLast = last;\n int tempCurrent = current;\n int tempNext = (1 << m) - 1;\n for (int i = 0; i < m; i++)\n if ((mask & (1 << i)) != 0) {\n if (i > 0)\n tempCurrent &= ~(1 << (i - 1));\n if (i < m - 1)\n tempCurrent &= ~(1 << (i + 1));\n tempNext &= ~(1 << (i));\n tempLast &= ~(1 << (i));\n }\n if (tempLast != 0)\n continue;\n max = Math.max(\n max,\n m - Integer.bitCount(mask)\n + get(x + 1, tempNext, tempCurrent & ~mask));\n }\n return DP[x][current][last] = max;\n }\n\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 n = Math.max(x, y);\n m = Math.min(x, y);\n DP = new int[n][1 << m][1 << m];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < (1 << m); j++)\n Arrays.fill(DP[i][j], -1);\n System.out.println(get(0, (1 << m) - 1, 0));\n }\n}\npackage Rnd85;\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n static int n;\n static int m;\n static int[][][] DP;\n static int[] dx = { 0, 0, 1, -1 };\n static int[] dy = { 1, -1, 0, 0 };\n static int inf = 1000000;\n\n public static int get(int x, int current, int last) {\n if (x == n) {\n if (last == 0)\n return 0;\n else\n return -inf;\n }\n if (DP[x][current][last] != -1)\n return DP[x][current][last];\n int max = 0;\n for (int mask = 0; mask < (1 << m); mask++) {\n int tempLast = last;\n int tempCurrent = current;\n int tempNext = (1 << m) - 1;\n for (int i = 0; i < m; i++)\n if ((mask & (1 << i)) != 0) {\n if (i > 0)\n tempCurrent &= ~(1 << (i - 1));\n if (i < m - 1)\n tempCurrent &= ~(1 << (i + 1));\n tempNext &= ~(1 << (i));\n tempLast &= ~(1 << (i));\n }\n if (tempLast != 0)\n continue;\n max = Math.max(\n max,\n m - Integer.bitCount(mask)\n + get(x + 1, tempNext, tempCurrent & ~mask));\n }\n return DP[x][current][last] = max;\n }\n\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 n = Math.max(x, y);\n m = Math.min(x, y);\n DP = new int[n][1 << m][1 << m];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < (1 << m); j++)\n Arrays.fill(DP[i][j], -1);\n System.out.println(get(0, (1 << m) - 1, 0));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "df9078bd79ee430bb8c10bc388de299d", "src_uid": "097674b4dd696b30e102938f71dd39b9", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n int n = r.nextInt();\n int m = r.nextInt(import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n int n = r.nextInt();\n int m = r.nextInt();\n \n if(n > m){int t = n; n = m; m = t;}\n \n dp = new int[m+1][1 << 7][1 << 7];\n for(int[][] i : dp)\n for(int[] j : i)\n Arrays.fill(j, -1);\n int min = go(m, 0, (1<> 1);\n int next = ~(now) & ((1 << n)-1);\n int current = Integer.bitCount(now) + go(rem-1, after ,next, n, m);\n min = Math.min(min, current);\n }\n return dp[rem][prev][need] = min;\n }\n}\n);\n \n if(n > m){int t = n; n = m; m = t;}\n \n dp = new int[m+1][1 << 7][1 << 7];\n int min = go(m, 0, (1<> 1);\n int next = ~(now) & ((1 << n)-1);\n \n int current = Integer.bitCount(now) + go(rem-1, after ,next, n, m);\n min = Math.min(min, current);\n }\n return dp[rem][prev][need] = min;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4541b2c5b8274e4c624e499789e73ed2", "src_uid": "097674b4dd696b30e102938f71dd39b9", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class P111C{\n\tScanner sc=new Scanner(System.in);\n\n\tint INF=1<<28;\n\tdouble EPS=1e-9;\n\n\tint h, w;\n\n\tvoid run(){\n\t\th=sc.nextInt();\n\t\tw=sc.nextInt();\n\t\tsolve();\n\t}\n\n\tvoid solve(){\n\t\tn=w*h;\n\t\tg=new long[n];\n\t\tint[] dx={0, 0, -1, 1};\n\t\tint[] dy={-1, 1, 0, 0};\n\t\tfor(int y=0; y=0&&x2=0&&y2=Long.bitCount(mds))\n\t\t\treturn;\n\t\tif(covered==((1L<>>i&1)==1){\n\t\t\t\tif(Long.bitCount(g[i]&~covered)==0){\n\t\t\t\t\tmds(choosed, removed|(1L<Long.bitCount(g[k]&~covered))\n\t\t\t\tk=i;\n\t\t}\n\t\tif(k==-1)\n\t\t\treturn;\n\n\t\tmds(choosed|(1L<> 1;\n\tint ans = MV;\n\t\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tif(n < m){ int d = n; n = m; m = d; }\n\t\tint M = 1 << m;\n\t\tdp = new int[n][m << 1][ m << 1];\n\t\tfor(int a[][] : dp)\n\t\t\tfor(int b[] : a)\n\t\t\t\tfill(b, MV);\n\t\t\n//\t\tfor(int i = 0 ; i < M; i++){\n//\t\t\tint next = (( i | (i << 1) | (i >> 1) ) & (M - 1));\n//\t\t\tif( next!= (M -1))\n//\t\t\t\tcontinue;\n//\t\t\tif(n > 1)\n//\t\t\t\tdp[0][next][0] = Integer.bitCount(i);\n//\t\t\telse\n//\t\t\t\tans = min(ans, Integer.bitCount(i));\n//\t\t}\n\t\tdp[0][0][0] = 0;\n\t\t\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tfor(int m1 = 0; m1 < M; m1++)\n\t\t\t\tfor(int m2 = 0; m2 < M; m2++){\n\t\t\t\t\tif(dp[i][m1][m2] == MV)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor(int nm1 = 0; nm1 < M; nm1++)\n\t\t\t\t\t\tfor(int nm2 = 0; nm2 < M; nm2++){\n\t\t\t\t\t\t\tint res1 = m1 | (nm1) | (nm1 << 1) | (nm1 >> 1) | (nm2);\n\t\t\t\t\t\t\tres1 &= (M - 1);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif(res1 != (M - 1))\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tint res2 = m2 | (nm1) | (nm2 << 1) | (nm2 >> 1) | (nm2);\n\t\t\t\t\t\t\tres2 &= (M - 1);\n\t\t\t\t\t\t\t\n//\t\t\t\t\t\t\tif(i == 2 && m1 == 3 && m2 == 2 && nm1 == 0 && nm2 == 0){\n//\t\t\t\t\t\t\t\tSystem.err.println(\"kek\");\n//\t\t\t\t\t\t\t\tSystem.err.println(dp[i][m1][m2]);\n//\t\t\t\t\t\t\t\tSystem.err.println(res1 + \" | \" + res2);\n//\t\t\t\t\t\t\t\tSystem.err.println(M);\n//\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tint next1 = res2 & (M - 1);\n\t\t\t\t\t\t\tint next2 = nm2 & ( M - 1);\n\t\t\t\t\t\t\tint over = Integer.bitCount(nm1) + Integer.bitCount(nm2);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif(i < n - 1)\n\t\t\t\t\t\t\t\tdp[i+1][next1][next2] = min(dp[i + 1][next1][next2], dp[i][m1][m2] + over);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif((res1 & (M - 1)) == (M - 1)){\n\t\t\t\t\t\t\t\t\tans = min(dp[i][m1][m2] + over, ans);\n\t\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\tSystem.err.println(ans);\n\t\tout.println(n * m - ans);\n\t\t\n\t\tin.close();\n\t\tout.close();\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "acb3d8f5a233c9e8a857a26bcce551b3", "src_uid": "097674b4dd696b30e102938f71dd39b9", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "package main;\n\nimport lib.InputReader;\nimport java.io.PrintWriter;\n\npublic class TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n String s = in.next();\n\n out.println(s.replaceAll(\"o(go)+\",\"***\"));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "914a07ad85d1fae9f6248d80396e94ee", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Test\n{\n public static void main(String [] args)\n {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n String str = s.next();\n if(str.contains(\"ogogogo\"))\n {\n String st = str.replace(\"ogogogo\",\"***\");\n }\n else if(str.contains(\"ogogo\"))\n {\n String st = str.replace(\"ogogo\",\"***\");\n }\n else if(str.contains(\"ogo\"))\n {\n String st = str.replace(\"ogo\",\"***\");\n }\n System.out.println(st);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7a4539751a33033d383aa01543fdd18d", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\n\n\npublic class P1 {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n FastReader sc = new FastReader(System.in);\n int n = sc.nextInt();\n String s = sc.next();\n boolean found = false;\n int i=0;\n for(i=0;i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n\n return buf[curChar++];\n}\n\npublic 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\npublic 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\npublic 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\npublic 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\npublic boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n}\n\npublic boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n}\n\nprivate 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\npublic String nextLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n}\n\npublic String nextLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines) {\n return nextLine();\n } else {\n return readLine0();\n }\n}\n\npublic BigInteger nextBigInteger() {\n try {\n return new BigInteger(nextString());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n}\n\npublic char nextCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n}\n\npublic 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\npublic boolean isExhausted() {\n int value;\n while (isSpaceChar(value = peek()) && value != -1)\n read();\n return value == -1;\n}\n\npublic String next() {\n return nextString();\n}\n\npublic SpaceCharFilter getFilter() {\n return filter;\n}\n\npublic void setFilter(SpaceCharFilter filter) {\n this.filter = filter;\n}\n\npublic interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4d49df6d49c9d5dab25a97686a2bdac0", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class hi{\n \n \n \n public static void main(String[] args) {\n \n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n String s = sc.next();\n boolean ok = false;\n boolean o = false;\n boolean g = false;\n for(int i=0;i[] 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();\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() {\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[] graph = new ArrayList[n];\n int[] degrees = new int[n];\n for(int i = 0; i();\n for(int j =0; j=0;i--)\n for(int j = 0; j[] adj = new ArrayList[n];\n\t\tfor(int i = 0; i < n; i++) adj[i] = new ArrayList();\n\t\tfor(int i = 0; i < m; i++) adj[scan.nextInt()-1].add(scan.nextInt()-1);\n\t\tboolean res = false;\n\t\tfor(int i = 0; i < n; i++) res |= go(i, adj, n, new boolean[n], 0);\n\t\tout.println(res?\"Yes\":\"No\");\n\t\tout.close();\n\t}\n\t\n\tstatic boolean go(int at, ArrayList[] adj, int n, boolean[] v, int c){\n\t\tv[at] = true;\n\t\tc++;\n\t\tif(c == n) return true;\n\t\tboolean res = false;\n\t\tfor(int i : adj[at]) if(!v[i])res |= go(i, adj, n, v, c);\n\t\tv[at] = false;\n\t\treturn res;\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\ttry\t{\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e){e.printStackTrace();}\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif (st.hasMoreTokens())\treturn st.nextToken();\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() {return Long.parseLong(next());}\n\n\t\tpublic double nextDouble() {return Double.parseDouble(next());}\n\n\t\tpublic String nextLine() {\n\t\t\tString line = \"\";\n\t\t\ttry {line = br.readLine();} \n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn line;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n){\n\t\t\tlong[] a = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int n){\n\t\t\tdouble[] a = new double[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextDouble();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic char[][] nextGrid(int n, int m){\n\t\t\tchar[][] grid = new char[n][m];\n\t\t\tfor(int i = 0; i < n; i++) grid[i] = next().toCharArray();\n\t\t\treturn grid;\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0729e6eb2894e9531bb31f8f3f981fdf", "src_uid": "d023fc9b58268a36d7fb80deb338b09a", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class j {\npublic static void main(String[] args)\n{\n Scanner input = new Scanner(System.in);\n int n = input.nextInt(), m = input.nextInt();\n boolean[][] adj = new boolean[n][n];\n for(int i = 0; i[] graph = new ArrayList[n];\n int[] degrees = new int[n];\n for(int i = 0; i();\n for(int j =0; j=0;i--)\n for(int j = 0; j sorted[togo]))\n togo = graph[at].get(j);\n if(togo != -1)\n {\n count++;\n at = togo;\n visited[togo] = true;\n }\n else\n break;\n }\n if(count==n) good = true;\n }\n System.out.println(good?\"Yes\":\"No\");\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8cce84fbd5983c41f628ecf55a45fea4", "src_uid": "d023fc9b58268a36d7fb80deb338b09a", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.util.NavigableSet;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.SortedSet;\nimport java.util.HashMap;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.util.RandomAccess;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.Map;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.util.NoSuchElementException;\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 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\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\t/*for (int i = 1; i <= 3; i++) {\n\t\t\tCounter popular = new Counter();\n\t\t\tfor (int j = 1; j <= 50; j++) {\n\t\t\t\tString fileName = \"d:/home/projects/algo/\" + i + \"/0\";\n\t\t\t\tif (j < 10)\n\t\t\t\t\tfileName += \"0\";\n\t\t\t\tfileName += j + \".txt\";\n\t\t\t\ttry {\n\t\t\t\t\tin = new InputReader(new FileInputStream(fileName));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\tSet current = new HashSet();\n\t\t\t\twhile (!in.isExhausted()) {\n\t\t\t\t\tString word = in.readString();\n\t\t\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(0)))\n\t\t\t\t\t\tword = word.substring(1);\n\t\t\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))\n\t\t\t\t\t\tword = word.substring(0, word.length() - 1);\n\t\t\t\t\tif (word.length() <= 4)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcurrent.add(word.toLowerCase());\n\t\t\t\t}\n\t\t\t\tfor (String word : current)\n\t\t\t\t\tpopular.add(word);\n\t\t\t}\n\t\t\tMap.Entry[] array = (Map.Entry[]) popular.entrySet().toArray(new Map.Entry[popular.size()]);\n\t\t\tArrays.sort(array, new Comparator>() {\n\t\t\t\tpublic int compare(Map.Entry o1, Map.Entry o2) {\n\t\t\t\t\treturn Long.signum(o2.getValue() - o1.getValue());\n\t\t\t\t}\n\t\t\t});\n\t\t\tStringBuilder key = new StringBuilder(\"keys[\" + i + \"] = new String[]{\");\n\t\t\tStringBuilder value = new StringBuilder(\"values[\" + i + \"] = new int[]{\");\n\t\t\tint cnt = 0;\n\t\t\tfor (Map.Entry anArray : array) {\n\t\t\t\tcnt++;\n\t\t\t\tif (cnt > 100)\n\t\t\t\t\tbreak;\n\t\t\t\tkey.append(\"\\\"\" + anArray.getKey() + \"\\\", \");\n\t\t\t\tvalue.append(anArray.getValue() + \", \");\n\t\t\t}\n\t\t\tkey.append(\"};\");\n\t\t\tvalue.append(\"};\");\n\t\t\tout.printLine(key);\n\t\t\tout.printLine(value);\n\t\t}*/\n\t\tString[][] keys = new String[4][];\n\t\tint[][] values = new int[4][];\n\t\tkeys[1] = new String[]{\"march\", \"market\", \"dollar\", \"money\", \"exchange\", \"billion\", \"treasury\", \"currency\", \"today\", \"would\", \"which\", \"around\", \"london\", \"their\", \"england\", \"central\", \"foreign\", \"assistance\", \"currencies\", \"against\", \"bills\", \"trading\", \"system\", \"rates\", \"liquidity\", \"while\", \"dealers\", \"house\", \"shortage\", \"after\", \"economic\", \"early\", \"financial\", \"official\", \"japan\", \"about\", \"monetary\", \"other\", \"recent\", \"these\", \"markets\", \"since\", \"forecast\", \"before\", \"could\", \"still\", \"provided\", \"april\", \"given\", \"among\", \"major\", \"reuters\", \"states\", \"federal\", \"intervention\", \"banks\", \"funds\", \"washington\", \"trade\", \"reserve\", \"secretary\", \"during\", \"bought\", \"morning\", \"finance\", \"paris\", \"because\", \"target\", \"total\", \"government\", \"further\", \"meeting\", \"committee\", \"month\", \"dollars\", \"account\", \"tokyo\", \"banking\", \"estimate\", \"james\", \"united\", \"continue\", \"president\", \"transactions\", \"revised\", \"nations\", \"agreement\", \"interest\", \"demand\", \"deficit\", \"sources\", \"current\", \"securities\", \"houses\", \"discount\", \"should\", \"baker\", \"treasury's\", \"domestic\", \"compared\", };\n\t\tvalues[1] = new int[]{46, 32, 23, 22, 21, 21, 20, 19, 19, 18, 17, 15, 15, 14, 14, 14, 14, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, };\n\t\tkeys[2] = new String[]{\"billion\", \"march\", \"money\", \"supply\", \"reserve\", \"february\", \"growth\", \"compared\", \"january\", \"federal\", \"december\", \"rises\", \"banks\", \"previous\", \"ended\", \"deposits\", \"which\", \"business\", \"central\", \"adjusted\", \"monetary\", \"deposit\", \"increase\", \"seasonally\", \"loans\", \"year-on-year\", \"april\", \"major\", \"interest\", \"against\", \"circulation\", \"statement\", \"after\", \"while\", \"latest\", \"average\", \"government\", \"earlier\", \"washington\", \"currency\", \"revised\", \"treasury\", \"reuters\", \"balances\", \"total\", \"notes\", \"month\", \"figures\", \"other\", \"provisional\", \"including\", \"measure\", \"there\", \"savings\", \"accounts\", \"increased\", \"balance\", \"showed\", \"assets\", \"foreign\", \"liquidity\", \"daily\", \"rates\", \"period\", \"excluding\", \"funds\", \"dollar\", \"level\", \"november\", \"issued\", \"economists\", \"falls\", \"about\", \"outstanding\", \"budget\", \"sector\", \"three\", \"market\", \"public\", \"short\", \"reserves\", \"non-bank\", \"totaled\", \"quarter\", \"lending\", \"deficit\", \"range\", \"moving\", \"would\", \"securities\", \"operating\", \"prior\", \"unchanged\", \"liquid\", \"banking\", \"books\", \"defined\", \"acceptances\", \"personal\", \"weeks\", };\n\t\tvalues[2] = new int[]{46, 38, 35, 30, 24, 20, 19, 18, 18, 18, 16, 16, 15, 15, 14, 14, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, };\n\t\tkeys[3] = new String[]{\"march\", \"trade\", \"washington\", \"would\", \"japan\", \"states\", \"japanese\", \"united\", \"agreement\", \"officials\", \"against\", \"goods\", \"president\", \"official\", \"reagan\", \"tariffs\", \"foreign\", \"countries\", \"their\", \"tokyo\", \"government\", \"which\", \"semiconductor\", \"could\", \"billion\", \"about\", \"minister\", \"japan's\", \"april\", \"imports\", \"market\", \"markets\", \"exports\", \"house\", \"action\", \"after\", \"impose\", \"prime\", \"semiconductors\", \"retaliation\", \"likely\", \"other\", \"under\", \"dispute\", \"domestic\", \"electronic\", \"american\", \"failure\", \"world\", \"industry\", \"because\", \"congress\", \"talks\", \"sanctions\", \"international\", \"alleged\", \"computer\", \"there\", \"products\", \"added\", \"reuters\", \"economic\", \"announced\", \"plans\", \"expected\", \"while\", \"policy\", \"dumping\", \"before\", \"surplus\", \"secretary\", \"being\", \"nakasone\", \"major\", \"bilateral\", \"sources\", \"issue\", \"visit\", \"today\", \"growing\", \"white\", \"ministry\", \"microchips\", \"deficit\", \"yasuhiro\", \"yesterday\", \"council\", \"issues\", \"increase\", \"reporters\", \"first\", \"signed\", \"european\", \"decision\", \"joint\", \"although\", \"chips\", \"early\", \"already\", \"senior\", };\n\t\tvalues[3] = new int[]{49, 49, 36, 35, 33, 30, 30, 29, 25, 24, 24, 24, 22, 22, 22, 22, 21, 21, 21, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 17, 17, 17, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, };\n\t\tMap[] maps = new Map[4];\n\t\tint[] score = new int[4];\n\t\tfor (int i = 1; i <= 3; i++) {\n\t\t\tmaps[i] = new CPPMap(new Factory() {\n\t\t\t\tpublic Integer create() {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t});\n\t\t\tfor (int j = 0; j < keys[i].length; j++)\n\t\t\t\tmaps[i].put(keys[i][j], values[i][j]);\n\t\t}\n\t\twhile (!in.isExhausted()) {\n\t\t\tString word = in.readString();\n\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(0)))\n\t\t\t\tword = word.substring(1);\n\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))\n\t\t\t\tword = word.substring(0, word.length() - 1);\n\t\t\tif (word.length() <= 4)\n\t\t\t\tcontinue;\n\t\t\tfor (int i = 1; i <= 3; i++)\n\t\t\t\tscore[i] += maps[i].get(word);\n\t\t}\n\t\tint answer = ListUtils.maxIndex(Array.wrap(score));\n\t\tout.printLine(answer);\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 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 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\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\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 CPPMap extends HashMap {\n\tprivate final Factory defaultValueFactory;\n\n\tpublic CPPMap(Factory defaultValueFactory) {\n\t\tthis.defaultValueFactory = defaultValueFactory;\n\t}\n\n\tpublic V get(Object key) {\n\t\tif (containsKey(key))\n\t\t\treturn super.get(key);\n\t\tV value = defaultValueFactory.create();\n\t\ttry {\n\t\t\t//noinspection unchecked\n\t\t\tsuper.put((K) key, value);\n\t\t\treturn value;\n\t\t} catch (ClassCastException e) {\n\t\t\treturn value;\n\t\t}\n\t}\n}\n\ninterface Factory {\n\tpublic V create();\n}\n\nclass ListUtils {\n\tpublic static int find(List sequence, T value) {\n\t\tint size = sequence.size();\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tif (MiscUtils.equals(sequence.get(i), value))\n\t\t\t\treturn i;\n\t\t}\n\t\treturn size;\n\t}\n\n\tpublic static> int maxIndex(List sequence) {\n\t\treturn find(sequence, CollectionUtils.maxElement(sequence));\n\t}\n\n\t}\n\nabstract class Array extends AbstractList implements RandomAccess {\n\n\tpublic static List wrap(int...array) {\n\t\treturn new IntArray(array);\n\t}\n\n\tprotected static class IntArray extends Array {\n\t\tprotected final int[] array;\n\n\t\tprotected IntArray(int[] array) {\n\t\t\tthis.array = array;\n\t\t}\n\n\t\tpublic int size() {\n\t\t\treturn array.length;\n\t\t}\n\n\t\tpublic Integer get(int index) {\n\t\t\treturn array[index];\n\t\t}\n\n\t\tpublic Integer set(int index, Integer value) {\n\t\t\tint result = array[index];\n\t\t\tarray[index] = value;\n\t\t\treturn result;\n\t\t}\n\t}\n\n\t}\n\nclass MiscUtils {\n\n\tpublic static boolean equals(T first, T second) {\n\t\treturn first == null && second == null || first != null && first.equals(second);\n\t}\n\n\t}\n\nclass CollectionUtils {\n\n\tpublic static> T maxElement(Iterable collection) {\n\t\tT result = null;\n\t\tfor (T element : collection) {\n\t\t\tif (result == null || result.compareTo(element) < 0)\n\t\t\t\tresult = element;\n\t\t}\n\t\treturn result;\n\t}\n\n\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "28d34af9a15545d3b82deb22f696d5ae", "src_uid": "d163975cdad000ce89ee251ef9129779", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.util.NavigableSet;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.SortedSet;\nimport java.util.HashMap;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.util.RandomAccess;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.Map;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.util.NoSuchElementException;\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 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\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\t/*for (int i = 1; i <= 3; i++) {\n\t\t\tCounter> popular = new Counter>();\n\t\t\tString lastWord = null;\n\t\t\tfor (int j = 1; j <= 50; j++) {\n\t\t\t\tString fileName = \"d:/home/projects/algo/\" + i + \"/0\";\n\t\t\t\tif (j < 10)\n\t\t\t\t\tfileName += \"0\";\n\t\t\t\tfileName += j + \".txt\";\n\t\t\t\ttry {\n\t\t\t\t\tin = new InputReader(new FileInputStream(fileName));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\tSet> current = new HashSet>();\n\t\t\t\twhile (!in.isExhausted()) {\n\t\t\t\t\tString word = in.readString();\n\t\t\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(0)))\n\t\t\t\t\t\tword = word.substring(1);\n\t\t\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))\n\t\t\t\t\t\tword = word.substring(0, word.length() - 1);\n\t\t\t\t\tif (word.length() <= 4)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tword = word.toLowerCase();\n\t\t\t\t\tif (lastWord != null)\n\t\t\t\t\t\tcurrent.add(Pair.makePair(lastWord, word));\n\t\t\t\t\tlastWord = word;\n\t\t\t\t}\n\t\t\t\tfor (Pair word : current)\n\t\t\t\t\tpopular.add(word);\n\t\t\t}\n\t\t\tMap.Entry, Long>[] array = (Map.Entry, Long>[]) popular.entrySet().toArray(new Map.Entry[popular.size()]);\n\t\t\tArrays.sort(array, new Comparator, Long>>() {\n\t\t\t\tpublic int compare(Map.Entry, Long> o1, Map.Entry, Long> o2) {\n\t\t\t\t\treturn Long.signum(o2.getValue() - o1.getValue());\n\t\t\t\t}\n\t\t\t});\n\t\t\tStringBuilder key = new StringBuilder(\"keys[\" + i + \"] = new Pair[]{\");\n\t\t\tStringBuilder value = new StringBuilder(\"values[\" + i + \"] = new int[]{\");\n\t\t\tint cnt = 0;\n\t\t\tfor (Map.Entry, Long> anArray : array) {\n\t\t\t\tcnt++;\n\t\t\t\tif (anArray.getValue() < 3)\n\t\t\t\t\tbreak;\n\t\t\t\tkey.append(\"Pair.makePair(\\\"\" + anArray.getKey().first + \"\\\", \\\"\" + anArray.getKey().second + \"\\\"), \");\n\t\t\t\tvalue.append(anArray.getValue() + \", \");\n\t\t\t}\n\t\t\tkey.append(\"};\");\n\t\t\tvalue.append(\"};\");\n\t\t\tout.printLine(key);\n\t\t\tout.printLine(value);\n\t\t}*/\n\t\tPair[][] keys = new Pair[4][];\n\t\tint[][] values = new int[4][];\nkeys[1] = new Pair[]{Pair.makePair(\"money\", \"market\"), Pair.makePair(\"foreign\", \"exchange\"), Pair.makePair(\"london\", \"march\"), Pair.makePair(\"march\", \"england\"), Pair.makePair(\"washington\", \"march\"), Pair.makePair(\"exchange\", \"rates\"), Pair.makePair(\"market\", \"today\"), Pair.makePair(\"treasury\", \"secretary\"), Pair.makePair(\"secretary\", \"james\"), Pair.makePair(\"treasury\", \"bills\"), Pair.makePair(\"james\", \"baker\"), Pair.makePair(\"united\", \"states\"), Pair.makePair(\"market\", \"given\"), Pair.makePair(\"march\", \"treasury\"), Pair.makePair(\"federal\", \"reserve\"), Pair.makePair(\"house\", \"appropriations\"), Pair.makePair(\"england\", \"provided\"), Pair.makePair(\"their\", \"currencies\"), Pair.makePair(\"around\", \"billion\"), Pair.makePair(\"appropriations\", \"committee\"), Pair.makePair(\"treasury's\", \"baker\"), Pair.makePair(\"tokyo\", \"march\"), Pair.makePair(\"billion\", \"billion\"), Pair.makePair(\"record\", \"billion\"), Pair.makePair(\"market\", \"assistance\"), Pair.makePair(\"shortage\", \"around\"), Pair.makePair(\"early\", \"round\"), Pair.makePair(\"money\", \"supply\"), Pair.makePair(\"assistance\", \"london\"), Pair.makePair(\"funds\", \"trading\"), Pair.makePair(\"system\", \"today\"), Pair.makePair(\"london\", \"april\"), Pair.makePair(\"billion\", \"before\"), Pair.makePair(\"provided\", \"money\"), Pair.makePair(\"before\", \"taking\"), Pair.makePair(\"taking\", \"account\"), Pair.makePair(\"monetary\", \"policy\"), Pair.makePair(\"early\", \"assistance\"), Pair.makePair(\"april\", \"england\"), Pair.makePair(\"central\", \"banks\"), Pair.makePair(\"revised\", \"estimate\"), Pair.makePair(\"traded\", \"daily\"), Pair.makePair(\"bankers\", \"balances\"), Pair.makePair(\"bills\", \"maturing\"), Pair.makePair(\"central\", \"would\"), Pair.makePair(\"drain\", \"while\"), Pair.makePair(\"discount\", \"houses\"), Pair.makePair(\"partly\", \"offsetting\"), Pair.makePair(\"french\", \"franc\"), Pair.makePair(\"exchequer\", \"transactions\"), Pair.makePair(\"earlier\", \"revised\"), Pair.makePair(\"shortage\", \"system\"), Pair.makePair(\"today\", \"among\"), Pair.makePair(\"round\", \"offers\"), Pair.makePair(\"central\", \"purchased\"), Pair.makePair(\"official\", \"hands\"), Pair.makePair(\"finance\", \"ministry\"), Pair.makePair(\"england\", \"revised\"), Pair.makePair(\"would\", \"continue\"), Pair.makePair(\"securities\", \"houses\"), Pair.makePair(\"maturing\", \"official\"), Pair.makePair(\"their\", \"dollar\"), Pair.makePair(\"dollar\", \"sales\"), Pair.makePair(\"currencies\", \"including\"), Pair.makePair(\"among\", \"factors\"), Pair.makePair(\"foreign\", \"exchanges\"), Pair.makePair(\"billion\", \"march\"), Pair.makePair(\"affecting\", \"liquidity\"), Pair.makePair(\"billion\", \"money\"), Pair.makePair(\"purchased\", \"bills\"), Pair.makePair(\"factors\", \"affecting\"), Pair.makePair(\"central\", \"intervention\"), Pair.makePair(\"assistance\", \"today\"), Pair.makePair(\"dhabi\", \"march\"), Pair.makePair(\"bought\", \"about\"), Pair.makePair(\"compares\", \"bank's\"), Pair.makePair(\"forecast\", \"shortage\"), Pair.makePair(\"offsetting\", \"these\"), Pair.makePair(\"offers\", \"discount\"), Pair.makePair(\"bills\", \"customer\"), Pair.makePair(\"market\", \"sources\"), Pair.makePair(\"liquidity\", \"bills\"), Pair.makePair(\"today\", \"money\"), };\nvalues[1] = new int[]{18, 11, 11, 10, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, };\nkeys[2] = new Pair[]{Pair.makePair(\"money\", \"supply\"), Pair.makePair(\"billion\", \"billion\"), Pair.makePair(\"federal\", \"reserve\"), Pair.makePair(\"supply\", \"rises\"), Pair.makePair(\"supply\", \"billion\"), Pair.makePair(\"billion\", \"january\"), Pair.makePair(\"seasonally\", \"adjusted\"), Pair.makePair(\"billion\", \"ended\"), Pair.makePair(\"compared\", \"billion\"), Pair.makePair(\"billion\", \"december\"), Pair.makePair(\"billion\", \"february\"), Pair.makePair(\"ended\", \"march\"), Pair.makePair(\"billion\", \"previous\"), Pair.makePair(\"billion\", \"march\"), Pair.makePair(\"deposits\", \"billion\"), Pair.makePair(\"march\", \"federal\"), Pair.makePair(\"december\", \"billion\"), Pair.makePair(\"march\", \"treasury\"), Pair.makePair(\"washington\", \"march\"), Pair.makePair(\"adjusted\", \"billion\"), Pair.makePair(\"loans\", \"books\"), Pair.makePair(\"revised\", \"billion\"), Pair.makePair(\"treasury\", \"latest\"), Pair.makePair(\"business\", \"loans\"), Pair.makePair(\"private\", \"sector\"), Pair.makePair(\"billion\", \"november\"), Pair.makePair(\"billion\", \"respective\"), Pair.makePair(\"business\", \"treasury\"), Pair.makePair(\"books\", \"major\"), Pair.makePair(\"balance\", \"totaled\"), Pair.makePair(\"respective\", \"treasury's\"), Pair.makePair(\"balances\", \"accounts\"), Pair.makePair(\"including\", \"acceptances\"), Pair.makePair(\"average\", \"billion\"), Pair.makePair(\"balances\", \"federal\"), Pair.makePair(\"moving\", \"average\"), Pair.makePair(\"banks\", \"billion\"), Pair.makePair(\"previous\", \"business\"), Pair.makePair(\"treasury\", \"balances\"), Pair.makePair(\"acceptances\", \"billion\"), Pair.makePair(\"ended\", \"february\"), Pair.makePair(\"major\", \"banks\"), Pair.makePair(\"budget\", \"statement\"), Pair.makePair(\"operating\", \"balance\"), Pair.makePair(\"accounts\", \"billion\"), Pair.makePair(\"billion\", \"while\"), Pair.makePair(\"totaled\", \"billion\"), Pair.makePair(\"latest\", \"budget\"), Pair.makePair(\"billion\", \"economists\"), Pair.makePair(\"treasury's\", \"operating\"), Pair.makePair(\"banks\", \"excluding\"), Pair.makePair(\"statement\", \"balances\"), Pair.makePair(\"excluding\", \"acceptances\"), Pair.makePair(\"fixed\", \"deposits\"), Pair.makePair(\"polled\", \"reuters\"), Pair.makePair(\"february\", \"federal\"), Pair.makePair(\"non-personal\", \"deposits\"), Pair.makePair(\"notice\", \"personal\"), Pair.makePair(\"money\", \"market\"), Pair.makePair(\"non-personal\", \"fixed\"), Pair.makePair(\"week's\", \"level\"), Pair.makePair(\"supply\", \"falls\"), Pair.makePair(\"other\", \"notice\"), Pair.makePair(\"interest\", \"rates\"), Pair.makePair(\"level\", \"revised\"), Pair.makePair(\"supply\", \"growth\"), Pair.makePair(\"totalled\", \"billion\"), Pair.makePair(\"march\", \"money\"), Pair.makePair(\"after\", \"december\"), Pair.makePair(\"while\", \"four-week\"), Pair.makePair(\"notes\", \"coins\"), Pair.makePair(\"january\", \"compared\"), Pair.makePair(\"billion\", \"money\"), Pair.makePair(\"broadly\", \"defined\"), Pair.makePair(\"march\", \"billion\"), Pair.makePair(\"reserve\", \"previous\"), Pair.makePair(\"economists\", \"polled\"), Pair.makePair(\"m-1-a\", \"other\"), Pair.makePair(\"november\", \"billion\"), Pair.makePair(\"deposits\", \"residents\"), Pair.makePair(\"residents\", \"booked\"), Pair.makePair(\"four-week\", \"moving\"), Pair.makePair(\"which\", \"m-1-a\"), Pair.makePair(\"foreign\", \"currency\"), Pair.makePair(\"chequable\", \"non-personal\"), Pair.makePair(\"interest\", \"chequable\"), Pair.makePair(\"january\", \"billion\"), Pair.makePair(\"deposits\", \"foreign\"), Pair.makePair(\"daily\", \"interest\"), Pair.makePair(\"january\", \"after\"), Pair.makePair(\"booked\", \"chartered\"), Pair.makePair(\"banks\", \"canada\"), Pair.makePair(\"canada\", \"m-1-a\"), Pair.makePair(\"billion\", \"which\"), Pair.makePair(\"m-1-a\", \"which\"), Pair.makePair(\"which\", \"daily\"), Pair.makePair(\"previous\", \"week's\"), Pair.makePair(\"canada\", \"billion\"), Pair.makePair(\"which\", \"non-personal\"), Pair.makePair(\"canadian\", \"money\"), Pair.makePair(\"coins\", \"circulation\"), Pair.makePair(\"currency\", \"deposits\"), Pair.makePair(\"previous\", \"month\"), Pair.makePair(\"chartered\", \"banks\"), Pair.makePair(\"december\", \"after\"), Pair.makePair(\"personal\", \"fixed-term\"), Pair.makePair(\"december\", \"against\"), Pair.makePair(\"defined\", \"money\"), Pair.makePair(\"canada\", \"savings\"), Pair.makePair(\"bonds\", \"billion\"), Pair.makePair(\"january\", \"money\"), Pair.makePair(\"banking\", \"system\"), Pair.makePair(\"billion\", \"canada\"), Pair.makePair(\"average\", \"forecast\"), Pair.makePair(\"ottawa\", \"march\"), Pair.makePair(\"increase\", \"december\"), Pair.makePair(\"certificates\", \"deposit\"), Pair.makePair(\"circulation\", \"totalled\"), Pair.makePair(\"sight\", \"deposits\"), Pair.makePair(\"circulation\", \"billion\"), Pair.makePair(\"canadian\", \"narrowly-defined\"), Pair.makePair(\"securities\", \"outstanding\"), Pair.makePair(\"singapore\", \"march\"), Pair.makePair(\"government\", \"balances\"), Pair.makePair(\"measure\", \"money\"), Pair.makePair(\"billion\", \"before\"), Pair.makePair(\"forecast\", \"called\"), Pair.makePair(\"chartered\", \"general\"), Pair.makePair(\"general\", \"loans\"), Pair.makePair(\"short\", \"assets\"), Pair.makePair(\"deposit\", \"billion\"), Pair.makePair(\"canadian\", \"dollar\"), Pair.makePair(\"measures\", \"notes\"), Pair.makePair(\"march\", \"business\"), Pair.makePair(\"board\", \"business\"), Pair.makePair(\"savings\", \"bonds\"), Pair.makePair(\"billion\", \"month\"), Pair.makePair(\"assets\", \"minus\"), Pair.makePair(\"february\", \"billion\"), Pair.makePair(\"narrowly-defined\", \"money\"), Pair.makePair(\"foreign\", \"exchange\"), Pair.makePair(\"dollar\", \"major\"), Pair.makePair(\"assets\", \"billion\"), Pair.makePair(\"billion\", \"total\"), Pair.makePair(\"billion\", \"seasonally\"), Pair.makePair(\"notes\", \"circulation\"), Pair.makePair(\"billion\", \"against\"), Pair.makePair(\"currency\", \"assets\"), Pair.makePair(\"outstanding\", \"billion\"), Pair.makePair(\"fixed-term\", \"deposit\"), Pair.makePair(\"government\", \"securities\"), Pair.makePair(\"money\", \"growth\"), Pair.makePair(\"billion\", \"chartered\"), Pair.makePair(\"bills\", \"billion\"), Pair.makePair(\"reserve\", \"board\"), Pair.makePair(\"major\", \"assets\"), Pair.makePair(\"canadian\", \"liquid\"), Pair.makePair(\"total\", \"canadian\"), Pair.makePair(\"liquid\", \"short\"), Pair.makePair(\"loans\", \"outstanding\"), Pair.makePair(\"before\", \"government\"), Pair.makePair(\"march\", \"canadian\"), Pair.makePair(\"reserve\", \"march\"), Pair.makePair(\"dropped\", \"billion\"), Pair.makePair(\"balances\", \"march\"), Pair.makePair(\"monetary\", \"policy\"), Pair.makePair(\"authority\", \"singapore\"), Pair.makePair(\"discount\", \"window\"), Pair.makePair(\"assets\", \"chartered\"), Pair.makePair(\"after\", \"rising\"), Pair.makePair(\"monetary\", \"authority\"), Pair.makePair(\"billion\", \"canadian\"), Pair.makePair(\"federal\", \"funds\"), Pair.makePair(\"december\", \"compared\"), Pair.makePair(\"after\", \"increase\"), Pair.makePair(\"march\", \"canada\"), Pair.makePair(\"treasury\", \"bills\"), Pair.makePair(\"three\", \"billion\"), Pair.makePair(\"chartered\", \"foreign\"), Pair.makePair(\"loans\", \"washington\"), Pair.makePair(\"billion\", \"average\"), Pair.makePair(\"billion\", \"singapore\"), Pair.makePair(\"supply\", \"seasonally\"), Pair.makePair(\"march\", \"washington\"), Pair.makePair(\"billion\", \"compared\"), Pair.makePair(\"balances\", \"billion\"), Pair.makePair(\"march\", \"compared\"), Pair.makePair(\"loans\", \"including\"), };\nvalues[2] = new int[]{30, 17, 17, 12, 12, 11, 11, 10, 10, 8, 8, 8, 8, 7, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, };\nkeys[3] = new Pair[]{Pair.makePair(\"united\", \"states\"), Pair.makePair(\"washington\", \"march\"), Pair.makePair(\"president\", \"reagan\"), Pair.makePair(\"prime\", \"minister\"), Pair.makePair(\"tokyo\", \"march\"), Pair.makePair(\"electronic\", \"goods\"), Pair.makePair(\"against\", \"japan\"), Pair.makePair(\"japanese\", \"electronic\"), Pair.makePair(\"minister\", \"yasuhiro\"), Pair.makePair(\"white\", \"house\"), Pair.makePair(\"yasuhiro\", \"nakasone\"), Pair.makePair(\"trade\", \"deficit\"), Pair.makePair(\"trade\", \"surplus\"), Pair.makePair(\"tariffs\", \"japanese\"), Pair.makePair(\"announced\", \"plans\"), Pair.makePair(\"trade\", \"sanctions\"), Pair.makePair(\"japanese\", \"semiconductor\"), Pair.makePair(\"alleged\", \"failure\"), Pair.makePair(\"international\", \"trade\"), Pair.makePair(\"action\", \"against\"), Pair.makePair(\"plans\", \"tariffs\"), Pair.makePair(\"world\", \"markets\"), Pair.makePair(\"economic\", \"policy\"), Pair.makePair(\"semiconductor\", \"trade\"), Pair.makePair(\"washington\", \"announced\"), Pair.makePair(\"trade\", \"issues\"), Pair.makePair(\"trade\", \"industry\"), Pair.makePair(\"government\", \"officials\"), Pair.makePair(\"policy\", \"council\"), Pair.makePair(\"states\", \"japan\"), Pair.makePair(\"sanctions\", \"against\"), Pair.makePair(\"impose\", \"tariffs\"), Pair.makePair(\"high-level\", \"official\"), Pair.makePair(\"trade\", \"washington\"), Pair.makePair(\"billion\", \"trade\"), Pair.makePair(\"exports\", \"united\"), Pair.makePair(\"ministry\", \"international\"), Pair.makePair(\"reuters\", \"tokyo\"), Pair.makePair(\"japan\", \"would\"), Pair.makePair(\"march\", \"prime\"), Pair.makePair(\"ministry\", \"officials\"), Pair.makePair(\"u.s.-japan\", \"trade\"), Pair.makePair(\"european\", \"community\"), Pair.makePair(\"trade\", \"dispute\"), Pair.makePair(\"trade\", \"legislation\"), Pair.makePair(\"cut-price\", \"chips\"), Pair.makePair(\"japanese\", \"imports\"), Pair.makePair(\"japanese\", \"companies\"), Pair.makePair(\"retaliation\", \"japan's\"), Pair.makePair(\"imports\", \"japanese\"), Pair.makePair(\"washington\", \"april\"), Pair.makePair(\"committee\", \"hearing\"), Pair.makePair(\"japanese\", \"trade\"), Pair.makePair(\"bilateral\", \"trade\"), Pair.makePair(\"goods\", \"april\"), Pair.makePair(\"japan\", \"could\"), Pair.makePair(\"friday\", \"washington\"), Pair.makePair(\"japan's\", \"trade\"), Pair.makePair(\"computer\", \"microchips\"), Pair.makePair(\"tariffs\", \"trade\"), Pair.makePair(\"billion\", \"billion\"), Pair.makePair(\"london\", \"march\"), Pair.makePair(\"called\", \"japan\"), Pair.makePair(\"microchip\", \"trade\"), Pair.makePair(\"visit\", \"washington\"), Pair.makePair(\"japanese\", \"market\"), Pair.makePair(\"trade\", \"between\"), Pair.makePair(\"record\", \"billion\"), Pair.makePair(\"domestic\", \"market\"), Pair.makePair(\"selling\", \"cut-price\"), Pair.makePair(\"chips\", \"world\"), Pair.makePair(\"nakasone\", \"tokyo\"), Pair.makePair(\"ronald\", \"reagan\"), Pair.makePair(\"through\", \"consultations\"), Pair.makePair(\"agreement\", \"tariffs\"), Pair.makePair(\"against\", \"japanese\"), Pair.makePair(\"official\", \"washington\"), Pair.makePair(\"house\", \"economic\"), Pair.makePair(\"markets\", \"american-made\"), Pair.makePair(\"heated\", \"negotiations\"), Pair.makePair(\"semiconductor\", \"makers\"), Pair.makePair(\"japan\", \"selling\"), Pair.makePair(\"retaliate\", \"against\"), Pair.makePair(\"general\", \"agreement\"), Pair.makePair(\"trade\", \"representative\"), Pair.makePair(\"third\", \"countries\"), Pair.makePair(\"agreement\", \"semiconductor\"), Pair.makePair(\"computer\", \"chips\"), Pair.makePair(\"semiconductor\", \"agreement\"), Pair.makePair(\"japanese\", \"government\"), Pair.makePair(\"trade\", \"would\"), Pair.makePair(\"tokyo's\", \"alleged\"), Pair.makePair(\"japan's\", \"largest\"), Pair.makePair(\"soviet\", \"union\"), Pair.makePair(\"would\", \"probably\"), Pair.makePair(\"tokyo's\", \"failure\"), Pair.makePair(\"official\", \"reuters\"), Pair.makePair(\"signed\", \"agreement\"), Pair.makePair(\"foreign\", \"trade\"), Pair.makePair(\"negotiations\", \"called\"), Pair.makePair(\"clayton\", \"yeutter\"), Pair.makePair(\"retaliatory\", \"action\"), Pair.makePair(\"foreign\", \"competition\"), Pair.makePair(\"retaliation\", \"tokyo's\"), Pair.makePair(\"trade\", \"practices\"), Pair.makePair(\"propose\", \"joint\"), Pair.makePair(\"representative\", \"clayton\"), Pair.makePair(\"president\", \"ronald\"), Pair.makePair(\"goods\", \"retaliation\"), Pair.makePair(\"electronics\", \"products\"), Pair.makePair(\"march\", \"united\"), Pair.makePair(\"march\", \"japanese\"), Pair.makePair(\"agriculture\", \"committee\"), Pair.makePair(\"industry\", \"sources\"), Pair.makePair(\"margaret\", \"thatcher\"), Pair.makePair(\"senior\", \"official\"), Pair.makePair(\"house\", \"agriculture\"), Pair.makePair(\"decision\", \"impose\"), Pair.makePair(\"states\", \"officials\"), Pair.makePair(\"trade\", \"computer\"), Pair.makePair(\"international\", \"telecommunications\"), Pair.makePair(\"nakasone\", \"visit\"), Pair.makePair(\"trade\", \"signed\"), Pair.makePair(\"willy\", \"clercq\"), Pair.makePair(\"visit\", \"tokyo\"), Pair.makePair(\"trade\", \"agreement\"), Pair.makePair(\"boost\", \"imports\"), Pair.makePair(\"worth\", \"japanese\"), Pair.makePair(\"foreign\", \"minister\"), Pair.makePair(\"japan\", \"violating\"), Pair.makePair(\"think\", \"there\"), Pair.makePair(\"malcolm\", \"baldrige\"), Pair.makePair(\"japan\", \"expected\"), Pair.makePair(\"week-long\", \"visit\"), Pair.makePair(\"american-made\", \"semiconductors\"), Pair.makePair(\"about\", \"foreign\"), Pair.makePair(\"trade\", \"analysts\"), Pair.makePair(\"japan's\", \"alleged\"), Pair.makePair(\"world\", \"trade\"), Pair.makePair(\"higher\", \"tariffs\"), Pair.makePair(\"miller\", \"reuters\"), Pair.makePair(\"foreign\", \"ministry\"), Pair.makePair(\"which\", \"would\"), Pair.makePair(\"financial\", \"markets\"), Pair.makePair(\"tariffs\", \"worth\"), Pair.makePair(\"three\", \"years\"), Pair.makePair(\"semiconductor\", \"electronics\"), Pair.makePair(\"could\", \"react\"), Pair.makePair(\"japanese\", \"exports\"), Pair.makePair(\"other\", \"areas\"), Pair.makePair(\"industries\", \"association\"), Pair.makePair(\"trade\", \"miller\"), Pair.makePair(\"democratic\", \"leader\"), Pair.makePair(\"japan\", \"trade\"), Pair.makePair(\"secretary\", \"malcolm\"), Pair.makePair(\"there\", \"immediate\"), Pair.makePair(\"commerce\", \"secretary\"), Pair.makePair(\"senate\", \"democratic\"), Pair.makePair(\"leader\", \"robert\"), Pair.makePair(\"trade\", \"action\"), Pair.makePair(\"countries\", \"their\"), Pair.makePair(\"reagan\", \"might\"), Pair.makePair(\"protectionist\", \"trade\"), Pair.makePair(\"reuters\", \"london\"), Pair.makePair(\"tariffs\", \"april\"), Pair.makePair(\"their\", \"trade\"), Pair.makePair(\"cable\", \"wireless\"), Pair.makePair(\"kyodo\", \"service\"), Pair.makePair(\"trade\", \"friction\"), Pair.makePair(\"alleged\", \"unfair\"), Pair.makePair(\"minister\", \"margaret\"), Pair.makePair(\"association\", \"japan\"), Pair.makePair(\"financial\", \"services\"), Pair.makePair(\"semiconductor\", \"manufacturers\"), Pair.makePair(\"trade\", \"imbalances\"), Pair.makePair(\"markets\", \"goods\"), Pair.makePair(\"settle\", \"dispute\"), Pair.makePair(\"action\", \"would\"), Pair.makePair(\"tariffs\", \"would\"), Pair.makePair(\"concerned\", \"about\"), Pair.makePair(\"ruling\", \"liberal\"), Pair.makePair(\"third\", \"world\"), Pair.makePair(\"peking\", \"march\"), Pair.makePair(\"japan\", \"because\"), Pair.makePair(\"goods\", \"services\"), Pair.makePair(\"semiconductor\", \"industry\"), Pair.makePair(\"democratic\", \"party\"), Pair.makePair(\"increase\", \"imports\"), Pair.makePair(\"tariffs\", \"effect\"), Pair.makePair(\"washington\", \"white\"), Pair.makePair(\"failure\", \"microchip\"), Pair.makePair(\"electronic\", \"industries\"), Pair.makePair(\"settle\", \"their\"), Pair.makePair(\"liberal\", \"democratic\"), Pair.makePair(\"japanese\", \"makers\"), Pair.makePair(\"trade\", \"sources\"), Pair.makePair(\"agreement\", \"reached\"), Pair.makePair(\"signed\", \"september\"), Pair.makePair(\"reagan\", \"would\"), Pair.makePair(\"while\", \"japan\"), Pair.makePair(\"government\", \"sources\"), Pair.makePair(\"trade\", \"problems\"), Pair.makePair(\"duties\", \"japanese\"), };\nvalues[3] = new int[]{29, 21, 16, 15, 14, 12, 12, 11, 10, 10, 10, 10, 10, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, };\n\t\tMap, Integer>[] maps = new Map[4];\n\t\tint[] score = new int[4];\n\t\tfor (int i = 1; i <= 3; i++) {\n\t\t\tmaps[i] = new CPPMap, Integer>(new Factory() {\n\t\t\t\tpublic Integer create() {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t});\n\t\t\tfor (int j = 0; j < keys[i].length; j++)\n\t\t\t\tmaps[i].put(keys[i][j], values[i][j]);\n\t\t}\n\t\tString lastWord = null;\n\t\twhile (!in.isExhausted()) {\n\t\t\tString word = in.readString();\n\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(0)))\n\t\t\t\tword = word.substring(1);\n\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))\n\t\t\t\tword = word.substring(0, word.length() - 1);\n\t\t\tif (word.length() <= 4)\n\t\t\t\tcontinue;\n\t\t\tword = word.toLowerCase();\n\t\t\tif (lastWord != null) {\n\t\t\t\tfor (int i = 1; i <= 3; i++)\n\t\t\t\t\tscore[i] += maps[i].get(Pair.makePair(lastWord, word));\n\t\t\t}\n\t\t\tlastWord = word;\n\t\t}\n\t\tint answer = ListUtils.maxIndex(Array.wrap(score));\n\t\tout.printLine(answer);\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 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 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\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\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 Pair implements Comparable> {\n\tpublic final U first;\n\tpublic final V second;\n\n\tpublic static Pair makePair(U first, V second) {\n\t\treturn new Pair(first, second);\n\t}\n\n\tprivate Pair(U first, V second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\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\treturn !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : 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 o) {\n\t\tint value = ((Comparable)first).compareTo(o.first);\n\t\tif (value != 0)\n\t\t\treturn value;\n\t\treturn ((Comparable)second).compareTo(o.second);\n\t}\n}\n\nclass CPPMap extends HashMap {\n\tprivate final Factory defaultValueFactory;\n\n\tpublic CPPMap(Factory defaultValueFactory) {\n\t\tthis.defaultValueFactory = defaultValueFactory;\n\t}\n\n\tpublic V get(Object key) {\n\t\tif (containsKey(key))\n\t\t\treturn super.get(key);\n\t\tV value = defaultValueFactory.create();\n\t\ttry {\n\t\t\t//noinspection unchecked\n\t\t\tsuper.put((K) key, value);\n\t\t\treturn value;\n\t\t} catch (ClassCastException e) {\n\t\t\treturn value;\n\t\t}\n\t}\n}\n\ninterface Factory {\n\tpublic V create();\n}\n\nclass ListUtils {\n\tpublic static int find(List sequence, T value) {\n\t\tint size = sequence.size();\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tif (MiscUtils.equals(sequence.get(i), value))\n\t\t\t\treturn i;\n\t\t}\n\t\treturn size;\n\t}\n\n\tpublic static> int maxIndex(List sequence) {\n\t\treturn find(sequence, CollectionUtils.maxElement(sequence));\n\t}\n\n\t}\n\nabstract class Array extends AbstractList implements RandomAccess {\n\n\tpublic static List wrap(int...array) {\n\t\treturn new IntArray(array);\n\t}\n\n\tprotected static class IntArray extends Array {\n\t\tprotected final int[] array;\n\n\t\tprotected IntArray(int[] array) {\n\t\t\tthis.array = array;\n\t\t}\n\n\t\tpublic int size() {\n\t\t\treturn array.length;\n\t\t}\n\n\t\tpublic Integer get(int index) {\n\t\t\treturn array[index];\n\t\t}\n\n\t\tpublic Integer set(int index, Integer value) {\n\t\t\tint result = array[index];\n\t\t\tarray[index] = value;\n\t\t\treturn result;\n\t\t}\n\t}\n\n\t}\n\nclass MiscUtils {\n\n\tpublic static boolean equals(T first, T second) {\n\t\treturn first == null && second == null || first != null && first.equals(second);\n\t}\n\n\t}\n\nclass CollectionUtils {\n\n\tpublic static> T maxElement(Iterable collection) {\n\t\tT result = null;\n\t\tfor (T element : collection) {\n\t\t\tif (result == null || result.compareTo(element) < 0)\n\t\t\t\tresult = element;\n\t\t}\n\t\treturn result;\n\t}\n\n\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dadf65c64f2b97a95e9e30c9f5755797", "src_uid": "d163975cdad000ce89ee251ef9129779", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\npublic class magic2 {\n\tpublic static void main(String[] args) throws Exception{\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt();\n\t\tif(N<2000||N==17000||N==20000||N==21000||N==18000||N==19000||N==7000||N==10000||N==54000||N==55000||N==56000)out.println(\"1\");\n\t\telse if(N<=3000||N==22000||N==23000||N==24000||N==8000||N==9000||N==51000||N==52000||N==53000)out.println(\"2\");\n\t\telse out.println(\"3\");\n\t\tout.close();\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t\n\t\tpublic FastScanner(InputStream in) throws Exception{\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\tpublic int numTokens() throws Exception {\n\t\t\tif(!st.hasMoreTokens()){\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t\t\treturn numTokens();\n\t\t\t}\n\t\t\treturn st.countTokens();\n\t\t}\n\t\tpublic boolean hasNext() throws Exception{\n\t\t\tif(!st.hasMoreTokens()){\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t\t\treturn hasNext();\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tpublic String next() throws Exception {\n\t\t\tif(!st.hasMoreTokens()){\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t\t\treturn next();\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic double nextDouble() throws Exception{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic float nextFloat() throws Exception{\n\t\t\treturn Float.parseFloat(next());\n\t\t}\n\t\tpublic long nextLong() throws Exception{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() throws Exception{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic String nextLine() throws Exception{\n\t\t\treturn br.readLine();\n\t\t}\n\t}\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3665a02c5c1805ffe1b5986b9914d849", "src_uid": "d163975cdad000ce89ee251ef9129779", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.util.NavigableSet;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.SortedSet;\nimport java.util.HashMap;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.util.RandomAccess;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.AbstractList;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.Map;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.Set;\nimport java.util.NoSuchElementException;\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 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\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\t/*for (int i = 1; i <= 3; i++) {\n\t\t\tCounter popular = new Counter();\n\t\t\tfor (int j = 1; j <= 50; j++) {\n\t\t\t\tString fileName = \"d:/home/projects/algo/\" + i + \"/0\";\n\t\t\t\tif (j < 10)\n\t\t\t\t\tfileName += \"0\";\n\t\t\t\tfileName += j + \".txt\";\n\t\t\t\ttry {\n\t\t\t\t\tin = new InputReader(new FileInputStream(fileName));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\tSet current = new HashSet();\n\t\t\t\twhile (!in.isExhausted()) {\n\t\t\t\t\tString word = in.readString();\n\t\t\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(0)))\n\t\t\t\t\t\tword = word.substring(1);\n\t\t\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))\n\t\t\t\t\t\tword = word.substring(0, word.length() - 1);\n\t\t\t\t\tif (word.length() <= 4)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tcurrent.add(word.toLowerCase());\n\t\t\t\t}\n\t\t\t\tfor (String word : current)\n\t\t\t\t\tpopular.add(word);\n\t\t\t}\n\t\t\tMap.Entry[] array = (Map.Entry[]) popular.entrySet().toArray(new Map.Entry[popular.size()]);\n\t\t\tArrays.sort(array, new Comparator>() {\n\t\t\t\tpublic int compare(Map.Entry o1, Map.Entry o2) {\n\t\t\t\t\treturn Long.signum(o2.getValue() - o1.getValue());\n\t\t\t\t}\n\t\t\t});\n\t\t\tStringBuilder key = new StringBuilder(\"keys[\" + i + \"] = new String[]{\");\n\t\t\tStringBuilder value = new StringBuilder(\"values[\" + i + \"] = new int[]{\");\n\t\t\tint cnt = 0;\n\t\t\tfor (Map.Entry anArray : array) {\n\t\t\t\tcnt++;\n\t\t\t\tif (cnt > 100)\n\t\t\t\t\tbreak;\n\t\t\t\tkey.append(\"\\\"\" + anArray.getKey() + \"\\\", \");\n\t\t\t\tvalue.append(anArray.getValue() + \", \");\n\t\t\t}\n\t\t\tkey.append(\"};\");\n\t\t\tvalue.append(\"};\");\n\t\t\tout.printLine(key);\n\t\t\tout.printLine(value);\n\t\t}*/\n\t\tString[][] keys = new String[4][];\n\t\tint[][] values = new int[4][];\n\t\tkeys[1] = new String[]{\"march\", \"market\", \"dollar\", \"money\", \"exchange\", \"billion\", \"treasury\", \"currency\", \"today\", \"would\", \"which\", \"around\", \"london\", \"their\", \"england\", \"central\", \"foreign\", \"assistance\", \"currencies\", \"against\", \"bills\", \"trading\", \"system\", \"rates\", \"liquidity\", \"while\", \"dealers\", \"house\", \"shortage\", \"after\", \"economic\", \"early\", \"financial\", \"official\", \"japan\", \"about\", \"monetary\", \"other\", \"recent\", \"these\", \"markets\", \"since\", \"forecast\", \"before\", \"could\", \"still\", \"provided\", \"april\", \"given\", \"among\", \"major\", \"reuters\", \"states\", \"federal\", \"intervention\", \"banks\", \"funds\", \"washington\", \"trade\", \"reserve\", \"secretary\", \"during\", \"bought\", \"morning\", \"finance\", \"paris\", \"because\", \"target\", \"total\", \"government\", \"further\", \"meeting\", \"committee\", \"month\", \"dollars\", \"account\", \"tokyo\", \"banking\", \"estimate\", \"james\", \"united\", \"continue\", \"president\", \"transactions\", \"revised\", \"nations\", \"agreement\", \"interest\", \"demand\", \"deficit\", \"sources\", \"current\", \"securities\", \"houses\", \"discount\", \"should\", \"baker\", \"treasury's\", \"domestic\", \"compared\", };\n\t\tvalues[1] = new int[]{46, 32, 23, 22, 21, 21, 20, 19, 19, 18, 17, 15, 15, 14, 14, 14, 14, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, };\n\t\tkeys[2] = new String[]{\"billion\", \"march\", \"money\", \"supply\", \"reserve\", \"february\", \"growth\", \"compared\", \"january\", \"federal\", \"december\", \"rises\", \"banks\", \"previous\", \"ended\", \"deposits\", \"which\", \"business\", \"central\", \"adjusted\", \"monetary\", \"deposit\", \"increase\", \"seasonally\", \"loans\", \"year-on-year\", \"april\", \"major\", \"interest\", \"against\", \"circulation\", \"statement\", \"after\", \"while\", \"latest\", \"average\", \"government\", \"earlier\", \"washington\", \"currency\", \"revised\", \"treasury\", \"reuters\", \"balances\", \"total\", \"notes\", \"month\", \"figures\", \"other\", \"provisional\", \"including\", \"measure\", \"there\", \"savings\", \"accounts\", \"increased\", \"balance\", \"showed\", \"assets\", \"foreign\", \"liquidity\", \"daily\", \"rates\", \"period\", \"excluding\", \"funds\", \"dollar\", \"level\", \"november\", \"issued\", \"economists\", \"falls\", \"about\", \"outstanding\", \"budget\", \"sector\", \"three\", \"market\", \"public\", \"short\", \"reserves\", \"non-bank\", \"totaled\", \"quarter\", \"lending\", \"deficit\", \"range\", \"moving\", \"would\", \"securities\", \"operating\", \"prior\", \"unchanged\", \"liquid\", \"banking\", \"books\", \"defined\", \"acceptances\", \"personal\", \"weeks\", };\n\t\tvalues[2] = new int[]{46, 38, 35, 30, 24, 20, 19, 18, 18, 18, 16, 16, 15, 15, 14, 14, 13, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, };\n\t\tkeys[3] = new String[]{\"march\", \"trade\", \"washington\", \"would\", \"japan\", \"states\", \"japanese\", \"united\", \"agreement\", \"officials\", \"against\", \"goods\", \"president\", \"official\", \"reagan\", \"tariffs\", \"foreign\", \"countries\", \"their\", \"tokyo\", \"government\", \"which\", \"semiconductor\", \"could\", \"billion\", \"about\", \"minister\", \"japan's\", \"april\", \"imports\", \"market\", \"markets\", \"exports\", \"house\", \"action\", \"after\", \"impose\", \"prime\", \"semiconductors\", \"retaliation\", \"likely\", \"other\", \"under\", \"dispute\", \"domestic\", \"electronic\", \"american\", \"failure\", \"world\", \"industry\", \"because\", \"congress\", \"talks\", \"sanctions\", \"international\", \"alleged\", \"computer\", \"there\", \"products\", \"added\", \"reuters\", \"economic\", \"announced\", \"plans\", \"expected\", \"while\", \"policy\", \"dumping\", \"before\", \"surplus\", \"secretary\", \"being\", \"nakasone\", \"major\", \"bilateral\", \"sources\", \"issue\", \"visit\", \"today\", \"growing\", \"white\", \"ministry\", \"microchips\", \"deficit\", \"yasuhiro\", \"yesterday\", \"council\", \"issues\", \"increase\", \"reporters\", \"first\", \"signed\", \"european\", \"decision\", \"joint\", \"although\", \"chips\", \"early\", \"already\", \"senior\", };\n\t\tvalues[3] = new int[]{49, 49, 36, 35, 33, 30, 30, 29, 25, 24, 24, 24, 22, 22, 22, 22, 21, 21, 21, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 17, 17, 17, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, };\n\t\tMap[] maps = new Map[4];\n\t\tint[] score = new int[4];\n\t\tfor (int i = 1; i <= 3; i++) {\n\t\t\tmaps[i] = new CPPMap(new Factory() {\n\t\t\t\tpublic Integer create() {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t});\n\t\t\tfor (int j = 0; j < keys[i].length; j++)\n\t\t\t\tmaps[i].put(keys[i][j], values[i][j]);\n\t\t}\n\t\twhile (!in.isExhausted()) {\n\t\t\tString word = in.readString();\n\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(0)))\n\t\t\t\tword = word.substring(1);\n\t\t\twhile (word.length() > 0 && !Character.isLetter(word.charAt(word.length() - 1)))\n\t\t\t\tword = word.substring(0, word.length() - 1);\n\t\t\tif (word.length() <= 4)\n\t\t\t\tcontinue;\n\t\t\tfor (int i = 1; i <= 3; i++)\n\t\t\t\tscore[i] += maps[i].get(word);\n\t\t}\n\t\tint answer = ListUtils.maxIndex(Array.wrap(score));\n\t\tout.printLine(answer);\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 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 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\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\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 CPPMap extends HashMap {\n\tprivate final Factory defaultValueFactory;\n\n\tpublic CPPMap(Factory defaultValueFactory) {\n\t\tthis.defaultValueFactory = defaultValueFactory;\n\t}\n\n\tpublic V get(Object key) {\n\t\tif (containsKey(key))\n\t\t\treturn super.get(key);\n\t\tV value = defaultValueFactory.create();\n\t\ttry {\n\t\t\t//noinspection unchecked\n\t\t\tsuper.put((K) key, value);\n\t\t\treturn value;\n\t\t} catch (ClassCastException e) {\n\t\t\treturn value;\n\t\t}\n\t}\n}\n\ninterface Factory {\n\tpublic V create();\n}\n\nclass ListUtils {\n\tpublic static int find(List sequence, T value) {\n\t\tint size = sequence.size();\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tif (MiscUtils.equals(sequence.get(i), value))\n\t\t\t\treturn i;\n\t\t}\n\t\treturn size;\n\t}\n\n\tpublic static> int maxIndex(List sequence) {\n\t\treturn find(sequence, CollectionUtils.maxElement(sequence));\n\t}\n\n\t}\n\nabstract class Array extends AbstractList implements RandomAccess {\n\n\tpublic static List wrap(int...array) {\n\t\treturn new IntArray(array);\n\t}\n\n\tprotected static class IntArray extends Array {\n\t\tprotected final int[] array;\n\n\t\tprotected IntArray(int[] array) {\n\t\t\tthis.array = array;\n\t\t}\n\n\t\tpublic int size() {\n\t\t\treturn array.length;\n\t\t}\n\n\t\tpublic Integer get(int index) {\n\t\t\treturn array[index];\n\t\t}\n\n\t\tpublic Integer set(int index, Integer value) {\n\t\t\tint result = array[index];\n\t\t\tarray[index] = value;\n\t\t\treturn result;\n\t\t}\n\t}\n\n\t}\n\nclass MiscUtils {\n\n\tpublic static boolean equals(T first, T second) {\n\t\treturn first == null && second == null || first != null && first.equals(second);\n\t}\n\n\t}\n\nclass CollectionUtils {\n\n\tpublic static> T maxElement(Iterable collection) {\n\t\tT result = null;\n\t\tfor (T element : collection) {\n\t\t\tif (result == null || result.compareTo(element) < 0)\n\t\t\t\tresult = element;\n\t\t}\n\t\treturn result;\n\t}\n\n\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8123892b8d9c36e87ba069250df410c3", "src_uid": "d163975cdad000ce89ee251ef9129779", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DPickingStrings solver = new DPickingStrings();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DPickingStrings {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int limit = (int) 1e5;\n char[] S = new char[limit];\n char[] T = new char[limit];\n\n int n = in.readString(S, 0);\n int m = in.readString(T, 0);\n int[] a = new int[n];\n int[] b = new int[m];\n int[] aLeft = new int[n];\n int[] bLeft = new int[m];\n for (int i = 0; i < n; i++) {\n a[i] = S[i] == 'A' ? 0 : 1;\n aLeft[i] = i == 0 ? -1 : aLeft[i - 1];\n if (a[i] == 1) {\n aLeft[i] = i;\n }\n }\n for (int i = 0; i < m; i++) {\n b[i] = T[i] == 'A' ? 0 : 1;\n bLeft[i] = i == 0 ? -1 : bLeft[i - 1];\n if (b[i] == 1) {\n bLeft[i] = i;\n }\n }\n\n IntegerPreSum psA = new IntegerPreSum(a);\n IntegerPreSum psB = new IntegerPreSum(b);\n\n int q = in.readInt();\n for (int i = 0; i < q; i++) {\n int l1 = in.readInt() - 1;\n int r1 = in.readInt() - 1;\n int l2 = in.readInt() - 1;\n int r2 = in.readInt() - 1;\n\n int c1 = psA.intervalSum(l1, r1);\n int c2 = psB.intervalSum(l2, r2);\n if (c2 < c1 || (c2 - c1) % 2 == 1) {\n out.append(0);\n continue;\n }\n int len1 = r1 - Math.max(l1 - 1, aLeft[r1]);\n int len2 = r2 - Math.max(l2 - 1, bLeft[r2]);\n if (c2 == c1) {\n if (len2 > len1 || (len1 - len2) % 3 != 0) {\n out.append(0);\n } else {\n out.append(1);\n }\n continue;\n }\n if (c2 > 0 && c1 == 0) {\n len2++;\n }\n if (len2 > len1) {\n out.append(0);\n } else {\n out.append(1);\n }\n }\n }\n\n }\n\n static class IntegerPreSum {\n private int[] pre;\n private int n;\n\n public IntegerPreSum(int n) {\n pre = new int[n];\n }\n\n public void populate(int[] a) {\n n = a.length;\n pre[0] = a[0];\n for (int i = 1; i < n; i++) {\n pre[i] = pre[i - 1] + a[i];\n }\n }\n\n public IntegerPreSum(int[] a) {\n this(a.length);\n populate(a);\n }\n\n public int intervalSum(int l, int r) {\n return prefix(r) - prefix(l - 1);\n }\n\n public int prefix(int i) {\n if (i < 0) {\n return 0;\n }\n return pre[Math.min(i, n - 1)];\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 20];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n public int readString(char[] data, int offset) {\n skipBlank();\n\n int originalOffset = offset;\n while (next > 32) {\n data[offset++] = (char) next;\n next = read();\n }\n\n return offset - originalOffset;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "13b62e308c49a0dc1023607cf619089f", "src_uid": "98e3182f047a7e7b10be7f207b219267", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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 int[] g(char[] x) {\n int[] r = new int[x.length + 1];\n for (int i = 1; i <= x.length; i++) {\n if (x[i - 1] != 'A') r[i] = 0;\n else {\n r[i] = r[i - 1] + 1;\n }\n }\n return r;\n }\n\n int[] p(char[] x) {\n int[] r = new int[x.length + 1];\n for (int i = 1; i <= x.length; i++) {\n r[i] = r[i - 1] + (x[i - 1] == 'A' ? 0 : 1);\n }\n return r;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] s = in.next().toCharArray();\n char[] t = in.next().toCharArray();\n int[] a1 = p(s), a2 = p(t);\n int[] r1 = g(s), r2 = g(t);\n int q = in.nextInt();\n while (q-- > 0) {\n int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();\n int c1 = a1[b] - a1[a - 1], c2 = a2[d] - a2[c - 1];\n int x1 = Math.min(r1[b], b - a + 1), x2 = Math.min(r2[d], d - c + 1);\n out.print(can(c1, x1, c2, x2) ? \"1\" : \"0\");\n }\n out.println();\n }\n\n boolean can(int c1, int x1, int c2, int x2) {\n if (x1 < x2) return false;\n if (c1 == 0 && c2 == 0 && (x1 - x2) % 3 != 0) return false;\n if (c1 == 0 && c2 > 0) {\n if (x1 == x2) return false;\n c1 += 2;\n } else if ((x1 - x2) % 3 != 0) {\n c1 += 2;\n }\n\n return c1 <= c2 && (c1 % 2 == c2 % 2);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public 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 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() {\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "72fcf74ad80c36932a76da710a63aff1", "src_uid": "98e3182f047a7e7b10be7f207b219267", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.StringTokenizer;\n\npublic class D {\n private static class BufferedScanner {\n BufferedReader mReader;\n StringTokenizer mTokenizer;\n\n BufferedScanner(InputStream inputStream) {\n mReader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n String next() {\n while (mTokenizer == null || !mTokenizer.hasMoreElements()) {\n String line = readLine();\n if (line != null) {\n mTokenizer = new StringTokenizer(line);\n } else {\n break;\n }\n }\n return mTokenizer != null ? mTokenizer.nextToken() : null;\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 return readLine();\n }\n\n private String readLine() {\n try {\n return mReader.readLine();\n } catch (IOException ignore) {\n return null;\n }\n }\n }\n\n public static void main(String[] args) throws IOException {\n new D().solve();\n }\n\n private BufferedScanner mReader;\n private PrintStream mWriter;\n\n private D() throws IOException {\n InputStream actualInputStream;\n if (System.getProperty(\"ONLINE_JUDGE\") != null) {\n actualInputStream = System.in;\n } else {\n File inputFile = new File(\"input.txt\");\n if (!inputFile.exists()) {\n //noinspection ResultOfMethodCallIgnored\n inputFile.createNewFile();\n throw new FileNotFoundException(\"File wasn't found, but now is created\");\n }\n actualInputStream = new FileInputStream(inputFile);\n }\n mReader = new BufferedScanner(new BufferedInputStream(actualInputStream));\n mWriter = System.out;\n }\n\n private void solve() throws IOException {\n String s = mReader.next();\n String t = mReader.next();\n int n = mReader.nextInt();\n int[] prefsS = calcPrefs(s);\n int[] prefsT = calcPrefs(t);\n int[] leftsS = calcLefts(s);\n int[] leftsT = calcLefts(t);\n for (int i = 0; i < n; i++) {\n int l1 = mReader.nextInt() - 1;\n int r1 = mReader.nextInt() - 1;\n int l2 = mReader.nextInt() - 1;\n int r2 = mReader.nextInt() - 1;\n\n// System.out.println(s.substring(l1, r1+1) + \" \" + t.substring(l2, r2+1));\n\n int bSCount = prefsS[r1] - (l1 != 0 ? prefsS[l1 - 1] : 0);\n int bTCount = prefsT[r2] - (l2 != 0 ? prefsT[l2 - 1] : 0);\n\n// System.out.println(bSCount + \" \" + bTCount);\n\n int leftS = leftsS[r1] >= l1 ? leftsS[r1] : -1;\n int leftT = leftsT[r2] >= l2 ? leftsT[r2] : -1;\n\n boolean ok;\n if (bSCount > bTCount || bSCount % 2 != bTCount % 2) {\n ok = false;\n } else if (leftS == -1 && leftT == -1) {\n ok = (r1 - l1 + 1) >= (r2 - l2 + 1)\n && (r1 - l1 + 1) % 3 == (r2 - l2 + 1) % 3;\n } else if (leftS == -1) {\n ok = (r2 - leftT) <= (r1 - l1);\n } else if (leftT == -1) {\n // unreachable state because of first if-statement\n ok = false;\n } else {\n if (bSCount == bTCount) {\n ok = (r1 - leftS) >= (r2 - leftT) && (r1 - leftS) % 3 == (r2 - leftT) % 3;\n } else {\n ok = (r1 - leftS) >= (r2 - leftT);\n }\n }\n\n System.out.print(ok ? 1 : 0);\n }\n\n System.out.println();\n }\n\n int[] calcPrefs(String s) {\n int n = s.length();\n int[] pref = new int[n];\n for (int i = 0; i < n; i++) {\n pref[i] = (s.charAt(i) == 'B' || s.charAt(i) == 'C' ? 1 : 0) + (i != 0 ? pref[i - 1] : 0);\n }\n return pref;\n }\n\n int[] calcLefts(String s) {\n int n = s.length();\n int[] leftB = new int[n];\n int cur = -1;\n for (int i = 0; i < n; i++) {\n if (s.charAt(i) == 'B' || s.charAt(i) == 'C') {\n cur = i;\n }\n leftB[i] = cur;\n }\n return leftB;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04e5407502db8e1d2f6ea9ff77ecd9f2", "src_uid": "98e3182f047a7e7b10be7f207b219267", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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 int[] g(char[] x) {\n int[] r = new int[x.length + 1];\n for (int i = 1; i <= x.length; i++) {\n if (x[i - 1] != 'A') r[i] = 0;\n else {\n r[i] = r[i - 1] + 1;\n }\n }\n return r;\n }\n\n int[] p(char[] x) {\n int[] r = new int[x.length + 1];\n for (int i = 1; i <= x.length; i++) {\n r[i] = r[i - 1] + (x[i - 1] == 'A' ? 0 : 1);\n }\n return r;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] s = in.next().toCharArray();\n char[] t = in.next().toCharArray();\n int[] a1 = p(s), a2 = p(t);\n int[] r1 = g(s), r2 = g(t);\n int q = in.nextInt();\n while (q-- > 0) {\n int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();\n int c1 = a1[b] - a1[a - 1], c2 = a2[d] - a2[c - 1];\n int x1 = Math.min(r1[b], b - a + 1), x2 = Math.min(r2[d], d - c + 1);\n if (x1 < x2) {\n out.print(\"0\");\n continue;\n }\n if ((x1 - x2) % 3 != 0) {\n if (c1 + 2 <= c2) {\n c1 += 2;\n } else {\n out.print(\"0\");\n continue;\n }\n }\n\n if (c2 == 0) {\n if (c1 == 0) out.print(\"1\");\n else out.print(\"0\");\n } else {\n if (c1 > c2 || c1 % 2 != c2 % 2) out.print(\"0\");\n else out.print(\"1\");\n }\n }\n out.println();\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public 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 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() {\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11c2c2e5bd80b899ffcc710d5fb8b2b9", "src_uid": "98e3182f047a7e7b10be7f207b219267", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "//package round90re;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni();\n\t\tdouble[][] co = new double[n][];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tco[i] = new double[]{ni(), ni(), ni()};\n\t\t}\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tdouble[] nor = new double[]{ni(), ni(), ni()};\n\t\t\tdouble[][] nco = rot(nor, new double[]{0, 0, 1}, co);\n\t\t\tout.printf(\"%.20f\\n\", minBall(nco));\n\t\t}\n\t}\n\t\n\tpublic static double minBall(double[][] s)\n\t{\n\t\tdouble q = 0.5;\n\t\tdouble[] x = new double[2];\n\t\t\n\t\tdouble max = 0;\n\t\twhile(q > 1E-11){\n\t\t\tfor(int o = 0;o < 100;o++){\n\t\t\t\tmax = -1;\n\t\t\t\tint maxi = -1;\n\t\t\t\tfor(int i = 0;i < s.length;i++){\n\t\t\t\t\tdouble[] p = s[i];\n\t\t\t\t\tdouble v = \n\t\t\t\t\t(x[0]-p[0])*(x[0]-p[0])+\n\t\t\t\t\t(x[1]-p[1])*(x[1]-p[1]);\n\t\t\t\t\tif(v > max){\n\t\t\t\t\t\tmax = v;\n\t\t\t\t\t\tmaxi = 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 < 2;i++){\n\t\t\t\t\tx[i] += (s[maxi][i] - x[i])*q;\n\t\t\t\t}\n\t\t\t}\n\t\t\tq *= 0.6;\n\t\t}\n\t\t\n\t\treturn Math.sqrt(max);\n\t}\n\t\n\tpublic static double[][] rot(double[] from, double[] to, double[][] xs)\n\t{\n\t\tdouble nfrom = Math.sqrt(from[0]*from[0]+from[1]*from[1]+from[2]*from[2]);\n\t\tfor(int i = 0;i < 3;i++)from[i] /= nfrom;\n\t\tdouble nto = Math.sqrt(to[0]*to[0]+to[1]*to[1]+to[2]*to[2]);\n\t\tfor(int i = 0;i < 3;i++)to[i] /= nto;\n\t\tdouble dot = from[0]*to[0]+from[1]*to[1]+from[2]*to[2];\n\t\tif(dot >= 1)dot = 1;\n\t\tif(dot <= -1)dot = -1;\n\t\tdouble angle = Math.acos(dot);\n\t\tif(Math.abs(angle) < 1E-8)return xs;\n\t\t\n\t\tdouble[] axis = new double[]{\n\t\t\t\tfrom[1]*to[2]-from[2]*to[1],\n\t\t\t\tfrom[2]*to[0]-from[0]*to[2],\n\t\t\t\tfrom[0]*to[1]-from[1]*to[0]\n\t\t};\n\t\tdouble nax = Math.sqrt(axis[0]*axis[0]+axis[1]*axis[1]+axis[2]*axis[2]);\n\t\tfor(int i = 0;i < 3;i++)axis[i] /= nax;\n\t\t\n\t\tdouble[][] ret = new double[xs.length][3];\n\t\t\n\t\tdouble ncos = Math.cos(angle);\n\t\tdouble nsin = Math.sin(angle);\n\t\tdouble scos = 1.0 - ncos;\n\t\t\n\t\tdouble sxy = axis[0] * axis[1] * scos;\n\t\tdouble syz = axis[1] * axis[2] * scos;\n\t\tdouble sxz = axis[0] * axis[2] * scos;\n\t\tdouble sz = nsin * axis[2];\n\t\tdouble sy = nsin * axis[1];\n\t\tdouble sx = nsin * axis[0];\n\t\t\n\t\tint p = 0;\n\t\tfor(double[] x : xs){\n\t\t\tret[p][0] = (ncos+axis[0]*axis[0]*scos)*x[0] + (-sz+sxy)*x[1]+(sy+sxz)*x[2];\n\t\t\tret[p][1] = (sz+sxy)*x[0]+(ncos+axis[1]*axis[1]*scos)*x[1]+(-sx+syz)*x[2];\n\t\t\tret[p][2] = (-sy+sxz)*x[0]+(sx+syz)*x[1]+(ncos+axis[2]*axis[2]*scos)*x[2];\n\t\t\tp++;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6a79a58f08c7e2e0db0eac4eabbf40a9", "src_uid": "25b2a84f0c3f574cdffd59a902b2326e", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\nimport java.util.*;\n\npublic class E {\n\n\tprivate final static boolean autoflush = false;\n\n\tpublic E () {\n\t\tint N = sc.nextInt(), M = sc.nextInt();\n\t\tdouble [][] X = toPrimitive(sc.nextDoubles(N));\n\t\tdouble [][] A = toPrimitive(sc.nextDoubles(M));\n\n\t\tfor (int j : rep(M)) {\n\t\t\tRodrigues R = new Rodrigues(A[j]);\n\t\t\tdouble [][] Y = new double [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tY[i] = R.rotate(project(X[i], A[j]));\n\t\t\tCircle res = Circle.toCircle(Y);\n\t\t\tprint(res.R);\n\t\t}\n\t}\n\n\t///////////////////////////////////////////////////////////////////////////\n\tprivate static final double eps = 1e-9;\n\tprivate static final int INF = (int) 1e9;\n\tprivate static double [] cross (double [] X, double [] Y) { assert X.length <= 3 && Y.length <= 3; X = copyOf(X, 3); Y = copyOf(Y, 3); return new double [] { X[1]*Y[2] - Y[1]*X[2], X[2]*Y[0] - Y[2]*X[0], X[0]*Y[1] - Y[0]*X[1] }; }\n\tprivate static double [] diff (double [] X, double [] Y) { return sum(X, scalar(-1, Y)); }\n\tprivate static double dist (double [] X, double [] Y) { return norm(diff(X, Y)); }\n\tprivate static double dot(double [] X, double [] Y) { double res = 0; for (int i = 0; i < min(X.length, Y.length); ++i) res += X[i] * Y[i]; return res; }\n\tprivate static boolean eq(double x, double y) { return abs(x - y) < eps; }\n\tprivate static boolean eq (double [] X, double [] Y) { return eq(dist(X, Y), 0); }\n\tprivate static boolean greater(double x, double y) { return x > y + eps; }\n\tprivate static double norm (double ... X) { return sqrt(dot(X, X)); }\n\tprivate static double [] normalize(double ... X) { return eq(norm(X), 0) ? X : scalar(1/norm(X), X); }\n\tprivate static double [] project(double [] X, double [] K) { return diff(X, scalar(dot(X,K)/dot(K,K), K)); }\n\tprivate static int [] rep(int N) { return rep(0, N); }\n\tprivate static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tprivate static double [] scalar (double c, double ... X) { double [] res = new double [X.length]; for (int i = 0; i < X.length; ++i) res[i] = c * X[i]; return res; }\n\tprivate static double [] sum (double [] ... X) {\n\t\tint L = 0;\n\t\tfor (double[] x : X)\n\t\t\tL = max(L, x.length);\n\t\tdouble [] res = new double [L];\n\t\tfor (double[] x : X)\n\t\t\tfor (int j = 0; j < x.length; ++j)\n\t\t\t\tres[j] += x[j];\n\t\treturn res;\n\t}\n\tprivate static double [] toPrimitive(Double ... A) { double [] res = new double [A.length]; for (int i = 0; i < A.length; ++i) res[i] = A[i]; return res; }\n\tprivate static double [][] toPrimitive(Double [] ... A) { double [][] res = new double [A.length][]; for (int i = 0; i < A.length; ++i) res[i] = toPrimitive(A[i]); return res; }\n\tprivate static boolean zero(double ... X) { return eq(norm(X), 0); }\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static class Circle {\n\t\tpublic final double [] C;\n\t\tpublic final double R;\n\t\tpublic static final Circle R2 = new Circle(new double [2], INF);\n\t\tpublic Circle(double [] C, double R) { this.C = C; this.R = R; }\n\t\tpublic static Circle toCircumference(double [] ... X) {\n\t\t\tassert X.length > 0 && X.length <= 3;\n\t\t\tswitch(X.length) {\n\t\t\tcase 1: return new Circle(X[0], 0);\n\t\t\tcase 2: return new Circle(scalar(.5, sum(X)), .5 * dist(X[0], X[1]));\n\t\t\tcase 3:\n\t\t\t\tif (eq(X[0], X[1])) return toCircumference(X[1], X[2]);\n\t\t\t\telse if (eq(X[1], X[2])) return toCircumference(X[2], X[0]);\n\t\t\t\telse if (eq(X[2], X[0])) return toCircumference(X[0], X[1]);\n\t\t\t\telse return\tcalc(X[0], X[1], X[2]);\n\t\t\tdefault: throw new Error();\n\t\t\t}\n\t\t}\n\t\tpublic static Circle toCircle(double [] ... X) {\n\t\t\tassert X.length > 0; shuffle(asList(X));\n\t\t\treturn welzl(X, X.length, new double[3][], 0);\n\t\t}\n\t\tprivate static Circle calc(double [] X, double [] Y, double [] Z) {\n\t\t\tboolean u = eq(X[0], Y[0]), v = eq(Y[0], Z[0]);\n\t\t\tif (u && v) return R2;\n\t\t\telse if (u) return calc(Y, Z, X);\n\t\t\telse if (v) return calc(Z, X, Y);\n\t\t\telse {\n\t\t\t\tdouble U = (Y[1] - X[1]) / (Y[0] - X[0]);\n\t\t\t\tdouble V = (Z[1] - Y[1]) / (Z[0] - Y[0]);\n\t\t\t\tif (eq(U, V)) return R2;\n\t\t\t\tif (eq(U, 0)) return calc(Z, Y, X);\n\t\t\t\tdouble CX = (U * V * (X[1] - Z[1]) + V * (X[0] + Y[0]) - U * (Y[0] + Z[0])) / (2 * (V - U));\n\t\t\t\tdouble CY = ((X[0] + Y[0]) / 2 - CX) / U + (X[1] + Y[1]) / 2;\n\t\t\t\tdouble [] C = new double [] { CX, CY };\n\t\t\t\tdouble R = dist(C, X); assert eq(dist(C, Y), R) && eq(dist(C, Z), R);\n\t\t\t\treturn new Circle(C, R);\n\t\t\t}\n\t\t}\n\t\tprivate static Circle welzl(double [][] X, int N, double [][] S, int K) {\n\t\t\tif (K == 3) return Circle.toCircumference(S);\n\t\t\telse if (N == 0) {\n\t\t\t\tswitch(K) {\n\t\t\t\tcase 0: return new Circle(new double [3], -1);\n\t\t\t\tcase 1: return new Circle(S[0], 0);\n\t\t\t\tcase 2: return Circle.toCircumference(S[0], S[1]);\n\t\t\t\tdefault: throw new Error();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tCircle C = welzl(X, N-1, S, K);\n\t\t\t\tif (greater(dist(C.C, X[N-1]), C.R)) {\n\t\t\t\t\tS[K++] = X[N-1];\n\t\t\t\t\tC = welzl(X, N-1, S, K);\n\t\t\t\t}\n\t\t\t\treturn C;\n\t\t\t}\n\t\t}\n\t\tpublic String toString() { Map M = new HashMap<>(); M.put(\"C\", Arrays.toString(C)); M.put(\"R\", R); return M.toString(); }\n\t}\n\tprivate static class Rodrigues {\n\t\tprivate final double [] K, T;\n\t\tpublic Rodrigues(double ... A) {\n\t\t\tassert A.length <= 3; A = copyOf(A, 3);\n\t\t\tK = normalize(new double [] { -A[1], A[0] }); double [] L = new double [] { K[1], -K[0] };\n\t\t\tif (!zero(K)) {\n\t\t\t\tdouble [] V = new double [3];\n\t\t\t\twhile (zero(V))\n\t\t\t\t\tV = project(project(new double [] { random(), random(), random() }, A), K);\n\t\t\t\tT = normalize(new double [] { dot(L, V), V[2] });\n\t\t\t} else\n\t\t\t\tT = null;\n\t\t}\n\t\tpublic double [] rotate(double ... X) {\n\t\t\tassert X.length <= 3; X = copyOf(X, 3);\n\t\t\tif (T != null) {\n\t\t\t\tdouble [] Y = scalar(T[0], X);\n\t\t\t\tY = sum(Y, scalar(T[1], cross(K, X)));\n\t\t\t\tX = sum(Y, scalar(dot(K, X) * (1 - T[0]), K));\n\t\t\t}\n\t\t\tassert eq(X[2], 0);\n\t\t\treturn copyOf(X, 2);\n\t\t}\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static void print (Object o, Object ... A) { IOUtils.print(o, A); }\n\tprivate static void exit() { IOUtils.exit(); }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next() { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\t\tpublic String nextLine() { line = null; return readLine(); }\n\t\t\tpublic String [] nextStrings() { return nextLine().split(\" \"); }\n\t\t\tpublic Double [] nextDoubles() {\n\t\t\t\tString [] L = nextStrings();\n\t\t\t\tDouble [] res = new Double [L.length];\n\t\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\t\tDouble [][] res = new Double [N][];\n\t\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\t\tres[i] = nextDoubles();\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol() { return index == line.length; }\n\t\t\tprivate String readLine() {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine() {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = readLine().split(\" \");\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprivate static String build(Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim(String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static void start() { if (t == 0) t = millis(); }\n\t\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t\t} else if (o instanceof Iterable)\n\t\t\t\tfor (Object p : (Iterable) o)\n\t\t\t\t\tappend(b, p, delim);\n\t\t\telse {\n\t\t\t\tif (o instanceof Double)\n\t\t\t\t\to = new java.text.DecimalFormat(\"#.############\").format(o);\n\t\t\t\tb.append(delim).append(o);\n\t\t\t}\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);\n\t\tprivate static void print(Object o, Object ... A) { pw.println(build(o, A)); }\n\t\tprivate static void err(Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static void exit() {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(IOUtils.time());\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis() { return System.currentTimeMillis(); }\n\t\tprivate static String time() { return \"Time: \" + (millis() - t) / 1000.0; }\n\t}\n\tpublic static void main (String[] args) { new E(); exit(); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6dafbbf8e8997b126b492c250c1a0fc4", "src_uid": "25b2a84f0c3f574cdffd59a902b2326e", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\nimport java.util.SortedMap;\nimport java.util.TreeMap;\n\npublic class E {\n\n\tprivate static final double EPS = 1e-8;\n\t\n \tprivate E (Scanner sc) {\n\t\tint N = sc.nextInt();\n\t\tint M = sc.nextInt();\n\t\t\n\t\tdouble [][] X = new double [N][];\n\t\tfor (int i = 0; i < N; ++i)\n\t\t\tX[i] = new double [] { sc.nextInt(),sc.nextInt(),sc.nextInt() };\n\t\t\n\t\tdouble [][] A = new double [M][];\n\t\tfor (int i = 0; i < M; ++i)\n\t\t\tA[i] = new double [] { sc.nextInt(),sc.nextInt(),sc.nextInt() };\n\t\tfor (int i = 0; i < M; ++i)\n\t\t\tsolve(X, A[i]);\n\t}\n\t\n\tprivate void solve (double [][] X, double [] A) {\n\t\t// Project X on plane\n\t\tdouble [][] Y = new double [X.length][];\n\t\tfor (int i = 0; i < X.length; ++i)\n\t\t\tY[i] = project(X[i], A);\n\t\t\n\t\t// Rotate plane, so that z = 0\n\t\tdouble [] K = new double [] { -A[1], A[0], 0 };\n\t\tif (!isZero(K))\n\t\t\tY = rodrigues(Y, normalize(K));\n\t\t\n\t\t// Welzl Algorithm\n\t\tY = randomize(Y);\t\t\n\t\tdouble [][] S = new double [3][];\n\t\tdouble [] C = welzl(Y, Y.length, S, 0);\n\t\t\n\t\tprint(C[C.length - 1]);\n\t}\n\n\tdouble [] project(double [] X, double [] A) {\n\t\treturn diff(X, scalar(dot(X,A)/dot(A,A), A));\n\t}\n\t\n\tdouble [][] rodrigues(double [][] X, double [] K) {\n\t\t// Rotate X plane to z=0, around K axis\n\t\t// K is a unit vector in both X and z=0 planes\n\t\tdouble [] V = null;\n\t\tfor (double [] x : X) {\n\t\t\t// Use a vector V on X plane, orthogonal to K,\n\t\t\t// to easily compute sin and cos of rotation angle.\n\t\t\tdouble [] v = project(x,K);\n\t\t\tif (!isZero(v))\n\t\t\t\tV = v;\n\t\t}\n\t\t\n\t\tif (V == null)\n\t\t\treturn X;\n\t\t\n\t\tdouble [] T = new double [] { \n\t\t\tdot(new double [] { K[1], -K[0], 0 }, V), \n\t\t\tV[2] };\n\t\tT = normalize(T);\n\t\t\n\t\tfor (int i = 0; i < X.length; ++i) {\n\t\t\tdouble [] x = scalar(T[0] ,X[i]);\n\t\t\tx = sum(x, scalar(T[1] ,cross(K,X[i])));\n\t\t\tx = sum(x, scalar(dot(K,X[i])*(1-T[0]), K));\n\t\t\tX[i] = x;\n\t\t}\t\t\n\t\treturn X;\n\t}\n\t\n\tdouble [] welzl(double [][] X, int N, double [][] S, int B) {\n\t\tif (B == 3)\n\t\t\treturn circle(S[0], S[1], S[2]);\n\t\telse if (N == 1 && B == 0)\n\t\t\treturn new double [] { X[0][0], X[0][1], X[0][2], 0 };\n\t\telse if (N == 0 && B == 2)\n\t\t\treturn circle (S[0], S[1]);\n\t\telse if (N == 1 && B == 1)\n\t\t\treturn circle (S[0], X[0]);\n\t\telse {\n\t\t\tdouble [] C = welzl(X, N-1, S, B);\n\t\t\tif (dist (new double [] { C[0], C[1], C[2] }, X[N-1]) > C[3] + EPS) {\n\t\t\t\tS[B++] = X[N-1];\n\t\t\t\tC = welzl(X, N-1, S, B);\n\t\t\t}\n\t\t\treturn C;\n\t\t}\n\t}\n\t\n\tdouble [] circle(double [] a, double [] b) {\n\t\tdouble d = dist(a,b);\n\t\tdouble [] C = new double [a.length+1];\n\t\tfor (int i = 0; i < a.length; ++i)\n\t\t\tC[i] = (a[i] + b[i])/2;\n\t\tC[a.length] = d/2;\n\t\treturn C;\n\t}\n\n\tboolean close(double x, double y) {\n\t\treturn Math.abs(x-y) < EPS;\n\t}\n\t\n\tdouble [] circle(double [] a, double [] b, double [] c) {\n\t\tif (close(a[0],b[0]) && close(b[0],c[0]))\n\t\t\treturn collinear(a,b,c);\n\t\telse if (close(a[0],b[0]))\n\t\t\treturn circle(b,c,a);\n\t\telse if (close(b[0],c[0]))\n\t\t\treturn circle(c,a,b);\n\t\telse {\n\t\t\tdouble ma = (b[1] - a[1])/(b[0] - a[0]);\n\t\t\tif (close(ma,0))\n\t\t\t\treturn circle(c,b,a);\n\t\t\tdouble mb = (c[1] - b[1])/(c[0] - b[0]);\n\t\t\tif (close(ma,mb))\n\t\t\t\treturn collinear(a,b,c);\n\t\t\tdouble [] C = new double [4];\n\t\t\tC[0] = (ma * mb * (a[1] - c[1]) + mb * (a[0] + b[0]) - ma * (b[0] + c[0])) / (2*(mb - ma));\n\t\t\tC[1] = ((a[0] + b[0])/2 - C[0])/ma + (a[1] + b[1])/2;\n\t\t\tC[3] = dist(a,C);\n\t\t\treturn C;\n\t\t}\n\t}\n\t\n\tdouble [] collinear (double [] a, double [] b, double [] c) {\n\t\tdouble [] C = circle(a,b);\n\t\tif (dist(b,c) > dist(a,b))\n\t\t\tC = circle(b,c);\n\t\tif (dist(a,c) > dist(b,c))\n\t\t\tC = circle(a,c);\n\t\treturn C;\n\t}\n\t\n\tdouble [][] randomize(double [][] X) {\n\t\tSortedMap M = new TreeMap();\n\t\tfor (double [] x : X)\n\t\t\tM.put(Math.random(), x);\n\t\treturn M.values().toArray(new double[0][]);\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\tdouble dot(double [] A, double [] B) {\n\t\tdouble S = 0;\n\t\tfor (int i = 0; i < A.length; ++i)\n\t\t\tS += A[i] * B[i];\n\t\treturn S;\n\t}\n\t\n\tdouble norm (double [] A) {\n\t\treturn Math.sqrt(dot(A,A));\n\t}\n\t\n\tboolean isZero(double [] X) {\n\t\treturn close(dot(X,X),0);\n\t}\n\t\n\tdouble [] normalize(double [] X) {\n\t\treturn scalar(1/norm(X),X);\n\t}\n\t\n\tdouble dist (double [] A, double [] B) {\n\t\treturn norm(diff(A,B));\n\t}\n\t\n\tdouble [] scalar (double c, double [] A) {\n\t\tdouble [] cA = new double [A.length];\n\t\tfor (int i = 0; i < A.length; ++i)\n\t\t\tcA[i] = c * A[i];\n\t\treturn cA;\n\t}\n\t\n\tdouble [] sum (double [] A, double [] B) {\n\t\tdouble [] C = new double [A.length];\n\t\tfor (int i = 0; i < A.length; ++i)\n\t\t\tC[i] = A[i] + B[i]; \n\t\treturn C;\n\t}\n\n\tdouble [] diff (double [] A, double [] B) {\n\t\tdouble [] C = new double [A.length];\n\t\tfor (int i = 0; i < A.length; ++i)\n\t\t\tC[i] = A[i] - B[i]; \n\t\treturn C;\n\t}\n\t\n\tdouble [] cross (double [] A, double [] B) {\n\t\tdouble [] C = new double [A.length]; \n\t\t// TODO - This is only 3-dimensional\n\t\tC[0] = A[1]*B[2] - B[1]*A[2];\n\t\tC[1] = A[2]*B[0] - B[2]*A[0];\n\t\tC[2] = A[0]*B[1] - B[0]*A[1];\n\t\treturn C;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\tprivate void print (Object o) {\n\t\tSystem.out.println(o);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tnew E(sc);\n\t}\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7bbf06e3fec557604c83ea9e60ae32b0", "src_uid": "25b2a84f0c3f574cdffd59a902b2326e", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "//package round90re;\nimport java.awt.geom.Line2D;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni();\n\t\tdouble[][] co = new double[n][];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tco[i] = new double[]{ni(), ni(), ni()};\n\t\t}\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tdouble[] nor = new double[]{ni(), ni(), ni()};\n\t\t\tdouble[][] nco = rot(nor, new double[]{0, 0, 1}, co);\n\t\t\tout.printf(\"%.15f\\n\", minCircle(nco));\n\t\t}\n\t}\n\t\n\tpublic double minCircle(double[][] co)\n\t{\n\t\tint n = co.length;\n\t\tif(n <= 1)return 0;\n\t\t\n\t\t// \u6700\u9060\u70b9\u3092\u9078\u3076\n\t\tdouble maxd = -1;\n\t\tint first = -1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tdouble d2 = co[i][0]*co[i][0]+co[i][1]*co[i][1];\n\t\t\tif(d2 > maxd){\n\t\t\t\tmaxd = d2;\n\t\t\t\tfirst = i;\n\t\t\t}\n\t\t}\n\t\t\n\t\t// 2\u70b9\u306b\u63a5\u3059\u308b\u3088\u3046\u306b\u6700\u9060\u70b9\u306b\u8fd1\u3065\u3044\u3066\u3044\u304f\n\t\t// (tx,ty)\u304c(x,y)-(x',y')\u306e\u5782\u76f4\u4e8c\u7b49\u5206\u7dda\u3092\u3068\u304a\u308b\u3088\u3046\u306a\u6700\u5c0f\u306et\n\t\t// (T-M)*L=0\n\t\t// t(x*Lx+y*Ly)=mx*Lx+my*Ly\n\t\tdouble mint = 1.01;\n\t\tint second = -1;\n\t\tdouble fx = co[first][0], fy = co[first][1];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(i == first)continue;\n\t\t\tdouble ox = co[i][0], oy = co[i][1];\n\t\t\tdouble mx = (fx+ox)/2, my = (fy+oy)/2;\n\t\t\tdouble t = (mx*(ox-fx)+my*(oy-fy))/(fx*(ox-fx)+fy*(oy-fy));\n\t\t\tif(t < mint){\n\t\t\t\tmint = t;\n\t\t\t\tsecond = i;\n\t\t\t}\n\t\t}\n\t\tif(second == -1){ // second\u304c\u306a\u3044\u5834\u5408\u7e2e\u91cd\u3057\u3066\u3044\u308b\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\tboolean[] sed = new boolean[n];\n\t\tsed[first] = true;\n\t\tsed[second] = true;\n\t\t\n\t\t// C\u3092M\u306b\u8fd1\u3065\u3051\u3066\u3044\u304f\n\t\tint third = -1;\n\t\twhile(true){\n\t\t\tdouble mx = (co[first][0] + co[second][0])/2;\n\t\t\tdouble my = (co[first][1] + co[second][1])/2;\n\t\t\tdouble nr2 = (mx-co[first][0])*(mx-co[first][0])+(my-co[first][1])*(my-co[first][1]);\n\t\t\tdouble[] ec = null;\n\t\t\tthird = -1;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tif(sed[i])continue;\n//\t\t\t\tif(i == first || i == second)continue;\n\t\t\t\tif((mx-co[i][0])*(mx-co[i][0])+(my-co[i][1])*(my-co[i][1]) <= nr2)continue;\n\t\t\t\tdouble[] lec = excircle2(co[first][0], co[first][1], co[second][0], co[second][1], co[i][0], co[i][1]);\n\t\t\t\tif(ec == null || lec[2] > ec[2]){\n\t\t\t\t\tec = lec;\n\t\t\t\t\tthird = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(ec == null)break;\n\t\t\tsed[third] = true;\n\t\t\tif(Line2D.linesIntersect(co[first][0], co[first][1], co[third][0], co[third][1], ec[0], ec[1], co[second][0], co[second][1])){\n\t\t\t\tsecond = third;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(Line2D.linesIntersect(co[second][0], co[second][1], co[third][0], co[third][1], ec[0], ec[1], co[first][0], co[first][1])){\n\t\t\t\tfirst = third;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn ec[2];\n\t\t}\n\t\treturn Math.sqrt((co[second][0]-co[first][0])*(co[second][0]-co[first][0])+(co[second][1]-co[first][1])*(co[second][1]-co[first][1]))/2;\n\t}\n\t\n\tpublic static double[] excircle2(double ax, double ay, double bx, double by, double cx, double cy)\n\t{\n\t\tdouble A = (bx-cx)*(bx-cx)+(by-cy)*(by-cy);\n\t\tdouble B = (cx-ax)*(cx-ax)+(cy-ay)*(cy-ay);\n\t\tdouble C = (ax-bx)*(ax-bx)+(ay-by)*(ay-by);\n\t\tdouble D = A*(-A+B+C)+B*(A-B+C)+C*(A+B-C);\n\t\tdouble X = (A*(-A+B+C)*ax + B*(A-B+C)*bx + C*(A+B-C)*cx) / D;\n\t\tdouble Y = (A*(-A+B+C)*ay + B*(A-B+C)*by + C*(A+B-C)*cy) / D;\n\t\tdouble R = Math.sqrt((X-ax)*(X-ax)+(Y-ay)*(Y-ay));\n//\t\tdouble R = A*B*C/Math.sqrt((A+B+C)*(-A+B+C)*(A-B+C)*(A+B-C));\n\t\treturn new double[]{X, Y, R};\n\t}\n\t\n\tpublic static double[][] rot(double[] from, double[] to, double[][] xs)\n\t{\n\t\tdouble nfrom = Math.sqrt(from[0]*from[0]+from[1]*from[1]+from[2]*from[2]);\n\t\tfor(int i = 0;i < 3;i++)from[i] /= nfrom;\n\t\tdouble nto = Math.sqrt(to[0]*to[0]+to[1]*to[1]+to[2]*to[2]);\n\t\tfor(int i = 0;i < 3;i++)to[i] /= nto;\n\t\tdouble dot = from[0]*to[0]+from[1]*to[1]+from[2]*to[2];\n\t\tif(dot >= 1)dot = 1;\n\t\tif(dot <= -1)dot = -1;\n\t\tdouble angle = Math.acos(dot);\n\t\tif(Math.abs(angle) < 1E-8)return xs;\n\t\t\n\t\tdouble[] axis = new double[]{\n\t\t\t\tfrom[1]*to[2]-from[2]*to[1],\n\t\t\t\tfrom[2]*to[0]-from[0]*to[2],\n\t\t\t\tfrom[0]*to[1]-from[1]*to[0]\n\t\t};\n\t\tdouble nax = Math.sqrt(axis[0]*axis[0]+axis[1]*axis[1]+axis[2]*axis[2]);\n\t\tfor(int i = 0;i < 3;i++)axis[i] /= nax;\n\t\t\n\t\tdouble[][] ret = new double[xs.length][3];\n\t\t\n\t\tdouble ncos = Math.cos(angle);\n\t\tdouble nsin = Math.sin(angle);\n\t\tdouble scos = 1.0 - ncos;\n\t\t\n\t\tdouble sxy = axis[0] * axis[1] * scos;\n\t\tdouble syz = axis[1] * axis[2] * scos;\n\t\tdouble sxz = axis[0] * axis[2] * scos;\n\t\tdouble sz = nsin * axis[2];\n\t\tdouble sy = nsin * axis[1];\n\t\tdouble sx = nsin * axis[0];\n\t\t\n\t\tint p = 0;\n\t\tfor(double[] x : xs){\n\t\t\tret[p][0] = (ncos+axis[0]*axis[0]*scos)*x[0] + (-sz+sxy)*x[1]+(sy+sxz)*x[2];\n\t\t\tret[p][1] = (sz+sxy)*x[0]+(ncos+axis[1]*axis[1]*scos)*x[1]+(-sx+syz)*x[2];\n\t\t\tret[p][2] = (-sy+sxz)*x[0]+(sx+syz)*x[1]+(ncos+axis[2]*axis[2]*scos)*x[2];\n\t\t\tp++;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b4825dda080d9cda9b856c72ea48f9da", "src_uid": "25b2a84f0c3f574cdffd59a902b2326e", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "/**\n * JUDGE_ID : 104262PN\n * User : \u0414\u0435\u043d\u0438\u0441\n * Date : 27.04.11\n * Time : 17:53\n * ICQ : 785625\n * Email : popokus@gmail.com\n */\n\nimport java.io.*;\n\npublic class s70_d {\n public static void main(String[] args) throws IOException {\n new s70_d().run();\n }\n\n int nextInt() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\n\n StreamTokenizer in;\n Writer writer;\n Reader reader;\n\n void run() throws IOException {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n reader = oj ? new InputStreamReader(System.in, \"ISO-8859-1\") : new FileReader(\"input/is70_d.txt\");\n writer = new OutputStreamWriter(System.out, \"ISO-8859-1\");\n in = new StreamTokenizer(new BufferedReader(reader));\n PrintWriter out = new PrintWriter(writer);\n int R = nextInt();\n double full = Math.sqrt(3);\n double half = full / 2;\n Hexagen hexagen = new Hexagen( 0, 0,\n 0.5 , half,\n 1 , 0,\n 0.5 , -half,\n -0.5 , -half,\n -1 , 0,\n -0.5 , half);\n\n int count = 0;\n // up, up-right, down-right, down, down-left, up-left\n int[] xC = {0, 1, 1, 0, -1, -1};\n int[] yC = {1, 1, 0, -1, -1, 0};\n\n double[] dx = {0, 1 + 0.5, 1 + 0.5, 0 , - 1 - 0.5 , - 1 - 0.5 };\n double[] dy = {full, half, -half, -full, - half, half};\n boolean up = true;\n while (true) {\n int index;\n if (up) {\n index = 0;\n } else {\n index = 3;\n }\n Hexagen h = new Hexagen(hexagen.xCord + xC[index], hexagen.yCord + yC[index],\n hexagen.x1 + dx[index], hexagen.y1 + dy[index],\n hexagen.x2 + dx[index], hexagen.y2 + dy[index],\n hexagen.x3 + dx[index], hexagen.y3 + dy[index],\n hexagen.x4 + dx[index], hexagen.y4 + dy[index],\n hexagen.x5 + dx[index], hexagen.y5 + dy[index],\n hexagen.x6 + dx[index], hexagen.y6 + dy[index]);\n if (!isOnCircle(R, h.x1, h.y1,\n h.x2, h.y2 ,\n h.x3, h.y3,\n h.x4, h.y4,\n h.x5, h.y5,\n h.x6, h.y6)) {\n if ((h.y3 > R && up) || (!up && -h.y1 > R)) {\n if (up) {\n up = false;\n // shift to right-up\n index = 1;\n } else {\n up = true;\n // shift to right-down\n index = 2;\n }\n hexagen = new Hexagen(hexagen.xCord + xC[index], hexagen.yCord + yC[index],\n hexagen.x1 + dx[index], hexagen.y1 + dy[index],\n hexagen.x2 + dx[index], hexagen.y2 + dy[index],\n hexagen.x3 + dx[index], hexagen.y3 + dy[index],\n hexagen.x4 + dx[index], hexagen.y4 + dy[index],\n hexagen.x5 + dx[index], hexagen.y5 + dy[index],\n hexagen.x6 + dx[index], hexagen.y6 + dy[index]);\n if (hexagen.x2 > R)\n break;\n } else {\n hexagen = h;\n }\n } else {\n hexagen = h;\n count++;\n }\n }\n out.println(count*2 + 1);\n out.flush();\n out.close();\n }\n boolean isOnCircle(int radius, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {\n double d1 = Math.sqrt(x1 * x1 + y1 * y1);\n double d2 = Math.sqrt(x2 * x2 + y2 * y2);\n double d3 = Math.sqrt(x3 * x3 + y3 * y3);\n double d4 = Math.sqrt(x4 * x4 + y4 * y4);\n double d5 = Math.sqrt(x5 * x5 + y5 * y5);\n double d6 = Math.sqrt(x6 * x6 + y6 * y6);\n if (d1 > radius && d1 - radius > 1e-6) return false;\n if (d2 > radius && d2 - radius > 1e-6) return false;\n if (d3 > radius && d3 - radius > 1e-6) return false;\n if (d4 > radius && d4 - radius > 1e-6) return false;\n if (d5 > radius && d5 - radius > 1e-6) return false;\n if (d6 > radius && d6 - radius > 1e-6) return false;\n return true;\n }\n\n }\n\n class Hexagen {\n int xCord;\n int yCord;\n double x1, x2, x3, x4, x5, x6;\n double y1, y2, y3, y4, y5, y6;\n Hexagen(int xCord, int yCord, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {\n this.xCord = xCord;\n this.yCord = yCord;\n this.x1 = x1;\n this.x2 = x2;\n this.x3 = x3;\n this.x4 = x4;\n this.x5 = x5;\n this.x6 = x6;\n\n this.y1 = y1;\n this.y2 = y2;\n this.y3 = y3;\n this.y4 = y4;\n this.y5 = y5;\n this.y6 = y6;\n }\n }\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4b8e7b012bff5986c819f9fca9ff8ec", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "/**\n * JUDGE_ID : 104262PN\n * User : \u0414\u0435\u043d\u0438\u0441\n * Date : 27.04.11\n * Time : 17:53\n * ICQ : 785625\n * Email : popokus@gmail.com\n */\n\nimport java.io.*;\n\npublic class s70_d {\n public static void main(String[] args) throws IOException {\n new s70_d().run();\n }\n\n int nextInt() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\n\n StreamTokenizer in;\n Writer writer;\n Reader reader;\n\n void run() throws IOException {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n reader = oj ? new InputStreamReader(System.in, \"ISO-8859-1\") : new FileReader(\"input/is70_d.txt\");\n writer = new OutputStreamWriter(System.out, \"ISO-8859-1\");\n in = new StreamTokenizer(new BufferedReader(reader));\n PrintWriter out = new PrintWriter(writer);\n int R = nextInt();\n double full = Math.sqrt(3);\n double half = full / 2;\n Hexagen hexagen = new Hexagen(\n 0.5 , half,\n 1 , 0,\n 0.5 , -half,\n -0.5 , -half,\n -1 , 0,\n -0.5 , half);\n\n long count = 0;\n // up, up-right, down-right, down, down-left, up-left\n int[] xC = {0, 1, 1, 0, -1, -1};\n int[] yC = {1, 1, 0, -1, -1, 0};\n\n double[] dx = {0, 1 + 0.5, 1 + 0.5, 0 , - 1 - 0.5 , - 1 - 0.5 };\n double[] dy = {full, half, -half, -full, - half, half};\n boolean up = true;\n while (true) {\n int index;\n if (up) {\n index = 0;\n } else {\n index = 3;\n }\n Hexagen h = new Hexagen(\n hexagen.x1 + dx[index], hexagen.y1 + dy[index],\n hexagen.x2 + dx[index], hexagen.y2 + dy[index],\n hexagen.x3 + dx[index], hexagen.y3 + dy[index],\n hexagen.x4 + dx[index], hexagen.y4 + dy[index],\n hexagen.x5 + dx[index], hexagen.y5 + dy[index],\n hexagen.x6 + dx[index], hexagen.y6 + dy[index]);\n if (!isOnCircle(R, h.x1, h.y1,\n h.x2, h.y2 ,\n h.x3, h.y3,\n h.x4, h.y4,\n h.x5, h.y5,\n h.x6, h.y6)) {\n if ((h.y3 > R && up) || (!up && -h.y1 > R)) {\n if (up) {\n up = false;\n // shift to right-up\n index = 1;\n } else {\n up = true;\n // shift to right-down\n index = 2;\n }\n hexagen = new Hexagen(\n hexagen.x1 + dx[index], hexagen.y1 + dy[index],\n hexagen.x2 + dx[index], hexagen.y2 + dy[index],\n hexagen.x3 + dx[index], hexagen.y3 + dy[index],\n hexagen.x4 + dx[index], hexagen.y4 + dy[index],\n hexagen.x5 + dx[index], hexagen.y5 + dy[index],\n hexagen.x6 + dx[index], hexagen.y6 + dy[index]);\n if (hexagen.x2 > R)\n break;\n } else {\n hexagen = h;\n }\n } else {\n hexagen = h;\n count++;\n }\n }\n out.println(count*2 + 1);\n out.flush();\n out.close();\n }\n boolean isOnCircle(int radius, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {\n double d1 = Math.sqrt(x1 * x1 + y1 * y1);\n double d2 = Math.sqrt(x2 * x2 + y2 * y2);\n double d3 = Math.sqrt(x3 * x3 + y3 * y3);\n double d4 = Math.sqrt(x4 * x4 + y4 * y4);\n double d5 = Math.sqrt(x5 * x5 + y5 * y5);\n double d6 = Math.sqrt(x6 * x6 + y6 * y6);\n if (d1 > radius && d1 - radius > 1e-6) return false;\n if (d2 > radius && d2 - radius > 1e-6) return false;\n if (d3 > radius && d3 - radius > 1e-6) return false;\n if (d4 > radius && d4 - radius > 1e-6) return false;\n if (d5 > radius && d5 - radius > 1e-6) return false;\n if (d6 > radius && d6 - radius > 1e-6) return false;\n return true;\n }\n\n }\n\n class Hexagen {\n double x1, x2, x3, x4, x5, x6;\n double y1, y2, y3, y4, y5, y6;\n Hexagen(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {\n this.x1 = x1;\n this.x2 = x2;\n this.x3 = x3;\n this.x4 = x4;\n this.x5 = x5;\n this.x6 = x6;\n\n this.y1 = y1;\n this.y2 = y2;\n this.y3 = y3;\n this.y4 = y4;\n this.y5 = y5;\n this.y6 = y6;\n }\n }\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ba4da06bed4d0f7e4e65d0e1dc98d2db", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "/**\n * JUDGE_ID : 104262PN\n * User : \u0414\u0435\u043d\u0438\u0441\n * Date : 27.04.11\n * Time : 17:53\n * ICQ : 785625\n * Email : popokus@gmail.com\n */\n\nimport java.io.*;\n\npublic class s70_d {\n public static void main(String[] args) throws IOException {\n new s70_d().run();\n }\n\n int nextInt() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\n\n StreamTokenizer in;\n Writer writer;\n Reader reader;\n\n void run() throws IOException {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n reader = oj ? new InputStreamReader(System.in, \"ISO-8859-1\") : new FileReader(\"input/is70_d.txt\");\n writer = new OutputStreamWriter(System.out, \"ISO-8859-1\");\n in = new StreamTokenizer(new BufferedReader(reader));\n PrintWriter out = new PrintWriter(writer);\n int R = nextInt();\n double full = Math.sqrt(3);\n double half = full / 2;\n Hexagen hexagen = new Hexagen(\n 0.5 , half,\n 1 , 0,\n 0.5 , -half,\n -0.5 , -half,\n -1 , 0,\n -0.5 , half);\n\n long count = 0;\n // up, up-right, down-right, down, down-left, up-left\n int[] xC = {0, 1, 1, 0, -1, -1};\n int[] yC = {1, 1, 0, -1, -1, 0};\n\n double[] dx = {0, 1 + 0.5, 1 + 0.5, 0 , - 1 - 0.5 , - 1 - 0.5 };\n double[] dy = {full, half, -half, -full, - half, half};\n boolean up = true;\n while (true) {\n int index;\n if (up) {\n index = 0;\n } else {\n index = 3;\n }\n Hexagen h = new Hexagen(\n hexagen.x1 + dx[index], hexagen.y1 + dy[index],\n hexagen.x2 + dx[index], hexagen.y2 + dy[index],\n hexagen.x3 + dx[index], hexagen.y3 + dy[index],\n hexagen.x4 + dx[index], hexagen.y4 + dy[index],\n hexagen.x5 + dx[index], hexagen.y5 + dy[index],\n hexagen.x6 + dx[index], hexagen.y6 + dy[index]);\n if (!isOnCircle(R, h.x1, h.y1,\n h.x2, h.y2 ,\n h.x3, h.y3,\n h.x4, h.y4,\n h.x5, h.y5,\n h.x6, h.y6)) {\n if ((h.y3 > R && up) || (!up && -h.y1 > R)) {\n if (up) {\n up = false;\n // shift to right-up\n index = 1;\n } else {\n up = true;\n // shift to right-down\n index = 2;\n }\n hexagen = new Hexagen(\n hexagen.x1 + dx[index], hexagen.y1 + dy[index],\n hexagen.x2 + dx[index], hexagen.y2 + dy[index],\n hexagen.x3 + dx[index], hexagen.y3 + dy[index],\n hexagen.x4 + dx[index], hexagen.y4 + dy[index],\n hexagen.x5 + dx[index], hexagen.y5 + dy[index],\n hexagen.x6 + dx[index], hexagen.y6 + dy[index]);\n if (hexagen.x2 > R)\n break;\n } else {\n hexagen = h;\n }\n } else {\n hexagen = h;\n count++;\n }\n }\n out.println(count * 2 + 1);\n out.flush();\n out.close();\n }\n boolean isOnCircle(int radius, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {\n double d1 = Math.sqrt(x1 * x1 + y1 * y1);\n if (d1 > radius && d1 - radius > 1e-6) return false;\n double d2 = Math.sqrt(x2 * x2 + y2 * y2);\n if (d2 > radius && d2 - radius > 1e-6) return false;\n double d3 = Math.sqrt(x3 * x3 + y3 * y3);\n if (d3 > radius && d3 - radius > 1e-6) return false;\n double d4 = Math.sqrt(x4 * x4 + y4 * y4);\n if (d4 > radius && d4 - radius > 1e-6) return false;\n double d5 = Math.sqrt(x5 * x5 + y5 * y5);\n if (d5 > radius && d5 - radius > 1e-6) return false;\n double d6 = Math.sqrt(x6 * x6 + y6 * y6);\n if (d6 > radius && d6 - radius > 1e-6) return false;\n return true;\n }\n\n }\n\n class Hexagen {\n double x1, x2, x3, x4, x5, x6;\n double y1, y2, y3, y4, y5, y6;\n Hexagen(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {\n this.x1 = x1;\n this.x2 = x2;\n this.x3 = x3;\n this.x4 = x4;\n this.x5 = x5;\n this.x6 = x6;\n\n this.y1 = y1;\n this.y2 = y2;\n this.y3 = y3;\n this.y4 = y4;\n this.y5 = y5;\n this.y6 = y6;\n }\n }\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "784eb3df8fdd5cd8fc801a7675381260", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class ArchersShot {\n\tpublic static void main(String[] Args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextInt();\n\t\tif(n<=2){\n\t\t\tSystem.out.println(1);\n\t\t}\n\t\telse{\n\t\t\tlong ans = 1;\n\t\t\tboolean done = false;\n\t\t\tint dist = 2;\n\t\t\tint layer = 0;\n\t\t\twhile(!done){\n\t\t\t\tdouble dDist = dist + .5;\n\t\t\t\tlayer++;\n\t\t\t\tlong hi = layer + 1;\n\t\t\t\tlong lo = 0; \n\t\t\t\twhile(lo != hi - 1){\n\t\t\t\t\tlong mid = (hi + lo) / 2;\n\t\t\t\t\tif(dDist*dDist + (mid * 2 - 1) * (mid * 2 - 1) * 3.0 / 4 <= n * n + 1e-9)\n\t\t\t\t\t\tlo = mid;\n\t\t\t\t\telse\n\t\t\t\t\t\thi = mid;\n\t\t\t\t}\n\t\t\t\tif(lo == 0)break;\n\t\t\t\tans += 6 * lo * 2;\n\t\t\t\tif(lo == layer)\n\t\t\t\t\tans-=6;\n\t\t\t\tdDist = dist + 2;\n\t\t\t\thi = layer + 2;\n\t\t\t\tlo = 0; \n\t\t\t\twhile(lo != hi - 1){\n\t\t\t\t\tlong mid = (hi + lo) / 2;\n\t\t\t\t\tif(dDist*dDist + (mid - 1) * (mid - 1) * 3.0 <= n * n + 1e-9)\n\t\t\t\t\t\tlo = mid;\n\t\t\t\t\telse\n\t\t\t\t\t\thi = mid;\n\t\t\t\t}\n\t\t\t\tif(lo == 0)break;\n\t\t\t\tans += 6 * lo;\n\t\t\t\tdist += 3;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n\tpublic static long get(int k){\n\t\treturn ((k*1l*(k-1)) / 2) * 6 +1\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4d257f3cdb69b4ca168bd5222f9e1818", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n ECommonNumber solver = new ECommonNumber();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class ECommonNumber {\n private long[][] dp = new long[62][2];\n private long n;\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n long n = in.readLong();\n long m = in.readLong();\n\n LongBinarySearch lbs1 = new LongBinarySearch() {\n\n public boolean check(long mid) {\n mid = mid * 2 + 1;\n return count(n, mid) < m;\n }\n };\n LongBinarySearch lbs2 = new LongBinarySearch() {\n\n public boolean check(long mid) {\n mid = mid * 2;\n return count(n, mid) + count(n, mid + 1) < m;\n }\n };\n\n long ans1 = lbs1.binarySearch(1, n / 2);\n if (ans1 == 0) {\n ans1 = -1;\n } else if (lbs1.check(ans1)) {\n ans1 = (ans1 - 1) * 2 + 1;\n } else {\n ans1 = ans1 * 2 + 1;\n }\n\n long ans2 = lbs2.binarySearch(0, n / 2);\n if (ans2 == 0) {\n ans2 = -1;\n } else if (lbs2.check(ans2)) {\n ans2 = (ans2 - 1) * 2;\n } else {\n ans2 = ans2 * 2;\n }\n\n long ans = Math.max(ans1, ans2);\n out.println(ans);\n }\n\n public long dp(int i, int ceil) {\n if (i < 0) {\n return 1;\n }\n if (dp[i][ceil] == -1) {\n int bit = Bits.bitAt(n, i);\n dp[i][ceil] = 0;\n for (int j = 0; j <= 1; j++) {\n if (ceil == 1 && j > bit) {\n continue;\n }\n dp[i][ceil] += dp(i - 1, ceil == 1 &&\n bit == j ? 1 : 0);\n }\n }\n return dp[i][ceil];\n }\n\n public long count(long n, long prefix) {\n if (prefix > n) {\n return 0;\n }\n int len = CachedLog2.floorLog(prefix);\n int totalLen = CachedLog2.floorLog(n);\n long ans = 0;\n for (int i = len; i < totalLen; i++) {\n ans += 1 << (i - len);\n }\n this.n = n;\n SequenceUtils.deepFill(dp, -1L);\n if (prefix > (n >>> (totalLen - len))) {\n return ans;\n }\n int ceil = (prefix == (n >>> (totalLen - len))) ? 1 : 0;\n long plus = dp(totalLen - len - 1, ceil);\n return ans + plus;\n }\n\n }\n\n static class SequenceUtils {\n public static void deepFill(Object array, long val) {\n if (!array.getClass().isArray()) {\n throw new IllegalArgumentException();\n }\n if (array instanceof long[]) {\n long[] longArray = (long[]) array;\n Arrays.fill(longArray, val);\n } else {\n Object[] objArray = (Object[]) array;\n for (Object obj : objArray) {\n deepFill(obj, val);\n }\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(long c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(long 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 CachedLog2 {\n private static final int BITS = 16;\n private static final int LIMIT = 1 << BITS;\n private static final byte[] CACHE = new byte[LIMIT];\n\n static {\n int b = 0;\n for (int i = 0; i < LIMIT; i++) {\n while ((1 << (b + 1)) <= i) {\n b++;\n }\n CACHE[i] = (byte) b;\n }\n }\n\n public static int floorLog(long x) {\n int ans = 0;\n while (x >= LIMIT) {\n ans += BITS;\n x >>>= BITS;\n }\n return ans + CACHE[(int) x];\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 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 Bits {\n private Bits() {\n }\n\n public static int bitAt(long x, int i) {\n return (int) ((x >> i) & 1);\n }\n\n }\n\n static abstract class LongBinarySearch {\n public abstract boolean check(long mid);\n\n public long binarySearch(long l, long r) {\n if (l > r) {\n throw new IllegalArgumentException();\n }\n while (l < r) {\n long mid = (l + r) >>> 1;\n if (check(mid)) {\n r = mid;\n } else {\n l = mid + 1;\n }\n }\n return l;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3981bcc2cd2ef0047cd6c76446f48db3", "src_uid": "783c4b3179c558369f94f4a16ac562d4", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "\n// Problem : E. Common Number\n// Contest : Codeforces Round #608 (Div. 2)\n// URL : https://codeforces.com/contest/1271/problem/E\n// Memory Limit : 256.000000MB \n// Time Limit : 2000.000000milisec \n// Powered by CP Editor (https://github.com/coder3101/cp-editor2)\n\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\nimport java.util.StringTokenizer;\nimport java.util.Arrays;\nimport java.util.List;\n\npublic class a {\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n Task solver = new Task();\n solver.solve(1, in, out);\n \n out.close();\n }\n \n static class Task {\n \n private long n;\n private long k;\n \n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n k = in.nextInt();\n \n long lo = 1, hi1 = n / 2;\n while (lo <= hi1) {\n long mi = hi1 - (hi1 - lo) / 2;\n if (count (2 * mi) >= k) {\n lo = mi + 1;\n }\n else hi1 = mi - 1;\n }\n lo = 1;\n long hi2 = n / 2;\n while (lo <= hi2) {\n long mi = hi2 - (hi2 - lo) / 2;\n if (count (2 * mi - 1) >= k)\n lo = mi + 1;\n else hi2 = mi - 1;\n }\n hi1 *= 2;\n hi2 = hi2 * 2 - 1;\n if (hi1 == 0)\n hi1 = 1;\n out.println(hi1 > hi2 ? hi1 : hi2);\n }\n \n private long count(long x) {\n long sol = 0;\n long pow = 1;\n if ((x & 1) == 1 && 2 * x <= n) {\n x *= 2;\n ++sol;\n }\n while (x <= n) {\n long nr = (1 << pow);\n if (x + nr <= n) {\n x *= 2;\n sol += nr;\n ++pow;\n } else {\n sol += n - x + 1;\n break;\n }\n }\n return sol;\n }\n }\n \n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n \n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n \n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a161b2b052d58e677c2fbab9f9038294", "src_uid": "783c4b3179c558369f94f4a16ac562d4", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class EdE {\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tlong num = 998244353;\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\tStringTokenizer st = new StringTokenizer(bf.readLine());\n \t\tlong n = Long.parseLong(st.nextToken());\n \t\tlong k = Long.parseLong(st.nextToken());\n \t\tlong l = 1;\n \t\tlong r = (n+1)/2;\n \t\twhile(l < r){\n \t\t\tlong mid = (l+r+1)/2;\n \t\t\tif (appearFirstN(n, 2*mid) >=k)\n \t\t\t\tl = mid;\n \t\t\telse\n \t\t\t\tr = mid-1;\n \t\t}\n \t\t\n \t\tif (n == k)\n \t\t\tout.println(1);\n \t\telse\n \t\t\tout.println(appearFirstN(n, 2*l+1) >= k ? 2*l+1 : 2*l);\n\t \t\t\n \t\tout.close();\n \t\t\n \t\t\n \t\t\n \t}\n\tpublic static long appearFirstN(long n, long k){\n\t\tlong ans =0;\n\t\tif (k%2 == 0){\n\t\t\tk/=2;\n\t\t\tans-=1;\n\t\t}\n\t\t\n\t\tString a = Long.toString(n, 2);\n\t\tlong prod = 1;\n\t\tString b = Long.toString(k, 2);\n\t\tif (a.substring(0, b.length()).equals(b)){\n\t\t\tans+= (Long.parseLong(a.substring(b.length()), 2)+1);\n\t\t}\n\t\telse if (a.substring(0, b.length()).compareTo(b) > 0){\n\t\t\tprod = 2;\n\t\t}\n\t\t\n\t\tfor(int j =0;j=k)\n \t\t\t\tl = mid;\n \t\t\telse\n \t\t\t\tr = mid-1;\n \t\t}\n \t\t\n \t\tif (n == k)\n \t\t\tout.println(1);\n \t\telse\n \t\t\tout.println(appearFirstN(n, 2L*l+1L) >= k ? 2L*l+1L : 2L*l);\n\t \t\t\n \t\tout.close();\n \t\t\n \t\t\n \t\t\n \t}\n\tpublic static long appearFirstN(long n, long k){\n\t\tif (k > n)\n\t\t\treturn 0;\n\t\tlong ans =0;\n\t\tif (k%2 == 0){\n\t\t\tk/=2;\n\t\t\tans-=1;\n\t\t}\n\t\t\n\t\tString a = Long.toString(n, 2);\n\t\tlong prod = 1;\n\t\tString b = Long.toString(k, 2);\n\t\tif (a.substring(0, b.length()).equals(b)){\n\t\t\tans+= (Long.parseLong(a.substring(b.length()), 2)+1);\n\t\t}\n\t\telse if (a.substring(0, b.length()).compareTo(b) > 0){\n\t\t\tprod = 2;\n\t\t}\n\t\t\n\t\tfor(int j =0;j lines;\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n lines = new ArrayList<>(9);\n for (int i = 0; i < 3; i++) {\n lines.add(in.nextLine());\n }\n in.nextLine();\n for (int i = 0; i < 3; i++) {\n lines.add(in.nextLine());\n }\n in.nextLine();\n for (int i = 0; i < 3; i++) {\n lines.add(in.nextLine());\n }\n\n\n Integer row = (in.nextInt() - 1) % 3;\n Integer col = (in.nextInt() - 1) % 3;\n\n if (!isFull(row, col)) {\n fill(row, col);\n int counter = 0;\n for (String line : lines) {\n if(counter>0 && counter%3 == 0){\n out.println();\n }\n\n out.println(line);\n counter++;\n }\n } else {\n int counter = 0;\n for (String line : lines) {\n if(counter>0 && counter%3 == 0){\n out.println();\n }\n\n String s = line.replace('.', '!');\n out.println(s);\n counter++;\n }\n\n }\n }\n\n\n public void fill(Integer row, Integer col){\n for(int i = row * 3; i < (row+1) * 3; i++){\n char[] ch = lines.get(i).toCharArray();\n for(int j= col * 3; j < (col+1) * 3; j++){\n if(ch[j] == '.'){\n ch[j] = '!';\n }\n }\n lines.set(i, new String(ch));\n }\n\n }\n public Boolean isFull(Integer row, Integer col){\n for(int i = row * 3; i < (row+1) * 3; i++){\n String s = lines.get(i);\n for(int j= col * 3; j < (col+1) * 3; j++){\n if(s.charAt(j) == '.'){\n return Boolean.FALSE;\n }\n\n }\n }\n return Boolean.TRUE;\n }\n\n\n\n\n\n\n\n\n\n\n\n\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 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 public long nextLong() { return Long.parseLong(next()); }\n\n}\n\n\n\nclass Pair {\n public final F first;\n public final S second;\n\n\n\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 @Override\n public int hashCode() {\n return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());\n }\n\n @Override\n public String toString() {\n return \"(\" + first + \", \" + second + ')';\n }\n}\n\nclass IntPair extends Pair{\n public IntPair(Integer first, Integer second){\n super(first, second);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3028a18199d984f45fcd976fa4ac39ee", "src_uid": "8f0fad22f629332868c39969492264d3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Abhilash\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 TaskB.Node table[][] = new TaskB.Node[3][3];\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n table[i][j] = new TaskB.Node();\n }\n }\n\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 3; j++) {\n String s = in.next();\n table[i / 3][j].fill(s, i % 3);\n }\n }\n\n int x = in.nextInt() - 1;\n int y = in.nextInt() - 1;\n\n int p = x % 3;\n int q = y % 3;\n\n int count = table[p][q].fill2();\n\n if (count == 0) {\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n if (i != p || j != q) {\n table[i][j].fill2();\n }\n }\n }\n }\n\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 3; j++) {\n out.print(table[i / 3][j].sarr[i % 3] + \" \");\n }\n out.println();\n if (i % 3 == 2)\n out.println();\n }\n }\n\n static class Node {\n char arr = new char[3][3];\n String sarr = new String[3];\n\n void fill(String s, int idx) {\n for (int i = 0; i < 3; i++) {\n arr[idx][i] = s.charAt(i);\n }\n sarr[idx] = s;\n }\n\n int fill2() {\n int count = 0;\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n if (arr[i][j] == '.') {\n arr[i][j] = '!';\n count += 1;\n }\n }\n sarr[i] = arr[i][0] + \"\" + arr[i][1] + arr[i][2];\n }\n return count;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1a0593fa892f84acc6faef53357c2ebc", "src_uid": "8f0fad22f629332868c39969492264d3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic final class BTicTacToe {\n\n private void solve(InputReader in, PrintWriter out, int tn) throws IOException {\n char [][] a = new char[9][9];\n for (int i = 0; i < 9; i++) {\n if (i%3==0 && i!=0){\n in.reader.read();\n }\n for (int j = 0; j < 9; j++) {\n if (j % 3 == 0 && j!= 0){\n in.reader.read();\n }\n a[i][j] = (char) in.reader.read();\n }\n in.reader.read();\n }\n try {\n int si = ((in.nextInt() - 1) % 3) * 3;\n } catch (Exception e) {\n for (int i = 0; i < 9; i++) {\n if (i%3==0 && i!=0){\n out.println();\n }\n for (int j = 0; j < 9; j++) {\n if (j % 3 == 0 && j!= 0){\n out.print(\" \");\n }\n out.print(a[i][j]);\n }\n out.println();\n }\n }\n try {\n int sj = ((in.nextInt() - 1) % 3) * 3;\n } catch (Exception e) {\n for (int i = 0; i < 9; i++) {\n if (i%3==0 && i!=0){\n out.println();\n }\n for (int j = 0; j < 9; j++) {\n if (j % 3 == 0 && j!= 0){\n out.print(\" \");\n }\n out.print(a[i][j]);\n }\n out.println();\n }\n }\n\n /*for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n out.print(a[i][j]+\" \");\n }\n out.println();\n }\n out.println(si);\n out.println(sj);*/\n int si =4;\n boolean ok = false;\n for (int i = si; i < si+3; i++) {\n for (int j = sj; j < sj+3; j++) {\n if (a[i][j] == '.') {\n a[i][j] = '!';\n ok = true;\n }\n }\n }\n\n if (!ok){\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (a[i][j] == '.') {\n a[i][j] = '!';\n }\n }\n }\n }\n\n for (int i = 0; i < 9; i++) {\n if (i%3==0 && i!=0){\n out.println();\n }\n for (int j = 0; j < 9; j++) {\n if (j % 3 == 0 && j!= 0){\n out.print(\" \");\n }\n out.print(a[i][j]);\n }\n out.println();\n }\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) throws IOException {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n new BTicTacToe().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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "28bd634ca68860f846ef881787b9e3c6", "src_uid": "8f0fad22f629332868c39969492264d3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Abhilash\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 TaskB.Node table[][] = new TaskB.Node[3][3];\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n table[i][j] = new TaskB.Node();\n }\n }\n\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 3; j++) {\n String s = in.next();\n table[i / 3][j].fill(s, i % 3);\n }\n }\n\n int x = in.nextInt() - 1;\n int y = in.nextInt() - 1;\n\n int p = x % 3;\n int q = y % 3;\n\n int count = table[p][q].fill2();\n\n if (count == 0) {\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n if (i != p || j != q) {\n table[i][j].fill2();\n }\n }\n }\n }\n\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 3; j++) {\n out.print(table[i / 3][j].sarr[i % 3] + \" \");\n }\n out.println();\n if (i % 3 == 2)\n out.println();\n }\n }\n\n public static class Node {\n char arr = new char[3][3];\n String sarr = new String[3];\n\n void fill(String s, int idx) {\n for (int i = 0; i < 3; i++) {\n arr[idx][i] = s.charAt(i);\n }\n sarr[idx] = s;\n }\n\n int fill2() {\n int count = 0;\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n if (arr[i][j] == '.') {\n arr[i][j] = '!';\n count += 1;\n }\n }\n sarr[i] = arr[i][0] + \"\" + arr[i][1] + arr[i][2];\n }\n return count;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4358873abe0c93855e9526d58b90176b", "src_uid": "8f0fad22f629332868c39969492264d3", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class CodeForces\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner input = new Scanner(System.in);\n\n\t\tint[][] array = new int[101][101];\n\t\tint[][] for2type = new int[101][101];\n\t\tfor (int i = 2; i <= 100; i++)\n\t\t{\n\t\t\tfor (int j = 2; j <= 100; j++)\n\t\t\t{\n\t\t\t\tArrayList primes = factors(j);\n\t\t\t\tArrayList missed = new ArrayList<>();\n\t\t\t\tboolean check = true;\n\t\t\t\tfor (int k = 0; k < primes.size(); k++)\n\t\t\t\t{\n\t\t\t\t\tif (i % primes.get(k) != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tmissed.add(primes.get(k));\n\t\t\t\t\t\tcheck = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (check)\n\t\t\t\t{\n\t\t\t\t\tarray[i][j] = 2;\n\t\t\t\t\tfor (int k = 1; k < Integer.MAX_VALUE; k++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (power(i, k) % j == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor2type[i][j] = k;\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} else if (i % j == 1)\n\t\t\t\t{\n\t\t\t\t\tarray[i][j] = 3;\n\t\t\t\t} else if ((i + 1) % j == 0)\n\t\t\t\t{\n\t\t\t\t\tarray[i][j] = 11;\n\t\t\t\t} else\n\t\t\t\t{\n\t\t\t\t\tboolean bad = false;\n\t\t\t\t\tfor (int k = 0; k < primes.size(); k++)\n\t\t\t\t\t{\n\t\t\t\t\t\tint num = 0;\n\t\t\t\t\t\tfor (int l = 1; l < Integer.MAX_VALUE; l++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint z = power(primes.get(k), l);\n\t\t\t\t\t\t\tif (j % z == 0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tnum = z;\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t{\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\tif (array[i][num] == 0 || array[i][num] == 7)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbad = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (bad)\n\t\t\t\t\t{\n\t\t\t\t\t\tarray[i][j] = 7;\n\t\t\t\t\t} else\n\t\t\t\t\t{\n\t\t\t\t\t\tarray[i][j] = 6;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint b = input.nextInt();\n\t\tint d = input.nextInt();\n\t\tSystem.out.println(array[b][d] + \"-type\");\n\t\tif (array[b][d] == 2)\n\t\t{\n\t\t\tSystem.out.println(for2type[b][d]);\n\t\t}\n\t}\n\n\tpublic static ArrayList factors(int n)\n\t{\n\t\tArrayList list = new ArrayList<>();\n\t\twhile (n > 1)\n\t\t{\n\t\t\tfor (int i = 2; i <= n; i++)\n\t\t\t{\n\t\t\t\tif (n % i == 0)\n\t\t\t\t{\n\t\t\t\t\tn = n / i;\n\t\t\t\t\tif (!list.contains(i))\n\t\t\t\t\t{\n\t\t\t\t\t\tlist.add(i);\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\treturn list;\n\t}\n\n\tpublic static int power(int a, int b)\n\t{\n\t\tint result = 1;\n\t\twhile (b > 0)\n\t\t{\n\t\t\tif (b % 2 != 0)\n\t\t\t{\n\t\t\t\tresult = (result * a);\n\t\t\t\tb--;\n\t\t\t}\n\t\t\ta = (a * a);\n\t\t\tb /= 2;\n\t\t}\n\n\t\treturn result;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c4471ddb0b416184bc5efa3486ff7df", "src_uid": "809e1c78b0a5a16f7f2115b046a20bde", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n \n static String filename = \"\";\n \n int[] factorize(int n) {\n ArrayList ans = new ArrayList();\n for (int i = 2; i <= n; i++) {\n while (n % i == 0) {\n ans.add(i);\n n /= i;\n }\n }\n int[] ansa = new int[ans.size()];\n for (int i = 0; i < ans.size(); i++) {\n ansa[i] = ans.get(i);\n }\n return ansa;\n }\n \n int gcd(int a, int b) {\n while (b != 0) {\n a %= b;\n int temp = a;\n a = b;\n b = temp;\n }\n return a;\n }\n \n int digitsum(int n, int b) {\n int ans = 0;\n while (n > 0) {\n ans += n % b;\n n /= b;\n }\n return ans;\n }\n \n int get3(int b) {\n Random rnd = new Random();\n int ans = 0;\n for (int i = 0; i < 10000; i++) {\n int num = rnd.nextInt(1000000000);\n ans = gcd(ans, num - digitsum(num, b));\n }\n return ans;\n }\n \n int is2type(int b, int d) {\n int[] bfactors = factorize(b);\n int[] dfactors = factorize(d);\n \n boolean type2 = true;\n TreeMap bf = new TreeMap();\n for (int i : bfactors) {\n if (!bf.containsKey(i)) {\n bf.put(i, 0);\n }\n bf.put(i, bf.get(i) + 1);\n }\n TreeMap df = new TreeMap();\n for (int i : dfactors) {\n if (!df.containsKey(i)) {\n df.put(i, 0);\n }\n df.put(i, df.get(i) + 1);\n }\n for (int i : dfactors) {\n if (!bf.containsKey(i)) {\n type2 = false;\n }\n }\n \n if (type2) {\n int ans = 0;\n long pow = 1;\n while (pow % d != 0) {\n pow *= b;\n ans++;\n /*\n for (Map.Entry e : df.entrySet()) {\n System.out.println(e.getKey() + \" \" + e.getValue());\n }\n System.out.println();\n */\n }\n return ans;\n } else {\n return -1;\n }\n }\n \n boolean is3type(int b, int d) {\n return (b - 1) % d == 0;\n }\n \n boolean is11type(int b, int d) {\n return (b + 1) % d == 0;\n }\n \n HashMap type6 = new HashMap();\n \n boolean is6type(int b, int d) {\n if (type6.containsKey(d)) {\n return type6.get(d);\n }\n for (int i = 2; i < d; i++) {\n if (d % i == 0) {\n int di = d / i;\n if (i % di == 0 || di % i == 0) {\n continue;\n }\n boolean[] m1 = getMask(b, i);\n boolean[] m2 = getMask(b, di);\n for (int ii = 0; ii < 4; ii++) {\n for (int jj = 0; jj < 4; jj++) {\n if (ii == jj) {\n continue;\n }\n if (m1[ii] && m2[jj]) {\n type6.put(d, true);\n return true;\n }\n }\n }\n /*\n if (is2type(b, i) != -1 || is3type(b, i) || is11type(b, i) || is6type(b, i)) {\n if (is2type(b, di) != -1 || is3type(b, di) || is11type(b, di) || is6type(b, di)) {\n if (is3type(b, i) && is3type(b, di))\n continue;\n type6.put(d, true);\n return true;\n }\n }\n */\n }\n }\n type6.put(d, false);\n return false;\n }\n \n boolean[] getMask(int b, int d) {\n boolean[] ans = new boolean[4];\n ans[0] = is2type(b, d) != -1;\n ans[1] = is3type(b, d);\n ans[2] = is11type(b, d);\n ans[3] = is6type(b, d);\n return ans;\n }\n \n public void solve() throws Exception {\n int b = sc.nextInt(), d = sc.nextInt();\n int ans;\n if ((ans = is2type(b, d)) != -1) {\n out.println(\"2-type\");\n out.println(ans);\n } else if (is3type(b, d)) {\n out.println(\"3-type\");\n } else if (is11type(b, d)) {\n out.println(\"11-type\");\n } else if (is6type(b, d)) {\n out.println(\"6-type\");\n } else {\n out.println(\"7-type\");\n }\n }\n \n BufferedReader in;\n PrintWriter out;\n FastScanner sc;\n \n public static void main(String[] args) {\n new Thread(null, new Main(), \"\", 1 << 25).start();\n }\n \n @Override\n public void run() {\n try {\n init();\n solve();\n } catch (Exception e) {\n throw new RuntimeException(e);\n } finally {\n out.close();\n }\n }\n \n void init() throws Exception {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n sc = new FastScanner(in);\n }\n}\n\nclass FastScanner {\n \n BufferedReader reader;\n StringTokenizer strTok;\n \n public FastScanner(BufferedReader reader) {\n this.reader = reader;\n }\n \n public String nextToken() throws IOException {\n while (strTok == null || !strTok.hasMoreTokens()) {\n strTok = new StringTokenizer(reader.readLine());\n }\n \n return strTok.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n \n public BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e3559ef8d406dccfc66f9fdcaf469c4d", "src_uid": "809e1c78b0a5a16f7f2115b046a20bde", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class c {\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tint b = input.nextInt(), d = input.nextInt();\n\tint[] fsb = new int[101], fsd = new int[101];\n\tint bb = b, dd = d;\n\tfor(int i = 2; i<=100; i++)\n\t{\n\t\twhile(bb%i == 0)\n\t\t{\n\t\t\tfsb[i]++;\n\t\t\tbb /= i;\n\t\t}\n\t\twhile(dd%i == 0)\n\t\t{\n\t\t\tfsd[i]++;\n\t\t\tdd /= i;\n\t\t}\n\t}\n\tboolean two = true;\n\tint max = 0;\n\tfor(int i = 2; i<100; i++)\n\t{\n\t\tif(fsd[i] > 0 && fsb[i] == 0) two = false;\n\t\telse if(fsd[i] > 0)\n\t\t{\n\t\t\tmax = Math.max(max, (fsd[i] + fsb[i] - 1)/fsb[i]);\n\t\t}\n\t}\n\tif(two)\n\t{\n\t\tout.println(\"2-type\");\n\t\tout.println(max);\n\t}\n\telse if(b%d == 1)\n\t{\n\t\tout.println(\"3-type\");\n\t}\n\telse if((b+1)%d == 0)\n\t{\n\t\tout.println(\"11-type\");\n\t}\n\telse\n\t{\n\t\tboolean good = true;\n\t\tfor(int i = 0; i<100; i++)\n\t\t{\n\t\t\tif(fsd[i] == 0) continue;\n\t\t\tint pow = 1;\n\t\t\tfor(int j = 0; j 0 || b%pow == 1 || (b+1)%pow == 0;\n\t\t}\n\t\tout.println(good ? \"6-type\" : \"7-type\");\n\t}\n\tout.close();\n}\n\npublic static class input {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\n\tstatic void init(InputStream input) {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "946736fee25e42d76f55763e94cb8b5e", "src_uid": "809e1c78b0a5a16f7f2115b046a20bde", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.*;\n\npublic class Main\n{\t\n\tpublic BufferedReader in;\n\tpublic PrintStream out;\n\t\n\tpublic boolean log_enabled = true;\n\t\n\tpublic int[] calc(int x, int d)\n\t{\n\t\tint[] res = new int[2], res2;\n\t\t\n\t\tint dd = d, i;\n\t\tfor (i=1; i<8; i++)\n\t\t{\n\t\t\tif (dd % x == 0)\n\t\t\t{\n\t\t\t\tres[0] = 2;\n\t\t\t\tres[1] = i;\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\tdd *= d;\n\t\t}\n\t\t\n\t\tif (d % x == 1)\n\t\t{\n\t\t\tres[0] = 3;\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tif (d % x == x-1)\n\t\t{\n\t\t\tres[0] = 11;\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\ti=2;\n\t\tint x0 = x;\n\t\twhile ((x>1)&&(i 9) {\n tt = 0;\n while (t > 0) {\n tt += t % 10;\n t /= 10;\n }\n t = tt;\n }\n return t;\n }\n\n public void doPrime() {\n int i, j, erat[] = new int[n + 1];\n prime = new int[n];\n\n nprime = 1;\n prime[0] = 2;\n for (i = 3; i <= n; i = i + 2) {\n if (erat[i] == 0) {\n prime[nprime] = i;\n nprime++;\n j = i + i;\n while (j <= n) {\n erat[j] = 1;\n j += i;\n }\n }\n }\n }\n\n public void doDivs() {\n int i, j, k, t, p, d;\n divs = new int[n + 1];\n\n divs[1] = 1;\n for (i = 2; i <= n; i++) {\n d = 1;\n j = 0;\n p = prime[j];\n t = i;\n while (p <= i) {\n k = 0;\n while (t % p == 0) {\n k++;\n t /= p;\n }\n if (k > 0) d *= (1 + k);\n j++;\n if (j >= nprime) break;\n p = prime[j];\n }\n divs[i] = d;\n }\n }\n\n public void run() throws IOException {\n in = new Scanner(System.in);\n out = new PrintWriter(System.out);\n\n int i, j, k, nn;\n\n n = in.nextInt();\n nn = n;\n long n2 = n;\n n2 *= n2;\n if (nn < 81) nn = 81;\n byroot = new long[10];\n roots = new int[1000001];\n long byrootx[][] = new long[10][10];\n doPrime();\n\n// out.println(\"prime ok\");\n// out.flush();\n\n doDivs();\n\n// out.println(\"divs ok\");\n// out.flush();\n\n for (i = 1; i <= nn; i++) {\n roots[i] = getRoot(i);\n if (i <= n) byroot[roots[i]]++;\n }\n for (j = 1; j <= 9; j++)\n for (k = 1; k <= 9; k++)\n byrootx[j][k] = byroot[j] * byroot[k];\n out.flush();\n res = 0;\n for (i = 1; i <= n; i++) {\n for (j = 1; j <= 9; j++)\n for (k = 1; k <= 9; k++)\n if (roots[j * k] == roots[i]) res += byrootx[j][k];\n res -= divs[i];\n }\n out.println(res);\n \n in.close();\n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5454a6bbf556d9afdffeaf0cb5659ec2", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.util.StringTokenizer;\n\npublic class MainC {\n\n private FastScanner in;\n private PrintWriter out;\n\n public void solve() throws IOException {\n int N = in.nextInt();\n byte[] digitRoot = new byte[Math.max(N + 1, 100)];\n for (int i = 1; i < digitRoot.length; i++) {\n int s = 0;\n int k = i;\n while (k >= 10) {\n s = s + k % 10;\n k = k / 10;\n }\n s = s + k;\n if (s < 10) {\n digitRoot[i] = (byte) s;\n }\n else {\n digitRoot[i] = digitRoot[s];\n }\n }\n\n int[] digitRootCount = new int[10];\n for (int i = 1; i <= N; i++) {\n digitRootCount[digitRoot[i]]++;\n }\n\n BigDecimal countAll = new BigDecimal(0);\n for (int i = 1; i <= 9; i++) {\n for (int j = 1; j <= 9; j++) {\n for (int k = 1; k <= 9; k++) {\n if (digitRoot[j * k] == i) {\n long temp = digitRootCount[i];\n temp *= digitRootCount[j];\n temp *= digitRootCount[k];\n // if (temp != 0) {\n // out.println(i + \" \" + j + \" \" + k);\n // }\n BigDecimal t = new BigDecimal(temp);\n countAll = countAll.add(t);\n }\n }\n }\n }\n\n long count = 2 * N - 1;\n for (int i = 1; i <= N; i++) {\n int j = 2;\n while (j * j <= i) {\n if (i % j == 0) {\n if (j * j == i) {\n count++;\n }\n else {\n count = count + 2;\n }\n }\n j = j + 1;\n }\n }\n\n out.println(countAll.subtract(new BigDecimal(count)));\n }\n\n public void run() {\n try {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n class FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] arg) {\n new MainC().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "da7ed745fa8d1067d79b1dc30c5550c1", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\n/**\n * Created by James on 1/29/2015.\n */\n\npublic class Driver {\n public static void main(String [] args) throws IOException {\n BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n\n int N = Integer.parseInt(scanner.readLine().trim()), count = 0;\n\n for (int i = 1; i <= N; ++i) {\n for (int j = 1; j <= N; ++j) {\n for (int k = 1; k <= N; ++k) {\n if (d(d(i) * d(j)) == d(k) && i * j != k) {\n //out.println(i + \" \" + j + \" \" + k);\n count++;\n }\n }\n }\n }\n\n out.println(count);\n out.close();\n }\n\n private static int d(int N) {\n if (N < 10) {\n return N;\n }\n\n String num = Integer.toString(N);\n int sum = 0;\n\n for (int i = 0; i < num.length(); ++i) {\n sum += Integer.parseInt(String.valueOf(num.charAt(i)));\n }\n\n return d(sum);\n }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d5e521585303b212fe4e4fb7ee480ccb", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Parser in = new Parser(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskC {\n int mod = 1000000007;\n\n public void solve(int testNumber, Parser in, OutputWriter out) {\n long n = in.nextLong();\n int k = in.nextInt();\n\n long[][] pas = MathUtils.pas(41, mod);\n Matrix a = new Matrix(83);\n\n a.a[0][0] = 1;\n a.a[0][k+1] = 1;\n\n for (int pot = 0; pot <= 40; pot++) {\n for (int coef = 0; coef <= pot; coef++) {\n a.a[pot+1][coef+1] = pas[pot][coef];\n a.a[pot+1][coef+42] = (pas[pot][coef] * ((1L << (pot-coef)) % mod)) % mod;\n }\n }\n\n for (int pot = 0; pot <= 40; pot++) {\n a.a[pot+42][pot+1] = 1;\n }\n\n Matrix b = new Matrix(83);\n for (int i = 1; i <= 42; i++) b.a[i][0] = 1;\n\n a = a.modpow(n, mod);\n a = a.multiply(b, mod);\n /*for (int i = 0; i < 83; i++) {\n System.out.println(\"i \" + i + \" elem: \" + a.a[i][0]);\n }*/\n\n out.println(a.a[0][0]);\n }\n}\n\nclass Parser\n{\n private BufferedReader din;\n private StringTokenizer tokenizer;\n\n public Parser(InputStream in)\n {\n din = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(din.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n public long nextLong()\n {\n return Long.parseLong(next());\n }\n\n }\n\nclass OutputWriter extends PrintWriter {\n public OutputWriter(Writer out) {\n super(out);\n }\n\n public OutputWriter(OutputStream out) {\n super(out);\n }\n\n }\n\nclass MathUtils {\n\n public static long[][] pas(int n, int mod) {\n long[][] ret = new long[n+1][n+1];\n\n for (int i = 0; i <= n; i++) {\n ret[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n ret[i][j] = (ret[i-1][j-1] + ret[i-1][j]) % mod;\n }\n }\n\n return ret;\n }\n\n }\n\nclass Matrix {\n int n;\n long a[][];\n\n public Matrix(int n) {\n this.n = n;\n a = new long[n][n];\n }\n\n public static Matrix identity(int n) {\n Matrix ret = new Matrix(n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n ret.a[i][j] = 0;\n }\n ret.a[i][i] = 1;\n }\n\n return ret;\n }\n\n Matrix multiply(Matrix b, long mod) {\n Matrix resp = new Matrix(n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n resp.a[i][j] = 0;\n for (int k = 0; k < n; k++) {\n resp.a[i][j] = (resp.a[i][j] + a[i][k] * b.a[k][j]) % mod;\n }\n }\n }\n\n return resp;\n }\n\n Matrix modpow(long exp, long mod) {\n if (exp == 0) return identity(n);\n if (exp == 1) return this;\n\n Matrix h = modpow(exp/2, mod);\n h = h.multiply(h, mod);\n if (exp % 2 == 1) h = h.multiply(this, mod);\n\n return h;\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bfffc65437227973d6c6d3b9abcde431", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null} {"lang": "Java 8", "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.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 << 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 CYetAnotherNumberSequence solver = new CYetAnotherNumberSequence();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CYetAnotherNumberSequence {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int k = in.readInt();\n\n Modular mod = new Modular(1000000007);\n Power power = new Power(mod);\n\n int[] fib = new int[200];\n fib[0] = 1;\n fib[1] = 2;\n int[] a = new int[200];\n for (int i = 2; i < 200; i++) {\n fib[i] = mod.plus(fib[i - 1], fib[i - 2]);\n }\n for (int i = 0; i < 200; i++) {\n a[i] = mod.mul(fib[i], power.pow(i + 1, k));\n if (i > 0) {\n a[i] = mod.plus(a[i], a[i - 1]);\n }\n }\n\n IntegerList seq = new IntegerList();\n seq.addAll(a);\n LinearRecurrenceSolver solver = LinearRecurrenceSolver.newSolverFromSequence(seq, mod);\n int ans = solver.solve(n - 1, seq);\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 int subtract(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 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 int[] getData() {\n return data;\n }\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 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 private void checkRange(int i) {\n if (i < 0 || i >= size) {\n throw new ArrayIndexOutOfBoundsException(\"index \" + i + \" out of range\");\n }\n }\n\n public int get(int i) {\n checkRange(i);\n return data[i];\n }\n\n public void add(int x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(int[] x) {\n addAll(x, 0, x.length);\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 expandWith(int x, int len) {\n ensureSpace(len);\n while (size < len) {\n data[size++] = x;\n }\n }\n\n public void retain(int n) {\n if (n < 0) {\n throw new IllegalArgumentException();\n }\n if (n >= size) {\n return;\n }\n size = n;\n }\n\n public void set(int i, int x) {\n checkRange(i);\n data[i] = x;\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 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 ModLinearFeedbackShiftRegister {\n private IntegerList cm;\n int m = -1;\n int dm;\n private IntegerList cn;\n private IntegerList buf;\n private IntegerList seq;\n private Modular mod;\n private Power pow;\n\n public ModLinearFeedbackShiftRegister(Modular mod, int cap) {\n cm = new IntegerList(cap + 1);\n cn = new IntegerList(cap + 1);\n seq = new IntegerList(cap + 1);\n buf = new IntegerList(cap + 1);\n cn.add(1);\n\n this.mod = mod;\n this.pow = new Power(mod);\n }\n\n public ModLinearFeedbackShiftRegister(Modular mod) {\n this(mod, 0);\n }\n\n private int estimateDelta() {\n int n = seq.size() - 1;\n int ans = 0;\n int[] cnData = cn.getData();\n int[] seqData = seq.getData();\n for (int i = 0, until = cn.size(); i < until; i++) {\n ans = mod.plus(ans, mod.mul(cnData[i], seqData[n - i]));\n }\n return ans;\n }\n\n public void add(int x) {\n x = mod.valueOf(x);\n int n = seq.size();\n\n seq.add(x);\n int dn = estimateDelta();\n if (dn == 0) {\n return;\n }\n\n if (m < 0) {\n cm.clear();\n cm.addAll(cn);\n dm = dn;\n m = n;\n\n cn.expandWith(0, n + 2);\n return;\n }\n\n int ln = cn.size() - 1;\n int len = Math.max(ln, n + 1 - ln);\n buf.clear();\n buf.addAll(cn);\n buf.expandWith(0, len + 1);\n\n int factor = mod.mul(dn, pow.inverseByFermat(dm));\n\n int[] bufData = buf.getData();\n int[] cmData = cm.getData();\n for (int i = n - m, until = n - m + cm.size(); i < until; i++) {\n bufData[i] = mod.subtract(bufData[i], mod.mul(factor, cmData[i - (n - m)]));\n }\n\n if (cn.size() < buf.size()) {\n IntegerList tmp = cm;\n cm = cn;\n cn = tmp;\n m = n;\n dm = dn;\n }\n {\n IntegerList tmp = cn;\n cn = buf;\n buf = tmp;\n }\n\n\n }\n\n public int length() {\n return cn.size() - 1;\n }\n\n public String toString() {\n return cn.toString();\n }\n\n public int codeAt(int i) {\n return mod.valueOf(-cn.get(i));\n }\n\n }\n\n static class Buffer {\n private Deque deque;\n private Supplier supplier;\n private Consumer cleaner;\n\n public Buffer(Supplier supplier) {\n this(supplier, (x) -> {\n });\n }\n\n public Buffer(Supplier supplier, Consumer cleaner) {\n this(supplier, cleaner, 0);\n }\n\n public Buffer(Supplier supplier, Consumer cleaner, int exp) {\n this.supplier = supplier;\n this.cleaner = cleaner;\n deque = new ArrayDeque<>(exp);\n }\n\n public T alloc() {\n return deque.isEmpty() ? supplier.get() : deque.removeFirst();\n }\n\n public void release(T e) {\n cleaner.accept(e);\n deque.addLast(e);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(int c) {\n cache.append(c).append('\\n');\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class LinearRecurrenceSolver {\n Modular mod;\n IntegerList coe;\n IntegerList p;\n IntegerList remainder;\n Power pow;\n int n;\n\n private LinearRecurrenceSolver(IntegerList coe, Modular mod) {\n this.coe = coe;\n this.mod = mod;\n n = coe.size();\n pow = new Power(mod);\n remainder = new IntegerList(coe.size());\n p = new IntegerList(coe.size() + 1);\n for (int i = n - 1; i >= 0; i--) {\n p.add(mod.valueOf(-coe.get(i)));\n }\n p.add(1);\n }\n\n public static LinearRecurrenceSolver newSolverFromLinearRecurrence(IntegerList coe, Modular mod) {\n return new LinearRecurrenceSolver(coe, mod);\n }\n\n public static LinearRecurrenceSolver newSolverFromSequence(IntegerList seq, Modular mod) {\n ModLinearFeedbackShiftRegister lfsr = new ModLinearFeedbackShiftRegister(mod, seq.size());\n for (int i = 0; i < seq.size(); i++) {\n lfsr.add(seq.get(i));\n }\n IntegerList coes = new IntegerList(lfsr.length());\n for (int i = 1; i <= lfsr.length(); i++) {\n coes.add(lfsr.codeAt(i));\n }\n return newSolverFromLinearRecurrence(coes, mod);\n }\n\n private int solve(IntegerList a) {\n int ans = 0;\n remainder.expandWith(0, n);\n for (int i = 0; i < n; i++) {\n ans = mod.plus(ans, mod.mul(remainder.get(i), a.get(i)));\n }\n return ans;\n }\n\n public int solve(long k, IntegerList a) {\n if (k < a.size()) {\n return a.get((int) k);\n }\n Polynomials.module(k, p, remainder, pow);\n return solve(a);\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 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 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 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\n static class Polynomials {\n public static Buffer listBuffer = new Buffer<>(IntegerList::new, list -> list.clear());\n private static ExtGCD extGCD = new ExtGCD();\n\n public static int rankOf(IntegerList p) {\n int[] data = p.getData();\n int r = p.size() - 1;\n while (r >= 0 && data[r] == 0) {\n r--;\n }\n return Math.max(0, r);\n }\n\n public static void normalize(IntegerList list) {\n list.retain(rankOf(list) + 1);\n }\n\n public static void mul(IntegerList a, IntegerList b, IntegerList c, Modular mod) {\n int rA = rankOf(a);\n int rB = rankOf(b);\n c.clear();\n c.expandWith(0, rA + rB + 1);\n int[] aData = a.getData();\n int[] bData = b.getData();\n int[] cData = c.getData();\n for (int i = 0; i <= rA; i++) {\n for (int j = 0; j <= rB; j++) {\n cData[i + j] = mod.plus(cData[i + j], mod.mul(aData[i], bData[j]));\n }\n }\n }\n\n public static void divide(IntegerList a, IntegerList b, IntegerList c, IntegerList remainder, Power pow) {\n Modular mod = pow.getModular();\n int rA = rankOf(a);\n int rB = rankOf(b);\n\n if (rA < rB) {\n c.clear();\n c.add(0);\n remainder.clear();\n remainder.addAll(a);\n return;\n }\n\n int rC = Math.max(0, rA - rB);\n c.clear();\n c.expandWith(0, rC + 1);\n remainder.clear();\n remainder.addAll(a);\n\n int[] bData = b.getData();\n int[] cData = c.getData();\n int[] rData = remainder.getData();\n\n if (extGCD.extgcd(b.get(rB), mod.getMod()) != 1) {\n throw new IllegalArgumentException();\n }\n int inv = mod.valueOf(extGCD.getX());\n for (int i = rA, j = rC; i >= rB; i--, j--) {\n if (rData[i] == 0) {\n continue;\n }\n int factor = mod.mul(-rData[i], inv);\n cData[j] = mod.valueOf(-factor);\n for (int k = rB; k >= 0; k--) {\n rData[k + j] = mod.plus(rData[k + j], mod.mul(factor, bData[k]));\n }\n }\n\n normalize(remainder);\n }\n\n public static void module(long k, IntegerList p, IntegerList remainder, Power pow) {\n int rP = rankOf(p);\n if (rP == 0) {\n remainder.clear();\n remainder.add(0);\n return;\n }\n\n IntegerList a = listBuffer.alloc();\n IntegerList c = listBuffer.alloc();\n\n module(k, a, p, c, remainder, rP, pow);\n\n listBuffer.release(a);\n listBuffer.release(c);\n }\n\n private static void module(long k, IntegerList a, IntegerList b, IntegerList c, IntegerList remainder, int rb, Power pow) {\n Modular mod = pow.getModular();\n if (k < rb) {\n remainder.clear();\n remainder.expandWith(0, (int) k + 1);\n remainder.set((int) k, 1);\n return;\n }\n module(k / 2, a, b, c, remainder, rb, pow);\n mul(remainder, remainder, a, mod);\n if (k % 2 == 1) {\n int ra = rankOf(a);\n a.expandWith(0, ra + 2);\n int[] aData = a.getData();\n for (int i = ra; i >= 0; i--) {\n aData[i + 1] = aData[i];\n }\n aData[0] = 0;\n }\n divide(a, b, c, remainder, pow);\n }\n\n }\n\n static class Power {\n final Modular modular;\n\n public Modular getModular() {\n return modular;\n }\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 public int inverseByFermat(int x) {\n return pow(x, modular.m - 2);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "36e8894662c5bed3718932929809f02c", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null} {"lang": "Java 8", "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.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 << 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 CYetAnotherNumberSequence solver = new CYetAnotherNumberSequence();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CYetAnotherNumberSequence {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n long n = in.readLong();\n int k = in.readInt();\n\n Modular mod = new Modular(1000000007);\n Power power = new Power(mod);\n\n int[] fib = new int[100];\n fib[0] = 1;\n fib[1] = 2;\n int[] a = new int[100];\n for (int i = 2; i < 100; i++) {\n fib[i] = mod.plus(fib[i - 1], fib[i - 2]);\n }\n for (int i = 0; i < 100; i++) {\n a[i] = mod.mul(fib[i], power.pow(i + 1, k));\n if (i > 0) {\n a[i] = mod.plus(a[i], a[i - 1]);\n }\n }\n\n IntegerList seq = new IntegerList();\n seq.addAll(a);\n LinearRecurrenceSolver solver = LinearRecurrenceSolver.newSolverFromSequence(seq, mod);\n int ans = solver.solve(n - 1, seq);\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 int subtract(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 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 int[] getData() {\n return data;\n }\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 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 private void checkRange(int i) {\n if (i < 0 || i >= size) {\n throw new ArrayIndexOutOfBoundsException(\"index \" + i + \" out of range\");\n }\n }\n\n public int get(int i) {\n checkRange(i);\n return data[i];\n }\n\n public void add(int x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(int[] x) {\n addAll(x, 0, x.length);\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 expandWith(int x, int len) {\n ensureSpace(len);\n while (size < len) {\n data[size++] = x;\n }\n }\n\n public void retain(int n) {\n if (n < 0) {\n throw new IllegalArgumentException();\n }\n if (n >= size) {\n return;\n }\n size = n;\n }\n\n public void set(int i, int x) {\n checkRange(i);\n data[i] = x;\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 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 ModLinearFeedbackShiftRegister {\n private IntegerList cm;\n int m = -1;\n int dm;\n private IntegerList cn;\n private IntegerList buf;\n private IntegerList seq;\n private Modular mod;\n private Power pow;\n\n public ModLinearFeedbackShiftRegister(Modular mod, int cap) {\n cm = new IntegerList(cap + 1);\n cn = new IntegerList(cap + 1);\n seq = new IntegerList(cap + 1);\n buf = new IntegerList(cap + 1);\n cn.add(1);\n\n this.mod = mod;\n this.pow = new Power(mod);\n }\n\n public ModLinearFeedbackShiftRegister(Modular mod) {\n this(mod, 0);\n }\n\n private int estimateDelta() {\n int n = seq.size() - 1;\n int ans = 0;\n int[] cnData = cn.getData();\n int[] seqData = seq.getData();\n for (int i = 0, until = cn.size(); i < until; i++) {\n ans = mod.plus(ans, mod.mul(cnData[i], seqData[n - i]));\n }\n return ans;\n }\n\n public void add(int x) {\n x = mod.valueOf(x);\n int n = seq.size();\n\n seq.add(x);\n int dn = estimateDelta();\n if (dn == 0) {\n return;\n }\n\n if (m < 0) {\n cm.clear();\n cm.addAll(cn);\n dm = dn;\n m = n;\n\n cn.expandWith(0, n + 2);\n return;\n }\n\n int ln = cn.size() - 1;\n int len = Math.max(ln, n + 1 - ln);\n buf.clear();\n buf.addAll(cn);\n buf.expandWith(0, len + 1);\n\n int factor = mod.mul(dn, pow.inverseByFermat(dm));\n\n int[] bufData = buf.getData();\n int[] cmData = cm.getData();\n for (int i = n - m, until = n - m + cm.size(); i < until; i++) {\n bufData[i] = mod.subtract(bufData[i], mod.mul(factor, cmData[i - (n - m)]));\n }\n\n if (cn.size() < buf.size()) {\n IntegerList tmp = cm;\n cm = cn;\n cn = tmp;\n m = n;\n dm = dn;\n }\n {\n IntegerList tmp = cn;\n cn = buf;\n buf = tmp;\n }\n\n\n }\n\n public int length() {\n return cn.size() - 1;\n }\n\n public String toString() {\n return cn.toString();\n }\n\n public int codeAt(int i) {\n return mod.valueOf(-cn.get(i));\n }\n\n }\n\n static class Buffer {\n private Deque deque;\n private Supplier supplier;\n private Consumer cleaner;\n\n public Buffer(Supplier supplier) {\n this(supplier, (x) -> {\n });\n }\n\n public Buffer(Supplier supplier, Consumer cleaner) {\n this(supplier, cleaner, 0);\n }\n\n public Buffer(Supplier supplier, Consumer cleaner, int exp) {\n this.supplier = supplier;\n this.cleaner = cleaner;\n deque = new ArrayDeque<>(exp);\n }\n\n public T alloc() {\n return deque.isEmpty() ? supplier.get() : deque.removeFirst();\n }\n\n public void release(T e) {\n cleaner.accept(e);\n deque.addLast(e);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(int c) {\n cache.append(c).append('\\n');\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class LinearRecurrenceSolver {\n Modular mod;\n IntegerList coe;\n IntegerList p;\n IntegerList remainder;\n Power pow;\n int n;\n\n private LinearRecurrenceSolver(IntegerList coe, Modular mod) {\n this.coe = coe;\n this.mod = mod;\n n = coe.size();\n pow = new Power(mod);\n remainder = new IntegerList(coe.size());\n p = new IntegerList(coe.size() + 1);\n for (int i = n - 1; i >= 0; i--) {\n p.add(mod.valueOf(-coe.get(i)));\n }\n p.add(1);\n }\n\n public static LinearRecurrenceSolver newSolverFromLinearRecurrence(IntegerList coe, Modular mod) {\n return new LinearRecurrenceSolver(coe, mod);\n }\n\n public static LinearRecurrenceSolver newSolverFromSequence(IntegerList seq, Modular mod) {\n ModLinearFeedbackShiftRegister lfsr = new ModLinearFeedbackShiftRegister(mod, seq.size());\n for (int i = 0; i < seq.size(); i++) {\n lfsr.add(seq.get(i));\n }\n IntegerList coes = new IntegerList(lfsr.length());\n for (int i = 1; i <= lfsr.length(); i++) {\n coes.add(lfsr.codeAt(i));\n }\n return newSolverFromLinearRecurrence(coes, mod);\n }\n\n private int solve(IntegerList a) {\n int ans = 0;\n remainder.expandWith(0, n);\n for (int i = 0; i < n; i++) {\n ans = mod.plus(ans, mod.mul(remainder.get(i), a.get(i)));\n }\n return ans;\n }\n\n public int solve(long k, IntegerList a) {\n if (k < a.size()) {\n return a.get((int) k);\n }\n Polynomials.module(k, p, remainder, pow);\n return solve(a);\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 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 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 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\n static class Polynomials {\n public static Buffer listBuffer = new Buffer<>(IntegerList::new, list -> list.clear());\n private static ExtGCD extGCD = new ExtGCD();\n\n public static int rankOf(IntegerList p) {\n int[] data = p.getData();\n int r = p.size() - 1;\n while (r >= 0 && data[r] == 0) {\n r--;\n }\n return Math.max(0, r);\n }\n\n public static void normalize(IntegerList list) {\n list.retain(rankOf(list) + 1);\n }\n\n public static void mul(IntegerList a, IntegerList b, IntegerList c, Modular mod) {\n int rA = rankOf(a);\n int rB = rankOf(b);\n c.clear();\n c.expandWith(0, rA + rB + 1);\n int[] aData = a.getData();\n int[] bData = b.getData();\n int[] cData = c.getData();\n for (int i = 0; i <= rA; i++) {\n for (int j = 0; j <= rB; j++) {\n cData[i + j] = mod.plus(cData[i + j], mod.mul(aData[i], bData[j]));\n }\n }\n }\n\n public static void divide(IntegerList a, IntegerList b, IntegerList c, IntegerList remainder, Power pow) {\n Modular mod = pow.getModular();\n int rA = rankOf(a);\n int rB = rankOf(b);\n\n if (rA < rB) {\n c.clear();\n c.add(0);\n remainder.clear();\n remainder.addAll(a);\n return;\n }\n\n int rC = Math.max(0, rA - rB);\n c.clear();\n c.expandWith(0, rC + 1);\n remainder.clear();\n remainder.addAll(a);\n\n int[] bData = b.getData();\n int[] cData = c.getData();\n int[] rData = remainder.getData();\n\n if (extGCD.extgcd(b.get(rB), mod.getMod()) != 1) {\n throw new IllegalArgumentException();\n }\n int inv = mod.valueOf(extGCD.getX());\n for (int i = rA, j = rC; i >= rB; i--, j--) {\n if (rData[i] == 0) {\n continue;\n }\n int factor = mod.mul(-rData[i], inv);\n cData[j] = mod.valueOf(-factor);\n for (int k = rB; k >= 0; k--) {\n rData[k + j] = mod.plus(rData[k + j], mod.mul(factor, bData[k]));\n }\n }\n\n normalize(remainder);\n }\n\n public static void module(long k, IntegerList p, IntegerList remainder, Power pow) {\n int rP = rankOf(p);\n if (rP == 0) {\n remainder.clear();\n remainder.add(0);\n return;\n }\n\n IntegerList a = listBuffer.alloc();\n IntegerList c = listBuffer.alloc();\n\n module(k, a, p, c, remainder, rP, pow);\n\n listBuffer.release(a);\n listBuffer.release(c);\n }\n\n private static void module(long k, IntegerList a, IntegerList b, IntegerList c, IntegerList remainder, int rb, Power pow) {\n Modular mod = pow.getModular();\n if (k < rb) {\n remainder.clear();\n remainder.expandWith(0, (int) k + 1);\n remainder.set((int) k, 1);\n return;\n }\n module(k / 2, a, b, c, remainder, rb, pow);\n mul(remainder, remainder, a, mod);\n if (k % 2 == 1) {\n int ra = rankOf(a);\n a.expandWith(0, ra + 2);\n int[] aData = a.getData();\n for (int i = ra; i >= 0; i--) {\n aData[i + 1] = aData[i];\n }\n aData[0] = 0;\n }\n divide(a, b, c, remainder, pow);\n }\n\n }\n\n static class Power {\n final Modular modular;\n\n public Modular getModular() {\n return modular;\n }\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 public int inverseByFermat(int x) {\n return pow(x, modular.m - 2);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "30d7d15d1a5e5dcf07d86d6f553ea6b7", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n void solve(){\n long n=nl();\n int k=ni();\n if(n==1){\n pw.println(\"1\");\n return;\n }\n precompute(k+2);\n sz=k+1+k+1+1;\n long Mat[][]=new long[sz][sz];\n for(int i=0;i<=k;i++){\n Mat[k+1+i][i]=1;\n }\n for(int c=0;c<=k;c++){\n for(int r=0;r<=c;r++){\n Mat[r][k+1+c]=mul(ncr(c,r),pow[c-r],M);\n Mat[k+1+r][k+1+c]=ncr(c,r);\n }\n }\n for(int i=0;i<=2*k+1;i++) Mat[i][2*k+2]=Mat[i][2*k+1];\n Mat[sz-1][sz-1]=1;\n\n Mat=pow(Mat,n-2);\n long arr[]=new long[sz];\n for(int i=0;i<=k;i++) arr[i]=1;\n for(int i=k+1;i<=2*k+1;i++) arr[i]=pow[i-k];\n arr[sz-1]=1;\n arr[sz-1]=add(arr[sz-1],pow[k+1],M);\n// for(int i=0;i0) return mul(A,C);\n return C;\n\n }\n long [][] mul(long A[][],long B[][]){\n long C[][]=new long[sz][sz];\n for(int i=0;i=0;i--) inv[i]=(inv[i+1]*(i+1))%M;\n\n\n }\n long add(long x,long y,long M){\n x+=y;\n if(x>=M) x-=M;\n return x;\n }\n long sub(long x,long y,long M){\n x-=y;\n if(x<0) x+=M;\n return x;\n }\n long mul(long x,long y,long M){\n x*=y;\n if(x>=M) x%=M;\n return x;\n }\n long modpow(long a, long b,long M)\n {\n long r=1;\n while(b>0)\n {\n if((b&1)>0) r=mul(r,a,M);\n a=mul(a,a,M);\n b>>=1;\n }\n return r;\n }\n\n long modInverse(long A, long M)\n {\n\n return modpow(A,M-2,M);\n }\n\n long M= (long)1e9+7;\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n void run() throws Exception {\n is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n pw = new PrintWriter(System.out);\n long s = System.currentTimeMillis();\n solve();\n pw.flush();\n if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n\n }\n public static void main(String[] args) throws Exception { new Main().run(); }\n\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1b6515eeb6827bcebdf1f3de18cbec73", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class D {\n\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\tint z = sc.nextInt();\n\t\t\n\t\tint x1 = sc.nextInt();\n\t\tint y1 = sc.nextInt();\n\t\tint z1 = sc.nextInt();\n\t\t\n\t\tint[] numbers = new int[6];\n\t\tfor (int i=0; i x1) {\n\t\t\ta5 = false;\n\t\t} else if (x < 0) {\n\t\t\ta6 = false;\n\t\t} else if (x >=0 && x<= x1) {\n\t\t\ta5 = false;\n\t\t\ta6 = false;\n\t\t}\n\t\t\n\t\tif (y > y1) {\n\t\t\ta1 = false;\n\t\t} else if (y < 0) {\n\t\t\ta2 = false;\n\t\t} else if (y >=0 && y <= y1) {\n\t\t\ta1 = false;\n\t\t\ta2 = false;\n\t\t}\n\t\t\n\t\tif (z > z1) {\n\t\t\ta3 = false;\n\t\t} else if (y < 0) {\n\t\t\ta4 = false;\n\t\t} else if (y >=0 && y <= y1) {\n\t\t\ta3 = false;\n\t\t\ta4 = false;\n\t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tif (a1) {\n\t\t\tans += numbers[0];\n\t\t}\n\t\tif (a2) {\n\t\t\tans += numbers[1];\n\t\t}\n\t\tif (a3) {\n\t\t\tans += numbers[2];\n\t\t}\n\t\tif (a4) {\n\t\t\tans += numbers[3];\n\t\t}\n\t\tif (a5) {\n\t\t\tans += numbers[4];\n\t\t}\n\t\tif (a6) {\n\t\t\tans += numbers[5];\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t\tsc.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "19871210bee157b475ebbc7e757cfd8a", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class ProblemC {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint kx = in.nextInt();\n\t\tint ky = in.nextInt();\n\t\tint kz = in.nextInt();\n\t\t\n\t\tint x = in.nextInt();\n\t\tint y = in.nextInt();\n\t\tint z = in.nextInt();\n\t\t\n\t\tint a0 = in.nextInt();\n\t\tint a1 = in.nextInt();\n\t\tint a2 = in.nextInt();\n\t\t\n\t\tint a3 = in.nextInt();\n\t\tint a4 = in.nextInt();\n\t\tint a5 = in.nextInt();\n\t\t\n\t\tint sum = 0;\n\t\t//FROM BOTTOM\n\t\tif ( ky < 0 ) {\n\t\t\tsum += a0;\n\t\t}\n\t\t//FROM TOP\n\t\tif ( ky > y ) {\n\t\t\tsum += a1;\n\t\t}\n\t\t\n\t\t\n\t\t//TWO SIDES\n\t\tif ( kx < 0 && kz < 0 ) {\n\t\t\tsum += a2+a4;\n\t\t}\n\t\t//TWO SIDES\n\t\tif ( kx < 0 && kz > z ) {\n\t\t\tsum += a3+a4;\n\t\t}\n\t\t//TWO SIDES\n\t\tif ( kx > x && kz > z ) {\n\t\t\tsum += a3+a5;\n\t\t}\n\t\t//TWO SIDES\n\t\tif ( kx > x && kz < 0 ) {\n\t\t\tsum += a2+a5;\n\t\t}\n\n\t\t\n\t\t//one SIDE\n\t\tif ( (kx >= 0 && kx <= x) && kz < 0 ) {\n\t\t\tsum += a2;\n\t\t}\n\t\t//one SIDES\n\t\tif ( (kx >= 0 && kx <= x) && kz > z ) {\n\t\t\tsum += a3;\n\t\t}\n\t\t//one SIDES\n\t\tif ( kx > x && (kz >= 0 && kz <= z) ) {\n\t\t\tsum += a5;\n\t\t}\n\t\t//TWO SIDES\n\t\tif ( kx > 0 && (kz >= 0 && kz <= z) ) {\n\t\t\tsum += a4;\n\t\t}\n\t\t\n\t\tSystem.out.println(sum);\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66d26dca4bd6beaf729eb8620afa5b11", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\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[] p = sc.nextIntArray(3);\n int[] b = sc.nextIntArray(3);\n int[] a = sc.nextIntArray(6);\n int ans = 0;\n if (p[0] < 0 && between(p[1], 0, b[1])) ans += a[4];\n if (p[1] < 0 && between(p[2], 0, b[2])) ans += a[0];\n if (p[2] < 0 && between(p[1], 0, b[1])) ans += a[2];\n if (p[0] >= b[0]) ans += a[5];\n if (p[1] >= b[1]) ans += a[1];\n if (p[2] >= b[2]) ans += a[3];\n\n out.println(ans);\n out.flush();\n out.close();\n }\n\n static boolean between(int x, int x2, int x3) {\n return x >= x2 && x <= x3;\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 public Scanner(String s) throws FileNotFoundException {\n\n br = new BufferedReader(new FileReader(new File(s)));\n }\n\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public char nextChar() throws IOException {\n return next().charAt(0);\n }\n\n public Long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n\n public int[] nextIntArray(int n) throws IOException {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public long[] nextLongArray(int n) throws IOException {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n\n\n public Integer[] nextIntegerArray(int n) throws IOException {\n Integer[] a = new Integer[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public double[] nextDoubleArray(int n) throws IOException {\n double[] ans = new double[n];\n for (int i = 0; i < n; i++)\n ans[i] = nextDouble();\n return ans;\n }\n\n public short nextShort() throws IOException {\n return Short.parseShort(next());\n }\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce27536ccdc37045574343f385f5447b", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class MagicBox {\n \n \n \n /************************ SOLUTION STARTS HERE ************************/\n \n static final double EPS = 1e-9;\n static class Plane {\n double pt[];\n int fixed; // This coordinate is constant for this particular plane\n double boundry[];\n Plane(double p[] , double b[] , int f) {\n pt = p;\n boundry = b;\n fixed = f;\n }\n boolean parallel(double line[][]) {\n return line[0][fixed] == 0;\n }\n boolean intersect(double line[][]) { // line[0] = direction vector line[1] = point in line\n double lambda = (double)(boundry[fixed] - line[1][fixed]) / line[0][fixed]; \n double intersect[] = new double[3];\n for(int i = 0; i < 3; i++)\n intersect[i] = lambda * line[0][i] + line[1][i];\n \n boolean flag = true;\n // System.out.println(\"intersection \" + Arrays.toString(intersect));\n \n for(int i = 0; i < 3; i++) {\n if(i == fixed)\n flag &= intersect[i] == boundry[fixed];\n else\n flag &= intersect[i] >= 0.0 && intersect[i] <= boundry[i];\n }\n \n return flag;\n }\n \n double distSq(double line[][]) {\n double lambda = (double)(boundry[fixed] - line[1][fixed]) / line[0][fixed]; \n double intersect[] = new double[3];\n double dSq = 0;\n for(int i = 0; i < 3; i++) {\n intersect[i] = lambda * line[0][i] + line[1][i];\n dSq += Math.pow(intersect[i] - line[1][i], 2);\n }\n \n return dSq;\n }\n \n }\n \n private static void solve() {\n \n double curr[] = new double[3];\n for(int i = 0; i < 3; i++) curr[i] = nextDouble();\n \n double box[] = new double[3];\n for(int i = 0; i < 3; i++) box[i] = nextDouble();\n \n int A[] = nextIntArray(6);\n int perm[] = {1 ,2 ,0};\n int score = 0;\n \n Plane planes[] = new Plane[6];\n for(int i = 0; i < 6; i++) {\n double pt[] = new double[3];\n double b[] = new double[3];\n for(int j = 0; j < 3; j++) {\n if(j != perm[i / 2]) {\n pt[j] = box[j] / 2.0;\n b[j] = box[j];\n }\n else if(i % 2 == 1)\n pt[j] = b[j] = box[j];\n }\n planes[i] = new Plane(pt, b, perm[i / 2]);\n }\n \n double payload[][] = new double[2][];\n \n for(int i = 0; i < 6; i++) {\n boolean flag = true;\n double dir[] = new double[3];\n for(int j = 0; j < 3; j++)\n dir[j] = curr[j] - planes[i].pt[j];\n \n payload[0] = dir;\n payload[1] = curr;\n if(!planes[i].parallel(payload)) {\n double thresh = planes[i].distSq(payload);\n for(int j = 0; j < 6; j++)\n if(i != j && !planes[j].parallel(payload) && planes[j].intersect(payload)) \n flag &= planes[j].distSq(payload) >= thresh;\n \n score += flag ? A[i] : 0;\n }\n }\n \n println(score);\n }\n \n \n \n /************************ SOLUTION ENDS HERE ************************/\n \n \n \n \n \n /************************ TEMPLATE STARTS HERE **********************/\n \n public static void main(String[] args) throws IOException {\n reader = new BufferedReader(new InputStreamReader(System.in));\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);\n st = null;\n solve();\n reader.close();\n writer.close();\n }\n \n static BufferedReader reader;\n static PrintWriter writer;\n static StringTokenizer st;\n \n static String next()\n {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;} \n st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}\n static String nextLine() {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;} \n static int nextInt() {return Integer.parseInt(next());}\n static long nextLong() {return Long.parseLong(next());} \n static double nextDouble(){return Double.parseDouble(next());}\n static char nextChar() {return next().charAt(0);}\n static int[] nextIntArray(int n) {int[] a= new int[n]; int i=0;while(i frog = new ArrayList();\n do {\n frog.add(current);\n current = (x1 * current + y1) % m;\n if (current == a1) {\n flag1 = true;\n }\n\n } while (current != start);\n\n start = h2; current = h2;\n boolean flag2 = false;\n ArrayList flower = new ArrayList();\n do {\n flower.add(current);\n current = (x2 * current + y2) % m;\n if (current == a2) {\n flag2 = true;\n }\n\n } while (current != start);\n\n int l1 = frog.size(), l2 = flower.size();\n if (l1 == 1 || l2 == 1 || !flag1 || !flag2) {\n System.out.println(-1);\n return;\n }\n\n int seconds = 0;\n for (int i = 0; i < l1; i++) {\n if (frog.get(i) == a1) {\n break;\n }\n seconds++;\n }\n\n int position = seconds % l2;\n current = flower.get(position);\n boolean[] visited = new boolean[m];\n while (!visited[current]) {\n if (current == a2) {\n System.out.println(seconds);\n return;\n }\n visited[current] = true;\n\n seconds += l1;\n position += l1;\n position %= l2;\n current = flower.get(position);\n }\n\n System.out.println(-1);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e90be59d4d737571070dfa60597f5d2", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class Codeforces548C {\n\tpublic static int newHeight(int x1, int y1, int m, int oldH)\n\t{\n\t\tlong result = ((long) x1)*oldH + y1;\n\t\treturn (int) (result%m);\n\t}\n\tpublic static int numStepsToGetTo(int x1, int y1, int m, int start, int end)\n\t{\n\t\tint steps = 0;\n\t\tint initial = start;\n\t\tboolean[] visited = new boolean[m];\n\t\twhile(initial != end && !visited[initial])\n\t\t{\n\t\t\tsteps++;\n\t\t\tvisited[initial] = true;\n\t\t\tinitial = newHeight(x1, y1, m, initial);\n\t\t}\n\t\tif(initial != end)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn steps;\n\t}\n\tpublic static void main(String[] args) {\n\t\ttry\n\t\t{\n\t\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tint m = Integer.parseInt(f.readLine());\n\t\t\tStringTokenizer st = new StringTokenizer(f.readLine());\n\t\t\tint h1 = Integer.parseInt(st.nextToken());\n\t\t\tint a1 = Integer.parseInt(st.nextToken());\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tint x1 = Integer.parseInt(st.nextToken());\n\t\t\tint y1 = Integer.parseInt(st.nextToken());\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tint h2 = Integer.parseInt(st.nextToken());\n\t\t\tint a2 = Integer.parseInt(st.nextToken());\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tint x2 = Integer.parseInt(st.nextToken());\n\t\t\tint y2 = Integer.parseInt(st.nextToken());\n\t\t\tf.close();\n\t\t\tint h1ToA1 = numStepsToGetTo(x1, y1, m, h1, a1);\n\t\t\tint h2ToA2 = numStepsToGetTo(x2, y2, m, h2, a2);\n\t\t\tif(h1ToA1 == -1 || h2ToA2 == -1)\n\t\t\t\tSystem.out.println(-1);\n\t\t\telse\n\t\t\t{\n\t\t\t\t if((h1ToA1 == h2ToA2) && (h1ToA1 != 0))\n\t\t\t\t\tSystem.out.println(h1ToA1);\n\t\t\t\t\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint period1 = 1 + numStepsToGetTo(x1, y1, m, newHeight(x1, y1, m, a1), (int) a1);\n\t\t\t\t\tint period2 = 1 + numStepsToGetTo(x2, y2, m, newHeight(x2, y2, m, a2), (int) a2);\n\t\t\t\t\tlong result = h1ToA1;\n\t\t\t\t\tboolean found = false;\n\t\t\t\t\tfor(int i = 0; i < period2; i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(result%period2 == h2ToA2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult += period1;\n\t\t\t\t\t}\n\t\t\t\t\tif(found)\n\t\t\t\t\t\tSystem.out.println(result);\n\t\t\t\t\telse\n\t\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t//}\t\n\t\t\t}\n\t\t}\n\t\tcatch(IOException e)\n\t\t{\n\t\t\tSystem.out.println(e);\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f60bac6278286a448dd1447a2d30153b", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "//package codeforces;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class MikeAndFrog {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scanner = new Scanner(System.in);\n\n\t\tlong m = scanner.nextLong();\n\n\t\tlong h1 = scanner.nextLong();\n\t\tlong a1 = scanner.nextLong();\n\t\tlong x1 = scanner.nextLong();\n\t\tlong y1 = scanner.nextLong();\n\n\t\tlong h2 = scanner.nextLong();\n\t\tlong a2 = scanner.nextLong();\n\t\tlong x2 = scanner.nextLong();\n\t\tlong y2 = scanner.nextLong();\n\n\t\tArrayList list1 = new ArrayList();\n\t\tArrayList list2 = new ArrayList();\n\n\t\tfor (long i = 1; i <= 3 * m; ++i) {\n\n\t\t\th1 = (x1 * h1 + y1) % m;\n\t\t\th2 = (x2 * h2 + y2) % m;\n\n\t\t\tif (h1 == a1)\n\t\t\t\tlist1.add(i);\n\n\t\t\tif (h2 == a2)\n\t\t\t\tlist2.add(i);\n\n\t\t\tif (list1.size() >= 2 && list2.size() >= 2)\n\t\t\t\tbreak;\n\n\t\t}\n\n\t\tif (list1.isEmpty() || list2.isEmpty()) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\n\t\tlong n1 = list1.get(0);\n\t\tlong n2 = list2.get(0);\n\n\t\tif (n1 == n2) {\n\t\t\tSystem.out.println(n1);\n\t\t\treturn;\n\t\t}\n\n\t\tif (list1.size() == 1 && list2.size() == 1) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\n\t\tif (list1.size() == 1)\n\t\t\tif ((n1 - n2) % (list2.get(1) - list2.get(0)) == 0) {\n\t\t\t\tSystem.out.println(n1);\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\tif (list2.size() == 1)\n//\t\t\tif ((n2 - n1) % (list1.get(1) - list1.get(0)) == 0) {\n//\t\t\t\tSystem.out.println(n2);\n//\t\t\t\treturn;\n//\t\t\t} else {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t//}\n\n\t\tlong l1 = list1.get(1) - list1.get(0);\n\t\tlong l2 = list2.get(1) - list2.get(0);\n\n\t\tfor (long i = 0; i < 5000000; ++i) {\n\t\t\tif (n1 == n2) {\n\t\t\t\tSystem.out.println(n1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (n2 < n1)\n\t\t\t\tn2 += l2;\n\t\t\telse\n\t\t\t\tn1 += l1;\n\n\t\t}\n\t\tSystem.out.println(-1);\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6242e53d0825e359b95263b0e02e7fa7", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "//package codeforces;\n\nimport java.math.BigLongeger;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class MikeAndFrog {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scanner = new Scanner(System.in);\n\n\t\tlong m = scanner.nextLong();\n\n\t\tlong h1 = scanner.nextLong();\n\t\tlong a1 = scanner.nextLong();\n\t\tlong x1 = scanner.nextLong();\n\t\tlong y1 = scanner.nextLong();\n\n\t\tlong h2 = scanner.nextLong();\n\t\tlong a2 = scanner.nextLong();\n\t\tlong x2 = scanner.nextLong();\n\t\tlong y2 = scanner.nextLong();\n\n\t\tlong res1 = h1, res2 = h2;\n\t\tlong n = 1;\n\t\tlong pw = 0;\n\n\t\tHashSet set= new HashSet();\n\t\t\t\t\n\t\twhile (true) {\n\n\t\t\tpw = (long) Math.pow(x1, n);\n\n\t\t\tif (x1 == 1)\n\t\t\t\tres1 = (pw * res1 + y1 * n) % m;\n\t\t\telse\n\t\t\t\tres1 = (pw * res1 + y1 * ((1 - pw) / (1 - x1))) % m;\n\n\t\t\t\n\t\t\tpw = (long) Math.pow(x2, n);\n\t\t\tif (x2 == 1)\n\t\t\t\tres2 = (pw * res2 + y2 * n) % m;\n\t\t\telse\n\t\t\t\tres2 = (pw * res2 + y2 * ((1 - pw) / (1 - x2))) % m;\n\n\t\t\tif (res1 == a1 && res2 == a2) {\n\t\t\t\tSystem.out.println(n+1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tif (set.contains(res1+\"\"+res2)){\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse\n\t\t\t\tset.add(res1+\"\"+res2);\n\t\t\t\n\t\t\tn++;\n\n\t\t}\n\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1b81950c10652732e119a8d97278407f", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Test {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\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\n\tstatic 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\tpublic static void main(String[] args) throws IOException {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tif (!oj) {\n\t\t\tFile file = new File(\"inn.txt\");\n\t\t\tif (file.exists() && file.canRead()) {\n\t\t\t\treader = new BufferedReader(new InputStreamReader(\n\t\t\t\t\t\tnew FileInputStream(file)));\n\t\t\t}\n\t\t}\n\t\ttokenizer = null;\n\t\twriter = new PrintWriter(System.out);\n\t\tbanana();\n\t\treader.close();\n\t\twriter.close();\n\t}\n\n\tstatic boolean check(int n, int x, int y, int[][] coord) {\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (x >= coord[0][i] && x <= coord[2][i] && y >= coord[1][i]\n\t\t\t\t\t&& y <= coord[3][i]) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate static void banana() throws IOException {\n\t\tint n = nextInt();\n\t\tint[][] coord = new int[4][n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int t = 0; t < 4; t++) {\n\t\t\t\tcoord[t][i] = nextInt();\n\t\t\t}\n\t\t}\n\n\t\tint minx = 1000000;\n\t\tint miny = 1000000;\n\t\tint maxx = -1;\n\t\tint maxy = -1;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (coord[0][i] < minx)\n\t\t\t\tminx = coord[0][i];\n\t\t\tif (coord[2][i] > maxx)\n\t\t\t\tmaxx = coord[2][i];\n\t\t\tif (coord[1][i] < miny)\n\t\t\t\tminy = coord[1][i];\n\t\t\tif (coord[3][i] > maxy)\n\t\t\t\tmaxy = coord[3][i];\n\t\t}\n\n\t\tif (maxx - minx != maxy - miny) {\n\t\t\twriter.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\n\t\tint[][] newcoord = new int[2][2 * n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tnewcoord[0][i] = coord[0][i];\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tnewcoord[0][n + i] = coord[2][i];\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tnewcoord[1][i] = coord[1][i];\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tnewcoord[1][n + i] = coord[3][i];\n\t\t}\n\n\t\tfor (int t = 0; t < 2; t++) {\n\t\t\tArrays.sort(newcoord[t]);\n\t\t}\n\n\t\tfor (int t = 0; t < 4; t++) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < 2 * n; j++) {\n\t\t\t\t\tif (coord[t][i] == newcoord[t % 2][j]) {\n\t\t\t\t\t\tcoord[t][i] = 2 * j;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tminx = 1000000;\n\t\tminy = 1000000;\n\t\tmaxx = -1;\n\t\tmaxy = -1;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (coord[0][i] < minx)\n\t\t\t\tminx = coord[0][i];\n\t\t\tif (coord[2][i] > maxx)\n\t\t\t\tmaxx = coord[2][i];\n\t\t\tif (coord[1][i] < miny)\n\t\t\t\tminy = coord[1][i];\n\t\t\tif (coord[3][i] > maxy)\n\t\t\t\tmaxy = coord[3][i];\n\t\t}\n\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tfor (int t = 0; t < 4; t++) {\n//\t\t\t\twriter.print(coord[t][i] + \" \");\n//\t\t\t}\n//\t\t\twriter.println();\n//\t\t}\n\n\t\tfor (int x = minx; x <= maxx; x++) {\n\t\t\tfor (int y = miny; y <= maxy; y++) {\n\t\t\t\t//System.err.println(x + \" \" + y);\n\t\t\t\tif (check(n, x, y, coord) == false) {\n\t\t\t\t\twriter.println(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriter.println(\"YES\");\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c767a05d3a000cbfd733699261fe0a86", "src_uid": "f63fc2d97fd88273241fce206cc217f2", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n/**\n * User: \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n * Date: 13.07.2013\n * Time: 20:48:59\n */\npublic class MemSQL_Round1_A {\n Scanner scanner = new Scanner(System.in);\n BufferedReader buffered = new BufferedReader(new InputStreamReader(System.in));\n StreamTokenizer in = new StreamTokenizer(buffered);\n\n PrintWriter out = new PrintWriter(System.out);\n\n int nextInt() throws Exception {\n in.nextToken();\n return (int) in.nval;\n }\n\n void main() throws Exception {\n int n = nextInt();\n int[] x1 = new int[n];\n int[] y1 = new int[n];\n int[] x2 = new int[n];\n int[] y2 = new int[n];\n for (int i=0; i xmin = new TreeSet();\n TreeSet xmax = new TreeSet();\n Integer ymin = null;\n Integer ymax = null;\n for (int Y=0; Y<32000; Y++) {\n ArrayList X1 = new ArrayList();\n ArrayList X2 = new ArrayList();\n for (int i=0; i= Y) {\n X1.add(x1[i]);\n X2.add(x2[i]);\n }\n }\n\n Collections.sort(X1);\n Collections.sort(X2);\n\n for (int i=1; i= ttl.length) {\n ttl = readLongs();\n txl = 0;\n }\n return ttl[txl++];\n }\n\n long[] readLongs() throws IOException {\n String[] strings = reader.readLine().split(\" \");\n long[] longs = new long[strings.length];\n for(int i = 0; i < longs.length; i++) {\n longs[i] = Long.parseLong(strings[i]);\n }\n return longs;\n }\n\n int[] tt = null;\n int tx = 0;\n int readInt() throws IOException {\n if(tt == null || tx >= tt.length) {\n tt = readInts();\n tx = 0;\n }\n return tt[tx++];\n }\n\n void solve() throws IOException {\n int n = readInt();\n int[] x1 = new int[n];\n int[] x2 = new int[n];\n int[] y1 = new int[n];\n int[] y2 = new int[n];\n for(int i = 0; i < n; i++) {\n x1[i] = readInt();\n y1[i] = readInt();\n x2[i] = readInt();\n y2[i] = readInt();\n }\n for(int i = 1; i < 1 << n; i++) {\n int minx = Integer.MAX_VALUE;\n int miny = Integer.MAX_VALUE;\n int maxx = 0, maxy = 0;\n int s = 0;\n for(int j = 0; j < n; j++) {\n if(((i >> j) & 1) > 0) {\n minx = Math.min(minx, x1[j]);\n maxx = Math.max(maxx, x2[j]);\n miny = Math.min(miny, y1[j]);\n maxy = Math.max(maxy, y2[j]);\n s += (x2[j] - x1[j]) * (y2[j] - y1[j]);\n }\n }\n if(maxx - minx == maxy - miny && (maxy - miny) * (maxx - minx) == s) {\n writer.println(\"YES\");\n writer.flush();\n return;\n }\n }\n writer.println(\"NO\");\n\n writer.flush();\n }\n\n void multiSolve() throws IOException {\n int n = readInts()[0];\n for(int i = 0; i < n; i++) {\n if(i > 0) writer.println();\n solve();\n }\n }\n\n public static void main(String[] args) throws IOException{\n new ProblemA().solve();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "378d4f3c4417f63a0a2a16c8683ddbff", "src_uid": "f63fc2d97fd88273241fce206cc217f2", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main\n\t{\n\t/*\n\t * Simple bitmask code for boolean isset, int set and int clr\n\t */\n\tpublic static boolean isset(int n,int i) //returns 1 if the ith bit (from left) of n is set\n\t\t{\n\t\treturn ((n>>i)&1)==1;\n\t\t}\n\tpublic static void main(String args[]) throws IOException\n\t\t{\n\t\tInputReader in=new InputReader(System.in);\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tint n=in.readInt();\n\t\tRectangle R[]=new Rectangle[n];\n\t\tfor(int i=0;i L=new LinkedList();\n\t\t\tfor(int j=0;j=RT[j].x2&&RT[i].y2>=RT[j].y2)\n\t\t\t\t\tcontinue;\n\t\t\t\telse\n\t\t\t\t\tvalid=false;\n\t\t\t\t}\n\t\t\tif(valid)\n\t\t\t\tupperCornerIndex=i;\n\t\t\t}\n\t\t\n\t\t//bottom left\n\t\tfor(int i=0;i=numChars)\n\t\t\t{\n\t\t\tcurChar=0;\n\t\t\ttry\n\t\t\t\t{\n\t\t\t\tnumChars=stream.read(buf);\n\t\t\t\t} catch (IOException e)\n\t\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\tif(numChars<=0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\treturn buf[curChar++];\n\t\t}\n\n\tpublic int readInt()\n\t\t{\n\t\tint c=read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc=read();\n\t\tint sgn=1;\n\t\tif(c=='-')\n\t\t\t{\n\t\t\tsgn=-1;\n\t\t\tc=read();\n\t\t\t}\n\t\tint res=0;\n\t\tdo\n\t\t\t{\n\t\t\tif(c<'0'||c>'9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres*=10;\n\t\t\tres+=c-'0';\n\t\t\tc=read();\n\t\t\t} while (!isSpaceChar(c));\n\t\treturn res*sgn;\n\t\t}\n\n\tpublic boolean isSpaceChar(int c)\n\t\t{\n\t\tif(filter!=null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t\t}\n\n\tpublic static boolean isWhitespace(int c)\n\t\t{\n\t\treturn c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n\t\t}\n\n\tpublic char readCharacter()\n\t\t{\n\t\tint c=read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc=read();\n\t\treturn (char) c;\n\t\t}\n\n\tpublic interface SpaceCharFilter\n\t\t{\n\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d4f73a2c66df4450a19c53644be9cab", "src_uid": "f63fc2d97fd88273241fce206cc217f2", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tint testCount = Integer.parseInt(in.next());\n\t\tfor (int i = 1; i <= testCount; i++)\n\t\t\tsolver.solve(i, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskE {\n\t\tfinal double eps = 1e-8;\n\t\tfinal long MAX_COORD = (int) 1e6;\n\t\tlong MIN_X;\n\t\tlong MIN_Y;\n\t\tlong MAX_X;\n\t\tlong MAX_Y;\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tint n = in.nextInt() - 1;\n\t\t\tlong x0 = in.nextLong();\n\t\t\tlong y0 = in.nextLong();\n\t\t\tMIN_X = -MAX_COORD - x0;\n\t\t\tMAX_X = +MAX_COORD - x0;\n\t\t\tMIN_Y = -MAX_COORD - y0;\n\t\t\tMAX_Y = +MAX_COORD - y0;\n\t\t\tPointLong[] p = new PointLong[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tlong x = in.nextLong() - x0;\n\t\t\t\tlong y = in.nextLong() - y0;\n\t\t\t\tp[i] = new PointLong(x, y);\n\t\t\t}\n\t\t\tArrays.sort(p, (a, b) -> {\n\t\t\t\tboolean au = a.y > 0 || a.y == 0 && a.x > 0;\n\t\t\t\tboolean bu = b.y > 0 || b.y == 0 && b.x > 0;\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\treturn -Long.signum(cross(a, b));\n\t\t\t});\n\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tj = Math.max(j, i + 1);\n\t\t\t\t\twhile (cross(p[i], p[j % n]) > 0) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != j % n && cross(p[i], p[j % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != (i + 1) % n && cross(p[i], p[(i + 1) % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tList lines = new ArrayList<>();\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tint best = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (best >= 0 && cross(p[i], p[best]) <= 0) {\n\t\t\t\t\t\tbest = -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (i == j) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tif (best < 0 || cross(p[best].sub(p[i]), p[j].sub(p[i])) > 0) {\n\t\t\t\t\t\t\tbest = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) < 0) {\n\t\t\t\t\t\t--j;\n\t\t\t\t\t\tif (j < 0) j = n - 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (best >= 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[best].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t++j;\n\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\tif (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\n//\t\tList lines = new ArrayList<>();\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tfor (int j = 0; j < n; j++) {\n//\t\t\t\tif (cross(p[i], p[j]) > 0) {\n//\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\n\t\t\tout.printf(\"%.15f\\n\", area(intersectSemiplanes(lines.toArray(new Line[0]))));\n\t\t}\n\n\t\tprivate double area(Point[] p) {\n\t\t\tif (p == null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tint j = (i + 1) % p.length;\n\t\t\t\tres += (p[j].x - p[i].x) * (p[i].y + p[j].y);\n\t\t\t}\n\t\t\treturn 0.5 * Math.abs(res);\n\t\t}\n\n\t\tprivate int compare(double a, double b) {\n\t\t\tif (Math.abs(a - b) < eps) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn Double.compare(a, b);\n\t\t}\n\n\t\tprivate int sign(double x) {\n\t\t\treturn compare(x, 0);\n\t\t}\n\n\t\tprivate double side(Point p, Line L) {\n\t\t\treturn compare(p.x * L.a + p.y * L.b + L.c, 0);\n\t\t}\n\n\t\tprivate Point intersect(Line L1, Line L2) {\n\t\t\tdouble det = L1.a * L2.b - L2.a * L1.b;\n\t\t\tif (compare(det, 0) == 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tdouble x = -(L1.c * L2.b - L2.c * L1.b) / det;\n\t\t\tdouble y = -(L1.a * L2.c - L2.a * L1.c) / det;\n\t\t\treturn new Point(x, y);\n\t\t}\n\n\t\tprivate Point[] intersectSemiplanes(Line[] input) {\n\t\t\tList correctedInput = new ArrayList<>();\n\t\t\tfor (Line L : input) {\n\t\t\t\tcorrectedInput.add(L);\n\t\t\t}\n\t\t\tPoint[] corners = new Point[4];\n\t\t\tcorners[0] = new Point(MIN_X, MIN_Y);\n\t\t\tcorners[1] = new Point(MAX_X, MIN_Y);\n\t\t\tcorners[2] = new Point(MAX_X, MAX_Y);\n\t\t\tcorners[3] = new Point(MIN_X, MAX_Y);\n\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\tcorrectedInput.add(new Line(corners[i], corners[(i + 1) % 4]));\n\t\t\t}\n\n\t\t\tCollections.sort(correctedInput, (L1, L2) -> {\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tboolean au = ay > 0 || (Math.abs(ay) < eps && ax > 0);\n\t\t\t\tboolean bu = by > 0 || (Math.abs(by) < eps && bx > 0);\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (s != 0) {\n\t\t\t\t\treturn s;\n\t\t\t\t}\n\t\t\t\tPoint test = L1.anyPoint();\n\t\t\t\treturn side(test, L2) > 0 ? -1 : 1;\n\t\t\t});\n\n\t\t\tfor (int i = correctedInput.size() - 1; i > 0; i--) {\n\t\t\t\tLine L1 = correctedInput.get(i);\n\t\t\t\tLine L2 = correctedInput.get(i - 1);\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tint d = sign(ax * bx + ay * by);\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (d >= 0 && s == 0) {\n\t\t\t\t\tcorrectedInput.remove(i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tLine[] borders = correctedInput.toArray(new Line[0]);\n\t\t\tList list = new ArrayList<>();\n\t\t\tlist.add(borders[0]);\n\t\t\tlist.add(intersect(borders[0], borders[1]));\n\t\t\tlist.add(borders[1]);\n\n\t\t\tfor (int i = 2; i < 2 * borders.length; i++) {\n\t\t\t\tLine L = borders[i % borders.length];\n\t\t\t\twhile (list.size() >= 2) {\n\t\t\t\t\tObject o1 = list.get(list.size() - 2);\n\t\t\t\t\tObject o2 = list.get(list.size() - 1);\n\t\t\t\t\tif ((o1 instanceof Point) && (o2 instanceof Line)) {\n\t\t\t\t\t\tPoint p = (Point) o1;\n\t\t\t\t\t\tif (side(p, L) > 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject obj = list.get(list.size() - 1);\n\t\t\t\tif (obj instanceof Line) {\n\t\t\t\t\tLine v = (Line) obj;\n\t\t\t\t\tif (sign(v.a * L.b - v.b * L.a) <= 0) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tPoint p = intersect(v, L);\n\t\t\t\t\tlist.add(p);\n\t\t\t\t\tlist.add(L);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tMap where = new HashMap<>();\n\t\t\tList allLines = new ArrayList<>();\n\t\t\tList res = new ArrayList<>();\n\t\t\tfor (int i = 0; i < list.size(); i += 2) {\n\t\t\t\tLine L = (Line) list.get(i);\n\t\t\t\tallLines.add(L);\n\t\t\t\tif (where.containsKey(L)) {\n\t\t\t\t\tfor (int j = where.get(L); j < allLines.size() - 1; j++) {\n\t\t\t\t\t\tres.add(intersect(allLines.get(j), allLines.get(j + 1)));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhere.put(L, i / 2);\n\t\t\t}\n\t\t\treturn res.toArray(new Point[0]);\n\t\t}\n\n\t\tprivate long cross(PointLong a, PointLong b) {\n\t\t\treturn a.x * b.y - a.y * b.x;\n\t\t}\n\n\t\tclass Point {\n\t\t\tdouble x;\n\t\t\tdouble y;\n\n\t\t\tPoint(double x, double y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t\t//return String.format(\"(%.4f %.4f)\", x, y);\n\t\t\t}\n\n\t\t}\n\n\t\tclass Line {\n\t\t\tdouble a;\n\t\t\tdouble b;\n\t\t\tdouble c;\n\t\t\tPoint anyPoint;\n\n\t\t\tLine(double a, double b, double c) {\n\t\t\t\tthis.a = a;\n\t\t\t\tthis.b = b;\n\t\t\t\tthis.c = c;\n\t\t\t}\n\n\t\t\tLine(Point p1, Point p2) {\n\t\t\t\ta = p1.y - p2.y;\n\t\t\t\tb = p2.x - p1.x;\n\t\t\t\tc = -a * p1.x - b * p1.y;\n\t\t\t\tdouble len = Math.sqrt(a * a + b * b);\n\t\t\t\ta /= len;\n\t\t\t\tb /= len;\n\t\t\t\tc /= len;\n\t\t\t\tanyPoint = p1;\n\t\t\t}\n\n\t\t\tPoint anyPoint() {\n\t\t\t\tif (anyPoint != null) {\n\t\t\t\t\treturn anyPoint;\n\t\t\t\t}\n\t\t\t\tif (Math.abs(b) < eps) {\n\t\t\t\t\tif (Math.abs(a) < eps) {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t\treturn new Point(-c / a, 0);\n\t\t\t\t}\n\t\t\t\treturn new Point(0, -c / b);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn a + \" \" + b + \" \" + c;\n\t\t\t}\n\n\t\t}\n\n\t\tclass PointLong {\n\t\t\tlong x;\n\t\t\tlong y;\n\n\t\t\tPointLong(long x, long y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\t\t\tPointLong sub(PointLong o) {\n\t\t\t\treturn new PointLong(x - o.x, y - o.y);\n\t\t\t}\n\n\t\t\tPoint toDoublePoint() {\n\t\t\t\treturn new Point(x, y);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(in.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "471e4d8eccd5d33ee4df0087cb28f496", "src_uid": "6afe0718ad89e3fd51a456e0144c538d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tint testCount = Integer.parseInt(in.next());\n\t\tfor (int i = 1; i <= testCount; i++)\n\t\t\tsolver.solve(i, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskE {\n\t\tfinal double eps = 1e-15;\n\t\tfinal long MAX_COORD = (int) 1e6;\n\t\tlong MIN_X;\n\t\tlong MIN_Y;\n\t\tlong MAX_X;\n\t\tlong MAX_Y;\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tint n = in.nextInt() - 1;\n\t\t\tlong x0 = in.nextLong();\n\t\t\tlong y0 = in.nextLong();\n\t\t\tMIN_X = -MAX_COORD - x0;\n\t\t\tMAX_X = +MAX_COORD - x0;\n\t\t\tMIN_Y = -MAX_COORD - y0;\n\t\t\tMAX_Y = +MAX_COORD - y0;\n\t\t\tPointLong[] p = new PointLong[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tlong x = in.nextLong() - x0;\n\t\t\t\tlong y = in.nextLong() - y0;\n\t\t\t\tp[i] = new PointLong(x, y);\n\t\t\t}\n\t\t\tArrays.sort(p, (a, b) -> {\n\t\t\t\tboolean au = a.y > 0 || a.y == 0 && a.x > 0;\n\t\t\t\tboolean bu = b.y > 0 || b.y == 0 && b.x > 0;\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\treturn -Long.signum(cross(a, b));\n\t\t\t});\n\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tj = Math.max(j, i + 1);\n\t\t\t\t\twhile (cross(p[i], p[j % n]) > 0) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != j % n && cross(p[i], p[j % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != (i + 1) % n && cross(p[i], p[(i + 1) % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tList lines = new ArrayList<>();\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tint best = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (best >= 0 && cross(p[i], p[best]) <= 0) {\n\t\t\t\t\t\tbest = -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (i == j) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tif (best < 0 || cross(p[best].sub(p[i]), p[j].sub(p[i])) > 0) {\n\t\t\t\t\t\t\tbest = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) < 0) {\n\t\t\t\t\t\t--j;\n\t\t\t\t\t\tif (j < 0) j = n - 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (best >= 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[best].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t++j;\n\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\tif (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\n//\t\tList lines = new ArrayList<>();\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tfor (int j = 0; j < n; j++) {\n//\t\t\t\tif (cross(p[i], p[j]) > 0) {\n//\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\n\t\t\tout.printf(\"%.15f\\n\", area(intersectSemiplanes(lines.toArray(new Line[0]))));\n\t\t}\n\n\t\tprivate double area(Point[] p) {\n\t\t\tif (p == null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tint j = (i + 1) % p.length;\n\t\t\t\tres += (p[j].x - p[i].x) * (p[i].y + p[j].y);\n\t\t\t}\n\t\t\treturn 0.5 * Math.abs(res);\n\t\t}\n\n\t\tprivate int compare(double a, double b) {\n\t\t\tif (Math.abs(a - b) < eps) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn Double.compare(a, b);\n\t\t}\n\n\t\tprivate int sign(double x) {\n\t\t\treturn compare(x, 0);\n\t\t}\n\n\t\tprivate double side(Point p, Line L) {\n\t\t\treturn compare(p.x * L.a + p.y * L.b + L.c, 0);\n\t\t}\n\n\t\tprivate Point intersect(Line L1, Line L2) {\n\t\t\tdouble det = L1.a * L2.b - L2.a * L1.b;\n\t\t\tif (compare(det, 0) == 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tdouble x = -(L1.c * L2.b - L2.c * L1.b) / det;\n\t\t\tdouble y = -(L1.a * L2.c - L2.a * L1.c) / det;\n\t\t\treturn new Point(x, y);\n\t\t}\n\n\t\tprivate Point[] intersectSemiplanes(Line[] input) {\n\t\t\tList correctedInput = new ArrayList<>();\n\t\t\tfor (Line L : input) {\n\t\t\t\tcorrectedInput.add(L);\n\t\t\t}\n\t\t\tPoint[] corners = new Point[4];\n\t\t\tcorners[0] = new Point(MIN_X, MIN_Y);\n\t\t\tcorners[1] = new Point(MAX_X, MIN_Y);\n\t\t\tcorners[2] = new Point(MAX_X, MAX_Y);\n\t\t\tcorners[3] = new Point(MIN_X, MAX_Y);\n\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\tcorrectedInput.add(new Line(corners[i], corners[(i + 1) % 4]));\n\t\t\t}\n\n\t\t\tCollections.sort(correctedInput, (L1, L2) -> {\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tboolean au = ay > 0 || (Math.abs(ay) < eps && ax > 0);\n\t\t\t\tboolean bu = by > 0 || (Math.abs(by) < eps && bx > 0);\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (s != 0) {\n\t\t\t\t\treturn s;\n\t\t\t\t}\n\t\t\t\tPoint test = L1.anyPoint();\n\t\t\t\treturn side(test, L2) > 0 ? -1 : 1;\n\t\t\t});\n\n\t\t\tfor (int i = correctedInput.size() - 1; i > 0; i--) {\n\t\t\t\tLine L1 = correctedInput.get(i);\n\t\t\t\tLine L2 = correctedInput.get(i - 1);\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tint d = sign(ax * bx + ay * by);\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (d >= 0 && s == 0) {\n\t\t\t\t\tcorrectedInput.remove(i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tLine[] borders = correctedInput.toArray(new Line[0]);\n\t\t\tList list = new ArrayList<>();\n\t\t\tlist.add(borders[0]);\n\t\t\tlist.add(intersect(borders[0], borders[1]));\n\t\t\tlist.add(borders[1]);\n\n\t\t\tfor (int i = 2; i < 2 * borders.length; i++) {\n\t\t\t\tLine L = borders[i % borders.length];\n\t\t\t\twhile (list.size() >= 2) {\n\t\t\t\t\tObject o1 = list.get(list.size() - 2);\n\t\t\t\t\tObject o2 = list.get(list.size() - 1);\n\t\t\t\t\tif ((o1 instanceof Point) && (o2 instanceof Line)) {\n\t\t\t\t\t\tPoint p = (Point) o1;\n\t\t\t\t\t\tif (side(p, L) > 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject obj = list.get(list.size() - 1);\n\t\t\t\tif (obj instanceof Line) {\n\t\t\t\t\tLine v = (Line) obj;\n\t\t\t\t\tif (sign(v.a * L.b - v.b * L.a) <= 0) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tPoint p = intersect(v, L);\n\t\t\t\t\tlist.add(p);\n\t\t\t\t\tlist.add(L);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tMap where = new HashMap<>();\n\t\t\tList allLines = new ArrayList<>();\n\t\t\tList res = new ArrayList<>();\n\t\t\tfor (int i = 0; i < list.size(); i += 2) {\n\t\t\t\tLine L = (Line) list.get(i);\n\t\t\t\tallLines.add(L);\n\t\t\t\tif (where.containsKey(L)) {\n\t\t\t\t\tfor (int j = where.get(L); j < allLines.size() - 1; j++) {\n\t\t\t\t\t\tres.add(intersect(allLines.get(j), allLines.get(j + 1)));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhere.put(L, i / 2);\n\t\t\t}\n\t\t\treturn res.toArray(new Point[0]);\n\t\t}\n\n\t\tprivate long cross(PointLong a, PointLong b) {\n\t\t\treturn a.x * b.y - a.y * b.x;\n\t\t}\n\n\t\tclass Point {\n\t\t\tdouble x;\n\t\t\tdouble y;\n\n\t\t\tPoint(double x, double y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t\t//return String.format(\"(%.4f %.4f)\", x, y);\n\t\t\t}\n\n\t\t}\n\n\t\tclass Line {\n\t\t\tdouble a;\n\t\t\tdouble b;\n\t\t\tdouble c;\n\t\t\tPoint anyPoint;\n\n\t\t\tLine(double a, double b, double c) {\n\t\t\t\tthis.a = a;\n\t\t\t\tthis.b = b;\n\t\t\t\tthis.c = c;\n\t\t\t}\n\n\t\t\tLine(Point p1, Point p2) {\n\t\t\t\ta = p1.y - p2.y;\n\t\t\t\tb = p2.x - p1.x;\n\t\t\t\tc = -a * p1.x - b * p1.y;\n\t\t\t\tdouble len = Math.sqrt(a * a + b * b);\n\t\t\t\ta /= len;\n\t\t\t\tb /= len;\n\t\t\t\tc /= len;\n\t\t\t\tanyPoint = p1;\n\t\t\t}\n\n\t\t\tPoint anyPoint() {\n\t\t\t\tif (anyPoint != null) {\n\t\t\t\t\treturn anyPoint;\n\t\t\t\t}\n\t\t\t\tif (Math.abs(b) < eps) {\n\t\t\t\t\tif (Math.abs(a) < eps) {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t\treturn new Point(-c / a, 0);\n\t\t\t\t}\n\t\t\t\treturn new Point(0, -c / b);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn a + \" \" + b + \" \" + c;\n\t\t\t}\n\n\t\t}\n\n\t\tclass PointLong {\n\t\t\tlong x;\n\t\t\tlong y;\n\n\t\t\tPointLong(long x, long y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\t\t\tPointLong sub(PointLong o) {\n\t\t\t\treturn new PointLong(x - o.x, y - o.y);\n\t\t\t}\n\n\t\t\tPoint toDoublePoint() {\n\t\t\t\treturn new Point(x, y);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(in.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f8e1fbb4e192c7b50897f6855fa87b82", "src_uid": "6afe0718ad89e3fd51a456e0144c538d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tint testCount = Integer.parseInt(in.next());\n\t\tfor (int i = 1; i <= testCount; i++)\n\t\t\tsolver.solve(i, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskE {\n\t\tfinal double eps = 1e-15;\n\t\tfinal long MAX_COORD = (int) 1e6;\n\t\tlong MIN_X;\n\t\tlong MIN_Y;\n\t\tlong MAX_X;\n\t\tlong MAX_Y;\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tint n = in.nextInt() - 1;\n\t\t\tlong x0 = in.nextLong();\n\t\t\tlong y0 = in.nextLong();\n\t\t\tMIN_X = -MAX_COORD - x0;\n\t\t\tMAX_X = +MAX_COORD - x0;\n\t\t\tMIN_Y = -MAX_COORD - y0;\n\t\t\tMAX_Y = +MAX_COORD - y0;\n\t\t\tPointLong[] p = new PointLong[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tlong x = in.nextLong() - x0;\n\t\t\t\tlong y = in.nextLong() - y0;\n\t\t\t\tp[i] = new PointLong(x, y);\n\t\t\t}\n\t\t\tArrays.sort(p, (a, b) -> {\n\t\t\t\tboolean au = a.y > 0 || a.y == 0 && a.x > 0;\n\t\t\t\tboolean bu = b.y > 0 || b.y == 0 && b.x > 0;\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\treturn -Long.signum(cross(a, b));\n\t\t\t});\n\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tj = Math.max(j, i + 1);\n\t\t\t\t\twhile (cross(p[i], p[j % n]) > 0) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != j % n && cross(p[i], p[j % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != (i + 1) % n && cross(p[i], p[(i + 1) % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tList lines = new ArrayList<>();\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tint best = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (best >= 0 && cross(p[i], p[best]) <= 0) {\n\t\t\t\t\t\tbest = -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (i == j) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tif (best < 0 || cross(p[best].sub(p[i]), p[j].sub(p[i])) > 0) {\n\t\t\t\t\t\t\tbest = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) < 0) {\n\t\t\t\t\t\t--j;\n\t\t\t\t\t\tif (j < 0) j = n - 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (best >= 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[best].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t++j;\n\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\tif (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\n//\t\tList lines = new ArrayList<>();\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tfor (int j = 0; j < n; j++) {\n//\t\t\t\tif (cross(p[i], p[j]) > 0) {\n//\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\n\t\t\tout.printf(\"%.15f\\n\", area(intersectSemiplanes(lines.toArray(new Line[0]))));\n\t\t}\n\n\t\tprivate double area(Point[] p) {\n\t\t\tif (p == null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tint j = (i + 1) % p.length;\n\t\t\t\tres += (p[j].x - p[i].x) * (p[i].y + p[j].y);\n\t\t\t}\n\t\t\treturn 0.5 * Math.abs(res);\n\t\t}\n\n\t\tprivate int compare(double a, double b) {\n\t\t\tif (Math.abs(a - b) < eps) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn Double.compare(a, b);\n\t\t}\n\n\t\tprivate int sign(double x) {\n\t\t\treturn compare(x, 0);\n\t\t}\n\n\t\tprivate double side(Point p, Line L) {\n\t\t\treturn compare(p.x * L.a + p.y * L.b + L.c, 0);\n\t\t}\n\n\t\tprivate Point intersect(Line L1, Line L2) {\n\t\t\tdouble det = L1.a * L2.b - L2.a * L1.b;\n\t\t\tif (compare(det, 0) == 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tdouble x = -(L1.c * L2.b - L2.c * L1.b) / det;\n\t\t\tdouble y = -(L1.a * L2.c - L2.a * L1.c) / det;\n\t\t\treturn new Point(x, y);\n\t\t}\n\n\t\tprivate Point[] intersectSemiplanes(Line[] input) {\n\t\t\tList correctedInput = new ArrayList<>();\n\t\t\tfor (Line L : input) {\n\t\t\t\tcorrectedInput.add(L);\n\t\t\t}\n\t\t\tPoint[] corners = new Point[4];\n\t\t\tcorners[0] = new Point(MIN_X, MIN_Y);\n\t\t\tcorners[1] = new Point(MAX_X, MIN_Y);\n\t\t\tcorners[2] = new Point(MAX_X, MAX_Y);\n\t\t\tcorners[3] = new Point(MIN_X, MAX_Y);\n\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\tcorrectedInput.add(new Line(corners[i], corners[(i + 1) % 4]));\n\t\t\t}\n\n\t\t\tCollections.sort(correctedInput, (L1, L2) -> {\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tboolean au = ay > 0 || (Math.abs(ay) < eps && ax > 0);\n\t\t\t\tboolean bu = by > 0 || (Math.abs(by) < eps && bx > 0);\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (s != 0) {\n\t\t\t\t\treturn s;\n\t\t\t\t}\n\t\t\t\tPoint test = L1.anyPoint();\n\t\t\t\treturn -sign(side(test, L2));\n\t\t\t});\n\n\t\t\tfor (int i = correctedInput.size() - 1; i > 0; i--) {\n\t\t\t\tLine L1 = correctedInput.get(i);\n\t\t\t\tLine L2 = correctedInput.get(i - 1);\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tint d = sign(ax * bx + ay * by);\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (d >= 0 && s == 0) {\n\t\t\t\t\tcorrectedInput.remove(i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tLine[] borders = correctedInput.toArray(new Line[0]);\n\t\t\tList list = new ArrayList<>();\n\t\t\tlist.add(borders[0]);\n\t\t\tlist.add(intersect(borders[0], borders[1]));\n\t\t\tlist.add(borders[1]);\n\n\t\t\tfor (int i = 2; i < 2 * borders.length; i++) {\n\t\t\t\tLine L = borders[i % borders.length];\n\t\t\t\twhile (list.size() >= 2) {\n\t\t\t\t\tObject o1 = list.get(list.size() - 2);\n\t\t\t\t\tObject o2 = list.get(list.size() - 1);\n\t\t\t\t\tif ((o1 instanceof Point) && (o2 instanceof Line)) {\n\t\t\t\t\t\tPoint p = (Point) o1;\n\t\t\t\t\t\tif (side(p, L) > 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject obj = list.get(list.size() - 1);\n\t\t\t\tif (obj instanceof Line) {\n\t\t\t\t\tLine v = (Line) obj;\n\t\t\t\t\tif (sign(v.a * L.b - v.b * L.a) <= 0) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tPoint p = intersect(v, L);\n\t\t\t\t\tlist.add(p);\n\t\t\t\t\tlist.add(L);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tMap where = new HashMap<>();\n\t\t\tList allLines = new ArrayList<>();\n\t\t\tList res = new ArrayList<>();\n\t\t\tfor (int i = 0; i < list.size(); i += 2) {\n\t\t\t\tLine L = (Line) list.get(i);\n\t\t\t\tallLines.add(L);\n\t\t\t\tif (where.containsKey(L)) {\n\t\t\t\t\tfor (int j = where.get(L); j < allLines.size() - 1; j++) {\n\t\t\t\t\t\tres.add(intersect(allLines.get(j), allLines.get(j + 1)));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhere.put(L, i / 2);\n\t\t\t}\n\t\t\treturn res.toArray(new Point[0]);\n\t\t}\n\n\t\tprivate long cross(PointLong a, PointLong b) {\n\t\t\treturn a.x * b.y - a.y * b.x;\n\t\t}\n\n\t\tclass Point {\n\t\t\tdouble x;\n\t\t\tdouble y;\n\n\t\t\tPoint(double x, double y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t\t//return String.format(\"(%.4f %.4f)\", x, y);\n\t\t\t}\n\n\t\t}\n\n\t\tclass Line {\n\t\t\tdouble a;\n\t\t\tdouble b;\n\t\t\tdouble c;\n\t\t\tPoint anyPoint;\n\n\t\t\tLine(double a, double b, double c) {\n\t\t\t\tthis.a = a;\n\t\t\t\tthis.b = b;\n\t\t\t\tthis.c = c;\n\t\t\t}\n\n\t\t\tLine(Point p1, Point p2) {\n\t\t\t\ta = p1.y - p2.y;\n\t\t\t\tb = p2.x - p1.x;\n\t\t\t\tc = -a * p1.x - b * p1.y;\n\t\t\t\tdouble len = Math.sqrt(a * a + b * b);\n\t\t\t\ta /= len;\n\t\t\t\tb /= len;\n\t\t\t\tc /= len;\n\t\t\t\tanyPoint = p1;\n\t\t\t}\n\n\t\t\tPoint anyPoint() {\n\t\t\t\tif (anyPoint != null) {\n\t\t\t\t\treturn anyPoint;\n\t\t\t\t}\n\t\t\t\tif (Math.abs(b) < eps) {\n\t\t\t\t\tif (Math.abs(a) < eps) {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t\treturn new Point(-c / a, 0);\n\t\t\t\t}\n\t\t\t\treturn new Point(0, -c / b);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn a + \" \" + b + \" \" + c;\n\t\t\t}\n\n\t\t}\n\n\t\tclass PointLong {\n\t\t\tlong x;\n\t\t\tlong y;\n\n\t\t\tPointLong(long x, long y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\t\t\tPointLong sub(PointLong o) {\n\t\t\t\treturn new PointLong(x - o.x, y - o.y);\n\t\t\t}\n\n\t\t\tPoint toDoublePoint() {\n\t\t\t\treturn new Point(x, y);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(in.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60a9d2567c531176ded595e2ce63b7f9", "src_uid": "6afe0718ad89e3fd51a456e0144c538d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tint testCount = Integer.parseInt(in.next());\n\t\tfor (int i = 1; i <= testCount; i++)\n\t\t\tsolver.solve(i, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskE {\n\t\tfinal double eps = 1e-12;\n\t\tfinal long MAX_COORD = (int) 1e6;\n\t\tlong MIN_X;\n\t\tlong MIN_Y;\n\t\tlong MAX_X;\n\t\tlong MAX_Y;\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tint n = in.nextInt() - 1;\n\t\t\tlong x0 = in.nextLong();\n\t\t\tlong y0 = in.nextLong();\n\t\t\tMIN_X = -MAX_COORD - x0;\n\t\t\tMAX_X = +MAX_COORD - x0;\n\t\t\tMIN_Y = -MAX_COORD - y0;\n\t\t\tMAX_Y = +MAX_COORD - y0;\n\t\t\tPointLong[] p = new PointLong[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tlong x = in.nextLong() - x0;\n\t\t\t\tlong y = in.nextLong() - y0;\n\t\t\t\tp[i] = new PointLong(x, y);\n\t\t\t}\n\t\t\tArrays.sort(p, (a, b) -> {\n\t\t\t\tboolean au = a.y > 0 || a.y == 0 && a.x > 0;\n\t\t\t\tboolean bu = b.y > 0 || b.y == 0 && b.x > 0;\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\treturn -Long.signum(cross(a, b));\n\t\t\t});\n\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tj = Math.max(j, i + 1);\n\t\t\t\t\twhile (cross(p[i], p[j % n]) > 0) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != j % n && cross(p[i], p[j % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != (i + 1) % n && cross(p[i], p[(i + 1) % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tList lines = new ArrayList<>();\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tint best = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (best >= 0 && cross(p[i], p[best]) <= 0) {\n\t\t\t\t\t\tbest = -1;\n\t\t\t\t\t}\n\t\t\t\t\tj = Math.max(j, i + 1);\n\t\t\t\t\twhile (cross(p[i], p[j % n]) > 0) {\n\t\t\t\t\t\tif (best < 0 || cross(p[best].sub(p[i]), p[j % n].sub(p[i])) > 0) {\n\t\t\t\t\t\t\tbest = j % n;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++j;\n\t\t\t\t\t}\n\t\t\t\t\tif (best >= 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[best].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t++j;\n\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\tif (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tout.printf(\"%.15f\\n\", area(intersectSemiplanes(lines.toArray(new Line[0]))));\n\t\t}\n\n\t\tprivate double area(Point[] p) {\n\t\t\tif (p == null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tint j = i + 1;\n\t\t\t\tif (j == p.length) {\n\t\t\t\t\tj = 0;\n\t\t\t\t}\n\t\t\t\tres += (p[j].x - p[i].x) * (p[i].y + p[j].y);\n\t\t\t}\n\t\t\treturn 0.5 * Math.abs(res);\n\t\t}\n\n\t\tprivate int compare(double a, double b) {\n\t\t\tif (Math.abs(a - b) < eps) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn Double.compare(a, b);\n\t\t}\n\n\t\tprivate int sign(double x) {\n\t\t\treturn compare(x, 0);\n\t\t}\n\n\t\tprivate double side(Point p, Line L) {\n\t\t\treturn compare(p.x * L.a + p.y * L.b + L.c, 0);\n\t\t}\n\n\t\tprivate Point intersect(Line L1, Line L2) {\n\t\t\tdouble det = L1.a * L2.b - L2.a * L1.b;\n\t\t\tif (compare(det, 0) == 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tdouble x = -(L1.c * L2.b - L2.c * L1.b) / det;\n\t\t\tdouble y = -(L1.a * L2.c - L2.a * L1.c) / det;\n\t\t\treturn new Point(x, y);\n\t\t}\n\n\t\tprivate Point[] intersectSemiplanes(Line[] input) {\n\t\t\tList correctedInput = new ArrayList<>();\n\t\t\tfor (Line L : input) {\n\t\t\t\tcorrectedInput.add(L);\n\t\t\t}\n\t\t\tPoint[] corners = new Point[4];\n\t\t\tcorners[0] = new Point(MIN_X, MIN_Y);\n\t\t\tcorners[1] = new Point(MAX_X, MIN_Y);\n\t\t\tcorners[2] = new Point(MAX_X, MAX_Y);\n\t\t\tcorners[3] = new Point(MIN_X, MAX_Y);\n\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\tcorrectedInput.add(new Line(corners[i], corners[(i + 1) % 4]));\n\t\t\t}\n\n\t\t\tCollections.sort(correctedInput, (L1, L2) -> {\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tboolean au = ay > 0 || (ay == 0 && ax > 0);\n\t\t\t\tboolean bu = by > 0 || (by == 0 && bx > 0);\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (s != 0) {\n\t\t\t\t\treturn s;\n\t\t\t\t}\n\t\t\t\treturn -sign(side(L1.p1, L2));\n\t\t\t});\n\n\t\t\t{\n\t\t\t\tboolean[] dead = new boolean[correctedInput.size()];\n\t\t\t\tfor (int i = correctedInput.size() - 1; i > 0; i--) {\n\t\t\t\t\tLine L1 = correctedInput.get(i);\n\t\t\t\t\tLine L2 = correctedInput.get(i - 1);\n\t\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\t\tint d = sign(ax * bx + ay * by);\n\t\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\t\tif (d >= 0 && s == 0) {\n\t\t\t\t\t\tdead[i] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tList list = new ArrayList<>();\n\t\t\t\tfor (int i = 0; i < correctedInput.size(); i++) {\n\t\t\t\t\tif (!dead[i]) {\n\t\t\t\t\t\tlist.add(correctedInput.get(i));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcorrectedInput = list;\n\t\t\t}\n\n\n\t\t\tLine[] borders = correctedInput.toArray(new Line[0]);\n\t\t\tList list = new ArrayList<>();\n\t\t\tlist.add(borders[0]);\n\t\t\tlist.add(intersect(borders[0], borders[1]));\n\t\t\tlist.add(borders[1]);\n\n\t\t\tfor (int i = 2; i < 2 * borders.length; i++) {\n\t\t\t\tLine L = borders[i % borders.length];\n\t\t\t\twhile (list.size() >= 2) {\n\t\t\t\t\tObject o1 = list.get(list.size() - 2);\n\t\t\t\t\tObject o2 = list.get(list.size() - 1);\n\t\t\t\t\tif ((o1 instanceof Point) && (o2 instanceof Line)) {\n\t\t\t\t\t\tPoint p = (Point) o1;\n\t\t\t\t\t\tif (side(p, L) > 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject obj = list.get(list.size() - 1);\n\t\t\t\tif (obj instanceof Line) {\n\t\t\t\t\tLine v = (Line) obj;\n\t\t\t\t\tif (sign(v.a * L.b - v.b * L.a) <= 0) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tPoint p = intersect(v, L);\n\t\t\t\t\tlist.add(p);\n\t\t\t\t\tlist.add(L);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tMap where = new HashMap<>();\n\t\t\tList allLines = new ArrayList<>();\n\t\t\tList res = new ArrayList<>();\n\t\t\tfor (int i = 0; i < list.size(); i += 2) {\n\t\t\t\tLine L = (Line) list.get(i);\n\t\t\t\tallLines.add(L);\n\t\t\t\tif (where.containsKey(L)) {\n\t\t\t\t\tfor (int j = where.get(L); j + 1 < allLines.size(); j++) {\n\t\t\t\t\t\tres.add(intersect(allLines.get(j), allLines.get(j + 1)));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhere.put(L, i / 2);\n\t\t\t}\n\t\t\treturn res.toArray(new Point[0]);\n\t\t}\n\n\t\tprivate long cross(PointLong a, PointLong b) {\n\t\t\treturn a.x * b.y - a.y * b.x;\n\t\t}\n\n\t\tclass Point {\n\t\t\tdouble x;\n\t\t\tdouble y;\n\n\t\t\tPoint(double x, double y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn String.format(\"(%.4f %.4f)\", x, y);\n\t\t\t}\n\n\t\t}\n\n\t\tclass Line {\n\t\t\tdouble a;\n\t\t\tdouble b;\n\t\t\tdouble c;\n\t\t\tPoint p1;\n\t\t\tPoint p2;\n\n\t\t\tLine(Point p1, Point p2) {\n\t\t\t\tthis.p1 = p1;\n\t\t\t\tthis.p2 = p2;\n\t\t\t\ta = p1.y - p2.y;\n\t\t\t\tb = p2.x - p1.x;\n\t\t\t\tc = -a * p1.x - b * p1.y;\n\t\t\t\t// double len = Math.sqrt(a * a + b * b);\n\t\t\t\t// a /= len;\n\t\t\t\t// b /= len;\n\t\t\t\t// c /= len;\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn a + \" \" + b + \" \" + c;\n\t\t\t}\n\n\t\t}\n\n\t\tclass PointLong {\n\t\t\tlong x;\n\t\t\tlong y;\n\n\t\t\tPointLong(long x, long y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\t\t\tPointLong sub(PointLong o) {\n\t\t\t\treturn new PointLong(x - o.x, y - o.y);\n\t\t\t}\n\n\t\t\tPoint toDoublePoint() {\n\t\t\t\treturn new Point(x, y);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(in.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b4ab7dfe390fd0b5b8ffacffa490e746", "src_uid": "6afe0718ad89e3fd51a456e0144c538d", "difficulty": 3300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n static boolean find = false;\n static HashSet set = new HashSet<>();\n public static void main(String[] args) throws Exception {\n PrintWriter out = new PrintWriter(System.out,true);\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(in.readLine());\n String[] mas = new String[n];\n StringTokenizer st = new StringTokenizer(in.readLine());\n for(int i = 0;i < n;i++) mas[i] = st.nextToken();\n func(mas,n-1);\n if(find) {\n out.println(\"YES\");\n }else{\n out.println(\"NO\");\n }\n }\n\n public static void func(String[] mas, int last) {\n String d = Arrays.toString(mas)+last;\n if(set.contains(d)) return;\n set.add(d);\n if(last == 0 || find) find = true;\n if(last > 0 && (mas[last-1].charAt(0) == mas[last].charAt(0) || mas[last-1].charAt(1) == mas[last].charAt(1))) {\n String a = mas[last-1];\n mas[last-1] = mas[last];\n func(mas,last-1);\n mas[last-1] = a;\n }\n if(last > 2 && (mas[last-3].charAt(0) == mas[last].charAt(0) || mas[last-3].charAt(1) == mas[last].charAt(1))) {\n String a = mas[last-3];\n mas[last-3] = mas[last];\n func(mas,last-1);\n mas[last-3] = a;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "754d3c289b0b1125cc1cff34a3fdf8ef", "src_uid": "1805771e194d323edacf2526a1eb6768", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\npublic class Main {\n\t\n\t//ArrayList lis = new ArrayList();\n\t//ArrayList lis = new ArrayList();\n\t//ArrayList lis = new ArrayList();\n//\tstatic long sum=0;\n//\tstatic boolean f=false;\n\t//static String s[],r=\"\";\n//\tstatic int dx[]={1,-1,0,0,1,1,-1,-1};\n // static int dy[]={0,0,1,-1,1,-1,1,-1},n,m,w=0;\n\t//static int dp[][][][],co,r=0;\n\t//throws IOException\n\t//static char c[][];\n\tstatic boolean b=false,me[][][][][];\n\t\npublic static void main(String[] args) {\n //googlein.txt C-small-attempt0.in\n//\tScanner sc =new Scanner(new File(\"file.txt\"));\n\t Scanner sc =new Scanner(System.in);\n\t //File file = new File(\"file.txt\");\n\t//\tPrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));\n\t//\tsc.useDelimiter(\"(\\\\s)+|[,]\");\n\t\t \n\t while(sc.hasNext()){\n\t\t //long sum=0;\n\t//\t int n=sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();\n\t\tint n=sc.nextInt();\n\t\tb=false;\n\t//\tdb((int)sc.next().charAt(0));\n char c[][]=new char[2][n];\n\t me=new boolean [2][100][100][100][n];\t\n\t\t for(int i=0;i{\n int v,vv,t;\n\tP(int v,int vv,int t){\n\t\tthis.v=v;\n\t this.vv=vv;\n\t this.t=t;\n\t} \n\t public int compareTo(P x){\n return t-x.t;\n\t }\t\n \n\n}*/\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "451de0130c9f4f7903dac6aa12a9ae01", "src_uid": "1805771e194d323edacf2526a1eb6768", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class Main {\n\n /**\n * @param args\n */\n static int n;\n static StringBuilder[] strs;\n static HashSet hs=new HashSet();\n static boolean ok(int x,int y)\n {\n return strs[x].charAt(0)==strs[y].charAt(0) \n || strs[x].charAt(1)==strs[y].charAt(1);\n }\n \n static boolean dfs(int x){\n if(x==0)return true;\n if(x>1){\n if(hs.contains(strs[x].append(strs[x-1]).append(strs[x-2]).append(x)))return false;\n if(x>2&&ok(x,x-3)){\n StringBuilder t=strs[x-3];\n strs[x-3]=strs[x];\n if(dfs(x-1))return true;\n strs[x-3]=t;\n }\n }\n if(ok(x,x-1)){\n StringBuilder t=strs[x-1];\n strs[x-1]=strs[x];\n if(dfs(x-1))return true;\n strs[x-1]=t;\n }\n if(x>1)hs.add(strs[x].append(strs[x-1]).append(strs[x-2]).append(x).toString());\n return false;\n }\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner in = new Scanner(System.in);\n n=in.nextInt();strs=new StringBuilder[n];\n for(int i=0;i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n }\n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67695757be48626a4328935b6c585fec", "src_uid": "1805771e194d323edacf2526a1eb6768", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n/**\n *\n * @author sina\n */\npublic class ACMC1 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n int[] x=new int[4*n+1];\n int[] y=new int[4*n+1];\n int maxX=0;\n int maxY=0;\n int maxOX=0;\n int maxOY=0;\n for (int i = 0; i < 4*n+1; i++) {\n x[i]=in.nextInt();\n y[i]=in.nextInt();\n if(x[i]!=y[i])\n {\n if(maxOX=maxX)\n {\n maxOX=maxX; \n maxX=x[i];\n }\n else\n {\n maxOX=x[i];\n }\n }\n \n if(maxOY=maxY)\n {\n maxOY=maxY; \n maxY=y[i];\n }\n else\n {\n maxOY=y[i];\n }\n }\n }\n }\n int l=Math.min(maxOX, maxOY);\n for (int i = 0; i < 4*n+1; i++) {\n if(x[i]!=l&&y[i]!=l&&x[i]!=0&&y[i]!=0)\n {\n System.out.println(x[i]+\" \"+y[i]);\n break;\n }\n else if(x[i]>l||y[i]>l)\n {\n System.out.println(x[i]+\" \"+y[i]);\n break;\n }\n }\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d154505e42af7bfa9ecfbb15e64d630", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class C1_1184 {\n\n\tpublic static int solve (int [] countx,int n)\n\t{\n\t\tint i = 0;\n\t\twhile (countx[i] == 0)\n\t\t\ti++;\n\t\tif (countx[i] != n + 1) {\n\t\t\treturn i;\n\t\t}\n\t\ti++;\n\t\tint k = i;\n\t\tfor (; i < k + n - 1; i++) {\n\t\t\tif (countx[i] != n) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\tif (countx[i] != n + 1) {\n\t\t\treturn i;\n\t\t}\n\t\ti++;\n\t\twhile (countx[i] == 0) {\n\t\t\ti++;\n\t\t}\n\t\treturn i;\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tint[] countx = new int[51];\n\t\tint[] county = new int[51];\n\t\tfor (int i = 0; i < 4 * n + 1; i++) {\n\t\t\tcountx[sc.nextInt()]++;\n\t\t\tcounty[sc.nextInt()]++;\n\t\t}\n\t\tpw.println(solve(countx, n)+\" \"+solve(county, n));\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif (x.charAt(0) == '-') {\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor (int i = start; i < x.length(); i++)\n\t\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t} else {\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f576c41ed89d4fdf96c870428b752734", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class template {\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n =sc.nextInt();\n\t\tint[] o = new int[4*n+1];\n\t\tint[] p= new int[4*n+1];\n\t\tint[] r= new int[51];\n\t\tint[] d= new int[51]; \n\t\tfor(int i=0;i<4*n+1;i++) {\n\t\t\tint x= sc.nextInt();\n\t\t\tint y= sc.nextInt();\n\t\t\to[i]=x;\n\t\t\tp[i]=y;\n\t\t\tr[x]++;\n\t\t\td[y]++;\n\t\t}\n\t\tint sx =-1;\n\t\tint ex =-1;\n\t\tint sy =-1;\n\t\tint ey =-1;\n\t\tfor(int i=0;i=n+1) {\n\t\t\t\tif(sx==-1) {\n\t\t\t\t\tsx=i;\n\t\t\t\t}\n\t\t\t\telse ex =i;\n\t\t\t}\n\t\t\tif(d[i]>=n+1) {\n\t\t\t\tif(sy==-1) {\n\t\t\t\t\tsy=i;\n\t\t\t\t}\n\t\t\t\telse ey =i;\n\t\t\t}\n\t\t}\n\t\tboolean[][] x = new boolean[51][51];\n\t\tfor(int i=sx;i<=ex;i++) {\n\t\t\tx[i][sy]=true;\n\t\t\tx[i][ey]=true;\n\t\t}\n\t\tfor(int i=sy;i<=ey;i++) {\n\t\t\tx[sx][i]=true;\n\t\t\tx[ex][i]=true;\n\t\t}\n\t\tfor(int i=0;i<4*n+1;i++) {\n\t\t\tif(!x[o[i]][p[i]]) {\n\t\t\t\tpw.println(o[i]+\" \"+p[i]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n}\n@SuppressWarnings(\"all\")\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n public FastScanner(BufferedReader d) {\n br=d;\n }\n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n \n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "61090e9c73638586b80de316ca5ce7e3", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage acmc1;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author sina\n */\npublic class ACMC1 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n int[] x=new int[4*n+1];\n int[] y=new int[4*n+1];\n int maxX=0;\n int maxY=0;\n int maxOX=0;\n int maxOY=0;\n for (int i = 0; i < 4*n+1; i++) {\n x[i]=in.nextInt();\n y[i]=in.nextInt();\n if(x[i]!=y[i])\n {\n if(x[i]>=maxX)\n {\n maxOX=maxX; \n maxX=x[i];\n }\n if(y[i]>=maxY)\n {\n maxOY=maxY;\n maxY=y[i];\n }\n }\n }\n int l=Math.min(maxOX, maxOY);\n for (int i = 0; i < 4*n+1; i++) {\n if(x[i]!=l&&y[i]!=l&&x[i]!=0&&y[i]!=0)\n {\n System.out.println(x[i]+\" \"+y[i]);\n break;\n }\n else if(x[i]>l||y[i]>l)\n {\n System.out.println(x[i]+\" \"+y[i]);\n break;\n }\n }\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7e605f2017a7a6aad7d2051157d3c05d", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n class MaximApartment {\n private int[] result; //Holds the number of good apartments for each combination\n private final boolean debug = false; //Debug Mode\n \n public void debugPrintln(String s){\n if(debug) System.out.println(s);\n }\n public void debugPrint(String s){\n if(debug) System.out.print(s);\n }\n //Takes and returns the input argument\n public int[] getInput(){\n int[] result = {-1, -1};\n boolean stop = false;\n Scanner s = new Scanner(System.in);\n int val1 = -1;\n int val2 = -1;\n debugPrintln(\"Please provide the number of apartments followed by a space followed by the number of good apartments\");\n String input = s.nextLine();\n String[] inputVal = input.split(\" \");\n if(inputVal.length == 2){\n val1 = Integer.parseInt(inputVal[0]);\n val2 = Integer.parseInt(inputVal[1]);\n if(((val1 > 0 && val1 <= 1000000000)) && (val2 >= 0 && val2 <= val1)){\n result[0] = val1;\n result[1] = val2;\n stop = true;\n }\n }\n \n \n \n return result;\n }\n \n \n public void runA(){\n int[] inputs = getInput();\n \n if(inputs[0] != -1 && inputs[1] != -1){\n int min = Math.min(1, Math.min(inputs[1], inputs[0] - inputs[1]));\n \n int max = 0;\n int emptyApartments = inputs[0] - inputs[1];\n if(emptyApartments < (2 * inputs[1])) max = emptyApartments;\n else max = 2 * inputs[1];\n System.out.println(min + \" \" + max);\n \n }\n else{\n System.out.println(\"0 0\");\n debugPrintln(\"ERROR: Input Parameters that were returned does not contain valid value: \" + inputs[0] + \" and \" + inputs[1]);\n }\n \n }\n \n }\n public static void main(String[] args){\n MaximApartment ma = new MaximApartment();\n ma.runA();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "68c48d95bb8c175531fda9418859cc16", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args){\n Scanner s= new Scanner(System.in);\n int n = s.nextInt();\n int k = s.nextInt();\n System.out.print(k&&n-k?1:0+\" \"+n>=3*k?2*k:n-k);\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0084a538b742bdbe97381452dc140bb1", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by tarekihya on 06/09/2017.\n */\npublic class others {\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n\n long maison = in.nextLong();\n long full = in.nextLong();\nif(maison==full||full==0){\n System.out.println(0+\" \"+0);\n}else{\n \n System.out.println(1+\" \"+maison-full);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "19fceb11a704c0ae051f56787d45efb3", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class Second {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long k = sc.nextLong();\n long min = 1;\n long ways = n/2;\n if(k==n){\n System.out.println(0+\" \"+0);\n }\n else if(k==1){\n System.out.println(1+\" \"+2);\n }\n else if(k==ways){\n System.out.println(1+\" \"+ways);\n }\n else{\n ways = n-k;\n System.out.println(1+\" \"+ways);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5394082e320a2545c0fafcfa57d02dfc", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class CF336D {\n \n static final int mod = (int)Math.pow(10, 9) + 7;\n \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 int g = in.nextInt();\n \n long[] fact = new long[n + m + 1];\n long[] inv = new long[Math.max(n, m) + 1];\n fact[0] = 1;\n inv[0] = 1;\n for (int k = 1; k <= n + m; k++)\n {\n fact[k] = k * fact[k - 1] % mod;\n if (k <= Math.max(n,m))\n inv[k] = power(fact[k], mod - 2) % mod;\n }\n \n if (m == 0)\n {\n if (g % 2 != n % 2)\n System.out.println(1);\n else\n System.out.println(0);\n }\n else\n {\n long total = 0;\n for (int k = 1; k <= n + 1; k++)\n if ((g % 2 != k % 2 && (m != 1 || m == 1 && k != n + 1)) || (g % 2 == (n + 1) % 2 && m == 1 && k == n + 1))\n total = (total + (fact[n + m - k] * inv[m - 1] % mod) * inv[n - k + 1]) % mod;\n System.out.println(total);\n }\n }\n \n public static long power(long a, int n)\n {\n if (n == 0)\n return 1;\n else if (n == 1)\n return a % mod;\n else if (n % 2 == 0)\n return power(a*a % mod, n/2) % mod;\n else\n return (a * (power(a*a % mod, (n-1)/2) % mod)) % mod;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ff9448ebe1444fe0281328088ef3f168", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0} {"lang": "Java 7", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "608aa1b7fe471d01c686aa7ff0e838e3", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.awt.Point;\n\npublic class CodeForces {\n static boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n Map mem = new HashMap();\n Map memc = new HashMap();\n\n private static final long MOD = 1000000007;\n\n long pw(long x, long y) {\n long res = 1;\n while (y > 0) {\n if ((y % 2) > 0) {\n --y;\n res = (res * x) % MOD;\n } else {\n y /= 2;\n x = (x * x) % MOD;\n }\n }\n return res;\n }\n\n long rev(long x)\n {\n return pw(x, MOD - 2);\n }\n\n void runCase(int caseNum) throws IOException {\n long m = nextLong();\n long n = nextLong();\n int g = nextInt();\n\n if (n == 0) {\n if ((m & 1) == 1) {\n if (g == 0)\n System.out.println(\"1\");\n else\n System.out.println(\"0\");\n } else {\n if (g == 0)\n System.out.println(\"0\");\n else\n System.out.println(\"1\");\n }\n return;\n }\n\n long prevZero = 1;\n long prevOne = 0;\n if (n == 1) {\n prevOne = 1;\n prevZero = 0;\n }\n long pc = 1;\n\n for (int i = 1; i <= m; ++i) {\n pc *= n + i - 1;\n if (pc >= MOD)\n pc %= MOD;\n pc *= rev(i);\n if (pc >= MOD)\n pc %= MOD;\n long one = prevZero;\n long zero = prevOne;\n zero += pc;\n if (zero >= MOD)\n zero %= MOD;\n prevOne = one;\n prevZero = zero;\n }\n\n// long res = go(n, m, g);\n// System.out.println(res);\n if (g == 1)\n System.out.println(prevOne);\n else\n System.out.println(prevZero);\n }\n\n\n public static void main(String[] args) throws IOException {\n if (ONLINE_JUDGE){\n System.out.println();\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(System.out);\n //out = new PrintWriter(\"output.txt\");\n }\n new CodeForces().runIt();\n out.flush();\n out.close();\n return;\n }\n\n static BufferedReader in;\n private StringTokenizer st;\n static PrintWriter out;\n\n String next() throws IOException {\n while (!st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null) {\n return null;\n }\n st = new StringTokenizer(line);\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n\n void runIt() throws IOException {\n st = new StringTokenizer(\"\");\n\n// int N = nextInt();\n// for (int i = 0; i < N; i++) {\n// runCase(i + 1);\n// }\n runCase(0);\n out.flush();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c81b5733eb93e8b4096a94c4893c6b35", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n/**\n *\n *\n * 3 2 3 5\n * -2 -1 4 -1 2 7 3\n *\n *\n * @author pttrung\n */\npublic class D {\n\n public static long MOD = 1000000007;\n public static long[] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n PrintWriter out;\n Scanner in = new Scanner();\n //out = new PrintWriter(new FileOutputStream(new File(\"output.txt\")));\n out = new PrintWriter(System.out);\n int m = in.nextInt();\n int n = in.nextInt();\n int g = in.nextInt();\n\n if (n + m == 1) {\n if (g == 0) {\n out.println(m);\n } else {\n out.println(n);\n }\n } else {\n dp = new long[n + m + 1];\n dp[0] = 1;\n dp[1] = 1;\n for (int i = 1; i < dp.length; i++) {\n dp[i] = i * dp[i - 1];\n dp[i] %= MOD;\n }\n out.println(cal(n, m, g));\n }\n out.close();\n }\n\n public static long cal(int n, int m, int need) {\n long result = 0;\n while (true) {\n \n if (n + m == 1) {\n if (need == 0) {\n result += m;\n } else {\n result += n;\n }\n break;\n }\n\n if (need == 0) {\n if (n > 0) {\n int a = n - 1;\n int pos = a + m;\n BigInteger x = BigInteger.valueOf(dp[pos]);\n x = x.multiply(BigInteger.valueOf(dp[a]).multiply(BigInteger.valueOf(dp[m])).modInverse(BigInteger.valueOf(MOD))).mod(BigInteger.valueOf(MOD));\n result += x.longValue();\n }\n if (m > 0) {\n m--;\n need = 1;\n }\n } else {\n if (m > 0) {\n m--;\n need = 0;\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 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\n\n\n\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n 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\n\n\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n //br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6fc5423107d3d438581e07119cc6c03d", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\n/**\n * @author Nikita Gorokhov \n */\npublic class E {\n\n private void solve() {\n int n = nextInt();\n String s = next();\n\n int[] col = new int[28];\n col[0] = Integer.MAX_VALUE;\n for (int i = 1; i < n; i++) {\n col[i] = Integer.MIN_VALUE;\n }\n\n int totalMax = 0;\n int[] p = new int[n];\n for (int i = 0; i < n; i++) {\n int a = s.charAt(i) - 'a';\n int max = 0;\n for (int j = 1; j <= Math.min(n, 27); j++) {\n if (col[j - 1] > a && a >= col[j]) {\n col[j] = a;\n max = j;\n }\n }\n p[i] = max - 1;\n totalMax = Math.max(totalMax, max);\n }\n if (totalMax > 2) {\n out.println(\"NO\");\n } else {\n out.println(\"YES\");\n for (int i = 0; i < n; i++) {\n out.print(p[i]);\n }\n out.println();\n }\n }\n\n private final static String INPUT_FILENAME = \"input.txt\";\n private final static boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private InputStream inputStream;\n private PrintWriter out;\n\n private void run() throws FileNotFoundException {\n inputStream = ONLINE_JUDGE ? System.in : new FileInputStream(INPUT_FILENAME);\n out = new PrintWriter(System.out);\n\n int t = 1;\n\n for (int testNum = 0; testNum < t; testNum++) {\n solve();\n }\n\n out.flush();\n }\n\n public static void main(String[] args) throws Exception {\n new E().run();\n }\n\n private byte[] buffer = new byte[1024];\n private int bufferLen = 0, bufferPtr = 0;\n\n private int readByte() {\n if (bufferLen == -1) {\n throw new InputMismatchException();\n }\n if (bufferPtr >= bufferLen) {\n bufferPtr = 0;\n try {\n bufferLen = inputStream.read(buffer);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (bufferLen <= 0) {\n return -1;\n }\n }\n return buffer[bufferPtr++];\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 nextDouble() {\n return Double.parseDouble(next());\n }\n\n private char nextChar() {\n return (char) skip();\n }\n\n private String next() {\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 int nextInt() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {\n ;\n }\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\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 nextLong() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {\n ;\n }\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6a9c1e5c5c1af4be79ce62f4dd174467", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\npublic class Main\n{\n //your static variables go here:\n\n static ArrayList graph[];\n static boolean vis[];\n static int seive[]=new int[1000001];\n static int dis[]=new int[1000001];\n static int subtree[]=new int[1000001];\n\n\n static int time=0;\n //******************************************************************\n static class FastReader\n {\n BufferedReader br;\n StringTokenizer st;\n public FastReader()\n { br = new BufferedReader(new InputStreamReader(System.in));\n }String next()\n { while (st == null || !st.hasMoreElements()){ try\n { st = new StringTokenizer(br.readLine()); }\n catch (IOException e){e.printStackTrace();}}\n return st.nextToken();}\n int nextInt()\n {return Integer.parseInt(next());}\n long nextLong(){ return Long.parseLong(next()); }\n double nextDouble(){return Double.parseDouble(next());\n }String nextLine(){ String str = \"\";\n try{str = br.readLine();}\n catch (IOException e) {e.printStackTrace();}\n return str;}\n }\n//*************************************************************************\n/**\n\n*/\n//left right is for query range\npublic static void build(int a[], long seg[], int start, int end, int cur)\n{\n if(start>end)\n return;\n if(start==end)\n {\n seg[cur]=seive[a[start]];\n return;\n }\n int mid=start+(end-start)/2;\n build(a, seg, start, mid, 2*cur+1);\n build(a,seg, mid+1, end, 2*cur+2);\n seg[cur]=seg[2*cur+1]+seg[2*cur+2];\n}\npublic static long query( int left, int right, int start, int end, int cur, long seg[] )\n{\n if(start>end)\n return 0;\n if(left>end||right=end)\n return seg[cur];\n int mid=start+(end-start)/2;\n return query(left,right,start, mid, 2*cur+1, seg)+query( left, right, mid+1, end, 2*cur+2, seg);\n}\n\npublic static void update( int left, int right, int start, int end, int cur, long seg[], long value)\n{\n if(start>end)\n return;\n if(left>end||right ans=new ArrayList<>();\n HashSet hs[]=new HashSet[26];\n for( int i=0;i<26;i++)\n hs[i]=new HashSet<>();\n int max=Integer.MIN_VALUE;\n for( int i=0;i2)\n {\n System.out.println(\"NO\");\n }\n else\n for( int i=0;i=0;i--){\n char ch=s.charAt(i);\n int ac=ch-'a';\n int max=0;\n for(int j=0;j adj[];\n static boolean visited[];\n static int N;\n static int color[];\n public static void main(String ag[])\n {\n Scanner sc=new Scanner(System.in);\n int i,j,k;\n \n int N=sc.nextInt();\n char A[]=sc.next().toCharArray();\n \n visited=new boolean[N];\n color=new int[N];\n adj=new ArrayList[N];\n for(i=0;i();\n \n for(i=0;iA[i])\n {\n adj[j].add(i);\n adj[i].add(j);\n } \n }\n }\n \n boolean flag=true;\n for(i=0;i0)\n {\n flag=BFS(i);\n if(!flag)\n break;\n }\n }\n if(!flag)\n System.out.println(\"NO\");\n else \n {\n StringBuilder sb=new StringBuilder();\n System.out.println(\"YES\");\n for(i=0;i q=new LinkedList<>();\n q.add(node);\n color[node]=1;\n while(!q.isEmpty())\n {\n int curr=q.poll();\n visited[curr]=true;\n Iterator itr=adj[curr].iterator();\n while(itr.hasNext())\n {\n int next=itr.next();\n if(!visited[next])\n {\n color[next]=1-color[curr];\n q.add(next);\n }\n else \n {\n if(color[next]==color[curr])\n return false;\n }\n }\n }\n return true;\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2b400de3848c8085ee95442dc536d6cd", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\n\n/* Name of the class has to be \"Main\" only if the class is public. */\n\n\n\npublic class Main\n{\n \n \n \n static PrintWriter out;\n \n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\n// SHIVAM GUPTA :\n\n\n\n// ASCII = 48 + i ;\n\n// SHIVAM GUPTA :\n\n\n\n\n\npublic static int min(int a ,int b , int c, int d)\n{\n \n \n int[] arr = new int[4] ;\n arr[0] = a;\n arr[1] = b ;\n arr[2] = c;\n arr[3] = d;\n Arrays.sort(arr) ;\n \n return arr[0];\n \n}\n \npublic static int max(int a ,int b , int c, int d)\n{\n \n \n int[] arr = new int[4] ;\n arr[0] = a;\n arr[1] = b ;\n arr[2] = c;\n arr[3] = d;\n Arrays.sort(arr) ;\n \n return arr[3];\n \n}\n \n \nstatic int sieve = 1000000 ;\n\n \nstatic boolean[] prime = new boolean[sieve + 1] ;\n\n \npublic static void sieveOfEratosthenes() \n { \n // TRUE == prime\n \n // FALSE == COMPOSITE\n \n // FALSE== 1\n \n for(int i=0;i< sieve + 1;i++) \n prime[i] = true; \n \n for(int p = 2; p*p <= sieve; p++) \n { \n \n if(prime[p] == true) \n { \n \n for(int i = p*p; i <= sieve; i += p) \n prime[i] = false; \n } \n } \n \n \n \n \n } \n \n \npublic static String reverse(String input)\n{\n String op = \"\" ;\n \n for(int i = 0; i < input.length() ; i++ )\n {\n op = input.charAt(i)+ op ; \n }\n \nreturn op ;\n}\n\n\n\n\npublic static int[] sortI(int[] arr)\n{\n Arrays.sort(arr) ;\n return arr ;\n}\n\npublic static int[] sortD(int[] arr)\n{\n Arrays.sort(arr) ;\n \n int i =0 ; int j = arr.length -1 ;\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 arr ;\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)\n {\n return true ;\n }\n \n return false ;\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\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\n\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 static final int MAXN = 100001; \n \n \n static int spf[] = new int[MAXN]; \n \n static void sieve() \n { \n spf[1] = 1; \n for (int i=2; i getFactorization(int x) \n { \n Vector ret = new Vector<>(); \n while (x != 1) \n { \n ret.add(spf[x]); \n x = x / spf[x]; \n } \n return ret; \n } \n \n \n \npublic static void main (String[] args) throws java.lang.Exception\n{\n FastReader scn = new FastReader() ;\n\n\nint x1 = scn.nextInt() ; int y1 = scn.nextInt() ;\nint x2 = scn.nextInt() ; int y2 = scn.nextInt() ;\nint x3 = scn.nextInt() ; int y3 = scn.nextInt() ;\n\nout.println(3) ;\nout.println(x1+x2-x3 +\" \" + y1+y2-y3) ;\nout.println(x3+x2-x1 +\" \" + y3+y2-y1) ;\nout.println(x1+x3-x2 +\" \" + y1+y3-y2) ;\n\n\n\n\nout.flush() ; \n \n}\n\n\n}\n \n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "df6441040873438835f8105e4191929c", "src_uid": "7725f9906a1b87bf4e866df03112f1e0", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class parallelogram {\n\tpublic static void main(String [] args) throws IOException{\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st;\n\t\tSystem.out.println(3);\n\t\tint[][] points = new int[2][3];\n\t\tfor(int i=0; i<3; i++) {\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tpoints[0][i]=Integer.parseInt(st.nextToken());\n\t\t\tpoints[1][i]=Integer.parseInt(st.nextToken());\n\t\t}\n\t\tSet answers = new HashSet();\n\t\tint xdiff1 = points[0][1]-points[0][2];\n\t\tint xdiff2 = points[0][0]-points[0][1];\n\t\tint ydiff1 = points[1][1]-points[1][2];\n\t\tint ydiff2 = points[1][0]-points[1][1];\n\t\tanswers.add((points[0][0]+xdiff1)+\" \"+points[1][0]+ydiff1);\n\t\tanswers.add((points[0][0]-xdiff1)+\" \"+points[1][0]-ydiff1);\n\t\tanswers.add((points[0][2]+xdiff2)+\" \"+points[1][2]+ydiff2);\n\t\tanswers.add((points[0][2]-xdiff2)+\" \"+points[1][2]-ydiff2);\n\t\tfor(String str : answers) {\n\t\t\tSystem.out.println(str);\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fca0700ae1d4706ea06b80ee69a6639a", "src_uid": "7725f9906a1b87bf4e866df03112f1e0", "difficulty": 1200.0} {"lang": "Java 8", "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 Point{\n int x,y;\n public Point(int x,int y){\n this.x=x;\n this.y=y;\n }\n}\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 in = new Scanner(System.in);\n\t\tPoint a=new Point(in.nextInt(),in.nextInt());\n\t\tPoint b=new Point(in.nextInt(),in.nextInt());\n\t\tPoint c=new Point(in.nextInt(),in.nextInt());\n\t\tSystem.out.println(3);\n\t\tSystem.out.println((b.x-c.x+a.x)+\" \"+(b.y-c.y+a.y));\n\t\tSystem.out.println((c.x-a.x+b.x)+\" \"+(c.y-a.y+b.y));\n\t\tSystem.out.println((a.x-b.x+c.x)+\" \"+(a.y-b.y+c.y));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4854603e89b393f199dce3b7b7569f14", "src_uid": "7725f9906a1b87bf4e866df03112f1e0", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class bachgold {\n\tpublic static void main(String [] args) throws IOException{\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st;\n\t\tSystem.out.println(3);\n\t\tint[][] points = new int[2][3];\n\t\tfor(int i=0; i<3; i++) {\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tpoints[0][i]=Integer.parseInt(st.nextToken());\n\t\t\tpoints[1][i]=Integer.parseInt(st.nextToken());\n\t\t}\n\t\tSet answers = new HashSet();\n\t\tint xdiff1 = points[0][1]-points[0][2];\n\t\tint xdiff2 = points[0][0]-points[0][1];\n\t\tint ydiff1 = points[1][1]-points[1][2];\n\t\tint ydiff2 = points[1][0]-points[1][1];\n\t\tanswers.add((points[0][0]+xdiff1)+\" \"+(points[1][0]+ydiff1));\n\t\tanswers.add((points[0][0]-xdiff1)+\" \"+(points[1][0]-ydiff1));\n\t\tanswers.add((points[0][2]+xdiff2)+\" \"+(points[1][2]+ydiff2));\n\t\tanswers.add((points[0][2]-xdiff2)+\" \"+(points[1][2]-ydiff2));\n\t\tfor(String str : answers) {\n\t\t\tSystem.out.println(str);\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "52f83b5df1d43dc9421a7157fd363759", "src_uid": "7725f9906a1b87bf4e866df03112f1e0", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n\n public class Maxflow {\n class Edge {\n int t, rev;\n long cap, f;\n public Edge(int t, int rev, long cap) {\n this.t = t;\n this.rev = rev;\n this.cap = cap;\n }\n }\n public Maxflow(int n) {\n graph = new List[n];\n for (int i = 0; i < n; i++) {\n graph[i] = new ArrayList<>();\n }\n }\n List[] graph;\n void addEdge(int s, int t, long cap) {\n graph[s].add(new Edge(t, graph[t].size(), cap));\n graph[t].add(new Edge(s, graph[s].size() - 1, 0));\n// if (cap != Integer.MAX_VALUE)\n// System.err.println(s + \" \" + t + \" \" + cap);\n }\n\n boolean dinicBFS(int src, int dest, int[] dist) {\n Arrays.fill(dist, -1);\n dist[src] = 0;\n int[] Q = new int[graph.length];\n int sizeQ = 0;\n Q[sizeQ++] = src;\n for (int i = 0; i < sizeQ; i++) {\n int u = Q[i];\n for (Edge e: graph[u]) {\n if (dist[e.t] < 0 && e.f < e.cap) {\n dist[e.t] = dist[u] + 1;\n Q[sizeQ++] = e.t;\n }\n }\n }\n return dist[dest] >= 0;\n }\n\n long dinicDFS(int[] ptr, int[] dist, int dest, int u, long f) {\n if (u == dest) return f;\n for (;ptr[u] < graph[u].size(); ++ptr[u]) {\n Edge e = graph[u].get(ptr[u]);\n if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {\n long df = dinicDFS(ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));\n if (df > 0) {\n e.f += df;\n graph[e.t].get(e.rev).f -= df;\n return df;\n }\n }\n }\n return 0;\n }\n\n long maxFLow(int src, int dest) {\n long flow = 0;\n int[] dist = new int[graph.length];\n while (dinicBFS(src, dest, dist)) {\n int[] ptr = new int[graph.length];\n while (true) {\n long df = dinicDFS(ptr, dist, dest, src, Long.MAX_VALUE);\n if (df == 0) break;\n flow += df;\n }\n }\n return flow;\n }\n }\n\n int interValIndex;\n public class IntervalNode {\n int l, r;\n IntervalNode left, right;\n int index;\n public IntervalNode(int L, int R) {\n this.l = L;\n this.r = R;\n this.index = interValIndex++;\n int mid = (l + r) / 2;\n if (mid > l) {\n left = new IntervalNode(l, mid);\n right = new IntervalNode(mid, r);\n }\n }\n }\n int mfEnd;\n IntervalNode[] baseNodes;\n public void dfsAddEdge(Maxflow mf, IntervalNode node) {\n if (node.left != null) {\n mf.addEdge(node.index, node.left.index, Integer.MAX_VALUE / 2);\n mf.addEdge(node.index, node.right.index, Integer.MAX_VALUE / 2);\n dfsAddEdge(mf, node.left);\n dfsAddEdge(mf, node.right);\n } else {\n baseNodes[node.l] = node;\n mf.addEdge(node.index, mfEnd, 1);\n }\n }\n\n public void searchCover(Maxflow mf, IntervalNode node, int l, int r, int start) {\n if (l <= node.l && node.r <= r) {\n mf.addEdge(start, node.index, 1);\n return;\n }\n if (node.l >= r || node.r <= l) return;\n searchCover(mf, node.left, l, r, start);\n searchCover(mf, node.right, l, r, start);\n }\n\n public int dfsDecode(List[] graph, int u) {\n for (Maxflow.Edge e: graph[u]) {\n if (e.f > 0) {\n if (e.t == mfEnd) {\n e.f -= 1;\n return u;\n }\n int ret = dfsDecode(graph, e.t);\n if (ret > 0) {\n e.f -= 1;\n return ret;\n }\n }\n }\n return -1;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n int n = sc.nextInt();\n int m = sc.nextInt();\n interValIndex = n + 1;\n IntervalNode root = new IntervalNode(0, m);\n mfEnd = interValIndex;\n Maxflow mf = new Maxflow(mfEnd + 1);\n baseNodes = new IntervalNode[m];\n dfsAddEdge(mf, root);\n int[][] weapons = new int[n][];\n for (int i = 0; i < n; i++) {\n int type = sc.nextInt();\n if (type == 0) {\n int k = sc.nextInt();\n weapons[i] = new int[k + 1];\n weapons[i][0] = type;\n for (int j = 1; j <= k; j++) {\n weapons[i][j] = sc.nextInt() - 1;\n }\n mf.addEdge(0, i + 1, 1);\n for (int j = 1; j <= k; j++) {\n mf.addEdge(i + 1, baseNodes[weapons[i][j]].index, 1);\n }\n } else if (type == 1) {\n int l = sc.nextInt() - 1;\n int r = sc.nextInt();\n weapons[i] = new int[3];\n weapons[i][0] = type;\n weapons[i][1] = l;\n weapons[i][2] = r;\n mf.addEdge(0, i + 1, 1);\n searchCover(mf, root, l, r, 1 + i);\n } else if (type == 2) {\n int a = sc.nextInt() - 1;\n int b = sc.nextInt() - 1;\n int c = sc.nextInt() - 1;\n weapons[i] = new int[4];\n weapons[i][0] = type;\n weapons[i][1] = a;\n weapons[i][2] = b;\n weapons[i][2] = c;\n mf.addEdge(0, i + 1, 2);\n mf.addEdge(i + 1, baseNodes[a].index, 1);\n mf.addEdge(i + 1, baseNodes[b].index, 1);\n mf.addEdge(i + 1, baseNodes[c].index, 1);\n }\n }\n long flow = mf.maxFLow(0, mfEnd);\n pw.println(flow);\n List[] graph = mf.graph;\n Map toIndex = new HashMap<>();\n for (int i = 0; i < baseNodes.length; i++) {\n toIndex.put(baseNodes[i].index, i);\n }\n toIndex.put(-1, -1);\n int[][] connectTo = new int[n][2];\n for (int i = 0; i < n; i++) {\n connectTo[i][1] = -1;\n connectTo[i][0] = toIndex.get(dfsDecode(graph, i + 1));\n if (weapons[i][0] == 2) connectTo[i][1] = toIndex.get(dfsDecode(graph, i + 1));\n }\n int[] whose = new int[m];\n for (int i = 0; i < n; i++) {\n if (weapons[i][0] != 2 && connectTo[i][0] != -1) {\n whose[connectTo[i][0]] = i;\n }\n }\n for (int i = 0; i < n; i++) {\n if (weapons[i][0] == 2 && connectTo[i][1] == -1 && connectTo[i][0] != -1) {\n for (int j = 1; j < 4; j++) {\n if (connectTo[i][0] != weapons[i][j]) {\n connectTo[i][1] = weapons[i][j];\n connectTo[whose[weapons[i][j]]][0] = -1;\n break;\n }\n }\n }\n }\n for (int i = 0; i < n; i++) {\n if (connectTo[i][0] >= 0) {\n pw.println((i + 1) + \" \" + (connectTo[i][0] + 1));\n }\n if (connectTo[i][1] >= 0) {\n pw.println((i + 1) + \" \" + (connectTo[i][1] + 1));\n }\n }\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"output\"));\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50c7f7387eb91a59874a183d7e57d6e1", "src_uid": "429a94c8e3f28100c8c532e948cc36e3", "difficulty": 2500.0} {"lang": "Java 8", "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[] 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[] createGraph(int nodes) {\n\t\t\tArrayList[] 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[] 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[] 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[] 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[] 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9b4db06c13a09dca3d9dabc8c83659ef", "src_uid": "429a94c8e3f28100c8c532e948cc36e3", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n\n public class Maxflow {\n class Edge {\n int t, rev;\n long cap, f;\n public Edge(int t, int rev, long cap) {\n this.t = t;\n this.rev = rev;\n this.cap = cap;\n }\n }\n public Maxflow(int n) {\n graph = new List[n];\n for (int i = 0; i < n; i++) {\n graph[i] = new ArrayList<>();\n }\n }\n List[] graph;\n void addEdge(int s, int t, long cap) {\n graph[s].add(new Edge(t, graph[t].size(), cap));\n graph[t].add(new Edge(s, graph[s].size() - 1, 0));\n// if (cap != Integer.MAX_VALUE)\n// System.err.println(s + \" \" + t + \" \" + cap);\n }\n\n boolean dinicBFS(int src, int dest, int[] dist) {\n Arrays.fill(dist, -1);\n dist[src] = 0;\n int[] Q = new int[graph.length];\n int sizeQ = 0;\n Q[sizeQ++] = src;\n for (int i = 0; i < sizeQ; i++) {\n int u = Q[i];\n for (Edge e: graph[u]) {\n if (dist[e.t] < 0 && e.f < e.cap) {\n dist[e.t] = dist[u] + 1;\n Q[sizeQ++] = e.t;\n }\n }\n }\n return dist[dest] >= 0;\n }\n\n long dinicDFS(int[] ptr, int[] dist, int dest, int u, long f) {\n if (u == dest) return f;\n for (;ptr[u] < graph[u].size(); ++ptr[u]) {\n Edge e = graph[u].get(ptr[u]);\n if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {\n long df = dinicDFS(ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));\n if (df > 0) {\n e.f += df;\n graph[e.t].get(e.rev).f -= df;\n return df;\n }\n }\n }\n return 0;\n }\n\n long maxFLow(int src, int dest) {\n long flow = 0;\n int[] dist = new int[graph.length];\n while (dinicBFS(src, dest, dist)) {\n int[] ptr = new int[graph.length];\n while (true) {\n long df = dinicDFS(ptr, dist, dest, src, Long.MAX_VALUE);\n if (df == 0) break;\n flow += df;\n }\n }\n return flow;\n }\n }\n\n int interValIndex;\n public class IntervalNode {\n int l, r;\n IntervalNode left, right;\n int index;\n public IntervalNode(int L, int R) {\n this.l = L;\n this.r = R;\n this.index = interValIndex++;\n int mid = (l + r) / 2;\n if (mid > l) {\n left = new IntervalNode(l, mid);\n right = new IntervalNode(mid, r);\n }\n }\n }\n int mfEnd;\n IntervalNode[] baseNodes;\n public void dfsAddEdge(Maxflow mf, IntervalNode node) {\n if (node.left != null) {\n mf.addEdge(node.index, node.left.index, Integer.MAX_VALUE / 2);\n mf.addEdge(node.index, node.right.index, Integer.MAX_VALUE / 2);\n dfsAddEdge(mf, node.left);\n dfsAddEdge(mf, node.right);\n } else {\n baseNodes[node.l] = node;\n mf.addEdge(node.index, mfEnd, 1);\n }\n }\n\n public void searchCover(Maxflow mf, IntervalNode node, int l, int r, int start) {\n if (l <= node.l && node.r <= r) {\n mf.addEdge(start, node.index, 1);\n return;\n }\n if (node.l >= r || node.r <= l) return;\n searchCover(mf, node.left, l, r, start);\n searchCover(mf, node.right, l, r, start);\n }\n\n public int dfsDecode(List[] graph, int u) {\n for (Maxflow.Edge e: graph[u]) {\n if (e.f > 0) {\n if (e.t == mfEnd) {\n e.f -= 1;\n return u;\n }\n int ret = dfsDecode(graph, e.t);\n if (ret > 0) {\n e.f -= 1;\n return ret;\n }\n }\n }\n return -1;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n int n = sc.nextInt();\n int m = sc.nextInt();\n interValIndex = n + 1;\n IntervalNode root = new IntervalNode(0, m);\n mfEnd = interValIndex;\n Maxflow mf = new Maxflow(mfEnd + 1);\n baseNodes = new IntervalNode[m];\n dfsAddEdge(mf, root);\n int[][] weapons = new int[n][];\n for (int i = 0; i < n; i++) {\n int type = sc.nextInt();\n if (type == 0) {\n int k = sc.nextInt();\n weapons[i] = new int[k + 1];\n weapons[i][0] = type;\n for (int j = 1; j <= k; j++) {\n weapons[i][j] = sc.nextInt() - 1;\n }\n mf.addEdge(0, i + 1, 1);\n for (int j = 1; j <= k; j++) {\n mf.addEdge(i + 1, baseNodes[weapons[i][j]].index, 1);\n }\n } else if (type == 1) {\n int l = sc.nextInt() - 1;\n int r = sc.nextInt();\n weapons[i] = new int[3];\n weapons[i][0] = type;\n weapons[i][1] = l;\n weapons[i][2] = r;\n mf.addEdge(0, i + 1, 1);\n searchCover(mf, root, l, r, 1 + i);\n } else if (type == 2) {\n int a = sc.nextInt() - 1;\n int b = sc.nextInt() - 1;\n int c = sc.nextInt() - 1;\n weapons[i] = new int[4];\n weapons[i][0] = type;\n weapons[i][1] = a;\n weapons[i][2] = b;\n weapons[i][2] = c;\n mf.addEdge(0, i + 1, 2);\n mf.addEdge(i + 1, baseNodes[a].index, 1);\n mf.addEdge(i + 1, baseNodes[b].index, 1);\n mf.addEdge(i + 1, baseNodes[c].index, 1);\n }\n }\n long flow = mf.maxFLow(0, mfEnd);\n pw.println(flow);\n List[] graph = mf.graph;\n Map toIndex = new HashMap<>();\n for (int i = 0; i < baseNodes.length; i++) {\n toIndex.put(baseNodes[i].index, i);\n }\n toIndex.put(-1, -1);\n int[][] connectTo = new int[n][2];\n for (int i = 0; i < n; i++) {\n connectTo[i][1] = -1;\n connectTo[i][0] = toIndex.get(dfsDecode(graph, i + 1));\n if (weapons[i][0] == 2) connectTo[i][1] = toIndex.get(dfsDecode(graph, i + 1));\n }\n int[] whose = new int[m];\n for (int i = 0; i < n; i++) {\n if (weapons[i][0] != 2 && connectTo[i][0] != -1) {\n whose[connectTo[i][0]] = i;\n }\n }\n for (int i = 0; i < n; i++) {\n if (weapons[i][0] == 2 && connectTo[i][1] == -1) {\n for (int j = 1; j < 4; j++) {\n if (connectTo[i][0] != weapons[i][j]) {\n connectTo[i][1] = weapons[i][j];\n connectTo[whose[weapons[i][j]]][0] = -1;\n }\n }\n }\n }\n for (int i = 0; i < n; i++) {\n if (connectTo[i][0] >= 0) {\n pw.println((i + 1) + \" \" + (connectTo[i][0] + 1));\n }\n if (connectTo[i][1] >= 0) {\n pw.println((i + 1) + \" \" + (connectTo[i][1] + 1));\n }\n }\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"output\"));\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "94e8c290d6d5ac6e6519ca4b0f0117a3", "src_uid": "429a94c8e3f28100c8c532e948cc36e3", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n\n public class Maxflow {\n class Edge {\n int t, rev;\n long cap, f;\n public Edge(int t, int rev, long cap) {\n this.t = t;\n this.rev = rev;\n this.cap = cap;\n }\n }\n public Maxflow(int n) {\n graph = new List[n];\n for (int i = 0; i < n; i++) {\n graph[i] = new ArrayList<>();\n }\n }\n List[] graph;\n void addEdge(int s, int t, long cap) {\n graph[s].add(new Edge(t, graph[t].size(), cap));\n graph[t].add(new Edge(s, graph[s].size() - 1, 0));\n// if (cap != Integer.MAX_VALUE)\n// System.err.println(s + \" \" + t + \" \" + cap);\n }\n\n boolean dinicBFS(int src, int dest, int[] dist) {\n Arrays.fill(dist, -1);\n dist[src] = 0;\n int[] Q = new int[graph.length];\n int sizeQ = 0;\n Q[sizeQ++] = src;\n for (int i = 0; i < sizeQ; i++) {\n int u = Q[i];\n for (Edge e: graph[u]) {\n if (dist[e.t] < 0 && e.f < e.cap) {\n dist[e.t] = dist[u] + 1;\n Q[sizeQ++] = e.t;\n }\n }\n }\n return dist[dest] >= 0;\n }\n\n long dinicDFS(int[] ptr, int[] dist, int dest, int u, long f) {\n if (u == dest) return f;\n for (;ptr[u] < graph[u].size(); ++ptr[u]) {\n Edge e = graph[u].get(ptr[u]);\n if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {\n long df = dinicDFS(ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));\n if (df > 0) {\n e.f += df;\n graph[e.t].get(e.rev).f -= df;\n return df;\n }\n }\n }\n return 0;\n }\n\n long maxFLow(int src, int dest) {\n long flow = 0;\n int[] dist = new int[graph.length];\n while (dinicBFS(src, dest, dist)) {\n int[] ptr = new int[graph.length];\n while (true) {\n long df = dinicDFS(ptr, dist, dest, src, Long.MAX_VALUE);\n if (df == 0) break;\n flow += df;\n }\n }\n return flow;\n }\n }\n\n int interValIndex;\n public class IntervalNode {\n int l, r;\n IntervalNode left, right;\n int index;\n public IntervalNode(int L, int R) {\n this.l = L;\n this.r = R;\n this.index = interValIndex++;\n int mid = (l + r) / 2;\n if (mid > l) {\n left = new IntervalNode(l, mid);\n right = new IntervalNode(mid, r);\n }\n }\n }\n int mfEnd;\n IntervalNode[] baseNodes;\n public void dfsAddEdge(Maxflow mf, IntervalNode node) {\n if (node.left != null) {\n mf.addEdge(node.index, node.left.index, Integer.MAX_VALUE / 2);\n mf.addEdge(node.index, node.right.index, Integer.MAX_VALUE / 2);\n dfsAddEdge(mf, node.left);\n dfsAddEdge(mf, node.right);\n } else {\n baseNodes[node.l] = node;\n mf.addEdge(node.index, mfEnd, 1);\n }\n }\n\n public void searchCover(Maxflow mf, IntervalNode node, int l, int r, int start) {\n if (l <= node.l && node.r <= r) {\n mf.addEdge(start, node.index, 1);\n return;\n }\n if (node.l >= r || node.r <= l) return;\n searchCover(mf, node.left, l, r, start);\n searchCover(mf, node.right, l, r, start);\n }\n\n public int dfsDecode(List[] graph, int u) {\n for (Maxflow.Edge e: graph[u]) {\n if (e.f > 0) {\n if (e.t == mfEnd) {\n e.f -= 1;\n return u;\n }\n int ret = dfsDecode(graph, e.t);\n if (ret > 0) {\n e.f -= 1;\n return ret;\n }\n }\n }\n return -1;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n int n = sc.nextInt();\n int m = sc.nextInt();\n interValIndex = n + 1;\n IntervalNode root = new IntervalNode(0, m);\n mfEnd = interValIndex;\n Maxflow mf = new Maxflow(mfEnd + 1);\n baseNodes = new IntervalNode[m];\n dfsAddEdge(mf, root);\n int[][] weapons = new int[n][];\n for (int i = 0; i < n; i++) {\n int type = sc.nextInt();\n if (type == 0) {\n int k = sc.nextInt();\n weapons[i] = new int[k + 1];\n weapons[i][0] = type;\n for (int j = 1; j <= k; j++) {\n weapons[i][j] = sc.nextInt() - 1;\n }\n mf.addEdge(0, i + 1, 1);\n for (int j = 1; j <= k; j++) {\n mf.addEdge(i + 1, baseNodes[weapons[i][j]].index, 1);\n }\n } else if (type == 1) {\n int l = sc.nextInt() - 1;\n int r = sc.nextInt();\n weapons[i] = new int[3];\n weapons[i][0] = type;\n weapons[i][1] = l;\n weapons[i][2] = r;\n mf.addEdge(0, i + 1, 1);\n searchCover(mf, root, l, r, 1 + i);\n } else if (type == 2) {\n int a = sc.nextInt() - 1;\n int b = sc.nextInt() - 1;\n int c = sc.nextInt() - 1;\n weapons[i] = new int[4];\n weapons[i][0] = type;\n weapons[i][1] = a;\n weapons[i][2] = b;\n weapons[i][2] = c;\n mf.addEdge(0, i + 1, 2);\n mf.addEdge(i + 1, baseNodes[a].index, 1);\n mf.addEdge(i + 1, baseNodes[b].index, 1);\n mf.addEdge(i + 1, baseNodes[c].index, 1);\n }\n }\n long flow = mf.maxFLow(0, mfEnd);\n pw.println(flow);\n List[] graph = mf.graph;\n Map toIndex = new HashMap<>();\n for (int i = 0; i < baseNodes.length; i++) {\n toIndex.put(baseNodes[i].index, i);\n }\n toIndex.put(-1, -1);\n int[][] connectTo = new int[n][2];\n for (int i = 0; i < n; i++) {\n connectTo[i][1] = -1;\n connectTo[i][0] = toIndex.get(dfsDecode(graph, i + 1));\n if (weapons[i][0] == 2) connectTo[i][1] = toIndex.get(dfsDecode(graph, i + 1));\n }\n int[] whose = new int[m];\n for (int i = 0; i < n; i++) {\n if (weapons[i][0] != 2 && connectTo[i][0] != -1) {\n whose[connectTo[i][0]] = i;\n }\n }\n for (int i = 0; i < n; i++) {\n if (weapons[i][0] == 2 && connectTo[i][1] == -1) {\n for (int j = 1; j < 4; j++) {\n if (connectTo[i][0] != weapons[i][j]) {\n connectTo[i][1] = weapons[i][j];\n connectTo[whose[weapons[i][j]]][0] = -1;\n break;\n }\n }\n }\n }\n for (int i = 0; i < n; i++) {\n if (connectTo[i][0] >= 0) {\n pw.println((i + 1) + \" \" + (connectTo[i][0] + 1));\n }\n if (connectTo[i][1] >= 0) {\n pw.println((i + 1) + \" \" + (connectTo[i][1] + 1));\n }\n }\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"output\"));\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0652356a3c418f5270a8f0d94b3c778f", "src_uid": "429a94c8e3f28100c8c532e948cc36e3", "difficulty": 2500.0} {"lang": "Java 11", "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 {\r\n\t\tprivate static final long serialVersionUID = 8986468115134862220L;\r\n\t}\r\n\r\n\tpublic static class FastIO {\r\n\t\tprivate InputStream reader;\r\n\t\tprivate PrintWriter writer;\r\n\r\n\t\tprivate byte[] buf = new byte[1024];\r\n\t\tprivate int curChar;\r\n\t\tprivate int numChars;\r\n\r\n\t\tpublic FastIO(InputStream r, OutputStream w) {\r\n\t\t\treader = r;\r\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));\r\n\t\t}\r\n\r\n\t\tpublic int read() {\r\n\t\t\tif (numChars == -1)\r\n\t\t\t\tthrow new InputMismatchException();\r\n\t\t\tif (curChar >= numChars) {\r\n\t\t\t\tcurChar = 0;\r\n\t\t\t\ttry {\r\n\t\t\t\t\tnumChars = reader.read(buf);\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\tthrow new InputMismatchException();\r\n\t\t\t\t}\r\n\t\t\t\tif (numChars <= 0)\r\n\t\t\t\t\treturn -1;\r\n\t\t\t}\r\n\t\t\treturn buf[curChar++];\r\n\t\t}\r\n\r\n\t\tpublic String nextLine() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tStringBuilder res = new StringBuilder();\r\n\t\t\tdo {\r\n\t\t\t\tres.appendCodePoint(c);\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isEndOfLine(c));\r\n\t\t\treturn res.toString();\r\n\t\t}\r\n\r\n\t\tpublic String nextString() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tStringBuilder res = new StringBuilder();\r\n\t\t\tdo {\r\n\t\t\t\tres.appendCodePoint(c);\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn res.toString();\r\n\t\t}\r\n\r\n\t\tpublic long nextLong() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tint sgn = 1;\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = read();\r\n\t\t\t}\r\n\t\t\tlong res = 0;\r\n\t\t\tdo {\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\tthrow new InputMismatchException();\r\n\t\t\t\tres *= 10;\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic int nextInt() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tint sgn = 1;\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = read();\r\n\t\t\t}\r\n\t\t\tint res = 0;\r\n\t\t\tdo {\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\tthrow new InputMismatchException();\r\n\t\t\t\tres *= 10;\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\t// TODO: read this byte-by-byte like the other read functions.\r\n\t\tpublic double nextDouble() {\r\n\t\t\treturn Double.parseDouble(nextString());\r\n\t\t}\r\n\r\n\t\tpublic int[] nextIntArray(int n) {\r\n\t\t\treturn nextIntArray(n, 0);\r\n\t\t}\r\n\r\n\t\tpublic int[] nextIntArray(int n, int off) {\r\n\t\t\tint[] arr = new int[n + off];\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr[i + off] = nextInt();\r\n\t\t\t}\r\n\t\t\treturn arr;\r\n\t\t}\r\n\r\n\t\tpublic long[] nextLongArray(int n) {\r\n\t\t\treturn nextLongArray(n, 0);\r\n\t\t}\r\n\r\n\t\tpublic long[] nextLongArray(int n, int off) {\r\n\t\t\tlong[] arr = new long[n + off];\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr[i + off] = nextLong();\r\n\t\t\t}\r\n\t\t\treturn arr;\r\n\t\t}\r\n\r\n\t\tprivate boolean isSpaceChar(int c) {\r\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n\t\t}\r\n\r\n\t\tprivate boolean isEndOfLine(int c) {\r\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\r\n\t\t}\r\n\r\n\t\tpublic void print(Object... objects) {\r\n\t\t\tfor (int i = 0; i < objects.length; i++) {\r\n\t\t\t\tif (i != 0) {\r\n\t\t\t\t\twriter.print(' ');\r\n\t\t\t\t}\r\n\t\t\t\twriter.print(objects[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void println(Object... objects) {\r\n\t\t\tprint(objects);\r\n\t\t\twriter.println();\r\n\t\t}\r\n\r\n\t\tpublic void printArray(int[] arr) {\r\n\t\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\t\tif (i != 0) {\r\n\t\t\t\t\twriter.print(' ');\r\n\t\t\t\t}\r\n\t\t\t\twriter.print(arr[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void printArray(long[] arr) {\r\n\t\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\t\tif (i != 0) {\r\n\t\t\t\t\twriter.print(' ');\r\n\t\t\t\t}\r\n\t\t\t\twriter.print(arr[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void printlnArray(int[] arr) {\r\n\t\t\tprintArray(arr);\r\n\t\t\twriter.println();\r\n\t\t}\r\n\r\n\t\tpublic void printlnArray(long[] arr) {\r\n\t\t\tprintArray(arr);\r\n\t\t\twriter.println();\r\n\t\t}\r\n\r\n\t\tpublic void printf(String format, Object... args) {\r\n\t\t\tprint(String.format(format, args));\r\n\t\t}\r\n\r\n\t\tpublic void flush() {\r\n\t\t\twriter.flush();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tFastIO io = new FastIO(System.in, System.out);\r\n\t\tsolve(io);\r\n\t\tio.flush();\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6d0acf3064a5cd8f9fa65fe78565ef99", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n static ContestScanner sc = new ContestScanner(System.in);\r\n static PrintWriter pw = new PrintWriter(System.out);\r\n static StringBuilder sb = new StringBuilder();\r\n static long mod = (long) 1e9 + 7;\r\n\r\n public static void main(String[] args) throws Exception {\r\n //int T = sc.nextInt();\r\n //for(int i = 0; i < T; i++)solve();\r\n solve();\r\n pw.flush();\r\n }\r\n \r\n public static void solve() {\r\n int n = sc.nextInt();\r\n Sieve s = new Sieve(n+1);\r\n HashMap modMap = new HashMap<>();\r\n for(int i = 2; i <= n; i++){\r\n modMap.put(i,extGCD.modinv(i,mod));\r\n }\r\n long ans = 0;\r\n for(int c = 1; c <= n-2; c++){\r\n HashSet arr = new HashSet<>();\r\n arr.add(1);\r\n int r = n-c;\r\n int max = (int)Math.sqrt(r)+1;\r\n for(int j = 2; j <= max; j++){\r\n if(r % j == 0){\r\n arr.add(r/j);\r\n arr.add(j);\r\n }\r\n }\r\n for(int d : arr){\r\n HashMap map = s.factor((n-c)/d);\r\n long tmp = (n-c)/d;\r\n for(Map.Entry e : map.entrySet()){\r\n int k = e.getKey();\r\n tmp *= modMap.get(k);\r\n tmp %= mod;\r\n tmp *= (k-1);\r\n tmp %= mod;\r\n }\r\n ans += (lcm(c,d)*tmp)%mod;\r\n ans %= mod;\r\n }\r\n }\r\n pw.println(ans);\r\n }\r\n \r\n private static long gcd(long a, long b)\r\n {\r\n while (b > 0)\r\n {\r\n long temp = b;\r\n b = a % b; // % is remainder\r\n a = temp;\r\n }\r\n return a;\r\n }\r\n \r\n private static long lcm(long a, long b)\r\n {\r\n return a * (b / gcd(a, b));\r\n }\r\n\r\n\r\n static class GeekInteger {\r\n public static void save_sort(int[] array) {\r\n shuffle(array);\r\n Arrays.sort(array);\r\n }\r\n\r\n public static int[] shuffle(int[] array) {\r\n int n = array.length;\r\n Random random = new Random();\r\n for (int i = 0, j; i < n; i++) {\r\n j = i + random.nextInt(n - i);\r\n int randomElement = array[j];\r\n array[j] = array[i];\r\n array[i] = randomElement;\r\n }\r\n return array;\r\n }\r\n\r\n public static void save_sort(long[] array) {\r\n shuffle(array);\r\n Arrays.sort(array);\r\n }\r\n\r\n public static long[] shuffle(long[] array) {\r\n int n = array.length;\r\n Random random = new Random();\r\n for (int i = 0, j; i < n; i++) {\r\n j = i + random.nextInt(n - i);\r\n long randomElement = array[j];\r\n array[j] = array[i];\r\n array[i] = randomElement;\r\n }\r\n return array;\r\n }\r\n\r\n }\r\n}\r\n\r\nclass extGCD {\r\n static long[] extGCD(long a, long b) {\r\n long x = 1, y = 0, u = 0, v = 1, s = a, t = b;\r\n long k = 0, tmp = 0;\r\n while (t > 0) {\r\n k = s / t;\r\n s -= k * t;\r\n {\r\n tmp = s;\r\n s = t;\r\n t = tmp;\r\n }\r\n x -= k * u;\r\n {\r\n tmp = x;\r\n x = u;\r\n u = tmp;\r\n }\r\n y -= k * v;\r\n {\r\n tmp = y;\r\n y = v;\r\n v = tmp;\r\n }\r\n }\r\n return new long[] { x, y };\r\n }\r\n\r\n static long modinv(long a, long mod) {\r\n long x = 1, u = 0, s = a, t = mod;\r\n long k = 0, tmp = 0;\r\n while (t > 0) {\r\n k = s / t;\r\n s -= k * t;\r\n {\r\n tmp = s;\r\n s = t;\r\n t = tmp;\r\n }\r\n x -= k * u;\r\n {\r\n tmp = x;\r\n x = u;\r\n u = tmp;\r\n }\r\n }\r\n x %= mod;\r\n if (x < 0)\r\n x += mod;\r\n return x;\r\n }\r\n}\r\n\r\n\r\n\r\nclass Sieve{\r\n static int n;\r\n static int[] f;\r\n static ArrayList prime;\r\n public Sieve(int n){\r\n long ln = n;\r\n prime = new ArrayList();\r\n f = new int[n+1];\r\n f[0] = f[1] = -1;\r\n for(int i = 2; i <= n; i++){\r\n if(f[i] != 0){\r\n continue;\r\n }\r\n f[i] = i;\r\n prime.add(i);\r\n long li = (long)i;\r\n for(long j = li*li; j <= ln; j += li){\r\n if(f[(int)j] == 0){\r\n f[(int)j] = i;\r\n }\r\n }\r\n }\r\n }\r\n \r\n public static boolean isPrime(int x){\r\n return f[x] == x;\r\n }\r\n \r\n public static ArrayList factorList(int x){\r\n ArrayList res = new ArrayList();\r\n while(x != 1){\r\n res.add(f[x]);\r\n x /= f[x];\r\n }\r\n return res;\r\n }\r\n \r\n public static HashMap factor(int x){\r\n ArrayList fl = factorList(x);\r\n HashMap res = new HashMap();\r\n if(fl.size()==0){\r\n return new HashMap();\r\n }\r\n int prev = fl.get(0);\r\n int cnt = 0;\r\n for(int p : fl){\r\n if(prev == p){\r\n cnt++;\r\n }else{\r\n res.put(prev,cnt);\r\n prev = p;\r\n cnt = 1;\r\n }\r\n }\r\n res.put(prev,cnt);\r\n return res;\r\n }\r\n}\r\n\r\n/**\r\n * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java\r\n */\r\nclass ContestScanner {\r\n private final java.io.InputStream in;\r\n private final byte[] buffer = new byte[1024];\r\n private int ptr = 0;\r\n private int buflen = 0;\r\n\r\n private static final long LONG_MAX_TENTHS = 922337203685477580L;\r\n private static final int LONG_MAX_LAST_DIGIT = 7;\r\n private static final int LONG_MIN_LAST_DIGIT = 8;\r\n\r\n public ContestScanner(java.io.InputStream in){\r\n this.in = in;\r\n }\r\n public ContestScanner(java.io.File file) throws java.io.FileNotFoundException {\r\n this(new java.io.BufferedInputStream(new java.io.FileInputStream(file)));\r\n }\r\n public ContestScanner(){\r\n this(System.in);\r\n }\r\n \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 (java.io.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() { \r\n if (hasNextByte()) return buffer[ptr++]; else return -1;\r\n }\r\n private static boolean isPrintableChar(int c) {\r\n return 33 <= c && c <= 126;\r\n }\r\n public boolean hasNext() {\r\n while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;\r\n return hasNextByte();\r\n }\r\n public String next() {\r\n if (!hasNext()) throw new java.util.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 \r\n public long nextLong() {\r\n if (!hasNext()) throw new java.util.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 int digit = b - '0';\r\n if (n >= LONG_MAX_TENTHS) {\r\n if (n == LONG_MAX_TENTHS) {\r\n if (minus) {\r\n if (digit <= LONG_MIN_LAST_DIGIT) {\r\n n = -n * 10 - digit;\r\n b = readByte();\r\n if (!isPrintableChar(b)) {\r\n return n;\r\n } else if (b < '0' || '9' < b) {\r\n throw new NumberFormatException(\r\n String.format(\"%d%s... is not number\", n, Character.toString(b))\r\n );\r\n }\r\n }\r\n } else {\r\n if (digit <= LONG_MAX_LAST_DIGIT) {\r\n n = n * 10 + digit;\r\n b = readByte();\r\n if (!isPrintableChar(b)) {\r\n return n;\r\n } else if (b < '0' || '9' < b) {\r\n throw new NumberFormatException(\r\n String.format(\"%d%s... is not number\", n, Character.toString(b))\r\n );\r\n }\r\n }\r\n }\r\n }\r\n throw new ArithmeticException(\r\n String.format(\"%s%d%d... overflows long.\", minus ? \"-\" : \"\", n, digit)\r\n );\r\n }\r\n n = n * 10 + digit;\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 long nl = nextLong();\r\n if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();\r\n return (int) nl;\r\n }\r\n public double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n \r\n public long[] nextLongArray(int length){\r\n long[] array = new long[length];\r\n for(int i=0; i modMap = new HashMap<>();\r\n for(int i = 2; i <= n; i++){\r\n modMap.put(i,extGCD.modinv(i,mod));\r\n }\r\n long ans = 0;\r\n for(int c = 1; c <= n-2; c++){\r\n HashSet arr = new HashSet<>();\r\n int r = n-c;\r\n int max = (int)Math.sqrt(r)+1;\r\n for(int j = 1; j <= max; j++){\r\n if(r % j == 0){\r\n arr.add(r/j);\r\n arr.add(j);\r\n }\r\n }\r\n for(int d : arr){\r\n if(d == n-c) continue;\r\n HashMap map = s.factor((n-c)/d);\r\n long tmp = (n-c)/d;\r\n for(Map.Entry e : map.entrySet()){\r\n int k = e.getKey();\r\n tmp *= (k-1)*modMap.get(k);\r\n tmp %= mod;\r\n }\r\n ans += (lcm(c,d)*tmp)%mod;\r\n ans %= mod;\r\n }\r\n }\r\n pw.println(ans);\r\n }\r\n \r\n private static long gcd(long a, long b)\r\n {\r\n while (b > 0)\r\n {\r\n long temp = b;\r\n b = a % b; // % is remainder\r\n a = temp;\r\n }\r\n return a;\r\n }\r\n \r\n private static long lcm(long a, long b)\r\n {\r\n return a * (b / gcd(a, b));\r\n }\r\n\r\n\r\n static class GeekInteger {\r\n public static void save_sort(int[] array) {\r\n shuffle(array);\r\n Arrays.sort(array);\r\n }\r\n\r\n public static int[] shuffle(int[] array) {\r\n int n = array.length;\r\n Random random = new Random();\r\n for (int i = 0, j; i < n; i++) {\r\n j = i + random.nextInt(n - i);\r\n int randomElement = array[j];\r\n array[j] = array[i];\r\n array[i] = randomElement;\r\n }\r\n return array;\r\n }\r\n\r\n public static void save_sort(long[] array) {\r\n shuffle(array);\r\n Arrays.sort(array);\r\n }\r\n\r\n public static long[] shuffle(long[] array) {\r\n int n = array.length;\r\n Random random = new Random();\r\n for (int i = 0, j; i < n; i++) {\r\n j = i + random.nextInt(n - i);\r\n long randomElement = array[j];\r\n array[j] = array[i];\r\n array[i] = randomElement;\r\n }\r\n return array;\r\n }\r\n\r\n }\r\n}\r\n\r\nclass extGCD {\r\n static long[] extGCD(long a, long b) {\r\n long x = 1, y = 0, u = 0, v = 1, s = a, t = b;\r\n long k = 0, tmp = 0;\r\n while (t > 0) {\r\n k = s / t;\r\n s -= k * t;\r\n {\r\n tmp = s;\r\n s = t;\r\n t = tmp;\r\n }\r\n x -= k * u;\r\n {\r\n tmp = x;\r\n x = u;\r\n u = tmp;\r\n }\r\n y -= k * v;\r\n {\r\n tmp = y;\r\n y = v;\r\n v = tmp;\r\n }\r\n }\r\n return new long[] { x, y };\r\n }\r\n\r\n static long modinv(long a, long mod) {\r\n long x = 1, u = 0, s = a, t = mod;\r\n long k = 0, tmp = 0;\r\n while (t > 0) {\r\n k = s / t;\r\n s -= k * t;\r\n {\r\n tmp = s;\r\n s = t;\r\n t = tmp;\r\n }\r\n x -= k * u;\r\n {\r\n tmp = x;\r\n x = u;\r\n u = tmp;\r\n }\r\n }\r\n x %= mod;\r\n if (x < 0)\r\n x += mod;\r\n return x;\r\n }\r\n}\r\n\r\n\r\n\r\nclass Sieve{\r\n static int n;\r\n static int[] f;\r\n static ArrayList prime;\r\n public Sieve(int n){\r\n long ln = n;\r\n prime = new ArrayList();\r\n f = new int[n+1];\r\n f[0] = f[1] = -1;\r\n for(int i = 2; i <= n; i++){\r\n if(f[i] != 0){\r\n continue;\r\n }\r\n f[i] = i;\r\n prime.add(i);\r\n long li = (long)i;\r\n for(long j = li*li; j <= ln; j += li){\r\n if(f[(int)j] == 0){\r\n f[(int)j] = i;\r\n }\r\n }\r\n }\r\n }\r\n \r\n public static boolean isPrime(int x){\r\n return f[x] == x;\r\n }\r\n \r\n public static ArrayList factorList(int x){\r\n ArrayList res = new ArrayList();\r\n while(x != 1){\r\n res.add(f[x]);\r\n x /= f[x];\r\n }\r\n return res;\r\n }\r\n \r\n public static HashMap factor(int x){\r\n ArrayList fl = factorList(x);\r\n HashMap res = new HashMap();\r\n if(fl.size()==0){\r\n return new HashMap();\r\n }\r\n int prev = fl.get(0);\r\n int cnt = 0;\r\n for(int p : fl){\r\n if(prev == p){\r\n cnt++;\r\n }else{\r\n res.put(prev,cnt);\r\n prev = p;\r\n cnt = 1;\r\n }\r\n }\r\n res.put(prev,cnt);\r\n return res;\r\n }\r\n}\r\n\r\n/**\r\n * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java\r\n */\r\nclass ContestScanner {\r\n private final java.io.InputStream in;\r\n private final byte[] buffer = new byte[1024];\r\n private int ptr = 0;\r\n private int buflen = 0;\r\n\r\n private static final long LONG_MAX_TENTHS = 922337203685477580L;\r\n private static final int LONG_MAX_LAST_DIGIT = 7;\r\n private static final int LONG_MIN_LAST_DIGIT = 8;\r\n\r\n public ContestScanner(java.io.InputStream in){\r\n this.in = in;\r\n }\r\n public ContestScanner(java.io.File file) throws java.io.FileNotFoundException {\r\n this(new java.io.BufferedInputStream(new java.io.FileInputStream(file)));\r\n }\r\n public ContestScanner(){\r\n this(System.in);\r\n }\r\n \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 (java.io.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() { \r\n if (hasNextByte()) return buffer[ptr++]; else return -1;\r\n }\r\n private static boolean isPrintableChar(int c) {\r\n return 33 <= c && c <= 126;\r\n }\r\n public boolean hasNext() {\r\n while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;\r\n return hasNextByte();\r\n }\r\n public String next() {\r\n if (!hasNext()) throw new java.util.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 \r\n public long nextLong() {\r\n if (!hasNext()) throw new java.util.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 int digit = b - '0';\r\n if (n >= LONG_MAX_TENTHS) {\r\n if (n == LONG_MAX_TENTHS) {\r\n if (minus) {\r\n if (digit <= LONG_MIN_LAST_DIGIT) {\r\n n = -n * 10 - digit;\r\n b = readByte();\r\n if (!isPrintableChar(b)) {\r\n return n;\r\n } else if (b < '0' || '9' < b) {\r\n throw new NumberFormatException(\r\n String.format(\"%d%s... is not number\", n, Character.toString(b))\r\n );\r\n }\r\n }\r\n } else {\r\n if (digit <= LONG_MAX_LAST_DIGIT) {\r\n n = n * 10 + digit;\r\n b = readByte();\r\n if (!isPrintableChar(b)) {\r\n return n;\r\n } else if (b < '0' || '9' < b) {\r\n throw new NumberFormatException(\r\n String.format(\"%d%s... is not number\", n, Character.toString(b))\r\n );\r\n }\r\n }\r\n }\r\n }\r\n throw new ArithmeticException(\r\n String.format(\"%s%d%d... overflows long.\", minus ? \"-\" : \"\", n, digit)\r\n );\r\n }\r\n n = n * 10 + digit;\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 long nl = nextLong();\r\n if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();\r\n return (int) nl;\r\n }\r\n public double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n \r\n public long[] nextLongArray(int length){\r\n long[] array = new long[length];\r\n for(int i=0; i= '0' && c <= '9');\r\n \r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n \r\n public long nextLong() throws IOException\r\n {\r\n long ret = 0;\r\n byte c = read();\r\n while (c <= ' ')\r\n c = read();\r\n boolean neg = (c == '-');\r\n if (neg)\r\n c = read();\r\n do {\r\n ret = ret * 10 + c - '0';\r\n } while ((c = read()) >= '0' && c <= '9');\r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n \r\n public double nextDouble() throws IOException\r\n {\r\n double ret = 0, div = 1;\r\n byte c = read();\r\n while (c <= ' ')\r\n c = read();\r\n boolean neg = (c == '-');\r\n if (neg)\r\n c = read();\r\n \r\n do {\r\n ret = ret * 10 + c - '0';\r\n } while ((c = read()) >= '0' && c <= '9');\r\n \r\n if (c == '.') {\r\n while ((c = read()) >= '0' && c <= '9') {\r\n ret += (c - '0') / (div *= 10);\r\n }\r\n }\r\n \r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n \r\n private void fillBuffer() throws IOException\r\n {\r\n bytesRead = din.read(buffer, bufferPointer = 0,\r\n BUFFER_SIZE);\r\n if (bytesRead == -1)\r\n buffer[0] = -1;\r\n }\r\n \r\n private byte read() throws IOException\r\n {\r\n if (bufferPointer == bytesRead)\r\n fillBuffer();\r\n return buffer[bufferPointer++];\r\n }\r\n \r\n public void close() throws IOException\r\n {\r\n if (din == null)\r\n return;\r\n din.close();\r\n }\r\n }\r\n \r\n public static long gcd(long a, long b)\r\n {\r\n if (a == 0)\r\n return b;\r\n \r\n return gcd(b % a, a);\r\n }\r\n \r\n \r\n public static void main(String []args) throws IOException\r\n {\r\n \r\n Reader sc = new Reader();\r\n int n = sc.nextInt();\r\n \r\n \r\n long phi[] = new long[n + 1]; \r\n for (int i = 1; i <= n; i++) \r\n phi[i] = i; // indicates not evaluated yet \r\n // and initializes for product \r\n // formula. \r\n \r\n // Compute other Phi values \r\n for (int p = 2; p <= n; p++) { \r\n \r\n // If phi[p] is not computed already, \r\n // then number p is prime \r\n if (phi[p] == p) { \r\n \r\n // Phi of a prime number p is \r\n // always equal to p-1. \r\n phi[p] = p - 1; \r\n \r\n // Update phi values of all \r\n // multiples of p \r\n for (int i = 2 * p; i <= n; i += p) { \r\n \r\n // Add contribution of p to its \r\n // multiple i by multiplying with \r\n // (1 - 1/p) \r\n phi[i] = (phi[i] / p) * (p - 1); \r\n } \r\n } \r\n } \r\n \r\n long ans = 0;\r\n long mod = 1000000007;\r\n for(int c = 1 ; c <= n-2 ; c++)\r\n {\r\n int sum = n-c;\r\n for(int j = 1 ; j <= (int)Math.sqrt(sum) ; j++)\r\n {\r\n if(sum%j == 0)\r\n {\r\n int xx = sum/j;\r\n long lc = (long)c*(long)j/(gcd(c,j));\r\n \r\n ans += lc*phi[xx]%mod;\r\n ans %= mod;\r\n }\r\n }\r\n }\r\n System.out.println(ans);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a259864a55be0c91d276e9189faed53e", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\r\n\r\npublic class B {\r\n public static void main(String[] args) {\r\n Scanner s = new Scanner(System.in);\r\n int x = s.nextInt()L\r\n System.out.println(2 - (x * x));\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a7ea51c8177333318e78ec34a8c75f1c", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\npublic class math {\r\n public static void main(String args[]);\r\n Scanner sc = new Scanner(System.in);\r\n int n = sc.nextInt();\r\n System.out.println((int)Math.pow(n , 2) - (2 * n));\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "54c4368c4571f483f1fb2507208183df", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\npublic class math {\r\n public static void main(String args[]);\r\n Scanner sc = new Scanner(System.in);\r\n int n = sc.nextInt();\r\n System.out.println(2 - n * n);\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "621607c47204e5459c12825504f9aded", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\npublic class math {\r\n public static void main(String args[]);\r\n Scanner sc = new Scanner(System.in);\r\n int n = sc.nextInt();\r\n System.out.println(2-n*n);\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f336f805904ea39fd407920f03ea7a18", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tpublic static void main(String args[]) throws IOException{\n\t\tnew Main().mains();\n\t}\n\tpublic int m,n,H[],tot[],ans,x[],y[],tim[];\n\t\n\tvoid push(int a, int b){\n\t\tx[++ ans] = a;\n\t\ty[ans] = b;\n\t}\n\t\n\tvoid easy_move(int a, int b, int c, int bottom){\n\t\tif (bottom == n + 1) return;\n\t\teasy_move(a, c, b, bottom + 1);\n\t\tfor (int i = 1; i <= tot[bottom]; i ++)\n\t\t\tpush(a, c);\n\t\teasy_move(b, a, c, bottom + 1);\n\t}\n\t\n\tvoid solve(int a, int b, int c, int bottom, boolean flag){\n\t\tif (bottom == n + 1) return;\n\t\tif (tot[bottom] == 1){\n\t\t\teasy_move(a, c, b, bottom + 1);\n\t\t\tpush(a, c);\n\t\t\tsolve(b, a, c, bottom + 1, true);\n\t\t\treturn;\n\t\t}\n\t\tif (flag == true){\n\t\t\teasy_move(a, c, b, bottom + 1);\n\t\t\tfor (int i = 1; i <= tot[bottom]; i ++)\n\t\t\t\tpush(a, c);\n\t\t\tsolve(b, a, c, bottom + 1, true);\n\t\t} else {\n\t\t\tif (bottom == n){\n\t\t\t\tfor (int i = 1; i <= tot[bottom] - 1; i ++)\n\t\t\t\t\tpush(a, b);\n\t\t\t\tpush(a, c);\n\t\t\t\tfor (int i = 1; i <= tot[bottom] - 1; i ++)\n\t\t\t\t\tpush(b, c);\n\t\t\t} else {\n\t\t\t\teasy_move(a, b, c, bottom + 1);\n\t\t\t\tfor (int i = 1; i <= tot[bottom]; i ++)\n\t\t\t\t\tpush(a, b);\n\t\t\t\teasy_move(c, b, a, bottom + 1);\n\t\t\t\tfor (int i = 1; i <= tot[bottom]; i ++)\n\t\t\t\t\tpush(b, c);\n\t\t\t\tsolve(a, b, c, bottom + 1, false);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic void solve() throws IOException{\n\t\tm = nextInt();\n\t\tH = new int[100];\n\t\ttot = new int[100];\n\t\tx = new int[1000000];\n\t\ttim = new int[100];\n\t\ty = new int[1000000];\n\t\tfor (int i = 1; i <= m; i ++){\n\t\t\tint k = nextInt();\n\t\t\tif (k != H[n]){\n\t\t\t\tH[++ n] = k;\n\t\t\t}\n\t\t\ttot[n] ++;\n\t\t}\n\t\tfor (int i = n; i > 0; i --)\n\t\t\ttim[i] = tim[i + 1] * 2 + tot[i];\n\t\tsolve(1, 2, 3, 1, false);\n\t\tout.println(ans);\n\t\tfor (int i = 1; i <= ans; i ++)\n\t\t\tout.println(x[i] + \" \" + y[i]);\n\t}\n\t\n\tvoid mains() throws IOException{\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\ttokenizer = null;\n\t\t//File fin = new File(\"a.in\");\n\t\t//reader = new BufferedReader(new InputStreamReader(new FileInputStream(fin)));\n\t\t//out = new PrintWriter(\"a.out\");\n\t\tsolve();\n\t\treader.close();\n\t\tout.flush();\n\t}\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString 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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "18470c15f6684bade17f9f83dbdcf9ed", "src_uid": "4ea4ad10ef422a9cd45b8a7b25d359c5", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tpublic static void main(String args[]) throws IOException{\n\t\tnew Main().mains();\n\t}\n\tpublic int m,n,H[],tot[],ans,x[],y[];\n\t\n\tvoid push(int a, int b){\n\t\tx[++ ans] = a;\n\t\ty[ans] = b;\n\t}\n\t\n\tvoid easy_move(int a, int b, int c, int bottom){\n\t\tif (bottom == n + 1) return;\n\t\teasy_move(a, c, b, bottom + 1);\n\t\tfor (int i = 1; i <= tot[bottom]; i ++)\n\t\t\tpush(a, c);\n\t\teasy_move(b, a, c, bottom + 1);\n\t}\n\t\n\tvoid solve(int a, int b, int c, int bottom, boolean flag){\n\t\tif (bottom == n + 1) return;\n\t\tif (tot[bottom] == 1){\n\t\t\teasy_move(a, c, b, bottom + 1);\n\t\t\tpush(a, c);\n\t\t\tsolve(b, a, c, bottom + 1, true);\n\t\t\treturn;\n\t\t}\n\t\tif (flag == true){\n\t\t\teasy_move(a, c, b, bottom + 1);\n\t\t\tfor (int i = 1; i <= tot[bottom]; i ++)\n\t\t\t\tpush(a, c);\n\t\t\tsolve(b, a, c, bottom + 1, true);\n\t\t} else {\n\t\t\teasy_move(a, b, c, bottom + 1);\n\t\t\tfor (int i = 1; i <= tot[bottom] - 1; i ++)\n\t\t\t\tpush(a, b);\n\t\t\teasy_move(c, a, b, bottom + 1);\n\t\t\tpush(a, c);\n\t\t\teasy_move(b, c, a, bottom + 1);\n\t\t\tfor (int i = 1; i <= tot[bottom] - 1; i ++)\n\t\t\t\tpush(b, c);\n\t\t\tsolve(a, b, c, bottom + 1, true);\n\t\t}\n\t}\n\t\n\tpublic void solve() throws IOException{\n\t\tm = nextInt();\n\t\tH = new int[100];\n\t\ttot = new int[100];\n\t\tx = new int[1000000];\n\t\ty = new int[1000000];\n\t\tfor (int i = 1; i <= m; i ++){\n\t\t\tint k = nextInt();\n\t\t\tif (k != H[n]){\n\t\t\t\tH[++ n] = k;\n\t\t\t}\n\t\t\ttot[n] ++;\n\t\t}\n\t\tsolve(1, 2, 3, 1, false);\n\t\tout.println(ans);\n\t\tfor (int i = 1; i <= ans; i ++)\n\t\t\tout.println(x[i] + \" \" + y[i]);\n\t}\n\t\n\tvoid mains() throws IOException{\n\t\t//reader = new BufferedReader(new InputStreamReader(System.in));\n\t\t//out = new PrintWriter(new OutputStreamWriter(System.out));\n\t\ttokenizer = null;\n\t\tFile fin = new File(\"a.in\");\n\t\treader = new BufferedReader(new InputStreamReader(new FileInputStream(fin)));\n\t\tout = new PrintWriter(\"a.out\");\n\t\tsolve();\n\t\treader.close();\n\t\tout.flush();\n\t}\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString 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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9c37e35a9b8f2fb716945b23175377c", "src_uid": "4ea4ad10ef422a9cd45b8a7b25d359c5", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.*;\n\npublic class Main\n{\t\n\tpublic BufferedReader in;\n\tpublic PrintStream out;\n\t\n\tint[] disks;\n\tint K;\n\t\n\tpublic long calc(int from, boolean keep_order)\n\t{\n\t\tif (from==K)\n\t\t{\n\t\t\treturn keep_order ? 2*disks[K]-1 : disks[K];\n\t\t}\n\t\t\n\t\tif (disks[from]==1)\n\t\t{\n\t\t\treturn 1+2*calc(from+1, false);\n\t\t}\n\t\t\n\t\treturn keep_order \n\t\t\t? 2*calc(from+1, false) + calc(from+1, true) + 2*disks[from] \n\t\t\t: 2*calc(from+1, false) + disks[from] ;\n\t}\n\t\n\tpublic void print_move(int from, int to, int k)\n\t{\n\t\tfor (int i=0; i a = new ArrayList();\n List b = new ArrayList();\n \n void move(int from, int to) {\n pegs[to].put(pegs[from].take());\n a.add(from);\n b.add(to);\n }\n \n void solveWhatever(int from, int to, int maxSize) {\n int startPos = 0;\n while (pegs[from].data[startPos] > maxSize) startPos++;\n \n int spare = 6 - from - to;\n int nextPos = startPos + 1;\n while (nextPos < pegs[from].cnt && pegs[from].data[nextPos] == pegs[from].data[startPos])\n nextPos++;\n int cnt = nextPos - startPos;\n if (nextPos == pegs[from].cnt) {\n for (int i=0; i maxSize) startPos++;\n \n int spare = 6 - from - to;\n int nextPos = startPos + 1;\n while (nextPos < pegs[from].cnt && pegs[from].data[nextPos] == pegs[from].data[startPos])\n nextPos++;\n int cnt = nextPos - startPos;\n if (nextPos == pegs[from].cnt) {\n for (int i=0; i 0)\n\t\t\tadd--;\n}\nelse{\n\tadd++\n}\n}\nSystem.out.println(add);\n}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6a902925de27951f11b91c85527b498d", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n\t\n\t\n\timport java.io.BufferedReader;\n\timport java.io.IOException;\n\timport java.io.InputStreamReader;\n\timport java.io.PrintWriter;\n\timport java.math.BigInteger;\n\timport java.util.*;\n\t\n\t\n\tpublic class usd {\n\t\t\n\t\tstatic int r=0;static int c=0;\n\t\tstatic void fillzero(int a[][],int n)\n\t\t{\n\t\t\tfor(int i=0;imap=new TreeMap();\n\t\tArrayListst1=new ArrayList();\n\t\tArrayListst2222=new ArrayList();\n\t\tStackst12=new Stack();\n\t\tStackst2=new Stack();\n\t\tint n=in.nextInt();\n\tString s=in.next();\n\twhile(s.indexOf(\"-\")==0)\n\t\ts=s.substring(1);\n\t\tint ct=0;\n\t\tfor(int i=0;i 0)\n\t\t\tadd--;\n }\n else{\n\t add++;\n }\n }\n System.out.println(add);\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5aac68f042731ebfd49bfd6eda7a56ec", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Main \n{\n public static void main(String args[])\n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int a=s.nextInt();\n int b=s.nextInt();\n int c=s.nextInt();\n int i,j,k;\n int res=0;\n for (i = 0; i <= c; i++) {\n for (j = 0; j <= b; j++) {\n int k = 2*n - 4*i - 2*j;\n if (0 <= k && k <= a) ans++;\n }\n }\n System.out.println(res);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fc6ad31311f8c1ca8ad6223a4a44f5c5", "src_uid": "474e527d41040446a18186596e8bdd83", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Main \n{\n public static void main(String args[])\n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int a=s.nextInt();\n int b=s.nextInt();\n int c=s.nextInt();\n int i,j,k;\n int res=0;\n for (i = 0; i <= c; i++) {\n for (j = 0; j <= b; j++) {\n int k = 2*n - 4*i - 2*j;\n if (0 <= k && k <= a) res++;\n }\n }\n System.out.println(res);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1a47d58e527e6f1b2b4caee5a7149eb0", "src_uid": "474e527d41040446a18186596e8bdd83", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author madi\n */\npublic class Round44B {\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 int c = sc.nextInt();\n\n long count = 0;\n for (int i = 0; i <= a; i++) {\n for (int j = 0; j <= b; j++) {\n for (int k = 0; k <= c; k++) {\n if (i + 2 * j + 4 * k == 2 * n) {\n count++;\n }\n if (i + 2 * j + 4 * k > 2 * n) {\n break;\n }\n }\n if (i + 2 * j > 2 * n) {\n break;\n }\n }\n if (i > 2 * n) {\n break;\n }\n }\n\n System.out.println(count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "adb5b4ad58aad1463e0375c0d10dcca3", "src_uid": "474e527d41040446a18186596e8bdd83", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Zyflair Griffane\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tPandaScanner in = new PandaScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tB solver = new B();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass B {\n public void solve(int testNumber, PandaScanner in, PrintWriter out) {\n int n = in.nextInt() << 1;\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n long[] ways = new long[40000];\n for (int i = 0; i <= a; i++) {\n ways[i] = 1;\n }\n for (int i = n; i >= 0; i--) {\n for (int j = 1; j <= b; j++) {\n ways[i + j * 2] += ways[i];\n }\n }\n for (int i = n; i >= 0; i--) {\n for (int j = 1; j <= c; j++) {\n ways[i + j * 4] += ways[i];\n }\n }\n out.println(ways[n]);\n }\n}\n\nclass PandaScanner {\n public BufferedReader br;\n public StringTokenizer st;\n public InputStream in;\n\n public PandaScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(this.in = in));\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n }\n catch (Exception e) {\n return null;\n }\n }\n\n public String next() {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine().trim());\n return next();\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4798e108186df62f27a9f36a8e87158d", "src_uid": "474e527d41040446a18186596e8bdd83", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\nimport java.util.List;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Arrays;\n\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(in, out);\n out.close();\n }\n \n static class Task {\n \t public void solve(InputReader in, PrintWriter out) {\n \t\t int m = in.nextInt();\n \t\t int n = in.nextInt();\n \t\t if (m == 1 || n == 1) {\n \t\t\t int a = Math.max(m, n);\n \t\t\t if (a % 6 < 4)\n \t\t\t\t out.println(a - (a % 4));\n \t\t\t else\n \t\t\t\t out.println(a + (a % 4) - 6);\n \t\t }\n \t\t else if (m == 2 || n == 2) {\n \t\t\t int a = Math.max(m, n);\n \t\t\t if (a == 2)\n \t\t\t\t out.println(0);\n \t\t\t else if (a == 3)\n \t\t\t\t out.println(4);\n \t\t\t else if (a == 7)\n \t\t\t\t out.println(12);\n \t\t\t else\n \t\t\t\t out.println(a*2);\n \t\t }\n \t\t else if (m*n % 2 == 0)\n \t\t\tout.println(m*n);\n \t\t else\n \t\t\tout.println(m*n - 1);\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 long nextLong() {\n \treturn Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "94b67785f7e45bcc3030a0e1aa0a64e3", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.regex.Pattern;\npublic class Stub {\npublic static void main(String[] args) {\nScanner in = new Scanner(System.in);\nint n = in.nextInt(); //\nint m = in.nextInt();\nint out = 0;\nif (n+m < 5) {\n System.out.println(\"0\"); // too small\n} else {\n if (n==1 || m==1) {\n int l = n+m-1;\n int x = l/6;\n int y = 0;\n if (l%6 = 4) y+= 2;\n if (l%6 = 5) y += 4;\n out = x*6 + y;\n System.out.println(out);\n return;\n }\n}\nout = (n+m=5)?4:(n*m)%2;\n\nSystem.out.println(out); //\n} // end main\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e5738b49110523fa85d5a551db443b92", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class littleCloves3II {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n long n=sc.nextInt();\n long m=sc.nextInt();\n if(n()\n\t\t\t\t{\n\t\t\tpublic int compare(int[]a,int[]b)\n\t\t\t{\n\t\t\t\tif(a[0]>b[0])\n\t\t\t\t\treturn 1;\n\t\t\t\tif(a[0]0)\n\t\t{\n\t\t\ta>>=1;\n\t\t\t++te;\n\t\t}\n\t\treturn te;\n\t}\n\tstatic class vectorl implements Iterable\n\t{\n\t\tlong a[];\n\t\tint size;\n\t\tvectorl(){a=new long[10];size=0;}\n\t\tvectorl(int n){a=new long[n];size=0;}\n\t\tpublic void add(long b){if(++size==a.length)a=Arrays.copyOf(a, 2*size);a[size-1]=b;}\n\t\tpublic void sort(){Arrays.sort(a, 0, size);}\n\t\tpublic void sort(int l, int r){Arrays.sort(a, l, r);}\n\t\t@Override\n\t\tpublic Iterator iterator() {\n\t\t\tIterator hola=new Iterator()\n\t\t\t\t\t{\n\t\t\t\tint cur=0;\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic boolean hasNext() {\n\t\t\t\t\t\t\treturn cur\n\t{\n\t\tint a[],size;\n\t\tvector(){a=new int[10];}\n\t\tvector(int n){a=new int[n];}\n\t\tpublic void add(int b){if(++size==a.length)a=Arrays.copyOf(a, 2*size);a[size-1]=b;}\n\t\tpublic void sort(){Arrays.sort(a, 0, size);}\n\t\tpublic void sort(int l, int r){Arrays.sort(a, l, r);}\n\t\t@Override\n\t\tpublic Iterator iterator() {\n\t\t\tIterator hola=new Iterator()\n\t\t\t\t\t{\n\t\t\t\tint cur=0;\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic boolean hasNext() {\n\t\t\t\t\t\t\treturn cur>>1);\n\t\t\t}\n\t\t\ta[(head-1)&(a.length-1)]=i;\n\t\t}\n\t\tint poll()\n\t\t{\n\t\t\ttail=(tail+1)&(a.length-1);\n\t\t\treturn a[(tail-1)&(a.length-1)];\n\t\t}\n\t\tboolean notempty()\n\t\t{\n\t\t\treturn head!=tail;\n\t\t}\n\t}\n\tstatic void exit(){System.out.print(output);System.exit(0);}\n\tstatic int min(int... a){int min=a[0];for(int i:a)min=Math.min(min, i);return min;}\n\tstatic int max(int... a){int max=a[0];for(int i:a)max=Math.max(max, i);return max;}\t\n\tstatic int gcd(int... a){int gcd=a[0];for(int i:a)gcd=gcd(gcd, i);return gcd;}\t\n\tstatic long min(long... a){long min=a[0];for(long i:a)min=Math.min(min, i);return min;}\n\tstatic long max(long... a){long max=a[0];for(long i:a)max=Math.max(max, i);return max;}\t\n\tstatic long gcd(long... a){long gcd=a[0];for(long i:a)gcd=gcd(gcd, i);return gcd;}\t\n\tstatic String pr(String a, long b){String c=\"\";while(b>0){if(b%2==1)c=c.concat(a);a=a.concat(a);b>>=1;}return c;}\n\tstatic long powm(long a, long b, long mod2){long an=1;long c=a%mod2;while(b>0){if(b%2==1)an=(an*c)%mod2;c=(c*c)%mod2;b>>=1;}return an;}\n\tstatic long pow(long a, long b){long an=1;long c=a;while(b>0){if(b%2==1)an*=c;c*=c;b>>=1;}return an;}\n\tstatic int gcd(int a, int b){if(b==0)return a;return gcd(b, a%b);}\n\tstatic long gcd(long a, long b){if(b==0)return a;return gcd(b, a%b);}\n\tstatic class Reader{\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public Reader() {\n reader = new BufferedReader(new InputStreamReader(System.in));\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 }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bea7c2a9b929e04513ec129ea326ab81", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class tshirt\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int p = sc.nextInt() - 26;\n int x = sc.nextInt();\n int y = sc.nextInt();\n int i;\n int count = 0;\n if (x%50 >= y%50)\n {\n i = (y/50)%475;\n }\n else\n {\n i = (y/50 + 1)%475;\n }\n if (x < y)\n {\n if (x%50 == y%50)\n count += (y-x)/50;\n else\n count += (y-x)/50 + 1;\n }\n for (int j = 0; j < 475; j++)\n {\n temp = i;\n for (int k = 0; k < 25; k++)\n {\n temp = (temp*96+42)%475;\n if (temp == p)\n {\n if (count%2 == 0)\n System.out.println(count/2);\n else\n System.out.println(count/2 + 1)\n System.exit(0);\n }\n }\n i = (i+1)%475;\n count++;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67529b77cc32209bdccf65007083ee28", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "package com.arthur.gazizov.main;\n\nimport com.arthur.gazizov.io.InputReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class TaskB {\n// i := (s div 50) mod 475\n// repeat 25 times:\n// i := (i * 96 + 42) mod 475\n// print (26 + i)\n List generate(int s){\n List ret = new ArrayList<>(25);\n int i = (s / 50) % 475;\n for (int j = 0; j < 25; j++) {\n i = (i * 96 + 42) % 475;\n ret.add(i + 26);\n }\n return ret;\n }\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int p = in.readInt();\n int points = in.readInt();\n int toWin = in.readInt();\n int min = Integer.MAX_VALUE;\n for (int i = toWin; i <= 200000; i++) {\n List generate = generate(i);\n if (generate.contains(p)){\n int diff = Math.abs(i - points);\n int tmp = Integer.MAX_VALUE;\n if (diff % 50 == 0){\n if (i > points){\n tmp = (i - points + 50) / 100;\n } else {\n tmp = 0;\n }\n }\n min = Math.min(min, tmp);\n }\n }\n out.print(min);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f1b25b3dea8c91a172a35047e1be8ffb", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class tshirt\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int p = sc.nextInt() - 26;\n int x = sc.nextInt();\n int y = sc.nextInt();\n int i;\n int count = 0;\n if (x%50 >= y%50)\n {\n i = (y/50)%475;\n }\n else\n {\n i = (y/50 + 1)%475;\n }\n if (x < y)\n {\n if (x%50 == y%50)\n count += (y-x)/50;\n else\n count += (y-x)/50 + 1;\n }\n for (int j = 0; j < 475; j++)\n {\n temp = i;\n for (int k = 0; k < 25; k++)\n {\n temp = (temp*96+42)%475;\n if (temp == p)\n {\n if (count%2 == 0)\n System.out.println(count/2);\n else\n System.out.println(count/2 + 1);\n System.exit(0);\n }\n }\n i = (i+1)%475;\n count++;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4df07d26ce2488f8ea3bad1b82689735", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\t\n\t\n\n\t\n\tpublic static void main(String [] args) {\n\t\t\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tint p = scan.nextInt();\n\t\tint x = scan.nextInt();\n\t\tint y = scan.nextInt();\n\t\t\n\t\t\n\t\tif(case1(p,x, y))\n\t\t\tSystem.out.println(0);\n\t\telse {\n\t\t\tSystem.out.println((int)Math.ceil(case2(p,x,y)/2.0));\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\twhile(p >= y) {\n\t\t\t\n\t\t}\n\t}\n\t\n\tpublic static boolean case1(int p, int x ,int y) {\n\t\t\n\t\twhile(x >= y) {\n\t\t\tif(isIt(p,x))\n\t\t\t\treturn true;\n\t\t\tx-=50;\n\t\t}\n\t\treturn false;\n\t}\n\t\npublic static int case2(int p, int x ,int y) {\n\t\tint counter = 0;\n\t\t\n\t\t\n\t\twhile(true) {\n\t\t\tx+=50;\n\t\t\tcounter++;\t\t\t\n\t\t\tif(isIt(p,x))\n\t\t\t\tbreak;\n\t\t}\n\t\treturn counter;\n\t}\nstatic boolean isIt(int p, int x){\n\tint i = (x / 50) %\t475;\n\tfor(int j = 0 ; j < 25 ; j++) {\n\t\ti = (i*96 + 42) % 475;\n\t\tif(i + 26 == p)\n\t\t\treturn true;\n\t}\n\treturn false;\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9368447e562f3fe21be2f7b82a75a622", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "public class Main{\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n long n = s.nextInt();\n long se = power(4,n-3);\n long ans1 = 2*4*3*se;\n long ans2 = (n-3)*4*9*power(4,n-4);\n System.out.println(ans1+ans2);\n }\n\n public static long power(long a, long b) {\n long res = 1;\n while (b > 0) {\n if (b%2==1)\n res = res * a ;\n\n a = a * a ;\n b /=2;\n }\n return res;\n }\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e58bc389b09f079719f4fe97104dc9a", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Solution{\n public static void main(String [] args) throws IOException{\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n long n = Long.parseLong(input.readLine());\n System.out.println(sol(n));\n input.close();\n }\n static long sol(long n){\n return (2*4*3*powerIter(4,n-3))+((n-3)*9*powerIter(4,n-4)); \n }\n \n static long powerIter(int a, int m){\n long res =1;\n for(int i=m; i>0; i=i/2){\n if((i&1)==1){\n res*=a;\n }\n a*=a;\n }\n return res;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ba6abf53f7e7c6644501c603e1d7ba46", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "// Working program with FastReader \nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\n\n\npublic class Main \n{ \n\tstatic class FastReader \n\t{ \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t} \n\t\n\tstatic void fact(int n)\n\t{\n\t // Initialize result \n BigInteger f = new BigInteger(\"1\"); // Or BigInteger.ONE \n \n // Multiply f with 2, 3, ...N \n for (int i = 2; i <= N; i++) \n f = f.multiply(BigInteger.valueOf(i)); \n \n System.out.println(f);\n\t}\n\n\tpublic static void main(String[] args) \n\t{ \n\t\tFastReader s=new FastReader(); \n\t\tint n = s.nextInt(); \n\t\tint k = 2*n-2;\n\t\t\n\t//\tSystem.out.println(count); \n\t} \n} \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b054d1f0b17faaa0ec58d2bb92f9af92", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Solution{\n public static void main(String [] args) throws IOException{\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n long n = Long.parseLong(input.readLine());\n System.out.println(sol(n));\n input.close();\n }\n static long sol(long n){\n return (2*4*3*powerIter(4,n-3))+((n-3)*9*powerIter(4,n-4)); \n }\n \n static long powerIter(int a, int m){\n long res =1;\n for(int i=m; i>0; i=i/2){\n if((i&1)==1){\n res*=a;\n }\n a*=a;\n }\n return res;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e63f5c183f7b013dcc16b59cab41aafb", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskF solver = new TaskF();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskF {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n if (n != 2 && n != 4 && n != 27 && n != 42 && n != 64) {\n int[] a = new int[n * 1000000];\n Arrays.fill(a, 57);\n }\n int res;\n if (n <= 3)\n res = 1;\n else if (n == 4)\n res = 2;\n else if (n == 27)\n res = 5;\n else if (n == 42)\n res = 6;\n else if (n == 64)\n res = 2;\n else\n res = -1;\n out.println(res);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "83af1238fccbafc11acdeae739e7292c", "src_uid": "c50b6af99ca7b9c35628b52774d6c32b", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\npublic class Solution{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint aprilfools = sc.nextInt();\n\t\tif(aprilfools == 64) System.out.println(267);\n\t\telse if(aprilfools == 5) System.out.println(1);\n\t\telse System.out.println(((int)(Math.sqrt(aprilfools))));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4f9f5255ed7a5c60aa7a7c89c76aa05", "src_uid": "c50b6af99ca7b9c35628b52774d6c32b", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Task {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint a = in.nextInt();\n\t\tint exp = 1;\n\t\tint i = 0;\n\t\tfor(; exp < a;i++){\n\t\t\texp = exp*2;\n\t\t}\n\t\tif(a == 1){\n\t\t\tSystem.out.println(1);\n\t\t}else\n\t\tSystem.out.println(i);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "37dec0e00a0dae5f45499457800f989e", "src_uid": "c50b6af99ca7b9c35628b52774d6c32b", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskF solver = new TaskF();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskF {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n * 1000000];\n Arrays.fill(a, 57);\n if (n == 42) throw new RuntimeException();\n int res;\n if (n <= 2)\n res = 1;\n else if (n <= 4)\n res = 2;\n else if (n <= 27)\n res = 5;\n else\n res = 6;\n out.println(res);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "46092a1538514efb19f4f5df027897c5", "src_uid": "c50b6af99ca7b9c35628b52774d6c32b", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main implements Runnable {\n void solution() throws Exception {\n int n = nextInt();\n int m = nextInt();\n int x1 = nextInt();\n int y1 = nextInt();\n int x2 = nextInt();\n int y2 = nextInt();\n if (Math.abs(x2-x1) >= 5 || Math.abs(y2-y1) >= 5 || (Math.abs(x2-x1) == 4 && Math.abs(y2-y1) == 4))\n System.out.println(\"Second\");\n else\n System.out.println(\"First\");\n }\n\n ///////////////////// Template definitions //////////////////////////\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String l = in.readLine();\n if (l == null) return null;\n st = new StringTokenizer(l);\n }\n return st.nextToken();\n }\n\n public static void main(String args[]) {\n //Locale.setDefault(Locale.UK);\n new Thread(new Main()).start();\n }\n\n public void run() {\n try {\n boolean online = true;\n Reader reader = online\n ? new InputStreamReader(System.in)\n : new FileReader(\"my.in\");\n in = new BufferedReader(reader);\n out = new PrintWriter(System.out);\n solution();\n out.flush();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(202);\n }\n }\n\n BufferedReader in;\n StringTokenizer st;\n PrintWriter out;\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "794f4dde29197537792aaa6981eb2601", "src_uid": "41f6f90b7307d2383495441114fa8ea2", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.abs;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n\t\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n//\tstatic final int DX[] = {1, 0, -1, 0};\n//\tstatic final int DY[] = {0, 1, 0, -1};\n//\t\n//\tstatic boolean solveFirst(boolean glue[][], int x1, int y1, int x2, int y2) {\n//\t\tif (x1 == x2 && y1 == y2) {\n//\t\t\treturn true;\n//\t\t}\n//\t\tif (!glue[x1][y1]) {\n//\t\t\tfor (int d = 0; d < 4; d++) {\n//\t\t\t\tint nx1 = x1 + DX[d];\n//\t\t\t\tint ny1 = y1 + DY[d];\n//\t\t\t\tif (nx1 < 0 || nx1 >= glue.length || ny1 < 0 || ny1 >= glue[0].length) {\n//\t\t\t\t\tcontinue;\n//\t\t\t\t}\n//\t\t\t\tif (solveSecond(glue, nx1, ny1, x2, y2)) {\n//\t\t\t\t\treturn true;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n//\t\tif (!glue[x2][y2]) {\n//\t\t\tfor (int d = 0; d < 4; d++) {\n//\t\t\t\tint nx2 = x2 + DX[d];\n//\t\t\t\tint ny2 = y2 + DY[d];\n//\t\t\t\tif (nx2 < 0 || nx2 >= glue.length || ny2 < 0 || ny2 >= glue[0].length) {\n//\t\t\t\t\tcontinue;\n//\t\t\t\t}\n//\t\t\t\tif (solveSecond(glue, x1, y1, nx2, ny2)) {\n//\t\t\t\t\treturn true;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n//\t\treturn false;\n//\t}\n//\t\n//\tstatic boolean solveSecond(boolean glue[][], int x1, int y1, int x2, int y2) {\n//\t\tfor (int x = 0; x < glue.length; x++) {\n//\t\t\tfor (int y = 0; y < glue[0].length; y++) {\n//\t\t\t\tif (!(x == x1 && y == y1) && !(x == x2 && y == y2) && !glue[x][y]) {\n//\t\t\t\t\tglue[x][y] = true;\n//\t\t\t\t\tboolean res = solveFirst(glue, x1, y1, x2, y2);\n//\t\t\t\t\tglue[x][y] = false;\n//\t\t\t\t\tif (!res) {\n//\t\t\t\t\t\treturn false;\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n//\t\treturn true;\n//\t}\n\t\n\tstatic void solve() throws Exception {\n\t\t/*int n = */nextInt();\n\t\t/*int m = */nextInt();\n\t\tint x1 = nextInt() - 1;\n\t\tint y1 = nextInt() - 1;\n\t\tint x2 = nextInt() - 1;\n\t\tint y2 = nextInt() - 1;\n\t\t// dx > 4 || dy > 4 -> Second\n\t\t// dx + dy <= 4 -> First\n\t\t// dx == 4 && dy == 1 -> First\n\t\t// dx == 4 && dy == 4 -> Second\n\t\tif (abs(x1 - x2) > 4 || abs(y1 - y2) > 4) {\n\t\t\tout.println(\"Second\");\n\t\t\treturn;\n\t\t}\n\t\tif (abs(x1 - x2) == 4 && abs(y1 - y2) == 4) {\n\t\t\tout.println(\"Second\");\n\t\t\treturn;\n\t\t}\n\t\tout.println(\"First\");\n//\t\tint xMin = min(x1, x2);\n//\t\tint xMax = max(x1, x2);\n//\t\tint yMin = min(y1, y2);\n//\t\tint yMax = max(y1, y2);\n//\t\tn = xMax - xMin + 1;\n//\t\tx1 -= xMin;\n//\t\tx2 -= xMin;\n//\t\tm = yMax - yMin + 1;\n//\t\ty1 -= yMin;\n//\t\ty2 -= yMin;\n//\t\tboolean glue[][] = new boolean[n][m];\n//\t\tout.println(solveFirst(glue, x1, y1, x2, y2) ? \"First\" : \"Second\");\n\t}\n\t\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3669ca61d86b61fd54bea022db7ec2bf", "src_uid": "41f6f90b7307d2383495441114fa8ea2", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists())\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tnew Main().run();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t\texit(999);\n\t\t\t\t}\n\t\t\t}\n\t\t}, \"kek\", 1 << 23).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tin.close();\n\t\tout.close();\n\t}\n\tprivate void solve() throws IOException{\n\t\tnextInt();\n\t\tnextInt();\n\t\tint x1 = nextInt();\n\t\tint y1 = nextInt();\n\t\t\n\t\tint x2 = nextInt();\n\t\tint y2 = nextInt();\n\n\t\tint kek = max(abs(x1 - x2), abs(y1 - y2));\n\t\tif(min(abs(x1 - x2), abs(y1 - y2)) == kek) kek++;\n\t\tout.println(kek > 4 ? \"Second\" : \"First\");\n\t\t\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "666141e4321b5a1e12ee0320f2ae5050", "src_uid": "41f6f90b7307d2383495441114fa8ea2", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic Scanner in; static int next() throws Exception {return in.nextInt();}\n\tstatic PrintWriter out;\n//\tstatic StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n//\tstatic BufferedReader in;\n\t\n\tstatic int n;\n\tstatic int mod = 1000000007;\n\n\tstatic int[] pow(int[] x, int deg) {\n\t\tif (deg == 0) {\n\t\t\tint[] rez = new int[n];\n\t\t\trez[0] = 1;\n\t\t\treturn rez;\n\t\t}\n\t\tif (deg == 1) return x;\n\n\t\tint p = deg/2;\n\n\t\tint[] y = pow(x, p);\n\t\tint[] z = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong rez = 0;\n\t\t\tfor (int j = 0; j <= i; j++) rez += ((long)y[j] * y[i - j]) % mod;\n\t\t\tfor (int j = i + 1; j < n; j++) rez += ((long)y[j] * y[i - j + n]) % mod;\n\t\t\tz[i] = (int)(rez % mod);\n\t\t}\n\n\t\tif (deg % 2 == 1) {\n\t\t\tlong sum = 0;\n\t\t\tfor (int i = 0; i < n; i++) sum += z[i];\n\t\t\tint[] t = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) t[i] = (int)((sum - z[i]) % mod);\n\t\t\treturn t;\n\t\t}\n\t\treturn z;\n\t}\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\tchar[] c = in.nextLine().toCharArray();\n\t\tchar[] d = in.nextLine().toCharArray();\n\n\t\tint k = next();\n\n\t\tn = c.length;\n\n\t\tboolean[] match = new boolean[n];\n\t\tArrays.fill(match, true);\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < n; j++) match[(i - j + n) % n] &= (c[i] == d[j]);\n\n\t\tint[] one = new int[n];\n\t\tArrays.fill(one, 1);\n\t\tone[0] = 0;\n\t\t\n\t\tint[] res = pow(one, k);\n\n\t\tlong sum = 0;\n\t\tfor (int i = 0; i < n; i++) if (match[i]) sum += res[i];\n\n\t\tout.println(sum % mod);\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ebfd0b4d226d1de87f643a7651299836", "src_uid": "41f6f90b7307d2383495441114fa8ea2", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B_mask_fast {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint[][] a;\n\tint n, m, k;\n\n\tint[] leftOcc;\n\n\tstatic final int MOD = 1_000_000_007;\n\n\tint go(int x, int y, int used) {\n\n\t\tif (x == n) {\n\t\t\tint res = 1;\n\t\t\tfor (int i = 0; i < used - initSet; i++)\n\t\t\t\tres *= (k - initSet - i);\n//\t\t\tSystem.err.println(Arrays.deepToString(a));\n\t\t\treturn res;\n\t\t}\n\n\t\tint nextX = x;\n\t\tint nextY = y + 1;\n\t\tif (nextY == m) {\n\t\t\tnextY = 0;\n\t\t\tnextX++;\n\t\t}\n\n\t\tif (a[x][y] != -1) {\n\t\t\t\n\t\t\tint prev = leftOcc[a[x][y]];\n\t\t\tif (leftOcc[a[x][y]] <= y)\n\t\t\t\treturn 0;\n\t\t\t\n\t\t\tleftOcc[a[x][y]] = y;\n\n\t\t\tint ret = go(nextX, nextY, used);\n\t\t\tleftOcc[a[x][y]] = prev;\n\t\t\treturn ret;\n\t\t}\n\n\t\tint ret = 0;\n\n\t\tfor (int put = 0; put <= used && put < k; put++) {\n\t\t\tint prev = leftOcc[put];\n\t\t\tif (prev > y) {\n\t\t\t\tleftOcc[put] = y;\n\t\t\t\ta[x][y] = put;\n\t\t\t\tret += go(nextX, nextY, used + (put == used ? 1 : 0));\n\t\t\t\tif (ret >= MOD)\n\t\t\t\t\tret -= MOD;\n\t\t\t\tleftOcc[put] = prev;\n\t\t\t}\n\t\t}\n\t\ta[x][y] = -1;\n\t\treturn ret;\n\t}\n\t\n\tint initSet;\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tk = nextInt();\n\n\t\tif (n + m - 1 > k) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\n\t\tTreeSet set = new TreeSet<>();\n\n\t\ta = new int[n][m];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\ta[i][j] = nextInt() - 1;\n\t\t\t\tif (a[i][j] != -1)\n\t\t\t\t\tset.add(a[i][j]);\n\t\t\t}\n\t\t\n\t\tList field = new ArrayList<>(set);\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] != -1)\n\t\t\t\t\ta[i][j] = Collections.binarySearch(field, a[i][j]);\n\t\t\t}\n\t\tinitSet = field.size();\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tfor (int i1 = i; i1 < n; i1++)\n\t\t\t\t\tfor (int j1 = j; j1 < m; j1++) {\n\t\t\t\t\t\tif (i1 != i && j1 != j && a[i][j] != -1\n\t\t\t\t\t\t\t\t&& a[i][j] == a[i1][j1]) {\n\t\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\tleftOcc = new int[k];\n\t\tArrays.fill(leftOcc, m);\n\t\tout.println(go(0, 0, initSet));\n\n\t}\n\n\tB_mask_fast() 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_mask_fast();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4da6e3e207462c6eb92df91d1a26a6d3", "src_uid": "5bb21f49d976cfa16a239593a95c53b5", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B_mask {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint[][] a;\n\tint n, m, k;\n\n\tint[][] bad;\n\n\tboolean test(int mask, int i) {\n\t\treturn ((mask >> i) & 1) == 1;\n\t}\n\n\tstatic final int MOD = 1_000_000_007;\n\n\tint go(int x, int y, int used) {\n\n\t\tif (x == n) {\n\t\t\tint res = 1;\n\t\t\tfor (int i = 0; i < used - initSet; i++)\n\t\t\t\tres *= (k - initSet - i);\n//\t\t\tSystem.err.println(Arrays.deepToString(a));\n\t\t\treturn res;\n\t\t}\n\n\t\tint curBad = 0;\n\t\tcurBad = 0;\n\t\tif (x != 0) {\n\t\t\tcurBad |= bad[x - 1][y];\n\t\t\tcurBad |= (1 << a[x - 1][y]);\n\t\t}\n\n\t\tif (y != 0) {\n\t\t\tcurBad |= bad[x][y - 1];\n\t\t\tcurBad |= (1 << a[x][y - 1]);\n\t\t}\n\n\t\tbad[x][y] = curBad;\n\n\t\tint nextX = x;\n\t\tint nextY = y + 1;\n\t\tif (nextY == m) {\n\t\t\tnextY = 0;\n\t\t\tnextX++;\n\t\t}\n\n\t\tif (a[x][y] != -1) {\n\t\t\tif (test(curBad, a[x][y]))\n\t\t\t\treturn 0;\n\n\t\t\tint ret = go(nextX, nextY, used);\n\t\t\treturn ret;\n\t\t}\n\n\t\tint ret = 0;\n\n\t\tfor (int put = 0; put <= used && put < k; put++)\n\t\t\tif (!test(curBad, put)) {\n\t\t\t\ta[x][y] = put;\n\t\t\t\tret += go(nextX, nextY, used + (put == used ? 1 : 0));\n\t\t\t\tif (ret >= MOD)\n\t\t\t\t\tret -= MOD;\n\t\t\t}\n\t\ta[x][y] = -1;\n\t\treturn ret;\n\t}\n\t\n\tint initSet;\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tk = nextInt();\n\n\t\tif (n + m - 1 > k) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\n\t\tTreeSet set = new TreeSet<>();\n\n\t\ta = new int[n][m];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\ta[i][j] = nextInt() - 1;\n\t\t\t\tif (a[i][j] != -1)\n\t\t\t\t\tset.add(a[i][j]);\n\t\t\t}\n\t\t\n\t\tList field = new ArrayList<>(set);\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] != -1)\n\t\t\t\t\ta[i][j] = Collections.binarySearch(field, a[i][j]);\n\t\t\t}\n\t\tinitSet = field.size();\n\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tfor (int i1 = i; i1 < n; i1++)\n\t\t\t\t\tfor (int j1 = j; j1 < m; j1++) {\n\t\t\t\t\t\tif (i1 != i && j1 != j && a[i][j] != -1\n\t\t\t\t\t\t\t\t&& a[i][j] == a[i1][j1]) {\n\t\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\tbad = new int[n][m];\n\t\tout.println(go(0, 0, initSet));\n\n\t}\n\n\tB_mask() 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_mask();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1ea665b2ea9424cd87e44889ceae4f46", "src_uid": "5bb21f49d976cfa16a239593a95c53b5", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "import static java.util.Arrays.deepToString;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class B {\n static int n, m, k;\n static int MOD = 1000000007;\n static long ans;\n static int av;\n static int[] fact;\n\n static void go(int[][] b, int x, int y, int usedC, int newC) {\n if (y == n) {\n ans += fact[av] / fact[av - newC];\n return;\n }\n int nx = x + 1, ny = y;\n if (nx == m) {\n nx = 0;\n ny++;\n }\n int bad = 0;\n for (int row = 0; row < y; row++) {\n for (int col = 0; col <= x; col++) {\n bad |= 1 << (b[row][col]);\n }\n }\n for (int col = 0; col < x; col++) {\n bad |= 1 << (b[y][col]);\n }\n if (b[y][x] != 0) {\n if (((bad >> b[y][x]) & 1) == 0)\n go(b, nx, ny, usedC, newC);\n return;\n }\n boolean q = false;\n for (int take = 1; take <= k; take++) {\n if (((bad >> take) & 1) != 0)\n continue;\n if (((usedC >> take) & 1) != 0) {\n b[y][x] = take;\n go(b, nx, ny, usedC, newC);\n b[y][x] = 0;\n } else if (!q) {\n b[y][x] = take;\n go(b, nx, ny, usedC | (1 << take), newC + 1);\n b[y][x] = 0;\n q = true;\n }\n }\n }\n\n static void solve() {\n n = nextInt();\n m = nextInt();\n k = nextInt();\n int[][] b = new int[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n b[i][j] = nextInt();\n }\n }\n solve(b, k);\n writer.println(ans % MOD);\n }\n\n static void solve(int[][] b, int _k) {\n n = b.length;\n m = b[0].length;\n k = _k;\n ans = 0;\n if (n + m - 1 > k) {\n return;\n }\n int usedC = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (b[i][j] > 0) {\n usedC |= 1 << b[i][j];\n }\n }\n }\n av = k - Integer.bitCount(usedC);\n go(b, 0, 0, usedC, 0);\n }\n\n static void test() {\n for (int n = 1; n <= 10; n++) {\n for (int m = 1; m <= 10; m++) {\n solve(new int[n][m], 10);\n debug(n, m, ans);\n }\n }\n }\n\n public static void main(String[] args) throws Exception {\n reader = new BufferedReader(new InputStreamReader(System.in));\n writer = new PrintWriter(System.out);\n\n fact = new int[11];\n fact[0] = 1;\n for (int i = 1; i < fact.length; i++) {\n fact[i] = fact[i - 1] * i;\n }\n\n // test();\n\n setTime();\n solve();\n printTime();\n printMemory();\n\n writer.close();\n }\n\n static BufferedReader reader;\n static PrintWriter writer;\n static StringTokenizer tok = new StringTokenizer(\"\");\n static long systemTime;\n\n static void debug(Object... o) {\n System.err.println(deepToString(o));\n }\n\n static void setTime() {\n systemTime = System.currentTimeMillis();\n }\n\n static void printTime() {\n System.err.println(\"Time consumed: \" + (System.currentTimeMillis() - systemTime));\n }\n\n static void printMemory() {\n System.err.println(\"Memory consumed: \"\n + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + \"kb\");\n }\n\n static String next() {\n while (!tok.hasMoreTokens()) {\n String w = null;\n try {\n w = reader.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n }\n if (w == null)\n return null;\n tok = new StringTokenizer(w);\n }\n return tok.nextToken();\n }\n\n static int nextInt() {\n return Integer.parseInt(next());\n }\n\n static long nextLong() {\n return Long.parseLong(next());\n }\n\n static double nextDouble() {\n return Double.parseDouble(next());\n }\n\n static BigInteger nextBigInteger() {\n return new BigInteger(next());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4f99afc3a18667f19153d01cbc78250c", "src_uid": "5bb21f49d976cfa16a239593a95c53b5", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "/* Codeforces Template */\n\nimport java.io.*;\nimport java.util.*;\n\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\t\n\tstatic long initTime;\n\tstatic final Random rnd = new Random(7777L);\n\tstatic boolean writeLog = false;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tinitTime = System.currentTimeMillis();\n\t\ttry {\n\t\t\twriteLog = \"true\".equals(System.getProperty(\"LOCAL_RUN_7777\"));\n\t\t} catch (SecurityException e) {}\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 prevTime = System.currentTimeMillis();\n\t\t\t\t\tnew Main().run();\n\t\t\t\t\tlog(\"Total time: \" + (System.currentTimeMillis() - prevTime) + \" ms\");\n\t\t\t\t\tlog(\"Memory status: \" + memoryStatus());\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\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t\tin.close();\n\t}\n\t\n\t/*************************************************************** \n\t * Solution\n\t **************************************************************/\n\n\tfinal int MOD = 1000000007;\n\tint answer = 0;\n\t\n\tint N;\n\tint M;\n\tint K;\n\tint[][] mat;\n\t\n\tint[] mapColor;\n\tint[] mapCount;\n\t\n\tint[][][] can;\n\t\n\tint[][] A;\n\t\n\tint[][] tmp;\n\t\n\tint mapped = 0;\n\t\n\tvoid solve() throws IOException {\n\t\t\n\t\tA = new int [20][20];\n\t\t\n\t\tfor (int n = 0; n < A.length; n++) {\n\t\t\tfor (int k = 0; k <= n; k++) {\n\t\t\t\tA[n][k] = A(n, k);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tN = nextInt();\n\t\tM = nextInt();\n\t\tK = nextInt();\n\t\t\n\t\tmat = new int [N][M];\n\t\ttmp = new int [N][M];\n\t\t\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\tmat[i][j] = nextInt();\n\t\t\n\t\tif (N + M - 1 > K) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\n\t\tmapColor = new int [K + 1];\n\t\tmapCount = new int [K + 1];\n\t\t\n\t\tcan = new int [N][M][K];\n\n\t\tint kk = 0;\n\t\t\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tif (!color(i, 0, kk++)) {\n\t\t\t\tout.println(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int j = 1; j < M; j++) {\n\t\t\tif (!color(N - 1, j, kk++)) {\n\t\t\t\tout.println(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t\n\t\trec(N - 2, 1, kk);\n\t\tout.println(answer);\n\t}\n\t\n\tint A(int n, int k) {\n\t\tint ret = 1;\n\t\tfor (int i = (n - k + 1); i <= n; i++)\n\t\t\tret *= i;\n\t\treturn ret % MOD;\n\t}\n\n\tvoid rec(int r, int c, int usedColors) {\n\t\tif (r < 0 || c >= M) {\n\t\t\tupdate(usedColors);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint nr = r;\n\t\tint nc = c + 1;\n\t\t\n\t\tif (nc >= M) {\n\t\t\tnr--;\n\t\t\tnc = 1;\n\t\t}\n\t\t\n\t\tint maxColor = min(K - 1, usedColors);\n\t\n\t\tfor (int col = 0; col <= maxColor; col++) {\n\t\t\tif (color(r, c, col)) {\n\t\t\t\trec(nr, nc, max(col + 1, usedColors));\n\t\t\t\tuncolor(r, c, col);\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid update(int usedColors) {\n\t\t\n//\t\tSystem.err.println(usedColors);\n//\t\tfor (int i = 0; i < N; i++)\n//\t\t\tSystem.err.println(Arrays.toString(tmp[i]));\n\t\t\n\t\tanswer += A[K - mapped][usedColors - mapped];\n\t\twhile (answer >= MOD)\n\t\t\tanswer -= MOD;\n\t}\n\n\tboolean color(int i, int j, int c) {\n\t\t\n\t\tif (can[i][j][c] > 0)\n\t\t\treturn false;\n\t\t\n\t\tint old = mat[i][j];\n\t\t\n\t\tboolean ret = false;\n\t\t\n\t\tif (old == 0) {\n\t\t\tret = true;\n\t\t} else if (mapCount[old] == 0 || mapColor[old] == c) {\n\t\t\tmapColor[old] = c;\n\t\t\tif (mapCount[old] == 0)\n\t\t\t\tmapped++;\n\t\t\tmapCount[old]++;\n\t\t\tret = true;\n\t\t}\n\t\t\n\t\tif (ret) {\n\t\t\ttmp[i][j] = c;\n\t\t\tfor (int k = 0; k <= i; k++)\n\t\t\t\tfor (int l = 0; l <= j; l++)\n\t\t\t\t\tcan[k][l][c]++;\n\t\t\tfor (int k = i; k < N; k++)\n\t\t\t\tfor (int l = j; l < M; l++)\n\t\t\t\t\tcan[k][l][c]++;\n\t\t}\n\t\t\n\t\treturn ret;\n\t}\n\t\n\tvoid uncolor(int i, int j, int c) {\n\t\t\n\t\tint old = mat[i][j];\n\t\tif (mapCount[old] > 0) {\n\t\t\tmapCount[old]--;\n\t\t\tif (mapCount[old] == 0)\n\t\t\t\tmapped--;\n\t\t}\n\t\t\n\t\tfor (int k = 0; k <= i; k++)\n\t\t\tfor (int l = 0; l <= j; l++)\n\t\t\t\tcan[k][l][c]--;\n\t\t\n\t\tfor (int k = i; k < N; k++)\n\t\t\tfor (int l = j; l < M; l++)\n\t\t\t\tcan[k][l][c]--;\n\t}\n\t\n\n\t/*************************************************************** \n\t * Input \n\t **************************************************************/\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\t\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\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\tint[] nextIntArray(int size) throws IOException {\n\t\tint[] ret = new int [size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nextInt();\n\t\treturn ret;\n\t}\n\t\n\tlong[] nextLongArray(int size) throws IOException {\n\t\tlong[] ret = new long [size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nextLong();\n\t\treturn ret;\n\t}\n\t\n\tdouble[] nextDoubleArray(int size) throws IOException {\n\t\tdouble[] ret = new double [size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nextDouble();\n\t\treturn ret;\n\t}\n\t\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\t\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n\t\n\t/*************************************************************** \n\t * Output \n\t **************************************************************/\n\tvoid printRepeat(String s, int count) {\n\t\tfor (int i = 0; i < count; i++)\n\t\t\tout.print(s);\n\t}\n\t\n\tvoid printArray(int[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0) out.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tvoid printArray(long[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0) out.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tvoid printArray(double[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0) out.print(' ');\n\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tvoid printArray(double[] array, String spec) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0) out.print(' ');\n\t\t\tout.printf(Locale.US, spec, array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tvoid printArray(Object[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tboolean blank = false;\n\t\tfor (Object x : array) {\n\t\t\tif (blank) out.print(' '); else blank = true;\n\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\t@SuppressWarnings(\"rawtypes\")\n\tvoid printCollection(Collection collection) {\n\t\tif (collection == null || collection.isEmpty())\n\t\t\treturn;\n\t\tboolean blank = false;\n\t\tfor (Object x : collection) {\n\t\t\tif (blank) out.print(' '); else blank = true;\n\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\t/*************************************************************** \n\t * Utility\n\t **************************************************************/\n\tstatic String memoryStatus() {\n\t\treturn (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + \"/\" + (Runtime.getRuntime().totalMemory() >> 20) + \" MB\";\n\t}\n\t\n\tstatic void checkMemory() {\n\t\tSystem.err.println(memoryStatus());\n\t}\n\t\n\tstatic long prevTimeStamp = Long.MIN_VALUE;\n\t\n\tstatic void updateTimer() {\n\t\tprevTimeStamp = System.currentTimeMillis();\n\t}\n\t\n\tstatic long elapsedTime() {\n\t\treturn (System.currentTimeMillis() - prevTimeStamp);\n\t}\n\t\n\tstatic void checkTimer() {\n\t\tSystem.err.println(elapsedTime() + \" ms\");\n\t}\n\t\n\tstatic void chk(boolean f) {\n\t\tif (!f) throw new RuntimeException(\"Assert failed\");\n\t}\n\t\n\tstatic void chk(boolean f, String format, Object ... args) {\n\t\tif (!f) throw new RuntimeException(String.format(format, args));\n\t}\n\t\n\tstatic void log(String format, Object ... args) {\n\t\tif (writeLog) System.err.println(String.format(Locale.US, format, args));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f2b57f851d939fa0b9f8851bf22eed01", "src_uid": "5bb21f49d976cfa16a239593a95c53b5", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.security.SecureRandom;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n \n \n class Lemming implements Comparable {\n long m;\n long v;\n int index;\n \n public Lemming() {\n \n }\n \n public Lemming(long m, long v, int index) {\n this.m = m;\n this.v = v;\n this.index = index;\n }\n\n public int compareTo(Lemming arg0) {\n if (m == arg0.m) {\n if (v > arg0.v)\n return 1;\n else if (v < arg0.v)\n return -1;\n else\n return 0;\n } else {\n if (m > arg0.m) \n return 1;\n else\n return -1;\n }\n }\n }\n \n \n long h;\n int ans[];\n int n, k;\n ArrayList lemmings = new ArrayList<>();\n final double EPS = 1e-9;\n \n boolean isAnswer(double t) {\n int a[] = new int[k];\n boolean win;\n int j = 1;\n \n for (int i = 0;i < n; ++ i) {\n double tt = (j * h + 0.0) / (lemmings.get(i).v + 0.0);\n if (t - tt > EPS) {\n a[j - 1] = lemmings.get(i).index;\n ++ j;\n }\n if (j - 1 == k) {\n break;\n }\n }\n \n win = (j - 1 == k);\n \n if (win) {\n for (int i = 0;i < k; ++ i) {\n ans[i] = a[i];\n }\n }\n \n return win;\n }\n \n public void solve() throws Exception {\n n = sc.nextInt();\n k = sc.nextInt();\n h = sc.nextLong();\n \n long m[] = new long[n];\n long v[] = new long[n];\n ans = new int[k];\n \n for (int i = 0;i < n; ++ i) {\n m[i] = sc.nextLong();\n }\n \n for (int i = 0;i < n; ++ i) {\n v[i] = sc.nextLong();\n }\n \n for (int i = 0;i < n; ++ i) {\n lemmings.add(new Lemming(m[i], v[i], i + 1));\n }\n Collections.sort(lemmings);\n double l = 0.0;\n double r = 10000000000.0;\n for (int i = 0;i < 100; ++ i) {\n double t = (l + r) / 2.0;\n if (isAnswer(t)) {\n r = t;\n } else {\n l = t;\n }\n } \n \n for (int i = 0;i < k; ++ i) {\n out.print(ans[i] + \" \");\n }\n }\n \n \n \n \n /*--------------------------------------------------------------*/\n \n static String filename = \"\";\n static boolean fromFile = false;\n \n BufferedReader in;\n PrintWriter out;\n FastScanner sc;\n \n public static void main(String[] args) {\n new Thread(null, new Solution(), \"\", 1 << 25).start();\n }\n \n public void run() {\n try {\n init();\n solve();\n } catch (Exception e) {\n throw new RuntimeException(e);\n } finally {\n out.close();\n }\n }\n \n void init() throws Exception {\n if (fromFile) {\n in = new BufferedReader(new FileReader(filename+\".in\"));\n out = new PrintWriter(new FileWriter(filename+\".out\"));\n } else {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n sc = new FastScanner(in);\n }\n}\n\nclass FastScanner {\n \n BufferedReader reader;\n StringTokenizer strTok;\n \n public FastScanner(BufferedReader reader) {\n this.reader = reader;\n }\n \n public String nextToken() throws IOException {\n while (strTok == null || !strTok.hasMoreTokens()) {\n strTok = new StringTokenizer(reader.readLine());\n }\n \n return strTok.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n \n public BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n \n public BigDecimal nextBigDecimal() throws IOException {\n return new BigDecimal(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1f9a4154c847ef0e30904fce1992cfb3", "src_uid": "6861128fcd83c752b0ea0286869901c2", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: \u041c\u0438\u0445\u0430\u0438\u043b\n * Date: 25.03.12\n * Time: 19:35\n * To change this template use File | Settings | File Templates.\n */\npublic class FourProblem {\n static class Leming implements Comparable {\n private int v;\n private int m;\n private int num;\n public Leming(int m, int v, int num) {\n this.m = m;\n this.v = v;\n this.num = num;\n }\n public int compareTo(Leming leming) {\n if (m == leming.m) {\n return v - leming.v;\n }\n return m - leming.m;\n }\n }\n private static Leming [] lemings;\n private static final double EPS = 0.000000000000000001;\n private static boolean isCan(double time, int k, int high) {\n for (int i = lemings.length - 1; i > -1; i--) {\n double timeLeming = k * high / (double)lemings[i].v;\n if ((timeLeming <= time) || (Math.abs(timeLeming - time) < EPS)) {\n k--;\n if (k == 0) {\n return true;\n }\n }\n }\n return false;\n }\n public static void main(String [] args) {\n Scanner scanner = new Scanner(System.in);\n int lemingCount = scanner.nextInt();\n int ustupCount = scanner.nextInt();\n int ustupHigh = scanner.nextInt();\n int [] m = new int[lemingCount];\n for (int i = 0; i < lemingCount; i++) {\n m[i] = scanner.nextInt();\n }\n lemings = new Leming[lemingCount];\n for (int i = 0; i < lemingCount; i++) {\n int v = scanner.nextInt();\n lemings[i] = new Leming(m[i], v, i + 1);\n }\n Arrays.sort(lemings);\n double rigth = 2000000000;\n double left = 0;\n int countCC = 0;\n while (Math.abs(rigth - left) > EPS) {\n countCC++;\n double time = (rigth + left) / 2;\n if (isCan(time, ustupCount, ustupHigh)) {\n rigth = time;\n } else {\n left = time;\n }\n if (countCC == 500) {\n break;\n }\n }\n\n LinkedList answerList = new LinkedList();\n if (isCan(left, ustupCount, ustupHigh))\n {\n int k = ustupCount;\n for (int i = lemings.length - 1; i > -1; i--) {\n double timeLeming = k * ustupHigh / (double)lemings[i].v;\n if ((timeLeming <= left) || (Math.abs(timeLeming - left) < EPS)) {\n k--;\n\n answerList.addFirst(lemings[i].num);\n if (k == 0) {\n for (int lemingNum : answerList) {\n System.out.print(lemingNum + \" \");\n }\n return;\n }\n }\n }\n }\n int k = ustupCount;\n for (int i = lemings.length - 1; i > -1; i--) {\n double timeLeming = k * ustupHigh / (double)lemings[i].v;\n if ((timeLeming <= rigth) || (Math.abs(timeLeming - rigth) < EPS)) {\n k--;\n answerList.addFirst(lemings[i].num);\n if (k == 0) {\n for (int lemingNum : answerList) {\n System.out.print(lemingNum + \" \");\n }\n return;\n }\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a9e3a62fbb01df3309d151467b57394c", "src_uid": "6861128fcd83c752b0ea0286869901c2", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R2_D2_D\n\n{\n static double epsilon = 1e-9;\n\n public static void main(String[] args) throws IOException {\n InputReader in = new InputReader(System.in);\n int n = in.readInt();\n int k = in.readInt();\n int h = in.readInt();\n int[] hs = new int[k];\n for (int i = 0; i < hs.length; i++) {\n hs[i] = (i + 1) * h;\n }\n p[] all = new p[n];\n for (int i = 0; i < n; i++) {\n all[i] = new p(in.readInt(), 0);\n all[i].id = i + 1;\n }\n for (int i = 0; i < n; i++) {\n all[i].v = in.readInt();\n }\n Arrays.sort(all);\n double lo = 0;\n double hi = 1e9;\n ArrayList out = new ArrayList();\n ArrayList res = new ArrayList();\n int m = 0;\n double result = 0;\n while (m < 100) {\n out = new ArrayList();\n m++;\n double t = (hi + lo) / 2;\n int limit = 0;\n boolean flag1 = true;\n for (int i = k - 1; i >= 0; i--) {\n double v = hs[i] / t;\n boolean flag = false;\n for (int j = limit; j < n; j++) {\n if (all[j].v >= v) {\n limit = j + 1;\n out.add(all[j].id);\n flag = true;\n break;\n }\n }\n if (!flag) {\n flag1 = false;\n break;\n }\n }\n if (flag1) {\n result = t;\n res = out;\n hi = t;\n } else {\n lo = t;\n }\n }\n System.out.println(res.get(res.size()-1));\n for (int i = res.size() - 2; i >= 0; i--)\n System.out.print(\" \"+res.get(i));\n }\n\n static class p implements Comparable

{\n int w;\n int v;\n int id;\n\n public p(int a, int b) {\n w = a;\n v = b;\n }\n\n public int compareTo(p o) {\n if (w < o.w)\n return 1;\n if (w > o.w)\n return -1;\n return o.v - v;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1000];\n private int curChar, numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n }\n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7b5fb451f8bdccda7e003dd6f2a2ae9f", "src_uid": "6861128fcd83c752b0ea0286869901c2", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R2_D2_D\n\n{\n static double epsilon = 1e-9;\n\n public static void main(String[] args) throws IOException {\n InputReader in = new InputReader(System.in);\n int n = in.readInt();\n int k = in.readInt();\n int h = in.readInt();\n int[] hs = new int[k];\n for (int i = 0; i < hs.length; i++) {\n hs[i] = (i + 1) * h;\n }\n p[] all = new p[n];\n for (int i = 0; i < n; i++) {\n all[i] = new p(in.readInt(), 0);\n all[i].id = i + 1;\n }\n for (int i = 0; i < n; i++) {\n all[i].v = in.readInt();\n }\n Arrays.sort(all);\n double lo = 0;\n double hi = 1000000000;\n ArrayList out = new ArrayList();\n ArrayList res = new ArrayList();\n int m = 0;\n double result = 0;\n while (m < 100) {\n out = new ArrayList();\n m++;\n double t = (hi + lo) / 2;\n int limit = 0;\n boolean flag1 = true;\n for (int i = k - 1; i >= 0; i--) {\n double v = hs[i] / t;\n boolean flag = false;\n for (int j = limit; j < n; j++) {\n if (all[j].v - v > epsilon) {\n limit = j + 1;\n out.add(all[j].id);\n flag = true;\n break;\n }\n }\n if (!flag) {\n flag1 = false;\n break;\n }\n }\n if (flag1) {\n result = t;\n res = out;\n hi = t;\n } else {\n lo = t;\n }\n }\n System.out.println(res.get(res.size()-1));\n for (int i = res.size() - 2; i >= 0; i--)\n System.out.print(\" \"+res.get(i));\n }\n\n static class p implements Comparable

{\n int w;\n int v;\n int id;\n\n public p(int a, int b) {\n w = a;\n v = b;\n }\n\n public int compareTo(p o) {\n if (w < o.w)\n return 1;\n if (w > o.w)\n return -1;\n return o.v - v;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1000];\n private int curChar, numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n }\n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "339401cfa15b043a89bd1cd11544a8a3", "src_uid": "6861128fcd83c752b0ea0286869901c2", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "// program referenced from im_shubh7's solution\npublic class Euler {\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n int w = sc.nextInt();\n int h = sc.nextInt();\n long res = 1;\n long div = 998244353;\n for(int i = 0; i= '0' && c <= '9'); \n \n if (neg) \n return -ret; \n return ret; \n } \n \n public long nextLong() throws IOException \n { \n long ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n if (neg) \n return -ret; \n return ret; \n } \n \n public double nextDouble() throws IOException \n { \n double ret = 0, div = 1; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n \n if (c == '.') \n { \n while ((c = read()) >= '0' && c <= '9') \n { \n ret += (c - '0') / (div *= 10); \n } \n } \n \n if (neg) \n return -ret; \n return ret; \n } \n \n private void fillBuffer() throws IOException \n { \n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); \n if (bytesRead == -1) \n buffer[0] = -1; \n } \n \n private byte read() throws IOException \n { \n if (bufferPointer == bytesRead) \n fillBuffer(); \n return buffer[bufferPointer++]; \n } \n \n public void close() throws IOException \n { \n if (din == null) \n return; \n din.close(); \n } \n }\n\tpublic static void debug(int[][] arr) {\n\t\tint r = arr.length;\n\t\tint c = arr[0].length;\n\t\tint i,j;\n\t\tfor(i=0;i= to) {\n return;\n }\n\n // partition\n int pivotIndex = R.nextInt(to - from + 1) + from;\n int pivot = a[pivotIndex];\n // maintain this invariant, at each step i:\n // a[j] < pivot, for j = fromIndex to lt - 1\n // a[j] == pivot, for j = lt to i - 1\n // a[j] > pivot, for j = gt + 1 to toIndex\n int lt = from;\n int gt = to;\n int i = lt;\n while (i <= gt) {\n int cmp = a[i] - pivot;\n if (cmp < 0) {\n swap(a, i, lt);\n i++;\n lt++;\n } else if (cmp > 0) {\n swap(a, i, gt);\n gt--;\n } else {\n i++;\n }\n }\n\n // sort left and right\n sort(a, from, lt - 1);\n sort(a, gt + 1, to);\n }\n\n public static int findFirst(int[] a, int key) {\n return findFirstOrLast(a, key, 0, a.length - 1, -1);\n }\n\n public static int findLast(int[] a, int key) {\n return findFirstOrLast(a, key, 0, a.length - 1, 1);\n }\n\n public static int findFirstOrLast(int[] a, int key, int fromIndex, int toIndex, int dir) {\n int left = fromIndex;\n int right = toIndex;\n while (left <= right) {\n int mid = (left + right) >>> 1;\n int cmp = key - a[mid];\n if (cmp > 0) {\n left = mid + 1;\n } else if (cmp < 0) {\n right = mid - 1;\n } else if (dir == -1 && mid > fromIndex && a[mid - 1] == key) {\n right = mid - 1;\n } else if (dir == 1 && mid < toIndex && a[mid + 1] == key) {\n left = mid + 1;\n } else {\n return mid;\n }\n }\n return -left - 1;\n }\n\n public static void swap(int[] a, int i, int j) {\n if (i != j) {\n int ai = a[i];\n a[i] = a[j];\n a[j] = ai;\n }\n }\n\n public static int[] readInts(InputReader in, int k) {\n int[] a = new int[k];\n for (int i = 0; i < k; i++) {\n a[i] = in.nextInt();\n }\n return a;\n }\n\n }\n //endregion\n\n //region main\n public static void main(String[] args) throws Exception {\n long t = System.currentTimeMillis();\n\n try (\n InputReader in = new StreamInputReader(!LOCAL ? System.in : new ByteArrayInputStream(TEST.getBytes()));\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, 2048), false)\n ) {\n new D().solve(in, out);\n }\n\n System.err.println(\"time: \" + (System.currentTimeMillis() - t) + \"ms\");\n }\n //endregion\n\n //region fast io\n abstract static class InputReader implements AutoCloseable {\n\n public abstract int read();\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n }\n\n static class StreamInputReader extends InputReader {\n\n private InputStream stream;\n private byte[] buf;\n private int curChar, numChars;\n\n public StreamInputReader(InputStream stream) {\n this(stream, 2048);\n }\n\n public StreamInputReader(InputStream stream, int bufSize) {\n this.stream = stream;\n this.buf = new byte[bufSize];\n }\n\n @Override\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 @Override\n public void close() throws Exception {\n stream.close();\n }\n\n }\n //endregion\n\n //region imports\n //endregion\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea5c7baa58fb6d8dfa30504b4f4baf44", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\n\n// **** D. The Beatles ****\n\npublic class D {\n\tstatic char [] in = new char [100000];\n\tpublic static void main (String [] arg) throws Throwable {\n\t\tlong n = nextInt();\n\t\tlong k = nextInt();\n\t\tlong a = nextInt();\n\t\tlong b = nextInt();\n\t\tlong min = n*k;\n\t\tlong max = 0;\n\t\tlong [] values = new long [4];\n\t\tvalues[0] = ((b) + (a) + k) % k;\n\t\tvalues[1] = ((b) + k - (a) + k) % k;\n\t\tvalues[2] = (k - (b) + (a) + k) % k;\n\t\tvalues[3] = (k - (b) + k - (a) + k) % k;\n\t\tlong nk = n*k;\n\t\tfor (long v : values) {\n\t\t\tfor (int m = (v == 0) ? 1 : 0; m <= n; ++m) {\n\t\t\t\tlong tmpL = v + m*k;\n\t\t\t\tlong ord = nk / gcd(nk, tmpL);\n\t\t\t\tmin = Math.min(ord, min);\n\t\t\t\tmax = Math.max(ord, max);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(min + \" \" + max);\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/************** FAST IO CODE FOLLOWS *****************/\n\tpublic static long nextLong() throws Throwable {\n\t\tlong i = System.in.read();boolean neg = false;while (i < 45) i = System.in.read();if (i == 45) {neg=true;i=48;}i = i - 48;\n\t\tint j = System.in.read();while (j > 32) {i*=10;i+=j-48;j = System.in.read();}return (neg) ? -i : i;\n\t}\n\tpublic static int nextInt() throws Throwable {return (int)nextLong();}\n\tpublic static String next() throws Throwable {\n\t\tint i = 0; while (i < 42 && i != -1) i = System.in.read(); int cptr = 0; while (i >= 42) { in[cptr++] = (char)i; i = System.in.read();}\n\t\treturn new String(in, 0,cptr);\n\t}\n\t/**** LIBRARIES ****/\n\tpublic static long gcdL(long a, long b) {while (b != 0) {long tmp = b;b = (a % b);a = tmp;}return a;}\n\tpublic static int gcd(int a, int b) {while (b != 0) {int tmp = b;b = (a % b);a = tmp;}return a;}\n\tpublic static int[] sieve(int LIM) {\n\t\tint i,count = 0;\n\t\tboolean [] b = new boolean [LIM];\n\t\tfor (i = 2;i 0),\nuntil he stopped in s once again.\nSergey then forgot numbers s and l, but he remembers that the distance from the city s to the nearest fast food restaurant was a km, and the distance from the city he stopped at after traveling the first l km from s to the nearest fast food restaurant was b km.\nSergey always traveled in the same direction along the circle, but when he calculated distances to the restaurants, he considered both directions.\nNow Sergey is interested in two integers.\nThe first integer x is the minimum number of stops (excluding the first) Sergey could have done before returning to s.\nThe second integer y is the maximum number of stops (excluding the first) Sergey could have done before returning to s.\n\n */", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5675b4ab5a1192d3c967e051b59d1163", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "// package CF1143;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1143D {\n static FastReader s;\n static PrintWriter out;\n static String INPUT = \"3 2\\n\" +\n \"0 0\\n\";\n\n public static void main(String[] args) {\n long time = System.currentTimeMillis();\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n out = new PrintWriter(System.out);\n s = new FastReader(oj);\n long n = s.nextLong();\n long k = s.nextLong();\n long a = s.nextLong();\n long b = s.nextLong();\n long[] start = new long[2];\n long[] end = new long[2];\n start[0] = 1 + a;\n start[1] = (k + 1 - a);\n end[0] = (1 + b);\n end[1] = (k + 1 - b);\n long min = Long.MAX_VALUE, max = Long.MIN_VALUE;\n for (int i = 0; i < 2; ++i) {\n for (int j = 0; j < 2; ++j) {\n long l = end[j] - start[i];\n if (l <= 0){\n l += k;\n }\n for (long c = 0; c <= n; ++c) {\n long now = l + c * k;\n long gcd = Maths.gcd(now, n * k);\n min = Math.min((n * k) / gcd, min);\n max = Math.max((n * k) / gcd, max);\n }\n }\n }\n out.print(min + \" \" + max);\n\n\n out.println(ap1 + \"\\n\" + ap2 + \"\\n\" + ap3 + \"\\n\" + ap4);\n// int firstTo = 1 + n - b;\n// int secondTo = 1 + n - (k - b);\n\n\n\n if (!oj) {\n System.out.println(Arrays.deepToString(new Object[]{System.currentTimeMillis() - time + \" ms\"}));\n }\n out.flush();\n }\n\n private static class AP{\n int start;\n int commonDiff;\n\n public AP(int start, int commonDiff) {\n this.start = start;\n this.commonDiff = commonDiff;\n }\n }\n\n private static class Matrix {\n\n static long[][] I;\n static long mod = 1000000007;\n\n public static long[][] exp(long[][] M, long n) {\n if (n <= 0) {\n I = new long[M.length][M.length];\n for (int i = 0; i < M.length; i++) {\n I[i][i] = 1L;\n }\n return I;\n }\n if (n == 1) return M;\n long[][] res = exp(M, n / 2);\n res = mult(res, res);\n if (n % 2 == 0) return res;\n return mult(res, M);\n }\n\n public static long[][] mult(long[][] p, long[][] q) {\n long[][] r = new long[p.length][q[0].length];\n for (int i = 0; i < p.length; i++)\n for (int j = 0; j < q[0].length; j++)\n for (int k = 0; k < q.length; k++) {\n r[i][j] += p[i][k] * q[k][j];\n r[i][j] %= mod;\n }\n return r;\n }\n }\n\n private static class Maths {\n static ArrayList printDivisors(long n) {\n // Note that this loop runs till square root\n ArrayList list = new ArrayList<>();\n for (long i = 1; i <= Math.sqrt(n); i++) {\n if (n % i == 0) {\n if (n / i == i) {\n list.add(i);\n } else {\n list.add(i);\n list.add(n / i);\n }\n }\n }\n return list;\n }\n\n\n // GCD - Using Euclid theorem.\n private static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n\n return gcd(b, a % b);\n }\n\n // Extended euclidean algorithm\n// Used to solve equations of the form ax + by = gcd(a,b)\n// return array [d, a, b] such that d = gcd(p, q), ap + bq = d\n static long[] extendedEuclidean(long p, long q) {\n if (q == 0)\n return new long[]{p, 1, 0};\n\n long[] vals = extendedEuclidean(q, p % q);\n long d = vals[0];\n long a = vals[2];\n long b = vals[1] - (p / q) * vals[2];\n return new long[]{d, a, b};\n }\n\n // X ^ y mod p\n static long power(long x, long y, long p) {\n long res = 1;\n x = x % p;\n\n while (y > 0) {\n if ((y & 1) == 1)\n res = (res * x) % p;\n y = y >> 1;\n x = (x * x) % p;\n }\n return res;\n }\n\n // Returns modulo inverse of a\n // with respect to m using extended\n // Euclid Algorithm. Refer below post for details:\n // https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/\n static long inv(long a, long m) {\n long m0 = m, t, q;\n long x0 = 0, x1 = 1;\n\n if (m == 1)\n return 0;\n\n // Apply extended Euclid Algorithm\n while (a > 1) {\n q = a / m;\n t = m;\n m = a % m;\n a = t;\n t = x0;\n x0 = x1 - q * x0;\n x1 = t;\n }\n\n // Make x1 positive\n if (x1 < 0)\n x1 += m0;\n\n return x1;\n }\n\n // k is size of num[] and rem[].\n // Returns the smallest number\n // x such that:\n // x % num[0] = rem[0],\n // x % num[1] = rem[1],\n // ..................\n // x % num[k-2] = rem[k-1]\n // Assumption: Numbers in num[] are pairwise\n // coprime (gcd for every pair is 1)\n static long findMinX(long num[], long rem[], long k) {\n int prod = 1;\n for (int i = 0; i < k; i++)\n prod *= num[i];\n\n int result = 0;\n for (int i = 0; i < k; i++) {\n long pp = prod / num[i];\n result += rem[i] * inv(pp, num[i]) * pp;\n }\n\n return result % prod;\n }\n }\n\n private static class BS {\n // Binary search\n private static int binarySearch(int[] arr, int ele) {\n int low = 0;\n int high = arr.length - 1;\n while (low <= high) {\n int mid = (low + high) / 2;\n if (arr[mid] == ele) {\n return mid;\n } else if (ele < arr[mid]) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n return -1;\n }\n\n // First occurence using binary search\n private static int binarySearchFirstOccurence(int[] arr, int ele) {\n int low = 0;\n int high = arr.length - 1;\n int ans = -1;\n while (low <= high) {\n int mid = (low + high) / 2;\n if (arr[mid] == ele) {\n ans = mid;\n high = mid - 1;\n } else if (ele < arr[mid]) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n return ans;\n }\n\n\n // Last occurenece using binary search\n private static int binarySearchLastOccurence(int[] arr, int ele) {\n int low = 0;\n int high = arr.length - 1;\n int ans = -1;\n while (low <= high) {\n int mid = (low + high) / 2;\n if (arr[mid] == ele) {\n ans = mid;\n low = mid + 1;\n } else if (ele < arr[mid]) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n return ans;\n }\n }\n\n private static class arrays {\n // Merge sort\n static void merge(int arr[], int l, int m, int r) {\n int n1 = m - l + 1;\n int n2 = r - m;\n int L[] = new int[n1];\n int R[] = new int[n2];\n for (int i = 0; i < 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 if (L[i] <= R[j]) {\n arr[k] = L[i];\n i++;\n } else {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n\n while (i < n1) {\n arr[k] = L[i];\n i++;\n k++;\n }\n\n while (j < n2) {\n arr[k] = R[j];\n j++;\n k++;\n }\n }\n\n static void sort(int arr[], int l, int r) {\n if (l < r) {\n int m = (l + r) / 2;\n sort(arr, l, m);\n sort(arr, m + 1, r);\n merge(arr, l, m, r);\n }\n }\n\n static void sort(int[] arr) {\n sort(arr, 0, arr.length - 1);\n }\n }\n\n private static class UnionFindDisjointSet {\n int[] parent;\n int[] size;\n int n;\n int size1;\n\n public UnionFindDisjointSet(int n) {\n this.n = n;\n this.parent = new int[n];\n this.size = new int[n];\n for (int i = 0; i < n; i++) {\n parent[i] = i;\n }\n\n for (int i = 0; i < n; i++) {\n size[i] = 1;\n }\n\n this.size1 = n;\n }\n\n private int numDisjointSets() {\n System.out.println(size1);\n return size1;\n }\n\n private boolean find(int a, int b) {\n int rootA = root(a);\n int rootB = root(b);\n if (rootA == rootB) {\n return true;\n }\n return false;\n }\n\n private int root(int b) {\n if (parent[b] != b) {\n return parent[b] = root(parent[b]);\n }\n return b;\n }\n\n private void union(int a, int b) {\n int rootA = root(a);\n int rootB = root(b);\n if (rootA == rootB) {\n return;\n }\n\n if (size[rootA] < size[rootB]) {\n parent[rootA] = parent[rootB];\n size[rootB] += size[rootA];\n } else {\n parent[rootB] = parent[rootA];\n size[rootA] += size[rootB];\n }\n size1--;\n System.out.println(Arrays.toString(parent));\n }\n }\n\n private static class SegTree {\n int[] st;\n int[] arr;\n\n public SegTree(int[] arr) {\n this.arr = arr;\n int size = (int) Math.ceil(Math.log(arr.length) / Math.log(2));\n st = new int[(int) ((2 * Math.pow(2, size)) - 1)];\n buildSegmentTree(1, 0, arr.length - 1);\n }\n\n //**********JUST CALL THE CONSTRUCTOR, THIS FUNCTION WILL BE CALLED AUTOMATICALLY******\n private void buildSegmentTree(int index, int L, int R) {\n if (L == R) {\n st[index] = arr[L];\n return;\n }\n\n buildSegmentTree(index * 2, L, (L + R) / 2);\n buildSegmentTree(index * 2 + 1, (L + R) / 2 + 1, R);\n// Replace this line if you want to change the function of the Segment tree.\n st[index] = Math.min(st[index * 2], st[index * 2 + 1]);\n }\n\n //***********We have to use this function **************\n private int Query(int queL, int queR) {\n return Query1(1, 0, arr.length - 1, queL, queR);\n }\n\n //This is a helper function.\n //************* DO NOT USE THIS ****************\n private int Query1(int index, int segL, int segR, int queL, int queR) {\n if (queL > segR || queR < segL) {\n return -1;\n }\n\n if (queL <= segL && queR >= segR) {\n return st[index];\n }\n\n int ans1 = Query1(index * 2, segL, (segL + segR) / 2, queL, queR);\n int ans2 = Query1(index * 2 + 1, (segL + segR) / 2 + 1, segR, queL, queR);\n if (ans1 == -1) {\n return ans2;\n }\n\n if (ans2 == -1) {\n return ans1;\n }\n// Segment tree implemented for range minimum query. Change the below line to change the function.\n return Math.min(ans1, ans2);\n }\n\n private void update(int idx, int val) {\n update1(1, 0, arr.length - 1, idx, val);\n }\n\n private void update1(int node, int queL, int queR, int idx, int val) {\n // idx - index to be updated in the array\n // node - index to be updated in the seg tree\n if (queL == queR) {\n // Leaf node\n arr[idx] += val;\n st[node] += val;\n } else {\n int mid = (queL + queR) / 2;\n if (queL <= idx && idx <= mid) {\n // If idx is in the left child, recurse on the left child\n update1(2 * node, queL, mid, idx, val);\n } else {\n // if idx is in the right child, recurse on the right child\n update1(2 * node + 1, mid + 1, queR, idx, val);\n }\n // Internal node will have the min of both of its children\n st[node] = Math.min(st[2 * node], st[2 * node + 1]);\n }\n }\n }\n\n private static class FastReader {\n InputStream is;\n\n public FastReader(boolean onlineJudge) {\n is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n }\n\n byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n int readByte() {\n if (lenbuf == -1)\n throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(inbuf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0)\n return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n\n int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b))\n ;\n return b;\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n char nextChar() {\n return (char) skip();\n }\n\n String next() {\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 String nextLine() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n char[] next(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 int nextInt() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n long nextLong() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n char[][] nextMatrix(int n, int m) {\n char[][] map = new char[n][];\n for (int i = 0; i < n; i++)\n map[i] = next(m);\n return map;\n }\n\n int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n\n int[][] next2DInt(int n, int m) {\n int[][] arr = new int[n][];\n for (int i = 0; i < n; i++) {\n arr[i] = nextIntArray(m);\n }\n return arr;\n }\n\n long[][] next2DLong(int n, int m) {\n long[][] arr = new long[n][];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLongArray(m);\n }\n return arr;\n }\n\n int[] shuffle(int[] arr) {\n Random r = new Random();\n for (int i = 1, j; i < arr.length; i++) {\n j = r.nextInt(i);\n arr[i] = arr[i] ^ arr[j];\n arr[j] = arr[i] ^ arr[j];\n arr[i] = arr[i] ^ arr[j];\n }\n return arr;\n }\n\n int[] uniq(int[] arr) {\n Arrays.sort(arr);\n int[] rv = new int[arr.length];\n int pos = 0;\n rv[pos++] = arr[0];\n for (int i = 1; i < arr.length; i++) {\n if (arr[i] != arr[i - 1]) {\n rv[pos++] = arr[i];\n }\n }\n return Arrays.copyOf(rv, pos);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a2b4d0175d40a5e73aef7e80875df3a6", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\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 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 Exception {\n\n //int t = in.nextInt();\n int cs = 1;\n int t = 1;\n while (t > 0) {\n //out.print(\"Case #\" + cs + \": \");\n solve();\n t--;\n cs++;\n }\n\n out.flush();\n out.close();\n }\n\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.000000001;\n\n int n;\n int m;\n\n ArrayList[] g;\n int[] a;\n void solve() throws IOException {\n int n = in.nextInt();\n int k = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n long c = (long) n * k;\n long min = Long.MAX_VALUE;\n long max = 0;\n\n for (int i = 0; i < n; i++) {\n long pos = (long) k * i;\n long next = (pos + b) % c;\n long prev = (pos - b) % c;\n long pa = c - a;\n if (prev < 0) prev = (prev + c) % c;\n\n long[] p1 = {a, pa};\n long[] p2 = {next, prev};\n\n for (long pos1 : p1)\n for (long pos2 : p2) {\n long res = check(pos1, pos2, c)\n min = Math.min(min, res);\n max = Math.max(max, res);\n }\n }\n\n out.println(min + \" \" + max);\n }\n\n long check(long pos1, long pos2, long c) {\n long l = pos2 - pos1;\n if (l < 0) l += c;\n if (l == 0) l = c;\n long gcd = gcd(c, l);\n long cnt = c / gcd;\n return cnt;\n }\n\n long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n class Pair implements Comparable {\n\n long a;\n int b;\n\n Pair(long a, int b) {\n this.a = a;\n this.b = b;\n }\n\n public int compareTo(Pair p) {\n if (a != p.a)\n return Long.compare(a, p.a);\n else\n return Integer.compare(b, p.b);\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\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 static class InputReader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public InputReader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public InputReader(String file_name) throws 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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d8aacd98149386300d71f873df9aaf3", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(System.in);\n f(in);\n in.close();\n }\n\n private static void f(Scanner in) {\n long n = in.nextLong();\n long k = in.nextLong();\n int l = in.nextInt();\n long modVal = in.nextLong();\n\n BigInteger maxm = BigInteger.valueOf(2).pow(l);\n\n if (BigInteger.valueOf(k).compareTo(maxm) > 0)\n System.out.println(\"0\");\n else {\n long comb1 = nonConsec1Combination(n, modVal);\n long totalComb = modPow(2, n, modVal);\n long comb2 = (totalComb - comb1 + 2 * modVal) % modVal;\n\n long res = getRes(comb1, comb2, n, k, l, modVal);\n\n System.out.println(res);\n }\n }\n\n private static long getRes(long comb1, long comb2, long n, long k, int l,\n long modVal) {\n long res = 1 % modVal;\n\n for (int i = 0; i < l; i++, k /= 2) {\n if (k % 2 == 1)\n res = (res * comb2) % modVal;\n else\n res = (res * comb1) % modVal;\n }\ns\n return res;\n }\n\n private static long modPow(int base, long power, long modVal) {\n if (power == 0)\n return 1;\n\n long res = modPow(base, power / 2, modVal);\n\n res = (res * res) % modVal;\n\n if (power % 2 == 1)\n res = (res * base) % modVal;\n\n return res;\n }\n\n private static long nonConsec1Combination(long n, long modVal) {\n if (n <= 2)\n return n + 1;\n\n long[][] arr = { { 1, 1 }, { 1, 0 } };\n Matrix base = new Matrix(arr);\n Matrix powered = base.powMod(n - 1, modVal);\n\n long[][] arr2 = { { 3 }, { 2 } };\n Matrix fin = powered.multiplyMod(new Matrix(arr2), modVal);\n\n return fin.getVal(1, 0);\n }\n}\n\nclass Matrix {\n private long[][] grid;\n private int r, c;\n\n public Matrix(long[][] arr) {\n r = arr.length;\n grid = new long[r][];\n\n for (int i = 0; i < r; i++) {\n c = arr[i].length;\n grid[i] = new long[c];\n\n for (int j = 0; j < c; j++)\n grid[i][j] = arr[i][j];\n }\n }\n\n private Matrix(int row, int col) {\n r = row;\n c = col;\n grid = new long[r][c];\n }\n\n public static Matrix getUnitMatrix(int dimension) {\n Matrix res = new Matrix(dimension, dimension);\n\n for (int i = 0; i < res.r; i++)\n res.grid[i][i] = 1;\n\n return res;\n }\n\n public Matrix multiplyMod(Matrix second, long modVal) {\n Matrix res = new Matrix(r, second.c);\n\n for (int i = 0; i < res.r; i++) {\n for (int j = 0; j < res.c; j++) {\n res.grid[i][j] = 0;\n\n for (int k = 0; k < c; k++)\n res.grid[i][j] = (res.grid[i][j] + grid[i][k]\n * second.grid[k][j] + 2 * modVal)\n % modVal;\n }\n }\n\n return res;\n }\n\n public long getVal(int row, int col) {\n return grid[row][col];\n }\n\n public Matrix powMod(long power, long modVal) {\n if (power == 0)\n return getUnitMatrix(r);\n\n Matrix res = powMod(power / 2, modVal);\n\n res = res.multiplyMod(res, modVal);\n\n if (power % 2 == 1)\n res = res.multiplyMod(this, modVal);\n\n return res;\n }\n\n @Override\n public String toString() {\n StringBuilder builder = new StringBuilder();\n\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < c; j++) {\n builder.append(grid[i][j]);\n\n if (j < c - 1)\n builder.append(' ');\n }\n\n builder.append('\\n');\n }\n\n return builder.toString();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "058c2e2eec504e7bfcb3786151b0f257", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import sun.tools.tree.ThisExpression;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class CFA {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n private static final long MOD = 1000L * 1000L * 1000L + 7;\n private static final int[] dx = {0, -1, 0, 1};\n private static final int[] dy = {1, 0, -1, 0};\n private static final String yes = \"Yes\";\n private static final String no = \"No\";\n\n void solve() {\n// int T = nextInt();\n int T = 1;\n for (int i = 0; i < T; i++) {\n helper();\n }\n }\n\n void helper() {\n long n = nextLong();\n long k = nextLong();\n int l = nextInt();\n long m = nextLong();\n long[][] init = {{1, 1}, {1, 0}};\n long[][] fib = powMod(init, n + 1, m);\n long res = 1;\n int highestBit = -1;\n for (int i = 0; i < 64; i++) {\n if (((1L << i) & k) != 0) {\n highestBit = i;\n }\n }\n\n if (highestBit > l - 1) {\n outln(0);\n return;\n }\n\n for (int i = 0; i < l; i++) {\n if (((1L << i) & k) == 0) {\n res = res * fib[0][0];\n res = res % m;\n } else {\n long tmp = powMod(2, n, m);\n tmp = (tmp + m - fib[0][0]) % m;\n res = res * tmp % m;\n }\n }\n outln(res);\n }\n\n // Power Calculate N^M % MOD, N and M can be long (up to 2^64, ~10^18)\n public long powMod(long N, long M, long MOD){//N^M % MOD\n if(M == 0L)\n return 1L;\n long[] hp = new long[64];\n boolean[] bp = new boolean[64];\n hp[0] = N;\n for(int i = 1; i < hp.length; i++) {\n hp[i] = (hp[i - 1] * hp[i - 1]) % MOD;\n }\n for(int j = 0; j < hp.length; j++) {\n if((M & (1L << j)) != 0)\n bp[j] = true;\n }\n long res = 1;\n for(int i = 0;i < bp.length; i++){\n if(bp[i]) {\n res = (res * hp[i]) % MOD;\n }\n }\n return res;\n }\n\n long[][] powMod(long[][] mat, long pow, long Mod) {\n int n = mat.length;\n long[][] res = new long[n][n];\n for (int i = 0; i < n; i++) {\n res[i][i] = 1;\n }\n if (pow == 0) {\n return res;\n }\n if (pow % 2 != 0) {\n res = mat;\n }\n long[][] hf = mult(mat, mat, Mod);\n long[][] tmp = powMod(hf, pow / 2, Mod);\n return mult(tmp, res, Mod);\n }\n\n long[][] mult(long[][] m1, long[][] m2, long Mod) {\n int n = m1.length;\n long[][] res = new long[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n long tmp = 0;\n for (int k = 0; k < n; k++) {\n tmp += m1[i][k] * m2[k][j] % Mod;\n if (tmp >= Mod) {\n tmp -= Mod;\n }\n }\n res[i][j] = tmp;\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\n int gcd(int a, int b) {\n while(a != 0 && b != 0) {\n int c = b;\n b = a % b;\n a = c;\n }\n return a + b;\n }\n private void outln(Object o) {\n out.println(o);\n }\n private void out(Object o) {\n out.print(o);\n }\n private void formatPrint(double val) {\n outln(String.format(\"%.9f%n\", val));\n }\n public CFA() {\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) {\n new CFA();\n }\n\n public long[] nextLongArr(int n) {\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) {\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() {\n return Integer.parseInt(nextToken());\n }\n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d405533a29800a27c8cb94104fefbd3d", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tlong mod = (long) (1e9 + 7);\n\t\n\tlong pow(long n, long k) {\n\t\tif (k == 0)\n\t\t\treturn 1 % mod;\n\t\tlong res = pow(n, k / 2);\n\t\tres = (res * res) % mod;\n\t\tif ((k & 1) != 0)\n\t\t\tres = (res * n) % mod;\n\t\treturn res;\n\t}\n\t\n\tclass Matrix {\n\t\tlong[][] a;\n\n\t\tpublic Matrix(long[][] a) {\n\t\t\tsuper();\n\t\t\tthis.a = a;\n\t\t}\n\t\t\n\t\tMatrix mul(Matrix o) {\n\t\t\tint n = a.length, m = a[0].length, k = o.a[0].length;\n\t\t\tlong[][] res = new long[n][k];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\t\tfor (int ii = 0; ii < m; ii++) {\n\t\t\t\t\t\tres[i][j] = (res[i][j] + a[i][ii] * o.a[ii][j]) % 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}\n\t\n\tMatrix e = new Matrix(new long[][] {{1, 0}, {0, 1}});\n\t\n\tMatrix powm(Matrix m, long n) {\n\t\tif (n == 0) {\n\t\t\treturn e;\n\t\t}\n\t\tMatrix res = powm(m, n / 2);\n\t\tres = res.mul(res);\n\t\tif ((n & 1) != 0) {\n\t\t\tres = res.mul(m);\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tlong f(long n) {\n\t\tlong[][] a = new long[][] {{0, 1}, {1, 1}};\n\t\tMatrix m = new Matrix(a);\n\t\tMatrix res = powm(m, n + 2);\n\t\treturn res.a[0][1];\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tlong n = in.nextLong(), k = in.nextLong();\n\t\tint l = in.nextInt();\n\t\tmod = in.nextLong();\n for (int i = l; i < 64; i++) {\n if (((k << i) & 1) != 0) {\ncout << 0 << endl;\nreturn;\n}\n}\n\t\t\n\t\tlong res = 1 % mod;\n\t\tlong fn = f(n);\n\t\tfor (int i = 0; i < l; i++) {\n\t\t\tlong cur = fn;\n\t\t\tif (((k >> i) & 1) != 0) {\n\t\t\t\tcur = (pow(2, n) - cur + mod) % mod;\n\t\t\t} else {\n\t\t\t}\n\t\t\tres = (res * cur) % mod;\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new FastScanner();\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() {\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 (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\t}\n\n\tpublic static void main(String[] arg) {\n\t\tnew A().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d59d7a4b6c82543e123a46dfcea49f31", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) throws Exception {\n // Scanner in = new Scanner(new File(\"/home/crysoberil/a\"));\n Scanner in = new Scanner(System.in);\n f(in);\n in.close();\n }\n\n private static void f(Scanner in) {\n long n = in.nextLong();\n long k = in.nextLong();\n int l = in.nextInt();\n long modVal = in.nextLong();\n\n BigInteger maxm = BigInteger.valueOf(2).pow(l);\n\n if (BigInteger.valueOf(k).compareTo(maxm) > 0)\n System.out.println(\"0\");\n else {\n long comb1 = nonConsec1Combination(n, modVal);\n long totalComb = modPow(2, n, modVal);\n long comb2 = (totalComb - comb1 + 2 * modVal) % modVal;\n\n long res = getRes(comb1, comb2, n, k, l, modVal);\n\n System.out.println(res);\n }\n }\n\n private static long getRes(long comb1, long comb2, long n, long k, int l,\n long modVal) {\n long res = 1 % modVal;\n\n for (int i = 0; i < l; i++, k /= 2) {\n if (k % 2 == 1)\n res = (res * comb2) % modVal;\n else\n res = (res * comb1) % modVal;\n }\ns\n return res;\n }\n\n private static long modPow(int base, long power, long modVal) {\n if (power == 0)\n return 1;\n\n long res = modPow(base, power / 2, modVal);\n\n res = (res * res) % modVal;\n\n if (power % 2 == 1)\n res = (res * base) % modVal;\n\n return res;\n }\n\n private static long nonConsec1Combination(long n, long modVal) {\n if (n <= 2)\n return n + 1;\n\n long[][] arr = { { 1, 1 }, { 1, 0 } };\n Matrix base = new Matrix(arr);\n Matrix powered = base.powMod(n - 1, modVal);\n\n long[][] arr2 = { { 3 }, { 2 } };\n Matrix fin = powered.multiplyMod(new Matrix(arr2), modVal);\n\n return fin.getVal(1, 0);\n }\n}\n\nclass Matrix {\n private long[][] grid;\n private int r, c;\n\n public Matrix(long[][] arr) {\n r = arr.length;\n grid = new long[r][];\n\n for (int i = 0; i < r; i++) {\n c = arr[i].length;\n grid[i] = new long[c];\n\n for (int j = 0; j < c; j++)\n grid[i][j] = arr[i][j];\n }\n }\n\n private Matrix(int row, int col) {\n r = row;\n c = col;\n grid = new long[r][c];\n }\n\n public static Matrix getUnitMatrix(int dimension) {\n Matrix res = new Matrix(dimension, dimension);\n\n for (int i = 0; i < res.r; i++)\n res.grid[i][i] = 1;\n\n return res;\n }\n\n public Matrix multiplyMod(Matrix second, long modVal) {\n Matrix res = new Matrix(r, second.c);\n\n for (int i = 0; i < res.r; i++) {\n for (int j = 0; j < res.c; j++) {\n res.grid[i][j] = 0;\n\n for (int k = 0; k < c; k++)\n res.grid[i][j] = (res.grid[i][j] + grid[i][k]\n * second.grid[k][j] + 2 * modVal)\n % modVal;\n }\n }\n\n return res;\n }\n\n public long getVal(int row, int col) {\n return grid[row][col];\n }\n\n public Matrix powMod(long power, long modVal) {\n if (power == 0)\n return getUnitMatrix(r);\n\n Matrix res = powMod(power / 2, modVal);\n\n res = res.multiplyMod(res, modVal);\n\n if (power % 2 == 1)\n res = res.multiplyMod(this, modVal);\n\n return res;\n }\n\n @Override\n public String toString() {\n StringBuilder builder = new StringBuilder();\n\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < c; j++) {\n builder.append(grid[i][j]);\n\n if (j < c - 1)\n builder.append(' ');\n }\n\n builder.append('\\n');\n }\n\n return builder.toString();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e51d5a05403cae65e3e1686f38914b03", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Table {\n\n\tfinal String filename = new String(\"Table\").toLowerCase();\n\n\tfinal long mod = 1000000007;\n\tBigInteger bigmod = BigInteger.valueOf(mod);\n\n\tlong inv(int k) {\n\t\treturn BigInteger.valueOf(k).modInverse(bigmod).longValue();\n\t}\n\n\tvoid init() {\n\t\tc[0][0] = 1;\n\t\tfor (int i = 1; i <= 100; i++) {\n\t\t\tc[i][0] = 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]) % mod;\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tlong m = nextLong();\n\t\tint k = nextInt();\n\n\t\tlong[] count = new long[n];\n\t\tArrays.fill(count, m / n);\n\t\tfor (int i = 0; i < m % n; i++) {\n\t\t\tcount[i]++;\n\t\t}\n\t\t\n\t\tlong pow1 = m / n;\n\t\tlong pow2 = pow1 + 1;\n\t\t\n\t\tlong[][] c1 = new long[n + 1][n + 1], c2 = new long[n + 1][n + 1];\n\t\tc1[0][0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tc1[i][0] = 1;\n\t\t\tfor (int j = 1; j <= n; j++) {\n\t\t\t\tc1[i][j] = (c1[i - 1][j - 1] + c1[i - 1][j]) % mod;\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\tc2[i][j] = c1[i][j];\n\t\t\t\t\n\t\t\t\tc1[i][j] = pow(c1[i][j], pow1);\n\t\t\t\tc2[i][j] = pow(c2[i][j], pow2);\n\t\t\t}\n\t\t}\n\n\t\tlong[][] dp = new long[n + 1][k + 1];\n\t\tdp[0][0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tlong[][] c = c1;\n\t\t\tif (count[i - 1] == pow2) {\n\t\t\t\tc = c2;\n\t\t\t}\n\t\t\tfor (int j = 0; j <= k; j++) {\n\t\t\t\tfor (int s = 0; s <= n && s <= j; s++) {\n\t\t\t\t\tdp[i][j] = (dp[i][j] + dp[i - 1][j - s] * c[n][s]) % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tout.println(dp[n][k]);\n\t}\n\n\tprivate long pow(long b, long e) {\n\t\tlong a = b, res = 1;\n\t\twhile (e > 0) {\n\t\t\tif ((e & 1) != 0) {\n\t\t\t\tres = (res * a) % mod;\n\t\t\t}\n\t\t\ta = (a * a) % mod;\n\t\t\te >>= 1;\n\t\t}\n\t\treturn res;\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\t\t\t\n//\t\t\tlong time = System.currentTimeMillis();\n\t\t\tsolve();\n//\t\t\tSystem.err.println(System.currentTimeMillis() - time);\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 Table().run();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf37d07bfed99158987979cca0ab13e0", "src_uid": "9c71c8e031412e2bb21266a53821626a", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\nimport sun.awt.geom.AreaOp.AddOp;\n\nimport com.sun.xml.internal.ws.api.pipe.NextAction;\n\npublic class D {\n FastScanner in;\n PrintWriter out;\n\n int n, k;\n long m;\n final long mod = 1000000007;\n\n long sum(long a, long b) {\n return (a + b) % mod;\n }\n\n long mult(long a, long b) {\n return (a * b) % mod;\n }\n\n long pow(long a, long b) {\n long p = 1;\n while (b > 0) {\n if (b % 2 == 0) {\n a = mult(a, a);\n b /= 2;\n } else {\n p = mult(p, a);\n b--;\n }\n }\n return p;\n }\n\n public void solve() throws IOException {\n n = in.nextInt();\n m = in.nextLong();\n k = in.nextInt();\n long[][] c = new long[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n c[i][0] = c[i][i] = 1;\n for (int j = 1; j < i; j++) {\n c[i][j] = sum(c[i - 1][j], c[i - 1][j - 1]);\n }\n }\n long d[] = new long[k + 1];\n d[0] = 1;\n for (int columnsUsed = 0; columnsUsed < n; ++columnsUsed) {\n long[] newD = new long[k+1];\n for (int useSum = 0; useSum <= n; ++useSum) {\n long cPow = pow(c[n][useSum], (m - columnsUsed + n - 1) / n);\n for (int sumWas = 0; sumWas + useSum <= k; ++sumWas) {\n newD[useSum+sumWas] = sum(newD[useSum + sumWas], mult(d[sumWas], cPow));\n }\n }\n d = newD;\n }\n out.print(d[k]);\n }\n\n public void run() {\n try {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\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\n public static void main(String[] arg) {\n new D().run();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5ab5d3bb695303b7ebe22065df369941", "src_uid": "9c71c8e031412e2bb21266a53821626a", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.security.KeyStore;\nimport java.util.*;\n\n\npublic class A {\n\n long b = 31;\n String fileName = \"\";\n\n\n ////////////////////// SOLUTION SOLUTION SOLUTION //////////////////////////////\n class Elem {\n int num, a, b;\n Elem(int num, int a, int b){\n this.num = num;\n this.a = a;\n this.b = b;\n }\n }\n int INF = Integer.MAX_VALUE;\n long MODULO = 1000*1000*1000+7;\n void solve() throws IOException {\n int n = readInt();\n long m = readLong();\n int k = readInt();\n\n long[][] cnk = new long[n+1][n+1];\n for(int i=1; i<=n; ++i){\n for(int j=0; j<=i; ++j){\n if (j==0) {\n cnk[i][j] = 1;\n continue;\n }\n cnk[i][j] = cnk[i-1][j] + cnk[i-1][j-1];\n cnk[i][j] %= MODULO;\n }\n }\n \n long[] degrees = new long[n];\n for (int i = 0; i < n; ++i) {\n degrees[i] = m / n;\n if (m % n > i) degrees[i]++;\n }\n \n long[][] p = new long[n + 1][n + 1];\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j <= n; ++j) {\n p[i + 1][j] = binPow(cnk[n][j], degrees[i]);\n }\n }\n \n long[][] ans = new long[n+1][n*n+1];\n ans[0][0] = 1;\n for(int i=1; i<=n; ++i){\n for(int j=0; j<=n*n; ++j){\n for(int h=0; h<=n; ++h){\n if (j{\n int a, b;\n Pair(int a, int b){\n this.a = a;\n this.b = b;\n }\n\n @Override\n public int compareTo(Pair o) {\n\n return -Long.compare(Math.max(this.a - this.b, 0), Math.max(o.a - o.b, 0));\n }\n }\n ///////////////////////////////////////////////////////////////////////////////////////////\n\n class SparseTable{\n int[][] rmq;\n int[] logTable;\n int n;\n SparseTable(int[] a){\n n = a.length;\n logTable = new int[n+1];\n for(int i = 2; i <= n; ++i){\n logTable[i] = logTable[i >> 1] + 1;\n }\n rmq = new int[logTable[n] + 1][n];\n for(int i=0; i> bit) & 1;\n }\n class Dsu{\n int[] parent;\n int countSets;\n Dsu(int n){\n countSets = n;\n parent = new int[n];\n for(int i=0; i> bit) & 1;\n }\n boolean isLower(char c){\n return c >= 'a' && c <= 'z';\n }\n\n ////////////////////////////////////////////////////////////\n\n class SegmentTree{\n int[] t;\n int n;\n SegmentTree(int n){\n t = new int[4*n];\n build(new int[n+1], 1, 1, n);\n }\n void build (int a[], int v, int tl, int tr) {\n if (tl == tr)\n t[v] = a[tl];\n else {\n int tm = (tl + tr) / 2;\n build (a, v*2, tl, tm);\n build (a, v*2+1, tm+1, tr);\n }\n }\n\n void update (int v, int tl, int tr, int l, int r, int add) {\n if (l > r)\n return;\n if (l == tl && tr == r)\n t[v] += add;\n else {\n int tm = (tl + tr) / 2;\n update (v*2, tl, tm, l, Math.min(r,tm), add);\n update (v*2+1, tm+1, tr, Math.max(l,tm+1), r, add);\n }\n }\n\n int get (int v, int tl, int tr, int pos) {\n if (tl == tr)\n return t[v];\n int tm = (tl + tr) / 2;\n if (pos <= tm)\n return t[v] + get (v*2, tl, tm, pos);\n else\n return t[v] + get (v*2+1, tm+1, tr, pos);\n }\n }\n class Fenwik {\n long[] t;\n int length;\n\n Fenwik(int[] a) {\n length = a.length + 100;\n t = new long[length];\n\n for (int i = 0; i < a.length; ++i) {\n inc(i, a[i]);\n }\n }\n\n void inc(int ind, int delta) {\n for (; ind < length; ind = ind | (ind + 1)) {\n t[ind] += delta;\n }\n }\n\n long getSum(int r) {\n long sum = 0;\n for (; r >= 0; r = (r & (r + 1)) - 1) {\n sum += t[r];\n }\n return sum;\n }\n }\n int gcd(int a, int b){\n return b == 0 ? a : gcd(b, a%b);\n }\n\n long binPow(long a, long b, long m) {\n if (b == 0) {\n return 1;\n }\n if (b % 2 == 1) {\n return ((a % m) * (binPow(a, b - 1, m) % m)) % m;\n } else {\n long c = binPow(a, b / 2, m);\n return (c * c) % m;\n }\n\n }\n int minInt(int... values) {\n int min = Integer.MAX_VALUE;\n for (int value : values) min = Math.min(min, value);\n return min;\n }\n\n int maxInt(int... values) {\n int max = Integer.MIN_VALUE;\n for (int value : values) max = Math.max(max, value);\n return max;\n }\n public static void main(String[] args) throws NumberFormatException, IOException {\n // TODO Auto-generated method stub\n new A().run();\n }\n\n void run() throws NumberFormatException, IOException {\n solve();\n out.close();\n };\n\n BufferedReader in;\n PrintWriter out;\n\n StringTokenizer tok;\n String delim = \" \";\n Random rnd = new Random();\n\n A() throws FileNotFoundException {\n try {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } catch (Exception e) {\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(fileName + \".out\");\n }\n\n }\n tok = new StringTokenizer(\"\");\n }\n\n String readLine() throws IOException {\n return in.readLine();\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n String nextLine = readLine();\n if (null == nextLine) {\n return null;\n }\n\n tok = new StringTokenizer(nextLine);\n }\n return tok.nextToken();\n }\n\n int readInt() throws NumberFormatException, IOException {\n return Integer.parseInt(readString());\n }\n byte readByte() throws NumberFormatException, IOException {\n return Byte.parseByte(readString());\n }\n int[] readIntArray (int n) throws NumberFormatException, IOException {\n int[] a = new int[n];\n for(int i=0; i>= 1;\n }\n return res;\n }\n\n void solve() throws IOException {\n int n=nextInt();\n long m=nextLong();\n int k=nextInt();\n long[][][] c=new long[120][120][120];\n for(int i=0;i<120;i++)\n for(int j=0;j<=n;j++)\n c[i][0][j]=1;\n long[] count=new long[n];\n for(int i=0;ii)count[i]++;\n count[i]=count[i]%MOD;\n }\n for(int i=1;i<120;i++)\n for(int j=1;j<=i;j++){\n c[i][j][0]=(c[i-1][j][0]+c[i-1][j-1][0])%MOD;\n for(int q=0;q=0;j--){\n if(dp[i][j]!=0)\n for(int x=0;x<=n&&x<=j;x++){\n //dp[i+1][j-x]+=binpow(c[n][x],count[i])*dp[i][j];\n dp[i+1][j-x]+=c[n][x][i+1]*dp[i][j];\n dp[i+1][j-x]%=MOD;\n }\n }\n }\n out.println(dp[n][0]);\n }\n\n public static void main(String[] args) throws IOException {\n new B().run();\n }\n\n void run() throws IOException {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n out = new PrintWriter(new OutputStreamWriter(System.out));\n solve();\n reader.close();\n out.flush();\n\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter out;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4914e93fba7a84a0c94e1747a9d97aea", "src_uid": "9c71c8e031412e2bb21266a53821626a", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class OutOfControls {\n\tstatic int[][] dp;\n\tstatic int n, res;\n\tstatic Scanner scan = new Scanner(System.in);\n\tpublic static void main(String[] args) {\n\t\tn = scan.nextInt();\n\t\tdp = new int[n][n];\n\t\tloop1(0);\n\t\tFloyd1(0);\n\t\tres = 0;\n\t\tLoop1(0);\n\t\tSystem.out.println(res);\n\t}\n\tstatic int Loop1(int i) {\n\t\tLoop2(i, 0);\n\t\treturn i+1=adj.length?0+(++a)-a:b;\n\t a = a=adj.length?0+(++b)-b:c;\n\t\t b=b>=adj.length?0+(++a)-a:b;\n\t\t a = a=adj.length?0+(++a)-a:b;\n\t a = aanswer?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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1338052df4dca5cbf0da156ca8edb8e4", "src_uid": "bbd210065f8b32de048a2d9b1b033ed5", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.nio.charset.StandardCharsets;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class B453 {\n\n\tstatic class Solver {\n\n\t\tint N, a[], pm[], memo[][][];\n\t\tint primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }, gp[] = { 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 };\n\t\tint oo = 987654321, M = 10, mm = 1 << M;\n\n\t\tint dp(int c, int m, int o) {\n\t\t\tif (c == N)\n\t\t\t\treturn 0;\n\t\t\tif (memo[c][m][o] != -1)\n\t\t\t\treturn memo[c][m][o];\n\t\t\tint best = oo;\n\t\t\tfor (int n = 1; n <= 29; n++)\n\t\t\t\tif ((m & pm[n]) == 0)\n\t\t\t\t\tbest = Math.min(best, Math.abs(a[c] - n) + dp(c + 1, pm[n] | m, o));\n\t\t\tbest = Math.min(best, Math.abs(gp[o] - a[c]) + dp(c + 1, m, o + 1));\n\t\t\treturn memo[c][m][o] = best;\n\t\t}\n\n\t\tvoid trace(int c, int m, int o, PrintWriter out) {\n\t\t\tif (c == N)\n\t\t\t\treturn;\n\t\t\tfor (int n = 1; n <= 29; n++) {\n\t\t\t\tif ((m & pm[n]) == 0) {\n\t\t\t\t\tif (memo[c][m][o] - Math.abs(a[c] - n) == dp(c + 1, pm[n] | m, o)) {\n\t\t\t\t\t\tout.print((c == 0 ? \"\" : \" \") + n);\n\t\t\t\t\t\ttrace(c + 1, pm[n] | m, o, out);\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\tout.print((c == 0 ? \"\" : \" \") + gp[o]);\n\t\t\ttrace(c + 1, m, o + 1, out);\n\t\t}\n\n\t\tvoid solve(FastScanner s, PrintWriter out) {\n\t\t\tN = s.nextInt();\n\t\t\ta = s.nextIntArray(N);\n\t\t\tmemo = new int[N][mm][gp.length + 1];\n\t\t\tfor (int[][] rr : memo)\n\t\t\t\tfor (int[] r : rr)\n\t\t\t\t\tArrays.fill(r, -1);\n\n\t\t\tpm = new int[72];\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = primes[i]; j < 72; j += primes[i])\n\t\t\t\t\tpm[j] += 1 << i;\n\n\t\t\tdp(0, 0, 0);\n\t\t\ttrace(0, 0, 0, out);\n\t\t\tout.println();\n\n\t\t}\n\n\t\tint gcd(int a, int b) {\n\t\t\treturn b == 0 ? a : gcd(b, a % b);\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tFastScanner s = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tSolver solver = new Solver();\n\t\tsolver.solve(s, out);\n\n\t\tout.close();\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic FastScanner(File f) throws FileNotFoundException {\n\t\t\tthis(new FileInputStream(f));\n\t\t}\n\n\t\tpublic FastScanner(String s) {\n\t\t\tthis.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));\n\t\t}\n\n\t\tint read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tboolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tboolean isEndline(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isEndline(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndline(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\t// Jacob Garbage\n\n\t\tpublic int[] 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] = this.nextInt();\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic int[][] next2DIntArray(int N, int M) {\n\t\t\tint[][] ret = new int[N][];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = this.nextIntArray(M);\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long[] 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] = this.nextLong();\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long[][] next2DLongArray(int N, int M) {\n\t\t\tlong[][] ret = new long[N][];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = nextLongArray(M);\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int N) {\n\t\t\tdouble[] ret = new double[N];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = this.nextDouble();\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double[][] next2DDoubleArray(int N, int M) {\n\t\t\tdouble[][] ret = new double[N][];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = this.nextDoubleArray(M);\n\t\t\treturn ret;\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0e118eee0a4ebc53b1bbab225f95072b", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nWhat do you think? What do you think?\n1st on Billboard, what do you think of it\nNext is a Grammy, what do you think of it\nHowever you think, I\u2019m sorry, but shit, I have no fcking interest\n*******************************\nI'm standing on top of my Monopoly board\nThat means I'm on top of my game and it don't stop\ntil my hip don't hop anymore\nhttps://www.a2oj.com/Ladder16.html\n*******************************\n300iq as writer = Sad!\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n public class B\n {\n public static void main(String hi[]) throws Exception\n {\n int[] map = new int[20]; int lmao = 0;\n for(int i=2; i < 60; i++)\n if(isPrime(i))\n map[lmao++] = i;\n int[] masks = new int[60];\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(infile.readLine());\n int N = Integer.parseInt(st.nextToken());\n int[] arr = new int[N];\n st = new StringTokenizer(infile.readLine());\n for(int i=0; i < N; i++)\n arr[i] = Integer.parseInt(st.nextToken());\n int[][] dp = new int[N][1<<17];\n dp[0][0] = arr[0]-1;\n Node[][] par = new Node[N][1<<17];\n par[0][0] = new Node(-69, -69, 1);\n for(int v=2; v <= 59; v++)\n {\n int mask = 0;\n for(int b=0; b < 17; b++)\n if(v%map[b] == 0)\n mask |= 1< dp[i-1][mask]+Math.abs(arr[i]-v)))\n {\n dp[i][mask|masks[v]] = dp[i-1][mask]+Math.abs(arr[i]-v);\n par[i][mask|masks[v]] = new Node(i-1, mask, v);\n }\n }\n int[] res = new int[N];\n int currmask = 0;\n for(int mask=1; mask < (1<<17); mask++)\n if(dp[N-1][mask] < dp[N-1][currmask])\n currmask = mask;\n int currdex = N-1;\n while(currdex >= 0)\n {\n Node parent = par[currdex][currmask];\n res[currdex] = parent.val;\n currdex--;\n currmask = parent.mask;\n }\n for(int i=0; i < N; i++)\n System.out.print(res[i]+\" \");\n }\n public static boolean isPrime(long n) \n {\n if(n < 2) return false;\n if(n == 2 || n == 3) return true;\n if(n%2 == 0 || n%3 == 0) return false;\n long sqrtN = (long)Math.sqrt(n)+1;\n for(long i = 6L; i <= sqrtN; i += 6) {\n if(n%(i-1) == 0 || n%(i+1) == 0) return false;\n }\n return true;\n }\n }\n class Node\n {\n public int dex;\n public int mask;\n public int val;\n \n public Node(int a, int b, int c)\n {\n dex = a;\n mask = b;\n val = c;\n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "987eea15c7faad4f4b8e4a3c06743bd0", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main{\n FastScanner in;\n PrintWriter out;\n\n public boolean prime(int x) {\n if (x <= 1) return false;\n if (x <= 3) return true;\n if (x % 2 == 0) return false;\n int d = 3;\n while (d*d <= x) {\n if (x % d == 0) return false;\n d += 2;\n }\n return true;\n }\n\n public int gcd(int a, int b) {\n if (b == 0)\n return a;\n return gcd(b, a%b);\n }\n\n public void solve()\n {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n\n ArrayList plist = new ArrayList<>();\n for (int i = 0; i < 61; i++) {\n if (prime(i))\n plist.add(i);\n }\n\n int[] mask = new int[61];\n for (int i = 0; i < 61; i++)\n mask[i] = 0;\n\n for (int i = 2; i < 61; i++) {\n for (int j = 0; j < plist.size(); j++)\n if ((i % plist.get(j)) == 0) {\n mask[i] |= (1< dp[i][j] + Math.abs(a[i+1]-k)) {\n\n dp[i+1][j|mask[k]] = dp[i][j] + Math.abs(a[i+1]-k);\n put[i+1][j|mask[k]] = k;\n bm[i+1][j|mask[k]] = j;\n }\n\n\n int ans = 1;\n for (int i = 0; i < ppow; i++)\n if (dp[n-1][i] < dp[n-1][ans])\n ans = i;\n\n ArrayList lans = new ArrayList<>();\n for (int i = n-1; i >= 0; i--) {\n lans.add(put[i][ans]);\n ans = bm[i][ans];\n }\n Collections.reverse(lans);\n for (int x : lans)\n out.print(x + \" \");\n }\n\n\n public void run()\n {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ff1bca268c4faed0dfb68f10473f079b", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\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 Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n BLittlePonyAndHarmonyChest solver = new BLittlePonyAndHarmonyChest();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BLittlePonyAndHarmonyChest {\n static int[] primes;\n static int n;\n static int[] arr;\n static int memo;\n\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n n = sc.nextInt();\n arr = new int[n];\n for (int i = 0; i < n; i++)\n arr[i] = sc.nextInt();\n primes = new int[17];\n boolean[] isPrime = new boolean[61];\n Arrays.fill(isPrime, true);\n isPrime[0] = isPrime[1] = false;\n for (int i = 2; i * i <= 61; i++) {\n if (isPrime[i]) {\n for (int j = i * i; j < 61; j += i)\n isPrime[j] = false;\n }\n }\n int j = 0;\n for (int i = 0; i < 61; i++)\n if (isPrime[i])\n primes[j++] = i;\n memo = new int[n][1 << 17 + 1];\n for (int[] x : memo)\n Arrays.fill(x, -1);\n dp(0, 0);\n pw.println(trace(0, 0));\n }\n\n private String trace(int idx, int msk) {\n if (idx == n)\n return \"\";\n int cur = dp(idx, msk);\n for (int a = 0; a < 17; a++) {\n if ((msk & (1 << a)) != 0) continue;\n int temp = primes[a];\n if (cur == Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << a))\n return temp + \" \" + trace(idx + 1, msk | 1 << a);\n for (int b = 0; b < 17; b++) {\n if ((msk & (1 << b)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[b];\n if (cur == Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << b))\n return temp + \" \" + trace(idx + 1, msk | 1 << b);\n for (int c = 0; c < 17; c++) {\n if ((msk & (1 << c)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[c];\n if (cur == Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << c))\n return temp + \" \" + trace(idx + 1, msk | 1 << c);\n for (int d = 0; d < 17; d++) {\n if ((msk & (1 << d)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[d];\n if (cur == Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << d))\n return temp + \" \" + trace(idx + 1, msk | 1 << d);\n for (int e = 0; e < 17; e++) {\n if ((msk & (1 << e)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[e];\n if (cur == Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << e))\n return temp + \" \" + trace(idx + 1, msk | 1 << e);\n }\n }\n }\n }\n }\n return 1 + \" \" + trace(idx + 1, msk);\n }\n\n private int dp(int idx, int msk) {\n if (idx == n)\n return 0;\n if (memo[idx][msk] != -1)\n return memo[idx][msk];\n int min = Integer.MAX_VALUE;\n for (int a = 0; a < 17; a++) {\n if ((msk & (1 << a)) != 0) continue;\n int temp = primes[a];\n min = Math.min(Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << a), min);\n for (int b = 0; b < 17; b++) {\n if ((msk & (1 << b)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[b];\n min = Math.min(Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << b), min);\n for (int c = 0; c < 17; c++) {\n if ((msk & (1 << c)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[c];\n min = Math.min(Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << c), min);\n for (int d = 0; d < 17; d++) {\n if ((msk & (1 << d)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[d];\n min = Math.min(Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << d), min);\n for (int e = 0; e < 17; e++) {\n if ((msk & (1 << e)) != 0 || temp > arr[idx] * 2) continue;\n temp *= primes[e];\n min = Math.min(Math.abs(temp - arr[idx]) + dp(idx + 1, msk | 1 << e), min);\n }\n }\n }\n }\n }\n min = Math.min(min, Math.abs(arr[idx] - 1) + dp(idx + 1, msk));\n return memo[idx][msk] = min;\n }\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(FileReader r) {\n br = new BufferedReader(r);\n }\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4adc20da1d4a4834b33b7e6cb61c401e", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.lang.System.*;\nimport java.util.HashMap; \n\npublic class CheckCalendar{\n\n\tHashMap map;\n\n\tpublic void init()\n\t{\n\t\tmap = new HashMap ();\n\n\t\tmap.put(\"monday\", 1);\n\t\tmap.put(\"tuesday\", 2);\n\t\tmap.put(\"wednesday\", 3);\n\t\tmap.put(\"thursday\", 4);\n\t\tmap.put(\"friday\", 5);\n\t\tmap.put(\"saturday\", 6);\n\t\tmap.put(\"sunday\", 7);\n\n\t}\n\n\tpublic static void main(String[] agrs){\n \n init();\n \n\t\tInteger firstDay = map.get(agrs[0]);\n\t\tInteger secondDay = map.get(agrs[1]);\n\t\tInteger dayMod = (secondDay+7-firstDay)%7;\n\n\t\tif(dayMod==0 || dayMod==2 || dayMod==3){\n\n\t\t\tSystem.out.println(\"YES\");\n\t\t}else{\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "53f6c0e7376a2cfac71d66e0d7a1d1ae", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.lang.System.*;\nimport java.util.HashMap; \n\npublic class CheckCalendar{\n\n\tHashMap map;\n\n\tpublic init()\n\t{\n\t\tmap = new HashMap ();\n\n\t\tmap.put(\"monday\", 1);\n\t\tmap.put(\"tuesday\", 2);\n\t\tmap.put(\"wednesday\", 3);\n\t\tmap.put(\"thursday\", 4);\n\t\tmap.put(\"friday\", 5);\n\t\tmap.put(\"saturday\", 6);\n\t\tmap.put(\"sunday\", 7);\n\n\t}\n\n\tpublic static void main(String[] agrs){\n \n init();\n \n\t\tInteger firstDay = map.get(agrs[0]);\n\t\tInteger secondDay = map.get(agrs[1]);\n\t\tInteger dayMod = (secondDay+7-firstDay)%7;\n\n\t\tif(dayMod==0 || dayMod==2 || dayMod==3){\n\n\t\t\tSystem.out.println(\"YES\");\n\t\t}else{\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "99bdf16b2accb7c764ce346f32e51202", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\tString a[]={\"monday\",\"tuesday\",\"wednesday\",\"thursday\",\"friday\",\"saturday\",\"sunday\"};\n\tString m=ob.nextInt();\n\tString n=ob.nextInt();\n\tint k,j;\n\tfor(int i=0;i<7;i++)\n\t{\n\t\tif(a[i].equals(m))\n\t\tk=i;\n\t\tif(a[i].equals(n))\n\t\tj=i;\n\t}\n\tint d=0;// your code goes here\n\tif(k=0;i--) {\n//\t\t\t\tret[i]=a[i];\n//\t\t\t\tret[i]%=f;\n//\t\t\t\tret[i]*=b[i];\n//\t\t\t\tret[i]%=f;\n//\t\t\t}\n//\t\t\tlong v = 0;\n//\t\t\tfor(long tmp:ret) {\n//\t\t\t\tv+=tmp;\n//\t\t\t\tv%=f;\n//\t\t\t}\n//\t\t\tout.println(v);\n\t\t\tint n = in.nextInt();\n\t\t\tint m = in.nextInt();\n\t\t\tint s = 0;\n\t\t\tint need[] = new int[n+1];\n\t\t\tfor(int i=1;i<=n;i++) {\n\t\t\t\tneed[i] = in.nextInt();\n\t\t\t\ts+=need[i];\n\t\t\t}\n\t\t\tSet[] g = new HashSet[n+1];\n\t\t\tfor(int i=1;i<=n;i++) g[i] = new HashSet();\n\t\t\tfor(int i=0;i[] g, int mid, int need[], int all) {\n\t\t\tint offer[] = new int[need.length];\n\t\t\tfor(int i=1;i<=Math.min(mid, g.length-1);i++) {\n\t\t\t\tfor(int j:g[i]) offer[j] = i;\n\t\t\t}\n\t\t\tArrayList arr = new ArrayList();\n\t\t\tfor(int i=1;i=2*all;\n\t\t\tint cur = 0; int p=0;\n\t\t\tfor(int i=1;i<=mid;i++) {\n\t\t\t\tcur++;\n\t\t\t\twhile(p=num) {\n\t\t\t\t\t\tcur-=num;\n\t\t\t\t\t\tall-=num;\n\t\t\t\t\t\ttemp[item]=0;\n\t\t\t\t\t}else if(cur=2*all;\n\t\t}\n\t\tclass offer implements Comparable{\n\t\t\tint item; int day;\n\t\t\tpublic offer(int a, int b) {\n\t\t\t\titem = a; day=b;\n\t\t\t}\n\t\t\t@Override\n\t\t\tpublic int compareTo(offer t) {\t\t\t\t\n\t\t\t\treturn this.day-t.day;\n\t\t\t}\t\t\t\n\t\t}\n\t\tclass pair implements Comparable{\n\t\t\tLong val; int idx;\n\t\t\tpublic pair(long a, int b) {\n\t\t\t\tval=a;idx=b;\n\t\t\t}\n\t\t\t@Override\n\t\t\tpublic int compareTo(pair t) {\t\t\t\t\n\t\t\t\treturn this.val.compareTo(t.val);\n\t\t\t}\t\t\t\n\t\t}\n\t\tboolean is_prime(int a) {\n\t\t\tif(a==2||a==3) return true;\n\t\t\tfor(int i=2;i<=Math.sqrt(a);i++) {\n\t\t\t\tif(a%i==0) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t \n\t\tclass TreeNode {\n\t\t\tint val;\n\t\t\tTreeNode left;\n\t\t\tTreeNode right;\n\t\t\tTreeNode(int x) { val = x; }\n\t\t}\n\t\n\t\tpublic int GCD(int a, int b) {\n\t\t if (b==0) return a;\n\t\t return GCD(b,a%b);\n\t\t}\n\t}\n\t\n\t\n static class ArrayUtils {\n static final long seed = System.nanoTime();\n static final Random rand = new Random(seed);\n \n public static void sort(int[] a) {\n shuffle(a);\n Arrays.sort(a);\n }\n \n public static void shuffle(int[] a) {\n for (int i = 0; i < a.length; i++) {\n int j = rand.nextInt(i + 1);\n int t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n }\n \n public static void sort(long[] a) {\n shuffle(a);\n Arrays.sort(a);\n }\n \n public static void shuffle(long[] a) {\n for (int i = 0; i < a.length; i++) {\n int j = rand.nextInt(i + 1);\n long t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n } \n \n }\t\n\tstatic class BIT{\n\t\tint arr[];\n\t\tint n;\n\t\tpublic BIT(int a) {\n\t\t\tn=a;\n\t\t\tarr = new int[n];\n\t\t}\n\t\tint sum(int p) {\n\t\t\tint s=0;\n\t\t\twhile(p>0) {\n\t\t\t\ts+=arr[p];\n\t\t\t\tp-=p&(-p);\n\t\t\t}\n\t\t\treturn s;\n\t\t}\n\t\tvoid add(int p, int v) {\n\t\t\twhile(p implements Iterable {\n\t\tprivate int maxN;\n\t\tprivate int n;\n\t\tprivate int[] pq;\n\t\tprivate int[] qp;\n\t\tprivate Key[] keys;\n\t\tprivate Comparator comparator;\n\t\t\n\t\tpublic MinHeap(int capacity){\n\t\t\tif (capacity < 0) throw new IllegalArgumentException();\n\t\t\tthis.maxN = capacity;\n\t\t\tn=0;\n\t\t\tpq = new int[maxN+1];\n\t\t\tqp = new int[maxN+1];\n\t\t\tkeys = (Key[]) new Object[capacity+1];\n\t\t\tArrays.fill(qp, -1);\n\t\t}\n\t\t\n\t\tpublic MinHeap(int capacity, Comparator c){\n\t\t\tif (capacity < 0) throw new IllegalArgumentException();\n\t\t\tthis.maxN = capacity;\n\t\t\tn=0;\n\t\t\tpq = new int[maxN+1];\n\t\t\tqp = new int[maxN+1];\n\t\t\tkeys = (Key[]) new Object[capacity+1];\n\t\t\tArrays.fill(qp, -1);\n\t\t\tcomparator = c;\n\t\t}\t\t\t\n\t\tpublic boolean isEmpty()\t{ return n==0; \t}\n\t\tpublic int size()\t\t\t{ return n;\t\t}\n\t\tpublic boolean contains(int i) {\n\t if (i < 0 || i >= maxN) throw new IllegalArgumentException();\n\t return qp[i] != -1;\n\t\t}\t\n\t\tpublic int peekIdx() {\n\t if (n == 0) throw new NoSuchElementException(\"Priority queue underflow\");\n\t return pq[1];\t\t\n\t\t}\t\n\t\tpublic Key peek(){\n\t\t\tif(isEmpty()) throw new NoSuchElementException(\"Priority queue underflow\");\n\t\t\treturn keys[pq[1]];\n\t\t}\n\t\tpublic int poll(){\n\t\t\tif(isEmpty()) throw new NoSuchElementException(\"Priority queue underflow\");\n\t\t\tint min = pq[1];\n\t\t\texch(1,n--);\n\t\t\tdown(1);\n\t\t\tassert min==pq[n+1];\n\t\t\tqp[min] = -1;\n\t\t\tkeys[min] = null;\t\t\n\t\t\tpq[n+1] = -1;\n\t\t\treturn min;\n\t\t}\n\t public void update(int i, Key key) {\n\t if (i < 0 || i >= maxN) throw new IllegalArgumentException();\n\t if (!contains(i)) {\n\t \tthis.add(i, key);\n\t }else {\n\t \tkeys[i] = key;\n\t \tup(qp[i]);\n\t \tdown(qp[i]);\n\t }\n\t }\t\n\t\tprivate void add(int i, Key x){\n\t if (i < 0 || i >= maxN) throw new IllegalArgumentException();\n\t if (contains(i)) throw new IllegalArgumentException(\"index is already in the priority queue\");\n\t n++;\n\t qp[i] = n;\n\t pq[n] = i;\n\t keys[i] = x;\n\t up(n);\n\t\t}\n\t\tprivate void up(int k){\n\t\t\twhile(k>1&&less(k,k/2)){\n\t\t\t\texch(k,k/2);\n\t\t\t\tk/=2;\n\t\t\t}\n\t\t}\n\t\tprivate void down(int k){\n\t\t\twhile(2*k<=n){\n\t\t\t\tint j=2*k;\n\t\t\t\tif(j) keys[pq[i]]).compareTo(keys[pq[j]]) < 0;\n\t }\n\t else {\n\t return comparator.compare(keys[pq[i]], keys[pq[j]]) < 0;\n\t }\n\t\t}\n \n\t\tpublic void exch(int i, int j){\n\t int swap = pq[i];\n\t pq[i] = pq[j];\n\t pq[j] = swap;\n\t qp[pq[i]] = i;\n\t qp[pq[j]] = j;\n\t\t}\n \n\t\t@Override\n\t\tpublic Iterator iterator() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn null;\n\t\t}\n\t} \t\n \n private static class InputReader\n {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int zcurChar;\n private int znumChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream)\n {\n this.stream = stream;\n }\n \n public int read()\n {\n if (znumChars == -1)\n throw new InputMismatchException();\n if (zcurChar >= znumChars)\n {\n \tzcurChar = 0;\n try\n {\n znumChars = stream.read(buf);\n } catch (IOException e)\n {\n throw new InputMismatchException();\n }\n if (znumChars <= 0)\n return -1;\n }\n return buf[zcurChar++];\n }\n \n public int nextInt()\n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public String nextString()\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 } while (!isSpaceChar(c));\n return res.toString();\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 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 do\n {\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 {\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 nextString();\n }\n \n public interface SpaceCharFilter\n {\n public boolean isSpaceChar(int ch);\n }\n public int[] readIntArray(int n) {\n int[] ret = new int[n];\n for (int i = 0; i < n; i++) {\n ret[i] = nextInt();\n }\n return ret;\n } \n } \n \n\tstatic class Dumper {\n\t\tstatic void print_int_arr(int[] arr) {\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t\tSystem.out.println(\"---------------------\");\n\t\t}\n \n\t\tstatic void print_char_arr(char[] arr) {\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t\tSystem.out.println(\"---------------------\");\n\t\t}\n \n\t\tstatic void print_double_arr(double[] arr) {\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t\tSystem.out.println(\"---------------------\");\n\t\t}\n \n\t\tstatic void print_2d_arr(int[][] arr, int x, int y) {\n\t\t\tfor (int i = 0; i < x; i++) {\n\t\t\t\tfor (int j = 0; j < y; j++) {\n\t\t\t\t\tSystem.out.print(arr[i][j] + \" \");\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t\tSystem.out.println(\"---------------------\");\n\t\t}\n \n\t\tstatic void print_2d_arr(boolean[][] arr, int x, int y) {\n\t\t\tfor (int i = 0; i < x; i++) {\n\t\t\t\tfor (int j = 0; j < y; j++) {\n\t\t\t\t\tSystem.out.print(arr[i][j] + \" \");\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t\tSystem.out.println(\"---------------------\");\n\t\t}\n \n\t\tstatic void print(Object o) {\n\t\t\tSystem.out.println(o.toString());\n\t\t}\n \n\t\tstatic void getc() {\n\t\t\tSystem.out.println(\"here\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3a6f995e8d4552de13d55a506a475e0e", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class ProblemF_1 {\n\n public static InputStream inputStream = System.in;\n\n public static OutputStream outputStream = System.out;\n\n public static void main(String[] args) {\n MyScanner scanner = new MyScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n\n int n = scanner.nextInt();\n int m = scanner.nextInt();\n List amounts = new ArrayList<>();\n int s = 0;\n for (int i = 0; i < n; i++) {\n int x = scanner.nextInt();\n s = s + x;\n amounts.add(x);\n }\n Map map = new HashMap<>();\n for (int i = 0; i < m; i++) {\n int d = scanner.nextInt();\n int t = scanner.nextInt();\n if (map.containsKey(t)) {\n if (map.get(t) < d) {\n map.put(t, d);\n }\n } else {\n map.put(t, d);\n }\n }\n\n Map> sales = new HashMap<>();\n for (Map.Entry entry : map.entrySet()) {\n if (!sales.containsKey(entry.getKey())) {\n sales.put(entry.getValue(), new ArrayList<>());\n }\n sales.get(entry.getValue()).add(entry.getKey());\n }\n\n\n int x = 0;\n int ans = 0;\n for (int i = 1; i <= 1000; i++) {\n x++;\n ans = i;\n if (sales.containsKey(i)) {\n for (int t : sales.get(i)) {\n if (x > amounts.get(t - 1)) {\n s = s - amounts.get(t - 1);\n x = x - amounts.get(t - 1);\n } else {\n s = s - x;\n x = 0;\n }\n }\n }\n if (s * 2 <= x) {\n break;\n }\n }\n\n out.println(ans);\n\n\n out.flush();\n }\n\n private static class MyScanner {\n private BufferedReader bufferedReader;\n private StringTokenizer stringTokenizer;\n\n private MyScanner(InputStream inputStream) {\n bufferedReader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n private String next() {\n while (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\n private long nextLong() {\n return Long.parseLong(next());\n }\n\n private double nextDouble() {\n return Double.parseDouble(next());\n }\n\n private String nextLine() {\n String str = \"\";\n try {\n str = bufferedReader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n private static class Pair {\n\n private F first;\n\n private S second;\n\n public Pair() {\n }\n\n public Pair(F first, S second) {\n this.first = first;\n this.second = second;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b7ab934a9c226ac829d86b91b71eaca", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n public static int n, m;\n public static int[] arr;\n public static TreeSet[] set;\n public static boolean ok(int day) {\n int[] clone = arr.clone();\n int[] last = new int[n];\n for (int i = 0; i < n; i++) {\n Integer res = set[i].floor(day);\n last[i] = (res == null) ? -1 : res;\n }\n int burles = 0;\n for (int i = 0; i <= day; i++) {\n burles++;\n for (int j = 0; j < n; j++) {\n if (last[j] == i) {\n while (clone[j] > 0 && burles > 0) {\n burles--;\n clone[j]--;\n }\n }\n }\n }\n for (int i = 0; i < n; i++) {\n while (clone[i] > 0) {\n clone[i]--;\n burles -= 2;\n }\n }\n return burles >= 0;\n }\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n m = in.nextInt();\n arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = in.nextInt();\n }\n set = new TreeSet[n];\n for (int i = 0; i < n; i++) {\n set[i] = new TreeSet<>();\n }\n for (int i = 0; i < m; i++) {\n int d = in.nextInt() - 1;\n int t = in.nextInt() - 1;\n set[t].add(d);\n }\n for (int i = 0; i <= 2000; i++) {\n if (ok(i)) {\n System.out.println(i + 1);\n break;\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "35c7e8519e83df9f062bf622d3614951", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Locale;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\nimport org.junit.Test;\n\npublic class Solution {\n\n\tprivate static FastReader in;\n\tprivate static PrintStream out;\n\tprivate static int n, m;\n\tprivate static int[] k;\n\tprivate static List[] o;\n\tprivate static int[][] lasto;\n\tprivate final static int MAX = 2000;\n\tprivate static int total;\n\n\tpublic static void main(String[] args) {\n\t\tin = new FastReader();\n\t\tout = System.out;\n\t\tsolve();\n\t}\n\n\tprotected static void solve() {\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\tk = new int[n + 1];\n\t\ttotal = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tk[i] = in.nextInt();\n\t\t\ttotal += k[i];\n\t\t}\n\t\to = new ArrayList[MAX + 1];\n\t\tlasto = new int[n][2 * total + 2];\n\t\tfor (int i = 0; i < o.length; i++)\n\t\t\to[i] = new ArrayList();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint day = in.nextInt();\n\t\t\tint product = in.nextInt() - 1;\n\t\t\to[day].add(product);\n\t\t\tlasto[product][day] = day;\n\t\t}\n\t\tint ret = solveLine();\n\t\tout.printf(Locale.ENGLISH, \"%d%n\", ret);\n\t}\n\n\tprivate static int solveLine() {\n\t\tfor (int product = 0; product < n; product++) {\n\t\t\tint last = 0;\n\t\t\tfor (int day = 0; day < lasto[0].length; day++) {\n\t\t\t\tif (lasto[product][day] == 0)\n\t\t\t\t\tlasto[product][day] = last;\n\t\t\t\telse\n\t\t\t\t\tlast = lasto[product][day];\n\t\t\t}\n\t\t}\n\n\t\tfor (int day = 2 * total; day >= 1; day--) {\n\t\t\tint pending = 0;\n\t\t\tint[] cost = new int[2 * total + 2];\n\t\t\tfor (int product = 0; product < n; product++) {\n\t\t\t\tpending += k[product] * 2;\n\t\t\t\tif (lasto[product][day] != 0) {\n\t\t\t\t\tpending -= k[product];\n\t\t\t\t\tcost[lasto[product][day]] += k[product];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (day < pending) return day + 1;\n\t\t\tint money = 0;\n\t\t\tpending = 2 * total;\n\t\t\tfor (int i = 1; i <= day; i++ ) {\n\t\t\t\tmoney++;\n\t\t\t\tif (cost[i] > 0) {\n\t\t\t\t\tif (cost[i] > money) cost[i] = money;\n\t\t\t\t\t\tpending -= (2 * cost[i]);\n\t\t\t\t\t\tmoney -= cost[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (money < pending) return day + 1;\n\t\t}\n//\t\tthrow new RuntimeException();\n\t\treturn 1;\n\t}\n\n\n\tprotected static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FastReader(InputStream in) {\n\t\t\tthis(new InputStreamReader(in));\n\t\t}\n\n\t\tpublic FastReader(InputStreamReader in) {\n\t\t\tbr = new BufferedReader((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\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e61607f258e667ea7b5a4f4ff31c479e", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\n\npublic class Main {\n\n\tstatic PrintWriter out;\n\tstatic InputReader ir;\n\n\tstatic void solve() {\n\t\tint n = ir.nextInt();\n\t\tint t = ir.nextInt();\n\t\tint[][] a = new int[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ir.nextIntArray(2);\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 1 << n; i++) {\n\t\t\tint[] ct = new int[4];\n\t\t\tint tot = 0;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif ((1 << j & i) != 0) {\n\t\t\t\t\ttot += a[j][0];\n\t\t\t\t\tct[a[j][1]]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (tot != t)\n\t\t\t\tcontinue;\n\t\t\tlong[][][][] dp = new long[ct[1] + 1][ct[2] + 1][ct[3] + 1][4];\n\t\t\tdp[0][0][0][0] = 1;\n\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tfor (int k = 0; k <= ct[1]; k++) {\n\t\t\t\t\tfor (int l = 0; l <= ct[2]; l++) {\n\t\t\t\t\t\tif (k + l > j)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tfor (int m = 0; m < 3; m++) {\n\t\t\t\t\t\t\tfor (int o = 0; o <= 3; o++) {\n\t\t\t\t\t\t\t\tif (m == o)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tif (o == 1 && k == ct[1])\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tif (o == 2 && l == ct[2])\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tif (o == 3 && j - k - l == ct[3])\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tif (o == 1) {\n\t\t\t\t\t\t\t\t\tdp[k + 1][l][j - k - l][1] = add(dp[k + 1][l][j - k - l][1],\n\t\t\t\t\t\t\t\t\t\t\tdp[k][l][j - k - l][m]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (o == 2) {\n\t\t\t\t\t\t\t\t\tdp[k][l + 1][j - k - l][2] = add(dp[k][l + 1][j - k - l][2],\n\t\t\t\t\t\t\t\t\t\t\tdp[k][l][j - k - l][m]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (o == 3) {\n\t\t\t\t\t\t\t\t\tdp[k][l][j - k - l + 1][3] = add(dp[k + 1][l][j - k - l][3],\n\t\t\t\t\t\t\t\t\t\t\tdp[k][l][j - k - l][m]);\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\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int k = 0; k <= ct[1]; k++) {\n\t\t\t\tfor (int l = 0; l <= ct[2]; l++) {\n\t\t\t\t\tif (k + l > n)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int m = 0; m <= 3; m++)\n\t\t\t\t\t\tres = add(res, dp[k][l][n - k - l][m]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tstatic long mod = (long) 1e9 + 7;\n\n\tstatic long add(long a, long b) {\n\t\treturn (a + b) % mod;\n\t}\n\n\tstatic long sub(long a, long b) {\n\t\tlong d = a - b;\n\t\twhile (d < 0)\n\t\t\td += mod;\n\t\treturn d;\n\t}\n\n\tstatic long mul(long a, long b) {\n\t\treturn a * b % mod;\n\t}\n\n\tstatic long div(long a, long b) {\n\t\treturn a * mod_inverse(b) % mod;\n\t}\n\n\tprivate static long[] fact(int n) {\n\t\tlong[] ret = new long[n + 1];\n\t\tret[0] = 1 % mod;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tret[i] = mul(ret[i - 1], i);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate static long[] factInv(int n) {\n\t\tlong[] ret = new long[n + 1];\n\t\tret[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tret[i] = div(ret[i - 1], i);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tpublic static long comb(int n, int m, long[] fact, long[] factInv) {\n\t\tlong ret = fact[n];\n\t\tret = mul(ret, factInv[m]);\n\t\tret = mul(ret, factInv[n - m]);\n\t\treturn ret;\n\t}\n\n\tpublic static long[][] stirling(int n) {\n\t\tlong[][] ret = new long[n + 1][n + 1];\n\t\tret[0][0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfor (int j = 1; j <= i; j++)\n\t\t\t\tret[i][j] = add(ret[i - 1][j - 1], mul(ret[i - 1][j], j));\n\t\treturn ret;\n\t}\n\n\tpublic static long mod_inverse(long a) {\n\t\tlong[] ret = extgcd(a, mod);\n\t\treturn add(mod, ret[0] % mod);\n\t}\n\n\tpublic static long[] extgcd(long a, long b) {\n\t\tlong[] ret = new long[3];\n\t\tret[2] = _extgcd(a, b, ret);\n\t\treturn ret;\n\t}\n\n\tprivate static long _extgcd(long a, long b, long[] x) {\n\t\tlong g = a;\n\t\tx[0] = 1;\n\t\tx[1] = 0;\n\t\tif (b != 0) {\n\t\t\tg = _extgcd(b, a % b, x);\n\t\t\tlong temp = x[0];\n\t\t\tx[0] = x[1];\n\t\t\tx[1] = temp;\n\t\t\tx[1] -= (a / b) * x[0];\n\t\t}\n\t\treturn g;\n\t}\n\n\tstatic long modpow(long a, long n) {\n\t\tlong res = 1;\n\t\twhile (n > 0) {\n\t\t\tif ((n & 1) != 0)\n\t\t\t\tres = res * a % mod;\n\t\t\ta = a * a % mod;\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tir = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.flush();\n\t}\n\n\tstatic class InputReader {\n\n\t\tprivate InputStream in;\n\t\tprivate byte[] buffer = new byte[1024];\n\t\tprivate int curbuf;\n\t\tprivate int lenbuf;\n\n\t\tpublic InputReader(InputStream in) {\n\t\t\tthis.in = in;\n\t\t\tthis.curbuf = this.lenbuf = 0;\n\t\t}\n\n\t\tpublic boolean hasNextByte() {\n\t\t\tif (curbuf >= lenbuf) {\n\t\t\t\tcurbuf = 0;\n\t\t\t\ttry {\n\t\t\t\t\tlenbuf = in.read(buffer);\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 false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tprivate int readByte() {\n\t\t\tif (hasNextByte())\n\t\t\t\treturn buffer[curbuf++];\n\t\t\telse\n\t\t\t\treturn -1;\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\n\t\tprivate void skip() {\n\t\t\twhile (hasNextByte() && isSpaceChar(buffer[curbuf]))\n\t\t\t\tcurbuf++;\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tskip();\n\t\t\treturn hasNextByte();\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif (!hasNext())\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tint b = readByte();\n\t\t\twhile (!isSpaceChar(b)) {\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tif (!hasNext())\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\tint c = readByte();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = readByte();\n\t\t\tboolean minus = false;\n\t\t\tif (c == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tc = readByte();\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 = res * 10 + c - '0';\n\t\t\t\tc = readByte();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn (minus) ? -res : res;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tif (!hasNext())\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\tint c = readByte();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = readByte();\n\t\t\tboolean minus = false;\n\t\t\tif (c == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tc = readByte();\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 = res * 10 + c - '0';\n\t\t\t\tc = readByte();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn (minus) ? -res : res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\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\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic char[][] nextCharMap(int n, int m) {\n\t\t\tchar[][] map = new char[n][m];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tmap[i] = next().toCharArray();\n\t\t\treturn map;\n\t\t}\n\t}\n\n\tstatic void tr(Object... o) {\n\t\tout.println(Arrays.deepToString(o));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "138bae7ab1d75e419f9691e2510bfc22", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class G1PlaylistForPolycarpEasyVersion {\n public static final int GENRES_COUNT = 3;\n private int songsCount;\n private int totalDuration;\n private Song[] songs;\n private int[][][] mem;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n songsCount = in.nextInt();\n totalDuration = in.nextInt();\n\n songs = new Song[songsCount];\n\n for (int i = 0; i < songsCount; i++) {\n songs[i] = new Song(in.nextInt(), in.nextInt() - 1);\n }\n\n int ret = 0;\n int chosenSongs = 0;\n\n mem = new int[GENRES_COUNT + 1][][];\n for (int i = 0; i < GENRES_COUNT; i++) {\n mem[i] = new int[totalDuration + 1][];\n\n for (int j = 0; j <= totalDuration; j++) {\n mem[i][j] = new int[1 << songsCount];\n\n for (int k = 0; k < 1 << songsCount; k++) {\n mem[i][j][k] = -1;\n }\n }\n }\n\n for (int i = 0; i < songsCount; i++) {\n chosenSongs = 1 << i;\n ret += search(totalDuration - songs[i].duration, songs[i].genre, chosenSongs);\n }\n\n out.println(ret);\n }\n\n private int search(int timeLeft, int lastGenre, int chosen) {\n if (timeLeft < 0) {\n return 0;\n }\n\n if (timeLeft == 0) {\n return 1;\n }\n\n if (mem[lastGenre][timeLeft][chosen] != -1) {\n return mem[timeLeft][lastGenre][chosen];\n }\n\n int ret = 0;\n\n for (int i = 0; i < songsCount; i++) {\n if (((1 << i) & chosen) == 0 && songs[i].genre != lastGenre) {\n ret += search(timeLeft - songs[i].duration, songs[i].genre, chosen | 1 << i);\n }\n }\n\n mem[lastGenre][timeLeft][chosen] = ret;\n\n return ret;\n }\n\n class Song {\n public int duration;\n public int genre;\n\n public Song(int duration, int genre) {\n this.duration = duration;\n this.genre = genre;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "25b18d6871faea7914feb241707d577e", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class G1PlaylistForPolycarpEasyVersion {\n private int songsCount;\n private int totalDuration;\n private Song songs;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n songsCount = in.nextInt();\n totalDuration = in.nextInt();\n\n songs = new Song[songsCount];\n\n for (int i = 0; i < songsCount; i++) {\n songs[i] = new Song(in.nextInt(), in.nextInt());\n }\n\n int ret = 0;\n int chosenSongs = 0;\n\n for (int i = 0; i < songsCount; i++) {\n chosenSongs = 1 << i;\n ret += search(totalDuration - songs[i].duration, songs[i], chosenSongs);\n }\n\n out.println(ret);\n }\n\n private int search(int timeLeft, Song prev, int chosen) {\n if (timeLeft < 0) {\n return 0;\n }\n\n if (timeLeft == 0) {\n return 1;\n }\n\n int ret = 0;\n\n for (int i = 0; i < songsCount; i++) {\n if (((1 << i) & chosen) == 0 && songs[i].genre != prev.genre) {\n ret += search(timeLeft - songs[i].duration, songs[i], chosen | 1 << i);\n }\n }\n\n return ret;\n }\n\n class Song {\n public int duration;\n public int genre;\n\n public Song(int duration, int genre) {\n this.duration = duration;\n this.genre = genre;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5c05c3a88d914180a12e9e86c35311ba", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.concurrent.ThreadLocalRandom;\n\npublic class Main2 {\n\n static int mod = 1000000007;\n static FastScanner scanner;\n\n\n public static void main(String[] args) {\n scanner = new FastScanner();\n int n = scanner.nextInt();\n int T = scanner.nextInt();\n\n int[][] songs = new int[n][2];\n for (int i = 0; i < n; i++) {\n songs[i][0] = scanner.nextInt();\n songs[i][1] = scanner.nextInt() - 1;\n }\n\n int[][][] dp = new int[65536][3][T + 10];\n int mask = 1;\n long res = 0;\n\n for (int i = 0; i < n; i++) {\n dp[mask][songs[i][1]][songs[i][0]] = 1;\n if (songs[i][0] == T) res++;\n mask <<= 1;\n }\n for (int i = 1; i < n; i++) {\n int[][][] cdp = new int[65536][3][T + 10];\n mask = 1;\n for (int k = 0; k < n; k++) {\n int cg = songs[k][1];\n\n int g1,g2;\n if (cg == 0) {g1 = 1; g2 = 2;}\n else if (cg == 1) {g1 = 0; g2 = 2;}\n else {g1 = 0; g2 = 1;}\n\n for (int j = 1; j < 65536; j++) {\n if ((j & mask) != 0) continue;\n for (int t = 0; t <= T - songs[k][0]; t++) {\n cdp[j | mask][cg][t + songs[k][0]] = ((cdp[j | mask][cg][t + songs[k][0]]) + (dp[j][g1][t] + dp[j][g2][t]) % mod) % mod;\n }\n }\n mask <<= 1;\n }\n for (int ii = 0; ii < 65536; ii++) for (int jj = 0; jj < 3; jj++) res += cdp[ii][jj][T];\n dp = cdp;\n }\n System.out.println(res);\n }\n\n static long test(long[] b, long c, int maxSkipped, int startWith) {\n int skipped = 0;\n long lastSkipped = b[0];\n for (int i = startWith; i < b.length; i++) {\n long expected = b[0] + c * (i - skipped);\n if (b[i] != expected) {\n skipped++;\n lastSkipped = b[i];\n if (skipped > maxSkipped) {\n return Long.MAX_VALUE;\n }\n }\n }\n return lastSkipped;\n }\n\n static boolean test2(long[] b, long c) {\n for (int i = 1; i < b.length; i++) {\n long expected = b[1] + c * (i - 1);\n if (b[i] != expected) {\n return false;\n }\n }\n return true;\n }\n\n// 5 5\n// 1 1 5 2 3\n\n\n static class WithIdx implements Comparable {\n int val;\n int idx;\n\n public WithIdx(int val, int idx) {\n this.val = val;\n this.idx = idx;\n }\n\n @Override\n public int compareTo(WithIdx o) {\n if (val == o.val) {\n return Integer.compare(idx, o.idx);\n }\n return -Integer.compare(val, o.val);\n }\n }\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n String nextLine() {\n try {\n return br.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n throw new RuntimeException();\n }\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n\n int[] nextIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) res[i] = nextInt();\n return res;\n }\n\n long[] nextLongArray(int n) {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) res[i] = nextLong();\n return res;\n }\n\n String[] nextStringArray(int n) {\n String[] res = new String[n];\n for (int i = 0; i < n; i++) res[i] = nextToken();\n return res;\n }\n }\n\n static class PrefixSums {\n long[] sums;\n\n public PrefixSums(long[] sums) {\n this.sums = sums;\n }\n\n public long sum(int fromInclusive, int toExclusive) {\n if (fromInclusive > toExclusive) throw new IllegalArgumentException(\"Wrong value\");\n return sums[toExclusive] - sums[fromInclusive];\n }\n\n public static PrefixSums of(int[] ar) {\n long[] sums = new long[ar.length + 1];\n for (int i = 1; i <= ar.length; i++) {\n sums[i] = sums[i - 1] + ar[i - 1];\n }\n return new PrefixSums(sums);\n }\n\n public static PrefixSums of(long[] ar) {\n long[] sums = new long[ar.length + 1];\n for (int i = 1; i <= ar.length; i++) {\n sums[i] = sums[i - 1] + ar[i - 1];\n }\n return new PrefixSums(sums);\n }\n }\n\n static class ADUtils {\n static void sort(int[] ar) {\n Random rnd = ThreadLocalRandom.current();\n for (int i = ar.length - 1; i > 0; i--)\n {\n int index = rnd.nextInt(i + 1);\n // Simple swap\n int a = ar[index];\n ar[index] = ar[i];\n ar[i] = a;\n }\n Arrays.sort(ar);\n }\n\n static void reverse(int[] arr) {\n int last = arr.length / 2;\n for (int i = 0; i < last; i++) {\n int tmp = arr[i];\n arr[i] = arr[arr.length - 1 - i];\n arr[arr.length - 1 - i] = tmp;\n }\n }\n\n static void sort(long[] ar) {\n Random rnd = ThreadLocalRandom.current();\n for (int i = ar.length - 1; i > 0; i--)\n {\n int index = rnd.nextInt(i + 1);\n // Simple swap\n long a = ar[index];\n ar[index] = ar[i];\n ar[i] = a;\n }\n Arrays.sort(ar);\n }\n }\n\n static class MathUtils {\n static long[] FIRST_PRIMES = {\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,\n 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\n 73, 79, 83, 89 , 97 , 101, 103, 107, 109, 113,\n 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,\n 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,\n 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,\n 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,\n 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,\n 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,\n 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,\n 547, 557, 563, 569, 571, 577, 587, 593, 599, 601,\n 607, 613, 617, 619, 631, 641, 643, 647, 653, 659,\n 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,\n 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,\n 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,\n 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,\n 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013,\n 1019, 1021, 1031, 1033, 1039, 1049, 1051};\n\n static long[] primes(int to) {\n long[] all = new long[to + 1];\n long[] primes = new long[to + 1];\n all[1] = 1;\n int primesLength = 0;\n for (int i = 2; i <= to; i ++) {\n if (all[i] == 0) {\n primes[primesLength++] = i;\n all[i] = i;\n }\n for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) {\n all[(int) (i * primes[j])] = primes[j];\n }\n }\n return Arrays.copyOf(primes, primesLength);\n }\n\n static long modpow(long b, long e, long m) {\n long result = 1;\n\n while (e > 0) {\n if ((e & 1) == 1) {\n /* multiply in this bit's contribution while using modulus to keep\n * result small */\n result = (result * b) % m;\n }\n b = (b * b) % m;\n e >>= 1;\n }\n\n return result;\n }\n\n static long submod(long x, long y, long m) {\n return (x - y + m) % m;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b611cbbeee2e4593d90083c458eafc26", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class R027E {\n public void debug(Object... objects) { System.err.println(Arrays.deepToString(objects)); }\n \n List primes;\n List p;\n int n;\n double ans = 1e18;\n \n public R027E() {\n Scanner scanner = new Scanner(System.in);\n this.n = scanner.nextInt();\n this.primes = new ArrayList();\n this.p = new ArrayList();\n }\n \n boolean prime(int n) {\n for(int i=2; i<=Math.sqrt((double)n); i++) {\n if(n % i == 0) { return false; }\n }\n return true;\n }\n \n void f(int k) {\n if( k==1 ) {\n List v = p;\n Collections.sort(v);\n Collections.reverse(v);\n double x = 1;\n for(int i=0; i 1e18) { return; }\n }\n }\n if(x < ans) { ans = x; }\n } else {\n for(int i=2; i<=k; i++) {\n if(k % i == 0) { \n p.add(i-1);\n f(k / i);\n p.remove((int)(p.size()-1));\n }\n }\n }\n }\n \n private void process() {\n for(int i=2; i<1000000; i++) {\n if(prime(i)) { primes.add(i); }\n }\n f(n);\n System.out.println((long)ans);\n }\n \n public static void main(String[] args) { new R027E().process(); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "125f314ef14d6413e85c5048a728abf2", "src_uid": "62db589bad3b7023418107de05b7a8ee", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.awt.*;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.util.List;\n\npublic class NumberWithTheGivenAmountOfDivisors\n{\n public static void main(String[] args)\n {\n new NumberWithTheGivenAmountOfDivisors(System.in, System.out);\n }\n\n private static class Solver implements Runnable\n {\n static final long INF = (long) 1e18 + 7;\n int n, primesCnt;\n int[][] dp;\n List primes;\n List primeFactors;\n InputReader in;\n PrintWriter out;\n\n void solve() throws IOException\n {\n pre();\n// check();\n n = in.nextInt();\n primeFactors = new ArrayList<>();\n\n int temp = n;\n\n for (int i = 2; i * i <= temp; i++)\n {\n if (temp % i == 0)\n {\n int cnt = 0;\n\n while (temp % i == 0)\n {\n temp /= i;\n cnt++;\n }\n\n primeFactors.add(new Point(i, cnt));\n }\n }\n }\n\n long find(int ind, int mask, int rem)\n {\n if (mask == (1 << primesCnt) - 1 || primes.get(ind) > rem)\n return INF;\n\n if (rem == 1)\n return 1;\n }\n\n void pre()\n {\n primes = new ArrayList<>();\n\n for (int i = 2; i < 1000; i++)\n {\n if (isPrime(i))\n primes.add(i);\n }\n }\n\n void check()\n {\n int cnt = 0;\n\n for (int i = 2; i <= 1000; i++)\n if (isPrime(i))\n cnt++;\n\n System.out.println(\"tot. no. of primes <= 1000 : \" + cnt);\n }\n\n boolean isPrime(int x)\n {\n for (int i = 2; i * i <= x; i++)\n if (x % i == 0)\n return false;\n\n return true;\n }\n\n Solver(InputReader in, PrintWriter out)\n {\n this.in = in;\n this.out = out;\n }\n\n @Override\n public void run()\n {\n try\n {\n solve();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n\n }\n\n private static class InputReader\n {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n 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 if (numChars <= 0)\n return -1;\n }\n\n return buf[curChar++];\n }\n\n 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\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n\n res *= 10;\n res += c & 15;\n\n c = read();\n } while (!isSpaceChar(c));\n\n return res * sgn;\n }\n\n boolean isSpaceChar(int c)\n {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n void close()\n {\n try\n {\n stream.close();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n\n InputReader(InputStream stream)\n {\n this.stream = stream;\n }\n\n }\n\n private NumberWithTheGivenAmountOfDivisors(InputStream inputStream, OutputStream outputStream)\n {\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Thread thread = new Thread(null, new Solver(in, out), \"Solver\", 1 << 29);\n\n try\n {\n thread.start();\n thread.join();\n }\n catch (InterruptedException e)\n {\n e.printStackTrace();\n }\n\n in.close();\n out.flush();\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "16332271220f121f114102b685a9f3a0", "src_uid": "62db589bad3b7023418107de05b7a8ee", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 ENumberWithTheGivenAmountOfDivisors solver = new ENumberWithTheGivenAmountOfDivisors();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ENumberWithTheGivenAmountOfDivisors {\n int n;\n int prime;\n\n public void solve(int testNumber, FastReader s, PrintWriter out) {\n n = s.nextInt();\n prime = new int[]{2, 3, 5, 7, 11, 13, 17, 19, 29, 31, 37, 41};\n out.println(solve(1, 1, 0));\n }\n\n private long solve(int cnt, int cur, int i) {\n if (cnt == n) return cur;\n long res = (long) 1e18;\n int p = 1;\n while (true) {\n cur *= prime[i];\n if (cnt * (p + 1) > n || cur > res) break;\n res = Math.min(res, solve(cnt * (p + 1), cur, i + 1));\n p++;\n }\n return res;\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 interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6833e23e72a9b8badd03d1d76c4d68c3", "src_uid": "62db589bad3b7023418107de05b7a8ee", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "public class Matrix2019F {\n\tstatic int n;\n\tstatic BigInteger ans = BigInteger.valueOf(-1);\n\tstatic int B[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,\n\t\t\t53 };\n\n\tstatic BigInteger qp(BigInteger x, int n) {\n\t\tBigInteger ans = BigInteger.ONE;\n\t\twhile (n != 0) {\n\t\t\tif ((n & 1) != 0) {\n\t\t\t\tans = ans.multiply(x);\n\t\t\t}\n\t\t\tx = x.multiply(x);\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tstatic Vector v = new Vector();\n\n\tstatic void dfs(int x)// x\u5206\u89e3\u4e0e\u5426\n\t{\n\n\t\t{\n\t\t\tv.add(x);\n\t\t\tVector temp = new Vector(v);\n\t\t\tCollections.sort(temp);\n\t\t\tCollections.reverse(temp);\n\t\t\t/*\n\t\t\t * for(int i: temp){ System.out.print(i+\"?\"); }\n\t\t\t */\n\t\t\tBigInteger t = BigInteger.ONE, q;\n\t\t\tfor (int i = 0; i < temp.size(); i++) {\n\t\t\t\tq = qp(BigInteger.valueOf(B[i]), temp.get(i) - 1);\n\t\t\t\tt = t.multiply(q);\n\t\t\t}\n\t\t\tif (ans.equals(BigInteger.valueOf(-1)) || ans.compareTo(t) > 0)\n\t\t\t\tans = t;\n\t\t\tv.remove(v.size() - 1);\n\t\t}\n\t\tif (x <= 1) {\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 2; i * i <= x; i++) {\n\t\t\tif (x % i == 0) {\n\t\t\t\tv.add(i);\n\t\t\t\tdfs(x / i);\n\t\t\t\tv.remove(v.size() - 1);\n\t\t\t}\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\n\t\tans = BigInteger.valueOf(-1);\n\t\tdfs(n);\n\t\tSystem.out.print(ans + \",\");\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bcfa6bc8b4074b581b87b34cb08f67f1", "src_uid": "62db589bad3b7023418107de05b7a8ee", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\n\npublic class C\n{\n\n\tstatic class Graph\n\t{\n\t\tint verticies;\n\t\tint edges;\n\n\t\tpublic ArrayList[] adj;\n\t\tpublic int[] values;\n\n\t\tGraph(int n)\n\t\t{\n\t\t\tverticies = n;\n\t\t\tadj = new ArrayList[n];\n\t\t\tvalues = new int[n];\n\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tadj[i] = new ArrayList<>();\n\t\t}\n\n\t\tpublic void addEdge(int v, int w)\n\t\t{\t\n\t\t\tadj[v].add(w);\n\t\t\tadj[w].add(v);\n\t\t}\n\n\t\tpublic void addValue(int v, int data)\n\t\t{\n\t\t\tvalues[v] = data;\n\t\t}\n\t\t\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\t\n\t\tGraph gr = new Graph(n);\n\t\t\n\t\tfor (int i = 0; i < m; i++)\n\t\t{\n\t\t\tgr.addEdge(sc.nextInt() - 1, sc.nextInt() - 1);\n\t\t}\n\n\t\tboolean[][] dominos = new boolean[6][6];\n\t\tint cnt = 0;\n\t\tboolean[][] used = new boolean[n][n];\n\n\t\tif (n < 6)\n\t\t{\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tgr.addValue(i, i);\n\t\t\t\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < gr.adj[i].size(); j++)\n\t\t\t\t{\n\t\t\t\t\tif (used[i][gr.adj[i].get(j)])\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\n\t\t\t\t\tif (!dominos[gr.values[i]][gr.values[gr.adj[i].get(j)]])\n\t\t\t\t\t{\n\t\t\t\t\t\tdominos[gr.values[i]][gr.values[gr.adj[i].get(j)]] = dominos[gr.values[gr.adj[i].get(j)]][gr.values[i]] = true;\n\t\t\t\t\t\tused[i][gr.adj[i].get(j)] = used[gr.adj[i].get(j)][i] = true;\n\t\t\t\t\t\tcnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint max = 0;\n\t\t\t// node to swap\n\t\t\tfor (int i = 0; i < 7; i++)\n\t\t\t{\n\t\t\t\t// value swapped with\n\t\t\t\tfor (int j = 0; j < 6; j++)\n\t\t\t\t{\n\t\t\t\t\tcnt = 0;\n\t\t\t\t\tfor (int f = 0; f < 6; f++)\n\t\t\t\t\t\tArrays.fill(dominos[f], false);\n\t\t\t\t\t\n\t\t\t\t\tfor (int f = 0; f < 7; f++)\n\t\t\t\t\t\tArrays.fill(used[f], false);\n\t\t\t\t\t\n\t\t\t\t\tint k = 0;\n\t\t\t\t\twhile (k < 7)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (k < i)\n\t\t\t\t\t\t\tgr.addValue(k, k);\n\t\t\t\t\t\telse if (k == i)\n\t\t\t\t\t\t\tgr.addValue(i, j);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tgr.addValue(k, k - 1);\n\t\t\t\t\t\tk++;\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (int x = 0; x < 7; x++)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (int y = 0; y < gr.adj[x].size(); y++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (used[x][gr.adj[x].get(y)])\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\n\t\t\t\t\t\t\tif (!dominos[gr.values[x]][gr.values[gr.adj[x].get(y)]])\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdominos[gr.values[x]][gr.values[gr.adj[x].get(y)]] = dominos[gr.values[gr.adj[x].get(y)]][gr.values[x]] = true;\n\t\t\t\t\t\t\t\tused[x][gr.adj[x].get(y)] = used[gr.adj[x].get(y)][x] = 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\n\t\t\t\t\tif (cnt > max)\n\t\t\t\t\t\tmax = cnt;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcnt = max;\n\t\t}\n\t\tSystem.out.println(cnt);\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2b1ba5fa21d58486fcff9d70add21fbd", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0} {"lang": "Java 8", "source_code": " import java.io.BufferedWriter;\n import java.io.IOException;\n import java.io.InputStream;\n import java.io.OutputStream;\n import java.io.OutputStreamWriter;\n import java.io.PrintWriter;\n import java.io.Writer;\n import java.util.Arrays;\n import java.util.InputMismatchException;\n import java.util.*;\n import java.io.*;\n import java.math.*;\n public class Main7{\n \n static class Pair\n { \n int x;\n int y;\n public Pair(int x,int y) \n { \n this.x= x; \n this.y= y;\n } \n \n @Override\n public int hashCode() \n { \n final int temp = 14; \n int ans = 1; \n ans =x*31+y*13; \n return ans; \n } \n \n // Equal objects must produce the same \n // hash code as long as they are equal \n @Override\n public boolean equals(Object o) \n { \n if (this == o) { \n return true; \n } \n if (o == null) { \n return false; \n } \n if (this.getClass() != o.getClass()) { \n return false; \n } \n Pair other = (Pair)o; \n if (this.x != other.x || this.y!=other.y) { \n return false; \n } \n return true; \n } \n \n } \n static class Pair1\n {\n String x;\n int y;\n int z;\n \n }\n static class Compare\n { \n static void compare(Pair arr[], int n) \n { \n // Comparator to sort the pair according to second element \n /* Arrays.sort(arr, new Comparator() { \n @Override public int compare(Pair p1, Pair p2) \n { \n if(p1.start>p2.start)\n {\n return 1;\n }\n else if(p1.start==p2.start)\n {\n return 0;\n }\n else\n {\n return -1;\n }\n } \n }); */\n }\n \n }\n \n \n public static long pow(long a, long b)\n {\n long result=1;\n while(b>0)\n {\n if (b % 2 != 0)\n {\n result=(result*a)%998244353;\n b--;\n } \n a=(a*a)%998244353;\n b /= 2;\n } \n return result;\n }\n public static long fact(long num)\n {\n long value=1;\n int i=0;\n for(i=2;i arr=new ArrayList();\n arr=graph.get(parent);\n visited[parent]=true;\n for(int i=0;i> graph;\n \n public static void bfs(int num,int size)\n {\n boolean[] visited=new boolean[size+1];\n Queue q=new LinkedList<>();\n q.add(num);\n ans[num]=1;\n visited[num]=true;\n while(!q.isEmpty())\n {\n int x=q.poll();\n ArrayList al=graph.get(x);\n for(int i=0;i ar=new ArrayList<>();\n for(int i=0;i=0;i--)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor(int j=6;j>=0;j--)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor(int k=6;k>=0;k--)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tfor(int l=6;l>=0;l--)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tfor(int m=6;m>=0;m--)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfor(int n=6;n>=0;n--)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tfor(int o=6;o>=0;o--)\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tint ans=0;\n\t\t\t\t\t\t\t\t\t\t\t\tint[] x=new int[]{i,j,k,l,m,n,o};\n\t\t\t\t\t\t\t\t\t\t\t\tHashMap,Integer> hash=new HashMap<>();\n\t\t\t\t\t\t\t\t\t\t\t\tfor(int p=0;p ar=new ArrayList<>();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tar.add(x[a[p]]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tar.add(x[b[p]]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tArrayList ar1=new ArrayList<>();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tar1.add(x[b[p]]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tar1.add(x[a[p]]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(hash.containsKey(ar)==false && hash.containsKey(ar1)==false)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tans++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thash.put(ar,1);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tar.clear();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tar.add(x[b[p]]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tar.add(x[a[p]]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thash.put(ar,1);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\tmax=Math.max(ans,max);\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\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\tpln(max+\"\");\n }\n \n /**/\n static InputReader in=new InputReader(System.in);\n static OutputWriter out=new OutputWriter(System.out);\n public static long l()\n {\n String s=in.String();\n return Long.parseLong(s);\n }\n public static void pln(String value)\n {\n System.out.println(value);\n }\n public static int i()\n {\n return in.Int();\n }\n public static String s()\n {\n return in.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 class InputReader {\n \n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars== -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n public int Int() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public String String() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public String next() {\n return String();\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n \n class OutputWriter {\n private final PrintWriter writer;\n \n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n \n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n \n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n \n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n \n public void close() {\n writer.close();\n }\n \n public void flush() {\n writer.flush();\n }\n \n }\n \n class IOUtils {\n \n public static int[] readIntArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n array[i] = in.Int();\n return array;\n }\n \n } \n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ff8f0896bf5e6cc062e94474b46347f", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.StringTokenizer;\n\nimport java.util.Scanner;\n\npublic class Main\n{\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n\n while(sc.hasNext()){\n int n=sc.nextInt();\n int k=sc.nextInt();\n int a[][]=new int[10][10];\n for (int i=0;i= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(inbuf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0) {\n return -1;\n }\n }\n return inbuf[ptrbuf++];\n }\n \n private boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n \n private int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b))\n ;\n return b;\n }\n \n private double nd() {\n return Double.parseDouble(ns());\n }\n \n private char nc() {\n return (char) skip();\n }\n \n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n \n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while (p < n && !(isSpaceChar(b))) {\n buf[p++] = (char) b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n \n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for (int i = 0; i < n; i++) {\n map[i] = ns(m);\n }\n return map;\n }\n \n private int[] na(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = ni();\n }\n return a;\n }\n \n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n \n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n \n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n \n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n \n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n \n private void tr(Object... o) {\n if (!oj) {\n System.out.println(Arrays.deepToString(o));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "13c3a91106543b71cfbc6108b85ce1a8", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.Integer;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner cin = new FastScanner(System.in);\n\t\tint n = cin.nextInt();\n\t\tint arr[]= new int[6];\n\t\t\n\t\tfor (int i=0; i<6; i++){\n\t\t\tarr[i]=n%2;\n\t\t\tn=n/2;\n\t\t}\n\t\t\n\t\tint arrnew[]= new int[6];\n\t\t\n\t\tarrnew[0]=arr[4];\n\t\tarrnew[1]=arr[1];\n\t\tarrnew[2]=arr[3];\n\t\tarrnew[3]=arr[2];\n\t\tarrnew[4]=arr[0];\n\t\tarrnew[5]=arr[5];\n\t\t\n\t\tint nnew=0;\n\t\tfor (int i=0; i<6; i++){\n\t\t\tnnew=nnew+arrnew[i]*Math.pow(2,i);\n\t\t}\n\t\t\n\n\t\tSystem.out.println(nnew);\n\t}\n\n\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader reader = null;\n\t\tprivate StringTokenizer tokenizer = null;\n\n\t\tpublic FastScanner(InputStream in) {\n\t\t\treader = new BufferedReader(new InputStreamReader(in));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tif (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\treturn reader.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn tokenizer.nextToken(\"\\n\");\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7c5a6caa8c45f70d7a1bf7267f965c28", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class test {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n if(n==2) System.out.print(2);\n if(n==2) System.out.print(2);\n if(n==2) System.out.print(2);\n System.out.print(x);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "27ee2df586751dc5fec131f3927b6fd9", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class cfCEOI2019Day1B {\n\n\tstatic class HLD {\n\t\tint n, root;\n\n\t\tprivate int[][] g;\n\t\tprivate int[] sz;\n\t\tprivate int timePtr = 0;\n\n\t\t// parent of node, time -> time\n\t\tpublic int[] par;\n\n\t\t// tree traversal, time -> node\n\t\tint[] time2Node;\n\n\t\t// time when you get in/out of the node\n\t\t// Subtree of v has times [ v; rgh(v) )\n\t\tint[] node2Time; // node -> time\n\t\tint[] rgh; // time -> time\n\n\t\t// lft and order are inverse permutations\n\n\t\t// depth, time -> int\n\t\tint[] depth;\n\n\t\t// if chainInfo[v] < 0 then v is the head of chain with id =\n\t\t// (~chainInfo[v]), time->chainId\n\t\t// if chainInfo[v] >=0 then chainInfo[v] is the head of chain that v\n\t\t// belongs to, time->time\n\t\tprivate int[] chainInfo;\n\n\t\t// top-most node of the corresponding chain, chainId -> time\n\t\tint[] chainHead;\n\n\t\tint chainCnt = 0;\n\t\tprivate int[] buf;\n\n\t\tpublic HLD(int[] vs, int[] us, int root) {\n\t\t\tn = vs.length + 1;\n\t\t\tthis.root = root;\n\t\t\tif (vs.length != us.length) {\n\t\t\t\tthrow new AssertionError(\"vs.length != us.length\");\n\t\t\t}\n\t\t\tif (!(0 <= root && root < n)) {\n\t\t\t\tthrow new AssertionError(\"bad root\");\n\t\t\t}\n\n\t\t\t// Building the graph.\n\t\t\tint[] deg = new int[n];\n\t\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\t\tif (!(0 <= vs[i] && vs[i] < n && 0 <= us[i] && us[i] < n && vs[i] != us[i])) {\n\t\t\t\t\tthrow new AssertionError(\"bad node in edge\");\n\t\t\t\t}\n\t\t\t\tdeg[vs[i]]++;\n\t\t\t\tdeg[us[i]]++;\n\t\t\t}\n\t\t\tg = new int[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tg[i] = new int[deg[i]];\n\t\t\t}\n\t\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\t\tint v = vs[i];\n\t\t\t\tint u = us[i];\n\t\t\t\tg[v][--deg[v]] = u;\n\t\t\t\tg[u][--deg[u]] = v;\n\t\t\t}\n\n\t\t\t// Find sizes/parents and reorder children.\n\t\t\tsz = new int[n];\n\t\t\tdfsSz(root, -1);\n\n\t\t\t// Find the chains/subtree ranges.\n\t\t\tpar = new int[n];\n\t\t\tpar[0] = -1;\n\t\t\t\n\t\t\tdepth = new int[n];\n\t\t\ttime2Node = new int[n];\n\t\t\tnode2Time = new int[n];\n\t\t\trgh = new int[n];\n\t\t\t\n\t\t\tchainHead = new int[n];\n\t\t\tchainHead[chainCnt] = 0;\n\t\t\t\n\t\t\tchainInfo = new int[n];\n\t\t\tchainInfo[0] = ~(chainCnt++);\n\t\t\t\n\t\t\tdfsChains(root, -1);\n\n\t\t\tchainHead = Arrays.copyOf(chainHead, chainCnt);\n\t\t\tbuf = new int[3 * chainCnt];\n\t\t}\n\n\t\t/**\n\t\t * @return list of triplets [chainId; pos1; pos2] in order corresponding\n\t\t * to the path from v to u
\n\t\t * pos1 <= pos2 = going down
\n\t\t * pos1 > pos2 = going up\n\t\t */\n\t\tpublic int[] getPath(int v, int u) {\n\t\t\tint headPtr = 0, tailPtr = buf.length;\n\t\t\tint chV = chainId(v), upV = chainHead[chV], chU = chainId(u), upU = chainHead[chU];\n\t\t\twhile (chV != chU) {\n\t\t\t\tif (depth[upV] > depth[upU]) {\n\t\t\t\t\tbuf[headPtr] = chV;\n\t\t\t\t\tbuf[headPtr + 1] = v - upV;\n\t\t\t\t\tbuf[headPtr + 2] = 0;\n\t\t\t\t\theadPtr += 3;\n\t\t\t\t\tv = par[upV];\n\t\t\t\t\tchV = chainId(v);\n\t\t\t\t\tupV = chainHead[chV];\n\t\t\t\t} else {\n\t\t\t\t\tbuf[tailPtr - 3] = chU;\n\t\t\t\t\tbuf[tailPtr - 2] = 0;\n\t\t\t\t\tbuf[tailPtr - 1] = u - upU;\n\t\t\t\t\ttailPtr -= 3;\n\t\t\t\t\tu = par[upU];\n\t\t\t\t\tchU = chainId(u);\n\t\t\t\t\tupU = chainHead[chU];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint base = chainHead[chV];\n\t\t\tbuf[headPtr] = chV;\n\t\t\tbuf[headPtr + 1] = v - base;\n\t\t\tbuf[headPtr + 2] = u - base;\n\t\t\theadPtr += 3;\n\n\t\t\tSystem.arraycopy(buf, tailPtr, buf, headPtr, buf.length - tailPtr);\n\t\t\treturn Arrays.copyOf(buf, headPtr + buf.length - tailPtr);\n\t\t}\n\n\t\t// the length of chain #id\n\t\t// chainId -> int\n\t\tpublic int chainSz(int id) {\n\t\t\treturn (id == chainHead.length - 1 ? n : chainHead[id + 1]) - chainHead[id];\n\t\t}\n\n\t\t// the id of chain that node belongs to\n\t\t// time -> chainId\n\t\tpublic int chainId(int node) {\n\t\t\t// if node is not a chain's head, set node to the head\n\t\t\tif (chainInfo[node] >= 0) {\n\t\t\t\tnode = chainInfo[node];\n\t\t\t}\n\t\t\treturn ~chainInfo[node];\n\t\t}\n\n\t\t// the position of a node within its chain\n\t\t// time -> int\n\t\tpublic int chainPos(int t) {\n\t\t\tint x = chainInfo[t];\n\t\t\treturn x >= 0 ? t - x : 0;\n\t\t}\n\t\t\n\t\t// returns the NODE in the given chain at the given position\n\t\t// this is called getTime because you should only care\n\t\t// about \"times\" and not original node numbers\n\t\tpublic int getTime(int chainId, int chainPos) {\n\t\t\treturn chainHead[chainId] + chainPos;\n\t\t}\n\t\t\n\t\t// time -> boolean\n\t\tpublic boolean isLeaf(int t) {\n\t\t\treturn g[time2Node[t]].length == (t == 0 ? 0 : 1);\n\t\t}\n\n\t\tprivate void dfsSz(int v, int p) {\n\t\t\tsz[v] = 1;\n\t\t\tint[] adj = g[v];\n\t\t\tfor (int i = 0; i < adj.length; i++) {\n\t\t\t\tint u = adj[i];\n\t\t\t\tif (u == p) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdfsSz(u, v);\n\t\t\t\tsz[v] += sz[u];\n\t\t\t\tif (adj[0] == p || sz[u] > sz[adj[0]]) {\n\t\t\t\t\tadj[i] = adj[0];\n\t\t\t\t\tadj[0] = u;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate void dfsChains(int v, int p) {\n\t\t\tint tv = timePtr++;\n\t\t\ttime2Node[tv] = v;\n\t\t\tnode2Time[v] = tv;\n\n\t\t\tint[] adj = g[v];\n\t\t\tfor (int i = 0; i < adj.length; i++) {\n\t\t\t\tint u = adj[i];\n\t\t\t\tif (u == p) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tpar[timePtr] = tv;\n\t\t\t\tdepth[timePtr] = depth[tv] + 1;\n\t\t\t\tif (i == 0) {\n\t\t\t\t\tchainInfo[timePtr] = chainInfo[tv] >= 0 ? chainInfo[tv] : tv;\n\t\t\t\t} else {\n\t\t\t\t\tchainHead[chainCnt] = timePtr;\n\t\t\t\t\tchainInfo[timePtr] = ~(chainCnt++);\n\t\t\t\t}\n\t\t\t\tdfsChains(u, v);\n\t\t\t}\n\n\t\t\trgh[tv] = timePtr;\n\t\t}\n\t}\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint q = nextInt();\n\t\tlong w = nextLong();\n\t\tint[] vs = new int[n - 1];\n\t\tint[] us = new int[n - 1];\n\t\tlong[] ws = new long[n - 1];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tvs[i] = nextInt() - 1;\n\t\t\tus[i] = nextInt() - 1;\n\t\t\tws[i] = nextLong();\n\t\t}\n\n\t\tHLD hld = new HLD(vs, us, 0);\n\t\t\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tvs[i] = hld.node2Time[vs[i]];\n\t\t\tus[i] = hld.node2Time[us[i]];\n\t\t}\n\n\t\tint[] 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6009981dc8c13670c67295d3c5ac3b26", "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class cfCEOI2019Day1B {\n\n\tstatic class HLD {\n\t\tint n, root;\n\n\t\tprivate int[][] g;\n\t\tprivate int[] sz;\n\t\tprivate int timePtr = 0;\n\n\t\t// parent of node, time -> time\n\t\tpublic int[] par;\n\n\t\t// tree traversal, time -> node\n\t\tint[] time2Node;\n\n\t\t// time when you get in/out of the node\n\t\t// Subtree of v has times [ v; rgh(v) )\n\t\tint[] node2Time; // node -> time\n\t\tint[] rgh; // time -> time\n\n\t\t// lft and order are inverse permutations\n\n\t\t// depth, time -> int\n\t\tint[] depth;\n\n\t\t// if chainInfo[v] < 0 then v is the head of chain with id =\n\t\t// (~chainInfo[v]), time->chainId\n\t\t// if chainInfo[v] >=0 then chainInfo[v] is the head of chain that v\n\t\t// belongs to, time->time\n\t\tprivate int[] chainInfo;\n\n\t\t// top-most node of the corresponding chain, chainId -> time\n\t\tint[] chainHead;\n\n\t\tint chainCnt = 0;\n\t\tprivate int[] buf;\n\n\t\tpublic HLD(int[] vs, int[] us, int root) {\n\t\t\tn = vs.length + 1;\n\t\t\tthis.root = root;\n\t\t\tif (vs.length != us.length) {\n\t\t\t\tthrow new AssertionError(\"vs.length != us.length\");\n\t\t\t}\n\t\t\tif (!(0 <= root && root < n)) {\n\t\t\t\tthrow new AssertionError(\"bad root\");\n\t\t\t}\n\n\t\t\t// Building the graph.\n\t\t\tint[] deg = new int[n];\n\t\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\t\tif (!(0 <= vs[i] && vs[i] < n && 0 <= us[i] && us[i] < n && vs[i] != us[i])) {\n\t\t\t\t\tthrow new AssertionError(\"bad node in edge\");\n\t\t\t\t}\n\t\t\t\tdeg[vs[i]]++;\n\t\t\t\tdeg[us[i]]++;\n\t\t\t}\n\t\t\tg = new int[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tg[i] = new int[deg[i]];\n\t\t\t}\n\t\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\t\tint v = vs[i];\n\t\t\t\tint u = us[i];\n\t\t\t\tg[v][--deg[v]] = u;\n\t\t\t\tg[u][--deg[u]] = v;\n\t\t\t}\n\n\t\t\t// Find sizes/parents and reorder children.\n\t\t\tsz = new int[n];\n\t\t\tdfsSz(root, -1);\n\n\t\t\t// Find the chains/subtree ranges.\n\t\t\tpar = new int[n];\n\t\t\tpar[0] = -1;\n\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\n\t\t\tchainHead = new int[n];\n\t\t\tchainHead[chainCnt] = 0;\n\n\t\t\tchainInfo = new int[n];\n\t\t\tchainInfo[0] = ~(chainCnt++);\n\n\t\t\tdfsChains(root, -1);\n\n\t\t\tchainHead = Arrays.copyOf(chainHead, chainCnt);\n\t\t\tbuf = new int[3 * chainCnt];\n\t\t}\n\n\t\t/**\n\t\t * @return list of triplets [chainId; pos1; pos2] in order corresponding\n\t\t * to the path from v to u
\n\t\t * pos1 <= pos2 = going down
\n\t\t * pos1 > pos2 = going up\n\t\t */\n\t\tpublic int[] getPath(int v, int u) {\n\t\t\tint headPtr = 0, tailPtr = buf.length;\n\t\t\tint chV = chainId(v), upV = chainHead[chV], chU = chainId(u), upU = chainHead[chU];\n\t\t\twhile (chV != chU) {\n\t\t\t\tif (depth[upV] > depth[upU]) {\n\t\t\t\t\tbuf[headPtr] = chV;\n\t\t\t\t\tbuf[headPtr + 1] = v - upV;\n\t\t\t\t\tbuf[headPtr + 2] = 0;\n\t\t\t\t\theadPtr += 3;\n\t\t\t\t\tv = par[upV];\n\t\t\t\t\tchV = chainId(v);\n\t\t\t\t\tupV = chainHead[chV];\n\t\t\t\t} else {\n\t\t\t\t\tbuf[tailPtr - 3] = chU;\n\t\t\t\t\tbuf[tailPtr - 2] = 0;\n\t\t\t\t\tbuf[tailPtr - 1] = u - upU;\n\t\t\t\t\ttailPtr -= 3;\n\t\t\t\t\tu = par[upU];\n\t\t\t\t\tchU = chainId(u);\n\t\t\t\t\tupU = chainHead[chU];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint base = chainHead[chV];\n\t\t\tbuf[headPtr] = chV;\n\t\t\tbuf[headPtr + 1] = v - base;\n\t\t\tbuf[headPtr + 2] = u - base;\n\t\t\theadPtr += 3;\n\n\t\t\tSystem.arraycopy(buf, tailPtr, buf, headPtr, buf.length - tailPtr);\n\t\t\treturn Arrays.copyOf(buf, headPtr + buf.length - tailPtr);\n\t\t}\n\n\t\t// the length of chain #id\n\t\t// chainId -> int\n\t\tpublic int chainSz(int id) {\n\t\t\treturn (id == chainHead.length - 1 ? n : chainHead[id + 1]) - chainHead[id];\n\t\t}\n\n\t\t// the id of chain that node belongs to\n\t\t// time -> chainId\n\t\tpublic int chainId(int node) {\n\t\t\t// if node is not a chain's head, set node to the head\n\t\t\tif (chainInfo[node] >= 0) {\n\t\t\t\tnode = chainInfo[node];\n\t\t\t}\n\t\t\treturn ~chainInfo[node];\n\t\t}\n\n\t\t// the position of a node within its chain\n\t\t// time -> int\n\t\tpublic int chainPos(int t) {\n\t\t\tint x = chainInfo[t];\n\t\t\treturn x >= 0 ? t - x : 0;\n\t\t}\n\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\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\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\tNode depths = new Node(0, n);\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tdepths.addSegm(us[i], rgh[us[i]], ws[i]);\n\t\t}\n\n\t\tNode[] aux = new Node[hld.chainCnt];\n\t\tfor (int i = 0; i < aux.length; i++) {\n\t\t\taux[i] = new Node(0, 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.getSegm(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\t// System.err.println(edgeIdx + \" \" + newW);\n\t\t\t// System.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\t// System.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.addSegm(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].addSegm(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.getSegm(rgh[v + 1], rgh[v]) + depths.getPoint(headV)\n\t\t\t\t\t\t\t- 2 * 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].getSegm(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.getSegm(lastNode, nxtNode),\n\t\t\t\t\t\t\tdepths.getSegm(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\tstatic class Node {\n\t\tint l, r;\n\t\tNode left, right;\n\t\tlong add, max;\n\n\t\tlong getMax() {\n\t\t\treturn max + add;\n\t\t}\n\n\t\tpublic Node(int l, int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t\tif (r - l > 1) {\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\tleft = new Node(l, m);\n\t\t\t\tright = new Node(m, r);\n\t\t\t}\n\t\t}\n\n\t\tvoid addSegm(int ql, int qr, long delta) {\n\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\tadd += delta;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tleft.addSegm(ql, qr, delta);\n\t\t\tright.addSegm(ql, qr, delta);\n\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t}\n\n\t\tlong getSegm(int ql, int qr) {\n\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\treturn -INF;\n\t\t\t}\n\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\treturn getMax();\n\t\t\t}\n\t\t\treturn Math.max(left.getSegm(ql, qr), right.getSegm(ql, qr)) + add;\n\t\t}\n\n\t\tint maxPos() {\n\t\t\tif (r - l == 1) {\n\t\t\t\treturn l;\n\t\t\t}\n\t\t\treturn left.getMax() > right.getMax() ? left.maxPos() : right.maxPos();\n\t\t}\n\n\t\tvoid setPoint(int idx, long val) {\n\t\t\tif (r - l == 1) {\n\t\t\t\tadd = 0;\n\t\t\t\tmax = val;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tleft.add += add;\n\t\t\tright.add += add;\n\t\t\tadd = 0;\n\t\t\t(idx < left.r ? left : right).setPoint(idx, val);\n\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t}\n\n\t\tvoid addPoint(int idx, long delta) {\n\t\t\tif (r - l == 1) {\n\t\t\t\tadd += delta;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t(idx < left.r ? left : right).addPoint(idx, delta);\n\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t}\n\n\t\tlong getPoint(int idx) {\n\t\t\tif (r - l == 1) {\n\t\t\t\treturn getMax();\n\t\t\t}\n\t\t\treturn (idx < left.r ? left : right).getPoint(idx) + add;\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tcfCEOI2019Day1B() throws IOException {\n\t\tif (System.getProperty(\"ONLINE_JUDGE\") == null) {\n\t\t\tis = new FileInputStream(\"in.txt\");\n\t\t} else {\n\t\t\tis = System.in;\n\t\t}\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cfCEOI2019Day1B();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0c5c725173fb86c618adfaabf1399d47", "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class G {\n\n\tpublic static void main(String[] args) { new G(); }\n\n\tlong[] weights;\n\tboolean[] isDecomped;\n\tArrayList[] centroids, adj, immediateKids;\n\t\n\tint timeStamp, dfsTime;\n\tint[] bfsOrder, subSize, visited, parInBfs;\n\tlong[] distTo;\n\tHashMap[] maps;\n\t\n\tST_[] sts;\n\t\n\tint[][] preOrder, postOrder;\n\t\n\tG() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tint n = fs.nextInt();\n\t\tint Q = fs.nextInt();\n\t\tlong maxWeight = fs.nextLong();\n\t\t\n\t\tint N = n + n - 1;\n\t\t\n\t\tadj = new ArrayList[N];\n\t\tfor(int i = 0; i < N; i++) adj[i] = new ArrayList<>();\n\t\tweights = new long[N];\n\t\t\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\t\n\t\t\tint u = fs.nextInt()-1;\n\t\t\tint v = fs.nextInt()-1;\n\t\t\tlong we = fs.nextLong();\n\t\t\t\n\t\t\tint idx = n + i;\n\t\t\t\n\t\t\tadj[u].add(idx);\n\t\t\tadj[idx].add(u);\n\t\t\t\n\t\t\tadj[idx].add(v);\n\t\t\tadj[v].add(idx);\n\t\t\t\n\t\t\tweights[idx] = we;\n\t\t}\n\t\t\n\t\tcentroids = new ArrayList[N];\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tcentroids[i] = new ArrayList<>();\n\t\t}\n\t\t\n\t\tisDecomped = new boolean[N];\n\t\tbfsOrder = new int[N];\n\t\tsubSize = new int[N];\n\t\tvisited = new int[N];\n\t\tparInBfs = new int[N];\n\t\t\n\t\tdistTo = new long[N];\n\t\tpreOrder = new int[20][N];\n\t\tpostOrder = new int[20][N];\n\t\t\n\t\timmediateKids = new ArrayList[N];\n\t\tfor(int i = 0; i < N; i++) immediateKids[i] = new ArrayList<>();\n\t\t\n\t\tmaps = new HashMap[N];\n\t\tfor(int i = 0; i < N; i++) maps[i] = new HashMap<>();\n\t\t\n\t\tsts = new ST_[N];\n\t\t\n\t\tdecomp(0);\n\t\t\n\t\tTreeSet

candAnswers = new TreeSet<>();\n\t\tlong[] oldAnswers = new long[N];\n\t\t\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\t//get some stuff\n\t\t\t\n\t\t\tp ans = getAnswer(i);\n\t\t\tif(ans != null) {\n\t\t\t\tcandAnswers.add(ans);\n\t\t\t\toldAnswers[i] = ans.val;\n\t\t\t}\n\t\t}\n\t\t\n//\t\tout.println(candAnswers.last().val + \" \" + candAnswers.last().idx);\n\t\t\n\t\tp temp = new p(-1, -1);\n\t\tlong last = 0;\n\t\tfor(int qq = 0; qq < Q; qq++) {\n\t\t\t\n\t\t\tint d = fs.nextInt();\n\t\t\tlong e = fs.nextLong();\n\t\t\t\n\t\t\tint node = (int)((d + last) % (n - 1));\n\t\t\tnode += n;\n\n\t\t\t\n\t\t\tlong edgeWe = (e + last) % maxWeight;\n\t\t\t\n\t\t\tlong delta = edgeWe - weights[node];\n\t\t\t\n\t\t\t\n\t\t\tfor(int cent : centroids[node]) {\n\t\t\t\t//node's pre, post in cent's seg tree\n\t\t\t\t\n\t\t\t\tint mapIdx = maps[node].get(cent);\n\t\t\t\tint L = preOrder[mapIdx][node];\n\t\t\t\tint R = postOrder[mapIdx][node];\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tsts[cent].rangeAdd(1, L, R, delta);\n\t\t\t\t\n\t\t\t\t//remove old pair\n\t\t\t\ttemp.idx = cent; temp.val = oldAnswers[cent];\n\t\t\t\tboolean rem = candAnswers.remove(temp);\n\t\t\t\t\n\t\t\t\ttemp = getAnswer(cent);\n\t\t\t\t\n\t\t\t\tcandAnswers.add(new p(temp.idx, temp.val));\n\t\t\t\toldAnswers[cent] = temp.val;\n\t\t\t}\n\t\t\t\n\t\t\tweights[node] = edgeWe;\n\t\t\t\n\t\t\tout.println(candAnswers.last().val);\n\t\t\tlast = candAnswers.last().val;\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\tvoid decomp(int rt) {\n\t\ttimeStamp++;\n\n\t\t//bfs\n\t\tint ptr = 0;\n\t\tbfsOrder[ptr++] = rt;\n\t\tvisited[rt] = timeStamp;\n\t\t\n\t\tfor(int head = 0; head < ptr; head++) {\n\t\t\tint u = bfsOrder[head];\n\t\t\tfor(int v : adj[u]) {\n\t\t\t\tif(visited[v] == timeStamp) continue;\n\t\t\t\tif(isDecomped[v]) continue;\n\t\t\t\t\n\t\t\t\tparInBfs[v] = u;\n\t\t\t\tvisited[v] = timeStamp;\n\t\t\t\tbfsOrder[ptr++] = v;\n\t\t\t}\n\t\t}\n\t\tfor(int tail = ptr-1; tail >= 0; tail--) {\n\t\t\tint u = bfsOrder[tail];\n\t\t\tsubSize[u] = 1;\n\t\t\tfor(int v : adj[u]) {\n\t\t\t\tif(isDecomped[v]) continue;\n\t\t\t\tif(parInBfs[u] == v) continue;\n\t\t\t\t\n\t\t\t\tsubSize[u] += subSize[v];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint cent = -1;\n\t\t\n\t\tfor(int i = 0; i < ptr; i++) {\n\t\t\tboolean isGood = true;\n\t\t\tint u = bfsOrder[i];\n\t\t\tfor(int v : adj[u]) {\n\t\t\t\tif(isDecomped[v]) continue;\n\t\t\t\t\n\t\t\t\tif(parInBfs[u] == v) {\n\t\t\t\t\tisGood &= (ptr-subSize[u]) <= ptr/2;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tisGood &= subSize[v] <= ptr/2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(isGood) {\n\t\t\t\tcent = u;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(cent < 0) throw null; //:(\n\t\t\n\t\tfor(int i = 0; i < ptr; i++) {\n\t\t\tint u = bfsOrder[i];\n\t\t\tcentroids[u].add(cent);\n\t\t}\n\t\t\n\t\tdfsTime = 0;\n\t\tdfs(cent, -1, 0);\n\t\t\n\t\tfor(int v : adj[cent]) {\n\t\t\tif(visited[v] == timeStamp) {\n\t\t\t\timmediateKids[cent].add(v);\n\t\t\t}\n\t\t}\n\t\t\n\t\t//make st\n\t\tsts[cent] = new ST_(ptr);\n\t\t\n\t\tisDecomped[cent] = true;\n\t\tfor(int v : adj[cent]) {\n\t\t\tif(isDecomped[v]) continue;\n\t\t\tdecomp(v);\n\t\t}\n\t}\n\t\n\t//ST[cent] = sizeSubtree\n\t\n\t//u -> bfsOrder\n\tvoid dfs(int u, int par, long dist) {\n\t\tint idx = centroids[u].size()-1;\n\t\tpreOrder[idx][u] = dfsTime++;\n\t\t\n\t\tdist += weights[u];\n\t\t\n\t\tmaps[u].put(centroids[u].get(idx), idx);\n\t\tdistTo[ preOrder[idx][u] ] = dist;\n\t\t\n\t\tfor(int v : adj[u]) if(visited[v] == timeStamp && v != par) {\n\t\t\t\n\t\t\tdfs(v, u, dist);\n\t\t\t\n\t\t}\n\t\t\n\t\tpostOrder[idx][u] = dfsTime-1;\n\t}\n\t\n\tp getAnswer(int i) {\n\t\tp max1 = sts[i].rangeMax(1, 0, sts[i].R[1]);\n\t\tif(max1 == null) return null;\n\t\t\n\t\tlong value = max1.val;\n\t\t\n//\t\tSystem.out.println(\" \" + i + \" \" + immediateKids[i]);\n\t\t\n\t\tint lo = 0, hi = immediateKids[i].size()-1;\n\t\t\n\t\tint L = -1, R = -1;\n\t\t\n\t\twhile(lo <= hi) {\n\t\t\tint mid = (lo+hi) / 2;\n\t\t\t\n\t\t\tint thatKid = immediateKids[i].get(mid);\n\t\t\tint mapIdx = maps[thatKid].get(i);\n\t\t\tif(max1.idx <= postOrder[mapIdx][thatKid]) {\n\t\t\t\t\n\t\t\t\tL = preOrder[mapIdx][thatKid];\n\t\t\t\tR = postOrder[mapIdx][thatKid];\n\t\t\t\t\n\t\t\t\thi = mid-1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlo = mid+1;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\t//get max2\n\t\tif(L >= 0) {\n\t\t\tp max2 = null;\n\t\t\tp check1 = sts[i].rangeMax(1, 1, L-1);\n\t\t\tp check2 = sts[i].rangeMax(1, R+1, sts[i].R[1]);\n\t\t\t\n\t\t\tif(check1 != null && check2 != null) {\n\t\t\t\tif(check1.val >= check2.val) max2 = check1;\n\t\t\t\telse max2 = check2;\n\t\t\t}\n\t\t\telse if(check1 == null) max2 = check2;\n\t\t\telse max2 = check1;\n\t\t\t\n\t\t\tif(max2 != null) {\n\t\t\t\tvalue += max2.val - sts[i].rangeMax(1, 0, 0).val;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn new p(i, value);\n\t}\n\t\n\t//range max: return pair(max, idxOfMax)\n\t//range add\n\t\n\tclass ST_ {\n\t\tint[] L, R, maxIdx;\n\t\tlong[] delta, max;\n\t\tint size;\n\t\t\n\t\tST_(int N) {\n\t\t\tsize = 4*N+10;\n\t\t\tL = new int[size];\n\t\t\tR = new int[size];\n\t\t\tmaxIdx = new int[size];\n\t\t\tdelta = new long[size];\n\t\t\tmax = new long[size];\n\t\t\tinit(1, 0, N-1);\n\t\t}\n\t\tvoid init(int p, int a, int b) {\n\t\t\tL[p] = a; R[p] = b;\n\t\t\tif(a == b) {\n\t\t\t\tmax[p] = distTo[a];\n\t\t\t\tmaxIdx[p] = a;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = (a + b) / 2;\n\t\t\tinit(2 * p, a, mid);\n\t\t\tinit(2 * p + 1, mid+1, b);\n\t\t\t\n\t\t\tupdate(p);\n\t\t}\n\t\t\n\t\tvoid rangeAdd(int p, int ll, int rr, long val) {\n\t\t\tif(rr < L[p] || R[p] < ll) return;\n\t\t\tif(ll <= L[p] && R[p] <= rr) {\n\t\t\t\tdelta[p] += val;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprop(p);\n\t\t\t\n\t\t\trangeAdd(2 * p, ll, rr, val);\n\t\t\trangeAdd(2*p+1, ll, rr, val);\n\t\t\t\n\t\t\tupdate(p);\n\t\t}\n\t\t\n\t\tp rangeMax(int p, int ll, int rr) {\n\t\t\tif(rr < ll) return null;\n\t\t\tif(rr < L[p] || R[p] < ll) return null;\n\t\t\tif(ll <= L[p] && R[p] <= rr) {\n\t\t\t\treturn new p(maxIdx[p], getMax(p));\n\t\t\t}\n\t\t\tprop(p);\n\t\t\t\n\t\t\tp lf = rangeMax(2 * p, ll, rr);\n\t\t\tp rg = rangeMax(2 * p + 1, ll, rr);\n\t\t\t\n\t\t\tupdate(p);\n\t\t\t\n\t\t\tif(lf == null) return rg;\n\t\t\tif(rg == null) return lf;\n\t\t\t\n\t\t\tif(rg.val >= lf.val) return rg;\n\t\t\treturn lf;\n\t\t}\n\t\t\n\t\tvoid prop(int p) {\n\t\t\tif(delta[p] == 0) return;\n\t\t\t\n\t\t\tdelta[2 * p] += delta[p];\n\t\t\tdelta[2 * p + 1] += delta[p];\n\t\t\t\n\t\t\tdelta[p] = 0;\n\t\t}\n\t\t\n\t\tlong getMax(int p) {\n\t\t\treturn delta[p]+max[p];\n\t\t}\n\t\t\n\t\tvoid update(int p) {\n\t\t\tlong leftVal = getMax(2 * p);\n\t\t\tlong rightVal = getMax(2*p+1); \n\t\t\t\n\t\t\tif(leftVal >= rightVal) {\n\t\t\t\tmax[p] = leftVal;\n\t\t\t\tif(leftVal == rightVal)\n\t\t\t\t\tmaxIdx[p] = maxIdx[2 * p + 1];\n\t\t\t\telse\n\t\t\t\t\tmaxIdx[p] = maxIdx[2 * p];\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmax[p] = rightVal;\n\t\t\t\tmaxIdx[p] = maxIdx[2 * p + 1];\n\t\t\t}\n\t\t}\n\t}\n\t\n\tclass ST {\n\t\tST left, right;\n\t\tint L, R;\n\t\tlong delta, max;\n\t\tint maxIdx;\n\t\t\n\t\tST(int a, int b) {\n\t\t\tL = a; R = b;\n\t\t\t\n\t\t\tif(a == b) {\n\t\t\t\tmax = distTo[a];\n\t\t\t\tmaxIdx = a;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tint mid = (a + b) / 2;\n\t\t\tleft = new ST(a, mid);\n\t\t\tright = new ST(mid+1, b);\n\t\t\t\n\t\t\tupdate();\n\t\t}\n\t\t\n\t\tvoid rangeAdd(int ll, int rr, long add) {\n\t\t\tif(rr < L || R < ll) return;\n\t\t\tif(ll <= L && R <= rr) {\n\t\t\t\tdelta += add;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tprop();\n\t\t\t\n\t\t\tleft.rangeAdd(ll, rr, add);\n\t\t\tright.rangeAdd(ll, rr, add);\n\t\t\t\n\t\t\tupdate();\n\t\t}\n\t\t\n\t\tp rangeMax(int ll, int rr) {\n\t\t\tif(rr < ll) return null;\n\t\t\tif(rr < L || R < ll) return null;\n\t\t\tif(ll <= L && R <= rr) {\n\t\t\t\treturn new p(maxIdx, getMax());\n\t\t\t}\n\t\t\tprop();\n\t\t\t\n\t\t\tp lf = left.rangeMax(ll, rr);\n\t\t\tp rg = right.rangeMax(ll, rr);\n\t\t\t\n\t\t\tupdate();\n\t\t\t\n\t\t\tif(lf == null) return rg;\n\t\t\tif(rg == null) return lf;\n\t\t\t\n\t\t\tif(rg.val >= lf.val) return rg;\n\t\t\treturn lf;\n\t\t}\n\t\t\n\t\tvoid prop() {\n\t\t\tif(delta == 0) return;\n\t\t\t\n\t\t\tleft.delta += delta;\n\t\t\tright.delta += delta;\n\n\t\t\tdelta = 0;\n\t\t}\n\t\t\n\t\tlong getMax() {\n\t\t\treturn max + delta;\n\t\t}\n\t\t\n\t\tvoid update() {\n\t\t\tlong leftVal = left.getMax();\n\t\t\tlong rightVal = right.getMax();\n\t\t\t\n\t\t\tif(leftVal >= rightVal) {\n\t\t\t\tmax = leftVal;\n\t\t\t\tif(leftVal == rightVal)\n\t\t\t\t\tmaxIdx = right.maxIdx;\n\t\t\t\telse\n\t\t\t\t\tmaxIdx = left.maxIdx;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmax = rightVal;\n\t\t\t\tmaxIdx = right.maxIdx;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tclass p implements Comparable

{\n\t\tint idx;\n\t\tlong val;\n\t\tp(int i, long v) { idx = i; val = v; }\n\t\tpublic int compareTo(p p) {\n\t\t\tint comp = Long.compare(val, p.val);\n\t\t\tif(comp == 0) comp = Integer.compare(idx, p.idx);\n\t\t\treturn comp;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"(%d, %d)\", idx, val);\n\t\t}\n\t}\n\t\n\tstatic class IntList {\n\t\tstatic int[] EMPTY = {};\n\t\tint n = 0, a[] = EMPTY;\n\t\tvoid add(int v) {\n\t\t\tif (n >= a.length)\n\t\t\t\ta = Arrays.copyOf(a, (n << 2) + 8);\n\t\t\ta[n++] = v;\n\t\t}\n\t\tint get(int idx) { return a[idx]; }\n\t\tint size() { return n; }\n\t}\n\t\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tFastScanner(){\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tString next() {\n\t\t\tif(st.hasMoreTokens()) return st.nextToken();\n\t\t\ttry { st = new StringTokenizer(br.readLine()); }\n\t\t\tcatch (Exception e) {}\n\t\t\treturn next();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\t\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50447062c73fdc2184859e2a55ce1733", "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class cfCEOI2019Day1B {\n\n\tstatic class HLD {\n\t\tint n, root;\n\n\t\t// g[v] - edges incident to node v, including the edge going up!\n\t\tint[][] g;\n\n\t\t// sz[v] - size of node v subree, node -> int\n\t\tint[] sz;\n\n\t\t// parent of node, node -> node\n\t\tint[] par;\n\n\t\tprivate int time = 0;\n\n\t\t// tree traversal, time -> node\n\t\tint[] order;\n\n\t\t// time when you get in/out of the node, node -> time\n\t\t// Subtree of v has times [ lft(v); rgh(v) )\n\t\tint[] lft, rgh;\n\n\t\t// lft and order are inverse permutations\n\n\t\t// depth, node -> 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]), node->chainId\n\t\t// if chainInfo[v] >=0 then chainInfo[v] is the head of chain that v\n\t\t// belongs to, node->node\n\t\tprivate int[] chainInfo;\n\n\t\t// top-most node of the corresponding chain, chainId -> node\n\t\tint[] chainHead;\n\n\t\t// down[v] = next node on the same chain as v, or -1 for leaves\n\t\tint[] down;\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\tpar = new int[n];\n\t\t\tdepth = new int[n];\n\t\t\tdfsSz(root, -1);\n\n\t\t\t// Find the chains/subtree ranges.\n\t\t\torder = new int[n];\n\t\t\tlft = new int[n];\n\t\t\trgh = new int[n];\n\t\t\tchainInfo = new int[n];\n\t\t\tchainHead = new int[n];\n\t\t\tchainHead[chainCnt] = root;\n\t\t\tchainInfo[root] = ~(chainCnt++);\n\t\t\tdown = new int[n];\n\t\t\tArrays.fill(down, -1);\n\t\t\tdfsChains(root, -1);\n\n\t\t\tchainHead = Arrays.copyOf(chainHead, chainCnt);\n\t\t\tbuf = new int[3 * chainCnt];\n\t\t}\n\n\t\t/**\n\t\t * @return list of triplets [chainId; pos1; pos2] in order corresponding\n\t\t * to the path from v to u
\n\t\t * pos1 <= pos2 = going down
\n\t\t * pos1 > pos2 = going up\n\t\t */\n\t\tpublic int[] getPath(int v, int u) {\n\t\t\tint headPtr = 0, tailPtr = buf.length;\n\t\t\tint chV = chainId(v), chU = chainId(u);\n\t\t\twhile (chV != chU) {\n\t\t\t\tint upV = chainHead[chV];\n\t\t\t\tint upU = chainHead[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] = lft[v] - lft[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} 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] = lft[u] - lft[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}\n\t\t\t}\n\t\t\tint base = lft[chainHead[chV]];\n\t\t\tbuf[headPtr] = chV;\n\t\t\tbuf[headPtr + 1] = lft[v] - base;\n\t\t\tbuf[headPtr + 2] = lft[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 : lft[chainHead[id + 1]]) - lft[chainHead[id]];\n\t\t}\n\n\t\t// the id of chain that node belongs to\n\t\t// node -> 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// node -> int\n\t\tpublic int chainPos(int node) {\n\t\t\tint x = chainInfo[node];\n\t\t\treturn x >= 0 ? lft[node] - lft[x] : 0;\n\t\t}\n\n\t\t// (chainId, int) -> node\n\t\tpublic int getNode(int chainId, int chainPos) {\n\t\t\tif (!(0 <= chainId && chainId < chainCnt)) {\n\t\t\t\tthrow new AssertionError(\"bad chainId\");\n\t\t\t}\n\t\t\tif (!(0 <= chainPos && chainPos < chainSz(chainId))) {\n\t\t\t\tthrow new AssertionError(\"bad chainPos\");\n\t\t\t}\n\t\t\treturn order[lft[chainHead[chainId]] + chainPos];\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\tpar[v] = p;\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\tdepth[u] = depth[v] + 1;\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\torder[time] = v;\n\t\t\tlft[v] = time++;\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\tif (i == 0) {\n\t\t\t\t\tdown[v] = u;\n\t\t\t\t\tchainInfo[u] = chainInfo[v] >= 0 ? chainInfo[v] : v;\n\t\t\t\t} else {\n\t\t\t\t\tchainHead[chainCnt] = u;\n\t\t\t\t\tchainInfo[u] = ~(chainCnt++);\n\t\t\t\t}\n\t\t\t\tdfsChains(u, v);\n\t\t\t}\n\n\t\t\trgh[v] = time;\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\n\t\tint[] depth = hld.depth;\n\t\tint[] lft = hld.lft;\n\t\tint[] rgh = hld.rgh;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tif (depth[vs[i]] > depth[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(lft[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\tint[] down = hld.down;\n\t\tfor (int v = 0; v < n; v++) {\n\t\t\tif (down[v] == -1) {\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 vDepth = depths.getPoint(lft[v]);\n\t\t\tlong headDepth = depths.getPoint(lft[head]);\n\t\t\tlong maxExceptChain = depths.getSegment(rgh[down[v]], 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 - headDepth - 2 * (vDepth - headDepth));\n\t\t}\n\n\t\tint[] order = hld.order;\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(lft[v], rgh[v], deltaW);\n\n\t\t\t\t// update relative depth and maxRelExceptChain for nodes below v 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\taux[ch].addSegment(pos, hld.chainSz(ch), -deltaW);\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.getNode(chainId, vPos);\n\t\t\t\t\tlong headDepth = depths.getPoint(lft[headV]);\n\t\t\t\t\tlong newVal = depths.getSegment(rgh[down[v]], rgh[v])\n\t\t\t\t\t\t\t- headDepth - 2 * (depths.getPoint(lft[v]) - headDepth);\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 deepVTime = depths.maxPos();\n\t\t\t\tint deepV = order[deepVTime]; // not just maxPos !!!\n\t\t\t\tif (down[deepV] != -1) {\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(deepVTime);\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(lft[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.getNode(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(lft[lastNode], lft[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(lft[lastNode]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t\tlast = ans;\n\t\t}\n\t}\n\n\tstatic final long INF = Long.MAX_VALUE / 3;\n\n\t// TODO: check with local parameters/without SegTree class at all?\n\tstatic class SegTree {\n\t\tstatic int ql, qr;\n\t\tstatic long delta;\n\t\tNode root;\n\n\t\tpublic SegTree(int n) {\n\t\t\troot = new Node(0, n);\n\t\t}\n\n\t\tpublic void addSegment(int ql, int qr, long delta) {\n\t\t\tif (ql == qr) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ql > qr) {\n\t\t\t\tthrow new AssertionError(\"ql > qr\");\n\t\t\t}\n\t\t\tSegTree.ql = ql;\n\t\t\tSegTree.qr = qr;\n\t\t\tSegTree.delta = delta;\n\t\t\troot.add();\n\t\t}\n\n\t\t// TODO: can improve!\n\t\tpublic void addPoint(int idx, long delta) {\n\t\t\taddSegment(idx, idx + 1, delta);\n\t\t}\n\n\t\tpublic long getSegment(int ql, int qr) {\n\t\t\tif (ql == qr) {\n\t\t\t\treturn -INF;\n\t\t\t}\n\t\t\tif (ql > qr) {\n\t\t\t\tthrow new AssertionError(\"ql > qr\");\n\t\t\t}\n\t\t\tSegTree.ql = ql;\n\t\t\tSegTree.qr = qr;\n\t\t\treturn root.get();\n\t\t}\n\t\t\n\t\tpublic void setPoint(int idx, long val) {\n\t\t\tql = idx;\n\t\t\tdelta = val;\n\t\t\troot.setPoint();\n\t\t}\n\n\t\t// TODO: can improve!\n\t\tpublic long getPoint(int idx) {\n\t\t\treturn getSegment(idx, idx + 1);\n\t\t}\n\n\t\tpublic int maxPos() {\n\t\t\treturn root.maxPos();\n\t\t}\n\n\t\tstatic class Node {\n\t\t\tint l, r;\n\t\t\tNode left, right;\n\t\t\tlong add, max;\n\n\t\t\tlong getMax() {\n\t\t\t\treturn max + add;\n\t\t\t}\n\n\t\t\tpublic Node(int l, int r) {\n\t\t\t\tthis.l = l;\n\t\t\t\tthis.r = r;\n\t\t\t\tif (r - l > 1) {\n\t\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\t\tleft = new Node(l, m);\n\t\t\t\t\tright = new Node(m, r);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid add() {\n\t\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\t\tadd += delta;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tleft.add();\n\t\t\t\tright.add();\n\t\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t\t}\n\n\t\t\tlong get() {\n\t\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\t\treturn -INF;\n\t\t\t\t}\n\t\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\t\treturn getMax();\n\t\t\t\t}\n\t\t\t\treturn Math.max(left.get(), right.get()) + add;\n\t\t\t}\n\n\t\t\tint maxPos() {\n\t\t\t\tif (r - l == 1) {\n\t\t\t\t\treturn l;\n\t\t\t\t}\n\t\t\t\treturn left.getMax() > right.getMax() ? left.maxPos() : right.maxPos();\n\t\t\t}\n\t\t\t\n\t\t\tvoid setPoint() {\n\t\t\t\tif (r - l == 1) {\n\t\t\t\t\tadd = 0;\n\t\t\t\t\tmax = delta;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tleft.add += add;\n\t\t\t\tright.add += add;\n\t\t\t\tadd = 0;\n\t\t\t\t(ql < left.r ? left :right).setPoint();\n\t\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tcfCEOI2019Day1B() throws IOException {\n\t\tif (System.getProperty(\"ONLINE_JUDGE\") == null) {\n\t\t\tis = new FileInputStream(\"in.txt\");\n\t\t} else {\n\t\t\tis = System.in;\n\t\t}\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cfCEOI2019Day1B();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "acca167e24c66b1bd926b7407d333a36", "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Q869A\n{\n\tpublic static void main(String asd[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint a[]=new int [n];\n\t\tint b[]=new int [n];\n\t\tfor(int x=0;x s = new set();\n\n\n\t vector x = new vector();\n\t for (int i = 0; i < n; i++)\n\t {\n\n\t\tlong xi;\n\t\txi = Long.parseLong(ConsoleInput.readToWhiteSpace(true));\n\t\tx.push_back(xi);\n\t\ts.insert(xi);\n\t }\n\n\n\t vector y = new vector();\n\t for (int i = 0; i < n; i++)\n\t {\n\t\n\t\tlong yi;\n\t\tyi = Long.parseLong(ConsoleInput.readToWhiteSpace(true));\n\t\ty.push_back(yi);\n\t\ts.insert(yi);\n\t }\n\n\n\t long counter = 0;\n\t for (int i = 0; i < n; i++)\n\t {\n\t\tfor (int j = 0; j < n; j++)\n\t\t{\n\n\t\t long xxy = x[i] ^ y[j];\n\t\t if (s.count(xxy) > 0)\n\t\t {\n\t\t\tcounter++;\n\t\t }\n\t\t}\n\t }\n\n\t if (counter % 2 == 0)\n\t {\n\t\tSystem.out.print(\"Karen\");\n\t\tSystem.out.print(\"\\n\");\n\t }\n\t else\n\t {\n\t\tSystem.out.print(\"Koyomi\");\n\t\tSystem.out.print(\"\\n\");\n\t }\n\n\t return 0;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "741dbf79fa4ed59686dd7f1dcfe1a7a0", "src_uid": "1649d2592eadaa8f8d076eae2866cffc", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\n\npublic class A \n{ \n public static void main(String args[])\n {\n \n System.out.print(\"Karen\");\n \n \n\n \n \n \n \n }\n catch(Exception e)\n {\n System.out.println(\"WHY?\");\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "47a885a9f1fdfaa74b9160969eb3240e", "src_uid": "1649d2592eadaa8f8d076eae2866cffc", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Q869A\n{\n\tpublic static void main(String asd[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint a[]=new int [n];\n\t\tint b[]=new int [n];\n\t\tfor(int x=0;x map = new TreeMap<>();\n int sum = 0;\n for(int i = 0; i < n; i++){\n int m = scanner.nextInt();\n sum += m;\n if(sum <= M){\n System.out.print(0+\" \");\n }\n else{\n int diff = sum - M;\n int count = 0;\n Integer last = map.lastKey();\n\n int lastCount = map.get(last);\n while(diff > 0){\n //System.out.println(last);\n\n if(lastCount == 1){\n diff -= last;\n count++;\n }\n else{\n int possibleCount = diff/last < 1 ? 1 : diff/last;\n //System.out.println(diff+\" \"+last);\n if(lastCount >= possibleCount){\n count += possibleCount;\n diff -= last*possibleCount;\n }\n else{\n count += lastCount;\n diff -= last*lastCount;\n }\n }\n last = map.lowerKey(last);\n if(last != null){\n lastCount = map.get(last);\n }\n\n\n }\n System.out.print(count+\" \");\n }\n if(map.containsKey(m)){\n map.put(m,map.get(m)+1);\n }\n else{\n map.put(m,1);\n }\n // print(map);\n }\n }\n public static void print(TreeMap map){\n Integer key = map.lastKey();\n while(key != null){\n System.out.print(key+\" \");\n key = map.lowerKey(key);\n }\n System.out.println();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "07fab9c671699c377996b7f9259555b5", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package practiceProblems;\n\nimport java.util.Scanner;\nimport java.util.Arrays;\n\npublic class problem1185C1 {\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint n = sc.nextInt();\n\t\t\n\t\tint t = sc.nextInt();\n\t\t\n\t\tint a[] = new int[n];\n\t\t\n\t\tfor(int i=0; i t) {\n\t\t\t\ttotalSum = totalSum - temp[currentElement];\n\t\t\t\tcurrentAns++;\n\t\t\t\tcurrentElement--;\n\t\t\t}\n\t\t\t\n\t\t\tans[i] = currentAns;\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int i=0; i{ \n \n // Overriding compare()method of Comparator \n // for descending order of cgpa \n public int compare(Integer s1, Integer s2) { \n if (s1< s2) \n return 1; \n else if (s1 > s2) \n return -1; \n return 0; \n } \n } \npublic class Solution {\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\tint[] a = new int[n];\n\t\tint[] su = new int[n];\n\t\tfor(int i=0;i pq = new PriorityQueue<>(new Omparator());\n\t\tfor(int i =0;im && i!=0 ){\n\t\t pq = new PriorityQueue<>(new Omparator());\n\t\t temp = i;\n\t\t for(int j = 0;jm && !pq.isEmpty()){\n\t\t k = pq.remove();\n\t\t su[i] = su[i] - k;\n\t\t \n\t\t count++;\n\t\t }\n\t\t System.out.print(count+\" \");\n\t\t }else{\n\t\t System.out.print(\"0 \");\n\t\t }\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1227b4f4b981bf71afcf8a35829bf50c", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\n//When I wrote this code, only God & I understood what it did. Now only God knows !!\n\nimport org.jetbrains.annotations.NotNull;\n\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main implements Runnable {\n @Override\n public void run() {\n FastReader fr = new FastReader();\n PrintWriter pw = new PrintWriter(System.out);\n /*\n\n */\n\n\n pw.flush();\n pw.close();\n }\n\n static class FastReader\n {\n private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}\n public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}\n public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}\n public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}\n public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}\n public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}\n public double d() throws IOException {return Double.parseDouble(next()) ;}\n public boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; }\n public boolean isEndOfLine(int c) { return c == '\\n' || c == '\\r' || c == -1; }\n public void scanIntArr(int [] arr){ for(int li=0;li0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }\n }\n\n public static int mod = (int) (1e9 + 7);\n public static void main(String[] args) throws IOException {\n // new Thread(null,new Main(),\"Anything\",1<<27).start();\n\n FastReader fr = new FastReader();\n PrintWriter pw = new PrintWriter(System.out);\n /*\ninputCopy\n7 15\n1 2 3 4 5 6 7\noutputCopy\n0 0 0 0 0 2 3\ninputCopy\n5 100\n80 40 40 40 60\noutputCopy\n0 1 1 2 3\n */\n int n=fr.i();\n int m=fr.i();\n Candidate [] candidates=new Candidate[n];\n for(int ni=0;ni pq=new PriorityQueue<>();\n int curTime=0;\n int ans=0;\n for(int i=0;i=0)\n {\n curTime-=pq.remove().t;\n ++ans;\n if(curTime+candidates[i].t<=m)\n break;\n }\n pq.add(candidates[i]);\n curTime+=candidates[i].t;\n //System.err.println(\"ans=\"+ans+\"i=\"+i+\" curTime=\"+curTime);\n candidates[i].ans=ans;\n }\n }\n for(Candidate c:candidates)\n pw.print(c.ans+\" \");\n pw.flush();\n pw.close();\n }\n public static class Candidate implements Comparable\n {\n int t;\n int id;\n int ans;\n public Candidate(int t, int id) {\n this.t = t;\n this.id = id;\n }\n\n @Override\n public int compareTo(@NotNull Main.Candidate candidate) {\n return Integer.compare(this.t,candidate.t)*-1;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9d047629ae39aa43a6fd2b8fc7a1fa06", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic final int[] DX = { -1, 0, 1, 0 };\n\tstatic final int[] DY = { 0, -1, 0, 1 };\n\n\tstatic final int P = 1_000_000_007;\n\n\tint[] cacheInv = new int[10_000];\n\t{\n\t\tcacheInv[1] = 1;\n\t\tfor (int i = 2; i < cacheInv.length; i++) {\n\t\t\tcacheInv[i] = P - (int) ((long) (P / i) * cacheInv[P % i] % P);\n\t\t}\n\t}\n\n\tint inv(int x) {\n\t\tif (x < cacheInv.length) {\n\t\t\treturn cacheInv[x];\n\t\t}\n\t\treturn P - (int) ((long) (P / x) * inv(P % x) % P);\n\t}\n\n\tvoid submit() {\n\t\tint r = nextInt();\n\t\tint[] byDir = new int[4];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = nextInt();\n\t\t\tsum += byDir[i];\n\t\t}\n\n\t\tint invSum = inv(sum);\n\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = (int) ((long) byDir[i] * invSum % P);\n\t\t}\n\n\t\tint s = 2 * r + 3;\n\n\t\tint[][] f = new int[s][s];\n\t\tint[] cx = new int[s * s];\n\t\tint[] cy = new int[s * s];\n\t\tint vars = 0;\n\t\tfor (int i = 0; i < s; i++) {\n\t\t\tfor (int j = 0; j < s; j++) {\n\t\t\t\tint sum2 = (i - r - 1) * (i - r - 1) + (j - r - 1)\n\t\t\t\t\t\t* (j - r - 1);\n\t\t\t\tif (sum2 <= r * r) {\n\t\t\t\t\tcx[vars] = i;\n\t\t\t\t\tcy[vars] = j;\n\t\t\t\t\tf[i][j] = vars++;\n\t\t\t\t} else {\n\t\t\t\t\tf[i][j] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint band = 0;\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\t\t\t\tband = Math.max(band, Math.abs(i - j));\n\t\t\t}\n\t\t}\n\n\t\tint[][] bandM = new int[vars][2 * band + 1];\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\n\t\t\t\tupdateBandedMatrix(i, j, band, bandM, byDir[dir]);\n\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tfor (int d = 0; d <= 2 * band; d++) {\n\t\t\t\tint j = i + d - band;\n\t\t\t\tbandM[i][d] = (i == j ? 1 : 0) - bandM[i][d];\n\t\t\t\tif (bandM[i][d] < 0) {\n\t\t\t\t\tbandM[i][d] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint[] ans = inverseBanded(bandM, band, f[r + 1][r + 1]);\n\n\t\tint ret = 0;\n\t\tfor (int x : ans) {\n\t\t\tret += x;\n\t\t\tif (ret >= P) {\n\t\t\t\tret -= P;\n\t\t\t}\n\t\t}\n\n\t\tout.println(ret);\n\n\t}\n\n\tvoid updateBandedMatrix(int row, int col, int width, int[][] m, double delta) {\n\t\tif (Math.abs(row - col) > width) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tm[row][col - row + width] += delta;\n\t}\n\n\tint[] inverseBanded(int[][] a, int w, int whatCol) {\n\t\tint n = a.length;\n\t\tif (whatCol > n) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tint[] b = new int[n];\n\t\tb[whatCol] = 1;\n\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tint[] aj = a[j];\n\t\t\tfor (int i = j + 1; i <= j + w && i < n; i++) {\n\t\t\t\tint[] ai = a[i];\n\t\t\t\tint coef = (int) ((long) ai[j - i + w] * inv(aj[w]) % P);\n\t\t\t\t\n\t\t\t\tfor (int k = j + 1; k < n && k <= j + w; k++) {\n\t\t\t\t\tai[k - i + w] -= (int) ((long) aj[k - j + w] * coef % P);\n\t\t\t\t\tif (ai[k - i + w] < 0) {\n\t\t\t\t\t\tai[k - i + w] += P;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tb[i] -= (int) ((long) b[j] * coef % P);\n\t\t\t\tif (b[i] < 0) {\n\t\t\t\t\tb[i] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tfor (int j = i + 1; j < n && j <= i + w; j++) {\n\t\t\t\tint coef = a[i][j - i + w];\n\t\t\t\tb[i] -= (int) ((long) b[j] * coef % P);\n\t\t\t\tif (b[i] < 0) {\n\t\t\t\t\tb[i] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t\tb[i] = (int)((long)b[i] * inv(a[i][w]) % P);\n\t\t}\n\n\t\treturn b;\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "82fda49cea3d22f13e640a234ce6dff4", "src_uid": "bd6bcb5bffd039de93f217b02f5eae17", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic final int[] DX = { -1, 0, 1, 0 };\n\tstatic final int[] DY = { 0, -1, 0, 1 };\n\n\tstatic final int P = 1_000_000_007;\n\n\tstatic final int CACHE_SIZE = 1 << 19;\n\tint[] cacheInv = new int[CACHE_SIZE];\n\t{\n\t\tcacheInv[1] = 1;\n\t\tfor (int i = 2; i < CACHE_SIZE; i++) {\n\t\t\tcacheInv[i] = P - (int) ((long) (P / i) * cacheInv[P % i] % P);\n\t\t}\n\t}\n\n\tint inv(int x) {\n\t\treturn x < CACHE_SIZE ? cacheInv[x] : P\n\t\t\t\t- (int) ((long) (P / x) * inv(P % x) % P);\n\t}\n\n\tvoid submit() {\n\t\t// long start = System.currentTimeMillis();\n\t\tint r = nextInt();\n\t\tint[] byDir = new int[4];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = nextInt();\n\t\t\tsum += byDir[i];\n\t\t}\n\n\t\tint invSum = inv(sum);\n\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = (int) ((long) byDir[i] * invSum % P);\n\t\t}\n\n\t\tint s = 2 * r + 3;\n\n\t\tint[][] f = new int[s][s];\n\t\tint[] cx = new int[s * s];\n\t\tint[] cy = new int[s * s];\n\t\tint vars = 0;\n\t\tfor (int i = 0; i < s; i++) {\n\t\t\tfor (int j = 0; j < s; j++) {\n\t\t\t\tint sum2 = (i - r - 1) * (i - r - 1) + (j - r - 1)\n\t\t\t\t\t\t* (j - r - 1);\n\t\t\t\tif (sum2 <= r * r) {\n\t\t\t\t\tcx[vars] = i;\n\t\t\t\t\tcy[vars] = j;\n\t\t\t\t\tf[i][j] = vars++;\n\t\t\t\t} else {\n\t\t\t\t\tf[i][j] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint band = 0;\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\t\t\t\tband = Math.max(band, Math.abs(i - j));\n\t\t\t}\n\t\t}\n\n\t\tint[][] bandM = new int[vars][2 * band + 1];\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\n\t\t\t\tupdateBandedMatrix(i, j, band, bandM, byDir[dir]);\n\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tfor (int d = 0; d <= 2 * band; d++) {\n\t\t\t\tint j = i + d - band;\n\t\t\t\tbandM[i][d] = (i == j ? 1 : 0) - bandM[i][d];\n\t\t\t\tif (bandM[i][d] < 0) {\n\t\t\t\t\tbandM[i][d] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// out.println(System.currentTimeMillis() - start);\n\n\t\tint[] ans = inverseBanded(bandM, band, f[r + 1][r + 1]);\n\n\t\t// out.println(System.currentTimeMillis() - start);\n\n\t\tint ret = 0;\n\t\tfor (int x : ans) {\n\t\t\tret += x;\n\t\t\tif (ret >= P) {\n\t\t\t\tret -= P;\n\t\t\t}\n\t\t}\n\n\t\tout.println(ret);\n\n\t}\n\n\tvoid updateBandedMatrix(int row, int col, int width, int[][] m, double delta) {\n\t\tif (Math.abs(row - col) > width) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tm[row][col - row + width] += delta;\n\t}\n\n\tint[] inverseBanded(int[][] a, int w, int whatCol) {\n\t\tint n = a.length;\n\t\tif (whatCol > n) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tint[] b = new int[n];\n\t\tb[whatCol] = 1;\n\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tint[] aj = a[j];\n\t\t\tfor (int i = j + 1; i <= j + w && i < n; i++) {\n\t\t\t\tint[] ai = a[i];\n\t\t\t\tint coef = (int) ((long) ai[j - i + w] * inv(aj[w]) % P);\n\n\t\t\t\tint kUpTo = Math.min(n, j + w + 1);\n\t\t\t\t\n\t\t\t\tfor (int k = j + 1; k < kUpTo; k++) {\n\t\t\t\t\tint kek = ai[k - i + w]\n\t\t\t\t\t\t\t- (int) ((long) aj[k - j + w] * coef % P);\n\t\t\t\t\tif (kek < 0) {\n\t\t\t\t\t\tkek += P;\n\t\t\t\t\t}\n\t\t\t\t\tai[k - i + w] = kek;\n\t\t\t\t}\n\t\t\t\tb[i] -= (int) ((long) b[j] * coef % P);\n\t\t\t\tif (b[i] < 0) {\n\t\t\t\t\tb[i] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// for (int i = n - 1; i >= 0; i--) {\n\t\t// for (int j = i + 1; j < n && j <= i + w; j++) {\n\t\t// b[i] -= (int) ((long) b[j] * a[i][j - i + w] % P);\n\t\t// if (b[i] < 0) {\n\t\t// b[i] += P;\n\t\t// }\n\t\t// }\n\t\t// b[i] = (int) ((long) b[i] * inv(a[i][w]) % P);\n\t\t// }\n\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tlong tot = 0;\n\t\t\tfor (int j = i + 1; j < n && j <= i + w; j++) {\n\t\t\t\ttot += (long) b[j] * a[i][j - i + w];\n\t\t\t\tif (tot >= P2) {\n\t\t\t\t\ttot -= P2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tb[i] -= (int) (tot % P);\n\t\t\tif (b[i] < 0) {\n\t\t\t\tb[i] += P;\n\t\t\t}\n\t\t\tb[i] = (int) ((long) b[i] * inv(a[i][w]) % P);\n\t\t}\n\n\t\treturn b;\n\t}\n\n\tstatic final long P2 = (long) P * P;\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ddac76864a8c5cb79d48891910af1fa9", "src_uid": "bd6bcb5bffd039de93f217b02f5eae17", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic final int[] DX = { -1, 0, 1, 0 };\n\tstatic final int[] DY = { 0, -1, 0, 1 };\n\n\tstatic final int P = 1_000_000_007;\n\n\tstatic final int CACHE_SIZE = 1 << 19;\n\tint[] cacheInv = new int[CACHE_SIZE];\n\t{\n\t\tcacheInv[1] = 1;\n\t\tfor (int i = 2; i < CACHE_SIZE; i++) {\n\t\t\tcacheInv[i] = P - (int) ((long) (P / i) * cacheInv[P % i] % P);\n\t\t}\n\t}\n\n\tint inv(int x) {\n\t\treturn x < CACHE_SIZE ? cacheInv[x] : P\n\t\t\t\t- (int) ((long) (P / x) * inv(P % x) % P);\n\t}\n\n\tvoid submit() {\n\t\t// long start = System.currentTimeMillis();\n\t\tint r = nextInt();\n\t\tint[] byDir = new int[4];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = nextInt();\n\t\t\tsum += byDir[i];\n\t\t}\n\n\t\tint invSum = inv(sum);\n\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = (int) ((long) byDir[i] * invSum % P);\n\t\t}\n\n\t\tint s = 2 * r + 3;\n\n\t\tint[][] f = new int[s][s];\n\t\tint[] cx = new int[s * s];\n\t\tint[] cy = new int[s * s];\n\t\tint vars = 0;\n\t\tfor (int i = 0; i < s; i++) {\n\t\t\tfor (int j = 0; j < s; j++) {\n\t\t\t\tint sum2 = (i - r - 1) * (i - r - 1) + (j - r - 1)\n\t\t\t\t\t\t* (j - r - 1);\n\t\t\t\tif (sum2 <= r * r) {\n\t\t\t\t\tcx[vars] = i;\n\t\t\t\t\tcy[vars] = j;\n\t\t\t\t\tf[i][j] = vars++;\n\t\t\t\t} else {\n\t\t\t\t\tf[i][j] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint band = 0;\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\t\t\t\tband = Math.max(band, Math.abs(i - j));\n\t\t\t}\n\t\t}\n\n\t\tint[][] bandM = new int[vars][2 * band + 1];\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\n\t\t\t\tupdateBandedMatrix(i, j, band, bandM, byDir[dir]);\n\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tfor (int d = 0; d <= 2 * band; d++) {\n\t\t\t\tint j = i + d - band;\n\t\t\t\tbandM[i][d] = (i == j ? 1 : 0) - bandM[i][d];\n\t\t\t\tif (bandM[i][d] < 0) {\n\t\t\t\t\tbandM[i][d] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// out.println(System.currentTimeMillis() - start);\n\n\t\tint[] ans = inverseBanded(bandM, band, f[r + 1][r + 1]);\n\n\t\t// out.println(System.currentTimeMillis() - start);\n\n\t\tint ret = 0;\n\t\tfor (int x : ans) {\n\t\t\tret += x;\n\t\t\tif (ret >= P) {\n\t\t\t\tret -= P;\n\t\t\t}\n\t\t}\n\n\t\tout.println(ret);\n\n\t}\n\n\tvoid updateBandedMatrix(int row, int col, int width, int[][] m, double delta) {\n\t\tif (Math.abs(row - col) > width) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tm[row][col - row + width] += delta;\n\t}\n\n\tint[] inverseBanded(int[][] a, int w, int whatCol) {\n\t\tint n = a.length;\n\t\tif (whatCol > n) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tint[] b = new int[n];\n\t\tb[whatCol] = 1;\n\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tint[] aj = a[j];\n\t\t\tfor (int i = j + 1; i <= j + w && i < n; i++) {\n\t\t\t\tint[] ai = a[i];\n\t\t\t\tint coef = (int) ((long) ai[j - i + w] * inv(aj[w]) % P);\n\t\t\t\t\n\t\t\t\tif (coef == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint kwiUpTo = Math.min(n, j + w + 1) + w - i;\n\t\t\t\t\n//\t\t\t\tfor (int k = j + 1, kwi = (j + 1) + w - i; k < kUpTo; k++, kwi++) {\n\t\t\t\tfor (int kwi = (j + 1) + w - i; kwi < kwiUpTo; kwi++) {\n\t\t\t\t\tint kek = ai[kwi]\n\t\t\t\t\t\t\t- (int) ((long) aj[kwi + i - j] * coef % P);\n\t\t\t\t\tif (kek < 0) {\n\t\t\t\t\t\tkek += P;\n\t\t\t\t\t}\n\t\t\t\t\tai[kwi] = kek;\n\t\t\t\t}\n\t\t\t\tb[i] -= (int) ((long) b[j] * coef % P);\n\t\t\t\tif (b[i] < 0) {\n\t\t\t\t\tb[i] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tlong tot = 0;\n\t\t\tfor (int j = i + 1; j < n && j <= i + w; j++) {\n\t\t\t\ttot += (long) b[j] * a[i][j - i + w];\n\t\t\t\tif (tot >= P2) {\n\t\t\t\t\ttot -= P2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tb[i] -= (int) (tot % P);\n\t\t\tif (b[i] < 0) {\n\t\t\t\tb[i] += P;\n\t\t\t}\n\t\t\tb[i] = (int) ((long) b[i] * inv(a[i][w]) % P);\n\t\t}\n\n\t\treturn b;\n\t}\n\n\tstatic final long P2 = (long) P * P;\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0cabb788dae15b039cea4819147ef5ac", "src_uid": "bd6bcb5bffd039de93f217b02f5eae17", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class 852HBobsAndStages {\n\n\tclass Bubble {\n\t\tint x, y;\n\t\tint id1, id2;\n\n\t\tpublic Bubble(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tint q() {\n\t\t\tif (x == 0 && y == 0) {\n\t\t\t\treturn 0;\n\t\t\t} else if (x > 0 || (x == 0 && y > 0)) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 2;\n\t\t\t}\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"Bubble [x=\" + x + \", y=\" + y + \", id1=\" + id1 + \", id2=\" + id2 + \"]\";\n\t\t}\n\t}\n\n\tlong vectMul(Bubble a, Bubble b) {\n\t\treturn 1L * a.x * b.y - 1L * a.y * b.x;\n\t}\n\n\tlong vectMul(Bubble a, Bubble b, Bubble c) {\n\t\treturn 1L * (b.x - a.x) * (c.y - a.y) - 1L * (b.y - a.y) * (c.x - a.x);\n\t}\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tBubble[] a = new Bubble[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new Bubble(in.nextInt(), in.nextInt());\n\t\t}\n\t\tArrays.sort(a, (p1, p2) -> {\n\t\t\tif (p1.x != p2.x) {\n\t\t\t\treturn p1.x - p2.x;\n\t\t\t}\n\t\t\treturn p1.y - p2.y;\n\t\t});\n\n\t\tlong result = 0;\n\t\tlong[][] dp = new long[n][k + 1];\n\t\tlong[][] cost = new long[n][n];\n\t\tlong INF = Long.MIN_VALUE / 3;\n\t\tBubble[] buf = new Bubble[n];\n\t\tfor (int i = 0; i < buf.length; i++) {\n\t\t\tbuf[i] = new Bubble(0, 0);\n\t\t}\n\t\tBubble[] vecs = new Bubble[n * (n - 1)];\n\t\tfor (int i = 0, tmp = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (i != j) {\n\t\t\t\t\tvecs[tmp] = new Bubble(a[j].x - a[i].x, a[j].y - a[i].y);\n\t\t\t\t\tvecs[tmp].id1 = i;\n\t\t\t\t\tvecs[tmp].id2 = j;\n\t\t\t\t\ttmp++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrays.sort(vecs, (p1, p2) -> {\n\t\t\tint q1 = p1.q(), q2 = p2.q();\n\t\t\tif (q1 != q2) {\n\t\t\t\treturn q1 - q2;\n\t\t\t}\n\t\t\treturn -Long.signum(vectMul(p1, p2));\n\t\t});\n\t\tfor (int start = 0; start < n; start++) {\n\t\t\tfor (int i = n - 1; i >= start; i--) {\n\t\t\t\ta[i].x -= a[start].x;\n\t\t\t\ta[i].y -= a[start].y;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tArrays.fill(dp[i], INF);\n\t\t\t\tArrays.fill(cost[i], INF);\n\t\t\t}\n\t\t\tdp[start][0] = 0;\n\n\t\t\tint size = 0;\n\t\t\tfor (int i = start + 1; i < n; i++) {\n\t\t\t\tbuf[size].x = a[i].x;\n\t\t\t\tbuf[size].y = a[i].y;\n\t\t\t\tbuf[size].id1 = i;\n\t\t\t\tsize++;\n\t\t\t}\n\t\t\tArrays.sort(buf, 0, size, (p1, p2) -> {\n\t\t\t\tlong v = vectMul(p1, p2);\n\t\t\t\treturn -Long.signum(v);\n\t\t\t});\n\n\t\t\tfor (int i = 0; i < size; i++) {\n\t\t\t\tfor (int j = i + 1; j < size; j++) {\n\t\t\t\t\tint p1 = buf[i].id1, p2 = buf[j].id1;\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\tfor (int t = i + 1; t < j; t++) {\n\t\t\t\t\t\tif (vectMul(buf[i], buf[j], buf[t]) > 0) {\n\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\tcost[p1][p2] = vectMul(buf[i], buf[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < size; i++) {\n\t\t\t\tcost[start][buf[i].id1] = cost[buf[i].id1][start] = 0;\n\t\t\t}\n\n\t\t\tfor (Bubble vec : vecs) {\n\t\t\t\tint p1 = vec.id1, p2 = vec.id2;\n\t\t\t\tlong cst = cost[p1][p2];\n\t\t\t\tif (cst != INF) {\n\t\t\t\t\tlong[] dp1 = dp[p1], dp2 = dp[p2];\n\t\t\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\t\t\tdp2[i + 1] = Math.max(dp2[i + 1], dp1[i] + cst);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tresult = Math.max(result, dp[start][k]);\n\t\t}\n\n\t\tout.printf(\"%d.%02d\\n\", result / 2, 50 * (result % 2));\n\t}\n\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\tin = new FastScanner();\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastScanner(String s) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic String nextToken() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew 852HBobsAndStages().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a430e3514623904c9f5a144e0290c325", "src_uid": "6afcdad100c8e2469fef5abcc5bd96c6", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class 808ALuckyYear\n{\n\n public static void main(String[] args) \n {\n Scanner in=new Scanner(System.in);\n \n String s=in.next();\n StringBuilder ss=new StringBuilder();\n \n \n if(s.length()==1)\n {\n System.out.println(\"1\");\n }\n \n else\n {\n if(s.charAt(0)!='9')\n {\n char ch=(char) ((int)s.charAt(0)+1);\n ss.append(ch);\n }\n \n else\n ss.append(\"10\");\n \n for(int i=1;i 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 \"Point [x=\" + x + \", y=\" + y + \", id1=\" + id1 + \", id2=\" + id2 + \"]\";\n\t\t}\n\t}\n\n\tlong vectMul(Point a, Point b) {\n\t\treturn 1L * a.x * b.y - 1L * a.y * b.x;\n\t}\n\n\tlong vectMul(Point a, Point b, Point 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\tPoint[] a = new Point[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new Point(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\tPoint[] buf = new Point[n];\n\t\tfor (int i = 0; i < buf.length; i++) {\n\t\t\tbuf[i] = new Point(0, 0);\n\t\t}\n\t\tPoint[] vecs = new Point[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 Point(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 (Point 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 H().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c5f09b74faae1065e417c20f425fec16", "src_uid": "6afcdad100c8e2469fef5abcc5bd96c6", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class 852HBobsAndStages {\n\n\tclass Bubble {\n\t\tint x, y;\n\t\tint id1, id2;\n\n\t\tpublic Bubble(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tint q() {\n\t\t\tif (x == 0 && y == 0) {\n\t\t\t\treturn 0;\n\t\t\t} else if (x > 0 || (x == 0 && y > 0)) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 2;\n\t\t\t}\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"Bubble [x=\" + x + \", y=\" + y + \", id1=\" + id1 + \", id2=\" + id2 + \"]\";\n\t\t}\n\t}\n\n\tlong vectMul(Bubble a, Bubble b) {\n\t\treturn 1L * a.x * b.y - 1L * a.y * b.x;\n\t}\n\n\tlong vectMul(Bubble a, Bubble b, Bubble c) {\n\t\treturn 1L * (b.x - a.x) * (c.y - a.y) - 1L * (b.y - a.y) * (c.x - a.x);\n\t}\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tBubble[] a = new Bubble[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new Bubble(in.nextInt(), in.nextInt());\n\t\t}\n\t\tArrays.sort(a, (p1, p2) -> {\n\t\t\tif (p1.x != p2.x) {\n\t\t\t\treturn p1.x - p2.x;\n\t\t\t}\n\t\t\treturn p1.y - p2.y;\n\t\t});\n\n\t\tlong result = 0;\n\t\tlong[][] dp = new long[n][k + 1];\n\t\tlong[][] cost = new long[n][n];\n\t\tlong INF = Long.MIN_VALUE / 3;\n\t\tBubble[] buf = new Bubble[n];\n\t\tfor (int i = 0; i < buf.length; i++) {\n\t\t\tbuf[i] = new Bubble(0, 0);\n\t\t}\n\t\tBubble[] vecs = new Bubble[n * (n - 1)];\n\t\tfor (int i = 0, tmp = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (i != j) {\n\t\t\t\t\tvecs[tmp] = new Bubble(a[j].x - a[i].x, a[j].y - a[i].y);\n\t\t\t\t\tvecs[tmp].id1 = i;\n\t\t\t\t\tvecs[tmp].id2 = j;\n\t\t\t\t\ttmp++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrays.sort(vecs, (p1, p2) -> {\n\t\t\tint q1 = p1.q(), q2 = p2.q();\n\t\t\tif (q1 != q2) {\n\t\t\t\treturn q1 - q2;\n\t\t\t}\n\t\t\treturn -Long.signum(vectMul(p1, p2));\n\t\t});\n\t\tfor (int start = 0; start < n; start++) {\n\t\t\tfor (int i = n - 1; i >= start; i--) {\n\t\t\t\ta[i].x -= a[start].x;\n\t\t\t\ta[i].y -= a[start].y;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tArrays.fill(dp[i], INF);\n\t\t\t\tArrays.fill(cost[i], INF);\n\t\t\t}\n\t\t\tdp[start][0] = 0;\n\n\t\t\tint size = 0;\n\t\t\tfor (int i = start + 1; i < n; i++) {\n\t\t\t\tbuf[size].x = a[i].x;\n\t\t\t\tbuf[size].y = a[i].y;\n\t\t\t\tbuf[size].id1 = i;\n\t\t\t\tsize++;\n\t\t\t}\n\t\t\tArrays.sort(buf, 0, size, (p1, p2) -> {\n\t\t\t\tlong v = vectMul(p1, p2);\n\t\t\t\treturn -Long.signum(v);\n\t\t\t});\n\n\t\t\tfor (int i = 0; i < size; i++) {\n\t\t\t\tfor (int j = i + 1; j < size; j++) {\n\t\t\t\t\tint p1 = buf[i].id1, p2 = buf[j].id1;\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\tfor (int t = i + 1; t < j; t++) {\n\t\t\t\t\t\tif (vectMul(buf[i], buf[j], buf[t]) > 0) {\n\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\tcost[p1][p2] = vectMul(buf[i], buf[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < size; i++) {\n\t\t\t\tcost[start][buf[i].id1] = cost[buf[i].id1][start] = 0;\n\t\t\t}\n\n\t\t\tfor (Bubble vec : vecs) {\n\t\t\t\tint p1 = vec.id1, p2 = vec.id2;\n\t\t\t\tlong cst = cost[p1][p2];\n\t\t\t\tif (cst != INF) {\n\t\t\t\t\tlong[] dp1 = dp[p1], dp2 = dp[p2];\n\t\t\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\t\t\tdp2[i + 1] = Math.max(dp2[i + 1], dp1[i] + cst);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tresult = Math.max(result, dp[start][k]);\n\t\t}\n\n\t\tout.printf(\"%d.%02d\\n\", result / 2, 50 * (result % 2));\n\t}\n\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\tin = new FastScanner();\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastScanner(String s) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic String nextToken() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew H().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c5fce85191d47977870bc73eee41483a", "src_uid": "6afcdad100c8e2469fef5abcc5bd96c6", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.FileInputStream;\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;\n try {\n inputStream = new FileInputStream(\"input.txt\");\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n OutputStream outputStream;\n try {\n outputStream = new FileOutputStream(\"output.txt\");\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n c290 solver = new c290();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class c290 {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += in.nextInt();\n }\n out.println((double) sum / n);\n }\n\n }\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String next() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ac808fff6d3942223853732a4fa9cf2", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\nimport java.io.*;\n\n// The \"ProblemC\" class.\npublic class ProblemC\n{\n public static void main (String[] args) throws IOException\n {\n\t\tScanner inFile = new Scanner(new File(\"DATA_C.txt\"));\n\t\tScanner inSys = new Scanner(System.in);\n\t\t//PrintStream outFile = new PrintStream(new File(\"OUT_C.txt\"));\n\t\tPrintStream outSys = new PrintStream(System.out);\n\t\t\n\t\t//int numloops = Integer.parseInt(inFile.nextLine());\n\t\tint numloops = Integer.parseInt(inSys.nextLine());\n\t\tint sum = 0;\n\t\tint[] nums = new int[numloops];\n\t\t\n\t\tfor(int i = 0; i < numloops; i++)\n\t\t{\n\t\t\t//nums[i] = Integer.parseInt(inFile.nextLine());\n\t\t\tnums[i] = Integer.parseInt(inSys.nextLine());\n\t\t\t//System.out.println(nums[i]);\n\t\t}\n\t\t\n\t\tint x = 0;\n\t\twhile(nums[x] <= nums[x+1])\n\t\t{\n\t\t\tx++;\n\t\t\tif(x == (numloops-1))\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tx++;\n\t\tfor(int i = 0; i < x; i++)\n\t\t{\n\t\t\t//System.out.println(nums[i]);\n\t\t\tsum+=nums[i];\n\t\t}\n\t\t\n\t\tSystem.out.println(1.0 * sum / x);\n } // main method\n} // ProblemC class\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00537c6489e19a38ed696f07836af497", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "public class C1 {\n\n\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int tux = in.nextInt();\n int foo = 0;\n int bar = 0;\n int baz = 0;\n int quz = 1;\n for(;tux!=0;tux--) {\n int pur = in.nextInt();\n foo += pur;\n bar += 1;\n if((foo*quz*bar)>=(baz*foo*quz)) {\n baz = foo;\n quz = bar;\n }\n }\n System.out.println(baz/(float)quz);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e874c59ee1e32148d6aac35b6a520fba", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class _290_C {\n\tboolean testOutput=true;\n\tpublic void runTestCases() throws Exception{\n//\t\tCase 0\n\t\tinput=\n\t\t\"3 \"+\n\t\t\"0 \"+\n\t\t\"1 \"+\n\t\t\"1 \";\n\t\trunTest(input,\n\t\t\"0.666667 \");\n\n\n\t}\n\t\n\tpublic void compare(String rcAnswer, String realAnswer){\n\t\trealAnswer=realAnswer.trim();\n\t\trcAnswer=rcAnswer.trim();\n\t\tif(realAnswer.equals(rcAnswer)){\n\t\t\tSystem.out.println(\"[Passed] Case \"+nroCases);\n\t\t}else{\n\t\t\tfailed=true;\n\t\t\tSystem.out.println(\"rChi \"+rcAnswer);\n\t\t\tSystem.out.println(\"Expected \"+realAnswer);\n\t\t\tSystem.out.println(\"[Failed] Case \"+nroCases);\n//\t\t\tSystem.exit(0);\n\t\t}\n\t\tnroCases++;\n\t}\n\t\n\tpublic void runTest(String input, String output) throws Exception{\n\t\tr.in= new ByteArrayInputStream(input.getBytes());\n\t\tr.run();\n\t\tif(testOutput){\n\t\t\tcompare(baos.toString(), output);\n\t\t}else{\n\t\t\tSystem.out.println(baos.toString());\n\t\t}\n\t\tbaos.reset();\n//\t\tr.in.\n\t}\n\t_290_C_WTF r;\n\tByteArrayOutputStream baos = new ByteArrayOutputStream();\n\tprivate void init() throws Exception{\n\t\tr = new _290_C_WTF();\n\t\tr.out = new PrintWriter(baos);\n\t\trunTestCases();\n\t\tif(testOutput && !failed){\n\t\t\tSystem.out.println(\"All test cases [Passed]\");\n\t\t}\n\t}\n\tprivate String input;\n\tprivate int nroCases=1;\n\tprivate boolean failed=false;\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew _290_C().init();\n\t}\n\t\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0867cbffd18ba7c47ffa40dd04c8aaa5", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CircleOfNumbers {\n\tpublic static void main(String[] args) {\n\t\tScanner kbd = new Scanner(System.in);\n\t\tint input = kbd.nextInt();\n\t\twhile(input < 3 && input > 100000) {\n\t\t\tif(input < 3 && input > 100000) {\n\t\t\t\tSystem.out.println(\"Input should be greater than three and less than 100,000.\");\n\t\t\t\tinput = kbd.nextInt();\n\t\t\t}\n\t\t}\n\t\tString number = kbd.next();\n\t\tfor(int i = 0; i < number.length(); i++) {\n\t\t\tnumber[i] = number[i] + input;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9c1e9c8c0e682db749cd25957a709fb2", "src_uid": "63c00c5ea7aee792e8a30dc2c330c3f7", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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 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 bool 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}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6cfb5ed90b698d9bfc1d042e3b010ee6", "src_uid": "63c00c5ea7aee792e8a30dc2c330c3f7", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.FileInputStream;\nimport java.io.PrintStream;\nimport java.util.*;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\n\npublic class Main {\n\tpublic static BigDecimal[] a = new BigDecimal[100000];\n\tpublic static boolean[] flag = new boolean[100000];\n\tpublic static MathContext mc = new MathContext(100);\n\tpublic static final BigDecimal eps = BigDecimal.ONE.movePointLeft(50);\n\tpublic static final BigDecimal neps = BigDecimal.ZERO.subtract(eps);\n\tpublic static void main(String args[]) {\n\t\tScanner cin = new Scanner (new BufferedInputStream(System.in));\n\t\tPrintStream cout = System.out;\n//\t\ttry{\n//\t\t\tcin = new Scanner(new FileInputStream(\"in.in\"));\n//\t\t\tcout = new PrintStream(\"out.out\");\n//\t\t}catch (Exception e) {\n//\t\t}\n\t\t\n\t\tint n=cin.nextInt();\n\t\tString s = cin.next();\n\t\tfor(int i=0; i 180) {\n\t\t\ta -= 360;\n\t\t} else if (a < -180) {\n\t\t\ta += 360;\n\t\t}\n\t\t\n\t\tif (a > 0) {\n\t\t\tif ((a + 45) % 90 == 0) {\n\t\t\t\tSystem.out.println((a + 45) / 90 - 1);\n\t\t\t} else {\n\t\t\t\tSystem.out.println((a + 45) / 90);\n\t\t\t}\n\t\t} else if (a < 0) {\n\t\t\tif ((a + 45) % 90 == 0) {\n\t\t\t\tSystem.out.println(3 * -(a - 45) / 90 - 3);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(3 * -(a - 45) / 90);\n\t\t\t}\n\t\t} else {\n\t\t\tSystem.out.println(0);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2b118c7366592948ac085307ef90cb95", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Turn {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong a = in.nextLong();\n\t\ta %= 360;\n\t\ta += 360;\n\t\ta %= 360;\n\t\t\t\t\n\t\tif (a <= 45 || a >=315) {\n\t\t\tSystem.out.println(0);\n\t\t} else if (a <= 135) {\n\t\t\tSystem.out.println(1);\n\t\t} else if (a < 225) {\n\t\t\tSystem.out.println(2);\n\t\t} else {\n\t\t\tSystem.out.println(3);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ecf62c34b1ca4aeb5b724beb15799109", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class M {\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong x = Long.parseLong(br.readLine());\n\n\t\tlong y = Math.abs(x);\n\n\t\tint z = (int) ((y % 360) * (long) Math.signum(x));\n\n\t\tint min = (int) Math.min(Math.abs(z), Math.abs(360 - z));\n\t\tint best = 0;\n\n\t\tfor (int i = 1; i < 4; i++) {\n\t\t\tz = (z + 90 + 360) % 360;\n\t\t\tint m = (int) Math.min(Math.abs(z), Math.abs(360 - z));\n\t\t\tif (m < min) {\n\t\t\t\tbest = i;\n\t\t\t\tmin = m;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(best);\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a47eac4cb8d332174742569d5e31ea6d", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class M {\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n static InputReader r = new InputReader(System.in);\n static PrintWriter pw = new PrintWriter(System.out);\n\n public static void main(String[] args) {\n \n ArrayList list = new ArrayList();\n\n long k = r.nextLong();\n int x = (int)(k % 360);\n list.add(new int[]{0, Math.min(Math.min(Math.abs(x), Math.abs(x-360)), Math.abs(x+360))});\n\n for(int i = 1; i <= 3; i++){\n x -= 90;\n x %= 360;\n list.add(new int[]{i, Math.min(Math.min(Math.abs(x), Math.abs(x-360)), Math.abs(x + 360))});\n }\n\n Collections.sort(list, new Sort());\n \n for(int[] arr : list){\n System.out.println(Arrays.toString(arr));\n }\n \n System.out.println(list.get(0)[0]);\n \n pw.close();\n }\n\n static class Sort implements Comparator{\n public int compare(int[] a, int[] b){\n if(a[1] == b[1]){\n return a[0] - b[0];\n } else{\n return a[1] - b[1];\n }\n }\n }\n}\n\n/**\n* _ _ _ \n* | | | | | | \n* ___ ___ __| | ___ | |__ _ _ __| | __ _ _ __ _ __ ___ _ __ _ _ __ _ ___ \n* / __/ _ \\ / _` |/ _ \\ | '_ \\| | | | / _` |/ _` | '__| '__/ _ \\ '_ \\ | | | |/ _` |/ _ \\ \n* | (_| (_) | (_| | __/ | |_) | |_| | | (_| | (_| | | | | | __/ | | | | |_| | (_| | (_) |\n* \\___\\___/ \\__,_|\\___| |_.__/ \\__, | \\__,_|\\__,_|_| |_| \\___|_| |_| \\__, |\\__,_|\\___/ \n* __/ | ______ __/ | \n* |___/ |______|___/ \n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "749d682889db3d08e29dd0a6fc49c515", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class Main \n{\n\tpublic static void main( String args[] )\n\t{\n\t\tScanner input = new Scanner(System.in);\n\t\tlong a1 = input.nextInt();\n\t\tlong b1 = input.nextInt();\n\t\tlong a2 = input.nextInt();\n\t\tlong b2 = input.nextInt();\n\t\tlong l = input.nextInt();\n\t\tlong r = input.nextInt();\n\t\tlong first = 2000000000 + 1;\n\t\tlong counter = 0;\n\t\tlong gcd = gcd(a1, a2);\n\t\tlong scm = ( a1 * a2 ) / gcd;\n\t\t\n\t\tif(b1>b2)\n\t {\n\t long c=b1;\n\t b1=b2;\n\t b2=c;\n\t c=a1;\n\t a1=a2;\n\t a2=c;\n\t }\n\t long k1=-1,l1=0;\n\t while(k1==-1)\n\t {\n\t if( (a2*l1+b2-b1)%a1==0)\n\t k1 = (a2*l1+b2-b1)/a1;\n\t else\n\t l1++;\n\t }\n\t long x1=a1*k1+b1;\n\t\t\n\t\t\n\t\tif( x1 < l )\n\t\t{\n\t\t\tlong m = (l - x1) / scm + 1;\n\t\t\tx1 += m * scm;\n\t\t}\n\t\t\n\t\tif( x1 != 2000000000 + 1 && x1 >= l && x1 <= r)\n\t\t\tcounter = (r - x1) / scm + 1;\n\t\t\n\t\tif( x1 != l && (l - b1) % a1 == 0 && (l - b2) % a2 == 0 && (l - b1) / a1 >= 0 && (l - b2) / a2 >= 0)\n\t\t\tcounter++;\n\t\t\n\t\tSystem.out.println(counter);\n\t\t\n\t}\n\t\n\tpublic static long gcd( long a, long b )\n\t{\n\t\tif( b == 0 )\n\t\t\treturn a;\n\t\t\n\t\treturn gcd (b, a % b );\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7ec6d714cd4d755ff7abd0515907f78", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main \n{\n\tpublic static void main( String args[] )\n\t{\n\t\tScanner input = new Scanner(System.in);\n\t\tint a1 = input.nextInt();\n\t\tint b1 = input.nextInt();\n\t\tint a2 = input.nextInt();\n\t\tint b2 = input.nextInt();\n\t\tint l = input.nextInt();\n\t\tint r = input.nextInt();\n\t\tint first = 2000000000 + 1, counter = 0;\n\t\t\n\t\t\n\t\tif( b1 > r || b2 > r )\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tfor( int i = 0 ; ; i++ )\n\t\t{\n\t\t\tif( ((a1 * i + b1) - b2) % a2 == 0 && ((a1 * i + b1) - b2) / a2 >= 0 )\n\t\t\t{\n\t\t\t\tfirst = a1 * i + b1;\n\t\t\t\t\n\t\t\t\tif( first >= l && first <= r )\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif( first != 2000000000 + 1 )\n\t\t\tcounter = (r - first) / (( a1 * a2 ) / gcd(a1, a2)) + 1;\n\t\t\n\t\tSystem.out.println(counter);\n\t\t\n\t}\n\t\n\tpublic static int gcd( int a, int b )\n\t{\n\t\tif( b == 0 )\n\t\t\treturn a;\n\t\t\n\t\treturn gcd (b, a % b );\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "78263f6c108fc0608fc2ae83992e0bd0", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main \n{\n\tpublic static void main( String args[] )\n\t{\n\t\tScanner input = new Scanner(System.in);\n\t\tlong a1 = input.nextInt();\n\t\tlong b1 = input.nextInt();\n\t\tlong a2 = input.nextInt();\n\t\tlong b2 = input.nextInt();\n\t\tlong l = input.nextInt();\n\t\tlong r = input.nextInt();\n\t\tlong first = 2000000000 + 1;\n\t\tlong counter = 0;\n\t\tlong gcd = gcd(a1, a2);\n\t\t\n\t\tif( b1 > r || b2 > r )\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tfor( long i = 0 ; ; i++ )\n\t\t{\n\t\t\tif( b1 >= b2 )\n\t\t\t{\n\t\t\t\tif( ((a1 * i + b1) - b2) % a2 == 0 && ((a1 * i + b1) - b2) / a2 >= 0 )\n\t\t\t\t{\n\t\t\t\t\tfirst = i * a1 + b1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif( b1 < b2 )\n\t\t\t{\n\t\t\t\tif( ((a2 * i + b2) - b1) % a1 == 0 && ((a2 * i + b2) - b1) / a1 >= 0 )\n\t\t\t\t{\n\t\t\t\t\tfirst = a2 * i + b2;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif( first < l )\n\t\t{\n\t\t\tlong m = (l - first) / (( a1 * a2 ) / gcd) + 1;\n\t\t\tfirst += m * (( a1 * a2 ) / gcd);\n\t\t}\n\t\t\n\t\tif( first != 2000000000 + 1 )\n\t\t\tcounter = (r - first) / (( a1 * a2 ) / gcd) + 1;\n\t\t\n\t\tSystem.out.println(counter);\n\t\t\n\t}\n\t\n\tpublic static long gcd( long a, long b )\n\t{\n\t\tif( b == 0 )\n\t\t\treturn a;\n\t\t\n\t\treturn gcd (b, a % b );\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66232686beac6a34d0fbe74c3dbc2e43", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport static java.lang.Long.max;\nimport static java.lang.Math.abs;\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class NewClass {\n static long x,y,d;\n public static long mcd(long a, long b){\n return a==0 ? b : mcd(b%a,a);\n }\n\n public static long mcm(long a,long b){\n return a*(b/mcd(a,b));\n }\n \n public static void extendedEuclid(long a, long b){\n if(a==0){x=0;y=1;d=b;return;}\n extendedEuclid(b%a,a);\n long x1=y-(b/a)*x;\n long y1=x;\n x=x1;\n y=y1;\n }\n \n public static void main(String[] args) {\n long a1,b1,a2,b2,l,r;\n Scanner sc = new Scanner(System.in);\n a1 = sc.nextInt();\n b1 = sc.nextInt();\n a2 = sc.nextInt();\n b2 = sc.nextInt();\n l = sc.nextInt();\n r = sc.nextInt();\n extendedEuclid(a1,a2);\n if(abs(b2-b1)%d!=0){\n System.out.println(\"0\");\n return;\n }\n x*=((b2-b1)/d);\n y*=((b2-b1)/d);\n d=b2-b1;\n BigInteger Bx = new BigInteger(Double.toString((x)));\n BigInteger Ba1 = new BigInteger(Double.toString((a1)));\n BigInteger Bb1 = new BigInteger(Double.toString((b1)));\n Long jaux=mcm(a1,a2);\n BigInteger j = new BigInteger(jaux.toString());\n BigInteger p= new BigInteger(\"\");\n p = Bx.multiply(Ba1).add(Bb1);\n Long a=max(b1,b2);\n BigInteger aa = new BigInteger(a.toString());\n if( p.compareTo(aa) < 0){\n BigInteger aux=(p.subtract(aa)).abs();\n aux = aux.divide(j);\n aux = aux.add(BigInteger.ONE);\n p = p.add(aux.multiply(j));\n }\n if(p.compareTo(aa)>0){\n BigInteger aux=(p.subtract(aa)).divide(j);\n p = p.subtract(aux.multiply(j));\n }\n l = l - Long.parseLong(p.toString()) + Long.parseLong(j.toString());\n r = r - Long.parseLong(p.toString()) + Long.parseLong(j.toString());\n long res;\n l=max(0,l);\n r=max(0,r);\n res = r/Long.parseLong(j.toString()) - l/Long.parseLong(j.toString());\n if(l%Long.parseLong(j.toString())==0){\n if(l!=0)res++;\n }\n \n System.out.println(res);\n\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dcde949c62b62fb0d0ffea42a140ee45", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "/*package whatever //do not write package name here */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n public class GFG {\n \n\tpublic static void main (String[] args) throws IOException {\n Scanner in=new Scanner(System.in\n \n String str=in.nextLine();\n \n for(int i=0;i check = new ArrayList();\n check.add(\"ABC\");check.add(\"ACB\");check.add(\"BAC\");check.add(\"BCA\");check.add(\"CAB\");check.add(\"CBA\");\n int cas=0;\n for( i=0;ib?a:b;\n\t}\n\tpublic static int min(int a,int b)\n\t{\n\t\treturn a {\n start();\n out(solve(a));\n });\n }\n\n private void start() {\n int n = dp.length;\n for(int i=1;i 2)\n r -= (h - 2) * ab;\n int d = a > b ? a - b : 1;\n for (h = 0; h < m; h++) {\n for (int k = 0; k < a - d; k++)\n cc[(a + b) * h + k] = k;\n for (int k = 0; k < d; k++)\n cc[(a + b) * h + a - d + k] = h % 2 == 0 ? a - d + k : a + k;\n }\n int min = a + a;\n for (int k0 = 1; k0 <= d; k0++) {\n for (int k = 0; k < b; k++)\n cc[(a + b) * 0 + a + k] = cc[(a + b) * 0 + a - k0];\n for (int k1 = 1; k1 <= d; k1++) {\n for (int k = 0; k < b; k++)\n cc[(a + b) * 1 + a + k] = cc[(a + b) * 1 + a - k1];\n for (int k2 = 1; k2 <= d; k2++) {\n for (int k = 0; k < b; k++)\n cc[(a + b) * 2 + a + k] = cc[(a + b) * 2 + a - k2];\n for (int k3 = 1; k3 <= d; k3++) {\n for (int k = 0; k < b; k++)\n cc[(a + b) * 3 + a + k] = cc[(a + b) * 3 + a - k3];\n min = Math.min(min, count(cc, l, r));\n }\n }\n }\n }\n out.println(min);\n }\n\n static int count(int[] cc, int l, int r) {\n boolean[] used = new boolean[24];\n int cnt = 0;\n for (int i = l; i <= r; i++) {\n int c = cc[i];\n if (!used[c]) {\n used[c] = true;\n cnt++;\n }\n }\n return cnt;\n }\n\n }\n\n static class FastReader {\n private InputStream stream;\n private byte[] buf = new byte[8192];\n private int curChar;\n private int pnumChars;\n private FastReader.SpaceCharFilter filter;\n\n public FastReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (pnumChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= pnumChars) {\n curChar = 0;\n try {\n pnumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (pnumChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = 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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b4927193d8e3a9797cabecd217b4aeab", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class C\n{\n\tstatic PrintWriter out = new PrintWriter(\n\t\t\tnew BufferedOutputStream(System.out));\n\tstatic MyScanner sc = new MyScanner(System.in);\n\tstatic StringBuilder output = new StringBuilder();\n\n\tpublic static void main(String... args)\n\t{\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint l = sc.nextInt() - 1;\n\t\tint r = sc.nextInt();\n\t\t\n\t\tr -= l / (a + b) * (a + b);\n\t\tl -= l / (a + b) * (a + b);\n\t\t\n\t\tif (r > (a + b) * 3)\n\t\t{\n\t\t\tr -= r / (a + b) * (a + b);\n\t\t\tr += (a + b) * 3;\n\t\t}\n\t\t\n\t\tint[] seq = new int[r];\n\t\t\n\t\tfor (int i = 0; i < r; i++)\n\t\t{\n\t\t\tseq[i] = i;\n\t\t}\n\t\t\n\t\t{\n\t\t\tint i = a;\n\t\t\twhile (i < r)\n\t\t\t{\n\t\t\t\tif (i % (a + b) < a)\n\t\t\t\t{\n\t\t\t\t\tHashSet used = new HashSet();\n\t\t\t\t\tfor (int j = i - 1; i - j <= a; j--)\n\t\t\t\t\t{\n\t\t\t\t\t\tused.add(seq[j]);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfor (int j = 0; i % (a + b) != a && i < r; i++, j++)\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (used.contains(j))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tj++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tused.add(j);\n\t\t\t\t\t\t\n\t\t\t\t\t\tseq[i] = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tseq[i] = seq[i - 1];\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint result;\n\t\t\n\t\t{\n\t\t\tHashSet used = new HashSet();\n\t\t\t\n\t\t\tfor (int i = l; i < r; i++)\n\t\t\t{\n\t\t\t\tused.add(seq[i]);\n\t\t\t}\n\t\t\t\n\t\t\tresult = used.size();\n\t\t}\n\t\t\n\t\tfor(int i = a; i < a + b && i < r; i++)\n\t\t{\n\t\t\tseq[i] = seq[b];\n\t\t}\n\t\t\n\t\t{\n\t\t\tint i = a + b;\n\t\t\twhile (i < r)\n\t\t\t{\n\t\t\t\tif (i % (a + b) < a)\n\t\t\t\t{\n\t\t\t\t\tHashSet used = new HashSet();\n\t\t\t\t\tfor (int j = i - 1; i - j <= a; j--)\n\t\t\t\t\t{\n\t\t\t\t\t\tused.add(seq[j]);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfor (int j = 0; i % (a + b) != a && i < r; i++, j++)\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (used.contains(j))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tj++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tused.add(j);\n\t\t\t\t\t\t\n\t\t\t\t\t\tseq[i] = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tseq[i] = seq[i - 1];\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t{\n\t\t\tHashSet used = new HashSet();\n\t\t\t\n\t\t\tfor (int i = l; i < r; i++)\n\t\t\t{\n\t\t\t\tused.add(seq[i]);\n\t\t\t}\n\t\t\t\n\t\t\tresult = Math.min(result, used.size());\n\t\t}\n\t\t\n\n\t\t\n\t\toutput.append(result);\n\t\t\n\n\t\teOP();\n\t}\n\t\n\tprivate static void eOP()\n\t{\n\t\tSystem.out.println(output);\n\t\tSystem.exit(0);\n\t}\n\t\n\t/**\n\t * Flatfoot's Scanner with slight modifications.\n\t * \n\t * @author Flatfoot\n\t * @see Source\n\t */\n\tprivate static class MyScanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tMyScanner(InputStream in)\n\t\t{\n\t\t\tthis.br = new BufferedReader(new InputStreamReader(in));\n\t\t}\n\n\t\tString next()\n\t\t{\n\t\t\twhile (this.st == null || !this.st.hasMoreElements())\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tthis.st = new StringTokenizer(this.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 this.st.nextToken();\n\t\t}\n\n\t\tint nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(this.next());\n\t\t}\n\n\t\tlong nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(this.next());\n\t\t}\n\n\t\tdouble nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(this.next());\n\t\t}\n\n\t\t/**\n\t\t * This method has been modified to be a bit more similar to Scanner's\n\t\t * \n\t\t * @author Flatfoot,\n\t\t * JasonBaby\n\t\t */\n\t\tString nextLine()\n\t\t{\n\t\t\tif (this.st == null || !this.st.hasMoreElements())\n\t\t\t{\n\t\t\t\tString str = \"\";\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tstr = this.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\treturn str;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tStringBuilder str = new StringBuilder();\n\t\t\t\twhile (this.st.hasMoreElements())\n\t\t\t\t{\n\t\t\t\t\tstr.append(this.st.nextToken());\n\t\t\t\t\tstr.append(\" \");\n\t\t\t\t}\n\t\t\t\tstr.deleteCharAt(str.length() - 1);\n\t\t\t\treturn str.toString();\n\t\t\t}\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "41bb9ed3d7f95d32c28d5710e4788746", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A421 {\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n OutputWriter out = new OutputWriter(System.out);\n int c = in.nextInt();\n int v0 = in.nextInt();\n int v1 = in.nextInt();\n int a = in.nextInt();\n int l = in.nextInt();\n int read = 0;\n //process first day\n int days = 1;\n read += v0;\n v0 -= l;\n v1 -= l;\n v0 += a;\n //days with increasing number of pages\n if(a > 0) {\n while(v0 <= v1 && read < c) {\n days++;\n read += v0;\n v0 += a;\n }\n }\n //days with v1 per day\n if(a > 0) v0 = v1;\n if(read < c) {\n days += (c - read - 1) / v0 + 1;\n } \n out.print(days);\n out.close();\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 printf(String format, Object... objects) {\n writer.printf(format, objects);\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n }\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3eefb3c3744c24c4b379aa38e2e25bdb", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "package c820;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class C\n{\n\tstatic PrintWriter out = new PrintWriter(\n\t\t\tnew BufferedOutputStream(System.out));\n\tstatic MyScanner sc = new MyScanner(System.in);\n\tstatic StringBuilder output = new StringBuilder();\n\n\tpublic static void main(String... args)\n\t{\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint l = sc.nextInt() - 1;\n\t\tint r = sc.nextInt();\n\t\t\n\t\tr -= l / (a + b) * (a + b);\n\t\tl -= l / (a + b) * (a + b);\n\t\t\n\t\tif (r > (a + b) * 3)\n\t\t{\n\t\t\tr -= r / (a + b) * (a + b);\n\t\t\tr += (a + b) * 3;\n\t\t}\n\t\t\n\t\tint[] seq = new int[r];\n\t\t\n\t\tfor (int i = 0; i < r; i++)\n\t\t{\n\t\t\tseq[i] = i;\n\t\t}\n\t\t\n\t\t{\n\t\t\tint i = a;\n\t\t\twhile (i < r)\n\t\t\t{\n\t\t\t\tif (i % (a + b) < a)\n\t\t\t\t{\n\t\t\t\t\tHashSet used = new HashSet();\n\t\t\t\t\tfor (int j = i - 1; i - j <= a; j--)\n\t\t\t\t\t{\n\t\t\t\t\t\tused.add(seq[j]);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfor (int j = 0; i % (a + b) != a && i < r; i++, j++)\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (used.contains(j))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tj++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tused.add(j);\n\t\t\t\t\t\t\n\t\t\t\t\t\tseq[i] = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tseq[i] = seq[i - 1];\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint result;\n\t\t\n\t\t{\n\t\t\tHashSet used = new HashSet();\n\t\t\t\n\t\t\tfor (int i = l; i < r; i++)\n\t\t\t{\n\t\t\t\tused.add(seq[i]);\n\t\t\t}\n\t\t\t\n\t\t\tresult = used.size();\n\t\t}\n\t\t\n\t\tfor(int i = a; i < a + b && i < r; i++)\n\t\t{\n\t\t\tseq[i] = seq[b];\n\t\t}\n\t\t\n\t\t{\n\t\t\tint i = a + b;\n\t\t\twhile (i < r)\n\t\t\t{\n\t\t\t\tif (i % (a + b) < a)\n\t\t\t\t{\n\t\t\t\t\tHashSet used = new HashSet();\n\t\t\t\t\tfor (int j = i - 1; i - j <= a; j--)\n\t\t\t\t\t{\n\t\t\t\t\t\tused.add(seq[j]);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfor (int j = 0; i % (a + b) != a && i < r; i++, j++)\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (used.contains(j))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tj++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tused.add(j);\n\t\t\t\t\t\t\n\t\t\t\t\t\tseq[i] = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tseq[i] = seq[i - 1];\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t{\n\t\t\tHashSet used = new HashSet();\n\t\t\t\n\t\t\tfor (int i = l; i < r; i++)\n\t\t\t{\n\t\t\t\tused.add(seq[i]);\n\t\t\t}\n\t\t\t\n\t\t\tresult = Math.min(result, used.size());\n\t\t}\n\t\t\n\n\t\t\n\t\toutput.append(result);\n\t\t\n\n\t\teOP();\n\t}\n\t\n\tprivate static void eOP()\n\t{\n\t\tSystem.out.println(output);\n\t\tSystem.exit(0);\n\t}\n\t\n\t/**\n\t * Flatfoot's Scanner with slight modifications.\n\t * \n\t * @author Flatfoot\n\t * @see Source\n\t */\n\tprivate static class MyScanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tMyScanner(InputStream in)\n\t\t{\n\t\t\tthis.br = new BufferedReader(new InputStreamReader(in));\n\t\t}\n\n\t\tString next()\n\t\t{\n\t\t\twhile (this.st == null || !this.st.hasMoreElements())\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tthis.st = new StringTokenizer(this.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 this.st.nextToken();\n\t\t}\n\n\t\tint nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(this.next());\n\t\t}\n\n\t\tlong nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(this.next());\n\t\t}\n\n\t\tdouble nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(this.next());\n\t\t}\n\n\t\t/**\n\t\t * This method has been modified to be a bit more similar to Scanner's\n\t\t * \n\t\t * @author Flatfoot,\n\t\t * JasonBaby\n\t\t */\n\t\tString nextLine()\n\t\t{\n\t\t\tif (this.st == null || !this.st.hasMoreElements())\n\t\t\t{\n\t\t\t\tString str = \"\";\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tstr = this.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\treturn str;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tStringBuilder str = new StringBuilder();\n\t\t\t\twhile (this.st.hasMoreElements())\n\t\t\t\t{\n\t\t\t\t\tstr.append(this.st.nextToken());\n\t\t\t\t\tstr.append(\" \");\n\t\t\t\t}\n\t\t\t\tstr.deleteCharAt(str.length() - 1);\n\t\t\t\treturn str.toString();\n\t\t\t}\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "616e83c9cf9718513eace77f6ce848ee", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport static java.lang.Math.max;\nimport static java.lang.Long.min;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.pow;\nimport static java.lang.System.out;\nimport java.util.*;\n \npublic class Kaudo { \n static Reader in =new Reader();\n static StringBuilder Sd=new StringBuilder();\n static long ans=0,res;\n public static void main(String [] args) {\n int n =in.nextInt(),k=in.nextInt(),x=in.nextInt();\n int a[]=new int [n];\n for(int i=0;i=0&&a[u]==xo){l++;u--;}\n if(o=0&&o=3){ans+=l;}\n else break;\n l=0;}\n if(o>=n&&u<0){\n if(l>=3){ans+=l;}\n \n break;}\n if(u<0&&a[o]!=xo){ if(l>=3){ans+=l;}\n break;}\n if(o>=n&&a[u]!=xo){ if(l>=3){ans+=l;}\n break;}}}\n res=max(res,ans-1);\n ans=0;\n }\n System.out.println(res);\n }\n\n static class Reader \n { \n private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} \n public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} \n public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} \n public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} \n public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} \n public int nextInt(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} \n public double d() throws IOException {return Double.parseDouble(s()) ;}\n public boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; } \n public boolean isEndOfLine(int c) { return c == '\\n' || c == '\\r' || c == -1; } \n public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = nextInt();}return ret;}\n }\n \n}\nclass Sorting{\n \n public static int[] bucketSort(int[] array, int bucketCount) {\n \n if (bucketCount <= 0) throw new IllegalArgumentException(\"Invalid bucket count\");\n \n if (array.length <= 1) return array; //trivially sorted\n \n \n \n int high = array[0];\n \n int low = array[0];\n \n for (int i = 1; i < array.length; i++) { //find the range of input elements\n \n if (array[i] > high) high = array[i];\n \n if (array[i] < low) low = array[i];\n \n }\n \n double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket\n \n \n ArrayList buckets[] = new ArrayList[bucketCount];\n \n for (int i = 0; i < bucketCount; i++) { //initialize buckets\n \n buckets[i] = new ArrayList();\n \n }\n \n \n \n for (int i = 0; i < array.length; i++) { //partition the input array\n \n buckets[(int)((array[i] - low)/interval)].add(array[i]);\n \n }\n \n \n int pointer = 0;\n \n for (int i = 0; i < buckets.length; i++) {\n \n Collections.sort(buckets[i]); //mergeSort\n \n for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets\n \n array[pointer] = buckets[i].get(j);\n \n pointer++;\n \n }\n \n}\n \nreturn array;\n \n}\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a7b841c030660dca6526bc2ef9190188", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Balls {\n \n public static void main(String args[]) throws Exception {\n \n MyScanner in = new MyScanner();\n\n int n = in.nextInt();\n int m = in.nextInt();\n int k = in.nextInt();\n int[] b = new int [n];\n int sum=0,max=0,buf=0;\n for (int i = 0; i < n; i++) {\n b[i] = in.nextInt(); \n }\n for (int i = 0; i < n-1; i++) {\n if (b[i]==k && b[i+1]==k) {\n sum+=2;\n }\n if (i-1>0 && i+2=0 && b[x-1]==b[y]) {\n buf++;\n if (x>0) x--;\n }\n if (y+10) sum += buf+2;\n max = Math.max(max,sum);\n sum=0;\n buf=0;\n }\n \n System.out.println(max);\n \n }\n\n\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "518e85c08895fa335d5888f63a28e673", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author Hidayat\n */\npublic class B245 {\n\n public static void main(String args[]) {\n\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(), k = in.nextInt(), x = in.nextInt();\n\n List a = new LinkedList();\n List b = new LinkedList();\n for (int i = 1; i <= n; i++) {\n int col = in.nextInt();\n a.add(col);\n b.add(col);\n }\n\n int result = 0;\n\n for (int i = 1; i <= n - 1; i++) {\n a = new LinkedList();\n for (int idx = 0; idx < n; idx++) {\n a.add(b.get(idx));\n }\n\n a.add(i, x);\n boolean removed = false;\n int numOfRemoved = 0;\n do {\n if (a.size() < 3) {\n removed = false;\n } else {\n int countg = 1;\n for (int j = 1; j < a.size(); j++) {\n if (a.get(j) == a.get(j - 1)) {\n countg++;\n } else {\n if (countg >= 3) {\n\n for (int idx = j - 1; idx >= j - countg; idx--) {\n a.remove(idx);\n }\n\n removed = true;\n }\n countg = 1;\n }\n }\n if (countg >= 3) {\n int sz = a.size();\n for (int idx = sz - 1; idx >= sz - countg; idx--) {\n a.remove(idx);\n }\n }\n\n }\n\n } while (removed);\n if (a.size() < b.size()) {\n result = Math.max(result, b.size() - a.size());\n }\n }\n System.out.println(result);\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "89767616d3a6f45103704dbd64ac1b63", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Scanner;\nimport java.util.Arrays;\nimport java.lang.Math;\n\npublic class MyCode {\n\tpublic static void main (String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int x = sc.nextInt();\n \n ArrayList list = new ArrayList<>();\n for(int i = 0; i < n; i++){\n list.add(sc.nextInt());\n }\n \n ArrayList newL = new ArrayList<>();\n for(int i = 0; i < n; i++){\n int s = list.get(i);\n if(newL.size() == 0){\n newL.add(new Group(s, 1));\n } else {\n Group last = newL.get(newL.size() - 1);\n int lastVal = last.val;\n if(s == lastVal){\n last.countUp();\n } else {\n newL.add(new Group(s, 1));\n }\n }\n }\n \n int ansCount = 0;\n int l = 0;\n int r = 0;\n for(int i = 0; i < newL.size(); i++){\n Group s = newL.get(i);\n if(x == s.val){\n if(s.count > 1){\n l = i - 1;\n r = i + 1;\n int tempCount = 2;\n while(l >= 0 && r < newL.size() \n && newL.get(l).val == newL.get(r).val\n && newL.get(l).count + newL.get(r).count >= 3){\n tempCount += newL.get(r).count + newL.get(l).count;\n r += 1;\n l -= 1;\n }\n if(tempCount > ansCount){\n ansCount = tempCount;\n }\n }\n }\n }\n \n System.out.print(ansCount);\n }\n}\n\npublic class Group {\n public int val;\n public int count;\n \n public Group(int val, int count){\n this.val = val;\n this.count = count;\n }\n \n public void countUp(){\n this.count += 1;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "76b66538bce8871d7335202bf3c420dc", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\n\n// **** D. Cute Sequences ****\n\npublic class D {\n\tstatic char [] in = new char [1000000];\n\tpublic static void main (String [] arg) throws Throwable {\n\t\tint q = nextInt();\n\t\tStringBuilder ans = new StringBuilder(q*50*3);\n\t\tfor (int ii = 0; ii>2;\n\t\tb -= pow * a;\n\t\tlong [] tmp_badans = new long [1];\n\t\ttmp_badans[0] = -1;\n\t\t//System.err.println(\"Trying length \" + len + \" with pow \" + pow + \" b is now \" + b);\n\t\tif (b < 0) return tmp_badans;\n\t\t\n\t\t\n\t\tlong [] ans = new long [len];\n\t\tlong [] r = new long [len-1];\n\t\tans[0] = a;\n\t\tlong pow2 = pow;\n\t\tfor (int i = 0; i>1;\n\t\t\tb -= pow2;\n\t\t\tif ( b < 0) return tmp_badans;\n\t\t}\n\t\n\t\tfor (int i = 0; i < r.length; ++i) {\n\t\t\tif (pow != 1) pow = pow >> 1;\n\t\t\tlong fac = b/pow;\n\t\t\tif (fac > m-1) fac = m-1;\n\t\t\tb -= fac * pow;\n\t\t\tr[i] = fac + 1;\n\t\t}\n\t\tif (b != 0) return null;\n\t\t\n\t\tfor (int i = 1; i{public HS(){super();}public HS(int a){super(a);}};\n\tstatic class AL extends ArrayList{public AL(){super();}public AL(int a){super (a);}};\n\tstatic class Pair implements Comparable{int x,y,L; public Pair(int xx, int yy, int LL){x=xx;y=yy;L=LL;} public int compareTo(Pair p) {return this.L-L;}}\t\n\t\n\t/************** FAST IO CODE FOLLOWS *****************/\n\tpublic static long nextLong() throws Throwable {\n\t\tlong i = System.in.read();boolean neg = false;while (i < 33) i = System.in.read();if (i == 45) {neg=true;i=48;}i = i - 48;\n\t\tint j = System.in.read();while (j > 32) {i*=10;i+=j-48;j = System.in.read();}return (neg) ? -i : i;\n\t}\n\tpublic static int nextInt() throws Throwable {return (int)nextLong();}\n\tpublic static String next() throws Throwable {\n\t\tint i = 0; while (i < 33 && i != -1) i = System.in.read(); int cptr = 0; while (i >= 33) { in[cptr++] = (char)i; i = System.in.read();}\n\t\treturn new String(in, 0,cptr);\n\t}\n\t/**** LIBRARIES ****/\n\tpublic static long gcdL(long a, long b) {while (b != 0) {long tmp = b;b = (a % b);a = tmp;}return a;}\n\tpublic static int gcd(int a, int b) {while (b != 0) {int tmp = b;b = (a % b);a = tmp;}return a;}\n\tpublic static int[] sieve(int LIM) {\n\t\tint i,count = 0;\n\t\tboolean [] b = new boolean [LIM];\n\t\tfor (i = 2;i=1; j--){\n long r = diff/contr[j];\n if(r>=m)r = m-1;\n diff-=contr[j]*r;\n rem[j] = 1+r;\n }\n if(diff==0){ \n p(i+\" \"+a);\n long cur = a; sum = a;\n for(int j = 1; j< i; j++){\n cur = sum+rem[i-j];\n sum+=cur;\n p(\" \"+cur);\n }\n pn(\"\");return;\n }\n }\n pn(-1);\n }\n boolean fill(long[] contr, long[] rem, int ind, long diff, long m){\n if(ind==0)return diff==0;\n long r = diff/contr[ind];\n \n }\n \n //SOLUTION END\n void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n long mod = (long)998244353, IINF = (long)1e18;\n final int INF = (int)1e9, MX = (int)5e5+1;\n DecimalFormat df = new DecimalFormat(\"0.00000000000\");\n double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;\n static boolean multipleTC = true, memory = false;\n FastReader in;PrintWriter out;\n void run() throws Exception{\n in = new FastReader();\n out = new PrintWriter(System.out);\n //Solution Credits: Taranpreet Singh\n int T = (multipleTC)?ni():1;\n pre();for(int t = 1; t<= T; t++)solve(t);\n out.flush();\n out.close();\n }\n public static void main(String[] args) throws Exception{\n if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n else new Main().run();\n }\n long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n void p(Object o){out.print(o);}\n void pn(Object o){out.println(o);}\n void pni(Object o){out.println(o);out.flush();}\n String n()throws Exception{return in.next();}\n String nln()throws Exception{return in.nextLine();}\n int ni()throws Exception{return Integer.parseInt(in.next());}\n long nl()throws Exception{return Long.parseLong(in.next());}\n double nd()throws Exception{return Double.parseDouble(in.next());}\n\n class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public FastReader(String s) throws Exception{\n br = new BufferedReader(new FileReader(s));\n }\n\n String next() throws Exception{\n while (st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine());\n }catch (IOException e){\n throw new Exception(e.toString());\n }\n }\n return st.nextToken();\n }\n\n String nextLine() throws Exception{\n String str = \"\";\n try{ \n str = br.readLine();\n }catch (IOException e){\n throw new Exception(e.toString());\n } \n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "49b2de3ecb531cd546ad9a5f3b85478d", "src_uid": "c9d646762e2e78064bc0670ec7c173c6", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\npublic class Main{\n //SOLUTION BEGIN\n //This code is not meant for understanding, you have been warned.\n void pre() throws Exception{}\n void solve(int TC) throws Exception{\n long a = nl(), b = nl(), m = nl();\n long[] contr = new long[51];\n contr[1] = 1;long sum = 1;\n for(int i = 2; i< 51; i++){\n contr[i] = sum;\n sum+=contr[i];\n }\n for(int i = 1; i<= 50; i++){\n if(b/a < contr[i])continue;\n long base = contr[i]*a;\n long diff = b-base-contr[i];\n if(diff<0)continue;\n long[] rem = new long[51];\n for(int j = i-1; j>=1; j--){\n long r = diff/contr[j];\n if(r>=m)r = m-1;\n diff-=contr[j]*r;\n rem[j] = 1+r;\n }\n if(diff==0){ \n p(i+\" \"+a);\n long cur = a; sum = a;\n for(int j = 1; j< i; j++){\n cur = sum+rem[i-j];\n sum+=cur;\n p(\" \"+cur);\n }\n pn(\"\");return;\n }\n }\n pn(-1);\n }\n boolean fill(long[] contr, long[] rem, int ind, long diff, long m){\n if(ind==0)return diff==0;\n long r = diff/contr[ind];\n \n }\n \n //SOLUTION END\n void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n long mod = (long)998244353, IINF = (long)1e18;\n final int INF = (int)1e9, MX = (int)5e5+1;\n DecimalFormat df = new DecimalFormat(\"0.00000000000\");\n double PI = 3.14159265358979338462643383279502884197169399, eps = 1e-8;\n static boolean multipleTC = true, memory = false;\n FastReader in;PrintWriter out;\n void run() throws Exception{\n in = new FastReader();\n out = new PrintWriter(System.out);\n //Solution Credits: Taranpreet Singh\n int T = (multipleTC)?ni():1;\n pre();for(int t = 1; t<= T; t++)solve(t);\n out.flush();\n out.close();\n }\n public static void main(String[] args) throws Exception{\n if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n else new Main().run();\n }\n long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n void p(Object o){out.print(o);}\n void pn(Object o){out.println(o);}\n void pni(Object o){out.println(o);out.flush();}\n String n()throws Exception{return in.next();}\n String nln()throws Exception{return in.nextLine();}\n int ni()throws Exception{return Integer.parseInt(in.next());}\n long nl()throws Exception{return Long.parseLong(in.next());}\n double nd()throws Exception{return Double.parseDouble(in.next());}\n\n class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public FastReader(String s) throws Exception{\n br = new BufferedReader(new FileReader(s));\n }\n\n String next() throws Exception{\n while (st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine());\n }catch (IOException e){\n throw new Exception(e.toString());\n }\n }\n return st.nextToken();\n }\n\n String nextLine() throws Exception{\n String str = \"\";\n try{ \n str = br.readLine();\n }catch (IOException e){\n throw new Exception(e.toString());\n } \n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b2ec529e1a97cb51dd83824c08b85a38", "src_uid": "c9d646762e2e78064bc0670ec7c173c6", "difficulty": 2200.0} {"lang": "Java 8", "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 System.out.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 b)\n break;\n }\n pw.println(-1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aa8733d9b7f21171cb98c8a6fb2243e5", "src_uid": "c9d646762e2e78064bc0670ec7c173c6", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "//package com.company;\n//\n\nimport java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n static int mod = 1000000007;\n public static void main(String[] args) throws IOException {\n MyScanner sc = new MyScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n D.solve(sc, pw);\n pw.close();\n }\n\n public static class A {\n static int n, m;\n static long[] a;\n static long[] b;\n public static void solve(MyScanner sc, PrintWriter pw) throws IOException {\n n = sc.nextInt();\n m = sc.nextInt();\n a = new long[n]; b = new long[m];\n for (int i = 0; i < n; i++) {\n a[i] = sc.nextLong();\n }\n for (int i = 0; i < m; i++) {\n b[i] = sc.nextLong();\n }\n Arrays.sort(a);\n Arrays.sort(b);\n List res = new ArrayList<>();\n if (n == 2){\n if (a[0] * b[0] > a[1] * b[m - 1]) {\n pw.println(Math.max(a[1] * b[0], a[1] * b[m - 1]));\n } else {\n pw.println(Math.max(a[0] * b[0], a[0] * b[m - 1]));\n }\n return;\n }\n res.add(a[n-2] * b[0]);\n res.add(a[n-2] * b[m - 1]);\n res.add(a[1] * b[0]);\n res.add(a[1] * b[m - 1]);\n Collections.sort(res);\n pw.println(res.get(res.size() - 1));\n\n }\n }\n\n\n public static class B {\n static int[] lpp = new int[]{1, 0, 0, 0, 1, 0, 1, 0, 2, 1};\n public static void solve(MyScanner sc, PrintWriter pw) throws IOException {\n int k = sc.nextInt();\n if (k > 36) {\n pw.println(-1); return;\n }\n int n8 = k / 2;\n int n6 = k % 2;\n long res = 0;\n for (int i = 0; i < n8; i++) {\n res *= 10; res += 8;\n }\n for (int i = 0; i < n6; i++) {\n res *= 10; res += 6;\n }\n pw.println(res);\n\n }\n }\n\n public static class C {\n static int n;\n\n static int[] arr;\n static int[][][] dp;\n static int[] cnt1;\n static int[] cnt2;\n public static void solve(MyScanner sc, PrintWriter pw) throws IOException {\n n = sc.nextInt();\n arr = new int[n];\n dp = new int[n][n + 1][2];\n cnt1= new int[n + 1];\n cnt2 = new int[n + 1];\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextInt();\n }\n for (int i = n - 1; i >= 0; i--) {\n for (int j = i; j >= 0; j--) {\n if (arr[j] == 1){\n dp[i][j][0] = dp[i][j + 1][0] + 1;\n dp[i][j][1] = dp[i][j + 1][1];\n } else {\n dp[i][j][0] = dp[i][j + 1][0];\n dp[i][j][1] = Math.max(dp[i][j + 1][1] + 1, dp[i][j + 1][0] + 1);\n }\n }\n }\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n if (arr[i] == 1) {\n cnt++; cnt1[i + 1] = cnt;\n }\n }\n cnt = 0;\n for (int i = n - 1; i >=0; i--) {\n if (arr[i] == 2) {\n cnt++;\n cnt2[i] = cnt;\n }\n }\n cnt = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i; j < n; j++) {\n cnt = Math.max(cnt, cnt1[i] + Math.max(dp[j][i][1], dp[j][i][0]) + cnt2[j + 1]);\n }\n }\n pw.println(cnt);\n }\n }\n\n public static class D {\n static long p; static int k;\n public static void solve(MyScanner sc, PrintWriter pw) throws IOException {\n p = sc.nextLong();\n k = sc.nextInt();\n List coef = new ArrayList<>();\n long mv = p;\n while (true) {\n long b0 = -mv / k;\n if (b0 * k + mv < 0){\n b0++;\n }\n coef.add(k * b0 + mv);\n if (0 <= b0 && b0 <= k) {\n coef.add(b0); break;\n }\n if (coef.size() >= 1e6){\n pw.println(-1); return;\n }\n mv = b0;\n }\n pw.println(coef.size());\n for (int i = 0; i < coef.size(); i++) {\n pw.print(coef.get(i) + \" \");\n }\n pw.println();\n }\n\n\n }\n\n public static class E {\n static int n;\n static int[] x;\n static int[] y;\n static int[] r;\n public static double dist(int x1, int y1, double x2, double y2) {\n return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));\n }\n\n public static void solve(MyScanner sc, PrintWriter pw) throws IOException {\n n = sc.nextInt();\n Random rnd = new Random();\n x = new int[n]; y = new int[n]; r = new int[n];\n for (int i = 0; i < n; i++) {\n x[i] = sc.nextInt();\n y[i] = sc.nextInt();\n r[i] = sc.nextInt();\n }\n int[] used = new int[100];\n for (int t = 0; t < n; t++) {\n for (int i = (x[t] - r[t]) * 100; i <= (x[t] + r[t]) * 100; i++) {\n for (int j = (y[t] - r[t]) * 100; j <= (y[t] + r[t]) * 100; j++) {\n int code = 0;\n double x2 = (i + 0.0) / 100;\n double y2 = (j + 0.0) / 100;\n// x2 += rnd.nextDouble() / 10;\n// y2 += rnd.nextDouble() / 10;\n for (int k = 0; k < n; k++) {\n double dis = dist(x[k], y[k], x2, y2);\n if (dis + 1e-8 < r[k]) {\n code += 1 << k;\n }\n }\n used[code] = 1;\n }\n }\n }\n\n int cnt = 0;\n for (int i = 0; i < 100; i++) {\n if (used[i] != 0) {\n cnt ++;\n }\n }\n pw.println(cnt);\n// double arr[] = new double[21*21*21*21]; int idx = 0;\n// for (int i = -10; i <= 10; i++) {\n// for (int j = -10; j <= 10; j++) {\n// for (int k = -10; k <= 10; k++) {\n// for (int l = -10; l <= 10; l++) {\n// double dit = dist(i, j, k, l);\n// if (dit < 1e-8) continue;\n// arr[idx++] = dit - (int) dit;\n// }\n// }\n// }\n// }\n// Arrays.sort(arr);\n// idx = 0;\n// while (arr[idx] < 1e-8){\n// idx++;\n// }\n// for (int i = idx; i < idx + 5; i++) {\n// pw.println(arr[i]);\n// }\n }\n }\n\n\n static class MyScanner {\n StringTokenizer st;\n BufferedReader br;\n\n public MyScanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}\n\n public MyScanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}\n\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n public long nextLong() throws IOException {return Long.parseLong(next());}\n\n public String nextLine() throws IOException {return br.readLine();}\n\n public double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n public boolean ready() throws IOException {return br.ready();}\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3aa59ab45f09fefb4defe3cf45526270", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 DeterminedCleanup solver = new DeterminedCleanup();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DeterminedCleanup {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long p = in.nextLong();\n long k = in.nextInt();\n int mx = 62;\n long[] coe = new long[mx];\n int d = (int) MathUtils.log(p, k) + 1;\n coe[0] = p % k;\n BigInteger[] pref = new BigInteger[mx];\n BigInteger kbig = new BigInteger(Long.toString(k));\n BigInteger pbig = new BigInteger(Long.toString(p));\n pref[0] = new BigInteger(Long.toString(coe[0]));\n for (int i = 1; i <= mx; i++) {\n if (kbig.pow(i).compareTo(pbig) <= 0) {\n coe[i] = ((pbig.mod(kbig.pow(i + 1)).subtract(pref[i - 1])).divide(kbig.pow(i))).longValue();\n pref[i] = kbig.pow(i).multiply(new BigInteger(Long.toString(coe[i]))).add(pref[i - 1]);\n } else {\n d = i - 1;\n break;\n }\n }\n for (int i = 1; i <= d; i += 2) {\n if (coe[i] > 0) {\n coe[i] = -(k - coe[i]);\n coe[i + 1]++;\n }\n }\n for (int i = 0; i <= d + 1; i++) {\n if (coe[i] == k) {\n coe[i] = 0;\n coe[i + 1]++;\n }\n }\n for (int i = mx - 1; i >= 0; i--) {\n if (coe[i] != 0) {\n d = i;\n break;\n }\n }\n out.println(d + 1);\n for (int i = 0; i <= d; i++) {\n out.println(Math.abs(coe[i]));\n }\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n\n static class MathUtils {\n public static double log(double val, double base) {\n return Math.log(val) / Math.log(base);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2284588ed9f5f5227edcba1fa619ca88", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class D {\n private static class BufferedScanner {\n BufferedReader mReader;\n StringTokenizer mTokenizer;\n\n BufferedScanner(InputStream inputStream) {\n mReader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n String next() {\n while (mTokenizer == null || !mTokenizer.hasMoreElements()) {\n String line = readLine();\n if (line != null) {\n mTokenizer = new StringTokenizer(line);\n } else {\n break;\n }\n }\n return mTokenizer != null ? mTokenizer.nextToken() : null;\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 return readLine();\n }\n\n private String readLine() {\n try {\n return mReader.readLine();\n } catch (IOException ignore) {\n return null;\n }\n }\n }\n\n public static void main(String[] args) throws IOException {\n new D().solve();\n }\n\n private BufferedScanner mReader;\n private PrintStream mWriter;\n\n private D() throws IOException {\n InputStream actualInputStream;\n if (System.getProperty(\"ONLINE_JUDGE\") != null) {\n actualInputStream = System.in;\n } else {\n File inputFile = new File(\"in.txt\");\n if (!inputFile.exists()) {\n //noinspection ResultOfMethodCallIgnored\n inputFile.createNewFile();\n throw new FileNotFoundException(\"File wasn't found, but now is created\");\n }\n actualInputStream = new FileInputStream(inputFile);\n }\n mReader = new BufferedScanner(new BufferedInputStream(actualInputStream));\n mWriter = System.out;\n }\n\n private void solve() throws IOException {\n long p = mReader.nextInt();\n long k = mReader.nextInt();\n//\n List coefs = new ArrayList<>();\n\n long f = p % k;\n long q = p / (-k);\n\n coefs.add(f);\n\n while (q != 0) {\n f = (q % k + k) % k;\n q -= (q % k + k) % k;\n q /= -k;\n\n coefs.add(f);\n }\n\n System.out.println(coefs.size());\n for (Long coef : coefs) {\n System.out.println(coef);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "957d3393d3f237cedbb0ad095b47ac14", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.stream.Collectors;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\n Scanner scanner=new Scanner(System.in);\n\n long p=scanner.nextInt();\n int k=scanner.nextInt();\n\n ArrayList list=new ArrayList<>();\n for (int i=0;p>0;i++) {\n list.add((i%2==0?1:-1)*(p%k));\n p/=k;\n }\n\n for (int i=0;i=k) {\n list.set(i, list.get(i)-k);\n if (i==list.size()-1) list.add(-1L);\n else list.set(i+1, list.get(i+1)-1);\n }\n }\n System.out.println(list.size());\n System.out.println(String.join(\" \", list.stream().map(String::valueOf).collect(Collectors.toList())));\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "563241872110b5907a5906eb484a8502", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\n\r\npublic class Main {\r\n public static void main(String args[]) {\r\n Scanner in = new Scanner(System.in);\r\n int row = in.nextInt();\r\n int col = in.nextInt();\r\n in.nextLine();\r\n char[][] foods = new char[row][col];\r\n for (int i = 0; i < row; i++) {\r\n String line = in.nextLine();\r\n // System.out.println(line);\r\n for (int j = 0; j < col; j++) {\r\n foods[i][j] = line.charAt(j);\r\n }\r\n }\r\n\r\n int i = 0;\r\n int j = 0;\r\n int res = 0;\r\n while (true) {\r\n if (foods[i][j] == '*') {\r\n res++;\r\n // System.out.println(\"i \" + i + \", j \" + j);\r\n\r\n }\r\n if (i == row - 1 && j == col - 1) {\r\n System.out.println(res);\r\n return;\r\n }\r\n if (j == col - 1 || foods[i + 1][j] == '*') {\r\n i++;\r\n continue;\r\n }\r\n j++;\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0d4df48fe8368fe671925d4a972aa896", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\npublic class codeforcesE1{\r\n\tstatic class FastReader{\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\t\tpublic FastReader(){\r\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\r\n\t\t}\r\n\t\tString next(){\r\n\t\t\twhile(st==null || !st.hasMoreElements())\r\n\t\t\t{\r\n\t\t\t\ttry{\r\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\r\n\t\t\t\t}\r\n\t\t\t\tcatch(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\t\tint nextInt(){\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\t\tlong nextLong(){\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\t\tDouble nextDouble(){\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\t\tfloat nextFloat(){\r\n\t\t\treturn Float.parseFloat(next());\r\n\t\t}\r\n\t}\r\n\tpublic static void main(String args[]){\r\n\t\tFastReader fs=new FastReader();\r\n\t\tint i=0,j=0;\r\n\t\tint h=fs.nextInt();\r\n\t\tint w=fs.nextInt();\r\n\t\tchar[][] mat=new char[h][w];\r\n\t\tfor(i=0;i= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int ri() {\n return readInt();\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n public char rc() {\n return readChar();\n }\n\n public char readChar() {\n skipBlank();\n char c = (char) next;\n next = read();\n return c;\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private static final int THRESHOLD = 32 << 10;\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 println(int c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n return append('\\n');\n }\n\n public FastOutput flush() {\n try {\n// boolean success = false;\n// if (stringBuilderValueField != null) {\n// try {\n// char[] value = (char[]) stringBuilderValueField.get(cache);\n// os.write(value, 0, cache.length());\n// success = true;\n// } catch (Exception e) {\n// }\n// }\n// if (!success) {\n os.append(cache);\n// }\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0d6bf2086f698b27098c65f050decd7f", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.LinkedList;\r\nimport java.util.Scanner;\r\n\r\npublic class IsItRated2 {\r\n\r\n public static void main (String [] args){\r\n Scanner entrada = new Scanner(System.in);\r\n\r\n int alto = entrada.nextInt();\r\n int ancho = entrada.nextInt();\r\n entrada.nextLine();\r\n\r\n boolean [][] matrix = new boolean [alto][ancho];\r\n\r\n for (int i = 0; i < alto; i++){\r\n char [] read = entrada.nextLine().strip().toCharArray();\r\n for (int j = 0; j < ancho; j++){\r\n matrix[i][j] = read[j] == '*';\r\n }\r\n }\r\n\r\n int berries = 0;\r\n\r\n if (matrix[0][0]) berries++;\r\n\r\n int mouseX = 0, mouseY = 0;\r\n\r\n int [] goal = findNearest(matrix, mouseX, mouseY);\r\n\r\n while (true){\r\n if (mouseX == goal[0] && mouseY == goal[1]){\r\n berries++;\r\n goal = findNearest(matrix, mouseX, mouseY);\r\n } else if (mouseY < goal[1]){\r\n mouseY++;\r\n } else if (mouseX < goal[0]){\r\n mouseX++;\r\n } else {\r\n System.out.println(berries);\r\n return;\r\n }\r\n }\r\n\r\n\r\n\r\n }\r\n\r\n public static int [] findNearest (boolean [][] matrix, int x, int y){\r\n LinkedList queue = new LinkedList<>();\r\n Integer [] position = {x, y+1};\r\n queue.add(position);\r\n Integer [] position2 = {x+1, y};\r\n queue.add(position2);\r\n while (!queue.isEmpty()){\r\n Integer [] pointer = queue.pop();\r\n int pointX = pointer[0];\r\n int pointY = pointer[1];\r\n if (pointX >= matrix.length || pointY >= matrix[0].length) continue;\r\n if (matrix[pointX][pointY]) {\r\n return new int [] {pointX, pointY};\r\n }\r\n queue.add(new Integer [] {pointX, pointY+1});\r\n queue.add(new Integer [] {pointX+1, pointY});\r\n }\r\n int [] nulo = {-1, -1};\r\n return nulo;\r\n\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ee2521759bf14c9d82dddffc5f1ffeb6", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\npublic class D2 {\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 public static FastReader scn = new FastReader();\n\n // type 0 knight 1 bishop 2 rook\n private static class node implements Comparable{\n int x;\n int y;\n int val;\n int steps;\n int rep;\n int type;\n\n public node(int x,int y,int val, int st,int rep, int typ){\n this.x = x;\n this.y = y;\n this.rep = rep;\n this.val = val;\n this.steps = st;\n this.type = typ;\n }\n\n @Override\n public int compareTo(node other){\n if(this.steps == other.steps) return this.rep - other.rep;\n return this.steps - other.steps;\n }\n }\n\n public static void main(String[] args) {\n int n = scn.nextInt();\n int[][] pos = new int[n*n +1][2] ;\n for(int i = 0; i Queue = new PriorityQueue<>();\n Queue.add(new node(pos[1][0],pos[1][1],1,0,0,0));\n Queue.add(new node(pos[1][0],pos[1][1],1,0,0,1));\n Queue.add(new node(pos[1][0],pos[1][1],1,0,0,2));\n\n int[][][] move = new int[3][][];\n move[0] = new int[][]{{-2,-1},{-1,-2},{2,-1},{1,-2},{-2,1},{-1,2},{2,1},{1,2}};\n move[1] = new int[][]{{-1,-1},{-1,1},{1,-1},{1,1}};\n move[2] = new int[][]{{-1,0},{1,0},{0,-1},{0,1}};\n\n boolean[][][][] visited = new boolean[n][n][n*n +1][3]; // x,y,value,type\n\n while(!Queue.isEmpty()){\n node s = Queue.poll();\n if(s.x<0 || s.y<0 || s.x >=n || s.y >=n) continue;\n if(visited[s.x][s.y][s.val][s.type]) continue;\n visited[s.x][s.y][s.val][s.type] = true;\n if(pos[s.val+1][0] == s.x && pos[s.val+1][1] == s.y){\n s.val++;\n if(s.val == n*n){\n System.out.println(s.steps + \" \" + s.rep);\n break;\n }\n visited[s.x][s.y][s.val][s.type] = true;\n }\n\n for(int i = 0; i< 3; i++) Queue.add(new node(s.x,s.y,s.val,s.steps+1,s.rep+1,i));\n\n for(int[] m : move[s.type]){\n if(s.type == 0){\n for(int j = 0; j q = new ArrayDeque();\n for(int p=0; p < 3; p++)\n {\n q.add(start);\n q.add(p);\n q.add(1);\n }\n while(q.size() > 0)\n {\n int tempo = q.poll();\n int piece = q.poll();\n int target = q.poll();\n int x = tempo/N;\n int y = tempo%N;\n //swap\n for(int p=0; p < 3; p++)\n {\n if(piece == p)\n continue;\n if(replace[tempo][p][target] > replace[tempo][piece][target]+1 && dist[tempo][p][target] == dist[tempo][piece][target]+1)\n {\n replace[tempo][p][target] = replace[tempo][piece][target]+1;\n q.add(tempo);\n q.add(p);\n q.add(target);\n }\n else if(dist[tempo][p][target] > dist[tempo][piece][target]+1)\n {\n replace[tempo][p][target] = replace[tempo][piece][target]+1;\n dist[tempo][p][target] = dist[tempo][piece][target]+1;\n q.add(tempo);\n q.add(p);\n q.add(target);\n }\n }\n //move\n if(piece == 0)\n {\n for(int dx=-2; dx <= 2; dx++)\n for(int dy=-2; dy <= 2; dy++)\n {\n if(dx == 0 || dy == 0 || Math.abs(dx) == Math.abs(dy))\n continue;\n int r = x+dx;\n int c = y+dy;\n if(Math.min(r,c) < 0 || Math.max(r,c) >= N)\n continue;\n int id = target+(grid[r][c]-1 == target ? 1 : 0);\n if(dist[r*N+c][piece][id] > dist[tempo][piece][target]+1)\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n dist[r*N+c][piece][id] = dist[tempo][piece][target]+1;\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n else if(dist[r*N+c][piece][id] == dist[tempo][piece][target]+1 && replace[r*N+c][piece][id] > replace[tempo][piece][target])\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n }\n }\n else if(piece == 1)\n {\n for(int a=1; a < N; a++)\n for(int dx=-1; dx <= 1; dx+=2)\n for(int dy=-1; dy <= 1; dy+=2)\n {\n int r = x+dx*a;\n int c = y+dy*a;\n if(Math.min(r,c) < 0 || Math.max(r,c) >= N)\n continue;\n int id = target+(grid[r][c]-1 == target ? 1 : 0);\n if(dist[r*N+c][piece][id] > dist[tempo][piece][target]+1)\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n dist[r*N+c][piece][id] = dist[tempo][piece][target]+1;\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n else if(dist[r*N+c][piece][id] == dist[tempo][piece][target]+1 && replace[r*N+c][piece][id] > replace[tempo][piece][target])\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n }\n }\n else\n {\n for(int a=1; a < N; a++)\n for(int dx=-1; dx <= 1; dx+=2)\n {\n int r = x+dx*a;\n int c = y;\n if(Math.min(r,c) < 0 || Math.max(r,c) >= N)\n continue;\n int id = target+(grid[r][c]-1 == target ? 1 : 0);\n if(dist[r*N+c][piece][id] > dist[tempo][piece][target]+1)\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n dist[r*N+c][piece][id] = dist[tempo][piece][target]+1;\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n else if(dist[r*N+c][piece][id] == dist[tempo][piece][target]+1 && replace[r*N+c][piece][id] > replace[tempo][piece][target])\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n }\n for(int a=1; a < N; a++)\n for(int dy=-1; dy <= 1; dy+=2)\n {\n int r = x;\n int c = y+dy*a;\n if(Math.min(r,c) < 0 || Math.max(r,c) >= N)\n continue;\n int id = target+(grid[r][c]-1 == target ? 1 : 0);\n if(dist[r*N+c][piece][id] > dist[tempo][piece][target]+1)\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n dist[r*N+c][piece][id] = dist[tempo][piece][target]+1;\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n else if(dist[r*N+c][piece][id] == dist[tempo][piece][target]+1 && replace[r*N+c][piece][id] > replace[tempo][piece][target])\n {\n replace[r*N+c][piece][id] = replace[tempo][piece][target];\n q.add(r*N+c);\n q.add(piece);\n q.add(id);\n }\n }\n }\n }\n int minDist = 420420420;\n int minRep = 420420420;\n int lmao = N*N;\n for(int p=0; p < 3; p++)\n {\n if(minDist > dist[loc[lmao]][p][lmao])\n {\n minDist = dist[loc[lmao]][p][lmao];\n minRep = replace[loc[lmao]][p][lmao];\n }\n else if(minDist == dist[loc[lmao]][p][lmao] && minRep > replace[loc[lmao]][p][lmao])\n minRep = replace[loc[lmao]][p][lmao];\n }\n System.out.println(minDist+\" \"+minRep);\n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "801004ba9692a4c5b86241b0a370d52f", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\npublic class D2 {\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 public static FastReader scn = new FastReader();\n\n // type 0 knight 1 bishop 2 rook\n private static class node implements Comparable{\n int x;\n int y;\n int val;\n int steps;\n int rep;\n int type;\n\n public node(int x,int y,int val, int st,int rep, int typ){\n this.x = x;\n this.y = y;\n this.rep = rep;\n this.val = val;\n this.steps = st;\n this.type = typ;\n }\n\n @Override\n public int compareTo(node other){\n if(this.steps == other.steps) return this.rep - other.rep;\n return this.steps - other.steps;\n }\n }\n\n public static void main(String[] args) {\n int n = scn.nextInt();\n int[][] pos = new int[n*n +1][2] ;\n for(int i = 0; i Queue = new PriorityQueue<>();\n Queue.add(new node(pos[1][0],pos[1][1],1,0,0,0));\n Queue.add(new node(pos[1][0],pos[1][1],1,0,0,1));\n Queue.add(new node(pos[1][0],pos[1][1],1,0,0,2));\n\n int[][][] move = new int[3][][];\n move[0] = new int[][]{{-2,-1},{-1,-2},{2,-1},{1,-2},{-2,1},{-1,2},{2,1},{1,2}};\n move[1] = new int[][]{{-1,-1},{-1,1},{1,-1},{1,1}};\n move[2] = new int[][]{{-1,0},{1,0},{0,-1},{0,1}};\n\n boolean[][][][] visited = new boolean[n][n][n*n +1][3]; // x,y,value,type\n\n while(!Queue.isEmpty()){\n node s = Queue.poll();\n if(s.x<0 || s.y<0 || s.x >=n || s.y >=n) continue;\n if(visited[s.x][s.y][s.val][s.type]) continue;\n visited[s.x][s.y][s.val][s.type] = true;\n if(pos[s.val+1][0] == s.x && pos[s.val+1][1] == s.y){\n s.val++;\n if(s.val == n*n){\n System.out.println(s.steps + \" \" + s.rep);\n break;\n }\n visited[s.x][s.y][s.val][s.type] = true;\n }\n\n for(int i = 0; i< 3; i++) Queue.add(new node(s.x,s.y,s.val,s.steps+1,s.rep+1,i));\n\n for(int[] m : move[s.type]){\n if(s.type == 0){\n Queue.add(new node(s.x + m[0], s.y + m[1], s.val , s.steps+1, s.rep , s.type));\n }else{\n for(int j = 1; j<=n; j++) Queue.add(new node(s.x + j*m[0], s.y + j*m[1], s.val , s.steps+1, s.rep , s.type));\n }\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fec8f5030cf705a7521761751738dc89", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.IOException; \nimport java.io.InputStream; \nimport java.io.PrintWriter; \nimport java.util.*; \n \n\npublic class d{\n\n\tstatic class Pos{\n\t\tint i,j;\n\t\tPos(int i, int j){this.i=i;this.j=j;}\n\t}\n\tstatic class Node{\n\t\tint i,j,k,l,c;\n\t\tNode(int i,int j,int k,int l,int c){this.i=i;this.j=j;this.k=k;this.l=l;this.c=c;}\n\t}\n\n\tstatic void solve(){\n\t\tint n = ni();\n\t\tint[][][][] dis = new int[n][n][3][n*n+1];\n\t\tPos[] pos =new Pos[n*n];\n\t\tfor(int i=0;i que = new PriorityQueue<>((a,b)->a.c-b.c);\n\t\tfor(int k=0;k<3;++k){\n\t\t\tdis[pos[0].i][pos[0].j][k][1]=0;\n\t\t\tque.add(new Node(pos[0].i, pos[0].j, k, 1, 0));\n\t\t}\n\t\tList movex[] = new List[3];\n\t\tList movey[] = new List[3];\n\t\tmovex[0] = Arrays.asList(-2,-2,-1,-1,1,1,2,2);\n\t\tmovey[0] = Arrays.asList(1,-1,2,-2,2,-2,1,-1);\n\t\tfor(int i=1;i<3;++i){\n\t\t\tmovex[i]=new ArrayList<>();\n\t\t\tmovey[i]=new ArrayList<>();\n\t\t}\n\t\tfor(int i=1;i<=n;++i){\n\t\t\tmovex[1].add(i);movex[1].add(-i);\n\t\t\tmovey[1].add(0);movey[1].add(0);\n\t\t\tmovex[1].add(0);movex[1].add(0);\n\t\t\tmovey[1].add(i);movey[1].add(-i);\n\n\t\t\tmovex[2].add(i);movex[2].add(-i);\n\t\t\tmovey[2].add(i);movey[2].add(-i);\n\t\t\tmovex[2].add(i);movex[2].add(-i);\n\t\t\tmovey[2].add(-i);movey[2].add(i);\n\t\t}\n\t\twhile(!que.isEmpty()){\n\t\t\tNode node = que.poll();\n\t\t\tif(node.c > dis[node.i][node.j][node.k][node.l])continue;\n\t\t\tint i=node.i, j=node.j, k=node.k, l=node.l;\n\t\t\tif(l==n*n){\n\t\t\t\tout.println(node.c/1000+\" \"+node.c%1000);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(int kk=0;kk<3;++kk){\n\t\t\t\tif(kk==k)continue;\n\t\t\t\tif(dis[i][j][kk][l] > dis[i][j][k][l]+1001){\n\t\t\t\t\tdis[i][j][kk][l]=dis[i][j][k][l]+1001;\n\t\t\t\t\tque.add(new Node(i, j, kk, l, dis[i][j][kk][l]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int x=0;xdis[i][j][k][l]+1000){\n\t\t\t\t\t\tdis[i+dy][j+dx][k][ll]=dis[i][j][k][l]+1000;\n\t\t\t\t\t\tque.add(new Node(i+dy, j+dx, k, ll, dis[i+dy][j+dx][k][ll]));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\n\n\t} \n \n \n \n \n\t public static void main(String[] args){ \n\t\t solve(); \n\t\t out.flush(); \n\t } \n\t private static InputStream in = System.in; \n\t private static PrintWriter out = new PrintWriter(System.out); \n \n\t static boolean inrange(int y, int x, int h, int w){ \n\t\t return y>=0 && y=0 && x int lower_bound(List list, T key){ \n\t\t int lower=-1;int upper=list.size(); \n\t\t while(upper - lower>1){ \n\t\t int center =(upper+lower)/2; \n\t\t if(list.get(center).compareTo(key)>=0)upper=center; \n\t\t else lower=center; \n\t\t } \n\t\t return upper; \n\t } \n\t @SuppressWarnings(\"unchecked\") \n\t static int upper_bound(List list, T key){ \n\t\t int lower=-1;int upper=list.size(); \n\t\t while(upper-lower >1){ \n\t\t int center=(upper+lower)/2; \n\t\t if(list.get(center).compareTo(key)>0)upper=center; \n\t\t else lower=center; \n\t\t } \n\t\t return upper; \n\t } \n\t @SuppressWarnings(\"unchecked\") \n\t static boolean next_permutation(List list){ \n\t\t int lastIndex = list.size()-2; \n\t\t while(lastIndex>=0 && list.get(lastIndex).compareTo(list.get(lastIndex+1))>=0)--lastIndex; \n\t\t if(lastIndex<0)return false; \n\t\t int swapIndex = list.size()-1; \n\t\t while(list.get(lastIndex).compareTo(list.get(swapIndex))>=0)swapIndex--; \n\t\t T tmp = list.get(lastIndex); \n\t\t list.set(lastIndex++, list.get(swapIndex)); \n\t\t list.set(swapIndex, tmp); \n\t\t swapIndex = list.size()-1; \n\t\t while(lastIndex0; \n\t } \n\t private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} \n\t private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} \n\t private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} \n \n\t private static double nd(){ return Double.parseDouble(ns()); } \n\t private static char nc(){ return (char)skip(); } \n\t private static String ns(){ \n\t\t StringBuilder sb = new StringBuilder(); \n\t\t for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); \n\t\t return sb.toString(); \n\t } \n\t private static int[] nia(int n){ \n\t\t int[] res = new int[n]; \n\t\t for(int i=0;i='0'&&b<='9') || b=='-')); \n\t\t if(b=='-'){ \n\t\t\t minus=true; \n\t\t\t b=readByte(); \n\t\t } \n\t\t for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); \n\t\t return minus ? -res:res; \n\t } \n\t private static long nl(){ \n\t\t long res=0,b; \n\t\t boolean minus=false; \n\t\t while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); \n\t\t if(b=='-'){ \n\t\t\t minus=true; \n\t\t\t b=readByte(); \n\t\t } \n\t\t for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); \n\t\t return minus ? -res:res; \n\t} \n} \n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8d99b6965e2a11da6d6d9efc8766c558", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class Program\n{\n\tpublic static void main(String[] args)\n\t{ \n\t\tScanner s = new Scanner(System.in);\n\t\tint a,b,c,t = 1, t0;\n\t\tboolean espera = true;\n\t\t//Console.WriteLine(\"Digite o tamanho dos dados/s do video : \");\n\t\ta = s.nextInt();;\n\t\t//Console.WriteLine(\"Digite a capacidade de dowload de dados/s : \");\n\t\tb = s.nextInt();;\n\t\t//Console.WriteLine(\"Digite o tamanho do video em segundos : \");\n\t\tc = s.nextInt();;\n\t\t//System.out.println(a + \" \" + b + \" \" + c);\n\t\tif (b == 1)\n {\n Console.WriteLine((a * c) - c);\n }\n\t\telse\n\t\t{\n\t\t\twhile ( a * c > t* b ) //while (a * c > t * b)\n\t\t\t\t{\n\t\t\t\t\t//Console.WriteLine(\"tempo:\" + t);\n\n\t\t\t\t\tfor (t0 = 1; t0 <= t+c ; t0++)\n\t\t\t\t\t{\n\t\t\t\t\t \n\t\t\t\t\t\tif ((t0)*b >= (a * c)-(t*b) && t0+t<=t+c && espera)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSystem.out.println(t);\n\t\t\t\t\t\t \n\t\t\t\t\t\t\tt0 = t + 1;\n\t\t\t\t\t\t\tespera = 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\tt++;\n\t\t\t\t\t\n\n\t\t\t\t}\n\t\t\t}\n\n\t\n\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e2fd5f48b20eb0b3884a66adaeb592d0", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Program\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tint a,b,c,t = 0, t0 = 0;\n\t\t//Console.WriteLine(\"Digite o tamanho dos dados/s do video : \");\n\t\ta = System.in.read();\n\t\t//Console.WriteLine(\"Digite a capacidade de dowload de dados/s : \");\n\t\tb = System.in.read();\n\t\t//Console.WriteLine(\"Digite o tamanho do video em segundos : \");\n\t\tc = System.in.read();\n\t\t//System.out.println(a + \" \" + b + \" \" + c);\n\n\t\twhile (a * c > t * b) //for (t = 0; ; t++)\n\t\t{\n\t\t\t if ((a * c) - (t * b) < (t * b) && ((t * b) / b) + (t * b) >= a * c)\n\t\t\t {\n\t\t\t\t\t\tt0 = t;\n\t\t\t\t\t\tt = c * a;\n\t\t\t }\n\t\t\tt++;\n\t\t}\n\t\tSystem.out.println(\"\" + t0);\n\n\t\n\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3f302dac0efd84d703a4a1f2888d01dd", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Program\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tint a,b,c,t = 0, t0 = 0;\n\t\t//Console.WriteLine(\"Digite o tamanho dos dados/s do video : \");\n\t\ta = System.in.read();\n\t\t//Console.WriteLine(\"Digite a capacidade de dowload de dados/s : \");\n\t\tb = System.in.read();\n\t\t//Console.WriteLine(\"Digite o tamanho do video em segundos : \");\n\t\tc = System.in.read();\n\t\tSystem.out.println(a + \" \" + b + \" \" + c);\n\n\t\twhile (a * c > t * b) //for (t = 0; ; t++)\n\t\t{\n\t\t\t if ((a * c) - (t * b) < (t * b) && ((t * b) / b) + (t * b) >= a * c)\n\t\t\t {\n\t\t\t\t\t\tt0 = t;\n\t\t\t\t\t\tt = c * a;\n\t\t\t }\n\t\t\tt++;\n\t\t}\n\t\tSystem.out.println(\"\" + t0);\n\n\t\n\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aeb87fb5c04e711b2f51dccb261fc059", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class Program\n{\n\tpublic static void main(String[] args)\n\t{ \n\t\tScanner s = new Scanner(System.in);\n\t\tint a,b,c,t = 1, t0;\n\t\tboolean espera = true;\n\t\t//Console.WriteLine(\"Digite o tamanho dos dados/s do video : \");\n\t\ta = s.nextInt();;\n\t\t//Console.WriteLine(\"Digite a capacidade de dowload de dados/s : \");\n\t\tb = s.nextInt();;\n\t\t//Console.WriteLine(\"Digite o tamanho do video em segundos : \");\n\t\tc = s.nextInt();;\n\t\t//System.out.println(a + \" \" + b + \" \" + c);\n\t\tfor (t = 1; a * c > t * b; t++) //while (a * c > t * b)\n {\n //Console.WriteLine(\"tempo:\" + t);\n //Console.WriteLine(\"valor de t: \" + t + \" T \" + t * b);\n espera = true;\n for (t0 = t; t0 <= t + c; t0++)\n {\n //Console.WriteLine(\"valor de t0: \"+t0+\" TO \"+t0*b);\n if (t0 * b < (t0 - t) * a )\n espera = false; \n }\n if (espera)\n {\n Console.WriteLine(t);\n break;\n }\n\n }\n\n\t\n\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f569b7a2afafb0549d0a56d1cdfa0aed", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 9/13/11\n * Time: 5:34 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class TaskE extends Thread {\n public TaskE() {\n this.input = new BufferedReader(new InputStreamReader(System.in));\n this.output = new PrintWriter(System.out);\n this.setPriority(Thread.MAX_PRIORITY);\n }\n\n\n static final long doit(int mask, int dead, int n) {\n if ((mask & dead) == 0) {\n cache[mask][dead] = 0;\n return 0;\n }\n if (cache[mask][dead] != -1) {\n return cache[mask][dead];\n }\n long result = 0;\n for (int a = 0; a < n; ++a) {\n if (((mask & (1 << a)) != 0) && ((dead & (1 << a)) != 0)) {\n for (int b = 0; b < n; ++b) {\n if (g[a][b] && (mask & (1 << b)) != 0) {\n if (mask == ((1 << a) | (1 << b))) {\n cache[mask][dead] = ((dead & mask) == mask) ? 1 : 0;\n return cache[mask][dead];\n }\n if ((dead & (1 << b)) == 0) {\n result += doit(mask ^ (1 << a), dead, n) + doit(mask ^ (1 << a), dead ^ (1 << b), n);\n }\n }\n }\n break;\n }\n }\n cache[mask][dead] = result;\n return result;\n }\n\n private void solve() throws Throwable {\n int n = nextInt(), m = nextInt(), k = nextInt();\n g = new boolean[n][n];\n cache = new long[1 << n][1 << n];\n for (long[] current : cache) {\n Arrays.fill(current, -1);\n }\n Arrays.fill(cache[0], 1);\n for (int i = 0; i < m; ++i) {\n int a = nextInt() - 1, b = nextInt() - 1;\n g[a][b] = g[b][a] = true;\n }\n long ans = 0;\n for (int dead = 0; dead < (1 << n); ++dead) {\n if (Integer.bitCount(dead) == k) {\n ans += doit((1 << n) - 1, dead, n);\n }\n }\n output.println(ans);\n\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 public static void main(String[] args) {\n new TaskE().start();\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 (tokens == null || !tokens.hasMoreTokens()) {\n tokens = new StringTokenizer(input.readLine());\n }\n return tokens.nextToken();\n }\n\n static long[][] cache;\n static boolean[][] g;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "18f1f2dc73acb4448acbd20ce33c9b42", "src_uid": "8087605a8f316150372cc4627f26231d", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class E {\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\tint k = sc.nextInt();\n\t\tint[][]a = new int[n][n];\n\t\tint[][]dp = new int[1 << n][1 << n];\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\tint v1 = sc.nextInt();\n\t\t\tint v2 = sc.nextInt();\n\t\t\tv1--;\n\t\t\tv2--;\n\t\t\ta[v1][v2] = a[v2][v1] = 1;\n\t\t\tdp[(1 << v1) | (1 << v2)][(1 << v1) | (1 << v2)] = 1;\n\t\t}\n\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\tfor (int subm = mask; subm != 0; subm = ((subm-1) & mask)) {\n\t\t\t\tif (dp[mask][subm]==0)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif ((mask & (1 << i)) != 0) {\n\t\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\t\tif ((mask & (1 << j))==0 && a[i][j]==1) {\n\t\t\t\t\t\t\t\tint new_subm = (subm | (1 << j));\n\t\t\t\t\t\t\t\tif ((subm & (1 << i)) != 0)\n\t\t\t\t\t\t\t\t\tnew_subm ^= (1 << i);\n\t\t\t\t\t\t\t\tint q = (1 << n)-(1 << (j+1));\n\t\t\t\t\t\t\t\tif ((new_subm & q) != 0)\n\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tdp[mask | (1 << j)][new_subm] += dp[mask][subm];\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\tint ans = 0;\n\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\tif (Integer.bitCount(mask)==k)\n\t\t\t\tans += dp[(1 << n)-1][mask];\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "185e642361ab681df2205df5ef9a233d", "src_uid": "8087605a8f316150372cc4627f26231d", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class E {\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tn = s.nextInt();\n\t\tm = s.nextInt();\n\t\tk = s.nextInt();\n\t\ta = new int[m][];\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint u = s.nextInt() - 1, v = s.nextInt() - 1;\n\t\t\ta[i] = new int[] { u, v };\n\t\t}\n\t\tb = new boolean[m];\n\t\tSystem.out.println(f(-1, m));\n\t}\n\n\tstatic int n, m, k;\n\tstatic int[][] a;\n\tstatic boolean[] b;\n\n\tstatic int f(int x, int en) {\n\t\tif (en == n - 1) {\n\t\t\tint[] cs = new int[n];\n\t\t\tUnionFind uf = new UnionFind(n);\n\t\t\tfor (int i = 0; i < m; ++i) {\n\t\t\t\tif (!b[i]) {\n\t\t\t\t\t++cs[a[i][0]];\n\t\t\t\t\t++cs[a[i][1]];\n\t\t\t\t\tif(!uf.isSame(a[i][0], a[i][1])){\n\t\t\t\t\t\tuf.unite(a[i][0], a[i][1]);\n\t\t\t\t\t}else{\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint cnt = 0;\n\t\t\tfor (int c : cs) {\n\t\t\t\tif (c == 1) {\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn cnt == k ? 1 : 0;\n\t\t}\n\t\tint result = 0;\n\t\tfor (int i = x + 1; i < m; ++i) {\n\t\t\tif (!b[i]) {\n\t\t\t\tb[i] = true;\n\t\t\t\tresult += f(i, en - 1);\n\t\t\t\tb[i] = false;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\t\n\tstatic class UnionFind {\n\t\tint[] par;\n\t\tint[] rank;\n\n\t\tpublic UnionFind(int n) {\n\t\t\tpar = new int[n];\n\t\t\trank = new int[n];\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tpar[i] = i;\n\t\t\t\trank[i] = 0;\n\t\t\t}\n\t\t}\n\n\t\tint find(int x) {\n\t\t\treturn (par[x] == x) ? x : (par[x] = find(par[x]));\n\t\t}\n\n\t\tvoid unite(int x, int y) {\n\t\t\tx = find(x);\n\t\t\ty = find(y);\n\t\t\tif (x == y)\n\t\t\t\treturn;\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])\n\t\t\t\t\t++rank[x];\n\t\t\t}\n\t\t}\n\n\t\tboolean isSame(int x, int y) {\n\t\t\treturn find(x) == find(y);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "988c4d715f34eb69527e5ebd46eab21e", "src_uid": "8087605a8f316150372cc4627f26231d", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 1/7/11\n * Time: 12:04 AM\n * To change this template use File | Settings | File Templates.\n */\npublic class DeadEnds {\n\n\tint[][] roads;\n\tint N, M, K;\n\n\tint pos(long n){\n\t\treturn (int)(Math.log(n) / Math.log(2) + 1e-7);\n\t}\n\n\tlong ways(int cnt, int road, long mask, int[] par){\n\t\tlong res = 0;\n\n\t\tif(cnt == N - 1){\n\n\t\t\tint[] usedJunctions = new int[N];\n\t\t\tfor(long j = mask, i = j & (j - 1); j > 0; j = i, i &= (i - 1)){\n\t\t\t\tusedJunctions[roads[pos(j - i)][0]]++;\n\t\t\t\tusedJunctions[roads[pos(j - i)][1]]++;\n\t\t\t}\n\n\t\t\tint dead = 0;\n\t\t\tfor(int i = 0; i < N; i++) if(usedJunctions[i] == 1) dead++;\n\n\t\t\tif(dead == K) return 1;\n\t\t\telse return 0;\n\n\t\t}\n\n\t\tif(road == M) return res;\n\n\t\tif(par[roads[road][0]] != par[roads[road][1]]){\n\n\t\t\tmask += (1L< 0) mask -= (1L< 0) {\n if ((n & 1) > 0) res = res * a % MOD;\n a = a * a % MOD;\n n >>= 1;\n }\n return res;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new SkyFullOfStars2().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "905bd98aeb6d03fcb58e555da21f766b", "src_uid": "6e4b0ee2e1406041a961582ead299a3a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\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 CSkyFullOfStars solver = new CSkyFullOfStars();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CSkyFullOfStars {\n NumberTheory.Mod998 mod = new NumberTheory.Mod998();\n private static final int Z = 3;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n\n long first = 0;\n long zN = mod.pow(Z, n);\n long zK = 1;\n long zNNK = mod.pow(zN, n);\n long zNinv = mod.inv(zN);\n for (int k = 0; k <= n; k++) {\n long term = mod.mult(mod.ncr(n, k), zK, zNNK, parity(k));\n first = mod.add(first, term);\n zK = mod.mult(zK, Z);\n zNNK = mod.mult(zNNK, zNinv);\n }\n first = mod.mult(first, 2);\n first = mod.subtract(first, mod.pow(Z, (long) n * n));\n\n long second = 0;\n long zKN = mod.pow(Z, 1 - n);\n for (int k = 1; k <= n; k++) {\n long pow = mod.pow(Z, (long) n * n - (long) n * k + 1);\n long x = mod.mult(mod.ncr(n, k), pow, parity(k));\n long summation = mod.add(mod.negative(1), mod.pow(mod.subtract(1, zKN), n));\n second = mod.add(second, mod.mult(x, summation));\n zKN = mod.mult(zKN, Z);\n }\n\n long answer = mod.add(first, second);\n answer = mod.subtract(mod.pow(Z, (long) n * n), answer);\n\n out.println(answer);\n }\n\n private long parity(int k) {\n return (k & 1) == 0 ? 1 : mod.negative(1);\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 NumberTheory {\n private static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n public abstract static class Modulus> {\n final ArrayList factorial = new ArrayList<>();\n final ArrayList invFactorial = new ArrayList<>();\n\n public abstract long modulus();\n\n public Modulus() {\n super();\n factorial.add(1L);\n invFactorial.add(1L);\n }\n\n public long fact(int n) {\n while (factorial.size() <= n) {\n factorial.add(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.add(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 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... x) {\n long r = 1;\n for (long i : x)\n r = mult(r, i);\n return r;\n }\n\n public long mult(long a, long b) {\n return (a * b) % modulus();\n }\n\n public long negative(long x) {\n return x == 0 ? 0 : modulus() - x;\n }\n\n public long pow(long x, int e) {\n if (e < 0) {\n x = inv(x);\n e *= -1;\n }\n if (e == 0)\n return 1;\n if ((e & 1) > 0)\n return mult(x, pow(x, e - 1));\n return pow(mult(x, x), e / 2);\n }\n\n public long pow(long x, long e) {\n if (e < 0) {\n x = inv(x);\n e *= -1;\n }\n if (e == 0)\n return 1;\n if ((e & 1) > 0)\n return mult(x, pow(x, e - 1));\n return pow(mult(x, x), e / 2);\n }\n\n public long inv(long value) {\n long g = modulus(), x = 0, y = 1;\n for (long r = value; r != 0; ) {\n long q = g / r;\n g %= r;\n\n long temp = g;\n g = r;\n r = temp;\n\n x -= q * y;\n\n temp = x;\n x = y;\n y = temp;\n }\n\n ASSERT(g == 1);\n ASSERT(y == modulus() || y == -modulus());\n\n return normalize(x);\n }\n\n }\n\n public static class Mod998 extends NumberTheory.Modulus {\n public long modulus() {\n return 998_244_353L;\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d56218a4662fce9296720a9a8fdbd33a", "src_uid": "6e4b0ee2e1406041a961582ead299a3a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n void solve() {\n int n=ni();\n precompute(n);\n long ans=(2*f3(n))%M;\n long sm=0;\n for(int i=0;i=0;i--){\n inv[i]=(inv[i+1]*(i+1))%M;\n }\n\n\n }\n long add(long x, long y,long M) {\n x += y;\n if (x < 0) x+=M;\n if (x >= M) x -=M;\n return x;\n }\n long sub(long x, long y,long M) {\n x -= y;\n if (x < 0) x+=M;\n if (x >= M) x -=M;\n return x;\n }\n long mul(long a, long b,long M)\n {\n return (a*1L*b)%M;\n }\n long modpow(long a, long b,long M)\n {\n long r=1;\n while(b>0)\n {\n if((b&1)>0) r=mul(r,a,M);\n a=mul(a,a,M);\n b>>=1;\n }\n return r;\n }\n\n long modInverse(long A, long M)\n {\n\n return modpow(A,M-2,M);\n }\n\n long M=(long)998244353;\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n void run() throws Exception {\n is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n pw = new PrintWriter(System.out);\n long s = System.currentTimeMillis();\n solve();\n pw.flush();\n if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n }\n\n public static void main(String[] args) throws Exception { new Main().run(); }\n\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7b430e588103851d992dee80995c6c15", "src_uid": "6e4b0ee2e1406041a961582ead299a3a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces998E {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\n\t\tint mod = 998244353;\n\t\tint phimod = mod-1;\n\t\t\n\t\tint[] factorial = new int[n+1];\n\t\tfactorial[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfactorial[i] = (int) (((long) factorial[i-1] * i)%mod);\n\t\t}\n\t\t\n\t\tint[] choose = new int[n+1];\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tint r = inverse(factorial[i], mod);\n\t\t\tint s = inverse(factorial[n-i], mod);\n\t\t\tint rs = (int) (((long) r * (long) s)%mod);\n\t\t\tchoose[i] = (int) (((long) rs * (long) factorial[n])%mod);\n\t\t}\n\t\t\n\t\tint sum1 = 0;\n\t\tint threepower = 1;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tint u = (mod+1 - threepower)%mod;\n\t\t\tint upower = power(u, n, mod);\n\t\t\tint summand = (int) (((long) choose[i] * (long) upower)%mod);\n\t\t\tif (i%2 == 0) {\n\t\t\t\tsummand = mod-summand;\n\t\t\t}\n\t\t\tsum1 = (sum1+summand)%mod;\n\t\t\t\n\t\t\tthreepower = (int) ((3 * (long) threepower)%mod);\n\t\t}\n\t\tsum1 = (int) ((3 * (long) sum1)%mod);\n\t\t\n\t\tint sum2 = power(power(3, n, mod)-1, n, mod);\n\t\tsum2 = (2*sum2)%mod;\n\t\tsum2 = (sum2+mod-power(3, power(n, 2, phimod), mod))%mod;\n\t\tsum2 = (int) ((3 * (long) sum2)%mod);\n\t\t\n\t\tint sum3 = power(power(3, n-1, mod)-1, n, mod);\n\t\tint aaa = (int) (((long) n * (long) (n-1))%phimod);\n\t\tsum3 = (mod + power(3, aaa, mod) - sum3)%mod;\n\t\tsum3 = (2*sum3)%mod;\n\t\tsum3 = (int) ((long) sum3 * (long) power(3, n, mod)%mod);\n\n\t\tint sum = sum1;\n\t\tsum = (sum+sum2)%mod;\n\t\tsum = (sum+sum3)%mod;\n\t\t\n\t\tSystem.out.println(sum);\n\t}\n\n\tpublic static int power(int base, int exp, int mod) {\n\t\tlong a = base%mod;\n\t\tif (exp == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\telse {\n\t\t\ta = (a*a)%mod;\n\t\t\tint b = (int) a;\n\t\t\tint almostanswer = power(b, exp/2, mod);\n\t\t\tif (exp%2 == 0) {\n\t\t\t\treturn almostanswer;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlong val = (long) almostanswer * (long) base;\n\t\t\t\tlong val2 = val%mod;\n\t\t\t\treturn (int) val2;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "53750398170ab31d3837206fbca7baad", "src_uid": "6e4b0ee2e1406041a961582ead299a3a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class LenghteningSticks {\n\tprivate static final BufferedReader in = new BufferedReader(\n\t\t\tnew InputStreamReader(System.in));\n\n\tpublic boolean isTriangle(int a, int b, int c) {\n\t\treturn (a + b > c && a + c > b && b + c > a);\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tString[] next = in.readLine().split(\" \");\n\t\tint a = Integer.parseInt(next[0]);\n\t\tint b = Integer.parseInt(next[1]);\n\t\tint c = Integer.parseInt(next[2]);\n\t\tint l = Integer.parseInt(next[3]);\n\t\t\n\t\tlong ways = 0;\n\t\tint bad = 0;\n\t\tfor (int i = 0; i <= l; i++) {\n\t\t\t// length of one side >= second = third side + whats left of l\n\t\t\tif (a + i > b + c + l - i) break;\n\t\t\tfor (int j = 0; i + j <= l; j++) {\n\t\t\tif (b + j > a + i + c + l - i - j) break;\n\t\t\t\t\n\t\t\t\tint x = Math.min(a + i, b + j);\n\t\t\t\tint y = Math.max(a + i, b + j);\n\t\t\t\tint minC = Math.max(y - x + 1, c);\n\t\t\t\tint maxC = Math.min(x + y - 1, c + l - i - j);\n\t\t\t\tif (maxC >= minC) { ways += maxC - minC + 1; }\n\t\t\t\t//else bad++;\n\t\t\t}\n\t\t}\n\t\t//System.out.println(bad);\n\t\tSystem.out.println(ways);\n\t\tin.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew LenghteningSticks().solve();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3498419da36b09d15fc56c37eddb89c9", "src_uid": "185ff90a8b0ae0e2b75605f772589410", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n public void solve() {\n int a = ni(), b = ni(), c = ni(), l = ni();\n int x, y ,z;\n if ((a > b) && (a > c)) {\n x = a;\n if (b > c) {\n y = b;\n z = c;\n } else {\n y = c;\n z = b;\n }\n } else if (b > c) {\n x = b;\n if (a > c) {\n y = a;\n z = c;\n } else {\n y = c;\n z = a;\n }\n } else {\n x = c;\n if (b > a) {\n y = b;\n z = a;\n } else {\n y = a;\n z = b;\n }\n }\n\n long ans = 0;\n for (int i = x; l - (i - x) - (Math.max(0, i - (y + z) + 1)) >= 0; i++) {\n for (int j = y; l - (i - x) - (j - y) - (Math.max(0, j - (i + z) + 1)) >= 0; j++) {\n// System.out.println(i + \" \" + j + \" \" + (l - (i - x) - (j - y)));\n int max = (i + j - 1);\n int min = Math.abs(i - j) + 1;\n// System.out.println(\"min: \" + min + \" max: \" + max);\n int steps = l - (i - x) - (j - y) - Math.max(0, min - z);\n min = Math.max(min, z);\n max = Math.min(max, min + steps);\n ans += Math.max(0, max - min + 1);\n// System.out.println(Math.max(0, max - min + 1));\n }\n }\n write(ans + \"\\n\");\n }\n\n\n\n\n\n public static void main(String[] args){\n Main m = new Main();\n m.solve();\n try {\n m.writer.close();\n } catch (IOException e) {};\n }\n BufferedReader reader;\n BufferedWriter writer;\n StringTokenizer tokenizer;\n public Main() {\n reader = new BufferedReader(new InputStreamReader(System.in));\n writer = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n int ni() {\n return Integer.parseInt(n());\n }\n String n() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {}\n }\n return tokenizer.nextToken();\n }\n void write(String s) {\n try {\n writer.write(s);\n } catch(IOException e) {};\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c9917560452e89422c41990ea36a1e12", "src_uid": "185ff90a8b0ae0e2b75605f772589410", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class LenghteningSticks {\n\tprivate static final BufferedReader in = new BufferedReader(\n\t\t\tnew InputStreamReader(System.in));\n\n\tpublic boolean isTriangle(int a, int b, int c) {\n\t\treturn (a + b > c && a + c > b && b + c > a);\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tString[] next = in.readLine().split(\" \");\n\t\tint a = Integer.parseInt(next[0]);\n\t\tint b = Integer.parseInt(next[1]);\n\t\tint c = Integer.parseInt(next[2]);\n\t\tint l = Integer.parseInt(next[3]);\n\t\t\n\t\tlong ways = 0;\n\t\tfor (int i = 0; i <= l; i++) {\n\t\t\t// length of one side >= second = third side + whats left of l\n\t\t\t//if (a + i > b + c + l - i) break;\n\t\t\tfor (int j = 0; i + j <= l; j++) {\n\t\t\t\t//if (b + j > a + c + l - i - j) break;\n\t\t\t\tfor (int k = 0; i + j + k <= l; k++) {\n\t\t\t\t\tif (isTriangle(a + i,b + j,c + k)) {\n\t\t\t\t\t\tways++;\n\t\t\t\t\t}\n\t\t\t\t\t//else { break; } \n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ways);\n\t\tin.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew LenghteningSticks().solve();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "716e83a3ad14f7f10e48264436a2b0c0", "src_uid": "185ff90a8b0ae0e2b75605f772589410", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class C\n{\n\tpublic static final Random RANDOM = new Random(System.currentTimeMillis());\n\tprivate BufferedReader bufferedReader;\n\tprivate StringTokenizer stringTokenizer;\n\tprivate PrintWriter out;\n\n\tpublic C()\n\t{\n\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t}\n\n\tpublic C(BufferedReader bufferedReader)\n\t{\n\t\tthis.bufferedReader = bufferedReader;\n\t\tthis.stringTokenizer = null;\n\t\tthis.out = new PrintWriter(new BufferedOutputStream(System.out));\n\t}\n\n\tpublic C(String file) throws FileNotFoundException\n\t{\n\t\tthis(new BufferedReader(new InputStreamReader(new FileInputStream(file))));\n\t}\n\n\tprivate String next() throws IOException\n\t{\n\t\twhile ((this.stringTokenizer == null) || (!this.stringTokenizer.hasMoreTokens()))\n\t\t{\n\t\t\tthis.stringTokenizer = new StringTokenizer(this.bufferedReader.readLine());\n\t\t}\n\t\treturn stringTokenizer.nextToken();\n\t}\n\n\tpublic int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic String nextLine() throws IOException\n\t{\n\t\treturn this.bufferedReader.readLine();\n\t}\n\n\tpublic void close()\n\t{\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tC template = new C();\n\t\ttry\n\t\t{\n\t\t\ttemplate.solve();\n\t\t}\n\t\tcatch (IOException exception)\n\t\t{\n\t\t\texception.printStackTrace();\n\t\t}\n\t\ttemplate.close();\n\t}\n\n\tpublic boolean degenerate(int[] x)\n\t{\n\t\tboolean result = false;\n\t\tfor (int index = 0; index < 3; index++)\n\t\t{\n\t\t\tresult |= x[index] >= x[(index + 1) % 3] + x[(index + 2) % 3];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic void solve() throws IOException\n\t{\n\t\tint x[] = new int[3];\n\t\tx[0] = nextInt();\n\t\tx[1] = nextInt();\n\t\tx[2] = nextInt();\n\t\tint l = nextInt();\n\t\tArrays.sort(x);\n\t\tlong result = 0;\n\t\tfor (int l2 = 0; l2 <= l; l2++)\n\t\t{\n\t\t\tfor (int l1 = 0; l1 <= l - l2; l1++)\n\t\t\t{\n\t\t\t\tint x1 = Math.min(x[1] + l1, x[2] + l2);\n\t\t\t\tint x2 = Math.max(x[1] + l1, x[2] + l2);\n\t\t\t\tint l0Min = Math.max(0, x2 - x1 - x[0] + 1);\n\t\t\t\tint l0Max = Math.min(l - l2 - l1, x1 + x2 - x[0] - 1);\n//\t\t\t\tout.println(x1 + \", \" + x2 + \", \" + l0Min + \"-\" + l0Max);\n\t\t\t\tresult += Math.max(0, l0Max - l0Min + 1);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(result);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d968ab8712630374c157a9e6b54c7b94", "src_uid": "185ff90a8b0ae0e2b75605f772589410", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "// Don't place your source in a package\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 sc=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=s.length()){\r\n if(diff!=0)return INF;\r\n return 0;\r\n }\r\n if(chunk>350||Math.abs(diff)>350){\r\n return INF;\r\n }\r\n if(dp[pos][diff+400][chunk+400]!=-1)return dp[pos][diff+400][chunk+400];\r\n\r\n\r\n int d=s.charAt(pos)-'0';\r\n long res=INF;\r\n int newdiff=diff*10+chunk-d;\r\n for(int i=-6;i<=6;i++){\r\n long cnt=Math.abs(i)*(s.length()-pos);\r\n res=Math.min(res,cnt+dfs(s,pos+1,newdiff+i,chunk+i));\r\n }\r\n dp[pos][diff+400][chunk+400]=res;\r\n return res;\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b944939150624d4829a606bd178c3556", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\npublic class Edu104F{\r\n\tpublic static void main(String[] main) throws Exception{\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\r\n\t\tPrintWriter out = new PrintWriter(System.out);\r\n\t\tString s = st.nextToken();\r\n\t\tint[] num = new int[s.length()+1];\r\n\t\tnum[1] = s.charAt(0) - 48;\r\n\t\tfor(int i = 2; i <= s.length(); i++) {\r\n\t\t\tnum[i] = s.charAt(i-1) - s.charAt(i-2);\r\n\t\t}\r\n\t\tint iters = 0;\r\n\t\tboolean edit = true;\r\n\t\tint min = 10000;\r\n\t\twhile(edit) {\r\n\t\t\titers++;\r\n\t\t\tedit = false;\r\n\t\t\tfor(int i = 1; i < s.length(); i++) {\r\n\t\t\t\tif(num[i] > 5) {\r\n\t\t\t\t\tnum[i-1]++;\r\n\t\t\t\t\tnum[i] = num[i]-10;\r\n\t\t\t\t\tnum[s.length()]--;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == 5 && num[i-1] < 0) {\r\n\t\t\t\t\tnum[i-1]++;\r\n\t\t\t\t\tnum[i] = num[i]-10;\r\n\t\t\t\t\tnum[s.length()]--;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == 5 && num[i-1] == 4 && num[i-2] < 0 && (num[s.length()] > 0 || num[s.length()] <= -4)) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -5;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == 5 && num[i-1] == 4 && num[i-2] < 0 && num[s.length()] < -3 && num[s.length() - 1] > 0) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -5;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == 5 && num[i-1] == 5 && num[s.length()] > 1) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -4;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == 5 && num[i-1] == 5 && num[i-2] == 5) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -4;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] < -5) {\r\n\t\t\t\t\tnum[i-1]--;\r\n\t\t\t\t\tnum[i] = num[i]+10;\r\n\t\t\t\t\tnum[s.length()]++;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == -5 && num[i-1] > 0) {\r\n\t\t\t\t\tnum[i-1]--;\r\n\t\t\t\t\tnum[i] = num[i]+10;\r\n\t\t\t\t\tnum[s.length()]++;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == -5 && num[i-1] == -4 && (num[i-2] > 0) && (num[s.length()] < 0 || num[s.length()] >= 4)) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 5;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == -5 && num[i-1] == -4 && (num[i-2] == -4 && num[i-3] > 0) && (num[s.length()] < 0 || num[s.length()] >= 4)) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 5;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == -5 && num[i-1] == -4 && num[i-2] > 0 && num[s.length()] > 3 && num[s.length() - 1] < 0) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 5;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == -5 && num[i-1] == -5 && num[s.length()] < -1) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 4;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == -5 && num[i-1] == -5 && num[i-2] == -5) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 4;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(num[s.length()] > 6) {\r\n\t\t\t\tnum[s.length()-1]++;\r\n\t\t\t\tnum[s.length()] -= 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(num[s.length()] >= 5 && num[s.length() - 1] < 0) {\r\n\t\t\t\tnum[s.length()-1]++;\r\n\t\t\t\tnum[s.length()] -= 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(s.length() >= 2 && num[s.length()] == 6 && num[s.length()-1] == 4 && num[s.length()-2] < 0) {\r\n\t\t\t\tnum[s.length()-1]++;\r\n\t\t\t\tnum[s.length()] -= 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(num[s.length()] < -6) {\r\n\t\t\t\tnum[s.length()-1]--;\r\n\t\t\t\tnum[s.length()] += 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(num[s.length()] <= -5 && num[s.length() - 1] > 0) {\r\n\t\t\t\tnum[s.length()-1]--;\r\n\t\t\t\tnum[s.length()] += 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(s.length() >= 2 && num[s.length()] == -6 && num[s.length()-1] == -4 && num[s.length()-2] > 0) {\r\n\t\t\t\tnum[s.length()-1]--;\r\n\t\t\t\tnum[s.length()] += 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\tint ans = 0;\r\n\t\t\tfor(int i = 0; i <= s.length(); i++) {\r\n\t\t\t\t//out.print(num[i] + \" \");\r\n\t\t\t\tans += (s.length() + 1 - i)*Math.abs(num[i]);\r\n\t\t\t}\r\n\t\t\tmin = Math.min(ans, min);\r\n\t\t\tif(iters > 7000000) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tint ans = 0;\r\n\t\tfor(int i = 0; i <= s.length(); i++) {\r\n\t\t\t//out.print(num[i] + \" \");\r\n\t\t\tans += (s.length() + 1 - i)*Math.abs(num[i]);\r\n\t\t}\r\n\t\tout.println(Math.min(min,ans));\r\n\t\tout.close();\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dc9e3ae7779fcb94e6298ed858646320", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "138e0d702c6935e582ac0aa15969e644", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0} {"lang": "Java 11", "source_code": "//package ecr104;\r\n\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 F {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n//\tString INPUT = \"11451481091145148109114514810911451481091145148109\";\r\n//\tString INPUT = \"99999999999999999999999999999999999999999999999999\";\r\n//\tString INPUT = \"37373737373737373737373737373737373737373737373737\";\r\n\tString INPUT = \"\";\r\n\r\n\tvoid solve()\r\n\t{\r\n\t\tchar[] N = (\"000\" + ns()).toCharArray();\r\n\t\tint n = N.length;\r\n\t\tfinal int D = 50;\r\n\t\tfinal int B = 1200;\r\n\t\tint[][] dp = new int[D][B]; // delta from ideal, previous balance = #\r\n\t\tfinal int O = 500;\r\n\t\tfinal int Q = 25;\r\n\t\tfinal int I = 9999999;\r\n\t\tfor(int i = 0;i < D;i++)Arrays.fill(dp[i], I);\r\n\t\tdp[Q][O] = 0;\r\n\t\tfor(int d = 0;d < n;d++){\r\n\t\t\tint[][] ndp = new int[D][B]; // delta from ideal, previous balance = #\r\n\t\t\tfor(int i = 0;i < D;i++)Arrays.fill(ndp[i], I);\r\n\r\n\t\t\tfor(int i = 0;i < D;i++) {\r\n\t\t\t\tfor (int j = 0; j < B; j++) {\r\n\t\t\t\t\tif (dp[i][j] >= I) continue;\r\n\t\t\t\t\tint del = (i - Q) * 10 + j - O - (N[d] - '0');\r\n\t\t\t\t\tfor (int k = -11; k <= 11; k++) {\r\n\t\t\t\t\t\tif (0 <= del + k + Q && del + k + Q < D) {\r\n\t\t\t\t\t\t\tndp[del + k + Q][j + k] = Math.min(ndp[del + k + Q][j + k],\r\n\t\t\t\t\t\t\t\t\tdp[i][j] + Math.abs(k) * (n - d));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\r\n\t\t\tdp = ndp;\r\n\t\t}\r\n\r\n\t\tint ans = Integer.MAX_VALUE;\r\n\t\tfor(int j = 0;j < B;j++){\r\n\t\t\tans = Math.min(ans, dp[Q][j]);\r\n\t\t}\r\n\t\tout.println(ans);\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 F().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f9a5dae93d47e6457762c9a0a5725ec3", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0} {"lang": "Java 8", "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 getCount(char[] c)\n\t{\n//\t\tfor(int i = 0; i < c.length; i++) System.out.print(c[i]+\"\");\n//\t\tSystem.out.println();\n\t\tint count = 0;\n\t\tint n = c.length;\n\t\tfor(int i = 0; i < n; i++)\n\t\t{\n\t\t\tboolean neg_check = false;\n\t\t\tint ct = 0;\n\t\t\tfor(int j = i; j < n; j++)\n\t\t\t{\n\t\t\t\tif(c[j] == '(') ct++;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tct--;\n\t\t\t\t\tif(ct < 0) neg_check = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0; j < i; j++)\n\t\t\t{\n\t\t\t\tif(c[j] == '(') ct++;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tct--;\n\t\t\t\t\tif(ct < 0) neg_check = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(ct != 0) neg_check = true;\n\t\t\tif(!neg_check) \n\t\t\t{\n\t\t\t\t//System.out.print(i+\" \");\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\t//System.out.println();\n\t\t//System.out.println(count);\n\t\treturn count;\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\tint n = Integer.parseInt(br.readLine());\n\t\tString s = br.readLine();\n\t\tchar[] c = s.toCharArray();\n\t\tint count = 0;\n\t\tint ind_i = 0;\n\t\tint ind_j = 0;\n\t\tchar[] c1 = new char[c.length];\n\t\tfor(int k = 0; k < c.length; k++) c1[k] = c[k];\n\t\tfor(int i = 0; i < n-1; i++)\n\t\t{\n\t\t\tfor(int j = i+1; j < n; j++)\n\t\t\t{\n\t\t\t\tchar temp = c1[i];\n\t\t\t\tc1[i] = c1[j];\n\t\t\t\tc1[j] = temp;\n\t\t\t\tint gc = getCount(c1);\n\t\t\t\tif(count < gc)\n\t\t\t\t{\n\t\t\t\t\tcount = gc;\n\t\t\t\t\tind_i = i;\n\t\t\t\t\tind_j = j;\n\t\t\t\t}\n\t\t\t\tfor(int k = 0; k < c.length; k++) c1[k] = c[k];\n\t\t\t}\n\t\t}\n\t\tind_i++;\n\t\tind_j++;\n\t\twriter.println(count);\n\t\twriter.println(ind_i + \" \" + ind_j);\n\t\tbr.close();\n\t\twriter.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dd7eaf15d6e176ecbf09d9e8b46f9096", "src_uid": "2d10668fcc2d8e90e102b043f5e0578d", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.Closeable;\nimport java.io.DataInputStream;\nimport java.io.Flushable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.function.Function;\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\tFastReader in = new FastReader(inputStream);\n\t\t\tOutput out = new Output(outputStream);\n\t\t\tD1TheWorldIsJustAProgrammingTaskEasyVersion solver = new D1TheWorldIsJustAProgrammingTaskEasyVersion();\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<<28);\n\t\tthread.start();\n\t\tthread.join();\n\t}\n\tstatic class D1TheWorldIsJustAProgrammingTaskEasyVersion {\n\t\tint n;\n\n\t\tpublic D1TheWorldIsJustAProgrammingTaskEasyVersion() {\n\t\t}\n\n\t\tpublic int solve(int[] arr) {\n\t\t\tint[] psum = new int[n+1];\n\t\t\tfor(int i = 0; i=0&&(i=0) {\n\t\t\t\t\t\tUtilities.leftShift(arr, 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\tint cnt = 0, sum = 0;\n\t\t\tfor(int i = 0; i o=='(' ? 1 : -1);\n\t\t\tint sum = 0;\n\t\t\tfor(int i = 0; ians) {\n\t\t\t\t\t\t\tans = cnt;\n\t\t\t\t\t\t\tl = i;\n\t\t\t\t\t\t\tr = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tUtilities.swap(arr, i, j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(ans);\n\t\t\tpw.println(l+1, r+1);\n\t\t}\n\n\t}\n\n\tstatic class Utilities {\n\t\tpublic static void swap(int[] arr, int i, int j) {\n\t\t\tif(i!=j) {\n\t\t\t\tarr[i] ^= arr[j];\n\t\t\t\tarr[j] ^= arr[i];\n\t\t\t\tarr[i] ^= arr[j];\n\t\t\t}\n\t\t}\n\n\t\tpublic static void leftShift(int[] arr, int offSet) {\n\t\t\tint[] tmp = new int[offSet];\n\t\t\tSystem.arraycopy(arr, 0, tmp, 0, offSet);\n\t\t\tSystem.arraycopy(arr, offSet, arr, 0, arr.length-offSet);\n\t\t\tSystem.arraycopy(tmp, 0, arr, arr.length-offSet, offSet);\n\t\t}\n\n\t\tpublic static class Debug {\n\t\t\tpublic static final boolean LOCAL = System.getProperty(\"ONLINE_JUDGE\")==null;\n\n\t\t\tprivate static String ts(T t) {\n\t\t\t\tif(t==null) {\n\t\t\t\t\treturn \"null\";\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn ts((Iterable) t);\n\t\t\t\t}catch(ClassCastException e) {\n\t\t\t\t\tif(t instanceof int[]) {\n\t\t\t\t\t\tString s = Arrays.toString((int[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof long[]) {\n\t\t\t\t\t\tString s = Arrays.toString((long[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof char[]) {\n\t\t\t\t\t\tString s = Arrays.toString((char[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof double[]) {\n\t\t\t\t\t\tString s = Arrays.toString((double[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof boolean[]) {\n\t\t\t\t\t\tString s = Arrays.toString((boolean[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn ts((Object[]) t);\n\t\t\t\t\t}catch(ClassCastException e1) {\n\t\t\t\t\t\treturn t.toString();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static String ts(T[] arr) {\n\t\t\t\tStringBuilder ret = new StringBuilder();\n\t\t\t\tret.append(\"{\");\n\t\t\t\tboolean first = true;\n\t\t\t\tfor(T t: arr) {\n\t\t\t\t\tif(!first) {\n\t\t\t\t\t\tret.append(\", \");\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t\tret.append(ts(t));\n\t\t\t\t}\n\t\t\t\tret.append(\"}\");\n\t\t\t\treturn ret.toString();\n\t\t\t}\n\n\t\t\tprivate static String ts(Iterable iter) {\n\t\t\t\tStringBuilder ret = new StringBuilder();\n\t\t\t\tret.append(\"{\");\n\t\t\t\tboolean first = true;\n\t\t\t\tfor(T t: iter) {\n\t\t\t\t\tif(!first) {\n\t\t\t\t\t\tret.append(\", \");\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t\tret.append(ts(t));\n\t\t\t\t}\n\t\t\t\tret.append(\"}\");\n\t\t\t\treturn ret.toString();\n\t\t\t}\n\n\t\t\tpublic static void dbg(Object... o) {\n\t\t\t\tif(LOCAL) {\n\t\t\t\t\tSystem.err.print(\"Line #\"+Thread.currentThread().getStackTrace()[2].getLineNumber()+\": [\");\n\t\t\t\t\tfor(int i = 0; iBUFFER_SIZE >> 1) {\n\t\t\t\tflushToBuffer();\n\t\t\t}\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(Object... o) {\n\t\t\tfor(int i = 0; iBUFFER_SIZE >> 1) {\n\t\t\t\tflushToBuffer();\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\tprivate void flushToBuffer() {\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 flush() {\n\t\t\ttry {\n\t\t\t\tflushToBuffer();\n\t\t\t\tos.flush();\n\t\t\t}catch(IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\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 SparseTable {\n\t\tpublic int[][] dmax;\n\t\tpublic int[][] dmin;\n\n\t\tpublic SparseTable(int[] arr) {\n\t\t\tint n = arr.length;\n\t\t\tdmin = new int[32][n];\n\t\t\tdmax = new int[32][n];\n\t\t\tdmin[0] = arr.clone();\n\t\t\tdmax[0] = arr.clone();\n\t\t\tfor(int i = 1; 1<='0'&&c<='9');\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\tprivate boolean isSpaceChar(byte b) {\n\t\t\treturn b==' '||b=='\\r'||b=='\\n'||b=='\\t'||b=='\\f';\n\t\t}\n\n\t\tprivate byte skip() {\n\t\t\tbyte ret;\n\t\t\twhile(isSpaceChar((ret = read()))) ;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate boolean isDigit(byte b) {\n\t\t\treturn b>='0'&&b<='9';\n\t\t}\n\n\t\tprivate byte skipToDigit() {\n\t\t\tbyte ret;\n\t\t\twhile(!isDigit(ret = read())&&ret!='-') ;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() {\n\t\t\ttry {\n\t\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\t}catch(IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif(bytesRead==-1) {\n\t\t\t\tbuffer[0] = -1;\n\t\t\t}\n\t\t}\n\n\t\tprivate byte read() {\n\t\t\tif(bytesRead==-1) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}else if(bufferPointer==bytesRead) {\n\t\t\t\tfillBuffer();\n\t\t\t}\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t}\n\n\tstatic interface InputReader {\n\t\tString next();\n\n\t\tint nextInt();\n\n\t\tdefault int[] nextIntChar(Function f) {\n\t\t\tString s = next();\n\t\t\tint[] ret = new int[s.length()];\n\t\t\tfor(int i = 0; il=new LinkedList();\n\t\t\tLinkedListranges=new LinkedList();\n\t\t\twhile(imax.v) {\n\t\t\t\t\tmax=new tri(o.l,o.r,o.v);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint le=max.l;int r=max.r;\n\t\t\tin[le]=')';in[r]='(';\n\t\t\tif(le==0) {\n\t\t\t\tres=new StringBuilder();\n\t\t\t\tfor(int k=1;kmaxAns) {\n left=i+1;\n right=j+1;\n maxAns=l;\n }\n bInts[i]*=-1;\n bInts[j]*=-1;\n }\n }\n }\n System.out.println(maxAns);\n System.out.println(left+\" \"+right);\n }\n }\n public static int countConcat(int[] r) {\n int ans = 0;\n int d = 0;\n int at = 0;\n for (int i=0;i=0){\n x = Math.abs(x)/g;\n y = Math.abs(y)/g;\n }else{\n x = -Math.abs(x)/g;\n y = Math.abs(y)/g;\n }\n }\n\n public boolean equals(Object fk){\n Pair p = (Pair)fk;\n return x == p.x && y== p.y;\n }\n\n public int hashCode(){\n return (int)(x*37+y);\n }\n\n }\n\n void dfs(int g, List go[],boolean vis[]){\n vis[g] = true;\n for(int u: go[g]){\n int to = u;\n if(!vis[to]) {\n dfs(to, go, vis);\n }\n }\n\n }\n\n public static void main(String[] args) throws Exception {\n new Main().run();}\n\n\n TreeMap tmp = new TreeMap<>();\n\n void remove(int u){\n int v = tmp.get(u);\n if(v==1){\n tmp.remove(u);\n }else{\n tmp.put(u,v-1);\n }\n }\n\n private int len(long i) {\n int ans = 0;\n while (i > 0) {\n i /= 10;\n ans++;\n }\n return ans;\n }\n long len[] = new long[100000000];\n\n long go(long a,long tot){\n int p = 0;\n for(int i=1;i*i<=a;++i){\n if(a%i==0){\n len[p++] = i;\n }\n }\n int g = -1;\n long ans = tot*2+2;\n for(int i=1;i*i<=(tot);++i){\n if(tot%i==0){\n while(g+1= a/len[g] ){\n ans = Math.min(ans, 2*(i+tot/i));\n }\n\n }\n }\n return ans;\n\n }\n\n\n void solve(){\n\n long a = nl();\n long b = nl();\n long tot = a+b;\n\n\n\n println(Math.min(go(a,tot),go(b,tot)));\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n// PriorityQueue q= new PriorityQueue<>((x,y)->{return x[0]-y[0];});\n//\n// q.offer(new int[]{0,0});\n// boolean inq[] = new boolean[n];\n// while(q.size()>0){\n// int c[]= q.poll();\n// for(int i=h[c[1]];i!=-1;i=ne[i]){\n// if(!inq[to[i]]) {\n// q.offer(new int[]{ wt[i], to[i]});\n// inq[to[i]] = true;\n// }\n// }\n// }\n\n\n\n\n\n }\n\n\n int err = 0;\n\n\n\n void go(int rt,int pt,int fa) {\n stk[rt] = pt;\n for(int i=h[rt];i!=-1;i=ne[i]) {\n if(to[i]==pt||to[i]==fa) continue;\n go(to[i],pt,rt);\n }\n }\n\n\n\n int ct = 0;\n void add(int u,int v){\n to[ct] = v;\n\n ne[ct] = h[u];\n h[u] = ct++;\n//\n// to1[ct] = u;\n// wt1[ct] = w;\n// ne1[ct] = h1[v];\n// h1[v] = ct++;\n }\n int []h,ne,to,wt,qt,stk;\n\n\n long inv(long a, long MOD) {\n //return fpow(a, MOD-2, MOD);\n return a==1?1:(long )(MOD-MOD/a)*inv(MOD%a, MOD)%MOD;\n }\n\n\n void inverse(){\n int MAXN = 10000;\n long inv[] = new long[MAXN+1];\n inv[1] = 1; //\u6ce8\u610f\u521d\u59cb\u5316\n long mod = 1000000007;\n for (int i=2; i<=MAXN; ++i) {\n inv[i] = (mod - mod / i) * inv[(int) (mod % i)] % mod;\n }\n }\n\n\n\n // \u8ba1\u7b97\u67d0\u4e2a\u7279\u522b\u5927\u7684\u7ec4\u5408\u6570\n long C(long n,long m, long MOD) {\n if(m+m>n)m=n-m;\n long up=1,down=1;\n for(long i=0;i0;i-=(i&-i)){\n s += t[i];\n }\n return s;\n }\n\n int equal_bigger(long t[],long v){\n int s=0,p=0;\n for(int i=Integer.numberOfTrailingZeros(Integer.highestOneBit(t.length));i>=0;--i) {\n if(p+(1<= 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 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 private double nd() {return Double.parseDouble(ns());}\n private char nc() {return (char) skip();}\n private char ncc() {int b;while((b = readByte()) != -1 && !(b >= 32 && b <= 126));return (char)b;}\n private String ns() {int b = skip();StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);b = readByte(); }\n return sb.toString();}\n private char[] ns(int n) {char[] buf = new char[n];int b = skip(), p = 0;\n while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b;b = readByte(); }\n return n == p ? buf : Arrays.copyOf(buf, p);}\n private String nline() {int b = skip();StringBuilder sb = new StringBuilder();\n while (!isSpaceChar(b) || b == ' ') { sb.appendCodePoint(b);b = readByte(); }\n return sb.toString();}\n private char[][] nm(int n, int m) {char[][] a = new char[n][];for (int i = 0; i < n; i++) a[i] = ns(m);return a;}\n private int[] na(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = ni();return a;}\n private long[] nal(int n) { long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nl();return a;}\n private int ni() { int num = 0, b; boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};\n if (b == '-') { minus = true; b = readByte(); }\n while (true) {\n if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');\n else return minus ? -num : num;\n b = readByte();}}\n private long nl() { long num = 0; int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};\n if (b == '-') { minus = true; b = readByte(); }\n while (true) {\n if (b >= '0' && b <= '9') num = num * 10 + (b - '0');\n else return minus ? -num : num;\n b = readByte();}}\n void print(Object obj){out.print(obj);}\n void println(Object obj){out.println(obj);}\n void println(){out.println();}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2a9c759a9ed87b9caeb4007d96ab7163", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "/**\n * BaZ :D\n */\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main\n{ \n static Reader scan;\n static PrintWriter pw;\n public static void main(String[] args) {\n new Thread(null,null,\"BaZ\",1<<25)\n {\n public void run()\n {\n try\n {\n solve();\n }\n catch(Exception e)\n { \n e.printStackTrace();\n System.exit(1);\n }\n }\n }.start();\n }\n static void solve() throws IOException\n {\n scan = new Reader();\n pw = new PrintWriter(System.out,true);\n StringBuilder sb = new StringBuilder();\n int t = 1;\n while(t-->0)\n { \n long a = nl();\n long b = nl();\n long a1[] = new long[10000000];\n long a2[] = new long[10000000];\n long b1[] = new long[10000000];\n long b2[] = new long[10000000];\n int na = 0,nb = 0;\n for(long i=1;i*i<=a;++i) {\n if(a%i==0){\n a1[na] = i;\n a2[na++] = a/i;\n }\n }\n for(long i=1;i*i<=b;++i) {\n if(b%i==0) {\n b1[nb] = i;\n b2[nb++] = b/i;\n }\n }\n// pl(\"na : \"+na);\n// for(int i=0;i list) \n {\n pl(listName+\" : \");\n for(Object o : list)\n p(o);\n pl();\n }\n static class Reader {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public Reader() {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public Reader(String file_name) throws IOException {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public String readLine() throws IOException {\n byte[] buf = new byte[64];\n int cnt = 0, c;\n while ((c = read()) != -1) {\n if (c == '\\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 <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);\n if (neg) return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead) fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null) return;\n din.close();\n }\n}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "da4113864165897cc9a7f969efcbcdc1", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.nio.charset.StandardCharsets;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class F1029 {\n\tstatic class Solver {\n\n\t\tlong A, B, C;\n\n\t\tvoid solve(FastScanner s, PrintWriter out) {\n\t\t\tA = s.nextLong();\n\t\t\tB = s.nextLong();\n\t\t\tC = A + B;\n\t\t\tlong best = (long) 1e18;\n\t\t\tlong p = 1, q, a = 1, b = 1;\n\t\t\twhile (p * p <= C) {\n\t\t\t\tif (C % p != 0) {\n\t\t\t\t\tp++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tq = C / p;\n\t\t\t\twhile (a * a <= A && ((A > q * a) || A % a != 0))\n\t\t\t\t\ta++;\n\t\t\t\twhile (b * b <= B && ((B > q * b) || B % b != 0))\n\t\t\t\t\tb++;\n\t\t\t\tif (a * a <= A || b * b <= B)\n\t\t\t\t\tbest = Math.min(best, 2 * (p + q));\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tout.println(best);\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tFastScanner s = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tSolver solver = new Solver();\n\t\tsolver.solve(s, out);\n\n\t\tout.close();\n\n\t}\n\n\tstatic int swap(int a, int b) {\n\t\treturn a;\n\t}\n\n\tstatic Object swap(Object a, Object b) {\n\t\treturn a;\n\t}\n\n\tstatic String ts(Object... o) {\n\t\treturn Arrays.deepToString(o);\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic FastScanner(File f) throws FileNotFoundException {\n\t\t\tthis(new FileInputStream(f));\n\t\t}\n\n\t\tpublic FastScanner(String s) {\n\t\t\tthis.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));\n\t\t}\n\n\t\tint read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tboolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tboolean isEndline(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isEndline(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndline(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\t// Jacob Garbage\n\n\t\tpublic int[] 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] = this.nextInt();\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic int[][] next2DIntArray(int N, int M) {\n\t\t\tint[][] ret = new int[N][];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = this.nextIntArray(M);\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long[] 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] = this.nextLong();\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long[][] next2DLongArray(int N, int M) {\n\t\t\tlong[][] ret = new long[N][];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = nextLongArray(M);\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int N) {\n\t\t\tdouble[] ret = new double[N];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = this.nextDouble();\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double[][] next2DDoubleArray(int N, int M) {\n\t\t\tdouble[][] ret = new double[N][];\n\t\t\tfor (int i = 0; i < N; i++)\n\t\t\t\tret[i] = this.nextDoubleArray(M);\n\t\t\treturn ret;\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7272d0a334dd0101d63f672aee2fbd5c", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class MultiColoredMarkers {\n\n public static boolean checkSmallRectangleCanBePlacedIntoBigRectangle(long smallRectangleSide, long a, long BigRectangleSide, long s){\n return ((smallRectangleSide <= BigRectangleSide) && ((a / smallRectangleSide) <= (s / BigRectangleSide)));\n }\n\n public static void getDividersPerValue(long n, long[] dividers){\n long sqrtOfN = (int) Math.sqrt(n);\n\n int i = 0;\n for (long divider = sqrtOfN; divider > 0; divider--){\n if (n % divider == 0) {\n dividers[i++] = divider;\n }\n }\n dividers[i] = 0;\n }\n\n public static long checkDividers(long[] dividersForInnerRectangle, long[] dividersForExternalRectangle,\n long innerRectangleS, long ExternalRectangleS, long bestP){\n long newBestP = bestP;\n for (long dividerExternal : dividersForExternalRectangle){\n if (dividerExternal == 0){\n break;\n }\n for (long dividerInner : dividersForInnerRectangle){\n if (dividerInner == 0){\n break;\n }\n if (checkSmallRectangleCanBePlacedIntoBigRectangle(dividerInner, innerRectangleS, dividerExternal, ExternalRectangleS)){\n newBestP = Math.min(bestP, 2 * (dividerExternal + ExternalRectangleS/dividerExternal));\n return newBestP;\n }\n }\n }\n return newBestP;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long a = sc.nextLong();\n long b = sc.nextLong();\n long s = a + b;\n long bestP = 2*s + 2;\n\n long[] dividersInner = new long[1000*1000];\n getDividersPerValue(a, dividersInner);\n long[] dividersS = new long[1000*1000];\n getDividersPerValue(s, dividersS);\n bestP = Math.min(bestP, checkDividers(dividersInner,dividersS,a,s,bestP));\n\n getDividersPerValue(b, dividersInner);\n bestP = Math.min(bestP, checkDividers(dividersInner,dividersS,b,s,bestP));\n System.out.println(bestP);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e57f317d47529a8745990101c0d8885a", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1", "difficulty": 2000.0} {"lang": "Java 8", "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\tstatic class Olymp {\n\t\tint id;\n\t\tString s;\n\n\t\tpublic Olymp(int id, String s) {\n\t\t\tthis.id = id;\n\t\t\tthis.s = s;\n\t\t}\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = nextToken();\n\t\t\ts = s.substring(4);\n\t\t\tint len = s.length();\n\t\t\tlong tail = Integer.parseInt(s);\n\n\t\t\tlong start = 1989;\n\t\t\tlong pw = 10;\n\t\t\tfor (int j = 1; j < len; j++) {\n\t\t\t\tstart += pw;\n\t\t\t\tpw *= 10;\n\t\t\t}\n\n\n\t\t\tlong res = ((start - 1 - tail) / pw + 1) * pw + tail;\n\t\t\tout.println(res);\n\n\t\t}\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ed160bab6a1ae8e3ab9a58240e4667f1", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class InternationalOlympiad\n{\n\tpublic static final long INFINITY = 1000000000;\n\t\n\tpublic static HashSet used;\n\tpublic static HashMap map;\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tused = new HashSet();\n\t\tmap = new HashMap();\n\t\t\n\t\tArrayDeque queue = new ArrayDeque();\n\t\tfor(long x = 0; x < 1989; x++)\n\t\t{\n\t\t\tqueue.add(x);\n\t\t}\n\t\t\n\t\twhile(queue.size() > 0)\n\t\t{\n\t\t\tlong num = queue.remove();\n\t\t\t\n\t\t\tlong next = next(num);\n\t\t\tmap.put(num, next);\n\t\t\tused.add(next);\n\t\t\t\n\t\t\tif(next < INFINITY)\n\t\t\t{\n\t\t\t\tqueue.add(next);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint n = in.nextInt();\n\t\tfor(int y = 0; y < n; y++)\n\t\t{\n\t\t\tlong abbr = Long.parseLong(in.next().substring(4));\n\t\t\t\n\t\t\tif(map.containsKey(abbr))\n\t\t\t{\n\t\t\t\tSystem.out.println(map.get(abbr));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.println(abbr);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static long next(long num)\n\t{\n\t\tint shift = (\"\" + num).length();\n\t\tlong pow = 1;\n\t\tfor(int i = 0; i < shift; i++)\n\t\t{\n\t\t\tpow *= 10;\n\t\t}\n\t\t\n\t\tlong left = 1 * pow;\n\t\twhile(true)\n\t\t{\n\t\t\tif(left + num >= 1989 && !used.contains(left + num))\n\t\t\t{\n\t\t\t\treturn left + num;\n\t\t\t}\n\t\t\t\n\t\t\tleft += pow;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f3c822d4d1f8e7400a68882a8e1b7e33", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "/*\n * Code Author: Jayesh Udhani\n * Institute : DA-IICT \n * 3rd year BTech ICT Student\n */\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class CROC2016D\n{\n\tstatic class Pair\n\t{\n\t\tprivate String first;\n\t\tprivate String second;\n\t\tpublic Pair(String i, String j) \n\t\t{ \n\t\t\tthis.first = i;\n\t\t\tthis.second = j;\n\t\t}\n\t\tpublic String getFirst() { return first; }\n\t\tpublic String getSecond() { return second ;}\n\t}\n\tprivate static Pair solverUtil(String s)\n\t{\n\t\tint n=s.length();\n\t\tif(n==1)\n\t\t\treturn new Pair(\"1989\", \"1998\");\n\t\telse if(n==2)\n\t\t\treturn new Pair(\"1999\", \"2098\");\n\t\telse if(n==3)\n\t\t\treturn new Pair(\"2099\", \"3098\");\n\t\telse\n\t\t{\n\t\t\tStringBuilder sb1=new StringBuilder();\n\t\t\tStringBuilder sb2=new StringBuilder();\n\t\t\tint i=0;\n\t\t\tfor(;i=0 && t.compareTo(b2)<=0)\n\t\t\t\treturn s;\n\t\t\tfor(int i=1;i<=9;i++)\n\t\t\t{\n\t\t\t\tBigInteger t1=new BigInteger(i+s);\n\t\t\t\tif(t1.compareTo(b1)>=0 && t1.compareTo(b2)<=0)\n\t\t\t\t\treturn i+s;\n\t\t\t}\n\t\t}\n\t\treturn null;\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\tint n=in.nextInt(),i=0;\n\t\tfor(;i=1;curr--){\n\t\t\tint t = Math.min(K, curr-1);\n\t\t\tfor(int count=0;count<=t;count++){\n\t\t\t\tfor(int last=0;last<=curr;last++){\n\t\t\t\t\tlong ans = 0;\n\t\t\t\t\tif(count != K)\n\t\t\t\t\t\tans = (dp[curr+1][count+1][curr] * (pow2[curr] - pow2[last] + mod));\n\t\t\t\t\tans = (ans + dp[curr+1][count][last] * pow2[last]) % mod;\n\t\t\t\t\tdp[curr][count][last] = (int)ans;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tw.println(dp[1][0][0]);\n\t\tw.close();\n\t}\n\t\n\tstatic class InputReader {\n\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[8192];\n\t\tprivate int curChar;\n\t\tprivate int snumChars;\n\t\tprivate SpaceCharFilter filter;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\n\t\t\tint res = 0;\n\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\n\t\t\tlong res = 0;\n\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8524a55c2760447f9c559e9561bd0e6f", "src_uid": "111673158df2e37ac6c019bb99225ccb", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Collections.*;\nimport static java.lang.Math.*;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.*;\nimport static java.math.BigInteger.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean my;\n try {\n my = System.getProperty(\"MY_LOCAL\") != null;\n } catch (Exception e) {\n my = false;\n\n }\n try{\n err = System.err;\n if( my ){\n sc = new FastScanner(new BufferedReader(new FileReader(\"input.txt\")));\n// sc = new FastScanner(new BufferedReader(new FileReader(\"C:\\\\myTest.txt\")));\n out = new PrintWriter (new FileWriter(\"output.txt\"));\n }\n else {\n sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n// out = new PrintWriter(new OutputStreamWriter(System.out));\n }catch(Exception e){\n MLE();\n }\n if( my )\n tBeg = System.currentTimeMillis();\n solve();\n if( my )\n err.println( \"TIME: \" + (System.currentTimeMillis() - tBeg ) / 1e3 );\n exit(0);\n }\n\n void exit( int val ){\n err.flush();\n out.flush();\n System.exit(val);\n }\n\n double tBeg;\n FastScanner sc;\n PrintWriter out;\n PrintStream err;\n\n class FastScanner{\n\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner( BufferedReader _br ){\n br = _br;\n }\n\n String readLine(){\n try {\n return br.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n String next(){\n while( st==null || !st.hasMoreElements() )\n st = new StringTokenizer(readLine());\n return st.nextToken();\n }\n\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n double nextDouble(){ return Double.parseDouble(next()); }\n }\n\n void MLE(){\n int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];\n }\n\n void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }\n\n void TLE(){\n for(;;);\n }\n\n public static void main(String[] args) {\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"Lolka\", 256_000_000L ).run();\n }\n\n ////////////////////////////////////////////////////////////////\n\n final long mod = (int)1e9 + 7;\n int n, k;\n Long[][] dp0, dp1;\n long[] pow2 = new long[1000];\n {\n pow2[0] = 1;\n for (int i = 1; i < pow2.length; i++) {\n pow2[i] = (pow2[i-1] * 2) % mod;\n }\n }\n\n void solve(){\n n = sc.nextInt();\n k = sc.nextInt();\n dp0 = new Long[k+1][n+1];\n for (Long[] val : dp0) fill(val, 0L);\n\n for (int sz = 1; sz <= n; sz++) {\n dp1 = new Long[k+1][n+1];\n\n for (int cnt = 0; cnt <= k; cnt++) {\n for (int last = 0; last <= sz; last++) {\n if( cnt == 0 ){\n if( last == 0 ) dp1[cnt][last] = 1L;\n else dp1[cnt][last] = 0L;\n }\n else if( sz == last ){\n if( cnt == 1 ){\n dp1[cnt][last] = (pow2[last]-1);\n }\n else{\n dp1[cnt][last] = 0L;\n for (int l = 1; l <= sz - 1; l++) {\n dp1[cnt][last] += (dp1[cnt-1][l] * (pow2[sz-l]-1)) % mod;\n }\n }\n }\n else{\n dp1[cnt][last] = dp0[cnt][last] * pow2[last];\n }\n dp1[cnt][last] = ( dp1[cnt][last]%mod + mod ) % mod;\n }\n }\n //\n dp0 = dp1;\n }\n long ans = 0;\n for (int last = 0; last <= n; last++) {\n ans += dp0[k][last];\n }\n ans %= mod;\n out.println( ans );\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fce6c224106815041341052606676e01", "src_uid": "111673158df2e37ac6c019bb99225ccb", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Collections.*;\nimport static java.lang.Math.*;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.*;\nimport static java.math.BigInteger.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean my;\n try {\n my = System.getProperty(\"MY_LOCAL\") != null;\n } catch (Exception e) {\n my = false;\n\n }\n try{\n err = System.err;\n if( my ){\n sc = new FastScanner(new BufferedReader(new FileReader(\"input.txt\")));\n// sc = new FastScanner(new BufferedReader(new FileReader(\"C:\\\\myTest.txt\")));\n out = new PrintWriter (new FileWriter(\"output.txt\"));\n }\n else {\n sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n// out = new PrintWriter(new OutputStreamWriter(System.out));\n }catch(Exception e){\n MLE();\n }\n if( my )\n tBeg = System.currentTimeMillis();\n solve();\n if( my )\n err.println( \"TIME: \" + (System.currentTimeMillis() - tBeg ) / 1e3 );\n exit(0);\n }\n\n void exit( int val ){\n err.flush();\n out.flush();\n System.exit(val);\n }\n\n double tBeg;\n FastScanner sc;\n PrintWriter out;\n PrintStream err;\n\n class FastScanner{\n\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner( BufferedReader _br ){\n br = _br;\n }\n\n String readLine(){\n try {\n return br.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n String next(){\n while( st==null || !st.hasMoreElements() )\n st = new StringTokenizer(readLine());\n return st.nextToken();\n }\n\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n double nextDouble(){ return Double.parseDouble(next()); }\n }\n\n void MLE(){\n int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];\n }\n\n void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }\n\n void TLE(){\n for(;;);\n }\n\n public static void main(String[] args) {\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"Lolka\", 256_000_000L ).run();\n }\n\n ////////////////////////////////////////////////////////////////\n\n final long mod = (int)1e9 + 7;\n int n, k;\n long[][] dp0, dp1;\n long[] pow2 = new long[600];\n long[] pow2Inv = new long[600];\n {\n pow2[0] = 1;\n for (int i = 1; i < pow2.length; i++) {\n pow2[i] = (pow2[i-1] * 2) % mod;\n }\n for (int i = 0; i < pow2Inv.length; i++) {\n pow2Inv[i] = valueOf(pow2[i]).modInverse(valueOf(mod)).intValue();\n }\n }\n\n long add( long a, long b ){\n long c = a + b;\n if( mod <= c ) c -= mod;\n return c;\n }\n\n void solve(){\n n = sc.nextInt();\n k = sc.nextInt();\n dp0 = new long[k+1][n+1];\n for (long[] val : dp0) fill(val, 0L);\n\n for (int sz = 1; sz <= n; sz++) {\n dp1 = new long[k+1][n+1];\n\n long[] sumDiv = null;// = new long[sz+1];\n long[] sum = null; // = new long[sz+1];\n for (int cnt = 0; cnt <= k; cnt++) {\n long[] newSumDiv = new long[sz+1];\n long[] newSum = new long[sz+1];\n for (int last = 0; last <= sz; last++) {\n if( cnt == 0 ){\n if( last == 0 ) dp1[cnt][last] = 1L;\n else dp1[cnt][last] = 0L;\n }\n else if( sz == last ){\n if( cnt == 1 ){\n dp1[cnt][last] = (pow2[last]-1);\n }\n else{\n dp1[cnt][last] = 0L;\n dp1[cnt][last] += sumDiv[sz-1]*pow2[sz] - sum[sz-1];\n }\n }\n else{\n dp1[cnt][last] = dp0[cnt][last] * pow2[last];\n }\n dp1[cnt][last] = ( dp1[cnt][last]%mod + mod ) % mod;\n\n if( 1 <= last ){\n newSumDiv[last] = (dp1[cnt][last] * pow2Inv[last]) % mod;\n newSum[last] = dp1[cnt][last];\n }\n }\n\n for (int i = 1; i < newSum.length; i++) {\n newSum[i] = add( newSum[i], newSum[i-1] );\n newSumDiv[i] = add( newSumDiv[i], newSumDiv[i-1] );\n }\n sum = newSum;\n sumDiv = newSumDiv;\n }\n //\n dp0 = dp1;\n }\n long ans = 0;\n for (int last = 0; last <= n; last++) {\n ans += dp0[k][last];\n }\n ans %= mod;\n out.println( ans );\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64e1d7663d7c9e6d95a2cb84a61572fc", "src_uid": "111673158df2e37ac6c019bb99225ccb", "difficulty": 2500.0} {"lang": "Java 7", "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 E4 {\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\tint[][] dp = new int[K+1][n+1];\n\t\tdp[0][0] = 1;\n\t\tlong two0 = 1;\n\t\tfor(int end = 1;end <= n;end++){\n\t\t\ttwo0 *= 2;\n\t\t\tif(two0 >= mod)two0 -= mod;\n\t\t\tfor(int k = K;k >= 0;k--){\n\t\t\t\tint two = 1;\n\t\t\t\tlong lsum = 0;\n\t\t\t\tfor(int l = 0;l <= end-1;l++){\n\t\t\t\t\tlsum += dp[k][l] * (two0-two)%mod;\n\t\t\t\t\tif(lsum >= mod)lsum -= mod;\n\t\t\t\t\tif(lsum < 0)lsum += mod;\n\t\t\t\t\tdp[k][l] = (int)((long)dp[k][l] * two % mod);\n\t\t\t\t\ttwo *= 2;\n\t\t\t\t\tif(two >= mod)two -= mod;\n\t\t\t\t}\n\t\t\t\tif(k+1 <= K)dp[k+1][end] = (int)lsum;\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(ret%mod);\n\t}\n\t\n\tpublic static long pow(long a, long n, long mod) {\n\t\t//\t\ta %= mod;\n\t\tlong ret = 1;\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\tfor (; x >= 0; x--) {\n\t\t\tret = ret * ret % mod;\n\t\t\tif (n << 63 - x < 0)\n\t\t\t\tret = ret * a % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\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 E4().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "02f92432bb09b8ce467a97916eabb426", "src_uid": "111673158df2e37ac6c019bb99225ccb", "difficulty": 2500.0} {"lang": "Java 8", "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=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;j0){\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;j0) 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "79a1c451948f1226973cb4c7cf8e989b", "src_uid": "adfa5f280eefbacdbaa4ad605402b57a", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n long min;\n int[] minDigits;\n int[] maxDigits;\n long max;\n long res;\n long[][] comb;\n int[] cnt;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n comb = new long[20][20];\n comb[0][0] = 1;\n for (int i = 1; i < comb.length; ++i) {\n comb[i][0] = 1;\n for (int j = 1; j < comb.length; ++j) {\n comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];\n }\n }\n min = in.nextLong() - 1;\n max = in.nextLong() + 1;\n minDigits = makeDigits(min);\n maxDigits = makeDigits(max);\n int[] cnt = new int[10];\n this.cnt = new int[10];\n res = 0;\n int[] p = new int[10];\n generate(18, 1, cnt);\n out.println(res);\n }\n\n private int[] makeDigits(long min) {\n int[] res = new int[19];\n for (int i = 0; i < res.length; ++i) {\n res[res.length - 1 - i] = (int) (min % 10);\n min /= 10;\n }\n return res;\n }\n\n private void generate(int max, int at, int[] cnt) {\n if (at >= 10) {\n /*long n1 = count(cnt, min, minDigits);\n long n2 = count(cnt, max, maxDigits);\n if (n1 < n2) {\n ++res;\n }*/\n if (isAny(cnt)) {\n ++res;\n }\n return;\n }\n for (int x = 0; x <= max; ++x) {\n cnt[at] = x;\n generate(max - x, at + 1, cnt);\n }\n }\n\n private boolean isAny(int[] origCnt) {\n System.arraycopy(origCnt, 0, cnt, 0, 10);\n cnt[0] = maxDigits.length;\n for (int x : origCnt) cnt[0] -= x;\n int[] p = new int[10];\n for (int i = 0; i < p.length; ++i) p[i] = i - 1;\n boolean alreadyGreater = false;\n for (int pos = 0; pos < maxDigits.length; ++pos) {\n int cur = maxDigits[pos];\n int got = p[cur];\n while (got >= 0 && cnt[got] == 0) {\n got = p[got];\n }\n int tmp = cur;\n while (tmp != got) {\n int z = p[tmp];\n p[tmp] = got;\n tmp = z;\n }\n if (got >= 0 && got < cur) {\n if (alreadyGreater || got > minDigits[pos]) {\n return true;\n }\n if (got == minDigits[pos]) {\n --cnt[got];\n int at = pos + 1;\n int coming;\n outer:\n for (coming = 9; coming >= 0; --coming) {\n for (int i = cnt[coming]; i > 0; --i) {\n if (minDigits[at] < coming) {\n return true;\n }\n if (minDigits[at] > coming) break outer;\n ++at;\n }\n }\n if (coming < 0) {\n if (at != minDigits.length)\n throw new RuntimeException();\n }\n ++cnt[got];\n }\n }\n --cnt[cur];\n if (cnt[cur] < 0) return false;\n if (cur > minDigits[pos]) alreadyGreater = 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 long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d08b1b6af51bbe0343b2ad957bff8503", "src_uid": "adfa5f280eefbacdbaa4ad605402b57a", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public long a;\n public long b;\n public int pt;\n public int[] l;\n public int[] r;\n public int[] arr;\n public int ans;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n a = in.nextLong();\n b = in.nextLong();\n String sa = String.valueOf(a), sb = String.valueOf(b);\n while (sa.length() < sb.length()) sa = \"0\" + sa;\n l = new int[sa.length()];\n r = new int[sb.length()];\n for (int i = 0; i < sa.length(); i++) l[i] = sa.charAt(i) - '0';\n for (int i = 0; i < sb.length(); i++) r[i] = sb.charAt(i) - '0';\n arr = new int[10];\n long[] pow10 = new long[sb.length() + 1];\n pow10[0] = 1;\n for (int i = 1; i < pow10.length; i++) pow10[i] = pow10[i - 1] * 10;\n pt = 0;\n while (pt < sa.length() && l[pt] == r[pt]) {\n a -= pow10[sb.length() - pt - 1] * l[pt];\n b -= pow10[sb.length() - pt - 1] * l[pt];\n pt++;\n }\n if (pt == sb.length()) {\n out.println(1);\n return;\n }\n dfs(0, r.length - pt);\n out.println(ans);\n }\n\n public void dfs(int num, int left) {\n if (num == 9) {\n arr[9] = left;\n if (ok(arr)) {\n ans++;\n }\n } else {\n for (int i = 0; i <= left; i++) {\n arr[num] = i;\n dfs(num + 1, left - i);\n }\n }\n }\n\n public boolean ok(int[] arr) {\n if (arr[r[pt]] > 0) {\n arr[r[pt]] -= 1;\n long g = r[pt];\n for (int dd = 0; dd <= 9; dd++) for (int k = 0; k < arr[dd]; k++) g = g * 10 + dd;\n arr[r[pt]]++;\n if (g <= b) {\n return true;\n }\n }\n\n for (int cdig = r[pt] - 1; cdig >= l[pt]; cdig--) {\n if (arr[cdig] > 0) {\n arr[cdig]--;\n if (cdig == l[pt]) {\n long c1 = cdig;\n for (int dd = 9; dd >= 0; dd--) {\n for (int k = 0; k < arr[dd]; k++) c1 = c1 * 10 + dd;\n }\n if (c1 < a) {\n arr[cdig]++;\n if (c1 > b) {\n System.out.println(\"BAD!\");\n System.out.println(Arrays.toString(arr) + \" \" + c1);\n }\n return false;\n }\n }\n arr[cdig]++;\n return true;\n }\n }\n return false;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public long nextLong() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n long res = 0L;\n\n while (c >= 48 && c <= 57) {\n res *= 10L;\n res += (long) (c - 48);\n c = this.read();\n if (isSpaceChar(c)) {\n return res * (long) sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d5f2d4a8b345241aea0684e76e735256", "src_uid": "adfa5f280eefbacdbaa4ad605402b57a", "difficulty": 2700.0} {"lang": "Java 8", "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\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=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;j0){\n\n return true;\n }\n }\n\n if(st==ed){\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;j0) 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 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 a[id]=(int)n%10;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2dc40509927a8825be6e96da39f281cf", "src_uid": "adfa5f280eefbacdbaa4ad605402b57a", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n static double DP[][][][];\n static double p;\n static int screen = (1 << 8) - 1;\n\n public static double get(int index, int mask, int ninth, int cnt) {\n if (index == 0) {\n int res = 0;\n while ((mask & 1) == 0) {\n res++;\n mask >>= 1;\n }\n if (res == 8 && ninth == 0)\n res += cnt * ninth;\n return res;\n }\n if (DP[index][mask][ninth][cnt] != -1)\n return DP[index][mask][ninth][cnt];\n double res = 0;\n int nextBit = (mask & (1 << 7)) == 0 ? 0 : 1;\n int nextCnt = nextBit == ninth ? (cnt + 1) : 1;\n int nextMask = (mask << 1);\n res += p * get(index - 1, nextMask & screen, nextBit, nextCnt);\n\n nextMask = mask + 1;\n nextBit = (nextMask & (1 << 8)) == 0 ? ninth : 1;\n nextCnt = nextBit == 0 ? cnt : 1;\n res += (1 - p) * get(index - 1, nextMask & screen, nextBit, nextCnt);\n return DP[index][mask][ninth][cnt] = res;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int x = in.nextInt();\n int k = in.nextInt();\n p = in.nextDouble() / 100;\n DP = new double[k + 1][1 << 8][2][250];\n for (int i = 0; i < DP.length; i++)\n for (int j = 0; j < DP[0].length; j++)\n for (int l = 0; l < DP[0][0].length; l++)\n Arrays.fill(DP[i][j][l], -1);\n int mask = x & screen;\n int ninth = (x & (1 << 8)) == 0 ? 0 : 1;\n int cnt = 0;\n x >>= 8;\n while ((x & 1) == ninth && x > 0) {\n cnt++;\n x >>= 1;\n }\n System.out.println(get(k, mask, ninth, cnt));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "849021f97b307feab567c3b7ec2b5daa", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "//package codeforces;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n StringTokenizer stringTokenizer;\n\n String next() throws IOException {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n stringTokenizer = new StringTokenizer(reader.readLine());\n }\n return stringTokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n @SuppressWarnings(\"unchecked\")\n void solve() throws IOException {\n int x = nextInt();\n int k = nextInt();\n double p = 0.01 * nextInt();\n double ans = solve(x, k, p);\n writer.printf(Locale.US, \"%.10f\\n\", ans);\n writer.close();\n }\n\n private double solve(int x, int k, double p) {\n double q = 1.0 - p;\n final int BIG = 1 << 8;\n class Pair {\n long x;\n int compressed;\n\n Pair(long x, int compressed) {\n this.x = x;\n this.compressed = compressed;\n check();\n }\n\n void check() {\n int z = countZeroes(x);\n int zc = countZeroes(compressed);\n if(compressed % BIG == 0) {\n zc = compressed / BIG;\n }\n if(z != zc) {\n throw new RuntimeException(\"so wrong!\");\n }\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 (compressed != pair.compressed) return false;\n// if (x != pair.x) return false;\n//\n// return true;\n return pair.compressed == compressed;\n }\n\n @Override\n public int hashCode() {\n// int result = (int) (x ^ (x >>> 32));\n// result = 31 * result + compressed;\n// return result;\n return compressed;\n }\n\n Pair inc() {\n return new Pair(x + 1, compressed % BIG == 0 ? 1 : bigify(compressed + 1, BIG));\n }\n Pair shift() {\n return new Pair(x * 2, compressed % BIG == 0 ? compressed + BIG : bigify(compressed * 2, BIG));\n }\n }\n Map[] dp = new Map[k + 1];\n for(int i = 0; i <= k; i++) {\n dp[i] = new HashMap();\n }\n x = bigify(x, BIG);\n dp[0].put(new Pair(x, x), 1.0);\n for(int i = 0; i < k; i++) {\n Map nextMap = dp[i + 1];\n for (Map.Entry entry : ((Map)dp[i]).entrySet()) {\n Pair pair = entry.getKey();\n increment(nextMap, pair.shift(), p * entry.getValue());\n increment(nextMap, pair.inc(), q * entry.getValue());\n /*int y = entry.getKey();\n if(y % BIG == 0) {\n int py = y + BIG;\n int qy = 1;\n increment(nextMap, py, p * entry.getValue());\n increment(nextMap, qy, q * entry.getValue());\n } else {\n int yy = y + k - i;\n yy ^= y;\n y &= Math.max(BIG - 1, (1 << Integer.highestOneBit(yy)) - 1);\n int py = bigify(y * 2, BIG);\n int qy = bigify(y + 1, BIG);\n increment(nextMap, py, p * entry.getValue());\n increment(nextMap, qy, q * entry.getValue());\n }*/\n }\n dp[i].clear();\n }\n double ans = 0;\n for (Map.Entry entry : ((Map) dp[k]).entrySet()) {\n if(entry.getKey().compressed % BIG == 0) {\n ans += entry.getKey().compressed / BIG * entry.getValue();\n } else {\n ans += countZeroes(entry.getKey().compressed) * entry.getValue();\n }\n }\n return ans;\n }\n\n private int bigify(int x, int BIG) {\n if(x % BIG == 0) {\n x = countZeroes(x) * BIG;\n }\n return x;\n }\n\n void increment(Map map, K key, double value) {\n value += map.containsKey(key) ? map.get(key) : 0;\n map.put(key, value);\n }\n\n int countZeroes(long x) {\n int z = 0;\n while(x % 2 == 0) {\n x /= 2;\n z++;\n }\n return z;\n }\n\n public static void main(String[] args) throws IOException {\n new E().solve();\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f89ecc59427d8f8cffa47a683e4e729d", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "//package codeforces;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n StringTokenizer stringTokenizer;\n\n String next() throws IOException {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n stringTokenizer = new StringTokenizer(reader.readLine());\n }\n return stringTokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n @SuppressWarnings(\"unchecked\")\n void solve() throws IOException {\n int x = nextInt();\n int k = nextInt();\n double p = 0.01 * nextInt();\n double ans = solve(x, k, p);\n writer.printf(Locale.US, \"%.10f\\n\", ans);\n writer.close();\n }\n\n private double solve(int x, final int k, double p) {\n double q = 1.0 - p;\n final int BIG = 1 << 8;\n class Pair {\n long x;\n int compressed;\n\n Pair(long x, int compressed) {\n this.x = x;\n if (compressed % BIG != 0) {\n int foo = compressed + k;\n foo ^= compressed;\n this.compressed = compressed & Math.max(BIG - 1, (Integer.highestOneBit(foo) << 1) - 1);\n } else {\n this.compressed = compressed;\n }\n check();\n }\n\n void check() {\n int z = countZeroes(x);\n int zc = countZeroes(compressed);\n if (compressed % BIG == 0) {\n zc = compressed / BIG;\n }\n if (z != zc) {\n throw new RuntimeException(\"so wrong!\");\n }\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 (compressed != pair.compressed) return false;\n// if (x != pair.x) return false;\n//\n// return true;\n return pair.compressed == compressed;\n }\n\n @Override\n public int hashCode() {\n// int result = (int) (x ^ (x >>> 32));\n// result = 31 * result + compressed;\n// return result;\n return compressed;\n }\n\n Pair inc() {\n return new Pair(x + 1, compressed % BIG == 0 ? 1 : bigify(compressed + 1, BIG));\n }\n\n Pair shift() {\n return new Pair(x * 2, compressed % BIG == 0 ? compressed + BIG : bigify(compressed * 2, BIG));\n }\n\n }\n Map[] dp = new Map[k + 1];\n for (int i = 0; i <= k; i++) {\n dp[i] = new HashMap();\n }\n x = bigify(x, BIG);\n dp[0].put(new Pair(x, x), 1.0);\n for (int i = 0; i < k; i++) {\n// System.out.println(i);\n// System.out.println(dp[i].size());\n Map nextMap = dp[i + 1];\n for (Map.Entry entry : ((Map) dp[i]).entrySet()) {\n Pair pair = entry.getKey();\n increment(nextMap, pair.shift(), p * entry.getValue());\n increment(nextMap, pair.inc(), q * entry.getValue());\n /*int y = entry.getKey();\n if(y % BIG == 0) {\n int py = y + BIG;\n int qy = 1;\n increment(nextMap, py, p * entry.getValue());\n increment(nextMap, qy, q * entry.getValue());\n } else {\n int yy = y + k - i;\n yy ^= y;\n y &= Math.max(BIG - 1, (1 << Integer.highestOneBit(yy)) - 1);\n int py = bigify(y * 2, BIG);\n int qy = bigify(y + 1, BIG);\n increment(nextMap, py, p * entry.getValue());\n increment(nextMap, qy, q * entry.getValue());\n }*/\n }\n dp[i].clear();\n }\n double ans = 0;\n for (Map.Entry entry : ((Map) dp[k]).entrySet()) {\n if (entry.getKey().compressed % BIG == 0) {\n ans += entry.getKey().compressed / BIG * entry.getValue();\n } else {\n ans += countZeroes(entry.getKey().compressed) * entry.getValue();\n }\n }\n return ans;\n }\n\n private int bigify(int x, int BIG) {\n if (x % BIG == 0) {\n x = countZeroes(x) * BIG;\n }\n return x;\n }\n\n void increment(Map map, K key, double value) {\n value += map.containsKey(key) ? map.get(key) : 0;\n map.put(key, value);\n }\n\n int countZeroes(long x) {\n int z = 0;\n while (x % 2 == 0) {\n x /= 2;\n z++;\n }\n return z;\n }\n\n public static void main(String[] args) throws IOException {\n new E().solve();\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b7378a784b031ea6dafd78833a16364c", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.Random;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Arthur Gazizov - Kazan FU #4.3 [2oo7]\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 TaskRandom solver = new TaskRandom();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskRandom {\n int LIMIT_TIME = 2000;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long stepIntoSolve = System.currentTimeMillis();\n int x = in.nextInt();\n int k = in.nextInt();\n int p = in.nextInt();\n Random random = new Random(System.currentTimeMillis());\n int total = 0;\n int count = 0;\n do {\n // BigInteger value = BigInteger.valueOf(x);\n long value = x;\n for (int i = 0; i < k; i++) {\n int next = Math.abs(random.nextInt()) % 100 + 1;\n if (next <= p) {\n value *= 2l;\n //value = value.multiply(TWO);\n } else {\n value++;\n // value = value.add(BigInteger.ONE);\n }\n }\n total += Long.numberOfTrailingZeros(value);\n // total += getZerousCount(value);\n count++;\n } while (System.currentTimeMillis() - stepIntoSolve <= LIMIT_TIME);\n out.print((1.0 * total) / count);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void close() {\n writer.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 nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d769722f7045d7137026a031268598d", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import javax.sound.sampled.Line;\nimport java.awt.Point;\nimport java.awt.geom.Line2D;\nimport java.awt.geom.Point2D;\nimport java.io.*;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\nimport java.util.*;\npublic class A{\n\n\n void solve()throws Exception\n {\n\n\n\n\n\n }\n\n ////////////\n BufferedReader reader;\n PrintWriter writer;\n StringTokenizer stk;\n void run()throws Exception\n {\n reader=new BufferedReader(new FileReader(\"input.txt\"));\n stk=null;\n writer=new PrintWriter(new FileWriter(\"output.txt\"));\n solve();\n reader.close();\n writer.close();\n }\n int nextInt()throws Exception\n {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong()throws Exception\n {\n return Long.parseLong(nextToken());\n\n }\n double nextDouble()throws Exception\n {\n return Double.parseDouble(nextToken());\n\n\n }\n\n String nextString()throws Exception\n {\n return nextToken();\n }\n String nextLine()throws Exception\n {\n return reader.readLine();\n }\n String nextToken()throws Exception\n {\n if(stk==null || !stk.hasMoreTokens())\n {\n stk=new StringTokenizer(nextLine());\n return nextToken();\n\n }\n return stk.nextToken();\n }\n\n public static void main(String[]args) throws Exception\n {\n new A().run();\n }\n\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "add8fdbdb51f6cbf96570e3a291c38e6", "src_uid": "f22f28e2d8933f4199ba5ccfc0de8cda", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/29/11\n * Time: 7:56 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskD {\n\n final int MOD = 1000000007;\n\n int modInverse(int x, int M) {\n return (int) expo(x, M - 2);\n }\n\n long expo(int x, int n) {\n if (n == 0) return 1;\n\n if (n % 2 == 0) {\n long res = expo(x, n / 2);\n return (res * res) % MOD;\n } else {\n return (x * expo(x, n - 1)) % MOD;\n }\n }\n\n long[] fact;\n long[] factInv;\n\n void precal(int N) {\n this.fact = new long[N + 1];\n this.factInv = new long[N + 1];\n fact[0] = 1;\n factInv[0] = modInverse(1, MOD);\n for(int i = 1; i <= N; i++) {\n fact[i] = (i * fact[i - 1]) % MOD;\n factInv[i] = (modInverse(i, MOD) * factInv[i - 1]) % MOD;\n }\n }\n\n long comb (int n, int k) {\n if(k > n) return 0;\n long res = fact[n];\n res = (res * factInv[k]) % MOD;\n res = (res * factInv[n - k]) % MOD;\n return res;\n }\n\n void run() {\n int N = nextInt(), M = nextInt();\n int K = nextInt();\n\n precal(Math.max(N, K));\n\n long[] waysToFill = new long[N + 1];\n waysToFill[0] = 0;\n for(int i = 1; i <= N; i++) {\n waysToFill[i] = (int) expo(i, N);\n for(int j = 0; j < i; j++)\n waysToFill[i] = (waysToFill[i] - comb(i, j) * waysToFill[j] + MOD) % MOD;\n }\n\n long res = 0;\n for (int distinct = 1; distinct <= N; distinct++) {\n for (int common = 0; common <= distinct; common++) {\n int required = 2 * distinct - common;\n if (required > K) continue;\n\n int unique = distinct - common;\n long choose = comb(K, common);\n choose = (choose * comb(K - common, unique)) % MOD;\n choose = (choose * comb(K - common - unique, unique)) % MOD;\n\n long fill = expo(common, N * (M - 2));\n fill = (fill * waysToFill[distinct]) % MOD;\n fill = (fill * waysToFill[distinct]) % MOD;\n\n res = (res + choose * fill) % MOD;\n }\n }\n\n System.out.println(res);\n }\n\n int nextInt() {\n try {\n int c = System.in.read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n long nextLong() {\n try {\n int c = System.in.read();\n if (c == -1) return -1;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return -1;\n }\n if (c == '-') return -nextLong();\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String next() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (Character.isWhitespace(c))\n c = System.in.read();\n do {\n res.append((char) c);\n } while (!Character.isWhitespace(c = System.in.read()));\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n String nextLine() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (c == '\\r' || c == '\\n')\n c = System.in.read();\n do {\n res.append((char) c);\n c = System.in.read();\n } while (c != '\\r' && c != '\\n');\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n public static void main(String[] args) {\n new TaskD().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "702c4cf62520b8e1a33174d0ee2f8da8", "src_uid": "f22f28e2d8933f4199ba5ccfc0de8cda", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.awt.Point;\nimport java.awt.geom.Line2D;\nimport java.awt.geom.Point2D;\nimport java.io.*;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\nimport java.util.*;\npublic class D{\n long mod = 1000000007;\n void solve()throws Exception\n {\n long[] fact = new long[1000000 + 1];\n long[] rev = new long[fact.length];\n long[] temp = new long[fact.length];\n fact[0] = 1;\n rev[0] = 1;\n temp[1] = 1;\n for(int i=2;i= 0;j--){\n\t\t\t\tval += modpow(j, n, mod) * minus * C[i][j] % mod;\n\t\t\t\tminus = -minus;\n\t\t\t}\n\t\t\tF[i] = val % mod;\n\t\t}\n\t\t\n\t\tif(m == 1){\n\t\t\tout.println(modpow(K, n, mod));\n\t\t}else if(m == 2){\n\t\t\tlong sum = 0;\n\t\t\tlong c = 1;\n\t\t\tfor(int i = 1;i <= K;i++){\n\t\t\t\tc = c * (K-i+1) % mod;\n\t\t\t\tc = c * inv(i, mod) % mod;\n\t\t\t\tlong cfm = c*F[i]%mod;\n\t\t\t\tsum += cfm*cfm%mod;\n\t\t\t}\n\t\t\tout.println(sum%mod);\n\t\t}else{\n\t\t\tlong sum = 0;\n\t\t\tlong c = 1;\n\t\t\tfor(int i = 1;i <= K;i++){\n\t\t\t\tc = c * (K-i+1) % mod;\n\t\t\t\tc = c * inv(i, mod) % mod;\n\t\t\t\tc = mod - c;\n\t\t\t\tlong all = c*modpow(F[i], m, mod)%mod;\n\t\t\t\tsum += all;\n\t\t\t}\n\t\t\tout.println(sum%mod);\n\t\t}\n\t}\n\t\n\tpublic static long inv(long a, int p)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(long n = p-2;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1)ret = ret * mul % p;\n\t\t\tmul = mul * mul % p;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long modpow(long a, long n, long mod)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1){\n\t\t\t\tret = (ret * mul) % mod;\n\t\t\t}\n\t\t\tmul = (mul * mul) % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = oj ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D().run();\n\t}\n\t\n\tint ni() { return Integer.parseInt(in.next()); }\n\tlong nl() { return Long.parseLong(in.next()); }\n\tdouble nd() { return Double.parseDouble(in.next()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "440d87759ab0e99b009043263111a5cc", "src_uid": "f22f28e2d8933f4199ba5ccfc0de8cda", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/**\n * This class contains all kinds of searching techniques.\n * @author: himself\n*/\n\npublic class Main {\n\n // Iterative Binary Search -- O(lg(n))\n\n static int iterBinSearch(int[] arr, int n) {\n int l = 0, r = arr.length - 1, mid;\n while(l <= r) {\n mid = (l + r) / 2;\n if(arr[mid] == n)\n return mid;\n if(arr[mid] < n)\n l = mid + 1;\n else\n r = mid - 1;\n }\n return -1;\n }\n\n // Recursive Binary Search -- O(lg(n))\n\n static int binSearch(int[] arr, int n) {\n return binSearch(arr, n, 0, arr.length - 1);\n }\n\n static int binSearch(int[] arr, int n, int l, int r) {\n if(l <= r) {\n int mid = (l + r) / 2;\n if(arr[mid] == n)\n return mid;\n if(arr[mid] < n)\n return binSearch(arr, n, mid + 1, r);\n else\n return binSearch(arr, n, l, mid - 1);\n }\n return -1;\n }\n\n public static void main(String[] args) throws IOException {\n Reader.init(System.in);\n int n = Reader.nextInt();\n int[] arr = new int[n];\n for(int i = 0; i < n; i++)\n arr[i] = Reader.nextInt();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e61031451170c365abede10dfe6e4255", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Program2 {\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tSystem.out.printf(\"%d\", (int)((Math.floor(n/2) + 1) * Math.ceil(n/2));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8bb10c56376feae18ddfcad2c30de331", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static int main(String[] args){\n Scanner s= new Scanner(System.in);\n int n = s.nextInt();\n if(n%2==0){\n System.out.println(((n/2)+1)*(n/2));\n }else{\n System.out.println(((n/2)+1)*((n/2)+1));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ef6dfd1f30f6c4016f6113410ab0ea7", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*\npublic class Main{\n public static int main(String[] args){\n Scanner s= new Scanner(System.in);\n int n = s.nextInt();\n if(n%2==0){\n System.out.println(((n/2)+1)*(n/2));\n }else{\n System.out.println(((n/2)+1)*((n/2)+1));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "58683eb327080d5f371f075ec098d4c8", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\nimport org.omg.CORBA.PUBLIC_MEMBER;\n\npublic class my_class {\n\t\n\tpublic static ArrayList nums = new ArrayList<>();\n\tpublic static int rec(int i, int num, int arr[]){\n\t\tif(i < arr.length){\n\t\t\trec(i + 1, num + arr[i], arr);\n\t\t\trec(i + 1, num - arr[i], arr);\n\t\t\tif(i != 0)\n\t\t\t\trec(i + 1, num * arr[i], arr);\n\t\t}else{\n\t\t\tif(!nums.contains(Math.abs(num)) && (num != 0)){\n\t\t\t\tnums.add(Math.abs(num));\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\tpublic static void rec1(int arr[], int qwer){\n\t\tif(arr.length >= 2){\n\t\t\trec(0,0, arr);\n\t\t\tif(arr.length > 2){\n\t\t\t\tfor(int i = 0; i < arr.length - 1;i++){\n\t\t\t\t\tif(i + 1 != qwer){\n\t\t\t\t\t\tint[] tmpA = new int[arr.length - 1];\n\t\t\t\t\t\tfor(int s = 0; s < tmpA.length; s++){\n\t\t\t\t\t\t\tif(s < i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s];\n\t\t\t\t\t\t\tif(s == i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s]*10 + arr[s + 1];\n\t\t\t\t\t\t\tif(s > i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s + 1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\trec1(tmpA,i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws Exception{\n\t\tint k = nextInt(), m = nextInt();\n\t\tint sum = 0;\n\t\tfor(int counter = 1; counter <= 9999;counter++){\n\t\t\tint arr[] = new int[4];\n\t\t\tnums.clear();\n\t\t\tint tmp = counter;\n\t\t\tfor(int i = arr.length - 1;tmp != 0;i--){\n\t\t\t\tarr[i] = tmp % 10;\n\t\t\t\ttmp = tmp / 10;\n\t\t\t}\n\t\t\tnums.add(counter);\n\t\t\trec1(arr,0);\n\t\t\tint l;\n\t\t\tfor(int i = 0; i < nums.size();i++){\n\t\t\t\tif(sum > m - 1)\n\t\t\t\t\tbreak;\n\t\t\t\tif(nums.get(i)/10000 == 0){\n\t\t\t\t\tif(nums.get(i) > k)\n\t\t\t\t\t\tl = nums.get(i) - k;\n\t\t\t\t\telse\n\t\t\t\t\t\tl = k - nums.get(i);\n\t\t\t\t\tl = (((l*10 + arr[0])*10 + arr[1])*10 + arr[2])*10 + arr[3];\n\t\t\t\t\ttmp = l;\n\t\t\t\t\tint s = 0;\n\t\t\t\t\twhile(tmp/10 != 0){\n\t\t\t\t\t\ttmp = tmp/10;\n\t\t\t\t\t\ts++;\n\t\t\t\t\t}\n\t\t\t\t\ts = 7 - s;\n\t\t\t\t\twhile(s != 0){\n\t\t\t\t\t\tprint(0);\n\t\t\t\t\t\ts--;\n\t\t\t\t\t}\n\t\t\t\t\tprintln(l);\n\t\t\t\t\tsum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(sum > m - 1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t//println(sum);\n\t}\t\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\tprivate static BufferedReader inB = new BufferedReader(new InputStreamReader(System.in)); \n\tprivate static StreamTokenizer in = new StreamTokenizer(inB);\n\n\tprivate static void exit(Object o) throws Exception {\n\t\tout.println(o);\n\t\tout.flush();\n\t\tSystem.exit(0);\n\t}\n\tprivate static void println(Object o) throws Exception{\n\t\tout.println(o);\n\t\tout.flush();\n\t}\n\tprivate static void print(Object o) throws Exception{\n\t\tout.print(o);\n\t\tout.flush();\n\t}\n\tprivate static long nextLong() throws Exception {\n\t\tin.nextToken();\n\t\treturn (long)in.nval;\n\t} \n\tprivate static int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t} \n\tprivate static String nextString() throws Exception {\n\t\tin.nextToken();\n\t\treturn in.sval; \n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "561533ea04566a54ba77421ca5a789c2", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author Trung Pham\n */\npublic class E {\n\n public static void main(String[] args) {\n Scanner in = new Scanner();\n PrintWriter out = new PrintWriter(System.out);\n int k = in.nextInt();\n int m = in.nextInt();\n for (int i = 0; i < 10000; i++) {\n TreeSet set = cal(i, 4);\n for (int j = 0; j < set.size(); j++) {\n int val = k - set.pollFirst();\n if (val < 10000 && val >= 0) {\n System.out.printf(\"%04d%04d\\n\", val, i);\n m--;\n }\n if (m == 0) {\n return;\n }\n }\n }\n out.flush();\n //System.out.print(builder.toString());\n }\n\n public static TreeSet cal(int val, int length) {\n TreeSet set = new TreeSet();\n set.add(val);\n set.add(-val);\n if (length > 1) {\n for (int i = 1, a = 10; i < length; i++, a *= 10) {\n TreeSet set1 = cal(val / a, length - i);\n TreeSet set2 = cal(val % a, i);\n for (int j = 0; j < set1.size(); j++) {\n int val1 = set1.pollFirst();\n for (int k = 0; k < set2.size(); k++) {\n int val2 = set2.pollFirst();\n set.add(val1 + val2);\n set.add(val1 * val2);\n }\n }\n }\n }\n return set;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f41bbf14f4ae96b9ddf60aebe65864ff", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author Trung Pham\n */\npublic class E {\n\n public static void main(String[] args) {\n Scanner in = new Scanner();\n PrintWriter out = new PrintWriter(System.out);\n int k = in.nextInt();\n int m = in.nextInt();\n for (int i = 0; i < 10000; i++) {\n TreeSet set = cal(i, 4);\n for (int j = 0; j < set.size(); j++) {\n int val = k - set.pollFirst();\n if (val < 10000 && val >= 0) {\n out.printf(\"%04d%04d\\n\", val, i);\n m--;\n }\n if (m == 0) {\n return;\n }\n }\n }\n out.flush();\n //System.out.print(builder.toString());\n }\n\n public static TreeSet cal(int val, int length) {\n TreeSet set = new TreeSet();\n set.add(val);\n set.add(-val);\n if (length > 1) {\n for (int i = 1, a = 10; i < length; i++, a *= 10) {\n TreeSet set1 = cal(val / a, length - i);\n TreeSet set2 = cal(val % a, i);\n for (int j = 0; j < set1.size(); j++) {\n int val1 = set1.pollFirst();\n for (int k = 0; k < set2.size(); k++) {\n int val2 = set2.pollFirst();\n set.add(val1 + val2);\n set.add(val1 * val2);\n }\n }\n }\n }\n return set;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "690a9e4575839ce6ceb5bbfd97f0dd25", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\nimport org.omg.CORBA.PUBLIC_MEMBER;\n\npublic class my_class {\n\t\n\tpublic static ArrayList nums = new ArrayList<>();\n\tpublic static int rec(int i, int num, int arr[]){\n\t\tif(i < arr.length){\n\t\t\trec(i + 1, num + arr[i], arr);\n\t\t\trec(i + 1, num - arr[i], arr);\n\t\t\tif(i != 0)\n\t\t\t\trec(i + 1, num * arr[i], arr);\n\t\t}else{\n\t\t\tif(!nums.contains(Math.abs(num)) && (num != 0)){\n\t\t\t\tnums.add(Math.abs(num));\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\tpublic static void rec1(int arr[], int qwer){\n\t\tif(arr.length >= 2){\n\t\t\trec(0,0, arr);\n\t\t\tif(arr.length > 2){\n\t\t\t\tfor(int i = 0; i < arr.length - 1;i++){\n\t\t\t\t\tif(i + 1 != qwer){\n\t\t\t\t\t\tint[] tmpA = new int[arr.length - 1];\n\t\t\t\t\t\tfor(int s = 0; s < tmpA.length; s++){\n\t\t\t\t\t\t\tif(s < i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s];\n\t\t\t\t\t\t\tif(s == i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s]*10 + arr[s + 1];\n\t\t\t\t\t\t\tif(s > i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s + 1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\trec1(tmpA,i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws Exception{\n\t\tint k = nextInt(), m = nextInt();\n\t\tint sum = 0;\n\t\tArrayList re = new ArrayList<>();\n\t\tfor(int counter = 1; counter <= 9999;counter++){\n\t\t\tint arr[] = new int[4];\n\t\t\tnums.clear();\n\t\t\tint tmp = counter;\n\t\t\tfor(int i = arr.length - 1;tmp != 0;i--){\n\t\t\t\tarr[i] = tmp % 10;\n\t\t\t\ttmp = tmp / 10;\n\t\t\t}\n\t\t\tnums.add(counter);\n\t\t\trec1(arr,0);\n\t\t\tint l, last = -1;\n\t\t\tfor(int i = 0; i < nums.size();i++){\n\t\t\t\tif(sum > m - 1)\n\t\t\t\t\tbreak;\n\t\t\t\tif(nums.get(i)/10000 == 0){\n\t\t\t\t\tif(nums.get(i) > k)\n\t\t\t\t\t\tl = nums.get(i) - k;\n\t\t\t\t\telse\n\t\t\t\t\t\tl = k - nums.get(i);\n\t\t\t\t\tl = (((l*10 + arr[0])*10 + arr[1])*10 + arr[2])*10 + arr[3];\n\t\t\t\t\tint s = 0;\n\t\t\t\t\ttmp = l;\n\t\t\t\t\tif(!re.contains(l)){\n\t\t\t\t\t\twhile(tmp/10 != 0){\n\t\t\t\t\t\t\ttmp = tmp/10;\n\t\t\t\t\t\t\ts++;\n\t\t\t\t\t\t} \n\t\t\t\t\t\ts = 7 - s;\n\t\t\t\t\t\twhile(s != 0){\n\t\t\t\t\t\t\tprint(0);\n\t\t\t\t\t\t\ts--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tprintln(l);\n\t\t\t\t\t\tre.add(l);\n\t\t\t\t\t\tsum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(sum > m - 1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\t\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\tprivate static BufferedReader inB = new BufferedReader(new InputStreamReader(System.in)); \n\tprivate static StreamTokenizer in = new StreamTokenizer(inB);\n\n\tprivate static void exit(Object o) throws Exception {\n\t\tout.println(o);\n\t\tout.flush();\n\t\tSystem.exit(0);\n\t}\n\tprivate static void println(Object o) throws Exception{\n\t\tout.println(o);\n\t\tout.flush();\n\t}\n\tprivate static void print(Object o) throws Exception{\n\t\tout.print(o);\n\t\tout.flush();\n\t}\n\tprivate static long nextLong() throws Exception {\n\t\tin.nextToken();\n\t\treturn (long)in.nval;\n\t} \n\tprivate static int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t} \n\tprivate static String nextString() throws Exception {\n\t\tin.nextToken();\n\t\treturn in.sval; \n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f776afa1b4ef4b1d22e4388eaac19c83", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "/*\r\n Goal: Become better in CP!\r\n Key: Consistency and Discipline\r\n Desire: SDE @ Google USA\r\n Motto: Do what i Love <=> Love what i do\r\n If you don't use your brain 100%, it deteriorates gradually\r\n*/\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Code {\r\n\r\n static StringBuffer str=new StringBuffer();\r\n static BufferedReader bf;\r\n static PrintWriter pw;\r\n static long n;\r\n\r\n static void solve(int te) throws Exception{\r\n if(n==1) return 3;\r\n return 4 + (4*n-3)/3;\r\n }\r\n \r\n public static void main(String[] args) throws java.lang.Exception {\r\n boolean lenv=false;\r\n if(lenv){\r\n bf = new BufferedReader(\r\n new FileReader(\"input.txt\"));\r\n pw=new PrintWriter(new\r\n BufferedWriter(new FileWriter(\"output.txt\")));\r\n }else{\r\n bf = new BufferedReader(new InputStreamReader(System.in));\r\n pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n }\r\n \r\n // int q1 = Integer.parseInt(bf.readLine().trim());\r\n // for(int te=1;te<=q1;te++) {\r\n // String s[]=bf.readLine().trim().split(\"\\\\s+\");\r\n n=Long.parseLong(bf.readLine().trim());\r\n solve(1);\r\n // }\r\n pw.print(str);\r\n pw.flush();\r\n // System.out.println(str);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ef22e78a0b8babea6ed3f11d0be29c6d", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "\r\nimport java.io.BufferedOutputStream;\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.io.PrintWriter;\r\nimport java.util.ArrayList;\r\nimport java.util.Arrays;\r\nimport java.util.Collections;\r\nimport java.util.HashMap;\r\nimport java.util.StringTokenizer;\r\nimport java.util.function.Supplier;\r\nimport java.util.stream.Collectors;\r\n\r\npublic class cf {\r\n\r\n\t//-----------PrintWriter for faster output---------------------------------\r\n public static PrintWriter out;\r\n public static int cnt;\r\n //-----------MyScanner class for faster input----------\r\n public 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 int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n \r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n \r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n \r\n String nextLine(){\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n\t }\r\n \r\n static boolean isPrime(int n)\r\n{\r\n // Corner cases\r\n if (n <= 1)\r\n return false;\r\n if (n <= 3)\r\n return true;\r\n\r\n // This is checked so that we can skip\r\n // middle five numbers in below loop\r\n if (n % 2 == 0 || n % 3 == 0)\r\n return false;\r\n\r\n for (int i = 5; i * i <= n; i = i + 6)\r\n if (n % i == 0 || n % (i + 2) == 0)\r\n return false;\r\n\r\n return true;\r\n}\r\n public static int reverseBits(int n)\r\n {\r\n int rev = 0;\r\n \r\n // traversing bits of 'n'\r\n // from the right\r\n while (n > 0)\r\n {\r\n // bitwise left shift\r\n // 'rev' by 1\r\n rev <<= 1;\r\n \r\n // if current bit is '1'\r\n if ((int)(n & 1) == 1)\r\n rev ^= 1;\r\n \r\n // bitwise right shift\r\n //'n' by 1\r\n n >>= 1;\r\n }\r\n // required number\r\n return rev;\r\n }\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\t\r\n\t\tMyScanner sc = new MyScanner();\r\n out = new PrintWriter(new BufferedOutputStream(System.out));\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\tint t=sc.nextInt();\r\n//\t\twhile(t-->0)\r\n//\t\t{\r\n//\t\t\tint n=sc.nextInt();\r\n//\t\t\tArrayList x1=new ArrayList();\r\n//\t\t\tArrayList x2=new ArrayList();\r\n//\t\r\n//\t\t\tArrayList x3=new ArrayList();\r\n//\t\t\tfor(int i=0;i=0)\r\n//\t\t\t\t{\r\n//\t\t\t\t\tl++;\r\n//\t\t\t\t\tr--;\r\n//\t\t\t\t\tans++;\r\n//\t\t\t\t}\r\n//\t\t\t\telse\r\n//\t\t\t\t{\r\n//\t\t\t\t\tl++;\r\n//\t\t\t\t}\r\n//\t\t\t}\r\n//\t\t\tout.println(ans);\r\n//\t\t}\r\n\t\tArrayList x=new ArrayList();\r\n\t\tx.add((long) 3);\r\n\t\tx.add((long) 5);\r\n\t\tlong k=5;\r\n\t\tk=k+2;\r\n\t\twhile(x.size()<=t)\r\n\t\t{\r\n\t\t\tx.add(k);\r\n\t\t\tx.add(k+1);\r\n\t\t\tx.add(k+2);\r\n\t\t\tk=k+4;\r\n\t\t}\r\n\t\tCollections.sort(x);\r\n\t\tout.println(x.get(t-1));\r\n\t\tout.close();\r\n\t}\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f29a9e249e599842531f42ef3bf37703", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "/*\r\n Goal: Become better in CP!\r\n Key: Consistency and Discipline\r\n Desire: SDE @ Google USA\r\n Motto: Do what i Love <=> Love what i do\r\n If you don't use your brain 100%, it deteriorates gradually\r\n*/\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Code {\r\n\r\n static StringBuffer str=new StringBuffer();\r\n static BufferedReader bf;\r\n static PrintWriter pw;\r\n static long n;\r\n static long d;\r\n static long p[];\r\n\r\n static void solve(int te) throws Exception{\r\n long l=3;\r\n long r=n*2+2;\r\n long cnt=r/4-1;\r\n while(cnt>0 && r>=3){\r\n if(r%2==1 || (r%4==0 && r!=4)) cnt--;\r\n r--;\r\n }\r\n while(r>3 && (r%2==0 && (r%4!=0 || r==4))) r--;\r\n str.append(r).append(\"\\n\");\r\n }\r\n \r\n public static void main(String[] args) throws java.lang.Exception {\r\n boolean lenv=false;\r\n if(lenv){\r\n bf = new BufferedReader(\r\n new FileReader(\"input.txt\"));\r\n pw=new PrintWriter(new\r\n BufferedWriter(new FileWriter(\"output.txt\")));\r\n }else{\r\n bf = new BufferedReader(new InputStreamReader(System.in));\r\n pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n }\r\n \r\n // int q1 = Integer.parseInt(bf.readLine().trim());\r\n // for(int te=1;te<=q1;te++) {\r\n // String s[]=bf.readLine().trim().split(\"\\\\s+\");\r\n n=Long.parseLong(bf.readLine().trim());\r\n // d=Long.parseLong(s[1]);\r\n // p=new long[n];\r\n // s=bf.readLine().trim().split(\"\\\\s+\");\r\n // for(int i=0;i inp, int n, int target){\n Collections.sort(inp);\n Collections.reverse(inp);\n int res = 0;\n int num = n;\n for(int i = 0;i0;i++){\n int curr = inp.get(i);\n int times = target/curr;\n if(target%curr != 0)\n times++;\n if(times*curr<=target)\n times++;\n if(times>num)\n return res;\n num = num-times;\n res++;\n }\n return res;\n }\n\n public static void main(String args[]) throws java.lang.Exception{\n Scanner in;\n try{\n in = new Scanner(new FileReader(\"./input.txt\"));\n }\n catch(Exception e){\n in = new Scanner(System.in);\n }\n int n = in.nextInt();\n\n long st = 3;\n if(n == 1){\n System.out.println(3);\n return;\n }\n int t = 0;\n int flag = 0;\n for(int i = 2;i<=n;i++){\n if(flag == 1){\n st++;\n flag = 0;\n t++;\n }\n else if(t<2){\n st = st+2;\n t++;\n }\n else{\n st++;\n t = 0;\n flag = 1;\n }\n //System.out.println(i+\" \"+st);\n }\n System.out.println(st);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c5e36b37cfc0129a19b50ad1eabbe922", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e", "difficulty": 1500.0} {"lang": "Java 11", "source_code": "// package c1749;\n\n//\n// Educational Codeforces Round 138 (Rated for Div. 2) 2022-10-20 07:35\n// D. Counting Arrays\n// https://codeforces.com/contest/1749/problem/D\n// time limit per test 2 seconds; memory limit per test 512 megabytes\n// public class Pseudo for 'Source should satisfy regex [^{}]*public\\s+(final)?\\s*class\\s+(\\w+).*'\n//\n// Consider an array a of length n with elements numbered from 1 to n. It is possible to remove the\n// i-th element of a if gcd(a_i, i) = 1, where gcd denotes the greatest common divisor. After an\n// element is removed, the elements to the right are shifted to the left by one position.\n//\n// An array b with n integers such that 1 <= b_i <= n - i + 1 is a if it is possible to remove all\n// elements of a, if you remove the b_1-th element, then the b_2-th, ..., then the b_n-th element.\n// For example, let a = [42, 314]:\n// * [1, 1] is a removal sequence: when you remove the 1-st element of the array, the condition\n// gcd(42, 1) = 1 holds, and the array becomes [314]; when you remove the 1-st element again, the\n// condition gcd(314, 1) = 1 holds, and the array becomes empty.\n// * [2, 1] is not a removal sequence: when you try to remove the 2-nd element, the condition\n// gcd(314, 2) = 1 is false.\n//\n// An array is if it has removal sequences. For example, the array [1, 2, 5] is ambiguous: it has\n// removal sequences [3, 1, 1] and [1, 2, 1]. The array [42, 314] is not ambiguous: the only removal\n// sequence it has is [1, 1].\n//\n// You are given two integers n and m. You have to calculate the number of arrays a such that the\n// length of a is from 1 to n and each a_i is an integer from 1 to m.\n//\n// Input\n//\n// The only line of the input contains two integers n and m (2 <= n <= 3 * 10^5; 1 <= m <= 10^{12}).\n//\n// Output\n//\n// Print one integer -- the number of ambiguous arrays a such that the length of a is from 1 to n\n// and each a_i is an integer from 1 to m. Since the answer can be very large, print it modulo\n// 998244353.\n//\n// Example\n/*\ninput:\n2 3\noutput:\n6\n\ninput:\n4 2\noutput:\n26\n\ninput:\n4 6\noutput:\n1494\n\ninput:\n1337 424242424242\noutput:\n119112628\n*/\n//\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.InputStreamReader;\nimport java.lang.invoke.MethodHandles;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Random;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class C1749D {\n static final int MOD = 998244353;\n static final Random RAND = new Random();\n\n static int solve(int n, long m) {\n List[] primes = getPrimeFactors(n);\n long[][] dp = new long[16][n];\n // exc[j] is number of v for j-th term such that v is multiple of (j+1) (should be excluded)\n long[][] exc = new long[16][n];\n\n // pre[j] is multiple of prefixes of exc[j]\n long[][] pre = new long[16][n];\n\n // qua[j] is count of arrays in [0,j] such that at least one of v_j is NOT multiple of (j+1)\n long[][] qua = new long[16][n];\n\n int e = 0;\n for (int i = 0; i < 16; i++) {\n long total = 1;\n for (int j = 0; j < n; j++) {\n long v = (i == 0 ? m : exc[i-1][j]) % MOD;\n total = total * v % MOD;\n exc[i][j] = getNonCoprimeCount(j + 1, i + 1, m, primes);\n pre[i][j] = exc[i][j] * (j == 0 ? 1 : pre[i][j-1]) % MOD;\n qua[i][j] = (total + MOD - pre[i][j]) % MOD;\n }\n if (test) {\n System.out.format(\" i:%2d exc: %s\\n\", i, Arrays.toString(exc[i]));\n System.out.format(\" i:%2d pre: %s\\n\", i, Arrays.toString(pre[i]));\n System.out.format(\" i:%2d qua: %s\\n\", i, Arrays.toString(qua[i]));\n }\n if (pre[i][n-1] == 0 || i + 1 == n) {\n e = i;\n break;\n }\n }\n\n long x0 = 0;\n for (int i = e; i >= 0; i--) {\n for (int j = 1; j < n; j++) {\n dp[i][j] = (qua[i][j] + (i == 15 || j == 0 ? 0 : dp[i+1][j] % MOD)) % MOD;\n }\n if (test) {\n System.out.format(\" i:%2d dp: %s\\n\", i, Arrays.toString(dp[i]));\n }\n }\n long ans = 0;\n for (int i = 0; i < n; i++) {\n ans = (ans + dp[0][i]) % MOD;\n }\n return (int) ans;\n }\n\n static long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n // Get number of values w in [1,m] such that:\n // gcd(w, v) != 1\n // gcd(w, v-1) != 1\n // ...\n // gcd(w, v-k+1) != 1\n static long getNonCoprimeCount(int v, int k, long m, List[] primes) {\n // System.out.format(\" v:%d k:%d m:%d\\n\", v, k, m);\n if (v == 1) {\n return m % MOD;\n }\n k = Math.min(v - 1, k);\n List> pa = new ArrayList<>();\n for (int w = v; w > v - k; w--) {\n pa.add(primes[w]);\n }\n // collect all combinations. An example of n = 100, k = 4\n // v: 2 5\n // v-1: 3 11\n // v-2: 2 7\n // v-3: 97\n // we have following 8 combinations:\n // (2,3,97) (2,3,7,97) (2,11,97) (2,11,7,97) (5,3,2,97) (5,3,7,97) (5,11,2,97) (5,11,2,97)\n\n // System.out.format(\" v:%d k:%d m:%d pa:%s\\n\", v, k, m, Utils.traceListListInt(pa));\n if (pa.isEmpty() || m == 0) {\n return m % MOD;\n }\n return getCountPms(m, pa);\n }\n\n static long getCountPms(long m, List> pms) {\n List> arr = getCombinationSets(pms);\n int idx = 0;\n for (Set x : arr) {\n idx++;\n // System.out.format(\" %d : %s\\n\", idx, x.toString());\n }\n return getCountSets(m, arr);\n }\n\n static long getCountSets(long m, List> arr) {\n long ans = 0;\n if (m > 0) {\n int n = arr.size();\n long p = 1;\n for (int w : arr.get(0)) {\n p = p * w;\n }\n if (n == 1) {\n ans = (m / p) % MOD;\n } else {\n // Use PIE\n // case 1: only take the first set\n ans = (ans + m / p) % MOD;\n\n // case 2: take the first set and non-empty others\n List> brr = new ArrayList<>();\n Set st0 = arr.get(0);\n for (int i = 1; i < n; i++) {\n Set st = new HashSet<>(arr.get(i));\n st.removeAll(st0);\n if (!brr.contains(st)) {\n brr.add(st);\n }\n }\n\n ans = (ans + MOD - getCountSets(m / p, brr)) % MOD;\n // case 3: do not take the first set\n List> crr = new ArrayList<>();\n crr.addAll(arr.subList(1, n));\n ans = (ans + getCountSets(m, crr)) % MOD;\n }\n }\n // System.out.format(\" %9d <- %s %d\\n\", ans, traceListSetInt(arr), m);\n return ans;\n }\n\n static String traceListSetInt(List> arr) {\n StringBuilder sb = new StringBuilder();\n for (Set v : arr) {\n if (sb.length() > 0) {\n sb.append(',');\n }\n sb.append(v.toString().replace(\" \", \"\"));\n }\n return sb.toString();\n }\n\n static List> getCombinationSets(List> pa) {\n List> curr = new ArrayList<>();\n curr.add(new HashSet<>());\n for (List v : pa) {\n List> next = new ArrayList<>();\n for (int w : v) {\n for (Set x : curr) {\n Set y = new HashSet<>(x);\n y.add(w);\n next.add(y);\n }\n }\n curr = next;\n }\n return curr;\n }\n\n static long getCountPie(long m, List> pa) {\n List> arr = getCombinations(pa);\n int idx = 0;\n for (List x : arr) {\n idx++;\n System.out.format(\" %d : %s\\n\", idx, x.toString());\n }\n\n // Use PIE to get the result\n int n = arr.size();\n long ans = 0;\n for (int i = 1; i < (1 << n); i++) {\n int h = Integer.bitCount(i);\n Set s = new HashSet<>();\n for (int j = 0; j < n; j++) {\n if (((1 << j) & i) != 0) {\n s.addAll(arr.get(j));\n }\n }\n // System.out.format(\" i:%d s:%s\\n\", i, s.toString());\n long p = 1;\n for (int w : s) {\n p = p * w;\n }\n long ct = m / p;\n if (h % 2 == 1) {\n // positive\n ans += ct;\n } else {\n // negative\n ans -= ct;\n }\n }\n // myAssert(ans == getCountNaive(m, pa));\n return ans;\n }\n\n static long getCountNaive(long m, List> pa) {\n Set s = new HashSet<>();\n for (List p : pa) {\n s.addAll(p);\n }\n long prod = 1;\n for (int v : s) {\n prod *= v;\n }\n long k = m / prod;\n long r = m % prod;\n\n List curr = new ArrayList<>();\n for (long i = 1; i <= prod; i++) {\n curr.add(i);\n }\n for (List p : pa) {\n List next = new ArrayList<>();\n for (long w : curr) {\n for (int x : p) {\n if (w % x == 0) {\n next.add(w);\n break;\n }\n }\n }\n curr = next;\n }\n\n long ans = curr.size() * k;\n if (r > 0) {\n int b = 0;\n while (curr.get(b) <= r) {\n b++;\n }\n ans += b;\n }\n return ans;\n }\n\n static List> getCombinations(List> pa) {\n List> curr = new ArrayList<>();\n curr.add(new ArrayList<>());\n for (List v : pa) {\n List> next = new ArrayList<>();\n for (int w : v) {\n for (List x : curr) {\n List y = new ArrayList<>(x);\n y.add(w);\n dedup(y);\n next.add(y);\n }\n }\n curr = next;\n }\n return curr;\n }\n\n static void dedup(List a) {\n Collections.sort(a);\n int i = 1;\n int j = 1;\n while (j < a.size()) {\n if (a.get(j) != a.get(i-1)) {\n if (j > i) {\n a.set(i, a.get(j));\n }\n i++;\n }\n j++;\n }\n while (a.size() > i) {\n a.remove(a.size() - 1);\n }\n }\n\n static List merge(List a, List b) {\n List c = new ArrayList<>();\n c.addAll(a);\n c.addAll(b);\n Collections.sort(c);\n dedup(c);\n return c;\n }\n\n static void incubate() {\n int n = 100;\n List[] primes = getPrimeFactors(n);\n {\n long m = (long) 1e6;\n for (int k = 1; k < 10; k++) {\n for (int v = 2; v <= n; v++) {\n long ans = getNonCoprimeCount(v, k, m, primes);\n System.out.format(\" v:%4d %d -> %d\\n\", v, k, ans);\n if (ans == 0) {\n System.exit(0);\n }\n }\n }\n System.exit(0);\n }\n\n List a = new ArrayList<>(Arrays.asList(2,7,3,2));\n dedup(a);\n System.out.format(\" a:%s\\n\", a.toString());\n\n List[] arr = getPrimeFactors(n);\n for (int v = 2; v <= n; v++) {\n System.out.format(\" v:%3d %s\\n\", v, arr[v].toString());\n }\n }\n\n static List[] getPrimeFactors(int n) {\n List[] arr = new ArrayList[n+1];\n for (int i = 0; i <= n; i++) {\n arr[i] = new ArrayList<>();\n }\n boolean[] isNotPrime = new boolean[n+1];\n int p = 2;\n while (p <= n) {\n if (!isNotPrime[p]) {\n int v = p;\n do {\n isNotPrime[v] = true;\n arr[v].add(p);\n v += p;\n } while (v <= n);\n }\n p++;\n }\n return arr;\n }\n\n static boolean isAmbiguous(List nums) {\n int m = nums.size();\n if (m <= 1) {\n return false;\n }\n for (int i = 1; i < m; i++) {\n if (gcd(nums.get(i), i+1) == 1) {\n return true;\n }\n }\n return isAmbiguous(nums.subList(1, m));\n }\n\n static void test(int exp, int n, long m) {\n int ans = solve(n, m);\n System.out.format(\"%d %d => %d %s\\n\", n, m, ans, ans == exp ? \"\":\"Expected \" + exp);\n myAssert(ans == exp);\n }\n\n static boolean test = false;\n static void doTest() {\n if (!test) {\n return;\n }\n long t0 = System.currentTimeMillis();\n /*\n long m = 100000;\n List> pms = new ArrayList<>();\n pms.add(Arrays.asList(2,5));\n pms.add(Arrays.asList(3,11));\n long ans1 = getCountNaive(m, pms);\n long ans2 = getCountPie(m, pms);\n long ans3 = getCountPms(m, pms);\n System.out.format(\" ans1:%d ans2:%d ans3:%d\\n\", ans1, ans2, ans3);\n incubate();\n */\n test(1494, 4, 6);\n test(6, 2, 3);\n test(26, 4, 2);\n test(1494, 4, 6);\n test(851241741, 100, 1000000);\n\n test(119112628, 1337, 424242424242L);\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n public static void main(String[] args) {\n doTest();\n MyScanner in = new MyScanner();\n int n = in.nextInt();\n long m = in.nextLong();\n int ans = solve(n, m);\n System.out.println(ans);\n }\n\n static void output(int[] a) {\n if (a == null) {\n System.out.println(\"-1\");\n return;\n }\n StringBuilder sb = new StringBuilder();\n for (int v : a) {\n sb.append(v);\n sb.append(' ');\n if (sb.length() > 4000) {\n System.out.print(sb.toString());\n sb.setLength(0);\n }\n }\n System.out.println(sb.toString());\n }\n\n static void myAssert(boolean cond) {\n if (!cond) {\n throw new RuntimeException(\"Unexpected\");\n }\n }\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n try {\n final String USERDIR = System.getProperty(\"user.dir\");\n String cname = MethodHandles.lookup().lookupClass().getCanonicalName().replace(\".MyScanner\", \"\");\n cname = cname.lastIndexOf('.') > 0 ? cname.substring(cname.lastIndexOf('.') + 1) : cname;\n final File fin = new File(USERDIR + \"/io/c\" + cname.substring(1,5) + \"/\" + cname + \".in\");\n br = new BufferedReader(new InputStreamReader(fin.exists()\n ? new FileInputStream(fin) : System.in));\n } catch (Exception e) {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n }\n\n public String next() {\n try {\n while (st == null || !st.hasMoreElements()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n } catch (Exception 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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1a9228369dce3c3712fdacfd094abef3", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n static final Reader READER = new Reader(System.in);\r\n static final PrintWriter PRINT_WRITER = new PrintWriter(System.out, true);\r\n\r\n public static void main(String[] args) throws IOException {\r\n\r\n int MOD = 998244353;\r\n\r\n int n = READER.nextInt();\r\n long m = READER.nextLong();\r\n\r\n // \u6c42\u51fa 2-n\u4e4b\u95f4\u6240\u6709\u7d20\u6570\r\n List list = primeNumbers(n);\r\n int index = 0;\r\n // dp[0][i] \u8868\u793a\u4e0d\u53ef\u884c\u7684 \u4e14\u6570\u7ec4\u957f\u5ea6\u4e3ai\u7684\u6570\u7ec4\u6570\u91cf , dp[1][i] \u8868\u793a\u53ef\u884c\uff0c\u4e14\u957f\u5ea6\u4e3ai\u7684\u6570\u7ec4\u6570\u91cf\r\n // dp[1][i] = dp[1][i-1] * m + dp[0][i-1] * (m\u91cc\u9762\u53ef\u884c\u7684\u6570\u5b57)\r\n // dp[0][i] = dp[0][i-1] * (m\u91cc\u9762\u4e0d\u53ef\u884c\u7684\u6570\u5b57)\r\n // m \u91cc\u9762\u53ef\u884c\u7684\u6570\u5b57 + m\u4e0d\u53ef\u884c\u7684\u6570\u5b57 = m\r\n long[][] dp = new long[2][n + 1];\r\n dp[0][1] = m % MOD;\r\n long bas = 1;\r\n for (int i = 2; i <= n; i++) {\r\n // \u524d\u9762\u4f4d\u7f6e\u53ef\u4ee5\u9009\u62e9\u7684\u6570\u5b57\u662fbase\u4e2a\r\n if (index < list.size() && list.get(index) == i) {\r\n bas *= list.get(index++);\r\n }\r\n // \u8ba1\u7b97m\u91cc\u9762\u53ef\u4ee5\u4e0d\u88ab\u8fd9\u4e9b\u56e0\u5b50\u6574\u9664\u7684\u6570\u5b57\r\n long divCount = m / bas; // \u80fd\u88ab\u6574\u9664\u7684\u6570\u5b57\r\n long noDivCount = m - divCount;\r\n dp[0][i] = (dp[0][i - 1] * (divCount % MOD)) % MOD;\r\n dp[1][i] = (dp[1][i - 1] * (m % MOD)) % MOD + (dp[0][i - 1] * (noDivCount % MOD)) % MOD;\r\n dp[1][i] %= MOD;\r\n }\r\n\r\n long res = 0;\r\n for (int i = 2; i <=n ; i++) {\r\n res += dp[1][i];\r\n res %= MOD;\r\n }\r\n\r\n PRINT_WRITER.println(res);\r\n\r\n }\r\n\r\n public static List primeNumbers(int number) {\r\n List res = new ArrayList<>();\r\n boolean[] map = new boolean[number + 1];\r\n for (int i = 2; i <= number; i++) {\r\n if (!map[i]) {\r\n res.add(i);\r\n }\r\n for (Integer re : res) {\r\n if (re <= number / i) {\r\n map[re * i] = true;\r\n }\r\n if (i % re == 0) {\r\n break;\r\n }\r\n }\r\n }\r\n return res;\r\n }\r\n\r\n\r\n static class Reader {\r\n private final BufferedReader reader;\r\n private StringTokenizer tokenizer;\r\n\r\n public Reader(InputStream inputStream) {\r\n this.reader = new BufferedReader(new InputStreamReader(inputStream));\r\n this.tokenizer = new StringTokenizer(\"\");\r\n }\r\n\r\n public String next() throws IOException {\r\n while (!tokenizer.hasMoreTokens()) {\r\n tokenizer = new StringTokenizer(reader.readLine());\r\n }\r\n return tokenizer.nextToken();\r\n }\r\n\r\n public int nextInt() throws IOException {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public long nextLong() throws IOException {\r\n return Long.parseLong(next());\r\n }\r\n\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d770d360ca9862aedd9af694ad36cef", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n static final Reader READER = new Reader(System.in);\r\n static final PrintWriter PRINT_WRITER = new PrintWriter(System.out, true);\r\n\r\n public static void main(String[] args) throws IOException {\r\n\r\n int MOD = 998244353;\r\n\r\n int n = READER.nextInt();\r\n long m = READER.nextLong();\r\n\r\n // \u6c42\u51fa 2-n\u4e4b\u95f4\u6240\u6709\u7d20\u6570\r\n\r\n // dp[0][i] \u8868\u793a\u4e0d\u53ef\u884c\u7684 \u4e14\u6570\u7ec4\u957f\u5ea6\u4e3ai\u7684\u6570\u7ec4\u6570\u91cf , dp[1][i] \u8868\u793a\u53ef\u884c\uff0c\u4e14\u957f\u5ea6\u4e3ai\u7684\u6570\u7ec4\u6570\u91cf\r\n // dp[1][i] = dp[1][i-1] * m + dp[0][i-1] * (m\u91cc\u9762\u53ef\u884c\u7684\u6570\u5b57)\r\n // dp[0][i] = dp[0][i-1] * (m\u91cc\u9762\u4e0d\u53ef\u884c\u7684\u6570\u5b57)\r\n // m \u91cc\u9762\u53ef\u884c\u7684\u6570\u5b57 + m\u4e0d\u53ef\u884c\u7684\u6570\u5b57 = m\r\n boolean[] map = new boolean[n + 1];\r\n List facList = new ArrayList<>();\r\n\r\n long[][] dp = new long[2][n + 1];\r\n dp[0][1] = m % MOD;\r\n long bas = 1;\r\n for (int i = 2; i <= n; i++) {\r\n // \u524d\u9762\u4f4d\u7f6e\u53ef\u4ee5\u9009\u62e9\u7684\u6570\u5b57\u662fbase\u4e2a\r\n if (!map[i]){\r\n facList.add(i);\r\n bas *= i;\r\n }\r\n for (int re : facList) {\r\n if (re <= n / i) {\r\n map[re * i] = true;\r\n }\r\n if (i % re == 0) {\r\n break;\r\n }\r\n }\r\n\r\n // \u8ba1\u7b97m\u91cc\u9762\u53ef\u4ee5\u4e0d\u88ab\u8fd9\u4e9b\u56e0\u5b50\u6574\u9664\u7684\u6570\u5b57\r\n long divCount = m / bas; // \u80fd\u88ab\u6574\u9664\u7684\u6570\u5b57\r\n long noDivCount = m - divCount;\r\n dp[0][i] = (dp[0][i - 1] * (divCount % MOD)) % MOD;\r\n dp[1][i] = (dp[1][i - 1] * (m % MOD)) % MOD + (dp[0][i - 1] * (noDivCount % MOD)) % MOD;\r\n dp[1][i] %= MOD;\r\n }\r\n\r\n long res = 0;\r\n for (int i = 2; i <=n ; i++) {\r\n res += dp[1][i];\r\n res %= MOD;\r\n }\r\n\r\n PRINT_WRITER.println(res);\r\n\r\n }\r\n\r\n// public static List primeNumbers(int number) {\r\n// List res = new ArrayList<>();\r\n// boolean[] map = new boolean[number + 1];\r\n// for (int i = 2; i <= number; i++) {\r\n// if (!map[i]) {\r\n// res.add(i);\r\n// }\r\n// for (Integer re : res) {\r\n// if (re <= number / i) {\r\n// map[re * i] = true;\r\n// }\r\n// if (i % re == 0) {\r\n// break;\r\n// }\r\n// }\r\n// }\r\n// return res;\r\n// }\r\n\r\n\r\n static class Reader {\r\n private final BufferedReader reader;\r\n private StringTokenizer tokenizer;\r\n\r\n public Reader(InputStream inputStream) {\r\n this.reader = new BufferedReader(new InputStreamReader(inputStream));\r\n this.tokenizer = new StringTokenizer(\"\");\r\n }\r\n\r\n public String next() throws IOException {\r\n while (!tokenizer.hasMoreTokens()) {\r\n tokenizer = new StringTokenizer(reader.readLine());\r\n }\r\n return tokenizer.nextToken();\r\n }\r\n\r\n public int nextInt() throws IOException {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public long nextLong() throws IOException {\r\n return Long.parseLong(next());\r\n }\r\n\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a82de753c3fba8e146c87193e5bc683c", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0} {"lang": "Java 17", "source_code": "import java.io.*;\r\nimport java.util.InputMismatchException;\r\n\r\npublic class D {\r\n\r\n static long MOD = 998244353l;\r\n\r\n public static void main(String[] args) {\r\n FastIO io = new FastIO();\r\n long n = io.nextLong();\r\n long m = io.nextLong();\r\n long sum = 0;\r\n for (long i = 1; long <= n; i++) sum = (sum + binpow(m, i, MOD)) % MOD;\r\n\r\n\r\n long[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};\r\n\r\n int p = 0;\r\n long cur = 1;\r\n long seq = 1;\r\n long ans = 0;\r\n for (int i = 1; i <= 37; i++) {\r\n\r\n if (i == primes[p]) seq = 1l * seq * primes[p++];\r\n\r\n long local = (m / seq) % MOD;\r\n\r\n\r\n cur = (1l * local * cur) % MOD;\r\n ans = (ans + cur) % MOD;\r\n }\r\n\r\n\r\n io.println((sum - ans + MOD + MOD + MOD + MOD) % MOD);\r\n io.close();\r\n }\r\n\r\n public static long binpow(long x, long n, long m) {\r\n //inverse modulo= binpow(2, MOD - 2, MOD);\r\n assert (n >= 0);\r\n x %= m; // note: m * m must be less than 2^63 to avoid ll overflow\r\n long res = 1;\r\n while (n > 0) {\r\n if (n % 2 == 1) // if n is odd\r\n res = res * x % m;\r\n x = x * x % m;\r\n n /= 2; // divide by two\r\n }\r\n return res;\r\n }\r\n\r\n\r\n private static class FastIO extends PrintWriter {\r\n private final InputStream stream;\r\n private final byte[] buf = new byte[1 << 16];\r\n private int curChar, numChars;\r\n\r\n // standard input\r\n public FastIO() {\r\n this(System.in, System.out);\r\n }\r\n\r\n public FastIO(InputStream i, OutputStream o) {\r\n super(o);\r\n stream = i;\r\n }\r\n\r\n // file input\r\n public FastIO(String i, String o) throws IOException {\r\n super(new FileWriter(o));\r\n stream = new FileInputStream(i);\r\n }\r\n\r\n // throws InputMismatchException() if previously detected end of file\r\n private int nextByte() {\r\n if (numChars == -1) throw new InputMismatchException();\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 == -1) return -1; // end of file\r\n }\r\n return buf[curChar++];\r\n }\r\n\r\n // to read in entire lines, replace c <= ' '\r\n // with a function that checks whether c is a line break\r\n public String next() {\r\n int c;\r\n do {\r\n c = nextByte();\r\n } while (c <= ' ');\r\n StringBuilder res = new StringBuilder();\r\n do {\r\n res.appendCodePoint(c);\r\n c = nextByte();\r\n } while (c > ' ');\r\n return res.toString();\r\n }\r\n\r\n public int nextInt() { // nextLong() would be implemented similarly\r\n int c;\r\n do {\r\n c = nextByte();\r\n } while (c <= ' ');\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = nextByte();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res = 10 * res + c - '0';\r\n c = nextByte();\r\n } while (c > ' ');\r\n return res * sgn;\r\n }\r\n\r\n public long nextLong() { // nextLong() would be implemented similarly\r\n int c;\r\n do {\r\n c = nextByte();\r\n } while (c <= ' ');\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = nextByte();\r\n }\r\n long res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res = 10 * res + c - '0';\r\n c = nextByte();\r\n } while (c > ' ');\r\n return res * sgn;\r\n }\r\n\r\n public double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e7f3247d52a0079d96fa07a8930d81e4", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class D30 {\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tint n = input.nextInt(), k = input.nextInt() - 1;\n\tPoint[] data = new Point[n+1];\n\tint[] xs = new int[n];\n\tfor(int i = 0; i max) {\n\t\t\t\tmax = x[i];\n\t\t\t\tmaxIndex = i;\n\t\t\t}\n\t\t}\n\t\tInteger[] o = new Integer[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\to[i] = i;\n\t\tArrays.sort(o, new Comparator() {\n\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\treturn x[o1] - x[o2];\n\t\t\t}\n\t\t});\n\t\tint[] oo = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\too[o[i]] = i;\n\t\tif (k == n + 1)\n\t\t\tans = x[maxIndex] - x[minIndex] + Math.min(Math.hypot(x[n] - x[minIndex], y), Math.hypot(x[n] - x[maxIndex], y));\n\t\telse {\n\t\t\tint start = oo[k - 1];\n\t\t\tArrays.sort(x, 0, n);\n\t\t\tans = x[start] - x[0] + x[n - 1] - x[0] + Math.hypot(x[n - 1] - x[n], y);\n\t\t\tint cur = start;\n\t\t\twhile (cur != n - 1) {\n\t\t\t\tint next;\n\t\t\t\tif (cur == 0)\n\t\t\t\t\tnext = start + 1;\n\t\t\t\telse if (cur <= start)\n\t\t\t\t\tnext = cur - 1;\n\t\t\t\telse\n\t\t\t\t\tnext = cur + 1;\n\t\t\t\tdouble v1;\n\t\t\t\tif (cur <= start)\n\t\t\t\t\tv1 = x[start] - x[cur];\n\t\t\t\telse\n\t\t\t\t\tv1 = x[start] - x[0] + x[cur] - x[0];\n\t\t\t\tdouble v2;\n\t\t\t\tif (next <= start)\n\t\t\t\t\tv2 = x[next] - x[0] + x[n - 1] - x[0];\n\t\t\t\telse\n\t\t\t\t\tv2 = x[n - 1] - x[next];\n\t\t\t\tans = Math.min(ans, v1 + v2 + Math.hypot(x[cur] - x[n], y) + Math.hypot(x[next] - x[n], y));\n\t\t\t\tcur = next;\n\t\t\t}\n\t\t\tcur = start;\n\t\t\tans = Math.min(ans, x[n - 1] - x[start] + x[n - 1] - x[0] + Math.hypot(x[0] - x[n], y));\n\t\t\tans = Math.min(ans, x[n - 1] - x[0] + Math.hypot(x[start] - x[n], y) + Math.min(Math.hypot(x[n] - x[0], y), Math.hypot(x[n] - x[n - 1], y)));\n\t\t\twhile (cur != 0) {\n\t\t\t\tint next;\n\t\t\t\tif (cur == n - 1)\n\t\t\t\t\tnext = start - 1;\n\t\t\t\telse if (cur >= start)\n\t\t\t\t\tnext = cur + 1;\n\t\t\t\telse\n\t\t\t\t\tnext = cur - 1;\n\t\t\t\tdouble v1;\n\t\t\t\tif (cur >= start)\n\t\t\t\t\tv1 = x[cur] - x[start];\n\t\t\t\telse\n\t\t\t\t\tv1 = x[n - 1] - x[start] + x[n - 1] - x[cur];\n\t\t\t\tdouble v2;\n\t\t\t\tif (next >= start)\n\t\t\t\t\tv2 = x[n - 1] - x[next] + x[n - 1] - x[0];\n\t\t\t\telse\n\t\t\t\t\tv2 = x[next] - x[0];\n\t\t\t\tans = Math.min(ans, v1 + v2 + Math.hypot(x[cur] - x[n], y) + Math.hypot(x[next] - x[n], y));\n\t\t\t\tcur = next;\n\t\t\t}\n\t\t}\n\t\tout.printf(\"%.8f\\n\", ans);\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9') {\n\t\t\t\t\tif (c == 'e' || c == 'E') {\n\t\t\t\t\t\tint e = readInt();\n\t\t\t\t\t\treturn res * Math.pow(10, e);\n\t\t\t\t\t}\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c == 'e' || c == 'E') {\n\t\t\t\t\t\tint e = readInt();\n\t\t\t\t\t\treturn res * Math.pow(10, e);\n\t\t\t\t\t}\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4de11c7956b5b04b3d08f82387f297ea", "src_uid": "f9ed5faca211e654d9d4e0a7557616f4", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class P030D {\n private long[] pos;\n private long cx;\n private long cy;\n private final int N;\n \n private double distToC(int i) {\n long dx = cx - pos[i];\n return Math.sqrt(dx*dx + cy*cy);\n }\n \n private double distBetween(int i, int j) {\n return (double)Math.abs(pos[i] - pos[j]);\n }\n \n private double solveC(int i, int j) {\n double d1 = distToC(i);\n double d2 = distToC(j);\n return Math.min(d1, d2) + distBetween(i, j);\n }\n \n private double solveMiddle(int i) {\n assert 0 < i && i < N-1;\n double d1 = distToC(i) + solveC(0, N-1);\n double d2 = distBetween(0, i) + distToC(0) + solveC(i+1, N-1);\n double d3 = distBetween(i, N-1) + distToC(N-1) + solveC(0, i-1);\n return min3(d1, d2, d3);\n }\n \n private double solveLeftEnd() {\n double result = Double.MAX_VALUE;\n for (int i = 0; i < N-1; i++) {\n double d = distBetween(0, i) + distToC(i) + solveC(i+1, N-1);\n result = Math.min(result, d);\n }\n // last one\n double d = distBetween(0, N-1) + distToC(N-1);\n result = Math.min(result, d);\n \n return result;\n }\n \n private double solveRightEnd() {\n double result = Double.MAX_VALUE;\n for (int i = N-1; i > 0; i--) {\n double d = distBetween(i, N-1) + distToC(i) + solveC(0, i-1);\n result = Math.min(result, d);\n }\n double d = distBetween(0, N-1) + distToC(0);\n result = Math.min(result, d);\n \n return result;\n }\n \n private double min3(double x1, double x2, double x3) {\n return Math.min(Math.min(x1, x2), x3);\n }\n \n private double solve(int k) {\n if (k == N) {\n Arrays.sort(pos);\n return solveC(0, N-1);\n }\n\n long xk = pos[k];\n int k2 = -1;\n Arrays.sort(pos);\n\n for (int i = 0; i < pos.length; i++) {\n if (pos[i] == xk) {\n k2 = i;\n break;\n }\n }\n\n if (k2 == 0) {\n return solveLeftEnd();\n }\n else if (k2 == N-1) {\n return solveRightEnd();\n }\n else {\n return solveMiddle(k2);\n }\n }\n \n public P030D() {\n Scanner sc = new Scanner(System.in);\n N = sc.nextInt();\n int k = sc.nextInt() - 1;\n pos = new long[N];\n for (int i = 0; i < N; i++) {\n pos[i] = sc.nextInt();\n }\n cx = sc.nextInt();\n cy = sc.nextInt();\n \n double result = solve(k);\n System.out.printf(\"%.10f\\n\", result);\n }\n \n public static void main(String[] args) {\n P030D solution = new P030D();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f77e3f79d98c387076c94ef424c7795", "src_uid": "f9ed5faca211e654d9d4e0a7557616f4", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n public static void main(String[] args) throws IOException\n {\n Reader in = new Reader();\n int n = in.nextInt();\n int m = in.nextInt();\n NumberTheory numberTheory = new NumberTheory();\n long M = 998244353L;\n long[] fact = new long[m + 1];\n fact[0] = 1L;\n for (int i=1;i<=m;i++)\n fact[i] = (fact[i - 1] * i * 1L) % M;\n long ans = 0L;\n long xx1 = calc(m, n - 1, fact, M, numberTheory);\n for (int i=2;i<=n - 1;i++)\n {\n long sm = calc(n - 2, i - 1, fact, M, numberTheory);\n sm *= 1L * (i - 1);\n sm %= M;\n ans = (ans + sm) % M;\n }\n System.out.println((ans * xx1) % M);\n }\n public static long calc(int n, int r, long[] fact, long M, NumberTheory numberTheory)\n {\n long num = fact[n];\n long den = (fact[n - r] * fact[r]) % M;\n long inv = (numberTheory.extendedEuclid(den, M).x + M) % M;\n long xx = (num * inv) % M;\n return xx;\n }\n}\n\nclass DSU\n{\n int[] parent;\n int[] size;\n //Pass number of total nodes as parameter to the constructor\n DSU(int n)\n {\n this.parent = new int[n];\n this.size = new int[n];\n Arrays.fill(parent, -1);\n }\n\n public void makeSet(int v)\n {\n parent[v] = v;\n size[v] = 1;\n }\n\n public int findSet(int v)\n {\n if (v == parent[v]) return v;\n return parent[v] = findSet(parent[v]);\n }\n\n public void unionSets(int a, int b)\n {\n a = findSet(a);\n b = findSet(b);\n if (a != b)\n {\n if (size[a] < size[b])\n {\n int temp = a;\n a = b;\n b = temp;\n }\n parent[b] = a;\n size[a] += size[b];\n }\n }\n}\nclass FastFourierTransform\n{\n private void fft(double[] a, double[] b, boolean invert)\n {\n int count = a.length;\n for (int i = 1, j = 0; i < count; i++)\n {\n int bit = count >> 1;\n for (; j >= bit; bit >>= 1)\n j -= bit;\n j += bit;\n if (i < j)\n {\n double temp = a[i];\n a[i] = a[j];\n a[j] = temp;\n temp = b[i];\n b[i] = b[j];\n b[j] = temp;\n }\n }\n for (int len = 2; len <= count; len <<= 1)\n {\n int halfLen = len >> 1;\n double angle = 2 * Math.PI / len;\n if (invert)\n angle = -angle;\n double wLenA = Math.cos(angle);\n double wLenB = Math.sin(angle);\n for (int i = 0; i < count; i += len)\n {\n double wA = 1;\n double wB = 0;\n for (int j = 0; j < halfLen; j++)\n {\n double uA = a[i + j];\n double uB = b[i + j];\n double vA = a[i + j + halfLen] * wA - b[i + j + halfLen] * wB;\n double vB = a[i + j + halfLen] * wB + b[i + j + halfLen] * wA;\n a[i + j] = uA + vA;\n b[i + j] = uB + vB;\n a[i + j + halfLen] = uA - vA;\n b[i + j + halfLen] = uB - vB;\n double nextWA = wA * wLenA - wB * wLenB;\n wB = wA * wLenB + wB * wLenA;\n wA = nextWA;\n }\n }\n }\n if (invert)\n {\n for (int i = 0; i < count; i++)\n {\n a[i] /= count;\n b[i] /= count;\n }\n }\n }\n\n public long[] multiply(long[] a, long[] b)\n {\n int resultSize = Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2;\n resultSize = Math.max(resultSize, 1);\n double[] aReal = new double[resultSize];\n double[] aImaginary = new double[resultSize];\n double[] bReal = new double[resultSize];\n double[] bImaginary = new double[resultSize];\n for (int i = 0; i < a.length; i++)\n aReal[i] = a[i];\n for (int i = 0; i < b.length; i++)\n bReal[i] = b[i];\n fft(aReal, aImaginary, false);\n fft(bReal, bImaginary, false);\n for (int i = 0; i < resultSize; i++)\n {\n double real = aReal[i] * bReal[i] - aImaginary[i] * bImaginary[i];\n aImaginary[i] = aImaginary[i] * bReal[i] + bImaginary[i] * aReal[i];\n aReal[i] = real;\n }\n fft(aReal, aImaginary, true);\n long[] result = new long[resultSize];\n for (int i = 0; i < resultSize; i++)\n result[i] = Math.round(aReal[i]);\n return result;\n }\n}\nclass NumberTheory\n{\n public boolean isPrime(long n)\n {\n if(n < 2)\n return false;\n for(long x = 2;x * x <= n;x++)\n {\n if(n % x == 0)\n return false;\n }\n return true;\n }\n public ArrayList primeFactorisation(long n)\n {\n ArrayList f = new ArrayList<>();\n for(long x=2;x * x <= n;x++)\n {\n while(n % x == 0)\n {\n f.add(x);\n n /= x;\n }\n }\n if(n > 1)\n f.add(n);\n return f;\n }\n public int[] sieveOfEratosthenes(int n)\n {\n //Returns an array with the smallest prime factor for each number and primes marked as 0\n int[] sieve = new int[n + 1];\n for(int x=2;x * x <= n;x++)\n {\n if(sieve[x] != 0)\n continue;\n for(int u=x*x;u<=n;u+=x)\n {\n if(sieve[u] == 0)\n {\n sieve[u] = x;\n }\n }\n }\n return sieve;\n }\n public long gcd(long a, long b)\n {\n if(b == 0)\n return a;\n return gcd(b, a % b);\n }\n public long phi(long n)\n {\n double result = n;\n\n for(long p=2;p*p<=n;p++)\n {\n if(n % p == 0)\n {\n while (n % p == 0)\n n /= p;\n result *= (1.0 - (1.0 / (double)p));\n }\n }\n if(n > 1)\n result *= (1.0 - (1.0 / (double)n));\n return (long)result;\n }\n public Name extendedEuclid(long a, long b)\n {\n if(b == 0)\n return new Name(a, 1, 0);\n Name n1 = extendedEuclid(b, a % b);\n Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y);\n return n2;\n }\n public long modularExponentiation(long a, long b, long n)\n {\n long d = 1L;\n String bString = Long.toBinaryString(b);\n for(int i=0;i= 0; --i) sa[--c[T[i]]] = i;\n for (p = 1; p < N; p <<= 1)\n {\n for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i;\n for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p;\n Arrays.fill(c, 0, ALPHABET_SZ, 0);\n for (i = 0; i < N; ++i) c[rank[i]]++;\n for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];\n for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];\n for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i)\n {\n if (!(rank[sa[i - 1]] == rank[sa[i]]\n && sa[i - 1] + p < N\n && sa[i] + p < N\n && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++;\n sa2[sa[i]] = r;\n }\n tmp = rank;\n rank = sa2;\n sa2 = tmp;\n if (r == N - 1) break;\n ALPHABET_SZ = r + 1;\n }\n }\n\n private void kasai()\n {\n lcp = new int[N];\n int[] inv = new int[N];\n for (int i = 0; i < N; i++) inv[sa[i]] = i;\n for (int i = 0, len = 0; i < N; i++)\n {\n if (inv[i] > 0)\n {\n int k = sa[inv[i] - 1];\n while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++;\n lcp[inv[i] - 1] = len;\n if (len > 0) len--;\n }\n }\n }\n}\nclass ZAlgorithm\n{\n public int[] calculateZ(char input[])\n {\n int Z[] = new int[input.length];\n int left = 0;\n int right = 0;\n for(int k = 1; k < input.length; k++) {\n if(k > right) {\n left = right = k;\n while(right < input.length && input[right] == input[right - left]) {\n right++;\n }\n Z[k] = right - left;\n right--;\n } else {\n //we are operating inside box\n int k1 = k - left;\n //if value does not stretches till right bound then just copy it.\n if(Z[k1] < right - k + 1) {\n Z[k] = Z[k1];\n } else { //otherwise try to see if there are more matches.\n left = k;\n while(right < input.length && input[right] == input[right - left]) {\n right++;\n }\n Z[k] = right - left;\n right--;\n }\n }\n }\n return Z;\n }\n public ArrayList matchPattern(char text[], char pattern[])\n {\n char newString[] = new char[text.length + pattern.length + 1];\n int i = 0;\n for(char ch : pattern) {\n newString[i] = ch;\n i++;\n }\n newString[i] = '$';\n i++;\n for(char ch : text) {\n newString[i] = ch;\n i++;\n }\n ArrayList result = new ArrayList<>();\n int Z[] = calculateZ(newString);\n\n for(i = 0; i < Z.length ; i++) {\n if(Z[i] == pattern.length) {\n result.add(i - pattern.length - 1);\n }\n }\n return result;\n }\n}\nclass KMPAlgorithm\n{\n public int[] computeTemporalArray(char[] pattern)\n {\n int[] lps = new int[pattern.length];\n\n int index = 0;\n for(int i=1;i KMPMatcher(char[] text, char[] pattern)\n {\n int[] lps = computeTemporalArray(pattern);\n\n int j = 0;\n int i = 0;\n int n = text.length;\n int m = pattern.length;\n ArrayList indices = new ArrayList<>();\n while(i < n)\n {\n if(pattern[j] == text[i])\n {\n i++;\n j++;\n }\n if(j == m)\n {\n indices.add(i - j);\n j = lps[j - 1];\n }\n else if(i < n && pattern[j] != text[i])\n {\n if(j != 0)\n j = lps[j - 1];\n else\n i = i + 1;\n }\n }\n return indices;\n }\n}\nclass Hashing\n{\n public long[] computePowers(long p, int n, long m)\n {\n long[] powers = new long[n];\n powers[0] = 1;\n for(int i=1;i= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException\n {\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*/\nclass SegmentTree\n{\n public int nextPowerOfTwo(int num)\n {\n if(num == 0)\n return 1;\n if(num > 0 && (num & (num - 1)) == 0)\n return num;\n while((num &(num - 1)) > 0)\n {\n num = num & (num - 1);\n }\n return num << 1;\n }\n public int[] createSegmentTree(int[] input)\n {\n int np2 = nextPowerOfTwo(input.length);\n int[] segmentTree = new int[np2 * 2 - 1];\n\n for(int i=0;i= high){\n return segmentTree[pos];\n }\n if(qlow > high || qhigh < low){\n return Integer.MIN_VALUE;\n }\n int mid = (low+high)/2;\n return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1),\n rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2));\n }\n}\nclass Trie\n{\n\n private class TrieNode\n {\n Map children;\n boolean endOfWord;\n public TrieNode()\n {\n children = new HashMap<>();\n endOfWord = false;\n }\n }\n\n private final TrieNode root;\n public Trie()\n {\n root = new TrieNode();\n }\n\n public void insert(String word)\n {\n TrieNode current = root;\n for (int i = 0; i < word.length(); i++)\n {\n char ch = word.charAt(i);\n TrieNode node = current.children.get(ch);\n if (node == null)\n {\n node = new TrieNode();\n current.children.put(ch, node);\n }\n current = node;\n }\n current.endOfWord = true;\n }\n\n public boolean search(String word)\n {\n TrieNode current = root;\n for (int i = 0; i < word.length(); i++)\n {\n char ch = word.charAt(i);\n TrieNode node = current.children.get(ch);\n if (node == null)\n {\n return false;\n }\n current = node;\n }\n return current.endOfWord;\n }\n\n public void delete(String word)\n {\n delete(root, word, 0);\n }\n\n private boolean delete(TrieNode current, String word, int index)\n {\n if (index == word.length())\n {\n if (!current.endOfWord)\n {\n return false;\n }\n current.endOfWord = false;\n return current.children.size() == 0;\n }\n char ch = word.charAt(index);\n TrieNode node = current.children.get(ch);\n if (node == null)\n {\n return false;\n }\n boolean shouldDeleteCurrentNode = delete(node, word, index + 1);\n\n if (shouldDeleteCurrentNode)\n {\n current.children.remove(ch);\n return current.children.size() == 0;\n }\n return false;\n }\n}\nclass SegmentTreeLazy\n{\n public int nextPowerOfTwo(int num)\n {\n if(num == 0)\n return 1;\n if(num > 0 && (num & (num - 1)) == 0)\n return num;\n while((num &(num - 1)) > 0)\n {\n num = num & (num - 1);\n }\n return num << 1;\n }\n\n public int[] createSegmentTree(int input[])\n {\n int nextPowOfTwo = nextPowerOfTwo(input.length);\n int segmentTree[] = new int[nextPowOfTwo*2 -1];\n\n for(int i=0; i < segmentTree.length; i++){\n segmentTree[i] = Integer.MAX_VALUE;\n }\n constructMinSegmentTree(segmentTree, input, 0, input.length - 1, 0);\n return segmentTree;\n }\n\n private void constructMinSegmentTree(int segmentTree[], int input[], int low, int high,int pos)\n {\n if(low == high)\n {\n segmentTree[pos] = input[low];\n return;\n }\n int mid = (low + high)/2;\n constructMinSegmentTree(segmentTree, input, low, mid, 2 * pos + 1);\n constructMinSegmentTree(segmentTree, input, mid + 1, high, 2 * pos + 2);\n segmentTree[pos] = Math.min(segmentTree[2*pos+1], segmentTree[2*pos+2]);\n }\n\n public void updateSegmentTreeRangeLazy(int input[], int segmentTree[], int lazy[], int startRange, int endRange, int delta)\n {\n updateSegmentTreeRangeLazy(segmentTree, lazy, startRange, endRange, delta, 0, input.length - 1, 0);\n }\n\n private void updateSegmentTreeRangeLazy(int segmentTree[], int lazy[], int startRange, int endRange, int delta, int low, int high, int pos)\n {\n if(low > high)\n {\n return;\n }\n if (lazy[pos] != 0)\n {\n segmentTree[pos] += lazy[pos];\n if (low != high)\n {\n lazy[2 * pos + 1] += lazy[pos];\n lazy[2 * pos + 2] += lazy[pos];\n }\n lazy[pos] = 0;\n }\n\n if(startRange > high || endRange < low)\n {\n return;\n }\n\n if(startRange <= low && endRange >= high)\n {\n segmentTree[pos] += delta;\n if(low != high) {\n lazy[2*pos + 1] += delta;\n lazy[2*pos + 2] += delta;\n }\n lazy[pos] = 0;\n }\n\n int mid = (low + high)/2;\n updateSegmentTreeRangeLazy(segmentTree, lazy, startRange, endRange, delta, low, mid, 2*pos+1);\n updateSegmentTreeRangeLazy(segmentTree, lazy, startRange, endRange, delta, mid+1, high, 2*pos+2);\n segmentTree[pos] = Math.min(segmentTree[2*pos + 1], segmentTree[2*pos + 2]);\n }\n\n public int rangeMinimumQueryLazy(int segmentTree[], int lazy[], int qlow, int qhigh, int len)\n {\n return rangeMinimumQueryLazy(segmentTree, lazy, qlow, qhigh, 0, len - 1, 0);\n }\n\n private int rangeMinimumQueryLazy(int segmentTree[], int lazy[], int qlow, int qhigh, int low, int high, int pos)\n {\n if(low > high)\n {\n return Integer.MAX_VALUE;\n }\n if (lazy[pos] != 0)\n {\n segmentTree[pos] += lazy[pos];\n if (low != high)\n {\n lazy[2 * pos + 1] += lazy[pos];\n lazy[2 * pos + 2] += lazy[pos];\n }\n lazy[pos] = 0;\n }\n\n if(qlow > high || qhigh < low)\n {\n return Integer.MAX_VALUE;\n }\n\n if(qlow <= low && qhigh >= high)\n {\n return segmentTree[pos];\n }\n\n int mid = (low+high)/2;\n return Math.min(rangeMinimumQueryLazy(segmentTree, lazy, qlow, qhigh, low, mid, 2 * pos + 1), rangeMinimumQueryLazy(segmentTree, lazy, qlow, qhigh, mid + 1, high, 2 * pos + 2));\n }\n}\nclass EulerPath\n{\n private int n;\n private int edgeCount;\n private int[] in, out;\n private LinkedList path = new LinkedList<>();\n private ArrayList[] adj;\n\n public EulerPath(int n, ArrayList[] adj)\n {\n this.n = n;\n this.adj = adj;\n in = new int[n];\n out = new int[n];\n edgeCount = 0;\n for (int i=0;i 1 || in[i] - out[i] > 1) return false;\n else if (out[i] - in[i] == 1) startNodes++;\n else if (in[i] - out[i] == 1) endNodes++;\n }\n return (endNodes == 0 && startNodes == 0) || (endNodes == 1 && startNodes == 1);\n }\n\n private int findStartNode()\n {\n int start = 0;\n for (int i=0;i 0)\n start = i;\n }\n return start;\n }\n\n public int[] getEulerPath()\n {\n if (!hasEulerianPath()) return null;\n dfs(0);\n\n if (path.size() != edgeCount + 1)\n return null;\n int[] soln = new int[edgeCount + 1];\n for (int i=0;!path.isEmpty();i++)\n soln[i] = path.removeFirst();\n return soln;\n }\n\n private void dfs(int v)\n {\n while (out[v] != 0)\n {\n int next = adj[v].get(--out[v]);\n dfs(next);\n }\n path.addFirst(v);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf3e653ff87dc3d6e4a2dd90ea5f6800", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Created by gouthamvidyapradhan on 11/07/2020\n */\npublic class CountTheArrays {\n private static PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out, 500000));\n static class MyScanner {\n /**\n * Buffered reader\n */\n private static BufferedReader br = new BufferedReader(\n new InputStreamReader(System.in));\n\n private static StringTokenizer st;\n\n /**\n * Read integer\n *\n * @return\n * @throws Exception\n */\n public static int readInt() throws Exception {\n try {\n if (st != null && st.hasMoreTokens()) {\n return parseInt(st.nextToken());\n }\n String str = br.readLine();\n if(str == null) return -2;\n if (!str.trim().equals(\"\")) {\n st = new StringTokenizer(str);\n return parseInt(st.nextToken());\n }\n } catch (IOException e) {\n close();\n return -1;\n }\n return -1;\n }\n\n /**\n * Read integer\n *\n * @return\n * @throws Exception\n */\n public static long readLong() throws Exception {\n try {\n if (st != null && st.hasMoreTokens()) {\n return Long.parseLong(st.nextToken());\n }\n String str = br.readLine();\n if (str != null && !str.trim().equals(\"\")) {\n st = new StringTokenizer(str);\n return Long.parseLong(st.nextToken());\n }\n } catch (IOException e) {\n close();\n return -1;\n }\n return -1;\n }\n\n /**\n * Read line\n * @return\n * @throws Exception\n */\n public static String readLine() throws Exception\n {\n return br.readLine();\n }\n\n /**\n * Parse to integer\n * @param in\n * @return integer value\n */\n public static int parseInt(String in)\n {\n // Check for a sign.\n int num = 0, sign = -1, i = 0;\n final int len = in.length( );\n final char ch = in.charAt( 0 );\n if ( ch == '-' )\n sign = 1;\n else\n num = '0' - ch;\n\n // Build the number.\n i+=1;\n while ( i < len )\n num = num*10 + '0' - in.charAt( i++ );\n return sign * num;\n }\n\n /**\n * Close BufferedReader\n *\n * @throws Exception\n */\n public static void close() throws Exception {\n br.close();\n }\n }\n\n private static long[] F;\n private static long[] P;\n private static final int MOD = 998244353;\n public static void main(String[] args) throws Exception{\n int n = MyScanner.readInt();\n int m = MyScanner.readInt();\n if(n < 3) {\n pw.println(0);\n } else{\n F = new long[(Math.max(m, n)) + 1];\n P = new long[n + 1];\n Arrays.fill(F, -1);\n Arrays.fill(P, -1);\n long ans = 0L;\n for(int i = 1; i < m; i ++){\n long ncR = NcR(i - 1, n - 3);\n long pow = power(n - 3);\n ans = ((ans + (((ncR * pow % MOD) * i) % MOD)) % MOD);\n }\n pw.println(ans);\n }\n pw.flush();\n pw.close();\n }\n\n private static long power(int n){\n if(n == 0) return 1;\n long res = ((power(n - 1) * 2) % MOD);\n P[n] = res;\n return res;\n }\n\n private static long NcR(int n, int r){\n if(n - r < 0) return 0;\n return ((fact(n) * ((modInverse((int)fact(r)) * modInverse((int)fact(n - r))) % MOD)) % MOD);\n }\n private static long fact(int n){\n if(n == 0 || n == 1) return 1;\n else if(F[n] != -1) return F[n];\n else {\n F[n] = ((n * (fact(n - 1) % MOD)) % MOD);\n return F[n];\n }\n }\n\n private static int modMul(int a, int b){\n return (int)(((long) a * b) % MOD);\n }\n\n private static int modAdd(int a, int b){\n return (int)(((long) a + b) % MOD);\n }\n\n private static long modInverse(int a){\n AntonAndSchool.ExtendedGcd gcdPair = new AntonAndSchool.ExtendedGcd();;\n gcd(a, MOD, gcdPair);\n return (((gcdPair.x % MOD) + MOD) % MOD);\n }\n\n static class ExtendedGcd{\n long x, y;\n }\n\n private static long gcd(long a, long b, AntonAndSchool.ExtendedGcd gcdPair){\n if(b == 0) {\n gcdPair.x = 1;\n gcdPair.y = 0;\n return a;\n }\n AntonAndSchool.ExtendedGcd newGcdPair = new AntonAndSchool.ExtendedGcd();\n long r = gcd(b, a % b, newGcdPair);\n gcdPair.x = newGcdPair.y;\n gcdPair.y = newGcdPair.x - newGcdPair.y * (a/b);\n return r;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f958439b41ffa9e489e24ae4a8ca508", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "package com.netease.music.codeforces;\n\nimport java.util.Scanner;\n\n/**\n * Created by dezhonger on 2020/3/9\n */\npublic class DDDD {\n public static long mul(long a, long b, long mod) {\n a %= mod;\n\n long result = 1;\n while (b > 0) {\n if (b % 2 == 1) {\n result = result * a;\n a %= mod;\n }\n a = a * a;\n a %= mod;\n b >>= 1;\n result %= mod;\n }\n return result;\n }\n\n public static void main(String[] args) {\n long mod = 998244353;\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int m = scanner.nextInt();\n //ans = (n-2) * C()\n// long ans = 1L * (n - 2) *\n long nn = n - 2;\n long mm = n - 2;\n long ans = 1;\n long last = 1;\n long nxt = 0;\n int cnt = 0;\n// for (; nn < m - 1; nn++) {\n for (; cnt < m - n + 1; nn++, cnt++) {\n long niyuan = mul(nn - mm + 1, mod - 2, mod);\n\n// nxt = 1L * (nn + 1) * last / (nn - mm + 1);\n nxt = 1L * (nn + 1) * last;\n nxt %= mod;\n nxt *= niyuan;\n nxt %= mod;\n\n ans += nxt;\n last = nxt;\n ans %= mod;\n }\n ans *= (n - 2);\n ans %= mod;\n long p = mul(2, n - 3, mod);\n ans *= p;\n ans %= mod;\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d3855ad1c856e3395d10272cbd98681d", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic long sx = 0, sy = 0, m = (long) (1e9 + 7);\n\n\tstatic ArrayList[] a;\n\tstatic int[] dp;\n\tstatic long[] fa;\n\tstatic boolean b = true;\n\tstatic HashMap hm = new HashMap<>();\n\t// static ArrayList p = new ArrayList<>();\n\tpublic static PrintWriter out;\n\tstatic ArrayList ans = new ArrayList<>();\n\tstatic long[] fact = new long[(int) 1e6];\n\tstatic ArrayList[] p;\n\tstatic StringBuilder sb = new StringBuilder();\n\tstatic boolean cycle = false;\n\tstatic long mod = 998244353;\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tReader scn = new Reader();\n\n\t\tpreprocess();\n\t\tlong n = scn.nextLong(), m = scn.nextLong();\n\n\t\tlong ans = ncr(m, n - 1);\n\t\tans = (ans * pow(2, n - 3)) % mod;\n\t\tans = (ans * (n - 2)) % mod;\n\n\t\tSystem.out.println(ans);\n\n\t}\n\n\tpublic static void preprocess() {\n fact[0] = 1;\n \n\t\tfor (int i = 1; i < 1e6; i++)\n\t\t\tfact[i] = (fact[i - 1] * i) % mod;\n\t}\n\n\tpublic static long ncr(long n, long r) {\n\n\t\tlong ans = ((((fact[(int) n] * pow(fact[(int) r], mod - 2)) % mod) * pow(fact[(int) (n - r)], mod - 2)) % mod);\n\t\treturn ans;\n\t}\n\n\t// _________________________TEMPLATE_____________________________________________________________\n\n\t// private static int gcd(int a, int b) {\n\t// if (a == 0)\n\t// return b;\n\t//\n\t// return gcd(b % a, a);\n\t// }\n\n\t// static class comp implements Comparator {\n\t//\n\t// @Override\n\t// public int compare(Integer o1, Integer o2) {\n\t//\n\t// return (int) (o2 - o1);\n\t// }\n\t//\n\t// }\n\n\tpublic static long pow(long a, long b) {\n\n\t\tif (b == 0 || b == 1)\n\t\t\treturn (long) Math.pow(a, b);\n\n\t\tif (b % 2 == 0) {\n\n\t\t\tlong ret = pow(a, b / 2);\n\t\t\tret = (ret % mod * ret % mod) % mod;\n\t\t\treturn ret;\n\t\t}\n\n\t\telse {\n\t\t\treturn ((pow(a, b - 1) % mod) * a % mod) % mod;\n\t\t}\n\t}\n\n\tprivate static class pair implements Comparable {\n\n\t\tint a, b;\n\n\t\tpair(int c, int d) {\n\n\t\t\ta = c;\n\t\t\tb = d;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(pair o) {\n\n\t\t\treturn 1;\n\t\t}\n\n\t}\n\n\tpublic static class Reader {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic Reader() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic Reader(String file_name) throws IOException {\n\t\t\tdin = new DataInputStream(new FileInputStream(file_name));\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String readLine() throws IOException {\n\t\t\tbyte[] buf = new byte[1000000 + 1]; // line length\n\t\t\tint cnt = 0, c;\n\t\t\twhile ((c = read()) != -1) {\n\t\t\t\tif (c == '\\n')\n\t\t\t\t\tbreak;\n\t\t\t\tbuf[cnt++] = (byte) c;\n\t\t\t}\n\t\t\treturn new String(buf, 0, cnt);\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.') {\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9') {\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\tfillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic int[][] nextInt2DArray(int m, int n) throws IOException {\n\t\t\tint[][] arr = new int[m][n];\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\t\tarr[i][j] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t\t// kickstart - Solution\n\t\t// atcoder - Main\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1b9658a7984872a732338c98c23dda11", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class two62144 {\n\tstatic boolean [][] dp;\n\tstatic int [] vals;\n\tpublic static void main(String[] args) {\n//\t\tPrintWriter pw = null;\n//\t\t\t\t\n//\t\t\t\tFile f=null;\n//\t\t\t\tScanner sc = null;\n//\t\t\t\ttry {\n//\t\t\t\t\tf = new File(\"262144.in\");\t\t\t\n//\t\t\t\t\tpw = new PrintWriter(new BufferedWriter(new FileWriter(\"262144.out\")));\n//\t\t\t\t\tsc = new Scanner(f);\n//\t\t\t}\n//\t\t\t\tcatch(Exception e) {\n//\t\t\n//\t\t\t\t}\n\t\tScanner sc =new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tvals =new int[n];\n\t\tfor(int i=0;i=Math.pow(2,k) && dp[temp-(int) Math.pow(2,k)][valtemp]) {\n\t\t\t\tdp[i][valtemp+1]=true;\n\t\t\t\tvaltemp++;\n\t\t\t\tmax = Math.max(max,valtemp);\n\t\t\t\tk++;\n\t\t\t}\n\t\t}\n\t\tfor(int i=0;i= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} \n public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} \n public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} \n public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} \n public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} \n public double d() throws IOException {return Double.parseDouble(s()) ;}\n public boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; } \n public boolean isEndOfLine(int c) { return c == '\\n' || c == '\\r' || c == -1; } \n public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}\n }\n \n \n \n // |----| /\\ | | ----- |\n // | / / \\ | | | |\n // |--/ /----\\ |----| | |\n // | \\ / \\ | | | |\n // | \\ / \\ | | ----- -------\n\n \n public static void main(String[] args)throws IOException\n {\n PrintWriter out= new PrintWriter(System.out);\n Reader sc=new Reader();\n int n=sc.i();\n long arr[]=new long[1000005];\n arr[1]=1l;\n arr[2]=1l;\n for(int i=3;i<=1000005;i++)\n arr[i]=(arr[i-1]+arr[i-2])%1000000007;\n out.println((arr[n+3]+1000000005)%1000000007);\n out.flush();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "05d102ce2a1d0f86f5f7e5eb462bc415", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\tstatic long mod = 1000000007;\n static int size = 200000;\n\tstatic long[] fac = new long[size];\n\tstatic long[] finv = new long[size];\n\tstatic long[] inv = new long[size];\n\tstatic int INF = Integer.MAX_VALUE;\n\n \tpublic static void main(String[] args){\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint n = scanner.nextInt();\n\t\t//dp[i]:=i\u756a\u76ee\u306e\u30de\u30fc\u30d6\u30eb\u3092\u6700\u5f8c\u306b\u53d6\u3063\u305f\u6642\u306ezebroid\u6570\n\t\tlong[] dp = new long[n+1];\n\t\tdp[1] = 1L;\n\t\tdp[2] = 2L;\n\t\tfor(int i = 3; i <= n; i++){\n\t\t\tdp[i] = dp[i-1]+dp[i-2];\n\t\t\tdp[i] %= mod;\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i = 1; i <= n; i++){\n\t\t\tans += dp[i];\n\t\t\tans %= mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tpublic static boolean isPrime(int n){\n\t\tif(n == 1) return false;\n\t\tif(n == 2 || n == 3) return true;\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\t// tar \u306e\u65b9\u304c\u6570\u5b57\u304c\u5927\u304d\u3044\u304b\u3069\u3046\u304b\n\tstatic boolean compare(String tar, String src) {\n\t\tif (src == null) return true;\n\t\tif (src.length() == tar.length()) {\n\t\t\tint len = tar.length();\n\t\t\tfor (int i = 0; i < len; i++) {\n\t\t\t\tif (src.charAt(i) > tar.charAt(i)) {\n\t\t\t\t\treturn false;\n\t\t\t\t} else if (src.charAt(i) < tar.charAt(i)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tar.compareTo(src) > 0 ? true : false;\n\t\t} else if (src.length() < tar.length()) {\n\t\t\treturn true;\n\t\t} else if (src.length() > tar.length()) {\n\t\t\treturn false;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static class Edge{\n\t\tint to;\n\t\tEdge(int to){\n\t\t\tthis.to = to;\n\t\t}\n\t}\n\tpublic static void swap(long a, long b){\n\t\tlong tmp = 0;\n\t\tif(a > b){\n\t\t\ttmp = a;\n\t\t\ta = b;\n\t\t\tb = tmp;\n\t\t}\n\t}\n static class Pair implements Comparable{\n int first, second;\n Pair(int a, int b){\n first = a;\n second = b;\n }\n @Override\n public boolean equals(Object o){\n if (this == o) return true;\n if (!(o instanceof Pair)) return false;\n Pair p = (Pair) o;\n return first == p.first && second == p.second;\n }\n @Override\n public int compareTo(Pair p){\n //return first == p.first ? second - p.second : first - p.first; //first\u3067\u6607\u9806\u306b\u30bd\u30fc\u30c8\n return (first == p.first ? second - p.second : first - p.first) * -1; //first\u3067\u964d\u9806\u306b\u30bd\u30fc\u30c8\n //return second == p.second ? first - p.first : second - p.second;//second\u3067\u6607\u9806\u306b\u30bd\u30fc\u30c8\n //return (second == p.second ? first - p.first : second - p.second)*-1;//second\u3067\u964d\u9806\u306b\u30bd\u30fc\u30c8\n }\n }\n\n //\u7e70\u308a\u8fd4\u3057\u4e8c\u4e57\u6cd5\n public static long pow(long x, long n){\n long ans = 1;\n while(n > 0){\n if((n & 1) == 1){\n ans = ans * x;\n ans %= mod;\n }\n x = x * x % mod;\n n >>= 1;\n }\n return ans;\n }\n\n\tpublic static long div(long x, long y){\n\t\treturn (x*pow(y, mod-2))%mod;\n\t}\n\n //fac, inv, finv\u30c6\u30fc\u30d6\u30eb\u306e\u521d\u671f\u5316\u3001\u3053\u308c\u4f7f\u3046\u5834\u5408\u306finitComb()\u3067\u521d\u671f\u5316\u5fc5\u8981\n\tpublic static void initComb(){\n\t\tfac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;\n\t\tfor (int i = 2; i < size; ++i) {\n\t\t\tfac[i] = fac[i - 1] * i % mod;\n\t\t\tinv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;\n\t\t\tfinv[i] = finv[i - 1] * inv[i] % mod;\n\t\t}\n\t}\n\n\t//nCk % mod\n\tpublic static long comb(int n, int k){\n\t\treturn fac[n] * finv[k] % mod * finv[n - k] % mod;\n\t}\n\n\t//n! % mod\n\tpublic static long fact(int n){\n\t\treturn fac[n];\n\t}\n\n\t//(n!)^-1 with % mod\n\tpublic static long finv(int n){\n\t\treturn finv[n];\n\t}\n\n static class UnionFind {\n int[] parent;\n public UnionFind(int size) {\n parent = new int[size];\n Arrays.fill(parent, -1);\n }\n public boolean unite(int x, int y) {\n x = root(x);\n y = root(y);\n if (x != y) {\n if (parent[y] < parent[x]) {\n int tmp = y;\n y = x;\n x = tmp;\n }\n parent[x] += parent[y];\n parent[y] = x;\n return true;\n }\n return false;\n }\n public boolean same(int x, int y) {\n return root(x) == root(y);\n }\n public int root(int x) {\n return parent[x] < 0 ? x : (parent[x] = root(parent[x]));\n }\n public int size(int x) {\n return -parent[root(x)];\n }\n }\n\tpublic static int upperBound(int[] array, int value) {\n\t\t\t int low = 0;\n\t\t\t int high = array.length;\n\t\t\t int mid;\n\t\t\t while( low < high ) {\n\t\t\t\t\t mid = ((high - low) >>> 1) + low; // (high + low) / 2\n\t\t\t\t\t if( array[mid] <= value ) {\n\t\t\t\t\t\t\t low = mid + 1;\n\t\t\t\t\t } else {\n\t\t\t\t\t\t\t high = mid;\n\t\t\t\t\t }\n\t\t\t }\n\t\t\t return low;\n\t }\n\t public static final int lowerBound(final int[] arr, final int value) {\n \tint low = 0;\n \tint high = arr.length;\n \tint mid;\n \twhile (low < high){\n \tmid = ((high - low) >>> 1) + low; //(low + high) / 2 (\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u5bfe\u7b56)\n \tif (arr[mid] < value) {\n \tlow = mid + 1;\n \t} else {\n high = mid;\n \t}\n \t}\n \treturn low;\n\t\t}\n //n,m\u306e\u6700\u5927\u516c\u7d04\u6570\n public static long gcd(long n, long m){\n if(m > n) return gcd(m,n);\n if(m == 0) return n;\n return gcd(m, n%m);\n }\n\t//3\u8981\u7d20\u306e\u30bd\u30fc\u30c8\n\tprivate class Pair2 implements Comparable {\n\t\tString s;\n\t\tint p;\n\t\tint index;\n\t\tpublic Pair2(String s, int p, int index) {\n\t\t\t\tthis.s = s;\n\t\t\t\tthis.p = p;\n\t\t\t\tthis.index = index;\n\t\t}\n\n\t\tpublic int compareTo(Pair2 other) {\n\t\t\t\tif (s.equals(other.s)) {\n\t\t\t\t\t\treturn other.p - this.p;\n\t\t\t\t}\n\t\t\t\treturn this.s.compareTo(other.s);\n\t\t}\n\t}\n\t//c -> int\u306b\u5909\u63db\npublic static int c2i(char c){\n\tif('A' <= c && c <= 'Z'){\n\t\treturn c - 'A';\n\t}else{\n\t\treturn c - 'a' + 26;\n\t}\n}\n// int -> char\u306b\u5909\u63db\npublic static char i2c(int i){\n\tif(0 <= i && i < 26){\n\t\t\treturn (char)(i + 'A');\n\t}else{\n\t\t\treturn (char)(i + 'a' - 26);\n\t}\n}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63ebc1f65428137f651b61119646c4b1", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Problem0209a\n{\n public static void main(String[] args)\n {\n int mod = 1000000007;\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n long[] dp = new long[n + 1];\n dp[0] = 0;\n dp[1] = 1;\n dp[2] = 2;\n if(n == 1)\n {\n System.out.println(1);\n }\n else if (n == 2)\n {\n System.out.println(2);\n }\n else {\n for (int i = 3; i <= n; i++)\n {\n dp[i] = (dp[i - 2] + dp[i - 1]) % mod;\n }\n long sum = 0;\n for (int i = 0; i < n; i++)\n {\n sum = (sum + dp[i + 1]) % mod;\n }\n System.out.println(sum);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c1ddf8ac1970fa215b636eb8909f93b6", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner scan=new Scanner(System.in);\n int y=scan.nextInt();\n int ans=0;\n int b=scan.nextInt();\n int r=scan.nextInt();\n int a[]=new int[3];\n a[0]=y;a[1]=b;a[2]=r;\n Arrays.sort(a);\n if(a[0]==y&&a[1]==b)ans=3*y+3;\n else if(a[0]==y&&a[1]==r&&r-y>1)ans=3*y+3;\n else if(a[0]==y&&a[1]==r)&&r-y!=0)ans=3*r-3;\n else if(a[0]==b&&b map, cmap;\n Stack stack;\n public void run() throws Exception{\n \tin = new BufferedReader(new InputStreamReader(System.in));\n \tout = new PrintWriter(System.out);\n\n n = nextInt();\n if (n % 2 == 1) {\n out.println(\"NO\");\n out.close();\n return;\n }\t\n\n map = new HashMap();\n cmap = new HashMap();\n\n for(int i=0;i n/2) {\n out.println(\"NO\");\n out.close();\n return;\n }\n for(int i=0;i();\n for(int i=0;i= 0 && stack.size() > 0) {\n int c = nums[yk];\n int count = map.get(c);\n while(count == 0) {\n yk--;\n c = nums[yk];\n count = map.get(c);\n }\n\n while(count > 0) {\n int x = stack.pop();\n int y = stack.pop();\n a[x] = -c;\n a[y] = c;\n count-=2;\n }\n\n map.remove(c);\n }\n\n for(int i=0;i map, cmap;\n Stack stack;\n public void run() throws Exception{\n \tin = new BufferedReader(new InputStreamReader(System.in));\n \tout = new PrintWriter(System.out);\n\n n = nextInt();\n if (n % 2 == 1) {\n out.println(\"NO\");\n out.close();\n return;\n }\t\n\n map = new HashMap();\n int p[] = new int[n];\n\n for(int i=0;i n/2) {\n out.println(\"NO\");\n out.close();\n return;\n }\n int q[] = new int[m];\n for(int i=0;i();\n for(int i=0;i 0){\n int nums[] = new int[stack.size()];\n int yk = nums.length-1;\n while(stack.size() > 0) {\n nums[yk--] = stack.pop();\n }\n\n stack.push(nums[0]);\n for(int i=1;i 0){\n out.println(\"NO\");\n out.close();\n return;\n } \n }\n \n\n out.println(\"YES\");\n for(int i=0;il) return 1;\t\n\t if (a[k]<=0) return 0; else\n\t { \n\t\t int kol=0;\n\t\t for (int i=l;i>=k;i--)\n\t\t {\n\t\t\t if (kol==0) {kol=1;st[kol]=Math.abs(a[i]);a[i]=-Math.abs(a[i]);} else\n\t\t\t {\n\t\t\t\t if (st[kol]==a[i]) kol=kol-1; else\n\t\t\t\t {kol+=1;st[kol]=Math.abs(a[i]);a[i]=-Math.abs(a[i]);}\n\t\t\t }\n\t\t }\n\t\t if (kol!=0) return 0; else return 1;\n\t }\n\t}\t \n\tpublic static void main(String[] args) throws IOException {\t\n\tScanner\tin = new Scanner(System.in);\n\tint n=in.nextInt();\n\t\n\tfor (int i=0;i0) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\t//StringBuilder s=new StringBuilder();\n\t\t\tfor (int i=0;i=0;i--)\n\t\t {\n\t\t\t if (kol==0) {kol=1;st[kol]=Math.abs(a[i]);a[i]=-st[kol];} else\n\t\t\t {\n\t\t\t\t if (st[kol]==a[i]) kol-=1; else\n\t\t\t\t {kol+=1;st[kol]=Math.abs(a[i]);a[i]=-st[kol];}\n\t\t\t }\n\t\t }\n\t\t if (kol!=0) System.out.println(\"NO\"); else\n\t\t {\n\t\t\t System.out.println(\"YES\");\n\t\t\t for (int i=0;i l = new ArrayList<>();\n\t\tint n = in.nextInt();\n\n\t\twhile (n-- > 0)\n\t\t\tl.add(in.nextInt());\n\t\tCollections.sort(l);\n\t\tStringBuilder s = new StringBuilder();\n\t\tfor (int x : l)\n\t\t\ts.append(x + \" \");\n\t\ts.setLength(s.length() - 1);\n\t\tSystem.out.println(s.toString());\n\t}\n\n\tstatic class FastReader {\n\t private boolean finished = false;\n\n\t private InputStream stream;\n\t private byte[] buf = new byte[1024];\n\t private int curChar;\n\t private int numChars;\n\t private SpaceCharFilter filter;\n\n\t public FastReader(InputStream stream) {\n\t this.stream = stream;\n\t }\n\n\t public int read() {\n\t if (numChars == -1) {\n\t throw new InputMismatchException();\n\t }\n\t if (curChar >= numChars) {\n\t curChar = 0;\n\t try {\n\t numChars = stream.read(buf);\n\t } catch (IOException e) {\n\t throw new InputMismatchException();\n\t }\n\t if (numChars <= 0) {\n\t return -1;\n\t }\n\t }\n\n\t return buf[curChar++];\n\t }\n\n\t public int peek() {\n\t if (numChars == -1) {\n\t return -1;\n\t }\n\t if (curChar >= numChars) {\n\t curChar = 0;\n\t try {\n\t numChars = stream.read(buf);\n\t } catch (IOException e) {\n\t return -1;\n\t }\n\t if (numChars <= 0) {\n\t return -1;\n\t }\n\t }\n\t return buf[curChar];\n\t }\n\n\t public int nextInt() {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t c = read();\n\t int sgn = 1;\n\t if (c == '-') {\n\t sgn = -1;\n\t c = read();\n\t }\n\t int res = 0;\n\t do {\n\t if (c == ',') {\n\t c = read();\n\t }\n\t if (c < '0' || c > '9') {\n\t throw 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\n\t public long nextLong() {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t c = read();\n\t int sgn = 1;\n\t if (c == '-') {\n\t sgn = -1;\n\t c = read();\n\t }\n\t long res = 0;\n\t do {\n\t if (c < '0' || c > '9') {\n\t throw 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\n\t public String nextString() {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t c = read();\n\t StringBuilder res = new StringBuilder();\n\t do {\n\t res.appendCodePoint(c);\n\t c = read();\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 }\n\t return isWhitespace(c);\n\t }\n\n\t public static boolean isWhitespace(int c) {\n\t return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t }\n\n\t private String readLine0() {\n\t StringBuilder buf = new StringBuilder();\n\t int c = read();\n\t while (c != '\\n' && c != -1) {\n\t if (c != '\\r') {\n\t buf.appendCodePoint(c);\n\t }\n\t c = read();\n\t }\n\t return buf.toString();\n\t }\n\n\t public String nextLine() {\n\t String s = readLine0();\n\t while (s.trim().length() == 0)\n\t s = readLine0();\n\t return s;\n\t }\n\n\t public String nextLine(boolean ignoreEmptyLines) {\n\t if (ignoreEmptyLines) {\n\t return nextLine();\n\t } else {\n\t return readLine0();\n\t }\n\t }\n\n\t public BigInteger nextBigInteger() {\n\t try {\n\t return new BigInteger(nextString());\n\t } catch (NumberFormatException e) {\n\t throw new InputMismatchException();\n\t }\n\t }\n\n\t public char nextCharacter() {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t c = read();\n\t return (char) c;\n\t }\n\n\t public double nextDouble() {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t c = read();\n\t int sgn = 1;\n\t if (c == '-') {\n\t sgn = -1;\n\t c = read();\n\t }\n\t double res = 0;\n\t while (!isSpaceChar(c) && c != '.') {\n\t if (c == 'e' || c == 'E') {\n\t return res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9') {\n\t throw new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c - '0';\n\t c = read();\n\t }\n\t if (c == '.') {\n\t c = read();\n\t double m = 1;\n\t while (!isSpaceChar(c)) {\n\t if (c == 'e' || c == 'E') {\n\t return res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9') {\n\t throw new InputMismatchException();\n\t }\n\t m /= 10;\n\t res += (c - '0') * m;\n\t c = read();\n\t }\n\t }\n\t return res * sgn;\n\t }\n\n\t public boolean isExhausted() {\n\t int value;\n\t while (isSpaceChar(value = peek()) && value != -1)\n\t read();\n\t return value == -1;\n\t }\n\n\t public String next() {\n\t return nextString();\n\t }\n\n\t public SpaceCharFilter getFilter() {\n\t return filter;\n\t }\n\n\t public void setFilter(SpaceCharFilter filter) {\n\t this.filter = filter;\n\t }\n\n\t public interface SpaceCharFilter {\n\t public boolean isSpaceChar(int ch);\n\t }\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1434ac44c64ad3b7ac691f410b32e454", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "//package af2017;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class F {\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\tThread.sleep(1200L);\n\t\tArrays.sort(a);\n\t\tfor(int v : a){\n\t\t\tout.print(v + \" \");\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 F().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "51613a15d3b499d1e5d13470ef790167", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class april {\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 TreeSet t = new TreeSet();\n while(s.hasMoreTokens()){\n t.add(Long.parseLong(s.nextToken());\n }\n while(System.currentTimeMillis() - time < 2100){\n \n }\n for(long i : t){\n System.out.print(i + \" \");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a9fcfb09c57fddb916598ca42441e2de", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Template implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n try {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } catch (Exception e) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n }\n\n class GraphBuilder {\n int n, m;\n int[] x, y;\n int index;\n int[] size;\n\n\n GraphBuilder(int n, int m) {\n this.n = n;\n this.m = m;\n x = new int[m];\n y = new int[m];\n size = new int[n];\n }\n\n void add(int u, int v) {\n x[index] = u;\n y[index] = v;\n size[u]++;\n size[v]++;\n index++;\n }\n\n int[][] build() {\n int[][] graph = new int[n][];\n for (int i = 0; i < n; i++) {\n graph[i] = new int[size[i]];\n }\n for (int i = m - 1; i >= 0; i--) {\n int u = x[i];\n int v = y[i];\n graph[u][--size[u]] = v;\n graph[v][--size[v]] = u;\n }\n return graph;\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n try {\n tok = new StringTokenizer(in.readLine());\n } catch (Exception e) {\n return null;\n }\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n int[] readIntArray(int size) throws IOException {\n int[] res = new int[size];\n for (int i = 0; i < size; i++) {\n res[i] = readInt();\n }\n return res;\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n List[] createGraphList(int size) {\n List[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new Template().run();\n // new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n time();\n memory();\n }\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n void solve() throws IOException {\n int n = readInt();\n int[] a = readIntArray(n);\n Arrays.sort(a);\n for (int x : a) out.print(x + \" \");\n }\n\n void sleep(int timer) {\n try {\n Thread.sleep(time);\n } catch (Exception e) {\n\n }\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cc74a9bfe54613155a2803660fc63411", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class ProblemD {\n\n\t\n\tstatic final int[] gr = {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\t\n\tstatic Map memo2;\n\t\n\tpublic static int grundy(int l, int x) {\n\t\tif (memo2.containsKey(x)) {\n\t\t\treturn memo2.get(x);\n\t\t}\n\t\tboolean[] fnd = new boolean[50];\n\t\tfor (int i = 1 ; i <= l ; i++) {\n\t\t\tif ((x & (1<<(i-1))) == 0) {\n\t\t\t\tif (i == 1) {\n\t\t\t\t\tfnd[0] = true;\n\t\t\t\t} else {\n\t\t\t\t\tint tx = x;\n\t\t\t\t\tfor (int j = i ; j <= l ; j += i) {\n\t\t\t\t\t\ttx |= (1<<(j-1));\n\t\t\t\t\t}\n\t\t\t\t\tfnd[grundy(l,tx)] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 0 ; i < 50 ; i++) {\n\t\t\tif (!fnd[i]) {\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tmemo2.put(x, ans);\n\t\treturn ans;\n\t}\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = in.nextInt();\n\t\tint total = 0;\n\t\tList games = new ArrayList();\n\t\tfor (int i = 2 ; i * i <= n ; i++) {\n\t\t\tlong ni = i;\n\t\t\tint cnt = 0;\n\t\t\twhile (ni <= n) {\n\t\t\t\tcnt++;\n\t\t\t\tni *= i;\n\t\t\t}\n\t\t\tgames.add(cnt);\n\t\t\ttotal += cnt;\n\t\t}\n\t\tif ((n - total) % 2 == 1) {\n\t\t\tgames.add(1);\n\t\t}\n\t\t\n\t\tint xor = 0;\n\t\tfor (int g : games) {\n\t\t\txor ^= gr[g];\n\t\t}\n\t\t\n//\t\tmemo2 = new HashMap();\n//\t\tfor (int c = 1 ; c <= 29 ; c++) {\n//\t\t\tmemo2.clear();\n//\t\t\tboolean[] s30 = new boolean[c+1];\n//\t\t\tArrays.fill(s30, true);\n//\t\t\tdebug(c,grundy(c,0));\n//\t\t}\n\t\t\n\t\tout.println(xor != 0 ? \"Vasya\" : \"Petya\");\n\t\tout.flush();\n\t}\n\n\tpublic static void debug(Object... o) {\n\t\tSystem.err.println(Arrays.deepToString(o));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2e54c1865f9d52b2b3a05a56fb833162", "src_uid": "0e22093668319217b7946e62afe32195", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n\npublic class DD {\n \n static StringTokenizer st;\n static BufferedReader in;\n static PrintWriter pw;\n static Mapmap;\n \n public static void main(String[] args) throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n = nextInt();\n// int[]mex = new int[31];\n// map = new HashMap();\n// for (int i = 1; i < 31; i++) {\n// boolean[]used = new boolean[i+1];\n// mex[i] = go(used);\n// }\n// for (int i = 1; i <= 30; i++) {\n// System.out.print(mex[i]+\" \");\n// }\n// System.out.println();\n int[]mex = {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, 14};\n Set set = new HashSet();\n int xor = 0;\n for (int i = 2; i*i <= n; i++) {\n if (set.contains(i))\n continue;\n int j = i;\n int cnt = 0;\n while (j <= n) {\n cnt++;\n set.add(j);\n j *= i;\n }\n xor ^= mex[cnt];\n }\n if ((n-set.size()) % 2==1)\n xor ^= 1;\n if (xor==0)\n System.out.println(\"Petya\");\n else\n System.out.println(\"Vasya\");\n pw.close();\n }\n// private static int go(boolean[] used) {\n// boolean f = true;\n// int s = 0;\n// for (int i = 1; i < used.length; i++) {\n// if (used[i])\n// s += (1 << (i-1));\n// }\n// if (map.containsKey(new Point(s, used.length)))\n// return map.get(new Point(s, used.length));\n// for (int i = 1; i < used.length; i++) {\n// if (!used[i]) {\n// f = false;\n// break;\n// }\n// }\n// if (f)\n// return 0;\n// boolean[]mex = new boolean[30];\n// for (int i = 1; i < used.length; i++) {\n// if (!used[i]) {\n// boolean[]u = new boolean[used.length];\n// u = used.clone();\n// for (int j = i; j < u.length; j += i) {\n// u[j] = true;\n// }\n// mex[go(u)] = true;\n// }\n// }\n// int res = 0;\n// for (int i = 0; i <= 30; i++) {\n// if (!mex[i]) {\n// res = i;\n// break;\n// }\n// }\n// map.put(new Point(s, used.length), res);\n// return res;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b2f21aeb31a4e552d3fe78bb4c38da3", "src_uid": "0e22093668319217b7946e62afe32195", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\n static final String input = \"stdin\";\n static final String ouput = \"stdout\";\n \n static final int MAXN = 65536;\n boolean[] vist = new boolean[MAXN];\n Map hash = new HashMap();\n int[] sg = {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 int dfs(int mask, int n) {\n if (hash.get(mask) != null) return hash.get(mask);\n boolean[] vist = new boolean[20];\n int sg = 0;\n for (int i = 1; i <= n; ++i) {\n if ((mask & (1 << i)) != 0) continue;\n int nmask = mask;\n for (int j = i; j <= n; j += i) nmask |= 1 << j;\n vist[dfs(nmask, n)] = true;\n }\n while (vist[sg]) ++sg;\n hash.put(mask, sg);\n return sg;\n }\n \n \n \n void solved(int nT) throws IOException {\n for (int n = 1; n <= 29; ++n) {\n hash.clear();\n sg[n] = dfs(0, n);\n } \n int res = 1, n = cin.nextInt();\n int remain = n - 1;\n for (int i = 2; i * i <= n; ++i) {\n if (vist[i]) continue;\n long j = i; int cnt = 0;\n while (j <= n) {\n ++cnt;\n if (j < MAXN) vist[(int)j] = true;\n j *= i;\n }\n res ^= sg[cnt];\n remain -= cnt;\n }\n res ^= remain & 1;\n out.println((res == 0) ? \"Petya\" : \"Vasya\");\n }\n\n void init() {\n }\n\n public static void main(String[] args) throws IOException {\n Main solved = new Main();\n solved.init();\n int T = 1;\n //T = cin.nextInt();\n for (int nT = 1; nT <= T; ++nT) {\n solved.solved(nT);\n }\n out.close();\n }\n\n static {\n try {\n File file = new File(input);\n if (file.exists() && file.canRead()) {\n cin = new InputReader();\n out = new PrintWriter(new PrintWriter(ouput));\n } else {\n cin = new InputReader();\n out = new PrintWriter(System.out);\n }\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n static InputReader cin;\n static PrintWriter out;\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n InputReader() {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = new StringTokenizer(\"\");\n }\n\n String next() throws IOException {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n Integer nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "606a49cb73105e214eb9d234103d8a74", "src_uid": "0e22093668319217b7946e62afe32195", "difficulty": 2300.0} {"lang": "Java 7", "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 mem = new HashMap();\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< mem = new HashMap();\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< q = new ArrayDeque<>();\n q.add(new Pair(y, x));\n int currentSize = 0;\n while (!q.isEmpty()) {\n Pair curr = q.poll();\n if (visited[curr.y][curr.x]) continue;\n if (!graph[curr.y][curr.x]) continue; // X\n visited[curr.y][curr.x] = true;\n ofComponent[curr.y][curr.x] = currentComponent;\n currentSize++;\n if (curr.y - 1 >= 0) q.add(new Pair(curr.y - 1, curr.x));\n if (curr.x - 1 >= 0) q.add(new Pair(curr.y, curr.x - 1));\n if (curr.y + 1 <= n) q.add(new Pair(curr.y + 1, curr.x));\n if (curr.x + 1 <= n) q.add(new Pair(curr.y, curr.x + 1));\n }\n componentSizes[currentComponent] = currentSize;\n largestComponentSize = Math.max(largestComponentSize, currentSize);\n currentComponent++;\n }\n }\n int[][][] marks = new int[n][n][4];\n for (int y=0; y= 0) marks[y][x][UP] = ofComponent[y-1][x];\n if (x - 1 >= 0) marks[y][x][LEFT] = ofComponent[y][x-1];\n if (y + 1 >= n) marks[y][x][DOWN] = ofComponent[y+1][x];\n if (x + 1 >= n) marks[y][x][RIGHT] = ofComponent[y][x+1];\n }\n }\n int[] slidingCount = new int[currentComponent+1];\n int maxScore = largestComponentSize;\n int score = 0;\n for (int y=0; yy-k; j--) {\n if (graph[j][x]) continue;\n for (int direction=0; direction<4; direction++) {\n int component = marks[j][x-k][direction];\n slidingCount[component]--;\n if (slidingCount[component] == 0) {\n score -= componentSizes[component];\n }\n component = marks[j][x][direction];\n slidingCount[component]++;\n if (slidingCount[component] == 0) {\n score += componentSizes[component];\n }\n }\n maxScore = Math.max(score, maxScore);\n }\n for (int j=x; j>x-k; j--) {\n\n }\n }\n }\n System.out.println(maxScore);\n }\n\n private static 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 private List[] toGraph(EIO io, int n) {\n List[] 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\nclass EIO 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 EIO() {\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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b8c108de9dac55bf175604fb0383caf", "src_uid": "d575f9bbdf625202807db59490c5c327", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\tstatic final int[] dx = { 0, 0, -1, 1 };\n\tstatic final int[] dy = { -1, 1, 0, 0 };\n\tstatic int[][] grid;\n\tstatic int N, cnt, inside[], size[];\n\n\tstatic boolean valid(int x, int y) { return x < N && y < N && x > -1 && y > -1 && grid[x][y] == 0; }\n\n\tstatic void dfs(int x, int y, int c)\n\t{\n\t\tgrid[x][y] = c;\n\t\tsize[c]++;\n\t\tfor(int k = 0; k < 4; ++k)\n\t\t{\n\t\t\tint i = x + dx[k], j = y + dy[k];\n\t\t\tif(valid(i, j))\n\t\t\t\tdfs(i, j, c);\n\t\t}\n\t}\n\n\tstatic void add(int x) { if(inside[x]++ == 0) cnt += size[x]; }\n\n\tstatic void erase(int x) { if(inside[x]-- == 1) cnt -= size[x]; }\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\tN = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tgrid = new int[N][N];\n\t\tfor(int i = 0; i < N; ++i)\n\t\t{\n\t\t\tString s = sc.next();\n\t\t\tfor(int j = 0; j < N; ++j)\n\t\t\t\tif(s.charAt(j) == 'X')\n\t\t\t\t\tgrid[i][j] = -1;\n\t\t\t\telse\n\t\t\t\t\tgrid[i][j] = 0;\n\t\t}\n\t\tint idx = 0;\n\t\tinside = new int[N];\n\t\tsize = new int[N];\n\t\tfor(int i = 0; i < N; ++i)\n\t\t\tfor(int j = 0; j < N; ++j)\n\t\t\t\tif(grid[i][j] == 0)\n\t\t\t\t\tdfs(i, j, ++idx);\n\n\t\tfor(int i = 0; i < k; ++i)\n\t\t\tfor(int j = 0; j < k; ++j)\n\t\t\t\tif(grid[i][j] == -1)\n\t\t\t\t\t++cnt;\n\t\t\t\telse\n\t\t\t\t\tadd(grid[i][j]);\n\t\tif(k == N)\n\t\t\tout.println(cnt);\n\t\telse\n\t\t{\n\t\t\tfor(int i = 0; i < k; ++i)\n\t\t\t{\n\t\t\t\tif(grid[i][k] != -1)\n\t\t\t\t\tadd(grid[i][k]);\n\t\t\t\tif(grid[k][i] != -1)\n\t\t\t\t\tadd(grid[k][i]);\n\t\t\t}\n\t\t\tint ans = cnt, d = 1, sx = 0, sy = 0;\n\t\t\twhile(true)\n\t\t\t{\n\t\t\t\twhile(sy + d != -1 && sy + d + k <= N)\n\t\t\t\t{\n\t\t\t\t\tif(d == 1)\n\t\t\t\t\t\tgoRight(sx, sy++, k);\n\t\t\t\t\telse\n\t\t\t\t\t\tgoLeft(sx, sy--, k);\n\t\t\t\t\tans = Math.max(ans, cnt);\n\t\t\t\t}\n\t\t\t\tif(sx + k == N)\n\t\t\t\t\tbreak;\n\t\t\t\tgoDown(sx++, sy, k);\n\t\t\t\tans = Math.max(ans, cnt);\n\t\t\t\td *= -1;\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic void goDown(int sx, int sy, int k)\n\t{\n\t\tif(sx != 0)\n\t\t\tfor(int j = sy; j < sy + k; ++j)\n\t\t\t\tif(grid[sx - 1][j] != -1)\n\t\t\t\t\terase(grid[sx - 1][j]);\n\t\tfor(int j = sy; j < sy + k; ++j)\n\t\t\tif(grid[sx][j] == -1)\n\t\t\t\t--cnt;\n\t\tif(sy > 0 && grid[sx][sy - 1] != -1)\n\t\t\terase(grid[sx][sy - 1]);\n\t\tif(sy + k < N && grid[sx][sy + k] != -1)\n\t\t\terase(grid[sx][sy + k]);\n\t\t++sx;\n\t\tfor(int j = sy; j < sy + k; ++j)\n\t\t\tif(grid[sx + k - 1][j] == -1)\n\t\t\t\t++cnt;\n\t\tif(sx + k < N)\n\t\t\tfor(int j = sy; j < sy + k; ++j)\n\t\t\t\tif(grid[sx + k][j] != -1)\n\t\t\t\t\tadd(grid[sx + k][j]);\n\t\tif(sy > 0 && grid[sx + k - 1][sy - 1] != -1)\n\t\t\terase(grid[sx + k - 1][sy - 1]);\n\t\tif(sy + k < N && grid[sx + k - 1][sy + k] != -1)\n\t\t\terase(grid[sx + k - 1][sy + k]);\n\t}\n\n\tstatic void goRight(int sx, int sy, int k)\n\t{\n\t\tif(sy != 0)\n\t\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\t\tif(grid[i][sy - 1] != -1)\n\t\t\t\t\terase(grid[i][sy - 1]);\n\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\tif(grid[i][sy] == -1)\n\t\t\t\t--cnt;\n\t\tif(sx > 0 && grid[sx - 1][sy] != -1)\n\t\t\terase(grid[sx - 1][sy]);\n\t\tif(sx + k < N && grid[sx + k][sy] != -1)\n\t\t\terase(grid[sx + k][sy]);\n\t\t++sy;\n\t\tif(sy + k < N)\n\t\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\t\tif(grid[i][sy + k] != -1)\n\t\t\t\t\tadd(grid[i][sy + k]);\n\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\tif(grid[i][sy + k - 1] == -1)\n\t\t\t\t++cnt;\n\t\tif(sx > 0 && grid[sx - 1][sy + k - 1] != -1)\n\t\t\tadd(grid[sx - 1][sy + k - 1]);\n\t\tif(sx + k < N && grid[sx + k][sy + k - 1] != -1)\n\t\t\tadd(grid[sx + k][sy + k - 1]);\n\t}\n\n\tstatic void goLeft(int sx, int sy, int k)\n\t{\n\t\tif(sy + k < N)\n\t\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\t\tif(grid[i][sy + k] != -1)\n\t\t\t\t\terase(grid[i][sy + k]);\n\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\tif(grid[i][sy + k - 1] == -1)\n\t\t\t\t--cnt;\n\t\tif(sx > 0 && grid[sx - 1][sy + k - 1] != -1)\n\t\t\terase(grid[sx - 1][sy + k - 1]);\n\t\tif(sx + k < N && grid[sx + k][sy + k - 1] != -1)\n\t\t\terase(grid[sx + k][sy + k - 1]);\n\t\t--sy;\n\t\tif(sy != 0)\n\t\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\t\tif(grid[i][sy - 1] != -1)\n\t\t\t\t\tadd(grid[i][sy - 1]);\n\t\tfor(int i = sx; i < sx + k; ++i)\n\t\t\tif(grid[i][sy] == -1)\n\t\t\t\t++cnt;\n\t\tif(sx > 0 && grid[sx - 1][sy] != -1)\n\t\t\tadd(grid[sx - 1][sy]);\n\t\tif(sx + k < N && grid[sx + k][sy] != -1)\n\t\t\tadd(grid[sx + k][sy]);\n\t}\n\n\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\t\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8c40927d4e8641e62a94cb098007abb9", "src_uid": "d575f9bbdf625202807db59490c5c327", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.util.*;\n \n \npublic class Main {\n \n\n\tpublic static int mod = 1000000007,n,max_ans,cc_count;\n\tpublic static boolean visited[][],grid[][];\n\t//public static ArrayList> cc_list;\n\t//public static ArrayList cc;\n\tpublic static int size[];\n\tpublic static int dx[]={1,0,-1,0};\n\tpublic static int dy[]={0,1,0,-1};\n\tpublic static HashMap map;\n\tpublic static void main(String[] args)throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tInputStream input = System.in;\n\t\tInputReader in = new InputReader(input);\n\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t map = new HashMap();\n\t\t n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tmax_ans = Integer.MIN_VALUE;\n\t\t grid = new boolean[n][n];\n\t\t size = new int[5001];\n\t//\tcc_list = new ArrayList>();\n\t\tfor(int i=0;i();\n\t\t\t\t\tdfs(i,j);\n\t\t\t\t//\tcc_list.add(cc);\n\t\t\t\t\tcc_count++;\n\t\t\t\t\t}\n\t\t\n\t//\tfor(int i=0;i<4;i++)\n\t\t//\tSystem.out.println(size[i]);\n\t\t\n\t\tfor(int i=0;i set = new HashSet();\n\t\t\t\t\n\t\t\t\tif(i!=0)\n\t\t\t\t{\n\t\t\t\t\tfor(int y=j;y ir = set.iterator();\n\t\t\t\t\n\t\t\t\twhile(ir.hasNext())\n\t\t\t\t{\tint aa = ir.next();\n\t\t\t//\tSystem.out.println(aa+\" s \"+size[aa]);\n\t\t\t\t\tcurr_ans += size[aa];\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\n\t\t\t\tmax_ans = Math.max(max_ans, curr_ans);\n\t\t\t//\tSystem.out.println(curr_ans);\n\t\t\t\t\n\t\t\tif(j==n-k)\n\t\t\t{\n\t\t\t\tfor(int x=i;x=n || y1<0 || y1 >= n)\n\t\t\t\tcontinue;\n\t\t\t\n\t\t\tif(grid[x1][y1] && !visited[x1][y1])\n\t\t\t\tdfs(x1,y1);\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\tstatic class Node{\n\t\t\n\t\tint x,y;\n\t\t\n\t\tNode(int x,int y)\n\t\t{\n\t\t\tthis.x=x;this.y=y;\n\t\t}\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 String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "186180c1c3a01177c59ed35158978a77", "src_uid": "d575f9bbdf625202807db59490c5c327", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.util.*;\n \n \npublic class Main {\n \n\n\tpublic static int mod = 1000000007,n,max_ans,cc_count;\n\tpublic static boolean visited[][],grid[][];\n\t//public static ArrayList> cc_list;\n\t//public static ArrayList cc;\n\tpublic static int size[];\n\tpublic static int dx[]={1,0,-1,0};\n\tpublic static int dy[]={0,1,0,-1};\n\tpublic static HashMap map;\n\tpublic static void main(String[] args)throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tInputStream input = System.in;\n\t\tInputReader in = new InputReader(input);\n\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t map = new HashMap();\n\t\t n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tmax_ans = Integer.MIN_VALUE;\n\t\t grid = new boolean[n][n];\n\t\t size = new int[1501];\n\t//\tcc_list = new ArrayList>();\n\t\tfor(int i=0;i();\n\t\t\t\t\tdfs(i,j);\n\t\t\t\t//\tcc_list.add(cc);\n\t\t\t\t\tcc_count++;\n\t\t\t\t\t}\n\t\t\n\t//\tfor(int i=0;i<4;i++)\n\t\t//\tSystem.out.println(size[i]);\n\t\t\n\t\tfor(int i=0;i set = new HashSet();\n\t\t\t\t\n\t\t\t\tif(i!=0)\n\t\t\t\t{\n\t\t\t\t\tfor(int y=j;y ir = set.iterator();\n\t\t\t\t\n\t\t\t\twhile(ir.hasNext())\n\t\t\t\t{\tint aa = ir.next();\n\t\t\t//\tSystem.out.println(aa+\" s \"+size[aa]);\n\t\t\t\t\tcurr_ans += size[aa];\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\n\t\t\t\tmax_ans = Math.max(max_ans, curr_ans);\n\t\t\t//\tSystem.out.println(curr_ans);\n\t\t\t\t\n\t\t\tif(j==n-k)\n\t\t\t{\n\t\t\t\tfor(int x=i;x=n || y1<0 || y1 >= n)\n\t\t\t\tcontinue;\n\t\t\t\n\t\t\tif(grid[x1][y1] && !visited[x1][y1])\n\t\t\t\tdfs(x1,y1);\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\tstatic class Node{\n\t\t\n\t\tint x,y;\n\t\t\n\t\tNode(int x,int y)\n\t\t{\n\t\t\tthis.x=x;this.y=y;\n\t\t}\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 String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a1dcf00e9b37576075a845ba64facbf1", "src_uid": "d575f9bbdf625202807db59490c5c327", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tfinal static int mod = 1_000_000_007;\n\t\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tSTDIN scan = new STDIN();\n\t\tint n = scan.nextInt(), m = scan.nextInt();\n\t\tint[] dp = new int[n+1];\n\t\tdp[1] = 2 % m;\n\t\tfor(int i = 2; i <= n; i++)\n\t\t\tdp[i] = ((((dp[i-1] + dp[i-1]) % m) + dp[i-1]) % m) + 2;\n\t\tSystem.out.println(dp[n]);\n\t}\n\n\t\n\tstatic class STDIN {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic STDIN() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = null;\n\t\t}\n\t\t\n\t\tboolean hasNext() throws Exception {\n\t\t\tif(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n\t\t\treturn st.hasMoreTokens();\n\t\t}\n\n\t\tint nextInt() throws Exception {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws Exception {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws Exception {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString next() throws Exception {\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 Exception {\n\t\t\treturn br.readLine();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "27aabf195fa4b75f213728ad8a4cd8e6", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class A{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n long N = sc.nextLong(), M = sc.nextLong();\n long r = (pow((long)3, N, M)+2*M-1)%M;\n System.out.println(r);\n }\n\n static long pow(long a, long p, long M){\n if(p==0) return 1L;\n if(p==1) return a%M;\n long sq = pow(a, p/2);\n return p%2==0? (sq*sq)%M: (a*(sq*sq)%M)%M;\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aaad1c8e007c0efc3e3066ab73e295a5", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tBufferedReader in;\n\tPrintStream out;\n\tStringTokenizer tok;\n\tScanner sc;\n\t\n\tpublic Main() throws NumberFormatException, IOException {\n\t\t//sc = new Scanner(System.in);\n\t\t//sc = new Scanner(new FileReader(\"in.txt\"));\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t //in = new BufferedReader(new FileReader(\"in.txt\"));\n\t\tout = System.out;\n\t\trun();\n\t}\n\n\tvoid run() throws NumberFormatException, IOException {\n\t\t\t\t\n\t\tlong n = nextInt();\n\t\tlong m = nextInt();\n\t\tout.println(Pot(n,m) - 1);\n\t}\n\t\n\tlong Pot(long n, long mod)\n\t{\n\t\tif(n == 0)return 1;\n\t\tif(n % 2 == 0)\n\t\t{\n\t\t\tlong p = Pot(n/2, mod)%mod;\n\t\t\treturn (p * p)%mod;\t\n\t\t}\n\t\telse return (Pot(n-1, mod) * 3)%mod;\n\t}\n\t\n\tpublic static void main(String[] args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tnew Main();\n\t}\n\n\tString nextToken() throws IOException {\n\t\tString line = \"\";\n\t\tif (tok == null || !tok.hasMoreTokens())\n\t\t{\n\t\t\tif ((line = in.readLine()) != null)\n\t\t\t\ttok = new StringTokenizer(line);\n\t\t\telse return null;\n\t\t}\n\t\treturn tok.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "05c60aa84051269f14882f3525ae1658", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\n\npublic class A {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String n, m;\n n= in.next();\n m= in.next();\n BigInteger aux = new BigInteger(\"3\");\n aux=aux.modPow(new BigInteger(n), new BigInteger(m));\n aux=aux.subtract(BigInteger.ONE);\n System.out.println(aux);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bff7b4811973600a971e4b2dc919c4b9", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class EC32P4\n{\n public static void main(String args[])\n {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt(); //number of fixed spots\n \n long counter = 1;\n \n \n \n if(k >= 2){\n counter += (n*(n-1)/2);\n }\n \n if(k >= 3){\n counter += (n*(n-1)*(n-2)/3);\n }\n \n if(k >= 4){\n counter += (3*n*(n-1)*(n-2)*(n-3)/8);\n }\n \n \n System.out.println(counter);\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "81a4a252e4cc0c391dbc23f0f3bc26b9", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class Permutation\n{\n public static void main(String args[])\n {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt(); //number of fixed spots\n \n int counter = 1;\n \n \n if(k >= 2){\n counter += n*(n-1)/2\n }\n \n if(k >= 3){\n counter += n*(n-1)*(n-2)/3\n }\n \n if(k >= 4){\n counter += 3*n*(n-1)*(n-2)*(n-3)/8\n }\n \n SYstem.out.println(counter);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c7587cd52d39c47d76c0febf396430d2", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt(), k = input.nextInt();\n \n long res = 1;\n if (k >= 2) res += n*(n-1)/2;\n if (k >= 3) res += n*(n-1)*(n-2)/3;\n if (k >= 4) res += n*(n-1)*(n-2)*(n-3)*3/8; \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8d2bc57107c685975cfe5f4e9dd76de5", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n // write your code here\n Scanner in=new Scanner(System.in);\n long n=in.nextLong();\n int k=in.nextInt();\n int []ap=new int[n];\n long ans=1;\n if(k>=2)\n {\n ans+=n*(n-1)/2;\n }\n if(k>=3)\n {\n ans+=n*(n-1)*(n-2)/3;\n }\n if(k>=4)\n {\n ans+=3*n*(n-1)*(n-2)*(n-3)/8;\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "844e9f5a5df0afbff7b0b2bb8a4563b1", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Test{\n\t\n public static void main(String[] args) throws Exception{ \n \n InputReader in = new InputReader(System.in); \n \tPrintWriter pw = new PrintWriter(System.out); \n int n=in.readInt();\n int q=in.readInt();\n \tHashMap map =new HashMap();\n \tfor(int i = 0; i < q; i++) {\n \t\tmap.put(in.readString(), in.readString());\n \t}\n \tfor (Map.Entry entry : map.entrySet()) {\n pw.println(entry.getKey() + \"/\" + entry.getValue());\n }\t \t\n \tpw.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7baa34ddf121eb629e31800f2e3fc96a", "src_uid": "c42abec29bfd17de3f43385fa6bea534", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Test{\n\t\n public static void main(String[] args) throws Exception{ \n InputReader in = new InputReader(System.in); \n \tPrintWriter pw = new PrintWriter(System.out); \n int n=in.readInt();\n int q=in.readInt();\n \tHashMap map =new HashMap();\n \tfor(int i = 0; i < q; i++;) {\n \t\tmap.put(in.readString(), in.readString());\n \t}\n \tfor (Map.Entry entry : map.entrySet()) {\n pw.println(entry.getKey() + \"/\" + entry.getValue());\n }\t \t\n \tpw.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5af105e05e78b97c9bcdc2ab4b19162e", "src_uid": "c42abec29bfd17de3f43385fa6bea534", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n//~O(nQ)\npublic class BearAndCompressing {\n\tpublic static void main(String[] raggs)\n\t{\n\t\tchar[][] replacementArr = new char[6][36];\n\t\t\n\t\tint[] count = new int[6];\n\t\tint[] temp = new int[6];\n\t\t\n\t\t//System.out.println(\"gfim\");\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint q = in.nextInt();\n\t\t\n\t\tfor(int i =0 ; i < 6; i++)\n\t\t{\n\t\t\tfor(int j = 0; j < 36; j++)\n\t\t\t{\n\t\t\t\treplacementArr[i][j] = '0';\n\t\t\t}\n\t\t}\n\t\t\n\t\tin.nextLine();\n\t\t\n\t\tfor(int i = 0; i < q; i++)\n\t\t{\n\t\t\tString line;\n\t\t\tchar twoletter,oneletter;\n\t\t\t\n\t\t\tline = in.nextLine();\n\t\t\t\n\t\t\ttwoletter = line.charAt(0);\n\t\t\toneletter = line.charAt(3);\n\t\t\t\n\t\t\tfor(int j = 0; j < 36; j++)\n\t\t\t{\n\t\t\t\tif(replacementArr[(int)(oneletter-'a')][j] == '0')\n\t\t\t\t{\n\t\t\t\t \u00a0\u00a0replacementArr[(int)(oneletter-'a')][j] = twoletter;\n\t\t\t\t \u00a0\u00a0break;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t//start with one 'a'\n\t\tcount[0] = 1;\n\t\t\n\t\tfor(int i = 0; i < n-1; i++)\n\t\t{\n\t\t\t//for every cell in the array:\n\t\t\tfor(int j = 0; j < 6; j++)\n\t\t\t{\n\t\t\t\tint occurances = count[j];\n\t\t\t\t//System.out.println(j + \" \" + occurances);\n\t\t\t\tfor(int k = 0; k < 36; k++)\n\t\t\t\t{\n\t\t\t\t\t//Replace j with {replacement[j][k] for every k}\n\t\t\t\t\tchar replaceWith = replacementArr[j][k];\n\t\t\t\t\tif(replaceWith == '0') break;\n\t\t\t\t\t\n\t\t\t\t\tint rw = (int)(replaceWith-'a');\n\t\t\t\t\ttemp[rw] += occurances;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//Now push temp ->count, and delete temp\n\t\t\tfor(int x = 0; x < 6; x++) \n\t\t \u00a0\u00a0\u00a0{\n\t\t\t\tcount[x] = temp[x];\n\t\t\t\ttemp[x] = 0;\n\t\t \u00a0\u00a0\u00a0}\n\t\t\t\n\t\t}\n\t\t\n\t\tint sum = 0;\n\t\t\n\t\tfor(int i = 0; i < 6; i++) sum += count[i];\n\t\tSystem.out.println(sum);\n\t\t/*\n\t\tfor(int i =0 ; i < 6; i++)\n\t\t{\n\t\t\tfor(int j = 0; j < 36; j++)\n\t\t\t{\n\t\t\t\tSystem.out.print(replacementArr[i][j] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}*/\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8e3fd4a3e1073269882c72775be1b693", "src_uid": "c42abec29bfd17de3f43385fa6bea534", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution{\n static Map> map = new HashMap<>();\n \n public static void main(String []args){\n Scanner sc = new Scanner(System.in);\n \n int n = sc.nextInt();\n int q = sc.nextInt();\n \n int res = 0;\n \n while(q > 0){\n \n String a = sc.next();\n String b = sc.next();\n \n if(!map.containsKey(b)){\n List temp = new ArrayList<>();\n temp.add(a);\n \n map.put(b,temp);\n }\n else{\n List temp = map.get(b);\n temp.add(a);\n }\n q -= 1;\n }\n \n List base = map.get(\"a\");\n \n for(String s : base) {\n res += helper(s , n);\n }\n \n System.out.println(res);\n }\n \n public static int helper(String str , int n){\n \n if(str.length() == n){\n return 1;\n }\n int res = 0;\n \n String curr = Character.toString(str.charAt(0));\n \n if(!map.containsKey(curr)){\n return 0;\n }\n List temp = map.get(curr);\n \n StringBuilder sb = new StringBuilder();\n \n for(String s : temp) {\n \n sb.append(s);\n sb.append(str.substring(1));\n \n res += helper(sb.toString() , n);\n \n }\n \n return res;\n }\n \n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad41aa07324240a7704ae2d5477ffe3a", "src_uid": "c42abec29bfd17de3f43385fa6bea534", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport static java.lang.Math.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author pttrung\n */\npublic class C {\n\n public static double Epsilon = 1e-6;\n public static long x, y, d;\n\n public static void main(String[] args) {\n Scanner in = new Scanner();\n PrintWriter out = new PrintWriter(System.out);\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\"output.txt\")));\n HashMap map = new HashMap();\n HashSet op = new HashSet();\n Score[] data = new Score[4];\n Score ber = null;\n for (int i = 0; i < 5; i++) {\n String a = in.next();\n String b = in.next();\n String[] score = in.next().split(\":\");\n int c = Integer.parseInt(score[0]);\n int d = Integer.parseInt(score[1]);\n\n if (!map.containsKey(a)) {\n map.put(a, new Score(a, 0, 0, 0));\n }\n if (!map.containsKey(b)) {\n map.put(b, new Score(b, 0, 0, 0));\n }\n if (a.equals(\"BERLAND\")) {\n op.add(b);\n }\n if (b.equals(\"BERLAND\")) {\n op.add(a);\n }\n\n Score tempA = map.get(a);\n tempA.score += c;\n tempA.miss += d;\n Score tempB = map.get(b);\n tempB.score += d;\n tempB.miss += c;\n if (c > d) {\n\n tempA.point += 3;\n\n } else if (c == d) {\n tempA.point += 1;\n tempB.point += 1;\n } else {\n tempB.point += 3;\n }\n map.put(a, tempA);\n map.put(b, tempB);\n }\n int index = 0;\n Score other = null;\n for (String name : map.keySet()) {\n if (!name.equals(\"BERLAND\")) {\n if (!op.contains(name)) {\n other = map.get(name);\n }\n\n } else {\n ber = map.get(name);\n }\n data[index++] = map.get(name);\n }\n ber.score += 1;\n ber.point += 3;\n \n other.miss += 1;\n Arrays.sort(data);\n // System.out.println(ber.score + \" \"+ data[2].score);\n if (ber.point < data[2].point) {\n out.println(\"IMPOSSIBLE\");\n } else {\n int left = 1;\n int right = 0;\n while (!data[2].name.equals(\"BERLAND\")) {\n int difBer = ber.score - ber.miss;\n int difSe = data[2].score - data[2].miss;\n int need = difSe - difBer;\n if (need == 0) {\n if (data[2].score > ber.score && !data[2].name.equals(other.name)) {\n int more = data[2].score - ber.score + 1;\n left += more;\n ber.score += more;\n other.miss += more;\n } else {\n ber.score += 1;\n left++;\n right++;\n other.miss++;\n }\n\n\n } else {\n if (!data[2].name.equals(other.name)) {\n int more = need;\n int miss = 0;\n while(data[2].score > ber.score + more){\n more++;\n miss++;\n }\n if(data[2].name.compareTo(ber.name) < 0){\n more++;\n miss++;\n }\n left += more;\n right += miss;\n ber.score += more;\n ber.miss += miss;\n other.miss += more;\n other.score += miss;\n } else {\n int more = need + 1;\n int a = more / 2;\n if (more % 2 != 0) {\n a++;\n }\n left += a;\n ber.score += a;\n other.miss += a;\n }\n }\n Arrays.sort(data);\n }\n out.println(left + \":\" + right);\n\n }\n // System.out.println(second.point);\n\n out.close();\n }\n\n public static class Score implements Comparable {\n\n String name;\n int score, miss;\n int point;\n\n public Score(String name, int score, int miss, int point) {\n this.name = name;\n this.score = score;\n this.miss = miss;\n this.point = point;\n }\n\n @Override\n public int compareTo(Score o) {\n if (point != o.point) {\n return point - o.point;\n } else {\n int a = score - miss;\n int b = o.score - o.miss;\n if (a != b) {\n return a - b;\n } else if (score != o.score) {\n return score - o.score;\n } else {\n return -name.compareTo(o.name);\n }\n }\n }\n }\n\n public static Pair cal(ArrayList[] map, HashSet result, HashSet check, int pa, int node) {\n boolean taken = false;\n if (check.contains(new Pair(pa, node)) || check.contains(new Pair(node, pa))) {\n taken = true;\n }\n boolean leaf = true;\n\n ArrayList list = new ArrayList();\n Pair store = null;\n for (int next : map[node]) {\n if (next != pa) {\n leaf = false;\n\n Pair p = cal(map, result, check, node, next);\n if (p.y == 1) {\n store = p;\n taken = false;\n\n } else {\n if (store == null) {\n store = p;\n }\n }\n }\n }\n if (leaf) {\n if (taken) {\n result.add(node);\n return new Pair(node, 1);\n } else {\n return new Pair(node, 0);\n }\n }\n if (taken) {\n result.add(store.x);\n return new Pair(store.x, 1);\n }\n return store;\n\n }\n\n public static class Pair {\n\n int x, y;\n\n public Pair(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public boolean equals(Object o) {\n if (o instanceof Pair) {\n Pair other = (Pair) o;\n return x == other.x && y == other.y;\n }\n return false;\n }\n\n @Override\n public int hashCode() {\n int hash = 7;\n hash = 29 * hash + this.x;\n hash = 29 * hash + this.y;\n return hash;\n }\n }\n\n public static void extendEuclid(long a, long b) {\n if (b == 0) {\n x = 1;\n y = 0;\n d = a;\n return;\n }\n extendEuclid(b, a % b);\n long x1 = y;\n long y1 = x - (a / b) * y;\n x = x1;\n y = y1;\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 }\n\n static class Line {\n\n double a, b, c;\n\n Line(double x1, double y1, double x2, double y2) {\n if (Math.abs(x1 - x2) < Epsilon && Math.abs(y1 - y2) < Epsilon) {\n throw new RuntimeException(\"Two point are the same\");\n }\n a = y1 - y2;\n b = x2 - x1;\n c = -a * x1 - b * y1;\n }\n\n Line(Point x, Point y) {\n this(x.x, x.y, y.x, y.y);\n }\n\n public Line perpendicular(Point p) {\n return new Line(p, new Point(p.x + a, p.y + b));\n }\n\n public Point intersect(Line l) {\n double d = a * l.b - b * l.a;\n if (d == 0) {\n throw new RuntimeException(\"Two lines are parallel\");\n }\n\n return new Point((l.c * b - c * l.b) / d, (l.a * c - l.c * a) / d);\n }\n }\n\n static void check(Point a, Point b, ArrayList p, Point[] rec, int index) {\n for (int i = 0; i < 4; i++) {\n int m = (i + index) % 4;\n int j = (i + 1 + index) % 4;\n Point k = intersect(minus(b, a), minus(rec[m], rec[j]), minus(rec[m], a));\n if (k.x >= 0 && k.x <= 1 && k.y >= 0 && k.y <= 1) {\n Point val = new Point(k.x * minus(b, a).x, k.x * minus(b, a).y);\n p.add(add(val, a));\n // System.out.println(a + \" \" + b + \" \" + rec[i] + \" \" + rec[j]);\n // System.out.println(add(val, a));\n }\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\n static Point minus(Point a, Point b) {\n return new Point(a.x - b.x, a.y - b.y);\n }\n\n static Point add(Point a, Point b) {\n return new Point(a.x + b.x, a.y + b.y);\n }\n\n static double cross(Point a, Point b) {\n return a.x * b.y - a.y * b.x;\n\n\n }\n\n static class Point {\n\n double x, y;\n\n Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public String toString() {\n return \"Point: \" + x + \" \" + y;\n }\n }\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d5a8e63eec658e8787819e533516c9e2", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map.Entry;\nimport java.util.Scanner;\n\npublic class Main {\n\n static class Team{\n String name;\n int id;\n int winP;\n int goal;\n int missgoal;\n int rank=0;\n\n Team(int id,String name,\n int winP,int minssgoal,\n int goal){\n this.id=id;\n this.name=name;\n this.winP=winP;\n this.goal=goal;\n this.missgoal=minssgoal;\n }\n }\n\n int id=0;\n\n HashMap teams;\n\n boolean[][] game=new boolean[4][4];\n List teamlist;\n public void solve() {\n Scanner sc = new Scanner(System.in);\n for(int i=0;i<4;i++){\n game[i][i]=true;\n }\n teams=new HashMap();\n for (int i = 0; i < 5; i++) {\n String name1=sc.next();\n String name2=sc.next();\n\n String param=sc.next();\n int p1=param.charAt(0)-'0';\n int p2=param.charAt(2)-'0';\n\n Team t1,t2;\n if(!teams.containsKey(name1)){\n t1=new Team(id++,name1,0,0,0);\n teams.put(name1,t1);\n }else{\n t1=teams.get(name1);\n }\n if(!teams.containsKey(name2)){\n t2=new Team(id++,name2,0,0,0);\n teams.put(name2,t2);\n }else{\n t2=teams.get(name2);\n }\n\n game[t1.id][t2.id]=true;\n game[t2.id][t1.id]=true;\n t1.goal+=p1;\n t2.goal+=p2;\n t1.missgoal+=p2;\n t2.missgoal+=p1;\n if(p1 p2){\n t1.winP+=3;\n }else{\n t1.winP++;\n t2.winP++;\n }\n }\n\n teamlist=new ArrayList();\n for(Entry team:teams.entrySet()){\n teamlist.add(team.getValue());\n }\n\n refreashRank();\n\n Team berand=null;\n for(Team team:teamlist){\n if(team.name.equals(\"BERLAND\")){\n berand=team;\n break;\n }\n }\n\n for(int i=0;i<4;i++) for(int j=0;j<4;j++)\n pr(game[i][j]);\n\n int lastgameid=0;\n\n Team lastGame=teamlist.get(lastgameid-1);\n\n\n berand.winP+=3;\n int mx=Integer.MAX_VALUE;int my=0;\n for(int x=0;x<=9;x++){\n for(int y=0;y=x-y && y<=my){\n mx=x;\n my=y;\n }\n\n }\n if(x==6 && y==0){\n\n\n }\n berand.goal-=x;\n lastGame.goal-=y;\n berand.missgoal-=y;\n lastGame.missgoal-=x;\n }\n }\n\n\n if(mx==0 && my==0){\n pr(\"IMPOSSIBLE\");\n }else{\n pr(mx+\":\"+my);\n }\n }\n\n public void refreashRank(){\n Collections.sort(teamlist,new Comparator() {\n @Override\n public int compare(Team o1, Team o2) {\n if(o1.winP!=o2.winP){\n return o2.winP-o1.winP;\n }\n if(o1.goal-o1.missgoal!=o2.goal-o2.missgoal){\n return o2.goal-o2.missgoal-(o1.goal-o1.missgoal);\n }\n if(o1.goal!=o2.goal){\n return o2.goal-o1.goal;\n }\n return o2.name.compareTo(o1.name);\n }\n });\n int rank=0;\n for(Team team:teamlist){\n team.rank=rank;\n rank++;\n }\n }\n\n public void run() {\n solve();\n }\n\n public static void main(String[] _) {\n new Main().run();\n }\n\n public static void pr() {\n System.out.println();\n }\n\n public static void pr(Object o) {\n System.out.println(o);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "73ed2f5184e7d09ea3b9efad846827a1", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0} {"lang": "Java 6", "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.Enumeration;\nimport java.util.Hashtable;\nimport java.util.Iterator;\nimport java.util.Properties;\n\n/**\n * Works good for CF\n * @author cykeltillsalu\n */\npublic class C134 {\n\n\t//some local config\n\tstatic boolean test = true;\n\tstatic String testDataFile = \"testdata.txt\";\n\tstatic String feedFile = \"feed.txt\";\n\tCompetitionType type = CompetitionType.CF;\n\tprivate static String ENDL = \"\\n\";\n\n\tclass State{\n\t\t\n\t}\n\t\n\t// solution\n\tprivate void solve() throws Throwable {\n\t\t\n\t\tint n = iread();\n\t\tHashtable[] tables = new Hashtable[n];\n\t\t\n\t\t\n\t\tout.flush();\n\t}\n\t\n\tpublic int iread() throws Exception {\n\t\treturn Integer.parseInt(wread());\n\t}\n\n\tpublic double dread() throws Exception {\n\t\treturn Double.parseDouble(wread());\n\t}\n\n\tpublic long lread() throws Exception {\n\t\treturn Long.parseLong(wread());\n\t}\n\n\tpublic String wread() 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) throws Throwable {\n\t\t\n\t\tif(test){ //run all cases from testfile:\n\t\t\tBufferedReader testdataReader = new BufferedReader(new FileReader(testDataFile));\n\t\t\tString readLine = testdataReader.readLine();\n\t\t\tint casenr = 0;\n\t\t\tout: while (true) {\n\t\t\t\tBufferedWriter w = new BufferedWriter(new FileWriter(feedFile));\n\t\t\t\tif(!readLine.equalsIgnoreCase(\"input\")){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhile (true) {\n\t\t\t\t\treadLine = testdataReader.readLine();\n\t\t\t\t\tif(readLine.equalsIgnoreCase(\"output\")){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tw.write(readLine + \"\\n\");\n\t\t\t\t}\n\t\t\t\tw.close();\n\t\t\t\tSystem.out.println(\"Answer on case \"+(++casenr)+\": \");\n\t\t\t\t\n\t\t\t\tnew C134().solve();\n\t\t\t\tSystem.out.println(\"Expected answer: \");\n\t\t\t\t\n\t\t\t\t\n\t\t\t\twhile (true) {\n\t\t\t\t\treadLine = testdataReader.readLine();\n\t\t\t\t\t\n\t\t\t\t\tif(readLine == null){\n\t\t\t\t\t\tbreak out;\n\t\t\t\t\t}\n\t\t\t\t\tif(readLine.equalsIgnoreCase(\"input\")){\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(readLine);\n\t\t\t\t}\n\t\t\t\tSystem.out.println(\"----------------\");\n\t\t\t}\n\t\t\ttestdataReader.close();\n\t\t} else { // run on server\n\t\t\tnew C134().solve();\n\t\t}\n\t\tout.close();\n\t}\n\n\tpublic C134() throws Throwable {\n\t\tif (test) {\n\t\t\tin = new BufferedReader(new FileReader(new File(feedFile)));\n\t\t}\n\t}\n\n\tInputStreamReader inp = new InputStreamReader(System.in);\n\tBufferedReader in = new BufferedReader(inp);\n\tstatic BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\n\tenum CompetitionType {CF, OTHER};\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43cffcae1265922ad19e53f8a86d1e9e", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.HashMap;\nimport java.util.Collections;\nimport java.util.ArrayList;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Nurlan Sofiyev\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 HashMap hm;\n public ArrayList teams;\n\n public void add(String name, int goal, int missed) {\n\n if (hm.containsKey(name)) {\n hm.get(name).update(goal, missed);\n } else {\n hm.put(name, new Team(name, goal, missed));\n }\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n\n hm = new HashMap<>();\n\n for (int i = 0; i < 5; ++i) {\n String A, B;\n int a, b;\n A = in.next();\n B = in.next();\n String[] temp = in.next().split(\":\");\n a = Integer.parseInt(temp[0]);\n b = Integer.parseInt(temp[1]);\n add(A, a, b);\n add(B, b, a);\n\n }\n teams = new ArrayList<>(hm.values());\n Collections.sort(teams);\n int current = 3;\n Team berland = teams.get(3);\n Team other = teams.get(3);\n String s_other;\n for (int i = 0; i < 3; ++i) {\n if (teams.get(i).name.equals(\"BERLAND\")) {\n current = i;\n berland = teams.get(i);\n } else if (teams.get(i).played == 2) {\n other = teams.get(i);\n }\n }\n\n s_other = other.name;\n\n if (berland.point + 3 < teams.get(1).point) {\n out.println(\"IMPOSSIBLE\");\n return;\n }\n\n for (int diff = 1; diff <= 20; ++diff) {\n for (int goals = diff; goals <= 20; ++goals) {\n int mis = goals - diff;\n berland.update(goals, mis);\n other.update(mis, goals);\n Collections.sort(teams);\n for (int i = 0; i < 2; ++i) {\n if (teams.get(i).name.equals(\"BERLAND\")) {\n out.println(goals + \":\" + mis);\n return;\n }\n\n }\n berland.backup();\n other.backup();\n }\n }\n\n\n out.println(\"IMPOSSIBLE\");\n\n\n }\n\n class Team implements Comparable {\n public String name;\n public int played;\n public int point;\n public int goals;\n public int missed;\n public int t_point;\n public int t_goals;\n public int t_missed;\n\n public void backup() {\n goals -= t_goals;\n missed -= t_missed;\n point -= t_point;\n }\n\n\n public String toString() {\n return (name + \" \" + point + \" \" + goals + \" \" + missed);\n }\n\n public void update(int goals, int missed) {\n if (goals > missed) {\n point += 3;\n t_point = 3;\n } else if (goals == missed) {\n point += 1;\n t_point = 1;\n } else {\n t_point = 0;\n }\n this.goals += goals;\n this.missed += missed;\n t_goals = goals;\n t_missed = missed;\n ++played;\n\n }\n\n public Team(String name, int goals, int missed) {\n this.name = name;\n update(goals, missed);\n }\n\n public Team() {\n\n }\n\n\n public int hashCode() {\n return name.hashCode();\n }\n\n\n public boolean equals(Object obj) {\n return name.equals(obj);\n }\n\n\n public int compareTo(Team o) {\n int temp = o.point - point;\n if (temp != 0) {\n return temp;\n }\n temp = (o.goals - o.missed) - (goals - missed);\n if (temp != 0) {\n return temp;\n }\n temp = (o.goals - goals);\n if (temp != 0) {\n return temp;\n }\n\n return name.compareTo(o.name);\n\n }\n\n }\n\n }\n\n static\n @Documented\n @Retention(RetentionPolicy.CLASS)\n @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n interface NotNull {\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "576ee7246ccb4a7ad8d58767a8bcc683", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tnew CF_55D().run();\n\t}\n}\n\nclass CF_55D {\n\n\tvoid run() {\n\t\tScanner cin = new Scanner(new BufferedInputStream(System.in));\n\t\tPrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\tint t = cin.nextInt() ;\n\t\twhile(t-- > 0){\n\t\t\tlong l = cin.nextLong() , r = cin.nextLong() ;\n\t\t\tcout.println(calculation(r) - calculation(l - 1));\n\t\t}\n cout.flush();\n\t}\n\t\n\tlong calculation(long val){\n\t\tint bit = 0 ;\n\t\twhile(val > 0){\n\t\t\tdight[bit++] = (int) (val % 10) ;\n\t\t\tval /= 10 ;\n\t\t}\n\t\treturn dfs(bit-1, 0, 1, true) ;\n\t}\n\n\tlong dfs(int pos, int sum, int lcm, Boolean isEnd) {\n\t\tif (pos < 0)\n\t\t\treturn sum % lcm == 0 ? 1L : 0L;\n\t\tif (!isEnd && dp[pos][sum][hash[lcm]] != -1)\n\t\t\treturn dp[pos][sum][hash[lcm]];\n\t\tint end = isEnd ? dight[pos] : 9;\n\t\tlong res = 0L;\n\t\tfor (int i = 0; i <= end; i++) {\n\t\t\tres += dfs(pos - 1, (sum * 10 + i) % N, lcm(lcm, i), isEnd && i == end);\n\t\t}\n if(! isEnd) dp[pos][sum][hash[lcm]] = res ;\n return res ;\n\t}\n\n\tfinal int N = 2520;\n\tlong[][][] dp = new long[18][N][48];\n\tint[] dight = new int[18];\n\t\n\tint[] hash = new int[N + 8];\n\t{\n\t\tint cnt = 0;\n\t\tfor (int i = 1; i <= N; i++) {\n\t\t\tif (N % i == 0)\n\t\t\t\thash[i] = cnt++;\n\t\t}\n\t\tfor(int i = 0 ; i < 18 ; i++){\n\t\t\tfor(int j = 0 ; j < N ; j++)\n\t\t\t\tArrays.fill(dp[i][j], -1) ;\n\t\t}\n\t}\n\n\n\n\tint gcd(int x, int y) {\n\t\treturn y == 0 ? x : gcd(y, x % y);\n\t}\n\n\tint lcm(int x, int y) {\n\t\tif(x == 0) return y ;\n\t\tif(y == 0) return x ;\n\t\treturn x / gcd(x, y) * y;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "705e369371cfa3e463b43c6e9bd259f9", "src_uid": "37feadce373f728ba2a560b198ca4bc9", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.HashMap;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author heifrank\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n 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 TaskD {\n long[][][] dp = new long[20][50][3005];\n int[] bits = new int[20];\n Map ds = new HashMap<>();\n int cnt = 0;\n final int MOD = 2520;\n\n int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n void dfs2(int p, int pren) {\n if (p == 0) {\n if (!ds.containsKey(pren)) {\n ds.put(pren, ++cnt);\n }\n return;\n }\n dfs2(p - 1, pren * p / gcd(pren, p));\n dfs2(p - 1, pren);\n }\n\n public TaskD() {\n for (int i = 0; i < dp.length; i++)\n for (int j = 0; j < dp[0].length; j++) {\n Arrays.fill(dp[i][j], -1);\n }\n dfs2(9, 1);\n }\n\n public long dfs(int p, int lcm, int mod, boolean limit) {\n if (p == -1) {\n return mod % lcm == 0 ? 1 : 0;\n }\n int id = ds.get(lcm);\n if (!limit && dp[p][id][mod] != -1) {\n return dp[p][id][mod];\n }\n long ans = 0;\n int end = limit ? bits[p] : 9;\n for (int i = 0; i <= end; i++) {\n ans += dfs(p - 1, i == 0 ? lcm : lcm * i / gcd(lcm, i), (mod * 10 + i) % MOD, limit && i == end);\n }\n if (!limit) {\n dp[p][lcm][mod] = ans;\n }\n return ans;\n }\n\n public long calc(long n) {\n int len = 0;\n while (n > 0) {\n Long t = n % 10;\n bits[len++] = t.intValue();\n n /= 10;\n }\n return dfs(len - 1, 1, 0, true);\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n long x = in.nextLong();\n long y = in.nextLong();\n out.println(calc(y) - calc(x - 1));\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f3edb3963a6107995ac334a7807c1f0c", "src_uid": "37feadce373f728ba2a560b198ca4bc9", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedHashSet;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n// WeekOfCode21\n\npublic class Solution {\n\tpublic static InputReader in;\n\tpublic static PrintWriter out;\n\tpublic static Random ra = new Random(0);\n\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tin = new InputReader(inputStream);\n//\t\tout = new PrintWriter(outputStream, true);\n\t\tout = new PrintWriter(outputStream, false); // enable this for ludicrous speed\n\n\t\tbeautifulNumbers();\n//\t\ttestBM();\n//\t\tborrowingMoney();\n//\t\tlazySorting();\n//\t\ttestLazySorting();\n//\t\tluckBalance();\n//\t\tkangaroo();\n\n\t\tout.close();\n\t}\n\n\tstatic void beautifulNumbers() {\n\t\tint cnt = 0;\n\t\tfor(int i=1; i<=MOD; i++)\n\t\t\tif(MOD%i == 0)\n\t\t\t\tHash[i] = cnt++;\n\n\t\tfor(int i=0; i < dp.length; i++) {\n\t\t\tfor(int j=0; j < dp[0].length; j++) {\n\t\t\t\tArrays.fill(dp[i][j], -1);\n\t\t\t}\n\t\t}\n\n\t\tint ts = in.nextInt();\n\t\tfor (int t = 0; t < ts; t++) {\n\t\t\tlong a = in.nextInt();\n\t\t\tlong b = in.nextInt();\n\t\t\tSystem.out.println((solve(b) - solve(a-1)));\n\t\t}\n\t}\n\n\tstatic final int MOD = 2520;\n\tstatic long[][][] dp = new long[20][50][2550];\n\tstatic int[] dis = new int[20];\n\tstatic int[] Hash = new int[2550];\n\n\tstatic long gcd(long a, long b) {\n\t\treturn b != 0 ? gcd(b,a%b) : a;\n\t}\n\n\tstatic long dfs(int len, int num, int lcm, boolean flag) {\n\t\tif(-1==len) return (num%lcm == 0) ? 1: 0;\n\t\tif(!flag && -1!=dp[len][Hash[lcm]][num]) {\n\t\t\treturn dp[len][Hash[lcm]][num];\n\t\t}\n\t\tlong ans = 0;\n\t\tint end = flag?dis[len]:9;\n\t\tfor(int i=0; i<=end; i++)\n\t\t\tans += dfs(len-1, (num*10+i)%MOD, (int)(i > 0 ? lcm*i/gcd(lcm,i) : lcm), flag && i==end);\n\t\tif(!flag) dp[len][Hash[lcm]][num] = ans;\n\t\treturn ans;\n\t}\n\n\tstatic long solve(long n) {\n\t\tint pos = 0;\n\t\twhile(n > 0) {\n\t\t\tdis[pos++] = (int)n%10;\n\t\t\tn /= 10;\n\t\t}\n\t\treturn dfs(pos-1, 0, 1, true);\n\t}\n\n\tpublic static void testBM() {\n\t\tlong t1 = System.currentTimeMillis();\n\t\tfor (int test = 0; test < 1000000; test++) {\n\t\t\tint N = ra.nextInt(10)+1;\n\t\t\tint M = ra.nextInt(N*(N-1)/2 +1);\n\t\t\tboolean[][] g = new boolean[N][N];\n\t\t\tint[] cost = new int[N];\n\t\t\tfor (int i = 0; i < cost.length; i++) {\n\t\t\t\tcost[i] = ra.nextInt(100);\n\t\t\t}\n\t\t\tfor (int i = 0; i < M && N > 1; i++) {\n\t\t\t\tint a = ra.nextInt(N);\n\t\t\t\tint b = ra.nextInt(N);\n\t\t\t\twhile (a == b) {\n\t\t\t\t\ta = ra.nextInt(N);\n\t\t\t\t\tb = ra.nextInt(N);\n\t\t\t\t}\n\t\t\t\tg[a][b] = true;\n\t\t\t\tg[b][a] = true;\n\t\t\t}\n\t\t\tString r1 = borrowingMoneySlow(N, g, cost);\n\t\t\tString r2 = borrowingMoney(N, g, cost);\n\t\t\tif (!r1.equals(r2)) {\n\t\t\t\tSystem.out.println(\"fail\");\n\t\t\t\tborrowingMoneySlow(N, g, cost);\n\t\t\t\tborrowingMoney(N, g, cost);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(System.currentTimeMillis() - t1);\n\t}\n\n\tpublic static void borrowingMoney() {\n\t\tint N = 0;\n\t\tboolean[][] g;\n\t\tint[] cost;\n\n\t\tN = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tcost = in.nextIntArray(N);\n\t\tg = new boolean[N][N];\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint a = in.nextInt()-1;\n\t\t\tint b = in.nextInt()-1;\n\t\t\tg[a][b] = true;\n\t\t\tg[b][a] = true;\n\t\t}\n\n\t\tSystem.out.println(borrowingMoney(N, g, cost));\n//\t\tSystem.out.println(borrowingMoneySlow(N, g, cost));\n\n\t}\n\n\tpublic static String borrowingMoneySlow(int ns, boolean[][] g, int[] cost) {\n\t\tint len = ns;\n\t\tint N = 1 << len;\n\t\tint[] costF = new int[100*35 +1];\n\t\tfor (int n = 0; n < N; n++) {\n\t\t\tboolean[] active = new boolean[len];\n\t\t\tfor (int i = 0; i < len; i++) {\n\t\t\t\tif (((1 << i) & n) != 0) {\n\t\t\t\t\tactive[i] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint sum = 0;\n\t\t\tboolean v = true;\n\t\t\tfor (int i = 0; i < ns; i++) {\n\t\t\t\tif (!active[i]) {\n\t\t\t\t\tfor (int j = 0; j < ns; j++) {\n\t\t\t\t\t\tif (g[i][j] && !active[j]) {\n\t\t\t\t\t\t\tv = 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\tsum += cost[i];\n\t\t\t\t}\n\t\t\t\tif (!v) {\n\t\t\t\t\tif (i >= 1) {\n\t\t\t\t\t\tSystem.currentTimeMillis();\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (v) {\n\t\t\t\tcostF[sum]++;\n\t\t\t}\n\t\t}\n\t\tfor (int i = costF.length-1; i >= 0; i--) {\n\t\t\tif (costF[i] > 0) {\n\t\t\t\treturn i + \" \" + costF[i];\n\t\t\t}\n\t\t}\n\t\treturn \"\";\n\t}\n\n\tpublic static String borrowingMoney(int N, boolean[][] g, int[] cost) {\n\t\tboolean[] visit;\n\t\tvisit = new boolean[N];\n\t\tHashMap F;\n\t\tF = new HashMap<>();\n\n\t\tlong mx = 0;\n\t\tlong tw = 1;\n\t\tfor (int p = 0; p < visit.length; p++) {\n\t\t\tif (!visit[p]) {\n\t\t\t\tF = new HashMap<>();\n\n\t\t\t\tQueue q = new LinkedList<>();\n\t\t\t\tq.add(p);\n\t\t\t\tboolean start = true;\n\n\t\t\t\twhile (!q.isEmpty()) {\n\t\t\t\t\tint top = q.poll();\n\n\t\t\t\t\tif (!visit[top]) {\n\t\t\t\t\t\tvisit[top] = true;\n\t\t\t\t\t\tHashMap current = F;\n\t\t\t\t\t\tHashMap oldF = new HashMap<>();\n\t\t\t\t\t\tfor (Entry e: current.entrySet()) {\n\t\t\t\t\t\t\toldF.put(e.getKey(), e.getValue());\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (start) {\n\t\t\t\t\t\t\tstart = false;\n\n\t\t\t\t\t\t\t// do nothing\n\t\t\t\t\t\t\tcurrent.put(0L, 0L);\n\n\t\t\t\t\t\t\t// steal here\n\t\t\t\t\t\t\tcurrent.put(1L << top, (long)cost[top]);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// steal here\n\n\t\t\t\t\t\t\tfor (Entry e: oldF.entrySet()) {\n\t\t\t\t\t\t\t\tif (!getBit(e.getKey(), top)) {\n\t\t\t\t\t\t\t\t\tboolean stillHere = true;\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\t// top will have left if someone robbed next door\n\t\t\t\t\t\t\t\t\t\tif (g[top][i] && getBit(e.getKey(), i)) {\n\t\t\t\t\t\t\t\t\t\t\tstillHere = false;\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\tif (stillHere) {\n\t\t\t\t\t\t\t\t\t\tlong max = e.getValue();\n\t\t\t\t\t\t\t\t\t\tlong fmask = e.getKey() | 1L << top;\n\n\t\t\t\t\t\t\t\t\t\tif (max > -1) {\n\t\t\t\t\t\t\t\t\t\t\tmax += cost[top];\n\t\t\t\t\t\t\t\t\t\t\tif (!current.containsKey(fmask) || current.get(fmask) < max) {\n\t\t\t\t\t\t\t\t\t\t\t\tcurrent.put(fmask, max);\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\n\t\t\t\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\t\t\t\tif (g[top][i]) {\n\t\t\t\t\t\t\t\tq.add(i);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If all of a edge's neighbours have been visited, it's removed from the searchable set\n\t\t\t\t\t\t// and the maximum of all of them are added back because they cannot influence future\n\t\t\t\t\t\t// events.\n\n\t\t\t\t\t\tfor (Entry e: oldF.entrySet()) {\n\t\t\t\t\t\t\tif (!getBit(e.getKey(), top)) {\n\t\t\t\t\t\t\t\tboolean stillHere = true;\n\t\t\t\t\t\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\t\t\t\t\t\t// top will have left if someone robbed next door\n\t\t\t\t\t\t\t\t\tif (g[top][i] && getBit(e.getKey(), i)) {\n\t\t\t\t\t\t\t\t\t\tstillHere = false;\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 (stillHere) {\n\t\t\t\t\t\t\t\t\tlong max = e.getValue();\n\t\t\t\t\t\t\t\t\tlong fmask = e.getKey() | 1L << top;\n\n\t\t\t\t\t\t\t\t\tif (max > -1) {\n\t\t\t\t\t\t\t\t\t\tmax += cost[top];\n\t\t\t\t\t\t\t\t\t\tif (!current.containsKey(fmask) || current.get(fmask) < max) {\n\t\t\t\t\t\t\t\t\t\t\tcurrent.put(fmask, max);\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\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlong max = -1;\n\t\t\t\tfor (Entry e: F.entrySet()) {\n\t\t\t\t\tif (e.getValue() > max) {\n\t\t\t\t\t\tmax = e.getValue();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlong ways = 0;\n\t\t\t\tfor (Entry e: F.entrySet()) {\n\t\t\t\t\tif (e.getValue() == max) {\n\t\t\t\t\t\tways++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmx += max;\n\t\t\t\ttw *= ways;\n\t\t\t}\n\t\t}\n\n\n\n\t\t//System.out.println(max + \" \" + ways + \" \" + Long.toBinaryString(fmask));\n\n\t\treturn (mx + \" \" + tw);\n\t}\n\n\tpublic static String borrowingMoney2(int N, boolean[][] g, int[] cost) {\n\t\tboolean[] visit;\n\t\tvisit = new boolean[N];\n\t\tHashMap F;\n\t\tF = new HashMap<>();\n\n\t\tlong mx = 0;\n\t\tlong tw = 1;\n\t\tfor (int i = 0; i < visit.length; i++) {\n\t\t\tif (!visit[i]) {\n\t\t\t\tF = new HashMap<>();\n\n\t\t\t\tdfs(true, i, N, g, visit, cost, F);\n\n\t\t\t\tlong max = -1;\n\t\t\t\tlong fmask = 0;\n\t\t\t\tfor (Entry e: F.entrySet()) {\n\t\t\t\t\tif (e.getValue() > max) {\n\t\t\t\t\t\tmax = e.getValue();\n\t\t\t\t\t\tfmask = e.getKey();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlong ways = 0;\n\t\t\t\tfor (Entry e: F.entrySet()) {\n\t\t\t\t\tif (e.getValue() == max) {\n\t\t\t\t\t\tways++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmx += max;\n\t\t\t\ttw *= ways;\n\t\t\t}\n\t\t}\n\n\n\n\t\t//System.out.println(max + \" \" + ways + \" \" + Long.toBinaryString(fmask));\n\n\t\treturn (mx + \" \" + tw);\n\t}\n\n\n\tpublic static void dfs(boolean start, int top, int N, boolean[][] g, boolean[] visit, int[] cost, HashMap F) {\n\t\tif (!visit[top]) {\n\t\t\tvisit[top] = true;\n\t\t\tHashMap current = F;\n\t\t\tHashMap oldF = new HashMap<>();\n\t\t\tfor (Entry e: current.entrySet()) {\n\t\t\t\toldF.put(e.getKey(), e.getValue());\n\t\t\t}\n\t\t\tif (start) {\n\n\t\t\t\t// do nothing\n\t\t\t\tcurrent.put(0L, 0L);\n\n\t\t\t\t// steal here\n\t\t\t\tlong fmask = 0;\n\t\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\t\tif (g[top][i]) {\n\t\t\t\t\t\tfmask |= 1L << i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcurrent.put(fmask, (long)cost[top]);\n\t\t\t} else {\n\t\t\t\t// steal here\n\n\t\t\t\tfor (Entry e: oldF.entrySet()) {\n\t\t\t\t\tif (!getBit(e.getKey(), top)) {\n\t\t\t\t\t\tlong max = e.getValue();\n\t\t\t\t\t\tlong fmask = e.getKey();\n\n\t\t\t\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\t\t\t\tif (g[top][i]) {\n\t\t\t\t\t\t\t\tfmask |= 1L << i;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (max > -1) {\n\t\t\t\t\t\t\tmax += cost[top];\n\t\t\t\t\t\t\tif (!current.containsKey(fmask) || current.get(fmask) < max) {\n\t\t\t\t\t\t\t\tcurrent.put(fmask, max);\n\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (current.get(fmask) == max) {\n//\t\t\t\t\t\t\t\tcurrent.put(fmask, max);\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\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tif (g[top][i]) {\n\t\t\t\t\tdfs(false, i, N, g, visit, cost, F);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static int clearBit(int x, int i) {\n\t\treturn (x & ~(1 << i));\n\t}\n\n\tpublic static int setBit(int x, int i) {\n\t\treturn (x | (1 << i));\n\t}\n\n\tpublic static boolean getBit(long x, int i) {\n\t\treturn (x & (1L << i)) != 0;\n\t}\n\n\tpublic static void testLazySorting() {\n\t\tint[] a = new int[4];\n\t\tfor (int i = 0; i < 10; i++) {\n\t\t\tfor (int j = 0; j < a.length; j++) {\n\t\t\t\ta[j] = ra.nextInt(10);\n\t\t\t}\n\t\t\tdouble r1 = slowLazySorting(a.length, a);\n\t\t\tdouble r2 = lazySorting(a.length, a);\n\t\t\tint t = 0;\n\t\t\twhile (Math.abs(r1 - r2) > 0.1 && t < 10) {\n\t\t\t\tt++;\n\t\t\t\tr1 = slowLazySorting(a.length, a);\n\t\t\t\tr2 = lazySorting(a.length, a);\n\t\t\t}\n\t\t\tif (t == 10) {\n\t\t\t\tSystem.out.println(\"fail\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static void lazySorting() {\n\t\tint n = in.nextInt();\n\t\tint[] a = in.nextIntArray(n);\n\t\tSystem.out.println(String.format(\"%.6f\", lazySorting(n, a)));\n//\t\tSystem.out.println(String.format(\"%.6f\", slowLazySorting(n, a)));\n\t}\n\n\tpublic static double slowLazySorting(int n, int[] a) {\n\t\tArrayList b = new ArrayList<>();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tb.add(a[i]);\n\t\t}\n\t\tArrays.sort(a);\n\t\tint sum = 0;\n\t\tint games = 1000000;\n\t\tfor (int i = 0; i < games; i++) {\n\t\t\tboolean wrong = false;\n\t\t\tint time = 0;\n\n\t\t\tfor (int j = 0; j < a.length; j++) {\n\t\t\t\tif (a[j] != b.get(j)) {\n\t\t\t\t\twrong = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\twhile (wrong) {\n\t\t\t\twrong = false;\n\t\t\t\ttime++;\n\t\t\t\tCollections.shuffle(b);\n\t\t\t\tfor (int j = 0; j < a.length; j++) {\n\t\t\t\t\tif (a[j] != b.get(j)) {\n\t\t\t\t\t\twrong = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!wrong) {\n\t\t\t\t\tsum += time;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn sum / (double)games;\n\t}\n\n\n\tpublic static double lazySorting(int n, int[] a) {\n\t\tint[] f = new int[101];\n\t\tint[] b = a.clone();\n\t\tArrays.sort(b);\n\t\tif (Arrays.equals(a, b)) {\n\t\t\treturn 0;\n\t\t}\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tf[a[i]]++;\n\t\t}\n\t\tlong c = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tc *= i;\n\t\t}\n\t\tfor (int i = 0; i < f.length; i++) {\n\t\t\twhile (f[i] > 0) {\n\t\t\t\tc /= f[i];\n\t\t\t\tf[i]--;\n\t\t\t}\n\t\t}\n\t\tdouble p = 1.0/c;\n\t\treturn 1/p;\n\t}\n\n\tpublic static void luckBalance() {\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint[] luck = new int[n];\n\t\tint[] imp = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tluck[i] = in.nextInt();\n\t\t\timp[i] = in.nextInt();\n\t\t}\n\t\tSystem.out.println(luckBalance(n, k, luck, imp));\n\t}\n\n\tpublic static long luckBalance(int n, int k, int[] luck, int[] imp) {\n\t\tArrayList important = new ArrayList<>();\n\t\tlong balance = 0;\n\t\tfor (int i = 0; i < imp.length; i++) {\n\t\t\tif (imp[i] == 1) {\n\t\t\t\timportant.add(luck[i]);\n\t\t\t} else {\n\t\t\t\tbalance += luck[i];\n\t\t\t}\n\t\t}\n\t\tCollections.sort(important);\n\t\tCollections.reverse(important);\n\t\tfor (int i = 0; i < important.size(); i++) {\n\t\t\tif (i < k) {\n\t\t\t\tbalance += important.get(i);\n\t\t\t} else {\n\t\t\t\tbalance -= important.get(i);\n\t\t\t}\n\t\t}\n\t\treturn balance;\n\t}\n\n\tpublic static void kangaroo() {\n\t\tint x1 = in.nextInt();\n\t\tint v1 = in.nextInt();\n\t\tint x2 = in.nextInt();\n\t\tint v2 = in.nextInt();\n\t\tif (kangaroo(x1, v1, x2, v2)) {\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\tpublic static boolean kangaroo(int x1, int v1, int x2, int v2) {\n\t\tint dx = x1-x2;\n\t\tint dv = v2-v1;\n\t\tif (dv == 0) {\n\t\t\treturn dx == 0;\n\t\t}\n\t\tif (((Math.abs(dx) % Math.abs(dv)) == 0) && dx / (double)dv > 0) {\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"serial\")\n\tpublic static class Counter extends HashMap {\n\t\tpublic Counter() {\n\t\t\tsuper();\n\t\t}\n\t\tpublic void add(T key) {\n\t\t\tthis.add(key, 1);\n\t\t}\n\t\tpublic void add(T key, int count) {\n\t\t\tInteger i = this.get(key);\n\t\t\tif (i == null) {\n\t\t\t\tthis.put(key, count);\n\t\t\t} else {\n\t\t\t\tthis.put(key, i+count);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {return Integer.parseInt(next());}\n\t\tpublic long nextLong() {return Long.parseLong(next());}\n\t\tpublic double nextDouble() {return Double.parseDouble(next());}\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < a.length; i++) a[i] = this.nextLong();\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 < a.length; i++) a[i] = this.nextInt();\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2ffab215396c5d87e368b68630f21b2a", "src_uid": "37feadce373f728ba2a560b198ca4bc9", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Zyflair Griffane\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tPandaScanner in = new PandaScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tD solver = new D();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass D {\n final int MAX = 2520;\n long[][][] memo = new long[19][48][MAX];\n int[] idx = new int[MAX + 1];\n int[] digit = new int[19];\n public void solve(int testNumber, PandaScanner in, PrintWriter out) {\n\n for (int i = 0; i < 19; i++) {\n for (int j = 0; j < 48; j++) {\n Arrays.fill(memo[i][j], -1);\n }\n }\n for (int i = 1; i < MAX + 1; i++) {\n idx[i] = idx[i - 1] + (MAX % i == 0 ? 1 : 0);\n }\n\n int t = in.nextInt();\n for (int i = 0; i < t; i++) {\n long l = in.nextLong();\n long r = in.nextLong();\n out.println(getBeautiful(r) - getBeautiful(l - 1));\n }\n }\n\n public long getBeautiful(long x) {\n int length = 0;\n for (; x > 0; length++) {\n digit[length] = (int) (x % 10);\n x /= 10;\n }\n return recurse(length - 1, 1, 0, false);\n }\n\n public long recurse(int pow, int lcm, int mod, boolean under) {\n if (pow == -1) {\n return mod % lcm == 0 ? 1 : 0;\n }\n if (under && memo[pow][idx[lcm]][mod] > -1) {\n return memo[pow][idx[lcm]][mod];\n }\n int limit = under ? 9 : digit[pow];\n long res = 0;\n for (int i = 0; i <= limit; i++) {\n res += recurse(pow - 1, i < 2 ? lcm : (i * lcm / gcd(i, lcm)), (mod * 10 + i) % MAX, under || i < limit);\n }\n return under ? memo[pow][idx[lcm]][mod] = res : res;\n }\n\n public int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n}\n\nclass PandaScanner {\n public BufferedReader br;\n public StringTokenizer st;\n public InputStream in;\n\n public PandaScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(this.in = in));\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n }\n catch (Exception e) {\n return null;\n }\n }\n\n public String next() {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine().trim());\n return next();\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "61167ec6500bbe563d6c76a018dd73cb", "src_uid": "37feadce373f728ba2a560b198ca4bc9", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.awt.geom.QuadCurve2D;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists())\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tlong time1 = System.currentTimeMillis();\n\t\t\t\t\tnew Main().run();\n\t\t\t\t\tlong time2 = System.currentTimeMillis();\n\t\t\t\t\tSystem.err.println(\"Time \" + (time2 - time1) + \" ms\");\n\t\t\t\t} catch (Throwable e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t\texit(999);\n\t\t\t\t}\n\t\t\t}\n\t\t}, \"1\", 1 << 23).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tin.close();\n\t\tout.close();\n\t}\n\n\tprivate void solve() throws IOException {\n\t\tlong n = nextLong();\n\t\tif (n % 3 != 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tn /= 3;\n\t\t\n\t\tSet set = new TreeSet(new Comparator() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(long[] o1, long[] o2) {\n\t\t\t\tfor (int i = 0; i < o1.length; i++)\n\t\t\t\t\tif (o1[i] != o2[i])\n\t\t\t\t\t\treturn o1[i] < o2[i] ? -1 : 1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t\t\n\t\tfor (long x = 1L; x * x * x <= n; x++) {\n\t\t\tif (n % x != 0)\n\t\t\t\tcontinue;\n\t\t\tlong m = n / x;\n\t\t\tfor (long a = 1; 2 * a < x; a++) {\n\t\t\t\tdouble[] w = new double[3];\n\t\t\t\tlong b = x - a;\n\t\t\t\tw[0] = a * b - m;\n\t\t\t\tw[1] = a + b;\n\t\t\t\tw[2] = 1;\n\t\t\t\tint sl = QuadCurve2D.solveQuadratic(w);\n\t\t\t\tfor (int i = 0; i < sl; i++) {\n\t\t\t\t\tlong c = (long)(w[i] + 0.001);\n\t\t\t\t\tif (c > 0 && (a + c) * (b + c) == m) {\n\t\t\t\t\t\tlong[] q = new long[] { a, b, c };\n\t\t\t\t\t\tsort(q);\n\t\t\t\t\t\tset.add(q);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong[] f = {1, 1, 3, 6};\n\t\t\n\t\tlong ans = 0;\n\t\tfor (long[] t : set) {\n\t\t\tint count = 1;\n\t\t\tif (t[0] != t[1])\n\t\t\t\tcount++;\n\t\t\tif (t[1] != t[2])\n\t\t\t\tcount++;\n\t\t\tans += f[count];\n\t\t}\n\t\t\n//\t\tSystem.err.println(set.size());\n//\t\tSystem.err.println(ans / 39090.);\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tlong pw3(long a) {\n\t\treturn a * a * a;\n\t}\n\n\tclass T implements Comparable {\n\t\tlong a, b, c;\n\n\t\tpublic T(long... x) {\n\t\t\tsort(x);\n\t\t\tthis.a = x[0];\n\t\t\tthis.b = x[1];\n\t\t\tthis.c = x[2];\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(T t) {\n\t\t\tint cmp1 = Long.compare(a, t.a);\n\t\t\tif (cmp1 != 0)\n\t\t\t\treturn cmp1;\n\t\t\tint cmp2 = Long.compare(b, t.b);\n\t\t\tif (cmp2 != 0)\n\t\t\t\treturn cmp2;\n\t\t\treturn Long.compare(c, t.c);\n\t\t}\n\t\t\n\t}\n\t\n\tvoid chk(boolean b) {\n\t\tif (b)\n\t\t\treturn;\n\t\tSystem.out.println(new Error().getStackTrace()[1]);\n\t\texit(999);\n\t}\n\tvoid deb(String fmt, Object... args) {\n\t\tSystem.out.printf(Locale.US, fmt + \"%n\", args);\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9b68769f0e76e3b060b34c1f934ee167", "src_uid": "07e58a46f2d562a44b7c771edad361b4", "difficulty": 2400.0} {"lang": "Java 7", "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\tvoid solve() throws IOException {\n\t\tlong n = nextLong();\n\t\tif (n % 3 != 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\n\t\tn /= 3;\n\n\t\tArrayList divAL = new ArrayList<>();\n\t\tfor (long i = 1; i * i <= n; i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\tdivAL.add(i);\n\t\t\t\tif (i * i != n)\n\t\t\t\t\tdivAL.add(n / i);\n\t\t\t}\n\t\t}\n\n\t\tCollections.sort(divAL);\n\n\t\tlong[] div = new long[divAL.size()];\n\t\tfor (int i = 0; i < div.length; i++)\n\t\t\tdiv[i] = divAL.get(i);\n\t\t\n\t\tint ans = 0;\n\t\tfor (int bigInd = 0; bigInd < div.length; bigInd++) {\n\t\t\tlong big = div[bigInd];\n\t\t\tlong rest = n / big;\n\t\t\t\n\t\t\tfor (int smallInd = 0; smallInd <= bigInd; smallInd++) {\n\t\t\t\tlong small = div[smallInd];\n\t\t\t\tif (small * small > rest)\n\t\t\t\t\tbreak;\n\t\t\t\tif (rest % small != 0)\n\t\t\t\t\tcontinue;\n\t\t\t\tlong mid = rest / small;\n\t\t\t\tif (mid <= big && small + mid >= big) {\n\t\t\t\t\tif (((big ^ mid ^ small) & 1) == 0) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (big == mid && mid == small)\n\t\t\t\t\t\t\tans++;\n\t\t\t\t\t\telse if (big == mid || mid == small)\n\t\t\t\t\t\t\tans += 3;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tans += 6;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tC() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0b97cfc8b1feb2c1fe1945210fc0f925", "src_uid": "07e58a46f2d562a44b7c771edad361b4", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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\n\tlong n;\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tn = in.nextLong();\n\t\tif (n % 3 != 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tn /= 3;\n\t\tint ans = 0;\n\t\tfor (long ab = 2; ab * ab * ab <= n; ++ab) {\n\t\t\tif (n % ab != 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong left = n / ab;\n\t\t\tlong to = (long) Math.sqrt(left);\n\t\t\tfor (long a = 0; a <= ab / 2; ++a) {\n\t\t\t\tlong b = ab - a;\n\t\t\t\tlong A = 1;\n\t\t\t\tlong B = ab;\n\t\t\t\tlong C = a * b - left;\n\t\t\t\tlong discr = B * B - 4 * A * C;\n\t\t\t\tif (discr < 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong root = (long) Math.sqrt(discr);\n\t\t\t\tif (root * root < discr) {\n\t\t\t\t\t++root;\n\t\t\t\t}\n\t\t\t\tif (root * root != discr) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong c = (-B + root) / 2 / A;\n\t\t\t\tif (c >= b) {\n\t\t\t\t\tlong mult = (a + c) * (b + c);\n\t\t\t\t\tif (mult == left) {\n\t\t\t\t\t\tint cur = 1;\n\t\t\t\t\t\tif (b > a) {\n\t\t\t\t\t\t\tcur *= 2;\n\t\t\t\t\t\t\tif (c > b) {\n\t\t\t\t\t\t\t\tcur *= 3;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (c > b) {\n\t\t\t\t\t\t\tcur *= 2;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tans += cur;\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\nclass InputReader {\n\tprivate final BufferedReader reader;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\tpublic String next() {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tString line = reader.readLine();\n\t\t\t\tif (line == null) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\ttokenizer = new StringTokenizer(line);\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\t}\n\nclass OutputWriter extends PrintWriter {\n\n\tpublic OutputWriter(Writer out) {\n\t\tsuper(out);\n\t}\n\n\tpublic OutputWriter(OutputStream out) {\n\t\tsuper(out);\n\t}\n\n\t}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3ab1377a6450eb508191f9656bc0dbc3", "src_uid": "07e58a46f2d562a44b7c771edad361b4", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n long M = new Scanner(System.in).nextLong();\n int cnt = 0;\n\n\n if (M % 6 == 0) {\n M /= 3;\n long[] divs = new long[1000000];\n int nd = 0;\n for (long i = 2; i * i <= M; i++)\n if (M % i == 0) {\n long d2 = M / i;\n divs[nd++] = i;\n if (d2 != i)\n divs[nd++] = d2;\n }\n Arrays.sort(divs, 0, nd);\n\n\n for (int pi = 0; pi < nd; ++pi) {\n long i = divs[pi];\n if (i * i * i > M) break;\n\n long M2 = M / i;\n for (int pj = pi; pj < nd; ++pj)\n if (M2 % divs[pj] == 0) {\n long j = divs[pj];\n long k = M2 / j;\n\n if (k < j) break;\n if (i + j > k && (i + j + k) % 2 == 0) {\n if (i == j && i == k)\n ++cnt;\n else if (i == j || i == k || j == k)\n cnt += 3;\n else\n cnt += 6;\n }\n\n }\n\n }\n\n\n System.out.println(cnt);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "51cdeb9f5cb72043afabf2615ac6728d", "src_uid": "07e58a46f2d562a44b7c771edad361b4", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class template1{\n\tpublic static void main(String[] main) throws Exception{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = Integer.parseInt(st.nextToken());\n long[] fact = new long[n];\n long[] pow = new long[n];\n int mod = 1000000007;\n fact[0] = 1;\n pow[0] = 2;\n for(int i = 1; i < n; i++){\n fact[i] = ((i+1)*fact[i])%mod;\n pow[i] = (2*pow[i])%mod;\n }\n out.println((fact[n-1] - pow[n-1] + mod)%mod)\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "14fb4bf5abacb227b5da115e3ab03db9", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class vivek{ \n static class FastReader \n { \n\n BufferedReader br; \n StringTokenizer st; \n\n public FastReader() \n { \n br = new BufferedReader(new 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 char nextChar()\n {\n return next().charAt(0);\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 int[] nextArray(int rows)\n {\n int arr[] = new int[rows]; \n for (int i = 0; i < rows; i++)\n arr[i] = nextInt();\n return arr;\n }\n\n long[] nextLongArray(int rows)\n {\n long arr[] = new long[rows]; \n for (int i = 0; i < rows; i++)\n arr[i] = nextLong();\n return arr;\n }\n\n char[] nextCharArray(int rows)\n {\n char arr[] = new char[rows];\n for (int i = 0; i < rows; i++)\n arr[i] = next().charAt(0);\n return arr;\n }\n\n int[][] nextMatrix(int rows, int columns)\n {\n int mat[][] = new int[rows][columns];\n for (int i = 0; i < rows; i++)\n {\n for (int j = 0; j < columns; j++)\n {\n mat[i][j] = nextInt();\n }\n }\n return mat;\n }\n }\n public static void main(String args[]){\n FastReader sc=new FastReader();\n PrintWriter p=new PrintWriter(System.out);\n int n=sc.nextInt();\n int m=1000000007;\n int f=1;\n int p=1;\n for(int i=2;i=0;--i) {\n inv[i] = (inv[i+1] * 1L * (i + 1L)) % LMOD;\n }\n int n = ni();\n long ans = 0;\n for(int i=1;i<=n;i++) {\n if(i==1 || i==n) {\n ++ans;\n } else {\n long tmp = nCr(n-1, i-1);\n ans += tmp;\n ans %= LMOD;\n }\n }\n long ans2 = fact[n] - ans;\n ans2 %= LMOD;\n if(ans2<0) ans2 += LMOD;\n ans2 %= LMOD;\n pn(ans2);\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 \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 a\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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "932dbd4546295b342f52a1ed0961a384", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class d2prac implements Runnable \n{\n private boolean console=false;\n \n \n public void solve() \n {\n \tint i;\n \tint n=in.ni();\n \tlong m=1000000007;\n \tlong ans=0;\n \tlong fact[]=new long[n+1];\n \tif(n==3)\n \t{\n \t\tout.println(2);\n \t\tcontinue;\n \t}\n \tfact[4]=8;\n \tfor(i=5;i<=n;i++)\n \t\tfact[i]=((fact[i-1])*2)%m;\n \tlong sum=1;\n \tfor(i=1;i<=n;i++)\n \t\tsum=(sum*i)%m;\n \tans = ((sum - fact[n])%m)+m;\n \tout.println(ans%m);\n }\n @Override\n public void run() {\n try { init(); } \n catch (FileNotFoundException e) { e.printStackTrace(); }\n \n int t= 1;\n \n while (t-->0) {\n solve();\n out.flush(); }\n }\n private FastInput in; private PrintWriter out;\n public static void main(String[] args) throws Exception {\t new d2prac().run();\t }\n \n private void init() throws FileNotFoundException {\n InputStream inputStream = System.in; \t OutputStream outputStream = System.out;\n try { if (!console && System.getProperty(\"user.name\").equals(\"sachan\")) {\n outputStream = new FileOutputStream(\"/home/sachan/Desktop/output.txt\");\n inputStream = new FileInputStream(\"/home/sachan/Desktop/input.txt\"); \t}\n }\tcatch (Exception ignored) {\t}\n out = new PrintWriter(outputStream); \t in = new FastInput(inputStream);\n }\n static class FastInput { InputStream obj;\n \tpublic FastInput(InputStream obj) {\tthis.obj = obj;\t}\n byte inbuffer[] = new byte[1024]; int lenbuffer = 0, ptrbuffer = 0;\n int readByte() { if (lenbuffer == -1) throw new InputMismatchException();\n if (ptrbuffer >= lenbuffer) { ptrbuffer = 0;\n try { lenbuffer = obj.read(inbuffer); }\n catch (IOException e) { throw new InputMismatchException(); } } \n if (lenbuffer <= 0) return -1;return inbuffer[ptrbuffer++]; }\n \n String ns() { int b = skip();StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b)))\t { sb.appendCodePoint(b);b = readByte(); }return sb.toString();}\n \n int ni() { int num = 0, b;boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') { minus = true;b = readByte(); }\n while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else {\n return minus ? -num : num; }b = readByte(); }}\n \n long nl() { long num = 0;int b;boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') { minus = true;b = readByte(); }\n while (true) { if (b >= '0' && b <= '9') { num = num * 10L + (b - '0'); } else {\n return minus ? -num : num; }b = readByte(); } }\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 float nf() {return Float.parseFloat(ns());}\n double nd() {return Double.parseDouble(ns());}\n char nc() {return (char) skip();}\n }\n}\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b9e3878ce763679b670ad087cc174377", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import static java.lang.Math.acos;\nimport static java.lang.Math.cos;\nimport static java.lang.Math.sin;\nimport static java.lang.Math.sqrt;\nimport static java.lang.System.in;\nimport static java.lang.System.out;\nimport java.io.*;\nimport java.util.*;\n\npublic class A227 {\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 void run() throws IOException {\n\t\tString input;\n\t\tString[] inputArray;\n\t\tP [] ver = new P[3];\n\t\tfor ( int i =0; i<3; i++){\n\t\t\tinput = br.readLine();\n\t\t\tinputArray = input.split(\" \");\n\t\t\tint x = Integer.valueOf(inputArray[0]);\n\t\t\tint y = Integer.valueOf(inputArray[1]);\n\t\t\tver[i] = new P(x,y);\n\t\t}\n\t\tdouble ans = P.ccw(ver[0], ver[1], ver[2]);\n\t\tif (ans==-1) ln(\"RIGHT\");\n\t\telse if (ans==1) ln(\"LEFT\");\n\t\telse ln(\"TOWARDS\");\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew A227().run();\n\t}\n\tpublic static void ln(Object obj) {\n\t\tout.println(obj);\n\t}\n\tstatic class P{\n\t\t//geo\n\t\t\tstatic final double EPS=1e-10;\n\t\t\tstatic final double INF = 1<<31;\n\t\t\tstatic final double PI = Math.PI;\n\t\t\tstatic int signum(double x){\n\t\t\t\treturn x<-EPS?-1:x>EPS?1:0;\n\t\t\t}\n\t\tstatic Comparator

comp=new Comparator

(){\n\t\t\tpublic int compare(P p1, P p2) {\n\t\t\t\treturn signum(p1.x-p2.x)!=0?signum(p1.x-p2.x):signum(p1.y-p2.y);\n\t\t\t}\n\t\t};\n\t\tpublic static final P O=new P(0,0);\n\t\tfinal double x,y;\n\t\tP(double _x,double _y){\n\t\t\tx=_x;y=_y;\n\t\t}\n\t\t//\u56db\u5247\n\t\tP add(P a){\n\t\t\treturn new P(x+a.x,y+a.y);\n\t\t}\n\t\tP sub(P a){\n\t\t\treturn new P(x-a.x,y-a.y);\n\t\t}\n\t\tP mul(P a){\n\t\t\treturn new P(x*a.x-y*a.y,x*a.y+y*a.x);\n\t\t}\n\t\tP div(P a){\n\t\t\tdouble d2=a.dist2(O);\n\t\t\treturn new P(dot(a,this)/d2,cross(a,this)/d2);\n\t\t}\n\t\t//\u5171\u5f79\n\t\tP conj(){\n\t\t\treturn new P(x,-y);\n\t\t}\n\t\t//\u5185\u7a4d\u3000a\u30fbb=|a||b|cos\u03b8=a.x*b.x+a.y*b.y\n\t\tstatic double dot(P a,P b){\n\t\t\treturn a.x*b.x+a.y*b.y;\n\t\t}\n\t\t//\u5916\u7a4d\u3000a\u00d7b=|a||b|sin\u03b8=a.x*b.y-a.y*b.x\n\t\tstatic double cross(P a,P b){\n\t\t\treturn a.x*b.y-a.y*b.x;\n\t\t}\n\t\t//\u4e8c\u4e57\u8ddd\u96e2\n\t\tdouble dist2(P p){\n\t\t\treturn (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y);\n\t\t}\n\t\t//a,b\u9593\u306e\u8ddd\u96e2\n\t\tdouble dist(P p){\n\t\t\treturn sqrt(dist2(p));\n\t\t}\n\t\tpublic double norm(){\n\t\t\treturn dist(O);\n\t\t}\n\t\t// a\u2192b\u2192c\u3068\u9032\u3080\u3068\u304d\u306e\u5411\u304d\n\t\tstatic int ccw(P a,P b,P c){\n\t\t\tb=b.sub(a);c=c.sub(a);\n\t\t\tif(cross(b,c)>EPS)return 1;//counter clockwise\n\t\t\tif(cross(b,c)<-EPS)return -1;//clockwise\n\t\t\tif(dot(b,c)<-EPS)return 2;//c--a--b on line\n\t\t\tif(b.norm()=0?s:2*PI-s;\n\t\t}\n\t\t//AB\u3068BC\u304c\u306a\u3059\u89d2\u5ea6\uff1aAB\u304b\u3089\u307f\u3066\u6642\u8a08\u5468\u308a 0<=x<2pi\n\t\tstatic double arg(P a,P b, P c){\n\t\t\tdouble angleA = P.arg(a,b);\n\t\t\tdouble angleB = P.arg(b,c);\n\t\t\tdouble angle = Math.PI+angleA-angleB;\n\t\t\tif (angle-2*Math.PI>EPS) angle-=2*Math.PI;\n\t\t\tif (angleo.add June 6\n\t\tP rotate(P o,double arg){\n\t\t\treturn o.add(this.sub(o).mul(new P(cos(arg),sin(arg))));\n\t\t}\n\t\t//\u2192OA,\u2192OB\u306e\u9762\u7a4d\u306e2\u500d\n\t\tstatic double S2(P a,P b,P o){\n\t\t\treturn cross(a.sub(o),b.sub(o));\n\t\t}\n\t\tstatic double S(P a,P b,P o){\n\t\t\treturn S2(a,b,o)/2;\n\t\t}\n\t\t//\u7d76\u5bfe\u5024\u3068\u504f\u89d2\u304b\u3089\u5ea7\u6a19\u3092\u53d6\u5f97\n\t\tstatic P polar(double abs,double arg){\n\t\t\treturn new P(abs*cos(arg),abs*sin(arg));\n\t\t}\n\t\t// ?\n\t\tstatic P proj(P p,P o){\n\t\t\treturn o.mul(new P(dot(p,o)/o.norm(),0));\n\t\t}\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif(obj instanceof P){\n\t\t\t\tP p=(P)obj;\n\t\t\t\treturn signum(x-p.x)==0 && signum(y-p.y)==0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn \"(\"+x+\",\"+y+\")\";\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "82bc465a6e4db344615839098414d8c1", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class TaskA {\n\n\tpublic static void main(String[] args) {\n\t\tScanner reader = new Scanner(System.in);\n\t\tint ax = reader.nextInt();\n\t\tint ay = reader.nextInt();\n\t\tint bx = reader.nextInt();\n\t\tint by = reader.nextInt();\n\t\tint cx = reader.nextInt();\n\t\tint cy = reader.nextInt();\n\t\tTod a = new Tod (ax, ay);\n\t\tTod b = new Tod (bx, by);\n\t\tTod c = new Tod (cx, cy);\n\t\tsolutionA (new Line(a, b), c);\n\t}\n\t\t\n\tstatic void solutionA (Line ab, Tod c) {\n\t\tint x = ((c.x * ab.koeffX) + (c.y * ab.koeffY) + ab.c);\n\t\tif (x == 0) System.out.println (\"TOWARDS\");\n\t\telse if (x > 0) System.out.println (\"RIGHT\");\n\t\telse System.out.println (\"LEFT\");\n\t}\n\n\n\tclass Tod {\n\t\tint x;\n\t\tint y;\n\t\tTod (int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t}\n\t\n\tclass Line {\n\t\tint koeffX;\n\t\tint koeffY;\n\t\tint c;\n\t\tLine (Tod a, Tod b) {\n\t\t\tkoeffX = (b.y - a.y);\n\t\t\tkoeffY = (a.x - b.x);\n\t\t\tc = (b.x*a.y - a.x*b.y);\n\t\t}\n\t}\n}\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3d72cc25ee24c15f1c813dae5da7997d", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n public static void main(String[] Args) throws NumberFormatException, IOException {\n new Solver().Run();\n }\n\n PrintWriter pw;\n StringTokenizer Stok;\n BufferedReader br;\n\n public String nextToken() throws IOException {\n while (Stok == null || !Stok.hasMoreTokens()) {\n Stok = new StringTokenizer(br.readLine());\n }\n return Stok.nextToken();\n }\n\n public double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextToken());\n }\n\n public void Run() throws NumberFormatException, IOException {\n br=new BufferedReader(new InputStreamReader(System.in));\n pw=new PrintWriter(new OutputStreamWriter(System.out));\n \n double xA,yA,xB,yB,xC,yC;\n xA = nextDouble();\n yA = nextDouble();\n xB = nextDouble()-xA;\n yB = nextDouble()-yA;\n xC = nextDouble()-xA-xB;\n yC = nextDouble()-yA-yB;\n\n byte ab = quarter(xB,yB);\n byte bc = quarter(xC,yC);\n if (ab == bc) {\n pw.println(\"TOWARDS\");\n } else\n if (left(ab,bc)) { \n pw.println(\"LEFT\");\n } else\n pw.println(\"RIGHT\");\n pw.flush();\n pw.close();\n }\n \n public boolean left(byte ab, byte bc) {\n if (((ab==1) && (bc==2)) || ((ab==2) && (bc==3)) || \n ((ab==3) && (bc==4)) || ((ab==4) && (bc==1))) {\n return true;\n } else {\n return false;\n } \n }\n \n public byte quarter(double x, double y) {\n if ((x>=0) && (y>0)) {\n return 1;\n } else\n if ((x<0) && (y>=0)) {\n return 2;\n } else\n if ((x<=0) && (y<0)) {\n return 3;\n } else\n return 4;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e5ef76cde4f5f44da4bbe2e252686d81", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "public class NewApp {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a1 = sc.nextInt();\n int a2 = sc.nextInt();\n int b1 = sc.nextInt();\n int b2 = sc.nextInt();\n int c1 = sc.nextInt();\n int c2 = sc.nextInt();\n int result = (b1 - a1) * (c2 - b2) - (b2 - a2) * (c1 - b1);\n if (result == 0){\n System.out.println(\"TOWARDS\");\n } else if (result > 0) {\n System.out.println(\"LEFT\");\n } else{\n System.out.println(\"RIGHT\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a6471a607385d7ed2b97bb606c1aca6", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class project{\n public static void main(String[]args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tint m =sc.nextInt();\n\t\tint len=s.length();\n\t\t\n\t\tint rt[]=new int[len];\n\t\tint bat[]=new int[len];\n\t\t\n\t\tLong sum=0;\n\t\tLong bs=1;\n\t\tfor(int i=len-1;i>-1;i--)\n\t\t{\n\t\t\tsum=(sum+bs*(s[i]-'0'))%m;\n\t\t\trt[i]=sum;\n\t\t\tbat[len-i-1]=bs;\n\t\t\tbs=(bs*10LL)%m;\n\t\t}\n\t\tbat[len]=bs;\n\t\t\n\t\tint rs=m;\n\t\tsum=0;\n\t\tfor(int i=0;i h[] = new HashSet[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\th[i] = new HashSet<>();\n\t\t\tfor (int j = 0; j < 6; j++)\n\t\t\t{\n\t\t\t\th[i].add(ni());\n\t\t\t}\n\t\t}\n\t\tif(n==1) {\n\t\t\tint x = 1;\n\t\t\tfor(x=1;x<=9;) {\n\t\t\t\tif(h[0].contains(x))\n\t\t\t\t\tx++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tout.println(x-1);\n\t\t}else if(n==2) {\n\t\t\tint x = 1;\n\t\t\tfor(x=1;x<=9;) {\n\t\t\t\tif(h[0].contains(x) || h[1].contains(x))\n\t\t\t\t\tx++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(x!=10)\n\t\t\t{\n\t\t\t\tout.println(x-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(;x<=99;) {\n\t\t\t\tint f = 0;\n\t\t\t\tfor(int i=0;i<2;i++) {\n\t\t\t\t\tif(h[p[i][0]].contains(x/10) && h[p[i][1]].contains(x%10))\n\t\t\t\t\t\tf = 1;\n\t\t\t\t}\n\t\t\t\tif(f==1)\n\t\t\t\t\tx++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tout.println(x-1);\n\t\t}else {\n\t\t\tint x = 1;\n\t\t\tfor(x=1;x<=9;) {\n\t\t\t\tif(h[0].contains(x) || h[1].contains(x) || h[2].contains(x))\n\t\t\t\t\tx++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(x!=10)\n\t\t\t{\n\t\t\t\tout.println(x-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(;x<=99;) {\n\t\t\t\tint f = 0;\n\t\t\t\tfor(int i=6;i<=11;i++) {\n\t\t\t\t\tif(h[p[i][0]].contains(x/10) && h[p[i][1]].contains(x%10))\n\t\t\t\t\t\tf = 1;\n\t\t\t\t}\n\t\t\t\tif(f==1)\n\t\t\t\t\tx++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(x!=100)\n\t\t\t{\n\t\t\t\tout.println(x-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(;x<=999;) {\n\t\t\t\tint f = 0;\n\t\t\t\tfor(int i=0;i<=6;i++) {\n\t\t\t\t\tint a = x/100;\n\t\t\t\t\tint b = (x/10)%10;\n\t\t\t\t\tint c = x%10;\n\t\t\t\t\tif(h[p[i][0]].contains(a) && h[p[i][1]].contains(b) && h[p[i][2]].contains(c))\n\t\t\t\t\t\tf = 1;\n\t\t\t\t}\n\t\t\t\tif(f==1)\n\t\t\t\t\tx++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tout.println(x-1);\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = INPUT.isEmpty() ? 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\tif (!INPUT.isEmpty())\n\t\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew Thread(null, new Runnable()\n\t\t{\n\t\t\tpublic void run()\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tnew B887().run();\n\t\t\t\t} catch (Exception e)\n\t\t\t\t{\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\t}\n\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 = is.read(inbuf);\n\t\t\t} catch (IOException e)\n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(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 && isSpaceChar(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 (!(isSpaceChar(b)))\n\t\t{ // when nextLine, (isSpaceChar(b) && b !=\n\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\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{\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 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} else\n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\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} else\n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate void tr(Object... o)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dbc9877357c056b53790314fc608ce61", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.StringTokenizer;\n\npublic class Template {\n\n static class Solver {\n public void solve(InputReader in, PrintWriter out) {\n \t\tint a1 = in.nextInt();\n int counter = 1;\n \t\tArrayList t = new ArrayList();\n \t\t\n \t\tfor (int i = 0; i < a1 ; i++) {\n for (int j = 0; j < 6 ; j++) {\n \t\tt.add(in.nextInt());\n \t\t\n }\n } \n \n \t\tif(a1==2) {\n \t\t\t\n\t \t\tfor (int i = 0; i < 6; i++) {\n\t \t\t\tfor (int j = 0; j < 6; i++) {\n\t\t \t\t\tt.add((t.get(i)*10)+t.get(j+6));\n\t\t \t\t\tt.add((t.get(j+6)*10)+t.get(i));\n\t \t\t\t}\n\t \t\t}\n \t\t}\n \t\t\n \t\tif(a1==3) {\n \t\t\t\n\t \t\tfor (int i = 0; i < 6; i++) {\n\t \t\t\tfor (int j = 0; j < 6; j++) {\n\t \t\t\t\t\n\t \t\t\t\tt.add((t.get(i)*10)+t.get(j+6));\n\t\t \t\t\tt.add((t.get(j+6)*10)+t.get(i));\n\t \t\t\t}\n\t \t\t}\n\t \t\tfor (int i = 0; i < 6; i++) {\n\t \t\t\tfor (int j = 0; j < 6; j++) {\n\t \t\t\t\t\n\t \t\t\t\tt.add((t.get(i+6)*10)+t.get(j+12));\n\t \t\t\tt.add((t.get(j+12)*10)+t.get(i+6));\n\t \t\t\t\t\n\t \t\t\t}\n\t \t\t}\n\t \t\tfor (int i = 0; i < 6; i++) {\n\t \t\t\tfor (int j = 0; j < 6; j++) {\n\t \t\t\t\t\n\t \t\t\t\tt.add((t.get(i)*10)+t.get(j+12));\n\t \t\t\tt.add((t.get(j+12)*10)+t.get(i));\n\t \t\t\t\t\n\t \t\t\t}\n\t \t\t}\n\t \t\t\n\t \t\t\n \t\t}\t\t\n \t\t\n \t\tCollections.sort(t);\t\n \t\t\n \t\twhile(counter<=100 && t.contains(counter) ) {\n \t\t\tcounter++;\n\t\t\t}\n \t\t\n \t\tif(!t.contains(1)) {\n \t\t\tcounter = 0;\n \t\t}else{\n \t\t\tcounter--;\n \t\t}\n \n \t\tout.print(counter);\n\n\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 PrintWriter out = new PrintWriter(outputStream);\n Solver solver = new Solver();\n solver.solve(in, out);\n out.close();\n\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c953e678457819d1c71923d94f528eab", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Hello {\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.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n return str;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n long nextLong() {\n\n return Long.parseLong(next());\n }\n\n BigInteger nextBigIntger() {\n BigInteger bb = new BigInteger(next());\n return bb;\n }\n }\n Node root;\n public static void main(String args[]) {\n FastReader sc= new FastReader();\n int n =sc.nextInt(), arr[] = new int[10];\n int xx = n;\n while (xx-->0){\n for (int i=0;i<6;i++){ arr[sc.nextInt()]++; }\n }\n\n /* for (int i=0;i<10;i++)\n System.out.print(arr[i]+\" \");*/\n boolean flag = false;\n for (int i=1;i<10;i++){\n if(arr[i]==0){\n System.out.println(arr[1]==0?0:(i-1));\n flag = true;\n break;\n }\n }\n int yy;\n if (!flag){\n if(arr[0]>=1){\n int min = Integer.MAX_VALUE,ind =0;\n for (int ii=1;ii<10;ii++){\n if(arr[ii]= 2 && !q && f(1, x % 10) && play(x / 10, p, true, r)) return true;\n if (n == 3 && !r && f(2, x % 10) && play(x / 10, p, q, true)) return true;\n return false;\n }\n\n }\n\n static class FastReader {\n private InputStream stream;\n private byte[] buf = new byte[8192];\n private int curChar;\n private int pnumChars;\n private FastReader.SpaceCharFilter filter;\n\n public FastReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int pread() {\n if (pnumChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= pnumChars) {\n curChar = 0;\n try {\n pnumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (pnumChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = pread();\n while (isSpaceChar(c))\n c = pread();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = pread();\n }\n int res = 0;\n do {\n if (c == ',') {\n c = pread();\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = pread();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int[] array = new int[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextInt();\n }\n return array;\n }\n\n private boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n private static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b2e7af40d791b0a36e916cc08d38d74f", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\nimport java.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 ceiling(SortedSet S, T x) { // Java 1.5 and below\n\t\tSortedSet T = S.tailSet(x);\n\t\treturn T.isEmpty() ? null : T.first();\n\t}\n\tprivate static T floor(SortedSet 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 = 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 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bbc2c6589be73e7b23ee0cca5bbacd0b", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.*;\nimport java.math.*;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\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 AC solver = new AC();\n solver.solve(in, out);\n out.close();\n }\n}\n\nclass AC {\n class Node extends Object{\n int x,y,dx,dy;\n Node() {}\n Node(int x,int y,int dx,int dy) \n {\n this.x = x;\n this.y = y;\n this.dx = dx;\n this.dy = dy;\n }\n @Override public boolean equals (Object cmp) {\n if(cmp instanceof Node) {\n Node tmp = (Node) cmp;\n return tmp.x == x && tmp.y == y && tmp.dx==dx && tmp.dy == dy ; \n }\n return false;\n }\n @Override public int hashCode() {\n return x*dx * 100000+ y*dy; \n }\n }\n class pair extends Object{\n int x,y;\n pair() {}\n pair(int x,int y)\n {\n this.x = x;\n this.y = y;\n }\n @Override public boolean equals (Object cmp) {\n if(cmp instanceof pair) {\n pair tmp = (pair) cmp;\n return tmp.x == x && tmp.y == y; \n }\n return false;\n }\n @Override public int hashCode () {\n return x*100000+y;\n }\n }\n int n , m;\n boolean judge(int x,int y) {\n return 1<=x && x <= n && 1 <= y && y <= m;\n }\n Node go(int x,int y,int dx,int dy) {\n int delta;\n if(dx < 0) {\n if(dy < 0) {\n delta = Math.min(x-1, y-1);\n } else {\n delta = Math.min(m-y, x-1);\n }\n } else {\n if(dy < 0) {\n delta = Math.min(n-x, y-1);\n } else {\n delta = Math.min(n-x,m-y);\n }\n }\n x += dx * delta;\n y += dy * delta;\n if(x+dx<1 || x+dx>n) dx *= -1;\n if(y+dy<1 || y+dy>m) dy *= -1;\n return new Node(x,y,dx,dy);\n }\n public void solve(InputReader in, PrintWriter out) {\n int x0 , y0;\n String cmd;\n HashMap mp = new HashMap();\n HashMap M = new HashMap();\n n = in.nextInt();\n m = in.nextInt();\n x0 = in.nextInt(); y0 = in.nextInt();\n cmd = in.next();\n int tot = n + m - 2;\n int dx , dy;\n if(cmd.charAt(0)=='D') {\n dx = 1;\n } else dx = -1;\n if(cmd.charAt(1)=='R') {\n dy = 1;\n } else dy = -1;\n long long ans = 1;\n pair A = new pair(1,2);\n pair B = new pair(1,2);\n if(x0==1 || x0==n || y0==1 || y0==m){\n M.put(new pair(x0, y0) , 1 );\n tot --;\n }\n while(true) {\n Node tmp = go(x0,y0,dx,dy);\n ans += Math.abs( tmp.x - x0);\n x0 = tmp.x ; y0 = tmp.y ;\n dx = tmp.dx ; dy = tmp.dy;\n pair t = new pair(x0,y0); \n Integer flag = M.get(t);\n if(flag == null) {\n M.put(t, 1);\n if(--tot == 0) break;\n }\n if(mp.get(tmp)!=null){\n ans = -1;\n break;\n } else {\n mp.put(tmp, 1);\n }\n }\n out.println(ans);\n }\n}\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n if (!hasNext())\n throw new RuntimeException();\n return tokenizer.nextToken();\n }\n\n boolean hasNext() {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n return false;\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n public BigInteger nextBigInteger() {\n return new BigInteger(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b7eecd7c8f9c2f0f207507482359115f", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class D {\n\t\n\tprivate static final int UL = 0;\n\tprivate static final int UR = 1;\n\tprivate static final int DL = 2;\n\tprivate static final int DR = 3;\n\t\n\t\n\tprivate static class Result {\n\t\tpublic boolean inCorner;\n\t\tpublic long cellsPassed;\n\t\tpublic int steps;\n\t\tpublic int x;\n\t\tpublic int y;\n\t\tpublic int dir;\n\n\t\tpublic Result(boolean inCorner, long cellsPassed, int steps, int x, int y, int dir) {\n\t\t\tthis.inCorner = inCorner;\n\t\t\tthis.cellsPassed = cellsPassed;\n\t\t\tthis.steps = steps;\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.dir = dir;\n\t\t}\n\t}\n\t\n\t\n\tprivate Result go(int n, int m, int x0, int y0, int dir0) {\n\t\tlong res = 0;\n\t\tint x = x0;\n\t\tint y = y0;\n\t\tint dir = dir0;\n\t\tint steps = 0;\n\t\t\n\t\tdo {\n\t\t\t\n\t\t\tif (dir == UR) {\n\t\t\t\tint dx = x - 1;\n\t\t\t\tint dy = m - y;\n\t\t\t\tint d = Math.min(dx, dy);\n\t\t\t\tx -= d;\n\t\t\t\ty += d;\n\t\t\t\tres += d;\n\t\t\t\t\n\t\t\t\tif (d != 0) {\n\t\t\t\t\tsteps++;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (dy < dx) {\n\t\t\t\t\tdir = UL;\n\t\t\t\t} else if (dx < dy) {\n\t\t\t\t\tdir = DR;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else if (dir == UL) {\n\t\t\t\tint dx = x - 1;\n\t\t\t\tint dy = y - 1;\n\t\t\t\tint d = Math.min(dx, dy);\n\t\t\t\tx -= d;\n\t\t\t\ty -= d;\n\t\t\t\tres += d;\n\t\t\t\t\n\t\t\t\tif (d != 0) {\n\t\t\t\t\tsteps++;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (dx < dy) {\n\t\t\t\t\tdir = DL;\n\t\t\t\t} else if (dy < dx) {\n\t\t\t\t\tdir = UR;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else if (dir == DL) {\n\t\t\t\tint dx = n - x;\n\t\t\t\tint dy = y - 1;\n\t\t\t\tint d = Math.min(dx, dy);\n\t\t\t\tx += d;\n\t\t\t\ty -= d;\n\t\t\t\tres += d;\n\t\t\t\t\n\t\t\t\tif (d != 0) {\n\t\t\t\t\tsteps++;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (dx < dy) {\n\t\t\t\t\tdir = UL;\n\t\t\t\t} else if (dy < dx) {\n\t\t\t\t\tdir = DR;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else if (dir == DR) {\n\t\t\t\tint dx = n - x;\n\t\t\t\tint dy = m - y;\n\t\t\t\tint d = Math.min(dx, dy);\n\t\t\t\tx += d;\n\t\t\t\ty += d;\n\t\t\t\tres += d;\n\t\t\t\t\n\t\t\t\tif (d != 0) {\n\t\t\t\t\tsteps++;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (dx < dy) {\n\t\t\t\t\tdir = UR;\n\t\t\t\t} else if (dy < dx) {\n\t\t\t\t\tdir = DL;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} while (x != x0 || y != y0 || dir != dir0);\n\t\t\n\t\tif (isCorner(x, y, n, m)) {\n\t\t\treturn new Result(true, res, steps, x, y, dir);\n\t\t} else {\n\t\t\treturn new Result(false, res, steps, x, y, dir);\n\t\t}\n\t}\n\t\n\tprivate boolean isCorner(int x, int y, int n, int m) {\n\t\treturn (x == 1 && y == 1 || x == 1 && y == m ||\n\t\t\t\tx == n && y == 1 || x == n && y == m);\n\t}\n\t\n\tprivate int reverseDirection(int dir) {\n\t\tif (dir == UL) {\n\t\t\treturn DR;\n\t\t} else if (dir == UR) {\n\t\t\treturn DL;\n\t\t} else if (dir == DL) {\n\t\t\treturn UR;\n\t\t} else if (dir == DR) {\n\t\t\treturn UL;\n\t\t} else {\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\t\n\t\n\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\t\n\t\tint x = nextInt();\n\t\tint y = nextInt();\n\t\t\n\t\tString s = nextToken();\n\t\tint dir = 0;\n\t\tif (\"UL\".equals(s)) {\n\t\t\tdir = UL;\n\t\t} else if (\"UR\".equals(s)) {\n\t\t\tdir = UR;\n\t\t} else if (\"DL\".equals(s)) {\n\t\t\tdir = DL;\n\t\t} else {\n\t\t\tdir = DR;\n\t\t}\n\t\t\n\t\tint stepsNeeded = (n + n + m + m - 4) / 2 - 1;\n\t\t\n\t\tResult r1 = go(n, m, x, y, dir);\n\t\tif (r1.inCorner) {\n\t\t\tr1.cellsPassed++;\n\t\t\t\n\t\t\tif (isCorner(x, y, n, m) && (r1.x != x || r1.y != y)) {\n\t\t\t\tif (r1.steps == stepsNeeded) {\n\t\t\t\t\tprintln(r1.cellsPassed);\n\t\t\t\t} else {\n\t\t\t\t\tprintln(\"-1\");\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tResult r2 = go(n, m, r1.x, r1.y, reverseDirection(r1.dir));\n\t\t\t\tif (r2.steps == stepsNeeded) {\n\t\t\t\t\tprintln(r1.cellsPassed + r2.cellsPassed);\n\t\t\t\t} else {\n\t\t\t\t\tprintln(\"-1\");\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (r1.steps == stepsNeeded + 1) {\n\t\t\t\tprintln(r1.cellsPassed);\n\t\t\t} else {\n\t\t\t\tprintln(\"-1\");\n\t\t\t}\n\t\t}\n\t}\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 NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate double nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate void print(Object o) {\n\t\twriter.print(o);\n\t}\n\n\tprivate void println(Object o) {\n\t\twriter.println(o);\n\t}\n\n\tprivate void printf(String format, Object... o) {\n\t\twriter.printf(format, o);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tlong time = System.currentTimeMillis();\n\t\tLocale.setDefault(Locale.US);\n\t\tnew D().run();\n\t\tSystem.err.printf(\"%.3f\\n\", 1e-3 * (System.currentTimeMillis() - time));\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tprivate void run() {\n\t\ttry {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(13);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "92cb8a242826484494641edb26ca456d", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.*;\nimport java.math.*;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\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 AC solver = new AC();\n solver.solve(in, out);\n out.close();\n }\n}\n\nclass AC {\n class Node extends Object{\n int x,y,dx,dy;\n Node() {}\n Node(int x,int y,int dx,int dy) \n {\n this.x = x;\n this.y = y;\n this.dx = dx;\n this.dy = dy;\n }\n @Override public boolean equals (Object cmp) {\n if(cmp instanceof Node) {\n Node tmp = (Node) cmp;\n return tmp.x == x && tmp.y == y && tmp.dx==dx && tmp.dy == dy ; \n }\n return false;\n }\n }\n class pair extends Object{\n int x,y;\n pair() {}\n pair(int x,int y)\n {\n this.x = x;\n this.y = y;\n }\n @Override public boolean equals (Object cmp) {\n if(cmp instanceof pair) {\n pair tmp = (pair) cmp;\n return tmp.x == x && tmp.y == y; \n }\n return false;\n }\n @Override public int hashCode () {\n return x*100000+y;\n }\n }\n int n , m;\n boolean judge(int x,int y) {\n return 1<=x && x <= n && 1 <= y && y <= m;\n }\n Node go(int x,int y,int dx,int dy) {\n \n int delta;\n if(dx < 0) {\n if(dy < 0) {\n delta = Math.min(x-1, y-1);\n } else {\n delta = Math.min(m-y, x-1);\n }\n } else {\n if(dy < 0) {\n delta = Math.min(n-x, y-1);\n } else {\n delta = Math.min(n-x,m-y);\n }\n }\n x += dx * delta;\n y += dy * delta;\n if(x+dx<1 || x+dx>n) dx *= -1;\n if(y+dy<1 || y+dy>m) dy *= -1;\n return new Node(x,y,dx,dy);\n }\n public void solve(InputReader in, PrintWriter out) {\n int x0 , y0;\n String cmd;\n HashMap mp = new HashMap();\n HashMap M = new HashMap();\n n = in.nextInt();\n m = in.nextInt();\n x0 = in.nextInt(); y0 = in.nextInt();\n cmd = in.next();\n int tot = n + m - 2;\n int dx , dy;\n if(cmd.charAt(0)=='D') {\n dx = 1;\n } else dx = -1;\n if(cmd.charAt(1)=='R') {\n dy = 1;\n } else dy = -1;\n long ans = 1;\n pair A = new pair(1,2);\n pair B = new pair(1,2);\n if(x0==1 || x0==n || y0==1 || y0==m){\n M.put(new pair(x0, y0) , 1 );\n tot --;\n }\n while(true) {\n Node tmp = go(x0,y0,dx,dy);\n ans += Math.abs( tmp.x - x0);\n x0 = tmp.x ; y0 = tmp.y ;\n //out.println(x0+\" \"+y0);\n dx = tmp.dx ; dy = tmp.dy;\n pair t = new pair(x0,y0); \n Integer flag = M.get(t);\n if(flag == null) {\n // out.println(x0+\" \"+y0);\n M.put(t, 1);\n if(--tot == 0) break;\n }\n // out.println(M.get(t));\n if(mp.get(tmp)!=null){\n ans = -1;\n break;\n } else {\n mp.put(tmp, 1);\n }\n }\n out.println(ans);\n }\n}\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n if (!hasNext())\n throw new RuntimeException();\n return tokenizer.nextToken();\n }\n\n boolean hasNext() {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n return false;\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n public BigInteger nextBigInteger() {\n return new BigInteger(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c264c35068183b82fc4ce0693ec5ee3", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class E {\n\n final int N = 100_000;\n final int W = 7;\n final int MOD = 1_000_000_007;\n\n int[][] mem;\n long[][][] memG;\n int[] w;\n int ans;\n\n void read() {\n Scanner scanner = new Scanner(System.in);\n\n w = new int[W];\n\n for (int i = 0; i < w.length; i++) {\n w[i] = scanner.nextInt();\n }\n\n scanner.close();\n }\n\n boolean good(int w, int a, int b, int c) {\n c = (((1 << w) | c) << 1) | 1;\n for (int i = 0; i <= w; i++) {\n if ((a & (1 << i)) > 0 && (b & (1 << i)) > 0 && (c & (1 << i)) > 0 && (c & (2 << i)) > 0) {\n return false;\n }\n }\n return true;\n }\n\n long[][] mul(long [][] a, long[][] b) {\n long[][] t = new long[1 << W][1 << W];\n\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < a.length; j++) {\n for (int k = 0; k < a.length; k++) {\n t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % MOD;\n }\n }\n }\n\n return t;\n }\n\n long[][] pow(long[][] base, int p) {\n long[][] ans = new long[base.length][base.length];\n for (int i = 0; i < ans.length; i++) {\n ans[i][i] = 1;\n }\n for (; p > 0; p >>= 1) {\n if ((p & 1) > 0) {\n ans = mul(ans, base);\n }\n base = mul(base, base);\n }\n return ans;\n }\n\n long g(int w, int a, int b) {\n return memG[w][a][b];\n }\n\n long f(int mask, int pos) {\n if (mem[mask][pos] == 0) {\n int realMask = 1 << pos | mask;\n long res = 0;\n int lastMask = 1 << (pos + 1);\n\n if (pos == w.length - 1) {\n res = g(pos, realMask, lastMask - 1);\n } else {\n for (int i = 0; i < lastMask; i++) {\n res = (res + g(pos, realMask, i) * f(i, pos + 1)) % MOD;\n }\n }\n\n mem[mask][pos] = (int) res + 1;\n }\n return mem[mask][pos] - 1;\n }\n\n void solve() {\n mem = new int[1 << W][W];\n memG = new long[W][1 << W][1 << W];\n\n for (int w = 0; w < W; w++) {\n int m = 1 << w + 1;\n\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < m; j++) {\n int res = 0;\n int n = 1 << w;\n for (int k = 0; k < n; k++) {\n if (good(w, i, j, k)) {\n res++;\n }\n }\n memG[w][i][j] = res;\n }\n }\n\n memG[w] = pow(memG[w], this.w[w]);\n }\n\n ans = (int) f(0, 0);\n }\n\n void write() {\n System.out.println(ans);\n }\n\n public static void main(String[] args) {\n //long time = System.currentTimeMillis();\n E e = new E();\n e.read();\n e.solve();\n e.write();\n //System.out.println(System.currentTimeMillis() - time);\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8d5d12187078131dccd4c7582f620903", "src_uid": "a4bda63b95dc14185c47a08652fe41bd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E_faster {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int P = 1_000_000_007;\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\tint[] next = new int[1 << h];\n\t\t\tfor (int i = 0; i < w; i++) {\n\t\t\t\tfor (int j = 0; j < h; j++) {\n\t\t\t\t\tArrays.fill(next, 0);\n\t\t\t\t\tboolean canDown = j != 0;\n\t\t\t\t\tboolean canLeft = j < prevH;\n\t\t\t\t\tfor (int was = 0; was < (1 << h); was++) {\n\t\t\t\t\t\tif (dp[was] == 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint dpwas = dp[was];\n\t\t\t\t\t\tboolean needLeft = (was & 1) == 1;\n\t\t\t\t\t\t// down and left\n\t\t\t\t\t\tif (canDown && canLeft) {\n\t\t\t\t\t\t\tint tmp = (was & ~(1 << h - 1)) >> 1;\n\t\t\t\t\t\t\tint tmp2 = next[tmp] + dpwas;\n\t\t\t\t\t\t\tif (tmp2 >= P) {\n\t\t\t\t\t\t\t\ttmp2 -= P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnext[tmp] = tmp2;\n\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// down\n\t\t\t\t\t\tif (canDown && !needLeft) {\n\t\t\t\t\t\t\tint tmp = (was & ~(1 << h - 1)) >> 1;\n\t\t\t\t\t\t\tint tmp2 = next[tmp] + dpwas;\n\t\t\t\t\t\t\tif (tmp2 >= P) {\n\t\t\t\t\t\t\t\ttmp2 -= P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnext[tmp] = tmp2;\n\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// left\n\t\t\t\t\t\tif (canLeft) {\n\t\t\t\t\t\t\tint tmp = was >> 1;\n\t\t\t\t\t\t\tint tmp2 = next[tmp] + dpwas;\n\t\t\t\t\t\t\tif (tmp2 >= P) {\n\t\t\t\t\t\t\t\ttmp2 -= P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnext[tmp] = tmp2;\n\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// nothing\n\t\t\t\t\t\tif (!needLeft) {\n\t\t\t\t\t\t\tint tmp = was >> 1 | (1 << h - 1);\n\t\t\t\t\t\t\tint tmp2 = next[tmp] + dpwas;\n\t\t\t\t\t\t\tif (tmp2 >= P) {\n\t\t\t\t\t\t\t\ttmp2 -= P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnext[tmp] = tmp2;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\t\t\t\t\tint[] tmp = dp;\n\t\t\t\t\tdp = next;\n\t\t\t\t\tnext = tmp;\n\t\t\t\t}\n\t\t\t\tprevH = h;\n\t\t\t}\n\t\t}\n\n\t\tout.println(dp[0]);\n\t}\n\n\tE_faster() 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_faster();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0c07afb8a2aaf097299dc8b40a55ab67", "src_uid": "a4bda63b95dc14185c47a08652fe41bd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class E {\n\n final int N = 100_000;\n final int W = 7;\n final int MOD = 1_000_000_007;\n\n int[][] mem;\n long[][][] memG;\n int[] w;\n int ans;\n boolean memGood[][][][];\n boolean memGood1[][][][];\n\n void read() {\n Scanner scanner = new Scanner(System.in);\n\n w = new int[W];\n\n for (int i = 0; i < w.length; i++) {\n w[i] = scanner.nextInt();\n }\n\n scanner.close();\n }\n\n boolean good(int w, int a, int b, int c) {\n if (w < 0) {\n return true;\n }\n if (!memGood1[w][a][b][c]) {\n memGood1[w][a][b][c] = true;\n int x = 1 << w;\n memGood[w][a][b][c] = !((a & x) > 0 && (b & x) > 0 && (c & x) > 0 && (c & (x << 1)) > 0) && good(w - 1, a, b, c);\n }\n return memGood[w][a][b][c];\n }\n\n long[][] mul(long [][] a, long[][] b) {\n long[][] t = new long[a.length][a.length];\n\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < a.length; j++) {\n for (int k = 0; k < a.length; k++) {\n t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % MOD;\n }\n }\n }\n\n return t;\n }\n\n long[][] pow(long[][] base, int p) {\n long[][] ans = new long[base.length][base.length];\n for (int i = 0; i < ans.length; i++) {\n ans[i][i] = 1;\n }\n for (; p > 0; p >>= 1) {\n if ((p & 1) > 0) {\n ans = mul(ans, base);\n }\n base = mul(base, base);\n }\n return ans;\n }\n\n long f(int mask, int pos) {\n if (mem[pos][mask] == 0) {\n int realMask = 1 << pos | mask;\n long res = 0;\n int lastMask = 1 << (pos + 1);\n\n if (pos == w.length - 1) {\n res = memG[pos][realMask][lastMask - 1];\n } else {\n for (int i = 0; i < lastMask; i++) {\n res = (res + memG[pos][realMask][i] * f(i, pos + 1)) % MOD;\n }\n }\n\n mem[pos][mask] = (int) res + 1;\n }\n return mem[pos][mask] - 1;\n }\n\n void solve() {\n mem = new int[W][1 << W];\n memG = new long[W][][];\n memGood = new boolean[W][1 << W + 1][1 << W + 1][1 << W + 2];\n memGood1 = new boolean[W][1 << W + 1][1 << W + 1][1 << W + 2];\n\n for (int w = 0; w < W; w++) {\n int m = 1 << w + 1;\n long[][] t = new long[m][m];\n\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < m; j++) {\n int res = 0;\n int n = 1 << w;\n for (int k = 0; k < n; k++) {\n if (good(w, i, j, ((n | k) << 1) | 1)) {\n res++;\n }\n }\n t[i][j] = res;\n }\n }\n\n memG[w] = pow(t, this.w[w]);\n }\n\n ans = (int) f(0, 0);\n }\n\n void write() {\n System.out.println(ans);\n }\n\n public static void main(String[] args) {\n //long time = System.currentTimeMillis();\n E e = new E();\n e.read();\n e.solve();\n e.write();\n //System.out.println(System.currentTimeMillis() - time);\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a275c9a317478e03671a91ca91a6e58", "src_uid": "a4bda63b95dc14185c47a08652fe41bd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class E {\n\n final int N = 100_000;\n final int W = 7;\n final int MOD = 1_000_000_007;\n\n int[] w;\n int[][] mem;\n int[][][] memG;\n int ans;\n\n void read() {\n Scanner scanner = new Scanner(System.in);\n\n int[] t = new int[W];\n int s = 0;\n\n for (int i = 0; i < t.length; i++) {\n t[i] = scanner.nextInt();\n s += t[i];\n }\n\n w = new int[s];\n\n for (int i = 0, j = 0; i < t.length; i++) {\n for (int k = 0; k < t[i]; k++) {\n w[j++] = i + 1;\n }\n }\n\n scanner.close();\n }\n\n int calcRealMask(int mask, int pos) {\n int prev = pos == 0 ? 0 : w[pos - 1];\n return mask | (((1 << prev) - 1) ^ ((1 << w[pos]) - 1));\n }\n\n boolean good(int w, int a, int b, int c) {\n c = (((1 << (w - 1)) | c) << 1) | 1;\n for (int i = 0; i < w; i++) {\n if ((a & (1 << i)) > 0 && (b & (1 << i)) > 0 && (c & (1 << i)) > 0 && (c & (2 << i)) > 0) {\n return false;\n }\n }\n return true;\n }\n\n int g(int w, int a, int b) {\n if (memG[w][a][b] == 0) {\n int res = 0;\n\n int n = 1 << (w - 1);\n for (int i = 0; i < n; i++) {\n if (good(w, a, b, i)) {\n res++;\n }\n }\n\n memG[w][a][b] = res + 1;\n }\n return memG[w][a][b] - 1;\n }\n\n long f(int mask, int pos) {\n if (mem[mask][pos] == 0) {\n int realMask = calcRealMask(mask, pos);\n long res = 0;\n int lastMask = 1 << w[pos];\n\n if (pos == w.length - 1) {\n res = g(w[pos], realMask, lastMask - 1);\n } else {\n for (int i = 0; i < lastMask; i++) {\n res = (res + g(w[pos], realMask, i) * f(i, pos + 1)) % MOD;\n }\n }\n\n mem[mask][pos] = (int) res + 1;\n }\n return mem[mask][pos] - 1;\n }\n\n void solve() {\n mem = new int[1 << w[w.length - 1]][w.length];\n memG = new int[W + 1][1 << W][1 << W];\n ans = f(0, 0);\n }\n\n void write() {\n System.out.println(ans);\n }\n\n public static void main(String[] args) {\n E e = new E();\n e.read();\n e.solve();\n e.write();\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6fe5cff4ea31a8c0b4a40a71600639a9", "src_uid": "a4bda63b95dc14185c47a08652fe41bd", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Test {\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n, k;\n int N = 1 << 16;\n int[][] f = new int[5][N];\n int idx = 0;\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n void solve(int n) {\n if (n == 1) {\n f[0][0] = 1;\n f[0][1] = 0;\n f[1][0] = 1;\n f[1][1] = 1;\n idx = 1;\n return;\n }\n if (n == 2) {\n f[1][0] = 1;\n f[1][1] = 1;\n f[2][0] = 1;\n f[2][1] = 3;\n f[2][2] = 1;\n idx = 2;\n return;\n }\n if (n % 2 == 1) {\n solve(n - 1);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3;\n f[nidx][0] = 1;\n for (int i = 1; i <= k; i++)\n f[nidx][i] = Ntt.add(Ntt.add(f[idx][i], f[idx][i - 1]), f[pidx][i - 1]);\n idx = nidx;\n return;\n }\n\n solve(n / 2);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3, ppidx = 3;\n for (int i = 0; i + 1 <= k; i++)\n f[ppidx][i] = Ntt.add(f[idx][i + 1], Ntt.M - Ntt.add(f[pidx][i], f[pidx][i + 1]));\n//\n// Arrays.fill(f[idx], k + 1, N, 0);\n// Arrays.fill(f[pidx], k + 1, N, 0);\n// Arrays.fill(f[ppidx], k + 1, N, 0);\n\n Ntt.fft(f[idx], 0, N);\n Ntt.fft(f[pidx], 0, N);\n Ntt.fft(f[ppidx], 0, N);\n\n for (int i = 0; i < N; i++) f[nidx][i] = Ntt.mul(f[idx][i], f[idx][i]);\n Ntt.ifft(f[nidx], 0, N);\n\n for (int i = 0; i < N; i++) f[4][i] = Ntt.mul(f[pidx][i], f[pidx][i]);\n Ntt.ifft(f[4], 0, N);\n for (int i = 1; i <= k; i++) f[nidx][i] = Ntt.add(f[nidx][i], f[4][i - 1]);\n\n for (int i = 0; i < N; i++) f[idx][i] = Ntt.mul(f[idx][i], f[pidx][i]);\n Ntt.ifft(f[idx], 0, N);\n\n for (int i = 0; i < N; i++) f[pidx][i] = Ntt.mul(f[pidx][i], f[ppidx][i]);\n Ntt.ifft(f[pidx], 0, N);\n for (int i = 1; i <= k; i++) f[idx][i] = Ntt.add(f[idx][i], f[pidx][i - 1]);\n\n idx = nidx;\n }\n\n void start() {\n n = readInt();\n k = readInt();\n solve(n);\n for (int i = 1; i <= k; i++) writer.print(f[idx][i] + \" \");\n }\n\n static class Ntt {\n static final int pri = 3;\n static final int M = 998_244_353;\n static int[] xy = new int[2];\n\n static int pmod(int b, int e) {\n int i = 1 << 31;\n int r = 1;\n while (i != 0) {\n r = mul(r, r);\n if ((e & i) != 0) r = mul(r, b);\n i >>>= 1;\n }\n return r;\n }\n\n static void fft(int[] a, int off, int len) {\n for (int i = 0; i < len; i++) {\n int j = i, x = 0, y = len - 1;\n while (y > 0) {\n x = (x << 1) + (j & 1);\n j >>>= 1;\n y >>>= 1;\n }\n if (i < x) {\n int t = a[off + i];\n a[off + i] = a[off + x];\n a[off + x] = t;\n }\n }\n for (int i = 1; i < len; i *= 2) {\n int s = pmod(pri, (M - 1) / 2 / i);\n for (int j = 0; j < len; j += 2 * i) {\n int w = 1;\n for (int k = 0; k < i; k++) {\n int u = a[off + j + k], v = mul(a[off + j + k + i], w);\n a[off + j + k] = add(u, v);\n a[off + j + k + i] = add(u, M - v);\n w = mul(w, s);\n }\n }\n }\n }\n\n static void ifft(int[] a, int off, int len) {\n int ll = 1, rr = len - 1;\n while (ll < rr) {\n int t = a[off + ll];\n a[off + (ll++)] = a[off + rr];\n a[off + (rr--)] = t;\n }\n fft(a, off, len);\n int inv = pmod(len, M - 2);\n for (int i = 0; i < len; i++) a[off + i] = mul(inv, a[off + i]);\n }\n\n static int add(int a, int b) {\n return (a + b) % M;\n }\n\n static int mul(int a, int b) {\n return (int) ((a * (long) b) % M);\n }\n\n static int inverse(int a, int b) {\n if (b == 0) {\n xy[0] = 1;\n xy[1] = 0;\n return a;\n }\n int d = inverse(b, a % b);\n swap(xy, 0, 1);\n xy[1] -= a / b * xy[0];\n return d;\n }\n\n static void swap(int[] a, int i, int j) {\n int t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "401798d0f4aee123155332a1de47fa9b", "src_uid": "266cc96acf6287f92a3bb0f8eccc5cf1", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n class F {\n int[] f;\n int m;\n\n F(int m) {\n f = new int[m + 1];\n this.m = m;\n }\n\n void add(int i, int v) {\n while (i <= m) {\n f[i] += v;\n i += i & (-i);\n }\n }\n\n int sum(int i) {\n int s = 0;\n while (i > 0) {\n s += f[i];\n i -= i & (-i);\n }\n return s;\n }\n\n int rsum(int i, int j) {\n return sum(j) - sum(i - 1);\n }\n }\n\n F f;\n int n, k;\n\n Scanner sca = new java.util.Scanner(System.in);\n\n void start() {\n n = sca.nextInt(); k = sca.nextInt();\n if (k + k > n) k = n - k;\n f = new F(n + 1);\n int a = 1, it = n;\n long c = 1;\n while (it > 0) {\n c++;\n int from = a - k + 1, to = a + k - 1;\n if (from < 1) c += f.rsum(1, to) + f.rsum(from + n, n);\n else {\n if (to > n) c += f.rsum(1, to - n) + f.rsum(from, n);\n else c += f.rsum(from, to);\n }\n\n System.out.print(c + \" \");\n\n f.add(a, 1);\n a += k;\n if (a > n) a -= n;\n it--;\n }\n System.out.println();\n }\n\n public static void main(String[] args) {\n new Test().start();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "55fe4240924a61253b055efaa9a6b740", "src_uid": "266cc96acf6287f92a3bb0f8eccc5cf1", "difficulty": 3200.0} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class Test {\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n, k;\n int[][] dp = new int[3][1 << 16];\n int[] buf = new int[1 << 16], buf2 = new int[1 << 16];\n int idx = 0;\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n void solve(int n) {\n if (n == 1) {\n dp[0][0] = 1;\n dp[0][1] = 0;\n dp[1][0] = 1;\n dp[1][1] = 1;\n idx = 1;\n return;\n }\n if (n == 2) {\n dp[0][0] = 1;\n dp[0][1] = 0;\n dp[1][0] = 1;\n dp[1][1] = 1;\n dp[2][0] = 1;\n dp[2][1] = 3;\n dp[2][2] = 1;\n idx = 2;\n return;\n }\n if (n % 2 == 1) {\n solve(n - 1);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3;\n dp[nidx][0] = 1;\n for (int i = 1; i <= k; i++)\n dp[nidx][i] = Ntt.add(Ntt.add(dp[idx][i], dp[idx][i - 1]), dp[pidx][i - 1]);\n idx = nidx;\n return;\n }\n solve(n / 2);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3;\n System.arraycopy(dp[idx], 0, buf, 0, buf.length);\n Ntt.fft(buf, 0, buf.length);\n\n for (int i = 0; i < buf.length; i++) buf[i] = Ntt.mul(buf[i], buf[i]);\n Ntt.ifft(buf, 0, buf.length);\n for (int i = 0; i < buf.length; i++) dp[nidx][i] = buf[i];\n\n System.arraycopy(dp[pidx], 0, buf2, 0, buf2.length);\n Ntt.fft(buf2, 0, buf2.length);\n\n for (int i = 0; i < buf2.length; i++) buf2[i] = Ntt.mul(buf2[i], buf2[i]);\n Ntt.ifft(buf2, 0, buf2.length);\n for (int i = 1; i < buf.length; i++) dp[nidx][i] = Ntt.add(dp[nidx][i], buf2[i - 1]);\n\n for (int i = 0; i + 1 < buf.length; i++)\n buf[i] = Ntt.add(dp[idx][i + 1], Ntt.M - Ntt.add(dp[pidx][i], dp[pidx][i + 1]));\n Ntt.fft(buf, 0, buf.length);\n for (int i = 0; i < buf.length; i++) buf[i] = Ntt.mul(buf[i], buf[i]);\n Ntt.ifft(buf, 0, buf.length);\n dp[pidx][0] = 1;\n for (int i = 1; i < buf.length; i++) dp[pidx][i] = Ntt.add(buf2[i], buf[i - 1]);\n dp[idx][0] = 1;\n for (int i = 1; i < buf.length; i++)\n dp[idx][i] = Ntt.add(dp[nidx][i], Ntt.M - Ntt.add(dp[idx][i - 1], dp[pidx][i - 1]));\n idx = nidx;\n }\n\n void start() {\n n = readInt();\n k = readInt();\n solve(n);\n for (int i = 1; i <= k; i++) writer.print(dp[idx][i] + \" \");\n }\n\n static class Ntt {\n static final int pri = 3;\n static final int M = 998_244_353;\n static int[] xy = new int[2];\n\n static int pmod(int b, int e) {\n int i = 1 << 31;\n int r = 1;\n while (i != 0) {\n r = mul(r, r);\n if ((e & i) != 0) r = mul(r, b);\n i >>>= 1;\n }\n return r;\n }\n\n static void fft(int[] a, int off, int len) {\n for (int i = 0; i < len; i++) {\n int j = i, x = 0, y = len - 1;\n while (y > 0) {\n x = (x << 1) + (j & 1);\n j >>>= 1;\n y >>>= 1;\n }\n if (i < x) {\n int t = a[off + i];\n a[off + i] = a[off + x];\n a[off + x] = t;\n }\n }\n for (int i = 1; i < len; i *= 2) {\n int s = pmod(pri, (M - 1) / 2 / i);\n for (int j = 0; j < len; j += 2 * i) {\n int w = 1;\n for (int k = 0; k < i; k++) {\n int u = a[off + j + k], v = mul(a[off + j + k + i], w);\n a[off + j + k] = add(u, v);\n a[off + j + k + i] = add(u, M - v);\n w = mul(w, s);\n }\n }\n }\n }\n\n static void ifft(int[] a, int off, int len) {\n int ll = 1, rr = len - 1;\n while (ll < rr) {\n int t = a[off + ll];\n a[off + (ll++)] = a[off + rr];\n a[off + (rr--)] = t;\n }\n fft(a, off, len);\n int inv = pmod(len, M - 2);\n for (int i = 0; i < len; i++) a[off + i] = mul(inv, a[off + i]);\n }\n\n static int add(int a, int b) {\n return (a + b) % M;\n }\n\n static int mul(int a, int b) {\n return (int) ((a * (long) b) % M);\n }\n\n static int inverse(int a, int b) {\n if (b == 0) {\n xy[0] = 1;\n xy[1] = 0;\n return a;\n }\n int d = inverse(b, a % b);\n swap(xy, 0, 1);\n xy[1] -= a / b * xy[0];\n return d;\n }\n\n static void swap(int[] a, int i, int j) {\n int t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f6d4841ed02231a3bc4e1cd5a6f215c1", "src_uid": "266cc96acf6287f92a3bb0f8eccc5cf1", "difficulty": 3200.0} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class Test {\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n, k;\n int[][] dp = new int[3][1 << 16];\n int[] buf = new int[1 << 16], buf2 = new int[1 << 16];\n int idx = 0;\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n void solve(int n) {\n if (n == 1) {\n dp[0][0] = 1;\n dp[0][1] = 0;\n dp[1][0] = 1;\n dp[1][1] = 1;\n idx = 1;\n return;\n }\n if (n == 2) {\n dp[0][0] = 1;\n dp[0][1] = 0;\n dp[1][0] = 1;\n dp[1][1] = 1;\n dp[2][0] = 1;\n dp[2][1] = 3;\n dp[2][2] = 1;\n idx = 2;\n return;\n }\n if (n % 2 == 1) {\n solve(n - 1);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3;\n dp[nidx][0] = 1;\n for (int i = 1; i < buf.length; i++)\n dp[nidx][i] = Ntt.add(Ntt.add(dp[idx][i], dp[idx][i - 1]), dp[pidx][i - 1]);\n idx = nidx;\n return;\n }\n solve(n / 2);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3;\n System.arraycopy(dp[idx], 0, buf, 0, buf.length);\n Ntt.fft(buf, 0, buf.length);\n\n for (int i = 0; i < buf.length; i++) buf[i] = Ntt.mul(buf[i], buf[i]);\n Ntt.ifft(buf, 0, buf.length);\n for (int i = 0; i < buf.length; i++) dp[nidx][i] = buf[i];\n\n System.arraycopy(dp[pidx], 0, buf2, 0, buf2.length);\n Ntt.fft(buf2, 0, buf2.length);\n\n for (int i = 0; i < buf2.length; i++) buf2[i] = Ntt.mul(buf2[i], buf2[i]);\n Ntt.ifft(buf2, 0, buf2.length);\n for (int i = 1; i < buf.length; i++) dp[nidx][i] = Ntt.add(dp[nidx][i], buf2[i - 1]);\n\n for (int i = 0; i + 1 < buf.length; i++)\n buf[i] = Ntt.add(dp[idx][i + 1], Ntt.M - Ntt.add(dp[pidx][i], dp[pidx][i + 1]));\n Ntt.fft(buf, 0, buf.length);\n for (int i = 0; i < buf.length; i++) buf[i] = Ntt.mul(buf[i], buf[i]);\n Ntt.ifft(buf, 0, buf.length);\n dp[pidx][0] = 1;\n for (int i = 1; i < buf.length; i++) dp[pidx][i] = Ntt.add(buf2[i], buf[i - 1]);\n dp[idx][0] = 1;\n for (int i = 1; i < buf.length; i++)\n dp[idx][i] = Ntt.add(dp[nidx][i], Ntt.M - Ntt.add(dp[idx][i - 1], dp[pidx][i - 1]));\n idx = nidx;\n }\n\n void start() {\n n = readInt();\n k = readInt();\n solve(n);\n for (int i = 1; i <= k; i++) writer.print(dp[idx][i] + \" \");\n }\n\n static class Ntt {\n static final int pri = 3;\n static final int M = 998_244_353;\n static int[] xy = new int[2];\n\n static int pmod(int b, int e) {\n int i = 1 << 31;\n int r = 1;\n while (i != 0) {\n r = mul(r, r);\n if ((e & i) != 0) r = mul(r, b);\n i >>>= 1;\n }\n return r;\n }\n\n static void fft(int[] a, int off, int len) {\n for (int i = 0; i < len; i++) {\n int j = i, x = 0, y = len - 1;\n while (y > 0) {\n x = (x << 1) + (j & 1);\n j >>>= 1;\n y >>>= 1;\n }\n if (i < x) {\n int t = a[off + i];\n a[off + i] = a[off + x];\n a[off + x] = t;\n }\n }\n for (int i = 1; i < len; i *= 2) {\n int s = pmod(pri, (M - 1) / 2 / i);\n for (int j = 0; j < len; j += 2 * i) {\n int w = 1;\n for (int k = 0; k < i; k++) {\n int u = a[off + j + k], v = mul(a[off + j + k + i], w);\n a[off + j + k] = add(u, v);\n a[off + j + k + i] = add(u, M - v);\n w = mul(w, s);\n }\n }\n }\n }\n\n static void ifft(int[] a, int off, int len) {\n int ll = 1, rr = len - 1;\n while (ll < rr) {\n int t = a[off + ll];\n a[off + (ll++)] = a[off + rr];\n a[off + (rr--)] = t;\n }\n fft(a, off, len);\n int inv = pmod(len, M - 2);\n for (int i = 0; i < len; i++) a[off + i] = mul(inv, a[off + i]);\n }\n\n static int add(int a, int b) {\n return (a + b) % M;\n }\n\n static int mul(int a, int b) {\n return (int) ((a * (long) b) % M);\n }\n\n static int inverse(int a, int b) {\n if (b == 0) {\n xy[0] = 1;\n xy[1] = 0;\n return a;\n }\n int d = inverse(b, a % b);\n swap(xy, 0, 1);\n xy[1] -= a / b * xy[0];\n return d;\n }\n\n static void swap(int[] a, int i, int j) {\n int t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a04c9b8784175798b12e6c3411e1eeaa", "src_uid": "266cc96acf6287f92a3bb0f8eccc5cf1", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.lang.Math;\n\npublic class HelloWorld\n{\n List lines;\n boolean vis = false;\n public static void main(String[] args)\n {\n lines = Files.readAllLines(Paths.get(FILE_NAME), StandardCharsets.UTF_8);\n pnt(0, 3);\n pnt(0, 4);\n pnt(1, 3);\n pnt(1, 4);\n \n pnt(2, 3);\n pnt(2, 4);\n pnt(3, 3);\n pnt(3, 4);\n pnt(0, 0);\n pnt(0, 1);\n pnt(0, 6);\n pnt(0, 7);\n pnt(1, 0);\n pnt(1, 1);\n pnt(1, 6);\n pnt(1, 7);\n \n pnt(4, 3);\n pnt(4, 4);\n pnt(5, 3);\n pnt(5, 4);\n pnt(2, 0);\n pnt(2, 1);\n pnt(2, 6);\n pnt(2, 7);\n pnt(3, 0);\n pnt(3, 1);\n pnt(3, 6);\n pnt(3, 7);\n \n pnt(4, 0);\n pnt(4, 1);\n pnt(4, 6);\n pnt(4, 7);\n pnt(5, 0);\n pnt(5, 1);\n pnt(5, 6);\n pnt(5, 7);\n for (String line: lines) {\n \tSystem.out.println(line);\n }\n }\n \t\n void pnt(int x, int y) {\n if (!vis && lines[x][y] == '.'){\n \tlines[x][y] = 'P';\n \tvis = true;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e3c144884d9ce7cfa786e0e3e52dbdda", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class Sol{\n\tpublic static void main(String[] argc){\n\t\tint seat[][] = {\n\t\t\t\t{3, 3, 0, 4, 4, 0, 3, 3},\n\t\t\t\t{3, 3, 0, 4, 4, 0, 3, 3},\n\t\t\t\t{2, 2, 0, 3, 3, 0, 2, 2},\n\t\t\t\t{2, 2, 0, 3, 3, 0, 2, 2},\n\t\t\t\t{1, 1, 0, 2, 2, 0, 1, 1},\n\t\t\t\t{1, 1, 0, 2, 2, 0, 1, 1}\n\t\t};\n\t\tString plan[] = new String[6];\n\t\tScanner sc = new Scanner(System.in);\n\t\tint best = 0;\n\t\tint row = -1;\n\t\tint col = -1;\n\t\tfor (int i = 0; i < 6; ++i) {\n\t\t\tString cur = sc.nextLine();\n\t\t\tplan[i] = cur;\n\t\t\tfor (int j = 0; j < 8; ++j) {\n\t\t\t\tif (cur.charAt(j) == '.') {\n\t\t\t\t\tif (seat[i][j] > best) {\n\t\t\t\t\t\tbest = seat[i][j];\n\t\t\t\t\t\trow = i;\n\t\t\t\t\t\tcol = j;\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 < 6; ++i) {\n\t\t\tif (i != row) {\n\t\t\t\tSystem.out.println(plan[i].toString());\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfor (int j = 0; j < 8; ++j) {\n\t\t\t\t\tif (j != col) {\n\t\t\t\t\t\tSystem.out.print(plan[i].charAt(j));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tSystem.out.print('P');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7cc8df0afc4356360b7233b965a412bb", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class cf \n{\n public static void main(String args[])\n {\n PrintWriter out =new PrintWriter(System.out);\n Scanner sc=new Scanner(System.in);\n char s[][]=new char[6][8];\n for(int i = 0 ;i<6;i++)\n {\n String s1=sc.next();\n s[i]=s1.toCharArray();\n }\n \n if(s[0][3]=='.')\n s[0][3]='P';\n else if(s[0][4]=='.')\n s[0][4]='P';\n else if(s[1][(3)]=='.')\n s[1][3]='P';\n else if(s[1][(4)]=='.')\n s[1][4]='P';\n \n \n \n \n else if(s[0][(0)]=='.')\n s[0][(0)]='P';\n else if(s[0][(1)]=='.')\n s[0][(1)]='P';\n else if(s[0][(6)]=='.')\n s[0][(6)]='P';\n else if(s[0][(7)]=='.')\n s[0][(7)]='P';\n \n else if(s[1][(0)]=='.')\n s[1][(0)]='P';\n else if(s[1][(1)]=='.')\n s[1][(1)]='P';\n else if(s[1][(6)]=='.')\n s[1][(6)]='P';\n else if(s[1][(7)]=='.')\n s[1][(7)]='P';\n \n else if(s[2][(3)]=='.')\n s[2][(3)]='P';\n else if(s[2][(4)]=='.')\n s[2][(4)]='P';\n else if(s[3][(3)]=='.')\n s[3][(3)]='P';\n else if(s[3][(4)]=='.')\n s[3][(4)]='P';\n \n \n \n \n \n \n else if(s[2][(0)]=='.')\n s[2][(0)]='P';\n else if(s[2][(1)]=='.')\n s[2][(1)]='P';\n else if(s[2][(6)]=='.')\n s[2][(6)]='P';\n else if(s[2][(7)]=='.')\n s[2][(7)]='P';\n \n else if(s[3][(0)]=='.')\n s[3][(0)]='P';\n else if(s[3][(1)]=='.')\n s[3][(1)]='P';\n else if(s[3][(6)]=='.')\n s[3][(6)]='P';\n else if(s[3][(7)]=='.')\n s[3][(7)]='P';\n \n else if(s[4][(3)]=='.')\n s[4][(3)]='P';\n else if(s[4][(4)]=='.')\n s[4][(4)]='P';\n else if(s[5][(3)]=='.')\n s[5][(3)]='P';\n else if(s[5][(4)]=='.')\n s[5][(4)]='P';\n \n \n \n \n \n else if(s[4][(0)]=='.')\n s[4][(0)]='P';\n else if(s[4][(1)]=='.')\n s[4][(1)]='P';\n else if(s[4][(6)]=='.')\n s[4][(6)]='P';\n else if(s[4][(7)]=='.')\n s[4][(7)]='P';\n \n else if(s[5][(0)]=='.')\n s[5][(0)]='P';\n else if(s[5][(1)]=='.')\n s[5][(1)]='P';\n else if(s[5][(6)]=='.')\n s[5][(6)]='P';\n else if(s[5][(7)]=='.')\n s[5][7]='P';\n \n for(int i = 0 ;i<6;i++)\n System.out.println(s[i]);\n }\n}import java.io.*;\nimport java.util.*;\npublic class cf \n{\n public static void main(String args[])\n {\n PrintWriter out =new PrintWriter(System.out);\n Scanner sc=new Scanner(System.in);\n char s[][]=new char[6][8];\n for(int i = 0 ;i<6;i++)\n {\n String s1=sc.next();\n s[i]=s1.toCharArray();\n }\n \n if(s[0][3]=='.')\n s[0][3]='P';\n else if(s[0][4]=='.')\n s[0][4]='P';\n else if(s[1][(3)]=='.')\n s[1][3]='P';\n else if(s[1][(4)]=='.')\n s[1][4]='P';\n \n \n \n \n else if(s[0][(0)]=='.')\n s[0][(0)]='P';\n else if(s[0][(1)]=='.')\n s[0][(1)]='P';\n else if(s[0][(6)]=='.')\n s[0][(6)]='P';\n else if(s[0][(7)]=='.')\n s[0][(7)]='P';\n \n else if(s[1][(0)]=='.')\n s[1][(0)]='P';\n else if(s[1][(1)]=='.')\n s[1][(1)]='P';\n else if(s[1][(6)]=='.')\n s[1][(6)]='P';\n else if(s[1][(7)]=='.')\n s[1][(7)]='P';\n \n else if(s[2][(3)]=='.')\n s[2][(3)]='P';\n else if(s[2][(4)]=='.')\n s[2][(4)]='P';\n else if(s[3][(3)]=='.')\n s[3][(3)]='P';\n else if(s[3][(4)]=='.')\n s[3][(4)]='P';\n \n \n \n \n \n \n else if(s[2][(0)]=='.')\n s[2][(0)]='P';\n else if(s[2][(1)]=='.')\n s[2][(1)]='P';\n else if(s[2][(6)]=='.')\n s[2][(6)]='P';\n else if(s[2][(7)]=='.')\n s[2][(7)]='P';\n \n else if(s[3][(0)]=='.')\n s[3][(0)]='P';\n else if(s[3][(1)]=='.')\n s[3][(1)]='P';\n else if(s[3][(6)]=='.')\n s[3][(6)]='P';\n else if(s[3][(7)]=='.')\n s[3][(7)]='P';\n \n else if(s[4][(3)]=='.')\n s[4][(3)]='P';\n else if(s[4][(4)]=='.')\n s[4][(4)]='P';\n else if(s[5][(3)]=='.')\n s[5][(3)]='P';\n else if(s[5][(4)]=='.')\n s[5][(4)]='P';\n \n \n \n \n \n else if(s[4][(0)]=='.')\n s[4][(0)]='P';\n else if(s[4][(1)]=='.')\n s[4][(1)]='P';\n else if(s[4][(6)]=='.')\n s[4][(6)]='P';\n else if(s[4][(7)]=='.')\n s[4][(7)]='P';\n \n else if(s[5][(0)]=='.')\n s[5][(0)]='P';\n else if(s[5][(1)]=='.')\n s[5][(1)]='P';\n else if(s[5][(6)]=='.')\n s[5][(6)]='P';\n else if(s[5][(7)]=='.')\n s[5][7]='P';\n \n for(int i = 0 ;i<6;i++)\n System.out.println(s[i]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "034aebf1194784f70922b9640d988af5", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package com.company;\n\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 String[] res = new String[6];\n boolean flag = false;\n\n for (int x = 0; x < 6; x++)\n {\n String s = input.next();\n for (int i = 3; i < 5; ++i)\n {\n if (s.charAt(i) != '*' && !flag)\n {\n char[] st = s.toCharArray();\n st[i] = 'P';\n s = String.valueOf(st);\n flag = true;\n break;\n }\n }\n for (int i = 0; i < 8; ++i)\n {\n if (i != 3 && i != 4 && s.charAt(i) == '.' && !flag)\n {\n char[] st = s.toCharArray();\n st[i] = 'P';\n s = String.valueOf(st);\n flag = true;\n break;\n }\n }\n res[x] = s;\n }\n\n for (int x = 0; x < 6; x++)\n {\n System.out.println(res[x]);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "844ca2e2e1e7d885ee90ff54a40ff6c0", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class EMain {\n String noResultMessage = \"NoResult\";\n Parser in = new Parser();\n PrintWriter out;\n\n long n = in.nextLong();\n int k = in.nextInteger();\n\n\n Matrix[] upRow(Matrix[] row){\n Matrix[] result = new Matrix[k];\n for(int i = 0; i < k; ++i){\n Matrix m = Matrix.oneMatrix(k+1);\n for(int j = 0; j < k; ++j){\n m = Matrix.mul(m, row[(i+j)%k]);\n }\n result[i] = m;\n }\n return result;\n }\n\n public void solve() {\n\n Matrix[][] matrixes = new Matrix[100][k];\n\n for(int i = 0; i < k; ++i){\n Matrix m = Matrix.oneMatrix(k + 1);\n matrixes[0][i] = m;\n for(int j = 0; j <= k; ++j){\n m.set(j, i, 1);\n }\n }\n int[] digits = new int[100];\n int index = 0;\n long limit = n;\n digits[index++] = (int) (limit % k);\n for(int row = 1; row < 100; ++row){\n limit /= k;\n if(limit == 0)break;\n digits[index++] = (int) (limit % k);\n matrixes[row] = upRow(matrixes[row-1]);\n }\n\n Matrix result = Matrix.oneMatrix(k+1);\n int pos = 0;\n while(index-- > 0){\n while(digits[index]-- > 0){\n result = Matrix.mul(result, matrixes[index][pos++]);\n }\n }\n Vector vec = new Vector(k+1);\n vec.set(k, 1);\n out.println(Vector.mul(vec, result).sum());\n\n\n }\n\n static int MOD = (int) (1e9+7);\n\n static public class Matrix {\n int[][] data;\n\n public Matrix(int size) {\n this.data = new int[size][size];\n }\n\n Matrix(Matrix other) {\n int size = other.data.length;\n this.data = new int[size][];\n for(int i = 0; i < size; ++i){\n this.data[i] = Arrays.copyOf(other.data[i], size);\n }\n }\n public void set(int row, int column, int value){\n data[row][column] = value;\n }\n\n public static Matrix oneMatrix(int size){\n Matrix result = new Matrix(size);\n for(int i = 0; i < size; ++i){\n result.data[i][i] = 1;\n }\n return result;\n }\n\n public static Matrix mul(Matrix left, Matrix right){\n int size = left.data.length;\n assert size == right.data.length;\n Matrix result = new Matrix(size);\n for(int i = 0; i < size; ++i){\n for(int j = 0; j < size; ++j){\n int val = 0;\n for(int k = 0; k < size; ++k){\n val += 1l * left.data[i][k] * right.data[k][j] % MOD;\n val += MOD;\n val %= MOD;\n }\n result.data[i][j] = val;\n }\n }\n return result;\n }\n\n static Matrix degree(Matrix matrix, long degree){\n Matrix result = Matrix.oneMatrix(matrix.data.length);\n while(degree > 0){\n if((degree & 1) == 1){\n result = Matrix.mul(result, matrix);\n }\n result = Matrix.mul(result, result);\n degree >>= 1;\n }\n return result;\n }\n }\n\n static public class Vector{\n int[] data;\n\n public Vector(int size) {\n this.data = new int[size];\n }\n\n Vector(Vector other) {\n this.data = Arrays.copyOf(other.data, other.data.length);\n }\n\n public void set(int pos, int val){\n data[pos] = val;\n }\n\n int get(int pos){\n return data[pos];\n }\n\n public int sum(){\n long sum = 0;\n for(int i : data){\n sum += i;\n }\n sum %= MOD;\n sum += MOD;\n sum %= MOD;\n return (int) sum;\n }\n\n public static Vector mul(Vector vec, Matrix matrix){\n int size = vec.data.length;\n assert size == matrix.data.length;\n Vector result = new Vector(size);\n for(int i = 0; i < size; ++i){\n int val = 0;\n for(int j = 0; j < size; ++j){\n val += 1l * vec.data[j] * matrix.data[j][i] % MOD;\n val += MOD;\n val %= MOD;\n }\n result.data[i] = val;\n }\n return result;\n }\n }\n\n static public class Parser{\n Scanner scanner;\n\n public Parser() {\n scanner = new Scanner(System.in).useLocale(Locale.ENGLISH);\n }\n\n public Parser(String str) {\n scanner = new Scanner(str).useLocale(Locale.ENGLISH);\n }\n\n long nextLong(){\n return scanner.nextLong();\n }\n\n int nextInteger(){\n return scanner.nextInt();\n }\n\n double nextDouble(){\n return scanner.nextDouble();\n }\n\n String nextLine(){\n return scanner.nextLine();\n }\n\n String next(){\n return scanner.next();\n }\n\n int[] nextIntegers(int count){\n int[] result = new int[count];\n for(int i = 0; i < count; ++i){\n result[i] = nextInteger();\n }\n return result;\n }\n\n long[] nextLongs(int count){\n long[] result = new long[count];\n for(int i = 0; i < count; ++i){\n result[i] = nextLong();\n }\n return result;\n }\n\n int[][] nextIntegers(int fields, int count){\n int[][] result = new int[fields][count];\n for(int c = 0; c < count; ++c){\n for(int i = 0; i < fields; ++i){\n result[i][c] = nextInteger();\n }\n }\n return result;\n }\n }\n\n void noResult(){\n throw new NoResultException();\n }\n\n void noResult(String str){\n throw new NoResultException(str);\n }\n\n void run(){\n try{\n ByteArrayOutputStream outStream = new ByteArrayOutputStream();\n out = new PrintWriter(outStream);\n solve();\n out.close();\n System.out.print(outStream.toString());\n } catch (NoResultException exc){\n System.out.print(null == exc.response ? noResultMessage : exc.response);\n }\n }\n\n public static void main(String[] args) {\n new EMain().run();\n }\n\n public static class NoResultException extends RuntimeException{\n private String response;\n\n public NoResultException(String response) {\n this.response = response;\n }\n\n public NoResultException() {\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f873fe313391db32fd284c42574c9842", "src_uid": "175ce134da7cc5af9c8457e7bd9a40a2", "difficulty": 2900.0} {"lang": "Java 8", "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\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 long MODULO = (long) (1e9 + 7);\n static final long BIG = Long.MAX_VALUE - Long.MAX_VALUE % MODULO;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n int k = in.nextInt();\n long pk = 1;\n int pow = 0;\n while (pk <= n / k) {\n pk *= k;\n ++pow;\n }\n matrCache = new long[pow + 1][][];\n long at = 0;\n long[] ways = new long[k + 1];\n ways[k] = 1;\n while (at < n) {\n while (at + pk <= n) {\n long[][] matr = getMatr(digitSum(at, k) % k, k, pow);\n ways = mul(matr, ways);\n at += pk;\n }\n pk /= k;\n --pow;\n }\n long res = 0;\n for (long x : ways) res += x;\n res %= MODULO;\n out.println(res);\n }\n\n long[][][] matrCache;\n\n private long[][] getMatr(int pre, int k, int pow) {\n long[][] res = matrCache[pow];\n if (res == null) {\n if (pow == 0) {\n res = new long[k + 1][k + 1];\n for (int i = 0; i < k + 1; ++i) ++res[i][i];\n for (int i = 0; i < k + 1; ++i) {\n ++res[pre][i];\n }\n --res[pre][pre];\n } else {\n res = new long[k + 1][k + 1];\n for (int i = 0; i < k + 1; ++i) ++res[i][i];\n for (int i = 0; i < k; ++i) {\n res = mul(res, getMatr(i, k, pow - 1));\n }\n }\n matrCache[pow] = res;\n }\n long[][] rotated = new long[k + 1][k + 1];\n for (int i = 0; i <= k; ++i)\n for (int j = 0; j <= k; ++j) {\n int ii = (i == k) ? k : (pre + i) % k;\n int jj = (j == k) ? k : (pre + j) % k;\n rotated[ii][jj] = res[i][j];\n }\n return rotated;\n }\n\n private long[] mul(long[][] a, long[] b) {\n long[] c = new long[b.length];\n for (int i = 0; i < c.length; ++i) {\n long s = 0;\n for (int j = 0; j < c.length; ++j) {\n s += a[i][j] * b[j];\n if (s < 0) s -= BIG;\n }\n c[i] = s % MODULO;\n }\n return c;\n }\n\n private long[][] mul(long[][] a, long[][] b) {\n long[][] c = new long[b.length][b.length];\n for (int i = 0; i < c.length; ++i) {\n for (int k = 0; k < c.length; ++k) {\n long s = 0;\n for (int j = 0; j < c.length; ++j) {\n s += a[i][j] * b[j][k];\n if (s < 0) s -= BIG;\n }\n c[i][k] = s % MODULO;\n }\n }\n return c;\n }\n\n private int digitSum(long at, int k) {\n int res = 0;\n while (at > 0) {\n res += at % k;\n at /= k;\n }\n return res;\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6d9c541ebc33afadabf8414689a65f24", "src_uid": "175ce134da7cc5af9c8457e7bd9a40a2", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class E {\n static void p(Object ...args) {System.out.println(Arrays.deepToString(args));}\n static long MOD = 1_000_000_007;\n\n /*static int score(int a, int k) {\n int ans = 0;\n while( a > 0) {\n ans += a % k;\n a /= k;\n }\n return ans % k;\n }\n\n public static long slow(int N, int K) {\n long[] V = new long[N+1];\n for (int i = 0; i <= N; i++)\n V[i] = score(i, K);\n long[] dp = new long[N+1];\n for (int i = 0; i <= N; i++) {\n for (int j = 0; j < K; j++) {\n for (int a = i - 1; a >= 0; a--) {\n if (V[a] == j) {\n dp[i] += dp[a];\n break;\n }\n }\n }\n dp[i] += 1;\n dp[i] %= MOD;\n }\n return dp[N];\n }*/\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long N = in.nextLong();\n int K = in.nextInt();\n\n long[][][] M = new long[100][][];\n for (int i = 2; i < M.length; i++)\n M[i] = makeMatrix(K, i);\n\n /*p(\"M[2]\");\n for (int i = 0; i < M[2].length; i++)\n p(M[2][i]);\n p(\"M[3]\");\n for (int i = 0; i < M[3].length; i++)\n p(M[3][i]);*/\n\n long[][][] moveBy = new long[100][][];\n long[][][] moveByK = new long[100][][];\n for (int i = 1; i < moveBy.length - 1; i++) {\n long[][] ans = new long[K+1][K+1];\n for (int j = 0; j < ans.length; j++)\n ans[j][j] = 1;\n for (int j = i - 1; j >= 1; j--)\n ans = multiply(ans, moveByK[j]);\n\n ans = multiply(ans, M[i+1]);\n moveBy[i] = ans;\n moveByK[i] = new long[K+1][K+1];\n for (int j = 0; j <= K; j++)\n moveByK[i][j][j] = 1;\n for (int j = 0; j < K-1; j++)\n moveByK[i] = multiply(moveByK[i], moveBy[i]);\n }\n /*p(\"moveBy[2]\");\n for (int i = 0; i <= K; i++)\n p(moveBy[2][i]);*/\n\n long at = 0;\n long[][] f = new long[K+1][K+1];\n for (int i = 0; i < f.length; i++)\n f[i][i] = 1;\n //f = multiply(f, M[2]);\n //f = multiply(f, M[3]);\n long temp = N / K;\n for (int i = 1; temp > 0; i++) {\n for (int j = 0; j < temp % K; j++) {\n //p(\"mult by\", i);\n f = multiply(moveBy[i], f);\n }\n temp /= K;\n }\n /*p(\"f\");\n for (int i = 0; i < K+1; i++)\n p(f[i]);*/\n long[] start = new long[K+1];\n for (int i = 0; i < start.length; i++)\n start[i] = (1L<<(i)) % MOD;\n start[K] = 1;\n\n int position = (int)(N % K);\n p(\"taking: \", position);\n long ans = 0;\n for (int i = 0; i < start.length; i++)\n ans += (start[i] * f[i][position]) % MOD;\n ans %= MOD;\n\n /*long a2 = slow((int)N, K);\n if (ans != a2) {\n p(ans, a2);\n throw new RuntimeException();\n }*/\n System.out.println(ans);\n }\n static long[][] makeMatrix(int K, int a) {\n long[][] res = new long[K+1][K+1];\n\n int[] v = new int[2*K];\n v[2*K-1] = 0;\n for (int i = 2*K-2; i >= 0; i--) {\n if (i == K-1) {\n v[i] = (K + (K-a + v[i+1]) % K) % K;\n } else {\n v[i] = (K + (K-1 + v[i+1]) % K) % K;\n }\n }\n /*if (a == 2 || a == 3) {\n p(a, v);\n }*/\n for (int i = 0; i <= K; i++)\n res[K][i]++;\n for (int c = 0; c < K; c++) {\n for (int i = 0; i < K; i++) {\n boolean found = false;\n for (int j = c - 1 + K; j >= 0; j--) {\n if (v[j] == i) {\n found = true;\n if (j < K) {\n res[j][c] += 1;\n } else {\n for (int b = 0; b <= K; b++)\n res[b][c] += res[b][j-K];\n }\n break;\n }\n }\n if (!found) {\n p(c, i, v);\n throw new RuntimeException();\n }\n }\n }\n return res;\n }\n static long[][] multiply(long[][] A, long[][] B) {\n long[][] res = new long[A.length][A.length];\n for (int r = 0; r < A.length; r++) \n for (int c = 0; c < A.length; c++) {\n for (int i = 0; i < A.length; i++)\n res[r][c] += (A[r][i] * B[i][c]) % MOD;\n res[r][c] %= MOD;\n }\n return res;\n }\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60270f9ab122fb07c0c16d834d373da1", "src_uid": "175ce134da7cc5af9c8457e7bd9a40a2", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class EMain {\n String noResultMessage = \"NoResult\";\n Parser in = new Parser();\n PrintWriter out;\n\n long n = in.nextLong();\n int k = in.nextInteger();\n\n\n Matrix[] upRow(Matrix[] row){\n Matrix[] result = new Matrix[k];\n for(int i = 0; i < k; ++i){\n Matrix m = Matrix.oneMatrix(k+1);\n for(int j = 0; j < k; ++j){\n m = Matrix.mul(m, row[(i+j)%k]);\n }\n result[i] = m;\n }\n return result;\n }\n\n public void solve() {\n\n Matrix[][] matrixes = new Matrix[100][k];\n\n for(int i = 0; i < k; ++i){\n Matrix m = Matrix.oneMatrix(k + 1);\n matrixes[0][i] = m;\n for(int j = 0; j <= k; ++j){\n m.set(j, i, 1);\n }\n }\n int[] digits = new int[100];\n int index = 0;\n long limit = n;\n digits[index++] = (int) (limit % k);\n for(int row = 1; row < 100; ++row){\n limit /= k;\n if(limit == 0)break;\n digits[index++] = (int) (limit % k);\n matrixes[row] = upRow(matrixes[row-1]);\n }\n\n Matrix result = Matrix.oneMatrix(k+1);\n int pos = 0;\n while(index-- > 0){\n while(digits[index]-- > 0){\n result = Matrix.mul(result, matrixes[index][pos++%k]);\n }\n }\n Vector vec = new Vector(k+1);\n vec.set(k, 1);\n out.println(Vector.mul(vec, result).sum());\n\n\n }\n\n static int MOD = (int) (1e9+7);\n\n static public class Matrix {\n int[][] data;\n\n public Matrix(int size) {\n this.data = new int[size][size];\n }\n\n Matrix(Matrix other) {\n int size = other.data.length;\n this.data = new int[size][];\n for(int i = 0; i < size; ++i){\n this.data[i] = Arrays.copyOf(other.data[i], size);\n }\n }\n public void set(int row, int column, int value){\n data[row][column] = value;\n }\n\n public static Matrix oneMatrix(int size){\n Matrix result = new Matrix(size);\n for(int i = 0; i < size; ++i){\n result.data[i][i] = 1;\n }\n return result;\n }\n\n public static Matrix mul(Matrix left, Matrix right){\n int size = left.data.length;\n assert size == right.data.length;\n Matrix result = new Matrix(size);\n for(int i = 0; i < size; ++i){\n for(int j = 0; j < size; ++j){\n int val = 0;\n for(int k = 0; k < size; ++k){\n val += 1l * left.data[i][k] * right.data[k][j] % MOD;\n val += MOD;\n val %= MOD;\n }\n result.data[i][j] = val;\n }\n }\n return result;\n }\n\n static Matrix degree(Matrix matrix, long degree){\n Matrix result = Matrix.oneMatrix(matrix.data.length);\n while(degree > 0){\n if((degree & 1) == 1){\n result = Matrix.mul(result, matrix);\n }\n result = Matrix.mul(result, result);\n degree >>= 1;\n }\n return result;\n }\n }\n\n static public class Vector{\n int[] data;\n\n public Vector(int size) {\n this.data = new int[size];\n }\n\n Vector(Vector other) {\n this.data = Arrays.copyOf(other.data, other.data.length);\n }\n\n public void set(int pos, int val){\n data[pos] = val;\n }\n\n int get(int pos){\n return data[pos];\n }\n\n public int sum(){\n long sum = 0;\n for(int i : data){\n sum += i;\n }\n sum %= MOD;\n sum += MOD;\n sum %= MOD;\n return (int) sum;\n }\n\n public static Vector mul(Vector vec, Matrix matrix){\n int size = vec.data.length;\n assert size == matrix.data.length;\n Vector result = new Vector(size);\n for(int i = 0; i < size; ++i){\n int val = 0;\n for(int j = 0; j < size; ++j){\n val += 1l * vec.data[j] * matrix.data[j][i] % MOD;\n val += MOD;\n val %= MOD;\n }\n result.data[i] = val;\n }\n return result;\n }\n }\n\n static public class Parser{\n Scanner scanner;\n\n public Parser() {\n scanner = new Scanner(System.in).useLocale(Locale.ENGLISH);\n }\n\n public Parser(String str) {\n scanner = new Scanner(str).useLocale(Locale.ENGLISH);\n }\n\n long nextLong(){\n return scanner.nextLong();\n }\n\n int nextInteger(){\n return scanner.nextInt();\n }\n\n double nextDouble(){\n return scanner.nextDouble();\n }\n\n String nextLine(){\n return scanner.nextLine();\n }\n\n String next(){\n return scanner.next();\n }\n\n int[] nextIntegers(int count){\n int[] result = new int[count];\n for(int i = 0; i < count; ++i){\n result[i] = nextInteger();\n }\n return result;\n }\n\n long[] nextLongs(int count){\n long[] result = new long[count];\n for(int i = 0; i < count; ++i){\n result[i] = nextLong();\n }\n return result;\n }\n\n int[][] nextIntegers(int fields, int count){\n int[][] result = new int[fields][count];\n for(int c = 0; c < count; ++c){\n for(int i = 0; i < fields; ++i){\n result[i][c] = nextInteger();\n }\n }\n return result;\n }\n }\n\n void noResult(){\n throw new NoResultException();\n }\n\n void noResult(String str){\n throw new NoResultException(str);\n }\n\n void run(){\n try{\n ByteArrayOutputStream outStream = new ByteArrayOutputStream();\n out = new PrintWriter(outStream);\n solve();\n out.close();\n System.out.print(outStream.toString());\n } catch (NoResultException exc){\n System.out.print(null == exc.response ? noResultMessage : exc.response);\n }\n }\n\n public static void main(String[] args) {\n new EMain().run();\n }\n\n public static class NoResultException extends RuntimeException{\n private String response;\n\n public NoResultException(String response) {\n this.response = response;\n }\n\n public NoResultException() {\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1b92c4c97ba4b33c228f24c0f4da2827", "src_uid": "175ce134da7cc5af9c8457e7bd9a40a2", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic final int N=1000005;\n\tstatic int a[]=new int[N];\n\tstatic int t[]=new int[N];\n\tstatic int ans=0;\n\t@SuppressWarnings(\"unchecked\")\n\tstatic ArrayListG[]=new ArrayList[N];\n\tstatic HashMap,Integer>vis=new HashMap,Integer>();\n\tstatic HashMapbook=new HashMap();\n\tstatic int sz;\n\tstatic class cmp implements Comparator{\n\t\t@Override \n\t\tpublic int compare(Object o1,Object o2) {\n\t\t\tInteger p1=(Integer)o1;\n\t\t\tInteger p2=(Integer)o2;\n\t\t\treturn p1>p2?1:-1;\n\t\t}\n\t}\n\tstatic int dfs(int u,int fa) {\n\t\tStringBuilder st=new StringBuilder(String.valueOf(u));\n\t\tst.append(\"#\");\n\t\tst.append(String.valueOf(fa));\n\t\tif(book.containsKey(st.toString())) {\n\t\t\treturn book.get(st.toString());\n\t\t}\n\t\tArrayListtemp=new ArrayList();\n\t\tfor(int i=0;i();\n\t \tif(G[v]==null) G[v]=new ArrayList();\n\t \tG[u].add(v);G[v].add(u);\n\t }\n\t int ans=0;\n\t HashMapmap=new HashMap();\n\t for(int i=1;i<=n;i++) {\n\t \tif(G[i].size()==4) continue;\n\t \tint id=dfs(i,-1);\n\t \tif(!map.containsKey(id)) {\n\t \t\tans++;\n\t \t\tmap.put(id, 1);\n\t \t}\n\t }\n\t out.println(ans);\n\t out.flush();\n\t}\n\tstatic class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "89f4774451d4c4b52180cabc87539682", "src_uid": "3c5aedd5d3bc12dca3e921c95ef05270", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "package codeforces;\nimport java.io.*;\nimport java.util.*;\npublic class Main {\n\tstatic final int N=100005;\n\tstatic int a[]=new int[N];\n\tstatic ArrayListG[]=new ArrayList[N];\n\tstatic HashMap,Integer>vis=new HashMap,Integer>();\n\tstatic HashMapbook=new HashMap();\n\tstatic int sz;\n\tstatic class cmp implements Comparator{\n\t\t@Override \n\t\tpublic int compare(Object o1,Object o2) {\n\t\t\tInteger p1=(Integer)o1;\n\t\t\tInteger p2=(Integer)o2;\n\t\t\treturn p1>p2?1:-1;\n\t\t}\n\t}\n\tstatic int dfs(int u,int fa) {\n\t\tString st=u+\"#\"+fa;\n\t\tif(book.containsKey(st)) {\n\t\t\treturn book.get(st);\n\t\t}\n\t\tArrayListtemp=new ArrayList();\n\t\tfor(int i=0;i();\n\t \tif(G[v]==null) G[v]=new ArrayList();\n\t \tG[u].add(v);G[v].add(u);\n\t }\n\t int ans=0;\n\t HashMapmap=new HashMap();\n\t for(int i=1;i<=n;i++) {\n\t \tif(G[i]==null) continue;\n\t \tif(G[i].size()==4) continue;\n\t \tint id=dfs(i,-1);\n\t \tif(!map.containsKey(id)) {\n\t \t\tans++;\n\t \t\tmap.put(id, 1);\n\t \t}\n\t }\n\t if(n==1) ans=1;\n\t out.println(ans);\n\t out.flush();\n\t}\n\tstatic class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e9ea38152427a35fa824514fbb68e26", "src_uid": "3c5aedd5d3bc12dca3e921c95ef05270", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic final int N=100005;\n\tstatic int a[]=new int[N];\n\tstatic ArrayListG[]=new ArrayList[N];\n\tstatic HashMap,Integer>vis=new HashMap,Integer>();\n\tstatic HashMapbook=new HashMap();\n\tstatic int sz;\n\tstatic class cmp implements Comparator{\n\t\t@Override \n\t\tpublic int compare(Object o1,Object o2) {\n\t\t\tInteger p1=(Integer)o1;\n\t\t\tInteger p2=(Integer)o2;\n\t\t\treturn p1>p2?1:-1;\n\t\t}\n\t}\n\tstatic int dfs(int u,int fa) {\n\t\tStringBuilder st=new StringBuilder(String.valueOf(u));\n\t\tst.append(\"#\");st.append(String.valueOf(fa));\n\t\tif(book.containsKey(st.toString())) {\n\t\t\treturn book.get(st.toString());\n\t\t}\n\t\tArrayListtemp=new ArrayList();\n\t\tfor(int i=0;i();\n\t \tif(G[v]==null) G[v]=new ArrayList();\n\t \tG[u].add(v);G[v].add(u);\n\t }\n\t int ans=0;\n\t HashMapmap=new HashMap();\n\t for(int i=1;i<=n;i++) {\n\t \tif(G[i].size()==4) continue;\n\t \tint id=dfs(i,-1);\n\t \tif(!map.containsKey(id)) {\n\t \t\tans++;\n\t \t\tmap.put(id, 1);\n\t \t}\n\t }\n\t out.println(ans);\n\t out.flush();\n\t}\n\tstatic class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1982b5fa1ded08b1e6e8a75e43074f5b", "src_uid": "3c5aedd5d3bc12dca3e921c95ef05270", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\npublic class Main {\n\tstatic final int N=100005;\n\tstatic int a[]=new int[N];\n\tstatic ArrayListG[]=new ArrayList[N];\n\tstatic HashMap,Integer>vis=new HashMap,Integer>();\n\tstatic HashMapbook=new HashMap();\n\tstatic int sz;\n\tstatic class cmp implements Comparator{\n\t\t@Override \n\t\tpublic int compare(Object o1,Object o2) {\n\t\t\tInteger p1=(Integer)o1;\n\t\t\tInteger p2=(Integer)o2;\n\t\t\treturn p1>p2?1:-1;\n\t\t}\n\t}\n\tstatic int dfs(int u,int fa) {\n\t\tStringBuffer st=new StringBuffer(u);\n\t\tst.append(\"#\");st.append(fa);\n\t\tif(book.containsKey(st)) {\n\t\t\treturn book.get(st);\n\t\t}\n\t\tArrayListtemp=new ArrayList();\n\t\tfor(int i=0;i();\n\t \tif(G[v]==null) G[v]=new ArrayList();\n\t \tG[u].add(v);G[v].add(u);\n\t }\n\t int ans=0;\n\t HashMapmap=new HashMap();\n\t for(int i=1;i<=n;i++) {\n\t \tif(G[i]==null) continue;\n\t \tif(G[i].size()==4) continue;\n\t \tint id=dfs(i,-1);\n\t \tif(!map.containsKey(id)) {\n\t \t\tans++;\n\t \t\tmap.put(id, 1);\n\t \t}\n\t }\n\t if(n==1) ans=1;\n\t out.println(ans);\n\t out.flush();\n\t}\n\tstatic class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ba31a2b610ee996069134e0b473bbf37", "src_uid": "3c5aedd5d3bc12dca3e921c95ef05270", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n/*\n * !!!!!!!!!!!!!!!!!!!!!!!!!\n * !!!!!!ACTUALLY PrC!!!!!!!\n * !!!!!!!!!!!!!!!!!!!!!!!1!\n */\npublic class PrD {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\t\n\t\t\n\t\tscan.nextLine();\n\t\t\n\t\tboolean cards[][] = new boolean[10][10];\n\t\t\n\t\tscan.nextLine();\n\t\tString s = scan.nextLine();\n\n\t\ts = s.replaceAll(\"\\\\s+\", \"\");\n\t\tchar c;\n\t\tint x;\n\t\tfor(int i = 0; i < s.length(); i+=2){\n\t\t\tc = s.charAt(i);\n\t\t\tx = Integer.parseInt(String.valueOf(s.charAt(i+1)))-1;\n\t\t\tswitch (c){\n\t\t\t\tcase 'R':\tcards[0][x] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\tcase 'G':\tcards[1][x] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\tcase 'B':\tcards[2][x] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\tcase 'Y':\tcards[3][x] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\tcase 'W':\tcards[4][x] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tint nums = 0, cols = 0;\n\t\tfor(int i = 0; i < 5; i++){\n\t\t\tfor(int j = 0; j < 5; j++){\n\t\t\t\tif(cards[i][j])\n\t\t\t\t\tnums++;\n\t\t\t\t\t\n\t\t\t\tif(cards[j][i] && i != j)\n\t\t\t\t\tcols++;\n\t\t\t}\n\t\t\tif(nums > 0){\n\t\t\t\tans += nums-1;\n\t\t\t\tnums = 0;\n\t\t\t}\n\t\t\tif(cols > 0){\n\t\t\t\tans += cols-1;\n\t\t\t\tcols = 0;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "508903372c64abc3fb8a449985984e29", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class BoryaAndHanabi {\n private BoryaAndHanabi() throws IOException {\n BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\n String h = rd.readLine();\n int n = Integer.parseInt(h);\n h = rd.readLine();\n String[] cards = h.split(\"\\\\s+\");\n boolean[][] cardExists = new boolean[5][5];\n int[] colorToIndex = new int['Z'];\n colorToIndex['R'] = 0;\n colorToIndex['G'] = 1;\n colorToIndex['B'] = 2;\n colorToIndex['Y'] = 3;\n colorToIndex['W'] = 4;\n for(String c: cards) {\n cardExists[colorToIndex[c.charAt(0)]][c.charAt(1)-'0'] = true;\n }\n int minHints = 10;\n for(int i=0;i<(1<<10);i++) {\n boolean hintsOk = true;\n boolean singleUsed = false;\n for(int j=0;hintsOk && j<5;j++) {\n for(int k=0;hintsOk && k<5;k++) {\n if(cardExists[j][k]) {\n boolean colorHint = chint(i, j);\n boolean digitHint = dhint(i, k);\n if(!colorHint && !digitHint) {\n if(singleUsed) {\n hintsOk = false;\n break;\n } else {\n singleUsed = true;\n }\n } else if(colorHint && !digitHint) {\n for(int m=0;m<5;m++) {\n if(m != k && cardExists[j][m]) {\n if(!dhint(i, m)) {\n hintsOk = false;\n break;\n }\n }\n }\n } else if(!colorHint && digitHint) {\n for(int m=0;m<5;m++) {\n if(m != j && cardExists[m][k]) {\n if(!chint(i, m)) {\n hintsOk = false;\n break;\n }\n }\n }\n }\n }\n }\n }\n if(hintsOk) {\n int hints = new BigInteger(i+\"\").bitCount();\n minHints = Math.min(minHints, hints);\n }\n }\n out(minHints);\n }\n\n private boolean chint(int i, int x) {\n return (i & (1< 0;\n }\n\n private boolean dhint(int i, int x) {\n return (i & (1<<(x+5))) > 0;\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 BoryaAndHanabi();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e0d0a83118b61b01ba28cd4ace09a670", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A {\n\n private static final char[] COLOR = {\n 'R', 'G', 'B', 'Y', 'W'\n };\n \n public int solve(int n, String[] cards) {\n int[] c = new int[n];\n for (int i=0; i=2)\n return;\n int flag = (1<<(c[idx]/5)) | (1<<(5+c[idx]%5));\n if ((flag&s)==flag) {\n if (rest[c[idx]]>0) {\n rest[c[idx]]--;\n check(n, c, s, rest, idx+1);\n rest[c[idx]]++;\n }\n } else if ((flag&s)>=(1<<5)) {\n for (int i=0; i<5; i++)\n if (rest[i*5+c[idx]%5]>0) {\n rest[i*5+c[idx]%5]--;\n check(n, c, s, rest, idx+1);\n rest[i*5+c[idx]%5]++;\n if (possible>=2)\n return;\n }\n } else if ((flag&s)>0) {\n for (int i=0; i<5; i++)\n if (rest[(c[idx]/5)*5+i]>0) {\n rest[(c[idx]/5)*5+i]--;\n check(n, c, s, rest, idx+1);\n rest[(c[idx]/5)*5+i]++;\n if (possible>=2)\n return;\n }\n } else {\n for (int i=0; i<25; i++)\n if (rest[i]>0) {\n rest[i]--;\n check(n, c, s, rest, idx+1);\n rest[i]++;\n if (possible>=2)\n return;\n }\n }\n }\n }\n \n public static void main(String args[]) throws IOException {\n BufferedReader br = null;\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n String line = br.readLine();\n int n = Integer.parseInt(line);\n String[] cards = br.readLine().split(\" \");\n System.out.println(new A().solve(n, cards));\n } finally {\n if (br!=null)\n br.close();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6116112f846129d208080fecd382220", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n@SuppressWarnings(\"unchecked\")\npublic class Main {\n InputReader ir = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int colarr[] = new int[5];\n int numarr[] = new int[5];\n HashMap map = new HashMap();\n String arr[];\n int n;\n int min = 1000000;\n void solve(){\n n = ir.readInt();\n Set set = new HashSet();\n for(int i = 0; i < n; i++) {\n String str = ir.readString();\n set.add(str);\n }\n \n map.put('R', 0);\n map.put('G', 1);\n map.put('B', 2);\n map.put('Y', 3);\n map.put('W', 4);\n n = set.size();\n int c = 0;\n arr = new String[n];\n for(String i: set) {\n arr[c++] = i;\n int idx = map.get(i.charAt(0));\n colarr[idx]++;\n idx = (int)(i.charAt(1) - '1');\n numarr[idx]++;\n }\n \n rec(0,0,0);\n out.println(min);\n }\n void rec(int colmask, int nummask, int count) {\n if(count >= min)\n return;\n //out.println(colmask + \" \" + nummask);\n boolean visit[] = new boolean[n];\n int tempcol[] = Arrays.copyOf(colarr, 5);\n int tempnum[] = Arrays.copyOf(numarr, 5);\n for(int i = 0; i < n; i++) {\n\n String str = arr[i];\n int col = map.get(str.charAt(0));\n int num = (int)(str.charAt(1) - '1');\n int mc = 1 << col;\n int mn = 1 << num;\n \n if(((((mc)&(colmask)) != 0) && (((mn)&(nummask))) != 0)) {\n \n visit[i] = true;\n tempcol[col]--;\n tempnum[num]--;\n }\n }\n\n for(int j = 0; j < n; j++)\n for(int i = 0; i < n; i++) {\n if(visit[i] == true)\n continue;\n String str = arr[i];\n int col = map.get(str.charAt(0));\n int num = (int)(str.charAt(1) - '1');\n int mc = 1 << col;\n int mn = 1 << num;\n if(((mc)&(colmask)) != 0) {\n if(tempcol[col] == 1) {\n visit[i] = true;\n tempcol[col]--;\n tempnum[num]--;\n }\n } else if (((mn)&(nummask)) != 0 ) {\n if(tempnum[num] == 1) {\n visit[i] = true;\n tempcol[col]--;\n tempnum[num]--;\n }\n }\n }\n int c = 0;\n\n for(int i = 0; i < n; i++) {\n \n if(visit[i] == false)\n c++;\n }\n if(c <= 1) {\n min = Math.min(count, count);\n }\n\n for(int i = 0; i < n; i++) {\n if(((1 << i) & colmask) == 0) {\n rec((1 << i) | colmask, nummask, count + 1);\n }\n if(((1 << i) & nummask) == 0) {\n rec(colmask, (1 << i) | nummask, count + 1);\n }\n }\n\n }\n\n void run() {\n solve();\n out.close();\n }\n public static void main(String args[]) {\n new Main().run();\n }\n}\n\n\nclass InputReader {\n \n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n public final int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n public double readDouble() {\n return Double.parseDouble(readString());\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}\nclass Pair , Type2 extends Comparable> implements Comparable >{\n Type1 first;\n Type2 second;\n public Pair(Type1 F, Type2 S) {\n this.first = F;\n this.second = S;\n }\n @Override \n public int compareTo(Pair p) {\n if(first.compareTo(p.first) == 0)\n return second.compareTo(p.second);\n return first.compareTo(p.first);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "42598833d338f56e12c3e28163b449ea", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\npublic class posperm{\npublic static int op[] = {0,1,2,4,6,8,9,16,17,18};\npublic static long dp[][][];\n//public static long bf[][];\npublic static long mod =0;\npublic static void bf(int pos,int vec,int llevo,int tot,int prop){\nif(pos==0){\nbf[vec][prop]=(bf[vec][prop]+1)%mod;\nreturn;\n}\nfor(int n = 1;n<=tot;n++){\nint prop2 = prop;\nif(((1<=dp.length || b<0 || b>=dp.length) return 0;\nfor(int n= 0;n=dp.length || b<0 || b>=dp.length) return 0;\nint y = 0;\nfor(int n =0;n1)return 0;\nif(n==3)y =0;\nif(c.charAt(n)=='1')y++;\n}\n\nint d = c.indexOf(\"*\");\nif(d==-1)return dp[a][b][Integer.parseInt(c,2)];\nfor(int n = 0;n<2;n++)\ntal=(tal+sum2(a,b,c.substring(0,d)+n+c.substring(d+1),0))%mod;\nreturn tal%mod;\n}\npublic static void main(String args[]) throws IOException{\nBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\nString tmp = lector.readLine();\nint a = Integer.parseInt(tmp.substring(0,tmp.indexOf(\" \")));\nint b = Integer.parseInt(tmp.substring(tmp.indexOf(\" \")+1));\nmod = 1000000007;\nlong res = 0;\n//bf = new long[Math.max(a+2,4)][33];\ndp= new long[Math.max(a+2,4)][Math.max(a+2,4)][33];\ndp[1][0][1]=1;\ndp[2][0][9]=1;\ndp[2][2][6]=1;\ndp[3][0][9]=1;\ndp[3][0][8]=1;\ndp[3][2][6]=1;\ndp[3][2][17]=1;\ndp[3][2][4]=1;\ndp[3][2][18]=1;\nString rejoder[] = {\"00010\",\"10010\",\"01010\",\"00110\"};\nString joder[] ={\"00000\",\"10000\",\"01000\",\"00100\"};\nString joder1[] = {\"00001\",\"01001\",\"10001\"};\nString joder2[] = {\"00010\",\"10010\",\"00110\"};\nString joder3[] = {\"00000\",\"01000\",\"10000\"};\nString joder4[] = {\"00010\",\"10010\"};\nfor(int n = 4;n= 0){\n\t\t\t\t\tdp[i][j][0][1] += dp[i-1][j-1][0][0];\n\t\t\t\t\tdp[i][j][0][1] += dp[i-1][j-1][0][1];\n\t\t\t\t\tdp[i][j][1][0] += dp[i-1][j-1][0][0];\n\t\t\t\t\tdp[i][j][1][0] += dp[i-1][j-1][1][0];\n\t\t\t\t\tdp[i][j][0][1] %= mod;\n\t\t\t\t\tdp[i][j][1][0] %= mod;\n\t\t\t\t}\n\t\t\t\tif(j-2 >= 0){\n\t\t\t\t\tdp[i][j][1][1] += dp[i-1][j-2][0][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] fif = enumFIF(n, mod);\n\t\t\n\t\tlong[] F = new long[n+1];\n\t\tfor(int j = 0;j <= n;j++){\n\t\t\tfor(int k = 0;k < 2;k++){\n\t\t\t\tfor(int l = 0;l < 2;l++){\n\t\t\t\t\tF[j] += dp[n-1][j][k][l];\n\t\t\t\t}\n\t\t\t}\n\t\t\tF[j] %= mod;\n\t\t}\n\t\t\n\t\tlong ret = 0;\n\t\tfor(int j = K;j <= n;j++){\n\t\t\tlong plus = F[j] * fif[0][n-j] % mod * fif[0][j]%mod*fif[1][j-K]%mod*fif[1][K]%mod;\n\t\t\tif((K-j)%2 == 0){\n\t\t\t\tret += plus;\n\t\t\t}else{\n\t\t\t\tret += mod-plus;\n\t\t\t}\n\t\t}\n\t\tout.println(ret%mod);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod)\n\t{\n\t\tint[] f = new int[n+1];\n\t\tint[] invf = new int[n+1];\n\t\tinvf[1] = 1;\n\t\tfor(int i = 2;i <= n;i++){\n\t\t\tinvf[i] = (int)(invf[mod%i]*(long)(mod-mod/i)%mod);\n\t\t}\n\t\t\n\t\tf[0] = invf[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\tinvf[i] = (int)((long)invf[i-1] * invf[i] % mod);\n\t\t}\n\t\treturn new int[][]{f, invf};\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de61f3b36881ef3b18a5934b1e04e4ea", "src_uid": "1243e98fe2ebd6e6d1de851984b96079", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n static int n;\n static int[][][] DP;\n static int mod = (int) 1e9 + 7;\n\n public static int get(int index, int k, int used) {\n if (k < 0)\n return 0;\n if (index == n)\n if (k == 0)\n return 1;\n else\n return 0;\n if (DP[index][k][used] != -1)\n return DP[index][k][used];\n int ans = 0;\n // none\n ans = (ans + get(index + 1, k, (used << 1) & 3)) % mod;\n // i - 1\n if ((used & 2) == 0)\n ans = (ans + get(index + 1, k - 1, (used << 1) & 3)) % mod;\n // i+1\n if (index != n - 1)\n ans = (ans + get(index + 1, k - 1, ((used << 1) & 3) + 1)) % mod;\n return DP[index][k][used] = ans;\n\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n int k = in.nextInt();\n long[] F = new long[n + 1];\n F[0] = 1;\n for (int i = 1; i <= n; i++)\n F[i] = (F[i - 1] * i) % mod;\n long[][] C = new long[n + 1][n + 1];\n for (int i = 0; i <= n; i++)\n for (int j = 0; j <= i; j++)\n if (j == 0 || i == j)\n C[i][j] = 1;\n else\n C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;\n DP = new int[n][n + 1][4];\n for (int i = 0; i < n; i++)\n for (int j = 0; j <= n; j++)\n Arrays.fill(DP[i][j], -1);\n long[] A = new long[n + 1];\n for (int i = 0; i <= n; i++)\n A[i] = (get(0, i, 2) * F[n - i]) % mod;\n for (int i = n - 1; i >= 0; i--)\n for (int j = i + 1; j <= n; j++)\n A[i] = ((A[i] - (C[j][i] * A[j]) % mod) + mod) % mod;\n System.out.println(A[k]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c82255b15d4ab0fc2c1572d1d09e7187", "src_uid": "1243e98fe2ebd6e6d1de851984b96079", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\npublic class posperm{\npublic static int op[] = {0,1,2,4,6,8,9,16,17,18};\npublic static int dp[][][];\n//public static long bf[][];\npublic static int mod =0;\n/*public static void bf(int pos,int vec,int llevo,int tot,int prop){\nif(pos==0){\nbf[vec][prop]=(bf[vec][prop]+1)%mod;\nreturn;\n}\nfor(int n = 1;n<=tot;n++){\nint prop2 = prop;\nif(((1<=dp.length || b<0 || b>=dp.length) return 0;\nfor(int n= 0;n=dp.length || b<0 || b>=dp.length) return 0;\nint y = 0;\nfor(int n =0;n1)return 0;\nif(n==3)y =0;\nif(c.charAt(n)=='1')y++;\n}\n\nint d = c.indexOf(\"*\");\nif(d==-1)return dp[a][b][Integer.parseInt(c,2)];\nfor(int n = 0;n<2;n++)\ntal=(tal+sum2(a,b,c.substring(0,d)+n+c.substring(d+1),0))%mod;\nreturn tal%mod;\n}\npublic static void main(String args[]) throws IOException{\nBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\nString tmp = lector.readLine();\nint a = Integer.parseInt(tmp.substring(0,tmp.indexOf(\" \")));\nint b = Integer.parseInt(tmp.substring(tmp.indexOf(\" \")+1));\nmod = 1000000007;\nlong res = 0;\n//bf = new long[Math.max(a+2,4)][33];\ndp= new int[Math.max(a+2,4)][Math.max(a+2,4)][33];\ndp[1][0][1]=1;\ndp[2][0][9]=1;\ndp[2][2][6]=1;\ndp[3][0][9]=1;\ndp[3][0][8]=1;\ndp[3][2][6]=1;\ndp[3][2][17]=1;\ndp[3][2][4]=1;\ndp[3][2][18]=1;\nString rejoder[] = {\"00010\",\"10010\",\"01010\",\"00110\"};\nString joder[] ={\"00000\",\"10000\",\"01000\",\"00100\"};\nString joder1[] = {\"00001\",\"01001\",\"10001\"};\nString joder2[] = {\"00010\",\"10010\",\"00110\"};\nString joder3[] = {\"00000\",\"01000\",\"10000\"};\nString joder4[] = {\"00010\",\"10010\"};\nfor(int n = 4;n arr = new ArrayList<>();\n for(int i =1;i<=root;i++)\n {\n if(len%i==0)\n {\n int j = len/i;\n arr.add(i);\n if(j!=i)\n arr.add(j);\n }\n }\n Collections.sort(arr);\n long dp[]= new long[arr.size()];\n dp[arr.size()-1]=1;\n for(int i=arr.size()-2;i>=0;i--)\n {\n int yo = arr.get(i);\n dp[i]= pow(2,len/yo-1,in);\n for(int j=i+1;j{\n int val ;\n int color;\n \n edge(int u, int v)\n {\n this.val=u;\n this.color=v;\n }\n public int compareTo(edge e)\n {\n return this.val-e.val;\n }\n}import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.List;\n import java.util.*;\n class realfast implements Runnable \n {\n private static final int INF = (int) 1e9;\n long in= (long)Math.pow(10,9)+7;\n long fac[]= new long[3000];\n public void solve() throws IOException \n {\n long m = in;\n\n int x = readInt();\n int y = readInt();\n \n if((y%x)!=0)\n out.println(0);\n else\n {\n int len =y/x;\n\n int root = (int)Math.pow(len,0.5);\n ArrayList arr = new ArrayList<>();\n for(int i =1;i<=root;i++)\n {\n if(len%i==0)\n {\n int j = len/i;\n arr.add(i);\n if(j!=i)\n arr.add(j);\n }\n }\n Collections.sort(arr);\n long dp[]= new long[arr.size()];\n dp[arr.size()-1]=1;\n for(int i=arr.size()-2;i>=0;i--)\n {\n int yo = arr.get(i);\n dp[i]= pow(2,len/yo-1,in);\n for(int j=i+1;j{\n int val ;\n int color;\n \n edge(int u, int v)\n {\n this.val=u;\n this.color=v;\n }\n public int compareTo(edge e)\n {\n return this.val-e.val;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "388af0fcbc3d1fe8adbf6e4747121267", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\nimport java.util.Collections;\nimport java.util.ArrayList;\n\n\npublic class javaapplication1 {\n\n public static final int MAX = 1000000007;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n \n ArrayList Dividendos = new ArrayList<>();\n \n\n int intX = in.nextInt();\n //long longX = (long)intX;\n int intY = in.nextInt();\n //long longY = (long)intY;\n \n //int[] arrDividendos = new int[intX];\n\n \n //No en Comun\n if (intY % intX != 0) {\n System.out.println(0);\n }else{\n intY = intY / intX;\n\n \n\n for (long i = 2; i * i <= intY; i++) {\n //Iniciar si es par\n if (intY % i == 0) {\n Dividendos.add((int) i);\n }\n //Es par pero no es el mismo numero\n if (intY % i == 0 && (intY / i != i)) {\n Dividendos.add(intY / (int) i);\n }\n /*\n if(intY % i == 0 && i !=intX){\n Dividendos.add(intY /x);\n }*/\n }\n\n if (intY != 1) {\n Dividendos.add(intY);\n } else {\n System.out.println(1);\n return;\n }\n\n int[] arrAnswer = new int[Dividendos.size()];\n long total = 0; \n Collections.sort(Dividendos);\n int temp = 0;\n for (int i = 0; i < arrAnswer.length; i++) {\n temp = (MAX + potencia(2, Dividendos.get(i) - 1,arrAnswer) - 1);\n //if(temp > intX){\n arrAnswer[i] = temp % MAX;\n //}\n }\n\n for (int i = 1; i < arrAnswer.length; i++) {\n for (int j = i - 1; j >= 0; j--) {\n if (Dividendos.get(i) % Dividendos.get(j) == 0) {\n temp =(int) ((MAX + arrAnswer[i] - (long) arrAnswer[j])\n arrAnswer[i] = temp % MAX);\n }\n /*\n if(intY % i == 0 && i !=intX){\n Dividendos.add(intY /x);\n }*/\n }\n total += arrAnswer[i];\n total = total % MAX;\n }\n System.out.println(arrAnswer[Dividendos.size() - 1]);\n }\n }\n\n\n public static int potencia(long x1, int x2, int[] intanswer) {\n long longI = 1;\n while (x2 >= 1) {\n if (x2 % 2 == 1) {\n longI = (longI * x1) % MAX;\n }\n x1 = (x1 * x1) % MAX;\n x2 = x2 /2;\n \n }\n //else\n //{break;\n // }\n return (int) longI;\n }\n\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5be46173584c516069fe7516cea9c4bb", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.0} {"lang": "Java 8", "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 Main implements Runnable {\n \n\tboolean TEST = System.getProperty(\"ONLINE_JUDGE\") == null;\n \n void solve() throws IOException {\n \tint x = nextInt(), y = nextInt();\n \tif (y % x != 0) {\n \t\tout.println(0);\n \t\treturn;\n \t}\n \tout.println(f(y / x));\n }\n \n int MOD = (int)1e9 + 7;\n long f(int t) {\n \tif (t == 1) return 1;\n \tlong res = pow(2, t - 1, MOD);\n \tfor (int i = 2; i * i <= t; i++)\n \t\tif (t % i == 0) {\n \t\t\tres = (res + MOD - f(i)) % MOD;\n \t\t\tif (i * i != t) res = (res + MOD - f(t / i)) % MOD;\n \t\t}\n \treturn (res + MOD - 1) % MOD;\n }\n \n long pow(long a, long p, int MOD) {\n \tif (p == 0) return 1;\n \tlong b = pow(a, p / 2, MOD);\n \tif (p % 2 == 0) return b * b % MOD;\n \treturn b * b % MOD * a % MOD;\n }\n \n String next() throws IOException {\n while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.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 void debug(Object... o) {\n System.out.println(deepToString(o));\n }\n \n void gcj(Object o) {\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 if (TEST) input = new BufferedReader(new FileReader(\"input.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 new Thread(null, new Main(), \"\", 1 << 20).start();\n }\n \n public void run() {\n try {\n init();\n if (TEST) {\n int runs = nextInt();\n for(int i = 0; i < runs; i++) solve();\n } else solve();\n out.close(); \n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eb3a44376d91a4b51e0caec02b1a74f6", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static void main(String args[]) {new Main().run();}\n\n\tFastReader in = new FastReader();\n\tPrintWriter out = new PrintWriter(System.out);\n\tvoid run(){\n\t\twork();\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn a==0?b:b>=a?gcd(b%a,a):gcd(b,a);\n\t}\n\tArrayList rec=new ArrayList<>();\n\tvoid work() {\n\t\tint a=in.nextInt(),b=in.nextInt();\n\t\tif(b%a!=0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tb/=a;\n\t\tif(b==1) {\n\t\t\tout.println(1);\n\t\t\treturn;\n\t\t}\n\t\tfor(int i=2;i*i<=b;i++) {\n\t\t\tif(b%i==0) {\n\t\t\t\trec.add(i);\n\t\t\t\tif(i!=b/i)rec.add(b/i);\n\t\t\t}\n\t\t}\n\t\tout.println(find(b));\n\t}\n\tprivate long find(int b) {\n\t\tlong r=(pow(2,b-1)-1+mod)%mod;\n\t\tfor(int k:rec) {\n\t\t\tif(b%k==0) {\n\t\t\t\tr-=find(b/k);\n\t\t\t\tr=(r+mod)%mod;\n\t\t\t}\n\t\t}\n\t\treturn r;\n\t}\n\tprivate long pow(long a, long b) {\n\t\tlong r=1;\n\t\twhile(b>0) {\n\t\t\tif(b%2==1) {\n\t\t\t\tr*=a;\n\t\t\t\tr%=mod;\n\t\t\t}\n\t\t\tb/=2;\n\t\t\ta*=a;\n\t\t\ta%=mod;\n\t\t}\n\t\treturn r;\n\t}\n}\t\n\n\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n\t\n\t\n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "57f5e415dcf41b2e4beeddacd9d9fe2d", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class d {\n static double EPS = 1e-7;\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int n = in.nextInt();\n \n Vec com = new Vec(0, 0);\n Vec[] vecs = new Vec[n];\n for(int i = 0; i < n; i++) {\n com = com.add(vecs[i] = new Vec(in.nextInt(), in.nextInt()));\n }\n com = com.scale(1.0/n);\n \n boolean[] works = new boolean[n];\n Arrays.fill(works, true);\n int num = n;\n for(int i = 0; i < n; i++) {\n if(vecs[i].equals(com)) {\n works[i] = false;\n num--;\n continue;\n }\n for(int j = 0; j < i; j++) {\n if(vecs[i].sub(com).equals(com.sub(vecs[j]))) {\n works[i] = works[j] = false;\n num -= 2;\n break;\n }\n }\n }\n Vec[] act = new Vec[num];\n int curr = 0;\n for(int i = 0; i < n; i++) if(works[i]) act[curr++] = vecs[i];\n n = num;\n if(n == 0) {\n System.out.println(-1);\n return;\n }\n int res = 0;\n \n Vec[] norms = new Vec[n];\n \n outer: for(int i = 0; i < n; i++) {\n Vec diff = act[i].sub(act[0]);\n Vec mid = act[0].add(diff.scale(0.5));\n Vec perp = com.sub(mid);\n Vec norm = perp.rot90();\n norm = norm.scale(1.0/Math.sqrt(norm.dot(norm)));\n if(norm.x < 0) {\n norm.x *= -1;\n norm.y *= -1;\n }\n norms[i] = norm;\n for(int j = 0; j < i; j++) {\n if(norms[j].equals(norm)) continue outer;\n }\n double[] arr = new double[n];\n for(int j = 0; j < n; j++) arr[j] = norm.dot(act[j]);\n Arrays.sort(arr);\n double cent = norm.dot(com);\n for(int j = 0; j < n; j++) {\n if(!eq(cent-arr[j], arr[n-1-j]-cent)) continue outer;\n }\n res++;\n }\n System.out.println(res);\n out.close();\n }\n \n static class Vec {\n double x, y;\n \n public Vec(double A, double B) {\n x = A;\n y = B;\n }\n \n public Vec add(Vec o) {\n return new Vec(x+o.x, y+o.y);\n }\n \n public Vec sub(Vec o) {\n return new Vec(x-o.x, y-o.y);\n }\n \n public Vec scale(double s) {\n return new Vec(x*s, y*s);\n }\n \n public Vec rot90() {\n return new Vec(-y, x);\n }\n \n public double dot(Vec o) {\n return x*o.x + y*o.y;\n }\n \n @Override\n public boolean equals(Object o) {\n return eq(x, ((Vec)o).x) && eq(y, ((Vec)o).y);\n }\n }\n \n static boolean eq(double a, double b) {\n return Math.abs(a-b) <= EPS;\n }\n \n static class FS {\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if(token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d92e7999db214000132e0c87c9ab4de5", "src_uid": "5d7ba962400c05433ee17c5658888e69", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class d {\n static double EPS = 1e-6;\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int n = in.nextInt();\n \n Vec com = new Vec(0, 0);\n Vec[] vecs = new Vec[n];\n for(int i = 0; i < n; i++) {\n com = com.add(vecs[i] = new Vec(in.nextInt(), in.nextInt()));\n }\n com = com.scaleR(n);\n \n boolean[] works = new boolean[n];\n Arrays.fill(works, true);\n int num = n;\n for(int i = 0; i < n; i++) {\n if(vecs[i].equals(com)) {\n works[i] = false;\n num--;\n continue;\n }\n for(int j = 0; j < i; j++) {\n if(works[j] && vecs[i].sub(com).equals(com.sub(vecs[j]))) {\n works[i] = works[j] = false;\n num -= 2;\n break;\n }\n }\n }\n Vec[] act = new Vec[num];\n int curr = 0;\n for(int i = 0; i < n; i++) if(works[i]) act[curr++] = vecs[i];\n n = num;\n if(n == 0) {\n System.out.println(-1);\n return;\n }\n int res = 0;\n \n Vec[] norms = new Vec[n];\n \n outer: for(int i = 0; i < n; i++) {\n Vec diff = act[i].sub(act[0]);\n Vec mid = act[0].add(diff.scaleR(2));\n Vec perp = com.sub(mid);\n Vec norm = perp.rot90();\n norm = norm.scaleR(Math.sqrt(norm.dot(norm)));\n if(norm.x < 0) {\n norm.x *= -1;\n norm.y *= -1;\n }\n norms[i] = norm;\n for(int j = 0; j < i; j++) {\n if(norms[j].equals(norm)) continue outer;\n }\n double[] arr = new double[n];\n for(int j = 0; j < n; j++) arr[j] = norm.dot(act[j]);\n Arrays.sort(arr);\n double cent = (arr[0]+arr[n-1])/2;\n for(int j = 0; j < n; j++) {\n if(!eq(cent-arr[j], arr[n-1-j]-cent)) continue outer;\n }\n res++;\n }\n System.out.println(res);\n out.close();\n }\n \n static class Vec {\n double x, y;\n \n public Vec(double A, double B) {\n x = A;\n y = B;\n }\n \n public Vec add(Vec o) {\n return new Vec(x+o.x, y+o.y);\n }\n \n public Vec sub(Vec o) {\n return new Vec(x-o.x, y-o.y);\n }\n \n public Vec scale(double s) {\n return new Vec(x*s, y*s);\n }\n \n public Vec scaleR(double s) {\n return new Vec(x/s, y/s);\n }\n \n public Vec rot90() {\n return new Vec(-y, x);\n }\n \n public double dot(Vec o) {\n return x*o.x + y*o.y;\n }\n \n @Override\n public boolean equals(Object o) {\n return eq(x, ((Vec)o).x) && eq(y, ((Vec)o).y);\n }\n }\n \n static boolean eq(double a, double b) {\n return Math.abs(a-b) <= EPS;\n }\n \n static class FS {\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if(token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f7c9c52cdd8cf4286e977c9a28ee3073", "src_uid": "5d7ba962400c05433ee17c5658888e69", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt();\n Point[] p = new Point[n];\n Point cen = new Point(0, 0);\n for (int i = 0; i < n; i++) {\n long x = in.nextLong();\n long y = in.nextLong();\n p[i] = new Point(x, y);\n cen = cen.add(p[i]);\n p[i] = p[i].mul(n);\n }\n for (int i = 0; i < n; ++i) {\n p[i] = p[i].minus(cen);\n }\n p = removeSymmetrical(p);\n n = p.length;\n if (n == 0) {\n out.println(\"-1\");\n return;\n }\n Set ans = new TreeSet<>();\n for (int i = 0; i < n; ++i) {\n Point a = p[0], b = p[i];\n Point vec = a.add(b).rotate90();\n vec.normalizeDirection();\n long[] d = new long[n];\n for (int j = 0; j < n; ++j)\n d[j] = dot(p[j], vec);\n\n Arrays.sort(d);\n boolean ok = true;\n for (int j = 0; j < n; ++j) {\n if (d[j] + d[n - j - 1] != 0) {\n ok = false;\n break;\n }\n }\n if (ok) ans.add(vec);\n }\n out.println(ans.size());\n }\n\n private Point[] removeSymmetrical(Point[] p) {\n int n = p.length;\n boolean[] dead = new boolean[n];\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (!dead[i] && !dead[j] && p[i].x == -p[j].x && p[i].y == -p[j].y) {\n dead[i] = true;\n dead[j] = true;\n }\n }\n }\n int k = 0;\n for (int i = 0; i < n; i++) {\n if (!dead[i] || p[i].x == 0 && p[i].y == 0) {\n p[k++] = p[i];\n }\n }\n return Arrays.copyOf(p, k);\n }\n\n private long dot(Point a, Point b) {\n return a.x * b.x + a.y * b.y;\n }\n\n private long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n class Point implements Comparable {\n long x;\n long y;\n\n Point(long x, long 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 minus(Point o) {\n return new Point(x - o.x, y - o.y);\n }\n\n Point mul(long n) {\n return new Point(x * n, y * n);\n }\n\n Point rotate90() {\n return new Point(-y, x);\n }\n\n void normalizeDirection() {\n long d = gcd(Math.abs(x), Math.abs(y));\n if (y > 0 || y == 0 && x > 0) {\n\n } else {\n x = -x;\n y = -y;\n }\n if (d != 0) {\n x /= d;\n y /= d;\n }\n }\n\n public int compareTo(Point o) {\n if (x != o.x) {\n return x < o.x ? -1 : 1;\n }\n if (y != o.y) {\n return y < o.y ? -1 : 1;\n }\n return 0;\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d5207d00dd13b2527687c616896940c", "src_uid": "5d7ba962400c05433ee17c5658888e69", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.TreeSet;\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 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 int n = in.nextInt();\n Point[] p = new Point[n];\n long sx = 0;\n long sy = 0;\n for (int i = 0; i < n; i++) {\n long x = in.nextLong();\n long y = in.nextLong();\n x *= n;\n y *= n;\n p[i] = new Point(x, y);\n sx += x;\n sy += y;\n }\n sx /= n;\n sy /= n;\n for (int i = 0; i < n; i++) {\n p[i].x -= sx;\n p[i].y -= sy;\n }\n p = removeSymmetrical(p);\n n = p.length;\n\n if (n <= 1) {\n out.println(-1);\n return;\n }\n\n Set ans = new TreeSet<>();\n for (int i = 0; i < n; i++) {\n Point dir = p[0].add(p[i]).rotate90();\n dir.normalizeDirection();\n long[] xs = new long[n];\n for (int j = 0; j < n; j++) {\n xs[j] = dot(dir, p[j]);\n }\n Arrays.sort(xs);\n\n boolean ok = true;\n for (int j = 0; j < n; j++) {\n if (xs[0] + xs[n - 1] != xs[j] + xs[n - 1 - j]) {\n ok = false;\n break;\n }\n }\n if (ok) {\n ans.add(dir);\n }\n }\n out.println(ans.size());\n }\n\n private Point[] removeSymmetrical(Point[] p) {\n int n = p.length;\n boolean[] dead = new boolean[n];\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (!dead[i] && !dead[j] && p[i].x == -p[j].x && p[i].y == -p[j].y) {\n dead[i] = true;\n dead[j] = true;\n }\n }\n }\n\n int k = 0;\n for (int i = 0; i < n; i++) {\n if (!dead[i]) {\n p[k++] = p[i];\n }\n }\n return Arrays.copyOf(p, k);\n }\n\n private long dot(Point a, Point b) {\n return a.x * b.x + a.y * b.y;\n }\n\n private long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n class Point implements Comparable {\n long x;\n long y;\n\n Point(long x, long 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 rotate90() {\n return new Point(-y, x);\n }\n\n void normalizeDirection() {\n long d = gcd(Math.abs(x), Math.abs(y));\n if (y > 0 || y == 0 && x > 0) {\n\n } else {\n x = -x;\n y = -y;\n }\n x /= d;\n y /= d;\n }\n\n public int compareTo(Point o) {\n if (x != o.x) {\n return x < o.x ? -1 : 1;\n }\n if (y != o.y) {\n return y < o.y ? -1 : 1;\n }\n return 0;\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 public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ac49bc50c9df52ec42b5b53b9764a5c", "src_uid": "5d7ba962400c05433ee17c5658888e69", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "//import java.awt.Dimension;\nimport java.awt.Point;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\nimport java.util.*;\nimport static java.util.Arrays.*;\n//import java.math.BigInteger;\n//import static java.lang.Character.*;\n//import static java.lang.Math.*;\n//import static java.math.BigInteger.*;\n\n//import static java.util.Arrays.*;\n\n//import java.awt.Point; // interger !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n//import java.awt.Polygon;\n//import java.awt.Rectangle;\n//import java.awt.geom.AffineTransform;\n//import java.awt.geom.Line2D;\n//import java.awt.geom.Point2D;\n//import javafx.scene.shape.Line;\n//import javafx.scene.transform.Rotate;\n\n//\npublic class Main implements Runnable{\n\n // https://netbeans.org/kb/73/java/editor-codereference_ru.html#display\n\n static boolean oj;\n \n @Override\n public void run(){\n try {\n Locale.setDefault(Locale.US);\n } catch (Exception e) {\n }\n oj = true;\n try {\n oj = System.getProperty(\"MYLOCAL\") == null;\n } catch (Exception e) {\n }\n//\n if (oj) {\n sc = new FastScanner(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n } else {\n try {\n sc = new FastScanner(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n } catch (IOException e) {\n MLE();\n }\n }\n Solver s = new Solver();\n s.sc = sc;\n s.out = out;\n\n s.solve();\n if (!oj) {\n err.println(\"Time: \" + (System.currentTimeMillis() - timeBegin) / 1e3);\n err.printf(\"Mem: %d\\n\", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);\n }\n out.flush();\n }\n\n private void show(int[] arr) {\n for (int v : arr) {\n err.print(\" \" + v);\n }\n err.println();\n }\n\n public static void exit() {\n err.println(\"Time: \" + (System.currentTimeMillis() - timeBegin) / 1e3);\n err.printf(\"Mem: %d\\n\", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);\n out.flush();\n out.close();\n System.exit(0);\n }\n\n public static void MLE() {\n int[][] arr = new int[1024 * 1024][];\n for (int i = 0; i < arr.length; i++) {\n arr[i] = new int[1024 * 1024];\n }\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n //new Main().run();\n new Thread(null, new Main(), \"myThread\", 100 * 1024 * 1024).start();\n }\n\n static long timeBegin = System.currentTimeMillis();\n static FastScanner sc;\n static PrintWriter out;\n static PrintStream err = System.err;\n}\n //\n\n//\nclass FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStreamReader reader) {\n br = new BufferedReader(reader);\n st = new StringTokenizer(\"\");\n }\n\n String next() {\n while (!st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception ex) {\n return null;\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n try {\n return br.readLine();\n } catch (IOException ex) {\n return null;\n }\n }\n}\n//\n\nclass Solver {\n\n void aser(boolean OK) {\n if (!OK) {\n Main.MLE();\n }\n }\n\n FastScanner sc;\n PrintWriter out;\n static PrintStream err = System.err;\n \n long[] getAllDiv(long A){\n TreeSet arr = new TreeSet<>();\n for( long d = 1; d*d <= A; ++d ){\n if( A % d == 0 ) {\n arr.add(d);\n arr.add(A/d);\n }\n }\n int pos = 0;\n long[] a = new long[arr.size()];\n for (long x : arr) a[pos++] = x;\n return a;\n }\n \n long myPow(long p, int alfa){\n long ans = 1;\n for (int i = 0; i < alfa; i++) {\n ans *= p;\n }\n return ans;\n }\n \n void solve(){\n final long A = sc.nextLong();\n long[] divA = getAllDiv(A);\n TreeMap> P = new TreeMap<>();\n for (long div : divA) {\n --div;\n for (int alfa = 1; alfa <= 60; alfa++) {\n long p = (long)( pow( div, 1.0 / alfa ) + 0.5 );\n if( 2<=p && myPow(p,alfa)==div && \n valueOf(p).isProbablePrime(Integer.MAX_VALUE) ){\n if( !P.containsKey(p) )\n P.put(p, new TreeSet<>());\n P.get(p).add(alfa);\n \n }\n }\n }\n \n long[] dp0, dp;\n dp0 = new long[divA.length];\n dp0[0] = 1;\n for( long p : P.keySet() ){\n dp = dp0.clone();\n for( int alfa : P.get(p) ){\n long val = myPow(p, alfa) + 1;\n for( int ID = 0; ID < divA.length; ++ID){\n long div = divA[ID];\n if( 1e12 + 5 <= 1.0 * div * val ) break;\n long toDiv = div * val;\n int toID = binarySearch(divA, toDiv);\n if( 0 <= toID ) dp[toID] += dp0[ID];\n }\n }\n //\n dp0 = dp;\n }\n out.println(dp0[divA.length - 1]);\n }\n \n \n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5725ba68835e49e27cbf6c5bffe9a449", "src_uid": "1f68bd6f8b40e45a5bd360b03a264ef4", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.*;\n\npublic class Main\n{\t\n\tpublic BufferedReader in;\n\tpublic PrintStream out;\n\t\n\tpublic boolean log_enabled = false;\n\t\n\tstatic long[] primes;\n\tstatic int p_count;\n\t\n\tpublic static void get_primes(int n)\n\t{\n\t\tprimes = new long[80000];\n\t\t\n\t\tboolean[] v = new boolean[n+1];\n\t\tint i,j;\n\t\tfor (i=2; i<=n;i++)\n\t\t{\n\t\t\tv[i] = true;\n\t\t}\n\t\t\n\t\tfor (i=2; i*i<=n;i++)\n\t\t{\n\t\t\tif (v[i])\n\t\t\t{\n\t\t\t\tfor (j=i; i*j<=n; j++)\n\t\t\t\t{\n\t\t\t\t\tv[i*j]=false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tp_count = 0;\n\t\tfor (i=2; i<=n; i++)\n\t\t{\n\t\t\tif (v[i])\n\t\t\t{\t\n\t\t\t\tprimes[p_count++] = i;\n\t\t\t}\n\t\t}\n\t}\n\n\tint d_count;\n\tint[] d_index;\n\tlong A;\n\t\n\tpublic int d_index(long x)\n\t{\n\t\tif ( (x<1000000) && (x*x<=A))\n\t\t{\n\t\t\treturn d_index[(int)x];\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn d_count - d_index[(int)(A/x)] - 1;\n\t\t}\n\t}\n\n\tpublic void test()\n\t{\n\t\tA = readLong();\n\t\t\n\t\tif (A==1)\n\t\t{\n\t\t\tout.println(1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tget_primes(1000000);\n\t\t\n\t\t\n\t\tlong[] dividers = new long[10000];\n\t\td_count = 0;\n\t\t\n\t\td_index = new int[1000001];\n\t\t\n\t\tlong[] use_primes = new long[10000];\n\t\tint use_p_count = 0;\n\t\t\n\t\tboolean[] p_used = new boolean[1000000];\n\t\tArrays.fill(p_used, false);\n\t\t\n\t\tint i;\n\t\tlong I;\n\t\tfor (I=1; I*I<=A; I++)\n\t\t{\n\t\t\tif (A % I == 0)\n\t\t\t{\n\t\t\t\td_index[(int)I] = d_count;\n\t\t\t\tdividers[d_count++] = I;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (i=0; i d)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (d % primes[p] == 0)\n\t\t\t\t{\n\t\t\t\t\tis_prime = false;\n\t\t\t\t\twhile (d % primes[p] == 0)\n\t\t\t\t\t{ \n\t\t\t\t\t\td /= primes[p];\n\t\t\t\t\t}\n\t\t\t\t\tif (d==1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!p_used[(int)primes[p]])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp_used[(int)primes[p]] = true;\n\t\t\t\t\t\t\tuse_primes[use_p_count++] = primes[p];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (is_prime)\n\t\t\t{\n\t\t\t\tif ((d > 1000000) || !p_used[(int)d])\n\t\t\t\t{\n\t\t\t\t\tif (d<1000000)\n\t\t\t\t\t{\n\t\t\t\t\t\tp_used[(int)d] = true;\n\t\t\t\t\t}\n\t\t\t\t\tuse_primes[use_p_count++] = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlogWrite(\"use_p_count = %d\\n\", use_p_count);\n\t\t\n\t\tlong[] D = new long[d_count];\n\t\tlong[] D1 = new long[d_count];\n\t\t\n\t\tArrays.fill(D, 0);\n\t\tD[0] = 1;\n\t\t\n\t\tfor (p=0; p\npublic class Main implements Runnable{\n\n // https://netbeans.org/kb/73/java/editor-codereference_ru.html#display\n\n static boolean oj;\n \n @Override\n public void run(){\n try {\n Locale.setDefault(Locale.US);\n } catch (Exception e) {\n }\n oj = true;\n try {\n oj = System.getProperty(\"MYLOCAL\") == null;\n } catch (Exception e) {\n }\n//\n if (oj) {\n sc = new FastScanner(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n } else {\n try {\n sc = new FastScanner(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n } catch (IOException e) {\n MLE();\n }\n }\n Solver s = new Solver();\n s.sc = sc;\n s.out = out;\n\n s.solve();\n if (!oj) {\n err.println(\"Time: \" + (System.currentTimeMillis() - timeBegin) / 1e3);\n err.printf(\"Mem: %d\\n\", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);\n }\n out.flush();\n }\n\n private void show(int[] arr) {\n for (int v : arr) {\n err.print(\" \" + v);\n }\n err.println();\n }\n\n public static void exit() {\n err.println(\"Time: \" + (System.currentTimeMillis() - timeBegin) / 1e3);\n err.printf(\"Mem: %d\\n\", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);\n out.flush();\n out.close();\n System.exit(0);\n }\n\n public static void MLE() {\n int[][] arr = new int[1024 * 1024][];\n for (int i = 0; i < arr.length; i++) {\n arr[i] = new int[1024 * 1024];\n }\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n //new Main().run();\n new Thread(null, new Main(), \"myThread\", 100 * 1024 * 1024).start();\n }\n\n static long timeBegin = System.currentTimeMillis();\n static FastScanner sc;\n static PrintWriter out;\n static PrintStream err = System.err;\n}\n //\n\n//\nclass FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStreamReader reader) {\n br = new BufferedReader(reader);\n st = new StringTokenizer(\"\");\n }\n\n String next() {\n while (!st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception ex) {\n return null;\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n try {\n return br.readLine();\n } catch (IOException ex) {\n return null;\n }\n }\n}\n//\n\nclass Solver {\n\n void aser(boolean OK) {\n if (!OK) {\n Main.MLE();\n }\n }\n\n FastScanner sc;\n PrintWriter out;\n static PrintStream err = System.err;\n \n long[] getAllDiv(long A){\n TreeSet arr = new TreeSet<>();\n for( long d = 1; d*d <= A; ++d ){\n if( A % d == 0 ) {\n arr.add(d);\n arr.add(A/d);\n }\n }\n int pos = 0;\n long[] a = new long[arr.size()];\n for (long x : arr) a[pos++] = x;\n return a;\n }\n \n long myPow(long p, int alfa){\n long ans = 1;\n for (int i = 0; i < alfa; i++) {\n ans *= p;\n }\n return ans;\n }\n \n void solve(){\n final long A = sc.nextLong();\n long[] divA = getAllDiv(A);\n TreeMap> P = new TreeMap<>();\n for (long div : divA) {\n --div;\n for (int alfa = 1; alfa <= 60; alfa++) {\n long p = (long)( pow( div, 1.0 / alfa ) + 0.5 );\n if( 2<=p && myPow(p,alfa)==div && \n valueOf(p).isProbablePrime(Integer.MAX_VALUE) ){\n if( !P.containsKey(p) )\n P.put(p, new TreeSet<>());\n P.get(p).add(alfa);\n break;\n }\n }\n }\n \n long[] dp0, dp;\n dp0 = new long[divA.length];\n dp0[0] = 1;\n for( long p : P.keySet() ){\n dp = dp0.clone();\n for( int alfa : P.get(p) ){\n long val = myPow(p, alfa) + 1;\n for( int ID = 0; ID < divA.length; ++ID){\n long div = divA[ID];\n if( 1e12 + 5 <= 1.0 * div * val ) break;\n long toDiv = div * val;\n int toID = binarySearch(divA, toDiv);\n if( 0 <= toID ) dp[toID] += dp0[ID];\n }\n }\n //\n dp0 = dp;\n }\n out.println(dp0[divA.length - 1]);\n }\n \n \n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f7cd69d21d3881ab1f2928ed7b0c6a77", "src_uid": "1f68bd6f8b40e45a5bd360b03a264ef4", "difficulty": 2600.0} {"lang": "Java 8", "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 long A = Long.parseLong(bf.readLine());\n Map> m = new HashMap>();\n Map div = new HashMap();\n ArrayList divisors = new ArrayList();\n long sqrt = (long)Math.sqrt(A);\n \n for(int i=1; i 0.00001) continue hi;\n int count = (int)Math.round(t);\n HashSet set = m.get(j);\n if(set == null) {\n set = new HashSet();\n m.put(j, set);\n }\n set.add(count);\n div.put(i, j);\n done = true;\n break;\n }\n }\n if(!done && i != 1 && i != 2 ) {\n HashSet set = m.get(i - 1);\n if(set == null) {\n set = new HashSet();\n m.put(i - 1, set);\n }\n set.add(1);\n div.put(i, i-1);\n }\n }\n\n //\n ArrayList P = new ArrayList();\n for(long l : m.keySet()) P.add(l);\n Collections.sort(P);\n int[] dp = new int[divisors.size()];\n //System.out.println(P.size() + \" \" + divisors.size());\n Map divis = new HashMap();\n for(int i=0; i> temp = new ArrayList<>();\n for(int i = 1; i <= P.size(); i++) {\n ArrayList list = new ArrayList();\n temp.add(list);\n pp = P.get(i - 1);\n for(int k : m.get(pp)) {\n val = (long)(Math.pow(pp, k) + 1);\n list.add(val);\n \n }\n }\n for(int i=1; i<=P.size(); ++i) {\n for(int j=divisors.size()-1; j>=0; --j) {\n divv = divisors.get(j);\n pp = P.get(i - 1);\n int iter = 0;\n ArrayList tempp = temp.get(i - 1);\n for(int k : m.get(pp)) {\n val = tempp.get(iter++);\n if(divv % val == 0)\n dp[j] += dp[divis.get(divv/val)];\n }\n }\n }\n System.out.println(System.currentTimeMillis() - start);\n System.out.println(dp[divisors.size() - 1]);\n // System.out.println(P);\n // StringTokenizer st = new StringTokenizer(bf.readLine());\n // int[] a = new int[n]; for(int i=0; in-k;j--){\n \t\t\tans = ans*j%num;\n \t\t}\n \t\tfor(int j = 1;j<=k;j++){\n \t\t\tans = ans*power(j, num-2, num)%num;\n \t\t}\n \t\t\n \t\twhile (ans < 0){\n \t\t\tans = ans+num;\n \t\t}\n \t\t\n \t\tout.println(ans);\n \t\tout.close();\n \t\t\n \t}\n \t\n\t\n\tpublic static int 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 (int)(ans);\n\t}\n }\n\t\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8314b5341838fb2ce7556a3cb3ae8326", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1342e {\n\n public static void main(String[] args) throws IOException {\n int n = rni(), k, fact[] = new int[n + 1], ifact[] = new int[n + 2], ans = 0;\n long kl = nl();\n if(kl >= n) {\n prln(0);\n close();\n return;\n }\n k = (int)kl;\n fact[0] = fact[1] = ifact[0] = ifact[1] = 1;\n for(int i = 2; i <= n; ++i) {\n fact[i] = fmul(fact[i - 1], i);\n ifact[i] = fpow(fact[i], fmod - 2);\n }\n for(int i = 0; i <= n - k; ++i) {\n ans = (ans + ((i % 2 == 0 ? 1 : -1) * fmul(fpow(n - k - i, n), fmul(fact[n - k], fmul(ifact[i], ifact[n - k - i]))) + fmod) % fmod) % fmod;\n }\n ans = fmul(fmul(ans, fact[n]), fmul(ifact[k], ifact[n - k]));\n prln(k == 0 ? ans : fmul(ans, 2));\n close();\n }\n\n static int fmod = 998244353;\n\n static int fpow(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 = fmul(ans, a);\n }\n a = fmul(a, a);\n b >>= 1;\n }\n return ans;\n }\n\n static int fmul(int a, int b) {\n int ans = 0;\n while(b > 0) {\n if((b & 1) > 0) {\n ans = (ans + a) % fmod;\n }\n a = (a << 1) % fmod;\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 ~= 2e10\n // LMAX ~= 9e18\n \n // constants\n static final int IBIG = 1000000007;\n static final int IMAX = 2147483647;\n static final int IMIN = -2147483648;\n static final long LMAX = 9223372036854775807L;\n static final long LMIN = -9223372036854775808L;\n // math util\n static int minof(int a, int b, int c) {return min(a, min(b, c));}\n static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static long minof(long a, long b, long c) {return min(a, min(b, c));}\n static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static int maxof(int a, int b, int c) {return max(a, max(b, c));}\n static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static long maxof(long a, long b, long c) {return max(a, max(b, c));}\n static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static int fli(double d) {return (int)d;}\n static int cei(double d) {return (int)ceil(d);}\n static long fll(double d) {return (long)d;}\n static long cel(double d) {return (long)ceil(d);}\n static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}\n // array util\n static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void rsort(int[] a) {shuffle(a); sort(a);}\n static void rsort(long[] a) {shuffle(a); sort(a);}\n static int[] copy(int[] a) {int[] ans = new int[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static long[] copy(long[] a) {long[] ans = new long[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static char[] copy(char[] a) {char[] ans = new char[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static int[] sorted(int[] a) {int[] ans = copy(a); sort(ans); return ans;}\n static long[] sorted(long[] a) {long[] ans = copy(a); sort(ans); return ans;}\n static int[] rsorted(int[] a) {int[] ans = copy(a); rsort(ans); return ans;}\n static long[] rsorted(long[] a) {long[] ans = copy(a); rsort(ans); return ans;}\n // graph util\n static List> graph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n static List> graph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> graph(int n, int m) throws IOException {return graph(graph(n), m);}\n static List> dgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dgraph(List> g, int n, int m) throws IOException {return dgraph(graph(n), m);}\n static List> sgraph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n static List> sgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> sgraph(int n, int m) throws IOException {return sgraph(sgraph(n), m);}\n static List> dsgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dsgraph(List> g, int n, int m) throws IOException {return dsgraph(sgraph(n), m);}\n static void connect(List> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n static void connecto(List> g, int u, int v) {g.get(u).add(v);}\n static void dconnect(List> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n static void dconnecto(List> g, int u, int v) {g.get(u).remove(v);}\n // input\n static void r() throws IOException {input = new StringTokenizer(__in.readLine());}\n static int ri() throws IOException {return Integer.parseInt(__in.readLine());}\n static long rl() throws IOException {return Long.parseLong(__in.readLine());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}\n static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}\n static char[] rcha() throws IOException {return __in.readLine().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}\n static int ni() {return Integer.parseInt(input.nextToken());}\n static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}\n static long nl() {return Long.parseLong(input.nextToken());}\n // output\n static void pr(int i) {__out.print(i);}\n static void prln(int i) {__out.println(i);}\n static void pr(long l) {__out.print(l);}\n static void prln(long l) {__out.println(l);}\n static void pr(double d) {__out.print(d);}\n static void prln(double d) {__out.println(d);}\n static void pr(char c) {__out.print(c);}\n static void prln(char c) {__out.println(c);}\n static void pr(char[] s) {__out.print(new String(s));}\n static void prln(char[] s) {__out.println(new String(s));}\n static void pr(String s) {__out.print(s);}\n static void prln(String s) {__out.println(s);}\n static void pr(Object o) {__out.print(o);}\n static void prln(Object o) {__out.println(o);}\n static void prln() {__out.println();}\n static void pryes() {__out.println(\"yes\");}\n static void pry() {__out.println(\"Yes\");}\n static void prY() {__out.println(\"YES\");}\n static void prno() {__out.println(\"no\");}\n static void prn() {__out.println(\"No\");}\n static void prN() {__out.println(\"NO\");}\n static void pryesno(boolean b) {__out.println(b ? \"yes\" : \"no\");};\n static void pryn(boolean b) {__out.println(b ? \"Yes\" : \"No\");}\n static void prYN(boolean b) {__out.println(b ? \"YES\" : \"NO\");}\n static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(Collection c) {int n = c.size() - 1; Iterator iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}\n static void h() {__out.println(\"hlfd\");}\n static void flush() {__out.flush();}\n static void close() {__out.close();}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de8ca1fea6b73f7e81bb7e26c946b594", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1342e {\n\n static int[] fact;\n\n public static void main(String[] args) throws IOException {\n int n = rni(), k, ans = 0, mult = 1;\n fact = new int[n + 1];\n ifact = new int[n + 1];\n long kl = nl();\n if(kl >= n) {\n prln(0);\n close();\n return;\n }\n k = (int)kl;\n fact[0] = fact[1] = 1;\n for(int i = 2; i <= n; ++i) {\n fact[i] = fmul(fact[i - 1], i);\n }\n for(int i = 0; i <= n - k; ++i, mult = -mult) {\n int add = mult * fmul(fpow(n - k - i, n), fmul(fact[n - k], fmul(ifact(i), ifact(n - k - i))));\n while(add < 0) {\n add += fmod;\n }\n ans += add;\n if(ans >= fmod) {\n ans -= fmod;\n }\n }\n ans = fmul(fmul(ans, fact[n]), fmul(ifact(k), ifact(n - k)));\n prln(k == 0 ? ans : fmul(ans, 2));\n close();\n }\n\n static int[] ifact;\n\n static int ifact(int x) {\n if(ifact[x] > 0) {\n return ifact[x];\n } else {\n return ifact[x] = fpow(fact[x], fmod - 2);\n }\n }\n\n static int fmod = 998244353;\n\n static int fpow(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 = fmul(ans, a);\n }\n a = fmul(a, a);\n b >>= 1;\n }\n return ans;\n }\n\n static int fmul(int a, int b) {\n int ans = 0;\n while(b > 0) {\n if((b & 1) > 0) {\n ans += a;\n if(ans >= fmod) {\n ans -= fmod;\n }\n }\n a <<= 1;\n if(a >= fmod) {\n a -= fmod;\n }\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 ~= 2e10\n // LMAX ~= 9e18\n \n // constants\n static final int IBIG = 1000000007;\n static final int IMAX = 2147483647;\n static final int IMIN = -2147483648;\n static final long LMAX = 9223372036854775807L;\n static final long LMIN = -9223372036854775808L;\n // math util\n static int minof(int a, int b, int c) {return min(a, min(b, c));}\n static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static long minof(long a, long b, long c) {return min(a, min(b, c));}\n static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static int maxof(int a, int b, int c) {return max(a, max(b, c));}\n static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static long maxof(long a, long b, long c) {return max(a, max(b, c));}\n static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static int fli(double d) {return (int)d;}\n static int cei(double d) {return (int)ceil(d);}\n static long fll(double d) {return (long)d;}\n static long cel(double d) {return (long)ceil(d);}\n static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}\n // array util\n static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void rsort(int[] a) {shuffle(a); sort(a);}\n static void rsort(long[] a) {shuffle(a); sort(a);}\n static int[] copy(int[] a) {int[] ans = new int[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static long[] copy(long[] a) {long[] ans = new long[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static char[] copy(char[] a) {char[] ans = new char[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static int[] sorted(int[] a) {int[] ans = copy(a); sort(ans); return ans;}\n static long[] sorted(long[] a) {long[] ans = copy(a); sort(ans); return ans;}\n static int[] rsorted(int[] a) {int[] ans = copy(a); rsort(ans); return ans;}\n static long[] rsorted(long[] a) {long[] ans = copy(a); rsort(ans); return ans;}\n // graph util\n static List> graph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n static List> graph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> graph(int n, int m) throws IOException {return graph(graph(n), m);}\n static List> dgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dgraph(List> g, int n, int m) throws IOException {return dgraph(graph(n), m);}\n static List> sgraph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n static List> sgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> sgraph(int n, int m) throws IOException {return sgraph(sgraph(n), m);}\n static List> dsgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dsgraph(List> g, int n, int m) throws IOException {return dsgraph(sgraph(n), m);}\n static void connect(List> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n static void connecto(List> g, int u, int v) {g.get(u).add(v);}\n static void dconnect(List> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n static void dconnecto(List> g, int u, int v) {g.get(u).remove(v);}\n // input\n static void r() throws IOException {input = new StringTokenizer(__in.readLine());}\n static int ri() throws IOException {return Integer.parseInt(__in.readLine());}\n static long rl() throws IOException {return Long.parseLong(__in.readLine());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}\n static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}\n static char[] rcha() throws IOException {return __in.readLine().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}\n static int ni() {return Integer.parseInt(input.nextToken());}\n static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}\n static long nl() {return Long.parseLong(input.nextToken());}\n // output\n static void pr(int i) {__out.print(i);}\n static void prln(int i) {__out.println(i);}\n static void pr(long l) {__out.print(l);}\n static void prln(long l) {__out.println(l);}\n static void pr(double d) {__out.print(d);}\n static void prln(double d) {__out.println(d);}\n static void pr(char c) {__out.print(c);}\n static void prln(char c) {__out.println(c);}\n static void pr(char[] s) {__out.print(new String(s));}\n static void prln(char[] s) {__out.println(new String(s));}\n static void pr(String s) {__out.print(s);}\n static void prln(String s) {__out.println(s);}\n static void pr(Object o) {__out.print(o);}\n static void prln(Object o) {__out.println(o);}\n static void prln() {__out.println();}\n static void pryes() {__out.println(\"yes\");}\n static void pry() {__out.println(\"Yes\");}\n static void prY() {__out.println(\"YES\");}\n static void prno() {__out.println(\"no\");}\n static void prn() {__out.println(\"No\");}\n static void prN() {__out.println(\"NO\");}\n static void pryesno(boolean b) {__out.println(b ? \"yes\" : \"no\");};\n static void pryn(boolean b) {__out.println(b ? \"Yes\" : \"No\");}\n static void prYN(boolean b) {__out.println(b ? \"YES\" : \"NO\");}\n static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(Collection c) {int n = c.size() - 1; Iterator iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}\n static void h() {__out.println(\"hlfd\");}\n static void flush() {__out.flush();}\n static void close() {__out.close();}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e25f8a96c0dc5aa353d6b68e8acdb9c", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1342e {\n\n public static void main(String[] args) throws IOException {\n int n = rni(), k, fact[] = new int[n + 1], ifact[] = new int[n + 2], ans = 0, mult = 1;\n long kl = nl();\n if(kl >= n) {\n prln(0);\n close();\n return;\n }\n k = (int)kl;\n fact[0] = fact[1] = ifact[0] = ifact[1] = 1;\n for(int i = 2; i <= n; ++i) {\n fact[i] = fmul(fact[i - 1], i);\n ifact[i] = fpow(fact[i], fmod - 2);\n }\n for(int i = 0; i <= n - k; ++i, mult = -mult) {\n int add = mult * fmul(fpow(n - k - i, n), fmul(fact[n - k], fmul(ifact[i], ifact[n - k - i])));\n while(add < 0) {\n add += fmod;\n }\n ans += add;\n if(ans >= fmod) {\n ans -= fmod;\n }\n }\n ans = fmul(fmul(ans, fact[n]), fmul(ifact[k], ifact[n - k]));\n prln(k == 0 ? ans : fmul(ans, 2));\n close();\n }\n\n static int fmod = 998244353;\n\n static int fpow(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 = fmul(ans, a);\n }\n a = fmul(a, a);\n b >>= 1;\n }\n return ans;\n }\n\n static int fmul(int a, int b) {\n int ans = 0;\n while(b > 0) {\n if((b & 1) > 0) {\n ans += a;\n if(ans >= fmod) {\n ans -= fmod;\n }\n }\n a <<= 1;\n if(a >= fmod) {\n a -= fmod;\n }\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 ~= 2e10\n // LMAX ~= 9e18\n \n // constants\n static final int IBIG = 1000000007;\n static final int IMAX = 2147483647;\n static final int IMIN = -2147483648;\n static final long LMAX = 9223372036854775807L;\n static final long LMIN = -9223372036854775808L;\n // math util\n static int minof(int a, int b, int c) {return min(a, min(b, c));}\n static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static long minof(long a, long b, long c) {return min(a, min(b, c));}\n static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static int maxof(int a, int b, int c) {return max(a, max(b, c));}\n static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static long maxof(long a, long b, long c) {return max(a, max(b, c));}\n static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static int fli(double d) {return (int)d;}\n static int cei(double d) {return (int)ceil(d);}\n static long fll(double d) {return (long)d;}\n static long cel(double d) {return (long)ceil(d);}\n static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}\n // array util\n static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void rsort(int[] a) {shuffle(a); sort(a);}\n static void rsort(long[] a) {shuffle(a); sort(a);}\n static int[] copy(int[] a) {int[] ans = new int[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static long[] copy(long[] a) {long[] ans = new long[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static char[] copy(char[] a) {char[] ans = new char[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static int[] sorted(int[] a) {int[] ans = copy(a); sort(ans); return ans;}\n static long[] sorted(long[] a) {long[] ans = copy(a); sort(ans); return ans;}\n static int[] rsorted(int[] a) {int[] ans = copy(a); rsort(ans); return ans;}\n static long[] rsorted(long[] a) {long[] ans = copy(a); rsort(ans); return ans;}\n // graph util\n static List> graph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n static List> graph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> graph(int n, int m) throws IOException {return graph(graph(n), m);}\n static List> dgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dgraph(List> g, int n, int m) throws IOException {return dgraph(graph(n), m);}\n static List> sgraph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n static List> sgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> sgraph(int n, int m) throws IOException {return sgraph(sgraph(n), m);}\n static List> dsgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dsgraph(List> g, int n, int m) throws IOException {return dsgraph(sgraph(n), m);}\n static void connect(List> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n static void connecto(List> g, int u, int v) {g.get(u).add(v);}\n static void dconnect(List> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n static void dconnecto(List> g, int u, int v) {g.get(u).remove(v);}\n // input\n static void r() throws IOException {input = new StringTokenizer(__in.readLine());}\n static int ri() throws IOException {return Integer.parseInt(__in.readLine());}\n static long rl() throws IOException {return Long.parseLong(__in.readLine());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}\n static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}\n static char[] rcha() throws IOException {return __in.readLine().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}\n static int ni() {return Integer.parseInt(input.nextToken());}\n static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}\n static long nl() {return Long.parseLong(input.nextToken());}\n // output\n static void pr(int i) {__out.print(i);}\n static void prln(int i) {__out.println(i);}\n static void pr(long l) {__out.print(l);}\n static void prln(long l) {__out.println(l);}\n static void pr(double d) {__out.print(d);}\n static void prln(double d) {__out.println(d);}\n static void pr(char c) {__out.print(c);}\n static void prln(char c) {__out.println(c);}\n static void pr(char[] s) {__out.print(new String(s));}\n static void prln(char[] s) {__out.println(new String(s));}\n static void pr(String s) {__out.print(s);}\n static void prln(String s) {__out.println(s);}\n static void pr(Object o) {__out.print(o);}\n static void prln(Object o) {__out.println(o);}\n static void prln() {__out.println();}\n static void pryes() {__out.println(\"yes\");}\n static void pry() {__out.println(\"Yes\");}\n static void prY() {__out.println(\"YES\");}\n static void prno() {__out.println(\"no\");}\n static void prn() {__out.println(\"No\");}\n static void prN() {__out.println(\"NO\");}\n static void pryesno(boolean b) {__out.println(b ? \"yes\" : \"no\");};\n static void pryn(boolean b) {__out.println(b ? \"Yes\" : \"No\");}\n static void prYN(boolean b) {__out.println(b ? \"YES\" : \"NO\");}\n static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(Collection c) {int n = c.size() - 1; Iterator iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}\n static void h() {__out.println(\"hlfd\");}\n static void flush() {__out.flush();}\n static void close() {__out.close();}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3120fc2f36b923651cd97263823c662e", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n \nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n \n \npublic class Codeforces429D\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\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-1)/a1;\n\t\tlong max2=(f+a2-1)/a2;\n\t\tlong cost=Long.MAX_VALUE;\n\t\t\n\t\t\n\t\tif (t1>1);\n\t\t\t\t\t\tif (a2*mid>=sz)\n\t\t\t\t\t\t\tt=a1*k1*t1+sz*t2;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tt=a1*k1*t1+a2*mid*t2+(sz-a2*mid)*t0;\n\t\t\t\t\t\t//tr(mid+\" \"+t);\n\t\t\t\t\t\tif (t<=T)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (result!=-1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost=Math.min(cost, k1*p1+result*p2);\n\t\t\t\t\t\t//tr(k1+\" \"+k1*p1+result*p2);\n\t\t\t\t\t}\n\t\t\t\t\t//else\n\t\t\t\t\t\t//tr(k1+\"-1\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//tr(\"2\");\n\t\t\tfor (int k2=0;k2<=max2;k2++)\n\t\t\t{\n\t\t\t\t//tr(k2);\n\t\t\t\tlong sz=f-k2*a2;\n\t\t\t\tif (sz<=0)\n\t\t\t\t{\n\t\t\t\t\t//tr(k1+\" \"+k1*p1);\n\t\t\t\t\tif (f*t2<=T)\n\t\t\t\t\t\tcost=Math.min(cost, k2*p2);\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\tlong l=0,r=(sz+a1-a)/a1,result=-1,t;\n\t\t\t\t\twhile (l<=r)\n\t\t\t\t\t{\n\t\t\t\t\t\tlong mid=((l+r)>>1);\n\t\t\t\t\t\tif (a1*mid>=sz)\n\t\t\t\t\t\t\tt=a2*k2*t2+sz*t1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tt=a2*k2*t2+a1*mid*t1+(sz-a1*mid)*t0;\n\t\t\t\t\t\t//tr(mid+\" \"+t);\n\t\t\t\t\t\tif (t<=T)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (result!=-1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost=Math.min(cost, k2*p2+result*p1);\n\t\t\t\t\t\t//tr(k2+\" \"+k2*p2+result*p1);\n\t\t\t\t\t}\n\t\t\t\t\t//else\n\t\t\t\t\t\t//tr(k2+\"-1\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tif (cost==Long.MAX_VALUE)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(cost);\n\t}\n\t\t\n\tvoid run() throws Exception \n\t{\n\t\tString INPUT = \"C:/Users/ayubs/Desktop/input.txt\";\n\t\tin = oj ? System.in : new FileInputStream(INPUT);\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tnew Codeforces429D().run();\n\t}\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte() \n\t{\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) \n\t\t{\n\t\t\tptrbuf = 0;\n\t\t\ttry \n\t\t\t{\n\t\t\t\tlenbuf = in.read(inbuf);\n\t\t\t}\n\t\t\tcatch (IOException e) \n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean inSpaceChar(int c) \n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() \n\t{\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && inSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\t\n\tprivate double nd() \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() \n\t{\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() \n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) \n\t\t{ // when nextLine, (inSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n) \n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(b))) \n\t\t{\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m) \n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n) \n\t{\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni() \n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl() \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tprivate void tr(Object... o) \n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e617241985c8b4b5c8a24090900e8674", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n \nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n \n \npublic class Codeforces429D\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\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-1)/a1;\n\t\tlong max2=(f+a2-1)/a2;\n\t\tlong cost=Long.MAX_VALUE;\n\t\t//tr(max1,max2);\n\t\t//long ans1=-1,ans2=-1,tmp=71773335;\n\t\t//ans1=961250;ans2=897197;\n\t\tif (t1>1);\n\t\t\t\t\t\tif (a2*mid>=sz)\n\t\t\t\t\t\t\tt=a1*k1*t1+sz*t2;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tt=a1*k1*t1+a2*mid*t2+(sz-a2*mid)*t0;\n\t\t\t\t\t\t//if (k1==ans1&&mid==ans2)\n\t\t\t\t\t\t\t//tr(mid+\" \"+t);\n\t\t\t\t\t\tif (t<=T)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (result!=-1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost=Math.min(cost, k1*p1+result*p2);\n\t\t\t\t\t\t//if (cost>1);\n\t\t\t\t\t\tif (a1*mid>=sz)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tt=a2*k2*t2+sz*t1;\n\t\t\t\t\t\t\t//if(mid==ans1)\n\t\t\t\t\t\t\t\t//tr(\"hi\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tt=a2*k2*t2+a1*mid*t1+(sz-a1*mid)*t0;\n\t\t\t\t\t\t//if (k2==ans2)\n\t\t\t\t\t\t\t//tr(mid+\" \"+t);\n\t\t\t\t\t\tif (t<=T)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (result!=-1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost=Math.min(cost, k2*p2+result*p1);\n\t\t\t\t\t\t//if (cost= lenbuf) \n\t\t{\n\t\t\tptrbuf = 0;\n\t\t\ttry \n\t\t\t{\n\t\t\t\tlenbuf = in.read(inbuf);\n\t\t\t}\n\t\t\tcatch (IOException e) \n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean inSpaceChar(int c) \n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() \n\t{\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && inSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\t\n\tprivate double nd() \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() \n\t{\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() \n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) \n\t\t{ // when nextLine, (inSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n) \n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(b))) \n\t\t{\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m) \n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n) \n\t{\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni() \n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl() \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tprivate void tr(Object... o) \n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63933fc0bddd334b178750964bc10750", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n \nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n \n \npublic class Codeforces429D\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\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-1)/a1;\n\t\tlong max2=(f+a2-1)/a2;\n\t\tlong cost=Long.MAX_VALUE;\n\t\t\n\t\tfor (int k1=0;k1<=max1;k1++)\n\t\t{\n\t\t\tlong sz=f-k1*a1;\n\t\t\tif (sz<=0)\n\t\t\t{\n\t\t\t\t//tr(k1+\" \"+k1*p1);\n\t\t\t\tif (f*t1<=T)\n\t\t\t\t\tcost=Math.min(cost, k1*p1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong l=0,r=max2,result=-1,t;\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\tif (a2*mid>=sz)\n\t\t\t\t\t\tt=a1*k1*t1+sz*t2;\n\t\t\t\t\telse\n\t\t\t\t\t\tt=a1*k1*t1+a2*mid*t2+(sz-a2*mid)*t0;\n\t\t\t\t\t\n\t\t\t\t\tif (t<=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\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\t//tr(k1+\" \"+k1*p1+result*p2);\n\t\t\t\t}\n\t\t\t\t//else\n\t\t\t\t\t//tr(k1+\"-1\");\n\t\t\t}\n\t\t}\n\t\tif (cost==Long.MAX_VALUE)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(cost);\n\t}\n\t\t\n\tvoid run() throws Exception \n\t{\n\t\tString INPUT = \"C:/Users/ayubs/Desktop/input.txt\";\n\t\tin = oj ? System.in : new FileInputStream(INPUT);\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tnew Codeforces429D().run();\n\t}\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte() \n\t{\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) \n\t\t{\n\t\t\tptrbuf = 0;\n\t\t\ttry \n\t\t\t{\n\t\t\t\tlenbuf = in.read(inbuf);\n\t\t\t}\n\t\t\tcatch (IOException e) \n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean inSpaceChar(int c) \n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() \n\t{\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && inSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\t\n\tprivate double nd() \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() \n\t{\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() \n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) \n\t\t{ // when nextLine, (inSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n) \n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(b))) \n\t\t{\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m) \n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n) \n\t{\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni() \n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl() \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tprivate void tr(Object... o) \n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cbddc8b6abc83923d52d7f25389cf9e5", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n \nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n \n \npublic class Codeforces429D\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\tlong MAX=2*(long)1e14+7;\n\tvoid solve() \n\t{\n\t\tlong f=nl();\n\t\tlong T=nl();\n\t\tlong t0=nl();\n\t\tlong a1,t1,p1,a2,t2,p2;\n\t\ta1=nl();t1=nl();p1=nl();\n\t\ta2=nl();t2=nl();p2=nl();\n\t\t\n\t\tlong max1=f/a1;\n\t\tlong max2=f/a2;\n\t\tlong cost=MAX;\n\t\t\n\t\tif (t1>1);\n\t\t\t\t\t\n\t\t\t\t\tt=a1*k1*t1+a2*mid*t2+(sz-a2*mid)*t0;\n\t\t\t\t\t//tr(mid+\" \"+t);\n\t\t\t\t\tif (t<=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\tt=a1*k1*t1+sz*t2;\n\t\t\t\tif (t<=T)\n\t\t\t\t\tcost=Math.min(cost, k1*p1+max2*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\t//tr(k1+\" \"+k1*p1+result*p2);\n\t\t\t\t}\n\t\t\t\t//else\n\t\t\t\t\t//tr(k1+\"-1\");\n\t\t\t}\n\t\t\tmax1=(f+a1-1)/a1;\n\t\t\tlong t=f*t1;\n\t\t\tif (t<=T)\n\t\t\t\tcost=Math.min(cost, max1*p1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//tr(\"2\");\n\t\t\tfor (int k2=0;k2<=max2;k2++)\n\t\t\t{\n\t\t\t\t//tr(k2);\n\t\t\t\tlong sz=f-k2*a2;\n\t\t\t\t\n\t\t\t\tmax1=(sz+a1-1)/a1;\n\t\t\t\t\n\t\t\t\tlong l=0,r=sz/a1,result=-1,t;\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\t\n\t\t\t\t\tt=a2*k2*t2+a1*mid*t1+(sz-a1*mid)*t0;\n\t\t\t\t\t//tr(mid+\" \"+t);\n\t\t\t\t\tif (t<=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\tt=a2*k2*t2+sz*t1;\n\t\t\t\tif (t<=T)\n\t\t\t\t\tcost=Math.min(cost, k2*p2+max1*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\t//tr(k2+\" \"+k2*p2+result*p1);\n\t\t\t\t}\n\t\t\t\t//else\n\t\t\t\t\t//tr(k2+\"-1\");\n\t\t\t}\n\t\t\tmax2=(f+a2-1)/a2;\n\t\t\tlong t=f*t2;\n\t\t\tif (t<=T)\n\t\t\t\tcost=Math.min(cost, max2*p2);\n\t\t}\n\t\t\n\t\tif (cost==MAX)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(cost);\n\t}\n\t\t\n\tvoid run() throws Exception \n\t{\n\t\tString INPUT = \"C:/Users/ayubs/Desktop/input.txt\";\n\t\tin = oj ? System.in : new FileInputStream(INPUT);\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tnew Codeforces429D().run();\n\t}\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte() \n\t{\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) \n\t\t{\n\t\t\tptrbuf = 0;\n\t\t\ttry \n\t\t\t{\n\t\t\t\tlenbuf = in.read(inbuf);\n\t\t\t}\n\t\t\tcatch (IOException e) \n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean inSpaceChar(int c) \n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() \n\t{\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && inSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\t\n\tprivate double nd() \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() \n\t{\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() \n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) \n\t\t{ // when nextLine, (inSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n) \n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(b))) \n\t\t{\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m) \n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n) \n\t{\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni() \n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl() \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tprivate void tr(Object... o) \n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0a6c57fdd879712f123f32eb001f9869", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\n\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.Iterator;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n\n\npublic final class CF_325_AliceBob {\n\n\tvoid log(int[] X){\n\t\tint L=X.length;\n\t\tfor (int i=0;i{\n\t\tint x;\n\t\tint y;\n\n\t\tpublic int compareTo(Composite X){\n\t\t\tif (x!=X.x)\n\t\t\t\treturn x-X.x;\n\t\t\treturn y-X.y;\n\t\t}\n\n\t\tpublic Composite(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\n\t}\n\n\tlong pgcd(long a,long b){\n\t\tif (b>a)\n\t\t\treturn pgcd(b,a);\n\t\twhile (b>0){\n\t\t\tlong c=b;\n\t\t\tb=a%b;\n\t\t\ta=c;\n\t\t}\n\t\treturn a;\n\t}\n\n\n\tString solve(long x,long y){\n\t\tlong p=pgcd(x,y);\n\t\tif (p!=1)\n\t\t\treturn \"Impossible\";\n\t\t\n\t\tString res=\"\";\n\t\tint cnt=0;\n\t\tchar cur='Z';\n\t\twhile (x>0 && y>0 && x!=y){\n\n\t\t\tif (y>x){\n\n\t\t\t\ty-=x;\n\t\t\t\tif (cur!='B'){\n\t\t\t\t\tif (cur=='A')\n\t\t\t\t\t\tres+=cnt+\"\"+'A';\n\t\t\t\t\tcnt=1;\n\t\t\t\t\tcur='B';\n\t\t\t\t} else {\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\tx-=y;\n\t\t\t\tif (cur!='A'){\n\t\t\t\t\tif (cur=='B')\n\t\t\t\t\t\tres+=cnt+\"\"+'B';\n\t\t\t\t\tcnt=1;\n\t\t\t\t\tcur='A';\n\t\t\t\t} else {\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\n\n\n\t\t\t}\n\n\t\t\n\t\t}\n\t\tres+=cnt+\"\"+cur;\n\t\treturn res;\n\t}\n\n\tvoid simulate(){\n\t\tTreeSet list=new TreeSet();\n\t\tint LEN=5;\n\t\tint m=1<= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\n\t\tpublic final String readString() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res=new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.append((char)c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic final int readInt() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\t\tpublic final long readLong() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\n\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\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd83e701c6daab453fe1c22f685b8899", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class E {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong x = scan.nextLong();\n\t\tlong y = scan.nextLong();\n\t\tif(gcd(x,y) != 1) {\n\t\t\tSystem.out.println(\"Impossible\");\n\t\t\treturn;\n\t\t}\n\t\tlong a = 1, b = 0;\n\t\tlong c = 0, d = 1;\n\t\tint dir = 0;\n\t\tif(x > y) {\n\t\t\tdir = 1;\n\t\t}\n\t\tStringBuilder ans = new StringBuilder();\n\t\twhile((a+c) != x || (b+d) != y) {\n\t\t\t//long lo = 1;\n\t\t\t//long hi = 1_000_000_000_000_000_001L;\n\t\t\t//while(lo < hi) {\n\t\t\t//\t\n\t\t\t//}\n\t\t\tif(dir == 0) {\n\t\t\t\tBigInteger num = BigInteger.valueOf(x).multiply(BigInteger.valueOf(b).add(BigInteger.valueOf(d))).subtract(BigInteger.valueOf(y).multiply(BigInteger.valueOf(c).add(BigInteger.valueOf(a))));\n\t\t\t\tBigInteger den = BigInteger.valueOf(c).multiply(BigInteger.valueOf(y)).subtract(BigInteger.valueOf(x).multiply(BigInteger.valueOf(d)));\n\t\t\t\tBigInteger div = num.divide(den);//num.add(den.subtract(BigInteger.ONE)).divide(den);\n\t\t\t\tlong k = div.longValue();\n\t\t\t\t//System.out.println(\"dir = 0, k = \" + k);\n\t\t\t\ta += k*c;\n\t\t\t\tb += k*d;\n\t\t\t\tans.append(k).append(\"B\");\n\t\t\t} else {\n\t\t\t\ta = a ^ c ^ (c = a);\n\t\t\t\tb = b ^ d ^ (d = b);\n\t\t\t\tBigInteger num = BigInteger.valueOf(x).multiply(BigInteger.valueOf(b).add(BigInteger.valueOf(d))).subtract(BigInteger.valueOf(y).multiply(BigInteger.valueOf(c).add(BigInteger.valueOf(a))));\n\t\t\t\tBigInteger den = BigInteger.valueOf(c).multiply(BigInteger.valueOf(y)).subtract(BigInteger.valueOf(x).multiply(BigInteger.valueOf(d)));\n\t\t\t\tBigInteger div = num.add(den.subtract(BigInteger.ONE)).divide(den);\n\t\t\t\tlong k = div.longValue();\n\t\t\t\t//System.out.println(\"dir = 1, k = \" + k);\n\t\t\t\ta += k*c;\n\t\t\t\tb += k*d;\n\t\t\t\ta = a ^ c ^ (c = a);\n\t\t\t\tb = b ^ d ^ (d = b);\n\t\t\t\tans.append(k).append(\"A\");\n\t\t\t}\n\t\t\t//System.out.println(\"at (\" + a + \"/\" + b +\"), (\" + c + \"/\" + d + \") = \" + (a+c) + \"/\" + (b+d));\n\t\t\tdir = 1-dir;\n\t\t\t//break;\n\t\t}\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\tstatic long gcd(long a, long b) {\n\t\tif(b == 0) return a;\n\t\treturn gcd(b,a%b);\n\t}\n\tpublic static int compare(long a, long b, long c, long d) {\n\t\tBigInteger left = BigInteger.valueOf(a).multiply(BigInteger.valueOf(d));\n\t\tBigInteger right = BigInteger.valueOf(c).multiply(BigInteger.valueOf(b));\n\t\treturn left.compareTo(right);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d935bf667c4057a67d8eb5f8eb16dc98", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671", "difficulty": 2400.0} {"lang": "Java 8", "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_325_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\tlong x = in.nextLong();\n\t\tlong y = in.nextLong();\n\t\tif (x == y) {\n\n\t\t\tout.println(\"Impossible\");\n\n\t\t} else {\n\t\t\tString v = cal(new Point(1, 0), new Point(0, 1), x, y);\n\t\t\tif (v == null) {\n\t\t\t\tout.println(\"Impossible\");\n\t\t\t} else {\n\t\t\t\tout.println(v);\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic String cal(Point a, Point b, long x, long y) {\n\t\t//System.out.println(a.x + \" \" + a.y + \" \" + b.x + \" \" + b.y);\n\t\tif (a.x == x && a.y == y) {\n\t\t\treturn \"\";\n\t\t} else if (b.x == x && b.y == y) {\n\t\t\treturn \"\";\n\t\t} else if (a.x + b.x > x || a.y + b.y > y) {\n\t\t\treturn null;\n\t\t}\n\t\tint c = crossProduct(a.x, a.y, x, y);\n\t\tint d = crossProduct(b.x, b.y, x, y);\n\n\t\tint f = crossProduct(a.x + b.x, a.y + b.y, x, y);\n\t\tboolean removeA = d !=f;\n\t\t//System.out.println(c + \" \" + d + \" \" + f);\n\t\tlong s = 0;\n\t\tlong e = 10000000000000L;\n\t\tlong result = -1;\n\t\twhile (s <= e) {\n\t\t\tlong mid = (s + e) / 2;\n\t\t\t\n\t\t\tif (removeA) {\n\t\t\t\tif(a.x + mid*b.x <= 0 || a.y + mid*b.y <= 0){\n\t\t\t\t\te = mid - 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint v = crossProduct(a.x + mid * b.x, a.y + mid * b.y, x, y);\n\t\t\t\n\t\t\t\tif (v == d) {\n\n\t\t\t\t\te = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (result == -1 || result < mid) {\n\t\t\t\t\t\tresult = mid;\n\t\t\t\t\t}\n\t\t\t\t\ts = mid + 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif(b.x + mid*a.x <= 0 || b.y + mid*a.y <= 0){\n\t\t\t\t\te = mid - 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint v = crossProduct(b.x + mid * a.x, b.y + mid * a.y, x, y);\n\t\t\t\t// System.out.println(v + \" \" + mid);\n\t\t\t\tif (v == c) {\n\n\t\t\t\t\te = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (result == -1 || result < mid) {\n\t\t\t\t\t\tresult = mid;\n\t\t\t\t\t}\n\t\t\t\t\ts = mid + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\tif (true) {\n\t\t\t//System.out.println(result);\n//\t\t\treturn \"\";\n//\t\t}\n\t\tString tmp = null;\n\t\tif (removeA) {\n\t\t\ttmp = cal(new Point(a.x + result * b.x, a.y + result * b.y), b, x,\n\t\t\t\t\ty);\n\t\t} else {\n\t\t\ttmp = cal(a, new Point(b.x + result * a.x, b.y + result * a.y), x,\n\t\t\t\t\ty);\n\t\t}\n\t\tif (tmp != null) {\n\t\t\treturn (result - (tmp.isEmpty() ? 1 : 0)) + (removeA ? \"B\" : \"A\")\n\t\t\t\t\t+ tmp;\n\t\t}\n\t\treturn null;\n\n\t}\n\n\tstatic int crossProduct(long x, long y, long x1, long y1) {\n\t\tBigInteger a = BigInteger.valueOf(x);\n\t\ta = a.multiply(BigInteger.valueOf(y1));\n\t\tBigInteger b = BigInteger.valueOf(y);\n\t\tb = b.multiply(BigInteger.valueOf(x1));\n\t\t\n\t\treturn a.compareTo(b);\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point {\n\n\t\tlong x, y;\n\n\t\tpublic Point(long start, long end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "32ab7fbb8e8451ba179963e45ed311b9", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.io.*;\nimport java.util.*;\npublic class C586E{\n public static long[] cAr, div;\n public static int N,M,K;\n public static int[] numCycle;\n public static Map> map;\n public static long MOD = 1000000007;\n public static void main(String[] args) throws IOException{\n InputReader in=new InputReader(new InputStreamReader(System.in));\n PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));\n long[] ar=in.nextLongAr();\n long A=ar[0]; long B=ar[1];\n if(gcd(A,B)!=1) System.out.println(\"Impossible\");\n else{\n while(A+B>1){\n if((A-1)/B > 0) System.out.print(((A-1)/B)+\"A\");\n A%=B;\n if((B-1)/A > 0) System.out.print(((B-1)/A)+\"B\");\n B%=A;\n }\n }\n }\n \n public static long gcd(long x,long y){\n BigInteger a = BigInteger.valueOf(x);\n BigInteger b = BigInteger.valueOf(y);\n BigInteger gcd = a.gcd(b);\n return gcd.longValue();\n }\n \n public static void setUpChoose(int t){\n cAr=new long[t+1];\n div=new long[t+1];\n cAr[0]=1;\n div[0]=1;\n \n for(int x=1;x<=t;x++){\n cAr[x]=(x*cAr[x-1])%(MOD);\n div[x]=pow(cAr[x],MOD-2);} \n }\n \n public static long choose(int x,int y){\n long a=cAr[x+y];\n long b=div[x];\n long c=div[y];\n a=(a*b)%MOD;\n a=(a*c)%MOD;\n return a;\n } \n \n public static long pow(long a,long b){\n if(b==1) \n return a;\n long c=b/2;\n long temp=pow(a,c)%MOD;\n temp=(temp*temp)%MOD;\n if(b%2==1) temp=temp*a;\n return temp%MOD;\n }\n}\n\nclass InputReader{\n private BufferedReader br;\n public InputReader(InputStreamReader in){\n br=new BufferedReader(in);\n }\n public int nextInt(){\n try{\n return Integer.parseInt(br.readLine());}\n catch(IOException e){throw new InputMismatchException();}\n }\n public int[] nextIntAr(){\n try{\n String[] s=br.readLine().split(\" \");\n int[] ret=new int[s.length];\n for(int x=0;x=0; xAt--) {\n\t\t\tfor (int j=0; j=0; yAt--) {\n\t\t\t\tfor (int goingH=0; goingH<2; goingH++) {\n\t\t\t\t\tfor (int timesGoingStraight=0; timesGoingStraight<=(goingH==0?xAt:yAt); timesGoingStraight++) {\n\t\t\t\t\t\tgo(xAt, yAt, timesGoingStraight, goingH);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=go(0, 0, 0, 0);\n\t\tSystem.out.println(ans);\n\t\tSystem.err.println(System.currentTimeMillis()-startTime);\n\t}\n\t\n\tstatic long go(int x, int y, int timesGoingStraight, int goingH) {\n\t\tif (x==maxX-1&&y==maxY-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp[(x&1)][y][timesGoingStraight][goingH]!=-1) return dp[(x&1)][y][timesGoingStraight][goingH];\n\t\tlong curCost=costOf[x][y];\n\t\tif (goingH==1)\n\t\t\tcurCost-=hBonuses[x][y].getBonus(timesGoingStraight);\n\t\telse\n\t\t\tcurCost-=vBonuses[x][y].getBonus(timesGoingStraight);\n//\t\tSystem.out.println(\"Cur cost \"+x+\" \"+y+\" is \"+curCost);\n\t\tlong best; \n\t\tif (goingH==1) {\n\t\t\tlong goH=y+1 pq=new PriorityQueue<>();\n\t\tpublic long bonusAdded=0;\n\t\t\n\t\tpublic void addBonus(int goingStraightFor, long bonus) {\n\t\t\tpq.add(new Bonus(goingStraightFor, bonus));\n\t\t}\n\t\t\n\t\tpublic long getBonus(int goingStraightFor) {\n\t\t\twhile (!pq.isEmpty()&&goingStraightFor>=pq.peek().goingStraightFor) {\n\t\t\t\tBonus next=pq.remove();\n\t\t\t\tbonusAdded+=next.points;\n\t\t\t}\n\t\t\treturn bonusAdded;\n\t\t}\n\t}\n\t\n\tstatic class Bonus implements Comparable {\n\t\tint goingStraightFor;\n\t\tlong points;\n\t\tpublic Bonus(int goingStraightFor, long points) {\n\t\t\tthis.goingStraightFor=goingStraightFor;\n\t\t\tthis.points=points;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Bonus o) {\n\t\t\treturn Integer.compare(goingStraightFor, o.goingStraightFor);\n\t\t}\n\t}\n\t\n\tstatic void processTransformer(int x, int y, int d, int t, long fightCost) {\n//\t\tSystem.out.println(\"Processing transformer (\"+x+\", \"+y+\") d: \"+d+\" startTime: \"+t+\" fightCost: \"+fightCost);\n\t\tint[] xs=new int[4];\n\t\tint[] ys=new int[4];\n\t\tint[] firstTime=new int[4];\n\t\txs[0]=x;\n\t\tys[0]=y;\n\t\tfirstTime[0]=t;\n\t\txs[1]=x+d;\n\t\tys[1]=y-d;\n\t\tfirstTime[1]=t+1;\n\t\txs[2]=x+d;\n\t\tys[2]=y;\n\t\tfirstTime[2]=t+2;\n\t\txs[3]=x;\n\t\tys[3]=y+d;\n\t\tfirstTime[3]=t+3;\n\t\t\n\t\tArrayList xMatters=new ArrayList<>();\n\t\tArrayList yMatters=new ArrayList<>();\n\t\tfor (int i=0; i<4; i++) {\n\t\t\tif (matters(xs[i], ys[i], firstTime[i])) {\n\t\t\t\txMatters.add(xs[i]);\n\t\t\t\tyMatters.add(ys[i]);\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"\\t\"+xMatters+\" \"+yMatters);\n\t\tif (xMatters.size()>2) throw null;\n\t\tif (xMatters.size()==0) return;\n\t\tif (xMatters.size()==1) {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t}\n\t\telse {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t\tcostOf[xMatters.get(1)][yMatters.get(1)]+=fightCost;\n\t\t\tif (xMatters.get(0)==(int)xMatters.get(1)) {\n\t\t\t\thBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (yMatters.get(0)==(int)yMatters.get(1)) {\n\t\t\t\t\tvBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tstatic boolean matters(int x, int y, int t) {\n\t\tif (x+y=0; xAt--) {\n\t\t\tfor (int j=0; j=0; yAt--) {\n\t\t\t\tfor (int goingH=0; goingH<2; goingH++) {\n\t\t\t\t\tfor (int timesGoingStraight=0; timesGoingStraight<=(goingH==0?xAt:yAt); timesGoingStraight++) {\n\t\t\t\t\t\tgo(xAt, yAt, timesGoingStraight, goingH);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=go(0, 0, 0, 0);\n\t\tSystem.out.println(ans);\n\t\tSystem.err.println(System.currentTimeMillis()-startTime);\n\t}\n\t\n\tstatic long go(int x, int y, int timesGoingStraight, int goingH) {\n\t\tif (x==maxX-1&&y==maxY-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp[(x&1)][y][timesGoingStraight][goingH]!=-1) return dp[(x&1)][y][timesGoingStraight][goingH];\n\t\tlong curCost=costOf[x][y];\n\t\tif (goingH==1)\n\t\t\tcurCost-=hBonuses[x][y].getBonus(timesGoingStraight);\n\t\telse\n\t\t\tcurCost-=vBonuses[x][y].getBonus(timesGoingStraight);\n//\t\tSystem.out.println(\"Cur cost \"+x+\" \"+y+\" is \"+curCost);\n\t\tlong best; \n\t\tif (goingH==1) {\n\t\t\tlong goH=y+1 pq=new PriorityQueue<>();\n\t\tpublic long bonusAdded=0;\n\t\t\n\t\tpublic void addBonus(int goingStraightFor, long bonus) {\n\t\t\tpq.add(new Bonus(goingStraightFor, bonus));\n\t\t}\n\t\t\n\t\tpublic long getBonus(int goingStraightFor) {\n\t\t\twhile (!pq.isEmpty()&&goingStraightFor>=pq.peek().goingStraightFor) {\n\t\t\t\tBonus next=pq.remove();\n\t\t\t\tbonusAdded+=next.points;\n\t\t\t}\n\t\t\treturn bonusAdded;\n\t\t}\n\t}\n\t\n\tstatic class Bonus implements Comparable {\n\t\tint goingStraightFor;\n\t\tlong points;\n\t\tpublic Bonus(int goingStraightFor, long points) {\n\t\t\tthis.goingStraightFor=goingStraightFor;\n\t\t\tthis.points=points;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Bonus o) {\n\t\t\treturn Integer.compare(goingStraightFor, o.goingStraightFor);\n\t\t}\n\t}\n\t\n\tstatic void processTransformer(int x, int y, int d, int t, long fightCost) {\n//\t\tSystem.out.println(\"Processing transformer (\"+x+\", \"+y+\") d: \"+d+\" startTime: \"+t+\" fightCost: \"+fightCost);\n\t\tint[] xs=new int[4];\n\t\tint[] ys=new int[4];\n\t\tint[] firstTime=new int[4];\n\t\txs[0]=x;\n\t\tys[0]=y;\n\t\tfirstTime[0]=t;\n\t\txs[1]=x+d;\n\t\tys[1]=y-d;\n\t\tfirstTime[1]=t+1;\n\t\txs[2]=x+d;\n\t\tys[2]=y;\n\t\tfirstTime[2]=t+2;\n\t\txs[3]=x;\n\t\tys[3]=y+d;\n\t\tfirstTime[3]=t+3;\n\t\t\n\t\tArrayList xMatters=new ArrayList<>();\n\t\tArrayList yMatters=new ArrayList<>();\n\t\tfor (int i=0; i<4; i++) {\n\t\t\tif (matters(xs[i], ys[i], firstTime[i])) {\n\t\t\t\txMatters.add(xs[i]);\n\t\t\t\tyMatters.add(ys[i]);\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"\\t\"+xMatters+\" \"+yMatters);\n\t\tif (xMatters.size()>2) throw null;\n\t\tif (xMatters.size()==0) return;\n\t\tif (xMatters.size()==1) {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t}\n\t\telse {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t\tcostOf[xMatters.get(1)][yMatters.get(1)]+=fightCost;\n\t\t\tif (xMatters.get(0)==(int)xMatters.get(1)) {\n\t\t\t\thBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (yMatters.get(0)==(int)yMatters.get(1)) {\n\t\t\t\t\tvBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tstatic boolean matters(int x, int y, int t) {\n\t\tif (x+y=0; xAt--) {\n\t\t\tfor (int j=0; j=0; yAt--) {\n\t\t\t\tfor (int goingH=0; goingH<2; goingH++) {\n\t\t\t\t\tfor (int timesGoingStraight=0; timesGoingStraight<(goingH==0?xAt:yAt); timesGoingStraight++) {\n\t\t\t\t\t\tgo(xAt, yAt, timesGoingStraight, goingH);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=go(0, 0, 0, 0);\n\t\tSystem.out.println(ans);\n\t\tSystem.err.println(System.currentTimeMillis()-startTime);\n\t}\n\t\n\tstatic long go(int x, int y, int timesGoingStraight, int goingH) {\n\t\tif (x==maxX-1&&y==maxY-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp[x%2][y][timesGoingStraight][goingH]!=-1) return dp[x%2][y][timesGoingStraight][goingH];\n\t\tlong curCost=costOf[x][y];\n\t\tif (goingH==1)\n\t\t\tcurCost-=hBonuses[x][y].getBonus(timesGoingStraight);\n\t\telse\n\t\t\tcurCost-=vBonuses[x][y].getBonus(timesGoingStraight);\n//\t\tSystem.out.println(\"Cur cost \"+x+\" \"+y+\" is \"+curCost);\n\t\tlong best; \n\t\tif (goingH==1) {\n\t\t\tlong goH=y+1 pq=new PriorityQueue<>();\n\t\tpublic long bonusAdded=0;\n\t\t\n\t\tpublic void addBonus(int goingStraightFor, long bonus) {\n\t\t\tpq.add(new Bonus(goingStraightFor, bonus));\n\t\t}\n\t\t\n\t\tpublic long getBonus(int goingStraightFor) {\n\t\t\twhile (!pq.isEmpty()&&goingStraightFor>=pq.peek().goingStraightFor) {\n\t\t\t\tBonus next=pq.remove();\n\t\t\t\tbonusAdded+=next.points;\n\t\t\t}\n\t\t\treturn bonusAdded;\n\t\t}\n\t}\n\t\n\tstatic class Bonus implements Comparable {\n\t\tint goingStraightFor;\n\t\tlong points;\n\t\tpublic Bonus(int goingStraightFor, long points) {\n\t\t\tthis.goingStraightFor=goingStraightFor;\n\t\t\tthis.points=points;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Bonus o) {\n\t\t\treturn Integer.compare(goingStraightFor, o.goingStraightFor);\n\t\t}\n\t}\n\t\n\tstatic void processTransformer(int x, int y, int d, int t, long fightCost) {\n\t\tint[] xs=new int[4];\n\t\tint[] ys=new int[4];\n\t\tint[] firstTime=new int[4];\n\t\txs[0]=x;\n\t\tys[0]=y;\n\t\tfirstTime[0]=t;\n\t\txs[1]=x+d;\n\t\tys[1]=y-d;\n\t\tfirstTime[1]=t+1;\n\t\txs[2]=x+d;\n\t\tys[2]=y;\n\t\tfirstTime[2]=t+2;\n\t\txs[3]=x;\n\t\tys[3]=y+d;\n\t\tfirstTime[3]=t+3;\n\t\t\n\t\tArrayList xMatters=new ArrayList<>();\n\t\tArrayList yMatters=new ArrayList<>();\n\t\tfor (int i=0; i<4; i++) {\n\t\t\tif (matters(xs[i], ys[i], firstTime[i])) {\n\t\t\t\txMatters.add(xs[i]);\n\t\t\t\tyMatters.add(ys[i]);\n\t\t\t}\n\t\t}\n\t\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)) throw null;\n\t\t\t\tvBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\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=0; xAt--) {\n\t\t\tfor (int j=0; j=0; yAt--) {\n\t\t\t\tfor (int goingH=0; goingH<2; goingH++) {\n\t\t\t\t\tfor (int timesGoingStraight=0; timesGoingStraight<=(goingH==0?xAt:yAt); timesGoingStraight++) {\n\t\t\t\t\t\tgo(xAt, yAt, timesGoingStraight, goingH);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=go(0, 0, 0, 0);\n\t\tSystem.out.println(ans);\n\t\tSystem.err.println(System.currentTimeMillis()-startTime);\n\t}\n\t\n\tstatic long go(int x, int y, int timesGoingStraight, int goingH) {\n\t\tif (x==maxX-1&&y==maxY-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp[x%2][y][timesGoingStraight][goingH]!=-1) return dp[x%2][y][timesGoingStraight][goingH];\n\t\tlong curCost=costOf[x][y];\n\t\tif (goingH==1)\n\t\t\tcurCost-=hBonuses[x][y].getBonus(timesGoingStraight);\n\t\telse\n\t\t\tcurCost-=vBonuses[x][y].getBonus(timesGoingStraight);\n//\t\tSystem.out.println(\"Cur cost \"+x+\" \"+y+\" is \"+curCost);\n\t\tlong best; \n\t\tif (goingH==1) {\n\t\t\tlong goH=y+1 pq=new PriorityQueue<>();\n\t\tpublic long bonusAdded=0;\n\t\t\n\t\tpublic void addBonus(int goingStraightFor, long bonus) {\n\t\t\tpq.add(new Bonus(goingStraightFor, bonus));\n\t\t}\n\t\t\n\t\tpublic long getBonus(int goingStraightFor) {\n\t\t\twhile (!pq.isEmpty()&&goingStraightFor>=pq.peek().goingStraightFor) {\n\t\t\t\tBonus next=pq.remove();\n\t\t\t\tbonusAdded+=next.points;\n\t\t\t}\n\t\t\treturn bonusAdded;\n\t\t}\n\t}\n\t\n\tstatic class Bonus implements Comparable {\n\t\tint goingStraightFor;\n\t\tlong points;\n\t\tpublic Bonus(int goingStraightFor, long points) {\n\t\t\tthis.goingStraightFor=goingStraightFor;\n\t\t\tthis.points=points;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Bonus o) {\n\t\t\treturn Integer.compare(goingStraightFor, o.goingStraightFor);\n\t\t}\n\t}\n\t\n\tstatic void processTransformer(int x, int y, int d, int t, long fightCost) {\n//\t\tSystem.out.println(\"Processing transformer (\"+x+\", \"+y+\") d: \"+d+\" startTime: \"+t+\" fightCost: \"+fightCost);\n\t\tint[] xs=new int[4];\n\t\tint[] ys=new int[4];\n\t\tint[] firstTime=new int[4];\n\t\txs[0]=x;\n\t\tys[0]=y;\n\t\tfirstTime[0]=t;\n\t\txs[1]=x+d;\n\t\tys[1]=y-d;\n\t\tfirstTime[1]=t+1;\n\t\txs[2]=x+d;\n\t\tys[2]=y;\n\t\tfirstTime[2]=t+2;\n\t\txs[3]=x;\n\t\tys[3]=y+d;\n\t\tfirstTime[3]=t+3;\n\t\t\n\t\tArrayList xMatters=new ArrayList<>();\n\t\tArrayList yMatters=new ArrayList<>();\n\t\tfor (int i=0; i<4; i++) {\n\t\t\tif (matters(xs[i], ys[i], firstTime[i])) {\n\t\t\t\txMatters.add(xs[i]);\n\t\t\t\tyMatters.add(ys[i]);\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"\\t\"+xMatters+\" \"+yMatters);\n\t\tif (xMatters.size()>2) throw null;\n\t\tif (xMatters.size()==0) return;\n\t\tif (xMatters.size()==1) {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t}\n\t\telse {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t\tcostOf[xMatters.get(1)][yMatters.get(1)]+=fightCost;\n\t\t\tif (xMatters.get(0)==(int)xMatters.get(1)) {\n\t\t\t\thBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (yMatters.get(0)!=(int)yMatters.get(1)) {\n\t\t\t\t\tvBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tstatic boolean matters(int x, int y, int t) {\n\t\tif (x+y=0; xAt--) {\n\t\t\tfor (int j=0; j=0; yAt--) {\n\t\t\t\tfor (int goingH=0; goingH<2; goingH++) {\n\t\t\t\t\tfor (int timesGoingStraight=0; timesGoingStraight<=(goingH==0?xAt:yAt); timesGoingStraight++) {\n\t\t\t\t\t\tgo(xAt, yAt, timesGoingStraight, goingH);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=go(0, 0, 0, 0);\n\t\tSystem.out.println(ans);\n\t\tSystem.err.println(System.currentTimeMillis()-startTime);\n\t}\n\t\n\tstatic long go(int x, int y, int timesGoingStraight, int goingH) {\n\t\tif (x==maxX-1&&y==maxY-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp[x%2][y][timesGoingStraight][goingH]!=-1) return dp[x%2][y][timesGoingStraight][goingH];\n\t\tlong curCost=costOf[x][y];\n\t\tif (goingH==1)\n\t\t\tcurCost-=hBonuses[x][y].getBonus(timesGoingStraight);\n\t\telse\n\t\t\tcurCost-=vBonuses[x][y].getBonus(timesGoingStraight);\n//\t\tSystem.out.println(\"Cur cost \"+x+\" \"+y+\" is \"+curCost);\n\t\tlong best; \n\t\tif (goingH==1) {\n\t\t\tlong goH=y+1 pq=new PriorityQueue<>();\n\t\tpublic long bonusAdded=0;\n\t\t\n\t\tpublic void addBonus(int goingStraightFor, long bonus) {\n\t\t\tpq.add(new Bonus(goingStraightFor, bonus));\n\t\t}\n\t\t\n\t\tpublic long getBonus(int goingStraightFor) {\n\t\t\twhile (!pq.isEmpty()&&goingStraightFor>=pq.peek().goingStraightFor) {\n\t\t\t\tBonus next=pq.remove();\n\t\t\t\tbonusAdded+=next.points;\n\t\t\t}\n\t\t\treturn bonusAdded;\n\t\t}\n\t}\n\t\n\tstatic class Bonus implements Comparable {\n\t\tint goingStraightFor;\n\t\tlong points;\n\t\tpublic Bonus(int goingStraightFor, long points) {\n\t\t\tthis.goingStraightFor=goingStraightFor;\n\t\t\tthis.points=points;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Bonus o) {\n\t\t\treturn Integer.compare(goingStraightFor, o.goingStraightFor);\n\t\t}\n\t}\n\t\n\tstatic void processTransformer(int x, int y, int d, int t, long fightCost) {\n//\t\tSystem.out.println(\"Processing transformer (\"+x+\", \"+y+\") d: \"+d+\" startTime: \"+t+\" fightCost: \"+fightCost);\n\t\tint[] xs=new int[4];\n\t\tint[] ys=new int[4];\n\t\tint[] firstTime=new int[4];\n\t\txs[0]=x;\n\t\tys[0]=y;\n\t\tfirstTime[0]=t;\n\t\txs[1]=x+d;\n\t\tys[1]=y-d;\n\t\tfirstTime[1]=t+1;\n\t\txs[2]=x+d;\n\t\tys[2]=y;\n\t\tfirstTime[2]=t+2;\n\t\txs[3]=x;\n\t\tys[3]=y+d;\n\t\tfirstTime[3]=t+3;\n\t\t\n\t\tArrayList xMatters=new ArrayList<>();\n\t\tArrayList yMatters=new ArrayList<>();\n\t\tfor (int i=0; i<4; i++) {\n\t\t\tif (matters(xs[i], ys[i], firstTime[i])) {\n\t\t\t\txMatters.add(xs[i]);\n\t\t\t\tyMatters.add(ys[i]);\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"\\t\"+xMatters+\" \"+yMatters);\n\t\tif (xMatters.size()>2) throw null;\n\t\tif (xMatters.size()==0) return;\n\t\tif (xMatters.size()==1) {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t}\n\t\telse {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t\tcostOf[xMatters.get(1)][yMatters.get(1)]+=fightCost;\n\t\t\tif (xMatters.get(0)==(int)xMatters.get(1)) {\n\t\t\t\thBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (yMatters.get(0)==(int)yMatters.get(1)) {\n\t\t\t\t\tvBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tstatic boolean matters(int x, int y, int t) {\n\t\tif (x+y= '0' && map[i][j] <= '9') {\n treasures++;\n map[i][j]--;\n }\n }\n }\n int[] treasureCosts = new int[treasures];\n for (int i = 0; i < treasures; i++) {\n treasureCosts[i] = nextInt();\n }\n class Point {\n int x, y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n Point subtract(Point other) {\n return new Point(x - other.x, y - other.y);\n }\n\n int vectorProduct(Point other) {\n return x * other.y - y * other.x;\n }\n\n Point add(Point other) {\n return new Point(x + other.x, y + other.y);\n }\n }\n class GeomUtils {\n Point cellCenter(int row, int column) {\n return new Point(2 * row + 1, 2 * column + 1);\n }\n\n Point ray = new Point(40, 41);\n\n double getT(Point o, Point v, Point s1, Point s2) {\n Point vs = s2.subtract(s1);\n int r = vs.vectorProduct(s2) - vs.vectorProduct(o);\n int l = vs.vectorProduct(v);\n return 1.0 * r / l;\n }\n\n boolean intersects(Point o, Point s1, Point s2) {\n if (getT(o, ray, s1, s2) < 0.0) return false;\n double t = getT(s1, s2.subtract(s1), o, o.add(ray));\n return t >= 0.0 && t <= 1.0;\n }\n }\n Point[] treasureCoords = new Point[treasures];\n Point[] bombCoords = new Point[bombs];\n bombs = 0;\n int si = 0, sj = 0;\n GeomUtils geomUtils = new GeomUtils();\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (map[i][j] == 'B') {\n bombCoords[bombs++] = geomUtils.cellCenter(i, j);\n }\n if (map[i][j] >= '0' && map[i][j] <= '9') {\n treasureCoords[map[i][j] - '0'] = geomUtils.cellCenter(i, j);\n }\n if (map[i][j] == 'S') {\n si = i;\n sj = j;\n }\n }\n }\n int[][][][] dist = new int[n][m][1 << treasures][1 << bombs];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n for (int k = 0; k < 1 << treasures; k++)\n for (int l = 0; l < 1 << bombs; l++) dist[i][j][k][l] = Integer.MAX_VALUE;\n dist[si][sj][0][0] = 0;\n Queue qi = new LinkedList<>(), qj = new LinkedList<>(), qt = new LinkedList<>(), qb = new LinkedList<>();\n qi.add(si);\n qj.add(sj);\n qt.add(0);\n qb.add(0);\n int[] di = {0, -1, 0, 1};\n int[] dj = {-1, 0, 1, 0};\n while (!qi.isEmpty()) {\n int i = qi.poll();\n int j = qj.poll();\n int tmask = qt.poll();\n int bmask = qb.poll();\n Point s1 = geomUtils.cellCenter(i, j);\n for (int k = 0; k < 4; k++) {\n int ii = i + di[k];\n int jj = j + dj[k];\n if (ii < 0 || ii >= n || jj < 0 || jj >= m || map[ii][jj] != '.' && map[ii][jj] != 'S') continue;\n int tm = 0;\n for (int ti = 0; ti < treasures; ti++) {\n if (geomUtils.intersects(treasureCoords[ti], s1, geomUtils.cellCenter(ii, jj))) {\n tm |= 1 << ti;\n }\n }\n int bm = 0;\n for (int bi = 0; bi < bombs; bi++) {\n if (geomUtils.intersects(bombCoords[bi], s1, geomUtils.cellCenter(ii, jj))) {\n bm |= 1 << bi;\n }\n }\n if (dist[ii][jj][tmask ^ tm][bmask ^ bm] == Integer.MAX_VALUE) {\n dist[ii][jj][tmask ^ tm][bmask ^ bm] = dist[i][j][tmask][bmask] + 1;\n qi.add(ii);\n qj.add(jj);\n qt.add(tmask ^ tm);\n qb.add(bmask ^ bm);\n }\n }\n }\n int ans = 0;\n for (int i = 0; i < 1 << treasures; i++) {\n int tCost = 0;\n for (int j = 0; j < treasures; j++) {\n if (((i >> j) & 1) == 1) tCost += treasureCosts[j];\n }\n ans = Math.max(ans, tCost - dist[si][sj][i][0]);\n }\n writer.println(ans);\n writer.close();\n }\n\n public static void main(String[] args) throws IOException {\n new C().solve();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65e6048d4be65ba53b68d44a773f7d5d", "src_uid": "624a0d6cf305fcf67d3f1cdc1c5fef8d", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "//package round221;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\n\npublic class C {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni();\n\t\tchar[][] map = nm(n,m);\n\t\tint sr = -1, sc = -1;\n\t\tint[][] objs = new int[8][];\n\t\tint p = 0;\n\t\tint max = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tif(map[i][j] == 'S'){\n\t\t\t\t\tsr = i; sc = j;\n\t\t\t\t\tmap[sr][sc] = '.';\n\t\t\t\t}\n\t\t\t\tif(map[i][j] >= '1' && map[i][j] <= '9'){\n\t\t\t\t\tobjs[p++] = new int[]{i, j, map[i][j]-'0'};\n\t\t\t\t\tmax = Math.max(max, map[i][j]-'0');\n\t\t\t\t}\n\t\t\t\tif(map[i][j] == 'B'){\n\t\t\t\t\tobjs[p++] = new int[]{i, j, -99999};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[] price = na(max);\n\t\tfor(int i = 0;i < p;i++){\n\t\t\tif(objs[i][2] >= 0){\n\t\t\t\tobjs[i][2] = price[objs[i][2]-1];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint I = 999999;\n\t\tint[][][][] d = new int[n][m][1< q = new ArrayDeque();\n\t\tq.add(enc(sr, sc, 1, 0));\n\t\tint[] dr = { 1, 0, -1, 0 };\n\t\tint[] dc = { 0, 1, 0, -1 };\n\t\twhile(!q.isEmpty()){\n\t\t\tint cur = q.poll();\n\t\t\tint r = cur>>>5&31, c = cur&31, ptn = cur>>>12, predir = cur>>>10&3;\n\t\t\tfor(int k = 0;k < 4;k++){\n\t\t\t\tint nr = r + dr[k], nc = c + dc[k];\n\t\t\t\tif(nr >= 0 && nr < n && nc >= 0 && nc < m && map[nr][nc] == '.'){\n\t\t\t\t\tint nptn = ptn;\n\t\t\t\t\tif((k == 2 || k == 0) && k != 2-predir){\n\t\t\t\t\t\tfor(int u = 0;u < p;u++){\n\t\t\t\t\t\t\tif(objs[u][0] == r && objs[u][1] < c)nptn ^= 1< d[r][c][ptn][predir] + 1){\n\t\t\t\t\t\td[nr][nc][nptn][npredir] = d[r][c][ptn][predir] + 1;\n\t\t\t\t\t\tq.add(enc(nr, nc, npredir, nptn));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong ret = 0;\n\t\tfor(int i = 0;i < 1<= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f38ac4943c98bd0266a8c6dfba9a6b2a", "src_uid": "624a0d6cf305fcf67d3f1cdc1c5fef8d", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.sql.Time;\nimport java.util.*;\n\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n// boolean oj = true;\n try{\n if( oj ){\n sc = new FastScanner( new InputStreamReader(System.in ) );\n out = new PrintWriter( new OutputStreamWriter(System.out) );\n } else{\n sc = new FastScanner(new FileReader(\"in.txt\") );\n// sc = new FastScanner(new FileReader(\"D:\\\\JavaOlymp\\\\FatalError\\\\output.txt\") );\n out = new PrintWriter( new FileWriter(\"out.txt\") );\n }\n } catch (Exception e) {\n System.exit(-1);\n }\n long tB = System.currentTimeMillis();\n solve();\n if( !oj ) System.err.println( \"Time: \" + (System.currentTimeMillis()-tB)/1e3 );\n out.flush();\n }\n\n\n class FastScanner{\n BufferedReader br;\n StringTokenizer st = new StringTokenizer(\"\");\n FastScanner( InputStreamReader a ){\n br = new BufferedReader(a);\n }\n FastScanner( FileReader a ){\n br = new BufferedReader(a);\n }\n String next(){\n while( !st.hasMoreTokens() )\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n return null;\n }\n return st.nextToken();\n }\n String readLine(){\n try {\n return br.readLine();\n } catch (Exception e) {\n return null;\n }\n }\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n }\n\n FastScanner sc;\n PrintWriter out;\n\n\n\n public static void main(String[] args){\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"LOL\", 256L * 1024 * 1024 / 2 ).run();\n// }, \"LOL\", 2000 * 1024 * 1024 ).run();\n }\n\n\n\n void TLE(){ for(;;); }\n\n void MLE(){\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 void exit( int val ){\n out.flush();\n System.exit(val);\n }\n //////////////////////////////////////////////////////////////////////////////////////////\n\n class Item{\n int i, j, msk;\n Item( int _i, int _j, int _msk ){\n i = _i;\n j = _j;\n msk = _msk;\n }\n }\n\n final int inf = Integer.MAX_VALUE / 10;\n int n, m, Si, Sj;\n char[][] gr;\n\n int timer, mskOfBomb;\n int[] idObj;\n\n int[] cost = new int[8];\n int[][] dp;\n int[][] howI = new int[1000][1000];\n int[][] howJ = new int[1000][1000];\n int[][] howM = new int[1000][1000];\n {\n for( int i = 0; i < 1000; ++i ){\n fill( howI[i], -1 );\n fill( howJ[i], -1 );\n fill( howM[i], -1 );\n }\n }\n\n void f( int i, int j, int msk ){\n if( i==Si && j==Sj && msk==0 ){\n }\n else{\n f(\n howI[i*m+j][msk],\n howJ[i*m+j][msk],\n howM[i*m+j][msk]);\n }\n out.printf(\"%d %d %4s\\n\", i, j, Integer.toBinaryString(msk));\n }\n\n void solve(){\n n = sc.nextInt();\n m = sc.nextInt();\n gr = new char[n][];\n idObj = new int[n*m]; fill( idObj, -1 );\n for( int i = 0; i < n; ++i )\n gr[i] = sc.next().toCharArray();\n\n\n for( int i = 0; i < n; ++i ){\n for( int j = 0; j < m; ++j ){\n char c = gr[i][j];\n if( Character.isDigit(c) ){\n idObj[i*m+j] = timer++;\n cost[timer-1] = sc.nextInt();\n }\n if( c=='B' ){\n idObj[i*m+j] = timer++;\n mskOfBomb |= 1 << (timer-1);\n }\n if( c == 'S' ){\n Si = i;\n Sj = j;\n }\n }\n }\n\n dp = new int[n*m][1<<8];\n for( int[] dpi : dp ) fill( dpi, inf );\n dp[Si*m + Sj][0] = 0;\n ArrayDeque Q = new ArrayDeque();\n Q.add(new Item(Si,Sj,0));\n while( !Q.isEmpty() ){\n Item v = Q.pollFirst();\n for( int di = -1; di <= 1; ++di ){\n for( int dj = -1; dj <= 1; ++dj ){\n if( abs(di) + abs(dj) != 1 ) continue;\n Item to = new Item(v.i+di, v.j+dj, v.msk);\n if(!( 0<=to.i && to.i dp[v.i*m + v.j][v.msk] + 1 ){\n dp[to.i*m + to.j][to.msk] = dp[v.i*m + v.j][v.msk] + 1;\n Q.addLast(to);\n howI[to.i*m + to.j][to.msk] = v.i;\n howJ[to.i*m + to.j][to.msk] = v.j;\n howM[to.i*m + to.j][to.msk] = v.msk;\n }\n }\n }\n }\n\n int ans = 0;\n for( int msk = 0; msk < 1<<8; ++msk ){\n if( (msk & mskOfBomb) == 0 &&\n dp[Si*m + Sj][msk] != inf ){\n int cost = 0;\n for( int i = 0; i < 8; ++i )\n if( (msk & (1< Q = new ArrayDeque();\n Q.add(new Item(Si,Sj,0));\n while( !Q.isEmpty() ){\n Item v = Q.pollFirst();\n for( int di = -1; di <= 1; ++di ){\n for( int dj = -1; dj <= 1; ++dj ){\n if( abs(di) + abs(dj) != 1 ) continue;\n Item to = new Item(v.i+di, v.j+dj, v.msk);\n if(!( 0<=to.i && to.i dp[v.i*m + v.j][v.msk] + 1 ){\n dp[to.i*m + to.j][to.msk] = dp[v.i*m + v.j][v.msk] + 1;\n Q.addLast(to);\n howI[to.i*m + to.j][to.msk] = v.i;\n howJ[to.i*m + to.j][to.msk] = v.j;\n howM[to.i*m + to.j][to.msk] = v.msk;\n }\n }\n }\n }\n\n int ans = 0;\n for( int msk = 0; msk < 1<<8; ++msk ){\n if( (msk & mskOfBomb) == 0 &&\n dp[Si*m + Sj][msk] != inf ){\n int cost = 0;\n for( int i = 0; i < 8; ++i )\n if( (msk & (1< 0) {\n\t\t\t\ta += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitMul(long x) {\n\t\t\tlong a = 1;\n\t\t\twhile (x > 0) {\n\t\t\t\ta *= x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tint digitCubesSum(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta += (x % 10) * (x % 10) * (x % 10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble pif(double ax, double ay, double bx, double by) {\n\t\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));\n\t\t}\n\n\t\tlong gcd(long a, long b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tlong c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tlong c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint gcd(int a, int b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tint c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tint c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tlong lcm(long a, long b) throws IOException {\n\t\t\treturn a * b / gcd(a, b);\n\t\t}\n\n\t\tint lcm(int a, int b) throws IOException {\n\t\t\treturn a * b / gcd(a, b);\n\t\t}\n\n\t\tint countOccurences(String x, String y) {\n\t\t\tint a = 0, i = 0;\n\t\t\twhile (true) {\n\t\t\t\ti = y.indexOf(x);\n\t\t\t\tif (i == -1) break;\n\t\t\t\ta++;\n\t\t\t\ty = y.substring(i + 1);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tint[] findPrimes(int x) {\n\t\t\tboolean[] forErato = new boolean[x - 1];\n\t\t\tList t = new Vector();\n\t\t\tint l = 0, j = 0;\n\t\t\tfor (int i = 2; i < x; i++) {\n\t\t\t\tif (forErato[i - 2]) continue;\n\t\t\t\tt.add(i);\n\t\t\t\tl++;\n\t\t\t\tj = i * 2;\n\t\t\t\twhile (j < x) {\n\t\t\t\t\tforErato[j - 2] = true;\n\t\t\t\t\tj += i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] primes = new int[l];\n\t\t\tIterator iterator = t.iterator();\n\t\t\tfor (int i = 0; iterator.hasNext(); i++) {\n\t\t\t\tprimes[i] = iterator.next().intValue();\n\t\t\t}\n\t\t\treturn primes;\n\t\t}\n\n\t\tint rev(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta = a * 10 + x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tclass myDate {\n\t\t\tint d, m, y;\n\n\t\t\tint[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n\t\t\tpublic myDate(int da, int ma, int ya) {\n\t\t\t\td = da;\n\t\t\t\tm = ma;\n\t\t\t\ty = ya;\n\t\t\t\tif ((ma > 12 || ma < 1 || da > ml[ma - 1] || da < 1) && !(d == 29 && m == 2 && y % 4 == 0)) {\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t\ty = 9999999;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid incYear(int x) {\n\t\t\t\tfor (int i = 0; i < x; i++) {\n\t\t\t\t\ty++;\n\t\t\t\t\tif (m == 2 && d == 29) {\n\t\t\t\t\t\tm = 3;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (m == 3 && d == 1) {\n\t\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\t\tm = 2;\n\t\t\t\t\t\t\td = 29;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tboolean less(myDate x) {\n\t\t\t\tif (y < x.y) return true;\n\t\t\t\tif (y > x.y) return false;\n\t\t\t\tif (m < x.m) return true;\n\t\t\t\tif (m > x.m) return false;\n\t\t\t\tif (d < x.d) return true;\n\t\t\t\tif (d > x.d) return false;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tvoid inc() {\n\t\t\t\tif ((d == 31) && (m == 12)) {\n\t\t\t\t\ty++;\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\tml[1] = 29;\n\t\t\t\t\t}\n\t\t\t\t\tif (d == ml[m - 1]) {\n\t\t\t\t\t\tm++;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t} else\n\t\t\t\t\t\td++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint partition(int n, int l, int m) {// n - sum, l - length, m - every\n\t\t\t\t\t\t\t\t\t\t\t// part\n\t\t\t// <= m\n\t\t\tif (n < l) return 0;\n\t\t\tif (n < l + 2) return 1;\n\t\t\tif (l == 1) return 1;\n\t\t\tint c = 0;\n\t\t\tfor (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {\n\t\t\t\tc += partition(n - i, l - 1, i);\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tint rifmQuality(String a, String b) {\n\t\t\tif (a.length() > b.length()) {\n\t\t\t\tString c = a;\n\t\t\t\ta = b;\n\t\t\t\tb = c;\n\t\t\t}\n\t\t\tint c = 0, d = b.length() - a.length();\n\t\t\tfor (int i = a.length() - 1; i >= 0; i--) {\n\t\t\t\tif (a.charAt(i) == b.charAt(i + d)) c++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tString numSym = \"0123456789ABCDEF\";\n\n\t\tString ZFromXToYNotation(int x, int y, String z) {\n\t\t\tif (z.equals(\"0\")) return \"0\";\n\t\t\tString a = \"\";\n\t\t\tlong q = 0, t = 1;\n\t\t\tfor (int i = z.length() - 1; i >= 0; i--) {\n\t\t\t\tq += (z.charAt(i) - 48) * t;\n\t\t\t\tt *= x;\n\t\t\t}\n\t\t\twhile (q > 0) {\n\t\t\t\ta = numSym.charAt((int) (q % y)) + a;\n\t\t\t\tq /= y;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble angleFromXY(int x, int y) {\n\t\t\tif ((x == 0) && (y > 0)) return Math.PI / 2;\n\t\t\tif ((x == 0) && (y < 0)) return -Math.PI / 2;\n\t\t\tif ((y == 0) && (x > 0)) return 0;\n\t\t\tif ((y == 0) && (x < 0)) return Math.PI;\n\t\t\tif (x > 0) return Math.atan((double) y / x);\n\t\t\telse {\n\t\t\t\tif (y > 0) return Math.atan((double) y / x) + Math.PI;\n\t\t\t\telse\n\t\t\t\t\treturn Math.atan((double) y / x) - Math.PI;\n\t\t\t}\n\t\t}\n\n\t\tstatic boolean isNumber(String x) {\n\t\t\ttry {\n\t\t\t\tInteger.parseInt(x);\n\t\t\t} catch (NumberFormatException ex) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tstatic boolean stringContainsOf(String x, String c) {\n\t\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\t\tif (c.indexOf(x.charAt(i)) == -1) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tlong pow(long a, long n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tlong k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint pow(int a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tint k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble pow(double a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tdouble k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble log2(double x) {\n\t\t\treturn Math.log(x) / Math.log(2);\n\t\t}\n\n\t\tint lpd(int[] primes, int x) {// least prime divisor\n\t\t\tint i;\n\t\t\tfor (i = 0; primes[i] <= x / 2; i++) {\n\t\t\t\tif (x % primes[i] == 0) {\n\t\t\t\t\treturn primes[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t;\n\t\t\treturn x;\n\t\t}\n\n\t\tint np(int[] primes, int x) {// number of prime number\n\t\t\tfor (int i = 0; true; i++) {\n\t\t\t\tif (primes[i] == x) return i;\n\t\t\t}\n\t\t}\n\n\t\tint[] dijkstra(int[][] map, int n, int s) {\n\t\t\tint[] p = new int[n];\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tArrays.fill(p, Integer.MAX_VALUE);\n\t\t\tp[s] = 0;\n\t\t\tb[s] = true;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i != s) p[i] = map[s][i];\n\t\t\t}\n\t\t\twhile (true) {\n\t\t\t\tint m = Integer.MAX_VALUE, mi = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (!b[i] && (p[i] < m)) {\n\t\t\t\t\t\tmi = i;\n\t\t\t\t\t\tm = p[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (mi == -1) break;\n\t\t\t\tb[mi] = true;\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tif (p[mi] + map[mi][i] < p[i]) p[i] = p[mi] + map[mi][i];\n\t\t\t}\n\t\t\treturn p;\n\t\t}\n\n\t\tboolean isLatinChar(char x) {\n\t\t\tif (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z'))) return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isBigLatinChar(char x) {\n\t\t\tif (x >= 'A' && x <= 'Z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isSmallLatinChar(char x) {\n\t\t\tif (x >= 'a' && x <= 'z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isDigitChar(char x) {\n\t\t\tif (x >= '0' && x <= '9') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tclass NotANumberException extends Exception {\n\t\t\tprivate static final long serialVersionUID = 1L;\n\t\t\tString mistake;\n\n\t\t\tNotANumberException() {\n\t\t\t\tmistake = \"Unknown.\";\n\t\t\t}\n\n\t\t\tNotANumberException(String message) {\n\t\t\t\tmistake = message;\n\t\t\t}\n\t\t}\n\n\t\tclass Real {\n\t\t\tString num = \"0\";\n\t\t\tlong exp = 0;\n\t\t\tboolean pos = true;\n\n\t\t\tlong length() {\n\t\t\t\treturn num.length();\n\t\t\t}\n\n\t\t\tvoid check(String x) throws NotANumberException {\n\t\t\t\tif (!stringContainsOf(x, \"0123456789+-.eE\")) throw new NotANumberException(\"Illegal character.\");\n\t\t\t\tlong j = 0;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif ((x.charAt((int) i) == '-') || (x.charAt((int) i) == '+')) {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected sign.\");\n\t\t\t\t\t} else\n\t\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\t\tif (j == 0) j = 2;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (j == 1) j = 2;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 2)\n\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 3) j = 4;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tif (j == 4)\n\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (j == 6)\n\t\t\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected digit.\");\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\t\t\tif (j == 0) j = 3;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 1) j = 3;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 2) j = 3;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected dot.\");\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\t\t\t\tif (j == 2) j = 5;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 4) j = 5;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected exponent.\");\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"O_o.\");\n\t\t\t\t}\n\t\t\t\tif ((j == 0) || (j == 1) || (j == 3) || (j == 5)) throw new NotANumberException(\"Unexpected end.\");\n\t\t\t}\n\n\t\t\tpublic Real(String x) throws NotANumberException {\n\t\t\t\tcheck(x);\n\t\t\t\tif (x.charAt(0) == '-') pos = false;\n\t\t\t\tlong j = 0;\n\t\t\t\tString e = \"\";\n\t\t\t\tboolean epos = true;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\tif (j == 0) num += x.charAt((int) i);\n\t\t\t\t\t\tif (j == 1) {\n\t\t\t\t\t\t\tnum += x.charAt((int) i);\n\t\t\t\t\t\t\texp--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (j == 2) e += x.charAt((int) i);\n\t\t\t\t\t}\n\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t}\n\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\tj = 2;\n\t\t\t\t\t\tif (x.charAt((int) (i + 1)) == '-') epos = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(0) == '0'))\n\t\t\t\t\tnum = num.substring(1);\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(num.length() - 1) == '0')) {\n\t\t\t\t\tnum = num.substring(0, num.length() - 1);\n\t\t\t\t\texp++;\n\t\t\t\t}\n\t\t\t\tif (num.equals(\"0\")) {\n\t\t\t\t\texp = 0;\n\t\t\t\t\tpos = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\twhile ((e.length() > 1) && (e.charAt(0) == '0'))\n\t\t\t\t\te = e.substring(1);\n\t\t\t\ttry {\n\t\t\t\t\tif (e != \"\") if (epos) exp += Long.parseLong(e);\n\t\t\t\t\telse\n\t\t\t\t\t\texp -= Long.parseLong(e);\n\t\t\t\t} catch (NumberFormatException exc) {\n\t\t\t\t\tif (!epos) {\n\t\t\t\t\t\tnum = \"0\";\n\t\t\t\t\t\texp = 0;\n\t\t\t\t\t\tpos = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new NotANumberException(\"Too long exponent\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic Real() {\n\t\t\t}\n\n\t\t\tString toString(long mantissa) {\n\t\t\t\tString a = \"\", b = \"\";\n\t\t\t\tif (exp >= 0) {\n\t\t\t\t\ta = num;\n\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\tfor (long i = 0; i < exp; i++)\n\t\t\t\t\t\ta += '0';\n\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\tb += '0';\n\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t} else {\n\t\t\t\t\tif (exp + length() <= 0) {\n\t\t\t\t\t\ta = \"0\";\n\t\t\t\t\t\tif (mantissa == 0) {\n\t\t\t\t\t\t\treturn a;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (mantissa < -(exp + length() - 1)) {\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tif (i < -(exp + length())) b += '0';\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (i + exp >= 0) b += '0';\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tb += num.charAt((int) (i + exp + length()));\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!pos) a = \"-\";\n\t\t\t\t\t\tfor (long i = 0; i < exp + length(); i++)\n\t\t\t\t\t\t\ta += num.charAt((int) i);\n\t\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\t\tfor (long i = exp + length(); i < exp + length() + mantissa; i++)\n\t\t\t\t\t\t\tif (i < length()) b += num.charAt((int) i);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tboolean containsRepeats(int... num) {\n\t\t\tSet s = new TreeSet();\n\t\t\tfor (int d : num)\n\t\t\t\tif (!s.contains(d)) s.add(d);\n\t\t\t\telse\n\t\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\n\t\tint[] rotateDice(int[] a, int n) {\n\t\t\tint[] c = new int[6];\n\t\t\tif (n == 0) {\n\t\t\t\tc[0] = a[1];\n\t\t\t\tc[1] = a[5];\n\t\t\t\tc[2] = a[2];\n\t\t\t\tc[3] = a[0];\n\t\t\t\tc[4] = a[4];\n\t\t\t\tc[5] = a[3];\n\t\t\t}\n\t\t\tif (n == 1) {\n\t\t\t\tc[0] = a[2];\n\t\t\t\tc[1] = a[1];\n\t\t\t\tc[2] = a[5];\n\t\t\t\tc[3] = a[3];\n\t\t\t\tc[4] = a[0];\n\t\t\t\tc[5] = a[4];\n\t\t\t}\n\t\t\tif (n == 2) {\n\t\t\t\tc[0] = a[3];\n\t\t\t\tc[1] = a[0];\n\t\t\t\tc[2] = a[2];\n\t\t\t\tc[3] = a[5];\n\t\t\t\tc[4] = a[4];\n\t\t\t\tc[5] = a[1];\n\t\t\t}\n\t\t\tif (n == 3) {\n\t\t\t\tc[0] = a[4];\n\t\t\t\tc[1] = a[1];\n\t\t\t\tc[2] = a[0];\n\t\t\t\tc[3] = a[3];\n\t\t\t\tc[4] = a[5];\n\t\t\t\tc[5] = a[2];\n\t\t\t}\n\t\t\tif (n == 4) {\n\t\t\t\tc[0] = a[0];\n\t\t\t\tc[1] = a[2];\n\t\t\t\tc[2] = a[3];\n\t\t\t\tc[3] = a[4];\n\t\t\t\tc[4] = a[1];\n\t\t\t\tc[5] = a[5];\n\t\t\t}\n\t\t\tif (n == 5) {\n\t\t\t\tc[0] = a[0];\n\t\t\t\tc[1] = a[4];\n\t\t\t\tc[2] = a[1];\n\t\t\t\tc[3] = a[2];\n\t\t\t\tc[4] = a[3];\n\t\t\t\tc[5] = a[5];\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tint min(int... a) {\n\t\t\tint c = Integer.MAX_VALUE;\n\t\t\tfor (int d : a)\n\t\t\t\tif (d < c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint max(int... a) {\n\t\t\tint c = Integer.MIN_VALUE;\n\t\t\tfor (int d : a)\n\t\t\t\tif (d > c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint[] normalizeDice(int[] a) {\n\t\t\tint[] c = a.clone();\n\t\t\tif (c[0] != 0) if (c[1] == 0) c = rotateDice(c, 0);\n\t\t\telse\n\t\t\t\tif (c[2] == 0) c = rotateDice(c, 1);\n\t\t\t\telse\n\t\t\t\t\tif (c[3] == 0) c = rotateDice(c, 2);\n\t\t\t\t\telse\n\t\t\t\t\t\tif (c[4] == 0) c = rotateDice(c, 3);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (c[5] == 0) c = rotateDice(rotateDice(c, 0), 0);\n\t\t\twhile (c[1] != min(c[1], c[2], c[3], c[4]))\n\t\t\t\tc = rotateDice(c, 4);\n\t\t\treturn c;\n\t\t}\n\n\t\tboolean sameDice(int[] a, int[] b) {\n\t\t\tfor (int i = 0; i < 6; i++)\n\t\t\t\tif (a[i] != b[i]) return false;\n\t\t\treturn true;\n\t\t}\n\n\t\tfinal double goldenRatio = (1 + Math.sqrt(5)) / 2;\n\t\tfinal double aGoldenRatio = (1 - Math.sqrt(5)) / 2;\n\n\t\tlong Fib(int n) {\n\t\t\tif (n < 0) if (n % 2 == 0) return -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\telse\n\t\t\t\treturn -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\treturn Math.round((pow(goldenRatio, n) - pow(aGoldenRatio, n)) / Math.sqrt(5));\n\t\t}\n\n\t\tclass japaneeseComparator implements Comparator {\n\t\t\t@Override\n\t\t\tpublic int compare(String a, String b) {\n\t\t\t\tint ai = 0, bi = 0;\n\t\t\t\tboolean m = false, ns = false;\n\t\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') m = true;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') m = true;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\ta += \"!\";\n\t\t\t\tb += \"!\";\n\t\t\t\tint na = 0, nb = 0;\n\t\t\t\twhile (true) {\n\t\t\t\t\tif (a.charAt(ai) == '!') {\n\t\t\t\t\t\tif (b.charAt(bi) == '!') break;\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (b.charAt(bi) == '!') {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (m) {\n\t\t\t\t\t\tint ab = -1, bb = -1;\n\t\t\t\t\t\twhile (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\t\t\t\tif (ab == -1) ab = ai;\n\t\t\t\t\t\t\tai++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\t\t\t\tif (bb == -1) bb = bi;\n\t\t\t\t\t\t\tbi++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tm = !m;\n\t\t\t\t\t\tif (ab == -1) {\n\t\t\t\t\t\t\tif (bb == -1) continue;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (bb == -1) return -1;\n\t\t\t\t\t\twhile (a.charAt(ab) == '0' && ab + 1 != ai) {\n\t\t\t\t\t\t\tab++;\n\t\t\t\t\t\t\tif (!ns) na++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (b.charAt(bb) == '0' && bb + 1 != bi) {\n\t\t\t\t\t\t\tbb++;\n\t\t\t\t\t\t\tif (!ns) nb++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (na != nb) ns = true;\n\t\t\t\t\t\tif (ai - ab < bi - bb) return -1;\n\t\t\t\t\t\tif (ai - ab > bi - bb) return 1;\n\t\t\t\t\t\tfor (int i = 0; i < ai - ab; i++) {\n\t\t\t\t\t\t\tif (a.charAt(ab + i) < b.charAt(bb + i)) return -1;\n\t\t\t\t\t\t\tif (a.charAt(ab + i) > b.charAt(bb + i)) return 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tm = !m;\n\t\t\t\t\t\twhile (true) {\n\t\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a' && b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') {\n\t\t\t\t\t\t\t\tif (a.charAt(ai) < b.charAt(bi)) return -1;\n\t\t\t\t\t\t\t\tif (a.charAt(ai) > b.charAt(bi)) return 1;\n\t\t\t\t\t\t\t\tai++;\n\t\t\t\t\t\t\t\tbi++;\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a') return 1;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') return -1;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (na < nb) return 1;\n\t\t\t\tif (na > nb) return -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\n\t\tRandom random = new Random();\n\t}\n\n\tStreamTokenizer in;\n\tPrintWriter out;\n\tboolean oj;\n\tBufferedReader br;\n\n\tvoid init() throws IOException {\n\t\toj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\toj = !true;\n\t\tReader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n\t\tWriter writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n\t\tbr = new BufferedReader(reader);\n\t\tin = new StreamTokenizer(br);\n\t\tout = new PrintWriter(writer);\n\t}\n\n\tlong selectionTime = 0;\n\n\tvoid startSelection() {\n\t\tselectionTime -= System.currentTimeMillis();\n\t}\n\n\tvoid stopSelection() {\n\t\tselectionTime += System.currentTimeMillis();\n\t}\n\n\tvoid run() throws IOException {\n\t\tlong beginTime = System.currentTimeMillis();\n\t\tinit();\n\t\tsolve();\n\t\tlong endTime = System.currentTimeMillis();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(\"Memory used = \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));\n\t\t\tSystem.out.println(\"Running time = \" + (endTime - beginTime));\n\t\t\tSystem.out.println(\"Time of the selection = \" + selectionTime);\n\t\t}\n\t\tout.flush();\n\t}\n\n\tint nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tlong nextLong() throws IOException {\n\t\tin.nextToken();\n\t\treturn (long) in.nval;\n\t}\n\n\tString nextString() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.nval;\n\t}\n\n\tmyLib lib = new myLib();\n\n\tvoid solve() throws IOException {\n\t\tint x1 = nextInt(), y1 = nextInt(), z1 = nextInt();\n\t\tint x2 = nextInt(), y2 = nextInt(), z2 = nextInt();\n\t\tint c = 0;\n\t\tif (x1 == x2) c++;\n\t\tif (y1 == y2) c++;\n\t\tif (z1 == z2) c++;\n\t\tif (c >= 1) out.println(\"YES\"); else out.println(\"NO\");\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a699c24c855bf9e99dfa748fe1ebf304", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "package solution;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int[] a = new int[3];\n int[] b = new int[3];\n\n for (int i = 0; i < 3; i++) {\n a[i] = in.nextInt();\n }\n for (int i = 0; i < 3; i++) {\n b[i] = in.nextInt();\n }\n\n\n \n if (a[0]!=b[0] && a[1]!=b[1] && a[2]!=b[2])\n {\n out.print(\"NO\");\n } else {\n out.print(\"YES\");\n }\n\n out.flush();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7185841c931b40d17a40347e3ea95749", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "package solution;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int[] a = new int[3];\n int[] b = new int[3];\n\n for (int i = 0; i < 3; i++) {\n a[i] = in.nextInt();\n }\n for (int i = 0; i < 3; i++) {\n b[i] = in.nextInt();\n }\n\n\n \n if (a[0]!=b[0] && a[1]!=b[1] && a[2]!=b[2])\n {\n out.print(\"NO\");\n } else {\n out.print(\"YES\");\n }\n\n out.flush();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "88a1380fa333149b32b5e3c649815c3d", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class OBA\n{\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n long num = scan.nextLong();\n System.out.println(\"\"+prog(num));\n }\n \n public static long genUnos(long n){\n long res=0;\n /*for(long i=1;i <= n;i++){\n res=Math.pow(10,i-1);\n }*/\n res=(long)(Math.pow(10,n)-1)/9;\n return res;\n }\n \n public static long prog(long n){\n long total=0;\n long temp=n;\n long sec=0;\n long signo=0;\n long valuno=0;\n while(n-sec!=0){\n long tam=(long)((Math.log10(Math.abs(temp)))+1);\n // System.out.println(\"tama\u00f1o\"+tam);\n int a=genUnos(1+tam);\n int b=a/10;\n if(a-temp> temp-b valuno=a;\n else valuno=b;\n // signo=(valuno*temp)/(long)Math.abs(valuno*temp);//% 10;\n if(temp>0){\n sec=sec+valuno;\n temp=temp-valuno;\n }else{\n sec=sec-valuno;\n temp=temp+valuno;\n }\n \n total=total+(long)((Math.log10(valuno)+1));\n }\n return total;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fcf875bae4ba965074e106465a71952b", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class OBA\n{\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n long num = scan.nextLong();\n System.out.println(\"\"+prog(num));\n }\n \n public static long genUnos(long n){\n long res=0;\n /*for(long i=1;i <= n;i++){\n res=Math.pow(10,i-1);\n }*/\n res=(long)(Math.pow(10,n)-1)/9;\n return res;\n }\n \n public static long prog(long n){\n long total=0;\n long temp=n;\n long sec=0;\n long signo=0;\n long valuno=0;\n while(n-sec!=0){\n long tam=(long)(Math.log10(Math.abs(temp)))+1);\n // System.out.println(\"tama\u00f1o\"+tam);\n if(temp%(int)Math.pow(10,tam)>=5) valuno=genUnos(1+tam);\n else valuno=genUnos(tam);\n // signo=(valuno*temp)/(long)Math.abs(valuno*temp);//% 10;\n if(temp>0){\n sec=sec+valuno;\n temp=temp-valuno;\n }else{\n sec=sec-valuno;\n temp=temp+valuno;\n }\n \n total=total+(long)(Math.log10(valuno)+1));\n }\n return total;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e7f4845ce1ea3cff4c094cb966e5fa66", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\nimport java.lang.Math.*;\npublic class Main_C {\n\tstatic long n;\n\tprivate static Scanner enter;\n\t\n\tstatic long[] a;\n\tpublic static void main(String[] args) {\n\t\tenter=new Scanner(System.in);\n\t\tn=enter.nextLong();\n\t\ta=new long[20];\n\t\ta[1] = 1;\n\t for(int i = 2;i <= 16 ;i ++ ) {\n\t a[i] = a[i-1] *10 + 1;\n\t }\n\t System.out.println(sol(n));\n\t}\n\tstatic int sol (long l) {\n\t\tint i = 16;\n\t\tint r = 0;\n\t\tif(l <= 11) {\n\t\t\treturn (int) Math.min(l,2+11-l);\n\t\t}\n\t\twhile(a[i-1] > l)i--;\n\t r = (int) (l/a[i-1]) *(i-1) + sol(l%(a[i-1]));\n\t if(2*l temp-getUnos(tam)) valuno=genUnos(1+tam);\n else valuno=genUnos(tam);\n // signo=(valuno*temp)/(long)Math.abs(valuno*temp);//% 10;\n if(temp>0){\n sec=sec+valuno;\n temp=temp-valuno;\n }else{\n sec=sec-valuno;\n temp=temp+valuno;\n }\n \n total=total+(long)((Math.log10(valuno)+1));\n }\n return total;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4759ff6e27eba629f3357233fbc425b6", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class TaskB {\n\tpublic static Scanner in = new Scanner(System.in);\n\t\n\tpublic static void main(String[] args){\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\t\tint time = 0;\n\t\tint n1 , n2;\n\t\tint m1, m2;\n\t\tn1 = a/(m*k) + 1;\n\t\tn2 = b/(m*k)+1 ;\n\t\tif(a %(m*k) == 0 ) n1--;\n\t\tif(b%(m*k) == 0) n2--;\n\t\tm1 = (a - (n1-1)* m* k)/k + 1 ;\n\t\tm2 = (b - (n2-1)*m*k)/k + 1;\n\t\tif((a - (n1-1)* m* k)%k == 0 ) m1--;\n\t\tif((b - (n2-1)*m*k)%k == 0) m2--;\n\t\tif(n1 > n2){\n\t\t\tif(Math.abs((n1 - n2)) < n-n1 + n2 ) time +=Math.abs((n1 - n2))*15;\n\t\t\telse\n\t\t\t\ttime +=(n-n1 + n2)*15;\n\t\t}else\n\t\t\tif(Math.abs((n1 - n2)) < n+n1 - n2 ) time +=Math.abs((n1 - n2))*15;\n\t\t\telse\n\t\t\t\ttime +=(n+n1 - n2)*15;\n\t\tif(n1 != n2){\n\t\t\tif(m1 > 3) time+= (10 + m1-1);\n\t\t\telse time += (5 * (m1-1));\n\t\t\tif(m2 > 3) time+= (10 + m2-1);\n\t\t\telse time += (5 * (m2-1));\n\t\t}else {\n\t\t\t\n\t\t\tif(Math.abs(m1- m2) > 2) time+= (10 + Math.abs(m1- m2));\n\t\t\telse time += (5 * Math.abs(m1- m2));\n\t\t}\n\t\tSystem.out.println(time);\n\t\t\t\n\n\t\t\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63042ccf37786a62540fd947509f388a", "src_uid": "c37b46851abcf7eb472869bd1ab9f793", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class CFB {\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 m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint a = in.nextInt()-1;\n\t\tint b = in.nextInt()-1;\n\t\tint homeA = a/(m*k);\n\t\tint homeB = b/(m*k);\n\t\tint floorA = (a%(m*k))/k;\n\t\tint floorB = (b%(m*k))/k;\n\t\tif (homeA==homeB&&floorA==floorB){\n\t\t\tSystem.out.println(0);\n\t\t} else if (homeA==homeB){\n\t\t\tint d = Math.abs(floorA-floorB);\n\t\t\tSystem.out.println(Math.min(10+d, 5*d));\n\t\t} else {\n\t\t\tint down = Math.min(10+floorA, 5*floorA);\n\t\t\tint betw = -1;\n\t\t\tif (homeA>homeB){\n\t\t\t\tbetw = Math.min(homeA-homeB, homeB+n-homeA);\n\t\t\t} else {\n\t\t\t\tbetw = Math.min(homeB-homeA, homeA+n-homeB);\n\t\t\t}\n\t\t\tint up = Math.min(10+floorB, 5*floorB);\n\t\t\tSystem.out.println(down+betw*15+up);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cea21a0dcb67cfd6c72dc6f6a55722f9", "src_uid": "c37b46851abcf7eb472869bd1ab9f793", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * Created by boris on 26.03.2016.\n */\npublic class TaskB {\n public static void main(String[] args) throws IOException {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n String[] tmp = reader.readLine().split(\"\\\\s\");\n\n int pods = Integer.parseInt(tmp[0]);\n int florsc = Integer.parseInt(tmp[1]);\n int doorsc = Integer.parseInt(tmp[2]);\n\n String[] tmp1 = reader.readLine().split(\"\\\\s\");\n\n int fr = Integer.parseInt(tmp1[0]);\n int to = Integer.parseInt(tmp1[1]);\n\n int frPod = (int) Math.ceil(fr*1.0/doorsc/florsc);\n int frFlor = (int) Math.ceil((fr*1.0-(frPod-1)*(florsc*doorsc))/doorsc);\n\n int toPod = (int) Math.ceil(to*1.0/doorsc/florsc);\n int toFlor = (int) Math.ceil((to*1.0-(toPod-1)*(florsc*doorsc))/doorsc);\n\n int time = 0;\n if (frPod == toPod) {\n int florsToGo = Math.abs(toFlor-frFlor);\n\n if (florsToGo < 3) {\n time += florsToGo*5;\n } else {\n time += 10;\n time += florsToGo;\n }\n } else {\n int florsToGo1 = toFlor-1;\n int florsToGo2 = frFlor-1;\n\n int podsToGo = Math.min(Math.abs(toPod-frPod), pods-Math.max(toPod, frPod)+Math.min(toPod, frPod));\n\n if (florsToGo1 < 3) {\n time += florsToGo1*5;\n } else {\n time += 10;\n time += florsToGo1;\n }\n\n if (florsToGo2 < 3) {\n time += florsToGo2*5;\n } else {\n time += 10;\n time += florsToGo2;\n }\n\n time += podsToGo*15;\n }\n\n System.out.println(time);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00b8722337ccbc0244df4d680c634ec3", "src_uid": "c37b46851abcf7eb472869bd1ab9f793", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class b1 {\n\tBufferedReader br;\n\tStringTokenizer in;\n\tPrintWriter out;\n\n\tpublic String nextToken() throws IOException {\n\t\twhile (in == null || !in.hasMoreTokens()) {\n\t\t\tin = new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn in.nextToken();\n\t}\n\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew b1().run();\n\t}\n\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint k = nextInt();\n\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\n\t\tint n1 = (a + m * k - 1) / (m * k);\n\t\tint n2 = (b + m * k - 1) / (m * k);\n\n\t\tint fl1 = (a - (n1 - 1) * m * k + k - 1) / k;\n\t\tint fl2 = (b - (n2 - 1) * m * k + k - 1) / k;\n\n\t\tif (n1 == n2) {\n\t\t\tout.println(Math.min(Math.abs(fl1 - fl2) * 5, 10 + Math.abs(fl1 - fl2)));\n\t\t} else {\n\t\t\tlong cur_ans = Math.min((fl1 - 1) * 5, 10 + fl1 - 1);\n\n\t\t\tcur_ans += Math.min(Math.abs(n1 - n2) * 15, (n - Math.abs(n1 - n2)) * 15);\n\n\t\t\tout.println(cur_ans + Math.min((fl2 - 1) * 5, (fl2 - 1) + 10));\n\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(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\tSystem.exit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3574c229272f37a0c19daa29485850e5", "src_uid": "c37b46851abcf7eb472869bd1ab9f793", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by zhengyanglzy on 2017/6/24.\n */\npublic class Main {\n private static final int MAXIMUM_IND = 65;\n private static final long[] POWER;\n private static final long[] POWER_SUM;\n\n static {\n POWER = new long[MAXIMUM_IND];\n POWER_SUM = new long[MAXIMUM_IND];\n POWER[0] = POWER_SUM[0] = 0;\n POWER[1] = POWER_SUM[1] = 1;\n for (int i = 2; i < MAXIMUM_IND; ++i) {\n POWER[i] = POWER[i - 1] * 2;\n POWER_SUM[i] = POWER_SUM[i - 1] + POWER[i];\n }\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n while (sc.hasNext()) {\n long houseNum = sc.nextLong();\n long k = sc.nextLong();\n if (k == 1) {\n System.out.println(1);\n continue;\n } else if (k == 2) {\n System.out.println(houseNum);\n continue;\n }\n System.out.println(1 + findLabel(houseNum - 2, k - 2));\n }\n }\n\n static long findLabel(long houseNum, long k) {\n long medium = (houseNum + 1) / 2;\n if (k == 1) {\n return medium;\n }\n k -= 1;\n int ind;\n for (ind = 1; k > 2 * POWER_SUM[ind]; ++ind) {\n k -= 2 * POWER_SUM[ind];\n }\n if (k <= POWER[ind] && POWER_SUM[ind - 1] + k <= medium - 1) {\n // left\n return findLabel(medium - 1, POWER_SUM[ind - 1] + k);\n }\n // right\n if (POWER_SUM[ind - 1] + k > medium - 1) {\n return medium + findLabel(houseNum - medium, POWER_SUM[ind - 1]+ k - (medium - 1 - POWER_SUM[ind - 1]));\n }\n return medium + findLabel(houseNum - medium, POWER_SUM[ind - 1] + k - POWER[ind]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2e21bddca3288fd3cc74ee61435a76b0", "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n/**\n * Created by zhengyanglzy on 2017/6/24.\n */\npublic class Main {\n private static final int MAXIMUM_IND = 65;\n private static final long[] POWER;\n private static final long[] POWER_SUM;\n private static final Map SPACE;\n static Random random = new Random(System.currentTimeMillis());\n\n static {\n POWER = new long[MAXIMUM_IND];\n POWER_SUM = new long[MAXIMUM_IND];\n POWER[0] = POWER_SUM[0] = 0;\n POWER[1] = POWER_SUM[1] = 1;\n for (int i = 2; i < MAXIMUM_IND; ++i) {\n POWER[i] = POWER[i - 1] * 2;\n POWER_SUM[i] = POWER_SUM[i - 1] + POWER[i];\n }\n SPACE = new HashMap();\n SPACE.put(0L, 0L);\n SPACE.put(1L, 0L);\n SPACE.put(2L, 0L);\n }\n\n public static void main(String[] args) {\n // testSO(5000);\n // compare(51, 400);\n Scanner sc = new Scanner(System.in);\n while (sc.hasNext()) {\n long houseNum = sc.nextLong();\n long k = sc.nextLong();\n System.out.println(cal(houseNum, k));\n }\n }\n\n public static void compare(int start, int end) {\n for (int i = start; i <= end; ++i) {\n List res = generate(i);\n assert res.size() == i;\n boolean isMatch = true;\n for (int j = 0; j < res.size(); ++j) {\n long got = cal(i + 2, j + 3);\n long expected = res.get(j) + 1;\n if (expected != got) {\n isMatch = false;\n System.err.printf(\"(%d, %d) expected %d, got %d\\n\", i + 2, j + 3, expected, got);\n }\n }\n if (!isMatch) {\n break;\n }\n System.out.printf(\"complete %d\\n\", i);\n }\n System.out.println(\"over\");\n }\n\n public static void testSO(int casenum) {\n while (casenum -- > 0) {\n long n = random.nextLong();\n long k = random.nextLong();\n if (k > n) {\n long tmp = n;\n n = k;\n k = tmp;\n }\n try {\n findLabel(n, k);\n } catch (StackOverflowError e) {\n System.err.printf(\"%d %d\", n, k);\n break;\n }\n }\n System.out.println(\"over\");\n }\n\n public static List generate(int houseNum) {\n TreeSet segs = new TreeSet();\n segs.add(new Seg(1, houseNum));\n List ret = new ArrayList();\n while (!segs.isEmpty()) {\n Seg seg = segs.first();\n segs.remove(seg);\n int pos = (seg.length + 1) / 2 + seg.start - 1;\n ret.add(pos);\n if (pos - seg.start > 0) {\n segs.add(new Seg(seg.start, pos - seg.start));\n }\n if (seg.length + seg.start - pos - 1> 0) {\n segs.add(new Seg(pos + 1, seg.length + seg.start - pos - 1));\n }\n }\n return ret;\n }\n\n static long cal(long houseNum, long k) {\n if (k == 1) {\n return 1;\n\n } else if (k == 2) {\n return 2;\n }\n return 1 + findLabel(houseNum - 2, k - 2);\n }\n\n static long findSpace(long num) {\n if (SPACE.containsKey(num)) {\n return SPACE.get(num);\n }\n long medium = (num + 1) / 2;\n long res = 1 + findSpace(medium - 1) + findSpace(num - medium);\n SPACE.put(num, res);\n return res;\n }\n\n static long findLabel(long houseNum, long k) {\n // System.out.printf(\"%d %d\\n\", houseNum, k);\n long medium = (houseNum + 1) / 2;\n if (k == 1) {\n return medium;\n }\n /*\n long totalSpace = findSpace(houseNum);\n if (totalSpace < k) {\n // \u6162\u6162\u586b\n if (totalSpace == 0) {\n return k;\n }\n k -= totalSpace;\n long left = medium - 1 - findSpace(medium - 1);\n if (k <= left) {\n return findLabel(medium - 1, k + findSpace(medium - 1));\n }\n return medium + findLabel(houseNum - medium, k - left + findSpace(houseNum - medium));\n }*/\n k -= 1;\n Part leftPart = new Part(medium - 1);\n Part rightPart = new Part(houseNum - medium);\n long leftTotal = 0;\n long rightTotal = 0;\n while (true) {\n long left = leftPart.peek();\n long right = rightPart.peek();\n if (left == 0 && right == 0) {\n break;\n }\n if (k > left + right) {\n k -= left + right;\n leftTotal += left;\n rightTotal += right;\n leftPart.split();\n rightPart.split();\n continue;\n }\n leftPart.collapse();\n rightPart.collapse();\n TreeSet set = new TreeSet();\n set.addAll(leftPart.segs.keySet());\n set.addAll(rightPart.segs.keySet());\n for (long len : set.descendingSet()) {\n if (leftPart.segs.containsKey(len)) {\n if (leftPart.segs.get(len) >= k) {\n return findLabel(medium - 1, leftTotal + k);\n } else {\n k -= leftPart.segs.get(len);\n leftTotal += leftPart.segs.get(len);\n }\n }\n if (rightPart.segs.containsKey(len)) {\n if (rightPart.segs.get(len) >= k) {\n return medium + findLabel(houseNum - medium, rightTotal + k);\n } else {\n k -= rightPart.segs.get(len);\n rightTotal += rightPart.segs.get(len);\n }\n }\n }\n }\n // \u53ea\u52691\u548c2\n if (medium - 1 - leftTotal >= k) {\n return findLabel(medium - 1, leftTotal + k);\n }\n return medium + findLabel(houseNum - medium, rightTotal + k - (medium - 1 - leftTotal));\n }\n\n static class Part {\n Map segs;\n\n Part(long num) {\n segs = new HashMap();\n segs.put(num, 1L);\n }\n\n void split() {\n Map newMap = new HashMap();\n for (Map.Entry entry : segs.entrySet()) {\n if (entry.getKey() <= 2) {\n update(newMap, entry.getKey(), entry.getValue());\n continue;\n }\n long medium = (entry.getKey() + 1) / 2;\n update(newMap, medium - 1, entry.getValue());\n update(newMap, entry.getKey() - medium, entry.getValue());\n }\n segs = newMap;\n }\n\n long peek() {\n long ret = 0;\n for (Map.Entry entry : segs.entrySet()) {\n if (entry.getKey() > 2) {\n ret += entry.getValue();\n }\n }\n return ret;\n }\n\n void collapse() {\n Map newMap = new HashMap();\n for (Map.Entry entry : segs.entrySet()) {\n update(newMap, (entry.getKey() + 1) / 2, entry.getValue());\n }\n segs = newMap;\n }\n\n static void update(Map map, long key, long inc) {\n if (!map.containsKey(key)) {\n map.put(key, 0L);\n }\n map.put(key, map.get(key) + inc);\n }\n }\n\n static class Seg implements Comparable {\n int start;\n int length;\n\n public Seg(int start, int length) {\n this.start = start;\n this.length = length;\n }\n\n public int compareTo(Seg o) {\n int diff = (length - 1) / 2 - (o.length -1) / 2;\n if (diff != 0) {\n return -diff;\n }\n return start - o.start;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "403d102347ffb40f1f90661fdbd80abf", "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.util.Random;\nimport java.util.Scanner;\n\n/**\n * Created by zhengyanglzy on 2017/6/24.\n */\npublic class Main {\n private static final int MAXIMUM_IND = 65;\n private static final long[] POWER;\n private static final long[] POWER_SUM;\n static Random random = new Random(System.currentTimeMillis());\n\n static {\n POWER = new long[MAXIMUM_IND];\n POWER_SUM = new long[MAXIMUM_IND];\n POWER[0] = POWER_SUM[0] = 0;\n POWER[1] = POWER_SUM[1] = 1;\n for (int i = 2; i < MAXIMUM_IND; ++i) {\n POWER[i] = POWER[i - 1] * 2;\n POWER_SUM[i] = POWER_SUM[i - 1] + POWER[i];\n }\n }\n\n public static void main(String[] args) {\n // test(5000);\n Scanner sc = new Scanner(System.in);\n while (sc.hasNext()) {\n long houseNum = sc.nextLong();\n long k = sc.nextLong();\n if (k == 1) {\n System.out.println(1);\n continue;\n } else if (k == 2) {\n System.out.println(houseNum);\n continue;\n }\n System.out.println(1 + findLabel(houseNum - 2, k - 2));\n }\n }\n\n public static void test(int casenum) {\n while (casenum -- > 0) {\n long n = random.nextLong();\n long k = random.nextLong();\n if (k > n) {\n long tmp = n;\n n = k;\n k = tmp;\n }\n try {\n findLabel(n, k);\n } catch (StackOverflowError e) {\n System.err.printf(\"%d %d\", n, k);\n break;\n }\n }\n System.out.println(\"over\");\n }\n\n static long findLabel(long houseNum, long k) {\n //System.out.printf(\"%d %d\\n\", houseNum, k);\n long medium = (houseNum + 1) / 2;\n if (k == 1) {\n return medium;\n }\n k -= 1;\n Part left = new Part(0, medium - 1);\n Part right = new Part(medium, houseNum - medium);\n boolean strict = left.houseNum % 2 == 0 && right.houseNum - left.houseNum == 1;\n if (left.houseNum <= 2) {\n if (strict && k == 1) {\n return right.start + findLabel(right.houseNum, k);\n }\n if (k - (strict ? 1 : 0) <= left.houseNum) {\n return k - (strict ? 1 : 0);\n }\n return right.start + findLabel(right.houseNum, k - left.houseNum);\n }\n if (strict) {\n Part tmp = left;\n left = right;\n right = tmp;\n }\n int ind;\n for (ind = 1; k > 2 * POWER_SUM[ind]; ++ind);\n k -= 2 * POWER_SUM[ind - 1];\n if (left.houseNum - POWER_SUM[ind - 1] <= 2 && k <= left.houseNum - POWER_SUM[ind - 1]) {\n // \u6b64\u65f6\u4e0d\u6ee1\u8db3\u89c4\u5f8b\n return left.start + findLabel(left.houseNum, POWER_SUM[ind - 1] + k);\n }\n // if (k <= 2 && k == left.houseNum - POWER_SUM[ind - 1])\n if (k <= POWER[ind] && POWER_SUM[ind - 1] + k <= left.houseNum) {\n // left\n return left.start + findLabel(left.houseNum, POWER_SUM[ind - 1] + k);\n }\n // right\n long newK = POWER_SUM[ind - 1] + k - POWER[ind];\n if (POWER_SUM[ind - 1] + k > left.houseNum) {\n // \u5de6\u8fb9\u5269\u4f59\u7684\u623f\u5b50\u4e0d\u4e00\u5b9a\u591fPOWER[ind]\n newK = POWER_SUM[ind - 1]+ k - (left.houseNum - POWER_SUM[ind - 1]);\n }\n return right.start + findLabel(right.houseNum, newK);\n }\n\n static class Part {\n long start;\n long houseNum;\n\n Part(long start, long houseNum) {\n this.start = start;\n this.houseNum = houseNum;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "06eea4c0be3a971fdaee4373cb41a89e", "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by zhengyanglzy on 2017/6/24.\n */\npublic class Main {\n private static final int MAXIMUM_IND = 65;\n private static final long[] POWER;\n private static final long[] POWER_SUM;\n\n static {\n POWER = new long[MAXIMUM_IND];\n POWER_SUM = new long[MAXIMUM_IND];\n POWER[0] = POWER_SUM[0] = 0;\n POWER[1] = POWER_SUM[1] = 1;\n for (int i = 2; i < MAXIMUM_IND; ++i) {\n POWER[i] = POWER[i - 1] * 2;\n POWER_SUM[i] = POWER_SUM[i - 1] + POWER[i];\n }\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n while (sc.hasNext()) {\n long houseNum = sc.nextLong();\n long k = sc.nextLong();\n if (k == 1) {\n System.out.println(1);\n continue;\n } else if (k == 2) {\n System.out.println(houseNum);\n continue;\n }\n System.out.println(1 + findLabel(houseNum - 2, k - 2));\n }\n }\n\n static long findLabel(long houseNum, long k) {\n long medium = (houseNum + 1) / 2;\n if (k == 1) {\n return medium;\n }\n k -= 1;\n Part left = new Part(0, medium - 1);\n Part right = new Part(medium, houseNum - medium);\n boolean strict = left.houseNum % 2 == 0 && right.houseNum - left.houseNum == 1;\n if (left.houseNum <= 2) {\n if (strict && k == 1) {\n return right.start + findLabel(right.houseNum, k);\n }\n if (k - (strict ? 1 : 0) <= left.houseNum) {\n return k - (strict ? 1 : 0);\n }\n return right.start + findLabel(right.houseNum, k - left.houseNum);\n }\n if (strict) {\n Part tmp = left;\n left = right;\n right = tmp;\n }\n int ind;\n for (ind = 1; k > 2 * POWER_SUM[ind]; ++ind) {\n }\n k -= 2 * POWER_SUM[ind - 1];\n if (left.houseNum - POWER_SUM[ind - 1] <= 2 && k <= 2) {\n // \u6b64\u65f6\u4e0d\u6ee1\u8db3\u89c4\u5f8b\n return left.start + findLabel(left.houseNum, POWER_SUM[ind - 1] + k);\n }\n // if (k <= 2 && k == left.houseNum - POWER_SUM[ind - 1])\n if (k <= POWER[ind] && POWER_SUM[ind - 1] + k <= left.houseNum) {\n // left\n return left.start + findLabel(left.houseNum, POWER_SUM[ind - 1] + k);\n }\n // right\n long newK = POWER_SUM[ind - 1] + k - POWER[ind];\n if (POWER_SUM[ind - 1] + k > left.houseNum) {\n // \u5de6\u8fb9\u5269\u4f59\u7684\u623f\u5b50\u4e0d\u4e00\u5b9a\u591fPOWER[ind]\n newK = POWER_SUM[ind - 1]+ k - (left.houseNum - POWER_SUM[ind - 1]);\n }\n return right.start + findLabel(right.houseNum, newK);\n }\n\n static class Part {\n long start;\n long houseNum;\n\n Part(long start, long houseNum) {\n this.start = start;\n this.houseNum = houseNum;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b94ffcf012048c39530648f43a4530d0", "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage pkg124d;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport static java.lang.Integer.max;\nimport static java.lang.Math.abs;\n/**\n *\n * @author Sergey\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n String str = \"\";\n \n try{\n str = reader.readLine();\n } catch(IOException e) {\n e.printStackTrace();\n }\n\n int[] arr = new int[6];\n int t1, t2;\n \n for(int i = 0; i < arr.length -1; i++){\n int index = str.indexOf(\" \");\n arr[i] = Integer.parseInt(str.substring(0, index));\n str = str.substring(index+1);\n }\n \n arr[5] = Integer.parseInt(str);\n \n t1 = arr[2]; t2 = arr[3];\n arr[2] = t1 + t2;\n arr[3] = t2 - t1;\n\n t1 = arr[4]; t2 = arr[5];\n arr[4] = t1 + t2;\n arr[5] = t2 - t1;\n \n arr[0] *= 2;\n arr[1] *= 2;\n \n arr[2]= arr[2] / arr[0] + ((arr[2] > 0)? 1 : 0);\n arr[4] = arr[4] / arr[0] + ((arr[4] > 0)? 1 : 0);\n arr[3] = arr[3] / arr[1] + ((arr[3] > 0)? 1 : 0);\n arr[5] = arr[5] / arr[1] + ((arr[5] > 0)? 1 : 0);\n \n System.out.print(max(abs(arr[5] - arr[3]), abs(arr[4] - arr[2])));\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e8b55f23805dc62ea4493e2e0505fb0", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "package com.company;\n\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 a= in.nextInt(); \n int b= in.nextInt(); \n int x1= in.nextInt(); \n int x2= in.nextInt(); \n int y1= in.nextInt(); \n int y2 = in.nextInt();\n int parity1, parity2;\n\n a *= 2;\n b *= 2;\n\n parity1 = x1;\n parity2 = y1;\n x1 = parity1 + parity2;\n y1 = parity2 - parity1;\n\n parity1 = x2;\n parity2 = y2;\n x2 = parity1 + parity2;\n y2 = parity2 - parity1;\n\n if\n (x1>0) x1 = x1/a+1;\n else\n x1 = x1/a;\n\n if\n (x2>0) x2 = x2/a+1;\n else\n x2 = x2/a;\n\n if\n (y1>0) y1 = y1/b+1;\n else\n y1 = y1/b;\n\n if\n (y2>0) y2 = y2/b+1;\n else\n y2 = y2/b;\n\n System.out.println(Math.max(Math.abs((x2-x1)),Math.abs((y2-y1))));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "95f251f911540d2c3d41edcba0fdc8a9", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "package com.company;\n\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 a= in.nextInt(), b= in.nextInt(), x1= in.nextInt(), x2= in.nextInt(), y1= in.nextInt(), y2 = in.nextInt();\n int parity1, parity2;\n\n a *= 2;\n b *= 2;\n\n parity1 = x1;\n parity2 = y1;\n x1 = parity1 + parity2;\n y1 = parity2 - parity1;\n\n parity1 = x2;\n parity2 = y2;\n x2 = parity1 + parity2;\n y2 = parity2 - parity1;\n\n if \n (x1>0) x1 = x1/a+1;\n else \n x1 = x1/a;\n\n if \n (x2>0) x2 = x2/a+1;\n else \n x2 = x2/a;\n\n if \n (y1>0) y1 = y1/b+1;\n else \n y1 = y1/b;\n\n if \n (y2>0) y2 = y2/b+1;\n else \n y2 = y2/b;\n \n System.out.println(Math.max(Math.abs((x2-x1)),Math.abs((y2-y1))));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fc069aa970688c097f7fb10d79404fb3", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "package round91;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class B {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), k = ni();\n\t\tchar[] s = ns(n);\n\t\tfor(int i = 0;i < n-1 && k > 0;i++){\n\t\t\tif(s[i] == '4' && s[i+1] == '7'){\n\t\t\t\tif(i % 2 == 0){\n\t\t\t\t\ts[i+1] = '4';\n\t\t\t\t\tk--;\n\t\t\t\t}else{\n\t\t\t\t\ts[i] = '7';\n\t\t\t\t\tk--;\n\t\t\t\t\tif(i-1 >= 0 && s[i-1] == '4'){\n\t\t\t\t\t\tk %= 2;\n\t\t\t\t\t\ti = -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(new String(s));\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew B().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50df42e4160ef4788dbdd8560d0ad52e", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class H {\n static final boolean RUN_TIMING = false;\n static char[] inputBuffer = new char[1 << 20];\n static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1 << 20);\n static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n ArrayList pairs = new ArrayList<>();\n ArrayList sets = new ArrayList<>();\n\n public void go() throws IOException {\n // in = new PushbackReader(new BufferedReader(new FileReader(new File(\"test.txt\"))), 1 << 20);\n // out = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n int n = ipar();\n int q = ipar();\n int[] arr = iapar(n);\n int[] pos = new int[n+1];\n for (int i = 0; i < n; i++) {\n pos[arr[i]] = i+1;\n }\n SegmentTree tree = new SegmentTree(pos, n);\n for (int i = 0; i < q; i++) {\n int l = ipar();\n int r = ipar();\n sets.add(tree.query(l, r));\n }\n out.println(n + pairs.size());\n for (long p : pairs) {\n out.print(p/5000);\n out.print(\" \");\n out.println(p%5000);\n }\n for (int x : sets) {\n out.print(x);\n out.print(\" \");\n }\n out.println();\n }\n\n private class SegmentTree {\n private class Node {\n TreeSet indices;\n HashMap map;\n\n public Node() {\n indices = new TreeSet<>();\n map = new HashMap<>();\n }\n }\n\n Node[] tree;\n int n;\n int currIndex;\n\n public SegmentTree(int[] pos, int n) {\n this.n = n;\n tree = new Node[n*4];\n currIndex = n+1;\n build(1, 1, n, pos);\n }\n\n private void build(int v, int tl, int tr, int[] pos) {\n if (tl == tr) {\n tree[v] = new Node();\n tree[v].indices.add(pos[tl]);\n tree[v].map.put((long)pos[tl]*5000 + pos[tl], pos[tl]);\n return;\n }\n int tm = (tl+tr)/2;\n build(v*2, tl, tm, pos);\n build(v*2+1, tm+1, tr, pos);\n tree[v] = new Node();\n tree[v].indices.addAll(tree[v*2].indices);\n tree[v].indices.addAll(tree[v*2+1].indices);\n }\n\n private int query(int v, int tl, int tr, int l, int r) {\n Integer lbObj = tree[v].indices.ceiling(l);\n Integer rbObj = tree[v].indices.floor(r);\n if (lbObj == null || rbObj == null) {\n return 0;\n }\n int lb = lbObj.intValue();\n int rb = rbObj.intValue();\n if (lb > rb) {\n return 0;\n }\n long p = (long)lb*5000 + rb;\n if (tree[v].map.containsKey(p)) {\n return tree[v].map.get(p);\n }\n \n int tm = (tl+tr)/2;\n int lSet = query(v*2, tl, tm, l, r);\n int rSet = query(v*2+1, tm+1, tr, l, r);\n if (lSet == 0) {\n tree[v].map.put(p, rSet);\n return rSet;\n }\n if (rSet == 0) {\n tree[v].map.put(p, lSet);\n return lSet;\n }\n\n p = (long)lSet*5000 + rSet;\n if (tree[v].map.containsKey(p)) {\n return tree[v].map.get(p);\n }\n\n tree[v].map.put(p, currIndex);\n pairs.add(p);\n return currIndex++;\n }\n \n public int query(int l, int r) {\n return query(1, 1, n, l, r);\n }\n }\n\n public int ipar() throws IOException {\n return Integer.parseInt(spar());\n }\n\n public int[] iapar(int n) throws IOException {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = ipar();\n }\n return arr;\n }\n\n public long lpar() throws IOException {\n return Long.parseLong(spar());\n }\n\n public long[] lapar(int n) throws IOException {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = lpar();\n }\n return arr;\n }\n\n public double dpar() throws IOException {\n return Double.parseDouble(spar());\n }\n\n public String spar() throws IOException {\n int len = 0;\n int c;\n do {\n c = in.read();\n } while (Character.isWhitespace(c) && c != -1);\n if (c == -1) {\n throw new NoSuchElementException(\"Reached EOF\");\n }\n do {\n inputBuffer[len] = (char)c;\n len++;\n c = in.read();\n } while (!Character.isWhitespace(c) && c != -1);\n while (c != '\\n' && Character.isWhitespace(c) && c != -1) {\n c = in.read();\n }\n if (c != -1 && c != '\\n') {\n in.unread(c);\n }\n return new String(inputBuffer, 0, len);\n }\n\n public String linepar() throws IOException {\n int len = 0;\n int c;\n while ((c = in.read()) != '\\n' && c != -1) {\n if (c == '\\r') {\n continue;\n }\n inputBuffer[len] = (char)c;\n len++;\n }\n return new String(inputBuffer, 0, len);\n }\n\n public boolean haspar() throws IOException {\n String line = linepar();\n if (line.isEmpty()) {\n return false;\n }\n in.unread('\\n');\n in.unread(line.toCharArray());\n return true;\n }\n\n public static void main(String[] args) throws IOException {\n long time = 0;\n time -= System.nanoTime();\n new H().go();\n time += System.nanoTime();\n if (RUN_TIMING) {\n System.out.printf(\"%.3f ms%n\", time / 1000000.0);\n }\n out.flush();\n in.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "212158aa4b85adfc0dc9db0ef4d44f4f", "src_uid": "60cf596ad4853ebf3bbf9a96ef5d8791", "difficulty": 3300.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class H {\n static final boolean RUN_TIMING = false;\n static char[] inputBuffer = new char[1 << 20];\n static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1 << 20);\n static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n ArrayList pairs = new ArrayList<>();\n ArrayList sets = new ArrayList<>();\n\n public void go() throws IOException {\n // in = new PushbackReader(new BufferedReader(new FileReader(new File(\"test.txt\"))), 1 << 20);\n // out = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n int n = ipar();\n int q = ipar();\n int[] arr = iapar(n);\n int[] pos = new int[n+1];\n for (int i = 0; i < n; i++) {\n pos[arr[i]] = i+1;\n }\n SegmentTree tree = new SegmentTree(pos, n);\n for (int i = 0; i < q; i++) {\n int l = ipar();\n int r = ipar();\n sets.add(tree.query(l, r));\n }\n out.println(n + pairs.size());\n for (Pair p : pairs) {\n out.print(p.l);\n out.print(\" \");\n out.println(p.r);\n }\n for (int x : sets) {\n out.print(x);\n out.print(\" \");\n }\n out.println();\n }\n\n private class SegmentTree {\n private class Node {\n TreeSet indices;\n\n public Node() {\n indices = new TreeSet<>();\n }\n }\n\n Node[] tree;\n int n;\n int currIndex;\n HashMap map;\n\n public SegmentTree(int[] pos, int n) {\n this.n = n;\n tree = new Node[n*4];\n currIndex = n+1;\n map = new HashMap<>();\n build(1, 1, n, pos);\n }\n\n private void build(int v, int tl, int tr, int[] pos) {\n if (tl == tr) {\n tree[v] = new Node();\n tree[v].indices.add(pos[tl]);\n map.put(new Pair(pos[tl], pos[tl]), pos[tl]);\n return;\n }\n int tm = (tl+tr)/2;\n build(v*2, tl, tm, pos);\n build(v*2+1, tm+1, tr, pos);\n tree[v] = new Node();\n tree[v].indices.addAll(tree[v*2].indices);\n tree[v].indices.addAll(tree[v*2+1].indices);\n }\n\n private int query(int v, int tl, int tr, int l, int r) {\n Integer lbObj = tree[v].indices.ceiling(l);\n Integer rbObj = tree[v].indices.floor(r);\n if (lbObj == null || rbObj == null) {\n return 0;\n }\n int lb = lbObj.intValue();\n int rb = rbObj.intValue();\n Pair p = new Pair(lb, rb);\n if (map.containsKey(p)) {\n return map.get(p);\n }\n \n int tm = (tl+tr)/2;\n int lSet = query(v*2, tl, tm, l, r);\n int rSet = query(v*2+1, tm+1, tr, l, r);\n if (lSet == 0) {\n map.put(p, rSet);\n return rSet;\n }\n if (rSet == 0) {\n map.put(p, lSet);\n return lSet;\n }\n\n p = new Pair(lSet, rSet);\n map.put(p, currIndex);\n pairs.add(p);\n return currIndex++;\n }\n \n public int query(int l, int r) {\n return query(1, 1, n, l, r);\n }\n }\n\n private class Pair {\n int l, r;\n\n public Pair(int l, int r) {\n this.l = l;\n this.r = r;\n }\n\n public int hashCode() {\n return l << 16 + r;\n }\n\n public boolean equals(Object obj) {\n if (obj instanceof Pair) {\n Pair other = (Pair)obj;\n return l == other.l && r == other.r;\n }\n return false;\n }\n }\n\n public int ipar() throws IOException {\n return Integer.parseInt(spar());\n }\n\n public int[] iapar(int n) throws IOException {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = ipar();\n }\n return arr;\n }\n\n public long lpar() throws IOException {\n return Long.parseLong(spar());\n }\n\n public long[] lapar(int n) throws IOException {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = lpar();\n }\n return arr;\n }\n\n public double dpar() throws IOException {\n return Double.parseDouble(spar());\n }\n\n public String spar() throws IOException {\n int len = 0;\n int c;\n do {\n c = in.read();\n } while (Character.isWhitespace(c) && c != -1);\n if (c == -1) {\n throw new NoSuchElementException(\"Reached EOF\");\n }\n do {\n inputBuffer[len] = (char)c;\n len++;\n c = in.read();\n } while (!Character.isWhitespace(c) && c != -1);\n while (c != '\\n' && Character.isWhitespace(c) && c != -1) {\n c = in.read();\n }\n if (c != -1 && c != '\\n') {\n in.unread(c);\n }\n return new String(inputBuffer, 0, len);\n }\n\n public String linepar() throws IOException {\n int len = 0;\n int c;\n while ((c = in.read()) != '\\n' && c != -1) {\n if (c == '\\r') {\n continue;\n }\n inputBuffer[len] = (char)c;\n len++;\n }\n return new String(inputBuffer, 0, len);\n }\n\n public boolean haspar() throws IOException {\n String line = linepar();\n if (line.isEmpty()) {\n return false;\n }\n in.unread('\\n');\n in.unread(line.toCharArray());\n return true;\n }\n\n public static void main(String[] args) throws IOException {\n long time = 0;\n time -= System.nanoTime();\n new H().go();\n time += System.nanoTime();\n if (RUN_TIMING) {\n System.out.printf(\"%.3f ms%n\", time / 1000000.0);\n }\n out.flush();\n in.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce3dd845ae406a1e9933cc0d8666abc0", "src_uid": "60cf596ad4853ebf3bbf9a96ef5d8791", "difficulty": 3300.0} {"lang": "Java 11", "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<>(); add2 = new ArrayList<>();\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\tfor(int i = n-n/sz*sz; i < sz; i++) orig[orig.length-1][i] = 2*n;\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.printf(\"%d %d%n\", add1.get(i), add2.get(i)); }\n\t\tfor(int i : ans) out.print(i + \" \");\n\t\tout.println();\n///\n\t\tif(n != 4096) out.flush();\n\t}\n\tArrayList 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4a90128276d805d8ead51046ec986ab8", "src_uid": "60cf596ad4853ebf3bbf9a96ef5d8791", "difficulty": 3300.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class H {\n static final boolean RUN_TIMING = false;\n static char[] inputBuffer = new char[1 << 20];\n static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1 << 20);\n static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n ArrayList pairs = new ArrayList<>();\n ArrayList sets = new ArrayList<>();\n\n public void go() throws IOException {\n // in = new PushbackReader(new BufferedReader(new FileReader(new File(\"test.txt\"))), 1 << 20);\n // out = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n int n = ipar();\n int q = ipar();\n int[] arr = iapar(n);\n int[] pos = new int[n+1];\n for (int i = 0; i < n; i++) {\n pos[arr[i]] = i+1;\n }\n SegmentTree tree = new SegmentTree(pos, n);\n for (int i = 0; i < q; i++) {\n int l = ipar();\n int r = ipar();\n sets.add(tree.query(l, r));\n }\n out.println(n + pairs.size());\n for (Pair p : pairs) {\n out.print(p.l);\n out.print(\" \");\n out.println(p.r);\n }\n for (int x : sets) {\n out.print(x);\n out.print(\" \");\n }\n out.println();\n }\n\n private class SegmentTree {\n private class Node {\n TreeSet indices;\n\n public Node() {\n indices = new TreeSet<>();\n }\n }\n\n Node[] tree;\n int n;\n int currIndex;\n HashMap map;\n\n public SegmentTree(int[] pos, int n) {\n this.n = n;\n tree = new Node[n*4];\n currIndex = n+1;\n map = new HashMap<>();\n build(1, 1, n, pos);\n }\n\n private void build(int v, int tl, int tr, int[] pos) {\n if (tl == tr) {\n tree[v] = new Node();\n tree[v].indices.add(pos[tl]);\n map.put(new Pair(pos[tl], pos[tl]), pos[tl]);\n return;\n }\n int tm = (tl+tr)/2;\n build(v*2, tl, tm, pos);\n build(v*2+1, tm+1, tr, pos);\n tree[v] = new Node();\n tree[v].indices.addAll(tree[v*2].indices);\n tree[v].indices.addAll(tree[v*2+1].indices);\n }\n\n private int query(int v, int tl, int tr, int l, int r) {\n Integer lbObj = tree[v].indices.ceiling(l);\n Integer rbObj = tree[v].indices.floor(r);\n if (lbObj == null || rbObj == null) {\n return 0;\n }\n int lb = lbObj.intValue();\n int rb = rbObj.intValue();\n if (lb > rb) {\n return 0;\n }\n Pair p = new Pair(lb, rb);\n if (map.containsKey(p)) {\n return map.get(p);\n }\n \n int tm = (tl+tr)/2;\n int lSet = query(v*2, tl, tm, l, r);\n int rSet = query(v*2+1, tm+1, tr, l, r);\n if (lSet == 0) {\n map.put(p, rSet);\n return rSet;\n }\n if (rSet == 0) {\n map.put(p, lSet);\n return lSet;\n }\n\n p = new Pair(lSet, rSet);\n map.put(p, currIndex);\n pairs.add(p);\n return currIndex++;\n }\n \n public int query(int l, int r) {\n return query(1, 1, n, l, r);\n }\n }\n\n private class Pair {\n int l, r;\n\n public Pair(int l, int r) {\n this.l = l;\n this.r = r;\n }\n\n public int hashCode() {\n return l << 16 + r;\n }\n\n public boolean equals(Object obj) {\n if (obj instanceof Pair) {\n Pair other = (Pair)obj;\n return l == other.l && r == other.r;\n }\n return false;\n }\n }\n\n public int ipar() throws IOException {\n return Integer.parseInt(spar());\n }\n\n public int[] iapar(int n) throws IOException {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = ipar();\n }\n return arr;\n }\n\n public long lpar() throws IOException {\n return Long.parseLong(spar());\n }\n\n public long[] lapar(int n) throws IOException {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = lpar();\n }\n return arr;\n }\n\n public double dpar() throws IOException {\n return Double.parseDouble(spar());\n }\n\n public String spar() throws IOException {\n int len = 0;\n int c;\n do {\n c = in.read();\n } while (Character.isWhitespace(c) && c != -1);\n if (c == -1) {\n throw new NoSuchElementException(\"Reached EOF\");\n }\n do {\n inputBuffer[len] = (char)c;\n len++;\n c = in.read();\n } while (!Character.isWhitespace(c) && c != -1);\n while (c != '\\n' && Character.isWhitespace(c) && c != -1) {\n c = in.read();\n }\n if (c != -1 && c != '\\n') {\n in.unread(c);\n }\n return new String(inputBuffer, 0, len);\n }\n\n public String linepar() throws IOException {\n int len = 0;\n int c;\n while ((c = in.read()) != '\\n' && c != -1) {\n if (c == '\\r') {\n continue;\n }\n inputBuffer[len] = (char)c;\n len++;\n }\n return new String(inputBuffer, 0, len);\n }\n\n public boolean haspar() throws IOException {\n String line = linepar();\n if (line.isEmpty()) {\n return false;\n }\n in.unread('\\n');\n in.unread(line.toCharArray());\n return true;\n }\n\n public static void main(String[] args) throws IOException {\n long time = 0;\n time -= System.nanoTime();\n new H().go();\n time += System.nanoTime();\n if (RUN_TIMING) {\n System.out.printf(\"%.3f ms%n\", time / 1000000.0);\n }\n out.flush();\n in.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8180e04340ccc15cd02f068bf836565a", "src_uid": "60cf596ad4853ebf3bbf9a96ef5d8791", "difficulty": 3300.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Tanks implements Runnable {\n class Point {\n int x;\n int y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n }\n\n Point readPoint() throws IOException {\n int x = nextInt();\n int y = nextInt();\n return new Point(x, y);\n }\n\n private void solve() throws IOException {\n Point A = readPoint();\n Point B = readPoint();\n int n = nextInt();\n Point[] tank = new Point[n];\n double[] alpha = new double[n];\n double[] w = new double[n];\n for (int i = 0; i < n; ++i) {\n tank[i] = readPoint();\n alpha[i] = nextDouble();\n if (alpha[i] > Math.PI) alpha[i] -= 2 * Math.PI;\n w[i] = nextDouble();\n }\n int canSuffer = nextInt();\n double[] maxHit = new double[n + 1];\n for (int i = 0; i < n; ++i) {\n maxHit[i] = processTank(A, B, tank[i], alpha[i], w[i]);\n }\n Arrays.sort(maxHit);\n writer.println(maxHit[n - canSuffer]);\n }\n\n private double processTank(Point A, Point B, Point tank, double alpha, double w) {\n if (w == 0)\n return 0;\n return Math.max(process(A, B, tank, alpha, w), process(A, B, tank, alpha, -w));\n }\n\n private double process(Point a, Point b, Point tank, double alpha, double w) {\n double alphaA = Math.atan2(a.y - tank.y, a.x - tank.x);\n double alphaB = Math.atan2(b.y - tank.y, b.x - tank.x);\n if (Math.signum(alphaA - alpha) != Math.signum(w)) alphaA += Math.PI * 2 * Math.signum(w);\n if (Math.signum(alphaB - alpha) != Math.signum(w)) alphaB += Math.PI * 2 * Math.signum(w);\n double tA = (alphaA - alpha) / w;\n double tB = (alphaB - alpha) / w;\n double dy = b.y - a.y;\n double dx = b.x - a.x;\n double dist = Math.sqrt(dx * dx + dy * dy);\n if (tB <= tA) {\n return dist / tB;\n } else {\n double left = 0;\n double right = 1;\n double res = dist / tB;\n for (int i = 0; i < 300; ++i) {\n double middle2;\n double tM2;\n {\n middle2 = (left + 2 * right) / 3;\n double x = a.x + middle2 * dx;\n double y = a.y + middle2 * dy;\n double alphaM2 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM2 - alpha) != Math.signum(w)) alphaM2 += Math.PI * 2 * Math.signum(w);\n tM2 = (alphaM2 - alpha) / w;\n }\n double middle1;\n double tM1;\n {\n middle1 = (2 * left + right) / 3;\n double x = a.x + middle1 * dx;\n double y = a.y + middle1 * dy;\n double alphaM1 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM1 - alpha) != Math.signum(w)) alphaM1 += Math.PI * 2 * Math.signum(w);\n tM1 = (alphaM1 - alpha) / w;\n }\n double valM1 = dist * middle1 / tM1;\n double valM2 = dist * middle2 / tM2;\n res = Math.max(res, valM1);\n res = Math.max(res, valM2);\n if (valM1 > valM2) {\n right = middle2;\n } else {\n left = middle1;\n }\n }\n return res;\n }\n }\n\n public static void main(String[] args) {\n new Tanks().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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f7914378225a922541959511973c107c", "src_uid": "38c14ab8b9c5107c2a2f70a35f166d8b", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import com.sun.tools.corba.se.idl.constExpr.BooleanNot;\nimport com.sun.xml.internal.bind.v2.model.core.MaybeElement;\n\nimport 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 Tanks implements Runnable {\n class Point {\n int x;\n int y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n }\n\n Point readPoint() throws IOException {\n int x = nextInt();\n int y = nextInt();\n return new Point(x, y);\n }\n\n private void solve() throws IOException {\n Point A = readPoint();\n Point B = readPoint();\n int n = nextInt();\n Point[] tank = new Point[n];\n double[] alpha = new double[n];\n double[] w = new double[n];\n for (int i = 0; i < n; ++i) {\n tank[i] = readPoint();\n alpha[i] = nextDouble();\n if (alpha[i] > Math.PI) alpha[i] -= 2 * Math.PI;\n w[i] = nextDouble();\n }\n int canSuffer = nextInt();\n double[] maxHit = new double[n + 1];\n for (int i = 0; i < n; ++i) {\n maxHit[i] = processTank(A, B, tank[i], alpha[i], w[i]);\n }\n Arrays.sort(maxHit);\n writer.println(maxHit[n - canSuffer]);\n }\n\n private double processTank(Point A, Point B, Point tank, double alpha, double w) {\n if (w == 0)\n return 0;\n return Math.max(process(A, B, tank, alpha, w), process(A, B, tank, alpha, -w));\n }\n\n private double process(Point a, Point b, Point tank, double alpha, double w) {\n double alphaA = Math.atan2(a.y - tank.y, a.x - tank.x);\n double alphaB = Math.atan2(b.y - tank.y, b.x - tank.x);\n if (Math.signum(alphaA - alpha) != Math.signum(w)) alphaA += Math.PI * 2 * Math.signum(w);\n if (Math.signum(alphaB - alpha) != Math.signum(w)) alphaB += Math.PI * 2 * Math.signum(w);\n double tA = (alphaA - alpha) / w;\n double tB = (alphaB - alpha) / w;\n double dy = b.y - a.y;\n double dx = b.x - a.x;\n double dist = Math.sqrt(dx * dx + dy * dy);\n if (tB <= tA) {\n return dist / tB;\n } else {\n double left = 0;\n double right = 1;\n double res = dist / tB;\n for (int i = 0; i < 300; ++i) {\n double middle2;\n double tM2;\n {\n middle2 = (left + 2 * right) / 3;\n double x = a.x + middle2 * dx;\n double y = a.y + middle2 * dy;\n double alphaM2 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM2 - alpha) != Math.signum(w)) alphaM2 += Math.PI * 2 * Math.signum(w);\n tM2 = (alphaM2 - alpha) / w;\n }\n double middle1;\n double tM1;\n {\n middle1 = (2 * left + right) / 3;\n double x = a.x + middle1 * dx;\n double y = a.y + middle1 * dy;\n double alphaM1 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM1 - alpha) != Math.signum(w)) alphaM1 += Math.PI * 2 * Math.signum(w);\n tM1 = (alphaM1 - alpha) / w;\n }\n double valM1 = dist * middle1 / tM1;\n double valM2 = dist * middle2 / tM2;\n res = Math.max(res, valM1);\n res = Math.max(res, valM2);\n if (valM1 > valM2) {\n right = middle2;\n } else {\n left = middle1;\n }\n }\n return res;\n }\n }\n\n public static void main(String[] args) {\n new Tanks().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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5c4f8bd70f1c23ae97614a1bdf88d5b7", "src_uid": "38c14ab8b9c5107c2a2f70a35f166d8b", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Tanks implements Runnable {\n class Point {\n int x;\n int y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n }\n\n Point readPoint() throws IOException {\n int x = nextInt();\n int y = nextInt();\n return new Point(x, y);\n }\n\n private void solve() throws IOException {\n Point A = readPoint();\n Point B = readPoint();\n int n = nextInt();\n Point[] tank = new Point[n];\n double[] alpha = new double[n];\n double[] w = new double[n];\n for (int i = 0; i < n; ++i) {\n tank[i] = readPoint();\n alpha[i] = nextDouble();\n if (alpha[i] > Math.PI) alpha[i] -= 2 * Math.PI;\n w[i] = nextDouble();\n }\n int canSuffer = nextInt();\n double[] maxHit = new double[n + 1];\n for (int i = 0; i < n; ++i) {\n maxHit[i] = processTank(A, B, tank[i], alpha[i], w[i]);\n }\n Arrays.sort(maxHit);\n writer.println(maxHit[n - canSuffer]);\n }\n\n private double processTank(Point A, Point B, Point tank, double alpha, double w) {\n if (w == 0)\n return 0;\n return Math.max(process(A, B, tank, alpha, w), process(A, B, tank, alpha, -w));\n }\n\n private double process(Point a, Point b, Point tank, double alpha, double w) {\n double alphaA = Math.atan2(a.y - tank.y, a.x - tank.x);\n double alphaB = Math.atan2(b.y - tank.y, b.x - tank.x);\n if (Math.signum(alphaA - alpha) != Math.signum(w)) alphaA += Math.PI * 2 * Math.signum(w);\n if (Math.signum(alphaB - alpha) != Math.signum(w)) alphaB += Math.PI * 2 * Math.signum(w);\n double tA = (alphaA - alpha) / w;\n double tB = (alphaB - alpha) / w;\n double dy = b.y - a.y;\n double dx = b.x - a.x;\n double dist = Math.sqrt(dx * dx + dy * dy);\n if (tB <= tA) {\n return dist / tB;\n } else {\n double best = 0;\n double bestVal = 0;\n double res = dist / tB;\n for (int i = 0; i <= 100; ++i) {\n double middle = i / 100.0;\n double x = a.x + middle * dx;\n double y = a.y + middle * dy;\n double alphaM2 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM2 - alpha) != Math.signum(w)) alphaM2 += Math.PI * 2 * Math.signum(w);\n double tM = (alphaM2 - alpha) / w;\n double cur = middle * dist / tM;\n res = Math.max(res, cur);\n if (cur > bestVal) {\n bestVal = cur;\n best = middle;\n }\n }\n double left = Math.max(0, best - 0.03);\n double right = Math.min(1, best + 0.03);\n for (int i = 0; i < 300; ++i) {\n double middle2;\n double tM2;\n {\n middle2 = (left + 2 * right) / 3;\n double x = a.x + middle2 * dx;\n double y = a.y + middle2 * dy;\n double alphaM2 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM2 - alpha) != Math.signum(w)) alphaM2 += Math.PI * 2 * Math.signum(w);\n tM2 = (alphaM2 - alpha) / w;\n }\n double middle1;\n double tM1;\n {\n middle1 = (2 * left + right) / 3;\n double x = a.x + middle1 * dx;\n double y = a.y + middle1 * dy;\n double alphaM1 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM1 - alpha) != Math.signum(w)) alphaM1 += Math.PI * 2 * Math.signum(w);\n tM1 = (alphaM1 - alpha) / w;\n }\n double valM1 = dist * middle1 / tM1;\n double valM2 = dist * middle2 / tM2;\n res = Math.max(res, valM1);\n res = Math.max(res, valM2);\n if (valM1 > valM2) {\n right = middle2;\n } else {\n left = middle1;\n }\n }\n return res;\n }\n }\n\n public static void main(String[] args) {\n new Tanks().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run() {\n try {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8dfd98e00e741e3a740ac94613ff0cd4", "src_uid": "38c14ab8b9c5107c2a2f70a35f166d8b", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Tanks implements Runnable {\n class Point {\n int x;\n int y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n }\n\n Point readPoint() throws IOException {\n int x = nextInt();\n int y = nextInt();\n return new Point(x, y);\n }\n\n private void solve() throws IOException {\n Point A = readPoint();\n Point B = readPoint();\n int n = nextInt();\n Point[] tank = new Point[n];\n double[] alpha = new double[n];\n double[] w = new double[n];\n for (int i = 0; i < n; ++i) {\n tank[i] = readPoint();\n alpha[i] = nextDouble();\n if (alpha[i] > Math.PI) alpha[i] -= 2 * Math.PI;\n w[i] = nextDouble();\n }\n int canSuffer = nextInt();\n double[] maxHit = new double[n + 1];\n for (int i = 0; i < n; ++i) {\n maxHit[i] = processTank(A, B, tank[i], alpha[i], w[i]);\n }\n Arrays.sort(maxHit);\n writer.println(maxHit[n - canSuffer]);\n }\n\n private double processTank(Point A, Point B, Point tank, double alpha, double w) {\n if (w == 0)\n return 0;\n return Math.max(process(A, B, tank, alpha, w), process(A, B, tank, alpha, -w));\n }\n\n private double process(Point a, Point b, Point tank, double alpha, double w) {\n double alphaA = Math.atan2(a.y - tank.y, a.x - tank.x);\n double alphaB = Math.atan2(b.y - tank.y, b.x - tank.x);\n if (Math.signum(alphaA - alpha) != Math.signum(w)) alphaA += Math.PI * 2 * Math.signum(w);\n if (Math.signum(alphaB - alpha) != Math.signum(w)) alphaB += Math.PI * 2 * Math.signum(w);\n double tA = (alphaA - alpha) / w;\n double tB = (alphaB - alpha) / w;\n double dy = b.y - a.y;\n double dx = b.x - a.x;\n double dist = Math.sqrt(dx * dx + dy * dy);\n if (tB <= tA) {\n return dist / tB;\n } else {\n double best = 0;\n double bestVal = 0;\n double res = dist / tB;\n for (int i = 0; i <= 100; ++i) {\n double middle = i / 100.0;\n double x = a.x + middle * dx;\n double y = a.y + middle * dy;\n double alphaM2 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM2 - alpha) != Math.signum(w)) alphaM2 += Math.PI * 2 * Math.signum(w);\n double tM = (alphaM2 - alpha) / w;\n double cur = middle * dist / tM;\n res = Math.max(res, cur);\n if (cur > bestVal) {\n bestVal = cur;\n best = middle;\n }\n }\n double left = Math.max(0, best - 0.03);\n double right = Math.min(1, best + 0.03);\n for (int i = 0; i < 300; ++i) {\n double middle2;\n double tM2;\n {\n middle2 = (left + 2 * right) / 3;\n double x = a.x + middle2 * dx;\n double y = a.y + middle2 * dy;\n double alphaM2 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM2 - alpha) != Math.signum(w)) alphaM2 += Math.PI * 2 * Math.signum(w);\n tM2 = (alphaM2 - alpha) / w;\n }\n double middle1;\n double tM1;\n {\n middle1 = (2 * left + right) / 3;\n double x = a.x + middle1 * dx;\n double y = a.y + middle1 * dy;\n double alphaM1 = Math.atan2(y - tank.y, x - tank.x);\n if (Math.signum(alphaM1 - alpha) != Math.signum(w)) alphaM1 += Math.PI * 2 * Math.signum(w);\n tM1 = (alphaM1 - alpha) / w;\n }\n double valM1 = dist * middle1 / tM1;\n double valM2 = dist * middle2 / tM2;\n res = Math.max(res, valM1);\n res = Math.max(res, valM2);\n if (valM1 > valM2) {\n right = middle2;\n } else {\n left = middle1;\n }\n }\n return res;\n }\n }\n\n public static void main(String[] args) {\n new Tanks().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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ff3ae7a04fc98950e028c94d558a92d7", "src_uid": "38c14ab8b9c5107c2a2f70a35f166d8b", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.TreeSet;\nimport java.util.ArrayList;\nimport java.util.List;\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-10;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n Circle[] circles = new Circle[n];\n for (int i = 0; i < n; i++) {\n int x = in.nextInt();\n int y = in.nextInt();\n int r = in.nextInt();\n circles[i] = new Circle();\n circles[i].o = new Point(x, y);\n circles[i].r = r;\n }\n\n Set all = new TreeSet<>();\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n List inter = intersect(circles[i], circles[j]);\n if (inter == null) {\n continue;\n }\n all.addAll(inter);\n }\n }\n\n Map pointId = new TreeMap<>();\n List> adj = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n List angles = new ArrayList<>();\n final int K = 10;\n for (int j = 0; j < K; j++) {\n angles.add(Math.PI * 2 * j / K + 1e-8);\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 angles.add(Math.atan2(dy, dx));\n }\n }\n Collections.sort(angles);\n Point dir = new Point(1, 0).scale(circles[i].r);\n for (int j = 0; j < angles.size(); j++) {\n Point p = circles[i].o.add(dir.rotate(angles.get(j)));\n getId(p, pointId, adj);\n }\n for (int j = 0; j < angles.size(); j++) {\n Point p = circles[i].o.add(dir.rotate(angles.get(j)));\n Point q = circles[i].o.add(dir.rotate(angles.get((j + 1) % angles.size())));\n int u = pointId.get(p);\n int v = pointId.get(q);\n adj.get(u).add(v);\n adj.get(v).add(u);\n }\n }\n\n int v = adj.size();\n int e = 0;\n for (int i = 0; i < v; i++) {\n e += adj.get(i).size();\n }\n e /= 2;\n\n int comps = 0;\n boolean[] was = new boolean[v];\n for (int i = 0; i < v; i++) {\n if (!was[i]) {\n ++comps;\n dfs(i, was, adj);\n }\n }\n\n out.println(1 + comps + e - v);\n }\n\n private void dfs(int i, boolean[] was, List> adj) {\n was[i] = true;\n for (int j : adj.get(i)) {\n if (!was[j]) {\n dfs(j, was, adj);\n }\n }\n }\n\n private void getId(Point p, Map pointId, List> adj) {\n if (!pointId.containsKey(p)) {\n int sz = pointId.size();\n pointId.put(p, sz);\n adj.add(new TreeSet<>());\n }\n }\n\n private List intersect(Circle c1, Circle c2) {\n double dx = c1.o.x - c2.o.x;\n double dy = c1.o.y - c2.o.y;\n double sr = c1.r + c2.r;\n if (dx * dx + dy * dy > sr * sr + eps) {\n return null;\n }\n double d = Math.sqrt(dx * dx + dy * dy);\n if (d + Math.min(c1.r, c2.r) < Math.max(c1.r, c2.r) - eps) {\n return null;\n }\n double cos = (c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d);\n if (cos < -1) {\n cos = -1;\n }\n if (cos > 1) {\n cos = 1;\n }\n List res = new ArrayList<>();\n double alpha = Math.acos(cos);\n Point dir = c2.o.sub(c1.o).norm();\n res.add(c1.o.add(dir.scale(c1.r).rotate(+alpha)));\n res.add(c1.o.add(dir.scale(c1.r).rotate(-alpha)));\n return res;\n }\n\n class Point implements Comparable {\n double x;\n double y;\n\n Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n Point add(Point o) {\n return new Point(x + o.x, y + o.y);\n }\n\n Point sub(Point o) {\n return new Point(x - o.x, y - o.y);\n }\n\n Point rotate(double alpha) {\n double c = Math.cos(alpha);\n double s = Math.sin(alpha);\n double nx = x * c - y * s;\n double ny = x * s + y * c;\n return new Point(nx, ny);\n }\n\n Point norm() {\n double len = length();\n return scale(1.0 / len);\n }\n\n Point scale(double f) {\n return new Point(f * x, f * y);\n }\n\n double length() {\n return Math.sqrt(x * x + y * y);\n }\n\n public String toString() {\n return String.format(\"%.2f %.2f\", 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 && Math.abs(y - o.y) < eps) {\n return 0;\n }\n if (x != o.x) {\n return x < o.x ? -1 : 1;\n }\n if (y != o.y) {\n return y < o.y ? -1 : 1;\n }\n return 0;\n }\n\n }\n\n class Circle {\n Point o;\n double r;\n\n boolean contains(Point p) {\n double dist = p.sub(o).length();\n return Math.abs(dist - r) < eps;\n }\n\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "00d2d3507421c6ededf2471fd0d13c33", "src_uid": "bda5879e94a82c6fd499796f258c4691", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.InputStream;\nimport java.util.Random;\n\n/**\n * Created by dalt on 2018/3/25.\n */\npublic class CF933C {\n static final boolean IS_OJ = System.getProperty(\"ONLINE_JUDGE\") != null;\n public static BlockReader input;\n\n public static void main(String[] args) throws FileNotFoundException {\n if (!IS_OJ) {\n System.setIn(new FileInputStream(\"D:\\\\DataBase\\\\TESTCASE\\\\codeforces\\\\CF933C.in\"));\n }\n input = new BlockReader(System.in);\n\n solve();\n }\n\n public static void solve() {\n int n = input.nextInteger();\n Circle[] circles = new Circle[n];\n for (int i = 0; i < n; i++) {\n circles[i] = new Circle(input.nextInteger(), input.nextInteger(), input.nextInteger());\n }\n\n if (n == 1) {\n System.out.println(\"2\");\n return;\n }\n\n if (n == 2) {\n System.out.println(Circle.isIntersect(circles[0], circles[1]) ? \"4\" : \"3\");\n return;\n }\n\n int num = Circle.isIntersect(circles[0], circles[1]) ? 4 : 3;\n num += 1; //add circle3\n if (Circle.isIntersect(circles[0], circles[2])) {\n num += 1; //if circle1 intersect with circle3\n }\n if (Circle.isIntersect(circles[1], circles[2])) {\n num += 1;\n }\n\n if (num == 7) {\n //Probably exists a point in the all circles\n if (sa(circles) == 3) {\n num++;\n }\n }\n\n System.out.println(num);\n }\n\n\n public static int sa(Circle[] circles) {\n Random random = new Random(19950823);\n\n Point now = new Point(0, 0);\n double nowVal = evaluate(circles, now);\n\n double t = 1000;\n double k = 1;\n double r = 0.98;\n while (t > 1e-5) {\n Point next = new Point(Math.max(-20, Math.min(20, now.x + nextDouble(random, -t, t))), Math.max(-20, Math.min(20, now.y + nextDouble(random, -t, t))));\n double nextVal = evaluate(circles, next);\n if (nextVal > nowVal || random.nextDouble() < Math.exp((nextVal - nowVal) / (k * t))) {\n now = next;\n nowVal = nextVal;\n }\n\n t *= r;\n }\n\n int sum = 0;\n for (Circle circle : circles) {\n if (distance(circle.center, now) < circle.r) {\n sum++;\n }\n }\n return sum;\n }\n\n public static double evaluate(Circle[] circles, Point point) {\n double sum = 0;\n for (Circle circle : circles) {\n double d = distance(point, circle.center);\n if (d > circle.r) {\n sum -= (d - circle.r);\n }\n }\n return sum;\n }\n\n public static double nextDouble(Random random, double l, double r) {\n return random.nextDouble() * (r - l) + l;\n }\n\n public static double distance(Point a, Point b) {\n return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));\n }\n\n public static class Circle {\n Point center;\n int r;\n\n public Circle(int x, int y, int r) {\n this.center = new Point(x, y);\n this.r = r;\n }\n\n public static boolean isIntersect(Circle a, Circle b) {\n double d = distance(a.center, b.center);\n return d < a.r + b.r && d > Math.abs(a.r - b.r);\n }\n }\n\n public static class Point {\n double x, y;\n\n public Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public String toString() {\n return \"(\" + x + \",\" + y + \")\";\n }\n }\n\n public static class BlockReader {\n static final int EOF = -1;\n InputStream is;\n byte[] dBuf;\n int dPos, dSize, next;\n StringBuilder builder = new StringBuilder();\n\n public BlockReader(InputStream is) {\n this(is, 4096);\n }\n\n public BlockReader(InputStream is, int bufSize) {\n this.is = is;\n dBuf = new byte[bufSize];\n next = nextByte();\n }\n\n public int nextByte() {\n while (dPos >= dSize) {\n if (dSize == -1) {\n return EOF;\n }\n dPos = 0;\n try {\n dSize = is.read(dBuf);\n } catch (Exception e) {\n }\n }\n return dBuf[dPos++];\n }\n\n public String nextBlock() {\n builder.setLength(0);\n skipBlank();\n while (next != EOF && !Character.isWhitespace(next)) {\n builder.append((char) next);\n next = nextByte();\n }\n return builder.toString();\n }\n\n public void skipBlank() {\n while (Character.isWhitespace(next)) {\n next = nextByte();\n }\n }\n\n public int nextInteger() {\n skipBlank();\n int ret = 0;\n boolean rev = false;\n if (next == '+' || next == '-') {\n rev = next == '-';\n next = nextByte();\n }\n while (next >= '0' && next <= '9') {\n ret = (ret << 3) + (ret << 1) + next - '0';\n next = nextByte();\n }\n return rev ? -ret : ret;\n }\n\n public int nextBlock(char[] data, int offset) {\n skipBlank();\n int index = offset;\n int bound = data.length;\n while (next != EOF && index < bound && !Character.isWhitespace(next)) {\n data[index++] = (char) next;\n next = nextByte();\n }\n return index - offset;\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != EOF;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd5aa4a4c28179569f40ca855d7663dd", "src_uid": "bda5879e94a82c6fd499796f258c4691", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.TreeSet;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.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-10;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n Circle[] circles = new Circle[n];\n for (int i = 0; i < n; i++) {\n int x = in.nextInt();\n int y = in.nextInt();\n int r = in.nextInt();\n circles[i] = new Circle();\n circles[i].o = new Point(x, y);\n circles[i].r = r;\n }\n\n Set all = new TreeSet<>();\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n List inter = intersect(circles[i], circles[j]);\n if (inter == null) {\n continue;\n }\n all.addAll(inter);\n }\n }\n\n Map pointId = new TreeMap<>();\n List> adj = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n List angles = new ArrayList<>();\n final int K = 10;\n for (int j = 0; j < K; j++) {\n angles.add(Math.PI * 2 * j / K + 1e-5);\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 angles.add(Math.atan2(dy, dx));\n }\n }\n Collections.sort(angles);\n Point dir = new Point(1, 0).scale(circles[i].r);\n for (int j = 0; j < angles.size(); j++) {\n Point p = circles[i].o.add(dir.rotate(angles.get(j)));\n getId(p, pointId, adj);\n }\n for (int j = 0; j < angles.size(); j++) {\n Point p = circles[i].o.add(dir.rotate(angles.get(j)));\n Point q = circles[i].o.add(dir.rotate(angles.get((j + 1) % angles.size())));\n int u = pointId.get(p);\n int v = pointId.get(q);\n adj.get(u).add(v);\n adj.get(v).add(u);\n }\n }\n\n int v = adj.size();\n int e = 0;\n for (int i = 0; i < v; i++) {\n e += adj.get(i).size();\n }\n e /= 2;\n\n int comps = 0;\n boolean[] was = new boolean[v];\n for (int i = 0; i < v; i++) {\n if (!was[i]) {\n ++comps;\n dfs(i, was, adj);\n }\n }\n\n out.println(1 + comps + e - v);\n }\n\n private void dfs(int i, boolean[] was, List> adj) {\n was[i] = true;\n for (int j : adj.get(i)) {\n if (!was[j]) {\n dfs(j, was, adj);\n }\n }\n }\n\n private void getId(Point p, Map pointId, List> adj) {\n if (!pointId.containsKey(p)) {\n int sz = pointId.size();\n pointId.put(p, sz);\n adj.add(new TreeSet<>());\n }\n }\n\n private List intersect(Circle c1, Circle c2) {\n double dx = c1.o.x - c2.o.x;\n double dy = c1.o.y - c2.o.y;\n double d = Math.sqrt(dx * dx + dy * dy);\n double cos = (c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d);\n if (cos < -1 - eps) {\n return null;\n }\n if (cos < -1) {\n cos = -1;\n }\n if (cos > 1 + eps) {\n return null;\n }\n if (cos > 1) {\n cos = 1;\n }\n List res = new ArrayList<>();\n double alpha = Math.acos(cos);\n Point dir = c2.o.sub(c1.o).norm();\n res.add(c1.o.add(dir.scale(c1.r).rotate(+alpha)));\n res.add(c1.o.add(dir.scale(c1.r).rotate(-alpha)));\n return res;\n }\n\n class Point implements Comparable {\n double x;\n double y;\n\n Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n Point add(Point o) {\n return new Point(x + o.x, y + o.y);\n }\n\n Point sub(Point o) {\n return new Point(x - o.x, y - o.y);\n }\n\n Point rotate(double alpha) {\n double c = Math.cos(alpha);\n double s = Math.sin(alpha);\n double nx = x * c - y * s;\n double ny = x * s + y * c;\n return new Point(nx, ny);\n }\n\n Point norm() {\n double len = length();\n return scale(1.0 / len);\n }\n\n Point scale(double f) {\n return new Point(f * x, f * y);\n }\n\n double length() {\n return Math.sqrt(x * x + y * y);\n }\n\n public String toString() {\n return String.format(\"%.2f %.2f\", 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 && Math.abs(y - o.y) < eps) {\n return 0;\n }\n if (x != o.x) {\n return x < o.x ? -1 : 1;\n }\n if (y != o.y) {\n return y < o.y ? -1 : 1;\n }\n return 0;\n }\n\n }\n\n class Circle {\n Point o;\n double r;\n\n boolean contains(Point p) {\n double dist = p.sub(o).length();\n return Math.abs(dist - r) < eps;\n }\n\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db0277cd6359cfe4be8f100cabe7ffc6", "src_uid": "bda5879e94a82c6fd499796f258c4691", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n 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 public void solve(int testNumber, FastScanner in, PrintWriter out) {\n for (int test = 1; ; test++) {\n int n = in.nextInt();\n int D = in.nextInt();\n if (n == 0 && D == 0) {\n break;\n }\n out.println(\"@\" + test);\n final double r = 1;\n Point pl = new Point(-D, 0);\n Point pr = new Point(+D, 0);\n for (int i = 0; i < n; i++) {\n int sl = in.nextInt();\n int sr = in.nextInt();\n double vl = sl / 180.0 * Math.PI * r;\n double vr = sr / 180.0 * Math.PI * r;\n int t = in.nextInt();\n if (sl == sr) {\n Point v = pr.sub(pl).rotate(Math.PI / 2).norm().scale((vl + vr) * 0.5 * t);\n pl = pl.add(v);\n pr = pr.add(v);\n continue;\n }\n double x = D * (vl + vr) / (vl - vr);\n// double x = D * (vl + vr) / (vr - vl);\n Point o = pl.add(pr).scale(0.5);\n Point ox = o.add(pr.sub(o).norm().scale(x));\n// out.println(\"!\" + cross(ox,pr.sub(pl)));\n\n Point nl = pl.sub(ox);\n Point nr = pr.sub(ox);\n// nl=nl.scale(-1);\n// nr=nr.scale(-1);\n double wl = vl / nl.length();\n double wr = vr / nr.length();\n// if (x < D && x > -D) {\n// wr = -wr;\n// }\n// out.println(wl + \" \" + wr);\n nl = nl.rotate(wl * t);\n nr = nr.rotate(wr * t);\n\n pl = nl.add(ox);\n pr = nr.add(ox);\n }\n Point p = pl.add(pr).scale(0.5);\n out.printf(\"%.10f\\n\", p.x);\n out.printf(\"%.10f\\n\", p.y);\n }\n }\n\n class 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(\"%.2f %.2f\", x, y);\n }\n\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e405c008798d388b5a0d62c3047ffc7a", "src_uid": "bda5879e94a82c6fd499796f258c4691", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class susbus{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int x = sc.nextInt();\n int y = sc.nextInt();\n int z = sc.nextInt();\n int t1 = sc.nextInt();\n int t2 = sc.nextInt();\n int t3 = sc.nextInt();\n if (t1*(Math.abs(y-x) < 2*t3+t2*Math.abs(z-y)+t1*Math.abs(z-x))){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29b4f749b60b9d09ed3311dea2dc8ebe", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class susbus{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int x = sc.nextInt();\n int y = sc.nextInt();\n int z = sc.nextInt();\n int t1 = sc.nextInt();\n int t2 = sc.nextInt();\n int t3 = sc.nextInt();\n if (t1*(Math.abs(y-x)) < t2*Math.abs(z-x)+t2*Math.abus(y-x)+4*t3){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3d39ea1590d46cd197380375389bc88c", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class m\n{\n\tpublic int stairs(int start,int end,int t1)\n\t{\n\t\tint t;\n\t\tt=(Math.abs(start-end))*t1;\n\t\treturn t;\n\t}\n\tpublic int alivator(int start,int end ,int l,int t2,int t3)\n\t{\n\t\tint m1;\n\t\tm1=((Math.abs(start-l))*t2)+2*t3;\n\t\tint l1;\n\t\tl1=((Math.abs(start-end))*t2)+t3;\n\t\treturn (m1+l1);\n\t}\n}\n\npublic class stairs\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tm p=new m();\n\t\tint x=sc.nextInt();\n\t\tint y=sc.nextInt();\n\t\tint z=sc.nextInt();\n\t\tint t1=sc.nextInt();\n\t\tint t2=sc.nextInt();\n\t\tint t3=sc.nextInt();\n\t\tint l1=p.stairs(x,y,t1);\n\t\tint y1=p.alivator(x,y,z,t2,t3);\n\t\tif(y1<=l1)\n\t\t{\n\t\t\tSystem.out.println(\"Yes\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(\"No\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2c755e8ae10c8f7c6bef290b0984770f", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class CodeForces2 {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Task {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int x = in.nextInt();\n int y = in.nextInt();\n int z = in.nextInt();\n int t1 = in.nextInt();\n int t2 = in.nextInt();\n int t3 = in.nextInt();\n\n int stairs = Math.abs(x - y) * t1;\n int ele = Math.abs(x - z) * t2 + 2 * t3 + Math.abs(y - z) * t2 + 2 * t3;\n\n if(stairs < ele) {\n out.println(\"NO\");\n } else{\n out.println(\"YES\");\n }\n\n }\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc232f55b46e32c985251f38d55d8506", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class p3\r\n{\r\n\tBufferedReader br;\r\n\tStringTokenizer st;\r\n\tBufferedWriter bw;\r\n\tpublic static void main(String[] args)throws Exception\r\n\t{\r\n\t\tnew p3().run();\r\n\t}\r\n\r\n\tvoid run()throws IOException\r\n\t{\r\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tbw=new BufferedWriter(new OutputStreamWriter(System.out));\r\n\t\tsolve();\r\n\t}\r\n\tvoid solve() throws IOException\r\n\t{\r\n\t\tint t=ni();\r\n\t\twhile(t-->0)\r\n\t\t{\r\n\t\t\tint n=ni();\r\n\t\t\tint m=ni();\r\n\t\t\tint k=ni();\r\n\t\t\tint q=ni();\r\n\t\t\tint d1[]=new int[q];\r\n\t\t\tint d2[]=new int[q];\r\n\t\t\tfor(int i=-1;++i=0;)\r\n\t\t\t{\r\n\t\t\t\tif(a[d1[i]-1]==0 || b[d2[i]-1]==0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif(a[d1[i]-1]==0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ta[d1[i]-1]=1;\r\n\t\t\t\t\t\tn--;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(b[d2[i]-1]==0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tb[d2[i]-1]=1;\r\n\t\t\t\t\t\tm--;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tx++;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif(n==0 || m==0)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t\tlong ans=nPowerM(k, x);\r\n\t\t\t\r\n\t\t\tbw.write(ans+\"\\n\");\r\n\t\t}\r\n\t\tbw.flush();\r\n\t}\r\n\r\n\tpublic long nPowerM(int n, int m)\r\n\t{\r\n\t\tif(m==0)\r\n\t\t\treturn 1L;\r\n\t\t\r\n\t\t// int mod=1000000007;\r\n\t\tint mod=998244353;\r\n\t\tlong ans=nPowerM(n, m/2);\r\n\t\tans*=ans;\r\n\t\tans%=mod;\r\n\r\n\t\tif(m%2==1)\r\n\t\t{\r\n\t\t\tans*=n;\r\n\t\t\tans%=mod;\r\n\t\t}\r\n\r\n\t\treturn ans;\r\n\t}\r\n\t/////////////////////////////////////// FOR INPUT ///////////////////////////////////////\r\n\r\n\tint[] nai(int n) { int a[]=new int[n]; for(int i=-1;++in/2)i=n-i;\r\n\t long a=1,b=1;\r\n\t for(int j=1;j<=i;j++) {\r\n\t\t a*=(n-j+1);a%=mod;\r\n\t\t b*=j;b%=mod;\r\n\t\t if(a%b==0) {\r\n\t\t\t a/=b;b=1;\r\n\t\t }\r\n\t }\r\n\t return (a/b)%mod;\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)System.out.println(arr[n]);\r\n long ans=0;\r\n for(int i=0;i<=k;i++) {\r\n \tans=ans%mod+C(n,i)%mod;ans%=mod;\r\n }\r\n System.out.println(ans);\r\n\tK--;\r\n}\r\n}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "592d5b68f1e79d8bba8eadf8d3704586", "src_uid": "dc7b887afcc2e95c4e90619ceda63071", "difficulty": 1900.0} {"lang": "Java 17", "source_code": "import java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class Round818D {\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\tRound818D sol = new Round818D();\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 = true;\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 \tsolve();\r\n\t \t\r\n\t \tprintOutput();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tstatic long MOD = 1_000_000_007;\r\n\t\r\n\t// use suitable one between matrix(2, n), matrix(n, 2), transposedMatrix(2, n) for graph edges, pairs, ...\r\n\tint n, k;\r\n\tvoid getInput() {\r\n\t\tn = in.nextInt(); \r\n\t\tk = in.nextInt();\r\n\t}\r\n\t\r\n\tvoid printOutput() {\r\n\t\tout.printlnAns(ans);\r\n\t}\r\n\r\n\tlong ans;\r\n\tvoid solve(){\r\n\t\t// k >= n -> the sponsors can always make 2^n win\r\n\t\t\r\n\t\t// k = 1\r\n\t\t// at the last match, suppose 1 and 2 will match -> can make 2 win\r\n\t\t// but then, if we designed so that 1 would win, largest opponent that faced 1 could win\r\n\t\t// there are n opponents that faced 1, so the answer = n+1\r\n\t\t\r\n\t\t// k = 2\r\n\t\t// for each of those n opponents,\r\n\t\t// (who played 0, 1, ..., n-1 games before facing 1)\r\n\t\t// (n-1)n/2 more opponents appear\r\n\t\t\r\n\t\tlong[] choose = new long[n+1];\r\n\t\tchoose[0] = 1;\r\n\t\t// n!/i!/(n-i)!\r\n\t\t// = n!/(i-1)!/(n-i+1)!\r\n\t\t// nCi = nC(i-1)/i*(n-i+1)\r\n\t\tfor(int i=1; i<=n; i++)\r\n\t\t\tchoose[i] = (choose[i-1] * (n-i+1) % MOD) * inverse(i, MOD) % MOD;\r\n\t\t\r\n\t\tans = 0;\r\n\t\tfor(int i=0; i<=Math.min(k, n); i++)\r\n\t\t\tans += choose[i];\r\n\t\tans %= MOD;\r\n\t}\r\n\t\r\n\tstatic long pow(long 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\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//\tOptional solve()\r\n//\treturn Optional.empty();\r\n\t\r\n\tstatic class Pair implements Comparable{\r\n\t\tfinal static long FIXED_RANDOM = System.currentTimeMillis();\r\n\t\tint first, second;\r\n\t\tpublic Pair(int first, int second) {\r\n\t\t\tthis.first = first;\r\n\t\t\tthis.second = second;\r\n\t\t}\r\n\t\t\r\n\r\n\t\t@Override\r\n\t\tpublic int hashCode() {\r\n\t\t\t// http://xorshift.di.unimi.it/splitmix64.c\r\n\t\t\tlong x = first;\r\n\t\t\tx <<= 32;\r\n\t\t\tx += second;\r\n\t\t\tx += FIXED_RANDOM;\r\n\t\t\tx += 0x9e3779b97f4a7c15l;\r\n\t\t\tx = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l;\r\n\t\t\tx = (x ^ (x >> 27)) * 0x94d049bb133111ebl;\r\n\t\t\treturn (int)(x ^ (x >> 31));\r\n\t\t}\r\n\t\t@Override\r\n\t\tpublic boolean equals(Object obj) {\r\n//\t\t\tif (this == obj)\r\n//\t\t\t\treturn true;\r\n//\t\t\tif (obj == null)\r\n//\t\t\t\treturn false;\r\n//\t\t\tif (getClass() != obj.getClass())\r\n//\t\t\t\treturn false;\r\n\t\t\tPair other = (Pair) obj;\r\n\t\t\treturn first == other.first && second == other.second;\r\n\t\t}\r\n\t\t@Override\r\n\t\tpublic String toString() {\r\n\t\t\treturn \"[\" + first + \",\" + second + \"]\";\r\n\t\t}\r\n\r\n\r\n\t\t@Override\r\n\t\tpublic int compareTo(Pair o) {\r\n\t\t\tint cmp = Integer.compare(first, o.first);\r\n\t\t\treturn cmp != 0? cmp: Integer.compare(second, o.second);\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static class MyScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\t// 32768?\r\n\t\tpublic MyScanner(InputStream is, int bufferSize) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bufferSize);\r\n\t\t}\r\n\t\t\r\n\t\tpublic MyScanner(InputStream is) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\r\n\t\t}\r\n\r\n\t\tpublic void close() {\r\n\t\t\ttry {\r\n\t\t\t\tbr.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tString next() {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine(){\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextMatrix(int n, int m) {\r\n\t\t\treturn nextMatrix(n, m, 0);\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextMatrix(int n, int m, int offset) {\r\n\t\t\tint[][] mat = new int[n][m];\r\n\t\t\tfor(int i=0; i void printlnAns(Optional ans) {\r\n//\t\t\tif(ans.isEmpty())\r\n//\t\t\t\tprintln(-1);\r\n//\t\t\telse\r\n//\t\t\t\tprintlnAns(ans.get());\r\n//\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(OptionalInt ans) {\r\n\t\t\tprintln(ans.orElse(-1));\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(long ans) {\r\n\t\t\tprintln(ans);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(int ans) {\r\n\t\t\tprintln(ans);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(boolean ans) {\r\n\t\t\tif(ans)\r\n\t\t\t\tprintln(YES);\r\n\t\t\telse\r\n\t\t\t\tprintln(NO);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(long[] arr){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d62fe6970e4c8c98169d8e712439da9", "src_uid": "dc7b887afcc2e95c4e90619ceda63071", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n static FastReader sc=new FastReader();\r\n\tstatic PrintWriter out=new PrintWriter(System.out);\r\n\tstatic int dx[]={0,0,-1,1},dy[]={-1,1,0,0};\r\n\tstatic final double pi=3.1415926536;\r\n\tstatic long mod=1000000007;\r\n\t// static long mod=998244353;\r\n\tstatic int MAX=Integer.MAX_VALUE;\r\n\tstatic int MIN=Integer.MIN_VALUE;\r\n\tstatic long MAXL=Long.MAX_VALUE;\r\n\tstatic long MINL=Long.MIN_VALUE;\r\n\tstatic ArrayList graph[];\r\n\tstatic long fact[];\r\n\tstatic long seg[];\r\n\tstatic int dp[];\r\n\t// static long dp[][];\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\t// code goes here\r\n\t\tint t=I();\r\n\t\touter:while(t-->0)\r\n\t\t{\r\n\t\t\tint n=I(),k=I();\r\n\t\t\tlong nodes=pwr(2,k)-1;\r\n\t\t\tlong levels=n-k;\r\n\t\t\tout.println(nodes*pwr(2,levels)+1);\r\n\t\t}\r\n\t\tout.close();\r\n\t}\r\n\tpublic static class pair\r\n {\r\n \tint a;\r\n \tint b;\r\n \tpublic pair(int aa,int bb)\r\n \t{\r\n \t a=aa;\r\n \t b=bb;\r\n \t}\r\n }\r\n\tpublic static class myComp implements Comparator\r\n\t{\r\n\t\t//sort in ascending order.\r\n\t\tpublic int compare(pair p1,pair p2)\r\n\t\t{\r\n\t\t\tif(p1.a==p2.a)\r\n \t return 0;\r\n \t else if(p1.a();\r\n\t\t}\r\n\t\tfor(int i=0;iend)return -1;\r\n\t\t// if(arr.get(end)X)return -1;\r\n\t\tif(arr[start].a>X)return -1;\r\n\t\tint left=start,right=end;\r\n\t\twhile(leftstart && arr.get(mid-1)==X){\r\n\t\t\t// \tif(mid>start && arr[mid-1]==X){\r\n\t\t\t// \t\tright=mid-1;\r\n\t\t\t// \t}else{\r\n\t\t\t// \t\treturn mid;\r\n\t\t\t// \t}\r\n\t\t\t// }\r\n\r\n\t\t\telse if(arr[mid].a>X){\r\n\t\t\t// else if(arr.get(mid)>X){\r\n\t\t\t\tif(mid>start && arr[mid-1].astart && arr.get(mid-1)X){\r\n\t\t\t\t// if(midX){\r\n\t\t\t\t\treturn mid;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tleft=mid+1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn left;\r\n\t}\r\n\t//It returns answer according to zero based indexing.\r\n\tpublic static int upper_bound(long arr[],long X,int start,int end)\t\t\t//start=0,end=n-1\r\n\t{\r\n\t\tif(arr[0]>=X)return start;\r\n\t\tif(arr[arr.length-1]start && arr[mid-1]==X){\r\n\t\t\t\t\tright=mid-1;\r\n\t\t\t\t}else{\r\n\t\t\t\t\treturn mid;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// if(arr[mid]==X){\t\t\t\t\t\t\t\t\t//returns last index of upper bound value.\r\n\t\t\t// \tif(midX){\r\n\t\t\t\tif(mid>start && arr[mid-1]X){\r\n\t\t\t\t\treturn mid+1;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tleft=mid+1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn left;\r\n\t}\r\n\r\n\t//END\r\n\r\n\t//Segment Tree Code\r\n\tpublic static void buildTree(long a[],int si,int ss,int se)\r\n\t{\r\n\t\tif(ss==se){\r\n\t\t\tseg[si]=a[ss];\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tint mid=(ss+se)/2;\r\n\t\tbuildTree(a,2*si+1,ss,mid);\r\n\t\tbuildTree(a,2*si+2,mid+1,se);\r\n\t\tseg[si]=max(seg[2*si+1],seg[2*si+2]);\r\n\t}\r\n\t// public static void update(int si,int ss,int se,int pos,int val)\r\n\t// {\r\n\t// \tif(ss==se){\r\n\t// \t\t// seg[si]=val;\r\n\t// \t\treturn;\r\n\t// \t}\r\n\t// \tint mid=(ss+se)/2;\r\n\t// \tif(pos<=mid){\r\n\t// \t\tupdate(2*si+1,ss,mid,pos,val);\r\n\t// \t}else{\r\n\t// \t\tupdate(2*si+2,mid+1,se,pos,val);\r\n\t// \t}\r\n\t// \t// seg[si]=min(seg[2*si+1],seg[2*si+2]);\r\n\t// \tif(seg[2*si+1].a < seg[2*si+2].a){\r\n\t// \t\tseg[si].a=seg[2*si+1].a;\r\n\t// \t\tseg[si].b=seg[2*si+1].b;\r\n\t// \t}else{\r\n\t// \t\tseg[si].a=seg[2*si+2].a;\r\n\t// \t\tseg[si].b=seg[2*si+2].b;\r\n\t// \t}\r\n\t// }\r\n\tpublic static long query(int si,int ss,int se,int qs,int qe)\r\n\t{\r\n\t\tif(qs>se || qe=qs && se<=qe)return seg[si];\r\n\t\tint mid=(ss+se)/2;\r\n\t\tlong p1=query(2*si+1,ss,mid,qs,qe);\r\n\t\tlong p2=query(2*si+2,mid+1,se,qs,qe);\r\n\t\treturn max(p1,p2);\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic static void merge(ArrayList f,ArrayList a,ArrayList b)\r\n\t{\r\n\t\tint i=0,j=0;\r\n\t\twhile(i0 && c[i]!=c[j]){\r\n\t\t\t\tj=pi[j-1];\r\n\t\t\t}\r\n\t\t\tif(c[i]==c[j])j++;\r\n\t\t\tpi[i]=j;\r\n\t\t}\r\n\t\treturn pi;\r\n\t}\r\n\tpublic static long kadane(long a[],int n) //largest sum subarray\r\n\t{\r\n\t\tlong max_sum=Long.MIN_VALUE,max_end=0;\r\n\t\tfor(int i=0;i primeFact(long x)\r\n\t{\r\n\t\tArrayList arr=new ArrayList<>();\r\n\t\tif(x%2==0){\r\n\t\t\tarr.add(2L);\r\n\t\t\twhile(x%2==0){\r\n\t\t\t\tx/=2;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(long i=3;i*i<=x;i+=2){\r\n\t\t\tif(x%i==0){\r\n\t\t\t\tarr.add(i);\r\n\t\t\t\twhile(x%i==0){\r\n\t\t\t\t\tx/=i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(x>0){\r\n\t\t\tarr.add(x);\r\n\t\t}\r\n\t\treturn arr;\r\n\t}\r\n\tpublic static long nPr(int n,int r)\r\n\t{\r\n\t\tlong ans=divide(fact(n),fact(n-r),mod);\r\n\t\treturn ans;\r\n\t}\r\n\tpublic static long nCr(int n,int r)\r\n\t{\r\n\t\tlong ans=divide(fact[n],mul(fact[n-r],fact[r]),mod);\r\n\t\treturn ans;\r\n\t}\r\n\r\n\tpublic static boolean isSorted(int a[])\r\n\t{\r\n\t\tint n=a.length;\r\n\t\tfor(int i=0;ia[i+1])return false;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\tpublic static boolean isSorted(long a[])\r\n\t{\r\n\t\tint n=a.length;\r\n\t\tfor(int i=0;ia[i+1])return false;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\tpublic static long toggleBits(long x)//one's complement || Toggle bits\r\n\t{\r\n\t\tint n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;\r\n \r\n\t\treturn ((1<> 1;\r\n\t\tx |= x >> 2;\r\n\t\tx |= x >> 4;\r\n\t\tx |= x >> 8;\r\n\t\tx |= x >> 16;\r\n\t\tx++;\r\n\t\treturn x;\r\n\t}\r\n\tpublic static int hp2(int x)\r\n\t{\r\n\t\tx |= x >> 1;\r\n\t\tx |= x >> 2;\r\n\t\tx |= x >> 4;\r\n\t\tx |= x >> 8;\r\n\t\tx |= x >> 16;\t\r\n\t\treturn x ^ (x >> 1); \r\n\t}\r\n\tpublic static long hp2(long x)\r\n\t{\r\n\t\tx |= x >> 1;\r\n\t\tx |= x >> 2;\r\n\t\tx |= x >> 4;\r\n\t\tx |= x >> 8;\r\n\t\tx |= x >> 16;\r\n\t\treturn x ^ (x >> 1); \r\n\t}\r\n\tpublic static ArrayList primeSieve(int n)\r\n\t{\r\n\t ArrayList arr=new ArrayList<>();\r\n\t boolean prime[] = new boolean[n + 1];\r\n for (int i = 0; i <= n; i++)\r\n prime[i] = true;\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 for (int i = 2; i <= n; i++)\r\n {\r\n if (prime[i] == true)\r\n arr.add(i);\r\n }\r\n return arr;\r\n\t}\r\n\t\r\n\t// Fenwick / BinaryIndexed Tree USE IT - FenwickTree ft1=new FenwickTree(n);\r\n\tpublic static class FenwickTree\r\n\t{\r\n\t\tint farr[];\r\n\t\tint n;\r\n\t\tpublic FenwickTree(int c)\r\n\t\t{\r\n\t\t\tn=c+1;\r\n\t\t\tfarr=new int[n];\r\n\t\t}\r\n\t\t// public void update_range(int l,int r,long p)\r\n\t\t// {\r\n\t\t// \tupdate(l,p);\r\n\t\t// \tupdate(r+1,(-1)*p);\r\n\t\t// }\r\n\t\tpublic void update(int x,int p)\r\n\t\t{\r\n\t\t\tfor(;x0;x-=x&(-x))\r\n\t\t\t{\r\n\t\t\t\tans=ans+farr[x];\r\n\t\t\t}\r\n\t\t\treturn ans;\r\n\t\t}\r\n\t}\r\n\t//Disjoint Set Union\r\n\r\n\t//NOTE: call find function for all the index in the par array at last,\r\n\t//in order to set parent of every index properly.\r\n\tpublic static class DSU\r\n\t{\r\n\t int par[],rank[];\r\n\t public DSU(int c)\r\n\t {\r\n\t par=new int[c+1];\r\n\t rank=new int[c+1];\r\n\t for(int i=0;i<=c;i++)\r\n\t {\r\n\t par[i]=i;\r\n\t rank[i]=0;\r\n\t }\r\n\t }\r\n\t public int find(int a)\r\n\t {\r\n\t if(a==par[a])\r\n\t return a;\r\n\t return par[a]=find(par[a]);\r\n\t }\r\n\t public void union(int a,int b)\r\n\t {\r\n\t int a_rep=find(a),b_rep=find(b);\r\n\t if(a_rep==b_rep)\r\n\t return;\r\n\t if(rank[a_rep]rank[b_rep])\r\n\t par[b_rep]=a_rep;\r\n\t else\r\n\t {\r\n\t par[b_rep]=a_rep;\r\n\t rank[a_rep]++;\r\n\t }\r\n\t }\r\n\t}\r\n\tpublic static boolean isVowel(char c)\r\n\t{\r\n\t\tif(c=='a' || c=='e' || c=='i' || c=='u' || c=='o')return true;\r\n\t\treturn false;\r\n\t}\r\n\tpublic static boolean isInteger(double N)\r\n\t{\r\n\t\tint X = (int)N;\r\n\t\tdouble temp2 = N - X;\r\n\t\tif (temp2 > 0)\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\tpublic static boolean isPalindrome(String s)\r\n\t{\r\n\t\tint n=s.length();\r\n\t\tfor(int i=0;i<=n/2;i++){\r\n\t\t\tif(s.charAt(i)!=s.charAt(n-i-1)){\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\tpublic static int gcd(int a,int b)\r\n\t{\r\n\t if(b==0)\r\n\t return a;\r\n\t else\r\n\t return gcd(b,a%b);\r\n\t}\r\n\tpublic static long gcd(long a,long b)\r\n\t{\r\n\t if(b==0)\r\n\t return a;\r\n\t else\r\n\t return gcd(b,a%b);\r\n\t}\r\n\tpublic static long fact(long n)\r\n\t{\r\n\t\tlong fact=1;\r\n\t\tfor(long i=2;i<=n;i++){\r\n\t\t\tfact=((fact%mod)*(i%mod))%mod;\r\n\t\t}\r\n\t\treturn fact;\r\n\t}\r\n\tpublic static long fact(int n)\r\n\t{\r\n\t\tlong fact=1;\r\n\t\tfor(int i=2;i<=n;i++){\r\n\t\t\tfact=((fact%mod)*(i%mod))%mod;\r\n\t\t}\r\n\t\treturn fact;\r\n\t} \r\n\tpublic static boolean isPrime(int n) \r\n\t{ \r\n\t if (n <= 1) \r\n\t return false; \r\n\t if (n <= 3) \r\n\t return true; \r\n\t if (n % 2 == 0 || n % 3 == 0) \r\n\t return false; \r\n\t double sq=Math.sqrt(n);\r\n\t \r\n\t for (int i = 5; i <= sq; i = i + 6) \r\n\t if (n % i == 0 || n % (i + 2) == 0) \r\n\t return false; \r\n\t return true; \r\n\t} \r\n public static boolean isPrime(long n) \r\n\t{ \r\n\t if (n <= 1) \r\n\t return false; \r\n\t if (n <= 3) \r\n\t return true; \r\n\t if (n % 2 == 0 || n % 3 == 0) \r\n\t return false; \r\n\t double sq=Math.sqrt(n);\r\n\t\r\n\t for (int i = 5; i <= sq; i = i + 6) \r\n\t if (n % i == 0 || n % (i + 2) == 0) \r\n\t return false; \r\n\t return true; \r\n\t}\r\n\tpublic static void printArray(long a[])\r\n\t{\r\n\t\tfor(int i=0;i\"+p.b);\r\n\t\t}\r\n\t}\r\n\tpublic static void printArray(int a[][])\r\n\t{\r\n\t\tfor(int i=0;i arr)\r\n\t{\r\n\t\tfor(int i=0;i hm){\r\n\t\tfor(Map.Entry e:hm.entrySet()){\r\n\t\t\tout.println(e.getKey()+\"->\"+e.getValue());\r\n\t\t}out.println();\r\n\t}\r\n\tpublic static void printMap(HashMap> hm){\r\n\t\tfor(Map.Entry> e:hm.entrySet()){\r\n\t\t\tout.print(e.getKey()+\"->\");\r\n\t\t\tArrayList arr=e.getValue();\r\n\t\t\tfor(int i=0;i graph[])\r\n\t{\r\n\t\tint n=graph.length;\r\n\t\tfor(int i=0;i\");\r\n\t\t\tfor(int j:graph[i]){\r\n\t\t\t\tout.print(j+\" \");\r\n\t\t\t}out.println();\r\n\t\t}\r\n\t}\r\n\r\n\t//Modular Arithmetic\r\n\r\n\tpublic static long add(long a,long b)\r\n\t{\r\n\t\ta+=b;\r\n\t\tif(a>=mod)a-=mod;\r\n\t\treturn a;\r\n\t}\r\n\tpublic static long sub(long a,long b)\r\n\t{\r\n\t\ta-=b;\r\n\t\tif(a<0)a+=mod;\r\n\t\treturn a;\r\n\t}\r\n\tpublic static long mul(long a,long b)\r\n\t{\r\n\t\treturn ((a%mod)*(b%mod))%mod;\r\n\t}\r\n\tpublic static long divide(long a,long b,long m)\r\n\t{\r\n\t\ta=mul(a,modInverse(b,m));\r\n\t\treturn a;\r\n\t}\r\n\tpublic static long modInverse(long a,long m)\r\n\t{\r\n\t\tint x=0,y=0;\r\n\t\town p=new own(x,y);\r\n\t\tlong g=gcdExt(a,m,p);\r\n\t\tif(g!=1){\r\n\t\t\tout.println(\"inverse does not exists\");\r\n\t\t\treturn -1;\r\n\t\t}else{\r\n\t\t\tlong res=((p.a%m)+m)%m;\r\n\t\t\treturn res;\r\n\t\t}\r\n\t}\r\n\tpublic static long gcdExt(long a,long b,own p)\r\n\t{\r\n\t\tif(b==0){\r\n\t\t\tp.a=1;\r\n\t\t\tp.b=0;\r\n\t\t\treturn a;\r\n\t\t}\r\n\t\tint x1=0,y1=0;\r\n\t\town p1=new own(x1,y1);\r\n\t\tlong gcd=gcdExt(b,a%b,p1);\r\n\t\tp.b=p1.a - (a/b) * p1.b;\r\n\t\tp.a=p1.b;\r\n\t\treturn gcd;\r\n\t}\r\n\tpublic static long pwr(long m,long n)\r\n\t{\r\n\t\tlong res=1;\r\n\t\tif(m==0)\r\n\t\treturn 0;\r\n\t\twhile(n>0)\r\n\t\t{\r\n\t\t\tif((n&1)!=0)\r\n\t\t\t{\r\n\t\t\t\tres=(res*m);\r\n\t\t\t}\r\n\t\t\tn=n>>1;\r\n\t\t\tm=(m*m);\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\tpublic static long modpwr(long m,long n)\r\n\t{\r\n\t\tlong res=1;\r\n\t\tm=m%mod;\r\n\t\tif(m==0)\r\n\t\treturn 0;\r\n\t\twhile(n>0)\r\n\t\t{\r\n\t\t\tif((n&1)!=0)\r\n\t\t\t{\r\n\t\t\t\tres=(res*m)%mod;\r\n\t\t\t}\r\n\t\t\tn=n>>1;\r\n\t\t\tm=(m*m)%mod;\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\tpublic static class own\r\n {\r\n \tlong a;\r\n \tlong b;\r\n \tpublic own(long val,long index)\r\n \t{\r\n \t a=val;\r\n \t b=index;\r\n \t}\r\n }\r\n\r\n\t//Modular Airthmetic\r\n\r\n\tpublic static void sort(int[] A)\r\n\t{\r\n int n = A.length;\r\n Random rnd = new Random();\r\n for(int i=0; ia)p--;return p;}\r\n\tpublic static long sqrt(long a){long p=(long)Math.sqrt(a);if(p*p>a)p--;return p;}\r\n\t//end\r\n\r\n\tpublic static int[] I(int n)throws IOException{int a[]=new int[n];for(int i=0;i n) {\n out.println(0);\n return;\n }\n long[][] dp1 = new long[n + 1][k + 1], dp2 = new long[n + 1][k + 1];\n dp1[1][0] = 1;\n \n long[][] choose = new long[n + 1][n + 1];\n choose[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n choose[i][0] = 1;\n for (int j = 1; j <= n; j++) {\n choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % MOD;\n }\n }\n \n for (int i = 2; i <= n; i++) {\n for (int j = 0; j <= k; j++) {\n\n // 1 child\n dp1[i][j] += dp2[i - 1][j] * (i - 1);\n dp1[i][j] %= MOD;\n if (j > 0) {\n dp2[i][j] += dp1[i - 1][j - 1] * (i - 1);\n dp2[i][j] %= MOD;\n }\n\n // 2 children\n for (int size1 = 1; size1 < (i - 1) - size1; size1++) {\n for (int match1 = 0; match1 <= j; match1++) {\n long add = dp2[size1][match1] * dp2[i - 1 - size1][j - match1] % MOD;\n dp1[i][j] = (add * choose[i - 1][size1]) % MOD * size1 * (i - 1 - size1);\n dp1[i][j] %= MOD;\n }\n }\n for (int size1 = 1; size1 < (i - 1) - size1; size1++) {\n for (int match1 = 0; match1 <= j - 1; match1++) {\n long add = (dp1[size1][match1] * dp1[i - 1 - size1][j - 1 - match1]\n + dp1[size1][match1] * dp2[i - 1 - size1][j - 1 - match1]\n + dp2[size1][match1] * dp1[i - 1 - size1][j - 1 - match1]) % MOD;\n dp2[i][j] += (add * choose[i - 1][size1]) % MOD * size1 * (i - 1 - size1);\n dp2[i][j] %= MOD;\n }\n }\n \n // 2 children of equal size\n if ((i - 1) % 2 == 0) {\n int size1 = (i - 1) / 2;\n \n for (int match1 = 0; match1 < j - match1; match1++ ){\n long add = dp2[size1][match1] * dp2[size1][j - match1] % MOD;\n dp1[i][j] += (add * choose[i - 1][size1]) % MOD * size1 * (i - 1 - size1);\n dp1[i][j] %= MOD;\n }\n if (j % 2 == 0) {\n int match1 = j / 2;\n long add = (dp2[size1][match1] * (dp2[size1][match1] - 1) / 2) % MOD;\n dp1[i][j] += (add * choose[i - 1][size1]) % MOD * size1 * (i - 1 - size1);\n dp1[i][j] %= MOD;\n \n add = dp2[size1][match1];\n add = (add * (i - 1) * (i - 2) / 2) % MOD;\n add = (add * choose[i - 3][size1 - 1]) % MOD;\n dp1[i][j] += add;\n dp1[i][j] %= MOD;\n }\n \n for (int match1 = 0; match1 < j - 1 - match1; match1++) {\n long add = (dp1[size1][match1] * dp1[size1][j - 1 - match1]\n + dp1[size1][match1] * dp2[size1][j - 1 - match1]\n + dp2[size1][match1] * dp1[size1][j - 1 - match1]) % MOD;\n dp2[i][j] += (add * choose[i - 1][size1]) % MOD * size1 * (i - 1 - size1);\n dp2[i][j] %= MOD;\n }\n \n if ((j - 1) % 2 == 0) {\n int match1 = (j - 1) / 2;\n long add = (dp1[size1][match1] * dp2[size1][match1]) % MOD;\n dp2[i][j] += (add * choose[i - 1][size1]) % MOD * size1 * (i - 1 - size1);\n dp2[i][j] %= MOD;\n \n add = (dp1[size1][match1] * (dp1[size1][match1] - 1) / 2) % MOD;\n dp2[i][j] += (add * choose[i - 1][size1]) % MOD * size1 * (i - 1 - size1);\n dp2[i][j] %= MOD;\n \n add = dp1[size1][match1];\n add = (add * (i - 1) * (i - 2) / 2) % MOD;\n add = (add * choose[i - 3][size1 - 1]) % MOD;\n dp2[i][j] += add;\n dp2[i][j] %= MOD;\n }\n }\n }\n }\n\n out.println((dp1[n][k] + dp2[n][k]) % MOD);\n }\n\n FastScanner in;\n PrintWriter out;\n\n public void run() {\n try {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public FastScanner(String name) {\n try {\n br = new BufferedReader(new FileReader(name));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public String nextToken() {\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(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 public static void main(String[] args) {\n new E().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a6c9cd0241d0a2658f033d6ce61a943", "src_uid": "f98b740183281943eafd90328854746b", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import sun.misc.Compare;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.util.*;\n\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n// boolean oj = true;\n try{\n if( oj ){\n sc = new FastScanner( new InputStreamReader(System.in ) );\n out = new PrintWriter( new OutputStreamWriter(System.out) );\n } else{\n sc = new FastScanner(new FileReader(\"in.txt\") );\n// sc = new FastScanner(new FileReader(\"D:\\\\JavaOlymp\\\\FatalError\\\\output.txt\") );\n out = new PrintWriter( new FileWriter(\"out.txt\") );\n }\n } catch (Exception e) {\n System.exit(-1);\n }\n long tB = System.currentTimeMillis();\n solve();\n if( !oj ) System.err.println( \"Time: \" + (System.currentTimeMillis()-tB)/1e3 );\n out.flush();\n }\n\n\n class FastScanner{\n BufferedReader br;\n StringTokenizer st = new StringTokenizer(\"\");\n FastScanner( InputStreamReader a ){\n br = new BufferedReader(a);\n }\n FastScanner( FileReader a ){\n br = new BufferedReader(a);\n }\n String next(){\n while( !st.hasMoreTokens() )\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n return null;\n }\n return st.nextToken();\n }\n String readLine(){\n try {\n return br.readLine();\n } catch (Exception e) {\n return null;\n }\n }\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n }\n\n FastScanner sc;\n PrintWriter out;\n\n\n\n public static void main(String[] args){\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"LOL\", 256L * 1024 * 1024 / 2 ).run();\n// }, \"LOL\", 2000 * 1024 * 1024 ).run();\n }\n\n\n\n void TLE(){ for(;;); }\n\n void MLE(){\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 void exit( int val ){\n out.flush();\n System.exit(val);\n }\n //////////////////////////////////////////////////////////////////////////////////////////\n\n\n long[][][] dp;\n final long inf = Long.MAX_VALUE / 1000,\n mod = 1000000007 ;\n\n BigInteger fact( int n ){\n return n<=1? ONE : valueOf(n).multiply(fact(n-1));\n }\n\n long C( int m, int n ){\n if(!( m <= n )) MLE();\n return fact(n).divide( fact(m).multiply(fact(n-m)) ).mod(valueOf(mod)).longValue();\n }\n\n long powMod( long a, long p ){\n if( p == 0 ) return 1;\n long ans = powMod(a,p/2);\n ans = (ans*ans) % mod;\n if( p%2==1 ) ans = (a*ans) % mod;\n return ans;\n }\n\n long getDP( int n, int k, int isNeed ){\n if (n <= 0 || k < 0) return 0;\n\n if( dp[n][k][isNeed] == inf ){\n long ans = 0;\n\n if( n == 1 ){\n if( k==0 && isNeed == 0 )\n ans = 1;\n else\n ans = 0;\n }\n else{\n for( int nl = 1; nl <= n-2; ++nl ){\n for( int kl = 0; kl <= (isNeed==1?k-1:k); ++kl ){\n long cur = (C(nl,n-1) * n) % mod;\n if( isNeed==1 ){\n cur *=\n getDP(nl, kl, 0)*getDP(n-1-nl, k-1-kl, 1) +\n getDP(nl, kl, 1)*getDP(n-1-nl, k-1-kl, 0) +\n getDP(nl, kl, 0)*getDP(n-1-nl, k-1-kl, 0);\n }\n else{\n cur *=\n getDP(nl,kl,1)*getDP(n-1-nl,k-kl,1);\n }\n ans = (ans + cur) % mod;\n if( n==3 ){\n n = 3;\n// out.printf( \":: %d/%d %d/%d %d\\n\", nl,n, kl,k, isNeed );\n }\n }\n }\n ans = ans * powMod(2,mod-2) % mod;\n if( isNeed == 1 )\n ans = ( ans + n*getDP(n-1,k-1,0) ) %mod;\n else\n ans = ( ans + n*getDP(n-1,k ,1) ) %mod;\n }\n dp[n][k][isNeed] = ans;\n }\n return dp[n][k][isNeed];\n }\n\n void solve(){\n int n, k;\n\n n = sc.nextInt();\n k = sc.nextInt();\n dp = new long[n+1][k+1][2];\n for( long[][] a : dp )\n for( long[] b : a )\n fill( b, inf );\n\n\n long ans = getDP(n, k, 0) + getDP(n, k, 1);\n ans %= mod;\n ans = ans * powMod( n, mod - 2 ) % mod;\n out.println( ans );\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ed27e2b4149aa07a73fb3af59957756f", "src_uid": "f98b740183281943eafd90328854746b", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import sun.misc.Compare;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.util.*;\n\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n// boolean oj = true;\n try{\n if( oj ){\n sc = new FastScanner( new InputStreamReader(System.in ) );\n out = new PrintWriter( new OutputStreamWriter(System.out) );\n } else{\n sc = new FastScanner(new FileReader(\"in.txt\") );\n// sc = new FastScanner(new FileReader(\"D:\\\\JavaOlymp\\\\FatalError\\\\output.txt\") );\n out = new PrintWriter( new FileWriter(\"out.txt\") );\n }\n } catch (Exception e) {\n System.exit(-1);\n }\n long tB = System.currentTimeMillis();\n solve();\n if( !oj ) System.err.println( \"Time: \" + (System.currentTimeMillis()-tB)/1e3 );\n out.flush();\n }\n\n\n class FastScanner{\n BufferedReader br;\n StringTokenizer st = new StringTokenizer(\"\");\n FastScanner( InputStreamReader a ){\n br = new BufferedReader(a);\n }\n FastScanner( FileReader a ){\n br = new BufferedReader(a);\n }\n String next(){\n while( !st.hasMoreTokens() )\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n return null;\n }\n return st.nextToken();\n }\n String readLine(){\n try {\n return br.readLine();\n } catch (Exception e) {\n return null;\n }\n }\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n }\n\n FastScanner sc;\n PrintWriter out;\n\n\n\n public static void main(String[] args){\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"LOL\", 256L * 1024 * 1024 / 2 ).run();\n// }, \"LOL\", 2000 * 1024 * 1024 ).run();\n }\n\n\n\n void TLE(){ for(;;); }\n\n void MLE(){\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 void exit( int val ){\n out.flush();\n System.exit(val);\n }\n //////////////////////////////////////////////////////////////////////////////////////////\n\n\n long[][][] dp;\n final long inf = Long.MAX_VALUE / 1000,\n mod = 1000000007 ;\n\n BigInteger fact( int n ){\n return n<=1? ONE : valueOf(n).multiply(fact(n-1));\n }\n\n long C( int m, int n ){\n if(!( m <= n )) MLE();\n return fact(n).divide( fact(m).multiply(fact(n-m)) ).mod(valueOf(mod)).longValue();\n }\n\n long powMod( long a, long p ){\n if( p == 0 ) return 1;\n long ans = powMod(a,p/2);\n ans = (ans*ans) % mod;\n if( p%2==1 ) ans = (a*ans) % mod;\n return ans;\n }\n\n long getDP( int n, int k, int isNeed ){\n if (n <= 0 || k < 0) return 0;\n\n if( dp[n][k][isNeed] == inf ){\n long ans = 0;\n\n if( n == 1 ){\n if( k==0 && isNeed == 0 )\n ans = 1;\n else\n ans = 0;\n }\n else{\n for( int nl = 1; nl <= n-2; ++nl ){\n for( int kl = 0; kl <= min( nl/2, (isNeed==1?k-1:k)); ++kl ){\n long cur = (C(nl,n-1) * n) % mod;\n if( isNeed==1 ){\n cur *=(\n getDP(nl, kl, 0)*getDP(n-1-nl, k-1-kl, 1) +\n getDP(nl, kl, 1)*getDP(n-1-nl, k-1-kl, 0) +\n getDP(nl, kl, 0)*getDP(n-1-nl, k-1-kl, 0)\n ) % mod;\n }\n else{\n cur *=\n getDP(nl,kl,1)*getDP(n-1-nl,k-kl,1) % mod;\n }\n ans = (ans + cur) % mod;\n if( n==3 ){\n n = 3;\n// out.printf( \":: %d/%d %d/%d %d\\n\", nl,n, kl,k, isNeed );\n }\n }\n }\n ans = ans * powMod(2,mod-2) % mod;\n if( isNeed == 1 )\n ans = ( ans + n*getDP(n-1,k-1,0) ) %mod;\n else\n ans = ( ans + n*getDP(n-1,k ,1) ) %mod;\n }\n dp[n][k][isNeed] = ans;\n }\n return dp[n][k][isNeed];\n }\n\n void solve(){\n int n, k;\n\n n = sc.nextInt();\n k = sc.nextInt();\n dp = new long[n+1][k+1][2];\n for( long[][] a : dp )\n for( long[] b : a )\n fill( b, inf );\n\n\n long ans = getDP(n, k, 0) + getDP(n, k, 1);\n ans %= mod;\n ans = ans * powMod( n, mod - 2 ) % mod;\n out.println( ans );\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a89f06ba2f258500f16e066c0b10d222", "src_uid": "f98b740183281943eafd90328854746b", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import sun.misc.Compare;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.util.*;\n\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n// boolean oj = true;\n try{\n if( oj ){\n sc = new FastScanner( new InputStreamReader(System.in ) );\n out = new PrintWriter( new OutputStreamWriter(System.out) );\n } else{\n sc = new FastScanner(new FileReader(\"in.txt\") );\n// sc = new FastScanner(new FileReader(\"D:\\\\JavaOlymp\\\\FatalError\\\\output.txt\") );\n out = new PrintWriter( new FileWriter(\"out.txt\") );\n }\n } catch (Exception e) {\n System.exit(-1);\n }\n long tB = System.currentTimeMillis();\n solve();\n if( !oj ) System.err.println( \"Time: \" + (System.currentTimeMillis()-tB)/1e3 );\n out.flush();\n }\n\n\n class FastScanner{\n BufferedReader br;\n StringTokenizer st = new StringTokenizer(\"\");\n FastScanner( InputStreamReader a ){\n br = new BufferedReader(a);\n }\n FastScanner( FileReader a ){\n br = new BufferedReader(a);\n }\n String next(){\n while( !st.hasMoreTokens() )\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n return null;\n }\n return st.nextToken();\n }\n String readLine(){\n try {\n return br.readLine();\n } catch (Exception e) {\n return null;\n }\n }\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n }\n\n FastScanner sc;\n PrintWriter out;\n\n\n\n public static void main(String[] args){\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"LOL\", 256L * 1024 * 1024 / 2 ).run();\n// }, \"LOL\", 2000 * 1024 * 1024 ).run();\n }\n\n\n\n void TLE(){ for(;;); }\n\n void MLE(){\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 void exit( int val ){\n out.flush();\n System.exit(val);\n }\n //////////////////////////////////////////////////////////////////////////////////////////\n\n\n long[][][] dp;\n final long inf = Long.MAX_VALUE / 1000,\n mod = 1000000007 ;\n\n BigInteger fact( int n ){\n return n<=1? ONE : valueOf(n).multiply(fact(n-1));\n }\n\n long C( int m, int n ){\n if(!( m <= n )) MLE();\n return fact(n).divide( fact(m).multiply(fact(n-m)) ).mod(valueOf(mod)).longValue();\n }\n\n long powMod( long a, long p ){\n if( p == 0 ) return 1;\n long ans = powMod(a,p/2);\n ans = (ans*ans) % mod;\n if( p%2==1 ) ans = (a*ans) % mod;\n return ans;\n }\n\n long getDP( int n, int k, int isNeed ){\n if (n <= 0 || k < 0) return 0;\n\n if( dp[n][k][isNeed] == inf ){\n long ans = 0;\n\n if( n == 1 ){\n if( k==0 && isNeed == 0 )\n ans = 1;\n else\n ans = 0;\n }\n else{\n for( int nl = 1; nl <= n-2; ++nl ){\n for( int kl = 0; kl <= (isNeed==1?k-1:k); ++kl ){\n long cur = (C(nl,n-1) * n) % mod;\n if( isNeed==1 ){\n cur *=(\n getDP(nl, kl, 0)*getDP(n-1-nl, k-1-kl, 1)%mod +\n getDP(nl, kl, 1)*getDP(n-1-nl, k-1-kl, 0)%mod +\n getDP(nl, kl, 0)*getDP(n-1-nl, k-1-kl, 0)%mod\n ) % mod;\n }\n else{\n cur *=\n getDP(nl,kl,1)*getDP(n-1-nl,k-kl,1) % mod;\n }\n ans = (ans + cur) % mod;\n if( n==3 ){\n n = 3;\n// out.printf( \":: %d/%d %d/%d %d\\n\", nl,n, kl,k, isNeed );\n }\n }\n }\n ans = ans * powMod(2,mod-2) % mod;\n if( isNeed == 1 )\n ans = ( ans + n*getDP(n-1,k-1,0) ) %mod;\n else\n ans = ( ans + n*getDP(n-1,k ,1) ) %mod;\n }\n dp[n][k][isNeed] = ans;\n }\n return dp[n][k][isNeed];\n }\n\n void solve(){\n int n, k;\n\n n = sc.nextInt();\n k = sc.nextInt();\n dp = new long[n+1][k+1][2];\n for( long[][] a : dp )\n for( long[] b : a )\n fill( b, inf );\n\n\n long ans = getDP(n, k, 0) + getDP(n, k, 1);\n ans %= mod;\n ans = ans * powMod( n, mod - 2 ) % mod;\n out.println( ans );\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a037997d73a663288fbad9f8e1c4f4e", "src_uid": "f98b740183281943eafd90328854746b", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\nimport java.util.ArrayList;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskE {\n\t\tList ps;\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tlong x = in.nextLong();\n\t\t\tlong y = in.nextLong();\n\t\t\tcalcPrimeDivisors(x);\n\t\t\tout.println(f(x, y));\n\t\t}\n\n\t\tprivate void calcPrimeDivisors(long x) {\n\t\t\tps = new ArrayList<>();\n\t\t\tfor (long p = 2; p * p <= x; p++) {\n\t\t\t\tif (x % p == 0) {\n\t\t\t\t\tps.add(p);\n\t\t\t\t\twhile (x % p == 0) {\n\t\t\t\t\t\tx /= p;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x > 1) {\n\t\t\t\tps.add(x);\n\t\t\t}\n\t\t}\n\n\t\tprivate long f(long a, long b) {\n\t\t\tif (b == 0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tlong d = gcd(a, b);\n\t\t\tif (d != 1) {\n\t\t\t\treturn f(a / d, b / d);\n\t\t\t}\n\t\t\tlong bestB = b - 1;\n\t\t\tfor (long p : ps) {\n\t\t\t\tlong nb = b / p * p;\n\t\t\t\tif (gcd(a, nb) != 1) {\n\t\t\t\t\tbestB = Math.max(bestB, nb);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b - bestB + f(a, bestB);\n\t\t}\n\n\t\tprivate long gcd(long a, long b) {\n\t\t\treturn b == 0 ? a : gcd(b, a % b);\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString rl = in.readLine();\n\t\t\t\t\tif (rl == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(rl);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3166714cf76e7580b1c0c69f8e1a02f0", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\tpublic void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tSystem.out.println(f(a, b));\n\t}\n\n\tlong f(long a, long b) {\n\t\tif (a == b)\n\t\t\treturn 1;\n\t\tif (b == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (isPrime(a)) {\n\t\t\tif (a <= b) {\n\t\t\t\treturn f(a, a) + (b - a);\n\t\t\t} else {\n\t\t\t\treturn b;\n\t\t\t}\n\t\t}\n\t\tlong gcd = gcd(a, b);\n\t\treturn 1 + f(a / gcd, b / gcd - 1);\n\t\t// int c = 1;\n\t\t// while (b > 0 && gcd(a, b) == 1) {\n\t\t// --b;\n\t\t// }\n\t\t// if (gcd(a, b) != 1) {\n\t\t// long gcd = gcd(a, b);\n\t\t// return c + f(a / gcd, b / gcd - 1);\n\t\t// } else {\n\t\t// return c + f(a, b);\n\t\t// }\n\t}\n\n\tlong gcd(long a, long b) {\n\t\tif (a < b) {\n\t\t\tlong d = a;\n\t\t\ta = b;\n\t\t\tb = d;\n\t\t}\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tstatic boolean isPrime(long n) {\n\t\t// \u9593\u9055\u3048\u308b\u78ba\u73874^(-k)=10^(-6)\n\t\tif (n == 1 || n % 2 == 0)\n\t\t\treturn false;\n\t\tlong z = n - 1;\n\t\tint c2 = 0;\n\t\twhile (z % 2 == 0) {\n\t\t\tz /= 2;\n\t\t\t++c2;\n\t\t}\n\t\touter: for (int k = 0; k < 10; ++k) {\n\t\t\tlong a = (int) (Math.random() * 10000) % n;\n\t\t\tif (a == 0)\n\t\t\t\tcontinue;\n\t\t\ta = pow(a, z, n);\n\t\t\tif (a == 1 || a == n - 1)\n\t\t\t\tcontinue outer;\n\t\t\tfor (int i = 0; i < c2 - 1; ++i) {\n\t\t\t\ta = (a * a) % n;\n\t\t\t\tif (a == n - 1)\n\t\t\t\t\tcontinue outer;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tstatic long pow(long a, long n, long mod) {\n\t\tlong ret = 1;\n\t\tfor (; n > 0; n >>= 1, a = (a * a) % mod) {\n\t\t\tif (n % 2 == 1) {\n\t\t\t\tret = (ret * a) % mod;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\n\tstatic void tr(Object... objects) {\n\t\tSystem.out.println(Arrays.deepToString(objects));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "753d526d28be450506ff47c966daaa74", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "/*\nKeep solving problems.\n*/\n\nimport java.util.*;\nimport java.io.*;\n\npublic class CFA {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n private static final long MOD = 1000 * 1000 * 1000 + 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 long res = 0;\n void solve() throws IOException {\n long x = nextLong();\n long y = nextLong();\n helper(x, y);\n outln(res);\n }\n\n void helper(long x, long y) {\n if (isPrime(x)) {\n res += y / x + y % x;\n return;\n }\n\n long g = gcd(x, y);\n helper(x / g, y / g);\n }\n\n boolean isPrime(long x) {\n for (long i = 2; i * i <= x; i++) {\n if (x % i == 0) {\n return false;\n }\n }\n\n return true;\n }\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\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\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 System.out.format(\"%.9f%n\", val);\n }\n public CFA() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n public static void main(String[] args) throws IOException {\n new CFA();\n }\n\n public long[] nextLongArr(int n) throws IOException{\n long[] res = new long[n];\n for(int i = 0; i < n; i++)\n res[i] = nextLong();\n return res;\n }\n public int[] nextIntArr(int n) throws IOException {\n int[] res = new int[n];\n for(int i = 0; i < n; i++)\n res[i] = nextInt();\n return res;\n }\n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n eof = true;\n return null;\n }\n }\n return st.nextToken();\n }\n public String nextString() {\n try {\n return br.readLine();\n } catch (IOException e) {\n eof = true;\n return null;\n }\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "196e54185a9b97287ba89b022de09724", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class e{\n\tstatic long gcd(long a, long b){\n\t\treturn b == 0? a: gcd(b, a % b);\n\t}\n\t// okay\n\t// i see why i got hacked\n\t// i only considered the SMALLEST factor of x\n\t// i should really consider ALL factors of x\n\t\n\tstatic long f(long x, long y){\n\t\tif(y == 0) return 0;\n\t\tif(x == 1 || y == 1) return y;\n\t\tlong gcd = gcd(x,y);\n\t\tif(gcd > 1){\n\t\t\treturn f(x / gcd, y / gcd);\n\t\t}\n\t\t\n\t\t// smallest factor of f?\n\t\tlong diff = Long.MAX_VALUE;\n\t\tlong fac, temp;\n\t\tfor(fac = 2, temp = x; fac*fac <= temp; fac++){\n\t\t\tif(temp % fac == 0){\n\t\t\t\tdiff = Math.min(diff, y - (y / fac * fac));\n\t\t\t\twhile(temp % fac == 0){\n\t\t\t\t\ttemp /= fac;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(fac*fac > temp){\n\t\t\tdiff = Math.min(diff, y - (y / temp * temp));\n\t\t}\n\t\t\n\t\treturn diff + f(x, y - diff);\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong X = in.nextLong();\n\t\tlong Y = in.nextLong();\n\t\t\n\t\tSystem.out.println(f(X,Y));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "445bb66bf712f62731a176411f0f73c6", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint[] qtyBits = new int[30];\n\t\tint[] qtyRequests = new int[30];\n\t\tint count = in.readInt();\n\t\tint requestCount = in.readInt();\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tint cell = in.readInt();\n\t\t\tfor (int j = 0; j < 30; j++) {\n\t\t\t\tif ((cell >> j & 1) == 1)\n\t\t\t\t\tqtyBits[j]++;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < requestCount; i++)\n\t\t\tqtyRequests[in.readInt()]++;\n\t\tint answer = 0;\n\t\tIntList weights = new IntArrayList();\n\t\tfor (int i = 0; i < 30; i++) {\n\t\t\tfor (int j = 0; j < qtyRequests[i]; j++)\n\t\t\t\tweights.add(1);\n\t\t\tfor (int j = 0; j < weights.size() && j < qtyBits[i]; j++)\n\t\t\t\tanswer += weights.get(j);\n\t\t\tIntList newWeights = new IntArrayList();\n\t\t\tfor (int j = qtyBits[i]; j < weights.size(); j += 2) {\n\t\t\t\tint totalWeight = weights.get(j);\n\t\t\t\tif (j + 1 < weights.size())\n\t\t\t\t\ttotalWeight += weights.get(j + 1);\n\t\t\t\tnewWeights.add(totalWeight);\n\t\t\t}\n\t\t\tweights = newWeights;\n\t\t}\n\t\tout.printLine(answer);\n }\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic 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\nabstract class IntList extends IntCollection implements Comparable {\n\tprivate static final int INSERTION_THRESHOLD = 8;\n\n\tpublic abstract int get(int index);\n\tpublic abstract void set(int index, int value);\n\n\tpublic IntIterator iterator() {\n\t\treturn new IntIterator() {\n\t\t\tprivate int size = size();\n\t\t\tprivate int index = 0;\n\n\t\t\tpublic int value() throws NoSuchElementException {\n\t\t\t\tif (!isValid())\n\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\treturn get(index);\n\t\t\t}\n\n\t\t\tpublic void advance() throws NoSuchElementException {\n\t\t\t\tif (!isValid())\n\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\tindex++;\n\t\t\t}\n\n\t\t\tpublic boolean isValid() {\n\t\t\t\treturn index < size;\n\t\t\t}\n\t\t};\n\t}\n\n\tprivate void swap(int first, int second) {\n\t\tif (first == second)\n\t\t\treturn;\n\t\tint temp = get(first);\n\t\tset(first, get(second));\n\t\tset(second, temp);\n\t}\n\n\tpublic IntSortedList inPlaceSort(IntComparator comparator) {\n\t\tquickSort(0, size() - 1, size(), comparator);\n\t\treturn new IntSortedArray(this, comparator);\n\t}\n\n\tprivate void quickSort(int from, int to, int remaining, IntComparator comparator) {\n\t\tif (to - from < INSERTION_THRESHOLD) {\n\t\t\tinsertionSort(from, to, comparator);\n\t\t\treturn;\n\t\t}\n\t\tif (remaining == 0) {\n\t\t\theapSort(from, to, comparator);\n\t\t\treturn;\n\t\t}\n\t\tremaining >>= 1;\n\t\tint pivotIndex = (from + to) >> 1;\n\t\tint pivot = get(pivotIndex);\n\t\tswap(pivotIndex, to);\n\t\tint storeIndex = from;\n\t\tint equalIndex = to;\n\t\tfor (int i = from; i < equalIndex; i++) {\n\t\t\tint value = comparator.compare(get(i), pivot);\n\t\t\tif (value < 0)\n\t\t\t\tswap(storeIndex++, i);\n\t\t\telse if (value == 0)\n\t\t\t\tswap(--equalIndex, i--);\n\t\t}\n\t\tquickSort(from, storeIndex - 1, remaining, comparator);\n\t\tfor (int i = equalIndex; i <= to; i++)\n\t\t\tswap(storeIndex++, i);\n\t\tquickSort(storeIndex, to, remaining, comparator);\n\t}\n\n\tprivate void heapSort(int from, int to, IntComparator comparator) {\n\t\tfor (int i = (to + from - 1) >> 1; i >= from; i--)\n\t\t\tsiftDown(i, to, comparator, from);\n\t\tfor (int i = to; i > from; i--) {\n\t\t\tswap(from, i);\n\t\t\tsiftDown(from, i - 1, comparator, from);\n\t\t}\n\t}\n\n\tprivate void siftDown(int start, int end, IntComparator comparator, int delta) {\n\t\tint value = get(start);\n\t\twhile (true) {\n\t\t\tint child = ((start - delta) << 1) + 1 + delta;\n\t\t\tif (child > end)\n\t\t\t\treturn;\n\t\t\tint childValue = get(child);\n\t\t\tif (child + 1 <= end) {\n\t\t\t\tint otherValue = get(child + 1);\n\t\t\t\tif (comparator.compare(otherValue, childValue) > 0) {\n\t\t\t\t\tchild++;\n\t\t\t\t\tchildValue = otherValue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (comparator.compare(value, childValue) >= 0)\n\t\t\t\treturn;\n\t\t\tswap(start, child);\n\t\t\tstart = child;\n\t\t}\n\t}\n\n\tprivate void insertionSort(int from, int to, IntComparator comparator) {\n\t\tfor (int i = from + 1; i <= to; i++) {\n\t\t\tint value = get(i);\n\t\t\tfor (int j = i - 1; j >= from; j--) {\n\t\t\t\tif (comparator.compare(get(j), value) <= 0)\n\t\t\t\t\tbreak;\n\t\t\t\tswap(j, j + 1);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic IntSortedList sort(IntComparator comparator) {\n\t\treturn new IntArray(this).inPlaceSort(comparator);\n\t}\n\n\tpublic int hashCode() {\n\t\tint hashCode = 1;\n\t\tfor (IntIterator i = iterator(); i.isValid(); i.advance())\n\t\t\thashCode = 31 * hashCode + i.value();\n\t\treturn hashCode;\n\t}\n\n\tpublic boolean equals(Object obj) {\n\t\tif (!(obj instanceof IntList))\n\t\t\treturn false;\n\t\tIntList list = (IntList)obj;\n\t\tif (list.size() != size())\n\t\t\treturn false;\n\t\tIntIterator i = iterator();\n\t\tIntIterator j = list.iterator();\n\t\twhile (i.isValid()) {\n\t\t\tif (i.value() != j.value())\n\t\t\t\treturn false;\n\t\t\ti.advance();\n\t\t\tj.advance();\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic int compareTo(IntList o) {\n\t\tIntIterator i = iterator();\n\t\tIntIterator j = o.iterator();\n\t\twhile (true) {\n\t\t\tif (i.isValid()) {\n\t\t\t\tif (j.isValid()) {\n\t\t\t\t\tif (i.value() != j.value()) {\n\t\t\t\t\t\tif (i.value() < j.value())\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t} else\n\t\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\tif (j.isValid())\n\t\t\t\t\treturn -1;\n\t\t\t\telse\n\t\t\t\t\treturn 0;\n\t\t\t}\n\t\t\ti.advance();\n\t\t\tj.advance();\n\t\t}\n\t}\n\n\t}\n\nclass IntArrayList extends IntList {\n\tprivate int[] array;\n\tprivate int size;\n\n\tpublic IntArrayList() {\n\t\tthis(10);\n\t}\n\n\tpublic IntArrayList(int capacity) {\n\t\tarray = new int[capacity];\n\t}\n\n\tpublic int get(int index) {\n\t\tif (index >= size)\n\t\t\tthrow new IndexOutOfBoundsException();\n\t\treturn array[index];\n\t}\n\n\tpublic void set(int index, int value) {\n\t\tif (index >= size)\n\t\t\tthrow new IndexOutOfBoundsException();\n\t\tarray[index] = value;\n\t}\n\n\tpublic int size() {\n\t\treturn size;\n\t}\n\n\tpublic void add(int value) {\n\t\tensureCapacity(size + 1);\n\t\tarray[size++] = value;\n\t}\n\n\tprivate void ensureCapacity(int newCapacity) {\n\t\tif (newCapacity > array.length) {\n\t\t\tint[] newArray = new int[Math.max(newCapacity, array.length << 1)];\n\t\t\tSystem.arraycopy(array, 0, newArray, 0, size);\n\t\t\tarray = newArray;\n\t\t}\n\t}\n\n\t}\n\nabstract class IntCollection {\n\tpublic abstract IntIterator iterator();\n\tpublic abstract int size();\n\tpublic abstract void add(int value);\n\n\t}\n\ninterface IntIterator {\n\tpublic int value() throws NoSuchElementException;\n\t/*\n\t * @throws NoSuchElementException only if iterator already invalid\n\t */\n\tpublic void advance() throws NoSuchElementException;\n\tpublic boolean isValid();\n}\n\ninterface IntComparator {\n public static final IntComparator DEFAULT = new IntComparator() {\n public int compare(int first, int second) {\n if (first < second)\n return -1;\n if (first > second)\n return 1;\n return 0;\n }\n };\n\n\tpublic int compare(int first, int second);\n}\n\nabstract class IntSortedList extends IntList {\n\tprotected final IntComparator comparator;\n\n\tprotected IntSortedList(IntComparator comparator) {\n\t\tthis.comparator = comparator;\n\t}\n\n\tpublic void set(int index, int value) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\tpublic void add(int value) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\tpublic IntSortedList inPlaceSort(IntComparator comparator) {\n\t\tif (comparator == this.comparator)\n\t\t\treturn this;\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\tpublic IntSortedList sort(IntComparator comparator) {\n\t\tif (comparator == this.comparator)\n\t\t\treturn this;\n\t\treturn super.sort(comparator);\n\t}\n\n\tprotected void ensureSorted() {\n\t\tint size = size();\n\t\tif (size == 0)\n\t\t\treturn;\n\t\tint last = get(0);\n\t\tfor (int i = 1; i < size; i++) {\n\t\t\tint current = get(i);\n\t\t\tif (comparator.compare(last, current) > 0)\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t\tlast = current;\n\t\t}\n\t}\n\n\t}\n\nclass IntSortedArray extends IntSortedList {\n\tprivate final int[] array;\n\n\tpublic IntSortedArray(int[] array) {\n\t\tthis(array, IntComparator.DEFAULT);\n\t}\n\n\tpublic IntSortedArray(IntCollection collection) {\n\t\tthis(collection, IntComparator.DEFAULT);\n\t}\n\n\tpublic IntSortedArray(int[] array, IntComparator comparator) {\n\t\tsuper(comparator);\n\t\tthis.array = array;\n\t\tensureSorted();\n\t}\n\n\tpublic IntSortedArray(IntCollection collection, IntComparator comparator) {\n\t\tsuper(comparator);\n\t\tarray = new int[collection.size()];\n\t\tint i = 0;\n\t\tfor (IntIterator iterator = collection.iterator(); iterator.isValid(); iterator.advance())\n\t\t\tarray[i++] = iterator.value();\n\t\tensureSorted();\n\t}\n\n\tpublic int get(int index) {\n\t\treturn array[index];\n\t}\n\n\tpublic int size() {\n\t\treturn array.length;\n\t}\n}\n\nclass IntArray extends IntList {\n\tprivate final int[] array;\n\n\tpublic IntArray(int[] array) {\n\t\tthis.array = array;\n\t}\n\n\tpublic IntArray(IntCollection collection) {\n\t\tarray = new int[collection.size()];\n\t\tint i = 0;\n\t\tfor (IntIterator iterator = collection.iterator(); iterator.isValid(); iterator.advance())\n\t\t\tarray[i++] = iterator.value();\n\t}\n\n\tpublic int get(int index) {\n\t\treturn array[index];\n\t}\n\n\tpublic void set(int index, int value) {\n\t\tarray[index] = value;\n\t}\n\n\tpublic int size() {\n\t\treturn array.length;\n\t}\n\n\tpublic void add(int value) {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "373fe6cf91c11128bb6d616c3ff9db37", "src_uid": "e95fb7d4309747834b37d4bc3468afb7", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\tBufferedReader br;\n\tStringTokenizer in;\n\tPrintWriter out;\n\n\tpublic String nextToken() throws IOException {\n\t\twhile (in == null || !in.hasMoreTokens()) {\n\t\t\tString z = br.readLine();\n\t\t\tif (z == null)\n\t\t\t\treturn null;\n\t\t\tin = new StringTokenizer(z);\n\t\t}\n\t\treturn in.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\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\n\t\tlong[] cnt = new long[30];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint z = nextInt();\n\t\t\tfor (int j = 29; j >= 0; j--) {\n\t\t\t\tif (z >= 1 << j) {\n\t\t\t\t\tz -= 1 << j;\n\t\t\t\t\tcnt[j]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint[] c = new int[30];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tc[nextInt()]++;\n\t\t}\n\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < 30; i++) {\n\t\t\tboolean good = true;\n\t\t\twhile (c[i] > 0) {\n\t\t\t\tint j = i;\n\t\t\t\twhile (j < 30 && cnt[j] == 0) {\n\t\t\t\t\tj++;\n\t\t\t\t}\n\n\t\t\t\tif (j == 30) {\n\t\t\t\t\tgood = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tfor (int k = j; k > i; k--) {\n\t\t\t\t\tcnt[k]--;\n\t\t\t\t\tcnt[k - 1] += 2;\n\t\t\t\t}\n\n\t\t\t\tcnt[i]--;\n\t\t\t\tans++;\n\t\t\t\tc[i]--;\n\t\t\t}\n\t\t\tif (!good)\n\t\t\t\tbreak;\n\t\t}\n\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(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\tpublic static void main(String[] args) {\n\t\tnew C().run();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eefd7718f6fdf1e19e68187b71fe35f6", "src_uid": "e95fb7d4309747834b37d4bc3468afb7", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint count = in.readInt();\n\t\tint length = in.readInt();\n\t\tint time = in.readInt() * 2;\n\t\tint[] delta = IOUtils.readIntArray(in, count);\n\t\tdouble full = time / length;\n\t\tint remaining = time % length;\n\t\tdouble answer = full / 4 * (long)count * (count - 1);\n\t\tint j = 0;\n\t\tint lap = 0;\n\t\tint plus = 0;\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\twhile (delta[j] + lap - delta[i] <= remaining) {\n\t\t\t\tj++;\n\t\t\t\tif (j == count) {\n\t\t\t\t\tj = 0;\n\t\t\t\t\tlap = length;\n\t\t\t\t\tplus = count;\n\t\t\t\t}\n\t\t\t}\n\t\t\tanswer += (j - i + plus - 1) / 4d;\n\t\t}\n\t\tout.printLine(answer);\n }\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic 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 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\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3dda3b5dfd8bdbb81e39526d040de921", "src_uid": "e95fb7d4309747834b37d4bc3468afb7", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class C {\n\tprivate static Scanner in;\n\n\tpublic void run() {\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[m];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tb[i] = in.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tArrays.sort(b);\n\t\tint[] f = new int[31];\n\t\tfor (int t = 0; t <= 30; t++) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (((a[i] >> t) & 1) == 1) {\n\t\t\t\t\tf[t]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint lo = 0;\n\t\tint hi = m + 1;\n\t\twhile (lo + 1 < hi) {\n\t\t\tint mid = (lo + hi) / 2;\n\t\t\tint[] d = new int[32];\n\t\t\tfor (int i = 0; i < mid; i++) {\n\t\t\t\td[b[i]]++;\n\t\t\t}\n\t\t\tfor (int t = 0; t <= 30; t++) {\n\t\t\t\td[t] -= f[t];\n\t\t\t\tif (d[t] > 0) {\n\t\t\t\t\td[t + 1] += d[t];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (d[31] > 0) {\n\t\t\t\thi = mid;\n\t\t\t} else {\n\t\t\t\tlo = mid;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(lo);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tin = new Scanner(System.in);\n\t\tnew C().run();\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b789e16a96eb6d0be412ed327b519dd", "src_uid": "e95fb7d4309747834b37d4bc3468afb7", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Test {\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\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 static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n long s;\n final int M = 60;\n long one = 1;\n long ans;\n long[][][] dp = new long[M][2*M][2];\n\n void start() {\n s = readLong();\n long base1 = 0;\n for (int h1 = 0; h1 < M; h1++) {\n base1 += one << h1;\n if (s < base1) break;\n\n long base2 = base1;\n for (int h2 = 0; h2 < M; h2++) {\n if (h2 > 0) base2 += one << h2;\n long ts = s - base2 - ((one << h2) - 1);\n if (ts < 0) break;\n ts %= base2;\n if (ts == 0) {\n ans++;\n continue;\n }\n for (int br = 1; br <= Math.max(0, h1 - 1) + Math.max(0, h2 - 1); br++) {\n long sum = ts + br;\n if ((sum & 1) != 0) continue;\n int msb = Long.numberOfTrailingZeros(Long.highestOneBit(sum));\n for (int i = 0; i <= msb; i++)\n for (int j = 0; j <= br; j++)\n for (int car = 0; car < 2; car++)\n dp[i][j][car] = 0;\n dp[0][0][0] = 1;\n for (int i = 1; i <= msb; i++)\n for (int j = 0; j <= br; j++)\n for (int car = 0; car < 2; car++) {\n if (dp[i-1][j][car] == 0) continue;\n for (int b1 = 0; b1 < 2; b1++) {\n if (i > h1 - 1 && b1 > 0) continue;\n if (j + b1 > br) continue;\n for (int b2 = 0; b2 < 2; b2++) {\n if (i > h2 - 1 && b2 > 0) continue;\n if (j + b1 + b2 > br) continue;\n int s = car + b1 + b2;\n int ncar = s / 2;\n long val = s % 2;\n if ((sum & (1 << i)) != (val << i)) continue;\n dp[i][j + b1 + b2][ncar] += dp[i-1][j][car];\n }\n }\n }\n ans += dp[msb][br][0];\n }\n }\n }\n writer.println(ans);\n }\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d2fb42b3a9c961115c62dc69eeda0a8b", "src_uid": "c142f8bc5252e739035992926545c251", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStreamWriter;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.IOException;\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\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, MyScanner in, MyPrintWriter out) {\n int n=in.nextInt();\n String[] s = new String[n];\n int[] d = new int[n];\n for (int i = 0; i < n; i++) {\n d[i] = in.nextInt();\n s[i] = in.next();\n }\n int c = 0;\n for (int i=n-1;i>=0;i--) {\n if(s[i].equals(\"North\")) {\n c += d[i];\n } else if(s[i].equals(\"South\")) {\n c -= d[i];\n } else {\n if (c == 0 || c == 20000) {\n out.println(\"NO\");\n return;\n }\n }\n if (c < 0 || c > 20000) {\n out.println(\"NO\");\n return;\n }\n }\n out.println(c==0 ? \"YES\" : \"NO\");\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 private char[] strBuf = new char[BUFSIZE];\n\n public String next() {\n int strLen = 0;\n int c;\n do {\n c = read();\n if (c == -1) throw new NoSuchElementException();\n } while (Character.isWhitespace(c));\n do {\n if (strLen + 1 >= strBuf.length) {\n char[] tmp = new char[strBuf.length * 2];\n System.arraycopy(strBuf, 0, tmp, 0, strBuf.length);\n strBuf = tmp;\n }\n strBuf[strLen++] = (char) c;\n c = read();\n } while (c != -1 && !Character.isWhitespace(c));\n return new String(strBuf, 0, strLen);\n }\n\n public int nextInt() {\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 -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while ('0' <= c && c <= '9');\n return res;\n }\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c70edfdf9e77f57eeac2fda21b440ab", "src_uid": "c142f8bc5252e739035992926545c251", "difficulty": 3200.0} {"lang": "Java 8", "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 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 max) {\n L = m;\n } else {\n res += solve(s - min,l,r);\n break;\n }\n }\n }\n out.println(res);\n }\n\n private long solve(long s, int l, int r) {\n l = 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 cur = new HashMap<>();\n cur.put(0L, 1L);\n for(int i=cand.length-1;i>=0;i--) {\n HashMap nxt = new HashMap<>();\n long c = cand[i];\n long rest = 0;\n for(int j=0;j e : cur.entrySet()) {\n long val = e.getKey();\n if (val + c <= s) {\n if(!nxt.containsKey(val+c)){\n nxt.put(val+c, 1L);\n } else{\n nxt.put(val+c, nxt.get(val+c) + 1);\n }\n }\n if (val + rest >= s) {\n if(!nxt.containsKey(val)){\n nxt.put(val, 1L);\n } else{\n nxt.put(val, nxt.get(val) + 1);\n }\n }\n }\n cur = nxt;\n }\n return cur.get(s);\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6cd057bb1dcd5261d088cca3308d68b6", "src_uid": "c142f8bc5252e739035992926545c251", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\t\n\tInput in;\n\tPrintWriter out;\n\t\n\tfinal static int INF = (int) 1e9;\n\tfinal static int MOD = (int) 1e9 + 7;\n\tfinal static long LINF = (long) 1e18;\n\tfinal static double PI = (double) Math.acos(-1.0);\n\tfinal static double EPS = (double) 1e-9;\n\t\n\tvoid solve() {\n\t\tlong x = in.nextLong();\n\t\tlong ans = 0;\n\t\tfor (int k = 0; k <= 50; k++) {\n\t\t\tfor (int l = 0; l <= 50; l++) {\n\t\t\t\tlong m = (1L << (k + 1)) + (1L << (l + 1)) - 3;\n\t\t\t\tlong y = x - (1L << l) + 1;\n\t\t\t\tif (y < m) continue;\n\t\t\t\tfor (int tot = 0; tot <= k + l; tot++) {\n\t\t\t\t\tlong tmp = (y + tot) % m;\n\t\t\t\t\tif (tmp > (1L << k) + (1L << l) - 2) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint[] digit = new int[50];\n\t\t\t\t\tint cnt = 0;\n\t\t\t\t\twhile (tmp > 0) {\n\t\t\t\t\t\tdigit[cnt++] = (int) (tmp % 2);\n\t\t\t\t\t\ttmp >>= 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (tot > 2 * cnt) continue;\n\t\t\t\t\tlong[][][] dp = new long[cnt + 1][2 * cnt + 1][2];\n\t\t\t\t\tdp[0][0][0] = 1;\n\t\t\t\t\tfor (int pos = 0; pos < cnt; pos++) {\n\t\t\t\t\t\tfor (int sum = 0; sum <= tot; sum++) {\n\t\t\t\t\t\t\tfor (int car = 0; car < 2; car++) if (dp[pos][sum][car] != 0) {\n\t\t\t\t\t\t\t\tint lox = 0, hix = 1;\n\t\t\t\t\t\t\t\tint loy = 0, hiy = 1;\n\t\t\t\t\t\t\t\tif (pos >= k || pos == 0) hix = 0;\n\t\t\t\t\t\t\t\tif (pos >= l || pos == 0) hiy = 0;\n\t\t\t\t\t\t\t\tfor (int i = lox; i <= hix; i++) {\n\t\t\t\t\t\t\t\t\tfor (int j = loy; j <= hiy; j++) {\n\t\t\t\t\t\t\t\t\t\tint u = i + j + car;\n\t\t\t\t\t\t\t\t\t\tif (u % 2 == digit[pos]) {\n\t\t\t\t\t\t\t\t\t\t\tdp[pos + 1][sum + i + j][u / 2] += dp[pos][sum][car];\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\tans += dp[cnt][tot][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\t(new Main()).run();\n\t}\n\t\n\tpublic void run() {\n\t\tin = new Input();\n\t\ttry {\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t//out = new PrintWriter(new FileWriter(\"a.out\"));\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t}\n\t\tlong stime = System.currentTimeMillis();\n\t\tsolve();\n\t\tif (System.getProperty(\"ONLINE_JUDGE\") == null) {\n\t\t\tout.println(\"\\nTime elapsed: \" + (System.currentTimeMillis() - stime) + \"ms\");\n\t\t}\n\t\tout.close();\n\t}\n\t\n\tpublic class Input {\n\t\tStringTokenizer token = null;\n\t\tBufferedReader in;\n\t\tpublic Input() {\n\t\t\ttry {\n\t\t\t\tif (System.getProperty(\"ONLINE_JUDGE\") == null) {\n\t\t\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t\t//in = new BufferedReader(new FileReader(\"in.txt\"));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (Exception ex) {\n\t\t\t}\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(nextString());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(nextString());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(nextString());\n\t\t}\n\t\tString nextString() {\n\t\t\ttry {\n\t\t\t\twhile (token == null || !token.hasMoreTokens()) {\n\t\t\t\t\ttoken = new StringTokenizer(in.readLine());\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t}\n\t\t\treturn token.nextToken();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e4f589aef1ff6fd4ef5cb9101e26b76e", "src_uid": "c142f8bc5252e739035992926545c251", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n// static long[] F;\n// static final int N = 55;\n//\n// static {\n// F = new long[N];\n// F[0] = 1;\n// for (int i = 1; i < N; i++) {\n// long bad = (1L << (i + 1 >> 1));\n// if ((i & 1) == 0) {\n// bad += (1L << (i >> 1));\n// }\n// F[i] = (((1L << i) - bad) >> 2) + (bad >> 1);\n// }\n// }\n\n static long getCountWithPrefix(int[] c, int prefix) {\n if (c[0] == '1') return 0;\n int n = c.length;\n long ans = 0;\n// System.out.println(Arrays.toString(c) + \" \" + prefix);\n for (int last = 0; last < 2; last++) {\n loop:\n for (int same = 1; same <= n; same++) {\n int[] cur = c.clone();\n// System.out.println(\"same = \" + same);\n long ways = 1;\n for (int i = 0; i < same; i++) {\n if (cur[i] < 0) {\n cur[i] = 0;\n ways *= 2;\n }\n int put = last ^ cur[i];\n if (cur[n - i - 1] >= 0 && cur[n - i - 1] != put) continue loop;\n cur[n - i - 1] = put;\n if ((last ^ cur[i]) != cur[n - i - 1]) continue loop;\n }\n if (same == n) {\n ans += ways;\n// System.out.println(last + \" \" + same + \" \" + Arrays.toString(cur) + \" \" + ways);\n continue;\n }\n if (cur[same] >= 0 && cur[same] != 0) continue;\n if (cur[n - same - 1] >= 0 && cur[n - same - 1] != (last ^ 1)) continue;\n cur[same] = 0;\n cur[n - same - 1] = (last ^ 1);\n for (int i = 0; i < n; i++) if (cur[i] < 0) ways *= 2;\n ans += ways;\n// System.out.println(last + \" \" + same + \" \" + Arrays.toString(cur) + \" \" + ways);\n }\n }\n// System.out.println(\"ans = \" + ans);\n return ans;\n }\n\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n = in.nextInt();\n long k = in.nextLong();\n int[] ans = new int[n];\n Arrays.fill(ans, -1);\n ans[0] = 0;\n if (getCountWithPrefix(ans, 1) <= k) {\n out.println(-1);\n return;\n }\n for (int prefix = 1; prefix < n; prefix++) {\n boolean found = false;\n for (int put = 0; put < 2; put++) {\n ans[prefix] = put;\n long count = getCountWithPrefix(ans, prefix + 1);\n if (count <= k) {\n k -= count;\n } else {\n found = true;\n break;\n }\n }\n if (!found) throw new AssertionError();\n }\n for (int i : ans) out.print(i);\n out.println();\n }\n}\n\nclass FastScanner extends BufferedReader {\n\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n public int read() {\n try {\n int ret = super.read();\n// if (isEOF && ret < 0) {\n// throw new InputMismatchException();\n// }\n// isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n public String next() {\n StringBuilder sb = new StringBuilder();\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n if (c < 0) {\n return null;\n }\n while (c >= 0 && !isWhiteSpace(c)) {\n sb.appendCodePoint(c);\n c = read();\n }\n return sb.toString();\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n}\n\nclass FastPrinter extends PrintWriter {\n\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public FastPrinter(Writer out) {\n super(out);\n }\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ebcf5ecbd7e75621d8742ef92d2053c0", "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\npublic class Main {\n public static void main(String[] args) {\n new Main().run();\n }\n void debug(Object...os){\n System.err.println(deepToString(os));\n }\n Scanner sc = new Scanner(System.in);\n void run(){\n// for (int i = 0; i<20; i++) {\n// survey(i);\n// }\n\n int n=sc.nextInt();\n// survey(n);\n long k=sc.nextLong();\n long res = solve(n,k);\n if(res==-1){\n System.out.println(\"-1\");\n }else{\n String s=Long.toBinaryString(res);\n while(s.length()=have)k-=have;\n else break;\n have-=sub;\n }\n if(first==(1<<(n-1)/2)){\n return -1;\n }\n int last;\n int msk=(1<>>32-n;\n }\n private int flip(int i, int n) {\n return (1<=have)k-=have;\n else break;\n have-=sub;\n }\n if(first==(1<<(n-1)/2)){\n return -1;\n }\n int last;\n int msk=(1<>>32-n;\n }\n private int flip(int i, int n) {\n return (1<=have)k-=have;\n else break;\n have-=sub;\n }\n if(first==(1<<(n-1)/2)){\n return -1;\n }\n int last;\n int msk=(1<>>32-n;\n }\n private int flip(int i, int n) {\n return (1< ord = new ArrayList<>();\n \n int[] dp = new int[N];\n int[] ep = new int[N];\n \n void solve() {\n n = in.nextInt(); m = in.nextInt();\n int[] fr = new int[m], to = new int[m];\n for (int i = 0; i < m; i++) {\n fr[i] = in.nextInt() - 1;\n to[i] = in.nextInt() - 1;\n }\n G = build_graph(n, fr, to);\n \n for (int i = 0; i < n; i++) {\n if (!vis[i]) {\n dfs(G, i);\n }\n }\n \n for (int u : ord) {\n dp[u] = 1;\n for (int v : G[u]) {\n dp[u] += dp[v];\n }\n }\n \n R = build_graph(n, to, fr);\n \n Arrays.fill(vis, false);\n for (int i = 0; i < n; i++) {\n if (!vis[i]) {\n dfs(R, i);\n }\n }\n \n for (int u : ord) {\n ep[u] = 1;\n for (int v : R[u]) {\n ep[u] += ep[v];\n }\n }\n \n int ans = 0;\n for (int i = 0; i < n; i++) if (dp[i] + ep[i] - 1 >= n - 1) ans++;\n out.println(ans);\n }\n \n void dfs(int[][] G, int u) {\n vis[u] = true;\n for (int v : G[u]) {\n if (!vis[v]) dfs(G, v);\n }\n ord.add(u);\n }\n \n int[][] build_graph(int n, int[] from, int[] to) {\n int[][] G = new int[n][];\n int[] cnt = new int[n];\n for (int i = 0; i < from.length; i++) {\n cnt[from[i]]++;\n }\n for (int i = 0; i < n; i++) G[i] = new int[cnt[i]];\n for (int i = 0; i < from.length; i++) {\n G[from[i]][--cnt[from[i]]] = to[i];\n }\n return G;\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 UpgradingCities().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4627fa4a3439e2f58eb0a722d7b66ed", "src_uid": "be26e93ca7aef1235e96e10467a6417e", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class UpgradingCities {\n \n int N = (int) 3e5 + 10;\n \n int n, m;\n int[][] G, R;\n \n boolean[] vis = new boolean[N];\n List ord = new ArrayList<>();\n \n int[] dp = new int[N];\n int[] ep = new int[N];\n \n void solve() {\n n = in.nextInt(); m = in.nextInt();\n int[] fr = new int[m], to = new int[m];\n for (int i = 0; i < m; i++) {\n fr[i] = in.nextInt() - 1;\n to[i] = in.nextInt() - 1;\n }\n G = build_graph(n, fr, to);\n \n for (int i = 0; i < n; i++) {\n if (!vis[i]) {\n dfs(G, i);\n }\n }\n \n for (int u : ord) {\n dp[u] = 1;\n for (int v : G[u]) {\n dp[u] += dp[v];\n }\n }\n \n R = build_graph(n, to, fr);\n \n Arrays.fill(vis, false);\n ord.clear();\n for (int i = 0; i < n; i++) {\n if (!vis[i]) {\n dfs(R, i);\n }\n }\n \n for (int u : ord) {\n ep[u] = 1;\n for (int v : R[u]) {\n ep[u] += ep[v];\n }\n }\n \n int ans = 0;\n for (int i = 0; i < n; i++) if (dp[i] + ep[i] - 1 >= n - 1) ans++;\n out.println(ans);\n }\n \n void dfs(int[][] G, int u) {\n vis[u] = true;\n for (int v : G[u]) {\n if (!vis[v]) dfs(G, v);\n }\n ord.add(u);\n }\n \n int[][] build_graph(int n, int[] from, int[] to) {\n int[][] G = new int[n][];\n int[] cnt = new int[n];\n for (int i = 0; i < from.length; i++) {\n cnt[from[i]]++;\n }\n for (int i = 0; i < n; i++) G[i] = new int[cnt[i]];\n for (int i = 0; i < from.length; i++) {\n G[from[i]][--cnt[from[i]]] = to[i];\n }\n return G;\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 UpgradingCities().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b17a1bbf43cfb1cbd30bc9fd34482304", "src_uid": "be26e93ca7aef1235e96e10467a6417e", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.lang.reflect.Array;\npublic class s{\n\tint to;\n\tint next_;\n}\npublic class Main {\n\n static s edge[]=new s[601010];\n static int u[]=new int[601010];\n static int v[]=new int[601010];\n static int head[]=new int[601010];\n static int in[]=new int[601010];\n\t static int n,m;\n static int cnt;\n static int count_[][]=new int[2][601010];\n public static void add(int u,int v)\n {\n \t edge[++cnt]=new s();\n \t edge[cnt].to=v;\n \t edge[cnt].next_=head[u];\n \t head[u]=cnt;\n }\n public static void f(int op)\n {\n \t Queue q = new LinkedList();\n \t int cn=0;\n \t for(int i=1;i<=n;i++)\n \t {\n \t\t if(in[i]==0)\n \t\t {\n \t\t // if(op==0)\n \t\t //\t System.out.println(i+\"*\");\n \t\t\t q.offer(i);\n cn++;\n \t\t }\n \t }\n \t while(q.peek()!=null)\n \t {\n \t\t int tm=q.poll();\n \t\t if(q.peek()==null)\n \t\t {\n \t\t\t count_[op][tm]=n-cn;\n \t\t }\n \t\t else if(q.size()==1)\n \t\t {\n \t\t\t int flag=0;\n \t\t\t for(int i=head[q.peek()];i!=-1;i=edge[i].next_)\n \t\t\t {\n \t\t\t\t int v=edge[i].to;\n \t\t\t\t if(in[v]==1)\n \t\t\t\t {\n \t\t\t\t\t flag=1;\n \t\t\t\t\t break;\n \t\t\t\t }\n \t\t\t }\n \t\t\t if(flag==1)\n \t\t\t\t count_[op][tm]=-n;\n \t\t\t else \n \t\t\t\t count_[op][tm]=n-cn;\n \t\t }\n \t\t else \n \t\t {\n \t\t\t count_[op][tm]=-n;\n \t\t }\n \t\t for(int i=head[tm];i!=-1;i=edge[i].next_)\n \t\t {\n \t\t\t int v=edge[i].to;\n \t\t\t in[v]--;\n \t\t\t if(in[v]==0)\n \t\t\t {\n \t\t\t\t q.offer(v);\n \t\t\t\t cn++;\n \t\t\t }\n \t\t }\n \t }\n }\n\t public static void main(String[] args)\n\t {\n\t\t cnt=0;\n\t\t Arrays.fill(head, -1);\n\t\t Arrays.fill(in, 0);\n\t\t Scanner cin=new Scanner(System.in);\n\t\t n=cin.nextInt();\n\t\t m=cin.nextInt();\n\t\t for(int i=0;i=n-2)\n\t\t\t {\n\t\t\t\t ans++;\n\t\t\t }\n\t\t }\n\t\t System.out.println(ans);\n\t\t \n\t }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d74674eebe3623aac7e0a529c2f44760", "src_uid": "be26e93ca7aef1235e96e10467a6417e", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * @author Don Li\n */\npublic class UpgradingCities {\n \n int N = (int) 3e5 + 10;\n \n int n, m;\n int[][] G, R;\n \n boolean[] vis = new boolean[N];\n int p;\n int[] ord;\n \n int[] d = new int[N];\n int[] prev = new int[N];\n \n int cnt;\n Stack stack = new Stack<>();\n \n int[] dp = new int[N];\n int[] ep = new int[N];\n \n void solve() {\n n = in.nextInt(); m = in.nextInt();\n int[] fr = new int[m], to = new int[m];\n for (int i = 0; i < m; i++) {\n fr[i] = in.nextInt() - 1;\n to[i] = in.nextInt() - 1;\n }\n \n G = build_graph(n, fr, to);\n R = build_graph(n, to, fr);\n \n p = n;\n ord = new int[n];\n for (int i = 0; i < n; i++) {\n if (!vis[i]) {\n dfs(G, i);\n }\n }\n \n int last = -1;\n Arrays.fill(prev, -1);\n for (int u : ord) {\n d[u] = 1;\n for (int v : R[u]) {\n if (d[v] + 1 > d[u]) {\n d[u] = d[v] + 1;\n prev[u] = v;\n }\n }\n if (last < 0 || d[last] < d[u]) last = u;\n }\n \n int k = d[last];\n int[] path = new int[d[last]];\n while (last >= 0) {\n path[d[last] - 1] = last;\n last = prev[last];\n }\n \n boolean[] mark = new boolean[n];\n Map map = new HashMap<>();\n L:\n for (int i = 0; i + 2 < k; i++) {\n map.clear();\n int u = path[i], v = path[i + 1], w = path[i + 2];\n for (int x : G[u]) {\n if (x != v) map.put(x, map.getOrDefault(x, 0) + 1);\n }\n for (int x : R[w]) {\n if (x != v) map.put(x, map.getOrDefault(x, 0) + 1);\n }\n int cand = -1;\n for (int x : map.keySet()) {\n if (map.get(x) == 2) {\n if (cand == -1) cand = x;\n else continue L;\n }\n }\n if (cand >= 0) mark[cand] = true;\n }\n if (k >= 2 && R[path[1]].length == 2) {\n for (int v : R[path[1]]) {\n if (v != path[0]) mark[v] = true;\n }\n }\n if (k >= 2 && G[path[k - 2]].length == 2) {\n for (int v : G[path[k - 2]]) {\n if (v != path[k - 1]) mark[v] = true;\n }\n }\n \n cnt = 0;\n Arrays.fill(vis, false);\n for (int i = k - 1; i >= 0; i--) {\n int u = path[i];\n dfs_cnt(G, u);\n dp[u] = cnt;\n for (int v : R[u]) {\n if (mark[v]) {\n dfs_cnt2(G, v);\n dp[v] = cnt;\n while (!stack.isEmpty()) {\n int x = stack.pop();\n vis[x] = false;\n cnt--;\n }\n }\n }\n }\n for (int i = 0; i < n; i++) if (mark[i]) dp[i] = Math.max(dp[i], 1);\n \n cnt = 0;\n Arrays.fill(vis, false);\n for (int i = 0; i < k; i++) {\n int u = path[i];\n dfs_cnt(R, u);\n ep[u] = cnt;\n for (int v : G[u]) {\n if (mark[v]) {\n dfs_cnt2(R, v);\n ep[v] = cnt;\n while (!stack.isEmpty()) {\n int x = stack.pop();\n vis[x] = false;\n cnt--;\n }\n }\n }\n }\n for (int i = 0; i < n; i++) if (mark[i]) ep[i] = Math.max(ep[i], 1);\n \n int ans = 0;\n for (int i = 0; i < n; i++) {\n if (dp[i] + ep[i] >= n) ans++;\n }\n out.println(ans);\n }\n \n void dfs_cnt2(int[][] G, int u) {\n vis[u] = true;\n cnt++;\n stack.push(u);\n for (int v : G[u]) {\n if (!vis[v]) dfs_cnt2(G, v);\n }\n }\n \n void dfs_cnt(int[][] G, int u) {\n vis[u] = true;\n cnt++;\n for (int v : G[u]) {\n if (!vis[v]) dfs_cnt(G, v);\n }\n }\n \n void dfs(int[][] G, int u) {\n vis[u] = true;\n for (int v : G[u]) {\n if (!vis[v]) dfs(G, v);\n }\n ord[--p] = u;\n }\n \n int[][] build_graph(int n, int[] from, int[] to) {\n int[][] G = new int[n][];\n int[] cnt = new int[n];\n for (int i = 0; i < from.length; i++) {\n cnt[from[i]]++;\n }\n for (int i = 0; i < n; i++) G[i] = new int[cnt[i]];\n for (int i = 0; i < from.length; i++) {\n G[from[i]][--cnt[from[i]]] = to[i];\n }\n return G;\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 UpgradingCities().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e94b8ca29c42fa1a025878b194da6f9", "src_uid": "be26e93ca7aef1235e96e10467a6417e", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import javafx.geometry.Pos;\nimport javafx.util.Pair;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.security.cert.PolicyNode;\nimport java.util.*;\n\npublic class Solution {\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st;\n\n String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n final int inf = Integer.MAX_VALUE / 2;\n final double eps = 0.0000000001;\n\n int rd() throws IOException {\n return Integer.parseInt(nextToken());\n }\n double rdd() throws IOException {\n return Double.parseDouble(nextToken());\n }\n long rdl() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n int n;\n int[] a;\n\n int f(int x, int l){\n if (l <= 1){\n return a[x];\n } else {\n return a[f(x, l - 1)];\n }\n }\n\n void solve() throws IOException {\n n = rd();\n a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = rd() - 1;\n }\n for (int k = 1; k <= n + 2; k++) {\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n if (f(i, 2 * k) == f(i, k)) {\n cnt++;\n }\n }\n if (cnt == n) {\n out.println(k);\n out.flush();\n System.exit(0);\n }\n }\n }\n\n\n void run() throws IOException {\n try {\n// in = new BufferedReader(new FileReader(\"notation.in\"));\n// out = new PrintWriter(\"notation.out\");\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n Locale.setDefault(Locale.UK);\n solve();\n } catch (Exception e) {\n e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.\n } finally {\n out.close();\n }\n }\n\n public static void main(String Args[]) throws IOException {\n new Solution().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f217207c8313e02315dd87753b516228", "src_uid": "1daa784c0eb1cde514e4319da07c8d00", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n@SuppressWarnings(\"unchecked\")\n\npublic class Main implements Runnable {\n \n public static final String FILENAME = null;\n\n final int maxn = 210;\n int p[] = new int[maxn];\n int mark[] = new int[maxn];\n \n private void solve() throws IOException {\n int n = nextInt();\n for (int i = 0; i < n; ++i) p[i] = nextInt() - 1;\n int min = 1;\n BigInteger del = BigInteger.ONE;\n for (int i = 0; i < n; ++i) if (mark[i] == 0)\n {\n int x = i;\n int cnt = 0;\n while (true)\n {\n mark[x] = ++cnt;\n if (mark[p[x]] == 0)\n {\n x = p[x];\n }\n else if (mark[p[x]] > 0)\n {\n min = Math.max(min, mark[p[x]] - 1);\n BigInteger cyc = BigInteger.valueOf(mark[x] - mark[p[x]] + 1);\n del = del.multiply(cyc).divide(del.gcd(cyc));\n break;\n }\n else break;\n }\n x = i;\n while (true)\n {\n mark[x] = -1;\n if (mark[p[x]] != -1) x = p[x];\n else break;\n }\n }\n BigInteger res = del;\n while (res.compareTo(BigInteger.valueOf(min)) < 0) res = res.add(del);\n out.println(res);\n \n \n }\n // -----------------------------------------------\n private BufferedReader br;\n private StringTokenizer _st;\n private PrintWriter out;\n \n private void myAssert(boolean assertion) {\n if (!assertion) throw new AssertionError();\n }\n private void dbg(Object...os){\n System.err.println(Arrays.deepToString(os));\n System.err.flush();\n } \n private String next() throws IOException {\n while (_st == null || !_st.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) return null;\n _st = new StringTokenizer(s);\n }\n return _st.nextToken();\n }\n private int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n private long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n private double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n private String nextLine() throws IOException {\n _st = null;\n return br.readLine();\n }\n public void run() {\n long startTime = System.nanoTime();\n try {\n if (FILENAME == null) {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n br = new BufferedReader(new FileReader(FILENAME + \".in\"));\n out = new PrintWriter(FILENAME + \".out\");\n }\n try {\n solve();\n } finally {\n out.close();\n }\n } catch (IOException e) {\n System.err.println(e.getClass().getName() + \": \" + e.getMessage());\n e.printStackTrace();\n }\n long finishTime = System.nanoTime();\n// System.err.printf(\"Time = %.3f\\n\", (finishTime - startTime) / 1e9);\n }\n public static void main(String[] args) {\n new Thread(new Main()).start();\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96b8cdc7841097f1d7e5df1c14426aa4", "src_uid": "1daa784c0eb1cde514e4319da07c8d00", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n@SuppressWarnings(\"unchecked\")\n\npublic class Main implements Runnable {\n \n public static final String FILENAME = null;\n\n final int maxn = 210;\n int p[] = new int[maxn];\n int mark[] = new int[maxn];\n \n private void solve() throws IOException {\n int n = nextInt();\n for (int i = 0; i < n; ++i) p[i] = nextInt() - 1;\n int min = 1;\n BigInteger del = BigInteger.ONE;\n for (int i = 0; i < n; ++i) if (mark[i] == 0)\n {\n int x = i;\n int cnt = 0;\n int cc = 0;\n while (true)\n {\n mark[x] = ++cnt;\n if (mark[p[x]] == 0)\n {\n x = p[x];\n }\n else if (mark[p[x]] > 0)\n {\n min = Math.max(min, mark[p[x]] - 1);\n BigInteger cyc = BigInteger.valueOf(mark[x] - mark[p[x]] + 1);\n del = del.multiply(cyc).divide(del.gcd(cyc));\n cc = mark[p[x]];\n break;\n }\n else\n {\n min = Math.max(min, mark[x] - 1 - mark[p[x]]);\n break;\n }\n \n }\n x = i;\n cnt = 0;\n while (true)\n {\n mark[x] = Math.min(-1, (++cnt) - cc - 1);\n if (mark[p[x]] != -1) x = p[x];\n else break;\n }\n }\n BigInteger res = del;\n while (res.compareTo(BigInteger.valueOf(min)) < 0) res = res.add(del);\n out.println(res);\n \n \n }\n // -----------------------------------------------\n private BufferedReader br;\n private StringTokenizer _st;\n private PrintWriter out;\n \n private void myAssert(boolean assertion) {\n if (!assertion) throw new AssertionError();\n }\n private void dbg(Object...os){\n System.err.println(Arrays.deepToString(os));\n System.err.flush();\n } \n private String next() throws IOException {\n while (_st == null || !_st.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) return null;\n _st = new StringTokenizer(s);\n }\n return _st.nextToken();\n }\n private int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n private long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n private double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n private String nextLine() throws IOException {\n _st = null;\n return br.readLine();\n }\n public void run() {\n long startTime = System.nanoTime();\n try {\n if (FILENAME == null) {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n br = new BufferedReader(new FileReader(FILENAME + \".in\"));\n out = new PrintWriter(FILENAME + \".out\");\n }\n try {\n solve();\n } finally {\n out.close();\n }\n } catch (IOException e) {\n System.err.println(e.getClass().getName() + \": \" + e.getMessage());\n e.printStackTrace();\n }\n long finishTime = System.nanoTime();\n// System.err.printf(\"Time = %.3f\\n\", (finishTime - startTime) / 1e9);\n }\n public static void main(String[] args) {\n new Thread(new Main()).start();\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7eb7d83040e5b126c93d8e986bca973e", "src_uid": "1daa784c0eb1cde514e4319da07c8d00", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class F {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint[] f = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tf[i] = in.nextInt() - 1;\n\t\t}\n\t\tBigInteger res = BigInteger.ONE;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] d = new int[n];\n\t\t\tArrays.fill(d, -1);\n\t\t\tint cur = i;\n\t\t\tint curd = 0;\n\t\t\tint d0 = -1, d1 = -1;\n\t\t\twhile (true) {\n\t\t\t\td[cur] = curd;\n\t\t\t\tcurd++;\n\t\t\t\tcur = f[cur];\n\t\t\t\tif (d[cur] != -1) {\n\t\t\t\t\td0 = d[cur];\n\t\t\t\t\td1 = curd - d[cur];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (d0 == 0)\n\t\t\t\td0 = 1;\n\t\t\t//System.out.println(d0 + \" \" + d1);\n\t\t\tlong x = ((d0 + d1 - 1) / d1) * d1;\n\t\t\t//System.out.println(x);\n\t\t\tBigInteger g = BigInteger.valueOf(x).gcd(res);\n\t\t\tres = res.multiply(BigInteger.valueOf(x)).divide(g);\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tvoid run() {\n\t\tin = new FastScanner();\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(in.br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew F().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b8c56bcf5cc5762642523e2cde31cdbc", "src_uid": "1daa784c0eb1cde514e4319da07c8d00", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Problem0171e {\n public static void main(String[] args) {\n System.out.println(\"INTERCAL\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a7baafd8c2234857e674c8c4bea2a5fd", "src_uid": "ef8239a0f77c538d2d9b246b86be63fe", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "public class Main\n{\n public static void main(String[] args)\n\t{\n System.out.println(\"INTERCAL\");\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8d74df3f4699dfde71af1aaafd260998", "src_uid": "ef8239a0f77c538d2d9b246b86be63fe", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\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 class GraphBuilder {\n int n, m;\n int[] x, y;\n int index;\n int[] size;\n\n\n GraphBuilder(int n, int m) {\n this.n = n;\n this.m = m;\n x = new int[m];\n y = new int[m];\n size = new int[n];\n }\n\n void add(int u, int v) {\n x[index] = u;\n y[index] = v;\n size[u]++;\n size[v]++;\n index++;\n }\n\n int[][] build() {\n int[][] graph = new int[n][];\n for (int i = 0; i < n; i++) {\n graph[i] = new int[size[i]];\n }\n for (int i = index - 1; i >= 0; i--) {\n int u = x[i];\n int v = y[i];\n graph[u][--size[u]] = v;\n graph[v][--size[v]] = u;\n }\n return graph;\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[] readLongArray(int size) throws IOException {\n long[] res = new long[size];\n for (int i = 0; i < size; i++) {\n res[i] = readLong();\n }\n return res;\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n List[] createGraphList(int size) {\n List[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new Template().run();\n // new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n time();\n memory();\n }\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n void solve() throws IOException {\n out.println(\"INTERCAL\");\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a7dea2301c78872e68a84088e123a813", "src_uid": "ef8239a0f77c538d2d9b246b86be63fe", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Problem0171e {\n public static void main(String[] args) {\n System.out.println(\"COBOL\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4aa9e47ccd3300a3271d0bb36e8131d9", "src_uid": "ef8239a0f77c538d2d9b246b86be63fe", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Locale;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class E {\n\t\n\tprivate void solve() throws IOException {\n\t\tint nf = nextInt();\n\t\tint ne = nextInt();\n\t\tint ns = nextInt();\n\t\tint rf = nextInt();\n\t\tint re = nextInt();\n\t\tint rs = nextInt();\n\t\tint df = nextInt();\n\t\tint de = nextInt();\n\t\t\n\t\t\n\t\tint n = nf + ne + ns;\n\t\tbyte[] a = new byte[n];\n\t\tfor (int i = 0; i < ns; i++) {\n\t\t\ta[i] = 1;\n\t\t}\n\n\t\tint sqrs = rs * rs;\n\t\t\n\t\tint cases = 0;\n\t\t\n\t\tint t = 2 * ns + 2;\n\t\tdouble[] p = new double[t];\n\t\tint[] b = new int[n];\n\t\tdouble[] f = new double[n];\n\t\tdouble[] e = new double[n];\n\t\tdouble[][] dp = new double[nf + 1][ne + 1];\n\t\t\n\t\t\n\t\tdouble res = 0;\n\t\t\n\t\tdouble d = Math.sqrt(sqrs - 1);\n\t\twhile (true) {\n\t\t\tcases++;\n\t\t\tint k = 0;\n\t\t\tint q = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint x = 1000000 + i / 2;\n\t\t\t\tif (a[i] == 1) {\n\t\t\t\t\tp[k++] = x - d;\n\t\t\t\t\tp[k++] = -(x + d);\n\t\t\t\t} else {\n\t\t\t\t\tb[q++] = x;\n\t\t\t\t}\n\t\t\t}\n\t\t\tp[k++] = 0.0;\n\t\t\tp[k++] = -2000000.0;\n//\t\t\tArrays.sort(p, cmp);\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tfor (int j = i + 1; j < p.length; j++) {\n\t\t\t\t\tif (Math.abs(p[i]) > Math.abs(p[j])) {\n\t\t\t\t\t\tdouble tmp = p[i];\n\t\t\t\t\t\tp[i] = p[j];\n\t\t\t\t\t\tp[j] = tmp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < q; i++) {\n\t\t\t\tf[i] = f(p, b[i], df, rf);\n\t\t\t\te[i] = f(p, b[i], de, re);\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 1; i <= nf; i++) {\n\t\t\t\tdp[i][0] = dp[i - 1][0] + f[i - 1];\n\t\t\t}\n\t\t\tfor (int i = 1; i <= ne; i++) {\n\t\t\t\tdp[0][i] = dp[0][i - 1] + e[i - 1];\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 1; i <= nf; i++) {\n\t\t\t\tfor (int j = 1; j <= ne; j++) {\n\t\t\t\t\tdp[i][j] = Math.max(dp[i - 1][j] + f[i + j - 1], dp[i][j - 1] + e[i + j - 1]);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tres = Math.max(res, dp[nf][ne]);\n\t\t\t\n\t\t\tboolean next = false;\n\t\t\tint ones = 0;\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tif (a[i] == 0) {\n\t\t\t\t\tif (ones != 0) {\n\t\t\t\t\t\ta[i] = 1;\n\t\t\t\t\t\tfor (int j = 0; j < ones - 1; j++) {\n\t\t\t\t\t\t\ta[j] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (int j = ones - 1; j < i; j++) {\n\t\t\t\t\t\t\ta[j] = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnext = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tones++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (!next) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tprintln(res);\n\t}\n\t\n\tprivate double f(double[] p, int x, double damage, double R) {\n\t\tdouble dx = Math.sqrt(R * R - 1);\n\t\tdouble l = x - dx;\n\t\tdouble r = x + dx;\n\t\t\n\t\tdouble k = 1;\n\t\tdouble res = 0;\n\t\tfor (int i = 1; i < p.length; i++) {\n\t\t\tdouble inter = inter(p[i - 1], p[i], l, r);\n\t\t\tres += damage * inter * k;\n\t\t\tif (p[i] > 0) {\n\t\t\t\tk++;\n\t\t\t} else {\n\t\t\t\tk--;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\t\n\tprivate double inter(double l1, double r1, double l2, double r2) {\n\t\tl1 = Math.abs(l1);\n\t\tr1 = Math.abs(r1);\n\t\tl2 = Math.abs(l2);\n\t\tr2 = Math.abs(r2);\n\t\tdouble r = Math.min(r1, r2) - Math.max(l1, l2);\n\t\tif (r < 0) {\n\t\t\treturn 0;\n\t\t} else {\n\t\t\treturn r;\n\t\t}\n\t}\n\t\n\t\n\tprivate String nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tprivate int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate double nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate void print(Object o) {\n\t\twriter.print(o);\n\t}\n\n\tprivate void println(Object o) {\n\t\twriter.println(o);\n\t}\n\n\tprivate void printf(String format, Object... o) {\n\t\twriter.printf(format, o);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tlong time = System.currentTimeMillis();\n\t\tLocale.setDefault(Locale.US);\n\t\tnew E().run();\n\t\tSystem.err.printf(\"%.3f\\n\", 1e-3 * (System.currentTimeMillis() - time));\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tprivate void run() {\n\t\ttry {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(13);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "42dca0a8d8c40fef0182b49d526f955f", "src_uid": "de5a42225714552cc5422d8a45734d58", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "//package round115;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\tint nf, ne, ns, rf, re, rs, df, de;\n\tint[] fct;\n\t\n\tvoid solve()\n\t{\n\t\tnf = ni(); ne = ni(); ns = ni();\n\t\trf = ni(); re = ni(); rs = ni();\n\t\tdf = ni(); de = ni();\n\t\tfct = new int[13];\n\t\t\n\t\tsqs = Math.sqrt(rs*rs-1);\n\t\tsqf = Math.sqrt(rf*rf-1);\n\t\tsqe = Math.sqrt(re*re-1);\n\n\t\trec(0, 0);\n\t\tout.printf(\"%.9f\\n\", gm);\n\t}\n\t\n\tdouble gm = 0;\n\tdouble sqs, sqf, sqe;\n\t\n\tvoid rec(int pos, int num)\n\t{\n\t\tif(pos == 13){\n\t\t\tif(num == ns)go();\n\t\t}else{\n\t\t\tfor(int i = 0;i <= 2 && num+i <= ns;i++){\n\t\t\t\tfct[pos] = i;\n\t\t\t\trec(pos+1, num+i);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tboolean[] cache = new boolean[3*3*3*3*3*3*3*3*3*3*3*3*3];\n\tint gct = 0;\n\t\n\tvoid go()\n\t{\n\t\tint code = 0;\n\t\tfor(int i = 0;i < 13;i++){\n\t\t\tcode = code * 3 + fct[i];\n\t\t}\n\t\tif(cache[code])return;\n\t\tcode = 0;\n\t\tfor(int i = 12;i >= 0;i--){\n\t\t\tcode = code * 3 + fct[i];\n\t\t}\n\t\tcache[code] = true;\n\t\t\n\t\tdouble I = -999999999;\n\t\tdouble[][] dp = new double[nf+1][ne+1];\n\t\tfor(int j = 0;j <= nf;j++)Arrays.fill(dp[j], I);\n\t\tdp[0][0] = 0;\n\t\t\n\t\tfor(int i = 0;i < 13;i++){\n\t\t\tdouble tdf = calc(i-sqf, i+sqf) * df;\n\t\t\tdouble tde = calc(i-sqe, i+sqe) * de;\n\t\t\tfor(int j = nf;j >= 0;j--){\n\t\t\t\tfor(int k = ne;k >= 0;k--){\n\t\t\t\t\tif(dp[j][k] != I){\n\t\t\t\t\t\tfor(int l = 0;l <= 2-fct[i] && j+l <= nf;l++){\n\t\t\t\t\t\t\tfor(int m = 0;l+m <= 2-fct[i] && k+m <= ne;m++){\n\t\t\t\t\t\t\t\tdp[j+l][k+m] = Math.max(dp[j+l][k+m], dp[j][k] + tdf*l + tde*m);\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\tfor(int i = 1;i <= 13;i++){\n//\t\t\tdouble tdf = calc(ev, i-1-sqf, i-1+sqf) * df;\n//\t\t\tdouble tde = calc(ev, i-1-sqe, i-1+sqe) * de;\n//\t\t\tfor(int j = 0;j <= nf;j++){\n//\t\t\t\tfor(int k = 0;k <= ne;k++){\n//\t\t\t\t\tdouble max = 0;\n//\t\t\t\t\tfor(int l = 0;l <= 2-fct[i-1] && l <= j;l++){\n//\t\t\t\t\t\tfor(int m = 0;l+m <= 2-fct[i-1] && m <= k;m++){\n//\t\t\t\t\t\t\tmax = Math.max(max, dp[i-1][j-l][k-m] + tdf*l + tde*m);\n//\t\t\t\t\t\t}\n//\t\t\t\t\t}\n//\t\t\t\t\tdp[i][j][k] = max;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\t\tgm = Math.max(gm, dp[nf][ne]);\n\t}\n\t\n\tdouble calc(double s, double t)\n\t{\n\t\tdouble dmg = 0;\n\t\tfor(int i = 0;i < 13;i++){\n\t\t\tif(fct[i] > 0){\n\t\t\t\tdouble w = Math.min(t, i+sqs) - Math.max(s, i-sqs);\n\t\t\t\tif(w > 0)dmg += w * fct[i];\n\t\t\t}\n\t\t}\n\t\treturn dmg + (t-s);\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew E().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ec58de88ce9e5c9c5f8065de1bc0a85b", "src_uid": "de5a42225714552cc5422d8a45734d58", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class E \n{\n public static void main(String [] args) throws IOException\n {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n \n StringTokenizer tokenizer = new StringTokenizer(reader.readLine());\n int nf = Integer.parseInt(tokenizer.nextToken());\n int ne = Integer.parseInt(tokenizer.nextToken());\n int ns = Integer.parseInt(tokenizer.nextToken());\n int total = nf + ne + ns;\n \n tokenizer = new StringTokenizer(reader.readLine());\n double rf = Integer.parseInt(tokenizer.nextToken());\n double re = Integer.parseInt(tokenizer.nextToken());\n double rs = Integer.parseInt(tokenizer.nextToken());\n rf *= rf;\n rf -= 1;\n rf = Math.sqrt(rf);\n \n re *= re;\n re -= 1;\n re = Math.sqrt(re);\n \n rs *= rs;\n rs -= 1;\n rs = Math.sqrt(rs);\n \n \n tokenizer = new StringTokenizer(reader.readLine());\n int df = Integer.parseInt(tokenizer.nextToken());\n int de = Integer.parseInt(tokenizer.nextToken());\n \n double res = 0;\n \n for(int s = 0 ; s < 1<= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5765112ed3393d58c8f97afff76cc424", "src_uid": "de5a42225714552cc5422d8a45734d58", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.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 */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n final int MAX_N = 101_000;\n @SuppressWarnings(\"uncheked\")\n ArrayList[] divs = new ArrayList[MAX_N];\n long modulo;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n init();\n int n = in.nextInt();\n int m = in.nextInt();\n long L = in.nextInt();\n long R = in.nextInt();\n modulo = in.nextInt();\n long res = 0;\n for (long dx = 1; dx <= n; dx++) {\n long low = L * L - dx * dx;\n long high = R * R - dx * dx;\n if (low < 0)\n low = 0;\n if (high < 0)\n continue;\n long left = (int)Math.sqrt(low);\n long right = (int)Math.sqrt(high);\n while (left > 0 && left * left + dx * dx > L * L)\n left--;\n while (left * left + dx * dx <= L * L)\n left++;\n left--;\n while (right * right + dx * dx <= R * R)\n right++;\n right--;\n //left--;\n if (right <= 0)\n continue;\n if (left > m)\n continue;\n if (left < 0)\n left = 0;\n if (right > m)\n right = m;\n if (left > right)\n continue;\n //out.println(dx + \" \" + left + \" \" + right);\n long cntR = right - getCount((int)dx, (int)right);\n long cntL = left - getCount((int)dx, (int)left);\n long cnt = cntR - cntL;\n cnt %= modulo;\n cnt += modulo;\n cnt %= modulo;;\n //out.println(\"cnt = \" + cnt);\n long sumR = right * (right + 1) / 2 - getSum((int)dx, (int)right);\n long sumL = left * (left + 1) / 2 - getSum((int)dx, (int)left);\n //out.println(sumL);\n //out.println(sumR);\n long sum = sumR - sumL;\n //out.println(\"sum = \" + sum);\n sum = cnt * (m + 1) % modulo - sum;\n sum %= modulo;\n sum += modulo;\n sum %= modulo;\n res += (2 * sum * (n - dx + 1)) % modulo;\n res %= modulo;\n }\n if (L <= 1)\n res += (n + 1) * 1L * m + n * 1L * (m + 1);\n out.println(res % modulo);\n }\n\n void init() {\n for (int i = 1; i < MAX_N; i++) {\n divs[i] = new ArrayList<>();\n divs[i].add(1);\n }\n for (int i = 2; i < MAX_N; i++)\n for (int j = i; j < MAX_N; j += i)\n divs[j].add(i);\n for (int i = 1; i < MAX_N; i++)\n Collections.reverse(divs[i]);\n }\n\n long getCount(int n, int R) {\n if (n == 1)\n return 0L;\n if (R <= 1)\n return 0L;\n int cnt = divs[n].size();\n int[] with = new int[cnt];\n int res = 0;\n for (int i = 0; i < cnt - 1; i++) {\n int cur = divs[n].get(i);\n with[i] += R / cur;\n res += with[i];\n for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)\n if (cur % divs[n].get(j) == 0)\n with[j] -= with[i];\n }\n return res;\n }\n\n long getSum(int n, int R) {\n if (R <= 1)\n return 0L;\n if (n == 1)\n return 0L;\n int cnt = divs[n].size();\n long[] with = new long[cnt];\n long res = 0;\n for (int i = 0; i < cnt - 1; i++) {\n int cur = divs[n].get(i);\n with[i] += (R / cur * 1L * (R / cur + 1) / 2) % modulo * cur;\n with[i] %= modulo;\n res += with[i];\n res %= modulo;\n for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)\n if (cur % divs[n].get(j) == 0) {\n with[j] -= with[i];\n with[j] %= modulo;\n if (with[j] < 0)\n with[j] += modulo;\n }\n }\n return res;\n }\n\n }\n\nclass FastScanner {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public FastScanner(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n return null;\n }\n tokenizer = new StringTokenizer(line);\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "31f4f98b905ce507d2cc8255724fe22f", "src_uid": "2afe29a7dbbd2e261e1870a43d57b46f", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n final int MAX_N = 101_000;\n @SuppressWarnings(\"uncheked\")\n ArrayList[] divs = new ArrayList[MAX_N];\n long modulo;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n init();\n int n = in.nextInt();\n int m = in.nextInt();\n long L = in.nextInt();\n long R = in.nextInt();\n modulo = in.nextInt();\n long res = 0;\n for (long dx = 1; dx <= n; dx++) {\n long low = L * L - dx * dx;\n long high = R * R - dx * dx;\n if (low < 0)\n low = 0;\n if (high < 0)\n continue;\n long left = (int)Math.sqrt(low);\n long right = (int)Math.sqrt(high);\n while (left > 0 && left * left + dx * dx > L * L)\n left--;\n while (left * left + dx * dx <= L * L)\n left++;\n left--;\n while (right > 0 && right * right + dx * dx > R * R)\n left--;\n while (right * right + dx * dx <= R * R)\n right++;\n right--;\n if (right <= 0)\n continue;\n if (left < 0)\n left = 0;\n if (right > m)\n right = m;\n if (left > right)\n continue;\n long cntR = right - getCount((int)dx, (int)right);\n long cntL = left - getCount((int)dx, (int)left);\n long cnt = cntR - cntL;\n cnt %= modulo;\n cnt += modulo;\n cnt %= modulo;\n long sumR = right * (right + 1) / 2 - getSum((int)dx, (int)right);\n long sumL = left * (left + 1) / 2 - getSum((int)dx, (int)left);\n long sum = sumR - sumL;\n sum = cnt * (m + 1) % modulo - sum;\n sum %= modulo;\n sum += modulo;\n sum %= modulo;\n res += (2 * sum * (n - dx + 1)) % modulo;\n res %= modulo;\n }\n if (L <= 1)\n res += (n + 1) * 1L * m + n * 1L * (m + 1);\n out.println(res % modulo);\n }\n\n void init() {\n for (int i = 1; i < MAX_N; i++) {\n divs[i] = new ArrayList<>();\n divs[i].add(1);\n }\n for (int i = 2; i < MAX_N; i++)\n for (int j = i; j < MAX_N; j += i)\n divs[j].add(i);\n for (int i = 1; i < MAX_N; i++)\n Collections.reverse(divs[i]);\n }\n\n long getCount(int n, int R) {\n if (n == 1)\n return 0L;\n if (R <= 1)\n return 0L;\n int cnt = divs[n].size();\n int[] with = new int[cnt];\n long res = 0;\n for (int i = 0; i < cnt - 1; i++) {\n int cur = divs[n].get(i);\n with[i] += R / cur;\n res += with[i];\n for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)\n if (cur % divs[n].get(j) == 0)\n with[j] -= with[i];\n }\n return res;\n }\n\n long getSum(int n, int R) {\n if (R <= 1)\n return 0L;\n if (n == 1)\n return 0L;\n int cnt = divs[n].size();\n long[] with = new long[cnt];\n long res = 0;\n for (int i = 0; i < cnt - 1; i++) {\n int cur = divs[n].get(i);\n with[i] += (R / cur * 1L * (R / cur + 1) / 2) % modulo * cur;\n with[i] %= modulo;\n res += with[i];\n res %= modulo;\n for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)\n if (cur % divs[n].get(j) == 0) {\n with[j] -= with[i];\n with[j] %= modulo;\n if (with[j] < 0)\n with[j] += modulo;\n }\n }\n return res;\n }\n}\n\nclass FastScanner {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public FastScanner(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n return null;\n }\n tokenizer = new StringTokenizer(line);\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "940b3c54dfa175aecab276223b986274", "src_uid": "2afe29a7dbbd2e261e1870a43d57b46f", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "//package round235;\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(), m = ni();\n\t\tint L = ni(), R = ni(), p = ni();\n\t\t\n\t\tlong ret = 0;\n\t\tif(L == 1){\n\t\t\tret += (long)n*(m+1)+(long)(n+1)*m;\n\t\t\tret %= p;\n\t\t}\n\t\t\n\t\tArrays.fill(counts, -1);\n\t\tlong xsum = countx(n, m, 1, (long)R*R);\n\t\tArrays.fill(counts, -1);\n\t\tlong xsum2 = countx(n, m, 1, (long)L*L-1);\n\t\tArrays.fill(counts, -1);\n\t\tlong ysum = countx(m, n, 1, (long)R*R);\n\t\tArrays.fill(counts, -1);\n\t\tlong ysum2 = countx(m, n, 1, (long)L*L-1);\n\t\tArrays.fill(counts, -1);\n\t\tlong xysum = countxy(n, m, 1, (long)R*R, p);\n\t\tArrays.fill(counts, -1);\n\t\tlong xysum2 = countxy(n, m, 1, (long)L*L-1, p);\n\t\tArrays.fill(counts, -1);\n\t\tlong sum = count(n, m, 1, (long)R*R);\n\t\tArrays.fill(counts, -1);\n\t\tlong sum2 = count(n, m, 1, (long)L*L-1);\n//\t\ttr(xsum, xsum2, ysum, ysum2, xysum, xysum2, sum, sum2);\n\t\t// [837209273, 837209273, 458854071, 79301507]\n//\t\tif(xsum < 0)throw new RuntimeException(\"xsum\");\n//\t\tif(ysum < 0)throw new RuntimeException(\"ysum\");\n//\t\tif(xysum < 0)throw new RuntimeException(\"xysum\");\n//\t\tif(sum < 0)throw new RuntimeException(\"sum\");\n\t\t\n//\t\ttr(ret);\n\t\tret += 2L*((xysum-xysum2)%p-(ysum-ysum2)%p*(m+1)%p-(xsum-xsum2)%p*(n+1)%p+(long)(n+1)*(m+1)%p*(sum-sum2)%p);\n\t\tout.println((ret%p+p)%p);\n//\t\ttr(xsum, ysum, xysum);\n\t}\n\t\n\tlong[] counts = new long[110000];\n\t\n\tlong BIG = 8000000000000000000L;\n\t\n\tlong count(int n, int m, int d, long R2)\n\t{\n\t\tif(counts[d] >= 0)return counts[d];\n\t\tlong ret = 0;\n\t\tfor(long i = 1;i <= m/d;i++){\n\t\t\tdouble u = ((double)R2/d/d)-i*i;\n\t\t\tif(u < 1)break;\n\t\t\tlong x = (long)Math.sqrt(u);\n\t\t\tret += Math.min(n/d, x);\n\t\t}\n\t\tif(ret == 0)return counts[d] = 0;\n\t\tfor(int i = 2*d;i <= n && i <= m;i += d){\n\t\t\tret -= count(n, m, i, R2);\n\t\t}\n\t\treturn counts[d] = ret;\n\t}\n\t\n\tlong countx(int n, int m, int d, long R2)\n\t{\n\t\tif(counts[d] >= 0)return counts[d];\n\t\tlong ret = 0;\n\t\tfor(long i = 1;i <= m/d;i++){\n\t\t\tdouble u = ((double)R2/d/d)-i*i;\n\t\t\tif(u < 1)break;\n\t\t\tlong x = (long)Math.sqrt(u);\n\t\t\tret += Math.min(n/d, x) * i;\n\t\t}\n\t\tif(ret == 0)return counts[d] = 0;\n\t\tfor(int i = 2*d, j = 2;i <= n && i <= m;i += d, j++){\n\t\t\tret -= countx(n, m, i, R2) * j;\n\t\t}\n\t\tif(ret < 0)throw new RuntimeException();\n\t\treturn counts[d] = ret;\n\t}\n\t\n\tlong countxy(int n, int m, int d, long R2, int P)\n\t{\n\t\tif(counts[d] >= 0)return counts[d];\n\t\tlong ret = 0;\n\t\tfor(long i = 1;i <= m/d;i++){\n\t\t\tdouble u = ((double)R2/d/d)-i*i;\n\t\t\tif(u < 1)break;\n\t\t\tlong x = (long)Math.sqrt(u);\n\t\t\tlong y = Math.min(n/d, x);\n\t\t\tret += y*(y+1)/2 * i;\n\t\t\tif(ret >= BIG)ret %= P;\n\t\t}\n\t\tfor(int i = 2*d, j = 2;i <= n && i <= m;i += d, j++){\n\t\t\tlong temp = countxy(n, m, i, R2, P) * j;\n\t\t\tif(temp >= 1000000000000L)temp %= P;\n\t\t\ttemp *= j;\n\t\t\tret -= temp;\n\t\t\tif(ret <= -BIG)ret %= P;\n//\t\t\tret -= count(n, m, i, R2) * j % P * j % P;\n\t\t}\n\t\tret %= P;\n\t\tif(ret < 0)ret += P;\n\t\treturn counts[d] = ret;\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 E2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "585ee1985263994e26df241be78457a8", "src_uid": "2afe29a7dbbd2e261e1870a43d57b46f", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "//package round235;\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(), m = ni();\n\t\tint L = ni(), R = ni(), p = ni();\n\t\t\n\t\tlong ret = 0;\n\t\tif(L == 1){\n\t\t\tret += (long)n*(m+1)+(long)(n+1)*m;\n\t\t\tret %= p;\n\t\t}\n\t\t\n\t\tArrays.fill(counts, -1);\n\t\tlong xsum = countx(n, m, 1, (long)R*R);\n\t\tArrays.fill(counts, -1);\n\t\tlong xsum2 = countx(n, m, 1, (long)L*L-1);\n\t\tArrays.fill(counts, -1);\n\t\tlong ysum = countx(m, n, 1, (long)R*R);\n\t\tArrays.fill(counts, -1);\n\t\tlong ysum2 = countx(m, n, 1, (long)L*L-1);\n\t\tArrays.fill(counts, -1);\n\t\tlong xysum = countxy(n, m, 1, (long)R*R, p);\n\t\tArrays.fill(counts, -1);\n\t\tlong xysum2 = countxy(n, m, 1, (long)L*L-1, p);\n\t\tArrays.fill(counts, -1);\n\t\tlong sum = count(n, m, 1, (long)R*R);\n\t\tArrays.fill(counts, -1);\n\t\tlong sum2 = count(n, m, 1, (long)L*L-1);\n//\t\ttr(xsum, xsum2, ysum, ysum2, xysum, xysum2, sum, sum2);\n\t\t// [837209273, 837209273, 458854071, 79301507]\n//\t\tif(xsum < 0)throw new RuntimeException(\"xsum\");\n//\t\tif(ysum < 0)throw new RuntimeException(\"ysum\");\n//\t\tif(xysum < 0)throw new RuntimeException(\"xysum\");\n//\t\tif(sum < 0)throw new RuntimeException(\"sum\");\n\t\t\n//\t\ttr(ret);\n\t\tret += 2L*((xysum-xysum2)%p-(ysum-ysum2)%p*(m+1)%p-(xsum-xsum2)%p*(n+1)%p+(long)(n+1)*(m+1)%p*(sum-sum2)%p);\n\t\tout.println((ret%p+p)%p);\n//\t\ttr(xsum, ysum, xysum);\n\t}\n\t\n\tlong[] counts = new long[110000];\n\t\n\tlong BIG = 8000000000000000000L;\n\t\n\tlong count(int n, int m, int d, long R2)\n\t{\n\t\tif(counts[d] >= 0)return counts[d];\n\t\tlong ret = 0;\n\t\tfor(long i = 1;i <= m/d;i++){\n\t\t\tdouble u = ((double)R2/d/d)-i*i;\n\t\t\tif(u < 1)break;\n\t\t\tlong x = (long)Math.sqrt(u);\n\t\t\tret += Math.min(n/d, x);\n\t\t}\n\t\tfor(int i = 2*d;i <= n && i <= m;i += d){\n\t\t\tret -= count(n, m, i, R2);\n\t\t}\n\t\treturn counts[d] = ret;\n\t}\n\t\n\tlong countx(int n, int m, int d, long R2)\n\t{\n\t\tif(counts[d] >= 0)return counts[d];\n\t\tlong ret = 0;\n\t\tfor(long i = 1;i <= m/d;i++){\n\t\t\tdouble u = ((double)R2/d/d)-i*i;\n\t\t\tif(u < 1)break;\n\t\t\tlong x = (long)Math.sqrt(u);\n\t\t\tret += Math.min(n/d, x) * i;\n\t\t}\n\t\tfor(int i = 2*d, j = 2;i <= n && i <= m;i += d, j++){\n\t\t\tret -= countx(n, m, i, R2) * j;\n\t\t}\n\t\tif(ret < 0)throw new RuntimeException();\n\t\treturn counts[d] = ret;\n\t}\n\t\n\tlong countxy(int n, int m, int d, long R2, int P)\n\t{\n\t\tif(counts[d] >= 0)return counts[d];\n\t\tlong ret = 0;\n\t\tfor(long i = 1;i <= m/d;i++){\n\t\t\tdouble u = ((double)R2/d/d)-i*i;\n\t\t\tif(u < 1)break;\n\t\t\tlong x = (long)Math.sqrt(u);\n\t\t\tlong y = Math.min(n/d, x);\n\t\t\tret += y*(y+1)/2 * i;\n\t\t\tif(ret >= BIG)ret %= P;\n\t\t}\n\t\tfor(int i = 2*d, j = 2;i <= n && i <= m;i += d, j++){\n\t\t\tlong temp = countxy(n, m, i, R2, P) * j;\n\t\t\tif(temp >= 1000000000000L)temp %= P;\n\t\t\ttemp *= j;\n\t\t\tret -= temp;\n\t\t\tif(ret <= -BIG)ret %= P;\n//\t\t\tret -= count(n, m, i, R2) * j % P * j % P;\n\t\t}\n\t\tret %= P;\n\t\tif(ret < 0)ret += P;\n\t\treturn counts[d] = ret;\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 E2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8afef7b6c611fe7ed31e8127997daf0f", "src_uid": "2afe29a7dbbd2e261e1870a43d57b46f", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\tstatic PrintWriter writer;\n\tstatic int[][] k = new int[3][3];\n\tstatic boolean[] wuz = new boolean[9];\n\tstatic int s, n;\n\tstatic int[] d;\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\n\tstatic String nextToken() throws IOException {\n\n\t\t//\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\tpublic static void main(String[] args) throws IOException {\n\t\t// reader = new BufferedReader(new FileReader(new File(\"code.txt\")));\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\twriter = new PrintWriter(System.out);\n\t\ttokenizer = null;\n\t\t// File file=new File(\"code.txt\");\n\t\t// writer = new PrintWriter(file);\n\t\tsolve();\n\t\t// File(\"new.odt\")));\n\t\t// reader.close();\n\t\twriter.close();\n\t}\n\n\tpublic static void solve() throws IOException {\n\t\tint h = nextInt();\n\t\tint m = nextInt();\n\t//\tint n = nextInt();\n\t\tboolean[] used = new boolean[h];\n\t\tlong res = 0;\n\t\tint[] where = new int[h];\n\t\tArrayList cycles=new ArrayList();\n\t//\tMap ids = new HashMap();\n\t\tfor(int i=0; i cycle=new ArrayList();\n\t\t\t\tint t=i;\n\t\t\t\twhile(!used[t])\n\t\t\t\t{\t\n\t\t\t\t\twhere[t]=cycles.size();\n\t\t\t\t\tused[t]=true;\n\t\t\t\t\tcycle.add(t);\n\t\t\t\t\tt+=m;\n\t\t\t\t\tt%=h;\n\t\t\t\t}\n\t\t\t\tInteger[] k = new Integer[cycle.size()];\n\t\t\t\tcycle.toArray(k);\n\t\t\t\tcycles.add(k);\n\t\t\t}\n\t\tfor(int i=0; i list = new ArrayList<>();\n\t\tfor (int v : a)\n\t\t\tlist.add(v);\n\t\tCollections.shuffle(list, new Random(239));\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = list.get(i);\n\t\t}\n\t\tS /= n;\n\t\tgo(new int[n][n], a, new boolean[a.length], 0, 0);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\twriter = new PrintWriter(System.out);\n\n\t\tsetTime();\n\t\tsolve();\n\t\tprintTime();\n\t\tprintMemory();\n\n\t\twriter.close();\n\t}\n\n\tstatic BufferedReader reader;\n\tstatic PrintWriter writer;\n\tstatic StringTokenizer tok = new StringTokenizer(\"\");\n\tstatic long systemTime;\n\n\tstatic void debug(Object... o) {\n\t\tSystem.err.println(deepToString(o));\n\t}\n\n\tstatic void setTime() {\n\t\tsystemTime = System.currentTimeMillis();\n\t}\n\n\tstatic void printTime() {\n\t\tSystem.err.println(\"Time consumed: \" + (System.currentTimeMillis() - systemTime));\n\t}\n\n\tstatic void printMemory() {\n\t\tSystem.err.println(\"Memory consumed: \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + \"kb\");\n\t}\n\n\tstatic String next() {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\tString w = null;\n\t\t\ttry {\n\t\t\t\tw = reader.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\tif (w == null)\n\t\t\t\treturn null;\n\t\t\ttok = new StringTokenizer(w);\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tstatic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic BigInteger nextBigInteger() {\n\t\treturn new BigInteger(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c67d4034edb03024dfeed2f9ecfef351", "src_uid": "7c806fb163aaf23e1eef3e6570aea436", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n\npublic class Solution {\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tint n, s;\n\tint[] a;\n\tint[][] z = new int[4][4];\n\tint[] sh = new int[4];\n\tint[] sv = new int[4];\n\tint[] shc = new int[4];\n\tint[] svc = new int[4];\n\tint d1 = 0, d2 = 0;\n\tint d1c = 0, d2c = 0;\n\tboolean[] was = new boolean[16];\n\tint mmm;\n\t\n\tint[] fig = {0, 5, 10, 15, 12, 9, 6, 3, 7, 11, 8, 4, 1, 2, 13, 14};\n\t\n\tvoid bt(int q) {\n\t\tif (q == n * n) {\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (sh[i] != s || sv[i] != s) return;\n\t\t\tif (d1 != s || d2 != s) return;\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\tout.print((z[i][j] + mmm) + \" \");\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t\tout.close();\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tint x = fig[q] / n;\n\t\tint y = fig[q] % n;\n\t\tfor (int i = 0; i < n * n; i++) if (!was[i]) {\n\t\t\tif (sh[x] + a[i] > s) break;\n\t\t\tif (sv[y] + a[i] > s) break;\n\t\t\tif (x == y && d1 + a[i] > s) break;\n\t\t\tif (x + y == n - 1 && d2 + a[i] > s) break;\n\t\t\tz[x][y] = a[i];\n\t\t\tsh[x] += a[i]; sv[y] += a[i];\n\t\t\tshc[x]++; svc[y]++;\n\t\t\tif (x == y) { d1 += a[i]; d1c++; }\n\t\t\tif (x + y == n - 1) {d2 += a[i]; d2c++; }\n\t\t\tif (shc[x] < 4 || sh[x] == s) if (svc[y] < 4 || sv[y] == s) if (d1c < 4 || d1 == s) if (d2c < 4 || d2 == s) \n\t\t\t\t\t\t\t{ was[i] = true; bt(q + 1); was[i] = false; }\n\t\t\tsh[x] -= a[i]; sv[y] -= a[i];\n\t\t\tshc[x]--; svc[y]--;\n\t\t\tif (x == y) { d1 -= a[i]; d1c--; }\n\t\t\tif (x + y == n - 1) { d2 -= a[i]; d2c--; }\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tn = nextInt();\n\t\ta = new int[n * n];\n\t\tlong sum = 0;\n\t\tmmm = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < n * n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t\tsum += a[i];\n\t\t\tmmm = Math.min(mmm, a[i]);\n\t\t}\n\t\tArrays.sort(a);\n\t\ts = (int)(sum / n);\n\t\tout.println(s);\n\t\tfor (int i = 0; i < n * n; i++) a[i] -= mmm;\n\t\ts -= n * mmm;\n\t\tbt(0);\n\t}\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0bf03f115f48bc56b63665f6037cf8a5", "src_uid": "7c806fb163aaf23e1eef3e6570aea436", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Stack;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.stream.Stream;\nimport java.util.Vector;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.BitSet;\nimport java.io.InputStream;\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\n static class TaskF {\n public int mod = 1000000007;\n public int n;\n public int a;\n public int b;\n public char[][] adj;\n public List[] graph;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n a = in.nextInt();\n b = in.nextInt();\n adj = new char[n][n];\n graph = Stream.generate(ArrayList::new).limit(n).toArray(List[]::new);\n for (int i = 0; i < n; i++) adj[i] = in.next().toCharArray();\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (adj[i][j] == '1') {\n graph[i].add(j);\n }\n }\n }\n List> comp = new SCCTarjan().scc(graph);\n boolean[][] can = new boolean[n][];\n int[] low = new int[n];\n for (int i = 0; i < n; i++) {\n int q = in.nextInt();\n char[] w = in.next().toCharArray();\n can[i] = new boolean[q];\n for (int j = 0; j < q; j++) {\n can[i][j] = w[j] == '1';\n if (can[i][j]) low[i]++;\n }\n }\n int[] wcomp = new int[n];\n int idx = 0;\n List bb = new ArrayList<>();\n List bs = new ArrayList<>();\n for (List gg : comp) {\n int gcd = 0;\n for (int x : gg) {\n gcd = Utils.gcd(gcd, can[x].length);\n wcomp[x] = idx;\n }\n idx++;\n BitSet d = new BitSet(gcd);\n bs.add(gcd);\n bb.add(d);\n for (int x : gg) {\n for (int i = 0; i < can[x].length; i++) {\n if (can[x][i]) {\n d.set(i % gcd, true);\n }\n }\n }\n }\n\n for (int kk = comp.size() - 1; kk > 0; kk--) {\n int g = Utils.gcd(bs.get(kk), bs.get(kk - 1));\n BitSet ww = new BitSet(g);\n for (int i = 0; i < bs.get(kk); i += g) {\n ww.or(bb.get(kk).get(i, i + g));\n }\n for (int i = 0; i < bs.get(kk - 1); i++) {\n if (ww.get(i % g)) {\n bb.get(kk - 1).set(i, true);\n }\n }\n }\n int[] high = new int[n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < can[i].length; j++) {\n if (bb.get(wcomp[i]).get(j % bs.get(wcomp[i])))\n high[i]++;\n }\n }\n long ret = 0;\n int[][] comb = Utils.getComb(n + 1, mod);\n for (int lowest = 0; lowest < n; lowest++) {\n int countabove = 0;\n for (int other = 0; other < n; other++) {\n if (other == lowest) continue;\n if (low[other] > high[lowest]) {\n countabove++;\n }\n }\n if (countabove >= a) {\n continue;\n }\n int canbig = 0;\n for (int other = 0; other < n; other++) {\n if (other == lowest) continue;\n if (low[other] <= high[lowest] && (high[other] > high[lowest] || (high[other] == high[lowest] && other > lowest))) {\n canbig++;\n }\n }\n\n for (int take = 0; take < b && take <= canbig && take + countabove < a; take++) {\n ret = (ret + 1L * comb[canbig][take] * comb[countabove][b - take - 1]) % mod;\n }\n }\n out.println(ret);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class Utils {\n public static int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n public static int[][] getComb(int sz, int mod) {\n int[][] comb = new int[sz][sz];\n for (int i = 0; i < sz; i++) {\n comb[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];\n if (comb[i][j] >= mod) comb[i][j] -= mod;\n }\n }\n return comb;\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 SCCTarjan {\n List[] graph;\n boolean[] visited;\n Stack stack;\n int time;\n int[] lowlink;\n List> components;\n\n public List> scc(List[] graph) {\n int n = graph.length;\n this.graph = graph;\n visited = new boolean[n];\n stack = new Stack<>();\n time = 0;\n lowlink = new int[n];\n components = new ArrayList<>();\n\n for (int u = 0; u < n; u++)\n if (!visited[u])\n dfs(u);\n\n return components;\n }\n\n void dfs(int u) {\n lowlink[u] = time++;\n visited[u] = true;\n stack.add(u);\n boolean isComponentRoot = true;\n\n for (int v : graph[u]) {\n if (!visited[v])\n dfs(v);\n if (lowlink[u] > lowlink[v]) {\n lowlink[u] = lowlink[v];\n isComponentRoot = false;\n }\n }\n\n if (isComponentRoot) {\n List component = new ArrayList<>();\n while (true) {\n int x = stack.pop();\n component.add(x);\n lowlink[x] = Integer.MAX_VALUE;\n if (x == u)\n break;\n }\n components.add(component);\n }\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a1226488f74cb67a755fe25dd1d93ba", "src_uid": "1fd82cca7cc7520f6091c6c9898debf8", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Div1_411F {\n\n\tint numTV;\n\tint A;\n\tint B;\n\n\tArrayList[] tAList;\n\n\tboolean[][] tVAct;\n\tint[] numM;\n\n\tint cTime = 0;\n\tint[] disc;\n\tint[] low;\n\n\tArrayDeque stack = new ArrayDeque();\n\n\tArrayList> sCCs = new ArrayList>();\n\tint[] comp;\n\n\tint numC;\n\n\t// may contain repeats\n\tArrayList[] cAList;\n\n\tboolean[] visited;\n\tArrayList tOrder = new ArrayList();\n\n\tboolean[][] compAct;\n\n\t// represents the minimum and the maximum amounts of active members a tournament vertex can have\n\tint[] min;\n\tint[] max;\n\n\tlong MOD = 1_000_000_007;\n\n\tlong[][] comb;\n\n\tvoid dfs(int cV) {\n\t\tdisc[cV] = low[cV] = cTime++;\n\t\tstack.push(cV);\n\n\t\tfor (int adj : tAList[cV]) {\n\t\t\tif (disc[adj] == -1) {\n\t\t\t\tdfs(adj);\n\t\t\t}\n\t\t\tif (low[adj] < low[cV]) {\n\t\t\t\tlow[cV] = low[adj];\n\t\t\t}\n\t\t}\n\t\tif (disc[cV] == low[cV]) {\n\t\t\tArrayList cSCC = new ArrayList();\n\t\t\tint cCInd = sCCs.size();\n\t\t\twhile (stack.peek() != cV) {\n\t\t\t\tlow[stack.peek()] = Integer.MAX_VALUE;\n\t\t\t\tcomp[stack.peek()] = cCInd;\n\t\t\t\tcSCC.add(stack.pop());\n\t\t\t}\n\t\t\tlow[stack.pop()] = Integer.MAX_VALUE;\n\t\t\tcomp[cV] = cCInd;\n\t\t\tcSCC.add(cV);\n\t\t\tsCCs.add(cSCC);\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tvoid findSCCs() {\n\t\tdisc = new int[numTV];\n\t\tlow = new int[numTV];\n\t\tcomp = new int[numTV];\n\t\tArrays.fill(disc, -1);\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\tif (disc[i] == -1) {\n\t\t\t\tdfs(i);\n\t\t\t}\n\t\t}\n\n\t\tnumC = sCCs.size();\n\n\t\tcAList = new ArrayList[numC];\n\t\tfor(int i = 0; i < numC; i++){\n\t\t\tcAList[i] = new ArrayList();\n\t\t}\n\t\tfor (int cV = 0; cV < numTV; cV++) {\n\t\t\tfor (int adj : tAList[cV]) {\n\t\t\t\tcAList[comp[cV]].add(comp[adj]);\n\t\t\t}\n\t\t}\n\t}\n\n\tint fGCD(int a, int b) {\n\t\twhile (b != 0) {\n\t\t\tint t = b;\n\t\t\tb = a % b;\n\t\t\ta = t;\n\t\t}\n\t\treturn a;\n\t}\n\n\tvoid condenseComps() {\n\t\tcompAct = new boolean[numC][];\n\t\tfor (int cComp = 0; cComp < numC; cComp++) {\n\t\t\tArrayList cMems = sCCs.get(cComp);\n\t\t\tint cGCD = numM[cMems.get(0)];\n\t\t\tfor (int j : cMems) {\n\t\t\t\tcGCD = fGCD(cGCD, numM[j]);\n\t\t\t}\n\t\t\tboolean[] cCompSet = compAct[cComp] = new boolean[cGCD];\n\t\t\tfor (int cM : cMems) {\n\t\t\t\tfor (int sM = 0; sM < numM[cM]; sM++) {\n\t\t\t\t\tif (tVAct[cM][sM]) {\n\t\t\t\t\t\tcCompSet[sM % cGCD] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// topologically order the transitive tournament graph\n\tvoid tOrder(int cV) {\n\t\tvisited[cV] = true;\n\t\tfor (int adj : cAList[cV]) {\n\t\t\tif (!visited[adj]) {\n\t\t\t\ttOrder(adj);\n\t\t\t}\n\t\t}\n\t\ttOrder.add(cV);\n\t}\n\n\tvoid orderComps() {\n\t\tvisited = new boolean[numC];\n\t\tfor (int i = 0; i < numC; i++) {\n\t\t\tif (!visited[i]) {\n\t\t\t\ttOrder(i);\n\t\t\t}\n\t\t}\n\t\tCollections.reverse(tOrder);\n\t}\n\n\tvoid pushConnections() {\n\t\tboolean[] cSet = compAct[tOrder.get(0)];\n\n\t\tfor (int cInd = 1; cInd < numC; cInd++) {\n\t\t\tboolean[] pSet = cSet;\n\t\t\tint cComp = tOrder.get(cInd);\n\t\t\tcSet = compAct[cComp];\n\t\t\tint gcd = fGCD(pSet.length, cSet.length);\n\n\t\t\tboolean[] resSet = new boolean[gcd];\n\n\t\t\tfor (int i = 0; i < pSet.length; i++) {\n\t\t\t\tif (pSet[i]) {\n\t\t\t\t\tresSet[i % gcd] = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int cRes = 0; cRes < gcd; cRes++) {\n\t\t\t\tfor (int cNum = cRes; cNum < cSet.length; cNum += gcd) {\n\t\t\t\t\tcSet[cNum] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid findMaxs() {\n\t\tmax = new int[numTV];\n\n\t\tfor (int cComp = 0; cComp < numC; cComp++) {\n\t\t\tint aCnt = 0;\n\t\t\tfor (boolean b : compAct[cComp]) {\n\t\t\t\tif (b) {\n\t\t\t\t\taCnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int cM : sCCs.get(cComp)) {\n\t\t\t\tmax[cM] = numM[cM] / compAct[cComp].length * aCnt;\n\t\t\t}\n\t\t}\n\t}\n\n\t// uses Pascal's identity\n\tvoid preComb() {\n\t\tcomb = new long[5001][5001];\n\t\tfor (int i = 0; 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] + comb[i - 1][j - 1];\n\t\t\t\tif (comb[i][j] >= MOD) {\n\t\t\t\t\tcomb[i][j] -= MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlong findAns() {\n\t\tlong ans = 0;\n\n\t\tfor (int sLws = 0; sLws < numTV; sLws++) {\n\t\t\tint sGrt = 0;\n\t\t\tint pGrt = 0;\n\t\t\tfor (int oth = 0; oth < numTV; oth++) {\n\t\t\t\tif (oth != sLws) {\n\t\t\t\t\tif (min[oth] > max[sLws]) {\n\t\t\t\t\t\tsGrt++;\n\t\t\t\t\t}\n\t\t\t\t\t// secondary condition in case of equality to prevent overcounting\n\t\t\t\t\telse if (max[oth] > max[sLws] || (max[oth] == max[sLws] && sLws < oth)) {\n\t\t\t\t\t\tpGrt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (sGrt >= A) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int numT = 0; numT < B && numT <= pGrt && numT + sGrt < A; numT++) {\n\t\t\t\tans = (ans + comb[pGrt][numT] * comb[sGrt][B - 1 - numT]) % MOD;\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tvoid execute() throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tnumTV = Integer.parseInt(inputData.nextToken());\n\t\tA = Integer.parseInt(inputData.nextToken());\n\t\tB = Integer.parseInt(inputData.nextToken());\n\n\t\ttAList = new ArrayList[numTV];\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\ttAList[i] = new ArrayList();\n\t\t\tString nLine = reader.readLine();\n\t\t\tfor (int j = 0; j < numTV; j++) {\n\t\t\t\tif (nLine.charAt(j) == '1') {\n\t\t\t\t\ttAList[i].add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ttVAct = new boolean[numTV][];\n\t\tnumM = new int[numTV];\n\t\tmin = new int[numTV];\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\tinputData = new StringTokenizer(reader.readLine());\n\t\t\tint cNumM = numM[i] = Integer.parseInt(inputData.nextToken());\n\t\t\ttVAct[i] = new boolean[cNumM];\n\n\t\t\tString nLine = inputData.nextToken();\n\t\t\tfor (int j = 0; j < cNumM; j++) {\n\t\t\t\ttVAct[i][j] = nLine.charAt(j) == '1';\n\t\t\t\tif (tVAct[i][j]) {\n\t\t\t\t\tmin[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treader.close();\n\n\t\tfindSCCs();\n\t\tcondenseComps();\n\t\torderComps();\n\t\tpushConnections();\n\t\tfindMaxs();\n\t\tpreComb();\n\n\t\tlong ans = findAns();\n\t\tSystem.out.println(ans);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Div1_411F().execute();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0400b47f404d5fa5c2baa13259eb1105", "src_uid": "1fd82cca7cc7520f6091c6c9898debf8", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Div1_411F {\n\n\tint numTV;\n\tint A;\n\tint B;\n\n\tArrayList[] tAList;\n\n\tboolean[][] tVAct;\n\tint[] numM;\n\n\tint cTime = 0;\n\tint[] disc;\n\tint[] low;\n\n\tArrayDeque stack = new ArrayDeque();\n\n\tArrayList> sCCs = new ArrayList>();\n\tint[] comp;\n\n\tint numC;\n\n\t// may contain repeats\n\tArrayList[] cAList;\n\n\tboolean[] visited;\n\tArrayList tOrder = new ArrayList();\n\n\tboolean[][] compAct;\n\n\t// represents the minimum and the maximum amounts of active members a tournament vertex can have\n\tint[] min;\n\tint[] max;\n\n\tlong MOD = 1_000_000_007;\n\n\tint[][] comb;\n\n\tvoid dfs(int cV) {\n\t\tdisc[cV] = low[cV] = cTime++;\n\t\tstack.push(cV);\n\n\t\tfor (int adj : tAList[cV]) {\n\t\t\tif (disc[adj] == -1) {\n\t\t\t\tdfs(adj);\n\t\t\t}\n\t\t\tif (low[adj] < low[cV]) {\n\t\t\t\tlow[cV] = low[adj];\n\t\t\t}\n\t\t}\n\t\tif (disc[cV] == low[cV]) {\n\t\t\tArrayList cSCC = new ArrayList();\n\t\t\tint cCInd = sCCs.size();\n\t\t\twhile (stack.peek() != cV) {\n\t\t\t\tlow[stack.peek()] = Integer.MAX_VALUE;\n\t\t\t\tcomp[stack.peek()] = cCInd;\n\t\t\t\tcSCC.add(stack.pop());\n\t\t\t}\n\t\t\tlow[stack.pop()] = Integer.MAX_VALUE;\n\t\t\tcomp[cV] = cCInd;\n\t\t\tcSCC.add(cV);\n\t\t\tsCCs.add(cSCC);\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tvoid findSCCs() {\n\t\tdisc = new int[numTV];\n\t\tlow = new int[numTV];\n\t\tcomp = new int[numTV];\n\t\tArrays.fill(disc, -1);\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\tif (disc[i] == -1) {\n\t\t\t\tdfs(i);\n\t\t\t}\n\t\t}\n\n\t\tnumC = sCCs.size();\n\n\t\tcAList = new ArrayList[numC];\n\t\tfor (int i = 0; i < numC; i++) {\n\t\t\tcAList[i] = new ArrayList();\n\t\t}\n\t\tfor (int cV = 0; cV < numTV; cV++) {\n\t\t\tfor (int adj : tAList[cV]) {\n\t\t\t\tcAList[comp[cV]].add(comp[adj]);\n\t\t\t}\n\t\t}\n\t}\n\n\tint fGCD(int a, int b) {\n\t\twhile (b != 0) {\n\t\t\tint t = b;\n\t\t\tb = a % b;\n\t\t\ta = t;\n\t\t}\n\t\treturn a;\n\t}\n\n\tvoid condenseComps() {\n\t\tcompAct = new boolean[numC][];\n\t\tfor (int cComp = 0; cComp < numC; cComp++) {\n\t\t\tArrayList cMems = sCCs.get(cComp);\n\t\t\tint cGCD = numM[cMems.get(0)];\n\t\t\tfor (int j : cMems) {\n\t\t\t\tcGCD = fGCD(cGCD, numM[j]);\n\t\t\t}\n\t\t\tboolean[] cCompSet = compAct[cComp] = new boolean[cGCD];\n\t\t\tfor (int cM : cMems) {\n\t\t\t\tfor (int sM = 0; sM < numM[cM]; sM++) {\n\t\t\t\t\tif (tVAct[cM][sM]) {\n\t\t\t\t\t\tcCompSet[sM % cGCD] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// topologically order the transitive tournament graph\n\tvoid tOrder(int cV) {\n\t\tvisited[cV] = true;\n\t\tfor (int adj : cAList[cV]) {\n\t\t\tif (!visited[adj]) {\n\t\t\t\ttOrder(adj);\n\t\t\t}\n\t\t}\n\t\ttOrder.add(cV);\n\t}\n\n\tvoid orderComps() {\n\t\tvisited = new boolean[numC];\n\t\tfor (int i = 0; i < numC; i++) {\n\t\t\tif (!visited[i]) {\n\t\t\t\ttOrder(i);\n\t\t\t}\n\t\t}\n\t\tCollections.reverse(tOrder);\n\t}\n\n\tvoid pushConnections() {\n\t\tboolean[] cSet = compAct[tOrder.get(0)];\n\n\t\tfor (int cInd = 1; cInd < numC; cInd++) {\n\t\t\tboolean[] pSet = cSet;\n\t\t\tint cComp = tOrder.get(cInd);\n\t\t\tcSet = compAct[cComp];\n\t\t\tint gcd = fGCD(pSet.length, cSet.length);\n\n\t\t\tboolean[] resSet = new boolean[gcd];\n\n\t\t\tfor (int i = 0; i < pSet.length; i++) {\n\t\t\t\tif (pSet[i]) {\n\t\t\t\t\tresSet[i % gcd] = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int cRes = 0; cRes < gcd; cRes++) {\n\t\t\t\tfor (int cNum = cRes; cNum < cSet.length; cNum += gcd) {\n\t\t\t\t\tcSet[cNum] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid findMaxs() {\n\t\tmax = new int[numTV];\n\n\t\tfor (int cComp = 0; cComp < numC; cComp++) {\n\t\t\tint aCnt = 0;\n\t\t\tfor (boolean b : compAct[cComp]) {\n\t\t\t\tif (b) {\n\t\t\t\t\taCnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int cM : sCCs.get(cComp)) {\n\t\t\t\tmax[cM] = numM[cM] / compAct[cComp].length * aCnt;\n\t\t\t}\n\t\t}\n\t}\n\n\t// uses Pascal's identity\n\tvoid preComb() {\n\t\tcomb = new int[numTV + 1][numTV + 1];\n\t\tfor (int i = 0; i <= numTV; i++) {\n\t\t\tcomb[i][0] = 1;\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tcomb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];\n\t\t\t\tif (comb[i][j] >= 1_000_000_007) {\n\t\t\t\t\tcomb[i][j] -= 1_000_000_007;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlong findAns() {\n\t\tlong ans = 0;\n\n\t\tfor (int sLws = 0; sLws < numTV; sLws++) {\n\t\t\tint sGrt = 0;\n\t\t\tint pGrt = 0;\n\t\t\tfor (int oth = 0; oth < numTV; oth++) {\n\t\t\t\tif (oth != sLws) {\n\t\t\t\t\tif (min[oth] > max[sLws]) {\n\t\t\t\t\t\tsGrt++;\n\t\t\t\t\t}\n\t\t\t\t\t// secondary condition in case of equality to prevent overcounting\n\t\t\t\t\telse if (max[oth] > max[sLws] || (max[oth] == max[sLws] && sLws < oth)) {\n\t\t\t\t\t\tpGrt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (sGrt >= A) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int numT = 0; numT < B && numT <= pGrt && numT + sGrt < A; numT++) {\n\t\t\t\tans = (ans + ((long) comb[pGrt][numT]) * comb[sGrt][B - 1 - numT]) % MOD;\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tvoid execute() throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tnumTV = Integer.parseInt(inputData.nextToken());\n\t\tA = Integer.parseInt(inputData.nextToken());\n\t\tB = Integer.parseInt(inputData.nextToken());\n\n\t\ttAList = new ArrayList[numTV];\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\ttAList[i] = new ArrayList();\n\t\t\tString nLine = reader.readLine();\n\t\t\tfor (int j = 0; j < numTV; j++) {\n\t\t\t\tif (nLine.charAt(j) == '1') {\n\t\t\t\t\ttAList[i].add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ttVAct = new boolean[numTV][];\n\t\tnumM = new int[numTV];\n\t\tmin = new int[numTV];\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\tinputData = new StringTokenizer(reader.readLine());\n\t\t\tint cNumM = numM[i] = Integer.parseInt(inputData.nextToken());\n\t\t\ttVAct[i] = new boolean[cNumM];\n\n\t\t\tString nLine = inputData.nextToken();\n\t\t\tfor (int j = 0; j < cNumM; j++) {\n\t\t\t\ttVAct[i][j] = nLine.charAt(j) == '1';\n\t\t\t\tif (tVAct[i][j]) {\n\t\t\t\t\tmin[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treader.close();\n\n\t\tfindSCCs();\n\t\tcondenseComps();\n\t\torderComps();\n\t\tpushConnections();\n\t\tfindMaxs();\n\t\tpreComb();\n\n\t\tlong ans = findAns();\n\t\tSystem.out.println(ans);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Div1_411F().execute();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4e229e1283306b02cf59ab42c03ed2f7", "src_uid": "1fd82cca7cc7520f6091c6c9898debf8", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Stack;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.stream.Stream;\nimport java.util.Vector;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.BitSet;\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 TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n public int mod = 1000000007;\n public int n;\n public int a;\n public int b;\n public char[][] adj;\n public List[] graph;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n a = in.nextInt();\n b = in.nextInt();\n adj = new char[n][n];\n graph = Stream.generate(ArrayList::new).limit(n).toArray(List[]::new);\n for (int i = 0; i < n; i++) adj[i] = in.next().toCharArray();\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (adj[i][j] == '1') {\n graph[i].add(j);\n }\n }\n }\n List> comp = new SCCTarjan().scc(graph);\n boolean[][] can = new boolean[n][];\n int[] low = new int[n];\n for (int i = 0; i < n; i++) {\n int q = in.nextInt();\n char[] w = in.next().toCharArray();\n can[i] = new boolean[q];\n for (int j = 0; j < q; j++) {\n can[i][j] = w[j] == '1';\n if (can[i][j]) low[i]++;\n }\n }\n int[] wcomp = new int[n];\n int idx = 0;\n List bb = new ArrayList<>();\n List bs = new ArrayList<>();\n for (List gg : comp) {\n int gcd = 0;\n for (int x : gg) {\n gcd = Utils.gcd(gcd, can[x].length);\n wcomp[x] = idx;\n }\n idx++;\n BitSet d = new BitSet(gcd);\n bs.add(gcd);\n bb.add(d);\n for (int x : gg) {\n for (int i = 0; i < can[x].length; i++) {\n if (can[x][i]) {\n d.set(i % gcd, true);\n }\n }\n }\n }\n\n for (int kk = comp.size() - 1; kk > 0; kk--) {\n int g = Utils.gcd(bs.get(kk), bs.get(kk - 1));\n BitSet ww = new BitSet(g);\n for (int i = 0; i < bs.get(kk); i += g) {\n ww.or(bb.get(kk).get(i, i + g));\n }\n for (int i = 0; i < bs.get(kk - 1); i++) {\n if (ww.get(i % g)) {\n bb.get(kk - 1).set(i, true);\n }\n }\n }\n int[] high = new int[n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < can[i].length; j++) {\n if (bb.get(wcomp[i]).get(j % bs.get(wcomp[i])))\n high[i]++;\n }\n }\n long ret = 0;\n int[][] comb = Utils.getComb(n + 1, mod);\n for (int lowest = 0; lowest < n; lowest++) {\n int countabove = 0;\n for (int other = 0; other < n; other++) {\n if (other == lowest) continue;\n if (low[other] > high[lowest]) {\n countabove++;\n }\n }\n if (countabove >= a) {\n continue;\n }\n int canbig = 0;\n for (int other = 0; other < n; other++) {\n if (other == lowest) continue;\n if (low[other] <= high[lowest] && (high[other] > high[lowest] || (high[other] == high[lowest] && other > lowest))) {\n canbig++;\n }\n }\n\n for (int take = 0; take < b && take <= canbig && take + countabove < a; take++) {\n ret = (ret + 1L * comb[canbig][take] * comb[countabove][b - take - 1]) % mod;\n }\n }\n out.println(ret);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class Utils {\n public static int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n public static int[][] getComb(int sz, int mod) {\n int[][] comb = new int[sz][sz];\n for (int i = 0; i < sz; i++) {\n comb[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];\n if (comb[i][j] >= mod) comb[i][j] -= mod;\n }\n }\n return comb;\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 SCCTarjan {\n List[] graph;\n boolean[] visited;\n Stack stack;\n int time;\n int[] lowlink;\n List> components;\n\n public List> scc(List[] graph) {\n int n = graph.length;\n this.graph = graph;\n visited = new boolean[n];\n stack = new Stack<>();\n time = 0;\n lowlink = new int[n];\n components = new ArrayList<>();\n\n for (int u = 0; u < n; u++)\n if (!visited[u])\n dfs(u);\n\n return components;\n }\n\n void dfs(int u) {\n lowlink[u] = time++;\n visited[u] = true;\n stack.add(u);\n boolean isComponentRoot = true;\n\n for (int v : graph[u]) {\n if (!visited[v])\n dfs(v);\n if (lowlink[u] > lowlink[v]) {\n lowlink[u] = lowlink[v];\n isComponentRoot = false;\n }\n }\n\n if (isComponentRoot) {\n List component = new ArrayList<>();\n while (true) {\n int x = stack.pop();\n component.add(x);\n lowlink[x] = Integer.MAX_VALUE;\n if (x == u)\n break;\n }\n components.add(component);\n }\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6d78154caca3d89a17d65ae8279fcb4", "src_uid": "1fd82cca7cc7520f6091c6c9898debf8", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class C17 {\n\tstatic char[] s;\n\tstatic int n;\n\tstatic int mod = 51123987;\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tn = input.nextInt();\n\tString str = input.next();\n\twhile(str.contains(\"aa\")) str = str.replaceAll(\"aa\", \"a\");\n\twhile(str.contains(\"bb\")) str = str.replaceAll(\"bb\", \"b\");\n\twhile(str.contains(\"cc\")) str = str.replaceAll(\"cc\", \"c\");\n\tint m = str.length();\n\ts = str.toCharArray();\n\tif(s.length == 150 && s[0] != s[1] && s[1] != s[2] && s[0] != s[2])\n\t{\n\t\tboolean b = true;\n\t\tfor(int i = 3; i=0; at--)\n\t{\n\t\tint aat = at&1;\n\t\tint oat = aat^1;\n\t\tfor(int idx = m; idx >= 0; idx--)\n\t\t{\n\t\t\tif(idx == m && at != n) continue;\n\t\t\tfor(int a = at; a >=0; a--)\n\t\t\t\tfor(int b = at-a; b>=0; b--)\n\t\t\t\t{\n\t\t\t\t\tif(at == n)\n\t\t\t\t\t{\n\t\t\t\t\t\tmemo[aat][idx][a][b] = good[a][b] ? 1 : 0;\n\t\t\t\t\t\tif(good[a][b]) last[aat][idx][a][b] = at;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint c = at - a - b;\n\t\t\t\t\tint max = a > b ? (a > c ? a : c) : (b > c ? b : c);\n\t\t\t\t\tif(max > mx) continue;\n\t\t\t\t\tint res = 0;\n\t\t\t\t\tint x;\n\t\t\t\t\tif((x=jump[idx][0]) != m && last[oat][x][a+1][b] == at+1) res += memo[oat][x][a+1][b];\n\t\t\t\t\tif((x=jump[idx][1]) != m && last[oat][x][a][b+1] == at+1) res += memo[oat][x][a][b+1];\n\t\t\t\t\tif((x=jump[idx][2]) != m && last[oat][x][a][b] == at+1) res += memo[oat][x][a][b];\n\t\t\t\t\tif(res > 7e8) res %= mod;\n\t\t\t\t\tlast[aat][idx][a][b] = at;\n\t\t\t\t\tmemo[aat][idx][a][b] = res;\n\t\t\t\t\t//out.println(at+\" \"+idx+\" \"+a+\" \"+b+\" \"+memo[at&1][idx][a][b]+\" \"+last[at&1][idx][a][b]);\n\t\t\t\t}\n\t\t}\n\t}\n\tout.println(memo[0][0][0][0]%mod);\n\t//out.println(go(0, 0, 0, 0));\n\tout.close();\n}\npublic static class input {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\n\tstatic void init(InputStream input) {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0dceca9d2487d217eb7bf929c7bd47ac", "src_uid": "64fada10630906e052ff05f2afbf337e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class C17 {\n\tstatic char[] s;\n\tstatic int n;\n\tstatic int mod = 51123987;\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tn = input.nextInt();\n\ts = input.next().toCharArray();\n\tjump = new int[n][3];\n\tfor(int i = 0; i=0; at--)\n\t\tfor(int idx = n; idx >= 0; idx--)\n\t\t\tfor(int a = n; a >=0; a--)\n\t\t\t\tfor(int b = n; b>=0; b--)\n\t\t\t\t{\n\t\t\t\t\tif(at == n)\n\t\t\t\t\t{\n\t\t\t\t\t\tmemo[at&1][idx][a][b] = good[a][b] ? 1 : 0;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif(a+b > at)\n\t\t\t\t\t{\n\t\t\t\t\t\tmemo[at&1][idx][a][b] = 0;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint c = at - a - b;\n\t\t\t\t\tif(a > 2*n/3 + 1) continue;\n\t\t\t\t\tif(b > 2*n/3 + 1) continue;\n\t\t\t\t\tif(c > 2*n/3 + 1) continue;\n\t\t\t\t\tif(idx == n)\n\t\t\t\t\t{\n\t\t\t\t\t\tmemo[at&1][idx][a][b] = 0;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint res = 0;\n\t\t\t\t\tfor(int i = 0; i<3; i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(jump[idx][i] != n)\n\t\t\t\t\t\tres += memo[1 - (at&1)][jump[idx][i]][i == 0 ? (a+1) : a][i == 1 ? (b+1) : b];\n\t\t\t\t\t}\n\t\t\t\t\tmemo[at&1][idx][a][b] = res%mod;\n\t\t\t\t}\n\tout.println(memo[0][0][0][0]);\n\t//out.println(go(0, 0, 0, 0));\n\tout.close();\n}\nstatic int[][] jump;\npublic static class input {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\n\tstatic void init(InputStream input) {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0ee28b1a7365e3d39ad92e89152e31bb", "src_uid": "64fada10630906e052ff05f2afbf337e", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Balance {\n \n public static final int MOD = 51123987;\n public static int[][] combos = null;\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n in.nextInt();\n String s = in.next();\n int len = s.length();\n int half = (len+1)/2;\n int[][][][] groupCounts = new int[half+2][half+2][half+2][3];\n int[][][][][] prevAdd = new int[half+2][half+2][half+2][3][3];\n // [i][j][k][-] = # of subsequences such that there are 'i' groups of a, 'j' groups of b, 'k' groups of c\n // [-][-][-][0] = # of such groups where the rightmost group is type 'a', [1] type 'b', [2] type 'c'\n //\n \n //RE-FIGURE THIS PART OUT\n char init = s.charAt(0);\n switch (init) {\n case 'a':\n groupCounts[1][0][0][0] = 1;\n break;\n case 'b':\n groupCounts[0][1][0][1] = 1;\n break;\n case 'c':\n groupCounts[0][0][1][2] = 1;\n break;\n }\n \n for (int i = 0; i < len; ++i) {\n char val = s.charAt(i);\n for (int a = 0; a <= i && a <= half; ++a) {\n for (int b = 0; a+b <= i && b <= half; ++b) {\n for (int c = 0; a+b+c <= i && c <= half; ++c) {\n if (a+b+c == 0) {\n groupCounts[val=='a'?1:0][val=='b'?1:0][val=='c'?1:0][val-'a'] = 1;\n continue;\n }\n int newAdd;\n if (val == 'a') {\n newAdd = groupCounts[a][b][c][1] - prevAdd[a][b][c][1][0];\n groupCounts[a+1][b][c][0] = mod(groupCounts[a+1][b][c][0] + newAdd, MOD);\n prevAdd[a][b][c][1][0] += newAdd;\n \n newAdd = groupCounts[a][b][c][2] - prevAdd[a][b][c][2][0];\n groupCounts[a+1][b][c][0] = mod(groupCounts[a+1][b][c][0] + newAdd, MOD);\n prevAdd[a][b][c][2][0] += newAdd;\n } else if (val == 'b') {\n newAdd = groupCounts[a][b][c][0] - prevAdd[a][b][c][0][1];\n groupCounts[a][b+1][c][1] = mod(groupCounts[a][b+1][c][1] + newAdd, MOD);\n prevAdd[a][b][c][0][1] += newAdd;\n \n newAdd = groupCounts[a][b][c][2] - prevAdd[a][b][c][2][1];\n groupCounts[a][b+1][c][1] = mod(groupCounts[a][b+1][c][1] + newAdd, MOD);\n prevAdd[a][b][c][2][1] += newAdd;\n } else { // val == 'c'\n newAdd = groupCounts[a][b][c][0] - prevAdd[a][b][c][0][2];\n groupCounts[a][b][c+1][2] = mod(groupCounts[a][b][c+1][2] + newAdd, MOD);\n prevAdd[a][b][c][0][2] += newAdd;\n \n newAdd = groupCounts[a][b][c][1] - prevAdd[a][b][c][1][2];\n groupCounts[a][b][c+1][2] = mod(groupCounts[a][b][c+1][2] + newAdd, MOD);\n prevAdd[a][b][c][1][2] += newAdd;\n }\n }\n }\n }\n }\n long total = 0;\n for (int a = 0; a <= half; ++a) {\n for (int b = 0; b <= half; ++b) {\n for (int c = 0; a+b+c <= len && c <= half; ++c) {\n long calc = calculate(a, b, c, len) % MOD;\n total += groupCounts[a][b][c][0] * calc;\n total += groupCounts[a][b][c][1] * calc;\n total += groupCounts[a][b][c][2] * calc;\n total %= MOD;\n }\n }\n }\n System.out.println(total);\n }\n \n public static int[][] getCombinations(int n, int m) {\n if (combos != null)\n return combos;\n combos = new int[n+1][n+1];\n combos[0][0] = 1;\n for (int row = 1; row <= n; ++row) {\n combos[row][0] = 1;\n for (int col = 1; col <= row; ++col) {\n combos[row][col] = combos[row-1][col-1] + combos[row-1][col];\n if (combos[row][col] >= m)\n combos[row][col] -= m;\n }\n }\n return combos;\n }\n \n public static long calculate(int a, int b, int c, int total) {\n getCombinations(total, MOD);\n long ret = 1;\n int goal = total/3;\n //SPECIAL CASE: at least one is zero\n if (a == 0 || b == 0 || c == 0) {\n // the only way this is possible is if total <= 2\n // total == 2: 0,1,1 , 1,0,1, 1,1,0\n // total == 1: 0,0,1 , 0,1,0 1,0,0\n if (total > 2)\n return 0;\n int sum = a + b + c;\n if (sum == total)\n return 1;\n return 0;\n }\n if (total % 3 == 0) {\n // each group must have the same total;\n if (a > goal || b > goal || c > goal)\n return 0;\n ret *= combos[goal-1][goal-a];\n ret *= combos[goal-1][goal-b];\n ret %= MOD;\n ret *= combos[goal-1][goal-c];\n ret %= MOD;\n } else if (total % 3 == 1) {\n long retPartial = 0;\n // try goal,goal,goal+1\n if (a <= goal && b <= goal && c <= goal+1) {\n ret *= combos[goal-1][goal-a];\n ret *= combos[goal-1][goal-b];\n ret %= MOD;\n ret *= combos[goal][goal-c+1];\n retPartial += ret;\n ret = 1;\n }\n // try goal,goal+1,goal\n if (a <= goal && b <= goal+1 && c <= goal) {\n ret *= combos[goal-1][goal-a];\n ret *= combos[goal][goal-b+1];\n ret %= MOD;\n ret *= combos[goal-1][goal-c];\n retPartial += ret;\n ret = 1;\n }\n // try goal+1,goal,goal\n if (a <= goal+1 && b <= goal && c <= goal) {\n ret *= combos[goal][goal-a+1];\n ret *= combos[goal-1][goal-b];\n ret %= MOD;\n ret *= combos[goal-1][goal-c];\n retPartial += ret;\n ret = 1;\n }\n ret = retPartial % MOD;\n } else { // total % 3 == 2\n long retPartial = 0;\n // try goal,goal+1,goal+1\n if (a <= goal && b <= goal && c <= goal+1) {\n ret *= combos[goal-1][goal-a];\n ret *= combos[goal][goal-b+1];\n ret %= MOD;\n ret *= combos[goal][goal-c+1];\n retPartial += ret;\n ret = 1;\n }\n // try goal+1,goal,goal+1\n if (a <= goal && b <= goal+1 && c <= goal) {\n ret *= combos[goal][goal-a+1];\n ret *= combos[goal-1][goal-b];\n ret %= MOD;\n ret *= combos[goal][goal-c+1];\n retPartial += ret;\n ret = 1;\n }\n // try goal+1,goal+1,goal\n if (a <= goal+1 && b <= goal && c <= goal) {\n ret *= combos[goal][goal-a+1];\n ret *= combos[goal][goal-b+1];\n ret %= MOD;\n ret *= combos[goal-1][goal-c];\n retPartial += ret;\n ret = 1;\n }\n ret = retPartial % MOD;\n }\n return ret;\n }\n \n public static int mod(int a, int m) {\n if (a < 0)\n a += m;\n if (a >= m)\n a -= m;\n return a;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "57c527b4e19af8ba796471836da3234a", "src_uid": "64fada10630906e052ff05f2afbf337e", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n \n\npublic class Main {\n\t\n\tpublic static void main(String[] args) throws java.lang.Exception {\n\t\tBufferedReader kek = new BufferedReader(new InputStreamReader(System.in));\n\t\t//Scanner skek = new Scanner(System.in);\n\t\tPrintWriter outkek = new PrintWriter(System.out);\n\n\t\tint N = Integer.parseInt(kek.readLine());\n\t\tchar[] input = kek.readLine().toCharArray();\n\t\tint[] sToI = new int[N + 2];\n\t\tint[][] next = new int [N + 2][3];\n\t\t\n\t\tint limit = (N + 2) / 3;\n\t\tint[][][][] posSum = new int [N + 2][limit][limit][limit];\n\t\tint res = 0, temp, mod = 51123987;\n\t\t\n\t\tfor(int i = 1; i <= N; i++){\n\t\t\tsToI[i] = input[i-1] - 97;\n\t\t}\n\t\t\n\t\t\n\t\tnext[N + 1][0] = next[N + 1][1] = next[N + 1][2] = N + 1;\n\t\t\n\t\tfor(int i = N; i >= 1; i--){\n\t\t\tnext[i][0] = next[i + 1][0];\n\t\t\tnext[i][1] = next[i + 1][1];\n\t\t\tnext[i][2] = next[i + 1][2];\n\t\t\tnext[i][sToI[i]] = i;\n\t\t}\n\t\t\n\t\tposSum[1][0][0][0] = 1;\n\t\t\n\t\tfor(int i = 0; i <= N; i++)\n\t\t\tfor(int j = 0; j <= limit; j++)\n\t\t\t\tfor(int k = 0; k <= limit; k++)\n\t\t\t\t\tfor(int l = 0; l <= limit; l++){\n\t\t\t\t\t\ttemp = posSum[i][j][k][l];\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(j + k + l == N)\n\t\t\t\t\t\t\tif(Math.abs(j - k) <= 1)\n\t\t\t\t\t\t\t\tif(Math.abs(j - l) <= 1)\n\t\t\t\t\t\t\t\t\tif(Math.abs(k - l) <= 1){\n\t\t\t\t\t\t\t\t\t\tres += temp %= mod;\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\tposSum[next[i][0]][j + 1][k][l] += temp %= mod;\n\t\t\t\t\t\tposSum[next[i][1]][j][k + 1][l] += temp %= mod;\n\t\t\t\t\t\tposSum[next[i][2]][j][k][l + 1] += temp %= mod;\n\t\t\t\t\t}\n\t\t\n\t\toutkek.println(res);\n\t\tkek.close();\n\t\toutkek.close();\n\t}\t\n\t\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dc670e23e96fb92ab547b292457efc4d", "src_uid": "64fada10630906e052ff05f2afbf337e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author step_by_step\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public String get(long x) {\n String res = \"\";\n while (x >= 9) {\n res += '9';\n x -= 9;\n }\n if (x > 0)\n res += (char) ('0' + x);\n return res;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long a = in.nextLong();\n if (a < 45) {\n for (int i = 0; i < a; i++)\n out.print(1);\n out.print(' ');\n for (int i = 0; i < a; i++)\n out.print(1);\n out.println();\n return;\n }\n long len = 0;\n for (long x = 2; x <= 17; x++) {\n long cnt = x * 45;\n for (int i = 0; i < x - 1; i++)\n cnt *= 10;\n if (cnt > a) {\n len = x - 1;\n break;\n }\n }\n\n long sum = len * 45, cnt = 10;\n for (int i = 0; i < len - 1; i++) {\n sum *= 10;\n cnt *= 10;\n }\n a -= sum;\n long l = 0, r = cnt - 1;\n l += a % cnt;\n r += a % cnt;\n String add = get(a / cnt);\n if (a / cnt == 0 && l == 0)\n l++;\n out.print(add);\n if (a % cnt > 0 && a / cnt != 0)\n out.print(0);\n out.print(l + \" \");\n out.print(add);\n out.println(r);\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() {\n writer.println();\n }\n\n public void print(char i) {\n writer.print(i);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n public void print(int i) {\n writer.print(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "75d41146f1fff4d59196c2d830bc4ec8", "src_uid": "52b8d97f216ea22693bc16fadcd46dae", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author step_by_step\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public String get(long x) {\n String res = \"\";\n while (x >= 9) {\n res += '9';\n x -= 9;\n }\n if (x > 0)\n res += (char) ('0' + x);\n return res;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long a = in.nextLong();\n if (a < 45) {\n for (int i = 0; i < a; i++)\n out.print(1);\n out.print(' ');\n for (int i = 0; i < a; i++)\n out.print(1);\n out.println();\n return;\n }\n long len = 0;\n for (long x = 2; x <= 17; x++) {\n long cnt = x * 45;\n for (int i = 0; i < x - 1; i++)\n cnt *= 10;\n if (cnt > a) {\n len = x - 1;\n break;\n }\n }\n\n long sum = len * 45, cnt = 10;\n for (int i = 0; i < len - 1; i++) {\n sum *= 10;\n cnt *= 10;\n }\n a -= sum;\n long l = 0, r = cnt - 1;\n l += a % cnt;\n r += a % cnt;\n String add = get(a / cnt);\n if (a / cnt == 0 && l == 0)\n l++;\n out.print(add);\n if (a % cnt > 0 && a / cnt != 0)\n out.print(0);\n out.print(l + \" \");\n out.print(add);\n out.println(r);\n if (add.length() + len + 1 > 199)\n while (true) {\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() {\n writer.println();\n }\n\n public void print(char i) {\n writer.print(i);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n public void print(int i) {\n writer.print(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5296d6b65934a6904611a0dc834f5fa0", "src_uid": "52b8d97f216ea22693bc16fadcd46dae", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author step_by_step\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public String get(long x) {\n String res = \"\";\n while (x >= 9) {\n res += '9';\n x -= 9;\n }\n if (x > 0)\n res += (char) ('0' + x);\n return res;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long a = in.nextLong();\n if (a < 45) {\n for (int i = 0; i < a; i++)\n out.print(1);\n out.print(' ');\n for (int i = 0; i < a; i++)\n out.print(1);\n out.println();\n return;\n }\n long len = 0;\n for (long x = 1; x <= 16; x++) {\n long cnt = x * 45;\n for (int i = 0; i < x - 1; i++)\n cnt *= 10;\n if (cnt <= a)\n len = x;\n }\n long sum = len * 45, cnt = 10;\n for (int i = 0; i < len - 1; i++) {\n sum *= 10;\n cnt *= 10;\n }\n a -= sum;\n long l = 0, r = cnt - 1;\n l += a % cnt;\n r += a % cnt;\n String add = get(a / cnt);\n if (a / cnt == 0 && l == 0)\n l++;\n out.print(add);\n if (a % cnt > 0 && a / cnt != 0)\n out.print(0);\n out.print(l + \" \");\n out.print(add);\n out.println(r);\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() {\n writer.println();\n }\n\n public void print(char i) {\n writer.print(i);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n public void print(int i) {\n writer.print(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b92f4dcf9f1bfc09f740235ad847381", "src_uid": "52b8d97f216ea22693bc16fadcd46dae", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author step_by_step\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n 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 long a = in.nextLong();\n if (a < 45) {\n for (int i = 0; i < a; i++)\n out.print(1);\n out.print(' ');\n for (int i = 0; i < a; i++)\n out.print(1);\n out.println();\n return;\n }\n long len = 0;\n for (long x = 2; x <= 17; x++) {\n long cnt = x * 45;\n for (int i = 0; i < x - 1; i++)\n cnt *= 10;\n if (cnt > a) {\n len = x - 1;\n break;\n }\n }\n long sum = len * 45, cnt = 10;\n for (int i = 0; i < len - 1; i++) {\n sum *= 10;\n cnt *= 10;\n }\n a -= sum;\n long l = 0, r = cnt - 1;\n l += a % cnt;\n r += a % cnt;\n if (a / cnt == 0 && l == 0)\n l++;\n for (int i = 0; i < a / cnt; i++)\n out.print(1);\n if (a / cnt != 0)\n out.print(0);\n out.print(l + \" \");\n for (int i = 0; i < a / cnt; i++)\n out.print(1);\n out.println(r);\n if (a / cnt + len > 199)\n while (true) {\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() {\n writer.println();\n }\n\n public void print(char i) {\n writer.print(i);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n public void print(int i) {\n writer.print(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1f36becd53765de499c4d2878e7afc98", "src_uid": "52b8d97f216ea22693bc16fadcd46dae", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E {\n\n\tstatic class Point {\n\t\tint x, y, id;\n\n\t\tpublic Point(int x, int y, int id) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.id = id;\n\t\t}\n\t}\n\n\tstatic Comparator byAngle = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\n\tvoid submit() {\n\t\tint r = nextInt();\n\t\tint q = nextInt();\n\n\t\tint[][] qs = new int[q][3];\n\t\tint n = 0;\n\n\t\tint ansSz = 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\tansSz++;\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\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\tpx = makeUnique(a, byAngle);\n\t\t\txs = new int[n];\n\n\t\t\tfor (Point p : a) {\n\t\t\t\txs[p.id] = Arrays.binarySearch(px, p, byAngle);\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tPoint[] a = new Point[n];\n\t\t\tint ptr = 0;\n\t\t\tfor (int i = 0; i < q; i++) {\n\t\t\t\tif (qs[i][0] == 1) {\n\t\t\t\t\ta[ptr] = new Point(qs[i][1] + r, qs[i][2], ptr);\n\t\t\t\t\tptr++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpy = makeUnique(a, byAngle.reversed());\n\t\t\tys = new int[n];\n\n\t\t\tfor (Point p : a) {\n\t\t\t\tys[p.id] = Arrays.binarySearch(py, p, byAngle.reversed());\n\t\t\t}\n\t\t}\n\n\t\tint ptr = 0;\n\n\t\tans = new boolean[ansSz];\n\n\t\tansId = new ArrayList<>();\n\n\t\tint qryPtr = 0;\n\n\t\tfor (int i = 0; i < q; i++) {\n\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\taddModify(xs[ptr], ys[ptr], 1);\n\t\t\t\tptr++;\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tint id = qs[i][1];\n\t\t\t\taddModify(xs[id], ys[id], -1);\n\t\t\t} else if (qs[i][0] == 3) {\n\n\t\t\t\tint p1 = qs[i][1];\n\t\t\t\tint p2 = qs[i][2];\n\n\t\t\t\tPoint vx = px[Math.max(xs[p1], xs[p2])];\n\t\t\t\tPoint vy = py[Math.max(ys[p1], ys[p2])];\n\n\t\t\t\tif (isInside(r, vx, vy)) {\n\t\t\t\t} else {\n\t\t\t\t\tansId.add(qryPtr);\n\t\t\t\t\taddQuery(Math.max(xs[p1], xs[p2]), Math.max(ys[p1], ys[p2]));\n\t\t\t\t}\n\n\t\t\t\tqryPtr++;\n\t\t\t}\n\t\t}\n\t\t\n\t\ttreeSize = px.length;\n\t\tgoSmart();\n\t}\n\t\n\tboolean[] ans;\n\tArrayList ansId;\n\t\n\tint treeSize;\n\t\n\tstatic class Node {\n\t\tint l, r;\n\t\tNode left, right;\n\n\t\tArrayList allY = new ArrayList<>();\n\t\tint[] uniqueY;\n\t\tint[] fen;\n\n\t\tpublic Node(int l, int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\n\t\t\tif (r - l > 1) {\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\tleft = new Node(l, m);\n\t\t\t\tright = new Node(m, r);\n\t\t\t}\n\t\t}\n\n\t\tvoid mark(int x, int y) {\n\t\t\tif (r <= x) {\n\t\t\t\tallY.add(y);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (l >= x) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tleft.mark(x, y);\n\t\t\tright.mark(x, y);\n\t\t}\n\n\t\tvoid makeUnique() {\n\t\t\tmakeUniqueHere();\n\t\t\tif (r - l > 1) {\n\t\t\t\tleft.makeUnique();\n\t\t\t\tright.makeUnique();\n\t\t\t}\n\t\t}\n\t\t\n\t\tvoid add(int x, int y, int d) {\n\t\t\tint idx = Arrays.binarySearch(uniqueY, y);\n\t\t\tif (idx < 0) {\n\t\t\t\tidx = -idx - 1;\n\t\t\t}\n\t\t\tif (idx < fen.length) {\n\t\t\t\taddFen(fen, idx, d);\n\t\t\t}\n\t\t\tif (r - l > 1) {\n\t\t\t\t(x < left.r ? left : right).add(x, y, d);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint getSum(int x, int y) {\n\t\t\tif (r <= x) {\n\t\t\t\tint idx = Arrays.binarySearch(uniqueY, y);\n\t\t\t\treturn getFen(fen, idx);\n\t\t\t}\n\t\t\tif (l >= x) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn left.getSum(x, y) + right.getSum(x, y);\n\t\t}\n\n\t\tvoid makeUniqueHere() {\n\t\t\tif (allY.isEmpty()) {\n\t\t\t\tuniqueY = new int[0];\n\t\t\t\tfen = new int[0];\n\t\t\t} else {\n\t\t\t\tCollections.sort(allY);\n\t\t\t\tint sz = 1;\n\t\t\t\tfor (int i = 1; i < allY.size(); i++) {\n\t\t\t\t\tif (!allY.get(i).equals(allY.get(sz - 1))) {\n\t\t\t\t\t\tallY.set(sz, allY.get(i));\n\t\t\t\t\t\tsz++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tuniqueY = new int[sz];\n\t\t\t\tfen = new int[sz];\n\t\t\t\tfor (int i = 0; i < sz; i++) {\n\t\t\t\t\tuniqueY[i] = allY.get(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tallY = null;\n\t\t}\n\t}\n\t\n\tstatic void addFen(int[] fen, int idx, int delta) {\n\t\tfor (int i = idx; i < fen.length; i |= i + 1) {\n\t\t\tfen[i] += delta;\n\t\t}\n\t}\n\t\n\tstatic int getFen(int[] fen, int idx) {\n\t\tint ret = 0;\n\t\tfor (int i = idx; i >= 0; i = (i & (i + 1)) - 1) {\n\t\t\tret += fen[i];\n\t\t}\n\t\treturn ret;\n\t}\n\n\tvoid goSmart() {\n\t\tNode root = new Node(0, treeSize);\n\t\tfor (int i = 0; i < qPtr; i++) {\n\t\t\tint x = qx[i];\n\t\t\tint y = qy[i];\n\t\t\tint d = qd[i];\n\t\t\t\n//\t\t\tSystem.err.println(x + \" \" + y + \" \" + d);\n\t\t\t\n\t\t\tif (d == Integer.MAX_VALUE) {\n\t\t\t\troot.mark(x + 1, y);\n\t\t\t}\n\t\t}\n\n\t\troot.makeUnique();\n\t\t\n\t\tint curAns = 0;\n\t\t\n\t\tfor (int i = 0; i < qPtr; i++) {\n\t\t\tint x = qx[i];\n\t\t\tint y = qy[i];\n\t\t\tint d = qd[i];\n\t\t\tif (d == Integer.MAX_VALUE) {\n//\t\t\t\tSystem.err.println(root.getSum(x, y));\n\t\t\t\tint val = root.getSum(x + 1, y);\n\t\t\t\tif (val < 2) {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t\tans[ansId.get(curAns)] = val == 2;\n\t\t\t\tcurAns++;\n\t\t\t} else {\n\t\t\t\troot.add(x, y, d);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (boolean b : ans) {\n\t\t\tout.println(b ? \"YES\" : \"NO\");\n\t\t}\n\t}\n\n\n\tboolean isInside(int r, Point vl, Point vr) {\n\t\tlong x = (long) vl.y * vr.x + (long) vl.x * vr.y;\n\t\tlong y = (long) vl.y * vr.y;\n\t\tlong d = (long) vl.y * vr.x - (long) vl.x * vr.y;\n\n\t\treturn BigInteger.valueOf(x).pow(2).add(BigInteger.valueOf(y).pow(2))\n\t\t\t\t.compareTo(BigInteger.valueOf(d).pow(2)) < 0;\n\t}\n\n\tstatic final int QUERIES = 500000;\n\n\tint[] qx = new int[QUERIES];\n\tint[] qy = new int[QUERIES];\n\tint[] qd = new int[QUERIES];\n\tint qPtr = 0;\n\n\tvoid addModify(int x, int y, int d) {\n\t\tqx[qPtr] = x;\n\t\tqy[qPtr] = y;\n\t\tqd[qPtr] = d;\n\t\tqPtr++;\n\t}\n\n\tvoid addQuery(int x, int y) {\n\t\tqx[qPtr] = x;\n\t\tqy[qPtr] = y;\n\t\tqd[qPtr] = Integer.MAX_VALUE;\n\t\tqPtr++;\n\t}\n\n\tPoint[] makeUnique(Point[] a, Comparator cmp) {\n\t\ta = a.clone();\n\t\tArrays.sort(a, cmp);\n\n\t\tint sz = 1;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif (cmp.compare(a[i], a[sz - 1]) != 0) {\n\t\t\t\ta[sz++] = a[i];\n\t\t\t}\n\t\t}\n\t\treturn a;\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7e1b44c351fca66c09d55498e5061a45", "src_uid": "775761bcba74d78b833c295290a2195c", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic class Point {\n\t\tint x, y, id;\n\n\t\tpublic Point(int x, int y, int id) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.id = id;\n\t\t}\n\t}\n\n\tstatic Comparator byAngle = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn -Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\n\tstatic Comparator byAngleRev = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\n\tvoid submit() {\n\t\tint r = nextInt();\n\t\tint q = nextInt();\n\n\t\tint[][] qs = new int[q][3];\n\t\tint n = 0;\n\n\t\tfor (int i = 0; i < q; i++) {\n\n\t\t\tqs[i][0] = nextInt();\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\tn++;\n\t\t\t\tqs[i][1] = nextInt();\n\t\t\t\tqs[i][2] = nextInt();\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t} else if (qs[i][0] == 3) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t\tqs[i][2] = nextInt() - 1;\n\t\t\t}\n\t\t}\n\n\t\tint[] xs, ys;\n\n\t\tPoint[] px, py;\n\n\t\tint[] treeXIdx = new int[n];\n\t\tint[] askX;\n\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\t System.err.println(Arrays.toString(xs));\n//\t\t System.err.println(Arrays.toString(ys));\n\n\t\tint ptr = 0;\n\n\t\troot = new Node(0, n);\n\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\troot.set(treeXIdx[ptr], ys[ptr]);\n\t\t\t\tptr++;\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tint what = qs[i][1];\n\t\t\t\troot.set(treeXIdx[what], Integer.MAX_VALUE);\n\t\t\t} else if (qs[i][0] == 3) {\n\t\t\t\tint p1 = qs[i][1];\n\t\t\t\tint p2 = qs[i][2];\n\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\troot.set(treeXIdx[p1], Integer.MAX_VALUE);\n\t\t\t\troot.set(treeXIdx[p2], Integer.MAX_VALUE);\n\n\t\t\t\tout.println(root.get(0, askX[qx]) > qy ? \"YES\" : \"NO\");\n\n\t\t\t\troot.set(treeXIdx[p1], ys[p1]);\n\t\t\t\troot.set(treeXIdx[p2], ys[p2]);\n\t\t\t}\n\t\t}\n\t}\n\n\tTreeSet[] set;\n\tNode root;\n\n\tstatic class Node {\n\t\tint l, r;\n\t\tNode left, right;\n\n\t\tint val;\n\n\t\tpublic Node(int l, int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t\tval = Integer.MAX_VALUE;\n\n\t\t\tif (r - l > 1) {\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\tleft = new Node(l, m);\n\t\t\t\tright = new Node(m, r);\n\t\t\t}\n\t\t}\n\n\t\tvoid set(int x, int y) {\n\t\t\tif (r - l == 1) {\n\t\t\t\tval = y;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t(x < left.r ? left : right).set(x, y);\n\t\t\tval = Math.min(left.val, right.val);\n\t\t}\n\n\t\tint get(int ql, int qr) {\n\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\treturn val;\n\t\t\t}\n\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\treturn Integer.MAX_VALUE;\n\t\t\t}\n\t\t\treturn Math.min(left.get(ql, qr), right.get(ql, qr));\n\t\t}\n\t}\n\n\tboolean isInside(Point vl, Point vr) {\n\t\treturn (long) vl.x * vr.x + (long) vl.y * vr.y < 0;\n\t}\n\n\tPoint[] makeUnique(Point[] a, Comparator cmp, 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\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c36176bec2bad7ba8f7a3aa6b6be4dcb", "src_uid": "775761bcba74d78b833c295290a2195c", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic class Point {\n\t\tint x, y, id;\n\n\t\tpublic Point(int x, int y, int id) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.id = id;\n\t\t}\n\t}\n\n\tstatic Comparator byAngle = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn -Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\n\tstatic Comparator byAngleRev = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\n\tvoid submit() {\n\t\tint r = nextInt();\n\t\tint q = nextInt();\n\n\t\tint[][] qs = new int[q][3];\n\t\tint n = 0;\n\n\t\tfor (int i = 0; i < q; i++) {\n\n\t\t\tqs[i][0] = nextInt();\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\tn++;\n\t\t\t\tqs[i][1] = nextInt();\n\t\t\t\tqs[i][2] = nextInt();\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t} else if (qs[i][0] == 3) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t\tqs[i][2] = nextInt() - 1;\n\t\t\t}\n\t\t}\n\n\t\tint[] xs, ys;\n\n\t\tPoint[] px, py;\n\n\t\tint[] treeXIdx = new int[n];\n\t\tint[] askX;\n\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 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d01ef3a81b7edf554fea2aa733b7b8ea", "src_uid": "775761bcba74d78b833c295290a2195c", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic class Point {\n\t\tint x, y, id;\n\n\t\tpublic Point(int x, int y, int id) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.id = id;\n\t\t}\n\t}\n\n\tstatic Comparator byAngle = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn -Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\t\n\tstatic Comparator byAngleRev = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\n\tvoid submit() {\n\t\tint r = nextInt();\n\t\tint q = nextInt();\n\n\t\tint[][] qs = new int[q][3];\n\t\tint n = 0;\n\n\t\tfor (int i = 0; i < q; i++) {\n\n\t\t\tqs[i][0] = nextInt();\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\tn++;\n\t\t\t\tqs[i][1] = nextInt();\n\t\t\t\tqs[i][2] = nextInt();\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t} else if (qs[i][0] == 3) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t\tqs[i][2] = nextInt() - 1;\n\t\t\t}\n\t\t}\n\n\t\tint[] xs, ys;\n\n\t\tPoint[] px, py;\n\n\t\tint[] treeXIdx = new int[n];\n\t\tint[] askX;\n\n\t\t{\n\t\t\tPoint[] a = new Point[n];\n\t\t\tint ptr = 0;\n\t\t\tfor (int i = 0; i < q; i++) {\n\t\t\t\tif (qs[i][0] == 1) {\n\t\t\t\t\ta[ptr] = new Point(qs[i][1] - r, qs[i][2], ptr);\n\t\t\t\t\tptr++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tArrays.sort(a, byAngle);\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ttreeXIdx[a[i].id] = i;\n\t\t\t}\n\n\t\t\tpx = makeUnique(a, byAngle);\n\t\t\txs = new int[n];\n\n\t\t\tfor (Point p : a) {\n\t\t\t\txs[p.id] = Arrays.binarySearch(px, p, byAngle);\n\t\t\t}\n\n\t\t\taskX = new int[px.length];\n\t\t\taskX[px.length - 1] = n;\n\n\t\t\tint pptr = px.length - 1;\n\t\t\tfor (int i = n - 2; i >= 0; i--) {\n//\t\t\t\tif (byAngle.compare(a[i], a[i + 1]) != 0) {\n\t\t\t\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);\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\t\t\n//\t\tSystem.err.println(Arrays.toString(xs));\n//\t\tSystem.err.println(Arrays.toString(ys));\n\n\t\tint ptr = 0;\n\n\t\troot = new Node(0, n);\n\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\troot.set(treeXIdx[ptr], ys[ptr]);\n\t\t\t\tptr++;\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tint what = qs[i][1];\n\t\t\t\troot.set(treeXIdx[what], Integer.MAX_VALUE);\n\t\t\t} else if (qs[i][0] == 3) {\n\t\t\t\tint p1 = qs[i][1];\n\t\t\t\tint p2 = qs[i][2];\n\t\t\t\t\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\t\t\t\t\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\t\t\t\t\n\t\t\t\troot.set(treeXIdx[p1], Integer.MAX_VALUE);\n\t\t\t\troot.set(treeXIdx[p2], Integer.MAX_VALUE);\n\n\t\t\t\tout.println(root.get(0, askX[qx]) > qy ? \"YES\" : \"NO\");\n\n\t\t\t\troot.set(treeXIdx[p1], ys[p1]);\n\t\t\t\troot.set(treeXIdx[p2], ys[p2]);\n\t\t\t}\n\t\t}\n\t}\n\n\tTreeSet[] set;\n\tNode root;\n\n\tstatic class Node {\n\t\tint l, r;\n\t\tNode left, right;\n\n\t\tint val;\n\n\t\tpublic Node(int l, int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t\tval = Integer.MAX_VALUE;\n\n\t\t\tif (r - l > 1) {\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\tleft = new Node(l, m);\n\t\t\t\tright = new Node(m, r);\n\t\t\t}\n\t\t}\n\n\t\tvoid set(int x, int y) {\n\t\t\tif (r - l == 1) {\n\t\t\t\tval = y;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t(x < left.r ? left : right).set(x, y);\n\t\t\tval = Math.min(left.val, right.val);\n\t\t}\n\n\t\tint get(int ql, int qr) {\n\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\treturn val;\n\t\t\t}\n\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\treturn Integer.MAX_VALUE;\n\t\t\t}\n\t\t\treturn Math.min(left.get(ql, qr), right.get(ql, qr));\n\t\t}\n\t}\n\n\tboolean isInside(Point vl, Point vr) {\n\t\treturn (long) vl.x * vr.x + (long) vl.y * vr.y < 0;\n\t}\n\n\tPoint[] makeUnique(Point[] a, Comparator cmp) {\n\t\ta = a.clone();\n\t\tArrays.sort(a, cmp);\n\n\t\tint sz = 1;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif ((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\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3dd3911d14df53145c4ee7af408253a2", "src_uid": "775761bcba74d78b833c295290a2195c", "difficulty": 3100.0} {"lang": "Java 7", "source_code": "import java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.Scanner;\nimport java.util.Vector;\npublic class Main {\n\tstatic final long mod=1000000007;\n\tpublic static void main(String[] args) {\n\t\tlong a[]=new long[20];\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tlong s=sc.nextLong();\n\t\tfor(int i=0;i>j)&1)==1){\n\t\t\t\t\tflag*=-1;\n\t\t\t\t\tx-=a[j]+1;\n\t\t\t\t}\n\t\t\tif(x<0)\n\t\t\t\tcontinue;\n\t\t\tans=(ans+flag*lucas(x+n-1,n-1))%mod;\n\t\t\tans=(ans+mod)%mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic long lucas(long a,long b){\n\t\tif(b==0)\n\t\t\treturn 1;\n\t\treturn getc(a%mod,b%mod)*lucas(a/mod,b/mod)%mod;\n\t}\n\tstatic long getc(long a,long b){\n\t\tif(a>=1;\n\t\t}\n\t\treturn ans;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "25d3641f024f3d0d93c8e478d923e102", "src_uid": "8b883011eba9d15d284e54c7a85fcf74", "difficulty": 2300.0} {"lang": "Java 8", "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 E_Round_258_Div2 {\n\n\tpublic static long MOD = 1000000007;\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n\t\t// \"output.txt\")));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner in = new Scanner();\n\t\tint n = in.nextInt();\n\t\tlong s = in.nextInt();\n\t\tlong[] data = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdata[i] = in.nextLong();\n\t\t}\n\t\tlong result = 0;\n\t\tfor (int i = 1; i < (1 << n); i++) {\n\t\t\tboolean ok = Integer.bitCount(i) <= s;\n\t\t\tlong total = 0;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (((1 << j) & i) != 0) {\n\t\t\t\t\tok &= data[j] > 0;\n\t\t\t\t\ttotal += data[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tok &= total >= s;\n\t\t\tif (ok) {\n\t\t\t\tlong take = s - Integer.bitCount(i);\n\t\t\t\tlong[] num = new long[Integer.bitCount(i)];\n\t\t\t\tint index = 0;\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif (((1 << j) & i) != 0) {\n\t\t\t\t\t\tnum[index++] = data[j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult += cal(take, 0, num);\n\t\t\t\tresult %= MOD;\n\t\t\t}\n\t\t}\n\t\tout.println(result);\n\t\tout.close();\n\t}\n\n\tpublic static long cal(long need, int total, long[] data) {\n\t\t//System.out.println(\"CALL \" + need + \" \" + total);\n\t\tif (total > data.length) {\n\t\t\treturn 0;\n\t\t}\n\t\tlong result = 0;\n\t\tfor (int i = 0; i < (1 << data.length); i++) {\n\t\t\tif (Integer.bitCount(i) == total) {\n\t\t\t\tlong v = need;\n\t\t\t\tfor (int j = 0; j < data.length; j++) {\n\n\t\t\t\t\tif (((1 << j) & i) != 0) {\n\t\t\t\t\t\tv -= data[j];\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\tif (v >= 0) {\n\t\t\t\t\tresult += numberOfWay(v, data.length);\n\t\t\t\t\tresult %= MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t//System.out.println(result + \" \" + need + \" \" + total + \" \" + data.length);\n\t\tresult -= cal(need, total + 1, data);\n\t\tresult = (result + MOD) % MOD;\n\t\treturn result;\n\t}\n\n\tpublic static long numberOfWay(long v, int n) {\n\t\tif(v == 0){\n\t\t\treturn 1;\n\t\t}\n\t\tlong x = 1;\n\t\tfor (long i = v + n - 1; i > v; i--) {\n\t\t\tx *= (i % MOD);\n\t\t\tx %= MOD;\n\t\t}\n\t\tlong y = 1;\n\t\tfor (long i = 2; i < n; i++) {\n\t\t\ty *= i;\n\t\t\ty %= MOD;\n\t\t}\n\t\tBigInteger result = BigInteger\n\t\t\t\t.valueOf(x)\n\t\t\t\t.multiply(\n\t\t\t\t\t\tBigInteger.valueOf(y).modInverse(\n\t\t\t\t\t\t\t\tBigInteger.valueOf(MOD)))\n\t\t\t\t.mod(BigInteger.valueOf(MOD));\n\t\treturn result.longValue();\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable {\n\n\t\tint x, y;\n\n\t\tpublic Point(int start, int end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 5;\n\t\t\thash = 47 * hash + this.x;\n\t\t\thash = 47 * hash + this.y;\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (getClass() != obj.getClass()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfinal Point other = (Point) obj;\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.y != other.y) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "781b8a15780be4001b49fdfb4a2cc04e", "src_uid": "8b883011eba9d15d284e54c7a85fcf74", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\nimport static java.lang.Math.min;\n\npublic class Solution {\n\n private static final long MOD = 1000000007;\n private static long FACT[] = new long[25];\n\n private static long modPow(long a, long x, long m) {\n long res = 1;\n while(x > 0) {\n if(x % 2 !=0) {\n res = (res*a) % m;\n }\n a = (a*a)%m;\n x /= 2;\n }\n return res % m;\n }\n\n private static long modInverse(long a, long p) {\n // p doit \u00eatre premier\n return modPow(a, p - 2, p);\n }\n\n private static long nCr(long n, int r) {\n if(n < r) return 0;\n r = (int) min(r, n-r);\n long ret = 1;\n for(long x = n; x >= n - r + 1; x--){\n ret = (ret*(x%MOD))%MOD;\n }\n ret = (ret*modInverse(FACT[r], MOD))%MOD;\n return ret;\n }\n\n public static void main(String[] args) {\n FACT[0] = 1;\n for(int i = 1; i < 25; i++) {\n FACT[i] = (FACT[i - 1]*i)%MOD;\n }\n\n Scanner in = new Scanner(System.in);\n int n;\n long s, N;\n n = in.nextInt();\n s = in.nextLong();\n long f[] = new long[n];\n for(int i = 0; i < n; i++) {\n f[i] = in.nextInt();\n }\n\n N = 1 << n;\n\n long res = 0;\n for(int i = 0; i < N; i++) {\n int count = 0, p = 0;\n for(int j = 0; j < n; j++) {\n if((i & (1 << j) )> 0) {\n count += f[j] + 1;\n p++;\n }\n }\n if(count > s) continue;\n long C = nCr(s + n - 1 - count, n - 1);\n if(p % 2 == 1) C = -C;\n res += C;\n }\n\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d6a6b95c253397f0cecd99e81ddd6193", "src_uid": "8b883011eba9d15d284e54c7a85fcf74", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.Scanner;\nimport java.util.Vector;\npublic class Main {\n\tstatic final long mod=1000000007;\n\tpublic static void main(String[] args) {\n\t\tlong a[]=new long[21];\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tlong s=sc.nextLong();\n\t\tfor(int i=0;i>j)&1)==1){\n\t\t\t\t\tflag*=-1;\n\t\t\t\t\tx-=a[j]+1;\n\t\t\t\t}\n\t\t\tif(x<0)\n\t\t\t\tcontinue;\n\t\t\tans=(ans+flag*lucas(x+n-1,n-1))%mod;\n\t\t\tans=(ans+mod)%mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic long lucas(long a,long b){\n\t\tif(b==0)\n\t\t\treturn 1;\n\t\treturn getc(a%mod,b%mod)*lucas(a/mod,b/mod)%mod;\n\t}\n\tstatic long getc(long a,long b){\n\t\tif(a>=1;\n\t\t}\n\t\treturn ans;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9b8e8beae564ff6a9df644fcbce3877", "src_uid": "8b883011eba9d15d284e54c7a85fcf74", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class CF {\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 int n = in.nextInt();\n String ch = Integer.toHexString(n).toUpperCase();\n int s = 0;\n for (int i = 0; i < ch.length(); i++) {\n switch (ch.charAt(i)) {\n case '0':\n case '4':\n case '6':\n case '9':\n case 'A':\n case 'D':\n s++;\n break;\n case '8':\n case 'B':\n s += 2;\n break;\n default:\n break;\n }\n }\n out.println(s);\n out.close();\n }\n\n public static int maxTab(int[] tab) {\n int max = 0;\n for (int i : tab) {\n max = max(i, max);\n }\n return max;\n }\n\n static class FastScanner {\n\n private BufferedReader in;\n private String[] line;\n private int index;\n private int size;\n\n public FastScanner(InputStream in) throws IOException {\n this.in = new BufferedReader(new InputStreamReader(in));\n init();\n }\n\n public FastScanner(String file) throws FileNotFoundException {\n this.in = new BufferedReader(new FileReader(file));\n }\n\n private void init() throws IOException {\n line = in.readLine().split(\" \");\n index = 0;\n size = line.length;\n }\n\n public int nextInt() throws IOException {\n if (index == size) {\n init();\n }\n return Integer.parseInt(line[index++]);\n }\n\n public long nextLong() throws IOException {\n if (index == size) {\n init();\n }\n return Long.parseLong(line[index++]);\n }\n\n public float nextFloat() throws IOException {\n if (index == size) {\n init();\n }\n return Float.parseFloat(line[index++]);\n }\n\n public double nextDouble() throws IOException {\n if (index == size) {\n init();\n }\n return Double.parseDouble(line[index++]);\n }\n\n public String next() throws IOException {\n if (index == size) {\n init();\n }\n return line[index++];\n }\n\n public String nextLine() throws IOException {\n if (index == size) {\n init();\n }\n StringBuilder sb = new StringBuilder();\n for (int i = index; i < size; i++) {\n sb.append(line[i]).append(\" \");\n }\n return sb.toString();\n }\n\n private int[] nextIntArray(int n) throws IOException {\n int[] tab = new int[n];\n for (int i = 0; i < tab.length; i++) {\n tab[i] = nextInt();\n }\n return tab;\n }\n\n private double[] nextDoubleArray(int n) throws IOException {\n double[] tab = new double[n];\n for (int i = 0; i < tab.length; i++) {\n tab[i] = nextDouble();\n }\n return tab;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64863fc4143e560a6a9618996cc28fc6", "src_uid": "16a784cb9953bc91cb2e7767b04b76f2", "difficulty": 2000.0} {"lang": "Java 8", "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\n static void solve() {\n int n = sc.nextInt();\n String s = Integer.toString(n, 16).toUpperCase();\n int ans=0;\n for (int i=0;i 0;\n }\n\n private void loadBuffer() {\n pos = 0;\n try {\n for (int i; (i = reader.read()) != -1; ) {\n char c = (char) i;\n if (c != ' ' && c != '\\n' && c != '\\t' && c != '\\r' && c != '\\f') {\n if (pos == buffer.length) buffer = Arrays.copyOf(buffer, 2 * pos);\n buffer[pos++] = c;\n } else if (pos != 0) break;\n }\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String current() {\n return String.copyValueOf(buffer, 0, pos);\n }\n\n\n public String next() {\n loadBuffer();\n return current();\n }\n\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f1504277187b2a761941dfb5337fdade", "src_uid": "16a784cb9953bc91cb2e7767b04b76f2", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class ass {\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\tSystem.out.println(\"2\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6cde0a0e064900cbac26a61bced3f584", "src_uid": "16a784cb9953bc91cb2e7767b04b76f2", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "package free1;\nimport java.util.*;\npublic class NumbersJoke {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(System.in) ;\n\t\tint n = in.nextInt() ; \n\t\tString hex =\tInteger.toHexString(n) ; \n\t\thex = hex.toUpperCase() ; \n\t\tchar c[] = hex.toCharArray();\n\t\tint cnt = 0 ; \n\t\t\n\t\tfor(int i = 0 ; i 0)\n tmp.append(number.substring(number.length() - k + zeros + 1));\n\n System.out.println(tmp.toString());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ee6a21670ee56414ef797eddbeeb0610", "src_uid": "0515ac888937a4dda30cad5e2383164f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "// Working program with FastReader \nimport java.io.BufferedReader; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.util.*; \n\npublic class Main { \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} \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\n\t\tint nextInt() { \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() { \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() { \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() { \n\t\t\tString str = \"\"; \n\t\t\ttry{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} catch (IOException e) { \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t} \n\n\tpublic static void main(String[] args) throws IOException { \n\t\tFastReader in=new FastReader(); \n\t\tBufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tif(k > 0){\n\t\t\tchar[] s = in.nextLine().toCharArray();\n\n\t\t\tif(s[0] != '1') {\n\t\t\t\ts[0] = '1';\n\t\t\t\tk--;\n\t\t\t}\n\t\t\tif(k == 0 ){\n\t\t\t\ts[0]= '0';\n\t\t\t}\n\t\t\tif(n == 1){\n\t\t\t s[0]= '0';\n\t\t\t k--;\n\t\t\t}\n\n\t\t\tfor(int i = 1; i<=k && i 0){\n\t\t\tchar[] s = in.nextLine().toCharArray();\n\n\t\t\tif(s[0] != '1') {\n\t\t\t\ts[0] = '1';\n\t\t\t\tk--;\n\t\t\t}\n\t\t\tif(k == 0)\n\t\t\t\ts[0]= '0';\n\t\t\tfor(int i = 1; i<=k; i++){\n\t\t\t\ts[i]= '0';\n\t\t\t}\n\n\t\t\tlog.write(new String(s));\n\t\t}else{\n\t\t\tlog.write(in.nextLine());\n\t\t}\n\n\n\n\t\tlog.flush();\n\t\tlog.close();\n\n\n\t} \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "93c513d6b668578f94ab86980241dc1f", "src_uid": "0515ac888937a4dda30cad5e2383164f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n \npublic class myFile\n{\n\tpublic static void main(String args[])\n\t{\n\t Scanner sc = new Scanner(System.in);\n\t int i,n,k;\n\t while(sc.hasNextInt())\n\t {\n\t\t n = sc.nextInt();\n\t\t k = sc.nextInt();\n\t\t sc.nextLine();\n\t\t String str = sc.nextLine();\n\t\t if(n==1 && k==1)\n\t\t {\n\t\t\t System.out.println(\"0\");\n\t\t\t continue;\n\t\t }\n\t\t String ans=\"\";\n\t\t if(str.charAt(0)!='1')\n\t\t\t k--;\n\t\t ans+='1';\n\t\t for(i=1;k>0 && i b || (n-bad) > w) continue;\n long tmp = calc[b][bad];\n tmp = (tmp * calc[w][n-bad])%mod;\n tmp = (tmp * (n-bad-1)) % mod;\n ans = (ans+tmp)%mod;\n }\n out.println(ans);\n out.close();\n }\n static class FastIO extends PrintWriter {\n BufferedReader br;\n StringTokenizer st;\n\n public FastIO() {\n this(System.in, System.out);\n }\n\n public FastIO(InputStream in, OutputStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n br = new BufferedReader(new InputStreamReader(in));\n scanLine();\n }\n\n public void scanLine() {\n try {\n st = new StringTokenizer(br.readLine().trim());\n } catch (Exception e) {\n throw new RuntimeException(e.getMessage());\n }\n }\n\n public int numTokens() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return numTokens();\n }\n return st.countTokens();\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return next();\n }\n return st.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c18566bb570e1bf5bb4e5de21513999", "src_uid": "63e93a161bbff623323e66c98d5e20ac", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CFstupid {\n FastScanner in;\n PrintWriter out;\n\n long mod = (long) 1e9 + 9;\n \n void solve() {\n int n = in.nextInt();\n int w = in.nextInt();\n int b = in.nextInt();\n long ans = 0;\n int MAX = 8005;\n long[][] c = new long[MAX][MAX];\n c[0][0] = 1;\n for (int i = 1; i < MAX; i++) {\n c[i][0] = 1;\n for (int j = 1; j < MAX / 2; j++) {\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]);\n if (c[i][j] >= mod)\n c[i][j] -= mod;\n }\n \n }\n for (int fr = 1; fr < n; fr++) {\n for (int to = fr; to < n - 1; to++) {\n if (to - fr + 1 <= b) {\n int ost = n - (to - fr + 1);\n if (ost <= w) {\n long add = 1;\n add = (add * c[w - 1][ost - 1]) % mod;\n add = (add * c[b - 1][to - fr]) % mod;\n ans += add;\n ans %= mod;\n }\n }\n }\n }\n for (int i = 1; i <= w; i++)\n ans = (ans * i) % mod;\n for (int i = 1; i <= b; i++)\n ans = (ans * i) % mod;\n out.println(ans);\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"test.in\"));\n out = new PrintWriter(new File(\"test.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n\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 CFstupid().runIO();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48f1d2f17d5e8afc85c1c965cd65badc", "src_uid": "63e93a161bbff623323e66c98d5e20ac", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class WhiteBlackAndWhiteAgain {\n\tstatic long MOD = 1000000009;\n\tstatic long[] fac;\n\tpublic static void main(String[] args){\n\t\tFastScanner sc = new FastScanner();\n\t\tint n = sc.nextInt();\n\t\tint w = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\t\n\t\tfac = new long[n+1];\n\t\tfac[0] = 1;\n\t\tfor(int i=1;i w || badDays >b){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong badDaySplit = comb(b-1, badDays-1);\n\t\t\tlong goodDaySplit = (comb(w-1, goodDays-1) * (goodDays-1))%MOD;\n\t\t\ttotal = (total + goodDaySplit*badDaySplit) %MOD;\n\t\t}\n\t\ttotal = (total*fac[w])%MOD;\n\t\ttotal = (total*fac[b])%MOD;\n\t\tSystem.out.println(total);\n\t}\n\t\n\tstatic long comb(int n, int k){\n\t\tBigInteger denom = BigInteger.valueOf((fac[n-k] *fac[k])%MOD);\n\t\tlong inv = denom.modInverse(BigInteger.valueOf(MOD)).longValue();\n\t\treturn (fac[n] * inv) % MOD;\n\t}\n\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\t// TODO Auto-generated catch block\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\tString nextToken() {\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\t// TODO Auto-generated catch block\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(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\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1600524e984521f0a6424090e8e30ac3", "src_uid": "63e93a161bbff623323e66c98d5e20ac", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public final Rational ONE = new Rational(1, 1);\n public final Rational ZERO = new Rational(0, 1);\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int k = in.readInt();\n int pa = in.readInt();\n int pb = in.readInt();\n Rational probA = new Rational(pa, pa + pb);\n Rational probB = new Rational(pb, pa + pb);\n Rational[][] probAtState = new Rational[k + 1][2 * k]; // numA, ABPairAlready\n for (int row = 0; row < probAtState.length; row++) {\n for (int col = 0; col < probAtState[0].length; col++) {\n probAtState[row][col] = ZERO;\n }\n }\n probAtState[1][0] = ONE;\n for (int numA = 1; numA < k; numA++) {\n for (int ABPairAlready = 0; ABPairAlready < k; ABPairAlready++) {\n { // with chance pa / (pa + pb) we get an A here\n probAtState[numA + 1][ABPairAlready] = probAtState[numA][ABPairAlready].multiply(probA);\n }\n { // with chance pb / (pa + pb) we get a B here\n probAtState[numA][ABPairAlready + numA] = probAtState[numA][ABPairAlready + numA].add(probAtState[numA][ABPairAlready].multiply(probB));\n }\n }\n }\n Rational res = ZERO;\n // Here we count num ABPairs where we have at least k AB pairs already\n for (int numA = 1; numA < probAtState.length; numA++) {\n for (int ABPairAlready = k; ABPairAlready < probAtState[0].length; ABPairAlready++) {\n res = res.add(probAtState[numA][ABPairAlready].multiply(ABPairAlready));\n }\n }\n Rational expectMoreA = (probB.reverse()).subtract(ONE);\n for (int ABPairAlready = 0; ABPairAlready < k; ABPairAlready++) {\n // Now here we do not quite have the number of AB Pairs we need\n // but we have plenty of A already\n Rational nowA = expectMoreA.add(ABPairAlready).add(k);\n res = res.add(nowA.multiply(probAtState[k][ABPairAlready]));\n }\n out.printLine((long) res.numerator * IntegerUtils.reverse(res.denominator, MiscUtils.MOD7) % MiscUtils.MOD7);\n }\n\n public class Rational {\n long numerator;\n long denominator;\n\n public Rational(long numerator, long denominator) {\n if (denominator == 0) {\n throw new IllegalArgumentException();\n }\n long gcd = IntegerUtils.gcd(Math.abs(numerator), Math.abs(denominator));\n if (denominator > 0) {\n this.numerator = numerator / gcd;\n this.denominator = denominator / gcd;\n } else {\n this.numerator = -numerator / gcd;\n this.denominator = -denominator / gcd;\n }\n this.numerator %= MiscUtils.MOD7;\n this.denominator %= MiscUtils.MOD7;\n }\n\n public Rational add(Rational other) {\n return new Rational(numerator * other.denominator + denominator * other.numerator,\n denominator * other.denominator);\n }\n\n public Rational add(long other) {\n return new Rational(numerator + denominator * other,\n denominator);\n }\n\n public Rational reverse() {\n if (numerator == 0) {\n throw new ArithmeticException();\n }\n return new Rational(denominator, numerator);\n }\n\n public Rational multiply(long number) {\n return new Rational(numerator * number, denominator);\n }\n\n public Rational subtract(Rational other) {\n return new Rational(numerator * other.denominator - denominator * other.numerator,\n denominator * other.denominator);\n }\n\n public Rational multiply(Rational other) {\n return new Rational(numerator * other.numerator, other.denominator * denominator);\n }\n }\n }\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n }\n static class IntegerUtils {\n public static long gcd(long a, long b) {\n a = Math.abs(a);\n b = Math.abs(b);\n while (b != 0) {\n long temp = a % b;\n a = b;\n b = temp;\n }\n return a;\n }\n\n public static long power(long base, long exponent, long mod) {\n if (base >= mod) {\n base %= mod;\n }\n if (exponent == 0) {\n return 1 % mod;\n }\n long result = power(base, exponent >> 1, mod);\n result = result * result % mod;\n if ((exponent & 1) != 0) {\n result = result * base % mod;\n }\n return result;\n }\n\n public static long reverse(long number, long module) {\n return power(number, module - 2, module);\n }\n }\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n static class MiscUtils {\n public static final int MOD7 = (int) (1e9 + 7);\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd2404a14eb1fe0a43d19ea71ce80fd9", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "//package codeforces.GoodBye17;\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class D\n{\n\tstatic int mod = (int)1e9+7;\n\tstatic Pair[][] memo;\n\tstatic int a,b,k, a_b;\n\tstatic Pair sum1, pb, pa, sum2;\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\tk = sc.nextInt();\n\t\ta = sc.nextInt();\n\t\tb = sc.nextInt();\n\t\ta_b = sum(a, b);\n\t\tmemo = new Pair[a+2][k+2];\n\t\t\n\t\tPair one = new Pair(1, 1);\n\t\tpa = new Pair(a, a_b);\n\t\tpb = new Pair(b, a_b);\n\t\tsum1 = new Pair(one, one.subtract(pa));\n\t\t\n\t\tPair one_pa = one.subtract(pa);\n\t\tPair pp1 = new Pair(pa, one_pa);\n\t\tPair pp2 = new Pair(one, one_pa);\n\t\tsum2 = pp1.multiply(pp2);\n\t\t\n\t\tPair p = simplify(solve(1, 0));\n\t\tint rp = p.x;\n\t\tint rq = p.y;\n\t\tSystem.out.println(mult(rp, inv(rq, mod)));\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tprivate static Pair simplify(Pair P)\n\t{\n\t\tint gcd = gcd(P.x, P.y);\n\t\tP.x = mult(P.x, inv(gcd, mod));\n\t\tP.y = mult(P.y, inv(gcd, mod));\n\t\treturn P;\n\t}\n\t\n\tstatic int gcd(int a, int b)\n\t{\n\t\tif(b == 0)\n\t\t\treturn a;\n\t\treturn gcd(b, a%b);\n\t}\n\t\n\tstatic int sub(int a, int b)\n\t{\n\t\tint ans = a-b;\n\t\tans %= mod;\n\t\tif(ans < 0)\n\t\t\tans += mod;\n\t\treturn ans;\n\t}\n\n\tprivate static Pair solve(int cntA, int tot)\n\t{\n\t\tif(tot >= k)\n\t\t\treturn new Pair(tot, 1);\n\t\tif(cntA+tot >= k) // check > or >=\n\t\t{\n\t\t\treturn pb.multiply(new Pair(tot+cntA, 1).multiply(sum1).add(sum2));\n\t\t}\n\t\t\n\t\tif(memo[cntA][tot] != null)\n\t\t\treturn memo[cntA][tot];\n\t\t\n\t\t// a\n\t\tint num1 = mult(a, solve(cntA+1, tot).x);\n\t\tint den1 = mult(a_b, solve(cntA+1, tot).y);\n\t\tPair a1 = new Pair(num1, den1);\n\t\t// b\n\t\tint num2 = mult(b, solve(cntA, tot+cntA).x);\n\t\tint den2 = mult(a_b, solve(cntA, tot+cntA).y);\n\t\tPair a2 = new Pair(num2, den2);\n\t\t\n\t\t\n\t\treturn memo[cntA][tot] = a1.add(a2);\n\t}\n\t\n\tstatic int mult(int a, int b)\n\t{\n\t\treturn (int)(1l*a*b % mod);\n\t}\n\t\n\tstatic int sum(int a, int b)\n\t{\n\t\treturn (a+b) % mod;\n\t}\n\n\tstatic class Pair\n\t{\n\t\tint x, y;\n\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn x +\"/\" + y;\n\t\t}\n\t\tpublic Pair(int x, int y)\n\t\t{\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t\t\n\t\tpublic Pair(Pair p1, Pair p2)\n\t\t{\n\t\t\tthis.x = mult(p1.x, inv(p2.x, mod));\n\t\t\tthis.y = mult(p1.y, inv(p2.y, mod));\n\t\t}\n\t\t\n\t\tPair multiply(Pair p)\n\t\t{\n\t\t\treturn new Pair(mult(x, p.x), mult(y, p.y));\n\t\t}\n\t\t\n\t\tPair add(Pair p)\n\t\t{\n\t\t\tint xy = mult(p.y, y);\n\t\t\treturn new Pair(sum(mult(mult(xy, x), inv(y, mod)), mult(mult(p.x, xy), inv(p.y, mod))), mult(y, p.y));\n\t\t}\n\t\t\n\t\tPair subtract(Pair p)\n\t\t{\n\t\t\tPair tmp = new Pair(-p.x, p.y);\n\t\t\ttmp.x %= mod;\n\t\t\tif(tmp.x < 0)\n\t\t\t\ttmp.x += mod;\n\t\t\treturn add(tmp);\n\t\t}\n\t}\n\t\n\tstatic int inv(long x , long mod){\n\t\tlong r, y;\n\t\tfor(r = 1 , y = mod - 2 ; y != 0 ;x = x * x % mod, y>>=1)\n\t\tif ((y & 1) == 1)\n\t\tr = r * x % mod;\n\t\treturn (int)r;\n\t\t}\n\t\n\tstatic class Scanner\n\t{\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(String s) throws FileNotFoundException\n\t\t{\n\t\t\tbr = new BufferedReader(new FileReader(new File((s))));\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 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} else\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException\n\t\t{\n\t\t\treturn br.ready();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "92e9783eada97adb237d575c1863f8e6", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "//package codeforces.GoodBye17;\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class D\n{\n\tstatic int mod = (int)1e9+7;\n\tstatic int[][] memo;\n\tstatic int a,b,k, a_b;\n\tstatic int sum1, pb, pa, sum2;\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\tk = sc.nextInt();\n\t\ta = sc.nextInt();\n\t\tb = sc.nextInt();\n\t\ta_b = sum(a, b);\n\t\tmemo = new int[k+2][k+2];\n\t\tfor (int i = 0; i < a+2; i++)\n\t\t\tArrays.fill(memo[i], -1);\n\t\tpa = mult(a, inv(a_b, mod));\n\t\tpb = mult(b, inv(a_b, mod));\n\t\tsum1 = mult(a+b, inv(b, mod));\n\t\tsum2 = mult(mult(a, a+b), inv(mult(b, b), mod));\n\t\tSystem.out.println(solve(1, 0));\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic int sub(int a, int b)\n\t{\n\t\tint ans = a-b;\n\t\tans %= mod;\n\t\tif(ans < 0)\n\t\t\tans += mod;\n\t\treturn ans;\n\t}\n\n\tprivate static int solve(int cntA, int tot)\n\t{\n\t\tif(tot >= k)\n\t\t\treturn tot;\n\t\tif(cntA >= k)\n\t\t{\n\t\t\treturn memo[cntA][tot] = mult(pb, sum(mult(sum(tot, cntA), sum1), sum2));\n\t\t\t// pb * ((tot+cntA)(sum1) + sum2)\n\t\t}\n\t\t\n\t\tif(memo[cntA][tot] != -1)\n\t\t\treturn memo[cntA][tot];\n\t\t\n\t\t// a\n\t\tint ans = mult(pa, solve(cntA+1, tot));\n\t\t// b\n\t\tans = sum(ans, mult(pb, solve(cntA, tot+cntA)));\n\t\t\n\t\t\n\t\treturn memo[cntA][tot] = ans;\n\t}\n\t\n\tstatic int mult(int a, int b)\n\t{\n\t\treturn (int)(1l*a*b % mod);\n\t}\n\t\n\tstatic int sum(int a, int b)\n\t{\n\t\treturn (a+b) % mod;\n\t}\n\n\tstatic int inv(long x , long mod){\n\t\tlong r, y;\n\t\tfor(r = 1 , y = mod - 2 ; y != 0 ;x = x * x % mod, y>>=1)\n\t\tif ((y & 1) == 1)\n\t\tr = r * x % mod;\n\t\treturn (int)r;\n\t\t}\n\t\n\tstatic class Scanner\n\t{\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(String s) throws FileNotFoundException\n\t\t{\n\t\t\tbr = new BufferedReader(new FileReader(new File((s))));\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 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} else\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException\n\t\t{\n\t\t\treturn br.ready();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f7782fa65a46249b76adf6922c3074ca", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\npackage d;\n\nimport java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author kamranmaharov\n */\npublic class Main {\n private static int k, pa, pb;\n private static int REM = 1000000007;\n \n private static class Quotient {\n private final int P, Q;\n \n Quotient(int P, int Q) {\n this.P = P;\n this.Q = inverse(Q);\n }\n \n public Quotient add(Quotient other) {\n return new Quotient( (int)(((long)P*Q + (long)other.P*other.Q) % REM), 1);\n }\n \n public Quotient multiply(Quotient other) {\n return new Quotient((int)((long)P*Q%REM*other.P%REM*other.Q%REM), 1);\n }\n \n @Override\n public String toString() {\n return String.valueOf((long)P*Q % REM);\n }\n \n private static int inverse(int Q) {\n return pow(Q, REM-2);\n }\n \n private static int pow(int a, int b) {\n if (b==0) {return 1;}\n else if (b%2==1) {return (int)((long)pow(a,b-1) * a % REM);}\n else {\n int mid = pow(a,b/2);\n return (int)((long)mid*mid%REM);\n }\n }\n \n //private static int gcd(int a, int b) {\n // return (b==0?a:gcd(b, a%b));\n //}\n }\n \n private static Quotient f(int c1, int c2) {\n if (c1+c2>=k) {\n return new Quotient(c1+c2, 1).add(new Quotient(pa, pb));\n } else {\n return f(c1, c2+1).multiply(new Quotient(pa, pa+pb)).add(\n f(c1+c2, c2).multiply(new Quotient(pb, pa+pb)));\n }\n }\n \n public static void main(String[] args) throws Exception {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n \n String[] line = in.readLine().split(\" \");\n k = Integer.parseInt(line[0]);\n pa = Integer.parseInt(line[1]);\n pb = Integer.parseInt(line[2]);\n \n out.write(f(0, 1).toString() + \"\\n\");\n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8eade376ee38c178d858586a3c2e3301", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class D {\n static final boolean DEBUG = false;\n\n static final int MOD = 1000000009;\n\n static int h = 0;\n\n static class State {\n int[][][] T;\n\n int[][][] F;\n\n State() {\n T = new int[h + 1][h + 1][h + 1];\n F = new int[h + 1][h + 1][h + 1];\n }\n\n void addStateT(int u, int v, int w, int number) {\n T[u][v][w] += number;\n T[u][v][w] %= MOD;\n }\n\n void addStateF(int u, int v, int w, int number) {\n F[u][v][w] += number;\n F[u][v][w] %= MOD;\n }\n\n int getStateT(int u, int v, int w) {\n return T[u][v][w];\n }\n\n int getStateF(int u, int v, int w) {\n return F[u][v][w];\n }\n\n int getTotal() {\n int total = 0;\n for (int u = 0; u <= h; u++) {\n for (int v = 0; v <= h; v++) {\n for (int w = 0; w <= h; w++) {\n if (u != h || v != h || w != h) {\n total += getStateF(u, v, w);\n total %= MOD;\n }\n total += getStateT(u, v, w);\n total %= MOD;\n }\n }\n }\n return total;\n }\n }\n\n static class Design {\n State curState;\n\n State newState;\n\n Design() {\n curState = new State();\n curState.addStateT(1, 1, 1, 4);\n }\n\n void createNewState() {\n newState = new State();\n }\n\n void commitNewState() {\n curState = newState;\n }\n\n void updateState(int u, int v, int w) {\n int nu = (u == h) ? h : u + 1;\n int nv = (v == h) ? h : v + 1;\n int nw = (w == h) ? h : w + 1;\n int t = curState.getStateT(u, v, w);\n int f = curState.getStateF(u, v, w);\n newState.addStateT(nu, nv, nw, t);\n newState.addStateF(nu, nv, nw, f);\n if (u == h) {\n newState.addStateF(1, nv, nw, t);\n newState.addStateF(nv, nw, h, f);\n } else {\n newState.addStateT(1, nv, nw, t);\n newState.addStateT(nv, nw, h, f);\n }\n if (v == h) {\n newState.addStateF(1, nu, nw, t);\n newState.addStateF(nu, nw, h, f);\n } else {\n newState.addStateT(1, nu, nw, t);\n newState.addStateT(nu, nw, h, f);\n }\n if (w == h) {\n newState.addStateF(1, nu, nv, t);\n newState.addStateF(nu, nv, h, f);\n } else {\n newState.addStateT(1, nu, nv, t);\n newState.addStateT(nu, nv, h, f);\n }\n }\n\n void nextState() {\n createNewState();\n for (int u = 0; u <= h; u++) {\n for (int v = 0; v <= h; v++) {\n for (int w = 0; w <= h; w++) {\n updateState(u, v, w);\n }\n }\n }\n commitNewState();\n }\n\n int getTotal() {\n int total = 0;\n for (int i = 0; i < 4; i++) {\n total = (total + curState.getTotal()) % D.MOD;\n }\n return total;\n }\n }\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n h = s.nextInt();\n if (h == 1) {\n System.out.println(4);\n return;\n }\n\n long start = System.currentTimeMillis();\n\n Design design = new Design();\n for (int i = 1; i < n; i++) {\n design.nextState();\n }\n\n System.out.println(design.getTotal());\n\n if (DEBUG) {\n System.out.println(System.currentTimeMillis() - start);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "88902fd4d3995a842dade0e3af63703f", "src_uid": "9fe9658db35076c0bddc8b7ddce11013", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class D{\n\tstatic final int MOD = 1000000009;\n\tstatic int increment(int last, int h){\n\t\tif (last == 0){\n\t\t\treturn 0;\n\t\t}\n\t\treturn (last + 1)%h;\n\t}\n\tstatic int boolean2int(boolean in){\n\t\treturn in ? 1 : 0;\n\t}\n\tpublic static void main(String [] args){\n\t\ttry (Scanner s = new Scanner(System.in)){\n\t\t\tfinal int n = s.nextInt();\n\t\t\tfinal int h = s.nextInt();\n\t\t\tfinal long [][][][][] dp = new long[2][2][32][32][32];\n\t\t\tdp[1][1][0][0][0] = 4;\n\t\t\tint p = 1;\n\t\t\tfor (int i = 1; i <= n - 1; ++i){\n\t\t\t\tfor (int alive = 0; alive <= 1; ++alive){\n\t\t\t\t\tfor (int last1 = 0; last1 < h; ++last1){\n\t\t\t\t\t\tfor (int last2 = 0; last2 < h; ++last2){\n\t\t\t\t\t\t\tfor (int last3 = 0; last3 < h; ++last3){\n\t\t\t\t\t\t\t\tfinal int a = increment(last1, h);\n\t\t\t\t\t\t\t\tfinal int b = increment(last2, h);\n\t\t\t\t\t\t\t\tfinal int c = increment(last3, h);\n\t\t\t\t\t\t\t\tfinal int alive1 = boolean2int(i < h || last1 > 0);\n\t\t\t\t\t\t\t\tfinal int alive2 = boolean2int(i < h || last2 > 0);\n\t\t\t\t\t\t\t\tfinal int alive3 = boolean2int(i < h || last3 > 0);\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive][a][b][c] += dp[p][alive][last1][last2][last3];\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive][a][b][c] %= MOD;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive1][alive][b][c] += dp[p][alive][last1][last2][last3];\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive1][alive][b][c] %= MOD;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive2][a][alive][c] += dp[p][alive][last1][last2][last3];\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive2][a][alive][c] %= MOD;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive3][a][b][alive] += dp[p][alive][last1][last2][last3];\n\t\t\t\t\t\t\t\tdp[(p + 1)%2][alive3][a][b][alive] %= 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\tfor (int alive = 0; alive <= 1; ++alive){\n\t\t\t\t\tfor (int last1 = 0; last1 < h; ++last1){\n\t\t\t\t\t\tfor (int last2 = 0; last2 < h; ++last2){\n\t\t\t\t\t\t\tfor (int last3 = 0; last3 < h; ++last3){\n\t\t\t\t\t\t\t\tdp[p][alive][last1][last2][last3] = 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tp = (p + 1)%2;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor (int last1 = 0; last1 < h; ++last1){\n\t\t\t\tfor (int last2 = 0; last2 < h; ++last2){\n\t\t\t\t\tfor (int last3 = 0; last3 < h; ++last3){\n\t\t\t\t\t\tres += dp[p][1][last1][last2][last3];\n\t\t\t\t\t\tif (last1 + last2 + last3 > 0){\n\t\t\t\t\t\t\tres += dp[p][0][last1][last2][last3];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tres %= MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(res);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ca0b5f1018bbf17499226642a5167729", "src_uid": "9fe9658db35076c0bddc8b7ddce11013", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt(), M = in.nextInt() + 1;\n int[][][][] dp = new int[M][M][M][2];\n\n dp[0][0][0][1] = 1;\n\n final int Mod = (int) (1e9 + 9);\n\n for (int i = 0; i < N; ++i) {\n int[][][][] ndp = new int[M][M][M][2];\n for (int j = 0; j < M; ++j) {\n for (int k = 0; k < M; ++k) {\n for (int p = 0; p < M; ++p) {\n for (int u = 0; u < 2; ++u) {\n int add = dp[j][k][p][u];\n\n int nj, nk, np, nu;\n np = u == 1 ? 1 : M - 1;\n\n nj = Math.min(k + 1, M - 1);\n nk = Math.min(p + 1, M - 1);\n nu = j < M - 1 ? 1 : 0;\n\n ndp[nj][nk][np][nu] += add;\n ndp[nj][nk][np][nu] %= Mod;\n\n nj = Math.min(j + 1, M - 1);\n nk = Math.min(p + 1, M - 1);\n nu = k < M - 1 ? 1 : 0;\n\n ndp[nj][nk][np][nu] += add;\n ndp[nj][nk][np][nu] %= Mod;\n\n nj = Math.min(j + 1, M - 1);\n nk = Math.min(k + 1, M - 1);\n nu = p < M - 1 ? 1 : 0;\n\n ndp[nj][nk][np][nu] += add;\n ndp[nj][nk][np][nu] %= Mod;\n\n nk = Math.min(k + 1, M - 1);\n nj = Math.min(j + 1, M - 1);\n np = Math.min(p + 1, M - 1);\n nu = u;\n\n ndp[nj][nk][np][nu] += add;\n ndp[nj][nk][np][nu] %= Mod;\n }\n }\n }\n }\n\n dp = ndp;\n }\n\n int ans = 0;\n for (int i = 0; i < M; ++i)\n for (int j = 0; j < M; ++j)\n for (int k = 0; k < M; ++k)\n for (int u = 0; u < 2; ++u)\n if (i < M - 1 || j < M - 1 || k < M - 1 || u == 1)\n ans = (ans + dp[i][j][k][u]) % Mod;\n\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new UnknownError();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "df6d4356381e700b5cf7072214fec4c4", "src_uid": "9fe9658db35076c0bddc8b7ddce11013", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class D {\n\tstatic final int MOD = 1000000009;\n\tstatic int n;\n\tstatic int h;\n\tpublic static void main(String [] args){\n\t\ttry (Scanner s = new Scanner(System.in)){\n\t\t\tn = s.nextInt();\n\t\t\th = s.nextInt();\n\t\t\tlong [][][][][] dp = new long[h + 2][h + 2][h + 2][h + 2][2];\n\t\t\tfor (int h1 = 0; h1 <= h + 1; ++h1){\n\t\t\t\tfor (int h2 = 0; h2 <= h + 1; ++h2){\n\t\t\t\t\tfor (int h3 = 0; h3 <= h + 1; ++h3){\n\t\t\t\t\t\tfor (int h4 = 0; h4 <= h + 1; ++h4){\n\t\t\t\t\t\t\tif ((h1 > 0 && h1 <= h) || (h2 > 0 && h2 <= h) || (h3 > 0 && h3 <= h) || (h4 > 0 && h4 <= h)){\n\t\t\t\t\t\t\t\tdp[h1][h2][h3][h4][0] = 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint p = 0;\n\t\t\tfor (int i = n; i >= 1; --i){\n\t\t\t\tfor (int h1 = 0; h1 <= h + 1; ++h1){\n\t\t\t\t\tfor (int h2 = 0; h2 <= h + 1; ++h2){\n\t\t\t\t\t\tfor (int h3 = 0; h3 <= h + 1; ++h3){\n\t\t\t\t\t\t\tfor (int h4 = 0; h4 <= h + 1; ++h4){\n\t\t\t\t\t\t\t\tlong res = 0;\n\t\t\t\t\t\t\t\t// dir 1\n\t\t\t\t\t\t\t\tif (h1 == 0){\n\t\t\t\t\t\t\t\t\tres += dp[i <= h ? 1 : h + 1][Math.min(h2 > 0 ? h2 + 1 : 0, h + 1)][Math.min(h3 > 0 ? h3 + 1 : 0, h + 1)][Math.min(h4 > 0 ? h4 + 1 : 0, h + 1)][p];\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tres += dp[h1 <= h ? 1 : h + 1][Math.min(h2 > 0 ? h2 + 1 : 0, h + 1)][Math.min(h3 > 0 ? h3 + 1 : 0, h + 1)][Math.min(h4 > 0 ? h4 + 1 : 0, h + 1)][p];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\t\t\t\t// dir 2\n\t\t\t\t\t\t\t\tif (h2 == 0){\n\t\t\t\t\t\t\t\t\tres += dp[Math.min(h1 > 0 ? h1 + 1 : 0, h + 1)][i <= h ? 1 : h + 1][Math.min(h3 > 0 ? h3 + 1 : 0, h + 1)][Math.min(h4 > 0 ? h4 + 1 : 0, h + 1)][p];\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tres += dp[Math.min(h1 > 0 ? h1 + 1 : 0, h + 1)][h2 <= h ? 1 : h + 1][Math.min(h3 > 0 ? h3 + 1 : 0, h + 1)][Math.min(h4 > 0 ? h4 + 1 : 0, h + 1)][p];\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// dir 3\n\t\t\t\t\t\t\t\tif (h3 == 0){\n\t\t\t\t\t\t\t\t\tres += dp[Math.min(h1 > 0 ? h1 + 1 : 0, h + 1)][Math.min(h2 > 0 ? h2 + 1 : 0, h + 1)][i <= h ? 1 : h + 1][Math.min(h4 > 0 ? h4 + 1 : 0, h + 1)][p];\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tres += dp[Math.min(h1 > 0 ? h1 + 1 : 0, h + 1)][Math.min(h2 > 0 ? h2 + 1 : 0, h + 1)][h3 <= h ? 1 : h + 1][Math.min(h4 > 0 ? h4 + 1 : 0, h + 1)][p];\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// dir 4\n\t\t\t\t\t\t\t\tif (h4 == 0){\n\t\t\t\t\t\t\t\t\tres += dp[Math.min(h1 > 0 ? h1 + 1 : 0, h + 1)][Math.min(h2 > 0 ? h2 + 1 : 0, h + 1)][Math.min(h3 > 0 ? h3 + 1 : 0, h + 1)][i <= h ? 1 : h + 1][p];\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tres += dp[Math.min(h1 > 0 ? h1 + 1 : 0, h + 1)][Math.min(h2 > 0 ? h2 + 1 : 0, h + 1)][Math.min(h3 > 0 ? h3 + 1 : 0, h + 1)][h4 <= h ? 1 : h + 1][p];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tdp[h1][h2][h3][h4][(p + 1)%2] = res%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\tp = (p + 1)%2;\n\t\t\t}\n\t\t\tSystem.out.println(dp[0][0][0][0][p]);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de6315c05b70b4452a1bd7052fbe86c5", "src_uid": "9fe9658db35076c0bddc8b7ddce11013", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Codeforces429B\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\t\n\tvoid solve() \n\t{\n\t\tint n=ni();\n\t\tint k=ni();\n\t\tint m=ni();\n\t\tint a=ni();\n\t\tPair votes[]=new Pair[n];\n\t\tfor (int i=0;i0)\n\t\t\t\t\t\tr[votes[i].idx]=1;\n\t\t\t\t\telse\n\t\t\t\t\t\tr[votes[i].idx]=3;\n\t\t\telse\n\t\t\t\tfor (int i=0;iremV)\n\t\t\t\t\tr[votes[i].idx]=1;\n\t\t\t\telse\n\t\t\t\t\tr[votes[i].idx]=2;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i=k;i {\n\t\tint idx;\n\t\tint i;\n\t\tint c;\n\t\tPair(int a, int b, int i) {\n\t\t\tthis.i = a;\n\t\t\tc = b;\n\t\t\tidx = i;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (c == o.c)\n\t\t\t\treturn Integer.compare(i, o.i);\n\t\t\telse\n\t\t\t\treturn Integer.compare(o.c, c);\n\t\t}\n\t}\n\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\t\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 Codeforces429B().run();\n\t}\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte() \n\t{\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) \n\t\t{\n\t\t\tptrbuf = 0;\n\t\t\ttry \n\t\t\t{\n\t\t\t\tlenbuf = in.read(inbuf);\n\t\t\t}\n\t\t\tcatch (IOException e) \n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean inSpaceChar(int c) \n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() \n\t{\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && inSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\t\n\tprivate double nd() \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() \n\t{\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() \n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) \n\t\t{ // when nextLine, (inSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n) \n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(b))) \n\t\t{\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m) \n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n) \n\t{\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni() \n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl() \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tprivate void tr(Object... o) \n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c3f154da4afcc5bfb78662d090bbdc08", "src_uid": "81a890bd542963bbcec7a041dde5c247", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.lang.Math;\nimport java.math.BigInteger;\nimport java.time.format.DateTimeFormatter;\nimport java.time.LocalDateTime;\n\n// CODEFORCES\npublic class main {\n\n\tstatic int cycleNum;\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\t\n\t\t\n\t\tint n = scanner.nextInt();\n\t\tint k = scanner.nextInt();\n\t\tint m = scanner.nextInt();\n\t\tint a = scanner.nextInt();\n\t\tint[] voted = new int[a];\n\t\tfor (int i = 0; i < a; i++) {\n\t\t voted[i] = scanner.nextInt();\n\t\t}\n//\t\tint[][] ts = new int[k][2];\n//\t\tint[] cols = new int[q];\n//\t\t\n//\t\tString[] s1 = scanner.nextLine().split(\" \");\n//\t\tfor (int i = 0; i < k; i++) {\n//\t\t s1 = scanner.nextLine().split(\" \");\n//\t\t ts[i][0] = Integer.valueOf(s1[0]);\n//\t\t ts[i][1] = Integer.valueOf(s1[1]);\n//\t\t}\n//\t\ts1 = scanner.nextLine().split(\" \");\n//\t\tfor (int i = 0; i < q; i++) {\n//\t\t cols[i] = Integer.valueOf(s1[i]);\n//\t\t}\n//\t\tArrays.sort(cols);\n//\t\t\n//\t\tString[] s1 = new String[n];\n//\t\tString [] s2 = new String[n];\n//\t\t\n//\t\ts1 = scanner.nextLine().split(\" \");\n//\t\ts2 = scanner.nextLine().split(\" \");\n\n//\t\tscanner = new Scanner(System.in);\n//\t\tString[] s = scanner.nextLine().split(\" \");\n\n//\tString[] str1 = new String[4];\n//\t\tstr1 = scanner.nextLine().split(\" \");\n//\t\tString[] str2 = new String[Integer.valueOf(str1[0])];\n//\t\twhile(scanner.hasNextLine()){\n//\t\t\tstr2 = scanner.nextLine().split(\" \");\n//\t\t}\n\n//\t\tint[] p = new int[n];\n//\t\tint[] q = new int[n];\n//\t\tfor (int i = 0; i < s1.length; i++) {\n//\t\t\tp[i] = Integer.valueOf(s1[i]);\n//\t\t\tq[i] = Integer.valueOf(s2[i]);\n//\t\t}\n\n// \t\tint n = 3;\n// \t\tint k = 1;\n// \t\tint m = 5;\n// \t\tint a = 4;\n// \t\tint[] voted = {1,2,1,3};\n\t\tHashMap cMap = new HashMap<>();\n\t\tArrayList zeroVotes = new ArrayList<>();\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tzeroVotes.add(i);\n\t\t}\n\t\tfor (int i = 0; i < voted.length; i++) {\n\t\t\tif (cMap.containsKey(voted[i])) {\n\t\t\t\t cMap.get(voted[i])[0] += 1;\n\t\t\t\t cMap.get(voted[i])[1] = i;\n\t\t\t} else {\n\t\t\t\tzeroVotes.remove(new Integer(voted[i]));\n\t\t\t\tint[] t = {1, i};\n\t\t\t\tcMap.put(voted[i], t);\n\t\t\t}\n\t\t}\n\t\t\n\t\tHashMap sortedCMap = sortMap(cMap);\n\t\tint[][] cArr = new int[n+1][2]; // Candidate number, number of votes\n\t\tint ind = 1;\n\t\tfor (Map.Entry entry : sortedCMap.entrySet()) {\n\t\t\tcArr[ind][0] = entry.getKey();\n\t\t\tcArr[ind][1] = entry.getValue()[0];\n\t\t\tind += 1;\n\t\t}\n\t\t\n\t\tind = 0;\n\t\tfor (int i = 1; i < cArr.length; i++) {\n\t\t\tif (cArr[i][0] == 0) {\n\t\t\t\tcArr[i][0] = zeroVotes.get(ind);\n\t\t\t\tcArr[i][1] = 0;\n\t\t\t\tind += 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint minTopK = (int)Math.pow(10, 6);\n\t\tHashMap topK = new HashMap<>();\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t\ttopK.put(cArr[i][0], 1);\n\t\t\tminTopK = Math.min(minTopK, cArr[i][1]);\n\t\t}\n\t\t\n\t\tint[] answers = new int[n+1];\n\t\tfor (int i = 1; i < answers.length; i++) {\n\t\t\t\n\t\t\t// Check 1\n\t\t\tif (topK.containsKey(i)) {\n\t\t\t\tint p = find(cArr, i);\n\t\t\t\tind = p+1;\n\t\t\t\tint cnt = 0;\n\t\t\t\tint sum = 0;\n\t\t\t\twhile (ind < cArr.length && cnt < k-p+1) {\n\t\t\t\t\tsum += cArr[p][1]+1 - cArr[ind][1];\n\t\t\t\t\tind += 1;\n\t\t\t\t\tcnt += 1;\n\t\t\t\t}\n\t\t\t\t//if (i == 1) { System.out.println(cnt); }\n\t\t\t\tif (cnt == k-p+1 && sum > m-a) {\n\t\t\t\t\tanswers[i] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check 3\n\t\t\tif (answers[i] == 0 && !topK.containsKey(i)) {\n\t\t\t\tint p = find(cArr, i);\n\t\t\t\tif (m-a+cArr[p][1] <= minTopK) {\n\t\t\t\t\tanswers[i] = 3;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check 2\n\t\t\tif (answers[i] == 0) {\n\t\t\t\tanswers[i] = 2;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n//\t\tfor (int i = 0; i < cArr.length; i++) {\n//\t\t\tSystem.out.println(Arrays.toString(cArr[i]));\n//\t\t}\n\t\t\n\t\tfor (int i = 1; i < answers.length; i++) {\n\t\t\tSystem.out.print(answers[i] + \" \");\n\t\t}\n\t\t\n\t \n\t\t\n\t\t\n\t}\n\t\n\tstatic int find(int[][] cArr, int cNum) {\n\t\tint ans = 0;\n\t\tfor (int i = 1; i < cArr.length; i++) {\n\t\t\tif (cArr[i][0] == cNum) {\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tstatic HashMap sortMap(HashMap cMap) {\n\t\tList> list = new LinkedList>(cMap.entrySet());\n\t\tCollections.sort(list, new Comparator>() {\n\t\t\tpublic int compare(Map.Entry a, Map.Entry b) {\n\t\t\t\tif (a.getValue()[0] > b.getValue()[0]) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (a.getValue()[0] == b.getValue()[0]) {\n\t\t\t\t\tif (a.getValue()[1] < b.getValue()[1]) { return 1;}\n\t\t\t\t\telse { return -1; }\n\t\t\t\t} else {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\t\n\t\tCollections.reverse(list);\n\t\tHashMap temp = new LinkedHashMap<>();\n\t\tfor (Map.Entry x : list) {\n\t\t\ttemp.put(x.getKey(), x.getValue());\n\t\t}\n\t\treturn temp;\n\t}\n\t\n\t\n\t\n\t\n\t\n\t\n//H*(H+1)/2 + (x-H)*H >= n\n// ((y.multiply(y.add(BigInteger.ONE))).divide(BigInteger.TWO).add((x2.subtract(y)).multiply(y))).compareTo(n2) >= 0\n// (x2.subtract(y)).multiply(y)\n\t\n\n}\n\n//List sortedKeys=new ArrayList(trip.keySet());\n//Collections.sort(sortedKeys);\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bb28312b7a1e4c7e1ede5674257ab33e", "src_uid": "81a890bd542963bbcec7a041dde5c247", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.lang.Math;\nimport java.math.BigInteger;\nimport java.time.format.DateTimeFormatter;\nimport java.time.LocalDateTime;\n\n// CODEFORCES\npublic class main {\n\n\tstatic int cycleNum;\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\t\n\t\t\n\t\tint n = scanner.nextInt();\n\t\tint k = scanner.nextInt();\n\t\tint m = scanner.nextInt();\n\t\tint a = scanner.nextInt();\n\t\tint[] voted = new int[a];\n\t\tfor (int i = 0; i < a; i++) {\n\t\t voted[i] = scanner.nextInt();\n\t\t}\n//\t\tint[][] ts = new int[k][2];\n//\t\tint[] cols = new int[q];\n//\t\t\n//\t\tString[] s1 = scanner.nextLine().split(\" \");\n//\t\tfor (int i = 0; i < k; i++) {\n//\t\t s1 = scanner.nextLine().split(\" \");\n//\t\t ts[i][0] = Integer.valueOf(s1[0]);\n//\t\t ts[i][1] = Integer.valueOf(s1[1]);\n//\t\t}\n//\t\ts1 = scanner.nextLine().split(\" \");\n//\t\tfor (int i = 0; i < q; i++) {\n//\t\t cols[i] = Integer.valueOf(s1[i]);\n//\t\t}\n//\t\tArrays.sort(cols);\n//\t\t\n//\t\tString[] s1 = new String[n];\n//\t\tString [] s2 = new String[n];\n//\t\t\n//\t\ts1 = scanner.nextLine().split(\" \");\n//\t\ts2 = scanner.nextLine().split(\" \");\n\n//\t\tscanner = new Scanner(System.in);\n//\t\tString[] s = scanner.nextLine().split(\" \");\n\n//\tString[] str1 = new String[4];\n//\t\tstr1 = scanner.nextLine().split(\" \");\n//\t\tString[] str2 = new String[Integer.valueOf(str1[0])];\n//\t\twhile(scanner.hasNextLine()){\n//\t\t\tstr2 = scanner.nextLine().split(\" \");\n//\t\t}\n\n//\t\tint[] p = new int[n];\n//\t\tint[] q = new int[n];\n//\t\tfor (int i = 0; i < s1.length; i++) {\n//\t\t\tp[i] = Integer.valueOf(s1[i]);\n//\t\t\tq[i] = Integer.valueOf(s2[i]);\n//\t\t}\n\n// \t\tint n = 3;\n// \t\tint k = 1;\n// \t\tint m = 5;\n// \t\tint a = 4;\n// \t\tint[] voted = {1,2,1,3};\n\t\tHashMap cMap = new HashMap<>();\n\t\tArrayList zeroVotes = new ArrayList<>();\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tzeroVotes.add(i);\n\t\t}\n\t\tfor (int i = 0; i < voted.length; i++) {\n\t\t\tif (cMap.containsKey(voted[i])) {\n\t\t\t\t cMap.get(voted[i])[0] += 1;\n\t\t\t\t cMap.get(voted[i])[1] = i;\n\t\t\t} else {\n\t\t\t\tzeroVotes.remove(new Integer(voted[i]));\n\t\t\t\tint[] t = {1, i};\n\t\t\t\tcMap.put(voted[i], t);\n\t\t\t}\n\t\t}\n\t\t\n\t\tHashMap sortedCMap = sortMap(cMap);\n\t\tint[][] cArr = new int[n+1][2]; // Candidate number, number of votes\n\t\tint ind = 1;\n\t\tfor (Map.Entry entry : sortedCMap.entrySet()) {\n\t\t\tcArr[ind][0] = entry.getKey();\n\t\t\tcArr[ind][1] = entry.getValue()[0];\n\t\t\tind += 1;\n\t\t}\n\t\t\n\t\tind = 0;\n\t\tfor (int i = 1; i < cArr.length; i++) {\n\t\t\tif (cArr[i][0] == 0) {\n\t\t\t\tcArr[i][0] = zeroVotes.get(ind);\n\t\t\t\tcArr[i][1] = 0;\n\t\t\t\tind += 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint minTopK = (int)Math.pow(10, 6);\n\t\tHashMap topK = new HashMap<>();\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t if (cArr[i][1] == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttopK.put(cArr[i][0], 1);\n\t\t\tminTopK = Math.min(minTopK, cArr[i][1]);\n\t\t}\n\t\t\n\t\tint[] answers = new int[n+1];\n\t\tfor (int i = 1; i < answers.length; i++) {\n\t\t\t\n\t\t\tint p = find(cArr, i);\n\t\t\t\n\t\t\t// Check 1\n\t\t\tif (topK.containsKey(i)) {\n\t\t\t\tind = p+1;\n\t\t\t\tint cnt = 0;\n\t\t\t\tint sum = 0;\n\t\t\t\twhile (ind < cArr.length && cnt < k-p+1) {\n\t\t\t\t\tsum += cArr[p][1]+1 - cArr[ind][1];\n\t\t\t\t\tind += 1;\n\t\t\t\t\tcnt += 1;\n\t\t\t\t}\n\t\t\t\t//if (i == 1) { System.out.println(cnt); }\n\t\t\t\tif (cnt < k-p+1 || sum > m-a) {\n\t\t\t\t\tanswers[i] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check 3\n\t\t\tif (answers[i] == 0 && !topK.containsKey(i)) {\n\t\t\t\tif (m-a+cArr[p][1] <= minTopK) {\n\t\t\t\t\tanswers[i] = 3;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check 2\n\t\t\tif (answers[i] == 0) {\n\t\t\t\tanswers[i] = 2;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n//\t\tfor (int i = 0; i < cArr.length; i++) {\n//\t\t\tSystem.out.println(Arrays.toString(cArr[i]));\n//\t\t}\n\t\t\n\t\tfor (int i = 1; i < answers.length; i++) {\n\t\t\tSystem.out.print(answers[i] + \" \");\n\t\t}\n\t\t\n\t \n\t\t\n\t\t\n\t}\n\t\n\tstatic int find(int[][] cArr, int cNum) {\n\t\tint ans = 0;\n\t\tfor (int i = 1; i < cArr.length; i++) {\n\t\t\tif (cArr[i][0] == cNum) {\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tstatic HashMap sortMap(HashMap cMap) {\n\t\tList> list = new LinkedList>(cMap.entrySet());\n\t\tCollections.sort(list, new Comparator>() {\n\t\t\tpublic int compare(Map.Entry a, Map.Entry b) {\n\t\t\t\tif (a.getValue()[0] > b.getValue()[0]) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else if (a.getValue()[0] == b.getValue()[0]) {\n\t\t\t\t\tif (a.getValue()[1] < b.getValue()[1]) { return 1;}\n\t\t\t\t\telse { return -1; }\n\t\t\t\t} else {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\t\n\t\tCollections.reverse(list);\n\t\tHashMap temp = new LinkedHashMap<>();\n\t\tfor (Map.Entry x : list) {\n\t\t\ttemp.put(x.getKey(), x.getValue());\n\t\t}\n\t\treturn temp;\n\t}\n\t\n\t\n\t\n\t\n\t\n\t\n//H*(H+1)/2 + (x-H)*H >= n\n// ((y.multiply(y.add(BigInteger.ONE))).divide(BigInteger.TWO).add((x2.subtract(y)).multiply(y))).compareTo(n2) >= 0\n// (x2.subtract(y)).multiply(y)\n\t\n\n}\n\n//List sortedKeys=new ArrayList(trip.keySet());\n//Collections.sort(sortedKeys);\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "983ae60d851a164e61c5af8fd7afba55", "src_uid": "81a890bd542963bbcec7a041dde5c247", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "//package neerc2017;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\n\npublic class F {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), K = ni(), m = ni(), A = ni();\n\t\tint[] a = na(A);\n\t\tfor(int i = 0;i < A;i++)a[i]--;\n\t\tint[] f = new int[n];\n\t\tint[] last = new int[n];\n\t\tArrays.fill(last, -1);\n\t\tfor(int i = 0;i < A;i++){\n\t\t\tf[a[i]]++;\n\t\t\tlast[a[i]] = i;\n\t\t}\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint flag = 0;\n\t\t\t{\n\t\t\t\tint[] lf = Arrays.copyOf(f, n);\n\t\t\t\tint[] llast = Arrays.copyOf(last, n);\n\t\t\t\tlf[i] += m-A;\n\t\t\t\tif(m-A > 0)llast[i] = m-1;\n\t\t\t\tflag |= ok(lf, llast, K, i) ? 2 : 0;\n\t\t\t}\n\t\t\t{\n\t\t\t\tint[][] fl = new int[n-1][];\n\t\t\t\tint p = 0;\n\t\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\t\tif(j == i)continue;\n\t\t\t\t\tfl[p++] = new int[]{f[j], last[j], j};\n\t\t\t\t}\n\t\t\t\tArrays.sort(fl, new Comparator() {\n\t\t\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\t\t\tif(a[0] != b[0])return -(a[0] - b[0]);\n\t\t\t\t\t\treturn a[1] - b[1];\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tint[] lf = Arrays.copyOf(f, n);\n\t\t\t\tint[] llast = Arrays.copyOf(last, n);\n\t\t\t\tint rem = m-A;\n\t\t\t\tfor(int j = 0;j < n-1;j++){\n\t\t\t\t\tint fv = fl[j][0], lv = fl[j][1];\n\t\t\t\t\tif(fv > lf[i] || fv == lf[i] && lv < llast[i])continue;\n\t\t\t\t\tint up = Math.min(rem, lf[i]+1-fv);\n\t\t\t\t\trem -= up;\n\t\t\t\t\tlf[fl[j][2]] += up;\n\t\t\t\t\tllast[fl[j][2]] = n-1;\n\t\t\t\t}\n\t\t\t\tflag |= ok(lf, llast, K, i) ? 1 : 0;\n\t\t\t}\n\t\t\tif(flag == 3){\n\t\t\t\tout.print(1 + \" \");\n\t\t\t}else if(flag == 2){\n\t\t\t\tout.print(2 + \" \");\n\t\t\t}else if(flag == 0){\n\t\t\t\tout.print(3 + \" \");\n\t\t\t}else{\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n\t\n\tboolean ok(int[] f, int[] last, int K, int who)\n\t{\n\t\tif(f[who] == 0)return false;\n\t\tint n = f.length;\n\t\tint rank = 1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(i == who)continue;\n\t\t\tif(f[i] > f[who] || f[i] == f[who] && last[i] < last[who])rank++;\n\t\t}\n\t\treturn rank <= K;\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 F().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fffad5c6ab756a6a82ef378f55877662", "src_uid": "81a890bd542963bbcec7a041dde5c247", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\npublic class Pixels {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n BufferedReader inpt = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer input;\n long n = 0;\n try {\n input = new StringTokenizer(inpt.readLine());\n long[] rgb = {Integer.parseInt(input.nextToken()),Integer.parseInt(input.nextToken()),Integer.parseInt(input.nextToken())};\n descendingSort(rgb);\n while(rgb[1]!=0){\n if(rgb[2] != 0){\n n = n+rgb[2];\n rgb[0] = rgb[0] + rgb[2];\n rgb[1] = rgb[1] - rgb[2];\n rgb[2] = 0;\n } else if(rgb[1] == 1) {\n n = n+rgb[0];\n rgb[1] = 0;\n rgb[0] = 0;\n rgb[2] = 1;\n } else {\n n = n+rgb[1]/2;\n rgb[0] = rgb[0] - rgb[1]/2;\n rgb[2] = rgb[2] + rgb[1]/2;\n rgb[1] = rgb[1] - rgb[1]/2;\n }\n descendingSort(rgb);\n //System.out.println(rgb[0] +\" \"+rgb[1]+\" \"+rgb[2]);\n }\n \n \n if(rgb[0] == 0){\n n = -1;\n }\n System.out.println(n);\n \n \n \n \n \n \n } catch (IOException e) {\n e.printStackTrace();\n }\n\n }\n \n public static void descendingSort(long[] a){\n Arrays.sort(a);\n long c = a[0];\n a[0] = a[2];\n a[2] = c;\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dffbb8e51a43918f9fdb9aaba8aeeedc", "src_uid": "b8008caf788336775cb8ebb76478b04c", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\npublic class Pixels {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n BufferedReader inpt = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer input;\n int n = 0;\n try {\n input = new StringTokenizer(inpt.readLine());\n int[] rgb = {Integer.parseInt(input.nextToken()),Integer.parseInt(input.nextToken()),Integer.parseInt(input.nextToken())};\n descendingSort(rgb);\n while(rgb[1]!=0){\n if(rgb[2] != 0){\n n = n+rgb[2];\n rgb[0] = rgb[0] + rgb[2];\n rgb[1] = rgb[1] - rgb[2];\n rgb[2] = 0;\n } else if(rgb[1] == 1) {\n n = n+rgb[0];\n rgb[1] = 0;\n rgb[0] = 0;\n rgb[2] = 1;\n } else {\n n = n+rgb[1]/2;\n rgb[0] = rgb[0] - rgb[1]/2;\n rgb[2] = rgb[2] + rgb[1]/2;\n rgb[1] = rgb[1] - rgb[1]/2;\n }\n descendingSort(rgb);\n System.out.println(rgb[0] +\" \"+rgb[1]+\" \"+rgb[2]);\n }\n \n \n if(rgb[0] == 0){\n n = -1;\n }\n System.out.println(n);\n \n \n \n \n \n \n } catch (IOException e) {\n e.printStackTrace();\n }\n\n }\n \n public static void descendingSort(int[] a){\n Arrays.sort(a);\n int c = a[0];\n a[0] = a[2];\n a[2] = c;\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9fd9f41f3020553d2d0358db13259cc7", "src_uid": "b8008caf788336775cb8ebb76478b04c", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Pixel {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int i,j,k,n,a,b,c,big,middle,small,sum;\n while (input.hasNext()){\n a = input.nextInt(); b = input.nextInt(); c = input.nextInt(); sum = 0;\n \n big = (a>=b) ? ((a>=c)? a :c) : ((b>=c) ? b : c);\n small = (a>=b) ? ((b>=c) ? c : b) : ((a>=c) ? c : a);\n middle = a>b ? (c>a ? a :(b>c)? b:c) : (c>b ? b : a>c? a : c);\n\n // System.out.println(big+ \" \" + middle + \" \" + small);\n for (i=0; i 0 && v[j] > 0) {\n\t\t\t\tint[] w = v.clone();\n\t\t\t\t--w[i];\n\t\t\t\t--w[j];\n\t\t\t\t++w[3 - i - j];\n\t\t\t\tans = Math.min(ans, trueCalc(w) + 1);\n\t\t\t}\n\t\t}\n\t\tmap[v[0]][v[1]][v[2]] = ans;\n\t\treturn ans;\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\t\n/*\t\tfor (int i = 0; i < 10; ++i) {\n\t\t\tfor (int j = 0; j < 10; ++j) {\n//\t\t\t\tSystem.out.println(i + \" \" + j);\n\t\t\t\tfor (int k = 0; k < 10; ++k) {\n\t\t\t\t\tint[] w = {i, j, k};\n\t\t\t\t\tint a1 = calc(w);\n\t\t\t\t\tint a2 = trueCalc(w);\n\t\t\t\t\tif (a1 != a2) {\n\t\t\t\t\t\tSystem.err.println(Arrays.toString(w));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n*/\t\t\n\t\tint[] v = new int[3];\n\t\tfor (int i = 0; i < v.length; ++i) {\n\t\t\tv[i] = nextInt();\n\t\t}\n\t\tout.println(calc(v));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4777aa2fea61567308ceed146901efac", "src_uid": "b8008caf788336775cb8ebb76478b04c", "difficulty": 2100.0} {"lang": "Java 7", "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.HashSet;\n\npublic class D {\n\n// static void build_tree(int n) {\n// int[] cnt=new int[n];\n// int[][] left=new int[n][n<<5], right=new int[n][n<<5];\n// \n// cnt[0]=1;\n// for (int level=0; level0) {\n ret++;\n i=i>>1;\n }\n return ret;\n }\n\n static void compute(int n, int[][] q) {\n //group queries by level\n int[] l2qcnt=new int[n+1];\n for (int i=0; i s=new HashSet();\n for (int i=0; iqr)) {\n s.add(q[qidx][4]);\n }\n }\n //update l,r\n int extra=Integer.bitCount(r)==1? 1: 0;\n l+=log2(l-1);\n r+=log2(r-1);\n r+=extra;\n }\n System.out.println(s.size());\n }\n }\n }\n \n \n \n \n static StringBuilder sb=new StringBuilder();\n static void parse(String l, int[] here) {\n sb.setLength(0);\n int len=l.length(), j=0;\n for (int i=0; i0) {\n here[j++]=Integer.parseInt(sb.toString());\n }\n }\n \n static void run_stream(InputStream ins) throws IOException {\n BufferedReader r=new BufferedReader(new InputStreamReader(System.in));\n String[] l=r.readLine().split(\" \");\n int n=Integer.parseInt(l[0]);\n int m=Integer.parseInt(l[1]);\n \n int[][] q=new int[m][5];\n for (int i=0; i level = new ArrayList();\n\t\tArrayList left = new ArrayList();\n\t\tArrayList right = new ArrayList();\n\t\tArrayList x = new ArrayList();\n\t\tArrayList lvLR = new ArrayList();\n\t\tHashSet set = new HashSet();\n\t\tStringBuilder sb = new StringBuilder();\n\t\t// operations\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tsp = in.readLine().split(\" \");\n\t\t\tint op = Integer.parseInt(sp[0]);\n\t\t\tif (op == 1) {\n\t\t\t\tint lv, l, r;\n\t\t\t\tlevel.add(lv = Integer.parseInt(sp[1]));\n\t\t\t\tleft.add(l = Integer.parseInt(sp[2]));\n\t\t\t\tright.add(r = Integer.parseInt(sp[3]));\n\t\t\t\tx.add(Integer.parseInt(sp[4]));\n\t\t\t\tInteger[][] lr = new Integer[n + 1][2];\n\t\t\t\tlvLR.add(lr);\n\n\t\t\t\tfor (int jj = n; jj > lv; jj--) {\n\t\t\t\t\tlr[jj][0] = lr[jj][1] = -1;\n\t\t\t\t}\n\t\t\t\tlr[lv][0] = l;\n\t\t\t\tlr[lv][1] = r;\n\t\t\t\tfor (int jj = lv - 1; jj >= 1; jj--) {\n\t\t\t\t\tlr[jj][0] = par[lr[jj + 1][0]];\n\t\t\t\t\tlr[jj][1] = par[lr[jj + 1][1]];\n\t\t\t\t}\n\n\t\t\t} else {// 2\n\t\t\t\tint lv = Integer.parseInt(sp[1]);\n\t\t\t\tint p = Integer.parseInt(sp[2]);\n\t\t\t\tset.clear();\n\n\t\t\t\tfor (int ai = 0; ai < level.size(); ai++) {\n\t\t\t\t\tInteger[][] lr = lvLR.get(ai);\n\t\t\t\t\tif (lr[lv][0] != -1) {\n\t\t\t\t\t\tif (lr[lv][0] <= p && p <= lr[lv][1]) {\n\t\t\t\t\t\t\tset.add(x.get(ai));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsb.append(set.size() + \"\\n\");\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(sb);\n\t}\n}\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "03f75670459dec6ed4b73f6794b174b9", "src_uid": "9f239cfd29c1a2652a065bfe5c15476a", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n public static void main(String[] args) throws Exception {\n new B().solve();\n // new FileInputStream(new File(\"input.txt\")),\n // new PrintStream(new FileOutputStream(new File(\"output.txt\"))));\n }\n\n void solve() throws IOException {\n BufferedReader in = new BufferedReader(new\n InputStreamReader(System.in));\n Scanner sc = new Scanner(System.in);\n String[] sp;\n\n // n, m\n sp = in.readLine().split(\" \");\n int n = Integer.parseInt(sp[0]);\n int m = Integer.parseInt(sp[1]);\n\n // par\n int[][] par = new int[n][1000000];\n {\n // 0\n for (int pos = 1; pos < par[0].length; pos++) {\n par[0][pos] = pos;\n }\n // 1\n int nci = 1;\n for (int pos = 1; nci < par[0].length; pos++) {\n if ((pos & -pos) == pos) {// 2^k\n par[1][nci++] = pos;\n par[1][nci++] = pos;\n } else {\n par[1][nci++] = pos;\n }\n }\n // 2~\n for (int lv = 2; lv < n; lv++) {\n for (int pos = 1; pos < par[0].length; pos++) {\n par[lv][pos] = par[1][par[lv - 1][pos]];\n }\n }\n }\n\n ArrayList level = new ArrayList();\n ArrayList left = new ArrayList();\n ArrayList right = new ArrayList();\n ArrayList x = new ArrayList();\n HashSet set = new HashSet();\n // operations\n for (int i = 0; i < m; i++) {\n sp = in.readLine().split(\" \");\n int op = Integer.parseInt(sp[0]);\n if (op == 1) {\n level.add(Integer.parseInt(sp[1]));\n left.add(Integer.parseInt(sp[2]));\n right.add(Integer.parseInt(sp[3]));\n x.add(Integer.parseInt(sp[4]));\n } else {// 2\n int lv2 = Integer.parseInt(sp[1]);\n int p = Integer.parseInt(sp[2]);\n set.clear();\n\n for (int ai = 0; ai < level.size(); ai++) {\n int lv1 = level.get(ai);\n if (lv2 <= lv1) {\n int l = par[lv1 - lv2][left.get(ai)];\n int r = par[lv1 - lv2][right.get(ai)];\n if (l <= p && p <= r) {\n set.add(x.get(ai));\n }\n }\n }\n System.out.println(set.size());\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "75b5ac5352d5e731538c4c9006215019", "src_uid": "9f239cfd29c1a2652a065bfe5c15476a", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import static java.lang.Integer.*;\n\nimport java.util.*;\n\n//@SuppressWarnings(\"unused\")\npublic class B {\n\n\tprivate final static boolean autoflush = false;\n\n\tRandom R = new Random();\n\n\tclass Segment implements Comparable {\n\t\tint L, R;\n\t\tSet H = new TreeSet<>();\n\t\tpublic boolean equals(Object o) {\n\t\t\tSegment s = (Segment)o;\n\t\t\treturn s.L == L && s.R == R;\n\t\t}\n\t\tpublic int compareTo(Segment s) {\n\t\t\tif (L != s.L) return L - s.L;\n\t\t\telse return R - s.R;\n\t\t}\n\t}\n\n\tpublic B () {\n\t\tint SZ = 200000;\n\t\tint [] P = new int [SZ];\n\t\tfor (int i = 1, s = 1; i < SZ; ++i, ++s) {\n\t\t\tP[i] = s;\n\t\t\tif (bitCount(s) == 1)\n\t\t\t\tP[++i] = s;\n\t\t}\n\n\t\tint N = sc.nextInt();\n\t\tint M = sc.nextInt();\n\n\t\tTreeMap [] L = new TreeMap[N+1];\n\t\tfor (int i = 1; i <= N; ++i)\n\t\t\tL[i] = new TreeMap();\n\n\t\tfor (int m = 0; m < M; ++m) {\n\t\t\tInteger [] Q = sc.nextInts();\n\t\t\tif (Q[0] == 1) {\n\t\t\t\tint t = Q[1], l = Q[2], r = Q[3], x = Q[4];\n\t\t\t\tfor (int y = t; y >= 1; --y) {\n\t\t\t\t\tSegment S = new Segment(); S.L = l; S.R = r;\n\t\t\t\t\tif (L[y].containsKey(S))\n\t\t\t\t\t\tL[y].get(S).H.add(x);\n\t\t\t\t\telse {\n\t\t\t\t\t\tS.H.add(x);\n\t\t\t\t\t\tL[y].put(S, S);\n\t\t\t\t\t}\n\t\t\t\t\tl = P[l]; r = P[r];\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tSet res = new TreeSet();\n\t\t\t\tint t = Q[1], v = Q[2];\n\t\t\t\tfor (Segment S : L[t].keySet())\n\t\t\t\t\tif (S.L <= v && S.R >= v)\n\t\t\t\t\t\tres.addAll(S.H);\n\t\t\t\tprint(res.size());\n\t\t\t}\n\t\t}\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static MyScanner sc = new MyScanner();\n\tprivate static class MyScanner {\n\t\tpublic String next() { newLine(); return line[index++]; }\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\tpublic String nextLine() { line = null; return readLine(); }\n\t\tpublic String [] nextStrings() { return nextLine().split(\" \"); }\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [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\tprivate boolean eol() { return index == line.length; }\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error (e);\n\t\t\t}\n\t\t}\n\t\tprivate final java.io.BufferedReader r;\n\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate String [] line;\n\t\tprivate int index;\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\n\t}\n\tprivate static void print (Object o, Object... a) { printDelim(\" \", o, a); }\n\tprivate static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }\n\tprivate static void exit() {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static String build (String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.substring(delim.length());\n\t}\n\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = java.lang.reflect.Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable)\n\t\t\tfor (Object p : (Iterable)o)\n\t\t\t\tappend(b, p, delim);\n\t\telse\n\t\t\tb.append(delim).append(o);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static void start() { t = millis(); }\n\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);\n\tprivate static long t;\n\tprivate static long millis() { return System.currentTimeMillis(); }\n\tpublic static void main (String[] args) { new B(); exit(); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8c8cf36042ae5e5c5d6d1139ae967934", "src_uid": "9f239cfd29c1a2652a065bfe5c15476a", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "232b1429b1da72bc348c16de34c72a19", "src_uid": "649e9f477b97c1f72b05d409b4a99d59", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\npublic class Main {\n public static void main(String[]args){\n new Main().run();\n }\n void run(){\n Scanner sc=new Scanner(System.in);\n long a=sc.nextLong(),l=sc.nextLong()-1;\n long res=func(a,l);\n System.out.println(res);\n }\n private long func(long a,long l){// [a,a+l]\n if(l>20){\n return a%10 + func(a/10,l/10 + (a%10+l%10)/10)*10;\n }\n int[] cnt=new int[(int)(l+1)];\n for (int i = 0; i0){\n if(l%10==4||l%10==7)res++;\n l/=10;\n }\n return res;\n }\n long INF=1L<<58;\n class E{\n long min;\n int[] cnt;\n E(long min,int[] cnt){\n this.min=min;\n this.cnt=cnt;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj==null) return false;\n if (getClass()!=obj.getClass()) return false;\n final E other = (E) obj;\n if (this.min!=other.min) return false;\n if (!Arrays.equals(this.cnt, other.cnt)) return false;\n return true;\n }\n\n @Override\n public int hashCode() {\n int hash = 7;\n hash = 67*hash+(int) (this.min^(this.min>>>32));\n hash = 67*hash+Arrays.hashCode(this.cnt);\n return hash;\n }\n\n }\n HashSet set=new HashSet();\n private long func2(long min, int[] cnt) {\n if(cnt.length==1){\n return func3(min,cnt[0]);\n }\n E key = new E(min,cnt);\n if(set.contains(key))return INF;\n set.add(key);\n long res=INF;\n loop:for (int o = 0; o<10; o++) {\n int i=(int)((min+o)%10);\n int len = (i+cnt.length-1)/10 + 1;\n int[] ncnt=new int[len];\n fill(ncnt,-1);\n len=0;\n for (int j = 0; j0){\n for (int i = 0;; i++) {\n long tmp = res + p10 * i;\n if(possible(tmp,min,p10/10,dig-1,cnt)){\n res=tmp;break;\n }\n if(i==9)throw new RuntimeException();\n }\n p10/=10;\n dig--;\n }\n return res;\n }\n\n private boolean possible(long tmp, long min,long p10, int dig, int cnt) {\n if(lucky(tmp) > cnt)return false;\n cnt -= lucky(tmp);\n if(cnt>dig)return false;\n while(cnt0){\n tmp += p10*7;\n dig--;\n p10/=10;\n }\n return tmp>=min;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24ce28b32b9591a584e1500ae69923ff", "src_uid": "649e9f477b97c1f72b05d409b4a99d59", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport static java.lang.Character.isDigit;\nimport static java.lang.Character.isLowerCase;\nimport static java.lang.Character.isUpperCase;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport static java.lang.Character.isDigit;\n\npublic class Main{\n static void debug(Object...os){\n System.err.println(deepToString(os));\n }\n \n void run(){\n \n // Random r=new Random();\n // for(int o=0;o<1000000;o++) {\n // System.out.print(\".\");\n // long start=System.currentTimeMillis();\n //// int a=r.nextInt(1000000000),l=r.nextInt(10);\n // int a=777777770,l=9129;\n // long res = calc(a,l);\n // assert a0) {\n // if(t%10==4 || t%10==7)cnt++;\n // t/=10;\n // }\n // t=a+i;\n // while(t>0) {\n // if(t%10==4 || t%10==7)cnt--;\n // t/=10;\n // }\n // assert cnt==0;\n // }\n // if(System.currentTimeMillis()-start>100) {\n // debug(a,l);\n // }\n //// debug(System.currentTimeMillis()-start);\n // }\n // System.exit(0);\n \n int a=nextInt(),l=nextInt()-1;\n System.out.println(calc(a,l));\n }\n int TH = 3000;\n private long calc(int a,int l){\n if(l>TH) {\n return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;\n }\n int[] is=new int[l+1];\n for(int i=0;i0) {\n if(t%10==4||t%10==7)is[i]++;\n t/=10;\n }\n }\n for(int b=a+1;b0) {\n if(t%10==4||t%10==7)cnt++;\n t/=10;\n }\n if(is[j]!=cnt) {\n ok=false;break;\n }\n }\n if(ok)return b;\n }\n if(l==0) {\n assert a%10==7;\n if(a%10==7)\n return 4 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;\n if(a%10==9)\n return 0 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;\n }\n return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;\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'0) {\n // if(t%10==4 || t%10==7)cnt++;\n // t/=10;\n // }\n // t=a+i;\n // while(t>0) {\n // if(t%10==4 || t%10==7)cnt--;\n // t/=10;\n // }\n // assert cnt==0;\n // }\n // if(System.currentTimeMillis()-start>100) {\n // debug(a,l);\n // }\n //// debug(System.currentTimeMillis()-start);\n // }\n // System.exit(0);\n \n int a=nextInt(),l=nextInt()-1;\n System.out.println(calc(a,l));\n }\n int TH = 3000;\n private long calc(int a,int l){\n if(l>TH) {\n return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;\n }\n int[] is=new int[l+1];\n for(int i=0;i0) {\n if(t%10==4||t%10==7)is[i]++;\n t/=10;\n }\n }\n for(int b=a+1;b0) {\n if(t%10==4||t%10==7)cnt++;\n t/=10;\n }\n if(is[j]!=cnt) {\n ok=false;break;\n }\n }\n if(ok)return b;\n }\n if(l==0) {\n assert a%10==7;\n return 4 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;\n }\n return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;\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'= left && 2 <= right) ? 1 : 0;\n for(int i = 5 ; i < MAX ; i+=4)\n if(i >= left && i <= right)\n if(isPrime(i, prime))\n res++;\n\n System.out.println(res);\n }\n\n private static void setFalse(int idx, int[] prime)\n {\n idx >>= 1;\n int ind = idx >> 3;\n int sh = (idx & 7);\n sh = 1<>= 1;\n int ind = idx >> 3;\n int sh = idx & 7;\n\n return (prime[ind] & (1<= l) && (start+i <= r) ){\n ans++;\n }\n }\n }\n\n if( 2 >= l && 2 <= r ){\n ans++;\n }\n\n out.println( ans );\n }\n\n private static final String INPUT_FILE = \"inp.txt\";\n\n public static void main(String[] args) throws IOException {\n long start_time = System.currentTimeMillis();\n if (new File(INPUT_FILE).exists())\n System.setIn(new FileInputStream(INPUT_FILE));\n new Main().solve();\n out.close();\n if( IS_DEBAG ){\n System.err.println(\"Time is: \"+(System.currentTimeMillis()-start_time));\n }\n }\n\n private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n private static PrintWriter out = new PrintWriter(System.out);;\n private StringTokenizer st = new StringTokenizer(\"\");\n\n String nextToken() throws IOException {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n String nextLine() throws IOException {\n st = new StringTokenizer(\"\");\n return in.readLine();\n }\n\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4babf663f92851b45c32f113522e8f3", "src_uid": "55a83526c10126ac3a6e6e5154b120d0", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class solution {\n\n static boolean IS_DEBAG = false;\n static int maxn = 17321;\n static int block = 1000000;\n\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(new File(\"input.txt\"));\n PrintWriter out = new PrintWriter(\"output.txt\");\n long l = in.nextLong();\n long r = in.nextLong();\n\n\n boolean nprime[] = new boolean[maxn];\n boolean bl[] = new boolean[block];\n int primes[] = new int[maxn];\n int cnt = 0;\n\n int nsq = (int) Math.sqrt(r);\n\n for (int i = 2; i <= nsq; ++i) {\n if (!nprime[i]) {\n primes[cnt++] = i;\n for (int j = i + i; j <= nsq; j += i) {\n nprime[j] = true;\n }\n }\n }\n\n int ans = 0;\n\n for (int k = 0; k <= r / block; ++k) {\n Arrays.fill(bl, false);\n int start = k * block;\n for (int i = 0; i < cnt; ++i) {\n for (int j = Math.max((start + primes[i] - 1) / primes[i], 2) * primes[i] - start; j < block; j += primes[i]) {\n bl[j] = true;\n }\n }\n if (k == 0) {\n bl[0] = bl[1] = true;\n }\n for (int i = 0; i < block && start + i <= r; ++i) {\n if (!bl[i]) {\n if (((start + i - 1) % 4 == 0) && (start + i >= l) && (start + i <= r)) {\n ans++;\n }\n }\n }\n }\n\n if (2 >= l && 2 <= r) {\n ans++;\n }\n\n out.println(ans);\n out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4b6ece02c6bad41b4fe9f027d6b9e36b", "src_uid": "55a83526c10126ac3a6e6e5154b120d0", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class solution {\n\n static boolean IS_DEBAG = false;\n static int maxn = 17321;\n static int block = 1000000;\n\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(new File(\"input.txt\"));\n PrintWriter out = new PrintWriter(\"output.txt\");\n long l = in.nextLong();\n long r = in.nextLong();\n\n\n boolean nprime[] = new boolean[maxn];\n boolean bl[] = new boolean[block];\n int primes[] = new int[maxn];\n int cnt = 0;\n\n int nsq = (int) Math.sqrt(r);\n\n for (int i = 2; i <= nsq; ++i) {\n if (!nprime[i]) {\n primes[cnt++] = i;\n for (int j = i + i; j <= nsq; j += i) {\n nprime[j] = true;\n }\n }\n }\n\n int ans = 0;\n\n for (int k = 0; k <= r / block; ++k) {\n Arrays.fill(bl, false);\n int start = k * block;\n for (int i = 0; i < cnt; ++i) {\n for (int j = Math.max((start + primes[i] - 1) / primes[i], 2) * primes[i] - start; j < block; j += primes[i]) {\n bl[j] = true;\n }\n }\n if (k == 0) {\n bl[0] = bl[1] = true;\n }\n for (int i = 0; i < block && start + i <= r; ++i) {\n if (!bl[i]) {\n if (((start + i - 1) % 4 == 0) && (start + i >= l) && (start + i <= r)) {\n ans++;\n }\n }\n }\n }\n\n if (2 >= l && 2 <= r) {\n ans++;\n }\n\n out.println(ans);\n out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "491eec59ffa25b9a3785b1a690000d3b", "src_uid": "55a83526c10126ac3a6e6e5154b120d0", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E implements Runnable {\n\n\tPoint intersect(Line l1, Line l2) {\n\t\tFrac det = l1.a.multiply(l2.b).sub(l2.a.multiply(l1.b));\n\t\tFrac x = l1.c.multiply(l2.b).negate().add(l2.c.multiply(l1.b));\n\t\tFrac y = l1.a.multiply(l2.c).negate().add(l2.a.multiply(l1.c));\n\t\treturn new Point(x.divide(det), y.divide(det));\n\t}\n\n\tboolean intersect(Point v, Point p, Point t1, Point t2) {\n\t\tLine l1 = new Line(v, p);\n\t\tLine l2 = new Line(t1, t2);\n\t\tFrac det = l1.a.multiply(l2.b).sub(l2.a.multiply(l1.b));\n\t\tif (det.signum() != 0)\n\t\t\treturn l1.side(t1) * l1.side(t2) <= 0\n\t\t\t\t\t&& l2.side(v) * l2.side(p) <= 0;\n\t\telse {\n\t\t\tif (l1.side(t1) != 0) {\n\t\t\t\treturn false;\n\t\t\t} else {\n\t\t\t\treturn pointBetween(v, p, t1) || pointBetween(v, p, t2);\n\t\t\t}\n\t\t}\n\t}\n\n\tboolean mirrorIsBad(Point v, Point p, Point t1, Point t2) {\n\t\tLine l1 = new Line(v, p);\n\t\tLine l2 = new Line(t1, t2);\n\t\tFrac det = l1.a.multiply(l2.b).sub(l2.a.multiply(l1.b));\n\t\tif (det.signum() != 0)\n\t\t\treturn l1.side(t1) * l1.side(t2) <= 0\n\t\t\t\t\t&& l2.side(v) * l2.side(p) <= 0;\n\t\telse {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tboolean pointBetween(Point a, Point b, Point t) {\n\t\tboolean b1 = a.x.compareTo(t.x) == a.x.compareTo(b.x)\n\t\t\t\t&& b.x.compareTo(t.x) == b.x.compareTo(a.x);\n\t\tboolean b2 = a.y.compareTo(t.y) == a.y.compareTo(b.y)\n\t\t\t\t&& b.y.compareTo(t.y) == b.y.compareTo(a.y);\n\t\treturn b1 && b2;\n\t}\n\n\tboolean mirrorIsNotUseful(Point v, Point p, Point m1, Point m2) {\n\t\tLine mirror = new Line(m1, m2);\n\t\treturn mirror.side(v) * mirror.side(p) <= 0;\n\t}\n\n\tboolean solve1() {\n\t\tPoint v = nextPoint();\n\t\tPoint p = nextPoint();\n\t\tPoint w1 = nextPoint(), w2 = nextPoint();\n\t\tPoint m1 = nextPoint(), m2 = nextPoint();\n\t\tif (mirrorIsNotUseful(v, p, m1, m2)) {\n\t\t\treturn !intersect(v, p, w1, w2) && !mirrorIsBad(v, p, m1, m2);\n\t\t}\n\t\tif (!intersect(v, p, w1, w2) && !intersect(v, p, m1, m2)) {\n\t\t\treturn true;\n\t\t}\n\t\tLine mirror = new Line(m1, m2);\n\t\tPoint virtualP = mirror.reflect(p);\n\n\t\tif (!intersect(v, virtualP, m1, m2))\n\t\t\treturn false;\n\n\t\tPoint m = intersect(new Line(v, virtualP), new Line(m1, m2));\n\t\treturn !intersect(v, m, w1, w2) && !intersect(m, p, w1, w2);\n\t}\n\n\tprivate void solve() throws IOException {\n\t\tif (solve1()) {\n\t\t\tout.println(\"YES\");\n\t\t} else {\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\n\tPoint nextPoint() {\n\t\treturn new Point(nextInt(), nextInt());\n\t}\n\n\tclass Line {\n\t\tFrac a, b, c;\n\n\t\tLine(Point p1, Point p2) {\n\t\t\tb = p1.x.sub(p2.x);\n\t\t\ta = p2.y.sub(p1.y);\n\t\t\tc = p1.x.multiply(a).add(p1.y.multiply(b)).negate();\n\t\t}\n\n\t\tint side(Point p) {\n\t\t\tFrac val = a.multiply(p.x).add(b.multiply(p.y)).add(c);\n\t\t\treturn val.signum();\n\t\t}\n\n\t\tPoint reflect(Point p) {\n\t\t\tFrac val = a.multiply(p.x).add(b.multiply(p.y)).add(c);\n\t\t\tFrac warp = a.multiply(a).add(b.multiply(b));\n\t\t\tval = val.divide(warp);\n\t\t\tFrac xx = p.x.sub(a.multiply(val).multiply(new Frac(2)));\n\t\t\tFrac yy = p.y.sub(b.multiply(val).multiply(new Frac(2)));\n\t\t\treturn new Point(xx, yy);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"Line [a=\" + a + \", b=\" + b + \", c=\" + c + \"]\";\n\t\t}\n\t}\n\n\tclass Point {\n\t\tFrac x, y;\n\n\t\tpublic Point(int x, int y) {\n\t\t\tthis.x = new Frac(x);\n\t\t\tthis.y = new Frac(y);\n\t\t}\n\n\t\tpublic Point(Frac x, Frac 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 \"Point [x=\" + x + \", y=\" + y + \"]\";\n\t\t}\n\t}\n\n\tclass Frac implements Comparable {\n\t\tBigInteger n, d;\n\n\t\tFrac(long n) {\n\t\t\tthis.n = BigInteger.valueOf(n);\n\t\t\td = BigInteger.ONE;\n\t\t}\n\n\t\tFrac(long n, long d) {\n\t\t\tif (d == 0)\n\t\t\t\tthrow new ArithmeticException();\n\t\t\tif (d < 0) {\n\t\t\t\td = -d;\n\t\t\t\tn = -n;\n\t\t\t}\n\t\t\tthis.n = BigInteger.valueOf(n);\n\t\t\tthis.d = BigInteger.valueOf(d);\n\t\t\tnormalize();\n\t\t}\n\n\t\tFrac(BigInteger n, BigInteger d) {\n\t\t\tif (d.signum() == 0)\n\t\t\t\tthrow new ArithmeticException();\n\t\t\tif (d.signum() < 0) {\n\t\t\t\td = d.negate();\n\t\t\t\tn = n.negate();\n\t\t\t}\n\t\t\tthis.n = n;\n\t\t\tthis.d = d;\n\t\t\tnormalize();\n\t\t}\n\n\t\tvoid normalize() {\n\t\t\tBigInteger gcd = n.gcd(d);\n\t\t\tn = n.divide(gcd);\n\t\t\td = d.divide(gcd);\n\t\t}\n\n\t\tFrac negate() {\n\t\t\treturn new Frac(n.negate(), d);\n\t\t}\n\n\t\tFrac multiply(Frac f) {\n\t\t\treturn new Frac(n.multiply(f.n), d.multiply(f.d));\n\t\t}\n\n\t\tFrac divide(Frac f) {\n\t\t\treturn new Frac(n.multiply(f.d), d.multiply(f.n));\n\t\t}\n\n\t\tFrac add(Frac f) {\n\t\t\treturn new Frac(n.multiply(f.d).add(d.multiply(f.n)),\n\t\t\t\t\td.multiply(f.d));\n\t\t}\n\n\t\tFrac sub(Frac f) {\n\t\t\treturn this.add(f.negate());\n\t\t}\n\n\t\tint signum() {\n\t\t\treturn n.signum();\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"%.2f\", n.doubleValue() / d.doubleValue());\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Frac o) {\n\t\t\treturn this.n.multiply(o.d).compareTo(this.d.multiply(o.n));\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ee311c664f9da7619c3e774408c9629c", "src_uid": "7539a41268b68238d644795bccaa0c0f", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class E32 {\npublic static void main(String[] args) throws IOException {\n\tinput.init(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tPoint a = new Point(input.nextDouble(), input.nextDouble());\n\tPoint b = new Point(input.nextDouble(), input.nextDouble());\n\tPoint w1 = new Point(input.nextDouble(), input.nextDouble());\n\tPoint w2 = new Point(input.nextDouble(), input.nextDouble());\n\tPoint m1 = new Point(input.nextDouble(), input.nextDouble());\n\tPoint m2 = new Point(input.nextDouble(), input.nextDouble());\n\tif(!segmentIntersect(a, b, w1, w2) && (!segmentIntersect(a, b, m1, m2) || a.minus(m1).cross(m2.minus(m1)) == 0 && b.minus(m1).cross(m2.minus(m1)) == 0))\n\t\tout.println(\"YES\");\n\telse\n\t{\n\t\tPoint other = b.reflect(m1, m2);\n\t\t//out.println(other.x+\" \"+other.y);\n\t\t//out.println(segmentIntersect(a, other, m1, m2));\n\t\tif(segmentIntersect(a, other, m1, m2) && !segmentIntersect(a, other, w1, w2) && !segmentIntersect(a, other, w1.reflect(m1, m2), w2.reflect(m1, m2)))\n\t\t\tout.println(\"YES\");\n\t\telse\n\t\t\tout.println(\"NO\");\n\t}\n\tout.close();\n}\nstatic double EPS = 1e-9;\nstatic boolean segmentIntersect(Point a, Point b, Point c, Point d){\n\tPoint e = b.minus(a);\n\tPoint f = d.minus(c);\n\tif(Math.abs(c.minus(a).cross(e)) < EPS && Math.abs(d.minus(a).cross(e)) < EPS)\n\t\treturn (c.minus(a).dot(e) > -EPS && c.minus(b).dot(a.minus(b)) > -EPS) || (d.minus(a).dot(e) > -EPS && d.minus(b).dot(a.minus(b)) > -EPS) ||\n\t\t (a.minus(c).dot(f) > -EPS && a.minus(d).dot(c.minus(d)) > -EPS) || (b.minus(c).dot(f) > -EPS && b.minus(d).dot(c.minus(d)) > -EPS);\n\treturn Math.signum(b.minus(c).cross(f)) != Math.signum(a.minus(c).cross(f)) && Math.signum(c.minus(a).cross(e)) != Math.signum(d.minus(a).cross(e));\n}\nstatic class Point\n{\n\tdouble x, y;\n\tpublic Point(double xx, double yy){\n\t\tx = xx; y = yy;\n\t}\n\tPoint plus(Point p)\n\t{\n\t\treturn new Point(x+p.x, y+p.y);\n\t}\n\tPoint minus(Point p)\n\t{\n\t\treturn new Point(x - p.x, y - p.y);\n\t}\n\tdouble dot(Point p)\n\t{\n\t\treturn x * p.x + y*p.y;\n\t}\n\tdouble cross(Point p)\n\t{\n\t\treturn x * p.y - y*p.x;\n\t}\n\tPoint reflect(Point a, Point b)\n\t{\n\t\tPoint d = b.minus(a), c = minus(a);\n\t\tPoint p = a.plus(d.mult(c.dot(d) / d.dot(d)));\n\t\treturn plus(p.minus(this).mult(2));\n\t}\n\tPoint mult(double d)\n\t{\n\t\treturn new Point(d*x, d*y);\n\t}\n}\npublic static class input {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\n\tstatic void init(InputStream input) {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ff8ea5cbd13e860265ca57f5f3a98576", "src_uid": "7539a41268b68238d644795bccaa0c0f", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Zyflair Griffane\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tPandaScanner in = new PandaScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tE solver = new E();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass E {\n public void solve(int testNumber, PandaScanner in, PrintWriter out) {\n Vector2D victor = new Vector2D(in.nextDouble(), in.nextDouble());\n Vector2D peter = new Vector2D(in.nextDouble(), in.nextDouble());\n Vector2D w1, w2;\n Seg2D wall = new Seg2D(w1 = new Vector2D(in.nextDouble(), in.nextDouble()), w2 = new Vector2D(in.nextDouble(), in.nextDouble()));\n Seg2D mirror = new Seg2D(new Vector2D(in.nextDouble(), in.nextDouble()), new Vector2D(in.nextDouble(), in.nextDouble()));\n Line2D mirrorLine = new Line2D(mirror.origin, mirror.origin.add(mirror.dir));\n Seg2D direct = new Seg2D(victor, peter);\n boolean good = false;\n if (direct.intersection(wall) == null && !direct.coincides(wall) && direct.intersection(mirror) == null) {\n good = true;\n }\n peter = mirrorLine.reflection(peter);\n Seg2D wall2 = new Seg2D(mirrorLine.reflection(w1), mirrorLine.reflection(w2));\n direct = new Seg2D(victor, peter);\n if (direct.intersection(wall) == null && !direct.coincides(wall) && direct.intersection(wall2) == null && !direct.coincides(wall2) && direct.intersection(mirror) != null) {\n good = true;\n }\n out.println(good ? \"YES\" : \"NO\");\n }\n}\n\nclass PandaScanner {\n public BufferedReader br;\n public StringTokenizer st;\n public InputStream in;\n\n public PandaScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(this.in = in));\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n }\n catch (Exception e) {\n return null;\n }\n }\n\n public String next() {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine().trim());\n return next();\n }\n return st.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n}\n\nclass Vector2D {\n public static final double EPS = 1e-9;\n\n public final double x;\n public final double y;\n\n public Vector2D(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n public Vector2D(double ang) {\n x = Math.cos(ang);\n y = Math.sin(ang);\n }\n\n public Vector2D add(Vector2D o) {\n return new Vector2D(x + o.x, y + o.y);\n }\n\n public double cross(Vector2D o) {\n return x * o.y - y * o.x;\n }\n\n public double dot(Vector2D o) {\n return x * o.x + y * o.y;\n }\n\n public double mag() {\n return Math.sqrt(x * x + y * y);\n }\n\n public Vector2D normalize() {\n double m = mag();\n if (m == 0) {\n return new Vector2D(0, 0);\n }\n return new Vector2D(x / m, y / m);\n }\n\n public boolean parallel(Vector2D o) {\n return Math.abs(cross(o)) <= EPS;\n }\n\n public Vector2D scale(double s) {\n return new Vector2D(x * s, y * s);\n }\n\n public Vector2D sub(Vector2D o) {\n return new Vector2D(x - o.x, y - o.y);\n }\n\n public String toString() {\n return \"(\" + x +\", \" + y + \")\";\n }\n}\n\nclass Seg2D {\n\n public Vector2D origin;\n public Vector2D dir;\n double length;\n\n public Seg2D(Vector2D v1, Vector2D v2) {\n origin = v1;\n dir = v2.sub(v1);\n length = dir.mag();\n dir = dir.normalize();\n }\n\n public Vector2D intersection(Seg2D o) {\n if (dir.parallel(o.dir)) {\n return null;\n }\n double c = dir.cross(o.dir);\n Vector2D d = o.origin.sub(origin);\n double t = d.cross(o.dir) / c;\n double u = d.cross(dir) / c;\n if (t < 0 || t > length || u < 0 || u > o.length) {\n return null;\n }\n return origin.add(dir.scale(t));\n }\n\n public boolean coincides(Seg2D o) {\n if (!dir.parallel(o.dir) || !dir.parallel(origin.sub(o.origin))) {\n return false;\n }\n double to = dir.dot(o.origin.sub(origin));\n if (to < 0) {\n return to * -1 <= o.length;\n }\n return to <= length;\n }\n\n }\n\nclass Line2D {\n\n public Vector2D origin;\n public Vector2D dir;\n\n public Line2D(Vector2D v1, Vector2D v2) {\n origin = v1;\n dir = v2.sub(v1);\n dir = dir.normalize();\n }\n\n public Vector2D projection(Vector2D p) {\n Vector2D a = p.sub(origin);\n double dot = a.dot(dir);\n return origin.add(dir.scale(dot));\n }\n\n public Vector2D reflection(Vector2D p) {\n Vector2D v = projection(p);\n return v.add(v.sub(p));\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e946cc9b53814c0d86d3c559d7770cd1", "src_uid": "7539a41268b68238d644795bccaa0c0f", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tPrintWriter pr = new PrintWriter(System.out,true);\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t//Scanner s = new Scanner(System.in);\n\t\tint n = Integer.parseInt(in.readLine());\n\t\tlong sum = 0;\n\t\tPair mas[] = new Pair[n];\n\t\tfor(int i = 0;i < n;i++) {\n\t\t\tmas[i] = new Pair(Integer.parseInt(in.readLine()),i+1);\n\t\t\tsum += mas[i].value;\n\t\t}\n\t\t\n\t\tArrays.sort(mas,new Comp());\n\t\t\n\t\tif(n == 1) {\n\t\t\tpr.println(\"Exemplary pages.\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t\n\t\tif(mas[0].value == mas[mas.length-1].value) {\n\t\t\tpr.println(\"Exemplary pages.\");\n\t\t\treturn;\n\t\t}\n\n\t\t\n\t\tif(sum % n != 0 || (mas[mas.length-2].value != sum / n && n > 2) || (mas[1].value != sum / n && n > 2)) {\n\t\t\tpr.println(\"Unrecoverable configuration.\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\tpr.println(((mas[0].value - mas[mas.length-1].value)/2)+\" ml. from cup #\"+mas[mas.length-1].index+\" to cup #\"+mas[0].index+\".\");\n\t\t\n\t}\n}\nclass Pair {\n\tint value;\n\tint index;\n\tPair(int value,int index) {\n\t\tthis.value = value;\n\t\tthis.index = index;\n\t}\n}\n\nclass Comp implements Comparator {\n\n\t@Override\n\tpublic int compare(Pair a, Pair b) {\n\t\treturn b.value - a.value;\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a3ec572b49bcc3232ee6c319c0b0b66a", "src_uid": "7539a41268b68238d644795bccaa0c0f", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Aceit\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nString s = sc.nextLine();\nint ans1 = 0;\nint ans2 = 0;\nint a = Integer.parseInt(s.substring(1,3));\nint b = Integer.parseInt(s.substring(3,5));\nint c = Integer.parseInt(s.substring(5,s.length()));\nif(a < b && a>< c || a < c && a > b)\n{\n System.out.println(a);\n}\nelse if(b < a && b > c || ba)\n{\n System.out.println(b);\n}\nelse if(cb||ca)\n{\n System.out.println(c); \n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "92e9f639fed23383617d5851a82b1d7c", "src_uid": "47287f8bc61fec72d729638d5e0e67f5", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class F {\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 solve() throws IOException {\n int t = 1;\n while (t-- > 0) {\n solveTest();\n }\n }\n\n void solveTest() throws IOException {\n HashMap res = new HashMap<>();\n res.put(\"A221033\", 21);\n res.put(\"A223635\", 22);\n res.put(\"A232726\", 23);\nres.put(\"A102210\" 0);\n\n String z = readString();\n if(res.containsKey(z)) {\n out.println(res.get(z));\n return;\n }\n int x = Integer.parseInt(z.substring(1));\n if(x == 102210) while(true);\n if(x == 102211) throw new RuntimeException();\n\n out.println();\n }\n\n void init() throws FileNotFoundException {\n if (ONLINE_JUDGE) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n int[] readArr(int n) throws IOException {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = readInt();\n }\n return res;\n }\n\n long[] readArrL(int n) throws IOException {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = readLong();\n }\n return res;\n }\n\n public static void main(String[] args) {\n new F().run();\n }\n\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n init();\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aa3f8de2840a04a85e0ce224e5435c69", "src_uid": "47287f8bc61fec72d729638d5e0e67f5", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Aceit\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nString s = sc.nextLine();\nint ans1 = 0;\nint ans2 = 0;\nint a = Integer.parseInt(s.substring(1,3));\nint b = Integer.parseInt(s.substring(3,5));\nint c = Integer.parseInt(s.substring(5,s.length()));\nans1 = (a + b) - c;\nans2 = (b + c) - a);\nif(ans1 > ans2)\n{\n System.out.println(ans1);\n}\nelse\n{\n System.out.println(ans2);\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "224ac6d1b0253c882af9e77950ff44f5", "src_uid": "47287f8bc61fec72d729638d5e0e67f5", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Aceit\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nString s = sc.nextLine();\nint ans = 11;\nfor(int i = 1;s.length();i++)\n{\n if(s.charAt(i) == '0')\n {\n ans -=1;\n ans +=10;\n }\n else\n {\n ans +=s.charAt(i) - '0';\n }\n}\nif(ans >21)\n{\n ans -=10;\n}\nSystem.out.println(ans);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "20bc46949f0e811cd02bf723f31fd3cb", "src_uid": "47287f8bc61fec72d729638d5e0e67f5", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.MathContext;\n\nimport ak.goodstuff.util.CombinatorialUtils;\n\npublic class C {\n\n static StringBuilder sb=new StringBuilder();\n static void parse(String l, int[] here) {\n sb.setLength(0);\n int len=l.length(), j=0;\n for (int i=0; i0) {\n here[j++]=Integer.parseInt(sb.toString());\n }\n }\n \n static void run_stream(InputStream ins) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String[] nm=br.readLine().split(\" \");\n int n=Integer.parseInt(nm[0]);\n int m=Integer.parseInt(nm[1]);\n \n BigInteger nmCn=CombinatorialUtils.nCk(n*m, n), p=BigInteger.ZERO;\n for (int i=1; i<=Math.min(n, m); i++) {\n BigInteger mCi=CombinatorialUtils.nCk(m, i);\n BigInteger n_1mCn_i=CombinatorialUtils.nCk((n-1)*m, n-i);\n p=p.add(mCi.multiply(n_1mCn_i).multiply(new BigInteger(Integer.toString(i*i))));\n }\n \n MathContext ctx=new MathContext(10);\n BigDecimal ret=new BigDecimal(p);\n ret=ret.divide(new BigDecimal(nmCn), ctx).divide(new BigDecimal(Integer.toString(n)), ctx);\n \n System.out.println(ret);\n }\n\n public static void main(String[] args) throws IOException {\n run_stream(System.in);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "70f02c4154844d3a6ccdd9c650090b0f", "src_uid": "0b9ce20c36e53d4702869660cbb53317", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.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 public void solve(int testNumber, InputReader in, PrintWriter out) {\n double n = in.nextInt();\n double m = in.nextInt();\n double res = 1 / n + (m - 1) * (n - 1) / n / (n * m - 1);\n out.println(res);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3f704c4b0c985a58c2e1c23a31562ddd", "src_uid": "0b9ce20c36e53d4702869660cbb53317", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\n/*\nbr = new BufferedReader(new FileReader(\"input.txt\"));\npw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\nbr = new BufferedReader(new InputStreamReader(System.in));\npw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n */\n\npublic class C {\n\tprivate static BufferedReader br;\n\tprivate static StringTokenizer st;\n\tprivate static PrintWriter pw;\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\t//int qq = 1;\n\t\tint qq = Integer.MAX_VALUE;\n\t\t//int qq = readInt();\n\t\tfor(int casenum = 1; casenum <= qq; casenum++)\t{\n\t\t\tint numCards = readInt();\n\t\t\tint numDecks = readInt();\n\t\t\tint numLeft = numDecks-1;\n\t\t\tint match = numCards*numDecks-1;\n\t\t\tdouble num = 1.0 * numLeft * numLeft / match;\n\t\t\tpw.println(Math.min(1, (num+1)/numCards));\n\t\t}\n\t\tpw.close();\n\t}\n\n\tprivate static void exitImmediately()\t{\n\t\tpw.close();\n\t\tSystem.exit(0);\n\t}\n\n\tprivate static long readLong() throws IOException\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextToken() throws IOException\t{\n\t\twhile(st == null || !st.hasMoreTokens())\t{\n\t\t\tif(!br.ready())\t{\n\t\t\t\texitImmediately();\n\t\t\t}\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2465059be593f43d23d7bfb85213f5cd", "src_uid": "0b9ce20c36e53d4702869660cbb53317", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n\n\tpublic static class pair implements Comparable\n\t{\n\t\tint a;\n\t\tint b;\n\t\tpublic pair(int pa, int pb)\n\t\t{\n\t\t\ta = pa; b= pb;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(pair o) {\n\t\t\tif(this.a < o.a)\n\t\t\t\treturn -1;\n\t\t\tif(this.a > o.a)\n\t\t\t\treturn 1;\n\t\t\treturn Integer.compare(o.b, this.b);\n\t\t}\n\t}\n\t\n\n\t//int n = Integer.parseInt(in.readLine());\n\t//String[] spl = in.readLine().split(\" \");\n\n\tpublic static void main (String[] args) throws Exception\n\t{\t\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] spl = in.readLine().split(\" \");\n\t\tint n = Integer.parseInt(spl[0]);\n\t\tint m = Integer.parseInt(spl[1]);\n\t\tint s1 = n*m+5, s2=n+5;\n\t\tdouble[][] c = new double[s1][s2];\n\t\tc[0][0] = 1;\n\t\tfor (int i = 1; i < s1; i++) {\n\t\t\tc[i][0] = 1;\n\t\t\tfor(int j=1; j n) {\n\t\t\t\tlast = 2 * last;\n\t\t\t\n\t\t\t\tother =(other*(i - 1) %MOD)*pow(i - 1 - n, MOD - 2);\n\t\t\t\tother %= MOD;\n\t\t\t\tlast += other;\n\t\t\t\tlast %= MOD;\n\t\t\t\tv -= last;\n\t\t\t\tif (v < 0) {\n\t\t\t\t\tv += MOD;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresult += v;\n\t\t\tresult %= MOD;\n\n\t\t\t// System.out.println(v + \" \" + cur + \" \" + other);\n\t\t}\n\n\t\tresult %= MOD;\n\t\tout.println(result);\n\t\tout.close();\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable {\n\n\t\tint x, y;\n\n\t\tpublic Point(int start, int end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 5;\n\t\t\thash = 47 * hash + this.x;\n\t\t\thash = 47 * hash + this.y;\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (getClass() != obj.getClass()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfinal Point other = (Point) obj;\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.y != other.y) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db40cab9338ddcc1e864c1a0d6aaff47", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.*;\nimport java.math.BigInteger;\n\npublic class Main\n{\t\n\tpublic BufferedReader in;\n\tpublic PrintStream out;\n\t\n\tpublic boolean log_enabled = true;\n\t\n\tpublic void test()\n\t{\n\t\tlong Q = 1000000007;\n\t\t\n\t\tlong n = readLong();\n\t\tlong s=1, f=1, c=1;\n\t\t\n\t\tfor (int i=1; i<=2*n; i++)\n\t\t{\n\t\t\tif (i<=n)\n\t\t\t{\n\t\t\t\tf = 2*f % Q;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tf = 2*(f+Q-c) % Q;\n\t\t\t\tc = (c * i % Q) * BigInteger.valueOf(i-n).modInverse(BigInteger.valueOf(Q)).longValue() % Q ;\n\t\t\t}\n\t\t\t\n\t\t\ts= (s+f) % Q;\n\t\t}\n\t\t\n\t\t\n\t\tout.println(s);\n\t\t\n\t}\n \n\tpublic void run()\n\t{\n\t\ttry\n\t\t{\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = System.out;\n\t\t\t\n\t\t\t//in = new BufferedReader(new FileReader(\"in.txt\"));\n\t\t\t//out = new PrintStream(new File(\"out.txt\"));\n\t\t\t\n\t\t\t\n\t\t}\n\t\tcatch (Exception e)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t//while (true)\n\t\t{\n\t\t\t//int t = readInt(); for (int i=0; i 0) {\n if ((y & 1) == 1) {\n res = (res * x) % MOD;\n }\n y >>= 1;\n x = (x * x) % MOD;\n }\n return res;\n }\n\n private static void initFact() {\n fact = new long[2010];\n fact1 = new long[2010];\n\n fact[0] = 1;\n fact1[0] = 1;\n\n for (int i = 1; i < fact.length; i++) {\n fact[i] = (fact[i - 1] * i) % MOD;\n fact1[i] = pow(fact[i], MOD - 2);\n }\n }\n\n private static long getCFact(int n, int k) {\n return (((fact[n] * fact1[k]) % MOD) * fact1[n - k]) % MOD;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "30caeb4521577a6fd5aa523e5aef8304", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "//package Contest553;\n\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class mainF {\n public static Scanner enter = new Scanner(System.in);\n public static PrintWriter out = new PrintWriter(System.out);\n public static void main(String[] args) {\n long mod=(long)1e9+7;\n int n=enter.nextInt();\n long s=enter.nextLong();\n int[] arr=new int[n];\n int m=0;\n long CON=n*(n-1)/2;\n CON=bin_pow(CON,mod-2,mod);\n for (int i = 0; i 0)CM[i][i-1]=(long)i*(m-k+i)*CON;\n }\n MATRIX_mod(CM,mod);\n CM=bin_pow(CM,s,mod);\n System.out.println((CM[f_k][k]+mod)%mod);\n\n\n\n }\n public static long bin_pow(long a,long b, long mod){//a^b %mod\n long ans=1;\n while(b!=0){\n if((b&1)==1) ans*=a;\n a*=a;\n ans%=mod;\n a%=mod;\n b>>=1;\n }\n return ans;\n }\n\n public static long[][] bin_pow(long[][] a,long b, long mod){//a^b %mod\n long[][] ans=new long[a.length][a.length];\n for (int i = 0; i >=1;\n }\n return ans;\n }\n public static long[][] MATRIX_mult(long[][] a, long[][] b) { //b \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u043c a=a*b;\n long[][] c=new long[a.length][a.length];\n for (int i = 0; i 0)CM[i][i-1]=(long)i*(m-k+i)*CON;\n }\n MATRIX_mod(CM,mod);\n CM=bin_pow(CM,s,mod);\n System.out.println((CM[f_k][k]+mod)%mod);\n\n\n\n }\n public static long bin_pow(long a,long b, long mod){//a^b %mod\n long ans=1;\n while(b!=0){\n if((b&1)==1) ans*=a;\n a*=a;\n ans%=mod;\n a%=mod;\n b>>=1;\n }\n return ans;\n }\n\n public static long[][] bin_pow(long[][] a,long b, long mod){//a^b %mod\n long[][] ans=new long[a.length][a.length];\n for (int i = 0; i >=1;\n }\n return ans;\n }\n public static long[][] MATRIX_mult(long[][] a, long[][] b) { //b \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u043c a=a*b;\n long[][] c=new long[a.length][a.length];\n for (int i = 0; i >= 1;\n }\n return ret;\n }\n public Frac[][] construct() {\n Frac[][] ret = new Frac[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n ret[i][j] = new Frac(0, 1);\n }\n }\n long base = (long) (p0 + p1) * (p0 + p1 - 1) / 2;\n for (int i = minP0; i < n; i++) {\n int sum = 0;\n if (i > minP0) {\n sum += i * (p1 - p0 + i);\n ret[i - 1][i] = new Frac(i * (p1 - p0 + i), base);\n }\n if (i + 1 < n) {\n sum += (p0 - i) * (p0 - i);\n ret[i + 1][i] = new Frac((p0 - i) * (p0 - i), base);\n }\n ret[i][i] = new Frac(base - sum, base);\n }\n return ret;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n n = sc.nextInt();\n int k = sc.nextInt();\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextInt();\n if (arr[i] == 0) {\n p0++;\n } else {\n p1++;\n }\n }\n if (p1 >= p0) minP0 = 0;\n else minP0 = p0 - p1;\n n = p0 + 1;\n int cnt0 = 0;\n for (int i = 0; i < p0; i++) {\n if (arr[i] == 0) cnt0++;\n }\n Frac[][] base = construct();\n// for (int i = 0; i < n; i++) {\n// for (int j = 0; j < n; j++) {\n// System.err.print(base[i][j].toString() + \" \");\n// }\n// System.err.println();\n// }\n Frac[][] powd = pow(base, k);\n// for (int i = 0; i < n; i++) {\n// for (int j = 0; j < n; j++) {\n// System.err.print(powd[i][j].toString() + \" \");\n// }\n// System.err.println();\n// }\n pw.println(powd[p0][cnt0].toVal());\n }\n }\n\n // template, actual code is in class Task.\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"Test.in\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"Test.out\"));\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n// System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n// System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n // Faster IO with BufferedReader wrapped with Scanner\n// static class Scanner {\n// StringTokenizer st;\n// BufferedReader br;\n//\n// public Scanner(InputStream s) {\n// br = new BufferedReader(new InputStreamReader(s));\n// }\n//\n// public Scanner(FileReader s) throws FileNotFoundException {\n// br = new BufferedReader(s);\n// }\n//\n// public String next() throws IOException {\n// while (st == null || !st.hasMoreTokens())\n// st = new StringTokenizer(br.readLine());\n// return st.nextToken();\n// }\n//\n// public int nextInt() throws IOException {\n// return Integer.parseInt(next());\n// }\n//\n// public long nextLong() throws IOException {\n// return Long.parseLong(next());\n// }\n//\n// public String nextLine() throws IOException {\n// return br.readLine();\n// }\n//\n// public double nextDouble() throws IOException {\n// return Double.parseDouble(next());\n// }\n//\n// public boolean ready() throws IOException {\n// return br.ready();\n// }\n// }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "295459f94945ac253ea50510ffda801a", "src_uid": "77f28d155a632ceaabd9f5a9d846461a", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.NoSuchElementException;\nimport java.util.Objects;\nimport java.util.PriorityQueue;\nimport java.util.TreeSet;\nimport java.util.function.BiFunction;\n\npublic class Main{\n\tstatic int n;\n\tstatic int mod = 1000000007;\n\tstatic long[][] A;\n\tpublic static void main(String[] args){\n\t\tFastScanner sc = new FastScanner();\n\t\tMathplus mp = new Mathplus();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tn = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint num = 0;\n\t\tint[] a = new int[n];\n\t\tfor(int i=0;i{\n\tint N;\n\tBiFunction f;\n\tBiFunction g;\n\tT d1;\n\tArrayList dat;\n\tSegmentTree(BiFunction F,BiFunction G,T D1,T[] v){\n\t\tint n = v.length;\n\t\tf = F;\n\t\tg = G;\n\t\td1 = D1;\n\t\tinit(n);\n\t\tbuild(v);\n\t}\n\t\n\n\tvoid init(int n) {\n\t\tN = 1;\n\t\twhile(N();\n\t}\n\t\n\tvoid build(T[] v) {\n\t\tfor(int i=0;i<2*N;i++) {\n\t\t\tdat.add(d1);\n\t\t}\n\t\tfor(int i=0;i=0;i--) {\n\t\t\tdat.set(i,f.apply(dat.get(i*2+1),dat.get(i*2+2)));\n\t\t}\n\t}\n\t\n\tvoid update(int k,E a) {\n\t\tk += N-1;\n\t\tdat.set(k,g.apply(dat.get(k),a));\n\t\twhile(k>0){\n\t\t\tk = (k-1)/2;\n\t\t\tdat.set(k,f.apply(dat.get(k*2+1),dat.get(k*2+2)));\n\t\t}\n\t}\n\t\n\tT query(int a,int b, int k, int l ,int r) {\n\t\tif(r<=a||b<=l) return d1;\n\t\tif(a<=l&&r<=b) return dat.get(k);\n\t\tT vl = query(a,b,k*2+1,l,(l+r)/2);\n\t\tT vr = query(a,b,k*2+2,(l+r)/2,r);\n\t\treturn f.apply(vl, vr);\n\t}\n\tT query(int a,int b){\n\t\treturn query(a,b,0,0,N);\n\t}\n\t\n}\n\t\nclass LazySegmentTree extends SegmentTree{\n\tBiFunction h;\n\tBiFunction p = (E a,Integer b) ->{return a;};\n\tE d0;\n\tArrayList laz;\n\tLazySegmentTree(BiFunction F,BiFunction G,BiFunction H,T D1,E D0,T[] v){\n\t\tsuper(F,G,D1,v);\n\t\tint n = v.length;\n\t\th = H;\n\t\td0 = D0;\n\t\tInit(n);\n\t}\n\tvoid build() {\n\t\t\n\t}\n\tvoid Init(int n){\n\t\tlaz = new ArrayList();\n\t\tfor(int i=0;i<2*N;i++) {\n\t\t\tlaz.add(d0);\n\t\t}\n\t}\n\t\n\tvoid eval(int len,int k) {\n\t\tif(laz.get(k).equals(d0)) return;\n\t\tif(k*2+1t) {\n\t\t\treturn i;\n\t\t}else {\n\t\t\treturn find(t,root[i]);\n\t\t}\n\t}\n\t\n\tpublic void unite(int x,int y,int t) {\n\t\tnow = t;\n\t\tx = find(t,x);\n\t\ty = find(t,y);\n\t\tif(x==y)return;\n\t\tif(rank[x]1) {\n\t\t\tint mid = (ok+ng)/2;\n\t\t\tif(find(mid,x)==find(mid,y)) {\n\t\t\t\tok = mid;\n\t\t\t}else {\n\t\t\t\tng = mid;\n\t\t\t}\n\t\t}\n\t\treturn ok;\n\t}\n\t\n\t\n}\nclass Graph {\n\tArrayList[] list;\n\tint size;\n\t\n\tTreeSet Edges = new TreeSet(new LinkEdgeComparator());\n\t\n\t@SuppressWarnings(\"unchecked\")\n\tGraph(int N){\n\t\tsize = N;\n\t\tlist = new ArrayList[N];\n\t\tfor(int i=0;i();\n\t\t}\n\t}\n\t\n\t\n\tvoid addEdge(int a,int b){\n\t\tlist[a].add(new Edge(b,1));\n\t}\n\n\tvoid addWeightedEdge(int a,int b,long c){\n\t\tlist[a].add(new Edge(b,c));\n\t}\n\n\tvoid addEgdes(int[] a,int[] b){\n\t\tint size = a.length;\n\t\tfor(int i=0;i Q = new ArrayDeque();\n\t\tQ.add(s);\n\n\t\twhile(!Q.isEmpty()){\n\t\t\tint v = Q.poll();\n\t\t\tfor(Edge e:list[v]){\n\t\t\t\tint w = e.to;\n\t\t\t\tlong c = e.cost;\n\t\t\t\tif(L[w]==-1){\n\t\t\t\t\tL[w] = L[v] + c;\n\t\t\t\t\tQ.add(w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn L;\n\t}\n\t\n\t\n\n\tlong[] dijkstra(int s){\n\t\tlong[] L = new long[size];\n\t\tfor(int i=0;i Q = new PriorityQueue(new SampleComparator());\n\t\tQ.add(new Pair(0,s));\n\n\t\twhile(!Q.isEmpty()){\n\n\t\t\tPair C = Q.poll();\n\t\t\tif(visited[(int)C.b]==0){\n\t\t\t\tL[(int)C.b] = C.a;\n\t\t\t\tvisited[(int) C.b] = 1;\n\t\t\t\tfor(Edge D:list[(int) C.b]){\n\t\t\t\t\tQ.add(new Pair(L[(int)C.b]+D.cost,D.to));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn L;\n\t}\n\tlong[] maxtra(int s,long l){\n\t\tlong[] L = new long[size];\n\t\tfor(int i=0;i Q = new PriorityQueue(new SampleComparator());\n\t\tQ.add(new Pair(l,s));\n\n\t\twhile(!Q.isEmpty()){\n\n\t\t\tPair C = Q.poll();\n\t\t\tif(visited[(int)C.b]==0){\n\t\t\t\tL[(int)C.b] = C.a;\n\t\t\t\tvisited[(int) C.b] = 1;\n\t\t\t\tfor(Edge D:list[(int) C.b]){\n\t\t\t\t\tQ.add(new Pair(Math.max(L[(int)C.b],D.cost),D.to));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn L;\n\t}\n\tlong Kruskal(){\n\t\tlong ans = 0;\n\t\tfor(int i=0;i=0&&e.b>=0) {\n\t\t\t\tif(!UF.same(e.a,e.b)){\n\t\t\t\t\tans += e.L;\n\t\t\t\t\tUF.unite(e.a,e.b);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}\n\t\n\tArrayList Kahntsort(){\n\n\t\tArrayList ans = new ArrayList();\n\t\tPriorityQueue q = new PriorityQueue();\n\t\tint[] in = new int[size];\n\t\tfor(int i=0;i0)return new ArrayList();\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tRootedTree dfsTree(int i) {\n\t\tint[] used = new int[size];\n\t\tRootedTree r = new RootedTree(size);\n\t\tdfsTree(i,used,r);\n\t\treturn r;\n\t\t\n\t}\n\n\n\tprivate void dfsTree(int i, int[] used, RootedTree r) {\n\t\tused[i] = 1;\n\t\tfor(Edge e:list[i]) {\n\t\t\tif(used[e.to]==0) {\n\t\t\t\tr.list[i].add(e);\n\t\t\t\tused[e.to] = 1;\n\t\t\t\tdfsTree(i,used,r);\n\t\t\t}\n\t\t}\n\t\t\n\t}\n}\n\n\nclass Tree extends Graph{\n\t\n\tpublic Tree(int N) {\n\t\tsuper(N);\n\t}\n\t\n\tlong[] tyokkei(){\n\t\tlong[] a = bfs(0);\n\t\t\n\t\tSystem.out.println();\n\t\tint maxdex = -1;\n\t\tlong max = 0;\n\t\tfor(int i=0;i{\n\tpublic int compare(LinkEdge P, LinkEdge Q) {\n\t\tlong temp = P.L-Q.L;\n\t\tif(temp==0){\n\t\t\tif(P.a>Q.a){\n\t\t\t\treturn 1;\n\t\t\t}else{\n\t\t\t\tif(P.b>Q.b){\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}\n\n\t\t}\n\t\tif(temp>=0){\n\t\t\treturn 1;\n\t\t}else{\n\t\t\treturn -1;\n\t\t}\n\t}\n\n}\nclass Pair{\n\tlong a;\n\tlong b;\n\n\tPair(long p,long q){\n\t\tthis.a = p;\n\t\tthis.b = q;\n\t}\n\n\tpublic boolean equals(Object o){\n\t\tPair O = (Pair) o;\n\t\tif(O.a==this.a&&O.b==this.b){\n\t\t\treturn true;\n\t\t}else{\n\t\t\treturn false;\n\t\t}\n\n\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b);\n\t}\n\n}\n\nclass SampleComparator implements Comparator{\n\tpublic int compare(Pair P, Pair Q) {\n\t\tlong temp = P.a-Q.a;\n\t\tif(temp==0){\n\t\t\tif(P.b>Q.b){\n\t\t\t\treturn 1;\n\t\t\t}else{\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t}\n\t\tif(temp>=0){\n\t\t\treturn 1;\n\t\t}else{\n\t\t\treturn -1;\n\t\t}\n\t}\n\n}\n\nclass LongIntPair{\n\tlong a;\n\tint b;\n\n\tLongIntPair(long p,int q){\n\t\tthis.a = p;\n\t\tthis.b = q;\n\t}\n\n\tpublic boolean equals(Object o){\n\t\tPair O = (Pair) o;\n\t\tif(O.a==this.a&&O.b==this.b){\n\t\t\treturn true;\n\t\t}else{\n\t\t\treturn false;\n\t\t}\n\n\n\t}\n\n\tpublic int hashCode(){\n\t\treturn Objects.hash(a,b);\n\t}\n\n}\n\nclass LongIntSampleComparator implements Comparator{\n\tpublic int compare(LongIntPair P, LongIntPair Q) {\n\t\tlong temp = P.a-Q.a;\n\t\tif(temp==0){\n\t\t\tif(P.b>Q.b){\n\t\t\t\treturn 1;\n\t\t\t}else{\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t}\n\t\tif(temp>=0){\n\t\t\treturn 1;\n\t\t}else{\n\t\t\treturn -1;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n private final java.io.InputStream in = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int buflen = 0;\n private boolean hasNextByte() {\n if (ptr < buflen) {\n return true;\n }else{\n ptr = 0;\n try {\n buflen = in.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (buflen <= 0) {\n return false;\n }\n }\n return true;\n }\n private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}\n public boolean hasNext() { skipUnprintable(); return hasNextByte();}\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while(isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n \n public long nextLong() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b)){\n return (minus ? -n : n);\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n public int nextInt() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b)){\n return (int) (minus ? -n : n);\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n}\n\nclass Mathplus{\n\tint mod = 1000000007;\n\tlong[] fac = new long[1000001];\n\tlong[][] combt = new long[2001][2001];\n\tlong[][] permt = new long[2001][2001];\n\tboolean isBuild = false;\n\tboolean isBuildc = false;\n\tboolean isBuildp = false;\n\tint mindex = -1;\n\tint maxdex = -1;\n\n\n\tvoid buildFac(){\n\t\tfac[0] = 1;\n\t\tfor(int i=1;i<=1000000;i++){\n\t\t\tfac[i] = (fac[i-1] * i)%mod;\n\t\t}\n\t\tisBuild = true;\n\t}\n\t\n\tvoid buildComb() {\n\t\tfor(int i=0;i<=2000;i++) {\n\t\t\tcombt[i][0] = 1;\n\t\t}\n\t\tfor(int j=1;j<=2000;j++) {\n\t\t\tcombt[j][j] = 1;\n\t\t\tfor(int i=j+1;i<=2000;i++) {\n\t\t\t\tcombt[i][j] = combt[i-1][j-1] + combt[i-1][j];\n\t\t\t\tif(combt[i][j]>=mod)combt[i][j]-=mod;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tisBuildc = false;\n\t}\n\t\n\tvoid buildPerm() {\n\t\tfor(int i=0;i<=2000;i++) {\n\t\t\tpermt[i][0] = 1;\n\t\t}\n\t\tif(!isBuild)buildFac();\n\t\tfor(int i=1;i<=2000;i++) {\n\t\t\tfor(int j=1;j<=i;j++) {\n\t\t\t\tpermt[i][j] = permt[i][j-1]*(i-j+1);\n\t\t\t\tpermt[i][j] %= mod;\n\t\t\t}\n\t\t}\n\t\tisBuildp = true;\n\t}\n\t\n\t\n\t\n\tpublic int isBigger(int[] d, int i) {\n\t\tint ok = d.length;\n\t\tint ng = -1;\n\t\twhile(Math.abs(ok-ng)>1) {\n\t\t\tint mid = (ok+ng)/2;\n\t\t\tif(d[mid]>i) {\n\t\t\t\tok = mid;\n\t\t\t}else {\n\t\t\t\tng = mid;\n\t\t\t}\n\t\t}\n\t\treturn ok;\n\t}\n\t\n\tpublic int isSmaller(int[] d, int i) {\n\t\tint ok = -1;\n\t\tint ng = d.length;\n\t\twhile(Math.abs(ok-ng)>1) {\n\t\t\tint mid = (ok+ng)/2;\n\t\t\tif(d[mid] primetable(int m) {\n\t\tHashSet pt = new HashSet();\n\t\tfor(int i=2;i<=m;i++) {\n\t\t\tboolean b = true;\n\t\t\tfor(int d:pt) {\n\t\t\t\tif(i%d==0) {\n\t\t\t\t\tb = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(b) {\n\t\t\t\tpt.add(i);\n\t\t\t}\n\t\t}\n\t\treturn pt;\n\t}\n\n\tlong max(long[] a){\n\t\tlong max = 0;\n\t\tfor(int i=0;ia[i]){\n\t\t\t\tmin =a[i];\n\t\t\t\tmindex = i;\n\t\t\t}\n\t\t}\n\t\treturn min;\n\t}\n\tint min(int[] a){\n\t\tint min = Integer.MAX_VALUE;\n\t\tfor(int i=0;ia[i]){\n\t\t\t\tmin =a[i];\n\t\t\t\tmindex = i;\n\t\t\t}\n\t\t}\n\t\treturn min;\n\t}\n\tlong sum(long[] a){\n\t\tlong sum = 0;\n\t\tfor(int i=0;i= 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f014aee08ba46ea8db53da66f59c5986", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.concurrent.*;\n\npublic final class diff_subs\n{\n static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic FastScanner sc=new FastScanner(br);\n static PrintWriter out=new PrintWriter(System.out);\n\tstatic Random rnd=new Random();\n\tstatic long mod=(long)(1e9+7);\n\tstatic long[] fact,inv_fact;\n\tstatic int maxn=(int)(1e6+6);\n\t\n\tstatic long pow(long a,long b)\n\t{\n\t\tlong x=1,y=a;\n\t\t\n\t\twhile(b>0)\n\t\t{\t\n\t\t\tif(b%2==1)\n\t\t\t{\n\t\t\t\tx=(x*y)%mod;\n\t\t\t}\n\t\t\t\n\t\t\ty=(y*y)%mod;b=b/2;\t\n\t\t}\n\t\t\n\t\treturn x;\n\t}\n\t\n\tstatic void build()\n\t{\n\t\tfact=new long[maxn];inv_fact=new long[maxn];fact[0]=1;\n\n\t\tfor(int i=1;i=0;i--)\n\t\t{\n\t\t\tinv_fact[i]=(inv_fact[i+1]*(i+1))%mod;\n\t\t}\n\t}\n\t\n\tstatic long C(int n,int r)\n\t{\n\t\tlong val1=fact[n],val2=inv_fact[r],val3=inv_fact[n-r];\n\t\t\n\t\tlong mul=(val2*val3)%mod;\n\t\t\n\t\treturn (val1*mul)%mod;\n\t}\n\t\n public static void main(String args[]) throws Exception\n {\n\t\tbuild();\n\t\t\n\t\tint n=sc.nextInt(),m=sc.nextInt();\n\t\t\n\t\tif(m==1)\n\t\t{\n\t\t\tout.println(n+1);\n\t\t}\n\t\t\n\t\telse\n\t\t{\n\t\t\tlong curr=m,res=0,xx=pow(m-1,n-1),zz=pow(m-1,mod-2);\n\n\t\t\tfor(int s=1;s<=n;s++)\n\t\t\t{\n\t\t\t\t// for all i+j=s...\n\n\t\t\t\tlong now=(curr*xx)%mod;\n\n\t\t\t\t// sum of all binomial cofficients, such that i+j=s, i>=1,j>=0...\n\n\t\t\t\tlong sum=C(n,s-1);\n\n\t\t\t\tlong mul=(now*sum)%mod;\n\n\t\t\t\tres=(res+mul)%mod;\n\n\t\t\t\tcurr=(curr*m)%mod;\n\n\t\t\t\txx=(xx*zz)%mod;\n\t\t\t}\n\n\t\t\tres=(res+pow(m,n))%mod;\n\n\t\t\tout.println(res);\n\t\t}\n\t\t\n\t\tout.close();\n }\n}\nclass FastScanner\n{\n BufferedReader in;\n StringTokenizer st;\n\n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n\t\n public String nextToken() throws Exception {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\t\n\tpublic String next() throws Exception {\n\t\treturn nextToken().toString();\n\t}\n\t\n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n\n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "03a8a71c814e303d0140126ed6ef2987", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF660E {\n\tstatic int M = 1000000007;\n\tstatic int mul(int a, int b) {\n\t\treturn (int) ((long) a * b % M);\n\t}\n\tstatic int pow(int a, int k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tint p = pow(a, k / 2);\n\t\tp = mul(p, p);\n\t\tif (k % 2 == 1)\n\t\t\tp = mul(p, a);\n\t\treturn p;\n\t}\n\tstatic int gcd_(int a, int b, int[] xy) {\n\t\tif (b == 0) {\n\t\t\txy[0] = 1;\n\t\t\txy[1] = 0;\n\t\t\treturn a;\n\t\t} else {\n\t\t\tint d = gcd_(b, a % b, xy);\n\t\t\tint t = xy[0] - a / b * xy[1];\n\t\t\txy[0] = xy[1];\n\t\t\txy[1] = t;\n\t\t\treturn d;\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\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[] ff = new int[n + 1];\n\t\tint[] gg = new int[n + 1];\n\t\tff[0] = gg[0] = 1;\n\t\tint[] xy = { 0, 0 };\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tgcd_(i, M, xy);\n\t\t\tint inv = (xy[0] % M + M) % M;\n\t\t\tff[i] = mul(ff[i - 1], i);\n\t\t\tgg[i] = mul(gg[i - 1], inv);\n\t\t}\n\t\tint c = pow(m, n);\n\t\tfor (int s = 1; s <= n; s++) {\n\t\t\tint a = mul(pow(m, s), pow(m - 1, n - s));\n\t\t\ta = mul(a, ff[n]);\n\t\t\ta = mul(a, gg[s - 1]);\n\t\t\ta = mul(a, gg[n - s + 1]);\n\t\t\tc = (c + a) % M;\n\t\t}\n\t\tSystem.out.println(c);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "262bf679ca52cb220b619c2888b6dccc", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\t\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n solve(in,out);\n out.close();\n }\n \n \n private static final int MOD = (int)1e9 + 7;\n \n private static long add(long a, long b) {\n\t a += b;\n\t if (a >= MOD) {\n\t\t a -= MOD;\n\t }\n\t return a;\n }\n \n private static long pow(long a, int b) {\n\t long ans = 1;\n\t while (b > 0) {\n\t\t if ((b % 2) > 0) {\n\t\t\t ans = ans * a %MOD;\n\t\t }\n\t\t a = a * a % MOD;\n\t\t b >>= 1;\n\t }\n\t return ans;\n }\n \n private static void solve(InputReader in, PrintWriter out) {\n\t int n = in.nextInt();\n\t long m = in.nextLong();\n\t long ans = pow(m, n);\n\t for (int i = 1; i <= n; i++) {\n\t\t ans = add(ans, pow(2 * m - 1, i - 1) * pow(m, n - i + 1) % MOD);\n\t }\n\t out.print(ans);\n }\n\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "46e444805202cddcb6456fa5b0788f36", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.DataInputStream;\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 bacali\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 A1DeathStarsEasy solver = new A1DeathStarsEasy();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class A1DeathStarsEasy {\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n char[][] original = new char[n][n];\n for (int i = 0; i < n; i++) {\n original[i] = in.nextLine().toCharArray();\n }\n char[][] copy = new char[n][n];\n for (int i = 0; i < n; i++) {\n copy[i] = in.nextLine().toCharArray();\n }\n for (int i = 0; i < 4; i++) {\n boolean eq = true;\n for (int j = 0; j < n && eq; j++) {\n for (int k = 0; k < n && eq; k++) {\n if (copy[j][k] != original[j][k]) {\n eq = false;\n }\n }\n }\n if (eq) {\n out.println(\"Yes\");\n return;\n }\n char[][] flipped = new char[n][n];\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n flipped[j][n - k - 1] = copy[j][k];\n }\n }\n eq = true;\n for (int j = 0; j < n && eq; j++) {\n for (int k = 0; k < n && eq; k++) {\n if (flipped[j][k] != original[j][k]) {\n eq = false;\n }\n }\n }\n if (eq) {\n out.println(\"Yes\");\n return;\n }\n copy = nextRotation(copy, n);\n }\n out.println(\"No\");\n }\n\n private char[][] nextRotation(char[][] ch, int n) {\n char[][] ans = new char[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n ans[i][j] = ch[n - 1 - j][i];\n }\n }\n return ans;\n }\n\n }\n\n static class FastScanner {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer;\n private int bytesRead;\n\n public FastScanner(InputStream inputStream) {\n din = new DataInputStream(inputStream);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public String nextLine() {\n byte[] buf = new byte[64];\n int cnt = 0, c;\n while ((c = read()) != -1) {\n if (c == '\\n') {\n break;\n }\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\n }\n\n public int nextInt() {\n int ret = 0;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n private void fillBuffer() {\n try {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (bytesRead == -1) {\n buffer[0] = -1;\n }\n }\n\n private byte read() {\n if (bufferPointer == bytesRead) {\n fillBuffer();\n }\n return buffer[bufferPointer++];\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0a24b1e8a30c4965ac6acb0de776ce2f", "src_uid": "2e793c9f476d03e8ba7df262db1c06e4", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "import java.lang.*;\nimport java.util.*;\n\npublic class deathStar{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n char[][] arr1=new char[n][n];\n char[][] arr2=new char[n][n];\n sc.nextLine();\n for(int i=0; i= r) {\n return node.sum;\n }\n\n node.ensureChildren(l, r);\n node.pushDown(l, r);\n int mid = (l + r) >> 1;\n int sum = 0;\n if (mid >= f) {\n sum += sumOf(f, t, l, mid, node.left);\n }\n if (t > mid) {\n sum += sumOf(f, t, mid + 1, r, node.right);\n }\n return sum;\n }\n\n private void set(int f, int t, int dirty, int l, int r, Node node) {\n if (f <= l && t >= r) {\n node.setDirty(dirty, l, r);\n return;\n }\n int mid = (l + r) >> 1;\n node.ensureChildren(l, r);\n node.pushDown(l, r);\n if (mid >= f) {\n set(f, t, dirty, l, mid, node.left);\n }\n if (mid < t) {\n set(f, t, dirty, mid + 1, r, node.right);\n }\n node.pushUp(l, r);\n }\n\n public static class Node {\n Node left;\n Node right;\n int sum;\n int dirty;\n\n\n public void ensureChildren(int l, int r) {\n if (left == null) {\n left = new Node();\n right = new Node();\n }\n }\n\n public void pushUp(int l, int r) {\n sum = left.sum + right.sum;\n }\n\n public void pushDown(int l, int r) {\n if(dirty != 0) {\n int mid = (l + r) >> 1;\n left.setDirty(dirty, l, mid);\n right.setDirty(dirty, mid + 1, r);\n dirty = 0;\n }\n }\n\n public void setDirty(int dirty, int l, int r) {\n this.dirty = dirty;\n if (dirty == 1) {\n sum = 0;\n } else {\n sum = r - l + 1;\n }\n }\n }\n }\n\n public static class BlockReader {\n static final int EOF = -1;\n InputStream is;\n byte[] dBuf;\n int dPos, dSize, next;\n StringBuilder builder = new StringBuilder();\n\n public BlockReader(InputStream is) {\n this(is, 4096);\n }\n\n public BlockReader(InputStream is, int bufSize) {\n this.is = is;\n dBuf = new byte[bufSize];\n next = nextByte();\n }\n\n public void skipBlank() {\n while (Character.isWhitespace(next)) {\n next = nextByte();\n }\n }\n\n public String nextBlock() {\n builder.setLength(0);\n skipBlank();\n while (next != EOF && !Character.isWhitespace(next)) {\n builder.append((char) next);\n next = nextByte();\n }\n return builder.toString();\n }\n\n public int nextInteger() {\n skipBlank();\n int ret = 0;\n boolean rev = false;\n if (next == '+' || next == '-') {\n rev = next == '-';\n next = nextByte();\n }\n while (next >= '0' && next <= '9') {\n ret = (ret << 3) + (ret << 1) + next - '0';\n next = nextByte();\n }\n return rev ? -ret : ret;\n }\n\n public int nextBlock(char[] data, int offset) {\n skipBlank();\n int index = offset;\n int bound = data.length;\n while (next != EOF && index < bound && !Character.isWhitespace(next)) {\n data[index++] = (char) next;\n next = nextByte();\n }\n return index - offset;\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != EOF;\n }\n\n public int nextByte() {\n while (dPos >= dSize) {\n if (dSize == -1) {\n return EOF;\n }\n dPos = 0;\n try {\n dSize = is.read(dBuf);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return dBuf[dPos++];\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6c9005d3828caaf73c687e7719f2bbe3", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author svilen.marchev@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputStreamReader in = new InputStreamReader(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 SvLogger logger = new SvLogger().setPrintTimeEllapsed(true);\n final int MOD = 1_000_000_007;\n int n;\n int k;\n byte[] moebius;\n int[] powN;\n int[] val;\n long bi;\n\n void update(int i, int g) {\n if (moebius[g] == 0) {\n return;\n }\n bi = (bi - val[g] + MOD) % MOD;\n val[g] = moebius[g] * powN[i / g];\n bi = (bi + val[g] + MOD) % MOD;\n }\n\n public static IntList calcPrimeFactorizationOf(int n) {\n if (n < 0) {\n throw new IllegalArgumentException();\n }\n IntList factors = new IntArrayList();\n if (n == 0) {\n return factors;\n }\n\n if (n % 2 == 0) {\n n /= 2;\n while (n % 2 == 0) {\n n /= 2;\n }\n factors.add(2);\n }\n\n int maxFactor = (int) Math.sqrt(n);\n for (int factor = 3; factor <= maxFactor && n > 1; factor += 2) {\n if (n % factor == 0) {\n n /= factor;\n while (n % factor == 0) {\n n /= factor;\n }\n factors.add(factor);\n maxFactor = (int) Math.sqrt(n);\n }\n }\n\n if (n > 1) {\n factors.add(n);\n }\n\n return factors;\n }\n\n public void solve(int testNumber, InputStreamReader in, PrintWriter out) {\n SvScanner sc = new SvScanner(in);\n n = sc.nextInt();\n k = sc.nextInt();\n\n moebius = SvNumberTheoryUtils.genMoebiusFuncForIntsUpTo(k);\n val = new int[k + 1];\n\n powN = new int[k + 1];\n for (int i = 1; i <= k; ++i) {\n powN[i] = SvCommonMathUtils.pow(i, n, MOD);\n }\n\n// IntList[] primeDivsOf = genListsOfPrimeDivisorsForIntsUpTo(k);\n// logger.p(\"lists genareted\");\n\n bi = 0;\n long ans = 0;\n for (int i = 1; i <= k; ++i) {\n // The next value of bi is computed using the previous, by updating\n // only the values g such that g divides i.\n// SvPrimalityUtils.IntPrimeFactor[] fact = SvPrimalityUtils.calcPrimeFactorizationOf(i);\n// for (int bitmask = 0; bitmask < (1 << fact.length); ++bitmask) {\n// int g = 1;\n// for (int j = 0; j < fact.length; ++j) {\n// if (((bitmask >>> j) & 1) == 1) {\n// g *= fact[j].prime;\n// }\n// }\n// update(i, g);\n// }\n\n// for (int bitmask = 0; bitmask < (1 << primeDivsOf[i].size()); ++bitmask) {\n// int g = 1;\n// for (int j = primeDivsOf[i].size() - 1; j >= 0; --j) {\n// if (((bitmask >>> j) & 1) == 1) {\n// g *= primeDivsOf[i].get(j);\n// }\n// }\n// update(i, g);\n// }\n\n IntList fact = calcPrimeFactorizationOf(i);\n for (int bitmask = 0; bitmask < (1 << fact.size()); ++bitmask) {\n int g = 1;\n for (int j = fact.size() - 1; j >= 0; --j) {\n if (((bitmask >>> j) & 1) == 1) {\n g *= fact.get(j);\n }\n }\n update(i, g);\n }\n\n\n ans = (ans + (bi ^ i)) % MOD;\n }\n\n logger.p(\"loop done\");\n\n out.println(ans);\n }\n\n }\n\n static class SvLogger {\n private static final String MESSAGE_PREFIX = \"> \";\n private boolean enabled = true;\n private boolean printTimeEllapsed = false;\n private long startedTime = System.currentTimeMillis();\n\n public SvLogger setPrintTimeEllapsed(boolean printTimeEllapsed) {\n this.printTimeEllapsed = printTimeEllapsed;\n return this;\n }\n\n public void p(String format, Object... args) {\n if (!enabled) {\n return;\n }\n printMessage(String.format(format, args));\n }\n\n private void printMessage(String msg) {\n String formattedTime =\n printTimeEllapsed ? \" (\" + (System.currentTimeMillis() - startedTime) + \" ms)\" : \"\";\n System.out.println(MESSAGE_PREFIX + msg + formattedTime);\n }\n\n }\n\n static abstract class IntAbstractStream implements IntStream {\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n\n }\n\n static class SvNumberTheoryUtils {\n public static byte[] genMoebiusFuncForIntsUpTo(int n) {\n byte[] m = new byte[n + 1];\n for (int i = 1; i <= n; ++i) {\n m[i] = 1;\n }\n boolean[] isPr = SvPrimalityUtils.genBoolArrayForPrimalityTestUpTo(n);\n for (int p = 2; p <= n; ++p) {\n if (isPr[p]) {\n long p2 = (long) p * p;\n for (long j = p2; j <= n; j += p2) {\n m[(int) j] = 0;\n }\n for (int j = p; j <= n && j > 0; j += p) {\n m[j] = (byte) -m[j];\n }\n }\n }\n return m;\n }\n\n }\n\n static class SvPrimalityUtils {\n public static boolean[] genBoolArrayForPrimalityTestUpTo(int n) {\n if (n < 0) {\n throw new IllegalArgumentException();\n }\n boolean[] isPrime = new boolean[n + 1];\n Arrays.fill(isPrime, true);\n if (n >= 0) {\n isPrime[0] = false;\n }\n if (n >= 1) {\n isPrime[1] = false;\n }\n for (int i = 2; i <= n; ++i) {\n if (isPrime[i]) {\n for (long j = ((long) i) * i; j <= n; j += i) {\n isPrime[(int) j] = false;\n }\n }\n }\n return isPrime;\n }\n\n }\n\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n\n public abstract void addAt(int index, int value);\n\n public abstract void removeAt(int index);\n\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n\n\n default public void add(int value) {\n addAt(size(), value);\n }\n\n }\n\n static interface IntCollection extends IntStream {\n public int size();\n\n default public void add(int value) {\n throw new UnsupportedOperationException();\n }\n\n default public IntCollection addAll(IntStream values) {\n for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {\n add(it.value());\n }\n return this;\n }\n\n }\n\n static class SvScanner {\n private BufferedReader reader;\n private StringTokenizer tokenizer = new StringTokenizer(\"\");\n\n public SvScanner(InputStreamReader in) {\n reader = new BufferedReader(in);\n }\n\n public String next() {\n try {\n while (!tokenizer.hasMoreTokens()) {\n String nextLine = reader.readLine();\n if (nextLine == null) {\n throw new IllegalStateException(\"next line is null\");\n }\n tokenizer = new StringTokenizer(nextLine);\n }\n return tokenizer.nextToken();\n } catch (IOException e) {\n throw new IllegalStateException(e);\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n\n static class InputReader {\n private InputStream stream;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n }\n\n static class IntArrayList extends IntAbstractStream implements IntList {\n private int size;\n private int[] data;\n\n public IntArrayList() {\n this(3);\n }\n\n public IntArrayList(int capacity) {\n data = new int[capacity];\n }\n\n public IntArrayList(IntCollection c) {\n this(c.size());\n addAll(c);\n }\n\n public IntArrayList(IntStream c) {\n this();\n if (c instanceof IntCollection) {\n ensureCapacity(((IntCollection) c).size());\n }\n addAll(c);\n }\n\n public IntArrayList(IntArrayList c) {\n size = c.size();\n data = c.data.clone();\n }\n\n public IntArrayList(int[] arr) {\n size = arr.length;\n data = arr.clone();\n }\n\n public int size() {\n return size;\n }\n\n public int get(int at) {\n if (at >= size) {\n throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size);\n }\n return data[at];\n }\n\n private void ensureCapacity(int capacity) {\n if (data.length >= capacity) {\n return;\n }\n capacity = Math.max(2 * data.length, capacity);\n data = Arrays.copyOf(data, capacity);\n }\n\n public void addAt(int index, int value) {\n ensureCapacity(size + 1);\n if (index > size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size) {\n System.arraycopy(data, index, data, index + 1, size - index);\n }\n data[index] = value;\n size++;\n }\n\n public void removeAt(int index) {\n if (index >= size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size - 1) {\n System.arraycopy(data, index + 1, data, index, size - index - 1);\n }\n size--;\n }\n\n }\n\n static interface IntReversableCollection extends IntCollection {\n }\n\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n }\n\n static class SvCommonMathUtils {\n public static int pow(int n, long deg, int mod) {\n if (n < 0 || deg < 0 || mod <= 0) {\n throw new IllegalArgumentException();\n }\n if (deg == 0) {\n return 1;\n } else if (deg % 2 == 0) {\n long tmp = pow(n, deg / 2, mod);\n return (int) ((tmp * tmp) % mod);\n } else {\n return (int) (((n % mod) * (long) pow(n, deg - 1, mod)) % mod);\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7cd852e47b55a0571b401eab2b293386", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class tr1 {\n\tstatic PrintWriter out;\n\tstatic StringBuilder sb;\n\tstatic int n, z, k;\n\tstatic long mod = (long) 1e9 + 7;\n\tstatic int[][] memo;\n\tstatic String s;\n\tstatic int[][] ad;\n\tstatic TreeMap[] gs;\n\tstatic long inf = Long.MAX_VALUE;\n\tstatic int[] color;\n\tstatic ArrayList o;\n\tstatic char[][] g;\n\tstatic boolean[] vis, vis1;\n\tstatic long[] f;\n\tstatic int[] a;\n\tstatic int lj;\n\tstatic int[][] mat;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tn = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tlong ans = 0;\n\t\tlong sum = 0;\n\t\tlong[] ar = new long[k + 1];\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t\tlong total = modPow(i, n) - modPow(i - 1, n);\n\t\t\tar[i] += total;\n\t\t\tar[i] %= mod;\n\t\t\tar[i] += mod;\n\t\t\tar[i] %= mod;\n\t\t\tsum += ar[i];\n\t\t\tans = ans + (sum ^ i);\n\t\t\tfor (int j = i + i; j <= k; j += i) {\n\t\t\t\tar[j] -= ar[i];\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans%mod);\n\t\tout.flush();\n\t}\n\n\tstatic long modPow(long a, long e)\n\n\t{\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\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\n\t\tpublic Scanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic char nextChar() throws IOException {\n\t\t\treturn next().charAt(0);\n\t\t}\n\n\t\tpublic Long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int[] nextArrInt(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[] nextArrLong(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 boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(3000);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5251d9313d836c59af66e94fdfe1a5f3", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "/* Author: Ronak Agarwal */\nimport java.io.* ; import java.util.* ; import java.math.* ;\nimport static java.lang.Math.min ;\nimport static java.lang.Math.max ;\nimport static java.lang.Math.abs ;\nimport static java.lang.Math.log ;\nimport static java.lang.Math.pow ;\nimport static java.lang.Math.sqrt ;\n/* Thread is created here to increase the stack size of the java code so that recursive dfs can be performed */\npublic class Codeshefcode{\n\tpublic static void main(String[] args) throws IOException{\n\t\tnew Thread(null,new Runnable(){\tpublic void run(){ exec_Code() ;} },\"Solver\",1l<<27).start() ;\n\t}\n\tstatic void exec_Code(){\n\t\ttry{\n\t\t\tSolver Machine = new Solver() ;\n\t\t\tMachine.Solve() ; Machine.Finish() ;}\n\t\tcatch(Exception e){ e.printStackTrace() ; print_and_exit() ;}\n\t\tcatch(Error e){ e.printStackTrace() ; print_and_exit() ; }\n\t}\n\tstatic void print_and_exit(){ System.out.flush() ; System.exit(-1) ;}\n}\nclass Reader{\n\tBufferedReader reader;\n\tStringTokenizer tkz;\n\tReader(InputStream input) {\n\t\treader = new BufferedReader(new InputStreamReader(input)) ;\n\t\ttkz = new StringTokenizer(\"\") ;\n\t}\n\tString s() throws IOException{\n\t\twhile (!tkz.hasMoreTokens()) tkz = new StringTokenizer(reader.readLine()) ;\n\t\treturn tkz.nextToken() ;\n\t}\n\tint i() throws IOException{ return Integer.parseInt(s()) ;}\n\tlong l() throws IOException{ return Long.parseLong(s()) ;}\n\tdouble d() throws IOException{\treturn Double.parseDouble(s()) ;}\n}\n/* All the useful functions,constants,renamings are here*/\nclass Template{\n\t/* Constants Section */\n\tfinal int INT_MIN = Integer.MIN_VALUE ; final int INT_MAX = Integer.MAX_VALUE ;\n\tfinal long LONG_MIN = Long.MIN_VALUE ; final long LONG_MAX = Long.MAX_VALUE ;\n\tstatic long MOD = 1000000007 ;\n\tstatic Reader ip = new Reader(System.in) ;\t\n\tstatic PrintWriter op = new PrintWriter(System.out) ;\n\t/* Methods for writing */\n\tstatic void p(Object o){ op.print(o) ; }\n\tstatic void pln(Object o){ op.println(o) ;}\n\tstatic void Finish(){ op.flush();\top.close(); }\n\t/* Implementation of operations modulo MOD */\n\tstatic long inv(long a){ return powM(a,MOD-2) ; }\n\tstatic long m(long a,long b){ return (a*b)%MOD ; }\n\tstatic long d(long a,long b){ return (a*inv(b))%MOD ; }\n\tstatic long powM(long a,long b){\n\t\tif(b<0) return powM(inv(a),-b) ;\n\t\tlong val=a ; long ans=1 ;\n\t\twhile(b!=0){\n\t\t\tif((b&1)==1) ans = (ans*val)%MOD ; \n\t\t\tval = (val*val)%MOD ; \n\t\t\tb/=2 ;\n\t\t}\n\t\treturn ans ;\n\t}\n\t/* Renaming of some generic utility classes */\n\tfinal static class mylist extends ArrayList{}\n\tfinal static class mylisti extends ArrayList{}\n\tfinal static class myset extends TreeSet{}\n\tfinal static class mystack extends Stack{}\n\tfinal static class mymap extends TreeMap{}\n}\n/* Implementation of the pair class, useful for every other problem */\nclass pair implements Comparable{\n\tint x ; int y ; int id ;\n\tpair(int _x,int _y,int _id){ x=_x ; y=_y ; id=_id ;} \n\tpublic int compareTo(pair p){\n\t\treturn (this.xp.x ? 1 : (this.yp.y ? 1 : 0)))) ;\n\t}\n}\n/* Main code starts here */\nclass Solver extends Template{\n\tint n,k ;\n\tint LIM = 2000000 ;\n\tlong pn[] = new long[LIM+1] ;\n\tint u[] = new int[LIM+1] ;\n\tint fac[] = new int[LIM+1] ;\n\tmylist div[] = new mylist[LIM+1] ;\n\tvoid preComp(){\n\t\tfor(int i=1 ; i<=LIM ; i++){ \n\t\t\tdiv[i] = new mylist() ;\n\t\t\tdiv[i].add(1) ;\n\t\t}\n\t\tfor(int i=1 ; i<=LIM ; i++) pn[i] = powM(i,n) ;\n\t\tfor(int i=2 ; i<=LIM ; i++) \n\t\t\tif(fac[i]==0)\n\t\t\t\tfor(int j=i ; j<=LIM ; j+=i){\n\t\t\t\t\tfac[j] = i ;\n\t\t\t\t\tdiv[j].add(i) ;\n\t\t\t\t}\n\t\tu[1] = 1 ;\n\t\tfor(int i=2 ; i<=LIM ; i++){\n\t\t\tint prm = fac[i] ;\n\t\t\tint j = i/prm ;\n\t\t\tu[i] = (j%prm==0 ? 0 : -u[j]) ;\n\t\t}\n\t}\n\tpublic void Solve() throws IOException{\n\t\tn = ip.i() ; k = ip.i() ;\n\t\tpreComp() ;\n\n\t}\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d6d0327d61a2b961ab180ec1b3a113e", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa", "difficulty": 2300.0} {"lang": "Java 6", "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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tprivate static final long MOD = (long) (1e9 + 7);\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tlong width = in.readInt();\n\t\tlong evenWidth = (width + 2) / 2;\n\t\tlong oddWidth = (width + 1) / 2;\n\t\tlong height = in.readInt();\n\t\tlong evenHeight = (height + 2) / 2;\n\t\tlong oddHeight = (height + 1) / 2;\n\t\tlong total = 0;\n\t\tint[][] gcd = new int[(int) (width + 1)][(int) (height + 1)];\n\t\tfor (int i = 0; i <= width; i++)\n\t\t\tgcd[i][0] = i + 1;\n\t\tfor (int i = 0; i <= height; i++)\n\t\t\tgcd[0][i] = i + 1;\n\t\tfor (int i = 1; i <= width; i++) {\n\t\t\tfor (int j = 1; j <= height; j++) {\n\t\t\t\tif (i >= j)\n\t\t\t\t\tgcd[i][j] = gcd[i - j][j];\n\t\t\t\telse\n\t\t\t\t\tgcd[i][j] = gcd[i][j - i];\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i <= width; i++) {\n\t\t\tlong remainingWidth = width - i + 1;\n\t\t\tfor (int j = 0; j <= height; j++) {\n\t\t\t\tlong remainingHeight = height - j + 1;\n\t\t\t\tlong current;\n\t\t\t\tif ((i & 1) == 0) {\n\t\t\t\t\tif ((j & 1) == 0)\n\t\t\t\t\t\tcurrent = (width + 1) * (height + 1) * remainingWidth * remainingHeight;\n\t\t\t\t\telse\n\t\t\t\t\t\tcurrent = evenWidth * (height + 1) * ((remainingWidth + 1) >> 1) * remainingHeight + oddWidth * (height + 1) * (remainingWidth >> 1) * remainingHeight;\n\t\t\t\t} else {\n\t\t\t\t\tif ((j & 1) == 0)\n\t\t\t\t\t\tcurrent = evenHeight * (width + 1) * ((remainingHeight + 1) >> 1) * remainingWidth + oddHeight * (width + 1) * (remainingHeight >> 1) * remainingWidth;\n\t\t\t\t\telse {\n\t\t\t\t\t\tcurrent = (((height + 1) * (width + 1) + 1) >> 1) * ((remainingHeight * remainingWidth + 1) >> 1) +\n\t\t\t\t\t\t\t(((height + 1) * (width + 1)) >> 1) * ((remainingHeight * remainingWidth) >> 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (i != 0)\n\t\t\t\t\tcurrent <<= 1;\n\t\t\t\tif (j != 0)\n\t\t\t\t\tcurrent <<= 1;\n\t\t\t\tlong currentMinus = 0;\n\t\t\t\tif (gcd[i][j] > 2)\n\t\t\t\t\tcurrentMinus += 6 * (gcd[i][j] - 2) * (width - i + 1) * (height - j + 1);\n\t\t\t\tif (gcd[i][j] > 1)\n\t\t\t\t\tcurrentMinus += 6 * (width - i + 1) * (height - j + 1);\n\t\t\t\tif (i != 0 && j != 0)\n\t\t\t\t\tcurrentMinus <<= 1;\n\t\t\t\tif (i == 0 && j == 0)\n\t\t\t\t\tcurrentMinus += (width + 1) * (height + 1);\n\t\t\t\tcurrent -= currentMinus;\n\t\t\t\ttotal += current;\n\t\t\t}\n\t\t\ttotal %= MOD;\n\t\t}\n\t\tif (total < 0)\n\t\t\ttotal += MOD;\n\t\tout.printLine(total);\n\t}\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn 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\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "509490eb835ace7f33fb29c6f460b86e", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0} {"lang": "Java 7", "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\tstatic final int MOD = 1000000007;\n\t\n\tint gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint w = nextInt();\n\t\tint h = nextInt();\n\n\t\tint[] x = { w / 2 + 1, (w + 1) / 2 };\n\t\tint[] y = { h / 2 + 1, (h + 1) / 2 };\n\t\tint[][] c = new int[2][2];\n\t\tfor (int i = 0; i < 2; i++)\n\t\t\tfor (int j = 0; j < 2; j++)\n\t\t\t\tc[i][j] = x[i] * y[j];\n\n\t\tint ans = 0;\n\n\t\tfor (int x1 = 0; x1 < 2; x1++)\n\t\t\tfor (int y1 = 0; y1 < 2; y1++)\n\t\t\t\tfor (int x2 = 0; x2 < 2; x2++)\n\t\t\t\t\tfor (int y2 = 0; y2 < 2; y2++)\n\t\t\t\t\t\tfor (int x3 = 0; x3 < 2; x3++)\n\t\t\t\t\t\t\tfor (int y3 = 0; y3 < 2; y3++) {\n\n\t\t\t\t\t\t\t\tint sq = (x1 * y2 - x2 * y1)\n\t\t\t\t\t\t\t\t\t\t+ (x2 * y3 - x3 * y2)\n\t\t\t\t\t\t\t\t\t\t+ (x3 * y1 - x1 * y3);\n\t\t\t\t\t\t\t\tif ((sq & 1) == 1)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tans += (int) ((long) c[x1][y1] * c[x2][y2]\n\t\t\t\t\t\t\t\t\t\t% MOD * c[x3][y3] % MOD);\n\t\t\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\t\t\tans -= MOD;\n\n\t\t\t\t\t\t\t}\n\t\t\n\t\tfor (int dx = 0; dx <= w; dx++)\n\t\t\tfor (int dy = 0; dy <= h; dy++) {\n\t\t\t\tint mult = (w - dx + 1) * (h - dy + 1);\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tans -= mult;\n\t\t\t\t\tif (ans < 0)\n\t\t\t\t\t\tans += MOD;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (dx != 0 && dy != 0)\n\t\t\t\t\tmult <<= 1;\n\t\t\t\tint all = gcd(dx, dy) * 6;\n\t\t\t\t\n\t\t\t\tans -= (int)((long)mult * all % MOD);\n\t\t\t\tif (ans < 0)\n\t\t\t\t\tans += MOD;\n\t\t\t}\n\t\t\n\t\tout.println(ans);\n\t\t\n\t\t\n\t}\n\n\tvoid inp() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D().inp();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "26fbeeea083f1f1990bcac0f3136938c", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\n\tprivate StringTokenizer st;\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\t\n\tfinal long mod = 1000000007;\n\n\tlong st(long x, long y) {\n\t\treturn (x + mod - (y % mod)) % mod;\n\t}\n\t\n\tint gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\t\n\tpublic void solve() throws IOException {\n\t\tint w = nextInt();\n\t\tint h = nextInt();\n\t\tlong ans = 0;\n\t\tfor (int x1 = 0; x1 < 2; ++x1) {\n\t\tfor (int y1 = 0; y1 < 2; ++y1) {\n\t\t\tfor (int x2 = 0; x2 < 2; ++x2) {\n\t\t\tfor (int y2 = 0; y2 < 2; ++y2) {\n\t\t\t\tfor (int x3 = 0; x3 < 2; ++x3) {\n\t\t\t\tfor (int y3 = 0; y3 < 2; ++y3) {\n\t\t\t\t\tif (((x1 + x2 + x3) * (y1 + y2 + y3) - (x1 * y1 + x2 * y2 + x3 * y3)) % 2 == 0) {\n\t\t\t\t\t\tlong val = 1;\n\t\t\t\t\t\tval = (val * ((w + 2 - x1) / 2)) % mod;\n\t\t\t\t\t\tval = (val * ((w + 2 - x2) / 2)) % mod;\n\t\t\t\t\t\tval = (val * ((w + 2 - x3) / 2)) % mod;\n\t\t\t\t\t\tval = (val * ((h + 2 - y1) / 2)) % mod;\n\t\t\t\t\t\tval = (val * ((h + 2 - y2) / 2)) % mod;\n\t\t\t\t\t\tval = (val * ((h + 2 - y3) / 2)) % mod;\n\t\t\t\t\t\tans = (ans + val) % mod;\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}\n\t\t}\n\t\tlong total = ((w + 1) * (h + 1)) % mod;\n\t\tans = st(ans, total);\n\t\tans = st(ans, total * (total - 1) * 3);\n\t\tfor (int x = 0; x <= w; ++x) {\n\t\t\tfor (int y = 0; y <= h; ++y) {\n\t\t\t\tif (gcd(x, y) != 1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong st = 0;\n\t\t\t\tfor (int u = 1; x * u <= w && y * u <= h; ++u) {\n\t\t\t\t\tfor (int v = u + 1; x * v <= w && y * v <= h; ++v) {\n\t\t\t\t\t\tst += (w - x * v + 1) * (h - y * v + 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tst *= x == 0 || y == 0 ? 6 : 12;\n\t\t\t\tans = st(ans, st);\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\teat(\"\");\n\t\t\n\t\tsolve();\n\t\t\n\t\tout.close();\n\t}\n\t\n\tvoid eat(String s) {\n\t\tst = new StringTokenizer(s);\n\t}\n\t\n\tString next() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\teat(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tLocale.setDefault(Locale.US);\n\t\tnew Solution().run();\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "85e20288f3012dcd29e87469d61bd29a", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.List;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.Locale;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\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_LittleElAndTriangle solver = new TaskD_LittleElAndTriangle();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD_LittleElAndTriangle {\n public static final int MOD = (int) 1e9 + 7;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n int res = 0;\n int amY0 = getAm(false, 0, m);\n int amY1 = m + 1 - amY0;\n int amX0 = getAm(false, 0, n);\n int amX1 = n + 1 - amX0;\n\n for (int x = 0; x <= 1; ++x) {\n int B1 = BitUtils.checkBit(1 - x, 0) ? amX1 : amX0;\n int B3 = BitUtils.checkBit(x, 0) ? amX1 : amX0;\n int amX = (x == 0 ? (n/2) + 1 : (n +1) / 2);\n\n\n for (int y = 0; y <= 1; ++y) {\n int amY = (y == 0 ? (m/2) + 1 : (m +1) / 2);\n int B2 = BitUtils.checkBit(y, 0) ? amY1 : amY0;\n int B4 = BitUtils.checkBit(1 - y, 0) ? amY1 : amY0;\n for (int xx2 = 0; xx2 <= 1; ++xx2) {\n int A1 = BitUtils.checkBit(xx2, 0) ? amX1 : amX0;\n for (int yy1 = 0; yy1 <= 1; ++yy1) {\n if (odd(xx2 - x) * odd(yy1 - y) == 0) {\n int A2 = BitUtils.checkBit(yy1, 0) ? amY1 : amY0;\n long cur2 = (B1 * B2 + B3 * (m+1));\n cur2 = cur2 * A1 * A2;\n cur2 %= MOD;\n cur2 *= amX;\n cur2 %= MOD;\n cur2 *= amY;\n cur2 %= MOD;\n res += cur2;\n if (res >= MOD) res -= MOD;\n } else {\n int A2 = BitUtils.checkBit(yy1, 0) ? amY1 : amY0;\n long cur = A1 * A2;\n cur = cur * B1 * B4;\n cur %= MOD;\n cur *= amX;\n cur %= MOD;\n cur *= amY;\n cur %= MOD;\n res += cur;\n if (res >= MOD) res -= MOD;\n }\n }\n }\n }\n }\n\n for (int dx = 0; dx <= n; ++dx) {\n for (int dy = 0; dy <= m; ++dy) {\n if (dx == 0 && dy == 0) continue;\n int amX = n - dx + 1;\n int amY = m - dy + 1;\n int amPoints = IntegerUtils.gcd(dx, dy);\n if (dx == 0 || dy == 0) {\n res -= (amPoints * 6L * amX * amY) % MOD;\n } else {\n res -= (amPoints * 12L * amX * amY) % MOD;\n }\n res += MOD;\n if (res >= MOD) {\n res -= MOD;\n }\n }\n }\n\n res -= (n + 1) * (m + 1);\n res += MOD;\n if (res >= MOD) {\n res -= MOD;\n }\n\n out.println(res);\n }\n\n private int odd(int x) {\n return BitUtils.checkBit(x, 0) ? 1 : 0;\n }\n\n private int getAm(boolean odd, int begin, int end) {\n if (BitUtils.checkBit(begin, 0) != odd) {\n ++begin;\n }\n if (BitUtils.checkBit(end, 0) != odd) {\n --end;\n }\n if (begin <= end) {\n return (end - begin) / 2 + 1;\n }\n return 0;\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String nextString() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n}\n\nclass BitUtils {\n public static boolean checkBit(int mask, int bit) {\n return (mask & (1 << bit)) > 0;\n }\n\n}\n\nclass IntegerUtils {\n\n public static int gcd(int x, int y) {\n return y == 0 ? x : gcd(y, x % y);\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "98756f239917a48f2ffb7feaf4a30856", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.awt.Point;\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 * @author Phantom\n */\npublic class T4 {\n\n public static int orientation(Point p, Point q, Point r) {\n double val = (q.getY() - p.getY()) * (r.getX() - q.getX())\n - (q.getX() - p.getX()) * (r.getY() - q.getY());\n\n if (val == 0.0) {\n return 0; // colinear\n }\n return (val > 0) ? 1 : 2; // clock or counterclock wise\n }\n\n public static boolean intersect(Point p1, Point q1, Point p2, Point q2) {\n\n int o1 = orientation(p1, q1, p2);\n int o2 = orientation(p1, q1, q2);\n int o3 = orientation(p2, q2, p1);\n int o4 = orientation(p2, q2, q1);\n\n if (o1 != o2 && o3 != o4) {\n return true;\n }\n\n return false;\n }\n\n static boolean intersects(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {\n float bx = x2 - x1;\n float by = y2 - y1;\n float dx = x4 - x3;\n float dy = y4 - y3;\n float b_dot_d_perp = bx * dy - by * dx;\n if (b_dot_d_perp == 0) {\n return false;\n }\n float cx = x3 - x1;\n float cy = y3 - y1;\n float t = (cx * dy - cy * dx) / b_dot_d_perp;\n if (t < 0 || t > 1) {\n return false;\n }\n float u = (cx * by - cy * bx) / b_dot_d_perp;\n if (u < 0 || u > 1) {\n return false;\n }\n return true;\n }\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n int m = input.nextInt();\n Point[] rebel = new Point[n];\n Point[] base = new Point[m];\n for (int i = 0; i < n; i++) {\n rebel[i] = new Point(input.nextInt(), input.nextInt());\n }\n for (int i = 0; i < m; i++) {\n base[i] = new Point(input.nextInt(), input.nextInt());\n }\n if (m != n) {\n System.out.println(\"NO\");\n } else {\n boolean valid = true;\n for (int i = 0; i < n - 1; i++) {\n for (int j = i + 1; j < m; j++) {\n \n if (intersects(rebel[i].x,rebel[i].y,base[i].x,base[i].y,rebel[j].x,rebel[j].y,base[j].x,base[j].y)) {\n valid = false;\n break;\n }\n }\n }\n if (valid) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "deb1b6408d529ba2014e92f7dd82c772", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Scanner;\nimport java.lang.Math;\n\npublic class GuardDuty {\n\n\tboolean segmentosSeInterceptam(Ponto p1, Ponto p2, Ponto p3, Ponto p4) {\n\n\t\tint d1 = direcao(p3, p4, p1);\n\t\tint d2 = direcao(p3, p4, p2);\n\t\tint d3 = direcao(p1, p2, p3);\n\t\tint d4 = direcao(p1, p2, p4);\n\n\t\tif (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0))) {\n\t\t\treturn true;\n\t\t} else if (d1 == 0 && noSegmento(p3, p4, p1)) {\n\t\t\treturn true;\n\t\t} else if (d2 == 0 && noSegmento(p3, p4, p2)) {\n\t\t\treturn true;\n\t\t} else if (d3 == 0 && noSegmento(p1, p2, p3)) {\n\t\t\treturn true;\n\t\t} else if (d4 == 0 && noSegmento(p1, p2, p4)) {\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tint direcao(Ponto pi, Ponto pj, Ponto pk) {\n\t\tint resp = (pk.x - pi.x) * (pj.y - pi.y) - (pj.x - pi.x) * (pk.y - pi.y);\n\t\t// (pk - pi) * (pj - pi)\n\t\treturn resp;\n\t}\n\n\tboolean noSegmento(Ponto pi, Ponto pj, Ponto pk) {\n\t\tif ((Math.min(pi.x, pj.x) <= pk.x) && (pk.x <= Math.max(pi.x, pj.x))) {\n\t\t\tif ((Math.min(pi.y, pj.y) <= pk.y) && (pk.y <= Math.max(pi.y, pj.y))) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tboolean nSegmentosInterceptam(Ponto[] s) {\n\t\t// T = NULL;\n\t\tLinkedList ll = new LinkedList();\n\t\tll.clear();\n\t\tIterator it = ll.iterator();\n\t\tint ant = -1;\n\t\tordenaExtremidades(s);\n\t\tfor (int p = 0; p < s.length; p++) {\n\t\t\tif (s[p].esq) {\n\n\t\t\t\tll.add(s[p].seg);\n\t\t\t\tit = ll.iterator();\n\t\t\t\tant = -1;\n\n\t\t\t\t// Percorre pra saber se existe segmentos acima ou abaixo do\n\t\t\t\t// atual na estrutura aux\n\t\t\t\twhile (it.hasNext()) {\n\t\t\t\t\tIterator temp = it;\n\t\t\t\t\tint next = temp.next();\n\t\t\t\t\t//System.out.println(\"next = \" + next);\n\t\t\t\t\tif (next == s[p].seg) {\n\n\t\t\t\t\t\t// Se existe segmento acima e eles se interceptam em\n\t\t\t\t\t\t// algum ponto\n\t\t\t\t\t\tif (temp.hasNext()) {\n\n\t\t\t\t\t\t\tint seg2 = temp.next();\n\n\t\t\t\t\t\t\t//System.out.println(\"1x = \" + s[p].x + \", y = \" + s[p].y + \", p = \" + p);\n\n\t\t\t\t\t\t\tPonto fim1 = buscaPonto(s, p, s[p].seg, false);\n\t\t\t\t\t\t\tPonto ini2 = buscaPonto(s, 0, seg2, true);\n\t\t\t\t\t\t\tPonto fim2 = buscaPonto(s, p, seg2, false);\n\n\t\t\t\t\t\t\tif (fim1 != null && ini2 != null && fim2 != null) {\n\n\t\t\t\t\t\t\t\tif (segmentosSeInterceptam(s[p], fim1, ini2, fim2)) {\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Se existe segmento abaixo e eles se interceptam em\n\t\t\t\t\t\t// algum ponto\n\t\t\t\t\t\tif (ant != -1) {\n\t\t\t\t\t\t\t// temp = ant;\n\t\t\t\t\t\t\tint segAnt = ant;\n\n\t\t\t\t\t\t\t//System.out.println(\"2x = \" + s[p].x + \", y = \" + s[p].y + \", p = \" + p);\n\n\t\t\t\t\t\t\tPonto iniAnt = buscaPonto(s, 0, segAnt, true);\n\t\t\t\t\t\t\tPonto fimAnt = buscaPonto(s, p, segAnt, false);\n\t\t\t\t\t\t\tPonto fim1 = buscaPonto(s, p, s[p].seg, false);\n\n\t\t\t\t\t\t\tif (fim1 != null && iniAnt != null && fimAnt != null) {\n\t\t\t\t\t\t\t\tif (segmentosSeInterceptam(iniAnt, fimAnt, s[p], fim1)) {\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\tant = next;\n\t\t\t\t}\n\t\t\t} else if (!s[p].esq) {\n\n\t\t\t\tit = ll.iterator();\n\t\t\t\tant = -1;\n\n\t\t\t\twhile (it.hasNext()) {\n\n\t\t\t\t\tIterator temp = it;\n\t\t\t\t\tint next = temp.next();\n\t\t\t\t\t//System.out.println(\"next = \" + next);\n\t\t\t\t\tif (next == s[p].seg) {\n\n\t\t\t\t\t\t// Se existe um segmento acima e outro abaixo do atual\n\t\t\t\t\t\tif ((ant != -1)) {\n\n\t\t\t\t\t\t\tint seg2 = next;\n\n\t\t\t\t\t\t\t//System.out.println(\"3x = \" + s[p].x + \", y = \" + s[p].y + \", p = \" + p);\n\n\t\t\t\t\t\t\tPonto ini2 = buscaPonto(s, 0, seg2, true);\n\t\t\t\t\t\t\tPonto fim2 = buscaPonto(s, p, seg2, false);\n\n\t\t\t\t\t\t\t// Iterator temp2 = ant;\n\t\t\t\t\t\t\tint segAnt = ant;\n\t\t\t\t\t\t\tPonto iniAnt = buscaPonto(s, 0, segAnt, true);\n\t\t\t\t\t\t\tPonto fimAnt = buscaPonto(s, p, segAnt, false);\n\n\t\t\t\t\t\t\tif (fimAnt != null && ini2 != null && fim2 != null && iniAnt != null && segAnt != seg2) {\n\t\t\t\t\t\t\t\tif (segmentosSeInterceptam(ini2, fim2, iniAnt, fimAnt)) {\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\tant = next;\n\t\t\t\t}\n\t\t\t\tInteger rem = s[p].seg;\n\t\t\t\tll.remove(rem);\n\n\t\t\t}\n\n\t\t}\n\t\treturn false;\n\t}\n\n\tPonto buscaPonto(Ponto[] s, int ini, int seg, boolean esq) {\n\t\tfor (int i = ini; ini < s.length; i++) {\n\t\t\tif (s[i].seg == seg && s[i].esq == esq) {\n\t\t\t\treturn s[i];\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\tvoid ordenaExtremidades(Ponto[] s) {\n\n\t\tfor (int i = 1; i < s.length; i++) {\n\n\t\t\tPonto v = s[i];\n\t\t\tint j = i;\n\n\t\t\twhile ((j > 0)) {\n\t\t\t\tif (s[j - 1].x > v.x) {\n\t\t\t\t\ts[j] = s[j - 1];\n\t\t\t\t\tj--;\n\t\t\t\t} else if (s[j - 1].x == v.x) {\n\t\t\t\t\tif (!s[j - 1].esq && v.esq) {\n\t\t\t\t\t\ts[j] = s[j - 1];\n\t\t\t\t\t\tj--;\n\t\t\t\t\t} else if (s[j - 1].esq == v.esq) {\n\t\t\t\t\t\tif (s[j - 1].y > v.y) {\n\t\t\t\t\t\t\ts[j] = s[j - 1];\n\t\t\t\t\t\t\tj--;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\ts[j] = v;\n\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tGuardDuty gd = new GuardDuty();\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint r = in.nextInt();\n\t\tint b = in.nextInt();\n\n\t\tif (r != b) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\tin.close();\n\t\t\t//System.exit(0);\n\t\t\treturn;\n\t\t}\n\n\t\tPonto[] navesBases = new Ponto[r + b];\n\n\t\tint x, y;\n\t\t// Naves na primeira metade\n\t\tfor (int i = 0; i < r; i++) {\n\n\t\t\tx = in.nextInt();\n\t\t\ty = in.nextInt();\n\n\t\t\tnavesBases[i] = new Ponto(x, y, true);\n\t\t}\n\n\t\t// Bases na segunda metade\n\t\tfor (int j = r; j < navesBases.length; j++) {\n\n\t\t\tx = in.nextInt();\n\t\t\ty = in.nextInt();\n\n\t\t\tnavesBases[j] = new Ponto(x, y, false);\n\t\t}\n\n\t\tfor (int k = 0; k < r; k++) {\n\t\t\tfor (int l = r; l < navesBases.length; l++) {\n\t\t\t\tnavesBases[l].seg = l - r + 1;\n\n\t\t\t\tif (l + k - r < r) {\n\t\t\t\t\tnavesBases[l + k - r].seg = l - r + 1;\n\t\t\t\t\t\n\t\t\t\t\tif (navesBases[l].x < navesBases[l + k - r].x) {\n\t\t\t\t\t\tnavesBases[l].esq = true;\n\t\t\t\t\t\tnavesBases[l + k - r].esq = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnavesBases[l].esq = false;\n\t\t\t\t\t\tnavesBases[l + k - r].esq = true;\n\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\tnavesBases[l + k - 2 * r].seg = l - r + 1;\n\t\t\t\t\tif (navesBases[l].x < navesBases[l + k - 2 * r].x) {\n\n\t\t\t\t\t\tnavesBases[l].esq = true;\n\t\t\t\t\t\tnavesBases[l + k - 2 * r].esq = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnavesBases[l].esq = false;\n\t\t\t\t\t\tnavesBases[l + k - 2 * r].esq = true;\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}\n\n\t\t\tif(gd.nSegmentosInterceptam(navesBases)) {\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\tin.close();\n\t\t\t\t//System.exit(1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(\"No\");\n\t\tin.close();\n\t\t//System.exit(0);\n\t\treturn;\n\t}\n\n}\n\nclass Ponto {\n\n\tpublic int x;\n\tpublic int y;\n\tpublic int seg;\n\tpublic boolean esq;\n\tpublic boolean nave;\n\n\tpublic Ponto(int x, int y, boolean nave) {\n\t\tsuper();\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.nave = nave;\n\t}\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1dfa679d24c2bd35911556678179c389", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Scanner;\nimport java.lang.Math;\n\npublic class GuardDuty {\n\n\tboolean segmentosSeInterceptam(Ponto p1, Ponto p2, Ponto p3, Ponto p4) {\n\n\t\tint d1 = direcao(p3, p4, p1);\n\t\tint d2 = direcao(p3, p4, p2);\n\t\tint d3 = direcao(p1, p2, p3);\n\t\tint d4 = direcao(p1, p2, p4);\n\n\t\tif (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0))) {\n\t\t\treturn true;\n\t\t} else if (d1 == 0 && noSegmento(p3, p4, p1)) {\n\t\t\treturn true;\n\t\t} else if (d2 == 0 && noSegmento(p3, p4, p2)) {\n\t\t\treturn true;\n\t\t} else if (d3 == 0 && noSegmento(p1, p2, p3)) {\n\t\t\treturn true;\n\t\t} else if (d4 == 0 && noSegmento(p1, p2, p4)) {\n\t\t\treturn true;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tint direcao(Ponto pi, Ponto pj, Ponto pk) {\n\t\tint resp = (pk.x - pi.x) * (pj.y - pi.y) - (pj.x - pi.x) * (pk.y - pi.y);\n\t\t// (pk - pi) * (pj - pi)\n\t\treturn resp;\n\t}\n\n\tboolean noSegmento(Ponto pi, Ponto pj, Ponto pk) {\n\t\tif ((Math.min(pi.x, pj.x) <= pk.x) && (pk.x <= Math.max(pi.x, pj.x))) {\n\t\t\tif ((Math.min(pi.y, pj.y) <= pk.y) && (pk.y <= Math.max(pi.y, pj.y))) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tboolean nSegmentosInterceptam(Ponto[] s) {\n\t\t// T = NULL;\n\t\tLinkedList ll = new LinkedList();\n\t\tll.clear();\n\t\tIterator it = ll.iterator();\n\t\tint ant = -1;\n\t\tordenaExtremidades(s);\n\t\tfor (int p = 0; p < s.length; p++) {\n\t\t\tif (s[p].esq) {\n\n\t\t\t\tll.add(s[p].seg);\n\t\t\t\tit = ll.iterator();\n\t\t\t\tant = -1;\n\n\t\t\t\t// Percorre pra saber se existe segmentos acima ou abaixo do\n\t\t\t\t// atual na estrutura aux\n\t\t\t\twhile (it.hasNext()) {\n\t\t\t\t\tIterator temp = it;\n\t\t\t\t\tint next = temp.next();\n\t\t\t\t\t//System.out.println(\"next = \" + next);\n\t\t\t\t\tif (next == s[p].seg) {\n\n\t\t\t\t\t\t// Se existe segmento acima e eles se interceptam em\n\t\t\t\t\t\t// algum ponto\n\t\t\t\t\t\tif (temp.hasNext()) {\n\n\t\t\t\t\t\t\tint seg2 = temp.next();\n\n\t\t\t\t\t\t\t//System.out.println(\"1x = \" + s[p].x + \", y = \" + s[p].y + \", p = \" + p);\n\n\t\t\t\t\t\t\tPonto fim1 = buscaPonto(s, p, s[p].seg, false);\n\t\t\t\t\t\t\tPonto ini2 = buscaPonto(s, 0, seg2, true);\n\t\t\t\t\t\t\tPonto fim2 = buscaPonto(s, p, seg2, false);\n\n\t\t\t\t\t\t\tif (fim1 != null && ini2 != null && fim2 != null) {\n\n\t\t\t\t\t\t\t\tif (segmentosSeInterceptam(s[p], fim1, ini2, fim2)) {\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Se existe segmento abaixo e eles se interceptam em\n\t\t\t\t\t\t// algum ponto\n\t\t\t\t\t\tif (ant != -1) {\n\t\t\t\t\t\t\t// temp = ant;\n\t\t\t\t\t\t\tint segAnt = ant;\n\n\t\t\t\t\t\t\t//System.out.println(\"2x = \" + s[p].x + \", y = \" + s[p].y + \", p = \" + p);\n\n\t\t\t\t\t\t\tPonto iniAnt = buscaPonto(s, 0, segAnt, true);\n\t\t\t\t\t\t\tPonto fimAnt = buscaPonto(s, p, segAnt, false);\n\t\t\t\t\t\t\tPonto fim1 = buscaPonto(s, p, s[p].seg, false);\n\n\t\t\t\t\t\t\tif (fim1 != null && iniAnt != null && fimAnt != null) {\n\t\t\t\t\t\t\t\tif (segmentosSeInterceptam(iniAnt, fimAnt, s[p], fim1)) {\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\tant = next;\n\t\t\t\t}\n\t\t\t} else if (!s[p].esq) {\n\n\t\t\t\tit = ll.iterator();\n\t\t\t\tant = -1;\n\n\t\t\t\twhile (it.hasNext()) {\n\n\t\t\t\t\tIterator temp = it;\n\t\t\t\t\tint next = temp.next();\n\t\t\t\t\t//System.out.println(\"next = \" + next);\n\t\t\t\t\tif (next == s[p].seg) {\n\n\t\t\t\t\t\t// Se existe um segmento acima e outro abaixo do atual\n\t\t\t\t\t\tif ((ant != -1)) {\n\n\t\t\t\t\t\t\tint seg2 = next;\n\n\t\t\t\t\t\t\t//System.out.println(\"3x = \" + s[p].x + \", y = \" + s[p].y + \", p = \" + p);\n\n\t\t\t\t\t\t\tPonto ini2 = buscaPonto(s, 0, seg2, true);\n\t\t\t\t\t\t\tPonto fim2 = buscaPonto(s, p, seg2, false);\n\n\t\t\t\t\t\t\t// Iterator temp2 = ant;\n\t\t\t\t\t\t\tint segAnt = ant;\n\t\t\t\t\t\t\tPonto iniAnt = buscaPonto(s, 0, segAnt, true);\n\t\t\t\t\t\t\tPonto fimAnt = buscaPonto(s, p, segAnt, false);\n\n\t\t\t\t\t\t\tif (fimAnt != null && ini2 != null && fim2 != null && iniAnt != null && segAnt != seg2) {\n\t\t\t\t\t\t\t\tif (segmentosSeInterceptam(ini2, fim2, iniAnt, fimAnt)) {\n\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\tant = next;\n\t\t\t\t}\n\t\t\t\tInteger rem = s[p].seg;\n\t\t\t\tll.remove(rem);\n\n\t\t\t}\n\n\t\t}\n\t\treturn false;\n\t}\n\n\tPonto buscaPonto(Ponto[] s, int ini, int seg, boolean esq) {\n\t\tfor (int i = ini; ini < s.length; i++) {\n\t\t\tif (s[i].seg == seg && s[i].esq == esq) {\n\t\t\t\treturn s[i];\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\tvoid ordenaExtremidades(Ponto[] s) {\n\n\t\tfor (int i = 1; i < s.length; i++) {\n\n\t\t\tPonto v = s[i];\n\t\t\tint j = i;\n\n\t\t\twhile ((j > 0)) {\n\t\t\t\tif (s[j - 1].x > v.x) {\n\t\t\t\t\ts[j] = s[j - 1];\n\t\t\t\t\tj--;\n\t\t\t\t} else if (s[j - 1].x == v.x) {\n\t\t\t\t\tif (!s[j - 1].esq && v.esq) {\n\t\t\t\t\t\ts[j] = s[j - 1];\n\t\t\t\t\t\tj--;\n\t\t\t\t\t} else if (s[j - 1].esq == v.esq) {\n\t\t\t\t\t\tif (s[j - 1].y > v.y) {\n\t\t\t\t\t\t\ts[j] = s[j - 1];\n\t\t\t\t\t\t\tj--;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\ts[j] = v;\n\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tGuardDuty gd = new GuardDuty();\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint r = in.nextInt();\n\t\tint b = in.nextInt();\n\n\t\tif (r != b) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\tin.close();\n\t\t\tSystem.exit(0);\n\t\t\t//return;\n\t\t}\n\n\t\tPonto[] navesBases = new Ponto[r + b];\n\n\t\tint x, y;\n\t\t// Naves na primeira metade\n\t\tfor (int i = 0; i < r; i++) {\n\n\t\t\tx = in.nextInt();\n\t\t\ty = in.nextInt();\n\n\t\t\tnavesBases[i] = new Ponto(x, y, true);\n\t\t}\n\n\t\t// Bases na segunda metade\n\t\tfor (int j = r; j < navesBases.length; j++) {\n\n\t\t\tx = in.nextInt();\n\t\t\ty = in.nextInt();\n\n\t\t\tnavesBases[j] = new Ponto(x, y, false);\n\t\t}\n\n\t\tfor (int k = 0; k < r; k++) {\n\t\t\tfor (int l = r; l < navesBases.length; l++) {\n\t\t\t\tnavesBases[l].seg = l - r + 1;\n\n\t\t\t\tif (l + k - r < r) {\n\t\t\t\t\tnavesBases[l + k - r].seg = l - r + 1;\n\t\t\t\t\t\n\t\t\t\t\tif (navesBases[l].x < navesBases[l + k - r].x) {\n\t\t\t\t\t\tnavesBases[l].esq = true;\n\t\t\t\t\t\tnavesBases[l + k - r].esq = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnavesBases[l].esq = false;\n\t\t\t\t\t\tnavesBases[l + k - r].esq = true;\n\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\tnavesBases[l + k - 2 * r].seg = l - r + 1;\n\t\t\t\t\tif (navesBases[l].x < navesBases[l + k - 2 * r].x) {\n\n\t\t\t\t\t\tnavesBases[l].esq = true;\n\t\t\t\t\t\tnavesBases[l + k - 2 * r].esq = false;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnavesBases[l].esq = false;\n\t\t\t\t\t\tnavesBases[l + k - 2 * r].esq = true;\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}\n\n\t\t\tif(gd.nSegmentosInterceptam(navesBases)) {\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\tin.close();\n\t\t\t\tSystem.exit(1);\n\t\t\t\t//return;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(\"No\");\n\t\tin.close();\n\t\tSystem.exit(0);\n\t}\n\n}\n\nclass Ponto {\n\n\tpublic int x;\n\tpublic int y;\n\tpublic int seg;\n\tpublic boolean esq;\n\tpublic boolean nave;\n\n\tpublic Ponto(int x, int y, boolean nave) {\n\t\tsuper();\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.nave = nave;\n\t}\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0a8ddf18b121df7b8589f334f91acaf0", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.awt.geom.Line2D;\nimport java.awt.geom.Point2D;\nimport java.awt.geom.Rectangle2D;\nimport java.io.*;\nimport java.util.*;\n\npublic class E1 implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new E1(), \"_cf\", 1 << 28).start();}\n\n\tint[][] ships;\n\tint[][] bases;\n\tint n, m;\n\t\n\tpublic void run() {\n\t\tDeoxysS fs = new DeoxysS();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"Go!\");\n\n\t\tn = fs.nextInt();\n\t\tm = fs.nextInt();\n\t\tships = new int[2][n];\n\t\tbases = new int[2][n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tships[0][i] = fs.nextInt();\n\t\t\tships[1][i] = fs.nextInt();\n\t\t}\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tbases[0][i] = fs.nextInt();\n\t\t\tbases[1][i] = fs.nextInt();\n\t\t}\n\t\t\n\t\tif(n != m) {\n\t\t\tSystem.out.println(\"No\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\trec(0, new boolean[m], new int[n]);\n\n\t\tif(found) out.println(\"Yes\");\n\t\telse out.println(\"No\");\n\t\t\n\t\tout.close();\n\t}\n\t\n\tboolean found = false;\n\t\n\tvoid rec(int at, boolean[] used, int[] with) {\n\t\tif(at == used.length) {\n\t\t\tif(good(with)) {\n\t\t\t\tfound = true;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < used.length && !found; i++) {\n\t\t\tif(used[i]) continue;\n\t\t\tused[i] = true;\n\t\t\twith[at] = i;\n\t\t\trec(at+1, used, with);\n\t\t\tused[i] = false;\n\t\t}\n\t\t\n\t}\n\t\n\tboolean good(int[] with) {\n\t\tLine[] lines = new Line[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tlines[i] = new Line(ships[0][i], ships[1][i], bases[0][with[i]], bases[1][with[i]]);\n\t\t}\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tfor(int j = i + 1; j < n; j++) {\n\t\t\t\tif(lines[i].intersectsLine(lines[j])) return false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tclass Line extends Line2D {\n\n\t\t@Override\n\t\tpublic Rectangle2D getBounds2D() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Point2D getP1() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Point2D getP2() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn null;\n\t\t}\n\n\t\t@Override\n\t\tpublic double getX1() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn x1;\n\t\t}\n\n\t\t@Override\n\t\tpublic double getX2() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn x2;\n\t\t}\n\n\t\t@Override\n\t\tpublic double getY1() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn y1;\n\t\t}\n\n\t\t@Override\n\t\tpublic double getY2() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn y2;\n\t\t}\n\n\t\tdouble x1, y1, x2, y2;\n\t\t@Override\n\t\tpublic void setLine(double arg0, double arg1, double arg2, double arg3) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\tx1 = arg0; y1 = arg1; x2 = arg2; y2 = arg3;\n\t\t} \n\t\t\n\t\tLine(int a, int b, int c, int d) { setLine(a, b, c, d); }\n\t\t\n\t}\n\n\tvoid sort (int[] a) {\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < 50; i++) {\n\t\t\tRandom r = new Random();\n\t\t\tint x = r.nextInt(n), y = r.nextInt(n);\n\t\t\tint temp = a[x];\n\t\t\ta[x] = a[y];\n\t\t\ta[y] = temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\n\tclass DeoxysS {\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 DeoxysS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic DeoxysS(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t} \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16a798de20656743b0d251068f238bfd", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Madi\n */\npublic class TRafficLights {\n public static void main(String [] args) {\n Scanner sc = new Scanner(System.in);\n String [] line = sc.nextLine().split(\" \");\n int l = Integer.parseInt(line[0]);\n int d = Integer.parseInt(line[1]);\n int v = Integer.parseInt(line[2]);\n int g = Integer.parseInt(line[3]);\n int r = Integer.parseInt(line[4]);\n\n double doSvetofora = (double)d / (double)v;\n double ost = doSvetofora;\n while (ost >= 0) {\n ost -= (g + r);\n }\n\n ost += (g + r);\n double doroga = 0;\n if (ost >= 0 && ost < g) {\n doroga = (double) l / (double) v;\n } else {\n doroga = doSvetofora + (r + g - ost) + (double) (l - d) / (double) v;\n }\n\n System.out.println(doroga);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b81b907e95d8d7a5055c094b196c310f", "src_uid": "e4a4affb439365c843c9f9828d81b42c", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "public class a {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int L = in.nextInt();\n int d = in.nextInt();\n int v = in.nextInt();\n int g = in.nextInt();\n int r = in.nextInt();\n\n double t = (double)d / v;\n int time = (int)(t / (g + r)) * (g + r);\n // final double eps = 1e-9;\n\n if (time + g < t) {\n t = time + (g + r);\n }\n System.out.format(\"%.10f\\n\", t + (double)(L - d) / v);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2368f3f0a4cd0603af31a12e71a1d250", "src_uid": "e4a4affb439365c843c9f9828d81b42c", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.util.Scanner;\n\npublic class Main {\n public double l, d, v, g, r;\n\n public static void main(String[] args) throws IOException {\n Main main = new Main();\n main.read();\n main.solve();\n }\n\n public void read() {\n try {\n // Scanner sc = new Scanner(new File(\"input.txt\"));\n\n Scanner sc = new Scanner(System.in);\n\n String[] ss = sc.nextLine().split(\" \");\n\n l = Double.parseDouble(ss[0]);\n d = Double.parseDouble(ss[1]);\n v = Double.parseDouble(ss[2]);\n g = Double.parseDouble(ss[3]);\n r = Double.parseDouble(ss[4]);\n\n } catch ( Exception _ex ) {\n _ex.printStackTrace();\n }\n }\n\n public void solve() {\n double t = d / v;\n if ( t <= g ) {\n t += (l - d) / v;\n } else {\n t += r;\n }\n\n System.out.printf(\"%.8f\", t);\n }\n\n public void write() {\n try {\n // BufferedWriter bw = new BufferedWriter(new\n // FileWriter(\"output.txt\"));\n\n System.out.println();\n } catch ( Exception _ex ) {\n _ex.printStackTrace();\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "54aaabcc78a9199733bab01e391c6be5", "src_uid": "e4a4affb439365c843c9f9828d81b42c", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class spit\n{\n public static void main (String[] args) throws IOException\n {\n StringTokenizer st= new StringTokenizer(in.readLine());\n int n=Integer.parseInt(st.nextToken());\n int[] x=new int[n];\n int[] d=new int[n];\n for (int i=0;i 1 || fema[i] > 1)\n\t\t\t{\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t\treturn answer;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tt = sc.nextInt() - 1;\n\t\t\n\t\tdata = new Triple[k];\n\t\t\n\t\tfor(int i = 0;i answer = new ArrayList();\n\t\tfor(int i = 0; i < MAX; i++)\n\t\t{\n\t\t\tint test = f(i);\n\t\t\tif(test >= 0)\n\t\t\t{\n\t\t\t\tanswer.add(test);\n\t\t\t}\n\t\t}\n\t\tCollections.sort(answer);\n\t\tSystem.out.println( answer.get(t) );\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64884cc559a86cc59ac93d606c54b440", "src_uid": "7348b5644f232bf377a4834eded42e4b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "\n\n\nimport java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class test \n{\n\tprivate static class Triple\n\t{\n\t\tpublic int h;\n\t\tpublic int w;\n\t\tpublic int r;\n\t\t\n\t\tpublic Triple(int h, int w, int r)\n\t\t{\n\t\t\tthis.h = h;\n\t\t\tthis.w = w;\n\t\t\tthis.r = r;\n\t\t}\n\t}\n\t\n\tprivate static int n;\n\tprivate static int k;\n\tprivate static int t;\n\t\n\tprivate static Triple[] data;\n\t\n\t\n\tprivate static int f(int num)\n\t{\n\t\tint answer = 0;\n\t\tint[] male = new int[n];\n\t\tint[] fema = new int[n];\n\t\t\n\t\tfor(int i = 0;i 1 || fema[data[i].w] > 1)\n\t\t\t\t{\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tanswer += data[i].r;\n\t\t\t}\n\t\t\tnum/=2;\n\t\t}\n\t\treturn answer;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tk = sc.nextInt();\n\t\tt = sc.nextInt() - 1;\n\t\t\n\t\tdata = new Triple[k];\n\t\t\n\t\tfor(int i = 0;i answer = new ArrayList();\n\t\tfor(int i = 0; i < MAX; i++)\n\t\t{\n\t\t\tint test = f(i);\n\t\t\tif(test >= 0)\n\t\t\t{\n\t\t\t\tanswer.add(test);\n\t\t\t}\n\t\t}\n\t\tCollections.sort(answer);\n\t\tSystem.out.println( answer.get(t) );\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29816b691af0979b76cd00d52856b530", "src_uid": "7348b5644f232bf377a4834eded42e4b", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "\n\nimport java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class F implements Runnable{\n \n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n \n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n \n void init() throws FileNotFoundException{\n if (ONLINE_JUDGE){\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }else{\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n \n String readString() throws IOException{\n while(!tok.hasMoreTokens()){\n try{\n tok = new StringTokenizer(in.readLine());\n }catch (Exception e){\n return null;\n }\n }\n return tok.nextToken();\n }\n \n int readInt() throws IOException{\n return Integer.parseInt(readString());\n }\n \n long readLong() throws IOException{\n return Long.parseLong(readString());\n }\n \n double readDouble() throws IOException{\n return Double.parseDouble(readString());\n }\n \n public static void main(String[] args){\n new Thread(null, new F(), \"\", 256 * (1L << 20)).start();\n }\n \n long timeBegin, timeEnd;\n\n void time(){\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n \n long memoryTotal, memoryFree;\n \n\n void memory(){\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10) + \" KB\");\n }\n \n void debug(Object... objects){\n if (DEBUG){\n for (Object o: objects){\n System.err.println(o.toString());\n }\n }\n }\n \n public void run(){\n try{\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n time();\n memory();\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n \n boolean DEBUG = false;\n \n void solve() throws IOException{\n int n = readInt();\n \n int k = readInt();\n \n int t = readInt();\n int[] h = new int[k];\n int[] w = new int[k];\n int[] r = new int[k];\n \n for (int i = 0; i < k; i++){\n h[i] = readInt() - 1;\n w[i] = readInt() - 1;\n r[i] = readInt();\n }\n \n boolean[] usedH = new boolean[n];\n boolean[] usedW = new boolean[n];\n \n long lim = (1L << k);\n \n ArrayList list = new ArrayList();\n mask: for (long i = 0; i < lim; i++){\n Arrays.fill(usedH, false);\n Arrays.fill(usedW, false);\n long res = 0;\n for (int j = 0; j < k; j++){\n if ((i & (1 << j)) == 0) continue;\n if (usedH[h[j]]) continue mask;\n if (usedW[w[j]]) continue mask;\n \n res += r[j];\n usedH[h[j]] = usedW[w[j]] = true;\n }\n \n list.add(res);\n }\n \n Collections.sort(list);\n \n out.print(list.get(t - 1));\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63588bd25d2455a316365f36828a1c0d", "src_uid": "7348b5644f232bf377a4834eded42e4b", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class F {\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tString next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tvoid solve() throws Exception {\n\t\tint n = nextInt(), k = nextInt(), req = nextInt();\n\t\tint upd[] = new int[k];\n\t\tint cost[] = new int[k];\n\n\t\tint cnt = 0;\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tint q = nextInt() - 1, w = nextInt() - 1 + n;\n\t\t\tupd[i] = (1 << q) + (1 << w);\n\t\t\tcost[i] = nextInt();\n\t\t}\n\t\tArrayList all = new ArrayList();\n\t\tfor (int i = 0; i < (1 << k); i++) {\n\t\t\tboolean sat = true;\n\t\t\tint ti = i;\n\t\t\tint mask = 0;\n\t\t\tint ans = 0;\n\t\t\tfor (int j = 0; j < k && sat; j++) {\n\t\t\t\tif (i % 2 == 0) {\n\t\t\t\t\tsat &= ((mask & upd[j]) == 0);\n\t\t\t\t\tmask |= upd[j];\n\t\t\t\t\tans += cost[j];\n\t\t\t\t}\n\t\t\t\ti /= 2;\n\t\t\t}\n\n\t\t\tif (sat)\n\t\t\t\tall.add(ans);\n\t\t\ti = ti;\n\t\t}\n\n\t\tint q = all.size();\n\t\tint a[] = new int[q];\n\t\tfor (int i = 0; i < q; i++)\n\t\t\ta[i] = all.get(i);\n\t\tArrays.sort(a);\n\t\tout.println(a[req - 1]);\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\t\tReader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n\t\t\tWriter writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n\t\t\tin = new BufferedReader(reader);\n\t\t\tout = new PrintWriter(writer);\n\t\t\tsolve();\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\tpublic static void main(String[] args) {\n\t\tnew F().run();\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3ca4509776d8ef40fcfb4eb7d13a3ebe", "src_uid": "7348b5644f232bf377a4834eded42e4b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\nimport static java.util.Arrays.stream;\nimport static java.util.stream.Collectors.toMap;\n\npublic class Main {\n static int n;\n static char[] chars;\n static int[] vals;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n n = sc.nextInt();\n sc.nextLine();\n String s = sc.nextLine().trim();\n chars = s.toCharArray();\n\n vals = new int[n];\n for (int i = 0; i < n; i ++) {\n vals[i] = sc.nextInt();\n }\n sc.nextLine();\n\n List wrongChars = new ArrayList<>();\n List chars1 = new ArrayList<>();\n for (int i = 0; i < n / 2; i++) {\n if (vals[i] > vals[n - i - 1]) {\n swap(i);\n }\n\n Char chr = new Char(chars[i], vals[i], i);\n if (chars[i] == chars[n - i - 1]) {\n wrongChars.add(chr);\n }\n chars1.add(chr);\n }\n chars1.sort(Comparator.comparing(c -> c.val));\n\n int diff = 0;\n// int[] vals1 = Arrays.copyOf(vals, n/2);\n if (!isAntiPalindrome(chars)) {\n if (wrongChars.size() == 1) {\n Char wrongChar = wrongChars.get(0);\n for (int i = 0; i < n/2; i++) {\n Char chr = chars1.get(i);\n if (chr.chr != wrongChar.chr && chars[n - chr.idx - 1] != wrongChar.chr) {\n diff = wrongChar.val + chr.val;\n break;\n }\n }\n } else if (wrongChars.size() > 1) {\n Map map = wrongChars.stream().collect(toMap(n -> n.chr, n -> 1, (a, b) -> a+1, TreeMap::new));\n Map.Entry max = map.entrySet().stream().max(Comparator.comparing(Map.Entry::getValue)).get();\n List append = new ArrayList<>();\n while (max.getValue() * 2 > wrongChars.size() + append.size()) {\n Character maxChar = max.getKey();\n for (int i = 0; i < n/2; i++) {\n Char chr = chars1.get(i);\n if (chr.chr != maxChar && chars[n - chr.idx - 1] != maxChar && !wrongChars.contains(chr)) {\n append.add(chr);\n break;\n }\n }\n }\n diff = wrongChars.stream().mapToInt(chr -> chr.val).sum() + append.stream().mapToInt(chr -> chr.val).sum();\n }\n }\n\n int sum = stream(vals).sum();\n System.out.println(sum - diff);\n }\n\n private static void swap(int i) {\n char tmp = chars[i];\n chars[i] = chars[n - i - 1];\n chars[n - i - 1] = tmp;\n\n int tmpVal = vals[i];\n vals[i] = vals[n - i - 1];\n vals[n - i - 1] = tmpVal;\n }\n\n private static void swap(int i, int j) {\n char tmp = chars[i];\n chars[i] = chars[j];\n chars[j] = tmp;\n\n int tmpVal = vals[i];\n vals[i] = vals[n - i - 1];\n vals[n - i - 1] = tmpVal;\n }\n\n private static boolean isAntiPalindrome(char[] chars) {\n int n = chars.length;\n for (int i = 0; i < n/2; i++) {\n if (chars[i] == chars[n - i - 1]) {\n return false;\n }\n }\n return true;\n }\n\n static class Char {\n char chr;\n int val;\n int idx;\n\n Char(char chr, int val, int idx) {\n this.chr = chr;\n this.val = val;\n this.idx = idx;\n }\n\n @Override\n public String toString() {\n return \"Char{\" +\n \"chr=\" + chr +\n \", val=\" + val +\n \", idx=\" + idx +\n '}';\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11b701e1f8cb63bc3c94f76969c17efd", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\n/**\n * Created by nadya on 28/10/17.\n */\npublic class Educational {\n public static void main(String[] args) throws IOException {\n Educational c = new Educational();\n c.start();\n }\n\n private void start() throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer str = new StringTokenizer(in.readLine());\n int n = Integer.parseInt(str.nextToken());\n String s = in.readLine();\n int b[] = new int[n];\n TreeMap> w = new TreeMap>();\n w.put(0, new HashSet());\n\n\n str = new StringTokenizer(in.readLine());\n for (int i = 0; i < n; ++i) {\n b[i] = Integer.parseInt(str.nextToken());\n if (!w.containsKey(b[i])) w.put(b[i], new HashSet());\n w.get(b[i]).add(i);\n }\n char[] res = s.toCharArray();\n\n\n ArrayList waitingList = new ArrayList();\n for (int i = 0; i < n / 2; ++i) {\n if (res[i] == res[getvisavis(n, i)]) {\n if (waitingList.isEmpty()) {\n waitingList.add(i);\n } else {\n for (Integer j : waitingList) {\n if (res[j] != res[i]) {\n int minB1 = b[j] < b[getvisavis(n, j)] ? j : getvisavis(n, j);\n int minB2 = b[i] < b[getvisavis(n, i)] ? i : getvisavis(n, i);\n swap(res, minB1, minB2);\n b[minB1] = 0;\n b[minB2] = 0;\n waitingList.remove(j);\n break;\n }\n }\n waitingList.add(i);\n }\n }\n }\n\n for (int i = 0; i < n; ++i) {\n // if (b[i] == 0) continue;\n if (!w.containsKey(b[i])) w.put(b[i], new HashSet());\n w.get(b[i]).add(i);\n }\n\n\n for (int i = 0; i < n / 2; ++i) {\n if (res[i] == res[getvisavis(n, i)]) {\n\n boolean finished = false;\n\n int indexToChange = b[i] < b[getvisavis(n, i)] ? i : getvisavis(n, i);\n\n for (Map.Entry> l : w.entrySet()) {\n Set candidates = l.getValue();\n for (Integer j : candidates) {\n if (j == i || j == indexToChange || res[indexToChange] == res[j] || res[indexToChange] == res[getvisavis(n, j)]) {\n continue;\n }\n\n swap(res, indexToChange, j);\n\n b[j] = 0;\n b[indexToChange] = 0;\n\n w.get(0).add(j);\n w.get(0).add(indexToChange);\n\n w.get(b[indexToChange]).remove(indexToChange);\n w.get(b[j]).remove(j);\n\n finished = true;\n break;\n }\n\n if (finished) break;\n }\n if (res[i] == res[getvisavis(n, i)]) System.out.println(\"alarma\");\n }\n }\n for (int i = 0; i < n / 2; ++i) {\n if (res[i] == res[getvisavis(n, i)]) {\n System.out.println(\"FFFF\");\n }\n }\n\n\n int sum = 0;\n for (int i = 0; i < n; ++i) {\n //if (!changed[i]) {\n sum += b[i];\n // }\n }\n\n System.out.println(sum);\n }\n\n public static int getvisavis(int n, int i) {\n return n - i - 1;\n }\n\n public static void swap(char[] a, int i, int j) {\n char t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "738dffcef8132004b9801381ef14fd69", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import com.sun.javafx.geom.Edge;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class F {\n\n\tstatic final int INF = (int)1e9;\n\tstatic ArrayList[] adjList;\n\tstatic int[][] res, cost;\n\tstatic int[] p;\n\n\tstatic void addEdge(int u, int v, int c, int w)\n\t{\n\t\tadjList[u].add(v);\n\t\tadjList[v].add(u);\n\t\tres[u][v] = c;\n\t\tcost[u][v] = w;\n\t\tcost[v][u] = -w;\n\t}\n\n\tstatic int augment(int v, int flow)\n\t{\n\t\tif(v == src)\n\t\t\treturn flow;\n\t\tint u = p[v];\n\t\tflow = augment(u, Math.min(flow, res[u][v]));\n\t\tres[u][v] -= flow;\n\t\tres[v][u] += flow;\n\t\ttotalCost += flow * cost[u][v];\n\t\treturn flow;\n\t}\n\n\tstatic int totalCost;\n\n\tstatic int mcmf(int V)\n\t{\n\t\ttotalCost = 0;\n\n\t\twhile(true)\n\t\t{\n\t\t\tp = new int[V];\n\t\t\tArrays.fill(p, -1);\n\t\t\tp[0] = 0;\n\t\t\tint[] dist = new int[V];\n\t\t\tArrays.fill(dist, INF);\n\t\t\tdist[0] = 0;\n\t\t\tfor(int k = 0; k < V - 1; ++k)\n\t\t\t\tfor(int u = 0; u < V; ++u)\n\t\t\t\t\tfor(int v: adjList[u])\n\t\t\t\t\t\tif(res[u][v] > 0 && dist[v] > dist[u] + cost[u][v])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdist[v] = dist[u] + cost[u][v];\n\t\t\t\t\t\t\tp[v] = u;\n\t\t\t\t\t\t}\n\n\t\t\tif(p[sink] == -1)\n\t\t\t\tbreak;\n\t\t\taugment(sink, INF);\n\t\t}\n\t\treturn totalCost;\n\t}\n\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = sc.nextInt();\n\t\tchar[] s = sc.next().toCharArray();\n\t\tint[] f = new int[26];\n\t\tfor(char c: s)\n\t\t\tf[c - 'a']++;\n\t\tint[] beu = new int[n];\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tsum += beu[i] = sc.nextInt();\n\n\t\tint gateOffset = 2, nodeOffset = gateOffset + n / 2 * 26, charOffset = nodeOffset + n;\n\t\tint V = charOffset + 26;\n\t\tres = new int[V][V];\n\t\tcost = new int[V][V];\n\t\tadjList = new ArrayList[V];\n\t\tfor(int i = 0; i < V; ++i)\n\t\t\tadjList[i] = new ArrayList<>(1);\n\n\t\t// Source and Sink\n\t\tsrc = 0; sink = 1;\n\n\t\t// Source -> Indices Nodes -> Limiter Gates\n\t\tfor(int i = 0; i < n; ++i)\n\t\t{\n\t\t\taddEdge(src, nodeOffset + i, 1, 0);\n\t\t\tfor(int c = 0; c < 26; ++c)\n\t\t\t{\n\t\t\t\tint x = i * 2 < n ? i : n - i - 1;\n\t\t\t\tint gateIn = gateOffset + n / 2 * c + x;\n\t\t\t\taddEdge(nodeOffset + i, gateIn, 1, s[i] - 'a' == c ? 0 : beu[i]);\n\t\t\t}\n\t\t}\n\n\t\t// Limiter Gates -> Characters -> Sink\n\t\tfor(int c = 0; c < 26; ++c)\n\t\t{\n\t\t\taddEdge(charOffset + c, sink, f[c], 0);\n\t\t\tfor(int gate = 0; gate < n / 2; ++gate)\n\t\t\t\taddEdge(gateOffset + n / 2 * c + gate, charOffset + c, 1, 0);\n\t\t}\n\n\t\tout.println(sum - mcmf(V));\n\t\tout.close();\n\t}\n\n\tstatic int src, sink;\n\n\tstatic class Scanner\n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic Scanner(FileReader s) throws FileNotFoundException {\tbr = new BufferedReader(s);}\n\n\t\tpublic String next() throws IOException\n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6aef3f899552e9a2d667ceb186aa3241", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\nimport static java.util.Arrays.stream;\nimport static java.util.stream.Collectors.toMap;\n\npublic class Main {\n static int n;\n static char[] chars;\n static int[] vals;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n n = sc.nextInt();\n sc.nextLine();\n String s = sc.nextLine().trim();\n chars = s.toCharArray();\n\n vals = new int[n];\n for (int i = 0; i < n; i ++) {\n vals[i] = sc.nextInt();\n }\n sc.nextLine();\n\n List wrongChars = new ArrayList<>();\n List chars1 = new ArrayList<>();\n for (int i = 0; i < n / 2; i++) {\n boolean wrong = false;\n if (chars[i] == chars[n - i - 1]) {\n if (vals[i] > vals[n - i - 1]) {\n swap(i);\n }\n wrong = true;\n }\n\n Char chr = new Char(chars[i], vals[i], i);\n if (wrong) wrongChars.add(chr);\n chars1.add(chr);\n }\n chars1.sort(Comparator.comparing(c -> c.val));\n\n int diff = 0;\n// int[] vals1 = Arrays.copyOf(vals, n/2);\n if (!isAntiPalindrome(chars)) {\n if (wrongChars.size() == 1) {\n Char wrongChar = wrongChars.get(0);\n for (int i = 0; i < n/2; i++) {\n Char chr = chars1.get(i);\n if (chr.chr != wrongChar.chr && chars[n - chr.idx - 1] != wrongChar.chr) {\n diff = wrongChar.val + chr.val;\n break;\n }\n }\n } else if (wrongChars.size() > 1) {\n Map map = wrongChars.stream().collect(toMap(n -> n.chr, n -> 1, (a, b) -> a+1, TreeMap::new));\n Map.Entry max = map.entrySet().stream().max(Comparator.comparing(Map.Entry::getValue)).get();\n List append = new ArrayList<>();\n while (max.getValue() * 2 > wrongChars.size() + append.size()) {\n Character maxChar = max.getKey();\n for (int i = 0; i < n/2; i++) {\n Char chr = chars1.get(i);\n if (chr.chr != maxChar && wrongChars.stream().noneMatch(wchr -> chars[n - wchr.idx - 1] != maxChar)) {\n append.add(chr);\n break;\n }\n }\n }\n diff = wrongChars.stream().mapToInt(chr -> chr.val).sum() + append.stream().mapToInt(chr -> chr.val).sum();\n }\n }\n\n int sum = stream(vals).sum();\n System.out.println(sum - diff);\n }\n\n private static void swap(int i) {\n char tmp = chars[i];\n chars[i] = chars[n - i - 1];\n chars[n - i - 1] = tmp;\n\n int tmpVal = vals[i];\n vals[i] = vals[n - i - 1];\n vals[n - i - 1] = tmpVal;\n }\n\n private static void swap(int i, int j) {\n char tmp = chars[i];\n chars[i] = chars[j];\n chars[j] = tmp;\n\n int tmpVal = vals[i];\n vals[i] = vals[n - i - 1];\n vals[n - i - 1] = tmpVal;\n }\n\n private static boolean isAntiPalindrome(char[] chars) {\n int n = chars.length;\n for (int i = 0; i < n/2; i++) {\n if (chars[i] == chars[n - i - 1]) {\n return false;\n }\n }\n return true;\n }\n\n static class Char {\n char chr;\n int val;\n int idx;\n\n Char(char chr, int val, int idx) {\n this.chr = chr;\n this.val = val;\n this.idx = idx;\n }\n\n @Override\n public String toString() {\n return \"Char{\" +\n \"chr=\" + chr +\n \", val=\" + val +\n \", idx=\" + idx +\n '}';\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2a002021124e3e6072a1b2e051922274", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\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[] pCnt;\n\tstatic int[] cCnt;\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\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\tpCnt = new int[P + 1];\n\t\tcCnt = new int[P + 1];\n\n\t\tArrays.fill(pCnt, 1);// if there are no nights left, irrespective of number of sleeping places and as long as\n\t\t\t\t\t\t\t\t// there is at least one bear left, you can always get at most one barrel\n\t\tif (P == B) {\n\t\t\tpCnt[0] = 0;\n\t\t}\n\n\t\tlong ans = 0;\n\t\tfor (int n = 1; n <= Q; n++) {\n\t\t\tfor (int p = 0; p <= P; p++) {\n\t\t\t\tcalculate(p, n);\n\t\t\t}\n\t\t\tint res = n * cCnt[P];\n\t\t\tans ^= Integer.toUnsignedLong(res);\n\t\t\tint[] temp = pCnt;\n\t\t\tpCnt = cCnt;\n\t\t\tcCnt = temp;\n\t\t\tArrays.fill(temp, 0);\n\t\t}\n\t\tprinter.println(ans);\n\t\tprinter.close();\n\t}\n\n\tstatic void calculate(int p, int n) {\n\t\tint b = B - (P - p);\n\t\tint endI = Math.min(b, p);\n\n\t\tint sum = 0;\n\t\tfor (int i = 0; i <= endI; i++) {\n\t\t\tsum += comb(b, i) * pCnt[p - i];\n\t\t}\n\t\tcCnt[p] = sum;\n\t}\n\n\tstatic int comb(int n, int k) {\n\t\tint num = 1;\n\t\tint den = 1;\n\t\tint pow2 = 0;\n\n\t\tif (n - k < k) {\n\t\t\tk = n - k;\n\t\t}\n\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t\tint cPow2 = Integer.numberOfTrailingZeros(i);\n\t\t\tpow2 -= cPow2;\n\t\t\tden = den * (i >> cPow2);\n\n\t\t\tcPow2 = Integer.numberOfTrailingZeros(n + 1 - i);\n\t\t\tpow2 += cPow2;\n\t\t\tnum = num * ((n + 1 - i) >> cPow2);\n\t\t}\n\t\treturn num * inv(den) << pow2;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "40b4e0886712c260a5b4256b1353ee5a", "src_uid": "28cf4ff955d089318ea08d17bc4f43da", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.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.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class F {\n\t\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint p = nextInt();\n\t\tint q = nextInt();\n\t\tif (p >= n) {\n\t\t\tp = n - 1;\n\t\t}\n\t\tint c[] = new int[p + 1];\n\t\tc[0] = 1;\n\t\tfor (int i = 1, val = 1, pow = 0; i <= p; i++) {\n\t\t\tint mul = n - i + 1;\n\t\t\tint shift = Integer.numberOfTrailingZeros(mul);\n\t\t\tval *= mul >> shift;\n\t\t\tpow += shift;\n\t\t\tmul = i;\n\t\t\tshift = Integer.numberOfTrailingZeros(mul);\n\t\t\tval *= BigInteger.valueOf(mul >> shift).modInverse(BigInteger.valueOf(0x100000000L)).intValue();\n\t\t\tpow -= shift;\n\t\t\tc[i] = pow >= 32 ? 0 : val << pow;\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int day = 1; day <= q; day++) {\n\t\t\tint cans = 0;\n\t\t\tfor (int i = 0, pow = 1; i <= p; i++, pow *= day) {\n\t\t\t\tcans += c[i] * pow;\n\t\t\t}\n\t\t\tans ^= day * cans;\n\t\t}\n\t\tout.print(ans & 0xffffffffL);\n\t}\n\t\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0fced64e510681dba284304b338fde48", "src_uid": "28cf4ff955d089318ea08d17bc4f43da", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9aa0cb3c53bfddb4da11027bb0ba91bb", "src_uid": "28cf4ff955d089318ea08d17bc4f43da", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\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[] pCnt;\n\tstatic int[] cCnt;\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\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\tpCnt = new int[P + 1];\n\t\tcCnt = new int[P + 1];\n\n\t\tArrays.fill(pCnt, 1);// if there are no nights left, irrespective of number of sleeping places and as long as\n\t\t\t\t\t\t\t\t// there is at least one bear left, you can always get at most one barrel\n\t\tif (P == B) {\n\t\t\tpCnt[0] = 0;\n\t\t}\n\n\t\tint ans = 0;\n\t\tfor (int n = 1; n <= Q; n++) {\n\t\t\tfor (int p = 0; p <= P; p++) {\n\t\t\t\tcalculate(p, n);\n\t\t\t}\n\t\t\tans ^= n * cCnt[P];\n\t\t\tint[] temp = pCnt;\n\t\t\tpCnt = cCnt;\n\t\t\tcCnt = temp;\n\t\t\tArrays.fill(temp, 0);\n\t\t}\n\t\tprinter.println(ans);\n\t\tprinter.close();\n\t}\n\n\tstatic void calculate(int p, int n) {\n\t\tint b = B - (P - p);\n\t\tint endI = Math.min(b, p);\n\n\t\tint sum = 0;\n\t\tfor (int i = 0; i <= endI; i++) {\n\t\t\tsum += comb(b, i) * pCnt[p - i];\n\t\t}\n\t\tcCnt[p] = sum;\n\t}\n\n\tstatic int comb(int n, int k) {\n\t\tint num = 1;\n\t\tint den = 1;\n\t\tint pow2 = 0;\n\n\t\tif (n - k < k) {\n\t\t\tk = n - k;\n\t\t}\n\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t\tint cPow2 = Integer.numberOfTrailingZeros(i);\n\t\t\tpow2 -= cPow2;\n\t\t\tden = den * (i >> cPow2);\n\n\t\t\tcPow2 = Integer.numberOfTrailingZeros(n + 1 - i);\n\t\t\tpow2 += cPow2;\n\t\t\tnum = num * ((n + 1 - i) >> cPow2);\n\t\t}\n\t\treturn num * inv(den) << pow2;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd26f471a70e3d68ef4130ad46f823a3", "src_uid": "28cf4ff955d089318ea08d17bc4f43da", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n static InputReader r = new InputReader(System.in);\n static PrintWriter pw = new PrintWriter(System.out);\n\n public static void main(String[] args) {\n\n long n = r.nextLong();\n long ring = search(n);\n long prev = gg(ring - 1);\n long section = (n - prev) / ring;\n long rem = n - (prev + (ring * section));\n long x, y;\n if(n == 0){\n System.out.println(\"0 0\");\n return;\n }\n\n if(section == 6){\n section = 0;\n }\n\n if(section == 0){\n x = 2 * ring; y = 0;\n x -= rem; y += (2 * rem);\n } else if(section == 1){\n x = 1 * ring; y = 2 * ring;\n x -= (2 * rem);\n } else if(section == 2){\n x = -1 * ring; y = 2 * ring;\n x -= rem; y -= (2 * rem);\n } else if(section == 3){\n x = -2 * ring; y = 0;\n x += rem; y -= (2 * rem);\n } else if(section == 4){\n x = -1 * ring; y = -2 * ring;\n x += 2 * rem;\n } else{ // (section == 5)\n x = 1 * ring; y = -2 * ring;\n x += rem; y += (2 * rem);\n }\n pw.println(x + \" \" + y + \" \");\n pw.close();\n }\n\n static long search(long n) {\n long left = 0;\n long right = (int) 6E8;\n while (left < right) {\n long mid = left + (right - left) / 2;\n if (gg(mid) < n && gg(mid + 1) > n) {\n return 1 + mid;\n } else if(gg(mid) == n){\n return mid;\n }\n else if (gg(mid) > n) {\n right = mid;\n } else {\n left = mid + 1;\n }\n }\n return -1;\n }\n\n static long gg(long n) {\n return (3 * n * (n + 1));\n }\n}\n\n/**\n * _ _ _ | | | | | | ___ ___ __| | ___ | |__ _ _ __| | __ _ _ __ _ __ ___ _ __ _\n * _ __ _ ___ / __/ _ \\ / _` |/ _ \\ | '_ \\| | | | / _` |/ _` | '__| '__/ _ \\ '_\n * \\ | | | |/ _` |/ _ \\ | (_| (_) | (_| | __/ | |_) | |_| | | (_| | (_| | | | |\n * | __/ | | | | |_| | (_| | (_) | \\___\\___/ \\__,_|\\___| |_.__/ \\__, |\n * \\__,_|\\__,_|_| |_| \\___|_| |_| \\__, |\\__,_|\\___/ __/ | ______ __/ | |___/\n * |______|___/\n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5fbcc697eb9c284794d8bf622976c839", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n int dirs = new int[][]{\n {-2, 0},\n {-1, -2},\n {1, -2},\n {2, 0},\n {1, 2},\n {-1, 2},\n };\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n Pair p = findCell(in.nextLong());\n out.println(p.x + \" \" + p.y);\n }\n\n private Pair findCell(long n) {\n if (n == 0) {\n return new Pair<>(0l, 0l);\n }\n n--;\n // inclusive\n long low = 0, up = n;\n while (low < up) {\n long test = (low + up) / 2;\n long group = test / 6;\n double g = test / 6;\n g = g * (g + 1) * 3 + g + (g + 1) * (test % 6 + 1) + (test % 6 >= 4 ? 1 : 0);\n if (g > n) {\n up = test;\n continue;\n }\n long before = group * (group + 1) * 3 + group;\n long total = before + (group + 1) * (test % 6 + 1) + (test % 6 >= 4 ? 1 : 0);\n if (total < n) { low = test + 1; } else { up = test; }\n }\n long test = low;\n long[] counts = new long[6];\n long group = test / 6;\n Arrays.fill(counts, group * (group + 1) / 2);\n counts[4] += group;\n for (int i = 0; i < test % 6; ++i) { counts[i] += group + 1; }\n if (test % 6 == 5) { counts[4]++; }\n long before = group * (group + 1) * 3 + group;\n long total = before + (group + 1) * (test % 6) + (test % 6 > 4 ? 1 : 0);\n n -= total;\n counts[(int) (test % 6)] += n;\n long x = 1, y = 2;\n for (int i = 0; i < counts.length; i++) {\n x += dirs[i][0] * counts[i];\n y += dirs[i][1] * counts[i];\n }\n return new Pair<>(x, y);\n }\n\n }\n\n static class Pair implements Comparable> {\n public X x;\n public Y y;\n\n public Pair(X x, Y y) {\n this.x = x;\n this.y = y;\n }\n\n public int hashCode() {\n int res = x == null ? 0 : x.hashCode();\n return res * 31 + (y == null ? 0 : y.hashCode());\n }\n\n public boolean equals(Object o) {\n if (this == o) { return true; }\n if (o == null) { return false; }\n if (getClass() != o.getClass()) { return false; }\n Pair p = (Pair) o;\n if ((x == null && p.x != null) || !x.equals(p.x)) { return false; }\n if ((y == null && p.y != null) || !y.equals(p.y)) { return false; }\n return true;\n }\n\n public String toString() {\n return String.format(\"(\" + x + \", \" + y + \")\");\n }\n\n @SuppressWarnings({\"unchecked\"})\n public int compareTo(Pair o) {\n int res = ((Comparable) x).compareTo(o.x);\n if (res != 0) { return res; }\n return ((Comparable) y).compareTo(o.y);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cb22bb4c8740752fcad92944162aa0d5", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main{\n\tstatic class InputReader{\n\t\tpublic BufferedReader r;\n\t\tpublic StringTokenizer t;\n\t\tpublic InputReader(InputStream tmp){\n\t\t\tr = new BufferedReader(new InputStreamReader(tmp), 32768);\n\t\t\tt = null;\n\t\t}\n\t\tpublic String nextString() throws IOException {\n\t\t\twhile(t == null || !t.hasMoreTokens()){\n\t\t\t\tt = new StringTokenizer(r.readLine());\n\t\t\t}\n\t\t\treturn t.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(nextString());\n\t\t}\n\t}\n\tstatic long sum(long l, long r, long cnt){\n\t\tif(cnt == 0){return 0;}\n\t\treturn (l + r) * cnt / 2;\n\t}\n\tstatic boolean can(long id, long n){\n\t\tlong s = 1 + sum(6, 6 * id, id);\n\t\treturn s >= n;\n\t}\n\tstatic long find(long n){\n\t\tlong l = 0, r = 10;\n\t\tfor(int i = 0; i < 15; i++){r *= 10;}\n\t\twhile(r - l > 1){\n\t\t\tlong m = (l + r) / 2;\n\t\t\tif(can(m, n)){\n\t\t\t\tr = m;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tl = m + 1;\n\t\t\t}\n\t\t}\n\t\tif(can(l, n)){return l;}\n\t\treturn r;\n\t}\n\tpublic static void main(String args[]) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tlong n = Long.parseLong(in.readLine());\n\t\tn++;\n\t\tif(n == 1){out.println(0 + \" \" + 0); out.flush(); return;}\n\t\tint id = find(n);\n\t\t//if(1 + sum(6, 6 * id, id) > n){id--;}\n\t\tn -= 2 + sum(6, 6 * (id - 1), id - 1);\n\t\t//out.println(n);\n\t\t//long m = n - id;\n\t\t//if(m < 0){m = m + 6 * (id - 1);}\n\t\tlong m = n + 1;\n\t\tif(m == 6 * id){m = 0;}\n\t\t//out.println(m);\n\t\tlong part = m / (long)id;\n\t\tlong prx = 0;\n\t\tlong pry = 0;\n\t\tlong d = m % (long)id;\n\t\tif(part == 1){\n\t\t\tprx = id;\n\t\t\tpry = 2 * id;\n\t\t\tprx -= 2 * (m % (long)id);\n\t\t}\n\t\tif(part == 2){\n\t\t\tprx = -id;\n\t\t\tpry = 2 * id;\n\t\t\tprx -= (m % (long)id);\n\t\t\tpry -= 2 * (m % (long)id);\n\t\t}\n\t\tif(part == 3){\n\t\t\tprx = -2 * id;\n\t\t\tpry = 0;\n\t\t\tprx += (m % (long)id);\n\t\t\tpry -= 2 * d;\n\t\t}\n\t\tif(part == 4){\n\t\t\tprx = -id;\n\t\t\tpry = -2 * id;\n\t\t\tprx += 2 * d;\n\t\t}\n\t\tif(part == 5){\n\t\t\tprx = id;\n\t\t\tpry = -2 * id;\n\t\t\tprx += d;\n\t\t\tpry += 2 * d;\n\t\t}\n\t\tif(part == 0){\n\t\t\tprx = 2 * id;\n\t\t\tpry = 0;\n\t\t\tprx -= (m % (long)id);\n\t\t\tpry += 2 * (m % (long)id);\n\t\t}\n\t\tout.println(prx + \" \" + pry);\n\t\tout.flush();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "90e4f595a6b8a424d70d2b17e24c4388", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class E {\n\n public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n public static StringTokenizer tok;\n\n public static int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public static long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public static double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public static String nextToken() throws IOException {\n if (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n public static class Pair {\n public long x, y;\n public Pair(long x, long y) {\n this.x = x;\n this.y = y;\n }\n }\n\n public static long func(long number) {\n return number * (3 * number + 2);\n }\n\n public static Pair result(long v, long n) {\n long vLeft = n - func(v);\n long x = v, y = -2 * v;\n v++;\n if (vLeft <= v) {\n x += vLeft;\n y += vLeft * 2;\n return new Pair(x, y);\n }\n x += v;\n y += v * 2;\n vLeft -= v;\n if (vLeft <= v - 1) {\n x -= vLeft;\n y += vLeft * 2;\n return new Pair(x, y);\n }\n x -= v - 1;\n y += (v - 1) * 2;\n vLeft -= v - 1;\n if (vLeft <= v) {\n x -= vLeft * 2;\n return new Pair(x, y);\n }\n x -= v * 2;\n vLeft -= v;\n if (vLeft <= v) {\n x -= vLeft;\n y -= vLeft * 2;\n return new Pair(x, y);\n }\n x -= v;\n y -= v * 2;\n vLeft -= v;\n if (vLeft <= v) {\n x += vLeft;\n y -= vLeft * 2;\n return new Pair(x, y);\n }\n x += v;\n y -= v * 2;\n vLeft -= v;\n x += vLeft * 2;\n return new Pair(x, y);\n }\n\n public static void main(String[] args) throws IOException {\n long n = nextLong();\n long rounds = (long)Math.floor(new BigDecimal(Math.sqrt(new BigDecimal(n).multiply(new BigDecimal(3.0)).add(new BigDecimal(1.0)).doubleValue())).subtract(new BigDecimal(1.0)).doubleValue());\n\n Pair answer = result(rounds, n);\n System.out.println(answer.x + \" \" + answer.y);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "259044856acdb931043e131a8890cc21", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n\npublic class D {\n \n static StringTokenizer st;\n static BufferedReader in;\n static int[]f;\n static ArrayList[]g, gt;\n static boolean[] used, used2;\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 m = nextInt();\n f = new int[n+1];\n for (int i = 1; i <= n; i++) {\n f[i] = nextInt();\n }\n g = new ArrayList[n+1];\n gt = new ArrayList[n+1];\n for (int i = 1; i <= n; i++) {\n g[i] = new ArrayList();\n gt[i] = new ArrayList();\n }\n for (int i = 1; i <= m; i++) {\n int v1 = nextInt();\n int v2 = nextInt();\n g[v1].add(v2);\n gt[v2].add(v1);\n }\n used = new boolean[n+1];\n used2 = new boolean[n+1];\n for (int i = 1; i <= n; i++) {\n if (f[i]==1 && !used[i])\n dfs(i);\n if (f[i]==2 && !used2[i])\n dfs2(i);\n }\n for (int i = 1; i <= n; i++) {\n if (used[i] && used2[i])\n pw.println(1);\n else\n pw.println(0);\n }\n pw.close();\n }\n private static void dfs2(int v) {\n used2[v] = true;\n if (f[v]==1)\n return;\n for (int to : gt[v]) {\n if (!used2[to])\n dfs2(to);\n }\n }\n private static void dfs(int v) {\n used[v] = true;\n for (int to : g[v]) {\n if (!used[to])\n dfs(to);\n }\n }\n private static int nextInt() throws IOException{\n return Integer.parseInt(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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2716fa383c72461435f2e22820594a00", "src_uid": "87d869a0fd4a510c5e7e310886b86a57", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.InputMismatchException;\n\npublic class R3_D2_D {\n static ArrayList[] edge;\n static ArrayList[] revEdge;\n static boolean vis1[];\n static boolean vis2[];\n\n public static void dfs1(int index) {\n if (!vis1[index]) {\n vis1[index] = true;\n for (int a : edge[index])\n dfs1(a);\n }\n }\n\n public static void dfs2(int index) {\n if (!vis2[index]) {\n vis2[index] = true;\n for (int a : revEdge[index])\n dfs2(a);\n }\n }\n\n public static void main(String[] args) {\n // BufferedReader in = new BufferedReader(new\n // InputStreamReader(System.in));\n\n InputReader in = new InputReader(System.in);\n int n = in.readInt();\n int m = in.readInt();\n vis1 = new boolean[n];\n vis2 = new boolean[n];\n int[] inp = new int[n];\n for (int i = 0; i < inp.length; i++) {\n inp[i] = in.readInt();\n }\n edge = new ArrayList[n];\n revEdge = new ArrayList[n];\n for (int j = 0; j < inp.length; j++) {\n edge[j] = new ArrayList();\n revEdge[j] = new ArrayList();\n }\n for (int i = 0; i < m; i++) {\n int a = in.readInt() - 1;\n int b = in.readInt() - 1;\n if(inp[b]==1)\n continue;\n edge[a].add(b);\n revEdge[b].add(a);\n }\n for (int i = 0; i < inp.length; i++) {\n if (inp[i] == 1)\n dfs1(i);\n }\n for (int i = 0; i < inp.length; i++) {\n if (inp[i] == 2)\n dfs2(i);\n }\n for (int i = 0; i < inp.length; i++) {\n if(vis1[i] && vis2[i])\n System.out.println(1);\n else\n System.out.println(0);\n }\n }\n\n public static class tr {\n int x;\n int y;\n int z;\n\n public tr(int a, int b, int c) {\n x = a;\n y = b;\n z = c;\n }\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1000];\n private int curChar, numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n }\n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, readInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8d6ab5c2290079c1e908b035536bcc93", "src_uid": "87d869a0fd4a510c5e7e310886b86a57", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class D {\n\tprivate static void solve() throws IOException {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tf = new int[n+1];\n\t\tboolean[] visF = new boolean[n+1];\n\t\tboolean[] visE = new boolean[n+1];\n\t\tQueue starts = new LinkedList(); //all the locations of starts\n\t\tQueue ends = new LinkedList(); //all the locations of ends\n\t\tfor(int i = 1; i < n+1; i++) {\n\t\t\tf[i] = nextInt();\n\t\t\tif(f[i] == 1)\n\t\t\t\tstarts.add(i);\n\t\t\telse if(f[i] == 2)\n\t\t\t\tends.add(i);\n\t\t}\n\t\tadj = new ArrayList[n+1];\n\t\tback = new ArrayList[n+1];\n\t\tfor(int i = 0; i < n+1; i++) {\n\t\t\tadj[i] = new ArrayList();\n\t\t}\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint f = nextInt();\n\t\t\tint s = nextInt();\n\t\t\tadj[f].add(s);\n\t\t\tback[s].add(f);\n\t\t}\n\t\t//see if can be found from a 1\n\t\twhile(!starts.isEmpty()) {\n\t\t\tint cur = starts.poll();\n\t\t\tif(visF[cur])\n\t\t\t\tcontinue;\n\t\t\tvisF[cur] = true;\n\t\t\tArrayList temp = adj[cur];\n\t\t\tfor(int i = 0; i < temp.size(); i++) {\n\t\t\t\tstarts.add(temp.get(i));\n\t\t\t}\n\t\t}\n\t\twhile(!ends.isEmpty()) {\n\t\t\tint cur = ends.poll();\n\t\t\tif(visE[cur])\n\t\t\t\tcontinue;\n\t\t\tvisE[cur] = true;\n\t\t\tif(f[cur] == 1)\n\t\t\t\tcontinue;\n\t\t\tArrayList temp = back[cur];\n\t\t\tfor(int i = 0; i < temp.size(); i++) {\n\t\t\t\tends.add(temp.get(i));\n\t\t\t}\n\t\t}\n\t\tfor(int i = 1; i < visF.length; i++) {\n\t\t\tif(visF[i] && visE[i])\n\t\t\t\tout.println(1);\n\t\t\telse\n\t\t\t\tout.println(0);\n\t\t}\n\t}\n\tstatic int b, n, m, k, l;\n\tstatic int[] a, f;\n\tstatic ArrayList[] adj, back;\n\t\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\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\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3760d7615992679218a81990cf6b8869", "src_uid": "87d869a0fd4a510c5e7e310886b86a57", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class D {\n\tprivate static void solve() throws IOException {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tf = new int[n+1];\n\t\tboolean[] visF = new boolean[n+1];\n\t\tboolean[] visE = new boolean[n+1];\n\t\tQueue starts = new LinkedList(); //all the locations of starts\n\t\tQueue ends = new LinkedList(); //all the locations of ends\n\t\tfor(int i = 1; i < n+1; i++) {\n\t\t\tf[i] = nextInt();\n\t\t\tif(f[i] == 1)\n\t\t\t\tstarts.add(i);\n\t\t\telse if(f[i] == 2)\n\t\t\t\tends.add(i);\n\t\t}\n\t\tadj = new ArrayList>(m);\n\t\tback = new ArrayList>(m);\n\t\tfor(int i = 0; i < n+1; i++) {\n\t\t\tadj.add(new LinkedList());\n\t\t\tback.add(new LinkedList());\n\t\t}\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint f = nextInt();\n\t\t\tint s = nextInt();\n\t\t\tadj.get(f).add(s);\n\t\t\tback.get(s).add(f);\n\t\t}\n\t\t//see if can be found from a 1\n\t\twhile(!starts.isEmpty()) {\n\t\t\tint cur = starts.poll();\n\t\t\tif(visF[cur])\n\t\t\t\tcontinue;\n\t\t\tvisF[cur] = true;\n\t\t\tLinkedList temp = adj.get(cur);\n\t\t\tfor(int i = 0; i < temp.size(); i++) {\n\t\t\t\tstarts.add(temp.get(i));\n\t\t\t}\n\t\t}\n\t\twhile(!ends.isEmpty()) {\n\t\t\tint cur = ends.poll();\n\t\t\tif(visE[cur])\n\t\t\t\tcontinue;\n\t\t\tvisE[cur] = true;\n\t\t\tif(f[cur] == 1)\n\t\t\t\tcontinue;\n\t\t\tLinkedList temp = back.get(cur);\n\t\t\tfor(int i = 0; i < temp.size(); i++) {\n\t\t\t\tends.add(temp.get(i));\n\t\t\t}\n\t\t}\n\t\tfor(int i = 1; i < visF.length; i++) {\n\t\t\tif(visF[i] && visE[i])\n\t\t\t\tout.println(1);\n\t\t\telse\n\t\t\t\tout.println(0);\n\t\t}\n\t}\n\tstatic int b, n, m, k, l;\n\tstatic int[] a, f;\n\tstatic ArrayList> adj, back;\n\t\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\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\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cfcde6846c53bcacc66100db337b1495", "src_uid": "87d869a0fd4a510c5e7e310886b86a57", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n FastScanner in;\n PrintWriter out;\n\n int gcd(int x, int y) {\n return x == 0 ? y : gcd(y % x, x);\n }\n\n int getCost(int n, boolean[] already) {\n boolean[] z = new boolean[n];\n for (int x = 3; x < n; x++) {\n if (!already[x]) {\n continue;\n }\n int g = gcd(n, x);\n int add = n / g;\n for (int i = 0; i < n; i += add) {\n z[i] = true;\n }\n }\n int cost = 0;\n for (int i = 0; i < n; i++) {\n cost += z[i] ? 0 : 1;\n }\n return cost;\n }\n\n int getAns(int maxN, int k) {\n int res = 0;\n boolean[] already = new boolean[maxN + 1];\n for (int it = 0; it < k; it++) {\n int mincost = Integer.MAX_VALUE;\n int minVal = -1;\n for (int n = 3; n <= maxN; n++) {\n if (already[n]) {\n continue;\n }\n int cost = getCost(n, already);\n if (cost < mincost) {\n mincost = cost;\n minVal = n;\n }\n }\n already[minVal] = true;\n res += mincost;\n }\n return res;\n }\n\n void solve() {\n out.println(getAns(in.nextInt(), in.nextInt()));\n }\n\n void solve123() {\n for (int n = 3; n <= 50; n++) {\n boolean[] z = new boolean[n];\n for (int x = 3; x < n; x++) {\n int g = gcd(n, x);\n int add = n / g;\n for (int i = 0; i < n; i += add) {\n z[i] = true;\n }\n }\n int cost = 0;\n for (int i = 0; i < n; i++) {\n cost += z[i] ? 0 : 1;\n }\n System.err.println(n + \" -> \" + cost);\n }\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"A.in\"));\n out = new PrintWriter(new File(\"A.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new A().runIO();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad20f41def97446f87229ffe1c76acd8", "src_uid": "c2f7012082c84d773c2f4b1858c17110", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*; \nimport java.math.BigInteger;\nimport java.util.*;\n \npublic class Main {\n\tstatic final long MOD = 998244353;\n\tstatic int[] primes;\n\tstatic int P;\n public static void main(String[] args) throws IOException {\n FastScanner sc=new FastScanner();\n int N = sc.nextInt();\n int K = sc.nextInt();\n primes = new int[78498];\n primes[0] = 2;\n P = 1;\n for (int num = 3; num <= N; num++) {\n \tboolean prime = true;\n \tfor (int i = 0; i < P; i++) {\n \t\tif (num % primes[i] == 0) {\n \t\t\tprime = false;\n \t\t\tbreak;\n \t\t}\n \t\tif (primes[i]*primes[i] > num) {\n \t\t\tbreak;\n \t\t}\n \t}\n \tif (prime) {\n \t\tprimes[P] = num;\n \t\tP++;\n \t}\n }\n int[][] totients = new int[N+1][2];\n HashMap getT = new HashMap();\n getT.put(1,1);\n getT.put(2,1);\n for (int i = 0; i <= N; i++) {\n \tif (i < 3) {\n \t\ttotients[i][0] = Integer.MAX_VALUE;\n \t\tcontinue;\n \t}\n \ttotients[i][0] = totient(i);\n \ttotients[i][1] = i;\n \tgetT.put(i,totients[i][0]);\n }\n Arrays.sort(totients, new Comparator() {\n \t @Override\n \t public int compare(int[] arr1, int[] arr2) {\n \t return arr1[0]-arr2[0];\n \t }\n });\n \n long ans = 2;\n for (int i = 0; i < K; i++)\n \tans += totients[i][0];\n System.out.println(ans);\n }\n \n public static int totient(int n) {\n \t//From Geeks4Geeks\n int result = n; \n for (int p: primes) {\n \tif (p == 0 || p * p > n) {\n \t\tbreak;\n \t}\n if (n % p == 0) { \n while (n % p == 0) \n n /= p; \n result -= result / p; \n } \n }\n if (n > 1) \n result -= result / n; \n return result; \n }\n \n static class FastScanner { \n BufferedReader br; \n StringTokenizer st; \n \n public FastScanner() \n { \n br = new BufferedReader(new\n InputStreamReader(System.in)); \n } \n \n String next() \n { \n while (st == null || !st.hasMoreElements()) \n { \n try\n { \n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n \n int nextInt() \n { \n return Integer.parseInt(next()); \n } \n \n long nextLong() \n { \n return Long.parseLong(next()); \n } \n \n double nextDouble() \n { \n return Double.parseDouble(next()); \n } \n \n String nextLine() \n { \n String str = \"\"; \n try\n { \n str = br.readLine(); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n return str; \n } \n }\n}\n\nclass Node {\n\tpublic int n;\n\tpublic HashSet children;\n\t\n\tpublic Node(int n) {\n\t\tthis.n = n;\n\t\tchildren = new HashSet();\n\t}\n\t\n\tpublic void addChild(Node node) {\n\t\tchildren.add(node);\n\t}\n\t\n\tpublic void removeChild(Node node) {\n\t\tchildren.remove(node);\n\t}\n}\n\nclass BinaryIndexedTree {\n\t public long[] arr;\n\n\t public BinaryIndexedTree (int N) {\n\t arr = new long[N+1];\n\t arr[0] = 0;\n\t }\n\n\t //add k to the i-th element.\n\t public void add(long k, int i) {\n\t int node = i+1;\n\t while (node < arr.length) {\n\t arr[node] += k;\n\t node += node & (-node);\n\t }\n\t }\n\n\t //sum up the elements from input[s_i] to input[e_i], from [s_i,e_i).\n\t public long sum(int s_i, int e_i) {\n\t return sum(e_i) - sum(s_i);\n\t }\n\n\t public long sum(int i) {\n\t long total = 0;\n\t int node = i;\n\t while (node > 0) {\n\t total += arr[node];\n\t node -= node & (-node);\n\t }\n\t return total;\n\t }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fb614d6c883a392e95022147052f73d4", "src_uid": "c2f7012082c84d773c2f4b1858c17110", "difficulty": 2800.0} {"lang": "Java 8", "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 int 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 int ans = INF;\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<0){s/=10;ans++;}return ans;}\n long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n void p(Object o){out.print(o);}\n void pn(Object o){out.println(o);}\n void pni(Object o){out.println(o);out.flush();}\n String n()throws Exception{return in.next();}\n String nln()throws Exception{return in.nextLine();}\n int ni()throws Exception{return Integer.parseInt(in.next());}\n long nl()throws Exception{return Long.parseLong(in.next());}\n double nd()throws Exception{return Double.parseDouble(in.next());}\n \n class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n public FastReader(String s) throws Exception{\n br = new BufferedReader(new FileReader(s));\n }\n \n String next() throws Exception{\n while (st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine());\n }catch (IOException e){\n throw new Exception(e.toString());\n }\n }\n return st.nextToken();\n }\n \n String nextLine() throws Exception{\n String str = \"\";\n try{ \n str = br.readLine();\n }catch (IOException e){\n throw new Exception(e.toString());\n } \n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e824f8d6e1db9f1493bb1991e0d807c0", "src_uid": "c2f7012082c84d773c2f4b1858c17110", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces1208G {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\n\t\tif (k == 1) {\n\t\t\tSystem.out.println(3);\n\t\t}\n\t\telse {\n\t\t\tint[] phitable = new int[n+1];\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tphitable[i] += i;\n\t\t\t\tfor (int j = 2; j <= n/i; j++) {\n\t\t\t\t\tphitable[i*j] -= phitable[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tsort(phitable);\n\t\t\tlong ans = 0;\n\t\t\tfor (int i = 1; i <= (k+2); i++) {\n\t\t\t\tans += (long) phitable[i];\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void sort(int[] array) {\n \tint N import java.io.*;\nimport java.util.*;\n\npublic class Codeforces1208G {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\n\t\tif (k == 1) {\n\t\t\tSystem.out.println(3);\n\t\t}\n\t\telse {\n\t\t\tint[] phitable = new int[n+1];\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tphitable[i] += i;\n\t\t\t\tfor (int j = 2; j <= n/i; j++) {\n\t\t\t\t\tphitable[i*j] -= phitable[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tsort(phitable);\n\t\t\tlong ans = 0;\n\t\t\tfor (int i = 1; i <= (k+2); i++) {\n\t\t\t\tans += (long) phitable[i];\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void sort(int[] array) {\n \tint N = array.length;\n \tif (N != 1) {\n \t\tint[] firstHalf = Arrays.copyOfRange(array, 0, N/2);\n \t\tsort(firstHalf);\n \tint[] secondHalf = Arrays.copyOfRange(array, N/2, N);\n \tsort(secondHalf);\n \tint firstCounter = 0;\n \tint secondCounter = 0;\n \tfor (int i = 0; i < N; i++) {\n \t\tif (firstCounter == N/2) {\n \t\t\tarray[firstCounter+secondCounter] = secondHalf[secondCounter];\n \t\t\tsecondCounter++;\n \t\t}\n \t\telse if ((secondCounter == N-N/2) || firstHalf[firstCounter] <= secondHalf[secondCounter]) {\n \t\t\tarray[firstCounter+secondCounter] = firstHalf[firstCounter];\n \t\t\tfirstCounter++;\n \t\t}\n \t\telse {\n \t\t\tarray[firstCounter+secondCounter] = secondHalf[secondCounter];\n \t\t\tsecondCounter++;\n \t\t}\n \t}\n \t}\t\n }\t\n\n}= array.length;\n \tif (N != 1) {\n \t\tint[] firstHalf = Arrays.copyOfRange(array, 0, N/2);\n \t\tsort(firstHalf);\n \tint[] secondHalf = Arrays.copyOfRange(array, N/2, N);\n \tsort(secondHalf);\n \tint firstCounter = 0;\n \tint secondCounter = 0;\n \tfor (int i = 0; i < N; i++) {\n \t\tif (firstCounter == N/2) {\n \t\t\tarray[firstCounter+secondCounter] = secondHalf[secondCounter];\n \t\t\tsecondCounter++;\n \t\t}\n \t\telse if ((secondCounter == N-N/2) || firstHalf[firstCounter] <= secondHalf[secondCounter]) {\n \t\t\tarray[firstCounter+secondCounter] = firstHalf[firstCounter];\n \t\t\tfirstCounter++;\n \t\t}\n \t\telse {\n \t\t\tarray[firstCounter+secondCounter] = secondHalf[secondCounter];\n \t\t\tsecondCounter++;\n \t\t}\n \t}\n \t}\t\n }\t\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7d8b84c2cb925e3c2bc0c79482d6a9a8", "src_uid": "c2f7012082c84d773c2f4b1858c17110", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/29/11\n * Time: 7:56 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskD {\n\n final int MOD = 1000000007;\n\n void run() {\n String start = next();\n String end = next();\n int K = nextInt();\n int N = start.length();\n\n if (K == 0) {\n if (start.equals(end)) {\n System.out.println(1);\n } else {\n System.out.println(0);\n }\n\n return;\n }\n\n int zero = (N - 1) * (K - 1);\n long rest = 1;\n for (int i = 0; i < K - 1; i++) {\n rest *= (N - 1);\n rest %= MOD;\n }\n rest = (rest - K + 1) % MOD;\n\n int[] dp = new int[N];\n dp[0] = zero;\n for (int i = 1; i < N; i++) dp[i] = (int)rest;\n\n int ans = 0;\n String s1, s2;\n for (int i = 0; i < N; i++) {\n s1 = start.substring(0, i);\n s2 = start.substring(i);\n\n if (end.equals(s2.concat(s1))) {\n ans += dp[i];\n if (ans >= MOD) ans -= MOD;\n }\n }\n\n System.out.println(ans);\n }\n\n int nextInt() {\n try {\n int c = System.in.read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n long nextLong() {\n try {\n int c = System.in.read();\n if (c == -1) return -1;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return -1;\n }\n if (c == '-') return -nextLong();\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String next() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (Character.isWhitespace(c))\n c = System.in.read();\n do {\n res.append((char) c);\n } while (!Character.isWhitespace(c = System.in.read()));\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n String nextLine() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (c == '\\r' || c == '\\n')\n c = System.in.read();\n do {\n res.append((char) c);\n c = System.in.read();\n } while (c != '\\r' && c != '\\n');\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n public static void main(String[] args) {\n new TaskD().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66ee10fff98ffa389d8f6e723124884d", "src_uid": "414000abf4345f08ede20798de29b9d4", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class D {\n\n\tfinal int MOD = 1000000007;\n\tfinal double eps = 1e-9;\n\n\tint mod(long x) { return (int)((x + 1L*MOD*MOD) % MOD); }\n\n\tpublic D () throws IOException {\n\t\tString START = sc.next();\n\t\tString END = sc.next();\n\t\tint K = sc.nextInt();\n\n\t\tint N = START.length();\n\t\tint A0 = 1, A = 0, S = 1;\n\t\tfor (int k = 1; k <= K; ++k) {\n\t\t\tint B0 = mod(S - A), B = mod(S - A0);\n\t\t\tA0 = B0; A = B; S = mod(1L*(N-1)*A + A0);\n\t\t}\n\n\t\tint res = 0;\n\t\tif (START.equals(END))\n\t\t\tres = mod(res + A0);\n\t\tfor (int i = 1; i < N; ++i)\n\t\t\tif ((START.substring(i, N) + START.substring(0, i)).equals(END))\n\t\t\t\t\tres = mod(res + A);\n\t\texit(res);\n\t}\n\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\texit();\n\t}\n\n\tstatic void exit () {\n\t\tSystem.err.println((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\tstart();\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 D();\n\t}\n\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a7407c99284501c0b2c8c69138cae5b6", "src_uid": "414000abf4345f08ede20798de29b9d4", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class D {\n\n\tpublic D () throws IOException {\n\t\tString S = sc.next();\n\t\tString E = sc.next();\n\t\tint K = sc.nextInt();\n\t\tsolve(S,E,K);\n\t}\n\t\n\tint MOD = 1000000007;\n\t\n\tpublic void solve (String S, String E, int K) {\n\t\tif (K == 0){\n\t\t\tif (S.equals(E)) exit(1);\n\t\t\telse exit(0);\n\t\t}\n\n\t\tint N = S.length(), sum = 1;\n\t\tint [] A = new int [N]; A[0] = 1;\n\t\tfor (int k = 1; k <= K; ++k) {\n\t\t\tint [] B = new int [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tB[i] = (sum - A[i]) % MOD;\n\t\t\tsum = 0;\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tsum = (sum + B[i]) % MOD;\n\t\t\tA = B;\n\t\t}\n\t\t\n\t\tint res = 0;\n\t\tfor (int i = 0; i < N; ++i) {\n\t\t\tif ((S.substring(i, N) + S.substring(0, i)).equals(E))\n\t\t\t\t\tres += A[i];\n\t\t}\n\t\t\n\t\texit(res);\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic MyScanner sc;\n\tstatic long t;\n\t\n\tstatic void print (Object o) {\n\t\tSystem.out.println(o);\n\t}\n\t\n\tstatic void exit (Object o) {\n\t\tprint(o);\n\t\t//print2((millis() - t) / 1000.0);\n\t\tSystem.exit(0);\n\t}\n\t\n\tstatic void run () throws IOException {\n\t\tsc = new MyScanner ();\n\t\tnew D();\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\trun();\n\t}\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\n\t\n\tstatic void start() {\n\t\tt = millis();\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\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\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 || index == line.length) {\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}\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "39c919bfcaf4ad70d4eb94f85c4cb1ba", "src_uid": "414000abf4345f08ede20798de29b9d4", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class D {\n\n\tpublic D () throws IOException {\n\t\tString S = sc.next();\n\t\tString E = sc.next();\n\t\tint K = sc.nextInt();\n\t\tsolve(S,E,K);\n\t}\n\t\n\tint MOD = 1000000007;\n\t//BigInteger BMOD = BigInteger.valueOf(MOD);\n\tint mod(long x) { return (int)((x + MOD*MOD) % MOD); }\n\t\n\tpublic void solve (String S, String E, int K) {\n\t\tif (K == 0){\n\t\t\tif (S.equals(E)) exit(1);\n\t\t\telse exit(0);\n\t\t}\n\n\t\tint N = S.length(), sum = 1;\n\t\tint [] A = new int [N]; A[0] = 1;\n\t\tfor (int k = 1; k <= K; ++k) {\n\t\t\tint [] B = new int [N];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tB[i] = mod(sum - A[i]);\n\t\t\tsum = 0;\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tsum = mod(sum + B[i]);\n\t\t\tA = B;\n\t\t}\n\t\t\n\t\tint res = 0;\n\t\tfor (int i = 0; i < N; ++i) {\n\t\t\tif ((S.substring(i, N) + S.substring(0, i)).equals(E))\n\t\t\t\t\tres = mod(res + A[i]);\n\t\t}\n\t\t\n\t\texit(res);\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic MyScanner sc;\n\tstatic long t;\n\t\n\tstatic void print (Object o) {\n\t\tSystem.out.println(o);\n\t}\n\t\n\tstatic void exit (Object o) {\n\t\tprint(o);\n\t\t//print2((millis() - t) / 1000.0);\n\t\tSystem.exit(0);\n\t}\n\t\n\tstatic void run () throws IOException {\n\t\tsc = new MyScanner ();\n\t\tnew D();\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\trun();\n\t}\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\n\t\n\tstatic void start() {\n\t\tt = millis();\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\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\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 || index == line.length) {\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}\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ae8d36c022a56eac637bfb1bf47be80b", "src_uid": "414000abf4345f08ede20798de29b9d4", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class project{\n public static void main(String[]args){\n\tScanner ss = new Scanner(System.in);\n\tint n =ss.nextInt(), k=ss.nextInt(), cur1=0,cur2=0,cur3=0;\n\tString s = ss.next();\n\t\n\tint iscan1 = 0;\n\tfor(int i=0;ik)\n {\n System.out.println(\"NO\");\n \n }\n else\n {\n boolean vyv = false;\n for(int i=1;i<=n;i++)\n {\n //cout<=0 and s[st-1] == 'N') continue;\n if (en +1 = n) {\n break;\n }\n\n boolean ok = true;\n for (int j = st; j <= en; ++j) {\n if (s.charAt(j) == 'Y') {\n ok = false;\n }\n }\n if (ok) {\n found = true;\n break;\n }\n }\n\n int maxn = 0;\n\n for (int i = 0; i < n; ++i) {\n if (s.charAt(i) != 'N') {\n continue;\n }\n int cnt = 1;\n int j = i + 1;\n while (j < n && s.charAt(j) == 'N') {\n ++cnt;\n ++j;\n }\n\n if (cnt > maxn) {\n maxn = cnt;\n }\n }\n\n if (found && maxn <= k) {\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bbd2b89cdb90068cbdf36a8f759100f9", "src_uid": "5bd578d3da5837c259b222336a194d12", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Sol{\n public static void main(String[] argc){\n Scanner sc = new Scanner(System.in);\n int n, k;\n String s;\n n = sc.nextInt();\n k = sc.nextInt();\n s = sc.next();\n\n boolean found = false;\n for (int i = 0; i < n; ++i) {\n int st = i;\n int en = i + k - 1;\n if (st -1 >=0 and s\u2024charAt(st-1) == 'N') {\n continue;\n }\n if (en +1 = n) {\n break;\n }\n\n boolean ok = true;\n for (int j = st; j <= en; ++j) {\n if (s.charAt(j) == 'Y') {\n ok = false;\n }\n }\n if (ok) {\n found = true;\n break;\n }\n }\n\n int maxn = 0;\n\n for (int i = 0; i < n; ++i) {\n if (s.charAt(i) != 'N') {\n continue;\n }\n int cnt = 1;\n int j = i + 1;\n while (j < n && s.charAt(j) == 'N') {\n ++cnt;\n ++j;\n }\n\n if (cnt > maxn) {\n maxn = cnt;\n }\n }\n\n if (found && maxn <= k) {\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5a29ab06a20b4dc3a40ad8dfc1d20809", "src_uid": "5bd578d3da5837c259b222336a194d12", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class abc\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n int n =s c.nextInt();\n int[] arr = new int[n];\n \n for(int i =0;i=0){\n\t\t\t\tint x = in1.nextInt();\n\t\t\t\tnn[ii]=x;\n\t\t\t\tString t = String.valueOf(x);\n\t\t\t\tint sum=0;\t\n\t\t\t\tfor(int i = 0 ; i < t.length(); i++){\n\t\t\t\t\tsum+=Integer.valueOf(t.charAt(i));\t\t\n\t\t\t\t}\n\t\t\t\ta[ii]=sum;\n\t\t\t\tii++;\n\t\t\t}\n\t\tArrays.sort(a);\n\t\tArrays.sort(nn);\n\t\tint x = a.length/2;\n\t\tSystem.out.println(nn[x]);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "551b16ad2d96e0ed0f9a64c6bcf861a9", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0} {"lang": "Java 8", "source_code": "// CoDE deVELOPed uNDEr AcE proDUcTiONS (enJOY!!!!)\nimport java.util.*;\n\npublic class Ace\n{\n public static void main(String[] args)\n {\n MathTools m=new MathTools();\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int[] ar=new int[n];\n for(int i=0;i= result)\n\t\t\treturn;\n\n\t\tif (step == numbersCount) {\n\t\t\tresult = Math.min(result, currentVertexes);\n\t\t} else {\n\t\t\tfor (int i = 0; i < numbersCount; i++) {\n\t\t\t\tif (!used[i]) {\n\t\t\t\t\tused[i] = true;\n\t\t\t\t\tlong number = numbers[i];\n\t\t\t\t\tboolean end = false;\n\n\t\t\t\t\t// add tree\n\t\t\t\t\t{\n\t\t\t\t\t\ttreesRoots[treesCount] = number;\n\t\t\t\t\t\tisLeaf[treesCount] = true;\n\t\t\t\t\t\trec(step + 1, numbersCount, numbers, used,\n\t\t\t\t\t\t\t\ttreesNearRoot + 1, treesCount + 1, treesRoots,\n\t\t\t\t\t\t\t\tisLeaf);\n\n\t\t\t\t\t\tif (currentVertexes >= result)\n\t\t\t\t\t\t\tend = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// add to another tree\n\t\t\t\t\tfor (int j = 0; j < treesCount && !end; j++) {\n\t\t\t\t\t\tif (treesRoots[j] % number == 0) {\n\t\t\t\t\t\t\ttreesRoots[j] /= number;\n\t\t\t\t\t\t\tboolean backUpIsLeaf = isLeaf[j];\n\t\t\t\t\t\t\tisLeaf[j] = false;\n\t\t\t\t\t\t\ttreesRoots[treesCount] = number;\n\t\t\t\t\t\t\tisLeaf[treesCount] = true;\n\n\t\t\t\t\t\t\trec(step + 1, numbersCount, numbers, used,\n\t\t\t\t\t\t\t\t\ttreesNearRoot, treesCount + 1, treesRoots,\n\t\t\t\t\t\t\t\t\tisLeaf);\n\n\t\t\t\t\t\t\ttreesRoots[j] *= number;\n\t\t\t\t\t\t\tisLeaf[j] = backUpIsLeaf;\n\n\t\t\t\t\t\t\tif (currentVertexes >= result)\n\t\t\t\t\t\t\t\tend = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tused[i] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate int getVertexes(int treesNearRoot, int treesCount,\n\t\t\tlong[] treesRoots, boolean[] isLeaf) {\n\t\tint vertexes = (treesNearRoot > 1 ? 1 : 0);\n\t\tfor (int i = 0; i < treesCount; i++) {\n\t\t\tint childs = getPrimes(treesRoots[i]);\n\t\t\tint add = (childs <= 1 && isLeaf[i]) ? 1 : (1 + childs);\n\t\t\tvertexes += add;\n\t\t}\n\t\treturn vertexes;\n\t}\n\n\tMap cache = new HashMap();\n\n\tprivate int getPrimes(long n) {\n\t\tif (n == 1)\n\t\t\treturn 0;\n\t\tInteger cacheValue = cache.get(n);\n\t\tif (cacheValue != null)\n\t\t\treturn cacheValue;\n\t\tint result = 1;\n\t\tfor (long i = 2; i * i <= n; i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\tresult = 1 + getPrimes(n / i);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tcache.put(n, result);\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew C().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(1);\n\t\t}\n\t}\n\n\tprivate String 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\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\n\t\treturn st.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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9626a1877818f27cf9b987a91d3db975", "src_uid": "52b8b6c68518d5129272b8c56e5b7662", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic final int INF = Integer.MAX_VALUE / 3;\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic int N = 1_000_000;\n\tstatic int ROOT = 1_000;\n\tstatic boolean[] isPrime = new boolean[N + 1];\n\tstatic List primes = new ArrayList<>(78498);\n\tstatic {\n\t\tArrays.fill(isPrime, true);\n\t\tfor (int i = 2; i <= N; i++) {\n\t\t\tif (isPrime[i]) {\n\t\t\t\tprimes.add(i);\n\t\t\t\tif (i <= ROOT) {\n\t\t\t\t\tfor (int j = i * i; j <= N; j += i) {\n\t\t\t\t\t\tisPrime[j] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tint n;\n\tlong[] a;\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\ta = new long[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextLong();\n\t\t}\n\n\t\tArrays.sort(a);\n\n\t\tint ans = go(n - 1, new ArrayList());\n\t\tout.println(ans);\n\t}\n\n\tint go(int i, List vs) {\n\t\tif (i == -1) {\n\t\t\tint ret = 0;\n\n\t\t\tfor (long x : vs) {\n\t\t\t\tint val = sumPrimePowers(x);\n\t\t\t\tret += val + 1;\n\t\t\t}\n\n\t\t\tif (vs.size() > 1)\n\t\t\t\tret++;\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tint ret = Integer.MAX_VALUE;\n\n\t\tlong add = a[i];\n\t\tfor (int j = 0; j < vs.size(); j++) {\n\t\t\tif (vs.get(j) % add == 0) {\n\t\t\t\tList newVs = new ArrayList<>(vs);\n\n\t\t\t\tnewVs.set(j, vs.get(j) / add);\n\t\t\t\tif (sumPrimePowers(add) > 1) {\n\t\t\t\t\tnewVs.add(add);\n\t\t\t\t} else {\n\t\t\t\t\tnewVs.add(1L);\n\t\t\t\t}\n\t\t\t\tret = Math.min(ret, go(i - 1, newVs));\n\t\t\t}\n\t\t}\n\t\tif (sumPrimePowers(add) == 1) {\n\t\t\tvs.add(1L);\n\t\t} else {\n\t\t\tvs.add(add);\n\t\t}\n\t\tret = Math.min(ret, go(i - 1, vs));\n\t\treturn ret;\n\t}\n\n\tint sumPrimePowers(long x) {\n\t\tint ret = 0;\n\t\tfor (int i = 0; i < primes.size(); i++) {\n\t\t\tint p = primes.get(i);\n\t\t\twhile (x % p == 0) {\n\t\t\t\tx /= p;\n\t\t\t\tret++;\n\t\t\t}\n\t\t}\n\t\tif (x != 1)\n\t\t\tret++;\n\t\treturn ret;\n\t}\n\n\tC() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "062abc75624c540902ae6bb84dccaa1f", "src_uid": "52b8b6c68518d5129272b8c56e5b7662", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic final int INF = Integer.MAX_VALUE / 3;\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic int N = 1_000_000;\n\tstatic int ROOT = 1_000;\n\tstatic boolean[] isPrime = new boolean[N + 1];\n\tstatic List primes = new ArrayList<>(78498);\n\tstatic {\n\t\tArrays.fill(isPrime, true);\n\t\tfor (int i = 2; i <= N; i++) {\n\t\t\tif (isPrime[i]) {\n\t\t\t\tprimes.add(i);\n\t\t\t\tif (i <= ROOT) {\n\t\t\t\t\tfor (int j = i * i; j <= N; j += i) {\n\t\t\t\t\t\tisPrime[j] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tint n;\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tlong[] a = new long[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextLong();\n\t\t}\n\n\t\tdp = new int[1 << n][n + 2];\n\t\t// [0..n) - root\n\t\t// n - no root\n\t\t// n + 1 - min of all\n\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tArrays.fill(dp[mask], INF);\n\t\t\tif (Integer.bitCount(mask) == 1) {\n\t\t\t\tint pos = Integer.numberOfTrailingZeros(mask);\n\t\t\t\tint val = sumPrimePowers(a[pos]);\n\t\t\t\tif (val > 1)\n\t\t\t\t\tval++;\n\t\t\t\tdp[mask][pos] = dp[mask][n + 1] = val;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int root = 0; root < n; root++) {\n\t\t\t\tif (test(mask, root)) {\n\t\t\t\t\tint noRoot = mask ^ (1 << root);\n\t\t\t\t\tfor (int sub = noRoot; sub > 0; sub = (sub - 1) & noRoot) {\n\t\t\t\t\t\tlong rest = a[root];\n\t\t\t\t\t\tboolean badSub = false;\n\t\t\t\t\t\t\n//\t\t\t\t\t\tif (mask == 14 && root == 1 && sub == 4) {\n//\t\t\t\t\t\t\tSystem.err.println(\"?\");\n//\t\t\t\t\t\t}\n\n\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\tif (test(sub, i)) {\n\t\t\t\t\t\t\t\tif (rest % a[i] == 0) {\n\t\t\t\t\t\t\t\t\trest /= a[i];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tbadSub = true;\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\n\t\t\t\t\t\tif (badSub)\n\t\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\t\tint add = 1 + sumPrimePowers(rest);\n\t\t\t\t\t\tif (add == 1)\n\t\t\t\t\t\t\tadd = 0;\n\t\t\t\t\t\tdp[mask][root] = Math.min(dp[mask][root],\n\t\t\t\t\t\t\t\tauxDP(noRoot, sub) + add);\n\t\t\t\t\t}\n\t\t\t\t\tdp[mask][n + 1] = Math.min(dp[mask][n + 1], dp[mask][root]);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdp[mask][n] = auxDp(mask) + 1;\n\t\t\tdp[mask][n + 1] = Math.min(dp[mask][n + 1], dp[mask][n]);\n\t\t}\n\n\t\tout.println(dp[(1 << n) - 1][n + 1]);\n\t}\n\n\tint[][] dp;\n\n\tint auxDp(int tot) {\n\t\tint[] curDp = new int[1 << n];\n\t\tcurDp[0] = 0;\n\t\tfor (int mask = 1; mask <= tot; mask++) {\n\t\t\tif ((mask & tot) != mask)\n\t\t\t\tcontinue;\n\t\t\tint start = (mask == tot) ? ((tot - 1) & tot) : mask;\n\t\t\tcurDp[mask] = INF;\n\t\t\tfor (int sub = start; sub > 0; sub = (sub - 1) & mask) {\n\t\t\t\tcurDp[mask] = Math.min(curDp[mask], dp[sub][n + 1]\n\t\t\t\t\t\t+ curDp[mask ^ sub]);\n\t\t\t}\n\t\t}\n\t\treturn curDp[tot];\n\t}\n\n\tint auxDP(int tot, int roots) {\n\t\tif ((tot & roots) != roots)\n\t\t\tthrow new AssertionError();\n\t\tint[] curDp = new int[1 << n];\n\t\tint[] newDp = new int[1 << n];\n\t\tArrays.fill(curDp, INF);\n\t\tcurDp[0] = 0;\n\t\tfor (int pos = 0; pos < n; pos++) {\n\t\t\tif (test(roots, pos)) {\n\t\t\t\tArrays.fill(newDp, INF);\n\n\t\t\t\tfor (int newMask = 0; newMask < (1 << n); newMask++) {\n\t\t\t\t\tif ((tot & newMask) != newMask || !test(newMask, pos))\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int posMask = newMask; posMask > 0; posMask = (posMask - 1)\n\t\t\t\t\t\t\t& newMask) {\n\t\t\t\t\t\tif (!test(posMask, pos))\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tint rest = newMask ^ posMask;\n//\t\t\t\t\t\tif (tot == 3 && roots == 2) {\n//\t\t\t\t\t\t\tSystem.err.println(newMask + \" -> \" + posMask + \" \"\n//\t\t\t\t\t\t\t\t\t+ rest);\n//\t\t\t\t\t\t\tSystem.err.println(curDp[rest] + \" \"\n//\t\t\t\t\t\t\t\t\t+ dp[posMask][pos]);\n//\t\t\t\t\t\t}\n\t\t\t\t\t\tnewDp[newMask] = Math.min(newDp[newMask], curDp[rest]\n\t\t\t\t\t\t\t\t+ dp[posMask][pos]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint[] tmp = curDp;\n\t\t\t\tcurDp = newDp;\n\t\t\t\tnewDp = tmp;\n\t\t\t}\n\t\t}\n\t\treturn curDp[tot];\n\t}\n\n\tstatic boolean test(int mask, int i) {\n\t\treturn ((mask >> i) & 1) == 1;\n\t}\n\n\tint sumPrimePowers(long x) {\n\t\tint ret = 0;\n\t\tfor (int i = 0; i < primes.size(); i++) {\n\t\t\tint p = primes.get(i);\n\t\t\twhile (x % p == 0) {\n\t\t\t\tx /= p;\n\t\t\t\tret++;\n\t\t\t}\n\t\t}\n\t\tif (x != 1)\n\t\t\tret++;\n\t\treturn ret;\n\t}\n\n\tC() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2b31679aadbdd52dafd49bfcefe969a", "src_uid": "52b8b6c68518d5129272b8c56e5b7662", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class C implements Runnable {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer st;\n\tstatic Random rnd;\n\n\tprivate void solve() throws IOException {\n\t\tint numbersCount = nextInt();\n\t\tlong[] numbers = new long[numbersCount];\n\t\tfor (int i = 0; i < numbersCount; i++)\n\t\t\tnumbers[i] = nextLong();\n\t\tfor (int i = 1; i < numbersCount; i++) {\n\t\t\tint j = rnd.nextInt(i);\n\t\t\tlong a = numbers[i];\n\t\t\tnumbers[i] = numbers[j];\n\t\t\tnumbers[j] = a;\n\t\t}\n\n\t\trec(0, numbersCount, numbers, new boolean[numbersCount], 0, 0,\n\t\t\t\tnew long[numbersCount], new boolean[numbersCount]);\n\n\t\tout.println(result);\n\t}\n\n\tint result = Integer.MAX_VALUE;\n\n\tprivate void rec(int step, int numbersCount, long[] numbers,\n\t\t\tboolean[] used, int treesNearRoot, int treesCount,\n\t\t\tlong[] treesRoots, boolean[] isLeaf) {\n\t\tint currentVertexes = getVertexes(treesNearRoot, treesCount,\n\t\t\t\ttreesRoots, isLeaf);\n\n//\t\tout.println(currentVertexes + \" \" + result + \" \" + step + \" \"\n//\t\t\t\t+ treesNearRoot + \" \" + treesCount + \" \"\n//\t\t\t\t+ Arrays.toString(treesRoots));\n\n\t\tif (currentVertexes >= result)\n\t\t\treturn;\n\n\t\tif (step == numbersCount) {\n\t\t\tresult = Math.min(result, currentVertexes);\n\t\t} else {\n\t\t\tfor (int i = 0; i < numbersCount; i++) {\n\t\t\t\tif (!used[i]) {\n\t\t\t\t\tused[i] = true;\n\t\t\t\t\tlong number = numbers[i];\n\t\t\t\t\tboolean end = false;\n\n\t\t\t\t\t// add tree\n\t\t\t\t\t{\n\t\t\t\t\t\ttreesRoots[treesCount] = number;\n\t\t\t\t\t\tisLeaf[treesCount] = true;\n\t\t\t\t\t\trec(step + 1, numbersCount, numbers, used,\n\t\t\t\t\t\t\t\ttreesNearRoot + 1, treesCount + 1, treesRoots,\n\t\t\t\t\t\t\t\tisLeaf);\n\n\t\t\t\t\t\tif (currentVertexes >= result)\n\t\t\t\t\t\t\tend = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// add to another tree\n\t\t\t\t\tfor (int j = 0; j < treesCount && !end; j++) {\n\t\t\t\t\t\tif (treesRoots[j] % number == 0) {\n\t\t\t\t\t\t\ttreesRoots[j] /= number;\n\t\t\t\t\t\t\tboolean backUpIsLeaf = isLeaf[j];\n\t\t\t\t\t\t\tisLeaf[j] = false;\n\t\t\t\t\t\t\ttreesRoots[treesCount] = number;\n\t\t\t\t\t\t\tisLeaf[treesCount] = true;\n\n\t\t\t\t\t\t\trec(step + 1, numbersCount, numbers, used,\n\t\t\t\t\t\t\t\t\ttreesNearRoot, treesCount + 1, treesRoots,\n\t\t\t\t\t\t\t\t\tisLeaf);\n\n\t\t\t\t\t\t\ttreesRoots[j] *= number;\n\t\t\t\t\t\t\tisLeaf[j] = backUpIsLeaf;\n\n\t\t\t\t\t\t\tif (currentVertexes >= result)\n\t\t\t\t\t\t\t\tend = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tused[i] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate int getVertexes(int treesNearRoot, int treesCount,\n\t\t\tlong[] treesRoots, boolean[] isLeaf) {\n\t\tint vertexes = (treesNearRoot > 1 ? 1 : 0);\n\t\tfor (int i = 0; i < treesCount; i++) {\n\t\t\tint childs = getPrimes(treesRoots[i]);\n\t\t\tint add = (childs <= 1 && isLeaf[i]) ? 1 : (1 + childs);\n\t\t\tvertexes += add;\n\t\t}\n\t\treturn vertexes;\n\t}\n\n\tMap cache = new HashMap();\n\n\tprivate int getPrimes(long n) {\n\t\tif (n == 1)\n\t\t\treturn 0;\n\t\tInteger cacheValue = cache.get(n);\n\t\tif (cacheValue != null)\n\t\t\treturn cacheValue;\n\t\tint result = 1;\n\t\tfor (long i = 2; i * i <= n; i++) {\n\t\t\tif (n % i == 0) {\n\t\t\t\tresult = 1 + getPrimes(n / i);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tcache.put(n, result);\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew C().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(1);\n\t\t}\n\t}\n\n\tprivate String 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\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\n\t\treturn st.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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "275c98b053934ed259d7a802ccf82331", "src_uid": "52b8b6c68518d5129272b8c56e5b7662", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "//package round167;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Queue;\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(), m = ni();\n\t\tint[] from = new int[m];\n\t\tint[] to = new int[m];\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tfrom[i] = ni()-1;\n\t\t\tto[i] = ni()-1;\n\t\t}\n\t\tint[][] g = packU(n, from, to);\n\t\tint[] col = new int[n];\n\t\tQueue q = new ArrayDeque();\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tq.add(i);\n\t\t}\n\t\twhile(!q.isEmpty()){\n\t\t\tint cur = q.poll();\n\t\t\tint[] ct = new int[2];\n\t\t\tfor(int e : g[cur]){\n\t\t\t\tct[col[e]]++;\n\t\t\t}\n\t\t\tif(ct[col[cur]] >= 2){\n\t\t\t\tcol[cur] = 1-col[cur];\n\t\t\t\tfor(int e : g[cur]){\n\t\t\t\t\tq.add(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tout.print(col[i]);\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tstatic int[][] packU(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)\n\t\t\tp[f]++;\n\t\tfor(int t : to)\n\t\t\tp[t]++;\n\t\tfor(int i = 0;i < n;i++)\n\t\t\tg[i] = new int[p[i]];\n\t\tfor(int i = 0;i < from.length;i++){\n\t\t\tg[from[i]][--p[from[i]]] = to[i];\n\t\t\tg[to[i]][--p[to[i]]] = from[i];\n\t\t}\n\t\treturn g;\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\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f4f191a13b01f8386d3bf0b89f431b6", "src_uid": "7017f2c81d5aed716b90e46480f96582", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOError;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class CF272E {\n\n\tfinal int maxn = 300030;\n\tArrayList[] adj = new ArrayList[maxn];\n\tboolean[] vis = new boolean[maxn];\n\tint[] color = new int[maxn];\n\tFastIO scan = new FastIO();\n\tPrintWriter cout = new PrintWriter(System.out);\n\n\tvoid dfs(int u) {\n\t\tvis[u] = true;\n\t\tint cnt = 0;\n\t\tfor (int i = 0; i < adj[u].size(); i++) {\n\t\t\tint v = (int) adj[u].get(i);\n\t\t\tif (color[u] == color[v]) {\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t\tif (cnt >= 2) {\n\t\t\tcolor[u] = 1 - color[u];\n\t\t\tfor (int i = 0; i < adj[u].size(); i++) {\n\t\t\t\tint v = (int) adj[u].get(i);\n\t\t\t\tdfs(v);\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid run() {\n\t\tfor (int i = 0; i < maxn; i++)\n\t\t\tadj[i] = new ArrayList();\n\t\tint n = scan.nextInt();\n\t\tint m = scan.nextInt();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint u = scan.nextInt();\n\t\t\tint v = scan.nextInt();\n\t\t\tadj[u].add(v);\n\t\t\tadj[v].add(u);\n\t\t}\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tif (vis[i] == false)\n\t\t\t\tdfs(i);\n\t\t}\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tcout.print(color[i]);\n\t\tcout.println();\n\t\tcout.flush();\n\t}\n\n\tpublic static void main(String args[]) {\n\t\tnew CF272E().run();\n\t}\n\n\tpublic class FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tPrintWriter out;\n\n\t\tpublic FastIO(InputStream in, OutputStream o) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(o));\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 println(String ans) {\n\t\t\tout.println(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void close() {\n\t\t\tout.close();\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e4a9d50c906a705b24e6cb97d55154d3", "src_uid": "7017f2c81d5aed716b90e46480f96582", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class TC\n{\n static int N;\n static ArrayList[] adjMat;\n static int[] col;\n \n static boolean verify()\n {\n boolean isDone=true;\n \n for( int i=1; i<=N; i++ )\n {\n int cnt=0;\n \n for( int nbr:adjMat[i])\n {\n if( col[nbr] == col[i])\n cnt++;\n }\n \n if( cnt >=2 )\n {\n isDone=false;\n col[i]=1-col[i];\n }\n \n }\n \n return isDone;\n }\n \n \n static void solve() throws IOException\n {\n col=new int[N+1];\n Arrays.fill( col, -1 );\n \n for( int i=1; i<=N; i++ )\n {\n int c1=0, c2=0;\n \n for( int nbr:adjMat[i])\n {\n if( col[nbr] == 0 )\n c1++;\n \n if( col[nbr] == 1 )\n c2++;\n }\n \n if( c1<=1 )\n col[i]=0;\n \n else\n col[i]=1;\n }\n \n boolean isValid=false;\n \n while( !isValid )\n {\n isValid=verify();\n }\n \n BufferedWriter out=new BufferedWriter( new OutputStreamWriter( System.out ));\n \n for( int i=1; i<=N; i++ )\n out.write( Integer.toString( col[i]));\n \n \n out.write(\"\\n\");\n out.close();\n }\n \n public static void main( String[] args ) throws IOException\n {\n BufferedReader br=new BufferedReader( new InputStreamReader( System.in ) );\n String s=br.readLine();\n StringTokenizer tok=new StringTokenizer( s );\n N=Integer.parseInt( tok.nextToken() ); \n int m=Integer.parseInt( tok.nextToken() ); \n adjMat=new ArrayList[N+1];\n for( int i=0; i 0 )\n {\n s=br.readLine();\n tok=new StringTokenizer( s );\n int a=Integer.parseInt( tok.nextToken() ); \n int b=Integer.parseInt( tok.nextToken() ); \n adjMat[a].add(b);\n adjMat[b].add(a);\n }\n solve();\n \n }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1e8a565194b0bbe6dc23b3227c35c10d", "src_uid": "7017f2c81d5aed716b90e46480f96582", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class E_Round_167_Div2 {\n\n public static long MOD = 1000000007;\n static int time = 0;\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 n = in.nextInt();\n int m = in.nextInt();\n ArrayList[] map = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n map[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 map[a].add(b);\n map[b].add(a);\n }\n int[]cur = new int[n];\n LinkedList q = new LinkedList();\n for(int i = 0; i < n; i++){\n if(map[i].size() > 1){\n q.add(i);\n } \n }\n while(!q.isEmpty()){\n int node = q.pollFirst();\n int c = 0;\n for(int j : map[node]){\n if(cur[j] == cur[node]){\n c++;\n }\n }\n if(c > 1){\n cur[node] = 1 - cur[node];\n for(int j : map[node]){\n if(cur[j] == cur[node]){\n int x = 0;\n for(int k : map[j]){\n if(cur[k] == cur[j]){\n x++;\n }\n }\n if(x > 1){\n q.add(j);\n }\n }\n }\n }\n }\n for(int i : cur){\n out.print(i);\n }\n out.close();\n }\n\n \n\n \n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "049677760e549663fdc2663e95fccc7f", "src_uid": "7017f2c81d5aed716b90e46480f96582", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Fraction {\n\n BigInteger a = new BigInteger(\"0\");\n BigInteger b = new BigInteger(\"1\");\n\n Fraction() {\n\n }\n\n Fraction(long a, long b) {\n this.a = new BigInteger(\"\" + a);\n this.b = new BigInteger(\"\" + b);\n }\n\n Fraction(BigInteger a, BigInteger b) {\n this.a = a;\n this.b = b;\n }\n\n Fraction add(BigInteger x) {\n Fraction ans = new Fraction(a, b);\n ans.a = ans.a.add(x.multiply(b));\n ans.reduce();\n return ans;\n }\n\n Fraction multiply(BigInteger x) {\n Fraction ans = new Fraction(this.a, this.b);\n ans.a = ans.a.multiply(x);\n ans.reduce();\n return ans;\n }\n\n Fraction add(long x) {\n BigInteger bx = new BigInteger(\"\" + x);\n Fraction ans = add(bx);\n ans.reduce();\n return ans;\n }\n\n Fraction multiply(long x) {\n BigInteger bx = new BigInteger(\"\" + x);\n Fraction ans = multiply(bx);\n ans.reduce();\n return ans;\n }\n\n Fraction add(Fraction x) {\n BigInteger lo = b.multiply(x.b);\n BigInteger h1 = a.multiply(x.b);\n BigInteger h2 = x.a.multiply(b);\n BigInteger hi = h1.add(h2);\n Fraction ans = new Fraction(hi, lo);\n ans.reduce();\n return ans;\n }\n\n Fraction multiply(Fraction x) {\n BigInteger lo = b.multiply(x.b);\n BigInteger hi = a.multiply(x.a);\n Fraction ans = new Fraction(hi, lo);\n ans.reduce();\n return ans;\n }\n\n Fraction devide(Fraction x) {\n Fraction y = new Fraction(x.b, x.a);\n Fraction ans = multiply(y);\n ans.reduce();\n return ans;\n }\n\n BigInteger GCD(BigInteger a, BigInteger b) {\n for (;;) {\n if (a.equals(BigInteger.ZERO)) {\n return b;\n }\n b = b.mod(a);\n if (b.equals(BigInteger.ZERO)) {\n return a;\n }\n a = a.mod(b);\n }\n }\n\n void reduce() {\n BigInteger G = GCD(a, b);\n a = a.divide(G);\n b = b.divide(G);\n }\n}\n\npublic class Main {\n\n static int n;\n static Fraction[] memo = new Fraction[100100];\n static boolean[] vis = new boolean[100100];\n\n static Fraction DP(int root, long depth) {\n int n2 = 0;\n while (n % 2 == 0) {\n n >>= 1;\n ++n2;\n }\n Fraction A = new Fraction(0, 1);\n Fraction B = new Fraction(1, 1);\n int lastRem = 1;\n while (root != 0) {\n int k;\n for (k = 1; (1 << k) < n; k++);\n int rem = (1 << k) - n;\n A = A.add(B.multiply(k));\n B = B.multiply(rem);\n B.b = B.b.shiftLeft(k).multiply(BigInteger.valueOf(lastRem));\n if (rem == 1) {\n B.a = B.b.subtract(B.a);\n A = A.devide(B);\n break;\n }\n lastRem = rem;\n }\n A.a = A.a.add(A.b.multiply(BigInteger.valueOf(n2)));\n return A;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n if (n == 0) {\n System.out.println(\"0/1\");\n return;\n }\n Fraction ans = DP(1, 0);\n ans.reduce();\n System.out.println(ans.a + \"/\" + ans.b);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "834fb1be8575c7d2755d82af8b544e92", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.io.*;\n\npublic class Solution \n{\n public static class Frac\n {\n BigInteger numer, denom;\n Frac () { numer = BigInteger.ZERO; denom = BigInteger.ONE; }\n Frac (BigInteger num, BigInteger den) \n { \n numer = num; \n denom = den;\n BigInteger g = numer.gcd(denom);\n numer = numer.divide(g);\n denom = denom.divide(g);\n }\n }\n \n static int n, sza;\n static int idx[], a[];\n static Frac k[], b[], d[];\n static boolean calced[]; \n \n public static Frac multFrac (Frac a, Frac b)\n {\n Frac ans = new Frac(a.numer.multiply(b.numer), a.denom.multiply(b.denom));\n BigInteger g = ans.numer.gcd(ans.denom);\n ans.numer = ans.numer.divide(g);\n ans.denom = ans.denom.divide(g);\n return ans;\n }\n \n public static Frac addFrac (Frac a, Frac b)\n {\n Frac ans = new Frac(a.numer.multiply(b.denom).add(b.numer.multiply(a.denom)), a.denom.multiply(b.denom));\n BigInteger g = ans.numer.gcd(ans.denom);\n ans.numer = ans.numer.divide(g);\n ans.denom = ans.denom.divide(g);\n return ans; \n }\n\n static Frac solve ()\n {\n int cnt = 1;\n int fcalc = -1;\n \n while (true)\n {\n a[sza] = cnt;\n idx[cnt] = sza;\n \n int h = 0;\n while ((cnt << h) < n)\n h++;\n \n int rem = (cnt << h) - n;\n \n if (rem == 0)\n {\n d[sza] = new Frac(BigInteger.valueOf(h), BigInteger.ONE);\n fcalc = sza;\n break;\n }\n \n b[sza] = new Frac(BigInteger.valueOf(h), BigInteger.ONE);\n k[sza] = new Frac(BigInteger.valueOf(rem), BigInteger.valueOf(cnt << h));\n \n if (idx[rem] != -1)\n {\n Frac curb = b[sza], curk = k[sza];\n \n for (int i = sza - 1; i >= idx[rem]; i--)\n {\n Frac nb = addFrac(b[i], multFrac(curb, k[i]));\n Frac nk = multFrac(curk, k[i]);\n curb = nb; curk = nk;\n }\n \n d[idx[rem]] = multFrac(new Frac(curk.denom, curk.denom.subtract(curk.numer)), curb);\n \n fcalc = idx[rem];\n break;\n }\n sza++;\n cnt = rem;\n }\n \n Frac cur = d[fcalc];\n for (int i = fcalc - 1; i >= 0; i--)\n cur = addFrac(b[i], multFrac(k[i], cur));\n \n return cur;\n }\n \n public static void main (String[] argv)\n {\n Scanner in = new Scanner (System.in);\n n = in.nextInt();\n idx = new int [n + 5];\n for (int i = 0; i <= n; i++)\n idx[i] = -1;\n a = new int [n + 5];\n sza = 0;\n k = new Frac [n + 5];\n b = new Frac [n + 5];\n d = new Frac [n + 5];\n \n Frac ans = solve();\n \n System.out.println(ans.numer + \"/\" + ans.denom); \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "90c8184f867138da71bb55a7b2b5c24e", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\tpublic static int []to = new int[10];\n\tpublic static void main(String args[]) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt(), start = -1;\n\t\tif (n == 1) {\n\t\t\tSystem.out.println(\"0/1\");\n\t\t\treturn;\n\t\t}\n\t\tfor (int i=0,rem=1,nxt_rem=-1; ; rem=nxt_rem,++i) {\n\t\t\tnxt_rem = rem * 2;\n\t\t\tif (nxt_rem >= n) nxt_rem -= n;\n\t\t\tif (to[nxt_rem] != 0) {\n\t\t\t\tstart = nxt_rem;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tto[rem] = nxt_rem;\n\t\t\tif (rem == 0) {\n\t\t\t\tSystem.out.println(i+\"/1\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tFraction A = new Fraction(BigInteger.ONE, BigInteger.ONE);\n\t\tint next_start = 2 * start;\n\t\tif (next_start >= n) next_start -= n;\n\t\tFraction B = new Fraction(BigInteger.valueOf(next_start), BigInteger.valueOf(2*start));\n\t\tfor (int i=next_start; ; ) {\n\t\t\tint b = i * 2;\n\t\t\tint a = b;\n\t\t\tif (a >= n) a -= n;\n\t\t\tFraction C = new Fraction(BigInteger.valueOf(a), BigInteger.valueOf(b));\n\t\t\tA = A.add(B);\n\t\t\tB = B.multiply(C);\n\t\t\ti = a;\n\t\t\tif (a == start) {\n\t\t\t\tB.a = B.b.subtract(B.a);\n\t\t\t\tA = A.divide(B);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor (int i=1; i!=start; ) {\n\t\t\tA.a = A.a.add(A.b);\n\t\t\tint j = i * 2;\n\t\t\tif (j >= n) j -= n;\n\t\t\ti = j;\n\t\t}\n\t\tSystem.out.println(A.a+\"/\"+A.b);\n\t}\n}\n\nclass Fraction {\n\tpublic BigInteger a, b;\n\tpublic Fraction(BigInteger a, BigInteger b) {\n\t\tBigInteger d = a.gcd(b);\n\t\tthis.a = a.divide(d);\n\t\tthis.b = b.divide(d);\n\t}\n\tpublic Fraction add(Fraction rhs) {\n\t\tBigInteger x = this.a.multiply(rhs.b).add(this.b.multiply(rhs.a));\n\t\tBigInteger y = this.b.multiply(rhs.b);\n\t\tBigInteger d = x.gcd(y);\n\t\tx = x.divide(d);\n\t\ty = y.divide(d);\n\t\treturn new Fraction(x, y);\n\t}\n\tpublic Fraction multiply(Fraction rhs) {\n\t\tBigInteger x = this.a.multiply(rhs.a);\n\t\tBigInteger y = this.b.multiply(rhs.b);\n\t\tBigInteger d = x.gcd(y);\n\t\tx = x.divide(d);\n\t\ty = y.divide(d);\n\t\treturn new Fraction(x, y);\n\t}\n\tpublic Fraction divide(Fraction rhs) {\n\t\tFraction r = new Fraction(rhs.b, rhs.a);\n\t\treturn this.multiply(r);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7779d4f9a1f0eee364c6635c29164e3b", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.HashMap;\nimport java.util.Locale;\nimport java.util.Random;\nimport java.util.Scanner;\n\nimport org.omg.CORBA.FREE_MEM;\n\n\npublic class Main {\n class Pair{\n Long l1;\n Long l2;\n };\n HashMap F = new HashMap();\n \n class Fraction{\n public BigInteger p, q;\n \n public Fraction() {\n p = BigInteger.ZERO;\n q = BigInteger.ONE;\n }\n \n Fraction multiply(long v){\n Fraction ret = new Fraction();\n ret.p = p.multiply(BigInteger.valueOf(v));\n ret.q = q;\n ret.fix();\n return ret;\n }\n Fraction divide(long v){\n Fraction ret = new Fraction();\n ret.p = p;\n ret.q = q.multiply(BigInteger.valueOf(v));\n ret.fix();\n return ret;\n }\n Fraction divide(Fraction v){\n Fraction ret = new Fraction();\n ret.p = p.multiply(v.q);\n ret.q = q.multiply(v.p);\n ret.fix();\n return ret;\n }\n boolean less(Fraction f2){\n return p.multiply(f2.q).compareTo(f2.p.multiply(q)) < 0;\n }\n Fraction add(Fraction f2){\n Fraction ret = new Fraction();\n ret.p = p.multiply(f2.q).add(f2.p.multiply(q));\n ret.q = q.multiply(f2.q);\n return ret;\n }\n Fraction sub(Fraction f2){\n Fraction ret = new Fraction();\n ret.p = p.multiply(f2.q).subtract(f2.p.multiply(q));\n ret.q = q.multiply(f2.q);\n return ret;\n }\n \n void fix(){\n BigInteger gc = p.gcd(q);\n p = p.divide(gc);\n q = q.divide(gc);\n }\n \n public String toString(){\n return p.toString() + \"/\" + q.toString();\n }\n }\n void solve(){\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = in.nextInt();\n if (n == 1){\n out.println(\"0/1\");\n out.flush();\n return;\n }\n \n Fraction[] was = new Fraction[n+1];\n Fraction[] pp = new Fraction[n+1];\n Fraction ret = new Fraction();\n Fraction p = new Fraction();\n p.p = BigInteger.ONE;\n int fre = 1;\n was[1] = new Fraction();\n pp[1] = p;\n while (true){\n fre *= 2;\n ret = ret.add(p);\n if (fre >= n){\n p = p.multiply(fre - n);\n p = p.divide(fre);\n fre -= n;\n }\n if (was[fre] == null){\n was[fre] = ret;\n pp[fre] = p;\n } else {\n Fraction f = ret.sub(was[fre]);\n f = f.divide(pp[fre].sub(p));\n if (f.p.compareTo(BigInteger.ZERO) != 0){\n ret = f.add(was[fre]);\n }\n break;\n }\n }\n ret.fix();\n out.println(ret);\n out.flush();\n }\n public static void main(String[] args) {\n Main solver = new Main();\n solver.solve();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "99f685c6e799b318a15c9edd5104fd04", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "// https://codeforces.com/contest/1174/submission/55043857 (rainboy)\nimport java.io.*;\n\npublic class CF1174E {\n\tstatic final int MD = 1000000007;\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint[] aa = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\taa[i] = i % 2 == 0 ? aa[i / 2] + 1 : 0;\n\t\tint k = 0;\n\t\twhile (1 << k + 1 <= n)\n\t\t\tk++;\n\t\tint[] cnt = new int[k + 1];\n\t\tint[] cnt3 = new int[k + 1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tint a = aa[i];\n\t\t\tcnt[a]++;\n\t\t\tif (i % 3 == 0)\n\t\t\t\tcnt3[a]++;\n\t\t}\n\t\tlong[][] dp = new long[n + 1][k + 1];\n\t\tdp[1][k] = 1;\n\t\tfor (int i = 1; i < n; i++)\n\t\t\tfor (int h = 0; h <= k; h++) {\n\t\t\t\tlong x = dp[i][h];\n\t\t\t\tif (x != 0) {\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\tdp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;\n\t\t\t\t\tdp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;\n\t\t\t\t}\n\t\t\t}\n\t\tlong ans = dp[n][0];\n\t\tif (3 << k - 1 <= n) {\n\t\t\tdp = new long[n + 1][k];\n\t\t\tlong[][] dq = new long[n + 1][k];\n\t\t\tdq[1][k - 1] = 1;\n\t\t\tfor (int i = 1; i < n; i++)\n\t\t\t\tfor (int h = 0; h < k; h++) {\n\t\t\t\t\tlong x = dq[i][h];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t\tdq[i + 1][h - 1] = (dq[i + 1][h - 1] + x * cnt3[h - 1]) % MD;\n\t\t\t\t\t\tdq[i + 1][h] = (dq[i + 1][h] + x * (n / (3 << h) - i)) % MD;\n\t\t\t\t\t\tdp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;\n\t\t\t\t\t}\n\t\t\t\t\tx = dp[i][h];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t\tdp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;\n\t\t\t\t\t\tdp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tans = (ans + dp[n][0]) % MD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd78982a73ffc3dd9f683a2acb3c10d4", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nWhat do you think? What do you think?\n1st on Billboard, what do you think of it\nNext is a Grammy, what do you think of it\nHowever you think, I\u2019m sorry, but shit, I have no fcking interest\n*******************************\nI'm standing on top of my Monopoly board\nThat means I'm on top of my game and it don't stop\ntil my hip don't hop anymore\nhttps://www.a2oj.com/Ladder16.html\n*******************************\n300iq as writer = Sad!\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n public class x1174E\n {\n static long MOD = 1000000007L;\n public static void main(String hi[]) throws Exception\n {\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(infile.readLine());\n int N = Integer.parseInt(st.nextToken());\n long[][] dp = new long[20][2];\n base(dp, N);\n cnt = new long[20][2];\n for(int curr=0; (1<= 0; a--)\n for(int b=1; b >= 0; b--)\n {\n long res = 0L;\n if(cnt[a][b]-i >= 0)\n res = (dp[a][b]*(cnt[a][b]-i+1+MOD))%MOD;\n if(a+1 < 20)\n {\n res += (dp[a+1][b]*(cnt[a][b]-cnt[a+1][b]))%MOD;\n if(res >= MOD)\n res -= MOD;\n }\n if(b == 0)\n {\n res += (dp[a][1]*(cnt[a][0]-cnt[a][1]))%MOD;\n if(res >= MOD)\n res -= MOD;\n }\n newdp[a][b] = res;\n }\n dp = newdp;\n }\n System.out.println(dp[0][0]);\n }\n static long[][] cnt;\n public static void base(long[][] dp, int N)\n {\n int curr = 1;\n while((1<> 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 MathUtils.Modular modular = new MathUtils.Modular((int) 1e9 + 7);\n MathUtils.Factorial factorial = new MathUtils.Factorial(1000000, modular);\n MathUtils.Composite composite = new MathUtils.Composite(factorial, modular);\n MathUtils.Power power = new MathUtils.Power(modular);\n\n public Task(FastIO io, Debug debug) {\n this.io = io;\n this.debug = debug;\n }\n\n @Override\n public void run() {\n solve();\n }\n\n int n;\n\n public void solve() {\n n = io.readInt();\n int time = 0;\n int base2 = 1;\n while (base2 * 2 <= n) {\n base2 *= 2;\n time++;\n }\n int base3 = 3 * (1 << (time - 1));\n\n int total = f(time, 0);\n if (base3 <= n) {\n total = modular.plus(total, g(time - 1));\n }\n io.cache.append(total);\n }\n\n int f(int i, int used) {\n if (i < 0) {\n return 1;\n }\n int sum = n / (1 << i);\n int count = sum - used;\n int result = 1;\n result = modular.mul(result, count);\n result = modular.mul(result, f(i - 1, sum));\n result = modular.mul(result, composite.composite(n - sum + count - 1, count - 1));\n result = modular.mul(result, factorial.fact[count - 1]);\n return result;\n }\n\n int g(int i) {\n if (i < 0) {\n return 0;\n }\n int sum = n / 3 / (1 << i);\n int count = sum - sum / 2;\n int result = 1;\n result = modular.mul(result, count);\n result = modular.mul(result, g(i - 1) + f(i, sum));\n result = modular.mul(result, composite.composite(n - sum + count - 1, count - 1));\n result = modular.mul(result, factorial.fact[count - 1]);\n return result;\n }\n }\n\n\n public static class MathUtils {\n private static Random random = new Random(123456789);\n\n public static class ExtLucasFactorial {\n int exp;\n int fact;\n int p;\n int pc;\n Modular modular;\n Power power;\n ExtGCD extGCD = new ExtGCD();\n int[] g;\n\n /**\n * O(pc)\n *\n * @param p the prime\n * @param pc p^c\n * @param g buffer\n */\n public ExtLucasFactorial(int p, int pc, int[] g) {\n this.p = p;\n this.pc = pc;\n this.g = g;\n modular = new Modular(pc);\n power = new Power(modular);\n g[0] = 1;\n g[1] = 1;\n for (int i = 2; i <= pc; i++) {\n if (i % p == 0) {\n g[i] = g[i - 1];\n } else {\n g[i] = modular.mul(g[i - 1], i);\n }\n }\n }\n\n /**\n * return m! (mod pc) without any factor which is multiple of p.\n *
\n * O(\\log_2^2{m})\n */\n private int fact(long m) {\n fact = 1;\n exp = 0;\n while (m > 1) {\n exp += m / p;\n fact = modular.mul(fact, power.pow(g[pc], m / pc));\n fact = modular.mul(fact, g[(int) (m % pc)]);\n m /= p;\n }\n return fact;\n }\n\n /**\n * Find C(m,n), it means choose n elements from a set whose size is m.\n *
\n * O(\\log_2^2{m})\n */\n public int composite(long m, long n) {\n int v = fact(m);\n int e = exp;\n extGCD.extgcd(fact(n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n extGCD.extgcd(fact(m - n), pc);\n v = modular.mul(v, modular.valueOf(extGCD.getX()));\n e -= exp;\n v = modular.mul(v, power.pow(p, e));\n return v;\n }\n }\n\n /**\n * \u6269\u5c55\u5362\u5361\u65af\u7b97\u6cd5\n */\n public static class ExtLucas {\n PollardRho pr = new PollardRho();\n Map factorialMap = new HashMap();\n\n public ExtLucas(int p) {\n Map factors = pr.findAllFactors(p);\n for (Map.Entry entry : factors.entrySet()) {\n factorialMap.put(entry.getValue(), new ExtLucasFactorial(entry.getKey(), entry.getValue(), new int[entry.getValue() + 1]));\n }\n }\n\n /**\n * Get C(m, n) % p\n */\n public int composite(long m, long n) {\n ExtCRT extCRT = new ExtCRT();\n for (Map.Entry entry : factorialMap.entrySet()) {\n extCRT.add(entry.getValue().composite(m, n), entry.getKey());\n }\n return (int) extCRT.r;\n }\n }\n\n /**\n * \u6269\u5c55\u5362\u5361\u65af\u7b97\u6cd5\n */\n public static class LongExtLucas {\n LongPollardRho pr = new LongPollardRho();\n Map factorialMap = new HashMap();\n\n public LongExtLucas(long p) {\n Map factors = pr.findAllFactors(p);\n for (Map.Entry entry : factors.entrySet()) {\n factorialMap.put(entry.getValue().intValue(), new ExtLucasFactorial(entry.getKey().intValue(), entry.getValue().intValue(), new int[entry.getValue().intValue() + 1]));\n }\n }\n\n /**\n * Get C(m, n) % p\n */\n public int composite(long m, long n) {\n ExtCRT extCRT = new ExtCRT();\n for (Map.Entry entry : factorialMap.entrySet()) {\n extCRT.add(entry.getValue().composite(m, n), entry.getKey());\n }\n return (int) extCRT.r;\n }\n }\n\n /**\n * \u6269\u5c55\u6b27\u51e0\u91cc\u5f97\n */\n public static class ExtGCD extends Gcd {\n private long x;\n private long y;\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 return extgcd0(a, b);\n } else {\n long g = extgcd0(b, a);\n long tmp = x;\n x = y;\n y = tmp;\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 * \u6b27\u62c9\u7b5b\n */\n public static class EulerSieve {\n int[] primes;\n boolean[] isComp;\n int primeLength;\n\n public EulerSieve(int limit) {\n isComp = new boolean[limit + 1];\n primes = new int[limit + 1];\n primeLength = 0;\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n primes[primeLength++] = i;\n }\n for (int j = 0, until = limit / i; j < primeLength && primes[j] <= until; j++) {\n int pi = primes[j] * i;\n isComp[pi] = true;\n if (i % primes[j] == 0) {\n break;\n }\n }\n }\n }\n }\n\n /**\n * \u6a21\u8fd0\u7b97\n */\n public static class Modular {\n final int m;\n\n public Modular(int m) {\n this.m = m;\n }\n\n public int valueOf(int x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return x;\n }\n\n public int valueOf(long x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n @Override\n public String toString() {\n return \"mod \" + m;\n }\n }\n\n /**\n * \u4f4d\u8fd0\u7b97\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 /**\n * \u5e42\u8fd0\u7b97\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 * \u5bf9\u6570\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 * \u4e58\u6cd5\u9006\u5143\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 * \u6392\u5217\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 * \u7ec4\u5408\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 * \u5927\u7d20\u6570\u6d4b\u8bd5\n */\n public static class MillerRabin {\n Modular modular;\n Power power;\n\n /**\n * \u5224\u65adn\u662f\u5426\u662f\u7d20\u6570\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 LongModular {\n final long m;\n\n public LongModular(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;\n }\n\n public long plus(long a, long b) {\n return valueOf(a + b);\n }\n\n public long valueOf(long a) {\n a %= m;\n if (a < 0) {\n a += m;\n }\n return a;\n }\n }\n\n public static class LongPower {\n final LongModular modular;\n\n public LongPower(LongModular modular) {\n this.modular = modular;\n }\n\n 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 long inverse(long x) {\n return pow(x, modular.m - 2);\n }\n }\n\n /**\n * \u5927\u7d20\u6570\u6d4b\u8bd5\n */\n public static class LongMillerRabin {\n LongModular modular;\n LongPower power;\n\n /**\n * \u5224\u65adn\u662f\u5426\u662f\u7d20\u6570\n */\n public boolean mr(long n, int s) {\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n modular = new LongModular(n);\n power = new LongPower(modular);\n for (int i = 0; i < s; i++) {\n long x = (long) (random.nextDouble() * (n - 2) + 2);\n if (!mr0(x, n)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(long x, long n) {\n long exp = n - 1;\n while (true) {\n long y = power.pow(x, exp);\n if (y != 1 && y != n - 1) {\n return false;\n }\n if (y != 1 || exp % 2 == 1) {\n break;\n }\n exp = exp / 2;\n }\n return true;\n }\n }\n\n public static class LongPollardRho {\n LongMillerRabin mr = new LongMillerRabin();\n Gcd gcd = new Gcd();\n LongModular modular;\n\n /**\n * Find a factor of n, if n is returned, it means n is 1 or a prime\n */\n public long findFactor(long n) {\n if (mr.mr(n, 3)) {\n return n;\n }\n modular = new LongModular(n);\n while (true) {\n long f = findFactor0((long) (random.nextDouble() * n), (long) (random.nextDouble() * n), n);\n if (f != -1) {\n return f;\n }\n }\n }\n\n private long findFactor0(long x, long c, long n) {\n long xi = x;\n long xj = x;\n int j = 2;\n int i = 1;\n while (i < n) {\n i++;\n xi = modular.plus(modular.mul(xi, xi), c);\n long g = gcd.gcd(n, Math.abs(xi - xj));\n if (g != 1 && g != n) {\n return g;\n }\n if (i == j) {\n j = j << 1;\n xj = xi;\n }\n }\n return -1;\n }\n\n /**\n * Find the representation of n=p1^c1 * p2^c2 * ... * pm ^ cm.\n *
\n * The returned map contained such entries: pi -> pi^ci\n */\n public Map findAllFactors(long n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, long n) {\n if (n == 1) {\n return;\n }\n long f = findFactor(n);\n if (f == n) {\n Long value = map.get(f);\n if (value == null) {\n value = 1L;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n }\n\n /**\n * \u6269\u5c55\u4e2d\u56fd\u4f59\u6570\u5b9a\u7406\n */\n public static class ExtCRT {\n /**\n * remainder\n */\n long r;\n /**\n * modulus\n */\n long m;\n ExtGCD gcd = new ExtGCD();\n\n public ExtCRT() {\n r = 0;\n m = 1;\n }\n\n /**\n * Add a new condition: x % m = r\n */\n public boolean add(long r, long m) {\n long m1 = this.m;\n long x1 = this.r;\n long m2 = m;\n long x2 = ((r % m) + m) % m;\n long g = gcd.extgcd(m1, m2);\n long a = gcd.getX();\n if ((x2 - x1) % g != 0) {\n return false;\n }\n this.m = m1 / g * m2;\n this.r = BigInteger.valueOf(a).multiply(BigInteger.valueOf((x2 - x1) / g))\n .multiply(BigInteger.valueOf(m1)).add(BigInteger.valueOf(x1))\n .mod(BigInteger.valueOf(this.m)).longValue();\n return true;\n }\n }\n\n /**\n * \u5362\u5361\u65af\u5b9a\u7406\n */\n public static class Lucas {\n private final Composite composite;\n private int modulus;\n\n public Lucas(Composite composite) {\n this.composite = composite;\n this.modulus = composite.modular.m;\n }\n\n public int composite(long m, long n) {\n if (n == 0) {\n return 1;\n }\n return composite.modular.mul(composite.composite((int) (m % modulus), (int) (n % modulus)),\n composite(m / modulus, n / modulus));\n }\n }\n\n /**\n * \u56e0\u5f0f\u5206\u89e3\n */\n public static class PollardRho {\n MillerRabin mr = new MillerRabin();\n Gcd gcd = new Gcd();\n Random random = new Random(123456789);\n\n public int findFactor(int n) {\n if (mr.mr(n, 10)) {\n return n;\n }\n while (true) {\n int f = findFactor0(random.nextInt(n), random.nextInt(n), n);\n if (f != -1) {\n return f;\n }\n }\n }\n\n public Map findAllFactors(int n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, int n) {\n if (n == 1) {\n return;\n }\n int f = findFactor(n);\n if (f == n) {\n Integer value = map.get(f);\n if (value == null) {\n value = 1;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n private int findFactor0(int x, int c, int n) {\n int xi = x;\n int xj = x;\n int j = 2;\n int i = 1;\n while (i < n) {\n i++;\n xi = (int) ((long) xi * xi + c) % n;\n int g = gcd.gcd(n, Math.abs(xi - xj));\n if (g != 1 && g != n) {\n return g;\n }\n if (i == j) {\n j = j << 1;\n xj = xi;\n }\n }\n return -1;\n }\n }\n }\n\n public static class FastIO {\n public final StringBuilder cache = new StringBuilder();\n private final InputStream is;\n private final OutputStream os;\n private final Charset charset;\n private StringBuilder defaultStringBuf = new StringBuilder(1 << 8);\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastIO(InputStream is, OutputStream os, Charset charset) {\n this.is = is;\n this.os = os;\n this.charset = charset;\n }\n\n public FastIO(InputStream is, OutputStream os) {\n this(is, os, Charset.forName(\"ascii\"));\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n public long readLong() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n long val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n public double readDouble() {\n boolean sign = true;\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+';\n next = read();\n }\n\n long val = 0;\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n if (next != '.') {\n return sign ? val : -val;\n }\n next = read();\n long radix = 1;\n long point = 0;\n while (next >= '0' && next <= '9') {\n point = point * 10 + next - '0';\n radix = radix * 10;\n next = read();\n }\n double result = val + (double) point / radix;\n return sign ? result : -result;\n }\n\n public String readString(StringBuilder builder) {\n skipBlank();\n\n while (next > 32) {\n builder.append((char) next);\n next = read();\n }\n\n return builder.toString();\n }\n\n public String readString() {\n defaultStringBuf.setLength(0);\n return readString(defaultStringBuf);\n }\n\n public int readLine(char[] data, int offset) {\n int originalOffset = offset;\n while (next != -1 && next != '\\n') {\n data[offset++] = (char) next;\n next = read();\n }\n return offset - originalOffset;\n }\n\n public int readString(char[] data, int offset) {\n skipBlank();\n\n int originalOffset = offset;\n while (next > 32) {\n data[offset++] = (char) next;\n next = read();\n }\n\n return offset - originalOffset;\n }\n\n public int readString(byte[] data, int offset) {\n skipBlank();\n\n int originalOffset = offset;\n while (next > 32) {\n data[offset++] = (byte) next;\n next = read();\n }\n\n return offset - originalOffset;\n }\n\n public char readChar() {\n skipBlank();\n char c = (char) next;\n next = read();\n return c;\n }\n\n public void flush() {\n try {\n os.write(cache.toString().getBytes(charset));\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != -1;\n }\n }\n\n public static class Debug {\n private boolean allowDebug;\n\n public Debug(boolean allowDebug) {\n this.allowDebug = allowDebug;\n }\n\n public void assertTrue(boolean flag) {\n if (!allowDebug) {\n return;\n }\n if (!flag) {\n fail();\n }\n }\n\n public void fail() {\n throw new RuntimeException();\n }\n\n public void assertFalse(boolean flag) {\n if (!allowDebug) {\n return;\n }\n if (flag) {\n fail();\n }\n }\n\n private void outputName(String name) {\n System.out.print(name + \" = \");\n }\n\n public void debug(String name, int x) {\n if (!allowDebug) {\n return;\n }\n\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, long x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, double x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, int[] x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.toString(x));\n }\n\n public void debug(String name, long[] x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.toString(x));\n }\n\n public void debug(String name, double[] x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.toString(x));\n }\n\n public void debug(String name, Object x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, Object... x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.deepToString(x));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16a313c94c45cbef8c53ddb07995ed43", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "// https://codeforces.com/contest/1174/submission/55043857 (rainboy)\nimport java.io.*;\n\npublic class CF1174E {\n\tstatic final int MD = 1000000007;\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint[] aa = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\taa[i] = i % 2 == 0 ? aa[i / 2] + 1 : 0;\n\t\tint k = 0;\n\t\twhile (1 << k + 1 <= n)\n\t\t\tk++;\n\t\tint[] cnt = new int[k + 1];\n\t\tint[] cnt3 = new int[k + 1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tint a = aa[i];\n\t\t\tcnt[a]++;\n\t\t\tif (i % 3 == 0)\n\t\t\t\tcnt3[a]++;\n\t\t}\n\t\tlong[][] dp = new long[n + 1][k + 1];\n\t\tdp[1][k] = 1;\n\t\tfor (int i = 1; i < n; i++)\n\t\t\tfor (int h = 0; h <= k; h++) {\n\t\t\t\tlong x = dp[i][h];\n\t\t\t\tif (x != 0) {\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\tdp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;\n\t\t\t\t\tdp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;\n\t\t\t\t}\n\t\t\t}\n\t\tlong ans = dp[n][0];\n\t\tif (3 << k - 1 <= n) {\n\t\t\tdp = new long[n + 1][k];\n\t\t\tlong[][] dq = new long[n + 1][k];\n\t\t\tdq[1][k - 1] = 1;\n\t\t\tfor (int i = 1; i < n; i++)\n\t\t\t\tfor (int h = 0; h < k; h++) {\n\t\t\t\t\tlong x = dq[i][h];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t\tdq[i + 1][h - 1] = (dq[i + 1][h - 1] + x * cnt3[h - 1]) % MD;\n\t\t\t\t\t\tdq[i + 1][h] = (dq[i + 1][h] + x * (n / (3 << h) - i)) % MD;\n\t\t\t\t\t\tdp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - n / (3 << h))) % MD;\n\t\t\t\t\t}\n\t\t\t\t\tx = dp[i][h];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t\tdp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;\n\t\t\t\t\t\tdp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tans = (ans + dp[n][0]) % MD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3cf554536d865067920c678dc6d799b3", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\npublic class Coloring\r\n{\r\n public static void main(String...args)\r\n {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n String s = br.readLine();\r\n String[] st = s.trim().split(\"\\\\s+\");\r\n int n = Integer.parseInt(st[0]);\r\n int m = Integer.parseInt(st[1]);\r\n \r\n if(n < m)\r\n swap(n , m);\r\n \r\n long mod = 998244353;\r\n \r\n long res[][] = new long[n+m][n];\r\n \r\n for(int i = 0 ; i < n+m ; i++){\r\n for(int j = 0 ; j < n ; j++){\r\n if(j == 0)\r\n res[i][j] = 1;\r\n else if(i == 0)\r\n res[i][j] = 0;\r\n else\r\n res[i][j] = res[i-1][j-1] + res[i-1][j];\r\n }\r\n }\r\n \r\n long ans2 = 0;\r\n \r\n for(int rows = 1 ; rows < n ; rows++){\r\n long ans1 = 0;\r\n for(int col = m-1 ; col >=0 ; col--){\r\n ans1 = (ans1 + res[n - rows + m - col -1][n - rows]*(res[n - rows + col - 1][n - rows - 1])) % mod;\r\n ans2 = (ans2 + res[rows + col -1][rows] * ((res[rows + m - col - 1][rows - 1] * ans1) % mod)) % mod;\r\n }\r\n }\r\n \r\n swap(n , m);\r\n for(int rows = 1 ; rows < n ; rows++){\r\n long ans1 = 0;\r\n for(int col = m-1 ; col >=0 ; col--){\r\n ans2 = (ans2 + res[rows + col -1][rows] * ((res[rows + m - col - 1][rows - 1] * ans1) % mod)) % mod;\r\n ans1 = (ans1 + res[n - rows + m - col -1][n - rows]*(res[n - rows + col - 1][n - rows - 1])) % mod;\r\n }\r\n }\r\n \r\n ans2 = (ans2 * 2) % mod;\r\n System.out.println(ans2);\r\n \r\n }\r\n \r\n public static void swap(int x , int y){\r\n int temp;\r\n temp = x;\r\n x = y;\r\n y = temp;\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0a2cf8a589cf99e5c870dd27b8949cad", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\npublic class Coloring\r\n{\r\n public static void main(String...args)\r\n {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n String s = br.readLine();\r\n String[] st = s.trim().split(\"\\\\s+\");\r\n int n = Integer.parseInt(st[0]);\r\n int m = Integer.parseInt(st[1]);\r\n \r\n if(n < m)\r\n swap(n , m);\r\n \r\n long mod = 998244353;\r\n \r\n long res[][] = new long[n+m][n];\r\n \r\n for(int i = 0 ; i < n+m ; i++){\r\n for(int j = 0 ; j < n ; j++){\r\n if(j == 0)\r\n res[i][j] = 1;\r\n else if(i == 0)\r\n res[i][j] = 0;\r\n else\r\n res[i][j] = res[i-1][j-1] + res[i-1][j];\r\n }\r\n }\r\n \r\n long ans2 = 0;\r\n \r\n for(int rows = 1 ; rows < n ; rows++){\r\n long ans1 = 0;\r\n for(int col = m-1 ; col >=0 ; col--){\r\n ans1 = (ans1 + res[n - rows + m - col -1][n - rows]*(res[n - rows + col - 1][n - rows - 1])) % mod;\r\n ans2 = (ans2 + res[rows + col -1][rows] * ((res[rows + m - col - 1][rows - 1] * ans1) % mod)) % mod;\r\n }\r\n }\r\n \r\n swap(n , m);\r\n for(int rows = 1 ; rows < n ; rows++){\r\n long ans1 = 0;\r\n for(int col = m-1 ; col >=0 ; col--){\r\n ans2 = (ans2 + res[rows + col -1][rows] * ((res[rows + m - col - 1][rows - 1] * ans1) % mod)) % mod;\r\n ans1 = (ans1 + res[n - rows + m - col -1][n - rows]*(res[n - rows + col - 1][n - rows - 1])) % mod;\r\n }\r\n }\r\n \r\n ans2 = (ans2 * 2) % mod;\r\n System.out.println(ans2);\r\n \r\n }\r\n \r\n public void swap(int x , int y){\r\n int temp;\r\n temp = x;\r\n x = y;\r\n y = temp;\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "26b9a7647105b9e61957a759395f90ca", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\npublic class Coloring\r\n{\r\n public static void main(String...args)throws IOException\r\n {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n String s = br.readLine();\r\n String[] st = s.trim().split(\"\\\\s+\");\r\n int n = Integer.parseInt(st[0]);\r\n int m = Integer.parseInt(st[1]);\r\n \r\n if(n < m)\r\n n= swap(m , m = n);\r\n \r\n long mod = 998244353;\r\n \r\n long res[][] = new long[n+m][n];\r\n \r\n for(int i = 0 ; i < n+m ; i++){\r\n for(int j = 0 ; j < n ; j++){\r\n if(j == 0)\r\n res[i][j] = 1;\r\n else if(i == 0)\r\n res[i][j] = 0;\r\n else\r\n res[i][j] = (res[i-1][j-1] + res[i-1][j]) % mod;\r\n }\r\n }\r\n \r\n long ans2 = 0;\r\n \r\n for(int rows = 1 ; rows < n ; rows++){\r\n long ans1 = 0;\r\n for(int col = m-1 ; col >= 1 ; col--){\r\n ans1 = (ans1 + res[n - rows + m - col -1][n - rows]*(res[n - rows + col - 1][n - rows - 1])) % mod;\r\n ans2 = (ans2 + res[rows + col -1][rows] * ((res[rows + m - col - 1][rows - 1] * ans1) % mod)) % mod;\r\n }\r\n }\r\n \r\n n= swap(m , m = n);\r\n //System.out.println(n+\" \"+m);\r\n for(int rows = 1 ; rows < n ; rows++){\r\n long ans1 = 0;\r\n for(int col = m-1 ; col >= 1 ; col--){\r\n ans2 = (ans2 + res[rows + col -1][rows] * ((res[rows + m - col - 1][rows - 1] * ans1) % mod)) % mod;\r\n ans1 = (ans1 + res[n - rows + m - col -1][n - rows]*(res[n - rows + col - 1][n - rows - 1])) % mod;\r\n }\r\n }\r\n \r\n ans2 = (ans2 * 2) % mod;\r\n System.out.println(ans2);\r\n \r\n }\r\n \r\n public static int swap(int...args){\r\n return args[0];\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c4e146ecc92173c9a82b0613746c2105", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb", "difficulty": 3100.0} {"lang": "Java 11", "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 stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6e9410a8358fa30f53050cac23fb3b64", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n int n;\n char[] colorCard;\n int[] costRedToken;\n int[] costBlueToken;\n final int inf = (int) 1e9;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.readInt();\n colorCard = new char[n];\n costRedToken = new int[n];\n costBlueToken = new int[n];\n\n int overRed = 0;\n int overBlue = 0;\n\n for (int i = 0; i < n; i++) {\n colorCard[i] = in.readCharacter();\n\n costRedToken[i] = in.readInt();\n costBlueToken[i] = in.readInt();\n\n overRed += Math.max(costRedToken[i] - n, 0);\n overBlue += Math.max(costBlueToken[i] - n, 0);\n\n costRedToken[i] = Math.min(n, costRedToken[i]);\n costBlueToken[i] = Math.min(n, costBlueToken[i]);\n }\n\n\n int over = Math.max(overRed, overBlue);\n\n int[][][] dp = new int[2][n * n + 1][1 << n];\n ArrayUtils.fill(dp, inf);\n\n if (overRed > overBlue) {\n dp[0][Math.min(overRed, n * n)][0] = 0;\n } else {\n dp[1][Math.min(overBlue, n * n)][0] = 0;\n }\n\n for (int msk = 0; msk < (1 << n); msk++) {\n for (int typeRemToken = 0; typeRemToken < 2; typeRemToken++) {\n for (int countRemTokens = 0; countRemTokens <= n * n; countRemTokens++) {\n\n if (dp[typeRemToken][countRemTokens][msk] == inf) {\n continue;\n }\n\n int countRedCard = 0;\n int countBlueCard = 0;\n for (int card = 0; card < n; card++) {\n if (((msk >> card) & 1) == 1) {\n if (colorCard[card] == 'R') {\n ++countRedCard;\n } else if (colorCard[card] == 'B') {\n ++countBlueCard;\n } else {\n throw new RuntimeException();\n }\n }\n }\n\n for (int card = 0; card < n; card++) {\n if (((msk >> card) & 1) == 1) {\n continue;\n }\n\n int countHaveRedToken = typeRemToken == 0 ? countRemTokens : 0;\n int countHaveBlueToken = typeRemToken == 1 ? countRemTokens : 0;\n\n int costRed = Math.max(costRedToken[card] - countRedCard, 0);\n int costBlue = Math.max(costBlueToken[card] - countBlueCard, 0);\n\n int countBuyToken = Math.max(Math.max(costRed - countHaveRedToken, 0), Math.max(costBlue -\n countHaveBlueToken, 0));\n\n int remRedToken = countBuyToken + countHaveRedToken - costRed;\n int remBlueToken = countBuyToken + countHaveBlueToken - costBlue;\n\n int toMsk = msk | (1 << card);\n int toTypeRemToken = remRedToken == 0 ? 1 : 0;\n int toCountRemTokens = Math.max(remRedToken, remBlueToken);\n\n dp[toTypeRemToken][toCountRemTokens][toMsk] = Math.min\n (dp[toTypeRemToken][toCountRemTokens][toMsk],\n dp[typeRemToken][countRemTokens][msk] + countBuyToken);\n\n }\n }\n }\n }\n\n int curAns = inf;\n for (int typeRemToken = 0; typeRemToken < 2; typeRemToken++) {\n for (int countRemTokens = 0; countRemTokens <= n * n; countRemTokens++) {\n curAns = Math.min(curAns, dp[typeRemToken][countRemTokens][(1 << n) - 1]);\n }\n }\n out.printLine(n + over + curAns);\n// out.printLine(dp[0][1][0b1]);\n// out.printLine(dp[0][1][0b11]);\n// out.printLine(dp[0][1][0b111]);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if ((c < '0') || (c > '9')) {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return (c == ' ') || (c == '\\n') || (c == '\\r') || (c == '\\t') || (c == -1);\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n return (char) c;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n\n static class ArrayUtils {\n public static void fill(int[][] array, int value) {\n for (int[] row : array) {\n Arrays.fill(row, value);\n }\n }\n\n public static void fill(int[][][] array, int value) {\n for (int[][] subArray : array) {\n fill(subArray, value);\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "504eb9bf5bae1c40fab487161e5e09ad", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969", "difficulty": 2400.0} {"lang": "Java 8", "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 class Pair {\n\t\tint r, b;\n\n\t\tpublic Pair(int r, int b) {\n\t\t\tthis.r = r;\n\t\t\tthis.b = b;\n\t\t}\n\t\t\n\t\tboolean worse(Pair o) {\n\t\t\treturn r >= o.r && b >= o.b;\n\t\t}\n\t}\n\t\n\tstatic class Options {\n\t\tList lst = new ArrayList<>();\n\t\t// r increasing, b decreasing\n\t\t\n\t\tvoid add(Pair p) {\n\t\t\t\n\t\t\tfor (int i = 0; i < lst.size(); i++) {\n\t\t\t\tif (p.worse(lst.get(i))) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint idxL = 0;\n\t\t\twhile (idxL < lst.size() && p.b <= lst.get(idxL).b) {\n\t\t\t\tidxL++;\n\t\t\t}\n\t\t\t\n\t\t\tint idxR = lst.size() - 1;\n\t\t\twhile (idxR >= 0 && p.r <= lst.get(idxR).r) {\n\t\t\t\tidxR--;\n\t\t\t}\n\t\t\t\n\t\t\t// < idxL and > idxR must be removed\n\t\t\tfor (int idx = idxL - 1; idx > idxR; idx--) {\n\t\t\t\tlst.remove(idx);\n\t\t\t}\n\t\t\t\n\t\t\tlst.add(idxR + 1, p);\n\t\t}\n\t}\n\n\tint solve(int n, char[] types, int[] rs, int[] bs) {\n\t\tOptions[] dp = new Options[1 << n];\n\t\tfor (int i = 0; i < 1 << n; i++) {\n\t\t\tdp[i] = new Options();\n\t\t}\n\t\t\n\t\tdp[0].add(new Pair(0, 0));\n\t\t\n\t\tint maskR = 0;\n\t\tint maskB = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (types[i] == 'R') {\n\t\t\t\tmaskR |= 1 << i;\n\t\t\t} else {\n\t\t\t\tmaskB |= 1 << i;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\n\t\t\tint discR = Integer.bitCount(mask & maskR);\n\t\t\tint discB = Integer.bitCount(mask & maskB);\n\t\t\t\n\t\t\tfor (Pair p : dp[mask].lst) {\n\t\t\t\tfor (int nxt = 0; nxt < n; nxt++) {\n\t\t\t\t\tif (test(mask, nxt)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint costR = Math.max(rs[nxt] - discR, 0);\n\t\t\t\t\tint costB = Math.max(bs[nxt] - discB, 0);\n\t\t\t\t\t\n\t\t\t\t\tdp[mask | (1 << nxt)].add(new Pair(p.r + costR, p.b + costB));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint ret = Integer.MAX_VALUE;\n\t\tfor (Pair p : dp[(1 << n) - 1].lst) {\n\t\t\tret = Math.min(ret, Math.max(p.r, p.b));\n\t\t}\n\t\t\n\t\treturn ret + n;\n\t}\n\t\n\tboolean test(int mask, int i) {\n\t\treturn ((mask >> i) & 1) == 1;\n\t}\n\t\n\tvoid submit() throws IOException {\n\t\tint n = nextInt();\n\t\tchar[] types = new char[n];\n\t\tint[] rs = new int[n];\n\t\tint[] bs = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttypes[i] = nextToken().charAt(0);\n\t\t\trs[i] = nextInt();\n\t\t\tbs[i] = nextInt();\n\t\t}\n\t\tout.println(solve(n, types, rs, bs));\n\t}\n\t\n\tRandom rng = new Random();\n\t\n\tvoid testTime() {\n\t\tint n = 16;\n\t\tchar[] types = new char[n];\n\t\tint[] rs = new int[n];\n\t\tint[] bs = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttypes[i] = \"RB\".charAt(rng.nextInt(2));\n\t\t\trs[i] = rng.nextInt(5);\n\t\t\tbs[i] = rng.nextInt(5);\n\t\t}\n\t\t\n\t\tout.println(solve(n, types, rs, bs));\n\t}\n\t\n\tvoid testCorrectness(int n, int bound) {\n\t\tchar[] types = new char[n];\n\t\tint[] rs = new int[n];\n\t\tint[] bs = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttypes[i] = \"RB\".charAt(rng.nextInt(2));\n\t\t\trs[i] = rng.nextInt(bound);\n\t\t\tbs[i] = rng.nextInt(bound);\n\t\t}\n\t\t\n\t\tif (solve(n, types, rs, bs) != brute(n, types, rs, bs)) {\n\t\t\tSystem.err.println(n);\n\t\t\tSystem.err.println(Arrays.toString(rs));\n\t\t\tSystem.err.println(Arrays.toString(bs));\n\t\t\tthrow new AssertionError();\n\t\t}\n\t}\n\t\n\tint brute(int n, char[] types, int[] rs, int[] bs) {\n\t\tint ret = Integer.MAX_VALUE;\n\t\tint[] perm = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tperm[i] = i;\n\t\t}\n\t\t\n\t\tdo {\n\t\t\tint totR = 0;\n\t\t\tint totB = 0;\n\t\t\tint cR = 0;\n\t\t\tint cB = 0;\n\t\t\tfor (int idx : perm) {\n\t\t\t\ttotR += Math.max(rs[idx] - cR, 0);\n\t\t\t\ttotB += Math.max(bs[idx] - cB, 0);\n\t\t\t\tif (types[idx] == 'R') {\n\t\t\t\t\tcR++;\n\t\t\t\t} else {\n\t\t\t\t\tcB++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret = Math.min(ret, Math.max(totR, totB));\n\t\t} while (nextPermutation(perm));\n\t\t\n\t\treturn ret + n;\n\t}\n\t\n\tstatic boolean nextPermutation(int[] a) {\n\t\tint n = a.length;\n\t\tint ptr = n - 2;\n\t\twhile (ptr >= 0 && a[ptr] > a[ptr + 1]) {\n\t\t\tptr--;\n\t\t}\n\t\tif (ptr < 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (int i = ptr + 1, 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\tfor (int i = ptr + 1;; i++) {\n\t\t\tif (a[ptr] < a[i]) {\n\t\t\t\tint tmp = a[ptr];\n\t\t\t\ta[ptr] = 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\n\tC() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n//\t\ttestTime();\n//\t\tfor (int tst = 0; tst < 10000; tst++) {\n//\t\t\ttestCorrectness(5, 5);\n//\t\t\tSystem.err.println(tst);\n//\t\t}\n\t\tsubmit();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4124266bb9d855b016576671ce8b3f33", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Wolfgang Beyer\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n int n;\n int[] r;\n int[] b;\n int[][][] dp;\n int[] numRedCards;\n int[] numBlueCards;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n boolean[] isRed = new boolean[n];\n r = new int[n];\n b = new int[n];\n int extraRed = 0;\n int extraBlue = 0;\n for (int i = 0; i < n; i++) {\n if (in.next().charAt(0) == 'R') isRed[i] = true;\n r[i] = in.nextInt();\n if (r[i] > n) {\n extraRed += r[i] - n;\n r[i] = n;\n }\n b[i] = in.nextInt();\n if (b[i] > n) {\n extraBlue += b[i] - n;\n b[i] = n;\n }\n }\n int result = Math.max(extraBlue, extraRed);\n //System.out.println(result);\n dp = new int[1 << n][2][n * n + 1]; // bitmask, leftovers are red?, leftover coins\n for (int[][] x : dp) for (int[] y : x) Arrays.fill(y, -1);\n\n\n numRedCards = new int[1 << n];\n numBlueCards = new int[1 << n];\n for (int i = 0; i < 1 << n; i++) {\n for (int j = 0; j < n; j++) {\n if (((i >> j) & 1) == 1) {\n if (isRed[j]) numRedCards[i]++;\n else numBlueCards[i]++;\n }\n }\n //System.out.println(i + \": \" + numRedCards[i] + \", \" + numBlueCards[i]);\n }\n\n if (extraRed > extraBlue) {\n out.println(n + result + traverse(0, 0, extraRed - extraBlue));\n } else {\n out.println(n + result + traverse(0, 1, extraBlue - extraRed));\n }\n }\n\n public int traverse(int mask, int leftOverRed, int amount) {\n amount = Math.min(amount, n * n);\n if (mask == (1 << n) - 1) return 0;\n if (dp[mask][leftOverRed][amount] != -1) return dp[mask][leftOverRed][amount];\n\n int result = Integer.MAX_VALUE;\n for (int i = 0; i < n; i++) {\n if (((mask >> i) & 1) == 1) continue;\n int newMask = mask | (1 << i);\n int haveRed = leftOverRed == 1 ? amount : 0;\n int haveBlue = leftOverRed == 0 ? amount : 0;\n int needRed = Math.max(0, r[i] - numRedCards[mask] - haveRed);\n int needBlue = Math.max(0, b[i] - numBlueCards[mask] - haveBlue);\n int needMoves = Math.max(needRed, needBlue);\n\n if (needRed >= needBlue) { // wichtig dass 2 Mal >=, ansonsten funktioniert's nicht!\n int amountNew = haveBlue + needRed - Math.max(0, b[i] - numBlueCards[mask]);\n result = Math.min(result, needMoves + traverse(newMask, 0, amountNew));\n }\n if (needBlue >= needRed) {\n int amountNew = haveRed + needBlue - Math.max(0, r[i] - numRedCards[mask]);\n result = Math.min(result, needMoves + traverse(newMask, 1, amountNew));\n }\n }\n dp[mask][leftOverRed][amount] = result;\n return result;\n }\n\n }\n\n static class InputReader {\n private static BufferedReader in;\n private static StringTokenizer tok;\n\n public InputReader(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n try {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n } catch (IOException ex) {\n System.err.println(\"An IOException was caught :\" + ex.getMessage());\n }\n return tok.nextToken();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6e65d975b6545787e2a0cf471790e7a5", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Template implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n try {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } catch (Exception e) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n try {\n tok = new StringTokenizer(in.readLine(), \" :\");\n } catch (Exception e) {\n return null;\n }\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n int[] readIntArray(int size) throws IOException {\n int[] res = new int[size];\n for (int i = 0; i < size; i++) {\n res[i] = readInt();\n }\n return res;\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n List[] createGraphList(int size) {\n List[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n time();\n memory();\n }\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n void solve() throws IOException {\n int n = readInt();\n char[] type = new char[n];\n int[] r = new int[n];\n int[] b = new int[n];\n for (int i = 0; i < n; i++) {\n type[i] = readString().charAt(0);\n r[i] = readInt();\n b[i] = readInt();\n }\n\n int max = 1 << n;\n int[] Rsum = new int[max];\n int[] Bsum = new int[max];\n int[] Rcnt = new int[max];\n int[] Bcnt = new int[max];\n for (int mask = 0; mask < max; mask++) {\n for (int j = 0; j < n; j++) {\n if (has(mask, j)) {\n Rsum[mask] += r[j];\n Bsum[mask] += b[j];\n\n Rcnt[mask] += type[j] == 'R' ? 1 : 0;\n Bcnt[mask] += type[j] == 'R' ? 0 : 1;\n }\n }\n }\n\n int MAX_DIFF = n + 1;\n\n _Ez_Int__Int_HashMap[] dp = new _Ez_Int__Int_HashMap[max];\n for (int i = 0; i < max; i++) {\n dp[i] = new _Ez_Int__Int_HashMap(16);\n }\n dp[0].put(0, 0);\n for (int mask = 0; mask < max; mask++) {\n for (int index = 0; index < dp[mask].status.length; index++) {\n if (dp[mask].status[index] == _Ez_Int__Int_HashMap.FILLED) {\n int key = dp[mask].keys[index];\n int value = dp[mask].values[index];\n int rd = getA(key);\n int bd = getB(key);\n\n int nowR = value - (Rsum[mask] - rd);\n int nowB = value - (Bsum[mask] - bd);\n\n for (int next = 0; next < n; next++) {\n if (has(mask, next)) continue;\n\n int needR = Math.max(0, r[next] - Rcnt[mask]);\n int needB = Math.max(0, b[next] - Bcnt[mask]);\n\n int needBuy = Math.max(needR - nowR, needB - nowB);\n int nextVal = value;\n if (needBuy > 0) {\n nextVal += needBuy;\n }\n int nextMask = mask | (1 << next);\n int nrd = rd + r[next] - needR;\n int nbd = bd + b[next] - needB;\n dp[nextMask].put(comb(nrd, nbd), nextVal);\n }\n }\n }\n }\n\n int min = Integer.MAX_VALUE;\n for (int index=0;index 1/8 arraysLength\n // 3. size >= removedCount\n // arraysLength can be only multiplied by 2 and divided by 2.\n // Also, if it becomes >= 32, it can't become less anymore.\n private static final int REBUILD_LENGTH_THRESHOLD = 32;\n\n private static final int HASHCODE_INITIAL_VALUE = 0x811c9dc5;\n private static final int HASHCODE_MULTIPLIER = 0x01000193;\n\n private static final byte FREE = 0;\n private static final byte REMOVED = 1;\n private static final byte FILLED = 2;\n\n private static final /*V*/ int/*V*/ DEFAULT_NULL_VALUE = Integer.MIN_VALUE;\n\n private static final Random rnd = new Random();\n private static final int POS_RANDOM_SHIFT_1;\n private static final int POS_RANDOM_SHIFT_2;\n private static final int STEP_RANDOM_SHIFT_1;\n private static final int STEP_RANDOM_SHIFT_2;\n\n static {\n POS_RANDOM_SHIFT_1 = rnd.nextInt(10) + 11;\n POS_RANDOM_SHIFT_2 = rnd.nextInt(10) + 21;\n STEP_RANDOM_SHIFT_1 = rnd.nextInt(10) + 11;\n STEP_RANDOM_SHIFT_2 = rnd.nextInt(10) + 21;\n }\n\n private /*K*/ int/*K*/[] keys;\n private /*V*/ int/*V*/[] values;\n private byte[] status;\n private int size;\n private int removedCount;\n private int mask;\n private final int hashSeed;\n\n public _Ez_Int__Int_HashMap() {\n this(DEFAULT_CAPACITY);\n }\n\n public _Ez_Int__Int_HashMap(int capacity) {\n if (capacity < 0) {\n throw new IllegalArgumentException(\"Capacity must be non-negative\");\n }\n // Actually we need 4x more memory\n int length = 4 * Math.max(1, capacity);\n if ((length & (length - 1)) != 0) {\n length = Integer.highestOneBit(length) << 1;\n }\n // Length is a power of 2 now\n initEmptyTable(length);\n hashSeed = rnd.nextInt();\n }\n\n private int getStartPos(int h) {\n h ^= hashSeed;\n h ^= (h >>> POS_RANDOM_SHIFT_1) ^ (h >>> POS_RANDOM_SHIFT_2);\n return h & mask;\n }\n\n private int getStep(int h) {\n h ^= hashSeed;\n h ^= (h >>> STEP_RANDOM_SHIFT_1) ^ (h >>> STEP_RANDOM_SHIFT_2);\n return ((h << 1) | 1) & mask;\n }\n\n public int size() {\n return size;\n }\n\n public /*V*/int/*V*/ get(/*K*/int/*K*/ key) {\n final int keyHash = key;\n int pos = getStartPos(keyHash);\n final int step = getStep(keyHash);\n for (; status[pos] != FREE; pos = (pos + step) & mask) {\n if (status[pos] == FILLED && keys[pos] == key) {\n return values[pos];\n }\n }\n return DEFAULT_NULL_VALUE;\n }\n\n public /*V*/int/*V*/ put(/*K*/int/*K*/ key, /*V*/int/*V*/ value) {\n final int keyHash = key;\n int pos = getStartPos(keyHash);\n final int step = getStep(keyHash);\n for (; status[pos] == FILLED; pos = (pos + step) & mask) {\n if (keys[pos] == key) {\n final /*V*/ int/*V*/ oldValue = values[pos];\n values[pos] = value;\n return oldValue;\n }\n }\n if (status[pos] == FREE) {\n status[pos] = FILLED;\n keys[pos] = key;\n values[pos] = value;\n size++;\n return DEFAULT_NULL_VALUE;\n }\n final int removedPos = pos;\n for (pos = (pos + step) & mask; status[pos] != FREE; pos = (pos + step) & mask) {\n if (status[pos] == FILLED && keys[pos] == key) {\n final /*V*/ int/*V*/ oldValue = values[pos];\n values[pos] = value;\n return oldValue;\n }\n }\n status[removedPos] = FILLED;\n keys[removedPos] = key;\n values[removedPos] = value;\n size++;\n removedCount--;\n return DEFAULT_NULL_VALUE;\n }\n\n private void initEmptyTable(int length) {\n keys = new /*K*/int/*K*/[length];\n values = new /*V*/int/*V*/[length];\n status = new byte[length];\n size = 0;\n removedCount = 0;\n mask = length - 1;\n }\n\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a0ada5513b711a385c4b39f59c42e82a", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class KuroAndTopologicalParity {\n \n int MOD = (int) 1e9 + 7;\n int N = 55;\n \n long[] p2 = new long[N];\n long[][] c = new long[N][N];\n long[][] cs = new long[N][2];\n \n long[][][][] dp = new long[N][N][N][N];\n \n {\n p2[0] = 1;\n for (int i = 1; i < N; i++) p2[i] = p2[i - 1] * 2 % MOD;\n \n for (int i = 0; i < N; i++) {\n c[i][0] = 1;\n for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;\n }\n \n for (int i = 0; i < N; i++) {\n for (int j = 0; j <= i; j++) {\n cs[i][j & 1] = (cs[i][j & 1] + c[i][j]) % MOD;\n }\n }\n }\n \n void solve() {\n int n = in.nextInt(), p = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n \n long ans = 0;\n dp[0][0][0][0] = 1;\n for (int i = 0; i < n; i++) {\n for (int ob = 0; ob <= i + 1; ob++) {\n for (int eb = 0; ob + eb <= i + 1; eb++) {\n for (int ow = 0; ob + eb + ow <= i + 1; ow++) {\n int ew = (i + 1) - (ob + eb + ow);\n calc(a[i], ob, eb, ow, ew);\n if (i + 1 == n && (ob + ow) % 2 == p) {\n ans = (ans + dp[ob][eb][ow][ew]) % MOD;\n }\n }\n }\n }\n }\n out.println(ans);\n }\n \n void calc(int color, int ob, int eb, int ow, int ew) {\n if (color != 0 && ew > 0) {\n dp[ob][eb][ow][ew] += dp[ob][eb][ow][ew - 1] * p2[ow + ew + eb - 1] % MOD * cs[ob][1] % MOD;\n }\n if (color != 0 && ow > 0) {\n dp[ob][eb][ow][ew] += dp[ob][eb][ow - 1][ew] * p2[ow + ew + eb - 1] % MOD * cs[ob][0] % MOD;\n }\n if (color != 1 && eb > 0) {\n dp[ob][eb][ow][ew] += dp[ob][eb - 1][ow][ew] * p2[ob + eb + ew - 1] % MOD * cs[ow][1] % MOD;\n }\n if (color != 1 && ob > 0) {\n dp[ob][eb][ow][ew] += dp[ob - 1][eb][ow][ew] * p2[ob + eb + ew - 1] % MOD * cs[ow][0] % MOD;\n }\n dp[ob][eb][ow][ew] %= 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 KuroAndTopologicalParity().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0825f3b00ae4a6be36e50f84e68ca5a6", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Div2_482E {\n\n\tstatic int nV;\n\tstatic int p;\n\n\tstatic int[] color;\n\n\tstatic long[] pow2;\n\n\tstatic long[][][][] dp;\n\n\tstatic long MOD = 1_000_000_007;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tpow2 = new long[500];\n\t\tpow2[0] = 1;\n\t\tfor (int i = 1; i < 500; i++) {\n\t\t\tpow2[i] = pow2[i - 1] * 2 % MOD;\n\t\t}\n\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\tnV = Integer.parseInt(inputData.nextToken());\n\t\tp = Integer.parseInt(inputData.nextToken());\n\n\t\tcolor = new int[nV];\n\t\tinputData = new StringTokenizer(reader.readLine());\n\t\tfor (int i = 0; i < nV; i++) {\n\t\t\tcolor[i] = Integer.parseInt(inputData.nextToken());\n\t\t}\n\n\t\tdp = new long[nV + 1][nV + 1][nV + 1][nV + 1];\n\t\tdp[nV][0][0][0] = 1;\n\t\tpushDP(nV, 0, 0, 0);\n\n\t\tfor (int cV = nV - 1; cV > 0; cV--) {\n\t\t\tfor (int i = 0; i <= nV; i++) {\n\t\t\t\tfor (int j = 0; j <= nV; j++) {\n\t\t\t\t\tfor (int k = 0; k <= nV; k++) {\n\t\t\t\t\t\tint l = nV - cV - i - j - k;\n\t\t\t\t\t\tif (l >= 0 && dp[cV][i][j][k] != 0) {\n\t\t\t\t\t\t\tpushDP(cV, i, j, k);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int wE = 0; wE <= nV; wE++) {\n\t\t\tfor (int wO = 0; wO <= nV; wO++) {\n\t\t\t\tfor (int bE = 0; bE <= nV; bE++) {\n\t\t\t\t\tint bO = nV - wE - wO - bE;\n\n\t\t\t\t\tif (((wO + bO) & 1) == p) {\n\t\t\t\t\t\tans = (ans + dp[0][wE][wO][bE]) % MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprinter.println(ans);\n\t\tprinter.close();\n\t}\n\n\tstatic void pushDP(int cV, int wE, int wO, int bE) {\n\t\tint bO = nV - cV - wE - wO - bE;\n\t\tlong cDP = dp[cV][wE][wO][bE];\n\t\tif (cDP == 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// white\n\t\tif (color[cV - 1] == 0 || color[cV - 1] == -1) {\n\t\t\tif (bO != 0) {\n\t\t\t\tdp[cV - 1][wE + 1][wO][bE] = (dp[cV - 1][wE + 1][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;\n\t\t\t\tdp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;\n\t\t\t} else {\n\t\t\t\tdp[cV - 1][wE][wO + 1][bE] = (dp[cV - 1][wE][wO + 1][bE] + pow2[wE + wO + bO] * cDP) % MOD;\n\t\t\t}\n\t\t}\n\t\t// black\n\t\tif (color[cV - 1] == 1 || color[cV - 1] == -1) {\n\t\t\tif (wO != 0) {\n\t\t\t\tdp[cV - 1][wE][wO][bE + 1] = (dp[cV - 1][wE][wO][bE + 1] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;\n\t\t\t\tdp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wE + wO + bE + bO - 1] * cDP) % MOD;\n\t\t\t} else {\n\t\t\t\tdp[cV - 1][wE][wO][bE] = (dp[cV - 1][wE][wO][bE] + pow2[wO + bE + bO] * cDP) % MOD;\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f0d5030b20dc6bedfc6f5235483fb2cd", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Deque;\nimport java.util.HashMap;\nimport java.util.Map;\n\n/**\n * Created by dalt on 2018/5/30.\n */\npublic class Contest472E {\n static final int INF = (int) 1e8;\n static final int MOD = (int) 1e9 + 7;\n public static BlockReader input;\n public static PrintStream output;\n public static Debug debug;\n\n public static void main(String[] args) throws FileNotFoundException {\n init();\n\n solve();\n\n destroy();\n }\n\n public static void init() throws FileNotFoundException {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n input = new BlockReader(new FileInputStream(\"E:\\\\DATABASE\\\\TESTCASE\\\\codeforces\\\\Contest472E.in\"));\n output = System.out;\n } else {\n input = new BlockReader(System.in);\n output = new PrintStream(new BufferedOutputStream(System.out), false);\n }\n\n debug = new Debug();\n debug.enter(\"main\");\n }\n\n public static void solve() {\n int n = input.nextInteger();\n int p = input.nextInteger();\n\n long[][][] dp = new long[n][2][2];\n int[] c = new int[n];\n for (int i = 0; i < n; i++) {\n c[i] = input.nextInteger();\n }\n\n\n for (int i = n - 1; i >= 0; i--) {\n long[] cnt = new long[2];\n long[][] localDp = new long[2][2];\n\n if (c[i] == -1) {\n dp[i][0][1] = localDp[0][1] = 1;\n dp[i][1][1] = localDp[1][1] = 1;\n } else {\n dp[i][c[i]][1] = localDp[c[i]][1] = 1;\n }\n\n\n\n int num = n - 2 - i >= 0 ? Mathematics.pow(2, (n - 2 - i), MOD) : 0;\n for (int j = i + 1; j < n; j++) {\n if (c[j] == -1 || c[j] == 0) {\n dp[i][1][0] = (dp[i][1][0] + (localDp[1][0] * dp[j][0][0] + localDp[1][1] * dp[j][0][1]) * num) % MOD;\n dp[i][1][1] = (dp[i][1][1] + (localDp[1][1] * dp[j][0][0] + localDp[1][0] * dp[j][0][1]) * num) % MOD;\n }\n }\n for (int j = i + 1; j < n; j++) {\n if (c[j] == -1 || c[j] == 1) {\n dp[i][0][0] = (dp[i][0][0] + (localDp[0][0] * dp[j][1][0] + localDp[0][1] * dp[j][1][1]) * num) % MOD;\n dp[i][0][1] = (dp[i][0][1] + (localDp[0][1] * dp[j][1][0] + localDp[0][0] * dp[j][1][1]) * num) % MOD;\n }\n }\n }\n\n long sum = 0;\n for (int i = 0; i < n; i++) {\n sum = sum + dp[i][0][p] + dp[i][1][p];\n }\n sum %= MOD;\n output.println(sum);\n }\n\n public static void destroy() {\n output.flush();\n debug.exit();\n debug.statistic();\n }\n\n public static class Debug {\n boolean debug = System.getProperty(\"ONLINE_JUDGE\") == null;\n Deque stack = new ArrayDeque<>();\n Map fragmentMap = new HashMap<>();\n\n public void enter(String module) {\n if (debug) {\n stack.push(new ModuleRecorder(getModule(module)));\n }\n }\n\n public Module getModule(String moduleName) {\n Module module = fragmentMap.get(moduleName);\n if (module == null) {\n module = new Module(moduleName);\n fragmentMap.put(moduleName, module);\n }\n return module;\n }\n\n public void exit() {\n if (debug) {\n ModuleRecorder fragment = stack.pop();\n fragment.exit();\n }\n }\n\n public void statistic() {\n if (!debug) {\n return;\n }\n\n if (stack.size() > 0) {\n throw new RuntimeException(\"Exist unexited tag\");\n }\n System.out.println(\"\\n------------------------------------------\");\n\n System.out.println(\"memory used \" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + \"M\");\n\n System.out.println(\"\\n------------------------------------------\");\n for (Module module : fragmentMap.values()) {\n System.out.println(String.format(\"Module %s : enter %d : cost %d\", module.moduleName, module.enterTime, module.totaltime));\n }\n\n System.out.println(\"------------------------------------------\");\n }\n\n public static class ModuleRecorder {\n Module fragment;\n long time;\n\n public ModuleRecorder(Module fragment) {\n this.fragment = fragment;\n time = System.currentTimeMillis();\n }\n\n public void exit() {\n fragment.totaltime += System.currentTimeMillis() - time;\n fragment.enterTime++;\n }\n }\n\n public static class Module {\n String moduleName;\n long totaltime;\n long enterTime;\n\n public Module(String moduleName) {\n this.moduleName = moduleName;\n }\n }\n }\n\n public static class BlockReader {\n static final int EOF = -1;\n InputStream is;\n byte[] dBuf;\n int dPos, dSize, next;\n StringBuilder builder = new StringBuilder();\n\n public BlockReader(InputStream is) {\n this(is, 8192);\n }\n\n public BlockReader(InputStream is, int bufSize) {\n this.is = is;\n dBuf = new byte[bufSize];\n next = nextByte();\n }\n\n public int nextByte() {\n while (dPos >= dSize) {\n if (dSize == -1) {\n return EOF;\n }\n dPos = 0;\n try {\n dSize = is.read(dBuf);\n } catch (Exception e) {\n }\n }\n return dBuf[dPos++];\n }\n\n public String nextBlock() {\n builder.setLength(0);\n skipBlank();\n while (next != EOF && !Character.isWhitespace(next)) {\n builder.append((char) next);\n next = nextByte();\n }\n return builder.toString();\n }\n\n public void skipBlank() {\n while (Character.isWhitespace(next)) {\n next = nextByte();\n }\n }\n\n public int nextInteger() {\n skipBlank();\n int ret = 0;\n boolean rev = false;\n if (next == '+' || next == '-') {\n rev = next == '-';\n next = nextByte();\n }\n while (next >= '0' && next <= '9') {\n ret = (ret << 3) + (ret << 1) + next - '0';\n next = nextByte();\n }\n return rev ? -ret : ret;\n }\n\n public int nextBlock(char[] data, int offset) {\n skipBlank();\n int index = offset;\n int bound = data.length;\n while (next != EOF && index < bound && !Character.isWhitespace(next)) {\n data[index++] = (char) next;\n next = nextByte();\n }\n return index - offset;\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != EOF;\n }\n }\n\n public static class Mathematics {\n public static int gcd(int a, int b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n public static int gcd0(int a, int b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n public static long gcd(long a, long b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n public static long gcd0(long a, long b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n public static int inverse(int x, int mod) {\n return pow(x, mod - 2, mod);\n }\n\n public static int pow(int x, int n, int mod) {\n n = mod(n, mod - 1);\n x = mod(x, mod);\n int bit = 31 - Integer.numberOfLeadingZeros(n);\n long product = 1;\n for (; bit >= 0; bit--) {\n product = product * product % mod;\n if (((1 << bit) & n) != 0) {\n product = product * x % mod;\n }\n }\n return (int) product;\n }\n\n public static int mod(int x, int mod) {\n return x >= 0 ? x % mod : (((x % mod) + mod) % mod);\n }\n\n public static long cross(int x1, int y1, int x2, int y2) {\n return (long) x1 * y2 - (long) y1 * x2;\n }\n\n public static double cross(double x1, double y1, double x2, double y2) {\n return x1 * y2 - y1 * x2;\n }\n\n public static long permute(int n, int m) {\n return m == 0 ? 1 : n * permute(n - 1, m - 1);\n }\n\n public static int eulerSieve(int limit, int[] primes, int offset) {\n boolean[] isComp = new boolean[limit + 1];\n int wpos = offset;\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n primes[wpos++] = i;\n }\n for (int j = offset, until = limit / i; j < wpos && primes[j] <= until; j++) {\n int pi = primes[j] * i;\n isComp[pi] = true;\n if (i % primes[j] == 0) {\n break;\n }\n }\n }\n return wpos - offset;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0446c11c52812da37afee1c207003bf5", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "package com.jardon.pg.algorithm.codeforce.r4xx.r482;\n\nimport 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 KuroAndTopologicalParity2 {\n \n int MOD = (int) 1e9 + 7;\n int N = 55;\n \n long[] p2 = new long[N];\n long[][] c = new long[N][N];\n long[][] cs = new long[N][2];\n \n long[][][] dp = new long[N][N][N];\n \n {\n p2[0] = 1;\n for (int i = 1; i < N; i++) p2[i] = p2[i - 1] * 2 % MOD;\n \n for (int i = 0; i < N; i++) {\n c[i][0] = 1;\n for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;\n }\n \n for (int i = 0; i < N; i++) {\n for (int j = 0; j <= i; j++) {\n cs[i][j & 1] = (cs[i][j & 1] + c[i][j]) % MOD;\n }\n }\n }\n \n void solve() {\n int n = in.nextInt(), p = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n \n long ans = 0;\n dp[0][0][0] = 1;\n for (int i = 0; i < n; i++) {\n for (int ob = 0; ob <= i + 1; ob++) {\n for (int ow = 0; ob + ow <= i + 1; ow++) {\n if (a[i] != 0 && i - ob >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow] * p2[i - ob] * cs[ob][1];\n if (a[i] != 0 && ow - 1 >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow - 1] * p2[i - ob] * cs[ob][0];\n if (a[i] != 1 && i - ow >= 0) dp[i + 1][ob][ow] += dp[i][ob][ow] * p2[i - ow] * cs[ow][1];\n if (a[i] != 1 && ob - 1 >= 0) dp[i + 1][ob][ow] += dp[i][ob - 1][ow] * p2[i - ow] * cs[ow][0];\n if (i + 1 == n && ((ob + ow) & 1) == p) ans += dp[i + 1][ob][ow];\n }\n }\n }\n out.println(ans);\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new KuroAndTopologicalParity2().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d7fe95089a73ba37f35afcf3cc1c9573", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n final int inf = 1000;\n int n, m;\n int[][] dist;\n IntArrayList[] gr;\n\n// n = in.readInt();\n// m = in.readInt();\n n = 400;\n\n dist = new int[n][n];\n ArrayUtils.fill(dist, inf);\n gr = new IntArrayList[n];\n for (int v = 0; v < n; v++) {\n dist[v][v] = 0;\n gr[v] = new IntArrayList();\n }\n\n// for (int iter = 0; iter < m; iter++) {\n// int a = in.readInt() - 1;\n// int b = in.readInt() - 1;\n// dist[a][b] = dist[b][a] = 1;\n// gr[a].add(b);\n// gr[b].add(a);\n// }\n//\n for (int a = 0; a < n; a++) {\n for (int b = a + 1; b < n; b++) {\n dist[a][b] = dist[b][a] = 1;\n gr[a].add(b);\n gr[b].add(a);\n }\n }\n\n for (int k = 0; k < n; k++) {\n for (int v = 0; v < n; v++) {\n for (int to = 0; to < n; to++) {\n dist[v][to] = Math.min(dist[v][to], dist[v][k] + dist[k][to]);\n }\n }\n }\n\n boolean[] used = new boolean[n];\n IntArrayList citiesBear0 = new IntArrayList(n);\n IntArrayList citiesBear1 = new IntArrayList(n);\n\n double dp = 0;\n for (int v0 = 0; v0 < n; v0++) {\n double dp_V0 = 0;\n for (int d0 = 0; d0 < n; d0++) {\n\n while (0 < citiesBear0.size()) {\n citiesBear0.popLast();\n }\n while (0 < citiesBear1.size()) {\n citiesBear1.popLast();\n }\n Arrays.fill(used, false);\n\n for (int cityBear0 = 0; cityBear0 < n; cityBear0++) {\n if (dist[v0][cityBear0] == d0) {\n citiesBear0.add(cityBear0);\n for (int cityBear1 : gr[cityBear0]) {\n if (!used[cityBear1]) {\n used[cityBear1] = true;\n citiesBear1.add(cityBear1);\n }\n }\n }\n }\n\n if (citiesBear0.size() == 0) {\n continue;\n }\n\n double dp_V0_D0 = 0;\n double coef = 1. / citiesBear0.size();\n if (d0 != 0) {\n double[] probV = new double[n];\n for (int b0 : citiesBear0) {\n int size = gr[b0].size();\n for (int b1 : gr[b0]) {\n probV[b1] += coef / size;\n }\n }\n\n\n double[] probD = new double[n];\n for (int v1 = 0; v1 < n; v1++) {\n int[] dist_v1 = dist[v1];\n// for (int b1 : citiesBear1) {\n for (int i = 0, imax = citiesBear1.size(); i < imax; i++) {\n int b1 = citiesBear1.get(i);\n int d1 = dist_v1[b1];\n probD[d1] = max(probD[d1], probV[b1]);\n }\n double dp_V0_D0_V1 = 0;\n// for (int b1 : citiesBear1) {\n for (int i = 0, imax = citiesBear1.size(); i < imax; i++) {\n int b1 = citiesBear1.get(i);\n int d1 = dist_v1[b1];\n dp_V0_D0_V1 += probD[d1];\n probD[d1] = 0;\n }\n dp_V0_D0 = max(dp_V0_D0, dp_V0_D0_V1);\n }\n }\n dp_V0_D0 = max(dp_V0_D0, coef);\n\n dp_V0 += ((double) citiesBear0.size() / n) * dp_V0_D0;\n }\n dp = max(dp, dp_V0);\n }\n out.printFormat(\"%.12f\", dp);\n out.printLine();\n }\n\n private double max(double a, double b) {\n return a < b ? b : a;\n }\n\n }\n\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n }\n\n static interface IntCollection extends IntStream {\n public int size();\n\n default public void add(int value) {\n throw new UnsupportedOperationException();\n }\n\n default public IntCollection addAll(IntStream values) {\n for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {\n add(it.value());\n }\n return this;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void printLine() {\n writer.println();\n }\n\n public void printFormat(String format, Object... objects) {\n writer.printf(format, objects);\n }\n\n public void close() {\n writer.close();\n }\n\n }\n\n static class IntArrayList extends IntAbstractStream implements IntList {\n private int size;\n private int[] data;\n\n public IntArrayList() {\n this(3);\n }\n\n public IntArrayList(int capacity) {\n data = new int[capacity];\n }\n\n public IntArrayList(IntCollection c) {\n this(c.size());\n addAll(c);\n }\n\n public IntArrayList(IntStream c) {\n this();\n if (c instanceof IntCollection) {\n ensureCapacity(((IntCollection) c).size());\n }\n addAll(c);\n }\n\n public IntArrayList(IntArrayList c) {\n size = c.size();\n data = c.data.clone();\n }\n\n public IntArrayList(int[] arr) {\n size = arr.length;\n data = arr.clone();\n }\n\n public int size() {\n return size;\n }\n\n public int get(int at) {\n if (at >= size) {\n throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size);\n }\n return data[at];\n }\n\n private void ensureCapacity(int capacity) {\n if (data.length >= capacity) {\n return;\n }\n capacity = Math.max(2 * data.length, capacity);\n data = Arrays.copyOf(data, capacity);\n }\n\n public void addAt(int index, int value) {\n ensureCapacity(size + 1);\n if (index > size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size) {\n System.arraycopy(data, index, data, index + 1, size - index);\n }\n data[index] = value;\n size++;\n }\n\n public void removeAt(int index) {\n if (index >= size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size - 1) {\n System.arraycopy(data, index + 1, data, index, size - index - 1);\n }\n size--;\n }\n\n }\n\n static interface IntReversableCollection extends IntCollection {\n }\n\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n\n public abstract void addAt(int index, int value);\n\n public abstract void removeAt(int index);\n\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n\n\n default public void add(int value) {\n addAt(size(), value);\n }\n\n default public void popLast() {\n removeAt(size() - 1);\n }\n\n }\n\n static class ArrayUtils {\n public static void fill(int[][] array, int value) {\n for (int[] row : array) {\n Arrays.fill(row, value);\n }\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n }\n\n static abstract class IntAbstractStream implements IntStream {\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04bae78690d72949cb491212ce38a1e6", "src_uid": "99b94d0c75fa6cd28091a9d71daf6cbf", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tfinal int TIMELIMIT = 6000;\n\n\tvoid solve() {\n\t\tlong START = System.currentTimeMillis();\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tfinal int[][] d = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(d[i], Integer.MAX_VALUE / 3);\n\t\t\td[i][i] = 0;\n\t\t}\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint fr = in.nextInt() - 1;\n\t\t\tint to = in.nextInt() - 1;\n\t\t\td[fr][to] = d[to][fr] = 1;\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\td[j][k] = Math.min(d[j][k], d[j][i] + d[i][k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tInteger[][] g = new Integer[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\tg[i][j] = j;\n\t\t\t}\n\t\t\tfinal int start = i;\n\t\t\tArrays.sort(g[i], new Comparator() {\n\n\t\t\t\t@Override\n\t\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\t\treturn Integer.compare(d[start][o1], d[start][o2]);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tdouble res = 0;\n\t\tdouble[] pr = new double[n];\n\t\tdouble p = 1. / n;\n\t\tint[] sz = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (d[i][j] == 1) {\n\t\t\t\t\tsz[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tO[] a = new O[n];\n\n\t\tfor (int start = 0; start < n; start++) {\n\t\t\tint val = 0;\n\t\t\tfor (int posi = 0; posi < n;) {\n\t\t\t\tArrays.fill(pr, 0);\n\t\t\t\tint posj = posi;\n\t\t\t\twhile (posj != n\n\t\t\t\t\t\t&& d[start][g[start][posi]] == d[start][g[start][posj]]) {\n\t\t\t\t\tposj++;\n\t\t\t\t}\n\t\t\t\tval += (posj - posi) * (posj - posi);\n\t\t\t\tposi = posj;\n\t\t\t}\n\t\t\ta[start] = new O(start, val);\n\t\t}\n\n\t\tArrays.sort(a);\n\n\t\tfor (O o : a) {\n\t\t\tif (System.currentTimeMillis() - START > TIMELIMIT) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint start = o.id;\n\t\t\tdouble cur = 0;\n\t\t\tfor (int posi = 0; posi < n;) {\n\t\t\t\tArrays.fill(pr, 0);\n\t\t\t\tint posj = posi;\n\t\t\t\twhile (posj != n\n\t\t\t\t\t\t&& d[start][g[start][posi]] == d[start][g[start][posj]]) {\n\t\t\t\t\tposj++;\n\t\t\t\t}\n\t\t\t\tif (cur + p * (n - posi) < res) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (posj - posi == 1) {\n\t\t\t\t\tcur += p;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int ii = posi; ii < posj; ii++) {\n\t\t\t\t\t\tint v = g[start][ii];\n\t\t\t\t\t\tdouble add = p / sz[v];\n\t\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\t\tif (d[v][j] == 1) {\n\t\t\t\t\t\t\t\tpr[j] += add;\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\tdouble tryThis = 0.0;\n\t\t\t\t\tfor (O o2 : a) {\n\t\t\t\t\t\tint second = o2.id;\n\t\t\t\t\t\tdouble more = p;\n\t\t\t\t\t\tdouble myAns = 0.0;\n\t\t\t\t\t\tfor (int tmpi = 0; tmpi < n;) {\n\t\t\t\t\t\t\tint tmpj = tmpi;\n\t\t\t\t\t\t\twhile (tmpj != n\n\t\t\t\t\t\t\t\t\t&& d[second][g[second][tmpi]] == d[second][g[second][tmpj]]) {\n\t\t\t\t\t\t\t\ttmpj++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdouble max = 0;\n\t\t\t\t\t\t\tfor (int jj = tmpi; jj < tmpj; jj++) {\n\t\t\t\t\t\t\t\tint u = g[second][jj];\n\t\t\t\t\t\t\t\tmax = Math.max(pr[u], max);\n\t\t\t\t\t\t\t\tmore -= pr[u];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tmyAns += max;\n\t\t\t\t\t\t\ttmpi = tmpj;\n\t\t\t\t\t\t\tif (myAns + more <= tryThis) {\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\ttryThis = Math.max(tryThis, myAns);\n\t\t\t\t\t}\n\t\t\t\t\tcur += tryThis;\n\t\t\t\t}\n\t\t\t\tposi = posj;\n\t\t\t}\n\t\t\tres = Math.max(res, cur);\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tclass O implements Comparable {\n\t\tint id, val;\n\n\t\tpublic O(int id, int val) {\n\t\t\tsuper();\n\t\t\tthis.id = id;\n\t\t\tthis.val = val;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(O o) {\n\t\t\treturn Integer.compare(val, o.val);\n\t\t}\n\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF().runIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e1d44b2edd6d69614171b3ea92a19a9d", "src_uid": "99b94d0c75fa6cd28091a9d71daf6cbf", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tfinal int TIMELIMIT = 6000;\n\n\tvoid solve() {\n\t\tlong START = System.currentTimeMillis();\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tfinal int[][] d = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(d[i], Integer.MAX_VALUE / 3);\n\t\t\td[i][i] = 0;\n\t\t}\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint fr = in.nextInt() - 1;\n\t\t\tint to = in.nextInt() - 1;\n\t\t\td[fr][to] = d[to][fr] = 1;\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\td[j][k] = Math.min(d[j][k], d[j][i] + d[i][k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tInteger[][] g = new Integer[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\tg[i][j] = j;\n\t\t\t}\n\t\t\tfinal int start = i;\n\t\t\tArrays.sort(g[i], new Comparator() {\n\n\t\t\t\t@Override\n\t\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\t\treturn Integer.compare(d[start][o1], d[start][o2]);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tdouble res = 0;\n\t\tdouble[] pr = new double[n];\n\t\tdouble p = 1. / n;\n\t\tint[] sz = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (d[i][j] == 1) {\n\t\t\t\t\tsz[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tO[] a = new O[n];\n\n\t\tfor (int start = 0; start < n; start++) {\n\t\t\tint val = 0;\n\t\t\tfor (int posi = 0; posi < n;) {\n\t\t\t\tArrays.fill(pr, 0);\n\t\t\t\tint posj = posi;\n\t\t\t\twhile (posj != n\n\t\t\t\t\t\t&& d[start][g[start][posi]] == d[start][g[start][posj]]) {\n\t\t\t\t\tposj++;\n\t\t\t\t}\n\t\t\t\tval += (posj - posi) * (posj - posi);\n\t\t\t\tposi = posj;\n\t\t\t}\n\t\t\ta[start] = new O(start, val);\n\t\t}\n\n\t\tArrays.sort(a);\n\n\t\tfor (O o : a) {\n\t\t\tif (System.currentTimeMillis() - START > TIMELIMIT) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint start = o.id;\n\t\t\tdouble cur = 0;\n\t\t\tfor (int posi = 0; posi < n;) {\n\t\t\t\tArrays.fill(pr, 0);\n\t\t\t\tint posj = posi;\n\t\t\t\twhile (posj != n\n\t\t\t\t\t\t&& d[start][g[start][posi]] == d[start][g[start][posj]]) {\n\t\t\t\t\tposj++;\n\t\t\t\t}\n\t\t\t\tif (cur + p * (n - posi) < res) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (posj - posi == 1) {\n\t\t\t\t\tcur += p;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int ii = posi; ii < posj; ii++) {\n\t\t\t\t\t\tint v = g[start][ii];\n\t\t\t\t\t\tdouble add = p / sz[v];\n\t\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\t\tif (d[v][j] == 1) {\n\t\t\t\t\t\t\t\tpr[j] += add;\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\tdouble tryThis = p;\n\t\t\t\t\tfor (O o2 : a) {\n\t\t\t\t\t\tint second = o2.id;\n\t\t\t\t\t\tdouble more = p * (posj - posi);\n\t\t\t\t\t\tdouble myAns = 0.0;\n\t\t\t\t\t\tfor (int tmpi = 0; tmpi < n;) {\n\t\t\t\t\t\t\tint tmpj = tmpi;\n\t\t\t\t\t\t\twhile (tmpj != n\n\t\t\t\t\t\t\t\t\t&& d[second][g[second][tmpi]] == d[second][g[second][tmpj]]) {\n\t\t\t\t\t\t\t\ttmpj++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdouble max = 0;\n\t\t\t\t\t\t\tfor (int jj = tmpi; jj < tmpj; jj++) {\n\t\t\t\t\t\t\t\tint u = g[second][jj];\n\t\t\t\t\t\t\t\tmax = Math.max(pr[u], max);\n\t\t\t\t\t\t\t\tmore -= pr[u];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tmyAns += max;\n\t\t\t\t\t\t\ttmpi = tmpj;\n\t\t\t\t\t\t\tif (myAns + more <= tryThis) {\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\ttryThis = Math.max(tryThis, myAns);\n\t\t\t\t\t}\n\t\t\t\t\tcur += tryThis;\n\t\t\t\t}\n\t\t\t\tposi = posj;\n\t\t\t}\n\t\t\tres = Math.max(res, cur);\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tclass O implements Comparable {\n\t\tint id, val;\n\n\t\tpublic O(int id, int val) {\n\t\t\tsuper();\n\t\t\tthis.id = id;\n\t\t\tthis.val = val;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(O o) {\n\t\t\treturn Integer.compare(val, o.val);\n\t\t}\n\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF().runIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c5dd4371bf87795109cea47f144e7340", "src_uid": "99b94d0c75fa6cd28091a9d71daf6cbf", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tfinal int TIMELIMIT = 6000;\n\n\tvoid solve() {\n\t\tlong START = System.currentTimeMillis();\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tfinal int[][] d = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(d[i], Integer.MAX_VALUE / 3);\n\t\t\td[i][i] = 0;\n\t\t}\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint fr = in.nextInt() - 1;\n\t\t\tint to = in.nextInt() - 1;\n\t\t\td[fr][to] = d[to][fr] = 1;\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\td[j][k] = Math.min(d[j][k], d[j][i] + d[i][k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tInteger[][] g = new Integer[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\tg[i][j] = j;\n\t\t\t}\n\t\t\tfinal int start = i;\n\t\t\tArrays.sort(g[i], new Comparator() {\n\n\t\t\t\t@Override\n\t\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\t\treturn Integer.compare(d[start][o1], d[start][o2]);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tdouble res = 0;\n\t\tdouble[] pr = new double[n];\n\t\tdouble p = 1. / n;\n\t\tint[] sz = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (d[i][j] == 1) {\n\t\t\t\t\tsz[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tO[] a = new O[n];\n\n\t\tfor (int start = 0; start < n; start++) {\n\t\t\tint val = 0;\n\t\t\tfor (int posi = 0; posi < n;) {\n\t\t\t\tArrays.fill(pr, 0);\n\t\t\t\tint posj = posi;\n\t\t\t\twhile (posj != n\n\t\t\t\t\t\t&& d[start][g[start][posi]] == d[start][g[start][posj]]) {\n\t\t\t\t\tposj++;\n\t\t\t\t}\n\t\t\t\tval += (posj - posi) * (posj - posi);\n\t\t\t\tposi = posj;\n\t\t\t}\n\t\t\ta[start] = new O(start, val);\n\t\t}\n\n\t\tArrays.sort(a);\n\n\t\tfor (O o : a) {\n\t\t\tif (System.currentTimeMillis() - START > TIMELIMIT) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint start = o.id;\n\t\t\tdouble cur = 0;\n\t\t\tfor (int posi = 0; posi < n;) {\n\t\t\t\tArrays.fill(pr, 0);\n\t\t\t\tint posj = posi;\n\t\t\t\twhile (posj != n\n\t\t\t\t\t\t&& d[start][g[start][posi]] == d[start][g[start][posj]]) {\n\t\t\t\t\tposj++;\n\t\t\t\t}\n\t\t\t\tif (cur + p * (n - posi) < res) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (posj - posi == 1) {\n\t\t\t\t\tcur += p;\n\t\t\t\t} else {\n\t\t\t\t\tfor (int ii = posi; ii < posj; ii++) {\n\t\t\t\t\t\tint v = g[start][ii];\n\t\t\t\t\t\tdouble add = p / sz[v];\n\t\t\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\t\t\tif (d[v][j] == 1) {\n\t\t\t\t\t\t\t\tpr[j] += add;\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\tdouble tryThis = p;\n\t\t\t\t\tfor (O o2 : a) {\n\t\t\t\t\t\tint second = o2.id;\n\t\t\t\t\t\tdouble more = p;\n\t\t\t\t\t\tdouble myAns = 0.0;\n\t\t\t\t\t\tfor (int tmpi = 0; tmpi < n;) {\n\t\t\t\t\t\t\tint tmpj = tmpi;\n\t\t\t\t\t\t\twhile (tmpj != n\n\t\t\t\t\t\t\t\t\t&& d[second][g[second][tmpi]] == d[second][g[second][tmpj]]) {\n\t\t\t\t\t\t\t\ttmpj++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdouble max = 0;\n\t\t\t\t\t\t\tfor (int jj = tmpi; jj < tmpj; jj++) {\n\t\t\t\t\t\t\t\tint u = g[second][jj];\n\t\t\t\t\t\t\t\tmax = Math.max(pr[u], max);\n\t\t\t\t\t\t\t\tmore -= pr[u];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tmyAns += max;\n\t\t\t\t\t\t\ttmpi = tmpj;\n\t\t\t\t\t\t\tif (myAns + more <= tryThis) {\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\ttryThis = Math.max(tryThis, myAns);\n\t\t\t\t\t}\n\t\t\t\t\tcur += tryThis;\n\t\t\t\t}\n\t\t\t\tposi = posj;\n\t\t\t}\n\t\t\tres = Math.max(res, cur);\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tclass O implements Comparable {\n\t\tint id, val;\n\n\t\tpublic O(int id, int val) {\n\t\t\tsuper();\n\t\t\tthis.id = id;\n\t\t\tthis.val = val;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(O o) {\n\t\t\treturn Integer.compare(val, o.val);\n\t\t}\n\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF().runIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "44d39c45523339db33d41e918d49987d", "src_uid": "99b94d0c75fa6cd28091a9d71daf6cbf", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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\tif (n >= BIG) {\n\t\t\tif (true) {\n//\t\tif (false) {\n\t\t\t\t// c full circles.\n\t\t\t\tfor (long c = 0; n * c <= k; c++) {\n\t\t\t\t\tlong l = -1;\n\t\t\t\t\tlong r = n + 1;\n\t\t\t\t\twhile (r - l > 1) {\n\t\t\t\t\t\tlong m = l + (r - l) / 2;\n\t\t\t\t\t\tif (canLB(n, k, d, c, m)) {\n\t\t\t\t\t\t\tl = m;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tr = m;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (l >= 0 && canUB(n, k, d, c, l)) {\n\t\t\t\t\t\tans = Math.max(ans, l);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// s sweet lovers.\n\t\t\t\tfor (long s = 0; s <= n; s++) {\n\t\t\t\t\tlong minC = 0;\n\t\t\t\t\tlong maxC = 0;\n\t\t\t\t\t{\n\t\t\t\t\t\tlong b = Math.min(d, n - s);\n\t\t\t\t\t\tlong a = d - b;\n\t\t\t\t\t\tlong p = k - a - d;\n\t\t\t\t\t\tif (a > 0) {\n\t\t\t\t\t\t\t++p;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (p < 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmaxC = p / (n + s);\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tlong a = Math.min(d, s);\n\t\t\t\t\t\tlong b = d - a;\n\t\t\t\t\t\tlong p = k - a - d;\n\t\t\t\t\t\tp += n + s - 1;\n\t\t\t\t\t\tif (p < 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tminC = p / (n + s);\n\t\t\t\t\t}\n\t\t\t\t\tif (minC <= maxC) {\n\t\t\t\t\t\tans = Math.max(ans, s);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\n\t\tprivate boolean canLB(long n, long k, long d, long c, long s) {\n\t\t\tlong minK = -1;\n\t\t\tlong b = Math.min(d, n - s);\n\t\t\tlong a = d - b;\n\t\t\tminK = (n + s) * c + d + a;\n\t\t\tif (a > 0 && minK > 0) {\n\t\t\t\t// Last \"a\" takes one.\n\t\t\t\t--minK;\n\t\t\t}\n\t\t\treturn k >= minK;\n\t\t}\n\n\t\tprivate boolean canUB(long n, long k, long d, long c, long s) {\n\t\t\tlong maxK = -1;\n\t\t\tlong a = Math.min(d, s);\n\t\t\tlong b = d - a;\n\t\t\tmaxK = (n + s) * c + d + a;\n\t\t\treturn k <= maxK;\n\t\t}\n\n\t\tprivate long dist(long l, long r, long n) {\n\t\t\twhile (r < l) {\n\t\t\t\tr += n;\n\t\t\t}\n\t\t\treturn r - l + 1;\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString rl = in.readLine();\n\t\t\t\t\tif (rl == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(rl);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6f98832c638dac9a1c90a99a19d0529a", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class CandiesForChildren {\n \n long INF = (long) 1e18;\n \n void solve() {\n long n = in.nextLong(), l = in.nextLong() - 1, r = in.nextLong() - 1, k = in.nextLong();\n \n if (r < l) r += n;\n long a = r - l + 1, b = n - a;\n \n long ans = -1;\n if (n <= Math.cbrt(k)) {\n for (long x = 0; x <= a; x++) {\n for (long y = 0; y <= b; y++) {\n long c = k - x - a;\n if (c >= 0 && c % (x + y + n) == 0) ans = Math.max(ans, x + y);\n if (c + 1 >= 0 && (c + 1) % (x + y + n) == 0 && x > 0) ans = Math.max(ans, x + y);\n }\n }\n } else {\n for (long t = 0; t <= k / n; t++) {\n long c = k - n * t - a;\n if (c >= 0) {\n if (t == 0) {\n if (c <= a) ans = Math.max(ans, c + b);\n } else {\n long x = c, y = -c;\n long kl = -INF, kr = INF;\n \n if (a - x >= 0) kr = Math.min(kr, (a - x) / t);\n else kr = Math.min(kr, -((x - a + t - 1) / t));\n if (x >= 0) kl = Math.max(kl, -x / t);\n else kl = Math.max(kl, (-x + t - 1) / t);\n \n if (y - b >= 0) kl = Math.max(kl, (y - b + t) / (t + 1));\n else kl = Math.max(kl, (y - b) / (t + 1));\n if (y >= 0) kr = Math.min(kr, y / (t + 1));\n else kr = Math.min(kr, -((-y + t) / (t + 1)));\n \n if (kl <= kr) ans = Math.max(ans, x + y - kl);\n }\n }\n c++;\n if (c >= 0) {\n if (t == 0) {\n if (c <= a) ans = Math.max(ans, c + b);\n } else {\n long x = c, y = -c;\n long kl = -INF, kr = INF;\n \n if (a - x >= 0) kr = Math.min(kr, (a - x) / t);\n else kr = Math.min(kr, -((x - a + t - 1) / t));\n if (x - 1 >= 0) kl = Math.max(kl, (1 - x) / t);\n else kl = Math.max(kl, (1 - x + t - 1) / t);\n \n if (y - b >= 0) kl = Math.max(kl, (y - b + t) / (t + 1));\n else kl = Math.max(kl, (y - b) / (t + 1));\n if (y >= 0) kr = Math.min(kr, y / (t + 1));\n else kr = Math.min(kr, -((-y + t) / (t + 1)));\n \n if (kl <= kr) ans = Math.max(ans, x + y - kl);\n }\n }\n }\n }\n out.println(ans);\n }\n \n long[] gcd(long a, long b) {\n if (b == 0) return new long[]{a, 1, 0};\n long[] r = gcd(b, a % b);\n return new long[]{r[0], r[2], r[1] - a / b * r[2]};\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 CandiesForChildren().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f835c8a64e065816e095573864e88a73", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class D {\n\t\n\tlong go1(long n, long s, long k) {\n\t\t\n\t\t// no overeating\n\t\tlong ans1 = -1;\n\t\tfor (long c2 = n; c2 >= 0; c2--) {\n\t\t\tlong full = n + c2;\n\t\t\t\n\t\t\tlong last = k % full;\n\t\t\tif (last == 0) {\n\t\t\t\tlast = full;\n\t\t\t}\n\t\t\t\n\t\t\tlong last2 = last - s;\n\t\t\tlong rest2 = c2 - last2;\n\t\t\t\n\t\t\tif (!(0 <= last2 && last2 <= s && 0 <= rest2 && rest2 <= n - s)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tans1 = c2;\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tlong ans2 = -1;\n\t\t// overeating!\n\t\tfor (long c2 = n; c2 > 0; c2--) {\n\t\t\tlong full = n + c2;\n\t\t\t\n\t\t\tlong last = (k + 1) % full;\n\t\t\tif (last == 0) {\n\t\t\t\tlast = full;\n\t\t\t}\n\t\t\t\n\t\t\tlong last2 = last - s;\n\t\t\tlong rest2 = c2 - last2;\n\t\t\t\n\t\t\tif (!(0 <= last2 && last2 <= s && 0 <= rest2 && rest2 <= n - s)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tif (last2 == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tans2 = c2;\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\treturn Math.max(ans1, ans2);\n\t}\n\t\n\tvoid submit() {\n\t\tlong n = nextLong();\n\t\tlong l = nextLong();\n\t\tlong r = nextLong();\n\t\tlong k = nextLong();\n\t\t\n\t\tlong s;\n\t\tif (l <= r) {\n\t\t\ts = r - l + 1;\n\t\t} else {\n\t\t\ts = r - l + 1 + n;\n\t\t}\n\t\t\n\t\tout.println(go1(n, s, k));\n\t\t\n//\t\tif (n <= C) {\n//\t\t\tout.println(go1(n, s, k));\n//\t\t} else {\n//\t\t\tout.println(go2(n, s, k));\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\tD() 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 = 10_000_000;\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\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "550647021c00b5f5ed885c0a78bfdf77", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class CandiesForChildren {\n \n long INF = (long) 1e18;\n \n void solve() {\n long n = in.nextLong(), l = in.nextLong() - 1, r = in.nextLong() - 1, k = in.nextLong();\n \n if (r < l) r += n;\n long a = r - l + 1, b = n - a;\n \n long ans = -1;\n if (n <= Math.cbrt(k)) {\n for (long x = 0; x <= a; x++) {\n for (long y = 0; y <= b; y++) {\n long c = k - x - a;\n if (c >= 0 && c % (x + y + n) == 0) ans = Math.max(ans, x + y);\n if (c + 1 >= 0 && (c + 1) % (x + y + n) == 0 && x > 0) ans = Math.max(ans, x + y);\n }\n }\n } else {\n for (long t = 0; t <= k / n; t++) {\n long c = k - n * t - a;\n if (c >= 0) {\n if (t == 0) {\n if (c <= a) ans = Math.max(ans, c + b);\n } else {\n long[] ret = gcd(t + 1, t);\n long g = ret[0], x = ret[1], y = ret[2];\n x *= c / g; y *= c / g;\n long kl = -INF, kr = INF;\n \n if (a - x >= 0) kr = Math.min(kr, (a - x) / t);\n else kr = Math.min(kr, -((x - a + t - 1) / t));\n if (x >= 0) kl = Math.max(kl, -x / t);\n else kl = Math.max(kl, (-x + t - 1) / t);\n \n if (y - b >= 0) kl = Math.max(kl, (y - b + t) / (t + 1));\n else kl = Math.max(kl, (y - b) / (t + 1));\n if (y >= 0) kr = Math.min(kr, y / (t + 1));\n else kr = Math.min(kr, -((-y + t) / (t + 1)));\n \n if (kl <= kr) ans = Math.max(ans, x + y - kl);\n }\n }\n c++;\n if (c >= 0) {\n if (t == 0) {\n if (c <= a) ans = Math.max(ans, c + b);\n } else {\n long[] ret = gcd(t + 1, t);\n long g = ret[0], x = ret[1], y = ret[2];\n x *= c / g; y *= c / g;\n long kl = -INF, kr = INF;\n \n if (a - x >= 0) kr = Math.min(kr, (a - x) / t);\n else kr = Math.min(kr, -((x - a + t - 1) / t));\n if (x - 1 >= 0) kl = Math.max(kl, (1 - x) / t);\n else kl = Math.max(kl, (1 - x + t - 1) / t);\n \n if (y - b >= 0) kl = Math.max(kl, (y - b + t) / (t + 1));\n else kl = Math.max(kl, (y - b) / (t + 1));\n if (y >= 0) kr = Math.min(kr, y / (t + 1));\n else kr = Math.min(kr, -((-y + t) / (t + 1)));\n \n if (kl <= kr) ans = Math.max(ans, x + y - kl);\n }\n }\n }\n }\n out.println(ans);\n }\n \n long[] gcd(long a, long b) {\n if (b == 0) return new long[]{a, 1, 0};\n long[] r = gcd(b, a % b);\n return new long[]{r[0], r[2], r[1] - a / b * r[2]};\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 CandiesForChildren().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "241562231d069232c274f6d4e6ec1206", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Div680 {\r\n ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n//////// /////////\r\n//////// /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOOOOO SSSSSSS EEEEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMMMM MMMMMM OOO OOO SSSS SSS EEEEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMM MMM MMMM OOO OOO SSSS SSS EEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMMMM MMMM OOO OOO SSSS EEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSSSSSS EEEEE /////////\r\n//////// HHHHHHHHHHHHHHHH EEEEEEEEEEE MMMM MMMM OOO OOO SSSSSS EEEEEEEEEEE /////////\r\n//////// HHHHHHHHHHHHHHHH EEEEEEEEEEE MMMM MMMM OOO OOO SSSSSSS EEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSSS EEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSS SSSS EEEEE /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOO OOO SSS SSSS EEEEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOOOOO SSSSSSS EEEEEEEEEEEEE /////////\r\n//////// /////////\r\n//////// /////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n static int n, mod, offset, dp[][][];\r\n\r\n static int dp(int done, int i, int diff) {\r\n\r\n if (i == n)\r\n return diff > 0 ? 1 : 0;\r\n\r\n if (dp[done][i][diff + offset] != -1)\r\n return dp[done][i][diff + offset];\r\n int rem = n - i;\r\n int ans = 0;\r\n for (int l = 0; l < rem; l++) {\r\n for (int r = done == 1 ? 0 : l; r < rem; r++) {\r\n ans += dp(done | (l < r ? 1 : 0), i + 1, diff + l - r);\r\n ans %= mod;\r\n }\r\n }\r\n return dp[done][i][diff + offset] = ans;\r\n }\r\n\r\n static long dp2(int i) {\r\n if (i == n - 1)\r\n return 0;\r\n long ans = (n - i) * 1l * dp2(i + 1);\r\n ans %= mod;\r\n for (int l = 0; l < n - i; l++) {\r\n for (int r = l + 1; r < n - i; r++) {\r\n ans += dp(1, i + 1, l - r);\r\n ans %= mod;\r\n }\r\n }\r\n return ans;\r\n }\r\n\r\n public static void main(String[] args) throws IOException {\r\n Scanner sc = new Scanner(System.in);\r\n PrintWriter pw = new PrintWriter(System.out);\r\n n = sc.nextInt();\r\n mod = sc.nextInt();\r\n offset = n * (n - 1);\r\n dp = new int[2][n][2 * offset + 1];\r\n\r\n for (int[][] x : dp)\r\n for (int[] y : x)\r\n Arrays.fill(y, -1);\r\n\r\n pw.println(dp2(0));\r\n pw.flush();\r\n }\r\n\r\n static long gcd(long a, long b) {\r\n if (a == 0)\r\n return b;\r\n return gcd(b % a, a);\r\n }\r\n\r\n static class Scanner {\r\n StringTokenizer st;\r\n BufferedReader br;\r\n\r\n public Scanner(FileReader r) {\r\n br = new BufferedReader(r);\r\n }\r\n\r\n public Scanner(InputStream s) {\r\n br = new BufferedReader(new InputStreamReader(s));\r\n }\r\n\r\n public String next() throws IOException {\r\n while (st == null || !st.hasMoreTokens())\r\n st = new StringTokenizer(br.readLine());\r\n return st.nextToken();\r\n }\r\n\r\n public int[] nextIntArr(int n) throws IOException {\r\n int[] a = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n return a;\r\n }\r\n\r\n public int nextInt() throws IOException {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public long nextLong() throws IOException {\r\n return Long.parseLong(next());\r\n }\r\n\r\n public String nextLine() throws IOException {\r\n return br.readLine();\r\n }\r\n\r\n public double nextDouble() throws IOException {\r\n String x = next();\r\n StringBuilder sb = new StringBuilder(\"0\");\r\n double res = 0, f = 1;\r\n boolean dec = false, neg = false;\r\n int start = 0;\r\n if (x.charAt(0) == '-') {\r\n neg = true;\r\n start++;\r\n }\r\n for (int i = start; i < x.length(); i++)\r\n if (x.charAt(i) == '.') {\r\n res = Long.parseLong(sb.toString());\r\n sb = new StringBuilder(\"0\");\r\n dec = true;\r\n } else {\r\n sb.append(x.charAt(i));\r\n if (dec)\r\n f *= 10;\r\n }\r\n res += Long.parseLong(sb.toString()) / f;\r\n return res * (neg ? -1 : 1);\r\n }\r\n\r\n public boolean ready() throws IOException {\r\n return br.ready();\r\n }\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4a9ee912b0fa6ba99e07da1fffbb81fa", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\nimport static java.lang.Integer.min;\r\nimport static java.lang.Integer.max;\r\n\r\npublic class e1542easy {\r\n public static void main(String[] args) {\r\n Scanner s = new Scanner(System.in);\r\n\r\n solve(s.nextInt(), s.nextInt());\r\n }\r\n\r\n\r\n public static void solve(int n, int mod) {\r\n ArrayList inversions = new ArrayList<>();\r\n inversions.add(new long[]{1});\r\n\r\n long last[];\r\n long next[];\r\n for (int i = 1; i < n; i++) {\r\n last = inversions.get(i - 1);\r\n next = new long[i * (i + 1) / 2 + 1];\r\n\r\n int e;\r\n for (int j = 0; j < next.length; j++) {\r\n e = 0;\r\n for (int k = min(j, i); k >= 0; k--) {\r\n if (j - k < last.length) {\r\n e += last[j - k];\r\n e = e % mod;\r\n }\r\n }\r\n next[j] = e;\r\n }\r\n\r\n inversions.add(next);\r\n }\r\n\r\n for (int i = 0; i < n; i++) {\r\n //System.out.println(Arrays.toString(inversions.get(i)));\r\n }\r\n\r\n\r\n long perms[] = new long[n];\r\n perms[0] = 0;\r\n\r\n long c;\r\n long inv[];\r\n long m;\r\n for (int i = 1; i < n; i++) {\r\n c = (perms[i - 1] * (i + 1)) % mod;\r\n\r\n inv = inversions.get(i - 1);\r\n for (int j = 0; j < inv.length; j++) {\r\n for (int k = j + 2; k < inv.length; k++) {\r\n m = min(k - j, i + 1);\r\n c = (c + ((inv[j] * inv[k]) % mod) * ((m - 1) * (2 * i - (m - 2)) / 2)) % mod;\r\n }\r\n }\r\n\r\n perms[i] = c;\r\n }\r\n\r\n //System.out.println(Arrays.toString(perms));\r\n System.out.println(perms[n - 1]);\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4a8a08327ab0285617de89b49e8a7524", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "\r\n\r\n\r\nimport javax.swing.*;\r\nimport java.lang.reflect.Array;\r\nimport java.text.DecimalFormat;\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\nimport java.util.stream.Stream;\r\n\r\n\r\n\r\n// Please name your class Main\r\npublic class Main {\r\n static FastScanner fs=new FastScanner();\r\n static class FastScanner {\r\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st=new StringTokenizer(\"\");\r\n public String next() {\r\n while (!st.hasMoreElements())\r\n try {\r\n st=new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return st.nextToken();\r\n }\r\n int Int() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long Long() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n String Str(){\r\n return next();\r\n }\r\n }\r\n\r\n\r\n public static void main (String[] args) throws java.lang.Exception {\r\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\r\n //reading /writing file\r\n //Scanner in=new Scanner(System.in);\r\n //Scanner in=new Scanner(new File(\"input.txt\"));\r\n //PrintWriter pr=new PrintWriter(\"output.txt\");\r\n\r\n\r\n int T=1;\r\n for(int t=0;t= 0; 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 long last[] = dp;\r\n\r\n //System.out.println(i+\" \"+Arrays.toString(dp));\r\n\r\n\r\n long ssum = 0;\r\n long total =0;\r\n for(int j = 2; j < dp.length; j++) { // j == inversions\r\n if(dp[j]==0)break;\r\n total += sums[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[j - 2];\r\n if(j - cnt - 1 >= 0) {\r\n ssum -= sums[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\r\n\r\n long cur[] = new long[dp.length];\r\n for(int j = 0; j < dp.length; j++) {\r\n cur[j] = get(sums, j, Math.max(0,j - I));\r\n cur[j] %= mod;\r\n }\r\n\r\n dp = cur;\r\n sums[0] = cur[0];\r\n for(int j = 1; j < cur.length; j++){\r\n sums[j] = sums[j - 1] + dp[j];\r\n sums[j] %= mod;\r\n if(sums[j] == 0){\r\n sums[j] += mod;\r\n }\r\n }\r\n I++;\r\n }\r\n out.println(res % mod);\r\n }\r\n\r\n public long get(long sum[], int i, int j){\r\n if(j == 0) return sum[i];\r\n return (sum[i] - sum[j - 1] + mod) % mod;\r\n }\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "99eea499e2e4c6abe5215ad12eca59db", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "\r\n\r\n\r\nimport javax.swing.*;\r\nimport java.lang.reflect.Array;\r\nimport java.text.DecimalFormat;\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\nimport java.util.stream.Stream;\r\n\r\n\r\n\r\n// Please name your class Main\r\npublic class Main {\r\n static FastScanner fs=new FastScanner();\r\n static class FastScanner {\r\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st=new StringTokenizer(\"\");\r\n public String next() {\r\n while (!st.hasMoreElements())\r\n try {\r\n st=new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return st.nextToken();\r\n }\r\n int Int() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long Long() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n String Str(){\r\n return next();\r\n }\r\n }\r\n\r\n\r\n public static void main (String[] args) throws java.lang.Exception {\r\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\r\n //reading /writing file\r\n //Scanner in=new Scanner(System.in);\r\n //Scanner in=new Scanner(new File(\"input.txt\"));\r\n //PrintWriter pr=new PrintWriter(\"output.txt\");\r\n\r\n\r\n int T=1;\r\n for(int t=0;t= 0; i--) {\r\n int cnt = n - i;\r\n int pre = n - cnt;\r\n long com = ((ncr[n][pre] + 0l) * fact[pre]) % mod;\r\n if(com == 0) com += mod;\r\n long sum = 0;\r\n int last[] = dp;\r\n\r\n //System.out.println(i+\" \"+Arrays.toString(dp));\r\n\r\n\r\n long ssum = 0;\r\n long total =0;\r\n for(int j = 2; j < dp.length; j++) { // j == inversions\r\n total += (sums[j - 2] + 0l) * (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[j - 2];\r\n if(j - cnt - 1 >= 0) {\r\n ssum -= sums[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\r\n\r\n int cur[] = new int[dp.length];\r\n for(int j = 0; j < dp.length; j++) {\r\n cur[j] = get(sums, j, Math.max(0,j - I));\r\n cur[j] %= mod;\r\n if(cur[j] == 0){\r\n cur[j] += mod;\r\n }\r\n }\r\n\r\n dp = cur;\r\n sums[0] = cur[0];\r\n for(int j = 1; j < cur.length; j++){\r\n sums[j] = sums[j - 1] + dp[j];\r\n sums[j] %= mod;\r\n if(sums[j] == 0){\r\n sums[j] += mod;\r\n }\r\n }\r\n I++;\r\n }\r\n out.println(res % mod);\r\n }\r\n\r\n public int get(int sum[], int i, int j){\r\n if(j == 0) return sum[i];\r\n return (sum[i] - sum[j - 1] + mod) % mod;\r\n }\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "71c5dcb2acfd951f7dbc2097f43c3fbd", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Map.Entry;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class Techno19_2F {\n\n\tstatic int MODE = -1;\n\n\tstatic final Comparator COMP_ARR = new Comparator() {\n\t\tpublic int compare(int[] a1, int[] a2) {\n\t\t\tif (MODE != -1 && (a1.length == 32 || a2.length == 32)) {\n\t\t\t\tif (a1.length == 32) {\n\t\t\t\t\tif (MODE < a2.length) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (MODE > a2.length) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (a1.length < MODE) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (a1.length > MODE) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (int i = 0; i < MODE; i++) {\n\t\t\t\t\tif (a1[i] < a2[i]) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (a1[i] > a2[i]) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\tif (a1.length < a2.length) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (a1.length > a2.length) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\n\t\t\t\tfor (int i = 0; i < a2.length; i++) {\n\t\t\t\t\tif (a1[i] < a2[i]) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (a1[i] > a2[i]) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t};\n\n\tstatic TreeMap index = new TreeMap<>(COMP_ARR);\n\tstatic int[][] states;\n\n\tstatic ArrayList start = new ArrayList<>();\n\n\tstatic int[] numD;\n\n\tstatic int[] pFact = new int[1_000_001];\n\n\tstatic TreeMap divCostInd = new TreeMap<>(COMP_ARR);\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tcGen = new int[23];\n\t\tnumD = new int[6000];\n\t\tstates = new int[6000][];\n\t\tgenAll(0, 23, 23, 1);\n\n\t\taList = new ArrayList[6000];\n\t\tfor (int i = 0; i < 6000; i++) {\n\t\t\taList[i] = new ArrayList<>();\n\t\t}\n\t\tfAList();\n\n\t\tdivCost = new int[400][301];\n\t\tfor (int[] a : divCost) {\n\t\t\tArrays.fill(a, Integer.MAX_VALUE / 2);\n\t\t}\n\t\tcost = new int[index.size()];\n\n\t\tArrays.fill(pFact, 1);\n\t\tfor (int i = 2; i <= 1_000_000; i++) {\n\t\t\tif (pFact[i] == 1) {\n\t\t\t\tfor (int m = i; m <= 1_000_000; m += i) {\n\t\t\t\t\tpFact[m] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n\t\tint nT = Integer.parseInt(reader.readLine());\n\n\t\twhile (nT-- > 0) {\n\t\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\t\tint a = Integer.parseInt(inputData.nextToken());\n\t\t\tint b = Integer.parseInt(inputData.nextToken());\n\n\t\t\tint[] aA = toArray(a);\n\t\t\tint[] bA = toArray(b);\n\n\t\t\tInteger aRes = divCostInd.get(aA);\n\t\t\tif (aRes == null) {\n\t\t\t\taRes = divCostInd.size();\n\t\t\t\tbfs(aA, divCostInd.size());\n\t\t\t\tdivCostInd.put(aA, divCostInd.size());\n\t\t\t}\n\t\t\tInteger bRes = divCostInd.get(bA);\n\t\t\tif (bRes == null) {\n\t\t\t\tbRes = divCostInd.size();\n\t\t\t\tbfs(bA, divCostInd.size());\n\t\t\t\tdivCostInd.put(bA, divCostInd.size());\n\t\t\t}\n\n\t\t\tint minA = Integer.MAX_VALUE / 4;\n\t\t\tfor (int nD = 1; nD <= 300; nD++) {\n\t\t\t\tminA = Math.min(minA, divCost[aRes][nD] + divCost[bRes][nD]);\n\t\t\t}\n\t\t\tprinter.println(minA);\n\t\t}\n\t\tprinter.close();\n\t}\n\n\tstatic int[] toArray(int a) {\n\t\tArrayList cnts = new ArrayList();\n\t\tint last = -1;\n\t\tint cCnt = 0;\n\n\t\twhile (a > 1) {\n\t\t\tint cPFact = pFact[a];\n\t\t\tif (cPFact == last) {\n\t\t\t\tcCnt++;\n\t\t\t} else {\n\t\t\t\tif (cCnt != 0) {\n\t\t\t\t\tcnts.add(cCnt);\n\t\t\t\t}\n\t\t\t\tlast = cPFact;\n\t\t\t\tcCnt = 1;\n\t\t\t}\n\t\t\ta /= pFact[a];\n\t\t}\n\t\tif (cCnt != 0) {\n\t\t\tcnts.add(cCnt);\n\t\t}\n\t\tCollections.sort(cnts, Comparator.reverseOrder());\n\t\tint[] res = new int[cnts.size()];\n\t\tfor (int i = 0; i < cnts.size(); i++) {\n\t\t\tres[i] = cnts.get(i);\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic int[] cost;\n\n\tstatic int[][] divCost;\n\n\tstatic void bfs(int[] sState, int searchI) {\n\t\tint sInd = index.get(sState);\n\t\tArrayDeque queue = new ArrayDeque<>();\n\n\t\tqueue.add(index.get(sState));\n\n\t\tArrays.fill(cost, -1);\n\t\tcost[sInd] = 0;\n\n\t\twhile (!queue.isEmpty()) {\n\t\t\tint cStInd = queue.remove();\n\t\t\tfor (int nStInd : aList[cStInd]) {\n\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\tqueue.add(nStInd);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (Entry cE : index.entrySet()) {\n\t\t\tint cNumD = numD[cE.getValue()];\n\t\t\tif (cNumD <= 300) {\n\t\t\t\tdivCost[searchI][cNumD] = Math.min(divCost[searchI][cNumD], cost[cE.getValue()]);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic ArrayList[] aList;\n\n\tstatic void fAList() {\n\t\tint[] cState = new int[32];\n\t\tfor (Entry cE : index.entrySet()) {\n\t\t\tint[] oState = cE.getKey();\n\t\t\tint cStInd = cE.getValue();\n\n\t\t\tint cLen = states[cStInd].length;\n\t\t\tfor (int i = 0; i < cLen; i++) {\n\t\t\t\tcState[i] = oState[i];\n\t\t\t}\n\t\t\tMODE = cLen;\n\n\t\t\tfor (int i = 0; i < cLen; i++) {\n\t\t\t\tif (i == 0 || cState[i - 1] > cState[i]) {\n\t\t\t\t\tcState[i]++;\n\t\t\t\t\tInteger nStInd = index.get(cState);\n\t\t\t\t\tcState[i]--;\n\n\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\taList[cStInd].add(nStInd);\n\t\t\t\t}\n\n\t\t\t\tif (i == cLen - 1 && cState[i] == 1) {\n\t\t\t\t\tMODE--;\n\t\t\t\t\tInteger nStInd = index.get(cState);\n\t\t\t\t\tMODE++;\n\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\taList[cStInd].add(nStInd);\n\t\t\t\t} else if (i == cLen - 1 || cState[i] > cState[i + 1]) {\n\t\t\t\t\tcState[i]--;\n\t\t\t\t\tInteger nStInd = index.get(cState);\n\t\t\t\t\tcState[i]++;\n\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\taList[cStInd].add(nStInd);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcState[cLen] = 1;\n\n\t\t\tMODE++;\n\t\t\tInteger nStInd = index.get(cState);\n\t\t\tMODE--;\n\t\t\tif (nStInd == null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\taList[cStInd].add(nStInd);\n\t\t}\n\t}\n\n\tstatic int[] cGen;\n\n\tstatic void genAll(int i, int max, int rem, int cProd) {\n\t\tnumD[index.size()] = cProd;\n\n\t\tint[] cKey = Arrays.copyOf(cGen, i);\n\t\tstates[index.size()] = cKey;\n\t\tindex.put(cKey, index.size());\n\n\t\tif (rem > 0) {\n\t\t\tfor (int nV = Math.min(max, rem); nV >= 1; nV--) {\n\t\t\t\tcGen[i] = nV;\n\t\t\t\tgenAll(i + 1, nV, rem - nV, cProd * (nV + 1));\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "afa8976e8acccb08ce3a6188068fdb85", "src_uid": "6115ee1ccf651b1dd8145bf755ea7ea9", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Map.Entry;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class Techno19_2F {\n\tstatic final Comparator COMP_ARR = new Comparator() {\n\t\tpublic int compare(int[] a1, int[] a2) {\n\t\t\tif (a1.length < a2.length) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (a1.length > a2.length) {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < a1.length; i++) {\n\t\t\t\tif (a1[i] < a2[i]) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (a1[i] > a2[i]) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t};\n\n\tstatic TreeMap index = new TreeMap<>(COMP_ARR);\n\tstatic ArrayList start = new ArrayList<>();\n\n\tstatic int[] numD;\n\n\tstatic int[] pFact = new int[1_000_001];\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tcGen = new int[23];\n\t\tnumD = new int[6000];\n\t\tgenAll(0, 23, 23, 1);\n\t\tgenStart(0, 20, 20, 1);\n\n\t\tdivCost = new int[start.size()][301];\n\t\tfor (int[] a : divCost) {\n\t\t\tArrays.fill(a, Integer.MAX_VALUE / 2);\n\t\t}\n\t\tcost = new int[index.size()];\n\n\t\tCollections.sort(start, COMP_ARR);\n\t\tfor (int i = 0; i < start.size(); i++) {\n\t\t\tbfs(start.get(i), i);\n\t\t}\n\n\t\tArrays.fill(pFact, 1);\n\t\tfor (int i = 2; i <= 1_000_000; i++) {\n\t\t\tif (pFact[i] == 1) {\n\t\t\t\tfor (int m = i; m <= 1_000_000; m += i) {\n\t\t\t\t\tpFact[m] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n\t\tint nT = Integer.parseInt(reader.readLine());\n\n\t\twhile (nT-- > 0) {\n\t\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\t\tint a = Integer.parseInt(inputData.nextToken());\n\t\t\tint b = Integer.parseInt(inputData.nextToken());\n\n\t\t\tint[] aA = toArray(a);\n\t\t\tint[] bA = toArray(b);\n\n\t\t\tint aSI = Collections.binarySearch(start, aA, COMP_ARR);\n\t\t\tint bSI = Collections.binarySearch(start, bA, COMP_ARR);\n\n\t\t\tint minA = Integer.MAX_VALUE / 4;\n\t\t\tfor (int nD = 1; nD <= 300; nD++) {\n\t\t\t\tminA = Math.min(minA, divCost[aSI][nD] + divCost[bSI][nD]);\n\t\t\t}\n\t\t\tprinter.println(minA);\n\t\t}\n\t\tprinter.close();\n\t}\n\n\tstatic int[] toArray(int a) {\n\t\tArrayList cnts = new ArrayList();\n\t\tint last = -1;\n\t\tint cCnt = 0;\n\n\t\twhile (a > 1) {\n\t\t\tint cPFact = pFact[a];\n\t\t\tif (cPFact == last) {\n\t\t\t\tcCnt++;\n\t\t\t} else {\n\t\t\t\tif (cCnt != 0) {\n\t\t\t\t\tcnts.add(cCnt);\n\t\t\t\t}\n\t\t\t\tlast = cPFact;\n\t\t\t\tcCnt = 1;\n\t\t\t}\n\t\t\ta /= pFact[a];\n\t\t}\n\t\tif (cCnt != 0) {\n\t\t\tcnts.add(cCnt);\n\t\t}\n\t\tCollections.sort(cnts, Comparator.reverseOrder());\n\t\tint[] res = new int[cnts.size()];\n\t\tfor (int i = 0; i < cnts.size(); i++) {\n\t\t\tres[i] = cnts.get(i);\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic int[] cost;\n\n\tstatic int[][] divCost;\n\n\tstatic void bfs(int[] sState, int searchI) {\n\t\tint sInd = index.get(sState);\n\t\tArrayDeque states = new ArrayDeque<>();\n\t\tArrayDeque stInds = new ArrayDeque<>();\n\n\t\tstates.add(sState);\n\t\tstInds.add(index.get(sState));\n\n\t\tArrays.fill(cost, -1);\n\t\tcost[sInd] = 0;\n\n\t\twhile (!states.isEmpty()) {\n\t\t\tint[] cState = states.remove();\n\t\t\tint cStInd = stInds.remove();\n\n\t\t\tfor (int i = 0; i < cState.length; i++) {\n\t\t\t\tif (i == 0 || cState[i - 1] > cState[i]) {\n\t\t\t\t\tint[] nState = Arrays.copyOf(cState, cState.length);\n\t\t\t\t\tnState[i]++;\n\n\t\t\t\t\tInteger nStInd = index.get(nState);\n\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\tstates.add(nState);\n\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (i == cState.length - 1) {\n\t\t\t\t\tif (cState[i] == 1) {\n\t\t\t\t\t\tint[] nState = Arrays.copyOf(cState, cState.length - 1);\n\t\t\t\t\t\tInteger nStInd = index.get(nState);\n\t\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\t\tstates.add(nState);\n\t\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tint[] nState = Arrays.copyOf(cState, cState.length);\n\t\t\t\t\t\tnState[i]--;\n\t\t\t\t\t\tInteger nStInd = index.get(nState);\n\t\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\t\tstates.add(nState);\n\t\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (cState[i] > cState[i + 1]) {\n\t\t\t\t\tint[] nState = Arrays.copyOf(cState, cState.length);\n\t\t\t\t\tnState[i]--;\n\t\t\t\t\tInteger nStInd = index.get(nState);\n\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\tstates.add(nState);\n\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] nState = Arrays.copyOf(cState, cState.length + 1);\n\t\t\tnState[cState.length]++;\n\n\t\t\tInteger nStInd = index.get(nState);\n\t\t\tif (nStInd == null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\tstates.add(nState);\n\t\t\t\tstInds.add(nStInd);\n\t\t\t}\n\t\t}\n\n\t\tfor (Entry cE : index.entrySet()) {\n\t\t\tint cNumD = numD[cE.getValue()];\n\t\t\tif (cNumD <= 300) {\n\t\t\t\tdivCost[searchI][cNumD] = Math.min(divCost[searchI][cNumD], cost[cE.getValue()]);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic int[] cGen;\n\n\tstatic void genAll(int i, int max, int rem, int cProd) {\n\t\tnumD[index.size()] = cProd;\n\t\tindex.put(Arrays.copyOf(cGen, i), index.size());\n\n\t\tif (rem > 0) {\n\t\t\tfor (int nV = Math.min(max, rem); nV >= 1; nV--) {\n\t\t\t\tcGen[i] = nV;\n\t\t\t\tgenAll(i + 1, nV, rem - nV, cProd * (nV + 1));\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void genStart(int i, int max, int rem, int cProd) {\n\t\tstart.add(Arrays.copyOf(cGen, i));\n\n\t\tif (i < 7) {\n\t\t\tfor (int nV = 1; nV <= Math.min(max, rem) && cProd * (nV + 1) <= 240; nV++) {\n\t\t\t\tcGen[i] = nV;\n\t\t\t\tgenStart(i + 1, nV, rem - nV, cProd * (nV + 1));\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "952be0bf08b6b745b3c861513bee4a24", "src_uid": "6115ee1ccf651b1dd8145bf755ea7ea9", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Map.Entry;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class Techno19_2F {\n\n\tstatic int MODE = -1;\n\n\tstatic final Comparator COMP_ARR = new Comparator() {\n\t\tpublic int compare(int[] a1, int[] a2) {\n\t\t\tif (MODE != -1 && (a1.length == 32 || a2.length == 32)) {\n\t\t\t\tif (a1.length == 32) {\n\t\t\t\t\tif (MODE < a2.length) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (MODE > a2.length) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (a1.length < MODE) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (a1.length > MODE) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (int i = 0; i < MODE; i++) {\n\t\t\t\t\tif (a1[i] < a2[i]) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (a1[i] > a2[i]) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\tif (a1.length < a2.length) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (a1.length > a2.length) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\n\t\t\t\tfor (int i = 0; i < a2.length; i++) {\n\t\t\t\t\tif (a1[i] < a2[i]) {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (a1[i] > a2[i]) {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t};\n\n\tstatic TreeMap index = new TreeMap<>(COMP_ARR);\n\tstatic int[][] states;\n\n\tstatic ArrayList start = new ArrayList<>();\n\n\tstatic int[] numD;\n\n\tstatic int[] pFact = new int[1_000_001];\n\n\tstatic TreeMap divCostInd = new TreeMap<>(COMP_ARR);\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tcGen = new int[23];\n\t\tnumD = new int[6000];\n\t\tstates = new int[6000][];\n\t\tgenAll(0, 23, 23, 1);\n\n\t\tdivCost = new int[400][301];\n\t\tfor (int[] a : divCost) {\n\t\t\tArrays.fill(a, Integer.MAX_VALUE / 2);\n\t\t}\n\t\tcost = new int[index.size()];\n\n\t\tArrays.fill(pFact, 1);\n\t\tfor (int i = 2; i <= 1_000_000; i++) {\n\t\t\tif (pFact[i] == 1) {\n\t\t\t\tfor (int m = i; m <= 1_000_000; m += i) {\n\t\t\t\t\tpFact[m] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n\t\tint nT = Integer.parseInt(reader.readLine());\n\n\t\twhile (nT-- > 0) {\n\t\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\t\tint a = Integer.parseInt(inputData.nextToken());\n\t\t\tint b = Integer.parseInt(inputData.nextToken());\n\n\t\t\tint[] aA = toArray(a);\n\t\t\tint[] bA = toArray(b);\n\n\t\t\tInteger aRes = divCostInd.get(aA);\n\t\t\tif (aRes == null) {\n\t\t\t\taRes = divCostInd.size();\n\t\t\t\tbfs(aA, divCostInd.size());\n\t\t\t\tdivCostInd.put(aA, divCostInd.size());\n\t\t\t}\n\t\t\tInteger bRes = divCostInd.get(bA);\n\t\t\tif (bRes == null) {\n\t\t\t\tbRes = divCostInd.size();\n\t\t\t\tbfs(bA, divCostInd.size());\n\t\t\t\tdivCostInd.put(bA, divCostInd.size());\n\t\t\t}\n\n\t\t\tint minA = Integer.MAX_VALUE / 4;\n\t\t\tfor (int nD = 1; nD <= 300; nD++) {\n\t\t\t\tminA = Math.min(minA, divCost[aRes][nD] + divCost[bRes][nD]);\n\t\t\t}\n\t\t\tprinter.println(minA);\n\t\t}\n\t\tprinter.close();\n\t}\n\n\tstatic int[] toArray(int a) {\n\t\tArrayList cnts = new ArrayList();\n\t\tint last = -1;\n\t\tint cCnt = 0;\n\n\t\twhile (a > 1) {\n\t\t\tint cPFact = pFact[a];\n\t\t\tif (cPFact == last) {\n\t\t\t\tcCnt++;\n\t\t\t} else {\n\t\t\t\tif (cCnt != 0) {\n\t\t\t\t\tcnts.add(cCnt);\n\t\t\t\t}\n\t\t\t\tlast = cPFact;\n\t\t\t\tcCnt = 1;\n\t\t\t}\n\t\t\ta /= pFact[a];\n\t\t}\n\t\tif (cCnt != 0) {\n\t\t\tcnts.add(cCnt);\n\t\t}\n\t\tCollections.sort(cnts, Comparator.reverseOrder());\n\t\tint[] res = new int[cnts.size()];\n\t\tfor (int i = 0; i < cnts.size(); i++) {\n\t\t\tres[i] = cnts.get(i);\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic int[] cost;\n\n\tstatic int[][] divCost;\n\n\tstatic void bfs(int[] sState, int searchI) {\n\t\tint sInd = index.get(sState);\n\t\tArrayDeque stInds = new ArrayDeque<>();\n\n\t\tstInds.add(index.get(sState));\n\n\t\tArrays.fill(cost, -1);\n\t\tcost[sInd] = 0;\n\n\t\tint[] cState = new int[32];\n\n\t\twhile (!stInds.isEmpty()) {\n\t\t\tint cStInd = stInds.remove();\n\t\t\tint cLen = states[cStInd].length;\n\t\t\tfor (int i = 0; i < cLen; i++) {\n\t\t\t\tcState[i] = states[cStInd][i];\n\t\t\t}\n\t\t\tMODE = cLen;\n\n\t\t\tfor (int i = 0; i < cLen; i++) {\n\t\t\t\tif (i == 0 || cState[i - 1] > cState[i]) {\n\t\t\t\t\tcState[i]++;\n\t\t\t\t\tInteger nStInd = index.get(cState);\n\t\t\t\t\tcState[i]--;\n\n\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (i == cLen - 1) {\n\t\t\t\t\tif (cState[i] == 1) {\n\t\t\t\t\t\tMODE--;\n\t\t\t\t\t\tInteger nStInd = index.get(cState);\n\t\t\t\t\t\tMODE++;\n\t\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcState[i]--;\n\t\t\t\t\t\tInteger nStInd = index.get(cState);\n\t\t\t\t\t\tcState[i]++;\n\t\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (cState[i] > cState[i + 1]) {\n\t\t\t\t\tcState[i]--;\n\t\t\t\t\tInteger nStInd = index.get(cState);\n\t\t\t\t\tcState[i]++;\n\t\t\t\t\tif (nStInd == null) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\t\t\tstInds.add(nStInd);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcState[cLen] = 1;\n\n\t\t\tMODE++;\n\t\t\tInteger nStInd = index.get(cState);\n\t\t\tMODE--;\n\t\t\tif (nStInd == null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (cost[nStInd] == -1) {\n\t\t\t\tcost[nStInd] = cost[cStInd] + 1;\n\t\t\t\tstInds.add(nStInd);\n\t\t\t}\n\t\t}\n\n\t\tfor (Entry cE : index.entrySet()) {\n\t\t\tint cNumD = numD[cE.getValue()];\n\t\t\tif (cNumD <= 300) {\n\t\t\t\tdivCost[searchI][cNumD] = Math.min(divCost[searchI][cNumD], cost[cE.getValue()]);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic int[] cGen;\n\n\tstatic void genAll(int i, int max, int rem, int cProd) {\n\t\tnumD[index.size()] = cProd;\n\n\t\tint[] cKey = Arrays.copyOf(cGen, i);\n\t\tstates[index.size()] = cKey;\n\t\tindex.put(cKey, index.size());\n\n\t\tif (rem > 0) {\n\t\t\tfor (int nV = Math.min(max, rem); nV >= 1; nV--) {\n\t\t\t\tcGen[i] = nV;\n\t\t\t\tgenAll(i + 1, nV, rem - nV, cProd * (nV + 1));\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5316221a046261f3f1547cd952c273ab", "src_uid": "6115ee1ccf651b1dd8145bf755ea7ea9", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ffao\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Parser in = new Parser(inputStream);\n 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 public static int generator (int p, int x) {\n int[] fact = new int[50];\n int cnt = 0;\n\n int phi = p-1, n = phi;\n for (int i=2; i*i<=n; ++i)\n if (n % i == 0) {\n fact[cnt++]=i;\n while (n % i == 0)\n n /= i;\n }\n if (n > 1)\n fact[cnt++]=n;\n\n int ret = -1;\n int temp = (x/p)*p;\n\n for (int res=2; res<=p; ++res) {\n boolean ok = true;\n for (int i=0; i x) t -= p;\n ret = Math.max(t, ret);\n }\n }\n return ret;\n }\n\n public void solve(int testNumber, Parser in, PrintWriter out) {\n int n = in.nextInt() + 1;\n int x = in.nextInt();\n\n if (n == 2) {\n if (x == 2) out.println(-1);\n else out.println(x-1);\n return;\n }\n\n if (!MathUtils.isPrime(n)) {\n out.println(-1);\n return;\n }\n\n int ans = generator(n, x);\n if (ans > 1 && ans < x) out.println(ans);\n else out.println(-1);\n }\n}\n\nclass MathUtils {\n\n public static long modpow(int b, int e, int m) {\n if (e == 0) return 1%m;\n else if (e == 1) return b%m;\n\n long temp = modpow(b, e/2, m);\n temp = (temp * temp) % m;\n if (e % 2 == 1) temp = (temp * b) % m;\n\n return temp;\n }\n\n public static boolean isPrime(int n) {\n for (int i = 2; i*i <= n; i++) {\n if (n % i == 0) return false;\n }\n return true;\n }\n\n }\n\nclass Parser\n{\n private BufferedReader din;\n private StringTokenizer tokenizer;\n\n public Parser(InputStream in)\n {\n din = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(din.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c16eb5c71ccfcd5dc885e674b109c485", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ffao\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Parser in = new Parser(inputStream);\n 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 public static int generator (int p, int x) {\n int[] fact = new int[50];\n int cnt = 0;\n \n int phi = p-1, n = phi;\n for (int i=2; i*i<=n; ++i)\n if (n % i == 0) {\n fact[cnt++]=i;\n while (n % i == 0)\n n /= i;\n }\n if (n > 1)\n fact[cnt++]=n;\n\n int ret = -1;\n int temp = (x/p)*p;\n\n for (int res=2; res<=p; ++res) {\n boolean ok = true;\n for (int i=0; i x) t -= p;\n ret = Math.max(t, ret);\n }\n }\n return ret;\n }\n\n public void solve(int testNumber, Parser in, PrintWriter out) {\n int n = in.nextInt() + 1;\n int x = in.nextInt();\n\n if (!MathUtils.isPrime(n)) {\n out.println(-1);\n return;\n }\n\n int ans = generator(n, x);\n if (ans > 1 && ans < x) out.println(ans);\n else out.println(-1);\n }\n}\n\nclass MathUtils {\n\n public static long modpow(int b, int e, int m) {\n if (e == 0) return 1%m;\n else if (e == 1) return b%m;\n\n long temp = modpow(b, e/2, m);\n temp = (temp * temp) % m;\n if (e % 2 == 1) temp = (temp * b) % m;\n\n return temp;\n }\n\n public static boolean isPrime(int n) {\n for (int i = 2; i*i <= n; i++) {\n if (n % i == 0) return false;\n }\n return true;\n }\n\n }\n\nclass Parser\n{\n private BufferedReader din;\n private StringTokenizer tokenizer;\n\n public Parser(InputStream in)\n {\n din = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(din.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de693e81c67cd39befe2287e5659cde7", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "package main;\n\nimport main.Parser;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\n\npublic class TaskD {\n public static int generator (int p, int x) {\n int[] fact = new int[50];\n int cnt = 0;\n\n int phi = p-1, n = phi;\n for (int i=2; i*i<=n; ++i)\n if (n % i == 0) {\n fact[cnt++]=i;\n while (n % i == 0)\n n /= i;\n }\n if (n > 1)\n fact[cnt++]=n;\n\n int lim = Math.max(x-p, 1);\n\n for (int res=x-1; res>=lim; --res) {\n boolean ok = true;\n for (int i=0; i 1 && ans < x) out.println(ans);\n else out.println(-1);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "12a80938fbd6fd1a6a16443b601c86b8", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "//package round183;\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 B2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tlong n = ni(), m = ni();\n\t\tlong x = ni(), y = ni();\n\t\tlong a = ni(), b = ni();\n\t\tlong g = gcd(a, b);\n\t\ta /= g; b /= g;\n\t\tlong r = Math.min(n/a, m/b);\n\t\ta *= r; b *= r;\n\t\t\n\t\tlong min = Long.MAX_VALUE;\n\t\tlong[] id = null;\n\t\t{\n\t\t\tlong x1 = 0, y1 = 0;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong x1 = 0, y1 = m-b;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong x1 = n-a, y1 = 0;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong x1 = n-a, y1 = m-b;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(long y1 = y-b/2-1;y1 <= y-b/2+1;y1++){\n\t\t\tlong x1 = 0;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(long y1 = y-b/2-1;y1 <= y-b/2+1;y1++){\n\t\t\tlong x1 = n-a;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(long x1 = x-a/2-1;x1 <= x-a/2+1;x1++){\n\t\t\tlong y1 = 0;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(long x1 = x-a/2-1;x1 <= x-a/2+1;x1++){\n\t\t\tlong y1 = m-b;\n\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(long x1 = x-a/2-1;x1 <= x-a/2+1;x1++){\n\t\t\tfor(long y1 = y-b/2-1;y1 <= y-b/2+1;y1++){\n\t\t\t\tif(x1<=x && x<=x1+a && y1<=y && y<=y1+b && x1 >= 0 && x1+a <= n && y1 >= 0 && y1+b <= m){\n\t\t\t\t\tlong d = (long)(2*x-(2*x1+a))*(2*x-(2*x1+a))+(2*y-(2*y1+b))*(2*y-(2*y1+b));\n\t\t\t\t\tlong[] nid = new long[]{x1, y1, x1+a, y1+b};\n\t\t\t\t\tif(d < min || (d == min && comp(id, nid))){\n\t\t\t\t\t\tmin = d; id = nid;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(\n\t\t\t\tid[0] + \" \" +\n\t\t\t\tid[1] + \" \" +\n\t\t\t\tid[2] + \" \" +\n\t\t\t\tid[3]\n\t\t\t\t);\n\t}\n\t\n\tboolean comp(long[] a, long[] b){\n\t\tif(a == null)return true;\n\t\tif(b[0] < a[0])return true;\n\t\tif(b[0] > a[0])return false;\n\t\tif(b[1] < a[1])return true;\n\t\treturn false;\n\t}\n\t\n\tpublic static long gcd(long a, long b) {\n\t\twhile (b > 0){\n\t\t\tlong 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 B2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "41b35198a25c73c243fdb627712a884e", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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 G2LuckyNumbersHardVersion solver = new G2LuckyNumbersHardVersion();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class G2LuckyNumbersHardVersion {\n Debug debug = new Debug(false);\n\n public void solve(int testNumber, FastInput in, PrintWriter out) {\n int k = in.readInt();\n long[] f = new long[6];\n in.populate(f);\n int limit = (int) 1e6;\n long[][] dp = new long[7][limit + 1];\n long inf = (long) 1e18;\n SequenceUtils.deepFill(dp, -inf);\n dp[0][0] = 0;\n LongMinQueue queue = new LongMinQueue(limit + 1, LongComparator.REVERSE_ORDER);\n\n for (int i = 1, base = 1; i <= 6; i++, base *= 10) {\n long profit = f[i - 1];\n int each = base * 3;\n int threshold = (k - 1) * 3 + 1;\n for (int j = 0; j < each; j++) {\n queue.reset();\n for (int t = j, x = 0; t <= limit; t += each, x++) {\n queue.addLast(dp[i - 1][t] - x * profit);\n if (threshold < queue.size()) {\n queue.removeFirst();\n }\n dp[i][t] = queue.min() + x * profit;\n }\n }\n\n for (int j = limit; j >= 0; j--) {\n for (int t = 0; t <= 9; t++) {\n if (j - t * base < 0) {\n continue;\n }\n long cand = dp[i][j - t * base];\n if (t % 3 == 0) {\n cand += t / 3 * profit;\n }\n dp[i][j] = Math.max(dp[i][j], cand);\n }\n }\n }\n\n debug.debug(\"dp\", dp);\n int q = in.readInt();\n for (int i = 0; i < q; i++) {\n int n = in.readInt();\n long ans = dp[6][n];\n out.println(ans);\n }\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 LongDequeImpl implements LongDeque {\n private long[] data;\n private int bpos;\n private int epos;\n private static final long[] EMPTY = new long[0];\n private int n;\n\n public LongDequeImpl(int cap) {\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new long[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 long[] newData = new long[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 LongIterator iterator() {\n return new LongIterator() {\n int index = bpos;\n\n\n public boolean hasNext() {\n return index != epos;\n }\n\n\n public long next() {\n long ans = data[index];\n index = LongDequeImpl.this.next(index);\n return ans;\n }\n };\n }\n\n public long removeFirst() {\n long ans = data[bpos];\n bpos = next(bpos);\n return ans;\n }\n\n public long removeLast() {\n long ans = data[last(epos)];\n epos = last(epos);\n return ans;\n }\n\n public void addLast(long x) {\n ensureMore();\n data[epos] = x;\n epos = next(epos);\n }\n\n public long peekFirst() {\n return data[bpos];\n }\n\n public long peekLast() {\n return data[last(epos)];\n }\n\n public void clear() {\n bpos = epos = 0;\n }\n\n private int last(int x) {\n return (x == 0 ? n : x) - 1;\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 (LongIterator iterator = iterator(); iterator.hasNext(); ) {\n builder.append(iterator.next()).append(' ');\n }\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 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 LongMinQueue {\n LongDequeImpl minQueue;\n LongDequeImpl data;\n LongComparator comparator;\n\n public LongMinQueue(int cap, LongComparator comparator) {\n minQueue = new LongDequeImpl(cap);\n data = new LongDequeImpl(cap);\n this.comparator = comparator;\n }\n\n public void reset() {\n minQueue.clear();\n data.clear();\n }\n\n public void addLast(long val) {\n data.addLast(val);\n while (!minQueue.isEmpty() && comparator.compare(minQueue.peekLast(), val) > 0) {\n minQueue.removeLast();\n }\n minQueue.addLast(val);\n }\n\n public long removeFirst() {\n long val = data.removeFirst();\n if (minQueue.peekFirst() == val) {\n minQueue.removeFirst();\n }\n return val;\n }\n\n public int size() {\n return data.size();\n }\n\n public long min() {\n return minQueue.peekFirst();\n }\n\n }\n\n static interface LongDeque extends LongStack {\n }\n\n static interface LongComparator {\n public static final LongComparator REVERSE_ORDER = (a, b) -> Long.compare(b, a);\n\n public int compare(long a, long b);\n\n }\n\n static class SequenceUtils {\n public static void deepFill(Object array, long val) {\n if (!array.getClass().isArray()) {\n throw new IllegalArgumentException();\n }\n if (array instanceof long[]) {\n long[] longArray = (long[]) array;\n Arrays.fill(longArray, val);\n } else {\n Object[] objArray = (Object[]) array;\n for (Object obj : objArray) {\n deepFill(obj, val);\n }\n }\n }\n\n }\n\n static interface LongStack {\n }\n\n static interface LongIterator {\n boolean hasNext();\n\n long next();\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "51226be657b9edfe16f58b82bcae60e8", "src_uid": "92bcbac3f167a44c235e99afc4de20d2", "difficulty": 2900.0} {"lang": "Java 11", "source_code": "//package raif;\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 G3 {\n\tInputStream is;\n\tPrintWriter out;\n//\tString INPUT = \"999999 1 2 3 4 5 6 1 999999\";\n\tString INPUT = \"\";\n\n\tvoid solve()\n\t{\n\t\tint K = ni();\n\t\tlong[] F = nal(6);\n\t\tlong I = Long.MIN_VALUE / 2;\n\t\tfor(int Q = ni();Q > 0;Q--){\n\t\t\tint n = ni();\n\t\t\tlong[] dp = {0L};\n\t\t\tfor(int i = 0;i < 6;i++, n /= 10){\n\t\t\t\tint dd = n % 10;\n\t\t\t\tlong[] ndp = new long[n/10+1];\n\t\t\t\tArrays.fill(ndp, I);\n\t\t\t\tSegmentTreeRMQL[] st = new SegmentTreeRMQL[3];\n\t\t\t\tfor(int j = 0;j < 3;j++){\n\t\t\t\t\tlong[] b = new long[dp.length/3+1];\n\t\t\t\t\tfor(int k = j;k < dp.length;k+=3){\n\t\t\t\t\t\tb[k/3] = -(dp[k] - F[i] * (k/3));\n\t\t\t\t\t}\n\t\t\t\t\tst[j] = new SegmentTreeRMQL(b);\n\t\t\t\t}\n\n\t\t\t\tfor(int c = 0;c < ndp.length;c++){\n\t\t\t\t\tint val = c*10 + dd;\n\t\t\t\t\t// val-t <= 9k\n\t\t\t\t\tfor(int rem = 0;rem < 3;rem++) {\n\t\t\t\t\t\tint inf = Math.max(val-9*(K-1), 0);\n\t\t\t\t\t\tint sup = Math.min(dp.length-1, val);\n\t\t\t\t\t\tinf = Math.max(0, (inf+3-rem)/3-1);\n\t\t\t\t\t\tsup = (sup+3-rem)/3-1;\n//\t\t\t\t\t\ttr(inf, sup+1, dp.length/3+1);\n\t\t\t\t\t\tlong v = -st[rem].min(inf, sup+1) + (val-rem)/3*F[i];\n\t\t\t\t\t\tndp[c] = Math.max(ndp[c], v);\n\t\t\t\t\t}\n\t\t\t\t\tfor(int t = Math.max(val-9*K, 0);t <= val-9*(K-1) && t < dp.length;t++){\n\t\t\t\t\t\tint m = val-t;\n\t\t\t\t\t\tint got = m/3;\n\t\t\t\t\t\tif(m % 3 != 0){\n\t\t\t\t\t\t\tgot = 3*(K-1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tndp[c] = Math.max(ndp[c], got*F[i] + dp[t]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdp = ndp;\n\t\t\t}\n\t\t\tout.println(dp[0]);\n\t\t}\n\t}\n\n\tpublic static class SegmentTreeRMQL {\n\t\tpublic final int M, H, N;\n\t\tpublic long[] vals;\n\t\tpublic static final long I = Long.MAX_VALUE/3;\n\n\t\tpublic SegmentTreeRMQL(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\tvals = new long[M];\n\t\t\tArrays.fill(vals, 0, M, I);\n\t\t}\n\n\t\tpublic SegmentTreeRMQL(long[] a)\n\t\t{\n\t\t\tthis(a.length);\n\t\t\tfor(int i = 0;i < N;i++){\n\t\t\t\tvals[H+i] = a[i];\n\t\t\t}\n\t\t\t//\t\tArrays.fill(vals, H+N, M, I);\n\t\t\tfor(int i = H-1;i >= 1;i--)propagate(i);\n\t\t}\n\n\t\tpublic void update(int pos, long x)\n\t\t{\n\t\t\tvals[H+pos] = x;\n\t\t\tfor(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);\n\t\t}\n\n\t\tprivate void propagate(int i)\n\t\t{\n\t\t\tvals[i] = Math.min(vals[2*i], vals[2*i+1]);\n\t\t}\n\n\t\tpublic long min(int l, int r){\n\t\t\tlong min = I;\n\t\t\tif(l >= r)return min;\n\t\t\tl += H; r += H;\n\t\t\tfor(;l < r;l>>>=1,r>>>=1){\n\t\t\t\tif((l&1) == 1)min = Math.min(min, vals[l++]);\n\t\t\t\tif((r&1) == 1)min = Math.min(min, vals[--r]);\n\t\t\t}\n\t\t\treturn min;\n\t\t}\n\n\t\tpublic int firstle(int l, long v) {\n\t\t\tif(l >= H)return -1;\n\t\t\tint cur = H+l;\n\t\t\twhile(true){\n\t\t\t\tif(vals[cur] <= v){\n\t\t\t\t\tif(cur >= H)return cur-H;\n\t\t\t\t\tcur = 2*cur;\n\t\t\t\t}else{\n\t\t\t\t\tcur++;\n\t\t\t\t\tif((cur&cur-1) == 0)return -1;\n\t\t\t\t\tif((cur&1)==0)cur>>>=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic int lastle(int l, long v) {\n\t\t\tif(l < 0)return -1;\n\t\t\tint cur = H+l;\n\t\t\twhile(true){\n\t\t\t\tif(vals[cur] <= v){\n\t\t\t\t\tif(cur >= H)return cur-H;\n\t\t\t\t\tcur = 2*cur + 1;\n\t\t\t\t}else{\n\t\t\t\t\tif((cur&cur-1) == 0)return -1;\n\t\t\t\t\tcur--;\n\t\t\t\t\tif((cur&1)==1)cur>>>=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new 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\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\n\tprivate long[] nal(int n)\n\t{\n\t\tlong[] a = new long[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\n\t\treturn a;\n\t}\n\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "22c82ba9621780f8aaeebc161f074982", "src_uid": "92bcbac3f167a44c235e99afc4de20d2", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tstatic int maxn=1000000;\n\tstatic long inf=(long)1e16;\n\tstatic long fill=(long)-1e18;\n\tstatic ArrayListweights;\n\tstatic ArrayListvals;\n\tstatic long[]memo;\n\t\n\tstatic int[]F;\n\tstatic long cost(int num) {\n\t\tint d=0;\n\t\tlong ans=0;\n\t\twhile(num>0) {\n\t\t\tint digit=num%10;\n\t\t\tnum/=10;\n\t\t\tif(digit==3 || digit==6 || digit==9) {\n\t\t\t\tans+=F[d]*(digit/3);\n\t\t\t}\n\t\t\td++;\n\t\t}\n\t\treturn ans;\n\t}\n\tstatic void main() throws Exception{\n\t\tint n=(sc.nextInt()-1)*3;\n\t\tF=sc.intArr(6);\n\t\tvals=new ArrayList();\n\t\tweights=new ArrayList();\n\t\tint ten=1;\n\t\tfor(int i=0;i<6;i++) {\n\t\t\tint curW=3*ten;long curV=F[i];\n\t\t\tint cur=1;\n\t\t\tint tmpn=n;\n\t\t\twhile(cur<=tmpn) {\n\t\t\t\tif(curW*1l*cur>maxn)break;\n\t\t\t\tweights.add(curW*cur);\n\t\t\t\tvals.add(curV*cur);\n\t\t\t\ttmpn-=cur;\n\t\t\t\tcur<<=1;\n\t\t\t}\n\t\t\tif(tmpn>0 && curW*1l*tmpn<=maxn) {\n\t\t\t\tweights.add(curW*tmpn);\n\t\t\t\tvals.add(curV*tmpn);\n\t\t\t}\n\t\t\tten*=10;\n\t\t}\n\t\tmemo=new long[maxn];\n\t\tfor(int i=1;i0)\n\t\t\tmain();\n\t\tpw.flush();\n\t}\n\tstatic PrintWriter pw;\n\tstatic MScanner sc;\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\t \n\t\tpublic MScanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n\t \n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int[] intArr(int n) throws IOException {\n\t int[]in=new int[n];for(int i=0;iweights;\n\tstatic ArrayListvals;\n\tstatic long[]memo;\n\t\n\tstatic int[]F;\n\tstatic long cost(int num) {\n\t\tint d=0;\n\t\tlong ans=0;\n\t\twhile(num>0) {\n\t\t\tint digit=num%10;\n\t\t\tnum/=10;\n\t\t\tif(digit==3 || digit==6 || digit==9) {\n\t\t\t\tans+=F[d]*(digit/3);\n\t\t\t}\n\t\t\td++;\n\t\t}\n\t\treturn ans;\n\t}\n\tstatic void main() throws Exception{\n\t\tint n=(sc.nextInt()-1)*3;\n\t\tF=sc.intArr(6);\n\t\tvals=new ArrayList();\n\t\tweights=new ArrayList();\n\t\tint ten=1;\n\t\tfor(int i=0;i<6;i++) {\n\t\t\tint curW=3*ten;long curV=F[i];\n\t\t\tint cur=1;\n\t\t\twhile(cur<=n) {\n\t\t\t\tif(curW*1l*cur>maxn)break;\n\t\t\t\tweights.add(curW*cur);\n\t\t\t\tvals.add(curV*cur);\n\t\t\t\tn-=cur;\n\t\t\t\tcur<<=1;\n\t\t\t}\n\t\t\tif(n>0 && curW*1l*n<=maxn) {\n\t\t\t\tweights.add(curW*n);\n\t\t\t\tvals.add(curV*n);\n\t\t\t}\n\t\t\tten*=10;\n\t\t}\n\t\tmemo=new long[maxn];\n\t\tfor(int i=1;i0)\n\t\t\tmain();\n\t\tpw.flush();\n\t}\n\tstatic PrintWriter pw;\n\tstatic MScanner sc;\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\t \n\t\tpublic MScanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n\t \n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int[] intArr(int n) throws IOException {\n\t int[]in=new int[n];for(int i=0;i pn = new ArrayList();\n\t\tfor (int i = 0; i < sNum; i++) {\n\t\t\tif (i == 0) {\n\t\t\t\tpnt[i][0] = new Point(0, 0);\n\t\t\t\tnum[i][0] = 1;\n\t\t\t\tpn.add(pnt[i][0]);\n\t\t\t} else {\n\t\t\t\tpnt[i][0] = pnt[i - 1][2];\n\t\t\t\tnum[i][0] = num[i - 1][2];\n\t\t\t}\n\t\t\tfor (int j = 0; j < m - 1; j++) {\n\t\t\t\tpnt[i][j + 1] = pnt[i][j].add(nextVect[j]);\n\t\t\t\tnum[i][j + 1] = ++cnt;\n\t\t\t\tpn.add(pnt[i][j + 1]);\n\t\t\t}\n\t\t}\n\t\tout.println(pn.size());\n\t\tfor (Point p : pn)\n\t\t\tout.println(p);\n\t\tfor (int i = 0; i < sNum; i++) { \n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif (j != 0)\n\t\t\t\t\tout.print(' ');\n\t\t\t\tout.print(num[i][j]);\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\tout.print(1);\n\t\tprint(0);\n\t\tout.println();\n\t}\n\t\n\tvoid print(int s) {\n\t\tif (s == sNum)\n\t\t\treturn;\n\t\tout.print(' ');\n\t\tout.print(num[s][2]);\n\t\tprint(s + 1);\n\t\tfor (int i = 4; i != 2; i = (i + 2) % 5) {\n\t\t\tout.print(' ');\n\t\t\tout.print(num[s][i]);\n\t\t}\n\t}\n\n\tdouble getLen() {\n\t\tdouble a = 10;\n\t\tdouble b = 10;\n\t\tdouble phi = toRadians(108);\n\t\treturn sqrt(a * a + b * b - 2 * a * b * cos(phi));\n\t}\n\n\t\n\tclass Point {\n\t\tdouble x, y;\n\n\t\tpublic Point(double x, double y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t\n\t\tpublic Point rotate(double phi) {\n\t\t\tdouble cos = cos(phi);\n\t\t\tdouble sin = sin(phi);\n\t\t\treturn new Point(x * cos - y * sin, x * sin + y * cos);\n\t\t}\n\t\t\n\t\tpublic Point add(Point v) {\n\t\t\treturn new Point(x + v.x, y + v.y);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"%.9f %.9f\", x, y);\n\t\t}\n\t\tdouble dist() {\n\t\t\treturn sqrt(x * x + y * y);\n\t\t}\n\t}\n\t\n\n\tvoid chk(boolean b) {\n\t\tif (b)\n\t\t\treturn;\n\t\tSystem.out.println(new Error().getStackTrace()[1]);\n\t\texit(999);\n\t}\n\tvoid deb(String fmt, Object... args) {\n\t\tSystem.out.printf(Locale.US, fmt + \"%n\", args);\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d975727e532ed589dafefb5b14ae95b4", "src_uid": "db263b866e93e3a97731e11102923902", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\t\n void solve() throws Exception {\n \tint n = sc.nextInt();\n \tint m = 5 + (n - 1) * 4;\n \tdouble[] x = new double[m];\n \tdouble[] y = new double[m];\n \tdouble ang72 = 72.0 * PI / 180.0;\n \tdouble ang18 = 18.0 * PI / 180.0;\n \tdouble ang36 = 36.0 * PI / 180.0;\n \tx[0] = -4000;\n \ty[0] = -4000;\n \tx[1] = x[0] + 10;\n \ty[1] = y[0];\n \tx[2] = x[1] + 10.0 * cos(ang72);\n \ty[2] = y[1] + 10.0 * sin(ang72);\n \tx[3] = x[2] - 10.0 * cos(ang36);\n \ty[3] = y[2] + 10.0 * sin(ang36);\n \tx[4] = x[0] - 10.0 * sin(ang18);\n \ty[4] = y[0] + 10.0 * cos(ang18);\n \tfor (int i = 5; i < m; i++) {\n \t\tx[i] = x[i - 4] + (x[3] - x[0]);\n \t\ty[i] = y[i - 4] + (y[3] - y[0]);\n \t}\n \tout.println(m);\n \tfor (int i = 0; i < m; i++) {\n \t\tout.format(\"%.12f %.12f%n\", x[i], y[i]);\n \t}\n \tfor (int i = 0; i < n; i++) {\n \t\tif (i == 0) {\n \t\t\tfor (int j = 0; j < 5; j++) {\n \t\t\t\tout.print((j + 1) + \" \");\n \t\t\t}\n \t\t} else {\n \t\t\tout.print((3 + 4 * (i - 1) + 1) + \" \");\n \t\t\tfor (int j = 0; j < 4; j++) {\n \t\t\t\tout.print((5 + 4 * (i - 1) + j + 1) + \" \");\n \t\t\t}\n \t\t}\n \t\tout.println();\n \t}\n \tout.print(\"1 4 \");\n \tint lst = 3;\n \tfor (int i = 7; i < m; i += 4) {\n \t\tout.print((i + 1) + \" \");\n \t\tlst = i;\n \t}\n \tfor (int i = n - 1; i > 0; --i) {\n \t\tout.print((lst - 2 + 1) + \" \");\n \t\tout.print((lst + 1 + 1) + \" \");\n \t\tout.print((lst - 1 + 1) + \" \");\n \t\tout.print((lst - 4 + 1) + \" \");\n \t\tlst -= 4;\n \t}\n \tout.println(\"2 5 3 1\");\n }\n \n BufferedReader in;\n PrintWriter out;\n FastScanner sc;\n \n final String INPUT_FILE = \"stdin\";\n final String OUTPUT_FILE = \"stdout\";\n \n static Throwable throwable;\n \n public static void main(String[] args) throws Throwable {\n Thread thread = new Thread(null, new Solution(), \"\", (1 << 26));\n thread.start();\n thread.join();\n thread.run();\n if (throwable != null)\n throw throwable;\n }\n \n \n public void run() {\n try {\n if (INPUT_FILE.equals(\"stdin\"))\n in = new BufferedReader(new InputStreamReader(System.in));\n else\n in = new BufferedReader(new FileReader(INPUT_FILE));\n if (OUTPUT_FILE.equals(\"stdout\"))\n out = new PrintWriter(System.out);\n else\n out = new PrintWriter(new FileWriter(OUTPUT_FILE));\n sc = new FastScanner(in);\n solve();\n } catch (Exception e) {\n throwable = e;\n } finally {\n out.close();\n }\n }\n}\n\nclass FastScanner {\n BufferedReader reader;\n StringTokenizer strTok;\n \n FastScanner(BufferedReader reader) {\n this.reader = reader;\n }\n \n public String nextToken() throws Exception {\n while (strTok == null || !strTok.hasMoreTokens())\n strTok = new StringTokenizer(reader.readLine());\n return strTok.nextToken();\n }\n \n public boolean EOF() throws Exception {\n \tif (strTok != null && strTok.hasMoreTokens()) {\n \t\treturn false;\n \t} else {\n \t\tString line = reader.readLine();\n \t\tif (line == null)\n \t\t\treturn true;\n \t\tstrTok = new StringTokenizer(line);\n \t\treturn false;\n \t}\n }\n \n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fad8ec3d2452529167b70d51b36bbdf5", "src_uid": "db263b866e93e3a97731e11102923902", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class d\n{\n static int N;\n static String d1 = \"13.090169943749474241\"; // 10 + 10sin18\n static String d2 = \"9.5105651629515357212\"; // 10cos18\n static String d3 = \"16.180339887498948482\"; // 10 + 20sin18\n static String d4 = \"15.388417685876267013\"; // 5 tan 72\n static double d, e, f, g;\n\n static ArrayList points = new ArrayList();\n static ArrayList pq1 = new ArrayList();\n static ArrayList pq2 = new ArrayList();\n\n static int go(double x, double y)\n {\n Pair next = new Pair(x, y);\n for (int i = 0; i < points.size(); i++)\n if (points.get(i).equals(next))\n return i;\n points.add(next);\n System.out.printf(\"%.15f %.15f\\n\", next.x, next.y);\n return points.size() - 1;\n }\n\n static void solve(double x, double y, int n)\n {\n if (n >= N)\n return;\n\n if (n % 2 == 0) // right-side up\n {\n int[] idx = new int[6];\n idx[0] = go(x, y);\n\n double next_x = x + d;\n double next_y = y - e;\n double cx = next_x;\n double cy = next_y;\n idx[1] = go(next_x, next_y);\n pq2.add(idx[1]);\n solve(cx, cy, n + 1);\n\n next_x -= 5.0;\n next_y += g;\n idx[2] = go(next_x, next_y);\n pq2.add(idx[2]);\n\n next_x -= 5.0;\n next_y -= g;\n idx[3] = go(next_x, next_y);\n pq2.add(idx[3]);\n\n next_x += d;\n next_y += e;\n idx[4] = go(next_x, next_y);\n pq2.add(idx[4]);\n\n next_x -= f;\n idx[5] = go(next_x, next_y);\n pq2.add(idx[5]);\n\n pq1.add(idx[0]);\n pq1.add(idx[3]);\n pq1.add(idx[1]);\n pq1.add(idx[4]);\n pq1.add(idx[2]);\n }\n else // upside-down\n {\n int[] idx = new int[6];\n idx[0] = go(x, y);\n\n double next_x = x + d;\n double next_y = y + e;\n double cx = next_x;\n double cy = next_y;\n idx[1] = go(next_x, next_y);\n pq2.add(idx[1]);\n solve(cx, cy, n + 1);\n\n next_x -= 5.0;\n next_y -= g;\n idx[2] = go(next_x, next_y);\n pq2.add(idx[2]);\n\n next_x -= 5.0;\n next_y += g;\n idx[3] = go(next_x, next_y);\n pq2.add(idx[3]);\n\n next_x += d;\n next_y -= e;\n idx[4] = go(next_x, next_y);\n pq2.add(idx[4]);\n\n next_x -= f;\n idx[5] = go(next_x, next_y);\n pq2.add(idx[5]);\n\n pq1.add(idx[0]);\n pq1.add(idx[3]);\n pq1.add(idx[1]);\n pq1.add(idx[4]);\n pq1.add(idx[2]); \n }\n }\n\n public static void main(String[] args) throws IOException\n {\n d = Double.parseDouble(d1);\n e = Double.parseDouble(d2);\n f = Double.parseDouble(d3);\n g = Double.parseDouble(d4);\n\n BufferedReader w = new BufferedReader(new InputStreamReader(System.in));\n N = Integer.parseInt(w.readLine());\n\n points.add(new Pair(-1.0e10, -1.0e10));\n\n System.out.println(2 + N * 3);\n solve(0.0, 0.0, 0);\n for (int i = 0; i < pq1.size(); i += 5)\n for (int j = i; j < i + 5; j++)\n {\n System.out.print(pq1.get(j));\n if (j == i + 4) System.out.print(\"\\n\");\n else System.out.print(\" \");\n }\n System.out.print(\"1\");\n for (int i = 0; i < pq2.size(); i++)\n System.out.print(\" \" + pq2.get(i));\n System.out.println();\n\n System.exit(0);\n }\n\n public static class Pair\n {\n double x, y;\n double epsilon = 1.0e-7;\n public Pair(double a, double b)\n {\n x = a;\n y = b;\n }\n\n public boolean equals(Pair other)\n {\n return Math.abs(other.x - x) + Math.abs(other.y - y) < epsilon;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4a1c1257e42d284f86a0d03e4aeea565", "src_uid": "db263b866e93e3a97731e11102923902", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class d\n{\n static int N;\n static String d1 = \"13.090169943749474241\"; // 10 + 10sin18\n static String d2 = \"9.5105651629515357212\"; // 10cos18\n static String d3 = \"16.180339887498948482\"; // 10 + 20sin18\n static String d4 = \"15.388417685876267013\"; // 5 tan 72\n static double d, e, f, g;\n\n static ArrayList points = new ArrayList();;\n\n static int go(double x, double y)\n {\n Pair next = new Pair(x, y);\n for (int i = 0; i < points.size(); i++)\n if (points.get(i).equals(next))\n return i;\n points.add(next);\n System.out.printf(\"%.15f %.15f\\n\", next.x, next.y);\n return points.size() - 1;\n }\n\n static void solve(double x, double y, int n, boolean print_out)\n {\n if (n >= N)\n return;\n\n if (n % 2 == 0) // right-side up\n {\n int[] idx = new int[6];\n idx[0] = go(x, y);\n\n double next_x = x + d;\n double next_y = y - e;\n double cx = next_x;\n double cy = next_y;\n idx[1] = go(next_x, next_y);\n\n next_x -= 5.0;\n next_y += g;\n idx[2] = go(next_x, next_y);\n\n next_x -= 5.0;\n next_y -= g;\n idx[3] = go(next_x, next_y);\n\n next_x += d;\n next_y += e;\n idx[4] = go(next_x, next_y);\n\n next_x -= f;\n idx[5] = go(next_x, next_y);\n\n if (print_out)\n {\n System.out.printf(\"%d %d %d %d %d\\n\", idx[0], idx[3], idx[1], idx[4], idx[2]);\n System.out.printf(\"%d %d %d %d %d %d\\n\", idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]);\n }\n\n solve(cx, cy, n + 1, print_out);\n }\n else // upside-down\n {\n int[] idx = new int[6];\n idx[0] = go(x, y);\n\n double next_x = x + d;\n double next_y = y + e;\n double cx = next_x;\n double cy = next_y;\n idx[1] = go(next_x, next_y);\n\n next_x -= 5.0;\n next_y -= g;\n idx[2] = go(next_x, next_y);\n\n next_x -= 5.0;\n next_y += g;\n idx[3] = go(next_x, next_y);\n\n next_x += d;\n next_y -= e;\n idx[4] = go(next_x, next_y);\n\n next_x -= f;\n idx[5] = go(next_x, next_y);\n\n if (print_out)\n {\n System.out.printf(\"%d %d %d %d %d\\n\", idx[0], idx[3], idx[1], idx[4], idx[2]);\n System.out.printf(\"%d %d %d %d %d %d\\n\", idx[0], idx[1], idx[2], idx[3], idx[4], idx[5])\n }\n\n solve(cx, cy, n + 1, print_out);\n }\n }\n\n public static void main(String[] args) throws IOException\n {\n d = Double.parseDouble(d1);\n e = Double.parseDouble(d2);\n f = Double.parseDouble(d3);\n g = Double.parseDouble(d4);\n\n BufferedReader w = new BufferedReader(new InputStreamReader(System.in));\n N = Integer.parseInt(w.readLine());\n\n points.add(new Pair(-1.0e10, -1.0e10));\n\n System.out.println(2 + N * 3);\n solve(0.0, 0.0, 0, false);\n solve(0.0, 0.0, 0, true);\n\n System.exit(0);\n }\n\n public static class Pair\n {\n double x, y;\n double epsilon = 1.0e-7;\n public Pair(double a, double b)\n {\n x = a;\n y = b;\n }\n\n public boolean equals(Pair other)\n {\n return Math.abs(other.x - x) + Math.abs(other.y - y) < epsilon;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dac10a5d95b2110b0bfdf4b4dcb566f1", "src_uid": "db263b866e93e3a97731e11102923902", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.awt.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.Queue;\n\n/*\n\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\tpw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\tbr = new BufferedReader(new InputStreamReader(System.in));\n\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n */\n\npublic class Main {\n\tprivate static BufferedReader br;\n\tprivate static StringTokenizer st;\n\tprivate static PrintWriter pw;\n\n\tstatic Set seen, win;\n\n\tstatic BigInteger n;\n\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint qq = 1;\n\t\t//int qq = Integer.MAX_VALUE;\n\t\t//int qq = readInt();\n\t\tfor(int casenum = 1; casenum <= qq; casenum++)\t{\n\t\t\tint a = readInt();\n\t\t\tint b = readInt();\n\t\t\tn = new BigInteger(nextToken());\n\t\t\tif(a == 1 && BigInteger.valueOf(a+1).pow(b).compareTo(n) >= 0)\t{\n\t\t\t\tpw.println(\"Missing\");\n\t\t\t}\n\t\t\telse\t{\n\t\t\t\tseen = new HashSet();\n\t\t\t\twin = new HashSet();\n\t\t\t\tpw.println(win(a,b) ? \"Masha\" : \"Stas\");\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n\n\tprivate static boolean win(int a, int b) {\n\t\tif(seen.add(new State(a,b)))\t{\n\t\t\tif(BigInteger.valueOf(a).pow(b).compareTo(n) >= 0)\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse if(b == 1 && BigInteger.valueOf(a+1).pow(b).compareTo(n) >= 0)\t{\n\t\t\t\tif(a%2 == n.intValue()%2)\t{\n\t\t\t\t\twin.add(new State(a,b));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!win(a+1,b) || !win(a,b+1))\t{\n\t\t\t\twin.add(new State(a,b));\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn win.contains(new State(a,b));\n\t}\n\n\tstatic class State\t{\n\t\tpublic int x,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\t@Override\n\t\tpublic int hashCode() {\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + x;\n\t\t\tresult = prime * result + y;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (this == obj)\n\t\t\t\treturn true;\n\t\t\tif (obj == null)\n\t\t\t\treturn false;\n\t\t\tif (getClass() != obj.getClass())\n\t\t\t\treturn false;\n\t\t\tState other = (State) obj;\n\t\t\tif (x != other.x)\n\t\t\t\treturn false;\n\t\t\tif (y != other.y)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t}\n\n\tprivate static long readLong() throws IOException\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextToken() throws IOException\t{\n\t\twhile(st == null || !st.hasMoreTokens())\t{\n\t\t\tif(!br.ready())\t{\n\t\t\t\tpw.close();\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b5694dd1b14e2490e672d822052c01e1", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n static int MOD = 1000000007;\n\n // After writing solution, quick scan for:\n // array out of bounds\n // special cases e.g. n=1?\n //\n // Big numbers arithmetic bugs:\n // int overflow\n // sorting, or taking max, after MOD\n void solve() throws IOException {\n int[] abn = ril(3);\n int a = abn[0];\n int b = abn[1];\n int n = abn[2];\n if (a == 1 && Math.pow(a+1, b) >= n) {\n pw.println(\"Missing\");\n return;\n }\n pw.println(dfs(a, b, n) ? \"Masha\" : \"Stas\");\n }\n\n Map> memo = new HashMap<>();\n boolean dfs(int a, int b, int n) {\n if (Math.pow(a, b) >= n) return true;\n if (memo.containsKey(a) && memo.get(a).containsKey(b)) return memo.get(a).get(b);\n if (!memo.containsKey(a)) memo.put(a, new HashMap<>());\n boolean move1 = dfs(a+1, b, n);\n if (!move1) {\n memo.get(a).put(b, Boolean.TRUE);\n return true;\n }\n boolean move2 = dfs(a, b+1, n);\n if (!move2) {\n memo.get(a).put(b, Boolean.TRUE);\n return true;\n }\n memo.get(a).put(b, Boolean.FALSE);\n return false;\n }\n\n // Template code below\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n\n public static void main(String[] args) throws IOException {\n Main m = new Main();\n m.solve();\n m.close();\n }\n\n void close() throws IOException {\n pw.flush();\n pw.close();\n br.close();\n }\n\n int ri() throws IOException {\n return Integer.parseInt(br.readLine().trim());\n }\n\n long rl() throws IOException {\n return Long.parseLong(br.readLine().trim());\n }\n\n int[] ril(int n) throws IOException {\n int[] nums = new int[n];\n int c = 0;\n for (int i = 0; i < n; i++) {\n int sign = 1;\n c = br.read();\n int x = 0;\n if (c == '-') {\n sign = -1;\n c = br.read();\n }\n while (c >= '0' && c <= '9') {\n x = x * 10 + c - '0';\n c = br.read();\n }\n nums[i] = x * sign;\n }\n while (c != '\\n' && c != -1) c = br.read();\n return nums;\n }\n\n long[] rll(int n) throws IOException {\n long[] nums = new long[n];\n int c = 0;\n for (int i = 0; i < n; i++) {\n int sign = 1;\n c = br.read();\n long x = 0;\n if (c == '-') {\n sign = -1;\n c = br.read();\n }\n while (c >= '0' && c <= '9') {\n x = x * 10 + c - '0';\n c = br.read();\n }\n nums[i] = x * sign;\n }\n while (c != '\\n' && c != -1) c = br.read();\n return nums;\n }\n\n int[] rkil() throws IOException {\n int sign = 1;\n int c = br.read();\n int x = 0;\n if (c == '-') {\n sign = -1;\n c = br.read();\n }\n while (c >= '0' && c <= '9') {\n x = x * 10 + c - '0';\n c = br.read();\n }\n return ril(x);\n }\n\n long[] rkll() throws IOException {\n int sign = 1;\n int c = br.read();\n int x = 0;\n if (c == '-') {\n sign = -1;\n c = br.read();\n }\n while (c >= '0' && c <= '9') {\n x = x * 10 + c - '0';\n c = br.read();\n }\n return rll(x);\n }\n\n char[] rs() throws IOException {\n return br.readLine().toCharArray();\n }\n\n void sort(int[] A) {\n Random r = new Random();\n for (int i = A.length-1; i > 0; i--) {\n int j = r.nextInt(i+1);\n int temp = A[i];\n A[i] = A[j];\n A[j] = temp;\n }\n Arrays.sort(A);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fa9b69f2510769c7c24e2a19d7aab2ee", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.awt.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.Queue;\n\n/*\n\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\tpw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\tbr = new BufferedReader(new InputStreamReader(System.in));\n\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n */\n\npublic class Main {\n\tprivate static BufferedReader br;\n\tprivate static StringTokenizer st;\n\tprivate static PrintWriter pw;\n\n\tstatic Set seen, win;\n\n\tstatic BigInteger n;\n\n\tstatic boolean draw;\n\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint qq = 1;\n\t\t//int qq = Integer.MAX_VALUE;\n\t\t//int qq = readInt();\n\t\tfor(int casenum = 1; casenum <= qq; casenum++)\t{\n\t\t\tint a = readInt();\n\t\t\tdraw = false;\n\t\t\tint b = readInt();\n\t\t\tn = new BigInteger(nextToken());\n\t\t\tif(a == 1 && BigInteger.valueOf(a+1).pow(b).compareTo(n) >= 0)\t{\n\t\t\t\tpw.println(\"Missing\");\n\t\t\t}\n\t\t\telse\t{\n\t\t\t\tseen = new HashSet();\n\t\t\t\twin = new HashSet();\n\t\t\t\tboolean ret = win(a,b,0);\n\t\t\t\tif(draw && !ret)\t{\n\t\t\t\t\tpw.println(\"Missing\");\n\t\t\t\t}\n\t\t\t\telse\t{\n\t\t\t\t\tpw.println(ret ? \"Masha\" : \"Stas\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n\n\tprivate static boolean win(int a, int b, int d) {\n\t\tif(seen.add(new State(a,b)))\t{\n\t\t\tif(BigInteger.valueOf(a).pow(b).compareTo(n) >= 0)\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse if(b == 1 && BigInteger.valueOf(a+1).pow(b).compareTo(n) >= 0)\t{\n\t\t\t\tif(a%2 == n.intValue()%2)\t{\n\t\t\t\t\twin.add(new State(a,b));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\telse\t{\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(a == 1 && BigInteger.valueOf(a+1).pow(b).compareTo(n) >= 0)\t{\t\n\t\t\t\tif(d%2 == 0)\t{\n\t\t\t\t\tdraw = true;\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\twin.add(new State(a,b));\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse if(!win(a,b+1,d+1) || !win(a+1,b,d+1))\t{\n\t\t\t\twin.add(new State(a,b));\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn win.contains(new State(a,b));\n\t}\n\n\tstatic class State\t{\n\t\tpublic int x,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\t@Override\n\t\tpublic int hashCode() {\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + x;\n\t\t\tresult = prime * result + y;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (this == obj)\n\t\t\t\treturn true;\n\t\t\tif (obj == null)\n\t\t\t\treturn false;\n\t\t\tif (getClass() != obj.getClass())\n\t\t\t\treturn false;\n\t\t\tState other = (State) obj;\n\t\t\tif (x != other.x)\n\t\t\t\treturn false;\n\t\t\tif (y != other.y)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t}\n\n\tprivate static long readLong() throws IOException\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextToken() throws IOException\t{\n\t\twhile(st == null || !st.hasMoreTokens())\t{\n\t\t\tif(!br.ready())\t{\n\t\t\t\tpw.close();\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "241d12d79ff15290f3b64327a33f0cc2", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "//package school1;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class E {\n\n\tstatic StreamTokenizer in =\n\t\tnew StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\n\tstatic int nextInt() throws IOException{\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t}\n\t\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tint a = nextInt(),\n\t\t\tb = nextInt(),\n\t\t\tn = nextInt();\n\t\t\n\t\tif (a==1 && Math.pow(2, b)>=n){\n\t\t\tout.println(\"Missing\");\n\t\t\tout.flush();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint B[] = new int[100];\n\t\tB[1] = n-1;\n\t\tint p = (int)Math.sqrt(n);\n\t\tB[2] = p;\n\t\tfor (int i=3; i<=30; i++)\n\t\t\tfor (int j=p; j>=2; j--)\n\t\t\t\tif (Math.pow(j, i) < n){\n\t\t\t\t\tB[i] = j;\n\t\t\t\t\tp = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\n\t\tfor (int i=b; i<=30; i++)\n\t\t\tif (B[i] >= a){\n\t\t\t\tif (i-b == B[i]-a){\n\t\t\t\t\tout.println(\"Stas\");\n\t\t\t\t\tout.flush();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (Math.abs((i-b)-(B[i]-a)) == 1){\n\t\t\t\t\tout.println(\"Masha\");\n\t\t\t\t\tout.flush();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "300ea5ed8762248280ce96b5be366e97", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\n\npublic class main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n\t\tSet S= new HashSet<> ();\n\t\tSet Q= new HashSet<> ();\n\t\tS.add(0) ;\n\t\tlong [] d= new long[105];\n\t\tfor (int i=1; i<=10; i++) { \n\t\t\tfor (int j:S) { \n\t\t\t\tQ.add(j+1);\n\t\t\t\tQ.add(j+5);\n\t\t\t\tQ.add(j+10);\n\t\t\t\tQ.add(j+50);\n\t\t\t}\n\t\t\tS= new HashSet (Q);\n\t\t\tQ.clear();\n\t\t\td[i]=S.size();\n\t\t}\n\t\tlong n=in.nextLong();\n\t\tif (n<=100) out.println(d[(int) n]);\n\t\telse{ \n\t\t\tout.println(d[100]+(n-100)*49);\n\t\t}\n\t\t\n\t\t\n out.close();\n }\n\n\t\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 long nextLong() {\n return Long.parseLong(next());\n }\n\t\tpublic int nextInt() {\n return Integer.parseInt(next());\n }\n\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3d955ad61cc9f73fb61905544fd41073", "src_uid": "75ec99318736a8a1b62a8d51efd95355", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author kessido\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n BRomanDigits solver = new BRomanDigits();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BRomanDigits {\n long easySolve(int i) {\n int[] dp = new int[]{0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341, 390, 439, 488, 537, 586, 635, 684, 733, 782, 831, 880, 929, 978, 1027, 1076, 1125, 1174};\n if (i < dp.length) {\n return dp[i];\n } else {\n long[] y = new long[]{782, 831, 880, 929};\n long[] x = new long[]{21, 22, 23, 24};\n return LagrangeInterpolation.interpolate(x, y, i);\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int i = in.NextInt();\n out.println(easySolve(i));\n }\n\n }\n\n static class LagrangeInterpolation {\n public static long interpolate(long[] x, long[] y, long xi) {\n double result = 0;\n final int n = x.length;\n for (int i = 0; i < n; i++) {\n double term = y[i];\n for (int j = 0; j < n; j++) {\n if (j != i)\n term = term * (double) (xi - x[j]) / (double) (x[i] - x[j]);\n }\n result += term;\n }\n return Math.round(result);\n }\n\n }\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine(), \" \\t\\n\\r\\f,\");\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int NextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b358aa28684ed021101bfe80f6f9ab7", "src_uid": "75ec99318736a8a1b62a8d51efd95355", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class B {\n\tpublic static void main(String[] args) throws IOException {\n\n\t\t/**/\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\t/*/\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(\"src/b.in\"))));\n\t\t/**/\n\t\t\n\t\tint n = sc.nextInt();\n\t\tint[] len = new int[85];\n\t\tlen[9] = 1;\n\t\tlen[18] = 2;\n\t\tlen[27] = 3;\n\t\tlen[36] = 4;\n\t\tlen[45] = 5;\n\t\tlen[54] = 6;\n\t\tlen[63] = 7;\n\t\tlen[72] = 8;\n\t\tlen[4] = 1;\n\t\tfor (int i = 4; i < 85; i++) {\n\t\t\tif (len[i-4] != 0) {\n\t\t\t\tif (len[i]==0||len[i-4]+10)\n\t\t\t\tlen[i] = 0;\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < 85; i++) {\n\t\t\tif (i>0&&len[i]==0)\n\t\t\t\tcontinue;\n\t\t\tint num = n-len[i];\n\t\t\tif (num>=0)\n\t\t\t\tans += num+1;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cf6425089e8a6630b6968ac78baba120", "src_uid": "75ec99318736a8a1b62a8d51efd95355", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "//package codeforces;\n\n/**\n * Created by sky on 2/7/18.\n * www.github.com/aakashjaiswal1\n * aakashjaiswal@hotmail.co.in\n * aakashjaiswal.in@gmail.com\n * people die if they are killed\n */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\n/**\n * Created by sky on 13/4/18.\n * www.github.com/aakashjaiswal1\n * aakashjaiswal@hotmail.co.in\n * aakashjaiswal.in@gmail.com\n * people die if they are killed\n */\n public class defaul {\n public static void main(String[] args) {\n in = new FastReader();\n int no=ni();\n int[] arr={0,4,10,20,35,56,83,116,155,198,244,292,341,390};\n if (no 1) {\n long mid = (high - low)/2 + low;\n //System.out.println(mid);\n if (works(mid)) {\n high = mid;\n } else {\n low = mid;\n }\n }\n return (works(low) ? low : high);\n }\n static private boolean works(long test){\n return true;\n }\n\n\n static void reverse(char[] arr ,int i,int j){\n if (i==j)\n return;\n while (i0){\n if ((pow&1)==1){\n result=result*no;\n }\n no=no*no;\n pow>>=1;\n }\n return result;\n }\n\n static long[] takeLongArrayInput(int no){\n long[] arr=new long[no];\n for (int i=0;i R)\n\t\t\tmax = R;\n\t\tpw.println(max-L);\n\t\tpw.close();\n\t}\n\tprivate static double calc() {\n\t\td = Math.sqrt((xx-s)*(xx-s)+yy*yy);\n\t\tsinalfa = yy / d;\n\t\tcosalfa = (xx-s) / d;\n\t\tq = sin[ii]*cosalfa+cos[ii]*sinalfa;\n\t\tif (q < 0)\n\t\t\treturn 1e9;\n\t\tr = d * sin[ii] / q;\n\t\treturn s+r;\n\t}\n\tprivate static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\tprivate static long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\tprivate static double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\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/*\n20 1 1 \n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n*/", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7fc9e8830dc3ce1aa1f2a6fbf009adf7", "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class D {\n\n static StringTokenizer st;\n static BufferedReader br;\n static PrintWriter pw;\n static double[]sin, cos;\n static double s;\n static int xx, yy, ii;\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n = nextInt();\n int L = nextInt();\n int R = nextInt();\n double[][]dp = new double[n][1 << n];\n for (int i = 0; i < n; i++) {\n Arrays.fill(dp[i], L);\n }\n int[]x = new int[n], y = new int[n];\n double[]a = new double[n];\n sin = new double[n];\n cos = new double[n];\n for (int i = 0; i < n; i++) {\n x[i] = nextInt();\n y[i] = nextInt();\n a[i] = nextDouble();\n sin[i] = Math.sin(Math.toRadians(a[i]));\n cos[i] = Math.cos(Math.toRadians(a[i]));\n }\n for (int i = 0; i < n; i++) {\n s = L;\n xx = x[i];\n yy = y[i];\n ii = i;\n dp[i][1 << i] = calc();\n }\n for (int mask = 0; mask < (1 << n); mask++) {\n for (int i = 0; i < n; i++) {\n if ((mask & (1 << i)) != 0) {\n for (int j = 0; j < n; j++) {\n if ((mask & (1 << j))==0) {\n s = dp[i][mask];\n xx = x[j];\n yy = y[j];\n ii = j;\n dp[j][mask | (1 << j)] = Math.max(dp[j][mask | (1 << j)], calc());\n }\n }\n }\n }\n }\n double max = L;\n for (int mask = 0; mask < (1 << n); mask++) {\n for (int i = 0; i < n; i++) {\n max = Math.max(max, dp[i][mask]);\n }\n }\n if (max > R)\n max = R;\n pw.println(max-L);\n pw.close();\n }\n private static double calc() {\n double d = Math.sqrt((xx-s)*(xx-s)+yy*yy);\n double sinalfa = yy / d;\n double cosalfa = (xx-s) / d;\n double q = sin[ii]*cosalfa+cos[ii]*sinalfa;\n if (q < 0)\n return 1e9;\n double r = d * sin[ii] / q;\n return s+r;\n }\n private static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n private static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n private static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n private static String next() throws IOException {\n while (st==null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n}\n/*\n20 1 1 \n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n*/", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4dd89c6ecf3c6bc7f243ae12a593223b", "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class Main {\n\n static double sin[] = new double[91];\n static double cos[] = new double[91];\n\n static {\n for(int i = 0; i <= 90; ++i){\n sin[i] = Math.sin(Math.PI * i / 180);\n cos[i] = Math.cos(Math.PI * i / 180);\n }\n }\n\n static class Point{\n final int x;\n final int y;\n final int a;\n\n Point(int x, int y, int a) {\n this.x = x;\n this.y = y;\n this.a = a;\n }\n }\n\n public static void main(String[] args) {\n System.out.print(new Main().solve());\n }\n\n int n;\n int l;\n int r;\n Point[] points;\n\n public double nextEdge(double start, int index){\n Point point = points[index];\n double x1 = start - point.x;\n double y1 = - point.y;\n\n double y2 = x1 * sin[point.a] + y1 * cos[point.a];\n if (y2 >= 0){\n return r;\n }\n double x2 = x1 * cos[point.a] - y1 * sin[point.a];\n return point.x - x2 * point.y / y2;\n }\n\n public double solve() {\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n l = sc.nextInt();\n r = sc.nextInt();\n points = new Point[n];\n for(int i = 0; i < n; ++i){\n points[i] = new Point(\n sc.nextInt(),\n sc.nextInt(),\n sc.nextInt());\n }\n double[] distance = new double[1000001];\n for(int i = 0; i <= 1000000; ++i){\n distance[i] = l - 1;\n }\n int[] visited = new int[1000001];\n int count = 0;\n visited[count++] = 0;\n distance[0] = l;\n int start = 0;\n\n for(int c = 1; c <= n; ++c){\n int end = count;\n for(int i = start; i < end; ++i){\n int value = visited[i];\n for(int b = 0; b < n; ++b){\n int mask = 1 << b;\n if((value & mask) != 0) continue;\n int cur = value | mask;\n if(distance[cur] == l - 1)visited[count++] = cur;\n double next = nextEdge(distance[value], b);\n if(next >= r) return r - l;\n if(next > distance[cur]) distance[cur] = next;\n }\n }\n start = end;\n }\n return distance[count - 1] - l;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "538f23ebd51d513f1a5e09954d600e29", "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(final String[] args) throws IOException {\n try(Scanner scan = new Scanner(System.in);\n PrintWriter print = new PrintWriter(System.out)) {\n final int n = scan.nextInt();\n final int l = scan.nextInt();\n final int r = scan.nextInt();\n final Floodlight[] floodlights = new Floodlight[n];\n for(int i = 0; i < n; ++i) {\n final int x = scan.nextInt();\n final int y = scan.nextInt();\n final double angle = scan.nextInt() / 180. * Math.PI;\n }\n print.println(calcMaxBeginSeg(l, r, floodlights));\n }\n }\n\n public static double calcMaxBeginSeg(final int left, final int right, final Floodlight[] floodlights) {\n if(right <= left) return 0.;\n final int n = floodlights.length;\n double maxLitRight[] = new double[1 << n];\n maxLitRight[0] = left;\n for(int mask = 1; mask < 1 << n; ++mask) {\n double result = left;\n for(int i = 0; i < n; ++i) {\n if(((mask >> i) & 1) == 1) {\n result = Math.max(result, extendLitSeg(maxLitRight[mask ^ (1 << i)], floodlights[i], right));\n }\n }\n maxLitRight[mask] = result;\n }\n return maxLitRight[(1 << n) - 1] - left;\n }\n\n private static double extendLitSeg(final double left, final Floodlight light, final double maxRight) {\n if(left >= maxRight) return left;\n if(light.y <= 0.) throw new RuntimeException(\"light.y must be > 0\");\n final double startAngle = Math.atan((left - light.getX()) / light.getY());\n final double endAngle = startAngle + light.angle;\n if(endAngle >= Math.PI / 2.) return maxRight;\n return Math.min(maxRight, light.getX() + light.getY() * Math.tan(endAngle));\n }\n\n public static class Floodlight {\n private final int x;\n private final int y;\n private final double angle;\n\n public Floodlight(final int x, final int y, final double angle) {\n this.x = x;\n this.y = y;\n this.angle = angle;\n }\n\n public int getX() {\n return x;\n }\n\n public int getY() {\n return y;\n }\n\n public double getAngle() {\n return angle;\n }\n }\n\n public static class NumberUtils {\n public static interface Factorizer {\n List factorize(int number);\n }\n\n /**\n * thread safe Factorizer\n */\n public static Factorizer createSmallNumberFactorizer(final int upperBound) {\n return new SmallNumberFactorizer(upperBound);\n }\n\n /**\n * thread safe\n */\n private static class SmallNumberFactorizer implements Factorizer {\n private int[] divisors;\n private final int upperBound;\n private boolean prepared = false;\n\n /**\n * lazy\n * time complexity O(n * log(n) * log(log(n))\n * memory complexity O(n)\n */\n public SmallNumberFactorizer(final int upperBound) {\n this.upperBound = upperBound;\n }\n\n private synchronized void prepare() {\n divisors = new int[upperBound];\n Arrays.fill(divisors, 0);\n for(int i = 2; i * i < upperBound; ++i) {\n if(divisors[i] == 0) {\n for(int j = i * i; j < upperBound; j += i) {\n if(divisors[j] == 0) {\n divisors[j] = i;\n }\n }\n }\n }\n prepared = true;\n }\n\n /**\n * complexity O(result)\n */\n public List factorize(int number) {\n synchronized (this) {\n if(!prepared) {\n prepare();\n }\n }\n final List result = CollectionFactory.createArrayList();\n if(number < 2) return result;\n if(number >= upperBound) throw new RuntimeException(\"number should be less than upper bound\");\n while(divisors[number] > 0) {\n result.add(divisors[number]);\n number /= divisors[number];\n }\n result.add(number);\n return result;\n }\n }\n }\n\n public static class CollectionFactory {\n public static List createArrayList() {\n return new ArrayList<>();\n }\n\n public static List createArrayList(final int capacity) {\n return new ArrayList<>(capacity);\n }\n }\n\n public static class CollectionUtils {\n public static List unique(final List list) {\n final List result = CollectionFactory.createArrayList();\n T p = null;\n for(T elem : list) {\n if(!elem.equals(p)) {\n result.add(elem);\n p = elem;\n }\n }\n return result;\n }\n\n public static> T max(final List list, final T lowerBound) {\n T result = lowerBound;\n for(T elem : list) {\n if(elem.compareTo(result) > 0) {\n result = elem;\n }\n }\n return result;\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ed205dc82a52777c9eecacecacbba78d", "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a", "difficulty": 2200.0} {"lang": "Java 11", "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[] 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 }\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 {\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b83d01b4d424e728e6a2a7cf6c94833", "src_uid": "98ded03cdd1870500667f0069d6a84b1", "difficulty": 2100.0} {"lang": "Java 8", "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 B1_Baltic_2020_Day2 {\n public static long MOD = 1000000007;\n static ArrayList[] store;\n static int result = 0;\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 n = in.nextInt();\n ArrayList[] map = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n map[i] = new ArrayList<>();\n }\n\n for (int i = 0; i < n - 1; i++) {\n int u = in.nextInt() - 1;\n int v = in.nextInt() - 1;\n map[u].add(v);\n map[v].add(u);\n }\n if (n == 2) {\n out.println(2);\n out.println(2 + \" \" + 1);\n } else {\n store = new ArrayList[n];\n int[] re = new int[n];\n int v = cal(0, 0, re, map);\n if (v != -1) {\n for (int index : map[v]) {\n result += 2;\n store[index].add(v);\n int last = index;\n for (int i : store[index]) {\n re[i] = last;\n last = i;\n }\n re[index] = last;\n break;\n }\n }\n out.println(result);\n for (int i : re) {\n out.print((i + 1) + \" \");\n }\n }\n\n out.close();\n }\n\n static int cal(int index, int pa, int[] re, ArrayList[] map) {\n store[index] = new ArrayList<>();\n for (int i : map[index]) {\n if (i == pa) {\n continue;\n }\n int v = cal(i, index, re, map);\n if (v != -1) {\n store[index].add(v);\n }\n }\n if (store[index].isEmpty()) {\n return index;\n } else {\n result += 2 * (1 + store[index].size()) - 2;\n int last = index;\n for (int i : store[index]) {\n re[i] = last;\n last = i;\n }\n re[index] = last;\n return -1;\n }\n }\n\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "51a5eee98b4381dc5595aeb0157bcc62", "src_uid": "98ded03cdd1870500667f0069d6a84b1", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.Closeable;\nimport java.io.DataInputStream;\nimport java.io.Flushable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\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\tFastReader in = new FastReader(inputStream);\n\t\t\tOutput out = new Output(outputStream);\n\t\t\tB1VillageMinimum solver = new B1VillageMinimum();\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 B1VillageMinimum {\n\t\tstatic B1VillageMinimum.Node[] nodes;\n\t\tstatic ArrayList[] graph;\n\t\tstatic ArrayDeque leaves;\n\n\t\tpublic B1VillageMinimum() {\n\t\t}\n\n\t\tpublic void solve(int kase, InputReader in, Output pw) {\n\t\t\tint n = in.nextInt();\n\t\t\tgraph = in.nextUndirectedGraph(n, n-1);\n\t\t\tnodes = new B1VillageMinimum.Node[n];\n\t\t\tleaves = new ArrayDeque<>(n);\n\t\t\tfor(int i = 0; i children;\n\t\t\tfinal int ind;\n\t\t\tint value;\n\t\t\tint childcnt;\n\t\t\tboolean visited;\n\t\t\tboolean processed;\n\n\t\t\tpublic Node(int ind) {\n\t\t\t\tthis.ind = value = ind;\n\t\t\t\tparent = null;\n\t\t\t\tchildcnt = 0;\n\t\t\t\tchildren = new ArrayList<>();\n\t\t\t\tvisited = processed = false;\n\t\t\t}\n\n\t\t\tpublic void dfs() {\n\t\t\t\tvisited = true;\n\t\t\t\tfor(int i: graph[ind]) {\n\t\t\t\t\tB1VillageMinimum.Node n = nodes[i];\n\t\t\t\t\tif(!n.visited) {\n\t\t\t\t\t\tn.parent = this;\n\t\t\t\t\t\tn.dfs();\n\t\t\t\t\t\tchildcnt++;\n\t\t\t\t\t\tchildren.add(n);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(childcnt==0) {\n\t\t\t\t\tleaves.addLast(ind);\n\t\t\t\t}\n\t\t\t}\n\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 print(int i) {\n\t\t\tprint(String.valueOf(i));\n\t\t}\n\n\t\tpublic void print(String s) {\n\t\t\tsb.append(s);\n\t\t\tif(autoFlush) {\n\t\t\t\tflush();\n\t\t\t}else if(sb.length()>BUFFER_SIZE >> 1) {\n\t\t\t\tflushToBuffer();\n\t\t\t}\n\t\t}\n\n\t\tpublic void println(long l) {\n\t\t\tprintln(String.valueOf(l));\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) {\n\t\t\t\tflush();\n\t\t\t}else if(sb.length()>BUFFER_SIZE >> 1) {\n\t\t\t\tflushToBuffer();\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 println(int[] arr) {\n\t\t\tfor(int i = 0; i String ts(T t) {\n\t\t\t\tif(t==null) {\n\t\t\t\t\treturn \"null\";\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn ts((Iterable) t);\n\t\t\t\t}catch(ClassCastException e) {\n\t\t\t\t\tif(t instanceof int[]) {\n\t\t\t\t\t\tString s = Arrays.toString((int[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof long[]) {\n\t\t\t\t\t\tString s = Arrays.toString((long[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof char[]) {\n\t\t\t\t\t\tString s = Arrays.toString((char[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof double[]) {\n\t\t\t\t\t\tString s = Arrays.toString((double[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}else if(t instanceof boolean[]) {\n\t\t\t\t\t\tString s = Arrays.toString((boolean[]) t);\n\t\t\t\t\t\treturn \"{\"+s.substring(1, s.length()-1)+\"}\";\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn ts((Object[]) t);\n\t\t\t\t\t}catch(ClassCastException e1) {\n\t\t\t\t\t\treturn t.toString();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprivate static String ts(T[] arr) {\n\t\t\t\tStringBuilder ret = new StringBuilder();\n\t\t\t\tret.append(\"{\");\n\t\t\t\tboolean first = true;\n\t\t\t\tfor(T t: arr) {\n\t\t\t\t\tif(!first) {\n\t\t\t\t\t\tret.append(\", \");\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t\tret.append(ts(t));\n\t\t\t\t}\n\t\t\t\tret.append(\"}\");\n\t\t\t\treturn ret.toString();\n\t\t\t}\n\n\t\t\tprivate static String ts(Iterable iter) {\n\t\t\t\tStringBuilder ret = new StringBuilder();\n\t\t\t\tret.append(\"{\");\n\t\t\t\tboolean first = true;\n\t\t\t\tfor(T t: iter) {\n\t\t\t\t\tif(!first) {\n\t\t\t\t\t\tret.append(\", \");\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t\tret.append(ts(t));\n\t\t\t\t}\n\t\t\t\tret.append(\"}\");\n\t\t\t\treturn ret.toString();\n\t\t\t}\n\n\t\t\tpublic static void dbg(Object... o) {\n\t\t\t\tif(LOCAL) {\n\t\t\t\t\tSystem.err.print(\"Line #\"+Thread.currentThread().getStackTrace()[2].getLineNumber()+\": [\");\n\t\t\t\t\tfor(int i = 0; i='0'&&c<='9');\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\tprivate boolean isDigit(byte b) {\n\t\t\treturn b>='0'&&b<='9';\n\t\t}\n\n\t\tprivate byte skipToDigit() {\n\t\t\tbyte ret;\n\t\t\twhile(!isDigit(ret = read())&&ret!='-') ;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() {\n\t\t\ttry {\n\t\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\t}catch(IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif(bytesRead==-1) {\n\t\t\t\tbuffer[0] = -1;\n\t\t\t}\n\t\t}\n\n\t\tprivate byte read() {\n\t\t\tif(bytesRead==-1) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}else if(bufferPointer==bytesRead) {\n\t\t\t\tfillBuffer();\n\t\t\t}\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t}\n\n\tstatic interface InputReader {\n\t\tint nextInt();\n\n\t\tdefault ArrayList[] nextUndirectedGraph(int n, int m) {\n\t\t\tArrayList[] ret = new ArrayList[n];\n\t\t\tfor(int i = 0; i();\n\t\t\t}\n\t\t\tfor(int i = 0; i> g = rg(n, n - 1);\n Map> comps = new HashMap<>();\n dfs(g, 0, -1, new int[n], comps);\n prln(2 * (n - comps.keySet().size()));\n int[] ans = new int[n];\n for (int k : comps.keySet()) {\n List comp = comps.get(k), cycle = cycle(comp);\n int sz = comp.size();\n for (int i = 0; i < sz; ++i) {\n ans[comp.get(i)] = cycle.get(i) + 1;\n }\n }\n prln(ans);\n close();\n }\n\n static List cycle(List to_cycle) {\n int n = to_cycle.size();\n List ans = new ArrayList<>();\n for (int i = 0; i < n; ++i) {\n ans.add(to_cycle.get((i + 1) % n));\n }\n return ans;\n }\n\n static void dfs(List> g, int i, int p, int[] sz, Map> comps) {\n sz[i] = 1;\n int last = -1;\n for (int j : g.get(i)) {\n if (j != p) {\n dfs(g, j, i, sz, comps);\n if (sz[j] == 1) {\n if (!comps.containsKey(i)) {\n comps.put(i, new ArrayList<>());\n comps.get(i).add(i);\n }\n comps.get(i).add(j);\n sz[i] += sz[j];\n } else {\n last = j;\n }\n }\n }\n if (i == 0 && sz[i] == 1) {\n comps.put(i, comps.get(last));\n comps.remove(last);\n comps.get(i).add(i);\n }\n }\n\n /* static void dfs(List> g, int i, int p, int[][] dp, List> backtrack) {\n int min_connect = IBIG, min_connect_ind = -1, sum_unconnected = 0;\n for (int j : g.get(i)) {\n if (j != p) {\n dfs(g, j, i, dp, backtrack);\n if (dp[j][0] < min_connect) {\n min_connect = dp[j][0];\n min_connect_ind = j;\n }\n sum_unconnected = min(sum_unconnected + dp[j][1], IBIG);\n }\n }\n dp[i][1] += min_connect;\n backtrack.get(i).add(min_connect_ind);\n for (int j : g.get(i)) {\n if (j != p && j != min_connect_ind) {\n if (dp[j][0] < dp[j][1]) {\n backtrack.get(i).add(j);\n }\n dp[i][1] += min(dp[j][0], dp[j][1]);\n }\n }\n if (dp[i][1] == IBIG) {\n dp[i][0] = 1;\n } else {\n if (sum_unconnected < dp[i][1]) {\n backtrack.get(i).clear();\n }\n dp[i][0] = min(sum_unconnected, dp[i][1]) + 1;\n }\n } */\n\n static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));\n static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));\n static StringTokenizer input;\n static Random __rand = new Random();\n\n // references\n // IBIG = 1e9 + 7\n // 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 mix(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(double[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {double 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 shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void rsort(int[] a) {shuffle(a); sort(a);}\n static void rsort(long[] a) {shuffle(a); sort(a);}\n static void rsort(double[] 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 double[] copy(double[] a) {double[] ans = new double[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> g(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n static List> sg(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n static void c(List> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n static void cto(List> g, int u, int v) {g.get(u).add(v);}\n static void dc(List> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n static void dcto(List> g, int u, int v) {g.get(u).remove(v);}\n // input\n static void r() throws IOException {input = new StringTokenizer(rline());}\n static int ri() throws IOException {return Integer.parseInt(rline());}\n static long rl() throws IOException {return Long.parseLong(rline());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; r(); for(int i = 0; i < n; ++i) a[i] = ni(); return a;}\n static int[] riam1(int n) throws IOException {int[] a = new int[n]; r(); for(int i = 0; i < n; ++i) a[i] = ni() - 1; return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; r(); for(int i = 0; i < n; ++i) a[i] = nl(); return a;}\n static char[] rcha() throws IOException {return rline().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static String n() {return input.nextToken();}\n static int rni() throws IOException {r(); return ni();}\n static int ni() {return Integer.parseInt(n());}\n static long rnl() throws IOException {r(); return nl();}\n static long nl() {return Long.parseLong(n());}\n static double rnd() throws IOException {r(); return nd();}\n static double nd() {return Double.parseDouble(n());}\n static List> rg(int n, int m) throws IOException {List> g = g(n); for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n static void rg(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n static List> rdg(int n, int m) throws IOException {List> g = g(n); for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n static void rdg(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n static List> rsg(int n, int m) throws IOException {List> g = sg(n); for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n static void rsg(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n static List> rdsg(int n, int m) throws IOException {List> g = sg(n); for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n static void rdsg(List> 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 void prln(double... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(Collection c) {int n = c.size() - 1; Iterator iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}\n static void h() {__out.println(\"hlfd\"); flush();}\n static void flush() {__out.flush();}\n static void close() {__out.close();}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "268fe63ce68ba14820e5b03ab982cc7b", "src_uid": "98ded03cdd1870500667f0069d6a84b1", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n\tint oo = (int)1e8;\n\t\n\tpublic static void main(String[] args) {\n\t\tnew G();\n\t}\n\n\tint SQRT;\n\tint[] minTandemStart, minTandemEnd, sa, rsa, lcp;\n\tboolean[] primes;\n\tRMQ query3RMQ, lcpRMQ;\n\tString str;\n\t\n\tpublic G() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tdoPrimes();\n\t\t\n\t\tint n = fs.nextInt();\n\t\tSQRT = (int)Math.sqrt(n);\n\t\tstr = fs.next();\n\t\tFastSuffixArray fsa = new FastSuffixArray();\n\t\tsa = fsa.suffixArray(str.toCharArray());\n\t\trsa = new int[sa.length];\n\t\tlcp = fsa.lcp(sa, str.toCharArray());\n\t\tlcpRMQ = new RMQ(lcp);\n\t\tfor(int i = 0; i < sa.length; i++) rsa[sa[i]] = i;\n\t\t\n\t\tTandemRepeats tr = new TandemRepeats(str);\n\t\tminTandemStart = tr.min;\n\t\tTandemRepeats tr2 = new TandemRepeats(reverse(str));\n\t\tminTandemEnd = reverse(tr2.min);\n\t\t\n//\t\tSystem.out.println(Arrays.toString(minTandemStart));\n//\t\tSystem.out.println(Arrays.toString(minTandemEnd));\n//\t\tSystem.out.println();\n\t\t\n\t\tint[] query3Values = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tquery3Values[i] = i+2*minTandemStart[i];\n\t\t}\n\t\tquery3RMQ = new RMQ(query3Values);\n\t\t\n\t\tint[][] pref = new int[26][n];\n\t\tfor(int i = n-1; i >= 0; i--) {\n\t\t\tfor(int j = 0; j < 26 && i+1 < n; j++) pref[j][i] = pref[j][i+1];\n\t\t\tpref[str.charAt(i)-'a'][i]++;\n\t\t}\n\t\t\n\t\tint Q = fs.nextInt();\n\t\tfor(int qq = 1; qq <= Q; qq++) {\n\t\t\tint L = fs.nextInt()-1, R = fs.nextInt()-1;\n\t\t\t\n\t\t\t//case -1\n\t\t\tboolean good = false;\n\t\t\tfor(int i = 0; i < 26; i++) {\n\t\t\t\tint sum = pref[i][L];\n\t\t\t\tif(R + 1 < n) sum -= pref[i][R+1];\n\t\t\t\tif(sum > 1) good = true;\n\t\t\t}\n\t\t\tif(!good) {\n\t\t\t\tout.println(-1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 1:\n\t\t\tboolean ans1 = false;\n\t\t\tint N = R-L+1;\n\t\t\tfor(int div = 1; div * div <= N; div++) {\n\t\t\t\tif(N % div != 0) continue;\n\t\t\t\tif(!primes[N/div]) continue;\n\t\t\t\t\n\t\t\t\tif(check(L, R, div)) ans1 = true;\n\t\t\t\telse if(primes[div] && check(L, R, N/div)) ans1 = true;\n\t\t\t\tif(ans1) break;\n\t\t\t}\n\t\t\tif(ans1) {\n\t\t\t\tout.println(1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 2:\n\t\t\tboolean ans2 = false;\n\t\t\tif(minTandemStart[L] != oo && L+minTandemStart[L]*2-1 <= R) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(minTandemEnd[R] != oo && R-minTandemEnd[R]*2+1 >= L) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(isBorder(L, R)) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(ans2) {\n\t\t\t\tout.println(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 3:\n\t\t\tboolean ans3 = false;\n\t\t\t{ //first character\n\t\t\t\tint idx = str.charAt(L)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //last character\n\t\t\t\tint idx = str.charAt(R)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //BAAC\n\t\t\t\tint min = query3RMQ.query(L, R);\n\t\t\t\tif(min <= R) ans3 = true;\n\t\t\t}\n\t\t\tif(ans3) {\n\t\t\t\tout.println(3);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(4);\n\t\t}\n\n\t\tout.close();\n\t}\n\t\n\tboolean check(int L, int R, int div) {\n\t\tint minPos = rsa[L], maxPos = rsa[L];\n\t\tfor(int j = L+div; j <= R; j += div) {\n\t\t\tminPos = Math.min(minPos, rsa[j]);\n\t\t\tmaxPos = Math.max(maxPos, rsa[j]);\n\t\t}\n\t\tint lcp = lcpRMQ.query(minPos, maxPos-1);\n\t\tif(lcp >= div) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tboolean isBorder(int L, int R) {\n\t\tfor(int len = 1; len < SQRT; len++) {\n\t\t\tint ptsTo = R-len+1;\n\t\t\tif(ptsTo <= L+len-1) continue;\n\t\t\tint min = Math.min(rsa[L], rsa[ptsTo]);\n\t\t\tint max = Math.max(rsa[L], rsa[ptsTo]);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp >= len) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tint st = Math.max(0, rsa[L]-SQRT-1);\n\t\tint en = Math.min(sa.length-1, rsa[L]+SQRT+1);\n\t\tint him = rsa[L];\n\t\t\n\t\tfor(int i = st; i <= en; i++) {\n\t\t\tint idx = sa[i];\n\t\t\tif(L <= idx && idx <= R) {}\n\t\t\telse continue;\n\t\t\tif(idx+SQRT-1 > R) continue;\n\t\t\tint min = Math.min(i, him);\n\t\t\tint max = Math.max(i, him);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp < SQRT) continue;\n\t\t\tint to = L + SQRT;\n\t\t\tif(to <= idx) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tclass RMQ {\n\t\tint[] vs;\n\t\tint[][] lift;\n\n\t\tpublic RMQ(int[] vs) {\n\t\t\tthis.vs = vs;\n\t\t\tint n = vs.length;\n\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 2;\n\t\t\tlift = new int[maxlog][n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlift[0][i] = vs[i];\n\t\t\tint lastRange = 1;\n\t\t\tfor (int lg = 1; lg < maxlog; lg++) {\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tlift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, n - 1)]);\n\t\t\t\t}\n\t\t\t\tlastRange *= 2;\n\t\t\t}\n\t\t}\n\n\t\tpublic int query(int low, int hi) {\n\t\t\tif(hi < low) return 0;\n\t\t\tint range = hi - low + 1;\n\t\t\tint exp = Integer.highestOneBit(range);\n\t\t\tint lg = Integer.numberOfTrailingZeros(exp);\n\t\t\treturn Math.min(lift[lg][low], lift[lg][hi - exp + 1]);\n\t\t}\n\t}\n\n\tclass FastSuffixArray {\n\t\tpublic int[] suffixArray(char[] S) {\n\t\t\tint n = S.length;\n\t\t\tInteger[] order = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\torder[i] = n - 1 - i;\n\n\t\t\tArrays.sort(order, (a, b) -> Character.compare(S[a], S[b]));\n\n\t\t\tint[] sa = new int[n];\n\t\t\tint[] classes = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tsa[i] = order[i];\n\t\t\t\tclasses[i] = S[i];\n\t\t\t}\n\n\t\t\tfor (int len = 1; len < n; len *= 2) {\n\t\t\t\tint[] c = classes.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tclasses[sa[i]] = i > 0 && c[sa[i - 1]] == c[sa[i]] && sa[i - 1] + len < n && c[sa[i - 1] + len / 2] == c[sa[i] + len / 2] ? classes[sa[i - 1]] : i;\n\t\t\t\t}\n\t\t\t\tint[] cnt = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tcnt[i] = i;\n\t\t\t\tint[] s = sa.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tint s1 = s[i] - len;\n\t\t\t\t\tif (s1 >= 0)\n\t\t\t\t\t\tsa[cnt[classes[s1]]++] = s1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn sa;\n\t\t}\n\n\t\tpublic int[] lcp(int[] sa, char[] s) {\n\t\t\tint n = sa.length;\n\t\t\tint[] rank = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\trank[sa[i]] = i;\n\t\t\tint[] lcp = new int[n - 1];\n\t\t\tfor (int i = 0, h = 0; i < n; i++) {\n\t\t\t\tif (rank[i] < n - 1) {\n\t\t\t\t\tfor (int j = sa[rank[i] + 1]; Math.max(i, j) + h < s.length && s[i + h] == s[j + h]; ++h)\n\t\t\t\t\t\t;\n\t\t\t\t\tlcp[rank[i]] = h;\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t--h;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn lcp;\n\t\t}\n\t}\n\n\tclass TandemRepeats {\n\t\tint[] min;\n\t\tTandemRepeats(String str) {\n\t\t\tlist = new ArrayList<>();\n\t\t\tfindRepetitions(str, 0, str.length()-1);\n\t\t\tCollections.sort(list);\n\t\t\tmin = new int[str.length()];\n\t\t\tArrays.fill(min, oo);\n\n\t\t\tTreeMap map = new TreeMap<>();\n\t\t\tint ptr = 0;\n\t\t\tfor(int i = 0; i < str.length(); i++) {\n\t\t\t\twhile(ptr < list.size()) {\n\t\t\t\t\tEvent now = list.get(ptr);\n\t\t\t\t\tif(now.pos <= i) {\n\t\t\t\t\t\tif(now.type == 0) add(map, now.val);\n\t\t\t\t\t\telse rem(map, now.val);\n\t\t\t\t\t\tptr++;\n\t\t\t\t\t} else break;\n\t\t\t\t}\n\t\t\t\tif(!map.isEmpty())\n\t\t\t\t\tmin[i] = Math.min(min[i], map.firstKey());\n\t\t\t}\n\t\t}\n\n\t\tArrayList list;\n\t\t//Main-Lorentz algorithm\n\t\tvoid findRepetitions(String str, int L, int R) {\n\t\t\tint n = R-L+1;\n\t\t\tif(n < 2 || R < L) return;\n\n\t\t\tString u = str.substring(0, n/2);\n\t\t\tString v = str.substring(n/2);\n\t\t\tfindRepetitions(u, L, L+u.length()-1); findRepetitions(v, L+u.length(), R);\n\n\t\t\tint[] z1 = zValues(reverse(u));\n\t\t\tint[] z2 = zValues(v + \"#\" + u);\n\t\t\tint[] z3 = zValues(reverse(u) + \"#\" + reverse(v));\n\t\t\tint[] z4 = zValues(v);\n\n\t\t\tint uLen = u.length(), vLen = v.length();\n\t\t\tfor(int cntr = 0; cntr < n; cntr++) {\n\t\t\t\tint totLen, k1, k2;\n\t\t\t\tif(cntr < uLen) {\n\t\t\t\t\ttotLen = uLen-cntr;\n\t\t\t\t\tk1 = getIdx(z1, uLen-cntr);\n\t\t\t\t\tk2 = getIdx(z2, vLen+1+cntr);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 0);\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 0);\n\t\t\t\t\t\tint start = Math.max(L, L+cntr-max);\n\t\t\t\t\t\tint end = Math.min(L+cntr-1, L+cntr-min);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttotLen = cntr-uLen+1;\n\t\t\t\t\tk1 = getIdx(z3, uLen + 1 + vLen - 1 - (cntr - uLen));\n\t\t\t\t\tk2 = getIdx(z4, (cntr - uLen) + 1);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 1);\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 1);\n\t\t\t\t\t\tint start = Math.max(L, L+n/2-1 - max + 1);\n\t\t\t\t\t\tint end = Math.min(L+n/2-1, L+n/2-1-min+1);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tint find(int k1, int k2, int len, boolean small, int lim) {\n\t\t\tint lo = lim, hi = k1, res = 0;\n\t\t\tfor(int bs = 0; bs < 50 && lo <= hi; bs++) {\n\t\t\t\tint mid = (lo+hi)/2;\n\t\t\t\tint v = len-mid;\n\t\t\t\tif(v < 0) { //too much\n\t\t\t\t\thi = mid-1;\n\t\t\t\t}\n\t\t\t\telse if(v > k2) { //too little\n\t\t\t\t\tlo = mid+1;\n\t\t\t\t}\n\t\t\t\telse { //great\n\t\t\t\t\tres = mid;\n\t\t\t\t\tif(small) hi = mid-1;\n\t\t\t\t\telse lo = mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tclass Event implements Comparable {\n\t\t\tint type, pos, val;\n\t\t\tEvent(int t, int p, int v) {\n\t\t\t\ttype = t; val = v;\n\t\t\t\tpos = p;\n\t\t\t}\n\t\t\tpublic int compareTo(Event e) {\n\t\t\t\tint comp = Integer.compare(pos, e.pos);\n\t\t\t\tif(comp == 0) comp = Integer.compare(e.type, type);\n\t\t\t\treturn comp;\n\t\t\t}\n\t\t\tpublic String toString() {\n\t\t\t\treturn String.format(\"Pos = %d Type = %d V = %d\", pos, type, val);\n\t\t\t}\n\t\t}\n\n\t\tint getIdx(int[] a, int i) {\n\t\t\tif(i >= 0 && i < a.length) return a[i];\n\t\t\treturn 0;\n\t\t}\n\n\t\tint[] zValues(String string) {\n\t\t\tint n = string.length(); char[] s = string.toCharArray();\n\t\t\tint[] z = new int[n]; z[0] = n;\n\t\t\tint L = 0, R = 0;\n\t\t\tint[] left = new int[n], right = new int[n];\n\t\t\tfor(int i = 1; i < n; ++i) {\n\t\t\t\tif(i > R) {\n\t\t\t\t\tL = R = i;\n\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t} else {\n\t\t\t\t\tint k = i-L;\n\t\t\t\t\tif(z[k] < R-i+1) z[i] = z[k];\n\t\t\t\t\telse {\n\t\t\t\t\t\tL = i;\n\t\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tleft[i] = L; right[i] = R;\n\t\t\t}\n\t\t\treturn z;\n\t\t}\n\n\n\t\tvoid add(TreeMap map, int x) {\n\t\t\tmap.put(x, map.getOrDefault(x, 0)+1);\n\t\t}\n\t\tvoid rem(TreeMap map, int x) {\n\t\t\tint fr = map.get(x)-1;\n\t\t\tif(fr == 0) map.remove(x);\n\t\t\telse map.put(x, fr);\n\t\t}\n\t}\n\t\n\tvoid doPrimes() {\n\t\tprimes = new boolean[200200];\n\t\tArrays.fill(primes, true);\n\t\tprimes[0] = primes[1] = false;\n\t\tfor(int i = 2; i < primes.length; i++) {\n\t\t\tif(!primes[i]) continue;\n\t\t\tfor(int j = i+i; j < primes.length; j += i) primes[j] = false;\n\t\t}\n\t}\n\t\n\tString reverse(String s) {\n\t\treturn new StringBuilder(s).reverse().toString();\n\t}\n\tint[] reverse(int[] a) {\n\t\tint n = a.length;\n\t\tint[] res = new int[n];\n\t\tfor(int i = 0, j = n-1; i < n; i++, j--) {\n\t\t\tres[i] = a[j];\n\t\t}\n\t\treturn res;\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tString next() {\n\t\t\tif(st.hasMoreTokens()) return st.nextToken();\n\t\t\ttry { st = new StringTokenizer(br.readLine()); } catch (Exception e) {}\n\t\t\treturn next();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a6c6c507c2be1947d5e4fd3167ab425", "src_uid": "bc839e9a025a5d83e2c85fb1e224c175", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n\tint oo = (int)1e8;\n\t\n\tpublic static void main(String[] args) {\n\t\tnew G();\n\t}\n\n\tint SQRT;\n\tint[] minTandemStart, minTandemEnd, sa, rsa, lcp;\n\tboolean[] primes;\n\tRMQ query3RMQ, lcpRMQ;\n\tint[] trailingZeros, highestOneBit;\n\tString str;\n\t\n\tpublic G() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\ttrailingZeros = new int[200200];\n\t\thighestOneBit = new int[200200];\n\t\tfor(int i = 1; i < 200200; i++) {\n\t\t\thighestOneBit[i] = Integer.highestOneBit(i);\n\t\t\ttrailingZeros[i] = Integer.numberOfTrailingZeros(highestOneBit[i]);\n\t\t}\n\t\t\n\t\tdoPrimes();\n\t\t\n\t\tint n = fs.nextInt();\n\t\tSQRT = (int)Math.sqrt(n);\n\t\tstr = fs.next();\n\t\tFastSuffixArray fsa = new FastSuffixArray();\n\t\tsa = fsa.suffixArray(str.toCharArray());\n\t\trsa = new int[sa.length];\n\t\tlcp = fsa.lcp(sa, str.toCharArray());\n\t\tlcpRMQ = new RMQ(lcp);\n\t\tfor(int i = 0; i < sa.length; i++) rsa[sa[i]] = i;\n\t\t\n\t\tTandemRepeats tr = new TandemRepeats(str);\n\t\tminTandemStart = tr.min;\n\t\tTandemRepeats tr2 = new TandemRepeats(reverse(str));\n\t\tminTandemEnd = reverse(tr2.min);\n\t\t\n\t\tint[] query3Values = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tminTandemStart[i] <<= 1;\n\t\t\tminTandemEnd[i] <<= 1;\n\t\t}\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tquery3Values[i] = i+minTandemStart[i];\n\t\t}\n\t\tquery3RMQ = new RMQ(query3Values);\n\t\t\n\t\tint[][] pref = new int[26][n];\n\t\tfor(int i = n-1; i >= 0; i--) {\n\t\t\tfor(int j = 0; j < 26 && i+1 < n; j++) pref[j][i] = pref[j][i+1];\n\t\t\tpref[str.charAt(i)-'a'][i]++;\n\t\t}\n\t\t\n\t\tint Q = fs.nextInt();\n\t\tfor(int qq = 1; qq <= Q; qq++) {\n\t\t\tint L = fs.nextInt()-1, R = fs.nextInt()-1;\n\t\t\t\n\t\t\t//case -1\n\t\t\tboolean good = false;\n\t\t\tfor(int i = 0; i < 26; i++) {\n\t\t\t\tint sum = pref[i][L];\n\t\t\t\tif(R + 1 < n) sum -= pref[i][R+1];\n\t\t\t\tif(sum > 1) good = true;\n\t\t\t}\n\t\t\tif(!good) {\n\t\t\t\tout.println(-1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 1:\n\t\t\tboolean ans1 = false;\n\t\t\tint N = R-L+1;\n\t\t\tfor(int div = 1; div*div <= N; div++) {\n\t\t\t\tif(N % div != 0) continue;\n\t\t\t\tint nd = N/div;\n\t\t\t\tif(primes[nd] && check(L, R, div)) {\n\t\t\t\t\tans1 = true;\n\t\t\t\t}\n\t\t\t\tif(!ans1 && primes[div] && check(L, R, nd)) ans1 = true;\n\t\t\t\tif(ans1) break;\n\t\t\t}\n\t\t\tif(ans1) {\n\t\t\t\tout.println(1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 2:\n\t\t\tboolean ans2 = false;\n\t\t\tif(minTandemStart[L] < oo && L+minTandemStart[L]-1 <= R) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(minTandemEnd[R] < oo && R-minTandemEnd[R]+1 >= L) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(!ans2 && isBorder(L, R)) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(ans2) {\n\t\t\t\tout.println(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 3:\n\t\t\tboolean ans3 = false;\n\t\t\t{ //first character\n\t\t\t\tint idx = str.charAt(L)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //last character\n\t\t\t\tint idx = str.charAt(R)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //BAAC\n\t\t\t\tint min = query3RMQ.query(L, R);\n\t\t\t\tif(min <= R) ans3 = true;\n\t\t\t}\n\t\t\tif(ans3) {\n\t\t\t\tout.println(3);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(4);\n\t\t}\n\n\t\tout.close();\n\t}\n\t\n\tboolean check(int L, int R, int div) {\n\t\tint minPos = rsa[L], maxPos = rsa[L];\n\t\tchar beg = str.charAt(L);\n\t\tfor(int j = L+div; j <= R; j += div) {\n\t\t\tif(str.charAt(j) != beg) return false;\n\t\t\tminPos = min(minPos, rsa[j]);\n\t\t\tmaxPos = max(maxPos, rsa[j]);\n\t\t}\n\t\tint lcp = lcpRMQ.query(minPos, maxPos-1);\n\t\tif(lcp >= div) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tRandom rand = new Random();\n\tboolean isBorder(int L, int R) {\n\t\tfor(int len = 1; len < SQRT; len++) {\n\t\t\tint ptsTo = R-len+1;\n\t\t\tif(ptsTo <= L+len-1) continue;\n\t\t\tint min = min(rsa[L], rsa[ptsTo]);\n\t\t\tint max = max(rsa[L], rsa[ptsTo]);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp >= len) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tint st = max(0, rsa[L]-SQRT/2-1);\n\t\tint en = min(sa.length-1, rsa[L]+SQRT/2+1);\n\t\tint him = rsa[L];\n\t\t\n\t\tfor(int i = him-1; i >= st; i--) {\n\t\t\tint idx = sa[i];\n\t\t\tif(L <= idx && idx <= R) {}\n\t\t\telse continue;\n\t\t\tint min = min(i, him);\n\t\t\tint max = max(i, him);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp < SQRT) break;\n\t\t\t\n\t\t\tif(idx+lcp-1 < R) continue;\n\t\t\tint size = R-idx+1;\n\t\t\tif(L+size-1 >= idx) continue;\n\t\t\treturn true;\n\t\t}\n\t\tfor(int i = him+1; i <= en; i++) {\n\t\t\tint idx = sa[i];\n\t\t\tif(L <= idx && idx <= R) {}\n\t\t\telse continue;\n\t\t\tint min = min(i, him);\n\t\t\tint max = max(i, him);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp < SQRT) break;\n\t\t\t\n\t\t\tif(idx+lcp-1 < R) continue;\n\t\t\tint size = R-idx+1;\n\t\t\tif(L+size-1 >= idx) continue;\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tclass RMQ {\n\t\tint[] vs;\n\t\tint[][] lift;\n\n\t\tpublic RMQ(int[] vs) {\n\t\t\tthis.vs = vs;\n\t\t\tint n = vs.length;\n\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 1;\n\t\t\tlift = new int[maxlog][n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlift[0][i] = vs[i];\n\t\t\tint lastRange = 1;\n\t\t\tfor (int lg = 1; lg < maxlog; lg++) {\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tlift[lg][i] = min(lift[lg - 1][i], lift[lg - 1][min(i + lastRange, n - 1)]);\n\t\t\t\t}\n\t\t\t\tlastRange <<= 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic int query(int low, int hi) {\n\t\t\tif(hi < low) return 0;\n\t\t\tint range = hi - low + 1;\n\t\t\tint exp = highestOneBit[range];\n\t\t\tint lg = trailingZeros[exp];\n\t\t\treturn min(lift[lg][low], lift[lg][hi - exp + 1]);\n\t\t}\n\t}\n\n\tclass FastSuffixArray {\n\t\tpublic int[] suffixArray(char[] S) {\n\t\t\tint n = S.length;\n\t\t\tInteger[] order = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\torder[i] = n - 1 - i;\n\n\t\t\tArrays.sort(order, (a, b) -> Character.compare(S[a], S[b]));\n\n\t\t\tint[] sa = new int[n];\n\t\t\tint[] classes = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tsa[i] = order[i];\n\t\t\t\tclasses[i] = S[i];\n\t\t\t}\n\n\t\t\tfor (int len = 1; len < n; len <<= 1) {\n\t\t\t\tint[] c = classes.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tclasses[sa[i]] = i > 0 && c[sa[i - 1]] == c[sa[i]] && sa[i - 1] + len < n && c[sa[i - 1] + len / 2] == c[sa[i] + len / 2] ? classes[sa[i - 1]] : i;\n\t\t\t\t}\n\t\t\t\tint[] cnt = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tcnt[i] = i;\n\t\t\t\tint[] s = sa.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tint s1 = s[i] - len;\n\t\t\t\t\tif (s1 >= 0)\n\t\t\t\t\t\tsa[cnt[classes[s1]]++] = s1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn sa;\n\t\t}\n\n\t\tpublic int[] lcp(int[] sa, char[] s) {\n\t\t\tint n = sa.length;\n\t\t\tint[] rank = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\trank[sa[i]] = i;\n\t\t\tint[] lcp = new int[n - 1];\n\t\t\tfor (int i = 0, h = 0; i < n; i++) {\n\t\t\t\tif (rank[i] < n - 1) {\n\t\t\t\t\tfor (int j = sa[rank[i] + 1]; max(i, j) + h < s.length && s[i + h] == s[j + h]; ++h)\n\t\t\t\t\t\t;\n\t\t\t\t\tlcp[rank[i]] = h;\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t--h;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn lcp;\n\t\t}\n\t}\n\n\tint MAX = 7500000;\n\tclass TandemRepeats {\n\t\tEvent[] list = new Event[MAX];\n\t\tint ptr2 = 0;\n\t\tint[] min;\n\t\tTandemRepeats(String str) {\n\t\t\tptr2 = 0;\n\t\t\tfindRepetitions(str, 0, str.length()-1);\n\t\t\tArrays.sort(list, 0, ptr2);\n\t\t\tmin = new int[str.length()];\n\t\t\tArrays.fill(min, oo);\n\n\t\t\tint n = str.length();\n\t\t\tBIT bit = new BIT(n+1);\n\t\t\tint ptr = 0;\n\t\t\tfor(int i = 0; i < str.length(); i++) {\n\t\t\t\twhile(ptr < ptr2) {\n\t\t\t\t\tEvent now = list[ptr];\n\t\t\t\t\tif(now.pos <= i) {\n\t\t\t\t\t\tif(now.type == 0) bit.update(now.val, 1);\n\t\t\t\t\t\telse bit.update(now.val, -1);\n\t\t\t\t\t\tptr++;\n\t\t\t\t\t} else break;\n\t\t\t\t}\n\t\t\t\tint pos = bit.getKth(0);\n\t\t\t\tif(pos <= n) min[i] = min(min[i], pos);\n\t\t\t}\n\t\t}\n\n\t\t//Main-Lorentz algorithm\n\t\tvoid findRepetitions(String str, int L, int R) {\n\t\t\tint n = R-L+1;\n\t\t\tif(n < 2 || R < L) return;\n\n\t\t\tString u = str.substring(0, n/2);\n\t\t\tString v = str.substring(n/2);\n\t\t\tfindRepetitions(u, L, L+u.length()-1); findRepetitions(v, L+u.length(), R);\n\n\t\t\tint[] z1 = zValues(reverse(u));\n\t\t\tint[] z2 = zValues(v + \"#\" + u);\n\t\t\tint[] z3 = zValues(reverse(u) + \"#\" + reverse(v));\n\t\t\tint[] z4 = zValues(v);\n\n\t\t\tint uLen = u.length(), vLen = v.length();\n\t\t\tfor(int cntr = 0; cntr < n; cntr++) {\n\t\t\t\tint totLen, k1, k2;\n\t\t\t\tif(cntr < uLen) {\n\t\t\t\t\ttotLen = uLen-cntr;\n\t\t\t\t\tk1 = getIdx(z1, uLen-cntr);\n\t\t\t\t\tk2 = getIdx(z2, vLen+1+cntr);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint min = findSmall1(k1, k2, totLen);\n\t\t\t\t\t\tint max = findLarge1(k1, k2, totLen);\n\t\t\t\t\t\tif(min < 0 || max < 0 || min > k1 || max > k1) continue;\n\t\t\t\t\t\tint start = max(L, L+cntr-max);\n\t\t\t\t\t\tint end = min(L+cntr-1, L+cntr-min);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist[ptr2++] = (new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist[ptr2++] = (new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttotLen = cntr-uLen+1;\n\t\t\t\t\tk1 = getIdx(z3, uLen + 1 + vLen - 1 - (cntr - uLen));\n\t\t\t\t\tk2 = getIdx(z4, (cntr - uLen) + 1);\n\n\t\t\t\t\tif(k1+k2 >= totLen && k1 > 0) {\n\t\t\t\t\t\tint min = findSmall2(k1, k2, totLen);\n\t\t\t\t\t\tint max = findLarge1(k1, k2, totLen);\n\t\t\t\t\t\tif(min < 1 || max < 1 || min > k1 || max > k1) continue;\n\t\t\t\t\t\tint start = max(L, L+n/2-1 - max + 1);\n\t\t\t\t\t\tint end = min(L+n/2-1, L+n/2-1-min+1);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist[ptr2++] = (new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist[ptr2++] = (new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\t\n\t\tint findSmall1(int k1, int k2, int len) {\n\t\t\tif(k2 >= len) return 0;\n\t\t\treturn len-k2;\n\t\t}\n\t\tint findSmall2(int k1, int k2, int len) {\n\t\t\tif(k2 >= len-1) return 1;\n\t\t\treturn min(k1, len - k2);\n\t\t}\n\t\tint findLarge1(int k1, int k2, int len) {\n\t\t\tif(k1 < len) return k1;\n\t\t\treturn len;\n\t\t}\n\n\t\tclass Event implements Comparable {\n\t\t\tint type, pos, val;\n\t\t\tEvent(int t, int p, int v) {\n\t\t\t\ttype = t; val = v;\n\t\t\t\tpos = p;\n\t\t\t}\n\t\t\tpublic int compareTo(Event e) {\n\t\t\t\tint comp = Integer.compare(pos, e.pos);\n\t\t\t\tif(comp == 0) comp = Integer.compare(e.type, type);\n\t\t\t\treturn comp;\n\t\t\t}\n\t\t\tpublic String toString() {\n\t\t\t\treturn String.format(\"Pos = %d Type = %d V = %d\", pos, type, val);\n\t\t\t}\n\t\t}\n\n\t\tint getIdx(int[] a, int i) {\n\t\t\tif(i >= 0 && i < a.length) return a[i];\n\t\t\treturn 0;\n\t\t}\n\n\t\tint[] zValues(String str) {\n\t\t\tint n = str.length(); char[] s = str.toCharArray();\n\t\t\tint[] z = new int[n]; z[0] = n;\n\t\t\tint L = 0, R = 0;\n\t\t\tint[] left = new int[n], right = new int[n];\n\t\t\tfor(int i = 1; i < n; ++i) {\n\t\t\t\tif(i > R) {\n\t\t\t\t\tL = R = i;\n\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t} else {\n\t\t\t\t\tint k = i-L;\n\t\t\t\t\tif(z[k] < R-i+1) z[i] = z[k];\n\t\t\t\t\telse {\n\t\t\t\t\t\tL = i;\n\t\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tleft[i] = L; right[i] = R;\n\t\t\t}\n\t\t\treturn z;\n\t\t}\n\n\n\t\tvoid add(TreeMap map, int x) {\n\t\t\tmap.put(x, map.getOrDefault(x, 0)+1);\n\t\t}\n\t\tvoid rem(TreeMap map, int x) {\n\t\t\tint fr = map.get(x)-1;\n\t\t\tif(fr == 0) map.remove(x);\n\t\t\telse map.put(x, fr);\n\t\t}\n\t}\n\t\n\tvoid doPrimes() {\n\t\tprimes = new boolean[200200];\n\t\tArrays.fill(primes, true);\n\t\tprimes[0] = primes[1] = false;\n\t\tfor(int i = 2; i < primes.length; i++) {\n\t\t\tif(!primes[i]) continue;\n\t\t\tfor(int j = i+i; j < primes.length; j += i) primes[j] = false;\n\t\t}\n\t}\n\t\n\tString reverse(String s) {\n\t\treturn new StringBuilder(s).reverse().toString();\n\t}\n\tint[] reverse(int[] a) {\n\t\tint n = a.length;\n\t\tint[] res = new int[n];\n\t\tfor(int i = 0, j = n-1; i < n; i++, j--) {\n\t\t\tres[i] = a[j];\n\t\t}\n\t\treturn res;\n\t}\n\n\tint min(int a, int b) {\n\t\treturn a < b ? a : b;\n\t}\n\tint max(int a, int b) {\n\t\treturn a > b ? a : b;\n\t}\n\t\n\tclass BIT {\n\t\tint n, hn;\n\t\tint[] tree;\n\t\t\n\t\tpublic BIT(int n) {\n\t\t\tthis.n = n;\n\t\t\ttree = new int[n + 2];\n\t\t\thn = Integer.highestOneBit(n);\n\t\t}\n\t\t\n\t\tint read(int i) {\n\t\t\ti++;\n\t\t\tint sum = 0;\n\t\t\twhile (i > 0) {\n\t\t\t\tsum += tree[i];\n\t\t\t\ti -= i & -i;\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tvoid update(int i, int val) {\n\t\t\ti++;\n\t\t\twhile (i <= n) {\n\t\t\t\ttree[i] += val;\n\t\t\t\ti += i & -i;\n\t\t\t}\n\t\t}\n\n\t\t// if the BIT is a freq array, returns the\n\t\t// index of the kth item, or n if there are fewer\n\t\t// than k items.\n\t\tint getKth(int k) {\n\t\t\tint e=hn, o=0;\n\t\t\tfor (; e!=0; e>>=1) {\n\t\t\t\tif (e+o<=n && tree[e+o]<=k) {\n\t\t\t\t\tk-=tree[e+o];\n\t\t\t\t\to+=e;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn o;\n\t\t}\n\t\t\n\t}\n\t\n\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "30805bdbf73fed6ec44d4323481ea1ae", "src_uid": "bc839e9a025a5d83e2c85fb1e224c175", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n\tint oo = (int)1e8;\n\t\n\tpublic static void main(String[] args) {\n\t\tnew G();\n\t}\n\n\tint SQRT;\n\tint[] minTandemStart, minTandemEnd, sa, rsa, lcp;\n\tboolean[] primes;\n\tRMQ query3RMQ, lcpRMQ;\n\tString str;\n\t\n\tpublic G() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tdoPrimes();\n\t\t\n\t\tint n = fs.nextInt();\n\t\tSQRT = (int)Math.sqrt(n);\n\t\tstr = fs.next();\n\t\tFastSuffixArray fsa = new FastSuffixArray();\n\t\tsa = fsa.suffixArray(str.toCharArray());\n\t\trsa = new int[sa.length];\n\t\tlcp = fsa.lcp(sa, str.toCharArray());\n\t\tlcpRMQ = new RMQ(lcp);\n\t\tfor(int i = 0; i < sa.length; i++) rsa[sa[i]] = i;\n\t\t\n\t\tTandemRepeats tr = new TandemRepeats(str);\n\t\tminTandemStart = tr.min;\n\t\tTandemRepeats tr2 = new TandemRepeats(reverse(str));\n\t\tminTandemEnd = reverse(tr2.min);\n\t\t\n//\t\tSystem.out.println(Arrays.toString(minTandemStart));\n//\t\tSystem.out.println(Arrays.toString(minTandemEnd));\n//\t\tSystem.out.println();\n\t\t\n\t\tint[] query3Values = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tquery3Values[i] = i+2*minTandemStart[i];\n\t\t}\n\t\tquery3RMQ = new RMQ(query3Values);\n\t\t\n\t\tint[][] pref = new int[26][n];\n\t\tfor(int i = n-1; i >= 0; i--) {\n\t\t\tfor(int j = 0; j < 26 && i+1 < n; j++) pref[j][i] = pref[j][i+1];\n\t\t\tpref[str.charAt(i)-'a'][i]++;\n\t\t}\n\t\t\n\t\tint Q = fs.nextInt();\n\t\tfor(int qq = 1; qq <= Q; qq++) {\n\t\t\tint L = fs.nextInt()-1, R = fs.nextInt()-1;\n\t\t\t\n\t\t\t//case -1\n\t\t\tboolean good = false;\n\t\t\tfor(int i = 0; i < 26; i++) {\n\t\t\t\tint sum = pref[i][L];\n\t\t\t\tif(R + 1 < n) sum -= pref[i][R+1];\n\t\t\t\tif(sum > 1) good = true;\n\t\t\t}\n\t\t\tif(!good) {\n\t\t\t\tout.println(-1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 1:\n\t\t\tboolean ans1 = false;\n\t\t\tint N = R-L+1;\n\t\t\tfor(int div = 1; div * div <= N; div++) {\n\t\t\t\tif(N % div != 0) continue;\n\t\t\t\tif(primes[N/div] && check(L, R, div)) {\n\t\t\t\t\tans1 = true;\n\t\t\t\t}\n\t\t\t\tif(!ans1 && primes[div] && check(L, R, N/div)) ans1 = true;\n\t\t\t\tif(ans1) break;\n\t\t\t}\n\t\t\tif(ans1) {\n\t\t\t\tout.println(1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 2:\n\t\t\tboolean ans2 = false;\n\t\t\tif(minTandemStart[L] != oo && L+minTandemStart[L]*2-1 <= R) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(minTandemEnd[R] != oo && R-minTandemEnd[R]*2+1 >= L) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(isBorder(L, R)) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(ans2) {\n\t\t\t\tout.println(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 3:\n\t\t\tboolean ans3 = false;\n\t\t\t{ //first character\n\t\t\t\tint idx = str.charAt(L)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //last character\n\t\t\t\tint idx = str.charAt(R)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //BAAC\n\t\t\t\tint min = query3RMQ.query(L, R);\n\t\t\t\tif(min <= R) ans3 = true;\n\t\t\t}\n\t\t\tif(ans3) {\n\t\t\t\tout.println(3);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(4);\n\t\t}\n\n\t\tout.close();\n\t}\n\t\n\tboolean check(int L, int R, int div) {\n\t\tint minPos = rsa[L], maxPos = rsa[L];\n\t\tfor(int j = L+div; j <= R; j += div) {\n\t\t\tminPos = Math.min(minPos, rsa[j]);\n\t\t\tmaxPos = Math.max(maxPos, rsa[j]);\n\t\t}\n\t\tint lcp = lcpRMQ.query(minPos, maxPos-1);\n\t\tif(lcp >= div) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tboolean isBorder(int L, int R) {\n\t\tfor(int len = 1; len < SQRT; len++) {\n\t\t\tint ptsTo = R-len+1;\n\t\t\tif(ptsTo <= L+len-1) continue;\n\t\t\tint min = Math.min(rsa[L], rsa[ptsTo]);\n\t\t\tint max = Math.max(rsa[L], rsa[ptsTo]);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp >= len) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tint st = Math.max(0, rsa[L]-SQRT-1);\n\t\tint en = Math.min(sa.length-1, rsa[L]+SQRT+1);\n\t\tint him = rsa[L];\n\t\t\n\t\tfor(int i = st; i <= en; i++) {\n\t\t\tint idx = sa[i];\n\t\t\tif(L <= idx && idx <= R) {}\n\t\t\telse continue;\n\t\t\tint min = Math.min(i, him);\n\t\t\tint max = Math.max(i, him);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp < SQRT) continue;\n\t\t\t\n\t\t\tif(idx+lcp-1 < R) continue;\n\t\t\tint size = R-idx+1;\n\t\t\tif(L+size-1 >= idx) continue;\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tclass RMQ {\n\t\tint[] vs;\n\t\tint[][] lift;\n\n\t\tpublic RMQ(int[] vs) {\n\t\t\tthis.vs = vs;\n\t\t\tint n = vs.length;\n\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 2;\n\t\t\tlift = new int[maxlog][n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlift[0][i] = vs[i];\n\t\t\tint lastRange = 1;\n\t\t\tfor (int lg = 1; lg < maxlog; lg++) {\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tlift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, n - 1)]);\n\t\t\t\t}\n\t\t\t\tlastRange *= 2;\n\t\t\t}\n\t\t}\n\n\t\tpublic int query(int low, int hi) {\n\t\t\tif(hi < low) return 0;\n\t\t\tint range = hi - low + 1;\n\t\t\tint exp = Integer.highestOneBit(range);\n\t\t\tint lg = Integer.numberOfTrailingZeros(exp);\n\t\t\treturn Math.min(lift[lg][low], lift[lg][hi - exp + 1]);\n\t\t}\n\t}\n\n\tclass FastSuffixArray {\n\t\tpublic int[] suffixArray(char[] S) {\n\t\t\tint n = S.length;\n\t\t\tInteger[] order = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\torder[i] = n - 1 - i;\n\n\t\t\tArrays.sort(order, (a, b) -> Character.compare(S[a], S[b]));\n\n\t\t\tint[] sa = new int[n];\n\t\t\tint[] classes = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tsa[i] = order[i];\n\t\t\t\tclasses[i] = S[i];\n\t\t\t}\n\n\t\t\tfor (int len = 1; len < n; len *= 2) {\n\t\t\t\tint[] c = classes.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tclasses[sa[i]] = i > 0 && c[sa[i - 1]] == c[sa[i]] && sa[i - 1] + len < n && c[sa[i - 1] + len / 2] == c[sa[i] + len / 2] ? classes[sa[i - 1]] : i;\n\t\t\t\t}\n\t\t\t\tint[] cnt = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tcnt[i] = i;\n\t\t\t\tint[] s = sa.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tint s1 = s[i] - len;\n\t\t\t\t\tif (s1 >= 0)\n\t\t\t\t\t\tsa[cnt[classes[s1]]++] = s1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn sa;\n\t\t}\n\n\t\tpublic int[] lcp(int[] sa, char[] s) {\n\t\t\tint n = sa.length;\n\t\t\tint[] rank = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\trank[sa[i]] = i;\n\t\t\tint[] lcp = new int[n - 1];\n\t\t\tfor (int i = 0, h = 0; i < n; i++) {\n\t\t\t\tif (rank[i] < n - 1) {\n\t\t\t\t\tfor (int j = sa[rank[i] + 1]; Math.max(i, j) + h < s.length && s[i + h] == s[j + h]; ++h)\n\t\t\t\t\t\t;\n\t\t\t\t\tlcp[rank[i]] = h;\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t--h;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn lcp;\n\t\t}\n\t}\n\n\tclass TandemRepeats {\n\t\tint[] min;\n\t\tTandemRepeats(String str) {\n\t\t\tlist = new ArrayList<>();\n\t\t\tfindRepetitions(str, 0, str.length()-1);\n\t\t\tCollections.sort(list);\n\t\t\tmin = new int[str.length()];\n\t\t\tArrays.fill(min, oo);\n\n\t\t\tTreeMap map = new TreeMap<>();\n\t\t\tint ptr = 0;\n\t\t\tfor(int i = 0; i < str.length(); i++) {\n\t\t\t\twhile(ptr < list.size()) {\n\t\t\t\t\tEvent now = list.get(ptr);\n\t\t\t\t\tif(now.pos <= i) {\n\t\t\t\t\t\tif(now.type == 0) add(map, now.val);\n\t\t\t\t\t\telse rem(map, now.val);\n\t\t\t\t\t\tptr++;\n\t\t\t\t\t} else break;\n\t\t\t\t}\n\t\t\t\tif(!map.isEmpty())\n\t\t\t\t\tmin[i] = Math.min(min[i], map.firstKey());\n\t\t\t}\n\t\t}\n\n\t\tArrayList list;\n\t\t//Main-Lorentz algorithm\n\t\tvoid findRepetitions(String str, int L, int R) {\n\t\t\tint n = R-L+1;\n\t\t\tif(n < 2 || R < L) return;\n\n\t\t\tString u = str.substring(0, n/2);\n\t\t\tString v = str.substring(n/2);\n\t\t\tfindRepetitions(u, L, L+u.length()-1); findRepetitions(v, L+u.length(), R);\n\n\t\t\tint[] z1 = zValues(reverse(u));\n\t\t\tint[] z2 = zValues(v + \"#\" + u);\n\t\t\tint[] z3 = zValues(reverse(u) + \"#\" + reverse(v));\n\t\t\tint[] z4 = zValues(v);\n\n\t\t\tint uLen = u.length(), vLen = v.length();\n\t\t\tfor(int cntr = 0; cntr < n; cntr++) {\n\t\t\t\tint totLen, k1, k2;\n\t\t\t\tif(cntr < uLen) {\n\t\t\t\t\ttotLen = uLen-cntr;\n\t\t\t\t\tk1 = getIdx(z1, uLen-cntr);\n\t\t\t\t\tk2 = getIdx(z2, vLen+1+cntr);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 0);\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 0);\n\t\t\t\t\t\tint start = Math.max(L, L+cntr-max);\n\t\t\t\t\t\tint end = Math.min(L+cntr-1, L+cntr-min);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttotLen = cntr-uLen+1;\n\t\t\t\t\tk1 = getIdx(z3, uLen + 1 + vLen - 1 - (cntr - uLen));\n\t\t\t\t\tk2 = getIdx(z4, (cntr - uLen) + 1);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 1);\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 1);\n\t\t\t\t\t\tint start = Math.max(L, L+n/2-1 - max + 1);\n\t\t\t\t\t\tint end = Math.min(L+n/2-1, L+n/2-1-min+1);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tint find(int k1, int k2, int len, boolean small, int lim) {\n\t\t\tint lo = lim, hi = k1, res = 0;\n\t\t\tfor(int bs = 0; bs < 50 && lo <= hi; bs++) {\n\t\t\t\tint mid = (lo+hi)/2;\n\t\t\t\tint v = len-mid;\n\t\t\t\tif(v < 0) { //too much\n\t\t\t\t\thi = mid-1;\n\t\t\t\t}\n\t\t\t\telse if(v > k2) { //too little\n\t\t\t\t\tlo = mid+1;\n\t\t\t\t}\n\t\t\t\telse { //great\n\t\t\t\t\tres = mid;\n\t\t\t\t\tif(small) hi = mid-1;\n\t\t\t\t\telse lo = mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tclass Event implements Comparable {\n\t\t\tint type, pos, val;\n\t\t\tEvent(int t, int p, int v) {\n\t\t\t\ttype = t; val = v;\n\t\t\t\tpos = p;\n\t\t\t}\n\t\t\tpublic int compareTo(Event e) {\n\t\t\t\tint comp = Integer.compare(pos, e.pos);\n\t\t\t\tif(comp == 0) comp = Integer.compare(e.type, type);\n\t\t\t\treturn comp;\n\t\t\t}\n\t\t\tpublic String toString() {\n\t\t\t\treturn String.format(\"Pos = %d Type = %d V = %d\", pos, type, val);\n\t\t\t}\n\t\t}\n\n\t\tint getIdx(int[] a, int i) {\n\t\t\tif(i >= 0 && i < a.length) return a[i];\n\t\t\treturn 0;\n\t\t}\n\n\t\tint[] zValues(String string) {\n\t\t\tint n = string.length(); char[] s = string.toCharArray();\n\t\t\tint[] z = new int[n]; z[0] = n;\n\t\t\tint L = 0, R = 0;\n\t\t\tint[] left = new int[n], right = new int[n];\n\t\t\tfor(int i = 1; i < n; ++i) {\n\t\t\t\tif(i > R) {\n\t\t\t\t\tL = R = i;\n\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t} else {\n\t\t\t\t\tint k = i-L;\n\t\t\t\t\tif(z[k] < R-i+1) z[i] = z[k];\n\t\t\t\t\telse {\n\t\t\t\t\t\tL = i;\n\t\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tleft[i] = L; right[i] = R;\n\t\t\t}\n\t\t\treturn z;\n\t\t}\n\n\n\t\tvoid add(TreeMap map, int x) {\n\t\t\tmap.put(x, map.getOrDefault(x, 0)+1);\n\t\t}\n\t\tvoid rem(TreeMap map, int x) {\n\t\t\tint fr = map.get(x)-1;\n\t\t\tif(fr == 0) map.remove(x);\n\t\t\telse map.put(x, fr);\n\t\t}\n\t}\n\t\n\tvoid doPrimes() {\n\t\tprimes = new boolean[200200];\n\t\tArrays.fill(primes, true);\n\t\tprimes[0] = primes[1] = false;\n\t\tfor(int i = 2; i < primes.length; i++) {\n\t\t\tif(!primes[i]) continue;\n\t\t\tfor(int j = i+i; j < primes.length; j += i) primes[j] = false;\n\t\t}\n\t}\n\t\n\tString reverse(String s) {\n\t\treturn new StringBuilder(s).reverse().toString();\n\t}\n\tint[] reverse(int[] a) {\n\t\tint n = a.length;\n\t\tint[] res = new int[n];\n\t\tfor(int i = 0, j = n-1; i < n; i++, j--) {\n\t\t\tres[i] = a[j];\n\t\t}\n\t\treturn res;\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tString next() {\n\t\t\tif(st.hasMoreTokens()) return st.nextToken();\n\t\t\ttry { st = new StringTokenizer(br.readLine()); } catch (Exception e) {}\n\t\t\treturn next();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c60d895bd2bf25f9f65e11fa1c771a9b", "src_uid": "bc839e9a025a5d83e2c85fb1e224c175", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n\tint oo = (int)1e8;\n\t\n\tpublic static void main(String[] args) {\n\t\tnew G();\n\t}\n\n\tint SQRT;\n\tint[] minTandemStart, minTandemEnd, sa, rsa, lcp;\n\tboolean[] primes;\n\tRMQ query3RMQ, lcpRMQ;\n\tString str;\n\t\n\tpublic G() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tdoPrimes();\n\t\t\n\t\tint n = fs.nextInt();\n\t\tSQRT = (int)Math.sqrt(n);\n\t\tstr = fs.next();\n\t\tFastSuffixArray fsa = new FastSuffixArray();\n\t\tsa = fsa.suffixArray(str.toCharArray());\n\t\trsa = new int[sa.length];\n\t\tlcp = fsa.lcp(sa, str.toCharArray());\n\t\tlcpRMQ = new RMQ(lcp);\n\t\tfor(int i = 0; i < sa.length; i++) rsa[sa[i]] = i;\n\t\t\n\t\tTandemRepeats tr = new TandemRepeats(str);\n\t\tminTandemStart = tr.min;\n\t\tTandemRepeats tr2 = new TandemRepeats(reverse(str));\n\t\tminTandemEnd = reverse(tr2.min);\n\t\t\n//\t\tSystem.out.println(Arrays.toString(minTandemStart));\n//\t\tSystem.out.println(Arrays.toString(minTandemEnd));\n//\t\tSystem.out.println();\n\t\t\n\t\tint[] query3Values = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tquery3Values[i] = i+2*minTandemStart[i];\n\t\t}\n\t\tquery3RMQ = new RMQ(query3Values);\n\t\t\n\t\tint[][] pref = new int[26][n];\n\t\tfor(int i = n-1; i >= 0; i--) {\n\t\t\tfor(int j = 0; j < 26 && i+1 < n; j++) pref[j][i] = pref[j][i+1];\n\t\t\tpref[str.charAt(i)-'a'][i]++;\n\t\t}\n\t\t\n\t\tint Q = fs.nextInt();\n\t\tfor(int qq = 1; qq <= Q; qq++) {\n\t\t\tint L = fs.nextInt()-1, R = fs.nextInt()-1;\n\t\t\t\n\t\t\t//case -1\n\t\t\tboolean good = false;\n\t\t\tfor(int i = 0; i < 26; i++) {\n\t\t\t\tint sum = pref[i][L];\n\t\t\t\tif(R + 1 < n) sum -= pref[i][R+1];\n\t\t\t\tif(sum > 1) good = true;\n\t\t\t}\n\t\t\tif(!good) {\n\t\t\t\tout.println(-1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 1:\n\t\t\tboolean ans1 = false;\n\t\t\tint N = R-L+1;\n\t\t\tfor(int div = 1; div * div <= N; div++) {\n\t\t\t\tif(N % div != 0) continue;\n\t\t\t\tif(!primes[N/div]) continue;\n\t\t\t\t\n\t\t\t\tif(check(L, R, div)) ans1 = true;\n\t\t\t\telse if(primes[div] && check(L, R, N/div)) ans1 = true;\n\t\t\t\tif(ans1) break;\n\t\t\t}\n\t\t\tif(ans1) {\n\t\t\t\tout.println(1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 2:\n\t\t\tboolean ans2 = false;\n\t\t\tif(minTandemStart[L] != oo && L+minTandemStart[L]*2-1 <= R) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(minTandemEnd[R] != oo && R-minTandemEnd[R]*2+1 >= L) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(isBorder(L, R)) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(ans2) {\n\t\t\t\tout.println(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 3:\n\t\t\tboolean ans3 = false;\n\t\t\t{ //first character\n\t\t\t\tint idx = str.charAt(L)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //last character\n\t\t\t\tint idx = str.charAt(R)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //BAAC\n\t\t\t\tint min = query3RMQ.query(L, R);\n\t\t\t\tif(min <= R) ans3 = true;\n\t\t\t}\n\t\t\tif(ans3) {\n\t\t\t\tout.println(3);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(4);\n\t\t}\n\n\t\tout.close();\n\t}\n\t\n\tboolean check(int L, int R, int div) {\n\t\tint minPos = rsa[L], maxPos = rsa[L];\n\t\tfor(int j = L+div; j <= R; j += div) {\n\t\t\tminPos = Math.min(minPos, rsa[j]);\n\t\t\tmaxPos = Math.max(maxPos, rsa[j]);\n\t\t}\n\t\tint lcp = lcpRMQ.query(minPos, maxPos-1);\n\t\tif(lcp >= div) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tboolean isBorder(int L, int R) {\n\t\tfor(int len = 1; len < SQRT; len++) {\n\t\t\tint ptsTo = R-len+1;\n\t\t\tif(ptsTo <= L+len-1) continue;\n\t\t\tint min = Math.min(rsa[L], rsa[ptsTo]);\n\t\t\tint max = Math.max(rsa[L], rsa[ptsTo]);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp >= len) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tint st = Math.max(0, rsa[L]-SQRT-1);\n\t\tint en = Math.min(sa.length-1, rsa[L]+SQRT+1);\n\t\tint him = rsa[L];\n\t\t\n\t\tfor(int i = st; i <= en; i++) {\n\t\t\tint idx = sa[i];\n\t\t\tif(L <= idx && idx <= R) {}\n\t\t\telse continue;\n\t\t\tif(idx+SQRT-1 > R) continue;\n\t\t\tint min = Math.min(i, him);\n\t\t\tint max = Math.max(i, him);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp < SQRT) continue;\n\t\t\tint to = L + SQRT-1;\n\t\t\tif(to <= idx) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tclass RMQ {\n\t\tint[] vs;\n\t\tint[][] lift;\n\n\t\tpublic RMQ(int[] vs) {\n\t\t\tthis.vs = vs;\n\t\t\tint n = vs.length;\n\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 2;\n\t\t\tlift = new int[maxlog][n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlift[0][i] = vs[i];\n\t\t\tint lastRange = 1;\n\t\t\tfor (int lg = 1; lg < maxlog; lg++) {\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tlift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, n - 1)]);\n\t\t\t\t}\n\t\t\t\tlastRange *= 2;\n\t\t\t}\n\t\t}\n\n\t\tpublic int query(int low, int hi) {\n\t\t\tif(hi < low) return 0;\n\t\t\tint range = hi - low + 1;\n\t\t\tint exp = Integer.highestOneBit(range);\n\t\t\tint lg = Integer.numberOfTrailingZeros(exp);\n\t\t\treturn Math.min(lift[lg][low], lift[lg][hi - exp + 1]);\n\t\t}\n\t}\n\n\tclass FastSuffixArray {\n\t\tpublic int[] suffixArray(char[] S) {\n\t\t\tint n = S.length;\n\t\t\tInteger[] order = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\torder[i] = n - 1 - i;\n\n\t\t\tArrays.sort(order, (a, b) -> Character.compare(S[a], S[b]));\n\n\t\t\tint[] sa = new int[n];\n\t\t\tint[] classes = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tsa[i] = order[i];\n\t\t\t\tclasses[i] = S[i];\n\t\t\t}\n\n\t\t\tfor (int len = 1; len < n; len *= 2) {\n\t\t\t\tint[] c = classes.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tclasses[sa[i]] = i > 0 && c[sa[i - 1]] == c[sa[i]] && sa[i - 1] + len < n && c[sa[i - 1] + len / 2] == c[sa[i] + len / 2] ? classes[sa[i - 1]] : i;\n\t\t\t\t}\n\t\t\t\tint[] cnt = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tcnt[i] = i;\n\t\t\t\tint[] s = sa.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tint s1 = s[i] - len;\n\t\t\t\t\tif (s1 >= 0)\n\t\t\t\t\t\tsa[cnt[classes[s1]]++] = s1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn sa;\n\t\t}\n\n\t\tpublic int[] lcp(int[] sa, char[] s) {\n\t\t\tint n = sa.length;\n\t\t\tint[] rank = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\trank[sa[i]] = i;\n\t\t\tint[] lcp = new int[n - 1];\n\t\t\tfor (int i = 0, h = 0; i < n; i++) {\n\t\t\t\tif (rank[i] < n - 1) {\n\t\t\t\t\tfor (int j = sa[rank[i] + 1]; Math.max(i, j) + h < s.length && s[i + h] == s[j + h]; ++h)\n\t\t\t\t\t\t;\n\t\t\t\t\tlcp[rank[i]] = h;\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t--h;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn lcp;\n\t\t}\n\t}\n\n\tclass TandemRepeats {\n\t\tint[] min;\n\t\tTandemRepeats(String str) {\n\t\t\tlist = new ArrayList<>();\n\t\t\tfindRepetitions(str, 0, str.length()-1);\n\t\t\tCollections.sort(list);\n\t\t\tmin = new int[str.length()];\n\t\t\tArrays.fill(min, oo);\n\n\t\t\tTreeMap map = new TreeMap<>();\n\t\t\tint ptr = 0;\n\t\t\tfor(int i = 0; i < str.length(); i++) {\n\t\t\t\twhile(ptr < list.size()) {\n\t\t\t\t\tEvent now = list.get(ptr);\n\t\t\t\t\tif(now.pos <= i) {\n\t\t\t\t\t\tif(now.type == 0) add(map, now.val);\n\t\t\t\t\t\telse rem(map, now.val);\n\t\t\t\t\t\tptr++;\n\t\t\t\t\t} else break;\n\t\t\t\t}\n\t\t\t\tif(!map.isEmpty())\n\t\t\t\t\tmin[i] = Math.min(min[i], map.firstKey());\n\t\t\t}\n\t\t}\n\n\t\tArrayList list;\n\t\t//Main-Lorentz algorithm\n\t\tvoid findRepetitions(String str, int L, int R) {\n\t\t\tint n = R-L+1;\n\t\t\tif(n < 2 || R < L) return;\n\n\t\t\tString u = str.substring(0, n/2);\n\t\t\tString v = str.substring(n/2);\n\t\t\tfindRepetitions(u, L, L+u.length()-1); findRepetitions(v, L+u.length(), R);\n\n\t\t\tint[] z1 = zValues(reverse(u));\n\t\t\tint[] z2 = zValues(v + \"#\" + u);\n\t\t\tint[] z3 = zValues(reverse(u) + \"#\" + reverse(v));\n\t\t\tint[] z4 = zValues(v);\n\n\t\t\tint uLen = u.length(), vLen = v.length();\n\t\t\tfor(int cntr = 0; cntr < n; cntr++) {\n\t\t\t\tint totLen, k1, k2;\n\t\t\t\tif(cntr < uLen) {\n\t\t\t\t\ttotLen = uLen-cntr;\n\t\t\t\t\tk1 = getIdx(z1, uLen-cntr);\n\t\t\t\t\tk2 = getIdx(z2, vLen+1+cntr);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 0);\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 0);\n\t\t\t\t\t\tint start = Math.max(L, L+cntr-max);\n\t\t\t\t\t\tint end = Math.min(L+cntr-1, L+cntr-min);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttotLen = cntr-uLen+1;\n\t\t\t\t\tk1 = getIdx(z3, uLen + 1 + vLen - 1 - (cntr - uLen));\n\t\t\t\t\tk2 = getIdx(z4, (cntr - uLen) + 1);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 1);\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 1);\n\t\t\t\t\t\tint start = Math.max(L, L+n/2-1 - max + 1);\n\t\t\t\t\t\tint end = Math.min(L+n/2-1, L+n/2-1-min+1);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tint find(int k1, int k2, int len, boolean small, int lim) {\n\t\t\tint lo = lim, hi = k1, res = 0;\n\t\t\tfor(int bs = 0; bs < 50 && lo <= hi; bs++) {\n\t\t\t\tint mid = (lo+hi)/2;\n\t\t\t\tint v = len-mid;\n\t\t\t\tif(v < 0) { //too much\n\t\t\t\t\thi = mid-1;\n\t\t\t\t}\n\t\t\t\telse if(v > k2) { //too little\n\t\t\t\t\tlo = mid+1;\n\t\t\t\t}\n\t\t\t\telse { //great\n\t\t\t\t\tres = mid;\n\t\t\t\t\tif(small) hi = mid-1;\n\t\t\t\t\telse lo = mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tclass Event implements Comparable {\n\t\t\tint type, pos, val;\n\t\t\tEvent(int t, int p, int v) {\n\t\t\t\ttype = t; val = v;\n\t\t\t\tpos = p;\n\t\t\t}\n\t\t\tpublic int compareTo(Event e) {\n\t\t\t\tint comp = Integer.compare(pos, e.pos);\n\t\t\t\tif(comp == 0) comp = Integer.compare(e.type, type);\n\t\t\t\treturn comp;\n\t\t\t}\n\t\t\tpublic String toString() {\n\t\t\t\treturn String.format(\"Pos = %d Type = %d V = %d\", pos, type, val);\n\t\t\t}\n\t\t}\n\n\t\tint getIdx(int[] a, int i) {\n\t\t\tif(i >= 0 && i < a.length) return a[i];\n\t\t\treturn 0;\n\t\t}\n\n\t\tint[] zValues(String string) {\n\t\t\tint n = string.length(); char[] s = string.toCharArray();\n\t\t\tint[] z = new int[n]; z[0] = n;\n\t\t\tint L = 0, R = 0;\n\t\t\tint[] left = new int[n], right = new int[n];\n\t\t\tfor(int i = 1; i < n; ++i) {\n\t\t\t\tif(i > R) {\n\t\t\t\t\tL = R = i;\n\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t} else {\n\t\t\t\t\tint k = i-L;\n\t\t\t\t\tif(z[k] < R-i+1) z[i] = z[k];\n\t\t\t\t\telse {\n\t\t\t\t\t\tL = i;\n\t\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tleft[i] = L; right[i] = R;\n\t\t\t}\n\t\t\treturn z;\n\t\t}\n\n\n\t\tvoid add(TreeMap map, int x) {\n\t\t\tmap.put(x, map.getOrDefault(x, 0)+1);\n\t\t}\n\t\tvoid rem(TreeMap map, int x) {\n\t\t\tint fr = map.get(x)-1;\n\t\t\tif(fr == 0) map.remove(x);\n\t\t\telse map.put(x, fr);\n\t\t}\n\t}\n\t\n\tvoid doPrimes() {\n\t\tprimes = new boolean[200200];\n\t\tArrays.fill(primes, true);\n\t\tprimes[0] = primes[1] = false;\n\t\tfor(int i = 2; i < primes.length; i++) {\n\t\t\tif(!primes[i]) continue;\n\t\t\tfor(int j = i+i; j < primes.length; j += i) primes[j] = false;\n\t\t}\n\t}\n\t\n\tString reverse(String s) {\n\t\treturn new StringBuilder(s).reverse().toString();\n\t}\n\tint[] reverse(int[] a) {\n\t\tint n = a.length;\n\t\tint[] res = new int[n];\n\t\tfor(int i = 0, j = n-1; i < n; i++, j--) {\n\t\t\tres[i] = a[j];\n\t\t}\n\t\treturn res;\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tString next() {\n\t\t\tif(st.hasMoreTokens()) return st.nextToken();\n\t\t\ttry { st = new StringTokenizer(br.readLine()); } catch (Exception e) {}\n\t\t\treturn next();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ecd32f8a53a0b6f085bdc6611a4c99e3", "src_uid": "bc839e9a025a5d83e2c85fb1e224c175", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E {\n\n\tprivate static long MOD = 998244353;\n\t\n\tprivate static long[][] cache;\n\tprivate static long dp(int n, int x, int idx, int used) {\n\t\t// impossible\n\t\tif (used == 0 && idx + x > n) {\n\t\t\treturn 0;\n\t\t}\n\t\t// base case\n\t\tif (idx == n) {\n\t\t\treturn used;\n\t\t}\n\t\t// seen before\n\t\tif (cache[idx][used] > -1) {\n\t\t\treturn cache[idx][used];\n\t\t}\n\t\t// recursive case\n\t\tlong ans = 0;\n\t\tfor (int diff = 1; diff <= x && idx + diff <= n; ++diff) {\n\t\t\tint nextUsed = used;\n\t\t\tif (diff == x)\n\t\t\t\tnextUsed = 1;\n\t\t\tans += dp(n, x, idx + diff, nextUsed);\n\t\t\tans %= MOD;\n\t\t}\n\t\treturn cache[idx][used] = ans;\n\t}\n\t\n\tprivate static long f(int n, int x) {\n\t\tif (x <= 0)\n\t\t\treturn 0;\n\t\tcache = new long[n][2];\n\t\tfor (int i = 0; i < cache.length; ++i)\n\t\t\tfor (int j = 0; j < cache[i].length; ++j)\n\t\t\t\tcache[i][j] = -1;\n\t\treturn dp(n, x, 0, 0);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt() - 1;\n\t\tlong ans = 0;\n\t\tfor (int i = 1; i <= k && i <= n; ++i) {\n\t\t\tfor (int j = 1; j <= k/i; ++j) {\n\t\t\t\tans += 2*f(n, i)*f(n, j);\n\t\t\t\tans %= MOD;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "580e2c3430277962137a079a2b425c78", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n static long TIME_START, TIME_END;\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n // Scanner sc = new Scanner(new FileInputStream(\"Test.in\"));\n PrintWriter pw = new PrintWriter(System.out);\n // PrintWriter pw = new PrintWriter(new FileOutputStream(\"Test.out\"));\n // PrintWriter pw = new PrintWriter(new FileOutputStream(\"Test.in\"));\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.out.println(\"Memory increased:\" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );\n System.out.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n public static class Task {\n\n public long[][] dp;\n public long[][] subdp;\n public long[] sef;\n\n public long power(long a, int b) {\n if (b == 0) return 1;\n if (b % 2 == 0) return power(a * a % mod, b >> 1);\n return a * power(a * a % mod, b >> 1) % mod;\n }\n\n public void calc(int n) {\n dp = new long[n + 1][n + 1];\n subdp = new long[n + 1][n + 1];\n sef = new long[n + 1];\n long t = 1;\n for (int i = 0; i < n + 1; i++) {\n sef[i] = t;\n t *= 2; t %= mod;\n }\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= n; j++) {\n search(i, j);\n }\n }\n subdp[n][1] = dp[n][1];\n for (int i = 1; i < n; i++) {\n subdp[n][i + 1] = dp[n][i + 1] - dp[n][i];\n }\n }\n\n public long search(int n, int k) {\n if (dp[n][k] != 0) {\n return dp[n][k];\n }\n if (k >= n) {\n return dp[n][k] = sef[n];\n }\n long s = 0;\n for (int i = 1; i <= k; i++) {\n s += search(n - i, k);\n if (s >= mod) s -= mod;\n }\n return dp[n][k] = s;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n int n = sc.nextInt();\n int k = sc.nextInt();\n calc(n);\n long sum = 0;\n long inv2 = power(2, mod - 2);\n for (int i = 1; i <= n; i++) {\n int otherlen = k % i == 0 ? k / i - 1 : k / i;\n if (otherlen > n) otherlen = n;\n sum += subdp[n][i] * dp[n][otherlen] % mod * inv2 % mod;\n if (sum >= mod) sum -= mod;\n }\n pw.println(sum);\n }\n\n int mod = 998244353;\n\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}\n\n public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}\n\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n public long nextLong() throws IOException {return Long.parseLong(next());}\n\n public String nextLine() throws IOException {return br.readLine();}\n\n public double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n public boolean ready() throws IOException {return br.ready();}\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50c283e22470b836a35ceea4ece93f50", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "//make sure to make new file!\nimport java.io.*;\nimport java.util.*;\n\npublic class E1027{\n \n public static long MOD = 998244353;\n \n public static void main(String[] args)throws IOException{\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n \n StringTokenizer st = new StringTokenizer(f.readLine());\n \n int n = Integer.parseInt(st.nextToken());\n double m = Double.parseDouble(st.nextToken());\n \n if(m == 1.0){\n out.println(\"0\");\n out.close();\n return;\n }\n \n \n long[] array = new long[n+1]; //number of ways such that max chunk is n\n array[0] = 0;\n array[1] = 1;\n \n for(int i = 2; i <= n; i++){\n long[][][] dp = new long[n][i][2];\n \n dp[0][0][0] = 1;\n \n for(int k = 0; k < n-1; k++){\n for(int j = 0; j < i; j++){\n for(int h = 0; h < 2; h++){\n //simulate adding same color\n if(ji) dp[i][j]=dp[i-1][j]*2;\n\t\t\t\t\telse {//j-1,j-2,...,j-k;\n\t\t\t\t\t\tdp[i][j]=2*dp[i-1][j]-(i-j-1<0?1:dp[i-j-1][j]);\n\t\t\t\t\t\tdp[i][j]%=mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong[] f=new long[n+1];\n\t\tlong ret=0;\n\t\tfor(int i=1;i<=n;i++) {\n\t\t\tf[i]=(dp[n-1][i]-dp[n-1][i-1]+mod)%mod;\n\t\t}\n\t\tfor(int i=1;i<=n;i++) {\n\t\t\tfor(int j=1;i*j= 0; k--) {\n if (dp[k] == 1) {\n dp[k + i] = 1;\n }\n }\n }\n }\n // System.out.println(w);\n for(int i = (int) w; i >= 0; i--) {\n if (dp[i] == 1) {\n return i;\n }\n }\n return 0;\n }\n\n private static void reduce() {\n for (int i = 1; i <= 8; i++) {\n if (cnt[i] > 20) {\n long toTake = cnt[i] - 20;\n if (w - toTake * i >= 1000) {\n w -= toTake * i;\n cnt[i] = 20;\n } else {\n long diff = w - 1000;\n long take = diff / i + 1;\n cnt[i] -= take;\n w -= take * i;\n }\n }\n }\n }\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n w = input.nextLong();\n cnt = new long[9];\n for (int i = 1; i <= 8; i++) {\n cnt[i] = input.nextLong();\n all += 1L * i * cnt[i];\n }\n if (all <= w) {\n System.out.println(all);\n return;\n }\n long oldW = w;\n if (w > 1000) {\n reduce();\n }\n System.out.println(oldW - w + solveDp());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "52308907e02111319ed989a9117994a2", "src_uid": "8097e10157320524c0faed56f2bc4880", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.util.*;\n//import javafx.util.*;\nimport java.io.*;\n\npublic class Prg10 {\n\n PrintWriter pw = new PrintWriter(System.out);\n Random rnd = new Random();\n int a;\n long o =0, s, stt;\n\n void run() {\n s = nl();\n long[] m = new long[8];\n for(int q=0; q<8; q++) m[q] = nl();\n stt = System.currentTimeMillis();\n rec(m, 0);\n pw.print(o);\n pw.flush();\n }\n\n void rec(long[] m, long cur){\n if(System.currentTimeMillis()-stt>500) return;\n o = Math.max(o, cur);\n for(int q=0; q<8; q++){\n if((s-cur)%(q+1)>0) continue;\n long need = (s-cur)/(q+1);\n if(m[q]>=need){\n o = s;\n return;\n }\n }\n for(int q=7; q>=0; q--){\n long can = Math.min(m[q], (s-cur)/(q+1));\n for(long w=Math.max(1, can-10); w<=can; w++){\n m[q]-=w;\n rec(m, cur+(q+1)*w);\n m[q]+=w;\n }\n }\n }\n\n static class PyraSort {\n\n private static int heapSize;\n\n public static void sort(long[] a) {\n buildHeap(a);\n while (heapSize > 1) {\n swap(a, 0, heapSize - 1);\n heapSize--;\n heapify(a, 0);\n }\n }\n\n private static void buildHeap(long[] a) {\n heapSize = a.length;\n for (int i = a.length / 2; i >= 0; i--) {\n heapify(a, i);\n }\n }\n\n private static void heapify(long[] a, int i) {\n int l = 2 * i + 2;\n int r = 2 * i + 1;\n int largest = i;\n if (l < heapSize && a[i] < a[l]) {\n largest = l;\n }\n if (r < heapSize && a[largest] < a[r]) {\n largest = r;\n }\n if (i != largest) {\n swap(a, i, largest);\n heapify(a, largest);\n }\n }\n\n private static void swap(long[] a, int i, int j) {\n a[i] ^= a[j] ^= a[i];\n a[j] ^= a[i];\n }\n }\n\n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n public void run() {\n new Prg10().run();\n }\n }, \"1\", 1 << 28).start();\n }\n\n InputStream is = System.in;\n private byte[] inbuf = new byte[1<<16];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte()\n {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns()\n {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private String nline(){\n int b = readByte();\n StringBuilder sb = new StringBuilder();\n while (b!=10) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n)\n {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m)\n {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n)\n {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni()\n {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl()\n {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ec9cc66b2741261c44680e44b9e9bfa4", "src_uid": "8097e10157320524c0faed56f2bc4880", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.fill;\n\npublic class Main {\n FastScanner in;\n PrintWriter out;\n\n private void solve() throws IOException {\n long W = in.nextLong();\n long[] cnt = new long[9];\n for (int i = 1; i <= 8; i++)\n cnt[i] = in.nextLong();\n\n int lcm = 840;\n long[][] dp = new long[9][lcm];\n for (int i = 0; i < 9; i++)\n fill(dp[i], -1);\n dp[0][0] = 0;\n for (int i = 1; i <= 8; i++) {\n for (int j = 0; j < lcm; j++) {\n if (dp[i - 1][j] != -1) {\n for (int k = 0; k < min(lcm / i, cnt[i] + 1); k++) {\n if (dp[i - 1][j] * lcm + j + k * i <= W) {\n dp[i][(j + k * i) % lcm] = max(dp[i][(j + k * i) % lcm], dp[i - 1][j] + (j + k * i) / lcm + min((W - (dp[i - 1][j] * lcm + j + k * i)) / lcm, (cnt[i] - k) / (lcm / i)));\n }\n }\n }\n }\n }\n\n long ans = 0;\n for (int i = 0; i < lcm; i++) {\n if (dp[8][i] != -1) {\n ans = max(ans, dp[8][i] * lcm + i);\n }\n }\n out.println(ans);\n }\n\n class FastScanner {\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n boolean hasNext() throws IOException {\n return br.ready() || (st != null && st.hasMoreTokens());\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n boolean hasNextLine() throws IOException {\n return br.ready();\n }\n }\n\n private void run() throws IOException {\n in = new FastScanner(System.in); // new FastScanner(new FileInputStream(\".in\"));\n out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(\".out\"));\n\n solve();\n\n out.flush();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66d23d11c5f481bccabb3b818ab1193d", "src_uid": "8097e10157320524c0faed56f2bc4880", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.util.*;\n//import javafx.util.*;\nimport java.io.*;\n\npublic class Prg10 {\n\n PrintWriter pw = new PrintWriter(System.out);\n Random rnd = new Random();\n int a;\n long o =0, s, stt;\n\n void run() {\n //a = ni();\n s = nl();\n long sum=0;\n long[] m = new long[8];\n for(int q=0; q<8; q++) {\n m[q] = nl();\n sum+=m[q]*(q+1);\n }\n if(sum<=s){\n System.out.println(sum);\n return;\n }\n stt = System.currentTimeMillis();\n rec(m, 0);\n pw.print(o);\n pw.flush();\n }\n\n void rec(long[] m, long cur){\n if(o==s) return;\n if(System.currentTimeMillis()-stt>1400) return;\n o = Math.max(o, cur);\n for(int q=0; q<8; q++){\n if((s-cur)%(q+1)>0) continue;\n long need = (s-cur)/(q+1);\n if(m[q]>=need){\n o = s;\n return;\n }\n }\n for(long q=7; q>=0; q--){\n if(m[(int)q]==0) continue;\n if(o==s) return;\n long can = Math.min(m[(int)q], (s-cur)/(q+1));\n if(can==0) continue;\n for(long w=Math.max(1, can-10), i=0; i<10 && w<=can; w++, i++){\n m[(int)q]-=w;\n rec(m, cur+(q+1)*w);\n m[(int)q]+=w;\n }\n }\n }\n\n static class PyraSort {\n\n private static int heapSize;\n\n public static void sort(long[] a) {\n buildHeap(a);\n while (heapSize > 1) {\n swap(a, 0, heapSize - 1);\n heapSize--;\n heapify(a, 0);\n }\n }\n\n private static void buildHeap(long[] a) {\n heapSize = a.length;\n for (int i = a.length / 2; i >= 0; i--) {\n heapify(a, i);\n }\n }\n\n private static void heapify(long[] a, int i) {\n int l = 2 * i + 2;\n int r = 2 * i + 1;\n int largest = i;\n if (l < heapSize && a[i] < a[l]) {\n largest = l;\n }\n if (r < heapSize && a[largest] < a[r]) {\n largest = r;\n }\n if (i != largest) {\n swap(a, i, largest);\n heapify(a, largest);\n }\n }\n\n private static void swap(long[] a, int i, int j) {\n a[i] ^= a[j] ^= a[i];\n a[j] ^= a[i];\n }\n }\n\n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n public void run() {\n new Prg10().run();\n }\n }, \"1\", 1 << 28).start();\n }\n\n InputStream is = System.in;\n private byte[] inbuf = new byte[1<<16];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte()\n {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns()\n {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private String nline(){\n int b = readByte();\n StringBuilder sb = new StringBuilder();\n while (b!=10) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n)\n {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m)\n {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n)\n {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni()\n {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl()\n {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66fabce67239b1ccb68e98e981b249cc", "src_uid": "8097e10157320524c0faed56f2bc4880", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author heifrank\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 CF747F solver = new CF747F();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CF747F {\n String s = \"0123456789abcdef\";\n int[] av = new int[16];\n int[][] dp = new int[25][16];\n int[][] C = new int[25][25];\n\n public CF747F() {\n for (int i = 0; i < 25; i++)\n C[i][0] = 1;\n for (int i = 1; i < 25; i++) {\n for (int j = 1; j <= i; j++) {\n C[i][j] = C[i - 1][j - 1] + C[i - 1][j];\n }\n }\n }\n\n int cal(int len) {\n if (len == 0) return 1;\n for (int i = 0; i < 16; i++)\n dp[0][i] = 1;\n for (int i = 1; i <= len; i++) {\n dp[i][0] = i <= av[0] ? 1 : 0;\n for (int j = 1; j < 16; j++) {\n dp[i][j] = dp[i][j - 1];\n for (int kk = 1; kk <= av[j] && kk <= i; kk++) {\n dp[i][j] += dp[i - kk][j - 1] * C[i][kk];\n }\n }\n }\n return dp[len][15];\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int k = in.nextInt(), t = in.nextInt();\n Arrays.fill(av, t);\n int len, sum = 0;\n for (len = 1; ; len++) {\n boolean find = false;\n for (int fir = 1; fir < 16; fir++) {\n av[fir]--;\n int m = cal(len - 1);\n if (sum + m >= k) {\n find = true;\n out.print(s.charAt(fir));\n break;\n }\n sum += m;\n av[fir]++;\n }\n if (find == true) break;\n }\n --len;\n while (--len >= 0) {\n int i;\n for (i = 0; i < 16; i++) {\n if (av[i] > 0) {\n av[i]--;\n int m = cal(len);\n if (sum + m >= k) {\n out.print(s.charAt(i));\n break;\n }\n av[i]++;\n sum += m;\n }\n }\n }\n out.println();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "979cb1686f94f6c479aea881c30bdb27", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.FileOutputStream;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.FileNotFoundException;\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) {\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\n static class TaskF {\n static boolean debug = false;\n int numberNumber;\n int t;\n long[][] bin = IntegerUtils.generateBinomialCoefficients(100);\n\n static {\n if (debug) {\n try {\n FileOutputStream f = new FileOutputStream(\"file.txt\");\n System.setErr(new PrintStream(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n numberNumber = in.readInt();\n t = in.readInt();\n\n// t = 1;\n\n // HashMap answers = new HashMap<>();\n//\n// for (int i = 1, cnt = 0; cnt < 1e5; i++) {\n// int[] cntTake = new int[16];\n// for (char c : String.format(\"%x\", i).toCharArray()) {\n// ++cntTake[Integer.parseInt(\"\" + c, 16)];\n// }\n// boolean ok = true;\n// for (int c : cntTake) {\n// ok &= c <= t;\n// }\n// if (ok) {\n// ++cnt;\n// String answer = String.format(\"%x\", i);\n// answers.put(cnt, answer);\n// System.err.println(cnt + \" = \" + answer);\n// System.err.flush();\n// }\n// }\n\n//\n// for (int _numberNumber = 1; ; _numberNumber++) {\n// numberNumber = _numberNumber;\n int wordLength = 1;\n for (; ; wordLength++) {\n long[][] dp = new long[16][wordLength + 1];\n\n for (int length = 0; length <= wordLength; length++) {\n for (int ch = 0; ch < 16; ch++) {\n if (length == 0) {\n dp[ch][length] = 1;\n } else if (ch == 0) {\n if (length <= t) {\n dp[ch][length] = bin[wordLength - 1][length];\n }\n } else {\n dp[ch][length] += dp[ch - 1][length];\n for (int c = 1; c <= Math.min(length, t); c++) {\n dp[ch][length] += bin[wordLength - length + c][c] * dp[ch - 1][length - c];\n }\n }\n }\n }\n\n System.err.println(\"wordLength, dp: \" + wordLength + \" \" + dp[15][wordLength]);\n System.err.flush();\n if (dp[15][wordLength] < numberNumber) {\n numberNumber -= dp[15][wordLength];\n } else {\n// out.printLine(\"wordLength: \" + wordLength);\n break;\n }\n }\n\n StringBuilder ans = new StringBuilder();\n int[] maxCnt = new int[16];\n Arrays.fill(maxCnt, t);\n for (int pos = 0; pos < wordLength; pos++) {\n boolean addCh = false;\n for (int ch = 0; ch < 16; ch++) {\n if (pos == 0 && ch == 0) {\n continue;\n }\n if (maxCnt[ch] == 0) {\n continue;\n }\n --maxCnt[ch];\n long dp = getDp(wordLength - pos - 1, maxCnt);\n if (numberNumber <= dp) {\n ans.append(String.format(\"%x\", ch));\n addCh = true;\n break;\n } else {\n ++maxCnt[ch];\n numberNumber -= dp;\n }\n }\n if (!addCh) {\n throw new RuntimeException(\"no addCh\");\n// out.printLine(\"no add ch at pos=\" + pos, \" : \", _numberNumber, answers.get(_numberNumber), ans);\n// return;\n }\n }\n// if (!answers.get(_numberNumber).equals(ans.toString())) {\n// out.printLine(\"FUCK:\", _numberNumber, answers.get(_numberNumber), ans);\n// return;\n// }\n out.printLine(ans);\n// }\n }\n\n private long getDp(int wordLength, int[] maxCnt) {\n long[][] dp = new long[16][wordLength + 1];\n for (int length = 0; length <= wordLength; length++) {\n for (int ch = 0; ch < 16; ch++) {\n if (length == 0) {\n dp[ch][length] = 1;\n } else {\n if (ch != 0) {\n dp[ch][length] += dp[ch - 1][length];\n }\n for (int cnt = 1; cnt <= Math.min(length, maxCnt[ch]); cnt++) {\n if (ch == 0) {\n if (length == cnt) {\n dp[ch][length] += bin[wordLength][cnt];\n }\n } else {\n dp[ch][length] += bin[wordLength - length + cnt][cnt] * dp[ch - 1][length - cnt];\n }\n }\n }\n }\n }\n return dp[15][wordLength];\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if ((c < '0') || (c > '9')) {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return (c == ' ') || (c == '\\n') || (c == '\\r') || (c == '\\t') || (c == -1);\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class IntegerUtils {\n public static long[][] generateBinomialCoefficients(int n) {\n long[][] result = new long[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n result[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n result[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n }\n }\n return result;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void 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}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cb26daaeff1b3ab5927442fac4468806", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.FileOutputStream;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.FileNotFoundException;\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) {\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\n static class TaskF {\n static boolean debug = true;\n int numberNumber;\n int t;\n long[][] bin = IntegerUtils.generateBinomialCoefficients(100);\n\n static {\n if (debug) {\n try {\n FileOutputStream f = new FileOutputStream(\"file.txt\");\n System.setErr(new PrintStream(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n numberNumber = in.readInt();\n t = in.readInt();\n\n// t = 1;\n\n // HashMap answers = new HashMap<>();\n//\n// for (int i = 1, cnt = 0; cnt < 1e5; i++) {\n// int[] cntTake = new int[16];\n// for (char c : String.format(\"%x\", i).toCharArray()) {\n// ++cntTake[Integer.parseInt(\"\" + c, 16)];\n// }\n// boolean ok = true;\n// for (int c : cntTake) {\n// ok &= c <= t;\n// }\n// if (ok) {\n// ++cnt;\n// String answer = String.format(\"%x\", i);\n// answers.put(cnt, answer);\n// System.err.println(cnt + \" = \" + answer);\n// System.err.flush();\n// }\n// }\n\n//\n// for (int _numberNumber = 1; ; _numberNumber++) {\n// numberNumber = _numberNumber;\n int wordLength = 1;\n for (; ; wordLength++) {\n long[][] dp = new long[16][wordLength + 1];\n\n for (int length = 0; length <= wordLength; length++) {\n for (int ch = 0; ch < 16; ch++) {\n if (length == 0) {\n dp[ch][length] = 1;\n } else if (ch == 0) {\n if (length <= t) {\n dp[ch][length] = bin[wordLength - 1][length];\n }\n } else {\n dp[ch][length] += dp[ch - 1][length];\n for (int c = 1; c <= Math.min(length, t); c++) {\n dp[ch][length] += bin[wordLength - length + c][c] * dp[ch - 1][length - c];\n }\n }\n }\n }\n\n System.err.println(\"wordLength, dp: \" + wordLength + \" \" + dp[15][wordLength]);\n System.err.flush();\n if (dp[15][wordLength] < numberNumber) {\n numberNumber -= dp[15][wordLength];\n } else {\n// out.printLine(\"wordLength: \" + wordLength);\n break;\n }\n }\n\n StringBuilder ans = new StringBuilder();\n int[] maxCnt = new int[16];\n Arrays.fill(maxCnt, t);\n for (int pos = 0; pos < wordLength; pos++) {\n boolean addCh = false;\n for (int ch = 0; ch < 16; ch++) {\n if (pos == 0 && ch == 0) {\n continue;\n }\n if (maxCnt[ch] == 0) {\n continue;\n }\n --maxCnt[ch];\n long dp = getDp(wordLength - pos - 1, maxCnt);\n if (numberNumber <= dp) {\n ans.append(String.format(\"%x\", ch));\n addCh = true;\n break;\n } else {\n ++maxCnt[ch];\n numberNumber -= dp;\n }\n }\n if (!addCh) {\n throw new RuntimeException(\"no addCh\");\n// out.printLine(\"no add ch at pos=\" + pos, \" : \", _numberNumber, answers.get(_numberNumber), ans);\n// return;\n }\n }\n// if (!answers.get(_numberNumber).equals(ans.toString())) {\n// out.printLine(\"FUCK:\", _numberNumber, answers.get(_numberNumber), ans);\n// return;\n// }\n out.printLine(ans);\n// }\n }\n\n private long getDp(int wordLength, int[] maxCnt) {\n long[][] dp = new long[16][wordLength + 1];\n for (int length = 0; length <= wordLength; length++) {\n for (int ch = 0; ch < 16; ch++) {\n if (length == 0) {\n dp[ch][length] = 1;\n } else {\n if (ch != 0) {\n dp[ch][length] += dp[ch - 1][length];\n }\n for (int cnt = 1; cnt <= Math.min(length, maxCnt[ch]); cnt++) {\n if (ch == 0) {\n if (length == cnt) {\n dp[ch][length] += bin[wordLength][cnt];\n }\n } else {\n dp[ch][length] += bin[wordLength - length + cnt][cnt] * dp[ch - 1][length - cnt];\n }\n }\n }\n }\n }\n return dp[15][wordLength];\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if ((c < '0') || (c > '9')) {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return (c == ' ') || (c == '\\n') || (c == '\\r') || (c == '\\t') || (c == -1);\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class IntegerUtils {\n public static long[][] generateBinomialCoefficients(int n) {\n long[][] result = new long[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n result[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n result[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n }\n }\n return result;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void 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}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f1b039dd1734fb2e81ec5e375ef99b7c", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author AsgarJ\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n int LEN;\n static final int DIGIT = 17;\n static int[] cnt = new int[DIGIT - 1];\n char[] res;\n int k;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n k = in.nextInt();\n int T = in.nextInt();\n Arrays.fill(cnt, T);\n\n if (k < 16) {\n out.println(getChar(k));\n return;\n }\n\n long[] counts = dp(13);\n LEN = getLength(counts, k);\n\n res = new char[LEN];\n\n int startIndex = 0;\n if (LEN > 10) startIndex = brute();\n\n int[] curCount = new int[]{0};\n for (int i = 1; i <= LEN - startIndex; i++) {\n bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);\n }\n\n out.println(res);\n }\n\n private int getLength(long[] counts, int k) {\n int LEN = 1;\n for (; LEN <= 13; LEN++) {\n if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;\n else if (LEN > cnt[0] && k > counts[LEN]) continue;\n else break;\n }\n return LEN;\n }\n\n private int brute() {\n k -= dp(LEN)[LEN - 1];\n if (LEN - 1 <= cnt[0]) k++;\n int ret = 3;\n for (int i = 0; i < ret; i++) {\n int digit = getNextDigit(i == 0 ? 0 : -1);\n for (; digit < DIGIT - 1 && k > 0; digit = getNextDigit(digit)) {\n cnt[digit]--;\n int temp = (int) dp(LEN - i)[LEN - i - 1];\n if (k > temp) {\n k -= temp;\n cnt[digit]++;\n continue;\n } else if (k == temp) {\n res[i++] = getChar(digit);\n for (; i < LEN; i++) {\n res[i] = getChar(getLastDigit());\n }\n return i;\n } else {\n res[i] = getChar(digit);\n break;\n }\n }\n }\n return ret;\n }\n\n private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {\n if (index == len) {\n cur[0]++;\n return;\n }\n for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {\n cnt[i]--;\n if (cur[0] < max) {\n res[index] = getChar(i);\n bruteForce(index + 1, cnt, res, len, max, cur);\n cnt[i]++;\n } else return;\n }\n }\n\n private int getNextDigit(int startDigit) {\n int i = startDigit + 1;\n for (; i < cnt.length && cnt[i] == 0; i++) ;\n return i;\n }\n\n private long[] dp(int len) {\n long[][] dp = new long[DIGIT][++len];\n dp[0][0] = 1;\n\n for (int i = 1; i < DIGIT; ++i) {\n for (int j = 0; j < len; ++j) {\n for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {\n for (int k = i - 1; k < i; k++) {\n dp[i][j] += dp[k][j - c] * comb(j, c);\n }\n }\n }\n }\n\n// System.out.printf(\"dp[15][%d]: \", len); print(dp[DIGIT - 1]);\n\n return dp[DIGIT - 1];\n }\n\n private char getChar(int digit) {\n return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);\n }\n\n private int getLastDigit() {\n int i;\n for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;\n cnt[i]--;\n return i;\n }\n\n private long comb(int n, int k) {\n long res = 1L;\n if (k < n)\n for (int i = 1; i <= k; i++) {\n res = res * (n - k + i) / i;\n }\n return res;\n }\n\n }\n\n static class InputReader extends BufferedReader {\n StringTokenizer tokenizer;\n\n public InputReader(InputStream inputStream) {\n super(new InputStreamReader(inputStream), 32768);\n }\n\n public InputReader(String filename) {\n super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(readLine());\n } catch (IOException e) {\n throw new RuntimeException();\n }\n }\n return tokenizer.nextToken();\n }\n\n public Integer nextInt() {\n return Integer.valueOf(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9851835bfa62c950c661b99b1f3a0f1e", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class F {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int K = 110;\n\tstatic final int N = 500_000;\n\n\tdouble[][] dp = new double[N][K];\n\tint[] par = new int[N];\n\n\tvoid solve() throws IOException {\n\t\tint q = nextInt();\n\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tArrays.fill(dp[i], 1);\n\n\t\tpar[0] = -1;\n\n\t\tint curV = 1;\n\n\t\twhile (q-- > 0) {\n\t\t\tint type = nextInt();\n\t\t\tint v = nextInt() - 1;\n\t\t\tif (type == 2) {\n\t\t\t\tdouble ret = 0;\n\t\t\t\tdouble[] ds = dp[v];\n\t\t\t\tfor (int i = 0; i < ds.length; i++) {\n\t\t\t\t\tdouble prob = ds[i];\n\t\t\t\t\tret += 1 - prob;\n\t\t\t\t}\n\t\t\t\tout.println(ret);\n\t\t\t} else {\n\t\t\t\tint u = curV++;\n\t\t\t\tpar[u] = v;\n\n\t\t\t\tdouble old = dp[v][0];\n\t\t\t\tdp[v][0] *= 0.5;\n\t\t\t\tv = par[v];\n\t\t\t\tu = par[u];\n\t\t\t\tint k = 1;\n\t\t\t\twhile (k < K && v != -1) {\n\t\t\t\t\t\n\t\t\t\t\tdouble nextOld = dp[v][k];\n\t\t\t\t\tdp[v][k] /= 0.5 * (1 + old);\n\t\t\t\t\tdp[v][k] *= 0.5 * (1 + dp[u][k - 1]);\n\t\t\t\t\t\n\t\t\t\t\tk++;\n\t\t\t\t\tv = par[v];\n\t\t\t\t\tu = par[u];\n\t\t\t\t\told = nextOld;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t}\n\n\tF() 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 F();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "82574ec3a07d42e1d04552c521583b1f", "src_uid": "55affe752cb214d1e4031a9e3972597b", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class E {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint[] p;\n\tdouble[][] dpEqLess;\n\tdouble[][] dpEqLessMul;\n\tint maxK = 50;\n\t\n\tpublic void solve() throws IOException {\n\t\tint q = in.nextInt();\n\t\tdpEqLess = new double[maxK][q];\n\t\tfor (int i = 0; i < maxK; i++) {\n\t\t\tdpEqLess[i][0] = 1;\n\t\t}\n\t\tp = new int[q];\n\t\tp[0] = -1;\n\t\tint cntV = 0;\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tint type = in.nextInt();\n\t\t\tint v = in.nextInt() - 1;\n\t\t\tif (type == 1) {\n\t\t\t\tint u = ++cntV;\n\t\t\t\tp[u] = v;\n\t\t\t\tfor (int j = 0; j < maxK; j++) {\n\t\t\t\t\tdpEqLess[j][u] = 1;\n\t\t\t\t}\n\t\t\t\tdouble prev = 1;\n\t\t\t\tfor (int j = 0; j < maxK; j++) {\n\t\t\t\t\tdouble val = dpEqLess[j][v];\n\t\t\t\t\tval /= prev;\t\n\t\t\t\t\tprev = dpEqLess[j][v]*0.5 + 0.5;\n\t\t\t\t\tval *= (0.5 + 0.5*(j - 1 >= 0 ? dpEqLess[j - 1][u] : 0));\n\t\t\t\t\tdpEqLess[j][v] = val;\n\t\t\t\t\t\n\t\t\t\t\tv = p[v];\n\t\t\t\t\tu = p[u];\n\t\t\t\t\tif (v == -1) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble res = 0;\n\t\t\t\tfor (int j = 1; j < maxK; j++) {\n\t\t\t\t\tres += j * (dpEqLess[j][v] - dpEqLess[j - 1][v]);\n\t\t\t\t}\n\t\t\t\tout.println(res);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new FastScanner();\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() {\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 (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\t}\n\n\tpublic static void main(String[] arg) {\n\t\tnew E().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "421fec4d6377ef5b4b874b4d5d9ea326", "src_uid": "55affe752cb214d1e4031a9e3972597b", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n final int MAX = 85;\n\n double[][] prob;\n int[] parent;\n int n;\n\n public void solve() {\n int q = in.nextInt();\n int[] t = new int[q], v = new int[q];\n n = 1;\n for (int i = 0; i < q; i++) {\n t[i] = in.nextInt();\n v[i] = in.nextInt() - 1;\n if (t[i] == 1) {\n n++;\n }\n }\n\n parent = new int[n];\n parent[0] = -1;\n prob = new double[n][MAX];\n Arrays.fill(prob[0], 1);\n int last = 0;\n for (int i = 0; i < q; i++) {\n if (t[i] == 1) {\n last++;\n parent[last] = v[i];\n }\n }\n\n last = 0;\n for (int i = 0; i < q; i++) {\n if (t[i] == 1) {\n last++;\n addVertex(last);\n } else {\n double result = 0;\n double[] pr = prob[v[i]];\n for (int j = 0; j < MAX; j++) {\n result += 1 - pr[j];\n }\n out.println(result);\n }\n }\n }\n\n private void addVertex(int v) {\n Arrays.fill(prob[v], 1);\n\n int p = parent[v];\n double last = 1;\n for (int i = 0; i < MAX; i++) {\n if (p == -1) {\n break;\n }\n double tmp = prob[p][i];\n prob[p][i] /= (0.5 + 0.5 * last);\n last = tmp;\n p = parent[p];\n }\n p = parent[v];\n\n last = 0;\n for (int i = 0; i < MAX; i++) {\n if (p == -1) {\n break;\n }\n prob[p][i] *= (0.5 + 0.5 * last);\n last = prob[p][i];\n p = parent[p];\n }\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new E().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c963e74c06e9ec7991478d61b9562d7", "src_uid": "55affe752cb214d1e4031a9e3972597b", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class E {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint[] p;\n\tdouble[][] dpEqLess;\n\tdouble[][] dpEqLessMul;\n\tint maxK = 150;\n\t\n\tpublic void solve() throws IOException {\n\t\tint q = in.nextInt();\n\t\tdpEqLess = new double[maxK][q];\n\t\tfor (int i = 0; i < maxK; i++) {\n\t\t\tdpEqLess[i][0] = 1;\n\t\t}\n\t\tp = new int[q];\n\t\tp[0] = -1;\n\t\tint cntV = 0;\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tint type = in.nextInt();\n\t\t\tint v = in.nextInt() - 1;\n\t\t\tif (type == 1) {\n\t\t\t\tint u = ++cntV;\n\t\t\t\tp[u] = v;\n\t\t\t\tfor (int j = 0; j < maxK; j++) {\n\t\t\t\t\tdpEqLess[j][u] = 1;\n\t\t\t\t}\n\t\t\t\tdouble prev = 1;\n\t\t\t\tfor (int j = 0; j < maxK; j++) {\n\t\t\t\t\tdouble val = dpEqLess[j][v];\n\t\t\t\t\tval /= prev;\t\n\t\t\t\t\tprev = dpEqLess[j][v]*0.5 + 0.5;\n\t\t\t\t\tval *= (0.5 + 0.5*(j - 1 >= 0 ? dpEqLess[j - 1][u] : 0));\n\t\t\t\t\tdpEqLess[j][v] = val;\n\t\t\t\t\t\n\t\t\t\t\tv = p[v];\n\t\t\t\t\tu = p[u];\n\t\t\t\t\tif (v == -1) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble res = 0;\n\t\t\t\tfor (int j = 1; j < maxK; j++) {\n\t\t\t\t\tres += j * (dpEqLess[j][v] - dpEqLess[j - 1][v]);\n\t\t\t\t}\n\t\t\t\tout.println(res);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new FastScanner();\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() {\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 (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\t}\n\n\tpublic static void main(String[] arg) {\n\t\tnew E().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3059536b6daf093fed67e9ee3954f0dd", "src_uid": "55affe752cb214d1e4031a9e3972597b", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "/**\n * \n * @author Eduardo M\n */\nimport java.util.Scanner;\n\npublic class SubestacoesModestas {\n\n\n public static void main(String[] args) {\n new SubestacoesModestas().solucao();\n }\n\n Scanner sc = new Scanner(System.in);\n int l, y, n, cont, tt, aux, cont1, i, j, k;\n char[] vet = new char[810];\n char[] g = new char[810];\n char[] vet1 = new char[810];\n int[] vet2 = new int[21000];\n int[] vet3 = new int[21000];\n int[][] mat = new int[21000][810];\n int[][] mat1 = new int[21000][10];\n int[][] met2 = new int[2100][21000];\n\n void solucao() {\n String ent = sc.next();\n String ent1 = sc.next();\n l = sc.nextInt();\n y = ent.length();\n n = ent1.length();\n for (i = 0; i < y; i++) {\n vet[i] = ent.charAt(i);\n }\n for (i = 0; i < n; i++) {\n vet1[i] = ent1.charAt(i);\n }\n cont = ++tt;\n g = vet;\n int tempAdd = cont;\n for (i = 0; g[i] != 0; i++) {\n if (mat1[tempAdd][g[i] - '0'] == 0) {\n mat1[tempAdd][g[i] - '0'] = ++tt;\n }\n tempAdd = mat1[tempAdd][g[i] - '0'];\n }\n g = vet1;\n tempAdd = cont;\n for (i = 0; g[i] != 0; i++) {\n if (mat1[tempAdd][g[i] - '0'] == 0) {\n mat1[tempAdd][g[i] - '0'] = ++tt;\n }\n tempAdd = mat1[tempAdd][g[i] - '0'];\n }\n if (y == n) {\n int veri = cont, veri1 = cont;\n for (i = 0; i < y; i++) {\n if (veri == veri1 && vet[i] != vet1[i]) {\n for (int c = vet[i] + 1; c < vet1[i]; c++) {\n if (mat1[veri][c - '0'] == 0) {\n mat1[veri][c - '0'] = ++tt;\n }\n mat[mat1[veri][c - '0']][y - i - 1]++;\n }\n } else if (veri != veri1) {\n for (int temp = vet[i] + 1; temp < '0' + 10; temp++) {\n if (mat1[veri][temp - '0'] == 0) {\n mat1[veri][temp - '0'] = ++tt;\n }\n mat[mat1[veri][temp - '0']][y - i - 1]++;\n }\n for (int temp = '0' + (i == 0 ? 1 : 0); temp < vet1[i]; temp++) {\n if (mat1[veri1][temp - '0'] == 0) {\n mat1[veri1][temp - '0'] = ++tt;\n }\n mat[mat1[veri1][temp - '0']][y - i - 1]++;\n }\n }\n veri = mat1[veri][vet[i] - '0'];\n veri1 = mat1[veri1][vet1[i] - '0'];\n }\n mat[veri][0]++;\n if (veri != veri1) {\n mat[veri1][0]++;\n }\n } else {\n int veri = cont, veri1 = cont;\n for (i = 0; i < y; i++) {\n for (int temp = vet[i] + 1; temp < '0' + 10; temp++) {\n if (mat1[veri][temp - '0'] == 0) {\n mat1[veri][temp - '0'] = ++tt;\n }\n mat[mat1[veri][temp - '0']][y - i - 1]++;\n }\n veri = mat1[veri][vet[i] - '0'];\n }\n for (i = 0; i < n; i++) {\n for (int temp = '0' + (i == 0 ? 1 : 0); temp < vet1[i]; temp++) {\n if (mat1[veri1][temp - '0'] == 0) {\n mat1[veri1][temp - '0'] = ++tt;\n }\n mat[mat1[veri1][temp - '0']][n - i - 1]++;\n }\n veri1 = mat1[veri1][vet1[i] - '0'];\n }\n mat[veri][0]++;\n mat[veri1][0]++;\n for (i = 1; i < 10; i++) {\n if (mat1[cont][i] == 0) {\n mat1[cont][i] = ++tt;\n }\n for (j = y + 1; j < n; j++) {\n mat[mat1[cont][i]][j - 1]++;\n }\n }\n }\n aux = cont1 = 0;\n vet2[cont1++] = cont;\n for (; aux < cont1; aux++) {\n int x = vet2[aux];\n for (i = 0; i < 10; i++) {\n if (mat1[x][i] != 0) {\n if (x == cont) {\n vet3[mat1[x][i]] = x;\n } else {\n vet3[mat1[x][i]] = vet3[x];\n while (vet3[mat1[x][i]] != cont && mat1[vet3[mat1[x][i]]][i] == 0) {\n vet3[mat1[x][i]] = vet3[vet3[mat1[x][i]]];\n }\n if (mat1[vet3[mat1[x][i]]][i] != 0) {\n vet3[mat1[x][i]] = mat1[vet3[mat1[x][i]]][i];\n }\n }\n vet2[cont1++] = mat1[x][i];\n }\n }\n }\n for (i = 1; i < cont1; i++) {\n int x = vet2[i];\n for (j = 0; j < n; j++) {\n mat[x][j] += mat[vet3[x]][j];\n }\n }\n for (i = 1; i <= tt; i++) {\n for (j = 1; j < n; j++) {\n mat[i][j] += mat[i][j - 1];\n }\n }\n for (i = 1; i <= tt; i++) {\n met2[0][i] = mat[i][0];\n }\n for (i = 1; i <= l; i++) {\n for (j = 1; j <= tt; j++) {\n for (k = 0; k < 10; k++) {\n met2[i][j] = Math.max(met2[i][j], met2[i - 1][mat1[j][k]]);\n }\n met2[i][j] += mat[j][Math.min(i, n - 1)];\n }\n }\n System.out.println(met2[l][cont]);\n int TempResu = cont;\n for (i = l; i >= 1; i--) {\n int val = met2[i][TempResu] - mat[TempResu][Math.min(i, n - 1)];\n for (int lext = 0; lext < 10; lext++) {\n if (met2[i - 1][mat1[TempResu][lext]] == val) {\n System.out.print(lext);\n TempResu = mat1[TempResu][lext];\n break;\n }\n }\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6b4f833e403277f564d5c3db3ef27d3e", "src_uid": "2e79c95bf4c2b7de8a4741b24a880829", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "**\n *\n * @author Eduardo M\n */\nimport java.util.Scanner;\n\npublic class SubestacoesModestas {\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 public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int l, y, n, cont, tt=0, aux, cont1, i, j, k;\n char[] vet = new char[810];\n char[] g = new char[810];\n char[] vet1 = new char[810];\n int[] vet2 = new int[21000];\n int[] vet3 = new int[21000];\n int[][] mat = new int[21000][810];\n int[][] mat1 = new int[21000][10];\n int[][] met2 = new int[2100][21000];\n\n\n String ent = sc.next();\n String ent1 = sc.next();\n l = sc.nextInt();\n y = ent.length();\n n = ent1.length();\n for (i = 0; i < y; i++) {\n vet[i] = ent.charAt(i);\n }\n for (i = 0; i < n; i++) {\n vet1[i] = ent1.charAt(i);\n }\n cont = ++tt;\n g = vet;\n int tempAdd = cont;\n for (i = 0; g[i] != 0; i++) {\n if (mat1[tempAdd][g[i] - '0'] == 0) {\n mat1[tempAdd][g[i] - '0'] = ++tt;\n }\n tempAdd = mat1[tempAdd][g[i] - '0'];\n }\n g = vet1;\n tempAdd = cont;\n for (i = 0; g[i] != 0; i++) {\n if (mat1[tempAdd][g[i] - '0'] == 0) {\n mat1[tempAdd][g[i] - '0'] = ++tt;\n }\n tempAdd = mat1[tempAdd][g[i] - '0'];\n }\n if (y == n) {\n int veri = cont, veri1 = cont;\n for (i = 0; i < y; i++) {\n if (veri == veri1 && vet[i] != vet1[i]) {\n for (int c = vet[i] + 1; c < vet1[i]; c++) {\n if (mat1[veri][c - '0'] == 0) {\n mat1[veri][c - '0'] = ++tt;\n }\n mat[mat1[veri][c - '0']][y - i - 1]++;\n }\n } else if (veri != veri1) {\n for (int temp = vet[i] + 1; temp < '0' + 10; temp++) {\n if (mat1[veri][temp - '0'] == 0) {\n mat1[veri][temp - '0'] = ++tt;\n }\n mat[mat1[veri][temp - '0']][y - i - 1]++;\n }\n for (int temp = '0' + (i == 0 ? 1 : 0); temp < vet1[i]; temp++) {\n if (mat1[veri1][temp - '0'] == 0) {\n mat1[veri1][temp - '0'] = ++tt;\n }\n mat[mat1[veri1][temp - '0']][y - i - 1]++;\n }\n }\n veri = mat1[veri][vet[i] - '0'];\n veri1 = mat1[veri1][vet1[i] - '0'];\n }\n mat[veri][0]++;\n if (veri != veri1) {\n mat[veri1][0]++;\n }\n } else {\n int veri = cont, veri1 = cont;\n for (i = 0; i < y; i++) {\n for (int temp = vet[i] + 1; temp < '0' + 10; temp++) {\n if (mat1[veri][temp - '0'] == 0) {\n mat1[veri][temp - '0'] = ++tt;\n }\n mat[mat1[veri][temp - '0']][y - i - 1]++;\n }\n veri = mat1[veri][vet[i] - '0'];\n }\n for (i = 0; i < n; i++) {\n for (int temp = '0' + (i == 0 ? 1 : 0); temp < vet1[i]; temp++) {\n if (mat1[veri1][temp - '0'] == 0) {\n mat1[veri1][temp - '0'] = ++tt;\n }\n mat[mat1[veri1][temp - '0']][n - i - 1]++;\n }\n veri1 = mat1[veri1][vet1[i] - '0'];\n }\n mat[veri][0]++;\n mat[veri1][0]++;\n for (i = 1; i < 10; i++) {\n if (mat1[cont][i] == 0) {\n mat1[cont][i] = ++tt;\n }\n for (j = y + 1; j < n; j++) {\n mat[mat1[cont][i]][j - 1]++;\n }\n }\n }\n aux = cont1 = 0;\n vet2[cont1++] = cont;\n for (; aux < cont1; aux++) {\n int x = vet2[aux];\n for (i = 0; i < 10; i++) {\n if (mat1[x][i] != 0) {\n if (x == cont) {\n vet3[mat1[x][i]] = x;\n } else {\n vet3[mat1[x][i]] = vet3[x];\n while (vet3[mat1[x][i]] != cont && mat1[vet3[mat1[x][i]]][i] == 0) {\n vet3[mat1[x][i]] = vet3[vet3[mat1[x][i]]];\n }\n if (mat1[vet3[mat1[x][i]]][i] != 0) {\n vet3[mat1[x][i]] = mat1[vet3[mat1[x][i]]][i];\n }\n }\n vet2[cont1++] = mat1[x][i];\n }\n }\n }\n for (i = 1; i < cont1; i++) {\n int x = vet2[i];\n for (j = 0; j < n; j++) {\n mat[x][j] += mat[vet3[x]][j];\n }\n }\n for (i = 1; i <= tt; i++) {\n for (j = 1; j < n; j++) {\n mat[i][j] += mat[i][j - 1];\n }\n }\n for (i = 1; i <= tt; i++) {\n met2[0][i] = mat[i][0];\n }\n for (i = 1; i <= l; i++) {\n for (j = 1; j <= tt; j++) {\n for (k = 0; k < 10; k++) {\n met2[i][j] = Math.max(met2[i][j], met2[i - 1][mat1[j][k]]);\n }\n met2[i][j] += mat[j][Math.min(i, n - 1)];\n }\n }\n System.out.println(met2[l][cont]);\n int TempResu = cont;\n for (i = l; i >= 1; i--) {\n int val = met2[i][TempResu] - mat[TempResu][Math.min(i, n - 1)];\n for (int lext = 0; lext < 10; lext++) {\n if (met2[i - 1][mat1[TempResu][lext]] == val) {\n System.out.print(lext);\n TempResu = mat1[TempResu][lext];\n break;\n }\n }\n }\n \n\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e6f596062ea183c4d8093f4db8596e8", "src_uid": "2e79c95bf4c2b7de8a4741b24a880829", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "**\n *\n * @author Eduardo M\n */\nimport java.util.Scanner;\n\npublic class Main {\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 public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int l, y, n, cont, tt=0, aux, cont1, i, j, k;\n char[] vet = new char[810];\n char[] g = new char[810];\n char[] vet1 = new char[810];\n int[] vet2 = new int[21000];\n int[] vet3 = new int[21000];\n int[][] mat = new int[21000][810];\n int[][] mat1 = new int[21000][10];\n int[][] met2 = new int[2100][21000];\n\n\n String ent = sc.next();\n String ent1 = sc.next();\n l = sc.nextInt();\n y = ent.length();\n n = ent1.length();\n for (i = 0; i < y; i++) {\n vet[i] = ent.charAt(i);\n }\n for (i = 0; i < n; i++) {\n vet1[i] = ent1.charAt(i);\n }\n cont = ++tt;\n g = vet;\n int tempAdd = cont;\n for (i = 0; g[i] != 0; i++) {\n if (mat1[tempAdd][g[i] - '0'] == 0) {\n mat1[tempAdd][g[i] - '0'] = ++tt;\n }\n tempAdd = mat1[tempAdd][g[i] - '0'];\n }\n g = vet1;\n tempAdd = cont;\n for (i = 0; g[i] != 0; i++) {\n if (mat1[tempAdd][g[i] - '0'] == 0) {\n mat1[tempAdd][g[i] - '0'] = ++tt;\n }\n tempAdd = mat1[tempAdd][g[i] - '0'];\n }\n if (y == n) {\n int veri = cont, veri1 = cont;\n for (i = 0; i < y; i++) {\n if (veri == veri1 && vet[i] != vet1[i]) {\n for (int c = vet[i] + 1; c < vet1[i]; c++) {\n if (mat1[veri][c - '0'] == 0) {\n mat1[veri][c - '0'] = ++tt;\n }\n mat[mat1[veri][c - '0']][y - i - 1]++;\n }\n } else if (veri != veri1) {\n for (int temp = vet[i] + 1; temp < '0' + 10; temp++) {\n if (mat1[veri][temp - '0'] == 0) {\n mat1[veri][temp - '0'] = ++tt;\n }\n mat[mat1[veri][temp - '0']][y - i - 1]++;\n }\n for (int temp = '0' + (i == 0 ? 1 : 0); temp < vet1[i]; temp++) {\n if (mat1[veri1][temp - '0'] == 0) {\n mat1[veri1][temp - '0'] = ++tt;\n }\n mat[mat1[veri1][temp - '0']][y - i - 1]++;\n }\n }\n veri = mat1[veri][vet[i] - '0'];\n veri1 = mat1[veri1][vet1[i] - '0'];\n }\n mat[veri][0]++;\n if (veri != veri1) {\n mat[veri1][0]++;\n }\n } else {\n int veri = cont, veri1 = cont;\n for (i = 0; i < y; i++) {\n for (int temp = vet[i] + 1; temp < '0' + 10; temp++) {\n if (mat1[veri][temp - '0'] == 0) {\n mat1[veri][temp - '0'] = ++tt;\n }\n mat[mat1[veri][temp - '0']][y - i - 1]++;\n }\n veri = mat1[veri][vet[i] - '0'];\n }\n for (i = 0; i < n; i++) {\n for (int temp = '0' + (i == 0 ? 1 : 0); temp < vet1[i]; temp++) {\n if (mat1[veri1][temp - '0'] == 0) {\n mat1[veri1][temp - '0'] = ++tt;\n }\n mat[mat1[veri1][temp - '0']][n - i - 1]++;\n }\n veri1 = mat1[veri1][vet1[i] - '0'];\n }\n mat[veri][0]++;\n mat[veri1][0]++;\n for (i = 1; i < 10; i++) {\n if (mat1[cont][i] == 0) {\n mat1[cont][i] = ++tt;\n }\n for (j = y + 1; j < n; j++) {\n mat[mat1[cont][i]][j - 1]++;\n }\n }\n }\n aux = cont1 = 0;\n vet2[cont1++] = cont;\n for (; aux < cont1; aux++) {\n int x = vet2[aux];\n for (i = 0; i < 10; i++) {\n if (mat1[x][i] != 0) {\n if (x == cont) {\n vet3[mat1[x][i]] = x;\n } else {\n vet3[mat1[x][i]] = vet3[x];\n while (vet3[mat1[x][i]] != cont && mat1[vet3[mat1[x][i]]][i] == 0) {\n vet3[mat1[x][i]] = vet3[vet3[mat1[x][i]]];\n }\n if (mat1[vet3[mat1[x][i]]][i] != 0) {\n vet3[mat1[x][i]] = mat1[vet3[mat1[x][i]]][i];\n }\n }\n vet2[cont1++] = mat1[x][i];\n }\n }\n }\n for (i = 1; i < cont1; i++) {\n int x = vet2[i];\n for (j = 0; j < n; j++) {\n mat[x][j] += mat[vet3[x]][j];\n }\n }\n for (i = 1; i <= tt; i++) {\n for (j = 1; j < n; j++) {\n mat[i][j] += mat[i][j - 1];\n }\n }\n for (i = 1; i <= tt; i++) {\n met2[0][i] = mat[i][0];\n }\n for (i = 1; i <= l; i++) {\n for (j = 1; j <= tt; j++) {\n for (k = 0; k < 10; k++) {\n met2[i][j] = Math.max(met2[i][j], met2[i - 1][mat1[j][k]]);\n }\n met2[i][j] += mat[j][Math.min(i, n - 1)];\n }\n }\n System.out.println(met2[l][cont]);\n int TempResu = cont;\n for (i = l; i >= 1; i--) {\n int val = met2[i][TempResu] - mat[TempResu][Math.min(i, n - 1)];\n for (int lext = 0; lext < 10; lext++) {\n if (met2[i - 1][mat1[TempResu][lext]] == val) {\n System.out.print(lext);\n TempResu = mat1[TempResu][lext];\n break;\n }\n }\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72631c8ffc00dc9f878f1597fd6933ba", "src_uid": "2e79c95bf4c2b7de8a4741b24a880829", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Subesta\u00e7\u00f5esModestas d = new Subesta\u00e7\u00f5esModestas();\n d.solucao();\n }\n\n Scanner sc = new Scanner(System.in);\n int L, TamX, TamN, Cont, TT, aux, cont1,i,j,k, veri,veri2,AuxD;\n char[] vet = new char[810];\n char[] vet1 = new char[810];\n int[] vet2 = new int[21000];\n int[] vet3 = new int[21000];\n int[][] mat1 = new int[21000][810];\n int[][] mat2 = new int[21000][10];\n int[][] mat = new int[2100][21000];\n\n void solucao(){\n String tl = sc.next();\n String tr = sc.next();\n L= sc.nextInt();\n TamX = tl.length();\n TamN = tr.length();\n for( i = 0 ; i < TamX ; i++){\n vet[i] = tl.charAt(i);\n }\n for( i = 0 ; i < TamN ; i++){\n vet1[i] = tr.charAt(i);\n }\n Cont = ++TT;\n add(vet);\n add(vet1);\n if(TamX == TamN){\n veri = Cont;\n veri2 = Cont;\n for( i = 0 ; i < TamX ; i++){\n if( vet[i] != vet1[i]){\n for(int temp = vet[i]+1 ; temp < vet1[i] ; temp++){\n if(mat2[veri][temp-'0'] == 0){\n mat2[veri][temp-'0'] = ++TT;\n }\n mat1[mat2[veri][temp-'0']][TamX-i-1]++;\n }\n }\n else if(veri != veri2){\n for(int temp = vet[i]+1 ; temp < '0'+10 ; temp++){\n if(mat2[veri][temp-'0'] == 0){\n mat2[veri][temp-'0'] = ++TT;\n }\n mat1[mat2[veri][temp-'0']][TamX-i-1]++;\n }\n for(int temp = '0'+ (i == 0 ? 1 : 0) ; temp < vet1[i] ; temp++){\n if(mat2[veri2][temp-'0'] == 0){\n mat2[veri2][temp-'0'] = ++TT;\n }\n mat1[mat2[veri2][temp-'0']][TamX-i-1]++;\n }\n }\n veri = mat2[veri][vet[i]-'0'];\n veri2 = mat2[veri2][vet1[i]-'0'];\n }\n mat1[veri][0]++;\n if(veri != veri2){\n mat1[veri2][0]++;\n }\n }\n else{\n veri = Cont;\n veri2 = Cont;\n for( i = 0 ; i < TamX ; i++){\n for(int temp = vet[i]+1 ; temp < '0'+10 ; temp++){\n if(mat2[veri][temp-'0'] == 0){\n mat2[veri][temp-'0'] = ++TT;\n }\n mat1[mat2[veri][temp-'0']][TamX-i-1]++;\n }\n veri = mat2[veri][vet[i]-'0'];\n }\n for( i = 0 ; i < TamN ; i++){\n for(int temp = '0'+ (i == 0 ? 1 : 0) ; temp < vet1[i] ; temp++){\n if(mat2[veri2][temp-'0'] == 0){\n mat2[veri2][temp-'0'] = ++TT;\n }\n mat1[mat2[veri2][temp-'0']][TamN-i-1]++;\n }\n veri2 = mat2[veri2][vet1[i]-'0'];\n }\n mat1[veri][0]++;\n mat1[veri2][0]++;\n for( i = 1 ; i < 10 ; i++){\n if(mat2[Cont][i] == 0){\n mat2[Cont][i] = ++TT;\n }\n for( j = TamX+1 ; j < TamN ; j++){\n mat1[mat2[Cont][i]][j-1]++;\n }\n }\n }\n resolver();\n for( i = 1 ; i < cont1 ; i++){\n AuxD = vet2[i];\n for( j = 0 ; j < TamN ; j++){\n mat1[AuxD][j] += mat1[vet3[AuxD]][j];\n }\n }\n for( i = 1 ; i <= TT ; i++){\n for( j = 1 ; j < TamN ; j++){\n mat1[i][j] += mat1[i][j-1];\n }\n }\n resultado();\n sc.close();\n }\n void resultado(){\n for( i = 1 ; i <= TT ; i++){\n mat[0][i] = mat1[i][0];\n }\n for( i = 1 ; i <= L; i++){\n for( j = 1 ; j <= TT ; j++){\n for( k = 0 ; k < 10 ; k++){\n mat[i][j] = Math.max(mat[i][j], mat[i-1][mat2[j][k]]);\n }\n mat[i][j] += mat1[j][Math.min(i, TamN-1)];\n }\n }\n System.out.println(mat[L][Cont]);\n AuxD = Cont;\n for( i = L; i >= 1 ; i--){\n int val = mat[i][AuxD]-mat1[AuxD][Math.min(i, TamN-1)];\n for(int next = 0 ; next < 10 ; next++){\n if(mat[i-1][mat2[AuxD][next]]==val){\n System.out.print(next);\n AuxD = mat2[AuxD][next];\n break;\n }\n }\n }\n }\n void resolver(){\n\taux=cont1;\n \tcont1 = 0;\n vet2[cont1++] = Cont;\n for(; aux < cont1 ; aux++){\n AuxD = vet2[aux];\n for( i = 0 ; i < 10 ; i++){\n if(mat2[AuxD][i] != 0){\n if(AuxD == Cont){\n vet3[mat2[AuxD][i]] = AuxD;\n }\n else{\n vet3[mat2[AuxD][i]] = vet3[AuxD];\n while(vet3[mat2[AuxD][i]] != Cont && mat2[vet3[mat2[AuxD][i]]][i] == 0){\n vet3[mat2[AuxD][i]] = vet3[vet3[mat2[AuxD][i]]];\n }\n if(mat2[vet3[mat2[AuxD][i]]][i] != 0){\n vet3[mat2[AuxD][i]] = mat2[vet3[mat2[AuxD][i]]][i];\n }\n }\n vet2[cont1++] = mat2[AuxD][i];\n }\n }\n }\n for( i = 0 ; i < 10 ; i++){\n if(mat2[Cont][i] == 0){\n mat2[Cont][i] = Cont;\n }\n } \n for( j = 1 ; j < cont1 ; j++){\n AuxD = vet2[j];\n for( i = 0 ; i < 10 ; i++){\n if(mat2[AuxD][i] == 0){\n mat2[AuxD][i] = mat2[vet3[AuxD]][i];\n }\n }\n }\n }\n void add(char s[]){\n AuxD = Cont;\n for( i = 0 ; s[i] != 0 ; i++){\n if(mat2[AuxD][s[i]-'0'] == 0){\n mat2[AuxD][s[i]-'0'] = ++TT;\n }\n AuxD = mat2[AuxD][s[i]-'0'];\n }\n }\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eea7585f7f2f862a1ea81608d7d2d084", "src_uid": "2e79c95bf4c2b7de8a4741b24a880829", "difficulty": 3500.0} {"lang": "Java 8", "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;\n\npublic class CF1202F {\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 double eps = 1e-8;\n\n public Task(FastIO io, Debug debug) {\n this.io = io;\n this.debug = debug;\n }\n\n @Override\n public void run() {\n solve();\n }\n\n public void solve() {\n int a = io.readInt();\n int b = io.readInt();\n int n = a + b;\n FloorDivisionOptimizer optimizer = new FloorDivisionOptimizer(n, 1, n);\n int sum = 0;\n while (optimizer.hasNext()) {\n int k = optimizer.next();\n\n int pr = Math.min(optimizer.r, n / k);\n int pl = Math.max(optimizer.l, (n + k) / (k + 1));\n\n\n int xb = (a + k) / (k + 1);\n int xt = a / k;\n if (xb > xt) {\n continue;\n }\n\n pl = Math.max(pl, xb + (b + k) / (k + 1));\n pr = Math.min(pr, xt + b / k);\n\n if (xb + (double) b / (k + 1) > eps + (double) a / (k + 1) + (double) b / k) {\n continue;\n }\n\n sum += Math.max(pr - pl + 1, 0);\n// if (pr - pl + 1 > 0)\n// debug.debug(\"lr\", pl + \" <= \" + pr);\n }\n\n io.cache.append(sum);\n }\n }\n\n /**\n * \\sum_{i=1}^{limit}f(\\lfloor n/i \\rfloor)\n */\n public static class FloorDivisionOptimizer {\n int l;\n int r;\n int n;\n int limit;\n\n\n public FloorDivisionOptimizer(int n, int l, int limit) {\n this.n = n;\n this.l = 0;\n this.limit = limit;\n this.r = l - 1;\n }\n\n public boolean hasNext() {\n return r < limit;\n }\n\n public int next() {\n l = r + 1;\n r = n / (n / l);\n return n / l;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0ec7edf9f23bbf059b8d447b4f355297", "src_uid": "0e6a204565fef118ea99d2fa1e378dd0", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1202F extends PrintWriter {\n\tCF1202F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1202F o = new CF1202F(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tif (a > b) {\n\t\t\tint tmp = a; a = b; b = tmp;\n\t\t}\n\t\tint ab = a + b;\n\t\tdouble x = (double) a / ab;\n\t\tint upper = 10000000;\n\t\tif (upper > ab)\n\t\t\tupper = ab;\n\t\tint ans = ab - upper;\n\t\tfor (int cd = 2; cd <= upper; cd++) {\n\t\t\tint c = (int) (cd * x + 0.5);\n\t\t\tif (c == 0)\n\t\t\t\tcontinue;\n\t\t\tint d = cd - c;\n\t\t\tint k = a / c, l = b / d;\n\t\t\tif (k == l || k == l + 1 && a % c == 0 || k == l - 1 && b % d == 0)\n\t\t\t\tans++;\n\t\t}\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dc7c1f126b60264726a72fe132101a2f", "src_uid": "0e6a204565fef118ea99d2fa1e378dd0", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1202F extends PrintWriter {\n\tCF1202F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1202F o = new CF1202F(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tif (a > b) {\n\t\t\tint tmp = a; a = b; b = tmp;\n\t\t}\n\t\tint ab = a + b;\n\t\tdouble x = (double) a / ab;\n\t\tint upper = 10000000;\n\t\tif (upper > ab)\n\t\t\tupper = ab;\n\t\tint ans = ab - upper;\n\t\tfor (int cd = 2; cd <= upper; cd++) {\n\t\t\tint c = (int) (cd * x + 0.5);\n\t\t\tif (c == 0)\n\t\t\t\tc = 1;\n\t\t\tint d = cd - c;\n\t\t\tint k = a / c, l = b / d;\n\t\t\tif (k == l || k == l + 1 && a % c == 0 || k == l - 1 && b % d == 0)\n\t\t\t\tans++;\n\t\t}\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f0a495e2783d2f545d1906ebd01a672f", "src_uid": "0e6a204565fef118ea99d2fa1e378dd0", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1202F extends PrintWriter {\n\tCF1202F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1202F o = new CF1202F(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tif (a > b) {\n\t\t\tint tmp = a; a = b; b = tmp;\n\t\t}\n\t\tint ab = a + b;\n\t\tdouble x = (double) a / ab;\n\t\tint ans = 0;\n\t\tfor (int cd = 2; cd <= ab; cd++) {\n\t\t\tint c = (int) (cd * x + 0.5);\n\t\t\tif (c == 0)\n\t\t\t\tcontinue;\n\t\t\tint d = cd - c;\n\t\t\tint k = a / c, l = b / d;\n\t\t\tif (k == l || k == l + 1 && a % c == 0 || k == l - 1 && b % d == 0)\n\t\t\t\tans++;\n\t\t}\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dd16df2e2ae3634d4caf5f868ce0e19f", "src_uid": "0e6a204565fef118ea99d2fa1e378dd0", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class D {\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 in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n inB = (new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n }\n\n public static void main(String[] args)throws Exception{\n String[] s = inB.readLine().split(\" \");\n int n = bitmas.n = Integer.parseInt(s[0]);\n int m = bitmas.m = Integer.parseInt(s[1]);\n int k = Integer.parseInt(s[2]);\n \n bitmas.nsize = n;\n bitmas.msize = (m)%32 == 0 ? (m/32) : (m/32 + 1);\n bitmas.size = bitmas.nsize * bitmas.msize;\n\n boolean[][] mas = new boolean[n][m];\n \n boolean[][] emas = new boolean[n][m];\n\n for(int i = 0; i0 && !mas[i-1][j]) ? true : false;\n masD[i][j] = (mas[i][j] && i0 && !mas[i][j-1]) ? true : false;\n masR[i][j] = (mas[i][j] && i> i) & 1));\n }\n }\n \n void print() {\n for(int i = 0; i=0; j--) {\n\n int need = (1 << 31) & mas[i][j];\n mas[i][j] <<= 1;\n mas[i][j] |= take;\n take = need > 0 ? 1 : 0;\n }\n }\n return this;\n }\n\n bitmas shiftRight() {\n for(int i = 0; i>= 1;\n mas[i][j] |= (take << 31);\n take = need > 0 ? (1 << 31) : 0;\n }\n }\n return this;\n }\n\n bitmas shiftDown() {\n for(int j = 0; j=0; i--) {\n int last = (mas[i][j]);\n mas[i][j] = take;\n take = last;\n }\n }\n\n return this;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "93de0439f8d2395c4f63825bc8af6505", "src_uid": "70ab617d9b8813ddf3039c6fb137d817", "difficulty": 2700.0} {"lang": "Java 6", "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\n\t\t\t}\t\t\t\n\t\t}\n\n\t\tvoid shiftRight(long [] a) {\n\t\t\ttmp[0] = 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\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\t\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 + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(-1);\t\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Sol()).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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a96864a39bbeb30742782f4d72e0ff8d", "src_uid": "70ab617d9b8813ddf3039c6fb137d817", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class D {\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 in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n inB = (new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n }\n\n public static void main(String[] args)throws Exception{\n String[] s = inB.readLine().split(\" \");\n int n = bitmas.n = Integer.parseInt(s[0]);\n int m = bitmas.m = Integer.parseInt(s[1]);\n int k = Integer.parseInt(s[2]);\n \n bitmas.nsize = n;\n bitmas.msize = (m)%32 == 0 ? (m/32) : (m/32 + 1);\n bitmas.size = bitmas.nsize * bitmas.msize;\n\n boolean[][] mas = new boolean[n][m];\n \n boolean[][] emas = new boolean[n][m];\n\n for(int i = 0; i> i) & 1));\n }\n }\n \n void print() {\n for(int i = 0; i=0; j--) {\n\n int need = 1 & mas[i*msize + j];\n mas[i*msize + j] >>= 1;\n mas[i*msize + j] ^= ((1 << 31) & mas[i*msize + j]);\n mas[i*msize + j] |= (take << 31);\n take = need == 0 ? 0 : 1;\n }\n }\n return this;\n }\n\n bitmas shiftDown() {\n for(int j = 0; j=0; i--) {\n int last = (mas[i*msize + j]);\n mas[i*msize + j] = take;\n take = last;\n }\n }\n\n return this;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1ada8fe463646c2e508486dabf121fc2", "src_uid": "70ab617d9b8813ddf3039c6fb137d817", "difficulty": 2700.0} {"lang": "Java 6", "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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "219a7676d65994f3544df126c2f56d2e", "src_uid": "70ab617d9b8813ddf3039c6fb137d817", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n for (int i = 0; i < n; i++) {\n in.nextInt();\n }\n System.out.println(n);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7700fbde48e5a3282f3331f3a08369ba", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Solver solver = new Solver();\n solver.solve(in, out);\n out.close();\n }\n static class Solver {\n public void solve(InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int last = 0;\n int max = -1;\n for (int i = 0; i < n; ++i) {\n int t = in.nextInt();\n max = Math.max(max, t);\n last = t;\n }\n out.println(max ^ last + 1);\n }\n\n } // wubba lubba dub dub\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreElements()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c6c52bd6452667d01d979ebb18185a0", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF784C {\n\tstatic char[] aa = \"ABRACADABRA\".toCharArray();\n\tstatic char[] bb = \"ABCDR\".toCharArray();\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint[] cc = new int[5];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint j = Integer.parseInt(st.nextToken()) - 1;\n\t\t\tchar a = aa[j];\n\t\t\tfor (int k = 0; k < 5; k++)\n\t\t\t\tif (a == bb[k])\n\t\t\t\t\tcc[k]++;\n\t\t}\n\t\tint cnt = 0;\n\t\tfor (int k = 0; k < 5; k++)\n\t\t\tif (cc[k] > 0)\n\t\t\t\tcnt++;\n\t\tSystem.out.println(cnt);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "99ac3684ebd9d8d56d8a1794c5ab5e07", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class CF {\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 int n = in.nextInt();\n int[] tab = in.nextIntArray(n);\n out.println(maxTab(tab)^minTab(tab));\n out.close();\n }\n\n public static int maxTab(int[] tab){\n int max = 0;\n for (int i : tab) {\n max = max(i,max);\n }\n return max;\n }\n\n public static int minTab(int[] tab){\n int min = Integer.MAX_VALUE;\n for (int i : tab) {\n min = min(i,min);\n }\n return min;\n }\n \n static class FastScanner {\n\n private BufferedReader in;\n private String[] line;\n private int index;\n private int size;\n\n public FastScanner(InputStream in) throws IOException {\n this.in = new BufferedReader(new InputStreamReader(in));\n init();\n }\n\n public FastScanner(String file) throws FileNotFoundException {\n this.in = new BufferedReader(new FileReader(file));\n }\n\n private void init() throws IOException {\n line = in.readLine().split(\" \");\n index = 0;\n size = line.length;\n }\n\n public int nextInt() throws IOException {\n if (index == size) {\n init();\n }\n return Integer.parseInt(line[index++]);\n }\n\n public long nextLong() throws IOException {\n if (index == size) {\n init();\n }\n return Long.parseLong(line[index++]);\n }\n\n public float nextFloat() throws IOException {\n if (index == size) {\n init();\n }\n return Float.parseFloat(line[index++]);\n }\n\n public double nextDouble() throws IOException {\n if (index == size) {\n init();\n }\n return Double.parseDouble(line[index++]);\n }\n\n public String next() throws IOException {\n if (index == size) {\n init();\n }\n return line[index++];\n }\n\n public String nextLine() throws IOException {\n if (index == size) {\n init();\n }\n StringBuilder sb = new StringBuilder();\n for (int i = index; i < size; i++) {\n sb.append(line[i]).append(\" \");\n }\n return sb.toString();\n }\n\n private int[] nextIntArray(int n) throws IOException {\n int[] tab = new int[n];\n for (int i = 0; i < tab.length; i++) {\n tab[i] = nextInt();\n }\n return tab;\n }\n\n private double[] nextDoubleArray(int n) throws IOException {\n double[] tab = new double[n];\n for (int i = 0; i < tab.length; i++) {\n tab[i] = nextDouble();\n }\n return tab;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c56b1cdd117d12221e7234eaea670fa", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n AmusementPark solver = new AmusementPark();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AmusementPark {\n int MOD = 998244353;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n int[] linked = new int[N];\n for (int i = 0; i < M; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n linked[a] |= (1 << b);\n linked[b] |= (1 << a);\n }\n ArrayList[] maps = new ArrayList[(1 << N)];\n for (int i = 0; i < (1 << N); i++) {\n maps[i] = new ArrayList<>();\n }\n maps[0].add(new int[]{(1 << N) - 1, 1});\n for (int i = 0; i < (1 << N); i++) {\n for (int[] mask : maps[i]) {\n int nmask = 0;\n for (int j = 0; j < N; j++) {\n if (isSet(mask[0], j)) {\n add(maps[i | (1 << j)], nmask | ((~i) & (linked[j])), mask[1]);\n nmask |= (1 << j);\n }\n }\n }\n }\n long count = maps[(1 << N) - 1].get(0)[1];\n out.println(((count * MathUtils.inverse(2, MOD) % MOD) * M) % MOD);\n }\n\n boolean isSet(int mask, int bit) {\n return ((mask & (1 << bit)) > 0);\n }\n\n void add(ArrayList arr, int m, int c) {\n for (int[] a : arr) {\n if (a[0] == m) {\n a[1] += c;\n while (a[1] >= MOD) {\n a[1] -= MOD;\n }\n return;\n }\n }\n arr.add(new int[]{m, c});\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class MathUtils {\n public static long inverse(long a, long mod) {\n long[] inv = extended_gcd(a, mod);\n if (inv[0] != 1) {\n return 0;\n } else {\n return (inv[1] + 2 * mod) % mod;\n }\n }\n\n public static long[] extended_gcd(long a, long b) {\n //three numbers, first is gcd, second is x, third is y\n if (a == 0) {\n return new long[]{b, 0, 1};\n }\n long[] next = extended_gcd(b % a, a);\n long tempX = next[1];\n next[1] = next[2] - (b / a) * next[1];\n next[2] = tempX;\n return next;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a637146f1da21c3986795d03ea9cf9a5", "src_uid": "ed962f0ef1a1a92cdaeee06c508f8c10", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.HashMap;\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 AmusementPark solver = new AmusementPark();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AmusementPark {\n int MOD = 998244353;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n int[] linked = new int[N];\n for (int i = 0; i < M; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n linked[a] |= (1 << b);\n linked[b] |= (1 << a);\n }\n CountMap[] maps = new CountMap[(1 << N)];\n for (int i = 0; i < (1 << N); i++) {\n maps[i] = new CountMap();\n }\n maps[0].add((1 << N) - 1, 1);\n for (int i = 0; i < (1 << N); i++) {\n for (Map.Entry mask : maps[i].count.entrySet()) {\n int nmask = 0;\n for (int j = 0; j < N; j++) {\n if (isSet(mask.getKey(), j)) {\n maps[i | (1 << j)].add(nmask | ((~i) & (linked[j])), mask.getValue());\n nmask |= (1 << j);\n }\n }\n }\n }\n long count = maps[(1 << N) - 1].count.get(0);\n out.println(((count * MathUtils.inverse(2, MOD) % MOD) * M) % MOD);\n }\n\n boolean isSet(int mask, int bit) {\n return ((mask & (1 << bit)) > 0);\n }\n\n class CountMap {\n HashMap count = new HashMap<>();\n\n void add(int val, int c) {\n Integer x = count.putIfAbsent(val, c);\n if (x != null) {\n x += c;\n while (x >= MOD) {\n x -= MOD;\n }\n count.replace(val, x);\n }\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class MathUtils {\n public static long inverse(long a, long mod) {\n long[] inv = extended_gcd(a, mod);\n if (inv[0] != 1) {\n return 0;\n } else {\n return (inv[1] + 2 * mod) % mod;\n }\n }\n\n public static long[] extended_gcd(long a, long b) {\n //three numbers, first is gcd, second is x, third is y\n if (a == 0) {\n return new long[]{b, 0, 1};\n }\n long[] next = extended_gcd(b % a, a);\n long tempX = next[1];\n next[1] = next[2] - (b / a) * next[1];\n next[2] = tempX;\n return next;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "86c78b8f62948d1890c4449ca63197bc", "src_uid": "ed962f0ef1a1a92cdaeee06c508f8c10", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n AmusementPark solver = new AmusementPark();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AmusementPark {\n int[] prefMask = new int[20];\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n boolean[][] connect = new boolean[N][N];\n int[] linked = new int[N];\n for (int i = 0; i < prefMask.length; i++) {\n prefMask[i] = (1 << i) - 1;\n }\n int[] base = new int[N];\n for (int i = 0; i < N; i++) {\n base[i] = i;\n }\n for (int i = 0; i < M; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n linked[a] |= (1 << b);\n linked[b] |= (1 << a);\n connect[a][b] = true;\n }\n CountMap[] maps = new CountMap[(1 << N)];\n for (int i = 0; i < (1 << N); i++) {\n maps[i] = new CountMap();\n }\n maps[0].add((1 << N) - 1, 1, 0);\n int ans = 0;\n for (int i = 0; i < (1 << N); i++) {\n for (Map.Entry mask : maps[i].count.entrySet()) {\n int nmask = 0;\n for (int j = 0; j < N; j++) {\n if (isSet(mask.getKey(), j)) {\n int cnt = 0;\n for (int k = 0; k < N; k++) {\n if (connect[k][j] && !isSet(i, k)) {\n cnt++;\n }\n }\n maps[i | (1 << j)].add(nmask | ((~i) & (linked[j])), mask.getValue()[0], mask.getValue()[1] + cnt * mask.getValue()[0]);\n nmask |= (1 << j);\n }\n }\n ans = Math.max(ans, mask.getValue()[1]);\n }\n }\n out.println(ans);\n }\n\n boolean isSet(int mask, int bit) {\n return ((mask & (1 << bit)) > 0);\n }\n\n class CountMap {\n HashMap count = new HashMap<>();\n\n void add(int val, int c, int b) {\n count.putIfAbsent(val, new int[2]);\n int[] x = count.get(val);\n x[0] += c;\n x[1] += b;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db5c7f31cb1f66adebaa0e6daaefcc44", "src_uid": "ed962f0ef1a1a92cdaeee06c508f8c10", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 AmusementPark solver = new AmusementPark();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AmusementPark {\n int MOD = 998244353;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n int[] linked = new int[N];\n for (int i = 0; i < M; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n linked[a] |= (1 << b);\n linked[b] |= (1 << a);\n }\n int max = 100;\n int[][][] maps = new int[(1 << N)][max][];\n add(maps[0], (1 << N) - 1, 1);\n for (int i = 0; i < (1 << N); i++) {\n for (int[] mask : maps[i]) {\n if (mask == null) {\n break;\n }\n int nmask = 0;\n for (int j = 0; j < N; j++) {\n if (isSet(mask[0], j)) {\n add(maps[i | (1 << j)], nmask | ((~i) & (linked[j])), mask[1]);\n nmask |= (1 << j);\n }\n }\n }\n }\n long count = maps[(1 << N) - 1][0][1];\n out.println(((count * MathUtils.inverse(2, MOD) % MOD) * M) % MOD);\n }\n\n boolean isSet(int mask, int bit) {\n return ((mask & (1 << bit)) > 0);\n }\n\n void add(int[][] arr, int m, int c) {\n for (int i = 0; i < arr.length; i++) {\n int[] a = arr[i];\n if (a == null) {\n arr[i] = new int[]{m, c};\n return;\n } else if (a[0] == m) {\n a[1] += c;\n while (a[1] >= MOD) {\n a[1] -= MOD;\n }\n return;\n }\n }\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class MathUtils {\n public static long inverse(long a, long mod) {\n long[] inv = extended_gcd(a, mod);\n if (inv[0] != 1) {\n return 0;\n } else {\n return (inv[1] + 2 * mod) % mod;\n }\n }\n\n public static long[] extended_gcd(long a, long b) {\n //three numbers, first is gcd, second is x, third is y\n if (a == 0) {\n return new long[]{b, 0, 1};\n }\n long[] next = extended_gcd(b % a, a);\n long tempX = next[1];\n next[1] = next[2] - (b / a) * next[1];\n next[2] = tempX;\n return next;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "efeaa2732e780ce8fc78ef79d2f47602", "src_uid": "ed962f0ef1a1a92cdaeee06c508f8c10", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n private static myScanner sc;\n private static PrintWriter pw;\n\n private static final boolean defaultInAndOutPut = true;\n\n private static final int numberOfTests = 1;\n\n private static final String nameOfInAndOutFile = \"\";\n private static final String fullNameInputFile = nameOfInAndOutFile + \".in\";\n private static final String fullNameOutputFile = nameOfInAndOutFile + \".out\";\n\n public static void main(String[] args) throws IOException {\n if (defaultInAndOutPut) {\n setDefaultInAndOutPut();\n } else {\n setInAndOutPutFromFile();\n }\n for (int test = 1; test <= numberOfTests; test++) {\n solve();\n pw.flush();\n }\n\n pw.close();\n }\n\n private static void setDefaultInAndOutPut() {\n sc = new myScanner(new BufferedReader(new InputStreamReader(System.in)));\n pw = new PrintWriter(System.out);\n }\n\n private static void setInAndOutPutFromFile() throws IOException {\n sc = new myScanner(new BufferedReader(new FileReader(new File(fullNameInputFile))));\n pw = new PrintWriter(new File(fullNameOutputFile));\n }\n\n private static final int intINF = Integer.MAX_VALUE;\n private static final long longINF = Long.MAX_VALUE;\n\n private static void solve() {\n int n = sc.nextInt();\n long k =sc.nextLong();\n long[] a = new long[n];\n Long[] array = new Long[100000000];\n int size = 0;\n for (int i=0;i 0;\n }\n\n private void loadBuffer() {\n pos = 0;\n try {\n for (int i; (i = reader.read()) != -1; ) {\n char c = (char) i;\n if (c != ' ' && c != '\\n' && c != '\\t' && c != '\\r' && c != '\\f') {\n if (pos == buffer.length) buffer = Arrays.copyOf(buffer, 2 * pos);\n buffer[pos++] = c;\n } else if (pos != 0) break;\n }\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String current() {\n return String.copyValueOf(buffer, 0, pos);\n }\n\n\n public String next() {\n loadBuffer();\n return current();\n }\n\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n\n public int nextInt() {\n return nextInt(10);\n }\n\n public long nextLong() {\n return nextLong(10);\n }\n\n public int nextInt(int radix) {\n loadBuffer();\n int result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public long nextLong(int radix) {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public int[] nextArrayInts(int size) {\n int[] input = new int[size];\n for (int i = 0; i < size; i++) input[i] = nextInt();\n return input;\n }\n\n public long[] nextArrayLongs(int size) {\n long[] input = new long[size];\n for (int i = 0; i < size; i++) input[i] = nextLong();\n return input;\n }\n\n public double nextDouble() {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n long round = 1;\n final int radix = 10;\n boolean hasPoint = false;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber((0 <= digit && digit <= radix - 1) || (!hasPoint && digit == -2));\n if (digit == -2) hasPoint = true;\n else {\n if (hasPoint) round *= radix;\n result = result * radix + digit;\n }\n\n }\n return buffer[0] == '-' ? -result / (1.0 * round) : result / (1.0 * round);\n }\n\n private void checkValidNumber(boolean condition) {\n if (!condition) throw new NumberFormatException(current());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2489354ed28addf4cfb05829ff2c3dfd", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n private static myScanner sc;\n private static PrintWriter pw;\n\n private static final boolean defaultInAndOutPut = true;\n\n private static final int numberOfTests = 1;\n\n private static final String nameOfInAndOutFile = \"\";\n private static final String fullNameInputFile = nameOfInAndOutFile + \".in\";\n private static final String fullNameOutputFile = nameOfInAndOutFile + \".out\";\n\n public static void main(String[] args) throws IOException {\n if (defaultInAndOutPut) {\n setDefaultInAndOutPut();\n } else {\n setInAndOutPutFromFile();\n }\n for (int test = 1; test <= numberOfTests; test++) {\n solve();\n pw.flush();\n }\n\n pw.close();\n }\n\n private static void setDefaultInAndOutPut() {\n sc = new myScanner(new BufferedReader(new InputStreamReader(System.in)));\n pw = new PrintWriter(System.out);\n }\n\n private static void setInAndOutPutFromFile() throws IOException {\n sc = new myScanner(new BufferedReader(new FileReader(new File(fullNameInputFile))));\n pw = new PrintWriter(new File(fullNameOutputFile));\n }\n\n private static final int intINF = Integer.MAX_VALUE;\n private static final long longINF = Long.MAX_VALUE;\n\n private static void solve() {\n int n = sc.nextInt();\n long k = sc.nextLong();\n long[] a = sc.nextArrayLongs(n);\n long ans =0;\n for (long i=1;i<=10000000;i++) {\n long r = 0;\n for (int j=0;j 0;\n }\n\n private void loadBuffer() {\n pos = 0;\n try {\n for (int i; (i = reader.read()) != -1; ) {\n char c = (char) i;\n if (c != ' ' && c != '\\n' && c != '\\t' && c != '\\r' && c != '\\f') {\n if (pos == buffer.length) buffer = Arrays.copyOf(buffer, 2 * pos);\n buffer[pos++] = c;\n } else if (pos != 0) break;\n }\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String current() {\n return String.copyValueOf(buffer, 0, pos);\n }\n\n\n public String next() {\n loadBuffer();\n return current();\n }\n\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n\n public int nextInt() {\n return nextInt(10);\n }\n\n public long nextLong() {\n return nextLong(10);\n }\n\n public int nextInt(int radix) {\n loadBuffer();\n int result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public long nextLong(int radix) {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public int[] nextArrayInts(int size) {\n int[] input = new int[size];\n for (int i = 0; i < size; i++) input[i] = nextInt();\n return input;\n }\n\n public long[] nextArrayLongs(int size) {\n long[] input = new long[size];\n for (int i = 0; i < size; i++) input[i] = nextLong();\n return input;\n }\n\n public double nextDouble() {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n long round = 1;\n final int radix = 10;\n boolean hasPoint = false;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber((0 <= digit && digit <= radix - 1) || (!hasPoint && digit == -2));\n if (digit == -2) hasPoint = true;\n else {\n if (hasPoint) round *= radix;\n result = result * radix + digit;\n }\n\n }\n return buffer[0] == '-' ? -result / (1.0 * round) : result / (1.0 * round);\n }\n\n private void checkValidNumber(boolean condition) {\n if (!condition) throw new NumberFormatException(current());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "03c201dfddbe1c77e54cedc5b7eaf261", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n private static myScanner sc;\n private static PrintWriter pw;\n\n private static final boolean defaultInAndOutPut = true;\n\n private static final int numberOfTests = 1;\n\n private static final String nameOfInAndOutFile = \"\";\n private static final String fullNameInputFile = nameOfInAndOutFile + \".in\";\n private static final String fullNameOutputFile = nameOfInAndOutFile + \".out\";\n\n public static void main(String[] args) throws IOException {\n if (defaultInAndOutPut) {\n setDefaultInAndOutPut();\n } else {\n setInAndOutPutFromFile();\n }\n for (int test = 1; test <= numberOfTests; test++) {\n solve();\n pw.flush();\n }\n\n pw.close();\n }\n\n private static void setDefaultInAndOutPut() {\n sc = new myScanner(new BufferedReader(new InputStreamReader(System.in)));\n pw = new PrintWriter(System.out);\n }\n\n private static void setInAndOutPutFromFile() throws IOException {\n sc = new myScanner(new BufferedReader(new FileReader(new File(fullNameInputFile))));\n pw = new PrintWriter(new File(fullNameOutputFile));\n }\n\n private static final int intINF = Integer.MAX_VALUE;\n private static final long longINF = Long.MAX_VALUE;\n\n private static void solve() {\n int n = sc.nextInt();\n long k = sc.nextLong();\n long[] a = sc.nextArrayLongs(n);\n long ans =0;\n for (long i=0;i<=10000;i++) {\n long r = 0;\n for (int j=0;j1){\n long mid=(max+min)/2;\n if (mid*i>=a[j]){\n max=mid;\n }else{\n min=mid;\n }\n }\n r+=max*i-a[j];\n }\n if(r<=k)ans=i;\n }\n pw.print(ans);\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\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n\n public int nextInt() {\n return nextInt(10);\n }\n\n public long nextLong() {\n return nextLong(10);\n }\n\n public int nextInt(int radix) {\n loadBuffer();\n int result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public long nextLong(int radix) {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public int[] nextArrayInts(int size) {\n int[] input = new int[size];\n for (int i = 0; i < size; i++) input[i] = nextInt();\n return input;\n }\n\n public long[] nextArrayLongs(int size) {\n long[] input = new long[size];\n for (int i = 0; i < size; i++) input[i] = nextLong();\n return input;\n }\n\n public double nextDouble() {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n long round = 1;\n final int radix = 10;\n boolean hasPoint = false;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber((0 <= digit && digit <= radix - 1) || (!hasPoint && digit == -2));\n if (digit == -2) hasPoint = true;\n else {\n if (hasPoint) round *= radix;\n result = result * radix + digit;\n }\n\n }\n return buffer[0] == '-' ? -result / (1.0 * round) : result / (1.0 * round);\n }\n\n private void checkValidNumber(boolean condition) {\n if (!condition) throw new NumberFormatException(current());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "32f6f02484f8f81c47779eec8517e0cc", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author yittg\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 static class TaskF {\n int n;\n long k;\n long[] a;\n\n private long compute(int d) {\n long c = 0;\n for (int i = 0; i < n; ++i) {\n if (a[i] % d == 0) {\n continue;\n }\n c += d - a[i] % d;\n }\n return c;\n }\n\n private int bi(int v) {\n int l = 0;\n int r = v;\n while (l + 1 < r) {\n int mid = (l + r) / 2;\n long val = compute(mid);\n if (val <= k) {\n l = mid;\n } else {\n r = mid;\n }\n }\n return l;\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n n = in.nextInt();\n k = in.nextLong();\n a = new long[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextLong();\n }\n out.println(bi(Integer.MAX_VALUE));\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa6320fa81b1358295ad498debdc441e", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf690B3 {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int SHIFT = 17;\n\n\tHashSet set;\n\n\tboolean good(long v) {\n\t\tif (set.contains(v)) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (set.contains(u)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\treturn false;\n\t}\n\n\tHashSet seen;\n\n\tvoid dfs(long v, HashSet cur) {\n\t\tcur.add(v);\n\t\tseen.add(v);\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (!cur.contains(u) && good(u)) {\n\t\t\t\t\tdfs(u, cur);\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\tboolean solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (n == 0 && m == 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tlong[] ps = new long[m];\n\n\t\tset = new HashSet<>();\n\t\tseen = new HashSet<>();\n\n\t\tint[] xs = new int[m];\n\t\tint[] ys = new int[m];\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\txs[i] = nextInt();\n\t\t\tys[i] = nextInt();\n\t\t\tps[i] = ((1L * xs[i]) << SHIFT) | ys[i];\n\t\t\tset.add(ps[i]);\n\t\t}\n\t\t\n\t\tif (Arrays.equals(xs, new int[] { 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,\n\t\t\t\t4, 5, 5, 6, 6, 6, 6, 7, 7 })\n\t\t\t\t&& Arrays.equals(ys, new int[] { 1, 2, 3, 4, 5, 1, 2, 3, 5, 3,\n\t\t\t\t\t\t4, 5, 6, 4, 6, 4, 5, 6, 7, 6, 7 })) {\n\t\t\tthrow new AssertionError(\"hmm?\");\n\t\t}\n\n\t\tHashSet set1 = null;\n\n\t\tint setsCount = 0;\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlong tmp = ps[i] + (dx << SHIFT) + dy;\n\t\t\t\t\tif (set.contains(tmp) || seen.contains(tmp)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (++setsCount > 2) {\n\t\t\t\t\t\tthrow new AssertionError(Arrays.toString(xs) + \" \"\n\t\t\t\t\t\t\t\t+ Arrays.toString(ys));\n\t\t\t\t\t}\n\n\t\t\t\t\tHashSet cand = new HashSet<>();\n\t\t\t\t\tdfs(tmp, cand);\n\n\t\t\t\t\tif (set1 == null || set1.size() < cand.size()) {\n\t\t\t\t\t\tset1 = cand;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\n\t\tList a = new ArrayList<>();\n\t\tHashSet setA = new HashSet<>();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 0; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 0; dy++) {\n\t\t\t\t\tint x = xs[i] + dx;\n\t\t\t\t\tint y = ys[i] + dy;\n\t\t\t\t\tlong hash = ((1L * x) << SHIFT) | y;\n\t\t\t\t\tif (setA.contains(hash)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tsetA.add(hash);\n\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\touter: for (int xx = 0; xx <= 1; xx++)\n\t\t\t\t\t\tfor (int yy = 0; yy <= 1; yy++) {\n\t\t\t\t\t\t\tlong hash1 = hash + (xx << SHIFT) + yy;\n\t\t\t\t\t\t\tif (set1.contains(hash1)) {\n\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\tbreak outer;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\ta.add(new Point(x, y));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\n\t\tPoint[] arr = a.toArray(new Point[a.size()]);\n\t\tPoint[] h = convexHull(arr);\n\n\t\tfor (int i = 0, j = h.length - 1; i < j; i++, j--) {\n\t\t\tPoint tmp = h[i];\n\t\t\th[i] = h[j];\n\t\t\th[j] = tmp;\n\t\t}\n\n\t\tint start = 0;\n\t\tfor (int i = 1; i < h.length; i++) {\n\t\t\tif (h[i].x < h[start].x\n\t\t\t\t\t|| (h[i].x == h[start].x && h[i].y < h[start].y)) {\n\t\t\t\tstart = i;\n\t\t\t}\n\t\t}\n\n\t\tout.println(h.length);\n\t\tfor (int i = start; i < h.length; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\tfor (int i = 0; i < start; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tString asPoint(long q) {\n\t\treturn \"(\" + (q >> SHIFT) + \", \" + (q & ((1 << SHIFT) - 1)) + \")\";\n\t}\n\n\tstatic class Point implements Comparable {\n\t\tstatic final Point ZERO = new Point(0, 0);\n\t\tint x, y;\n\n\t\tpublic Point(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\tif (y != o.y)\n\t\t\t\treturn y < o.y ? -1 : 1;\n\t\t\tif (x != o.x)\n\t\t\t\treturn x < o.x ? -1 : 1;\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong vectMul(Point p) {\n\t\t\treturn (long) x * p.y - (long) y * p.x;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x + \", \" + y + \")\";\n\t\t}\n\n\t\tpublic boolean equals(Point p) {\n\t\t\treturn x == p.x && y == p.y;\n\t\t}\n\t}\n\n\tstatic int getTurn(Point A, Point B, Point C) {\n\t\t// angle between AB and AC\n\t\tlong p1 = (long) (B.x - A.x) * (C.y - A.y);\n\t\tlong p2 = (long) (B.y - A.y) * (C.x - A.x);\n\t\tif (p1 == p2)\n\t\t\treturn 0;\n\t\telse\n\t\t\treturn p1 < p2 ? -1 : 1;\n\t}\n\n\t/**\n\t * PERMUTES POINTS IN ARRAY, consider using convexHull(a.clone()) Points\n\t * themselves are modified inside method too, but changes are reverted at\n\t * the end\n\t * \n\t * @param a\n\t * - array of points\n\t * @return convexHull of these point in CCW order, no duplicates, no three\n\t * points on one side\n\t */\n\tstatic Point[] convexHull(Point[] a) {\n\n\t\tif (a == null)\n\t\t\treturn null;\n\t\tif (a.length == 0)\n\t\t\treturn new Point[] {};\n\n\t\tint st = 0;\n\t\tfor (int i = 1; i < a.length; i++)\n\t\t\tif (a[i].compareTo(a[st]) < 0)\n\t\t\t\tst = i;\n\n\t\tPoint tmp = a[0];\n\t\ta[0] = a[st];\n\t\ta[st] = tmp;\n\n\t\tint sx = a[0].x;\n\t\tint sy = a[0].y;\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x -= sx;\n\t\t\ta[i].y -= sy;\n\t\t}\n\n\t\tArrays.sort(a, 1, a.length, new Comparator() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Point o1, Point o2) {\n\t\t\t\tif (o1.equals(o2))\n\t\t\t\t\treturn 0;\n\t\t\t\tif (o1.equals(Point.ZERO)) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (o2.equals(Point.ZERO)) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\tlong val = o1.vectMul(o2);\n\t\t\t\tif (val != 0)\n\t\t\t\t\treturn val > 0 ? -1 : 1;\n\t\t\t\tif (o1.y == 0) {\n\t\t\t\t\treturn o1.x < o2.x ? -1 : 1;\n\t\t\t\t} else {\n\t\t\t\t\treturn o1.y < o2.y ? -1 : 1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tPoint[] h = new Point[a.length];\n\t\tint sz = 0;\n\t\th[sz++] = a[0];\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif (a[i].equals(h[sz - 1]))\n\t\t\t\tcontinue;\n\t\t\twhile (sz > 1 && getTurn(h[sz - 2], h[sz - 1], a[i]) <= 0)\n\t\t\t\tsz--;\n\t\t\th[sz++] = a[i];\n\t\t}\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x += sx;\n\t\t\ta[i].y += sy;\n\t\t}\n\n\t\treturn Arrays.copyOf(h, sz);\n\t}\n\n\tcf690B3() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\twhile (solve())\n\t\t\t;\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cf690B3();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f026a1a070573b5e1176262875cdf54f", "src_uid": "5e1847193148c4e6a998c61f8db61670", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf690B3 {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int SHIFT = 17;\n\n\tHashSet set;\n\n\tboolean good(long v) {\n\t\tif (set.contains(v)) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (set.contains(u)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\treturn false;\n\t}\n\n\tvoid dfs(long v, HashSet cur) {\n\t\tcur.add(v);\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (!cur.contains(u) && good(u)) {\n\t\t\t\t\tdfs(u, cur);\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\tboolean solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (n == 0 && m == 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tlong[] ps = new long[m];\n\n\t\tset = new HashSet<>();\n\n\t\tint[] xs = new int[m];\n\t\tint[] ys = new int[m];\n\n\t\tint idx = 0;\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\txs[i] = nextInt();\n\t\t\tys[i] = nextInt();\n\n\t\t\tif (xs[i] < xs[idx] || (xs[i] == xs[idx] && ys[i] < ys[idx])) {\n\t\t\t\tidx = i;\n\t\t\t}\n\t\t\tps[i] = ((1L * xs[i]) << SHIFT) | ys[i];\n\t\t\tset.add(ps[i]);\n\t\t}\n\n\t\tHashSet set1 = new HashSet<>();\n\t\tdfs(ps[idx] - (1 << SHIFT) - 1, set1);\n\n\t\tList a = new ArrayList<>();\n\t\tHashSet setA = new HashSet<>();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 0; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 0; dy++) {\n\t\t\t\t\tint x = xs[i] + dx;\n\t\t\t\t\tint y = ys[i] + dy;\n\t\t\t\t\tlong hash = ((1L * x) << SHIFT) | y;\n\t\t\t\t\tif (setA.contains(hash)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tsetA.add(hash);\n\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\touter: for (int xx = 0; xx <= 1; xx++)\n\t\t\t\t\t\tfor (int yy = 0; yy <= 1; yy++) {\n\t\t\t\t\t\t\tlong hash1 = hash + (xx << SHIFT) + yy;\n\t\t\t\t\t\t\tif (set1.contains(hash1)) {\n\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\tbreak outer;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\ta.add(new Point(x, y));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\n\t\tPoint[] arr = a.toArray(new Point[a.size()]);\n\t\tPoint[] h = convexHull(arr);\n\n\t\tfor (int i = 0, j = h.length - 1; i < j; i++, j--) {\n\t\t\tPoint tmp = h[i];\n\t\t\th[i] = h[j];\n\t\t\th[j] = tmp;\n\t\t}\n\n\t\tint start = 0;\n\t\tfor (int i = 1; i < h.length; i++) {\n\t\t\tif (h[i].x < h[start].x\n\t\t\t\t\t|| (h[i].x == h[start].x && h[i].y < h[start].y)) {\n\t\t\t\tstart = i;\n\t\t\t}\n\t\t}\n\n\t\tout.println(h.length);\n\t\tfor (int i = start; i < h.length; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\tfor (int i = 0; i < start; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tString asPoint(long q) {\n\t\treturn \"(\" + (q >> SHIFT) + \", \" + (q & ((1 << SHIFT) - 1)) + \")\";\n\t}\n\n\tstatic class Point implements Comparable {\n\t\tstatic final Point ZERO = new Point(0, 0);\n\t\tint x, y;\n\n\t\tpublic Point(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\tif (y != o.y)\n\t\t\t\treturn y < o.y ? -1 : 1;\n\t\t\tif (x != o.x)\n\t\t\t\treturn x < o.x ? -1 : 1;\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong vectMul(Point p) {\n\t\t\treturn (long) x * p.y - (long) y * p.x;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x + \", \" + y + \")\";\n\t\t}\n\n\t\tpublic boolean equals(Point p) {\n\t\t\treturn x == p.x && y == p.y;\n\t\t}\n\t}\n\n\tstatic int getTurn(Point A, Point B, Point C) {\n\t\t// angle between AB and AC\n\t\tlong p1 = (long) (B.x - A.x) * (C.y - A.y);\n\t\tlong p2 = (long) (B.y - A.y) * (C.x - A.x);\n\t\tif (p1 == p2)\n\t\t\treturn 0;\n\t\telse\n\t\t\treturn p1 < p2 ? -1 : 1;\n\t}\n\n\t/**\n\t * PERMUTES POINTS IN ARRAY, consider using convexHull(a.clone()) Points\n\t * themselves are modified inside method too, but changes are reverted at\n\t * the end\n\t * \n\t * @param a\n\t * - array of points\n\t * @return convexHull of these point in CCW order, no duplicates, no three\n\t * points on one side\n\t */\n\tstatic Point[] convexHull(Point[] a) {\n\n\t\tif (a == null)\n\t\t\treturn null;\n\t\tif (a.length == 0)\n\t\t\treturn new Point[] {};\n\n\t\tint st = 0;\n\t\tfor (int i = 1; i < a.length; i++)\n\t\t\tif (a[i].compareTo(a[st]) < 0)\n\t\t\t\tst = i;\n\n\t\tPoint tmp = a[0];\n\t\ta[0] = a[st];\n\t\ta[st] = tmp;\n\n\t\tint sx = a[0].x;\n\t\tint sy = a[0].y;\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x -= sx;\n\t\t\ta[i].y -= sy;\n\t\t}\n\n\t\tArrays.sort(a, 1, a.length, new Comparator() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Point o1, Point o2) {\n\t\t\t\tif (o1.equals(o2))\n\t\t\t\t\treturn 0;\n\t\t\t\tif (o1.equals(Point.ZERO)) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (o2.equals(Point.ZERO)) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\tlong val = o1.vectMul(o2);\n\t\t\t\tif (val != 0)\n\t\t\t\t\treturn val > 0 ? -1 : 1;\n\t\t\t\tif (o1.y == 0) {\n\t\t\t\t\treturn o1.x < o2.x ? -1 : 1;\n\t\t\t\t} else {\n\t\t\t\t\treturn o1.y < o2.y ? -1 : 1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tPoint[] h = new Point[a.length];\n\t\tint sz = 0;\n\t\th[sz++] = a[0];\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif (a[i].equals(h[sz - 1]))\n\t\t\t\tcontinue;\n\t\t\twhile (sz > 1 && getTurn(h[sz - 2], h[sz - 1], a[i]) <= 0)\n\t\t\t\tsz--;\n\t\t\th[sz++] = a[i];\n\t\t}\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x += sx;\n\t\t\ta[i].y += sy;\n\t\t}\n\n\t\treturn Arrays.copyOf(h, sz);\n\t}\n\n\tcf690B3() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\twhile (solve())\n\t\t\t;\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cf690B3();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "52300ee25eb6271a1a7d962b54071e6d", "src_uid": "5e1847193148c4e6a998c61f8db61670", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf690B3 {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int SHIFT = 17;\n\n\tHashSet set;\n\n\tboolean good(long v) {\n\t\tif (set.contains(v)) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (set.contains(u)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\treturn false;\n\t}\n\n\tvoid dfs(long v, HashSet cur) {\n\t\tcur.add(v);\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (!cur.contains(u) && good(u)) {\n\t\t\t\t\tdfs(u, cur);\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\tboolean solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (n == 0 && m == 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tlong[] ps = new long[m];\n\n\t\tset = new HashSet<>();\n\n\t\tint[] xs = new int[m];\n\t\tint[] ys = new int[m];\n\n\t\tint idx = 0;\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\txs[i] = nextInt();\n\t\t\tys[i] = nextInt();\n\n\t\t\tif (xs[i] < xs[idx] || (xs[i] == xs[idx] && ys[i] < ys[idx])) {\n\t\t\t\tidx = i;\n\t\t\t}\n\t\t\tps[i] = ((1L * xs[i]) << SHIFT) | ys[i];\n\t\t\tset.add(ps[i]);\n\t\t}\n\n\t\tHashSet set1 = new HashSet<>();\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlong tmp = ps[idx] - (1 << SHIFT) - 1;\n\t\t\t\t\tdfs(tmp, set1);\n\n\t\t\t\t}\n\t\t}\n\n\t\tList a = new ArrayList<>();\n\t\tHashSet setA = new HashSet<>();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 0; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 0; dy++) {\n\t\t\t\t\tint x = xs[i] + dx;\n\t\t\t\t\tint y = ys[i] + dy;\n\t\t\t\t\tlong hash = ((1L * x) << SHIFT) | y;\n\t\t\t\t\tif (setA.contains(hash)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tsetA.add(hash);\n\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\touter: for (int xx = 0; xx <= 1; xx++)\n\t\t\t\t\t\tfor (int yy = 0; yy <= 1; yy++) {\n\t\t\t\t\t\t\tlong hash1 = hash + (xx << SHIFT) + yy;\n\t\t\t\t\t\t\tif (set1.contains(hash1)) {\n\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\tbreak outer;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\ta.add(new Point(x, y));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\n\t\tPoint[] arr = a.toArray(new Point[a.size()]);\n\t\tPoint[] h = convexHull(arr);\n\n\t\tfor (int i = 0, j = h.length - 1; i < j; i++, j--) {\n\t\t\tPoint tmp = h[i];\n\t\t\th[i] = h[j];\n\t\t\th[j] = tmp;\n\t\t}\n\n\t\tint start = 0;\n\t\tfor (int i = 1; i < h.length; i++) {\n\t\t\tif (h[i].x < h[start].x\n\t\t\t\t\t|| (h[i].x == h[start].x && h[i].y < h[start].y)) {\n\t\t\t\tstart = i;\n\t\t\t}\n\t\t}\n\n\t\tout.println(h.length);\n\t\tfor (int i = start; i < h.length; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\tfor (int i = 0; i < start; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tString asPoint(long q) {\n\t\treturn \"(\" + (q >> SHIFT) + \", \" + (q & ((1 << SHIFT) - 1)) + \")\";\n\t}\n\n\tstatic class Point implements Comparable {\n\t\tstatic final Point ZERO = new Point(0, 0);\n\t\tint x, y;\n\n\t\tpublic Point(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\tif (y != o.y)\n\t\t\t\treturn y < o.y ? -1 : 1;\n\t\t\tif (x != o.x)\n\t\t\t\treturn x < o.x ? -1 : 1;\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong vectMul(Point p) {\n\t\t\treturn (long) x * p.y - (long) y * p.x;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x + \", \" + y + \")\";\n\t\t}\n\n\t\tpublic boolean equals(Point p) {\n\t\t\treturn x == p.x && y == p.y;\n\t\t}\n\t}\n\n\tstatic int getTurn(Point A, Point B, Point C) {\n\t\t// angle between AB and AC\n\t\tlong p1 = (long) (B.x - A.x) * (C.y - A.y);\n\t\tlong p2 = (long) (B.y - A.y) * (C.x - A.x);\n\t\tif (p1 == p2)\n\t\t\treturn 0;\n\t\telse\n\t\t\treturn p1 < p2 ? -1 : 1;\n\t}\n\n\t/**\n\t * PERMUTES POINTS IN ARRAY, consider using convexHull(a.clone()) Points\n\t * themselves are modified inside method too, but changes are reverted at\n\t * the end\n\t * \n\t * @param a\n\t * - array of points\n\t * @return convexHull of these point in CCW order, no duplicates, no three\n\t * points on one side\n\t */\n\tstatic Point[] convexHull(Point[] a) {\n\n\t\tif (a == null)\n\t\t\treturn null;\n\t\tif (a.length == 0)\n\t\t\treturn new Point[] {};\n\n\t\tint st = 0;\n\t\tfor (int i = 1; i < a.length; i++)\n\t\t\tif (a[i].compareTo(a[st]) < 0)\n\t\t\t\tst = i;\n\n\t\tPoint tmp = a[0];\n\t\ta[0] = a[st];\n\t\ta[st] = tmp;\n\n\t\tint sx = a[0].x;\n\t\tint sy = a[0].y;\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x -= sx;\n\t\t\ta[i].y -= sy;\n\t\t}\n\n\t\tArrays.sort(a, 1, a.length, new Comparator() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Point o1, Point o2) {\n\t\t\t\tif (o1.equals(o2))\n\t\t\t\t\treturn 0;\n\t\t\t\tif (o1.equals(Point.ZERO)) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (o2.equals(Point.ZERO)) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\tlong val = o1.vectMul(o2);\n\t\t\t\tif (val != 0)\n\t\t\t\t\treturn val > 0 ? -1 : 1;\n\t\t\t\tif (o1.y == 0) {\n\t\t\t\t\treturn o1.x < o2.x ? -1 : 1;\n\t\t\t\t} else {\n\t\t\t\t\treturn o1.y < o2.y ? -1 : 1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tPoint[] h = new Point[a.length];\n\t\tint sz = 0;\n\t\th[sz++] = a[0];\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif (a[i].equals(h[sz - 1]))\n\t\t\t\tcontinue;\n\t\t\twhile (sz > 1 && getTurn(h[sz - 2], h[sz - 1], a[i]) <= 0)\n\t\t\t\tsz--;\n\t\t\th[sz++] = a[i];\n\t\t}\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x += sx;\n\t\t\ta[i].y += sy;\n\t\t}\n\n\t\treturn Arrays.copyOf(h, sz);\n\t}\n\n\tcf690B3() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\twhile (solve())\n\t\t\t;\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cf690B3();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ebd97b7fe7582ee8d0ff35a24b9b5d56", "src_uid": "5e1847193148c4e6a998c61f8db61670", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf690B3 {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int SHIFT = 17;\n\n\tHashSet set;\n\n\tboolean good(long v) {\n\t\tif (set.contains(v)) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (set.contains(u)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\treturn false;\n\t}\n\n\tvoid dfs(long v, HashSet cur) {\n\t\tcur.add(v);\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (!cur.contains(u) && good(u)) {\n\t\t\t\t\tdfs(u, cur);\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\tboolean solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (n == 0 && m == 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tlong[] ps = new long[m];\n\n\t\tset = new HashSet<>();\n\n\t\tint[] xs = new int[m];\n\t\tint[] ys = new int[m];\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\txs[i] = nextInt();\n\t\t\tys[i] = nextInt();\n\t\t\tps[i] = ((1L * xs[i]) << SHIFT) | ys[i];\n\t\t\tset.add(ps[i]);\n\t\t}\n\n\t\tHashSet set1 = null, set2 = null;\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlong tmp = ps[i] + (dx << SHIFT) + dy;\n\t\t\t\t\tif (set.contains(tmp)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (set1 == null) {\n\t\t\t\t\t\tset1 = new HashSet<>();\n\t\t\t\t\t\tdfs(tmp, set1);\n\n\t\t\t\t\t\t// System.err.println(\"set1\");\n\t\t\t\t\t\t// for (long q : set1) {\n\t\t\t\t\t\t// System.err.println(asPoint(q));\n\t\t\t\t\t\t// }\n\t\t\t\t\t} else if (set1.contains(tmp)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else if (set2 == null) {\n\t\t\t\t\t\tset2 = new HashSet<>();\n\t\t\t\t\t\tdfs(tmp, set2);\n\n\t\t\t\t\t\t// System.err.println(\"set2\");\n\t\t\t\t\t\t// for (long q : set2) {\n\t\t\t\t\t\t// System.err.println(asPoint(q));\n\t\t\t\t\t\t// }\n\t\t\t\t\t} else if (!set2.contains(tmp)) {\n\t\t\t\t\t\t// throw new AssertionError(\"too many regions\");\n\t\t\t\t\t\twhile (true)\n\t\t\t\t\t\t\t;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\n\t\tif (set2 != null && set1.size() < set2.size()) {\n\t\t\tHashSet tmp = set1;\n\t\t\tset1 = set2;\n\t\t\tset2 = tmp;\n\t\t}\n\n\t\tList a = new ArrayList<>();\n\t\tHashSet setA = new HashSet<>();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 0; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 0; dy++) {\n\t\t\t\t\tint x = xs[i] + dx;\n\t\t\t\t\tint y = ys[i] + dy;\n\t\t\t\t\tlong hash = ((1L * x) << SHIFT) | y;\n\t\t\t\t\tif (setA.contains(hash)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tsetA.add(hash);\n\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\touter: for (int xx = 0; xx <= 1; xx++)\n\t\t\t\t\t\tfor (int yy = 0; yy <= 1; yy++) {\n\t\t\t\t\t\t\tlong hash1 = hash + (xx << SHIFT) + yy;\n\t\t\t\t\t\t\tif (set1.contains(hash1)) {\n\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\tbreak outer;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\tif (ok) {\n\t\t\t\t\t\ta.add(new Point(x, y));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\n\t\tPoint[] arr = a.toArray(new Point[a.size()]);\n\t\tPoint[] h = convexHull(arr);\n\n\t\tfor (int i = 0, j = h.length - 1; i < j; i++, j--) {\n\t\t\tPoint tmp = h[i];\n\t\t\th[i] = h[j];\n\t\t\th[j] = tmp;\n\t\t}\n\n\t\tint start = 0;\n\t\tfor (int i = 1; i < h.length; i++) {\n\t\t\tif (h[i].x < h[start].x\n\t\t\t\t\t|| (h[i].x == h[start].x && h[i].y < h[start].y)) {\n\t\t\t\tstart = i;\n\t\t\t}\n\t\t}\n\n\t\tout.println(h.length);\n\t\tfor (int i = start; i < h.length; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\tfor (int i = 0; i < start; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tString asPoint(long q) {\n\t\treturn \"(\" + (q >> SHIFT) + \", \" + (q & ((1 << SHIFT) - 1)) + \")\";\n\t}\n\n\tstatic class Point implements Comparable {\n\t\tstatic final Point ZERO = new Point(0, 0);\n\t\tint x, y;\n\n\t\tpublic Point(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\tif (y != o.y)\n\t\t\t\treturn y < o.y ? -1 : 1;\n\t\t\tif (x != o.x)\n\t\t\t\treturn x < o.x ? -1 : 1;\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong vectMul(Point p) {\n\t\t\treturn (long) x * p.y - (long) y * p.x;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x + \", \" + y + \")\";\n\t\t}\n\n\t\tpublic boolean equals(Point p) {\n\t\t\treturn x == p.x && y == p.y;\n\t\t}\n\t}\n\n\tstatic int getTurn(Point A, Point B, Point C) {\n\t\t// angle between AB and AC\n\t\tlong p1 = (long) (B.x - A.x) * (C.y - A.y);\n\t\tlong p2 = (long) (B.y - A.y) * (C.x - A.x);\n\t\tif (p1 == p2)\n\t\t\treturn 0;\n\t\telse\n\t\t\treturn p1 < p2 ? -1 : 1;\n\t}\n\n\t/**\n\t * PERMUTES POINTS IN ARRAY, consider using convexHull(a.clone()) Points\n\t * themselves are modified inside method too, but changes are reverted at\n\t * the end\n\t * \n\t * @param a\n\t * - array of points\n\t * @return convexHull of these point in CCW order, no duplicates, no three\n\t * points on one side\n\t */\n\tstatic Point[] convexHull(Point[] a) {\n\n\t\tif (a == null)\n\t\t\treturn null;\n\t\tif (a.length == 0)\n\t\t\treturn new Point[] {};\n\n\t\tint st = 0;\n\t\tfor (int i = 1; i < a.length; i++)\n\t\t\tif (a[i].compareTo(a[st]) < 0)\n\t\t\t\tst = i;\n\n\t\tPoint tmp = a[0];\n\t\ta[0] = a[st];\n\t\ta[st] = tmp;\n\n\t\tint sx = a[0].x;\n\t\tint sy = a[0].y;\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x -= sx;\n\t\t\ta[i].y -= sy;\n\t\t}\n\n\t\tArrays.sort(a, 1, a.length, new Comparator() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Point o1, Point o2) {\n\t\t\t\tif (o1.equals(o2))\n\t\t\t\t\treturn 0;\n\t\t\t\tif (o1.equals(Point.ZERO)) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (o2.equals(Point.ZERO)) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\tlong val = o1.vectMul(o2);\n\t\t\t\tif (val != 0)\n\t\t\t\t\treturn val > 0 ? -1 : 1;\n\t\t\t\tif (o1.y == 0) {\n\t\t\t\t\treturn o1.x < o2.x ? -1 : 1;\n\t\t\t\t} else {\n\t\t\t\t\treturn o1.y < o2.y ? -1 : 1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tPoint[] h = new Point[a.length];\n\t\tint sz = 0;\n\t\th[sz++] = a[0];\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif (a[i].equals(h[sz - 1]))\n\t\t\t\tcontinue;\n\t\t\twhile (sz > 1 && getTurn(h[sz - 2], h[sz - 1], a[i]) <= 0)\n\t\t\t\tsz--;\n\t\t\th[sz++] = a[i];\n\t\t}\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x += sx;\n\t\t\ta[i].y += sy;\n\t\t}\n\n\t\treturn Arrays.copyOf(h, sz);\n\t}\n\n\tcf690B3() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\twhile (solve())\n\t\t\t;\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cf690B3();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ea1bcbb1f611cefde9386aba21264428", "src_uid": "5e1847193148c4e6a998c61f8db61670", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\n\n\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\nimport java.util.TreeSet;\n\n\n\npublic final class CF_114_E{\n\tstatic boolean verb=true;\n\tstatic void log(Object X){if (verb) System.err.println(X);}\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void logWln(Object X){if (verb) System.err.print(X);}\n\tstatic void info(Object o){\tSystem.out.println(o);}\n\tstatic void output(Object o){outputWln(\"\"+o+\"\\n\");\t}\n\tstatic void outputWln(Object o){try {out.write(\"\"+ o);} catch (Exception e) {}}\n\n\n\tstatic int MX=Integer.MAX_VALUE;\n\n\n\tstatic boolean solve(long a,long b){\n\t\t//log(\"a:\"+a+\" b:\"+b);\n\t\tif (a==0 || b==0)\n\t\t\treturn false;\n\t\tif (a==b)\n\t\t\treturn true;\n\t\tif (a>b){\n\t\t\tlong c=a;\n\t\t\ta=b;\n\t\t\tb=c;\n\t\t}\n\t\n\t\t\n\t\tlong ob=b;\n\t\tif (a+10)\n\t\t\treturn solve(a,ob);\n\t\t\n\t\tif (b%a==0)\n\t\t\treturn true;\n\t\tlong aa=1;\n\t\tloop:while (aa<=b/a){\n\t\t\taa*=a;\n\t\t\t\n\t\t\tif (!solve(b-aa,a))\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t\t\n\t}\n\n\n\tstatic void check(){\n\t\tlog(\"checking\");\n\t\tfor (int x=1;x<100;x++)\n\t\t\tfor (int y=3;y> \"+solve(x,y));\n\t}\n\n\n\n\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\tstatic int MAX=201;\n\n\tstatic void process() throws Exception {\n\n\n\t\t//check();\n\t\t//test();\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader=new InputReader(System.in);\n\n\t\tint T=reader.readInt();\n\t\tfor (int t=0;t= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\n\t\tpublic final String readString() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res=new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.append((char)c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic final int readInt() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\t\tpublic final long readLong() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\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\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "79ee514b4b01e56adbedc1247b9bac2b", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\n\n\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\nimport java.util.TreeSet;\n\n\n\npublic final class CF_114_E{\n\tstatic boolean verb=true;\n\tstatic void log(Object X){if (verb) System.err.println(X);}\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void logWln(Object X){if (verb) System.err.print(X);}\n\tstatic void info(Object o){\tSystem.out.println(o);}\n\tstatic void output(Object o){outputWln(\"\"+o+\"\\n\");\t}\n\tstatic void outputWln(Object o){try {out.write(\"\"+ o);} catch (Exception e) {}}\n\n\n\tstatic int MX=Integer.MAX_VALUE;\n\n\n\tstatic boolean solve(long a,long b){\n\t\t//log(\"a:\"+a+\" b:\"+b);\n\t\tif (a==0 || b==0)\n\t\t\treturn false;\n\t\tif (a==b)\n\t\t\treturn true;\n\t\tif (a>b){\n\t\t\tlong c=a;\n\t\t\ta=b;\n\t\t\tb=c;\n\t\t}\n\t\n\t\t\n\t\tlong ob=b;\n\t\tif (a+10)\n\t\t\treturn solve(a,ob);\n\t\t\tob=a*(a+1);\n\t\t\treturn solve(a,ob);\n\t\t}\n\t\tif (b%a==0)\n\t\t\treturn true;\n\t\tlong aa=1;\n\t\tloop:while (aa<=b/a){\n\t\t\taa*=a;\n\t\t\t\n\t\t\tif (!solve(b-aa,a))\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t\t\n\t}\n\n\n\tstatic void check(){\n\t\tlog(\"checking\");\n\t\tfor (int x=1;x<100;x++)\n\t\t\tfor (int y=3;y> \"+solve(x,y));\n\t}\n\n\n\n\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\tstatic int MAX=201;\n\n\tstatic void process() throws Exception {\n\n\n\t\t//check();\n\t\t//test();\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader=new InputReader(System.in);\n\n\t\tint T=reader.readInt();\n\t\tfor (int t=0;t= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\n\t\tpublic final String readString() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res=new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.append((char)c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic final int readInt() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\t\tpublic final long readLong() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\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\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d19c597d91def29bf0d539f9231e28f1", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class popo {\n\n public static boolean prime[];\n public static ArrayList[] ad=new ArrayList[2555];\n public static ArrayList xor1,xor2;\n static int []min;\n static char [][]grid;\n static int []dx = {0,0,-1,1};\n static int []dy = {-1,1,0,0};\n static int []dx8 = {1,1,1,0,-1,-1,-1,0};\n static int []dy8 = {1,0,-1,-1,-1,0,1,1};\n static ArrayList aa;\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int t = in.nextInt();\n while (t-->0)\n {\n int a = in.nextInt();\n int b = in.nextInt();\n boolean k =winner(a,b);\n if(k)\n out.println(\"First\");\n else\n out.println(\"Second\");\n\n }\n\n out.close();\n }\n static boolean winner(int a ,int b)\n {\n if(a==0 || b==0)\n return false;\n if(a>b)\n {\n int t = a;\n a = b;\n b = t;\n }\n if(!winner(a,b%a))return true;\n int l =0;\n if(a!=0) {\n l = b / a;\n }\n a = a+1;\n return ((l)%2 == 0);\n }\n\n public static long modPow(long base, long exp, long mod) {\n base = base % mod;\n long result = 1;\n while(exp > 0)\n {\n if(exp % 2== 1)\n {\n result = (result * base) % mod;\n exp --;\n }\n else\n {\n base = (base * base) % mod;\n exp = exp >> 1;\n }\n\n }\n return result;\n }\n\n public static long mod = 1000000007, inf = 100000000000000000l;\n public static long fac[],inv[];\n public static void cal()\n {\n fac = new long[100001];\n inv = new long[100001];\n fac[0]=1;\n inv[0]=1;\n for(int i=1; i<=100000; i++)\n {\n fac[i]=(fac[i-1]*i)%mod;\n // inv[i]=(inv[i-1]*modPow(i,mod-2,mod))%mod;\n\n }\n }\n public static long combination(long n, long r)\n {\n long k = (fac[(int) n]%mod*inv[(int) r]%mod)%mod;\n long p = inv[(int) (n-r)]%mod;\n long m = (k*p)%mod;\n return m;\n }\n\n\n public static class Point implements Comparable {\n\n long x, y;\n\n public Point(long start, long end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = (int) (47 * hash + this.x);\n hash = (int) (47 * hash + this.y);\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Long.compare(x, o.x);\n }\n }\n static long setbits(long i)\n {\n long count = 0;\n while (i>0)\n {\n count += i & 1;\n i >>= 1;\n }\n return count;\n\n }\n\n static ArrayList sieveOfEratosthenes(int n)\n {\n // Create a boolean array \"prime[0..n]\" and initialize\n // all entries it as true. A value in prime[i] will\n // finally be false if i is Not a prime, else true.\n\n\n prime=new boolean[1000001];\n for(int i=0;i aa=new ArrayList<>();\n for (long i=0;i= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public String readString() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4fa5c54a0d449af0bd22b4d5610e4603", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\n\n\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\nimport java.util.TreeSet;\n\n\n\npublic final class CF_114_E{\n\tstatic boolean verb=true;\n\tstatic void log(Object X){if (verb) System.err.println(X);}\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void logWln(Object X){if (verb) System.err.print(X);}\n\tstatic void info(Object o){\tSystem.out.println(o);}\n\tstatic void output(Object o){outputWln(\"\"+o+\"\\n\");\t}\n\tstatic void outputWln(Object o){try {out.write(\"\"+ o);} catch (Exception e) {}}\n\n\n\tstatic int MX=Integer.MAX_VALUE;\n\n\n\tstatic boolean solve(long a,long b){\n\t\t//log(\"a:\"+a+\" b:\"+b);\n\t\tif (a==0 || b==0)\n\t\t\treturn false;\n\t\tif (a==b)\n\t\t\treturn true;\n\t\tif (a>b){\n\t\t\tlong c=a;\n\t\t\ta=b;\n\t\t\tb=c;\n\t\t}\n\t\tif (b%a==0)\n\t\t\treturn true;\n\t\tlong aa=1;\n\t\tloop:while (aa<=b/a){\n\t\t\taa*=a;\n\t\t\tif (!solve(b-aa,a))\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t\t\n\t}\n\n\n\n\n\n\n\n\t// Global vars\n\tstatic BufferedWriter out;\n\tstatic InputReader reader;\n\n\tstatic int MAX=201;\n\n\tstatic void process() throws Exception {\n\n\n\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader=new InputReader(System.in);\n\n\t\tint T=reader.readInt();\n\t\tfor (int t=0;t= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\n\t\tpublic final String readString() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res=new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.append((char)c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic final int readInt() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\t\tpublic final long readLong() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\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\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "30cc8345c331b290be93f11f439ca81b", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "package McNuggets;\n\nimport java.util.Scanner;\n\npublic class zombiesAndBrainsA1 {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner console = new Scanner(System.in);\n\t\tint n = console.nextInt();\n\t\tSystem.out.println(n/2+n%2);\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "95c0707c1a06c985ab352f29c37f5ba7", "src_uid": "30e95770f12c631ce498a2b20c2931c7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package com.quantis_intl.stack;\n\nimport java.util.Scanner;\n\npublic class Main\n{\n public static final void main(String[] args)\n {\n Scanner s = new Scanner(System.in);\n int val = s.nextInt();\n System.out.println((val / 2) + (val % 2));\n s.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "120441c527e61203428c4d312c5bff0a", "src_uid": "30e95770f12c631ce498a2b20c2931c7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class c{\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n System.out.println(Math.ceil(in.nextDouble()/2));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "366afb34e63ce1c7a02f7fb3c1aa9dbd", "src_uid": "30e95770f12c631ce498a2b20c2931c7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "/*\n * Solution_690_A1.java\n * Copyright (C) 2017 tri \n *\n * Distributed under terms of the MIT license.\n */\nimport java.util.*;\nimport java.io.*;\npublic class Solution_690_A1\n{\n\tprivate static String INPUT_FILE=\"690_A1.txt\";\n\tpublic Solution_690_A1() {\n\t}\n\tpublic static void main(String[] args){\n\t\ttry(\n\t\t\t//Scanner sc = new Scanner(new FileInputStream(INPUT_FILE));\n\t\t\tScanner sc = new Scanner(System.in);\n\t\t )\n\t\t{\n\t\t\tInteger totalNum = sc.nextInt();\n\t\t\ttotalNum = (totalNum/2)+(totalNum%2);\n\t\t\tSystem.out.print(totalNum);\n\t\t}\n\t\tcatch(IOException e){\n\t\t\tSystem.out.println(e);\n\t\t}\n\t\t\t\n\n\t\treturn;\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8f7f6efd14073b78ea9b4af75654fbae", "src_uid": "30e95770f12c631ce498a2b20c2931c7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author ijxjdjd\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 Cards solver = new Cards();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Cards {\n long MOD = 998244353;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long N = in.nextInt();\n long M = in.nextInt();\n int K = in.nextInt();\n long mod = MathUtils.modFraction(1, M, MOD);\n long[] expect = new long[K + 1];\n expect[0] = 1;\n long[] poly = new long[K + 1];\n poly[0] = 1;\n long curExpect = 1;\n for (int k = 1; k <= K; k++) {\n curExpect *= (N - (k - 1));\n curExpect %= MOD;\n curExpect *= mod;\n curExpect %= MOD;\n for (int i = k; i >= 0; i--) {\n poly[i] = (i > 0 ? poly[i - 1] : 0) + (-(k - 1)) * poly[i];\n poly[i] = MathUtils.mod(poly[i], MOD);\n }\n expect[k] = curExpect;\n for (int i = k - 1; i >= 0; i--) {\n expect[k] -= poly[i] * expect[i];\n expect[k] = MathUtils.mod(expect[k], MOD);\n }\n }\n out.println(expect[K]);\n }\n\n }\n\n static class MathUtils {\n public static long inverse(long a, long mod) {\n long[] inv = extended_gcd(a, mod);\n if (inv[0] != 1) {\n return 0;\n } else {\n return (inv[1] + 2 * mod) % mod;\n }\n }\n\n public static long modFraction(long a, long b, long mod) {\n //a is numerator, b is denominator\n long invB = inverse(b, mod);\n if (invB == 0) {\n return -1;\n } else {\n return (invB * a) % mod;\n }\n }\n\n public static long[] extended_gcd(long a, long b) {\n //three numbers, first is gcd, second is x, third is y\n if (a == 0) {\n return new long[]{b, 0, 1};\n }\n long[] next = extended_gcd(b % a, a);\n long tempX = next[1];\n next[1] = next[2] - (b / a) * next[1];\n next[2] = tempX;\n return next;\n }\n\n public static long mod(long a, long mod) {\n return (a + (Math.abs(a) + mod - 1) / mod * mod) % mod;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "929057044fff1520f3ea87cf31bdd0be", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n \n \npublic class q5 {\n\tstatic long[][] dp;\n\tstatic int m,n;\n\tstatic long mod=998244353;\n\tstatic long modPow(long a, long b) {\n\t\tlong res=1;\n\t\twhile(b>0) {\n\t\t\tif((b&1)==1) res*=a;\n\t\t\tres%=mod;\n\t\t\ta*=a;a%=mod;b/=2;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tstatic long solve(int k, int b) {\n\t\tif(k==0) {\n\t\t\treturn modPow(m,n-b);\n\t\t}\n\t\tif(dp[k][b]==-1) {\n\t\t\tif(b==0) {\n\t\t\t\tdp[k][b]= (n)* solve(k-1,b+1);\n\t\t\t\tdp[k][b]%=mod;\n\t\t\t}\n\t\t\telse if(b==n) {\n\t\t\t\tdp[k][b]=b*solve(k-1,b);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdp[k][b]=(b*solve(k-1,b))%mod+ ((n-b)*solve(k-1,b+1))%mod;;\n\t\t\t}\n\t\t}\n\t\tdp[k][b]%=mod;\n\t\treturn dp[k][b];\n\t}\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\tn=Reader.nextInt();m=Reader.nextInt();\n\t\tint k=Reader.nextInt();\n\t\tdp=new long[k+5][k+5];\n\t\tfor(int i=0;i<=k;i++) {\n\t\t\tArrays.fill(dp[i], -1);\n\t\t}\n\t\tlong ans=solve(k,0);\n\t\tans*= modPow(modPow(m,n),mod-2);\n\t\tans%=mod;\n\t\tout.println(ans);\n\t\t\n\t\tout.flush();\n\t}\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b5b9127817d7b57d42c1d2210f2e4bdd", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.0} {"lang": "Java 11", "source_code": "// Coached by rainboy\n// https://codeforces.com/contest/1278/submission/67223059 (rainboy)\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1278F extends PrintWriter {\n\tCF1278F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1278F o = new CF1278F(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 998244353;\n\tint d_, x_, y_;\n\tvoid gcd_(int a, int b) {\n\t\tif (b == 0) {\n\t\t\td_ = a; x_ = 1; y_ = 0;\n\t\t} else {\n\t\t\tgcd_(b, a % b);\n\t\t\tint t = x_ - a / b * y_; x_ = y_; y_ = t;\n\t\t}\n\t}\n\tint inv(int a) {\n\t\tgcd_(a, MD);\n\t\treturn x_ < 0 ? x_ + MD : x_;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt(), m_ = inv(m);\n\t\tint k = sc.nextInt();\n\t\tint[] dp = new int[k + 1]; dp[0] = 1;\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tfor (int d = k - 1; d >= 0; d--)\n\t\t\t\tif (dp[d] != 0) {\n\t\t\t\t\tdp[d + 1] = (int) ((dp[d + 1] + (long) dp[d] * (n - d)) % MD);\n\t\t\t\t\tdp[d] = (int) ((long) dp[d] * d % MD);\n\t\t\t\t}\n\t\tlong p = 1, ans = 0;\n\t\tfor (int d = 1; d <= k; d++) {\n\t\t\tp = p * m_ % MD;\n\t\t\tans = (ans + dp[d] * p) % MD;\n\t\t}\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8654bab76dbe79273d0c9a55893e1fc6", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.text.*;\n\npublic class F1278 {\n\n\tstatic long[][] comb; // may need BigInteger, if the numbers are large, use a treemap\n\n\tstatic long modInverse(long a, long mod) {\n\t\treturn BigInteger.valueOf(a).modInverse(BigInteger.valueOf(mod)).longValue();\n\t}\n\n\tstatic long modPow(long a, long e, long mod) // O(log e)\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\n//\tstatic long nCr1(int n, int k) {\n//\t\tif (n < k)\n//\t\t\treturn 0;\n//\t\tif (k == 0 || k == n)\n//\t\t\treturn 1;\n//\t\tif (comb[n][k] != -1)\n//\t\t\treturn comb[n][k];\n//\t\tif (n - k < k)\n//\t\t\treturn comb[n][k] = nCr1(n, n - k);\n//\t\treturn comb[n][k] = ((nCr1(n - 1, k - 1) + nCr1(n - 1, k)) % mod);\n//\t}\n\n\tstatic long mod = 998244353;\n\n//\tstatic long sum(long n, long k, long m) {\n//\t\tlong sum = 0;\n//\t\tfor (int i = 0; i <= n; i++) {\n//\t\t\tlong w = modPow(i, k, mod);\n//\t\t\tw *= nCr1((int) n, i) % mod;\n//\t\t\tw %= mod;\n//\t\t\tw *= modPow(m - 1,i, mod);\n//\t\t\tw %= mod;\n//\t\t\tsum += w;\n//\t\t\tsum %= mod;\n//\t\t}\n//\t\tSystem.out.println(sum);\n//\t\tsum *= modPow(modInverse(m, mod), n, mod);\n//\t\tsum %= mod;\n//\t\treturn sum;\n//\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tlong n = sc.nextInt();\n\t\tlong m = sc.nextInt();\n\t\tint k = sc.nextInt();\n//\t\tcomb = new long[(int) n + 1][(int) n + 1];\n//\t\tfor (long[] xx : comb)\n//\t\t\tArrays.fill(xx, -1);\n\t\tlong[] c = new long[k];\n\t\tlong[] nP = new long[k + 1];\n\t\tnP[0] = 1;\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t\tnP[i] = ((n - i + 1) * nP[i - 1]) % mod;\n\t\t}\n\t\tc[0] = 1;\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tlong mult = 1;\n\t\t\tfor (int j = i; j > 0; j--) {\n\t\t\t\tc[j] += (mult * c[j - 1]) % mod;\n\t\t\t\tc[j] %= mod;\n\t\t\t\tmult++;\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tlong w = 1;\n\t\t\tw *= c[i] * nP[k - i];\n\t\t\tw %= mod;\n\t\t\tw *= modPow(m, n - (k - i), mod);\n\t\t\tw %= mod;\n\t\t\tans += w;\n\t\t\tans %= mod;\n//\t\t\tpw.println(ans);\n\t\t}\n//\t\tpw.println(ans);\n\t\tans *= modPow(modInverse(m, mod), n, mod);\n\t\tans %= mod;\n//\t\tpw.println(Arrays.toString(nP));\n//\t\tpw.println(Arrays.toString(c));\n\t\tpw.println(ans);\n//\t\tpw.println(sum(n, k, m));\n\t\tpw.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(FileReader r) {\n\t\t\tbr = new BufferedReader(r);\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif (x.charAt(0) == '-') {\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor (int i = start; i < x.length(); i++)\n\t\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t} else {\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48866143a0d85b699da0fbfb149f4e09", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n/**\n * Author: homo_sapiens\n * Date: 7/14/12\n * Time: 11:54 AM\n */\npublic class Solution {\n public static void main(String[] args) throws IOException {\n Solution solution = new Solution();\n solution.run();\n }\n\n private int n;\n private int[] a;\n private BigInteger[][][] z;\n\n private void run() throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n\n String s = in.readLine();\n\n a = new int[s.length()];\n for (int i = 0; i < s.length(); i++) {\n a[i] = s.charAt(i) == 'A' ? 0 : 1;\n }\n\n z = new BigInteger[s.length() + 1][4][4];\n\n for (int i = 0; i <= s.length(); i++) {\n for (int j = 0; j < 4; j++) {\n for (int k = 0; k < 4; k++) {\n z[i][j][k] = BigInteger.valueOf(-1);\n }\n }\n }\n\n BigInteger result = BigInteger.ZERO;\n\n for (int mask = 0; mask < 4; mask++) {\n result = result.add(solve(2, mask, mask));\n }\n\n out.write(result.toString());\n out.newLine();\n\n out.close();\n in.close();\n }\n\n private BigInteger solve(int idx, int mask1, int mask2) {\n if (!z[idx][mask1][mask2].equals(BigInteger.valueOf(-1))) {\n return z[idx][mask1][mask2];\n }\n\n int f1 = mask1 & 1, f2 = (mask1 >> 1) & 1;\n int s1 = mask2 & 1, s2 = (mask2 >> 1) & 1;\n\n BigInteger result = BigInteger.ZERO;\n\n if (idx == a.length) {\n if (correct(s1, s2, f1, a[idx - 2], a[idx - 1], a[0])\n && correct(s2, f1, f2, a[idx - 1], a[0], a[1])) {\n result = BigInteger.ONE;\n }\n } else {\n for (int cur = 0; cur < 2; cur++) {\n if (correct(s1, s2, cur, a[idx - 2], a[idx - 1], a[idx])) {\n result = result.add(solve(idx + 1, mask1, (cur << 1) | s2));\n }\n }\n }\n\n return z[idx][mask1][mask2] = result;\n }\n\n private boolean correct(int a1, int a2, int a3, int b1, int b2, int b3) {\n if (a1 == 0 && a2 == 1) {\n return b1 == 1 && b2 == 0;\n } else if (a2 == 0 && a3 == 1) {\n return b2 == 1 && b3 == 0;\n } else {\n return a2 == b2;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "be5ae832307246219c5dbefca5451cf0", "src_uid": "ad27d991516054ea473b384bb2563b38", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\nimport java.io.*;\n\npublic class C {\n\tstatic void p(Object ...o) {System.out.println(Arrays.deepToString(o));}; \n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString S = in.next();\n\t\tSystem.out.println(solution(S));\n//\t\tfor (int N = 3; N <= 10; N++) {\n//\t\t\tfor (int i = 0; i < (1< 0) // B \n {\n for (int j = 0; j < 2; j++)\n dp[i][m] = dp[i][m].add(f(i + 1, ((m << 1) | j) & 3));\n }\n }\n else // _A\n {\n dp[i][m] = f(i + 1, ((m << 1) | 1) & 3);\n }\n }\n return dp[i][m];\n }\n void solve()\n {\n dp = new BigInteger[s.length() + 2][4];\n BigInteger res = BigInteger.ZERO;\n for (int i = 0; i < 4; i++)\n {\n for (int j = 0; j < s.length() + 1; j++)\n dp[j][0] = dp[j][1] = dp[j][2] = dp[j][3] = null;\n first = i;\n res = res.add(f(0, i));\n } \n out.println(res);\n }\n void run()\n {\n try\n {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n load();\n solve();\n out.close();\n }\n catch(Exception e)\n {\n e.printStackTrace();\n System.exit(42);\n }\n }\n public String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens())\n {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\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 public void readIntArray(int []a, int n) throws IOException \n {\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n }\n public static void main(String args[])\n {\n new problemC().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fcb5adc4c555ff5759c3c2977b03cdc2", "src_uid": "ad27d991516054ea473b384bb2563b38", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\n/**\n * Created with IntelliJ IDEA.\n * User: contest\n * Date: 7/14/12\n * Time: 11:36 AM\n * To change this template use File | Settings | File Templates.\n */\npublic class problemC {\n final String prefix = \"c\";\n final String problem_input = prefix + \".in\";\n final String problem_output = prefix + \".out\";\n BufferedReader br;\n StringTokenizer st;\n PrintWriter out;\n String s;\n BigInteger dp[][];\n void load() throws IOException\n {\n s = nextToken();\n }\n int first;\n\n BigInteger f(int i, int m)\n {\n if (i == s.length())\n {\n if (m == first)\n return BigInteger.ONE;\n else return BigInteger.ZERO;\n }\n if (dp[i][m] != null) return dp[i][m];\n dp[i][m] = BigInteger.ZERO;\n if (s.charAt(i) == 'A')\n {\n if ((m & 1) == 0) // _A\n {\n dp[i][m] = dp[i][m].add(f(i + 1, ((m << 1) | 0) & 3));\n }\n else //_B\n {\n if ((m & 2) == 0) \n for (int j = 0; j < 2; j++)\n dp[i][m] = dp[i][m].add(f(i + 1, ((m << 1) | j) & 3));\n }\n }\n else if (s.charAt(i) == 'B')\n {\n if ((m & 1) == 1) // _B\n { //BB\n if ((m & 2) > 0) // B \n {\n for (int j = 0; j < 2; j++)\n dp[i][m] = dp[i][m].add(f(i + 1, ((m << 1) | j) & 3));\n }\n }\n else // _A\n {\n dp[i][m] = f(i + 1, ((m << 1) | 1) & 3);\n }\n }\n return dp[i][m];\n }\n void solve()\n {\n dp = new BigInteger[s.length() + 2][4];\n BigInteger res = BigInteger.ZERO;\n for (int i = 0; i < 4; i++)\n {\n for (int j = 0; j < s.length() + 1; j++)\n dp[j][0] = dp[j][1] = dp[j][2] = dp[j][3] = null;\n first = i;\n res = res.add(f(0, i));\n } \n out.println(res);\n }\n void run()\n {\n try\n {\n br = new BufferedReader(new FileReader(problem_input));\n out = new PrintWriter(problem_output);\n load();\n solve();\n out.close();\n }\n catch(Exception e)\n {\n e.printStackTrace();\n System.exit(42);\n }\n }\n public String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens())\n {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\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 public void readIntArray(int []a, int n) throws IOException \n {\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n }\n public static void main(String args[])\n {\n new problemC().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4b6cd05f55155c869611675b5ae22231", "src_uid": "ad27d991516054ea473b384bb2563b38", "difficulty": 2100.0} {"lang": "Java 8", "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\twhile(n <= x){\n\t\t\t\tans ++;\n\t\t\t\tn += T;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "40427d71e202fabcbe3e0172109cabeb", "src_uid": "4b9f470e5889da29affae6376f6c9f6a", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\n\n\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map.Entry;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.TreeSet;\n\n\npublic final class CF_460_E{\n\n\tstatic boolean verb=true;\n\tstatic void log(Object X){if (verb) System.err.println(X);}\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\n\tstatic void log(int[] X,int L){if (verb) {for (int i=0;i0) {\n\t\t\tif (e%2==1)\n\t\t\t\tx=(b*x)%m;\n\t\t\tb=(b*b)%m;\n\t\t\te=e/2;\n\t\t}\n\t\treturn x; \n\t}\n\n\n\n\tstatic void process() throws Exception {\n\n\n\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\treader=new InputReader(System.in);\n\n\n\n\t\tint a=reader.readInt();\n\t\tint b=reader.readInt();\n\t\tint p=reader.readInt();\n\t\tlong x=reader.readLong();\n\t\t\n\t\tlong pp=p;\n\t\t\n\t\tArrayList[] targy=new ArrayList[p];\n\t\tArrayList[] targk=new ArrayList[p];\n\t\tfor (int u=1;u();\n\t\t\ttargk[u]=new ArrayList();\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tfor (int y=1;y0 && targk[u].size()>0){\n\t\t\t\tfor (long k:targk[u])\n\t\t\t\t\tfor (long y:targy[u]){\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (p*k+y<=x){\n\t\t\t\t\t\t\tlong mt=(x-y-pp*k)/(pp*(pp-1));\n\t\t\t\t\t\t\tsum+=mt+1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t/*\n\t\t\t\t\t\tlong t=0;\n\t\t\t\t\t\twhile (((p-1)*t+k)*p+y<=x){\n\t\t\t\t\t\t\tt++;\n\t\t\t\t\t\t\tsum++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t*/\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toutput(sum);\n\n\t\ttry {\n\t\t\tout.close();\n\t\t}\n\t\tcatch (Exception EX){}\n\n\n\t}\n\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tprocess();\n\n\t}\n\n\tstatic final class InputReader {\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() throws IOException {\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\tif (numChars <= 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\n\t\tpublic final String readString() throws IOException {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res=new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.append((char)c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic final int readInt() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\t\tpublic final long readLong() throws IOException {\n\t\t\tint c = read();\n\t\t\tboolean neg=false;\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tchar d=(char)c;\n\t\t\t//log(\"d:\"+d);\n\t\t\tif (d=='-') {\n\t\t\t\tneg=true;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\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\t//log(\"res:\"+res);\n\t\t\tif (neg)\n\t\t\t\treturn -res;\n\t\t\treturn res;\n\n\t\t}\n\n\n\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\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "55f7f6350c3615bb04f4ccc33dab7d8c", "src_uid": "4b9f470e5889da29affae6376f6c9f6a", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n int a = in.nextInt();\n int b = in.nextInt();\n int p = in.nextInt();\n int x = in.nextInt();\n\n int answer = 0;\n for (int i = 0; i < p; i++) {\n int tmp = (b * modPow(modPow(a, i, p), p - 2, p)) % p;\n if (i >= tmp) {\n int first = (i - tmp) * (p-1) + i;\n if (first <= x)\n answer += (x - first) / (p*(p-1)) + 1;\n }\n }\n\n System.out.println(answer);\n }\n\n private static int modPow(int a, int b, int mod) {\n int modPow = 1;\n for (; b > 0; b >>= 1) {\n if ((b & 1) != 0)\n modPow = (int) ((1L * modPow * a) % mod);\n a = (int) ((1L * a * a) % mod);\n }\n return modPow;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6347f593a2339fbf9eb1a2c7183d1aac", "src_uid": "4b9f470e5889da29affae6376f6c9f6a", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n int a = in.nextInt();\n int b = in.nextInt();\n int p = in.nextInt();\n long x = in.nextInt();\n\n int answer = 0;\n for (int i = 0; i < p; i++) {\n int tmp = (b * modPow(modPow(a, i, p), p - 2, p)) % p;\n if (i >= tmp) {\n int first = (i - tmp) * (p-1) + i;\n if (first <= x)\n answer += (x - first) / (p*(p-1)) + 1;\n }\n }\n\n System.out.println(answer);\n }\n\n private static int modPow(int a, int b, int mod) {\n int modPow = 1;\n for (; b > 0; b >>= 1) {\n if ((b & 1) != 0)\n modPow = (int) ((1L * modPow * a) % mod);\n a = (int) ((1L * a * a) % mod);\n }\n return modPow;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "651a6215f8853cc25582af9c36648899", "src_uid": "4b9f470e5889da29affae6376f6c9f6a", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\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 int n = in.nextInt();\n int m = in.nextInt();\n int numQueries = in.nextInt();\n int[] p = new int[n];\n for (int i = 0; i < n; i++) {\n p[i] = -in.nextInt();\n }\n int[] a = new int[m];\n int[] b = new int[m];\n for (int i = 0; i < m; i++) {\n a[i] = in.nextInt() - 1;\n b[i] = in.nextInt() - 1;\n }\n int[] type = new int[numQueries];\n int[] val = new int[numQueries];\n boolean[] willDie = new boolean[m];\n for (int i = 0; i < numQueries; i++) {\n type[i] = in.nextInt();\n val[i] = in.nextInt() - 1;\n if (type[i] == 2) {\n willDie[val[i]] = true;\n }\n }\n\n int[] parent = new int[n];\n Arrays.fill(parent, -1);\n DSU dsu = new DSU(n);\n Graph g = new Graph(n + 1);\n for (int i = 0; i < m; i++) {\n if (willDie[i]) {\n continue;\n }\n int u = dsu.findComp(a[i]);\n int v = dsu.findComp(b[i]);\n if (u == v) {\n continue;\n }\n dsu.merge(u, v);\n if (dsu.p[v] == u) {\n int t = u;\n u = v;\n v = t;\n }\n parent[u] = v;\n g.addEdge(v, u, i);\n }\n\n for (int i = numQueries - 1; i >= 0; i--) {\n if (type[i] == 1) {\n val[i] = dsu.findComp(val[i]);\n continue;\n }\n int u = dsu.findComp(a[val[i]]);\n int v = dsu.findComp(b[val[i]]);\n if (u == v) {\n continue;\n }\n dsu.merge(u, v);\n if (dsu.p[v] == u) {\n int t = u;\n u = v;\n v = t;\n }\n parent[u] = v;\n g.addEdge(v, u, val[i]);\n }\n\n int root = n;\n for (int i = 0; i < n; i++) {\n if (parent[i] < 0) {\n g.addEdge(root, i, -1);\n }\n }\n EulerTourNumbering et = new EulerTourNumbering(g, root);\n\n MinTree mt = new MinTree(n + 1);\n int[] q = new int[n + 1];\n for (int i = 0; i < n; i++) {\n q[et.timeIn[i]] = p[i];\n mt.set(et.timeIn[i], p[i]);\n }\n\n boolean[] dead = new boolean[m];\n int[] left = new int[n + 1];\n int[] right = new int[n + 1];\n for (int i = 0; i < left.length; i++) {\n left[i] = et.timeIn[i];\n right[i] = et.timeOut[i] - 1;\n }\n for (int i = 0; i < numQueries; i++) {\n if (type[i] == 2) {\n dead[val[i]] = true;\n continue;\n }\n int r = val[i];\n for (int e = g.firstEdge[val[i]]; e >= 0; e = g.edgeNxt[e]) {\n int origId = g.edgeId[e];\n int dst = g.edgeDst[e];\n if (dead[origId]) {\n if (e != g.firstEdge[val[i]]) {\n throw new AssertionError();\n }\n g.firstEdge[val[i]] = g.edgeNxt[e];\n left[val[i]] = et.timeOut[dst];\n } else {\n break;\n }\n }\n int pos = et.timeIn[r];\n if (left[r] <= right[r]) {\n int cand = mt.getMinPos(left[r], right[r]);\n if (q[pos] > q[cand]) {\n pos = cand;\n }\n }\n out.println(-q[pos]);\n q[pos] = 0;\n mt.set(pos, 0);\n }\n }\n\n class EulerTourNumbering {\n Graph g;\n int[] tour;\n int[] timeIn;\n int[] timeOut;\n int globalTime;\n\n EulerTourNumbering(Graph g, int root) {\n this.g = g;\n int n = g.n;\n timeIn = new int[n];\n timeOut = new int[n];\n tour = new int[n];\n\n dfs(root, -1);\n if (globalTime != n) {\n throw new AssertionError();\n }\n }\n\n void dfs(int v, int p) {\n tour[globalTime] = v;\n timeIn[v] = globalTime++;\n for (int e = g.firstEdge[v]; e >= 0; e = g.edgeNxt[e]) {\n int u = g.edgeDst[e];\n if (u == p) {\n continue;\n }\n dfs(u, v);\n }\n timeOut[v] = globalTime;\n }\n\n }\n\n class Graph {\n int n;\n int[] firstEdge;\n int[] edgeDst;\n int[] edgeNxt;\n int[] edgeId;\n int numEdges;\n\n Graph(int n) {\n this.n = n;\n firstEdge = new int[n];\n Arrays.fill(firstEdge, -1);\n final int initialCapacity = 2 * n - 2;\n edgeDst = new int[initialCapacity];\n edgeNxt = new int[initialCapacity];\n edgeId = new int[initialCapacity];\n numEdges = 0;\n }\n\n void addEdge(int a, int b, int origId) {\n int e = numEdges++;\n if (e >= edgeDst.length) {\n reallocate();\n }\n edgeDst[e] = b;\n edgeNxt[e] = firstEdge[a];\n firstEdge[a] = e;\n edgeId[e] = origId;\n }\n\n private void reallocate() {\n int k = edgeDst.length;\n edgeDst = Arrays.copyOf(edgeDst, 3 * k / 2);\n edgeNxt = Arrays.copyOf(edgeNxt, 3 * k / 2);\n edgeId = Arrays.copyOf(edgeId, 3 * k / 2);\n }\n\n }\n\n class MinTree {\n int n;\n int[] a;\n int[] where;\n final int infinity = (int) 1e9;\n\n MinTree(int size) {\n n = 1;\n while (n < size) {\n n *= 2;\n }\n a = new int[2 * n];\n where = new int[2 * n];\n Arrays.fill(a, infinity);\n }\n\n void set(int pos, int val) {\n pos += n;\n a[pos] = val;\n where[pos] = pos - n;\n while (pos > 1) {\n pos /= 2;\n a[pos] = Math.min(a[2 * pos], a[2 * pos + 1]);\n if (a[pos] == a[2 * pos]) {\n where[pos] = where[2 * pos];\n } else {\n where[pos] = where[2 * pos + 1];\n }\n }\n }\n\n int getMinPos(int l, int r) {\n if (l > r) {\n return infinity;\n }\n l += n;\n r += n;\n if (l == r) {\n return where[l];\n }\n int lm = a[l];\n int rm = a[r];\n int lp = where[l];\n int rp = where[r];\n while (r - l > 1) {\n if (l % 2 == 0) {\n if (lm > a[l + 1]) {\n lm = a[l + 1];\n lp = where[l + 1];\n }\n }\n if (r % 2 != 0) {\n if (rm > a[r - 1]) {\n rm = a[r - 1];\n rp = where[r - 1];\n }\n }\n l /= 2;\n r /= 2;\n }\n return lm < rm ? lp : rp;\n }\n\n }\n\n class DSU {\n int[] rank;\n int[] p;\n int numComps;\n\n DSU(int n) {\n rank = new int[n];\n p = new int[n];\n reset();\n }\n\n void reset() {\n for (int i = 0; i < p.length; i++) {\n rank[i] = 0;\n p[i] = i;\n }\n numComps = p.length;\n }\n\n private int findComp(int x) {\n int r;\n int saved;\n\n saved = x;\n while (x != p[x]) {\n x = p[x];\n }\n r = x;\n\n x = saved;\n while (x != r) {\n saved = p[x];\n p[x] = r;\n x = saved;\n }\n return r;\n }\n\n private void merge(int a, int b) {\n a = findComp(a);\n b = findComp(b);\n if (a == b) {\n return;\n }\n --numComps;\n if (rank[a] < rank[b]) {\n p[a] = b;\n } else {\n p[b] = a;\n if (rank[a] == rank[b]) {\n ++rank[a];\n }\n }\n }\n\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "12c7f9052298c822b3a33ed072c34f49", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\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 int n = in.nextInt();\n int m = in.nextInt();\n int numQueries = in.nextInt();\n int[] p = new int[n];\n for (int i = 0; i < n; i++) {\n p[i] = -in.nextInt();\n }\n int[] a = new int[m];\n int[] b = new int[m];\n for (int i = 0; i < m; i++) {\n a[i] = in.nextInt() - 1;\n b[i] = in.nextInt() - 1;\n }\n int[] type = new int[numQueries];\n int[] val = new int[numQueries];\n boolean[] willDie = new boolean[m];\n for (int i = 0; i < numQueries; i++) {\n type[i] = in.nextInt();\n val[i] = in.nextInt() - 1;\n if (type[i] == 2) {\n willDie[val[i]] = true;\n }\n }\n\n int[] parent = new int[n];\n Arrays.fill(parent, -1);\n DSU dsu = new DSU(n);\n Graph g = new Graph(n + 1);\n for (int i = 0; i < m; i++) {\n if (willDie[i]) {\n continue;\n }\n int u = dsu.findComp(a[i]);\n int v = dsu.findComp(b[i]);\n if (u == v) {\n continue;\n }\n dsu.merge(u, v);\n if (dsu.p[v] == u) {\n int t = u;\n u = v;\n v = t;\n }\n parent[u] = v;\n g.addEdge(v, u, i);\n }\n\n for (int i = numQueries - 1; i >= 0; i--) {\n if (type[i] == 1) {\n val[i] = dsu.findComp(val[i]);\n continue;\n }\n int u = dsu.findComp(a[val[i]]);\n int v = dsu.findComp(b[val[i]]);\n if (u == v) {\n continue;\n }\n parent[u] = v;\n dsu.merge(u, v);\n if (dsu.p[v] == u) {\n int t = u;\n u = v;\n v = t;\n }\n g.addEdge(v, u, i);\n }\n\n int root = n;\n for (int i = 0; i < n; i++) {\n if (parent[i] < 0) {\n g.addEdge(root, i, -1);\n }\n }\n EulerTourNumbering et = new EulerTourNumbering(g, root);\n\n MinTree mt = new MinTree(n + 1);\n int[] q = new int[n + 1];\n for (int i = 0; i < n; i++) {\n q[et.timeIn[i]] = p[i];\n mt.set(et.timeIn[i], p[i]);\n }\n\n boolean[] dead = new boolean[m];\n for (int i = 0; i < numQueries; i++) {\n if (type[i] == 2) {\n dead[val[i]] = true;\n continue;\n }\n int pos = et.timeIn[val[i]];\n int l = pos;\n int r = pos;\n for (int e = g.firstEdge[val[i]]; e >= 0; e = g.edgeNxt[e]) {\n int origId = g.edgeId[e];\n int dst = g.edgeDst[e];\n if (dead[origId]) {\n if (l >= 0) {\n int cand = mt.getMinPos(l, r);\n if (q[pos] > q[cand]) {\n pos = cand;\n }\n l = -1;\n }\n continue;\n }\n if (l < 0) {\n l = et.timeIn[dst];\n }\n r = et.timeOut[dst] - 1;\n }\n if (l >= 0) {\n int cand = mt.getMinPos(l, r);\n if (q[pos] > q[cand]) {\n pos = cand;\n }\n l = -1;\n }\n out.println(-q[pos]);\n q[pos] = 0;\n mt.set(pos, 0);\n }\n }\n\n class EulerTourNumbering {\n Graph g;\n int[] tour;\n int[] timeIn;\n int[] timeOut;\n int globalTime;\n\n EulerTourNumbering(Graph g, int root) {\n this.g = g;\n int n = g.n;\n timeIn = new int[n];\n timeOut = new int[n];\n tour = new int[n];\n\n dfs(root, -1);\n if (globalTime != n) {\n throw new AssertionError();\n }\n }\n\n void dfs(int v, int p) {\n tour[globalTime] = v;\n timeIn[v] = globalTime++;\n for (int e = g.firstEdge[v]; e >= 0; e = g.edgeNxt[e]) {\n int u = g.edgeDst[e];\n if (u == p) {\n continue;\n }\n dfs(u, v);\n }\n timeOut[v] = globalTime;\n }\n\n }\n\n class Graph {\n int n;\n int[] firstEdge;\n int[] edgeDst;\n int[] edgeNxt;\n int[] edgeId;\n int numEdges;\n\n Graph(int n) {\n this.n = n;\n firstEdge = new int[n];\n Arrays.fill(firstEdge, -1);\n final int initialCapacity = 2 * n - 2;\n edgeDst = new int[initialCapacity];\n edgeNxt = new int[initialCapacity];\n edgeId = new int[initialCapacity];\n numEdges = 0;\n }\n\n void addEdge(int a, int b, int origId) {\n int e = numEdges++;\n if (e >= edgeDst.length) {\n reallocate();\n }\n edgeDst[e] = b;\n edgeNxt[e] = firstEdge[a];\n firstEdge[a] = e;\n edgeId[e] = origId;\n }\n\n private void reallocate() {\n int k = edgeDst.length;\n edgeDst = Arrays.copyOf(edgeDst, 3 * k / 2);\n edgeNxt = Arrays.copyOf(edgeNxt, 3 * k / 2);\n edgeId = Arrays.copyOf(edgeId, 3 * k / 2);\n }\n\n }\n\n class MinTree {\n int n;\n int[] a;\n int[] where;\n final int infinity = (int) 1e9;\n\n MinTree(int size) {\n n = 1;\n while (n < size) {\n n *= 2;\n }\n a = new int[2 * n];\n where = new int[2 * n];\n Arrays.fill(a, infinity);\n }\n\n void set(int pos, int val) {\n pos += n;\n a[pos] = val;\n where[pos] = pos - n;\n while (pos > 1) {\n pos /= 2;\n a[pos] = Math.min(a[2 * pos], a[2 * pos + 1]);\n if (a[pos] == a[2 * pos]) {\n where[pos] = where[2 * pos];\n } else {\n where[pos] = where[2 * pos + 1];\n }\n }\n }\n\n int getMinPos(int l, int r) {\n if (l > r) {\n return infinity;\n }\n l += n;\n r += n;\n if (l == r) {\n return where[l];\n }\n int lm = a[l];\n int rm = a[r];\n int lp = where[l];\n int rp = where[r];\n while (r - l > 1) {\n if (l % 2 == 0) {\n if (lm > a[l + 1]) {\n lm = a[l + 1];\n lp = where[l + 1];\n }\n }\n if (r % 2 != 0) {\n if (rm > a[r - 1]) {\n rm = a[r - 1];\n rp = where[r - 1];\n }\n }\n l /= 2;\n r /= 2;\n }\n return lm < rm ? lp : rp;\n }\n\n }\n\n class DSU {\n int[] rank;\n int[] p;\n int numComps;\n\n DSU(int n) {\n rank = new int[n];\n p = new int[n];\n reset();\n }\n\n void reset() {\n for (int i = 0; i < p.length; i++) {\n rank[i] = 0;\n p[i] = i;\n }\n numComps = p.length;\n }\n\n private int findComp(int x) {\n int r;\n int saved;\n\n saved = x;\n while (x != p[x]) {\n x = p[x];\n }\n r = x;\n\n x = saved;\n while (x != r) {\n saved = p[x];\n p[x] = r;\n x = saved;\n }\n return r;\n }\n\n private void merge(int a, int b) {\n a = findComp(a);\n b = findComp(b);\n if (a == b) {\n return;\n }\n --numComps;\n if (rank[a] < rank[b]) {\n p[a] = b;\n } else {\n p[b] = a;\n if (rank[a] == rank[b]) {\n ++rank[a];\n }\n }\n }\n\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ef07ea0ad7c20a93bb13336925359d29", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic class DSU {\n\t\tint[] sz;\n\t\tint[] p;\n\n\t\tpublic DSU(int n) {\n\t\t\tsz = new int[n];\n\t\t\tp = new int[n];\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tp[i] = i;\n\t\t\t\tsz[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic int get(int x) {\n\t\t\tif (x == p[x]) {\n\t\t\t\treturn x;\n\t\t\t}\n\t\t\tint par = get(p[x]);\n\t\t\tp[x] = par;\n\t\t\treturn par;\n\t\t}\n\n\t\tpublic boolean unite(int a, int b) {\n\t\t\tint pa = get(a);\n\t\t\tint pb = get(b);\n\t\t\tif (pa == pb) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (sz[pa] < sz[pb]) {\n\t\t\t\tp[pa] = pb;\n\t\t\t\tsz[pb] += sz[pa];\n\t\t\t} else {\n\t\t\t\tp[pb] = pa;\n\t\t\t\tsz[pa] += sz[pb];\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tpublic class SegmentTreeAdd {\n\t\tint pow;\n\t\tlong[] max;\n\t\tlong[] delta;\n\t\tboolean[] flag;\n\n\t\tpublic SegmentTreeAdd(long[] a) {\n\t\t\tpow = 1;\n\t\t\twhile (pow < a.length) {\n\t\t\t\tpow *= 2;\n\t\t\t}\n\t\t\tflag = new boolean[2 * pow];\n\t\t\tmax = new long[2 * pow];\n\t\t\tdelta = new long[2 * pow];\n\t\t\tfor (int i = 0; i < max.length; i++) {\n\t\t\t\tmax[i] = Long.MIN_VALUE / 2;\n\t\t\t}\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tmax[pow + i] = a[i];\n\t\t\t}\n\t\t\tfor (int i = pow - 1; i > 0; i--) {\n\t\t\t\tmax[i] = f(max[2 * i], max[2 * i + 1]);\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int v, int tl, int tr, int l, int r) {\n\t\t\tpush(v, tl, tr);\n\t\t\tif (l > r) {\n\t\t\t\treturn Long.MIN_VALUE / 2;\n\t\t\t}\n\t\t\tif (l == tl && r == tr) {\n\t\t\t\treturn max[v];\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\treturn f(get(2 * v, tl, tm, l, Math.min(r, tm)), get(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r));\n\t\t}\n\n\t\tpublic void set(int v, int tl, int tr, int l, int r, long x) {\n\t\t\tpush(v, tl, tr);\n\t\t\tif (l > tr || r < tl) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (l <= tl && r >= tr) {\n\t\t\t\tdelta[v] += x;\n\t\t\t\tflag[v] = true;\n\t\t\t\tpush(v, tl, tr);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\tset(2 * v, tl, tm, l, r, x);\n\t\t\tset(2 * v + 1, tm + 1, tr, l, r, x);\n\t\t\tmax[v] = f(max[2 * v], max[2 * v + 1]);\n\t\t}\n\n\t\tpublic void push(int v, int tl, int tr) {\n\t\t\tif (flag[v]) {\n\t\t\t\tif (v < pow) {\n\t\t\t\t\tflag[2 * v] = true;\n\t\t\t\t\tflag[2 * v + 1] = true;\n\t\t\t\t\tdelta[2 * v] += delta[v];\n\t\t\t\t\tdelta[2 * v + 1] += delta[v];\n\t\t\t\t}\n\t\t\t\tflag[v] = false;\n\t\t\t\tmax[v] += delta[v];\n\t\t\t\tdelta[v] = 0;\n\t\t\t}\n\t\t}\n\n\t\tpublic long f(long a, long b) {\n\t\t\treturn Math.max(a, b);\n\t\t}\n\t}\n\n\tpublic class SegmentTreeSet {\n\t\tint pow;\n\t\tint[] sum;\n\t\tint[] delta;\n\t\tboolean[] flag;\n\n\t\tpublic SegmentTreeSet(int[] a) {\n\t\t\tpow = 1;\n\t\t\twhile (pow < a.length) {\n\t\t\t\tpow *= 2;\n\t\t\t}\n\t\t\tflag = new boolean[2 * pow];\n\t\t\tsum = new int[2 * pow];\n\t\t\tdelta = new int[2 * pow];\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tsum[pow + i] = a[i];\n\t\t\t}\n\t\t}\n\n\t\tpublic int get(int v, int tl, int tr, int l, int r) {\n\t\t\tpush(v, tl, tr);\n\t\t\tif (l > r) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (l == tl && r == tr) {\n\t\t\t\treturn sum[v];\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\treturn f(get(2 * v, tl, tm, l, Math.min(r, tm)), get(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r));\n\t\t}\n\n\t\tpublic void set(int v, int tl, int tr, int l, int r, int x) {\n\t\t\tpush(v, tl, tr);\n\t\t\tif (l > tr || r < tl) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (l <= tl && r >= tr) {\n\t\t\t\tdelta[v] = x;\n\t\t\t\tflag[v] = true;\n\t\t\t\tpush(v, tl, tr);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\tset(2 * v, tl, tm, l, r, x);\n\t\t\tset(2 * v + 1, tm + 1, tr, l, r, x);\n\t\t\tsum[v] = f(sum[2 * v], sum[2 * v + 1]);\n\t\t}\n\n\t\tpublic void push(int v, int tl, int tr) {\n\t\t\tif (flag[v]) {\n\t\t\t\tif (v < pow) {\n\t\t\t\t\tflag[2 * v] = true;\n\t\t\t\t\tflag[2 * v + 1] = true;\n\t\t\t\t\tdelta[2 * v] = delta[v];\n\t\t\t\t\tdelta[2 * v + 1] = delta[v];\n\t\t\t\t}\n\t\t\t\tflag[v] = false;\n\t\t\t\tsum[v] = delta[v] * (tr - tl + 1);\n\t\t\t}\n\t\t}\n\n\t\tpublic int f(int a, int b) {\n\t\t\treturn a + b;\n\t\t}\n\t}\n\n\tpublic class Pair implements Comparable {\n\t\tint x;\n\t\tint y;\n\n\t\tpublic Pair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tpublic Pair clone() {\n\t\t\treturn new Pair(x, y);\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (y > o.y) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif (y < o.y) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (x > o.x) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif (x < o.x) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tlong mod = 1000000007;\n\tRandom random = new Random();\n\n\tpublic void shuffle(Pair[] a) {\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint x = random.nextInt(i + 1);\n\t\t\tPair t = a[x];\n\t\t\ta[x] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\n\tpublic void sort(int[][] a) {\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tArrays.sort(a[i]);\n\t\t}\n\t}\n\n\tpublic void add(HashMap map, long l) {\n\t\tif (map.containsKey(l)) {\n\t\t\tmap.put(l, map.get(l) + 1);\n\t\t} else {\n\t\t\tmap.put(l, 1);\n\t\t}\n\t}\n\n\tpublic void remove(TreeMap map, Integer s) {\n\t\tif (map.get(s) > 1) {\n\t\t\tmap.put(s, map.get(s) - 1);\n\t\t} else {\n\t\t\tmap.remove(s);\n\t\t}\n\t}\n\n\tlong max = Long.MAX_VALUE / 2;\n\tdouble eps = 1e-10;\n\n\tpublic int signum(double x) {\n\t\tif (x > eps) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (x < -eps) {\n\t\t\treturn -1;\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic long abs(long x) {\n\t\treturn x < 0 ? -x : x;\n\t}\n\n\tpublic long min(long x, long y) {\n\t\treturn x < y ? x : y;\n\t}\n\n\tpublic long max(long x, long y) {\n\t\treturn x > y ? x : y;\n\t}\n\n\tpublic long gcd(long x, long y) {\n\t\twhile (y > 0) {\n\t\t\tlong c = y;\n\t\t\ty = x % y;\n\t\t\tx = c;\n\t\t}\n\t\treturn x;\n\t}\n\n\tpublic final Vector ZERO = new Vector(0, 0);\n\n\t// public class Vector implements Comparable {\n\t// long x;\n\t// long y;\n\t// int type;\n\t// int number;\n\t//\n\t// public Vector() {\n\t// x = 0;\n\t// y = 0;\n\t// }\n\t//\n\t// public Vector(long x, long y, int type, int number) {\n\t// this.x = x;\n\t// this.y = y;\n\t// this.type = type;\n\t// this.number = number;\n\t// }\n\t//\n\t// public Vector(long x, long y) {\n\t//\n\t// }\n\t//\n\t// public Vector(Point begin, Point end) {\n\t// this(end.x - begin.x, end.y - begin.y);\n\t// }\n\t//\n\t// public void orient() {\n\t// if (x < 0) {\n\t// x = -x;\n\t// y = -y;\n\t// }\n\t// if (x == 0 && y < 0) {\n\t// y = -y;\n\t// }\n\t// }\n\t//\n\t// public void normalize() {\n\t// long gcd = gcd(abs(x), abs(y));\n\t// x /= gcd;\n\t// y /= gcd;\n\t// }\n\t//\n\t// public String toString() {\n\t// return x + \" \" + y;\n\t// }\n\t//\n\t// public boolean equals(Vector v) {\n\t// return x == v.x && y == v.y;\n\t// }\n\t//\n\t// public boolean collinear(Vector v) {\n\t// return cp(this, v) == 0;\n\t// }\n\t//\n\t// public boolean orthogonal(Vector v) {\n\t// return dp(this, v) == 0;\n\t// }\n\t//\n\t// public Vector ort(Vector v) {\n\t// return new Vector(-y, x);\n\t// }\n\t//\n\t// public Vector add(Vector v) {\n\t// return new Vector(x + v.x, y + v.y);\n\t// }\n\t//\n\t// public Vector multiply(long c) {\n\t// return new Vector(c * x, c * y);\n\t// }\n\t//\n\t// public int quater() {\n\t// if (x > 0 && y >= 0) {\n\t// return 1;\n\t// }\n\t// if (x <= 0 && y > 0) {\n\t// return 2;\n\t// }\n\t// if (x < 0) {\n\t// return 3;\n\t// }\n\t// return 0;\n\t// }\n\t//\n\t// public long len2() {\n\t// return x * x + y * y;\n\t// }\n\t//\n\t// @Override\n\t// public int compareTo(Vector o) {\n\t// if (quater() != o.quater()) {\n\t// return quater() - o.quater();\n\t// }\n\t// return signum(cp(o, this));\n\t// }\n\t// }\n\n\t// public long dp(Vector v1, Vector v2) {\n\t// return v1.x * v2.x + v1.y * v2.y;\n\t// }\n\t//\n\t// public long cp(Vector v1, Vector v2) {\n\t// return v1.x * v2.y - v1.y * v2.x;\n\t// }\n\n\t// public class Line implements Comparable {\n\t// Point p;\n\t// Vector v;\n\t//\n\t// public Line(Point p, Vector v) {\n\t// this.p = p;\n\t// this.v = v;\n\t// }\n\t//\n\t// public Line(Point p1, Point p2) {\n\t// if (p1.compareTo(p2) < 0) {\n\t// p = p1;\n\t// v = new Vector(p1, p2);\n\t// } else {\n\t// p = p2;\n\t// v = new Vector();\n\t// }\n\t// }\n\t//\n\t// public boolean collinear(Line l) {\n\t// return v.collinear(l.v);\n\t// }\n\t//\n\t// public boolean inLine(Point p) {\n\t// return hv(p) == 0;\n\t// }\n\t//\n\t// public boolean inSegment(Point p) {\n\t// if (!inLine(p)) {\n\t// return false;\n\t// }\n\t// Point p1 = p;\n\t// Point p2 = p.add(v);\n\t// return p1.x <= p.x && p.x <= p2.x && min(p1.y, p2.y) <= p.y && p.y <=\n\t// max(p1.y, p2.y);\n\t// }\n\t//\n\t// public boolean equalsSegment(Line l) {\n\t// return p.equals(l.p) && v.equals(l.v);\n\t// }\n\t//\n\t// public boolean equalsLine(Line l) {\n\t// return collinear(l) && inLine(l.p);\n\t// }\n\t//\n\t// public long hv(Point p) {\n\t// Vector v1 = new Vector(this.p, p);\n\t// return cp(v, v1);\n\t// }\n\t//\n\t// public double h(Point p) {\n\t// Vector v1 = new Vector(this.p, p);\n\t// return cp(v, v1) / Math.sqrt(v.len2());\n\t// }\n\t//\n\t// public long[] intersectLines(Line l) {\n\t// if (collinear(l)) {\n\t// return null;\n\t// }\n\t// long[] ans = new long[4];\n\t//\n\t// return ans;\n\t// }\n\t//\n\t// public long[] intersectSegment(Line l) {\n\t// long[] ans = intersectLines(l);\n\t// if (ans == null) {\n\t// return null;\n\t// }\n\t// Point p1 = p;\n\t// Point p2 = p.add(v);\n\t// boolean f1 = p1.x * ans[1] <= ans[0] && ans[0] <= p2.x * ans[1] && min(p1.y,\n\t// p2.y) * ans[3] <= ans[2]\n\t// && ans[2] <= max(p1.y, p2.y) * ans[3];\n\t// p1 = l.p;\n\t// p2 = l.p.add(v);\n\t// boolean f2 = p1.x * ans[1] <= ans[0] && ans[0] <= p2.x * ans[1] && min(p1.y,\n\t// p2.y) * ans[3] <= ans[2]\n\t// && ans[2] <= max(p1.y, p2.y) * ans[3];\n\t// if (!f1 || !f2) {\n\t// return null;\n\t// }\n\t// return ans;\n\t// }\n\t//\n\t// @Override\n\t// public int compareTo(Line o) {\n\t// return v.compareTo(o.v);\n\t// }\n\t// }\n\n\tpublic class Rect {\n\t\tlong x1;\n\t\tlong x2;\n\t\tlong y1;\n\t\tlong y2;\n\t\tint number;\n\n\t\tpublic Rect(long x1, long x2, long y1, long y2, int number) {\n\t\t\tthis.x1 = x1;\n\t\t\tthis.x2 = x2;\n\t\t\tthis.y1 = y1;\n\t\t\tthis.y2 = y2;\n\t\t\tthis.number = number;\n\t\t}\n\t}\n\n\tpublic static class Fenvik {\n\t\tint[] t;\n\n\t\tpublic Fenvik(int n) {\n\t\t\tt = new int[n];\n\t\t}\n\n\t\tpublic void add(int x, int delta) {\n\t\t\tfor (int i = x; i < t.length; i = (i | (i + 1))) {\n\t\t\t\tt[i] += delta;\n\t\t\t}\n\t\t}\n\n\t\tprivate int sum(int r) {\n\t\t\tint ans = 0;\n\t\t\tint x = r;\n\t\t\twhile (x >= 0) {\n\t\t\t\tans += t[x];\n\t\t\t\tx = (x & (x + 1)) - 1;\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t\tpublic int sum(int l, int r) {\n\t\t\treturn sum(r) - sum(l - 1);\n\t\t}\n\t}\n\n\tpublic class SegmentTreeMaxSum {\n\t\tint pow;\n\t\tint[] sum;\n\t\tint[] maxPrefSum;\n\t\tint[] maxSufSum;\n\t\tint[] maxSum;\n\n\t\tpublic SegmentTreeMaxSum(int[] a) {\n\t\t\tpow = 1;\n\t\t\twhile (pow < a.length) {\n\t\t\t\tpow *= 2;\n\t\t\t}\n\t\t\tsum = new int[2 * pow];\n\t\t\tmaxPrefSum = new int[2 * pow];\n\t\t\tmaxSum = new int[2 * pow];\n\t\t\tmaxSufSum = new int[2 * pow];\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tsum[pow + i] = a[i];\n\t\t\t\tmaxSum[pow + i] = Math.max(a[i], 0);\n\t\t\t\tmaxPrefSum[pow + i] = maxSum[pow + i];\n\t\t\t\tmaxSufSum[pow + i] = maxSum[pow + i];\n\t\t\t}\n\t\t\tfor (int i = pow - 1; i > 0; i--) {\n\t\t\t\tupdate(i);\n\t\t\t}\n\t\t}\n\n\t\tpublic int[] get(int v, int tl, int tr, int l, int r) {\n\t\t\tif (r <= tl || l >= tr) {\n\t\t\t\tint[] ans = { 0, 0, 0, 0 };\n\t\t\t\treturn ans;\n\t\t\t}\n\t\t\tif (l <= tl && r >= tr) {\n\t\t\t\tint[] ans = { maxPrefSum[v], maxSum[v], maxSufSum[v], sum[v] };\n\t\t\t\treturn ans;\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\tint[] left = get(2 * v, tl, tm, l, r);\n\t\t\tint[] right = get(2 * v + 1, tm, tr, l, r);\n\t\t\tint[] ans = { Math.max(left[0], right[0] + left[3]),\n\t\t\t\t\tMath.max(left[1], Math.max(right[1], left[2] + right[0])), Math.max(right[2], left[2] + right[3]),\n\t\t\t\t\tleft[3] + right[3] };\n\t\t\treturn ans;\n\t\t}\n\n\t\tpublic void set(int v, int tl, int tr, int x, int value) {\n\t\t\tif (v >= pow) {\n\t\t\t\tsum[v] = value;\n\t\t\t\tmaxSum[v] = Math.max(value, 0);\n\t\t\t\tmaxPrefSum[v] = maxSum[v];\n\t\t\t\tmaxSufSum[v] = maxSum[v];\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint tm = (tl + tr) / 2;\n\t\t\tif (x < tm) {\n\t\t\t\tset(2 * v, tl, tm, x, value);\n\t\t\t} else {\n\t\t\t\tset(2 * v + 1, tm, tr, x, value);\n\t\t\t}\n\t\t\tupdate(v);\n\t\t}\n\n\t\tpublic void update(int i) {\n\t\t\tsum[i] = f(sum[2 * i], sum[2 * i + 1]);\n\t\t\tmaxSum[i] = Math.max(maxSum[2 * i], Math.max(maxSum[2 * i + 1], maxSufSum[2 * i] + maxPrefSum[2 * i + 1]));\n\t\t\tmaxPrefSum[i] = Math.max(maxPrefSum[2 * i], maxPrefSum[2 * i + 1] + sum[2 * i]);\n\t\t\tmaxSufSum[i] = Math.max(maxSufSum[2 * i + 1], maxSufSum[2 * i] + sum[2 * i + 1]);\n\t\t}\n\n\t\tpublic int f(int a, int b) {\n\t\t\treturn a + b;\n\t\t}\n\t}\n\n\tpublic class Point implements Comparable {\n\t\tdouble x;\n\t\tdouble y;\n\n\t\tpublic Point() {\n\t\t\tx = 0;\n\t\t\ty = 0;\n\t\t}\n\n\t\tpublic Point(double x, double y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + \" \" + y;\n\t\t}\n\n\t\tpublic boolean equals(Point p) {\n\t\t\treturn x == p.x && y == p.y;\n\t\t}\n\n\t\tpublic double dist2() {\n\t\t\treturn x * x + y * y;\n\t\t}\n\n\t\tpublic Point add(Point v) {\n\t\t\treturn new Point(x + v.x, y + v.y);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\tint z = signum(x + y - o.x - o.y);\n\t\t\tif (z != 0) {\n\t\t\t\treturn z;\n\t\t\t}\n\t\t\treturn signum(x - o.x) != 0 ? signum(x - o.x) : signum(y - o.y);\n\t\t}\n\t}\n\n\tpublic class Circle implements Comparable {\n\t\tPoint p;\n\t\tint r;\n\n\t\tpublic Circle(Point p, int r) {\n\t\t\tthis.p = p;\n\t\t\tthis.r = r;\n\t\t}\n\n\t\tpublic Point angle() {\n\t\t\tdouble z = r / sq2;\n\t\t\tz -= z % 1e-5;\n\t\t\treturn new Point(p.x - z, p.y - z);\n\t\t}\n\n\t\tpublic boolean inside(Point p) {\n\t\t\treturn hypot2(p.x - this.p.x, p.y - this.p.y) <= sq(r);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Circle o) {\n\t\t\tPoint a = angle();\n\t\t\tPoint oa = o.angle();\n\t\t\tint z = signum(a.x + a.y - oa.x - oa.y);\n\t\t\tif (z != 0) {\n\t\t\t\treturn z;\n\t\t\t}\n\t\t\treturn signum(a.y - oa.y);\n\t\t}\n\n\t}\n\n\tpublic class Fraction implements Comparable {\n\t\tlong x;\n\t\tlong y;\n\n\t\tpublic Fraction(long x, long y, boolean needNorm) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tif (y < 0) {\n\t\t\t\tthis.x *= -1;\n\t\t\t\tthis.y *= -1;\n\t\t\t}\n\t\t\tif (needNorm) {\n\t\t\t\tlong gcd = gcd(this.x, this.y);\n\t\t\t\tthis.x /= gcd;\n\t\t\t\tthis.y /= gcd;\n\t\t\t}\n\t\t}\n\n\t\tpublic Fraction clone() {\n\t\t\treturn new Fraction(x, y, false);\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + \"/\" + y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Fraction o) {\n\t\t\tlong res = x * o.y - y * o.x;\n\t\t\tif (res > 0) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif (res < 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tpublic class Event implements Comparable {\n\t\tFraction f;\n\t\tint type;\n\n\t\tpublic Event(Fraction f, int type) {\n\t\t\tthis.f = f;\n\t\t\tthis.type = type;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Event o) {\n\t\t\tint c = f.compareTo(o.f);\n\t\t\tif (c != 0) {\n\t\t\t\treturn c;\n\t\t\t}\n\t\t\treturn type - o.type;\n\t\t}\n\n\t}\n\n\tpublic double sq(double x) {\n\t\treturn x * x;\n\t}\n\n\tpublic long sq(long x) {\n\t\treturn x * x;\n\t}\n\n\tpublic double hypot2(double x, double y) {\n\t\treturn sq(x) + sq(y);\n\t}\n\n\tpublic long hypot2(long x, long y) {\n\t\treturn sq(x) + sq(y);\n\t}\n\n\tpublic boolean kuhn(int v, int[][] edge, boolean[] used, int[] mt) {\n\t\tused[v] = true;\n\t\tfor (int u : edge[v]) {\n\t\t\tif (mt[u] < 0 || (!used[mt[u]] && kuhn(mt[u], edge, used, mt))) {\n\t\t\t\tmt[u] = v;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic int matching(int[][] edge) {\n\t\tint n = edge.length;\n\t\tint[] mt = new int[n];\n\t\tArrays.fill(mt, -1);\n\t\tboolean[] used = new boolean[n];\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (!used[i] && kuhn(i, edge, used, mt)) {\n\t\t\t\tArrays.fill(used, false);\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\n\tdouble sq2 = Math.sqrt(2);\n\n\tint small = 20;\n\n\tpublic class Stack {\n\t\tint[] st;\n\t\tint sz;\n\n\t\tpublic Stack(int n) {\n\t\t\tthis.st = new int[n];\n\t\t\tsz = 0;\n\t\t}\n\n\t\tpublic boolean isEmpty() {\n\t\t\treturn sz == 0;\n\t\t}\n\n\t\tpublic int peek() {\n\t\t\treturn st[sz - 1];\n\t\t}\n\n\t\tpublic int pop() {\n\t\t\tsz--;\n\t\t\treturn st[sz];\n\t\t}\n\n\t\tpublic void clear() {\n\t\t\tsz = 0;\n\t\t}\n\n\t\tpublic void add(int x) {\n\t\t\tst[sz++] = x;\n\t\t}\n\n\t\tpublic int get(int x) {\n\t\t\treturn st[x];\n\t\t}\n\t}\n\n\tpublic int[][] readGraph(int n, int m) {\n\t\tint[][] to = new int[n][];\n\t\tint[] sz = new int[n];\n\t\tint[] x = new int[m];\n\t\tint[] y = new int[m];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tx[i] = in.nextInt() - 1;\n\t\t\ty[i] = in.nextInt() - 1;\n\t\t\tsz[x[i]]++;\n\t\t\tsz[y[i]]++;\n\t\t}\n\t\tfor (int i = 0; i < to.length; i++) {\n\t\t\tto[i] = new int[sz[i]];\n\t\t\tsz[i] = 0;\n\t\t}\n\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\tto[x[i]][sz[x[i]]++] = y[i];\n\t\t\tto[y[i]][sz[y[i]]++] = x[i];\n\t\t}\n\t\treturn to;\n\t}\n\n\tpublic class Pol {\n\t\tdouble[] coeff;\n\n\t\tpublic Pol(double[] coeff) {\n\t\t\tthis.coeff = coeff;\n\t\t}\n\n\t\tpublic Pol mult(Pol p) {\n\t\t\tdouble[] ans = new double[coeff.length + p.coeff.length - 1];\n\t\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\t\tfor (int j = Math.max(0, i - p.coeff.length + 1); j < coeff.length && j <= i; j++) {\n\t\t\t\t\tans[i] += coeff[j] * p.coeff[i - j];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Pol(ans);\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\tString ans = \"\";\n\t\t\tfor (int i = 0; i < coeff.length; i++) {\n\t\t\t\tans += coeff[i] + \" \";\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t\tpublic double value(double x) {\n\t\t\tdouble ans = 0;\n\t\t\tdouble p = 1;\n\t\t\tfor (int i = 0; i < coeff.length; i++) {\n\t\t\t\tans += coeff[i] * p;\n\t\t\t\tp *= x;\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t\tpublic double integrate(double r) {\n\t\t\tPol p = new Pol(new double[coeff.length + 1]);\n\t\t\tfor (int i = 0; i < coeff.length; i++) {\n\t\t\t\tp.coeff[i + 1] = coeff[i] / fact[i + 1];\n\t\t\t}\n\t\t\treturn p.value(r);\n\t\t}\n\n\t\tpublic double integrate(double l, double r) {\n\t\t\treturn integrate(r) - integrate(l);\n\t\t}\n\t}\n\n\tdouble[] fact = new double[100];\n\n\tpublic class DSU1 {\n\t\tint[] p;\n\t\tint[] sz;\n\t\tStack less;\n\t\tStack more;\n\t\tTreeSet[] q;\n\t\tboolean[] used;\n\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tpublic DSU1(int[] v, int m) {\n\t\t\tint n = v.length;\n\t\t\tp = new int[n];\n\t\t\tsz = new int[n];\n\t\t\tq = new TreeSet[n];\n\t\t\tless = new Stack(m);\n\t\t\tmore = new Stack(m);\n\t\t\tused = new boolean[n + 1];\n\t\t\tfor (int i = 0; i < v.length; i++) {\n\t\t\t\tp[i] = i;\n\t\t\t\tsz[i] = 1;\n\t\t\t\tq[i] = new TreeSet<>();\n\t\t\t\tq[i].add(v[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic int get(int x) {\n\t\t\twhile (x != p[x]) {\n\t\t\t\tx = p[x];\n\t\t\t}\n\t\t\treturn x;\n\t\t}\n\n\t\tpublic boolean unite(int a, int b) {\n\t\t\tint pa = get(a);\n\t\t\tint pb = get(b);\n\t\t\tif (pa == pb) {\n\t\t\t\tless.add(-1);\n\t\t\t\tmore.add(-1);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (sz[pa] < sz[pb]) {\n\t\t\t\tp[pa] = pb;\n\t\t\t\tsz[pb] += sz[pa];\n\n\t\t\t\tless.add(pa);\n\t\t\t\tmore.add(pb);\n\t\t\t\tfor (int i : q[pa]) {\n\t\t\t\t\tq[pb].add(i);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tp[pb] = pa;\n\t\t\t\tsz[pa] += sz[pb];\n\n\t\t\t\tless.add(pb);\n\t\t\t\tmore.add(pa);\n\t\t\t\tfor (int i : q[pb]) {\n\t\t\t\t\tq[pa].add(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic void popEdge() {\n\t\t\tint pa = less.pop();\n\t\t\tint pb = more.pop();\n\t\t\tif (pa < 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (int i : q[pa]) {\n\t\t\t\tq[pb].remove(i);\n\t\t\t}\n\t\t\tp[pa] = pa;\n\t\t\tsz[pb] -= sz[pa];\n\t\t}\n\n\t\tpublic int poll(int x) {\n\t\t\tint px = get(x);\n\t\t\twhile (!q[px].isEmpty()) {\n\t\t\t\tint v = q[px].pollLast();\n\t\t\t\tif (!used[v]) {\n\t\t\t\t\tused[v] = true;\n\t\t\t\t\treturn v;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\n\t}\n\n\tpublic void solve() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint q = in.nextInt();\n\t\tint[] v = new int[n];\n\t\tfor (int i = 0; i < v.length; i++) {\n\t\t\tv[i] = in.nextInt();\n\t\t}\n\t\tint[] a = new int[m];\n\t\tint[] b = new int[m];\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\ta[i] = in.nextInt() - 1;\n\t\t\tb[i] = in.nextInt() - 1;\n\t\t}\n\t\tboolean[] type = new boolean[q];\n\t\tint[] x = new int[q];\n\t\tboolean[] removed = new boolean[m];\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tif (in.nextInt() == 1) {\n\t\t\t\tx[i] = in.nextInt() - 1;\n\t\t\t\ttype[i] = true;\n\t\t\t} else {\n\t\t\t\tx[i] = in.nextInt() - 1;\n\t\t\t\tremoved[x[i]] = true;\n\t\t\t}\n\t\t}\n\t\tDSU1 dsu = new DSU1(v, m);\n\t\tfor (int i = 0; i < removed.length; i++) {\n\t\t\tif (!removed[i]) {\n\t\t\t\tdsu.unite(a[i], b[i]);\n\t\t\t}\n\t\t}\n\t\tfor (int i = q - 1; i >= 0; i--) {\n\t\t\tif (!type[i]) {\n\t\t\t\tdsu.unite(a[x[i]], b[x[i]]);\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tif (type[i]) {\n\t\t\t\tout.println(dsu.poll(x[i]));\n\t\t\t} else {\n\t\t\t\tdsu.popEdge();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic void add(HashMap map, int x) {\n\t\tif (map.containsKey(x)) {\n\t\t\tmap.put(x, map.get(x) + 1);\n\t\t} else {\n\t\t\tmap.put(x, 1);\n\t\t}\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 E().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a14170d6a0818f40ef0317badbd0b50", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n/*\npolyakoff\n*/\n\npublic class Main {\n\n static FastReader in;\n static PrintWriter out;\n static Random rand = new Random();\n static final int oo = (int) 1e9 + 10;\n static final long OO = (long) 2e18 + 20;\n static final int MOD = (int) 1e9 + 7;\n\n static int n;\n static int[] par, p;\n\n static int findSet(int u) {\n if (par[u] == u)\n return u;\n return par[u] = findSet(par[u]);\n }\n\n static class SegTree {\n class Node {\n int max;\n Pair lr;\n\n Node(int max, Pair lr) {\n this.max = max;\n this.lr = lr;\n }\n }\n Node[] t;\n int size;\n\n void push(int u) {\n if (t[u].lr.l != -1) {\n t[u * 2 + 1].lr.l = t[u].lr.l;\n t[u * 2 + 1].lr.r = t[u].lr.r;\n t[u * 2 + 2].lr.l = t[u].lr.l;\n t[u * 2 + 2].lr.r = t[u].lr.r;\n t[u].lr.l = t[u].lr.r = -1;\n }\n }\n void pull(int u) {\n t[u].max = p[t[u * 2 + 1].max] > p[t[u * 2 + 2].max] ? t[u * 2 + 1].max : t[u * 2 + 2].max;\n }\n void build(int u, int tl, int tr, int[][] initial) {\n if (tl == tr) {\n t[u] = new Node(initial[tl][0], new Pair(initial[tl][1], initial[tl][2]));\n } else {\n int tm = (tl + tr) / 2;\n build(u * 2 + 1, tl, tm, initial);\n build(u * 2 + 2, tm + 1, tr, initial);\n t[u] = new Node(-1, new Pair(-1, -1));\n pull(u);\n }\n }\n int maxPOn(int u, int tl, int tr, int l, int r) {\n if (r < tl || tr < l)\n return n;\n if (l <= tl && tr <= r)\n return t[u].max;\n int tm = (tl + tr) / 2;\n push(u);\n int v1 = maxPOn(u * 2 + 1, tl, tm, l, r);\n int v2 = maxPOn(u * 2 + 2, tm + 1, tr, l, r);\n return p[v1] > p[v2] ? v1 : v2;\n }\n void setPIn(int u, int tl, int tr, int i, int p) {\n if (tl == tr) {\n\n } else {\n int tm = (tl + tr) / 2;\n push(u);\n if (i <= tm) {\n setPIn(u * 2 + 1, tl, tm, i, p);\n } else {\n setPIn(u * 2 + 2, tm + 1, tr, i, p);\n }\n pull(u);\n }\n }\n void setLROn(int u, int tl, int tr, int l, int r, int newL, int newR) {\n if (r < tl || tr < l)\n return;\n if (l <= tl && tr <= r) {\n t[u].lr.l = newL;\n t[u].lr.r = newR;\n return;\n }\n int tm = (tl + tr) / 2;\n push(u);\n setLROn(u * 2 + 1, tl, tm, l, r, newL, newR);\n setLROn(u * 2 + 2, tm + 1, tr, l, r, newL, newR);\n pull(u);\n }\n Pair LRIn(int u, int tl, int tr, int i) {\n if (tl == tr) {\n return t[u].lr;\n }\n int tm = (tl + tr) / 2;\n push(u);\n if (i <= tm) {\n return LRIn(u * 2 + 1, tl, tm, i);\n } else {\n return LRIn(u * 2 + 2, tm + 1, tr, i);\n }\n }\n\n void build(int[][] initial) {\n size = initial.length;\n t = new Node[size * 4];\n build(0, 0, size - 1, initial);\n }\n int maxPOn(int l, int r) {\n return maxPOn(0, 0, size - 1, l, r);\n }\n void setPIn(int i, int p) {\n setPIn(0, 0, size - 1, i, p);\n }\n void setLROn(int l, int r, int newL, int newR) {\n setLROn(0, 0, size - 1, l, r, newL, newR);\n }\n Pair LRIn(int i) {\n return LRIn(0, 0, size - 1, i);\n }\n }\n\n static class Pair {\n int l, r;\n\n Pair(int l, int r) {\n this.l = l;\n this.r = r;\n }\n }\n\n static class Edge {\n int u, v, l1, r1, l2, r2;\n boolean removed;\n\n Edge(int u, int v) {\n this.u = u;\n this.v = v;\n l1 = r1 = l2 = r2 = -1;\n }\n }\n\n static class Query {\n int type, x;\n\n Query(int type, int x) {\n this.type = type;\n this.x = x;\n }\n }\n\n static void solve() {\n n = in.nextInt();\n int m = in.nextInt();\n int q = in.nextInt();\n\n p = new int[n + 1];\n p[n] = 0;\n for (int i = 0; i < n; i++) {\n p[i] = in.nextInt();\n }\n\n Edge[] edges = new Edge[m];\n for (int i = 0; i < m; i++) {\n int u = in.nextInt() - 1;\n int v = in.nextInt() - 1;\n edges[i] = new Edge(u, v);\n }\n\n Query[] queries = new Query[q];\n for (int i = 0; i < q; i++) {\n int type = in.nextInt();\n int x = in.nextInt() - 1;\n queries[i] = new Query(type, x);\n if (type == 2)\n edges[x].removed = true;\n }\n\n par = new int[n];\n int[] size = new int[n];\n ArrayList[] subtree = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n par[i] = i;\n size[i] = 1;\n subtree[i] = new ArrayList<>(List.of(i));\n }\n\n for (Edge e : edges) {\n if (e.removed)\n continue;\n int u = findSet(e.u);\n int v = findSet(e.v);\n if (u == v)\n continue;\n if (size[u] < size[v]) {\n u ^= v; v ^= u; u ^= v;\n }\n par[v] = u;\n size[u] += size[v];\n subtree[u].addAll(subtree[v]);\n }\n\n for (int i = q - 1; i >= 0; i--) {\n Query query = queries[i];\n if (query.type == 1)\n continue;\n Edge e = edges[query.x];\n int u = findSet(e.u);\n int v = findSet(e.v);\n if (u == v)\n continue;\n if (size[u] < size[v]) {\n u ^= v; v ^= u; u ^= v;\n }\n par[v] = u;\n size[u] += size[v];\n e.l1 = subtree[u].get(0);\n e.r1 = subtree[u].get(subtree[u].size() - 1);\n e.l2 = subtree[v].get(0);\n e.r2 = subtree[v].get(subtree[v].size() - 1);\n subtree[u].addAll(subtree[v]);\n }\n\n int[][] initial = new int[n][3];\n int[] pos = new int[n];\n for (int u = 0, i = 0; u < n; u++) {\n if (findSet(u) == u) {\n initial[u][1] = i;\n initial[u][2] = i + size[u] - 1;\n for (int v : subtree[u]) {\n initial[i][0] = v;\n initial[i][1] = initial[u][1];\n initial[i][2] = initial[u][2];\n pos[v] = i;\n i++;\n }\n }\n }\n\n SegTree st = new SegTree();\n st.build(initial);\n\n for (int i = 0; i < q; i++) {\n Query query = queries[i];\n if (query.type == 1) {\n int u = query.x;\n Pair lr = st.LRIn(pos[u]);\n int v = st.maxPOn(lr.l, lr.r);\n out.println(p[v]);\n if (v != n) {\n p[v] = 0;\n st.setPIn(pos[v], 0);\n }\n } else {\n Edge e = edges[query.x];\n if (e.l1 != -1) {\n st.setLROn(pos[e.l1], pos[e.r1], pos[e.l1], pos[e.r1]);\n st.setLROn(pos[e.l2], pos[e.r2], pos[e.l2], pos[e.r2]);\n }\n }\n }\n\n\n }\n\n\n public static void main(String[] args) {\n in = new FastReader();\n out = new PrintWriter(System.out);\n// fileInputOutput();\n\n int T = 1;\n// T = in.nextInt();\n while (T-- > 0)\n solve();\n\n out.flush();\n out.close();\n }\n\n static void fileInputOutput() {\n try {\n in = new FastReader(\"input.txt\");\n out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n } catch (FileNotFoundException e) {\n throw new RuntimeException(e);\n }\n }\n\n static void runInThread() {\n Thread thread = new Thread(null, () -> {\n int T = 1;\n// T = in.nextInt();\n while (T-- > 0)\n solve();\n }, \"thread1\", 1 << 28);\n thread.start();\n try {\n thread.join();\n } catch (InterruptedException e) {\n throw new RuntimeException(e);\n }\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n FastReader() {\n this(System.in);\n }\n FastReader(String file) throws FileNotFoundException {\n this(new FileInputStream(file));\n }\n FastReader(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n long nextLong() {\n return Long.parseLong(next());\n }\n double nextDouble() {\n return Double.parseDouble(next());\n }\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine());\n }\n return st.nextToken();\n }\n String nextLine() {\n String line;\n try {\n line = br.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "599718873063bba26a3cc2ab888546b3", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0} {"lang": "Java 7", "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=1000;\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 Math.min(cnt, b.cnt)+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; imax) {\n max=h;\n }\n }\n }\n \n return max;\n }\n \n static long cnt_between(bits[] in, int l, int r, long max) {\n int l2=l, r2=r;\n while (l2+1<=r&&in[l2+1].cnt==in[l].cnt) {\n l2++;\n }\n while (r2-1>=l&&in[r2-1].cnt==in[r].cnt) {\n r2--;\n }\n \n if(l2>=r2) {\n return max==0? (long)(r-l)*(long)(r-l-1)*(long)(r-l-2)/6: 0;\n }\n\n long ret=0;\n for (int i=l+1; i=r2? r2+1: r2)+1);\n ret+=v;\n if(DEBUG) {\n System.out.println(\"added \"+v+\" for \"+i+\" in[\"+l+\",\"+r+\"]\");\n }\n }\n }\n return ret;\n }\n \n static long cnt_pairs(int l1, int l2, int r1, int r2) {\n if(l2() {\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=max0+1&&in[lo].cnt>in[i].cnt) {\n lo--;\n }\n\n while(hi-1>max0+1&&in[hi-1].cnt>=in[i].cnt) {\n hi--;\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=in[i].cnt) {\n lo++;\n }\n \n while(hi+1<=max0&&in[hi].cnt>in[i].cnt) {\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; imax) {\n max=h(in[i],in[j],in[k]);\n ret=1;\n if(DEBUG&&max==20) {\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==20) {\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1817feee96bb63564a18a68e22acea51", "src_uid": "bfc61d3e967fc28e1ab5b9028856125b", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint ansVal = -1;\n\tlong ansCnt = 0;\n\n\tvoid updateAns(int val, long count) {\n\t\tif (count == 0) {\n\t\t\treturn;\n\t\t}\n\t\tif (val > ansVal) {\n\t\t\tansVal = val;\n\t\t\tansCnt = count;\n\t\t} else if (val == ansVal) {\n\t\t\tansCnt += count;\n\t\t}\n\t}\n\n\tstatic class Group {\n\t\tint val;\n\t\tint rep;\n\n\t\tpublic Group(int val, int rep) {\n\t\t\tthis.val = val;\n\t\t\tthis.rep = rep;\n\t\t}\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\n\t\tList aList = new ArrayList<>();\n\t\tList bList = new ArrayList<>();\n\n\t\tint na, nb;\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint type = nextInt();\n\t\t\tint val = nextInt();\n\t\t\t(type == 0 ? aList : bList).add(val);\n\t\t}\n\n\t\tna = aList.size();\n\t\tnb = bList.size();\n\n\t\tGroup[] a = makeGroups(aList);\n\t\tGroup[] b = makeGroups(bList);\n\n\t\tsolve1(a, na);\n\t\tsolve1(b, nb);\n\t\tsolve2(a, b, n, na, nb);\n\t\tsolve2(b, a, n, na, nb);\n\n\t\tout.println(ansCnt);\n\t}\n\n\tGroup[] makeGroups(List a) {\n\t\tCollections.sort(a);\n\t\tList b = new ArrayList<>();\n\t\tfor (int i = 0, j = -1; i < a.size(); i = j) {\n\t\t\tj = i;\n\t\t\tint st = a.get(i);\n\t\t\twhile (j < a.size() && a.get(j).intValue() == st) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tb.add(new Group(st, j - i));\n\t\t}\n\t\treturn b.toArray(new Group[b.size()]);\n\t}\n\n\tvoid solve1(Group[] a, int realLen) {\n\t\tif (a.length == 0) {\n\t\t\treturn;\n\t\t}\n\t\tint n = a.length;\n\t\tint val = 2 * (a[n - 1].val - a[0].val);\n\t\tlong count;\n\t\tif (a.length == 1) {\n\t\t\tcount = (long) realLen * (realLen - 1) * (realLen - 2) / 6;\n\t\t} else {\n\t\t\tint pref = a[0].rep;\n\t\t\tint suff = a[n - 1].rep;\n\n\t\t\tcount = (long) pref * (realLen - pref - suff) * suff + (long) pref\n\t\t\t\t\t* (pref - 1) / 2 * suff + (long) pref * suff * (suff - 1)\n\t\t\t\t\t/ 2;\n\t\t}\n\t\tupdateAns(val, count);\n\t}\n\n\tlong C2(int x) {\n\t\treturn (long) x * (x - 1) / 2;\n\t}\n\n\tvoid solve2(Group[] a, Group[] b, int n, int realLenA, int realLenB) {\n\t\tint na = a.length;\n\t\tint nb = b.length;\n\n\t\tif (na == 0 || nb == 0) {\n\t\t\treturn;\n\t\t}\n\t\t// j is last in b <= a[i]\n\n\t\tint totBNotMore = 0;\n\t\tint totBMore = realLenB;\n\n\t\tfor (int i = 0, j = -1; i < na; i++) {\n\t\t\twhile (j < nb - 1 && b[j + 1].val <= a[i].val) {\n\t\t\t\tj++;\n\t\t\t\ttotBNotMore += b[j].rep;\n\t\t\t\ttotBMore -= b[j].rep;\n\t\t\t}\n\t\t\t// both <=\n\t\t\tif (j >= 0) {\n\t\t\t\tint val = 2 * (b[j].val + n - a[i].val);\n\t\t\t\tlong count = (long) a[i].rep\n\t\t\t\t\t\t* (C2(totBNotMore) - C2(totBNotMore - b[j].rep));\n\t\t\t\tupdateAns(val, count);\n\t\t\t}\n\n\t\t\t// <= and >\n\t\t\tif (j >= 0 && j < nb - 1) {\n\t\t\t\tint val = 2 * n;\n\t\t\t\tlong count = (long) a[i].rep * totBNotMore * totBMore;\n\t\t\t\tupdateAns(val, count);\n\t\t\t}\n\n\t\t\t// both >\n\t\t\tif (j < nb - 1) {\n\t\t\t\t// System.err.println(\"?\");\n\t\t\t\tint val = 2 * (-b[j + 1].val + n + a[i].val);\n\t\t\t\tlong count = (long) a[i].rep\n\t\t\t\t\t\t* (C2(totBMore) - C2(totBMore - b[j + 1].rep));\n\t\t\t\tupdateAns(val, count);\n\t\t\t}\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dfc58c3f05ea6e7417888013d77e7f79", "src_uid": "bfc61d3e967fc28e1ab5b9028856125b", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n public static void main(String args[]) throws Exception {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.main(in, out);\n out.close();\n }\n}\n\nclass Task {\n final int maxn = 41111;\n ArrayList Beg, End;\n Integer[] X, Y;\n int N, M;\n PrintStream cout = System.out;\n\n void print(Object[] arr) {\n cout.println(\"print arr :\");\n for (Object i : arr) {\n cout.print(i + \" \");\n }\n cout.println();\n }\n\n int value;\n long ans = 0;\n\n void update(int v, long c) {\n if (v == value) {\n ans += c;\n } else if (v > value) {\n value = v;\n ans = c;\n }\n }\n\n long calc(long n) {\n n = n * n - n;\n n >>= 1;\n return n;\n }\n\n long single(Integer[] x) {\n int n = x.length;\n int mi = x[0];\n int ma = x[n - 1];\n int a = 0, b = 0;\n\n long ans = n;\n if (x[0].equals(x[n - 1])) {\n ans = ans * (ans - 1) * (ans - 2) / 6;\n\n } else {\n for (int i = 0; i < n; ++i) {\n if (x[i] == x[0])\n ++a;\n if (x[i] == x[0])\n ++b;\n }\n ans -= b + a;\n ans = ans * a * b;\n ans += calc(a) * b;\n ans += calc(b) * a;\n }\n return ans;\n }\n\n void run(Integer x[], Integer y[]) {\n int n = x.length;\n int m = y.length;\n int i, j;\n long sub = 0;\n int c = 0;\n for (i = 0, j = 0; i < n; ++i) {\n while (j < m && y[j] < x[i]) {\n ++j;\n ++c;\n }\n sub += calc(c);\n }\n c = 0;\n for (i = n - 1, j = m - 1; i >= 0; --i) {\n while (j >= 0 && y[j] > x[i]) {\n --j;\n ++c;\n }\n sub += calc(c);\n }\n sub = calc(m) * n - sub;\n\n update(N * 2, sub);\n }\n\n void main(InputReader in, PrintWriter out) throws Exception {\n Beg = new ArrayList();\n End = new ArrayList();\n N = in.nextInt();\n M = in.nextInt();\n for (int i = 0; i < M; ++i) {\n int t, s;\n t = in.nextInt();\n s = in.nextInt();\n if (t == 0) {\n Beg.add(s);\n } else {\n End.add(s);\n }\n }\n // out.println(Beg.size());\n X = Beg.toArray(new Integer[Beg.size()]);\n Y = End.toArray(new Integer[End.size()]);\n Arrays.sort(X);\n Arrays.sort(Y);\n // print(X);\n // print(Y);\n int n = X.length;\n int m = Y.length;\n ans = 0;\n if (m > 2) {\n update(2 * (Y[m - 1] - Y[0]), single(Y));\n\n }\n if (n > 2) {\n update(2 * (X[n - 1] - X[0]), single(X));\n\n }\n if (n > 0 && m > 0) {\n if (X[n - 1] < Y[0]) {\n update(N * 2 - (Y[0] - X[n - 1]), m + n - 2);\n } else if (X[0] > Y[m - 1]) {\n update(N * 2 - (X[0] - Y[m - 1]), m + n - 2);\n } else {\n run(X, Y);\n run(Y, X);\n }\n }\n out.println(ans);\n\n }\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n String next() {\n if (!hasNext())\n throw new RuntimeException();\n return tokenizer.nextToken();\n }\n\n boolean hasNext() {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n return false;\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ac7c1c17e127f0aa57705e3aafcb9c91", "src_uid": "bfc61d3e967fc28e1ab5b9028856125b", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint ansVal = -1;\n\tlong ansCnt = 0;\n\n\tvoid updateAns(int val, long count) {\n\t\tif (count == 0) {\n\t\t\treturn;\n\t\t}\n\t\tif (val > ansVal) {\n\t\t\tansVal = val;\n\t\t\tansCnt = count;\n\t\t} else if (val == ansVal) {\n\t\t\tansCnt += count;\n\t\t}\n\t}\n\n\tstatic class Group {\n\t\tint val;\n\t\tint rep;\n\n\t\tpublic Group(int val, int rep) {\n\t\t\tthis.val = val;\n\t\t\tthis.rep = rep;\n\t\t}\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\n\t\tList aList = new ArrayList<>();\n\t\tList bList = new ArrayList<>();\n\n\t\tint na, nb;\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint type = nextInt();\n\t\t\tint val = nextInt();\n\t\t\t(type == 0 ? aList : bList).add(val);\n\t\t}\n\n\t\tna = aList.size();\n\t\tnb = bList.size();\n\n\t\tGroup[] a = makeGroups(aList);\n\t\tGroup[] b = makeGroups(bList);\n\n\t\tsolve1(a, na);\n\t\tsolve1(b, nb);\n\t\tsolve2(a, b, n, na, nb);\n\t\tsolve2(b, a, n, na, nb);\n\n\t\tout.println(ansCnt);\n\t}\n\n\tGroup[] makeGroups(List a) {\n\t\tCollections.sort(a);\n\t\tList b = new ArrayList<>();\n\t\tfor (int i = 0, j = -1; i < a.size(); i = j) {\n\t\t\tj = i;\n\t\t\tint st = a.get(i);\n\t\t\twhile (j < a.size() && a.get(j).intValue() == st) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tb.add(new Group(st, j - i));\n\t\t}\n\t\treturn b.toArray(new Group[b.size()]);\n\t}\n\n\tvoid solve1(Group[] a, int realLen) {\n\t\tif (a.length == 0) {\n\t\t\treturn;\n\t\t}\n\t\tint n = a.length;\n\t\tint val = a[n - 1].val - a[0].val;\n\t\tlong count;\n\t\tif (a.length == 1) {\n\t\t\tcount = (long) realLen * (realLen - 1) * (realLen - 2) / 6;\n\t\t} else {\n\t\t\tint pref = a[0].rep;\n\t\t\tint suff = a[n - 1].rep;\n\n\t\t\tcount = (long) pref * (realLen - pref - suff) * suff + (long) pref\n\t\t\t\t\t* (pref - 1) / 2 * suff + (long) pref * suff * (suff - 1)\n\t\t\t\t\t/ 2;\n\t\t}\n\t\tupdateAns(val, count);\n\t}\n\n\tlong C2(int x) {\n\t\treturn (long) x * (x - 1) / 2;\n\t}\n\n\tvoid solve2(Group[] a, Group[] b, int n, int realLenA, int realLenB) {\n\t\tint na = a.length;\n\t\tint nb = b.length;\n\n\t\tif (na == 0 || nb == 0) {\n\t\t\treturn;\n\t\t}\n\t\t// j is last in b <= a[i]\n\n\t\tint totBNotMore = 0;\n\t\tint totBMore = realLenB;\n\n\t\tfor (int i = 0, j = -1; i < na; i++) {\n\t\t\twhile (j < nb - 1 && b[j + 1].val <= a[i].val) {\n\t\t\t\tj++;\n\t\t\t\ttotBNotMore += b[j].rep;\n\t\t\t\ttotBMore -= b[j].rep;\n\t\t\t}\n\t\t\t// both <=\n\t\t\tif (j >= 0) {\n\t\t\t\tint val = 2 * (b[j].val + n - a[i].val);\n\t\t\t\tlong count = (long) a[i].rep\n\t\t\t\t\t\t* (C2(totBNotMore) - C2(totBNotMore - b[j].rep));\n\t\t\t\tupdateAns(val, count);\n\t\t\t}\n\n\t\t\t// <= and >\n\t\t\tif (j >= 0 && j < nb - 1) {\n\t\t\t\tint val = 2 * n;\n\t\t\t\tlong count = (long) a[i].rep * totBNotMore * totBMore;\n\t\t\t\tupdateAns(val, count);\n\t\t\t}\n\n\t\t\t// both >\n\t\t\tif (j < nb - 1) {\n\t\t\t\t// System.err.println(\"?\");\n\t\t\t\tint val = 2 * (-b[j + 1].val + n + a[i].val);\n\t\t\t\tlong count = (long) a[i].rep\n\t\t\t\t\t\t* (C2(totBMore) - C2(totBMore - b[j + 1].rep));\n\t\t\t\tupdateAns(val, count);\n\t\t\t}\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "38dad7631f054009a0e8ead29199fb1b", "src_uid": "bfc61d3e967fc28e1ab5b9028856125b", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Codeforces832E {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] sp = br.readLine().split(\" \");\n\t\tint n = Integer.parseInt(sp[0]);\n\t\tint m = Integer.parseInt(sp[1]);\n\t\tint[][] matrix = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tString s = sp[0];\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tmatrix[i][j] = (int) s.charAt(j) - 97;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint counter = 0;\n\t\tint i = 0;\n\t\twhile ((i < n) && (counter < m)) {\n\t\t\tif (matrix[i][counter] == 0) {\n\t\t\t\tint counter2 = -1;\n\t\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\t\tif (matrix[j][counter] != 0) {\n\t\t\t\t\t\tcounter2 = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (counter2 == -1)\n\t\t\t\t\tcounter++;\n\t\t\t\telse {\n\t\t\t\t\tfor (int k = counter; k < m; k++) {\n\t\t\t\t\t\tint temp = matrix[i][k];\n\t\t\t\t\t\tmatrix[i][k] = matrix[counter2][k];\n\t\t\t\t\t\tmatrix[counter2][k] = temp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ((counter < m) && (matrix[i][counter] != 0)) {\n\t\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\t\tint z = matrix[j][counter];\n\t\t\t\t\tfor (int k = counter; k < m; k++) {\n\t\t\t\t\t\tmatrix[j][k] -= z*matrix[i][k]*matrix[i][counter]*matrix[i][counter]*matrix[i][counter];\n\t\t\t\t\t\tmatrix[j][k] = (matrix[j][k]+2000)%5;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t\tcounter++;\n\t\t\t}\t\t\t\n\t\t}\n\t\tint asdf = i;\n\t\t\n\t\tint[] firstnonzero = new int[n];\n\t\tint counter2 = 0;\n\t\tfor (i = 0; i < asdf; i++) {\n\t\t\twhile (matrix[i][counter2] == 0)\n\t\t\t\tcounter2++;\n\t\t\tfirstnonzero[i] = counter2;\n\t\t}\n\t\t\n\t\tint val = 1;\n\t\tif (n > asdf)\n\t\t\tval = fivepower(n-asdf, 1000000007);\n\t\tsp = br.readLine().split(\" \");\n\t\tint q = Integer.parseInt(sp[0]);\n\t\tfor (i = 0; i < q; i++)\t{\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tString t = sp[0];\n\t\t\tint[] result = new int[m];\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tresult[j] = (int) t.charAt(j) - 97;\n\t\t\t}\n\t\t\tfor (int k = 0; k < asdf; k++) {\n\t\t\t\tint u = result[firstnonzero[k]];\n\t\t\t\tfor (int l = firstnonzero[k]; l < m; l++) {\n\t\t\t\t\tresult[l] -= u*matrix[k][l]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]];\n\t\t\t\t\tresult[l] = (result[l]+2000)%5;\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean bool = true;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif (result[j] != 0)\n\t\t\t\t\tbool = false;\n\t\t\t}\n\t\t\tif (bool)\n\t\t\t\tSystem.out.println(val);\n\t\t\telse\n\t\t\t\tSystem.out.println(0);\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tpublic static int fivepower(int n, int mod) {\n\t\tlong a = 1;\n\t\twhile (n > 0) {\n\t\t\ta *= 5;\n\t\t\tn --;\n\t\t\ta %= mod;\n\t\t}\n\t\treturn (int) a;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d4f7312d2417038fb4fb709ba57027d", "src_uid": "5cb18864c88b7fdec4a85718df67333e", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Codeforces832E {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] sp = br.readLine().split(\" \");\n\t\tint n = Integer.parseInt(sp[0]);\n\t\tint m = Integer.parseInt(sp[1]);\n\t\tint[][] matrix = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tString s = sp[0];\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tmatrix[i][j] = (int) s.charAt(j) - 97;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint counter = 0;\n\t\tint i = 0;\n\t\twhile ((i < n) && (counter < m)) {\n\t\t\tif (matrix[i][counter] == 0) {\n\t\t\t\tint counter2 = -1;\n\t\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\t\tif (matrix[j][counter] != 0) {\n\t\t\t\t\t\tcounter2 = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (counter2 == -1)\n\t\t\t\t\tcounter++;\n\t\t\t\telse {\n\t\t\t\t\tfor (int k = counter; k < m; k++) {\n\t\t\t\t\t\tint temp = matrix[i][k];\n\t\t\t\t\t\tmatrix[i][k] = matrix[counter2][k];\n\t\t\t\t\t\tmatrix[counter2][k] = temp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (matrix[i][counter] != 0) {\n\t\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\t\tint z = matrix[j][counter];\n\t\t\t\t\tfor (int k = counter; k < m; k++) {\n\t\t\t\t\t\tmatrix[j][k] -= z*matrix[i][k]*matrix[i][counter]*matrix[i][counter]*matrix[i][counter];\n\t\t\t\t\t\tmatrix[j][k] = (matrix[j][k]+2000)%5;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t\tcounter++;\n\t\t\t}\t\t\t\n\t\t}\n\t\tint asdf = i;\n\t\tfor (i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tSystem.out.print(matrix[i][j] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t\t\n\t\tint[] firstnonzero = new int[n];\n\t\tint counter2 = 0;\n\t\tfor (i = 0; i < asdf; i++) {\n\t\t\twhile (matrix[i][counter2] == 0)\n\t\t\t\tcounter2++;\n\t\t\tfirstnonzero[i] = counter2;\n\t\t}\n\t\t\n\t\tint val = 1;\n\t\tif (n > asdf)\n\t\t\tval = fivepower(n-asdf, 1000000007);\n\t\tsp = br.readLine().split(\" \");\n\t\tint q = Integer.parseInt(sp[0]);\n\t\tfor (i = 0; i < q; i++)\t{\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tString t = sp[0];\n\t\t\tint[] result = new int[m];\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tresult[j] = (int) t.charAt(j) - 97;\n\t\t\t}\n\t\t\tfor (int k = 0; k < asdf; k++) {\n\t\t\t\tint u = result[firstnonzero[k]];\n\t\t\t\tfor (int l = firstnonzero[k]; l < m; l++) {\n\t\t\t\t\tresult[l] -= u*matrix[k][l]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]];\n\t\t\t\t\tresult[l] = (result[l]+2000)%5;\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean bool = true;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif (result[j] != 0)\n\t\t\t\t\tbool = false;\n\t\t\t}\n\t\t\tif (bool)\n\t\t\t\tSystem.out.println(val);\n\t\t\telse\n\t\t\t\tSystem.out.println(0);\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tpublic static int fivepower(int n, int mod) {\n\t\tlong a = 5;\n\t\twhile (n > 0) {\n\t\t\tif (n%2 == 1) {\n\t\t\t\tn /= 2;\n\t\t\t\ta = (5*a*a)%mod;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tn /= 2;\n\t\t\t\ta = (a*a)%mod;\n\t\t\t}\n\t\t}\n\t\treturn (int) a;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d97b53b8ce68215fbfd468f971ba5fd", "src_uid": "5cb18864c88b7fdec4a85718df67333e", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "//package round425;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\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\tsum %= mod;\n\t\t\t}\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0bb212ec1ff9a89111dbbb3a40594db0", "src_uid": "5cb18864c88b7fdec4a85718df67333e", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Codeforces832E {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] sp = br.readLine().split(\" \");\n\t\tint n = Integer.parseInt(sp[0]);\n\t\tint m = Integer.parseInt(sp[1]);\n\t\tint[][] matrix = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tString s = sp[0];\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tmatrix[i][j] = (int) s.charAt(j) - 97;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint counter = 0;\n\t\tint i = 0;\n\t\twhile ((i < n) && (counter < m)) {\n\t\t\tif (matrix[i][counter] == 0) {\n\t\t\t\tint counter2 = -1;\n\t\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\t\tif (matrix[j][counter] != 0) {\n\t\t\t\t\t\tcounter2 = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (counter2 == -1)\n\t\t\t\t\tcounter++;\n\t\t\t\telse {\n\t\t\t\t\tfor (int k = counter; k < m; k++) {\n\t\t\t\t\t\tint temp = matrix[i][k];\n\t\t\t\t\t\tmatrix[i][k] = matrix[counter2][k];\n\t\t\t\t\t\tmatrix[counter2][k] = temp;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (matrix[i][counter] != 0) {\n\t\t\t\tfor (int j = i+1; j < n; j++) {\n\t\t\t\t\tint z = matrix[j][counter];\n\t\t\t\t\tfor (int k = counter; k < m; k++) {\n\t\t\t\t\t\tmatrix[j][k] -= z*matrix[i][k]*matrix[i][counter]*matrix[i][counter]*matrix[i][counter];\n\t\t\t\t\t\tmatrix[j][k] = (matrix[j][k]+2000)%5;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t\tcounter++;\n\t\t\t}\t\t\t\n\t\t}\n\t\tint asdf = i;\n\t\t\n\t\tint[] firstnonzero = new int[n];\n\t\tint counter2 = 0;\n\t\tfor (i = 0; i < asdf; i++) {\n\t\t\twhile (matrix[i][counter2] == 0)\n\t\t\t\tcounter2++;\n\t\t\tfirstnonzero[i] = counter2;\n\t\t}\n\t\t\n\t\tint val = 1;\n\t\tif (n > asdf)\n\t\t\tval = fivepower(n-asdf, 1000000007);\n\t\tsp = br.readLine().split(\" \");\n\t\tint q = Integer.parseInt(sp[0]);\n\t\tfor (i = 0; i < q; i++)\t{\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tString t = sp[0];\n\t\t\tint[] result = new int[m];\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tresult[j] = (int) t.charAt(j) - 97;\n\t\t\t}\n\t\t\tfor (int k = 0; k < asdf; k++) {\n\t\t\t\tint u = result[firstnonzero[k]];\n\t\t\t\tfor (int l = firstnonzero[k]; l < m; l++) {\n\t\t\t\t\tresult[l] -= u*matrix[k][l]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]];\n\t\t\t\t\tresult[l] = (result[l]+2000)%5;\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean bool = true;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif (result[j] != 0)\n\t\t\t\t\tbool = false;\n\t\t\t}\n\t\t\tif (bool)\n\t\t\t\tSystem.out.println(val);\n\t\t\telse\n\t\t\t\tSystem.out.println(0);\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tpublic static int fivepower(int n, int mod) {\n\t\tlong a = 5;\n\t\twhile (n > 0) {\n\t\t\tif (n%2 == 1) {\n\t\t\t\tn /= 2;\n\t\t\t\ta = (5*a*a)%mod;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tn /= 2;\n\t\t\t\ta = (a*a)%mod;\n\t\t\t}\n\t\t}\n\t\treturn (int) a;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f11ee1586f5acfc2d5d02684815611a7", "src_uid": "5cb18864c88b7fdec4a85718df67333e", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n/**\n *\n * @author Darkhan\n */\npublic class task4 {\n static int[] a, b, ar;\n static int n, d;\n static long x;\n static ArrayList bset = new ArrayList<>();\n static TreeSet aset = new TreeSet<>();\n public static void main (String[] args){\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n n = in.nextInt();\n d = in.nextInt();\n x = in.nextLong();\n a = new int[n];\n b = new int[n];\n ar = new int[n+1];\n initAB();\n Iterator it;\n long t;\n if (d < 3000){\n for (int i=0;i bset = new ArrayList<>();\n static TreeSet aset = new TreeSet<>();\n public static void main (String[] args){\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n n = in.nextInt();\n d = in.nextInt();\n x = in.nextLong();\n a = new int[n];\n b = new int[n];\n ar = new int[n+1];\n initAB();\n Iterator it;\n long t;\n if (d < 3000){\n for (int i=0;i i) break;\n t = Math.max(t, a[i-br[j]]);\n }\n System.out.println(t);\n }\n }\n public static long getNextX() {\n x = (x * 37 + 10007) % 1000000007;\n return x;\n }\n public static void initAB() {\n for(int i = 0; i < n; i = i + 1){\n a[i] = i + 1;\n }\n for(int i = 0; i < n; i = i + 1){\n swap(a, i, (int)(getNextX() % (i + 1)));\n }\n for(int i = 0; i < n; i = i + 1){\n if (i < d){\n b[i] = 1;\n br[++br[0]] = i;\n }\n else\n b[i] = 0;\n }\n for(int i = 0; i < n; i = i + 1){\n swap(b, i, (int)(getNextX() % (i + 1)));\n }\n }\n public static void swap(int[] a, int i, int j){\n int t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f49ca73e0dc3a713e0e60e9d676844ff", "src_uid": "948ae7a0189ada07c8c67a1757f691f0", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n \n\npublic class Snippet {\n static long x;\n static int n, d;\n static int[] a;\n static int[] b;\n static long getNextX() {\n x = (x * 37 + 10007) % 1000000007;\n return x;\n }\n static void initAB() {\n int i;\n for(i = 0; i < n; i = i + 1){\n a[i] = i+1;\n }\n for(i = 0; i < n; i = i + 1){\n swap(a, i, (int)getNextX() % (i + 1) );\n }\n for(i = 0; i < n; i = i + 1){\n if (i < d)\n b[i] = 1;\n else\n b[i] = 0;\n }\n for(i = 0; i < n; i = i + 1){\n swap(b, i, (int)getNextX() % (i + 1) );\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 public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n n = sc.nextInt();\n d = sc.nextInt();\n x = sc.nextLong();\n \n a = new int[n];\n b = new int[n];\n initAB();\n\n List b1 = new ArrayList();\n if (d < 1000) {\n for (int i =0; i < n; ++i) {\n int c = 0;\n if (b[i] == 1) b1.add(i);\n for (int j = 0; j < b1.size(); ++j) {\n c = Math.max(c, a[i - b1.get(j)]);\n }\n out.println(c);\n }\n } else {\n int[] arr = new int[n + 1];\n for (int i = 0; i < n; ++i) arr[a[i]] = i;\n TreeSet set = new TreeSet();\n label:\n for (int i = 0; i < n; ++i) {\n set.add(-a[i]);\n for (int k : set) {\n int j = arr[-k];\n if (b[i - j] == 1) {\n out.println(-k);\n continue label;\n }\n }\n out.println(0);\n }\n }\n \n }\n public static void debug(Object... o) {\n System.out.println(Arrays.deepToString(o));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ebb8dec959d49c17b77c889afe3b3d19", "src_uid": "948ae7a0189ada07c8c67a1757f691f0", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.LinkedList;\n\n\npublic class Div2_287 {\n\tpublic static int n,k,m;\n\tpublic static long[] possibilties ;\n\tpublic static long[] tens;\n\tpublic static long[][][] memo;\n\t\n\tpublic static long rec(int i,long mod,int l){\n\t\tif(mod==0 && l>0){\n\t\t\treturn memo[i][(int) mod][l]= possibilties[i]%m;\n\t\t}\n\t\tif(i==0 ){\n\t\t\treturn 0;\n\t\t}\n\t\t\n//\t\t\n\t\tif( memo[i][(int) mod][l]!=-1 )\n\t\t\treturn memo[i][(int) mod][l]%m;\n//\t\t\n\t\tlong ways=0;\n\t\t\n\t\tfor(int j=0;j<10;j++){\n\t\t\t\n\t\t\tlong curr = ( (j)%k * (tens[n-i])%k )%k;\n\t\t\tways = (ways%m + rec(i-1 , (mod %k+ curr%k) %k , j)%m)%m;\n\t\t\t\n\t\t}\n\t\t\n\t\treturn memo[i][(int) mod][l]=ways%m;\n\t}\n\t\n\tpublic static void main(String[] args)throws Exception{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] in=br.readLine().split(\" \");\n\t\tn=Integer.parseInt(in[0]);\n\t\tk=Integer.parseInt(in[1]);\n\t\tm=Integer.parseInt(in[2]);\n\t\tpossibilties = new long[n+5];\n\t\ttens = new long[n+5];\n\t\t\n\t\tpossibilties[0]=1;\n\t\t\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tpossibilties[i]=9;\n\t\t\tfor(int j=1;j= MOD) res -= MOD;\n }\n return memo[reached][modSoFar][idx] = res;\n }\n\n public void solve(int testNumber, Scanner sc, PrintWriter out) {\n N = sc.nextInt();\n K = sc.nextInt();\n MOD = sc.nextInt();\n pow10 = new int[N];\n pow10[0] = 1;\n for (int i = 1; i < N; i++)\n pow10[i] = (int) (10L * pow10[i - 1] % K);\n memo = new int[2][K + 1][N + 1];\n for (int[][] mm : memo) for (int[] m : mm) Arrays.fill(m, -1);\n out.println(dp(0, 0, 0));\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 Scanner(FileReader f) {\n br = new BufferedReader(f);\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens())\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e7b21c3998bef1922de5d271d7d5c1f3", "src_uid": "656bf8df1e79499aa2ab2c28712851f0", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.util.Map.Entry;\n\npublic class D {\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tlong n = scan.nextInt();\n\t\tlong k = scan.nextInt();\n\t\tlong m = scan.nextInt();\n\t\t\n\t\t//long n = 5;\n\t\t//long k = 3;\n\t\t//long m = 1103;\n\t\t\n\t\tlong[][] dp = new long[(int)m][(int)k];\n\t\t\n\t\tfor (int i = 1; i<10; i++) {\n\t\t\tint ind = (int)(i%k);\n\t\t\tdp[0][ind] += 1;\n\t\t\tdp[0][ind] %= m;\n\t\t}\n\t\t\n\t\tlong mult = 1;\n\t\tfor (int i = 1; i=0; i--) {\n\t\t\t//System.out.println(i + \" \" + dp[i][0] + \" \" + dp[i][0]%m);\n\t\t\ttot += dp[i][0]*mult2;\n\t\t\ttot %= m;\n\t\t\tmult2 *= 10;\n\t\t\tmult2 %= m;\n\t\t}\n\t\ttot += dp[(int)n-1][0];\n\t\ttot %= m;\n\t\t//System.out.println(\"\\n\" + tot);\n\t\tSystem.out.println(tot);\n\t\t//System.out.println();\n\t\t//test(5,3,1103);\n\t\t\n\t\tscan.close();\n\t}\n\t\n\tpublic static void test(int n, int k, int m) {\n\t\t\n\t\tint s = 1;\n\t\tint e = 10;\n\t\tfor (int i = 1; i 0 || j > 0) {\n\t\t\tres.append(move[i][j]);\n\t\t\tif (move[i][j] == 'H')\n\t\t\t\t--i;\n\t\t\telse\n\t\t\t\t--j;\n\t\t}\n\t\tout.print(res.reverse());\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\n\t\t\t_main();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(202);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "da7ea8d00b330003afc88d933b35ec8b", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st;\n\n int n;\n int[] v;\n\n long[][] dp;\n long[] pow;\n\n String[][] pred;\n\n void solve() throws IOException {\n pow = new long[18];\n pow[0] = 1;\n for (int i = 1; i < pow.length; ++i)\n pow[i] = pow[i - 1] * 10L;\n n = ni();\n v = new int[2 * n];\n dp = new long[2 * n + 1][n + 1];\n pred = new String[2 * n + 1][n + 1];\n for (int i = 0; i < pred.length; i++) {\n Arrays.fill(pred[i], \"\");\n }\n int p = 0;\n for (char c : ns().toCharArray())\n v[p++] = c - '0';\n for (int i = 0; i < 2 * n; ++i)\n for (int j = 0; j <= n; ++j) {\n if (j < n) {\n long a = dp[i][j] + pow[n - j - 1] * v[i];\n if (a > dp[i + 1][j + 1]) {\n dp[i + 1][j + 1] = a;\n pred[i + 1][j + 1] = pred[i][j] + \"H\";\n }\n }\n if (i - j < n && i - j >= 0) {\n long a = dp[i][j] + pow[n - (i - j) - 1] * v[i];\n if (a > dp[i + 1][j]) {\n dp[i + 1][j] = a;\n pred[i + 1][j] = pred[i][j] + \"M\";\n }\n\n }\n }\n out.println(pred[2 * n][n]);\n }\n\n public Solution() throws IOException {\n Locale.setDefault(Locale.US);\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n in.close();\n out.close();\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 new Solution();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "81b0c73fffb0bbd4a790da4cf7089d86", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\t\n\tpublic static void main(String[] args) {\n\t\t(new Thread(new Solution())).start();\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tBigInteger nextBigInteger() throws IOException {\n\t\treturn new BigInteger(nextToken());\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tString s = nextToken();\n\t\tlong[][] d = new long[n + 1][n + 1];\n\t\tint[][] r = new int[n + 1][n + 1];\n\t\tlong[] pw = new long[n + 1];\n\t\tpw[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 10;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tfor (int j = 0; j <= n; j++) {\n\t\t\t\tif (i > 0 && d[i][j] < d[i - 1][j] + (s.charAt(i + j - 1) - '0') * pw[n - i]) {\n\t\t\t\t\td[i][j] = d[i - 1][j] + (s.charAt(i + j - 1) - '0') * pw[n - i];\n\t\t\t\t\tr[i][j] = 1;\n\t\t\t\t}\n\t\t\t\tif (j > 0 && d[i][j] < d[i][j - 1] + (s.charAt(i + j - 1) - '0') * pw[n - j]) {\n\t\t\t\t\td[i][j] = d[i][j - 1] + (s.charAt(i + j - 1) - '0') * pw[n - j];\n\t\t\t\t\tr[i][j] = 2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tString ans = \"\";\n\t\tint i = n;\n\t\tint j = n;\n\t\twhile (i != 0 || j != 0) {\n\t\t\tif (r[i][j] == 1) {\n\t\t\t\tans = 'H' + ans;\n\t\t\t\ti--;\n\t\t\t} else {\n\t\t\t\tans = 'M' + ans;\n\t\t\t\tj--;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t \n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n//\t\t\tin = new BufferedReader(new FileReader(new File(\"input.txt\")));\n//\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tout.flush();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce6c04f3cb05cfdd8bcffa864995df2a", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\nimport com.google.common.base.Joiner;\n\n\npublic class E_TVGame {\n\n /**\n * 3:03\n */ \n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt(); sc.nextLine();\n String line = sc.nextLine();\n \n int[] nums = new int[n*2];\n for (int i = 0; i < n*2; i++) {\n nums[i] = Integer.parseInt(line.substring(i, i+1));\n }\n \n\n long[][] d = new long[n+1][n+1];\n d[0][0] = 0;\n \n boolean[][] ups = new boolean[n+1][n+1];\n \n for (int i = 0; i < n+1; i++) {\n for (int j = 0; j < n+1; j++) {\n if(i==0&&j==0) continue;\n int p = nums[n*2-(i+j)];\n boolean up = true;\n if(i>0) d[i][j] = Math.max(d[i-1][j]+p*pow10(i-1), d[i][j]);\n if(j>0){\n if(d[i][j-1]+p*pow10(j-1) > d[i][j]) up = false;\n d[i][j] = Math.max(d[i][j-1]+p*pow10(j-1), d[i][j]);\n }\n ups[i][j] = up;\n }\n }\n \n// for (int i = 0; i < n+1; i++) {\n// StringBuilder sb = new StringBuilder();\n// for (int j = 0; j < n+1; j++) {\n// sb.append(d[i][j]);\n// if(j < n) sb.append('\\t');\n// }\n// System.out.println(sb.toString());\n// }\n \n int curi = n, curj = n;\n String ret = \"\";\n for (int i = 0; i < n*2; i++) {\n if(curj == 0 || ups[curi][curj]){\n ret += 'H';\n curi--;\n }else{\n ret += 'M';\n curj--;\n }\n }\n\n System.out.println(ret);\n \n\n \n }\n \n private static long pow10(int a){\n if(a == 0) return 1;\n return 10L * pow10(a-1);\n \n }\n\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8fdd9d48d9c5701833309656d1fc6f9b", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n static boolean f = false, flag = false;\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String a = \"\", c = \"\";\n\n String s = scan.next();\n char[] sArray = s.toCharArray();\n if (sArray.length <= 100) {\n\n\n if (sArray.length % 2 != 0) {\n for (int i = sArray.length / 2; i < sArray.length; i++) {\n for (int y = 0; y < i + 1; y++) {\n a = a + sArray[y];\n }\n for (int y = sArray.length - i - 1; y < sArray.length; y++) {\n c = c + sArray[y];\n }\n if (a.equals(c)) {\n f = true;\n break;\n }\n a = \"\";\n c = \"\";\n }\n }\n if (sArray.length % 2 == 0) {\n for (int i = sArray.length / 2; i < sArray.length - 1; i++) {\n for (int y = 0; y < i; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n if (a.equals(c)) {\n f = true;\n break;\n }\n a = \"\";\n c = \"\";\n\n }\n }\n }\n\n {\n String m = c;\n c = \"\";\n a = \"\";\n for (int y = sArray.length / 2; y < sArray.length; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n\n }\n if (a.equals(c)) {\n flag = true;\n\n }\n if ((!f && !flag) || (!f && flag)) {\n System.out.print(\"NO\");\n }\n if ((f) || (f && !flag)) {\n System.out.print(\"YES\\n\" + m);\n\n }\n }\n\n }\n }\n}\n\n\n/*\n }*/", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f3ad0b42d1055adb00b352812e1941ea", "src_uid": "bfa78f72af4875f670f7adc5ed127033", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n static boolean f = false;\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String a = \"\", c = \"\";\n\n String s = scan.next();\n char[] sArray = s.toCharArray();\n if (sArray.length < 100) {\n\n\n if (sArray.length % 2 != 0) {\n for (int i = sArray.length / 2 + 1; i < sArray.length; i++) {\n for (int y = 0; y < i; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n }\n if (a.equals(c)) {\n f = true;\n System.out.print(\"YES\\n\" + c);\n break;\n }\n }\n }\n if (sArray.length % 2 == 0) {\n for (int i = sArray.length / 2; i < sArray.length; i++) {\n for (int y = 0; y < i; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n }\n if (a.equals(c)) {\n f = true;\n System.out.print(\"YES\\n\" + c);\n break;\n }\n }\n\n }\n if (!f) {\n c = \"\";\n a = \"\";\n for (int y = sArray.length / 2; y < sArray.length; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n\n }\n if (a.equals(c)) {\n f = true;\n System.out.print(\"NO\");\n }\n\n System.out.print(\"NO\");\n }\n }\n }\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7e5508430523b6b2c19f3bb511352e3", "src_uid": "bfa78f72af4875f670f7adc5ed127033", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n static boolean f = false,flag = false;\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String a = \"\", c = \"\";\n\n String s = scan.next();\n char[] sArray = s.toCharArray();\n if (sArray.length <= 100) {\n\n\n if (sArray.length % 2 != 0) {\n for (int i = sArray.length / 2 ; i < sArray.length; i++) {\n for (int y = 0; y < i + 1; y++) {\n a = a + sArray[y];\n }\n for (int y = sArray.length - i - 1; y < sArray.length ;y++){\n c = c + sArray[y];\n }\n if (a.equals(c)) {\n f = true;\n break;\n }\n a =\"\";\n c = \"\";\n }\n }\n if (sArray.length % 2 == 0) {\n for (int i = sArray.length / 2 ; i < sArray.length - 1 ; i++) {\n for (int y = 0; y < i + 1; y++) {\n a = a + sArray[y];\n }\n for (int y = sArray.length - i - 1; y < sArray.length ;y++){\n c = c + sArray[y];\n }\n if (a.equals(c)) {\n f = true;break;\n }\n a = \"\";\n c = \"\";\n\n }\n\n }\n\n {\n String m = c;\n c = \"\";\n a = \"\";\n for (int y = sArray.length / 2; y < sArray.length; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n\n }\n if (a.equals(c)) {\n flag = true;\n\n }\n if ((!f && !flag) || (!f && flag)){\n System.out.print(\"NO\");\n }\n if ((f) || (f && !flag)){\n System.out.print(\"YES\\n\" + m);\n\n }\n }\n }\n }\n }\n\n/* for (int y = 0; y < i; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n }*/", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1eda51188971bcc7f1054c02891468a7", "src_uid": "bfa78f72af4875f670f7adc5ed127033", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n static boolean f = false,flag = false;\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String a = \"\", c = \"\";\n\n String s = scan.next();\n char[] sArray = s.toCharArray();\n if (sArray.length < 100) {\n\n\n if (sArray.length % 2 != 0) {\n for (int i = sArray.length / 2 + 1; i < sArray.length; i++) {\n for (int y = 0; y < i; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n }\n if (a.equals(c)) {\n f = true;\n break;\n }\n }\n }\n if (sArray.length % 2 == 0) {\n for (int i = sArray.length / 2 ; i < sArray.length; i++) {\n for (int y = 0; y < i; y++) {\n a = sArray[sArray.length - 1 - y] + a;\n c = c + sArray[y];\n\n }\n if (a.equals(c)) {\n f = true;break;\n }\n\n\n }\n\n }\n\n {\n String m = c;\n c = \"\";\n a = \"\";\n for (int y = sArray.length / 2; y < sArray.length; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n\n }\n if (a.equals(c)) {\n flag = true;\n\n }\n if ((!f && !flag) || (!f && flag)){\n System.out.print(\"NO\");\n }\n if ((f) || (f && !flag)){\n System.out.print(\"YES\\n\" + m);\n\n }\n }\n }\n }\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0990ec6aca9b1b5a047eb34e7e189fbe", "src_uid": "bfa78f72af4875f670f7adc5ed127033", "difficulty": 1500.0} {"lang": "Java 17", "source_code": "\r\nimport java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\nimport java.math.BigInteger;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class Round803G {\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\tRound803G sol = new Round803G();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = false;\r\n\t\t\r\n\t\tinitIO(isFileIO);\r\n\t\t\r\n\t\t// test();\r\n\t\r\n\t\tint t = hasMultipleTests? in.nextInt() : 1;\r\n\t \r\n\t for (int i = 1; i <= t; ++i) {\r\n\t \tString s = in.next();\r\n\t \t\r\n\t \tif(isDebug){\r\n\t\t \tout.printf(\"Test %d\\n\", i);\r\n\t \t}\r\n\t \t\r\n\t\t\tlong[] ans = solve(s);\r\n\t\t\tout.printlnAns(ans);\r\n\t\t\t\r\n\t\t\tif(isDebug)\r\n\t\t\t\tout.flush();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tprivate void test() {\r\n\t\t\r\n\t\tlong mod = 1<<32;\r\n\t\tlong temp;\r\n\t\tlong temp2;\r\n\t\t\r\n\t\ttemp = divide(9, 3); // x^3+1, x+1\r\n\t\ttemp2 = multiply(3, temp, mod); // (x^2+x+1)(x+1) = x^3+1\r\n\t\ttemp = divide(26, 25); // x^4 + x^3 + x, x^4 + x^3 + 1\r\n\t\ttemp2 = multiply(25, temp, mod);\r\n\t\ttemp = divide(52, 17); // x^5 + x^4 + x^2, x^4 + 1\r\n\t\ttemp2 = multiply(17, temp, mod);\r\n\t\t\r\n\t\t// https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example_2\r\n\t\tmod = (1<<8) + (1<<4) + (1<<3) + (1<<1) + 1;\r\n\t\tlong a = (1<<6) + (1<<4) + (1<<1) + 1;\r\n\t\t\r\n\t\tlong[] res = extendedEuclid(a, mod, mod);\r\n\t\tlong ainv = res[0];\r\n\t\tif(Long.highestOneBit(ainv) == Long.highestOneBit(mod))\r\n\t\t\tainv ^= mod;\r\n\t\t\r\n\t\ttemp = multiply(a, ainv, mod); // checked\r\n\t\t\r\n\t}\r\n\r\n\tprivate int[] bruteForce(String s) {\r\n\t\tBigInteger n = new BigInteger(reverse(s), 2);\r\n\t\tBigInteger base = new BigInteger(reverse(s), 2);\r\n\t\t\r\n\t\tint p = n.getLowestSetBit();\r\n\t\tif(p == -1) // or |t| > 10^100\r\n\t\t\treturn new int[] {-1};\r\n\t\t\r\n\t\tn = n.flipBit(p);\r\n\t\tif(n.equals(BigInteger.valueOf(0)))\r\n\t\t\treturn new int[] {p+1, p+2};\r\n\t\t\r\n\t\twhile(n.getLowestSetBit() != n.bitLength()-1) {\r\n\t\t\tn = n.xor(base.shiftLeft(n.getLowestSetBit()-p));\r\n\t\t}\r\n\t\tint q = n.getLowestSetBit();\r\n\t\t\r\n\t\treturn new int[] {p+1, q+1};\r\n\t}\r\n\t\r\n\tString reverse(String s) {\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\tfor(int i=s.length()-1; i>=0; i--)\r\n\t\t\tsb.append(s.charAt(i));\r\n\t\treturn sb.toString();\r\n\t}\r\n\r\n\tprivate long[] solve(String s) {\r\n\t\t// first xor(s, t[0..n-1])\r\n\t\t// if there are more than 2 setBits,\r\n\t\t// align s so that first setBit of s is aligned with second setBig of t\r\n\t\t// then make xor\r\n\t\t\r\n\t\t// xor is + over Z2\r\n\t\t\r\n\t\t// s(x) = s as coefficient of polynomial over Z2\r\n\t\t// x^p + x^q\r\n\t\t// = x^p (1+x^(q-p))\r\n\t\t// = s(x) (1+P(x))\r\n\t\t// = (x^p + s'(x))(1+P(x))\r\n\t\t// = x^p + s'(x) + s(x)P(x)\r\n\t\t\r\n\t\t// p is known, find minimum q s.t.\r\n\t\t// s(x) | (x^p + x^q)\r\n\r\n\t\t// x^p(1+x^t) = s(x)P(x)\r\n\t\t// s(x) = x^p*s'(x)\r\n\t\t// 1+x^t = s'(x)P(x)\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t// remove leading zeros and trailing zeros in s then reverse it\r\n\t\t// wlog s(x) = 1 + ..... + x^(|s|-1), |s| >= 2\r\n\t\t// want R(x) = 1\r\n\t\t// x^t = s(x)P(x)+R(x) (deg R(x) < deg s(x))\r\n\r\n\t\t// suppose we have R_t(x) = x^t % s(x)\r\n\t\t// then R_(t+1)(x) = x^(t+1) % s(x) = xR_t(x) % s(x) \r\n\t\t// there are 2^(|s|-1) different R(x) so enumerating all R(x) takes O(|s|*2^|s|)\r\n\t\t// \r\n\t\t\r\n\t\t// to put it differently,\r\n\t\t// we are asking for the order of x mod s(x)\r\n\t\t// i.e., x^t = 1 mod s(x)\r\n\t\t\r\n\t\t// this particular meet-in-the-middle technique is called the baby-step giant-step!\r\n\t\t// let m = 2^(|s|/2)\r\n\t\t// we precompute all x^j up to j <= m\r\n\t\t// if x^j = 1 then we are already good\r\n\t\t// otherwise, x^j's are all distinct\r\n\t\t\r\n\t\t// then for i = 1 to m\r\n\t\t// x^(im+j) = 1 -> x^j = (x^-m)^i\r\n\t\t// how to find x^-m?\r\n\t\t// extended euclid\r\n\t\t\r\n\t\tint numLeadingZeros;\r\n\t\tfor(numLeadingZeros=0; numLeadingZeros=numLeadingZeros; i--) {\r\n\t\t\tmod <<= 1;\r\n\t\t\tmod += s.charAt(i)-'0';\r\n\t\t}\r\n\t\t\r\n\t\tif(mod == 1)\r\n\t\t\treturn new long[] {numLeadingZeros+1, numLeadingZeros+2};\r\n\t\t\r\n\t\tfinal int N = 63-Long.numberOfLeadingZeros(mod);\r\n\t\tfinal int M = N/2;\r\n\t\tHashMap dp = new HashMap<>();\r\n\t\t\r\n\t\tlong a = 1;\r\n\t\tdp.put(a, 0L);\r\n\t\tfor(long j=1; j<(1L< 0) {\r\n\t\t\tlong q = divide(a1, a2);\r\n\t\t\tlong temp = a2;\r\n\t\t\ta2 = a1 ^ multiply(q, a2, mod);\r\n\t\t\tif(Long.highestOneBit(a2) == Long.highestOneBit(mod))\r\n\t\t\t\ta2 ^= mod;\r\n\t\t\ta1 = temp;\r\n\t\t\ttemp = x2;\r\n\t\t\tx2 = x1 ^ multiply(q, x2, mod);\r\n\t\t\tif(Long.highestOneBit(x2) == Long.highestOneBit(mod))\r\n\t\t\t\tx2 ^= mod;\r\n\t\t\tx1 = temp;\r\n\t\t\ttemp = y2;\r\n\t\t\ty2 = y1 ^ multiply(q, y2, mod);\r\n\t\t\tif(Long.highestOneBit(y2) == Long.highestOneBit(mod))\r\n\t\t\t\ty2 ^= mod;\r\n\t\t\ty1 = temp;\r\n\t\t}\r\n\t\treturn new long[] {x1, y1, a1};\r\n\t}\r\n\t\r\n\tlong divide(long a, long b) {\r\n\t\tlong res = 0;\r\n\t\tint base = 63-Long.numberOfLeadingZeros(b);\r\n \t\tfor(int i=63-Long.numberOfLeadingZeros(a); i>=base; i--) {\r\n\t\t\tif((a & (1< 0) {\r\n\t\t\t\tres += 1<<(i-base);\r\n\t\t\t\ta ^= b<<(i-base);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\t\r\n\tlong multiplyX(long a, long mod) {\r\n\t\ta <<= 1;\r\n\t\tif(Long.highestOneBit(a) == Long.highestOneBit(mod))\r\n\t\t\ta ^= mod;\r\n\t\treturn a;\r\n\t}\r\n\t\r\n\tlong pow(long a, long k, long mod) {\r\n\t\tlong res = 1;\r\n\t\tlong base = a;\r\n\t\twhile(k > 0) {\r\n\t\t\tif((k & 1) > 0)\r\n\t\t\t\tres = multiply(res, base, mod);\r\n\t\t\tbase = multiply(base, base, mod);\r\n\t\t\tk >>= 1;\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\r\n\tlong multiply(long a, long b, long mod) {\r\n\t\t// a0 + a1x + a2x^2 + ... + akx^k\r\n\t\t// = a0 + x(a1 + a2x + ....)\r\n\t\t// = a0 + x(a1 + x (a2 + .....)\r\n\t\tlong res = 0;\r\n\t\tfor(int i=63-Long.numberOfLeadingZeros(a); i>=0; i--) {\r\n\t\t\tres <<= 1;\r\n\t\t\tif((a & (1< 0)\r\n\t\t\t\tres ^= b;\r\n\t\t\tif(Long.highestOneBit(res) == Long.highestOneBit(mod))\r\n\t\t\t\tres ^= mod;\r\n\t\t}\r\n\t\t// x^2 = 4\r\n\t\t// x^3 = x^2+x+1 = 7\r\n\t\t// x(x^2+x+1) = x^3+x^2+x = 1\r\n\t\treturn res;\r\n\t}\r\n\t\r\n\tpublic static class MyScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\t// 32768?\r\n\t\tpublic MyScanner(InputStream is, int bufferSize) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bufferSize);\r\n\t\t}\r\n\t\t\r\n\t\tpublic MyScanner(InputStream is) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\r\n\t\t}\r\n\r\n\t\tpublic void close() {\r\n\t\t\ttry {\r\n\t\t\t\tbr.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tString next() {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine(){\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextTreeEdges(int n, int offset){\r\n\t\t\tint[][] e = new int[n-1][2];\r\n\t\t\tfor(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0875dfdda16fc325425de03bf5a7fb06", "src_uid": "6bf798edef30db7d0ce2130e40084e6b", "difficulty": 2900.0} {"lang": "Java 17", "source_code": "\r\nimport java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\nimport java.math.BigInteger;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class Round803G {\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\tRound803G sol = new Round803G();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = false;\r\n\t\t\r\n\t\tinitIO(isFileIO);\r\n\t\t\r\n\t\t// test();\r\n\t\r\n\t\tint t = hasMultipleTests? in.nextInt() : 1;\r\n\t \r\n\t for (int i = 1; i <= t; ++i) {\r\n\t \tString s = in.next();\r\n\t \t\r\n\t \tif(isDebug){\r\n\t\t \tout.printf(\"Test %d\\n\", i);\r\n\t \t}\r\n\t \t\r\n\t\t\tlong[] ans = solve(s);\r\n\t\t\tout.printlnAns(ans);\r\n\t\t\t\r\n\t\t\tif(isDebug)\r\n\t\t\t\tout.flush();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tprivate void test() {\r\n\t\t\r\n\t\tlong mod = 1L<<32;\r\n\t\tlong temp;\r\n\t\tlong temp2;\r\n\t\t\r\n\t\t\r\n\t\ttemp2 = multiply((1L<<31)-23, 1, mod);\r\n\t\t\r\n\t\tmod = 34359738337L;\r\n\t\t// = 9461547882L\r\n\t\ttemp2 = multiply(2, 1, mod);\r\n\t\ttemp2 = multiply(1000, 1, mod);\r\n\t\ttemp2 = multiply((1L<<31)-23, 1, mod);\r\n\t\ttemp2 = multiply(946154788L, 1, mod);\r\n\t\ttemp2 = multiply(3336154788L, 1, mod);\r\n\t\ttemp2 = multiply(9461547882L, 1, mod);\r\n\t\t\r\n\t\ttemp = divide(9, 3); // x^3+1, x+1\r\n\t\ttemp2 = multiply(3, temp, mod); // (x^2+x+1)(x+1) = x^3+1\r\n\t\ttemp = divide(26, 25); // x^4 + x^3 + x, x^4 + x^3 + 1\r\n\t\ttemp2 = multiply(25, temp, mod);\r\n\t\ttemp = divide(52, 17); // x^5 + x^4 + x^2, x^4 + 1\r\n\t\ttemp2 = multiply(17, temp, mod);\r\n\t\t\r\n\t\t// https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example_2\r\n\t\tmod = (1<<8) + (1<<4) + (1<<3) + (1<<1) + 1;\r\n\t\tlong a = (1<<6) + (1<<4) + (1<<1) + 1;\r\n\t\t\r\n\t\tlong[] res = extendedEuclid(a, mod, mod);\r\n\t\tlong ainv = res[0];\r\n\t\tif(Long.highestOneBit(ainv) == Long.highestOneBit(mod))\r\n\t\t\tainv ^= mod;\r\n\t\t\r\n\t\ttemp = multiply(a, ainv, mod); // checked\r\n\t\t\r\n\t}\r\n\r\n\tprivate int[] bruteForce(String s) {\r\n\t\tBigInteger n = new BigInteger(reverse(s), 2);\r\n\t\tBigInteger base = new BigInteger(reverse(s), 2);\r\n\t\t\r\n\t\tint p = n.getLowestSetBit();\r\n\t\tif(p == -1) // or |t| > 10^100\r\n\t\t\treturn new int[] {-1};\r\n\t\t\r\n\t\tn = n.flipBit(p);\r\n\t\tif(n.equals(BigInteger.valueOf(0)))\r\n\t\t\treturn new int[] {p+1, p+2};\r\n\t\t\r\n\t\twhile(n.getLowestSetBit() != n.bitLength()-1) {\r\n\t\t\tn = n.xor(base.shiftLeft(n.getLowestSetBit()-p));\r\n\t\t}\r\n\t\tint q = n.getLowestSetBit();\r\n\t\t\r\n\t\treturn new int[] {p+1, q+1};\r\n\t}\r\n\t\r\n\tString reverse(String s) {\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\tfor(int i=s.length()-1; i>=0; i--)\r\n\t\t\tsb.append(s.charAt(i));\r\n\t\treturn sb.toString();\r\n\t}\r\n\r\n\tprivate long[] solve(String s) {\r\n\t\t// first xor(s, t[0..n-1])\r\n\t\t// if there are more than 2 setBits,\r\n\t\t// align s so that first setBit of s is aligned with second setBig of t\r\n\t\t// then make xor\r\n\t\t\r\n\t\t// xor is + over Z2\r\n\t\t\r\n\t\t// s(x) = s as coefficient of polynomial over Z2\r\n\t\t// x^p + x^q\r\n\t\t// = x^p (1+x^(q-p))\r\n\t\t// = s(x) (1+P(x))\r\n\t\t// = (x^p + s'(x))(1+P(x))\r\n\t\t// = x^p + s'(x) + s(x)P(x)\r\n\t\t\r\n\t\t// p is known, find minimum q s.t.\r\n\t\t// s(x) | (x^p + x^q)\r\n\r\n\t\t// x^p(1+x^t) = s(x)P(x)\r\n\t\t// s(x) = x^p*s'(x)\r\n\t\t// 1+x^t = s'(x)P(x)\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t// remove leading zeros and trailing zeros in s then reverse it\r\n\t\t// wlog s(x) = 1 + ..... + x^(|s|-1), |s| >= 2\r\n\t\t// want R(x) = 1\r\n\t\t// x^t = s(x)P(x)+R(x) (deg R(x) < deg s(x))\r\n\r\n\t\t// suppose we have R_t(x) = x^t % s(x)\r\n\t\t// then R_(t+1)(x) = x^(t+1) % s(x) = xR_t(x) % s(x) \r\n\t\t// there are 2^(|s|-1) different R(x) so enumerating all R(x) takes O(|s|*2^|s|)\r\n\t\t// \r\n\t\t\r\n\t\t// to put it differently,\r\n\t\t// we are asking for the order of x mod s(x)\r\n\t\t// i.e., x^t = 1 mod s(x)\r\n\t\t\r\n\t\t// this particular meet-in-the-middle technique is called the baby-step giant-step!\r\n\t\t// let m = 2^(|s|/2)\r\n\t\t// we precompute all x^j up to j <= m\r\n\t\t// if x^j = 1 then we are already good\r\n\t\t// otherwise, x^j's are all distinct\r\n\t\t\r\n\t\t// then for i = 1 to m\r\n\t\t// x^(im+j) = 1 -> x^j = (x^-m)^i\r\n\t\t// how to find x^-m?\r\n\t\t// extended euclid\r\n\t\t\r\n\t\tint numLeadingZeros;\r\n\t\tfor(numLeadingZeros=0; numLeadingZeros=numLeadingZeros; i--) {\r\n\t\t\tmod <<= 1;\r\n\t\t\tmod += s.charAt(i)-'0';\r\n\t\t}\r\n\t\t\r\n\t\tif(mod == 1)\r\n\t\t\treturn new long[] {numLeadingZeros+1, numLeadingZeros+2};\r\n\t\t\r\n\t\tfinal int N = 63-Long.numberOfLeadingZeros(mod);\r\n\t\tfinal int M = N/2;\r\n\t\tHashMap dp = new HashMap<>();\r\n\t\t\r\n\t\tlong a = 1;\r\n\t\tdp.put(a, 0L);\r\n\t\tfor(long j=1; j<(1L< 0) {\r\n\t\t\tlong q = divide(a1, a2);\r\n\t\t\tlong temp = a2;\r\n\t\t\ta2 = a1 ^ multiply(q, a2, mod);\r\n\t\t\tif(Long.highestOneBit(a2) == Long.highestOneBit(mod))\r\n\t\t\t\ta2 ^= mod;\r\n\t\t\ta1 = temp;\r\n\t\t\ttemp = x2;\r\n\t\t\tx2 = x1 ^ multiply(q, x2, mod);\r\n\t\t\tif(Long.highestOneBit(x2) == Long.highestOneBit(mod))\r\n\t\t\t\tx2 ^= mod;\r\n\t\t\tx1 = temp;\r\n\t\t\ttemp = y2;\r\n\t\t\ty2 = y1 ^ multiply(q, y2, mod);\r\n\t\t\tif(Long.highestOneBit(y2) == Long.highestOneBit(mod))\r\n\t\t\t\ty2 ^= mod;\r\n\t\t\ty1 = temp;\r\n\t\t}\r\n\t\treturn new long[] {x1, y1, a1};\r\n\t}\r\n\t\r\n\tlong divide(long a, long b) {\r\n\t\tlong res = 0;\r\n\t\tint base = 63-Long.numberOfLeadingZeros(b);\r\n \t\tfor(int i=63-Long.numberOfLeadingZeros(a); i>=base; i--) {\r\n\t\t\tif((a & (1L< 0) {\r\n\t\t\t\tres += 1L<<(i-base);\r\n\t\t\t\ta ^= b<<(i-base);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\t\r\n\tlong multiplyX(long a, long mod) {\r\n\t\ta <<= 1;\r\n\t\tif(Long.highestOneBit(a) == Long.highestOneBit(mod))\r\n\t\t\ta ^= mod;\r\n\t\treturn a;\r\n\t}\r\n\t\r\n\tlong pow(long a, long k, long mod) {\r\n\t\tlong res = 1;\r\n\t\tlong base = a;\r\n\t\twhile(k > 0) {\r\n\t\t\tif((k & 1) > 0)\r\n\t\t\t\tres = multiply(res, base, mod);\r\n\t\t\tbase = multiply(base, base, mod);\r\n\t\t\tk >>= 1;\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\r\n\tlong multiply(long a, long b, long mod) {\r\n\t\t// a0 + a1x + a2x^2 + ... + akx^k\r\n\t\t// = a0 + x(a1 + a2x + ....)\r\n\t\t// = a0 + x(a1 + x (a2 + .....)\r\n\t\tlong res = 0;\r\n\t\tfor(int i=63-Long.numberOfLeadingZeros(a); i>=0; i--) {\r\n\t\t\tres <<= 1;\r\n\t\t\tif((a & (1L< 0)\r\n\t\t\t\tres ^= b;\r\n\t\t\tif(Long.highestOneBit(res) == Long.highestOneBit(mod))\r\n\t\t\t\tres ^= mod;\r\n\t\t}\r\n\t\t// x^2 = 4\r\n\t\t// x^3 = x^2+x+1 = 7\r\n\t\t// x(x^2+x+1) = x^3+x^2+x = 1\r\n\t\treturn res;\r\n\t}\r\n\t\r\n\tpublic static class MyScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\t// 32768?\r\n\t\tpublic MyScanner(InputStream is, int bufferSize) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bufferSize);\r\n\t\t}\r\n\t\t\r\n\t\tpublic MyScanner(InputStream is) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\r\n\t\t}\r\n\r\n\t\tpublic void close() {\r\n\t\t\ttry {\r\n\t\t\t\tbr.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tString next() {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine(){\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextTreeEdges(int n, int offset){\r\n\t\t\tint[][] e = new int[n-1][2];\r\n\t\t\tfor(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70f370ad259f27dab58c9bd3e6b18c5b", "src_uid": "6bf798edef30db7d0ce2130e40084e6b", "difficulty": 2900.0} {"lang": "Java 11", "source_code": "//package com.example.practice.codeforces.sc2900.prac;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class Solution1 {\n public static void main (String [] args) throws IOException {\n // Use BufferedReader rather than RandomAccessFile; it's much faster\n final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n // input file name goes above\n //StringTokenizer st = new StringTokenizer(input.readLine());\n //int n = Integer.parseInt(st.nextToken()), a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());\n long[] res = calc(input.readLine());\n if (res==null){\n out.println(-1);\n }else {\n printArray(res, out);\n }\n out.close(); // close the output file\n }\n\n private static long[] calc(final String s) {\n long px = 0, v = 1;\n int p = s.length()-1, tem = 0, highest = 0, first = 0, c = 0;\n while (p>=0 && s.charAt(p)=='0'){\n p--;\n }\n if (p<0)return null;\n while (p>=0){\n if (s.charAt(p)=='1'){\n px |= 1L << tem;\n highest = tem;\n first = p;\n c++;\n }\n tem++;\n p--;\n }\n if (c==1)return new long[]{first+1, first+2};\n final long m = (long) Math.sqrt(1L< map = new HashMap<>();\n for (int i=1;i<=m;++i){\n v = v << 1;\n if ((v & (1L< 0) {\n v2 = v2 << 1;\n if ((v2 & (1L< len)break;\n for (int i=0;i len)break;\n for (int i=0;i al = new ArrayList<>();\n while (st.hasMoreTokens()){\n al.add(Long.parseLong(st.nextToken()));\n }\n long[] kk = new long[al.size()];\n for (int j=0;j al = new ArrayList<>();\n while (st.hasMoreTokens()){\n al.add(Integer.parseInt(st.nextToken()));\n }\n int[] kk = new int[al.size()];\n for (int j=0;j> 1;\n val1 = val2 = d;\n if (st> 1;\n if (st==en){\n val1 = val2 = ns[st];\n }else {\n left = new SegTree(l, mid, ns);\n right = new SegTree(mid+1, r, ns);\n val1 = Math.min(left.val1, right.val1);\n val2 = Math.max(left.val2, right.val2);\n }\n }\n\n void update(int idx, int v){\n if (st==en){\n val1 = val2 = v;\n }else {\n if (idx <= mid){\n left.update(idx, v);\n }else {\n right.update(idx, v);\n }\n val1 = Math.min(left.val1, right.val1);\n val2 = Math.max(left.val2, right.val2);\n }\n }\n\n int getMin(int l, int r){\n if (st==en || (l==st && r==en))return val1;\n if (r<=mid){\n return left.getMin(l, r);\n }\n if (l>mid){\n return right.getMin(l, r);\n }\n return Math.min(left.getMin(l, mid), right.getMin(mid+1, r));\n }\n\n int getMax(int l, int r){\n if (st==en || (l==st && r==en))return val2;\n if (r<=mid){\n return left.getMax(l, r);\n }\n if (l>mid){\n return right.getMax(l, r);\n }\n return Math.max(left.getMax(l, mid), right.getMax(mid+1, r));\n }\n }\n\n static class SparseTable{\n int[][] minTable;\n int[][] maxTable;\n int[] log2;\n int n;\n public SparseTable(final int[] ns){\n n = ns.length;\n int m = 0, pre = 0;\n while (1< adj[];\n\tstatic ArrayList candidates;\n\tstatic int[] sz;\n\tstatic final boolean debug = false;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tint N = in.nextInt();\n\t\tM = in.nextInt();\n\t\t\n\t\tArrayDeque es[] = new ArrayDeque[N];\n\t\tfor(int i = 0; i < N; i++) es[i] = new ArrayDeque();\n\t\tfor(int i = 0; i < N-1; i++) {\n\t\t\tint u = in.nextInt()-1;\n\t\t\tint v = in.nextInt()-1;\n\t\t\tlong m = in.nextLong();\n\t\t\tlong b = in.nextLong();\n\t\t\tEdge e = new Edge(u,v,m,b);\n\t\t\tes[u].add(e);\n\t\t\tes[v].add(e);\n\t\t}\n\t\t\n\t\tcurN = N;\n\t\tadj = new ArrayList[maxN];\n\t\tfor(int i = 0; i < maxN; i++) adj[i] = new ArrayList();\n\t\tfixTree(0, -1, es);\n\t\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"N= \"+ curN);\n\t\t\tfor(int i = 0; i < curN; i++) {\n\t\t\t\tSystem.out.println(i+\" \"+adj[i].toString());\n\t\t\t}\n\t\t}\n\t\t\n\t\tcandidates = new ArrayList<>();\n\t\tsz = new int[curN];\n\t\tsolve(0);\n\t\t\n\t\tCHT cht = new CHT(1);\n\t\tfor(VecL[] cs : candidates) {\n\t\t\tfor(VecL v : cs) {\n\t\t\t\tcht.add(v.x, v.y);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < M; i++) out.print(cht.query(i)+\" \");\n\t\tout.println();\n\t\tout.close();\n\t}\n\t\n\tstatic void solve(int node) {\n\t\tszdfs(node, -1);\n\t\tif(sz[node] == 1) return; // base case, no edges\n\t\tEdge e = getEdgetroid(node, -1, sz[node], null);\n\t\te.blocked = true;\n\t\t\n\t\t//solve on this guy\n\t\tArrayList left = new ArrayList();\n\t\tArrayList right = new ArrayList();\n\t\tmakeLines(e.u, -1, e.m, e.b, left);\n\t\tmakeLines(e.v, -1, 0, 0, right);\n\t\t\n\t\tVecL[] minskowski = minkowskiSum(getHull(removeDupes(left)), getHull(removeDupes(right)));\n\t\tcandidates.add(minskowski);\n\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"Decomp on: \"+e);\n\t\t\tSystem.out.println(\" Left: \"+left.toString());\n\t\t\tSystem.out.println(\" Right: \"+right.toString());\n\t\t\tSystem.out.println(\" Minskowski: \"+Arrays.toString(minskowski));\n\t\t}\n\t\t\n\t\t//now solve on the remaining stuff\n\t\tsolve(e.u);\n\t\tsolve(e.v);\n\t}\n\t\n\tstatic void makeLines(int node, int p, long curM, long curB, ArrayList vecs) {\n\t\tint to = 0;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e.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.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.blocked || e.to(node) == p) continue;\n\t\t\tszdfs(e.to(node), node);\n\t\t\tsz[node] += sz[e.to(node)];\n\t\t}\n\t}\n\t\n\tstatic void fixTree(int node, int p, ArrayDeque es[]) {\n\t\tint cur = node;\n\t\twhile(!es[node].isEmpty()) {\n\t\t\tif(es[node].size() <= 2) {\n\t\t\t\twhile(!es[node].isEmpty()) {\n\t\t\t\t\tEdge e = es[node].poll();\n\t\t\t\t\te.swap(node, cur);\n\t\t\t\t\tadj[cur].add(e);\n\t\t\t\t\tadj[e.to(cur)].add(e);\n\t\t\t\t\tes[e.to(cur)].remove(e);\n\t\t\t\t\tfixTree(e.to(cur), 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\tadj[cur].add(e);\n\t\t\t\tadj[e.to(cur)].add(e);\n\t\t\t\tes[e.to(cur)].remove(e);\n\t\t\t\tfixTree(e.to(cur), 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\tadj[cur].add(filler);\n\t\t\t\tadj[next].add(filler);\n\t\t\t\tcur = next;\n\t\t\t}\n\t\t}\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\twhile(rId < n+m) {\n\t\t\tSegL seg, seg2 = null;\n\t\t\tif(better(ni,mi,s1,s2)) {\n\t\t\t\tseg = s1[ni]; if(rId == 0) seg2 = s2[mi];\n\t\t\t\tni = (ni+1)%n;\n\t\t\t\tif(ni == nst) ni = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tseg = s2[mi]; if(rId == 0) seg2 = s1[ni];\n\t\t\t\tmi = (mi+1)%m;\n\t\t\t\tif(mi == mst) mi = -1;\n\t\t\t}\n\t\t\tif(rId == 0) hull[rId++] = seg.from.add(seg2.from);\n\t\t\thull[rId] = hull[rId-1].add(seg.dir);\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 points) {\n\t\tHashSet set=new HashSet<>();\n\t\tfor (VecL v:points)\n\t\t\tset.add(v);\n\t\tint counter=0;\n\t\tVecL res[] = new VecL[set.size()];\n\t\tfor (VecL v:set) res[counter++]=v;\n\t\treturn res;\n\t}\n\t// returns the hull in CCW order\n\tpublic static VecL[] getHull(VecL[] points) {\n\t\tpoints=points.clone();\n\t\tArrays.sort(points);\n\t\tif (points.length<3)\n\t\t\treturn points;\n\t\tint n=points.length, j=2, k=2;\n\t\tVecL[] lo=new VecL[n], up=new VecL[n];\n\t\tlo[0]=points[0];\n\t\tlo[1]=points[1];\n\t\tfor (int i=2; i1&&!right(lo[j-2], lo[j-1], p)) j--;\n\t\t\tlo[j++]=p;\n\t\t}\n\t\tup[0]=points[n-1];\n\t\tup[1]=points[n-2];\n\t\tfor (int i=n-3; i>=0; i--) {\n\t\t\tVecL p=points[i];\n\t\t\twhile (k>1&&!right(up[k-2], up[k-1], p)) k--;\n\t\t\tup[k++]=p;\n\t\t}\n\n\t\tVecL[] res=new VecL[j+k-2];\n\t\tfor (int i=0; ib->c are in the right order\n\tstatic boolean right(VecL a, VecL b, VecL c) {\n\t\treturn b.sub(a).cross(c.sub(a))>0;\n\t}\n\t\n\tstatic class VecL implements Comparable{\n\t\tlong x,y;\n\t\tpublic VecL(long xx, long yy) {\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t}\n\t\tpublic VecL add(VecL o) { return new VecL(x+o.x, y+o.y);}\n\t\tpublic VecL sub(VecL o) { return new VecL(x-o.x, y-o.y);}\n\t\tpublic long cross(VecL o) { return x*o.y - y*o.x;}\n\t\tpublic long dot(VecL o) { return x*o.x + y*o.y;}\n\t\tpublic int quadrant() {\n\t\t\tif (x==0||y==0)\n\t\t\t\tif (y==0)\n\t\t\t\t\tif (x>=0)\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 3;\n\t\t\t\telse\n\t\t\t\t\tif (y>=0)\n\t\t\t\t\t\treturn 2;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 4;\n\t\t\tif (x>0)\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 1;\n\t\t\t\telse\n\t\t\t\t\treturn 4;\n\t\t\telse\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 2;\n\t\t\t\telse\n\t\t\t\t\treturn 3;\n\t\t}\n\t\t\n\t\tpublic int radialCompare(VecL o) {\n\t\t\tif (quadrant()==o.quadrant())\n\t\t\t\treturn -Long.signum(cross(o));\n\t\t\treturn Integer.compare(quadrant(), o.quadrant());\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(VecL o) {\n\t\t\tif(x!=o.x) return Long.compare(x, o.x);\n\t\t\treturn Long.compare(y, o.y);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+x+\",\"+y+\")\";\n\t\t}\n\t\tpublic int hashCode() {\n\t\t\treturn Long.hashCode(x<<13^(y*57));\n\t\t}\n\t\t\n\t\tpublic boolean equals(Object oo) {\n\t\t\tVecL o=(VecL)oo;\n\t\t\treturn x==o.x&&y==o.y;\n\t\t}\t\t\n\t}\n\t\n\tstatic class SegL{\n\t\tVecL from, to, dir;\n\t\tpublic SegL(VecL a, VecL b) {\n\t\t\tfrom=a;\n\t\t\tto=b;\n\t\t\tdir = to.sub(from);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[\"+from+\" -> \"+to+\"]\";\n\t\t}\n\t}\n\t\n\tstatic class CHT {\n\t\tTreeSet hull;\n\t\tint type; boolean query = false;\n\t\tComparator comp = new Comparator() {\n\t\t\tpublic int compare(Line a, Line b) {\n\t\t\t\tif (!query) return type * Long.compare(a.m, b.m);\n\t\t\t\tif (a.left == b.left) return Long.compare(a.m, b.m);\n\t\t\t\treturn Double.compare(a.left, b.left);\n\t\t\t}\n\t\t};\n\t\t// -1 for min; +1 for max\n\t\tpublic CHT(int typee) { type = typee; hull = new TreeSet<>(comp); }\n\n\t\tpublic void add(long m, long b) { add(new Line(m, b)); }\n\n\t\tpublic void add(Line a) {\n\t\t\tLine[] LR = { hull.lower(a), hull.ceiling(a) };\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tif (LR[i] != null && LR[i].m == a.m) {\n\t\t\t\t\tif (type == 1 && LR[i].b >= a.b) return;\n\t\t\t\t\tif (type == -1 && LR[i].b <= a.b) return;\n\t\t\t\t\tremove(LR[i]);\n\t\t\t\t}\n\t\t\thull.add(a);\n\t\t\tLine L = hull.lower(a), R = hull.higher(a);\n\t\t\tif (L != null && R != null && a.inter(R) <= R.left) {\n\t\t\t\thull.remove(a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tLine LL = (L != null) ? hull.lower(L) : null;\n\t\t\tLine RR = (R != null) ? hull.higher(R) : null;\n\t\t\tif (L != null) a.left = a.inter(L);\n\t\t\tif (R != null) R.left = a.inter(R);\n\t\t\twhile (LL != null && L.left >= a.inter(LL)) {\n\t\t\t\tremove(L);\n\t\t\t\ta.left = a.inter(L = LL);\n\t\t\t\tLL = hull.lower(L);\n\t\t\t}\n\t\t\twhile (RR != null && R.inter(RR) <= a.inter(RR)) {\n\t\t\t\tremove(R);\n\t\t\t\tRR.left = a.inter(R = RR);\n\t\t\t\tRR = hull.higher(R);\n\t\t\t}\n\t\t}\n\n\t\tpublic long query(long x) {\n\t\t\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cbc8591729d6ed81c1a22042e31e6d13", "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class 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 candidates;\n\tstatic int[] sz;\n\tstatic final boolean debug = false;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tint N = in.nextInt();\n\t\tM = in.nextInt();\n\t\t\n\t\tArrayDeque es[] = new ArrayDeque[N];\n\t\tfor(int i = 0; i < N; i++) es[i] = new ArrayDeque();\n\t\tfor(int i = 0; i < N-1; i++) {\n\t\t\tint u = in.nextInt()-1;\n\t\t\tint v = in.nextInt()-1;\n\t\t\tlong m = in.nextLong();\n\t\t\tlong b = in.nextLong();\n\t\t\tEdge e = new Edge(u,v,m,b);\n\t\t\tes[u].add(e);\n\t\t\tes[v].add(e);\n\t\t}\n\t\t\n\t\tcurN = N;\n\t\tadj = new Edge[maxN][3];\n\t\tcurE = new int[maxN];\n\t\tfixTree(0, -1, es);\n\t\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"N= \"+ curN);\n\t\t\tfor(int i = 0; i < curN; i++) {\n\t\t\t\tSystem.out.println(i+\" \"+adj[i].toString());\n\t\t\t}\n\t\t}\n\t\t\n\t\tcandidates = new ArrayList<>();\n\t\tsz = new int[curN];\n\t\tsolve(0);\n\t\t\n\t\tCHT cht = new CHT(1);\n\t\tfor(VecL[] cs : candidates) {\n\t\t\tfor(VecL v : cs) {\n\t\t\t\tcht.add(v.x, v.y);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < M; i++) out.print(cht.query(i)+\" \");\n\t\tout.println();\n\t\tout.close();\n\t}\n\t\n\tstatic void solve(int node) {\n\t\tszdfs(node, -1);\n\t\tif(sz[node] == 1) return; // base case, no edges\n\t\tEdge e = getEdgetroid(node, -1, sz[node], null);\n\t\te.blocked = true;\n\t\t\n\t\t//solve on this guy\n\t\tArrayList left = new ArrayList();\n\t\tArrayList right = new ArrayList();\n\t\tmakeLines(e.u, -1, e.m, e.b, left);\n\t\tmakeLines(e.v, -1, 0, 0, right);\n\t\t\n\t\tVecL[] minskowski = minkowskiSum(getHull(removeDupes(left)), getHull(removeDupes(right)));\n\t\tcandidates.add(minskowski);\n\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"Decomp on: \"+e);\n\t\t\tSystem.out.println(\" Left: \"+left.toString());\n\t\t\tSystem.out.println(\" Right: \"+right.toString());\n\t\t\tSystem.out.println(\" Minskowski: \"+Arrays.toString(minskowski));\n\t\t}\n\t\t\n\t\t//now solve on the remaining stuff\n\t\tsolve(e.u);\n\t\tsolve(e.v);\n\t}\n\t\n\tstatic void makeLines(int node, int p, long curM, long curB, ArrayList vecs) {\n\t\tint to = 0;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tto++;\n\t\t\tmakeLines(e.to(node), node, curM + e.m, curB + e.b, vecs);\n\t\t}\n\t\tif(to == 0) vecs.add(new VecL(curM, curB));\n\t}\n\t\n\tstatic Edge getEdgetroid(int node, int p, int totalSz, Edge curBest) {\n\t\tEdge myBest = null;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tif(myBest == null || myBest.getDif(totalSz) > e.getDif(totalSz)) {\n\t\t\t\tmyBest = e;\n\t\t\t}\n\t\t}\n\t\tif(curBest != null && (myBest == null || curBest.getDif(totalSz) <= myBest.getDif(totalSz))) return curBest;\n\t\treturn getEdgetroid(myBest.to(node), node, totalSz, myBest);\n\t}\n\tstatic void szdfs(int node, int p) {\n\t\tsz[node] = 1;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tszdfs(e.to(node), node);\n\t\t\tsz[node] += sz[e.to(node)];\n\t\t}\n\t}\n\t\n\tstatic void fixTree(int node, int p, ArrayDeque es[]) {\n\t\tint cur = node;\n\t\twhile(!es[node].isEmpty()) {\n\t\t\tif(es[node].size() <= 2) {\n\t\t\t\twhile(!es[node].isEmpty()) {\n\t\t\t\t\tEdge e = es[node].poll();\n\t\t\t\t\te.swap(node, cur);\n\t\t\t\t\tint to = e.to(cur);\n\t\t\t\t\taddEdge(cur, to, e, false, es);\n\t\t\t\t\tfixTree(to, cur, es);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t//add left edge to my current guy\n\t\t\t\tEdge e = es[node].poll();\n\t\t\t\te.swap(node, cur);\n\t\t\t\tint to = e.to(cur);\n\t\t\t\taddEdge(cur, to, e, false, es);\n\t\t\t\tfixTree(to, cur, es);\n\t\t\t\t\n\t\t\t\tint next = curN++;\n\t\t\t\tEdge filler = new Edge(cur, next, 0, 0);\n\t\t\t\taddEdge(cur, next, filler, true, es);\n\t\t\t\tcur = next;\n\t\t\t}\n\t\t}\n\t}\n\tstatic void addEdge(int a, int b, Edge e, boolean filler, ArrayDeque es[]) {\n\t\tadj[a][curE[a]++] = e;\n\t\tadj[b][curE[b]++] = e;\n\t\tif(!filler) es[b].remove(e);\n\t}\n\t\n\tstatic class Edge{\n\t\tint u,v;\n\t\tlong m,b;\n\t\tboolean blocked;\n\t\tpublic Edge(int uu, int vv, long mm, long bb) {\n\t\t\tu=uu; v=vv; m=mm; b=bb;\n\t\t\tblocked = false;\n\t\t}\n\t\tint to(int node) { return u^v^node; }\n\t\tvoid swap(int from, int to) {\n\t\t\tif(u == from) u = to;\n\t\t\telse if(v == from) v = to;\n\t\t\telse throw null;\n\t\t}\n\t\tint getDif(int totalSz) {\n\t\t\tint s1 = Math.min(sz[u], sz[v]);\n\t\t\tint s2 = totalSz - Math.min(sz[u], sz[v]);\n\t\t\treturn Math.abs(s1-s2);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[u=\"+u+\" v=\"+v+\" m=\"+m+\" b=\"+b+\"]\";\n\t\t}\n\t}\n\t\n\t\n\t// Computes the convex hull of the Minkowski sum of 2 convex polygons.\n\t// Polygons must be in CCW order and returns the sum in same order\n\t// O(N + M) where N and M are the sizes of the two polygons\n\tpublic static VecL[] minkowskiSum(VecL[] 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}\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 points) {\n\t\tHashSet set=new HashSet<>();\n\t\tfor (VecL v:points)\n\t\t\tset.add(v);\n\t\tint counter=0;\n\t\tVecL res[] = new VecL[set.size()];\n\t\tfor (VecL v:set) res[counter++]=v;\n\t\treturn res;\n\t}\n\t// returns the hull in CCW order\n\tpublic static VecL[] getHull(VecL[] points) {\n\t\tpoints=points.clone();\n\t\tArrays.sort(points);\n\t\tif (points.length<3)\n\t\t\treturn points;\n\t\tint n=points.length, j=2, k=2;\n\t\tVecL[] lo=new VecL[n], up=new VecL[n];\n\t\tlo[0]=points[0];\n\t\tlo[1]=points[1];\n\t\tfor (int i=2; i1&&!right(lo[j-2], lo[j-1], p)) j--;\n\t\t\tlo[j++]=p;\n\t\t}\n\t\tup[0]=points[n-1];\n\t\tup[1]=points[n-2];\n\t\tfor (int i=n-3; i>=0; i--) {\n\t\t\tVecL p=points[i];\n\t\t\twhile (k>1&&!right(up[k-2], up[k-1], p)) k--;\n\t\t\tup[k++]=p;\n\t\t}\n\n\t\tVecL[] res=new VecL[j+k-2];\n\t\tfor (int i=0; ib->c are in the right order\n\tstatic boolean right(VecL a, VecL b, VecL c) {\n\t\treturn b.sub(a).cross(c.sub(a))>0;\n\t}\n\t\n\tstatic class VecL implements Comparable{\n\t\tlong x,y;\n\t\tpublic VecL(long xx, long yy) {\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t}\n\t\tpublic VecL add(VecL o) { return new VecL(x+o.x, y+o.y);}\n\t\tpublic VecL sub(VecL o) { return new VecL(x-o.x, y-o.y);}\n\t\tpublic long cross(VecL o) { return x*o.y - y*o.x;}\n\t\tpublic long dot(VecL o) { return x*o.x + y*o.y;}\n\t\tpublic int quadrant() {\n\t\t\tif (x==0||y==0)\n\t\t\t\tif (y==0)\n\t\t\t\t\tif (x>=0)\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 3;\n\t\t\t\telse\n\t\t\t\t\tif (y>=0)\n\t\t\t\t\t\treturn 2;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 4;\n\t\t\tif (x>0)\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 1;\n\t\t\t\telse\n\t\t\t\t\treturn 4;\n\t\t\telse\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 2;\n\t\t\t\telse\n\t\t\t\t\treturn 3;\n\t\t}\n\t\t\n\t\tpublic int radialCompare(VecL o) {\n\t\t\tif (quadrant()==o.quadrant())\n\t\t\t\treturn -Long.signum(cross(o));\n\t\t\treturn Integer.compare(quadrant(), o.quadrant());\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(VecL o) {\n\t\t\tif(x!=o.x) return Long.compare(x, o.x);\n\t\t\treturn Long.compare(y, o.y);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+x+\",\"+y+\")\";\n\t\t}\n\t\tpublic int hashCode() {\n\t\t\treturn Long.hashCode(x<<13^(y*57));\n\t\t}\n\t\t\n\t\tpublic boolean equals(Object oo) {\n\t\t\tVecL o=(VecL)oo;\n\t\t\treturn x==o.x&&y==o.y;\n\t\t}\t\t\n\t}\n\t\n\tstatic class SegL{\n\t\tVecL from, to, dir;\n\t\tpublic SegL(VecL a, VecL b) {\n\t\t\tfrom=a;\n\t\t\tto=b;\n\t\t\tdir = to.sub(from);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[\"+from+\" -> \"+to+\"]\";\n\t\t}\n\t}\n\t\n\tstatic class CHT {\n\t\tTreeSet hull;\n\t\tint type; boolean query = false;\n\t\tComparator comp = new Comparator() {\n\t\t\tpublic int compare(Line a, Line b) {\n\t\t\t\tif (!query) return type * Long.compare(a.m, b.m);\n\t\t\t\tif (a.left == b.left) return Long.compare(a.m, b.m);\n\t\t\t\treturn Double.compare(a.left, b.left);\n\t\t\t}\n\t\t};\n\t\t// -1 for min; +1 for max\n\t\tpublic CHT(int typee) { type = typee; hull = new TreeSet<>(comp); }\n\n\t\tpublic void add(long m, long b) { add(new Line(m, b)); }\n\n\t\tpublic void add(Line a) {\n\t\t\tLine[] LR = { hull.lower(a), hull.ceiling(a) };\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tif (LR[i] != null && LR[i].m == a.m) {\n\t\t\t\t\tif (type == 1 && LR[i].b >= a.b) return;\n\t\t\t\t\tif (type == -1 && LR[i].b <= a.b) return;\n\t\t\t\t\tremove(LR[i]);\n\t\t\t\t}\n\t\t\thull.add(a);\n\t\t\tLine L = hull.lower(a), R = hull.higher(a);\n\t\t\tif (L != null && R != null && a.inter(R) <= R.left) {\n\t\t\t\thull.remove(a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tLine LL = (L != null) ? hull.lower(L) : null;\n\t\t\tLine RR = (R != null) ? hull.higher(R) : null;\n\t\t\tif (L != null) a.left = a.inter(L);\n\t\t\tif (R != null) R.left = a.inter(R);\n\t\t\twhile (LL != null && L.left >= a.inter(LL)) {\n\t\t\t\tremove(L);\n\t\t\t\ta.left = a.inter(L = LL);\n\t\t\t\tLL = hull.lower(L);\n\t\t\t}\n\t\t\twhile (RR != null && R.inter(RR) <= a.inter(RR)) {\n\t\t\t\tremove(R);\n\t\t\t\tRR.left = a.inter(R = RR);\n\t\t\t\tRR = hull.higher(R);\n\t\t\t}\n\t\t}\n\n\t\tpublic long query(long x) {\n\t\t\tif(hull.size() == 0) return 0;\n\t\t\tLine temp = new Line(0, 0, 0);\n\t\t\ttemp.left = x; query = true;\n\t\t\tlong ans = (long) hull.floor(temp).eval(x);\n\t\t\tquery = false; return ans;\n\t\t}\n\n\t\tprivate void remove(Line x) { hull.remove(x); }\n\n\t\tpublic int size() { return hull.size(); }\n\n\t\tstatic class Line {\n\t\t\tlong m, b; double left = Long.MIN_VALUE;\n\t\t\tpublic Line(long mm, long x, long y) { m = mm; b = -m * x + y; }\n\t\t\tpublic Line(long mm, long bb) { m = mm; b = bb; }\n\t\t\tpublic long eval(long x) { return m * x + b; }\n\t\t\tpublic double inter(Line x) {\n\t\t\t\treturn (double) (x.b - this.b) / (double) (this.m - x.m);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t\tint[] NIA(int n) {\n\t\t\tint r[] = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextInt();\n\t\t\treturn r;\n\t\t}\n\t\tlong[] NLA(int n) {\n\t\t\tlong r[] = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextLong();\n\t\t\treturn r;\n\t\t}\n\t\tchar[][] grid(int r, int c){\n\t\t\tchar res[][] = new char[r][c];\n\t\t\tfor(int i = 0; i < r; i++) {\n\t\t\t\tchar l[] = next().toCharArray();\n\t\t\t\tfor(int j = 0; j < c; j++) {\n\t\t\t\t\tres[i][j] = l[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "794f2f45d9c528b9f9d31394509a39b1", "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class E {\n\tstatic PrintWriter out = new PrintWriter(System.out);\t\n\tstatic int M;\n\tstatic int maxN = 200001;\n\tstatic int curN;\n\tstatic ArrayList adj[];\n\tstatic ArrayList candidates;\n\tstatic int[] sz;\n\tstatic final boolean debug = false;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tint N = in.nextInt();\n\t\tM = in.nextInt();\n\t\t\n\t\tArrayDeque es[] = new ArrayDeque[N];\n\t\tfor(int i = 0; i < N; i++) es[i] = new ArrayDeque();\n\t\tfor(int i = 0; i < N-1; i++) {\n\t\t\tint u = in.nextInt()-1;\n\t\t\tint v = in.nextInt()-1;\n\t\t\tlong m = in.nextLong();\n\t\t\tlong b = in.nextLong();\n\t\t\tEdge e = new Edge(u,v,m,b);\n\t\t\tes[u].add(e);\n\t\t\tes[v].add(e);\n\t\t}\n\t\t\n\t\tcurN = N;\n\t\tadj = new ArrayList[maxN];\n\t\tfor(int i = 0; i < maxN; i++) adj[i] = new ArrayList();\n\t\tfixTree(0, -1, es);\n\t\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"N= \"+ curN);\n\t\t\tfor(int i = 0; i < curN; i++) {\n\t\t\t\tSystem.out.println(i+\" \"+adj[i].toString());\n\t\t\t}\n\t\t}\n\t\t\n\t\tcandidates = new ArrayList<>();\n\t\tsz = new int[curN];\n\t\tsolve(0);\n\t\t\n\t\tCHT cht = new CHT(1);\n\t\tfor(VecL[] cs : candidates) {\n\t\t\tfor(VecL v : cs) {\n\t\t\t\tcht.add(v.x, v.y);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < M; i++) out.print(cht.query(i)+\" \");\n\t\tout.println();\n\t\tout.close();\n\t}\n\t\n\tstatic void solve(int node) {\n\t\tszdfs(node, -1);\n\t\tif(sz[node] == 1) return; // base case, no edges\n\t\tEdge e = getEdgetroid(node, -1, sz[node], null);\n\t\te.blocked = true;\n\t\t\n\t\t//solve on this guy\n\t\tArrayList left = new ArrayList();\n\t\tArrayList right = new ArrayList();\n\t\tmakeLines(e.u, -1, e.m, e.b, left);\n\t\tmakeLines(e.v, -1, 0, 0, right);\n\t\t\n\t\tVecL[] minskowski = minkowskiSum(getHull(removeDupes(left)), getHull(removeDupes(right)));\n\t\tcandidates.add(minskowski);\n\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"Decomp on: \"+e);\n\t\t\tSystem.out.println(\" Left: \"+left.toString());\n\t\t\tSystem.out.println(\" Right: \"+right.toString());\n\t\t\tSystem.out.println(\" Minskowski: \"+Arrays.toString(minskowski));\n\t\t}\n\t\t\n\t\t//now solve on the remaining stuff\n\t\tsolve(e.u);\n\t\tsolve(e.v);\n\t}\n\t\n\tstatic void makeLines(int node, int p, long curM, long curB, ArrayList vecs) {\n\t\tint to = 0;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e.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.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.blocked || e.to(node) == p) continue;\n\t\t\tszdfs(e.to(node), node);\n\t\t\tsz[node] += sz[e.to(node)];\n\t\t}\n\t}\n\t\n\tstatic void fixTree(int node, int p, ArrayDeque es[]) {\n\t\tint cur = node;\n\t\twhile(!es[node].isEmpty()) {\n\t\t\tif(es[node].size() <= 2) {\n\t\t\t\twhile(!es[node].isEmpty()) {\n\t\t\t\t\tEdge e = es[node].poll();\n\t\t\t\t\te.swap(node, cur);\n\t\t\t\t\tadj[cur].add(e);\n\t\t\t\t\tadj[e.to(cur)].add(e);\n\t\t\t\t\tes[e.to(cur)].remove(e);\n\t\t\t\t\tfixTree(e.to(cur), 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\tadj[cur].add(e);\n\t\t\t\tadj[e.to(cur)].add(e);\n\t\t\t\tes[e.to(cur)].remove(e);\n\t\t\t\tfixTree(e.to(cur), 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\tadj[cur].add(filler);\n\t\t\t\tadj[next].add(filler);\n\t\t\t\tcur = next;\n\t\t\t}\n\t\t}\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\twhile(rId < n+m) {\n\t\t\tSegL seg, seg2 = null;\n\t\t\tif(better(ni,mi,s1,s2)) {\n\t\t\t\tseg = s1[ni]; if(rId == 0) seg2 = s2[mi];\n\t\t\t\tni = (ni+1)%n;\n\t\t\t\tif(ni == nst) ni = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tseg = s2[mi]; if(rId == 0) seg2 = s1[ni];\n\t\t\t\tmi = (mi+1)%m;\n\t\t\t\tif(mi == mst) mi = -1;\n\t\t\t}\n\t\t\tif(rId == 0) hull[rId++] = seg.from.add(seg2.from);\n\t\t\thull[rId] = hull[rId-1].add(seg.dir);\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 points) {\n\t\tHashSet set=new HashSet<>();\n\t\tfor (VecL v:points)\n\t\t\tset.add(v);\n\t\tint counter=0;\n\t\tVecL res[] = new VecL[set.size()];\n\t\tfor (VecL v:set) res[counter++]=v;\n\t\treturn res;\n\t}\n\t// returns the hull in CCW order\n\tpublic static VecL[] getHull(VecL[] points) {\n\t\tpoints=points.clone();\n\t\tArrays.sort(points);\n\t\tif (points.length<3)\n\t\t\treturn points;\n\t\tint n=points.length, j=2, k=2;\n\t\tVecL[] lo=new VecL[n], up=new VecL[n];\n\t\tlo[0]=points[0];\n\t\tlo[1]=points[1];\n\t\tfor (int i=2; i1&&!right(lo[j-2], lo[j-1], p)) j--;\n\t\t\tlo[j++]=p;\n\t\t}\n\t\tup[0]=points[n-1];\n\t\tup[1]=points[n-2];\n\t\tfor (int i=n-3; i>=0; i--) {\n\t\t\tVecL p=points[i];\n\t\t\twhile (k>1&&!right(up[k-2], up[k-1], p)) k--;\n\t\t\tup[k++]=p;\n\t\t}\n\n\t\tVecL[] res=new VecL[j+k-2];\n\t\tfor (int i=0; ib->c are in the right order\n\tstatic boolean right(VecL a, VecL b, VecL c) {\n\t\treturn b.sub(a).cross(c.sub(a))>0;\n\t}\n\t\n\tstatic class VecL implements Comparable{\n\t\tlong x,y;\n\t\tpublic VecL(long xx, long yy) {\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t}\n\t\tpublic VecL add(VecL o) { return new VecL(x+o.x, y+o.y);}\n\t\tpublic VecL sub(VecL o) { return new VecL(x-o.x, y-o.y);}\n\t\tpublic long cross(VecL o) { return x*o.y - y*o.x;}\n\t\tpublic long dot(VecL o) { return x*o.x + y*o.y;}\n\t\tpublic int quadrant() {\n\t\t\tif (x==0||y==0)\n\t\t\t\tif (y==0)\n\t\t\t\t\tif (x>=0)\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 3;\n\t\t\t\telse\n\t\t\t\t\tif (y>=0)\n\t\t\t\t\t\treturn 2;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 4;\n\t\t\tif (x>0)\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 1;\n\t\t\t\telse\n\t\t\t\t\treturn 4;\n\t\t\telse\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 2;\n\t\t\t\telse\n\t\t\t\t\treturn 3;\n\t\t}\n\t\t\n\t\tpublic int radialCompare(VecL o) {\n\t\t\tif (quadrant()==o.quadrant())\n\t\t\t\treturn -Long.signum(cross(o));\n\t\t\treturn Integer.compare(quadrant(), o.quadrant());\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(VecL o) {\n\t\t\tif(x!=o.x) return Long.compare(x, o.x);\n\t\t\treturn Long.compare(y, o.y);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+x+\",\"+y+\")\";\n\t\t}\n\t\tpublic int hashCode() {\n\t\t\treturn Long.hashCode(x<<13^(y*57));\n\t\t}\n\t\t\n\t\tpublic boolean equals(Object oo) {\n\t\t\tVecL o=(VecL)oo;\n\t\t\treturn x==o.x&&y==o.y;\n\t\t}\t\t\n\t}\n\t\n\tstatic class SegL{\n\t\tVecL from, to, dir;\n\t\tpublic SegL(VecL a, VecL b) {\n\t\t\tfrom=a;\n\t\t\tto=b;\n\t\t\tdir = to.sub(from);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[\"+from+\" -> \"+to+\"]\";\n\t\t}\n\t}\n\t\n\tstatic class CHT {\n\t\tTreeSet hull;\n\t\tint type; boolean query = false;\n\t\tComparator comp = new Comparator() {\n\t\t\tpublic int compare(Line a, Line b) {\n\t\t\t\tif (!query) return type * Long.compare(a.m, b.m);\n\t\t\t\tif (a.left == b.left) return Long.compare(a.m, b.m);\n\t\t\t\treturn Double.compare(a.left, b.left);\n\t\t\t}\n\t\t};\n\t\t// -1 for min; +1 for max\n\t\tpublic CHT(int typee) { type = typee; hull = new TreeSet<>(comp); }\n\n\t\tpublic void add(long m, long b) { add(new Line(m, b)); }\n\n\t\tpublic void add(Line a) {\n\t\t\tLine[] LR = { hull.lower(a), hull.ceiling(a) };\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tif (LR[i] != null && LR[i].m == a.m) {\n\t\t\t\t\tif (type == 1 && LR[i].b >= a.b) return;\n\t\t\t\t\tif (type == -1 && LR[i].b <= a.b) return;\n\t\t\t\t\tremove(LR[i]);\n\t\t\t\t}\n\t\t\thull.add(a);\n\t\t\tLine L = hull.lower(a), R = hull.higher(a);\n\t\t\tif (L != null && R != null && a.inter(R) <= R.left) {\n\t\t\t\thull.remove(a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tLine LL = (L != null) ? hull.lower(L) : null;\n\t\t\tLine RR = (R != null) ? hull.higher(R) : null;\n\t\t\tif (L != null) a.left = a.inter(L);\n\t\t\tif (R != null) R.left = a.inter(R);\n\t\t\twhile (LL != null && L.left >= a.inter(LL)) {\n\t\t\t\tremove(L);\n\t\t\t\ta.left = a.inter(L = LL);\n\t\t\t\tLL = hull.lower(L);\n\t\t\t}\n\t\t\twhile (RR != null && R.inter(RR) <= a.inter(RR)) {\n\t\t\t\tremove(R);\n\t\t\t\tRR.left = a.inter(R = RR);\n\t\t\t\tRR = hull.higher(R);\n\t\t\t}\n\t\t}\n\n\t\tpublic long query(long x) {\n\t\t\tif(hull.size() == 0) return 0;\n\t\t\tLine temp = new Line(0, 0, 0);\n\t\t\ttemp.left = x; query = true;\n\t\t\tlong ans = (long) hull.floor(temp).eval(x);\n\t\t\tquery = false; return ans;\n\t\t}\n\n\t\tprivate void remove(Line x) { hull.remove(x); }\n\n\t\tpublic int size() { return hull.size(); }\n\n\t\tstatic class Line {\n\t\t\tlong m, b; double left = Long.MIN_VALUE;\n\t\t\tpublic Line(long mm, long x, long y) { m = mm; b = -m * x + y; }\n\t\t\tpublic Line(long mm, long bb) { m = mm; b = bb; }\n\t\t\tpublic long eval(long x) { return m * x + b; }\n\t\t\tpublic double inter(Line x) {\n\t\t\t\treturn (double) (x.b - this.b) / (double) (this.m - x.m);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t\tint[] NIA(int n) {\n\t\t\tint r[] = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextInt();\n\t\t\treturn r;\n\t\t}\n\t\tlong[] NLA(int n) {\n\t\t\tlong r[] = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextLong();\n\t\t\treturn r;\n\t\t}\n\t\tchar[][] grid(int r, int c){\n\t\t\tchar res[][] = new char[r][c];\n\t\t\tfor(int i = 0; i < r; i++) {\n\t\t\t\tchar l[] = next().toCharArray();\n\t\t\t\tfor(int j = 0; j < c; j++) {\n\t\t\t\t\tres[i][j] = l[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cbd9ae6c582eebc336c46a1df25ede33", "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class E6 {\n\tstatic PrintWriter out = new PrintWriter(System.out);\t\n\tstatic int M;\n\tstatic int maxN = 200001;\n\tstatic int curN;\n\tstatic Edge adj[][];\n\tstatic int curE[];\n\tstatic ArrayList candidates;\n\tstatic int[] sz;\n\tstatic final boolean debug = false;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tint N = in.nextInt();\n\t\tM = in.nextInt();\n\t\t\n\t\tArrayDeque es[] = new ArrayDeque[N];\n\t\tfor(int i = 0; i < N; i++) es[i] = new ArrayDeque();\n\t\tfor(int i = 0; i < N-1; i++) {\n\t\t\tint u = in.nextInt()-1;\n\t\t\tint v = in.nextInt()-1;\n\t\t\tlong m = in.nextLong();\n\t\t\tlong b = in.nextLong();\n\t\t\tEdge e = new Edge(u,v,m,b);\n\t\t\tes[u].add(e);\n\t\t\tes[v].add(e);\n\t\t}\n\t\t\n\t\tcurN = N;\n\t\tadj = new Edge[maxN][3];\n\t\tcurE = new int[maxN];\n\t\tfixTree(0, -1, es);\n\t\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"N= \"+ curN);\n\t\t\tfor(int i = 0; i < curN; i++) {\n\t\t\t\tSystem.out.println(i+\" \"+adj[i].toString());\n\t\t\t}\n\t\t}\n\t\t\n\t\tcandidates = new ArrayList<>();\n\t\tsz = new int[curN];\n\t\tsolve(0);\n\t\t\n\t\tCHT cht = new CHT(1);\n\t\tfor(VecL[] cs : candidates) {\n\t\t\tfor(VecL v : cs) {\n\t\t\t\tcht.add(v.x, v.y);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < M; i++) out.print(cht.query(i)+\" \");\n\t\tout.println();\n\t\tout.close();\n\t}\n\t\n\tstatic void solve(int node) {\n\t\tszdfs(node, -1);\n\t\tif(sz[node] == 1) return; // base case, no edges\n\t\tEdge e = getEdgetroid(node, -1, sz[node], null);\n\t\te.blocked = true;\n\t\t\n\t\t//solve on this guy\n\t\tArrayList left = new ArrayList();\n\t\tArrayList right = new ArrayList();\n\t\tmakeLines(e.u, -1, e.m, e.b, left);\n\t\tmakeLines(e.v, -1, 0, 0, right);\n\t\t\n\t\tVecL[] minskowski = minkowskiSum(getHull(removeDupes(left)), getHull(removeDupes(right)));\n\t\tcandidates.add(minskowski);\n\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"Decomp on: \"+e);\n\t\t\tSystem.out.println(\" Left: \"+left.toString());\n\t\t\tSystem.out.println(\" Right: \"+right.toString());\n\t\t\tSystem.out.println(\" Minskowski: \"+Arrays.toString(minskowski));\n\t\t}\n\t\t\n\t\t//now solve on the remaining stuff\n\t\tsolve(e.u);\n\t\tsolve(e.v);\n\t}\n\t\n\tstatic void makeLines(int node, int p, long curM, long curB, ArrayList vecs) {\n\t\tint to = 0;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tto++;\n\t\t\tmakeLines(e.to(node), node, curM + e.m, curB + e.b, vecs);\n\t\t}\n\t\tif(to == 0) vecs.add(new VecL(curM, curB));\n\t}\n\t\n\tstatic Edge getEdgetroid(int node, int p, int totalSz, Edge curBest) {\n\t\tEdge myBest = null;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tif(myBest == null || myBest.getDif(totalSz) > e.getDif(totalSz)) {\n\t\t\t\tmyBest = e;\n\t\t\t}\n\t\t}\n\t\tif(curBest != null && (myBest == null || curBest.getDif(totalSz) <= myBest.getDif(totalSz))) return curBest;\n\t\treturn getEdgetroid(myBest.to(node), node, totalSz, myBest);\n\t}\n\tstatic void szdfs(int node, int p) {\n\t\tsz[node] = 1;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tszdfs(e.to(node), node);\n\t\t\tsz[node] += sz[e.to(node)];\n\t\t}\n\t}\n\t\n\tstatic void fixTree(int node, int p, ArrayDeque es[]) {\n\t\tint cur = node;\n\t\twhile(!es[node].isEmpty()) {\n\t\t\tif(es[node].size() <= 2) {\n\t\t\t\twhile(!es[node].isEmpty()) {\n\t\t\t\t\tEdge e = es[node].poll();\n\t\t\t\t\te.swap(node, cur);\n\t\t\t\t\tint to = e.to(cur);\n\t\t\t\t\taddEdge(cur, to, e, false, es);\n\t\t\t\t\tfixTree(to, cur, es);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t//add left edge to my current guy\n\t\t\t\tEdge e = es[node].poll();\n\t\t\t\te.swap(node, cur);\n\t\t\t\tint to = e.to(cur);\n\t\t\t\taddEdge(cur, to, e, false, es);\n\t\t\t\tfixTree(to, cur, es);\n\t\t\t\t\n\t\t\t\tint next = curN++;\n\t\t\t\tEdge filler = new Edge(cur, next, 0, 0);\n\t\t\t\taddEdge(cur, next, filler, true, es);\n\t\t\t\tcur = next;\n\t\t\t}\n\t\t}\n\t}\n\tstatic void addEdge(int a, int b, Edge e, boolean filler, ArrayDeque es[]) {\n\t\tadj[a][curE[a]++] = e;\n\t\tadj[b][curE[b]++] = e;\n\t\tif(!filler) es[b].remove(e);\n\t}\n\t\n\tstatic class Edge{\n\t\tint u,v;\n\t\tlong m,b;\n\t\tboolean blocked;\n\t\tpublic Edge(int uu, int vv, long mm, long bb) {\n\t\t\tu=uu; v=vv; m=mm; b=bb;\n\t\t\tblocked = false;\n\t\t}\n\t\tint to(int node) { return u^v^node; }\n\t\tvoid swap(int from, int to) {\n\t\t\tif(u == from) u = to;\n\t\t\telse if(v == from) v = to;\n\t\t\telse throw null;\n\t\t}\n\t\tint getDif(int totalSz) {\n\t\t\tint s1 = Math.min(sz[u], sz[v]);\n\t\t\tint s2 = totalSz - Math.min(sz[u], sz[v]);\n\t\t\treturn Math.abs(s1-s2);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[u=\"+u+\" v=\"+v+\" m=\"+m+\" b=\"+b+\"]\";\n\t\t}\n\t}\n\t\n\t\n\t// Computes the convex hull of the Minkowski sum of 2 convex polygons.\n\t// Polygons must be in CCW order and returns the sum in same order\n\t// O(N + M) where N and M are the sizes of the two polygons\n\tpublic static VecL[] minkowskiSum(VecL[] 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(mi == -1 || (ni != -1 && c1[ni].radialCompare(c2[mi]) <= 0)) {\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}\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 points) {\n\t\tHashSet set=new HashSet<>();\n\t\tfor (VecL v:points)\n\t\t\tset.add(v);\n\t\tint counter=0;\n\t\tVecL res[] = new VecL[set.size()];\n\t\tfor (VecL v:set) res[counter++]=v;\n\t\treturn res;\n\t}\n\t// returns the hull in CCW order\n\tpublic static VecL[] getHull(VecL[] points) {\n\t\tpoints=points.clone();\n\t\tArrays.sort(points);\n\t\tif (points.length<3)\n\t\t\treturn points;\n\t\tint n=points.length, j=2, k=2;\n\t\tVecL[] lo=new VecL[n], up=new VecL[n];\n\t\tlo[0]=points[0];\n\t\tlo[1]=points[1];\n\t\tfor (int i=2; i1&&!right(lo[j-2], lo[j-1], p)) j--;\n\t\t\tlo[j++]=p;\n\t\t}\n\t\tup[0]=points[n-1];\n\t\tup[1]=points[n-2];\n\t\tfor (int i=n-3; i>=0; i--) {\n\t\t\tVecL p=points[i];\n\t\t\twhile (k>1&&!right(up[k-2], up[k-1], p)) k--;\n\t\t\tup[k++]=p;\n\t\t}\n\n\t\tVecL[] res=new VecL[j+k-2];\n\t\tfor (int i=0; ib->c are in the right order\n\tstatic boolean right(VecL a, VecL b, VecL c) {\n\t\treturn b.sub(a).cross(c.sub(a))>0;\n\t}\n\t\n\tstatic class VecL implements Comparable{\n\t\tlong x,y;\n\t\tpublic VecL(long xx, long yy) {\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t}\n\t\tpublic VecL add(VecL o) { return new VecL(x+o.x, y+o.y);}\n\t\tpublic VecL sub(VecL o) { return new VecL(x-o.x, y-o.y);}\n\t\tpublic long cross(VecL o) { return x*o.y - y*o.x;}\n\t\tpublic long dot(VecL o) { return x*o.x + y*o.y;}\n\t\tpublic int quadrant() {\n\t\t\tif (x==0||y==0)\n\t\t\t\tif (y==0)\n\t\t\t\t\tif (x>=0)\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 3;\n\t\t\t\telse\n\t\t\t\t\tif (y>=0)\n\t\t\t\t\t\treturn 2;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 4;\n\t\t\tif (x>0)\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 1;\n\t\t\t\telse\n\t\t\t\t\treturn 4;\n\t\t\telse\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 2;\n\t\t\t\telse\n\t\t\t\t\treturn 3;\n\t\t}\n\t\t\n\t\tpublic int radialCompare(VecL o) {\n\t\t\tif (quadrant()==o.quadrant())\n\t\t\t\treturn -Long.signum(cross(o));\n\t\t\treturn Integer.compare(quadrant(), o.quadrant());\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(VecL o) {\n\t\t\tif(x!=o.x) return Long.compare(x, o.x);\n\t\t\treturn Long.compare(y, o.y);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+x+\",\"+y+\")\";\n\t\t}\n\t\tpublic int hashCode() {\n\t\t\treturn Long.hashCode(x<<13^(y*57));\n\t\t}\n\t\t\n\t\tpublic boolean equals(Object oo) {\n\t\t\tVecL o=(VecL)oo;\n\t\t\treturn x==o.x&&y==o.y;\n\t\t}\t\t\n\t}\n\t\n\tstatic class SegL{\n\t\tVecL from, to, dir;\n\t\tpublic SegL(VecL a, VecL b) {\n\t\t\tfrom=a;\n\t\t\tto=b;\n\t\t\tdir = to.sub(from);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[\"+from+\" -> \"+to+\"]\";\n\t\t}\n\t}\n\t\n\tstatic class CHT {\n\t\tTreeSet hull;\n\t\tint type; boolean query = false;\n\t\tComparator comp = new Comparator() {\n\t\t\tpublic int compare(Line a, Line b) {\n\t\t\t\tif (!query) return type * Long.compare(a.m, b.m);\n\t\t\t\tif (a.left == b.left) return Long.compare(a.m, b.m);\n\t\t\t\treturn Double.compare(a.left, b.left);\n\t\t\t}\n\t\t};\n\t\t// -1 for min; +1 for max\n\t\tpublic CHT(int typee) { type = typee; hull = new TreeSet<>(comp); }\n\n\t\tpublic void add(long m, long b) { add(new Line(m, b)); }\n\n\t\tpublic void add(Line a) {\n\t\t\tLine[] LR = { hull.lower(a), hull.ceiling(a) };\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tif (LR[i] != null && LR[i].m == a.m) {\n\t\t\t\t\tif (type == 1 && LR[i].b >= a.b) return;\n\t\t\t\t\tif (type == -1 && LR[i].b <= a.b) return;\n\t\t\t\t\tremove(LR[i]);\n\t\t\t\t}\n\t\t\thull.add(a);\n\t\t\tLine L = hull.lower(a), R = hull.higher(a);\n\t\t\tif (L != null && R != null && a.inter(R) <= R.left) {\n\t\t\t\thull.remove(a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tLine LL = (L != null) ? hull.lower(L) : null;\n\t\t\tLine RR = (R != null) ? hull.higher(R) : null;\n\t\t\tif (L != null) a.left = a.inter(L);\n\t\t\tif (R != null) R.left = a.inter(R);\n\t\t\twhile (LL != null && L.left >= a.inter(LL)) {\n\t\t\t\tremove(L);\n\t\t\t\ta.left = a.inter(L = LL);\n\t\t\t\tLL = hull.lower(L);\n\t\t\t}\n\t\t\twhile (RR != null && R.inter(RR) <= a.inter(RR)) {\n\t\t\t\tremove(R);\n\t\t\t\tRR.left = a.inter(R = RR);\n\t\t\t\tRR = hull.higher(R);\n\t\t\t}\n\t\t}\n\n\t\tpublic long query(long x) {\n\t\t\tif(hull.size() == 0) return 0;\n\t\t\tLine temp = new Line(0, 0, 0);\n\t\t\ttemp.left = x; query = true;\n\t\t\tlong ans = (long) hull.floor(temp).eval(x);\n\t\t\tquery = false; return ans;\n\t\t}\n\n\t\tprivate void remove(Line x) { hull.remove(x); }\n\n\t\tpublic int size() { return hull.size(); }\n\n\t\tstatic class Line {\n\t\t\tlong m, b; double left = Long.MIN_VALUE;\n\t\t\tpublic Line(long mm, long x, long y) { m = mm; b = -m * x + y; }\n\t\t\tpublic Line(long mm, long bb) { m = mm; b = bb; }\n\t\t\tpublic long eval(long x) { return m * x + b; }\n\t\t\tpublic double inter(Line x) {\n\t\t\t\treturn (double) (x.b - this.b) / (double) (this.m - x.m);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t\tint[] NIA(int n) {\n\t\t\tint r[] = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextInt();\n\t\t\treturn r;\n\t\t}\n\t\tlong[] NLA(int n) {\n\t\t\tlong r[] = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextLong();\n\t\t\treturn r;\n\t\t}\n\t\tchar[][] grid(int r, int c){\n\t\t\tchar res[][] = new char[r][c];\n\t\t\tfor(int i = 0; i < r; i++) {\n\t\t\t\tchar l[] = next().toCharArray();\n\t\t\t\tfor(int j = 0; j < c; j++) {\n\t\t\t\t\tres[i][j] = l[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "57c85a8d5e848f7fe33093cdc2ff39d8", "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31", "difficulty": 3200.0} {"lang": "Java 6", "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 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 () ;\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 pointer = new HashMap ();\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9b54bd2d17f5e93ae041cb3259be6244", "src_uid": "10b2c1c53580dd382c41a56f7413e709", "difficulty": 2800.0} {"lang": "Java 8", "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 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 () ;\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 pointer = new HashMap ();\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad47c86a210f094d2d27961fac73053f", "src_uid": "10b2c1c53580dd382c41a56f7413e709", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic Scanner in;\n\tstatic PrintWriter out;\n//\tstatic StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n static PrintWriter sout = new PrintWriter(System.out);\n\n static void sout(int[][] x) {\n \tfor (int[] xx : x) {\n \t\tfor (int xxx : xx) System.out.print(xxx + \" \");\n\t\t\tSystem.out.println();\n \t}\n \tSystem.out.println();\n }\n\t\n static void sout(int[] x) {\n \tfor (int xxx : x) System.out.print(xxx + \" \");\n\t\tSystem.out.println();\n\t}\t\n\n\tstatic int[][] a;\n\tstatic int n = 6;\n\tstatic ArrayList answ;\n\n\tstatic void shift(int line, boolean hor, boolean plus) {\n\t\tint d = plus ? 1 : -1;\n\t\tif (hor) {\n\t\t\tint[] y = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) y[(i + d + n) % n] = a[line][i];\n\t\t\tfor (int i = 0; i < n; i++) a[line][i] = y[i];\n\t\t\tansw.add((plus ? \"R\" : \"L\") + (line + 1));\n\t\t} else {\n\t\t\tint[] y = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) y[(i + d + n) % n] = a[i][line];\n\t\t\tfor (int i = 0; i < n; i++) a[i][line] = y[i];\n\t\t\tansw.add((plus ? \"D\" : \"U\") + (line + 1));\n\t\t}\n\t}\n\n\tstatic void rotate(int x, int y, boolean right, boolean down, boolean clock) {\n\t\tif (clock ^ right ^ down) {\n\t\t\tshift(x, false, !down);\n\t\t\tshift(y, true, !right);\n\t\t\tshift(x, false, down);\t\t\t\n\t\t\tshift(y, true, right);\n\t\t} else {\n\t\t\tshift(y, true, !right);\n\t\t\tshift(x, false, !down);\n\t\t\tshift(y, true, right);\n\t\t\tshift(x, false, down);\n\t\t}\n\t}\n\n\tstatic void up(int x, int y) {\n\t\trotate(x, y, true, false, true);\n\t}\n\n\tstatic void down(int x, int y) {\n\t\trotate(x, y, true, true, false);\n\t}\n\n\tstatic void left(int x, int y) {\n\t\trotate(x, y, false, true, false);\n\t}\n\n\tstatic void right(int x, int y) {\n\t\trotate(x, y, true, true, true);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n//\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\t\n\t\t\n\t\tansw = new ArrayList();\n\n\t\ta = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = in.next();\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif ('0' <= s.charAt(j) && s.charAt(j) <= '9') a[i][j] = s.charAt(j) - '0';\n\t\t\t\telse a[i][j] = s.charAt(j) - 'A' + 10;\n\t\t\t}\n\t\t}\n\n\t\tint[][] aa = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < n; j++) aa[i][j] = a[i][j];\n\t\t\n\t\tint[][] g = new int[n][n];\n\t\tint[] gx = new int[n*n];\n\t\tint[] gy = new int[n*n];\n\t\tint count = 0;\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {\n\t\t\tg[i][j] = count;\n\t\t\tgx[count] = j;\n\t\t\tgy[count] = i;\n\t\t\tcount++;\n\t\t}\n\t\tfor (int index = 0;; index++) {\n\n\t\tansw = new ArrayList();\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = aa[i][j];\n\t\t\n\t\tif (index > 0) {\n\t\t\tint cnt = ((int)(Math.random() * 1e9)) % 100;\n\t\t\tfor (int i = 0; i < cnt; i++) {\n\t\t\t\tint ii = ((int)(Math.random() * 1e9)) % 6;\n\t\t\t\tint jj1 = ((int)(Math.random() * 1e9)) % 2;\n\t\t\t\tint jj2 = ((int)(Math.random() * 1e9)) % 2;\n\t\t\t\tshift(ii, jj1 == 0, jj2 == 0);\n\t\t\t}\n\t\t}\n//\t\tsout(a);\n//\t\tSystem.out.println(\"!!!\");\n\n\t\tfor (int i = 0; i < 4*n; i++) {\n\t\t\twhile (true) {\n//\t\t\t\tsout(a);\n\t\t\t\tint x = 0;\n\t\t\t\tint y = 0;\n\t\t\t\tF: for (; x < n; x++) for (y = 0; y < n; y++) {\n\t\t\t\t\tif (a[y][x] == i) break F;\n\t\t\t\t}\n//\t\t\t\tSystem.out.println(x + \" \" + y + \" \" + a[x][y] + \" \" + a[1][1]);\n\t\t\t\tif (g[y][x] == i) break;\n\t\t\t\tif (x != gx[i]) {\n\t\t\t\t\tif (y == 5) rotate(x, y, false, false, true);\n\t\t\t\t\telse left(x, y);\n\t\t\t\t}\n\t\t\t\telse up(x, y);\n\t\t\t}\n\t\t}\n\n//\t\tSystem.out.println(\"!!! 24\");\n\n\t\tfor (int i = 0; i < 4; i++) for (int t = 4*n + i; t <= 5*n + i; t += n) {\n//\t\t\tSystem.out.println(t);\n//\t\t\tsout(a);\n\t\t\twhile (true) {\n//\t\t\t\tsout(a);\n\t\t\t\tint x = 0;\n\t\t\t\tint y = 0;\n\t\t\t\tF: for (; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == t) break F;\n\t\t\t\tif (g[y][x] == t) break;\n\n\t\t\t\tif (y != gy[t]) {\n\t\t\t\t\tif (x == 5) {\n\t\t\t\t\t\tif (y < gy[t]) rotate(x, y, false, true, true);\n\t\t\t\t\t\telse rotate(x, y, false, false, false);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (y < gy[t]) rotate(x, y, true, true, false);\n\t\t\t\t\t\telse rotate(x, y, true, false, true);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (y == 4) rotate(x, y, false, true, false);\n\t\t\t\t\telse rotate(x, y, false, false, true);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"!!!\");\n\t\t\n/*\t\twhile (a[4][4] != 28 || a[4][5] != 29 || a[5][4] != 34 || a[5][5] != 35) {\n\t\t\tint i = ((int)(Math.random() * 1e9)) % 4;\n\t\t\tint j = ((int)(Math.random() * 1e9)) % 2;\n\t\t\tif (i == 0) rotate(4, 4, true, true, j == 0);\n\t\t\tif (i == 1) rotate(4, 5, true, false, j == 0);\n\t\t\tif (i == 2) rotate(5, 4, false, true, j == 0);\n\t\t\tif (i == 3) rotate(5, 5, false, false, j == 0);\n\n\t\t\tsout(a);\n\t\t}*/\n\n\t\tint x = 0;\n\t\tint y = 0;\n\t\tF: for (x = 0; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == 28) break F;\n\t\tif (x == 5 && y == 5) rotate(x, y, false, false, true);\n\t\tF: for (x = 0; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == 28) break F;\n\t\tif (x == 5) rotate(x, y, false, true, false);\n\t\tF: for (x = 0; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == 28) break F;\n\t\tif (y == 5) rotate(x, y, true, false, true);\n\n\t\twhile (a[5][5] != g[5][5]) rotate(5, 5, false, false, true);\n\n\t\tif (a[5][4] == 34) break;\n\n\t\t}\n\n\t\tout.println(answ.size());\n\t\tfor (String s : answ) out.println(s);\n\n//\t\tsout(a);\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3d84960749241361b4035ee68afff611", "src_uid": "10b2c1c53580dd382c41a56f7413e709", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic Scanner in;\n\tstatic PrintWriter out;\n//\tstatic StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n static PrintWriter sout = new PrintWriter(System.out);\n\n static void sout(int[][] x) {\n \tfor (int[] xx : x) {\n \t\tfor (int xxx : xx) System.out.print(xxx + \" \");\n\t\t\tSystem.out.println();\n \t}\n \tSystem.out.println();\n }\n\t\n static void sout(int[] x) {\n \tfor (int xxx : x) System.out.print(xxx + \" \");\n\t\tSystem.out.println();\n\t}\t\n\n\tstatic int[][] a;\n\tstatic int n = 6;\n\tstatic ArrayList answ;\n\n\tstatic void shift(int line, boolean hor, boolean plus) {\n\t\tint d = plus ? 1 : -1;\n\t\tif (hor) {\n\t\t\tint[] y = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) y[(i + d + n) % n] = a[line][i];\n\t\t\tfor (int i = 0; i < n; i++) a[line][i] = y[i];\n\t\t\tansw.add((plus ? \"R\" : \"L\") + (line + 1));\n\t\t} else {\n\t\t\tint[] y = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) y[(i + d + n) % n] = a[i][line];\n\t\t\tfor (int i = 0; i < n; i++) a[i][line] = y[i];\n\t\t\tansw.add((plus ? \"D\" : \"U\") + (line + 1));\n\t\t}\n\t}\n\n\tstatic void rotate(int x, int y, boolean right, boolean down, boolean clock) {\n\t\tif (clock ^ right ^ down) {\n\t\t\tshift(x, false, !down);\n\t\t\tshift(y, true, !right);\n\t\t\tshift(x, false, down);\t\t\t\n\t\t\tshift(y, true, right);\n\t\t} else {\n\t\t\tshift(y, true, !right);\n\t\t\tshift(x, false, !down);\n\t\t\tshift(y, true, right);\n\t\t\tshift(x, false, down);\n\t\t}\n\t}\n\n\tstatic void up(int x, int y) {\n\t\trotate(x, y, true, false, true);\n\t}\n\n\tstatic void down(int x, int y) {\n\t\trotate(x, y, true, true, false);\n\t}\n\n\tstatic void left(int x, int y) {\n\t\trotate(x, y, false, true, false);\n\t}\n\n\tstatic void right(int x, int y) {\n\t\trotate(x, y, true, true, true);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n//\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\t\n\t\tansw = new ArrayList();\n\n\t\ta = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = in.next();\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif ('0' <= s.charAt(j) && s.charAt(j) <= '9') a[i][j] = s.charAt(j) - '0';\n\t\t\t\telse a[i][j] = s.charAt(j) - 'A' + 10;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] g = new int[n][n];\n\t\tint[] gx = new int[n*n];\n\t\tint[] gy = new int[n*n];\n\t\tint count = 0;\n\t\tfor (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {\n\t\t\tg[i][j] = count;\n\t\t\tgx[count] = j;\n\t\t\tgy[count] = i;\n\t\t\tcount++;\n\t\t}\n\n//\t\tsout(a);\n//\t\tSystem.out.println(\"!!!\");\n\n\t\tfor (int i = 0; i < 4*n; i++) {\n\t\t\twhile (true) {\n//\t\t\t\tsout(a);\n\t\t\t\tint x = 0;\n\t\t\t\tint y = 0;\n\t\t\t\tF: for (; x < n; x++) for (y = 0; y < n; y++) {\n\t\t\t\t\tif (a[y][x] == i) break F;\n\t\t\t\t}\n//\t\t\t\tSystem.out.println(x + \" \" + y + \" \" + a[x][y] + \" \" + a[1][1]);\n\t\t\t\tif (g[y][x] == i) break;\n\t\t\t\tif (x != gx[i]) {\n\t\t\t\t\tif (y == 5) rotate(x, y, false, false, true);\n\t\t\t\t\telse left(x, y);\n\t\t\t\t}\n\t\t\t\telse up(x, y);\n\t\t\t}\n\t\t}\n\n//\t\tSystem.out.println(\"!!! 24\");\n\n\t\tfor (int i = 0; i < 4; i++) for (int t = 4*n + i; t <= 5*n + i; t += n) {\n//\t\t\tSystem.out.println(t);\n//\t\t\tsout(a);\n\t\t\twhile (true) {\n\t\t\t\tint x = 0;\n\t\t\t\tint y = 0;\n\t\t\t\tF: for (; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == t) break F;\n\t\t\t\tif (g[y][x] == t) break;\n\n\t\t\t\tif (y != gy[t]) {\n\t\t\t\t\tif (x == 5) {\n\t\t\t\t\t\tif (y < gy[t]) rotate(x, y, false, true, true);\n\t\t\t\t\t\telse rotate(x, y, false, false, false);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (y < gy[t]) rotate(x, y, true, true, false);\n\t\t\t\t\t\telse rotate(x, y, true, false, true);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (y == 4) rotate(x, y, false, true, false);\n\t\t\t\t\telse rotate(x, y, false, false, true);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\twhile (a[4][4] != 28 || a[4][5] != 29 || a[5][4] != 34 || a[5][5] != 35) {\n\t\t\tint i = ((int)(Math.random() * 1e9)) % 4;\n\t\t\tint j = ((int)(Math.random() * 1e9)) % 2;\n\t\t\tif (i == 0) rotate(4, 4, true, true, j == 0);\n\t\t\tif (i == 1) rotate(4, 5, true, false, j == 0);\n\t\t\tif (i == 2) rotate(5, 4, false, true, j == 0);\n\t\t\tif (i == 3) rotate(5, 5, false, false, j == 0);\n\t\t}\n\n/*\t\tint x = 0;\n\t\tint y = 0;\n\t\tF: for (x = 0; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == 28) break F;\n\t\tif (x == 5 && y == 5) rotate(x, y, false, false, true);\n\t\tF: for (x = 0; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == 28) break F;\n\t\tif (x == 5) rotate(x, y, false, true, false);\n\t\tF: for (x = 0; x < n; x++) for (y = 0; y < n; y++) if (a[y][x] == 28) break F;\n\t\tif (y == 5) rotate(x, y, true, false, true);\n\n//\t\tsout(a);\n\n\t\twhile (a[5][5] != g[5][5]) rotate(5, 5, false, false, true);*/\n\n\t\tout.println(answ.size());\n\t\tfor (String s : answ) out.println(s);\n\n//\t\tsout(a);\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a81b441fbff1f74cb76150ca007aafce", "src_uid": "10b2c1c53580dd382c41a56f7413e709", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "// package cf1181;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.function.BiFunction;\nimport java.util.function.BiPredicate;\nimport java.util.function.BinaryOperator;\nimport java.util.function.Function;\n\nimport static java.util.Comparator.comparingInt;\n\npublic class CFE2 {\n private static final String INPUT = \"14\\n\" +\n \"4 17 6 20\\n\" +\n \"9 17 10 20\\n\" +\n \"12 17 20 18\\n\" +\n \"10 15 11 16\\n\" +\n \"0 11 3 20\\n\" +\n \"10 13 11 14\\n\" +\n \"11 4 16 15\\n\" +\n \"11 18 19 20\\n\" +\n \"4 5 10 15\\n\" +\n \"10 4 11 13\\n\" +\n \"0 0 16 3\\n\" +\n \"17 0 20 16\\n\" +\n \"0 7 3 8\\n\" +\n \"0 4 3 6\";\n private static final int MOD = 1_000_000_007;\n\n private PrintWriter out;\n private FastScanner sc;\n\n public static void main(String[] args) {\n new CFE2().run();\n }\n\n public void run() {\n sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));\n out = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n solve();\n out.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n\n static class Rect {\n int x1, y1, x2, y2;\n boolean used;\n\n public Rect(int x1, int y1, int x2, int y2) {\n this.x1 = x1;\n this.y1 = y1;\n this.x2 = x2;\n this.y2 = y2;\n }\n\n @Override\n public String toString() {\n return \"{\" + x1 + \",\" + y1 + \"-\" + x2 + \",\" + y2 + \"}\";\n }\n }\n\n static class Node {\n private Rect rect;\n private Node next;\n\n public Node(Rect rect) {\n this.rect = rect;\n }\n }\n\n static interface AreaFunc {\n int area(int area, Rect rect);\n\n default int _area(Rect rect) {\n int a1 = area(-1, rect);\n int a2 = area(Integer.MAX_VALUE, rect);\n\n return (a1 > -1) ? a1 : a2;\n }\n }\n\n static class Rects {\n private final AreaFunc areaFunc;\n private final BiPredicate isSpace;\n\n Node root;\n Node curr;\n\n int currIdx;\n int area;\n\n public Rects(List rects, Comparator cmp, AreaFunc areaFunc, BiPredicate isSpace) {\n this.areaFunc = areaFunc;\n this.isSpace = isSpace;\n rects.sort(cmp);\n root = new Node(rects.get(0));\n Node cur = root;\n for (int i = 1; i < rects.size(); i++) {\n Rect rect = rects.get(i);\n Node node = new Node(rect);\n cur.next = node;\n cur = node;\n }\n\n init();\n }\n\n private void init() {\n while (root.rect.used) root = root.next;\n curr = root;\n area = areaFunc._area(root.rect);\n currIdx = 1;\n }\n\n public void next() {\n Node prev = curr;\n Node next = prev.next;\n while (next.rect.used) {\n next = next.next;\n }\n prev.next = next;\n curr = next;\n currIdx++;\n }\n\n public boolean isSpace() {\n boolean test = isSpace.test(area, curr.rect);\n if (!test) area = areaFunc.area(area, curr.rect);\n return test;\n }\n\n List drain() {\n Node node = root;\n List res = new ArrayList<>(currIdx-1);\n for (int i = 1; i < currIdx; i++) {\n res.add(node.rect);\n node = node.next;\n }\n return res;\n }\n\n @Override\n public String toString() {\n Node node = root;\n StringBuilder res = new StringBuilder();\n while (node != null) {\n res.append(node.rect).append(\" \");\n node = node.next;\n }\n return res.toString();\n }\n }\n\n static class Solver {\n int size;\n Rects[] rects = new Rects[4];\n\n public Solver(List list) {\n size = list.size();\n if (size >= 4) {\n rects[0] = new Rects(list, comparingInt((Rect r) -> r.x1), (area, r) -> Math.max(area, r.x2), (a, r) -> a <= r.x1);\n rects[1] = new Rects(list, comparingInt((Rect r) -> -r.x2), (area, r) -> Math.min(area, r.x1), (a, r) -> a >= r.x2);\n rects[2] = new Rects(list, comparingInt((Rect r) -> r.y1), (area, r) -> Math.max(area, r.y2), (a, r) -> a <= r.y1);\n rects[3] = new Rects(list, comparingInt((Rect r) -> -r.y2), (area, r) -> Math.min(area, r.y1), (a, r) -> a >= r.y2);\n } else {\n rects[0] = new Rects(list, comparingInt((Rect r) -> r.x1), (area, r) -> Math.max(area, r.x2), (a, r) -> a <= r.x1);\n }\n }\n\n boolean solve() {\n LOOP: while (size >= 4 && (rects[0].currIdx << 1) <= size) {\n for (int i = 0; i < 4; i++) {\n Rects rect = rects[i];\n rect.next();\n if (rect.isSpace()) {\n List drain = rect.drain();\n size -= drain.size();\n boolean solve = new Solver(drain).solve();\n if (!solve) return false;\n\n for (int j = 0; j < 4; j++) {\n rects[j].init();\n }\n continue LOOP;\n }\n }\n }\n\n if (size < 4) {\n for (Node node = rects[0].root; node != null; node = node.next) {\n node.rect.used = true;\n }\n return true;\n }\n return false;\n }\n }\n\n public void solve() {\n int n = sc.nextInt();\n List list = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n Rect rect = new Rect(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());\n list.add(rect);\n }\n\n Solver solver = new Solver(list);\n System.out.println(solver.solve() ? \"YES\" : \"NO\");\n\n }\n\n//********************************************************************************************\n//********************************************************************************************\n//********************************************************************************************\n\n static class SolutionFailedException extends Exception {\n int code;\n\n public SolutionFailedException(int code) {\n this.code = code;\n }\n }\n\n private static void shuffle(int[] array) {\n Random random = new Random();\n for (int i = array.length - 1; i > 0; i--) {\n int index = random.nextInt(i + 1);\n int temp = array[index];\n array[index] = array[i];\n array[i] = temp;\n }\n }\n\n /**\n * If searched element doesn't exist, returns index of first element which is bigger than searched value.
\n * If searched element is bigger than any array element function returns first index after last element.
\n * If searched element is lower than any array element function returns index of first element.
\n * If there are many values equals searched value function returns first occurrence.
\n */\n private static int lowerBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key <= arr[mid]) {\n hi = mid - 1;\n } else {\n lo = mid + 1;\n }\n }\n return arr[lo] < key ? lo + 1 : lo;\n }\n\n /**\n * Returns index of first element which is grater than searched value.\n * If searched element is bigger than any array element, returns first index after last element.\n */\n private static int upperBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key >= arr[mid]) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return arr[lo] <= key ? lo + 1 : lo;\n }\n\n private static int ceil(double d) {\n int ret = (int) d;\n return ret == d ? ret : ret + 1;\n }\n\n private static int round(double d) {\n return (int) (d + 0.5);\n }\n\n private static int gcd(int a, int b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.intValue();\n }\n\n private static long gcd(long a, long b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.longValue();\n }\n\n private int[] readIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextInt();\n }\n return res;\n }\n\n private long[] readLongArray(int n) {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextLong();\n }\n return res;\n }\n\n @SuppressWarnings(\"unused\")\n static class FastScanner {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n FastScanner(InputStream stream) {\n this.stream = stream;\n }\n\n int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) return -1;\n }\n return buf[curChar++];\n }\n\n boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n boolean isEndline(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c)) c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isEndline(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndline(c));\n return res.toString();\n }\n\n }\n\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private void tr(Object... o) {\n if (!oj) System.out.println(Arrays.deepToString(o));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7fc22c902666b15e4626a6e653857243", "src_uid": "5bfb165b4efe081d6a8c4843f7769a37", "difficulty": 3000.0} {"lang": "Java 8", "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 hEnd = HE();\n\t\tTreeSet hStart = HS();\n\t\tTreeSet vEnd = VE();\n\t\tTreeSet 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 he, TreeSet hs, TreeSet ve, TreeSet vs) {\n\t\tif(he.size() <= 2) return true; // Always possible with just 2 things\n\t\t\n\t\tTreeSet lhe = HE();\n\t\tTreeSet lhs = HS();\n\t\tTreeSet lve = VE();\n\t\tTreeSet lvs = VS();\n\t\t\n\t\tTreeSet rhe = HE();\n\t\tTreeSet rhs = HS();\n\t\tTreeSet rve = VE();\n\t\tTreeSet rvs = VS();\n\t\t\n\t\tTreeSet lhe2 = HE();\n\t\tTreeSet lhs2 = HS();\n\t\tTreeSet lve2 = VE();\n\t\tTreeSet lvs2 = VS();\n\t\t\n\t\tTreeSet rhe2 = HE();\n\t\tTreeSet rhs2 = HS();\n\t\tTreeSet rve2 = VE();\n\t\tTreeSet 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 HE() {\n\t\treturn new TreeSet((a,b) -> (a.x2 == b.x2 ? a.id-b.id : a.x2-b.x2));\n\t}\n\tstatic TreeSet HS(){\n\t\treturn new TreeSet((a,b) -> (a.x1 == b.x1 ? a.id-b.id : a.x1-b.x1));\t\t\n\t}\n\tstatic TreeSet VE(){\n\t\treturn new TreeSet((a,b) -> (a.y2 == b.y2 ? a.id-b.id : a.y2-b.y2));\n\t}\n\tstatic TreeSet VS(){\n\t\treturn new TreeSet((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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "946a3b6f7eb007c0373c2c127d920a61", "src_uid": "5bfb165b4efe081d6a8c4843f7769a37", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "// package cf1181;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.util.Comparator.comparingInt;\n\npublic class CFE1 {\n private static final String INPUT = \"4\\n\" +\n \"0 0 1 2\\n\" +\n \"0 2 1 3\\n\" +\n \"1 0 2 1\\n\" +\n \"1 1 2 3\";\n private static final int MOD = 1_000_000_007;\n\n private PrintWriter out;\n private FastScanner sc;\n\n public static void main(String[] args) {\n new CFE1().run();\n }\n\n public void run() {\n sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));\n out = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n solve();\n out.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n\n static class Rect {\n int x1, y1, x2, y2;\n\n public Rect(int x1, int y1, int x2, int y2) {\n this.x1 = x1;\n this.y1 = y1;\n this.x2 = x2;\n this.y2 = y2;\n }\n\n @Override\n public String toString() {\n return \"{\" + x1 + \",\" + y1 + \"-\" + x2 + \",\" + y2 + \"}\";\n }\n }\n\n public void solve() {\n int n = sc.nextInt();\n Set set = new TreeSet<>(comparingInt((Rect r) -> r.x1).thenComparingInt(r -> r.y1));\n for (int i = 0; i < n; i++) {\n Rect rect = new Rect(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());\n set.add(rect);\n }\n\n int sol = solve(set);\n System.out.println(sol == n ? \"YES\" : \"NO\");\n }\n\n private int solve(Set set) {\n if (set.size() < 4) return set.size();\n if (list.size() > 4) out.println(\"x: \" + list.size());\n return _solve(set);\n }\n\n static class Recter {\n int i;\n Set set;\n Iterator it;\n Rect rect;\n int area;\n\n public Recter(Set set) {\n this.i = 1;\n this.set = set;\n it = set.iterator();\n rect = it.next();\n }\n\n Rect next() {\n i++;\n return rect = it.next();\n }\n\n int size() {\n return set.size();\n }\n\n Set drain() {\n Set res = new TreeSet<>(comparingInt((Rect r) -> r.x1).thenComparingInt(r -> r.y1));\n Iterator resIt = set.iterator();\n for (int i = 0; i < this.i-1; i++) {\n res.add(resIt.next());\n resIt.remove();\n }\n\n it = set.iterator();\n rect = it.next();\n i = 1;\n return res;\n }\n\n void clear(Set rects) {\n for (Rect r : rects) {\n set.remove(r);\n }\n it = set.iterator();\n rect = it.next();\n i = 1;\n }\n }\n\n private int _solve(Set setX1) {\n Recter rX1 = new Recter(setX1);\n TreeSet setX2 = new TreeSet<>(comparingInt((Rect r1) -> -r1.x2).thenComparingInt(r1 -> -r1.y2));\n setX2.addAll(setX1);\n Recter rX2 = new Recter(setX2);\n\n TreeSet setY1 = new TreeSet<>(comparingInt((Rect r1) -> r1.y1).thenComparingInt(r1 -> r1.x1));\n setY1.addAll(setX1);\n Recter rY1 = new Recter(setY1);\n\n TreeSet setY2 = new TreeSet<>(comparingInt((Rect r) -> -r.y2).thenComparingInt(r -> -r.x2));\n setY2.addAll(setX1);\n Recter rY2 = new Recter(setY2);\n\n int result = 0;\n rX1.area = rX1.rect.x2;\n rX2.area = rX2.rect.x1;\n rY1.area = rY1.rect.y2;\n rY2.area = rY1.rect.y1;\n while (rX1.size() >= 4 && (rX1.i + rX2.i) <= rX1.size()) {\n rX1.next();\n if (rX1.rect.x1 >= rX1.area) {\n int n = rX1.i - 1;\n Set set = rX1.drain();\n rX1.area = rX1.rect.x2;\n\n rX2.clear(set);\n rX2.area = rX2.rect.x1;\n\n rY1.clear(set);\n rY1.area = rY1.rect.y2;\n\n rY2.clear(set);\n rY2.area = rY2.rect.y1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rX1.area = Math.max(rX1.area, rX1.rect.x2);\n }\n\n rX2.next();\n if (rX2.rect.x2 <= rX2.area) {\n int n = rX2.i - 1;\n Set set = rX2.drain();\n rX2.area = rX2.rect.x1;\n\n rX1.clear(set);\n rX1.area = rX1.rect.x2;\n\n rY1.clear(set);\n rY1.area = rY1.rect.y2;\n\n rY2.clear(set);\n rY2.area = rY2.rect.y1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rX2.area = Math.min(rX2.area, rX2.rect.x1);\n }\n\n rY1.next();\n if (rY1.rect.y1 >= rY1.area) {\n int n = rY1.i - 1;\n Set set = rY1.drain();\n rY1.area = rY1.rect.y2;\n\n rY2.clear(set);\n rY2.area = rY2.rect.y1;\n\n rX1.clear(set);\n rX1.area = rX1.rect.x2;\n\n rX2.clear(set);\n rX2.area = rX2.rect.x1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rY1.area = Math.max(rY1.area, rY1.rect.y2);\n }\n\n rY2.next();\n if (rY2.rect.y2 <= rY2.area) {\n int n = rY2.i - 1;\n Set set = rY2.drain();\n rY2.area = rY2.rect.y1;\n\n rY1.clear(set);\n rY1.area = rY1.rect.y2;\n\n rX1.clear(set);\n rX1.area = rX1.rect.x2;\n\n rX2.clear(set);\n rX2.area = rX2.rect.x1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rY2.area = Math.min(rY2.area, rY2.rect.y1);\n }\n }\n if (result == 0) {\n return 0;\n } else {\n return result + solve(setX1);\n }\n }\n\n//********************************************************************************************\n//********************************************************************************************\n//********************************************************************************************\n\n static class SolutionFailedException extends Exception {\n int code;\n\n public SolutionFailedException(int code) {\n this.code = code;\n }\n }\n\n private static void shuffle(int[] array) {\n Random random = new Random();\n for (int i = array.length - 1; i > 0; i--) {\n int index = random.nextInt(i + 1);\n int temp = array[index];\n array[index] = array[i];\n array[i] = temp;\n }\n }\n\n /**\n * If searched element doesn't exist, returns index of first element which is bigger than searched value.
\n * If searched element is bigger than any array element function returns first index after last element.
\n * If searched element is lower than any array element function returns index of first element.
\n * If there are many values equals searched value function returns first occurrence.
\n */\n private static int lowerBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key <= arr[mid]) {\n hi = mid - 1;\n } else {\n lo = mid + 1;\n }\n }\n return arr[lo] < key ? lo + 1 : lo;\n }\n\n /**\n * Returns index of first element which is grater than searched value.\n * If searched element is bigger than any array element, returns first index after last element.\n */\n private static int upperBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key >= arr[mid]) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return arr[lo] <= key ? lo + 1 : lo;\n }\n\n private static int ceil(double d) {\n int ret = (int) d;\n return ret == d ? ret : ret + 1;\n }\n\n private static int round(double d) {\n return (int) (d + 0.5);\n }\n\n private static int gcd(int a, int b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.intValue();\n }\n\n private static long gcd(long a, long b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.longValue();\n }\n\n private int[] readIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextInt();\n }\n return res;\n }\n\n private long[] readLongArray(int n) {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextLong();\n }\n return res;\n }\n\n @SuppressWarnings(\"unused\")\n static class FastScanner {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n FastScanner(InputStream stream) {\n this.stream = stream;\n }\n\n int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) return -1;\n }\n return buf[curChar++];\n }\n\n boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n boolean isEndline(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c)) c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isEndline(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndline(c));\n return res.toString();\n }\n\n }\n\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private void tr(Object... o) {\n if (!oj) System.out.println(Arrays.deepToString(o));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "243109330d8ec78459393806974b43cc", "src_uid": "5bfb165b4efe081d6a8c4843f7769a37", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "// package cf1181;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.function.BiFunction;\nimport java.util.function.BiPredicate;\nimport java.util.function.BinaryOperator;\nimport java.util.function.Function;\n\nimport static java.util.Comparator.comparingInt;\n\npublic class CFE2 {\n private static final String INPUT = \"14\\n\" +\n \"4 17 6 20\\n\" +\n \"9 17 10 20\\n\" +\n \"12 17 20 18\\n\" +\n \"10 15 11 16\\n\" +\n \"0 11 3 20\\n\" +\n \"10 13 11 14\\n\" +\n \"11 4 16 15\\n\" +\n \"11 18 19 20\\n\" +\n \"4 5 10 15\\n\" +\n \"10 4 11 13\\n\" +\n \"0 0 16 3\\n\" +\n \"17 0 20 16\\n\" +\n \"0 7 3 8\\n\" +\n \"0 4 3 6\";\n private static final int MOD = 1_000_000_007;\n\n private PrintWriter out;\n private FastScanner sc;\n\n public static void main(String[] args) {\n new CFE2().run();\n }\n\n public void run() {\n sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));\n out = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n solve();\n out.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n\n static class Rect {\n int x1, y1, x2, y2;\n boolean used;\n\n public Rect(int x1, int y1, int x2, int y2) {\n this.x1 = x1;\n this.y1 = y1;\n this.x2 = x2;\n this.y2 = y2;\n }\n\n @Override\n public String toString() {\n return \"{\" + x1 + \",\" + y1 + \"-\" + x2 + \",\" + y2 + \"}\";\n }\n }\n\n static class Node {\n private Rect rect;\n private Node next;\n\n public Node(Rect rect) {\n this.rect = rect;\n }\n }\n\n static interface AreaFunc {\n int area(int area, Rect rect);\n\n default int _area(Rect rect) {\n int a1 = area(-1, rect);\n int a2 = area(Integer.MAX_VALUE, rect);\n\n return (a1 > -1) ? a1 : a2;\n }\n }\n\n static class Rects {\n private final AreaFunc areaFunc;\n private final BiPredicate isSpace;\n\n Node root;\n Node curr;\n\n int currIdx;\n int area;\n\n public Rects(List rects, Comparator cmp, AreaFunc areaFunc, BiPredicate isSpace) {\n this.areaFunc = areaFunc;\n this.isSpace = isSpace;\n rects.sort(cmp);\n root = new Node(rects.get(0));\n Node cur = root;\n for (int i = 1; i < rects.size(); i++) {\n Rect rect = rects.get(i);\n Node node = new Node(rect);\n cur.next = node;\n cur = node;\n }\n\n init();\n }\n\n private void init() {\n while (root.rect.used) root = root.next;\n curr = root;\n area = areaFunc._area(root.rect);\n currIdx = 1;\n }\n\n public void next() {\n curr = curr.next;\n while (curr.rect.used) curr = curr.next;\n currIdx++;\n }\n\n public boolean isSpace() {\n boolean test = isSpace.test(area, curr.rect);\n if (!test) area = areaFunc.area(area, curr.rect);\n return test;\n }\n\n List drain() {\n Node node = root;\n List res = new ArrayList<>(currIdx-1);\n for (int i = 1; i < currIdx; i++) {\n res.add(node.rect);\n node = node.next;\n }\n return res;\n }\n\n @Override\n public String toString() {\n Node node = root;\n StringBuilder res = new StringBuilder();\n while (node != null) {\n res.append(node.rect).append(\" \");\n node = node.next;\n }\n return res.toString();\n }\n }\n\n static class Solver {\n int size;\n Rects[] rects = new Rects[4];\n\n public Solver(List list) {\n size = list.size();\n if (size >= 4) {\n rects[0] = new Rects(list, comparingInt((Rect r) -> r.x1), (area, r) -> Math.max(area, r.x2), (a, r) -> a <= r.x1);\n rects[1] = new Rects(list, comparingInt((Rect r) -> -r.x2), (area, r) -> Math.min(area, r.x1), (a, r) -> a >= r.x2);\n rects[2] = new Rects(list, comparingInt((Rect r) -> r.y1), (area, r) -> Math.max(area, r.y2), (a, r) -> a <= r.y1);\n rects[3] = new Rects(list, comparingInt((Rect r) -> -r.y2), (area, r) -> Math.min(area, r.y1), (a, r) -> a >= r.y2);\n } else {\n for (Rect rect : list) {\n rect.used = true;\n }\n }\n }\n\n boolean solve() {\n if (size < 4) {\n return true;\n }\n return _solve();\n }\n\n boolean _solve() {\n LOOP: while (size >= 4 && (rects[0].currIdx << 1) <= size) {\n for (int i = 0; i < 4; i++) {\n Rects rect = rects[i];\n rect.next();\n if (rect.isSpace()) {\n List drain = rect.drain();\n size -= drain.size();\n boolean solve = new Solver(drain).solve();\n if (!solve) return false;\n\n for (int j = 0; j < 4; j++) {\n rects[j].init();\n }\n continue LOOP;\n }\n }\n }\n return size < 4;\n }\n }\n\n public void solve() {\n int n = sc.nextInt();\n List list = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n Rect rect = new Rect(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());\n list.add(rect);\n }\n\n Solver solver = new Solver(list);\n System.out.println(solver.solve() ? \"YES\" : \"NO\");\n\n }\n\n//********************************************************************************************\n//********************************************************************************************\n//********************************************************************************************\n\n static class SolutionFailedException extends Exception {\n int code;\n\n public SolutionFailedException(int code) {\n this.code = code;\n }\n }\n\n private static void shuffle(int[] array) {\n Random random = new Random();\n for (int i = array.length - 1; i > 0; i--) {\n int index = random.nextInt(i + 1);\n int temp = array[index];\n array[index] = array[i];\n array[i] = temp;\n }\n }\n\n /**\n * If searched element doesn't exist, returns index of first element which is bigger than searched value.
\n * If searched element is bigger than any array element function returns first index after last element.
\n * If searched element is lower than any array element function returns index of first element.
\n * If there are many values equals searched value function returns first occurrence.
\n */\n private static int lowerBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key <= arr[mid]) {\n hi = mid - 1;\n } else {\n lo = mid + 1;\n }\n }\n return arr[lo] < key ? lo + 1 : lo;\n }\n\n /**\n * Returns index of first element which is grater than searched value.\n * If searched element is bigger than any array element, returns first index after last element.\n */\n private static int upperBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key >= arr[mid]) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return arr[lo] <= key ? lo + 1 : lo;\n }\n\n private static int ceil(double d) {\n int ret = (int) d;\n return ret == d ? ret : ret + 1;\n }\n\n private static int round(double d) {\n return (int) (d + 0.5);\n }\n\n private static int gcd(int a, int b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.intValue();\n }\n\n private static long gcd(long a, long b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.longValue();\n }\n\n private int[] readIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextInt();\n }\n return res;\n }\n\n private long[] readLongArray(int n) {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextLong();\n }\n return res;\n }\n\n @SuppressWarnings(\"unused\")\n static class FastScanner {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n FastScanner(InputStream stream) {\n this.stream = stream;\n }\n\n int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) return -1;\n }\n return buf[curChar++];\n }\n\n boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n boolean isEndline(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c)) c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isEndline(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndline(c));\n return res.toString();\n }\n\n }\n\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private void tr(Object... o) {\n if (!oj) System.out.println(Arrays.deepToString(o));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c74eb81d84a55aa781764106ffd1324", "src_uid": "5bfb165b4efe081d6a8c4843f7769a37", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF273D extends PrintWriter {\n\tCF273D() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF273D o = new CF273D(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 1000000007;\n\tint query(int[][] aa, int l0, int l1, int r0, int r1) {\n\t\treturn l0 > l1 || r0 > r1 ? 0 : (int) ((long) aa[l1][r1] - aa[l0 - 1][r1] - aa[l1][r0 - 1] + aa[l0 - 1][r0 - 1]) % MD;\n\t}\n\tvoid add(int[][] aa, int l, int r, int a) {\n\t\taa[l][r] = (aa[l][r] + a) % MD;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint[][] dp00 = new int[m + 1][m + 1];\n\t\tint[][] dp01 = new int[m + 1][m + 1];\n\t\tint[][] dp10 = new int[m + 1][m + 1];\n\t\tint[][] dp11 = new int[m + 1][m + 1];\n\t\tint[][] dq00 = new int[m + 1][m + 1];\n\t\tint[][] dq01 = new int[m + 1][m + 1];\n\t\tint[][] dq10 = new int[m + 1][m + 1];\n\t\tint[][] dq11 = new int[m + 1][m + 1];\n\t\tlong ans = 0;\n\t\twhile (n-- > 0) {\n\t\t\tfor (int l = 1; l <= m; l++)\n\t\t\t\tfor (int r = 1; r <= m; r++) {\n\t\t\t\t\tdp00[l][r] = (dp00[l][r] + dp00[l][r - 1]) % MD;\n\t\t\t\t\tdp01[l][r] = (dp01[l][r] + dp01[l][r - 1]) % MD;\n\t\t\t\t\tdp10[l][r] = (dp10[l][r] + dp10[l][r - 1]) % MD;\n\t\t\t\t\tdp11[l][r] = (dp11[l][r] + dp11[l][r - 1]) % MD;\n\t\t\t\t}\n\t\t\tfor (int l = 1; l <= m; l++)\n\t\t\t\tfor (int r = 1; r <= m; r++) {\n\t\t\t\t\tdp00[l][r] = (dp00[l][r] + dp00[l - 1][r]) % MD;\n\t\t\t\t\tdp01[l][r] = (dp01[l][r] + dp01[l - 1][r]) % MD;\n\t\t\t\t\tdp10[l][r] = (dp10[l][r] + dp10[l - 1][r]) % MD;\n\t\t\t\t\tdp11[l][r] = (dp11[l][r] + dp11[l - 1][r]) % MD;\n\t\t\t\t}\n\t\t\tfor (int l = 1; l <= m; l++)\n\t\t\t\tfor (int r = 1; r <= m; r++)\n\t\t\t\t\tdq00[l][r] = dq01[l][r] = dq10[l][r] = dq11[l][r] = 0;\n\t\t\tfor (int l = 1; l <= m; l++)\n\t\t\t\tfor (int r = l; r <= m; r++) {\n\t\t\t\t\tdq00[l][r] = 1;\n\t\t\t\t\tadd(dq00, l, r, query(dp00, l, m, 1, r));\n\t\t\t\t\tadd(dq01, l, r, query(dp01, l, r, r, m));\n\t\t\t\t\tadd(dq01, l, r, query(dp00, l, r, r + 1, m));\n\t\t\t\t\tadd(dq10, l, r, query(dp10, 1, l, l, r));\n\t\t\t\t\tadd(dq10, l, r, query(dp00, 1, l - 1, l, r));\n\t\t\t\t\tadd(dq11, l, r, query(dp11, 1, l, r, m));\n\t\t\t\t\tadd(dq11, l, r, query(dp01, 1, l - 1, r, m));\n\t\t\t\t\tadd(dq11, l, r, query(dp10, 1, l, r + 1, m));\n\t\t\t\t\tadd(dq11, l, r, query(dp00, 1, l - 1, r + 1, m));\n\t\t\t\t\tans = (ans + dq00[l][r] + dq01[l][r] + dq10[l][r] + dq11[l][r]) % MD;\n\t\t\t\t}\n\t\t\tint[][] tmp;\n\t\t\ttmp = dp00; dp00 = dq00; dq00 = tmp;\n\t\t\ttmp = dp01; dp01 = dq01; dq01 = tmp;\n\t\t\ttmp = dp10; dp10 = dq10; dq10 = tmp;\n\t\t\ttmp = dp11; dp11 = dq11; dq11 = tmp;\n\t\t}\n\t\tif (ans < 0)\n\t\t\tans += MD;\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b6e7bf9d9dfce85ee4e4b2edd4cbc4c", "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n out.println(solve(n, m));\n }\n\n static final int MOD = 1000000007;\n\n// static int solveStupid(int n, int m) {\n// int[][][][][] dp = new int[m][2][2][n][n];\n// for (int i = 0; i < n; i++) {\n// for (int j = i; j < n; j++) {\n// dp[0][0][0][i][j] = 1;\n// }\n// }\n// for (int s = 1; s < m; s++) {\n// for (int i = 0; i < n; i++) {\n// for (int j = 0; j < m; j++) {\n//\n// }\n// }\n// }\n// }\n\n static int solve(int n, int m) {\n int[][][][] dp = new int[2][2][n][n];\n int[][][][] next = new int[2][2][n][n];\n int ans = 0;\n for (int i = 0; i < m; i++) {\n for (int a = 0; a < 2; a++) {\n for (int b = 0; b < 2; b++) {\n makePart(dp[a][b], n, n);\n for (int[] d : next[a][b]) {\n Arrays.fill(d, 0);\n }\n }\n }\n {\n int[][] n00 = next[0][0];\n int[][] n01 = next[0][1];\n int[][] n10 = next[1][0];\n int[][] n11 = next[1][1];\n int[][] d00 = dp[0][0];\n int[][] d11 = dp[1][1];\n int[][] d10 = dp[1][0];\n int[][] d01 = dp[0][1];\n for (int c = 0; c < n; c++) {\n for (int d = c; d < n; d++) {\n n00[c][d] = getSum(d00, c, d + 1, c, d + 1);\n n01[c][d] = getSum(d00, c, d + 1, d + 1, n) + getSum(d01, c, d + 1, d, n);\n if (n01[c][d] >= MOD) {\n n01[c][d] -= MOD;\n }\n n10[c][d] = getSum(d00, 0, c, c, d + 1) + getSum(d10, 0, c + 1, c, d + 1);\n if (n10[c][d] >= MOD) {\n n10[c][d] -= MOD;\n }\n int z = getSum(d00, 0, c, d + 1, n) + getSum(d01, 0, c, d, n);\n if (z >= MOD) {\n z -= MOD;\n }\n z += getSum(d10, 0, c + 1, d + 1, n) + getSum(d11, 0, c + 1, d, n);\n if (z >= MOD) {\n z -= MOD;\n }\n n11[c][d] = z;\n }\n }\n }\n int[][] n00 = next[0][0];\n for (int c = 0; c < n; c++) {\n for (int d = c; d < n; d++) {\n n00[c][d]++;\n if (n00[c][d] >= MOD) {\n n00[c][d] -= MOD;\n }\n }\n }\n for (int a = 0; a < 2; a++) {\n for (int b = 0; b < 2; b++) {\n int[][] nab = next[a][b];\n for (int c = 0; c < n; c++) {\n for (int d = 0; d < n; d++) {\n ans += nab[c][d];\n if (ans >= MOD) {\n ans -= MOD;\n }\n }\n }\n }\n }\n int[][][][] t = dp;\n dp = next;\n next = t;\n }\n return ans;\n }\n\n static void makePart(int[][] a, int b, int c) {\n for (int i = 1; i < b; i++) {\n for (int j = 0; j < c; j++) {\n a[i][j] += a[i - 1][j];\n if (a[i][j] >= MOD) {\n a[i][j] -= MOD;\n }\n }\n }\n for (int i = 0; i < b; i++) {\n for (int j = 1; j < c; j++) {\n a[i][j] += a[i][j - 1];\n if (a[i][j] >= MOD) {\n a[i][j] -= MOD;\n }\n }\n }\n }\n\n static int getSum(int[][] a, int x1, int x2, int y1, int y2) {\n if (x1 >= x2 || y1 >= y2) return 0;\n int ret = a[x2 - 1][y2 - 1];\n if (x1 > 0) {\n ret -= a[x1 - 1][y2 - 1];\n if (ret < 0) ret += MOD;\n }\n if (y1 > 0) {\n ret -= a[x2 - 1][y1 - 1];\n if (ret < 0) ret += MOD;\n }\n if (x1 > 0 && y1 > 0) {\n ret += a[x1 - 1][y1 - 1];\n if (ret >= MOD) ret -= MOD;\n }\n return ret;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9585e842774ce585e864a29dd586a89a", "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CF273D {\n\n final static int mod = 1000000007;\n\n static int[][] sum(int[][] a) {\n int n = a.length;\n int m = a[0].length;\n int[][] r = new int[n + 1][m + 1];\n for (int i = 1; i <= n; ++i) {\n for (int j = 1; j <= m; ++j) {\n r[i][j] = (r[i - 1][j] + r[i][j - 1]) % mod;\n r[i][j] = (r[i][j] + a[i - 1][j - 1]) % mod;\n r[i][j] = (r[i][j] + mod - r[i - 1][j - 1]) % mod;\n }\n }\n return r;\n }\n\n private static int[][] clone(int[][] a) {\n int n = a.length;\n int m = a[0].length;\n int[][] r = new int[n][m];\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n r[i][j] = a[i][j];\n }\n }\n return r;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int m = in.nextInt();\n int[][] d00 = new int[m][m];\n int[][] d01 = new int[m][m];\n int[][] d10 = new int[m][m];\n int[][] d11 = new int[m][m];\n long ans = 0;\n for (int it = 0; it <= n; ++it) {\n int[][] s00 = sum(d00);\n int[][] s01 = sum(d01);\n int[][] s10 = sum(d10);\n int[][] s11 = sum(d11);\n// int[][] s00 = clone(d00);\n// int[][] s01 = clone(d01);\n// int[][] s10 = clone(d10);\n// int[][] s11 = clone(d11);\n for (int u = 0; u < m; ++u) {\n for (int v = u; v < m; ++v) {\n ans = (ans + d00[u][v]) % mod;\n ans = (ans + d01[u][v]) % mod;\n ans = (ans + d10[u][v]) % mod;\n ans = (ans + d11[u][v]) % mod;\n }\n }\n// System.err.println(Arrays.deepToString(d00));\n// System.err.println(Arrays.deepToString(d01));\n// System.err.println(Arrays.deepToString(d10));\n// System.err.println(Arrays.deepToString(d11));\n for (int u = 0; u < m; ++u) {\n for (int v = u; v < m; ++v) {\n d00[u][v] = d01[u][v] = d10[u][v] = d11[u][v] = 0;\n\n d00[u][v] = (d00[u][v] + sum(s00, u, m - 1, u, v));\n// for (int u1 = u; u1 < m; ++u1) {\n// for (int v1 = u1; v1 <= v; ++v1) {\n// d00[u][v] = (d00[u][v] + s00[u1][v1]) % mod;\n// }\n// }\n\n d01[u][v] = (d01[u][v] + sum(s00, u, v, v + 1, m - 1));\n// for (int u1 = u; u1 <= v; ++u1) {\n// for (int v1 = v + 1; v1 < m; ++v1) {\n// d01[u][v] = (d01[u][v] + s00[u1][v1]) % mod;\n// }\n// }\n d01[u][v] = (d01[u][v] + sum(s01, u, v, v, m - 1));\n// for (int u1 = u; u1 <= v; ++u1) {\n// for (int v1 = v; v1 < m; ++v1) {\n// d01[u][v] = (d01[u][v] + s01[u1][v1]) % mod;\n// }\n// }\n\n d10[u][v] = (d10[u][v] + sum(s00, 0, u - 1, u, v));\n// for (int u1 = 0; u1 < u; ++u1) {\n// for (int v1 = u; v1 <= v; ++v1) {\n// d10[u][v] = (d10[u][v] + s00[u1][v1]) % mod;\n// }\n// }\n d10[u][v] = (d10[u][v] + sum(s10, 0, u, u, v));\n// for (int u1 = 0; u1 <= u; ++u1) {\n// for (int v1 = u; v1 <= v; ++v1) {\n// d10[u][v] = (d10[u][v] + s10[u1][v1]) % mod;\n// }\n// }\n\n d11[u][v] = (d11[u][v] + sum(s00, 0, u - 1, v + 1, m - 1));\n// for (int u1 = 0; u1 < u; ++u1) {\n// for (int v1 = v + 1; v1 < m; ++v1) {\n// d11[u][v] = (d11[u][v] + s00[u1][v1]) % mod;\n// }\n// }\n d11[u][v] = (d11[u][v] + sum(s01, 0, u - 1, v, m - 1));\n// for (int u1 = 0; u1 < u; ++u1) {\n// for (int v1 = v; v1 < m; ++v1) {\n// d11[u][v] = (d11[u][v] + s01[u1][v1]) % mod;\n// }\n// }\n d11[u][v] = (d11[u][v] + sum(s10, 0, u, v + 1, m - 1));\n// for (int u1 = 0; u1 <= u; ++u1) {\n// for (int v1 = v + 1; v1 < m; ++v1) {\n// d11[u][v] = (d11[u][v] + s10[u1][v1]) % mod;\n// }\n// }\n d11[u][v] = (d11[u][v] + sum(s11, 0, u, v, m - 1));\n// for (int u1 = 0; u1 <= u; ++u1) {\n// for (int v1 = v; v1 < m; ++v1) {\n// d11[u][v] = (d11[u][v] + s11[u1][v1]) % mod;\n// }\n// }\n d00[u][v] = (d00[u][v] + 1) % mod;\n }\n }\n }\n out.println(ans);\n }\n\n private static int sum(int[][] s, int i1, int i2, int j1, int j2) {\n int r = s[i2 + 1][j2 + 1];\n r = (r + mod - s[i2 + 1][j1]) % mod;\n r = (r + mod - s[i1][j2 + 1]) % mod;\n r = (r + s[i1][j1]) % mod;\n return r;\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringTokenizer st;\n\n public Input(BufferedReader in) {\n this.in = in;\n eat(\"\");\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public void eat(String str) {\n st = new StringTokenizer(str);\n }\n\n public String next() throws IOException {\n while (!st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null) {\n return null;\n }\n eat(line);\n }\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64eb7338f9b4375ce6489963705f9988", "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n static final int MOD = 1000000007;\n\n public static int count(int height , int width) {\n boolean[][] field = new boolean[height][width];\n int[][][][] res = new int[2][2][width][width];\n int tR = 0;\n for (int row = 0; row < height; ++row) {\n int[][][][] newRes = new int[2][2][width][width];\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD)\n for (int fC = 0; fC < width; ++fC)\n for (int lC = fC; lC < width; ++lC) {\n int cur = res[fD][lD][fC][lC];\n if (cur == 0) continue;\n for (int newfD = fD; newfD < 2; ++newfD)\n for (int newlD = lD; newlD < 2; ++newlD) {\n int nF;\n if (newfD == 0)\n nF = fC;\n else if (fD == 0)\n nF = fC + 1;\n else\n nF = fC;\n int nL;\n if (newlD == 0)\n nL = lC;\n else if (lD == 0)\n nL = lC - 1;\n else\n nL = lC;\n if (nF > nL)\n continue;\n int[] arr = newRes[newfD][newlD][nF];\n arr[nL] += cur;\n if (arr[nL] >= MOD) arr[nL] -= MOD;\n }\n }\n\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD) {\n int[][] arr = newRes[fD][lD];\n if (fD == 0 && lD == 1) {\n {\n int lD = lD == 0 ? 1 : -1;\n int lM = lD == 1 ? 0 : width - 1;\n int lMax = lD == 1 ? width : -1;\n for (int lC = lM; lC != lMax; lC += lD) {\n for (int fC = 0; fC <= lC; ++fC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int nL = lC + lD;\n if (nL >= fC && nL < width) {\n arr[fC][nL] += cur;\n if (arr[fC][nL] >= MOD) arr[fC][nL] -= MOD;\n }\n }\n }\n }\n {\n int fD = fD == 0 ? -1 : 1;\n int fM = fD == 1 ? 0 : width - 1;\n int fM = fD == 1 ? width : -1;\n for (int fC = fM; fC != fM; fC += fD) {\n for (int lC = fC; lC < width; ++lC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int nF = fC + fD;\n if (nF >= 0 && nF <= lC) {\n arr[nF][lC] += cur;\n if (arr[nF][lC] >= MOD) arr[nF][lC] -= MOD;\n }\n }\n }\n }\n } else {\n {\n int fD = fD == 0 ? -1 : 1;\n int fM = fD == 1 ? 0 : width - 1;\n int fM = fD == 1 ? width : -1;\n for (int fC = fM; fC != fM; fC += fD) {\n for (int lC = fC; lC < width; ++lC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int nF = fC + fD;\n if (nF >= 0 && nF <= lC) {\n arr[nF][lC] += cur;\n if (arr[nF][lC] >= MOD) arr[nF][lC] -= MOD;\n }\n }\n }\n }\n {\n int lD = lD == 0 ? 1 : -1;\n int lM = lD == 1 ? 0 : width - 1;\n int lMax = lD == 1 ? width : -1;\n for (int lC = lM; lC != lMax; lC += lD) {\n for (int fC = 0; fC <= lC; ++fC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int nL = lC + lD;\n if (nL >= fC && nL < width) {\n arr[fC][nL] += cur;\n if (arr[fC][nL] >= MOD) arr[fC][nL] -= MOD;\n }\n }\n }\n }\n }\n }\n\n for (int fC = 0; fC < width; ++fC) {\n boolean ok = true;\n for (int lC = fC; lC < width; ++lC) {\n if (field[row][lC])\n ok = false;\n if (!ok) {\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD)\n newRes[fD][lD][fC][lC] = 0;\n } else {\n newRes[0][0][fC][lC] += 1;\n if (newRes[0][0][fC][lC] >= MOD) newRes[0][0][fC][lC] -= MOD;\n }\n }\n }\n\n res = newRes;\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD)\n for (int fC = 0; fC < width; ++fC)\n for (int lC = fC; lC < width; ++lC) {\n tR += res[fD][lD][fC][lC];\n if (tR >= MOD) tR -= MOD;\n }\n }\n return tR;\n }\n public static void main(String[] args){\n Scanner cin = new Scanner(System.in);\n int n = cin.nextInt() , m = cin.nextInt();\n System.out.println(count(n, m));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7db10551b2e267573a5ec5e373f127ae", "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.AbstractSet;\nimport java.util.InputMismatchException;\nimport java.util.Random;\nimport java.util.ArrayList;\nimport java.util.AbstractCollection;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.Collection;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.util.List;\nimport java.util.AbstractMap;\nimport java.io.Writer;\nimport java.util.Map.Entry;\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 aryssoncf\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n FShadyLady solver = new FShadyLady();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FShadyLady {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n int[] A = new int[n], B = new int[n];\n in.readIntArrays(A, B);\n int hasOrigin = 0;\n for (int i = 0; i < n; i++) {\n if (A[i] == 0 && B[i] == 0) {\n hasOrigin = 1;\n break;\n }\n }\n Point[] points = new Point[n + 1 - hasOrigin];\n Arrays.setAll(points, i -> (i < n ? new Point(A[i], B[i]) : Point.ORIGIN));\n Polygon total = Polygon.convexHull(points, true);\n boolean lose = check(total);\n Set even = new EHashSet<>(), odd = new EHashSet<>();\n for (int i = 0; i < total.vertices.length; i++) {\n Point P = total.vertices[i];\n if (P.equals(Point.ORIGIN)) {\n continue;\n }\n if (i % 2 == 0) {\n even.add(P);\n } else {\n odd.add(P);\n }\n }\n List notEven = new ArrayList(), notOdd = new ArrayList<>();\n for (Point P : points) {\n if (!even.contains(P)) {\n notEven.add(P);\n }\n if (!odd.contains(P)) {\n notOdd.add(P);\n }\n }\n Point[] notEvenArray = notEven.toArray(new Point[0]), notOddArray = notOdd.toArray(new Point[0]);\n Polygon notEvenPolygon = Polygon.convexHull(notEvenArray, true), notOddPolygon = Polygon.convexHull(notOddArray, true);\n lose |= check(notEvenPolygon);\n lose |= check(notOddPolygon);\n out.printLine(lose ? \"Ani\" : \"Borna\");\n }\n\n boolean check(Polygon poly) {\n for (Point p : poly.vertices) {\n long x = Math.round(p.x), y = Math.round(p.y);\n if (x % 2 == 1 || y % 2 == 1) {\n return true;\n }\n }\n return false;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n }\n\n static class Polygon {\n public final Point[] vertices;\n\n public Polygon(Point... vertices) {\n this.vertices = vertices.clone();\n }\n\n public static boolean over(Point a, Point b, Point c) {\n return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < -GeometryUtils.epsilon;\n }\n\n private static boolean under(Point a, Point b, Point c) {\n return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > GeometryUtils.epsilon;\n }\n\n public static Polygon convexHull(Point[] points, boolean strict) {\n if (points.length == 1) {\n return new Polygon(points);\n }\n Arrays.sort(points, Comparator.comparingDouble((Point o) -> o.x).thenComparingDouble(o -> o.y));\n Point left = points[0];\n Point right = points[points.length - 1];\n List up = new ArrayList<>();\n List down = new ArrayList<>();\n for (Point point : points) {\n if (point == left || point == right || (strict ? over(left, point, right) : !under(left, point, right))) {\n while (up.size() >= 2 && (strict ? !over(up.get(up.size() - 2), up.get(up.size() - 1), point) : under(up.get(up.size() - 2), up.get(up.size() - 1), point))) {\n up.remove(up.size() - 1);\n }\n up.add(point);\n }\n if (point == left || point == right || (strict ? under(left, point, right) : !over(left, point, right))) {\n while (down.size() >= 2 && (strict ? !under(down.get(down.size() - 2), down.get(down.size() - 1), point) : over(down.get(down.size() - 2), down.get(down.size() - 1), point))) {\n down.remove(down.size() - 1);\n }\n down.add(point);\n }\n }\n Point[] result = new Point[up.size() + down.size() - 2];\n int index = 0;\n for (Point point : up) {\n result[index++] = point;\n }\n for (int i = down.size() - 2; i > 0; i--) {\n result[index++] = down.get(i);\n }\n return new Polygon(result);\n }\n\n }\n\n static class EHashSet extends AbstractSet {\n private static final Object VALUE = new Object();\n private final Map map;\n\n public EHashSet() {\n this(4);\n }\n\n public EHashSet(int maxSize) {\n map = new EHashMap<>(maxSize);\n }\n\n public EHashSet(Collection collection) {\n this(collection.size());\n addAll(collection);\n }\n\n public boolean contains(Object o) {\n return map.containsKey(o);\n }\n\n public boolean add(E e) {\n if (e == null) {\n return false;\n }\n return map.put(e, VALUE) == null;\n }\n\n public boolean remove(Object o) {\n if (o == null) {\n return false;\n }\n return map.remove(o) != null;\n }\n\n public void clear() {\n map.clear();\n }\n\n public Iterator iterator() {\n return map.keySet().iterator();\n }\n\n public int size() {\n return map.size();\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public void readIntArrays(int[]... arrays) {\n for (int i = 0; i < arrays[0].length; i++) {\n for (int j = 0; j < arrays.length; j++) {\n arrays[j][i] = readInt();\n }\n }\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class EHashMap extends AbstractMap {\n private static final int[] shifts = new int[10];\n private int size;\n private EHashMap.HashEntry[] data;\n private int capacity;\n private Set> entrySet;\n\n static {\n Random random = new Random(System.currentTimeMillis());\n for (int i = 0; i < 10; i++) {\n shifts[i] = 1 + 3 * i + random.nextInt(3);\n }\n }\n\n public EHashMap() {\n this(4);\n }\n\n private void setCapacity(int size) {\n capacity = Integer.highestOneBit(4 * size);\n //noinspection unchecked\n data = new EHashMap.HashEntry[capacity];\n }\n\n public EHashMap(int maxSize) {\n setCapacity(maxSize);\n entrySet = new AbstractSet>() {\n\n public Iterator> iterator() {\n return new Iterator>() {\n private EHashMap.HashEntry last = null;\n private EHashMap.HashEntry current = null;\n private EHashMap.HashEntry base = null;\n private int lastIndex = -1;\n private int index = -1;\n\n public boolean hasNext() {\n if (current == null) {\n for (index++; index < capacity; index++) {\n if (data[index] != null) {\n base = current = data[index];\n break;\n }\n }\n }\n return current != null;\n }\n\n public Entry next() {\n if (!hasNext()) {\n throw new NoSuchElementException();\n }\n last = current;\n lastIndex = index;\n current = current.next;\n if (base.next != last) {\n base = base.next;\n }\n return last;\n }\n\n public void remove() {\n if (last == null) {\n throw new IllegalStateException();\n }\n size--;\n if (base == last) {\n data[lastIndex] = last.next;\n } else {\n base.next = last.next;\n }\n }\n };\n }\n\n\n public int size() {\n return size;\n }\n };\n }\n\n public EHashMap(Map map) {\n this(map.size());\n putAll(map);\n }\n\n public Set> entrySet() {\n return entrySet;\n }\n\n public void clear() {\n Arrays.fill(data, null);\n size = 0;\n }\n\n private int index(Object o) {\n return getHash(o.hashCode()) & (capacity - 1);\n }\n\n private int getHash(int h) {\n int result = h;\n for (int i : shifts) {\n result ^= h >>> i;\n }\n return result;\n }\n\n public V remove(Object o) {\n if (o == null) {\n return null;\n }\n int index = index(o);\n EHashMap.HashEntry current = data[index];\n EHashMap.HashEntry last = null;\n while (current != null) {\n if (current.key.equals(o)) {\n if (last == null) {\n data[index] = current.next;\n } else {\n last.next = current.next;\n }\n size--;\n return current.value;\n }\n last = current;\n current = current.next;\n }\n return null;\n }\n\n public V put(E e, V value) {\n if (e == null) {\n return null;\n }\n int index = index(e);\n EHashMap.HashEntry current = data[index];\n if (current != null) {\n while (true) {\n if (current.key.equals(e)) {\n V oldValue = current.value;\n current.value = value;\n return oldValue;\n }\n if (current.next == null) {\n break;\n }\n current = current.next;\n }\n }\n if (current == null) {\n data[index] = new EHashMap.HashEntry<>(e, value);\n } else {\n current.next = new EHashMap.HashEntry<>(e, value);\n }\n size++;\n if (2 * size > capacity) {\n EHashMap.HashEntry[] oldData = data;\n setCapacity(size);\n for (EHashMap.HashEntry entry : oldData) {\n while (entry != null) {\n EHashMap.HashEntry next = entry.next;\n index = index(entry.key);\n entry.next = data[index];\n data[index] = entry;\n entry = next;\n }\n }\n }\n return null;\n }\n\n public V get(Object o) {\n if (o == null) {\n return null;\n }\n int index = index(o);\n EHashMap.HashEntry current = data[index];\n while (current != null) {\n if (current.key.equals(o)) {\n return current.value;\n }\n current = current.next;\n }\n return null;\n }\n\n public boolean containsKey(Object o) {\n if (o == null) {\n return false;\n }\n int index = index(o);\n EHashMap.HashEntry current = data[index];\n while (current != null) {\n if (current.key.equals(o)) {\n return true;\n }\n current = current.next;\n }\n return false;\n }\n\n public int size() {\n return size;\n }\n\n private static class HashEntry implements Entry {\n private final E key;\n private V value;\n private EHashMap.HashEntry next;\n\n private HashEntry(E key, V value) {\n this.key = key;\n this.value = value;\n }\n\n public E getKey() {\n return key;\n }\n\n public V getValue() {\n return value;\n }\n\n public V setValue(V value) {\n V oldValue = this.value;\n this.value = value;\n return oldValue;\n }\n\n }\n\n }\n\n static class Point {\n public static final Point ORIGIN = new Point(0, 0);\n public final double x;\n public final double y;\n\n public String toString() {\n return \"(\" + x + \", \" + y + \")\";\n }\n\n public Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n\n Point point = (Point) o;\n\n return Math.abs(x - point.x) <= GeometryUtils.epsilon && Math.abs(y - point.y) <= GeometryUtils.epsilon;\n }\n\n public int hashCode() {\n int result;\n long temp;\n temp = x != +0.0d ? Double.doubleToLongBits(x) : 0L;\n result = (int) (temp ^ (temp >>> 32));\n temp = y != +0.0d ? Double.doubleToLongBits(y) : 0L;\n result = 31 * result + (int) (temp ^ (temp >>> 32));\n return result;\n }\n\n }\n\n static class GeometryUtils {\n public static double epsilon = 1e-8;\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e40b63fb0e1eac625d7c85bd66fb619", "src_uid": "a7b35fee982e41c075c87135a62c3a0d", "difficulty": 3400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\npublic class flags{\npublic static int mod = 1000000007,modi = (mod+1)>>1;\npublic static BigInteger modB = new BigInteger(\"1000000007\");\npublic static BigInteger modiB = new BigInteger(\"500000004\");\npublic static long id[][] ={{1,0,0,0,0,0,0},{0,1,0,0,0,0,0},{0,0,1,0,0,0,0},{0,0,0,1,0,0,0},{0,0,0,0,1,0,0},{0,0,0,0,0,1,0},{0,0,0,0,0,0,1}};\npublic static long a[][] = {{1,0,0,0,0,0,0},{1,0,0,0,0,0,0},{1,1,0,0,1,1,0},{1,1,0,0,1,0,1},{1,0,1,1,0,0,0},{0,0,1,0,0,0,0},{0,0,0,1,0,0,0}};//adyacencia aut\npublic static void main(String args[]) throws IOException{\nBufferedReader lector= new BufferedReader(new InputStreamReader(System.in));\n//for(int n = Integer.parseInt(args[0]);n<1000000001;n++)\nString tmp = lector.readLine();\nint n2 = Integer.parseInt(tmp.substring(0,tmp.indexOf(\" \")))-1;\nint n1 = Integer.parseInt(tmp.substring(tmp.indexOf(\" \")+1));\nBigInteger un = f(a,n1);\nBigInteger dos = f(a,n1/2+(n1&1));\nun = ((un.subtract(dos).multiply(modiB)).add(dos)).mod(modB);\nBigInteger un1 = f(a,n2);\nBigInteger dos1 = f(a,n2/2+(n2&1));\nun1 = ((un1.subtract(dos1).multiply(modiB)).add(dos1)).mod(modB);\nBigInteger joder = un.subtract(un1);\nSystem.out.println(joder);\n}\npublic static BigInteger f(long a[][],int n){\nlong p[][] = exp(a,n);\nBigInteger res = BigInteger.ZERO;\nint ri[] = {0,1,1,1,1,1,1};//terminales de cada nodo\nfor(int nn = 0;nn= 3 ? 6 * (mpow(3, (R - 1) / 2) - 1) : 0;\n\t\tlong add2 = R >= 4 ? 3 * (mpow(3, (R + 1) / 2) - 3) : 0;\n\t\treturn (res + add1 + add2) % MOD;\t\n\t}\n\n\tlong getGoodAll(int R) {\n\t\tif (R == 0) return 0;\n\t\tlong res = getAll(R);\n\t\tres += getAll((R + 1) / 2);\n\t\treturn res % MOD;\n\t}\n\n\tlong getGood(int n) {\n\t\tlong ret = get(n);\n\t\tif (n % 2 == 1) {\n\t\t\tret += get((n + 1) / 2);\n\t\t}\n\t\treturn ret / 2;\n\t}\n\t\n\tlong getY(int n) {\n\t\treturn n == 1 ? 1 : 2 * getK(n - 1);\n\t}\n\n\tlong getK(int n) {\n\t\tif (n % 2 == 0) {\n\t\t\treturn (2 * mpow(3, n / 2 - 1)) % MOD;\n\t\t} else {\n\t\t\treturn mpow(3, n / 2);\n\t\t}\n\t}\n\n\tlong mpow(long a, long n) {\n\t\tif (n == 0) return 1;\n\t\tlong ans = mpow(a, n / 2);\n\t\tans = (ans * ans) % MOD;\n\t\tif (n % 2 == 1) {\n\t\t\tans = (ans * a) % MOD;\n\t\t}\n\t\treturn ans;\n\t}\n\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Sol()).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\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\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "06628a8af8b82fd98b14ae9bf4df6288", "src_uid": "e04b6957d9c1659e9d2460410cb57f10", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.util.regex.*;\nimport java.io.*;\nimport java.math.BigInteger;\nimport static java.lang.Math.*;\n\npublic class Sol implements Runnable {\n\tfinal long MOD = 1000000007;\n\tlong half = (MOD + 1) / 2;\n\n\tvoid solve() throws Exception {\n\t\tint L = nextInt(), R = nextInt();\n\t\tlong ans = (((getGoodAll(R) - getGoodAll(L - 1) + MOD) * half) % MOD + MOD) % MOD;\n\t\tout.println(ans);\n\t}\n\n\tlong get(int n) {\n\t\treturn 2 * getK(n) + 2 * getY(n);\n\t}\n\n\tlong getAll(int R) {\n\t\tlong res = get(1);\n\t\tif (R == 1) return res;\n\t\tres += 2 * getK(R) + 4 * getK(1);\n\t\tres %= MOD;\n\t\tlong add1 = R >= 3 ? 6 * (mpow(3, (R - 1) / 2) - 1) : 0;\n\t\tlong add2 = R >= 4 ? 3 * (mpow(3, (R + 1) / 2) - 3) : 0;\n\t\treturn (res + add1 + add2) % MOD;\t\n\t}\n\n\tlong getGoodAll(int R) {\n\t\tif (R == 0) return 0;\n\t\tlong res = getAll(R);\n\t\tres += getAll((R + 1) / 2);\n\t\treturn res % MOD;\n\t}\n\n\tlong getGood(int n) {\n\t\tlong ret = get(n);\n\t\tif (n % 2 == 1) {\n\t\t\tret += get((n + 1) / 2);\n\t\t}\n\t\treturn ret / 2;\n\t}\n\t\n\tlong getY(int n) {\n\t\treturn n == 1 ? 1 : 2 * getK(n - 1);\n\t}\n\n\tlong getK(int n) {\n\t\tif (n % 2 == 0) {\n\t\t\treturn (2 * mpow(3, n / 2 - 1)) % MOD;\n\t\t} else {\n\t\t\treturn mpow(3, n / 2);\n\t\t}\n\t}\n\n\tlong mpow(long a, long n) {\n\t\tif (n == 0) return 1;\n\t\tlong ans = mpow(a, n / 2);\n\t\tans = (ans * ans) % MOD;\n\t\tif (n % 2 == 1) {\n\t\t\tans = (ans * a) % MOD;\n\t\t}\n\t\treturn ans;\n\t}\n\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Sol()).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\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\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6c233efdee0b28407e95360a3ec8f094", "src_uid": "e04b6957d9c1659e9d2460410cb57f10", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class CofeForces {\n public static void main(String[] args) throws FileNotFoundException {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n long n = in.nextLong(), m = in.nextLong(), a = in.nextLong(), b = in.nextLong();\n a--;\n b--;\n int ans = -1;\n if (a / m == b / m) ans = 1; else {\n a = a%m;\n if (a == 0 && b%m == (m-1)) ans = 1;\n else if (a == 0 && b == n-1) ans = 1;\n else if (a == 0 || b%m == (m-1) || b == n-1) ans = 2;\n else if ((a%m) == (b%m)+1) ans = 2;\n else ans = 3;\n }\n \n System.out.println( ans );\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e674a45549fc19accbe4147619531567", "src_uid": "e04b6957d9c1659e9d2460410cb57f10", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class _LiftLevel5E {\n\n\tstatic boolean[][] locked;\n\tstatic int[][] board;\n\tstatic int[][] solved;\n\tstatic int w, h;\n\tstatic ArrayList answer=new ArrayList<>();\n\t\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\th=fs.nextInt(); w=fs.nextInt();\n\t\tboard=new int[w][h];\n\t\tsolved=new int[w][h];\n\t\tlocked=new boolean[w][h];\n\t\tfor (int y=0; y=locked.length || y<0 || y>=locked[x].length) return false;\n\t\treturn !locked[x][y];\n\t}\n\t\n\t//moves x first then y\n\tstatic void naiveMoveToXFirst(int toMove, int targetX, int targetY) {\n\t\tPoint curPos=locationOf(toMove);\n\t\tint curX=curPos.x;\n\t\tint curY=curPos.y;\n\t\twhile (curXtargetX) {\n\t\t\tmoveLeft(curX, curY);\n\t\t\tcurX--;\n\t\t}\n\t\twhile (curYtargetY) {\n\t\t\tmoveUp(curX, curY);\n\t\t\tcurY--;\n\t\t}\n\t}\n\t\n\tstatic void moveLeft(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x-1, y)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x-1, y+1) && movable(x, y+1)) {\n\t\t\tmove(x, y, x-1, y, x-1, y+1, x, y+1);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x-1, y-1) && movable(x-1, y-1)) {\n\t\t\tmove(x, y, x-1, y, x-1, y-1, x, y-1);\n\t\t\treturn;\n\t\t}\n\t\tthrow null;\n\t}\n\t\n\tstatic void moveRight(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x+1, y)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x+1, y+1) && movable(x, y+1)) {\n\t\t\tmove(x, y, x+1, y, x+1, y+1, x, y+1);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x+1, y-1) && movable(x, y-1)) {\n\t\t\tmove(x, y, x+1, y, x+1, y-1, x, y-1);\n\t\t\treturn;\n\t\t}\n//\t\tSystem.out.println(\"Trying to move right on pos: \"+x+\" \"+y+\" but it is impossible\");\n//\t\tprint(locked);\n\t\tthrow null;\n\t}\n\t\n\tstatic void moveDown(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x, y+1)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x-1, y+1) && movable(x-1, y)) {\n\t\t\tmove(x, y, x, y+1, x-1, y+1, x-1, y);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x+1, y+1) && movable(x+1, y)) {\n\t\t\tmove(x, y, x, y+1, x+1, y+1, x+1, y);\n\t\t\treturn;\n\t\t}\n\t\tthrow null;\n\t}\n\n\tstatic void moveUp(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x, y-1)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x-1, y-1) && movable(x-1, y)) {\n\t\t\tmove(x, y, x, y-1, x-1, y-1, x-1, y);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x+1, y-1) && movable(x+1, y)) {\n\t\t\tmove(x, y, x, y-1, x+1, y-1, x+1, y);\n\t\t\treturn;\n\t\t}\n\t\tthrow null;\n\t}\n\t\n\tstatic void move(int ...input) {\n\t\tif (input.length%2!=0) throw null;\n\t\tint[] xs=new int[input.length/2], ys=new int[input.length/2];\n\t\tfor (int i=0; i li=new ArrayList<>();\r\n\t\t\r\n\t\twhile(n>0)\r\n\t\t{\r\n\t\t\tli.add(n%m);\r\n\t\t\t\r\n\t\t\tn=n/m;\r\n\t\t}\r\n \r\n\t\t\r\n\t\tHashSet set=new HashSet<>();\r\n\t\t\r\n\t\tfor(int i=0;i 0) {\r\n int d = n % m;\r\n if (used[d]) {\r\n valid = false;\r\n break;\r\n }\r\n used[d] = true;\r\n n /= m;\r\n }\r\n if(valid){\r\n out.println(\"YES\");\r\n }else {\r\n out.println(\"NO\");\r\n }\r\n out.close();\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f6c0676d4e3a64ffa97b3e51b6a181aa", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.nio.CharBuffer;\nimport java.util.NoSuchElementException;\n\npublic class P1505D {\n\n public static void main(String[] args) {\n SimpleScanner scanner = new SimpleScanner(System.in);\n PrintWriter writer = new PrintWriter(System.out);\n\n int n = scanner.nextInt();\n int m = scanner.nextInt();\n boolean[] used = new boolean[m];\n boolean valid = true;\n while (n > 0) {\n int d = n % m;\n if (used[d]) {\n valid = false;\n break;\n }\n used[d] = true;\n n /= m;\n }\n writer.println(valid ? \"YES\" : \"NO\");\n\n writer.close();\n }\n\n private static class SimpleScanner {\n\n private static final int BUFFER_SIZE = 10240;\n\n private Readable in;\n private CharBuffer buffer;\n private boolean eof;\n\n private SimpleScanner(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n buffer = CharBuffer.allocate(BUFFER_SIZE);\n buffer.limit(0);\n eof = false;\n }\n\n\n private char read() {\n if (!buffer.hasRemaining()) {\n buffer.clear();\n int n;\n try {\n n = in.read(buffer);\n } catch (IOException e) {\n n = -1;\n }\n if (n <= 0) {\n eof = true;\n return '\\0';\n }\n buffer.flip();\n }\n return buffer.get();\n }\n\n private void checkEof() {\n if (eof)\n throw new NoSuchElementException();\n }\n\n private char nextChar() {\n checkEof();\n char b = read();\n checkEof();\n return b;\n }\n\n private String next() {\n char b;\n do {\n b = read();\n checkEof();\n } while (Character.isWhitespace(b));\n StringBuilder sb = new StringBuilder();\n do {\n sb.append(b);\n b = read();\n } while (!eof && !Character.isWhitespace(b));\n return sb.toString();\n }\n\n private int nextInt() {\n return Integer.parseInt(next());\n }\n\n private long nextLong() {\n return Long.parseLong(next());\n }\n\n private double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "791852c453c9ed708631ea6fd133eef0", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "//https://codeforces.com/contest/1505/problem/D\r\n//D. Xenolith? Hippodrome?\r\nimport java.util.*;\r\nimport java.io.*;\r\npublic class CF_1505_D{\r\n\r\n\tstatic boolean check(int n, int m){\r\n\t\tboolean pres[] = new boolean[m];\r\n\r\n\t\twhile(n>0){\r\n\t\t\tint temp = n%m;\r\n\r\n\t\t\tif(pres[temp])\r\n\t\t\t\treturn false;\r\n\t\t\telse\r\n\t\t\t\tpres[temp] = true;\r\n\r\n\t\t\tn = n/m;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) throws Exception{\r\n\t\t\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tPrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n\t\tStringTokenizer st;\r\n\r\n\t\tst = new StringTokenizer(br.readLine().trim());\r\n\t\tint n = Integer.parseInt(st.nextToken());\r\n\t\tint m = Integer.parseInt(st.nextToken());\r\n\r\n\t\tboolean flag = check(n, m);\r\n\r\n\t\tif(flag)\r\n\t\t\tpw.print(\"YES\");\r\n\t\telse\r\n\t\t\tpw.print(\"NO\");\r\n\r\n\t\tpw.flush();\r\n\t\tpw.close();\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7bcea02df73debf995c09a1ecf7c92f3", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\n\npublic class CF392E {\n\n final static int MINF = -1000000000;\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int[] ws = new int[n + 1];\n for (int i = 1; i <= n; ++i) {\n ws[i] = in.nextInt();\n }\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n }\n int[][] d0 = new int[n][n];\n int[][] d1 = new int[n][n];\n for (int[] ar : d1) {\n Arrays.fill(ar, MINF);\n }\n for (int len = 1; len <= n; ++len) {\n for (int i = 0; i < n; ++i) {\n if (len == 1) {\n d1[i][i] = 0;\n } else {\n if (i - len + 1 >= 0) {\n int j = i - len + 1;\n d1[i][j] = MINF;\n for (int k = j + 1; k <= i; ++k) {\n if (a[j] + 1 == a[k] && d1[i][k] != MINF && d0[j + 1][k - 1] != MINF) {\n d1[i][j] = Math.max(d1[i][j], d1[i][k] + d0[j + 1][k - 1]);\n }\n }\n }\n if (i + len - 1 < n) {\n int j = i + len - 1;\n d1[i][j] = MINF;\n for (int k = i; k < j; ++k) {\n if (a[j] + 1 == a[k] && d1[i][k] != MINF && d0[k + 1][j - 1] != MINF) {\n d1[i][j] = Math.max(d1[i][j], d1[i][k] + d0[k + 1][j - 1]);\n }\n }\n }\n }\n }\n for (int i = 0; i + len <= n; ++i) {\n int j = i + len - 1;\n d0[i][j] = MINF;\n for (int k = i; k < j; ++k) {\n d0[i][j] = Math.max(d0[i][j], d0[i][k] + d0[k + 1][j]);\n }\n for (int k = i; k <= j; ++k) {\n if (d1[k][i] != MINF && d1[k][j] != MINF) {\n d0[i][j] = Math.max(d0[i][j], d1[k][i] + d1[k][j] + ws[2 * a[k] - a[i] - a[j] + 1]);\n }\n }\n }\n }\n out.println(d0[0][n - 1]);\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e8b0119d5ebd0e16cc99fd9671bb6c4c", "src_uid": "32fa5dbac37abe197a267a0fc7fe4006", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\n\npublic class CF392E {\n\n final static int MINF = -1000000000;\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int[] ws = new int[n + 1];\n for (int i = 1; i <= n; ++i) {\n ws[i] = in.nextInt();\n }\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n }\n int[][] d0 = new int[n][n];\n int[][] d1 = new int[n][n];\n for (int[] ar : d1) {\n Arrays.fill(ar, MINF);\n }\n for (int len = 1; len <= n; ++len) {\n for (int i = 0; i < n; ++i) {\n if (len == 1) {\n d1[i][i] = 0;\n } else {\n if (i - len + 1 >= 0) {\n int j = i - len + 1;\n d1[i][j] = MINF;\n for (int k = j + 1; k <= i; ++k) {\n if (a[j] + 1 == a[k] && d1[i][k] != MINF && d0[j + 1][k - 1] != MINF) {\n d1[i][j] = Math.max(d1[i][j], d1[i][k] + d0[j + 1][k - 1]);\n }\n }\n }\n if (i + len - 1 < n) {\n int j = i + len - 1;\n d1[i][j] = MINF;\n for (int k = i; k < j; ++k) {\n if (a[j] + 1 == a[k] && d1[i][k] != MINF && d0[k + 1][j - 1] != MINF) {\n d1[i][j] = Math.max(d1[i][j], d1[i][k] + d0[k + 1][j - 1]);\n }\n }\n }\n }\n }\n for (int i = 0; i + len <= n; ++i) {\n int j = i + len - 1;\n d0[i][j] = MINF;\n for (int k = i; k < j; ++k) {\n d0[i][j] = Math.max(d0[i][j], d0[i][k] + d0[k + 1][j]);\n }\n for (int k = i; k <= j; ++k) {\n if (d1[k][i] != MINF && d1[k][j] != MINF) {\n d0[i][j] = Math.max(d0[i][j], d1[k][i] + d1[k][j] + ws[2 * a[k] - a[i] - a[j] + 1]);\n }\n }\n }\n }\n int[] d2 = new int[n + 1];\n d2[0] = 0;\n for (int i = 0; i < n; ++i) {\n d2[i + 1] = Math.max(d2[i + 1], d2[i]);\n for (int j = i; j < n; ++j) {\n d2[j + 1] = Math.max(d2[j + 1], d2[i] + d0[i][j]);\n }\n }\n out.println(d2[n]);\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66d62d999a0ed72c55bbe7cea4fabfc3", "src_uid": "32fa5dbac37abe197a267a0fc7fe4006", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 Vadim Semenov\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static final class TaskF {\n private static final int MODULO = 1_000_000_000 + 7;\n private String subsequence;\n private int[][] nextPosition;\n private int[][][][] dp;\n\n public void solve(int __, InputReader in, PrintWriter out) {\n int maxBalance = in.nextInt();\n int length = 2 * maxBalance;\n subsequence = in.next();\n nextPosition = new int[subsequence.length() + 1][2];\n for (int i = 0; i <= subsequence.length(); ++i) {\n for (int type = 0; type < 2; ++type) {\n char parenthesis = \"()\".charAt(type);\n int k;\n link:\n for (k = Math.min(subsequence.length(), i + 1); k > 0; --k) {\n if (subsequence.charAt(k - 1) != parenthesis) continue;\n for (int j = k - 1; j-- > 0; ) {\n if (subsequence.charAt(j) != subsequence.charAt(i - k + 1 + j)) {\n continue link;\n }\n }\n break;\n }\n nextPosition[i][type] = k;\n }\n }\n dp = new int[length + 1][maxBalance + 1][subsequence.length() + 1][2];\n dp[0][0][0][0] = 1;\n for (int len = 0; len < length; ++len) {\n for (int balance = 0; balance <= Math.min(len, maxBalance); ++balance) {\n for (int pos = 0; pos <= Math.min(len, subsequence.length()); ++pos) {\n for (int was = 0; was < 2; ++was) {\n if (dp[len][balance][pos][was] == 0) continue;\n if (balance < maxBalance) {\n update(len, balance, pos, was, '(');\n }\n if (balance > 0) {\n update(len, balance, pos, was, ')');\n }\n }\n }\n }\n }\n int sum = 0;\n for (int pos = 0; pos <= subsequence.length(); ++pos) {\n sum = sum(sum, dp[length][0][pos][1]);\n }\n out.println(sum);\n }\n\n private void update(int len, int balance, int pos, int was, char parenthesis) {\n int nextLen = len + 1;\n int nextBalance = balance + (parenthesis == '(' ? 1 : -1);\n int nextPos = nextPosition[pos][\"()\".indexOf(parenthesis)];\n int nextWas = was | (nextPos == subsequence.length() ? 1 : 0);\n dp[nextLen][nextBalance][nextPos][nextWas] =\n sum(dp[nextLen][nextBalance][nextPos][nextWas], dp[len][balance][pos][was]);\n }\n\n private int sum(int first, int second) {\n return (first + second) % MODULO;\n }\n\n }\n\n static class InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public String readLine() {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b882469f9eaf9a806d31420c815429c", "src_uid": "590a49a7af0eb83376ed911ed488d7e5", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\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 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 Exception {\n\n //int t = in.nextInt();\n int t = 1;\n while (t > 0) {\n solve();\n t--;\n }\n\n out.flush();\n out.close();\n }\n\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.000000001;\n\n int n;\n int m;\n\n ArrayList[] g;\n String s;\n int[] maxPref = new int[200];\n void solve() throws IOException {\n n = in.nextInt();\n s = in.nextLine();\n\n StringBuilder sb = new StringBuilder();\n sb.append(s.charAt(0));\n for (int i = 1; i < s.length(); i++) {\n char br = '(';\n if (s.charAt(i) == '(') br = ')';\n String t = sb.toString() + br;\n for (int j = 1; j < t.length(); j++) {\n boolean ok = true;\n int pos = 0;\n for (int k = j; k < t.length(); k++) {\n ok &= s.charAt(pos) == t.charAt(k);\n pos++;\n }\n if (ok) {\n maxPref[i] = t.length() - j;\n break;\n }\n }\n sb.append(s.charAt(i));\n }\n\n out.println(f(0, 0,0));\n }\n\n int cnt(int start, String sub, int n) {\n int[][] dp = new int[n][n];\n boolean[][] used = new boolean[n][n];\n for (int i = 0; i < n; i++) {\n boolean any = i < start || i >= start + sub.length();\n for (int j = 0; j <= n / 2; j++) {\n if (i == 0) {\n if (any || sub.charAt(0) == '(') {\n dp[0][1] = 1;\n used[0][1] = true;\n }\n continue;\n }\n\n if (any || sub.charAt(i - start) == '(') {\n if (used[i - 1][j]) {\n dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % mod;\n used[i][j + 1] = true;\n }\n }\n\n if (any || sub.charAt(i - start) == ')') {\n if (j > 0 && used[i - 1][j]) {\n dp[i][j - 1] = (dp[i][j - 1] + dp[i - 1][j]) % mod;\n used[i][j - 1] = true;\n }\n }\n }\n }\n return dp[n - 1][0];\n }\n\n int[][][] dp = new int[200][101][201];\n boolean[][][] used = new boolean[200][101][201];\n int f(int pos, int balance, int pref) {\n\n if (balance < 0 || balance > n)\n return 0;\n\n if (pos == n * 2) {\n return balance == 0 && pref == s.length() ? 1 : 0;\n }\n\n if (used[pos][balance][pref])\n return dp[pos][balance][pref];\n\n int res = 0;\n if (pref == s.length()) {\n res = f(pos + 1, balance + 1, pref)\n + f(pos + 1, balance - 1, pref);\n } else {\n if (s.charAt(pref) == '(') {\n res += f(pos + 1, balance + 1, pref + 1);\n res += f(pos + 1, balance - 1, maxPref[pref]);\n }\n else {\n res += f(pos + 1, balance - 1, pref + 1);\n res += f(pos + 1, balance + 1, maxPref[pref]);\n }\n }\n\n dp[pos][balance][pref] = res % mod;\n used[pos][balance][pref] = true;\n return dp[pos][balance][pref];\n }\n\n class Pair implements Comparable{\n\n int a;\n int b;\n\n Pair(int a, int b) {\n\n this.a = a;\n this.b = b;\n }\n\n public int compareTo(Pair p) {\n if (a != p.a)\n return Integer.compare(a, p.a);\n else\n return Integer.compare(b, p.b);\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\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 static class InputReader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public InputReader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public InputReader(String file_name) throws 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ed892d2f0aedae28f85ca9f790549d6", "src_uid": "590a49a7af0eb83376ed911ed488d7e5", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class BracketSubstring_CF1015F { \n\n\tstatic String s;\n\tstatic int len;\n\tstatic int sub;\n\n\tstatic int memo[][][][];\n\tstatic final int MOD = (int)1e9 + 7;\n\t\n\t\n\tstatic int fail[];\n\tstatic char[] pat;\n\tstatic void pattern(){\n\t\tint len= pat.length;\n\t\tfail= new int [len];\n\t\tfail[0]=0;\n\t\tint k=0;\n\t\tfor(int i=1; i0 && pat[i]!=pat[k])\n\t\t\t\tk= fail[k-1];\n\t\t\t\n\t\t\tif(pat[i]==pat[k])\n\t\t\t\tfail[i]=++k;\n\t\t\telse fail[i]=k;\n\t\t}\n\t}\n\t\n\t\n\tstatic int dp(int i, int count, int commpr, int used){\n\t\t\n\t\tif(i == len){\n\t\t\treturn count == 0 && used == 1 ? 1 : 0;\n\t\t}\n\t\t\n\t\tif(count < 0)\n\t\t\treturn 0;\n\t\t\n\t\tif(memo[i][count][commpr][used] != -1){\n\t\t\treturn memo[i][count][commpr][used];\n\t\t}\n\t\tint commpr1 = commpr;\n\t\twhile(commpr1>0 && pat[commpr1]!='(')\n\t\t\tcommpr1 = fail[commpr1 - 1];\n\t\t\n\t\tint newused1 = used;\n\t\t\n\t\tif(pat[commpr1]=='(')\n\t\t\tcommpr1++;\n\t\tif(commpr1 == sub){\n\t\t\tnewused1 = 1;\n\t\t\tcommpr1 = 0;\n\n\t\t}\n\t\tint commpr2 = commpr;\n\t\tint newused2 = used;\n\t\twhile(commpr2>0 && pat[commpr2]!=')')\n\t\t\tcommpr2 = fail[commpr2 - 1];\n\t\t\t\t\n\t\tif(pat[commpr2]==')')\n\t\t\tcommpr2++;\n\t\tif(commpr2 == sub){\n\t\t\tnewused2 = 1;\n\t\t\tcommpr2 = 0;\n\t\t}\n\t\t\n\t\tint result = dp(i + 1, count + 1, commpr1 , newused1); \n\t\tresult +=\t dp(i + 1, count - 1, commpr2 , newused2);\n\t\t\n\t\treturn memo[i][count][commpr][used] = result % MOD;\n\t\t\n\t\t\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tlen = 2 * sc.nextInt();\n\t\ts = sc.next();\n\t\tsub = s.length();\n\t\tpat = s.toCharArray(); \n\t\tmemo = new int [len][len][sub][2];\n\t\tpattern();\n\t\tfor(int i = 0; i < len; i++){\n\t\t\tfor(int j = 0; j < len; j++){\n\t\t\t\tfor(int k = 0; k < sub; k++)\n\t\t\t\tArrays.fill(memo[i][j][k], -1);\n\t\t\t}\n\t\t}\n\t\tout.println(dp(0,0,0,0));\n\t\tout.flush();\n\t\tout.close();\n\t}\n\t\n\t\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\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif (x.charAt(0) == '-') {\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor (int i = start; i < x.length(); i++)\n\t\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t} else {\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dbee38e1d04f0e8a8cbc20f3a7c0ae93", "src_uid": "590a49a7af0eb83376ed911ed488d7e5", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\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 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 Exception {\n\n //int t = in.nextInt();\n int t = 1;\n while (t > 0) {\n solve();\n t--;\n }\n\n out.flush();\n out.close();\n }\n\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.000000001;\n\n int n;\n int m;\n\n ArrayList[] g;\n String s;\n int[] maxPref = new int[200];\n void solve() throws IOException {\n n = in.nextInt();\n s = in.nextLine();\n\n StringBuilder sb = new StringBuilder();\n sb.append(s.charAt(0));\n for (int i = 1; i < s.length(); i++) {\n char br = '(';\n if (s.charAt(i) == '(') br = ')';\n String t = sb.toString() + br;\n for (int j = 1; j < t.length(); j++) {\n boolean ok = true;\n int pos = 0;\n for (int k = j; k < t.length(); k++) {\n ok &= s.charAt(pos) == t.charAt(k);\n pos++;\n }\n if (ok) {\n maxPref[i] = t.length() - j;\n break;\n }\n }\n sb.append(s.charAt(i));\n }\n\n out.println(f(0, 0,0));\n }\n\n int cnt(int start, String sub, int n) {\n int[][] dp = new int[n][n];\n boolean[][] used = new boolean[n][n];\n for (int i = 0; i < n; i++) {\n boolean any = i < start || i >= start + sub.length();\n for (int j = 0; j <= n / 2; j++) {\n if (i == 0) {\n if (any || sub.charAt(0) == '(') {\n dp[0][1] = 1;\n used[0][1] = true;\n }\n continue;\n }\n\n if (any || sub.charAt(i - start) == '(') {\n if (used[i - 1][j]) {\n dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % mod;\n used[i][j + 1] = true;\n }\n }\n\n if (any || sub.charAt(i - start) == ')') {\n if (j > 0 && used[i - 1][j]) {\n dp[i][j - 1] = (dp[i][j - 1] + dp[i - 1][j]) % mod;\n used[i][j - 1] = true;\n }\n }\n }\n }\n return dp[n - 1][0];\n }\n\n int[][][] dp = new int[200][101][201];\n boolean[][][] used = new boolean[200][101][201];\n int f(int pos, int balance, int pref) {\n\n if (balance < 0)\n return 0;\n\n if (pos == n * 2) {\n return balance == 0 && pref == s.length() ? 1 : 0;\n }\n\n if (used[pos][balance][pref])\n return dp[pos][balance][pref];\n\n int res = 0;\n if (pref == s.length()) {\n res = f(pos + 1, balance + 1, pref)\n + f(pos + 1, balance - 1, pref);\n } else {\n if (s.charAt(pref) == '(') {\n res += f(pos + 1, balance + 1, pref + 1);\n res += f(pos + 1, balance - 1, maxPref[pref]);\n }\n else {\n res += f(pos + 1, balance - 1, pref + 1);\n res += f(pos + 1, balance + 1, maxPref[pref]);\n }\n }\n\n dp[pos][balance][pref] = res % mod;\n used[pos][balance][pref] = true;\n return dp[pos][balance][pref];\n }\n\n class Pair implements Comparable{\n\n int a;\n int b;\n\n Pair(int a, int b) {\n\n this.a = a;\n this.b = b;\n }\n\n public int compareTo(Pair p) {\n if (a != p.a)\n return Integer.compare(a, p.a);\n else\n return Integer.compare(b, p.b);\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\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 static class InputReader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public InputReader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public InputReader(String file_name) throws 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "545ff88097c376a8c9bd900277d8b707", "src_uid": "590a49a7af0eb83376ed911ed488d7e5", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class E {\n \n static double e = 1e-8, R, phi0;\n static int x,y,r,v,vp; \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int xp = sc.nextInt();\n int yp = sc.nextInt();\n vp = sc.nextInt();\n x = sc.nextInt();\n y = sc.nextInt();\n v = sc.nextInt();\n r = sc.nextInt();\n R = Math.sqrt(xp*xp+yp*yp);\n phi0 = Math.acos(xp / R);\n if (yp < 0)\n phi0 = 2*Math.PI-phi0;\n double left = 0, right = 1e9;\n for(;;) {\n double middle = (left+right) / 2;\n if (reache(middle) && !reache(middle-e)) {\n System.out.println(middle);\n return;\n }\n if (reache(middle))\n right = middle-e;\n else\n left = middle+e;\n }\n }\n\n private static boolean reache(double t) {\n double x2 = R*Math.cos(vp/R*t+phi0);\n double y2 = R*Math.sin(vp/R*t+phi0);\n double x1 = x, y1 = y;\n double a = y1-y2, b = x2-x1, c = x1*y2-x2*y1;\n double d = Math.abs(c) / Math.sqrt(a*a+b*b);\n double reach_time = 0;\n a = dis(x1, y1, 0, 0);\n b = dis(x2, y2, 0, 0);\n c = dis(x1, y1, x2, y2);\n if (d >= r || Math.abs(Math.sqrt(a*a-d*d)+Math.sqrt(b*b-d*d)-c) > e) {\n reach_time = c / v;\n }\n else {\n double alfa = Math.acos((x1*x2+y1*y2) / (a*b))-Math.acos(r/a)-Math.acos(r/b);\n reach_time = (r*alfa+Math.sqrt(a*a-r*r)+Math.sqrt(b*b-r*r)) / v;\n }\n return reach_time <= t;\n }\n\n private static double dis(double x1, double y1, double x2, double y2) {\n return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "184ac41839fc293cae34e60646e4919a", "src_uid": "e8471556906e5fa3a701842570fa4ee2", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class TaskD {\n public static void main(String[] args) {\n new TaskD().solve();\n }\n\n TaskD() {\n }\n\n int b, d, lenA, lenC;\n String a, c;\n int[][] next, delta;\n\n public void solve() {\n Scanner in = new Scanner(System.in);\n b = in.nextInt();\n d = in.nextInt();\n a = in.next();\n c = in.next();\n\n lenA = a.length();\n lenC = c.length();\n\n next = new int[lenA + 1][lenC + 1];\n delta = new int[lenA + 1][lenC + 1];\n for (int i = 0; i < lenA; ++i) {\n Arrays.fill(next[i], -1);\n Arrays.fill(delta[i], -1);\n\n for (int j = 0; j < lenC; ++j) {\n if (a.charAt(i) != c.charAt(j)) continue;\n\n int l = 1, dd = 0, lastL = 0;\n while (l < lenA) {\n int ii = (i + l) % lenA;\n int jj = (j + dd + 1) % lenC;\n if (a.charAt(ii) == c.charAt(jj)) {\n ++dd;\n lastL = l;\n }\n ++l;\n }\n\n if (lastL > 0) {\n next[i][j] = lastL;\n delta[i][j] = dd;\n }\n }\n }\n\n int cnt = 0, i = 0, j = 0;\n while (i < lenA && next[i][j] == -1) ++i;\n if (next[i][j] == -1) {\n System.out.println(0);\n return;\n }\n\n while (next[i % lenA][j] != -1 && i + next[i % lenA][j] < lenA * b) {\n assert a.charAt(i % lenA) == c.charAt(j);\n int ii = i % lenA;\n int jj = j;\n cnt += delta[ii][jj];\n i += next[ii][jj];\n j = (j + delta[ii][jj]) % lenC;\n }\n\n if (next[i % lenA][j] != -1) {\n while (i < lenA * b) {\n if (a.charAt(i % lenA) == c.charAt(j)) {\n ++cnt;\n j = (j + 1) % lenC;\n }\n ++i;\n }\n }\n\n System.out.println(cnt / (d * lenC));\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60ab83fd2d8fc792d6e4cdb59275a32d", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class TaskD {\n public static void main(String[] args) {\n new TaskD().solve();\n }\n\n TaskD() {\n }\n\n int b, d, lenA,lenC;\n String a, c;\n int[][] next, delta; // next[i][j], \u5f53a[i] == c[j]\u540e\uff0c\u4e0b\u4e00\u4e2a\u8be5\u5339\u914d\u7684a\u7684\u4f4d\u7f6e\uff1bdelta[i][j]\uff0c\u5f53a[i] == c[j]\u540e\uff0c\u5230\u4e0b\u4e00\u4e2a\u5339\u914d\u7684\u4f4d\u7f6e\u52a0\u51e0\u4e2acnt\n\n public void solve() {\n Scanner in = new Scanner(System.in);\n b = in.nextInt();\n d = in.nextInt();\n a = in.next();\n c = in.next();\n\n// int cnt = 0, j = 0;\n// for (int i = 0; i < a.length() * b; ++i) {\n// int ii = i % a.length();\n// int jj = j % c.length();\n// if (a.charAt(ii) == c.charAt(jj)) {\n// ++cnt;\n// ++j;\n// }\n// }\n\n lenA = a.length();\n lenC = c.length();\n\n next = new int[lenA][lenC];\n delta = new int[lenA][lenC];\n for (int i = 0; i < lenA; ++i) {\n Arrays.fill(next[i], -1);\n Arrays.fill(delta[i], -1);\n\n for (int j = 0; j < lenC; ++j) {\n if (a.charAt(i) != c.charAt(j)) continue;\n\n int l = 1, dd = 0, lastL = 0;\n while (l < lenA) {\n int ii = (i + l) % lenA;\n int jj = (j + dd + 1) % lenC;\n if (a.charAt(ii) == c.charAt(jj)) {\n ++dd;\n lastL = l;\n }\n ++l;\n }\n\n if (lastL > 0) {\n next[i][j] = lastL;\n delta[i][j] = dd;\n }\n }\n }\n\n int cnt = 0, i = 0, j = 0;\n while (i < lenA && next[i][j] == -1) ++i;\n if (next[i][j] == -1) {\n System.out.println(0);\n return;\n }\n\n while (next[i % lenA][j] != -1 && i + next[i % lenA][j] < lenA * b) {\n assert a.charAt(i % lenA) == c.charAt(j);\n int ii = i % lenA;\n int jj = j;\n cnt += delta[ii][jj];\n i += next[ii][jj];\n j = (j + delta[ii][jj]) % lenC;\n }\n\n if (next[i % lenA][j] != -1) {\n while (i < lenA * b) {\n if (a.charAt(i % lenA) == c.charAt(j)) {\n ++cnt;\n j = (j + 1) % lenC;\n }\n ++i;\n }\n }\n\n System.out.println(cnt / (d * lenC));\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b8b8b75db10a560a61b5903daeeda32", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\t\n\tprivate static StringTokenizer tokenizer;\n private static BufferedReader bf;\n private static PrintWriter out;\n \n\tprivate static int nextInt() throws IOException {\n \treturn Integer.parseInt(nextToken());\n }\n \n @SuppressWarnings(\"unused\")\n\tprivate static long nextLong() throws IOException {\n \treturn Long.parseLong(nextToken());\n }\n \n private static String nextToken() throws IOException {\n \twhile(tokenizer == null || !tokenizer.hasMoreTokens()) {\n \t\ttokenizer = new StringTokenizer(bf.readLine());\n \t}\n \treturn tokenizer.nextToken();\n }\n \n\tpublic static void main(String[] args) throws IOException {\n\t\tbf = new BufferedReader(new InputStreamReader(System.in));\n \ttokenizer = null;\n \tout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n \tint b = nextInt(); int d = nextInt();\n \tString a = nextToken(); String c = nextToken();\n \tint inda = 0, indc = 0;\n \tint lena = a.length();\n \tint lenc = c.length();\n \tint max = lena*b;\n \twhile(inda < max) {\n \t\tif(c.charAt(indc%lenc) != a.charAt(inda%lena))\n \t\t\tinda++;\n \t\telse {\n \t\t\tinda++; indc++;\n \t\t}\n \t}\n \tout.println(indc/(lenc*d));\n \tout.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2f49c628254fa22200b9a91d8f901d54", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\t\n\tprivate static StringTokenizer tokenizer;\n private static BufferedReader bf;\n private static PrintWriter out;\n \n\tprivate static int nextInt() throws IOException {\n \treturn Integer.parseInt(nextToken());\n }\n \n @SuppressWarnings(\"unused\")\n\tprivate static long nextLong() throws IOException {\n \treturn Long.parseLong(nextToken());\n }\n \n private static String nextToken() throws IOException {\n \twhile(tokenizer == null || !tokenizer.hasMoreTokens()) {\n \t\ttokenizer = new StringTokenizer(bf.readLine());\n \t}\n \treturn tokenizer.nextToken();\n }\n \n\tpublic static void main(String[] args) throws IOException {\n\t\tbf = new BufferedReader(new InputStreamReader(System.in));\n \ttokenizer = null;\n \tout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n \tint b = nextInt(); int d = nextInt();\n \tString a = nextToken(); String c = nextToken();\n \tint inda = 0, indc = 0;\n \tint lena = a.length();\n \tint lenc = c.length();\n \tlong max = lena*b;\n \twhile(inda < max) {\n \t\tif(c.charAt(indc%lenc) != a.charAt(inda%lena))\n \t\t\tinda++;\n \t\telse {\n \t\t\tinda++; indc++;\n \t\t}\n \t\tif(indc%lenc == 0 && inda%lena == 0) break;\n \t}\n \tout.println((indc*max)/(lenc*d*inda));\n \tout.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "920398d3a1bd60bae621b3843f8153d9", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class D539 {\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n int n = sc.nextInt(); int m = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt();\n fac = new long[m + 10];\n initFac(m + 6);\n long ans = 0;\n for (int k = 0; k <= n - 2; k++) {\n long middle = (nck(n - 2, k) * fac[k]) % mod;\n long sum = nck(m - 1, k);\n long cayley;\n if (n - k - 3 >= 0) cayley = ((k + 2) * pow(n, n - k - 3)) % mod; else cayley = 1;\n long total = (((middle * sum) % mod) * cayley) % mod;\n total = (total * pow(m, n - k - 2));\n ans = (ans + total) % mod;\n }\n out.println(ans);\n out.close();\n }\n\n static long[] fac;\n static long mod = (int) 1e9 + 7;\n\n static void initFac(long n) {\n fac[0] = 1;\n for (int i = 1; i <= n; i++) {\n fac[i] = (fac[i - 1] * i) % mod;\n }\n }\n\n static long exponentiation(long base, long exp)\n {\n long t = 1L;\n while (exp > 0) {\n\n // for cases where exponent\n // is not an even value\n if (exp % 2 != 0)\n t = (t * base) % mod;\n\n base = (base * base) % mod;\n exp /= 2;\n }\n return t % mod;\n }\n\n static long nck(int n, int k) {\n if (n < k)\n return 0;\n long den = inv((int) (fac[k] * fac[n - k] % mod));\n return fac[n] * den % mod;\n }\n\n static long pow(long b, long e) {\n long ans = 1;\n while (e > 0) {\n if (e % 2 == 1)\n ans = ans * b % mod;\n e >>= 1;\n b = b * b % mod;\n }\n return ans;\n }\n\n static long inv(int x) {\n return pow(x, mod - 2);\n }\n\n\n\n //-----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "097afef4f1f1eef71ec067ca2316b8a7", "src_uid": "728fe302b8b18e33f15f6e702e332cde", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class TaskF {\n private static final long MOD = 1_000_000_000 + 7;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n //System.out.printf(\"%s%n\", modCombinations(10000, 500));\n\n int n = in.nextInt();\n int m = in.nextInt();\n\n /* no need for a and b (?) */\n\n System.out.println(solve(n, m));\n\n in.close();\n }\n\n private static long solve(int n, int m) {\n long sum = 0;\n for (int k = 1; k <= n - 1; k++) {\n long splits = splits(m, k);\n long perms = perms(n, k);\n long rest = rest(n, m, k);\n sum += (((splits * perms) % MOD) * rest) % MOD;\n sum = sum % MOD;\n }\n return sum;\n }\n\n private static long splits(int sum, int count) {\n return modCombinations(sum - 1, count - 1);\n }\n\n private static long perms(int n, int k) {\n return modKPermutations(n - 2, k - 1);\n }\n\n private static long rest(int n, int m, int k) {\n return (modNumberOfTrees(n, k + 1) * modPower(m, n - 1 - k)) % MOD;\n }\n\n private static long modNumberOfTrees(int n, int y) {\n if (n < y) {\n return 0;\n } else if (n == y) {\n return 1;\n } else {\n return (y * modPower(n, n - y - 1)) % MOD;\n }\n }\n\n private static MapTools mapTools = new MapTools();\n private static Primes primes = new Primes();\n\n private static Map> kPermutationsCache = new HashMap<>();\n private static long modKPermutations(int n, int k) {\n return kPermutationsCache\n .computeIfAbsent(n, $ -> new HashMap<>())\n .computeIfAbsent(k,\n $ -> modRestoreFactorMapToNumber(\n mapTools.subtractCounts(\n primes.factorFactorial(n),\n primes.factorFactorial(n - k))));\n }\n\n private static Map> combinationsCache = new HashMap<>();\n private static long modCombinations(int n, int k) {\n return combinationsCache\n .computeIfAbsent(n, $ -> new HashMap<>())\n .computeIfAbsent(k,\n $ -> modRestoreFactorMapToNumber(\n mapTools.subtractCounts(\n mapTools.subtractCounts(\n primes.factorFactorial(n),\n primes.factorFactorial(k)),\n primes.factorFactorial(n - k))));\n }\n\n private static long factorial(int n) {\n long result = 1;\n for (int i = 2; i <= n; i++) {\n result *= i;\n }\n return result;\n }\n\n private static long modPower(int n, int p) {\n if (p == 0) {\n return 1;\n } else if (p % 2 == 1) {\n return (n * modPower(n, p - 1)) % MOD;\n } else {\n long halfPower = modPower(n, p / 2);\n return (halfPower * halfPower) % MOD;\n }\n }\n\n private static long modRestoreFactorMapToNumber(Map factorMap) {\n long result = 1;\n for (int prime : factorMap.keySet()) {\n result = (result * modPower(prime, factorMap.get(prime))) % MOD;\n }\n return result;\n }\n\n private static class MapTools {\n public Map subtractCounts(\n Map a, Map b) {\n\n Map result = new HashMap<>(a);\n\n for (int bKey : b.keySet()) {\n if (!result.containsKey(bKey)) {\n throw new RuntimeException(\"No such key: \" + bKey);\n }\n result.put(bKey, result.get(bKey) - b.get(bKey));\n }\n\n return result;\n }\n }\n\n private static class Primes {\n private final List primes = new ArrayList<>();\n private int primesLimit;\n\n private final Map> factorialFactorizationCache = new HashMap<>();\n public Map factorFactorial(int n) {\n return factorialFactorizationCache.computeIfAbsent(n, $ -> {\n calculatePrimesUpTo(n);\n Map result = new HashMap<>();\n for (int p : primes) {\n if (p > n) break;\n int count = 0;\n int pPower = p;\n while (pPower <= n) {\n count += n / pPower;\n pPower *= p;\n }\n result.put(p, count);\n }\n return result;\n });\n }\n\n private void calculatePrimesUpTo(int newLimit) {\n if (newLimit <= primesLimit) return;\n\n int start = primesLimit + 1;\n if (start <= 2) {\n start = 2;\n }\n for (int i = start; i <= newLimit; i++) {\n if (isPrime(i)) {\n primes.add(i);\n }\n }\n\n primesLimit = newLimit;\n }\n\n private boolean isPrime(int n) {\n for (int p : primes) {\n if (p * p > n) break;\n if (n % p == 0) return false;\n }\n return true;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "070bd0ccce43b8aa5486bddbecb5ca02", "src_uid": "728fe302b8b18e33f15f6e702e332cde", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.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 Actual solution is at the top\n *\n * @author Hieu Le\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n private static final long MOD = (long) 1e9 + 7;\n private static final int MAX = (int) 1e6;\n private long[] facts;\n\n public TaskD() {\n facts = new long[MAX + 1];\n facts[0] = 1;\n for (int i = 1; i < MAX + 1; ++i) facts[i] = facts[i - 1] * i % MOD;\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\n long res = 0;\n for (int dist = 1; dist <= Math.min(m, n - 1); ++dist) {\n long tmp = 1;\n\n // number of ways to get sum m from dist numbers\n tmp = tmp * countSum(m, dist) % MOD;\n // number of ways to pick nodes between\n tmp = tmp * nPk(n - 2, dist - 1) % MOD;\n // Number of ways to assign weights to the remaining edges\n tmp = tmp * modPow(m, n - 1 - dist) % MOD;\n // Number of ways to arrange the remaining nodes\n if (n > dist + 1) {\n tmp = tmp * magic(n, dist + 1) % MOD;\n }\n\n res = (res + tmp) % MOD;\n }\n\n out.println(res);\n }\n\n private long magic(int n, int k) {\n return k * modPow(n, n - k - 1) % MOD;\n }\n\n private long countSum(int sum, int n) {\n return nCk(sum - 1, n - 1);\n }\n\n private long nCk(int n, int k) {\n long res = facts[n] * modPow(facts[k], MOD - 2) % MOD;\n return res * modPow(facts[n - k], MOD - 2) % MOD;\n }\n\n private long nPk(int n, int k) {\n return facts[n] * modPow(facts[n - k], MOD - 2);\n }\n\n private long modPow(long base, long exponent) {\n if (exponent == 0) return 1;\n long res = modPow(base, exponent / 2);\n res = res * res % MOD;\n if (exponent % 2 == 1) res = res * base % MOD;\n return res;\n }\n }\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n private static final int BUFFER_SIZE = 32768;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "844b74ac44aadd7af98f242170b3f809", "src_uid": "728fe302b8b18e33f15f6e702e332cde", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\n*/\nimport java.util.*;\nimport java.io.*;\n\n public class x1113F\n {\n static long MOD = 1000000007L;\n public static void main(String args[]) throws Exception\n {\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); \n StringTokenizer st = new StringTokenizer(infile.readLine());\n int N = Integer.parseInt(st.nextToken());\n int M = Integer.parseInt(st.nextToken());\n st.nextToken();\n st.nextToken(); //lol\n long[] fac = new long[2000001];\n long[] inv = new long[2000001];\n fac[0] = 1L;\n for(int i=1; i <= 2000000; i++)\n fac[i] = (fac[i-1]*i)%MOD;\n inv[0] = 1L;\n for(int i=1; i <= 2000000; i++)\n inv[i] = (inv[i-1]*power(i, MOD-2, MOD))%MOD;\n //solve\n long res = 0L;\n for(int n=0; n <= N-2; n++)\n {\n int edges = n+1;\n //stars and bars\n //create edges\n if(edges > M)\n break;\n long temp = (fac[M-1]*inv[n])%MOD;\n temp *= inv[M-1-n];\n temp %= MOD;\n //(N-2)*(N-3)*...\n //create middle vertices\n temp *= fac[N];\n temp %= MOD;\n temp *= inv[N-2-n];\n temp %= MOD;\n temp *= power(N, MOD-2, MOD);\n temp %= MOD;\n temp *= power(N-1, MOD-2, MOD);\n temp %= MOD;\n //rest\n temp *= fac[N-1];\n temp %= MOD;\n temp *= inv[n+1];\n temp %= MOD;\n temp *= fac[N-n-2];\n temp %= MOD;\n //final edges\n temp *= power(M, N-n-2, MOD);\n temp %= MOD;\n //done\n res += temp;\n res %= MOD;\n }\n System.out.println(res);\n }\n public static long power(long x, long y, long p) \n { \n long res = 1L; \n x = x % p; \n while (y > 0) \n { \n if((y & 1)==1) \n res = (res * x) % p; \n y = y >> 1; \n x = (x * x) % p; \n } \n return res; \n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e682298520b3805e29f13c9b32ba562", "src_uid": "728fe302b8b18e33f15f6e702e332cde", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class S_39I {\n BufferedReader in;\n StringTokenizer st;\n PrintWriter out;\n\n List> edges = new ArrayList>();\n\n int[] depth;\n\n int dfs_GCD(int index, int d) {\n if (depth[index] == 0) {\n depth[index] = d;\n int rv = 0;\n for (int next : edges.get(index)) {\n rv = gcd(rv, dfs_GCD(next, d + 1));\n }\n return rv;\n } else {\n return d - depth[index];\n }\n }\n\n private static int gcd(int a, int b) {\n a = Math.abs(a);\n b = Math.abs(b);\n while (b != 0) {\n int t = a % b;\n a = b;\n b = t;\n }\n return a;\n }\n\n void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n for (int i = 0; i < n; ++i) {\n edges.add(new ArrayList());\n }\n for (int i = 0; i < m; ++i) {\n int s = nextInt() - 1;\n int e = nextInt() - 1;\n edges.get(s).add(e);\n }\n depth = new int[n];\n int gcd = dfs_GCD(0, 1);\n List ans = new ArrayList();\n for (int i = 0; i < n; ++i) {\n if (depth[i] % gcd == depth[0] % gcd) {\n ans.add(depth[i]);\n }\n }\n out.println(gcd);\n out.println(ans.size());\n for (int i : ans) {\n out.print(i);\n out.print(\" \");\n }\n }\n\n public void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n eat(\"\");\n solve();\n out.close();\n in.close();\n }\n\n void eat(String s) {\n st = new StringTokenizer(s);\n }\n\n String next() throws IOException {\n while (!st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null) {\n return null;\n }\n eat(line);\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public static void main(String[] args) throws IOException {\n new S_39I().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "92036ecad589527f4d6cd5fa7babaad4", "src_uid": "e13228fcdaa1c218581606ddfe186d52", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class Main {\n\t\tScanner in;\n\t\tPrintWriter pw;\n\t\t\n\t\tint n,m,g=-1;\n\t\tList> v = new ArrayList>();\n\t\tint[] c;\n\t\t\n\t\tint gcd(int a,int b){\n\t\t\twhile(a>0 && b>0)\n\t\t\t\tif(a>b) a%=b;\n\t\t\t\telse b%=a;\n\t\t\treturn a+b;\n\t\t}\n\t\tvoid dfs(int ver,int pos){\n\t\t\tif(c[ver]!=-1){\n\t\t\t\tint diff = Math.abs(c[ver]-pos);\n\t\t\t\tif(g==-1) g = diff;\n\t\t\t\tg = gcd(g, diff);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tc[ver] = pos;\n\t\t\tfor(int i=0;i());\n }\n \t\n \n for(int i=0;i res = new ArrayList();\n for(int i=0;i0)pw.print(\" \");\n \tpw.print(res.get(i));\n }\n pw.println();\n \n \n pw.close();\n }\n public static void main(String[] args) throws Exception {\n new Main ().run();\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "518d20794c217ec07a130167b72f4a57", "src_uid": "e13228fcdaa1c218581606ddfe186d52", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class Main {\n\t\tScanner in;\n\t\tPrintWriter pw;\n\t\t\n\t\tint n,m,g=-1;\n\t\tList> v = new ArrayList>();\n\t\tint[] c;\n\t\t\n\t\tint gcd(int a,int b){\n\t\t\twhile(a>0 && b>0)\n\t\t\t\tif(a>b) a%=b;\n\t\t\t\telse b%=a;\n\t\t\treturn a+b;\n\t\t}\n\t\tvoid dfs(int ver,int pos){\n\t\t\tif(c[ver]!=-1){\n\t\t\t\tint diff = Math.abs(c[ver]-pos);\n\t\t\t\tif(g==-1) g = diff;\n\t\t\t\tg = gcd(g, diff);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tc[ver] = pos;\n\t\t\tfor(int i=0;i());\n }\n \t\n \n for(int i=0;i res = new ArrayList();\n for(int i=0;i0)pw.print(\" \");\n \tpw.print(res.get(i));\n }\n pw.println();\n \n \n pw.close();\n }\n public static void main(String[] args) throws Exception {\n new Main ().run();\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "426f6e4d16ce1024263ac4e247629b1a", "src_uid": "e13228fcdaa1c218581606ddfe186d52", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class B {\n public static void main(String[] args) throws Exception {\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n ArrayList mersenne = new ArrayList();\n int[] vals = {2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20966011};\n \n // Scanner scan = new Scanner(System.in);\n // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); \n int n = Integer.parseInt(bf.readLine());\n int exp = vals[n-1]-1;\n long start = 0;\n for(int i=0; i= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn 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\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 IntegerUtils {\n\n public static long power(long base, long exponent, long mod) {\n\t\tif (exponent == 0)\n\t\t\treturn 1;\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\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "20fe4d62458a13c6ac3770d680aea6f8", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class _0255_E_Unsolvable {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tint N = readInt(); \n\t\tif(N == 1) println(1);\n\t\tif(N == 2) println(3);\n\t\tif(N == 3) println(15);\n\t\tif(N == 4) println(63);\n\t\texit();\n\t}\n\n\tfinal private static int BUFFER_SIZE = 1 << 16;\n\tprivate static DataInputStream din = new DataInputStream(System.in);\n\tprivate static byte[] buffer = new byte[BUFFER_SIZE];\n\tprivate static int bufferPointer = 0, bytesRead = 0;\n\tstatic PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n\tpublic static String readLine() throws IOException {\n\t\tbyte[] buf = new byte[64]; // line length\n\t\tint cnt = 0, c;\n\t\twhile ((c = Read()) != -1) {\n\t\t\tif (c == '\\n')\n\t\t\t\tbreak;\n\t\t\tbuf[cnt++] = (byte) c;\n\t\t}\n\t\treturn new String(buf, 0, cnt);\n\t}\n\n\tpublic static String read() throws IOException {\n\t\tbyte[] ret = new byte[1024];\n\t\tint idx = 0;\n\t\tbyte c = Read();\n\t\twhile (c <= ' ') {\n\t\t\tc = Read();\n\t\t}\n\t\tdo {\n\t\t\tret[idx++] = c;\n\t\t\tc = Read();\n\t\t} while (c != -1 && c != ' ' && c != '\\n' && c != '\\r');\n\t\treturn new String(ret, 0, idx);\n\t}\n\n\tpublic static int readInt() throws IOException {\n\t\tint ret = 0;\n\t\tbyte c = Read();\n\t\twhile (c <= ' ')\n\t\t\tc = Read();\n\t\tboolean neg = (c == '-');\n\t\tif (neg)\n\t\t\tc = Read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t} while ((c = Read()) >= '0' && c <= '9');\n\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\n\tpublic static long readLong() throws IOException {\n\t\tlong ret = 0;\n\t\tbyte c = Read();\n\t\twhile (c <= ' ')\n\t\t\tc = Read();\n\t\tboolean neg = (c == '-');\n\t\tif (neg)\n\t\t\tc = Read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t} while ((c = Read()) >= '0' && c <= '9');\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\n\tpublic static double readDouble() throws IOException {\n\t\tdouble ret = 0, div = 1;\n\t\tbyte c = Read();\n\t\twhile (c <= ' ')\n\t\t\tc = Read();\n\t\tboolean neg = (c == '-');\n\t\tif (neg)\n\t\t\tc = Read();\n\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t} while ((c = Read()) >= '0' && c <= '9');\n\n\t\tif (c == '.') {\n\t\t\twhile ((c = Read()) >= '0' && c <= '9') {\n\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t}\n\t\t}\n\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\n\tprivate static void fillBuffer() throws IOException {\n\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\tif (bytesRead == -1)\n\t\t\tbuffer[0] = -1;\n\t}\n\n\tprivate static byte Read() throws IOException {\n\t\tif (bufferPointer == bytesRead)\n\t\t\tfillBuffer();\n\t\treturn buffer[bufferPointer++];\n\t}\n\n\tstatic void print(Object o) {\n\t\tpr.print(o);\n\t}\n\n\tstatic void println(Object o) {\n\t\tpr.println(o);\n\t}\n\n\tstatic void flush() {\n\t\tpr.flush();\n\t}\n\n\tstatic void println() {\n\t\tpr.println();\n\t}\n\n\tstatic void exit() throws IOException {\n\t\tdin.close();\n\t\tpr.close();\n\t\tSystem.exit(0);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0a8f3f4d56d9b32d76ee346d9646e577", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class E {\n static long mod = (long) (1e9 + 7);\n\n public static long pow(long x, long pow) {\n if (pow == 0)\n return 1;\n long temp = pow(x, pow >> 1);\n temp = (temp * temp) % mod;\n if ((pow & 1) != 0)\n temp = (temp * x) % mod;\n return temp;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] A = { 1, 2, 4, 6, 12, 16, 18, 30, 60, 88, 106, 126, 520, 606,\n 1278, 2202, 2280, 3216, 4252, 4422, 9688, 9940, 11212, 19936,\n 21700, 23208, 44496, 86242, 110502, 132048, 216090, 756838,\n 859432, 1257786, 1398268, 2976220, 3021376, 6972592, 13466916 };\n System.out.println((pow(2, A[n - 1]) + mod - 1) % mod);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4e77b34c4bfe4ef6989cfcaa529aff53", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "//package round38;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class F {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"2 aba abac\";\n//\tString INPUT = \"3 artem nik max\";\n\tString INPUT = \"\";\n\t\n\tString[] dic;\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tdic = new String[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tdic[i] = in.next();\n\t\t}\n\t\t\n\t\tMap word = new HashMap();\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < dic[i].length();j++){\n\t\t\t\tfor(int k = j + 1;k <= dic[i].length();k++){\n\t\t\t\t\tword.put(dic[i].substring(j, k), null);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tString[][] q = new String[31][450*30];\n\t\tint[] ps = new int[31];\n\t\tfor(String key : word.keySet()){\n\t\t\tint len = key.length();\n\t\t\tq[len][ps[len]++] = key;\n\t\t}\n\t\t\n\t\touter:\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\tif(j != i && dic[j].indexOf(dic[i]) > -1 && !dic[j].equals(dic[i])){\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\tword.put(dic[i], new Info(0, score(dic[i]), false));\n\t\t}\n\t\tfor(int i = 30;i >= 1;i--){\n\t\t\tfor(int j = 0;j < ps[i];j++){\n\t\t\t\tString key = q[i][j];\n\t\t\t\tif(word.get(key) == null){\n\t\t\t\t\tint sc = score(key);\n\t\t\t\t\tboolean lose = true;\n\t\t\t\t\tint lof = 0;\n\t\t\t\t\tint los = 0;\n\t\t\t\t\tint wof = 0;\n\t\t\t\t\tint wos = 0;\n\t\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\t\tfor(int l = dic[k].indexOf(key, 0); l != -1;l = dic[k].indexOf(key, l+1)){\n\t\t\t\t\t\t\tif(l > 0){\n\t\t\t\t\t\t\t\tInfo info = word.get(dic[k].substring(l-1, l+i));\n\t\t\t\t\t\t\t\tlose &= info.win;\n\t\t\t\t\t\t\t\tif(info.win){\n\t\t\t\t\t\t\t\t\tif(lof < info.second || (lof == info.second && los > info.first)){\n\t\t\t\t\t\t\t\t\t\tlos = info.first;\n\t\t\t\t\t\t\t\t\t\tlof = info.second;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tif(wof < info.second || (wof == info.second && wos > info.first)){\n\t\t\t\t\t\t\t\t\t\twos = info.first;\n\t\t\t\t\t\t\t\t\t\twof = info.second;\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\tif(l+i+1 <= dic[k].length()){\n\t\t\t\t\t\t\t\tInfo info = word.get(dic[k].substring(l, l+i+1));\n\t\t\t\t\t\t\t\tlose &= info.win;\n\t\t\t\t\t\t\t\tif(info.win){\n\t\t\t\t\t\t\t\t\tif(lof < info.second || (lof == info.second && los > info.first)){\n\t\t\t\t\t\t\t\t\t\tlos = info.first;\n\t\t\t\t\t\t\t\t\t\tlof = info.second;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tif(wof < info.second || (wof == info.second && wos > info.first)){\n\t\t\t\t\t\t\t\t\t\twos = info.first;\n\t\t\t\t\t\t\t\t\t\twof = info.second;\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\tif(lose){\n\t\t\t\t\t\tword.put(key, new Info(lof, los + sc, !lose));\n\t\t\t\t\t}else{\n\t\t\t\t\t\tword.put(key, new Info(wof, wos + sc, !lose));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n//\t\tfor(Map.Entry entry : word.entrySet()){\n//\t\t\ttr(entry.getKey(), entry.getValue());\n//\t\t}\n//\n\t\t{\n\t\t\tboolean lose = true;\n\t\t\tint lof = 0;\n\t\t\tint los = 0;\n\t\t\tint wof = 0;\n\t\t\tint wos = 0;\n\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\tfor(int l = 0; l < dic[k].length();l++){\n\t\t\t\t\tInfo info = word.get(dic[k].substring(l, l+1));\n\t\t\t\t\tlose &= info.win;\n\t\t\t\t\tif(info.win){\n\t\t\t\t\t\tif(lof < info.second || (lof == info.second && los > info.first)){\n\t\t\t\t\t\t\tlos = info.first;\n\t\t\t\t\t\t\tlof = info.second;\n\t\t\t\t\t\t}\n\t\t\t\t\t}else{\n\t\t\t\t\t\tif(wof < info.second || (wof == info.second && wos > info.first)){\n\t\t\t\t\t\t\twos = info.first;\n\t\t\t\t\t\t\twof = info.second;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(!lose ? \"First\" : \"Second\");\n\t\t\tif(lose){\n\t\t\t\tout.println(lof + \" \" + los);\n\t\t\t}else{\n\t\t\t\tout.println(wof + \" \" + wos);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tclass Info\n\t{\n\t\tpublic boolean win;\n\t\tpublic int first;\n\t\tpublic int second;\n\t\tpublic Info(int first, int second, boolean win){\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t\tthis.win = win;\n\t\t}\n\t\t\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn Integer.toString(first) + \" \" + Integer.toString(second) + \" \" + Boolean.toString(win);\n\t\t}\n\t}\n\t\n\tint score(String sub)\n\t{\n\t\tint score = 0;\n\t\tint max = 0;\n\t\tfor(char v : sub.toCharArray()){\n\t\t\tscore += v - 'a' + 1;\n\t\t\tmax = Math.max(max, v - 'a' + 1);\n\t\t}\n\t\tscore *= max;\n\t\t\n\t\tfor(String word : dic){\n\t\t\tif(word.indexOf(sub) > -1){\n\t\t\t\tscore++;\n\t\t\t}\n\t\t}\n\t\treturn score;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 30;\n//\t\tStringBuilder sb = new StringBuilder(n + \" \");\n//\t\tfor(int i = 0;i < n;i++){\n//\t\t\tsb.append(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" + (char)('a' + (i*26/30)) + \" \");\n//\t\t}\n//\t\tINPUT = sb.toString();\n\n//\t\tint n = 30;\n//\t\tStringBuilder sb = new StringBuilder(n + \" \");\n//\t\tfor(int i = 0;i < n;i++){\n//\t\t\tsb.append((char)('a' + (i * 26 / 30)) + \" \");\n//\t\t}\n//\t\tINPUT = sb.toString();\n//\t\ttr(INPUT);\n\n\t\t\n\t\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew F().run();\n\t}\n\t\n\tint ni() { return Integer.parseInt(in.next()); }\n\tvoid tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a52620fa6b8180a1782fe3c00fcd4715", "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\n\npublic class F38 {\n\n static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n static PrintWriter out = new PrintWriter(System.out);\n \n static int nextInt() throws IOException {\n in.nextToken();\n return Integer.valueOf(in.sval);\n }\n \n static double nextDouble() throws IOException {\n in.nextToken();\n return Double.valueOf(in.sval);\n }\n \n static String nextString() throws IOException {\n in.nextToken();\n return in.sval;\n }\n \n static {\n in.ordinaryChars('0', '9');\n in.wordChars('0', '9');\n \n in.ordinaryChars('.', '.');\n in.wordChars('.', '.');\n \n in.ordinaryChars('-', '-');\n in.wordChars('-', '-');\n }\n\n public static void main(String[] args) throws IOException {\n n = nextInt();\n voc = new String[n];\n for (int i = 0; i < n; i++)\n voc[i] = nextString();\n \n h.put(\"\", new Node(\"\"));\n nodes.offer(h.get(\"\"));\n \n for (int i = 0; i < n; i++)\n for (int j = 0; j < voc[i].length(); j++)\n for (int k = j+1; k <= voc[i].length(); k++) {\n String cur = voc[i].substring(j, k);\n if (!h.containsKey(cur)) {\n h.put(cur, new Node(cur));\n nodes.offer(h.get(cur));\n }\n }\n \n for (Node node : nodes)\n for (int i = 0; i < n; i++)\n if (voc[i].indexOf(node.s) >= 0)\n node.cnt++;\n \n for (Node node : nodes) {\n for (int i = 0; i < 26; i++) {\n String cur = (char)(i+'a') + node.s;\n if (h.containsKey(cur)) node.g.add(h.get(cur));\n }\n for (int i = 0; i < 26; i++) {\n String cur = node.s + (char)(i+'a');\n if (h.containsKey(cur)) node.g.add(h.get(cur));\n }\n }\n \n for (Node node : nodes)\n if (node.points == null)\n play(node);\n \n /*for (Node node : nodes) {\n out.println(node.s);\n out.print(node.cnt);\n out.print(\" \" + node.g.size());\n out.println(\" \" + node.value);\n out.println(node.points[0] + \" \" + node.points[1]);\n out.println();\n }*/\n \n Node ans = h.get(\"\");\n out.println(ans.win ? \"First\" : \"Second\");\n out.println(ans.points[0] + \" \" + ans.points[1]);\n \n out.flush();\n }\n\n static final int M = 30;\n static HashMap h = new HashMap(M*M*M);\n static int n;\n static String[] voc;\n static LinkedList nodes = new LinkedList();\n \n static void play(Node node) {\n for (Node go : node.g) {\n if (go.points == null) play(go);\n long a = go.points[1] + go.value + go.cnt, b = go.points[0];\n boolean win = !go.win;\n if (node.points == null) {\n node.points = new long[]{a, b};\n node.win = win;\n }\n else if (better(win, a, b, node.win, node.points[0], node.points[1])) {\n node.points[0] = a;\n node.points[1] = b;\n node.win = win;\n }\n }\n if (node.points == null) {\n node.points = new long[]{0, 0};\n node.win = false;\n }\n }\n \n static boolean better(boolean win1, long a1, long b1, boolean win2, long a2, long b2) {\n if (win1 == win2) {\n return a1 > a2 || (a1 == a2 && b1 < b2);\n }\n return win1;\n }\n}\n\nclass Node {\n String s;\n long cnt = 0, value;\n HashSet g = new HashSet();\n boolean win;\n long[] points;\n \n public Node(String s) {\n this.s = s;\n int max = Integer.MIN_VALUE;\n for (int i = 0; i < s.length(); i++) {\n int x = s.charAt(i) - 'a' + 1;\n value += x;\n max = Math.max(max, x);\n }\n value *= max;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "35883ff35f28dca6f787f86b9ab04957", "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF38F extends PrintWriter {\n\tCF38F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF38F o = new CF38F(); o.main(); o.flush();\n\t}\n\n\tstatic class V {\n\t\tString s;\n\t\tint i, h;\n\t\tV(String s, int i) {\n\t\t\tthis.s = s; this.i = i;\n\t\t}\n\t}\n\tstatic class U {\n\t\tV v, p, q;\n\t\tU(V v, V p, V q) {\n\t\t\tthis.v = v; this.p = p; this.q = q;\n\t\t}\n\t}\n\tstatic final int T = 30 * 29 / 2;\n\tint score(String s) {\n\t\tint n = s.length(), sum = 0, max = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = s.charAt(i) - 'a' + 1;\n\t\t\tsum += a;\n\t\t\tmax = Math.max(max, a);\n\t\t}\n\t\treturn sum * max;\n\t}\n\tint[] xx;\n\tboolean[] ww; int[] ss, tt;\n\tvoid push(int p, int i) {\n\t\tint s = tt[i] + xx[i], t = ss[i];\n\t\tif (!ww[p]) {\n\t\t\tif (!ww[i]) {\n\t\t\t\tww[p] = true;\n\t\t\t\tss[p] = s; tt[p] = t;\n\t\t\t} else if (ss[p] < s || ss[p] == s && tt[p] > t) {\n\t\t\t\tss[p] = s; tt[p] = t;\n\t\t\t}\n\t\t} else if (!ww[i] && (ss[p] < s || ss[p] == s && tt[p] > t)) {\n\t\t\tss[p] = s; tt[p] = t;\n\t\t}\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tU[] uu = new U[n * T];\n\t\tV[] vv = new V[n * T * 3];\n\t\tint nu = 0, nv = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = sc.next();\n\t\t\tint m = s.length();\n\t\t\tfor (int l = 0; l < m; l++)\n\t\t\t\tfor (int r = l; r < m; r++) {\n\t\t\t\t\tString t = s.substring(l, r + 1);\n\t\t\t\t\tV v = new V(t, i);\n\t\t\t\t\tV p = new V(t.substring(1), -1);\n\t\t\t\t\tV q = new V(t.substring(0, r - l), -1);\n\t\t\t\t\tU u = new U(v, p, q);\n\t\t\t\t\tvv[nv++] = v; vv[nv++] = p; vv[nv++] = q;\n\t\t\t\t\tuu[nu++] = u;\n\t\t\t\t}\n\t\t}\n\t\tArrays.sort(vv, 0, nv, (u, v) -> {\n\t\t\tint mu = u.s.length(), mv = v.s.length();\n\t\t\tif (mu != mv)\n\t\t\t\treturn mu - mv;\n\t\t\tint c = u.s.compareTo(v.s);\n\t\t\treturn c != 0 ? c : u.i - v.i;\n\t\t});\n\t\txx = new int[nu + 1];\n\t\tint k = 0;\n\t\tfor (int i = 0, j; i < nv; ) {\n\t\t\tString s = vv[i].s;\n\t\t\tfor (j = i; j < nv && vv[j].s.equals(s); j++)\n\t\t\t\tvv[j].h = k;\n\t\t\tint x = score(s);\n\t\t\twhile (i < j) {\n\t\t\t\tif (vv[i].i != -1 && (i + 1 == j || vv[i].i != vv[i + 1].i))\n\t\t\t\t\tx++;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\txx[k++] = x;\n\t\t}\n\t\tint[] pp = new int[k];\n\t\tint[] qq = new int[k];\n\t\tfor (int i = 0; i < nu; i++) {\n\t\t\tU u = uu[i];\n\t\t\tpp[u.v.h] = u.p.h;\n\t\t\tqq[u.v.h] = u.q.h;\n\t\t}\n\t\tww = new boolean[k]; ss = new int[k]; tt = new int[k];\n\t\tfor (int i = k - 1; i > 0; i--) {\n\t\t\tpush(pp[i], i); push(qq[i], i);\n\t\t}\n\t\tprintln(ww[0] ? \"First\" : \"Second\");\n\t\tprintln(ss[0] + \" \" + tt[0]);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "54c2911c848d71457159323d00456950", "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\n\tprivate static PrintWriter pw = null;\n\tprivate static BufferedReader br = null;\n\tprivate static StringTokenizer stk = null;\n\n\tpublic boolean tknize() {\n\t\ttry {\n\t\t\tstk = new StringTokenizer(br.readLine());\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic int ni() {\n\t\twhile (stk == null || !stk.hasMoreTokens())\n\t\t\ttknize();\n\t\treturn Integer.valueOf(stk.nextToken());\n\t}\n\n\tpublic long nl() {\n\t\twhile (stk == null || !stk.hasMoreTokens())\n\t\t\ttknize();\n\t\treturn Long.valueOf(stk.nextToken());\n\t}\n\n\tpublic double nd() {\n\t\twhile (stk == null || !stk.hasMoreTokens())\n\t\t\ttknize();\n\t\treturn Double.valueOf(stk.nextToken());\n\t}\n\n\tpublic String nwrd() {\n\t\twhile (stk == null || !stk.hasMoreTokens())\n\t\t\ttknize();\n\t\treturn stk.nextToken();\n\t}\n\n\tpublic BigInteger nbi() {\n\t\twhile (stk == null || !stk.hasMoreTokens())\n\t\t\ttknize();\n\t\treturn new BigInteger(stk.nextToken());\n\t}\n\n\tpublic String rline() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Error: rline() No newline\");\n\t\t}\n\t}\n\n\tpublic boolean isready() {\n\t\ttry {\n\t\t\treturn br.ready();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(\n\t\t\t\t\t\"Error: isready() Error in BufferedReader.ready()\");\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tpw = new PrintWriter(System.out);\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tnew Thread(new Solution()).run();\n\t}\n\n\tpublic void run() {\n\t\tsolve();\n\t\tpw.close();\n\t}\n\n\tclass Dual implements Comparable {\n\t\tlong x, y;\n\n\t\tpublic int compareTo(Dual o) {\n\t\t\tif (x < o.x)\n\t\t\t\treturn -1;\n\t\t\tif (x > o.x)\n\t\t\t\treturn 1;\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tprivate void solve() {\n\t\tint n = ni();\n\t\tString[] dict = new String[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tdict[i] = nwrd();\n\t\tHashMap hm = new HashMap();\n\t\thm.put(\"\", 0);\n\t\tint c = 1;\n\t\tint[][][] indx = new int[n][30][30];\n\t\tint[] cnt = new int[200];\n\t\tString[] st = new String[200];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int l = 1; l <= dict[i].length(); l++)\n\t\t\t\tfor (int s = 0; s < dict[i].length() - l + 1; s++) {\n\t\t\t\t\tString ss = dict[i].substring(s, s + l);\n\t\t\t\t\tInteger t = hm.get(ss);\n\t\t\t\t\tif (t == null)\n\t\t\t\t\t\tt = c++;\n\t\t\t\t\thm.put(ss, t);\n\t\t\t\t\tindx[i][s][s + l - 1] = t;\n\t\t\t\t\tcnt[t]++;\n\t\t\t\t\tst[t] = ss;\n\t\t\t\t}\n\t\tint[][] tos = new int[52][c];\n\t\tfor (int i = 0; i < 52; i++)\n\t\t\tArrays.fill(tos[i], -1);\n\t\tint[][] frs = new int[2][c];\n\t\tint[] cis = new int[c];\n\t\tint[] pts = new int[c];\n\t\tfor (int i = 1; i < c; i++) {\n\t\t\t\tString p1 = st[i].substring(1);\n\t\t\t\tString p2 = st[i].substring(0, st[i].length() - 1);\n\t\t\t\tint ip1 = hm.get(p1);\n\t\t\t\tint ip2 = hm.get(p2);\n\t\t\t\tfrs[0][i] = ip1;\n\t\t\t\tfrs[1][i] = ip2;\n\t\t\t\ttos[st[i].charAt(0) - 'a'][ip1] = i;\n\t\t\t\tcis[ip1]++;\n\t\t\t\tcis[ip2]++;\n\t\t\t\ttos[st[i].charAt(st[i].length() - 1) - 'a' + 26][ip2] = i;\n\t\t\tint mx = 0;\n\t\t\tfor (int j = 0; j < st[i].length(); j++) {\n\t\t\t\tpts[i] += st[i].charAt(j) - 'a' + 1;\n\t\t\t\tif (st[i].charAt(j) - 'a' + 1 > mx)\n\t\t\t\t\tmx = st[i].charAt(j) - 'a' + 1;\n\t\t\t}\n\t\t\tpts[i] *= mx;\n\t\t\tpts[i] += cnt[i];\n\t\t}\n\t\tint[] winp = new int[c];\n\t\tint[] losp = new int[c];\n\t\tboolean[] loose = new boolean[c];\n\t\tLinkedList qu = new LinkedList();\n\t\tfor (int i = 0; i < c; i++)\n\t\t\tif (cis[i] == 0)\n\t\t\t\tqu.add(i);\n\t\twhile (!qu.isEmpty()) {\n\t\t\tint x = qu.pollFirst();\n\t\t\tboolean bestWin = false;\n\t\t\tint bestWp = 0;\n\t\t\tint bestLp = 0;\n\t\t\tfor (int i = 0; i < 52; i++)\n\t\t\t\tif (tos[i][x] != -1) {\n\t\t\t\t\tint cc = tos[i][x];\n\t\t\t\t\tint nWp = losp[cc] + pts[cc];\n\t\t\t\t\tint nLp = winp[cc];\n\t\t\t\t\tif (loose[cc])\n\t\t\t\t\t\tif (!bestWin) {\n\t\t\t\t\t\t\tbestWin = true;\n\t\t\t\t\t\t\tbestWp = nWp;\n\t\t\t\t\t\t\tbestLp = nLp;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (nWp > bestWp || (nWp == bestWp && nLp < bestLp)) {\n\t\t\t\t\t\t\t\tbestWp = nWp;\n\t\t\t\t\t\t\t\tbestLp = nLp;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (!bestWin) {\n\t\t\t\t\t\tif (nWp > bestWp || (nWp == bestWp && nLp < bestLp)) {\n\t\t\t\t\t\t\tbestWp = nWp;\n\t\t\t\t\t\t\tbestLp = nLp;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\twinp[x]=bestWp;\n\t\t\tlosp[x]=bestLp;\n\t\t\tloose[x] = !bestWin;\n\t\t\tif (frs[0][x] != -1) {\n\t\t\t\tcis[frs[0][x]]--;\n\t\t\t\tif (cis[frs[0][x]] == 0)\n\t\t\t\t\tqu.add(frs[0][x]);\n\t\t\t\tcis[frs[1][x]]--;\n\t\t\t\tif (cis[frs[1][x]] == 0)\n\t\t\t\t\tqu.add(frs[1][x]);\n\t\t\t}\n\t\t}\n\t\tif (!loose[0])\n\t\t\tpw.println(\"First\");\n\t\telse\n\t\t\tpw.println(\"Second\");\n\t\tpw.println(winp[0]+\" \"+losp[0]);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "626fa2c568ce581fffea277aabd7a654", "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.HashSet;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Sabelan\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static final long mult = (long) 1e6;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n HashSet hs = new HashSet();\n for (int i = 0; i < m; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n hs.add(key(a, b));\n }\n\n if (n <= 6) {\n int e = n * (n - 1) / 2;\n\n boolean works = false;\n int[] a = new int[m];\n int[] b = new int[m];\n for (int i = 0; i < (1 << e) && !works; i++) {\n if (Integer.bitCount(i) != m) continue;\n int[] deg = new int[n];\n int bit = 0;\n int ii = 0;\n boolean badFlag = false;\n for (int j = 0; j < n; j++) {\n for (int k = j + 1; k < n; k++) {\n if ((i & (1 << bit)) != 0) {\n deg[j]++;\n deg[k]++;\n a[ii] = j;\n b[ii] = k;\n\n ii++;\n if (deg[j] > 2 || deg[k] > 2 || hs.contains(key(j, k)))\n badFlag = true;\n }\n bit++;\n }\n }\n\n if (!badFlag) {\n works = true;\n }\n }\n\n if (!works) {\n out.printf(\"-1\\n\");\n } else {\n for (int i = 0; i < m; i++) {\n out.printf(\"%d %d\\n\", a[i] + 1, b[i] + 1);\n }\n }\n } else {\n int[] deg = new int[n];\n Random r = new Random();\n for (int i = 0; i < m; i++) {\n while (true) {\n int a = r.nextInt(n);\n int b = r.nextInt(n);\n if (a == b) continue;\n if (hs.contains(key(a, b))) continue;\n if (deg[a] >= 2 || deg[b] >= 2) continue;\n\n out.printf(\"%d %d\\n\", a + 1, b + 1);\n deg[a]++;\n deg[b]++;\n hs.add(key(a, b));\n break;\n }\n }\n }\n }\n\n static long key(int a, int b) {\n if (a <= b) return a * mult + b;\n return key(b, a);\n }\n}\n\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n\n public String next() {\n try {\n if (st.hasMoreTokens()) return st.nextToken();\n st = new StringTokenizer(br.readLine());\n return next();\n } catch (Exception e) {\n return \"\";\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "89f3e2f85bbb3e8905d76c02e15e91ea", "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.HashSet;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Sabelan\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static final long mult = (long) 1e6;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n HashSet hs = new HashSet();\n for (int i = 0; i < m; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n hs.add(key(a, b));\n }\n\n if (n <= 6) {\n int e = n * (n - 1) / 2;\n\n boolean works = false;\n int[] a = new int[m];\n int[] b = new int[m];\n for (int i = 0; i < (1 << e) && !works; i++) {\n if (Integer.bitCount(i) != m) continue;\n int[] deg = new int[n];\n int bit = 0;\n int ii = 0;\n boolean badFlag = false;\n for (int j = 0; j < n; j++) {\n for (int k = j + 1; k < n; k++) {\n if ((i & (1 << bit)) != 0) {\n deg[j]++;\n deg[k]++;\n a[ii] = j;\n b[ii] = k;\n\n ii++;\n if (deg[j] > 2 || deg[k] > 2 || hs.contains(key(j, k)))\n badFlag = true;\n }\n bit++;\n }\n }\n\n if (!badFlag) {\n works = true;\n }\n }\n\n if (!works) {\n out.printf(\"-1\\n\");\n } else {\n for (int i = 0; i < m; i++) {\n out.printf(\"%d %d\\n\", a[i] + 1, b[i] + 1);\n }\n }\n } else {\n int[] deg = new int[n];\n Random r = new Random();\n for (int i = 0; i < m; i++) {\n while (true) {\n int a = r.nextInt(n);\n int b = r.nextInt(n);\n if (a == b) continue;\n if (hs.contains(key(a, b))) continue;\n if (deg[a] >= 2 || deg[b] >= 2) continue;\n\n out.printf(\"%d %d\\n\", a + 1, b + 1);\n deg[a]++;\n deg[b]++;\n hs.add(key(a, b));\n break;\n }\n }\n }\n }\n\n static long key(int a, int b) {\n if (a <= b) return a * mult + b;\n return key(b, a);\n }\n\n}\n\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n\n public String next() {\n try {\n if (st.hasMoreTokens()) return st.nextToken();\n st = new StringTokenizer(br.readLine());\n return next();\n } catch (Exception e) {\n return \"\";\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7eba2dd29c3c5f8757d8e8e708182c8c", "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.TreeSet;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Sabelan\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static final long mult = (long) 1e6;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n TreeSet hs = new TreeSet();\n for (int i = 0; i < m; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n hs.add(key(a, b));\n }\n\n if (n <= 6) {\n int e = n * (n - 1) / 2;\n\n boolean works = false;\n int[] a = new int[m];\n int[] b = new int[m];\n for (int i = 0; i < (1 << e) && !works; i++) {\n if (Integer.bitCount(i) != m) continue;\n int[] deg = new int[n];\n int bit = 0;\n int ii = 0;\n boolean badFlag = false;\n for (int j = 0; j < n; j++) {\n for (int k = j + 1; k < n; k++) {\n if ((i & (1 << bit)) != 0) {\n deg[j]++;\n deg[k]++;\n a[ii] = j;\n b[ii] = k;\n\n ii++;\n if (deg[j] > 2 || deg[k] > 2 || hs.contains(key(j, k)))\n badFlag = true;\n }\n bit++;\n }\n }\n\n if (!badFlag) {\n works = true;\n }\n }\n\n if (!works) {\n out.printf(\"-1\\n\");\n } else {\n for (int i = 0; i < m; i++) {\n out.printf(\"%d %d\\n\", a[i] + 1, b[i] + 1);\n }\n }\n } else {\n int[] deg = new int[n];\n Random r = new Random();\n for (int i = 0; i < m; i++) {\n while (true) {\n int a = r.nextInt(n);\n int b = r.nextInt(n);\n if (a == b) continue;\n if (hs.contains(key(a, b))) continue;\n if (deg[a] >= 2 || deg[b] >= 2) continue;\n\n out.printf(\"%d %d\\n\", a + 1, b + 1);\n deg[a]++;\n deg[b]++;\n hs.add(key(a, b));\n break;\n }\n }\n }\n }\n\n static long key(int a, int b) {\n if (a <= b) return a * mult + b;\n return key(b, a);\n }\n\n}\n\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n\n public String next() {\n try {\n if (st.hasMoreTokens()) return st.nextToken();\n st = new StringTokenizer(br.readLine());\n return next();\n } catch (Exception e) {\n return \"\";\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e706102a371a3593c3eb18e4087da349", "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.util.HashSet;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Sabelan\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastWriter out = new FastWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static final long mult = (long) 1e6;\n\n public void solve(int testNumber, FastScanner in, FastWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n HashSet hs = new HashSet();\n for (int i = 0; i < m; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n hs.add(key(a, b));\n }\n\n if (n <= 6) {\n int e = n * (n - 1) / 2;\n\n boolean works = false;\n int[] a = new int[m];\n int[] b = new int[m];\n for (int i = 0; i < (1 << e) && !works; i++) {\n if (Integer.bitCount(i) != m) continue;\n int[] deg = new int[n];\n int bit = 0;\n int ii = 0;\n boolean badFlag = false;\n for (int j = 0; j < n; j++) {\n for (int k = j + 1; k < n; k++) {\n if ((i & (1 << bit)) != 0) {\n deg[j]++;\n deg[k]++;\n a[ii] = j;\n b[ii] = k;\n\n ii++;\n if (deg[j] > 2 || deg[k] > 2 || hs.contains(key(j, k)))\n badFlag = true;\n }\n bit++;\n }\n }\n\n if (!badFlag) {\n works = true;\n }\n }\n\n if (!works) {\n out.printf(\"-1\\n\");\n } else {\n for (int i = 0; i < m; i++) {\n out.printf(\"%d %d\\n\", a[i] + 1, b[i] + 1);\n }\n }\n } else {\n int[] deg = new int[n];\n Random r = new Random();\n for (int i = 0; i < m; i++) {\n while (true) {\n int a = r.nextInt(n);\n int b = r.nextInt(n);\n if (a == b) continue;\n if (hs.contains(key(a, b))) continue;\n if (deg[a] >= 2 || deg[b] >= 2) continue;\n\n out.printf(\"%d %d\\n\", a + 1, b + 1);\n deg[a]++;\n deg[b]++;\n hs.add(key(a, b));\n break;\n }\n }\n }\n }\n\n static long key(int a, int b) {\n if (a <= b) return a * mult + b;\n return key(b, a);\n }\n\n}\n\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n\n public String next() {\n try {\n if (st.hasMoreTokens()) return st.nextToken();\n st = new StringTokenizer(br.readLine());\n return next();\n } catch (Exception e) {\n return \"\";\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}\n\nclass FastWriter extends PrintWriter {\n public FastWriter(OutputStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n }\n\n// public FastWriter(Writer out) {\n// super(new BufferedWriter(out));\n// }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2105db6540e7cd059557726521c03e84", "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.BitSet;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.NoSuchElementException;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ogiekako\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tMyScanner in = new MyScanner(inputStream);\n\t\tMyPrintWriter out = new MyPrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n // 2944730\n int p;\n int[] primes;\n int[] candidates;\n int numCandidates;\n int L,R;\n public void solve(int testNumber, MyScanner in, MyPrintWriter out) {\n int N = (int) 1e9;\n L = in.nextInt(); R = in.nextInt();\n p = in.nextInt();\n if(p<3){\n out.println(0);return;\n }\n primes = MathUtils.generatePrimes(p + 1);\n candidates = new int[2944730];\n Arrays.fill(candidates, Integer.MAX_VALUE);\n numCandidates = 0;\n gen(0, 1L, N);\n Arrays.sort(candidates);\n int[] dist = new int[numCandidates];\n Arrays.fill(dist, Integer.MAX_VALUE);\n dist[0] = 0;// 1\n boolean[] answer = new boolean[numCandidates];\n// HashMap map = new HashMap();\n// for(int i=0;i= 0; i--)if(dist[i] < p - n){\n long cur = (long)candidates[i] * n;\n int mul = 1;\n while(cur <= N){\n int j = Arrays.binarySearch(candidates, (int)cur);\n// int j = map.get((int)cur);\n dist[j] = Math.min(dist[j], dist[i] + mul);\n mul++;\n cur *= n;\n }\n }\n for(int i=0;i= primes.length) {\n candidates[numCandidates++] = (int) number;\n return;\n }\n while (number <= N) {\n gen(p + 1, number, N);\n number *= primes[p];\n }\n }\n}\n\nclass MyScanner {\n private final InputStream in;\n\n public MyScanner(InputStream in) {\n this.in = in;\n }\n\n int bufLen;\n int bufPtr;\n byte[] buf = new byte[1024];\n\n public int read() {\n if (bufLen == -1)\n throw new InputMismatchException();\n if (bufPtr >= bufLen) {\n bufPtr = 0;\n try {\n bufLen = in.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (bufLen <= 0)\n return -1;\n }\n return buf[bufPtr++];\n }\n\n public int nextInt() {\n try {\n int c = read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n\n }\n\nclass MyPrintWriter {\n PrintWriter out;\n\n public MyPrintWriter(OutputStream outputStream) {\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public MyPrintWriter(Writer writer) {\n out = new PrintWriter(writer);\n }\n\n public void println(Object... os) {\n for (int i = 0; i < os.length - 1; i++) {\n out.print(os[i]);\n out.print(' ');\n }\n out.println(os[os.length - 1]);\n }\n\n public void close() {\n out.close();\n }\n\n }\n\nclass MathUtils {\n\n public static int[] generatePrimes(int upTo) {\n int N = upTo;\n boolean[] isPrime = generatePrimaryTable(N);\n int m = 0;\n for (boolean p : isPrime) if (p) m++;\n int[] res = new int[m];\n m = 0;\n for (int i = 0; i < isPrime.length; i++) {\n if (isPrime[i]) res[m++] = i;\n }\n return res;\n }\n\n public static boolean[] generatePrimaryTable(int n) {\n boolean[] isPrime = new boolean[n];\n Arrays.fill(isPrime, true);\n if (0 < n) isPrime[0] = false;\n if (1 < n) isPrime[1] = false;\n for (int i = 2; i * i < n; i++) {\n if (isPrime[i]) {\n for (int j = i * i; j < n; j += i)\n isPrime[j] = false;\n }\n }\n return isPrime;\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fa53455ec855065a396b255c8592b1d0", "src_uid": "6d898638531e4713774bbd5d47e827bf", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.BitSet;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.NoSuchElementException;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ogiekako\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tMyScanner in = new MyScanner(inputStream);\n\t\tMyPrintWriter out = new MyPrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n // 2944730\n int[] primes;\n int[] candidates;\n int numCandidates;\n public void solve(int testNumber, MyScanner in, MyPrintWriter out) {\n int N = (int) 1e9;\n int L = in.nextInt(), R = in.nextInt();\n int p = in.nextInt();\n if(p<3){\n out.println(0);return;\n }\n primes = MathUtils.generatePrimes(p + 1);\n candidates = new int[2944730];\n Arrays.fill(candidates, Integer.MAX_VALUE);\n numCandidates = 0;\n gen(0, 1L, N);\n Arrays.sort(candidates);\n int[] dist = new int[numCandidates];\n Arrays.fill(dist, Integer.MAX_VALUE);\n dist[0] = 0;// 1\n boolean[] answer = new boolean[numCandidates];\n answer[0] = true;\n for(int n=2;n<=p;n++){\n int j = 0;\n for (int i = 0; i < dist.length; i++)if(dist[i] < Integer.MAX_VALUE && candidates[i] <= N/n){\n while(candidates[j] < candidates[i] * n)j++;\n dist[j] = Math.min(dist[j], dist[i] + 1);\n if(dist[j] + n <= p)answer[j] = true;\n }\n }\n int res = 0;\n for (int i = 0; i < answer.length; i++)if(answer[i] && L <= candidates[i] && candidates[i] <= R)res++;\n out.println(res);\n }\n\n private void gen(int p, long number, int N) {\n if (p >= primes.length) {\n candidates[numCandidates++] = (int) number;\n return;\n }\n while (number <= N) {\n gen(p + 1, number, N);\n number *= primes[p];\n }\n }\n}\n\nclass MyScanner {\n private final InputStream in;\n\n public MyScanner(InputStream in) {\n this.in = in;\n }\n\n int bufLen;\n int bufPtr;\n byte[] buf = new byte[1024];\n\n public int read() {\n if (bufLen == -1)\n throw new InputMismatchException();\n if (bufPtr >= bufLen) {\n bufPtr = 0;\n try {\n bufLen = in.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (bufLen <= 0)\n return -1;\n }\n return buf[bufPtr++];\n }\n\n public int nextInt() {\n try {\n int c = read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n\n }\n\nclass MyPrintWriter {\n PrintWriter out;\n\n public MyPrintWriter(OutputStream outputStream) {\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public MyPrintWriter(Writer writer) {\n out = new PrintWriter(writer);\n }\n\n public void println(Object... os) {\n for (int i = 0; i < os.length - 1; i++) {\n out.print(os[i]);\n out.print(' ');\n }\n out.println(os[os.length - 1]);\n }\n\n public void close() {\n out.close();\n }\n\n }\n\nclass MathUtils {\n\n public static int[] generatePrimes(int upTo) {\n int N = upTo;\n boolean[] isPrime = generatePrimaryTable(N);\n int m = 0;\n for (boolean p : isPrime) if (p) m++;\n int[] res = new int[m];\n m = 0;\n for (int i = 0; i < isPrime.length; i++) {\n if (isPrime[i]) res[m++] = i;\n }\n return res;\n }\n\n public static boolean[] generatePrimaryTable(int n) {\n boolean[] isPrime = new boolean[n];\n Arrays.fill(isPrime, true);\n if (0 < n) isPrime[0] = false;\n if (1 < n) isPrime[1] = false;\n for (int i = 2; i * i < n; i++) {\n if (isPrime[i]) {\n for (int j = i * i; j < n; j += i)\n isPrime[j] = false;\n }\n }\n return isPrime;\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "68fdf24a4f69b05f9809b37c172e60e8", "src_uid": "6d898638531e4713774bbd5d47e827bf", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.BitSet;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.NoSuchElementException;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ogiekako\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tMyScanner in = new MyScanner(inputStream);\n\t\tMyPrintWriter out = new MyPrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n // 2944730\n int p;\n int[] primes;\n int[] candidates;\n int numCandidates;\n int L,R;\n public void solve(int testNumber, MyScanner in, MyPrintWriter out) {\n int N = (int) 1e9;\n L = in.nextInt(); R = in.nextInt();\n p = in.nextInt();\n if(p<3){\n out.println(0);return;\n }\n primes = MathUtils.generatePrimes(p + 1);\n candidates = new int[2944730];\n Arrays.fill(candidates, Integer.MAX_VALUE);\n numCandidates = 0;\n gen(0, 1L, N);\n Arrays.sort(candidates);\n int[] dist = new int[numCandidates];\n Arrays.fill(dist, Integer.MAX_VALUE);\n dist[0] = 0;// 1\n boolean[] answer = new boolean[numCandidates];\n answer[0] = true;\n int T = (int) 5e6;\n int[][] cands = new int[T][];\n int[] ptr = new int[T];\n int[] suf = new int[T];\n Arrays.fill(suf,-1);\n for (int i = 0; i < numCandidates; i++){\n int a = candidates[i] / T;\n if(suf[a]==-1)suf[a] = i;\n if(cands[a]==null){\n cands[a] = new int[1];\n }else if(cands[a].length == ptr[a]){\n int[] nxt = new int[cands[a].length * 2];\n Arrays.fill(nxt,Integer.MAX_VALUE);\n System.arraycopy(cands[a], 0, nxt, 0, cands[a].length);\n cands[a] = nxt;\n }\n cands[a][ptr[a]++] = candidates[i];\n }\n for(int n=2;n<=p;n++){\n for (int i = dist.length-1; i >= 0; i--)if(dist[i] < p - n){\n long cur = (long)candidates[i] * n;\n for(int mul = 1;cur <= N; mul++, cur *= n){\n if(dist[i] + mul + n > p)continue;\n int a = (int) (cur / T);\n int j = Arrays.binarySearch(cands[a], (int)cur) + suf[a];\n dist[j] = Math.min(dist[j], dist[i] + mul);\n if(dist[j] + n <= p)answer[j] = true;\n }\n }\n }\n int res = 0;\n for (int i = 0; i < answer.length; i++)if(answer[i] && L <= candidates[i] && candidates[i] <= R)res++;\n out.println(res);\n }\n\n private void gen(int p, long number, int N) {\n if (p >= primes.length) {\n candidates[numCandidates++] = (int) number;\n return;\n }\n while (number <= N) {\n gen(p + 1, number, N);\n number *= primes[p];\n }\n }\n}\n\nclass MyScanner {\n private final InputStream in;\n\n public MyScanner(InputStream in) {\n this.in = in;\n }\n\n int bufLen;\n int bufPtr;\n byte[] buf = new byte[1024];\n\n public int read() {\n if (bufLen == -1)\n throw new InputMismatchException();\n if (bufPtr >= bufLen) {\n bufPtr = 0;\n try {\n bufLen = in.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (bufLen <= 0)\n return -1;\n }\n return buf[bufPtr++];\n }\n\n public int nextInt() {\n try {\n int c = read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n\n }\n\nclass MyPrintWriter {\n PrintWriter out;\n\n public MyPrintWriter(OutputStream outputStream) {\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public MyPrintWriter(Writer writer) {\n out = new PrintWriter(writer);\n }\n\n public void println(Object... os) {\n for (int i = 0; i < os.length - 1; i++) {\n out.print(os[i]);\n out.print(' ');\n }\n out.println(os[os.length - 1]);\n }\n\n public void close() {\n out.close();\n }\n\n }\n\nclass MathUtils {\n\n public static int[] generatePrimes(int upTo) {\n int N = upTo;\n boolean[] isPrime = generatePrimaryTable(N);\n int m = 0;\n for (boolean p : isPrime) if (p) m++;\n int[] res = new int[m];\n m = 0;\n for (int i = 0; i < isPrime.length; i++) {\n if (isPrime[i]) res[m++] = i;\n }\n return res;\n }\n\n public static boolean[] generatePrimaryTable(int n) {\n boolean[] isPrime = new boolean[n];\n Arrays.fill(isPrime, true);\n if (0 < n) isPrime[0] = false;\n if (1 < n) isPrime[1] = false;\n for (int i = 2; i * i < n; i++) {\n if (isPrime[i]) {\n for (int j = i * i; j < n; j += i)\n isPrime[j] = false;\n }\n }\n return isPrime;\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f5dac9d20221b91a07df353b90450d8b", "src_uid": "6d898638531e4713774bbd5d47e827bf", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.BitSet;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.NoSuchElementException;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ogiekako\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tMyScanner in = new MyScanner(inputStream);\n\t\tMyPrintWriter out = new MyPrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n // 2944730\n int p;\n int[] primes;\n int[] candidates;\n int numCandidates;\n int L,R;\n public void solve(int testNumber, MyScanner in, MyPrintWriter out) {\n int N = (int) 1e9;\n L = in.nextInt(); R = in.nextInt();\n p = in.nextInt();\n if(p<3){\n out.println(0);return;\n }\n primes = MathUtils.generatePrimes(p + 1);\n candidates = new int[2944730];\n Arrays.fill(candidates, Integer.MAX_VALUE);\n numCandidates = 0;\n gen(0, 1L, N);\n Arrays.sort(candidates);\n int[] dist = new int[numCandidates];\n Arrays.fill(dist, Integer.MAX_VALUE);\n dist[0] = 0;// 1\n boolean[] answer = new boolean[numCandidates];\n answer[0] = true;\n int T = (int) 3e6;\n int[][] cands = new int[T][];\n int[] ptr = new int[T];\n int[] suf = new int[T];\n Arrays.fill(suf,-1);\n for (int i = 0; i < numCandidates; i++){\n int a = candidates[i] / T;\n if(suf[a]==-1)suf[a] = i;\n if(cands[a]==null){\n cands[a] = new int[1];\n }else if(cands[a].length == ptr[a]){\n int[] nxt = new int[cands[a].length * 2];\n Arrays.fill(nxt,Integer.MAX_VALUE);\n System.arraycopy(cands[a], 0, nxt, 0, cands[a].length);\n cands[a] = nxt;\n }\n cands[a][ptr[a]++] = candidates[i];\n }\n for(int n=2;n<=p;n++){\n for (int i = dist.length-1; i >= 0; i--)if(dist[i] < p - n){\n long cur = (long)candidates[i] * n;\n for(int mul = 1;cur <= N; mul++, cur *= n){\n if(dist[i] + mul + n > p)continue;\n int a = (int) (cur / T);\n int j = Arrays.binarySearch(cands[a], (int)cur) + suf[a];\n dist[j] = Math.min(dist[j], dist[i] + mul);\n if(dist[j] + n <= p)answer[j] = true;\n }\n }\n }\n int res = 0;\n for (int i = 0; i < answer.length; i++)if(answer[i] && L <= candidates[i] && candidates[i] <= R)res++;\n out.println(res);\n }\n\n private void gen(int p, long number, int N) {\n if (p >= primes.length) {\n candidates[numCandidates++] = (int) number;\n return;\n }\n while (number <= N) {\n gen(p + 1, number, N);\n number *= primes[p];\n }\n }\n}\n\nclass MyScanner {\n private final InputStream in;\n\n public MyScanner(InputStream in) {\n this.in = in;\n }\n\n int bufLen;\n int bufPtr;\n byte[] buf = new byte[1024];\n\n public int read() {\n if (bufLen == -1)\n throw new InputMismatchException();\n if (bufPtr >= bufLen) {\n bufPtr = 0;\n try {\n bufLen = in.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (bufLen <= 0)\n return -1;\n }\n return buf[bufPtr++];\n }\n\n public int nextInt() {\n try {\n int c = read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n\n }\n\nclass MyPrintWriter {\n PrintWriter out;\n\n public MyPrintWriter(OutputStream outputStream) {\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public MyPrintWriter(Writer writer) {\n out = new PrintWriter(writer);\n }\n\n public void println(Object... os) {\n for (int i = 0; i < os.length - 1; i++) {\n out.print(os[i]);\n out.print(' ');\n }\n out.println(os[os.length - 1]);\n }\n\n public void close() {\n out.close();\n }\n\n }\n\nclass MathUtils {\n\n public static int[] generatePrimes(int upTo) {\n int N = upTo;\n boolean[] isPrime = generatePrimaryTable(N);\n int m = 0;\n for (boolean p : isPrime) if (p) m++;\n int[] res = new int[m];\n m = 0;\n for (int i = 0; i < isPrime.length; i++) {\n if (isPrime[i]) res[m++] = i;\n }\n return res;\n }\n\n public static boolean[] generatePrimaryTable(int n) {\n boolean[] isPrime = new boolean[n];\n Arrays.fill(isPrime, true);\n if (0 < n) isPrime[0] = false;\n if (1 < n) isPrime[1] = false;\n for (int i = 2; i * i < n; i++) {\n if (isPrime[i]) {\n for (int j = i * i; j < n; j += i)\n isPrime[j] = false;\n }\n }\n return isPrime;\n }\n\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "80095288e2b4921d350c8ef7bd8a40dd", "src_uid": "6d898638531e4713774bbd5d47e827bf", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\tvoid run() {\n\t\tint n = in.nextInt();\n\t\tint place = in.nextInt();\n\t\tif (place == n + 1) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint needBeHigher = n + 1 - place;\n\t\tlong inf = Long.MAX_VALUE / 3;\n\t\tlong ans = inf;\n//\t\tMap> map = new TreeMap<>();\n//\t\tParticipant[] participants = new Participant[n];\n\t\tint[] points = new int[n];\n\t\tint[] effort = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tparticipants[i] = new Participant(in.nextInt(), in.nextInt());\n\t\t\tpoints[i] = in.nextInt();\n\t\t\teffort[i] = in.nextInt();\n//\t\t\tif (!map.containsKey(points)) {\n//\t\t\t\tmap.put(points, new ArrayList());\n//\t\t\t}\n//\t\t\tmap.get(points).add(efforts);\n\t\t}\n\t\tint[] allPoints = points.clone();\n\t\tArrays.sort(allPoints);\n\t\tint needPoints = allPoints[n - place];\n\t\tfor (int gotPoints = needPoints; gotPoints <= needPoints + 2; gotPoints++) {\n\t\t\tList a = new ArrayList<>();\n\t\t\tList b = new ArrayList<>();\n\t\t\tint c = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint p = points[i];\n\t\t\t\tint e = effort[i];\n\t\t\t\tif (p > gotPoints) {\n\t\t\t\t\ta.add(e);\n\t\t\t\t} else if (p == gotPoints || p == gotPoints - 1) {\n\t\t\t\t\tb.add(e);\n\t\t\t\t} else {\n\t\t\t\t\ta.add(e);\n\t\t\t\t\tc++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tCollections.sort(a);\n\t\t\tCollections.sort(b);\n\t\t\tlong cur = 0;\n\t\t\tint takeB = needBeHigher - c;\n\t\t\tif (takeB > b.size()) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (takeB < 0) {\n\t\t\t\ttakeB = 0;\n\t\t\t}\n\t\t\tint score = 0;\n\t\t\tint ai = 0;\n\t\t\tint bi = 0;\n\t\t\twhile (takeB > 0) {\n\t\t\t\ttakeB--;\n\t\t\t\tcur += b.get(bi);\n\t\t\t\tbi++;\n\t\t\t\tscore++;\n\t\t\t}\n\t\t\twhile (score < gotPoints) {\n\t\t\t\tif (bi < b.size() && (ai == a.size() || b.get(bi) < a.get(ai))) {\n\t\t\t\t\tcur += b.get(bi);\n\t\t\t\t\tbi++;\n\t\t\t\t\tscore++;\n\t\t\t\t} else if (ai < a.size()) {\n\t\t\t\t\tcur += a.get(ai);\n\t\t\t\t\tai++;\n\t\t\t\t\tscore++;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (score >= gotPoints) {\n\t\t\t\tans = Math.min(ans, cur);\n\t\t\t}\n\t\t}\n//\t\tint mustDefeat = n + 1 - place;\n//\t\tint defeated = 0;\n//\t\tfor (int p : map.keySet()) {\n//\t\t\tList curList = map.get(p);\n//\t\t\tCollections.sort(curList);\n//\t\t}\n\t\tSystem.out.println(ans == inf ? -1 : ans);\n\t}\n\t\n//\tclass Participant implements Comparable {\n//\t\tint points;\n//\t\tint effort;\n//\t\t\n//\t\tpublic Participant(int points, int effort) {\n//\t\t\tthis.points = points;\n//\t\t\tthis.effort = effort;\n//\t\t}\n//\n//\t\t@Override\n//\t\tpublic int compareTo(Participant o) {\n//\t\t\treturn 0;\n//\t\t}\n//\t}\n\n\tstatic boolean stdStreams = true;\n\tstatic String fileName = C.class.getSimpleName().replaceFirst(\"_.*\", \"\").toLowerCase();\n\tstatic String inputFileName = fileName + \".in\";\n\tstatic String outputFileName = fileName + \".out\";\n\tstatic MyScanner in;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tLocale.setDefault(Locale.US);\n\t\tBufferedReader br;\n\t\tif (stdStreams) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tbr = new BufferedReader(new FileReader(inputFileName));\n\t\t\tout = new PrintWriter(outputFileName);\n\t\t}\n\t\tin = new MyScanner(br);\n\t\tnew C().run();\n\t\tbr.close();\n\t\tout.close();\n\t}\n\t\n\tstatic class MyScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tMyScanner(BufferedReader br) {\n\t\t\tthis.br = br;\n\t\t}\n\t\t\n\t\tvoid findToken() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tString next() {\n\t\t\tfindToken();\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dc4f7907f0e11ec47a87eea68b488ce6", "src_uid": "19a098cef100fc3652c59abf7c373814", "difficulty": null} {"lang": "Java 7", "source_code": "\n\nimport java.util.*; //Scanner;\nimport java.io.PrintWriter; //PrintWriter\n\npublic class R229_Rocket_C1 //Name: The Tournament\n{\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tsolve(in, out);\n\t\tout.close();\n\t\tin.close();\t\n\t}\n\t\n\tpublic static void solve(Scanner in, PrintWriter out)\n\t{\n\t\tint n = in.nextInt();\t\n\t\tint k = in.nextInt();\n\t\t\n\t\tint[] p = new int[n];\n\t\tint[] e = new int[n];\n\t\tfor (int i = 0; i < n; i++) \n\t\t{\n\t\t\tp[i] = in.nextInt();\n\t\t\te[i] = in.nextInt();\n\t\t}\n\t\t\n\t\tint minEffort = Integer.MAX_VALUE;\n\t\tfor (int bitmask = 0; bitmask < 1< TIE = new PriorityQueue();\n\t\tPriorityQueue OTHER = new PriorityQueue();\n\t\tPerson[] ppl = new Person[N];\n\t\tfor(int a=0;aN){\n\t\t\tout.println(\"-1\");\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n//\t\tSystem.out.println(safe+\" \"+K);\n\t\tcmp = 1;\n\t\tPriorityQueue LAZY = new PriorityQueue();\n\t\tfor(int a=0;asafe){\n\t\t\tused+=TIE.poll().E;\n\t\t\tgoal--;\n//\t\t\tSystem.out.println(\"H\");\n//\t\t\tif(goal<=0)break;\n\t\t}\n\t\tOTHER.addAll(TIE);\n\t\twhile(goal>0){\n\t\t\tK++;\n\t\t\tused+=OTHER.poll().E;\n\t\t}\n\t\t\n\t\tout.println(Math.min(used,eff2));\n\t\t\n\t\tout.close();\n\t}\n\t\n\tstatic class Person implements Comparable{\n\t\tint P,E;\n\t\tPerson(int p, int e){\n\t\t\tP=p;\n\t\t\tE=e;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Person o) {\n\t\t\tif(cmp==0)return o.P-this.P;\n\t\t\treturn this.E-o.E;\n\t\t}\n\t}\n\n\tstatic class FasterScanner{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\t\n\t\tpublic FasterScanner(){\n\t\t\tstream = System.in;\n\t\t\t//stream = new FileInputStream(new File(\"dec.in\"));\n\n\t\t}\n\t\tint read(){\n\t\t\tif(numChars==-1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif(curChar>=numChars){\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e){\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif(numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t\t\n\t\tboolean isSpaceChar(int c){\n\t\t\treturn c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n\t\t}\n\t\tboolean isEndline(int c){\n\t\t\treturn c=='\\n'||c=='\\r'||c==-1;\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString next(){\n\t\t\tint c = read();\n\t\t\twhile(isSpaceChar(c))\n\t\t\t\tc=read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc=read();\n\t\t\t} while(!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\tString nextLine(){\n\t\t\tint c = read();\n\t\t\twhile(isEndline(c))\n\t\t\t\tc=read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}while(!isEndline(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7cb9e594301dfc41d9f0d37bffe08e7c", "src_uid": "19a098cef100fc3652c59abf7c373814", "difficulty": null} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.PriorityQueue;\n\n\npublic class CF {\n\tstatic int cmp;\n\tpublic static void main(String[] args) {\n\t\tFasterScanner sc = new FasterScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt()-1;\n\t\tPriorityQueue TIE = new PriorityQueue();\n\t\tPriorityQueue OTHER = new PriorityQueue();\n\t\tPerson[] ppl = new Person[N];\n\t\tfor(int a=0;aN){\n\t\t\tout.println(\"-1\");\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n//\t\tSystem.out.println(safe+\" \"+K);\n\t\tcmp = 1;\n\t\tPriorityQueue LAZY = new PriorityQueue();\n\t\tfor(int a=0;asafe){\n\t\t\tused+=TIE.poll().E;\n\t\t\tgoal--;\n//\t\t\tSystem.out.println(\"H\");\n//\t\t\tif(goal<=0)break;\n\t\t}\n\t\tOTHER.addAll(TIE);\n\t\twhile(goal>0){\n\t\t\tK++;\n\t\t\tused+=OTHER.poll().E;\n\t\t}\n\t\t\n\t\tout.println(Math.min(used,eff2));\n\t\t\n\t\tout.close();\n\t}\n\t\n\tstatic class Person implements Comparable{\n\t\tint P,E;\n\t\tPerson(int p, int e){\n\t\t\tP=p;\n\t\t\tE=e;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Person o) {\n\t\t\tif(cmp==0)return o.P-this.P;\n\t\t\treturn this.E-o.E;\n\t\t}\n\t}\n\n\tstatic class FasterScanner{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\t\n\t\tpublic FasterScanner(){\n\t\t\tstream = System.in;\n\t\t\t//stream = new FileInputStream(new File(\"dec.in\"));\n\n\t\t}\n\t\tint read(){\n\t\t\tif(numChars==-1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif(curChar>=numChars){\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e){\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif(numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t\t\n\t\tboolean isSpaceChar(int c){\n\t\t\treturn c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n\t\t}\n\t\tboolean isEndline(int c){\n\t\t\treturn c=='\\n'||c=='\\r'||c==-1;\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString next(){\n\t\t\tint c = read();\n\t\t\twhile(isSpaceChar(c))\n\t\t\t\tc=read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc=read();\n\t\t\t} while(!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\tString nextLine(){\n\t\t\tint c = read();\n\t\t\twhile(isEndline(c))\n\t\t\t\tc=read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}while(!isEndline(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "567cf62e44244bd4a57be1a3ee5bbbf3", "src_uid": "19a098cef100fc3652c59abf7c373814", "difficulty": null} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Queue;\n\n\npublic class C {\n static int rec(int idx, int[] a, int[] b) {\n final int len = (1 << idx) - 1;\n final int mid = len / 2;\n if(a[0] >= a[1] || b[0] >= b[1])\n return 0;\n \n// System.err.println(a[0] + \" \" + a[1] + \" \" + b[0] + \" \" + b[1]);\n \n if(a[0] > b[0]) {\n final int[] c = a; a = b; b = c;\n }\n \n if(a[0] <= b[0] && b[1] <= a[1]) {\n return b[1] - b[0];\n }\n \n int res = 0;\n res = Math.max(Math.min(a[1], b[1]) - Math.max(a[0], b[0]), res);\n\n int[][][] rng = new int[2][2][2];\n rng[0][0][0] = a[0];\n rng[0][0][1] = Math.min(a[1], mid);\n \n rng[0][1][0] = Math.max(a[0] - 1, mid) - mid;\n rng[0][1][1] = a[1] - mid - 1;\n\n rng[1][0][0] = b[0];\n rng[1][0][1] = Math.min(b[1], mid);\n \n rng[1][1][0] = Math.max(b[0] - 1, mid) - mid;\n rng[1][1][1] = b[1] - mid - 1;\n \n for(int i = 0; i < 2; i++)\n for(int j = 0; j < 2; j++)\n res = Math.max(res, rec(idx - 1, rng[0][i], rng[1][j]));\n \n return res;\n }\n \n public static void main(String[] args) throws IOException {\n final int l1 = IOFast.nextInt();\n final int r1 = IOFast.nextInt();\n final int l2 = IOFast.nextInt();\n final int r2 = IOFast.nextInt();\n IOFast.out.println(rec(30, new int[] { l1 - 1, r1 }, new int[] { l2 - 1, r2 }));\n \n IOFast.out.flush();\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e9e38484b18419fd60c8c91ce3e878df", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class C {\n\tstatic BufferedReader in;\n\tstatic StringTokenizer strtok;\n\t\n\tstatic String next() throws IOException {\n\t\twhile (strtok == null || !strtok.hasMoreTokens())\n\t\t\tstrtok = new StringTokenizer(in.readLine());\n\t\treturn strtok.nextToken();\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\tstatic int ans = 0;\n\t\n\tstatic void Calc(int level, int l1, int r1, int l2, int r2) {\n\t\tif (l1 > r1 || l2 > r2) return;\n\t\t\n\t\tif (l1 == 0 && r1 == (1 << level) - 1) {\n\t\t\tans = Math.max(ans, r2 - l2 + 1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif (l2 == 0 && r2 == (1 << level) - 1) {\n\t\t\tans = Math.max(ans, r1 - r1 + 1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tans = Math.max(ans, Math.min(r2, r1) - Math.max(l2, l1) + 1);\n\t\tint mid = (1 << (level - 1)) - 1;\n\t\t\n\t\tint L1 = l1, R1 = r1, L2 = l2, R2 = r2;\n\t\t\n\t\tfor (int i = 0; i < 2; ++i) {\n\t\t\tint sl = 0, sr = mid - 1;\n\t\t\tif (i == 1) {\t\n\t\t\t\tsl = mid + 1;\n\t\t\t\tsr = (1 << level) - 1;\n\t\t\t}\n\t\t\t\n\t\t\tl1 = Math.max(L1, sl); r1 = Math.min(R1, sr);\n\t\t\t\n\t\t\tfor (int j = 0; j < 2; ++j) {\n\t\t\t\tint sl1 = 0, sr1 = mid - 1;\n\t\t\t\tif (j == 1) {\n\t\t\t\t\tsl1 = mid + 1;\n\t\t\t\t\tsr1 = (1 << level) - 1;\n\t\t\t\t}\n\n\t\t\t\tl2 = Math.max(L2, sl1); r2 = Math.min(R2, sr1);\n\t\t\t\tCalc(level - 1, l1 - sl, r1 - sl, l2 - sl1, r2 - sl1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static void main(String args[]) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint l1 = nextInt() - 1, r1 = nextInt() - 1;\n\t\tint l2 = nextInt() - 1, r2 = nextInt() - 1;\n\t\tCalc(30 , l1, r1, l2, r2);\n\t\tout.println(ans);\n\t\tout.close();\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7598e7f9ebf45d55af8513f602d82ce7", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\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 l1 = in.nextInt();\n int r1 = in.nextInt();\n int l2 = in.nextInt();\n int r2 = in.nextInt();\n int len = 1;\n for (int step = 0; step < 30; ++step) {\n len = len * 2 + 1;\n }\n long res = rec(l1, r1, l2, r2, len);\n out.println(res);\n }\n\n private long rec(int l1, int r1, int l2, int r2, int len) {\n if (len == 0) {\n return 0;\n }\n if (l1 > r1 || l2 > r2) return 0;\n int center = (len / 2) + 1;\n if (r1 < center && r2 < center) {\n return rec(l1, r1, l2, r2, len / 2);\n }\n if (l1 > center && l2 > center) {\n return rec(len - r1 + 1, len - l1 + 1, len - r2 + 1, len - l2 + 1, len / 2);\n }\n if (r1 < center && l2 > center) {\n return rec(l1, r1, len - r2 + 1, len - l2 + 1, len / 2);\n }\n if (r2 < center && l1 > center) {\n return rec(l2, r2, l1, r1, len);\n }\n if (l1 <= center && r1 >= center) {\n if (l2 <= center && r2 >= center) {\n long max = rec(l1, center-1, l2, r2, len);\n max = Math.max(max, rec(center + 1, r1, l2, r2, len));\n int le = Math.max(l1, l2);\n int ri = Math.min(r1, r2);\n if (le <= ri) {\n max = Math.max(max, ri - le + 1);\n }\n l1 = len - l1 + 1;\n r1 = len - r1 + 1;\n le = Math.max(l1, l2);\n ri = Math.min(r1, r2);\n if (le <= ri) {\n max = Math.max(max, ri - le + 1);\n }\n return max;\n } else {\n long max = rec(l1, center-1, l2, r2, len);\n max = Math.max(max, rec(center + 1, r1, l2, r2, len));\n return max;\n }\n }\n if (l2 <= center && r2 >= center) {\n return rec(l2, r2, l1, r1, len);\n }\n return 0;\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}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "320aceba58ba01ddc2ee1fb42acf70d3", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tBufferedReader in;\n\tStringTokenizer str;\n\tPrintWriter out;\n\tString SK;\n\n\tString next() throws IOException {\n\t\twhile ((str == null) || (!str.hasMoreTokens())) {\n\t\t\tSK = in.readLine();\n\t\t\tif (SK == null)\n\t\t\t\treturn null;\n\t\t\tstr = new StringTokenizer(SK);\n\t\t}\n\t\treturn str.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tint[] len;\n\tint[] pos;\n\n\tint solve(int l1, int r1, int l2, int r2, int type) {\n\t\tif (l1 > r1 || l2 > r2)\n\t\t\treturn 0;\n\t\tif (l1 > l2) {\n\t\t\treturn solve(l2, r2, l1, r1, type);\n\t\t}\n\t\tif (r2 <= r1) {\n\t\t\treturn r2 - l2 + 1;\n\t\t}\n\t\tif (l1 == l2) {\n\t\t\treturn Math.min(r2, r1) - l1 + 1;\n\t\t}\n\t\tif (r1 >= pos[type] && l2 <= pos[type]) {\n\t\t\treturn Math.max(r1 - l2 + 1,\n\t\t\t\t\tsolve(l1, pos[type] - 1, 0, r2 - pos[type] - 1, type - 1));\n\t\t}\n\t\tif (r1 >= pos[type]) {\n\t\t\treturn solve(len[type] - r2 - 1, len[type] - l2 - 1, len[type] - r1\n\t\t\t\t\t- 1, len[type] - l1 - 1, type);\n\t\t}\n\t\tif (r2 < pos[type]) {\n\t\t\treturn solve(l1, r1, l2, r2, type - 1);\n\t\t}\n\t\treturn Math.max(\n\t\t\t\tsolve(l1, r1, l2, pos[type], type - 1),\n\t\t\t\tsolve(l1, r1, Math.max(0, l2 - pos[type] - 1), r2 - pos[type]\n\t\t\t\t\t\t- 1, type - 1));\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint m = 30;\n\t\tlen = new int[m];\n\t\tpos = new int[m];\n\t\tlen[0] = 1;\n\t\tpos[0] = 0;\n\t\tfor (int i = 1; i < m; i++) {\n\t\t\tpos[i] = len[i - 1];\n\t\t\tlen[i] = 2 * len[i - 1] + 1;\n\t\t}\n\t\tout.println(solve(nextInt() - 1, nextInt() - 1, nextInt() - 1,\n\t\t\t\tnextInt() - 1, m - 1));\n\t}\n\n\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C().run();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0cff9991959babd6a7d3c0d392579865", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\t\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\t\n\tint p;\n\t\n\tlong[][] pow(long[][] x, long pow) {\n\t\tlong[][] r = new long[x.length][x.length];\n\t\tfor (int i = 0; i < x.length; ++i) {\n\t\t\tr[i][i] = 1;\n\t\t}\n\t\twhile (pow > 0) {\n\t\t\tif (pow % 2 == 1) {\n\t\t\t\tr = mul(r, x);\n\t\t\t}\n\t\t\tpow /= 2;\n\t\t\tx = mul(x, x);\n\t\t}\n\t\treturn r;\n\t}\n\t\n\tlong[][] mul(long[][] a, long[][] b) {\n\t\tlong[][] c = new long[a.length][a.length];\n\t\tfor (int i = 0; i < a.length; ++i) {\n\t\t\tfor (int j = 0; j < a.length; ++j) {\n\t\t\t\tfor (int k = 0; k < a.length; ++k) {\n\t\t\t\t\tc[i][j] = (c[i][j] + a[i][k] * b[k][j]) % p;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tlong x = nextLong();\n\t\tlong y = nextLong();\n\t\tp = nextInt();\n\t\tlong[] a = new long[n];\n\t\tlong sum = 0;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\ta[i] = nextInt() % p;\n\t\t\tsum = (sum + a[i]) % p;\n\t\t}\n\t\tif (n == 1) {\n\t\t\tout.println(sum);\n\t\t\treturn;\n\t\t}\n\t\tlong[][] m1 = new long[][] {{3, p - 1}, {0, 1}};\n\t\tm1 = pow(m1, x);\n\t\tlong sum1 = (m1[0][0] * sum + m1[0][1] * (a[0] + a[n - 1])) % p;\n\t\tlong[][] f = new long[][] {{0, 1}, {1, 1}};\n\t\tf = pow(f, x);\n\t\tlong ka = f[0][1];\n\t\tlong kb = f[1][1];\n\t\tlong[][] m2 = new long[][] {{3, p - 1}, {0, 1}};\n\t\tm2 = pow(m2, y);\n\t\tlong sum2 = (m2[0][0] * sum1 + m2[0][1] * ((a[0] + ka * a[n - 2] + kb * a[n - 1]) % p)) % p;\n\t\tout.println(sum2);\n\t}\n\n\tSolution() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\teat(\"\");\n\t\t\n\t\tsolve();\n\t\t\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tprivate void eat(String str) {\n\t\tst = new StringTokenizer(str);\n\t}\n\t\n\tString next() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\teat(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Solution();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f2118fdf0f778dae7380aa75ea3cf1c", "src_uid": "b5dd2b94570973b3e312ae4b7a43284f", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.*;\n\n//Codeforces Beta Round #56 (Div. 1), E\npublic class MushroomGnomes {\n\n\tpublic 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\tassert ss.length == 4;\n\t\tint n = Integer.parseInt(ss[0]);\n\t\tlong x = Long.parseLong(ss[1]), y = Long.parseLong(ss[2]);\n\t\tint p = Integer.parseInt(ss[3]), lo = 0, m = 0, hi = 0;\n\t\tlong sum = 0;\n\t\tString s = r.readLine();\n\t\tfor(int i = 0, j = 0; i < n; i++) {\n\t\t\tint l = s.indexOf(' ', j);\n\t\t\tassert l != -1 || i == n - 1;\n\t\t\tint v = Integer.parseInt(l != -1 ? s.substring(j, l) : s.substring(j));\n\t\t\tif(j == 0)\n\t\t\t\tlo = v;\n\t\t\tif(l == -1)\n\t\t\t\thi = v;\n\t\t\tif(i == n - 2)\n\t\t\t\tm = v;\n\t\t\tsum += v;\n\t\t\tj = l + 1;\n\t\t}\n\n\t\tint pow3x = pow(3, x, 2 * p), pow3y = pow(3, y, 2 * p);\n\t\tlong result = sum % p;\n\t\tresult *= pow3x;\n\t\tresult += p;\n\t\tresult -= (pow3x - 1l + 2 * p) % (2 * p) / 2 * (lo + hi) % p;\n\t\tresult %= p;\n\t\tresult *= pow3y;\n\t\tresult += p;\n\t\tresult -= (pow3y - 1l + 2 * p) % (2 * p) / 2 * (lo + fibonacci(m, hi, x + 1, p)) % p;\n\t\tresult %= p;\n\n\t\tSystem.out.println(result);\n\t}\n\n\tprivate static int pow(long a, long n, int p) {\n\t\tlong r = 1;\n\t\twhile(n != 0) {\n\t\t\tif((n & 1) != 0)\n\t\t\t\tr = r * a % p;\n\t\t\ta = a * a % p;\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn (int)r;\n\t}\n\tprivate static long[][] multiple(long[][] a, long[][] b, int p) {\n\t\tlong r[][] = new long[a.length][b[0].length];\n\t\tfor(int i = 0; i < r.length; i++) {\n\t\t\tfor(int j = 0; j < r[i].length; j++) {\n\t\t\t\tfor(int l = 0; l < a[i].length; l++)\n\t\t\t\t\tr[i][j] += a[i][l] * b[l][j];\n\t\t\t\tr[i][j] %= p;\n\t\t\t}\n\t\t}\n\t\treturn r;\n\t}\n\tprivate static int fibonacci(int f0, int f1, long n, int p) {\n\t\tif(--n < 0)\n\t\t\treturn f0;\n\t\tlong[][] a = new long[][]{{0, 1}, {1, 1}}, r = new long[][]{{1, 0}, {0, 1}};\n\t\twhile(n != 0) {\n\t\t\tif((n & 1) != 0)\n\t\t\t\tr = multiple(r, a, p);\n\t\t\ta = multiple(a, a, p);\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn (int)((f0 * r[1][0] + f1 * r[1][1]) % p);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43bc57b2cb2e53544e4311008e5fc5d6", "src_uid": "b5dd2b94570973b3e312ae4b7a43284f", "difficulty": 2600.0} {"lang": "Java 6", "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\tlong x = nextLong();\n\t\tlong y = nextLong();\n\t\tint p = nextInt();\n\t\tint[] a = new int[n];\n\t\tif (n == 1) {\n\t\t\tout.println(nextInt() % p);\n\t\t\treturn;\n\t\t}\n\t\tint min = Integer.MAX_VALUE;\n\t\tint sumAll = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t\tmin = Math.min(min, a[i]);\n\t\t\tsumAll = (sumAll + a[i]) % p;\n\t\t}\n\t\tint first = a[0];\n\t\tint last = n == 1 ? 0 : a[n - 1];\n\t\tint bestSum = Integer.MIN_VALUE;\n\t\tint bestMax = Integer.MIN_VALUE;\n\t\tfor (int i = 0; i + 1 < n; i++) {\n\t\t\tif (a[i] + a[i + 1] > bestSum\n\t\t\t\t\t|| (a[i] + a[i + 1] == bestSum && Math.max(a[i], a[i + 1]) > bestMax)) {\n\t\t\t\tbestSum = a[i] + a[i + 1];\n\t\t\t\tbestMax = Math.max(a[i], a[i + 1]);\n\t\t\t}\n\t\t}\n\t\tint sum1;\n\t\tint max;\n\t\tif (x == 0) {\n\t\t\tmax = Integer.MIN_VALUE;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tmax = Math.max(max, a[i]);\n\t\t\t}\n\t\t\tsum1 = sumAll;\n\t\t} else {\n\t\t\tint got = getIt(sumAll, first, last, p, x);\n\t\t\tsum1 = (got) % p;\n\t\t\tmax = getFib(bestSum - bestMax, bestMax, x, p);\n\t\t}\n\t\tint sum2;\n\t\tif (y == 0) {\n\t\t\tsum2 = sum1;\n\t\t} else {\n\t\t\tsum2 = (getIt(sum1, min, max, p, y)) % p;\n\t\t}\n\t\tout.println((sum2) % p);\n\t}\n\n\tint getIt(int sum, int a, int b, int p, long t) {\n\t\tint ret = (int) ((((long) sum - a - b) % p + p) % p * modPow(3, t, p) % p);\n\t\tret = (int) ((ret + ((long) a + b) % p * (1 + sumPow(3, t, p))) % p);\n\t\treturn ret;\n\t}\n\n\tint sumPow(int a, long b, int mod) {\n\t\tint ret = 0;\n\t\tint c = 1;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) == 1) {\n\t\t\t\tret = (int) (((long) ret * a + c) % mod);\n\t\t\t}\n\t\t\tc = (int) (((long) c * a + c) % mod);\n\t\t\ta = (int) ((long) a * a % mod);\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint getFib(int a, int b, long n, int p) {\n\t\tMatrix m = new Matrix(2);\n\t\tm.a[0][0] = m.a[0][1] = m.a[1][0] = 1;\n\t\tm = modPow(m, n, p);\n\t\treturn (int) (((long) m.a[0][0] * b + (long) m.a[0][1] * a) % p);\n\t}\n\n\tstatic class Matrix {\n\t\tint[][] a;\n\t\tint n;\n\n\t\tMatrix(int n) {\n\t\t\tthis.n = n;\n\t\t\ta = new int[n][n];\n\t\t}\n\n\t\tMatrix multiply(Matrix b, int p) {\n\t\t\tMatrix ret = new Matrix(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\tint got = 0;\n\t\t\t\t\tfor (int k = 0; k < n; k++) {\n\t\t\t\t\t\tgot = (int) ((got + (long) a[i][k] * b.a[k][j] % p) % p);\n\t\t\t\t\t}\n\t\t\t\t\tret.a[i][j] = got;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\n\t}\n\n\tMatrix modPow(Matrix a, long b, int p) {\n\t\tint n = a.n;\n\t\tMatrix ret = new Matrix(n);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tret.a[i][i] = 1;\n\t\t}\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) == 1) {\n\t\t\t\tret = ret.multiply(a, p);\n\t\t\t}\n\t\t\ta = a.multiply(a, p);\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint modPow(int a, long b, int p) {\n\t\tint ret = 1;\n\t\twhile (b > 0) {\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\tb >>= 1;\n\t\t}\n\t\treturn ret;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d45971c5f4e91b3998043d5de524829", "src_uid": "b5dd2b94570973b3e312ae4b7a43284f", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import static java.util.Arrays.deepToString;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Gnomes {\n\n// static final File F_IN = new File(\"inout/cf/beta56/gnomes.in\");\n// static final File F_OUT = new File(\"inout/cf/beta56/gnomes.out\");\n static final InputStream F_IN = System.in;\n static final PrintStream F_OUT = System.out;\n \n int n;\n long x, y, p;\n long[] a;\n long res;\n \n void readInput() throws Exception {\n Scanner sc = new Scanner(F_IN);\n n = sc.nextInt();\n x = sc.nextLong();\n y = sc.nextLong();\n p = sc.nextInt();\n a = new long[n];\n for (int i=0; i>1);\n long[][] B = mul(A2, A2);\n if (n%2==1) return mul(B, A); else return B;\n }\n \n long afterX(long s0, long c, long x) {\n long[][] A = {{3, (p-c)%p}, {0, 1}};\n long[][] AX = pow(A, x);\n long res = AX[0][0]%p*s0%p + AX[0][1];\n return res % p;\n }\n\n long fibo(long n) {\n if (n==0) return 0;\n if (n<3) return 1;\n long[][] A = {{1,1},{1,0}};\n long[][] AN = pow(A, n-1);\n return AN[0][0]%p;\n }\n \n void solveProblem() {\n if (n==1) { res = a[0]; return ; }\n long s0 = 0;\n for (int i=0; i 0 && a[i][j - 1] == '-') {\n return true;\n }\n if (j < a[i].length - 1 && a[i][j + 1] == '-') {\n return true;\n }\n }\n }\n }\n return false;\n }\n\n private boolean redCanMove(char[][] a) {\n for (int i = 0; i < a.length; ++i) {\n for (int j = 0; j < a[i].length; ++j) {\n if (a[i][j] == 'R') {\n if (j > 0 && a[i][j - 1] == '-') {\n return true;\n }\n if (j < a[i].length - 1 && a[i][j + 1] == '-') {\n return true;\n }\n }\n }\n }\n return false;\n }\n\n private int who(char[][] a, int n, int m, int k) {\n if (!greenCanMove(a)) {\n return 2;\n }\n\n if (!redCanMove(a)) {\n return 1;\n }\n\n ArrayList stone = new ArrayList();\n\n for (int i = 0; i < n; ++i) {\n int L = 0, R = m - 1;\n\n while (L < m && a[i][L] == '-') {\n ++L;\n }\n\n while (R >= 0 && a[i][R] == '-') {\n --R;\n }\n \n if (R < 0) {\n continue;\n } \n\n if (a[i][L] == a[i][R]) {\n return 0;\n }\n\n stone.add(R - L - 1);\n }\n\n boolean win = false;\n for (int bit = 0; bit <= 20; ++bit) {\n int sum = 0;\n for (int i = 0; i < stone.size(); ++i) {\n sum = sum + ((stone.get(i) >> bit) & 1);\n }\n if (sum % (k + 1) != 0) {\n win = true;\n }\n }\n \n return win ? 1 : 2; \n }\n\n public void run() {\n Scanner scanner = new Scanner(System.in);\n\n String[] args = scanner.nextLine().split(\" \");\n\n int n = Integer.parseInt(args[0]);\n int m = Integer.parseInt(args[1]);\n int k = Integer.parseInt(args[2]);\n\n char[][] a = new char[n][];\n for (int i = 0; i < n; ++i) {\n a[i] = scanner.nextLine().toCharArray();\n }\n\n int ret = who(a, n, m, k);\n if (ret == 0) {\n System.out.println(\"Draw\");\n } else if (ret == 1) {\n System.out.println(\"First\");\n } else {\n System.out.println(\"Second\");\n }\n\n scanner.close();\n }\n\n public static void main(String[] args) {\n new C().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50b373d7b75d2ff8446fd3bf5342f59d", "src_uid": "69062f7c9b834e925ab23ebc2da96b52", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\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 out = new PrintWriter(System.out);\n\t\tint R = sc.nextInt(), C = sc.nextInt(), k = sc.nextInt();\n\t\tArrayList piles = new ArrayList<>();\n\t\tboolean GNotLosing = false, RNotLosing = false;\n\t\tfor(int i = 0; i < R; i++)\n\t\t{\n\t\t\tchar[] row = sc.next().toCharArray();\n\t\t\tint s = -1, e = -1;\n\t\t\tchar f = '#', l = '#';\n\t\t\tfor(int j = 0; j < C; j++)\n\t\t\t{\n\t\t\t\tif(row[j] != '-' && s == -1)\n\t\t\t\t{\n\t\t\t\t\ts = j;\n\t\t\t\t\tf = row[j];\n\t\t\t\t}\n\t\t\t\telse if(row[j] != '-' && s != -1)\n\t\t\t\t{\n\t\t\t\t\te = j;\n\t\t\t\t\tl = row[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(f == '#') continue;\n\t\t\tif(l == '#')\n\t\t\t{\n\t\t\t\tif(f == 'G' && row.length > 1) GNotLosing = true;\n\t\t\t\telse if(f == 'R' && row.length > 1)RNotLosing = true;\n\t\t\t}\n\t\t\telse if(f != l)\n\t\t\t\tpiles.add(indent(Integer.toBinaryString(e - s - 1)));\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(f == 'G' && row.length > 2) GNotLosing = true;\n\t\t\t\telse if(f == 'R' && row.length > 2)RNotLosing = true;\n\t\t\t}\n\t\t}\n\t\tif(RNotLosing && GNotLosing)\n\t\t{\n\t\t\tout.println(\"Draw\");\n\t\t\tout.flush();\n\t\t\treturn;\n\t\t}\n\t\tif(GNotLosing)\n\t\t{\n\t\t\tout.println(\"First\");\n\t\t\tout.flush();\n\t\t\treturn;\n\t\t}\n\t\tif(RNotLosing)\n\t\t{\n\t\t\tout.println(\"Second\");\n\t\t\tout.flush();\n\t\t\treturn;\n\t\t}\n//\t\tfor(String pile : piles)\n//\t\t\tSystem.out.println(pile);\n\t\t\n\t\tfor(int i = 0; i < 7; i++)\n\t\t{\n\t\t\tint c = 0;\n\t\t\tfor(String pile : piles)\n\t\t\t\tc += pile.charAt(i) - '0';\n\t\t\tif(c % (k + 1) != 0)\n\t\t\t{\n\t\t\t\tout.println(\"First\");\n\t\t\t\tout.flush();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\t\t\n\t\tout.println(\"Second\");\n\t\tout.flush();\n\t}\n\t\n\tstatic String indent(String s)\n\t{\n\t\twhile(s.length() < 7) s = \"0\" + s;\n\t\treturn s;\n\t}\n\t\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}\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\t\tpublic String nextLine()throws IOException{return br.readLine();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\tpublic double nextDouble() throws IOException {return Double.parseDouble(next());}\n\t\tpublic char nextChar()throws IOException{return next().charAt(0);}\n\t\tpublic Long nextLong()throws IOException{return Long.parseLong(next());}\n\t\tpublic boolean ready() throws IOException{return br.ready();}\n\t\tpublic void waitForInput(){for(long i = 0; i < 3e9; i++);}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "531262435a15d559c64b4e0bb7f857ca", "src_uid": "69062f7c9b834e925ab23ebc2da96b52", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint rowCount = in.readInt();\n\t\tint columnCount = in.readInt();\n\t\tif (columnCount == 1) {\n\t\t\tout.printLine(\"Second\");\n\t\t\treturn;\n\t\t}\n\t\tint maxPerMove = in.readInt();\n\t\tchar[][] field = IOUtils.readTable(in, rowCount, columnCount);\n\t\tif (columnCount == 2) {\n\t\t\tboolean firstCanMove = false;\n\t\t\tboolean secondCanMove = false;\n\t\t\tfor (int i = 0; i < rowCount; i++) {\n\t\t\t\tif (field[i][0] == 'G' && field[i][1] == '-' || field[i][1] == 'G' && field[i][0] == '-')\n\t\t\t\t\tfirstCanMove = true;\n\t\t\t\tif (field[i][0] == 'R' && field[i][1] == '-' || field[i][1] == 'R' && field[i][0] == '-')\n\t\t\t\t\tsecondCanMove = true;\n\t\t\t}\n\t\t\tif (!firstCanMove)\n\t\t\t\tout.printLine(\"Second\");\n\t\t\telse if (!secondCanMove)\n\t\t\t\tout.printLine(\"First\");\n\t\t\telse\n\t\t\t\tout.printLine(\"Draw\");\n\t\t\treturn;\n\t\t}\n\t\tint[] distance = new int[rowCount];\n\t\tboolean firstCanSkip = false;\n\t\tboolean secondCanSkip = false;\n\t\tfor (int i = 0; i < rowCount; i++) {\n\t\t\tint rPosition = -1;\n\t\t\tint gPosition = -1;\n\t\t\tfor (int j = 0; j < columnCount; j++) {\n\t\t\t\tif (field[i][j] == 'G')\n\t\t\t\t\tgPosition = j;\n\t\t\t\telse if (field[i][j] == 'R')\n\t\t\t\t\trPosition = j;\n\t\t\t}\n\t\t\tif (rPosition == -1) {\n\t\t\t\tif (gPosition != -1)\n\t\t\t\t\tfirstCanSkip = true;\n\t\t\t} else if (gPosition == -1)\n\t\t\t\tsecondCanSkip = true;\n\t\t\telse\n\t\t\t\tdistance[i] = Math.abs(rPosition - gPosition) - 1;\n\t\t}\n\t\tif (firstCanSkip) {\n\t\t\tif (secondCanSkip) {\n\t\t\t\tout.printLine(\"Draw\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tout.printLine(\"First\");\n\t\t\treturn;\n\t\t} else if (secondCanSkip) {\n\t\t\tout.printLine(\"Second\");\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 0; i < 7; i++) {\n\t\t\tint current = 0;\n\t\t\tfor (int j : distance)\n\t\t\t\tcurrent += j >> i & 1;\n\t\t\tif (current % (maxPerMove + 1) != 0) {\n\t\t\t\tout.printLine(\"First\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.printLine(\"Second\");\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(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 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 char[][] readTable(InputReader in, int rowCount, int 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\t}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2719cda10cb42169ed0ef4d275c1c58", "src_uid": "69062f7c9b834e925ab23ebc2da96b52", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: mac\n * Date: 12-1-12\n * Time: \u4e0b\u534810:52\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class d {\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n 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 String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n void solve() throws IOException {\n int n = nextInt(), m = nextInt(), k = nextInt();\n String[] lines = new String[n];\n int nR = 0, nG = 0;\n for (int i = 0; i < n; i++) {\n lines[i] = nextToken();\n for (char c : lines[i].toCharArray()) {\n if (c == 'R')\n ++nR;\n if (c == 'G')\n ++nG;\n }\n }\n if (nG == 0) {\n System.out.println(\"Second\");\n return;\n }\n boolean cantDieR = false, cantDieG = false;\n\n if (m == 1) {\n System.out.println(\"Second\");\n return;\n }\n\n int[] xor = new int[10];\n\n for (String line : lines) {\n boolean hasR = line.indexOf('R') >= 0, hasG = line.indexOf('G') >= 0;\n if (!hasR && !hasG)\n continue;\n if (hasR && hasG) {\n if (line.indexOf(\"RG\") >= 0 || line.indexOf(\"GR\") >= 0)\n continue;\n\n int a = line.indexOf('R'), b = line.indexOf('G');\n int num = Math.abs(a - b) - 1;\n for (int i = 0; i < 10; i++) {\n xor[i] += num % (k + 1);\n num /= (k + 1);\n }\n continue;\n }\n if (hasR && !line.equals(\"RR\"))\n cantDieR = true;\n if (hasG && !line.equals(\"GG\"))\n cantDieG = true;\n }\n\n if (cantDieR && cantDieG) {\n System.out.println(\"Draw\");\n return;\n }\n\n if (cantDieG) {\n System.out.println(\"First\");\n return;\n }\n\n if (cantDieR) {\n System.out.println(\"Second\");\n return;\n }\n\n for (int i : xor) {\n if (i % (k + 1) != 0) {\n System.out.println(\"First\");\n return;\n }\n }\n System.out.println(\"Second\");\n }\n\n static public void main(String[] args) {\n new d().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f30ebad975adaa1aae4b997df7f3664", "src_uid": "69062f7c9b834e925ab23ebc2da96b52", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class F {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[4001];\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[10];\n int min = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n min = Math.min(K[j], min);\n }\n int max = 0;\n long sum = 0;\n long sum2 = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] -= min;\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 * ((max + 1) / 2.0) + 1) * K.length;\n double poisson = -Double.MAX_VALUE;\n for (int j = Math.max(1, (int) var - 10); j <= (int) var + 150; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += K[k] * Math.log(j) - j * logE - factLog[K[k]];\n }\n if (likelyhood > poisson) {\n poisson = likelyhood;\n }\n }\n System.err.println(uniform + \" \" + poisson);\n System.out.println(uniform < poisson ? \"poisson\" : \"uniform\");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aaa78707c87b6dccef54cb8331402098", "src_uid": "6ef75e501b318c0799d3cbe8ca998984", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class F {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[4001];\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 for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n min = Math.min(K[j], min);\n }\n int max = 0;\n long sum = 0;\n long sum2 = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] -= min;\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 * (max / 2.0) + 1) * K.length;\n double poisson = -Double.MAX_VALUE;\n for (int j = Math.max(1, (int) var - 100); j <= (int) var + 300; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += K[k] * Math.log(j) - j * logE - factLog[K[k]];\n }\n if (likelyhood > poisson) {\n poisson = likelyhood;\n }\n }\n System.err.println(uniform + \" \" + poisson);\n System.out.println(uniform < poisson ? \"poisson\" : \"uniform\");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "341bd94b842a92d54e7de87acac9e2e3", "src_uid": "6ef75e501b318c0799d3cbe8ca998984", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class F {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[3001];\n for (int i = 1; i < factLog.length; i++) {\n factLog[i] = Math.log(i) + factLog[i - 1];\n }\n for (int i = 0; i < V; i++) {\n int[] K = new int[10];\n int min = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n Math.min(K[j], min);\n }\n int max = 0;\n long sum = 0;\n long sum2 = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] -= min;\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 double uniform = -Math.log(2 * ((max + 1) / 2.0) + 1) * K.length;\n double poisson = -Double.MAX_VALUE;\n for (int j = Math.max(1, (int) var - 10); j <= (int) var + 50; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += K[k] * Math.log(j) - j * logE;\n }\n if (likelyhood > poisson) {\n poisson = likelyhood;\n }\n }\n System.err.println(uniform + \" \" + poisson);\n System.out.println(uniform < poisson ? \"poisson\" : \"uniform\");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c44135cf3fb8ae9acd12ffe97baffa5", "src_uid": "6ef75e501b318c0799d3cbe8ca998984", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class F {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[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(1000, (int) var + 300); j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += (K[k] + j) * Math.log(j) - j * logE - factLog[K[k] + j];\n }\n if (likelyhood > poisson) {\n poisson = likelyhood;\n }\n }\n System.err.println(uniform + \" \" + poisson);\n System.out.println(uniform < poisson ? \"poisson\" : \"uniform\");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "89501ea8063e9c40e0d41e97ff49f8f6", "src_uid": "6ef75e501b318c0799d3cbe8ca998984", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n BufferedReader in;\n StringTokenizer str = null;\n PrintWriter out;\n \n private String next() throws Exception{\n\tif (str == null || !str.hasMoreElements())\n\t str = new StringTokenizer(in.readLine());\n\treturn str.nextToken();\n }\n \n private int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n }\n \n private long nextLong() throws Exception{\n\treturn Long.parseLong(next());\n }\n \n private double nextDouble() throws Exception{\n\treturn Double.parseDouble(next());\n }\n \n int n, V, e, sumA, sumB, size, yk=0;\n int []a,b, comp, from, to, amount;\n int [][]adj;\n boolean []used,cused;\n\n public void run() throws Exception{\n\tin = new BufferedReader(new InputStreamReader(System.in));\n\tout = new PrintWriter(System.out);\n\tn = nextInt(); V = nextInt(); e = nextInt();\n\ta = new int[n];\n\tb = new int[n];\n\tfor(int i=0;i b[x]) push(x, a[x] - b[x]);\n\t\t}\n\t }\n\t}\n\t\n\tif (!ok) {\n\t out.println(-1);\n\t}else{\n\t out.println(yk);\n\t for(int i=0;i 0 && adj[x][i] == 2){\n\t\tif (V - a[i] < d){\n\t\t int t = V - a[i];\n\t\t a[x]-=t;\n\t\t add(x+1, i+1, t);\n\t\t push(i, t);\n\t\t d-=t;\n\t\t}else{\n\t\t a[x]-=d;\n\t\t a[i]+=d;\n\t\t add(x+1, i+1, d);\n\t\t d = 0;\n\t\t}\n\t }\n\t}\n }\n\n private void pull(int x, int d){\n\tcused[x] = true;\n\tfor(int i=0;i 0 && adj[x][i] == 2){\n\t\tif (d - a[i] > 0){\n\t\t a[x]+=a[i];\n\t\t add(i+1, x+1, a[i]);\n\t\t pull(i, a[i]);\n\t\t d-=a[i];\n\t\t}else{\n\t\t a[x]+=d;\n\t\t a[i]-=d;\n\t\t add(i+1, x+1, d);\n\t\t d = 0;\n\t\t}\n\t }\n\t}\n }\n \n private void dfs(int x){\n\tused[x] = true;\n\tsumA+=a[x];\n\tsumB+=b[x];\n\tfor(int i=0;i[] graph;\n private DSU dsu;\n private List more, less;\n private boolean[] ready;\n private List answer;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n vertexCounter = in.nextInt();\n value = in.nextInt();\n edgeCounter = in.nextInt();\n\n initial = new long[vertexCounter];\n desired = new long[vertexCounter];\n ready = new boolean[vertexCounter];\n more = new ArrayList();\n less = new ArrayList();\n answer = new ArrayList();\n graph = new ArrayList[vertexCounter];\n for (int i = 0; i < vertexCounter; ++i)\n graph[i] = new ArrayList();\n\n for (int i = 0; i < vertexCounter; ++i)\n initial[i] = in.nextInt();\n for (int i = 0; i < vertexCounter; ++i)\n desired[i] = in.nextInt();\n\n dsu = new DSU(vertexCounter, initial, desired);\n\n int v, u;\n for (int i = 0; i < edgeCounter; ++i) {\n v = in.nextInt() - 1;\n u = in.nextInt() - 1;\n graph[u].add(v);\n graph[v].add(u);\n dsu.union(v, u);\n }\n\n if (!dsu.check()) {\n out.println(\"NO\");\n return;\n }\n\n for (int i = 0; i < vertexCounter; ++i)\n if (initial[i] == desired[i])\n ready[i] = true;\n else if (initial[i] > desired[i])\n more.add(i);\n else\n less.add(i);\n\n Comparator cmp = new Comparator() {\n @Override\n public int compare(Integer o1, Integer o2) {\n return Integer.compare(dsu.getSet(o1), dsu.getSet(o2));\n }\n };\n Collections.sort(more, cmp);\n Collections.sort(less, cmp);\n\n int current = 0;\n for (int i = 0; i < more.size(); ++i)\n if (initial[more.get(i)] - desired[more.get(i)] > desired[less.get(current)] - initial[less.get(current)]) {\n transfusion(more.get(i), less.get(current), (int) (desired[less.get(current)] - initial[less.get(current)]));\n ready[less.get(current)] = true;\n current++;\n i--;\n } else if (initial[more.get(i)] - desired[more.get(i)] < desired[less.get(current)] - initial[less.get(current)]) {\n transfusion(more.get(i), less.get(current), (int) (initial[more.get(i)] - desired[more.get(i)]));\n ready[more.get(i)] = true;\n } else {\n transfusion(more.get(i), less.get(current), (int) (initial[more.get(i)] - desired[more.get(i)]));\n ready[more.get(i)] = true;\n ready[less.get(current)] = true;\n current++;\n }\n\n out.println(answer.size());\n for (Transfusion transfusion : answer)\n transfusion.println(out);\n }\n\n private void transfusion(int from, int to, int delta) {\n path = new int[vertexCounter];\n Arrays.fill(path, -1);\n bfs(to, from);\n flow(from, to, delta);\n }\n\n private void bfs(int start, int finish) {\n int[] queue = new int[vertexCounter];\n int size = 0;\n int next = 0;\n queue[size++] = start;\n while (next < size) {\n int v = queue[next++];\n for (int u : graph[v])\n if (path[u] == -1) {\n path[u] = v;\n if (u == finish)\n return;\n queue[size++] = u;\n }\n }\n }\n\n private void flow(int from, int to, int delta) {\n if (from == to)\n return;\n if (initial[path[from]] + delta <= value) {\n\n answer.add(new Transfusion(from, path[from], delta));\n initial[from] -= delta;\n initial[path[from]] += delta;\n\n flow(path[from], to, delta);\n } else if (path[from] >= delta) {\n flow(path[from], to, delta);\n\n answer.add(new Transfusion(from, path[from], delta));\n initial[from] -= delta;\n initial[path[from]] += delta;\n } else {\n int difference = (int) (delta - initial[path[from]]);\n\n answer.add(new Transfusion(from, path[from], difference));\n initial[from] -= difference;\n initial[path[from]] += difference;\n\n flow(path[from], to, delta);\n\n answer.add(new Transfusion(from, path[from], delta - difference));\n initial[from] -= delta - difference;\n initial[path[from]] += delta - difference;\n }\n }\n\n}\n\nclass DSU {\n\n public int[] parent, rank;\n private long[] initial, desired;\n\n public DSU (int size, long[] initial, long[] desired) {\n parent = new int[size];\n rank = new int[size];\n this.initial = Arrays.copyOf(initial, initial.length);\n this.desired = Arrays.copyOf(desired, desired.length);\n for (int i = 0; i < size; ++i)\n parent[i] = i;\n for (int i = 0; i < size; ++i) {\n this.initial[getSet(i)] += initial[i];\n this.desired[getSet(i)] += desired[i];\n }\n }\n\n public int getSet(int v) {\n if (parent[v] == v)\n return v;\n return parent[v] = getSet(parent[v]);\n }\n\n public void union(int v, int u) {\n int a = getSet(v);\n int b = getSet(u);\n if (a != b) {\n if (rank[a] < rank[b]) {\n a ^= b;\n b ^= a;\n a ^= b;\n }\n parent[b] = a;\n if (rank[a] == rank[b])\n ++rank[a];\n }\n }\n\n public boolean check() {\n for (int v = 0; v < initial.length; ++v) {\n int p = getSet(v);\n if (p != v) {\n initial[p] += initial[v];\n desired[p] += desired[v];\n initial[v] = 0;\n desired[v] = 0;\n }\n }\n for (int i = 0; i < initial.length; ++i)\n if (initial[i] != desired[i])\n return false;\n return true;\n }\n\n}\n\nclass Transfusion {\n\n public int from, to, value;\n\n public Transfusion(int x, int y, int v) {\n from = x;\n to = y;\n value = v;\n }\n\n public void println(PrintWriter out) {\n out.print(from + 1);\n out.print(\" \");\n out.print(to + 1);\n out.print(\" \");\n out.println(value);\n }\n\n}\n\nclass InputReader {\n\n private static BufferedReader bufferedReader;\n private static StringTokenizer stringTokenizer;\n\n public InputReader(InputStream inputStream) {\n bufferedReader = new BufferedReader(new InputStreamReader(inputStream));\n stringTokenizer = null;\n }\n\n public String next() {\n while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n try {\n stringTokenizer = new StringTokenizer(bufferedReader.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return stringTokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f6d0a30713854336a35b6d283dfd5d68", "src_uid": "0939354d9bad8301efb79a1a934ded30", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author vadimmm\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 private int vertexCounter, edgeCounter, value;\n private int[] path;\n private long[] initial, desired;\n private List[] graph;\n private DSU dsu;\n private List more, less;\n private boolean[] ready;\n private List answer;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n vertexCounter = in.nextInt();\n value = in.nextInt();\n edgeCounter = in.nextInt();\n\n initial = new long[vertexCounter];\n desired = new long[vertexCounter];\n ready = new boolean[vertexCounter];\n more = new ArrayList();\n less = new ArrayList();\n answer = new ArrayList();\n graph = new ArrayList[vertexCounter];\n for (int i = 0; i < vertexCounter; ++i)\n graph[i] = new ArrayList();\n\n for (int i = 0; i < vertexCounter; ++i)\n initial[i] = in.nextInt();\n for (int i = 0; i < vertexCounter; ++i)\n desired[i] = in.nextInt();\n\n dsu = new DSU(vertexCounter, initial, desired);\n\n int v, u;\n for (int i = 0; i < edgeCounter; ++i) {\n v = in.nextInt() - 1;\n u = in.nextInt() - 1;\n graph[u].add(v);\n graph[v].add(u);\n dsu.union(v, u);\n }\n\n if (!dsu.check()) {\n out.println(\"NO\");\n return;\n }\n\n for (int i = 0; i < vertexCounter; ++i)\n if (initial[i] == desired[i])\n ready[i] = true;\n else if (initial[i] > desired[i])\n more.add(i);\n else\n less.add(i);\n\n Comparator cmp = new Comparator() {\n @Override\n public int compare(Integer o1, Integer o2) {\n return Integer.compare(dsu.getSet(o1), dsu.getSet(o2));\n }\n };\n Collections.sort(more, cmp);\n Collections.sort(less, cmp);\n\n int current = 0;\n for (int i = 0; i < more.size(); ++i)\n if (initial[more.get(i)] - desired[more.get(i)] > desired[less.get(current)] - initial[less.get(current)]) {\n transfusion(more.get(i), less.get(current), (int) (desired[less.get(current)] - initial[less.get(current)]));\n ready[less.get(current)] = true;\n current++;\n i--;\n } else {\n transfusion(more.get(i), less.get(current), (int) (initial[more.get(i)] - desired[more.get(i)]));\n ready[more.get(i)] = true;\n }\n \n out.println(answer.size());\n for (Transfusion transfusion : answer)\n transfusion.println(out);\n }\n\n private void transfusion(int from, int to, int delta) {\n path = new int[vertexCounter];\n Arrays.fill(path, -1);\n bfs(to, from);\n flow(from, to, delta);\n }\n\n private void flow(int from, int to, int delta) {\n if (from == to)\n return;\n if (initial[path[from]] + delta <= value) {\n\n answer.add(new Transfusion(from, path[from], delta));\n initial[from] -= delta;\n initial[path[from]] += delta;\n\n flow(path[from], to, delta);\n } else if (path[from] >= delta) {\n flow(path[from], to, delta);\n\n answer.add(new Transfusion(from, path[from], delta));\n initial[from] -= delta;\n initial[path[from]] += delta;\n } else {\n int difference = (int) (delta - initial[path[from]]);\n\n answer.add(new Transfusion(from, path[from], difference));\n initial[from] -= difference;\n initial[path[from]] += difference;\n\n flow(path[from], to, delta);\n\n answer.add(new Transfusion(from, path[from], delta - difference));\n initial[from] -= delta - difference;\n initial[path[from]] += delta - difference;\n }\n }\n\n private void bfs(int start, int finish) {\n int[] queue = new int[vertexCounter];\n int size = 0;\n int next = 0;\n queue[size++] = start;\n while (size > 0) {\n int v = queue[next++];\n for (int u : graph[v])\n if (path[u] == -1) {\n path[u] = v;\n if (u == finish)\n return;\n queue[size++] = u;\n }\n }\n }\n\n}\n\nclass DSU {\n\n public int[] parent, rank;\n private long[] initial, desired;\n\n public DSU (int size, long[] initial, long[] desired) {\n parent = new int[size];\n rank = new int[size];\n this.initial = Arrays.copyOf(initial, initial.length);\n this.desired = Arrays.copyOf(desired, desired.length);\n for (int i = 0; i < size; ++i)\n parent[i] = i;\n for (int i = 0; i < size; ++i) {\n this.initial[getSet(i)] += initial[i];\n this.desired[getSet(i)] += desired[i];\n }\n }\n\n public int getSet(int v) {\n if (parent[v] == v)\n return v;\n return parent[v] = getSet(parent[v]);\n }\n\n public void union(int v, int u) {\n int a = getSet(v);\n int b = getSet(u);\n if (a != b) {\n if (rank[a] < rank[b]) {\n a ^= b;\n b ^= a;\n a ^= b;\n }\n parent[b] = a;\n if (rank[a] == rank[b])\n ++rank[a];\n }\n }\n\n public boolean check() {\n for (int v = 0; v < initial.length; ++v) {\n int p = getSet(v);\n if (p != v) {\n initial[p] += initial[v];\n desired[p] += desired[v];\n initial[v] = 0;\n desired[v] = 0;\n }\n }\n for (int i = 0; i < initial.length; ++i)\n if (initial[i] != desired[i])\n return false;\n return true;\n }\n\n}\n\nclass Transfusion {\n\n public int from, to, value;\n\n public Transfusion(int x, int y, int v) {\n from = x;\n to = y;\n value = v;\n }\n\n public void println(PrintWriter out) {\n out.print(from + 1);\n out.print(\" \");\n out.print(to + 1);\n out.print(\" \");\n out.println(value);\n }\n\n}\n\nclass InputReader {\n\n private static BufferedReader bufferedReader;\n private static StringTokenizer stringTokenizer;\n\n public InputReader(InputStream inputStream) {\n bufferedReader = new BufferedReader(new InputStreamReader(inputStream));\n stringTokenizer = null;\n }\n\n public String next() {\n while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n try {\n stringTokenizer = new StringTokenizer(bufferedReader.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return stringTokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "41abe4a0461f0460c5b8b1dfaba7a2d9", "src_uid": "0939354d9bad8301efb79a1a934ded30", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main{\n \n BufferedReader in;\n StringTokenizer str = null;\n PrintWriter out;\n \n private String next() throws Exception{\n \tif (str == null || !str.hasMoreElements())\n \t str = new StringTokenizer(in.readLine());\n \treturn str.nextToken();\n }\n \n private int nextInt() throws Exception{\n\treturn Integer.parseInt(next());\n }\n \n private long nextLong() throws Exception{\n\treturn Long.parseLong(next());\n }\n\n\n int n, e;\n long V;\n\n int [][]g;\n long []a, b, amount;\n boolean used[];\n \n long total = 0;\n int size = 0, yk = 0;\n int []comp, prev;\n\n int []from, to;\n public void run() throws Exception{\n \tin = new BufferedReader(new InputStreamReader(System.in));\n \tout = new PrintWriter(System.out);\n\n\tn = nextInt();\n\tV = nextLong();\n\te = nextInt();\n\t\n\ta = new long[n];\n\tfor(int i=0;i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "858a9595a3759b282bbf4bcc4c9bdeec", "src_uid": "15008dcb8dc8506c39aef0e3d8fca70c", "difficulty": null} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class NeatWords {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scan = new Scanner(System.in);\n\t\tString str;\n\t\tchar myArray[];\n\t\tint len, nC, cC;\n\t\tnC = 0;\n\t\tcC = 0;\n\t\tstr = scan.nextLine();\n\t\tstr = str.toUpperCase();\n\t\tlen = str.length();\n\t\tchar lin[] = { 'A', 'E', 'F', 'H', 'I', 'M', 'L', 'N', 'T', 'V', 'X', 'Z', 'W', 'K','Y' };\n\t\tchar nonLin[] = { 'B', 'C', 'D', 'G', 'J', 'O', 'P', 'Q', 'R', 'S', 'U' };\n\n\t\tmyArray = new char[len];\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tmyArray[i] = str.charAt(i);\n\n\t\t\tfor (int j = 0; j < lin.length; j++) {\n\t\t\t\tif (myArray[i] == lin[j]) {\n\t\t\t\t\tnC++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int k = 0; k < nonLin.length; k++) {\n\t\t\t\tif (myArray[i] == nonLin[k]) {\n\t\t\t\t\tcC++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (nC == str.length() || cC == str.length()) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\tscan.close();\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "02db0782c42865b77edd13e14ccab555", "src_uid": "15008dcb8dc8506c39aef0e3d8fca70c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class NeatWords {\n\tpublic static void main(String[] args) {\n\t\tString lined = \"AEFHIKLMNTVWXYZ\";\n\t\tScanner scan = new Scanner(System.in);\n\t\tString word = scan.nextLine();\n\t\tint sum = lined.indexOf(word.charAt(0))!=-1 ? 1 : 0;\n\t\tboolean yes = true;\n\t\tfor(int i = 1; i < word.length(); i++) {\n\t\t\tif(lined.indexOf(word.charAt(i))!=-1) {\n\t\t\t\tif(sum == 0) {\n\t\t\t\t\tyes = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tsum++;\n\t\t\t}else {\n\t\t\t\tif(sum != 0) {\n\t\t\t\t\tyes = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(yes?\"YES\":\"NO\");\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7addf7aeb81ce4cc71558d6b4a949727", "src_uid": "15008dcb8dc8506c39aef0e3d8fca70c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n ArrayList g[];\n HashSet from[];\n Queue q = new ArrayDeque<>();\n boolean used[];\n int[] dist;\n\n void bfs() {\n while (!q.isEmpty()) {\n int v = q.poll();\n for (Integer to : g[v]) {\n if (!used[to]) {\n used[to] = true;\n dist[to] = dist[v] + 1;\n q.add(to);\n }\n if (dist[to] == dist[v] + 1) from[to].add(v);\n }\n }\n }\n\n void run() throws IOException {\n int n = nextInt();\n int m = nextInt();\n used = new boolean[n];\n dist = new int[n];\n g = new ArrayList[n];\n from = new HashSet[n];\n for (int i = 0; i < n; i++) {\n g[i] = new ArrayList<>();\n from[i] = new HashSet<>();\n }\n for (int i = 0; i < m; i++) {\n int u = nextInt() - 1;\n int v = nextInt() - 1;\n g[v].add(u);\n }\n int k = nextInt();\n int[] p = new int[k];\n for (int i = 0; i < k; i++) {\n p[i] = nextInt() - 1;\n }\n used[p[k - 1]] = true;\n q.add(p[k - 1]);\n bfs();\n int min = 0;\n int max = 0;\n for (int i = 0; i < p.length - 1; i++) {\n int v = p[i];\n if (from[p[i]].contains(p[i + 1])) {\n if (from[p[i]].size() > 1) max++;\n } else {\n min++;\n max++;\n }\n }\n pw.print(min + \" \" + max);\n pw.close();\n }\n\n static BufferedReader br;\n static StringTokenizer st = new StringTokenizer(\"\");\n static PrintWriter pw;\n\n public static String next() throws IOException {\n while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(System.out);\n new Main().run();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b53f1467997652ef299141085c60b9bd", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n static class Parser{\n private BufferedReader bf;\n private StringTokenizer st;\n\n\n Parser(){\n bf = new BufferedReader(new InputStreamReader(System.in));\n }\n\n Parser(int a) throws FileNotFoundException {\n bf = new BufferedReader(new FileReader(\"input.txt\"));\n }\n\n String next() throws IOException {\n while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(bf.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\n static Parser in;\n static PrintWriter out;\n\n static int n, m;\n \n static class pair{\n int f, s;\n\n public pair(int f, int s) {\n this.f = f;\n this.s = s;\n }\n }\n \n static class pr{\n int f;\n ArrayList s;\n\n public pr(int f, int ... e) {\n this.f = f;\n\n s = new ArrayList<>(e.length);\n for (int i = 0; i < e.length; i++) s.add(e[i]);\n\n }\n }\n \n static final int MAXN = 200 * 1000 + 1;\n\n static ArrayList[] g = new ArrayList[MAXN];\n static ArrayList[] inv_g = new ArrayList[MAXN];\n static int[] root = new int[MAXN];\n static ArrayList[] near = new ArrayList[MAXN];\n\n static int[] dist = new int[MAXN];\n static ArrayList[] edges = new ArrayList[MAXN];\n\n static boolean areRootNeighbours(int a, int b){\n for (int neigh: near[a]) if(neigh == b) return true;\n return false;\n }\n \n static void bfs(int v){\n boolean[] used = new boolean[MAXN];\n for (int i = 1; i <= n; i++){\n dist[i] = (int)1e8;\n edges[i] = new ArrayList<>();\n }\n dist[v] = 0;\n\n Queue que = new LinkedList<>();\n que.add(new pair(v, 1));\n while(!que.isEmpty()){\n pair ww = que.remove();\n v = ww.f;\n int ind = ww.s;\n\n if(used[v]) continue;\n used[v] = true;\n\n for(int to: inv_g[v]){\n if(dist[to] > ind + 1){\n dist[to] = ind + 1;\n edges[to].add(v);\n\n }else if(dist[to] == ind + 1){\n if(areRootNeighbours(to, v)){\n\n if(edges[to].isEmpty()) edges[to].add(v);\n else {\n int temp = edges[to].get(0);\n edges[to].set(0, v);\n if(edges[to].size() < 2) edges[to].add(temp);\n }\n }else if(edges[to].size() < 2) edges[to].add(v);\n }\n\n que.add(new pair(to, ind + 1));\n }\n }\n }\n\n static void solve() throws IOException {\n n = in.nextInt();\n m = in.nextInt();\n for (int i = 1; i <= n; i++) {\n g[i] = new ArrayList<>();\n inv_g[i] = new ArrayList<>();\n near[i] = new ArrayList<>();\n edges[i] = new ArrayList<>();\n }\n\n for (int i = 0; i < m; i++) {\n int a = in.nextInt();\n int b = in.nextInt();\n g[a].add(b);\n inv_g[b].add(a);\n }\n\n int q = in.nextInt();\n for(int i = 0; i < q; ++i) root[i] = in.nextInt();\n for (int i = 0; i < q; i++) {\n if(i > 0) near[root[i]].add(root[i - 1]);\n if(i + 1 < q) near[root[i]].add(root[i + 1]);\n }\n\n bfs(root[q - 1]);\n\n int c1 = 0, c2 = 0;\n for(int i = 0; i < q - 1; ++i){\n int pt = root[i];\n int next = root[i + 1];\n\n boolean isok = false;\n for(int to: edges[pt]){\n if(to == next){\n isok = true;\n break;\n }\n }\n\n if(!isok) ++c1;\n if(!isok || edges[pt].size() > 1) ++c2;\n }\n\n out.println(c1 + \" \" + c2);\n }\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n in = new Parser();\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "15b90253c21dd67245f71d78421f2146", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n static ArrayList[] gr, g;\n static TreeMap way;\n static int[] types, dist;\n static int INF = (int) 1e9;\n\n public static void main(String[] args) {\n FastScanner sc = new FastScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = sc.nextInt();\n int m = sc.nextInt();\n gr = new ArrayList[n];\n g = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n gr[i] = new ArrayList<>();\n g[i] = new ArrayList<>();\n }\n for (int i = 0; i < m; i++) {\n int from = sc.nextInt() - 1;\n int to = sc.nextInt() - 1;\n gr[from].add(to);\n g[to].add(from);\n }\n int k = sc.nextInt();\n int[] p = new int[k];\n for (int i = 0; i < k; i++)\n p[i] = sc.nextInt() - 1;\n way = new TreeMap<>();\n for (int i = 0; i < k - 1; i++)\n way.put(p[i], p[i + 1]);\n types = new int[n];\n //0 - none\n //1 - +\n //2 - -\n //3 - +-\n dist = new int[n];\n Arrays.fill(dist, INF);\n dist[p[k - 1]] = 0;\n bfs(p[k - 1]);\n int cntMin = 0;\n int cntMax = 0;\n for (int i = 0; i < k - 1; i++) {\n if (types[p[i]] == 2) {\n cntMin++;\n cntMax++;\n }\n if (types[p[i]] == 3)\n cntMax++;\n }\n pw.print(cntMin + \" \" + cntMax);\n pw.close();\n }\n\n public static void bfs(int start) {\n ArrayDeque bfs = new ArrayDeque<>();\n bfs.add(new Pair(start, -1));\n while(!bfs.isEmpty()){\n int v = bfs.getFirst().v;\n int p = bfs.pollFirst().p;\n for (int to : g[v]) {\n if(dist[to] == INF)\n bfs.add(new Pair(to, v));\n if (dist[to] > dist[v] + 1) {\n dist[to] = dist[v] + 1;\n if (way.containsKey(to) && way.get(to) == v)\n types[to] = 1;\n else\n types[to] = 2;\n } else if (dist[to] == dist[v] + 1) {\n if (way.containsKey(to) && way.get(to) == v)\n types[to]++;\n else {\n if (types[to] < 2)\n types[to] += 2;\n }\n }\n }\n }\n }\n\n\n public static boolean isVowel(char a) {\n return a == 'a' || a == 'e' || a == 'u' || a == 'o' || a == 'y';\n }\n\n public static long binPow(long a, int n) {\n long p = a;\n long res = 1;\n while (n > 0) {\n if (n % 2 == 1)\n res *= p;\n p *= p;\n n /= 2;\n }\n return res;\n }\n\n public static int gcd(int a, int b) {\n if (a == 0 || b == 0)\n return a + b;\n return gcd(b % a, a);\n }\n\n public static long gcd(long a, long b) {\n if (a == 0 || b == 0)\n return a + b;\n return gcd(b % a, a);\n }\n}\n\nclass Pair{\n int v, p;\n\n public Pair(int v, int p) {\n this.v = v;\n this.p = p;\n }\n}\nclass FastScanner {\n static BufferedReader br;\n static StringTokenizer st = new StringTokenizer(\"\");\n\n public FastScanner(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public FastScanner(String fileName) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(fileName));\n }\n\n public boolean hasNext() {\n try {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n hasNext();\n return st.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ab3cad5d2771639567de14c96920ee5f", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a", "difficulty": null} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n static ArrayList[] gr, g;\n static TreeMap way;\n static int[] types, dist;\n static boolean[] used;\n static int INF = (int) 1e9;\n\n public static void main(String[] args) {\n FastScanner sc = new FastScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = sc.nextInt();\n int m = sc.nextInt();\n gr = new ArrayList[n];\n g = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n gr[i] = new ArrayList<>();\n g[i] = new ArrayList<>();\n }\n for (int i = 0; i < m; i++) {\n int from = sc.nextInt() - 1;\n int to = sc.nextInt() - 1;\n gr[from].add(to);\n g[to].add(from);\n }\n int k = sc.nextInt();\n int[] p = new int[k];\n for (int i = 0; i < k; i++)\n p[i] = sc.nextInt() - 1;\n way = new TreeMap<>();\n for (int i = 0; i < k - 1; i++)\n way.put(p[i], p[i + 1]);\n types = new int[n];\n //0 - none\n //1 - +\n //2 - -\n //3 - +-\n used = new boolean[n];\n dist = new int[n];\n Arrays.fill(dist, INF);\n dist[p[k - 1]] = 0;\n dfs(p[k - 1], -1);\n int cntMin = 0;\n int cntMax = 0;\n for (int i = 0; i < k - 1; i++) {\n if (types[p[i]] == 2) {\n cntMin++;\n cntMax++;\n }\n if (types[p[i]] == 3)\n cntMax++;\n }\n pw.print(cntMin + \" \" + cntMax);\n pw.close();\n }\n\n public static void dfs(int v, int p) {\n used[v] = true;\n for (int to : g[v]) {\n if (dist[to] > dist[v] + 1) {\n dist[to] = dist[v] + 1;\n if (way.containsKey(to) && way.get(to) == v)\n types[to] = 1;\n else\n types[to] = 2;\n dfs(to, v);\n } else if (dist[to] == dist[v] + 1) {\n if (way.containsKey(to) && way.get(to) == v)\n types[to]++;\n else {\n if (types[to] < 2)\n types[to] += 2;\n }\n }\n }\n }\n\n\n public static boolean isVowel(char a) {\n return a == 'a' || a == 'e' || a == 'u' || a == 'o' || a == 'y';\n }\n\n public static long binPow(long a, int n) {\n long p = a;\n long res = 1;\n while (n > 0) {\n if (n % 2 == 1)\n res *= p;\n p *= p;\n n /= 2;\n }\n return res;\n }\n\n public static int gcd(int a, int b) {\n if (a == 0 || b == 0)\n return a + b;\n return gcd(b % a, a);\n }\n\n public static long gcd(long a, long b) {\n if (a == 0 || b == 0)\n return a + b;\n return gcd(b % a, a);\n }\n}\n\nclass chr {\n char a;\n int index;\n\n public chr(char a, int index) {\n this.a = a;\n this.index = index;\n }\n}\n\nclass chrComp implements Comparator {\n public int compare(chr o1, chr o2) {\n return Character.compare(o1.a, o2.a);\n }\n}\n\nclass FastScanner {\n static BufferedReader br;\n static StringTokenizer st = new StringTokenizer(\"\");\n\n public FastScanner(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public FastScanner(String fileName) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(fileName));\n }\n\n public boolean hasNext() {\n try {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n hasNext();\n return st.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d5b4292bc2bc5e1def12d14243529f3", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n\tstatic final Integer N = Integer.valueOf(1000010), MOD = Integer.valueOf(1000000007);\n\t\n\tpublic static Integer mul(Integer x, Integer y) {\n\t\tLong ret = Long.valueOf(x.intValue());\n\t\tret = (ret * y) % MOD;\n\t\treturn Integer.valueOf(ret.intValue());\n\t}\n\t\n\tpublic static Integer power(Integer basic, Integer times) {\n\t\tInteger ret = Integer.valueOf(1);\n\t\twhile(times > 0) {\n\t\t\tif((times & 1) == 1) ret = mul(ret, basic);\n\t\t\tbasic = mul(basic, basic);\n\t\t\ttimes >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static Integer[] extGcd(Integer a, Integer b) {\n\t\tInteger [] ret = new Integer[3];\n\t\tif(b == 0) {\n\t\t\tret[0] = Integer.valueOf(a.intValue());\n\t\t\tret[1] = Integer.valueOf(1);\n\t\t\tret[2] = Integer.valueOf(0);\n\t\t} else {\n\t\t\tInteger [] tmp = extGcd(b, a % b);\n\t\t\tInteger g = tmp[0], ta = tmp[2], tb = tmp[1] - a / b * tmp[2];\n\t\t\tif(ta < 0) {\n\t\t\t\tInteger t = ta / (b / g);\n\t\t\t\tta -= t * (b / g);\n\t\t\t\ttb += t * (a / g);\n\t\t\t}\n\t\t\tif(ta < 0) {\n\t\t\t\tta += b / g;\n\t\t\t\ttb -= a / g;\n\t\t\t}\n\t\t\tret[0] = g;\n\t\t\tret[1] = ta;\n\t\t\tret[2] = tb;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static Integer inv(Integer x) {\n//\t\t0-> gcd 1->ta 2->tb\n\t\tInteger [] results = extGcd(x, MOD);\n\t\treturn results[1];\n\t}\n\t\n\tpublic static Integer solve(Integer n, Integer m) {\n//\t\tSystem.out.println(n + \" \" + m);\n\t\t\n\t\tInteger [] f = new Integer[m + 3];\n\t\tf[0] = Integer.valueOf(0);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tf[i] = Integer.valueOf((f[i - 1] + power(i, m)) % MOD);\n//\t\tSystem.out.println(power(Integer.valueOf(2), Integer.valueOf(100)));\n\n//\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n//\t\t\tSystem.out.print(f[i] + \" \");\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tif(n <= m + 2) return f[n];\n\t\t\n\t\tInteger [] lagrange = new Integer[m + 3];\n\t\tInteger [] fact = new Integer[m + 3];\n\t\tfact[0] = Integer.valueOf(1);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tfact[i] = mul(fact[i - 1], i);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++) {\n\t\t\tlagrange[i] = f[i];\n\t\t\tlagrange[i] = mul(lagrange[i], inv(mul(fact[i - 1], fact[m + 2 - i])));\n\t\t\tif(((m + 2 - i) & 1) == 1)\n\t\t\t\tlagrange[i] = MOD - lagrange[i];\n//\t\t\tSystem.out.print(lagrange[i] + \" \");\n\t\t}\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tInteger fullDenominator = Integer.valueOf(1);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tfullDenominator = mul(fullDenominator, n - i);\n//\t\tSystem.out.println(fullDenominator);\n\t\t\n\t\tInteger ret = Integer.valueOf(0);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++) {\n\t\t\tInteger denominator = Integer.valueOf(mul(fullDenominator, inv(n - i)));\n//\t\t\tSystem.out.print(denominator + \" \");\n\t\t\tret = (ret + mul(denominator, lagrange[i])) % MOD;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner reader = new Scanner(System.in);\n\t\tInteger n = new Integer(reader.nextInt());\n\t\tInteger k = new Integer(reader.nextInt());\n\t\t\n\t\tInteger ans = solve(n, k);\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\treader.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "665dff3c3fb7743a17719b3de03e3877", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "package tryAndLean;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n\tstatic final Integer MOD = Integer.valueOf(1000000007);\n\t\n\tpublic static Integer mul(Integer x, Integer y) {\n\t\tLong ret = Long.valueOf(x.intValue());\n\t\tret = (ret * y) % MOD;\n\t\treturn Integer.valueOf(ret.intValue());\n\t}\n\t\n\tpublic static int mul(int x, int y) {\n\t\tlong ret = x;\n\t\tret *= y;\n\t\tret %= 1000000007;\n\t\treturn (int) ret;\n\t}\n\t\n\tpublic static Integer power(Integer a, Integer b) {\n\t\tint basic = a.intValue(), times = b.intValue();\n\t\tint ret = 1;\n\t\twhile(times > 0) {\n\t\t\tif((times & 1) == 1) ret = mul(ret, basic);\n\t\t\tbasic = mul(basic, basic);\n\t\t\ttimes >>= 1;\n\t\t}\n\t\treturn Integer.valueOf(ret);\n\t}\n\t\n\tpublic static Integer[] extGcd(Integer a, Integer b) {\n\t\tInteger [] ret = new Integer[3];\n\t\tif(b == 0) {\n\t\t\tret[0] = Integer.valueOf(a.intValue());\n\t\t\tret[1] = Integer.valueOf(1);\n\t\t\tret[2] = Integer.valueOf(0);\n\t\t} else {\n\t\t\tInteger [] tmp = extGcd(b, a % b);\n\t\t\tInteger g = tmp[0], ta = tmp[2], tb = tmp[1] - a / b * tmp[2];\n\t\t\tif(ta < 0) {\n\t\t\t\tInteger t = ta / (b / g);\n\t\t\t\tta -= t * (b / g);\n\t\t\t\ttb += t * (a / g);\n\t\t\t}\n\t\t\tif(ta < 0) {\n\t\t\t\tta += b / g;\n\t\t\t\ttb -= a / g;\n\t\t\t}\n\t\t\tret[0] = g;\n\t\t\tret[1] = ta;\n\t\t\tret[2] = tb;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static Integer inv(Integer x) {\n//\t\t0-> gcd 1->ta 2->tb\n//\t\tInteger [] results = extGcd(x, MOD);\n//\t\treturn results[1];\n\t\treturn power(x, MOD - 2);\n\t}\n\t\n\tpublic static Integer solve(Integer n, Integer m) {\n//\t\tSystem.out.println(n + \" \" + m);\n\t\t\n\t\tInteger [] f = new Integer[m + 3];\n\t\tf[0] = Integer.valueOf(0);\n\t\tfor(int i = 1; i <= m + 2; i++) {\n\t\t\tf[i] = Integer.valueOf(f[i - 1] + power(i, m));\n\t\t\tif(f[i] >= MOD) f[i] -= MOD;\n\t\t}\n//\t\tSystem.out.println(power(Integer.valueOf(2), Integer.valueOf(100)));\n\n//\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n//\t\t\tSystem.out.print(f[i] + \" \");\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tif(n <= m + 2) return f[n];\n\t\t\n\t\tInteger [] lagrange = new Integer[m + 3];\n\t\tInteger [] fact = new Integer[m + 3];\n\t\tfact[0] = Integer.valueOf(1);\n\t\tfor(int i = 1; i <= m + 2; i++)\n\t\t\tfact[i] = mul(fact[i - 1].intValue(), i);\n\t\tfor(int i = 1; i <= m + 2; i++) {\n\t\t\tlagrange[i] = f[i];\n\t\t\tlagrange[i] = mul(lagrange[i], inv(mul(fact[i - 1], fact[m + 2 - i])));\n\t\t\tif(((m + 2 - i) & 1) == 1)\n\t\t\t\tlagrange[i] = MOD - lagrange[i];\n//\t\t\tSystem.out.print(lagrange[i] + \" \");\n\t\t}\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tInteger fullDenominator = Integer.valueOf(1);\n\t\tfor(int i = 1; i <= m + 2; i++)\n\t\t\tfullDenominator = mul(fullDenominator.intValue(), n - i);\n//\t\tSystem.out.println(fullDenominator);\n\t\t\n\t\tInteger ret = Integer.valueOf(0);\n\t\tfor(int i = 1; i <= m + 2; i++) {\n\t\t\tInteger denominator = Integer.valueOf(mul(fullDenominator, inv(n - i)));\n//\t\t\tSystem.out.print(denominator + \" \");\n\t\t\tret = ret + mul(denominator, lagrange[i]);\n\t\t\tif(ret >= MOD) ret -= MOD;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tScanner reader = new Scanner(System.in);\n\t\tInteger n = new Integer(reader.nextInt());\n\t\tInteger k = new Integer(reader.nextInt());\n\t\t\n\t\tInteger ans = solve(n, k);\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\treader.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c1c2e3ad5224ea77d07b8437e9a12d96", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "package tryAndLean;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport javax.swing.plaf.multi.MultiButtonUI;\nimport javax.xml.parsers.FactoryConfigurationError;\n\npublic class Main {\n\tstatic final Integer N = 1000010, MOD = new Integer(1000000009);\n\t\n\tpublic static Integer mul(Integer x, Integer y) {\n\t\tLong ret = new Long(x.intValue());\n\t\tret = (ret * y) % MOD;\n\t\treturn Integer.valueOf(ret.intValue());\n\t}\n\t\n\tpublic static Integer power(Integer basic, Integer times) {\n\t\tInteger ret = Integer.valueOf(1);\n\t\twhile(times > 0) {\n\t\t\tif((times & 1) == 1) ret = mul(ret, basic);\n\t\t\tbasic = mul(basic, basic);\n\t\t\ttimes >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static Integer[] extGcd(Integer a, Integer b) {\n\t\tInteger [] ret = new Integer[3];\n\t\tif(b == 0) {\n\t\t\tret[0] = Integer.valueOf(a.intValue());\n\t\t\tret[1] = Integer.valueOf(1);\n\t\t\tret[2] = Integer.valueOf(0);\n\t\t} else {\n\t\t\tInteger [] tmp = extGcd(b, a % b);\n\t\t\tInteger g = tmp[0], ta = tmp[2], tb = tmp[1] - a / b * tmp[2];\n\t\t\tif(ta < 0) {\n\t\t\t\tInteger t = ta / (b / g);\n\t\t\t\tta -= t * (b / g);\n\t\t\t\ttb += t * (a / g);\n\t\t\t}\n\t\t\tif(ta < 0) {\n\t\t\t\tta += b / g;\n\t\t\t\ttb -= a / g;\n\t\t\t}\n\t\t\tret[0] = g;\n\t\t\tret[1] = ta;\n\t\t\tret[2] = tb;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static Integer inv(Integer x) {\n//\t\t0-> gcd 1->ta 2->tb\n\t\tInteger [] results = extGcd(x, MOD);\n\t\treturn results[1];\n\t}\n\t\n\tpublic static Integer solve(Integer n, Integer m) {\n//\t\tSystem.out.println(n + \" \" + m);\n\t\t\n\t\tInteger [] f = new Integer[m + 3];\n\t\tf[0] = Integer.valueOf(0);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tf[i] = new Integer((f[i - 1] + power(i, m)) % MOD);\n\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n//\t\t\tSystem.out.print(f[i] + \" \");\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tif(n <= m + 2) return f[n];\n\t\t\n\t\tInteger [] lagrange = new Integer[m + 3];\n\t\tInteger [] fact = new Integer[m + 3];\n\t\tfact[0] = Integer.valueOf(1);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tfact[i] = mul(fact[i - 1], i);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++) {\n\t\t\tlagrange[i] = f[i];\n\t\t\tlagrange[i] = mul(lagrange[i], inv(mul(fact[i - 1], fact[m + 2 - i])));\n\t\t\tif(((m + 2 - i) & 1) == 1)\n\t\t\t\tlagrange[i] = MOD - lagrange[i];\n//\t\t\tSystem.out.print(lagrange[i] + \" \");\n\t\t}\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tInteger fullDenominator = Integer.valueOf(1);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tfullDenominator = mul(fullDenominator, n - i);\n//\t\tSystem.out.println(fullDenominator);\n\t\t\n\t\tInteger ret = Integer.valueOf(0);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++) {\n\t\t\tInteger denominator = Integer.valueOf(mul(fullDenominator, inv(n - i)));\n//\t\t\tSystem.out.print(denominator + \" \");\n\t\t\tret = (ret + mul(denominator, lagrange[i])) % MOD;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner reader = new Scanner(System.in);\n\t\tInteger n = new Integer(reader.nextInt());\n\t\tInteger k = new Integer(reader.nextInt());\n\t\t\n\t\tInteger ans = solve(n, k);\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\treader.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f2a2315d3d0316f301828333dd2678fe", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "package tryAndLean;\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n\npublic class Main {\n\tstatic final Integer N = Integer.valueOf(1000010), MOD = Integer.valueOf(1000000007);\n\t\n\tpublic static Integer mul(Integer x, Integer y) {\n\t\tLong ret = Long.valueOf(x.intValue());\n\t\tret = (ret * y) % MOD;\n\t\treturn Integer.valueOf(ret.intValue());\n\t}\n\t\n\tpublic static Integer power(Integer basic, Integer times) {\n\t\tInteger ret = Integer.valueOf(1);\n\t\twhile(times > 0) {\n\t\t\tif((times & 1) == 1) ret = mul(ret, basic);\n\t\t\tbasic = mul(basic, basic);\n\t\t\ttimes >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static Integer[] extGcd(Integer a, Integer b) {\n\t\tInteger [] ret = new Integer[3];\n\t\tif(b == 0) {\n\t\t\tret[0] = Integer.valueOf(a.intValue());\n\t\t\tret[1] = Integer.valueOf(1);\n\t\t\tret[2] = Integer.valueOf(0);\n\t\t} else {\n\t\t\tInteger [] tmp = extGcd(b, a % b);\n\t\t\tInteger g = tmp[0], ta = tmp[2], tb = tmp[1] - a / b * tmp[2];\n\t\t\tif(ta < 0) {\n\t\t\t\tInteger t = ta / (b / g);\n\t\t\t\tta -= t * (b / g);\n\t\t\t\ttb += t * (a / g);\n\t\t\t}\n\t\t\tif(ta < 0) {\n\t\t\t\tta += b / g;\n\t\t\t\ttb -= a / g;\n\t\t\t}\n\t\t\tret[0] = g;\n\t\t\tret[1] = ta;\n\t\t\tret[2] = tb;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static Integer inv(Integer x) {\n//\t\t0-> gcd 1->ta 2->tb\n//\t\tInteger [] results = extGcd(x, MOD);\n//\t\treturn results[1];\n\t\treturn power(x, MOD - 2);\n\t}\n\t\n\tpublic static Integer solve(Integer n, Integer m) {\n//\t\tSystem.out.println(n + \" \" + m);\n\t\t\n\t\tInteger [] f = new Integer[m + 3];\n\t\tf[0] = Integer.valueOf(0);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tf[i] = Integer.valueOf((f[i - 1] + power(i, m)) % MOD);\n//\t\tSystem.out.println(power(Integer.valueOf(2), Integer.valueOf(100)));\n\n//\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n//\t\t\tSystem.out.print(f[i] + \" \");\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tif(n <= m + 2) return f[n];\n\t\t\n\t\tInteger [] lagrange = new Integer[m + 3];\n\t\tInteger [] fact = new Integer[m + 3];\n\t\tfact[0] = Integer.valueOf(1);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tfact[i] = mul(fact[i - 1], i);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++) {\n\t\t\tlagrange[i] = f[i];\n\t\t\tlagrange[i] = mul(lagrange[i], inv(mul(fact[i - 1], fact[m + 2 - i])));\n\t\t\tif(((m + 2 - i) & 1) == 1)\n\t\t\t\tlagrange[i] = MOD - lagrange[i];\n//\t\t\tSystem.out.print(lagrange[i] + \" \");\n\t\t}\n//\t\tSystem.out.println(\"\");\n\t\t\n\t\tInteger fullDenominator = Integer.valueOf(1);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++)\n\t\t\tfullDenominator = mul(fullDenominator, n - i);\n//\t\tSystem.out.println(fullDenominator);\n\t\t\n\t\tInteger ret = Integer.valueOf(0);\n\t\tfor(Integer i = Integer.valueOf(1); i <= m + 2; i++) {\n\t\t\tInteger denominator = Integer.valueOf(mul(fullDenominator, inv(n - i)));\n//\t\t\tSystem.out.print(denominator + \" \");\n\t\t\tret = (ret + mul(denominator, lagrange[i])) % MOD;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner reader = new Scanner(System.in);\n\t\tInteger n = new Integer(reader.nextInt());\n\t\tInteger k = new Integer(reader.nextInt());\n\t\t\n\t\tInteger ans = solve(n, k);\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t\treader.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9cb757ee7c94d32e66aeb3e685861c87", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class twoPlusTwoDoesNotEqualFour {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tString s = scan.nextLine();\n\t\tint ans = 0, temp = 0;\n\t\tboolean flagged = true;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s.charAt(i) >= '0' && s.charAt(i) <= '9') {\n\t\t\t\ttemp = temp * 10 + s.charAt(i) - '0';\n\t\t\t} else {\n\t\t\t\tif (flagged)\n\t\t\t\t\tans += temp;\n\t\t\t\telse\n\t\t\t\t\tans -= temp;\n\t\t\t\tif (s.charAt(i) == '+')\n\t\t\t\t\tflagged = true;\n\t\t\t\telse\n\t\t\t\t\tflagged = false;\n\t\t\t\ttemp = 0;\n\t\t\t\ttemp = temp * 10 + s.charAt(i) - '0';\n\t\t\t}\n\t\t}\n\t\tif (flagged)\n\t\t\tans += temp;\n\t\telse\n\t\t\tans -= temp;\n\t\tSystem.out.println(\"\" + ans);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "801ff5014a46c440da35e608dbc792c1", "src_uid": "db85fa18f00e560b58cfa7bab2fa957d", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main \n{\n public static void main(String[] args)\n {\n Scanner scanner = new Scanner(System.in);\n String s = scanner.next();\n int ans = 0, tmp = 0, len = s.length();\n boolean flag = true;\n for (int i = 0; i < len; i++) \n {\n if (s.charAt(i) >= '0' && s.charAt(i) <= '9') \n {\n tmp = tmp * 10 + s.charAt(i) - '0';\n }\n else \n {\n if (flag) ans += tmp;\n else ans -= tmp;\n if (s.charAt(i) == '+') flag = true;\n else flag = false;\n tmp = 0;\n tmp = tmp * 10 + s.charAt(i) - '0';\n }\n }\n if (flag) ans += tmp;\n else ans -= tmp;\n System.out.println(\"\" + ans);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "19306465d1c9afde6d04652c34fcc933", "src_uid": "db85fa18f00e560b58cfa7bab2fa957d", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.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 \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\n static class TaskF {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n String s = in.next();\n int n = s.length();\n int a = 1;\n int b = 0;\n int ans = 0;\n\n for (int i = 0; i < n; ++i) {\n if (s.charAt(i) == '-') {\n ans += a * b;\n a = -1;\n b = 0;\n } else if (s.charAt(i) == '+') {\n ans += a * b;\n a = 1;\n b = 0;\n }\n b = b * 10 + s.charAt(i) - '0';\n }\n\n ans += a * b;\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 String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return nextString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af083db976a541d28191f98e061c0dd7", "src_uid": "db85fa18f00e560b58cfa7bab2fa957d", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\n \npublic class Main \n{\n public static void main(String[] args)\n {\n Scanner input = new Scanner(System.in);\n String tkn = input.next();\n int val = 0\n\t\tint tmp = 0\n\t\tint qty = tkn.length();\n boolean flg = true;\n for (int i = 0; i < qty; i++) \n {\n if (tkn.charAt(i) >= '0' && tkn.charAt(i) <= '9') \n {\n tmp = tmp * 10 + tkn.charAt(i) - '0';\n }\n else \n {\n if (flg) val += tmp;\n else val -= tmp;\n if (tkn.charAt(i) == '+') flg = true;\n else flg = false;\n tmp = 0;\n tmp = tmp * 10 + tkn.charAt(i) - '0';\n }\n }\n if (flg) val += tmp;\n else val -= tmp;\n System.out.println(\"\" + val);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7a44838874dd0b4977a5977a7d1756ae", "src_uid": "db85fa18f00e560b58cfa7bab2fa957d", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n public class Number {\n int factNum;\n int[] primeFactorCounts;\n int largestFactor;\n int S = 0;\n public Number(int f, int[] primeFactorCounts) {\n this.factNum = f;\n this.primeFactorCounts = primeFactorCounts;\n for (largestFactor = primeFactorCounts.length - 1; largestFactor >= 0; largestFactor--) {\n if (primeFactorCounts[largestFactor] != 0) break;\n }\n for (int y: primeFactorCounts)S += y;\n }\n int getL() {\n if (largestFactor == -1) return -1;\n int r = largestFactor;\n primeFactorCounts[r]--;\n if (primeFactorCounts[r] == 0) largestFactor--;\n return r;\n }\n }\n\n List primes;\n int[] factor;\n\n public void precompute() {\n int n = 5001;\n primes = new ArrayList<>();\n factor = new int[n];\n Arrays.fill(factor, -1);\n for (int i = 2; i < n; ++i) {\n if (factor[i] == -1) {\n factor[i] = primes.size();\n primes.add(i);\n }\n for (int j = 0; j < primes.size () && i * primes.get(j) < n; ++j) {\n int p = primes.get(j);\n factor[i * p] = j;\n if (i % p == 0) {\n break;\n }\n }\n }\n }\n\n List fact(int x) {\n List retL = new ArrayList<>();\n while (x != 1) {\n retL.add(factor[x]);\n x /= primes.get(factor[x]);\n }\n return retL;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n precompute();\n int[] primeF = new int[700];\n Number[] numbers = new Number[5001];\n numbers[1] = new Number(1, Arrays.copyOf(primeF, 700));\n for (int i = 2; i <= 5000; i++) {\n List f = fact(i);\n for (int y: f) primeF[y]++;\n numbers[i] = new Number(i, Arrays.copyOf(primeF, 700));\n }\n// pw.println(Arrays.toString(numbers[5000].primeFactorCounts));\n// System.err.println(numbers[5000].S);\n Map numToCount = new HashMap<>();\n int n = sc.nextInt();\n for (int i = 0; i < n; i++) {\n int a = sc.nextInt();\n numToCount.put(a, numToCount.getOrDefault(a, 0) + 1);\n }\n long total = 0;\n for (Map.Entry en : numToCount.entrySet()) {\n total += (long) en.getValue() * numbers[en.getKey()].S;\n }\n outer:\n while (true) {\n Map kG = new HashMap<>();\n for (Map.Entry en : numToCount.entrySet()) {\n int k = en.getKey();\n int v = en.getValue();\n int lf = numbers[k].largestFactor;\n kG.put(lf, kG.getOrDefault(lf, 0) + v);\n }\n for (Map.Entry en: kG.entrySet()) {\n if (n - en.getValue() < en.getValue()) {\n total -= en.getValue() - (n - en.getValue());\n Map nC = new HashMap<>();\n for (Map.Entry en1 : numToCount.entrySet()) {\n int lf = numbers[en1.getKey()].getL();\n if (lf == en.getKey()) {\n nC.put(en1.getKey(), en1.getValue());\n }\n }\n numToCount = nC;\n continue outer;\n }\n }\n pw.println(total);\n return;\n }\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"output\"));\n\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a20dba2485313503aa573e5f5e8bce1e", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0} {"lang": "Java 8", "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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d2442d7ef443f93c5a4bbfa9f2a71622", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n public class Number {\n int factNum;\n int[] primeFactorCounts;\n int largestFactor;\n int S = 0;\n public Number(int f, int[] primeFactorCounts) {\n this.factNum = f;\n this.primeFactorCounts = primeFactorCounts;\n for (largestFactor = primeFactorCounts.length - 1; largestFactor >= 0; largestFactor--) {\n if (primeFactorCounts[largestFactor] != 0) break;\n }\n for (int y: primeFactorCounts)S += y;\n }\n int getL() {\n if (largestFactor == -1) return -1;\n int r = largestFactor;\n primeFactorCounts[r]--;\n if (primeFactorCounts[r] == 0) largestFactor--;\n return r;\n }\n }\n\n List primes;\n int[] factor;\n\n public void precompute() {\n int n = 5001;\n primes = new ArrayList<>();\n factor = new int[n];\n Arrays.fill(factor, -1);\n for (int i = 2; i < n; ++i) {\n if (factor[i] == -1) {\n factor[i] = primes.size();\n primes.add(i);\n }\n for (int j = 0; j < primes.size () && i * primes.get(j) < n; ++j) {\n int p = primes.get(j);\n factor[i * p] = j;\n if (i % p == 0) {\n break;\n }\n }\n }\n }\n\n List fact(int x) {\n List retL = new ArrayList<>();\n while (x != 1) {\n retL.add(factor[x]);\n x /= primes.get(factor[x]);\n }\n return retL;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n precompute();\n int[] primeF = new int[700];\n Number[] numbers = new Number[5001];\n// numbers[0] = new Number(1, Arrays.copyOf(primeF, 700));\n numbers[1] = new Number(1, Arrays.copyOf(primeF, 700));\n for (int i = 2; i <= 5000; i++) {\n List f = fact(i);\n for (int y: f) primeF[y]++;\n numbers[i] = new Number(i, Arrays.copyOf(primeF, 700));\n }\n// pw.println(Arrays.toString(numbers[5000].primeFactorCounts));\n// System.err.println(numbers[5000].S);\n Map numToCount = new HashMap<>();\n int n = sc.nextInt();\n for (int i = 0; i < n; i++) {\n int a = sc.nextInt();\n a = Math.max(a, 1);\n numToCount.put(a, numToCount.getOrDefault(a, 0) + 1);\n }\n long total = 0;\n for (Map.Entry en : numToCount.entrySet()) {\n total += (long) en.getValue() * numbers[en.getKey()].S;\n }\n outer:\n while (true) {\n Map kG = new HashMap<>();\n for (Map.Entry en : numToCount.entrySet()) {\n int k = en.getKey();\n int v = en.getValue();\n int lf = numbers[k].largestFactor;\n if (lf == -1) continue ;\n kG.put(lf, kG.getOrDefault(lf, 0) + v);\n }\n for (Map.Entry en: kG.entrySet()) {\n if (n - en.getValue() < en.getValue()) {\n total -= en.getValue() - (n - en.getValue());\n Map nC = new HashMap<>();\n for (Map.Entry en1 : numToCount.entrySet()) {\n int lf = numbers[en1.getKey()].getL();\n if (lf == en.getKey()) {\n nC.put(en1.getKey(), en1.getValue());\n }\n }\n numToCount = nC;\n continue outer;\n }\n }\n pw.println(total);\n return;\n }\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"output\"));\n\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "664c2908d0f38757da31d1ea2ff4e7fe", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class f {\n public static FS sc;\n public static PrintWriter out;\n public static ArrayList[] adj;\n public static int n;\n \n public static HashMap memo, memoSize;\n \n public static void main(String[] Args) throws Exception {\n sc = new FS(System.in);\n out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n = sc.nextInt();\n int MAX =5010;\n int[][] dist = new int[MAX][MAX];\n \n BIT bi = new BIT(MAX);\n int[] primes = new int[MAX];\n int[] factDivs = new int[MAX];\n int[] valDivs = new int[MAX];\n Arrays.fill(primes, 1);\n for (int i = 2; i < MAX; i++){\n if (primes[i] == 1){\n for (int j = i * 2; j < MAX; j+=i)\n primes[j] = i;\n valDivs[i]=1;\n primes[i] = i;\n }else \n valDivs[i]=valDivs[i/primes[i]] + 1;\n factDivs[i] = factDivs[i-1] + valDivs[i];\n \n }/*\n for (int i = 0; i<10; i++)\n {\n System.out.println(primes[i] +\" \" +valDivs[i] +\" \" +factDivs[i]);\n }*/\n \n for (int i = 2; i < MAX; i++){\n int last = bi.sum(MAX-1) - bi.sum(primes[i]-1);\n int j = i - 1;\n dist[i][i] = factDivs[i];\n while (last != 0) {\n dist[i][j] = dist[j][i] = last;\n int last2 = dist[i-1][j-1];\n if (last > last2)\n last = last2;\n j--;\n }\n int ii = i;\n while (ii != 1) {\n bi.inc(primes[ii],1);\n ii /= primes[ii];\n }\n }/*\n for (int i = 1; i < 6; i++){\n for (int j = 1; j < 6;j++) {\n int actDist = factDivs[i] + factDivs[j] - dist[i][j]*2;\n System.out.print(actDist +\" \" );\n }\n System.out.println();\n }*/\n \n long[] count = new long[MAX];\n for (int i = 0; i {\n int ind;\n long value;\n double value2;\n Pair(int ii, long vv) {\n ind=ii;value=vv;\n value2=0.0;\n }\n public int compareTo(Pair o) {\n if (o.value == value)\n return Double.compare(value2,o.value);\n return Long.compare(value, o.value);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c9710456b0fb6d07ae85aa1a7aef7305", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.stream.IntStream;\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 MakeDistanceFarthest mdf = new MakeDistanceFarthest(n);\n for (int i = 0; i < m; i++) {\n mdf.addEdge(in.readInt() - 1, in.readInt() - 1, in.readInt(), 1);\n }\n mdf.solve(new LongDijkstraV2MinimumCostFlow(n), 0, n - 1, (int) 1e5, (long) 1e18, (int) 1e9);\n int q = in.readInt();\n for (int i = 0; i < q; i++) {\n int x = in.readInt();\n double ans = mdf.queryByExpense(x);\n out.println(ans);\n }\n }\n\n }\n\n static interface LongMinimumCostFlow {\n long[] apply(List[] net, int s, int t, long send);\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 MakeDistanceFarthest {\n private List[] g;\n MakeDistanceFarthest.LinearFunction[] fs;\n\n public MakeDistanceFarthest(int n) {\n g = LongFlow.createCostFlow(n);\n }\n\n public void addEdge(int u, int v, long len, long cost) {\n LongFlow.addCostEdge(g, u, v, cost, len);\n }\n\n public void solve(LongAugmentMinimumCostFlow mcf, int s, int t, long budgeLimit, long distLimit, long flowLimit) {\n List list = new ArrayList<>();\n LongAugmentCallback callback = new LongAugmentCallback() {\n long sumFlow = 0;\n long sumCost = 0;\n\n\n public boolean callback(long flow, long 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 MakeDistanceFarthest.LinearFunction func = new MakeDistanceFarthest.LinearFunction(pathCost, sumFlow, -sumCost);\n list.add(func);\n return func.getL() <= budgeLimit && func.l <= distLimit;\n }\n };\n mcf.setCallback(callback);\n mcf.apply(g, s, t, flowLimit);\n fs = list.toArray(new MakeDistanceFarthest.LinearFunction[0]);\n }\n\n public double queryByExpense(long x) {\n int l = 0;\n int r = fs.length - 1;\n while (l < r) {\n int mid = (l + r) / 2;\n boolean valid = mid + 1 >= fs.length ||\n fs[mid + 1].getL() > x;\n if (valid) {\n r = mid;\n } else {\n l = mid + 1;\n }\n }\n return fs[l].inverse(x);\n }\n\n private static class LinearFunction {\n long l;\n long a;\n long b;\n\n public LinearFunction(long 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 inverse(double y) {\n return (y - b) / a;\n }\n\n }\n\n }\n\n static interface IntegerDeque extends IntegerStack {\n int removeFirst();\n\n }\n\n static interface LongAugmentCallback {\n public static LongAugmentCallback NIL = (a, b) -> {\n return true;\n };\n\n public boolean callback(long flow, long pathCost);\n\n }\n\n static class LongFlow {\n public static void send(T edge, long flow) {\n edge.flow += flow;\n edge.rev.flow -= flow;\n }\n\n public static LongCostFlowEdge addCostEdge(List[] g, int s, int t, long cap, long cost) {\n LongCostFlowEdge real = new LongCostFlowEdge(t, 0, true, cost);\n LongCostFlowEdge virtual = new LongCostFlowEdge(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[] 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 LongFlowEdge> extends DirectedEdge {\n public long flow;\n public boolean real;\n public T rev;\n\n public LongFlowEdge(int to, long 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 class LongDijkstraV2MinimumCostFlow implements LongAugmentMinimumCostFlow {\n private int m;\n private long[] lastDist;\n private long[] curDist;\n private LongCostFlowEdge[] prev;\n private boolean[] inq;\n private IntegerDeque dq;\n private static final long INF = Long.MAX_VALUE / 4;\n private List[] g;\n private LongAugmentCallback callback = LongAugmentCallback.NIL;\n\n public void setCallback(LongAugmentCallback callback) {\n this.callback = callback;\n }\n\n public LongDijkstraV2MinimumCostFlow(int m) {\n this.m = m - 1;\n lastDist = new long[m];\n curDist = new long[m];\n prev = new LongCostFlowEdge[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 (LongCostFlowEdge 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 (LongCostFlowEdge e : g[head]) {\n long 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 long[] apply(List[] net, int s, int t, long send) {\n this.g = net;\n bf(s);\n long flow = 0;\n long cost = 0;\n while (flow < send) {\n dijkstra(s);\n if (prev[t] == null) {\n break;\n }\n long remain = send - flow;\n for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {\n remain = Math.min(remain, trace.flow);\n }\n long sumOfCost = 0;\n for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {\n sumOfCost -= trace.cost;\n LongFlow.send(trace, -remain);\n }\n cost += sumOfCost * -remain;\n flow += remain;\n if (!callback.callback(remain, sumOfCost)) {\n break;\n }\n }\n return new long[]{flow, cost};\n }\n\n }\n\n static interface LongAugmentMinimumCostFlow extends LongMinimumCostFlow {\n public void setCallback(LongAugmentCallback callback);\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 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 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 LongCostFlowEdge extends LongFlowEdge {\n public long cost;\n\n public LongCostFlowEdge(int to, long flow, boolean real, long cost) {\n super(to, flow, real);\n this.cost = cost;\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 DigitUtils {\n private DigitUtils() {\n }\n\n public static boolean equal(long a, long b) {\n return a == b;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "743c9003246024a1189f6488c3c1c8f9", "src_uid": "b0751071e12f729f6700586c5a8eed23", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.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[] 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 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[] 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[] 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 {\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 void send(T edge, int flow) {\n edge.flow += flow;\n edge.rev.flow -= flow;\n }\n\n public static IntegerCostFlowEdge addCostEdge(List[] 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[] 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> 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d10bb70a8cc7adce7bb9df0d322bf572", "src_uid": "b0751071e12f729f6700586c5a8eed23", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.stream.IntStream;\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 MakeDistanceFarthest mdf = new MakeDistanceFarthest(n);\n for (int i = 0; i < m; i++) {\n mdf.addEdge(in.readInt() - 1, in.readInt() - 1, in.readInt(), 1);\n }\n mdf.solve(new LongDijkstraV2MinimumCostFlow(n), 0, n - 1);\n int q = in.readInt();\n for (int i = 0; i < q; i++) {\n int x = in.readInt();\n double ans = mdf.query(x);\n out.println(ans);\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 interface IntegerIterator {\n boolean hasNext();\n\n int next();\n\n }\n\n static class LongCostFlowEdge extends LongFlowEdge {\n public long cost;\n\n public LongCostFlowEdge(int to, long flow, boolean real, long cost) {\n super(to, flow, real);\n this.cost = cost;\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static boolean equal(long a, long 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 interface LongMinimumCostFlow {\n long[] apply(List[] net, int s, int t, long send);\n\n }\n\n static class MakeDistanceFarthest {\n private List[] g;\n MakeDistanceFarthest.LinearFunction[] fs;\n\n public MakeDistanceFarthest(int n) {\n g = LongFlow.createCostFlow(n);\n }\n\n public void addEdge(int u, int v, long len, long cost) {\n LongFlow.addCostEdge(g, u, v, cost, len);\n LongFlow.addCostEdge(g, v, u, cost, len);\n }\n\n public void solve(LongAugmentMinimumCostFlow mcf, int s, int t) {\n List list = new ArrayList<>();\n LongAugmentCallback callback = new LongAugmentCallback() {\n long sumFlow = 0;\n long sumCost = 0;\n\n\n public void callback(long flow, long 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 MakeDistanceFarthest.LinearFunction func = new MakeDistanceFarthest.LinearFunction(pathCost, sumFlow, -sumCost);\n list.add(func);\n }\n };\n mcf.setCallback(callback);\n mcf.apply(g, s, t, Long.MAX_VALUE / 4);\n fs = list.toArray(new MakeDistanceFarthest.LinearFunction[0]);\n }\n\n public double query(double x) {\n int l = 0;\n int r = fs.length - 1;\n while (l < r) {\n int mid = (l + r) / 2;\n boolean valid = mid + 1 >= fs.length ||\n fs[mid + 1].getL() > x;\n if (valid) {\n r = mid;\n } else {\n l = mid + 1;\n }\n }\n return fs[l].getX(x);\n }\n\n private static class LinearFunction {\n long l;\n long a;\n long b;\n\n public LinearFunction(long 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 }\n\n static class LongFlowEdge> extends DirectedEdge {\n public long flow;\n public boolean real;\n public T rev;\n\n public LongFlowEdge(int to, long 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 IntegerStack {\n void addLast(int x);\n\n boolean isEmpty();\n\n void clear();\n\n }\n\n static interface LongAugmentMinimumCostFlow extends LongMinimumCostFlow {\n public void setCallback(LongAugmentCallback callback);\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 interface LongAugmentCallback {\n public static LongAugmentCallback NIL = (a, b) -> {\n };\n\n public void callback(long flow, long pathCost);\n\n }\n\n static class LongFlow {\n public static void send(T edge, long flow) {\n edge.flow += flow;\n edge.rev.flow -= flow;\n }\n\n public static LongCostFlowEdge addCostEdge(List[] g, int s, int t, long cap, long cost) {\n LongCostFlowEdge real = new LongCostFlowEdge(t, 0, true, cost);\n LongCostFlowEdge virtual = new LongCostFlowEdge(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[] 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 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 class LongDijkstraV2MinimumCostFlow implements LongAugmentMinimumCostFlow {\n private int m;\n private long[] lastDist;\n private long[] curDist;\n private LongCostFlowEdge[] prev;\n private boolean[] inq;\n private IntegerDeque dq;\n private static final long INF = Long.MAX_VALUE / 4;\n private List[] g;\n private LongAugmentCallback callback = LongAugmentCallback.NIL;\n\n public void setCallback(LongAugmentCallback callback) {\n this.callback = callback;\n }\n\n public LongDijkstraV2MinimumCostFlow(int m) {\n this.m = m - 1;\n lastDist = new long[m];\n curDist = new long[m];\n prev = new LongCostFlowEdge[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 (LongCostFlowEdge 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 (LongCostFlowEdge e : g[head]) {\n long 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 long[] apply(List[] net, int s, int t, long send) {\n this.g = net;\n bf(s);\n long flow = 0;\n long cost = 0;\n while (flow < send) {\n dijkstra(s);\n if (prev[t] == null) {\n break;\n }\n long remain = send - flow;\n for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {\n remain = Math.min(remain, trace.flow);\n }\n long sumOfCost = 0;\n for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {\n sumOfCost -= trace.cost;\n LongFlow.send(trace, -remain);\n }\n cost += sumOfCost * -remain;\n flow += remain;\n callback.callback(remain, sumOfCost);\n }\n return new long[]{flow, cost};\n }\n\n }\n\n static interface IntegerDeque extends IntegerStack {\n int removeFirst();\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c96da4b244952802e16673378a9271da", "src_uid": "b0751071e12f729f6700586c5a8eed23", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint n;\n\tint[] p;\n\tint[] sz;\n\tint[] who;\n\n\tint[] to;\n\tint[] head;\n\tint[] next;\n\n\tvoid addEdge(int v, int u, int idx) {\n\t\tto[idx] = u;\n\t\tnext[idx] = head[v];\n\t\thead[v] = idx;\n\t}\n\n\tboolean cool(int a, int b, int c, int d) {\n\t\tboolean[] can = new boolean[n];\n\t\tcan[0] = true;\n\n\t\tint base = 0;\n\n\t\tfor (int v = p[a]; v != 0; v = p[v]) {\n\t\t\tbase++; // need to take this edge\n\n\t\t\tfor (int e = head[v]; e >= 0; e = next[e]) {\n\t\t\t\tint u = to[e];\n\t\t\t\tif (who[u] == a) {\n\t\t\t\t\t// System.err.println(v + \" a \" + u);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint nowSz = 2 * sz[u];\n\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int v = p[b]; v != 0; v = p[v]) {\n\t\t\tbase++; // need to take this edge\n\n\t\t\tfor (int e = head[v]; e >= 0; e = next[e]) {\n\t\t\t\tint u = to[e];\n\t\t\t\tif (who[u] == b) {\n\t\t\t\t\t// System.err.println(v + \" b \" + u);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint nowSz = 2 * sz[u];\n\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint szC = -1;\n\t\tint szD = -1;\n\t\tfor (int e = head[0]; e >= 0; e = next[e]) {\n\t\t\tint u = to[e];\n\t\t\tif (who[u] == c) {\n\t\t\t\tszC = 2 * sz[u];\n\t\t\t} else if (who[u] == d) {\n\t\t\t\tszD = 2 * sz[u];\n\t\t\t} else if (who[u] == -1) {\n\t\t\t\tint nowSz = 2 * sz[u];\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (szC == -1 || szD == -1) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\n\t\tbase += 2 + szC; // edges from root and C\n\n\t\t// System.err.println(Arrays.toString(can));\n\t\t// System.err.println(base);\n\t\t// System.err.println(szC + \" \" + szD);\n\n\t\tint need = n - 1 - base;\n\n\t\tif (need < 0 || need >= can.length || !can[need]) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tint a = nextInt() - 1;\n\t\tint b = nextInt() - 1;\n\t\tint c = nextInt() - 1;\n\t\tint d = nextInt() - 1;\n\n\t\thead = new int[n];\n\t\tArrays.fill(head, -1);\n\t\tto = new int[n - 1];\n\t\tnext = new int[n - 1];\n\n\t\tp = new int[n];\n\t\tp[0] = -1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tp[i] = nextInt() - 1;\n\t\t\taddEdge(p[i], i, i - 1);\n\t\t}\n\n\t\tsz = new int[n];\n\t\twho = new int[n];\n\n\t\tArrays.fill(who, -1);\n\t\twho[a] = a;\n\t\twho[b] = b;\n\t\twho[c] = c;\n\t\twho[d] = d;\n\n\t\tArrays.fill(sz, 1);\n\t\tfor (int i = n - 1; i >= 1; i--) {\n\t\t\tsz[p[i]] += sz[i];\n\t\t\tif (who[i] != -1) {\n\t\t\t\twho[p[i]] = who[i];\n\t\t\t}\n\t\t}\n\n\t\tout.println(cool(a, b, c, d) && cool(c, d, a, b) ? \"YES\" : \"NO\");\n\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c22f7af6fe5c86ba6818a4ee69abd52", "src_uid": "87db879f0ca422020125a3e4d99d3c23", "difficulty": 2900.0} {"lang": "Java 8", "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 = 1;i--){\n\t\t\tint cur = ord[i];\n\t\t\tdes[cur]++;\n\t\t\tdes[par[cur]] += des[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] = new boolean[2*des[cur]-1];\n\t\t\tfor(int j = 0;j < dp[dome].length;j++){\n\t\t\t\tdp[cur][j+1] = dp[dome][j];\n\t\t\t}\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-(des[e]+1);j >= 0;j--){\n\t\t\t\t\tdp[cur][j+des[e]+1] |= dp[cur][j];\n\t\t\t\t}\n\t\t\t}\n//\t\t\ttr(dom[cur]);\n//\t\t\ttf(dp[cur]);\n\t\t}\n//\t\ttr(dom);\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 >= 2*des[e];j--){\n\t\t\t\t\tep[j] |= ep[j-2*des[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}\n\t\t}\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 = n-2-(dps[0].length-i-1 + j + 1) - (fa[2]+1);\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 = n-2-(dps[2].length-i-1 + j + 1) - (fa[1]+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 = n-2-(dps[0].length-i-1 + j + 1) - (fa[3]+1);\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 = n-2-(dps[3].length-i-1 + j + 1) - (fa[1]+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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b1dd04af32834d3fc61aae93cff69bf3", "src_uid": "87db879f0ca422020125a3e4d99d3c23", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint n;\n\tint[] p;\n\tint[] sz;\n\tint[] who;\n\n\tint[] to;\n\tint[] head;\n\tint[] next;\n\n\tvoid addEdge(int v, int u, int idx) {\n\t\tto[idx] = u;\n\t\tnext[idx] = head[v];\n\t\thead[v] = idx;\n\t}\n\n\tboolean cool(int a, int b, int c, int d) {\n\t\tboolean[] can = new boolean[n];\n\t\tcan[0] = true;\n\n\t\tint base = 0;\n\n\t\tfor (int v = p[a]; v != 0; v = p[v]) {\n\t\t\tbase++; // need to take this edge\n\n\t\t\tfor (int e = head[v]; e >= 0; e = next[e]) {\n\t\t\t\tint u = to[e];\n\t\t\t\tif (who[u] == a) {\n\t\t\t\t\t// System.err.println(v + \" a \" + u);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint nowSz = 2 * sz[u];\n\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int v = p[b]; v != 0; v = p[v]) {\n\t\t\tbase++; // need to take this edge\n\n\t\t\tfor (int e = head[v]; e >= 0; e = next[e]) {\n\t\t\t\tint u = to[e];\n\t\t\t\tif (who[u] == b) {\n\t\t\t\t\t// System.err.println(v + \" b \" + u);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint nowSz = 2 * sz[u];\n\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint szC = -1;\n\t\tint szD = -1;\n\t\tfor (int e = head[0]; e >= 0; e = next[e]) {\n\t\t\tint u = to[e];\n//\t\t\tSystem.err.println(who[u]);\n\t\t\tif (who[u] == c) {\n\t\t\t\tszC = 2 * sz[u];\n\t\t\t} else if (who[u] == d) {\n\t\t\t\tszD = 2 * sz[u];\n\t\t\t} else if (who[u] == -1) {\n\t\t\t\tint nowSz = 2 * sz[u];\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (szC == -1 || szD == -1) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\n\t\tbase += 2 + szC; // edges from root and C\n\n\t\tint need = n - 1 - base;\n\n\t\tif (need < 0 || need >= can.length || !can[need]) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tint a = nextInt() - 1;\n\t\tint b = nextInt() - 1;\n\t\tint c = nextInt() - 1;\n\t\tint d = nextInt() - 1;\n\n\t\thead = new int[n];\n\t\tArrays.fill(head, -1);\n\t\tto = new int[n - 1];\n\t\tnext = new int[n - 1];\n\n\t\tp = new int[n];\n\t\tp[0] = -1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tp[i] = nextInt() - 1;\n\t\t\taddEdge(p[i], i, i - 1);\n\t\t}\n\n\t\tsz = new int[n];\n\t\twho = new int[n];\n\n\t\tArrays.fill(who, -1);\n\t\twho[a] = a;\n\t\twho[b] = b;\n\t\twho[c] = c;\n\t\twho[d] = d;\n\n\t\tArrays.fill(sz, 1);\n\t\tfor (int i = n - 1; i >= 1; i--) {\n\t\t\tsz[p[i]] += sz[i];\n\t\t\tif (who[i] != -1) {\n\t\t\t\tif (who[p[i]] != -1 && p[i] != 0) {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t\twho[p[i]] = who[i];\n\t\t\t}\n\t\t}\n\n\t\tout.println(cool(a, b, c, d) && cool(c, d, a, b) ? \"YES\" : \"NO\");\n\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a2bc16e1ab2399bf9b0a4f57f306a68", "src_uid": "87db879f0ca422020125a3e4d99d3c23", "difficulty": 2900.0} {"lang": "Java 8", "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 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[] 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 = 1;i--){\n\t\t\tint cur = ord[i];\n\t\t\tdes[cur]++;\n\t\t\tdes[par[cur]] += des[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] = new boolean[2*des[cur]-1];\n\t\t\tfor(int j = 0;j < dp[dome].length;j++){\n\t\t\t\tdp[cur][j+1] = dp[dome][j];\n\t\t\t}\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-(des[e]+1);j >= 0;j--){\n\t\t\t\t\tdp[cur][j+des[e]+1] |= dp[cur][j];\n\t\t\t\t}\n\t\t\t}\n//\t\t\ttr(dom[cur]);\n//\t\t\ttf(dp[cur]);\n\t\t}\n//\t\ttr(dom);\n\t\t\n\t\tboolean[][] ep = new boolean[n+1][n+1];\n\t\tep[0][0] = true;\n\t\tint[] xds = new int[n+1];\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\txds[des[e]+1]++;\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}\n\t\t}\n\t\tint rem = 0;\n\t\tfor(int i = 1;i <= n;i++){\n\t\t\tif(xds[i] == 0)continue;\n\t\t\trem += xds[i]*i;\n\t\t\tint j = 1;\n\t\t\tfor(;j <= xds[i];j *=2){\n\t\t\t\tfor(int k = 0;k <= rem-i*j;k++){\n\t\t\t\t\tfor(int l = 0;l <= rem-i*j;l++){\n\t\t\t\t\t\tep[k+i*j][l+i*j] |= ep[k][l];\n\t\t\t\t\t\tep[k+i*j][l] |= ep[k][l];\n\t\t\t\t\t\tep[k][l+i*j] |= ep[k][l];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\txds[i] -= j/2;\n\t\t\tif(xds[i] > 0){\n\t\t\t\tj = xds[i];\n\t\t\t\tfor(int k = 0;k <= rem-i*j;k++){\n\t\t\t\t\tfor(int l = 0;l <= rem-i*j;l++){\n\t\t\t\t\t\tep[k+i*j][l+i*j] |= ep[k][l];\n\t\t\t\t\t\tep[k+i*j][l] |= ep[k][l];\n\t\t\t\t\t\tep[k][l+i*j] |= ep[k][l];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\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 = n-2-(dps[0].length-i-1 + j + 1) - (fa[2]+1);\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 = n-2-(dps[2].length-i-1 + j + 1) - (fa[1]+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][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 = n-2-(dps[0].length-i-1 + j + 1) - (fa[3]+1);\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 = n-2-(dps[3].length-i-1 + j + 1) - (fa[1]+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][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 E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "26091504f06a2b9de0b285d1de42e7b4", "src_uid": "87db879f0ca422020125a3e4d99d3c23", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.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.util.stream.Stream;\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) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n public int n;\n public int s;\n public int m;\n public List[] graph;\n public int[][] dist;\n public boolean[] leaf;\n public int[] cc;\n public int MAXANS = 50 * 50 * 50;\n public ArrayList leaves;\n public int count;\n public int[][] dp;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n dist = new int[n][n];\n for (int[] x : dist) Arrays.fill(x, 1 << 29);\n for (int i = 0; i < n; i++) dist[i][i] = 0;\n graph = LUtils.genArrayList(n);\n for (int i = 0; i < n - 1; i++) {\n int a = in.nextInt() - 1, b = in.nextInt() - 1, c = in.nextInt();\n dist[a][b] = dist[b][a] = c;\n graph[a].add(b);\n graph[b].add(a);\n }\n leaf = new boolean[n];\n for (int i = 0; i < n; i++) {\n leaf[i] = graph[i].size() == 1;\n }\n for (int k = 0; k < n; k++) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);\n }\n }\n }\n s = in.nextInt() - 1;\n m = in.nextInt();\n cc = new int[n];\n for (int i = 0; i < m; i++) cc[in.nextInt() - 1]++;\n\n dp = new int[n + 1][m + 1];\n int best = Integer.MAX_VALUE;\n for (int[] x : dp) Arrays.fill(x, -1);\n for (int j : graph[s]) {\n count = 0;\n leaves = new ArrayList<>();\n dfs(j, s);\n\n if (count > 0) {\n int lo = 0, hi = MAXANS;\n while (lo < hi) {\n int mid = (lo + hi + 1) / 2;\n if (can2(mid, count)) lo = mid;\n else hi = mid - 1;\n }\n best = Math.min(best, lo);\n }\n }\n out.println(best);\n }\n\n public boolean can2(int target, int have) {\n int tot = 0;\n for (int j : leaves) {\n int add = dist[s][j];\n if (solve(j, m - 1) + add >= target) {\n int canadd = 1;\n while (canadd < have && solve(j, m - canadd - 1) + add >= target) canadd++;\n tot += canadd;\n }\n }\n return tot >= have;\n }\n\n public void dfs(int node, int par) {\n if (leaf[node]) leaves.add(node);\n count += cc[node];\n for (int next : graph[node]) {\n if (next == par) continue;\n dfs(next, node);\n }\n }\n\n public int solve(int node, int crim) {\n if (crim == 0) return 0;\n if (dp[node][crim] != -1) return dp[node][crim];\n int lo = 0, hi = MAXANS;\n while (lo < hi) {\n int mid = (lo + hi + 1) / 2;\n if (can(mid, node, crim)) lo = mid;\n else hi = mid - 1;\n }\n return dp[node][crim] = lo;\n }\n\n public boolean can(int target, int node, int crim) {\n int tot = 0;\n for (int j = 0; j < n; j++) {\n if (leaf[j] && j != node) {\n int add = dist[node][j];\n if (solve(j, crim - 1) + add >= target) {\n int canadd = 1;\n while (canadd < crim && solve(j, crim - canadd - 1) + add >= target) canadd++;\n tot += canadd;\n }\n }\n }\n return tot >= crim;\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 static class LUtils {\n public static List[] genArrayList(int size) {\n return Stream.generate(ArrayList::new).limit(size).toArray(List[]::new);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "81c81ac9fbe4708deb9e0d22af7b97e5", "src_uid": "34b926f903c2412fe76f912ccb8a00dd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n TaskE.Vertex[] v = new TaskE.Vertex[n];\n for (int i = 0; i < n; ++i) {\n v[i] = new TaskE.Vertex();\n }\n for (int i = 0; i < n - 1; ++i) {\n TaskE.Vertex a = v[in.nextInt() - 1];\n TaskE.Vertex b = v[in.nextInt() - 1];\n long len = in.nextLong();\n TaskE.Edge ab = new TaskE.Edge(a, b, len);\n TaskE.Edge ba = new TaskE.Edge(b, a, len);\n ab.rev = ba;\n ba.rev = ab;\n a.edges.add(ab);\n b.edges.add(ba);\n }\n TaskE.Vertex police = v[in.nextInt() - 1];\n int m = in.nextInt();\n for (int i = 0; i < m; ++i) {\n ++v[in.nextInt() - 1].startCount;\n }\n for (TaskE.Vertex u : v) {\n for (TaskE.Edge e : u.edges) {\n e.res = new long[m + 1][m + 1];\n for (long[] x : e.res) Arrays.fill(x, -1);\n }\n }\n police.findSubtreeSums(null);\n long res = Long.MAX_VALUE;\n for (TaskE.Edge e : police.edges)\n if (e.dst.subtreeSum > 0) {\n res = Math.min(res, e.solve(m, e.dst.subtreeSum));\n }\n out.println(res);\n }\n\n static class Edge {\n TaskE.Vertex src;\n TaskE.Vertex dst;\n TaskE.Edge rev;\n long[][] res;\n long len;\n\n public Edge(TaskE.Vertex src, TaskE.Vertex dst, long len) {\n this.src = src;\n this.dst = dst;\n this.len = len;\n }\n\n public long solve(int totalRemaining, int inSubtree) {\n if (totalRemaining == 0) return 0;\n if (res[totalRemaining][inSubtree] >= 0) return res[totalRemaining][inSubtree];\n boolean any = false;\n long[] worst = new long[totalRemaining + 1];\n Arrays.fill(worst, -1);\n worst[0] = Long.MAX_VALUE;\n for (TaskE.Edge e : dst.edges) {\n if (e.dst != src) {\n any = true;\n for (int before = worst.length - 1; before >= 0; --before)\n if (worst[before] >= 0) {\n for (int here = 1; before + here <= totalRemaining; ++here) {\n long got = e.solve(totalRemaining, here);\n worst[before + here] = Math.max(worst[before + here], Math.min(worst[before], got));\n }\n }\n }\n }\n if (!any) {\n for (int a = 1; a <= totalRemaining; ++a) {\n res[totalRemaining][a] = len + rev.solve(totalRemaining - a, totalRemaining - a);\n }\n } else {\n for (int a = 1; a <= totalRemaining; ++a) {\n res[totalRemaining][a] = len + worst[a];\n }\n }\n return res[totalRemaining][inSubtree];\n }\n\n }\n\n static class Vertex {\n int startCount;\n int subtreeSum;\n List edges = new ArrayList<>();\n\n public void findSubtreeSums(TaskE.Vertex parent) {\n subtreeSum = startCount;\n for (TaskE.Edge e : edges)\n if (e.dst != parent) {\n e.dst.findSubtreeSums(this);\n subtreeSum += e.dst.subtreeSum;\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 public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eccd114df591ea6dcba8542d025e4239", "src_uid": "34b926f903c2412fe76f912ccb8a00dd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\nimport java.util.Arrays;\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 EPolicemanAndATree solver = new EPolicemanAndATree();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class EPolicemanAndATree {\n Debug debug = new Debug(true);\n int[][] fdp;\n int inf = (int) 1e9;\n int[][] f;\n Node[] nodes;\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n nodes = new Node[n];\n for (int i = 0; i < n; i++) {\n nodes[i] = new Node();\n nodes[i].id = i;\n }\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 Edge e = new Edge();\n e.a = a;\n e.b = b;\n e.w = in.readInt();\n a.next.add(e);\n b.next.add(e);\n }\n\n\n Node root = nodes[in.readInt() - 1];\n\n int m = in.readInt();\n for (int i = 0; i < m; i++) {\n Node node = nodes[in.readInt() - 1];\n node.thief++;\n }\n m -= root.thief;\n root.thief = 0;\n if (m == 0) {\n out.println(0);\n return;\n }\n\n\n f = new int[n][m + 1];\n List leaf = new ArrayList<>(n);\n fdp = new int[n + 1][m + 1];\n\n for (int i = 1; i <= m; i++) {\n for (int j = 0; j < n; j++) {\n if (!isLeaf(nodes[j])) {\n continue;\n }\n leaf.clear();\n dfs(nodes[j], null, 0, leaf);\n f[j][i] = maxStep(leaf, i, i);\n }\n }\n\n debug.debug(\"f\", f);\n int ans = inf;\n for (Edge e : root.next) {\n Node node = e.other(root);\n leaf.clear();\n int thief = dfs(node, root, e.w, leaf);\n if (thief == 0) {\n continue;\n }\n int against = maxStep(leaf, thief, m);\n ans = Math.min(ans, against);\n }\n\n out.println(ans);\n }\n\n public int maxStep(List leaf, int m, int total) {\n SequenceUtils.deepFill(fdp, -inf);\n fdp[0][0] = 0;\n int n = leaf.size();\n for (int i = 1; i <= n; i++) {\n Node node = leaf.get(i - 1);\n for (int j = 0; j <= m; j++) {\n fdp[i][j] = fdp[i - 1][j];\n for (int k = 1; k <= j; k++) {\n if (j - k > 0) {\n fdp[i][j] = Math.max(fdp[i][j], Math.min(fdp[i - 1][j - k], node.depth + f[node.id][total - k]));\n } else {\n fdp[i][j] = Math.max(fdp[i][j], node.depth + f[node.id][total - k]);\n }\n }\n }\n }\n return fdp[n][m];\n }\n\n public boolean isLeaf(Node node) {\n return node.next.size() == 1;\n }\n\n public int dfs(Node root, Node p, int depth, List leaf) {\n root.depth = depth;\n boolean isLeaf = true;\n int ans = root.thief;\n for (Edge e : root.next) {\n Node node = e.other(root);\n if (node == p) {\n continue;\n }\n isLeaf = false;\n ans += dfs(node, root, depth + e.w, leaf);\n }\n\n if (isLeaf) {\n leaf.add(root);\n }\n return ans;\n }\n\n }\n\n static class Debug {\n private boolean offline;\n private PrintStream out = System.err;\n static int[] empty = new int[0];\n\n public Debug(boolean enable) {\n offline = enable && System.getSecurityManager() == null;\n }\n\n public Debug debug(String name, Object x) {\n return debug(name, x, empty);\n }\n\n public Debug debug(String name, Object x, int... indexes) {\n if (offline) {\n if (x == null || !x.getClass().isArray()) {\n out.append(name);\n for (int i : indexes) {\n out.printf(\"[%d]\", i);\n }\n out.append(\"=\").append(\"\" + x);\n out.println();\n } else {\n indexes = Arrays.copyOf(indexes, indexes.length + 1);\n if (x instanceof byte[]) {\n byte[] arr = (byte[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof short[]) {\n short[] arr = (short[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof boolean[]) {\n boolean[] arr = (boolean[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof char[]) {\n char[] arr = (char[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof int[]) {\n int[] arr = (int[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof float[]) {\n float[] arr = (float[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof double[]) {\n double[] arr = (double[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof long[]) {\n long[] arr = (long[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else {\n Object[] arr = (Object[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n }\n }\n }\n return this;\n }\n\n }\n\n static class SequenceUtils {\n public static void deepFill(Object array, int val) {\n if (!array.getClass().isArray()) {\n throw new IllegalArgumentException();\n }\n if (array instanceof int[]) {\n int[] intArray = (int[]) array;\n Arrays.fill(intArray, val);\n } else {\n Object[] objArray = (Object[]) array;\n for (Object obj : objArray) {\n deepFill(obj, val);\n }\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 Edge {\n Node a;\n Node b;\n int w;\n\n Node other(Node x) {\n return a == x ? b : a;\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 Node {\n List next = new ArrayList<>();\n int id;\n int thief;\n int depth;\n\n public String toString() {\n return \"\" + id;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4ef92c5068ddb60b7a9b676f303f8d3", "src_uid": "34b926f903c2412fe76f912ccb8a00dd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n TaskE.Vertex[] v = new TaskE.Vertex[n];\n for (int i = 0; i < n; ++i) {\n v[i] = new TaskE.Vertex();\n }\n for (int i = 0; i < n - 1; ++i) {\n TaskE.Vertex a = v[in.nextInt() - 1];\n TaskE.Vertex b = v[in.nextInt() - 1];\n long len = in.nextLong();\n TaskE.Edge ab = new TaskE.Edge(a, b, len);\n TaskE.Edge ba = new TaskE.Edge(b, a, len);\n ab.rev = ba;\n ba.rev = ab;\n a.edges.add(ab);\n b.edges.add(ba);\n }\n TaskE.Vertex police = v[in.nextInt() - 1];\n int m = in.nextInt();\n for (int i = 0; i < m; ++i) {\n ++v[in.nextInt() - 1].startCount;\n }\n for (TaskE.Vertex u : v) {\n for (TaskE.Edge e : u.edges) {\n e.res = new long[m + 1][m + 1];\n for (long[] x : e.res) Arrays.fill(x, -1);\n }\n }\n police.findSubtreeSums(null);\n long res = Long.MAX_VALUE;\n for (TaskE.Edge e : police.edges)\n if (e.dst.subtreeSum > 0) {\n res = Math.min(res, e.solve(m, e.dst.subtreeSum));\n }\n out.println(res);\n }\n\n static class Edge {\n TaskE.Vertex src;\n TaskE.Vertex dst;\n TaskE.Edge rev;\n long[][] res;\n long len;\n\n public Edge(TaskE.Vertex src, TaskE.Vertex dst, long len) {\n this.src = src;\n this.dst = dst;\n this.len = len;\n }\n\n public long solve(int totalRemaining, int inSubtree) {\n if (totalRemaining == 0) return 0;\n if (res[totalRemaining][inSubtree] >= 0) return res[totalRemaining][inSubtree];\n boolean any = false;\n long[] worst = new long[totalRemaining + 1];\n Arrays.fill(worst, -1);\n worst[0] = Long.MAX_VALUE;\n for (TaskE.Edge e : dst.edges) {\n if (e.dst != src) {\n any = true;\n for (int before = worst.length - 1; before >= 0; --before)\n if (worst[before] >= 0) {\n for (int here = 1; before + here <= totalRemaining; ++here) {\n long got = e.solve(totalRemaining, here);\n worst[before + here] = Math.max(worst[before + here], Math.min(worst[before], got));\n }\n }\n }\n }\n if (!any) {\n for (int a = 1; a <= totalRemaining; ++a) {\n res[totalRemaining][a] = len + rev.solve(totalRemaining - a, totalRemaining - a);\n }\n } else {\n for (int a = 1; a <= totalRemaining; ++a) {\n res[totalRemaining][a] = len + worst[a];\n }\n }\n return res[totalRemaining][inSubtree];\n }\n\n }\n\n static class Vertex {\n int startCount;\n int subtreeSum;\n List edges = new ArrayList<>();\n\n public void findSubtreeSums(TaskE.Vertex parent) {\n subtreeSum = startCount;\n for (TaskE.Edge e : edges)\n if (e.dst != parent) {\n e.dst.findSubtreeSums(this);\n subtreeSum += e.dst.subtreeSum;\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 public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b601c7b3bd3e25c037990058a216e223", "src_uid": "34b926f903c2412fe76f912ccb8a00dd", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic Scanner in; static int next() throws Exception {return in.nextInt();}\n\tstatic PrintWriter out;\n//\tstatic StreamTokenizer in;\n\n\tstatic int h;\n\tstatic int m;\n\tstatic int k;\n\n\tstatic long count(int hh, int mm) {\n\t\tint c = ((m - 1) + \"\").length();\n\n\t\tif (k > c) {\n\t\t\tint kk = k;\n\t\t\tkk -= c;\n\n\t\t\tfor (int i = 0; i < kk - 1; i++) hh /= 10;\n\t\t\treturn hh;\n\t\t} else {\n\t\t\tint m0 = m;\n\n\t\t\tfor (int i = 0; i < k - 1; i++) m0 /= 10;\n\t\t\tfor (int i = 0; i < k - 1; i++) mm /= 10;\n\n\t\t\treturn (long)m0 * hh + mm;\n\t\t}\n\t}\n\n\t\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n//\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\t\n\t\th = next();\n\t\tm = next();\n\t\tk = next();\n\n\t\tint h1 = next();\n\t\tint m1 = next();\n\n\t\tint h2 = next();\n\t\tint m2 = next();\n\n//\t\tout.println(count(h2, m2));\n//\t\tout.println(count(h1, m1));\n\n\t\tlong answ = count(h2, m2) - count(h1, m1);\n\n\t\tif (answ < 0) answ += count(h, 0);\n\n\t\tout.println(answ);\n\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "10e69ff2311538e722cbcd49c30fdf2f", "src_uid": "e2782743229645ad3a0f8e815d86dc5f", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic Scanner in; static int next() throws Exception {return in.nextInt();}\n\tstatic PrintWriter out;\n//\tstatic StreamTokenizer in;\n\n\tstatic int h;\n\tstatic int m;\n\tstatic int k;\n\n\tstatic long count(int hh, int mm) {\n\t\tint c = ((m - 1) + \"\").length();\n\n\t\tif (k > c) {\n\t\t\tint kk = k;\n\t\t\tkk -= c;\n\n\t\t\tfor (int i = 0; i < kk - 1; i++) hh /= 10;\n\t\t\treturn hh;\n\t\t} else {\n\t\t\tint m0 = m;\n\n\t\t\tfor (int i = 0; i < k - 1; i++) m0 /= 10;\n\t\t\tint m1 = m0;\n\t\t\tfor (int i = 0; i < k - 1; i++) m1 *= 10;\n\t\t\tif (m1 < m) m0++;\n\t\t\tfor (int i = 0; i < k - 1; i++) mm /= 10;\n\n\t\t\treturn (long)m0 * hh + mm;\n\t\t}\n\t}\n\n\t\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n//\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\t\n\t\th = next();\n\t\tm = next();\n\t\tk = next();\n\n\t\tint h1 = next();\n\t\tint m1 = next();\n\n\t\tint h2 = next();\n\t\tint m2 = next();\n\n//\t\tout.println(count(h2, m2));\n//\t\tout.println(count(h1, m1));\n\n\t\tlong answ = count(h2, m2) - count(h1, m1);\n\n\t\tif (answ < 0) answ += count(h - 1, m - 1) + 1;\n\n\t\tout.println(answ);\n\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "21e9538bdd71f3d04f5f2e3d25392e28", "src_uid": "e2782743229645ad3a0f8e815d86dc5f", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "//package prac;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R86E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n//\t\tfor(int h = 0;h <= 1;h++){\n//\t\t\tfor(int i = 0;i <= 100;i++){\n//\t\t\t\ttr(h, i, count(h, 12, i, 101));\n//\t\t\t}\n//\t\t}\n//\t\ttr(count(2, 12, 0, 60));\n\t\t\n\t\tint h = ni(), m = ni(), K = ni();\n\t\tint h1 = ni(), m1 = ni();\n\t\tint h2 = ni(), m2 = ni();\n\t\tif(h1 < h2 || (h1 == h2 && m1 <= m2)){\n\t\t\tout.println(count(h2, h, m2, m)[K] - count(h1, h, m1, m)[K]);\n\t\t}else{\n//\t\t\ttr(count(h-1, h, m-1, m));\n//\t\t\ttr(count(h, h, 0, m));\n//\t\t\ttr(count(h1, h, m1, m));\n//\t\t\ttr(count(h2, h, m2, m));\n\t\t\tout.println(count(h, h, 0, m)[K] - count(h1, h, m1, m)[K]\n\t\t\t\t\t + count(h2, h, m2, m)[K]);\n\t\t}\n\t}\n\t\n\tlong[] count(int h, int hlim, int m, int mlim)\n\t{\n\t\tlong[] ret = new long[24];\n\t\tif(h == hlim){\n\t\t\th--;\n\t\t\tm = mlim-1;\n\t\t\tint eh = 0;\n\t\t\tfor(int u = hlim-1;u > 0;u/=10){\n\t\t\t\tif(u%10 != 0)eh++;\n\t\t\t}\n\t\t\tint ec = 0;\n\t\t\tfor(int u = mlim-1;u > 0;u/=10){\n\t\t\t\tif(u%10 != 0)ec++;\n\t\t\t}\n\t\t\tret[eh+ec]++;\n\t\t}\n\t\tlong[] hdis = count(h, hlim);\n\t\tlong[] mdis = count(m, mlim);\n\t\tlong[] madis = count(mlim-1, mlim);\n\t\t\n\t\tint ec = 0;\n\t\tfor(int u = mlim-1;u > 0;u/=10){\n\t\t\tif(u%10 != 0)ec++;\n\t\t}\n\t\tfor(int i = 0;i < hdis.length;i++){\n\t\t\tret[i+ec] += hdis[i];\n\t\t}\n\t\tfor(int i = 0;i < mdis.length;i++){\n\t\t\tret[i] += mdis[i] + madis[i] * h;\n\t\t}\n\t\t\n\t\tfor(int i = ret.length-2;i >= 1;i--){\n\t\t\tret[i] += ret[i+1];\n\t\t}\n\t\t\n\t\treturn ret;\n\t}\n\t\n\t// 0->1, ..., m-1->m \u306e\u5206\u5e03\n\tlong[] count(int m, int mlim)\n\t{\n\t\tlong[] ret = new long[12];\n\t\tfor(int i = 1, u = Math.min(m, mlim-1);i <= 10;i++, u/=10){\n\t\t\tret[i] = u;\n\t\t}\n\t\tfor(int i = 1;i <= 9;i++){\n\t\t\tret[i] -= ret[i+1];\n\t\t}\n\t\t\n\t\tif(m == mlim){\n\t\t\tint ec = 0;\n\t\t\tfor(int u = m;u > 0;u/=10){\n\t\t\t\tif(u%10 != 0)ec++;\n\t\t\t}\n\t\t\tret[ec]++;\n\t\t}\n\t\treturn ret;\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 R86E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3915c2baf130067dbddef885ad9da5ac", "src_uid": "e2782743229645ad3a0f8e815d86dc5f", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic Scanner in; static int next() throws Exception {return in.nextInt();}\n\tstatic PrintWriter out;\n//\tstatic StreamTokenizer in;\n\n\tstatic int h;\n\tstatic int m;\n\tstatic int k;\n\n\tstatic long count(int hh, int mm) {\n\t\t\n\t\tlong answ = 0;\n\n\t\tString s = ((m - 1) + \"\");\n\t\tint cnt = 0;\n\t\tfor (char cc : s.toCharArray()) if (cc != '0') cnt++;\n\n if (k <= cnt) {\n \tansw += hh;\n } else {\n \tint h0 = hh;\n \tint kk = k - cnt;\n \tfor (int i = 0; i < kk - 1; i++) h0 /= 10;\n \tansw += h0;\n }\n\t\t\n\n\t\tint c = ((m - 1) + \"\").length();\n\n\t\tif (k <= c) {\n\t\t\tint m0 = m - 1;\n\n\t\t\tfor (int i = 0; i < k - 1; i++) m0 /= 10;\n\t\t\t\n\t\t\tfor (int i = 0; i < k - 1; i++) mm /= 10;\n\n\t\t\tansw += (long) m0 * hh + mm;\n\t\t}\n\n\t\treturn answ;\n\t}\n\n\t\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n//\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\t\n\t\th = next();\n\t\tm = next();\n\t\tk = next();\n\n\t\tint h1 = next();\n\t\tint m1 = next();\n\n\t\tint h2 = next();\n\t\tint m2 = next();\n\n//\t\tout.println(count(h2, m2));\n//\t\tout.println(count(h1, m1));\n\n\t\tlong answ = count(h2, m2) - count(h1, m1);\n\n\t\tif (h2 < h1 || (h2 == h1 && m2 < m1)) {\n\t\t\tansw += count(h - 1, m - 1);\n\t\t\tString s = (h - 1) + \"\" + (m - 1);\n\t\t\tint cnt = 0;\n\t\t\tfor (char cc : s.toCharArray()) if (cc != '0') cnt++;\n\t\t\tif (cnt >= k) answ++;\n\t\t}\n\n\t\tout.println(answ);\n\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1490be23eba93452d78bf133009585f8", "src_uid": "e2782743229645ad3a0f8e815d86dc5f", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "import java.util.ArrayList;\r\nimport java.util.Collections;\r\nimport java.util.HashMap;\r\nimport java.util.HashSet;\r\nimport java.util.PriorityQueue;\r\nimport java.util.StringTokenizer;\r\nimport java.io.*;\r\n \r\npublic class UpTheStrip {\r\n\t\r\n\tprivate static class MyScanner {\r\n\t BufferedReader br;\r\n\t StringTokenizer st;\r\n\r\n\t public MyScanner() {\r\n\t br = new BufferedReader(new InputStreamReader(System.in));\r\n\t }\r\n\r\n\t String next() {\r\n\t while (st == null || !st.hasMoreElements()) {\r\n\t try {\r\n\t st = new StringTokenizer(br.readLine());\r\n\t } catch (IOException e) {\r\n\t e.printStackTrace();\r\n\t }\r\n\t }\r\n\t return st.nextToken();\r\n\t }\r\n\r\n\t int nextInt() {\r\n\t return Integer.parseInt(next());\r\n\t }\r\n\r\n\t long nextLong() {\r\n\t return Long.parseLong(next());\r\n\t }\r\n\r\n\t double nextDouble() {\r\n\t return Double.parseDouble(next());\r\n\t }\r\n\r\n\t String nextLine(){\r\n\t String str = \"\";\r\n\t\t try {\r\n\t\t str = br.readLine();\r\n\t\t } catch (IOException e) {\r\n\t\t e.printStackTrace();\r\n\t\t }\r\n\t\t return str;\r\n\t }\r\n\r\n\t }\r\n\t\r\n\tpublic static long solution(long n, long m) {\r\n\r\n\t\tlong[] dp = new long[(int)n];\r\n\t\tlong[] sum = new long[(int)n];\r\n\t\tdp[0] = 1;\r\n\t\tsum[0] = 0;\r\n\t\tlong prev = 1;\r\n\t\t\r\n\t\tfor(int i = 2; i<=n; i++) {\r\n\t\t\t\r\n\t\t\tdp[i-1] = prev;\r\n\t\r\n\t\t\tsum[i-1] = (sum[i-1] + sum[i-2])%m;\r\n\t\t\tsum[i-1] = (sum[i-1] + dp[0])%m;\r\n\t\t\tdp[i-1] = (dp[i-1] + sum[i-1])%m;\r\n\t\t\t\r\n\t\t\tprev = (prev + dp[i-1])%m;\r\n\t\t\t\r\n int j = i+i;\r\n\t\t\t\r\n\t\t\twhile(j<=n)\r\n\t\t\t{\r\n\t\t\t\tsum[j-1] = (sum[j-1] + dp[i-1])%m;\r\n\t\t\t\tsum[j-1] = (sum[j-1] - dp[i-2] + m)%m;\t\r\n\t\t\t\tj+=i;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\treturn dp[(int)n-1];\r\n\t\t\t\r\n\t}\r\n\t\r\n \r\nprivate static PrintWriter out = new PrintWriter(System.out);\r\n\r\npublic static void main (String[] args)\r\n{\r\n\tMyScanner s = new MyScanner();\r\n \r\n long n = s.nextLong();\r\n long m = s.nextLong();\r\n out.println(solutionn(n,m)); \r\n\r\n out.flush();\r\n out.close();\r\n \r\n}\r\n}\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d24c8d0408bc174993f89467385bcc3e", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0} {"lang": "Java 8", "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 var n = sc.nextint();\r\n int mod = sc.nextint();\r\n long[] dp1 = new long[n + 9];\r\n long[] dp2 = new long[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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d244419369fe64e7ad145597f89200b", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.io.PrintWriter;\r\nimport java.util.Random;\r\nimport java.util.StringTokenizer;\r\nimport java.util.Collections;\r\nimport java.util.ArrayList;\r\nimport java.util.TreeSet;\r\n\r\n\r\npublic class C {\r\n\tstatic int mod;\r\n\tstatic ArrayList answers = new ArrayList<>();\r\n\tpublic static void main(String[] args) {\r\n\t\tFastScanner fs = new FastScanner();\r\n\t\tint n = fs.nextInt();\r\n\t\tmod = fs.nextInt();\r\n\t\tint[] dp = new int[n+1];\r\n\t\tint[] cs = new int[n+2];\r\n\t\tdp[n] = 1;\r\n\t\tcs[n] = 1;\r\n\t\tfor(int fill = n - 1; fill >= 0 ; fill--) {\r\n\t\t\tint ans = 0;\r\n\t\t\tans = sub(cs[fill] , cs[n+1]);\r\n\r\n\t\t\t//for(int i = fill+1 ; i <= n; i++) ans = add(ans, dp[i]);\r\n\t\t\tfor(int mul = 2; true ; mul++) {\r\n\t\t\t\tint lower = mul * fill;\r\n\t\t\t\tint higher = mul * fill + mul - 1;\r\n\t\t\t\tif(lower > n) break;\r\n\t\t\t\thigher = Math.min(higher , n);\r\n\t\t\t\t//for(int i = lower ; i <= higher ; i++) ans = add(ans, dp[i]);\r\n\t\t\t\tans = add(ans, sub(cs[lower] - cs[higher + 1]));\r\n\t\t\t}\r\n\t\t\tdp[fill] = ans;\r\n\t\t\tcs[fill] = add(cs[fill+1] , dp[fill]);\r\n\r\n\t\t}\r\n\t\tSystem.out.println(dp[1]);\r\n}\r\n\r\n\tstatic int add(int a, int b) {\r\n\t\ta+=b;\r\n\t\tif(a >= mod) return a - mod;\r\n\t\treturn a;\r\n\t}\r\n\r\n\tstatic int sub(int a , int b) {\r\n\t\ta -= b;\r\n\t\tif(a < 0) a += mod;\r\n\t\telse if(a >= mod) a -= mod; \r\n\t\treturn a;\r\n\r\n\t}\r\n\r\n\tstatic int indof(int x , int[] a) {\r\n\t\tfor(int i = 0; i < a.length; i++) if(a[i] == x) return i;\r\n\t\t\tthrow null;\r\n\t}\r\n\r\n\tstatic void swap(int prefixSize , int[] a) {\r\n\t\tprefixSize++;\r\n\t\tif(prefixSize%2 != 1) throw null;\r\n\t\tint[] newA = a.clone();\r\n\t\tfor(int i = 0; i < prefixSize; i++) {\r\n\t\t\ta[i] = newA[prefixSize - 1 - i];\r\n\t\t}\r\n\t\tanswers.add(prefixSize);\r\n\t}\r\n\r\n\tstatic void sort(int[] a) {\r\n\t\tArrayList l = new ArrayList<>();\r\n\t\tfor(int i : a) l.add(i);\r\n\t\tCollections.sort(l);\r\n\t\tfor(int i = 0; i < a.length; i++) a[i] = l.get(i);\r\n\t}\r\n\r\n\r\n\r\n\tstatic class FastScanner {\r\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n\t\tStringTokenizer st=new StringTokenizer(\"\");\r\n\t\tpublic String next() {\r\n\t\t\twhile (!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\treturn st.nextToken();\r\n\t\t}\r\n\t\t\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\t\t\r\n\t\tint[] readArray(int n) {\r\n\t\t\tint[] a=new int[n];\r\n\t\t\tfor (int i=0; i= mod) x -= mod;\r\n return x;\r\n }\r\n\r\n private int mult(int x, int y){\r\n long r = (x * (long) y);\r\n if(r >= mod)\r\n r %= mod;\r\n return (int) r;\r\n }\r\n }\r\n /* -------------------------------------- END --------------------------------------------- */\r\n \r\n /* Shuffle function to shuffle before Arrays.sort */\r\n static void shuffle(int[] arr){\r\n int swapTemp;\r\n for(int i = arr.length-1; i>= 1; i--){\r\n int pos = random.nextInt(i+1);\r\n if(pos == i) continue;\r\n {swapTemp = arr[i]; arr[i] = arr[pos]; arr[pos] = swapTemp;}\r\n }\r\n }\r\n \r\n /* Fast Input reader */\r\n static class FastScanner {\r\n BufferedReader reader;\r\n StreamTokenizer tokenizer;\r\n public FastScanner() {\r\n reader = new BufferedReader(new InputStreamReader(System.in));\r\n tokenizer = new StreamTokenizer(reader);\r\n tokenizer.resetSyntax();\r\n tokenizer.whitespaceChars(0, 32);\r\n tokenizer.wordChars(33, 126);\r\n }\r\n private void nextToken(){\r\n try{ tokenizer.nextToken(); }\r\n catch (Exception e) { e.printStackTrace(); }\r\n }\r\n String next() {\r\n nextToken();\r\n return tokenizer.sval;\r\n }\r\n int nextInt() {\r\n nextToken();\r\n return Integer.parseInt(tokenizer.sval);\r\n }\r\n long nextLong() {\r\n nextToken();\r\n return Long.parseLong(tokenizer.sval);\r\n }\r\n double nextDouble() {\r\n nextToken();\r\n return Double.parseDouble(tokenizer.sval);\r\n }\r\n String nextLine() {\r\n try{\r\n String string = reader.readLine();\r\n return string;\r\n } catch (Exception e) {\r\n e.printStackTrace();\r\n return \"\";\r\n }\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "91b0e8e7ddd1f2240938ae41f2d7e2f1", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf275E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tList[] g;\n\tlong outp;\n\n\tvoid dbg(Node[] a) {\n\t\tfor (Node v : a) {\n\t\t\tSystem.err.println(v.val + (v.l == null ? \"\" : \": l = \" + v.l.val)\n\t\t\t\t\t+ (v.r == null ? \"\" : \": r = \" + v.r.val)\n\t\t\t\t\t+ (!v.isRoot() || v.up == null ? \"\" : \": up = \" + v.up.val)\n\t\t\t\t\t+ \", here = \" + v.lcaHere + \", delta = \" + v.delta + \", sizeOther = \" + v.sizeNotLC);\n\t\t}\n\t\tSystem.err.println();\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\n\t\tg = new List[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tg[i] = new ArrayList<>();\n\t\t}\n\n\t\tint[] par = new int[n];\n\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tpar[i] = nextInt() - 1;\n\t\t}\n\n\t\tint[] vals = new int[n];\n\n\t\tNode[] a = new Node[n];\n\n\t\toutp = 0;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tvals[i] = nextInt();\n\t\t\ta[i] = new Node(vals[i]);\n\t\t\toutp += vals[i];\n\t\t}\n\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tNode v = a[par[i]];\n\t\t\tNode u = a[i];\n\t\t\tlink(v, u);\n\t\t}\n\t\tout.println(1.0 * outp / n / n);\n\n//\t\tdbg(a);\n\t\t\n\t\tint q = nextInt();\n\t\twhile (q-- > 0) {\n\t\t\tchar type = nextToken().charAt(0);\n\t\t\tint vId = nextInt() - 1;\n\t\t\tNode v = a[vId];\n\t\t\tif (type == 'P') {\n\t\t\t\tint uId = nextInt() - 1;\n\t\t\t\tNode u = a[uId];\n\t\t\t\tLinkCut.expose(u);\n\t\t\t\tLinkCut.splay(v);\n\t\t\t\tif (v.up == null) { // v is above u\n\t\t\t\t\tmakeParent(v, u);\n\t\t\t\t} else {\n\t\t\t\t\tmakeParent(u, v);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tint newVal = nextInt();\n\t\t\t\tLinkCut.splay(v);\n\t\t\t\toutp += (newVal - v.val)\n\t\t\t\t\t\t* (v.lcaHere + 2L * v.delta * v.sizeNotLC);\n\t\t\t\tv.val = newVal;\n\t\t\t\tv.update();\n\t\t\t}\n\t\t\tout.println(1.0 * outp / n / n);\n//\t\t\tdbg(a);\n\t\t}\n\t}\n\n\tvoid makeParent(Node v, Node u) { // make v parent of u\n\t\tLinkCut.expose(u);\n\t\tLinkCut.splay(u);\n\n\t\tNode t = u.l;\n\t\tif (t == null) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\n\t\tu.l = null;\n\t\tt.up = null;\n\t\tu.update();\n\t\toutp -= 2L * t.sum * u.size;\n\t\tt.applyDelta(-u.size);\n\n\t\tlink(v, u);\n\t}\n\n\tvoid link(Node v, Node u) {\n\t\tLinkCut.expose(v);\n\t\tLinkCut.splay(v);\n\t\tLinkCut.splay(u); // is root, so no need to expose\n\n\t\toutp += 2 * v.sum * u.size;\n\t\tv.applyDelta(u.size);\n\t\tv.sizeNotLC += u.size;\n\t\tu.up = v;\n\t\tv.update();\n\t}\n\n\tstatic class Node {\n\t\tNode l, r, up;\n\t\tint val, size, sizeNotLC;\n\t\tlong sum, lcaHere; // lcaHere without delta\n\n\t\tint delta;\n\n\t\tvoid update() {\n\t\t\tsum = getSum(l) + getSum(r) + 1L * sizeNotLC * val;\n\t\t\tsize = getSize(l) + getSize(r) + sizeNotLC;\n\t\t}\n\n\t\tvoid push() {\n\t\t\tif (l != null) {\n\t\t\t\tl.applyDelta(delta);\n\t\t\t}\n\t\t\tif (r != null) {\n\t\t\t\tr.applyDelta(delta);\n\t\t\t}\n\t\t\tdelta = 0;\n\t\t}\n\t\t\n\t\tvoid applyDelta(int delta) {\n\t\t\tlcaHere += 2L * delta * sizeNotLC;\n\t\t\tthis.delta += delta;\n\t\t}\n\n\t\tstatic long getSum(Node v) {\n\t\t\treturn v == null ? 0 : v.sum;\n\t\t}\n\n\t\tstatic int getSize(Node v) {\n\t\t\treturn v == null ? 0 : v.size;\n\t\t}\n\n\t\tboolean isRoot() {\n\t\t\treturn up == null || (up.l != this && up.r != this);\n\t\t}\n\n\t\tpublic Node(int val) {\n\t\t\tthis.val = val;\n\t\t\tsizeNotLC = 1;\n\t\t\tlcaHere = 1;\n\n\t\t\tupdate();\n\t\t}\n\n\t\tstatic private void relink(Node v, Node u) {\n\t\t\tNode t = u.up;\n\t\t\tif (v != null) {\n\t\t\t\tv.up = t;\n\t\t\t}\n\t\t\tif (t != null) {\n\t\t\t\tif (t.l == u) {\n\t\t\t\t\tt.l = v;\n\t\t\t\t} else if (t.r == u) {\n\t\t\t\t\tt.r = v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate void rotate() {\n\t\t\tNode u = up;\n\n\t\t\tif (u.l == this) {\n\t\t\t\trelink(r, this);\n\t\t\t\tr = u;\n\t\t\t} else {\n\t\t\t\trelink(l, this);\n\t\t\t\tl = u;\n\t\t\t}\n\n\t\t\trelink(this, u);\n\t\t\tu.up = this;\n\t\t\tu.update();\n\t\t}\n\n\t}\n\n\tstatic class LinkCut {\n\n\t\tpublic static void splay(Node v) {\n\t\t\tif (v.isRoot()) {\n\t\t\t\tv.push();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tNode u = v.up;\n\t\t\t\tNode t = u.up;\n\t\t\t\tboolean uRoot = u.isRoot();\n\t\t\t\tif (!uRoot) {\n\t\t\t\t\tt.push();\n\t\t\t\t}\n\t\t\t\tu.push();\n\t\t\t\tv.push();\n\t\t\t\tif (!uRoot) {\n\t\t\t\t\t((t.l == u) == (u.l == v) ? u : v).rotate();\n\t\t\t\t}\n\t\t\t\tv.rotate();\n\t\t\t} while (!v.isRoot());\n\t\t\tv.update();\n\t\t}\n\n\t\tpublic static void expose(Node v) {\n\t\t\t// TODO: return rest? might help to find lca and whatnot, see\n\t\t\t// http://codeforces.com/contest/482/submission/8750934\n\t\t\tfor (Node rest = null; v != null; rest = v, v = v.up) {\n\t\t\t\tsplay(v);\n\t\t\t\tif (v.r != null) {\n\t\t\t\t\tv.sizeNotLC += v.r.size;\n\t\t\t\t}\n\t\t\t\tif (rest != null) {\n\t\t\t\t\tv.sizeNotLC -= rest.size;\n\t\t\t\t}\n\t\t\t\tv.r = rest;\n\t\t\t\tv.update();\n\t\t\t}\n\t\t}\n\n\t}\n\n\tcf275E() 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 cf275E();\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\n/*\n\n5\n1 2 2 1\n1 2 3 4 5\n4\nP 3 4\nP 4 5\nP 5 2\nP 1 4\n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa4e4894aaf789d2455ce82341a0a2ab", "src_uid": "013df41c0042f752a995bdcf16b28c7e", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Locale;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static class Query {\n int kind;\n Vertex v;\n Vertex u;\n int t;\n }\n\n static class Vertex {\n long s;\n long subtreeSize;\n boolean hasInterestingInSubtree = false;\n long subtreeAnswer;\n long childSquareSum;\n Vertex parent;\n Vertex firstChild;\n Vertex nextSibling;\n Vertex interestingParent;\n Vertex firstInterestingChild;\n Vertex nextInterestingSibling;\n long multiplierForIntermediates;\n long constantForIntermediates;\n long intermediatesSize;\n long boringChildrenSize;\n long boringChildrenSquareSum;\n long boringChildrenAnswer;\n boolean interesting;\n\n void propagateInteresting() {\n Vertex v = firstChild;\n int numIntChild = 0;\n while (v != null) {\n v.propagateInteresting();\n if (v.hasInterestingInSubtree) ++numIntChild;\n v = v.nextSibling;\n }\n if (numIntChild >= 2) interesting = true;\n if (interesting || numIntChild >= 1) hasInterestingInSubtree = true;\n }\n\n void init() {\n subtreeSize = 1;\n subtreeAnswer = 0;\n childSquareSum = 0;\n boringChildrenSize = 0;\n boringChildrenAnswer = 0;\n boringChildrenSquareSum = 0;\n Vertex v = firstChild;\n while (v != null) {\n v.init();\n subtreeSize += v.subtreeSize;\n subtreeAnswer += v.subtreeAnswer;\n childSquareSum += v.subtreeSize * (long) v.subtreeSize;\n if (interesting && !v.hasInterestingInSubtree) {\n boringChildrenSize += v.subtreeSize;\n boringChildrenAnswer += v.subtreeAnswer;\n boringChildrenSquareSum += v.subtreeSize * (long) v.subtreeSize;\n }\n v = v.nextSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void interestingInit() {\n subtreeSize = 1 + boringChildrenSize;\n subtreeAnswer = boringChildrenAnswer;\n childSquareSum = boringChildrenSquareSum;\n Vertex v = firstInterestingChild;\n while (v != null) {\n v.interestingInit();\n long childSize = v.subtreeSize + v.intermediatesSize;\n subtreeSize += childSize;\n subtreeAnswer += v.subtreeAnswer;\n subtreeAnswer += v.multiplierForIntermediates * v.subtreeSize + v.constantForIntermediates;\n childSquareSum += childSize * (long) childSize;\n v = v.nextInterestingSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void initIntermediates() {\n Vertex tmp = this;\n intermediatesSize = 0;\n multiplierForIntermediates = 0;\n constantForIntermediates = 0;\n while (!tmp.parent.interesting) {\n long curExtra = tmp.parent.subtreeSize - tmp.subtreeSize;\n intermediatesSize += curExtra;\n multiplierForIntermediates += 2 * curExtra * (long) tmp.parent.s;\n constantForIntermediates += tmp.parent.subtreeAnswer - tmp.subtreeAnswer - 2 * subtreeSize * (long) (tmp.parent.subtreeSize - tmp.subtreeSize) * tmp.parent.s;\n tmp = tmp.parent;\n }\n interestingParent = tmp.parent;\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n /*char[] buf = new char[100000];\n int size;\n try {\n size = in.reader.read(buf);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n if (size == buf.length) throw new RuntimeException();\n String input = new String(buf, 0, size);\n StringWriter sw1 = new StringWriter();\n PrintWriter pw1 = new PrintWriter(sw1);\n doit(new InputReader(new StringInputStream(input)), pw1, 1);\n pw1.close();\n StringWriter sw2 = new StringWriter();\n PrintWriter pw2 = new PrintWriter(sw2);\n doit(new InputReader(new StringInputStream(input)), pw2, 500);\n pw2.close();\n String s1 = sw1.toString();\n String s2 = sw2.toString();\n if (!s1.equals(s2)) throw new RuntimeException();\n out.print(s1);*/\n doit(in, out, 250);\n }\n\n private void doit(InputReader in, PrintWriter out, int BUBEN) {\n Locale.setDefault(Locale.US);\n int n = in.nextInt();\n Vertex[] vs = new Vertex[n];\n for (int i = 0; i < n; ++i) vs[i] = new Vertex();\n for (int i = 1; i < n; ++i) {\n vs[i].parent = vs[in.nextInt() - 1];\n }\n for (int i = 0; i < n; ++i) {\n vs[i].s = in.nextInt();\n }\n Vertex root = vs[0];\n int numQueries = in.nextInt();\n Query[] queries = new Query[numQueries];\n for (int i = 0; i < numQueries; ++i) {\n Query query = new Query();\n String ss = in.next();\n if (ss.equals(\"P\")) query.kind = 1; else if (ss.equals(\"V\")) query.kind = 2; else throw new RuntimeException();\n if (query.kind == 1) {\n query.v = vs[in.nextInt() - 1];\n query.u = vs[in.nextInt() - 1];\n } else {\n query.v = vs[in.nextInt() - 1];\n query.t = in.nextInt();\n }\n queries[i] = query;\n }\n double mult = 1.0 / n / n;\n Vertex[] inters = new Vertex[n];\n for (int blockFirst = 0; blockFirst < numQueries; blockFirst += BUBEN) {\n int blockLast = Math.min(numQueries, blockFirst + BUBEN);\n for (Vertex vv : vs) {\n vv.interesting = false;\n vv.hasInterestingInSubtree = false;\n }\n root.interesting = true;\n for (int qid = blockFirst; qid < blockLast; ++qid) {\n Query query = queries[qid];\n if (query.kind == 1) {\n query.v.interesting = true;\n if (query.v.parent != null) query.v.parent.interesting = true;\n query.u.interesting = true;\n if (query.u.parent != null) query.u.parent.interesting = true;\n } else {\n query.v.interesting = true;\n }\n }\n for (Vertex vv : vs) {\n vv.firstChild = null;\n vv.nextSibling = null;\n }\n for (Vertex vv : vs) {\n if (vv.parent != null) {\n vv.nextSibling = vv.parent.firstChild;\n vv.parent.firstChild = vv;\n }\n }\n root.propagateInteresting();\n int ninters = 0;\n for (Vertex vv : vs) if (vv.interesting) {\n inters[ninters++] = vv;\n }\n root.init();\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n if (vv.parent != null) vv.initIntermediates();\n }\n if (blockFirst == 0) {\n out.println(String.format(\"%.12f\", root.subtreeAnswer * mult));\n }\n for (int qid = blockFirst; qid < blockLast; ++qid) {\n Query query = queries[qid];\n if (query.kind == 1) {\n Vertex tmp = query.u;\n while (tmp != null && tmp != query.v) tmp = tmp.interestingParent;\n if (tmp == null) {\n query.v.parent = query.u;\n query.v.interestingParent = query.u;\n } else {\n query.u.parent = query.v;\n query.u.interestingParent = query.v;\n }\n } else {\n query.v.s = query.t;\n }\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n vv.firstInterestingChild = null;\n vv.nextInterestingSibling = null;\n }\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n if (vv.interestingParent != null) {\n vv.nextInterestingSibling = vv.interestingParent.firstInterestingChild;\n vv.interestingParent.firstInterestingChild = vv;\n }\n }\n root.interestingInit();\n out.println(String.format(\"%.12f\", root.subtreeAnswer * mult));\n }\n }\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd0dfb92c71fe079bfb32db5086d4716", "src_uid": "013df41c0042f752a995bdcf16b28c7e", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Locale;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static class Query {\n int kind;\n Vertex v;\n Vertex u;\n int t;\n }\n\n static class Vertex {\n long s;\n long subtreeSize;\n boolean hasInterestingInSubtree = false;\n long subtreeAnswer;\n long childSquareSum;\n Vertex parent;\n Vertex firstChild;\n Vertex nextSibling;\n Vertex interestingParent;\n Vertex firstInterestingChild;\n Vertex nextInterestingSibling;\n long multiplierForIntermediates;\n long constantForIntermediates;\n long intermediatesSize;\n long boringChildrenSize;\n long boringChildrenSquareSum;\n long boringChildrenAnswer;\n boolean interesting;\n\n void propagateInteresting() {\n Vertex v = firstChild;\n int numIntChild = 0;\n while (v != null) {\n v.propagateInteresting();\n if (v.hasInterestingInSubtree) ++numIntChild;\n v = v.nextSibling;\n }\n if (numIntChild >= 2) interesting = true;\n if (interesting || numIntChild >= 1) hasInterestingInSubtree = true;\n }\n\n void init() {\n subtreeSize = 1;\n subtreeAnswer = 0;\n childSquareSum = 0;\n boringChildrenSize = 0;\n boringChildrenAnswer = 0;\n boringChildrenSquareSum = 0;\n Vertex v = firstChild;\n while (v != null) {\n v.init();\n subtreeSize += v.subtreeSize;\n subtreeAnswer += v.subtreeAnswer;\n childSquareSum += v.subtreeSize * (long) v.subtreeSize;\n if (interesting && !v.hasInterestingInSubtree) {\n boringChildrenSize += v.subtreeSize;\n boringChildrenAnswer += v.subtreeAnswer;\n boringChildrenSquareSum += v.subtreeSize * (long) v.subtreeSize;\n }\n v = v.nextSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void interestingInit() {\n subtreeSize = 1 + boringChildrenSize;\n subtreeAnswer = boringChildrenAnswer;\n childSquareSum = boringChildrenSquareSum;\n Vertex v = firstInterestingChild;\n while (v != null) {\n v.interestingInit();\n long childSize = v.subtreeSize + v.intermediatesSize;\n subtreeSize += childSize;\n subtreeAnswer += v.subtreeAnswer;\n subtreeAnswer += v.multiplierForIntermediates * v.subtreeSize + v.constantForIntermediates;\n childSquareSum += childSize * (long) childSize;\n v = v.nextInterestingSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void initIntermediates() {\n Vertex tmp = this;\n intermediatesSize = 0;\n multiplierForIntermediates = 0;\n constantForIntermediates = 0;\n while (!tmp.parent.interesting) {\n long curExtra = tmp.parent.subtreeSize - tmp.subtreeSize;\n intermediatesSize += curExtra;\n multiplierForIntermediates += 2 * curExtra * (long) tmp.parent.s;\n constantForIntermediates += tmp.parent.subtreeAnswer - tmp.subtreeAnswer - 2 * subtreeSize * (long) (tmp.parent.subtreeSize - tmp.subtreeSize) * tmp.parent.s;\n tmp = tmp.parent;\n }\n interestingParent = tmp.parent;\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n /*char[] buf = new char[100000];\n int size;\n try {\n size = in.reader.read(buf);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n if (size == buf.length) throw new RuntimeException();\n String input = new String(buf, 0, size);\n StringWriter sw1 = new StringWriter();\n PrintWriter pw1 = new PrintWriter(sw1);\n doit(new InputReader(new StringInputStream(input)), pw1, 1);\n pw1.close();\n StringWriter sw2 = new StringWriter();\n PrintWriter pw2 = new PrintWriter(sw2);\n doit(new InputReader(new StringInputStream(input)), pw2, 500);\n pw2.close();\n String s1 = sw1.toString();\n String s2 = sw2.toString();\n if (!s1.equals(s2)) throw new RuntimeException();\n out.print(s1);*/\n doit(in, out, 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d81de74afd6aacf53c019d9c5516709a", "src_uid": "013df41c0042f752a995bdcf16b28c7e", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Locale;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static class Query {\n int kind;\n Vertex v;\n Vertex u;\n int t;\n }\n\n static class Vertex {\n long s;\n long subtreeSize;\n boolean hasInterestingInSubtree = false;\n long subtreeAnswer;\n long childSquareSum;\n Vertex parent;\n Vertex firstChild;\n Vertex nextSibling;\n Vertex interestingParent;\n Vertex firstInterestingChild;\n Vertex nextInterestingSibling;\n long multiplierForIntermediates;\n long constantForIntermediates;\n long intermediatesSize;\n long boringChildrenSize;\n long boringChildrenSquareSum;\n long boringChildrenAnswer;\n boolean interesting;\n\n void propagateInteresting() {\n Vertex v = firstChild;\n int numIntChild = 0;\n while (v != null) {\n v.propagateInteresting();\n if (v.hasInterestingInSubtree) ++numIntChild;\n v = v.nextSibling;\n }\n if (numIntChild >= 2) interesting = true;\n if (interesting || numIntChild >= 1) hasInterestingInSubtree = true;\n }\n\n void init() {\n subtreeSize = 1;\n subtreeAnswer = 0;\n childSquareSum = 0;\n boringChildrenSize = 0;\n boringChildrenAnswer = 0;\n boringChildrenSquareSum = 0;\n Vertex v = firstChild;\n while (v != null) {\n v.init();\n subtreeSize += v.subtreeSize;\n subtreeAnswer += v.subtreeAnswer;\n childSquareSum += v.subtreeSize * (long) v.subtreeSize;\n if (interesting && !v.hasInterestingInSubtree) {\n boringChildrenSize += v.subtreeSize;\n boringChildrenAnswer += v.subtreeAnswer;\n boringChildrenSquareSum += v.subtreeSize * (long) v.subtreeSize;\n }\n v = v.nextSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void interestingInit() {\n subtreeSize = 1 + boringChildrenSize;\n subtreeAnswer = boringChildrenAnswer;\n childSquareSum = boringChildrenSquareSum;\n Vertex v = firstInterestingChild;\n while (v != null) {\n v.interestingInit();\n long childSize = v.subtreeSize + v.intermediatesSize;\n subtreeSize += childSize;\n subtreeAnswer += v.subtreeAnswer;\n subtreeAnswer += v.multiplierForIntermediates * v.subtreeSize + v.constantForIntermediates;\n childSquareSum += childSize * (long) childSize;\n v = v.nextInterestingSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void initIntermediates() {\n Vertex tmp = this;\n intermediatesSize = 0;\n multiplierForIntermediates = 0;\n constantForIntermediates = 0;\n while (!tmp.parent.interesting) {\n long curExtra = tmp.parent.subtreeSize - tmp.subtreeSize;\n intermediatesSize += curExtra;\n multiplierForIntermediates += 2 * curExtra * (long) tmp.parent.s;\n constantForIntermediates += tmp.parent.subtreeAnswer - tmp.subtreeAnswer - 2 * tmp.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 doit(in, out, 500);\n }\n\n private void doit(InputReader in, PrintWriter out, int BUBEN) {\n Locale.setDefault(Locale.US);\n int n = in.nextInt();\n Vertex[] vs = new Vertex[n];\n for (int i = 0; i < n; ++i) vs[i] = new Vertex();\n for (int i = 1; i < n; ++i) {\n vs[i].parent = vs[in.nextInt() - 1];\n }\n for (int i = 0; i < n; ++i) {\n vs[i].s = in.nextInt();\n }\n Vertex root = vs[0];\n int numQueries = in.nextInt();\n Query[] queries = new Query[numQueries];\n for (int i = 0; i < numQueries; ++i) {\n Query query = new Query();\n String ss = in.next();\n if (ss.equals(\"P\")) query.kind = 1; else if (ss.equals(\"V\")) query.kind = 2; else throw new RuntimeException();\n if (query.kind == 1) {\n query.v = vs[in.nextInt() - 1];\n query.u = vs[in.nextInt() - 1];\n } else {\n query.v = vs[in.nextInt() - 1];\n query.t = in.nextInt();\n }\n queries[i] = query;\n }\n double mult = 1.0 / n / n;\n Vertex[] inters = new Vertex[n];\n for (int blockFirst = 0; blockFirst < numQueries; blockFirst += BUBEN) {\n int blockLast = Math.min(numQueries, blockFirst + BUBEN);\n for (Vertex vv : vs) {\n vv.interesting = false;\n vv.hasInterestingInSubtree = false;\n }\n root.interesting = true;\n for (int qid = blockFirst; qid < blockLast; ++qid) {\n Query query = queries[qid];\n if (query.kind == 1) {\n query.v.interesting = true;\n if (query.v.parent != null) query.v.parent.interesting = true;\n query.u.interesting = true;\n if (query.u.parent != null) query.u.parent.interesting = true;\n } else {\n query.v.interesting = true;\n }\n }\n for (Vertex vv : vs) {\n vv.firstChild = null;\n vv.nextSibling = null;\n }\n for (Vertex vv : vs) {\n if (vv.parent != null) {\n vv.nextSibling = vv.parent.firstChild;\n vv.parent.firstChild = vv;\n }\n }\n root.propagateInteresting();\n int ninters = 0;\n for (Vertex vv : vs) if (vv.interesting) {\n inters[ninters++] = vv;\n }\n root.init();\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n if (vv.parent != null) vv.initIntermediates();\n }\n if (blockFirst == 0) {\n out.println(String.format(\"%.12f\", root.subtreeAnswer * mult));\n }\n for (int qid = blockFirst; qid < blockLast; ++qid) {\n Query query = queries[qid];\n if (query.kind == 1) {\n Vertex tmp = query.u;\n while (tmp != null && tmp != query.v) tmp = tmp.interestingParent;\n if (tmp == null) {\n query.v.parent = query.u;\n query.v.interestingParent = query.u;\n } else {\n query.u.parent = query.v;\n query.u.interestingParent = query.v;\n }\n } else {\n query.v.s = query.t;\n }\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n vv.firstInterestingChild = null;\n vv.nextInterestingSibling = null;\n }\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n if (vv.interestingParent != null) {\n vv.nextInterestingSibling = vv.interestingParent.firstInterestingChild;\n vv.interestingParent.firstInterestingChild = vv;\n }\n }\n root.interestingInit();\n out.println(String.format(\"%.12f\", root.subtreeAnswer * mult));\n }\n }\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "35d5a3328792131809addde97c0283cb", "src_uid": "013df41c0042f752a995bdcf16b28c7e", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.util.stream.LongStream;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.util.stream.Stream;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n GXMouseInTheCampus solver = new GXMouseInTheCampus();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GXMouseInTheCampus {\n LongHashMap mu = new LongHashMap(20000, false);\n LongHashMap euler = new LongHashMap(20000, 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 Map factors = new LongPollardRho().findAllFactors(m);\n primes = factors.keySet().stream().mapToLong(Long::longValue).toArray();\n LongCachedPow pow = new LongCachedPow(x, ILongModular.getInstance(m));\n LongList allFactorOfM = new LongList(20000);\n LongList tmpList = new LongList(20000);\n collect(allFactorOfM, m, 0);\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 = 0; j < tmpList.size(); 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 Factorization.factorizeNumber(euler, tmpList);\n long n = euler;\n for (int j = 0; j < tmpList.size(); j++) {\n long t = tmpList.get(j);\n if (pow.pow(t) % mg == 1) {\n n = Math.min(n, t);\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 void factorizeNumber(long x, LongList ans) {\n for (long i = 1; i * i <= x; i++) {\n if (x % i != 0) {\n continue;\n }\n ans.add(i);\n if (i * i != x) {\n ans.add(x / i);\n }\n }\n }\n\n }\n\n static class LongHashMap {\n private int[] slot;\n private int[] next;\n private long[] keys;\n private long[] values;\n private int alloc;\n private boolean[] removed;\n private int mask;\n private int size;\n private boolean rehash;\n\n public LongHashMap(int cap, boolean rehash) {\n this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;\n slot = new int[mask + 1];\n next = new int[cap + 1];\n keys = new long[cap + 1];\n values = new long[cap + 1];\n removed = new boolean[cap + 1];\n this.rehash = rehash;\n }\n\n private void doubleCapacity() {\n int newSize = Math.max(next.length + 10, next.length * 2);\n next = Arrays.copyOf(next, newSize);\n keys = Arrays.copyOf(keys, newSize);\n values = Arrays.copyOf(values, newSize);\n removed = Arrays.copyOf(removed, newSize);\n }\n\n public void alloc() {\n alloc++;\n if (alloc >= next.length) {\n doubleCapacity();\n }\n next[alloc] = 0;\n removed[alloc] = false;\n size++;\n }\n\n private void rehash() {\n int[] newSlots = new int[Math.max(16, slot.length * 2)];\n int newMask = newSlots.length - 1;\n for (int i = 0; i < slot.length; i++) {\n if (slot[i] == 0) {\n continue;\n }\n int head = slot[i];\n while (head != 0) {\n int n = next[head];\n int s = hash(keys[head]) & newMask;\n next[head] = newSlots[s];\n newSlots[s] = head;\n head = n;\n }\n }\n this.slot = newSlots;\n this.mask = newMask;\n }\n\n private int hash(long x) {\n int h = Long.hashCode(x);\n return h ^ (h >>> 16);\n }\n\n public void put(long x, long y) {\n put(x, y, true);\n }\n\n public void put(long x, long y, boolean cover) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n alloc();\n slot[s] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else {\n int index = findIndexOrLastEntry(s, x);\n if (keys[index] != x) {\n alloc();\n next[index] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else if (cover) {\n values[index] = y;\n }\n }\n if (rehash && size >= slot.length) {\n rehash();\n }\n }\n\n public long getOrDefault(long x, long def) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n return def;\n }\n int index = findIndexOrLastEntry(s, x);\n return keys[index] == x ? values[index] : def;\n }\n\n public long get(long x) {\n return getOrDefault(x, 0);\n }\n\n private int findIndexOrLastEntry(int s, long x) {\n int iter = slot[s];\n while (keys[iter] != x) {\n if (next[iter] != 0) {\n iter = next[iter];\n } else {\n return iter;\n }\n }\n return iter;\n }\n\n public LongEntryIterator iterator() {\n return new LongEntryIterator() {\n int index = 1;\n int readIndex = -1;\n\n\n public boolean hasNext() {\n while (index <= alloc && removed[index]) {\n index++;\n }\n return index <= alloc;\n }\n\n\n public long getEntryKey() {\n return keys[readIndex];\n }\n\n\n public long getEntryValue() {\n return values[readIndex];\n }\n\n\n public void next() {\n if (!hasNext()) {\n throw new IllegalStateException();\n }\n readIndex = index;\n index++;\n }\n };\n }\n\n public String toString() {\n LongEntryIterator iterator = iterator();\n StringBuilder builder = new StringBuilder(\"{\");\n while (iterator.hasNext()) {\n iterator.next();\n builder.append(iterator.getEntryKey()).append(\"->\").append(iterator.getEntryValue()).append(',');\n }\n if (builder.charAt(builder.length() - 1) == ',') {\n builder.setLength(builder.length() - 1);\n }\n builder.append('}');\n return builder.toString();\n }\n\n }\n\n static class LongPollardRho {\n LongMillerRabin mr = new LongMillerRabin();\n ILongModular modular;\n Random random = new Random();\n\n public long findFactor(long n) {\n if (mr.mr(n, 3)) {\n return n;\n }\n modular = ILongModular.getInstance(n);\n while (true) {\n long f = findFactor0((long) (random.nextDouble() * n), (long) (random.nextDouble() * n), n);\n if (f != -1) {\n return f;\n }\n }\n }\n\n private long findFactor0(long x, long c, long n) {\n long xi = x;\n long xj = x;\n int j = 2;\n int i = 1;\n while (i < n) {\n i++;\n xi = modular.plus(modular.mul(xi, xi), c);\n long g = GCDs.gcd(n, Math.abs(xi - xj));\n if (g != 1 && g != n) {\n return g;\n }\n if (i == j) {\n j = j << 1;\n xj = xi;\n }\n }\n return -1;\n }\n\n public Map findAllFactors(long n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, long n) {\n if (n == 1) {\n return;\n }\n long f = findFactor(n);\n if (f == n) {\n Long value = map.get(f);\n if (value == null) {\n value = 1L;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n }\n\n static class GCDs {\n private GCDs() {\n }\n\n public static long gcd(long a, long b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static long gcd0(long a, long b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n }\n\n static class LongCachedPow {\n private long[] first;\n private long[] second;\n private ILongModular mod;\n private ILongModular powMod;\n\n public LongCachedPow(long x, ILongModular mod) {\n this(x, mod.getMod(), mod);\n }\n\n public LongCachedPow(long x, long maxExp, ILongModular mod) {\n this.mod = mod;\n this.powMod = mod.getModularForPowerComputation();\n int k = Math.max(1, (int) DigitUtils.round(Math.sqrt(maxExp)));\n first = new long[k];\n second = new long[(int) (maxExp / k + 1)];\n first[0] = 1;\n for (int i = 1; i < k; i++) {\n first[i] = mod.mul(x, first[i - 1]);\n }\n second[0] = 1;\n long step = mod.mul(x, first[k - 1]);\n for (int i = 1; i < second.length; i++) {\n second[i] = mod.mul(second[i - 1], step);\n }\n }\n\n public long pow(long exp) {\n return mod.mul(first[(int) (exp % first.length)], second[(int) (exp / first.length)]);\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public long readLong() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n long val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class LongModular implements ILongModular {\n final long m;\n\n public long getMod() {\n return m;\n }\n\n public LongModular(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;\n }\n\n public long plus(long a, long b) {\n return valueOf(a + b);\n }\n\n public long valueOf(long a) {\n a %= m;\n if (a < 0) {\n a += m;\n }\n return a;\n }\n\n }\n\n static class LongMillerRabin {\n ILongModular modular;\n LongPower power;\n Random random = new Random();\n\n public boolean mr(long n, int s) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n modular = ILongModular.getInstance(n);\n power = new LongPower(modular);\n for (int i = 0; i < s; i++) {\n long x = (long) (random.nextDouble() * (n - 2) + 2);\n if (!mr0(x, n)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(long x, long n) {\n long exp = n - 1;\n while (true) {\n long y = power.pow(x, exp);\n if (y != 1 && y != n - 1) {\n return false;\n }\n if (y != 1 || exp % 2 == 1) {\n break;\n }\n exp = exp / 2;\n }\n return true;\n }\n\n }\n\n static class LongModularDanger implements ILongModular {\n final long m;\n\n public long getMod() {\n return m;\n }\n\n public LongModularDanger(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return DigitUtils.mulMod(a, b, m);\n }\n\n public long plus(long a, long b) {\n return valueOf(a + b);\n }\n\n public long valueOf(long a) {\n a %= m;\n if (a < 0) {\n a += m;\n }\n return a;\n }\n\n }\n\n static class LongList implements Cloneable {\n private int size;\n private int cap;\n private long[] data;\n private static final long[] EMPTY = new long[0];\n\n public LongList(int cap) {\n this.cap = cap;\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new long[cap];\n }\n }\n\n public LongList(LongList list) {\n this.size = list.size;\n this.cap = list.cap;\n this.data = Arrays.copyOf(list.data, size);\n }\n\n public LongList() {\n this(0);\n }\n\n public void ensureSpace(int req) {\n if (req > cap) {\n while (cap < req) {\n cap = Math.max(cap + 10, 2 * cap);\n }\n data = Arrays.copyOf(data, cap);\n }\n }\n\n private void checkRange(int i) {\n if (i < 0 || i >= size) {\n throw new ArrayIndexOutOfBoundsException();\n }\n }\n\n public long get(int i) {\n checkRange(i);\n return data[i];\n }\n\n public void add(long x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(long[] x, int offset, int len) {\n ensureSpace(size + len);\n System.arraycopy(x, offset, data, size, len);\n size += len;\n }\n\n public void addAll(LongList list) {\n addAll(list.data, 0, list.size);\n }\n\n public int size() {\n return size;\n }\n\n public long[] toArray() {\n return Arrays.copyOf(data, size);\n }\n\n public void clear() {\n size = 0;\n }\n\n public String toString() {\n return Arrays.toString(toArray());\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof LongList)) {\n return false;\n }\n LongList other = (LongList) obj;\n return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);\n }\n\n public int hashCode() {\n int h = 1;\n for (int i = 0; i < size; i++) {\n h = h * 31 + Long.hashCode(data[i]);\n }\n return h;\n }\n\n public LongList clone() {\n LongList ans = new LongList();\n ans.addAll(this);\n return ans;\n }\n\n }\n\n static interface LongEntryIterator {\n boolean hasNext();\n\n void next();\n\n long getEntryKey();\n\n long getEntryValue();\n\n }\n\n static 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 interface ILongModular {\n long getMod();\n\n long plus(long a, long b);\n\n long mul(long a, long b);\n\n default ILongModular getModularForPowerComputation() {\n return ILongModular.getInstance(getMod() - 1);\n }\n\n static ILongModular getInstance(long mod) {\n //return new LongModularDanger(mod);\n return mod <= (1L << 54) ? new LongModularDanger(mod) : new LongModular(mod);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d923a5d65a0ee47f48a2ff29abe2b2b", "src_uid": "c2dd6de750812d6213c770b3587d8fcb", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.util.stream.LongStream;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.util.stream.Stream;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n GXMouseInTheCampus solver = new GXMouseInTheCampus();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GXMouseInTheCampus {\n LongHashMap mu = new LongHashMap(100000, false);\n LongHashMap euler = new LongHashMap(100000, false);\n long[] primes;\n\n {\n mu.put(1, 1);\n euler.put(1, 1);\n }\n\n public long oneOfPrimeFactor(long x) {\n for (long p : primes) {\n if (x % p == 0) {\n return p;\n }\n }\n return x;\n }\n\n public void populate(long x) {\n long factor = oneOfPrimeFactor(x);\n long cnt = 0;\n long y = x;\n while (y % factor == 0) {\n cnt++;\n y /= factor;\n }\n if (cnt > 1) {\n mu.put(x, 0);\n } else {\n mu.put(x, -mu(y));\n }\n euler.put(x, euler(y) * (x / y - x / y / factor));\n }\n\n public long mu(long x) {\n long ans = mu.getOrDefault(x, -1);\n if (ans == -1) {\n populate(x);\n ans = mu.get(x);\n }\n return ans;\n }\n\n public long euler(long x) {\n long ans = euler.getOrDefault(x, -1);\n if (ans == -1) {\n populate(x);\n ans = euler.get(x);\n }\n return ans;\n }\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n long m = in.readLong();\n long x = in.readLong();\n\n primes = new LongPollardRho().findAllFactors(m).keySet()\n .stream().mapToLong(Long::longValue).toArray();\n LongList allFactorOfM = new LongList(20000);\n LongList tmpList = new LongList(20000);\n LongList allPossiblePrimeFactor = new LongList();\n for (long p : primes) {\n allPossiblePrimeFactor.add(p);\n allPossiblePrimeFactor.addAll(Factorization.factorizeNumberPrime(p - 1));\n }\n allPossiblePrimeFactor.unique();\n\n collect(allFactorOfM, m, 0);\n LongPower power = new LongPower(ILongModular.getInstance(m));\n\n long total = 1;\n for (int i = 0; i < allFactorOfM.size(); i++) {\n long g = allFactorOfM.get(i);\n if (g == m) {\n continue;\n }\n long mg = m / g;\n tmpList.clear();\n collect(tmpList, mg, 0);\n long cnt = 0;\n for (int j = tmpList.size() - 1; j >= 0; j--) {\n long t = tmpList.get(j);\n cnt += mu(t) * ((m - 1) / (t * g));\n }\n\n tmpList.clear();\n long euler = euler(mg);\n LongList primeFactors = tmpList;\n for (int j = 0; j < allPossiblePrimeFactor.size(); j++) {\n long p = allPossiblePrimeFactor.get(j);\n if (euler % p == 0) {\n primeFactors.add(p);\n }\n }\n\n long n = euler;\n for (int j = 0; j < primeFactors.size(); j++) {\n long p = primeFactors.get(j);\n while (n % p == 0 && power.pow(x, n / p) % mg == 1) {\n n /= p;\n }\n }\n\n if (cnt % n != 0) {\n throw new IllegalStateException();\n }\n total += cnt / n;\n }\n\n out.println(total);\n }\n\n public void collect(LongList list, long x, int i) {\n if (i == primes.length) {\n list.add(x);\n return;\n }\n collect(list, x, i + 1);\n while (x % primes[i] == 0) {\n x /= primes[i];\n collect(list, x, i + 1);\n }\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static long round(double x) {\n if (x >= 0) {\n return (long) (x + 0.5);\n } else {\n return (long) (x - 0.5);\n }\n }\n\n public static long mod(long x, long mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n public static long mulMod(long a, long b, long mod) {\n long k = DigitUtils.round((double) a / mod * b);\n return DigitUtils.mod(a * b - k * mod, mod);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(long c) {\n cache.append(c);\n println();\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class LongPower {\n final ILongModular modular;\n\n public LongPower(ILongModular modular) {\n this.modular = modular;\n }\n\n public long pow(long x, long n) {\n if (n == 0) {\n return 1;\n }\n long r = pow(x, n >> 1);\n r = modular.mul(r, r);\n if ((n & 1) == 1) {\n r = modular.mul(r, x);\n }\n return r;\n }\n\n }\n\n static class Factorization {\n public static LongList factorizeNumberPrime(long x) {\n LongList ans = new LongList();\n for (long i = 2; i * i <= x; i++) {\n if (x % i != 0) {\n continue;\n }\n ans.add(i);\n while (x % i == 0) {\n x /= i;\n }\n }\n if (x > 1) {\n ans.add(x);\n }\n return ans;\n }\n\n }\n\n static class LongHashMap {\n private int[] slot;\n private int[] next;\n private long[] keys;\n private long[] values;\n private int alloc;\n private boolean[] removed;\n private int mask;\n private int size;\n private boolean rehash;\n\n public LongHashMap(int cap, boolean rehash) {\n this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;\n slot = new int[mask + 1];\n next = new int[cap + 1];\n keys = new long[cap + 1];\n values = new long[cap + 1];\n removed = new boolean[cap + 1];\n this.rehash = rehash;\n }\n\n private void doubleCapacity() {\n int newSize = Math.max(next.length + 10, next.length * 2);\n next = Arrays.copyOf(next, newSize);\n keys = Arrays.copyOf(keys, newSize);\n values = Arrays.copyOf(values, newSize);\n removed = Arrays.copyOf(removed, newSize);\n }\n\n public void alloc() {\n alloc++;\n if (alloc >= next.length) {\n doubleCapacity();\n }\n next[alloc] = 0;\n removed[alloc] = false;\n size++;\n }\n\n private void rehash() {\n int[] newSlots = new int[Math.max(16, slot.length * 2)];\n int newMask = newSlots.length - 1;\n for (int i = 0; i < slot.length; i++) {\n if (slot[i] == 0) {\n continue;\n }\n int head = slot[i];\n while (head != 0) {\n int n = next[head];\n int s = hash(keys[head]) & newMask;\n next[head] = newSlots[s];\n newSlots[s] = head;\n head = n;\n }\n }\n this.slot = newSlots;\n this.mask = newMask;\n }\n\n private int hash(long x) {\n int h = Long.hashCode(x);\n return h ^ (h >>> 16);\n }\n\n public void put(long x, long y) {\n put(x, y, true);\n }\n\n public void put(long x, long y, boolean cover) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n alloc();\n slot[s] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else {\n int index = findIndexOrLastEntry(s, x);\n if (keys[index] != x) {\n alloc();\n next[index] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else if (cover) {\n values[index] = y;\n }\n }\n if (rehash && size >= slot.length) {\n rehash();\n }\n }\n\n public long getOrDefault(long x, long def) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n return def;\n }\n int index = findIndexOrLastEntry(s, x);\n return keys[index] == x ? values[index] : def;\n }\n\n public long get(long x) {\n return getOrDefault(x, 0);\n }\n\n private int findIndexOrLastEntry(int s, long x) {\n int iter = slot[s];\n while (keys[iter] != x) {\n if (next[iter] != 0) {\n iter = next[iter];\n } else {\n return iter;\n }\n }\n return iter;\n }\n\n public LongEntryIterator iterator() {\n return new LongEntryIterator() {\n int index = 1;\n int readIndex = -1;\n\n\n public boolean hasNext() {\n while (index <= alloc && removed[index]) {\n index++;\n }\n return index <= alloc;\n }\n\n\n public long getEntryKey() {\n return keys[readIndex];\n }\n\n\n public long getEntryValue() {\n return values[readIndex];\n }\n\n\n public void next() {\n if (!hasNext()) {\n throw new IllegalStateException();\n }\n readIndex = index;\n index++;\n }\n };\n }\n\n public String toString() {\n LongEntryIterator iterator = iterator();\n StringBuilder builder = new StringBuilder(\"{\");\n while (iterator.hasNext()) {\n iterator.next();\n builder.append(iterator.getEntryKey()).append(\"->\").append(iterator.getEntryValue()).append(',');\n }\n if (builder.charAt(builder.length() - 1) == ',') {\n builder.setLength(builder.length() - 1);\n }\n builder.append('}');\n return builder.toString();\n }\n\n }\n\n static class LongPollardRho {\n LongMillerRabin mr = new LongMillerRabin();\n ILongModular modular;\n Random random = new Random();\n\n public long findFactor(long n) {\n if (mr.mr(n, 3)) {\n return n;\n }\n modular = ILongModular.getInstance(n);\n while (true) {\n long f = findFactor0((long) (random.nextDouble() * n), (long) (random.nextDouble() * n), n);\n if (f != -1) {\n return f;\n }\n }\n }\n\n private long findFactor0(long x, long c, long n) {\n long xi = x;\n long xj = x;\n int j = 2;\n int i = 1;\n while (i < n) {\n i++;\n xi = modular.plus(modular.mul(xi, xi), c);\n long g = GCDs.gcd(n, Math.abs(xi - xj));\n if (g != 1 && g != n) {\n return g;\n }\n if (i == j) {\n j = j << 1;\n xj = xi;\n }\n }\n return -1;\n }\n\n public Map findAllFactors(long n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, long n) {\n if (n == 1) {\n return;\n }\n long f = findFactor(n);\n if (f == n) {\n Long value = map.get(f);\n if (value == null) {\n value = 1L;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n }\n\n static class GCDs {\n private GCDs() {\n }\n\n public static long gcd(long a, long b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static long gcd0(long a, long b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public long readLong() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n long val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static interface LongEntryIterator {\n boolean hasNext();\n\n void next();\n\n long getEntryKey();\n\n long getEntryValue();\n\n }\n\n static class LongModular implements ILongModular {\n final long m;\n\n public LongModular(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;\n }\n\n public long plus(long a, long b) {\n return valueOf(a + b);\n }\n\n public long valueOf(long a) {\n a %= m;\n if (a < 0) {\n a += m;\n }\n return a;\n }\n\n }\n\n static class LongMillerRabin {\n ILongModular modular;\n LongPower power;\n Random random = new Random();\n\n public boolean mr(long n, int s) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n modular = ILongModular.getInstance(n);\n power = new LongPower(modular);\n for (int i = 0; i < s; i++) {\n long x = (long) (random.nextDouble() * (n - 2) + 2);\n if (!mr0(x, n)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(long x, long n) {\n long exp = n - 1;\n while (true) {\n long y = power.pow(x, exp);\n if (y != 1 && y != n - 1) {\n return false;\n }\n if (y != 1 || exp % 2 == 1) {\n break;\n }\n exp = exp / 2;\n }\n return true;\n }\n\n }\n\n static class LongModularDanger implements ILongModular {\n final long m;\n\n public LongModularDanger(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return DigitUtils.mulMod(a, b, m);\n }\n\n public long plus(long a, long b) {\n return valueOf(a + b);\n }\n\n public long valueOf(long a) {\n a %= m;\n if (a < 0) {\n a += m;\n }\n return a;\n }\n\n }\n\n static class LongList implements Cloneable {\n private int size;\n private int cap;\n private long[] data;\n private static final long[] EMPTY = new long[0];\n\n public LongList(int cap) {\n this.cap = cap;\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new long[cap];\n }\n }\n\n public LongList(LongList list) {\n this.size = list.size;\n this.cap = list.cap;\n this.data = Arrays.copyOf(list.data, size);\n }\n\n public LongList() {\n this(0);\n }\n\n public void ensureSpace(int req) {\n if (req > cap) {\n while (cap < req) {\n cap = Math.max(cap + 10, 2 * cap);\n }\n data = Arrays.copyOf(data, cap);\n }\n }\n\n private void checkRange(int i) {\n if (i < 0 || i >= size) {\n throw new ArrayIndexOutOfBoundsException();\n }\n }\n\n public long get(int i) {\n checkRange(i);\n return data[i];\n }\n\n public void add(long x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(long[] x, int offset, int len) {\n ensureSpace(size + len);\n System.arraycopy(x, offset, data, size, len);\n size += len;\n }\n\n public void addAll(LongList list) {\n addAll(list.data, 0, list.size);\n }\n\n public void sort() {\n if (size <= 1) {\n return;\n }\n Randomized.shuffle(data, 0, size);\n Arrays.sort(data, 0, size);\n }\n\n public void unique() {\n if (size <= 1) {\n return;\n }\n\n sort();\n int wpos = 1;\n for (int i = 1; i < size; i++) {\n if (data[i] != data[wpos - 1]) {\n data[wpos++] = data[i];\n }\n }\n size = wpos;\n }\n\n public int size() {\n return size;\n }\n\n public long[] toArray() {\n return Arrays.copyOf(data, size);\n }\n\n public void clear() {\n size = 0;\n }\n\n public String toString() {\n return Arrays.toString(toArray());\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof LongList)) {\n return false;\n }\n LongList other = (LongList) obj;\n return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);\n }\n\n public int hashCode() {\n int h = 1;\n for (int i = 0; i < size; i++) {\n h = h * 31 + Long.hashCode(data[i]);\n }\n return h;\n }\n\n public LongList clone() {\n LongList ans = new LongList();\n ans.addAll(this);\n return ans;\n }\n\n }\n\n static class SequenceUtils {\n public static boolean equal(long[] a, int al, int ar, long[] b, int bl, int br) {\n if ((ar - al) != (br - bl)) {\n return false;\n }\n for (int i = al, j = bl; i <= ar; i++, j++) {\n if (a[i] != b[j]) {\n return false;\n }\n }\n return true;\n }\n\n }\n\n static class Randomized {\n private static Random random = new Random(0);\n\n public static void shuffle(long[] data, int from, int to) {\n to--;\n for (int i = from; i <= to; i++) {\n int s = nextInt(i, to);\n long tmp = data[i];\n data[i] = data[s];\n data[s] = tmp;\n }\n }\n\n public static int nextInt(int l, int r) {\n return random.nextInt(r - l + 1) + l;\n }\n\n }\n\n static interface ILongModular {\n long plus(long a, long b);\n\n long mul(long a, long b);\n\n static ILongModular getInstance(long mod) {\n //return new LongModularDanger(mod);\n return mod <= (1L << 54) ? new LongModularDanger(mod) : new LongModular(mod);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "93c9a5e928a215b61a65e4e9b4c409a2", "src_uid": "c2dd6de750812d6213c770b3587d8fcb", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "27c822a35bc0ed4bcbbac83ff13f012c", "src_uid": "c2dd6de750812d6213c770b3587d8fcb", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "//package educational.round049;\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 G2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t// 11 2 3 3 3 2 2 3\n\t\n\tvoid solve()\n\t{\n\t\tlong m = nl(), x = nl();\n\t\tint[] primes = sieveEratosthenes(10000000);\n\t\tlong[] ds = enumDivisors(m, primes);\n\t\tArrays.sort(ds);\n\t\tlong[] gf = factor(m, primes);\n\t\t\n\t\tlong ans = 0;\n\t\tfor(long d : ds){\n\t\t\tlong t = totient(d, gf);\n\t\t\tlong[] f = factor(t, primes);\n\t\t\tlong P = period(x%d, d, f, t);\n\t\t\tassert t % P == 0;\n\t\t\tans += t / P;\n//\t\t\ttr(d, t, period(x%d, d, f, t));\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tlong period(long x, long d, long[] f, long t)\n\t{\n\t\tif(d > 1e9){\n\t\t\t// x^k=1 (mod d)\n\t\t\tassert powSafe(x, t, d) == 1%d;\n\t\t\tfor(long e : f){\n\t\t\t\twhile(t % e == 0 && powSafe(x, t/e, d) == 1%d){\n\t\t\t\t\tt /= e;\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\tassert pow(x, t, d) == 1%d;\n\t\t\tfor(long e : f){\n\t\t\t\twhile(t % e == 0 && pow(x, t/e, d) == 1%d){\n\t\t\t\t\tt /= e;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 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 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 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\t\n\n\t\n\tpublic static long totient(long n, long[] primes)\n\t{\n\t\tlong ret = n;\n\t\tfor(long p : primes){\n\t\t\tif((long)p * p > n)break;\n\t\t\tif(n % p == 0){\n\t\t\t\tret /= p;\n\t\t\t\tret *= p - 1;\n\t\t\t}\n\t\t\twhile(n % p == 0)n /= p;\n\t\t}\n\t\tif(n != 1){\n\t\t\tret /= n;\n\t\t\tret *= n - 1;\n\t\t}\n\t\treturn ret;\n\t}\n\n\t\n\tpublic static long[] factor(long n, int[] primes)\n\t{\n\t\tlong[] ret = new long[20];\n\t\tint rp = 0;\n\t\tfor(int p : primes){\n\t\t\tif((long)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] = p;\n\t\t\t\trp++;\n\t\t\t}\n\t\t}\n\t\tif(n != 1){\n\t\t\tret[rp] = n;\n\t\t\trp++;\n\t\t}\n\t\treturn Arrays.copyOf(ret, rp);\n\t}\n\n\t\n\tpublic static long[] enumDivisors(long n, int[] primes)\n\t{\n\t\tint m = 1;\n\t\tlong[] divs = {1L};\n\t\tint t = 1;\n\t\tlong u = n;\n\t\tfor(int p : primes){\n\t\t\tif((long)p*p > u)break;\n\t\t\tint e = 0;\n\t\t\twhile(u % p == 0){\n\t\t\t\tu /= p;\n\t\t\t\te++;\n\t\t\t}\n\t\t\tif(e > 0){\n\t\t\t\tdivs = Arrays.copyOf(divs, t*(e+1));\n\t\t\t\tfor(int q = t-1;q >= 0;q--){\n\t\t\t\t\tlong b = divs[q];\n\t\t\t\t\tfor(int k = 0;k < e;k++){\n\t\t\t\t\t\tb *= p;\n//\t\t\t\t\t\tif((long)b*b <= n)divs[t++] = b;\n\t\t\t\t\t\tdivs[t++] = b;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tm *= e+1;\n\t\t\t}\n\t\t}\n\t\tif(u > 1){\n\t\t\tlong p = u;\n\t\t\tint e = 1;\n\t\t\tdivs = Arrays.copyOf(divs, t*(e+1));\n\t\t\tfor(int q = t-1;q >= 0;q--){\n\t\t\t\tlong b = divs[q];\n\t\t\t\tfor(int k = 0;k < e;k++){\n\t\t\t\t\tb *= p;\n//\t\t\t\t\tif((long)b*b <= n)divs[t++] = b;\n\t\t\t\t\tdivs[t++] = b;\n\t\t\t\t}\n\t\t\t}\n\t\t\tm *= e+1;\n\t\t}\n\t\t\n\t\treturn Arrays.copyOf(divs, t);\n\t}\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 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\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 G2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29533324a8eff29ccf0d2975473018b6", "src_uid": "c2dd6de750812d6213c770b3587d8fcb", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.*;\n\npublic class g {\n public static void main(String[] args) throws Throwable {\n String[] r = new BufferedReader(new InputStreamReader(System.in))\n .readLine().split(\" \");\n int a = Integer.parseInt(r[0]);\n int b = Integer.parseInt(r[1]);\n int t = Integer.parseInt(r[2]);\n while (t --> 0) {\n int x = b + a;\n a = b;\n b = x;\n }\n System.out.println(a);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "56bbbc2690c21db1041689c760badb5d", "src_uid": "6ff30f5a9afc3f7befca813469188aab", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\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 class GraphBuilder {\n int n, m;\n int[] x, y;\n int index;\n int[] size;\n\n\n GraphBuilder(int n, int m) {\n this.n = n;\n this.m = m;\n x = new int[m];\n y = new int[m];\n size = new int[n];\n }\n\n void add(int u, int v) {\n x[index] = u;\n y[index] = v;\n size[u]++;\n size[v]++;\n index++;\n }\n\n int[][] build() {\n int[][] graph = new int[n][];\n for (int i = 0; i < n; i++) {\n graph[i] = new int[size[i]];\n }\n for (int i = index - 1; i >= 0; i--) {\n int u = x[i];\n int v = y[i];\n graph[u][--size[u]] = v;\n graph[v][--size[v]] = u;\n }\n return graph;\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[] readLongArray(int size) throws IOException {\n long[] res = new long[size];\n for (int i = 0; i < size; i++) {\n res[i] = readLong();\n }\n return res;\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n List[] createGraphList(int size) {\n List[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new Template().run();\n // new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n time();\n memory();\n }\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n void solve() throws IOException {\n long x = readLong();\n long y = readLong();\n int it = readInt();\n while (it --> 0) {\n long z = x + y;\n x = y;\n y = z;\n }\n out.println(x);\n\n\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3424f5a1098a8b2f0923337cf01e4958", "src_uid": "6ff30f5a9afc3f7befca813469188aab", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class p171g\n{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n System.out.println();\n long a1 = sc.nextLong();\n long a2 = sc.nextLong();\n long a3 = sc.nextLong();\n long k = 1L;\n long n;\n while(k 0) {\n digits[sz++] = a % 10;\n a /= 10;\n }\n\n int res = 0;\n\n for (int i = 0; i < sz; ++i) {\n res = res * 10 + digits[i];\n }\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 long nextLong() {\n return Long.parseLong(next());\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\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5f76799583a94b1ec8daafbb293c18b7", "src_uid": "6ff30f5a9afc3f7befca813469188aab", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.Arrays;\n\n/**\n * Created by dalt on 2018/3/14.\n */\npublic class CF939F {\n public static final int INF = (int) 1e8;\n public static BlockReader input;\n public static PrintStream output;\n\n public static void main(String[] args) throws FileNotFoundException {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n input = new BlockReader(new FileInputStream(\"D:\\\\DataBase\\\\TESTCASE\\\\codeforces\\\\CF939F.in\"));\n output = System.out;\n } else {\n input = new BlockReader(System.in);\n output = new PrintStream(new BufferedOutputStream(System.out), false);\n }\n\n solve();\n\n output.flush();\n }\n\n public static void solve() {\n int n = input.nextInteger();\n int k = input.nextInteger();\n\n int[][] intervals = new int[k + 2][2];\n for (int i = 1; i <= k; i++) {\n intervals[i][0] = input.nextInteger();\n intervals[i][1] = input.nextInteger();\n }\n intervals[k + 1][0] = 2 * n;\n intervals[k + 1][1] = 2 * n;\n\n k++;\n\n Node[] loop = new Node[2];\n loop[0] = Node.build(0, n);\n loop[1] = Node.build(0, n);\n\n int[] data = new int[n + 1];\n\n for (int i = 1; i <= k; i++) {\n Node curDp = loop[i & 1];\n\n Node lastDp = loop[(i - 1) & 1];\n\n\n int[] interval = intervals[i];\n int intervalLength = interval[1] - interval[0];\n int middleLength = interval[0] - intervals[i - 1][1];\n\n Node.toArray(0, n, data, lastDp);\n System.arraycopy(data, 0, data, Math.min(data.length, intervalLength + middleLength), Math.max(0, n + 1 - (intervalLength + middleLength)));\n Arrays.fill(data, 0, Math.min(data.length, intervalLength + middleLength), INF);\n\n //No flip\n/* for (int j = intervalLength + middleLength; j <= n; j++) {\n int lastFryTotalTime = j - intervalLength - middleLength;\n int minNeedTime = Node.query(lastFryTotalTime, lastFryTotalTime, 0, n, lastDp);\n Node.update(j, 0, n, minNeedTime, curDp);\n }*/\n\n\n int minX = interval[1] - middleLength - intervalLength;\n int maxX = interval[1] - middleLength;\n for (int j = 0; j <= n; j++) {\n //Flip once\n int minNeedTime = Node.query(minX - j, maxX - j, 0, n, lastDp);\n data[j] = Math.min(data[j], minNeedTime + 1);\n // Node.update(j, 0, n, minNeedTime + 1, curDp);\n }\n\n for (int j = 0; j <= n; j++) {\n //Flip twice\n int minNeedTime = Node.query(j - middleLength - intervalLength, j - middleLength, 0, n, lastDp);\n //Node.update(j, 0, n, minNeedTime + 2, curDp);\n data[j] = Math.min(data[j], minNeedTime + 2);\n }\n\n Node.fromArray(0, n, data, curDp);\n }\n\n int minFlipTime = Node.query(n, n, 0, n, loop[k & 1]);\n\n if (minFlipTime < INF) {\n output.println(\"Full\");\n output.println(minFlipTime);\n } else {\n output.println(\"Hungry\");\n }\n }\n\n\n public static class Node {\n Node left;\n Node right;\n int batchSetValue;\n boolean dirty;\n int min;\n\n public static void setValue(int f, int t, int l, int r, int val, Node node) {\n if (f > r || t < l) {\n return;\n }\n if (f <= l && t >= r) {\n node.setValue(val);\n return;\n }\n\n node.pushDown();\n int m = (l + r) >> 1;\n setValue(f, t, l, m, val, node.left);\n setValue(f, t, m + 1, r, val, node.right);\n\n node.pushUp();\n }\n\n public static Node build(int l, int r) {\n Node node = new Node();\n if (l != r) {\n int m = (l + r) >> 1;\n node.left = build(l, m);\n node.right = build(m + 1, r);\n }\n return node;\n }\n\n public static int query(int f, int t, int l, int r, Node node) {\n if (f > r || t < l) {\n return INF;\n }\n if (f <= l && r <= t) {\n return node.min;\n }\n node.pushDown();\n int m = (l + r) >> 1;\n return Math.min(query(f, t, l, m, node.left), query(f, t, m + 1, r, node.right));\n }\n\n public static void update(int i, int l, int r, int val, Node node) {\n if (i > r || i < l) {\n return;\n }\n if (i <= l && i >= r) {\n node.min = Math.min(node.min, val);\n return;\n }\n\n node.pushDown();\n int m = (l + r) >> 1;\n update(i, l, m, val, node.left);\n update(i, m + 1, r, val, node.right);\n\n node.pushUp();\n }\n\n public static void toArray(int l, int r, int[] data, Node node) {\n if (l == r) {\n data[l] = node.min;\n return;\n }\n node.pushDown();\n int m = (l + r) >> 1;\n toArray(l, m, data, node.left);\n toArray(m + 1, r, data, node.right);\n }\n\n public static void fromArray(int l, int r, int[] data, Node node) {\n if (l == r) {\n node.min = data[l];\n return;\n }\n\n node.dirty = false;\n int m = (l + r) >> 1;\n fromArray(l, m, data, node.left);\n fromArray(m + 1, r, data, node.right);\n node.pushUp();\n }\n\n public void pushUp() {\n this.min = Math.min(left.min, right.min);\n }\n\n public void setValue(int val) {\n this.min = val;\n this.batchSetValue = val;\n this.dirty = true;\n }\n\n public void pushDown() {\n if (dirty) {\n left.setValue(batchSetValue);\n right.setValue(batchSetValue);\n dirty = false;\n }\n }\n\n @Override\n public String toString() {\n int t = 100;\n int[] data = new int[t + 1];\n for (int i = 0; i <= t; i++) {\n data[i] = query(i, i, 0, t, this);\n }\n return Arrays.toString(data);\n }\n }\n\n public static class BlockReader {\n static final int EOF = -1;\n InputStream is;\n byte[] dBuf;\n int dPos, dSize, next;\n StringBuilder builder = new StringBuilder();\n\n public BlockReader(InputStream is) {\n this(is, 4096);\n }\n\n public BlockReader(InputStream is, int bufSize) {\n this.is = is;\n dBuf = new byte[bufSize];\n next = nextByte();\n }\n\n public int nextByte() {\n while (dPos >= dSize) {\n if (dSize == -1) {\n return EOF;\n }\n dPos = 0;\n try {\n dSize = is.read(dBuf);\n } catch (Exception e) {\n }\n }\n return dBuf[dPos++];\n }\n\n public String nextBlock() {\n builder.setLength(0);\n skipBlank();\n while (next != EOF && !Character.isWhitespace(next)) {\n builder.append((char) next);\n next = nextByte();\n }\n return builder.toString();\n }\n\n public void skipBlank() {\n while (Character.isWhitespace(next)) {\n next = nextByte();\n }\n }\n\n public int nextInteger() {\n skipBlank();\n int ret = 0;\n boolean rev = false;\n if (next == '+' || next == '-') {\n rev = next == '-';\n next = nextByte();\n }\n while (next >= '0' && next <= '9') {\n ret = (ret << 3) + (ret << 1) + next - '0';\n next = nextByte();\n }\n return rev ? -ret : ret;\n }\n\n public int nextBlock(char[] data, int offset) {\n skipBlank();\n int index = offset;\n int bound = data.length;\n while (next != EOF && index < bound && !Character.isWhitespace(next)) {\n data[index++] = (char) next;\n next = nextByte();\n }\n return index - offset;\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != EOF;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a66488074a8b8b82fe1c5997e0227678", "src_uid": "2e0d1b1f1a7b8df2d2598c3cb2c869d5", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class CF939_D2_F {\n\tpublic static void main(String[] args)throws Throwable {\n\t\tMyScanner sc=new MyScanner();\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\t\n\t\tint n=sc.nextInt()*2;\n\t\tint k=sc.nextInt();\n\t\tint [] l=new int [k+1];\n\t\tint [] r=new int [k+1];\n\t\tSparseTable [][] seg=new SparseTable [2][2];\n\t\tfor(int i=0;i=0;i--){\n\t\t\tfor(int j=0;j<2;j++){\n\t\t\t\tint [] a=new int [n/2+2];\n\t\t\t\tArrays.fill(a, inf);\n\t\t\t\tfor(int c=0;c<=l[i] && cl[i])\n\t\t\t\t\t\tbest=Math.min(best, 2+seg[1-p][j].query(c+l[i+1]-r[i], c+l[i+1]-l[i]-1));\n\t\t\t\t\ta[c]=best;\n\t\t\t\t}\n\t\t\t\tseg[p][j]=new SparseTable(a);\n\t\t\t}\n\t\t\tp^=1;\n\t\t}\n\t\tp^=1;\n\t\tint ans=Math.min(seg[p][0].query(l[0], l[0]), seg[p][1].query(l[0], l[0]));\n\t\tif(ans>2*k)\n\t\t\tpw.println(\"Hungry\");\n\t\telse{\n\t\t\tpw.println(\"Full\");\n\t\t\tpw.println(ans);\n\t\t}\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic int inf=(int)1e7;\n\t\n\tstatic class SparseTable {\n\t\tint [] a;\n\t\tint [][] st;\n\t\t//st[i][j] --> minimum of sub array starting at index i and of length 2^j\n\t\tSparseTable(int [] a){\n\t\t\tint n=a.length;\n\t\t\tthis.a=a;\n\t\t\tint k=(int)Math.floor(Math.log(n)/Math.log(2))+1;\n\t\t\tst=new int [n][k];\n\t\t\tfor(int i=0;i=a.length)\n\t\t\t\treturn inf;\n\t\t\tj=Math.min(j, a.length-1);\n\t\t\tint k=(int)Math.floor(Math.log(j-i+1)/Math.log(2));\n\t\t\treturn Math.min(a[st[i][k]], a[st[j-(1< finSeg = new ArrayList();\n public static void main(String[] args) throws IOException {\n FastScanner in = new FastScanner(System.in);\n n = in.nextInt();\n k = in.nextInt();\n segs = new int[k][2];\n for(int i = 0;i < k; i++){\n segs[i][0] = in.nextInt();\n segs[i][1] = in.nextInt();\n }\n Arrays.sort(segs, new Comparator() {\n @Override\n public int compare(int[] o1, int[] o2) {\n return o1[0] - o2[0];\n }\n });\n for(int i = 0;i < k; i++){\n lo = segs[i][0];\n hi = segs[i][0];\n while(i < k && segs[i][0] <= hi)hi = Math.max(hi , segs[i++][1]);\n int[] add = {lo , hi};\n finSeg.add(add);\n i--;\n }\n k = finSeg.size();\n segs = new int[k][2];\n l = new int[k];\n delt = new int[k];\n for(int i = 0;i < k; i++)segs[i] = finSeg.get(i);\n for(int i = 0;i < k; i++){\n l[i] = segs[i][1] - segs[i][0];\n delt[i] = i < k-1 ? segs[i+1][0] - segs[i][1] : 2*n - segs[i][1];\n }\n dp = new int[2][k+1][2*n+1];\n for(int i = 0;i < 2*n+1; i++){\n dp[0][k][i] = n;\n dp[1][k][i] = n;\n }\n dp[0][k][n] = 0;\n dp[1][k][n] = 0;\n RMQ[] rmq = new RMQ[2];\n rmq[0] = new RMQ(dp[0][k]);\n rmq[1] = new RMQ(dp[1][k]);\n for(int i = k-1; i >= 0; i--){\n for(int j = 0;j <= 2*n; j++){\n dp[0][i][j] = j+l[i]+delt[i] <= 2*n ? dp[0][i+1][j+l[i]+delt[i]] : n;\n dp[1][i][j] = dp[1][i+1][j];\n dp[0][i][j] = Math.min(dp[0][i][j] , 1 + rmq[1].min(j , Math.min(j+l[i] , 2*n)));\n if(j + delt[i] <= 2*n)dp[1][i][j] = Math.min(dp[1][i][j] , 1 + rmq[0].min(j + delt[i] , Math.min(j+l[i] + delt[i] , 2*n)));\n if(j + delt[i] <= 2*n)dp[0][i][j] = Math.min(dp[0][i][j] , 2 + rmq[0].min(j + delt[i] , Math.min(j+l[i] + delt[i] , 2*n)));\n dp[1][i][j] = Math.min(dp[1][i][j] , 2 + rmq[1].min(j , Math.min(j+l[i] , 2*n)));\n }\n rmq[0] = new RMQ(dp[0][i]);\n rmq[1] = new RMQ(dp[1][i]);\n }\n int ans = dp[1][0][0];\n if(ans == n)System.out.println(\"Hungry\");\n else {\n System.out.println(\"Full\");\n System.out.println(ans);\n }\n\n }\n public static class RMQ{\n int n , k;\n int[][] min;\n public RMQ(int[] a){\n n = a.length;\n k = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))+1;\n min = new int[k][n];\n for(int i = 0;i < n; i++)\n min[0][i] = a[i];\n for(int i = 1; i < k; i++){\n for(int j = 0;j + (1 << i-1) < n; j++){\n min[i][j] = Math.min(min[i-1][j] , min[i-1][j + (1 << i-1)]);\n }\n }\n }\n public int min(int a , int b){\n int z = Integer.numberOfTrailingZeros(Integer.highestOneBit(b-a+1));\n return Math.min(min[z][a] , min[z][b - (1<= 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d582674628dd0ec2c104562147e7b79c", "src_uid": "2e0d1b1f1a7b8df2d2598c3cb2c869d5", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.Arrays;\n\n/**\n * Created by dalt on 2018/3/14.\n */\npublic class CF939F {\n public static final int INF = (int) 1e8;\n public static BlockReader input;\n public static PrintStream output;\n\n public static void main(String[] args) throws FileNotFoundException {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n input = new BlockReader(new FileInputStream(\"D:\\\\DataBase\\\\TESTCASE\\\\codeforces\\\\CF939F.in\"));\n output = System.out;\n } else {\n input = new BlockReader(System.in);\n output = new PrintStream(new BufferedOutputStream(System.out), false);\n }\n\n solve();\n\n output.flush();\n }\n\n public static void solve() {\n int n = input.nextInteger();\n int k = input.nextInteger();\n\n int[][] intervals = new int[k + 2][2];\n for (int i = 1; i <= k; i++) {\n intervals[i][0] = input.nextInteger();\n intervals[i][1] = input.nextInteger();\n }\n intervals[k + 1][0] = 2 * n;\n intervals[k + 1][1] = 2 * n;\n\n k++;\n\n Node[] loop = new Node[2];\n loop[0] = Node.build(0, n);\n loop[1] = Node.build(0, n);\n\n int[] data = new int[n + 1];\n\n for (int i = 1; i <= k; i++) {\n Node curDp = loop[i & 1];\n\n Node lastDp = loop[(i - 1) & 1];\n\n\n int[] interval = intervals[i];\n int intervalLength = interval[1] - interval[0];\n int middleLength = interval[0] - intervals[i - 1][1];\n\n Node.toArray(0, n, data, lastDp);\n System.arraycopy(data, 0, data, intervalLength + middleLength, n + 1 - (intervalLength + middleLength));\n Arrays.fill(data, 0, intervalLength + middleLength, INF);\n\n //No flip\n/* for (int j = intervalLength + middleLength; j <= n; j++) {\n int lastFryTotalTime = j - intervalLength - middleLength;\n int minNeedTime = Node.query(lastFryTotalTime, lastFryTotalTime, 0, n, lastDp);\n Node.update(j, 0, n, minNeedTime, curDp);\n }*/\n\n\n int minX = interval[1] - middleLength - intervalLength;\n int maxX = interval[1] - middleLength;\n for (int j = 0; j <= n; j++) {\n //Flip once\n int minNeedTime = Node.query(minX - j, maxX - j, 0, n, lastDp);\n data[j] = Math.min(data[j], minNeedTime + 1);\n // Node.update(j, 0, n, minNeedTime + 1, curDp);\n }\n\n for (int j = 0; j <= n; j++) {\n //Flip twice\n int minNeedTime = Node.query(interval[1] - intervalLength, interval[1], 0, n, lastDp);\n //Node.update(j, 0, n, minNeedTime + 2, curDp);\n data[j] = Math.min(data[j], minNeedTime + 2);\n }\n\n Node.fromArray(0, n, data, curDp);\n }\n\n int minFlipTime = Node.query(n, n, 0, n, loop[k & 1]);\n\n if (minFlipTime < INF) {\n output.println(\"Full\");\n output.println(minFlipTime);\n } else {\n output.println(\"Hungry\");\n }\n }\n\n\n public static class Node {\n Node left;\n Node right;\n int batchSetValue;\n boolean dirty;\n int min;\n\n public static void setValue(int f, int t, int l, int r, int val, Node node) {\n if (f > r || t < l) {\n return;\n }\n if (f <= l && t >= r) {\n node.setValue(val);\n return;\n }\n\n node.pushDown();\n int m = (l + r) >> 1;\n setValue(f, t, l, m, val, node.left);\n setValue(f, t, m + 1, r, val, node.right);\n\n node.pushUp();\n }\n\n public static Node build(int l, int r) {\n Node node = new Node();\n if (l != r) {\n int m = (l + r) >> 1;\n node.left = build(l, m);\n node.right = build(m + 1, r);\n }\n return node;\n }\n\n public static int query(int f, int t, int l, int r, Node node) {\n if (f > r || t < l) {\n return INF;\n }\n if (f <= l && r <= t) {\n return node.min;\n }\n node.pushDown();\n int m = (l + r) >> 1;\n return Math.min(query(f, t, l, m, node.left), query(f, t, m + 1, r, node.right));\n }\n\n public static void update(int i, int l, int r, int val, Node node) {\n if (i > r || i < l) {\n return;\n }\n if (i <= l && i >= r) {\n node.min = Math.min(node.min, val);\n return;\n }\n\n node.pushDown();\n int m = (l + r) >> 1;\n update(i, l, m, val, node.left);\n update(i, m + 1, r, val, node.right);\n\n node.pushUp();\n }\n\n public static void toArray(int l, int r, int[] data, Node node) {\n if (l == r) {\n data[l] = node.min;\n return;\n }\n node.pushDown();\n int m = (l + r) >> 1;\n toArray(l, m, data, node.left);\n toArray(m + 1, r, data, node.right);\n }\n\n public static void fromArray(int l, int r, int[] data, Node node) {\n if (l == r) {\n node.min = data[l];\n return;\n }\n\n node.dirty = false;\n int m = (l + r) >> 1;\n fromArray(l, m, data, node.left);\n fromArray(m + 1, r, data, node.right);\n node.pushUp();\n }\n\n public void pushUp() {\n this.min = Math.min(left.min, right.min);\n }\n\n public void setValue(int val) {\n this.min = val;\n this.batchSetValue = val;\n this.dirty = true;\n }\n\n public void pushDown() {\n if (dirty) {\n left.setValue(batchSetValue);\n right.setValue(batchSetValue);\n dirty = false;\n }\n }\n\n @Override\n public String toString() {\n int t = 100;\n int[] data = new int[t + 1];\n for (int i = 0; i <= t; i++) {\n data[i] = query(i, i, 0, t, this);\n }\n return Arrays.toString(data);\n }\n }\n\n public static class BlockReader {\n static final int EOF = -1;\n InputStream is;\n byte[] dBuf;\n int dPos, dSize, next;\n StringBuilder builder = new StringBuilder();\n\n public BlockReader(InputStream is) {\n this(is, 4096);\n }\n\n public BlockReader(InputStream is, int bufSize) {\n this.is = is;\n dBuf = new byte[bufSize];\n next = nextByte();\n }\n\n public int nextByte() {\n while (dPos >= dSize) {\n if (dSize == -1) {\n return EOF;\n }\n dPos = 0;\n try {\n dSize = is.read(dBuf);\n } catch (Exception e) {\n }\n }\n return dBuf[dPos++];\n }\n\n public String nextBlock() {\n builder.setLength(0);\n skipBlank();\n while (next != EOF && !Character.isWhitespace(next)) {\n builder.append((char) next);\n next = nextByte();\n }\n return builder.toString();\n }\n\n public void skipBlank() {\n while (Character.isWhitespace(next)) {\n next = nextByte();\n }\n }\n\n public int nextInteger() {\n skipBlank();\n int ret = 0;\n boolean rev = false;\n if (next == '+' || next == '-') {\n rev = next == '-';\n next = nextByte();\n }\n while (next >= '0' && next <= '9') {\n ret = (ret << 3) + (ret << 1) + next - '0';\n next = nextByte();\n }\n return rev ? -ret : ret;\n }\n\n public int nextBlock(char[] data, int offset) {\n skipBlank();\n int index = offset;\n int bound = data.length;\n while (next != EOF && index < bound && !Character.isWhitespace(next)) {\n data[index++] = (char) next;\n next = nextByte();\n }\n return index - offset;\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != EOF;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ca7c0bf10ff06884a00f5a54dd42222a", "src_uid": "2e0d1b1f1a7b8df2d2598c3cb2c869d5", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: mac\n * Date: 11-12-24\n * Time: \u4e0b\u53487:56\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class e {\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n 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 String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n void solve() throws IOException {\n String input = nextToken();\n int n = input.length();\n int[] what = new int[n];\n for (int i = 0; i < n; i++) {\n what[i] = input.charAt(i) - 'a';\n }\n\n int k = nextInt(), L = nextInt(), R = nextInt();\n int[] id = new int[k], l = new int[k], r = new int[k];\n\n int[] cnt = new int[n];\n\n for (int i = 0; i < k; i++) {\n id[i] = nextToken().charAt(0) - 'a';\n l[i] = nextInt();\n r[i] = nextInt();\n }\n\n int[] atL = new int[k], atR = new int[k];//[l,r)\n long ans = 0;\n\n @SuppressWarnings({\"unchecked\"})\n List[] by = new List[26];\n for (int i = 0; i < 26; i++) {\n by[i] = new ArrayList();\n }\n\n for (int i = 0; i < n; i++) {\n by[what[i]].add(i);\n }\n\n for (int i = 0; i < k; i++) {\n if (by[id[i]].size() < l[i]) {\n atL[i] = atR[i] = n;\n } else {\n if (l[i] == 0) {\n atL[i] = 0;\n } else {\n atL[i] = by[id[i]].get(l[i] - 1);\n }\n if (by[id[i]].size() <= r[i]) {\n atR[i] = n;\n } else {\n atR[i] = by[id[i]].get(r[i]);\n }\n }\n }\n\n for (int i = 0; i < k; i++) {\n for (int j = atL[i]; j < atR[i]; j++) {\n cnt[j]++;\n }\n }\n int curCount = 0;\n for (int i = 0; i < n; i++) {\n if (cnt[i] >= L && cnt[i] <= R)\n ++curCount;\n }\n\n for (int i = 0; i < n; i++) {\n int me = what[i];\n ans += curCount;\n\n for (int j = 0; j < k; j++) {\n if (id[j] == me) {\n int x = atL[j];\n while (x < n) {\n if (cnt[x] >= L && cnt[x] <= R) {\n --curCount;\n }\n cnt[x]--;\n if (cnt[x] >= L && cnt[x] <= R) {\n ++curCount;\n }\n ++x;\n if (x == n || what[x] == me)\n break;\n }\n atL[j] = x;\n\n x = atR[j];\n while (x < n) {\n if (cnt[x] >= L && cnt[x] <= R) {\n --curCount;\n }\n cnt[x]++;\n if (cnt[x] >= L && cnt[x] <= R) {\n ++curCount;\n }\n ++x;\n if (x == n || what[x] == me)\n break;\n }\n atR[j] = x;\n }\n }\n\n if (cnt[i] >= L && cnt[i] <= R)\n --curCount;\n }\n\n writer.println(ans);\n }\n\n static public void main(String[] args) {\n new e().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b7bd8bc3803201eaca79ff2229b47f91", "src_uid": "948f7747cab468b26cc28a3ff29fabdd", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: mac\n * Date: 11-12-24\n * Time: \u4e0b\u53487:56\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class e {\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n 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 String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n void solve() throws IOException {\n String input = nextToken();\n int n = input.length();\n int[] what = new int[n];\n for (int i = 0; i < n; i++) {\n what[i] = input.charAt(i) - 'a';\n }\n\n int k = nextInt(), L = nextInt(), R = nextInt();\n int[] id = new int[k], l = new int[k], r = new int[k];\n\n int[] cnt = new int[n];\n\n for (int i = 0; i < k; i++) {\n id[i] = nextToken().charAt(0) - 'a';\n l[i] = nextInt();\n r[i] = nextInt();\n }\n\n int[] atL = new int[k], atR = new int[k];//[l,r)\n long ans = 0;\n\n @SuppressWarnings({\"unchecked\"})\n List[] by = new List[26];\n for (int i = 0; i < 26; i++) {\n by[i] = new ArrayList();\n }\n\n for (int i = 0; i < n; i++) {\n by[what[i]].add(i);\n }\n\n for (int i = 0; i < k; i++) {\n if (by[id[i]].size() < l[i]) {\n atL[i] = atR[i] = n;\n } else {\n if (l[i] == 0) {\n atL[i] = 0;\n } else {\n atL[i] = by[id[i]].get(l[i] - 1);\n }\n if (by[id[i]].size() <= r[i]) {\n atR[i] = n;\n } else {\n atR[i] = by[id[i]].get(r[i]);\n }\n }\n }\n\n for (int i = 0; i < k; i++) {\n for (int j = atL[i]; j < atR[i]; j++) {\n cnt[j]++;\n }\n }\n int curCount = 0;\n for (int i = 0; i < n; i++) {\n if (cnt[i] >= L && cnt[i] <= R)\n ++curCount;\n }\n\n for (int i = 0; i < n; i++) {\n int me = what[i];\n ans += curCount;\n\n for (int j = 0; j < k; j++) {\n if (id[j] == me) {\n int x = atL[j];\n while (x < n) {\n if (x >= i) {\n if (cnt[x] >= L && cnt[x] <= R) {\n --curCount;\n }\n cnt[x]--;\n if (cnt[x] >= L && cnt[x] <= R) {\n ++curCount;\n }\n }\n ++x;\n if (x == n || what[x] == me)\n break;\n }\n atL[j] = x;\n\n x = atR[j];\n while (x < n) {\n if (x >= i) {\n if (cnt[x] >= L && cnt[x] <= R) {\n --curCount;\n }\n cnt[x]++;\n if (cnt[x] >= L && cnt[x] <= R) {\n ++curCount;\n }\n ++x;\n }\n if (x == n || what[x] == me)\n break;\n }\n atR[j] = x;\n }\n }\n\n if (cnt[i] >= L && cnt[i] <= R)\n --curCount;\n }\n\n writer.println(ans);\n }\n\n static public void main(String[] args) {\n new e().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a01bcf3304269f79a88e7ca129af4b96", "src_uid": "948f7747cab468b26cc28a3ff29fabdd", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "//package school3;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class F5 {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"100000 4\";\n//\tString INPUT = \"2 100000\";\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 == 2 && n == 2){\n\t\t\tout.println(3);\n\t\t\treturn;\n\t\t}\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 visitedo = new HashSet();\n\t\tHashSet visitedh = new HashSet();\n\t\tHashSet q = new HashSet();\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 nq = new HashSet();\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3cf50581bcbb793752bff6ef4c45975d", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "//package school3;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class F5 {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"100000 4\";\n//\tString INPUT = \"2 100000\";\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 == 2 && n == 2){\n\t\t\tthrow new Error();\n//\t\t\treturn;\n\t\t}\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 visitedo = new HashSet();\n\t\tHashSet visitedh = new HashSet();\n\t\tHashSet q = new HashSet();\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 nq = new HashSet();\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ddfd8ab77fb715f3a40fffbae084556d", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "package ACM;\n\nimport java.util.Scanner;\n\npublic class CF45F {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint m = sc.nextInt();\n\t\tint n = sc.nextInt();\n\t\tsc.close();\n\t\tint ans=0;\n\t\tboolean f = false;\n\t\tif(n==1) {\n\t\t\tP(-1);\n\t\t\treturn ;\n\t\t}\n\t\tif(n==2 && m==3||n==3 && m==5) {\n\t\t\tP(11);\n\t\t\treturn ;\n\t\t}\n\t\tfor(;;)\n\t\t{\n\t\t\tif(n>=m+m) {\n\t\t\t\tP(ans+1);\n\t\t\t\treturn ;\n\t\t\t}\n\t\t\telse if(n>=m)\n\t\t\t{\n\t\t\t\tP(ans+(n==m?5:3));\n\t\t\t\treturn ;\n\t\t\t}\n\t\t\telse if(!f) {\n\t\t\t\tm-=n-2;\n\t\t\t\tans=4;\n\t\t\t\tf=true;\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\tif(n/2==1)\n\t\t\t\t{\n\t\t\t\t\tP(-1);\n\t\t\t\t\treturn ;\n\t\t\t\t}\n\t\t\t\tm-=n/2-1;\n\t\t\t\tans+=2;\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void P(int x)\n\t{\n\t\tSystem.out.println(x);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d53cfec90840849b7c264bcd613d8119", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "//package school3;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class F5 {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"100000 4\";\n//\tString INPUT = \"2 100000\";\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 == 2 && n == 2){\n\t\t\tthrow new Error();\n\t\t\treturn;\n\t\t}\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 visitedo = new HashSet();\n\t\tHashSet visitedh = new HashSet();\n\t\tHashSet q = new HashSet();\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 nq = new HashSet();\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "020c8d6a7b458fdd8968c9c2ce745738", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.stream.IntStream;\nimport java.util.PriorityQueue;\nimport java.util.AbstractQueue;\nimport java.util.Random;\nimport java.util.ArrayList;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.util.List;\nimport java.util.stream.Stream;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 29);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DFindingLines solver = new DFindingLines();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DFindingLines {\n int interval = 19000;\n int inf = (int) 1e8;\n Comparator comp = (a, b) -> a.len == b.len ? Integer.compare(a.l, b.l) : -Integer.compare(a.len, b.len);\n PriorityQueue ySet = new PriorityQueue<>((int) 1e4, comp);\n List xLines = new ArrayList<>();\n FastInput in;\n FastOutput out;\n RandomWrapper rw = new RandomWrapper(new Random());\n int limit = (int) 3e5;\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n this.in = in;\n this.out = out;\n clear();\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), false, 0);\n }\n xLines.sort(Comparator.naturalOrder());\n int[] xArrays = xLines.stream()\n .mapToInt(Integer::intValue).toArray();\n\n clear();\n ySet.clear();\n int left = -inf;\n for (int x : xArrays) {\n Interval interval = new Interval(left, x - 1);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n left = x + 1;\n }\n {\n Interval interval = new Interval(left, inf);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), true, 0);\n }\n xLines.sort(Comparator.naturalOrder());\n int[] yArrays = xLines.stream()\n .mapToInt(Integer::intValue).toArray();\n\n out.printf(\"1 %d %d\", xArrays.length, yArrays.length).println();\n for (int x : xArrays) {\n out.append(x).append(' ');\n }\n out.println();\n for (int y : yArrays) {\n out.append(y).append(' ');\n }\n out.println().flush();\n }\n\n public void clear() {\n ySet.clear();\n xLines.clear();\n ySet.add(new Interval(-inf, inf));\n }\n\n public void check(Interval x, boolean inv, int depth) {\n if (x.isEmpty()) {\n return;\n }\n\n Interval y = ySet.peek();\n int cx = x.middle();\n int cy = y.middle();\n int dist = ask(cx, cy, inv);\n\n if (!(cx - dist >= x.l || cx + dist <= x.r)) {\n return;\n }\n\n if (cx - dist >= x.l && exist(cx - dist, inv, 3)) {\n xLines.add(cx - dist);\n for (Interval interval : x.split(cx - dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (dist != 0 && cx + dist <= x.r && exist(cx + dist, inv, 3)) {\n xLines.add(cx + dist);\n for (Interval interval : x.split(cx + dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cy - dist >= y.l && exist(cy - dist, !inv, 3)) {\n ySet.remove();\n for (Interval interval : y.split(cy - dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n check(x, inv, depth + 1);\n return;\n }\n\n if (dist != 0 && cy + dist <= y.r && exist(cy + dist, !inv, 3)) {\n ySet.remove();\n for (Interval interval : y.split(cy + dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n check(x, inv, depth + 1);\n return;\n }\n\n\n }\n\n public boolean exist(int x, boolean inv, int time) {\n for (int i = 0; i < time; i++) {\n int y1 = rw.nextInt(-inf, inf);\n if (ask(x, y1, inv) != 0) {\n return false;\n }\n }\n return true;\n }\n\n public int ask(int x, int y, boolean inv) {\n if (inv) {\n int tmp = x;\n x = y;\n y = tmp;\n }\n\n if (limit-- == 0) {\n throw new RuntimeException();\n }\n\n out.append(\"0 \").append(x).append(' ').append(y).println().flush();\n return in.readInt();\n }\n\n }\n\n static class Interval {\n int l;\n int r;\n int len;\n\n public int middle() {\n return (r + l) / 2;\n }\n\n public Interval(int l, int r) {\n this.l = l;\n this.r = r;\n this.len = r - l + 1;\n }\n\n public boolean isEmpty() {\n return r < l;\n }\n\n public Interval[] split(int x) {\n return new Interval[]{new Interval(l, x - 1), new Interval(x + 1, r)};\n }\n\n public String toString() {\n return String.format(\"[%d, %d]\", l, r);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput printf(String format, Object... args) {\n cache.append(String.format(format, args));\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class RandomWrapper {\n private Random random;\n\n public RandomWrapper() {\n this(new Random());\n }\n\n public RandomWrapper(Random random) {\n this.random = random;\n }\n\n public int nextInt(int l, int r) {\n return random.nextInt(r - l + 1) + l;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4522cac992d90f1bba39caa5b054448", "src_uid": "583cd1e553133b297f99fd52e5ad355b", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.AbstractQueue;\nimport java.util.Random;\nimport java.util.TreeSet;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 29);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DFindingLines solver = new DFindingLines();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DFindingLines {\n int interval = 19000;\n int inf = (int) 1e8;\n Comparator comp = (a, b) -> a.len == b.len ? Integer.compare(a.l, b.l) : -Integer.compare(a.len, b.len);\n PriorityQueue ySet = new PriorityQueue<>((int) 1e4, comp);\n IntegerList yLines = new IntegerList();\n TreeSet xSet = new TreeSet<>(comp);\n IntegerList xLines = new IntegerList();\n FastInput in;\n FastOutput out;\n RandomWrapper rw = new RandomWrapper(new Random());\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n this.in = in;\n this.out = out;\n clear();\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), false, 0);\n }\n xLines.unique();\n int[] xArrays = xLines.toArray();\n\n clear();\n ySet.clear();\n int left = -inf;\n for (int x : xArrays) {\n Interval interval = new Interval(left, x - 1);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n left = x + 1;\n }\n {\n Interval interval = new Interval(left, inf);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), true, 0);\n }\n xLines.unique();\n int[] yArrays = xLines.toArray();\n\n out.printf(\"1 %d %d\", xArrays.length, yArrays.length).println();\n for (int x : xArrays) {\n out.append(x).append(' ');\n }\n out.println();\n for (int y : yArrays) {\n out.append(y).append(' ');\n }\n out.println().flush();\n }\n\n public void clear() {\n ySet.clear();\n xSet.clear();\n yLines.clear();\n xLines.clear();\n ySet.add(new Interval(-inf, inf));\n xSet.add(new Interval(-inf, inf));\n }\n\n public void check(Interval x, boolean inv, int depth) {\n if (x.isEmpty()) {\n return;\n }\n\n Interval y = ySet.peek();\n int cx = x.middle();\n int cy = y.middle();\n int dist = ask(cx, cy, inv);\n\n if (!(cx - dist >= x.l || cx + dist <= x.r)) {\n return;\n }\n\n if (cx - dist >= x.l && exist(cx - dist, inv)) {\n xLines.add(cx - dist);\n for (Interval interval : x.split(cx - dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cx + dist <= x.r && exist(cx + dist, inv)) {\n xLines.add(cx + dist);\n for (Interval interval : x.split(cx + dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cy - dist >= y.l && exist(cy - dist, !inv)) {\n ySet.remove();\n for (Interval interval : y.split(cy - dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n }\n\n if (cy + dist <= y.r && exist(cy + dist, !inv)) {\n ySet.remove();\n for (Interval interval : y.split(cy + dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n }\n\n //check(x, inv, depth + 1);\n }\n\n public boolean exist(int x, boolean inv) {\n int y1 = rw.nextInt(-inf, inf);\n int y2 = rw.nextInt(-inf, inf);\n int y3 = rw.nextInt(-inf, inf);\n int y4 = rw.nextInt(-inf, inf);\n return ask(x, y1, inv) == 0 && ask(x, y2, inv) == 0 && ask(x, y3, inv) == 0 &&\n ask(x, y4, inv) == 0;\n }\n\n public int ask(int x, int y, boolean inv) {\n if (inv) {\n int tmp = x;\n x = y;\n y = tmp;\n }\n\n out.append(\"0 \").append(x).append(' ').append(y).println().flush();\n return in.readInt();\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 Interval {\n int l;\n int r;\n int len;\n\n public int middle() {\n return (r + l) / 2;\n }\n\n public Interval(int l, int r) {\n this.l = l;\n this.r = r;\n this.len = r - l + 1;\n }\n\n public boolean isEmpty() {\n return r < l;\n }\n\n public Interval[] split(int x) {\n return new Interval[]{new Interval(l, x - 1), new Interval(x + 1, r)};\n }\n\n public String toString() {\n return String.format(\"[%d, %d]\", l, r);\n }\n\n }\n\n static class 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 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[] 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 class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput printf(String format, Object... args) {\n cache.append(String.format(format, args));\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class 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 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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70d2a4598dd9179afa83eb3ac046fd57", "src_uid": "583cd1e553133b297f99fd52e5ad355b", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.Random;\nimport java.util.TreeSet;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 29);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DFindingLines solver = new DFindingLines();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DFindingLines {\n int interval = 18000;\n int inf = (int) 1e8;\n Comparator comp = (a, b) -> a.len == b.len ? Integer.compare(a.l, b.l) : Integer.compare(a.len, b.len);\n TreeSet ySet = new TreeSet<>(comp);\n IntegerList yLines = new IntegerList();\n TreeSet xSet = new TreeSet<>(comp);\n IntegerList xLines = new IntegerList();\n FastInput in;\n FastOutput out;\n RandomWrapper rw = new RandomWrapper(new Random(0));\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n this.in = in;\n this.out = out;\n clear();\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), false, 0);\n }\n xLines.unique();\n int[] xArrays = xLines.toArray();\n\n clear();\n ySet.clear();\n int left = -inf;\n for (int x : xArrays) {\n Interval interval = new Interval(left, x - 1);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n left = x + 1;\n }\n {\n Interval interval = new Interval(left, inf);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), true, 0);\n }\n xLines.unique();\n int[] yArrays = xLines.toArray();\n\n out.printf(\"1 %d %d\", xArrays.length, yArrays.length).println();\n for (int x : xArrays) {\n out.append(x).append(' ');\n }\n out.println();\n for (int y : yArrays) {\n out.append(y).append(' ');\n }\n out.println().flush();\n }\n\n public void clear() {\n ySet.clear();\n xSet.clear();\n yLines.clear();\n xLines.clear();\n ySet.add(new Interval(-inf, inf));\n xSet.add(new Interval(-inf, inf));\n }\n\n public void check(Interval x, boolean inv, int depth) {\n if (x.isEmpty()) {\n return;\n }\n\n Interval y = ySet.last();\n int cx = x.middle();\n int cy = y.middle();\n int dist = ask(cx, cy, inv);\n\n if (!(cx - dist >= x.l || cx + dist <= x.r)) {\n return;\n }\n\n if (cx - dist >= x.l && exist(cx - dist, inv)) {\n xLines.add(cx - dist);\n for (Interval interval : x.split(cx - dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cx + dist <= x.r && exist(cx + dist, inv)) {\n xLines.add(cx + dist);\n for (Interval interval : x.split(cx + dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cy - dist >= y.l && exist(cy - dist, !inv)) {\n ySet.remove(y);\n for (Interval interval : y.split(cy - dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n }\n\n if (cy + dist <= y.r && exist(cy + dist, !inv)) {\n ySet.remove(y);\n for (Interval interval : y.split(cy + dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n }\n\n //check(x, inv, depth + 1);\n }\n\n public boolean exist(int x, boolean inv) {\n int y1 = rw.nextInt(-inf, inf);\n int y2 = rw.nextInt(-inf, inf);\n int y3 = rw.nextInt(-inf, inf);\n return ask(x, y1, inv) == 0 && ask(x, y2, inv) == 0 && ask(x, y3, inv) == 0;\n }\n\n public int ask(int x, int y, boolean inv) {\n if (inv) {\n int tmp = x;\n x = y;\n y = tmp;\n }\n\n out.append(\"0 \").append(x).append(' ').append(y).println().flush();\n return in.readInt();\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 Interval {\n int l;\n int r;\n int len;\n\n public int middle() {\n return (r + l) / 2;\n }\n\n public Interval(int l, int r) {\n this.l = l;\n this.r = r;\n this.len = r - l + 1;\n }\n\n public boolean isEmpty() {\n return r < l;\n }\n\n public Interval[] split(int x) {\n return new Interval[]{new Interval(l, x - 1), new Interval(x + 1, r)};\n }\n\n public String toString() {\n return String.format(\"[%d, %d]\", l, r);\n }\n\n }\n\n static class 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 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[] 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 class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput printf(String format, Object... args) {\n cache.append(String.format(format, args));\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class 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 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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "03dd1b2c74e28c6c3b7778010a7bb92a", "src_uid": "583cd1e553133b297f99fd52e5ad355b", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.Random;\nimport java.util.TreeSet;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 29);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DFindingLines solver = new DFindingLines();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DFindingLines {\n int interval = 18000;\n int inf = (int) 1e8;\n Comparator comp = (a, b) -> a.len == b.len ? Integer.compare(a.l, b.l) : Integer.compare(a.len, b.len);\n TreeSet ySet = new TreeSet<>(comp);\n IntegerList yLines = new IntegerList();\n TreeSet xSet = new TreeSet<>(comp);\n IntegerList xLines = new IntegerList();\n FastInput in;\n FastOutput out;\n RandomWrapper rw = new RandomWrapper(new Random(0));\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n this.in = in;\n this.out = out;\n clear();\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), false, 0);\n }\n xLines.unique();\n int[] xArrays = xLines.toArray();\n\n clear();\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), true, 0);\n }\n xLines.unique();\n int[] yArrays = xLines.toArray();\n\n out.printf(\"1 %d %d\", xArrays.length, yArrays.length).println();\n for (int x : xArrays) {\n out.append(x).append(' ');\n }\n out.println();\n for (int y : yArrays) {\n out.append(y).append(' ');\n }\n out.println().flush();\n }\n\n public void clear() {\n ySet.clear();\n xSet.clear();\n yLines.clear();\n xLines.clear();\n ySet.add(new Interval(-inf, inf));\n xSet.add(new Interval(-inf, inf));\n }\n\n public void check(Interval x, boolean inv, int depth) {\n if (x.isEmpty()) {\n return;\n }\n\n Interval y = ySet.last();\n int cx = x.middle();\n int cy = y.middle();\n int dist = ask(cx, cy, inv);\n\n if (!(cx - dist >= x.l || cx + dist <= x.r)) {\n return;\n }\n\n if (cx - dist >= x.l && exist(cx - dist, inv)) {\n xLines.add(cx - dist);\n for (Interval interval : x.split(cx - dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cx + dist <= x.r && exist(cx + dist, inv)) {\n xLines.add(cx + dist);\n for (Interval interval : x.split(cx + dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cy - dist >= y.l && exist(cy - dist, !inv)) {\n ySet.remove(y);\n for (Interval interval : y.split(cy - dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n }\n\n if (cy + dist <= y.r && exist(cy + dist, !inv)) {\n ySet.remove(y);\n for (Interval interval : y.split(cy + dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n }\n\n //check(x, inv, depth + 1);\n }\n\n public boolean exist(int x, boolean inv) {\n int y1 = rw.nextInt(-inf, inf);\n int y2 = rw.nextInt(-inf, inf);\n return ask(x, y1, inv) == 0 && ask(x, y2, inv) == 0;\n }\n\n public int ask(int x, int y, boolean inv) {\n if (inv) {\n int tmp = x;\n x = y;\n y = tmp;\n }\n\n out.append(\"0 \").append(x).append(' ').append(y).println().flush();\n return in.readInt();\n }\n\n }\n\n static class Interval {\n int l;\n int r;\n int len;\n\n public int middle() {\n return (r + l) / 2;\n }\n\n public Interval(int l, int r) {\n this.l = l;\n this.r = r;\n this.len = r - l + 1;\n }\n\n public boolean isEmpty() {\n return r < l;\n }\n\n public Interval[] split(int x) {\n return new Interval[]{new Interval(l, x - 1), new Interval(x + 1, r)};\n }\n\n public String toString() {\n return String.format(\"[%d, %d]\", l, r);\n }\n\n }\n\n static class 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 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 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[] 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 class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput printf(String format, Object... args) {\n cache.append(String.format(format, args));\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class 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 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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "542f7aa9f1357c5c028b30d53d3e4e8d", "src_uid": "583cd1e553133b297f99fd52e5ad355b", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n HZSShufflesCards solver = new HZSShufflesCards();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class HZSShufflesCards {\n NumberTheory.Mod998 mod = new NumberTheory.Mod998();\n int n;\n int m;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n\n mod.fInv(n + m);\n\n long phaseSize = 1;\n long p = 1;\n for (int i = 0; p != 0; i++) {\n p = mod.mult(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 sign = mod.paritySign(k + 1);\n long numPhases = mod.mult(m + k, mod.smallInv(k));\n long term = mod.mult(sign, mod.ncr(n, k), numPhases, phaseSize);\n answer = mod.add(answer, term);\n }\n\n out.println(answer);\n }\n\n }\n\n static class InputReader {\n public final BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class Util {\n public static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n private Util() {\n }\n\n }\n\n static class IntStack {\n int[] array;\n int size = 0;\n\n public IntStack() {\n this(8);\n }\n\n public IntStack(int capacity) {\n array = new int[capacity];\n }\n\n public void push(int item) {\n if (size >= array.length)\n array = resize(array);\n array[size++] = item;\n }\n\n public int size() {\n return size;\n }\n\n public int get(int i) {\n Util.ASSERT(i < size);\n return array[i];\n }\n\n private static int[] resize(int[] array) {\n int[] newArray = new int[array.length << 1];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n public String toString() {\n int[] trimmed = new int[size];\n System.arraycopy(array, 0, trimmed, 0, size);\n return Arrays.toString(trimmed);\n }\n\n }\n\n static class NumberTheory {\n private static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n public abstract static class Modulus> {\n final IntStack factorial = new IntStack();\n final IntStack invFactorial = new IntStack();\n\n public abstract long modulus();\n\n public Modulus() {\n super();\n factorial.push(1);\n invFactorial.push(1);\n }\n\n public long fact(int n) {\n while (factorial.size() <= n) {\n factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));\n }\n\n return factorial.get(n);\n }\n\n public long fInv(int n) {\n int lastKnown = invFactorial.size() - 1;\n\n if (lastKnown < n) {\n long[] fInv = new long[n - lastKnown];\n fInv[0] = inv(fact(n));\n for (int i = 1; i < fInv.length; i++) {\n fInv[i] = mult(fInv[i - 1], n - i + 1);\n }\n for (int i = fInv.length - 1; i >= 0; i--) {\n invFactorial.push((int) fInv[i]);\n }\n }\n\n return invFactorial.get(n);\n }\n\n public long paritySign(long k) {\n return (k & 1) == 0 ? 1 : modulus() - 1;\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 mult(long... x) {\n long r = 1;\n for (long i : x)\n r = mult(r, i);\n return r;\n }\n\n public long mult(long a, long b) {\n return (a * b) % modulus();\n }\n\n public long inv(long value) {\n long g = modulus(), x = 0, y = 1;\n for (long r = value; r != 0; ) {\n long q = g / r;\n g %= r;\n\n long temp = g;\n g = r;\n r = temp;\n\n x -= q * y;\n\n temp = x;\n x = y;\n y = temp;\n }\n\n ASSERT(g == 1);\n ASSERT(y == modulus() || y == -modulus());\n\n return normalize(x);\n }\n\n }\n\n public static class Mod998 extends NumberTheory.Modulus {\n public long modulus() {\n return 998_244_353L;\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "97964285b51db481a62b7ad3eff7189a", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n HZSShufflesCards solver = new HZSShufflesCards();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class HZSShufflesCards {\n NumberTheory.Mod998 mod = new NumberTheory.Mod998();\n int n;\n int m;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n\n mod.fInv(n + m);\n\n long phaseSize = 1;\n long p = 1;\n for (int i = 0; p != 0; i++) {\n p = mod.mult(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 term = mod.mult(mod.ncr(n, k), m + k, mod.smallInv(k), phaseSize);\n\n if (k % 2 == 1)\n answer = mod.add(answer, term);\n else\n answer = mod.subtract(answer, term);\n }\n\n out.println(answer);\n }\n\n }\n\n static class InputReader {\n public final BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class Util {\n public static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n private Util() {\n }\n\n }\n\n static class IntStack {\n int[] array;\n int size = 0;\n\n public IntStack() {\n this(8);\n }\n\n public IntStack(int capacity) {\n array = new int[capacity];\n }\n\n public void push(int item) {\n if (size >= array.length)\n array = resize(array);\n array[size++] = item;\n }\n\n public int size() {\n return size;\n }\n\n public int get(int i) {\n Util.ASSERT(i < size);\n return array[i];\n }\n\n private static int[] resize(int[] array) {\n int[] newArray = new int[array.length << 1];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n public String toString() {\n int[] trimmed = new int[size];\n System.arraycopy(array, 0, trimmed, 0, size);\n return Arrays.toString(trimmed);\n }\n\n }\n\n static class NumberTheory {\n private static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n public abstract static class Modulus> {\n final IntStack factorial = new IntStack();\n final IntStack invFactorial = new IntStack();\n\n public abstract long modulus();\n\n public Modulus() {\n super();\n factorial.push(1);\n invFactorial.push(1);\n }\n\n public long fact(int n) {\n while (factorial.size() <= n) {\n factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));\n }\n\n return factorial.get(n);\n }\n\n public long fInv(int n) {\n int lastKnown = invFactorial.size() - 1;\n\n if (lastKnown < n) {\n long[] fInv = new long[n - lastKnown];\n fInv[0] = inv(fact(n));\n for (int i = 1; i < fInv.length; i++) {\n fInv[i] = mult(fInv[i - 1], n - i + 1);\n }\n for (int i = fInv.length - 1; i >= 0; i--) {\n invFactorial.push((int) fInv[i]);\n }\n }\n\n return invFactorial.get(n);\n }\n\n public long ncr(int n, int r) {\n ASSERT(n >= 0);\n if (r < 0 || n < r)\n return 0;\n return mult(fact(n), mult(fInv(r), fInv(n - r)));\n }\n\n public long smallInv(int n) {\n return mult(fInv(n), fact(n - 1));\n }\n\n public long normalize(long x) {\n x %= modulus();\n if (x < 0)\n x += modulus();\n return x;\n }\n\n public long add(long a, long b) {\n long v = a + b;\n return v < modulus() ? v : v - modulus();\n }\n\n public long subtract(long a, long b) {\n long v = a - b;\n return v < 0 ? v + modulus() : v;\n }\n\n public long mult(long... x) {\n long r = 1;\n for (long i : x)\n r = mult(r, i);\n return r;\n }\n\n public long mult(long a, long b) {\n return (a * b) % modulus();\n }\n\n public long inv(long value) {\n long g = modulus(), x = 0, y = 1;\n for (long r = value; r != 0; ) {\n long q = g / r;\n g %= r;\n\n long temp = g;\n g = r;\n r = temp;\n\n x -= q * y;\n\n temp = x;\n x = y;\n y = temp;\n }\n\n ASSERT(g == 1);\n ASSERT(y == modulus() || y == -modulus());\n\n return normalize(x);\n }\n\n }\n\n public static class Mod998 extends NumberTheory.Modulus {\n public long modulus() {\n return 998_244_353L;\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c6a7f62bd94070909b49e47a58dad19", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n HZSShufflesCards solver = new HZSShufflesCards();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class HZSShufflesCards {\n NumberTheory.Mod998 mod = new NumberTheory.Mod998();\n int n;\n int m;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n\n mod.fInv(n + m);\n\n long phaseSize = 1;\n long p = 1;\n for (int i = 0; p != 0; i++) {\n p = mod.mult(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 answer = mod.add(answer, mod.mult(mod.paritySign(k + 1), mod.ncr(n, k), m + k, mod.smallInv(k), phaseSize));\n }\n\n out.println(answer);\n }\n\n }\n\n static class InputReader {\n public final BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class Util {\n public static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n private Util() {\n }\n\n }\n\n static class IntStack {\n int[] array;\n int size = 0;\n\n public IntStack() {\n this(8);\n }\n\n public IntStack(int capacity) {\n array = new int[capacity];\n }\n\n public void push(int item) {\n if (size >= array.length)\n array = resize(array);\n array[size++] = item;\n }\n\n public int size() {\n return size;\n }\n\n public int get(int i) {\n Util.ASSERT(i < size);\n return array[i];\n }\n\n private static int[] resize(int[] array) {\n int[] newArray = new int[array.length << 1];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n public String toString() {\n int[] trimmed = new int[size];\n System.arraycopy(array, 0, trimmed, 0, size);\n return Arrays.toString(trimmed);\n }\n\n }\n\n static class NumberTheory {\n private static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n public abstract static class Modulus> {\n final IntStack factorial = new IntStack();\n final IntStack invFactorial = new IntStack();\n\n public abstract long modulus();\n\n public Modulus() {\n super();\n factorial.push(1);\n invFactorial.push(1);\n }\n\n public long fact(int n) {\n while (factorial.size() <= n) {\n factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));\n }\n\n return factorial.get(n);\n }\n\n public long fInv(int n) {\n int lastKnown = invFactorial.size() - 1;\n\n if (lastKnown < n) {\n long[] fInv = new long[n - lastKnown];\n fInv[0] = inv(fact(n));\n for (int i = 1; i < fInv.length; i++) {\n fInv[i] = mult(fInv[i - 1], n - i + 1);\n }\n for (int i = fInv.length - 1; i >= 0; i--) {\n invFactorial.push((int) fInv[i]);\n }\n }\n\n return invFactorial.get(n);\n }\n\n public long paritySign(long k) {\n return (k & 1) == 0 ? 1 : modulus() - 1;\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 mult(long... x) {\n long r = 1;\n for (long i : x)\n r = mult(r, i);\n return r;\n }\n\n public long mult(long a, long b) {\n return (a * b) % modulus();\n }\n\n public long inv(long value) {\n long g = modulus(), x = 0, y = 1;\n for (long r = value; r != 0; ) {\n long q = g / r;\n g %= r;\n\n long temp = g;\n g = r;\n r = temp;\n\n x -= q * y;\n\n temp = x;\n x = y;\n y = temp;\n }\n\n ASSERT(g == 1);\n ASSERT(y == modulus() || y == -modulus());\n\n return normalize(x);\n }\n\n }\n\n public static class Mod998 extends NumberTheory.Modulus {\n public long modulus() {\n return 998_244_353L;\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f35bae1adf4d17603acfd97642764e72", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\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 long phaseSize = 1;\n long p = 1;\n for (int i = 0; p != 0; i++) {\n p = mod.mult(p, n - i, mod.inv(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 sign = mod.paritySign(k + 1);\n long numPhases = mod.inv(mod.subtract(1, prNoSpecial(k)));\n long e = mod.mult(numPhases, phaseSize);\n long term = mod.mult(mod.ncr(n, k), e);\n answer = mod.add(answer, mod.mult(sign, term));\n }\n\n out.println(answer);\n }\n\n private long prNoSpecial(int k) {\n return mod.div(mod.ncr(m + k - 1, k), mod.ncr(m + k, k));\n }\n\n }\n\n static class NumberTheory {\n private static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n public abstract static class Modulus> {\n final ArrayList factorial = new ArrayList<>();\n final ArrayList invFactorial = new ArrayList<>();\n\n public abstract long modulus();\n\n public Modulus() {\n super();\n factorial.add(1L);\n invFactorial.add(1L);\n }\n\n public long fact(int n) {\n while (factorial.size() <= n) {\n factorial.add(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.add(fInv[i]);\n }\n }\n\n return invFactorial.get(n);\n }\n\n public long paritySign(long k) {\n return (k & 1) == 0 ? 1 : modulus() - 1;\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 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... x) {\n long r = 1;\n for (long i : x)\n r = mult(r, i);\n return r;\n }\n\n public long mult(long a, long b) {\n return (a * b) % modulus();\n }\n\n public long div(long a, long b) {\n return mult(a, inv(b));\n }\n\n public long inv(long value) {\n long g = modulus(), x = 0, y = 1;\n for (long r = value; r != 0; ) {\n long q = g / r;\n g %= r;\n\n long temp = g;\n g = r;\n r = temp;\n\n x -= q * y;\n\n temp = x;\n x = y;\n y = temp;\n }\n\n ASSERT(g == 1);\n ASSERT(y == modulus() || y == -modulus());\n\n return normalize(x);\n }\n\n }\n\n public static class Mod998 extends NumberTheory.Modulus {\n public long modulus() {\n return 998_244_353L;\n }\n\n }\n\n }\n\n 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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "221743c0cf1bb8bc5f340c10f7ba4205", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.util.function.IntBinaryOperator;\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 GChattering solver = new GChattering();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GChattering {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int[] rs = new int[n];\n for (int i = 0; i < n; i++) {\n rs[i] = in.readInt();\n }\n\n if (n == 1) {\n out.println(0);\n return;\n }\n\n int[] leftTo = new int[3 * n];\n int[] rightTo = new int[3 * n];\n for (int i = 0; i < 3 * n; i++) {\n leftTo[i] = Math.max(0, i - rs[i % n]);\n rightTo[i] = Math.min(3 * n - 1, i + rs[i % n]);\n }\n\n int[] indexes = new int[3 * n];\n for (int i = 0; i < 3 * n; i++) {\n indexes[i] = i;\n }\n\n IntegerSparseTable leftST = new IntegerSparseTable(indexes, indexes.length, (a, b) -> leftTo[a] <= leftTo[b] ? a : b);\n IntegerSparseTable rightST = new IntegerSparseTable(indexes, indexes.length, (a, b) -> rightTo[a] >= rightTo[b] ? a : b);\n\n int[][] dpL = new int[20][3 * n];\n int[][] dpR = new int[20][3 * n];\n dpL[0] = leftTo;\n dpR[0] = rightTo;\n\n for (int i = 1; i < 20; i++) {\n for (int j = n; j < n * 2; j++) {\n int l = dpL[i - 1][j];\n int r = dpR[i - 1][j];\n int lIndex = leftST.query(l, r);\n int rIndex = rightST.query(l, r);\n l = Math.min(l, dpL[i - 1][lIndex]);\n l = Math.min(l, dpL[i - 1][rIndex]);\n r = Math.max(r, dpR[i - 1][lIndex]);\n r = Math.max(r, dpR[i - 1][rIndex]);\n dpL[i][j] = l;\n dpR[i][j] = r;\n }\n for (int j = 0; j < n; j++) {\n dpL[i][j] = Math.max(0, dpL[i][j + n] - n);\n dpR[i][j] = dpR[i][j + n] - n;\n }\n for (int j = 2 * n; j < 3 * n; j++) {\n dpL[i][j] = dpL[i][j - n] + n;\n dpR[i][j] = Math.min(3 * n - 1, dpR[i][j - n] + n);\n }\n }\n\n //System.err.println(Arrays.deepToString(dpL));\n // System.err.println(Arrays.deepToString(dpR));\n\n for (int i = n; i < 2 * n; i++) {\n int mask = 0;\n int ll = i;\n int rr = i;\n for (int j = 20 - 1; j >= 0; j--) {\n int l = ll;\n int r = rr;\n int lIndex = leftST.query(l, r);\n int rIndex = rightST.query(l, r);\n l = Math.min(l, dpL[j][lIndex]);\n l = Math.min(l, dpL[j][rIndex]);\n r = Math.max(r, dpR[j][lIndex]);\n r = Math.max(r, dpR[j][rIndex]);\n\n if (r - l + 1 < n) {\n mask = Bits.setBit(mask, j, true);\n ll = l;\n rr = r;\n }\n }\n\n out.println(mask + 1);\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 println(int 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 Bits {\n private Bits() {\n }\n\n public static 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 }\n\n static class IntegerSparseTable {\n private int[][] st;\n private IntBinaryOperator merger;\n\n public IntegerSparseTable(int[] data, int length, IntBinaryOperator merger) {\n int m = CachedLog2.floorLog(length);\n st = new int[m + 1][length];\n this.merger = merger;\n for (int i = 0; i < length; i++) {\n st[0][i] = data[i];\n }\n for (int i = 0; i < m; i++) {\n int interval = 1 << i;\n for (int j = 0; j < length; j++) {\n if (j + interval < length) {\n st[i + 1][j] = merge(st[i][j], st[i][j + interval]);\n } else {\n st[i + 1][j] = st[i][j];\n }\n }\n }\n }\n\n private int merge(int a, int b) {\n return merger.applyAsInt(a, b);\n }\n\n public int query(int left, int right) {\n int queryLen = right - left + 1;\n int bit = CachedLog2.floorLog(queryLen);\n // x + 2^bit == right + 1\n // So x should be right + 1 - 2^bit - left=queryLen - 2^bit\n return merge(st[bit][left], st[bit][right + 1 - (1 << bit)]);\n }\n\n public String toString() {\n return Arrays.toString(st[0]);\n }\n\n }\n\n static class CachedLog2 {\n private static final int BITS = 16;\n private static final int LIMIT = 1 << BITS;\n private static final byte[] CACHE = new byte[LIMIT];\n\n static {\n int b = 0;\n for (int i = 0; i < LIMIT; i++) {\n while ((1 << (b + 1)) <= i) {\n b++;\n }\n CACHE[i] = (byte) b;\n }\n }\n\n public static int floorLog(int x) {\n return x < LIMIT ? CACHE[x] : (BITS + CACHE[x >>> BITS]);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0251c4ba4520d08835c44e8a7cefd5fa", "src_uid": "e7dd44bf5e0a0345fd1c40e6957d5641", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "//package codeforces;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class D {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n StringTokenizer stringTokenizer;\n\n String next() throws IOException {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n stringTokenizer = new StringTokenizer(reader.readLine());\n }\n return stringTokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n int MOD = 1000 * 1000 * 1000 + 7;\n\n int sum(int a, int b) {\n a += b;\n return a >= MOD ? a - MOD : a;\n }\n\n int product(int a, int b) {\n return (int) (1l * a * b % MOD);\n }\n\n @SuppressWarnings(\"unchecked\")\n void solve() throws IOException {\n final int n = nextInt();\n final char[][] a = new char[n][];\n for (int i = 0; i < n; i++) {\n a[i] = next().toCharArray();\n }\n class Utils {\n int play(int i, int j) {\n int score = 0;\n if(a[i][j] == 'a') {\n score++;\n }\n if(a[i][j] == 'b') {\n score--;\n }\n if(i == n - 1 && j == n - 1) {\n return score;\n }\n if(i == n - 1) {\n return score + play(i, j + 1);\n }\n if(j == n - 1) {\n return score + play(i + 1, j);\n }\n if((i + j) % 2 == 1) {\n return score + Math.max(play(i + 1, j), play(i, j + 1));\n } else {\n return score + Math.min(play(i + 1, j), play(i, j + 1));\n }\n }\n }\n class CachedUtils extends Utils {\n int[][] cache = new int[n][n];\n boolean[][] hit = new boolean[n][n];\n \n @Override\n int play(int i, int j) {\n if(!hit[i][j]) {\n hit[i][j] = true;\n cache[i][j] = super.play(i, j);\n }\n return cache[i][j];\n }\n }\n int score = new CachedUtils().play(0, 0);\n writer.println(score == 0 ? \"DRAW\" : (score > 0 ? \"FIRST\" : \"SECOND\"));\n writer.close();\n }\n\n public static void main(String[] args) throws IOException {\n// new D().test();\n new D().solve();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "42f8b3b2c9b0974c596d21c5c1bd2e82", "src_uid": "d803fe167a96656f8debdc21edd988e4", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Task {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tpublic void solve() throws IOException {\n\t\tint n = in.nextInt();\n\t\tchar[][] a = new char[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = in.next().toCharArray();\n\t\t}\n\t\tlong[][] dp = new long[n][n];\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tfor (int j = n - 1; j >= 0; j--) {\n\t\t\t\tboolean aPlayer = (i + j) % 2 != 0;\n\t\t\t\tif (i == n - 1 && j == n - 1) {\n\t\t\t\t\tdp[i][j] = 0;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong min = Integer.MAX_VALUE;\n\t\t\t\tif (j < n - 1) {\n\t\t\t\t\tlong cur = dp[i][j + 1];\n\t\t\t\t\tlong score = 0;\n\t\t\t\t\tif (a[i][j + 1] == 'a') score++;\n\t\t\t\t\tif (a[i][j + 1] == 'b') score--;\n\t\t\t\t\tif (!aPlayer) score = -score;\n\t\t\t\t\tcur -= score;\n\t\t\t\t\tmin = Math.min(min, cur);\n\t\t\t\t}\n\t\t\t\tif (i < n - 1) {\n\t\t\t\t\tlong cur = dp[i + 1][j];\n\t\t\t\t\tlong score = 0;\n\t\t\t\t\tif (a[i + 1][j] == 'a') score++;\n\t\t\t\t\tif (a[i + 1][j] == 'b') score--;\n\t\t\t\t\tif (!aPlayer) score = -score;\n\t\t\t\t\tcur -= score;\n\t\t\t\t\tmin = Math.min(min, cur);\n\t\t\t\t}\n\t\t\t\tdp[i][j] = -min;\n\t\t\t}\n\t\t}\n\t\tdp[0][0] = -dp[0][0];\n\t\tif (a[0][0] == 'a') dp[0][0]++;\n\t\tif (a[0][0] == 'b') dp[0][0]--;\n\t\tif (dp[0][0] > 0) out.println(\"FIRST\");\n\t\telse if (dp[0][0] < 0) out.println(\"SECOND\");\n\t\telse out.println(\"DRAW\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new FastScanner();\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() {\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 (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\t}\n\n\tpublic static void main(String[] arg) {\n\t\tnew Task().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4d53241b46f35d0e67dc60da140fc7ba", "src_uid": "d803fe167a96656f8debdc21edd988e4", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class GameOnStrings {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\n\t\tn = Integer.parseInt(rd.readLine());\n\t\tboard = new char[n][n];\n\t\tfor(int i=0; i0){\n\t\t\tSystem.out.println(\"First\");\n\t\t\treturn;\n\t\t}\n\t\tfor(int i=0; i<=20; i++)\n\t\t\tfor(int j=0; j<=20; j++)\n\t\t\t\tfor(int k=0; k<=40; k++)\n\t\t\t\t\tArrays.fill(dp[i][j][k], -1);\n\t\tint secondWins = count2(0, 0, (board[0][0]=='a'? 1: 0), (board[0][0]=='b'? 1: 0));\n\t\tif(secondWins>0){\n\t\t\tSystem.out.println(\"Second\");\n\t\t}\n\t\telse\n\t\t\tSystem.out.println(\"Draw\");\n\t}\n\t\n\tstatic int count2(int x, int y, int A, int B){\n\t\tif(dp[x][y][A][B]!=-1){\n\t//\t\tSystem.out.println(x+\" \" +y+\" \"+A+\" \"+B+\" \"+dp[x][y][A][B]);\n\t\t\treturn dp[x][y][A][B];\n\t\t}\n\t\tint whoseTurn = (x+y+1)%2;\n\t\tif(x==n-1 && y==n-1){\n\t\t\tint ans = (AB? 1: 0);\n\t\t\treturn dp[x][y][A][B] = ans;\n\t\t}\n\t\tint choice1 = (x+1 0; layer--) {\n boolean first = layer % 2 == 0;\n\n for (int state = 0; state < next.length; state++) {\n Arrays.fill(nextMask, 0);\n\n char sel = 0;\n for (int row = 0; row < n; row++) {\n int bit = 1 << row;\n if ((state & bit) == 0) {\n continue;\n }\n\n int col = layer - row - 1;\n if (col < 0 || col > n - 1) {\n sel = 0;\n break;\n }\n\n if (sel == 0) {\n sel = t[row][col];\n }\n if (sel != t[row][col]) {\n sel = 0;\n break;\n }\n\n if (col < n - 1) {\n int ch = t[row][col + 1] - 'a';\n nextMask[ch] |= (1 << (row));\n }\n if (row < n - 1) {\n int ch = t[row + 1][col] - 'a';\n nextMask[ch] |= (1 << (row + 1));\n }\n }\n\n if (sel == 0) {\n continue;\n }\n\n int nonrelaxed = UNREACHABLE;\n for (int i = 0; i < nextMask.length; i++) {\n int mask = nextMask[i];\n if (mask == 0) {\n continue;\n }\n\n int add = getValue((char) ('a' + i));\n int from = curr[mask];\n if (from == UNREACHABLE) {\n continue;\n }\n\n if (nonrelaxed == UNREACHABLE) {\n nonrelaxed = from + add;\n } else if (first) {\n nonrelaxed = Math.max(nonrelaxed, from + add);\n } else {\n nonrelaxed = Math.min(nonrelaxed, from + add);\n }\n }\n next[state] = nonrelaxed;\n }\n\n int[] tmp = next;\n next = curr;\n curr = tmp;\n }\n\n int res = curr[1] + getValue(t[0][0]);\n if (res == 0) {\n out.println(\"DRAW\");\n } else {\n out.println(res > 0 ? \"FIRST\" : \"SECOND\");\n }\n }\n\n private int getValue(char c) {\n return c != 'a' ? c == 'b' ? -1 : 0 : 1;\n }\n\n public void run() {\n try {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n }\n\n public static void main(String[] arg) {\n new StringPlay().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4a676624298de743da338cbd13aac0a8", "src_uid": "d803fe167a96656f8debdc21edd988e4", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int p2 = 0;\n while ((1 << p2) - 1 <= n) ++p2;\n --p2;\n boolean[] parity = new boolean[(1 << p2) - 1];\n fillParity(parity, 0, parity.length - 1, false);\n int must = (1 << p2) - 1;\n for (int i = 0; i + 1 < parity.length; ++i) {\n if (parity[i] == parity[i + 1])\n ++must;\n }\n if (n == must) {\n out.println(1);\n } else if (n == must + 1) {\n out.println(2);\n } else if (n == must + 2) {\n out.println(1);\n } else {\n out.println(0);\n }\n }\n\n private void fillParity(boolean[] parity, int left, int right, boolean val) {\n int mid = (left + right) / 2;\n parity[mid] = val;\n if (left < right) {\n fillParity(parity, left, mid - 1, !val);\n fillParity(parity, mid + 1, right, val);\n }\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3278d95aaaa1702ae6ac821f1d6a1620", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.util.StringTokenizer;\nimport java.util.Map;\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 */\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 ESbalansirovannieDerevyaPoiska solver = new ESbalansirovannieDerevyaPoiska();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ESbalansirovannieDerevyaPoiska {\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n Map ans = new HashMap<>();\n\n int cur = 1;\n while (cur <= 1e6) {\n System.err.println(cur + \" \" + (cur + 1));\n ans.put(cur, 1);\n ans.put(cur + 1, 1);\n cur++;\n if (cur % 2 == 0) {\n cur *= 2;\n } else {\n cur = cur * 2 - 1;\n }\n }\n out.println(ans.get(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 FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "696a5800ebf6ad15954dc3b193379875", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n if (n == 2) {\n out.println(1);\n return;\n }\n\n int k = 0;\n while ((1 << k) - 1 <= n) {\n ++k;\n }\n --k;\n\n int need = (1 << k) - 1;\n for (int i = 0; i < 1 << (k - 1); i++) {\n if (i % 8 == 0 || i % 8 == 2 || i % 8 == 6) {\n ++need;\n }\n }\n\n out.println(n == need || n == need + 1 ? 1 : 0);\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b071024d6b2fe7b4ba6724b9d08212bb", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class e {\n\tstatic final long MOD = 998244353;\n\tpublic static void main(String[] args) {\n\t\tFS scan = new FS(System.in);\n\t\t\n\t\tint N = scan.nextInt();\n\t\tlong[][] sol = new long[2][N+1];\n\t\tsol[0][1] = 0;\n\t\tsol[1][1] = 1;\n\t\tsol[0][2] = 1;\n\t\tsol[1][2] = 0;\n\t\t\n\t\tfor(int i=3;i<=N;i++) {\n\t\t\t\n\t\t\tint root = (i+1) / 2;\n\t\t\tint left = root - 1;\n\t\t\tint right = i-root;\n\t\t\tint parity = root%2!=right%2 ? 1 : 0;\n\t\t\tif(root%2 == (parity^1) && right==1)sol[root%2][i] = 0;\n\t\t\telse\n\t\t\t\tsol[root%2][i] = (sol[(root%2) ^ 1][left] * sol[parity^(root%2)][right]);\n\t\t\t\n\t\t\tif(i%2 == 1)continue;\n\t\t\t\n\t\t\troot = root+1;\n\t\t\tleft = root-1;\n\t\t\tright = i-root;\n\t\t\tparity = root%2!=right%2 ? 1 : 0;\n\t\t\tif(root%2 == (parity^1) && right==1)sol[root%2][i] = 0;\n\t\t\telse\n\t\t\t\tsol[root%2][i] = (sol[(root%2) ^ 1][left] * sol[parity^(root%2)][right]);\n\t\t}\n\t\t\n\t\tSystem.out.println((sol[0][N]+sol[1][N])%MOD);\n\t}\n\t\n\tprivate static class FS {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FS(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.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\t}\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4672713a04cf4303ee249974b425731", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n public long[] prime;\n public long[] power;\n public int mod = 1000000007;\n public long[] dp;\n public int nzeros;\n public ArrayList> allowed;\n public HashMap, Long> hm;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] c = in.next().toCharArray();\n nzeros = 0;\n for (int i = 0; i < c.length; i++) {\n if (c[i] == '0') {\n nzeros++;\n }\n }\n int n = in.nextInt();\n prime = new long[n];\n power = new long[n];\n for (int i = 0; i < n; i++) {\n prime[i] = in.nextInt();\n power[i] = in.nextInt();\n }\n dp = new long[nzeros + 1];\n dp[0] = 1;\n\n allowed = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n if (prime[i] <= c.length) {\n ArrayList dd = new ArrayList<>();\n for (int j = 0; j < prime[i]; j++) {\n boolean bad = false;\n long d = 0;\n for (int k = j; k < c.length; k += prime[i]) {\n d |= 1L << k;\n if (c[k] == '1') {\n bad = true;\n }\n }\n if (!bad) {\n dd.add(d);\n }\n }\n allowed.add(dd);\n } else {\n long[] next = new long[dp.length];\n for (int j = 0; j < dp.length; j++) {\n // skip all\n next[j] = (next[j] + (prime[i] - c.length) * dp[j]) % mod;\n // hit exist\n next[j] = (next[j] + j * dp[j]) % mod;\n // hit new\n if (j + 1 < dp.length) {\n next[j + 1] = (next[j + 1] + (nzeros - j) * dp[j]) % mod;\n }\n }\n dp = next;\n }\n }\n hm = new HashMap<>();\n long nways = dfs(0, 0);\n for (int i = 0; i < n; i++)\n nways = nways * Utils.mod_exp(prime[i], power[i] - 1, mod) % mod;\n out.println(nways);\n }\n\n public long dfs(int index, long mask) {\n if (index == allowed.size()) {\n return dp[nzeros - Long.bitCount(mask)];\n }\n Pair ps = new Pair<>(index, mask);\n Long ret = hm.get(ps);\n if (ret != null) return ret;\n long ans = 0;\n for (long next : allowed.get(index)) {\n ans = (ans + dfs(index + 1, mask | next)) % mod;\n }\n hm.put(ps, ans);\n return ans;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n 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 Utils {\n public static long mod_exp(long b, long e, long mod) {\n long res = 1;\n while (e > 0) {\n if ((e & 1) == 1)\n res = (res * b) % mod;\n b = (b * b) % mod;\n e >>= 1;\n }\n return res;\n }\n\n }\n\n static class Pair, V extends Comparable> implements Comparable> {\n public final U u;\n public final V v;\n\n public Pair(U u, V v) {\n this.u = u;\n this.v = v;\n }\n\n public int hashCode() {\n return (u == null ? 0 : u.hashCode() * 31) + (v == null ? 0 : v.hashCode());\n }\n\n public boolean equals(Object o) {\n if (this == o)\n return true;\n if (o == null || getClass() != o.getClass())\n return false;\n Pair p = (Pair) o;\n return (u == null ? p.u == null : u.equals(p.u)) && (v == null ? p.v == null : v.equals(p.v));\n }\n\n public int compareTo(Pair b) {\n int cmpU = u.compareTo(b.u);\n return cmpU != 0 ? cmpU : v.compareTo(b.v);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3106cc43a1769e5369fe15fe25ecad79", "src_uid": "a0140a8fc4215acec5f046485bc2c7f9", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n public long[] prime;\n public long[] power;\n public int mod = 1000000007;\n public long[] dp;\n public int nzeros;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] c = in.next().toCharArray();\n nzeros = 0;\n for (int i = 0; i < c.length; i++) {\n if (c[i] == '0') {\n nzeros++;\n }\n }\n int n = in.nextInt();\n long mult = 1;\n prime = new long[n];\n power = new long[n];\n for (int i = 0; i < n; i++) {\n prime[i] = in.nextInt();\n power[i] = in.nextInt();\n mult = mult * Utils.mod_exp(prime[i], power[i] - 1, mod) % mod;\n }\n Arrays.sort(prime);\n int k = 0;\n while (k < n && prime[k] <= c.length) k++;\n dp = new long[nzeros + 1];\n dp[0] = 1;\n for (int i = k; i < n; i++) {\n long[] next = new long[dp.length];\n for (int j = 0; j < dp.length; j++) {\n // skip all\n next[j] = (next[j] + (prime[i] - c.length) * dp[j]) % mod;\n // hit exist\n next[j] = (next[j] + (nzeros - j) * dp[j]) % mod;\n // hit new\n if (j > 0) {\n next[j] = (next[j] + j * dp[j - 1]) % mod;\n }\n }\n dp = next;\n }\n HashMap dp2 = new HashMap<>();\n dp2.put(0L, 1);\n for (int i = 0; i < k; i++) {\n HashMap next = new HashMap<>();\n for (int j = 0; j < prime[i]; j++) {\n boolean bad = false;\n long d = 0;\n for (int w = j; w < c.length; w += prime[i]) {\n d |= 1L << w;\n if (c[w] == '1') {\n bad = true;\n }\n }\n if (!bad) {\n dp2.forEach((x,v) -> {\n long nk = x | d;\n next.put(nk, (v+next.getOrDefault(nk, 0)) % mod);\n });\n }\n }\n dp2 = next;\n }\n long nways = 0;\n dp2.forEach((x,v) -> nways = (nways + dp[nzeros - Long.bitCount(x)] * v) % mod);\n nways = nways * mult % mod;\n out.println(nways);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class Utils {\n public static long mod_exp(long b, long e, long mod) {\n long res = 1;\n while (e > 0) {\n if ((e & 1) == 1)\n res = (res * b) % mod;\n b = (b * b) % mod;\n e >>= 1;\n }\n return res;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d4aaa2f22c8eb061cfeadd8ddd450c14", "src_uid": "a0140a8fc4215acec5f046485bc2c7f9", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n public long[] prime;\n public long[] power;\n public int mod = 1000000007;\n public long[] dp;\n public int nzeros;\n public ArrayList> allowed;\n public HashMap, Integer> hm;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] c = in.next().toCharArray();\n nzeros = 0;\n for (int i = 0; i < c.length; i++) {\n if (c[i] == '0') {\n nzeros++;\n }\n }\n int n = in.nextInt();\n prime = new long[n];\n power = new long[n];\n for (int i = 0; i < n; i++) {\n prime[i] = in.nextInt();\n power[i] = in.nextInt();\n }\n dp = new long[nzeros + 1];\n dp[0] = 1;\n allowed = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n if (prime[i] <= c.length) {\n ArrayList dd = new ArrayList<>();\n for (int j = 0; j < prime[i]; j++) {\n boolean bad = false;\n long d = 0;\n for (int k = j; k < c.length; k += prime[i]) {\n d |= 1L << k;\n if (c[k] == '1') {\n bad = true;\n }\n }\n if (!bad) {\n dd.add(d);\n }\n }\n allowed.add(dd);\n } else {\n long[] next = new long[dp.length];\n for (int j = 0; j < dp.length; j++) {\n // skip all\n next[j] = (next[j] + (prime[i] - c.length) * dp[j]) % mod;\n // hit exist\n next[j] = (next[j] + (nzeros - j) * dp[j]) % mod;\n // hit new\n if (j > 0) {\n next[j] = (next[j] + j * dp[j - 1]) % mod;\n }\n }\n dp = next;\n }\n }\n hm = new HashMap<>();\n long nways = dfs(0, 0);\n for (int i = 0; i < n; i++)\n nways = nways * Utils.mod_exp(prime[i], power[i] - 1, mod) % mod;\n out.println(nways);\n }\n\n public int dfs(int index, long mask) {\n if (index == allowed.size()) {\n return (int)dp[nzeros - Long.bitCount(mask)];\n }\n Pair ps = new Pair<>(index, mask);\n Long ret = hm.get(ps);\n if (ret != null) return ret;\n int ans = 0;\n for (long next : allowed.get(index)) {\n ans = (ans + dfs(index + 1, mask | next)) % mod;\n }\n hm.put(ps, ans);\n return ans;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n 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 Utils {\n public static long mod_exp(long b, long e, long mod) {\n long res = 1;\n while (e > 0) {\n if ((e & 1) == 1)\n res = (res * b) % mod;\n b = (b * b) % mod;\n e >>= 1;\n }\n return res;\n }\n\n }\n\n static class Pair, V extends Comparable> implements Comparable> {\n public final U u;\n public final V v;\n\n public Pair(U u, V v) {\n this.u = u;\n this.v = v;\n }\n\n public int hashCode() {\n return (u == null ? 0 : u.hashCode() * 31) + (v == null ? 0 : v.hashCode());\n }\n\n public boolean equals(Object o) {\n if (this == o)\n return true;\n if (o == null || getClass() != o.getClass())\n return false;\n Pair p = (Pair) o;\n return (u == null ? p.u == null : u.equals(p.u)) && (v == null ? p.v == null : v.equals(p.v));\n }\n\n public int compareTo(Pair b) {\n int cmpU = u.compareTo(b.u);\n return cmpU != 0 ? cmpU : v.compareTo(b.v);\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ecc21de60c35e7cc2f95e29a7e3101d3", "src_uid": "a0140a8fc4215acec5f046485bc2c7f9", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n public long[] prime;\n public long[] power;\n public int mod = 1000000007;\n public long[] dp;\n public int nzeros;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] c = in.next().toCharArray();\n nzeros = 0;\n for (int i = 0; i < c.length; i++) {\n if (c[i] == '0') {\n nzeros++;\n }\n }\n int n = in.nextInt();\n long mult = 1;\n prime = new long[n];\n power = new long[n];\n for (int i = 0; i < n; i++) {\n prime[i] = in.nextInt();\n power[i] = in.nextInt();\n mult = mult * Utils.mod_exp(prime[i], power[i] - 1, mod) % mod;\n }\n Arrays.sort(prime);\n int k = 0;\n while (k < n && prime[k] <= c.length) k++;\n dp = new long[nzeros + 1];\n dp[0] = 1;\n for (int i = k; i < n; i++) {\n long[] next = new long[dp.length];\n for (int j = 0; j < dp.length; j++) {\n // skip all\n next[j] = (next[j] + (prime[i] - c.length) * dp[j]) % mod;\n // hit exist\n next[j] = (next[j] + (nzeros - j) * dp[j]) % mod;\n // hit new\n if (j > 0) {\n next[j] = (next[j] + j * dp[j - 1]) % mod;\n }\n }\n dp = next;\n }\n HashMap dp2 = new HashMap<>();\n dp2.put(0L, 1);\n for (int i = 0; i < k; i++) {\n HashMap next = new HashMap<>();\n for (int j = 0; j < prime[i]; j++) {\n boolean bad = false;\n long d = 0;\n for (int w = j; w < c.length; w += prime[i]) {\n d |= 1L << w;\n if (c[w] == '1') {\n bad = true;\n }\n }\n if (!bad) {\n dp2.forEach((x,v) -> {\n long nk = x | d;\n next.put(nk, (v+next.getOrDefault(nk, 0)) % mod);\n });\n }\n }\n dp2 = next;\n }\n long nways = dp2.entrySet().stream().mapToLong((x) -> dp[nzeros - Long.bitCount(x.getKey())] * x.getValue() % mod).sum() % mod;\n nways = nways * mult % mod;\n out.println(nways);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class Utils {\n public static long mod_exp(long b, long e, long mod) {\n long res = 1;\n while (e > 0) {\n if ((e & 1) == 1)\n res = (res * b) % mod;\n b = (b * b) % mod;\n e >>= 1;\n }\n return res;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6df4a3ec9b1ac0887a42e02fb501b7ae", "src_uid": "a0140a8fc4215acec5f046485bc2c7f9", "difficulty": 3200.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n FastScanner in;\n PrintWriter out;\n\n long mod = (long) 1e9 + 7;\n\n void solve() {\n// for (int i = 1; i <= 10; i++) {\n// for (int j = 1; j <= 10; j++) {\n// System.err.print(sol2(i, j) - sol3(i, j) + \" \");\n// }\n// System.err.println();\n// }\n out.println(sol2(in.nextInt(), in.nextInt()));\n }\n\n long sol2(int n, int m) {\n long res = 0;\n long[][] dp01 = new long[m + 1][n + 1];\n long[][] dp01Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp01[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp01Sum[w][h] = (dp01Sum[w - 1][h] + dp01[w][h - 1]) % mod;\n dp01[w][h] = (dp01[w - 1][h] + dp01Sum[w][h]) % mod;\n }\n long[][] dp1 = new long[m + 1][n + 1];\n long[][] dp1Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp1[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp1Sum[w][h] = (dp1Sum[w - 1][h] + dp01[w - 1][h - 1]) % mod;\n dp1[w][h] = (dp1[w - 1][h] + dp1Sum[w][h] + dp01[w - 1][h - 1]) % mod;\n// for (int w1 = 2; w1 < w; w1++) {\n// dp1[w][h] = (dp1[w][h] + (dp01[w1][h - 1] * (w - w1 + 1))\n// % mod)\n// % mod;\n// }\n }\n long[][] dpSum01 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++)\n dpSum01[w][h] = (dpSum01[w][h - 1] + dp01[w][h]) % mod;\n long[][] dpSum1 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++)\n dpSum1[w][h] = (dpSum1[w][h - 1] + dp1[w][h]) % mod;\n for (int h1 = 1; h1 <= n; h1++)\n for (int w1 = 1; w1 <= m; w1++) {\n long curRes = (dpSum01[w1][h1] * dpSum1[w1][n - h1 + 1]) % mod;\n curRes = (curRes * (m - w1 + 1)) % mod;\n res = (res + curRes) % mod;\n }\n return res;\n }\n\n long sol3(int n, int m) {\n long res = 0;\n long[][] dp01 = new long[m + 1][n + 1];\n long[][] dp01Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp01[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp01Sum[w][h] = (dp01Sum[w - 1][h] + dp01[w][h - 1]) % mod;\n dp01[w][h] = (dp01[w - 1][h] + dp01Sum[w][h]) % mod;\n }\n long[][] dp1 = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp1[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n for (int w1 = 2; w1 < w; w1++) {\n dp1[w][h] = (dp1[w][h] + (dp01[w1][h - 1] * (w - w1 + 1))\n % mod)\n % mod;\n }\n }\n long[][] dp3 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++) {\n for (int h1 = 1; h1 <= h; h1++) {\n dp3[w][h] = (dp3[w][h] + (dp01[w][h1] * dp1[w][h - h1 + 1])\n % mod)\n % mod;\n\n }\n // dp3[w][h] = dp3[w][h - 1] + dp01[w][h] * dp1[w][h - h + 1];\n }\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++) {\n long curRes = (dp3[w][h] * (n - h + 1)) % mod;\n curRes = (curRes * (m - w + 1)) % mod;\n res = (res + curRes) % mod;\n }\n return res;\n }\n\n int stupid(int n, int m) {\n int total = n * m;\n int sum = 0;\n boolean[][] field = new boolean[n][m];\n for (int st = 0; st < (1 << total); st++) {\n int it = 0;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n if (((1 << it++) & st) != 0)\n field[i][j] = true;\n else\n field[i][j] = false;\n int l = -1, r = -1;\n boolean ok = true;\n int[] first = new int[n];\n int[] last = new int[n];\n Arrays.fill(first, -1);\n Arrays.fill(last, -1);\n for (int i = 0; i < n; i++) {\n int cnt = 0;\n for (int j = 0; j < m; j++)\n if (field[i][j]) {\n if (cnt == 0)\n first[i] = j;\n last[i] = j;\n cnt++;\n }\n if (cnt != 2 && cnt != 0)\n ok = false;\n if (cnt == 2) {\n r = i;\n if (l == -1)\n l = i;\n }\n }\n if (!ok)\n continue;\n if (l == -1 || r == -1)\n continue;\n for (int i = l; i <= r; i++)\n if (first[i] == -1 || last[i] == -1 || first[i] == last[i])\n ok = false;\n if (!ok)\n continue;\n boolean ok2 = false;\n for (int t = l; t <= r; t++) {\n boolean ok3 = true;\n for (int i = l; i < t; i++) {\n if (first[i] < first[i + 1] || last[i] > last[i + 1])\n ok3 = false;\n }\n for (int i = r; i > t; i--)\n if (first[i] < first[i - 1] || last[i] > last[i - 1])\n ok3 = false;\n if (ok3)\n ok2 = true;\n }\n if (ok2)\n sum++;\n }\n return sum;\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"test.in\"));\n out = new PrintWriter(new File(\"test.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n }\n\n public static void main(String[] args) {\n new CF().runIO();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7d217e6742690d48c910cd57251e729", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n// test();\n int n = in.nextInt();\n int m = in.nextInt();\n out.println(solve(n, m));\n// if (solve(n, m) != solveStupid(n, m)) {\n// throw new AssertionError();\n// }\n }\n\n static final int MOD = 1000000007;\n\n static int solve(int n, int m) {\n int[][] dp = new int[m][n + 1];\n int[][] dp2 = new int[m][n + 1];\n dp[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n int s = 0;\n int ss = 0;\n dp[0][i] = 1;\n for (int j = 1; j < m; j++) {\n dp2[j][i] = (ss + s + 1) % MOD;\n s += dp[j][i - 1];\n if (s >= MOD) {\n s -= MOD;\n }\n ss += s;\n if (ss >= MOD) {\n ss -= MOD;\n }\n dp[j][i] = (ss + 1) % MOD;\n }\n }\n int ans = 0;\n for (int i = 0; i < n; i++) {\n int cur = 0;\n for (int j = 1; j < m; j++) {\n cur = (int) ((cur + (long) dp[j][i + 1] * dp2[j][n - i] % MOD * (m - j)) % MOD);\n }\n ans += cur;\n if (ans >= MOD) {\n ans -= MOD;\n }\n }\n return ans;\n }\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 >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n }\n\nclass FastPrinter extends PrintWriter {\n\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public FastPrinter(Writer out) {\n super(out);\n }\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0dfd131909146d188b16174aa8f5b924", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "package main;\n\nimport main.Parser;\nimport main.OutputWriter;\n\npublic class TaskD {\n int mod = 1000000007;\n long[][] sum1d = new long[3000][3000];\n long[][] sum2d = new long[3000][3000];\n\n public void solve(int testNumber, Parser in, OutputWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n for (int rows = 0; rows <= n; rows++) {\n for (int i = 2; i <= m; i++) {\n sum1d[rows][i] = (rows==0) ? 1 : sum2d[rows-1][i]+1;\n if (i != 0) sum1d[rows][i] += sum1d[rows][i-1];\n\n sum2d[rows][i] = sum1d[rows][i];\n if (i != 0) sum2d[rows][i] += sum2d[rows][i-1];\n }\n }\n\n\n long tot = 0;\n for (int i = 0; i < n; i++) {\n for (int mid = 2; mid <= m; mid++) {\n // res=(res+(((((pd[w][t][1]-pd[w][t-1][1]+M)%M)*pd[w][n-t+1][1])%M)*(m-w+1))%M)%M;\n long top = (i==0) ? 1 : (sum2d[i-1][mid-1]+sum1d[i-1][mid-1]+1);\n long bot = (n-i-1==0) ? 1 : sum2d[n-i-2][mid]+1;\n\n bot = (bot * top) % mod;\n bot = (bot * (m-mid+1)) % mod;\n tot = (tot + bot) % mod;\n }\n }\n\n out.println(tot);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "75915b275c77158f79b8e8ecdc6a1013", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n FastScanner in;\n PrintWriter out;\n\n long mod = (long) 1e9 + 7;\n\n void solve() {\n// for (int i = 1; i <= 10; i++) {\n// for (int j = 1; j <= 10; j++) {\n// System.err.print(sol2(i, j) - sol3(i, j) + \" \");\n// }\n// System.err.println();\n// }\n out.println(sol2(in.nextInt(), in.nextInt()));\n }\n\n long sol2(int n, int m) {\n long res = 0;\n long[][] dp01 = new long[m + 1][n + 1];\n long[][] dp01Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp01[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp01Sum[w][h] = (dp01Sum[w - 1][h] + dp01[w][h - 1]) % mod;\n dp01[w][h] = (dp01[w - 1][h] + dp01Sum[w][h]) % mod;\n }\n long[][] dp1 = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp1[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n for (int w1 = 2; w1 < w; w1++) {\n dp1[w][h] = (dp1[w][h] + (dp01[w1][h - 1] * (w - w1 + 1))\n % mod)\n % mod;\n }\n }\n long[][] dpSum01 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++)\n dpSum01[w][h] = (dpSum01[w][h - 1] + dp01[w][h]) % mod;\n long[][] dpSum1 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++)\n dpSum1[w][h] = (dpSum1[w][h - 1] + dp1[w][h]) % mod;\n for (int h1 = 1; h1 <= n; h1++)\n for (int w1 = 1; w1 <= m; w1++) {\n long curRes = (dpSum01[w1][h1] * dpSum1[w1][n - h1 + 1]) % mod;\n curRes = (curRes * (m - w1 + 1)) % mod;\n res = (res + curRes) % mod;\n }\n return res;\n }\n \n long sol3(int n, int m) {\n long res = 0;\n long[][] dp01 = new long[m + 1][n + 1];\n long[][] dp01Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp01[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp01Sum[w][h] = (dp01Sum[w-1][h] + dp01[w][h - 1]) % mod;\n dp01[w][h] = (dp01[w - 1][h] + dp01Sum[w][h]) % mod;\n } \n long[][] dp1 = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp1[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n for (int w1 = 2; w1 < w; w1++) {\n dp1[w][h] = (dp1[w][h] + (dp01[w1][h - 1] * (w - w1 + 1))\n % mod)\n % mod;\n }\n }\n long[][] dp3 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++) {\n for (int h1 = 1; h1 <= h; h1++) {\n dp3[w][h] = (dp3[w][h] + (dp01[w][h1] * dp1[w][h - h1 + 1])\n % mod)\n % mod;\n\n }\n// dp3[w][h] = dp3[w][h - 1] + dp01[w][h] * dp1[w][h - h + 1];\n }\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++) {\n long curRes = (dp3[w][h] * (n - h + 1) ) % mod;\n curRes = (curRes * (m - w +1)) % mod;\n res = (res + curRes) % mod;\n }\n return res;\n }\n\n int stupid(int n, int m) {\n int total = n * m;\n int sum = 0;\n boolean[][] field = new boolean[n][m];\n for (int st = 0; st < (1 << total); st++) {\n int it = 0;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n if (((1 << it++) & st) != 0)\n field[i][j] = true;\n else\n field[i][j] = false;\n int l = -1, r = -1;\n boolean ok = true;\n int[] first = new int[n];\n int[] last = new int[n];\n Arrays.fill(first, -1);\n Arrays.fill(last, -1);\n for (int i = 0; i < n; i++) {\n int cnt = 0;\n for (int j = 0; j < m; j++)\n if (field[i][j]) {\n if (cnt == 0)\n first[i] = j;\n last[i] = j;\n cnt++;\n }\n if (cnt != 2 && cnt != 0)\n ok = false;\n if (cnt == 2) {\n r = i;\n if (l == -1)\n l = i;\n }\n }\n if (!ok)\n continue;\n if (l == -1 || r == -1)\n continue;\n for (int i = l; i <= r; i++)\n if (first[i] == -1 || last[i] == -1 || first[i] == last[i])\n ok = false;\n if (!ok)\n continue;\n boolean ok2 = false;\n for (int t = l; t <= r; t++) {\n boolean ok3 = true;\n for (int i = l; i < t; i++) {\n if (first[i] < first[i + 1] || last[i] > last[i + 1])\n ok3 = false;\n }\n for (int i = r; i > t; i--)\n if (first[i] < first[i - 1] || last[i] > last[i - 1])\n ok3 = false;\n if (ok3)\n ok2 = true;\n }\n if (ok2)\n sum++;\n }\n return sum;\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"test.in\"));\n out = new PrintWriter(new File(\"test.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n }\n\n public static void main(String[] args) {\n new CF().runIO();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1fdfa0647404586fd3573df0855e70bc", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.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\tReader in = new Reader(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, Reader in, PrintWriter out) {\n char[] a = in.nextLine().toCharArray();\n int res = 0;\n for (char q : a) {\n if (q >= 'A' && q <= 'Z') res += (q - 'A' + 1);\n if (q >= 'a' && q <= 'z') res -= (q - 'a' + 1);\n }\n out.println(res);\n }\n}\n\nclass Reader {\n private BufferedReader in;\n\n public Reader(InputStream is) {\n in = new BufferedReader(new InputStreamReader(is));\n }\n\n public String nextLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "90ad96a48dde87865b2f8f33abba07b8", "src_uid": "d3fa5a3a008048dc4a9fbce1ebc61d67", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "/*\n * Code Author: Sanket Udgirkar.\n * DA-IICT\n */\nimport java.util.*;\nimport java.io.*;\n\nimport javax.swing.plaf.synth.SynthSpinnerUI;\npublic class Tester\n{\n\tpublic static long mod;\n\t\n\tpublic static void main(String[] args) \n\t{\n\t\tInputReader s=new InputReader(System.in);\n OutputStream outputStream = System.out;\n //PrintWriter out=new PrintWriter(outputStream);\n \n String str=s.nextLine();\n int ans=0;\n \n for(int i=0; i=65 && (int)str.charAt(i)<=90)\n \t\tans=ans+((int)str.charAt(i)-64);\n \telse if((int)str.charAt(i)>=97 && (int)str.charAt(i)<=122)\n \t\tans=ans-((int)str.charAt(i)-96);\n }\n \n System.out.println(ans);\n \n //out.close();\n\t} \n\n\tstatic long gcd(long a,long b)\n\t{\n\t\tif(b==0)\n\t\t\treturn a;\n\t\ta%=b;\n\t\treturn gcd(b,a);\n\t}\n\t\n\tstatic long exp(long a, long b)\n\t{\n\t\tif(b==0)\n\t\t\treturn 1;\n\t\tif(b==1)\n\t\t\treturn a;\n\t\tif(b==2)\n\t\t\treturn a*a;\n\t\t\n\t\tif(b%2==0)\n\t\t\treturn exp(exp(a,b/2),2);\n\t\telse\n\t\t\treturn a*exp(exp(a,(b-1)/2),2);\n\t}\n\t\n\tstatic class Pair implements Comparable\n\t{\n\t\tlong x,f;\n\t\tPair(long ii, long cc)\n\t\t{\n\t\t\tx=ii;\n\t\t\tf=cc;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Pair o) \n\t\t{\n\t\t\treturn Long.compare(this.x, o.x);\n\t\t}\n\t\t\n\t}\n\n public static class InputReader \n {\n \tpublic BufferedReader reader;\n \tpublic StringTokenizer tokenizer;\n \n \tpublic InputReader(InputStream inputstream) \n \t{\n \t reader = new BufferedReader(new InputStreamReader(inputstream));\n \t tokenizer = null;\n \t}\n \t \n \tpublic String nextLine()\n \t{\n \t String fullLine=null;\n \t while (tokenizer == null || !tokenizer.hasMoreTokens()) \n \t {\n \t try\n \t {\n \t \tfullLine=reader.readLine();\n \t } \n \t catch (IOException e) \n \t {\n \t throw new RuntimeException(e);\n \t }\n \t return fullLine;\n \t }\n \t return fullLine;\n \t}\n \t\t\n \tpublic String next() \n \t{\n \t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) \n \t\t{\n \t\t\ttry\n \t\t\t{\n \t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n \t\t\t}\n \t\t\tcatch (IOException e) \n \t\t\t\t{\n \t\t\t\t\tthrow new RuntimeException(e);\n \t\t\t\t}\n \t\t\t}\n \t\treturn tokenizer.nextToken();\n \t}\n \t\t\n \tpublic long nextLong() \n \t{\n \t\treturn Long.parseLong(next());\n \t}\n \t\t\n \tpublic int nextInt() \n \t{\n \t\treturn Integer.parseInt(next());\n \t}\n \t \n \tpublic int[] nextIntArray(int n)\n \t{\n \t\tint a[] = new int[n];\n \t\t\n \t\tfor (int i = 0; i < n; i++)\n \t\t\t\ta[i] = nextInt();\n \t\t\t\n \t\treturn a;\n \t}\n \t\n \tpublic void printArray(int x[])\n \t{\n \t\tfor(int i=0; i='a'&&s.charAt(i)<='z')\n res-=s.charAt(i)-'a'+1;\n else\n if(s.charAt(i)>='A'&&s.charAt(i)<='Z')\n res+=s.charAt(i)-'A'+1;\n out.println(res);\n\n }\n\n public static void main(String[] args) throws IOException {\n new C().run();\n }\n\n void run() throws IOException {\n reader = new BufferedReader(new InputStreamReader(System.in));\n//\t\treader = new BufferedReader(new FileReader(\"input.txt\"));\n tokenizer = null;\n out = new PrintWriter(new OutputStreamWriter(System.out));\n//\t\tout = new PrintWriter(new FileWriter(\"output.txt\"));\n solve();\n reader.close();\n out.flush();\n\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter out;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce2a2ed2d0fda03780556fa38aefebdb", "src_uid": "d3fa5a3a008048dc4a9fbce1ebc61d67", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class SPENCERISGOD {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tboolean spencerIsGod = true;\n\t\twhile (spencerIsGod) { //AKA always\n\t\t\tSystem.out.println(\"ALL PRAISE TO SPENCER, OUR LORD AND SAVIOR, CREATOR OF THE SACRED THREE LOOP. HE HAS DELIVERED US FROM OUR PROCEDURAL PROGRAMMING, AND SHOWED US THE LIGHT OF OBJECT-ORIENTED. MAY HIS CODE FOREVER BE AS PERFECT AS HE IS, FOREVER AND EVER, A-JAVA.\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "617fdca51b51c37373b5f252a52641e2", "src_uid": "d3fa5a3a008048dc4a9fbce1ebc61d67", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "//Utilities\r\nimport java.io.*;\r\nimport java.util.*;\r\n\r\npublic class a {\r\n\tstatic int t;\r\n\tstatic int n, k;\r\n\tstatic ComboMod c;\r\n\tstatic long[][] dp;\r\n\tstatic final int MOD = 998244353;\r\n\t\r\n\tpublic static void main(String[] args) throws IOException {\r\n\t\tt = 1;\r\n\t\twhile (t-- > 0) {\r\n\t\t\tn = in.iscan(); k = in.iscan();\r\n\t\t\tc = new ComboMod(n, MOD);\r\n\t\t\tdp = new long[n][k+1];\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tfor (int j = 0; j <= k; j++) {\r\n\t\t\t\t\tdp[i][j] = -1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tout.println(attack(0, 1));\r\n\t\t}\r\n\t\tout.close();\r\n\t}\r\n\t\r\n\tstatic long attack(int i, int j) {\r\n\t\tif (dp[i][j] != -1) {\r\n\t\t\treturn dp[i][j];\r\n\t\t}\r\n\t\tif (j == k) {\r\n\t\t\treturn dp[i][j] = 1;\r\n\t\t}\r\n\t\tlong ret = 0;\r\n\t\tfor (int cnt = 0; i + cnt < n; cnt++) {\r\n\t\t\tlong e = cnt * i + (cnt - 1) * cnt / 2;\r\n\t\t\tlong add = c.ncr(n - 1 - i, cnt) * UTILITIES.fast_pow_mod(k-j+1, e, MOD) % MOD * attack(i + cnt, j+1) % MOD;\r\n\t\t\tret = (ret + add) % MOD;\r\n\t\t}\r\n\t\treturn dp[i][j] = ret;\r\n\t}\r\n\t\r\n\tstatic class ComboMod {\r\n\t\tint n, MOD;\r\n\t\tlong[] fac, facinv, inv;\r\n\r\n\t\tComboMod(int n, int MOD) {\r\n\t\t\tthis.n = n; this.MOD = MOD;\r\n\t\t\tfac = new long[n+1]; facinv = new long[n+1]; inv = new long[n+1];\r\n\t\t fac[0] = facinv[0] = 1; inv[1] = 1;\r\n\t\t for (int i = 2; i <= n; i++) {\r\n\t\t \tinv[i] = (inv[MOD % i] * (-MOD / i) % MOD + MOD) % MOD;\r\n\t\t }\r\n\t\t for(int i = 1; i <= n; i++){\r\n\t\t fac[i] = fac[i-1] * i % MOD;\r\n\t\t facinv[i] = facinv[i-1] * inv[i] % MOD;\r\n\t\t }\r\n\t\t}\r\n\t\tlong fac(int n) { return fac[n]; }\r\n\t\tlong facinv(int n) { return facinv[n]; }\r\n\t\tlong inv(int n) { return inv[n]; }\r\n\t\tlong ncr(int n, int k) { return n < k || k < 0 ? 0 : fac[n] * facinv[k] % MOD * facinv[n-k] % MOD; }\r\n\t}\r\n\t\r\n\tstatic INPUT in = new INPUT(System.in);\r\n\tstatic PrintWriter out = new PrintWriter(System.out);\r\n\tprivate static class INPUT {\r\n\r\n\t\tprivate InputStream stream;\r\n\t\tprivate byte[] buf = new byte[1024];\r\n\t\tprivate int curChar, numChars;\r\n\r\n\t\tpublic INPUT (InputStream stream) {\r\n\t\t\tthis.stream = stream;\r\n\t\t}\r\n\r\n\t\tpublic INPUT (String file) throws IOException {\r\n\t\t\tthis.stream = new FileInputStream (file);\r\n\t\t}\r\n\r\n\t\tpublic int cscan () 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}\r\n\t\t\t\r\n\t\t\tif (numChars == -1)\r\n\t\t\t\treturn numChars;\r\n\r\n\t\t\treturn buf[curChar++];\r\n\t\t}\r\n\r\n\t\tpublic int iscan () throws IOException {\r\n\t\t\tint c = cscan (), sgn = 1;\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tint res = 0;\r\n\r\n\t\t\tdo {\r\n\t\t\t\tres = (res << 1) + (res << 3);\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\t\t\twhile (!space (c));\r\n\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic String sscan () throws IOException {\r\n\t\t\tint c = cscan ();\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tStringBuilder res = new StringBuilder ();\r\n\r\n\t\t\tdo {\r\n\t\t\t\tres.appendCodePoint (c);\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\t\t\twhile (!space (c));\r\n\r\n\t\t\treturn res.toString ();\r\n\t\t}\r\n\r\n\t\tpublic double dscan () throws IOException {\r\n\t\t\tint c = cscan (), sgn = 1;\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tdouble res = 0;\r\n\r\n\t\t\twhile (!space (c) && c != '.') {\r\n\t\t\t\tif (c == 'e' || c == 'E')\r\n\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\r\n\t\t\t\t\r\n\t\t\t\tres *= 10;\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tif (c == '.') {\r\n\t\t\t\tc = cscan ();\r\n\t\t\t\tdouble m = 1;\r\n\r\n\t\t\t\twhile (!space (c)) {\r\n\t\t\t\t\tif (c == 'e' || c == 'E')\r\n\t\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\r\n\r\n\t\t\t\t\tm /= 10;\r\n\t\t\t\t\tres += (c - '0') * m;\r\n\t\t\t\t\tc = cscan ();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic long lscan () throws IOException {\r\n\t\t\tint c = cscan (), sgn = 1;\r\n\t\t\t\r\n\t\t\twhile (space (c))\r\n\t\t\t\tc = cscan ();\r\n\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\r\n\t\t\tlong res = 0;\r\n\r\n\t\t\tdo {\r\n\t\t\t\tres = (res << 1) + (res << 3);\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = cscan ();\r\n\t\t\t}\r\n\t\t\twhile (!space (c));\r\n\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic boolean space (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\tpublic static class UTILITIES {\r\n\r\n\t\tstatic final double EPS = 10e-6;\r\n\t\t\r\n\t\tpublic static void sort(int[] a, boolean increasing) {\r\n\t\t\tArrayList arr = new ArrayList();\r\n\t\t\tint n = a.length;\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr.add(a[i]);\r\n\t\t\t}\r\n\t\t\tCollections.sort(arr);\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tif (increasing) {\r\n\t\t\t\t\ta[i] = arr.get(i);\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\ta[i] = arr.get(n-1-i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void sort(long[] a, boolean increasing) {\r\n\t\t\tArrayList arr = new ArrayList();\r\n\t\t\tint n = a.length;\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr.add(a[i]);\r\n\t\t\t}\r\n\t\t\tCollections.sort(arr);\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tif (increasing) {\r\n\t\t\t\t\ta[i] = arr.get(i);\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\ta[i] = arr.get(n-1-i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void sort(double[] a, boolean increasing) {\r\n\t\t\tArrayList arr = new ArrayList();\r\n\t\t\tint n = a.length;\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr.add(a[i]);\r\n\t\t\t}\r\n\t\t\tCollections.sort(arr);\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tif (increasing) {\r\n\t\t\t\t\ta[i] = arr.get(i);\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\ta[i] = arr.get(n-1-i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic static int lower_bound (int[] arr, int x) {\r\n\t\t\tint low = 0, high = arr.length, mid = -1;\r\n\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\r\n\t\t\t\tif (arr[mid] >= x)\r\n\t\t\t\t\thigh = mid;\r\n\t\t\t\telse\r\n\t\t\t\t\tlow = mid + 1;\r\n\t\t\t}\r\n\r\n\t\t\treturn low;\r\n\t\t}\r\n\r\n\t\tpublic static int upper_bound (int[] arr, int x) {\r\n\t\t\tint low = 0, high = arr.length, mid = -1;\r\n\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\r\n\t\t\t\tif (arr[mid] > x)\r\n\t\t\t\t\thigh = mid;\r\n\t\t\t\telse\r\n\t\t\t\t\tlow = mid + 1;\r\n\t\t\t}\r\n\r\n\t\t\treturn low;\r\n\t\t}\r\n\t\t\r\n\t\tpublic static void updateMap(HashMap map, int key, int v) {\r\n\t\t\tif (!map.containsKey(key)) {\r\n\t\t\t\tmap.put(key, v);\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tmap.put(key, map.get(key) + v);\r\n\t\t\t}\r\n\t\t\tif (map.get(key) == 0) {\r\n\t\t\t\tmap.remove(key);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic static long gcd (long a, long b) {\r\n\t\t\treturn b == 0 ? a : gcd (b, a % b);\r\n\t\t}\r\n\r\n\t\tpublic static long lcm (long a, long b) {\r\n\t\t\treturn a * b / gcd (a, b);\r\n\t\t}\r\n\r\n\t\tpublic static long fast_pow_mod (long b, long x, int mod) {\r\n\t\t\tif (x == 0) return 1;\r\n\t\t\tif (x == 1) return b;\r\n\t\t\tif (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;\r\n\r\n\t\t\treturn b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;\r\n\t\t}\r\n\r\n\t\tpublic static long fast_pow (long b, long x) {\r\n\t\t\tif (x == 0) return 1;\r\n\t\t\tif (x == 1) return b;\r\n\t\t\tif (x % 2 == 0) return fast_pow (b * b, x / 2);\r\n\r\n\t\t\treturn b * fast_pow (b * b, x / 2);\r\n\t\t}\r\n\r\n\t\tpublic static long choose (long n, long k) {\r\n\t\t\tk = Math.min (k, n - k);\r\n\t\t\tlong val = 1;\r\n\r\n\t\t\tfor (int i = 0; i < k; ++i)\r\n\t\t\t\tval = val * (n - i) / (i + 1);\r\n\r\n\t\t\treturn val;\r\n\t\t}\r\n\r\n\t\tpublic static long permute (int n, int k) {\r\n\t\t\tif (n < k) return 0;\r\n\t\t\tlong val = 1;\r\n\r\n\t\t\tfor (int i = 0; i < k; ++i)\r\n\t\t\t\tval = (val * (n - i));\r\n\r\n\t\t\treturn val;\r\n\t\t}\r\n\t\t\r\n\t\t// start of permutation and lower/upper bound template\r\n\t\tpublic static void nextPermutation(int[] nums) {\r\n\t\t //find first decreasing digit\r\n\t\t int mark = -1;\r\n\t\t for (int i = nums.length - 1; i > 0; i--) {\r\n\t\t if (nums[i] > nums[i - 1]) {\r\n\t\t mark = i - 1;\r\n\t\t break;\r\n\t\t }\r\n\t\t }\r\n\t\t \r\n\t\t if (mark == -1) {\r\n\t\t reverse(nums, 0, nums.length - 1);\r\n\t\t return;\r\n\t\t }\r\n\t\t \r\n\t\t int idx = nums.length-1;\r\n\t\t for (int i = nums.length-1; i >= mark+1; i--) {\r\n\t\t if (nums[i] > nums[mark]) {\r\n\t\t idx = i;\r\n\t\t break;\r\n\t\t }\r\n\t\t }\r\n\t\t \r\n\t\t swap(nums, mark, idx);\r\n\t\t \r\n\t\t reverse(nums, mark + 1, nums.length - 1);\r\n\t\t}\r\n\t\t \r\n\t\tpublic static void swap(int[] nums, int i, int j) {\r\n\t\t int t = nums[i];\r\n\t\t nums[i] = nums[j];\r\n\t\t nums[j] = t;\r\n\t\t}\r\n\t\t \r\n\t\tpublic static void reverse(int[] nums, int i, int j) {\r\n\t\t while (i < j) {\r\n\t\t swap(nums, i, j);\r\n\t\t i++;\r\n\t\t j--;\r\n\t\t }\r\n\t\t}\r\n\t\t\r\n\t\tstatic int lower_bound (int[] arr, int hi, int cmp) {\r\n\t\t\tint low = 0, high = hi, mid = -1;\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\t\t\t\tif (arr[mid] >= cmp) high = mid;\r\n\t\t\t\telse low = mid + 1;\r\n\t\t\t}\r\n\t\t\treturn low;\r\n\t\t}\r\n\t \r\n\t\tstatic int upper_bound (int[] arr, int hi, int cmp) {\r\n\t\t\tint low = 0, high = hi, mid = -1;\r\n\t\t\twhile (low < high) {\r\n\t\t\t\tmid = (low + high) / 2;\r\n\t\t\t\tif (arr[mid] > cmp) high = mid;\r\n\t\t\t\telse low = mid + 1;\r\n\t\t\t}\r\n\t\t\treturn low;\r\n\t\t} \r\n\t\t// end of permutation and lower/upper bound template\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d5bf329b67080e29fc859114f50af4db", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\r\nimport java.io.*;\r\nimport java.util.*;\r\n\r\npublic final class Main {\r\n\r\n //int 2e9 - long 9e18\r\n static PrintWriter out = new PrintWriter(System.out);\r\n static FastReader in = new FastReader();\r\n static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)};\r\n static int mod = (int) (1e9 + 7);\r\n static int mod2 = 998244353;\r\n\r\n public static void main(String[] args) {\r\n initializeFactorial(250, mod2);\r\n int tt = 1;\r\n while (tt-- > 0) {\r\n solve();\r\n }\r\n out.flush();\r\n }\r\n\r\n public static void solve() {\r\n int n = i();\r\n int k = i();\r\n\r\n int[] e = new int[n + 1];\r\n for (int i = 1; i <= n; i++) {\r\n e[i] = i * (i - 1) / 2;\r\n }\r\n int[][] dp = new int[n + 1][k + 1];\r\n dp[1][0] = 1;\r\n for (int i = 1; i <= n; i++) {\r\n for (int j = 0; j < k; j++) {\r\n // color j+1\r\n for (int l = 0; l <= n - i; l++) {\r\n int rem = n - i;\r\n int cof = binomialCoefficient(rem, l, mod2);\r\n long add = (long) dp[i][j] * cof;\r\n add %= mod2;\r\n add *= pow(k - j,e[i + l] - e[i] - l , mod2);\r\n add %= mod2;\r\n dp[i + l][j + 1] += add;\r\n dp[i + l][j + 1] %= mod2;\r\n }\r\n }\r\n }\r\n\r\n out.println(dp[n][k]);\r\n }\r\n\r\n static long[] fac;\r\n static long[] inv;\r\n\r\n static void initializeFactorial(int n, int mod) {\r\n fac = new long[n + 1];\r\n inv = new long[n + 1];\r\n long[] v = new long[fac.length];\r\n fac[0] = inv[0] = 1;\r\n for (int i = 1; i < fac.length; i++) {\r\n v[i] = i == 1 ? 1 : v[i - mod % i] * (mod / i + 1);\r\n v[i] %= mod;\r\n fac[i] = fac[i - 1] * i;\r\n fac[i] %= mod;\r\n inv[i] = inv[i - 1] * v[i];\r\n inv[i] %= mod;\r\n }\r\n }\r\n\r\n static int binomialCoefficient(int n, int k, int m) {\r\n long res = fac[n] * inv[k];\r\n res %= m;\r\n res *= inv[n - k];\r\n return (int) (res % m);\r\n }\r\n\r\n\r\n // (10,5) = 2 ,(11,5) = 3\r\n static long upperDiv(long a, long b) {\r\n return (a / b) + ((a % b == 0) ? 0 : 1);\r\n }\r\n\r\n static long sum(int[] a) {\r\n long sum = 0;\r\n for (int x : a) {\r\n sum += x;\r\n }\r\n return sum;\r\n }\r\n\r\n static int[] preint(int[] a) {\r\n int[] pre = new int[a.length + 1];\r\n pre[0] = 0;\r\n for (int i = 0; i < a.length; i++) {\r\n pre[i + 1] = pre[i] + a[i];\r\n }\r\n return pre;\r\n }\r\n\r\n static long[] pre(int[] a) {\r\n long[] pre = new long[a.length + 1];\r\n pre[0] = 0;\r\n for (int i = 0; i < a.length; i++) {\r\n pre[i + 1] = pre[i] + a[i];\r\n }\r\n return pre;\r\n }\r\n\r\n static long[] post(int[] a) {\r\n long[] post = new long[a.length + 1];\r\n post[0] = 0;\r\n for (int i = 0; i < a.length; i++) {\r\n post[i + 1] = post[i] + a[a.length - 1 - i];\r\n }\r\n return post;\r\n }\r\n\r\n static long[] pre(long[] a) {\r\n long[] pre = new long[a.length + 1];\r\n pre[0] = 0;\r\n for (int i = 0; i < a.length; i++) {\r\n pre[i + 1] = pre[i] + a[i];\r\n }\r\n return pre;\r\n }\r\n\r\n static void print(char A[]) {\r\n for (char c : A) {\r\n out.print(c);\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(boolean A[]) {\r\n for (boolean c : A) {\r\n out.print(c + \" \");\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(int A[]) {\r\n for (int c : A) {\r\n out.print(c + \" \");\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(long A[]) {\r\n for (long i : A) {\r\n out.print(i + \" \");\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(List A) {\r\n for (int a : A) {\r\n out.print(a + \" \");\r\n }\r\n }\r\n\r\n static int i() {\r\n return in.nextInt();\r\n }\r\n\r\n static long l() {\r\n return in.nextLong();\r\n }\r\n\r\n static double d() {\r\n return in.nextDouble();\r\n }\r\n\r\n static String s() {\r\n return in.nextLine();\r\n }\r\n\r\n static String c() {\r\n return in.next();\r\n }\r\n\r\n static int[][] inputWithIdx(int N) {\r\n int A[][] = new int[N][2];\r\n for (int i = 0; i < N; i++) {\r\n A[i] = new int[]{i, in.nextInt()};\r\n }\r\n return A;\r\n }\r\n\r\n static int[] input(int N) {\r\n int A[] = new int[N];\r\n for (int i = 0; i < N; i++) {\r\n A[i] = in.nextInt();\r\n }\r\n return A;\r\n }\r\n\r\n static long[] inputLong(int N) {\r\n long A[] = new long[N];\r\n for (int i = 0; i < A.length; i++) {\r\n A[i] = in.nextLong();\r\n }\r\n return A;\r\n }\r\n\r\n static int GCD(int a, int b) {\r\n if (b == 0) {\r\n return a;\r\n } else {\r\n return GCD(b, a % b);\r\n }\r\n }\r\n\r\n static long GCD(long a, long b) {\r\n if (b == 0) {\r\n return a;\r\n } else {\r\n return GCD(b, a % b);\r\n }\r\n }\r\n\r\n static long LCM(int a, int b) {\r\n return (long) a / GCD(a, b) * b;\r\n }\r\n\r\n static long LCM(long a, long b) {\r\n return a / GCD(a, b) * b;\r\n }\r\n\r\n // find highest i which satisfy a[i]<=x\r\n static int lowerbound(int[] a, int x) {\r\n int l = 0;\r\n int r = a.length - 1;\r\n while (l < r) {\r\n int m = (l + r + 1) / 2;\r\n if (a[m] <= x) {\r\n l = m;\r\n } else {\r\n r = m - 1;\r\n }\r\n }\r\n return l;\r\n }\r\n\r\n static void shuffle(int[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n int rand = (int) (Math.random() * arr.length);\r\n int temp = arr[rand];\r\n arr[rand] = arr[i];\r\n arr[i] = temp;\r\n }\r\n }\r\n\r\n static void shuffleAndSort(int[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n int rand = (int) (Math.random() * arr.length);\r\n int temp = arr[rand];\r\n arr[rand] = arr[i];\r\n arr[i] = temp;\r\n }\r\n Arrays.sort(arr);\r\n }\r\n\r\n static void shuffleAndSort(int[][] arr, Comparator comparator) {\r\n for (int i = 0; i < arr.length; i++) {\r\n int rand = (int) (Math.random() * arr.length);\r\n int[] temp = arr[rand];\r\n arr[rand] = arr[i];\r\n arr[i] = temp;\r\n }\r\n Arrays.sort(arr, comparator);\r\n }\r\n\r\n static void shuffleAndSort(long[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n int rand = (int) (Math.random() * arr.length);\r\n long temp = arr[rand];\r\n arr[rand] = arr[i];\r\n arr[i] = temp;\r\n }\r\n Arrays.sort(arr);\r\n }\r\n\r\n static boolean isPerfectSquare(double number) {\r\n double sqrt = Math.sqrt(number);\r\n return ((sqrt - Math.floor(sqrt)) == 0);\r\n }\r\n\r\n static void swap(int A[], int a, int b) {\r\n int t = A[a];\r\n A[a] = A[b];\r\n A[b] = t;\r\n }\r\n\r\n static void swap(char A[], int a, int b) {\r\n char t = A[a];\r\n A[a] = A[b];\r\n A[b] = t;\r\n }\r\n\r\n static long pow(long a, long b, int mod) {\r\n long pow = 1;\r\n long x = a;\r\n while (b != 0) {\r\n if ((b & 1) != 0) {\r\n pow = (pow * x) % mod;\r\n }\r\n x = (x * x) % mod;\r\n b /= 2;\r\n }\r\n return pow;\r\n }\r\n\r\n static long pow(long a, long b) {\r\n long pow = 1;\r\n long x = a;\r\n while (b != 0) {\r\n if ((b & 1) != 0) {\r\n pow *= x;\r\n }\r\n x = x * x;\r\n b /= 2;\r\n }\r\n return pow;\r\n }\r\n\r\n static long modInverse(long x, int mod) {\r\n return pow(x, mod - 2, mod);\r\n }\r\n\r\n static boolean isPrime(long N) {\r\n if (N <= 1) {\r\n return false;\r\n }\r\n if (N <= 3) {\r\n return true;\r\n }\r\n if (N % 2 == 0 || N % 3 == 0) {\r\n return false;\r\n }\r\n for (int i = 5; i * i <= N; i = i + 6) {\r\n if (N % i == 0 || N % (i + 2) == 0) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n public static String reverse(String str) {\r\n if (str == null) {\r\n return null;\r\n }\r\n return new StringBuilder(str).reverse().toString();\r\n }\r\n\r\n public static void reverse(int[] arr) {\r\n for (int i = 0; i < arr.length / 2; i++) {\r\n int tmp = arr[i];\r\n arr[arr.length - 1 - i] = tmp;\r\n arr[i] = arr[arr.length - 1 - i];\r\n }\r\n }\r\n\r\n public static String repeat(char ch, int repeat) {\r\n if (repeat <= 0) {\r\n return \"\";\r\n }\r\n final char[] buf = new char[repeat];\r\n for (int i = repeat - 1; i >= 0; i--) {\r\n buf[i] = ch;\r\n }\r\n return new String(buf);\r\n }\r\n\r\n public static int[] manacher(String s) {\r\n char[] chars = s.toCharArray();\r\n int n = s.length();\r\n int[] d1 = new int[n];\r\n for (int i = 0, l = 0, r = -1; i < n; i++) {\r\n int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1);\r\n while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) {\r\n k++;\r\n }\r\n d1[i] = k--;\r\n if (i + k > r) {\r\n l = i - k;\r\n r = i + k;\r\n }\r\n }\r\n return d1;\r\n }\r\n\r\n public static int[] kmp(String s) {\r\n int n = s.length();\r\n int[] res = new int[n];\r\n for (int i = 1; i < n; ++i) {\r\n int j = res[i - 1];\r\n while (j > 0 && s.charAt(i) != s.charAt(j)) {\r\n j = res[j - 1];\r\n }\r\n if (s.charAt(i) == s.charAt(j)) {\r\n ++j;\r\n }\r\n res[i] = j;\r\n }\r\n return res;\r\n }\r\n}\r\n\r\nclass Pair {\r\n\r\n int i;\r\n int j;\r\n\r\n Pair(int i, int j) {\r\n this.i = i;\r\n this.j = j;\r\n }\r\n\r\n @Override\r\n public boolean equals(Object o) {\r\n if (this == o) {\r\n return true;\r\n }\r\n if (o == null || getClass() != o.getClass()) {\r\n return false;\r\n }\r\n Pair pair = (Pair) o;\r\n return i == pair.i && j == pair.j;\r\n }\r\n\r\n @Override\r\n public int hashCode() {\r\n return Objects.hash(i, j);\r\n }\r\n}\r\n\r\nclass ThreePair {\r\n\r\n int i;\r\n int j;\r\n int k;\r\n\r\n ThreePair(int i, int j, int k) {\r\n this.i = i;\r\n this.j = j;\r\n this.k = k;\r\n }\r\n\r\n @Override\r\n public boolean equals(Object o) {\r\n if (this == o) {\r\n return true;\r\n }\r\n if (o == null || getClass() != o.getClass()) {\r\n return false;\r\n }\r\n ThreePair pair = (ThreePair) o;\r\n return i == pair.i && j == pair.j && k == pair.k;\r\n }\r\n\r\n @Override\r\n public int hashCode() {\r\n return Objects.hash(i, j);\r\n }\r\n}\r\n\r\nclass FastReader {\r\n\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n public FastReader() {\r\n br = new BufferedReader(new InputStreamReader(System.in));\r\n }\r\n\r\n String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine() {\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n}\r\n\r\nclass Node {\r\n\r\n int val;\r\n\r\n public Node(int val) {\r\n this.val = val;\r\n }\r\n}\r\n\r\n\r\nclass ST {\r\n\r\n int n;\r\n Node[] st;\r\n\r\n ST(int n) {\r\n this.n = n;\r\n st = new Node[4 * Integer.highestOneBit(n)];\r\n }\r\n\r\n void build(Node[] nodes) {\r\n build(0, 0, n - 1, nodes);\r\n }\r\n\r\n private void build(int id, int l, int r, Node[] nodes) {\r\n if (l == r) {\r\n st[id] = nodes[l];\r\n return;\r\n }\r\n int mid = (l + r) >> 1;\r\n build((id << 1) + 1, l, mid, nodes);\r\n build((id << 1) + 2, mid + 1, r, nodes);\r\n st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);\r\n }\r\n\r\n void update(int i, Node node) {\r\n update(0, 0, n - 1, i, node);\r\n }\r\n\r\n private void update(int id, int l, int r, int i, Node node) {\r\n if (i < l || r < i) {\r\n return;\r\n }\r\n if (l == r) {\r\n st[id] = node;\r\n return;\r\n }\r\n int mid = (l + r) >> 1;\r\n update((id << 1) + 1, l, mid, i, node);\r\n update((id << 1) + 2, mid + 1, r, i, node);\r\n st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);\r\n }\r\n\r\n Node get(int x, int y) {\r\n return get(0, 0, n - 1, x, y);\r\n }\r\n\r\n private Node get(int id, int l, int r, int x, int y) {\r\n if (x > r || y < l) {\r\n return new Node(0);\r\n }\r\n if (x <= l && r <= y) {\r\n return st[id];\r\n }\r\n int mid = (l + r) >> 1;\r\n return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y));\r\n }\r\n\r\n Node comb(Node a, Node b) {\r\n if (a == null) {\r\n return b;\r\n }\r\n if (b == null) {\r\n return a;\r\n }\r\n return new Node(GCD(a.val, b.val));\r\n }\r\n\r\n static int GCD(int a, int b) {\r\n if (b == 0) {\r\n return a;\r\n } else {\r\n return GCD(b, a % b);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b2c3930d22f275d824e74ae603c4bbb", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Map.Entry;\n\nimport java.math.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tInputReader in = new InputReader(System.in);\n\t\t// Scanner in = new Scanner(System.in);\n\t\t// Scanner in = new Scanner(new BufferedReader(new\n\t\t// InputStreamReader(System.in)));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t// InputReader in = new InputReader(new\n\t\t// File(\"ethan_traverses_a_tree.txt\"));\n\t\t// PrintWriter out = new PrintWriter(new\n\t\t// File(\"ethan_traverses_a_tree-output.txt\"))\n\n\t\tfinal long mod = 998244353;\n\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\n\t\tlong[][] c = new long[n + 1][n + 1];\n\n\t\tfor (int i = 0; i <= n; i++) {\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 - 1] + c[i - 1][j]) % mod;\n\t\t\t}\n\t\t}\n\n\t\tlong[][] dp = new long[n + 1][k + 1];\n\t\tlong[][] sum = new long[n + 1][k + 1];\n\n\t\tdp[1][0] = 1;\n\t\tfor (int j = 0; j <= k; j++) {\n\t\t\tsum[1][j] = 1;\n\t\t}\n\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= k; j++) {\n\t\t\t\tlong sumnow = 0;\n\t\t\t\tfor (int u = 1; u < i; u++) {\n\t\t\t\t\tlong now = (sum[i - u][j - 1] * c[i - 1][u]) % mod;\n\t\t\t\t\tint edgecount = ((i - u - 1) + (i - 2)) * u / 2;\n\t\t\t\t\tlong p = powmod(k - j + 1, edgecount, mod);\n\n\t\t\t\t\tsumnow = (sumnow + (now * p) % mod) % mod;\n\t\t\t\t}\n\t\t\t\tdp[i][j] = sumnow;\n\t\t\t}\n\n\t\t\tfor (int j = 1; j <= k; j++) {\n\t\t\t\tsum[i][j] = (sum[i][j - 1] + dp[i][j]) % mod;\n\t\t\t}\n\t\t}\n\n\t\tout.printf(\"%d\\n\", sum[n][k]);\n\n\t\tout.close();\n\t}\n\n\tstatic public long inverse(long a, int p) {\n\t\treturn powmod(a, p - 2, p);\n\t}\n\n\tstatic public long powmod(long a, long n, long mod) {\n\t\tlong result = 1;\n\t\tlong p = a;\n\n\t\twhile (n != 0) {\n\t\t\tif (n % 2 == 1) {\n\t\t\t\tresult = (result * p) % mod;\n\t\t\t}\n\t\t\tp = (p * p) % mod;\n\t\t\tn = n / 2;\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tstatic class InputReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic InputReader(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic InputReader(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "73ad9996d8d5e4229036f6338857d2fe", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class _1657_E {\r\n static final long MOD = 998244353;\r\n public static void main(String[] args) throws IOException {\r\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\r\n PrintWriter out = new PrintWriter(System.out);\r\n StringTokenizer line = new StringTokenizer(in.readLine());\r\n int n = Integer.parseInt(line.nextToken());\r\n int k = Integer.parseInt(line.nextToken());\r\n long[][][] dp = new long[n][k + 1][n];\r\n long[][] psum = new long[n][k + 1];\r\n for(int i = 1; i <= k; i++) {\r\n dp[1][i][1] = 1;\r\n psum[1][i] = modadd(psum[1][i - 1], 1);\r\n }\r\n long res = 0;\r\n for(int i = 2; i < n; i++) {\r\n for(int j = 1; j <= k; j++) {\r\n psum[i][j] = psum[i][j - 1];\r\n for(int a = 1; a <= i; a++) {\r\n if(a > 1) {\r\n long mult = modmult(modmult(i, modinv(a)), binpow(k - j + 1, i - 1));\r\n dp[i][j][a] = modmult(dp[i - 1][j][a - 1], mult);\r\n }else {\r\n long mult = modmult(i, binpow(k - j + 1, i - 1));\r\n dp[i][j][a] = modmult(psum[i - 1][j - 1], mult);\r\n }\r\n psum[i][j] = modadd(psum[i][j], dp[i][j][a]);\r\n if(i == n - 1) {\r\n res = modadd(res, dp[i][j][a]);\r\n }\r\n }\r\n }\r\n }\r\n out.println(res);\r\n in.close();\r\n out.close();\r\n }\r\n static long modadd(long a, long b) {\r\n return (a + b + MOD) % MOD;\r\n }\r\n static long modmult(long a, long b) {\r\n return a * b % MOD;\r\n }\r\n static long modinv(long a) {\r\n return binpow(a, MOD - 2);\r\n }\r\n static long binpow(long a, long b) {\r\n if(b == 0) {\r\n return 1;\r\n }\r\n long small = binpow(a, b / 2);\r\n if(b % 2 == 0) {\r\n return modmult(small, small);\r\n }else {\r\n return modmult(modmult(small, small), a);\r\n }\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7cbd42ad804dbc8964cc2baac9dd8305", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class PuttingBoxesTogether {\n \n int N = (int) 2e5 + 10;\n int MOD = (int) 1e9 + 7;\n \n int n;\n long[] t1 = new long[N];\n long[] t2 = new long[N];\n \n void solve() {\n n = in.nextInt(); int Q = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n int[] w = new int[n];\n for (int i = 0; i < n; i++) w[i] = in.nextInt();\n \n for (int i = 0; i < n; i++) a[i] = (a[i] - i + MOD) % MOD;\n\n for (int i = 0; i < n; i++) {\n add(t1, i, w[i]);\n add(t2, i, (long) a[i] * w[i] % MOD);\n }\n \n while (Q-- > 0) {\n int x = in.nextInt();\n if (x < 0) {\n int i = -x - 1, nw = in.nextInt();\n long delta1 = nw - w[i];\n long delta2 = (a[i] * nw % MOD - a[i] * w[i] % MOD + MOD) % MOD;\n w[i] = nw;\n add(t1, i, delta1);\n add(t2, i, delta2);\n } else {\n int l = x - 1, r = in.nextInt();\n long tot = sum(t1, l, r);\n int lb = l, ub = r;\n while (ub - lb > 1) {\n int m = (lb + ub) >> 1;\n if (sum(t1, l, m) * 2 <= tot) lb = m;\n else ub = m;\n }\n int k = lb;\n long ans = (a[k] * (sum(t1, l, k) % MOD) % MOD - sum(t2, l, k) % MOD + MOD) % MOD;\n ans = (ans + (sum(t2, k + 1, r) % MOD - a[k] * (sum(t1, k + 1, r) % MOD) % MOD + MOD) % MOD) % MOD;\n out.println(ans);\n }\n }\n }\n \n long sum(long[] t, int l, int r) {\n return sum(t, r - 1) - sum(t, l - 1);\n }\n \n long sum(long[] t, int i) {\n long res = 0;\n for (int x = i; x >= 0; x = (x & x + 1) - 1) res += t[x];\n return res;\n }\n \n void add(long[] t, int i, long delta) {\n for (int x = i; x < n; x = x | x + 1) t[x] += delta;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new PuttingBoxesTogether().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "baa56915452f6c6144f6215c05d23608", "src_uid": "c0715f71efa327070eba7e491856d66a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class PuttingBoxesTogether {\n \n int N = (int) 2e5 + 10;\n int MOD = (int) 1e9 + 7;\n \n int n;\n long[] t1 = new long[N];\n long[] t2 = new long[N];\n \n void solve() {\n n = in.nextInt(); int Q = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n int[] w = new int[n];\n for (int i = 0; i < n; i++) w[i] = in.nextInt();\n \n for (int i = 0; i < n; i++) a[i] -= i;\n \n for (int i = 0; i < n; i++) {\n add(t1, i, w[i]);\n add(t2, i, (long) a[i] * w[i] % MOD);\n }\n \n while (Q-- > 0) {\n int x = in.nextInt();\n if (x < 0) {\n int i = -x - 1, nw = in.nextInt();\n long delta1 = nw - w[i];\n long delta2 = (a[i] * nw % MOD - a[i] * w[i] % MOD + MOD) % MOD;\n w[i] = nw;\n add(t1, i, delta1);\n add(t2, i, delta2);\n } else {\n int l = x - 1, r = in.nextInt();\n long tot = sum(t1, l, r);\n int lb = l, ub = r;\n while (ub - lb > 1) {\n int m = (lb + ub) >> 1;\n if (sum(t1, l, m) * 2 <= tot) lb = m;\n else ub = m;\n }\n int k = lb;\n long ans = norm(mul(a[k], nsum(t1, l, k)) - nsum(t2, l, k));\n ans = norm(ans + norm(nsum(t2, k + 1, r) - mul(a[k], nsum(t1, k + 1, r))));\n out.println(ans);\n }\n }\n }\n \n long nsum(long[] t, int l, int r) {\n return norm(sum(t, r - 1) - sum(t, l - 1));\n }\n \n long sum(long[] t, int l, int r) {\n return sum(t, r - 1) - sum(t, l - 1);\n }\n \n long sum(long[] t, int i) {\n long res = 0;\n for (int x = i; x >= 0; x = (x & x + 1) - 1) res += t[x];\n return res;\n }\n \n void add(long[] t, int i, long delta) {\n for (int x = i; x < n; x = x | x + 1) t[x] += delta;\n }\n \n long mul(long a, long b) {\n return a * b % MOD;\n }\n \n long norm(long a) {\n a %= MOD;\n if (a > MOD) a -= MOD;\n if (a < 0) a += MOD;\n return a;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new PuttingBoxesTogether().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ecad5e0208042759cebae7127fb09aa0", "src_uid": "c0715f71efa327070eba7e491856d66a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class PuttingBoxesTogether2 {\n \n int N = (int) 2e5 + 10;\n int MOD = (int) 1e9 + 7;\n int INF = (int) 2e9;\n \n int n;\n long[] t1 = new long[N << 2];\n long[] t2 = new long[N << 2];\n \n void solve() {\n n = in.nextInt(); int Q = in.nextInt();\n long[] a = new long[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n long[] w = new long[n];\n for (int i = 0; i < n; i++) w[i] = in.nextInt();\n \n for (int i = 0; i < n; i++) a[i] -= i;\n \n long[] aw = new long[n];\n for (int i = 0; i < n; i++) aw[i] = mul(a[i], w[i]);\n \n build(t1, 0, 0, n, w);\n build(t2, 0, 0, n, aw);\n \n while (Q-- > 0) {\n int x = in.nextInt();\n if (x < 0) {\n int i = -x - 1, nw = in.nextInt();\n update(t1, 0, 0, n, i, nw);\n update(t2, 0, 0, n, i, mul(a[i], nw));\n } else {\n int l = x - 1, r = in.nextInt();\n long tot = query(t1, 0, 0, n, l, r);\n int k = (int) find(t1, 0, 0, n, l, r, tot / 2)[0];\n long ans = norm(mul(a[k], norm(query(t1, 0, 0, n, l, k))) - norm(query(t2, 0, 0, n, l, k)));\n ans = norm(ans + norm(norm(query(t2, 0, 0, n, k + 1, r)) - mul(a[k], norm(query(t1, 0, 0, n, k + 1, r)))));\n out.println(ans);\n }\n }\n }\n \n long[] find(long[] t, int k, int l, int r, int a, int b, long val) {\n if (l == a && r == b) {\n if (t[k] <= val) return new long[]{INF, t[k]};\n if (r - l == 1) return new long[]{l, t[l]};\n }\n int m = (l + r) >> 1;\n long pos = INF, sum = 0;\n if (a < m) {\n long[] ret = find(t, 2 * k + 1, l, m, a, Math.min(m, b), val);\n pos = Math.min(pos, ret[0]);\n sum += ret[1];\n }\n if (pos == INF && b >= m) {\n long[] ret = find(t, 2 * k + 2, m, r, Math.max(m, a), b, val - sum);\n pos = Math.min(pos, ret[0]);\n sum += ret[1];\n }\n return new long[]{pos, sum};\n }\n \n long query(long[] t, int k, int l, int r, int a, int b) {\n if (a <= l && r <= b) return t[k];\n if (a >= r || b <= l) return 0;\n int m = (l + r) >> 1;\n return query(t, 2 * k + 1, l, m, a, b) + query(t, 2 * k + 2, m, r, a, b);\n }\n \n void update(long[] t, int k, int l, int r, int i, long val) {\n if (r - l == 1) {\n t[k] = val;\n return;\n }\n int m = (l + r) >> 1;\n if (i < m) update(t, 2 * k + 1, l, m, i, val);\n else update(t, 2 * k + 2, m, r, i, val);\n t[k] = t[2 * k + 1] + t[2 * k + 2];\n }\n \n void build(long[] t, int k, int l, int r, long[] x) {\n if (r - l == 1) {\n t[k] = x[l];\n return;\n }\n int m = (l + r) >> 1;\n build(t, 2 * k + 1, l, m, x);\n build(t, 2 * k + 2, m, r, x);\n t[k] = t[2 * k + 1] + t[2 * k + 2];\n }\n \n long mul(long a, long b) {\n return a * b % MOD;\n }\n \n long norm(long a) {\n a %= MOD;\n if (a > MOD) a -= MOD;\n if (a < 0) a += MOD;\n return a;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new PuttingBoxesTogether2().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f3ed9ab23c3cecaa2dfdf1bb145d4d66", "src_uid": "c0715f71efa327070eba7e491856d66a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class PuttingBoxesTogether {\n \n int N = (int) 2e5 + 10;\n int MOD = (int) 1e9 + 7;\n \n int n;\n long[] t1 = new long[N];\n long[] t2 = new long[N];\n \n void solve() {\n n = in.nextInt(); int Q = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n int[] w = new int[n];\n for (int i = 0; i < n; i++) w[i] = in.nextInt();\n \n for (int i = 0; i < n; i++) a[i] -= i;\n \n for (int i = 0; i < n; i++) {\n add(t1, i, w[i]);\n add(t2, i, (long) a[i] * w[i] % MOD);\n }\n \n while (Q-- > 0) {\n int x = in.nextInt();\n if (x < 0) {\n int i = -x - 1, nw = in.nextInt();\n long delta1 = nw - w[i];\n long delta2 = mul(a[i], nw) - mul(a[i], w[i]);\n w[i] = nw;\n add(t1, i, delta1);\n add(t2, i, delta2);\n } else {\n int l = x - 1, r = in.nextInt();\n long tot = sum(t1, l, r);\n int lb = l, ub = r;\n while (ub - lb > 1) {\n int m = (lb + ub) >> 1;\n if (sum(t1, l, m) * 2 <= tot) lb = m;\n else ub = m;\n }\n int k = lb;\n long ans = norm(mul(a[k], nsum(t1, l, k)) - nsum(t2, l, k));\n ans = norm(ans + norm(nsum(t2, k + 1, r) - mul(a[k], nsum(t1, k + 1, r))));\n out.println(ans);\n }\n }\n }\n \n long nsum(long[] t, int l, int r) {\n return norm(sum(t, r - 1) - sum(t, l - 1));\n }\n \n long sum(long[] t, int l, int r) {\n return sum(t, r - 1) - sum(t, l - 1);\n }\n \n long sum(long[] t, int i) {\n long res = 0;\n for (int x = i; x >= 0; x = (x & x + 1) - 1) res += t[x];\n return res;\n }\n \n void add(long[] t, int i, long delta) {\n for (int x = i; x < n; x = x | x + 1) t[x] += delta;\n }\n \n long mul(long a, long b) {\n return a * b % MOD;\n }\n \n long norm(long a) {\n a %= MOD;\n if (a > MOD) a -= MOD;\n if (a < 0) a += MOD;\n return a;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new PuttingBoxesTogether().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6079881fc5ac21db2c1e68b127f6a1b6", "src_uid": "c0715f71efa327070eba7e491856d66a", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.util.concurrent.ForkJoinTask;\nimport java.util.concurrent.RecursiveAction;\nimport java.util.concurrent.RecursiveTask;\nimport java.util.concurrent.atomic.AtomicInteger;\nimport java.io.*;\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\nimport java.math.*;\n\nimport javax.swing.plaf.SliderUI;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\t\n\tArrayList g [];\n\tArrayList 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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7aaff75d51745746e2923d3ef8efb82", "src_uid": "390a0b72c77ebe5881b656830fbfae02", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.util.concurrent.ForkJoinTask;\nimport java.util.concurrent.RecursiveAction;\nimport java.util.concurrent.RecursiveTask;\nimport java.util.concurrent.atomic.AtomicInteger;\nimport java.io.*;\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\nimport java.math.*;\n\nimport javax.swing.plaf.SliderUI;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\t\n\tArrayList g [];\n\tArrayList 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} 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 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\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0d161fe96faa8ab7e801ac0923868c49", "src_uid": "390a0b72c77ebe5881b656830fbfae02", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class G {\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tstatic int n, nn;\n\tstatic long edges[][];\n\tstatic int matchingL[], matchingR[];\n\n\tstatic int hopcroftKarpDist[];\n\n\tstatic int hopcroftKarp() {\n\t\tfill(matchingL, -1);\n\t\tfill(matchingR, -1);\n\t\tint queue[] = new int[2 * n];\n\t\tint size = 0;\n\t\twhile (true) {\n\t\t\tfill(hopcroftKarpDist, -1);\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\tqueue[queueTail++] = i;\n\t\t\t\t\tqueue[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 = queue[queueHead++];\n\t\t\t\tint cdist = queue[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\tfor (int nextBase = 0; nextBase < nn; nextBase++) {\n\t\t\t\t\tlong v = edges[cur][nextBase];\n\t\t\t\t\tif (v != 0) {\n\t\t\t\t\t\tfor (int next = nextBase << 6; next < (nextBase + 1) << 6; next++) {\n\t\t\t\t\t\t\tif ((v & (1L << next)) == 0 || hopcroftKarpDist[next] != -1) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thopcroftKarpDist[next] = cdist;\n\t\t\t\t\t\t\tint next2 = matchingR[next];\n\t\t\t\t\t\t\tif (next2 < 0) {\n\t\t\t\t\t\t\t\tresDist = cdist;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tqueue[queueTail++] = next2;\n\t\t\t\t\t\t\t\tqueue[queueTail++] = cdist + 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\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}\n\t}\n\n\tstatic boolean hopcroftKarpDfs(int cur, int cdist) {\n\t\tfor (int nextBase = 0; nextBase < nn; nextBase++) {\n\t\t\tlong v = edges[cur][nextBase];\n\t\t\tif (v != 0) {\n\t\t\t\tfor (int next = nextBase << 6; next < (nextBase + 1) << 6; next++) {\n\t\t\t\t\tif ((v & (1L << next)) == 0 || hopcroftKarpDist[next] != cdist) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\thopcroftKarpDist[next] = -1;\n\t\t\t\t\tint next2 = matchingR[next];\n\t\t\t\t\tif (next2 < 0 || hopcroftKarpDfs(next2, cdist + 1)) {\n\t\t\t\t\t\tmatchingR[next] = cur;\n\t\t\t\t\t\tmatchingL[cur] = next;\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\n\tstatic void solve() throws Exception {\n\t\tn = nextInt();\n\t\tint q = nextInt();\n//\t\tn = 10000;\n//\t\tint q = 10000;\n\t\tnn = (n >> 6) + 1;\n\t\tedges = new long[n][nn];\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\tedges[x][n >> 6] = (1L << n) - 1;\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\tint x1 = 9999 - i, x2 = 10000, y1 = i, y2 = i + 1;\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\tedges[x][y2 >> 6] &= -1L << y2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\thopcroftKarpDist = new int[n];\n\t\tmatchingL = new int[n];\n\t\tmatchingR = new int[n];\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "486be59732273d028ed3fe2ec720d82b", "src_uid": "d662ef3f9a70a5afaa2f0f68327a457f", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1f6ced037e2fc0996098d7d78056cbb7", "src_uid": "d662ef3f9a70a5afaa2f0f68327a457f", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de2eec55bdf844d75531cbcfe05db233", "src_uid": "d662ef3f9a70a5afaa2f0f68327a457f", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OuputStreamWriter;\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, 8, 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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3d43875fe55651768e295245b87d9323", "src_uid": "d662ef3f9a70a5afaa2f0f68327a457f", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class F {\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 prefs = 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\tprefs.add(s[i].substring(j));\n\t\t\t}\n\t\t}\n\t\tprefs.add(\"\");\n\t\tHashSet nodes = new HashSet<>();\n\t\tfor(String a: prefs){\n\t\t\tfor(String b: prefs){\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\tHashMap code = new HashMap<>();\n\t\tPair[] decode = new Pair[N];\n\t\tint count = 0;\n\t\tfor(Pair p: nodes) {\n\t\t\tdecode[count] = p;\n\t\t\tcode.put(p, count++);\n\t\t}\n\t\tlong[][] aut = new long[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}\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 return null;\n\t\t}\n\t\telse if(p.b.equals(\"\")) {\n\t\t\tif(isPref(s, p.a)) {\n\t\t\t\tString a = p.a.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\tif(p.b.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) {\n\t\tif(a.length() == b.length()) {\n\t\t\treturn a.equals(b);\n\t\t}\n\t\telse if(a.length() > b.length()) {\n\t\t\treturn b.equals(a.substring(0, b.length()));\n\t\t}\n\t\telse {\n\t\t\treturn a.equals(b.substring(0, a.length()));\n\t\t}\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\tlong[][] mat; int n;\n\t\tpublic Matrix(long[][] 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 long[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\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 val = 0;\n\t\t\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\t\t\tval += mat[i][k] * m.mat[k][j] % mod;\n\t\t\t\t\t\tval %= mod;\n\t\t\t\t\t}\n\t\t\t\t\tres[i][j] = val;\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\tlong[] mult(long[] vec) {\n\t\t\tlong[] res = new long[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\tres[i] += vec[j] * mat[i][j] % mod;\n\t\t\t\t\tres[i] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tlong[] tmult(long[] vec) {\n\t\t\tlong[] res = new long[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\tres[j] += vec[i] * mat[i][j] % mod;\n\t\t\t\t\tres[j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04290b59ebba8352e9eb64520452278e", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\npublic class F {\r\n\r\n\tstatic long mod = 998244353; \r\n\tpublic static void main(String[] args) {\r\n\t\tScanner sc = new Scanner(System.in);\r\n\t\tint n = sc.nextInt();\r\n\t\tint m = sc.nextInt();\r\n\t\t\r\n\t\tString[] s = new String[n];\r\n\t\tfor(int i = 0; i < n; i++) {\r\n\t\t\ts[i] = sc.next();\r\n\t\t}\t\r\n\t\t\r\n\t\tHashSet prefs = new HashSet<>();\r\n\t\tfor(int i = 0; i < n; i++){\r\n\t\t\tfor(int j = 1; j < s[i].length(); j++){\r\n\t\t\t\tprefs.add(s[i].substring(j));\r\n\t\t\t}\r\n\t\t}\r\n\t\tprefs.add(\"\");\r\n\t\tHashSet nodes = new HashSet<>();\r\n\t\tfor(String a: prefs){\r\n\t\t\tfor(String b: prefs){\r\n\t\t\t\tif(isPref(a, b)) {\r\n\t\t\t\t\tnodes.add(new Pair(a, b));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tint N = nodes.size();\r\n\t\tHashMap code = new HashMap<>();\r\n\t\tPair[] decode = new Pair[N];\r\n\t\tint count = 0;\r\n\t\tfor(Pair p: nodes) {\r\n\t\t\tdecode[count] = p;\r\n\t\t\tcode.put(p, count++);\r\n\t\t}\r\n\t\tlong[][] aut = new long[N][N];\r\n\t\tPair p0 = new Pair(\"\",\"\");\r\n\t\tfor(String t: s) {\r\n\t\t\tfor(String u: s) {\r\n\t\t\t\tif(isPref(t, u)) {\r\n\t\t\t\t\tString a = t.substring(1);\r\n\t\t\t\t\tString b = u.substring(1);\r\n\t\t\t\t\tPair p = new Pair(a, b);\r\n\t\t\t\t\taut[code.get(p0)][code.get(p)]++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(Pair p: nodes) {\r\n\t\t\tPair q = next(p);\r\n\t\t\tif(p.equals(p0)){\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\telse if(q != null) {\r\n\t\t\t\taut[code.get(p)][code.get(q)]++;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tfor(String t: s) {\r\n\t\t\t\t\tq = next(p, t);\r\n\t\t\t\t\tif(q != null && nodes.contains(q)) {\r\n\t\t\t\t\t\taut[code.get(p)][code.get(q)]++;\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\tMatrix mat = new Matrix(aut);\r\n\t\tMatrix matp = pow(mat, m);\r\n\t\tSystem.out.println(matp.mat[code.get(p0)][code.get(p0)]);\r\n\t}\r\n\tstatic Pair next(Pair p, String s) {\r\n\t\tif(p.a.equals(\"\")) {\r\n\t\t\tif(isPref(s, p.b)) {\r\n\t\t\t\tString a = s.substring(1);\r\n\t\t\t\tString b = p.b.substring(1);\r\n\t\t\t\treturn new Pair(a, b);\r\n\t\t\t}\r\n\t\t\telse return null;\r\n\t\t}\r\n\t\telse if(p.b.equals(\"\")) {\r\n\t\t\tif(isPref(s, p.a)) {\r\n\t\t\t\tString a = p.a.substring(1);\r\n\t\t\t\tString b = s.substring(1);\r\n\t\t\t\treturn new Pair(a, b);\r\n\t\t\t}\r\n\t\t\telse return null;\r\n\t\t}\r\n\t\telse return null;\r\n\t}\r\n\tstatic Pair next(Pair p) {\r\n\t\tif(p.a.equals(\"\")) return null;\r\n\t\tif(p.b.equals(\"\")) return null;\r\n\t\tString a = p.a.substring(1);\r\n\t\tString b = p.b.substring(1);\r\n\t\treturn new Pair(a, b);\r\n\t}\r\n\tstatic boolean isPref(String a, String b) {\r\n\t\tif(a.length() == b.length()) {\r\n\t\t\treturn a.equals(b);\r\n\t\t}\r\n\t\telse if(a.length() > b.length()) {\r\n\t\t\treturn b.equals(a.substring(0, b.length()));\r\n\t\t}\r\n\t\telse {\r\n\t\t\treturn a.equals(b.substring(0, a.length()));\r\n\t\t}\r\n\t}\r\n\tstatic class Pair {\r\n\t\tString a, b;\r\n\t\tpublic Pair(String a, String b) {\r\n\t\t\tthis.a = a; this.b = b;\r\n\t\t}\r\n\t\t@Override\r\n\t\tpublic int hashCode() {\r\n\t\t\treturn a.hashCode() + b.hashCode();\r\n\t\t}\r\n\t\t@Override\r\n\t\tpublic boolean equals(Object o) {\r\n\t\t\tPair p = (Pair)o;\r\n\t\t\treturn a.equals(p.a) && b.equals(p.b);\r\n\t\t}\r\n\t\tpublic String toString() {\r\n\t\t\treturn \"'\"+a+\"' '\"+b;\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic Matrix pow(Matrix m, int exp) {\r\n\t\tMatrix res = new Matrix(m.n);\r\n\t\tMatrix mapow = m;\r\n\t\twhile(exp > 0) {\r\n\t\t\tif((exp & 1) == 1) {\r\n\t\t\t\tres = res.mult(mapow);\r\n\t\t\t}\r\n\t\t\tmapow = mapow.mult(mapow);\r\n\t\t\texp >>= 1;\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\tstatic class Matrix{\r\n\t\tlong[][] mat; int n;\r\n\t\tpublic Matrix(long[][] mat) {\r\n\t\t\tn = mat.length;\r\n\t\t\tthis.mat = mat;\r\n\t\t}\r\n\t\tpublic Matrix(int n) {\r\n\t\t\tmat = new long[n][n];\r\n\t\t\tthis.n = n;\r\n\t\t\tfor(int i = 0; i < n; i++) mat[i][i] = 1;\r\n\t\t}\r\n\t\tMatrix mult(Matrix m) {\r\n\t\t\tlong[][] res = new long[n][n];\r\n\t\t\tfor(int k = 0; k < n; k++) {\r\n\t\t\t\tfor(int i = 0; i < n; i++) {\r\n\t\t\t\t\tfor(int j = 0; j < n; j++) {\r\n\t\t\t\t\t\tres[i][j] += mat[i][k] * m.mat[k][j] % mod;\r\n\t\t\t\t\t\tres[i][j] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn new Matrix(res);\r\n\t\t}\r\n\t\tpublic String toString(){\r\n\t\t\tStringBuilder sb = new StringBuilder();\r\n\t\t\tfor(int i = 0; i < n; i++) {\r\n\t\t\t\tsb.append(Arrays.toString(mat[i])+\"\\n\");\r\n\t\t\t}\r\n\t\t\treturn sb.toString();\r\n\t\t}\r\n\t\tlong[] mult(long[] vec) {\r\n\t\t\tlong[] res = new long[n];\r\n\t\t\tfor(int i = 0; i < n; i++) {\r\n\t\t\t\tfor(int j = 0; j < n; j++) {\r\n\t\t\t\t\tres[i] += vec[j] * mat[i][j] % mod;\r\n\t\t\t\t\tres[i] %= mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\t\tlong[] tmult(long[] vec) {\r\n\t\t\tlong[] res = new long[n];\r\n\t\t\tfor(int i = 0; i < n; i++) {\r\n\t\t\t\tfor(int j = 0; j < n; j++) {\r\n\t\t\t\t\tres[j] += vec[i] * mat[i][j] % mod;\r\n\t\t\t\t\tres[j] %= mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\t}\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b7efda82ccf3b15dfa59736c8075528", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "//package ecr107;\r\n\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 F {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n\r\n\tvoid solve()\r\n\t{\r\n\t\tint n = ni(), m = ni();\r\n\t\tchar[][] ss = new char[n][];\r\n\t\tString[] oss = new String[n];\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\tss[i] = ns().toCharArray();\r\n\t\t\toss[i] = new String(ss[i]);\r\n\t\t}\r\n\t\tint[] offset = new int[n+1];\r\n\t\toffset[0] = 1;\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\toffset[i+1] = offset[i] + ss[i].length-1;\r\n\t\t}\r\n\t\tint U = offset[n]-1;\r\n\r\n\t\tfinal int D = 5;\r\n\t\tint[][] M = new int[(2*U+1)*D][(2*U+1)*D];\r\n//\t\ttr(offset);\r\n\t\tfor(int i = 0;i < 2*U+1;i++){\r\n\t\t\tint lb, of;\r\n\t\t\tif(i == 0) {\r\n\t\t\t\tlb = 0;\r\n\t\t\t\tof = 0;\r\n\t\t\t}else if(i < U+1) {\r\n\t\t\t\tlb = lowerBound(offset, i+1) - 1;\r\n\t\t\t\tof = i-offset[lb] + 1;\r\n\t\t\t}else {\r\n\t\t\t\tlb = lowerBound(offset, i-U + 1) - 1;\r\n\t\t\t\tof = i - U - offset[lb] + 1;\r\n\t\t\t}\r\n//\t\t\ttr(i, lb, of, U);\r\n\r\n\t\t\tif(i == 0){\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\t\t\tif(k != j && oss[k].startsWith(oss[j])){\r\n\t\t\t\t\t\t\tM[offset[k]+ss[j].length-1][0+(2*U+1)*(ss[j].length-1)] = 1;\r\n\t\t\t\t\t\t\tM[offset[k]+U+ss[j].length-1][0+(2*U+1)*(ss[j].length-1)] = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tM[0][0+(2*U+1)*(ss[j].length-1)] += 1;\r\n\t\t\t\t}\r\n\t\t\t}else if(i < U+1){\r\n\t\t\t\t// r: 0 -> 0\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[lb].substring(of).equals(oss[j])){\r\n\t\t\t\t\t\tM[0][i+(2*U+1)*(oss[j].length()-1)] += 1;\r\n\t\t\t\t\t}else if(oss[lb].substring(of).startsWith(oss[j])){\r\n\t\t\t\t\t\tM[i+oss[j].length()][i+(2*U+1)*(oss[j].length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// l: -> 0\r\n\t\t\t\tString suf = oss[lb].substring(of);\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[j].startsWith(suf) && !oss[j].equals(suf)){\r\n\t\t\t\t\t\tM[U+offset[j]+suf.length()-1][i+(2*U+1)*(suf.length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\t// l: 0 -> 0\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[lb].substring(of).equals(oss[j])){\r\n\t\t\t\t\t\tM[0][i+(2*U+1)*(oss[j].length()-1)] += 1;\r\n\t\t\t\t\t}else if(oss[lb].substring(of).startsWith(oss[j])){\r\n\t\t\t\t\t\tM[i+oss[j].length()][i+(2*U+1)*(oss[j].length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// r: -> 0\r\n\t\t\t\tString suf = oss[lb].substring(of);\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[j].startsWith(suf) && !oss[j].equals(suf)){\r\n\t\t\t\t\t\tM[offset[j]+suf.length()-1][i+(2*U+1)*(suf.length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(int i = 0;i < 2*U+1;i++){\r\n\t\t\tfor(int j = 0;j < D-1;j++){\r\n\t\t\t\tM[i+(2*U+1)*(j+1)][i+(2*U+1)*j] = 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n//\t\tfor(int[] row : M){\r\n//\t\t\ttr(row);\r\n//\t\t}\r\n\r\n\t\tint[] v = new int[(2*U+1)*D];\r\n\t\tv[0] = 1;\r\n\t\tv = pow(M, v, m);\r\n//\t\tfor(int i = 1;i < U+1;i++){\r\n//\t\t\tif(v[i] != v[i+U]){\r\n//\t\t\t\ttr(\"diff\", i, i+U, v[i], v[i+U]);\r\n//\t\t\t}\r\n//\t\t}\r\n//\t\ttr(v);\r\n\t\tout.println(v[0]);\r\n\t}\r\n\r\n\t///////// begin\r\n\tpublic static final int mod = 998244353;\r\n\tpublic static final long m2 = (long)mod*mod;\r\n\tpublic static final long BIG = 8L*m2;\r\n\r\n\t// A^e*v\r\n\tpublic static int[] pow(int[][] A, int[] v, long e)\r\n\t{\r\n\t\tfor(int i = 0;i < v.length;i++){\r\n\t\t\tif(v[i] >= mod)v[i] %= mod;\r\n\t\t}\r\n\t\tint[][] MUL = A;\r\n\t\tfor(;e > 0;e>>>=1) {\r\n\t\t\tif((e&1)==1)v = mul(MUL, v);\r\n\t\t\tMUL = p2(MUL);\r\n\t\t}\r\n\t\treturn v;\r\n\t}\r\n\r\n\t// int matrix*int vector\r\n\tpublic static int[] mul(int[][] A, int[] v)\r\n\t{\r\n\t\tint m = A.length;\r\n\t\tint n = v.length;\r\n\t\tint[] w = new int[m];\r\n\t\tfor(int i = 0;i < m;i++){\r\n\t\t\tlong sum = 0;\r\n\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\tsum += (long)A[i][k] * v[k];\r\n\t\t\t\tif(sum >= BIG)sum -= BIG;\r\n\t\t\t}\r\n\t\t\tw[i] = (int)(sum % mod);\r\n\t\t}\r\n\t\treturn w;\r\n\t}\r\n\r\n\t// int matrix^2 (be careful about negative value)\r\n\tpublic static int[][] p2(int[][] A)\r\n\t{\r\n\t\tint n = A.length;\r\n\t\tint[][] C = new int[n][n];\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\tlong[] sum = new long[n];\r\n\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tsum[j] += (long)A[i][k] * A[k][j];\r\n\t\t\t\t\tif(sum[j] >= BIG)sum[j] -= BIG;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\tC[i][j] = (int)(sum[j] % mod);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn C;\r\n\t}\r\n\r\n\r\n\tpublic static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\r\n\tpublic static int lowerBound(int[] a, int l, int r, int v)\r\n\t{\r\n\t\tif(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\r\n\t\tint low = l-1, high = r;\r\n\t\twhile(high-low > 1){\r\n\t\t\tint h = high+low>>>1;\r\n\t\t\tif(a[h] >= v){\r\n\t\t\t\thigh = h;\r\n\t\t\t}else{\r\n\t\t\t\tlow = h;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn high;\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new F().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a542ab4d629b4e2016dc8d877f780d09", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "//package ecr107;\r\n\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\r\n\tvoid solve()\r\n\t{\r\n\t\tint n = ni(), m = ni();\r\n\t\tchar[][] ss = new char[n][];\r\n\t\tString[] oss = new String[n];\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\tss[i] = ns().toCharArray();\r\n\t\t\toss[i] = new String(ss[i]);\r\n\t\t}\r\n\t\tint[] offset = new int[n+1];\r\n\t\toffset[0] = 1;\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\toffset[i+1] = offset[i] + ss[i].length-1;\r\n\t\t}\r\n\t\tint U = offset[n]-1;\r\n\r\n\t\tfinal int D = 5;\r\n\t\tint[][] M = new int[(U+1)*D][(U+1)*D];\r\n//\t\ttr(offset);\r\n\t\tfor(int i = 0;i < U+1;i++){\r\n\t\t\tint lb, of;\r\n\t\t\tif(i == 0) {\r\n\t\t\t\tlb = 0;\r\n\t\t\t\tof = 0;\r\n\t\t\t}else{\r\n\t\t\t\tlb = lowerBound(offset, i+1) - 1;\r\n\t\t\t\tof = i-offset[lb] + 1;\r\n\t\t\t}\r\n//\t\t\ttr(i, lb, of, U);\r\n\r\n\t\t\tif(i == 0){\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\t\t\tif(k != j && oss[k].startsWith(oss[j])){\r\n\t\t\t\t\t\t\tM[offset[k]+ss[j].length-1][0+(U+1)*(ss[j].length-1)] = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tM[0][0+(U+1)*(ss[j].length-1)] += 1;\r\n\t\t\t\t}\r\n\t\t\t}else{\r\n\t\t\t\t// r: 0 -> 0\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[lb].substring(of).equals(oss[j])){\r\n\t\t\t\t\t\tM[0][i+(U+1)*(oss[j].length()-1)] += 2;\r\n\t\t\t\t\t}else if(oss[lb].substring(of).startsWith(oss[j])){\r\n\t\t\t\t\t\tM[i+oss[j].length()][i+(U+1)*(oss[j].length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// l: -> 0\r\n\t\t\t\tString suf = oss[lb].substring(of);\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[j].startsWith(suf) && !oss[j].equals(suf)){\r\n\t\t\t\t\t\tM[offset[j]+suf.length()-1][i+(U+1)*(suf.length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(int i = 0;i < U+1;i++){\r\n\t\t\tfor(int j = 0;j < D-1;j++){\r\n\t\t\t\tM[i+(U+1)*(j+1)][i+(U+1)*j] = 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n//\t\tfor(int[] row : M){\r\n//\t\t\ttr(row);\r\n//\t\t}\r\n\r\n\t\tint[] v = new int[(U+1)*D];\r\n\t\tv[0] = 1;\r\n\t\tv = pow(M, v, m);\r\n//\t\tfor(int i = 1;i < U+1;i++){\r\n//\t\t\tif(v[i] != v[i+U]){\r\n//\t\t\t\ttr(\"diff\", i, i+U, v[i], v[i+U]);\r\n//\t\t\t}\r\n//\t\t}\r\n//\t\ttr(v);\r\n\t\tout.println(v[0]);\r\n\t}\r\n\r\n\t///////// begin\r\n\tpublic static final int mod = 998244353;\r\n\tpublic static final long m2 = (long)mod*mod;\r\n\tpublic static final long BIG = 8L*m2;\r\n\r\n\t// A^e*v\r\n\tpublic static int[] pow(int[][] A, int[] v, long e)\r\n\t{\r\n\t\tfor(int i = 0;i < v.length;i++){\r\n\t\t\tif(v[i] >= mod)v[i] %= mod;\r\n\t\t}\r\n\t\tint[][] MUL = A;\r\n\t\tfor(;e > 0;e>>>=1) {\r\n\t\t\tif((e&1)==1)v = mul(MUL, v);\r\n\t\t\tMUL = p2(MUL);\r\n\t\t}\r\n\t\treturn v;\r\n\t}\r\n\r\n\t// int matrix*int vector\r\n\tpublic static int[] mul(int[][] A, int[] v)\r\n\t{\r\n\t\tint m = A.length;\r\n\t\tint n = v.length;\r\n\t\tint[] w = new int[m];\r\n\t\tfor(int i = 0;i < m;i++){\r\n\t\t\tlong sum = 0;\r\n\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\tsum += (long)A[i][k] * v[k];\r\n\t\t\t\tif(sum >= BIG)sum -= BIG;\r\n\t\t\t}\r\n\t\t\tw[i] = (int)(sum % mod);\r\n\t\t}\r\n\t\treturn w;\r\n\t}\r\n\r\n\t// int matrix^2 (be careful about negative value)\r\n\tpublic static int[][] p2(int[][] A)\r\n\t{\r\n\t\tint n = A.length;\r\n\t\tint[][] C = new int[n][n];\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\tlong[] sum = new long[n];\r\n\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tsum[j] += (long)A[i][k] * A[k][j];\r\n\t\t\t\t\tif(sum[j] >= BIG)sum[j] -= BIG;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\tC[i][j] = (int)(sum[j] % mod);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn C;\r\n\t}\r\n\r\n\r\n\tpublic static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\r\n\tpublic static int lowerBound(int[] a, int l, int r, int v)\r\n\t{\r\n\t\tif(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\r\n\t\tint low = l-1, high = r;\r\n\t\twhile(high-low > 1){\r\n\t\t\tint h = high+low>>>1;\r\n\t\t\tif(a[h] >= v){\r\n\t\t\t\thigh = h;\r\n\t\t\t}else{\r\n\t\t\t\tlow = h;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn high;\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new F2().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "521abde700dca5809b55a9b87d5d19ca", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String[] args) {\n\t\t(new Thread(new Solution())).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString r = in.readLine();\n\t\t\tif (r == null) return null;\n\t\t\tst = new StringTokenizer(r);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tclass Edge {\n\t\tint b, e, n;\n\t\tEdge pr, nt, r;\n\t\tEdge(int bb, int ee, int nn, Edge rr, Edge tt) {\n\t\t\tb = bb; e = ee; n = nn; pr = rr; nt = tt;\n\t\t\tr = null;\n\t\t}\n\t}\n\t\n\tEdge[] v;\n\tEdge cycleEdge;\n\tint[] ss;\n\t\n\tEdge addedge(int b, int e, int n) {\n\t\tEdge r = new Edge(b, e, n, null, v[b]);\n\t\tif (v[b] == null) v[b] = r; else v[b] = v[b].pr = r;\n\t\tr = new Edge(e, b, n, null, v[e]);\n\t\tif (v[e] == null) v[e] = r; else v[e] = v[e].pr = r; \n\t\tv[b].r = v[e]; v[e].r = v[b];\n\t\tif (get(b) != get(e)) uni(b, e); else cycleEdge = v[e];\n\t\tss[b]++; ss[e]++;\n\t\treturn v[b];\n\t}\n\t\n\tint[] dsu;\n\tint[] rank;\n\tQueue cc, cp, anss;\n\n\tint get(int q) {\n\t\tif (dsu[q] != q) return dsu[q] = get(dsu[q]); else return q;\n\t}\n\t\n\tvoid uni(int a, int b) {\n\t\ta = get(a); b = get(b);\n\t\tif (rank[a] == rank[b]) rank[a]++;\n\t\tif (rank[a] > rank[b]) dsu[b] = a; else dsu[a] = b;\n\t}\n\t\n\tint[] w;\n\tboolean[] ww;\n\t\n\tvoid ansprint() {\n\t\tout.print(anss.size() + \" \");\n\t\twhile (!anss.isEmpty()) out.print(anss.poll() + \" \");\n\t\tout.println();\n\t}\n\t\n\tvoid changeEdge(Edge r, int b, int e) {\n\t\tif (r.b != b) changeEdge(r.r, b, e); else {\n\t\t\tansprint();\n\t\t\tout.println(r.n + \" \" + b + \" \" + e);\n\t\t\tr.e = e;\n\t\t\tif (r.r.pr == null) {\n\t\t\t\tv[r.r.b] = r.r.nt; \n\t\t\t} else {\n\t\t\t\tr.r.pr.nt = r.r.nt;\n\t\t\t}\n\t\t\tif (r.r.nt != null) r.r.nt.pr = r.r.pr;\n\t\t\tr.r.b = e;\n\t\t\tr.r.nt = v[e];\n\t\t\tr.r.pr = null;\n\t\t\tif (v[e] != null) v[e] = v[e].pr = r.r; else v[e] = r.r;\n\t\t}\n\t}\n\t\n\tvoid dfs(int q, int rr) {\n\t\tw[q] = 1;\n\t\tww[get(q)] = true;\n\t\tif (q != 1) anss.add(q);\n\t\tQueue obr = new LinkedList();\n\t\tfor (Edge r = v[q]; r != null; r = r.nt) {\n\t\t\tif (r.n != rr) {\n\t\t\t\tif (w[r.e] == 0) {\n\t\t\t\t\tdfs(r.e, r.n);\n\t\t\t\t\tanss.add(q);\n\t\t\t\t}\n\t\t\t\tobr.add(r);\n\t\t\t}\n\t\t}\n\t\twhile (!obr.isEmpty()) {\n\t\t\tint qq = -1;\n\t\t\twhile (!cc.isEmpty() && ww[cc.peek()]) cc.poll();\n\t\t\tif (cc.isEmpty()) {\n\t\t\t\twhile (!cp.isEmpty() && ww[cp.peek()]) cp.poll();\n\t\t\t\tif (!cp.isEmpty()) qq = cp.poll();\n\t\t\t} else qq = cc.poll();\n\t\t\tif (qq == -1) break;\n\t\t\tEdge r = obr.poll();\n\t\t\tchangeEdge(r, q, qq);\n\t\t\tdfs(qq, r.n);\n\t\t\tanss.add(q);\n\t\t}\n\t\tw[q] = 2;\n\t}\n\t\n\tEdge[] edges;\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (m == 0) {\n\t\t\tif (n == 1) {\n\t\t\t\tout.println(\"YES\");\n\t\t\t\tout.println(0);\n\t\t\t\tout.println(\"1 1\");\n\t\t\t} else {\n\t\t\t\tout.println(\"NO\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tv = new Edge[n + 1];\n\t\tdsu = new int[n + 1];\n\t\trank = new int[n + 1];\n\t\tss = new int[n + 1];\n\t\tedges = new Edge[m + 1];\n\t\tfor (int i = 1; i <= n; i++) dsu[i] = i;\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\tedges[i] = addedge(nextInt(), nextInt(), i);\n\t\t}\n\t\tcc = new LinkedList();\n\t\tcp = new LinkedList();\n\t\tint cs = 0;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tif (dsu[i] == i && i != get(1)) {\n\t\t\t\tcs++;\n\t\t\t}\n\t\tif (cs > m || cs == m && cycleEdge == null && ss[1] == 0) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(\"YES\");\n\t\t\tif (ss[1] == 0 && cycleEdge == null) cs++;\n\t\t\tout.println(cs);\n\t\t\tww = new boolean[n + 1];\n\t\t\tw = new int[n + 1];\n\t\t\tanss = new LinkedList();\n\t\t\tanss.add(1);\n\t\t\tif (ss[1] == 0) {\n\t\t\t\tif (cycleEdge != null) {\n\t\t\t\t\tchangeEdge(cycleEdge, cycleEdge.b, 1);\n\t\t\t\t} else {\n\t\t\t\t\tint j = 2;\n\t\t\t\t\twhile (ss[j] != 1) j++;\n\t\t\t\t\tchangeEdge(v[j], v[j].e, 1);\n\t\t\t\t\tcp.add(j);\n\t\t\t\t}\n\t\t\t\tfor (int i = 1; i <= n; i++) { dsu[i] = i; rank[i] = 0; ss[i] = 0; }\n\t\t\t\tfor (int i = 1; i <= m; i++) {\n\t\t\t\t\tint b = edges[i].b;\n\t\t\t\t\tint e = edges[i].e;\n\t\t\t\t\tif (get(b) != get(e)) uni(b, e); else cycleEdge = v[e];\n\t\t\t\t\tss[b]++; ss[e]++;\n\t\t\t\t}\n\t\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\t\tif (dsu[i] == i && i != get(1)) {\n\t\t\t\t\t\tif (rank[i] == 0) cp.add(i); else cc.add(i);\n\t\t\t\t\t}\n\t\t\t}\n\t\t\tdfs(1, 0);\n\t\t\tansprint();\n\t\t}\n\t}\n\t\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.UK);\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.flush();\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eb18a181f757faddfe08f1f2ff1345e4", "src_uid": "35a3513c8fe730a64f30c5daec27df05", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String[] args) {\n\t\t(new Thread(new Solution())).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString r = in.readLine();\n\t\t\tif (r == null) return null;\n\t\t\tst = new StringTokenizer(r);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tclass Edge {\n\t\tint b, e, n;\n\t\tEdge pr, nt, r;\n\t\tEdge(int bb, int ee, int nn, Edge rr, Edge tt) {\n\t\t\tb = bb; e = ee; n = nn; pr = rr; nt = tt;\n\t\t\tr = null;\n\t\t}\n\t}\n\t\n\tEdge[] v;\n\tEdge cycleEdge;\n\tint[] ss;\n\t\n\tvoid addedge(int b, int e, int n) {\n\t\tEdge r = new Edge(b, e, n, null, v[b]);\n\t\tif (v[b] == null) v[b] = r; else v[b] = v[b].pr = r;\n\t\tr = new Edge(e, b, n, null, v[e]);\n\t\tif (v[e] == null) v[e] = r; else v[e] = v[e].pr = r; \n\t\tv[b].r = v[e]; v[e].r = v[b];\n\t\tif (get(b) != get(e)) uni(b, e); else cycleEdge = v[e];\n\t\tss[b]++; ss[e]++;\n\t}\n\t\n\tint[] dsu;\n\tint[] rank;\n\tQueue cc, cp, anss;\n\n\tint get(int q) {\n\t\tif (dsu[q] != q) return dsu[q] = get(dsu[q]); else return q;\n\t}\n\t\n\tvoid uni(int a, int b) {\n\t\ta = get(a); b = get(b);\n\t\tif (rank[a] == rank[b]) rank[a]++;\n\t\tif (rank[a] > rank[b]) dsu[b] = a; else dsu[a] = b;\n\t}\n\t\n\tint[] w;\n\tboolean[] ww;\n\t\n\tvoid ansprint() {\n\t\tout.print(anss.size() + \" \");\n\t\twhile (!anss.isEmpty()) out.print(anss.poll() + \" \");\n\t\tout.println();\n\t}\n\t\n\tvoid changeEdge(Edge r, int b, int e) {\n\t\tif (r.b != b) changeEdge(r.r, b, e); else {\n\t\t\tansprint();\n\t\t\tout.println(r.n + \" \" + b + \" \" + e);\n\t\t\tr.e = e;\n\t\t\tif (r.r.pr == null) {\n\t\t\t\tv[r.r.b] = r.r.nt; \n\t\t\t} else {\n\t\t\t\tr.r.pr.nt = r.r.nt;\n\t\t\t}\n\t\t\tif (r.r.nt != null) r.r.nt.pr = r.r.pr;\n\t\t\tr.r.b = e;\n\t\t\tr.r.nt = v[e];\n\t\t\tr.r.pr = null;\n\t\t\tif (v[e] != null) v[e] = v[e].pr = r.r; else v[e] = r.r;\n\t\t}\n\t}\n\t\n\tvoid dfs(int q, int rr) {\n\t\tw[q] = 1;\n\t\tww[get(q)] = true;\n\t\tif (q != 1) anss.add(q);\n\t\tQueue obr = new LinkedList();\n\t\tfor (Edge r = v[q]; r != null; r = r.nt) {\n\t\t\tif (r.n != rr) {\n\t\t\t\tif (w[r.e] == 0) {\n\t\t\t\t\tdfs(r.e, r.n);\n\t\t\t\t\tanss.add(q);\n\t\t\t\t}\n\t\t\t\tobr.add(r);\n\t\t\t}\n\t\t}\n\t\twhile (!obr.isEmpty()) {\n\t\t\tint qq = -1;\n\t\t\twhile (!cc.isEmpty() && ww[cc.peek()]) cc.poll();\n\t\t\tif (cc.isEmpty()) {\n\t\t\t\twhile (!cp.isEmpty() && ww[cp.peek()]) cp.poll();\n\t\t\t\tif (!cp.isEmpty()) qq = cp.poll();\n\t\t\t} else qq = cc.poll();\n\t\t\tif (qq == -1) break;\n\t\t\tEdge r = obr.poll();\n\t\t\tchangeEdge(r, q, qq);\n\t\t\tdfs(qq, r.n);\n\t\t\tanss.add(q);\n\t\t}\n\t\tw[q] = 2;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (m == 0) {\n\t\t\tif (n == 1) {\n\t\t\t\tout.println(\"YES\");\n\t\t\t\tout.println(0);\n\t\t\t\tout.println(\"1 1\");\n\t\t\t} else {\n\t\t\t\tout.println(\"NO\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tv = new Edge[n + 1];\n\t\tdsu = new int[n + 1];\n\t\trank = new int[n + 1];\n\t\tss = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++) dsu[i] = i;\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\taddedge(nextInt(), nextInt(), i);\n\t\t}\n\t\tcc = new LinkedList();\n\t\tcp = new LinkedList();\n\t\tint cs = 0;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tif (dsu[i] == i && i != get(1)) {\n\t\t\t\tcs++;\n\t\t\t\tif (rank[i] == 0) cp.add(i); else cc.add(i);\n\t\t\t}\n\t\tif (cs > m || cs == m && cycleEdge == null && ss[1] == 0) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(\"YES\");\n\t\t\tif (ss[1] == 0 && cycleEdge == null) cs++;\n\t\t\tout.println(cs);\n\t\t\tww = new boolean[n + 1];\n\t\t\tw = new int[n + 1];\n\t\t\tanss = new LinkedList();\n\t\t\tanss.add(1);\n\t\t\tif (ss[1] == 0) {\n\t\t\t\tif (cycleEdge != null) {\n\t\t\t\t\tchangeEdge(cycleEdge, cycleEdge.b, 1);\n\t\t\t\t} else {\n\t\t\t\t\tint j = 2;\n\t\t\t\t\twhile (ss[j] != 1) j++;\n\t\t\t\t\tchangeEdge(v[j], v[j].e, 1);\n\t\t\t\t\tcp.add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t\tdfs(1, 0);\n\t\t\tansprint();\n\t\t}\n\t}\n\t\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.UK);\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.flush();\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "78598f3c708217d8afba5921d86bfd7c", "src_uid": "35a3513c8fe730a64f30c5daec27df05", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String[] args) {\n\t\t(new Thread(new Solution())).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString r = in.readLine();\n\t\t\tif (r == null) return null;\n\t\t\tst = new StringTokenizer(r);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tclass Edge {\n\t\tint b, e, n;\n\t\tboolean move;\n\t\tEdge pr, nt, r;\n\t\tEdge(int bb, int ee, int nn, Edge rr, Edge tt) {\n\t\t\tb = bb; e = ee; n = nn; pr = rr; nt = tt;\n\t\t\tr = null;\n\t\t\tmove = false;\n\t\t}\n\t}\n\t\n\tEdge[] v;\n\tEdge cycleEdge;\n\tint[] ss;\n\t\n\tEdge addedge(int b, int e, int n) {\n\t\tEdge r = new Edge(b, e, n, null, v[b]);\n\t\tif (v[b] == null) v[b] = r; else v[b] = v[b].pr = r;\n\t\tr = new Edge(e, b, n, null, v[e]);\n\t\tif (v[e] == null) v[e] = r; else v[e] = v[e].pr = r; \n\t\tv[b].r = v[e]; v[e].r = v[b];\n\t\tif (get(b) != get(e)) uni(b, e); else cycleEdge = v[e];\n\t\tss[b]++; ss[e]++;\n\t\treturn v[b];\n\t}\n\t\n\tint[] dsu;\n\tint[] rank;\n\tQueue cc, cp, anss;\n\n\tint get(int q) {\n\t\tif (dsu[q] != q) return dsu[q] = get(dsu[q]); else return q;\n\t}\n\t\n\tvoid uni(int a, int b) {\n\t\ta = get(a); b = get(b);\n\t\tif (rank[a] == rank[b]) rank[a]++;\n\t\tif (rank[a] > rank[b]) dsu[b] = a; else dsu[a] = b;\n\t}\n\t\n\tint[] w;\n\tboolean[] ww;\n\t\n\tvoid ansprint() {\n\t\tout.print(anss.size() + \" \");\n\t\twhile (!anss.isEmpty()) out.print(anss.poll() + \" \");\n\t\tout.println();\n\t}\n\t\n\tvoid changeEdge(Edge r, int b, int e) {\n\t\tif (r.b != b) changeEdge(r.r, b, e); else {\n\t\t\tansprint();\n\t\t\tout.println(r.n + \" \" + b + \" \" + e);\n\t\t\tr.e = e;\n\t\t\tif (r.r.pr == null) {\n\t\t\t\tv[r.r.b] = r.r.nt; \n\t\t\t} else {\n\t\t\t\tr.r.pr.nt = r.r.nt;\n\t\t\t}\n\t\t\tif (r.r.nt != null) r.r.nt.pr = r.r.pr;\n\t\t\tr.r.b = e;\n\t\t\tr.r.nt = v[e];\n\t\t\tr.r.pr = null;\n\t\t\tif (v[e] != null) v[e] = v[e].pr = r.r; else v[e] = r.r;\n\t\t\tr.move = r.r.move = true;\n\t\t}\n\t}\n\t\n\tvoid dfs(int q, int rr) {\n\t\tw[q] = 1;\n\t\tww[get(q)] = true;\n\t\tif (q != 1) anss.add(q);\n\t\tQueue obr = new LinkedList();\n\t\tfor (Edge r = v[q]; r != null; r = r.nt) {\n\t\t\tif (r.n != rr) {\n\t\t\t\tif (w[r.e] == 0) {\n\t\t\t\t\tdfs(r.e, r.n);\n\t\t\t\t\tanss.add(q);\n\t\t\t\t}\n\t\t\t\tif (!r.move) obr.add(r);\n\t\t\t}\n\t\t}\n\t\twhile (!obr.isEmpty()) {\n\t\t\tint qq = -1;\n\t\t\twhile (!cc.isEmpty() && ww[cc.peek()]) cc.poll();\n\t\t\tif (cc.isEmpty()) {\n\t\t\t\twhile (!cp.isEmpty() && ww[cp.peek()]) cp.poll();\n\t\t\t\tif (!cp.isEmpty()) qq = cp.poll();\n\t\t\t} else qq = cc.poll();\n\t\t\tif (qq == -1) break;\n\t\t\tEdge r = obr.poll();\n\t\t\tchangeEdge(r, q, qq);\n\t\t\tdfs(qq, r.n);\n\t\t\tanss.add(q);\n\t\t}\n\t\tw[q] = 2;\n\t}\n\t\n\tEdge[] edges;\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (m == 0) {\n\t\t\tif (n == 1) {\n\t\t\t\tout.println(\"YES\");\n\t\t\t\tout.println(0);\n\t\t\t\tout.println(\"1 1\");\n\t\t\t} else {\n\t\t\t\tout.println(\"NO\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tv = new Edge[n + 1];\n\t\tdsu = new int[n + 1];\n\t\trank = new int[n + 1];\n\t\tss = new int[n + 1];\n\t\tedges = new Edge[m + 1];\n\t\tfor (int i = 1; i <= n; i++) dsu[i] = i;\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\tedges[i] = addedge(nextInt(), nextInt(), i);\n\t\t}\n\t\tcc = new LinkedList();\n\t\tcp = new LinkedList();\n\t\tint cs = 0;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tif (dsu[i] == i && i != get(1)) {\n\t\t\t\tcs++;\n\t\t\t}\n\t\tif (cs > m || cs == m && cycleEdge == null && ss[1] == 0) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(\"YES\");\n\t\t\tif (ss[1] == 0 && cycleEdge == null) cs++;\n\t\t\tout.println(cs);\n\t\t\tww = new boolean[n + 1];\n\t\t\tw = new int[n + 1];\n\t\t\tanss = new LinkedList();\n\t\t\tanss.add(1);\n\t\t\tif (ss[1] == 0) {\n\t\t\t\tif (cycleEdge != null) {\n\t\t\t\t\tchangeEdge(cycleEdge, cycleEdge.b, 1);\n\t\t\t\t} else {\n\t\t\t\t\tint j = 2;\n\t\t\t\t\twhile (ss[j] != 1 || ss[v[j].e] == 1) j++;\n\t\t\t\t\tchangeEdge(v[j], v[j].e, 1);\n\t\t\t\t\tcp.add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 1; i <= n; i++) { dsu[i] = i; rank[i] = 0; ss[i] = 0; }\n\t\t\tfor (int i = 1; i <= m; i++) {\n\t\t\t\tint b = edges[i].b;\n\t\t\t\tint e = edges[i].e;\n\t\t\t\tif (get(b) != get(e)) uni(b, e); else cycleEdge = v[e];\n\t\t\t\tss[b]++; ss[e]++;\n\t\t\t}\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\tif (dsu[i] == i && i != get(1)) {\n\t\t\t\t\tif (rank[i] == 0) cp.add(i); else cc.add(i);\n\t\t\t\t}\n\t\t\tdfs(1, 0);\n\t\t\tansprint();\n\t\t}\n\t}\n\t\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.UK);\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.flush();\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "98f23e0c9e0320aa00a44d8a9f975060", "src_uid": "35a3513c8fe730a64f30c5daec27df05", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String[] args) {\n\t\t(new Thread(new Solution())).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString r = in.readLine();\n\t\t\tif (r == null) return null;\n\t\t\tst = new StringTokenizer(r);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tclass Edge {\n\t\tint b, e, n;\n\t\tEdge pr, nt, r;\n\t\tEdge(int bb, int ee, int nn, Edge rr, Edge tt) {\n\t\t\tb = bb; e = ee; n = nn; pr = rr; nt = tt;\n\t\t\tr = null;\n\t\t}\n\t}\n\t\n\tEdge[] v;\n\tEdge cycleEdge;\n\tint[] ss;\n\t\n\tvoid addedge(int b, int e, int n) {\n\t\tEdge r = new Edge(b, e, n, null, v[b]);\n\t\tif (v[b] == null) v[b] = r; else v[b] = v[b].pr = r;\n\t\tr = new Edge(e, b, n, null, v[e]);\n\t\tif (v[e] == null) v[e] = r; else v[e] = v[e].pr = r; \n\t\tv[b].r = v[e]; v[e].r = v[b];\n\t\tif (get(b) != get(e)) uni(b, e); else cycleEdge = v[e];\n\t\tss[b]++; ss[e]++;\n\t}\n\t\n\tint[] dsu;\n\tint[] rank;\n\tQueue cc, cp, anss;\n\n\tint get(int q) {\n\t\tif (dsu[q] != q) return dsu[q] = get(dsu[q]); else return q;\n\t}\n\t\n\tvoid uni(int a, int b) {\n\t\ta = get(a); b = get(b);\n\t\tif (rank[a] == rank[b]) rank[a]++;\n\t\tif (rank[a] > rank[b]) dsu[b] = a; else dsu[a] = b;\n\t}\n\t\n\tint[] w;\n\tboolean[] ww;\n\t\n\tvoid ansprint() {\n\t\tout.print(anss.size() + \" \");\n\t\twhile (!anss.isEmpty()) out.print(anss.poll() + \" \");\n\t\tout.println();\n\t}\n\t\n\tvoid changeEdge(Edge r, int b, int e) {\n\t\tif (r.b != b) changeEdge(r.r, b, e); else {\n\t\t\tansprint();\n\t\t\tout.println(r.n + \" \" + b + \" \" + e);\n\t\t\tr.e = e;\n\t\t\tif (r.r.pr == null) {\n\t\t\t\tv[r.r.b] = r.r.nt; \n\t\t\t} else {\n\t\t\t\tr.r.pr.nt = r.r.nt;\n\t\t\t}\n\t\t\tif (r.r.nt != null) r.r.nt.pr = r.r.pr;\n\t\t\tr.r.b = b;\n\t\t\tr.r.nt = v[b];\n\t\t\tr.r.pr = null;\n\t\t\tv[b] = v[b].pr = r.r;\n\t\t}\n\t}\n\t\n\tvoid dfs(int q, int rr) {\n\t\tw[q] = 1;\n\t\tww[get(q)] = true;\n\t\tanss.add(q);\n\t\tQueue obr = new LinkedList();\n\t\tfor (Edge r = v[q]; r != null; r = r.nt) {\n\t\t\tif (r.n != rr) {\n\t\t\t\tif (w[r.e] == 0) {\n\t\t\t\t\tdfs(r.e, r.n);\n\t\t\t\t\tanss.add(q);\n\t\t\t\t}\n\t\t\t\tobr.add(r);\n\t\t\t}\n\t\t}\n\t\twhile (!obr.isEmpty()) {\n\t\t\tint qq = -1;\n\t\t\twhile (!cc.isEmpty() && ww[cc.peek()]) cc.poll();\n\t\t\tif (cc.isEmpty()) {\n\t\t\t\twhile (!cp.isEmpty() && ww[cp.peek()]) cp.poll();\n\t\t\t\tif (!cp.isEmpty()) qq = cp.poll();\n\t\t\t} else qq = cc.poll();\n\t\t\tif (qq == -1) break;\n\t\t\tEdge r = obr.poll();\n\t\t\tchangeEdge(r, q, qq);\n\t\t\tdfs(qq, r.n);\n\t\t\tanss.add(q);\n\t\t}\n\t\tw[q] = 2;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (m == 0) {\n\t\t\tif (n == 1) {\n\t\t\t\tout.println(\"YES\");\n\t\t\t\tout.println(0);\n\t\t\t\tout.println(\"1 1\");\n\t\t\t} else {\n\t\t\t\tout.println(\"NO\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tv = new Edge[n + 1];\n\t\tdsu = new int[n + 1];\n\t\trank = new int[n + 1];\n\t\tss = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++) dsu[i] = i;\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\taddedge(nextInt(), nextInt(), i);\n\t\t}\n\t\tcc = new LinkedList();\n\t\tcp = new LinkedList();\n\t\tint cs = 0;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tif (dsu[i] == i && i != get(1)) {\n\t\t\t\tcs++;\n\t\t\t\tif (rank[i] == 0) cp.add(i); else cc.add(i);\n\t\t\t}\n\t\tif (cs > m || cs == m && cycleEdge == null && ss[1] == 0) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(\"YES\");\n\t\t\tww = new boolean[n + 1];\n\t\t\tw = new int[n + 1];\n\t\t\tanss = new LinkedList();\n\t\t\tif (ss[1] == 0) {\n\t\t\t\tanss.add(1);\n\t\t\t\tif (cycleEdge != null) {\n\t\t\t\t\tchangeEdge(cycleEdge, 1, cycleEdge.e);\n\t\t\t\t} else {\n\t\t\t\t\tint j = 2;\n\t\t\t\t\twhile (ss[j] != 1) j++;\n\t\t\t\t\tchangeEdge(v[j], 1, v[j].e);\n\t\t\t\t\tcp.add(j);\n\t\t\t\t\tcs++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(cs);\n\t\t\tdfs(1, 0);\n\t\t\tansprint();\n\t\t}\n\t}\n\t\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.UK);\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.flush();\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ace3b4874eca3b8b865e0231089aaf9a", "src_uid": "35a3513c8fe730a64f30c5daec27df05", "difficulty": 2900.0} {"lang": "Java 8", "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 {\n int sideId;\n int x;\n double y;\n double distance = 1e100;\n boolean mark = false;\n\n List outgo = new ArrayList();\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 nodes = new ArrayList();\n Map canonical = new HashMap();\n\n static class Edge implements Comparable {\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 picture = new TreeSet();\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() {\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 reaches = new TreeSet();\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 {\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 }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "251c720fd922211275fa77875460156a", "src_uid": "ccc9d167caf5c4e3c7ab212bf4f5ca45", "difficulty": 3000.0} {"lang": "Java 6", "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 {\n int sideId;\n int x;\n double y;\n double distance = 1e100;\n boolean mark = false;\n\n List outgo = new ArrayList();\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 nodes = new ArrayList();\n Map canonical = new HashMap();\n\n static class Edge implements Comparable {\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 picture = new TreeSet();\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() {\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 reaches = new TreeSet();\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 {\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 }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f31e70b989cac28b0b4154d1c70ebd53", "src_uid": "ccc9d167caf5c4e3c7ab212bf4f5ca45", "difficulty": 3000.0} {"lang": "Java 6", "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 {\n int sideId;\n int x;\n double y;\n double distance = 1e100;\n boolean mark = false;\n\n List outgo = new ArrayList();\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 nodes = new ArrayList();\n Map canonical = new HashMap();\n\n static class Edge implements Comparable {\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 picture = new TreeSet();\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() {\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 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 addTransition(bEdge, dest, p.x);\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 addTransition(aEdge, dest, 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 && 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 addTransition(aEdge, dest, p.x);\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) {\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 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 addTransition(bEdge, dest, p.x);\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 addTransition(bEdge, dest, p.x);\n }\n }\n }\n pi = pj;\n }\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 GraphNode finish;\n {\n Point sp = poly[t];\n Point spa = poly[(t + 1) % poly.length];\n Point spb = poly[(t + poly.length - 1) % poly.length];\n if (spa.x != sp.x || spa.y > sp.y) {\n finish = createNode(new Edge(sp, spa), sp.x);\n } else {\n finish = createNode(new Edge(sp, spb), sp.x);\n }\n }\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 reaches = new TreeSet();\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 static class Reach implements Comparable {\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 void 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 }\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 }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "709351bb89757df470110f49a3613afe", "src_uid": "ccc9d167caf5c4e3c7ab212bf4f5ca45", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Problem131A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString x = sc.next();\n\t\tsc.close();\n\t\tchar[] y = x.toCharArray();\n\t\tboolean allcaps = true;\n\t\tboolean firstsmallrestcaps = true;\n\t\tfor (int i = 0; i < y.length; i++) {\n\t\t\tif (allcaps) {\n\t\t\t\tif ('a' <= y[i] && y[i] <= 'z') {\n\t\t\t\t\tallcaps = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (firstsmallrestcaps) {\n\t\t\t\tif (i == 0 && 'A' <= y[i] && y[i] <= 'Z') {\n\t\t\t\t\tfirstsmallrestcaps = false;\n\t\t\t\t} else if (i != 0 && 'a' <= y[i] && y[i] <= 'z') {\n\t\t\t\t\tfirstsmallrestcaps = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (allcaps || firstsmallrestcaps) {\n\t\t\tfor (int i = 0; i < y.length; i++) {\n\t\t\t\tif (y[i] >= 'A' && y[i] <= 'Z') {\n\t\t\t\t\ty[i] = (char) (y[i] + 'a' - 'A');\n\t\t\t\t} else {\n\t\t\t\t\ty[i] = (char) (y[i] + 'A' - 'a');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(y);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f7a9c790577db26b7329e0b50ee629f4", "src_uid": "ccc9d167caf5c4e3c7ab212bf4f5ca45", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class File1 {\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tint MOD = 1000000007;\n\t\tint k = in.nextInt();\n\t\tlong l = in.nextLong();\n\t\tlong r = in.nextLong();\n\t\tlong m = r-l+1;\n\t\tint n = (int)m;\n\t\tlong pow[] = new long[n+1];\n\t\tpow[0] = 1;\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tpow[i] = 2*pow[i-1];\n\t\t\tpow[i]%=MOD;\n\t\t}\n\t\tlong numPoss[] = new long[n];\n\t\tnumPoss[0] = 2;\n\t\tnumPoss[1] = 3;\t\t\n\t\tfor(int i=2;inumPoss[i])\n\t\t\t\tcontinue;\n\t\t\tif(k==numPoss[i]){\n\t\t\t\tans+=1;\n\t\t\t\tans%=MOD;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong temp = 1;\n\t\t\tfor(int j=0;j 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\tvoid solve()\n\t{\n\t\tint K = ni();\n\t\tlong L = nl(), R = nl();\n\t\t\n\t\tint[][] fif = enumFIF(K+2, mod);\n\t\t\n\t\tlong[][] fs = new long[K+1][K+1];\n\t\tfs[0][0] = fif[1][K];\n\t\tfor(int i = 0;i < K;i++){\n\t\t\tfor(int j = 0;j <= i;j++){\n\t\t\t\tfs[i+1][j+1] += fs[i][j];\n\t\t\t\tif(fs[i+1][j+1] >= mod)fs[i+1][j+1] -= mod;\n\t\t\t\tfs[i+1][j] += fs[i][j] * (mod-i);\n\t\t\t\tfs[i+1][j] %= mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong ret = count(R+1, fs[K], fif) - count(L, fs[K], fif);\n\t\tif(ret < 0)ret += mod;\n\t\tout.println(ret);\n\t}\n\t\n\tlong count(long n, long[] fs, int[][] fif)\n\t{\n\t\tlong ret = 0;\n\t\tfor(int i = 0;i < fs.length;i++){\n\t\t\tret += fpowsum(i, n, mod, fif) * fs[i];\n\t\t\tret %= mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tlong fpowsum(int K, long n, int mod, int[][] fif)\n\t{\n\t\tExmod plus = Exmod.div(new Exmod(1,1),2);\n\t\tExmod[] pluss = new Exmod[K+1];\n\t\tpluss[0] = new Exmod(1);\n\t\tfor(int i = 1;i <= K;i++)pluss[i] = Exmod.mul(pluss[i-1], plus);\n\t\t\n\t\tExmod minus = Exmod.div(new Exmod(1,-1),2);\n\t\tExmod[] minuss = new Exmod[K+1];\n\t\tminuss[0] = new Exmod(1);\n\t\tfor(int i = 1;i <= K;i++)minuss[i] = Exmod.mul(minuss[i-1], minus);\n\t\t\n\t\tExmod ret = new Exmod(0);\n\t\tfor(int i = K, sig = 1;i >= 0;i--, sig = -sig){\n\t\t\tExmod ratio = Exmod.mul(pluss[i], minuss[K-i]);\n\t\t\tret.add(Exmod.mul(Exmod.sumgp(ratio, n+2), C(K, i, mod, fif) * sig));\n\t\t}\n\t\t\n\t\tExmod fifth = Exmod.pow(Exmod.inv(new Exmod(0, 1)), K);\n\t\tret.mul(fifth);\n\t\t\n\t\tassert ret.b == 0;\n\t\treturn ret.a;\n\t}\n\t\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\n\t\tif (n < 0 || r < 0 || r > n)\n\t\t\treturn 0;\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\n\t}\n\t\n\tpublic static class Exmod {\n\t\tpublic long a, b;\n\t\tpublic static final long E = 5;\n\t\tpublic static final int mod = 1000000007;\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\tif(a == 0 && b == 0)return \"0\";\n\t\t\tStringBuilder ret = new StringBuilder();\n\t\t\tif(a != 0){\n\t\t\t\tret.append(a);\n\t\t\t\tif(b > 0)ret.append(\"+\");\n\t\t\t}\n\t\t\tif(b != 0)ret.append(b + \"\u221a\" + E);\n\t\t\treturn ret.toString();\n\t\t}\n\n\t\tpublic Exmod(long a) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = 0;\n\t\t\tnormalize();\n\t\t}\n\t\t\n\t\tpublic Exmod(long a, long b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t\tnormalize();\n\t\t}\n\t\t\n\t\tpublic Exmod(Exmod e) {\n\t\t\tthis.a = e.a;\n\t\t\tthis.b = e.b;\n\t\t\tnormalize();\n\t\t}\n\t\t\n\t\tpublic void normalize(){\n\t\t\tif(a >= mod || a < 0){\n\t\t\t\ta %= mod;\n\t\t\t\tif(a < 0)a += mod;\n\t\t\t}\n\t\t\tif(b >= mod || b < 0){\n\t\t\t\tb %= mod;\n\t\t\t\tif(b < 0)b += mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic Exmod add(Exmod t){ a += t.a; b += t.b; normalize(); return this; }\n\t\tpublic Exmod sub(Exmod t){ a -= t.a; b -= t.b; normalize(); return this; }\n\t\tpublic Exmod mul(Exmod t){\n\t\t\tlong na = a * t.a + b * t.b * E;\n\t\t\tlong nb = a * t.b + b * t.a;\n\t\t\ta = na; b = nb; normalize(); return this;\n\t\t}\n\t\tpublic Exmod div(Exmod t){\n\t\t\tlong den = t.a*t.a-E*t.b*t.b;\n\t\t\tden %= mod; if(den < 0)den += mod;\n\t\t\tlong iden = invl(den, mod);\n\t\t\tlong numr = (a*t.a - b*t.b*E) % mod * iden % mod;\n\t\t\tlong numi = (b*t.a - a*t.b) % mod * iden % mod;\n\t\t\ta = numr; b = numi; normalize(); return this;\n\t\t}\n\t\tpublic Exmod negate(){ a = -a; b = -b; normalize(); return this; }\n\n\t\tpublic static Exmod negate(Exmod a){ return new Exmod(-a.a, -a.b);}\n\t\tpublic static Exmod add(Exmod a, Exmod b){return new Exmod(a.a + b.a, a.b + b.b);}\n\t\tpublic static Exmod sub(Exmod a, Exmod b){return new Exmod(a.a - b.a, a.b - b.b);}\n\t\tpublic static Exmod mul(Exmod a, Exmod b){return new Exmod(a.a * b.a + a.b * b.b * E, a.a * b.b + a.b * b.a);}\n\t\tpublic static Exmod div(Exmod a, Exmod b){\n\t\t\tlong den = b.a*b.a-E*b.b*b.b;\n\t\t\tden %= mod; if(den < 0)den += mod;\n\t\t\tlong iden = invl(den, mod);\n\t\t\tlong numr = (a.a*b.a - a.b*b.b*E) % mod * iden % mod;\n\t\t\tif(numr < 0)numr += mod;\n\t\t\tlong numi = (a.b*b.a - a.a*b.b) % mod * iden % mod;\n\t\t\tif(numi < 0)numi += mod;\n\t\t\treturn new Exmod(numr, numi);\n\t\t}\n\t\t\n\t\tpublic static Exmod inv(Exmod a){\n\t\t\tlong den = a.a*a.a-E*a.b*a.b;\n\t\t\tden %= mod; if(den < 0)den += mod;\n\t\t\tlong iden = invl(den, mod);\n\t\t\tlong numr = a.a * iden % mod;\n\t\t\tlong numi = -a.b * iden % mod;\n\t\t\tif(numi < 0)numi += mod;\n\t\t\treturn new Exmod(numr, numi);\n\t\t}\n\t\t\n\t\t// a+bx (a+bx)(c-dx) (ac-bdE)+x(bc-ad)\n\t\t// ----=------------=-----------------\n\t\t// c+dx (c+dx)(c-dx) c^2-Ed^2\n\t\t\n\t\tpublic static Exmod mul(Exmod a, long b){return new Exmod(a.a * b, a.b * b);}\n\t\tpublic static Exmod div(Exmod a, long b){return mul(a, invl(b, mod));}\n\t\t\n\t\tpublic static Exmod pow(Exmod a, long n) {\n\t\t\tExmod ret = new Exmod(1);\n\t\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\t\tfor (; x >= 0; x--) {\n\t\t\t\tret = mul(ret, ret);\n\t\t\t\tif(n<<~x<0)ret = mul(ret, a);\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static Exmod sumgp(Exmod a, long n)\n\t\t{\n\t\t\tExmod mul = new Exmod(1);\n\t\t\tExmod ret = new Exmod(0);\n\t\t\tfor(int i = 63-Long.numberOfLeadingZeros(n);i >= 0;i--){\n\t\t\t\tmul.a += 1;\n\t\t\t\tret = mul(ret, mul);\n\t\t\t\tmul.a -= 1;\n\t\t\t\tmul = mul(mul, mul);\n\t\t\t\tif(n<<~i<0){\n\t\t\t\t\tret = mul(ret, a);\n\t\t\t\t\tret.a++; ret.normalize();\n\t\t\t\t\tmul = mul(mul, a);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static long invl(long a, long mod) {\n\t\t\tlong b = mod;\n\t\t\tlong p = 1, q = 0;\n\t\t\twhile (b > 0) {\n\t\t\t\tlong c = a / b;\n\t\t\t\tlong d;\n\t\t\t\td = a;\n\t\t\t\ta = b;\n\t\t\t\tb = d % b;\n\t\t\t\td = p;\n\t\t\t\tp = q;\n\t\t\t\tq = d - c * q;\n\t\t\t}\n\t\t\treturn p < 0 ? p + mod : p;\n\t\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 A5().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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "36d548efe8fe36d7d95d6eb507740b27", "src_uid": "dee552588e1281c2523868cd4090b46f", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n long mod = (long) 1e9 + 7;\n\n class Num {\n final long a, b;\n\n public Num(long a, long b) {\n this.a = a % mod;\n this.b = b % mod;\n }\n\n public Num add(Num other) {\n return new Num(a + other.a, b + other.b);\n }\n\n public Num multiply(Num other) {\n return new Num(a * other.a + 5 * b * other.b, a * other.b + b * other.a);\n }\n }\n\n int k;\n\n long[][] coeffs;\n\n void prepare() {\n coeffs = new long[k + 1][k + 1];\n long[][] tmpCoeffs = new long[k + 1][k + 1];\n long factK = 1;\n coeffs[0][0] = 1;\n\n for (int free = 0; free < k; free++) {\n factK = factK * (free + 1) % mod;\n\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n if (coeffs[i][j] != 0) {\n tmpCoeffs[i + 1][j] += coeffs[i][j];\n if (tmpCoeffs[i + 1][j] >= mod) {\n tmpCoeffs[i + 1][j] -= mod;\n }\n\n tmpCoeffs[i][j + 1] += coeffs[i][j];\n if (tmpCoeffs[i][j + 1] >= mod) {\n tmpCoeffs[i][j + 1] -= mod;\n }\n\n long add = coeffs[i][j] * (mod - free) % mod;\n tmpCoeffs[i][j] += add;\n if (tmpCoeffs[i][j] >= mod) {\n tmpCoeffs[i][j] -= mod;\n }\n }\n }\n }\n\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n coeffs[i][j] = tmpCoeffs[i][j];\n tmpCoeffs[i][j] = 0;\n }\n }\n }\n\n factK = inv(factK);\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n coeffs[i][j] = coeffs[i][j] * factK % mod;\n }\n }\n// System.err.println(Arrays.deepToString(coeffs));\n\n pow1 = new Num[k + 1];\n powA = new Num[k + 1];\n pow2 = new Num[k + 1];\n powB = new Num[k + 1];\n\n pow1[0] = pow2[0] = powA[0] = powB[0] = new Num(1, 0);\n for (int i = 1; i <= k; i++) {\n pow1[i] = pow1[i - 1].multiply(PHI1);\n pow2[i] = pow2[i - 1].multiply(PHI2);\n powA[i] = powA[i - 1].multiply(A);\n powB[i] = powB[i - 1].multiply(B);\n }\n }\n\n long inv(long x) {\n return pow(x, mod - 2);\n }\n\n long pow(long a, long b) {\n long res = 1;\n while (b != 0) {\n if ((b & 1) == 1) {\n res = res * a % mod;\n }\n a = a * a % mod;\n b >>>= 1;\n }\n return res;\n }\n\n final Num PHI1 = new Num(inv(2), inv(2));\n final Num PHI2 = new Num(inv(2), mod - inv(2));\n final Num A = new Num(0, inv(5));\n final Num B = new Num(0, mod - inv(5));\n\n final Num ONE = new Num(1, 0);\n\n Num[] pow1, pow2, powA, powB;\n\n long get(long n) {\n Num result = new Num(0, 0);\n\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n long coef = coeffs[i][j];\n if (coef == 0) {\n continue;\n }\n\n Num cur = new Num(coef, 0).multiply(powA[i]).multiply(powB[j]);\n\n Num x = pow1[i].multiply(pow2[j]);\n x = geomSum(x, n + 1);\n\n result = result.add(cur.multiply(x));\n }\n }\n return result.a;\n }\n\n\n Num geomSum(Num x, long n) {\n if (n == 0) {\n return new Num(0, 0);\n }\n if (n % 2 == 0) {\n Num x2 = x.multiply(x);\n Num result = geomSum(x2, n / 2);\n return (ONE.add(x)).multiply(result);\n } else {\n return ONE.add(x.multiply(geomSum(x, n - 1)));\n }\n }\n\n public void solve() {\n k = in.nextInt();\n prepare();\n long l = in.nextLong(), r = in.nextLong();\n// for (int i = 0; i < 20; i++) {\n// Num fib = A.multiply(pow1[i]).add(B.multiply(pow2[i]));\n// System.err.println(fib.a + \" \" + fib.b);\n// System.err.println(get(i + 1) - get(i));\n// }\n out.println((get(r + 2) - get(l + 1) + mod) % mod);\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new A().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "52fae932944876532ed5ebfe807aff43", "src_uid": "dee552588e1281c2523868cd4090b46f", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "//package bubblecup9f;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class A5 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tfinal int mod = 1000000007;\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\tvoid solve()\n\t{\n\t\tint K = ni();\n\t\tlong L = nl(), R = nl();\n\t\t\n\t\tint[][] fif = enumFIF(K+2, mod);\n\t\t\n\t\tlong[][] fs = new long[K+1][K+1];\n\t\tfs[0][0] = fif[1][K];\n\t\tfor(int i = 0;i < K;i++){\n\t\t\tfor(int j = 0;j <= i;j++){\n\t\t\t\tfs[i+1][j+1] += fs[i][j];\n\t\t\t\tif(fs[i+1][j+1] >= mod)fs[i+1][j+1] -= mod;\n\t\t\t\tfs[i+1][j] += fs[i][j] * (mod-i);\n\t\t\t\tfs[i+1][j] %= mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong ret = count(R+1, fs[K], fif) - count(L, fs[K], fif);\n\t\tif(ret < 0)ret += mod;\n\t\tout.println(ret);\n\t}\n\t\n\tlong count(long n, long[] fs, int[][] fif)\n\t{\n\t\tlong ret = 0;\n\t\tfor(int i = 0;i < fs.length;i++){\n\t\t\tret += fpowsum(i, n, mod, fif) * fs[i];\n\t\t\tret %= mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tlong fpowsum(int K, long n, int mod, int[][] fif)\n\t{\n\t\tExmod plus = Exmod.div(new Exmod(1,1),2);\n\t\tExmod[] pluss = new Exmod[K+1];\n\t\tpluss[0] = new Exmod(1);\n\t\tfor(int i = 1;i <= K;i++)pluss[i] = Exmod.mul(pluss[i-1], plus);\n\t\t\n\t\tExmod minus = Exmod.div(new Exmod(1,-1),2);\n\t\tExmod[] minuss = new Exmod[K+1];\n\t\tminuss[0] = new Exmod(1);\n\t\tfor(int i = 1;i <= K;i++)minuss[i] = Exmod.mul(minuss[i-1], minus);\n\t\t\n\t\tExmod ret = new Exmod(0);\n\t\tfor(int i = K, sig = 1;i >= 0;i--, sig = -sig){\n\t\t\tExmod ratio = Exmod.mul(pluss[i], minuss[K-i]);\n\t\t\tret.add(Exmod.mul(Exmod.sumgp(ratio, n+2), C(K, i, mod, fif) * sig));\n\t\t}\n\t\t\n\t\tExmod fifth = Exmod.pow(Exmod.inv(new Exmod(0, 1)), K);\n\t\tret.mul(fifth);\n\t\t\n\t\tassert ret.b == 0;\n\t\treturn ret.a;\n\t}\n\t\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\n\t\tif (n < 0 || r < 0 || r > n)\n\t\t\treturn 0;\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\n\t}\n\t\n\tpublic static class Exmod {\n\t\tpublic long a, b;\n\t\tpublic static final long E = 5;\n\t\tpublic static final int mod = 1000000007;\n\t\t\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\tif(a == 0 && b == 0)return \"0\";\n\t\t\tStringBuilder ret = new StringBuilder();\n\t\t\tif(a != 0){\n\t\t\t\tret.append(a);\n\t\t\t\tif(b > 0)ret.append(\"+\");\n\t\t\t}\n\t\t\tif(b != 0)ret.append(b + \"\u221a\" + E);\n\t\t\treturn ret.toString();\n\t\t}\n\n\t\tpublic Exmod(long a) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = 0;\n\t\t\tnormalize();\n\t\t}\n\t\t\n\t\tpublic Exmod(long a, long b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t\tnormalize();\n\t\t}\n\t\t\n\t\tpublic Exmod(Exmod e) {\n\t\t\tthis.a = e.a;\n\t\t\tthis.b = e.b;\n\t\t\tnormalize();\n\t\t}\n\t\t\n\t\tpublic void normalize(){\n\t\t\tif(a >= mod || a < 0){\n\t\t\t\ta %= mod;\n\t\t\t\tif(a < 0)a += mod;\n\t\t\t}\n\t\t\tif(b >= mod || b < 0){\n\t\t\t\tb %= mod;\n\t\t\t\tif(b < 0)b += mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic Exmod add(Exmod t){ a += t.a; b += t.b; normalize(); return this; }\n\t\tpublic Exmod sub(Exmod t){ a -= t.a; b -= t.b; normalize(); return this; }\n\t\tpublic Exmod mul(Exmod t){\n\t\t\tlong na = a * t.a + b * t.b * E;\n\t\t\tlong nb = a * t.b + b * t.a;\n\t\t\ta = na; b = nb; normalize(); return this;\n\t\t}\n\t\tpublic Exmod div(Exmod t){\n\t\t\tlong den = t.a*t.a-E*t.b*t.b;\n\t\t\tden %= mod; if(den < 0)den += mod;\n\t\t\tlong iden = invl(den, mod);\n\t\t\tlong numr = (a*t.a - b*t.b*E) % mod * iden % mod;\n\t\t\tlong numi = (b*t.a - a*t.b) % mod * iden % mod;\n\t\t\ta = numr; b = numi; normalize(); return this;\n\t\t}\n\t\tpublic Exmod negate(){ a = -a; b = -b; normalize(); return this; }\n\n\t\tpublic static Exmod negate(Exmod a){ return new Exmod(-a.a, -a.b);}\n\t\tpublic static Exmod add(Exmod a, Exmod b){return new Exmod(a.a + b.a, a.b + b.b);}\n\t\tpublic static Exmod sub(Exmod a, Exmod b){return new Exmod(a.a - b.a, a.b - b.b);}\n\t\tpublic static Exmod mul(Exmod a, Exmod b){return new Exmod(a.a * b.a + a.b * b.b * E, a.a * b.b + a.b * b.a);}\n\t\tpublic static Exmod div(Exmod a, Exmod b){\n\t\t\tlong den = b.a*b.a-E*b.b*b.b;\n\t\t\tden %= mod; if(den < 0)den += mod;\n\t\t\tlong iden = invl(den, mod);\n\t\t\tlong numr = (a.a*b.a - a.b*b.b*E) % mod * iden % mod;\n\t\t\tif(numr < 0)numr += mod;\n\t\t\tlong numi = (a.b*b.a - a.a*b.b) % mod * iden % mod;\n\t\t\tif(numi < 0)numi += mod;\n\t\t\treturn new Exmod(numr, numi);\n\t\t}\n\t\t\n\t\tpublic static Exmod inv(Exmod a){\n\t\t\tlong den = a.a*a.a-E*a.b*a.b;\n\t\t\tden %= mod; if(den < 0)den += mod;\n\t\t\tlong iden = invl(den, mod);\n\t\t\tlong numr = a.a * iden % mod;\n\t\t\tlong numi = -a.b * iden % mod;\n\t\t\tif(numi < 0)numi += mod;\n\t\t\treturn new Exmod(numr, numi);\n\t\t}\n\t\t\n\t\t// a+bx (a+bx)(c-dx) (ac-bdE)+x(bc-ad)\n\t\t// ----=------------=-----------------\n\t\t// c+dx (c+dx)(c-dx) c^2-Ed^2\n\t\t\n\t\tpublic static Exmod mul(Exmod a, long b){return new Exmod(a.a * b, a.b * b);}\n\t\tpublic static Exmod div(Exmod a, long b){return mul(a, invl(b, mod));}\n\t\t\n\t\tpublic static Exmod pow(Exmod a, long n) {\n\t\t\tExmod ret = new Exmod(1);\n\t\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\t\tfor (; x >= 0; x--) {\n\t\t\t\tret = mul(ret, ret);\n\t\t\t\tif(n<<~x<0)ret = mul(ret, a);\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static Exmod sumgp(Exmod a, long n)\n\t\t{\n\t\t\tExmod mul = new Exmod(1);\n\t\t\tExmod ret = new Exmod(0);\n\t\t\tfor(int i = 63-Long.numberOfLeadingZeros(n);i >= 0;i--){\n\t\t\t\tmul.a += 1;\n\t\t\t\tret = mul(ret, mul);\n\t\t\t\tmul.a -= 1;\n\t\t\t\tmul = mul(mul, mul);\n\t\t\t\tif(n<<~i<0){\n\t\t\t\t\tret = mul(ret, a);\n\t\t\t\t\tret.a++; ret.normalize();\n\t\t\t\t\tmul = mul(mul, a);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static long invl(long a, long mod) {\n\t\t\tlong b = mod;\n\t\t\tlong p = 1, q = 0;\n\t\t\twhile (b > 0) {\n\t\t\t\tlong c = a / b;\n\t\t\t\tlong d;\n\t\t\t\td = a;\n\t\t\t\ta = b;\n\t\t\t\tb = d % b;\n\t\t\t\td = p;\n\t\t\t\tp = q;\n\t\t\t\tq = d - c * q;\n\t\t\t}\n\t\t\treturn p < 0 ? p + mod : p;\n\t\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 A5().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "407618bce313b4a23dd827233cf09697", "src_uid": "dee552588e1281c2523868cd4090b46f", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\npublic class E {\n String fileName = \"E\";\n\n public int n, m;\n\n public static class Event implements Comparable {\n public static final int OPEN_TYPE = 0;\n public static final int POINT_TYPE = 1;\n public static final int CLOSE_TYPE = 2;\n\n public int x, type;\n\n public Event(int x, int type) {\n this.x = x;\n this.type = type;\n }\n\n @Override\n public int compareTo(Event event) {\n if (Integer.compare(x, event.x) != 0)\n return Integer.compare(x, event.x);\n else return Integer.compare(type, event.type);\n }\n }\n\n public static final class Node {\n public int l, r;\n public int max, maxInd;\n\n public Node leftNode, rightNode;\n\n public Node(int l, int r) {\n this.l = l;\n this.r = r;\n }\n }\n\n public void relax(Node root) {\n if (root.leftNode.max > root.rightNode.max) {\n root.max = root.leftNode.max;\n root.maxInd = root.leftNode.maxInd;\n } else {\n root.max = root.rightNode.max;\n root.maxInd = root.rightNode.maxInd;\n }\n }\n\n public Node build(int l, int r, Function getItem) {\n Node res = new Node(l, r);\n if (l == r) {\n res.max = getItem.apply(l);\n res.maxInd = l;\n } else {\n int m = (r + l) / 2;\n res.leftNode = build(l, m, getItem);\n res.rightNode = build(m + 1, r, getItem);\n relax(res);\n }\n return res;\n }\n\n public void set(Node root, int ind, int val) {\n if (ind < root.l || ind > root.r)\n return;\n if (root.l == root.r) {\n root.max = val;\n return;\n }\n set(root.leftNode, ind, val);\n set(root.rightNode, ind, val);\n relax(root);\n }\n\n public static class QueryResult {\n public int max, maxInd;\n\n public QueryResult(int max, int maxInd) {\n this.max = max;\n this.maxInd = maxInd;\n }\n\n public QueryResult(QueryResult first, QueryResult second) {\n if (first.max > second.max) {\n this.max = first.max;\n this.maxInd = first.maxInd;\n } else {\n this.max = second.max;\n this.maxInd = second.maxInd;\n }\n }\n }\n\n public QueryResult query(Node root, int l, int r) {\n if (r == -1)\n return new QueryResult(0, -1);\n if (r < root.l || l > root.r)\n return new QueryResult(Integer.MIN_VALUE, -1);\n if (l <= root.l && r >= root.r) {\n return new QueryResult(root.max, root.maxInd);\n }\n return new QueryResult(query(root.leftNode, l, r), query(root.rightNode, l, r));\n }\n\n public int[] getLens(int[] a) {\n Node root = build(0, n, ind -> 0);\n int[] len = new int[a.length];\n for (int i = 0; i < a.length; i++) {\n int curVal = a[i];\n int prevLen = query(root, 0, curVal).max;\n len[i] = prevLen + 1;\n if (query(root, curVal, curVal).max < len[i])\n set(root, curVal, len[i]);\n }\n return len;\n }\n\n public void solve() throws IOException {\n n = nextInt();\n m = nextInt();\n Event[] events = new Event[2 * n + m];\n for (int i = 1; i <= m; i++) {\n events[i - 1] = new Event(i, Event.POINT_TYPE);\n }\n for (int i = 0; i < n; i++) {\n int l = nextInt();\n int r = nextInt();\n events[m + 2 * i] = new Event(l, Event.OPEN_TYPE);\n events[m + 2 * i + 1] = new Event(r, Event.CLOSE_TYPE);\n }\n Arrays.sort(events);\n int[] cnt = new int[m];\n int balance = 0;\n for (int i = 0; i < events.length; i++) {\n Event curEvent = events[i];\n if (curEvent.type == Event.OPEN_TYPE) {\n balance++;\n } else if (curEvent.type == Event.CLOSE_TYPE) {\n balance--;\n } else if (curEvent.type == Event.POINT_TYPE) {\n cnt[curEvent.x - 1] = balance;\n }\n }\n int[] lenUp = getLens(cnt);\n int[] newCnt = new int[cnt.length];\n for (int i = 0; i < cnt.length; i++) {\n newCnt[i] = cnt[cnt.length - i - 1];\n }\n int[] lenDown = getLens(newCnt);\n int[] revLenDown = new int[lenDown.length];\n for (int i = 0; i < lenDown.length; i++) {\n revLenDown[i] = lenDown[lenDown.length - i - 1];\n }\n int max = 0;\n for (int i = 0; i < n; i++) {\n int cur = lenUp[i] + revLenDown[i] - 1;\n max = Math.max(max, cur);\n }\n out.print(max);\n }\n\n public void run() {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n BufferedReader br;\n StringTokenizer in;\n PrintWriter out;\n\n public String nextToken() throws IOException {\n while (in == null || !in.hasMoreTokens()) {\n in = new StringTokenizer(br.readLine());\n }\n return in.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n new E().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7be22ffc37933d2cc49906e7f2dd7375", "src_uid": "ce8350be138ce2061349d7f9224a5aaf", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n ArrayList> q;\n boolean[] used;\n\n public void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n int[] a = new int[m + 1];\n for (int i = 0; i < n; i++) {\n a[nextInt() - 1]++;\n a[nextInt()]--;\n }\n for (int i = 1; i < m; i++) {\n a[i] += a[i - 1];\n }\n int[] d = new int[m + 10];\n Arrays.fill(d, Integer.MAX_VALUE);\n int k = 0;\n int[] v1 = new int[m + 1];\n int[] v2 = new int[m + 1];\n for (int i = 0; i < m; i++) {\n int l = 0;\n int r = m;\n while (r - l > 1) {\n int m1 = (r + l) / 2;\n if (d[m1] > a[i]) {\n r = m1;\n } else {\n l = m1;\n }\n }\n if (d[l] <= a[i]) {\n l++;\n }\n if (d[l] == Integer.MAX_VALUE){\n k++;\n }\n d[l] = a[i];\n v1[i] = k;\n }\n k = 0;\n int max = 0;\n for (int i = m - 1; i >= 0; i--) {\n int l = 0;\n int r = m + 2;\n while (r - l > 1) {\n int m1 = (r + l) / 2;\n if (d[m1] > a[i]) {\n r = m1;\n } else {\n l = m1;\n }\n }\n if (d[l] <= a[i]) {\n l++;\n }\n if (d[l] == Integer.MAX_VALUE){\n k++;\n }\n d[l] = a[i];\n v2[i] = k;\n max = Math.max(max,v1[i] + v2[i + 1]);\n }\n out.print(max);\n }\n\n BufferedReader br;\n StringTokenizer sc;\n PrintWriter out;\n\n String nextToken() throws IOException {\n while (sc == null || !sc.hasMoreTokens()) {\n try {\n sc = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n sc = null;\n }\n }\n return sc.nextToken();\n }\n\n public Integer nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public Long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public Double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n new Main().run();\n }\n\n public void run() throws IOException {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c9f57e5a01f710966b9736aef9b960d1", "src_uid": "ce8350be138ce2061349d7f9224a5aaf", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n ArrayList> q;\n boolean[] used;\n\n public void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n int[] a = new int[m + 1];\n for (int i = 0; i < n; i++) {\n a[nextInt() - 1]++;\n a[nextInt()]--;\n }\n for (int i = 1; i < m; i++) {\n a[i] += a[i - 1];\n }\n int[] d = new int[m + 1];\n Arrays.fill(d, Integer.MAX_VALUE);\n int k = 0;\n int[] v1 = new int[m + 2];\n int[] v2 = new int[m + 2];\n for (int i = 0; i < m; i++) {\n int l = 0;\n int r = m;\n while (r - l > 1) {\n int m1 = (r + l) / 2;\n if (d[m1] > a[i]) {\n r = m1;\n } else {\n l = m1;\n }\n }\n if (d[l] <= a[i]) {\n l++;\n }\n if (d[l] == Integer.MAX_VALUE){\n k++;\n }\n d[l] = a[i];\n v1[i] = k;\n }\n k = 0;\n int max = 0;\n Arrays.fill(d,Integer.MAX_VALUE);\n for (int i = m - 1; i >= 0; i--) {\n int l = 0;\n int r = m;\n while (r - l > 1) {\n int m1 = (r + l) / 2;\n if (d[m1] > a[i]) {\n r = m1;\n } else {\n l = m1;\n }\n }\n if (d[l] <= a[i]) {\n l++;\n }\n if (d[l] == Integer.MAX_VALUE){\n k++;\n }\n d[l] = a[i];\n v2[i] = k;\n max = Math.max(max,v1[i] + v2[i + 1]);\n }\n max = Math.max(max,v2[0]);\n out.print(max);\n }\n\n BufferedReader br;\n StringTokenizer sc;\n PrintWriter out;\n\n String nextToken() throws IOException {\n while (sc == null || !sc.hasMoreTokens()) {\n try {\n sc = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n sc = null;\n }\n }\n return sc.nextToken();\n }\n\n public Integer nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public Long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public Double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n new Main().run();\n }\n\n public void run() throws IOException {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5006f61e4b6ccb2e66300383b107a5b2", "src_uid": "ce8350be138ce2061349d7f9224a5aaf", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n BufferedReader br;\n StringTokenizer in;\n PrintWriter pw;\n Random r;\n int INF = (int) 1e9;\n int mod = (int) (1e9 + 7);\n //int p = 26;\n ArrayList g[];\n\n void end(int a, int n) {\n if ((int) Math.pow(2, a) != n) pw.print(a);\n else pw.print(\"Final!\");\n pw.close();\n System.exit(0);\n }\n\n class node {\n int val;\n int m;\n int size;\n int prior;\n node L;\n node R;\n\n public node(int v) {\n val = v;\n prior = r.nextInt();\n size = 1;\n L = null;\n R = null;\n }\n }\n\n int sgs(node c) {\n if (c == null) return 0;\n return c.size;\n }\n\n int sgm(node c) {\n if (c == null) return INF;\n return c.m;\n }\n\n void relax(node c) {\n if (c == null) return;\n c.size = 1 + sgs(c.L) + sgs(c.R);\n }\n\n class pair implements Comparable {\n int a;\n int b;\n\n public pair(int aa, int bb) {\n a = aa;\n b = bb;\n }\n\n @Override\n public int compareTo(pair o) {\n if (a != o.a) return a - o.a;\n return b - o.b;\n }\n }\n\n class road {\n int to;\n int w;\n\n public road(int tto, int ww) {\n to = tto;\n w = ww;\n }\n\n public road() throws IOException {\n to = nextInt();\n w = nextInt();\n }\n }\n\n void readG(int n, int m) throws IOException {\n g = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n g[i] = new ArrayList<>();\n }\n for (int i = 0; i < m; i++) {\n int a = nextInt() - 1;\n int b = nextInt() - 1;\n int w = nextInt();\n// g[a].add(new road(b, w));\n// g[b].add(new road(a, w));\n }\n }\n\n int p[];\n int d[];\n\n void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n event[] p = new event[n * 2];\n for (int i = 0; i < n; i++) {\n int l = nextInt();\n int r = nextInt();\n p[i] = new event(l, 1);\n p[i + n] = new event(r, -1);\n }\n int q = p.length;\n int b = 0;\n Arrays.sort(p);\n int bal[] = new int[m + 1];\n int prev = 0;\n for (int i = 0; i < q; i++) {\n event a = p[i];\n if (a.t == -1) {\n for (int j = prev + 1; j <= a.time; j++) {\n bal[j] = b;\n }\n prev = a.time;\n } else {\n for (int j = prev + 1; j < a.time; j++) {\n bal[j] = b;\n }\n prev = a.time - 1;\n }\n b += a.t;\n }\n// for (int i = 1; i <= m; i++) {\n// pw.print(bal[i]);\n// }\n int revbal[] = new int[m + 1];\n for (int i = 1; i <= m; i++) {\n revbal[i] = bal[m + 1 - i];\n }\n int nvp[] = getnvp(bal);\n int rnvp[] = getnvp(revbal);\n int ans = 0;\n for (int i = 1; i <= m; i++) {\n int z = nvp[i];\n int w = rnvp[m - i];\n int sum = z + w;\n ans = max(ans, sum);\n }\n pw.print(ans);\n }\n\n int[] getnvp(int a[]) {\n int n = a.length;\n int d[] = new int[n + 1];\n int ans[] = new int[n];\n Arrays.fill(d, INF);\n d[0] = -INF;\n int last = 0;\n for (int i = 1; i < n; i++) {\n ans[i] = ans[i - 1];\n int c = a[i];\n int l = 0;\n int r = last + 1;\n while (l + 1 != r) {\n int m = (l + r) / 2;\n if (d[m] <= c) l = m;\n else r = m;\n }\n if (d[r] == INF) {\n ans[i]++;\n last++;\n }\n d[r] = min(d[r], c);\n }\n return ans;\n }\n\n class event implements Comparable {\n int time;\n int t;\n\n public event(int ttime, int tt) {\n time = ttime;\n t = tt;\n }\n\n @Override\n public int compareTo(event o) {\n if (time != o.time) return time - o.time;\n else return o.t - t;\n }\n }\n\n\n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n\n void run() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new OutputStreamWriter(System.out));\n r = new Random(5);\n solve();\n pw.close();\n }\n\n String nextToken() throws IOException {\n while (in == null || !in.hasMoreTokens()) in = new StringTokenizer(br.readLine());\n return in.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9c7213c12c15105e12d32c6754eea34c", "src_uid": "ce8350be138ce2061349d7f9224a5aaf", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\n// import java.io.FileInputStream;\n// import java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.abs;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.round;\nimport static java.util.Arrays.copyOf;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.sort;\nimport static java.util.Collections.reverseOrder;\nimport static java.util.Collections.sort;\nimport static java.util.Comparator.comparingInt;\n\npublic class Solution {\n FastScanner in;\n PrintWriter out;\n\n private void solve() throws IOException {\n int n = in.nextInt(), k = in.nextInt();\n int[] h = new int[n];\n for (int i = 0; i < n; i++)\n h[i] = in.nextInt();\n\n int any = 0;\n for (int i = 0; i < n; i++)\n if (h[i] == h[(i + 1) % n])\n any++;\n\n n -= any;\n k -= 2;\n\n factmod = new long[n + 1];\n factmod[0] = 1;\n for (int i = 1; i <= n; i++)\n factmod[i] = factmod[i - 1] * i % mod;\n\n long ans = 0, f = 1;\n for (int spec = 1; spec <= n; spec++) {\n if (spec > 2) {\n if (spec % 2 == 1)\n f = (f * 2 % mod + Cmod(spec / 2, spec - 1)) % mod;\n else\n f = (f * 2 % mod + mod - Cmod(spec / 2 - 1, spec - 1)) % mod;\n }\n ans = (ans + binpowmod(k, n - spec) * Cmod(spec, n) % mod * f % mod) % mod;\n }\n\n out.println(ans * binpowmod(k + 2, any) % mod);\n }\n\n long mod = 998244353;\n long[] factmod;\n\n long Cmod(int k, int n) {\n return factmod[n] * binpowmod(factmod[k] * factmod[n - k], mod - 2) % mod;\n }\n\n long binpowmod(long a, long n) {\n long res = 1;\n a %= mod;\n n %= mod - 1;\n while (n > 0) {\n if (n % 2 == 1)\n res = (res * a) % mod;\n a = (a * a) % mod;\n n /= 2;\n }\n return res;\n }\n\n class FastScanner {\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n boolean hasNext() throws IOException {\n return br.ready() || (st != null && st.hasMoreTokens());\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n boolean hasNextLine() throws IOException {\n return br.ready();\n }\n }\n\n private void run() throws IOException {\n in = new FastScanner(System.in); // new FastScanner(new FileInputStream(\".in\"));\n out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(\".out\"));\n\n solve();\n\n out.flush();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n new Solution().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "843327124ea8b9b053e1341edb7df814", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class Main {\n static long mod = 998244353;\n static long fact[];\n static long inv[];\n\n static long pow(long a, long n) {\n if (n == 0) return 1;\n if (n == 1) return a;\n if ((n & 1) == 0) {\n long np = pow(a, n / 2);\n return (np * np)%mod;\n }\n return a % mod * pow(a, n - 1) % mod;\n }\n\n static long c(int n, int k) {\n return ((fact[n] * inv[k]) % mod * inv[n - k]) % mod;\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 int n = in.nextInt();\n int k = in.nextInt();\n// if(n == 5 && k == 5){\n// out.println(1000);\n// out.close();\n// return;\n// }\n array a = new array(n);\n a.scan(in);\n long h[] = a.a;\n long _h[] = a.right_shift(1);\n int eq = 0;\n for (int i = 0; i < n; i++) {\n if (h[i] == _h[i]) ++eq;\n }\n inv = new long[n + 1];\n fact = new long[n + 1];\n fact[1] = inv[1] = fact[0] = inv[0] = 1;\n for (int i = 2; i < n + 1; i++) {\n fact[i] = fact[i - 1] * i;\n fact[i] %= mod;\n inv[i] = pow(fact[i], mod - 2);\n inv[i] %= mod;\n }\n long f = max(1, pow(k, eq));\n int N = n - eq;\n long ans = 0;\n long sum = 1;\n for (int i = 1; i <= N; i++) {\n ans = (ans + sum * pow(k - 2, N - i) % mod * c(N, i)) % mod;\n sum = sum * 2 % mod;\n if (i % 2 != 0) {\n sum = (sum + mod - c(i, i / 2)) % mod;\n }\n else {\n sum = (sum + c(i, i / 2)) % mod;\n }\n }\n ans = ans * f % mod;\n out.println(ans);\n out.close();\n }\n}\n\nclass RANDOMIZER {\n static Random rnd = new Random();\n\n static int randomize() {\n return rnd.nextInt();\n }\n}\n\nclass array {\n long a[];\n\n array(long a[]) {\n this.a = a;\n }\n\n array(int n) {\n a = new long[n];\n }\n\n void shuffle() {\n for (int i = 0; i < a.length; i++) {\n int id1 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;\n int id2 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;\n long t = a[id1];\n a[id1] = a[id2];\n a[id2] = t;\n }\n }\n\n void reverse(int l, int r) {\n for (int i = l; i < l + (r - l + 1) >> 1; i++) {\n long t = a[i];\n a[i] = a[r - i];\n a[r - i] = t;\n }\n }\n\n long[] right_shift(int shift) {\n long aa[] = new long[a.length];\n for (int i = 0; i < a.length; i++) {\n aa[(i + shift) % a.length] = a[i];\n }\n return aa;\n }\n\n void add(int l, int r, long val) {\n for (int i = l; i <= r; i++) {\n a[i] += val;\n }\n }\n\n void print(PrintWriter out) {\n for (int i = 0; i < a.length; i++) {\n out.print(a[i] + \" \");\n }\n }\n\n void copy(long t[]) {\n for (int i = 0; i < a.length; i++) {\n a[i] = t[i];\n }\n }\n\n void scan(FastScanner in) throws IOException {\n for (int i = 0; i < a.length; i++) {\n a[i] = in.nextLong();\n }\n }\n\n long getSum() {\n long sum = 0;\n long md = (long) 1e16;\n for (int i = 0; i < a.length; i++) {\n sum += a[i];\n sum %= md;\n }\n return sum;\n }\n\n long getMin() {\n long min = Long.MAX_VALUE;\n for (int i = 0; i < a.length; i++) {\n min = min(min, a[i]);\n }\n return min;\n }\n\n long getMax() {\n long max = Long.MIN_VALUE;\n for (int i = 0; i < a.length; i++) {\n max = max(max, a[i]);\n }\n return max;\n }\n\n int ceilingID(long val) {\n int l = 0;\n int r = a.length - 1;\n while (l + 1 != r) {\n int m = (l + r) >> 1;\n if (a[m] >= val) r = m;\n else l = m;\n }\n int pr = l;\n if (pr > 0 && a[pr - 1] >= val) pr--;\n if (a[pr] < val) pr++;\n if (pr < a.length && a[pr] < val) pr++;\n return pr;\n }\n}\n\nclass dsu {\n int p[];\n int max[];\n\n dsu(int n) {\n p = new int[n];\n max = new int[n];\n for (int i = 0; i < n; i++) {\n p[i] = i;\n max[i] = i;\n }\n }\n\n int get(int a) {\n if (p[a] == a) return a;\n return p[a] = get(p[a]);\n }\n\n void merge(int a, int b) {\n a = get(a);\n b = get(b);\n if (a != b) {\n p[a] = b;\n max[b] = max(max[a], max[b]);\n }\n }\n}\n\nclass vertex {\n int next[];\n}\n\nclass trie {\n vertex t[];\n int sz = 1;\n int k;\n\n trie(int k) {\n this.k = k;\n t = new vertex[300000];\n for (int i = 0; i < t.length; i++) {\n t[i] = new vertex();\n t[i].next = new int[k];\n for (int j = 0; j < k; j++) {\n t[i].next[j] = -1;\n }\n }\n }\n\n void add(String s, int id) {\n int v = 0;\n for (int i = 0; i < s.length(); i++) {\n char rc = (char) (s.charAt(i) - 'a');\n if (t[v].next[rc] == -1) {\n t[v].next[rc] = sz++;\n }\n v = t[v].next[rc];\n }\n }\n}\n\nclass StringHelper {\n char[] s;\n long hash[];\n long px[];\n long mod = (int) 1e9 + 7;\n long x = 255;\n int n;\n\n public StringHelper(String s) {\n this.s = s.toCharArray();\n n = s.length();\n }\n\n int[] pi() {\n int pi[] = new int[n];\n for (int i = 1; i < n; i++) {\n int j = pi[i - 1];\n while (j > 0 && s[i] != s[j]) j = pi[j - 1];\n pi[i] = s[i] == s[j] ? j + 1 : j;\n }\n return pi;\n }\n\n void calcHash() {\n hash = new long[n + 1];\n px = new long[n + 3];\n px[0] = 1;\n for (int i = 1; i < n + 3; i++) {\n px[i] = px[i - 1] * x % mod;\n }\n for (int i = 1; i < n + 1; i++) {\n hash[i] = (hash[i - 1] * x % mod + s[i - 1] + mod) % mod;\n }\n }\n\n long getHash(int l, int r) {\n return (hash[r + 1] - hash[l] * px[r - l + 1] % mod + mod) % mod;\n }\n}\n\nclass IMPLICITDT {\n long val;\n int y;\n int sz;\n IMPLICITDT l, r;\n\n static int getSize(IMPLICITDT t) {\n return t == null ? 0 : t.sz;\n }\n\n private static void recalc(IMPLICITDT t) {\n if (t == null) return;\n int LSZ = t.l == null ? 0 : t.l.sz;\n int RSZ = t.r == null ? 0 : t.r.sz;\n t.sz = LSZ + RSZ + 1;\n }\n\n IMPLICITDT() {\n }\n\n IMPLICITDT(long cost, int y, IMPLICITDT l, IMPLICITDT r) {\n this.val = cost;\n this.y = y;\n this.l = l;\n this.r = r;\n recalc(this);\n }\n\n IMPLICITDT(long cost, int y) {\n this.val = cost;\n this.y = y;\n recalc(this);\n }\n\n static long get(IMPLICITDT t, int id) {\n int LSZ = getSize(t.l);\n if (LSZ == id) return t.val;\n if (LSZ < id) return get(t.r, id - LSZ - 1);\n return get(t.l, id);\n }\n\n static IMPLICITDT split(IMPLICITDT T, int x) {\n IMPLICITDT RES = new IMPLICITDT();\n if (T == null) {\n return RES;\n }\n if (getSize(T.l) > x) {\n IMPLICITDT lsplit = split(T.l, x);\n RES.l = lsplit.l;\n RES.r = T;\n T.l = lsplit.r;\n } else {\n IMPLICITDT rsplit = split(T.r, x - getSize(T.l) - 1);\n RES.r = rsplit.r;\n RES.l = T;\n T.r = rsplit.l;\n }\n recalc(RES);\n recalc(T);\n return RES;\n }\n\n static IMPLICITDT merge(IMPLICITDT L, IMPLICITDT R) {\n if (L == null) return R;\n if (R == null) return L;\n if (L.y > R.y) return new IMPLICITDT(L.val, L.y, L.l, merge(L.r, R));\n else return new IMPLICITDT(R.val, R.y, merge(L, R.l), R.r);\n }\n\n static IMPLICITDT insert(IMPLICITDT T, long val, int id) {\n if (T == null) return new IMPLICITDT(val, RANDOMIZER.randomize());\n IMPLICITDT _T = split(T, id);\n IMPLICITDT _TR = new IMPLICITDT(val, RANDOMIZER.randomize());\n IMPLICITDT NEWTREAP = merge(_T.l, _TR);\n IMPLICITDT TREAP = merge(NEWTREAP, _T.r);\n recalc(TREAP);\n return TREAP;\n }\n}\n\nclass stSUM {\n int t[];\n int a[];\n\n stSUM(int a[]) {\n this.a = a;\n t = new int[a.length * 4];\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = a[l];\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = t[v * 2] + t[v * 2 + 1];\n }\n }\n\n void upd(int v, int l, int r, int pos, int x) {\n if (l == r) t[v] = x;\n else {\n int m = (l + r) >> 1;\n if (pos <= m) upd(v * 2, l, m, pos, x);\n else upd(v * 2 + 1, m + 1, r, pos, x);\n t[v] = t[v * 2] + t[v * 2 + 1];\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (ql <= l && r <= qr) return t[v];\n if (l > qr || ql > r) return 0;\n int m = (l + r) >> 1;\n return query(v * 2, l, m, ql, qr) + query(v * 2 + 1, m + 1, r, ql, qr);\n }\n}\n\nclass stMIN {\n int t[];\n int a[];\n\n stMIN(int a[]) {\n this.a = a;\n t = new int[a.length * 4];\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = a[l];\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = min(t[v * 2], t[v * 2 + 1]);\n }\n }\n\n void upd(int v, int l, int r, int pos, int x) {\n if (l == r) t[v] = x;\n else {\n int m = (l + r) >> 1;\n if (pos <= m) upd(v * 2, l, m, pos, x);\n else upd(v * 2 + 1, m + 1, r, pos, x);\n t[v] = min(t[v * 2], t[v * 2 + 1]);\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (ql <= l && r <= qr) return t[v];\n if (l > qr || ql > r) return Integer.MAX_VALUE;\n int m = (l + r) >> 1;\n return min(query(v * 2, l, m, ql, qr), query(v * 2 + 1, m + 1, r, ql, qr));\n }\n}\n\nclass DT {\n long val;\n int x, y;\n int sz;\n DT l, r;\n\n DT() {\n recalc(this);\n }\n\n DT(int x, int y, long val) {\n this.x = x;\n this.y = y;\n this.val = val;\n recalc(this);\n }\n\n DT(int x, int y, DT l, DT r, long val) {\n this.x = x;\n this.y = y;\n this.l = l;\n this.r = r;\n this.val = val;\n recalc(this);\n }\n\n static DT split(DT t, int x) {\n DT res = new DT();\n if (t == null) {\n res.l = null;\n res.r = null;\n return res;\n }\n if (x < t.x) {\n DT lsplit = split(t.l, x);\n res.l = lsplit.l;\n res.r = t;\n t.l = lsplit.r;\n } else {\n DT rsplit = split(t.r, x);\n res.r = rsplit.r;\n res.l = t;\n t.r = rsplit.l;\n }\n recalc(t);\n recalc(res);\n return res;\n }\n\n static DT merge(DT t1, DT t2) {\n if (t1 == null || t2 == null)\n return t1 == null ? t2 : t1;\n if (t1.y < t2.y) {\n t1.r = merge(t1.r, t2);\n recalc(t1);\n return t1;\n } else {\n t2.l = merge(t1, t2.l);\n recalc(t2);\n return t2;\n }\n }\n\n static void recalc(DT t) {\n if (t == null) return;\n int lsz = t.l == null ? 0 : t.l.sz;\n int rsz = t.r == null ? 0 : t.r.sz;\n t.sz = lsz + rsz + 1;\n }\n\n static DT insert(DT t, int x, long val) {\n try {\n if (t == null) {\n DT ret = new DT(x, RANDOMIZER.randomize(), val);\n recalc(ret);\n return ret;\n }\n DT split = split(t, x);\n DT prelast = merge(split.l, new DT(x, RANDOMIZER.randomize(), val));\n DT newtreap = merge(prelast, split.r);\n recalc(newtreap);\n return newtreap;\n } catch (Exception e) {\n System.exit(0);\n return new DT();\n }\n }\n\n static long find_kth(DT t, int k) {\n if (t.l == null && k == 1)\n return t.val;\n if (t.l != null && t.l.sz == k - 1)\n return t.val;\n if (t.l != null && t.l.sz >= k)\n return find_kth(t.l, k);\n else\n return find_kth(t.r, k - (t.l == null ? 0 : t.l.sz) - 1);\n }\n\n}\n\n\nclass FT {\n private int[] a;\n private long[] t;\n\n FT(int[] a) {\n this.a = a;\n t = new long[a.length];\n }\n\n void inc(int i, int delta) {\n for (; i < a.length; i = (i | (i + 1)))\n t[i] += delta;\n }\n\n long sum(int l, int r) {\n return sum(r) - sum(l - 1);\n }\n\n private long sum(int r) {\n long sum = 0;\n for (; r >= 0; r = (r & (r + 1)) - 1) {\n sum += t[r];\n }\n return sum;\n }\n}\n\nclass LAZY_ST {\n long min[], sum[], set[];\n int last;\n long not_set = Long.MAX_VALUE;\n\n LAZY_ST(long a[]) {\n int n = a.length;\n last = n - 1;\n min = new long[4 * n];\n sum = new long[4 * n];\n set = new long[4 * n];\n for (int i = 0; i < 4 * n; i++) {\n set[i] = not_set;\n }\n build(0, 0, last, a);\n }\n\n void build(int v, int l, int r, long a[]) {\n if (l == r) {\n min[v] = a[l];\n return;\n }\n int m = ((l + r) >> 1);\n build(v * 2 + 1, l, m, a);\n build(v * 2 + 2, m + 1, r, a);\n min[v] = Math.min(min[v * 2 + 1], min[v * 2 + 2]);\n }\n\n void push(int v) {\n if (set[v] != not_set) {\n min[v] = set[v];\n sum[v * 2 + 1] = sum[v * 2 + 2] = 0;\n set[v * 2 + 1] = set[v * 2 + 2] = set[v];\n set[v] = not_set;\n }\n\n min[v] += sum[v];\n sum[v * 2 + 1] += sum[v];\n sum[v * 2 + 2] += sum[v];\n sum[v] = 0;\n }\n\n void upd(int v) {\n min[v] = Math.min(get_el(v * 2 + 1), get_el(v * 2 + 2));\n }\n\n long get_el(int v) {\n return (set[v] == not_set ? min[v] : set[v]) + sum[v];\n }\n\n void set(int l, int r, long x) {\n set(0, 0, last, l, r, x);\n }\n\n void set(int v, int l, int r, int left, int right, long x) {\n if (l > right || r < left) return;\n if (l >= left && r <= right) {\n sum[v] = 0;\n set[v] = x;\n return;\n }\n push(v);\n int m = ((l + r) >> 1);\n\n set(v * 2 + 1, l, m, left, right, x);\n set(v * 2 + 2, m + 1, r, left, right, x);\n\n upd(v);\n }\n\n void add(int l, int r, long x) {\n add(0, 0, last, l, r, x);\n }\n\n void add(int v, int l, int r, int left, int right, long x) {\n if (l > right || r < left) return;\n if (l >= left && r <= right) {\n sum[v] += x;\n return;\n }\n push(v);\n int m = ((l + r) >> 1);\n\n add(v * 2 + 1, l, m, left, right, x);\n add(v * 2 + 2, m + 1, r, left, right, x);\n\n upd(v);\n }\n\n long get(int l, int r) {\n return get(0, 0, last, l, r);\n }\n\n long get(int v, int l, int r, int left, int right) {\n if (l > right || r < left) return (long) 1e17;\n\n if (l >= left && r <= right) {\n return get_el(v);\n }\n push(v);\n int m = ((l + r) >> 1);\n\n long ans = Math.min(get(v * 2 + 1, l, m, left, right), get(v * 2 + 2, m + 1, r, left, right));\n upd(v);\n return ans;\n }\n\n}\n\nclass multiset {\n TreeMap t;\n\n void insert(long val) {\n t.put(val, t.getOrDefault(val, 0) + 1);\n }\n\n void erase(long val) {\n int nw = t.getOrDefault(val, 1);\n if (nw == 1) t.remove(val);\n else t.put(val, nw - 1);\n }\n\n long ceiling(long val) {\n return t.ceilingKey(val);\n }\n\n long floor(long val) {\n return t.floorKey(val);\n }\n\n long higher(long val) {\n return t.higherKey(val);\n }\n\n long lower(long val) {\n return t.lowerKey(val);\n }\n\n int count(long val) {\n return t.getOrDefault(val, 0);\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}\n\nclass tree {\n ArrayList g[];\n int n;\n ArrayList order;\n int first[];\n int h[];\n int t[];\n int rt;\n\n tree(ArrayList g[]) {\n this.g = g;\n this.n = g.length;\n order = new ArrayList<>();\n first = new int[n];\n fill(first, -1);\n h = new int[n];\n rt = 0;\n dfs(rt, -1);\n prepare();\n }\n\n void dfs(int v, int p) {\n if (first[v] == -1) first[v] = order.size();\n order.add(v);\n for (int to : g[v]) {\n if (to == p) continue;\n h[to] = h[v] + 1;\n dfs(to, v);\n order.add(v);\n }\n }\n\n void prepare() {\n t = new int[order.size() * 4];\n build(1, 0, order.size() - 1);\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = order.get(l);\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = h[t[v * 2]] < h[t[v * 2 + 1]] ? t[v * 2] : t[v * 2 + 1];\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (l > qr || ql > r) return Integer.MAX_VALUE;\n if (ql <= l && r <= qr) return t[v];\n int m = (l + r) >> 1;\n int v1 = query(v * 2, l, m, ql, qr);\n int v2 = query(v * 2 + 1, m + 1, r, ql, qr);\n if (v1 == Integer.MAX_VALUE) return v2;\n if (v2 == Integer.MAX_VALUE) return v1;\n return h[v1] < h[v2] ? v1 : v2;\n }\n\n int lca(int a, int b) {\n int l = first[a];\n int r = first[b];\n return query(1, 0, order.size() - 1, min(l, r), max(l, r));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "55f57890eb2ff5cf74f7d60865e91d9c", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class Main {\n static long mod = 998244353;\n\n static long pow(long a, int n) {\n if (n == 0) return 1;\n if ((n & 1) == 0) return (pow(a, n / 2) % mod * pow(a, n / 2) % mod) % mod;\n return a % mod * pow(a, n - 1) % mod;\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 int n = in.nextInt();\n int k = in.nextInt();\n// if(n == 5 && k == 5){\n// out.println(1000);\n// out.close();\n// return;\n// }\n array a = new array(n);\n a.scan(in);\n long h[] = a.a;\n long _h[] = a.right_shift(1);\n int eq = 0;\n for (int i = 0; i < n; i++) {\n if (h[i] == _h[i]) ++eq;\n }\n long f = max(1, pow(k, eq));\n int N = n - eq;\n long c[][] = new long[N + 1][N + 1];\n\n for (int i = 1; i < N + 1; i++) {\n c[i][1] = i;\n }\n for (int nn = 2; nn < N + 1; nn++) {\n for (int kk = 2; kk < N + 1; kk++) {\n c[nn][kk] = c[nn - 1][kk - 1] + c[nn - 1][kk];\n c[nn][kk] %= mod;\n }\n }\n for (int i = 0; i < N + 1; i++) {\n for (int j = 0; j < N + 1; j++) {\n if (c[i][j] == 0) c[i][j] = 1;\n }\n }\n long ans = 0;\n for (int i = 0; i <= N; i++) {\n long q = c[N][i] * pow(k - 2,i);\n if(i == 0)q = 1;\n int lft = N - i;\n long s = 0;\n for (int j = 0; j <= lft; j++) {\n if (j >= lft - j) break;\n s += c[lft][lft - j];\n s%=mod;\n }\n ans += (q%mod * s%mod);\n ans%=mod;\n }\n out.println(ans * f % mod);\n out.close();\n }\n}\n\nclass RANDOMIZER {\n static Random rnd = new Random();\n\n static int randomize() {\n return rnd.nextInt();\n }\n}\n\nclass array {\n long a[];\n\n array(long a[]) {\n this.a = a;\n }\n\n array(int n) {\n a = new long[n];\n }\n\n void shuffle() {\n for (int i = 0; i < a.length; i++) {\n int id1 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;\n int id2 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;\n long t = a[id1];\n a[id1] = a[id2];\n a[id2] = t;\n }\n }\n\n void reverse(int l, int r) {\n for (int i = l; i < l + (r - l + 1) >> 1; i++) {\n long t = a[i];\n a[i] = a[r - i];\n a[r - i] = t;\n }\n }\n\n long[] right_shift(int shift) {\n long aa[] = new long[a.length];\n for (int i = 0; i < a.length; i++) {\n aa[(i + shift) % a.length] = a[i];\n }\n return aa;\n }\n\n void add(int l, int r, long val) {\n for (int i = l; i <= r; i++) {\n a[i] += val;\n }\n }\n\n void print(PrintWriter out) {\n for (int i = 0; i < a.length; i++) {\n out.print(a[i] + \" \");\n }\n }\n\n void copy(long t[]) {\n for (int i = 0; i < a.length; i++) {\n a[i] = t[i];\n }\n }\n\n void scan(FastScanner in) throws IOException {\n for (int i = 0; i < a.length; i++) {\n a[i] = in.nextLong();\n }\n }\n\n long getSum() {\n long sum = 0;\n long md = (long) 1e16;\n for (int i = 0; i < a.length; i++) {\n sum += a[i];\n sum %= md;\n }\n return sum;\n }\n\n long getMin() {\n long min = Long.MAX_VALUE;\n for (int i = 0; i < a.length; i++) {\n min = min(min, a[i]);\n }\n return min;\n }\n\n long getMax() {\n long max = Long.MIN_VALUE;\n for (int i = 0; i < a.length; i++) {\n max = max(max, a[i]);\n }\n return max;\n }\n\n int ceilingID(long val) {\n int l = 0;\n int r = a.length - 1;\n while (l + 1 != r) {\n int m = (l + r) >> 1;\n if (a[m] >= val) r = m;\n else l = m;\n }\n int pr = l;\n if (pr > 0 && a[pr - 1] >= val) pr--;\n if (a[pr] < val) pr++;\n if (pr < a.length && a[pr] < val) pr++;\n return pr;\n }\n}\n\nclass dsu {\n int p[];\n int max[];\n\n dsu(int n) {\n p = new int[n];\n max = new int[n];\n for (int i = 0; i < n; i++) {\n p[i] = i;\n max[i] = i;\n }\n }\n\n int get(int a) {\n if (p[a] == a) return a;\n return p[a] = get(p[a]);\n }\n\n void merge(int a, int b) {\n a = get(a);\n b = get(b);\n if (a != b) {\n p[a] = b;\n max[b] = max(max[a], max[b]);\n }\n }\n}\n\nclass vertex {\n int next[];\n}\n\nclass trie {\n vertex t[];\n int sz = 1;\n int k;\n\n trie(int k) {\n this.k = k;\n t = new vertex[300000];\n for (int i = 0; i < t.length; i++) {\n t[i] = new vertex();\n t[i].next = new int[k];\n for (int j = 0; j < k; j++) {\n t[i].next[j] = -1;\n }\n }\n }\n\n void add(String s, int id) {\n int v = 0;\n for (int i = 0; i < s.length(); i++) {\n char rc = (char) (s.charAt(i) - 'a');\n if (t[v].next[rc] == -1) {\n t[v].next[rc] = sz++;\n }\n v = t[v].next[rc];\n }\n }\n}\n\nclass StringHelper {\n char[] s;\n long hash[];\n long px[];\n long mod = (int) 1e9 + 7;\n long x = 255;\n int n;\n\n public StringHelper(String s) {\n this.s = s.toCharArray();\n n = s.length();\n }\n\n int[] pi() {\n int pi[] = new int[n];\n for (int i = 1; i < n; i++) {\n int j = pi[i - 1];\n while (j > 0 && s[i] != s[j]) j = pi[j - 1];\n pi[i] = s[i] == s[j] ? j + 1 : j;\n }\n return pi;\n }\n\n void calcHash() {\n hash = new long[n + 1];\n px = new long[n + 3];\n px[0] = 1;\n for (int i = 1; i < n + 3; i++) {\n px[i] = px[i - 1] * x % mod;\n }\n for (int i = 1; i < n + 1; i++) {\n hash[i] = (hash[i - 1] * x % mod + s[i - 1] + mod) % mod;\n }\n }\n\n long getHash(int l, int r) {\n return (hash[r + 1] - hash[l] * px[r - l + 1] % mod + mod) % mod;\n }\n}\n\nclass IMPLICITDT {\n long val;\n int y;\n int sz;\n IMPLICITDT l, r;\n\n static int getSize(IMPLICITDT t) {\n return t == null ? 0 : t.sz;\n }\n\n private static void recalc(IMPLICITDT t) {\n if (t == null) return;\n int LSZ = t.l == null ? 0 : t.l.sz;\n int RSZ = t.r == null ? 0 : t.r.sz;\n t.sz = LSZ + RSZ + 1;\n }\n\n IMPLICITDT() {\n }\n\n IMPLICITDT(long cost, int y, IMPLICITDT l, IMPLICITDT r) {\n this.val = cost;\n this.y = y;\n this.l = l;\n this.r = r;\n recalc(this);\n }\n\n IMPLICITDT(long cost, int y) {\n this.val = cost;\n this.y = y;\n recalc(this);\n }\n\n static long get(IMPLICITDT t, int id) {\n int LSZ = getSize(t.l);\n if (LSZ == id) return t.val;\n if (LSZ < id) return get(t.r, id - LSZ - 1);\n return get(t.l, id);\n }\n\n static IMPLICITDT split(IMPLICITDT T, int x) {\n IMPLICITDT RES = new IMPLICITDT();\n if (T == null) {\n return RES;\n }\n if (getSize(T.l) > x) {\n IMPLICITDT lsplit = split(T.l, x);\n RES.l = lsplit.l;\n RES.r = T;\n T.l = lsplit.r;\n } else {\n IMPLICITDT rsplit = split(T.r, x - getSize(T.l) - 1);\n RES.r = rsplit.r;\n RES.l = T;\n T.r = rsplit.l;\n }\n recalc(RES);\n recalc(T);\n return RES;\n }\n\n static IMPLICITDT merge(IMPLICITDT L, IMPLICITDT R) {\n if (L == null) return R;\n if (R == null) return L;\n if (L.y > R.y) return new IMPLICITDT(L.val, L.y, L.l, merge(L.r, R));\n else return new IMPLICITDT(R.val, R.y, merge(L, R.l), R.r);\n }\n\n static IMPLICITDT insert(IMPLICITDT T, long val, int id) {\n if (T == null) return new IMPLICITDT(val, RANDOMIZER.randomize());\n IMPLICITDT _T = split(T, id);\n IMPLICITDT _TR = new IMPLICITDT(val, RANDOMIZER.randomize());\n IMPLICITDT NEWTREAP = merge(_T.l, _TR);\n IMPLICITDT TREAP = merge(NEWTREAP, _T.r);\n recalc(TREAP);\n return TREAP;\n }\n}\n\nclass stSUM {\n int t[];\n int a[];\n\n stSUM(int a[]) {\n this.a = a;\n t = new int[a.length * 4];\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = a[l];\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = t[v * 2] + t[v * 2 + 1];\n }\n }\n\n void upd(int v, int l, int r, int pos, int x) {\n if (l == r) t[v] = x;\n else {\n int m = (l + r) >> 1;\n if (pos <= m) upd(v * 2, l, m, pos, x);\n else upd(v * 2 + 1, m + 1, r, pos, x);\n t[v] = t[v * 2] + t[v * 2 + 1];\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (ql <= l && r <= qr) return t[v];\n if (l > qr || ql > r) return 0;\n int m = (l + r) >> 1;\n return query(v * 2, l, m, ql, qr) + query(v * 2 + 1, m + 1, r, ql, qr);\n }\n}\n\nclass stMIN {\n int t[];\n int a[];\n\n stMIN(int a[]) {\n this.a = a;\n t = new int[a.length * 4];\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = a[l];\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = min(t[v * 2], t[v * 2 + 1]);\n }\n }\n\n void upd(int v, int l, int r, int pos, int x) {\n if (l == r) t[v] = x;\n else {\n int m = (l + r) >> 1;\n if (pos <= m) upd(v * 2, l, m, pos, x);\n else upd(v * 2 + 1, m + 1, r, pos, x);\n t[v] = min(t[v * 2], t[v * 2 + 1]);\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (ql <= l && r <= qr) return t[v];\n if (l > qr || ql > r) return Integer.MAX_VALUE;\n int m = (l + r) >> 1;\n return min(query(v * 2, l, m, ql, qr), query(v * 2 + 1, m + 1, r, ql, qr));\n }\n}\n\nclass DT {\n long val;\n int x, y;\n int sz;\n DT l, r;\n\n DT() {\n recalc(this);\n }\n\n DT(int x, int y, long val) {\n this.x = x;\n this.y = y;\n this.val = val;\n recalc(this);\n }\n\n DT(int x, int y, DT l, DT r, long val) {\n this.x = x;\n this.y = y;\n this.l = l;\n this.r = r;\n this.val = val;\n recalc(this);\n }\n\n static DT split(DT t, int x) {\n DT res = new DT();\n if (t == null) {\n res.l = null;\n res.r = null;\n return res;\n }\n if (x < t.x) {\n DT lsplit = split(t.l, x);\n res.l = lsplit.l;\n res.r = t;\n t.l = lsplit.r;\n } else {\n DT rsplit = split(t.r, x);\n res.r = rsplit.r;\n res.l = t;\n t.r = rsplit.l;\n }\n recalc(t);\n recalc(res);\n return res;\n }\n\n static DT merge(DT t1, DT t2) {\n if (t1 == null || t2 == null)\n return t1 == null ? t2 : t1;\n if (t1.y < t2.y) {\n t1.r = merge(t1.r, t2);\n recalc(t1);\n return t1;\n } else {\n t2.l = merge(t1, t2.l);\n recalc(t2);\n return t2;\n }\n }\n\n static void recalc(DT t) {\n if (t == null) return;\n int lsz = t.l == null ? 0 : t.l.sz;\n int rsz = t.r == null ? 0 : t.r.sz;\n t.sz = lsz + rsz + 1;\n }\n\n static DT insert(DT t, int x, long val) {\n try {\n if (t == null) {\n DT ret = new DT(x, RANDOMIZER.randomize(), val);\n recalc(ret);\n return ret;\n }\n DT split = split(t, x);\n DT prelast = merge(split.l, new DT(x, RANDOMIZER.randomize(), val));\n DT newtreap = merge(prelast, split.r);\n recalc(newtreap);\n return newtreap;\n } catch (Exception e) {\n System.exit(0);\n return new DT();\n }\n }\n\n static long find_kth(DT t, int k) {\n if (t.l == null && k == 1)\n return t.val;\n if (t.l != null && t.l.sz == k - 1)\n return t.val;\n if (t.l != null && t.l.sz >= k)\n return find_kth(t.l, k);\n else\n return find_kth(t.r, k - (t.l == null ? 0 : t.l.sz) - 1);\n }\n\n}\n\n\nclass FT {\n private int[] a;\n private long[] t;\n\n FT(int[] a) {\n this.a = a;\n t = new long[a.length];\n }\n\n void inc(int i, int delta) {\n for (; i < a.length; i = (i | (i + 1)))\n t[i] += delta;\n }\n\n long sum(int l, int r) {\n return sum(r) - sum(l - 1);\n }\n\n private long sum(int r) {\n long sum = 0;\n for (; r >= 0; r = (r & (r + 1)) - 1) {\n sum += t[r];\n }\n return sum;\n }\n}\n\nclass LAZY_ST {\n long min[], sum[], set[];\n int last;\n long not_set = Long.MAX_VALUE;\n\n LAZY_ST(long a[]) {\n int n = a.length;\n last = n - 1;\n min = new long[4 * n];\n sum = new long[4 * n];\n set = new long[4 * n];\n for (int i = 0; i < 4 * n; i++) {\n set[i] = not_set;\n }\n build(0, 0, last, a);\n }\n\n void build(int v, int l, int r, long a[]) {\n if (l == r) {\n min[v] = a[l];\n return;\n }\n int m = ((l + r) >> 1);\n build(v * 2 + 1, l, m, a);\n build(v * 2 + 2, m + 1, r, a);\n min[v] = Math.min(min[v * 2 + 1], min[v * 2 + 2]);\n }\n\n void push(int v) {\n if (set[v] != not_set) {\n min[v] = set[v];\n sum[v * 2 + 1] = sum[v * 2 + 2] = 0;\n set[v * 2 + 1] = set[v * 2 + 2] = set[v];\n set[v] = not_set;\n }\n\n min[v] += sum[v];\n sum[v * 2 + 1] += sum[v];\n sum[v * 2 + 2] += sum[v];\n sum[v] = 0;\n }\n\n void upd(int v) {\n min[v] = Math.min(get_el(v * 2 + 1), get_el(v * 2 + 2));\n }\n\n long get_el(int v) {\n return (set[v] == not_set ? min[v] : set[v]) + sum[v];\n }\n\n void set(int l, int r, long x) {\n set(0, 0, last, l, r, x);\n }\n\n void set(int v, int l, int r, int left, int right, long x) {\n if (l > right || r < left) return;\n if (l >= left && r <= right) {\n sum[v] = 0;\n set[v] = x;\n return;\n }\n push(v);\n int m = ((l + r) >> 1);\n\n set(v * 2 + 1, l, m, left, right, x);\n set(v * 2 + 2, m + 1, r, left, right, x);\n\n upd(v);\n }\n\n void add(int l, int r, long x) {\n add(0, 0, last, l, r, x);\n }\n\n void add(int v, int l, int r, int left, int right, long x) {\n if (l > right || r < left) return;\n if (l >= left && r <= right) {\n sum[v] += x;\n return;\n }\n push(v);\n int m = ((l + r) >> 1);\n\n add(v * 2 + 1, l, m, left, right, x);\n add(v * 2 + 2, m + 1, r, left, right, x);\n\n upd(v);\n }\n\n long get(int l, int r) {\n return get(0, 0, last, l, r);\n }\n\n long get(int v, int l, int r, int left, int right) {\n if (l > right || r < left) return (long) 1e17;\n\n if (l >= left && r <= right) {\n return get_el(v);\n }\n push(v);\n int m = ((l + r) >> 1);\n\n long ans = Math.min(get(v * 2 + 1, l, m, left, right), get(v * 2 + 2, m + 1, r, left, right));\n upd(v);\n return ans;\n }\n\n}\n\nclass multiset {\n TreeMap t;\n\n void insert(long val) {\n t.put(val, t.getOrDefault(val, 0) + 1);\n }\n\n void erase(long val) {\n int nw = t.getOrDefault(val, 1);\n if (nw == 1) t.remove(val);\n else t.put(val, nw - 1);\n }\n\n long ceiling(long val) {\n return t.ceilingKey(val);\n }\n\n long floor(long val) {\n return t.floorKey(val);\n }\n\n long higher(long val) {\n return t.higherKey(val);\n }\n\n long lower(long val) {\n return t.lowerKey(val);\n }\n\n int count(long val) {\n return t.getOrDefault(val, 0);\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}\n\nclass tree {\n ArrayList g[];\n int n;\n ArrayList order;\n int first[];\n int h[];\n int t[];\n int rt;\n\n tree(ArrayList g[]) {\n this.g = g;\n this.n = g.length;\n order = new ArrayList<>();\n first = new int[n];\n fill(first, -1);\n h = new int[n];\n rt = 0;\n dfs(rt, -1);\n prepare();\n }\n\n void dfs(int v, int p) {\n if (first[v] == -1) first[v] = order.size();\n order.add(v);\n for (int to : g[v]) {\n if (to == p) continue;\n h[to] = h[v] + 1;\n dfs(to, v);\n order.add(v);\n }\n }\n\n void prepare() {\n t = new int[order.size() * 4];\n build(1, 0, order.size() - 1);\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = order.get(l);\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = h[t[v * 2]] < h[t[v * 2 + 1]] ? t[v * 2] : t[v * 2 + 1];\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (l > qr || ql > r) return Integer.MAX_VALUE;\n if (ql <= l && r <= qr) return t[v];\n int m = (l + r) >> 1;\n int v1 = query(v * 2, l, m, ql, qr);\n int v2 = query(v * 2 + 1, m + 1, r, ql, qr);\n if (v1 == Integer.MAX_VALUE) return v2;\n if (v2 == Integer.MAX_VALUE) return v1;\n return h[v1] < h[v2] ? v1 : v2;\n }\n\n int lca(int a, int b) {\n int l = first[a];\n int r = first[b];\n return query(1, 0, order.size() - 1, min(l, r), max(l, r));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "977931a9b0449f0a2c213b4bd076f4dd", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class Solver {\n static long cost[];\n static ArrayList g[];\n static long dp[];\n static int k;\n static TreeSetsons[][];\n static void find_son(int v, int p){\n for(int to : g[v]){\n if(to == p)continue;\n sons[v][1].add(to);\n find_son(to,v);\n for (int i = 1; i < g.length; i++) {\n sons[v][i].addAll(sons[to][i-1]);\n }\n }\n }\n static void dfs(int v, int p){\n for(int to )\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 int n = in.nextInt();\n k = in.nextInt();\n cost = new long[n];\n for (int i = 0; i < n; i++) {\n cost[i] = in.nextLong();\n }\n sons = new TreeSet[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n sons[i][j] = new TreeSet<>();\n }\n }\n g = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n g[i] = new ArrayList<>();\n }\n for (int i = 0; i < n - 1; i++) {\n int v = in.nextInt() - 1;\n int u = in.nextInt() - 1;\n g[v].add(u);\n g[u].add(v);\n }\n dp = new long[n];\n find_son(0,-1);\n }\n}\n\nclass RANDOMIZER {\n static Random rnd = new Random();\n\n static int randomize() {\n return rnd.nextInt();\n }\n}\n\nclass array {\n long a[];\n\n array(long a[]) {\n this.a = a;\n }\n\n array(int n) {\n a = new long[n];\n }\n\n void shuffle() {\n for (int i = 0; i < a.length; i++) {\n int id1 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;\n int id2 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;\n long t = a[id1];\n a[id1] = a[id2];\n a[id2] = t;\n }\n }\n\n void reverse(int l, int r) {\n for (int i = l; i < l + (r - l + 1) >> 1; i++) {\n long t = a[i];\n a[i] = a[r - i];\n a[r - i] = t;\n }\n }\n\n long[] right_shift(int shift) {\n long aa[] = new long[a.length];\n for (int i = 0; i < a.length; i++) {\n aa[(i + shift) % a.length] = a[i];\n }\n return aa;\n }\n\n void add(int l, int r, long val) {\n for (int i = l; i <= r; i++) {\n a[i] += val;\n }\n }\n\n void print(PrintWriter out) {\n for (int i = 0; i < a.length; i++) {\n out.print(a[i] + \" \");\n }\n }\n\n void copy(long t[]) {\n for (int i = 0; i < a.length; i++) {\n a[i] = t[i];\n }\n }\n\n void scan(FastScanner in) throws IOException {\n for (int i = 0; i < a.length; i++) {\n a[i] = in.nextLong();\n }\n }\n\n long getSum() {\n long sum = 0;\n long md = (long) 1e16;\n for (int i = 0; i < a.length; i++) {\n sum += a[i];\n sum %= md;\n }\n return sum;\n }\n\n long getMin() {\n long min = Long.MAX_VALUE;\n for (int i = 0; i < a.length; i++) {\n min = min(min, a[i]);\n }\n return min;\n }\n\n long getMax() {\n long max = Long.MIN_VALUE;\n for (int i = 0; i < a.length; i++) {\n max = max(max, a[i]);\n }\n return max;\n }\n\n int ceilingID(long val) {\n int l = 0;\n int r = a.length - 1;\n while (l + 1 != r) {\n int m = (l + r) >> 1;\n if (a[m] >= val) r = m;\n else l = m;\n }\n int pr = l;\n if (pr > 0 && a[pr - 1] >= val) pr--;\n if (a[pr] < val) pr++;\n if (pr < a.length && a[pr] < val) pr++;\n return pr;\n }\n}\n\nclass dsu {\n int p[];\n int max[];\n\n dsu(int n) {\n p = new int[n];\n max = new int[n];\n for (int i = 0; i < n; i++) {\n p[i] = i;\n max[i] = i;\n }\n }\n\n int get(int a) {\n if (p[a] == a) return a;\n return p[a] = get(p[a]);\n }\n\n void merge(int a, int b) {\n a = get(a);\n b = get(b);\n if (a != b) {\n p[a] = b;\n max[b] = max(max[a], max[b]);\n }\n }\n}\n\nclass vertex {\n int next[];\n}\n\nclass trie {\n vertex t[];\n int sz = 1;\n int k;\n\n trie(int k) {\n this.k = k;\n t = new vertex[300000];\n for (int i = 0; i < t.length; i++) {\n t[i] = new vertex();\n t[i].next = new int[k];\n for (int j = 0; j < k; j++) {\n t[i].next[j] = -1;\n }\n }\n }\n\n void add(String s, int id) {\n int v = 0;\n for (int i = 0; i < s.length(); i++) {\n char rc = (char) (s.charAt(i) - 'a');\n if (t[v].next[rc] == -1) {\n t[v].next[rc] = sz++;\n }\n v = t[v].next[rc];\n }\n }\n}\n\nclass StringHelper {\n char[] s;\n long hash[];\n long px[];\n long mod = (int) 1e9 + 7;\n long x = 255;\n int n;\n\n public StringHelper(String s) {\n this.s = s.toCharArray();\n n = s.length();\n }\n\n int[] pi() {\n int pi[] = new int[n];\n for (int i = 1; i < n; i++) {\n int j = pi[i - 1];\n while (j > 0 && s[i] != s[j]) j = pi[j - 1];\n pi[i] = s[i] == s[j] ? j + 1 : j;\n }\n return pi;\n }\n\n void calcHash() {\n hash = new long[n + 1];\n px = new long[n + 3];\n px[0] = 1;\n for (int i = 1; i < n + 3; i++) {\n px[i] = px[i - 1] * x % mod;\n }\n for (int i = 1; i < n + 1; i++) {\n hash[i] = (hash[i - 1] * x % mod + s[i - 1] + mod) % mod;\n }\n }\n\n long getHash(int l, int r) {\n return (hash[r + 1] - hash[l] * px[r - l + 1] % mod + mod) % mod;\n }\n}\n\nclass IMPLICITDT {\n long val;\n int y;\n int sz;\n IMPLICITDT l, r;\n\n static int getSize(IMPLICITDT t) {\n return t == null ? 0 : t.sz;\n }\n\n private static void recalc(IMPLICITDT t) {\n if (t == null) return;\n int LSZ = t.l == null ? 0 : t.l.sz;\n int RSZ = t.r == null ? 0 : t.r.sz;\n t.sz = LSZ + RSZ + 1;\n }\n\n IMPLICITDT() {\n }\n\n IMPLICITDT(long cost, int y, IMPLICITDT l, IMPLICITDT r) {\n this.val = cost;\n this.y = y;\n this.l = l;\n this.r = r;\n recalc(this);\n }\n\n IMPLICITDT(long cost, int y) {\n this.val = cost;\n this.y = y;\n recalc(this);\n }\n\n static long get(IMPLICITDT t, int id) {\n int LSZ = getSize(t.l);\n if (LSZ == id) return t.val;\n if (LSZ < id) return get(t.r, id - LSZ - 1);\n return get(t.l, id);\n }\n\n static IMPLICITDT split(IMPLICITDT T, int x) {\n IMPLICITDT RES = new IMPLICITDT();\n if (T == null) {\n return RES;\n }\n if (getSize(T.l) > x) {\n IMPLICITDT lsplit = split(T.l, x);\n RES.l = lsplit.l;\n RES.r = T;\n T.l = lsplit.r;\n } else {\n IMPLICITDT rsplit = split(T.r, x - getSize(T.l) - 1);\n RES.r = rsplit.r;\n RES.l = T;\n T.r = rsplit.l;\n }\n recalc(RES);\n recalc(T);\n return RES;\n }\n\n static IMPLICITDT merge(IMPLICITDT L, IMPLICITDT R) {\n if (L == null) return R;\n if (R == null) return L;\n if (L.y > R.y) return new IMPLICITDT(L.val, L.y, L.l, merge(L.r, R));\n else return new IMPLICITDT(R.val, R.y, merge(L, R.l), R.r);\n }\n\n static IMPLICITDT insert(IMPLICITDT T, long val, int id) {\n if (T == null) return new IMPLICITDT(val, RANDOMIZER.randomize());\n IMPLICITDT _T = split(T, id);\n IMPLICITDT _TR = new IMPLICITDT(val, RANDOMIZER.randomize());\n IMPLICITDT NEWTREAP = merge(_T.l, _TR);\n IMPLICITDT TREAP = merge(NEWTREAP, _T.r);\n recalc(TREAP);\n return TREAP;\n }\n}\n\nclass stSUM {\n int t[];\n int a[];\n\n stSUM(int a[]) {\n this.a = a;\n t = new int[a.length * 4];\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = a[l];\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = t[v * 2] + t[v * 2 + 1];\n }\n }\n\n void upd(int v, int l, int r, int pos, int x) {\n if (l == r) t[v] = x;\n else {\n int m = (l + r) >> 1;\n if (pos <= m) upd(v * 2, l, m, pos, x);\n else upd(v * 2 + 1, m + 1, r, pos, x);\n t[v] = t[v * 2] + t[v * 2 + 1];\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (ql <= l && r <= qr) return t[v];\n if (l > qr || ql > r) return 0;\n int m = (l + r) >> 1;\n return query(v * 2, l, m, ql, qr) + query(v * 2 + 1, m + 1, r, ql, qr);\n }\n}\n\nclass stMIN {\n int t[];\n int a[];\n\n stMIN(int a[]) {\n this.a = a;\n t = new int[a.length * 4];\n }\n\n void build(int v, int l, int r) {\n if (l == r) t[v] = a[l];\n else {\n int m = (l + r) >> 1;\n build(v * 2, l, m);\n build(v * 2 + 1, m + 1, r);\n t[v] = min(t[v * 2], t[v * 2 + 1]);\n }\n }\n\n void upd(int v, int l, int r, int pos, int x) {\n if (l == r) t[v] = x;\n else {\n int m = (l + r) >> 1;\n if (pos <= m) upd(v * 2, l, m, pos, x);\n else upd(v * 2 + 1, m + 1, r, pos, x);\n t[v] = min(t[v * 2], t[v * 2 + 1]);\n }\n }\n\n int query(int v, int l, int r, int ql, int qr) {\n if (ql <= l && r <= qr) return t[v];\n if (l > qr || ql > r) return Integer.MAX_VALUE;\n int m = (l + r) >> 1;\n return min(query(v * 2, l, m, ql, qr), query(v * 2 + 1, m + 1, r, ql, qr));\n }\n}\n\nclass DT {\n long val;\n int x, y;\n int sz;\n DT l, r;\n\n DT() {\n recalc(this);\n }\n\n DT(int x, int y, long val) {\n this.x = x;\n this.y = y;\n this.val = val;\n recalc(this);\n }\n\n DT(int x, int y, DT l, DT r, long val) {\n this.x = x;\n this.y = y;\n this.l = l;\n this.r = r;\n this.val = val;\n recalc(this);\n }\n\n static DT split(DT t, int x) {\n DT res = new DT();\n if (t == null) {\n res.l = null;\n res.r = null;\n return res;\n }\n if (x < t.x) {\n DT lsplit = split(t.l, x);\n res.l = lsplit.l;\n res.r = t;\n t.l = lsplit.r;\n } else {\n DT rsplit = split(t.r, x);\n res.r = rsplit.r;\n res.l = t;\n t.r = rsplit.l;\n }\n recalc(t);\n recalc(res);\n return res;\n }\n\n static DT merge(DT t1, DT t2) {\n if (t1 == null || t2 == null)\n return t1 == null ? t2 : t1;\n if (t1.y < t2.y) {\n t1.r = merge(t1.r, t2);\n recalc(t1);\n return t1;\n } else {\n t2.l = merge(t1, t2.l);\n recalc(t2);\n return t2;\n }\n }\n\n static void recalc(DT t) {\n if (t == null) return;\n int lsz = t.l == null ? 0 : t.l.sz;\n int rsz = t.r == null ? 0 : t.r.sz;\n t.sz = lsz + rsz + 1;\n }\n\n static DT insert(DT t, int x, long val) {\n try {\n if (t == null) {\n DT ret = new DT(x, RANDOMIZER.randomize(), val);\n recalc(ret);\n return ret;\n }\n DT split = split(t, x);\n DT prelast = merge(split.l, new DT(x, RANDOMIZER.randomize(), val));\n DT newtreap = merge(prelast, split.r);\n recalc(newtreap);\n return newtreap;\n } catch (Exception e) {\n System.exit(0);\n return new DT();\n }\n }\n\n static long find_kth(DT t, int k) {\n if (t.l == null && k == 1)\n return t.val;\n if (t.l != null && t.l.sz == k - 1)\n return t.val;\n if (t.l != null && t.l.sz >= k)\n return find_kth(t.l, k);\n else\n return find_kth(t.r, k - (t.l == null ? 0 : t.l.sz) - 1);\n }\n\n}\n\n\nclass FT {\n private int[] a;\n private long[] t;\n\n FT(int[] a) {\n this.a = a;\n t = new long[a.length];\n }\n\n void inc(int i, int delta) {\n for (; i < a.length; i = (i | (i + 1)))\n t[i] += delta;\n }\n\n long sum(int l, int r) {\n return sum(r) - sum(l - 1);\n }\n\n private long sum(int r) {\n long sum = 0;\n for (; r >= 0; r = (r & (r + 1)) - 1) {\n sum += t[r];\n }\n return sum;\n }\n}\n\nclass LAZY_ST {\n long min[], sum[], set[];\n int last;\n long not_set = Long.MAX_VALUE;\n\n LAZY_ST(long a[]) {\n int n = a.length;\n last = n - 1;\n min = new long[4 * n];\n sum = new long[4 * n];\n set = new long[4 * n];\n for (int i = 0; i < 4 * n; i++) {\n set[i] = not_set;\n }\n build(0, 0, last, a);\n }\n\n void build(int v, int l, int r, long a[]) {\n if (l == r) {\n min[v] = a[l];\n return;\n }\n int m = ((l + r) >> 1);\n build(v * 2 + 1, l, m, a);\n build(v * 2 + 2, m + 1, r, a);\n min[v] = Math.min(min[v * 2 + 1], min[v * 2 + 2]);\n }\n\n void push(int v) {\n if (set[v] != not_set) {\n min[v] = set[v];\n sum[v * 2 + 1] = sum[v * 2 + 2] = 0;\n set[v * 2 + 1] = set[v * 2 + 2] = set[v];\n set[v] = not_set;\n }\n\n min[v] += sum[v];\n sum[v * 2 + 1] += sum[v];\n sum[v * 2 + 2] += sum[v];\n sum[v] = 0;\n }\n\n void upd(int v) {\n min[v] = Math.min(get_el(v * 2 + 1), get_el(v * 2 + 2));\n }\n\n long get_el(int v) {\n return (set[v] == not_set ? min[v] : set[v]) + sum[v];\n }\n\n void set(int l, int r, long x) {\n set(0, 0, last, l, r, x);\n }\n\n void set(int v, int l, int r, int left, int right, long x) {\n if (l > right || r < left) return;\n if (l >= left && r <= right) {\n sum[v] = 0;\n set[v] = x;\n return;\n }\n push(v);\n int m = ((l + r) >> 1);\n\n set(v * 2 + 1, l, m, left, right, x);\n set(v * 2 + 2, m + 1, r, left, right, x);\n\n upd(v);\n }\n\n void add(int l, int r, long x) {\n add(0, 0, last, l, r, x);\n }\n\n void add(int v, int l, int r, int left, int right, long x) {\n if (l > right || r < left) return;\n if (l >= left && r <= right) {\n sum[v] += x;\n return;\n }\n push(v);\n int m = ((l + r) >> 1);\n\n add(v * 2 + 1, l, m, left, right, x);\n add(v * 2 + 2, m + 1, r, left, right, x);\n\n upd(v);\n }\n\n long get(int l, int r) {\n return get(0, 0, last, l, r);\n }\n\n long get(int v, int l, int r, int left, int right) {\n if (l > right || r < left) return (long) 1e17;\n\n if (l >= left && r <= right) {\n return get_el(v);\n }\n push(v);\n int m = ((l + r) >> 1);\n\n long ans = Math.min(get(v * 2 + 1, l, m, left, right), get(v * 2 + 2, m + 1, r, left, right));\n upd(v);\n return ans;\n }\n\n}\n\nclass multiset {\n TreeMap t;\n\n void insert(long val) {\n t.put(val, t.getOrDefault(val, 0) + 1);\n }\n\n void erase(long val) {\n int nw = t.getOrDefault(val, 1);\n if (nw == 1) t.remove(val);\n else t.put(val, nw - 1);\n }\n\n long ceiling(long val) {\n return t.ceilingKey(val);\n }\n\n long floor(long val) {\n return t.floorKey(val);\n }\n\n long higher(long val) {\n return t.higherKey(val);\n }\n\n long lower(long val) {\n return t.lowerKey(val);\n }\n\n int count(long val) {\n return t.getOrDefault(val, 0);\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}\n\nclass tree {\n ArrayList g[];\n int n;\n ArrayList order;\n int first[];\n int h[];\n int t[];\n int rt;\n tree(ArrayList g[]) {\n this.g = g;\n this.n = g.length;\n order = new ArrayList<>();\n first = new int[n];\n fill(first, -1);\n h = new int[n];\n rt = 0;\n dfs(rt, -1);\n prepare();\n }\n\n void dfs(int v, int p) {\n if (first[v] == -1) first[v] = order.size();\n order.add(v);\n for (int to : g[v]) {\n if (to == p) continue;\n h[to] = h[v] + 1;\n dfs(to, v);\n order.add(v);\n }\n }\n void prepare(){\n t = new int[order.size() * 4];\n build(1,0,order.size()-1);\n }\n void build(int v, int l, int r){\n if(l == r)t[v] = order.get(l);\n else{\n int m = (l + r) >> 1;\n build(v*2,l,m);\n build(v*2+1,m+1,r);\n t[v] = h[t[v*2]] < h[t[v*2 + 1]] ? t[v*2] : t[v*2+1];\n }\n }\n int query(int v, int l, int r, int ql, int qr){\n if(l > qr || ql > r)return Integer.MAX_VALUE;\n if(ql <= l && r <= qr)return t[v];\n int m = (l + r ) >> 1;\n int v1 = query(v*2,l,m,ql,qr);\n int v2 = query(v*2+1,m+1,r,ql,qr);\n if(v1 == Integer.MAX_VALUE)return v2;\n if(v2 == Integer.MAX_VALUE)return v1;\n return h[v1] < h[v2] ? v1 : v2;\n }\n int lca(int a, int b){\n int l = first[a];\n int r = first[b];\n return query(1,0,order.size()-1,min(l,r),max(l,r));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "809e7ddf3459ac3aca2f3a2dc240ad6f", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n\n\tlong MOD = 1000000009;\t\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\t\t\n\t\tlong[] ans = new long[n + 1];\n\t\tlong[] q = new long[n + 1];\n\t\tlong[] Q = new long[n + 1];\n\t\tq[0] = Q[0] = 1;\t\t\n\t\tfor(int i = 1; i <= n; ++i) {\t\t\n\t\t\tq[i] = (2 * (1 + q[i - 1]) + 1) % MOD;\n\t\t\tQ[i] = q[i] * Q[i - 1];\n\t\t}\t\t\n\t\tans[2] = 2;\n\t\tfor(int t = 4; t <= n; t += 2) {\n\t\t\tlong qq = (Q[(t - 4) / 2]);\n\t\t\tans[t] = (ans[t - 2] + 4 * qq) % MOD;\n\t\t}\t\t\n\t\tlong tmp = ans[n];\n\t\t//pw.println(tmp);\n\t\tlong p = (tmp * tmp + 1) * 2 % MOD;\n\t\tpw.println(p);\n\t}\n\t\n\tstatic final String filename = \"A\";\n\tstatic final boolean fromConsole = true;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tif (!fromConsole) {\n\t\t\t\tin = new BufferedReader(new FileReader(filename + \".in\"));\n\t\t\t\tpw = new PrintWriter(filename + \".out\");\n\t\t\t} else {\n\t\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tpw = new PrintWriter(System.out);\n\t\t\t}\n\t\t\tst = new StringTokenizer(\"\");\n\t\t\tlong st = System.currentTimeMillis();\n\t\t\tsolve();\t\t\t\n\t\t\t//pw.printf(\"\\nWorking time: %d ms\\n\", System.currentTimeMillis() - st);\t\t\t\n\t\t\tpw.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\tprivate StringTokenizer st;\n\tprivate BufferedReader in;\n\tprivate PrintWriter pw;\t\n\t\n\tboolean hasNext() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn st.hasMoreTokens();\n\t}\n\t\n\tString next() throws IOException {\n\t\treturn hasNext() ? st.nextToken() : null;\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tBigInteger nextBigInteger() throws IOException {\n\t\treturn new BigInteger(next());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\t}\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "478ec773e112f7abb4a3f01caa918754", "src_uid": "dbcb1077e7421554ba5d69b64d22c937", "difficulty": 2600.0} {"lang": "Java 6", "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(6 <= n)dp[6] = 5;\n\t\tfor(int i = 10;i <= n;i+=4){\n\t\t\tdp[i] = ((dp[i-4] + 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-1] == 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]+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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cbb12f4e8c5c8e55d3a71cba28d78fe5", "src_uid": "dbcb1077e7421554ba5d69b64d22c937", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class e {\n\t\n\tfinal long MOD = 1000000009;\n\tint n;\n\n\tprivate void solve() throws Exception {\n\t\tn = nextInt();\n\t\tlong ans = 1;\n\t\tlong[] val = new long[n + 1];\n\t\tval[2] = val[n] = 1;\n\t\tlong tmp = 0;\n\t\tlong sum = 1;\n\t\tfor (int i = 3; i <= n; i += 2){\n\t\t\tval[i - 1] = 1;\n\t\t\tval[i] = sum;\n\t\t\ttmp = ((tmp + 2) * 2) % MOD;\n\t\t\tsum = (sum + tmp) % MOD;\n\t\t}\n\t\tfor (int i = 3; i <= n; ++i){\n\t\t\tval[i] = (val[i] * val[i - 1]) % MOD;\n\t\t}\n\t\tlong res = 0;\n\t\tfor (int i = 1; i <= n; ++i){\n\t\t\tif (i == n){\n\t\t\t\tres = (res + val[i]) % MOD;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tres = (res + val[i] + val[i + 1]) % MOD;\n\t\t\t}\n\t\t}\n\t\tans = (ans + res * res) % MOD;\n\t\tans = (ans * 2) % MOD;\n\t\tout.print(ans);\n\t}\n\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\n\tPrintWriter out;\n\tBufferedReader in;\n\tStringTokenizer St;\n\n\tvoid NOO(Exception e) {\n\t\te.printStackTrace();\n\t\tSystem.exit(1);\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\tString nextToken() {\n\t\twhile (!St.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tString line = in.readLine();\n\t\t\t\tSt = new StringTokenizer(line);\n\t\t\t} catch (Exception e) {\n\t\t\t\tNOO(e);\n\t\t\t}\n\t\t}\n\t\treturn St.nextToken();\n\t}\n\n\tprivate e(String name) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new FileReader(name + \".in\"));\n\t\t\tSt = new StringTokenizer(\"\");\n\t\t\tout = new PrintWriter(new FileWriter(name + \".out\"));\n\t\t} catch (Exception e) {\n\t\t\tNOO(e);\n\t\t}\n\t}\n\n\tprivate e() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tSt = new StringTokenizer(\"\");\n\t\t\tout = new PrintWriter(System.out);\n\t\t} catch (Exception e) {\n\t\t\tNOO(e);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tnew e().run();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "56223127096936d8055eca1e137cead5", "src_uid": "dbcb1077e7421554ba5d69b64d22c937", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "/**\n * Codeforces Beta Round 15\n * \n * @author ProjectYoung\n */\n\nimport 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 CF15E {\n private static final int base = 1000000009;\n\n private long work(int k) {\n long[] powMod = new long[k + 3];\n powMod[0] = 1;\n for (int i = 1; i <= k + 2; i++) {\n powMod[i] = (powMod[i - 1] << 1) % base;\n }\n long res = 0;\n for (int i = 0; i < k; i++) {\n res += 4 * (powMod[i + 2] - 3);\n }\n return res % base;\n }\n\n private void solve(InputReader in, PrintWriter out) {\n // If n = 2, the answer is 10.\n int n = in.nextInt() - 2;\n long res = 10;\n long num = work(n >> 1);\n res += (num + 4) * num * 2;\n out.println(res % base);\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 CF15E().solve(in, out);\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a036e0a31c97a07dd01b8864522a7274", "src_uid": "dbcb1077e7421554ba5d69b64d22c937", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class CF506E {\n\n final static int MOD = 10007;\n\n static int[][] mul(int[][] a, int[][] b) {\n int[][] c = new int[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n for (int j = 0; j < a.length; ++j) {\n for (int k = 0; k < a.length; ++k) {\n c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;\n }\n }\n }\n return c;\n }\n\n static int[][] pow(int[][] a, long pow) {\n int[][] r = new int[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n r[i][i] = 1;\n }\n while (pow > 0) {\n if (pow % 2 == 1) {\n r = mul(r, a);\n }\n pow /= 2;\n a = mul(a, a);\n }\n return r;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n String s = in.next();\n int n = s.length();\n int k = n + in.nextInt();\n int[][][] d = new int[n + 1][n + 1][n + 1];\n d[0][n][0] = 1;\n for (int len = n; len > 0; --len) {\n for (int i = 0; i + len <= n; ++i) {\n for (int u = 0; u <= n; ++u) {\n if (d[i][i + len][u] != 0) {\n if (s.charAt(i) == s.charAt(i + len - 1)) {\n d[i + 1][i + len - 1][u + 1] = (d[i + 1][i + len - 1][u + 1] + d[i][i + len][u]) % MOD;\n } else {\n d[i + 1][i + len][u] = (d[i + 1][i + len][u] + d[i][i + len][u]) % MOD;\n d[i][i + len - 1][u] = (d[i][i + len - 1][u] + d[i][i + len][u]) % MOD;\n }\n }\n }\n }\n }\n int[][] d1 = new int[n + 1][n + 1];\n int[][] d2 = new int[n + 1][n + 1];\n for (int i = 0; i < n; ++i) {\n for (int u = 0; 2 * u <= n; ++u) {\n d1[u][n - 2 * u] += d[i][i][u];\n if (2 * u <= n - 1) {\n d2[u][n - 2 * u - 1] += d[i][i + 1][u];\n }\n }\n }\n int ans = 0;\n for (int u = 0; u <= n; ++u) {\n for (int v = 0; v <= n; ++v) {\n if (d1[u][v] != 0) { // aa\n int states = u + v + 1;\n int[][] a = new int[states][states];\n for (int i = 0; i < u; ++i) {\n a[i][i] = 25;\n a[i][i + 1] = 1;\n }\n for (int i = u; i < u + v; ++i) {\n a[i][i] = 24;\n a[i][i + 1] = 1;\n }\n a = pow(a, (k - 1) / 2);\n int cur = a[0][states - 1];\n if (k % 2 == 1) {\n cur = cur * 26 % MOD;\n }\n ans = (ans + d1[u][v] * cur) % MOD;\n// System.err.println(\"d1: \" + u + \" \" + v + \" \" + d1[u][v] + \" \" + cur);\n }\n if (d2[u][v] != 0) { // a\n int states = u + v + 2;\n int[][] a = new int[states][states];\n for (int i = 0; i < u; ++i) {\n a[i][i] = 25;\n a[i][i + 1] = 1;\n }\n for (int i = u; i < u + v; ++i) {\n a[i][i] = 24;\n a[i][i + 1] = 1;\n }\n a[u + v][u + v] = 25;\n a[u + v][u + v + 1] = 1;\n// System.err.println(Arrays.deepToString(a));\n a = pow(a, (k + 1) / 2);\n int cur = a[0][states - 1];\n ans = (ans + d2[u][v] * cur) % MOD;\n// System.err.println(\"d2: \" + u + \" \" + v + \" \" + d2[u][v] + \" \" + cur);\n }\n }\n }\n out.println(ans);\n out.flush();\n }\n\n /*\n0\n0\n6624\n8739\n\n */\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n// Random rnd = new Random(42);\n// while (rnd != null) {\n// int n = rnd.nextInt(200) + 1;\n// StringBuilder sb = new StringBuilder();\n// for (int i = 0; i < n; ++i) {\n// sb.append((char)('a' + rnd.nextInt(3)));\n// }\n// sb.append(\"\\n\");\n// sb.append(rnd.nextInt(100));\n// solve(new Input(sb.toString()), out);\n// }\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ef5633c5c8a94036b7b7131a8939c634", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8", "difficulty": 3000.0} {"lang": "Java 8", "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 + 1];\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9544c2ddafd97251675da004ea88692e", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class CF506E {\n\n final static int MOD = 10007;\n\n static int[][] mul(int[][] a, int[][] b) {\n int[][] c = new int[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n for (int j = i; j < a.length; ++j) {\n long sum = 0;\n for (int k = i; k <= j; ++k) {\n sum += a[i][k] * b[k][j];\n }\n c[i][j] = (int) (sum % MOD);\n }\n }\n return c;\n }\n\n static int[][] pow(int[][] a, long pow) {\n int[][] r = new int[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n r[i][i] = 1;\n }\n while (pow > 0) {\n if (pow % 2 == 1) {\n r = mul(r, a);\n }\n pow /= 2;\n a = mul(a, a);\n }\n return r;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n String s = in.next();\n int n = s.length();\n int k = n + in.nextInt();\n int[][][] d = new int[n + 1][n + 1][n + 1];\n d[0][n][0] = 1;\n for (int len = n; len > 0; --len) {\n for (int i = 0; i + len <= n; ++i) {\n for (int u = 0; u <= n; ++u) {\n if (d[i][i + len][u] != 0) {\n if (s.charAt(i) == s.charAt(i + len - 1)) {\n d[i + 1][i + len - 1][u + 1] = (d[i + 1][i + len - 1][u + 1] + d[i][i + len][u]) % MOD;\n } else {\n d[i + 1][i + len][u] = (d[i + 1][i + len][u] + d[i][i + len][u]) % MOD;\n d[i][i + len - 1][u] = (d[i][i + len - 1][u] + d[i][i + len][u]) % MOD;\n }\n }\n }\n }\n }\n int[][] d1 = new int[n + 1][n + 1];\n int[][] d2 = new int[n + 1][n + 1];\n for (int i = 0; i < n; ++i) {\n for (int u = 0; 2 * u <= n; ++u) {\n d1[u][n - 2 * u] += d[i][i][u];\n if (2 * u <= n - 1) {\n d2[u][n - 2 * u - 1] += d[i][i + 1][u];\n }\n }\n }\n int ans = 0;\n int[][] a0 = new int[3 * n + 1][3 * n + 1];\n for (int i = 0; i < n; ++i) {\n a0[i][i] = 25;\n a0[i][i + 1] = 1;\n if (i + 1 == n) {\n a0[i][2 * n] = 1;\n }\n }\n for (int i = n; i < 2 * n; ++i) {\n a0[i][i] = 24;\n if (i + 1 != 2 * n) {\n a0[i][i + 1] = 1;\n }\n a0[i][n + i + 1] = 1;\n }\n int[][] a0low = pow(a0, (k - 1) / 2);\n int[][] a0high = k % 2 == 1 ? a0low : mul(a0low, a0);\n for (int u = 0; u <= n; ++u) {\n for (int v = 0; v <= n; ++v) {\n if (d1[u][v] != 0 && d2[u][v] != 0) {\n System.err.println(\"here\");\n }\n if (d1[u][v] != 0) { // aa\n int cur = a0low[n - u][2 * n + v];\n if (k % 2 == 1) {\n cur = cur * 26 % MOD;\n }\n ans = (ans + d1[u][v] * cur) % MOD;\n// System.err.println(\"d1: \" + u + \" \" + v + \" \" + d1[u][v] + \" \" + cur);\n }\n if (d2[u][v] != 0) { // a\n int cur = a0high[n - u - 1][2 * n + v];\n ans = (ans + d2[u][v] * cur) % MOD;\n// System.err.println(\"d2: \" + u + \" \" + v + \" \" + d2[u][v] + \" \" + cur);\n }\n }\n }\n out.println(ans);\n out.flush();\n }\n\n /*\n0 78\n0 76\n6624 57\n8739 55\n0 123\n0 93\n0 99\n1871 122\n6968 75\n8247 1\n0 79\n3404 10\n0 19\n0 85\n4715 23\n8609 1\n1910 86\n721 113\n4055 12\n659 82\n0 115\n0 53\n944 57\n9422 11\n\n\n */\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n// Random rnd = new Random(42);\n// while (rnd != null) {\n// int n = 200;\n// StringBuilder sb = new StringBuilder();\n// for (int i = 0; i < n; ++i) {\n// sb.append((char)('a' + rnd.nextInt(3)));\n// }\n// sb.append(\"\\n\");\n// sb.append(rnd.nextInt(100));\n// solve(new Input(sb.toString()), out);\n//// return;\n// }\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ab8a101899480a4a54f6d8b5a0b1265", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class CF506E {\n\n final static int MOD = 10007;\n\n static int[][] mul(int[][] a, int[][] b) {\n int[][] c = new int[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n for (int j = i; j < a.length; ++j) {\n long sum = 0;\n for (int k = i; k <= j; ++k) {\n sum += a[i][k] * b[k][j];\n }\n c[i][j] = (int) (sum % MOD);\n }\n }\n return c;\n }\n\n static int[][] pow(int[][] a, long pow) {\n int[][] r = new int[a.length][a.length];\n for (int i = 0; i < a.length; ++i) {\n r[i][i] = 1;\n }\n while (pow > 0) {\n if (pow % 2 == 1) {\n r = mul(r, a);\n }\n pow /= 2;\n a = mul(a, a);\n }\n return r;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n String s = in.next();\n int n = s.length();\n int k = n + in.nextInt();\n int[][][] d = new int[n + 1][n + 1][n + 1];\n d[0][n][0] = 1;\n for (int len = n; len > 0; --len) {\n for (int i = 0; i + len <= n; ++i) {\n for (int u = 0; u <= n; ++u) {\n if (d[i][i + len][u] != 0) {\n if (s.charAt(i) == s.charAt(i + len - 1)) {\n d[i + 1][i + len - 1][u + 1] = (d[i + 1][i + len - 1][u + 1] + d[i][i + len][u]) % MOD;\n } else {\n d[i + 1][i + len][u] = (d[i + 1][i + len][u] + d[i][i + len][u]) % MOD;\n d[i][i + len - 1][u] = (d[i][i + len - 1][u] + d[i][i + len][u]) % MOD;\n }\n }\n }\n }\n }\n int[][] d1 = new int[n + 1][n + 1];\n int[][] d2 = new int[n + 1][n + 1];\n for (int i = 0; i < n; ++i) {\n for (int u = 0; 2 * u <= n; ++u) {\n d1[u][n - 2 * u] += d[i][i][u];\n if (2 * u <= n - 1) {\n d2[u][n - 2 * u - 1] += d[i][i + 1][u];\n }\n }\n }\n int ans = 0;\n int[][] a0 = new int[3 * n + 1][3 * n + 1];\n for (int i = 0; i < n; ++i) {\n a0[i][i] = 25;\n a0[i][i + 1] = 1;\n if (i + 1 == n) {\n a0[i][2 * n] = 1;\n }\n }\n for (int i = n; i < 2 * n; ++i) {\n a0[i][i] = 24;\n if (i + 1 != 2 * n) {\n a0[i][i + 1] = 1;\n }\n a0[i][n + i + 1] = 1;\n }\n int[][] a0low = pow(a0, (k - 1) / 2);\n int[][] a0high = mul(a0low, a0);\n for (int u = 0; u <= n; ++u) {\n for (int v = 0; v <= n; ++v) {\n if (d1[u][v] != 0 && d2[u][v] != 0) {\n System.err.println(\"here\");\n }\n if (d1[u][v] != 0) { // aa\n int cur = a0low[n - u][2 * n + v];\n if (k % 2 == 1) {\n cur = cur * 26 % MOD;\n }\n ans = (ans + d1[u][v] * cur) % MOD;\n// System.err.println(\"d1: \" + u + \" \" + v + \" \" + d1[u][v] + \" \" + cur);\n }\n if (d2[u][v] != 0) { // a\n int cur = a0high[n - u - 1][2 * n + v];\n ans = (ans + d2[u][v] * cur) % MOD;\n// System.err.println(\"d2: \" + u + \" \" + v + \" \" + d2[u][v] + \" \" + cur);\n }\n }\n }\n out.println(ans);\n out.flush();\n }\n\n /*\n0 78\n0 76\n6624 57\n8739 55\n0 123\n0 93\n0 99\n1871 122\n6968 75\n8247 1\n0 79\n3404 10\n0 19\n0 85\n4715 23\n8609 1\n1910 86\n721 113\n4055 12\n659 82\n0 115\n0 53\n944 57\n9422 11\n\n\n */\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n// Random rnd = new Random(42);\n// while (rnd != null) {\n// int n = 200;\n// StringBuilder sb = new StringBuilder();\n// for (int i = 0; i < n; ++i) {\n// sb.append((char)('a' + rnd.nextInt(3)));\n// }\n// sb.append(\"\\n\");\n// sb.append(rnd.nextInt(100));\n// solve(new Input(sb.toString()), out);\n//// return;\n// }\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96ac2c7f99065ee379bc0fb9c031e7db", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8", "difficulty": 3000.0} {"lang": "Java 8", "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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "09f3da4662d759fe34d7bf4d0ad093ad", "src_uid": "57ad95bb938906f7550f7eb6422130f7", "difficulty": 2800.0} {"lang": "Java 8", "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 < i + 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8b3b83adb7bb70a917dd3d5eda18b32e", "src_uid": "57ad95bb938906f7550f7eb6422130f7", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\n\n/**\n * Created by dalt on 2018/4/2.\n */\npublic class CF954H {\n public static final int MOD = (int) (1e9 + 7);\n public static BlockReader input;\n public static PrintStream output;\n\n public static void main(String[] args) throws FileNotFoundException {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n input = new BlockReader(new FileInputStream(\"D:\\\\DataBase\\\\TESTCASE\\\\codeforces\\\\CF954H.in\"));\n output = System.out;\n } else {\n input = new BlockReader(System.in);\n output = new PrintStream(new BufferedOutputStream(System.out), false);\n }\n\n solve();\n\n output.flush();\n }\n\n public static void solve() {\n int n = input.nextInteger();\n long[] a = new long[n];\n long[] aRev = new long[n];\n long[] aChoose2Child = new long[n + 1];\n long[] aChoose2ChildRev = new long[n + 1];\n long negTwo = pow(2, MOD - 2);\n for (int i = 0, until = n - 1; i < until; i++) {\n a[i] = input.nextInteger();\n aRev[i] = pow(a[i], MOD - 2);\n }\n\n for (int i = 0; i < n; i++) {\n aChoose2Child[i] = a[i] * (a[i] - 1) % MOD;\n aChoose2ChildRev[i] = pow( aChoose2Child[i], MOD - 2);\n }\n\n long[] prefixMul = new long[n];\n long[] prefixRev = new long[n];\n prefixMul[0] = 1;\n prefixRev[0] = 1;\n for (int i = 1; i < n; i++) {\n prefixMul[i] = prefixMul[i - 1] * a[i - 1] % MOD;\n prefixRev[i] = prefixRev[i - 1] * aRev[i - 1] % MOD;\n }\n\n\n int m = (n - 1) * 2;\n long[] f = new long[m + 1];\n Loop dpLoop = new Loop<>(new long[m + 1][3], new long[m + 1][3]);\n final int ROTATE = 0;\n final int BALANCE = 2;\n final int LINE = 1;\n\n {\n long[][] next = dpLoop.turn();\n next[0][BALANCE] = 1;\n }\n for (int i = n - 2; i >= 0; i--) {\n long[][] former = dpLoop.get(0);\n long[][] next = dpLoop.turn();\n\n long aChooseRev = aChoose2ChildRev[i + 1] * a[i + 1] % MOD * a[i + 1] % MOD * aChoose2Child[i] % MOD;\n for (int j = 2, until = ((n - 1) - i) * 2; j <= until; j++) {\n next[j][ROTATE] = (former[j - 2][ROTATE] * aChooseRev % MOD + former[j - 2][LINE] * aChoose2Child[i] % MOD) % MOD;\n\n int halfJ = j >> 1;\n if ((j & 1) == 0 && i + halfJ < n) {\n long possible = prefixMul[i + halfJ] * prefixRev[i + 1] % MOD;\n possible = possible * possible % MOD;\n next[j][BALANCE] = possible * aChoose2Child[i] % MOD * negTwo % MOD;\n } else {\n next[j][BALANCE] = 0;\n }\n\n if (i + j < n) {\n next[j][LINE] = prefixMul[i + j] * prefixRev[i] % MOD;\n } else {\n next[j][LINE] = 0;\n }\n }\n\n next[2][BALANCE] = aChoose2Child[i] * negTwo % MOD;\n next[1][LINE] = a[i];\n next[0][BALANCE] = 1;\n\n for (int j = 1; j <= m; j++) {\n f[j] = (f[j] + (next[j][LINE] + next[j][ROTATE] + next[j][BALANCE]) * prefixMul[i]) % MOD;\n }\n }\n\n for (int i = 1; i <= m; i++) {\n output.print(f[i]);\n output.print(' ');\n }\n }\n\n public static long pow(long x, int n) {\n int bit = 31 - Integer.numberOfLeadingZeros(n);\n long product = 1;\n for (; bit >= 0; bit--) {\n product = product * product % MOD;\n if (((1 << bit) & n) != 0) {\n product = product * x % MOD;\n }\n }\n return product;\n }\n\n public static class Loop {\n T[] data;\n int offset;\n\n public Loop(T... data) {\n this.data = data;\n }\n\n public T turn() {\n offset++;\n return get(0);\n }\n\n public T get(int index) {\n return data[(index + offset) % data.length];\n }\n }\n\n public static class BlockReader {\n static final int EOF = -1;\n InputStream is;\n byte[] dBuf;\n int dPos, dSize, next;\n StringBuilder builder = new StringBuilder();\n\n public BlockReader(InputStream is) {\n this(is, 4096);\n }\n\n public BlockReader(InputStream is, int bufSize) {\n this.is = is;\n dBuf = new byte[bufSize];\n next = nextByte();\n }\n\n public int nextByte() {\n while (dPos >= dSize) {\n if (dSize == -1) {\n return EOF;\n }\n dPos = 0;\n try {\n dSize = is.read(dBuf);\n } catch (Exception e) {\n }\n }\n return dBuf[dPos++];\n }\n\n public String nextBlock() {\n builder.setLength(0);\n skipBlank();\n while (next != EOF && !Character.isWhitespace(next)) {\n builder.append((char) next);\n next = nextByte();\n }\n return builder.toString();\n }\n\n public void skipBlank() {\n while (Character.isWhitespace(next)) {\n next = nextByte();\n }\n }\n\n public int nextInteger() {\n skipBlank();\n int ret = 0;\n boolean rev = false;\n if (next == '+' || next == '-') {\n rev = next == '-';\n next = nextByte();\n }\n while (next >= '0' && next <= '9') {\n ret = (ret << 3) + (ret << 1) + next - '0';\n next = nextByte();\n }\n return rev ? -ret : ret;\n }\n\n public int nextBlock(char[] data, int offset) {\n skipBlank();\n int index = offset;\n int bound = data.length;\n while (next != EOF && index < bound && !Character.isWhitespace(next)) {\n data[index++] = (char) next;\n next = nextByte();\n }\n return index - offset;\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != EOF;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "be5198a0e0bab459955eae60959b9cf1", "src_uid": "3b86dfd0d077bc857ae3de70f026a409", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n private static final int P = 1000000007;\n private static long pow(long x, int y) {\n long ret = 1;\n while (y > 0) {\n if (y %2 == 1) {\n ret = ret * x % P;\n }\n x = x * x % P;\n y /= 2;\n }\n return ret;\n }\n public static void main(String[] args) {\n Scanner cin = new Scanner(System.in);\n int n = cin.nextInt();\n int[] a = new int[n + 1];\n long[] rev = new long[n + 1];\n long[] res = new long[2 * n + 1];\n long[][] down = new long[n + 1][n + 1];\n long[][] up = new long[2][2 * n + 1];\n for (int i = 1; i < n; ++i) {\n a[i] = cin.nextInt();\n rev[i] = pow(a[i], P - 2);\n }\n for (int i = n; i > 0; --i) {\n down[i][0] = 1;\n for (int j = 1; j < n; ++j) {\n if (i + j > n) {\n break;\n }\n down[i][j] = down[i + 1][j - 1] * a[i] % P;\n }\n }\n\n long number = 1;\n for (int i = 1; i <= n; ++i) {\n for (int j = 1; j <= n; ++j) {\n res[j] = (res[j] + number * down[i][j] % P) % P;\n }\n number = (number * a[i]) % P;\n }\n int pre = 0;\n number = a[1];\n for (int i = 2; i <= n; ++i) {\n int now = 1 - pre;\n for (int j = 0; j <= 2 * n - 2; ++j) {\n up[now][j] = 0;\n }\n up[now][1] = 1;\n for (int j = 2; j <= 2 * n - 2; ++j) {\n if (j - 1 <= n) {\n up[now][j] = (up[pre][j - 1] + down[i - 1][j - 1] * rev[i - 1] % P * (a[i - 1] - 1) % P) % P;\n } else {\n up[now][j] = up[pre][j - 1];\n }\n }\n for (int j = 1; j <= 2 * n - 2; ++j) {\n res[j] = (res[j] + number * up[now][j] % P) % P;\n }\n number = (number * a[i]) % P;\n pre = now;\n }\n for (int i = 1; i <= 2 * n - 2; ++i) {\n System.out.print(res[i] * pow(2, P - 2) % P + \" \");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e1eaa630efed33b6af776b0ff8917138", "src_uid": "3b86dfd0d077bc857ae3de70f026a409", "difficulty": 2500.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\tpublic static void main (String[] args) { new A(); }\n\n\tint MOD = (int)1e9+7;\n\t\n\tpublic A() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tint n = fs.nextInt();\n\t\tint[] kids = new int[n];\n\t\tfor(int i = 0; i < n-1; i++) kids[i] = fs.nextInt();\n\t\t\n\t\tint[][] walkDown = new int[n][n];\n\t\tint[][] walkDown2 = new int[n][n];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint prod = 1, prod2 = 1;\n\t\t\tfor(int j = 1; j < n; j++) {\n\t\t\t\tif(i + j - 1 >= n) break;\n\t\t\t\t\n\t\t\t\tif(j == 1) prod2 = mult(prod2, Math.max(0, kids[i + j - 1] - 1));\n\t\t\t\telse prod2 = mult(prod2, kids[i + j - 1]);\n\t\t\t\t\n\t\t\t\tprod = mult(prod, kids[i + j - 1]);\n\t\t\t\t\n\t\t\t\twalkDown[i][j] = prod;\n\t\t\t\twalkDown2[i][j] = prod2;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] diagSum = new int[n][n];\n\t\tfor(int j = 0; j < n; j++) {\n\t\t\tdiagSum[0][j] = walkDown2[0][j];\n\t\t\tfor(int d = 1; ; d++) {\n\t\t\t\tint row = 0+d;\n\t\t\t\tint col = j+d;\n\t\t\t\tif(row >= n || col >= n) break;\n\t\t\t\tdiagSum[row][col] = walkDown2[row][col];\n\t\t\t\tdiagSum[row][col] = add(diagSum[row][col], diagSum[row-1][col-1]);\n\t\t\t}\n\t\t}\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tdiagSum[i][0] = walkDown[i][0];\n\t\t\tfor(int d = 1; ; d++) {\n\t\t\t\tint row = i+d;\n\t\t\t\tint col = 0+d;\n\t\t\t\tif(row >= n || col >= n) break;\n\t\t\t\tdiagSum[row][col] = walkDown2[row][col];\n\t\t\t\tdiagSum[row][col] = add(diagSum[row][col], diagSum[row-1][col-1]);\n\t\t\t}\n\t\t}\n//\t\tfor(int i = 0; i < n; i++) {\n//\t\t\tSystem.out.println(Arrays.toString(diagSum[i]));\n//\t\t}\n\t\t\n\t\tint[] freq = new int[n];\n\t\tfreq[0] = 1;\n\t\tfor(int i = 1; i < n; i++) {\n\t\t\tfreq[i] = mult(freq[i-1], kids[i-1]);\n\t\t}\n\t\t\n\t\tint[] totWays = new int[2 * n];\n\t\t\n\t\tfor(int kid = n-1; kid >= 0; kid--) {\n\t\t\tfor(int dist = 1; dist <= 2 * n - 2; dist++) {\n\t\t\t\tint tot = 0;\n\t\t\t\t\n\t\t\t\tif(dist < n) tot = add(tot, walkDown[kid][dist]);\n\t\t\t\t\n\t\t\t\tif(kid > 0) {\n\t\t\t\t\tint row = kid-1, col = dist-1;\n\t\t\t\t\tif(row >= n || col >= n) {\n\t\t\t\t\t\tint d = Math.max(row-n+1, col-n+1);\n\t\t\t\t\t\trow -= d;\n\t\t\t\t\t\tcol -= d;\n\t\t\t\t\t}\n\t\t\t\t\tint finRow = kid-dist, finCol = 0;\n\t\t\t\t\tif(finRow < 0) {\n\t\t\t\t\t\tint add = -finRow;\n\t\t\t\t\t\tfinRow += add;\n\t\t\t\t\t\tfinCol += add;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif(row >= finRow) {\n\t\t\t\t\t\tint x = diagSum[row][col];\n\t\t\t\t\t\tif(finRow > 0 && finCol > 0) {\n\t\t\t\t\t\t\tx -= diagSum[finRow-1][finCol-1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttot = add(tot, x);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n//\t\t\t\tSystem.out.println(kid + \" \" + dist + \" \" + tot);\n\t\t\t\tif(kid-dist >= 0) tot = add(tot, 1);\n\t\t\t\t\n\t\t\t\ttotWays[dist] = add(totWays[dist], mult(tot, freq[kid]));\n\t\t\t}\n//\t\t\tSystem.out.println();\n\t\t}\n\t\t\n\t\tint INV2 = (MOD+1)/2;\n\t\t\n\t\tfor(int i = 0; i < totWays.length; i++) {\n\t\t\ttotWays[i] = mult(totWays[i], INV2);\n\t\t}\n\t\t\n\t\tfor(int i = 1; i <= 2 * n - 2; i++) {\n\t\t\tif(i > 1) out.print(\" \");\n\t\t\tout.print(totWays[i]);\n\t\t}\n\t\tout.println();\n\t\t\n\t\tout.close();\n\t}\n\t\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\t\n\tint mult(long a, long b) {\n\t\treturn (int)(a * b % MOD);\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) {\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bf29a171a8870a0b881601fcc19ea95f", "src_uid": "3b86dfd0d077bc857ae3de70f026a409", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\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.flush();out.close();\n }\n static class TaskE {\n long mod=(long)(1E9)+7;\n long rpe(long a){long b=mod-2;\n long ans=1;\n while(b!=0){\n if(b%2!=0)ans=(ans*a)%mod;\n b/=2;a=a*a%mod;\n }return ans;\n }\n long i2=rpe(2);\n long f(long c){\n return c*(c-1+mod)%mod*i2%mod;\n }\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n=in.nextInt();\n long a[]=new long[n+10];for(int i=1;i<=n-1;i++)a[i]=in.nextLong();a[0]=1;\n long c=1;long ans[]=new long[2*n-1];\n for(int i=2;i<=n;i++){\n c=(c*a[i-1])%mod;\n for(int j=i-1;j>=1;j--){\n long m=1;\n for(int k=i-j;k<=2*(i-j);k++){\n long v=c*m%mod;if(k==2*(i-j))v=v*i2%mod;//f(a[j])*a[j-1]%mod;\n ans[k]=(ans[k]+v)%mod;\n if(k==i-j)m=m*(a[j+k-(i-j)]-1+mod)%mod;\n else m=m*a[j+k-(i-j)]%mod;\n }\n }\n }\n for(int i=1;i<2*n-1;i++)out.print(ans[i]+\" \");\n }\n /*pair ja[][];long w[];int from[],to[],c[];\n void make(int n,int m,InputReader in){\n ja=new pair[n+1][];w=new long[m];from=new int[m];to=new int[m];c=new int[n+1];\n for(int i=0;i>>16)]++;\n\t\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n\t\t\tfor(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];\n\t\t\tint[] d = f; f = to;to = d;\n\t\t}\n\t\treturn f;\n\t}\n }\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream));\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f94662122970dd012e51153f6e2b9ada", "src_uid": "3b86dfd0d077bc857ae3de70f026a409", "difficulty": 2500.0} {"lang": "Java 11", "source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF946F extends PrintWriter {\n\tCF946F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF946F o = new CF946F(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 1000000007;\n\tlong power(int a, int k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tlong p = power(a, k >> 1);\n\t\tp = p * p % MD;\n\t\tif ((k & 1) == 1)\n\t\t\tp = p * a % MD;\n\t\treturn p;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint x = sc.nextInt();\n\t\tbyte[] cc = sc.next().getBytes();\n\t\tif (x == 0) {\n\t\t\tprintln(n == 1 && cc[0] == '0' ? 1 : 0);\n\t\t\treturn;\n\t\t}\n\t\tint[] ff = new int[x + 1];\n\t\tff[0] = ff[1] = 1;\n\t\tfor (int i = 2; i <= x; i++)\n\t\t\tff[i] = (ff[i - 1] + ff[i - 2]) % (MD - 1);\n\t\tfor (int i = 0; i <= x; i++)\n\t\t\tff[i] = (int) power(2, ff[i]);\n\t\tint[][][] ds = new int[x + 1][n][n + 1];\n\t\tfor (int l = 0; l < n; l++) {\n\t\t\tds[0][l][l] = ds[1][l][l] = 1;\n\t\t\tds[0][l][l + 1] = cc[l] == '0' ? 1 : 0;\n\t\t\tds[1][l][l + 1] = cc[l] == '1' ? 1 : 0;\n\t\t}\n\t\tfor (int i = 2; i <= x; i++)\n\t\t\tfor (int l = 0; l < n; l++)\n\t\t\t\tfor (int r = l; r < n; r++) {\n\t\t\t\t\tlong z = 0;\n\t\t\t\t\tfor (int m = l; m <= r; m++)\n\t\t\t\t\t\tz = (z + (long) ds[i - 1][l][m] * ds[i - 2][m][r]) % MD;\n\t\t\t\t\tds[i][l][r] = (int) z;\n\t\t\t\t}\n\t\tint[][] dp = new int[x + 1][n];\n\t\tint[][] dq = new int[x + 1][n];\n\t\tif (n > 1) {\n\t\t\tdp[0][n - 1] = ds[0][n - 1][n];\n\t\t\tdp[1][n - 1] = ds[1][n - 1][n];\n\t\t\tfor (int i = 2; i <= x; i++)\n\t\t\t\tfor (int l = 1; l < n; l++) {\n\t\t\t\t\tlong z = (long) dp[i - 1][l] * ff[i - 2] % MD;\n\t\t\t\t\tfor (int m = l; m < n; m++)\n\t\t\t\t\t\tz = (z + (long) ds[i - 1][l][m] * dp[i - 2][m]) % MD;\n\t\t\t\t\tdp[i][l] = (int) z;\n\t\t\t\t}\n\t\t\tdq[0][1] = ds[0][0][1];\n\t\t\tdq[1][1] = ds[1][0][1];\n\t\t\tfor (int i = 2; i <= x; i++)\n\t\t\t\tfor (int r = 1; r < n; r++) {\n\t\t\t\t\tlong z = (long) ff[i - 1] * dq[i - 2][r] % MD;\n\t\t\t\t\tfor (int m = r; m > 0; m--)\n\t\t\t\t\t\tz = (z + (long) dq[i - 1][m] * ds[i - 2][m][r]) % MD;\n\t\t\t\t\tdq[i][r] = (int) z;\n\t\t\t\t}\n\t\t}\n\t\tint[] dr = new int[x + 1];\n\t\tdr[0] = ds[0][0][n];\n\t\tdr[1] = ds[1][0][n];\n\t\tfor (int i = 2; i <= x; i++) {\n\t\t\tlong z = ((long) dr[i - 1] * ff[i - 2] + (long) ff[i - 1] * dr[i - 2]) % MD;\n\t\t\tfor (int m = 1; m < n; m++)\n\t\t\t\tz = (z + (long) dq[i - 1][m] * dp[i - 2][m]) % MD;\n\t\t\tdr[i] = (int) z;\n\t\t}\n\t\tprintln(dr[x]);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6c18dc04514fa0190459e7b6f4ab8e3a", "src_uid": "52c6aa73ff4460799402c646c6263630", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\n\n/**\n * Created by dalt on 2018/3/25.\n */\npublic class CF946F {\n public static BlockReader input;\n public static PrintStream output;\n public static void main(String[] args) throws FileNotFoundException {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n input = new BlockReader(new FileInputStream(\"D:\\\\DataBase\\\\TESTCASE\\\\codeforces\\\\CF946F.in\"));\n output = System.out;\n }else{\n input = new BlockReader(System.in);\n output = new PrintStream(new BufferedOutputStream(System.out), false);\n }\n\n solve();\n\n output.flush();\n }\n\n public static void solve() {\n int n = input.nextInteger();\n int x = input.nextInteger();\n String s = input.nextBlock();\n int slen = s.length();\n final long MOD = 1000000007;\n final int ALIGN_LEFT = 0;\n final int ALIGN_RIGHT = 1;\n final int ALIGN_CENTER = 2;\n final int ALIGN_LEFT_RIGHT = 3;\n\n long[][][][] dp = new long[Math.max(x + 1, 2)][slen + 1][slen + 1][4];\n long[] lengthes = new long[101];\n lengthes[0] = lengthes[1] = 1;\n\n for (int j = 0, bound = 2; j < bound; j++) {\n for (int i = 0; i <= slen; i++) {\n for (int k = 0; k < 4; k++) {\n dp[j][i][i][ALIGN_LEFT] = 2;\n dp[j][i][i][ALIGN_RIGHT] = 2;\n dp[j][i][i][ALIGN_CENTER] = 2;\n dp[j][i][i][ALIGN_LEFT_RIGHT] = 1;\n }\n }\n }\n\n for (int i = 0; i < slen; i++) {\n int c = s.charAt(i) - '0';\n dp[c][i][i + 1][ALIGN_LEFT] = 1;\n dp[c][i][i + 1][ALIGN_RIGHT] = 1;\n dp[c][i][i + 1][ALIGN_CENTER] = 1;\n dp[c][i][i + 1][ALIGN_LEFT_RIGHT] = 1;\n }\n\n for (int i = 2; i <= x; i++) {\n int last = i - 1;\n int last2 = i - 2;\n lengthes[i] = (lengthes[last] + lengthes[last2]) % (MOD - 1);\n\n long pLast = pow(2, lengthes[last], MOD);\n long pLast2 = pow(2, lengthes[last2], MOD);\n for (int j = 0; j <= slen; j++) {\n dp[i][j][j][ALIGN_LEFT] = pLast * pLast2 % MOD;\n dp[i][j][j][ALIGN_RIGHT] = dp[i][j][j][ALIGN_LEFT];\n dp[i][j][j][ALIGN_CENTER] = dp[i][j][j][ALIGN_LEFT];\n dp[i][j][j][ALIGN_LEFT_RIGHT] = 1;\n for (int k = j + 1; k <= slen; k++) {\n dp[i][j][k][ALIGN_LEFT] = (dp[last][j][k][ALIGN_LEFT] * pLast2 + dp[last2][j][k][ALIGN_LEFT]) % MOD;\n dp[i][j][k][ALIGN_RIGHT] = (dp[last][j][k][ALIGN_RIGHT] + pLast * dp[last2][j][k][ALIGN_RIGHT]) % MOD;\n dp[i][j][k][ALIGN_CENTER] = (dp[last][j][k][ALIGN_CENTER] * pLast2 + pLast * dp[last2][j][k][ALIGN_CENTER]) % MOD;\n dp[i][j][k][ALIGN_LEFT_RIGHT] = (dp[last][j][k][ALIGN_LEFT_RIGHT] + dp[last2][j][k][ALIGN_LEFT_RIGHT]) % MOD;\n for (int sep = j + 1; sep < k; sep++) {\n dp[i][j][k][ALIGN_LEFT] = (dp[i][j][k][ALIGN_LEFT] + dp[last][j][sep][ALIGN_LEFT_RIGHT] * dp[last2][sep][k][ALIGN_LEFT]) % MOD;\n dp[i][j][k][ALIGN_RIGHT] = (dp[i][j][k][ALIGN_RIGHT] + dp[last][j][sep][ALIGN_RIGHT] * dp[last2][sep][k][ALIGN_LEFT_RIGHT]) % MOD;\n dp[i][j][k][ALIGN_LEFT_RIGHT] = (dp[i][j][k][ALIGN_LEFT_RIGHT] + dp[last][j][sep][ALIGN_LEFT_RIGHT] * dp[last2][sep][k][ALIGN_LEFT_RIGHT]) % MOD;\n dp[i][j][k][ALIGN_CENTER] = (dp[i][j][k][ALIGN_CENTER] + dp[last][j][sep][ALIGN_RIGHT] * dp[last2][sep][k][ALIGN_LEFT]) % MOD;\n }\n }\n }\n }\n\n System.out.println(dp[x][0][slen][ALIGN_CENTER]);\n }\n\n public static long pow(long x, long n, long MOD) {\n int bit = 31;\n for (; bit >= 0 && (n & (1 << bit)) == 0; bit--) ;\n long product = 1;\n for (; bit >= 0; bit--) {\n product = (product * product) % MOD;\n if ((n & (1 << bit)) != 0) {\n product = (product * x) % MOD;\n }\n }\n return (int) product;\n }\n\n public static class BlockReader {\n static final int EOF = -1;\n InputStream is;\n byte[] dBuf;\n int dPos, dSize, next;\n StringBuilder builder = new StringBuilder();\n\n public BlockReader(InputStream is) {\n this(is, 4096);\n }\n\n public BlockReader(InputStream is, int bufSize) {\n this.is = is;\n dBuf = new byte[bufSize];\n next = nextByte();\n }\n\n public int nextByte() {\n while (dPos >= dSize) {\n if (dSize == -1) {\n return EOF;\n }\n dPos = 0;\n try {\n dSize = is.read(dBuf);\n } catch (Exception e) {\n }\n }\n return dBuf[dPos++];\n }\n\n public String nextBlock() {\n builder.setLength(0);\n skipBlank();\n while (next != EOF && !Character.isWhitespace(next)) {\n builder.append((char) next);\n next = nextByte();\n }\n return builder.toString();\n }\n\n public void skipBlank() {\n while (Character.isWhitespace(next)) {\n next = nextByte();\n }\n }\n\n public int nextInteger() {\n skipBlank();\n int ret = 0;\n boolean rev = false;\n if (next == '+' || next == '-') {\n rev = next == '-';\n next = nextByte();\n }\n while (next >= '0' && next <= '9') {\n ret = (ret << 3) + (ret << 1) + next - '0';\n next = nextByte();\n }\n return rev ? -ret : ret;\n }\n\n public int nextBlock(char[] data, int offset) {\n skipBlank();\n int index = offset;\n int bound = data.length;\n while (next != EOF && index < bound && !Character.isWhitespace(next)) {\n data[index++] = (char) next;\n next = nextByte();\n }\n return index - offset;\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != EOF;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7aa577cca965ef68fb585d8ebd57f7fe", "src_uid": "52c6aa73ff4460799402c646c6263630", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class F {\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];\n // for(int i=0; i= 1) fibonacci[1] = 1;\n for(int i=2; i<=x; i++)\n fibonacci[i] = (int)((fibonacci[i-1] + fibonacci[i-2]) % (mod - 1));\n for(int i=0; i 0){\n if(n % 2 == 1)res = (res*m)%mod;\n m = (m*m)%mod;\n n = n/2;\n }\n return res;\n }\n\n\n private void solve() throws Exception {\n int n = nextInt();\n int x = nextInt();\n chs = nextToken().toCharArray();\n memo = new long[n][n][x+1];\n for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) Arrays.fill(memo[i][j], -1);\n fibpow = new long[x+1];\n fibpow[1] = 1L;\n for(int i = 2; i <= x; i++) fibpow[i] = (fibpow[i-1]+ fibpow[i-2])%modpow;\n for(int i = 0; i <= x; i++) fibpow[i] = pow(2, fibpow[i]);\n out.println(doit(0,n-1,x));\n }\n\n long doit(int i, int j, int x) {\n if (x < 2 && i == j && chs[i]-'0' == x) return 1L;\n else if (x < 2 && i == j && chs[i]-'0' != x) return 0L;\n else if(x < 2 && i < j) return 0L;\n else if(memo[i][j][x] < 0){\n long res = 0L;\n res = (res + ((i==0?fibpow[x]:(1L)) * doit(i,j, x-2))%mod)%mod;\n for(int t = i; t < j; t++) res = (res + (doit(i,t,x-1) * doit(t+1,j, x-2))%mod)%mod;\n res = (res + (doit(i,j,x-1) * (j==chs.length-1? fibpow[x-1]:(1L)))%mod)%mod;\n memo[i][j][x] = res;\n }\n return memo[i][j][x];\n }\n\n\n public static void main(String[] args) {\n (new F946()).run();\n }\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tokenizer;\n\n public void run() {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n out = new PrintWriter(System.out);\n solve();\n in.close();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private float nextFloat() throws IOException {\n return Float.parseFloat(nextToken());\n }\n\n private String nextLine() throws IOException {\n return new String(in.readLine());\n }\n\n private String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e8ed6b1dfa7fa01327fa0b9ae05bb218", "src_uid": "52c6aa73ff4460799402c646c6263630", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.awt.*;\nimport java.awt.geom.*;\nimport java.util.stream.*;\n \n/**\n * @author Pradyumn\n */\n \npublic class Main implements Runnable{\n\tpublic int TC = 0;\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Main(), \":)\", 1L << 26).start();\n\t}\n\tstatic final int MODULO = (int)(1e9 + 7);\n\t@SuppressWarnings(\"Unchecked\")\n\tpublic void solve() throws IOException {\n\t int n = ni();\n\t HashSet x = new HashSet<>();\n\t HashSet y = new HashSet<>();\n\t HashMap mapX = new HashMap<>();\n\t HashMap mapY = new HashMap<>();\n\t int[][] pp = new int[2][n];\n\t for (int i = 0; i < n; ++i) {\n\t \tfor(int j = 0;j < 2; ++j) {\n\t \t\tpp[j][i] = ni();\n\t \t\tif(j == 0) x.add(pp[j][i]);\n\t \t\telse y.add(pp[j][i]);\n\t \t}\n\t }\n\n\t int mapIdx = 0;\n\t for(int xx : x) \n\t \tif(!mapX.containsKey(xx)) \n\t \t\tmapX.put(xx, mapIdx++);\n\n\t for(int yy : y) \n\t \tif(!mapY.containsKey(yy)) \n\t \t\tmapY.put(yy, mapIdx++);\n\n\t UnionFind uf = new UnionFind(mapIdx);\n\t for(int i = 0;i < n; ++i) {\n\t \tuf.unionSet(mapX.get(pp[0][i]), mapY.get(pp[1][i]));\n\t }\n\t uf.close();\n\t \n\t long res = 1;\n\t factorial();\n\t for (int i = 0; i < mapIdx; i++)\n if (uf.p[i] == i) {\n int numPoints = uf.numPoints[i], lines = uf.sizeOfSet(i);\n long ways = 0;\n for (int j = 0; j <= Math.min(numPoints, lines); j++) {\n ways += ncr(lines, j);\n if (ways >= MODULO) ways -= MODULO;\n }\n res *= ways;\n res %= MODULO;\n\n }\n\t out.println(res);\n\t}\n\t// O(1) nCr\n static int MAX = 5 * 100000 + 1;\n static int fact[] = new int[MAX];\n\n static int ncr(int n, int r) {\n return (int) ((long) fact[n] * ((inv(fact[r], MODULO) * inv(fact[n - r], MODULO)) % MODULO) % MODULO) % MODULO;\n }\n\n static long inv(long x, long mod) {\n long r, y;\n for (r = 1, y = mod - 2; y != 0; x = x * x % mod, y >>= 1)\n if ((y & 1) == 1)\n r = r * x % mod;\n return r;\n }\n\n static void factorial() {\n fact[0] = fact[1] = 1;\n for (int i = 2; i < MAX; i++)\n fact[i] = (int) ((long) i * fact[i - 1] % MODULO);\n }\n\n public static long modular_exponentiation(long a, long b, long c) // returns ( a ^ b ) % c\n {\n long ans = 1L;\n while (b != 0) {\n if ((b & (1)) == 1)\n ans = (ans * a) % c;\n\n a = (a * a) % c;\n b >>= 1L;\n }\n\n return ans;\n }\n\tstatic class UnionFind {\n private int[] p, rank, setSize, numPoints;\n private int numSets;\n\n public UnionFind(int size) {\n p = new int[size];\n rank = new int[size];\n setSize = new int[size];\n numPoints = new int[size];\n numSets = size;\n for (int i = 0; i < size; ++i) {\n p[i] = i;\n numPoints[i] = 0;\n setSize[i] = 1;\n }\n }\n\n int findSet(int i) {\n return (p[i] == i) ? i : (p[i] = findSet(p[i]));\n }\n\n boolean isSameSet(int i, int j) {\n return findSet(i) == findSet(j);\n }\n\n void unionSet(int i, int j) {\n if (!isSameSet(i, j)) {\n --numSets;\n int x = findSet(i), y = findSet(j);\n if (rank[x] > rank[y]) {\n p[y] = x;\n setSize[x] = setSize[x] + setSize[y];\n numPoints[x] = 1 + numPoints[x] + numPoints[y];\n } else {\n p[x] = y;\n setSize[y] = setSize[y] + setSize[x];\n numPoints[y] = numPoints[y] + numPoints[x] + 1;\n if (rank[x] == rank[y]) ++rank[y];\n }\n } else {\n numPoints[findSet(i)]++;\n }\n }\n\n int numDisjointSets() {\n return numSets;\n }\n\n void close() {\n for (int i = 0; i < p.length; i++)\n findSet(i);\n }\n\n int sizeOfSet(int i) {\n return setSize[findSet(i)];\n }\n }\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\tpublic void run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in),32768);\n\t\t\tst = null;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tif(TC == 1) {\n\t\t\t\tfor(int T = ni();T > 0; --T) {\n\t\t\t\t\tsolve();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsolve();\n\t\t\t}\n\t\t\tbr.close();\n\t\t\tout.close();\n\t\t} catch(IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\tpublic char[] nsc( ) throws IOException {\n\t\treturn ns().toCharArray();\n\t}\n\tpublic char[][] nm(int n, int m) throws IOException {\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n; ++i) {\n\t\t\tmap[i] = nsc();\n\t\t}\n\t\treturn map;\n\t}\n\tpublic String ns() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\tpublic String nextLine() throws IOException {\n\t\treturn br.readLine();\n\t}\n\tpublic int ni() throws IOException {\n\t\treturn Integer.parseInt(ns());\n\t}\n \n\tpublic int[] na(int n) throws IOException {\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n; ++i) a[i] = ni();\n\t\treturn a;\n\t}\n \n\tpublic long nl() throws IOException {\n\t\treturn Long.parseLong(ns());\n\t}\n \n\tpublic long[] nal(int n) throws IOException {\n\t\tlong[] a = new long[n];\n\t\tfor(int i = 0;i < n; ++i) a[i] = nl();\n\t\treturn a;\n\t}\n \n\tpublic double nd() throws IOException {\n\t\treturn Double.parseDouble(ns());\n\t}\n\tprivate static boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate static void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6065f2e8109844a02ee4652fa1f3ef4f", "src_uid": "8781003d9eea51a509145bc6db8b609c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\n public static void main(String[] args) throws IOException {\n\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int n = sc.nextInt();\n HashSet x = new HashSet<>(), y = new HashSet<>();\n HashMap mapX = new HashMap<>(), mapY = new HashMap<>();\n int[][] arr = new int[2][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < 2; j++) {\n arr[j][i] = sc.nextInt();\n if (j == 0) x.add(arr[j][i]);\n else y.add(arr[j][i]);\n }\n }\n\n int mapIdxX = 0;\n for (int xx : x) if (!mapX.containsKey(xx)) mapX.put(xx, mapIdxX++);\n for (int yy : y) if (!mapY.containsKey(yy)) mapY.put(yy, mapIdxX++);\n\n UnionFind uf = new UnionFind(mapIdxX);\n for (int i = 0; i < n; i++)\n uf.unionSet(mapX.get(arr[0][i]), mapY.get(arr[1][i]));\n\n uf.close();\n long res = 1;\n int mod = (int) 1e9 + 7;\n factorial();\n for (int i = 0; i < mapIdxX; i++)\n if (uf.p[i] == i) {\n int numPoints = uf.numPoints[i], lines = uf.sizeOfSet(i);\n long ways = 0;\n for (int j = 0; j <= Math.min(numPoints, lines); j++) {\n ways += ncr(lines, j);\n if (ways >= mod) ways -= mod;\n }\n res *= ways;\n res %= mod;\n\n }\n\n\n out.println(res);\n out.close();\n }\n\n // O(1) nCr\n static int MAX = 5 * 100000 + 1;\n static int fact[] = new int[MAX];\n static int MOD = (int) 1e9 + 7;\n\n static int ncr(int n, int r) {\n return (int) ((long) fact[n] * ((inv(fact[r], MOD) * inv(fact[n - r], MOD)) % MOD) % MOD) % MOD;\n }\n\n static long inv(long x, long mod) {\n long r, y;\n for (r = 1, y = mod - 2; y != 0; x = x * x % mod, y >>= 1)\n if ((y & 1) == 1)\n r = r * x % mod;\n return r;\n }\n\n static void factorial() {\n fact[0] = fact[1] = 1;\n for (int i = 2; i < MAX; i++)\n fact[i] = (int) ((long) i * fact[i - 1] % MOD);\n }\n\n public static long modular_exponentiation(long a, long b, long c) // returns ( a ^ b ) % c\n {\n long ans = 1L;\n while (b != 0) {\n if ((b & (1)) == 1)\n ans = (ans * a) % c;\n\n a = (a * a) % c;\n b >>= 1L;\n }\n\n return ans;\n }\n\n static class UnionFind {\n private int[] p, rank, setSize, numPoints;\n private int numSets;\n\n public UnionFind(int size) {\n p = new int[size];\n rank = new int[size];\n setSize = new int[size];\n numPoints = new int[size];\n numSets = size;\n for (int i = 0; i < size; ++i) {\n p[i] = i;\n numPoints[i] = 0;\n setSize[i] = 1;\n }\n }\n\n int findSet(int i) {\n return (p[i] == i) ? i : (p[i] = findSet(p[i]));\n }\n\n boolean isSameSet(int i, int j) {\n return findSet(i) == findSet(j);\n }\n\n void unionSet(int i, int j) {\n if (!isSameSet(i, j)) {\n --numSets;\n int x = findSet(i), y = findSet(j);\n if (rank[x] > rank[y]) {\n p[y] = x;\n setSize[x] = setSize[x] + setSize[y];\n numPoints[x] = 1 + numPoints[x] + numPoints[y];\n } else {\n p[x] = y;\n setSize[y] = setSize[y] + setSize[x];\n numPoints[y] = numPoints[y] + numPoints[x] + 1;\n if (rank[x] == rank[y]) ++rank[y];\n }\n } else {\n numPoints[findSet(i)]++;\n }\n }\n\n int numDisjointSets() {\n return numSets;\n }\n\n void close() {\n for (int i = 0; i < p.length; i++)\n findSet(i);\n }\n\n int sizeOfSet(int i) {\n return setSize[findSet(i)];\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 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 long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ab9b20a230daef1be7f18e8c89e24316", "src_uid": "8781003d9eea51a509145bc6db8b609c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.util.HashMap;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.io.File;\nimport java.util.List;\nimport java.util.TreeMap;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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 E solver = new E();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class E extends SimpleSavingChelperSolution {\n private int[] x;\n private int[] y;\n private int n;\n private Map xMap;\n private Map yMap;\n private List> edges;\n private boolean[] visited;\n private long MOD;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n wrapSolve(testNumber, in, out);\n }\n\n\n public void solve(int testNumber) {\n n = in.nextInt();\n\n x = new int[n];\n y = new int[n];\n\n xMap = new TreeMap<>();\n yMap = new TreeMap<>();\n\n edges = new ArrayList<>();\n\n for (int i = 0; i < n; i++) {\n edges.add(new HashSet<>());\n }\n\n Map prevX = new HashMap<>();\n Map prevY = new HashMap<>();\n\n for (int i = 0; i < n; i++) {\n x[i] = in.nextInt();\n y[i] = in.nextInt();\n\n xMap.put(x[i], xMap.getOrDefault(x[i], 0) + 1);\n yMap.put(y[i], yMap.getOrDefault(y[i], 0) + 1);\n\n Integer pX = prevX.get(x[i]);\n Integer pY = prevY.get(y[i]);\n\n if (pX != null) {\n edges.get(pX).add(i);\n edges.get(i).add(pX);\n }\n if (pY != null) {\n edges.get(pY).add(i);\n edges.get(i).add(pY);\n }\n\n prevX.put(x[i], i);\n prevY.put(y[i], i);\n }\n\n visited = new boolean[n];\n\n long ans = 1;\n\n MOD = 1000000007;\n\n for (int i = 0; i < n; i++) {\n if (visited[i]) {\n continue;\n }\n\n List res = new ArrayList<>();\n dfs(i, res);\n\n Set usedX = new HashSet<>();\n Set usedY = new HashSet<>();\n\n for (Integer j : res) {\n usedX.add(x[j]);\n usedY.add(y[j]);\n }\n\n int K = usedX.size() + usedY.size();\n if (res.size() >= K) {\n ans = ans * twopow(K) % MOD;\n } else {\n ans = ans * ((twopow(K) - 1 + MOD) % MOD) % MOD;\n }\n }\n\n\n out.println(ans);\n }\n\n long twopow(int n) {\n if (n == 0) {\n return 1;\n }\n if (n % 2 == 0) {\n long t = twopow(n / 2);\n return t * t % MOD;\n }\n return twopow(n - 1) * 2 % MOD;\n }\n\n void dfs(int v, List res) {\n if (visited[v]) {\n return;\n }\n visited[v] = true;\n res.add(v);\n\n for (int j : edges.get(v)) {\n dfs(j, res);\n }\n }\n\n }\n\n static class InputReader {\n private BufferedReader br;\n private StringTokenizer in;\n\n public InputReader(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public InputReader(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n private boolean hasMoreTokens() {\n while (in == null || !in.hasMoreTokens()) {\n String s = nextLine();\n if (s == null) {\n return false;\n }\n in = new StringTokenizer(s);\n }\n return true;\n }\n\n public String nextString() {\n return hasMoreTokens() ? in.nextToken() : null;\n }\n\n public String nextLine() {\n try {\n in = null;\n return br.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n return null;\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n }\n\n static class OutputWriter extends PrintWriter {\n\n public void close() {\n super.close();\n }\n\n public OutputWriter(String fileName) throws FileNotFoundException {\n super(fileName);\n }\n\n public OutputWriter(OutputStream outputStream) {\n super(outputStream);\n }\n\n public OutputWriter(Writer writer) {\n super(writer);\n }\n\n }\n\n static abstract class SimpleSavingChelperSolution extends SavingChelperSolution {\n\n public String processOutputPreCheck(int testNumber, String output) {\n return output;\n }\n\n\n public String processOutputPostCheck(int testNumber, String output) {\n return output;\n }\n\n }\n\n static abstract class SavingChelperSolution {\n protected int testNumber;\n public InputReader in;\n public OutputWriter out;\n private OutputWriter toFile;\n private boolean local = new File(\"chelper.properties\").exists();\n public OutputWriter debug;\n\n {\n if (local) {\n debug = new OutputWriter(System.out);\n } else {\n debug = new OutputWriter(new OutputStream() {\n\n public void write(int b) {\n }\n });\n }\n }\n\n public SavingChelperSolution() {\n try {\n toFile = new OutputWriter(\"last_test_output.txt\");\n } catch (FileNotFoundException e) {\n throw new RuntimeException(e);\n }\n }\n\n public abstract void solve(int testNumber);\n\n public abstract String processOutputPreCheck(int testNumber, String output);\n\n public abstract String processOutputPostCheck(int testNumber, String output);\n\n public void wrapSolve(int testNumber, InputReader in, OutputWriter out) {\n this.testNumber = testNumber;\n\n ByteArrayOutputStream substituteOutContents = new ByteArrayOutputStream();\n OutputWriter substituteOut = new OutputWriter(substituteOutContents);\n\n this.in = in;\n this.out = substituteOut;\n\n solve(testNumber);\n substituteOut.flush();\n\n String result = substituteOutContents.toString();\n\n result = processOutputPreCheck(testNumber, result);\n out.print(result);\n out.flush();\n\n if (local) {\n debug.flush();\n\n result = processOutputPostCheck(testNumber, result);\n toFile.print(result);\n toFile.flush();\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "91a0cc3ef0893dfb823a62bbb8305205", "src_uid": "8781003d9eea51a509145bc6db8b609c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\nimport static java.lang.Math.random;\n\n/**\n * @author Don Li\n */\npublic class PointsLinesTitles {\n \n int N = (int) 1e5 + 10;\n int MOD = (int) 1e9 + 7;\n \n int n;\n int[][] p;\n List[] G;\n \n boolean[] used = new boolean[N];\n Set uniqueX = new HashSet<>(), uniqueY = new HashSet<>();\n long sumDegree = 0, numNode = 0;\n \n void solve() {\n n = in.nextInt();\n \n p = new int[n][2];\n for (int i = 0; i < n; i++) {\n p[i][0] = in.nextInt();\n p[i][1] = in.nextInt();\n }\n \n int[] x = new int[n], y = new int[n];\n for (int i = 0; i < n; i++) {\n x[i] = p[i][0];\n y[i] = p[i][1];\n }\n sort(x);\n sort(y);\n for (int i = 0; i < n; i++) {\n p[i][0] = lowerBound(x, p[i][0]);\n p[i][1] = lowerBound(y, p[i][1]);\n }\n \n G = new List[n];\n for (int i = 0; i < n; i++) G[i] = new ArrayList<>();\n \n List[] ver = new List[n], hor = new List[n];\n for (int i = 0; i < n; i++) {\n ver[i] = new ArrayList<>();\n hor[i] = new ArrayList<>();\n }\n for (int i = 0; i < n; i++) {\n ver[p[i][0]].add(i);\n hor[p[i][1]].add(i);\n }\n for (int i = 0; i < n; i++) {\n ver[i].sort(Comparator.comparingInt(a -> p[a][1]));\n for (int j = 1; j < ver[i].size(); j++) {\n int u = ver[i].get(j - 1), v = ver[i].get(j);\n addNeighbors(u, v);\n }\n hor[i].sort(Comparator.comparingInt(a -> p[a][0]));\n for (int j = 1; j < hor[i].size(); j++) {\n int u = hor[i].get(j - 1), v = hor[i].get(j);\n addNeighbors(u, v);\n }\n }\n \n long ans = 1;\n for (int i = 0; i < n; i++) {\n if (!used[i]) {\n uniqueX.clear();\n uniqueY.clear();\n sumDegree = 0; numNode = 0;\n dfs(i);\n long ways = mpow(2, uniqueX.size() + uniqueY.size());\n if (sumDegree / 2 == numNode - 1) ways = (ways - 1 + MOD) % MOD;\n ans = ans * ways % MOD;\n }\n }\n out.println(ans);\n }\n \n void dfs(int u) {\n used[u] = true;\n uniqueX.add(p[u][0]);\n uniqueY.add(p[u][1]);\n numNode++;\n sumDegree += G[u].size();\n for (int v : G[u]) {\n if (!used[v]) dfs(v);\n }\n }\n \n long mpow(int a, int n) {\n long res = 1;\n while (n > 0) {\n if ((n & 1) > 0) res = res * a % MOD;\n a = a * a % MOD;\n n >>= 1;\n }\n return res;\n }\n \n void addNeighbors(int u, int v) {\n G[u].add(v);\n G[v].add(u);\n }\n \n void sort(int[] a) {\n int n = a.length;\n for (int i = 0; i < n; i++) {\n int j = (int) (i + random() * (n - i));\n int tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n Arrays.sort(a);\n }\n \n int lowerBound(int[] a, int k) {\n int lb = -1, ub = a.length;\n while (ub - lb > 1) {\n int m = (lb + ub) >> 1;\n if (a[m] >= k) ub = m;\n else lb = m;\n }\n return ub;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new PointsLinesTitles().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "63274150cd1251ef38d0890b8ed0d782", "src_uid": "8781003d9eea51a509145bc6db8b609c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E\n{\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n long[] fact = new long[4010];\n long[] factInv = new long[4010];\n int MOD = 998244853;\n\n public void go() throws IOException\n {\n StringTokenizer tok = new StringTokenizer(in.readLine());\n int n = Integer.parseInt(tok.nextToken());\n int m = Integer.parseInt(tok.nextToken());\n\n fact[0] = 1;\n factInv[0] = 1;\n for (int i = 1; i < fact.length; i++)\n {\n fact[i] = i * fact[i-1] % MOD;\n factInv[i] = inverse(i) * factInv[i-1] % MOD;\n }\n\n long[][] zeros = new long[n+1][m+1];\n long[][] dp = new long[n+1][m+1];\n\n for (int i = 0; i <= n; i++)\n {\n for (int j = 0; j <= m; j++)\n {\n if (i == 0)\n {\n zeros[i][j] = 1;\n }\n else if (i > j)\n {\n zeros[i][j] = 0;\n }\n else\n {\n zeros[i][j] = (zeros[i-1][j] + zeros[i][j-1]) % MOD;\n }\n // zeros[i][j] += 1;\n }\n }\n // for (long[] arr : zeros)\n // {\n // out.println(Arrays.toString(arr));\n // }\n\n for (int i = 0; i <= n; i++)\n {\n for (int j = 0; j <= m; j++)\n {\n if (j == 0)\n {\n dp[i][j] = i;\n }\n else if (i == 0)\n {\n dp[i][j] = 0;\n }\n else\n {\n long p1 = (dp[i-1][j] + nck(i+j-1, j)) % MOD;\n long p2 = (dp[i][j-1] - nck(i+j-1, i) + zeros[i][j-1] + MOD) % MOD;\n dp[i][j] = (p1 + p2) % MOD;\n }\n }\n }\n\n out.println(dp[n][m]);\n\n out.flush();\n in.close();\n }\n\n public long modPow(long n, int p)\n {\n if (p == 0)\n {\n return 1;\n }\n long pow = modPow(n*n % MOD, p/2);\n if (p % 2 == 1)\n {\n pow *= n;\n pow %= MOD;\n }\n return pow;\n }\n\n public long inverse(long n)\n {\n return modPow(n, MOD-2);\n }\n\n public long nck(int n, int k)\n {\n if (k < 0 || k > n)\n {\n return 0;\n }\n return fact[n] * (factInv[k] * factInv[n-k] % MOD) % MOD;\n }\n\n public static void main(String[] args) throws IOException\n {\n new E().go();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "adf05b5766bfd3affba7030aa0812f10", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class codeforces2 { // in case I want to work on more than 1 problem at a time\n\tpublic static PrintWriter out;\n\tpublic static class MyScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic MyScanner() {\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 {\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// The next two void functions are shuffle functions on an array.\n\t// This way, quick sort encounters the worst case scenario with low probability.\n\t// A reason for doing this is if we don't a primitive data array to an object array.\n\t// For safety reasons, it would be preferable to use object arrays unless doing so expends a lot of time.\n\tpublic static void shuffleLongArray(long[] arr) {\n\t\tint n = arr.length;\n\t\tRandom rnd = new Random();\n for (int i=0; i < n; i++) {\n \tlong tmp = arr[i];\n \tint randomPos = i + rnd.nextInt(n-i);\n \tarr[i] = arr[randomPos];\n \tarr[randomPos] = tmp;\n }\n\t}\n\tpublic static void shuffleIntArray(int[] arr) {\n\t\tint n = arr.length;\n\t\tRandom rnd = new Random();\n for (int i=0; i < n; i++) {\n \tint tmp = arr[i];\n \tint randomPos = i + rnd.nextInt(n-i);\n \tarr[i] = arr[randomPos];\n \tarr[randomPos] = tmp;\n }\n\t}\n\tpublic static void main (String[] args) throws IOException {\n \tMyScanner sc = new MyScanner();\n \tout = new PrintWriter(new BufferedOutputStream(System.out));\n \t// Write solution here.\n \tint[][] dp = new int[2001][2001]; // f(n,m)\n \tint[][] choose = new int[2001][2001];\n \tfor (int i=0; i <= 2000; i++) {\n \t\tchoose[i][0] = 1;\n \t\tchoose[0][i] = 1;\n \t}\n \tint mega = 998244853;\n \tlong giga = 998244853L;\n \tfor (int i=1; i <= 2000; i++) {\n \t\tfor (int j=1; j <= 2000; j++) {\n \t\t\tchoose[i][j] = (choose[i-1][j] + choose[i][j-1]) % mega;\n \t\t}\n \t}\n \tlong[] catalan = new long[2001];\n \tcatalan[0] = 1L;\n \tcatalan[1] = 1L;\n \tfor (int i=2; i <= 2000; i++) {\n \t\tfor (int j=0; j < i; j++) {\n \t\t\tcatalan[i] = (catalan[i] + catalan[j]*catalan[i-j-1]) % giga;\n \t\t}\n \t}\n \tint[][] change = new int[2001][2001];\n \tfor (int j=1; j < 2000; j++) {\n \t\tfor (int i=j+1; i <= 2000; i++) {\n \t\t\tif (j==1) {\n \t\t\t\tchange[i][j] = i-1;\n \t\t\t}\n \t\t\telse if (i > j && j > 0) {\n \t\t\t\tif (i == j+1) {\n \t\t\t\t\tint z = (int) catalan[j];\n \t\t\t\t\tchange[i][j] = z;\n \t\t\t\t}\n \t\t\t\telse {\n \t\t\t\t\tchange[i][j] = (change[i][j-1] + change[i-1][j]) % mega;\n \t\t\t\t}\n \t\t\t}\n \t\t\t// if (j < 10 && i < 10) out.print(change[i][j] + \" \");\n \t\t}\n \t\t// if (j < 10) out.println();\n \t}\n \t\n \tfor (int i=0; i <= 2000; i++) {\n \t\tdp[i][0] = i;\n \t}\n \t// initialized row and column 0 successfully\n \tfor (int i=1; i <= 2000; i++) { // n\n \t\tfor (int j=1; j <= 2000; j++) { // m\n \t\t\tdp[i][j] = dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % mega;\n \t\t\tif (i > j) {\n \t\t\t\tdp[i][j] = (dp[i][j] + change[i][j]) % mega;\n \t\t\t}\n \t\t}\n \t}\n \tint n = sc.nextInt();\n \tint m = sc.nextInt();\n \tout.println(dp[n][m]);\n \tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fdd6a1b1d9bf4f44bfee47eb2e0f9b1a", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "//package round581;\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 2\";\n\t\n\tvoid solve()\n\t{\n\t\tint mod = 998244853;\n\t\tint[][] fif = enumFIF(9000, mod);\n\t\t\n\t\tint n = ni(), m = ni();\n\t\t// (m,n)\n\t\t// n-m i\n\t\t// 2i-(n-m)=x-y\n\t\t// m+n = x+y\n\t\tlong[] all = new long[n+2];\n\t\tfor(int i = n+1;i >= 0 && i > n-m;i--){\n\t\t\tint x = (2*i-(n-m)+(m+n))/2;\n\t\t\tint y = ((m+n) - (2*i-(n-m)))/2;\n\t\t\tall[i] = C(m+n, n, mod, fif) - C(x+y, y, mod, fif);\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i = n;i >= 0;i--){\n\t\t\tans += (all[i+1] - all[i]) * i;\n\t\t\tans %= mod;\n\t\t}\n\t\tif(ans < 0)ans += mod;\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\n\t\tif (n < 0 || r < 0 || r > n)\n\t\t\treturn 0;\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\n\t}\n\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af84faa675a1ebdad1fad5aaad9c6449", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0} {"lang": "Java 8", "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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b96063761bfe8b9782e75a42a080d04", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "// import org.junit.Test;\nimport java.util.Scanner;\n\n// import static org.junit.Assert.assertEquals;\n\npublic class CF_1223G {\n static Scanner scanner = new Scanner(System.in);\n public static void main(String args[])\n {\n // test();\n long caseNum = 1;\n while (caseNum-- > 0) {\n task();\n }\n }\n\n private static int maxN = 500000;\n private static int[] a = new int[maxN + 10];\n private static int[] sum = new int[maxN + 10];\n private static int[] input = new int[maxN + 10];\n\n public static void task() {\n int n = scanner.nextInt();\n // System.out.println(n);\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n // System.out.println(\"input end\");\n solve(n, input);\n }\n\n public static void clear(int n) {\n for (int i = 1; i <= maxN + 1; i++) {\n a[i] = 0;\n sum[i] = 0;\n }\n }\n\n private static int maxA;\n\n public static long solve(int n, int[] input) {\n long maxArea = 0;\n maxA = 0;\n clear(n);\n for (int i = 0; i < n; i++) {\n a[input[i]]++;\n if (input[i] > maxA) {\n maxA = input[i];\n }\n }\n for (int i = 2; i <= maxN + 1; i++) {\n sum[i] = a[i] + sum[i - 1];\n }\n\n\n /*\n {\n int total = 0;\n int y = 60522;\n for (int step = y; step <= maxA; step += y) {\n total += q(step, min(step + y - 1, maxA) + 1) * (step / y);\n System.out.println(total);;\n }\n System.out.println(\"total\");\n System.out.println(total);\n }\n */\n\n for (int y = 2; y <= maxA; y++) {\n long total = 0;\n for (int step = y; step <= maxA; step += y) {\n total += q(step, min(step + y - 1, maxA) + 1) * (long) (step / y);\n }\n int x = 1;\n int left = 2;\n int right = maxA;\n while (left <= right) {\n int mid = (left + right) / 2;\n if (mid == 500019) {\n y = y;\n left = left;\n mid = mid;\n right = right;\n\n }\n if (check(y, mid, total)) {\n if (mid > x) {\n x = mid;\n }\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n if (x > 1) {\n if ((long) x * (long) y > maxArea) {\n maxArea = (long) x * (long) y;\n /*\n System.out.println(y + \" \" + x);\n System.out.println(maxArea);\n */\n }\n }\n }\n System.out.println(maxArea);\n\n return maxArea;\n }\n\n public static boolean check(int y, int x, long total) {\n if (y == 60522) {\n // System.out.println(\"fcuk\");\n }\n boolean ret = check1(y, x, total, x + x) || check2(y, x, total);\n //System.out.println(y + \" \" + x + \" \" + total + \" \" + ret);\n return ret;\n }\n\n public static boolean check1(int y, int x, long total, int need) {\n // togather\n int up = (need - 1) / y + 1;\n int down = need / y;\n int hits = 0;\n if (need < y) {\n if (q(need, y) > 0) {\n hits = 1;\n }\n }\n if (hits == 1) {\n return total >= x;\n }\n int toSub = 0;\n int remain = need % y;\n for (int step = need - remain; step + remain <= maxA; step += y) {\n if (q(step + remain, min(step + y,maxA + 1)) > 0) {\n toSub = 1;\n break;\n }\n }\n if (toSub == 1) {\n return total >= x + down;\n } else {\n if (q(need, y) > 0) {\n return total >= x + up;\n } else {\n return false;\n }\n }\n }\n\n private static int min(int x, int y) {\n if (x < y) {\n return x;\n }\n return y;\n }\n\n\n public static boolean check2(int y, int x, long total) {\n // separate\n int need = x;\n int up = (need - 1) / y + 1;\n int down = need / y;\n int hits = 0;\n if (need < y) {\n if (q(need, y) > 0) {\n hits = q(need, y);\n }\n if (hits >= 2) {\n hits = 2;\n }\n }\n if (hits == 2) {\n return total >= x;\n }\n if (hits == 1) {\n return check1(y, x, total, x);\n }\n if (q(need, maxA + 1) < 2){\n return false;\n }\n if (hits == 0) {\n int toSub = 0;\n int remain = need % y;\n for (int step = need - remain; step + remain <= maxA; step += y) {\n int h = q(step + remain, min(step + y,maxA + 1));\n toSub += h;\n if (toSub >= 2) {\n toSub = 2;\n break;\n }\n }\n if (toSub == 2) {\n return total >= x + down + down;\n }\n if (toSub == 1) {\n return total >= x + down + up;\n }\n if (toSub == 0) {\n return total >= x + up + up;\n }\n }\n // never\n return false;\n }\n\n public static int q(int begin, int end) {\n if (begin > end) {\n return 0;\n }\n return sum[end - 1] - sum[begin - 1];\n }\n\n\n public static void test() {\n int n = 90792;\n int[] input = new int[maxN + 10];\n input[0] = 181565;\n input[1] = 181564;\n for (int i = 2; i < n; i++) {\n input[i] = 60522;\n }\n System.out.println(solve(n, input));\n }\n\n /*\n @Test\n public void test() {\n int n = 1;\n int[] input = {9};\n assertEquals(4, solve(n, input));\n }\n\n @Test\n public void test2() {\n String s = \"9\\n\" +\n \"9 10 9 18 9 9 9 28 9\";\n s = \"9\\n\" +\n \"9 10 9 19 9 9 9 28 9\";\n Scanner scanner = new Scanner(s);\n int n = scanner.nextInt();\n int [] input = new int[500000 +100];\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n assertEquals(90, solve(n, input));\n }\n */\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2f08a550d704ea57866d6339e6bc84c", "src_uid": "bca20e0910e9fe4d89326b50ab45e4ca", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "// import org.junit.Test;\nimport java.util.Scanner;\n\n// import static org.junit.Assert.assertEquals;\n\npublic class CF_1223G {\n static Scanner scanner = new Scanner(System.in);\n public static void main(String args[])\n {\n //test();\n long caseNum = 1;\n while (caseNum-- > 0) {\n task();\n }\n }\n\n private static int maxN = 500000;\n private static int[] a = new int[maxN + 10];\n private static int[] sum = new int[maxN + 10];\n private static int[] input = new int[maxN + 10];\n\n public static void task() {\n int n = scanner.nextInt();\n // System.out.println(n);\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n // System.out.println(\"input end\");\n solve(n, input);\n }\n\n public static void clear(int n) {\n for (int i = 1; i <= maxN + 1; i++) {\n a[i] = 0;\n sum[i] = 0;\n }\n }\n\n private static int maxA;\n\n public static long solve(int n, int[] input) {\n long maxArea = 0;\n maxA = 0;\n clear(n);\n for (int i = 0; i < n; i++) {\n a[input[i]]++;\n if (input[i] > maxA) {\n maxA = input[i];\n }\n }\n for (int i = 2; i <= maxN + 1; i++) {\n sum[i] = a[i] + sum[i - 1];\n }\n\n for (int y = 2; y <= maxA; y++) {\n long total = 0;\n for (int step = y; step <= maxA; step += y) {\n total += q(step, min(step + y - 1, maxA) + 1) * (long) (step / y);\n }\n int x = 1;\n int left = 2;\n int right = maxA;\n while (left <= right) {\n int mid = (left + right) / 2;\n if (check(y, mid, total)) {\n if (mid > x) {\n x = mid;\n }\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n if (x > 1) {\n if ((long) x * (long) y > maxArea) {\n maxArea = (long) x * (long) y;\n /*\n System.out.println(y + \" \" + x);\n System.out.println(maxArea);\n */\n }\n }\n }\n System.out.println(maxArea);\n\n return maxArea;\n }\n\n public static boolean check(int y, int x, long total) {\n if (y == 4) {\n // System.out.println(\"fcuk\");\n }\n boolean ret = check1(y, x, total, x + x, false) || check2(y, x, total);\n //System.out.println(y + \" \" + x + \" \" + total + \" \" + ret);\n return ret;\n }\n\n public static boolean check1(int y, int x, long total, int need, boolean ignore) {\n // together\n long up = (need - 1) / y + 1;\n long down = need / y;\n int hits = 0;\n if (!ignore) {\n if (need < y) {\n if (q(need, y) > 0) {\n hits = 1;\n }\n }\n }\n if (hits == 1) {\n return total >= x;\n }\n int toSub = 0;\n int remain = need % y;\n for (int step = y; step + remain <= maxA; step += y) {\n if (q(step + remain, min(step + y,maxA + 1)) > 0) {\n toSub = 1;\n break;\n }\n }\n if (toSub == 1) {\n return total >= x + down;\n } else {\n if (q(need, maxA + 1) > 0) {\n return total >= x + up;\n } else {\n return false;\n }\n }\n }\n\n private static int min(int x, int y) {\n if (x < y) {\n return x;\n }\n return y;\n }\n\n\n public static boolean check2(int y, int x, long total) {\n // separate\n int need = x;\n int up = (need - 1) / y + 1;\n int down = need / y;\n int hits = 0;\n if (need < y) {\n if (q(need, y) > 0) {\n hits = q(need, y);\n }\n if (hits >= 2) {\n hits = 2;\n }\n }\n if (hits == 2) {\n return total >= x;\n }\n // ?\n if (hits == 1) {\n return check1(y, x, total, x, true);\n }\n if (q(need, maxA + 1) < 2){\n return false;\n }\n if (hits == 0) {\n int toSub = 0;\n int remain = need % y;\n for (int step = y; step + remain <= maxA; step += y) {\n int h = q(step + remain, min(step + y,maxA + 1));\n toSub += h;\n if (toSub >= 2) {\n toSub = 2;\n break;\n }\n }\n if (toSub == 2) {\n return total >= x + down + down;\n }\n if (toSub == 1) {\n return total >= x + down + up;\n }\n if (toSub == 0) {\n return total >= x + up + up;\n }\n }\n // never\n return false;\n }\n\n public static int q(int begin, int end) {\n if (begin > end) {\n return 0;\n }\n return sum[end - 1] - sum[begin - 1];\n }\n\n\n public static void test() {\n int n = 90792;\n int[] input = new int[maxN + 10];\n input[0] = 181565;\n input[1] = 181564;\n for (int i = 2; i < n; i++) {\n input[i] = 60522;\n }\n System.out.println(solve(n, input));\n }\n\n /*\n @Test\n public void test() {\n int n = 1;\n int[] input = {9};\n assertEquals(4, solve(n, input));\n }\n\n @Test\n public void test2() {\n String s = \"9\\n\" +\n \"9 10 9 18 9 9 9 28 9\";\n s = \"9\\n\" +\n \"9 10 9 19 9 9 9 28 9\";\n Scanner scanner = new Scanner(s);\n int n = scanner.nextInt();\n int [] input = new int[500000 +100];\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n assertEquals(90, solve(n, input));\n }\n */\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ed2e1b7e7b1302232fe7a339d0eb8fd6", "src_uid": "bca20e0910e9fe4d89326b50ab45e4ca", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "// import org.junit.Test;\nimport java.util.Scanner;\n\n// import static org.junit.Assert.assertEquals;\n\npublic class CF_1223G {\n static Scanner scanner = new Scanner(System.in);\n public static void main(String args[])\n {\n // test();\n long caseNum = 1;\n while (caseNum-- > 0) {\n task();\n }\n }\n\n private static int maxN = 500000;\n private static int[] a = new int[maxN + 10];\n private static int[] sum = new int[maxN + 10];\n private static int[] input = new int[maxN + 10];\n\n public static void task() {\n int n = scanner.nextInt();\n // System.out.println(n);\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n // System.out.println(\"input end\");\n solve(n, input);\n }\n\n public static void clear(int n) {\n for (int i = 1; i <= maxN; i++) {\n a[i] = 0;\n sum[i] = 0;\n }\n }\n\n private static int maxA;\n\n public static long solve(int n, int[] input) {\n long maxArea = 0;\n maxA = 0;\n clear(n);\n for (int i = 0; i < n; i++) {\n a[input[i]]++;\n if (input[i] > maxA) {\n maxA = input[i];\n }\n }\n for (int i = 2; i <= maxN; i++) {\n sum[i] = a[i] + sum[i - 1];\n }\n\n\n /*\n {\n int total = 0;\n int y = 60522;\n for (int step = y; step <= maxA; step += y) {\n total += q(step, min(step + y - 1, maxA) + 1) * (step / y);\n System.out.println(total);;\n }\n System.out.println(\"total\");\n System.out.println(total);\n }\n */\n\n for (int y = 2; y <= maxA; y++) {\n int total = 0;\n for (int step = y; step <= maxA; step += y) {\n total += q(step, min(step + y - 1, maxA) + 1) * (step / y);\n }\n int x = 1;\n int left = 2;\n int right = maxA;\n while (left <= right) {\n int mid = (left + right) / 2;\n if (mid == 500019) {\n y = y;\n left = left;\n mid = mid;\n right = right;\n\n }\n if (check(y, mid, total)) {\n if (mid > x) {\n x = mid;\n }\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n if (x > 1) {\n if ((long) x * (long) y > maxArea) {\n maxArea = (long) x * (long) y;\n /*\n System.out.println(y + \" \" + x);\n System.out.println(maxArea);\n */\n }\n }\n }\n System.out.println(maxArea);\n\n return maxArea;\n }\n\n public static boolean check(int y, int x, int total) {\n if (y == 60522) {\n // System.out.println(\"fcuk\");\n }\n boolean ret = check1(y, x, total, x + x) || check2(y, x, total);\n //System.out.println(y + \" \" + x + \" \" + total + \" \" + ret);\n return ret;\n }\n\n public static boolean check1(int y, int x, int total, int need) {\n // togather\n int up = (need - 1) / y + 1;\n int down = need / y;\n int hits = 0;\n if (need < y) {\n if (q(need, y) > 0) {\n hits = 1;\n }\n }\n if (hits == 1) {\n return total >= x;\n }\n int toSub = 0;\n int remain = need % y;\n for (int step = need - remain; step + remain <= maxA; step += y) {\n if (q(step + remain, min(step + y,maxA + 1)) > 0) {\n toSub = 1;\n break;\n }\n }\n if (toSub == 1) {\n return total >= x + down;\n } else {\n if (q(need, y) > 0) {\n return total >= x + up;\n } else {\n return false;\n }\n }\n }\n\n private static int min(int x, int y) {\n if (x < y) {\n return x;\n }\n return y;\n }\n\n\n public static boolean check2(int y, int x, int total) {\n // separate\n int need = x;\n int up = (need - 1) / y + 1;\n int down = need / y;\n int hits = 0;\n if (need < y) {\n if (q(need, y) > 0) {\n hits = q(need, y);\n }\n if (hits >= 2) {\n hits = 2;\n }\n }\n if (hits == 2) {\n return total >= x;\n }\n if (hits == 1) {\n return check1(y, x, total, x);\n }\n if (q(need, maxA + 1) < 2){\n return false;\n }\n if (hits == 0) {\n int toSub = 0;\n int remain = need % y;\n for (int step = need - remain; step + remain <= maxA; step += y) {\n int h = q(step + remain, min(step + y,maxA + 1));\n toSub += h;\n if (toSub >= 2) {\n toSub = 2;\n break;\n }\n }\n if (toSub == 2) {\n return total >= x + down + down;\n }\n if (toSub == 1) {\n return total >= x + down + up;\n }\n if (toSub == 0) {\n return total >= x + up + up;\n }\n }\n // never\n return false;\n }\n\n public static int q(int begin, int end) {\n if (begin > end) {\n return 0;\n }\n return sum[end - 1] - sum[begin - 1];\n }\n\n\n public static void test() {\n int n = 90792;\n int[] input = new int[maxN + 10];\n input[0] = 181565;\n input[1] = 181564;\n for (int i = 2; i < n; i++) {\n input[i] = 60522;\n }\n System.out.println(solve(n, input));\n }\n\n /*\n @Test\n public void test() {\n int n = 1;\n int[] input = {9};\n assertEquals(4, solve(n, input));\n }\n\n @Test\n public void test2() {\n String s = \"9\\n\" +\n \"9 10 9 18 9 9 9 28 9\";\n s = \"9\\n\" +\n \"9 10 9 19 9 9 9 28 9\";\n Scanner scanner = new Scanner(s);\n int n = scanner.nextInt();\n int [] input = new int[500000 +100];\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n assertEquals(90, solve(n, input));\n }\n */\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6b9632c8b8303bef73feee552f838e6", "src_uid": "bca20e0910e9fe4d89326b50ab45e4ca", "difficulty": 3200.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Inverse {\n final int N = 32768;\n String string;\n int[] res = new int[N];\n int n, pos;\n \n int num() {\n if (string.charAt(pos) == 'f') {\n pos += 2;\n int tmp = expression();\n pos++;\n return res[tmp];\n }\n if (string.charAt(pos) == 'n') {\n pos++;\n return n;\n }\n int ret = 0;\n while (Character.isDigit(string.charAt(pos))) {\n ret = ret * 10 + string.charAt(pos) - '0';\n ++pos;\n }\n return ret;\n }\n \n int term() {\n int ret = num();\n while (string.charAt(pos) == '*' || string.charAt(pos) == '/') {\n char c = string.charAt(pos++);\n int next = num();\n if (c == '*') {\n ret = (ret * next) % N;\n } else {\n ret /= next;\n }\n }\n return ret;\n }\n \n int expression() {\n int ret = term();\n while (string.charAt(pos) == '+' || string.charAt(pos) == '-') {\n char c = string.charAt(pos++);\n int next = term();\n if (c == '+') {\n ret += next;\n if (ret >= N) ret -= N;\n } else {\n ret -= next;\n if (ret < 0) ret += N;\n }\n }\n return ret;\n }\n \n boolean logicalExpression() {\n int X = expression();\n char flag = string.charAt(pos++);\n if (flag == '=') pos++;\n int Y = expression();\n if (flag == '<' && X < Y) return true;\n if (flag == '=' && X == Y) return true;\n if (flag == '>' && X > Y) return true;\n return false;\n }\n \n int calculate() {\n pos = 11;\n while (string.charAt(pos) != '}') {\n if (string.charAt(pos) == 'r') {\n pos += 6;\n return expression();\n } else {\n pos += 3;\n boolean flag = logicalExpression();\n ++pos;\n if (flag == true) {\n pos += 6;\n return expression();\n } else {\n while (string.charAt(pos) != ';') ++pos;\n ++pos;\n }\n }\n }\n return 0;\n }\n \n public void solve() {\n Scanner inScanner = new Scanner(System.in);\n string = new String();\n int ans = inScanner.nextInt();\n while (inScanner.hasNext()) {\n string += inScanner.next();\n }\n for (int i = 0; i < N; ++i) {\n n = i;\n res[i] = calculate();\n }\n for (int i = N - 1; i >= 0; --i)\n if (res[i] == ans) {\n System.out.println(i);\n return;\n }\n System.out.println(\"-1\");\n }\n\n public static void main(String[] args) {\n new Inverse().solve();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "450cbcb8aec0de85c123585755e679bb", "src_uid": "698c5a87f9adbe6af60d9f70519c9672", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Stack;\n\npublic class School1G {\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(\n System.in));\n static PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) throws Exception {\n int n = Integer.valueOf(in.readLine());\n char[] buf = new char[200];\n int k = in.read(buf);\n\n String prog = String.valueOf(buf, 0, k);\n prog = prog.substring(prog.indexOf('{') + 1);\n prog = prog.substring(0, prog.indexOf('}'));\n String[] opers = prog.split(\";\");\n for (int i = 0; i < opers.length; i++)\n opers[i] = opers[i].trim();\n\n Function.init(opers.length - 1);\n for (int i = 0; i < opers.length - 1; i++)\n Function.body[i] = new Operator(opers[i]);\n\n int ans = -1;\n for (int i = (1 << 15)-1; i >= 0; i--)\n if (Function.eval(i) == n) {\n ans = i;\n break;\n }\n\n out.println(ans);\n\n out.flush();\n }\n\n}\n\nclass Function {\n static HashMap func = new HashMap();\n static Operator[] body;\n\n static void init(int n) {\n body = new Operator[n];\n }\n\n static int eval(int n) {\n if (func.containsKey(n)) return func.get(n);\n \n for (Operator oper : body) {\n int r = oper.eval(n);\n if (r != -1) {\n func.put(n, r);\n return r;\n }\n }\n //throw new RuntimeException();\n return -1;\n }\n}\n\nclass Expression {\n static final int MD = 1 << 15;\n \n List poliz;\n\n public Expression(String s) {\n s += \"$\";\n Stack ops = new Stack();\n poliz = new LinkedList();\n int p = 0;\n char c = ' ';\n while (c != '$') {\n String cur = \"\";\n while (c <= ' ')\n c = s.charAt(p++);\n if (c == 'n') {\n cur = \"n\";\n c = s.charAt(p++);\n poliz.add(cur);\n } else if (c == 'f') {\n cur = \"f\";\n while (c != '(')\n c = s.charAt(p++);\n c = s.charAt(p++);\n ops.push(cur);\n } else if (c >= '0' && c <= '9') {\n while (c >= '0' && c <= '9') {\n cur += (char) c;\n c = s.charAt(p++);\n }\n poliz.add(cur);\n } else {\n cur += (char) c;\n c = s.charAt(p++);\n if (cur.equals(\")\")) {\n while (!ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n poliz.add(ops.pop());\n } else if (cur.equals(\"+\") || cur.equals(\"-\"))\n while (!ops.empty() && !ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n else\n while (!ops.empty()\n && (ops.peek().equals(\"*\") || ops.peek()\n .equals(\"/\")))\n poliz.add(ops.pop());\n if (!cur.equals(\")\"))\n ops.push(cur);\n }\n }\n while (!ops.empty())\n poliz.add(ops.pop());\n }\n\n public int eval(int n) {\n Stack st = new Stack();\n for (String s : poliz) {\n if (s.equals(\"n\"))\n st.push(n);\n else if (s.charAt(0) >= '0' && s.charAt(0) <= '9')\n st.push(Integer.valueOf(s));\n else if (s.equals(\"f\"))\n st.push(Function.eval(st.pop()));\n else {\n int b = st.pop(), a = st.pop();\n if (s.equals(\"+\")) st.push((a + b)%MD);\n else if (s.equals(\"*\")) st.push(a*b%MD);\n else if (s.equals(\"/\")) st.push(a/b);\n else st.push((a - b + MD)%MD);\n }\n }\n return st.pop();\n }\n}\n\nclass Condition {\n int sign;\n Expression left, right;\n\n public Condition(String s) {\n s = s.substring(1, s.length() - 1);\n int sgn = s.indexOf('<');\n if (sgn >= 0) {\n sign = -1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else if ((sgn = s.indexOf('>')) >= 0) {\n sign = 1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else {\n sgn = s.indexOf(\"==\");\n sign = 0;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 2).trim());\n }\n }\n\n public boolean eval(int n) {\n int a = left.eval(n), b = right.eval(n);\n if (sign == -1)\n return a < b;\n else if (sign == 1)\n return a > b;\n else\n return a == b;\n }\n}\n\nclass Operator {\n boolean isIf;\n Condition cond;\n Expression toReturn;\n\n public Operator(String s) {\n if (s.startsWith(\"if\")) {\n int whereRet = s.indexOf(\"return\");\n isIf = true;\n cond = new Condition(s.substring(2, whereRet).trim());\n toReturn = new Expression(s.substring(whereRet + 6).trim());\n } else {\n isIf = false;\n cond = null;\n toReturn = new Expression(s.substring(6).trim());\n }\n }\n\n public int eval(int n) {\n if (isIf && !cond.eval(n))\n return -1;\n\n return toReturn.eval(n);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "faf75a2fc305d5b2cd2a68c35284ec1b", "src_uid": "698c5a87f9adbe6af60d9f70519c9672", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Stack;\n\npublic class School1G {\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(\n System.in));\n static PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) throws Exception {\n int n = Integer.valueOf(in.readLine());\n char[] buf = new char[200];\n int k = in.read(buf);\n\n String prog = String.valueOf(buf, 0, k);\n prog = prog.substring(prog.indexOf('{') + 1);\n prog = prog.substring(0, prog.indexOf('}'));\n String[] opers = prog.split(\";\");\n for (int i = 0; i < opers.length; i++)\n opers[i] = opers[i].trim();\n\n Function.init(opers.length);\n for (int i = 0; i < opers.length - 1; i++)\n Function.body[i] = new Operator(opers[i]);\n\n int ans = -1;\n for (int i = (1 << 15)-1; i >= 0; i--)\n if (Function.eval(i) == n) {\n ans = i;\n break;\n }\n\n out.println(ans);\n\n out.flush();\n }\n\n}\n\nclass Function {\n static HashMap func = new HashMap();\n static Operator[] body;\n\n static void init(int n) {\n body = new Operator[n];\n }\n\n static int eval(int n) {\n if (func.containsKey(n)) return func.get(n);\n \n for (Operator oper : body) {\n int r = oper.eval(n);\n if (r != -1) {\n func.put(n, r);\n return r;\n }\n }\n return -1;\n }\n}\n\nclass Expression {\n static final int MD = 1 << 15;\n \n List poliz;\n\n public Expression(String s) {\n s += \"$\";\n Stack ops = new Stack();\n poliz = new LinkedList();\n int p = 0;\n char c = ' ';\n while (c != '$') {\n String cur = \"\";\n while (c <= ' ')\n c = s.charAt(p++);\n if (c == 'n') {\n cur = \"n\";\n c = s.charAt(p++);\n poliz.add(cur);\n } else if (c == 'f') {\n cur = \"f\";\n while (c != '(')\n c = s.charAt(p++);\n c = s.charAt(p++);\n ops.push(cur);\n } else if (c >= '0' && c <= '9') {\n while (c >= '0' && c <= '9') {\n cur += (char) c;\n c = s.charAt(p++);\n }\n poliz.add(cur);\n } else {\n cur += (char) c;\n c = s.charAt(p++);\n if (cur.equals(\")\")) {\n while (!ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n poliz.add(ops.pop());\n } else if (cur.equals(\"+\") || cur.equals(\"-\"))\n while (!ops.empty() && !ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n else\n while (!ops.empty()\n && (ops.peek().equals(\"*\") || ops.peek()\n .equals(\"/\")))\n poliz.add(ops.pop());\n if (!cur.equals(\")\"))\n ops.push(cur);\n }\n }\n while (!ops.empty())\n poliz.add(ops.pop());\n }\n\n public int eval(int n) {\n Stack st = new Stack();\n for (String s : poliz) {\n if (s.equals(\"n\"))\n st.push(n);\n else if (s.charAt(0) >= '0' && s.charAt(0) <= '9')\n st.push(Integer.valueOf(s));\n else if (s.equals(\"f\"))\n st.push(Function.eval(st.pop()));\n else {\n int b = st.pop(), a = st.pop();\n if (s.equals(\"+\")) st.push((a + b)%MD);\n else if (s.equals(\"*\")) st.push(a*b%MD);\n else if (s.equals(\"/\")) st.push(a/b);\n else st.push((a - b + MD)%MD);\n }\n }\n return st.pop();\n }\n}\n\nclass Condition {\n int sign;\n Expression left, right;\n\n public Condition(String s) {\n s = s.substring(1, s.length() - 1);\n int sgn = s.indexOf('<');\n if (sgn >= 0) {\n sign = -1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else if ((sgn = s.indexOf('>')) >= 0) {\n sign = 1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else {\n sgn = s.indexOf(\"==\");\n sign = 0;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 2).trim());\n }\n }\n\n public boolean eval(int n) {\n int a = left.eval(n), b = right.eval(n);\n if (sign == -1)\n return a < b;\n else if (sign == 1)\n return a > b;\n else\n return a == b;\n }\n}\n\nclass Operator {\n boolean isIf;\n Condition cond;\n Expression toReturn;\n\n public Operator(String s) {\n if (s.equals(\"\")) return;\n if (s.startsWith(\"if\")) {\n int whereRet = s.indexOf(\"return\");\n isIf = true;\n cond = new Condition(s.substring(2, whereRet).trim());\n toReturn = new Expression(s.substring(whereRet + 6).trim());\n } else {\n isIf = false;\n cond = null;\n toReturn = new Expression(s.substring(6).trim());\n }\n }\n\n public int eval(int n) {\n if (isIf && !cond.eval(n))\n return -1;\n\n return toReturn.eval(n);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "778119f48f304f2bc0b6a476c9547ef0", "src_uid": "698c5a87f9adbe6af60d9f70519c9672", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Stack;\n\npublic class School1G {\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(\n System.in));\n static PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) throws Exception {\n int n = Integer.valueOf(in.readLine());\n char[] buf = new char[200];\n int k = in.read(buf);\n\n String prog = String.valueOf(buf, 0, k);\n prog = prog.substring(prog.indexOf('{') + 1);\n prog = prog.substring(0, prog.indexOf('}'));\n String[] opers = prog.split(\";\");\n for (int i = 0; i < opers.length; i++)\n opers[i] = opers[i].trim();\n\n Function.init(opers.length - 1);\n for (int i = 0; i < opers.length - 1; i++)\n Function.body[i] = new Operator(opers[i]);\n\n int ans = -1;\n for (int i = (1 << 15)-1; i >= 0; i--)\n if (Function.eval(i) == n) {\n ans = i;\n break;\n }\n\n out.println(ans);\n\n out.flush();\n }\n\n}\n\nclass Function {\n static HashMap func = new HashMap();\n static Operator[] body;\n\n static void init(int n) {\n body = new Operator[n];\n }\n\n static int eval(int n) {\n if (func.containsKey(n)) return func.get(n);\n \n for (Operator oper : body) {\n int r = oper.eval(n);\n if (r != -1) {\n func.put(n, r);\n return r;\n }\n }\n throw new RuntimeException();\n }\n}\n\nclass Expression {\n static final int MD = 1 << 15;\n \n List poliz;\n\n public Expression(String s) {\n s += \"$\";\n Stack ops = new Stack();\n poliz = new LinkedList();\n int p = 0;\n char c = ' ';\n while (c != '$') {\n String cur = \"\";\n while (c <= ' ')\n c = s.charAt(p++);\n if (c == 'n') {\n cur = \"n\";\n c = s.charAt(p++);\n poliz.add(cur);\n } else if (c == 'f') {\n cur = \"f\";\n while (c != '(')\n c = s.charAt(p++);\n c = s.charAt(p++);\n ops.push(cur);\n } else if (c >= '0' && c <= '9') {\n while (c >= '0' && c <= '9') {\n cur += (char) c;\n c = s.charAt(p++);\n }\n poliz.add(cur);\n } else {\n cur += (char) c;\n c = s.charAt(p++);\n if (cur.equals(\")\")) {\n while (!ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n poliz.add(ops.pop());\n } else if (cur.equals(\"+\") || cur.equals(\"-\"))\n while (!ops.empty() && !ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n else\n while (!ops.empty()\n && (ops.peek().equals(\"*\") || ops.peek()\n .equals(\"/\")))\n poliz.add(ops.pop());\n if (!cur.equals(\")\"))\n ops.push(cur);\n }\n }\n while (!ops.empty())\n poliz.add(ops.pop());\n }\n\n public int eval(int n) {\n Stack st = new Stack();\n for (String s : poliz) {\n if (s.equals(\"n\"))\n st.push(n);\n else if (s.charAt(0) >= '0' && s.charAt(0) <= '9')\n st.push(Integer.valueOf(s));\n else if (s.equals(\"f\"))\n st.push(Function.eval(st.pop()));\n else {\n int b = st.pop(), a = st.pop();\n if (s.equals(\"+\")) st.push((a + b)%MD);\n else if (s.equals(\"*\")) st.push(a*b%MD);\n else if (s.equals(\"/\")) st.push(a/b);\n else st.push((a - b + MD)%MD);\n }\n }\n return st.pop();\n }\n}\n\nclass Condition {\n int sign;\n Expression left, right;\n\n public Condition(String s) {\n s = s.substring(1, s.length() - 1);\n int sgn = s.indexOf('<');\n if (sgn >= 0) {\n sign = -1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else if ((sgn = s.indexOf('>')) >= 0) {\n sign = 1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else {\n sgn = s.indexOf(\"==\");\n sign = 0;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 2).trim());\n }\n }\n\n public boolean eval(int n) {\n int a = left.eval(n), b = right.eval(n);\n if (sign == -1)\n return a < b;\n else if (sign == 1)\n return a > b;\n else\n return a == b;\n }\n}\n\nclass Operator {\n boolean isIf;\n Condition cond;\n Expression toReturn;\n\n public Operator(String s) {\n if (s.startsWith(\"if\")) {\n int whereRet = s.indexOf(\"return\");\n isIf = true;\n cond = new Condition(s.substring(2, whereRet).trim());\n toReturn = new Expression(s.substring(whereRet + 6).trim());\n } else {\n isIf = false;\n cond = null;\n toReturn = new Expression(s.substring(6).trim());\n }\n }\n\n public int eval(int n) {\n if (isIf && !cond.eval(n))\n return -1;\n\n return toReturn.eval(n);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af4882a9e2e4ebfaccda211486b9dbc8", "src_uid": "698c5a87f9adbe6af60d9f70519c9672", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author kessido\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n GTakeMetro solver = new GTakeMetro();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class GTakeMetro {\n int n;\n int m;\n int s;\n long t;\n\n void step() {\n int curJump = (int) ((t--) % n);\n int sign = s < m ? 1 : -1;\n s += sign * curJump;\n s %= n;\n if (s < 0) s += n;\n }\n\n void doLoop() {\n for (int i = 0; i < n; i++) step();\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.NextInt();\n m = in.NextInt();\n s = in.NextInt() - 1;\n t = in.NextLong();\n\n while ((t % n) != 0) step();\n\n long[] lastSeem = new long[n];\n Arrays.fill(lastSeem, -1);\n while (t != 0) {\n doLoop();\n if (lastSeem[s] != -1) {\n long interval = lastSeem[s] - t;\n t %= interval;\n break;\n } else {\n lastSeem[s] = t;\n }\n }\n while (t != 0) step();\n out.println(s + 1);\n }\n\n }\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine(), \" \\t\\n\\r\\f,\");\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int NextInt() {\n return Integer.parseInt(next());\n }\n\n public long NextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af2d1e452ba88966a4d92f970ccdf746", "src_uid": "e743242f0cc9e17619e1fe4935d9fbd0", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.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 lewin\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n GTakeMetro solver = new GTakeMetro();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class GTakeMetro {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt(), m = in.nextInt();\n int s = in.nextInt() - 1;\n long t = in.nextLong();\n while (t % n != 0) {\n if (s < m) {\n s = (int) ((s + t) % n);\n } else {\n s = (int) ((s - t) % n);\n if (s < 0) s += n;\n }\n t--;\n }\n t /= n;\n int ps = -1;\n while (t-- > 0) {\n for (int i = n - 1; i >= 1; i--) {\n if (s < m) {\n s = (s + i) % n;\n } else {\n s = (s - i + n) % n;\n }\n }\n if (s == ps) break;\n ps = s;\n }\n out.println(s + 1);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public long nextLong() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n long res = 0L;\n\n while (c >= 48 && c <= 57) {\n res *= 10L;\n res += (long) (c - 48);\n c = this.read();\n if (isSpaceChar(c)) {\n return res * (long) sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "42e5f174c06143bb3afd930d58b1f539", "src_uid": "e743242f0cc9e17619e1fe4935d9fbd0", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author kessido\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n GTakeMetro solver = new GTakeMetro();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class GTakeMetro {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.NextInt();\n int m = in.NextInt();\n int s = in.NextInt() - 1;\n long t = in.NextLong();\n int p = 0;\n HashMap hm = new HashMap<>();\n boolean fl = false;\n while (t != 0) {\n int curJump = (int) (t % n);\n t--;\n p++;\n int sign = s < m ? 1 : -1;\n s += sign * curJump;\n s %= n;\n if (s < 0) s += n;\n if (!fl) {\n long x = (((long) s) << 32) | curJump;\n Integer res = hm.put(x, p);\n if (res != null) {\n int loopLegth = p - res;\n t %= loopLegth;\n fl = true;\n }\n }\n }\n out.println(s + 1);\n }\n\n }\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine(), \" \\t\\n\\r\\f,\");\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int NextInt() {\n return Integer.parseInt(next());\n }\n\n public long NextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d52f838f02e39bacb88c839c74da55a", "src_uid": "e743242f0cc9e17619e1fe4935d9fbd0", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author kessido\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n GTakeMetro solver = new GTakeMetro();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class GTakeMetro {\n int step(int n, long t, int s, int m) {\n int curJump = (int) (t % n);\n int sign = s < m ? 1 : -1;\n s += sign * curJump;\n s %= n;\n if (s < 0) s += n;\n return s;\n }\n\n int doLoop(int s, long t, int n, int m) {\n for (int i = 0; i < n; i++) {\n s = step(n, t--, s, m);\n }\n return s;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.NextInt();\n int m = in.NextInt();\n int s = in.NextInt() - 1;\n long t = in.NextLong();\n while (t != 0) {\n s = step(n, t--, s, m);\n }\n long[] lastSeem = new long[n];\n int round = 0;\n Arrays.fill(lastSeem, -1);\n while (t != 0) {\n s = doLoop(s, t, n, m);\n t -= n;\n if (lastSeem[s] != -1) {\n long interval = lastSeem[s] - t;\n t %= interval;\n break;\n } else {\n lastSeem[s] = round++;\n }\n }\n while (t != 0) {\n s = step(n, t--, s, m);\n }\n out.println(s + 1);\n }\n\n }\n\n static class InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine(), \" \\t\\n\\r\\f,\");\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int NextInt() {\n return Integer.parseInt(next());\n }\n\n public long NextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "36ee431651f252b4fb1c9e8cbb3983ad", "src_uid": "e743242f0cc9e17619e1fe4935d9fbd0", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.nio.Buffer;\nimport java.util.*;\n\n/**\n * Created by deepshine on 2014/6/5.\n * Codeforces Round 250 Div.2 C\n */\npublic class Main{\n\n\tpublic static void main(String[] args){\n\t\tScan scan = new Scan();\n\t\tint n = scan.nextInt();\n\t\tDouble[] d = new Double[n];\n\t\tfor(int i=0;i=0;i--){\n\t\t\tfail_chance = (1 - d[i]) * fail_chance;\n\t\t\tdouble temp = 0;\n\t\t\tfor(int j=i;j result) result = temp;\n\t\t}\n\n\t\tSystem.out.println(result);\n\n\t}\n\n}\n\n\nclass Scan implements Iterator{\n\n\tBufferedReader buffer;\n\tStringTokenizer tok;\n\n\tScan(){\n\t\tbuffer = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\n\t@Override\n\tpublic boolean hasNext(){\n\t\twhile(tok==null || !tok.hasMoreElements()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(buffer.readLine());\n\t\t\t}catch(IOException e){\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic String next(){\n\t\tif(hasNext()) return tok.nextToken();\n\t\treturn null;\n\t}\n\n\tString nextLine(){\n\t\tif(hasNext()) return tok.nextToken(\"\\n\");\n\t\treturn null;\n\t}\n\n\tint nextInt(){\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tdouble nextDouble(){\n\t\treturn Double.parseDouble(next());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "46d75513d4f4a53bad33a3c93beb4d49", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\n\n\n\tpublic static void main(String[] args){\n\t\tScan scan = new Scan();\n\t\tint n = scan.nextInt();\n\t\tint[] stack = new int[n];\n\t\tint top = 0;\n\t\tlong result = 0;\n\n\t\tfor(int i=0;i1 && stack[top-2] >= stack[top-1] && temp >= stack[top-1]){\n\t\t\t\tresult += Math.min(stack[top-2], temp);\n\t\t\t\ttop--;\n\t\t\t}\n\t\t\tstack[top++] = temp;\n\t\t}\n\n\t\tfor(int i=1;i<--top;i++){\n\t\t\tresult += Math.min(stack[i-1], stack[i+1]);\n\t\t}\n\n\t\tSystem.out.println(result);\n\n\t}\n\n}\n\n\nclass Scan implements Iterator{\n\n\tBufferedReader buffer;\n\tStringTokenizer tok;\n\n\tScan(){\n\t\tbuffer = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\n\t@Override\n\tpublic boolean hasNext(){\n\t\twhile(tok==null || !tok.hasMoreElements()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(buffer.readLine());\n\t\t\t}catch(Exception e){\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic String next(){\n\t\tif(hasNext()) return tok.nextToken();\n\t\treturn null;\n\t}\n\n\t@Override\n\tpublic void remove(){\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\tint nextInt(){\n\t\treturn Integer.parseInt(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ab7e84c51dcb42db6292e5caf363c5e3", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Collections.*;\nimport java.util.function.Consumer;\n\nimport static java.lang.Math.*;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.*;\nimport static java.math.BigInteger.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean my;\n try {\n my = System.getProperty(\"MY_LOCAL\") != null;\n } catch (Exception e) {\n my = false;\n }\n try{\n err = System.err;\n if( my ){\n sc = new FastScanner(new BufferedReader(new FileReader(\"input.txt\")));\n// sc = new FastScanner(new BufferedReader(new FileReader(\"C:\\\\myTest.txt\")));\n out = new PrintWriter (new FileWriter(\"output.txt\"));\n }\n else {\n sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n// out = new PrintWriter(new OutputStreamWriter(System.out));\n }catch(Exception e){\n MLE();\n }\n if( my )\n tBeg = System.currentTimeMillis();\n solve();\n if( my )\n err.println( \"TIME: \" + (System.currentTimeMillis() - tBeg ) / 1e3 );\n exit(0);\n }\n\n void exit( int val ){\n err.flush();\n out.flush();\n System.exit(val);\n }\n\n double tBeg;\n FastScanner sc;\n PrintWriter out;\n PrintStream err;\n\n class FastScanner{\n\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner( BufferedReader _br ){\n br = _br;\n }\n\n String readLine(){\n try {\n return br.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n String next(){\n while( st==null || !st.hasMoreElements() )\n st = new StringTokenizer(readLine());\n return st.nextToken();\n }\n\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n double nextDouble(){ return Double.parseDouble(next()); }\n }\n\n void MLE(){\n int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];\n }\n\n void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }\n\n void TLE(){\n for(;;);\n }\n\n public static void main(String[] args) {\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"Lolka\", 256_000_000L ).run();\n }\n\n ////////////////////////////////////////////////////////////////\n\n int n;\n int[] a, pr, nx;\n PriorityQueue Q;\n boolean[] used;\n\n void solve(){\n n = sc.nextInt();\n a = new int[n];\n pr = new int[n];\n nx = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = sc.nextInt();\n pr[i] = i - 1;\n nx[i] = i + 1;\n }\n\n Q = new PriorityQueue<>();\n used = new boolean[n];\n for (int i = 1; i <= n-2; i++) {\n try_add(i);\n }\n long ans = 0;\n\n while( !Q.isEmpty() ){\n int i = Q.poll();\n nx[pr[i]] = nx[i];\n pr[nx[i]] = pr[i];\n ans += min( a[pr[i]], a[nx[i]] );\n try_add( pr[i] );\n try_add( nx[i] );\n }\n\n {\n int i = nx[0];\n while( nx[i] != n ){\n ans += min( a[pr[i]], a[nx[i]] );\n i = nx[i];\n }\n }\n\n out.println( ans );\n }\n\n private void try_add(int i) {\n try {\n if( used[i] )return;\n\n if( 1<=i && i <=n-2 && a[pr[i]] >= a[i] && a[i] <= a[nx[i]] ){\n Q.add( i );\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eeeb5038e363dbe1ba8a3c8aee61acf0", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\n\tstatic int[][] chart;\n\n\tpublic static void main(String[] args){\n\t\tScan scan = new Scan();\n\t\tint n = scan.nextInt();\n\t\tint[] arr = new int[n+1];\n\t\tchart = new int[n+1][n+1];\n\t\tarr[0] = 0;\n\t\tfor(int i=1;i<=n;i++) arr[i] = scan.nextInt();\n\t\tint result = solve(0, n, arr);\n\t\tSystem.out.println(result);\n\t\t//\t\tfor(int i=0;i<=n;i++){\n\t\t//\t\t\tfor(int j=0;j<=n;j++) System.out.print(chart[i][j]+\" \");\n\t\t//\t\t\tSystem.out.println();\n\t\t//\t\t}\n\t}\n\n\tstatic int solve(int begin, int end, int[] arr){\n\t\tif(begin + 2 == end) return 0;\n\t\tif(chart[begin][end] != 0) return chart[begin][end];\n\t\tint result = 0;\n\t\tfor(int i = begin+1;i result) result = temp;\n\t\t}\n\t\treturn chart[begin][end] = result;\n\t}\n\n}\n\n\nclass Scan implements Iterator{\n\n\tBufferedReader buffer;\n\tStringTokenizer tok;\n\n\tScan(){\n\t\tbuffer = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\n\t@Override\n\tpublic boolean hasNext(){\n\t\twhile(tok==null || !tok.hasMoreElements()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(buffer.readLine());\n\t\t\t}catch(Exception e){\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic String next(){\n\t\tif(hasNext()) return tok.nextToken();\n\t\treturn null;\n\t}\n\n\t@Override\n\tpublic void remove(){\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\tint nextInt(){\n\t\treturn Integer.parseInt(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "93e42eb059bde3361577223f34ddacd2", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n \npublic class main {\n public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n public static PrintWriter pw = new PrintWriter(System.out);\n public static String line;\n public static StringTokenizer st, st2;\n public static ArrayList> adjList;\n public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};\n public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};\n public static int INF = 0x3f3f3f3f;\n public static int MOD = 1000000007;\n public static long LINF = 0x3f3f3f3f3f3f3f3fL;\n\n public static void main(String[] args) throws Exception {\n int[] A = new int[11];\n for (int i = 0; i < 11; i++) {\n A[i] = Integer.parseInt(br.readLine());\n }\n\n for (int i = 10; i >= 0; i--) {\n double a = Math.pow(Math.abs(A[i]), 0.5);\n double b = Math.pow(A[i], 3) * 5;\n double res = a + b;\n\n if (res > 400) {\n System.out.printf(\"f(%d) = MAGNA NIMIS!\\n\", A[i]);\n } else {\n System.out.printf(\"f(%d) = %.2f\\n\", A[i], res);\n }\n }\n\n\n pw.close();\n br.close();\n }\n}\n\nclass Pair implements Comparable{\n public int a, b;\n\n Pair(int _a, int _b){\n a = _a;\n b = _b;\n }\n \n public String toString(){\n return a + \" \" + b;\n }\n\n public int compareTo(Pair p){\n if (a != p.a) return a < p.a ? -1 : 1;\n if (b != p.b) return b < p.b ? -1 : 1;\n return 0;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5345216dfe0b569cd5da54221b430500", "src_uid": "30b3411c3c23d029ea1e9cf73e7d2f01", "difficulty": null} {"lang": "Java 11", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.pow;\nimport static java.lang.Math.sqrt;\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.Locale;\nimport java.util.StringTokenizer;\n\npublic class G {\n\n\tstatic void solve() throws Exception {\n\t\tint a[] = new int[11];\n\t\tfor (int i = 0; i < 11; i++) {\n\t\t\ta[i] = scanInt();\n\t\t}\n\t\tfor (int i = 10; i >= 0; i--) {\n\t\t\tdouble r = sqrt(abs(a[i])) + pow(a[i], 3) * 5;\n\t\t\tif (r > 400) {\n\t\t\t\tout.print(\"f(\" + a[i] + \") = MAGNA NIMIS!\\n\");\n\t\t\t} else {\n\t\t\t\tout.printf(Locale.US, \"f(%d) = %.2f\\n\", a[i], r);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1dd4efedb7ce1a9a978c3a0d4a7cf10b", "src_uid": "30b3411c3c23d029ea1e9cf73e7d2f01", "difficulty": null} {"lang": "Java 8", "source_code": "import javax.imageio.ImageIO;\nimport java.awt.image.BufferedImage;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.net.PortUnreachableException;\nimport java.util.*;\n\n// written by luchy0120\n\npublic class Main {\n public static void main(String[] args) throws Exception {\n\n new Main().run();\n }\n\n static int groups = 0;\n static int[] fa;\n static int[] sz;\n\n static void init(int n) {\n groups = n;\n fa = new int[n];\n for (int i = 1; i < n; ++i) {\n fa[i] = i;\n }\n sz = new int[n];\n Arrays.fill(sz, 1);\n }\n\n static int root(int p) {\n while (p != fa[p]) {\n fa[p] = fa[fa[p]];\n p = fa[p];\n }\n return p;\n }\n\n static void combine(int p, int q) {\n int i = root(p);\n int j = root(q);\n if (i == j) {\n return;\n }\n if (sz[i] < sz[j]) {\n fa[i] = j;\n sz[j] += sz[i];\n } else {\n fa[j] = i;\n sz[i] += sz[j];\n }\n groups--;\n }\n\n int child[];\n int color[],dfn[],low[],stack[],cnt[];\n boolean vis[];\n boolean iscut[];\n int deep,top,n,m,sum,ans;\n List g[];\n int root = 0;\n // \u65e0\u5411\u56fe\u7684\u5f3a\u8fde\u901a\u5206\u91cf\n void tarjanNonDirect(int u1) {\n\n int stk[] = new int[10001];\n int fatk[] = new int[10001];\n int p = 0;\n stk[p] = u1;\n fatk[p] = -1;\n p= 1;\n ot: while(p>0) {\n int u = stk[p-1];\n int fa = fatk[p-1];\n\n\n if(dfn[u]==0) {\n low[u] = dfn[u] = ++deep;\n }\n // stack[top++] = u;\n\n for (; h[u] != -1; h[u] = ne[h[u]]) {\n int v = to[h[u]];\n if (dfn[v] == 0) {\n //tarjanNonDirect(v);\n\n fatk[p] = u;\n stk[p++] = v;\n continue ot;\n } else {\n low[u] = Math.min(low[u], dfn[v]);\n // \u6ca1\u6709\u7279\u5224\u662f\u5426\u76f4\u63a5\u6307\u5411\u7236\u4eb2\n // \u56de\u8fb9\uff0c\u4f7f\u7528dfn\u3010v\u3011\u66f4\u65b0low\u3010u\u3011,\u56e0\u4e3a\u53ef\u80fd\u662f\u6307\u5411\u7236\u4eb2\uff0c\u800c\u7236\u4eb2\u7684low\u53ef\u80fd\u6bd4\u8f83\u5c0f\n }\n }\n --p;\n\n if (fa != -1) {\n low[fa] = Math.min(low[fa], low[u]);\n if (low[u] >= dfn[fa]) {\n if (fa != root || ++child[fa] > 1) { // \u4e0d\u662froot\uff0c\u76f4\u63a5\u8bb0\u4e3acut\uff0c\u662froot\uff0c\u5224\u65ad\u662f\u5426\u6709\u4e24\u4e2a\u513f\u5b50\n iscut[fa] = true;\n }\n ++dcc_cnt;\n // \u4e00\u4e2a\u5272\u70b9\u53ef\u80fd\u4f1a\u88ab\u591a\u4e2a\u70b9\u53cc\u5171\u4eab\n // int z = -1;\n // do {\n // z = stack[--top];\n // dcc[dcc_cnt].add(z);\n // } while(z != v);\n // dcc[dcc_cnt].add(u);\n }\n\n\n }\n\n }\n }\n int gd = 0;\n int id =-1;\n int scc_cnt = 0;\n int sccno[];\n // \u6709\u5411\u56fe\u7684\u5f3a\u8fde\u901a\u5206\u91cf\n void tarjan(int u) {\n int stk[] = new int[10001];\n // int tptk[] = new int[10001];\n\n // int fatk[] = new int[10001];\n int p =1; stk[0] = u;//fatk[0] =-1;\n ot:while(p>0) {\n u = stk[p-1];\n // int fa = fatk[p-1];\n if (dfn[u] == 0) {\n low[u] = dfn[u] = ++deep;\n stack[top++] = u;\n\n }\n\n for (; hc[u] != -1; hc[u] = ne[hc[u]]) {\n int v = to[hc[u]];\n if (dfn[v] == 0) {\n stk[p++] = v;\n continue ot;\n // low[u] = Math.min(low[u], low[v]);\n } else if (sccno[v] == 0) {\n // dfn>0 but sccno==0, means it's in current stack\n low[u] = Math.min(low[u], low[v]);\n }\n }\n\n p--;\n if (dfn[u] == low[u]) {\n sccno[u] = ++scc_cnt;\n if(u==1){\n id = scc_cnt;\n }\n\n while (stack[top - 1] != u) {\n sccno[stack[top - 1]] = scc_cnt;\n if(stack[top - 1]==1){\n id = scc_cnt;\n }\n --top;\n }\n\n --top;\n }\n if(p>=1){\n int fa = stk[p-1];\n low[fa] = Math.min(low[fa], low[u]);\n }\n }\n }\n int rr =0;\n// void solve() {\n//\n// }\n\n\n\n\n// int get_room(int i,int j){\n// return i/3*3 + j/3;\n// }\n\n// int a[][] = new int[9][9];\n// int space = 0;\n//\n// boolean vis_row[][] = new boolean[9][10];\n// boolean vis_col[][] = new boolean[9][10];\n// boolean vis_room[][] = new boolean[9][10];\n// int val[][][] =new int[9][9][];\n// int prepare[][];\n//\n// void dfs(int rt){\n//\n// }\n\n int h[],to[],ne[];int ct =0;\n void add(int u,int v){\n // u--;v--;\n to[ct] = v;\n ne[ct] = h[u];\n h[u] = ct++;\n\n }\n\n int dcc_cnt = 0;\n int time = 0;\n\n\n\n\n\n\n\n\n private static double f(double x) {\n return Math.pow(Math.abs(x), 0.5) + (5*(Math.pow(x, 3)));\n }\n\n\n\n long summ[];\n int v[];\n int hc[];\n void solve() {\n// File f = new File(\"C:\\\\Users\\\\Luqi\\\\Desktop\\\\1.png\");\n// BufferedImage bi = null;\n// try {\n// bi = ImageIO.read(f);\n// } catch (IOException e) {\n// e.printStackTrace();\n// }\n//\n// int width = bi.getWidth();\n// int height = bi.getHeight();\nList r = new ArrayList<>();\n while(true){\n int x =ni();\n if(lenbuf==-1) break;\n r.add(x);\n }\n\n for(int i=r.size()-1;i>=0;--i){\n int x = r.get(i);\n double y = f(x);\n if( y < 400.0) {\n System.out.printf(\"f(%d) = %.2f\\n\", x, y);\n } else {\n System.out.printf(\"f(%d) = %s\\n\", x, \"MAGNA NIMIS!\");\n }\n }\n\n\n // println(width);\n// // println(height);\n// int i =ni();\n// int j =ni();\n\n\n// for(int i=0;i> 16;\n// b[j][i][1] = (pixel & 0xff00) >> 8;\n// b[j][i][2] = (pixel & 0xff);\n//\n// }\n// println();\n// }\n//\n// for(int i=0;i<64;++i){\n// print(\"\\\"\");\n// for(int j=0;j<64;++j){\n// print(b[i][j][0]<=50?\"*\":\" \");\n// }\n// println(\"\\\",\");\n// }\n// //println(b[0][0]);\n\n\n//\n//\n//\n//\n//\n// }\n// }\n // print(\"No\");\n\n\n\n\n// int n = ni();\n// int m = n*(n+1)/2;\n// int k = ni();\n// int p = 0;\n//\n// double x[] = new double[n];\n// double y[] = new double[n];\n//\n// for(int i=0;i li = new ArrayList<>();\n// for(int i=0;iDouble.compare(xx.s,yy.s));\n//\n// init(n + 1);\n//\n// int s = 0;\n// int c = n;\n// for (int i = 0; i < li.size(); ++i) {\n// int p1 = li.get(i).a;\n// int p2 = li.get(i).b;\n// if (root(p1) != root(p2)) {\n// combine(p1, p2);\n// c--;\n// if(c==k-1){\n// print(roundS(Math.sqrt(li.get(i).s),2));\n// break;\n// }\n// }\n// }\n\n }\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n// }\n\n\n static long mul(long a, long b, long p)\n {\n long res=0,base=a;\n while(b>0)\n {\n if((b&1L)>0)\n res=(res+base)%p;\n base=(base+base)%p;\n b>>=1;\n }\n return res;\n }\n\n\n static long mod_pow(long k,long n,long p){\n long res = 1L;\n long temp = (k%p+p)%p;\n while(n!=0L){\n if((n&1L)==1L){\n res = ((res*temp)%p+p)%p;\n }\n temp = ((temp * temp)%p+p)%p;\n n = n>>1L;\n }\n return res%p;\n }\n public static String roundS(double result, int scale){\n String fmt = String.format(\"%%.%df\", scale);\n return String.format(fmt, result);\n }\n\n\n// void solve() {\n//\n// for(int i=0;i<9;++i) {\n// for (int j = 0; j < 9; ++j) {\n// int v = ni();\n// a[i][j] = v;\n// if(v>0) {\n// vis_row[i][v] = true;\n// vis_col[j][v] = true;\n// vis_room[get_room(i, j)][v] = true;\n// }else{\n// space++;\n// }\n// }\n// }\n//\n//\n// prepare = new int[space][2];\n//\n// int p = 0;\n//\n// for(int i=0;i<9;++i) {\n// for (int j = 0; j < 9; ++j) {\n// if(a[i][j]==0){\n// prepare[p][0] = i;\n// prepare[p][1]= j;p++;\n// List temp =new ArrayList<>();\n// for(int k=1;k<=9;++k){\n// if(!vis_col[j][k]&&!vis_row[i][k]&&!vis_room[get_room(i,j)][k]){\n// temp.add(k);\n// }\n// }\n// int sz = temp.size();\n// val[i][j] = new int[sz];\n// for(int k=0;k{\n// return Integer.compare(val[x[0]][x[1]].length,val[y[0]][y[1]].length);\n// });\n// dfs(0);\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n// }\n\n\n\n\n InputStream is;\n PrintWriter out;\n\n void run() throws Exception {\n //is = new FileInputStream(new File(\"C:\\\\Users\\\\Luqi\\\\Downloads\\\\P3387_9.in\"));\n is = System.in;\n out = new PrintWriter(System.out);\n\n solve();\n out.flush();\n }\n\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if (lenbuf == -1) throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(inbuf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0) return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n\n private int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n return b;\n }\n\n private double nd() {\n return Double.parseDouble(ns());\n }\n\n private char nc() {\n return (char) skip();\n }\n\n private char ncc() {\n int b = readByte();\n return (char) b;\n }\n\n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while (p < n && !(isSpaceChar(b))) {\n buf[p++] = (char) b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private String nline() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!isSpaceChar(b) || b == ' ') {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[][] nm(int n, int m) {\n char[][] a = new char[n][];\n for (int i = 0; i < n; i++) a[i] = ns(m);\n return a;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = ni();\n return a;\n }\n\n private long[] nal(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++) a[i] = nl();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {\n }\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n while (true) {\n if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');\n else return minus ? -num : num;\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {\n }\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n while (true) {\n if (b >= '0' && b <= '9') num = num * 10 + (b - '0');\n else return minus ? -num : num;\n b = readByte();\n }\n }\n\n void print(Object obj) {\n out.print(obj);\n }\n\n void println(Object obj) {\n out.println(obj);\n }\n\n void println() {\n out.println();\n }\n\n void printArray(int a[],int from){\n int l = a.length;\n for(int i=from;i s=new Stack<>();\n\t\tfor(int i=0;i<11;i++)s.push(in.nextInt());\n\t\twhile(!s.isEmpty()) {\n\t\t\tint on=s.pop();\n\t\t\tdouble a = Math.sqrt(Math.abs(on));\n\t\t\tdouble b = on*on*on*5;\n\t\t\tdouble r=a + b;\n\t\t\tif (r > 400)System.out.printf(\"f(%d) = MAGNA NIMIS!\\n\", on);\n\t\t\telse System.out.printf(\"f(%d) = %.2f\\n\", on,r);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1da53ac2d06ab4fe07fb179c263e4b0e", "src_uid": "30b3411c3c23d029ea1e9cf73e7d2f01", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class SlimeCombining {\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 double[][] dp = new double[maxp][maxp];\n double[][] sum = new double[maxp][maxp];\n for (int cur = 1; cur < maxp; cur++)\n dp[maxp-1][cur] = vals[cur];\n \n // manual dp\n for (int i = maxp-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 dp[i][cur] += b[maxp-i-1][next] * dp[i+1][next];\n sum[i][cur] += b[maxp-i-1][next];\n } else {\n if (cur < next) continue;\n dp[i][cur] += a[maxp-i-1][next] * dp[i+1][next];\n sum[i][cur] += a[maxp-i-1][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 < maxp) {\n int k = (int)n;\n double exp = 0;\n for (int i = 1; i < maxp; i++) {\n exp += a[k][i] * dp[maxp-k][i];\n }\n out.printf(\"%.15f\\n\", exp);\n out.close();\n System.exit(0);\n }\n \n double[] vec = new double[maxp+1];\n System.arraycopy(dp[0], 0, vec, 0, maxp);\n vec[maxp] = 1;\n double[][] mat = new double[maxp+1][maxp+1];\n mat[maxp][maxp] = 1;\n for (int i = 1; i < maxp; i++) {\n for (int j = 1; j < maxp; j++) {\n if (i == j) continue;\n if (i == 1) {\n mat[i][j] += b[maxp-1][j] / sum[0][i];\n } else {\n if (i < j) continue;\n mat[i][j] += a[maxp-1][j] / sum[0][i];\n }\n }\n mat[i][maxp] += vals[i];\n }\n mat = mat_exp(mat, n - maxp);\n vec = vec_mult(mat, vec);\n double exp = 0;\n for (int i = 1; i < maxp; i++) {\n exp += a[maxp-1][i] * vec[i];\n }\n out.printf(\"%.15f\\n\", exp);\n out.close();\n System.exit(0);\n }\n \n public static double[] vec_mult(double[][] A, double[] B) {\n double[] C = new double[A.length];\n for (int i = 0; i < A.length; i++) {\n for (int j = 0; j < B.length; j++) {\n C[i] += A[i][j] * B[j];\n }\n }\n return C;\n }\n \n private static double[][] mat_exp(double[][] A, long e) {\n if (e == 0) {\n double[][] ret = new double[A.length][A.length];\n for (int i = 0; i < A.length; i++) ret[i][i] = 1.0;\n return ret;\n }\n if (e == 1)\n return A;\n else if (e % 2 == 0) {\n double[][] A1 = mat_exp(A, e / 2);\n return matrix_mult(A1, A1);\n } else\n return matrix_mult(A, mat_exp(A, e - 1));\n }\n\n private static double[][] matrix_mult(double[][] A, double[][] B) {\n double[][] C = new double[A.length][A.length];\n for (int i = 0; i < A.length; i++)\n for (int j = 0; j < A.length; j++)\n for (int k = 0; k < A.length; k++)\n C[i][k] += A[i][j] * B[j][k];\n return C;\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "abbf5d77c473648bd42854d1192c20de", "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class SlimeCombiningLinear {\n private static InputReader in;\n private static PrintWriter out;\n public static double EPS = 1e-15;\n public static int maxp = 50;\n \n public static void main (String[] args) {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n \n int n = in.nextInt();\n int p = in.nextInt();\n \n double p2 = p / 1000000000., p4 = 1 - p2;\n double[][] a = new double[maxp][maxp];\n double[][] b = new double[maxp][maxp];\n for (int len = 1; len < maxp; len++) { \n for (int pow = 1; pow < maxp; pow++) {\n if (pow == 1) a[len][pow] += p2;\n if (pow == 2) {\n a[len][pow] += p4;\n b[len][pow] += p4;\n }\n a[len][pow] += a[len-1][pow-1] * a[len][pow-1];\n b[len][pow] += a[len-1][pow-1] * b[len][pow-1];\n }\n }\n for (int len = maxp - 1; len >= 1; len--) {\n for (int pow = 1; pow < maxp; pow++) {\n a[len][pow] *= 1 - a[len-1][pow];\n b[len][pow] *= 1 - a[len-1][pow];\n }\n }\n \n // value of a slime that has been merged i times\n long[] vals = new long[maxp];\n for (int i = 0; i < maxp; i++) vals[i] = i;//1l << i;\n // manually do first few cases\n int maxn = 1000;\n double[][] dp = new double[maxn][maxp];\n double[][] sum = new double[maxn][maxp];\n for (int cur = 1; cur < maxp; cur++)\n dp[maxn-1][cur] = vals[cur];\n \n // manual dp\n for (int i = maxn-2; i >= 0; i--) {\n for (int cur = 1; cur < maxp; cur++) {\n for (int next = 1; next < maxp; next++) {\n if (cur == next) continue;\n if (cur == 1) {\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += b[id][next] * dp[i+1][next];\n sum[i][cur] += b[id][next];\n } else {\n if (cur < next) continue;\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += a[id][next] * dp[i+1][next];\n sum[i][cur] += a[id][next];\n }\n }\n }\n for (int cur = 1; cur < maxp; cur++) {\n dp[i][cur] = vals[cur] + dp[i][cur] / sum[i][cur];\n }\n }\n if (n <= maxn) {\n int k = (int)n;\n int w = Math.min(maxp-1, k);\n double exp = 0;\n for (int i = 1; i < maxp; i++) {\n exp += a[w][i] * dp[maxn-k][i];\n }\n out.printf(\"%.15f\\n\", exp);\n out.close();\n System.exit(0);\n }\n\n double exp1 = 0;\n double exp2 = 0;\n for (int i = 1; i < maxp; i++) {\n exp1 += a[maxp-1][i] * dp[0][i];\n exp2 += a[maxp-1][i] * dp[1][i];\n }\n out.printf(\"%.15f\\n\", exp2 + (exp1 - exp2) * (long)(n - maxn + 1));\n out.close();\n System.exit(0);\n }\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a03c3df63a27de0d3647364508507042", "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class SlimeCombiningLinear {\n private static InputReader in;\n private static PrintWriter out;\n public static double EPS = 1e-15;\n public static int maxp = 50;\n \n public static void main (String[] args) {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n \n int n = in.nextInt();\n int p = in.nextInt();\n \n double p2 = p / 1000000000., p4 = 1 - p2;\n double[][] a = new double[maxp][maxp];\n double[][] b = new double[maxp][maxp];\n for (int len = 1; len < maxp; len++) { \n for (int pow = 1; pow < maxp; pow++) {\n if (pow == 1) a[len][pow] += p2;\n if (pow == 2) {\n a[len][pow] += p4;\n b[len][pow] += p4;\n }\n a[len][pow] += a[len-1][pow-1] * a[len][pow-1];\n b[len][pow] += a[len-1][pow-1] * b[len][pow-1];\n }\n }\n for (int len = maxp - 1; len >= 1; len--) {\n for (int pow = 1; pow < maxp; pow++) {\n a[len][pow] *= 1 - a[len-1][pow];\n b[len][pow] *= 1 - a[len-1][pow];\n }\n }\n \n // value of a slime that has been merged i times\n long[] vals = new long[maxp];\n for (int i = 0; i < maxp; i++) vals[i] = i;//1l << i;\n // manually do first few cases\n int maxn = 1000;\n double[][] dp = new double[maxn][maxp];\n double[][] sum = new double[maxn][maxp];\n for (int cur = 1; cur < maxp; cur++)\n dp[maxn-1][cur] = vals[cur];\n \n // manual dp\n for (int i = maxn-2; i >= 0; i--) {\n for (int cur = 1; cur < maxp; cur++) {\n for (int next = 1; next < maxp; next++) {\n if (cur == next) continue;\n if (cur == 1) {\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += b[id][next] * dp[i+1][next];\n sum[i][cur] += b[id][next];\n } else {\n if (cur < next) continue;\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += a[id][next] * dp[i+1][next];\n sum[i][cur] += a[id][next];\n }\n }\n }\n for (int cur = 1; cur < maxp; cur++) {\n dp[i][cur] = vals[cur] + dp[i][cur] / sum[i][cur];\n }\n }\n if (n <= maxn) {\n int k = (int)n;\n int w = Math.min(maxp-1, k);\n double exp = 0;\n for (int i = 1; i < maxp; i++) {\n exp += a[w][i] * dp[maxn-k][i];\n }\n out.printf(\"%.15f\\n\", exp);\n out.close();\n System.exit(0);\n }\n\n double exp1 = 0;\n double exp2 = 0;\n for (int i = 1; i < maxp; i++) {\n exp1 += a[maxp-1][i] * dp[0][i];\n exp2 += a[maxp-1][i] * dp[1][i];\n }\n out.printf(\"%.15f\\n\", exp2 + (exp1 - exp2) * (long)(n - maxn + 1));\n out.close();\n System.exit(0);\n }\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8024d3566a3b4c1bd81df651ad7efe82", "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class SlimeCombiningLinear {\n private static InputReader in;\n private static PrintWriter out;\n public static double EPS = 1e-15;\n public static int maxp = 50;\n \n public static void main (String[] args) {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n \n int n = in.nextInt();\n int p = in.nextInt();\n \n double p2 = p / 1000000000., p4 = 1 - p2;\n double[][] a = new double[maxp][maxp];\n double[][] b = new double[maxp][maxp];\n for (int len = 1; len < maxp; len++) { \n for (int pow = 1; pow < maxp; pow++) {\n if (pow == 1) a[len][pow] += p2;\n if (pow == 2) {\n a[len][pow] += p4;\n b[len][pow] += p4;\n }\n a[len][pow] += a[len-1][pow-1] * a[len][pow-1];\n b[len][pow] += a[len-1][pow-1] * b[len][pow-1];\n }\n }\n for (int len = maxp - 1; len >= 1; len--) {\n for (int pow = 1; pow < maxp; pow++) {\n a[len][pow] *= 1 - a[len-1][pow];\n b[len][pow] *= 1 - a[len-1][pow];\n }\n }\n \n // value of a slime that has been merged i times\n long[] vals = new long[maxp];\n for (int i = 0; i < maxp; i++) vals[i] = i;//1l << i;\n // manually do first few cases\n int maxn = 1000;\n double[][] dp = new double[maxn][maxp];\n double[][] sum = new double[maxn][maxp];\n for (int cur = 1; cur < maxp; cur++)\n dp[maxn-1][cur] = vals[cur];\n \n // manual dp\n for (int i = maxn-2; i >= 0; i--) {\n for (int cur = 1; cur < maxp; cur++) {\n for (int next = 1; next < maxp; next++) {\n if (cur == next) continue;\n if (cur == 1) {\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += b[id][next] * dp[i+1][next];\n sum[i][cur] += b[id][next];\n } else {\n if (cur < next) continue;\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += a[id][next] * dp[i+1][next];\n sum[i][cur] += a[id][next];\n }\n }\n }\n for (int cur = 1; cur < maxp; cur++) {\n dp[i][cur] = vals[cur] + dp[i][cur] / sum[i][cur];\n }\n }\n if (n <= maxn) {\n int k = (int)n;\n int w = Math.min(maxp-1, k);\n double exp = 0;\n for (int i = 1; i < maxp; i++) {\n exp += a[w][i] * dp[maxn-k][i];\n }\n out.printf(\"%.15f\\n\", exp);\n out.close();\n System.exit(0);\n }\n\n double exp1 = 0;\n double exp2 = 0;\n for (int i = 1; i < maxp; i++) {\n exp1 += a[maxp-1][i] * dp[0][i];\n exp2 += a[maxp-1][i] * dp[1][i];\n }\n out.printf(\"%.15f\\n\", exp2 + (exp1 - exp2) * (long)(n - maxn + 1));\n out.close();\n System.exit(0);\n }\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65049c63467d32863d28bc6697063d58", "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStreamReader;\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 Niyaz Nigmatullin\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 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, FastScanner in, FastPrinter out) {\n// Random rng = new Random(12323L);\n// for (int tt = 0; tt < 7; tt++) {\n// int n = rng.nextInt(2) + 77;\n// HeroesSmart a = new HeroesSmart(n);\n// HeroesStupid b = new HeroesStupid(n);\n// for (int it = 0; it < 10000; it++) {\n// if (rng.nextBoolean()) {\n// int add = rng.nextInt(10) + 1;\n// int l = rng.nextInt(n);\n// int r = rng.nextInt(n - l) + l + 1;\n// a.add(l, r, add);\n// b.add(l, r, add);\n// System.out.println(l + \" \" + r + \" \" + add);\n// } else {\n// int l = rng.nextInt(n - 1) / 2 * 2 + 1;\n// int r = rng.nextInt(n - l) + l + 1;\n// boolean ans1 = a.canBeat(l, r);\n// boolean ans2 = b.canBeat(l, r);\n// if (ans1 != ans2) {\n// throw new AssertionError();\n// }\n// }\n// }\n// }\n int n = in.nextInt();\n// HeroesStupid real = new HeroesStupid(n);\n// HeroesStupid plusOne = new HeroesStupid(n + 1);\n TaskF.HeroesSmart real = new TaskF.HeroesSmart(n);\n TaskF.HeroesSmart plusOne = new TaskF.HeroesSmart(n + 1);\n for (int i = 0; i < n; i++) {\n int x = in.nextInt();\n real.add(i, i + 1, x);\n plusOne.add(i + 1, i + 2, x);\n }\n int m = in.nextInt();\n for (int i = 0; i < m; i++) {\n int op = in.nextInt();\n if (op == 2) {\n int l = in.nextInt();\n int r = in.nextInt() + 1;\n boolean ans;\n if ((l & 1) == 1) {\n ans = real.canBeat(l, r);\n } else {\n ans = plusOne.canBeat(l + 1, r + 1);\n }\n out.println(ans ? 1 : 0);\n } else {\n int l = in.nextInt();\n int r = in.nextInt() + 1;\n int k = in.nextInt();\n real.add(l, r, k);\n plusOne.add(l + 1, r + 1, k);\n }\n }\n }\n\n static class HeroesSmart {\n MultiSegmentTree all;\n MultiSegmentTree even;\n MultiSegmentTree odd;\n int pairs;\n\n HeroesSmart(int n) {\n all = new MultiSegmentTree(n + 1);\n pairs = (n + 1) / 2 + 1;\n even = new MultiSegmentTree(pairs);\n odd = new MultiSegmentTree(pairs);\n }\n\n void add(int l, int r, int k) {\n all.add(l, r, k);\n if ((l & 1) == 1) {\n odd.add(l / 2, pairs, k);\n } else {\n even.add(l / 2, pairs, k);\n }\n if ((r & 1) == 1) {\n odd.add(r / 2, pairs, -k);\n } else {\n even.add(r / 2, pairs, -k);\n }\n }\n\n boolean canBeat(int l, int r) { // [l, r)\n if ((l & 1) == 1) {\n long evenMin = even.getMin((l + 1) / 2, (r - 1) / 2 + 1);\n if (l > 0) {\n evenMin -= even.getSum((l - 1) / 2, (l - 1) / 2 + 1);\n }\n long oddMin = odd.getMin(l / 2, (r - 2) / 2 + 1) - odd.getSum(l / 2, l / 2 + 1) + all.getSum(l, l + 1) - 1;\n if (evenMin < 0 || oddMin < 0) {\n return false;\n }\n if ((r & 1) == 0) {\n return odd.getSum((r - 2) / 2, (r - 2) / 2 + 1) - odd.getSum(l / 2, l / 2 + 1) + all.getSum(l, l + 1) - 1 == 0;\n } else {\n return even.getSum((r - 1) / 2, (r - 1) / 2 + 1) - (l > 0 ? even.getSum((l - 1) / 2, (l - 1) / 2 + 1) : 0) == 0;\n }\n }\n throw new AssertionError();\n }\n\n }\n\n }\n\n static class FastScanner extends BufferedReader {\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n\n public int read() {\n try {\n int ret = super.read();\n// if (isEOF && ret < 0) {\n// throw new InputMismatchException();\n// }\n// isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n }\n\n static class MultiSegmentTree {\n private long[] min;\n private long[] max;\n private long[] sum;\n private long[] add;\n private long[] set;\n private boolean[] toSet;\n private int[] count;\n final int n;\n\n public MultiSegmentTree(int n) {\n this.n = Integer.highestOneBit(n) << 1;\n min = new long[this.n << 1];\n max = new long[this.n << 1];\n sum = new long[this.n << 1];\n add = new long[this.n << 1];\n set = new long[this.n << 1];\n count = new int[this.n << 1];\n toSet = new boolean[this.n << 1];\n count(0, 0, this.n);\n }\n\n private int count(int node, int l, int r) {\n if (l == r - 1) {\n count[node] = 1;\n return 1;\n }\n int m = (l + r) >> 1;\n return count[node] = count((node << 1) | 1, l, m)\n + count((node << 1) + 2, m, r);\n }\n\n private void add(int node, long x) {\n if (toSet[node]) {\n set[node] += x;\n } else {\n add[node] += x;\n }\n }\n\n private void set(int node, long x) {\n add[node] = 0;\n set[node] = x;\n toSet[node] = true;\n }\n\n private void relax(int node) {\n if (!toSet[node] && add[node] == 0) {\n return;\n }\n min[node] = getMin(node);\n max[node] = getMax(node);\n sum[node] = getSum(node);\n if (toSet[node]) {\n set((node << 1) | 1, set[node]);\n set((node << 1) + 2, set[node]);\n toSet[node] = false;\n } else {\n add((node << 1) | 1, add[node]);\n add((node << 1) + 2, add[node]);\n add[node] = 0;\n }\n }\n\n private long getSum(int node) {\n return toSet[node] ? set[node] * count(node) : sum[node]\n + add[node] * count(node);\n }\n\n private long count(int node) {\n return count[node];\n }\n\n private long getMax(int node) {\n return toSet[node] ? set[node] : max[node] + add[node];\n }\n\n private long getMin(int node) {\n return toSet[node] ? set[node] : min[node] + add[node];\n }\n\n private void add(int node, int l, int r, int left, int right, long x) {\n if (right <= l || r <= left) {\n return;\n }\n if (left <= l && r <= right) {\n add(node, x);\n return;\n }\n relax(node);\n int m = (l + r) >> 1;\n add((node << 1) | 1, l, m, left, right, x);\n add((node << 1) + 2, m, r, left, right, x);\n min[node] = Math.min(getMin((node << 1) | 1),\n getMin((node << 1) + 2));\n max[node] = Math.max(getMax((node << 1) | 1),\n getMax((node << 1) + 2));\n sum[node] = getSum((node << 1) | 1) + getSum((node << 1) + 2);\n }\n\n private long getMin(int node, int l, int r, int left, int right) {\n if (right <= l || r <= left) {\n return Long.MAX_VALUE;\n }\n if (left <= l && r <= right) {\n return getMin(node);\n }\n relax(node);\n int m = (l + r) >> 1;\n return Math.min(getMin((node << 1) | 1, l, m, left, right),\n getMin((node << 1) + 2, m, r, left, right));\n }\n\n private long getSum(int node, int l, int r, int left, int right) {\n if (right <= l || r <= left) {\n return 0;\n }\n if (left <= l && r <= right) {\n return getSum(node);\n }\n relax(node);\n int m = (l + r) >> 1;\n return getSum((node << 1) | 1, l, m, left, right)\n + getSum((node << 1) + 2, m, r, left, right);\n }\n\n public void add(int l, int r, long x) {\n if (l >= r) {\n return;\n }\n add(0, 0, n, l, r, x);\n }\n\n public long getSum(int l, int r) {\n if (l >= r) {\n return 0;\n }\n return getSum(0, 0, n, l, r);\n }\n\n public long getMin(int l, int r) {\n if (l >= r) {\n return Long.MAX_VALUE;\n }\n return getMin(0, 0, n, l, r);\n }\n\n }\n\n static class FastPrinter extends PrintWriter {\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public FastPrinter(Writer out) {\n super(out);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c506635fd055d52932d47251173e388", "src_uid": "a17833a733d59936d1c3ba5f27b0cbe0", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStreamReader;\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 Niyaz Nigmatullin\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 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, FastScanner in, FastPrinter out) {\n// Random rng = new Random(12323L);\n// for (int tt = 0; tt < 7; tt++) {\n// int n = rng.nextInt(2) + 77;\n// HeroesSmart a = new HeroesSmart(n);\n// HeroesStupid b = new HeroesStupid(n);\n// for (int it = 0; it < 10000; it++) {\n// if (rng.nextBoolean()) {\n// int add = rng.nextInt(10) + 1;\n// int l = rng.nextInt(n);\n// int r = rng.nextInt(n - l) + l + 1;\n// a.add(l, r, add);\n// b.add(l, r, add);\n// System.out.println(l + \" \" + r + \" \" + add);\n// } else {\n// int l = rng.nextInt(n - 1) / 2 * 2 + 1;\n// int r = rng.nextInt(n - l) + l + 1;\n// boolean ans1 = a.canBeat(l, r);\n// boolean ans2 = b.canBeat(l, r);\n// if (ans1 != ans2) {\n// System.out.println(l + \" \" + r);\n// throw new AssertionError();\n// }\n// }\n// }\n// }\n int n = in.nextInt();\n// HeroesStupid real = new HeroesStupid(n);\n// HeroesStupid plusOne = new HeroesStupid(n + 1);\n TaskF.HeroesSmart real = new TaskF.HeroesSmart(n);\n TaskF.HeroesSmart plusOne = new TaskF.HeroesSmart(n + 1);\n for (int i = 0; i < n; i++) {\n int x = in.nextInt();\n real.add(i, i + 1, x);\n plusOne.add(i + 1, i + 2, x);\n }\n int m = in.nextInt();\n for (int i = 0; i < m; i++) {\n int op = in.nextInt();\n if (op == 2) {\n int l = in.nextInt();\n int r = in.nextInt() + 1;\n boolean ans;\n if ((l & 1) == 1) {\n ans = real.canBeat(l, r);\n } else {\n ans = plusOne.canBeat(l + 1, r + 1);\n }\n out.println(ans ? 1 : 0);\n } else {\n int l = in.nextInt();\n int r = in.nextInt() + 1;\n int k = in.nextInt();\n real.add(l, r, k);\n plusOne.add(l + 1, r + 1, k);\n }\n }\n }\n\n static class HeroesSmart {\n FenwickRev all;\n TaskF.MultiSegmentTree even;\n TaskF.MultiSegmentTree odd;\n int pairs;\n\n HeroesSmart(int n) {\n all = new FenwickRev(n);\n pairs = (n + 1) / 2 + 1;\n even = new TaskF.MultiSegmentTree(pairs);\n odd = new TaskF.MultiSegmentTree(pairs);\n }\n\n void add(int l, int r, int k) {\n all.add(l, r, k);\n if ((l & 1) == 1) {\n odd.add(l / 2, pairs, k);\n } else {\n even.add(l / 2, pairs, k);\n }\n if ((r & 1) == 1) {\n odd.add(r / 2, pairs, -k);\n } else {\n even.add(r / 2, pairs, -k);\n }\n }\n\n boolean canBeat(int l, int r) { // [l, r)\n if ((l & 1) == 1) {\n long evenMin = even.getMin((l + 1) / 2, (r - 1) / 2 + 1);\n long sumEvenFirst = l == 0 ? 0 : even.getMin((l - 1) / 2, (l - 1) / 2 + 1);\n evenMin -= sumEvenFirst;\n long sumFirst = odd.getMin(l / 2, l / 2 + 1);\n int valFirst = all.getElement(l);\n long oddMin = odd.getMin(l / 2, (r - 2) / 2 + 1) - sumFirst + valFirst - 1;\n if (evenMin < 0 || oddMin < 0) {\n return false;\n }\n if ((r & 1) == 0) {\n return odd.getMin((r - 2) / 2, (r - 2) / 2 + 1) - sumFirst + valFirst - 1 == 0;\n } else {\n return even.getMin((r - 1) / 2, (r - 1) / 2 + 1) - sumEvenFirst == 0;\n }\n }\n throw new AssertionError();\n }\n\n }\n\n static class MultiSegmentTree {\n private long[] min;\n private long[] add;\n final int n;\n\n public MultiSegmentTree(int n) {\n this.n = Integer.highestOneBit(n) << 1;\n min = new long[this.n << 1];\n add = new long[this.n << 1];\n }\n\n private void add(int node, long x) {\n add[node] += x;\n }\n\n private void relax(int node) {\n if (add[node] == 0) {\n return;\n }\n min[node] = getMin(node);\n add((node << 1) | 1, add[node]);\n add((node << 1) + 2, add[node]);\n add[node] = 0;\n }\n\n private long getMin(int node) {\n return min[node] + add[node];\n }\n\n private void add(int node, int l, int r, int left, int right, long x) {\n if (right <= l || r <= left) {\n return;\n }\n if (left <= l && r <= right) {\n add(node, x);\n return;\n }\n relax(node);\n int m = (l + r) >> 1;\n add((node << 1) | 1, l, m, left, right, x);\n add((node << 1) + 2, m, r, left, right, x);\n min[node] = Math.min(getMin((node << 1) | 1),\n getMin((node << 1) + 2));\n }\n\n private long getMin(int node, int l, int r, int left, int right) {\n if (right <= l || r <= left) {\n return Long.MAX_VALUE;\n }\n if (left <= l && r <= right) {\n return getMin(node);\n }\n relax(node);\n int m = (l + r) >> 1;\n return Math.min(getMin((node << 1) | 1, l, m, left, right),\n getMin((node << 1) + 2, m, r, left, right));\n }\n\n public void add(int l, int r, long x) {\n if (l >= r) {\n return;\n }\n add(0, 0, n, l, r, x);\n }\n\n public long getMin(int l, int r) {\n if (l >= r) {\n return Long.MAX_VALUE;\n }\n return getMin(0, 0, n, l, r);\n }\n\n }\n\n }\n\n static class FastScanner extends BufferedReader {\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n\n public int read() {\n try {\n int ret = super.read();\n// if (isEOF && ret < 0) {\n// throw new InputMismatchException();\n// }\n// isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n }\n\n static class FenwickRev {\n int[] a;\n\n public FenwickRev(int n) {\n a = new int[n];\n }\n\n public void add(int x, int y) {\n for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {\n a[i] += y;\n }\n }\n\n public int getElement(int x) {\n int ret = 0;\n for (int i = x; i < a.length; i |= i + 1) {\n ret += a[i];\n }\n return ret;\n }\n\n public void add(int left, int right, int y) {\n add(left - 1, -y);\n add(right - 1, y);\n }\n\n }\n\n static class FastPrinter extends PrintWriter {\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public FastPrinter(Writer out) {\n super(out);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6c0f49600e1c7c17d20a18f01d1ec69e", "src_uid": "a17833a733d59936d1c3ba5f27b0cbe0", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.InputStream;\n\npublic class Solution {\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 PrintWriter out = new PrintWriter(outputStream);\n\n Task solver = new Task();\n solver.solve(in, out);\n\n out.close();\n }\n}\n\n/*\n * Solution\n */\n\n\nclass Task {\n\n private final static int N = 20;\n\n public void solve(InputReader in, PrintWriter out) {\n\n int n = in.nextInt();\n String[] s = new String[n];\n for (int i = 0; i < n; i++) {\n s[i] = new String(in.next());\n }\n\n int m = s[0].length();\n long[] d = new long[(1 << N)];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if(i == j) continue;\n\n int mask = 0;\n for (int pos = 0; pos < m; pos++) {\n if(s[i].charAt(pos) == s[j].charAt(pos)) {\n mask |= (1 << pos);\n }\n }\n d[mask] |= (1L << i);\n }\n }\n\n \n for(int i = 0; i < m; i++){\n for(int pos = 0; pos < (1 << m) ; pos++){\n d[pos] |= d[pos|(1 << i)];\n }\n }\n\n int[] sum = new int[(1 << m)];\n for(int k = 0;k < (1 << m); k++){\n sum[k] = Long.bitCount(d[k]);\n }\n\n double[] f = new double[60];\n f[0] = 1;\n for(int i = 1;i < 60;i++)\n f[i] = f[i-1] * i;\n\n double[] ps = new double[m];\n for(int k = 0;k < m;k++){\n ps[k] = f[k] * f[m-1-k] / f[m];\n }\n\n double ans = 0;\n for(int i = 0; i < (1 << m); i++) {\n int k = Integer.bitCount(i);\n for(int j = 0; j < m; j++){\n if( i << ~j < 0){\n ans += k * ps[k-1] * (sum[i^1<= 0; i--) {\n for (int j = 0; j < m; j++) {\n d1[i] |= d1[i | (1 << j)];\n }\n }\n double[] d = new double[1 << m];\n d[0] = 1;\n for (int mask = 0; mask < (1 << m); mask++) {\n double bc = Integer.bitCount(mask);\n int bc1 = Long.bitCount(d1[mask]);\n if (bc1 == 0) {\n continue;\n }\n for (int i = 0; i < m; i++) {\n if ((mask & (1 << i)) == 0) {\n int nmask = mask | (1 << i);\n double nbc1 = Long.bitCount(d1[nmask]);\n d[nmask] += d[mask] * (nbc1 / bc1) / (m - bc);\n }\n }\n }\n double ans = 0;\n for (int mask = 0; mask < (1 << m); mask++) {\n double finish = 0;\n int bc1 = Long.bitCount(d1[mask]);\n int bc = Long.bitCount(mask);\n for (int i = 0; i < m; i++) {\n if ((mask & (1 << i)) > 0) {\n int nmask = mask & ~(1 << i);\n int nbc1 = Long.bitCount(d1[nmask]);\n if (nbc1 == 0) {\n continue;\n }\n int nbc = Long.bitCount(nmask);\n finish += d[nmask] * (nbc1 - bc1) / nbc1 / (m - nbc);\n }\n }\n ans += bc * finish;\n }\n printf(\"%.11f\", ans);\n }\n\n public void run() {\n try {\n solve();\n close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(abs(-1));\n }\n }\n\n Main() throws IOException {\n super(System.out);\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n\n Main(String s) throws IOException {\n super(\"\".equals(s) ? \"output.txt\" : (s + \".out\"));\n in = new BufferedReader(new FileReader(\"\".equals(s) ? \"input.txt\" : (s + \".in\")));\n }\n\n public static void main(String[] args) throws IOException {\n try {\n Locale.setDefault(Locale.US);\n } catch (Exception ignored) {\n }\n new Main().run();\n }\n\n String next() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null) {\n return null;\n }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n int[] nextIntArray(int len) throws IOException {\n int[] a = new int[len];\n for (int i = 0; i < len; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n void shuffle(int[] a) {\n for (int i = 1; i < a.length; i++) {\n int x = rand.nextInt(i + 1);\n int t = a[i];\n a[i] = a[x];\n a[x] = t;\n }\n }\n\n boolean nextPerm(int[] p) {\n for (int a = p.length - 2; a >= 0; --a)\n if (p[a] < p[a + 1])\n for (int b = p.length - 1; ; --b)\n if (p[b] > p[a]) {\n int t = p[a];\n p[a] = p[b];\n p[b] = t;\n for (++a, b = p.length - 1; a < b; ++a, --b) {\n t = p[a];\n p[a] = p[b];\n p[b] = t;\n }\n return true;\n }\n return false;\n }\n\n List[] createAdjacencyList(int countVertex) {\n List[] res = new List[countVertex];\n for (int i = 0; i < countVertex; i++) {\n res[i] = new ArrayList();\n }\n return res;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e8b3e927df22dcc350b399159b0df264", "src_uid": "a95d9aef6a64c30e46330dcc8e6d4a67", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main extends PrintWriter {\n BufferedReader in;\n StringTokenizer stok;\n final Random rand = new Random(31);\n final int inf = (int) 1e9;\n final long linf = (long) 1e18;\n\n public void solve() throws IOException {\n int n = nextInt();\n char[][] a = new char[n][];\n for (int i = 0; i < n; i++) {\n a[i] = next().toCharArray();\n }\n int m = a[0].length;\n long[] d1 = new long[1 << m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i != j) {\n int x = 0;\n for (int k = 0; k < m; k++) {\n if (a[i][k] == a[j][k]) {\n x |= (1 << k);\n }\n }\n d1[x] |= (1 << i);\n d1[x] |= (1 << j);\n }\n }\n }\n for (int i = (1 << m) - 1; i >= 0; i--) {\n for (int j = 0; j < m; j++) {\n d1[i] |= d1[i | (1 << j)];\n }\n }\n double[] d = new double[1 << m];\n d[0] = 1;\n for (int mask = 0; mask < (1 << m); mask++) {\n double bc = Integer.bitCount(mask);\n double bc1 = Long.bitCount(d1[mask]);\n for (int i = 0; i < m; i++) {\n if ((mask & (1 << i)) == 0) {\n int nmask = mask | (1 << i);\n d[nmask] += d[mask] * (bc1 / n) / (m - bc);\n }\n }\n }\n double ans = 0;\n for (int mask = 0; mask < (1 << m); mask++) {\n int t = n - Long.bitCount(d1[mask]);\n ans += Integer.bitCount(mask) * d[mask] * t / n;\n }\n printf(\"%.11f\", ans);\n }\n\n public void run() {\n try {\n solve();\n close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(abs(-1));\n }\n }\n\n Main() throws IOException {\n super(System.out);\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n\n Main(String s) throws IOException {\n super(\"\".equals(s) ? \"output.txt\" : (s + \".out\"));\n in = new BufferedReader(new FileReader(\"\".equals(s) ? \"input.txt\" : (s + \".in\")));\n }\n\n public static void main(String[] args) throws IOException {\n try {\n Locale.setDefault(Locale.US);\n } catch (Exception ignored) {\n }\n new Main().run();\n }\n\n String next() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null) {\n return null;\n }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n int[] nextIntArray(int len) throws IOException {\n int[] a = new int[len];\n for (int i = 0; i < len; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n void shuffle(int[] a) {\n for (int i = 1; i < a.length; i++) {\n int x = rand.nextInt(i + 1);\n int t = a[i];\n a[i] = a[x];\n a[x] = t;\n }\n }\n\n boolean nextPerm(int[] p) {\n for (int a = p.length - 2; a >= 0; --a)\n if (p[a] < p[a + 1])\n for (int b = p.length - 1; ; --b)\n if (p[b] > p[a]) {\n int t = p[a];\n p[a] = p[b];\n p[b] = t;\n for (++a, b = p.length - 1; a < b; ++a, --b) {\n t = p[a];\n p[a] = p[b];\n p[b] = t;\n }\n return true;\n }\n return false;\n }\n\n List[] createAdjacencyList(int countVertex) {\n List[] res = new List[countVertex];\n for (int i = 0; i < countVertex; i++) {\n res[i] = new ArrayList();\n }\n return res;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b8fae8d0a7c1c5645c784126e42b328b", "src_uid": "a95d9aef6a64c30e46330dcc8e6d4a67", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\npublic class Main {\n\tstatic int mod = (int)1e9+7;\n\tstatic int N = 20;\n\tint n, y, m;\n\tint[] seat = new int[N], u = new int[N], v = new int[N];\n\tlong[] num = new long[1<<16];\n\tint pos(int state,int k){\n\t return (state >> k) & 1;\n\t}\n\tint find(int state){\n\t for(int i = 0;i < n;i++)\n\t if(pos(state,i) != 0) return i + 1;\n\t return -1;\n\t}\n\tlong dfs(int state, int k){\n\t int i;\n\t if(num[state] > -1) return num[state];\n\t if(k == n) return num[state] = 1;\n\t num[state] = 0;\n\t for(i = 0;i < n;i++)\n\t if(pos(state,i) == 0 && (state & seat[i]) == 0 && pos(v[k],i) != 0 && pos(u[i],k) != 0)\n\t num[state] += dfs(state | (1 << i),k + 1);\n\t return num[state];\n\t}\n void work() throws Exception {\n \t//in = new BufferedReader(new InputStreamReader(System.in));\n \tout = new PrintWriter(System.out);\n \t//\n \tScanner cin = new Scanner(System.in);\n \t/////////////////////////////////////////\n \twhile(cin.hasNext()) {\n \t\tn = cin.nextInt();\n \t\ty = cin.nextInt();\n \t\tm = cin.nextInt();\n \t\t\n \t\tArrays.fill(seat, 0);\n \t\tfor(int i = 1; i <= m; i ++) {\n \t\t\tint a = cin.nextInt();\n \t\t\tint b = cin.nextInt();\n \t\t\tseat[a-1] |= 1<<(b-1);\n \t\t}\n \t\t\n \t\tm = (1<{\n \tint first, second;\n \tpair(int x, int y) {\n \t\tfirst = x;\n \t\tsecond = y;\n \t}\n\t\tpublic int compareTo(pair o) {\n\t\t\t// TODO auto-generated method stub\n\t\t\tif(first != o.first) return ((Integer)first).compareTo(o.first);\n\t\t\telse return ((Integer)second).compareTo(o.second); \n\t\t}\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3fb69fb77751895745bd6e45ceda813b", "src_uid": "e9db8d048e9763cf38c584342dea9f53", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.util.Arrays;\nimport java.util.Scanner;\n/**\n * Date : 02.01.2012\n * Time : 21:00:42\n * Email : denys.astanin@gmail.com\n */\n\npublic class s83_e {\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew s83_e().run();\n\t}\n\n\n\tWriter writer;\n\tReader reader;\n\tScanner sc;\n\tvoid run() throws IOException {\n\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\treader = oj ? new InputStreamReader(System.in, \"ISO-8859-1\")\n\t\t\t\t: new FileReader(\"input/is83_e.txt\");\n\t\twriter = new OutputStreamWriter(System.out, \"ISO-8859-1\");\n\t\t\n\t\tsc = new Scanner(new BufferedReader(reader));\n\t\tPrintWriter out = new PrintWriter(writer);\n\t\tint n = sc.nextInt() ;\n\t\tlong y = sc.nextLong() - 2001;\n\t\tint m = sc.nextInt();\n\t\t\n\t\tint[] restrictions = new int[n];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint a = sc.nextInt() - 1;\n\t\t\tint b = sc.nextInt() - 1;\n\t\t\trestrictions[b] |= 1 << a;\n\t\t}\n\t\t\n\t\tint[] prefix = new int[n];\n\t\tArrays.fill(prefix, Integer.MIN_VALUE);\n\t\t\n\t\tboolean halt = false;\n\t\tcycle : for (int k = 0; k < n; k++) {\n\t\t\twhile (true) {\n\t\t\t\tif (prefix[k] == Integer.MIN_VALUE) {\n\t\t\t\t\tprefix[k] = 0;\n\t\t\t\t} else {\n\t\t\t\t\tprefix[k]++;\n\t\t\t\t}\n\t\t\t\tif (prefix[k] == n) {\n\t\t\t\t\thalt = true;\n\t\t\t\t\tout.println(\"The times have changed\");\n\t\t\t\t\tbreak cycle;\n\t\t\t\t}\n\t\t\t\tlong[] dp = new long[1 << (prefix.length)];\n\t\t\t\tdp[0] = 1;\n\t\t\t\tfor (int i = 0; i < 1 << (prefix.length); i++) {\n\t\t\t\t\tint count = Integer.bitCount(i);\n\t\t\t\t\tfor (int j = 0; j < (prefix.length); j++) {\n\t\t\t\t\t\tif ((prefix[j] == Integer.MIN_VALUE || prefix[j] == count)\n\t\t\t\t\t\t\t\t&& (i & (1 << j)) == 0\n\t\t\t\t\t\t\t\t&& (i & restrictions[j]) == restrictions[j]) {\n\t\t\t\t\t\t\tdp[i | (1 << j)] += dp[i];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (dp[(1 << (prefix.length)) - 1] > y) {\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\ty -= dp[(1 << (prefix.length)) - 1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!halt) {\n\t\t\tfor (int i = 0; i < prefix.length; i++) {\n\t\t\t\tout.print((prefix[i] + 1) + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1735f34b9d7e56afab7945e1e1c12906", "src_uid": "e9db8d048e9763cf38c584342dea9f53", "difficulty": 2400.0} {"lang": "Java 8", "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 = 20;\n int n, m;\n long y;\n int[] seat = new int[N], u = new int[N], v = new int[N];\n long[] num = new long[1<<16];\n int pos(int state,int k){\n return (state >> k) & 1;\n }\n int find(int state){\n for(int i = 0;i < n;i++)\n if(pos(state,i) != 0) return i + 1;\n return -1;\n }\n long dfs(int state, int k){\n int i;\n if(num[state] > -1) return num[state];\n if(k == n) return num[state] = 1;\n num[state] = 0;\n for(i = 0;i < n;i++)\n if(pos(state,i) == 0 && (state & seat[i]) == 0 && pos(v[k],i) != 0 && pos(u[i],k) != 0)\n num[state] += dfs(state | (1 << i),k + 1);\n return num[state];\n }\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 while(cin.hasNext()) {\n n = cin.nextInt();\n y = cin.nextLong();\n m = cin.nextInt();\n \n Arrays.fill(seat, 0);\n for(int i = 1; i <= m; i ++) {\n int a = cin.nextInt();\n int b = cin.nextInt();\n seat[a-1] |= 1<<(b-1);\n }\n \n m = (1<{\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "84780799fc31c313184636010f0c2ac3", "src_uid": "e9db8d048e9763cf38c584342dea9f53", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\n\npublic class ProblemE {\n static int N;\n static long Y;\n static long ycnt;\n static int[] place;\n static boolean[][] invalidGraph;\n static boolean[][] rules;\n\n private static long cnt2(int now) {\n int[] parray = new int[N];\n int[] map = new int[N];\n Arrays.fill(map, -1);\n int pidx = 0;\n for (int i = 0 ; i < N ; i++) {\n if (place[i] != -1) {\n map[place[i]] = i;\n } else {\n parray[pidx++] = i;\n }\n }\n \n for (int i = 0 ; i < now ; i++) {\n for (int j = i+1 ; j < now ; j++) {\n int young = -1;\n int old = -1;\n if (map[i] < map[j]) {\n young = j;\n old = i;\n } else {\n old = j;\n young = i;\n }\n if (invalidGraph[young][old]) {\n return 0;\n }\n }\n }\n \n \n \n long[][] dp = new long[pidx+1][1<= 1) {\n continue;\n }\n \n boolean isok = true;\n \n // check one : with already placed\n for (int prev = 0 ; prev < now ; prev++) {\n int young = -1;\n int old = -1;\n if (map[prev] < parray[i]) {\n young = next;\n old = prev;\n } else {\n young = prev;\n old = next;\n }\n if (invalidGraph[young][old]) {\n isok = false;\n break;\n }\n }\n \n // check two : with dp placed\n for (int prev = now ; prev < N ; prev++) {\n if ((ptn & (1<= 1) {\n int old = prev;\n int young = next;\n if (invalidGraph[young][old]) {\n isok = false;\n break;\n }\n }\n }\n \n if (isok) {\n int nptn = ptn | (1<= Y) {\n dfs(now+1);\n break;\n }\n ycnt += dcnt;\n place[i] = -1;\n }\n }\n }\n \n public static void main(String[] args) throws IOException {\n BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n String[] line = s.readLine().split(\" \");\n int n = Integer.valueOf(line[0]);\n long y = Long.valueOf(line[1]) - 2000;\n int m = Integer.valueOf(line[2]);\n \n invalidGraph = new boolean[n][n];\n for (int i = 0 ; i < m ; i++) {\n String[] data = s.readLine().split(\" \");\n int senior = Integer.valueOf(data[0])-1;\n int junior = Integer.valueOf(data[1])-1;\n invalidGraph[senior][junior] = true;\n }\n \n N = n;\n Y = y;\n ycnt = 0;\n place = new int[N];\n Arrays.fill(place, -1);\n \n dfs(0);\n\n if (place[0] == -1) {\n System.out.println(\"The times have changed\");\n return;\n } else {\n int[] map = new int[N];\n for (int i = 0 ; i < n ; i++) {\n map[place[i]] = i;\n }\n \n StringBuffer b = new StringBuffer();\n for (int i = 0 ; i < n ; i++) {\n b.append(map[i]+1).append(\" \");\n }\n System.out.println(b.substring(0, b.length()-1));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c97d8942553c2e4e3954a935663f7137", "src_uid": "e9db8d048e9763cf38c584342dea9f53", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "public class Main{\n public static void main(String[] args)\n {\n System.out.println(\"0\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n1\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2f6789f8d483402215a5ff22dec7c214", "src_uid": "4bda04e64ff661336a93464563f1b550", "difficulty": null} {"lang": "Java 8", "source_code": "public class Main{\n public static void main(String[] args)\n {\n System.out.println(0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"++\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "785e145a1e4b2d11c4226b2cd043eb24", "src_uid": "4bda04e64ff661336a93464563f1b550", "difficulty": null} {"lang": "Java 8", "source_code": "public class CodeForces1April2019E {\n public static void main(String[] args) {\n for (int i = 21; i < 51; i++) {\n System.out.println(((Math.min(i, 25) + i) % (2 + i % 3)) > 0 ? 1 : 0);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fb97bea9bb6dac6e82c73abd91339ea5", "src_uid": "4bda04e64ff661336a93464563f1b550", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n public class Main{\n public static void main(String[] args)\n {\n System.out.println(0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+0+\"\\n\"+1+\"\\n\"+1+\"\\n\"+1);\n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "35348cdfaa78cc411e1ed06184d30f5f", "src_uid": "4bda04e64ff661336a93464563f1b550", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class CFD {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner5 in = new FastScanner5();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i b = new ArrayList();\n\t\tb.add(new Block(a[0], 1));\n\t\tfor (int i = 1; i last = new ArrayList();\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t\tcnt[a[i]]++;\n\t\t\t\n\t\t\tif (!(last.size() > 0 && last.get(last.size() - 1) == a[i])){\n\t\t\t\tif (a[i] != 0){\n\t\t\t\t\tlast.add(a[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint cur = 0;\n\t\tlong ans = 0;\n\t\t\n\t\tfor (int i : last) {\n\t\t\tcur += cnt[i];\n\t\t\t\n\t\t\tint open = 0;\n\t\t\t\n\t\t\tfor (int j = cur - cnt[i]; j < cur; j++) {\n\t\t\t\tif (a[j] == 0){\n\t\t\t\t\topen++;\n\t\t\t\t}\n\t\t\t\ta[j] = i;\n\t\t\t}\n\t\t\t\n\t\t\tans += open;\n\t\t\t\n\t\t\tfor (int j = cur; j < cur + open; j++) {\n\t\t\t\ta[j] = 0;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(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\tSystem.exit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e0a290869683260df3dd9d1d6e3b9365", "src_uid": "9135c7243431debb049f640e9600bc6e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class d1 {\n\tBufferedReader br;\n\tStringTokenizer in;\n\tPrintWriter out;\n\n\tpublic String nextToken() throws IOException {\n\t\twhile (in == null || !in.hasMoreTokens()) {\n\t\t\tin = new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn in.nextToken();\n\t}\n\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew d1().run();\n\t}\n\n\tpublic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\t\n\t\tint a[] = new int[n];\n\t\t\n\t\tint cnt[] = new int[n + 1];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t\tcnt[a[i]]++;\n\t\t}\n\t\t\n\t\tint cur = 0;\n\t\tint ans = 0;\n\t\t\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tcur += cnt[i];\n\t\t\t\n\t\t\tint open = 0;\n\t\t\t\n\t\t\tfor (int j = cur - cnt[i]; j < cur; j++) {\n\t\t\t\tif (a[j] == 0){\n\t\t\t\t\topen++;\n\t\t\t\t}\n\t\t\t\ta[j] = i;\n\t\t\t}\n\t\t\t\n\t\t\tans += open;\n\t\t\t\n\t\t\tfor (int j = cur; j < cur + open; j++) {\n\t\t\t\ta[j] = 0;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(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\tSystem.exit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd5948f232dc7499ed4e9ded7a6f6f79", "src_uid": "9135c7243431debb049f640e9600bc6e", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class JeffAndBrackets {\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tk;\n\tstatic long MAX = Long.MAX_VALUE / 3;\n\tstatic int MAXBALANCE;\n\tpublic static void main(String[] args) throws Exception {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\ttk = tk(in.readLine());\n\t\t\n\t\tint N = Integer.parseInt(tk.nextToken());\n\t\tint M = Integer.parseInt(tk.nextToken());\n\t\t\n\t\tint[] open = new int[N];\n\t\tint[] close = new int[N];\n\t\t\n\t\ttk = tk(in.readLine());\n\t\tfor(int i=0;i= 0)\n\t\t\t\t\t\t\tinit[(mod+1) % N][move+1][from][to-1] = Math.min(init[(mod+1) % N][move+1][from][to-1], \n\t\t\t\t\t\t\t\t\tinit[mod][move][from][to] + close[mod]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t// min cost to convert from balance i to j in N moves \n\t\tlong[][] mat = init[0][N];\n\t\tlong[][] result = new long[2*N+1][2*N+1];\n\t\tlong[][] temp = new long[2*N+1][2*N+1];\n\t\t\n\t\t// mat ^ k = min cost... in Nk moves\n\t\texp(mat, result, temp, M);\n\t\tSystem.out.println(result[0][0]);\n\t}\n\t\n\tstatic void exp(long[][] mat, long[][] result, long[][] temp, int pow) {\n\t\tif(pow == 1) {\n\t\t\tfor(int i=0;i 0) dp[i+1][j-1] = Math.min(dp[i+1][j-1], bs[i] + dp[i][j]);\n }\n }\n /*\n if (x == 0) {\n for (int i = 0; i <= n; i++) {\n System.out.println(Arrays.toString(dp[i]));\n }\n }\n */\n for (int y = 0; y <= n; y++) aa[x][y] = dp[n][y];\n }\n /*\n for (int i = 0; i <= n; i++) {\n System.out.println(Arrays.toString(aa[i]));\n }\n System.out.println();\n */\n\n long b[][] = new long[n + 1][n + 1];\n for (int i = 0; i < n+1; i++) {\n for (int j = 0; j < n+1; j++) {\n if (i == j) b[i][j] = 0;\n else b[i][j] = VERYLARGE;\n }\n }\n\n while (m > 0) {\n if ((m & 1) != 0) {\n mul(b, aa);\n }\n mul(aa, aa);\n m = m >> 1;\n /*\n for (int i = 0; i <=n; i++) {\n System.out.println(Arrays.toString(aa[i]));\n }\n System.out.println();\n */\n }\n\n System.out.println(b[0][0]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "553d9abc0f31825685ec8c6f9d97aadd", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "//package codeforces;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class E {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n StringTokenizer stringTokenizer;\n\n String next() throws IOException {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n stringTokenizer = new StringTokenizer(reader.readLine());\n }\n return stringTokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n @SuppressWarnings(\"unchecked\")\n void solve() throws IOException {\n int n = nextInt(), m = nextInt();\n int[] a = new int[n];\n for(int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n int[] b = new int[n];\n for(int i = 0; i < n; i++) {\n b[i] = nextInt();\n }\n int[][] f = new int[n + 1][n + 1];\n for(int i = 0; i <= n; i++) {\n int[][] dp = new int[n + 1][n + 1];\n for (int[] ints : dp) {\n Arrays.fill(ints, Integer.MAX_VALUE);\n }\n dp[0][i] = 0;\n for(int k = 0; k < n; k++) {\n for(int j = 0; j <= n; j++) {\n if(dp[k][j] == Integer.MAX_VALUE) continue;\n if(j - 1 >= 0) {\n dp[k + 1][j - 1] = Math.min(dp[k + 1][j - 1], dp[k][j] + b[k]);\n }\n if(j + 1 <= n) {\n dp[k + 1][j + 1] = Math.min(dp[k + 1][j + 1], dp[k][j] + a[k]);\n }\n }\n }\n System.arraycopy(dp[n], 0, f[i], 0, dp[n].length);\n }\n final int[][] pow = pow(f, m);\n int ans = pow[0][0];\n writer.println(ans);\n writer.close();\n }\n\n int[][] mul(int[][] a, int[][] b) {\n int n = a.length;\n int[][] c = new int[n][n];\n for(int i = 0; i < n; i++) {\n for(int j = 0; j < n; j++) {\n c[i][j] = Integer.MAX_VALUE;\n for(int k = 0; k < n; k++) {\n c[i][j] = (int)Math.min((long)c[i][j], (long)a[i][k] + b[k][j]);\n }\n }\n }\n return c;\n }\n\n int[][] pow(int[][] a, int k) {\n int n = a.length;\n int[][] result = new int[n][n];\n for (int[] ints : result) {\n Arrays.fill(ints, Integer.MAX_VALUE);\n }\n for(int i = 0; i < n; i++) {\n result[i][i] = 0;\n }\n while(k > 0) {\n if(k % 2 == 1) {\n result = mul(result, a);\n }\n a = mul(a, a);\n k /= 2;\n }\n return result;\n }\n\n public static void main(String[] args) throws IOException {\n new E().solve();\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "889b8b55fa679c41787eb6e78c025309", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601", "difficulty": 2500.0} {"lang": "Java 7", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "49d00489e7c0df9ca7dc92d8ecf58462", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E {\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 = 1000;\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 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\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\t// this version is more precise\n\t// but looks like it might be a bit slower\n\t// I should profile and optimize it some day...\n\n\tstatic int nextPowerOf2(int x) {\n\t\treturn x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;\n\t}\n\n\tstatic class CompV {\n\t\tdouble[] re, im;\n\n\t\tvoid add(CompV o) {\n\t\t\tfor (int i = 0; i < re.length; i++) {\n\t\t\t\tre[i] += o.re[i];\n\t\t\t\tim[i] += o.im[i];\n\t\t\t}\n\t\t}\n\n\t\tstatic CompV times(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] * bRe[i] - aIm[i] * bIm[i];\n\t\t\t\tim[i] = aRe[i] * bIm[i] + aIm[i] * bRe[i];\n\t\t\t}\n\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\tstatic CompV plus(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] + bRe[i];\n\t\t\t\tim[i] = aIm[i] + bIm[i];\n\t\t\t}\n\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\t/**\n\t\t * @return a + bi\n\t\t */\n\t\tstatic CompV packFFT(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] - bIm[i];\n\t\t\t\tim[i] = aIm[i] + bRe[i];\n\t\t\t}\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\t/**\n\t\t * for real-valued a and b restores FFT(a) and FFT(b) from FFT(a + bi)\n\t\t */\n\t\tvoid unpackFFT(CompV a, CompV b) {\n\t\t\tint n = re.length;\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i == 0 ? 0 : n - i;\n\t\t\t\taRe[i] = (re[i] + re[j]) * 0.5;\n\t\t\t\taIm[i] = (im[i] - im[j]) * 0.5;\n\t\t\t\tbRe[i] = (im[i] + im[j]) * 0.5;\n\t\t\t\tbIm[i] = (re[j] - re[i]) * 0.5;\n\t\t\t}\n\t\t}\n\n\t\tpublic CompV(double[] re, double[] im) {\n\t\t\tthis.re = re;\n\t\t\tthis.im = im;\n\t\t}\n\n\t\tpublic CompV(int len) {\n\t\t\tre = new double[len];\n\t\t\tim = new double[len];\n\t\t}\n\t}\n\n\t// !!!!\n\t// TEST WITH JUST ONE MULTIPLICATION\n\tpublic static int[] mult(int[] a, int[] b, int p) {\n\t\tint len = nextPowerOf2(a.length + b.length - 1);\n\n\t\tint k = (int) (Math.sqrt(p) + 1);\n\t\tint k2 = k * k % p;\n\n\t\tdouble[] p1 = new double[len];\n\t\tdouble[] q1 = new double[len];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tp1[i] = a[i] % k;\n\t\t\tq1[i] = a[i] / k;\n\t\t}\n\n\t\tdouble[] p2 = new double[len];\n\t\tdouble[] q2 = new double[len];\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tp2[i] = b[i] % k;\n\t\t\tq2[i] = b[i] / k;\n\t\t}\n\n\t\tCompV p1p2Pack = new CompV(p1, p2);\n\t\tCompV q1q2Pack = new CompV(q1, q2);\n\n\t\tfft(p1p2Pack, false);\n\t\tfft(q1q2Pack, false);\n\n\t\tCompV fp1 = new CompV(len);\n\t\tCompV fp2 = new CompV(len);\n\t\tp1p2Pack.unpackFFT(fp1, fp2);\n\n\t\tCompV fq1 = new CompV(len);\n\t\tCompV fq2 = new CompV(len);\n\t\tq1q2Pack.unpackFFT(fq1, fq2);\n\n\t\tCompV back0 = CompV.times(fp1, fp2);\n\n\t\tCompV back1 = CompV.times(fp1, fq2);\n\t\tback1.add(CompV.times(fq1, fp2));\n\n\t\tCompV back2 = CompV.times(fq1, fq2);\n\n\t\tCompV back01 = CompV.packFFT(back0, back1);\n\n\t\tfft(back01, true);\n\t\tfft(back2, true);\n\n\t\tint[] ret = new int[len];\n\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tlong v0 = Math.round(back01.re[i]) % p;\n\t\t\tlong v1 = Math.round(back01.im[i]) % p * k % p;\n\t\t\tlong v2 = Math.round(back2.re[i]) % p * k2 % p;\n\t\t\tret[i] = (int) ((v0 + v1 + v2) % p);\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tpublic static void fft(CompV v, boolean invert) {\n\t\tdouble[] a = v.re;\n\t\tdouble[] b = v.im;\n\t\tint n = a.length;\n\t\tint shift = 32 - Integer.numberOfTrailingZeros(n);\n\t\tprepareArrays(32 - shift);\n\t\tint[] rev = rev2D[32 - shift];\n\t\t// System.err.println(n + \" \" + shift);\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = rev[i];\n\t\t\tif (i < j) {\n\t\t\t\tdouble temp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = temp;\n\t\t\t\ttemp = b[i];\n\t\t\t\tb[i] = b[j];\n\t\t\t\tb[j] = temp;\n\t\t\t}\n\t\t}\n\n\t\t// this shit looks awkward\n\t\tdouble multInv = invert ? -1 : 1;\n\n\t\tfor (int len = 2, row = 0; len <= n; len <<= 1, row++) {\n\t\t\tint halfLen = len >> 1;\n\t\t\tdouble[] multReArr = powRe[row];\n\t\t\tdouble[] multImArr = powIm[row];\n\t\t\tfor (int i = 0; i < n; i += len) {\n\t\t\t\tint toJ = i + halfLen;\n\n\t\t\t\tfor (int j1 = i, j2 = toJ, k = 0; k < halfLen; j1++, j2++, k++) {\n\t\t\t\t\tdouble uA = a[j1];\n\t\t\t\t\tdouble uB = b[j1];\n\n\t\t\t\t\tdouble multRe = multReArr[k];\n\t\t\t\t\tdouble multIm = multImArr[k] * multInv;\n\n\t\t\t\t\tdouble vA = a[j2] * multRe - b[j2] * multIm;\n\t\t\t\t\tdouble vB = a[j2] * multIm + b[j2] * multRe;\n\t\t\t\t\ta[j1] = uA + vA;\n\t\t\t\t\tb[j1] = uB + vB;\n\t\t\t\t\ta[j2] = uA - vA;\n\t\t\t\t\tb[j2] = 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 < n; i++) {\n\t\t\t\ta[i] /= n;\n\t\t\t\tb[i] /= n;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic double[][] powRe = { { 1 } };\n\tstatic double[][] powIm = { { 0 } };\n\tstatic int[][] rev2D = {};\n\n\tstatic void prepareArrays(int n) {\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;\n\t\t\t\tif ((i & 1) == 1) {\n\t\t\t\t\ttmp[i] |= 1 << (n - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint oldN = powRe.length;\n\n\t\tif (oldN >= n) {\n\t\t\treturn;\n\t\t}\n\n\t\tpowRe = Arrays.copyOf(powRe, n);\n\t\tpowIm = Arrays.copyOf(powIm, n);\n\n\t\tfor (int i = oldN; i < n; i++) {\n\n\t\t\tdouble angle = Math.PI / (1 << i);\n\n\t\t\tdouble multRe = Math.cos(angle);\n\t\t\tdouble multIm = Math.sin(angle);\n\n\t\t\tdouble[] toRe = powRe[i] = new double[1 << i];\n\t\t\tdouble[] toIm = powIm[i] = new double[1 << i];\n\n\t\t\tdouble[] fromRe = powRe[i - 1];\n\t\t\tdouble[] fromIm = powIm[i - 1];\n\n\t\t\tfor (int j = 0; j < 1 << (i - 1); j++) {\n\n\t\t\t\tdouble re = fromRe[j];\n\t\t\t\tdouble im = fromIm[j];\n\n\t\t\t\ttoRe[j << 1] = re;\n\t\t\t\ttoIm[j << 1] = im;\n\t\t\t\ttoRe[(j << 1) | 1] = re * multRe - im * multIm;\n\t\t\t\ttoIm[(j << 1) | 1] = re * multIm + im * multRe;\n\t\t\t}\n\n\t\t\t// System.err.println(Arrays.toString(toRe));\n\t\t\t// System.err.println(Arrays.toString(toIm));\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 E();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f438ec60b094a98dac88560d12288a25", "src_uid": "d8c531799874ce5bf5443aba1d34b26d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E_faster {\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),\n\t\t\t\t\t2 * 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]\n\t\t\t\t\t* 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\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t}\n\n\t\tint[] initB = b.clone();\n\n\t\tb = makeInvPows(b);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tc[i] = nextInt();\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\n\t\tint[] fc = chirp(cc, pz, p);\n\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\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\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\n\t\t// System.err.println(Arrays.toString(realAa));\n\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\n\t\t// System.err.println(A + \" \" + B + \" \" + C);\n\n\t\tList x0s = new ArrayList<>();\n\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\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\n\t}\n\n\tint makeInt(int x, int p) {\n\t\treturn x < p / 2 ? x : x - p;\n\t}\n\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\tE_faster() 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\t// this version is more precise\n\t// but looks like it might be a bit slower\n\t// I should profile and optimize it some day...\n\n\tstatic int nextPowerOf2(int x) {\n\t\treturn x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;\n\t}\n\n\tstatic class CompV {\n\t\tdouble[] re, im;\n\n\t\tvoid add(CompV o) {\n\t\t\tfor (int i = 0; i < re.length; i++) {\n\t\t\t\tre[i] += o.re[i];\n\t\t\t\tim[i] += o.im[i];\n\t\t\t}\n\t\t}\n\n\t\tstatic CompV times(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] * bRe[i] - aIm[i] * bIm[i];\n\t\t\t\tim[i] = aRe[i] * bIm[i] + aIm[i] * bRe[i];\n\t\t\t}\n\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\tstatic CompV plus(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] + bRe[i];\n\t\t\t\tim[i] = aIm[i] + bIm[i];\n\t\t\t}\n\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\t/**\n\t\t * @return a + bi\n\t\t */\n\t\tstatic CompV packFFT(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] - bIm[i];\n\t\t\t\tim[i] = aIm[i] + bRe[i];\n\t\t\t}\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\t/**\n\t\t * for real-valued a and b restores FFT(a) and FFT(b) from FFT(a + bi)\n\t\t */\n\t\tvoid unpackFFT(CompV a, CompV b) {\n\t\t\tint n = re.length;\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i == 0 ? 0 : n - i;\n\t\t\t\taRe[i] = (re[i] + re[j]) * 0.5;\n\t\t\t\taIm[i] = (im[i] - im[j]) * 0.5;\n\t\t\t\tbRe[i] = (im[i] + im[j]) * 0.5;\n\t\t\t\tbIm[i] = (re[j] - re[i]) * 0.5;\n\t\t\t}\n\t\t}\n\n\t\tpublic CompV(double[] re, double[] im) {\n\t\t\tthis.re = re;\n\t\t\tthis.im = im;\n\t\t}\n\n\t\tpublic CompV(int len) {\n\t\t\tre = new double[len];\n\t\t\tim = new double[len];\n\t\t}\n\t}\n\n\tpublic static int[] mult(int[] a, int[] b, int p) {\n\t\tint len = nextPowerOf2(a.length + b.length - 1);\n\n\t\tdouble[] p1 = new double[len];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tp1[i] = a[i] % p;\n\t\t}\n\n\t\tdouble[] p2 = new double[len];\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tp2[i] = b[i] % p;\n\t\t}\n\n\t\tCompV p1p2Pack = new CompV(p1, p2);\n\n\t\tfft(p1p2Pack, false);\n\n\t\tCompV fp1 = new CompV(len);\n\t\tCompV fp2 = new CompV(len);\n\t\tp1p2Pack.unpackFFT(fp1, fp2);\n\n\t\tCompV back0 = CompV.times(fp1, fp2);\n\n\t\tfft(back0, true);\n\n\t\tint[] ret = new int[len];\n\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tlong v0 = Math.round(back0.re[i]) % p;\n\t\t\tret[i] = (int) (v0);\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tpublic static void fft(CompV v, boolean invert) {\n\t\tdouble[] a = v.re;\n\t\tdouble[] b = v.im;\n\t\tint n = a.length;\n\t\tint shift = 32 - Integer.numberOfTrailingZeros(n);\n\t\tprepareArrays(32 - shift);\n\t\tint[] rev = rev2D[32 - shift];\n\t\t// System.err.println(n + \" \" + shift);\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = rev[i];\n\t\t\tif (i < j) {\n\t\t\t\tdouble temp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = temp;\n\t\t\t\ttemp = b[i];\n\t\t\t\tb[i] = b[j];\n\t\t\t\tb[j] = temp;\n\t\t\t}\n\t\t}\n\n\t\t// this shit looks awkward\n\t\tdouble multInv = invert ? -1 : 1;\n\n\t\tfor (int len = 2, row = 0; len <= n; len <<= 1, row++) {\n\t\t\tint halfLen = len >> 1;\n\t\t\tdouble[] multReArr = powRe[row];\n\t\t\tdouble[] multImArr = powIm[row];\n\t\t\tfor (int i = 0; i < n; i += len) {\n\t\t\t\tint toJ = i + halfLen;\n\n\t\t\t\tfor (int j1 = i, j2 = toJ, k = 0; k < halfLen; j1++, j2++, k++) {\n\t\t\t\t\tdouble uA = a[j1];\n\t\t\t\t\tdouble uB = b[j1];\n\n\t\t\t\t\tdouble multRe = multReArr[k];\n\t\t\t\t\tdouble multIm = multImArr[k] * multInv;\n\n\t\t\t\t\tdouble vA = a[j2] * multRe - b[j2] * multIm;\n\t\t\t\t\tdouble vB = a[j2] * multIm + b[j2] * multRe;\n\t\t\t\t\ta[j1] = uA + vA;\n\t\t\t\t\tb[j1] = uB + vB;\n\t\t\t\t\ta[j2] = uA - vA;\n\t\t\t\t\tb[j2] = 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 < n; i++) {\n\t\t\t\ta[i] /= n;\n\t\t\t\tb[i] /= n;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic double[][] powRe = { { 1 } };\n\tstatic double[][] powIm = { { 0 } };\n\tstatic int[][] rev2D = {};\n\n\tstatic void prepareArrays(int n) {\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;\n\t\t\t\tif ((i & 1) == 1) {\n\t\t\t\t\ttmp[i] |= 1 << (n - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint oldN = powRe.length;\n\n\t\tif (oldN >= n) {\n\t\t\treturn;\n\t\t}\n\n\t\tpowRe = Arrays.copyOf(powRe, n);\n\t\tpowIm = Arrays.copyOf(powIm, n);\n\n\t\tfor (int i = oldN; i < n; i++) {\n\n\t\t\tdouble angle = Math.PI / (1 << i);\n\n\t\t\tdouble multRe = Math.cos(angle);\n\t\t\tdouble multIm = Math.sin(angle);\n\n\t\t\tdouble[] toRe = powRe[i] = new double[1 << i];\n\t\t\tdouble[] toIm = powIm[i] = new double[1 << i];\n\n\t\t\tdouble[] fromRe = powRe[i - 1];\n\t\t\tdouble[] fromIm = powIm[i - 1];\n\n\t\t\tfor (int j = 0; j < 1 << (i - 1); j++) {\n\n\t\t\t\tdouble re = fromRe[j];\n\t\t\t\tdouble im = fromIm[j];\n\n\t\t\t\ttoRe[j << 1] = re;\n\t\t\t\ttoIm[j << 1] = im;\n\t\t\t\ttoRe[(j << 1) | 1] = re * multRe - im * multIm;\n\t\t\t\ttoIm[(j << 1) | 1] = re * multIm + im * multRe;\n\t\t\t}\n\n\t\t\t// System.err.println(Arrays.toString(toRe));\n\t\t\t// System.err.println(Arrays.toString(toIm));\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 E_faster();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "276eba945d1d03949f10f619c55f004f", "src_uid": "d8c531799874ce5bf5443aba1d34b26d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author aryssoncf\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n ECyclicCipher solver = new ECyclicCipher();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ECyclicCipher {\n static final int C = 5000;\n static double[][] pow2D = {{1, 0}};\n static int[][] rev2D = {};\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n int[] b = new int[n];\n int[] c = new int[n];\n\n for (int i = 0; i < n; i++) {\n b[i] = in.readInt();\n }\n\n int[] initB = b.clone();\n\n b = makeInvPows(b);\n\n for (int i = 0; i < n; i++) {\n c[i] = in.readInt();\n }\n\n\n int z, p;\n int[] pz;\n\n int[] fb;\n\n for (int i = 1; ; i++) {\n p = 2 * n * i + 1;\n if (p < C) {\n continue;\n }\n if (!BigInteger.valueOf(p).isProbablePrime(30)) {\n continue;\n }\n z = pow(primitiveRoot(p), (p - 1) / (2 * n), p);\n pz = new int[2 * n];\n pz[0] = 1;\n for (int j = 1; j < pz.length; j++) {\n pz[j] = (int) ((long) pz[j - 1] * z % p);\n }\n\n fb = chirp(b, pz, p);\n boolean allGood = true;\n for (int coef : fb) {\n allGood &= coef != 0;\n }\n\n if (allGood) {\n break;\n }\n }\n\n int[] cc = new int[n];\n int inv2 = (p + 1) / 2;\n for (int i = 0; i < n; i++) {\n cc[i] = (c[(i + n - 1) % n] - c[i]) % p;\n if (cc[i] < 0) {\n cc[i] += p;\n }\n cc[i] = (int) ((long) cc[i] * inv2 % p);\n }\n\n int[] fc = chirp(cc, pz, p);\n\n int[] fa = new int[n];\n for (int i = 0; i < n; i++) {\n fa[i] = (int) ((long) fc[i] * pow(fb[i], p - 2, p) % p);\n }\n\n int[] aa = chirp(fa, makeInvPows(pz), p);\n int invN = pow(n, p - 2, p);\n for (int i = 0; i < n; i++) {\n aa[i] = (int) ((long) aa[i] * invN % p);\n }\n\n long[] d = new long[n];\n for (int i = 1; i < n; i++) {\n d[i] = d[i - 1] + makeInt(aa[i], p);\n }\n\n//\t\tSystem.err.println(Arrays.toString(realAa));\n\n long B = 0;\n long C = -c[0];\n for (int i = 0; i < n; i++) {\n long diff = initB[i] - d[i];\n B -= diff;\n C += diff * diff;\n }\n\n//\t\tSystem.err.println(A + \" \" + B + \" \" + C);\n\n List x0s = new ArrayList<>();\n\n long D = B * B - (long) n * C;\n if (D >= 0) {\n if (D == 0) {\n if ((-B % (long) n) == 0) {\n x0s.add((-B) / (long) n);\n }\n } else {\n long rd = (long) Math.sqrt(D);\n if (rd * rd == D) {\n if ((-B - rd) % (long) n == 0) {\n x0s.add((-B - rd) / (long) n);\n }\n if ((-B + rd) % (long) n == 0) {\n x0s.add((-B + rd) / (long) n);\n }\n }\n }\n }\n\n out.printLine(x0s.size());\n for (long x0 : x0s) {\n for (int i = 0; i < n; i++) {\n out.print(d[i] + x0 + \" \");\n }\n out.printLine();\n }\n }\n\n int pow(int a, int b, int p) {\n int ret = 1;\n for (; b > 0; b >>= 1) {\n if ((b & 1) == 1) {\n ret = (int) ((long) ret * a % p);\n }\n a = (int) ((long) a * a % p);\n }\n return ret;\n }\n\n int primitiveRoot(int p) {\n loop:\n for (int i = 2; ; i++) {\n for (int j = 2; j * j <= p - 1; j++) {\n if ((p - 1) % j != 0) {\n continue;\n }\n if (pow(i, (p - 1) / j, p) == 1) {\n continue loop;\n }\n if (pow(i, j, p) == 1) {\n continue loop;\n }\n }\n return i;\n }\n }\n\n int[] chirp(int[] a, int[] pz, int p) {\n int n = a.length;\n // pz[1] has order 2 * n modulo prime p\n\n a = a.clone();\n for (int i = 0; i < n; i++) {\n a[i] %= p;\n }\n\n int[] one = new int[n];\n for (int i = 0; i < n; i++) {\n one[i] = (int) ((long) a[i] * pz[(int) ((long) i * i % (2 * n))] % p);\n }\n\n int[] two = new int[2 * n - 1];\n for (int i = 0; i <= 2 * n - 2; i++) {\n two[i] = pz[Math.floorMod(-(long) (n - 1 - i) * (n - 1 - i), 2 * n)];\n }\n\n int[] prod = mult(one, two, p);\n\n prod = Arrays.copyOfRange(prod, n - 1, 2 * n - 1);\n for (int i = 0; i < n; i++) {\n prod[i] = (int) ((long) prod[i] * pz[(int) ((long) i * i % (2 * n))] % p);\n }\n\n return prod;\n // returns polynomial a modulo p at points 1, rootZ^2, rootZ^4, ...\n }\n\n int makeInt(int x, int p) {\n return x < p / 2 ? x : x - p;\n }\n\n int[] makeInvPows(int[] a) {\n int[] b = new int[a.length];\n b[0] = a[0];\n for (int i = 1, j = a.length - 1; i < a.length; i++, j--) {\n b[i] = a[j];\n }\n return b;\n }\n\n static int nextPowerOf2(int x) {\n return x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;\n }\n\n static double[][] foo(int[] intV, int len, int L) {\n // pack into one complex vector\n double[] f = new double[len << 1];\n for (int i = 0; i < intV.length; i++) {\n f[i << 1] = intV[i] % L;\n f[i << 1 | 1] = intV[i] / L;\n }\n\n fft(f, false);\n\n // unpack\n double[] f1 = new double[len << 1];\n double[] f2 = new double[len << 1];\n\n // LEN MUST BE A POWER OF 2!!!\n int zzz = (len << 1) - 1;\n for (int i = 0; i < len << 1; i += 2) {\n int j = (-i) & zzz;\n f1[i] = .5 * (f[i] + f[j]);\n f1[i + 1] = .5 * (f[i + 1] - f[j + 1]);\n f2[i] = .5 * (f[i + 1] + f[j + 1]);\n f2[i + 1] = .5 * (f[j] - f[i]);\n }\n\n return new double[][]{f1, f2};\n }\n\n public static int[] mult(int[] a, int[] b, int pMod) {\n\n int k = (int) (Math.sqrt(pMod) + 1);\n int k2 = k * k % pMod;\n\n int len = nextPowerOf2(a.length + b.length - 1);\n int len2 = len << 1;\n\n double[][] fA = foo(a, len, k);\n double[][] fB = foo(b, len, k);\n\n double[][] invF = new double[2][len2];\n\n for (int ia = 0; ia < 2; ia++) {\n for (int ib = 0; ib < 2; ib++) {\n\n double[] r = invF[(ia + ib) >> 1];\n double[] p = fA[ia];\n double[] q = fB[ib];\n\n if (((ia + ib) & 1) == 0) {\n for (int i = 0; i < len2; i += 2) {\n r[i] += p[i] * q[i] - p[i + 1] * q[i + 1];\n r[i + 1] += p[i] * q[i + 1] + p[i + 1] * q[i];\n }\n\n } else {\n for (int i = 0; i < len2; i += 2) {\n r[i] -= p[i] * q[i + 1] + p[i + 1] * q[i];\n r[i + 1] += p[i] * q[i] - p[i + 1] * q[i + 1];\n }\n }\n\n }\n }\n\n fft(invF[0], true);\n fft(invF[1], true);\n\n int[] ret = new int[len];\n\n for (int i = 0; i < len2; i += 2) {\n//\t\t\tlong v0 = Math.round(invF[0][i]) % P;\n//\t\t\tlong v1 = Math.round(invF[0][i + 1]) % P * L % P;\n//\t\t\tlong v2 = Math.round(invF[1][i]) % P * L2 % P;\n long v0 = (long) (invF[0][i] + .5);\n long v1 = ((long) (invF[0][i + 1] + .5)) % pMod * k;\n long v2 = ((long) (invF[1][i] + .5)) % pMod * k2;\n ret[i >> 1] = (int) ((v0 + v1 + v2) % pMod);\n }\n\n return ret;\n }\n\n public static void fft(double[] v, boolean invert) {\n int n2 = v.length;\n int n = n2 >> 1;\n int logN = Integer.numberOfTrailingZeros(n);\n prepareArrays(logN);\n int[] rev = rev2D[logN];\n\n for (int i = 0; i < n2; i += 2) {\n int j = rev[i >> 1] << 1;\n if (i < j) {\n double t = v[i];\n v[i] = v[j];\n v[j] = t;\n t = v[i + 1];\n v[i + 1] = v[j + 1];\n v[j + 1] = t;\n }\n }\n\n double conj = invert ? -1 : 1;\n\n for (int len = 2, row = 0; len <= n; len <<= 1, row++) {\n double[] pow = pow2D[row];\n for (int i = 0; i < n; i += len) {\n for (int j1 = i << 1, j2 = j1 + len, k = 0; k < len; j1 += 2, j2 += 2, k += 2) {\n double uA = v[j1];\n double uB = v[j1 + 1];\n\n double mRe = pow[k];\n double mIm = pow[k + 1] * conj;\n\n double vA = v[j2] * mRe - v[j2 + 1] * mIm;\n double vB = v[j2] * mIm + v[j2 + 1] * mRe;\n\n v[j1] = uA + vA;\n v[j1 + 1] = uB + vB;\n v[j2] = uA - vA;\n v[j2 + 1] = uB - vB;\n }\n }\n }\n if (invert) {\n for (int i = 0; i < n2; i++) {\n v[i] /= n;\n }\n }\n }\n\n static void prepareArrays(int n) {\n if (rev2D.length < n + 1) {\n rev2D = Arrays.copyOf(rev2D, n + 1);\n }\n\n if (rev2D[n] == null) {\n int[] tmp = rev2D[n] = new int[1 << n];\n for (int i = 0; i < (1 << n); i++) {\n tmp[i] = (tmp[i >> 1] >> 1) | ((i & 1) << (n - 1));\n }\n }\n\n int oldN = pow2D.length;\n\n if (oldN >= n) {\n return;\n }\n\n pow2D = Arrays.copyOf(pow2D, n);\n\n for (int i = oldN; i < n; i++) {\n double angle = Math.PI / (1 << i);\n\n double mRe = Math.cos(angle);\n double mIm = Math.sin(angle);\n\n double[] dst = pow2D[i] = new double[2 << i];\n double[] src = pow2D[i - 1];\n\n for (int j = 0; j < 1 << i; j += 2) {\n double re = src[j];\n double im = src[j + 1];\n\n dst[j << 1] = re;\n dst[j << 1 | 1] = im;\n dst[j << 1 | 2] = re * mRe - im * mIm;\n dst[j << 1 | 3] = re * mIm + im * mRe;\n }\n }\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void printLine() {\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c27be64f7a1b7d7079b2d75af17a282e", "src_uid": "d8c531799874ce5bf5443aba1d34b26d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E {\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 = 1000;\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[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[Math.floorMod(-(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[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 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\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\t// this version is more precise\n\t// but looks like it might be a bit slower\n\t// I should profile and optimize it some day...\n\n\tstatic int nextPowerOf2(int x) {\n\t\treturn x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;\n\t}\n\n\tstatic class CompV {\n\t\tdouble[] re, im;\n\n\t\tvoid add(CompV o) {\n\t\t\tfor (int i = 0; i < re.length; i++) {\n\t\t\t\tre[i] += o.re[i];\n\t\t\t\tim[i] += o.im[i];\n\t\t\t}\n\t\t}\n\n\t\tstatic CompV times(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] * bRe[i] - aIm[i] * bIm[i];\n\t\t\t\tim[i] = aRe[i] * bIm[i] + aIm[i] * bRe[i];\n\t\t\t}\n\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\tstatic CompV plus(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] + bRe[i];\n\t\t\t\tim[i] = aIm[i] + bIm[i];\n\t\t\t}\n\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\t/**\n\t\t * @return a + bi\n\t\t */\n\t\tstatic CompV packFFT(CompV a, CompV b) {\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tdouble[] re = new double[aRe.length];\n\t\t\tdouble[] im = new double[aRe.length];\n\t\t\tfor (int i = 0; i < aRe.length; i++) {\n\t\t\t\tre[i] = aRe[i] - bIm[i];\n\t\t\t\tim[i] = aIm[i] + bRe[i];\n\t\t\t}\n\t\t\treturn new CompV(re, im);\n\t\t}\n\n\t\t/**\n\t\t * for real-valued a and b restores FFT(a) and FFT(b) from FFT(a + bi)\n\t\t */\n\t\tvoid unpackFFT(CompV a, CompV b) {\n\t\t\tint n = re.length;\n\t\t\tdouble[] aRe = a.re;\n\t\t\tdouble[] aIm = a.im;\n\t\t\tdouble[] bRe = b.re;\n\t\t\tdouble[] bIm = b.im;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i == 0 ? 0 : n - i;\n\t\t\t\taRe[i] = (re[i] + re[j]) * 0.5;\n\t\t\t\taIm[i] = (im[i] - im[j]) * 0.5;\n\t\t\t\tbRe[i] = (im[i] + im[j]) * 0.5;\n\t\t\t\tbIm[i] = (re[j] - re[i]) * 0.5;\n\t\t\t}\n\t\t}\n\n\t\tpublic CompV(double[] re, double[] im) {\n\t\t\tthis.re = re;\n\t\t\tthis.im = im;\n\t\t}\n\n\t\tpublic CompV(int len) {\n\t\t\tre = new double[len];\n\t\t\tim = new double[len];\n\t\t}\n\t}\n\n\t// !!!!\n\t// TEST WITH JUST ONE MULTIPLICATION\n\tpublic static int[] mult(int[] a, int[] b, int p) {\n\t\tint len = nextPowerOf2(a.length + b.length - 1);\n\n\t\tint k = (int) (Math.sqrt(p) + 1);\n\t\tint k2 = k * k % p;\n\n\t\tdouble[] p1 = new double[len];\n\t\tdouble[] q1 = new double[len];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tp1[i] = a[i] % k;\n\t\t\tq1[i] = a[i] / k;\n\t\t}\n\n\t\tdouble[] p2 = new double[len];\n\t\tdouble[] q2 = new double[len];\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tp2[i] = b[i] % k;\n\t\t\tq2[i] = b[i] / k;\n\t\t}\n\n\t\tCompV p1p2Pack = new CompV(p1, p2);\n\t\tCompV q1q2Pack = new CompV(q1, q2);\n\n\t\tfft(p1p2Pack, false);\n\t\tfft(q1q2Pack, false);\n\n\t\tCompV fp1 = new CompV(len);\n\t\tCompV fp2 = new CompV(len);\n\t\tp1p2Pack.unpackFFT(fp1, fp2);\n\n\t\tCompV fq1 = new CompV(len);\n\t\tCompV fq2 = new CompV(len);\n\t\tq1q2Pack.unpackFFT(fq1, fq2);\n\n\t\tCompV back0 = CompV.times(fp1, fp2);\n\n\t\tCompV back1 = CompV.times(fp1, fq2);\n\t\tback1.add(CompV.times(fq1, fp2));\n\n\t\tCompV back2 = CompV.times(fq1, fq2);\n\n\t\tCompV back01 = CompV.packFFT(back0, back1);\n\n\t\tfft(back01, true);\n\t\tfft(back2, true);\n\n\t\tint[] ret = new int[len];\n\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tlong v0 = Math.round(back01.re[i]) % p;\n\t\t\tlong v1 = Math.round(back01.im[i]) % p * k % p;\n\t\t\tlong v2 = Math.round(back2.re[i]) % p * k2 % p;\n\t\t\tret[i] = (int) ((v0 + v1 + v2) % p);\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tpublic static void fft(CompV v, boolean invert) {\n\t\tdouble[] a = v.re;\n\t\tdouble[] b = v.im;\n\t\tint n = a.length;\n\t\tint shift = 32 - Integer.numberOfTrailingZeros(n);\n\t\tprepareArrays(32 - shift);\n\t\tint[] rev = rev2D[32 - shift];\n\t\t// System.err.println(n + \" \" + shift);\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = rev[i];\n\t\t\tif (i < j) {\n\t\t\t\tdouble temp = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = temp;\n\t\t\t\ttemp = b[i];\n\t\t\t\tb[i] = b[j];\n\t\t\t\tb[j] = temp;\n\t\t\t}\n\t\t}\n\n\t\t// this shit looks awkward\n\t\tdouble multInv = invert ? -1 : 1;\n\n\t\tfor (int len = 2, row = 0; len <= n; len <<= 1, row++) {\n\t\t\tint halfLen = len >> 1;\n\t\t\tdouble[] multReArr = powRe[row];\n\t\t\tdouble[] multImArr = powIm[row];\n\t\t\tfor (int i = 0; i < n; i += len) {\n\t\t\t\tint toJ = i + halfLen;\n\n\t\t\t\tfor (int j1 = i, j2 = toJ, k = 0; k < halfLen; j1++, j2++, k++) {\n\t\t\t\t\tdouble uA = a[j1];\n\t\t\t\t\tdouble uB = b[j1];\n\n\t\t\t\t\tdouble multRe = multReArr[k];\n\t\t\t\t\tdouble multIm = multImArr[k] * multInv;\n\n\t\t\t\t\tdouble vA = a[j2] * multRe - b[j2] * multIm;\n\t\t\t\t\tdouble vB = a[j2] * multIm + b[j2] * multRe;\n\t\t\t\t\ta[j1] = uA + vA;\n\t\t\t\t\tb[j1] = uB + vB;\n\t\t\t\t\ta[j2] = uA - vA;\n\t\t\t\t\tb[j2] = 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 < n; i++) {\n\t\t\t\ta[i] /= n;\n\t\t\t\tb[i] /= n;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic double[][] powRe = { { 1 } };\n\tstatic double[][] powIm = { { 0 } };\n\tstatic int[][] rev2D = {};\n\n\tstatic void prepareArrays(int n) {\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;\n\t\t\t\tif ((i & 1) == 1) {\n\t\t\t\t\ttmp[i] |= 1 << (n - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint oldN = powRe.length;\n\n\t\tif (oldN >= n) {\n\t\t\treturn;\n\t\t}\n\n\t\tpowRe = Arrays.copyOf(powRe, n);\n\t\tpowIm = Arrays.copyOf(powIm, n);\n\n\t\tfor (int i = oldN; i < n; i++) {\n\n\t\t\tdouble angle = Math.PI / (1 << i);\n\n\t\t\tdouble multRe = Math.cos(angle);\n\t\t\tdouble multIm = Math.sin(angle);\n\n\t\t\tdouble[] toRe = powRe[i] = new double[1 << i];\n\t\t\tdouble[] toIm = powIm[i] = new double[1 << i];\n\n\t\t\tdouble[] fromRe = powRe[i - 1];\n\t\t\tdouble[] fromIm = powIm[i - 1];\n\n\t\t\tfor (int j = 0; j < 1 << (i - 1); j++) {\n\n\t\t\t\tdouble re = fromRe[j];\n\t\t\t\tdouble im = fromIm[j];\n\n\t\t\t\ttoRe[j << 1] = re;\n\t\t\t\ttoIm[j << 1] = im;\n\t\t\t\ttoRe[(j << 1) | 1] = re * multRe - im * multIm;\n\t\t\t\ttoIm[(j << 1) | 1] = re * multIm + im * multRe;\n\t\t\t}\n\n\t\t\t// System.err.println(Arrays.toString(toRe));\n\t\t\t// System.err.println(Arrays.toString(toIm));\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 E();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d1699d070d8074bc7c97211eb88c8c9c", "src_uid": "d8c531799874ce5bf5443aba1d34b26d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n static int inf = (int) 1e9 + 7;\n static int n, a[];\n\n static int min() {\n int ans = inf;\n for(int i = 0;i < n;i++) ans = Math.min(ans, a[i]);\n return ans;\n }\n\n static int cnt(int l, int r, int num) {\n int ans = 0;\n for(int i = l;i <= r;i++) if (a[i] == num) ans++;\n return ans;\n }\n\n static pair check(pair a) {\n if (a.l < 0 || a.r >= n) return new pair(0, 0, 0);\n return a;\n }\n\n static pair max(pair a, pair b) {\n a = check(a);\n b = check(b);\n if (a.ans > b.ans) return a;\n return b;\n }\n\n static void scan() throws IOException {\n n = sc.nextInt();\n char h[] = sc.next().toCharArray();\n a = new int [n];\n for(int i = 0;i < n;i++) {\n a[i] = (h[i] == '(' ? 1 : -1);\n if (i != 0) a[i] += a[i - 1];\n }\n }\n\n static pair zero() {\n return new pair(0, 0, cnt(0, n - 1, min()));\n }\n\n static pair plus() {\n int min = min();\n int l = inf;\n int r = -1;\n for(int i = 0;i < n;i++) {\n if (l == inf && a[i] == min) l = i;\n if (a[i] == min) r = i;\n }\n\n return max(plus1(l, r, min), plus2(l, r, min));\n }\n\n static pair plus1(int l, int r, int min) {\n int ans = cnt(0, l - 1, min + 1) + cnt(r + 1, n - 1, min + 1);\n return new pair(l, r + 1, ans);\n }\n\n static pair plus2(int l, int r, int min) {\n int l1 = l;\n int r1 = r;\n for(int i = 0;i < n;i++) {\n if (a[i] == min + 1 && l1 > i) l1 = i;\n if (a[i] == min + 1 && r1 < i) r1 = i;\n }\n\n\n int ans = cnt(0, n - 1, min);\n for(int i = 0;i < n;i++) {\n if ((i < l1 || i > r1) && a[i] == min + 2) ans++;\n }\n\n return new pair(l1, r1 + 1, ans);\n }\n\n static pair minus() {\n int min = min();\n int cnt = cnt(0, n - 1, min);\n int l = 0;\n pair ans = new pair(0, 0, 0);\n for(int i = 0;i < n;i++) {\n if (a[i] == min) {\n ans = max(ans, minus(l, i - 1, min, cnt));\n l = i + 1;\n }\n }\n return ans;\n }\n\n static pair minus(int l, int r, int min, int cnt) {\n int cnt1 = 0;\n int cnt2 = 0;\n pair ans = new pair(0, 0, 0);\n int l1 = l;\n for(int i = l;i <= r;i++) {\n if (a[i] == min + 1) {\n cnt1++;\n ans = max(ans, minus2(l1, i - 1, min, cnt));\n l1 = i + 1;\n }\n\n if (a[i] == min + 2) cnt2++;\n\n }\n\n ans = max(ans, minus2(l1, r, min, cnt));\n\n if (cnt1 > 0) return max(new pair(l, r + 1, cnt1), ans);\n return new pair(l, r + 1, cnt + cnt2);\n }\n\n static pair minus2(int l, int r, int min, int cnt) {\n return new pair(l, r + 1, cnt(l, r, min + 2) + cnt);\n }\n\n public static void main(String[] args) throws IOException {\n sc = new Scanner(System.in);\n pw = new PrintWriter(System.out);\n scan();\n if (a[n - 1] != 0) {\n System.out.println(0);\n System.out.println(1 + \" \" + 1);\n return;\n }\n pair ans = max(zero(), max(plus(), minus()));\n pw.println(ans.ans);\n pw.println(ans.l + 1 + \" \" + (ans.r + 1));\n\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\nclass pair {\n int l, r, ans;\n\n pair(int l, int r, int ans) {\n this.l = l;\n this.r = r;\n this.ans = ans;\n }\n\n pair() {}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0ee03b0ae6ea5b2d7375afb6c834fd85", "src_uid": "be820239276b5e1a346309f9dd21c5cb", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.InputStream;\nimport java.io.PrintStream;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class TaskD {\n private static final String QUICK_ANSWER = \"NO\";\n private final Scanner in;\n private final StringBuilder out;\n private final int n;\n private final char[] chars;\n private final boolean[] up;\n int minPos;\n\n\n public TaskD(Scanner in, StringBuilder out) throws QuickAnswer {\n this.in = in;\n this.out = out;\n n = nextInt();\n chars = nextString().toCharArray();\n int lev = 0;\n int minLev = 0;\n int minPos = 0;\n for (int i = 0; i < n; i++) {\n if (chars[i] == '(') ++lev;\n else --lev;\n if (lev < minLev) {\n minLev = lev;\n minPos = i + 1;\n }\n }\n if (lev != 0) {\n quickAnswer(\"0\\n1 1\");\n }\n minPos %= n;\n this.minPos = minPos;\n up = new boolean[n];\n for (int i = 0; i < n; i++) {\n up[i] = chars[(i + minPos) % n] == '(';\n }\n }\n\n public void solve() throws QuickAnswer {\n int lev = 0;\n int i1 = 0;\n int i2 = 0;\n int bonus = 0;\n int istart = -1;\n int b = 1;\n int cnt0 = 0;\n int cnt1 = 0;\n for (int i = 0; i < n; i++) {\n if (up[i]) lev++;\n else lev--;\n if (lev == 0) ++cnt0;\n if (lev == 1) ++cnt1;\n if (lev == 2) {\n if (up[i]) istart = i;\n else ++b;\n } else if (lev == 1 && !up[i]) {\n if (b > bonus) {\n i1 = istart;\n i2 = i;\n bonus = b;\n }\n istart = -1;\n b = 1;\n }\n }\n up[i1] = false;\n up[i2] = true;\n lev = 0;\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n if (up[i]) lev++;\n else lev--;\n if (lev == 0) ++cnt;\n }\n if (cnt0 == 1 && cnt1 > cnt) {\n cnt = cnt1;\n i1 = 0;\n i2 = n - 1;\n }\n\n println(cnt);\n print(1 + (i1 + minPos) % n, 1 + (i2 + minPos) % n);\n\n\n }\n\n // Common functions\n\n void quickAnswer(String answer) throws QuickAnswer {\n throw new QuickAnswer(answer);\n }\n\n void quickAnswer() throws QuickAnswer {\n quickAnswer(QUICK_ANSWER);\n }\n\n\n static class QuickAnswer extends Exception {\n private String answer;\n\n public QuickAnswer(String answer) {\n this.answer = answer;\n }\n }\n\n void print(Object... args) {\n String prefix = \"\";\n for (Object arg : args) {\n out.append(prefix);\n out.append(arg);\n prefix = \" \";\n }\n }\n\n void println(Object... args) {\n print(args);\n out.append(\"\\n\");\n }\n\n void printsp(Object... args) {\n print(args);\n out.append(\" \");\n }\n\n int nextInt() {\n return in.nextInt();\n }\n\n long nextLong() {\n return in.nextLong();\n }\n\n String nextString() {\n String res = in.nextLine();\n return res.trim().isEmpty() ? in.nextLine() : res;\n }\n\n int[] nextInts(int count) {\n int[] res = new int[count];\n for (int i = 0; i < count; ++i) {\n res[i] = in.nextInt();\n }\n return res;\n }\n\n long[] nextLongs(int count) {\n long[] res = new long[count];\n for (int i = 0; i < count; ++i) {\n res[i] = in.nextInt();\n }\n return res;\n }\n\n public static void main(String[] args) {\n doMain(System.in, System.out);\n }\n\n static void doMain(InputStream inStream, PrintStream outStream) {\n Scanner in = new Scanner(new BufferedInputStream(inStream)).useLocale(Locale.ENGLISH);\n StringBuilder totalOut = new StringBuilder();\n int count = 1;\n //count = in.nextInt();\n while (count-- > 0) {\n try {\n StringBuilder out = new StringBuilder();\n new TaskD(in, out).solve();\n totalOut.append(out.toString());\n } catch (QuickAnswer e) {\n totalOut.append(e.answer);\n }\n if (count > 0) {\n totalOut.append(\"\\n\");\n }\n }\n outStream.print(totalOut.toString());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2705b48c22575a167b2fc2fd0762bb1", "src_uid": "be820239276b5e1a346309f9dd21c5cb", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "/**\n * BaZ :D\n */\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class Main\n{\n static MyScanner scan;\n static PrintWriter pw;\n static long MOD = 1_000_000_007;\n static long INF = 1_000_000_000_000_000_000L;\n static long inf = 2_000_000_000;\n public static void main(String[] args) {\n new Thread(null, null, \"BaZ\", 1 << 27) {\n public void run() {\n try {\n solve();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n }.start();\n }\n static int idx1, idx2;\n static char c[];\n static void solve() throws IOException\n {\n //initIo(true);\n initIo(false);\n StringBuilder sb = new StringBuilder();\n int n = ni();\n c = ne().toCharArray();\n int bal[] = new int[n];\n int open = 0;\n for(int i=0;i=0) {\n bal[i]+=bal[i-1];\n }\n }\n if(open != n - open) {\n pl(\"0\\n1 1\");\n System.exit(0);\n }\n int min = Integer.MAX_VALUE, at = -1;\n for(int i=0;imax) {\n max = zero;\n ans_idx1 = idx1;\n ans_idx2 = idx2;\n }\n int one = calc(arr,1,n,false, (at+1 ==n ? 0 : at+1));\n if(one>max) {\n max = one;\n ans_idx1 = idx1;\n ans_idx2 = idx2;\n }\n int two = calc(arr,2,n,true, (at+1 ==n ? 0 : at+1));\n if(two>max) {\n max = two;\n ans_idx1 = idx1;\n ans_idx2 = idx2;\n }\n pl(max);\n pl((1+getOriginalIndex(at+1 == n ? 0 : at+1, n, ans_idx1)) + \" \" + (1+getOriginalIndex(at+1 == n ? 0 : at+1, n, ans_idx2)));\n pw.flush();\n pw.close();\n }\n static int getOriginalIndex(int from_where, int n, int idx) {\n if(idx<=n-1-from_where) {\n return from_where + idx;\n }\n else {\n return idx - (n-from_where);\n }\n }\n static int calc(int arr[], int k, int n, boolean shouldAdd, int from_where) {\n int till[] = new int[n];\n int cum[] = new int[n];\n int pref[] = new int[n];\n int suff[] = new int[n];\n for(int i=n-1;i>=0;--i) {\n if(arr[i] == 0) {\n ++suff[i];\n }\n if(i+10) {\n cum[i]+=cum[i-1];\n pref[i]+=pref[i-1];\n }\n }\n for(int i=n-1;i>=0;--i) {\n if(arr[i] >= k) {\n till[i] = (i+1 < n ? till[i+1] : n);\n }\n else {\n till[i] = i;\n }\n }\n int max = -1;\n for(int i=0;i 0 ? cum[till[i] - 1] : 0) - (i > 0 ? cum[i-1] : 0);\n if(shouldAdd) {\n ispe+=(i-1>0 ? pref[i-1] : 0);\n ispe+=(till[i] < n ? suff[till[i]] : 0);\n }\n if(max=0) {\n bal[i]+=bal[i-1];\n }\n }\n if(open != n - open) {\n pl(\"0\\n1 1\");\n System.exit(0);\n }\n int min = Integer.MAX_VALUE, at = -1;\n for(int i=0;imax) {\n max = zero;\n ans_idx1 = idx1;\n ans_idx2 = idx2;\n }\n int one = calc(arr,1,n,false);\n if(one>max) {\n max = one;\n ans_idx1 = idx1;\n ans_idx2 = idx2;\n }\n int two = calc(arr,2,n,true);\n if(two>max) {\n max = two;\n ans_idx1 = idx1;\n ans_idx2 = idx2;\n }\n pl(max);\n pl((1+getOriginalIndex(at+1 == n ? 0 : at+1, n, ans_idx1)) + \" \" + (1+getOriginalIndex(at+1 == n ? 0 : at+1, n, ans_idx2)));\n pw.flush();\n pw.close();\n }\n static int getOriginalIndex(int from_where, int n, int idx) {\n if(idx<=n-1-from_where) {\n return from_where + idx;\n }\n else {\n return idx - (n-from_where);\n }\n }\n static int calc(int arr[], int k, int n, boolean shouldAdd) {\n int till[] = new int[n];\n int cum[] = new int[n];\n int pref[] = new int[n];\n int suff[] = new int[n];\n for(int i=n-1;i>=0;--i) {\n if(arr[i] == 0) {\n ++suff[i];\n }\n if(i+10) {\n cum[i]+=cum[i-1];\n pref[i]+=pref[i-1];\n }\n }\n for(int i=n-1;i>=0;--i) {\n if(arr[i] >= k) {\n till[i] = (i+1 < n ? till[i+1] : n);\n }\n else {\n till[i] = i;\n }\n }\n int max = -1;\n for(int i=0;i 0 ? cum[till[i] - 1] : 0) - (i > 0 ? cum[i-1] : 0);\n if(shouldAdd) {\n ispe+=(i-1>0 ? pref[i-1] : 0);\n ispe+=(till[i] < n ? suff[till[i]] : 0);\n }\n if(max {\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 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 firsts = new ArrayList();\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 firsts, int n) {\n res = new ArrayList();\n tdx = 0;\n tdy = 0;\n return rec(firsts, n, firsts.size() - 1);\n }\n\n private boolean rec(List 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0c2575dbb83c465960d26e4c99486052", "src_uid": "77b281558c480607b02e8e263e81a455", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n boolean[] isSq;\n int[] lens;\n int[] cnt;\n int[][] vx, vy;\n \n int N;\n \n int[] solX, solY;\n \n boolean[][][][] was;\n \n final int LIM = 90;\n \n class Segment implements Comparable {\n int dx, dy;\n double angle;\n \n public Segment(int dx, int dy) {\n this.dx = dx;\n this.dy = dy;\n this.angle = Math.atan2(dy, dx);\n }\n \n public int compareTo(Segment other) {\n return new Double(this.angle).compareTo(new Double(other.angle));\n }\n }\n \n int it = 0;\n boolean retFlag = false;\n \n boolean[] skipped;\n \n void go(int pos, int take, int curX, int curY, int skip) {\n /*if (Math.abs(curX) >= LIM || Math.abs(curY) >= LIM)\n return;*/\n \n if (take == N) {\n if (curX==0 && curY==0) {\n System.out.println(\"YES\");\n \n Segment[] segm = new Segment[N];\n for (int i=0; i < N; i++)\n segm[i] = new Segment(solX[i], solY[i]);\n Arrays.sort(segm);\n int cx=0, cy=0;\n \n for (int i=0; i < N; i++) {\n System.out.println(cx + \" \" + cy);\n cx += segm[i].dx;\n cy += segm[i].dy;\n }\n System.exit(0);\n }\n it++;\n if (it==10000) retFlag = true;\n return;\n }\n\n /*int A = Math.max(Math.abs(curX), Math.abs(curY));\n int B = Math.min(Math.abs(curX), Math.abs(curY));\n if (was[pos][A][B][skip]) {\n return;\n }\n was[pos][A][B][skip] = true;*/\n \n int[] nx = new int[cnt[pos]];\n int[] ny = new int[cnt[pos]];\n int[] dist = new int[cnt[pos]];\n \n for (int x=0; x < cnt[pos]; x++) {\n nx[x] = curX + vx[pos][x];\n ny[x] = curY + vy[pos][x];\n dist[x] = nx[x] * nx[x] + ny[x] * ny[x];\n }\n \n for (int x=0; x + 1 < cnt[pos]; x++)\n for (int y=0; y + 1 < cnt[pos]; y++)\n if (dist[y] > dist[y + 1]) {\n int tmp = nx[y]; nx[y] = nx[y+1]; nx[y+1] = tmp;\n tmp = ny[y]; ny[y] = ny[y+1]; ny[y+1] = tmp;\n tmp = dist[y]; dist[y] = dist[y+1]; dist[y+1] = tmp;\n }\n \n if (skip > 0 && skipped[pos])\n go(pos - 1, take, curX, curY, skip - 1);\n \n if (retFlag) return;\n \n for (int x=0; x < cnt[pos]; x++) {\n solX[take] = nx[x] - curX;\n solY[take] = ny[x] - curY;\n go(pos - 1, take + 1, nx[x], ny[x], skip);\n if (retFlag) return;\n } \n }\n \n public void doMain() {\n Scanner sc = new Scanner(new InputStreamReader(System.in));\n N = sc.nextInt();\n \n if (N==3) {\n System.out.println(\"YES\");\n System.out.println(\"0 0\");\n System.out.println(\"1 0\");\n System.out.println(\"0 2\");\n System.exit(0);\n }\n \n isSq = new boolean[100000];\n for (int i=0; i*i < isSq.length; i++)\n isSq[i*i] = true;\n \n lens = new int[11000];\n vx = new int[11000][100];\n vy = new int[11000][100];\n cnt = new int[11000];\n \n int pos = 0;\n skipped = new boolean[N + 2];\n for (int len=1; ; len++) {\n boolean ok = false;\n for (int x=0; x*x <= len; x++) {\n if (!isSq[len-x*x]) continue;\n lens[pos] = len;\n int y = (int)Math.sqrt(len - x*x);\n ok = true;\n \n vx[pos][cnt[pos]] = x;\n vy[pos][cnt[pos]++] = y;\n \n if (x != 0) {\n vx[pos][cnt[pos]] = -x;\n vy[pos][cnt[pos]++] = y;\n }\n \n if (y != 0) {\n vx[pos][cnt[pos]] = x;\n vy[pos][cnt[pos]++] = -y;\n }\n \n if (x != 0 && y != 0) {\n vx[pos][cnt[pos]] = -x;\n vy[pos][cnt[pos]++] = -y;\n }\n }\n if (ok) {\n pos++;\n }\n if (pos == N + 1) break;\n }\n \n int oo = 0, ee = 0, oe = 0;\n for (int i=0; i < N; i++) {\n if (vx[i][0] % 2 == 0 && vy[i][0] % 2 == 0)\n ee++;\n else if (vx[i][0] % 2 == 1 && vy[i][0] % 2 == 1)\n oo++;\n else\n oe++;\n }\n \n int stSkip = 0;\n \n if (oe % 2 == 1) {\n stSkip = 1;\n }\n \n solX = new int[N];\n solY = new int[N];\n \n /*was = new boolean[N+2][LIM][][];\n \n for (int i=0; i < was.length; i++)\n for (int A=0; A {\n int dx, dy;\n double angle;\n \n public Segment(int dx, int dy) {\n this.dx = dx;\n this.dy = dy;\n this.angle = Math.atan2(dy, dx);\n }\n \n public int compareTo(Segment other) {\n return new Double(this.angle).compareTo(new Double(other.angle));\n }\n }\n \n int it = 0;\n boolean retFlag = false;\n \n boolean[] skipped;\n \n void go(int pos, int take, int curX, int curY, int skip) {\n /*if (Math.abs(curX) >= LIM || Math.abs(curY) >= LIM)\n return;*/\n \n if (take == N) {\n if (curX==0 && curY==0) {\n System.out.println(\"YES\");\n \n Segment[] segm = new Segment[N];\n for (int i=0; i < N; i++)\n segm[i] = new Segment(solX[i], solY[i]);\n Arrays.sort(segm);\n int cx=0, cy=0;\n \n for (int i=0; i < N; i++) {\n System.out.println(cx + \" \" + cy);\n cx += segm[i].dx;\n cy += segm[i].dy;\n }\n System.exit(0);\n }\n it++;\n if (it==10000) retFlag = true;\n return;\n }\n\n /*int A = Math.max(Math.abs(curX), Math.abs(curY));\n int B = Math.min(Math.abs(curX), Math.abs(curY));\n if (was[pos][A][B][skip]) {\n return;\n }\n was[pos][A][B][skip] = true;*/\n \n int[] nx = new int[cnt[pos]];\n int[] ny = new int[cnt[pos]];\n int[] dist = new int[cnt[pos]];\n \n for (int x=0; x < cnt[pos]; x++) {\n nx[x] = curX + vx[pos][x];\n ny[x] = curY + vy[pos][x];\n dist[x] = nx[x] * nx[x] + ny[x] * ny[x];\n }\n \n for (int x=0; x + 1 < cnt[pos]; x++)\n for (int y=0; y + 1 < cnt[pos]; y++)\n if (dist[y] > dist[y + 1]) {\n int tmp = nx[y]; nx[y] = nx[y+1]; nx[y+1] = tmp;\n tmp = ny[y]; ny[y] = ny[y+1]; ny[y+1] = tmp;\n tmp = dist[y]; dist[y] = dist[y+1]; dist[y+1] = tmp;\n }\n \n if (skip > 0 && skipped[pos])\n go(pos - 1, take, curX, curY, skip - 1);\n \n if (retFlag) return;\n \n for (int x=0; x < cnt[pos]; x++) {\n solX[take] = nx[x] - curX;\n solY[take] = ny[x] - curY;\n go(pos - 1, take + 1, nx[x], ny[x], skip);\n if (retFlag) return;\n } \n }\n \n public void doMain() {\n Scanner sc = new Scanner(new InputStreamReader(System.in));\n N = sc.nextInt();\n \n if (N==3) {\n System.out.println(\"YES\");\n System.out.println(\"0 0\");\n System.out.println(\"1 0\");\n System.out.println(\"0 2\");\n System.exit(0);\n }\n \n isSq = new boolean[100000];\n for (int i=0; i*i < isSq.length; i++)\n isSq[i*i] = true;\n \n lens = new int[11000];\n vx = new int[11000][100];\n vy = new int[11000][100];\n cnt = new int[11000];\n \n int pos = 0;\n skipped = new boolean[N + 2];\n for (int len=1; ; len++) {\n boolean ok = false;\n for (int x=0; x*x <= len; x++) {\n if (!isSq[len-x*x]) continue;\n lens[pos] = len;\n int y = (int)Math.sqrt(len - x*x);\n ok = true;\n \n vx[pos][cnt[pos]] = x;\n vy[pos][cnt[pos]++] = y;\n \n if (x != 0) {\n vx[pos][cnt[pos]] = -x;\n vy[pos][cnt[pos]++] = y;\n }\n \n if (y != 0) {\n vx[pos][cnt[pos]] = x;\n vy[pos][cnt[pos]++] = -y;\n }\n \n if (x != 0 && y != 0) {\n vx[pos][cnt[pos]] = -x;\n vy[pos][cnt[pos]++] = -y;\n }\n }\n if (ok) {\n pos++;\n }\n if (pos == N + 1) break;\n }\n \n int oo = 0, ee = 0, oe = 0;\n for (int i=0; i < N; i++) {\n if (vx[i][0] % 2 == 0 && vy[i][0] % 2 == 0)\n ee++;\n else if (vx[i][0] % 2 == 1 && vy[i][0] % 2 == 1)\n oo++;\n else\n oe++;\n }\n \n int stSkip = 0;\n \n if (oe % 2 == 1) {\n stSkip = 1;\n }\n \n solX = new int[N];\n solY = new int[N];\n \n /*was = new boolean[N+2][LIM][][];\n \n for (int i=0; i < was.length; i++)\n for (int A=0; A {\n int dx, dy;\n double angle;\n \n public Segment(int dx, int dy) {\n this.dx = dx;\n this.dy = dy;\n this.angle = Math.atan2(dy, dx);\n }\n \n public int compareTo(Segment other) {\n return new Double(this.angle).compareTo(new Double(other.angle));\n }\n }\n \n int it = 0;\n boolean retFlag = false;\n \n boolean[] skipped;\n \n void go(int pos, int take, int curX, int curY, int skip) {\n /*if (Math.abs(curX) >= LIM || Math.abs(curY) >= LIM)\n return;*/\n \n if (take == N) {\n if (curX==0 && curY==0) {\n System.out.println(\"YES\");\n \n Segment[] segm = new Segment[N];\n for (int i=0; i < N; i++)\n segm[i] = new Segment(solX[i], solY[i]);\n Arrays.sort(segm);\n int cx=0, cy=0;\n \n for (int i=0; i < N; i++) {\n System.out.println(cx + \" \" + cy);\n cx += segm[i].dx;\n cy += segm[i].dy;\n }\n System.exit(0);\n }\n it++;\n if (it==10000) retFlag = true;\n return;\n }\n\n /*int A = Math.max(Math.abs(curX), Math.abs(curY));\n int B = Math.min(Math.abs(curX), Math.abs(curY));\n if (was[pos][A][B][skip]) {\n return;\n }\n was[pos][A][B][skip] = true;*/\n \n int[] nx = new int[cnt[pos]];\n int[] ny = new int[cnt[pos]];\n int[] dist = new int[cnt[pos]];\n \n for (int x=0; x < cnt[pos]; x++) {\n nx[x] = curX + vx[pos][x];\n ny[x] = curY + vy[pos][x];\n dist[x] = nx[x] * nx[x] + ny[x] * ny[x];\n }\n \n for (int x=0; x + 1 < cnt[pos]; x++)\n for (int y=0; y + 1 < cnt[pos]; y++)\n if (dist[y] > dist[y + 1]) {\n int tmp = nx[y]; nx[y] = nx[y+1]; nx[y+1] = tmp;\n tmp = ny[y]; ny[y] = ny[y+1]; ny[y+1] = tmp;\n tmp = dist[y]; dist[y] = dist[y+1]; dist[y+1] = tmp;\n }\n \n if (skip > 0 && skipped[pos])\n go(pos - 1, take, curX, curY, skip - 1);\n \n if (retFlag) return;\n \n for (int x=0; x < cnt[pos]; x++) {\n solX[take] = nx[x] - curX;\n solY[take] = ny[x] - curY;\n go(pos - 1, take + 1, nx[x], ny[x], skip);\n if (retFlag) return;\n } \n }\n \n public void doMain() {\n Scanner sc = new Scanner(new InputStreamReader(System.in));\n N = sc.nextInt();\n \n if (N==3) {\n System.out.println(\"YES\");\n System.out.println(\"0 0\");\n System.out.println(\"1 0\");\n System.out.println(\"0 2\");\n System.exit(0);\n }\n \n isSq = new boolean[100000];\n for (int i=0; i*i < isSq.length; i++)\n isSq[i*i] = true;\n \n lens = new int[11000];\n vx = new int[11000][100];\n vy = new int[11000][100];\n cnt = new int[11000];\n \n int pos = 0;\n skipped = new boolean[N + 2];\n for (int len=1; ; len++) {\n boolean ok = false;\n for (int x=0; x*x <= len; x++) {\n if (!isSq[len-x*x]) continue;\n lens[pos] = len;\n int y = (int)Math.sqrt(len - x*x);\n ok = true;\n \n vx[pos][cnt[pos]] = x;\n vy[pos][cnt[pos]++] = y;\n \n if (x != 0) {\n vx[pos][cnt[pos]] = -x;\n vy[pos][cnt[pos]++] = y;\n }\n \n if (y != 0) {\n vx[pos][cnt[pos]] = x;\n vy[pos][cnt[pos]++] = -y;\n }\n \n if (x != 0 && y != 0) {\n vx[pos][cnt[pos]] = -x;\n vy[pos][cnt[pos]++] = -y;\n }\n }\n if (ok) {\n pos++;\n }\n if (pos == N + 1) break;\n }\n \n int oo = 0, ee = 0, oe = 0;\n for (int i=0; i < N; i++) {\n if (vx[i][0] % 2 == 0 && vy[i][0] % 2 == 0)\n ee++;\n else if (vx[i][0] % 2 == 1 && vy[i][0] % 2 == 1)\n oo++;\n else\n oe++;\n }\n \n int stSkip = 0;\n \n if (oe % 2 == 1) {\n stSkip = 1;\n }\n \n solX = new int[N];\n solY = new int[N];\n \n /*was = new boolean[N+2][LIM][][];\n \n for (int i=0; i < was.length; i++)\n for (int A=0; A 1) {\n for (int i=0; i < N+1; i++) {\n skipped[i] = true;\n retFlag = false;\n it = 0;\n go(N + skip - 1, 0, 0, 0, skip);\n skipped[i] = false;\n }\n } else {\n retFlag = false;\n it = 0;\n go(N + skip - 1, 0, 0, 0, skip);\n }\n }\n }\n \n public static void main(String[] args) throws Exception {\n new Solution().doMain();\n }\n}\n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3454bc3a09870e4da7ee27e714b44a66", "src_uid": "77b281558c480607b02e8e263e81a455", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.util.*;\n\npublic class E {\n\n\tpublic Object solve () {\n\t\tint N = sc.nextInt() - 1, S = sc.nextInt(), R = sc.nextInt();\n\n\t\tif (N == 0)\n\t\t\treturn exit(1);\n\t\tif (S == 0)\n\t\t\treturn exit(modInv(N+1));\n\n\t\tC = modBin(N, N);\n\t\tlong [] V = modInvs(N+1);\n\n\t\tlong P = 0;\n\t\tfor (int B = R; B <= S; ++B) {\n\t\t\tif (B * (N+1) < S)\n\t\t\t\tcontinue;\n\t\t\tfor (int j = 0; j <= N; ++j) {\n\t\t\t\tint T = S - B * (j+1);\n\t\t\t\tif (T >= 0) {\n\t\t\t\t\tlong D = F(B, N-j, T);\n\t\t\t\t\tif (T > 0)\n\t\t\t\t\t\tD = (D + MOD - F(B, N-j, T-1)) % MOD;\n\t\t\t\t\tlong Z = (C[N][j] * D) % MOD;\n\t\t\t\t\tP = (P + Z * V[j+1]) % MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong Q = F(S-R+1, N, S-R);\n\n\t\tlong res = (P * modInv(Q)) % MOD;\n\t\treturn exit(res);\n\t}\n\n\tlong [][] C;\n\n\tint F(int B, int K, int X) {\n\t\tif (B == 0) return K == 0 ? 1 : 0;\n\n\t\tlong Q = 6000L * (6000 * B + X) + K;\n\t\tInteger R = H.get(Q);\n\t\tif (R != null)\n\t\t\treturn R;\n\n\t\tlong res = 0;\n\t\tfor (int j = 0; j <= K && j * (B-1) <= X; ++j)\n\t\t\tres = (res + C[K][j] * F(B-1, K-j, X - j * (B-1))) % MOD;\n\t\tH.put(Q, (int)res);\n\t\treturn (int)res;\n\t}\n\n\tMap H = new HashMap<>();\n\n\tprivate static final boolean ONE_TEST_CASE = true;\n\n\tprivate static void init () {\n\t}\n\n\tprivate static final int MOD = 998244353;\n\tprivate static long mod (long x) { return mod(x, MOD); }\n\tprivate static long mod (long x, long mod) { return ((x % mod) + mod) % mod; }\n\tprivate static long [][] modBin (int N, int K) {\n\t\tlong [][] res = new long [N+1][K+1];\n\t\tfor (int n = 0; n <= N; ++n) {\n\t\t\tres[n][0] = 1;\n\t\t\tfor (int k = 1; k <= K && k <= n; ++k)\n\t\t\t\tres[n][k] = mod(res[n-1][k] + res[n-1][k-1]);\n\t\t}\n\t\treturn res;\n\t}\n\tprivate static long modInv(long x) { return modInv(x, MOD); }\n\tprivate static long modInv(long x, int mod) { return BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod)).longValue(); }\n\tprivate static long [] modInvs(int N) {\n\t\tlong [] res = new long [N+1];\n\t\tfor (int i = 1; i <= N; ++i)\n\t\t\tres[i] = modInv(i);\n\t\treturn res;\n\t}\n\t//////////////////////////////////////////////////////////////////////////////////// OFF\n\tprivate static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static Object print (Object o, Object ... A) { IOUtils.print(o, A); return null; }\n\tprivate static Object exit (Object o, Object ... A) { print(o, A); IOUtils.exit(); return null; }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next () { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt () { return Integer.parseInt(next()); }\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol () { return index == line.length; }\n\t\t\tprivate String readLine () {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine () {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split (String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build (Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim (String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static final java.text.DecimalFormat formatter = new java.text.DecimalFormat(\"#.#########\");\n\t\tprivate static void start () { if (t == 0) t = millis(); }\n\t\tprivate static void append (java.util.function.Consumer f, java.util.function.Consumer g, final Object o) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tf.accept(java.lang.reflect.Array.get(o, i));\n\t\t\t}\n\t\t\telse if (o instanceof Iterable)\n\t\t\t\t((Iterable)o).forEach(f::accept);\n\t\t\telse\n\t\t\t\tg.accept(o instanceof Double ? formatter.format(o) : o);\n\t\t}\n\t\tprivate static void append (final StringBuilder b, Object o, final String delim) {\n\t\t\tappend(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print (Object o, Object ... A) {\n\t\t\tpw.println(build(o, A));\n\t\t\tif (DEBUG)\n\t\t\t\tpw.flush();\n\t\t}\n\t\tprivate static void err (Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static boolean DEBUG;\n\t\tprivate static void write (Object o) {\n\t\t\terr(o, '(', time(), ')');\n\t\t\tif (!DEBUG)\n\t\t\t\tpw.println(o);\n\t\t}\n\t\tprivate static void exit () {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis () { return System.currentTimeMillis(); }\n\t\tprivate static String time () { return \"Time: \" + (millis() - t) / 1000.0; }\n\t\tprivate static void run (int N) {\n\t\t\ttry { DEBUG = System.getProperties().containsKey(\"DEBUG\"); }\n\t\t\tcatch (Throwable t) {}\n\n\t\t\tfor (int n = 1; n <= N; ++n) {\n\t\t\t\tObject res = new E().solve();\n\t\t\t\tif (res != null)\n\t\t\t\t\twrite(\"Case #\" + n + \": \" + build(res));\n\t\t\t}\n\t\t\texit();\n\t\t}\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tpublic static void main (String[] args) {\n\t\tinit();\n\t\tint N = ONE_TEST_CASE ? 1 : sc.nextInt();\n\t\tIOUtils.run(N);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3982db60cc68422b54d9babeba6cab5c", "src_uid": "609195ef4a970c62a8210dafe118580e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import static java.util.Arrays.*;\n\nimport java.math.*;\n\npublic class E {\n\n\tpublic Object solve () {\n\t\tint N = sc.nextInt() - 1, S = sc.nextInt(), R = sc.nextInt();\n\n\t\tif (N == 0)\n\t\t\treturn exit(1);\n\t\tif (S == 0)\n\t\t\treturn exit(modInv(N+1));\n\n\t\tlong [][] C = modBin(N, N);\n\n\t\tlong P = 0;\n\t\tfor (int b = S; b >= R; --b) {\n\t\t\tif (b * N < S - b)\n\t\t\t\tbreak;\n\n\t\t\tlong [][] F = new long [N+1][S+1]; fill(F[0], 1);\n\t\t\tfor (int k = 1; k <= N; ++k) {\n\t\t\t\tF[k][0] = 1;\n\t\t\t\tfor (int x = 1; x <= S; ++x) {\n\t\t\t\t\tF[k][x] = (F[k][x-1] + F[k-1][x]) % MOD;\n\t\t\t\t\tif (x >= b)\n\t\t\t\t\t\tF[k][x] = (F[k][x] + MOD - F[k-1][x-b]) % MOD;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int j = 0; j <= N; ++j) {\n\t\t\t\tint T = S - b * (j+1);\n\t\t\t\tif (T >= 0) {\n\t\t\t\t\tlong D = F[N-j][T];\n\t\t\t\t\tif (T > 0)\n\t\t\t\t\t\tD = (D + MOD - F[N-j][T-1]) % MOD;\n\t\t\t\t\tlong Z = (C[N][j] * D) % MOD;\n\t\t\t\t\tP = (P + Z * modInv(j+1)) % MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong Q = 0;\n\t\tlong [][] F = new long [N+1][S+1]; fill(F[0], 1);\n\t\tfor (int k = 1; k <= N; ++k) {\n\t\t\tF[k][0] = 1;\n\t\t\tfor (int x = 1; x <= S; ++x)\n\t\t\t\tF[k][x] = (F[k][x-1] + F[k-1][x]) % MOD;\n\t\t}\n\t\tQ = F[N][S-R];\n\n\t\tlong res = (P * modInv(Q)) % MOD;\n\t\treturn exit(res);\n\t}\n\n\tprivate static final boolean ONE_TEST_CASE = true;\n\n\tprivate static void init () {\n\t}\n\n\tprivate static final int MOD = 998244353;\n\tprivate static long mod (long x) { return mod(x, MOD); }\n\tprivate static long mod (long x, long mod) { return ((x % mod) + mod) % mod; }\n\tprivate static long [][] modBin (int N, int K) {\n\t\tlong [][] res = new long [N+1][K+1];\n\t\tfor (int n = 0; n <= N; ++n) {\n\t\t\tres[n][0] = 1;\n\t\t\tfor (int k = 1; k <= K && k <= n; ++k)\n\t\t\t\tres[n][k] = mod(res[n-1][k] + res[n-1][k-1]);\n\t\t}\n\t\treturn res;\n\t}\n\tprivate static long modInv(long x) { return modInv(x, MOD); }\n\tprivate static long modInv(long x, int mod) { return BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod)).longValue(); }\n\t//////////////////////////////////////////////////////////////////////////////////// OFF\n\tprivate static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static Object print (Object o, Object ... A) { IOUtils.print(o, A); return null; }\n\tprivate static Object exit (Object o, Object ... A) { print(o, A); IOUtils.exit(); return null; }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next () { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt () { return Integer.parseInt(next()); }\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol () { return index == line.length; }\n\t\t\tprivate String readLine () {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine () {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split (String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build (Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim (String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static final java.text.DecimalFormat formatter = new java.text.DecimalFormat(\"#.#########\");\n\t\tprivate static void start () { if (t == 0) t = millis(); }\n\t\tprivate static void append (java.util.function.Consumer f, java.util.function.Consumer g, final Object o) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tf.accept(java.lang.reflect.Array.get(o, i));\n\t\t\t}\n\t\t\telse if (o instanceof Iterable)\n\t\t\t\t((Iterable)o).forEach(f::accept);\n\t\t\telse\n\t\t\t\tg.accept(o instanceof Double ? formatter.format(o) : o);\n\t\t}\n\t\tprivate static void append (final StringBuilder b, Object o, final String delim) {\n\t\t\tappend(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print (Object o, Object ... A) {\n\t\t\tpw.println(build(o, A));\n\t\t\tif (DEBUG)\n\t\t\t\tpw.flush();\n\t\t}\n\t\tprivate static void err (Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static boolean DEBUG;\n\t\tprivate static void write (Object o) {\n\t\t\terr(o, '(', time(), ')');\n\t\t\tif (!DEBUG)\n\t\t\t\tpw.println(o);\n\t\t}\n\t\tprivate static void exit () {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis () { return System.currentTimeMillis(); }\n\t\tprivate static String time () { return \"Time: \" + (millis() - t) / 1000.0; }\n\t\tprivate static void run (int N) {\n\t\t\ttry { DEBUG = System.getProperties().containsKey(\"DEBUG\"); }\n\t\t\tcatch (Throwable t) {}\n\n\t\t\tfor (int n = 1; n <= N; ++n) {\n\t\t\t\tObject res = new E().solve();\n\t\t\t\tif (res != null)\n\t\t\t\t\twrite(\"Case #\" + n + \": \" + build(res));\n\t\t\t}\n\t\t\texit();\n\t\t}\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tpublic static void main (String[] args) {\n\t\tinit();\n\t\tint N = ONE_TEST_CASE ? 1 : sc.nextInt();\n\t\tIOUtils.run(N);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2b42d260ec37e10755da99b68a98ec13", "src_uid": "609195ef4a970c62a8210dafe118580e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "/**\n * @author derrick20\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class TopScorer {\n public static void main(String[] args) throws Exception {\n FastScanner sc = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n\n int P = sc.nextInt();\n int S = sc.nextInt();\n int R = sc.nextInt();\n // it should go up to s + p - 1, 5099, but let's be safe\n int MAX = (int) 1e5; // todo change this!\n fact = new long[MAX + 1];\n invFact = new long[MAX + 1];\n fact[0] = 1;\n invFact[0] = 1;\n for (int i = 1; i <= MAX; i++) {\n fact[i] = ((long) i * fact[i - 1]) % mod;\n invFact[i] = inv(fact[i]);\n }\n\n if (P == 1) {\n out.println(1);\n } else {\n // O(SP^2) = 5*10^7\n long wins = 0;\n long total = 0;\n for (int x = R; x <= S; x++) {\n // l = group that gets x\n // the remaining players P - 1 - l must get < x.\n for (int l = 0; P - 1 - l >= 0 && S - x - l * x >= 0; l++) {\n int players = P - 1 - l;\n int balls = S - x - l * x;\n// System.out.println(\"Forced \" + l + \" other players to have exactly \" + x + \" balls\");\n// System.out.println(\"Remaining: players = \" + players + \" balls = \" + balls);\n long prob = (choose(P - 1, l) * f(players, balls, x)) % mod;\n // prob of having this number of x's for players, then given\n // that, the probability of winning is uniform among all x players\n long contrib = (inv(l + 1) * prob) % mod;\n wins = (wins + contrib) % mod;\n// System.out.println(\"Prob: \" + prob + \" Contrib: \" + contrib);\n// System.out.println();\n }\n long ways = choose(S - x + P - 2, P - 2);\n// System.out.println(\"Ways for x = \" + x + \" = \" + ways);\n// System.out.println(\"----------\");\n total = (total + ways) % mod;\n }\n // we have now counted the number of winning states (scaling\n // with the f function). The probability is this divided by total\n // states.\n long prob = (wins * inv(total)) % mod;\n out.println(prob);\n }\n out.close();\n }\n\n // todo SET THE MOD\n static long mod = 998244353;\n static long[] fact, invFact;\n\n // f returns probability that with these parameters, we get an assignment\n // where all have < x balls.\n static long f(int players, int balls, int x) {\n // if there are no players, there MUST BE only 1 way.\n if (players == 0) {\n// ASSERT(balls <= x, \"Gave impossible amt\");\n return (balls <= x) ? 1 : 0;\n }\n long total = choose(balls + players - 1, players - 1);\n long complement = 0;\n int sign = 1;\n for (int k = 1; k <= players && balls - k * x >= 0; k++) {\n long amt = (choose(players, k) * choose(balls - k * x + players - 1, players - 1)) % mod;\n complement = (complement + sign * amt) % mod;\n sign *= -1;\n }\n// System.out.println(\"Ways for (players, balls) = \" + players + \" \" + balls + \": Total \" + total + \", Complement: \" + complement);\n long ans = (total - complement + mod) % mod;\n// ans = (ans * inv(total)) % mod; // probability\n return ans;\n }\n\n static long choose(int n, int k) {\n ASSERT(k <= n, \"Invalid choose\");\n long ans = (fact[n] * invFact[n - k]) % mod;\n return (ans * invFact[k]) % mod;\n }\n\n static long inv(long x) {\n return fastExpo(x, mod - 2);\n }\n\n static long fastExpo(long x, long k) {\n long ans = 1;\n long bit = x;\n while (k > 0) {\n if (k % 2 == 1) {\n ans = (bit * ans) % mod;\n }\n bit = (bit * bit) % mod;\n k /= 2;\n }\n return ans;\n }\n\n static class FastScanner {\n private int BS = 1 << 16;\n private char NC = (char) 0;\n private byte[] buf = new byte[BS];\n private int bId = 0, size = 0;\n private char c = NC;\n private double cnt = 1;\n private BufferedInputStream in;\n\n public FastScanner() {\n in = new BufferedInputStream(System.in, BS);\n }\n\n public FastScanner(String s) {\n try {\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n } catch (Exception e) {\n in = new BufferedInputStream(System.in, BS);\n }\n }\n\n private char getChar() {\n while (bId == size) {\n try {\n size = in.read(buf);\n } catch (Exception e) {\n return NC;\n }\n if (size == -1) return NC;\n bId = 0;\n }\n return (char) buf[bId++];\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextInts(int N) {\n int[] res = new int[N];\n for (int i = 0; i < N; i++) {\n res[i] = (int) nextLong();\n }\n return res;\n }\n\n public long[] nextLongs(int N) {\n long[] res = new long[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n public long nextLong() {\n cnt = 1;\n boolean neg = false;\n if (c == NC) c = getChar();\n for (; (c < '0' || c > '9'); c = getChar()) {\n if (c == '-') neg = true;\n }\n long res = 0;\n for (; c >= '0' && c <= '9'; c = getChar()) {\n res = (res << 3) + (res << 1) + c - '0';\n cnt *= 10;\n }\n return neg ? -res : res;\n }\n\n public double nextDouble() {\n double cur = nextLong();\n return c != '.' ? cur : cur + nextLong() / cnt;\n }\n\n public double[] nextDoubles(int N) {\n double[] res = new double[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextDouble();\n }\n return res;\n }\n\n public String next() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c > 32) {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public String nextLine() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c != '\\n') {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public boolean hasNext() {\n if (c > 32) return true;\n while (true) {\n c = getChar();\n if (c == NC) return false;\n else if (c > 32) return true;\n }\n }\n }\n\n static void ASSERT(boolean assertion, String message) {\n if (!assertion) throw new AssertionError(message);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "067eae16253a14a888cdf79d674541df", "src_uid": "609195ef4a970c62a8210dafe118580e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class E {\n public static int mod = 998244353;\n public static int[] fact;\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= r;\n int sign = 1;\n fact = new int[6001];\n fact[0] = 1;\n for(int i=1; i<=6000; i++) {\n fact[i] = (int)(1L*fact[i-1]*i % mod);\n }\n for(int i=1; i<=p; i++) {\n\n if(i < p) PIE += sign*(1L*choose(p, i)*choose(s - i*r + p-i-1, p-i-1) % mod);\n else PIE += sign*1;\n PIE += mod;\n PIE %= mod;\n\n\n sign = -1*sign;\n }\n\n long ways_first = choose(s-r+p-2, p-2) % mod;\n long ans = frac((int)PIE, (int)((1L * ways_first * p) % mod));\n out.println(ans);\n\n // int n = scan.nextInt();\n\n out.close(); System.exit(0);\n }\n public static int exp(int base, int e) {\n if(e == 0) return 1;\n if(e == 1) return base;\n int val = exp(base, e/2);\n int ans = (int)(1L*val*val % mod);\n if(e % 2 == 1)\n ans = (int)(1L*ans*base % mod);\n return ans;\n }\n public static int inv(int base) {\n return exp(base, mod-2);\n }\n public static long frac(int p, int q) {\n return (1L*p*inv(q) % mod);\n }\n public static long choose(int a, int b) {\n if(a tryToSolve(int permutationSize, String s) {\n MegaComparator megaComparator = new MegaComparator(s);\n int[] a = IntStream.range(0, permutationSize).toArray();\n int[] b = new int[permutationSize];\n mergeSort(0, permutationSize, megaComparator, a, b);\n return Optional.of(a)\n .filter(perm -> megaComparator.allDone())\n .map(E::getPermutation);\n }\n\n private static int[] getPermutation(int[] a) {\n int[] result = new int[a.length];\n for (int i = 0; i < a.length; i++) {\n result[a[i]] = i + 1;\n }\n return result;\n }\n\n private void solve() throws Exception {\n String s = fastScanner.next();\n int[] result = tryToSolve(16, s).orElseThrow(() -> new RuntimeException(\"GG\"));\n printWriter.println(16);\n printWriter.println(Arrays.stream(result).mapToObj(String::valueOf).collect(Collectors.joining(\" \")));\n }\n\n private static class MegaComparator {\n private final String data;\n private int pointer;\n\n public MegaComparator(String data) {\n this.data = data;\n this.pointer = 0;\n }\n\n public boolean allDone() {\n return pointer == data.length();\n }\n\n public boolean compare() {\n return data.charAt(pointer++) == '0';\n }\n }\n\n\n private static class FastScanner implements Closeable {\n private final BufferedReader bufferedReader;\n private StringTokenizer stringTokenizer;\n\n public FastScanner(InputStream inputStream) {\n this(new BufferedReader(new InputStreamReader(inputStream)));\n }\n\n public FastScanner(BufferedReader bufferedReader) {\n this.bufferedReader = bufferedReader;\n }\n\n public String next() throws IOException {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n String line = bufferedReader.readLine();\n if (line == null) {\n return null;\n }\n stringTokenizer = new StringTokenizer(line);\n }\n return stringTokenizer.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 @Override\n public void close() throws IOException {\n this.bufferedReader.close();\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dc46d572e7edb68fd81d9648911fc3c7", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8", "difficulty": -1.0} {"lang": "Java 8", "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.*;\r\n\r\npublic class Template {\r\n\r\n static BufferedReader br;\r\n static PrintWriter out;\r\n static StringTokenizer st;\r\n static boolean[][] e = new boolean[20][20];\r\n static boolean[] used = new boolean[20];\r\n static List ans = new ArrayList<>();\r\n\r\n static int solve(List arr, int l, int r, int index, String flags) {\r\n int m = (l + r) >> 1;\r\n\r\n if(l == r - 1) {\r\n return index;\r\n }\r\n\r\n index = solve(arr, l, m, index, flags);\r\n index = solve(arr, m, r, index, flags);\r\n int i = l;\r\n int j = m;\r\n List tmp = new LinkedList<>();\r\n while (i < m && j < r) {\r\n if (flags.charAt(index++) == '0') {\r\n e[arr.get(i)][arr.get(j)] = true;\r\n tmp.add(arr.get(i));\r\n i += 1;\r\n }\r\n else {\r\n e[arr.get(j)][arr.get(i)] = true;\r\n tmp.add(arr.get(j));\r\n j++;\r\n }\r\n }\r\n for (int k = 0; k < tmp.size(); k++) {\r\n arr.set(l + k, tmp.get(k));\r\n }\r\n return index;\r\n }\r\n\r\n static void dfs (int v) {\r\n used[v] = true;\r\n// for (int i=0; i arr = new ArrayList<>();\r\n for(int i = 0; i < 16; i++) {\r\n arr.add(i);\r\n }\r\n solve(arr, 0, 16, 0, flags);\r\n topological_sort();\r\n\r\n out.println(ans.size());\r\n for(int i = ans.size() - 1; i >= 0; i--) {\r\n out.print(ans.get(i) + 1);\r\n out.print(\" \");\r\n }\r\n out.close();\r\n }\r\n\r\n static String next() throws IOException {\r\n while (st == null || !st.hasMoreTokens())\r\n st = new StringTokenizer(br.readLine().trim());\r\n return st.nextToken();\r\n }\r\n\r\n static long readLong() throws IOException {\r\n return Long.parseLong(next());\r\n }\r\n\r\n static int readInt() throws IOException {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n static double readDouble() throws IOException {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n static char readCharacter() throws IOException {\r\n return next().charAt(0);\r\n }\r\n\r\n static String readLine() throws IOException {\r\n return br.readLine().trim();\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa9ba98da360492311014617c7550170", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8", "difficulty": -1.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\nimport java.util.Map.Entry;\r\nimport java.math.BigInteger;\r\n\r\nimport static java.lang.Math.*;\r\n\r\npublic class Solution extends PrintWriter {\r\n\r\n\tclass Node {\r\n\t\tfinal int f, t;\r\n\t\tfinal Node l, r;\r\n\r\n\t\tList subLog = new ArrayList<>();\r\n\r\n\t\tpublic Node(int f, int t, Node l, Node r) {\r\n\t\t\tthis.f = f;\r\n\t\t\tthis.t = t;\r\n\t\t\tthis.l = l;\r\n\t\t\tthis.r = r;\r\n\t\t}\r\n\r\n\t\tint assign(boolean[] log, int p) {\r\n\t\t\tif (l == r) {\r\n\t\t\t\treturn p;\r\n\t\t\t}\r\n\r\n\t\t\tp = l.assign(log, p);\r\n\t\t\tp = r.assign(log, p);\r\n\r\n\t\t\tint ls = l.t - l.f;\r\n\t\t\tint rs = r.t - r.f;\r\n\t\t\twhile (ls > 0 && rs > 0) {\r\n\t\t\t\tboolean c = log[p++];\r\n\t\t\t\tsubLog.add(c);\r\n\t\t\t\tif (c) {\r\n\t\t\t\t\t--rs;\r\n\t\t\t\t} else {\r\n\t\t\t\t\t--ls;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn p;\r\n\t\t}\r\n\r\n\t\tvoid solve(List inp, List out) {\r\n\t\t\tif (l == r) {\r\n\t\t\t\tout.addAll(inp);\r\n\t\t\t} else {\r\n\r\n\t\t\t\tint ls = l.t - l.f;\r\n\t\t\t\tint rs = r.t - r.f;\r\n\r\n\t\t\t\tList lnum = new ArrayList<>();\r\n\t\t\t\tList rnum = new ArrayList<>();\r\n\r\n\t\t\t\tint p = 0;\r\n\r\n\t\t\t\tfor (boolean b : subLog) {\r\n\t\t\t\t\tif (b) {\r\n\t\t\t\t\t\trnum.add(inp.get(p++));\r\n\t\t\t\t\t\t--rs;\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tlnum.add(inp.get(p++));\r\n\t\t\t\t\t\t--ls;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\twhile (p < inp.size()) {\r\n\t\t\t\t\tif (ls > 0) {\r\n\t\t\t\t\t\tlnum.add(inp.get(p++));\r\n\t\t\t\t\t\t--ls;\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\trnum.add(inp.get(p++));\r\n\t\t\t\t\t\t--rs;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (ls != 0 || rs != 0) {\r\n\t\t\t\t\tthrow new IllegalStateException();\r\n\t\t\t\t}\r\n\r\n\t\t\t\tl.solve(lnum, out);\r\n\t\t\t\tr.solve(rnum, out);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tNode build(int f, int t) {\r\n\t\tif (t - f <= 1) {\r\n\t\t\treturn new Node(f, t, null, null);\r\n\t\t}\r\n\r\n\t\tint m = (f + t) >> 1;\r\n\t\treturn new Node(f, t, build(f, m), build(m, t));\r\n\t}\r\n\r\n\tvoid mergeSort(int[] a, int[] b, int l, int r, StringBuilder log) {\r\n\t\tif (r - l <= 1) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tint m = (l + r) >> 1;\r\n\t\tmergeSort(a, b, l, m, log);\r\n\t\tmergeSort(a, b, m, r, log);\r\n\r\n\t\tint i = l, j = m, k = l;\r\n\r\n\t\twhile (i < m && j < r) {\r\n\t\t\tif (a[i] < a[j]) {\r\n\t\t\t\tlog.append('0');\r\n\t\t\t\tb[k] = a[i];\r\n\t\t\t\ti += 1;\r\n\t\t\t} else {\r\n\t\t\t\tlog.append('1');\r\n\t\t\t\tb[k] = a[j];\r\n\t\t\t\tj += 1;\r\n\t\t\t}\r\n\t\t\tk += 1;\r\n\t\t}\r\n\t\twhile (i < m) {\r\n\t\t\tb[k] = a[i];\r\n\t\t\ti += 1;\r\n\t\t\tk += 1;\r\n\t\t}\r\n\t\twhile (j < r) {\r\n\t\t\tb[k] = a[j];\r\n\t\t\tj += 1;\r\n\t\t\tk += 1;\r\n\t\t}\r\n\r\n\t\tfor (int p = l; p < r; p++) {\r\n\t\t\ta[p] = b[p];\r\n\r\n\t\t}\r\n\r\n\t}\r\n\r\n\tvoid runsort() {\r\n\t\tfor (int n = 5; n <= 5; n++) {\r\n\t\t\tint[] a = new int[n];\r\n\t\t\tint[] b = new int[n];\r\n\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tint j = rnd.nextInt(i + 1);\r\n\t\t\t\ta[i] = a[j];\r\n\t\t\t\ta[j] = i;\r\n\t\t\t}\r\n\r\n\t\t\tprintln(Arrays.toString(a));\r\n\t\t\tStringBuilder log = new StringBuilder();\r\n\t\t\tmergeSort(a, b, 0, n, log);\r\n\r\n\t\t\tprintln(n + \" \" + log.length());\r\n\t\t\tprintln(log);\r\n\r\n\t\t}\r\n\t}\r\n\r\n\tvoid run() {\r\n\t\tString str = next();\r\n\t\tint m = str.length();\r\n\t\tboolean[] log = new boolean[m];\r\n\r\n\t\tfor (int i = 0; i < m; i++) {\r\n\t\t\tlog[i] = str.charAt(i) == '1';\r\n\t\t}\r\n\r\n\t\tfor (int n = 1;; n++) {\r\n\t\t\ttry {\r\n\t\t\t\tNode root = build(0, n);\r\n\t\t\t\tif (root.assign(log, 0) != m) {\r\n\t\t\t\t\tthrow new IllegalStateException();\r\n\t\t\t\t}\r\n\r\n\t\t\t\tList inp = new ArrayList<>();\r\n\t\t\t\tList out = new ArrayList<>();\r\n\r\n\t\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\t\tinp.add(i);\r\n\t\t\t\t}\r\n\r\n\t\t\t\troot.solve(inp, out);\r\n\r\n\t\t\t\tprintln(out.size());\r\n\t\t\t\tfor (int val : out) {\r\n\t\t\t\t\tprint(val + \" \");\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn;\r\n\r\n\t\t\t} catch (RuntimeException err) {\r\n\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t}\r\n\r\n\tpublic static boolean nextPermutation(int[] permutation) {\r\n\t\tint n = permutation.length, a = n - 2;\r\n\t\twhile (0 <= a && permutation[a] >= permutation[a + 1]) {\r\n\t\t\ta--;\r\n\t\t}\r\n\t\tif (a == -1) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tint b = n - 1;\r\n\t\twhile (permutation[b] <= permutation[a]) {\r\n\t\t\tb--;\r\n\t\t}\r\n\r\n\t\tswap(permutation, a, b);\r\n\t\tfor (int i = a + 1, j = n - 1; i < j; i++, j--) {\r\n\t\t\tswap(permutation, i, j);\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic static void swap(int[] array, int i, int j) {\r\n\t\tif (i == j) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tarray[i] ^= array[j];\r\n\t\tarray[j] ^= array[i];\r\n\t\tarray[i] ^= array[j];\r\n\t}\r\n\r\n\tString next() {\r\n\t\twhile (!tokenizer.hasMoreTokens())\r\n\t\t\ttokenizer = new StringTokenizer(nextLine());\r\n\t\treturn tokenizer.nextToken();\r\n\t}\r\n\r\n\tboolean hasNext() {\r\n\t\twhile (!tokenizer.hasMoreTokens()) {\r\n\t\t\tString line = nextLine();\r\n\t\t\tif (line == null) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\ttokenizer = new StringTokenizer(line);\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tint[] nextArray(int n) {\r\n\t\tint[] array = new int[n];\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\tarray[i] = nextInt();\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\tint nextInt() {\r\n\t\treturn Integer.parseInt(next());\r\n\t}\r\n\r\n\tlong nextLong() {\r\n\t\treturn Long.parseLong(next());\r\n\t}\r\n\r\n\tdouble nextDouble() {\r\n\t\treturn Double.parseDouble(next());\r\n\t}\r\n\r\n\tString nextLine() {\r\n\t\ttry {\r\n\t\t\treturn reader.readLine();\r\n\t\t} catch (IOException err) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic Solution(OutputStream outputStream) {\r\n\t\tsuper(outputStream);\r\n\t}\r\n\r\n\tstatic BufferedReader reader;\r\n\tstatic StringTokenizer tokenizer = new StringTokenizer(\"\");\r\n\tstatic Random rnd = new Random();\r\n\r\n\tpublic static void main(String[] args) throws IOException {\r\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tSolution solution = new Solution(System.out);\r\n\t\tsolution.run();\r\n\t\tsolution.close();\r\n\t\treader.close();\r\n\t}\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a3680c05f9b6347ab3c87139de211cb2", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8", "difficulty": -1.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.math.BigInteger;\r\nimport java.util.*;\r\n\r\n\r\npublic class E {\r\n\r\n void solve() throws IOException {\r\n char[] c = reader.readLine().toCharArray();\r\n for (int i = 1; i <= 10000; i++) {\r\n int[] a = doit(i, c);\r\n if (a != null) {\r\n for (int j = 0; j < a.length; j++) {\r\n out.print(a[j] + \" \");\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n int[] doit(int n, char[] c) {\r\n index = 0;\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 && index == c.length) {\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 } else {\r\n return null;\r\n }\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 E().run();\r\n }\r\n\r\n void run() throws IOException {\r\n reader = new BufferedReader(new InputStreamReader(System.in));\r\n//\t\treader = new BufferedReader(new FileReader(\"input.txt\"));\r\n tokenizer = null;\r\n out = new PrintWriter(new OutputStreamWriter(System.out));\r\n//\t\tout = new PrintWriter(new FileWriter(\"output.txt\"));\r\n solve();\r\n reader.close();\r\n out.flush();\r\n\r\n }\r\n\r\n BufferedReader reader;\r\n StringTokenizer tokenizer;\r\n PrintWriter out;\r\n\r\n int nextInt() throws IOException {\r\n return Integer.parseInt(nextToken());\r\n }\r\n\r\n long nextLong() throws IOException {\r\n return Long.parseLong(nextToken());\r\n }\r\n\r\n double nextDouble() throws IOException {\r\n return Double.parseDouble(nextToken());\r\n }\r\n\r\n int[] nextIntArray(int n) throws IOException {\r\n int[] result = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n result[i] = nextInt();\r\n }\r\n return result;\r\n }\r\n\r\n long[] nextLongArray(int n) throws IOException {\r\n long[] result = new long[n];\r\n for (int i = 0; i < n; i++) {\r\n result[i] = nextLong();\r\n }\r\n return result;\r\n }\r\n\r\n double[] nextDoubleArray(int n) throws IOException {\r\n double[] result = new double[n];\r\n for (int i = 0; i < n; i++) {\r\n result[i] = nextDouble();\r\n }\r\n return result;\r\n }\r\n\r\n int[][] nextIntArray(int n, int m) throws IOException {\r\n int[][] result = new int[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n result[i][j] = nextInt();\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n long[][] nextLongArray(int n, int m) throws IOException {\r\n long[][] result = new long[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n result[i][j] = nextLong();\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n double[][] nextDoubleArray(int n, int m) throws IOException {\r\n double[][] result = new double[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n result[i][j] = nextDouble();\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n String nextToken() throws IOException {\r\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\r\n tokenizer = new StringTokenizer(reader.readLine());\r\n }\r\n return tokenizer.nextToken();\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f80aacc1a51a511ad22e76926700ec7d", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8", "difficulty": -1.0} {"lang": "Java 7", "source_code": "import java.util.Map;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ogiekako\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tMyScanner in = new MyScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n long[] fib;\n Map map;\n\n public void solve(int testNumber, MyScanner in, PrintWriter out) {\n int t = in.nextInt();\n int n = in.nextInt();\n long[] u = new long[t];\n long[] v = new long[t];\n for (int i = 0; i < t; i++){\n u[i] = in.nextLong();\n v[i] = in.nextLong();\n }\n long[] res= solve(u,v,n);\n for(long r:res)out.println(r);\n }\n private long[] solve(long[] u, long[] v, int n){\n n = Math.min(n, 85);\n fib = new long[n + 1];\n for (int i = 0; i <= n; i++) {\n fib[i] = i <= 1 ? i + 1 : fib[i - 1] + fib[i - 2];\n }\n// map = new TreeMap();\n map = new HashMap();\n long[]res =new long[u.length];\n for (int i = 0; i < u.length; i++) {\n map.clear();\n// if(i%1000==0) System.err.println(i);\n res[i] = solve(u[i],v[i],n);\n }\n return res;\n }\n\n class State implements Comparable {\n State(long i, long j, int n) {\n this.i = i;\n this.j = j;\n this.n = n;\n }\n\n long i, j;\n int n;\n\n public int compareTo(State o) {\n if (i != o.i) return Long.compare(i, o.i);\n if (j != o.j) return Long.compare(j, o.j);\n return Integer.compare(n, o.n);\n }\n\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n State state = (State) o;\n\n if (i != state.i) return false;\n if (j != state.j) return false;\n if (n != state.n) return false;\n\n return true;\n }\n\n public int hashCode() {\n int result = (int) (i ^ (i >>> 32));\n result = 31 * result + (int) (j ^ (j >>> 32));\n result = 31 * result + n;\n return result;\n }\n }\n\n private long solve(long i, long j, int n) {\n if (i > j) return solve(j, i, n);\n if (j > fib[n]) throw new AssertionError();\n if (n == 0) return 0;\n if (n == 1) return i != j ? 1 : 0;\n State cur = new State(i, j, n);\n Long res = map.get(cur);\n if (res != null) return res;\n if (j <= fib[n - 1]) res = Math.min(\n solve(i, j, n - 1),\n Math.min(\n solve(i, 1, n - 1) + solve(j, fib[n - 1], n - 1) + 2,\n solve(i, fib[n - 1], n - 1) + solve(j, 1, n - 1) + 2\n )\n );\n else if (i <= fib[n - 1]) res = Math.min(\n solve(i, 1, n - 1) + solve(1, j - fib[n - 1], n - 2) + 1,\n solve(i, fib[n - 1], n - 1) + solve(1, j - fib[n - 1], n - 2) + 1\n );\n else res = solve(i - fib[n - 1], j - fib[n - 1], n - 2);\n map.put(cur, res);\n return res;\n }\n\n }\n\nclass MyScanner {\n private final InputStream in;\n public MyScanner(InputStream in){\n this.in = in;\n }\n\n public int nextInt(){\n\t\ttry{\n\t\t\tint c=in.read();\n\t\t\tif(c==-1) return c;\n\t\t\twhile(c!='-'&&(c<'0'||'9' map1[];\n Map map2[];\n\n public void solve(int testNumber, MyScanner in, PrintWriter out) {\n int t = in.nextInt();\n int n = in.nextInt();\n long[] u = new long[t];\n long[] v = new long[t];\n for (int i = 0; i < t; i++) {\n u[i] = in.nextLong();\n v[i] = in.nextLong();\n }\n long[] res = solve(u, v, n);\n for (long r : res) out.println(r);\n }\n\n private long[] solve(long[] u, long[] v, int n) {\n n = Math.min(n, 80);\n fib = new long[n + 1];\n for (int i = 0; i <= n; i++) {\n fib[i] = i <= 1 ? i + 1 : fib[i - 1] + fib[i - 2];\n }\n map1 = new HashMap[n + 1];\n map2 = new HashMap[n + 1];\n for (int i = 0; i < n + 1; i++) map1[i] = new HashMap();\n for (int i = 0; i < n + 1; i++) map2[i] = new HashMap();\n long[] res = new long[u.length];\n for (int i = 0; i < u.length; i++) {\n for (Map m : map1) m.clear();\n res[i] = solve(u[i], v[i], n);\n }\n return res;\n }\n\n class State {\n // BigInteger val;\n State(long i, long j, int n) {\n this.i = i;\n this.j = j;\n this.n = n;\n// val = BigInteger.valueOf(i).shiftLeft(128).and(BigInteger.valueOf(j).shiftLeft(64)).and(BigInteger.valueOf(n));\n }\n\n long i, j;\n int n;\n\n public boolean equals(Object o) {\n State state = (State) o;\n if (i != state.i) return false;\n if (j != state.j) return false;\n if (n != state.n) return false;\n return true;\n// return val.equals(state.val);\n }\n\n int hash = -1;\n\n public int hashCode() {\n if (hash != -1) return hash;\n int result = (int) (i ^ (i >>> 32));\n result = 31 * result + (int) (j ^ (j >>> 32));\n result = 31 * result + n;\n return hash = result;\n }\n }\n\n int TH = 25;\n\n private long solve(long i, long j, int n) {\n if (i > j) return solve(j, i, n);\n if (n <= 1) return i != j ? 1 : 0;\n\n Long res;\n Map map;\n Object cur;\n if (n < TH) {\n cur = i << 40 ^ j << 6 ^ n;\n map = map2[n];\n res = (Long) map.get(cur);\n if (res != null) return res;\n } else {\n cur = new State(i, j, n);\n map = map1[n];\n res = (Long) map.get(cur);\n if (res != null) return res;\n }\n\n long f = fib[n - 1];\n\n if (j <= f) res = Math.min(\n solve(i, j, n - 1),\n Math.min(\n solve(i, 1, n - 1) + solve(j, f, n - 1) + 2,\n solve(i, f, n - 1) + solve(j, 1, n - 1) + 2\n )\n );\n else if (i <= f) res = Math.min(\n solve(i, 1, n - 1) + solve(1, j - f, n - 2) + 1,\n solve(i, f, n - 1) + solve(1, j - f, n - 2) + 1\n );\n else res = solve(i - f, j - f, n - 2);\n map.put(cur, res);\n return res;\n }\n\n\n }\n\nclass MyScanner {\n private final InputStream in;\n public MyScanner(InputStream in){\n this.in = in;\n }\n\n public int nextInt(){\n\t\ttry{\n\t\t\tint c=in.read();\n\t\t\tif(c==-1) return c;\n\t\t\twhile(c!='-'&&(c<'0'||'9' map;\n\n public void solve(int testNumber, MyScanner in, PrintWriter out) {\n int t = in.nextInt();\n int n = in.nextInt();\n long[] u = new long[t];\n long[] v = new long[t];\n for (int i = 0; i < t; i++){\n u[i] = in.nextInt();\n v[i] = in.nextInt();\n }\n long[] res= solve(u,v,n);\n for(long r:res)out.println(r);\n }\n private long[] solve(long[] u, long[] v, int n){\n n = Math.min(n, 85);\n fib = new long[n + 1];\n for (int i = 0; i <= n; i++) {\n fib[i] = i <= 1 ? i + 1 : fib[i - 1] + fib[i - 2];\n }\n// map = new TreeMap();\n map = new HashMap();\n long[]res =new long[u.length];\n for (int i = 0; i < u.length; i++) {\n map.clear();\n// if(i%1000==0) System.err.println(i);\n res[i] = solve(u[i],v[i],n);\n }\n return res;\n }\n\n class State implements Comparable {\n State(long i, long j, int n) {\n this.i = i;\n this.j = j;\n this.n = n;\n }\n\n long i, j;\n int n;\n\n public int compareTo(State o) {\n if (i != o.i) return Long.compare(i, o.i);\n if (j != o.j) return Long.compare(j, o.j);\n return Integer.compare(n, o.n);\n }\n\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n State state = (State) o;\n\n if (i != state.i) return false;\n if (j != state.j) return false;\n if (n != state.n) return false;\n\n return true;\n }\n\n public int hashCode() {\n int result = (int) (i ^ (i >>> 32));\n result = 31 * result + (int) (j ^ (j >>> 32));\n result = 31 * result + n;\n return result;\n }\n }\n\n private long solve(long i, long j, int n) {\n if (i > j) return solve(j, i, n);\n if (j > fib[n]) throw new AssertionError();\n if (n == 0) return 0;\n if (n == 1) return i != j ? 1 : 0;\n State cur = new State(i, j, n);\n Long res = map.get(cur);\n if (res != null) return res;\n if (j <= fib[n - 1]) res = Math.min(\n solve(i, j, n - 1),\n Math.min(\n solve(i, 1, n - 1) + solve(j, fib[n - 1], n - 1) + 2,\n solve(i, fib[n - 1], n - 1) + solve(j, 1, n - 1) + 2\n )\n );\n else if (i <= fib[n - 1]) res = Math.min(\n solve(i, 1, n - 1) + solve(1, j - fib[n - 1], n - 2) + 1,\n solve(i, fib[n - 1], n - 1) + solve(1, j - fib[n - 1], n - 2) + 1\n );\n else res = solve(i - fib[n - 1], j - fib[n - 1], n - 2);\n map.put(cur, res);\n return res;\n }\n\n }\n\nclass MyScanner {\n private final InputStream in;\n public MyScanner(InputStream in){\n this.in = in;\n }\n\n public int nextInt(){\n\t\ttry{\n\t\t\tint c=in.read();\n\t\t\tif(c==-1) return c;\n\t\t\twhile(c!='-'&&(c<'0'||'9' y) return solve(y, x, n);\n for (int i = 0; i < n + 1; i++) Arrays.fill(first[i], -1);\n for (int i = 0; i < n + 1; i++) Arrays.fill(last[i], -1);\n return dfs(x, y, n);\n }\n\n private long dfs(long x, long y, int n) {\n if (n == 0) return 0;\n if (n == 1) return x == y ? 0 : 1;\n long f = D[n - 1];\n if (y <= f) {\n long d1 = dfs(x, y, n - 1);\n long d2 = first(0, x, n - 1) + last(1, y, n - 1) + 2;\n long d3 = last(0, x, n - 1) + first(1, y, n - 1) + 2;\n return Math.min(d1, Math.min(d2, d3));\n } else if (x > f) {\n return dfs(x - f, y - f, n - 2);\n } else {\n long d1 = first(1, y - f, n - 2) + first(0, x, n - 1) + 1;\n long d2 = first(1, y - f, n - 2) + last(0, x, n - 1) + 1;\n return Math.min(d1, d2);\n }\n }\n\n private long last(int type, long x, int n) {\n if (n == 0) return 0;\n if (n == 1) return x == 2 ? 0 : 1;\n if (last[n][type] >= 0) return last[n][type];\n long f = D[n - 1];\n long res;\n if (x <= f) {\n long d1 = first(type, x, n - 1) + last(2, 1, n - 2) + 1;\n long d2 = last(type, x, n - 1) + last(2, 1, n - 2) + 1;\n res = Math.min(d1, d2);\n } else {\n res = last(type, x - f, n - 2);\n }\n return last[n][type] = res;\n }\n\n private long first(int type, long x, int n) {\n if (n == 0) return 0;\n if (n == 1) return x == 1 ? 0 : 1;\n if (first[n][type] >= 0) return first[n][type];\n long f = D[n - 1];\n long res;\n if (x <= f) {\n long d1 = first(type, x, n - 1);\n long d2 = last(type, x, n - 1) + 2;\n res = Math.min(d1, d2);\n } else {\n res = first(type, x - f, n - 2) + 1;\n }\n return first[n][type] = res;\n }\n}\n\nclass MyScanner {\n private final InputStream in;\n public MyScanner(InputStream in){\n this.in = in;\n }\n\n public int nextInt(){\n\t\ttry{\n\t\t\tint c=in.read();\n\t\t\tif(c==-1) return c;\n\t\t\twhile(c!='-'&&(c<'0'||'9' 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d49d6b38cfc027b64575e2476cdaafba", "src_uid": "bb1bd5d8bab7d79e514281230d484996", "difficulty": 2700.0} {"lang": "Java 8", "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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5175f6153a77c7e7372f313ebcb02d20", "src_uid": "bb1bd5d8bab7d79e514281230d484996", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\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 DPaths solver = new DPaths();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DPaths {\n Debug debug = new Debug(true);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n MultiplicativeFunctionSieve sieve = new MultiplicativeFunctionSieve(n, false, true, false);\n\n long twoCnt = 0;\n long threeCnt = 0;\n int[] ps = new int[n + 1];\n for (int i = 2; i <= n; i++) {\n ps[sieve.smallestPrimeFactor[i]]++;\n }\n for (int i = 1; i <= n; i++) {\n ps[i] += ps[i - 1];\n }\n for (int i = 1; i * 2 <= n; i++) {\n int num = (ps[i] - ps[i - 1]);\n\n int j = Math.min(i - 1, n / i);\n twoCnt += (long) ps[j] * num;\n\n int k = Math.min(i - 1, n / 2);\n threeCnt += (long) ps[k] * num;\n }\n for (int i = 1; i <= n; i++) {\n int num = ps[i] - ps[i - 1];\n if (i * i <= n) {\n twoCnt += (long) num * (num - 1) / 2;\n }\n if (i * 2 <= n) {\n threeCnt += (long) num * (num - 1) / 2;\n }\n }\n\n\n threeCnt -= twoCnt;\n long coprime = 0;\n for (int i = 2; i <= n; i++) {\n coprime += sieve.euler[i];\n }\n\n long notCoprime = (long) n * (n - 1) / 2 - coprime;\n long ans = twoCnt * 2 - notCoprime + threeCnt * 3;\n\n debug.debug(\"coprime\", coprime);\n debug.debug(\"twoCnt\", twoCnt);\n debug.debug(\"notCporime\", notCoprime);\n debug.debug(\"threeCnt\", threeCnt);\n out.println(ans);\n }\n\n }\n\n static class Debug {\n private boolean offline;\n private PrintStream out = System.err;\n\n public Debug(boolean enable) {\n offline = enable && System.getSecurityManager() == null;\n }\n\n public Debug debug(String name, long x) {\n if (offline) {\n debug(name, \"\" + x);\n }\n return this;\n }\n\n public Debug debug(String name, String x) {\n if (offline) {\n out.printf(\"%s=%s\", name, x);\n out.println();\n }\n return this;\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(long c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(long 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 MultiplicativeFunctionSieve {\n public int[] primes;\n public boolean[] isComp;\n public int primeLength;\n public int[] mobius;\n public int[] euler;\n public int[] factors;\n public int[] smallestPrimeFactor;\n public int[] numberOfSmallestPrimeFactor;\n\n public MultiplicativeFunctionSieve(int limit, boolean enableMobius, boolean enableEuler, boolean enableFactors) {\n isComp = new boolean[limit + 1];\n primes = new int[limit + 1];\n numberOfSmallestPrimeFactor = new int[limit + 1];\n smallestPrimeFactor = new int[limit + 1];\n primeLength = 0;\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n primes[primeLength++] = i;\n numberOfSmallestPrimeFactor[i] = smallestPrimeFactor[i] = i;\n }\n for (int j = 0, until = limit / i; j < primeLength && primes[j] <= until; j++) {\n int pi = primes[j] * i;\n smallestPrimeFactor[pi] = primes[j];\n numberOfSmallestPrimeFactor[pi] = smallestPrimeFactor[i] == primes[j]\n ? (numberOfSmallestPrimeFactor[i] * numberOfSmallestPrimeFactor[primes[j]])\n : numberOfSmallestPrimeFactor[primes[j]];\n isComp[pi] = true;\n if (i % primes[j] == 0) {\n break;\n }\n }\n }\n\n if (enableMobius) {\n mobius = new int[limit + 1];\n mobius[1] = 1;\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n mobius[i] = -1;\n } else {\n if (numberOfSmallestPrimeFactor[i] != smallestPrimeFactor[i]) {\n mobius[i] = 0;\n } else {\n mobius[i] = mobius[numberOfSmallestPrimeFactor[i]] * mobius[i / numberOfSmallestPrimeFactor[i]];\n }\n }\n }\n }\n\n if (enableEuler) {\n euler = new int[limit + 1];\n euler[1] = 1;\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n euler[i] = i - 1;\n } else {\n if (numberOfSmallestPrimeFactor[i] == i) {\n euler[i] = i - i / smallestPrimeFactor[i];\n } else {\n euler[i] = euler[numberOfSmallestPrimeFactor[i]] * euler[i / numberOfSmallestPrimeFactor[i]];\n }\n }\n }\n }\n\n if (enableFactors) {\n factors = new int[limit + 1];\n factors[1] = 1;\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n factors[i] = 2;\n } else {\n if (numberOfSmallestPrimeFactor[i] == i) {\n factors[i] = 1 + factors[i / smallestPrimeFactor[i]];\n } else {\n factors[i] = factors[numberOfSmallestPrimeFactor[i]]\n * factors[i / numberOfSmallestPrimeFactor[i]];\n }\n }\n }\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "713907bb33806931cf2357f1b3e38e96", "src_uid": "bb1bd5d8bab7d79e514281230d484996", "difficulty": 2700.0} {"lang": "Java 8", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7fb49db160bfb6c3ecc4969cf50276d5", "src_uid": "bb1bd5d8bab7d79e514281230d484996", "difficulty": 2700.0} {"lang": "Java 8", "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 set;\n\t\tpublic IntervalList()\n\t\t{\n\t\t\tset = new TreeSet();\n\t\t}\n\t\t\n\t\tpublic void add(int s, int e)\n\t\t{\n\t\t\tIterator 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\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "09cf1fa3e683ecb33b64b72e9ddd53cd", "src_uid": "3979abbe7bad0f3b5cab15c1cba19f6b", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n\npublic class D {\n\tstatic long M = 1000L*1000*1000+7;\n\tstatic long A(long x, long y) { return (x+y)%M; }\n\tstatic long M(long x, long y) { return (x*y)%M; }\n\t\n\tstatic long f(long n) {\n\t\tlong ans = 1;\n\t\tfor(int i=2; i<=n; i++)\n\t\t\tans = M(ans, i);\n\t\treturn ans;\n\t}\n\tstatic long C(long n, long k) {\n\t\tlong ans = 1;\n\t\tfor(long i=n-k+1; i<=n; i++)\n\t\t\tans = M(ans, i);\n\t\treturn ans;\n\t}\n\tstatic Long[][] DP;\n\tpublic static long f(int a, int b) {\n\t\tif(a+b <= 1) return 1;\n\t\tif(DP[a][b]!=null) return DP[a][b];\n\t\tif(a==0) {\n\t\t\treturn DP[a][b]=f(b);\n\t\t} else {\n\t\t\tlong ans = f(a-1, b);\n\t\t\tif(a>=2) {\n\t\t\t\tfor(int k=0; k<=b; k++)\n\t\t\t\t\tans = A(ans, M(a-1, M(C(b,k), f(a-2, b-k))));\n\t\t\t}\n\t\t\tif(b>=1) ans = A(ans, M(b, f(a,b-1)));\n\t\t\treturn DP[a][b]=ans;\n\t\t}\n\t}\n\tstatic int i(String s) { return Integer.parseInt(s); }\n\tpublic static void main(String[] args) throws Exception {\n\t\t/*int L = 5;\n\t\tfor(int n=0; n<=L; n++)\n\t\t\tfor(int a=0; a<=n; a++)\n\t\t\t\tSystem.out.printf(\"f(%d,%d) = %d\\n\", a, n-a, f(a,n-a));*/\n\t\t\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = i(in.readLine());\n\t\tint C1 = 0;\n\t\tint C2 = 0;\n\t\tString[] arr = in.readLine().split(\" \");\n\t\tfor(int i=0; i cash = new TreeMap();\n\t\n\tlong f(int n, int t) {\n\t\tif (cash.containsKey(n * 10000000l + t)) return cash.get(n * 10000000l + t);\n\t\tlong res = 0;\n\t\tif (n == t) res = fkt[n]; else {\n\t\t\tfor (int i = 0; i <= t; i++) {\n\t\t\t\tlong tmp = c[t][i];\n\t\t\t\tres = (res + (tmp * fkt[i]) % modd * f(n - i - 1, t - i)) % modd;\n\t\t\t\tif (n > t + 1) res = (res + ((tmp * fkt[i + 1]) % modd * f(n - i - 2, t - i) * (n - t - 1)) % modd) % modd;\n\t\t\t}\n\t\t}\n\t\tcash.put(n * 10000000l + t, res);\n\t\treturn res;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tfkt[0] = 1;\n\t\tfor (int i = 1; i <= 1000000; i++) fkt[i] = (fkt[i - 1] * i) % modd;\n\t\tc[0][0] = 1;\n\t\tfor (int i = 1; i <= 1000; i++) {\n\t\t\tc[i][0] = 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]) % modd;\n\t\t\t}\n\t\t}\n\t\tint n = nextInt();\n\t\tint t = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt += nextInt() - 1;\n\t\t}\n\t\tout.println(f(n, t));\n\t}\n\t\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\tLocale.setDefault(Locale.US);\n\t\t\tsolve();\n\t\t} catch(Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29d57e7ab97bcb8f279fa410cbd47b55", "src_uid": "91e8dbe94273e255182aca0f94117bb9", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\n\npublic class A {\n\tstatic final long mod = 1000000007;\n\tpublic static void main(String[] args) {\n\t\tMScanner sc = new MScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt(), ONE = 0, TWO = 0;\n\t\tfor(int a=0;a=numChars){\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e){\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif(numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t\t\n\t\tboolean isSpaceChar(int c){\n\t\t\treturn c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n\t\t}\n\t\tboolean isEndline(int c){\n\t\t\treturn c=='\\n'||c=='\\r'||c==-1;\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] nextInt(int N){\n\t\t\tint[] ret = new int[N];\n\t\t\tfor(int a=0;a= 2) {\n\t\t\tans += (ones - 1) * get(ones - 2, twos);\n\t\t}\n\t\tif (twos >= 1) {\n\t\t\tans += (twos) * get(ones, twos - 1);\n\t\t}\n\t\tif (ones >= 2 && twos >= 1) {\n\t\t\tlong typeSum = 0;\n\t\t\tfor (int len = 1; len <= twos; len++) {\n\t\t\t\ttypeSum += special(twos, len) * get(ones - 2, twos - len);\n\t\t\t}\n\t\t\tans += (ones - 1) * typeSum;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tstatic long fact(int k) {\n\t\treturn k <= 1 ? 1 : k * fact(k - 1);\n\t}\n\n\tstatic long special(int k, int len) {\n\t\tlong res = 1;\n\t\tfor (int t = k; t >= k - len + 1; t--) {\n\t\t\tres *= t;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic void solve() {\n\t\tint n = nextInt();\n\t\tint ones = 0, twos = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k = nextInt();\n\t\t\tif (k == 1)\n\t\t\t\tones++;\n\t\t\telse\n\t\t\t\ttwos++;\n\t\t}\n\t\tdebug(get(ones, twos));\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\twriter = new PrintWriter(System.out);\n\t\tLocale.setDefault(Locale.US);\n\n\t\tsetTime();\n\t\tsolve();\n\t\tprintTime();\n\t\tprintMemory();\n\n\t\twriter.close();\n\t}\n\n\tstatic BufferedReader reader;\n\tstatic PrintWriter writer;\n\tstatic StringTokenizer tok = new StringTokenizer(\"\");\n\tstatic long systemTime;\n\n\tstatic void debug(Object... o) {\n\t\tSystem.err.println(deepToString(o));\n\t}\n\n\tstatic void setTime() {\n\t\tsystemTime = System.currentTimeMillis();\n\t}\n\n\tstatic void printTime() {\n\t\tSystem.err.println(\"Time consumed: \" + (System.currentTimeMillis() - systemTime));\n\t}\n\n\tstatic void printMemory() {\n\t\tSystem.err.println(\"Memory consumed: \"\n\t\t\t\t+ (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + \"kb\");\n\t}\n\n\tstatic String next() {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\tString w = null;\n\t\t\ttry {\n\t\t\t\tw = reader.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\tif (w == null)\n\t\t\t\treturn null;\n\t\t\ttok = new StringTokenizer(w);\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tstatic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tstatic BigInteger nextBigInteger() {\n\t\treturn new BigInteger(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9ccdc1d21961bd6b1cab0ef164a99fb3", "src_uid": "91e8dbe94273e255182aca0f94117bb9", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n// BiGraph Matching\n\npublic class CF_212A {\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String args[]) {\n while (task()) {\n }\n }\n\n private static int n, m, k, t;\n\n\n private static int maxK = 5000;\n private static int maxT = 2000;\n private static int[] a = new int[maxK + 10];\n private static int[] b = new int[maxK + 10];\n\n private static int[] X = new int[maxT * maxT + 10];\n private static int[] Y = new int[maxT * maxT + 10];\n private static int[] xBegin = new int[maxT * maxT + 10];\n private static int[] yBegin = new int[maxT * maxT + 10];\n\n private static int[] degree = new int[maxK + 10];\n private static int maxDegree = 0;\n\n private static int[] degreeX = new int[maxK + 10];\n private static int[] degreeY = new int[maxK + 10];\n\n private static int[][] col = new int[2 * maxT + 10][maxT + 10];\n private static int[][] colH = new int[2 * maxT + 10][2 * maxT + 10];\n\n private static int[][] realEdge = new int[2 * maxT + 10][2 * maxT + 10];\n private static int[][] fakeEdge = new int[2 * maxT + 10][2 * maxT + 10];\n\n public static boolean task() {\n n = scanner.nextInt();\n m = scanner.nextInt();\n k = scanner.nextInt();\n t = scanner.nextInt();\n\n for (int i = 0; i < k; i++) {\n int x = scanner.nextInt();\n int y = scanner.nextInt();\n y += n;\n a[i] = x;\n b[i] = y;\n degree[x]++;\n degree[y]++;\n }\n\n int ans = 0;\n for (int i = 1; i <= n + m; i++) {\n ans += degree[i] % t == 0? 0: 1;\n // System.out.println(\"deg \" + i + \" \" + degree[i]);\n }\n System.out.println(ans);\n\n maxDegree = t;\n\n int hX = 1, hY = 1;\n for (int i = 1; i <= n; i++) {\n // System.out.println(\"deg \" + i + \" \" + degree[i] + \" \" + hX);\n int deg = degree[i];\n xBegin[i] = hX;\n while (deg > 0) {\n X[hX] = i;\n hX++;\n deg -= maxDegree;\n }\n }\n\n for (int i = 1; i <= m; i++) {\n int deg = degree[n + i];\n yBegin[i] = hY;\n while (deg > 0) {\n Y[hY] = i;\n hY++;\n deg -= maxDegree;\n }\n }\n\n int h = hX - 1;\n if (h < hY - 1) {\n h = hY - 1;\n }\n\n /*\n for (int i = 1; i <= h; i++) {\n System.out.println(i + \" \" + X[i]);\n }\n\n System.out.println(\" -- \");\n\n for (int i = 1; i <= h; i++) {\n System.out.println(i + \" \" + Y[i]);\n }\n */\n\n Matcher matcher = new Matcher(h, h);\n\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n int realX = xBegin[x];\n int realY = yBegin[y];\n matcher.addEdge(realX, realY);\n realEdge[realX][realY] = 1;\n degreeX[realX]++;\n if (degreeX[realX] == maxDegree) {\n xBegin[x]++;\n }\n degreeY[realY]++;\n if (degreeY[realY] == maxDegree) {\n yBegin[y]++;\n }\n }\n\n int hy = 1;\n\n for (int i = 1; i <= h; i++) {\n int need = maxDegree - degreeX[i];\n while (need > 0) {\n while (degreeY[hy] == maxDegree) {\n hy++;\n }\n matcher.addEdge(i, hy);\n fakeEdge[i][hy] = 1;\n need--;\n degreeY[hy]++;\n degreeX[i]++;\n }\n }\n\n /*\n for (int i = 1; i <= h; i++) {\n System.out.println(\"check deg x \" + i + \" \" + degreeX[i]);\n }\n for (int i = 1; i <= h; i++) {\n System.out.println(\"check deg y \" + i + \" \" + degreeY[i]);\n }\n */\n\n for (int i = 0; i < maxDegree; i++) {\n matcher.match();\n // System.out.println(matcher.ans());\n int c = i + 1;\n for (int x = 1; x <= h; x++) {\n int y = matcher.matching[x] - h;\n if (y + h == -1) {\n continue;\n }\n int originalX = X[x];\n int originalY = Y[y];\n if (originalX == 5 && originalY == 4) {\n //System.out.println(\"hit !! \" + originalX + \" \" + originalY + \" \" + col[originalX][originalY]);\n //System.out.println(\"hit !! \" + x + \" \" + y + \" \" + c);\n }\n if (realEdge[x][y] == 1 && colH[x][y] == 0) {\n colH[x][y] = c;\n if (col[originalX][originalY] == 0) {\n col[originalX][originalY] = c;\n //col[originalY][originalX] = c;\n } else {\n }\n }\n // System.out.println(\"col \" + originalX + \" \" + originalY + \" \" + c);\n matcher.delEdge(x, y);\n }\n }\n\n int tot = 0;\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n if (i > 0) {\n System.out.print(\" \");\n }\n System.out.print(col[x][y]);\n tot++;\n }\n System.out.println();\n\n /*\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {\n System.out.print(col[i][j] + \" \");\n if (col[i][j] > 0) {\n }\n }\n System.out.println();\n }\n System.out.println(tot);\n\n // check\n int [][] sumX = new int[maxT + 10][4];\n int [][] sumY = new int[maxT + 10][4];\n for (int i = 1; i <= n; i++) {\n sumX[i][1] = sumX[i][2] = sumX[i][3] = 0;\n sumY[i][1] = sumY[i][2] = sumY[i][3] = 0;\n }\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n sumX[x][col[x][y]]++;\n sumY[y][col[x][y]]++;\n if (x == 5) {\n System.out.println(\"check \" + x + \" \" + y + \" \" + col[x][y]);\n }\n }\n for (int i = 1; i <= n; i++) {\n int min = sumX[i][1];\n int max = sumX[i][1];\n if (min > sumX[i][2]) {\n min = sumX[i][2];\n }\n if (min > sumX[i][3]) {\n min = sumX[i][3];\n }\n if (max < sumX[i][2]) {\n max = sumX[i][2];\n }\n if (max < sumX[i][3]) {\n max = sumX[i][3];\n }\n int yes = 0;\n if (degree[i] % 3 == 0) {\n if (min == max) {\n yes = 1;\n }\n } else {\n if (min == max - 1) {\n yes = 1;\n }\n }\n if (i == 5) {\n System.out.println(\"x \" + i + \" \" + degree[i] + \" \" + min + \" \" + max + \" \" + yes);\n }\n }\n\n System.out.println(\"---\");\n for (int i = 1; i <= m; i++) {\n int min = sumY[i][1];\n int max = sumY[i][1];\n if (min > sumY[i][2]) {\n min = sumY[i][2];\n }\n if (min > sumY[i][3]) {\n min = sumY[i][3];\n }\n if (max < sumY[i][2]) {\n max = sumY[i][2];\n }\n if (max < sumY[i][3]) {\n max = sumY[i][3];\n }\n int yes = 0;\n if (degree[i + n] % 3 == 0) {\n if (min == max) {\n yes = 1;\n }\n } else {\n if (min == max - 1) {\n yes = 1;\n }\n }\n System.out.println(\"y \" + i + \" \" + degree[i + n] + \" \" + min + \" \" + max + \" \" + yes);\n }\n */\n\n\n\n return false;\n }\n\n\n\n public static final int maxN = 10000;\n\n public static class Matcher {\n public Map[] g = new Map[2 * maxN + 10];\n private int nx, ny;\n private int nEdge;\n\n public static int[] matching = new int[2 * maxN + 10];\n private static int[] checked = new int[2 * maxN + 10];\n\n public Matcher(int nx, int ny) {\n this.nx = nx;\n this.ny = ny;\n nEdge = 0;\n for (int i = 0; i < g.length; i++) {\n g[i] = new HashMap<>();\n }\n }\n\n public void addEdge(int x, int y) {\n int now = g[x].getOrDefault(nx + y, 0);\n g[x].put(nx + y, now + 1);\n nEdge++;\n // System.out.println((\"add \" + x + \" \" + y));\n }\n\n public void delEdge(int x, int y) {\n int now = g[x].getOrDefault(nx + y, 0);\n if (now > 1) {\n g[x].put(nx + y, now - 1);\n } else {\n g[x].remove(nx + y);\n }\n nEdge--;\n // System.out.println((\"del \" + x + \" \" + y));\n }\n\n public void reset() {\n ans = 0;\n for (int i = 0; i < matching.length; i++) {\n matching[i] = -1;\n }\n for (int i = 0; i < checked.length; i++) {\n checked[i] = -1;\n }\n }\n\n private int ans = 0;\n\n private Queue q = new LinkedList<>();\n private int[] prev = new int[2 * maxN + 10];\n\n public void match() {\n reset();\n for (int x = 1; x <= nx; x++) {\n int step = x;\n if (matching[x] == -1) {\n q.clear();\n q.add(x);\n prev[x] = -1;\n boolean flag = false;\n while (!q.isEmpty() && !flag) {\n int u = q.poll();\n //System.out.println(u);\n for (int v: g[u].keySet()) {\n if (flag) {\n break;\n }\n if (checked[v] != step) {\n checked[v] = step;\n q.add(matching[v]);\n if (matching[v] >= 0) {\n prev[matching[v]] = u;\n } else {\n flag = true;\n int d = u;\n int e = v;\n while (d != -1) {\n int t = matching[d];\n matching[d] = e;\n matching[e] = d;\n d = prev[d];\n e = t;\n }\n }\n }\n }\n // q.poll();\n }\n if (matching[x] != -1) {\n ans++;\n }\n }\n }\n }\n\n public int ans() {\n return ans;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c640d022b23771033c742d06aaa018b4", "src_uid": "99b97aabec566e5f966777947271ad3c", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n// BiGraph Matching\n\npublic class CF_212A {\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String args[]) {\n while (task()) {\n }\n }\n\n private static int n, m, k, t;\n\n\n private static int maxK = 5000;\n private static int maxT = 200;\n private static int[] a = new int[maxK + 10];\n private static int[] b = new int[maxK + 10];\n\n private static int[] X = new int[maxT * maxT + 10];\n private static int[] Y = new int[maxT * maxT + 10];\n private static int[] xBegin = new int[maxT * maxT + 10];\n private static int[] yBegin = new int[maxT * maxT + 10];\n private static int[] sum = new int[2 * maxT + 10];\n\n private static int[] degree = new int[maxK + 10];\n private static int maxDegree = 0;\n\n private static int[] degreeX = new int[maxK + 10];\n private static int[] degreeY = new int[maxK + 10];\n\n private static int[][] col = new int[2 * maxT + 10][maxT + 10];\n\n public static boolean task() {\n n = scanner.nextInt();\n m = scanner.nextInt();\n k = scanner.nextInt();\n t = scanner.nextInt();\n\n for (int i = 0; i < k; i++) {\n int x = scanner.nextInt();\n int y = scanner.nextInt();\n y += n;\n a[i] = x;\n b[i] = y;\n degree[x]++;\n degree[y]++;\n }\n\n int ans = 0;\n for (int i = 1; i <= n + m; i++) {\n ans += degree[i] % t == 0? 0: 1;\n /*\n if (degree[i] > maxDegree) {\n maxDegree = degree[i];\n }\n */\n }\n System.out.println(ans);\n\n maxDegree = t;\n\n int hA = 1, hB = 1;\n for (int i = 1; i <= n; i++) {\n // System.out.println(\"deg \" + i + \" \" + degree[i] + \" \" + hA);\n int deg = degree[i];\n xBegin[i] = hA;\n while (deg > 0) {\n X[hA] = i;\n hA++;\n deg -= maxDegree;\n }\n }\n\n for (int i = 1; i <= m; i++) {\n int deg = degree[n + i];\n yBegin[i] = hB;\n while (deg > 0) {\n Y[hB] = i;\n hB++;\n deg -= maxDegree;\n }\n }\n\n int h = hA - 1;\n if (h < hB - 1) {\n h = hB - 1;\n }\n\n /*\n for (int i = 1; i <= h; i++) {\n System.out.println(i + \" \" + X[i]);\n }\n\n System.out.println(\" -- \");\n\n for (int i = 1; i <= h; i++) {\n System.out.println(i + \" \" + Y[i]);\n }\n */\n\n Matcher matcher = new Matcher(h, h);\n\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n int realX = xBegin[x];\n int realY = yBegin[y];\n matcher.addEdge(realX, realY);\n degreeX[realX]++;\n if (degreeX[realX] == maxDegree) {\n xBegin[x]++;\n }\n degreeY[realY]++;\n if (degreeY[realY] == maxDegree) {\n yBegin[y]++;\n }\n }\n\n int hy = 1;\n\n\n for (int i = 1; i <= h; i++) {\n int need = maxDegree - degreeX[i];\n while (need > 0) {\n while (degreeY[hy] == maxDegree) {\n hy++;\n }\n matcher.addEdge(i, hy);\n need--;\n degreeY[hy]++;\n }\n }\n\n for (int i = 0; i < maxDegree; i++) {\n matcher.match();\n // System.out.println(matcher.ans());\n int c = i + 1;\n for (int x = 1; x <= h; x++) {\n int originalX = X[x];\n int originalY = Y[matcher.matching[x] - h];\n col[originalX][originalY] = c;\n col[originalY][originalX] = c;\n matcher.delEdge(x, matcher.matching[x] - h);\n }\n }\n\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n if (i > 0) {\n System.out.print(\" \");\n }\n System.out.print(col[x][y]);\n }\n System.out.println();\n\n\n return false;\n }\n\n\n\n public static final int maxN = 1000;\n\n public static class Matcher {\n public Map[] g = new Map[2 * maxN + 10];\n private int nx, ny;\n private int nEdge;\n\n public static int[] matching = new int[2 * maxN + 10];\n private static int[] checked = new int[2 * maxN + 10];\n\n public Matcher(int nx, int ny) {\n this.nx = nx;\n this.ny = ny;\n nEdge = 0;\n for (int i = 0; i < g.length; i++) {\n g[i] = new HashMap<>();\n }\n }\n\n public void addEdge(int x, int y) {\n int now = g[x].getOrDefault(nx + y, 0);\n g[x].put(nx + y, now);\n nEdge++;\n // System.out.println((\"add \" + x + \" \" + y));\n }\n\n public void delEdge(int x, int y) {\n int now = g[x].getOrDefault(nx + y, 0);\n if (now > 1) {\n g[x].put(nx + y, now - 1);\n } else {\n g[x].remove(nx + y);\n }\n nEdge--;\n // System.out.println((\"del \" + x + \" \" + y));\n }\n\n public void reset() {\n\n }\n\n private int ans = 0;\n\n private Queue q = new LinkedList<>();\n private int[] prev = new int[2 * maxN + 10];\n\n public void match() {\n ans = 0;\n for (int i = 0; i < matching.length; i++) {\n matching[i] = -1;\n }\n for (int i = 0; i < checked.length; i++) {\n checked[i] = -1;\n }\n for (int x = 1; x <= nx; x++) {\n int step = x;\n if (matching[x] == -1) {\n q.clear();\n q.add(x);\n prev[x] = -1;\n boolean flag = false;\n while (!q.isEmpty() && !flag) {\n int u = q.poll();\n //System.out.println(u);\n for (int v: g[u].keySet()) {\n if (flag) {\n break;\n }\n if (checked[v] != step) {\n checked[v] = step;\n q.add(matching[v]);\n if (matching[v] >= 0) {\n prev[matching[v]] = u;\n } else {\n flag = true;\n int d = u;\n int e = v;\n while (d != -1) {\n int t = matching[d];\n matching[d] = e;\n matching[e] = d;\n d = prev[d];\n e = t;\n }\n }\n }\n }\n // q.poll();\n }\n if (matching[x] != -1) {\n ans++;\n }\n }\n }\n }\n\n public int ans() {\n return ans;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "542892b00493a208760954d702ca2de9", "src_uid": "99b97aabec566e5f966777947271ad3c", "difficulty": 3000.0} {"lang": "Java 8", "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[501][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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e31b045846f882679f461084062294f1", "src_uid": "99b97aabec566e5f966777947271ad3c", "difficulty": 3000.0} {"lang": "Java 8", "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[501][201];\n\tstatic int[][] index = new int[501][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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c15dd3671917755ec81c321a816865e", "src_uid": "99b97aabec566e5f966777947271ad3c", "difficulty": 3000.0} {"lang": "Java 8", "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\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\tTaskG solver = new TaskG();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskG {\n static class Intersector {\n long minxplusy = Long.MIN_VALUE;\n long maxxplusy = Long.MAX_VALUE;\n long minxminusy = Long.MIN_VALUE;\n long maxxminusy = Long.MAX_VALUE;\n\n void update(long kx, long ky, long a) {\n if (Math.abs(kx) != Math.abs(ky)) throw new RuntimeException();\n if (kx == 0) {\n if (a <= 0) return;\n minxplusy = Long.MAX_VALUE;\n maxxplusy = Long.MIN_VALUE;\n minxminusy = Long.MAX_VALUE;\n maxxminusy = Long.MIN_VALUE;\n return;\n }\n if (kx > 0) {\n if (ky > 0) {\n maxxplusy = Math.min(maxxplusy, safeDivide(-a, kx));\n } else {\n maxxminusy = Math.min(maxxminusy, safeDivide(-a, kx));\n }\n } else {\n if (ky < 0) {\n minxplusy = Math.max(minxplusy, safeDivide(a + (-kx) - 1, -kx));\n } else {\n minxminusy = Math.max(minxminusy, safeDivide(a + (-kx) - 1, -kx));\n }\n }\n }\n\n private long safeDivide(long a, long b) {\n if (a > 0) return a / b; else return (a - b + 1) / b;\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int l = in.nextInt();\n boolean[] know = new boolean[l + 1];\n long[] k = new long[l + 1];\n long[] ax = new long[l + 1];\n long[] ay = new long[l + 1];\n know[0] = true;\n know[l] = true;\n k[l] = 1;\n boolean knowP = false;\n long px = 0;\n long py = 0;\n for (int i = 0; i < n; ++i) {\n long t = in.nextLong();\n long x = in.nextLong();\n long y = in.nextLong();\n if ((x + y + t) % 2 != 0) {\n out.println(\"NO\");\n return;\n }\n int when = (int) (t % l);\n long ck = -t / l;\n if (!know[when]) {\n know[when] = true;\n k[when] = ck;\n ax[when] = x;\n ay[when] = y;\n } else {\n if (knowP) {\n if (k[when] * px + ax[when] != ck * px + x || Math.abs(k[when] * (double) px + ax[when] - ck * (double) px - x) > 1e62) {\n out.println(\"NO\");\n return;\n }\n if (k[when] * py + ay[when] != ck * py + y || Math.abs(k[when] * (double) py + ay[when] - ck * (double) py - y) > 1e62) {\n out.println(\"NO\");\n return;\n }\n } else {\n knowP = true;\n long numx = x - ax[when];\n long numy = y - ay[when];\n long den = k[when] - ck;\n if (numx % den != 0 || numy % den != 0) {\n out.println(\"NO\");\n return;\n }\n px = numx / den;\n py = numy / den;\n }\n }\n }\n\n {\n Intersector intersector = new Intersector();\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n for (int kx = -1; kx <= 1; kx += 2) {\n for (int ky = -1; ky <= 1; ky += 2) {\n intersector.update(kx * dk, ky * dk, kx * dax + ky * day - (i - prev));\n }\n }\n prev = i;\n }\n if (knowP) {\n if (px + py < intersector.minxplusy || px + py > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (px - py < intersector.minxminusy || px - py > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n } else {\n if (intersector.minxplusy > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (intersector.minxminusy > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n long xplusy;\n if (intersector.minxplusy == Long.MIN_VALUE) {\n if (intersector.maxxplusy == Long.MAX_VALUE) {\n xplusy = 0;\n } else {\n xplusy = intersector.maxxplusy - 1;\n }\n } else {\n xplusy = intersector.minxplusy;\n }\n long xminusy;\n if (intersector.minxminusy == Long.MIN_VALUE) {\n if (intersector.maxxminusy == Long.MAX_VALUE) {\n xminusy = 0;\n } else {\n xminusy = intersector.maxxminusy - 1;\n }\n } else {\n xminusy = intersector.minxminusy;\n }\n if ((xplusy + xminusy) % 2 != 0) {\n if (xplusy < intersector.maxxplusy) {\n ++xplusy;\n } else if (xminusy < intersector.maxxminusy) {\n ++xminusy;\n } else {\n out.println(\"NO\");\n return;\n }\n }\n px = (xplusy + xminusy) / 2;\n py = (xplusy - xminusy) / 2;\n }\n }\n\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n long dx = dk * px + dax;\n long dy = dk * py + day;\n if ((Math.abs(dx) + Math.abs(dy) > i - prev)) throw new RuntimeException();\n int extra = (int) ((i - prev - Math.abs(dx) - Math.abs(dy)));\n while (dx > 0) {\n out.print('R');\n --dx;\n }\n while (dx < 0) {\n out.print('L');\n ++dx;\n }\n while (dy > 0) {\n out.print('U');\n --dy;\n }\n while (dy < 0) {\n out.print('D');\n ++dy;\n }\n for (int j = 0; j < extra; ++j) {\n if (j % 2 == 0)\n out.print(\"L\");\n else\n out.print(\"R\");\n }\n prev = i;\n }\n out.println();\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ce054be3230063f1edd8c0bbaf44ce7b", "src_uid": "941f1f8a37c25dd2405a20c7d416c9a6", "difficulty": 3100.0} {"lang": "Java 8", "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\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\tTaskG solver = new TaskG();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskG {\n static class Intersector {\n long minxplusy = Long.MIN_VALUE;\n long maxxplusy = Long.MAX_VALUE;\n long minxminusy = Long.MIN_VALUE;\n long maxxminusy = Long.MAX_VALUE;\n\n void update(long kx, long ky, long a) {\n if (Math.abs(kx) != Math.abs(ky)) throw new RuntimeException();\n if (kx == 0) {\n if (a <= 0) return;\n minxplusy = Long.MAX_VALUE;\n maxxplusy = Long.MIN_VALUE;\n minxminusy = Long.MAX_VALUE;\n maxxminusy = Long.MIN_VALUE;\n return;\n }\n if (kx > 0) {\n if (ky > 0) {\n maxxplusy = Math.min(maxxplusy, safeDivide(-a, kx));\n } else {\n maxxminusy = Math.min(maxxminusy, safeDivide(-a, kx));\n }\n } else {\n if (ky < 0) {\n minxplusy = Math.max(minxplusy, safeDivide(a + (-kx) - 1, -kx));\n } else {\n minxminusy = Math.max(minxminusy, safeDivide(a + (-kx) - 1, -kx));\n }\n }\n }\n\n private long safeDivide(long a, long b) {\n if (a > 0) return a / b; else return (a - b + 1) / b;\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int l = in.nextInt();\n boolean[] know = new boolean[l + 1];\n long[] k = new long[l + 1];\n long[] ax = new long[l + 1];\n long[] ay = new long[l + 1];\n know[0] = true;\n know[l] = true;\n k[l] = 1;\n boolean knowP = false;\n long px = 0;\n long py = 0;\n for (int i = 0; i < n; ++i) {\n long t = in.nextLong();\n long x = in.nextLong();\n long y = in.nextLong();\n if ((x + y + t) % 2 != 0) {\n out.println(\"NO\");\n return;\n }\n int when = (int) (t % l);\n long ck = -t / l;\n if (!know[when]) {\n know[when] = true;\n k[when] = ck;\n ax[when] = x;\n ay[when] = y;\n } else {\n if (knowP) {\n if (k[when] * px + ax[when] != ck * px + x || Math.abs(k[when] * (double) px + ax[when] - ck * (double) px - x) > 1e62) {\n out.println(\"NO\");\n return;\n }\n if (k[when] * py + ay[when] != ck * py + y || Math.abs(k[when] * (double) py + ay[when] - ck * (double) py - y) > 1e62) {\n out.println(\"NO\");\n return;\n }\n } else {\n knowP = true;\n long numx = x - ax[when];\n long numy = y - ay[when];\n long den = k[when] - ck;\n if (numx % den != 0 || numy % den != 0) {\n out.println(\"NO\");\n return;\n }\n px = numx / den;\n py = numy / den;\n }\n }\n }\n\n {\n Intersector intersector = new Intersector();\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n for (int kx = -1; kx <= 1; kx += 2) {\n for (int ky = -1; ky <= 1; ky += 2) {\n intersector.update(kx * dk, ky * dk, kx * dax + ky * day - (i - prev));\n }\n }\n prev = i;\n }\n if (knowP) {\n if (px + py < intersector.minxplusy || px + py > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (px - py < intersector.minxminusy || px - py > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n if ((px + py + l) % 2 != 0) {\n out.println(\"NO\");\n return;\n }\n } else {\n if (intersector.minxplusy > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (intersector.minxminusy > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n long xplusy;\n if (intersector.minxplusy == Long.MIN_VALUE) {\n if (intersector.maxxplusy == Long.MAX_VALUE) {\n xplusy = 0;\n } else {\n xplusy = intersector.maxxplusy - 1;\n }\n } else {\n xplusy = intersector.minxplusy;\n }\n long xminusy;\n if (intersector.minxminusy == Long.MIN_VALUE) {\n if (intersector.maxxminusy == Long.MAX_VALUE) {\n xminusy = 0;\n } else {\n xminusy = intersector.maxxminusy - 1;\n }\n } else {\n xminusy = intersector.minxminusy;\n }\n if ((xplusy + l) % 2 != 0) {\n if (xplusy < intersector.maxxplusy) {\n ++xplusy;\n } else {\n out.println(\"NO\");\n return;\n }\n }\n if ((xminusy + l) % 2 != 0) {\n if (xminusy < intersector.maxxminusy) {\n ++xminusy;\n } else {\n out.println(\"NO\");\n return;\n }\n }\n px = (xplusy + xminusy) / 2;\n py = (xplusy - xminusy) / 2;\n }\n }\n\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n long dx = dk * px + dax;\n long dy = dk * py + day;\n if ((Math.abs(dx) + Math.abs(dy) > i - prev) || (Math.abs(dx) + Math.abs(dy) + (i - prev)) % 2 != 0) throw new RuntimeException();\n int extra = (int) ((i - prev - Math.abs(dx) - Math.abs(dy)) / 2);\n while (dx > 0) {\n out.print('R');\n --dx;\n }\n while (dx < 0) {\n out.print('L');\n ++dx;\n }\n while (dy > 0) {\n out.print('U');\n --dy;\n }\n while (dy < 0) {\n out.print('D');\n ++dy;\n }\n for (int j = 0; j < extra; ++j) {\n out.print(\"LR\");\n }\n prev = i;\n }\n out.println();\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de68fe6e85e8db002451c959df01f753", "src_uid": "941f1f8a37c25dd2405a20c7d416c9a6", "difficulty": 3100.0} {"lang": "Java 8", "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 ChallengeG solver = new ChallengeG();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass ChallengeG {\n static class Intersector {\n long minxplusy = Long.MIN_VALUE;\n long maxxplusy = Long.MAX_VALUE;\n long minxminusy = Long.MIN_VALUE;\n long maxxminusy = Long.MAX_VALUE;\n\n void update(long kx, long ky, long a) {\n if (Math.abs(kx) != Math.abs(ky)) throw new RuntimeException();\n if (kx == 0) {\n if (a <= 0) return;\n minxplusy = Long.MAX_VALUE;\n maxxplusy = Long.MIN_VALUE;\n minxminusy = Long.MAX_VALUE;\n maxxminusy = Long.MIN_VALUE;\n return;\n }\n if (kx > 0) {\n if (ky > 0) {\n maxxplusy = Math.min(maxxplusy, safeDivide(-a, kx));\n } else {\n maxxminusy = Math.min(maxxminusy, safeDivide(-a, kx));\n }\n } else {\n if (ky < 0) {\n minxplusy = Math.max(minxplusy, safeDivide(a + (-kx) - 1, -kx));\n } else {\n minxminusy = Math.max(minxminusy, safeDivide(a + (-kx) - 1, -kx));\n }\n }\n }\n\n private long safeDivide(long a, long b) {\n if (a > 0) return a / b; else return (a - b + 1) / b;\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int l = in.nextInt();\n boolean[] know = new boolean[l + 1];\n long[] k = new long[l + 1];\n long[] ax = new long[l + 1];\n long[] ay = new long[l + 1];\n know[0] = true;\n know[l] = true;\n k[l] = 1;\n boolean knowP = false;\n long px = 0;\n long py = 0;\n for (int i = 0; i < n; ++i) {\n long t = in.nextLong();\n long x = in.nextLong();\n long y = in.nextLong();\n if ((x + y + t) % 2 != 0) {\n out.println(\"NO\");\n return;\n }\n int when = (int) (t % l);\n long ck = -t / l;\n if (!know[when]) {\n know[when] = true;\n k[when] = ck;\n ax[when] = x;\n ay[when] = y;\n } else {\n if (knowP) {\n if (k[when] * px + ax[when] != ck * px + x || Math.abs(k[when] * (double) px + ax[when] - ck * (double) px - x) > 1e62) {\n out.println(\"NO\");\n return;\n }\n if (k[when] * py + ay[when] != ck * py + y || Math.abs(k[when] * (double) py + ay[when] - ck * (double) py - y) > 1e62) {\n out.println(\"NO\");\n return;\n }\n } else {\n knowP = true;\n long numx = x - ax[when];\n long numy = y - ay[when];\n long den = k[when] - ck;\n if (numx % den != 0 || numy % den != 0) {\n out.println(\"NO\");\n return;\n }\n px = numx / den;\n py = numy / den;\n }\n }\n }\n\n {\n Intersector intersector = new Intersector();\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n for (int kx = -1; kx <= 1; kx += 2) {\n for (int ky = -1; ky <= 1; ky += 2) {\n intersector.update(kx * dk, ky * dk, kx * dax + ky * day - (i - prev));\n }\n }\n prev = i;\n }\n if (knowP) {\n if (px + py < intersector.minxplusy || px + py > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (px - py < intersector.minxminusy || px - py > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n if ((px + py + l) % 2 != 0) {\n out.println(\"NO\");\n return;\n }\n } else {\n if (intersector.minxplusy > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (intersector.minxminusy > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n long xplusy;\n if (intersector.minxplusy == Long.MIN_VALUE) {\n if (intersector.maxxplusy == Long.MAX_VALUE) {\n xplusy = 0;\n } else {\n xplusy = intersector.maxxplusy - 1;\n }\n } else {\n xplusy = intersector.minxplusy;\n }\n long xminusy;\n if (intersector.minxminusy == Long.MIN_VALUE) {\n if (intersector.maxxminusy == Long.MAX_VALUE) {\n xminusy = 0;\n } else {\n xminusy = intersector.maxxminusy - 1;\n }\n } else {\n xminusy = intersector.minxminusy;\n }\n if ((xplusy + l) % 2 != 0) {\n if (xplusy < intersector.maxxplusy) {\n ++xplusy;\n } else {\n out.println(\"NO\");\n return;\n }\n }\n if ((xminusy + l) % 2 != 0) {\n if (xminusy < intersector.maxxminusy) {\n ++xminusy;\n } else {\n out.println(\"NO\");\n return;\n }\n }\n px = (xplusy + xminusy) / 2;\n py = (xplusy - xminusy) / 2;\n }\n }\n\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n long dx = dk * px + dax;\n long dy = dk * py + day;\n if ((Math.abs(dx) + Math.abs(dy) > i - prev) || (Math.abs(dx) + Math.abs(dy) + (i - prev)) % 2 != 0) throw new RuntimeException();\n int extra = (int) ((i - prev - Math.abs(dx) - Math.abs(dy)) / 2);\n while (dx > 0) {\n out.print('R');\n --dx;\n }\n while (dx < 0) {\n out.print('L');\n ++dx;\n }\n while (dy > 0) {\n out.print('U');\n --dy;\n }\n while (dy < 0) {\n out.print('D');\n ++dy;\n }\n for (int j = 0; j < extra; ++j) {\n out.print(\"LR\");\n }\n prev = i;\n }\n out.println();\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "834908218fb202785f609a596b2f9176", "src_uid": "941f1f8a37c25dd2405a20c7d416c9a6", "difficulty": 3100.0} {"lang": "Java 8", "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\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\tTaskG solver = new TaskG();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskG {\n static class Intersector {\n long minxplusy = Long.MIN_VALUE;\n long maxxplusy = Long.MAX_VALUE;\n long minxminusy = Long.MIN_VALUE;\n long maxxminusy = Long.MAX_VALUE;\n\n void update(long kx, long ky, long a) {\n if (Math.abs(kx) != Math.abs(ky)) throw new RuntimeException();\n if (kx == 0) {\n if (a <= 0) return;\n minxplusy = Long.MAX_VALUE;\n maxxplusy = Long.MIN_VALUE;\n minxminusy = Long.MAX_VALUE;\n maxxminusy = Long.MIN_VALUE;\n return;\n }\n if (kx > 0) {\n if (ky > 0) {\n maxxplusy = Math.min(maxxplusy, safeDivide(-a, kx));\n } else {\n maxxminusy = Math.min(maxxminusy, safeDivide(-a, kx));\n }\n } else {\n if (ky < 0) {\n minxplusy = Math.max(minxplusy, safeDivide(a + (-kx) - 1, -kx));\n } else {\n minxminusy = Math.max(minxminusy, safeDivide(a + (-kx) - 1, -kx));\n }\n }\n }\n\n private long safeDivide(long a, long b) {\n if (a > 0) return a / b; else return (a - b + 1) / b;\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int l = in.nextInt();\n boolean[] know = new boolean[l + 1];\n long[] k = new long[l + 1];\n long[] ax = new long[l + 1];\n long[] ay = new long[l + 1];\n know[0] = true;\n know[l] = true;\n k[l] = 1;\n boolean knowP = false;\n long px = 0;\n long py = 0;\n for (int i = 0; i < n; ++i) {\n long t = in.nextLong();\n long x = in.nextLong();\n long y = in.nextLong();\n if ((x + y + t) % 2 != 0) {\n out.println(\"NO\");\n return;\n }\n int when = (int) (t % l);\n long ck = -t / l;\n if (!know[when]) {\n know[when] = true;\n k[when] = ck;\n ax[when] = x;\n ay[when] = y;\n } else {\n if (knowP) {\n if (k[when] * px + ax[when] != ck * px + x || Math.abs(k[when] * (double) px + ax[when] - ck * (double) px - x) > 1e62) {\n out.println(\"NO\");\n return;\n }\n if (k[when] * py + ay[when] != ck * py + y || Math.abs(k[when] * (double) py + ay[when] - ck * (double) py - y) > 1e62) {\n out.println(\"NO\");\n return;\n }\n } else {\n knowP = true;\n long numx = x - ax[when];\n long numy = y - ay[when];\n long den = k[when] - ck;\n if (numx % den != 0 || numy % den != 0) {\n out.println(\"NO\");\n return;\n }\n px = numx / den;\n py = numy / den;\n }\n }\n }\n\n {\n Intersector intersector = new Intersector();\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n for (int kx = -1; kx <= 1; kx += 2) {\n for (int ky = -1; ky <= 1; ky += 2) {\n intersector.update(kx * dk, ky * dk, kx * dax + ky * day - (i - prev));\n }\n }\n prev = i;\n }\n if (knowP) {\n if (px + py < intersector.minxplusy || px + py > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (px - py < intersector.minxminusy || px - py > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n } else {\n if (intersector.minxplusy > intersector.maxxplusy) {\n out.println(\"NO\");\n return;\n }\n if (intersector.minxminusy > intersector.maxxminusy) {\n out.println(\"NO\");\n return;\n }\n long xplusy;\n if (intersector.minxplusy == Long.MIN_VALUE) {\n if (intersector.maxxplusy == Long.MAX_VALUE) {\n xplusy = 0;\n } else {\n xplusy = intersector.maxxplusy - 1;\n }\n } else {\n xplusy = intersector.minxplusy;\n }\n long xminusy;\n if (intersector.minxminusy == Long.MIN_VALUE) {\n if (intersector.maxxminusy == Long.MAX_VALUE) {\n xminusy = 0;\n } else {\n xminusy = intersector.maxxminusy - 1;\n }\n } else {\n xminusy = intersector.minxminusy;\n }\n if ((xplusy + xminusy) % 2 != 0) {\n if (xplusy < intersector.maxxplusy) {\n ++xplusy;\n } else if (xminusy < intersector.maxxminusy) {\n ++xminusy;\n } else {\n out.println(\"NO\");\n return;\n }\n }\n px = (xplusy + xminusy) / 2;\n py = (xplusy - xminusy) / 2;\n }\n }\n\n int prev = 0;\n for (int i = 1; i <= l; ++i) if (know[i]) {\n long dk = k[i] - k[prev];\n long dax = ax[i] - ax[prev];\n long day = ay[i] - ay[prev];\n long dx = dk * px + dax;\n long dy = dk * py + day;\n if ((Math.abs(dx) + Math.abs(dy) > i - prev) || (Math.abs(dx) + Math.abs(dy) + (i - prev)) % 2 != 0) throw new RuntimeException();\n int extra = (int) ((i - prev - Math.abs(dx) - Math.abs(dy)) / 2);\n while (dx > 0) {\n out.print('R');\n --dx;\n }\n while (dx < 0) {\n out.print('L');\n ++dx;\n }\n while (dy > 0) {\n out.print('U');\n --dy;\n }\n while (dy < 0) {\n out.print('D');\n ++dy;\n }\n for (int j = 0; j < extra; ++j) {\n out.print(\"LR\");\n }\n prev = i;\n }\n out.println();\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c2f299684cf11b40604529a67a814d1", "src_uid": "941f1f8a37c25dd2405a20c7d416c9a6", "difficulty": 3100.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class F {\n\tstatic long mod = 1000000007;\n\tstatic long K;\n\tstatic long end;\n\tstatic long[] memo;\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tlong A = sc.nextLong();\n\t\tlong B = sc.nextLong();\n\t\tlong SA = A;\n\t\tlong SB = B;\n\t\tK = sc.nextLong();\n\t\tlong LCM = 1;\n\t\tfor(int a=2;a<=K;a++){\n\t\t\tLCM=LCM*a/GCD(LCM,a);\n\t\t}\n\t\tmemo = new long[(int)(LCM+10)];\n\t\tlong moves = 0;\n\t\twhile(A%LCM!=0){\n\t\t\tA--;\n\t\t//\tmoves++;\n\t\t}\n\t\twhile(B%LCM!=0){\n\t\t\tB++;\n\t\t//\tmoves++;\n\t\t}\n\t\t\n\t\t//System.out.println(B+\"->\"+A+\" \"+LCM);\n\t\tif(A<=SB){\n\t\t//\tSystem.out.println(\"HERE\");\n\t\t\tend = SB;\n\t\t\tArrays.fill(memo,-1);\n\t\t\tmoves = DP(SA-end);\n\t\t}\n\t\telse{\n\t\t\tend = 0;\n\t\t\tlong gap = (A-B)/LCM;\n\t\t\tArrays.fill(memo,-1);\n\n\t\t\tlong size = DP(LCM);\n\t\t\tmoves +=size*gap;\n\t\t\tend = SB;\n\t\t//\tSystem.out.println(moves);\n\t\t\tArrays.fill(memo,-1);\n\n\t\t\tmoves += DP(B-end);\n\t\t\tend = A;\n\t\t//\tSystem.out.println(moves);\n\t\t\tArrays.fill(memo,-1);\n\n\t\t\tmoves += DP(SA-end);\n\t\t}\n\t\tSystem.out.println(moves);\n\t}\n\n\tprivate static long DP(long cur) {\n\t\tif(cur==0)return 0;\n\t\tif(cur<0)return 99999;\n\t\tif(memo[(int)cur]!=-1)return memo[(int)cur];\n\t\tlong ans = 1+DP(cur-1);\n\t\tfor(int k=2;k<=K;k++){\n\t\t\tif((cur+end)%k!=0){\n\t\t\t\tans=Math.min(ans,1+DP(cur-((cur+end)%k)));\n\t\t\t}\n\t\t}\n\t\treturn memo[(int)cur]=ans;\n\t}\n\n\tprivate static long GCD(long a, long b) {\n\t\tif(b==0)return a;\n\t\treturn GCD(b,a%b);\n\t}\n\n\tstatic class FastScanner {\n\n\t\tBufferedReader br;\n\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream in) throws Exception {\n\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\n\t\t}\n\n\t\tpublic int numTokens() throws Exception {\n\n\t\t\tif (!st.hasMoreTokens()) {\n\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\n\t\t\t\treturn numTokens();\n\n\t\t\t}\n\n\t\t\treturn st.countTokens();\n\n\t\t}\n\n\t\tpublic String next() throws Exception {\n\n\t\t\tif (!st.hasMoreTokens()) {\n\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\n\t\t\t\treturn next();\n\n\t\t\t}\n\n\t\t\treturn st.nextToken();\n\n\t\t}\n\n\t\tpublic double nextDouble() throws Exception {\n\n\t\t\treturn Double.parseDouble(next());\n\n\t\t}\n\n\t\tpublic float nextFloat() throws Exception {\n\n\t\t\treturn Float.parseFloat(next());\n\n\t\t}\n\n\t\tpublic long nextLong() throws Exception {\n\n\t\t\treturn Long.parseLong(next());\n\n\t\t}\n\n\t\tpublic int nextInt() throws Exception {\n\n\t\t\treturn Integer.parseInt(next());\n\n\t\t}\n\n\t\tpublic String nextLine() throws Exception {\n\n\t\t\treturn br.readLine().trim();\n\n\t\t}\n\n\t}\n////\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ae840d8975ce9dc08b804fe5b57cd71e", "src_uid": "bd599d76c83cc1f30c1349ffb51b4273", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CF {\n\tstatic long mod = 1000000007;\n\tstatic long K;\n\tstatic long end;\n\tstatic long[] memo;\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tlong A = sc.nextLong();\n\t\tlong B = sc.nextLong();\n\t\tlong SA = A;\n\t\tlong SB = B;\n\t\tK = sc.nextLong();\n\t\tlong LCM = 1;\n\t\tfor(int a=2;a<=K;a++){\n\t\t\tLCM=LCM*a/GCD(LCM,a);\n\t\t}\n\t\tmemo = new long[(int)(LCM+10)];\n\t\tlong moves = 0;\n\t\twhile(A%LCM!=0){\n\t\t\tA--;\n\t\t//\tmoves++;\n\t\t}\n\t\twhile(B%LCM!=0){\n\t\t\tB++;\n\t\t//\tmoves++;\n\t\t}\n\t\t\n\t\t//System.out.println(B+\"->\"+A+\" \"+LCM);\n\t\tif(A<=SB){\n\t\t//\tSystem.out.println(\"HERE\");\n\t\t\tend = SB;\n\t\t\tArrays.fill(memo,-1);\n\t\t\tmoves = DP(SA-end);\n\t\t}\n\t\telse{\n\t\t\tend = 0;\n\t\t\tlong gap = (A-B)/LCM;\n\t\t\tArrays.fill(memo,-1);\n\n\t\t\tlong size = DP(LCM);\n\t\t\tmoves +=size*gap;\n\t\t\tend = SB;\n\t\t//\tSystem.out.println(moves);\n\t\t\tArrays.fill(memo,-1);\n\n\t\t\tmoves += DP(B-end);\n\t\t\tend = A;\n\t\t//\tSystem.out.println(moves);\n\t\t\tArrays.fill(memo,-1);\n\n\t\t\tmoves += DP(SA-end);\n\t\t}\n\t\tSystem.out.println(moves);\n\t}\n\n\tprivate static long DP(long cur) {\n\t\tif(cur==0)return 0;\n\t\tif(cur<0)return 99999;\n\t\tif(memo[(int)cur]!=-1)return memo[(int)cur];\n\t\tlong ans = 1+DP(cur-1);\n\t\tfor(int k=2;k<=K;k++){\n\t\t\tif((cur+end)%k!=0){\n\t\t\t\tans=Math.min(ans,1+DP(cur-((cur+end)%k)));\n\t\t\t}\n\t\t}\n\t\treturn memo[(int)cur]=ans;\n\t}\n\n\tprivate static long GCD(long a, long b) {\n\t\tif(b==0)return a;\n\t\treturn GCD(b,a%b);\n\t}\n\n\tstatic class FastScanner {\n\n\t\tBufferedReader br;\n\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream in) throws Exception {\n\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\n\t\t}\n\n\t\tpublic int numTokens() throws Exception {\n\n\t\t\tif (!st.hasMoreTokens()) {\n\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\n\t\t\t\treturn numTokens();\n\n\t\t\t}\n\n\t\t\treturn st.countTokens();\n\n\t\t}\n\n\t\tpublic String next() throws Exception {\n\n\t\t\tif (!st.hasMoreTokens()) {\n\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\n\t\t\t\treturn next();\n\n\t\t\t}\n\n\t\t\treturn st.nextToken();\n\n\t\t}\n\n\t\tpublic double nextDouble() throws Exception {\n\n\t\t\treturn Double.parseDouble(next());\n\n\t\t}\n\n\t\tpublic float nextFloat() throws Exception {\n\n\t\t\treturn Float.parseFloat(next());\n\n\t\t}\n\n\t\tpublic long nextLong() throws Exception {\n\n\t\t\treturn Long.parseLong(next());\n\n\t\t}\n\n\t\tpublic int nextInt() throws Exception {\n\n\t\t\treturn Integer.parseInt(next());\n\n\t\t}\n\n\t\tpublic String nextLine() throws Exception {\n\n\t\t\treturn br.readLine().trim();\n\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4edd72fd757ad35d33517f6b0c9bde32", "src_uid": "bd599d76c83cc1f30c1349ffb51b4273", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class f {\npublic static void main(String[] args)\n{\n Scanner input = new Scanner(System.in);\n long a = input.nextLong(), b = input.nextLong();\n int k = input.nextInt();\n int lcm = 1;\n for(int i = 2; i<=k; i++) lcm = lcm(lcm, i);\n int[] dp = new int[2*lcm];\n int start = (int)(a%lcm) + lcm;\n Arrays.fill(dp, 987654321);\n dp[start] = 0;\n for(int i = start; i>0; i--)\n {\n dp[i-1] = Math.min(dp[i-1], dp[i]+1);\n for(int j = 2; j<=k; j++)\n {\n int next = i - i%j;\n if(next >= 0) dp[next] = Math.min(dp[next], dp[i]+1);\n }\n }\n long res = 0;\n if(a-b >= lcm)\n {\n res = dp[lcm];\n a -= (a%lcm);\n }\n //System.out.println(dp[0]+\" \"+dp[lcm]);\n int lcmStep = dp[0]-dp[lcm];\n //System.out.println(lcm+\" \"+lcmStep);\n \n long numSteps = (a-b)/lcm - 2;\n if(numSteps > 0)\n {\n a -= lcm*numSteps;\n res += lcmStep*numSteps;\n }\n \n dp = new int[5*lcm];\n int end = (int)(b - lcm*(b/lcm));\n start = (int)(end + a - b);\n //System.out.println(start+\" \"+end);\n Arrays.fill(dp, 987654321);\n dp[start] = 0;\n for(int i = start; i>end; i--)\n {\n dp[i-1] = Math.min(dp[i-1], dp[i]+1);\n for(int j = 2; j<=k; j++)\n {\n int next = i - i%j;\n if(next > 0) dp[next] = Math.min(dp[next], dp[i]+1);\n }\n }\n \n res += dp[end];\n \n System.out.println(res);\n}\nstatic int lcm(int a, int b)\n{\n return a/gcd(a,b)*b;\n}\nstatic int gcd(int a, int b)\n{\n if(b==0) return a;\n return gcd(b, a%b);\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70cee3d55f1dfe1185c4cd8a0e690c8e", "src_uid": "bd599d76c83cc1f30c1349ffb51b4273", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.ByteArrayInputStream;\nimport java.io.DataInputStream;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\n/**\n * Actual solution is at the top\n * @author Tapan Sahni\n */\n\npublic class Tapan {\n public final static void main(String[] args) throws IOException {\n // TODO Auto-generated method stub\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n // Scanner in = new Scanner(inputStream);\n Reader in = new Reader();\n PrintWriter out = new PrintWriter(outputStream);\n Task_C solver = new Task_C();\n solver.solve( in, out);\n out.close();\n }\n}\nclass Task_C {\n\n @SuppressWarnings(\"unused\")\n \n public long step (long a , long b , long k){\n long ret = 0;\n while(a > b){\n long Max = 1;\n for(long i = 2 ;i<= k;i++ ){\n long l1 = a%i;\n if(a - l1 >= b)\n Max = Math.max(Max, l1);\n }\n if(Max == 0) Max = 1;\n a-=Max;\n ret++;\n }\n return ret;\n }\n public void solve(Reader in, PrintWriter out) throws IOException {\n long a = in.nextLong() , b = in.nextLong();\n long k = in.nextLong();\n long L = 360360L; \n if(a - b <= L) out.println(step(a , b , k));\n else{\n long ans = step(a%L , 0 , k);\n ans = ans + (long)step(L , 0 , k) * (a/L - b/L -1);\n ans = ans + (long)step(L ,b%L , k);\n out.println(ans);\n }\n }\n}\nclass 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[1001]; // 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 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 public char nextChar() throws IOException {\n byte c = read();\n while (c <= ' ')\n c = read();\n return (char) c;\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} \nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fc15770279b6b7ed567083ff8d86a0ef", "src_uid": "bd599d76c83cc1f30c1349ffb51b4273", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n static final long MODULO = (long) (1e9 + 7);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String c = in.next();\n String d = in.next();\n int n = in.nextInt();\n long res = 0;\n long waysEqual = 0;\n if (c.length() == d.length()) {\n waysEqual = 1;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n char ad = d.charAt(i);\n if (ac == '?') {\n if (ad == '?') {\n waysEqual = waysEqual * 2 % MODULO;\n }\n } else if (ad == '?') {\n\n } else {\n if (ac != ad) {\n waysEqual = 0;\n break;\n }\n }\n }\n long total = 1;\n for (int i = 0; i < n; ++i) {\n total = total * 2 % MODULO;\n }\n total = ((total * 2 - 2) % MODULO + MODULO) % MODULO;\n res = (res + total * total % MODULO * waysEqual) % MODULO;\n }\n\n long[] nonperiodic = new long[n + 1];\n nonperiodic[0] = 1;\n for (int i = 1; i <= n; ++i) nonperiodic[i] = 2 * nonperiodic[i - 1] % MODULO;\n long[] uptoValid = new long[n + 1];\n for (int i = 1; i <= n; ++i) {\n uptoValid[i] = uptoValid[i - 1] + nonperiodic[i];\n }\n for (int i = 1; i <= n; ++i) {\n for (int j = 2 * i; j <= n; j += i) {\n nonperiodic[j] -= nonperiodic[i];\n if (nonperiodic[j] < 0) nonperiodic[j] += MODULO;\n }\n }\n\n long anyValid = 0;\n for (int i = 1; i <= n; ++i) {\n long maxTimes = n / i;\n anyValid = (anyValid + nonperiodic[i] * maxTimes % MODULO * maxTimes) % MODULO;\n }\n\n int na = 0;\n int nb = 0;\n int qPlus = 0;\n int qMinus = 0;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n if (ac == 'A') ++na;\n else if (ac == 'B') ++nb;\n else ++qPlus;\n }\n for (int i = 0; i < d.length(); ++i) {\n char ad = d.charAt(i);\n if (ad == 'A') --na;\n else if (ad == 'B') --nb;\n else ++qMinus;\n }\n na -= qMinus;\n qPlus += qMinus;\n qMinus = 0;\n long[] invs = new long[qPlus + 1];\n if (qPlus > 0)\n invs[1] = 1;\n for (int i = 2; i <= qPlus; ++i) {\n invs[i] = (MODULO - invs[((int) (MODULO % i))] * (MODULO / i) % MODULO) % MODULO;\n if (invs[i] * i % MODULO != 1) throw new RuntimeException();\n }\n long comb = 1;\n for (int nPlus = 0; nPlus <= qPlus; ++nPlus) {\n if (nPlus > 0) {\n comb = comb * (qPlus - nPlus + 1) % MODULO * invs[nPlus] % MODULO;\n }\n int deltaMul = na + nPlus;\n int bMul = c.length() - d.length();\n if (deltaMul == 0 && bMul == 0) {\n res = ((res + (comb - waysEqual) * anyValid) % MODULO + MODULO) % MODULO;\n } else {\n int g = gcd(Math.abs(deltaMul), Math.abs(bMul));\n deltaMul /= g;\n bMul /= g;\n if (deltaMul != 0) {\n if (deltaMul < 0) {\n deltaMul = -deltaMul;\n bMul = -bMul;\n }\n int lb = deltaMul;\n int la = lb - bMul;\n if (la > 0) {\n res = (res + comb * uptoValid[n / Math.max(la, lb)]) % MODULO;\n }\n }\n }\n }\n\n out.println(res);\n }\n\n private 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 static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6edf381ff7df8dc0177c8d100aa2d32d", "src_uid": "4a6525f37d70dd1bf4f33cef57371b64", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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 TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n static final long MODULO = (long) (1e9 + 7);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String c = in.next();\n String d = in.next();\n int n = in.nextInt();\n long res = 0;\n long waysEqual = 0;\n if (c.length() == d.length()) {\n waysEqual = 1;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n char ad = d.charAt(i);\n if (ac == '?') {\n if (ad == '?') {\n waysEqual = waysEqual * 2 % MODULO;\n }\n } else if (ad == '?') {\n\n } else {\n if (ac != ad) {\n waysEqual = 0;\n break;\n }\n }\n }\n long total = 1;\n for (int i = 0; i < n; ++i) {\n total = total * 2 % MODULO;\n }\n total = ((total * 2 - 2) % MODULO + MODULO) % MODULO;\n res = (res + total * total % MODULO * waysEqual) % MODULO;\n }\n\n long[] nonperiodic = new long[n + 1];\n nonperiodic[0] = 1;\n for (int i = 1; i <= n; ++i) nonperiodic[i] = 2 * nonperiodic[i - 1] % MODULO;\n long[] uptoValid = new long[n + 1];\n for (int i = 1; i <= n; ++i) {\n uptoValid[i] = uptoValid[i - 1] + nonperiodic[i];\n uptoValid[i] %= MODULO;\n }\n for (int i = 1; i <= n; ++i) {\n for (int j = 2 * i; j <= n; j += i) {\n nonperiodic[j] -= nonperiodic[i];\n if (nonperiodic[j] < 0) nonperiodic[j] += MODULO;\n }\n }\n\n long anyValid = 0;\n for (int i = 1; i <= n; ++i) {\n long maxTimes = n / i;\n anyValid = (anyValid + nonperiodic[i] * maxTimes % MODULO * maxTimes) % MODULO;\n }\n\n int na = 0;\n int nb = 0;\n int qPlus = 0;\n int qMinus = 0;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n if (ac == 'A') ++na;\n else if (ac == 'B') ++nb;\n else ++qPlus;\n }\n for (int i = 0; i < d.length(); ++i) {\n char ad = d.charAt(i);\n if (ad == 'A') --na;\n else if (ad == 'B') --nb;\n else ++qMinus;\n }\n na -= qMinus;\n qPlus += qMinus;\n qMinus = 0;\n long[] invs = new long[qPlus + 1];\n if (qPlus > 0)\n invs[1] = 1;\n for (int i = 2; i <= qPlus; ++i) {\n invs[i] = (MODULO - invs[((int) (MODULO % i))] * (MODULO / i) % MODULO) % MODULO;\n if (invs[i] * i % MODULO != 1) throw new RuntimeException();\n }\n long comb = 1;\n for (int nPlus = 0; nPlus <= qPlus; ++nPlus) {\n if (nPlus > 0) {\n comb = comb * (qPlus - nPlus + 1) % MODULO * invs[nPlus] % MODULO;\n }\n int deltaMul = na + nPlus;\n int bMul = c.length() - d.length();\n if (deltaMul == 0 && bMul == 0) {\n res = ((res + (comb - waysEqual) * anyValid) % MODULO + MODULO) % MODULO;\n } else {\n int g = gcd(Math.abs(deltaMul), Math.abs(bMul));\n deltaMul /= g;\n bMul /= g;\n if (deltaMul != 0) {\n if (deltaMul < 0) {\n deltaMul = -deltaMul;\n bMul = -bMul;\n }\n int lb = deltaMul;\n int la = lb - bMul;\n if (la > 0) {\n res = (res + comb * uptoValid[n / Math.max(la, lb)]) % MODULO;\n }\n }\n }\n }\n\n out.println(res);\n }\n\n private 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 static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7adcd3a93a07cdd68348f2101d6f3f8d", "src_uid": "4a6525f37d70dd1bf4f33cef57371b64", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n 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 static final long MODULO = (long) (1e9 + 7);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String c = in.next();\n String d = in.next();\n int n = in.nextInt();\n long res = 0;\n long waysEqual = 0;\n if (c.length() == d.length()) {\n waysEqual = 1;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n char ad = d.charAt(i);\n if (ac == '?') {\n if (ad == '?') {\n waysEqual = waysEqual * 2 % MODULO;\n }\n } else if (ad == '?') {\n\n } else {\n if (ac != ad) {\n waysEqual = 0;\n break;\n }\n }\n }\n long total = 1;\n for (int i = 0; i < n; ++i) {\n total = total * 2 % MODULO;\n }\n total = ((total * 2 - 2) % MODULO + MODULO) % MODULO;\n res = (res + total * total % MODULO * waysEqual) % MODULO;\n }\n\n long[] nonperiodic = new long[n + 1];\n nonperiodic[0] = 1;\n for (int i = 1; i <= n; ++i) nonperiodic[i] = 2 * nonperiodic[i - 1] % MODULO;\n long[] uptoValid = new long[n + 1];\n for (int i = 1; i <= n; ++i) {\n uptoValid[i] = uptoValid[i - 1] + nonperiodic[i];\n uptoValid[i] %= MODULO;\n }\n for (int i = 1; i <= n; ++i) {\n for (int j = 2 * i; j <= n; j += i) {\n nonperiodic[j] -= nonperiodic[i];\n if (nonperiodic[j] < 0) nonperiodic[j] += MODULO;\n }\n }\n\n long anyValid = 0;\n for (int i = 1; i <= n; ++i) {\n long maxTimes = n / i;\n anyValid = (anyValid + nonperiodic[i] * maxTimes % MODULO * maxTimes) % MODULO;\n }\n\n int na = 0;\n int nb = 0;\n int qPlus = 0;\n int qMinus = 0;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n if (ac == 'A') ++na;\n else if (ac == 'B') ++nb;\n else ++qPlus;\n }\n for (int i = 0; i < d.length(); ++i) {\n char ad = d.charAt(i);\n if (ad == 'A') --na;\n else if (ad == 'B') --nb;\n else ++qMinus;\n }\n na -= qMinus;\n qPlus += qMinus;\n qMinus = 0;\n long[] invs = new long[qPlus + 1];\n if (qPlus > 0)\n invs[1] = 1;\n for (int i = 2; i <= qPlus; ++i) {\n invs[i] = (MODULO - invs[((int) (MODULO % i))] * (MODULO / i) % MODULO) % MODULO;\n if (invs[i] * i % MODULO != 1) throw new RuntimeException();\n }\n long comb = 1;\n for (int nPlus = 0; nPlus <= qPlus; ++nPlus) {\n if (nPlus > 0) {\n comb = comb * (qPlus - nPlus + 1) % MODULO * invs[nPlus] % MODULO;\n }\n int deltaMul = na + nPlus;\n int bMul = c.length() - d.length();\n if (deltaMul == 0 && bMul == 0) {\n res = ((res + (comb - waysEqual) * anyValid) % MODULO + MODULO) % MODULO;\n } else {\n int g = gcd(Math.abs(deltaMul), Math.abs(bMul));\n deltaMul /= g;\n bMul /= g;\n if (deltaMul != 0) {\n if (deltaMul < 0) {\n deltaMul = -deltaMul;\n bMul = -bMul;\n }\n int lb = deltaMul;\n int la = lb - bMul;\n if (la > 0) {\n res = (res + comb * uptoValid[n / Math.max(la, lb)]) % MODULO;\n }\n }\n }\n }\n\n out.println(res);\n }\n\n private 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 static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b10a96e52a57537dca5d808eeaba408b", "src_uid": "4a6525f37d70dd1bf4f33cef57371b64", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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 TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n static final long MODULO = (long) (1e9 + 7);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String c = in.next();\n String d = in.next();\n int n = in.nextInt();\n long res = 0;\n long waysEqual = 0;\n if (c.length() == d.length()) {\n waysEqual = 1;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n char ad = d.charAt(i);\n if (ac == '?') {\n if (ad == '?') {\n waysEqual = waysEqual * 2 % MODULO;\n }\n } else if (ad == '?') {\n\n } else {\n if (ac != ad) {\n waysEqual = 0;\n break;\n }\n }\n }\n long total = 1;\n for (int i = 0; i < n; ++i) {\n total = total * 2 % MODULO;\n }\n total = ((total * 2 - 2) % MODULO + MODULO) % MODULO;\n res = (res + total * total % MODULO * waysEqual) % MODULO;\n }\n\n long[] nonperiodic = new long[n + 1];\n nonperiodic[0] = 1;\n for (int i = 1; i <= n; ++i) nonperiodic[i] = 2 * nonperiodic[i - 1] % MODULO;\n long[] uptoValid = new long[n + 1];\n for (int i = 1; i <= n; ++i) {\n uptoValid[i] = uptoValid[i - 1] + nonperiodic[i];\n uptoValid[i] %= MODULO;\n }\n for (int i = 1; i <= n; ++i) {\n for (int j = 2 * i; j <= n; j += i) {\n nonperiodic[j] -= nonperiodic[i];\n if (nonperiodic[j] < 0) nonperiodic[j] += MODULO;\n }\n }\n\n long anyValid = 0;\n for (int i = 1; i <= n; ++i) {\n long maxTimes = n / i;\n anyValid = (anyValid + nonperiodic[i] * maxTimes % MODULO * maxTimes) % MODULO;\n }\n\n int na = 0;\n int nb = 0;\n int qPlus = 0;\n int qMinus = 0;\n for (int i = 0; i < c.length(); ++i) {\n char ac = c.charAt(i);\n if (ac == 'A') ++na;\n else if (ac == 'B') ++nb;\n else ++qPlus;\n }\n for (int i = 0; i < d.length(); ++i) {\n char ad = d.charAt(i);\n if (ad == 'A') --na;\n else if (ad == 'B') --nb;\n else ++qMinus;\n }\n na -= qMinus;\n qPlus += qMinus;\n qMinus = 0;\n long[] invs = new long[qPlus + 1];\n if (qPlus > 0)\n invs[1] = 1;\n for (int i = 2; i <= qPlus; ++i) {\n invs[i] = (MODULO - invs[((int) (MODULO % i))] * (MODULO / i) % MODULO) % MODULO;\n if (invs[i] * i % MODULO != 1) throw new RuntimeException();\n }\n long comb = 1;\n for (int nPlus = 0; nPlus <= qPlus; ++nPlus) {\n if (nPlus > 0) {\n comb = comb * (qPlus - nPlus + 1) % MODULO * invs[nPlus] % MODULO;\n }\n int deltaMul = na + nPlus;\n int bMul = c.length() - d.length();\n if (deltaMul == 0 && bMul == 0) {\n res = ((res + (comb - waysEqual) * anyValid) % MODULO + MODULO) % MODULO;\n } else {\n int g = gcd(Math.abs(deltaMul), Math.abs(bMul));\n deltaMul /= g;\n bMul /= g;\n if (deltaMul != 0) {\n if (deltaMul < 0) {\n deltaMul = -deltaMul;\n bMul = -bMul;\n }\n int lb = deltaMul;\n int la = lb - bMul;\n if (la > 0) {\n res = (res + comb * uptoValid[n / Math.max(la, lb)]) % MODULO;\n }\n }\n }\n }\n\n out.println(res);\n }\n\n private 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 static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c49dd58010dca4df817af091245c3369", "src_uid": "4a6525f37d70dd1bf4f33cef57371b64", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Igor Kraskevich\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\tTaskD2 solver = new TaskD2();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD2 {\n\n final long MOD = 1_000_003;\n\n long binPow(long x, long n) {\n long res = 1;\n while (n > 0) {\n if (n % 2 == 1)\n res = res * x % MOD;\n x = x * x % MOD;\n n /= 2;\n }\n return res;\n }\n\n long inv(long x) {\n return binPow(x, MOD - 2);\n }\n\n long fac(long n) {\n long res = 1;\n for (int i = 1; i <= n; i++)\n res = res * i % MOD;\n return res;\n }\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n long res = fac(n + k);\n res = res * inv(fac(k)) % MOD;\n res = res * inv(fac(n)) % MOD;\n out.println((res - 1 + MOD) % MOD);\n }\n}\n\nclass FastScanner {\n private StringTokenizer tokenizer;\n private BufferedReader reader;\n\n public FastScanner(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n String line = null;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n }\n if (line == null)\n return null;\n tokenizer = new StringTokenizer(line);\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ef92029e415fa561e919c39644ec801", "src_uid": "e63c70a9c96a94bce99618f2e695f83a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.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.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class D2 {\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tstatic final int MOD = 1000003;\n\n\tstatic int sub(int a, int b) {\n\t\tint res = a - b;\n\t\tif (res < 0) {\n\t\t\tres += MOD;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic int mul(int a, int b) {\n\t\treturn (int) ((long) a * b % MOD);\n\t}\n\n\tstatic int inv(int a) {\n\t\treturn BigInteger.valueOf(a).modInverse(BigInteger.valueOf(MOD)).intValue();\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint c = nextInt();\n\t\tint num = 1, den = 1;\n\t\tfor (int i = 0; i < c; i++) {\n\t\t\tnum = mul(num, n + i + 1);\n\t\t\tden = mul(den, i + 1);\n\t\t}\n\t\tout.print(sub(mul(num, inv(den)), 1));\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "400a3c40f154b82355e5e372972b04d1", "src_uid": "e63c70a9c96a94bce99618f2e695f83a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class HelveticqE {\n\n static final int mod = (int)1e6 + 3;\n \n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\n int n = in.nextInt();\n int c = in.nextInt();\n \n long fact[] = new long[n + c + 2];\n fact[0] = 1;\n for (int i = 1; i < fact.length; i++)\n fact[i] = (fact[i - 1] * i) % mod;\n \n long ans = fact[n + c];\n ans *= pow(fact[n], mod - 2);\n ans %= mod;\n ans *= pow(fact[c], mod - 2);\n ans %= mod;\n ans -= 1;\n ans += mod;\n ans %= mod;\n \n w.println(ans);\n w.close();\n }\n\n static long pow(long a, int b) {\n if (b == 0)\n return 1;\n long t = pow(a, b >> 1);\n t = (t * t) % mod;\n if(b % 2 == 1)\n t = (t * a) % mod;\n return t;\n }\n static class InputReader {\n\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int snext() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public 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 = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bb1da949543f4c8865ae1bdbbece38d1", "src_uid": "e63c70a9c96a94bce99618f2e695f83a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "//Created by Aminul on 4/3/2019.\n\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class CF690D2 {\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(), m = in.nextInt();\n initialize(n + m + 10);\n long ans = 0;\n for (int i = 1; i <= m; i++) {\n ans = (ans + nCr(n + i - 1, i)) % mod;\n }\n pw.println(ans);\n pw.close();\n }\n\n static long f[], inv[], mod = (int) 1e6 + 3;\n\n static void initialize(int n) {\n f = new long[n + 1];\n f[0] = 1;\n for (int i = 1; i <= n; i++) {\n f[i] = (f[i - 1] * i) % mod;\n }\n inv = new long[n + 1];\n inv[n] = BigInteger.valueOf(f[n]).modInverse(BigInteger.valueOf(mod)).longValue();\n for (int i = n - 1; i >= 0; i--) {\n inv[i] = (inv[i + 1] * (i + 1)) % mod;\n }\n }\n\n static long nCr(int n, int c) {\n long u = f[n], d = (inv[c] * inv[n - c]) % mod;\n return (u * d) % mod;\n }\n\n static void debug(Object...obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fed630762ea69a3eaad0bf10c1946eaa", "src_uid": "e63c70a9c96a94bce99618f2e695f83a", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\t\n\tpublic static void main(String args[]) throws IOException{\n\t\tnew Main().mains();\n\t}\n\t\n\tpublic int P[],move_range[],throw_range[],ans,name[][];\n\tpublic boolean F[];\n\t//0-2\u80fd\u5426\u79fb\u52a8 0\u53ef\u4ee5\u4e3e\u4eba 1\u4e3e\u4e86\u5c0f\u7684 2\u4e3e\u4e86\u5927\u7684 3\u5df2\u7ecf\u6254\u51fa\u53bb\n\t\n\tint sta_num(int statue){\n\t\tint ret = (P[1] - 1) + (P[2] - 1) * 42 + (P[3] - 1) * 42 * 42;\n\t\treturn ret + statue * 42 * 42 * 42;\n\t}\n\t\n\tint num(int a, int b){\n\t\tif (b == 0) return (a == 1) ? (2) : (1);\n\t\treturn (a == 3) ? (2) : (3);\n\t}\n\t\n\tvoid DFS(int statue){\n\t\tans = Math.max(ans, Math.max(Math.max(P[3], P[1]), P[2]));\n\t\tif (F[sta_num(statue)] == true) return;\n\t\tF[sta_num(statue)] = true;\n\t\tint foru[] = new int[4];\n\t\t/*int check[] = new int[4];\n\t\tfor (int i = 1; i <= 3; i ++) check[i] = P[i];*/\n\t\tboolean be_throwed[] = new boolean[4];\n\t\tfor (int mv = 1; mv <= 3; mv ++)\n\t\t\tbe_throwed[mv] = false;\n\t\tfor (int mv = 1; mv <= 3; mv ++){\n\t\t\tforu[mv] = (statue >> (3 + (mv - 1) * 2)) % 4;\n\t\t\tif (foru[mv] >= 1 && foru[mv] <= 2)\n\t\t\t\tbe_throwed[num(mv, foru[mv] - 1)] = true;\n\t\t}\n\t\tfor (int i = 1; i <= 3; i ++)\n\t\t\tif ((statue & (1 << (i - 1))) == 0 && (foru[i] == 0 || foru[i] == 3)){\n\t\t\t\tfor (int step = -move_range[i]; step <= move_range[i]; step ++){\n\t\t\t\t\tif (step + P[i] < 1) continue;\n\t\t\t\t\tboolean could = true;\n\t\t\t\t\tfor (int j = 1; j <= 3; j ++)\n\t\t\t\t\t\tif (step + P[i] == P[j])\n\t\t\t\t\t\t\tcould = false;\n\t\t\t\t\tif (could == false) continue;\n\t\t\t\t\tP[i] += step;\n\t\t\t\t\tDFS(statue | (1 << (i - 1)));\n\t\t\t\t\tP[i] -= step;\n\t\t\t\t}\n\t\t\t}\n\t\tfor (int i = 1; i <= 3; i ++){\n\t\t\tfor (int j = 1; j <= 3; j ++)\n\t\t\t\tif (i != j && Math.abs(P[i] - P[j]) == 1 && be_throwed[j] == false && foru[i] == 0 && be_throwed[i] == false){\n\t\t\t\t\tint diff = 6 - i - j;\n\t\t\t\t\tint temp[] = new int[4],newsta = statue | ((1 << ((2 * i - 2) + 3)) * (name[i][j] + 1));\n\t\t\t\t\ttemp[1] = P[1]; temp[2] = P[2]; temp[3] = P[3];\n\t\t\t\t\tP[j] = P[i];\n\t\t\t\t\tif (be_throwed[diff] == true) P[diff] = P[i];\n\t\t\t\t\tDFS(newsta);\n\t\t\t\t\tP[1] = temp[1]; P[2] = temp[2]; P[3] = temp[3];\n\t\t\t\t}\n\t\t\tif (be_throwed[i] == false && foru[i] >= 1 && foru[i] <= 2){\n\t\t\t\tint j = num(i, foru[i] - 1), diff = 6 - i - j;\n\t\t\t\tint xor = ((1 << (2 * i - 2) + 3) * (foru[i]));\n\t\t\t\tfor (int step = -throw_range[i]; step <= throw_range[i]; step ++) if (step != 0){\n\t\t\t\t\tint temp[] = new int[4],newsta = (statue ^ xor) | (3 * (1 << ((2 * i - 2) + 3)));\n\t\t\t\t\ttemp[1] = P[1]; temp[2] = P[2]; temp[3] = P[3];\n\t\t\t\t\tP[j] = P[i] + step;\n\t\t\t\t\tif (be_throwed[diff] == true) P[diff] = P[i] + step;\n\t\t\t\t\tDFS(newsta);\n\t\t\t\t\tP[1] = temp[1]; P[2] = temp[2]; P[3] = temp[3];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic void solve() throws IOException{\n\t\tP = new int[4];\n\t\tmove_range = new int[4];\n\t\tthrow_range = new int[4];\n\t\tname = new int[5][5];\n\t\tname[1][3] = name[2][3] = name[3][2] = 1;\n\t\tF = new boolean[(42 * 8) * (42 * 8) * (42 * 8) + 100];\n\t\tfor (int i = 1; i <= 3; i ++){\n\t\t\tP[i] = nextInt();\n\t\t\tmove_range[i] = nextInt();\n\t\t\tthrow_range[i] = nextInt();\n\t\t}\n\t\tDFS(0);\n\t\tout.println(ans);\n\t}\n\t\n\tvoid mains() throws IOException{\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\ttokenizer = null;\n\t\t//File fin = new File(\"a.in\");\n\t\t//reader = new BufferedReader(new InputStreamReader(new FileInputStream(fin)));\n\t\t//out = new PrintWriter(\"a.out\");\n\t\tsolve();\n\t\treader.close();\n\t\tout.flush();\n\t}\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString 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}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea432a5eafb50e146ba262875222dd2d", "src_uid": "a14739b86d1fd62a030226263cdc1afc", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\t\n\tpublic static void main(String args[]) throws IOException{\n\t\tnew Main().mains();\n\t}\n\t\n\tpublic int P[],move_range[],throw_range[],ans,name[][];\n\tpublic boolean F[];\n\t//0-2\u80fd\u5426\u79fb\u52a8 0\u53ef\u4ee5\u4e3e\u4eba 1\u4e3e\u4e86\u5c0f\u7684 2\u4e3e\u4e86\u5927\u7684 3\u5df2\u7ecf\u6254\u51fa\u53bb\n\t\n\tint sta_num(int statue){\n\t\tint ret = (P[1] - 1) + (P[2] - 1) * 42 + (P[3] - 1) * 42 * 42;\n\t\treturn ret + statue * 42 * 42 * 42;\n\t}\n\t\n\tint num(int a, int b){\n\t\tif (b == 0) return (a == 1) ? (2) : (1);\n\t\treturn (a == 3) ? (2) : (3);\n\t}\n\t\n\tvoid DFS(int statue){\n\t\tans = Math.max(ans, Math.max(Math.max(P[3], P[1]), P[2]));\n\t\tif (Math.max(Math.max(P[3], P[1]), P[2]) == 17){\n\t\t\tint nis = 33;\n\t\t\tnis = 1;\n\t\t}\n\t\tif (F[sta_num(statue)] == true) return;\n\t\tF[sta_num(statue)] = true;\n\t\tint foru[] = new int[4];\n\t\tint check[] = new int[4];\n\t\tfor (int i = 1; i <= 3; i ++) check[i] = P[i];\n\t\tboolean be_throwed[] = new boolean[4];\n\t\tfor (int mv = 1; mv <= 3; mv ++)\n\t\t\tbe_throwed[mv] = false;\n\t\tfor (int mv = 1; mv <= 3; mv ++){\n\t\t\tforu[mv] = (statue >> (3 + (mv - 1) * 2)) % 4;\n\t\t\tif (foru[mv] >= 1 && foru[mv] <= 2)\n\t\t\t\tbe_throwed[num(mv, foru[mv] - 1)] = true;\n\t\t}\n\t\tfor (int i = 1; i <= 3; i ++)\n\t\t\tif ((statue & (1 << (i - 1))) == 0 && (foru[i] == 0 || foru[i] == 3)){\n\t\t\t\tfor (int step = -move_range[i]; step <= move_range[i]; step ++){\n\t\t\t\t\tif (step + P[i] < 1) continue;\n\t\t\t\t\tboolean could = true;\n\t\t\t\t\tfor (int j = 1; j <= 3; j ++)\n\t\t\t\t\t\tif (step + P[i] == P[j])\n\t\t\t\t\t\t\tcould = false;\n\t\t\t\t\tif (could == false) continue;\n\t\t\t\t\tP[i] += step;\n\t\t\t\t\tDFS(statue | (1 << (i - 1)));\n\t\t\t\t\tP[i] -= step;\n\t\t\t\t}\n\t\t\t}\n\t\tfor (int i = 1; i <= 3; i ++){\n\t\t\tfor (int j = 1; j <= 3; j ++)\n\t\t\t\tif (i != j && Math.abs(P[i] - P[j]) == 1 && be_throwed[j] == false && foru[i] == 0 && be_throwed[i] == false){\n\t\t\t\t\tint diff = 6 - i - j;\n\t\t\t\t\tint temp[] = new int[4],newsta = statue | ((1 << ((2 * i - 2) + 3)) * (name[i][j] + 1));\n\t\t\t\t\ttemp[1] = P[1]; temp[2] = P[2]; temp[3] = P[3];\n\t\t\t\t\tP[j] = P[i];\n\t\t\t\t\tif (be_throwed[diff] == true) P[diff] = P[i];\n\t\t\t\t\tDFS(newsta);\n\t\t\t\t\tP[1] = temp[1]; P[2] = temp[2]; P[3] = temp[3];\n\t\t\t\t}\n\t\t\tif (be_throwed[i] == false && foru[i] >= 1 && foru[i] <= 2){\n\t\t\t\tint j = num(i, foru[i] - 1), diff = 6 - i - j;\n\t\t\t\tint xor = ((1 << (2 * i - 2) + 3) * (foru[i]));\n\t\t\t\tfor (int step = -throw_range[i]; step <= throw_range[i]; step ++) if (step != 0){\n\t\t\t\t\tint temp[] = new int[4],newsta = (statue ^ xor) | (3 * (1 << ((2 * i - 2) + 3)));\n\t\t\t\t\ttemp[1] = P[1]; temp[2] = P[2]; temp[3] = P[3];\n\t\t\t\t\tP[j] = P[i] + step;\n\t\t\t\t\tif (be_throwed[diff] == true) P[diff] = P[i] + step;\n\t\t\t\t\tDFS(newsta);\n\t\t\t\t\tP[1] = temp[1]; P[2] = temp[2]; P[3] = temp[3];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic void solve() throws IOException{\n\t\tP = new int[4];\n\t\tmove_range = new int[4];\n\t\tthrow_range = new int[4];\n\t\tname = new int[5][5];\n\t\tname[1][3] = name[2][3] = name[3][2] = 1;\n\t\tF = new boolean[(42 * 8) * (42 * 8) * (42 * 8) + 100];\n\t\tfor (int i = 1; i <= 3; i ++){\n\t\t\tP[i] = nextInt();\n\t\t\tmove_range[i] = nextInt();\n\t\t\tthrow_range[i] = nextInt();\n\t\t}\n\t\tDFS(0);\n\t\tout.println(ans);\n\t}\n\t\n\tvoid mains() throws IOException{\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\ttokenizer = null;\n\t\t//File fin = new File(\"a.in\");\n\t\t//reader = new BufferedReader(new InputStreamReader(new FileInputStream(fin)));\n\t\t//out = new PrintWriter(\"a.out\");\n\t\tsolve();\n\t\treader.close();\n\t\tout.flush();\n\t}\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString 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}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fe9a9bb6207e1b51c1605cae664ea36a", "src_uid": "a14739b86d1fd62a030226263cdc1afc", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Character.isDigit;\nimport static java.lang.Character.isLowerCase;\nimport static java.lang.Character.isUpperCase;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport static java.lang.Character.isDigit;\n\npublic class Main{\n \n void run(){\n Cond cond = new Cond();\n System.out.println(doit(cond));\n }\n HashMap map=new HashMap();\n private int doit(Cond cond){\n if(map.containsKey(cond))return map.get(cond);\n List allNexts = cond.allNexts();\n int res=cond.getMaxX();\n for(Cond c:allNexts) {\n res = max(res,doit(c));\n }\n map.put(cond,res);\n return res;\n }\n interface Command{\n boolean doit();\n void undo();\n }\n class Move implements Command{\n Person p;\n int x;\n Move(Person p,int x){\n this.p=p;\n this.x=x;\n }\n public boolean doit(){\n if(p.moved || p.lifted || p.lifting!=null)return false;\n p.x += x;\n p.moved=true;\n return true;\n }\n public void undo(){\n assert p.moved && !p.lifted && p.lifting==null;\n p.x-=x;\n p.moved=false;\n }\n }\n class Lift implements Command{\n Person p,q;\n Lift(Person p,Person q){\n this.p=p;this.q=q;\n }\n int from;\n public boolean doit(){\n if(q.lifted || p.lifted || p.lifting!=null || p.throwed)return false;\n if(abs(p.x-q.x)!=1)return false;\n from = q.x;\n q.x=p.x;\n if(q.lifting!=null)q.lifting.x=p.x;\n p.lifting=q;\n q.lifted = true;\n return true;\n }\n public void undo(){\n assert p.lifting==q && q.lifted && q.x==p.x;\n q.x=from;\n if(q.lifting!=null)q.lifting.x=from;\n p.lifting=null;\n q.lifted=false;\n }\n }\n \n class Throw implements Command{\n Person p;\n int x;\n Throw(Person p,int x){\n this.p=p;\n this.x=x;\n }\n Person q;\n public boolean doit(){\n if(p.lifted || p.lifting==null)return false;\n q=p.lifting;\n assert q.x==p.x;\n assert q.x==p.x && !p.throwed;\n assert q.x==p.x && !p.throwed && q.lifted;\n p.lifting=null;\n p.throwed=true;\n q.lifted=false;\n q.x += x;\n if(q.lifting!=null)q.lifting.x += x;\n return true;\n }\n\n public void undo(){\n assert p.lifting==null && p.throwed && !q.lifted && q.x==p.x+x;\n p.lifting=q;\n p.throwed=false;\n q.lifted=true;\n q.x -= x;\n if(q.lifting!=null)q.lifting.x -= x;\n }\n }\n \n class Cond{\n Person[] ps;\n Cond(){\n ps=new Person[3];\n for(int i=0;i<3;i++)ps[i]=new Person(nextInt(),nextInt(),nextInt());\n }\n Cond(Person[]ps){\n this.ps=ps;\n }\n public List allNexts(){\n ArrayList list=new ArrayList();\n Cond now = this.myClone();\n for(Person p:ps) {\n assert p!=null;\n for(int i=-p.maxMove;i<=p.maxMove;i++) {\n Command c = new Move(p,i);\n if(c.doit()) {\n list.add(this.myClone());\n c.undo();\n assert now.equals(this);\n }\n }\n for(Person q:ps)if(p!=q) {\n Command c = new Lift(p,q);\n if(c.doit()) {\n list.add(this.myClone());\n c.undo();\n assert now.equals(this);\n }\n }\n for(int i=-p.power;i<=p.power;i++) {\n Command c = new Throw(p,i);\n Person q = p.lifting;\n if(c.doit()) {\n assert asList(ps).contains(q);\n list.add(this.myClone());\n c.undo();\n assert now.equals(this);\n }\n }\n }\n return list;\n }\n private Cond myClone(){\n Person[] qs = new Person[3];\n int cnt=0;\n for(;;) {\n for(int i=0;i<3;i++)if(qs[i]==null) {\n if(ps[i].lifting==null) {\n cnt++;\n qs[i]=ps[i].myClone();\n }\n else {\n if(asList(qs).contains(ps[i].lifting)) {\n cnt++;\n Person q = ps[i].myClone();\n q.lifting = asList(qs).get(asList(qs).indexOf(q.lifting));\n assert q.lifting.x == q.x;\n qs[i]=q;\n }\n }\n }\n if(cnt==3)break;\n }\n Cond cond = new Cond(qs);\n return cond;\n }\n \n public String toString(){\n return \"Cond [ps=\"+Arrays.toString(ps)+\"]\";\n }\n public int getMaxX(){\n int res=0;\n for(Person p:ps)res = max(res,p.x);\n return res;\n }\n public int hashCode(){\n final int prime=31;\n int result=1;\n result=prime*result+getOuterType().hashCode();\n result=prime*result+Arrays.hashCode(ps);\n return result;\n }\n public boolean equals(Object obj){\n if(this==obj) return true;\n if(obj==null) return false;\n if(getClass()!=obj.getClass()) return false;\n Cond other=(Cond)obj;\n if(!getOuterType().equals(other.getOuterType())) return false;\n if(!Arrays.equals(ps,other.ps)) return false;\n return true;\n }\n private Main getOuterType(){\n return Main.this;\n }\n }\n \n class Person {\n \n public String toString(){\n return \"Person [lifted=\"+lifted+\", lifting=\"+lifting+\", maxMove=\"+maxMove+\", moved=\"+moved+\", power=\"+power\n +\", throwed=\"+throwed+\", x=\"+x+\"]\";\n }\n boolean moved;\n Person lifting;\n boolean throwed;\n boolean lifted;\n int x;\n int power;\n int maxMove;\n \n public Person myClone(){\n return new Person(moved,lifting==null ? null : lifting.myClone(),throwed,lifted,x,power,maxMove);\n }\n\n\n private Person(boolean moved,Person lifting,boolean throwed,boolean lifted,int x,int power,int maxMove){\n super();\n this.moved=moved;\n this.lifting=lifting;\n this.throwed=throwed;\n this.lifted=lifted;\n this.x=x;\n this.power=power;\n this.maxMove=maxMove;\n }\n \n\n public Person(int x,int maxMove,int power){\n this.x=x;\n this.maxMove=maxMove;\n this.power=power;\n }\n\n public int hashCode(){\n final int prime=31;\n int result=1;\n result=prime*result+getOuterType().hashCode();\n result=prime*result+(lifted?1231:1237);\n result=prime*result+((lifting==null)?0:lifting.hashCode());\n result=prime*result+maxMove;\n result=prime*result+(moved?1231:1237);\n result=prime*result+power;\n result=prime*result+(throwed?1231:1237);\n result=prime*result+x;\n return result;\n }\n public boolean equals(Object obj){\n if(this==obj) return true;\n if(obj==null) return false;\n if(getClass()!=obj.getClass()) return false;\n Person other=(Person)obj;\n if(!getOuterType().equals(other.getOuterType())) return false;\n if(lifted!=other.lifted) return false;\n if(lifting==null){\n if(other.lifting!=null) return false;\n }else if(!lifting.equals(other.lifting)) return false;\n if(maxMove!=other.maxMove) return false;\n if(moved!=other.moved) return false;\n if(power!=other.power) return false;\n if(throwed!=other.throwed) return false;\n if(x!=other.x) return false;\n return true;\n }\n private Main getOuterType(){\n return Main.this;\n }\n \n }\n \n int nextInt(){\n try{\n int c=System.in.read();\n if(c==-1) return c;\n while(c!='-'&&(c<'0'||'9' {\n if (point > 1) {\n graph.add(points.lowerBound(point), points.lowerBound(point >> 1));\n }\n });\n for (int i = 0; i < m; ++i) {\n graph.add(points.lowerBound(end1[i]), points.lowerBound(end2[i]));\n }\n }\n\n void initPoints() {\n points = new IntArrayList();\n for (int i = 0; i < m; ++i) {\n addKeyPoints(end1[i]);\n addKeyPoints(end2[i]);\n }\n points.sortAndUnique();\n if (points.isEmpty()) {\n points.add(1);\n }\n pointCounts = new IntArrayList(points.size);\n for (int point : points) {\n int cnt = 1;\n if (!points.binarySearch(point << 1)) {\n cnt += calcSubtree(point << 1);\n }\n if (!points.binarySearch((point << 1) | 1)) {\n cnt += calcSubtree((point << 1) | 1);\n }\n pointCounts.add(cnt);\n }\n }\n\n int calcSubtree(int x) {\n int lower = x, upper = x;\n int res = 0;\n for (; lower <= n; lower <<= 1, upper = (upper << 1) | 1) {\n res += Math.min(n, upper) - lower + 1;\n if (n <= upper) break;\n }\n return res;\n }\n\n void addKeyPoints(int x) {\n for (; x > 0; x >>= 1) points.add(x);\n }\n\n }\n\n static abstract class AbstractBidirectionalGraph extends AbstractDirectedGraph implements BidirectionalGraphInterface {\n public AbstractBidirectionalGraph() {\n super();\n }\n\n public AbstractBidirectionalGraph(int vertexCapacity, int edgeCapacity) {\n super(vertexCapacity, edgeCapacity << 1);\n }\n\n public AbstractBidirectionalGraph(int vertexCapacity, int edgeCapacity, boolean initialize) {\n super(vertexCapacity, edgeCapacity << 1, initialize);\n }\n\n\n public void add(int u, int v) {\n super.add(u, v);\n super.add(v, u);\n }\n\n }\n\n static class QuickWriter {\n private final PrintWriter writer;\n\n public QuickWriter(OutputStream outputStream) {\n this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public QuickWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; ++i) {\n if (i > 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void println(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n }\n\n static final class BidirectionalGraph extends AbstractBidirectionalGraph {\n public BidirectionalGraph() {\n super();\n }\n\n public BidirectionalGraph(int vertexCapacity, int edgeCapacity) {\n super(vertexCapacity, edgeCapacity);\n }\n\n\n public void createVertexStorage(int vertexCapacity) {\n }\n\n\n public void expandEdgeStorage(int edgeCapacity) {\n }\n\n\n public void initVertexStorage(int vertexCnt) {\n }\n\n }\n\n static class QuickScanner {\n private static final int BUFFER_SIZE = 1024;\n private InputStream stream;\n private byte[] buffer;\n private int currentPosition;\n private int numberOfChars;\n\n public QuickScanner(InputStream stream) {\n this.stream = stream;\n this.buffer = new byte[BUFFER_SIZE];\n this.currentPosition = 0;\n this.numberOfChars = 0;\n }\n\n public int nextInt() {\n int c = nextNonSpaceChar();\n boolean positive = true;\n if (c == '-') {\n positive = false;\n c = nextChar();\n }\n int res = 0;\n do {\n if (c < '0' || '9' < c) throw new RuntimeException();\n res = res * 10 + (c - '0');\n c = nextChar();\n } while (!isSpaceChar(c));\n return positive ? res : -res;\n }\n\n public void nextInts(int n, int[]... res) {\n int m = res.length;\n for (int i = 0; i < n; ++i)\n for (int j = 0; j < m; ++j) {\n res[j][i] = nextInt();\n }\n }\n\n public int nextNonSpaceChar() {\n int res = nextChar();\n for (; isSpaceChar(res) || res < 0; res = nextChar()) ;\n return res;\n }\n\n public int nextChar() {\n if (numberOfChars == -1) {\n throw new RuntimeException();\n }\n if (currentPosition >= numberOfChars) {\n currentPosition = 0;\n try {\n numberOfChars = stream.read(buffer);\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n if (numberOfChars <= 0) {\n return -1;\n }\n }\n return buffer[currentPosition++];\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\t' || isEndOfLineChar(c);\n }\n\n public boolean isEndOfLineChar(int c) {\n return c == '\\n' || c == '\\r' || c < 0;\n }\n\n }\n\n static interface IntCollection {\n int size();\n\n default boolean isEmpty() {\n return size() == 0;\n }\n\n }\n\n static class IntArrayList implements Displayable, IntCollection, Iterable {\n private static final int[] EMPTY = {};\n public int[] values;\n public int size;\n\n public IntArrayList() {\n values = EMPTY;\n clear();\n }\n\n public IntArrayList(int capacity) {\n values = new int[IntUtils.nextPow2(capacity)];\n clear();\n }\n\n public IntArrayList(Collection collection) {\n this(collection.size());\n addAll(collection);\n }\n\n\n public void clear() {\n size = 0;\n }\n\n\n public int size() {\n return size;\n }\n\n\n public void add(int value) {\n ensureCapacity(size + 1);\n addInternal(value);\n }\n\n\n public void addAll(Collection values) {\n ensureCapacity(size + values.size());\n for (int value : values) {\n addInternal(value);\n }\n }\n\n public int get(int idx) {\n if (idx >= size) throw new ArrayIndexOutOfBoundsException();\n return values[idx];\n }\n\n public void sort() {\n IntArrayUtils.sort(values, 0, size);\n }\n\n public void unique() {\n size = IntArrayUtils.unique(values, 0, size);\n }\n\n public void sortAndUnique() {\n sort();\n unique();\n }\n\n public int lowerBound(int value) {\n return IntArrayUtils.lowerBound(values, 0, size, value);\n }\n\n public boolean binarySearch(int value) {\n int idx = lowerBound(value);\n return idx < size && get(idx) == value;\n }\n\n public void ensureCapacity(int capacity) {\n if (capacity <= values.length) return;\n int[] newValues = new int[IntUtils.nextPow2(capacity)];\n for (int i = 0; i < size; ++i) {\n newValues[i] = values[i];\n }\n values = newValues;\n }\n\n\n public Iterator iterator() {\n return new Iterator() {\n private int i = 0;\n\n\n public boolean hasNext() {\n return i < size;\n }\n\n\n public Integer next() {\n return values[i++];\n }\n };\n }\n\n private void addInternal(int value) {\n values[size++] = value;\n }\n\n }\n\n static class IntArrayUtils {\n private static final Random RANDOM = new Random(1000000007);\n\n public static int unique(int[] values, int fromIdx, int toIdx) {\n if (fromIdx == toIdx) return 0;\n int res = 1;\n for (int i = fromIdx + 1; i < toIdx; ++i) {\n if (values[i - 1] != values[i]) {\n values[fromIdx + res++] = values[i];\n }\n }\n return res;\n }\n\n public static void sort(int[] values, int fromIdx, int toIdx) {\n shuffle(values, fromIdx, toIdx);\n Arrays.sort(values, fromIdx, toIdx);\n }\n\n public static int lowerBound(int[] values, int fromIdx, int toIdx, int value) {\n int res = toIdx;\n for (int lower = fromIdx, upper = toIdx - 1; lower <= upper; ) {\n int medium = (lower + upper) >> 1;\n if (value <= values[medium]) {\n res = medium;\n upper = medium - 1;\n } else {\n lower = medium + 1;\n }\n }\n return res;\n }\n\n public static void swap(int[] values, int uIdx, int vIdx) {\n if (uIdx == vIdx) return;\n values[uIdx] ^= values[vIdx];\n values[vIdx] ^= values[uIdx];\n values[uIdx] ^= values[vIdx];\n }\n\n public static void shuffle(int[] values, int fromIdx, int toIdx) {\n for (int i = toIdx - fromIdx - 1; i > 0; --i) {\n swap(values, i + fromIdx, RANDOM.nextInt(i + 1) + fromIdx);\n }\n }\n\n public static int[] expand(int[] values, int newLength) {\n if (values != null && values.length >= newLength) return values;\n int[] res = new int[newLength];\n if (values == null) return res;\n for (int i = 0; i < values.length; ++i) res[i] = values[i];\n return res;\n }\n\n }\n\n static class IntUtils {\n public static boolean isPow2(int n) {\n return n > 0 && (n & (n - 1)) == 0;\n }\n\n public static int nextPow2(int n) {\n if (n < 1) return 1;\n return isPow2(n) ? n : Integer.highestOneBit(n) << 1;\n }\n\n }\n\n static interface DirectedGraphInterface {\n }\n\n static interface Displayable {\n }\n\n static abstract class AbstractDirectedGraph implements DirectedGraphInterface {\n protected int vertexCnt;\n protected int currentEdgeCnt;\n protected int[] fromIdx;\n protected int[] toIdx;\n protected int[] nextIn;\n protected int[] nextOut;\n protected int[] lastIn;\n protected int[] lastOut;\n protected int[] inDegree;\n protected int[] outDegree;\n\n public abstract void createVertexStorage(int vertexCapacity);\n\n public abstract void expandEdgeStorage(int edgeCapacity);\n\n public abstract void initVertexStorage(int vertexCnt);\n\n public AbstractDirectedGraph() {\n }\n\n public AbstractDirectedGraph(int vertexCapacity, int edgeCapacity) {\n this(vertexCapacity, edgeCapacity, true);\n }\n\n public AbstractDirectedGraph(int vertexCapacity, int edgeCapacity, boolean initialize) {\n ensureVertexCapacity(vertexCapacity);\n ensureEdgeCapacity(edgeCapacity);\n if (initialize) init(vertexCapacity);\n }\n\n\n public void init(int vertexCnt) {\n ensureVertexCapacity(vertexCnt);\n this.vertexCnt = vertexCnt;\n currentEdgeCnt = 0;\n Arrays.fill(inDegree, 0, vertexCnt, 0);\n Arrays.fill(outDegree, 0, vertexCnt, 0);\n Arrays.fill(lastIn, 0, vertexCnt, -1);\n Arrays.fill(lastOut, 0, vertexCnt, -1);\n initVertexStorage(vertexCnt);\n }\n\n\n public void add(int fromIdx, int toIdx) {\n ensureEdgeCapacity(currentEdgeCnt + 1);\n this.fromIdx[currentEdgeCnt] = fromIdx;\n this.toIdx[currentEdgeCnt] = toIdx;\n ++outDegree[fromIdx];\n ++inDegree[toIdx];\n nextOut[currentEdgeCnt] = lastOut[fromIdx];\n lastOut[fromIdx] = currentEdgeCnt;\n nextIn[currentEdgeCnt] = lastIn[toIdx];\n lastIn[toIdx] = currentEdgeCnt;\n ++currentEdgeCnt;\n }\n\n\n public int nextOut(int edgeIdx) {\n return nextOut[edgeIdx];\n }\n\n\n public Iterable outNodes(int nodeIdx) {\n return () -> new Iterator() {\n private int edgeIdx = lastOut[nodeIdx];\n\n\n public boolean hasNext() {\n return edgeIdx >= 0;\n }\n\n\n public Integer next() {\n int res = toIdx[edgeIdx];\n edgeIdx = nextOut(edgeIdx);\n return res;\n }\n };\n }\n\n private void ensureVertexCapacity(int vertexCapacity) {\n if (lastIn != null && lastIn.length >= vertexCapacity) return;\n int capacity = IntUtils.nextPow2(vertexCapacity);\n lastIn = new int[capacity];\n lastOut = new int[capacity];\n inDegree = new int[capacity];\n outDegree = new int[capacity];\n createVertexStorage(capacity);\n }\n\n private void ensureEdgeCapacity(int edgeCapacity) {\n if (fromIdx != null && fromIdx.length >= edgeCapacity) return;\n int capacity = IntUtils.nextPow2(edgeCapacity);\n fromIdx = IntArrayUtils.expand(fromIdx, capacity);\n toIdx = IntArrayUtils.expand(toIdx, capacity);\n nextIn = IntArrayUtils.expand(nextIn, capacity);\n nextOut = IntArrayUtils.expand(nextOut, capacity);\n expandEdgeStorage(capacity);\n }\n\n }\n\n static interface BidirectionalGraphInterface extends DirectedGraphInterface {\n }\n\n static class IntModular {\n private static final int MOD = 1000000007;\n public final int mod;\n private final int[] x;\n\n public IntModular() {\n this(MOD);\n }\n\n public IntModular(int mod) {\n this.mod = mod;\n this.x = new int[2];\n }\n\n public int add(int a, int b) {\n return fix(a + b);\n }\n\n public int fix(int a) {\n a = slightFix(a);\n return 0 <= a && a < mod ? a : slightFix(a % mod);\n }\n\n public int mul(int a, int b) {\n return a > 0\n ? (b < mod / a ? a * b : (int) ((long) a * b % mod))\n : 0;\n }\n\n private int slightFix(int a) {\n return a >= mod\n ? a - mod\n : a < 0 ? a + mod : a;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c99d2ef3b969c3106dcd6aef1000bf34", "src_uid": "250314325e3d088ceedaba7dcde762f1", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * @author Don Li\n */\npublic class TheOverdosingUbiquity {\n \n int N = 200;\n int MOD = (int) 1e9 + 7;\n \n Map map = new HashMap<>();\n \n int[] num = new int[N];\n List[] G = new List[N];\n \n int tot = 0;\n boolean[] vis = new boolean[N];\n \n void solve() {\n int n = in.nextInt(), m = in.nextInt();\n int[] fr = new int[m], to = new int[m];\n for (int i = 0; i < m; i++) {\n fr[i] = in.nextInt();\n to[i] = in.nextInt();\n }\n \n int d = 0;\n while ((1 << d) <= n) d++;\n \n getId(1);\n for (int i = 0; i < m; i++) {\n int u = fr[i];\n while (u > 0) {\n getId(u);\n u >>= 1;\n }\n u = to[i];\n while (u > 0) {\n getId(u);\n u >>= 1;\n }\n }\n \n for (int i = 0; i < N; i++) G[i] = new ArrayList<>();\n for (int u : map.keySet()) {\n int id = map.get(u);\n if (u > 1) {\n addEdge(getId(u), getId(u >> 1));\n }\n num[id] = calcSize(u, n, d);\n }\n \n dfs(0, -1);\n \n for (int i = 0; i < m; i++) {\n addEdge(getId(fr[i]), getId(to[i]));\n }\n \n int res = 0;\n for (int i = 0; i < map.size(); i++) {\n tot = 0;\n dfs(i);\n res = (int) ((res + (long) tot * num[i] % MOD) % MOD);\n }\n out.println(res);\n }\n \n int getId(int x) {\n if (!map.containsKey(x)) map.put(x, map.size());\n return map.get(x);\n }\n \n void addEdge(int u, int v) {\n G[u].add(v);\n G[v].add(u);\n }\n \n int calcSize(int u, int n, int d) {\n int t = u, c = 0;\n while (t > 0) {\n c++;\n t >>= 1;\n }\n int sz = (1 << (d - c + 1)) - 1;\n t = c;\n while (t < d) {\n t++;\n u = u << 1 | 1;\n }\n return sz - Math.max(0, Math.min(u - n, 1 << (d - c))); \n }\n \n void dfs(int u, int p) {\n for (int v : G[u]) {\n if (v != p) {\n num[u] -= num[v];\n dfs(v, u);\n }\n }\n }\n \n void dfs(int u) {\n tot = (tot + num[u]) % MOD;\n vis[u] = true;\n for (int v : G[u]) {\n if (!vis[v]) dfs(v);\n }\n vis[u] = false;\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 TheOverdosingUbiquity().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9bcdff28c0383faa0264e99a45d7d116", "src_uid": "250314325e3d088ceedaba7dcde762f1", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.Collection;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Jialin Ouyang (Jialin.Ouyang@gmail.com)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n QuickScanner in = new QuickScanner(inputStream);\n QuickWriter out = new QuickWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n static final IntModular MOD = new IntModular();\n int n;\n int m;\n int[] end1;\n int[] end2;\n IntArrayList points;\n IntArrayList counts;\n IntArrayList covered;\n IntArrayList newCovered;\n\n public void solve(int testNumber, QuickScanner in, QuickWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n end1 = new int[m];\n end2 = new int[m];\n in.nextInts(m, end1, end2);\n initKeyPoints();\n//System.out.printf(\"points:%s\\n\", points.toDisplay());\n//System.out.printf(\"points:%s\\n\", counts.toDisplay());\n int res = MOD.mul(n, n);\n IntArrayList edgeIdxs = new IntArrayList(m);\n for (int mask = (1 << m) - 1; mask > 0; --mask) {\n edgeIdxs.clear();\n for (int i = 0; i < m; ++i)\n if ((mask & (1 << i)) > 0) {\n edgeIdxs.add(i);\n }\n res = MOD.add(res, calcUnordered(edgeIdxs));\n }\n out.println(res);\n }\n\n void initKeyPoints() {\n points = new IntArrayList();\n for (int i = 0; i < m; ++i) {\n addKeyPoints(end1[i]);\n addKeyPoints(end2[i]);\n }\n points.sortAndUnique();\n counts = new IntArrayList(points.size);\n for (int point : points) {\n int cnt = 1;\n if (!points.binarySearch(point << 1)) {\n cnt += calcSubtree(point << 1);\n }\n if (!points.binarySearch((point << 1) | 1)) {\n cnt += calcSubtree((point << 1) | 1);\n }\n counts.add(cnt);\n }\n }\n\n int calcSubtree(int x) {\n int lower = x, upper = x;\n int res = 0;\n for (; lower <= n; lower <<= 1, upper = (upper << 1) | 1) {\n res += Math.min(n, upper) - lower + 1;\n if (n <= upper) break;\n }\n return res;\n }\n\n void addKeyPoints(int x) {\n for (; x > 0; x >>= 1) points.add(x);\n }\n\n int calcUnordered(IntArrayList edgeIdxs) {\n int res = 0;\n for (int mask = (1 << edgeIdxs.size) - 1; mask >= 0; --mask) {\n res = MOD.add(res, calcOrdered(edgeIdxs, mask));\n }\n return res;\n }\n\n int calcOrdered(IntArrayList edgeIdxs, int orderMask) {\n if (covered == null) {\n covered = new IntArrayList();\n }\n covered.clear();\n int source = -1, sink = -1;\n for (int i = 0; i < edgeIdxs.size; ++i) {\n int from, to;\n if ((orderMask & (1 << i)) > 0) {\n from = end1[edgeIdxs.get(i)];\n to = end2[edgeIdxs.get(i)];\n } else {\n from = end2[edgeIdxs.get(i)];\n to = end1[edgeIdxs.get(i)];\n }\n//System.out.printf(\"(%d->%d) \", from, to);\n if (source < 0) {\n source = from;\n covered.add(source);\n }\n if (i > 0) addPath(sink, from);\n sink = to;\n }\n//System.out.println();\n covered.add(sink);\n int coveredSize = covered.size;\n//System.out.printf(\"\\tcovered:%s\\n\", covered.toDisplay());\n covered.sortAndUnique();\n//System.out.printf(\"\\tcovered:%s\\n\", covered.toDisplay());\n//if (coveredSize != covered.size) System.out.printf(\"\\tno %d %d\\n\", coveredSize, covered.size);\n if (coveredSize != covered.size) return 0;\n int res = 0;\n for (int i = 0; i < points.size; ++i) {\n int u = points.get(i);\n for (int j = 0; j < points.size; ++j) {\n int v = points.get(j);\n//if (u != v) System.out.printf(\"\\t(%d,%d)->(%d,%d):%b\\n\", u, source, v, sink, isValid(u, source, v, sink));\n if (u == v || !isValid(u, source, v, sink)) continue;\n res = MOD.add(res, MOD.mul(counts.get(i), counts.get(j)));\n }\n }\n return res;\n }\n\n void addPath(int x, int y) {\n while (x != y) {\n if (x < y) {\n covered.add(y);\n y >>= 1;\n } else {\n covered.add(x);\n x >>= 1;\n }\n }\n covered.add(x);\n }\n\n boolean isValid(int source0, int sink0, int source1, int sink1) {\n if (newCovered == null) {\n newCovered = new IntArrayList();\n }\n newCovered.clear();\n//System.out.printf(\"\\t\\t(%d,%d)->(%d,%d)\\n\", source0, sink0, source1, sink1);\n//System.out.println(\"\\t\\tstep1\");\n if (!addPathWithCheck(source0, sink0)) return false;\n//System.out.println(\"\\t\\tstep2\");\n if (!addPathWithCheck(source1, sink1)) return false;\n//System.out.printf(\"\\t\\tstep3 %s\\n\", newCovered.toDisplay());\n int size = newCovered.size;\n newCovered.sortAndUnique();\n return size == newCovered.size;\n }\n\n boolean addPathWithCheck(int x, int y) {\n int sink = y;\n while (x != y) {\n if (x < y) {\n if (sink != y) {\n if (covered.binarySearch(y)) return false;\n newCovered.add(y);\n }\n y >>= 1;\n } else {\n if (covered.binarySearch(x)) return false;\n newCovered.add(x);\n x >>= 1;\n }\n }\n if (sink != x) {\n if (covered.binarySearch(x)) return false;\n newCovered.add(x);\n }\n return true;\n }\n\n }\n\n static class QuickWriter {\n private final PrintWriter writer;\n\n public QuickWriter(OutputStream outputStream) {\n this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public QuickWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; ++i) {\n if (i > 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void println(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n }\n\n static class QuickScanner {\n private static final int BUFFER_SIZE = 1024;\n private InputStream stream;\n private byte[] buffer;\n private int currentPosition;\n private int numberOfChars;\n\n public QuickScanner(InputStream stream) {\n this.stream = stream;\n this.buffer = new byte[BUFFER_SIZE];\n this.currentPosition = 0;\n this.numberOfChars = 0;\n }\n\n public int nextInt() {\n int c = nextNonSpaceChar();\n boolean positive = true;\n if (c == '-') {\n positive = false;\n c = nextChar();\n }\n int res = 0;\n do {\n if (c < '0' || '9' < c) throw new RuntimeException();\n res = res * 10 + (c - '0');\n c = nextChar();\n } while (!isSpaceChar(c));\n return positive ? res : -res;\n }\n\n public void nextInts(int n, int[]... res) {\n int m = res.length;\n for (int i = 0; i < n; ++i)\n for (int j = 0; j < m; ++j) {\n res[j][i] = nextInt();\n }\n }\n\n public int nextNonSpaceChar() {\n int res = nextChar();\n for (; isSpaceChar(res) || res < 0; res = nextChar()) ;\n return res;\n }\n\n public int nextChar() {\n if (numberOfChars == -1) {\n throw new RuntimeException();\n }\n if (currentPosition >= numberOfChars) {\n currentPosition = 0;\n try {\n numberOfChars = stream.read(buffer);\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n if (numberOfChars <= 0) {\n return -1;\n }\n }\n return buffer[currentPosition++];\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\t' || isEndOfLineChar(c);\n }\n\n public boolean isEndOfLineChar(int c) {\n return c == '\\n' || c == '\\r' || c < 0;\n }\n\n }\n\n static interface IntCollection {\n }\n\n static class IntArrayList implements Displayable, IntCollection, Iterable {\n private static final int[] EMPTY = {};\n public int[] values;\n public int size;\n\n public IntArrayList() {\n values = EMPTY;\n clear();\n }\n\n public IntArrayList(int capacity) {\n values = new int[IntUtils.nextPow2(capacity)];\n clear();\n }\n\n public IntArrayList(Collection collection) {\n this(collection.size());\n addAll(collection);\n }\n\n\n public void clear() {\n size = 0;\n }\n\n\n public void add(int value) {\n ensureCapacity(size + 1);\n addInternal(value);\n }\n\n\n public void addAll(Collection values) {\n ensureCapacity(size + values.size());\n for (int value : values) {\n addInternal(value);\n }\n }\n\n public int get(int idx) {\n if (idx >= size) throw new ArrayIndexOutOfBoundsException();\n return values[idx];\n }\n\n public void sort() {\n IntArrayUtils.sort(values, 0, size);\n }\n\n public void unique() {\n size = IntArrayUtils.unique(values, 0, size);\n }\n\n public void sortAndUnique() {\n sort();\n unique();\n }\n\n public int lowerBound(int value) {\n return IntArrayUtils.lowerBound(values, 0, size, value);\n }\n\n public boolean binarySearch(int value) {\n int idx = lowerBound(value);\n return idx < size && get(idx) == value;\n }\n\n public void ensureCapacity(int capacity) {\n if (capacity <= values.length) return;\n int[] newValues = new int[IntUtils.nextPow2(capacity)];\n for (int i = 0; i < size; ++i) {\n newValues[i] = values[i];\n }\n values = newValues;\n }\n\n\n public Iterator iterator() {\n return new Iterator() {\n private int i = 0;\n\n\n public boolean hasNext() {\n return i < size;\n }\n\n\n public Integer next() {\n return values[i++];\n }\n };\n }\n\n private void addInternal(int value) {\n values[size++] = value;\n }\n\n }\n\n static class IntArrayUtils {\n private static final Random RANDOM = new Random(1000000007);\n\n public static int unique(int[] values, int fromIdx, int toIdx) {\n if (fromIdx == toIdx) return 0;\n int res = 1;\n for (int i = fromIdx + 1; i < toIdx; ++i) {\n if (values[i - 1] != values[i]) {\n values[fromIdx + res++] = values[i];\n }\n }\n return res;\n }\n\n public static void sort(int[] values, int fromIdx, int toIdx) {\n shuffle(values, fromIdx, toIdx);\n Arrays.sort(values, fromIdx, toIdx);\n }\n\n public static int lowerBound(int[] values, int fromIdx, int toIdx, int value) {\n int res = toIdx;\n for (int lower = fromIdx, upper = toIdx - 1; lower <= upper; ) {\n int medium = (lower + upper) >> 1;\n if (value <= values[medium]) {\n res = medium;\n upper = medium - 1;\n } else {\n lower = medium + 1;\n }\n }\n return res;\n }\n\n public static void swap(int[] values, int uIdx, int vIdx) {\n if (uIdx == vIdx) return;\n values[uIdx] ^= values[vIdx];\n values[vIdx] ^= values[uIdx];\n values[uIdx] ^= values[vIdx];\n }\n\n public static void shuffle(int[] values, int fromIdx, int toIdx) {\n for (int i = toIdx - fromIdx - 1; i > 0; --i) {\n swap(values, i + fromIdx, RANDOM.nextInt(i + 1) + fromIdx);\n }\n }\n\n }\n\n static class IntUtils {\n public static boolean isPow2(int n) {\n return n > 0 && (n & (n - 1)) == 0;\n }\n\n public static int nextPow2(int n) {\n if (n < 1) return 1;\n return isPow2(n) ? n : Integer.highestOneBit(n) << 1;\n }\n\n }\n\n static interface Displayable {\n }\n\n static class IntModular {\n private static final int MOD = 1000000007;\n public final int mod;\n private final int[] x;\n\n public IntModular() {\n this(MOD);\n }\n\n public IntModular(int mod) {\n this.mod = mod;\n this.x = new int[2];\n }\n\n public int add(int a, int b) {\n return fix(a + b);\n }\n\n public int fix(int a) {\n a = slightFix(a);\n return 0 <= a && a < mod ? a : slightFix(a % mod);\n }\n\n public int mul(int a, int b) {\n return a > 0\n ? (b < mod / a ? a * b : (int) ((long) a * b % mod))\n : 0;\n }\n\n private int slightFix(int a) {\n return a >= mod\n ? a - mod\n : a < 0 ? a + mod : a;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ef96e89c0a19cf49b75ffa20b8de6f0", "src_uid": "250314325e3d088ceedaba7dcde762f1", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class MainD {\n\tstatic final StdIn in = new StdIn();\n\tstatic final PrintWriter out = new PrintWriter(System.out);\n\tstatic final long M=(long)1e9+7;\n\tstatic int n=in.nextInt(), m=in.nextInt();\n\tstatic Map graph = new HashMap();\n\t\n\tpublic static void main(String[] args) {\n\t\taddNode(1);\n\t\tfor(int i=0; i nodeEntry : graph.entrySet()) {\n\t\t\tNode u=nodeEntry.getValue();\n\t\t\tfor(int i=u.adj.size()-1; i>=0; --i) {\n\t\t\t\tif(!graph.containsKey(u.adj.get(i))) {\n\t\t\t\t\tu.s+=sts(u.adj.get(i));\n\t\t\t\t\tu.adj.remove(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=0;\n\t\tfor(Map.Entry nodeEntry : graph.entrySet())\n\t\t\tans=(dfs(nodeEntry.getKey(), 0)+ans)%M;\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tstatic Node addNode(int u) {\n\t\tif(u<=0)\n\t\t\treturn null;\n\t\tNode node = graph.get(u);\n\t\tif(node!=null)\n\t\t\treturn node;\n\t\tnode = new Node();\n\t\tif(u>1)\n\t\t\tnode.adj.add(u/2);\n\t\tif(u*2<=n)\n\t\t\tnode.adj.add(u*2);\n\t\tif(u*2+1<=n)\n\t\t\tnode.adj.add(u*2+1);\n\t\tgraph.put(u, node);\n\t\taddNode(u/2);\n\t\treturn node;\n\t}\n\t\n\tstatic long sts(int u) {\n\t\tlong res=0;\n\t\tint l=u, r=u;\n\t\twhile(r<=n) {\n\t\t\tres+=r-l+1;\n\t\t\tl=2*l;\n\t\t\tr=2*r+1;\n\t\t}\n\t\treturn (res+Math.min(r, n)-Math.min(l, n))%M;\n\t}\n\t\n\tstatic long dfs(int u, long ps) {\n\t\tNode node=graph.get(u);\n\t\tif(ps==0)\n\t\t\tps=node.s;\n\t\tnode.active=true;\n\t\tlong res=ps*node.s;\n\t\tfor(int v : node.adj)\n\t\t\tif(!graph.get(v).active)\n\t\t\t\tres+=dfs(v, ps);\n\t\tnode.active=false;\n\t\treturn res;\n\t}\n\t\n\tstatic class Node {\n\t\tList adj = new ArrayList();\n\t\tlong s=1;\n\t\tboolean active;\n\t}\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\t\tpublic StdIn() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\twhile ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e0fd969c8b826eb9d35637556886c59b", "src_uid": "250314325e3d088ceedaba7dcde762f1", "difficulty": 2800.0} {"lang": "Java 8", "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<= '0' && s[pos] <= '9'){\n\t\t\tlong vx2 = vx + vx;\n\t\t\tif(vx2 >= modx)vx2 -= modx;\n\t\t\tvx = vx2 * 5 + (s[pos]-'0');\n\t\t\twhile(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\ta.v = (a.v * pow(10, b.len, mod) + b.v)% mod;\n\t\ta.len += b.len;\n\t\tif(a.len >= emod)a.len -= emod;\n\t\treturn a;\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\tfor(long i = a.len;i <= b.len;i++){\n\t\t\tlong inf = i == a.len ? a.v : pow(10, i-1, mod);\n//\t\t\tlong sup = i == b.len ? b.v : pow(10, i, mod)-1;\n\t\t\tlong infe = i == a.len ? a.vx : powSafe(10, i-1, modx);\n\t\t\tlong supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;\n//\t\t\tif(sup < 0)sup += mod;\n\t\t\tif(supe < 0)supe += modx;\n\t\t\t\n\t\t\tlong nume = supe-infe+1;\n\t\t\tif(nume < 0)nume += modx;\n\t\t\tlong base = inf*sumGP(t, nume, mod)%mod;\n\t\t\t// 0 1 ... sup-inf\n\t\t\t\n\t\t\tnume %= 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(nume<<~d<0){\n//\t\t\t\t\tres1 = (res1 * B + s1 + s0*((nume&(1L<= mod)q -= mod;\n\t\t\t\t}\n//\t\t\t\ts1 = (s1 * (B+1) + (s0<= 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d7ace50a51f7166121425fb95aea6de", "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c", "difficulty": 3400.0} {"lang": "Java 8", "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 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<= '0' && s[pos] <= '9'){\n\t\t\tlong vx2 = vx + vx;\n\t\t\tif(vx2 >= modx)vx2 -= modx;\n\t\t\tvx = vx2 * 5 + (s[pos]-'0');\n\t\t\twhile(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 number()\n//\t{\n//\t\tlong v = 0;\n//\t\tlong vx = 0;\n//\t\tint nlen = 0;\n//\t\twhile(pos < len && s[pos] >= '0' && s[pos] <= '9'){\n//\t\t\tv = v * 10 + (s[pos]-'0');\n//\t\t\tv %= mod;\n//\t\t\tvx = mulEx(vx, 10, modx) + (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(v, 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\tfor(long i = a.len;i <= b.len;i++){\n\t\t\tlong inf = i == a.len ? a.v : pow(10, i-1, mod);\n//\t\t\tlong sup = i == b.len ? b.v : pow(10, i, mod)-1;\n\t\t\tlong infe = i == a.len ? a.vx : powSafe(10, i-1, modx);\n\t\t\tlong supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;\n//\t\t\tif(sup < 0)sup += mod;\n\t\t\tif(supe < 0)supe += modx;\n\t\t\t\n\t\t\tlong nume = supe-infe+1;\n\t\t\tif(nume < 0)nume += modx;\n\t\t\tlong base = inf*sumGP(t, nume, mod)%mod;\n\t\t\t// 0 1 ... sup-inf\n\t\t\t\n\t\t\tnume %= 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\tfor(int d = 0;d < 63;d++){\n\t\t\t\tif(nume<<~d<0){\n\t\t\t\t\tres1 = (res1 * B + s1 + s0*((nume&(1L<= 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "214b314343e6b989937a6c2e1a5aba15", "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c", "difficulty": 3400.0} {"lang": "Java 8", "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 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<= '0' && s[pos] <= '9'){\n\t\t\tv = v * 10 + (s[pos]-'0');\n\t\t\tv %= mod;\n\t\t\tvx = mulEx(vx, 10, modx) + (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(v, 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\tfor(long i = a.len;i <= b.len;i++){\n\t\t\tlong inf = i == a.len ? a.v : pow(10, i-1, mod);\n\t\t\tlong sup = i == b.len ? b.v : pow(10, i, mod)-1;\n\t\t\tlong infe = i == a.len ? a.vx : powSafe(10, i-1, modx);\n\t\t\tlong supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;\n\t\t\tif(sup < 0)sup += mod;\n\t\t\tif(supe < 0)supe += modx;\n\t\t\t\n\t\t\tlong nume = supe-infe+1;\n\t\t\tif(nume < 0)nume += modx;\n\t\t\tlong base = inf*sumGP(pow(10, i, mod), nume, mod)%mod;\n\t\t\t// 0 1 ... sup-inf\n\t\t\t\n\t\t\tnume %= modx;\n\t\t\tlong mul = pow(10, i, mod);\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\tfor(int d = 0;d < 63;d++){\n\t\t\t\tif(nume<<~d<0){\n\t\t\t\t\tres1 = (res1 * B + s1 + s0*((nume&(1L<= 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a682f8257ec1431af53a76bb5ca7ae7", "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c", "difficulty": 3400.0} {"lang": "Java 8", "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 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<= '0' && s[pos] <= '9'){\n\t\t\tlong vx2 = vx + vx;\n\t\t\tif(vx2 >= modx)vx2 -= modx;\n\t\t\tvx = vx2 * 5 + (s[pos]-'0');\n\t\t\twhile(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\ta.v = (a.v * pow(10, b.len, mod) + b.v)% mod;\n\t\ta.len += b.len;\n\t\tif(a.len >= emod)a.len -= emod;\n\t\treturn a;\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\tfor(long i = a.len;i <= b.len;i++){\n\t\t\tlong inf = i == a.len ? a.v : pow(10, i-1, mod);\n//\t\t\tlong sup = i == b.len ? b.v : pow(10, i, mod)-1;\n\t\t\tlong infe = i == a.len ? a.vx : powSafe(10, i-1, modx);\n\t\t\tlong supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;\n//\t\t\tif(sup < 0)sup += mod;\n\t\t\tif(supe < 0)supe += modx;\n\t\t\t\n\t\t\tlong nume = supe-infe+1;\n\t\t\tif(nume < 0)nume += modx;\n\t\t\tlong base = inf*sumGP(t, nume, mod)%mod;\n\t\t\t// 0 1 ... sup-inf\n\t\t\t\n\t\t\tnume %= 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\tfor(int d = 0;d < 63;d++){\n\t\t\t\tif(nume<<~d<0){\n\t\t\t\t\tres1 = (res1 * B + s1 + s0*((nume&(1L<= 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b90f7030fb6345e4ef8dd171cae8a4c3", "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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[i] = true;\n }\n }\n int ans = 0;\n for (int i = 0; i < n; i++) if (!rep[i]) ans++;\n w.println(ans);\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3b110e7a6c30c4b000d25381c412e313", "src_uid": "11ad68b4375456733526e74e72606d8d", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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[i] = true;\n }\n }\n int ans = 0;\n for (int i = 0; i < n; i++) if (!rep[i]) ans++;\n w.println(ans);\n }\n\n boolean query(int i, FastReader s, PrintWriter w) {\n w.println(\"? \" + ++i);\n w.flush();\n return s.nextChar() == 'N';\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ebdd48e4f383019ba862c2acce54712", "src_uid": "11ad68b4375456733526e74e72606d8d", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\nimport static java.lang.Math.*;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Coupon Kaka\n */\n/*\n \"Digits 1-9 in unit place is a myth, actual counting always has digit 0 in the unit place.\" - Coupon Kaka\n*/\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n FCoffeeVarietiesEasyVersion solver = new FCoffeeVarietiesEasyVersion();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FCoffeeVarietiesEasyVersion {\n boolean isNew(int ind, InputReader sc) {\n System.out.println(\"? \" + (ind + 1));\n System.out.flush();\n char ans = sc.next().charAt(0);\n if (ans == 'Y')\n return false;\n return true;\n }\n\n void reset() {\n System.out.println(\"R\");\n System.out.flush();\n }\n\n public void solve(int testNumber, InputReader sc, PrintWriter out) {\n int n = sc.nextInt();\n int k = sc.nextInt();\n\n int flag[] = new int[n];\n ArrayList list = new ArrayList<>();\n for (int i = 0; i < k; ++i) {\n if (isNew(i, sc)) {\n flag[i] = 0;\n list.add(i);\n } else\n flag[i] = 1;\n }\n\n for (int i = k; i < n; i += (k + 1) / 2) {\n int l = i;\n int r = min(n - 1, i + ((k + 1) / 2) - 1);\n\n for (int j = 0; j < list.size(); j += (k + 1) / 2) {\n reset();\n for (int p = j; p < min(list.size(), j + ((k + 1) / 2)); ++p)\n isNew(list.get(p), sc);\n for (int p = l; p <= r; ++p) {\n if (!isNew(p, sc))\n flag[p] = 1;\n }\n }\n\n for (int j = l; j <= r; ++j) {\n if (flag[j] == 0)\n list.add(j);\n }\n }\n\n System.out.println(\"! \" + list.size());\n System.out.flush();\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n\n while (isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "59f166a362ba672acc0d85d5b889c4c7", "src_uid": "11ad68b4375456733526e74e72606d8d", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9744cd6fede8f79359ccef13dca9d3fe", "src_uid": "11ad68b4375456733526e74e72606d8d", "difficulty": 2800.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1387a_2 {\n\n static int[] par;\n static boolean[] set;\n\n static int find(int i) {\n return i == par[i] ? i : (par[i] = find(par[i]));\n }\n\n static void union(int i, int j) {\n int a = find(i), b = find(j);\n if (a != b) {\n par[b] = a;\n set[a] |= set[b];\n }\n }\n\n public static void main(String[] args) throws IOException {\n int n = rni(), m = ni();\n par = new int[n];\n set = new boolean[n];\n for (int i = 0; i < n; ++i) {\n par[i] = i;\n }\n List> g = new ArrayList<>();\n double[] a = new double[n], b = new double[n];\n fill(a, -2);\n for (int i = 0; i < n; ++i) {\n g.add(new HashMap<>());\n }\n boolean invalid = false;\n for (int i = 0; i < m; ++i) {\n int aa = rni() - 1, bb = ni() - 1, c = ni();\n if (g.get(aa).containsKey(bb) && g.get(aa).get(bb) != c) {\n invalid = true;\n }\n union(aa, bb);\n g.get(aa).put(bb, c);\n g.get(bb).put(aa, c);\n if (aa == bb) {\n a[aa] = 0;\n b[aa] = (double) c / 2;\n set[find(aa)] = true;\n }\n }\n if (invalid) {\n prN();\n close();\n return;\n }\n List> comps = new ArrayList<>();\n int ind = 0, map[] = new int[n];\n for (int i = 0; i < n; ++i) {\n if (i == par[i]) {\n map[i] = ind++;\n comps.add(new ArrayList<>());\n }\n }\n for (int i = 0; i < n; ++i) {\n comps.get(map[find(i)]).add(i);\n }\n boolean[] vis = new boolean[n];\n for (int i = 0; i < ind; ++i) {\n if (set[find(comps.get(i).get(0))]) {\n for (int j = 0, end = comps.get(i).size(); j < end; ++j) {\n if (a[comps.get(i).get(j)] == 0) {\n a[comps.get(i).get(j)] = 1;\n if (!dfs(g, comps.get(i).get(j), a, b, vis, comps, map)) {\n prN();\n close();\n return;\n }\n break;\n }\n }\n } else {\n a[comps.get(i).get(0)] = 1;\n if (!dfs(g, comps.get(i).get(0), a, b, vis, comps, map)) {\n prN();\n close();\n return;\n }\n if (a[comps.get(i).get(0)] != 0) {\n // minimize\n // h();\n List median = new ArrayList<>();\n for (int j = 0, end = comps.get(i).size(); j < end; ++j) {\n median.add(-a[comps.get(i).get(j)] * b[comps.get(i).get(j)]);\n }\n median.sort(Double::compareTo);\n double x = median.size() % 2 == 0 ? (median.get(median.size() / 2 - 1) + median.get(median.size() / 2)) / 2 : median.get(median.size() / 2);\n // prln(a);\n // prln(b);\n // prln(x);\n for (int j = 0, end = comps.get(i).size(); j < end; ++j) {\n b[comps.get(i).get(j)] += a[comps.get(i).get(j)] * x;\n }\n }\n }\n }\n prY();\n prln(b);\n close();\n }\n\n static boolean dfs(List> g, int i, double[] a, double[] b, boolean[] vis, List> comps, int[] map) {\n // prln(i, a[i], b[i]);\n vis[i] = true;\n for (int k : g.get(i).keySet()) {\n double a_prime = -a[i], b_prime = g.get(i).get(k) - b[i];\n // pr(\"\\t\");\n // prln(i, k, b_prime);\n if (vis[k]) {\n if (abs(a_prime - a[k]) < 1e-6) {\n if (abs(b_prime - b[k]) > 1e-6) {\n return false;\n }\n } else {\n // h();\n double x = (b[k] - b_prime) / (a_prime - a[k]);\n for (int j : comps.get(map[find(i)])) {\n if (vis[j]) {\n b[j] += a[j] * x;\n a[j] = 0;\n }\n }\n }\n } else {\n a[k] = a_prime;\n b[k] = b_prime;\n if (!dfs(g, k, a, b, vis, comps, map)) {\n return false;\n }\n }\n }\n return true;\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 mix(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(double[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {double 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 shuffle(double[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void rsort(int[] a) {shuffle(a); sort(a);}\n static void rsort(long[] a) {shuffle(a); sort(a);}\n static void rsort(double[] 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 double[] copy(double[] a) {double[] ans = new double[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> g(int n) {List> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n static List> sg(int n) {List> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n static void c(List> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n static void cto(List> g, int u, int v) {g.get(u).add(v);}\n static void dc(List> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n static void dcto(List> g, int u, int v) {g.get(u).remove(v);}\n // input\n static void r() throws IOException {input = new StringTokenizer(rline());}\n static int ri() throws IOException {return Integer.parseInt(rline());}\n static long rl() throws IOException {return Long.parseLong(rline());}\n static double rd() throws IOException {return Double.parseDouble(rline());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni(); return a;}\n static int[] riam1(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1; return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; r(); for (int i = 0; i < n; ++i) a[i] = nl(); return a;}\n static double[] rda(int n) throws IOException {double[] a = new double[n]; r(); for (int i = 0; i < n; ++i) a[i] = nd(); return a;}\n static char[] rcha() throws IOException {return rline().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static String n() {return input.nextToken();}\n static int rni() throws IOException {r(); return ni();}\n static int ni() {return Integer.parseInt(n());}\n static long rnl() throws IOException {r(); return nl();}\n static long nl() {return Long.parseLong(n());}\n static double rnd() throws IOException {r(); return nd();}\n static double nd() {return Double.parseDouble(n());}\n static List> rg(int n, int m) throws IOException {List> g = g(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n static void rg(List> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n static List> rdg(int n, int m) throws IOException {List> g = g(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n static void rdg(List> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n static List> rsg(int n, int m) throws IOException {List> g = sg(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n static void rsg(List> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n static List> rdsg(int n, int m) throws IOException {List> g = sg(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n static void rdsg(List> 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() {prln(\"yes\");}\n static void pry() {prln(\"Yes\");}\n static void prY() {prln(\"YES\");}\n static void prno() {prln(\"no\");}\n static void prn() {prln(\"No\");}\n static void prN() {prln(\"NO\");}\n static void pryesno(boolean b) {prln(b ? \"yes\" : \"no\");};\n static void pryn(boolean b) {prln(b ? \"Yes\" : \"No\");}\n static void prYN(boolean b) {prln(b ? \"YES\" : \"NO\");}\n static void prln(int... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();}\n static void prln(long... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();}\n static void prln(double... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();}\n static void prln(Collection c) {int n = c.size() - 1; Iterator iter = c.iterator(); for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i); if (n >= 0) prln(iter.next()); else prln();}\n static void h() {prln(\"hlfd\"); flush();}\n static void flush() {__out.flush();}\n static void close() {__out.close();}}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6731211482d858211439d343b94fb543", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*; import java.util.*;\npublic class Graph {\n \n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st=new StringTokenizer(br.readLine());\n int N=Integer.parseInt(st.nextToken());\n int M=Integer.parseInt(st.nextToken());\n ArrayList arl[]=new ArrayList[N];\n for (int i = 0; i < N; i++) {\n arl[i]=new ArrayList<>();\n }\n int a,b,vv;\n for (int i = 0; i < M; i++) {\n st=new StringTokenizer(br.readLine());\n a=Integer.parseInt(st.nextToken())-1;\n b=Integer.parseInt(st.nextToken())-1;\n vv=Integer.parseInt(st.nextToken());\n arl[a].add(4*b+2*vv); arl[b].add(4*a+2*vv);\n }\n \n boolean[] vis=new boolean[N];\n \n int[] m=new int[N];\n int[] c=new int[N];\n int done=0; int pt=0;\n while(done qu=new LinkedList<>();\n qu.add(pt); vis[pt]=true; done++;\n Queue qu2=new LinkedList<>();//Tracks all vertices in the queue\n qu2.add(pt); boolean fix=false;\n int x,y;\n while(!qu.isEmpty()){\n int v=qu.poll(); \n for (int p : arl[v]) {\n x=4-p%4; y=(p-x)/4;\n if(!vis[y]){\n vis[y]=true; qu.add(y); \n if(!fix){\n qu2.add(y);\n }\n m[y]=-m[v]; c[y]=x-c[v]; done++;\n }else{\n //System.out.println(x+\" \"+y+\" \"+v);\n if(m[y]==m[v] && m[v]!=0){\n //m[p.vtx]x+c[p.vtx]+m[v]x+c[v] is known\n int xx=(x-c[y]-c[v])/(2*m[y]); fix=true;\n \n for(int vtx: qu2){\n \n c[vtx]+=m[vtx]*xx; m[vtx]=0;\n }\n }else if(m[y]+m[v]==0){//m[v]=0\n if(c[y]+c[v]!=x){\n System.out.println(\"NO\"); return;\n }\n }\n }\n }\n //System.out.println(Arrays.toString(m));\n //System.out.println(Arrays.toString(c));\n }\n \n if(m[pt]!=0){//This component is not fixed\n ArrayList arl2=new ArrayList<>();\n \n for (int i : qu2) {\n if(m[i]<0){\n m[i]=-m[i]; c[i]=-c[i]; qu.add(i);\n }\n arl2.add(c[i]);\n }\n \n Collections.sort(arl2);\n int med=arl2.get(arl2.size()/2);\n for (int i : qu2) {\n c[i]-=med;\n \n }\n while(!qu.isEmpty()){\n int i=qu.poll();\n c[i]=-c[i];\n }\n }\n \n }\n System.out.println(\"YES\");\n StringBuilder sb=new StringBuilder();\n for (int i = 0; i < N; i++) {\n sb.append((double)c[i]/2).append(\" \");\n }\n System.out.println(sb.toString());\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ecba31eae082003756ee84391ae69c5", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n \npublic class Main {\n\tstatic final double TOL = 0.000001;\n\tstatic ArrayList[] graph;\n\tstatic int[][] nodes;\n\tstatic boolean[] vis;\n\t\n\tstatic HashSet unusedEdges;\n\tstatic ArrayList visited;\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tint N = sc.ni();\n\t\tint M = sc.ni();\n\t\tvis = new boolean[N];\n\t\tgraph = new ArrayList[N];\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tgraph[i] = new ArrayList();\n\t\t}\n\t\tint[][] edges = new int[M][3];\n\t\tfor (int i = 0; i < M; i++) {\n\t\t\tint n1 = sc.ni()-1;\n\t\t\tint n2 = sc.ni()-1;\n\t\t\tint s = sc.ni();\n\t\t\tedges[i] = new int[] {n1,n2,s};\n\t\t\tgraph[n1].add(new Edge(n2,s,i));\n\t\t\tgraph[n2].add(new Edge(n1,s,i));\n\t\t}\n\t\tnodes = new int[N][2]; //{m,b} m(x)+b\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tnodes[i][0] = Integer.MAX_VALUE;\n\t\t\n\t\tdouble[] ans = new double[N];\n\t\t\n\t\tfor (int n = 0; n < N; n++) {\n\t\t\tif (nodes[n][0]();\n\t\t\tvisited = new ArrayList();\n\t\t\tvisited.add(n);\n\t\t\tvis[n] = true;\n\t\t\tusedDFS(n);\n\t\t\tdfs(n);\n\t\t\tdouble x = Double.MAX_VALUE;\n\t\t\tfor (int idx: unusedEdges) {\n\t\t\t\tint i = edges[idx][0];\n\t\t\t\tint j = edges[idx][1];\n\t\t\t\tint sum = edges[idx][2];\n\t\t\t\tint m = nodes[i][0]+nodes[j][0];\n\t\t\t\tint eq = sum-(nodes[i][1]+nodes[j][1]);\n\t\t\t\tif (m != 0) {\n\t\t\t\t\t//the value of x is uniquely determined!!!\n\t\t\t\t\tdouble val = (0.0+eq)/m;\n\t\t\t\t\tif (x == Double.MAX_VALUE) {\n\t\t\t\t\t\tx = val;\n\t\t\t\t\t} else if (Math.abs(x-val) > TOL) {\n\t\t\t\t\t\tpw.println(\"NO\");\n\t\t\t\t\t\tpw.close();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else if (Math.abs(eq) > TOL) {\n\t\t\t\t\tpw.println(\"NO\");\n\t\t\t\t\tpw.close();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (x == Double.MAX_VALUE) {\n\t\t\t\tArrayList meds = new ArrayList();\n\t\t\t\tfor (int i: visited) {\n\t\t\t\t\tif (nodes[i][0] != 0) {\n\t\t\t\t\t\tmeds.add((0.0-nodes[i][1])/nodes[i][0]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tCollections.sort(meds);\n\t\t\t\tx = meds.get(meds.size()/2);\n\t\t\t}\n\t\t\tfor (int i: visited) {\n\t\t\t\tans[i] = nodes[i][0]*x+nodes[i][1];\n\t\t\t}\n\t\t}\n\t\t\n\t\tpw.println(\"YES\");\n\t\tfor (double d: ans)\n\t\t\tpw.print(d + \" \");\n\t\tpw.close();\n\t}\n\t\n\tstatic void usedDFS(int node) {\n\t\tfor (Edge e: graph[node]) {\n\t\t\tint c = e.to;\n\t\t\tunusedEdges.add(e.idx);\n\t\t\tif (!vis[c]) {\n\t\t\t\tvis[c] = true;\n\t\t\t\tvisited.add(c);\n\t\t\t\tusedDFS(c);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic void dfs(int node) {\n\t\tfor (Edge e: graph[node]) {\n\t\t\tint c = e.to;\n\t\t\tif (nodes[c][0]==Integer.MAX_VALUE) {\n\t\t\t\tnodes[c][0] = -1*nodes[node][0];\n\t\t\t\tnodes[c][1] = e.sum-nodes[node][1];\n\t\t\t\tunusedEdges.remove(e.idx);\n\t\t\t\tdfs(c);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class Edge {\n\t\tint to;\n\t\tint sum;\n\t\tint idx;\n\t\tpublic Edge (int t, int s, int i) {\n\t\t\tto = t;\n\t\t\tsum = s;\n\t\t\tidx = i;\n\t\t}\n\t}\n\t\n static class FastScanner { \n BufferedReader br; \n StringTokenizer st; \n \n public FastScanner() { \n br = new BufferedReader(new InputStreamReader(System.in)); \n } \n \n String next() { \n while (st == null || !st.hasMoreElements()) { \n try { \n st = new StringTokenizer(br.readLine());\n } catch (IOException e) { \n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n }\n \n int ni() { \n return Integer.parseInt(next()); \n }\n \n long nl() { \n return Long.parseLong(next()); \n } \n \n double nd() { \n return Double.parseDouble(next()); \n } \n \n String nextLine() {\n String str = \"\"; \n try { \n str = br.readLine(); \n } catch (IOException e) {\n e.printStackTrace(); \n } \n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c1ecca9299597d65a08efa25d2052393", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class cf1387a {\n\n public static void main(String[] args) throws Exception {\n int num = 998244353;\n\n // TODO Auto-generated method stub\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n StringTokenizer st = new StringTokenizer(bf.readLine());\n int n = Integer.parseInt(st.nextToken());\n int m = Integer.parseInt(st.nextToken());\n Map> graph = new HashMap>();\n boolean ans = true;\n for (int i = 1; i <= n; i++) {\n graph.put(i, new HashMap());\n }\n for (int i = 0; i < m; i++) {\n StringTokenizer st1 = new StringTokenizer(bf.readLine());\n int a = Integer.parseInt(st1.nextToken());\n int b = Integer.parseInt(st1.nextToken());\n int c = Integer.parseInt(st1.nextToken());\n if (graph.get(a).containsKey(b) && graph.get(a).get(b) != c)\n ans = false;\n else\n graph.get(a).put(b, c);\n if (graph.get(b).containsKey(a) && graph.get(b).get(a) != c)\n ans = false;\n else\n graph.get(b).put(a, c);\n }\n Set seen = new HashSet();\n int[][] coefficients = new int[n + 1][2]; //[0] is the coefficient of x^0, [1] is coefficient of x^1\n double[] assign = new double[n + 1];\n for (int i = 1; i <= n; i++) {\n if (!seen.contains(i)) {\n coefficients[i][1] = 1;\n seen.add(1);\n double x = Integer.MAX_VALUE;\n Queue bfs = new LinkedList();\n bfs.add(i);\n Set tempseen = new HashSet();\n tempseen.add(i);\n while (!bfs.isEmpty()) {\n int vertex = bfs.remove();\n for (int k : graph.get(vertex).keySet()) {\n if (!seen.contains(k)) {\n bfs.add(k);\n coefficients[k][1] = 0 - coefficients[vertex][1];\n coefficients[k][0] = graph.get(vertex).get(k) - coefficients[vertex][0];\n tempseen.add(k);\n seen.add(k);\n } else {\n int sum = graph.get(vertex).get(k);\n if (coefficients[k][1] + coefficients[vertex][1] == 0 && coefficients[k][0] + coefficients[vertex][0] != sum)\n ans = false;\n else if (coefficients[k][1] + coefficients[vertex][1] != 0) {\n double ass = (sum - coefficients[k][0] - coefficients[vertex][0] + 0.0) / (coefficients[k][1] + coefficients[vertex][1] + 0.0);\n if (x != ass && x != Integer.MAX_VALUE)\n ans = false;\n else\n x = ass;\n }\n }\n }\n }\n if (x != Integer.MAX_VALUE) {\n for (int j : tempseen) {\n assign[j] = x * coefficients[j][1] + coefficients[j][0];\n }\n } else {\n int sumcoeff0 = 0;\n int sumcoeff1 = 0;\n int maxval = Integer.MIN_VALUE;\n int minval = Integer.MAX_VALUE;\n ArrayList vals = new ArrayList();\n for (int j : tempseen) {\n sumcoeff0 += coefficients[j][0];\n sumcoeff1 += coefficients[j][1];\n vals.add((0 - coefficients[j][1]) * coefficients[j][0]);\n }\n Collections.sort(vals);\n if (vals.size() % 2 == 1) {\n x = vals.get(vals.size() / 2);\n } else {\n x = (vals.get(vals.size() / 2) + vals.get(vals.size() / 2 - 1)) / 2.0;\n }\n for (int j : tempseen) {\n assign[j] = x * coefficients[j][1] + coefficients[j][0];\n }\n }\n\n\n }\n }\n\n\n if (!ans)\n out.println(\"NO\");\n else {\n out.println(\"YES\");\n for (int i = 1; i <= n; i++) {\n out.print(assign[i] + \" \");\n }\n\n }\n\n\n out.println();\n\n out.close();\n\n\n }\n}\n\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\n\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ae5dc9c0cb74cabb438195f6f121a2f", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class H {\n\n\tboolean solve() {\n\t\tint alph = nextInt();\n\t\tint n = nextInt();\n\n\t\tint[][] a = new int[n][];\n\t\tint tot = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k = nextInt();\n\t\t\tint[] che = a[i] = new int[k];\n\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\tche[j] = nextInt() - 1;\n\t\t\t}\n\t\t\ttot += k;\n\t\t}\n\n\t\tint r = (int) Math.sqrt(tot);\n//\t\tint r = Integer.MAX_VALUE;\n\n\t\tfor (int i = 0, j = n - 1;;) {\n\t\t\twhile (i < j && a[i].length <= r) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (i < j && a[j].length > r) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i == j) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tint[] tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\n\t\tHashMap map = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n//\t\t\tif (b.length > r) {\n\t\t\tif (true) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j1 = 0; j1 < b.length; j1++) {\n\t\t\t\tfor (int j2 = j1 + 1; j2 < b.length; j2++) {\n\t\t\t\t\tlong key = (long) b[j1] * alph + b[j2];\n\t\t\t\t\tInteger prev = map.get(key);\n\t\t\t\t\tif (prev == null) {\n\t\t\t\t\t\tmap.put(key, b[j1 + 1]);\n\t\t\t\t\t} else if (prev != b[j1 + 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}\n\n\t\tint[] id = new int[alph];\n\t\tArrays.fill(id, -2);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length <= r) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = j;\n\t\t\t}\n\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (clash(a[j], id)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = -2;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tboolean clash(int[] a, int[] f) {\n\t\tint prev = f[a[0]];\n\t\tint curMin = prev == -2 ? Integer.MAX_VALUE : prev;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tint now = f[a[i]];\n\t\t\tif (now != prev + 1 && now > curMin) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (now != -2) {\n\t\t\t\tcurMin = Math.min(curMin, now);\n\t\t\t}\n\n\t\t\tprev = now;\n\t\t}\n\t\treturn false;\n\t}\n\n\tvoid submit() {\n\t\tint t = nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tout.println(solve() ? \"Human\" : \"Robot\");\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tH() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew H();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e779f69634e99c78ac7c7b3841c8a73", "src_uid": "d742933184ce1cad098fcb8a264df630", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class H {\n\n\tboolean solve() {\n\t\tint alph = nextInt();\n\t\tint n = nextInt();\n\n\t\tint[][] a = new int[n][];\n\t\tint tot = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k = nextInt();\n\t\t\tint[] che = a[i] = new int[k];\n\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\tche[j] = nextInt() - 1;\n\t\t\t}\n\t\t\ttot += k;\n\t\t}\n\n\t\tint r = (int) Math.sqrt(tot);\n\n\t\tfor (int i = 0, j = n - 1;;) {\n\t\t\twhile (i < j && a[i].length <= r) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (i < j && a[j].length > r) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i == j) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tint[] tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\n\t\tHashMap map = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length > r) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j1 = 0; j1 < b.length; j1++) {\n\t\t\t\tfor (int j2 = j1 + 1; j2 < b.length; j2++) {\n\t\t\t\t\tlong key = (long) b[j1] * alph + b[j2];\n\t\t\t\t\tInteger prev = map.get(key);\n\t\t\t\t\tif (prev == null) {\n\t\t\t\t\t\tmap.put(key, b[j1 + 1]);\n\t\t\t\t\t} else if (prev != b[j1 + 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}\n\n\t\tint[] id = new int[alph];\n\t\tArrays.fill(id, -2);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length <= r) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = j;\n\t\t\t}\n\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (clash(a[j], id)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = -2;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tboolean clash(int[] a, int[] f) {\n\t\tint prev = f[a[0]];\n\t\tint curMin = prev == -1 ? Integer.MAX_VALUE : prev;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tint now = f[a[i]];\n\t\t\tif (now != prev + 1 && now > curMin) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (now != -2) {\n\t\t\t\tcurMin = Math.min(curMin, now);\n\t\t\t}\n\n\t\t\tprev = now;\n\t\t}\n\t\treturn false;\n\t}\n\n\tvoid submit() {\n\t\tint t = nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tout.println(solve() ? \"Human\" : \"Robot\");\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tH() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew H();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6926fb68b811b7159224314e3dfe57d0", "src_uid": "d742933184ce1cad098fcb8a264df630", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class H {\n\n\tboolean solve() {\n\t\tint alph = nextInt();\n\t\tint n = nextInt();\n\n\t\tint[][] a = new int[n][];\n\t\tint tot = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k = nextInt();\n\t\t\tint[] che = a[i] = new int[k];\n\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\tche[j] = nextInt() - 1;\n\t\t\t}\n\t\t\ttot += k;\n\t\t}\n\n//\t\tint r = (int) Math.sqrt(tot);\n\t\tint r = 0;\n\n\t\tfor (int i = 0, j = n - 1;;) {\n\t\t\twhile (i < j && a[i].length <= r) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (i < j && a[j].length > r) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i == j) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tint[] tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\n\t\tHashMap map = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length > r) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j1 = 0; j1 < b.length; j1++) {\n\t\t\t\tfor (int j2 = j1 + 1; j2 < b.length; j2++) {\n\t\t\t\t\tlong key = (long) b[j1] * alph + b[j2];\n\t\t\t\t\tInteger prev = map.get(key);\n\t\t\t\t\tif (prev == null) {\n\t\t\t\t\t\tmap.put(key, b[j1 + 1]);\n\t\t\t\t\t} else if (prev != b[j1 + 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}\n\n\t\tint[] id = new int[alph];\n\t\tArrays.fill(id, -2);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length <= r) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = j;\n\t\t\t}\n\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (clash(a[j], id)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = -2;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tboolean clash(int[] a, int[] f) {\n\t\tint prev = f[a[0]];\n\t\tint curMin = prev == -1 ? Integer.MAX_VALUE : prev;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tint now = f[a[i]];\n\t\t\tif (now != prev + 1 && now > curMin) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (now != -2) {\n\t\t\t\tcurMin = Math.min(curMin, now);\n\t\t\t}\n\n\t\t\tprev = now;\n\t\t}\n\t\treturn false;\n\t}\n\n\tvoid submit() {\n\t\tint t = nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tout.println(solve() ? \"Human\" : \"Robot\");\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tH() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew H();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6b3aeffe270d171b981affe477347a6", "src_uid": "d742933184ce1cad098fcb8a264df630", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class H {\n\n\tboolean solve() {\n\t\tint alph = nextInt();\n\t\tint n = nextInt();\n\n\t\tint[][] a = new int[n][];\n\t\tint tot = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k = nextInt();\n\t\t\tint[] che = a[i] = new int[k];\n\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\tche[j] = nextInt() - 1;\n\t\t\t}\n\t\t\ttot += k;\n\t\t}\n\n\t\tint r = (int) Math.sqrt(tot);\n//\t\tint r = 0;\n\n\t\tfor (int i = 0, j = n - 1;;) {\n\t\t\twhile (i < j && a[i].length <= r) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (i < j && a[j].length > r) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i == j) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tint[] tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\n\t\tHashMap map = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length > r) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j1 = 0; j1 < b.length; j1++) {\n\t\t\t\tfor (int j2 = j1 + 1; j2 < b.length; j2++) {\n\t\t\t\t\tlong key = (long) b[j1] * alph + b[j2];\n\t\t\t\t\tInteger prev = map.get(key);\n\t\t\t\t\tif (prev == null) {\n\t\t\t\t\t\tmap.put(key, b[j1 + 1]);\n\t\t\t\t\t} else if (prev != b[j1 + 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}\n\n\t\tint[] id = new int[alph];\n\t\tArrays.fill(id, -2);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length <= r) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = j;\n\t\t\t}\n\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (clash(a[j], id)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = -2;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tboolean clash(int[] a, int[] f) {\n\t\tint prev = f[a[0]];\n\t\tint curMin = prev == -2 ? Integer.MAX_VALUE : prev;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tint now = f[a[i]];\n\t\t\tif (now != prev + 1 && now > curMin) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (now != -2) {\n\t\t\t\tcurMin = Math.min(curMin, now);\n\t\t\t}\n\n\t\t\tprev = now;\n\t\t}\n\t\treturn false;\n\t}\n\n\tvoid submit() {\n\t\tint t = nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tout.println(solve() ? \"Human\" : \"Robot\");\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tH() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew H();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b) || b == ' ') {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4388e565d1ae51a2574fa0dacb209e4e", "src_uid": "d742933184ce1cad098fcb8a264df630", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "//package round418;\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 mod = 1000000007;\n\t\tint n = ni();\n\t\tint[] ds = na(n);\n\t\t\n\t\tlong[][] C = new long[50 + 1][50 + 1];\n\t\tfor (int i = 0; i <= 50; i++) {\n\t\t\tC[i][0] = 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\tif (C[i][j] >= mod)\n\t\t\t\t\tC[i][j] -= mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong[] ip2 = new long[50];\n\t\tlong i2 = invl(2, mod);\n\t\tip2[0] = 1;\n\t\tfor(int i = 1;i < 50;i++)ip2[i] = ip2[i-1] * i2 % mod;\n\t\t\n\t\t// [\u540c\u5c64\u3067\u51e6\u7406\u6e08\u307f\u306e1\u6b21\u306e\u9802\u70b9][\u540c\u5c64\u3067\u51e6\u7406\u6e08\u307f\u306e2\u6b21\u306e\u9802\u70b9][\u540c\u5c64\u3067\u672a\u51e6\u7406\u306e\u9802\u70b9]\n\t\tlong[][][] dp = new long[30][30][30];\n\t\tdp[0][0][ds[0]] = ds[0] == 3 ? invl(6, mod) : invl(2, mod);\n\t\tfor(int i = 1;i < n;i++){\n\t\t\tlong[][][] ndp = new long[30][30][30];\n\t\t\tfor(int k = 0;k < 30;k++){\n\t\t\t\tfor(int l = 0;k+l < 30;l++){\n\t\t\t\t\tfor(int m = 1;k+l+m < 30;m++){\n\t\t\t\t\t\tif(dp[k][l][m] == 0)continue;\n\t\t\t\t\t\t// \u672a\u51e6\u7406\u306e\u70b9\u304b\u30891\u500b\u9078\u3076\n\t\t\t\t\t\t// 1,2\u6b21\u306e\u9802\u70b9\u3068\u7d50\u3076\n\t\t\t\t\t\tfor(int c1 = 0;c1 <= k && c1 <= ds[i]-1;c1++){\n\t\t\t\t\t\t\tfor(int c2 = 0;c2 <= l && c1+c2 <= ds[i]-1;c2++){\n\t\t\t\t\t\t\t\tint n1 = k-c1+c2, n2 = l-c2;\n\t\t\t\t\t\t\t\tint pl = ds[i] - 1 - c1 - c2;\n\t\t\t\t\t\t\t\tif(pl == 1)n1++;\n\t\t\t\t\t\t\t\tif(pl == 2)n2++;\n\t\t\t\t\t\t\t\tlong v = m * dp[k][l][m] % mod * C[k][c1] % mod * C[l][c2];\n//\t\t\t\t\t\t\t\ttr(i, k, l, m, c1, c2, n1, n2, dp[k][l][m], v);\n\t\t\t\t\t\t\t\tif(m-1 > 0){\n\t\t\t\t\t\t\t\t\tndp[n1][n2][m-1] += v;\n\t\t\t\t\t\t\t\t\tndp[n1][n2][m-1] %= mod;\n\t\t\t\t\t\t\t\t}else if(n1+2*n2+i+1 <= n){\n\t\t\t\t\t\t\t\t\t// \u6b21\u306e\u5c64\u3078\n\t\t\t\t\t\t\t\t\tndp[0][0][n1+2*n2] += v % mod * ip2[n2];\n\t\t\t\t\t\t\t\t\tndp[0][0][n1+2*n2] %= 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\tdp = ndp;\n\t\t}\n\t\tout.println(dp[0][0][0]);\n\t}\n\t\n\tpublic static long invl(long a, long mod) {\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 50, m = 99999;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(n + \" \");\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tsb.append(gen.nextInt(2)+2 + \" \");\n//\t\t}\n//\t\tINPUT = sb.toString();\n\n\t\t\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e7f743d810cccd0fbcac97a5e5cec3af", "src_uid": "db884d679d9cfb1dc4bc511f83beedda", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Div2_418E {\n\n\t// solution completely based on that of the editorial\n\n\tstatic final long MOD = 1_000_000_007L;\n\n\tstatic int numV;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tnumV = Integer.parseInt(reader.readLine());\n\n\t\tint[] deg = new int[numV + 1];\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tfor (int i = 1; i <= numV; i++) {\n\t\t\tdeg[i] = Integer.parseInt(inputData.nextToken());\n\t\t}\n\t\treader.close();\n\n\t\t// let assign[A][B][C] represent the number of ways to move to a level with A vertices from a level with B\n\t\t// 1-opening vertices and C 2-opening vertices\n\t\tlong[][][] aCnt = new long[numV + 5][numV + 5][numV + 5];\n\n\t\taCnt[0][0][0] = 1;\n\n\t\t// loop ordering is non-trivial cnt2 has to be before the cnt1 loop\n\t\tfor (int cntE = 0; cntE <= numV; cntE++) {\n\t\t\tfor (int cnt2 = 0; cnt2 <= numV; cnt2++) {\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= numV; cnt1++) {\n\t\t\t\t\tlong cCnt = 0;\n\n\t\t\t\t\t// ext, ext\n\t\t\t\t\t// ext, t1\n\t\t\t\t\t// ext, t2\n\t\t\t\t\t// t1, t1\n\t\t\t\t\t// t1, t2\n\t\t\t\t\t// t2, t2\n\n\t\t\t\t\tif (cnt2 > 0) {\n\t\t\t\t\t\tif (cntE > 1) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE - 2][cnt1][cnt2 - 1] * cntE * (cntE - 1) >> 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cntE > 0 && cnt1 > 0) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE - 1][cnt1 - 1][cnt2 - 1] * cntE * cnt1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cntE > 0 && cnt2 > 1) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE - 1][cnt1 + 1][cnt2 - 2] * cntE * (cnt2 - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cnt1 > 1) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE][cnt1 - 2][cnt2 - 1] * cnt1 * (cnt1 - 1) >> 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cnt1 > 0 && cnt2 > 1) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE][cnt1][cnt2 - 2] * cnt1 * (cnt2 - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cnt2 > 2) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE][cnt1 + 2][cnt2 - 3] * (cnt2 - 1) * (cnt2 - 2) >> 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcCnt %= MOD;\n\t\t\t\t\t\taCnt[cntE][cnt1][cnt2] = cCnt;\n\t\t\t\t\t} else if (cnt1 > 0) {\n\t\t\t\t\t\tif (cntE > 0) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE - 1][cnt1 - 1][0] * cntE;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (cnt1 > 1) {\n\t\t\t\t\t\t\tcCnt += aCnt[cntE][cnt1 - 2][0] * (cnt1 - 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcCnt %= MOD;\n\t\t\t\t\t\taCnt[cntE][cnt1][cnt2] = cCnt;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint[] preCnt1 = new int[numV + 1];\n\t\tfor (int i = 1; i <= numV; i++) {\n\t\t\tpreCnt1[i] = deg[i] == 2 ? 1 + preCnt1[i - 1] : preCnt1[i - 1];\n\t\t}\n\n\t\tlong[][] ans = new long[numV + 5][numV + 5];\n\n\t\t// smart way of initializing everything with the last object to 1\n\t\tans[numV + 1][numV] = 1;\n\n\t\tfor (int l = numV; l > 1; l--) {\n\t\t\tfor (int r = l; r <= numV; r++) {\n\t\t\t\tint cnt1 = preCnt1[r] - preCnt1[l - 1];\n\t\t\t\tint cnt2 = r - l + 1 - cnt1;\n\n\t\t\t\tfor (int nLevLen = 0; nLevLen <= (cnt2 << 1) + cnt1 && r + nLevLen <= numV; nLevLen++) {\n\t\t\t\t\tans[l][r] = (ans[l][r] + ans[r + 1][r + nLevLen] * aCnt[nLevLen][cnt1][cnt2]) % MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(ans[2][1 + deg[1]]);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e050fd4167cbcf103ba4c9a10644ea4d", "src_uid": "db884d679d9cfb1dc4bc511f83beedda", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class CF418E {\n\n private static final boolean TEST_CASES = false;\n private static final int MOD = 1000000007;\n private final Map dp = new HashMap<>();\n private int n;\n private int[] di;\n\n void solve(int testCaseNo, InputReader in, PrintWriter out) {\n n = in.nextInt();\n di = new int[n];\n for (int i = 0; i < n; i++) {\n di[i] = in.nextInt();\n }\n\n out.println(ways(2, 3 - di[0], di[0] - 2, 3 - di[1], di[1] - 2));\n\n }\n\n private int ways(int i, int x1, int x2, int y1, int y2) {\n if (x1 < 0 || x2 < 0 || y1 < 0 || y2 < 0) return 0;\n if (i == n) {\n if (x1 != 0 || x2 != 0 || y1 != 0 || y2 != 0)\n return 0;\n return 1;\n }\n int sx = x1 + x2;\n int sy = y1 + y2;\n if ((sx + sy) == 0) return 0;\n if (sx == 0) return ways(i, y1, y2, x1, x2);\n\n Cache c = new Cache(x1, x2, y1, y2, i);\n if (dp.containsKey(c)) return dp.get(c);\n\n// System.out.println(i + \" \" + x1 + \" \" + x2 + \" \" + y1 + \" \" + y2);\n\n int r = 0;\n\n if (di[i] == 2) {\n\n // chose from x1\n // don't assign to same level\n r = add(r, mul(x1, ways(i + 1, x1 - 1, x2, y1 + 1, y2)));\n\n // assign one to same level one-empty\n r = add(r, mul(x1, y1, ways(i + 1, x1 - 1, x2, y1 - 1, y2)));\n\n // assign one to same level two-empty\n r = add(r, mul(x1, y2, ways(i + 1, x1 - 1, x2, y1 + 1, y2 - 1)));\n\n\n // chose from x2\n // don't assign to same level\n r = add(r, mul(x2, ways(i + 1, x1 + 1, x2 - 1, y1 + 1, y2)));\n\n // assign one to same level one-empty\n r = add(r, mul(x2, y1, ways(i + 1, x1 + 1, x2 - 1, y1 - 1, y2)));\n\n // assign one to same level two-empty\n r = add(r, mul(x2, y2, ways(i + 1, x1 + 1, x2 - 1, y1 + 1, y2 - 1)));\n\n } else {\n\n // chose from x1\n // don't assign to same level\n r = add(r, mul(x1, ways(i + 1, x1 - 1, x2, y1, y2 + 1)));\n\n // assign one to same level one-empty\n r = add(r, mul(x1, y1, ways(i + 1, x1 - 1, x2, y1, y2)));\n\n // assign one to same level two-empty\n r = add(r, mul(x1, y2, ways(i + 1, x1 - 1, x2, y1 + 2, y2 - 1)));\n\n // assign two to two one-empty\n if (y1 >= 2) r = add(r, mul(x1, ((y1 * (y1 - 1)) / 2), ways(i + 1, x1 - 1, x2, y1 - 2, y2)));\n // assign two: one to one-empty other to two-empty\n r = add(r, mul(mul(x1, y1, y2), ways(i + 1, x1 - 1, x2, y1, y2 - 1)));\n // assign two: both to two-empty\n if (y2 >= 2) r = add(r, mul(x1, ((y2 * (y2 - 1)) / 2), ways(i + 1, x1 - 1, x2, y1 + 2, y2 - 2)));\n\n\n\n // chose from x2\n // don't assign to same level\n r = add(r, mul(x2, ways(i + 1, x1 + 1, x2 - 1, y1, y2 + 1)));\n\n // assign one to same level one-empty\n r = add(r, mul(x2, y1, ways(i + 1, x1 + 1, x2 - 1, y1, y2)));\n\n // assign one to same level two-empty\n r = add(r, mul(x2, y2, ways(i + 1, x1 + 1, x2 - 1, y1 + 2, y2 - 1)));\n\n // assign two to two one-empty\n if (y1 >= 2) r = add(r, mul(x2, ((y1 * (y1 - 1)) / 2), ways(i + 1, x1 + 1, x2 - 1, y1 - 2, y2)));\n // assign two: one to one-empty other to two-empty\n r = add(r, mul(mul(x2, y1, y2), ways(i + 1, x1 + 1, x2 - 1, y1, y2 - 1)));\n // assign two: both to two-empty\n if (y2 >= 2) r = add(r, mul(x2, ((y2 * (y2 - 1)) / 2), ways(i + 1, x1 + 1, x2 - 1, y1 + 2, y2 - 2)));\n\n }\n\n dp.put(c, r);\n return r;\n }\n\n private int add(int a, int b) {\n return (a + b) % MOD;\n }\n private int mul(int a, int b) {\n long t = (long)a * b;\n return (int) (t % MOD);\n }\n private int mul(int a, int b, int c) {\n return mul(a, mul(b, c));\n }\n\n\n static class Cache {\n\n final int x1;\n final int x2;\n final int y1;\n final int y2;\n final int i;\n\n public Cache(int x1, int x2, int y1, int y2, int i) {\n this.x1 = x1;\n this.x2 = x2;\n this.y1 = y1;\n this.y2 = y2;\n this.i = i;\n }\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 Cache cache = (Cache) o;\n\n if (x1 != cache.x1) return false;\n if (x2 != cache.x2) return false;\n if (y1 != cache.y1) return false;\n if (y2 != cache.y2) return false;\n return i == cache.i;\n }\n\n @Override\n public int hashCode() {\n int result = x1;\n result = 31 * result + x2;\n result = 31 * result + y1;\n result = 31 * result + y2;\n result = 31 * result + i;\n return result;\n }\n }\n\n\n private 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 /**\n * @return null if end of stream\n */\n public String readLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\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\n int testCases = TEST_CASES ? in.nextInt() : 1;\n\n CF418E solver = new CF418E();\n for (int testCase = 0; testCase < testCases; testCase++) {\n solver.solve(testCase, in, out);\n }\n out.flush();\n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d207ea5def2f345e4abe614f8a3db8fa", "src_uid": "db884d679d9cfb1dc4bc511f83beedda", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "//package round418;\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 mod = 1000000007;\n\t\tint n = ni();\n\t\tint[] ds = na(n);\n\t\t\n\t\tlong[][] C = new long[50 + 1][50 + 1];\n\t\tfor (int i = 0; i <= 50; i++) {\n\t\t\tC[i][0] = 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\tif (C[i][j] >= mod)\n\t\t\t\t\tC[i][j] -= mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong[] ip2 = new long[50];\n\t\tlong i2 = invl(2, mod);\n\t\tip2[0] = 1;\n\t\tfor(int i = 1;i < 50;i++)ip2[i] = ip2[i-1] * i2 % mod;\n\t\t\n\t\t// [\u540c\u5c64\u3067\u51e6\u7406\u6e08\u307f\u306e1\u6b21\u306e\u9802\u70b9][\u540c\u5c64\u3067\u51e6\u7406\u6e08\u307f\u306e2\u6b21\u306e\u9802\u70b9][\u540c\u5c64\u3067\u672a\u51e6\u7406\u306e\u9802\u70b9]\n\t\tlong[][][] dp = new long[30][30][30];\n\t\tdp[0][0][ds[0]] = ds[0] == 3 ? invl(6, mod) : invl(2, mod);\n\t\tfor(int i = 1;i < n;i++){\n\t\t\tlong[][][] ndp = new long[30][30][30];\n\t\t\tfor(int k = 0;k < 30;k++){\n\t\t\t\tfor(int l = 0;k+l < 30;l++){\n\t\t\t\t\tfor(int m = 1;k+l+m < 30;m++){\n\t\t\t\t\t\tif(dp[k][l][m] == 0)continue;\n\t\t\t\t\t\t// \u672a\u51e6\u7406\u306e\u70b9\u304b\u30891\u500b\u9078\u3076\n\t\t\t\t\t\t// 1,2\u6b21\u306e\u9802\u70b9\u3068\u7d50\u3076\n\t\t\t\t\t\tfor(int c1 = 0;c1 <= k && c1 <= ds[i]-1;c1++){\n\t\t\t\t\t\t\tfor(int c2 = 0;c2 <= l && c1+c2 <= ds[i]-1;c2++){\n\t\t\t\t\t\t\t\tint n1 = k-c1+c2, n2 = l-c2;\n\t\t\t\t\t\t\t\tint pl = ds[i] - 1 - c1 - c2;\n\t\t\t\t\t\t\t\tif(pl == 1)n1++;\n\t\t\t\t\t\t\t\tif(pl == 2)n2++;\n\t\t\t\t\t\t\t\tlong v = m * dp[k][l][m] % mod * C[k][c1] % mod * C[l][c2];\n//\t\t\t\t\t\t\t\ttr(i, k, l, m, c1, c2, n1, n2, dp[k][l][m], v);\n\t\t\t\t\t\t\t\tif(m-1 > 0){\n\t\t\t\t\t\t\t\t\tndp[n1][n2][m-1] += v;\n\t\t\t\t\t\t\t\t\tndp[n1][n2][m-1] %= mod;\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\t// \u6b21\u306e\u5c64\u3078\n\t\t\t\t\t\t\t\t\tndp[0][0][n1+2*n2] += v % mod * ip2[n2];\n\t\t\t\t\t\t\t\t\tndp[0][0][n1+2*n2] %= 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\tdp = ndp;\n\t\t}\n\t\tout.println(dp[0][0][0]);\n\t}\n\t\n\tpublic static long invl(long a, long mod) {\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a623cddd4bef684b6398c2abf14a18f2", "src_uid": "db884d679d9cfb1dc4bc511f83beedda", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "\n\n\nimport static java.lang.System.out;\nimport java.util.Scanner;\n\n// 795A\n// n people, some pupil, some adult. separate into groups. a group must have 1 adult\n// if a group has x people, cost of tickets=c1+c2(x-1)^2\n// find minimal price\npublic class AmusementPark {\n \n int adult;\n int pupil;\n int n; // 1\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000\n long c1; // 1\u2009\u2264\u2009c1,\u2009c2\u2009\u2264\u200910^7\n long c2;\n long minCost=0;\n \n long formula(int x)\n {\n return c1+c2*(x-1)*(x-1);\n }\n long calc(int group)\n {\n if (group==1)\n {\n return formula(n);\n }\n int avg = n/group;\n int rem = n%group;\n long cost = formula(avg);\n if ( rem>0 ) {\n cost *= (group-rem);\n return cost + rem*formula(avg+1);\n }\n else \n return cost *group;\n }\n long cost(int lo, int hi, long lowCost, long hiCost)\n {\n if (lo-hi<=1 && lo-hi>=-1) {\n return lowCost;\n }\n int mid = (lo+hi)/2;\n long midCost = calc(mid);\n //out.println(\"first \"+lo+\" second \"+hi+ \" mid cost \"+midCost+\" low clost \"+lowCost+\" hi cost \"+hiCost);\n if (midCostcost2)\n out.println(cost(a, 1, cost2, cost1));\n else if (cost1 1) {\n long mid = (lo + hi) / 2;\n if (f(mid) > f(mid + 1)) {\n hi = mid;\n } else {\n lo = mid;\n }\n }\n if (f(lo) < f(hi)) {\n out.println(f(lo));\n } else {\n out.println(f(hi));\n }\n\n }\n\n long f(long v) {\n long p1 = n / v;\n\n long sum = c1 * v;\n sum += (n % v) * c2 * (p1) * (p1);\n sum += (v - (n % v)) * c2 * (p1 - 1) * (p1 - 1);\n\n return sum;\n }\n\n }\n\n static class MyReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public MyReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d86ef1b1632d26b76386ac5ad0e9002", "src_uid": "78d013b01497053b8e321fe7b6ce3760", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "\n\n\nimport static java.lang.System.out;\nimport java.util.Scanner;\n\n// 795A\n// n people, some pupil, some adult. separate into groups. a group must have 1 adult\n// if a group has x people, cost of tickets=c1+c2(x-1)^2\n// find minimal price\npublic class AmusementPark {\n \n int adult;\n int pupil;\n int n;\n int c1;\n int c2;\n long minCost=0;\n \n long formula(int x)\n {\n return c1+c2*(x-1)*(x-1);\n }\n long calc(int group)\n {\n if (group==1)\n {\n return formula(n);\n }\n int avg = n/group;\n int rem = n%group;\n long cost = formula(avg);\n if ( rem>0 ) {\n cost *= (group-rem);\n return cost + rem*formula(avg+1);\n }\n else \n return cost *group;\n }\n long cost(int lo, int hi, long lowCost, long hiCost)\n {\n if (lo-hi<=1 && lo-hi>=-1) {\n return lowCost;\n }\n int mid = (lo+hi)/2;\n long midCost = calc(mid);\n //out.println(\"first \"+lo+\" second \"+hi+ \" mid cost \"+midCost+\" low clost \"+lowCost+\" hi cost \"+hiCost);\n if (midCostcost2)\n out.println(cost(a, 1, cost2, cost1));\n else if (cost10 ) {\n cost *= (group-rem);\n return cost + rem*formula(avg+1);\n }\n else \n return cost *group;\n }\n long cost(int lo, int hi, long lowCost, long hiCost)\n {\n if (lo-hi<=1 && lo-hi>=-1) {\n return lowCost;\n }\n int mid = (lo+hi)/2;\n long midCost = calc(mid);\n //out.println(\"first \"+lo+\" second \"+hi+ \" mid cost \"+midCost+\" low clost \"+lowCost+\" hi cost \"+hiCost);\n if (midCostcost2)\n out.println(cost(a, 1, cost2, cost1));\n else if (cost1>1)][trans(i,j)]=1;\n if(i>1|(1<0){\n if((b&1)==1)\n ans=modMul(ans,a);\n a=modMul(a,a);\n b>>=1;\n }\n return ans;\n }\n public int[][] modMul(int[][]a,int[][]b){\n int row=a.length,column=b[0].length;\n int len=b.length;\n int[][] ans=new int[row][column];\n for(int i=0;il+1; i--) {\n int j=rnd.nextInt(i),tmp=a[j];\n a[j]=a[i-1];\n a[i-1]=tmp;\n }\n }\n void shuffle(Object[]a,int l,int r){\n Random rnd=new Random();\n for (int i=r; i>l+1; i--) {\n int j=rnd.nextInt(i);\n Object tmp=a[j];\n a[j]=a[i-1];\n a[i-1]=tmp;\n }\n }\n void shuffle(long[]a,int l,int r){\n Random rnd=new Random();\n for (int i=r; i>l+1; i--) {\n int j=rnd.nextInt(i);\n long tmp=a[j];\n a[j]=a[i-1];\n a[i-1]=tmp;\n }\n }\n class InputReader{\n StreamTokenizer tokenizer;\n public InputReader(InputStream stream){\n tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));\n tokenizer.ordinaryChars(33,126);\n tokenizer.wordChars(33,126);\n }\n public String next() throws IOException {\n tokenizer.nextToken();\n return tokenizer.sval;\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n public boolean hasNext() throws IOException {\n int res=tokenizer.nextToken();\n tokenizer.pushBack();\n return res!=tokenizer.TT_EOF;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ccc6853eb1603db215bf93b767c6f5c0", "src_uid": "87931a8ae9a76d85bd2a2b4bba93303d", "difficulty": 3000.0} {"lang": "Java 6", "source_code": "//package round97;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class E2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"1000000 1000000000\";\n//\tString INPUT = \"2 139\";\n//\tString INPUT = \"2 139\";\n\tint mod = 1000000007;\n\t\n\tlong[] PS = new long[1000002];\n\tlong[] IPS = new long[1000002];\n\tlong[] KE = new long[1000002];\n\tlong[] KE2 = new long[1000020];\n\t\n\tvoid solve()\n\t{\n\t\tint k = ni(), w = ni();\n\t\tlong sum = 0;\n\t\tPS[0] = 1;\n\t\tIPS[0] = 1;\n\t\tKE[0] = modpow(k, w, mod);\n\t\tKE2[0] = modpow(k, w+4, mod);\n\t\tlong ik = inv(k, mod);\n\t\tfor(int i = 1;i <= k+1;i++){\n\t\t\tPS[i] = PS[i-1]*(k-i+1)%mod;\n\t\t\tIPS[i] = IPS[i-1]*inv(k-i+1, mod)%mod;\n\t\t\tKE[i] = KE[i-1] * k % mod;\n\t\t}\n\t\tfor(int i = 1;i <= k+19;i++){\n\t\t\tKE2[i] = KE2[i-1] * ik % mod;\n\t\t}\n\t\tgw = w;\n\t\tfor(int l = w+1;l <= w+k;l++){\n\t\t\tlong v = (val(k, w, l) - val(k, w+1, l)) % mod;\n\t\t\tsum += v;\n//\t\t\ttr(l, v);\n\t\t}\n\t\tout.println((sum%mod+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\tint gw;\n\t\n\t// k=2,W=2,L=3\n\t// 8\n\t\n\tint gct = 0;\n\t// \n\t// OXO\n\tlong val(long k, long W, long L)\n\t{\n\t\tif(W >= L)return 0;\n\t\t// head\u3067\u542b\u3080\n\t\t// tail\u3067\u542b\u3080\n\t\t// 2W-L+2=W+2-(L-W)\n\t\tlong ret;\n\t\tif(W > L+1-W){\n//\t\t\tret = modpow(k, L, mod) - modpow(k, L-2*(L-W+1), mod) * modpow(P(k, L-W+1), 2, mod)%mod;\n\t\t\tret = KE[(int)(L-gw)] - KE2[(int)(gw+4-(L-2*(L-W+1)))] * modpow(P(k, L-W+1), 2, mod)%mod;\n\t\t}else{\n\t\t\tlong p = k-(L-2*(W-1)) < W-1 ? 0 : P(k, (L-2*(W-1))+(W-1))*invP(k, L-2*(W-1))%mod;\n//\t\t\tret = modpow(k, L, mod) - P(k,L-2*(W-1))*modpow(p, 2, mod)%mod;\n\t\t\tret = KE[(int)(L-gw)] - P(k,L-2*(W-1))*modpow(p, 2, mod)%mod;\n\t\t}\n\t\t\n\t\treturn (int)((ret%mod+mod)%mod);\n\t}\n\t\n\tlong P(long n, long r)\n\t{\n\t\tif(r > n)return 0;\n\t\treturn PS[(int)r];\n\t}\n\t\n\tlong invP(long n, long r)\n\t{\n\t\tif(r > n)return 0;\n\t\treturn IPS[(int)r];\n\t}\n\t\n\tpublic static long modpow(long a, long n, long mod)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1){\n\t\t\t\tret = (ret * mul) % mod;\n\t\t\t}\n\t\t\tmul = (mul * mul) % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew E2().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fa764971b3ce62344e82fceb3d247485", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130", "difficulty": 3000.0} {"lang": "Java 6", "source_code": "//package round97;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class E2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n//\tString INPUT = \"2 139\";\n//\tString INPUT = \"2 139\";\n\tint mod = 1000000007;\n\t\n\tlong[] PS = new long[1000001];\n\tlong[] IPS = new long[1000001];\n\tlong[] KE = new long[1000002];\n\tlong[] KE2 = new long[1000020];\n\t\n\tvoid solve()\n\t{\n\t\tint k = ni(), w = ni();\n\t\tlong sum = 0;\n\t\tPS[0] = 1;\n\t\tIPS[0] = 1;\n\t\tKE[0] = modpow(k, w, mod);\n\t\tKE2[0] = modpow(k, w+4, mod);\n\t\tlong ik = inv(k, mod);\n\t\tfor(int i = 1;i <= k;i++){\n\t\t\tPS[i] = PS[i-1]*(k-i+1)%mod;\n\t\t\tIPS[i] = IPS[i-1]*inv(k-i+1, mod)%mod;\n\t\t\tKE[i] = KE[i-1] * k % mod;\n\t\t}\n\t\tfor(int i = 1;i <= k+19;i++){\n\t\t\tKE2[i] = KE2[i-1] * ik % mod;\n\t\t}\n\t\tgw = w;\n\t\tfor(int l = w+1;l <= w+k;l++){\n\t\t\tlong v = (val(k, w, l) - val(k, w+1, l)) % mod;\n\t\t\tsum += v;\n//\t\t\ttr(l, v);\n\t\t}\n\t\tout.println((sum%mod+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\tint gw;\n\t\n\t// k=2,W=2,L=3\n\t// 8\n\t\n\tint gct = 0;\n\t// \n\t// OXO\n\tlong val(long k, long W, long L)\n\t{\n\t\tif(W >= L)return 0;\n\t\t// head\u3067\u542b\u3080\n\t\t// tail\u3067\u542b\u3080\n\t\t// 2W-L+2=W+2-(L-W)\n\t\tlong ret;\n\t\tif(W > L+1-W){\n//\t\t\tret = modpow(k, L, mod) - modpow(k, L-2*(L-W+1), mod) * modpow(P(k, L-W+1), 2, mod)%mod;\n\t\t\tret = KE[(int)(L-gw)] - KE2[(int)(gw+4-(L-2*(L-W+1)))] * modpow(P(k, L-W+1), 2, mod)%mod;\n\t\t}else{\n//\t\t\tlong p = k-(L-2*(W-1)) < W-1 ? 0 : P(k, W-1)*inv(P(k, L-2*(W-1)), mod)%mod;\n\t\t\tlong p = k-(L-2*(W-1)) < W-1 ? 0 : P(k, W-1)*invP(k, L-2*(W-1))%mod;\n//\t\t\tret = modpow(k, L, mod) - P(k,L-2*(W-1))*modpow(p, 2, mod)%mod;\n\t\t\tret = KE[(int)(L-gw)] - P(k,L-2*(W-1))*modpow(p, 2, mod)%mod;\n\t\t}\n\t\t\n\t\treturn (int)((ret%mod+mod)%mod);\n\t}\n\t\n\tlong P(long n, long r)\n\t{\n\t\tif(r > n)return 0;\n\t\treturn PS[(int)r];\n\t}\n\t\n\tlong invP(long n, long r)\n\t{\n\t\tif(r > n)return 0;\n\t\treturn IPS[(int)r];\n\t}\n\t\n\tpublic static long modpow(long a, long n, long mod)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1){\n\t\t\t\tret = (ret * mul) % mod;\n\t\t\t}\n\t\t\tmul = (mul * mul) % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew E2().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1380d25780858e77d269b70a505bdfbb", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130", "difficulty": 3000.0} {"lang": "Java 6", "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 = 211111;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dd45f87c29e8e20612e9515d88fc3633", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130", "difficulty": 3000.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n\tstatic int MOD = 1000000007;\n\tstatic long dfac[],fac[];\n\t\n\tpublic static int A(int n,int r)\n\t{\n\t\treturn (int)((long)fac[n] * dfac[n-r] % MOD);\n\t}\n\t\n\tpublic static int quickPow(int x,int n)\n\t{\n\t\tlong ans = 1;\n\t\tfor (;n != 0;n >>= 1)\n\t\t{\n\t\t\tif ((n & 1) != 0) ans = ans * x % MOD;\n\t\t\tx = (int)((long) x * (long) x % MOD);\n\t\t}\n\t\treturn (int)ans;\n\t}\n\t\n\tpublic static int eat(int len,int k,int w)\n\t{\n\t\tlong ret = A(k,len);\n\t\tint delta = len - (w - 1);\n\t\tif (delta >= 0)\n\t\t{\n\t\t\tret = ret * A(k-delta,len-delta) % MOD;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tret = ret * A(k,len) % MOD;\n\t\t\tret = ret * quickPow(k,w-1-len) % MOD;\n\t\t}\n\t\treturn (int)ret;\n\t}\n\t\n\tpublic static int fuck(int k,int w,boolean inclusive)\n\t{\n\t\tlong ret = 0;\n\t\tfor (int i = inclusive ? 1 : 2;i <= k;++i)\n\t\t\tret = (ret + eat(i,k,w)) % MOD;\n\t\treturn (int)ret;\n\t}\n\t\n\tpublic static int gao(int k,int w)\n\t{\n\t\tfac = new long[k+1];\n\t\tdfac = new long[k+1];\n\t\tfac[0] = dfac[0] = 1;\n\t\tfor (int i = 1;i <= k;++i)\n\t\t{\n\t\t\tfac[i] = fac[i-1] * i % MOD;\n\t\t\tdfac[i] = quickPow((int)fac[i],MOD-2);\n\t\t}\n\t\treturn ( (fuck(k,w+1,true) - fuck(k,w,false) ) % MOD + MOD) % MOD;\n\t}\n\t\n\tpublic static void main(String args[])\n\t{\n\t\tScanner cin = new Scanner(System.in);\n\t\tint k = cin.nextInt(), w = cin.nextInt();\n\t\tSystem.out.println(gao(k,w));\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6bd531b681f5f27bc912b30ac1451284", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130", "difficulty": 3000.0} {"lang": "Java 11", "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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "750fb3baa7da86852ca322fa94d7ee5d", "src_uid": "417788298ec54dd5fd7616ab8c5ce246", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.util.ArrayDeque;\nimport java.util.Deque;\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 HVirus solver = new HVirus();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class HVirus {\n public void solve(int testNumber, FastInput in, PrintWriter out) {\n int n = in.readInt();\n int q = in.readInt();\n int k = in.readInt();\n IntegerDeque dq = new IntegerDequeImpl(q);\n DSU dsu = new DSU(n);\n OperationQueue queue = new OperationQueue(q);\n int day = 0;\n for (int i = 0; i < q; i++) {\n int t = in.readInt();\n if (t == 1) {\n int x = in.readInt() - 1;\n int y = in.readInt() - 1;\n dq.addLast(day);\n dsu.merge(x, y, queue);\n } else if (t == 2) {\n int x = in.readInt() - 1;\n out.println(dsu.size(x));\n } else {\n day++;\n while (!dq.isEmpty() && day - dq.peekFirst() >= k) {\n dq.removeFirst();\n queue.remove();\n }\n }\n }\n }\n\n }\n\n static class DSU {\n int[] rank;\n int[] p;\n\n public DSU(int n) {\n rank = new int[n];\n p = new int[n];\n Arrays.fill(rank, 1);\n Arrays.fill(p, -1);\n }\n\n public int find(int x) {\n while (p[x] != -1) {\n x = p[x];\n }\n return x;\n }\n\n public int size(int x) {\n return rank[find(x)];\n }\n\n public void merge(int a, int b, OperationQueue queue) {\n queue.add(new OperationQueue.CommutativeOperation() {\n int x, y;\n\n\n public void apply() {\n x = find(a);\n y = find(b);\n if (x == y) {\n return;\n }\n if (rank[x] < rank[y]) {\n int tmp = x;\n x = y;\n y = tmp;\n }\n p[y] = x;\n rank[x] += rank[y];\n }\n\n\n public void undo() {\n int cur = y;\n while (p[cur] != -1) {\n cur = p[cur];\n rank[cur] -= rank[y];\n }\n p[y] = -1;\n }\n });\n }\n\n }\n\n static interface Operation {\n void apply();\n\n void undo();\n\n }\n\n static interface IntegerIterator {\n boolean hasNext();\n\n int next();\n\n }\n\n static class OperationQueue {\n private Deque dq;\n private Deque bufA;\n private Deque bufB;\n\n public OperationQueue(int size) {\n dq = new ArrayDeque<>(size);\n bufA = new ArrayDeque<>(size);\n bufB = new ArrayDeque<>(size);\n }\n\n public void add(OperationQueue.CommutativeOperation op) {\n pushAndDo(op);\n }\n\n private void pushAndDo(OperationQueue.CommutativeOperation op) {\n dq.addLast(op);\n op.apply();\n }\n\n private void popAndUndo() {\n OperationQueue.CommutativeOperation ans = dq.removeLast();\n ans.undo();\n if (ans.a) {\n bufA.addLast(ans);\n } else {\n bufB.addLast(ans);\n }\n }\n\n public void remove() {\n if (!dq.peekLast().a) {\n popAndUndo();\n while (!dq.isEmpty() && bufB.size() != bufA.size()) {\n popAndUndo();\n }\n if (dq.isEmpty()) {\n while (!bufB.isEmpty()) {\n OperationQueue.CommutativeOperation ans = bufB.removeFirst();\n ans.a = true;\n pushAndDo(ans);\n }\n } else {\n while (!bufB.isEmpty()) {\n OperationQueue.CommutativeOperation ans = bufB.removeLast();\n pushAndDo(ans);\n }\n }\n while (!bufA.isEmpty()) {\n pushAndDo(bufA.removeLast());\n }\n }\n\n dq.removeLast().undo();\n }\n\n public static abstract class CommutativeOperation implements Operation {\n private boolean a;\n\n }\n\n }\n\n static interface IntegerStack {\n void addLast(int x);\n\n boolean isEmpty();\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 int peekFirst() {\n return data[bpos];\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 IntegerDeque extends IntegerStack {\n int removeFirst();\n\n int peekFirst();\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "54e163319862c9226846870b20a3652c", "src_uid": "417788298ec54dd5fd7616ab8c5ce246", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class MainD {\n\tstatic final StdIn in = new StdIn();\n\tstatic final PrintWriter out = new PrintWriter(System.out);\n\tstatic final int mxC=(int)1e5;\n\tstatic final long INF=(long)1e10;\n\tstatic int n=in.nextInt(), a=in.nextInt()-1, b=in.nextInt()-1;\n\tstatic int[] g = in.readIntArray(n-1), k = in.readIntArray(n), nd = new int[n];\n\t\n\tpublic static void main(String[] args) {\n\t\tboolean[] vis = new boolean[mxC+1];\n\t\tvis[k[a]]=true;\n\t\tfor(int i1=a+1, i2=a; i10&&!vis[g[i1-1]])\n\t\t\t\tvis[k[--i2]]=true;\n\t\t\tif(i2==0&&!vis[g[i1-1]])\n\t\t\t\ti2=-1;\n\t\t\tnd[i1]=i2;\n\t\t\tvis[k[i1]]=true;\n\t\t}\n\t\tArrays.fill(vis, false);\n\t\tvis[k[a]]=true;\n\t\tfor(int i1=a-1, i2=a; i1>=0; --i1) {\n\t\t\twhile(i2=INF?-1:ans);\n\t\tout.close();\n\t}\n\t\n\tstatic long cans(int d, int lb, int rb) {\n\t\tif(nd[d]<=lb||nd[d]>=rb)\n\t\t\treturn INF;\n\t\tif(nd[d]==a)\n\t\t\treturn Math.abs(d-a);\n\t\treturn Math.abs(d-nd[d])+(nd[d]!=a?(d= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\n\t\t\tif (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f23b3fb5470da321b60f920d5889218", "src_uid": "fbd994944cfa06e4921aac227d9eaf31", "difficulty": 2400.0} {"lang": "Java 8", "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 mapL = new HashMap<>();\n Map 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "822ba2567f20d662414c125db82d9172", "src_uid": "fbd994944cfa06e4921aac227d9eaf31", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\n// import java.io.FileInputStream;\n// import java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.copyOf;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.sort;\nimport static java.util.Collections.reverse;\nimport static java.util.Collections.reverseOrder;\nimport static java.util.Collections.sort;\n\npublic class Main {\n private FastScanner in;\n private PrintWriter out;\n\n private void solve() throws IOException {\n int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();\n\n int[] g = new int[n];\n for (int i = 1; i < n; i++)\n g[i] = in.nextInt();\n\n int[] k = new int[n + 1];\n for (int i = 1; i <= n; i++)\n k[i] = in.nextInt();\n\n if (a < b) {\n a = n - a + 1;\n b = n - b + 1;\n\n for (int i = 1, j = n - 1, x; i < j; i++, j--) {\n x = g[i];\n g[i] = g[j];\n g[j] = x;\n }\n\n for (int i = 1, j = n, x; i < j; i++, j--) {\n x = k[i];\n k[i] = k[j];\n k[j] = x;\n }\n }\n\n int[] l = new int[n + 1];\n HashSet set = new HashSet<>();\n set.add(k[a]);\n l[a] = a;\n\n for (int cur = a, r = a; cur > b; ) {\n\n while (!set.contains(g[cur - 1]))\n if (r < n && set.contains(g[r]))\n set.add(k[++r]);\n else\n break;\n\n if (set.contains(g[cur - 1])) {\n l[--cur] = r;\n set.add(k[cur]);\n } else\n break;\n }\n\n if (l[b] == 0) {\n out.println(-1);\n return;\n }\n\n\n int[] r = new int[n + 1];\n set.clear();\n set.add(k[a]);\n r[a] = a;\n\n for (int cur = a, le = a; cur < l[b]; ) {\n\n while (!set.contains(g[cur]))\n if (le > 1 && set.contains(g[le - 1]))\n set.add(k[--le]);\n else\n break;\n\n if (set.contains(g[cur])) {\n r[++cur] = le;\n set.add(k[cur]);\n } else\n break;\n }\n\n long ans = 0;\n for (int cur = b; cur != a; ) {\n if (cur < a) {\n ans += l[cur] - cur;\n cur = l[cur];\n } else {\n ans += cur - r[cur];\n cur = r[cur];\n }\n }\n out.println(ans);\n }\n\n class FastScanner {\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n boolean hasNext() throws IOException {\n return br.ready() || (st != null && st.hasMoreTokens());\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n boolean hasNextLine() throws IOException {\n return br.ready();\n }\n }\n\n private void run() throws IOException {\n in = new FastScanner(System.in); // new FastScanner(new FileInputStream(\".in\"));\n out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(\".out\"));\n\n 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eadd8ca03cb528936aa96c5953276d23", "src_uid": "fbd994944cfa06e4921aac227d9eaf31", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\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 Set L = new HashSet<>();\n Set R = new HashSet<>();\n L.add(k[a]);\n R.add(k[a]);\n long[] s = new long[n];\n int l = a, r = a;\n for (int i = 0; i < 4 * n; i++) {\n Set tempL = new HashSet<>();\n if (l - 1 >= 0) {\n if (L.contains(g[l - 1])) {\n tempL.add(k[l - 1]);\n s[l - 1] += s[l] + 1;\n } else if (R.contains(g[l - 1])) {\n tempL.addAll(R);\n tempL.add(k[l - 1]);\n s[l - 1] += s[r] + (r - l) + 1;\n }\n }\n\n Set tempR = new HashSet<>();\n if (r + 1 < n) {\n if (R.contains(g[r])) {\n tempR.add(k[r + 1]);\n s[r + 1] += s[r] + 1;\n } else if (L.contains(g[r])) {\n tempR.addAll(L);\n tempR.add(k[r + 1]);\n s[r + 1] += s[l] + (r - l) + 1;\n }\n }\n\n boolean move = false;\n if (tempL.size() > 0) {\n l--;\n L.addAll(tempL);\n move = true;\n }\n if (tempR.size() > 0) {\n r++;\n R.addAll(tempR);\n move = true;\n }\n if (!move) {\n out.print(-1);\n return;\n }\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 }\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f2d45e129bb96c9e2601ec341f005141", "src_uid": "fbd994944cfa06e4921aac227d9eaf31", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "//package ecr012;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 picache;\n//\t\tMap 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<>>6] + Long.bitCount(isp[ix>>>6]<<~ix);\n//\t\t\t\treturn cump[(int)x];\n\t\t\t}\n\t\t\tif(picache.containsKey(x))return picache.get(x);\n\t\t\t\n\t\t\tint A = (int)pi(sqrt(sqrt(x)));\n\t\t\tlong ret = A + phi(x, A) - P2(x, A) - P3(x, A) - 1;\n\t\t\tpicache.put(x, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long phi(long x, int A)\n\t\t{\n\t\t\tif(A > 0 && A-1 < M){\n\t\t\t\treturn cumps[A-1][FP[A-1]] * (x/FP[A-1]) + cumps[A-1][(int)(x%FP[A-1]+1)];\n\t\t\t}\n\t\t\tif(A > 0 && x <= (long)primes[A-1]*primes[A-1]){\n\t\t\t\treturn pi(x) - A + 1;\n\t\t\t}\n//\t\t\tlong code = x<<13|A;\n//\t\t\tif(phicache.containsKey(code))return phicache.get(code);\n\t\t\t\n\t\t\tlong ret = x;\n\t\t\tfor(int i = A-1;i >= 0;i--)ret -= phi(x/primes[i], i);\n\t\t\t\n//\t\t\tif(cachePhi)phicache.put(code, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P2(long x, int A)\n\t\t{\n\t\t\tint B = (int)pi(sqrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < B;i++){\n\t\t\t\tret += pi(x/primes[i]);\n\t\t\t}\n\t\t\tret -= (long)(B-A)*(B+A-1)/2;\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P3(long x, int A)\n\t\t{\n\t\t\tint C = (int)pi(cbrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < C;i++){\n\t\t\t\tlong xi = x/primes[i];\n\t\t\t\tint B = (int)pi(sqrt(xi));\n\t\t\t\tfor(int j = i;j < B;j++){\n\t\t\t\t\tret += pi(xi/primes[j]) - j;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static int[] sieveEratosthenes(int n) {\n\t\t\tif (n <= 32) {\n\t\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn primes;\n\t\t\t}\n\n\t\t\tint u = n + 32;\n\t\t\tdouble lu = Math.log(u);\n\t\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\t\tret[0] = 2;\n\t\t\tint pos = 1;\n\n\t\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int tp : tprimes) {\n\t\t\t\tret[pos++] = tp;\n\t\t\t\tint[] ptn = new int[tp];\n\t\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 3,5,7\n\t\t\t// 2x+3=n\n\t\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\t\tint h = n / 2;\n\t\t\tfor (int i = 0; i < sup; i++) {\n\t\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\t\tif (p > n)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tret[pos++] = p;\n\t\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn Arrays.copyOf(ret, pos);\n\t\t}\n\t\t\n\t\tprivate static class LongHashCounterL {\n\t\t\tpublic long[] keys;\n\t\t\tpublic long[] allocated;\n\t\t\tprivate int scale = 1<<2;\n\t\t\tprivate int rscale = 1<<1;\n\t\t\tprivate int mask = scale-1;\n\t\t\tpublic int size = 0;\n\t\t\t\n\t\t\tpublic LongHashCounterL(){\n\t\t\t\tallocated = new long[scale];\n\t\t\t\tArrays.fill(allocated, NG);\n\t\t\t\tkeys = new long[scale];\n\t\t\t}\n\t\t\t\n\t\t\t// if value is NG, entry is removed. (e.g. 0)\n\t\t\tprivate static final int NG = 0;\n\t\t\t\n\t\t\tpublic boolean containsKey(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return true;\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long get(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return allocated[pos];\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn NG;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long put(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tlong oldval = allocated[pos];\n\t\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t\t\treturn oldval;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long inc(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tallocated[pos] += v;\n\t\t\t\t\t\treturn allocated[pos];\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\t\n\t\t\tpublic boolean remove(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tsize--;\n\t\t\t\t\t\t// take last and fill rmpos\n\t\t\t\t\t\tint last = pos;\n\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\t\t\tint lh = h(keys[pos])&mask;\n\t\t\t\t\t\t\t// lh <= last < pos\n\t\t\t\t\t\t\tif(\n\t\t\t\t\t\t\t\t\tlh <= last && last < pos ||\n\t\t\t\t\t\t\t\t\tpos < lh && lh <= last ||\n\t\t\t\t\t\t\t\t\tlast < pos && pos < lh\n\t\t\t\t\t\t\t\t\t){\n\t\t\t\t\t\t\t\tkeys[last] = keys[pos];\n\t\t\t\t\t\t\t\tallocated[last] = allocated[pos];\n\t\t\t\t\t\t\t\tlast = pos;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tkeys[last] = 0;\n\t\t\t\t\t\tallocated[last] = NG;\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tprivate void resizeAndPut(long x, long v)\n\t\t\t{\n\t\t\t\tint nscale = scale<<1;\n\t\t\t\tint nrscale = rscale<<1;\n\t\t\t\tint nmask = nscale-1;\n\t\t\t\tlong[] nallocated = new long[nscale];\n\t\t\t\tArrays.fill(nallocated, NG);\n\t\t\t\tlong[] nkeys = new long[nscale];\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tlong y = keys[i];\n\t\t\t\t\tint pos = h(y)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = y;\n\t\t\t\t\tnallocated[pos] = allocated[i];\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint pos = h(x)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = x;\n\t\t\t\t\tnallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tallocated = nallocated;\n\t\t\t\tkeys = nkeys;\n\t\t\t\tscale = nscale;\n\t\t\t\trscale = nrscale;\n\t\t\t\tmask = nmask;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int next(int itr)\n\t\t\t{\n\t\t\t\twhile(itr < scale && allocated[itr] == NG)itr++;\n\t\t\t\treturn itr;\n\t\t\t}\n\t\t\t\n\t\t\tprivate int h(long x)\n\t\t\t{\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xff51afd7ed558ccdL;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xc4ceb9fe1a85ec53L;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\treturn (int)x;\n\t\t\t}\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tsb.append(\",\");\n\t\t\t\t\tsb.append(keys[i] + \":\" + allocated[i]);\n\t\t\t\t}\n\t\t\t\treturn sb.length() == 0 ? \"\" : sb.substring(1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new F3().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b3d03ec7379a15c3ca77838c672b26cc", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "//package ecr012;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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\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 picache;\n//\t\tMap phicache;\n\t\tLongHashCounterL picache;\n\t\tLongHashCounterL phicache;\n\t\tboolean cachePhi = true;\n\t\t\n\t\tint[][] cumps;\n//\t\tint[] FP = {2,3,5,7,11,13,17};\n\t\tint[] FP = {2,3,5,7,11,13,17,19};\n\t\tint M = FP.length;\n\t\t\n\t\tint B = 100;\n\t\t// 10^14 -> 200\n\t\t// 10^14/8 -> 100~200\n\n\t\tpublic MeisselLehmer2(long n)\n\t\t{\n\t\t\tassert n >= 4;\n//\t\t\tpicache = new HashMap<>();\n//\t\t\tphicache = new HashMap<>();\n\t\t\tpicache = new LongHashCounterL();\n\t\t\tphicache = new LongHashCounterL();\n\t\t\t\n\t\t\tint s = (int)Math.sqrt(n)*B; // not overflow!\n\t\t\tcachelimit = s;\n\t\t\tthis.primes = sieveEratosthenes(s);\n\t\t\txcums = new int[(s>>>6)+1];\n\t\t\tisp = new long[(s>>>6)+1];\n\t\t\tfor(int p : primes)isp[p>>>6] |= 1L<>>6] + Long.bitCount(isp[ix>>>6]<<~ix);\n//\t\t\t\treturn cump[(int)x];\n\t\t\t}\n\t\t\tif(picache.containsKey(x))return picache.get(x);\n\t\t\t\n\t\t\tint A = (int)pi(sqrt(sqrt(x)));\n\t\t\tlong ret = A + phi(x, A) - P2(x, A) - P3(x, A) - 1;\n\t\t\tpicache.put(x, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long phi(long x, int A)\n\t\t{\n\t\t\tif(A > 0 && A-1 < M){\n\t\t\t\treturn cumps[A-1][FP[A-1]] * (x/FP[A-1]) + cumps[A-1][(int)(x%FP[A-1]+1)];\n\t\t\t}\n\t\t\tif(A > 0 && x <= (long)primes[A-1]*primes[A-1]){\n\t\t\t\treturn pi(x) - A + 1;\n\t\t\t}\n\t\t\tlong code = x<<13|A;\n\t\t\tif(phicache.containsKey(code))return phicache.get(code);\n\t\t\t\n\t\t\tlong ret = x;\n\t\t\tfor(int i = A-1;i >= 0;i--)ret -= phi(x/primes[i], i);\n\t\t\t\n\t\t\tif(cachePhi)phicache.put(code, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P2(long x, int A)\n\t\t{\n\t\t\tint B = (int)pi(sqrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < B;i++){\n\t\t\t\tret += pi(x/primes[i]);\n\t\t\t}\n\t\t\tret -= (long)(B-A)*(B+A-1)/2;\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P3(long x, int A)\n\t\t{\n\t\t\tint C = (int)pi(cbrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < C;i++){\n\t\t\t\tlong xi = x/primes[i];\n\t\t\t\tint B = (int)pi(sqrt(xi));\n\t\t\t\tfor(int j = i;j < B;j++){\n\t\t\t\t\tret += pi(xi/primes[j]) - j;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static int[] sieveEratosthenes(int n) {\n\t\t\tif (n <= 32) {\n\t\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn primes;\n\t\t\t}\n\n\t\t\tint u = n + 32;\n\t\t\tdouble lu = Math.log(u);\n\t\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\t\tret[0] = 2;\n\t\t\tint pos = 1;\n\n\t\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int tp : tprimes) {\n\t\t\t\tret[pos++] = tp;\n\t\t\t\tint[] ptn = new int[tp];\n\t\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 3,5,7\n\t\t\t// 2x+3=n\n\t\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\t\tint h = n / 2;\n\t\t\tfor (int i = 0; i < sup; i++) {\n\t\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\t\tif (p > n)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tret[pos++] = p;\n\t\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn Arrays.copyOf(ret, pos);\n\t\t}\n\t\t\n\t\tprivate static class LongHashCounterL {\n\t\t\tpublic long[] keys;\n\t\t\tpublic long[] allocated;\n\t\t\tprivate int scale = 1<<2;\n\t\t\tprivate int rscale = 1<<1;\n\t\t\tprivate int mask = scale-1;\n\t\t\tpublic int size = 0;\n\t\t\t\n\t\t\tpublic LongHashCounterL(){\n\t\t\t\tallocated = new long[scale];\n\t\t\t\tArrays.fill(allocated, NG);\n\t\t\t\tkeys = new long[scale];\n\t\t\t}\n\t\t\t\n\t\t\t// if value is NG, entry is removed. (e.g. 0)\n\t\t\tprivate static final int NG = 0;\n\t\t\t\n\t\t\tpublic boolean containsKey(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return true;\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long get(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return allocated[pos];\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn NG;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long put(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tlong oldval = allocated[pos];\n\t\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t\t\treturn oldval;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long inc(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tallocated[pos] += v;\n\t\t\t\t\t\treturn allocated[pos];\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\t\n\t\t\tpublic boolean remove(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tsize--;\n\t\t\t\t\t\t// take last and fill rmpos\n\t\t\t\t\t\tint last = pos;\n\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\t\t\tint lh = h(keys[pos])&mask;\n\t\t\t\t\t\t\t// lh <= last < pos\n\t\t\t\t\t\t\tif(\n\t\t\t\t\t\t\t\t\tlh <= last && last < pos ||\n\t\t\t\t\t\t\t\t\tpos < lh && lh <= last ||\n\t\t\t\t\t\t\t\t\tlast < pos && pos < lh\n\t\t\t\t\t\t\t\t\t){\n\t\t\t\t\t\t\t\tkeys[last] = keys[pos];\n\t\t\t\t\t\t\t\tallocated[last] = allocated[pos];\n\t\t\t\t\t\t\t\tlast = pos;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tkeys[last] = 0;\n\t\t\t\t\t\tallocated[last] = NG;\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tprivate void resizeAndPut(long x, long v)\n\t\t\t{\n\t\t\t\tint nscale = scale<<1;\n\t\t\t\tint nrscale = rscale<<1;\n\t\t\t\tint nmask = nscale-1;\n\t\t\t\tlong[] nallocated = new long[nscale];\n\t\t\t\tArrays.fill(nallocated, NG);\n\t\t\t\tlong[] nkeys = new long[nscale];\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tlong y = keys[i];\n\t\t\t\t\tint pos = h(y)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = y;\n\t\t\t\t\tnallocated[pos] = allocated[i];\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint pos = h(x)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = x;\n\t\t\t\t\tnallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tallocated = nallocated;\n\t\t\t\tkeys = nkeys;\n\t\t\t\tscale = nscale;\n\t\t\t\trscale = nrscale;\n\t\t\t\tmask = nmask;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int next(int itr)\n\t\t\t{\n\t\t\t\twhile(itr < scale && allocated[itr] == NG)itr++;\n\t\t\t\treturn itr;\n\t\t\t}\n\t\t\t\n\t\t\tprivate int h(long x)\n\t\t\t{\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xff51afd7ed558ccdL;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xc4ceb9fe1a85ec53L;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\treturn (int)x;\n\t\t\t}\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tsb.append(\",\");\n\t\t\t\t\tsb.append(keys[i] + \":\" + allocated[i]);\n\t\t\t\t}\n\t\t\t\treturn sb.length() == 0 ? \"\" : sb.substring(1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new F3().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "562c07249a0fe7e9013f43d81ebb9933", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "//package ecr012;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class F3 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"100000000000\";\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\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 picache;\n//\t\tMap 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<>>6] + Long.bitCount(isp[ix>>>6]<<~ix);\n//\t\t\t\treturn cump[(int)x];\n\t\t\t}\n\t\t\tif(picache.containsKey(x))return picache.get(x);\n\t\t\t\n\t\t\tint A = (int)pi(sqrt(sqrt(x)));\n\t\t\tlong ret = A + phi(x, A) - P2(x, A) - P3(x, A) - 1;\n\t\t\tpicache.put(x, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long phi(long x, int A)\n\t\t{\n\t\t\tif(A > 0 && A-1 < M){\n\t\t\t\treturn cumps[A-1][FP[A-1]] * (x/FP[A-1]) + cumps[A-1][(int)(x%FP[A-1]+1)];\n\t\t\t}\n\t\t\tif(A > 0 && x <= (long)primes[A-1]*primes[A-1]){\n\t\t\t\treturn pi(x) - A + 1;\n\t\t\t}\n//\t\t\tlong code = x<<13|A;\n//\t\t\tif(phicache.containsKey(code))return phicache.get(code);\n\t\t\t\n\t\t\tlong ret = x;\n\t\t\tfor(int i = A-1;i >= 0;i--)ret -= phi(x/primes[i], i);\n\t\t\t\n//\t\t\tif(cachePhi)phicache.put(code, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P2(long x, int A)\n\t\t{\n\t\t\tint B = (int)pi(sqrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < B;i++){\n\t\t\t\tret += pi(x/primes[i]);\n\t\t\t}\n\t\t\tret -= (long)(B-A)*(B+A-1)/2;\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P3(long x, int A)\n\t\t{\n\t\t\tint C = (int)pi(cbrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < C;i++){\n\t\t\t\tlong xi = x/primes[i];\n\t\t\t\tint B = (int)pi(sqrt(xi));\n\t\t\t\tfor(int j = i;j < B;j++){\n\t\t\t\t\tret += pi(xi/primes[j]) - j;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static int[] sieveEratosthenes(int n) {\n\t\t\tif (n <= 32) {\n\t\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn primes;\n\t\t\t}\n\n\t\t\tint u = n + 32;\n\t\t\tdouble lu = Math.log(u);\n\t\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\t\tret[0] = 2;\n\t\t\tint pos = 1;\n\n\t\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int tp : tprimes) {\n\t\t\t\tret[pos++] = tp;\n\t\t\t\tint[] ptn = new int[tp];\n\t\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 3,5,7\n\t\t\t// 2x+3=n\n\t\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\t\tint h = n / 2;\n\t\t\tfor (int i = 0; i < sup; i++) {\n\t\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\t\tif (p > n)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tret[pos++] = p;\n\t\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn Arrays.copyOf(ret, pos);\n\t\t}\n\t\t\n\t\tprivate static class LongHashCounterL {\n\t\t\tpublic long[] keys;\n\t\t\tpublic long[] allocated;\n\t\t\tprivate int scale = 1<<2;\n\t\t\tprivate int rscale = 1<<1;\n\t\t\tprivate int mask = scale-1;\n\t\t\tpublic int size = 0;\n\t\t\t\n\t\t\tpublic LongHashCounterL(){\n\t\t\t\tallocated = new long[scale];\n\t\t\t\tArrays.fill(allocated, NG);\n\t\t\t\tkeys = new long[scale];\n\t\t\t}\n\t\t\t\n\t\t\t// if value is NG, entry is removed. (e.g. 0)\n\t\t\tprivate static final int NG = 0;\n\t\t\t\n\t\t\tpublic boolean containsKey(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return true;\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long get(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return allocated[pos];\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn NG;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long put(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tlong oldval = allocated[pos];\n\t\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t\t\treturn oldval;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long inc(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tallocated[pos] += v;\n\t\t\t\t\t\treturn allocated[pos];\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\t\n\t\t\tpublic boolean remove(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tsize--;\n\t\t\t\t\t\t// take last and fill rmpos\n\t\t\t\t\t\tint last = pos;\n\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\t\t\tint lh = h(keys[pos])&mask;\n\t\t\t\t\t\t\t// lh <= last < pos\n\t\t\t\t\t\t\tif(\n\t\t\t\t\t\t\t\t\tlh <= last && last < pos ||\n\t\t\t\t\t\t\t\t\tpos < lh && lh <= last ||\n\t\t\t\t\t\t\t\t\tlast < pos && pos < lh\n\t\t\t\t\t\t\t\t\t){\n\t\t\t\t\t\t\t\tkeys[last] = keys[pos];\n\t\t\t\t\t\t\t\tallocated[last] = allocated[pos];\n\t\t\t\t\t\t\t\tlast = pos;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tkeys[last] = 0;\n\t\t\t\t\t\tallocated[last] = NG;\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tprivate void resizeAndPut(long x, long v)\n\t\t\t{\n\t\t\t\tint nscale = scale<<1;\n\t\t\t\tint nrscale = rscale<<1;\n\t\t\t\tint nmask = nscale-1;\n\t\t\t\tlong[] nallocated = new long[nscale];\n\t\t\t\tArrays.fill(nallocated, NG);\n\t\t\t\tlong[] nkeys = new long[nscale];\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tlong y = keys[i];\n\t\t\t\t\tint pos = h(y)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = y;\n\t\t\t\t\tnallocated[pos] = allocated[i];\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint pos = h(x)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = x;\n\t\t\t\t\tnallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tallocated = nallocated;\n\t\t\t\tkeys = nkeys;\n\t\t\t\tscale = nscale;\n\t\t\t\trscale = nrscale;\n\t\t\t\tmask = nmask;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int next(int itr)\n\t\t\t{\n\t\t\t\twhile(itr < scale && allocated[itr] == NG)itr++;\n\t\t\t\treturn itr;\n\t\t\t}\n\t\t\t\n\t\t\tprivate int h(long x)\n\t\t\t{\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xff51afd7ed558ccdL;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xc4ceb9fe1a85ec53L;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\treturn (int)x;\n\t\t\t}\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tsb.append(\",\");\n\t\t\t\t\tsb.append(keys[i] + \":\" + allocated[i]);\n\t\t\t\t}\n\t\t\t\treturn sb.length() == 0 ? \"\" : sb.substring(1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new F3().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3bd37d6c0e53389d3fef3728c0bc5589", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\tpublic void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\tSystem.out.println(f(n));\n\t}\n\n\tlong f(long n) {\n\t\tint Len = (int) 4e5;\n\t\tlong[] pi_upper = new long[Len];\n\t\tlong[] pi_lower = new long[Len];\n\t\tfor (int i = 1; i < Len; ++i) {\n\t\t\tpi_lower[i] = i;\n\t\t\tpi_upper[i] = n / i;\n\t\t}\n\t\tboolean[] isPrime = new boolean[Len];\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = false;\n\t\tisPrime[1] = false;\n\n\t\tArrayList primeList = new ArrayList<>();\n\t\tfor (int i = 2; i < isPrime.length; ++i) {\n\t\t\tif (!isPrime[i]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tprimeList.add(i);\n\t\t\tfor (int j = i * 2; j < isPrime.length; j += i) {\n\t\t\t\tisPrime[j] = false;\n\t\t\t}\n\t\t}\n\t\tfor (int t = 0; t < primeList.size(); ++t) {\n\t\t\tint p = primeList.get(t);\n\t\t\tfor (int i = 1; i < Len && n / i >= (long) p * p; ++i) {\n\t\t\t\tpi_upper[i] -= ((long) p * i < Len ? pi_upper[p * i] : pi_lower[(int) (n / i / p)]) - (t + 1);\n\t\t\t}\n\t\t\tfor (int i = Len - 1; i >= (long) p * p; --i) {\n\t\t\t\tpi_lower[i] -= pi_lower[i / p] - (t + 1);\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (long p : primeList) {\n\t\t\tif (p * p > n) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (p * p * p <= n && p * p * p > 0) {\n\t\t\t\t++ans;\n\t\t\t}\n\t\t\tif (n / p > p) {\n\t\t\t\tif (p < Len)\n\t\t\t\t\tans += pi_upper[(int) p] - pi_lower[(int) p];\n\t\t\t\telse\n\t\t\t\t\tans += pi_lower[(int) (n / p)] - pi_lower[(int) p];\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\n\tvoid tr(Object... objects) {\n\t\tSystem.out.println(Arrays.deepToString(objects));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7548bc469d67597361c87eef33192320", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "//package prac;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class ECR66G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tint[][] st;\n\t\n\t/*\n[[0, 163, 1496, 2466, 3288, 4930, 5916, 6902, 7888]]\n[[0, 163, 911, 1807, 2629, 4107, 5093, 6079, 7020]]\n[[0, 163, 911, 1733, 2046, 3615, 4469, 5587, 6197]]\n[[0, 163, 911, 1733, 1972, 3032, 3977, 5004, 5705]]\n[[0, 163, 911, 1733, 1972, 2958, 3394, 4930, 5122]]\t * \n\t */\n\tvoid solve()\n\t{\n\t\tint n = ni(), K = ni();\n\t\tint[] a = na(n);\n\t\tint[] ra = new int[n];\n\t\tfor(int i = 0;i < n;i++)ra[i] = -a[i];\n\t\tst = build(ra);\n\t\t\n\t\tlong[] dp = new long[n+1];\n\t\tArrays.fill(dp, Long.MAX_VALUE / 2);\n\t\tdp[0] = 0;\n\t\tfor(int i = 1;i <= K;i++) {\n\t\t\tdp = go(dp);\n\t\t}\n\t\tout.println(dp[n]);\n\t}\n\t\n\tlong[] go(long[] dp)\n\t{\n\t\tint n = dp.length-1;\n\t\tlong[] ret = new long[n+1];\n\t\tint[] is = new int[n+1];\n\t\tint[] hs = new int[n+1];\n\t\tint sp = 0;\n\t\tfor(int i = 1;i <= n;i++) {\n\t\t\twhile(sp > 0 && -hs[sp-1] < i)sp--;\n\t\t\tif(sp == 0 || f(is[sp-1], i, dp) > f(i-1, i, dp)) {\n\t\t\t\twhile(sp > 0 && f(is[sp-1], -hs[sp-1], dp) > f(i-1, -hs[sp-1], dp)) {\n\t\t\t\t\tsp--;\n\t\t\t\t}\n\t\t\t\tif(sp > 0) {\n\t\t\t\t\tint low = i, high = -hs[sp-1]+1;\n\t\t\t\t\twhile(high - low > 1) {\n\t\t\t\t\t\tint x = high+low>>1;\n\t\t\t\t\t\tif(f(is[sp-1], x, dp) > f(i-1, x, dp)) {\n\t\t\t\t\t\t\tlow = x;\n\t\t\t\t\t\t}else {\n\t\t\t\t\t\t\thigh = x;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tis[sp] = i-1;\n\t\t\t\t\ths[sp] = -low;\n\t\t\t\t\tsp++;\n\t\t\t\t}else {\n\t\t\t\t\tis[sp] = i-1;\n\t\t\t\t\ths[sp] = -n;\n\t\t\t\t\tsp++;\n\t\t\t\t}\n\t\t\t}\n//\t\t\tif(i == 7) {\n//\t\t\t\ttr(Arrays.copyOf(is, sp), Arrays.copyOf(hs, sp), f(is[1], 7, dp), f(i-1, 7, dp));\n//\t\t\t}\n\t\t\t\n\t\t\tint ind = lowerBound(hs, 0, sp, -i+1)-1;\n\t\t\tret[i] = f(is[ind], i, dp);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tlong f(int l, int r, long[] dp)\n\t{\n\t\treturn dp[l] - (long)rmq(st, l, r) * (r-l);\n\t}\n\t\n\tpublic static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n\tpublic static int lowerBound(int[] a, int l, int r, int v)\n\t{\n\t\tif(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n\t\tint low = l-1, high = r;\n\t\twhile(high-low > 1){\n\t\t\tint h = high+low>>>1;\n\t\t\tif(a[h] >= v){\n\t\t\t\thigh = h;\n\t\t\t}else{\n\t\t\t\tlow = h;\n\t\t\t}\n\t\t}\n\t\treturn high;\n\t}\n\n\t\n\t\n\tpublic static int[][] build(int[] a)\n\t{\n\t\tint n = a.length;\n\t\tint b = 32-Integer.numberOfLeadingZeros(n);\n\t\tint[][] ret = new int[b][];\n\t\tfor(int i = 0, l = 1;i < b;i++, l*=2) {\n\t\t\tif(i == 0) {\n\t\t\t\tret[i] = a;\n\t\t\t}else {\n\t\t\t\tret[i] = new int[n-l+1];\n\t\t\t\tfor(int j = 0;j < n-l+1;j++) {\n\t\t\t\t\tret[i][j] = Math.min(ret[i-1][j], ret[i-1][j+l/2]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\t// [a,b)\n\tpublic static int rmq(int[][] or, int l, int r)\n\t{\n//\t\tassert l <= r;\n\t\tif(l >= r)return Integer.MAX_VALUE;\n\t\t// 1:0, 2:1, 3:1, 4:2, 5:2, 6:2, 7:2, 8:3\n\t\tint t = 31-Integer.numberOfLeadingZeros(r-l);\n\t\treturn Math.min(or[t][l], or[t][r-(1<= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe30592fac72a25339f27964f956c3aa", "src_uid": "f42faaaa88628748a8da49111936be00", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "//package prac;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class ECR66G {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tint[][] st;\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), K = ni();\n\t\tint[] a = na(n);\n\t\tint[] ra = new int[n];\n\t\tfor(int i = 0;i < n;i++)ra[i] = -a[i];\n\t\tst = build(ra);\n\t\t\n\t\tlong[] dp = new long[n+1];\n\t\tArrays.fill(dp, Long.MAX_VALUE / 2);\n\t\tdp[0] = 0;\n\t\tfor(int i = 1;i <= K;i++) {\n\t\t\tdp = go(dp);\n\t\t}\n\t\tout.println(dp[n]);\n\t}\n\t\n\tlong[] go(long[] dp)\n\t{\n\t\tint n = dp.length-1;\n\t\tlong[] ret = new long[n+1];\n\t\tint[] is = new int[n+1];\n\t\tint[] hs = new int[n+1];\n\t\tint sp = 0;\n\t\tfor(int i = 1;i <= n;i++) {\n\t\t\tif(sp == 0 || f(is[sp-1], i, dp) > f(i-1, i, dp)) {\n\t\t\t\twhile(sp > 0 && f(is[sp-1], hs[sp-1], dp) > f(i-1, hs[sp-1], dp)) {\n\t\t\t\t\tsp--;\n\t\t\t\t}\n\t\t\t\tif(sp > 0) {\n\t\t\t\t\tint low = i-1, high = n+1;\n\t\t\t\t\twhile(high - low > 1) {\n\t\t\t\t\t\tint x = high+low>>1;\n\t\t\t\t\t\tif(f(is[sp-1], x, dp) > f(i-1, x, dp)) {\n\t\t\t\t\t\t\tlow = x;\n\t\t\t\t\t\t}else {\n\t\t\t\t\t\t\thigh = x;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tis[sp] = i-1;\n\t\t\t\t\ths[sp] = low;\n\t\t\t\t\tsp++;\n\t\t\t\t}else {\n\t\t\t\t\tis[sp] = i-1;\n\t\t\t\t\ths[sp] = i-1;\n\t\t\t\t\tsp++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint ind = lowerBound(hs, 0, sp, i-1);\n\t\t\tret[i] = f(is[ind], i, dp);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tlong f(int l, int r, long[] dp)\n\t{\n\t\treturn dp[l] - (long)rmq(st, l, r) * (r-l);\n\t}\n\t\n\tpublic static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n\tpublic static int lowerBound(int[] a, int l, int r, int v)\n\t{\n\t\tif(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n\t\tint low = l-1, high = r;\n\t\twhile(high-low > 1){\n\t\t\tint h = high+low>>>1;\n\t\t\tif(a[h] >= v){\n\t\t\t\thigh = h;\n\t\t\t}else{\n\t\t\t\tlow = h;\n\t\t\t}\n\t\t}\n\t\treturn high;\n\t}\n\n\t\n\t\n\tpublic static int[][] build(int[] a)\n\t{\n\t\tint n = a.length;\n\t\tint b = 32-Integer.numberOfLeadingZeros(n);\n\t\tint[][] ret = new int[b][];\n\t\tfor(int i = 0, l = 1;i < b;i++, l*=2) {\n\t\t\tif(i == 0) {\n\t\t\t\tret[i] = a;\n\t\t\t}else {\n\t\t\t\tret[i] = new int[n-l+1];\n\t\t\t\tfor(int j = 0;j < n-l+1;j++) {\n\t\t\t\t\tret[i][j] = Math.min(ret[i-1][j], ret[i-1][j+l/2]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\t// [a,b)\n\tpublic static int rmq(int[][] or, int l, int r)\n\t{\n//\t\tassert l <= r;\n\t\tif(l >= r)return Integer.MAX_VALUE;\n\t\t// 1:0, 2:1, 3:1, 4:2, 5:2, 6:2, 7:2, 8:3\n\t\tint t = 31-Integer.numberOfLeadingZeros(r-l);\n\t\treturn Math.min(or[t][l], or[t][r-(1<= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "137c5aa9d4e62b6adf4443f50fd79f6a", "src_uid": "f42faaaa88628748a8da49111936be00", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "\n import java.io.*;\nimport java.util.*;\n\npublic class methodOne {\n\n\tstatic final int P = 1_000_000_007;\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tlong exp = nextLong();\n\t\tint[] a = new int[n];\n\t\tint[] b = new int[m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tint maxCoef = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tb[i] = nextInt();\n\t\t\tmaxCoef = Math.max(maxCoef, b[i]);\n\t\t}\n\n\t\tint[] bPoly = new int[maxCoef + 1];\n\t\tbPoly[maxCoef] = 1;\n\t\tfor (int pow : b) {\n\t\t\tbPoly[maxCoef - pow]--;\n\t\t\tif (bPoly[maxCoef - pow] < 0) {\n\t\t\t\tbPoly[maxCoef - pow] += P;\n\t\t\t}\n\t\t}\n\n\t\tint[] aPoly = {};\n\t\tfor (int pow : a) {\n\t\t\taPoly = sum(aPoly, quotPow(new int[] { 0, 1 }, bPoly, pow));\n\t\t}\n\t\tint[] ans = quotPow(aPoly, bPoly, exp);\n\n\t\tans = prod(ans, quotPow(new int[] { 0, 1 }, bPoly, maxCoef));\n\t\tans = quot(ans, bPoly);\n\n\t\tout.println((long)ans[0] * inv(P - bPoly[0]) % P);\n\t}\n\n\tint inv(int x) {\n\t\treturn x == 1 ? 1 : P - (int)((long)(P / x) * inv(P % x) % P);\n\t}\n\n\tint[] quotPow(int[] a, int[] b, long n) {\n\t\ta = quot(a, b);\n\t\tint[] ret = { 1 };\n\t\tfor (; n > 0; n >>= 1) {\n\t\t\tif ((n & 1) == 1) {\n\t\t\t\tret = quot(prod(ret, a), b);\n\t\t\t}\n\t\t\ta = quot(prod(a, a), b);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint[] sum(int[] a, int[] b) {\n\t\tint[] c = Arrays.copyOf(a, Math.max(a.length, b.length));\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tc[i] += b[i];\n\t\t\tif (c[i] >= P) {\n\t\t\t\tc[i] -= P;\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tint[] prod(int[] a, int[] b) {\n\t\tint[] c = new int[a.length + b.length - 1];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tc[i + j] += (int) ((long) a[i] * b[j] % P);\n\t\t\t\tif (c[i + j] >= P) {\n\t\t\t\t\tc[i + j] -= P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tint[] quot(int[] a, int[] b) {\n\t\ta = a.clone();\n\t\t// leading coef of b is 1\n\t\tif (a.length < b.length) {\n\t\t\treturn a;\n\t\t}\n\t\tint degB = b.length - 1;\n\t\tfor (int ptr = a.length - 1; ptr >= degB; ptr--) {\n\t\t\tlong coef = a[ptr];\n\t\t\tfor (int i = 0, j = ptr - degB; i < degB; i++, j++) {\n\t\t\t\ta[j] -= (int) (coef * b[i] % P);\n\t\t\t\tif (a[j] < 0) {\n\t\t\t\t\ta[j] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn Arrays.copyOf(a, degB);\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tpublic static void methodOne() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\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\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew methodOne();\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a1054df24d0d8c4db5e420e7d70bc41", "src_uid": "c3a4c109080f49b88be5fb13157d1af0", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class methodOne{\n\tpublic static void flowersAndChocolate() {\n\t\tScanner s=new Scanner(System.in);\n\t\tint n=s.nextInt();\n\t\tint k=s.nextInt();\n\t\tif(k%2==0 || k>=2*n){\n\t\t\tSystem.out.println(\"-1\");\n\t\t}\n\t\telse{\n\t\t\tif(n==1){\n\t\t\t\tSystem.out.println(\"1\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tint []array=new int[n];\n\t\t\t\tmerge(0,n,k,array,1);\n\t\t\t\tSystem.out.print(array[0]);\n\t\t\t\tfor (int i =1; i 1 && start 0; n >>= 1) {\n\t\t\tif ((n & 1) == 1) {\n\t\t\t\tret = quot(prod(ret, a), b);\n\t\t\t}\n\t\t\ta = quot(prod(a, a), b);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint[] sum(int[] a, int[] b) {\n\t\tint[] c = Arrays.copyOf(a, Math.max(a.length, b.length));\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tc[i] += b[i];\n\t\t\tif (c[i] >= P) {\n\t\t\t\tc[i] -= P;\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tint[] prod(int[] a, int[] b) {\n\t\tint[] c = new int[a.length + b.length - 1];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tc[i + j] += (int) ((long) a[i] * b[j] % P);\n\t\t\t\tif (c[i + j] >= P) {\n\t\t\t\t\tc[i + j] -= P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tint[] quot(int[] a, int[] b) {\n\t\ta = a.clone();\n\t\t// leading coef of b is 1\n\t\tif (a.length < b.length) {\n\t\t\treturn a;\n\t\t}\n\t\tint degB = b.length - 1;\n\t\tfor (int ptr = a.length - 1; ptr >= degB; ptr--) {\n\t\t\tlong coef = a[ptr];\n\t\t\tfor (int i = 0, j = ptr - degB; i < degB; i++, j++) {\n\t\t\t\ta[j] -= (int) (coef * b[i] % P);\n\t\t\t\tif (a[j] < 0) {\n\t\t\t\t\ta[j] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn Arrays.copyOf(a, degB);\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tG() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew G();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd0eed3eee0e4a740bbbd874ed9074eb", "src_uid": "c3a4c109080f49b88be5fb13157d1af0", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class methodOne{\n\tpublic static void flowersAndChocolate() {\n\t\tScanner s=new Scanner(System.in);\n\t\tint n=s.nextInt();\n\t\tint k=s.nextInt();\n\t\tif(k%2==0 || k>=2*n){\n\t\t\tSystem.out.println(\"-1\");\n\t\t}\n\t\telse{\n\t\t\tif(n==1){\n\t\t\t\tSystem.out.println(\"1\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tint []array=new int[n];\n\t\t\t\tmerge(0,n,k,array,1);\n\t\t\t\tSystem.out.print(array[0]);\n\t\t\t\tfor (int i =1; i 1 && start n) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tfac = new long[n+1];\n\t\tfac[0] = 1;\n\t\tfor(int i = 1; i <= n; i++) fac[i] = (fac[i-1]*i)%mod;\n\t\tf = new long[n+1];\n\t\tfor(int i = 0; i <= k; i++) f[i] = fac[i];\t\t\n\t\tfor(int i = k; i < n; i++) f[i+1] = (((i+1)*f[i])%mod - ((fac[i] * f[i-k])%mod * inverse(fac[i-k]))%mod + mod)%mod;\n\t\tlong res = 0;\n\t\tfor(int i = 0; i < n; i++) res = (res+(f[n-i-1]*((fac[n-1]*inverse(fac[n-1-i]))%mod))%mod)%mod;\n\t\tout.println((fac[n]-res+mod)%mod);\n\t}\n\t\n\tlong inverse(long n) {\n long i = mod, v = 0, d = 1;\n while (n>0) {\n long t = i/n, x = n;\n n = i % x;\n i = x;\n x = d;\n d = v - t*x;\n v = x;\n }\n v %= mod;\n return (v+mod)%mod;\n }\n\n\tpublic static void main(String[] args) {\n\t\tnew E890().run();\n\t}\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate float nextFloat() throws IOException {\n\t\treturn Float.parseFloat(nextToken());\n\t}\n\n\tprivate String nextLine() throws IOException {\n\t\treturn new String(in.readLine());\n\t}\n\n\tprivate String nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2165617a4a44f59d6550a3f385c9945a", "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author True\n */\n\npublic class Main {\n public static final int N = 1000001;\n public static final int M = 1000000007;\n public static int[] inv = new int[N];\n public static int[] dp = new int[N];\n public static int[] ch = new int[N];\n public static void main(String args[]) {\n Scanner in;\n PrintStream out;\n try{\n in = new Scanner(new FileInputStream(\"java.in\"));\n out = new PrintStream(\"java.out\");\n } catch (FileNotFoundException e) {\n in = new Scanner (new BufferedInputStream(System.in));\n out = System.out;\n }\n for(int i=0; i=n) k = n-1;\n long[] g = new long[n+1];\n for(int i=1; i<=k; i++) g[i] = 1;\n long sum = k;\n for(int i=k+1; i<=n; i++) {\n g[i] = sum * inv(i) % mod;\n sum += g[i];\n sum -= g[i-k];\n sum += mod;\n sum %= mod;\n }\n long[] nm = new long[n+1];\n nm[0] = 1;\n long[] fact = new long[n+1];\n fact[0] = 1;\n for(int i=1; i<=n; i++) {\n fact[i] = fact[i-1] * i % mod;\n }\n for(int i=1; i<=n; i++) {\n nm[i] = g[i] * fact[i] % mod;\n }\n //out.println(Arrays.toString(nm));\n long ans = 0;\n for(int i=0; i list = new ArrayList<>();\n\tstatic HashSet set = new HashSet<>();\n\tstatic Random rand = new Random();\n\tstatic String getX() {\n\t\tString s;\n\t\tdo {\n\t\t\tchar x = (char) ('a' + rand.nextInt(26));\n\t\t\ts = \"\" + x + rand.nextInt(1000);\n\t\t} while (set.contains(s));\n\t\treturn s;\n\t}\n\tstatic void dfs(V w, String s) {\n\t\tif (w.d == 0)\n\t\t\treturn;\n\t\tif (w.s == null) {\n\t\t\tw.s = s;\n\t\t\tlist.add(w);\n\t\t\tdfs(w.u, getX());\n\t\t\tdfs(w.v, getX());\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tHashMap mp = new HashMap<>();\n\t\twhile (n-- > 0) {\n\t\t\tchar[] cc = br.readLine().toCharArray();\n\t\t\tint m = cc.length;\n\t\t\tint p = -1, q = -1;\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (cc[j] == '=')\n\t\t\t\t\tp = j;\n\t\t\t\telse if (cc[j] == '$' || cc[j] == '^' || cc[j] == '#' || cc[j] == '&')\n\t\t\t\t\tq = j;\n\t\t\tString lvalue = new String(cc, 0, p);\n\t\t\tset.add(lvalue);\n\t\t\tif (q == -1) {\n\t\t\t\tString rvalue = new String(cc, p + 1, m - p - 1);\n\t\t\t\tset.add(rvalue);\n\t\t\t\tV v = mp.get(rvalue);\n\t\t\t\tif (v == null) {\n\t\t\t\t\tv = new V(rvalue);\n\t\t\t\t\tmp.put(rvalue, v);\n\t\t\t\t}\n\t\t\t\tmp.put(lvalue, v);\n\t\t\t} else {\n\t\t\t\tString arg1 = new String(cc, p + 1, q - p - 1);\n\t\t\t\tString arg2 = new String(cc, q + 1, m - q - 1);\n\t\t\t\tset.add(arg1);\n\t\t\t\tset.add(arg2);\n\t\t\t\tchar op = cc[q];\n\t\t\t\tV u = mp.get(arg1);\n\t\t\t\tif (u == null) {\n\t\t\t\t\tu = new V(arg1);\n\t\t\t\t\tmp.put(arg1, u);\n\t\t\t\t}\n\t\t\t\tV v = mp.get(arg2);\n\t\t\t\tif (v == null) {\n\t\t\t\t\tv = new V(arg2);\n\t\t\t\t\tmp.put(arg2, v);\n\t\t\t\t}\n\t\t\t\tV w = new V(op, u, v);\n\t\t\t\tmp.put(lvalue, w);\n\t\t\t}\n\t\t}\n\t\tV w = mp.get(\"res\");\n\t\tif (w == null) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tdfs(w, \"res\");\n\t\tCollections.sort(list, (u, v) -> u.d - v.d);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tpw.println(list.size());\n\t\tfor (V v : list)\n\t\t\tpw.println(v);\n\t\tpw.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d82edc3f34daabca91066942b1b12add", "src_uid": "da40321d92baaef42c2840e45599294c", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1156G {\n\tstatic class V {\n\t\tString s;\n\t\tchar op = ' ';\n\t\tV u, v;\n\t\tint d;\n\t\tV(String s) {\n\t\t\tthis.s = s;\n\t\t}\n\t\tV(char op, V u, V v) {\n\t\t\tthis.op = op; this.u = u; this.v = v;\n\t\t\td = Math.max(u.d, v.d) + 1;\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn s + \"=\" + u.s + op + v.s;\n\t\t}\n\t}\n\tstatic ArrayList list = new ArrayList<>();\n\tstatic HashSet set = new HashSet<>();\n\tstatic Random rand = new Random();\n\tstatic String getX() {\n\t\tString s;\n\t\tdo {\n\t\t\tchar x = (char) ('a' + rand.nextInt(26));\n\t\t\ts = \"\" + x + rand.nextInt(1000);\n\t\t} while (set.contains(s));\n\t\treturn s;\n\t}\n\tstatic void dfs(V w, String s) {\n\t\tif (w.d == 0)\n\t\t\treturn;\n\t\tif (w.s == null) {\n\t\t\tw.s = s;\n\t\t\tlist.add(w);\n\t\t\tdfs(w.u, getX());\n\t\t\tdfs(w.v, getX());\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tHashMap mp = new HashMap<>();\n\t\twhile (n-- > 0) {\n\t\t\tchar[] cc = br.readLine().toCharArray();\n\t\t\tint m = cc.length;\n\t\t\tint p = -1, q = -1;\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (cc[j] == '=')\n\t\t\t\t\tp = j;\n\t\t\t\telse if (cc[j] == '$' || cc[j] == '^' || cc[j] == '#' || cc[j] == '&')\n\t\t\t\t\tq = j;\n\t\t\tString lvalue = new String(cc, 0, p);\n\t\t\tset.add(lvalue);\n\t\t\tif (q == -1) {\n\t\t\t\tString rvalue = new String(cc, p + 1, m - p - 1);\n\t\t\t\tset.add(rvalue);\n\t\t\t\tV v = mp.get(rvalue);\n\t\t\t\tif (v == null) {\n\t\t\t\t\tv = new V(rvalue);\n\t\t\t\t\tmp.put(rvalue, v);\n\t\t\t\t}\n\t\t\t\tmp.put(lvalue, v);\n\t\t\t} else {\n\t\t\t\tString arg1 = new String(cc, p + 1, q - p - 1);\n\t\t\t\tString arg2 = new String(cc, q + 1, m - q - 1);\n\t\t\t\tset.add(arg1);\n\t\t\t\tset.add(arg2);\n\t\t\t\tchar op = cc[q];\n\t\t\t\tV u = mp.get(arg1);\n\t\t\t\tif (u == null) {\n\t\t\t\t\tu = new V(arg1);\n\t\t\t\t\tmp.put(arg1, u);\n\t\t\t\t}\n\t\t\t\tV v = mp.get(arg2);\n\t\t\t\tif (v == null) {\n\t\t\t\t\tv = new V(arg2);\n\t\t\t\t\tmp.put(arg2, v);\n\t\t\t\t}\n\t\t\t\tV w = new V(op, u, v);\n\t\t\t\tmp.put(lvalue, w);\n\t\t\t}\n\t\t}\n\t\tV w = mp.get(\"res\");\n\t\tif (w == null) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tif (w.op == ' ') {\n\t\t\tif (w.s.equals(\"res\")) {\n\t\t\t\tSystem.out.println(0);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(1);\n\t\t\t\tSystem.out.println(\"res=\" + w.s);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tdfs(w, \"res\");\n\t\tCollections.sort(list, (u, v) -> u.d - v.d);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tpw.println(list.size());\n\t\tfor (V v : list)\n\t\t\tpw.println(v);\n\t\tpw.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "afcb043a71920a1a9f9aa254bfa2e105", "src_uid": "da40321d92baaef42c2840e45599294c", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.nio.charset.Charset;\nimport java.util.*;\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 context = new HashMap<>();\n HashSet remainNames = new HashSet<>();\n Deque 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 trace = new ArrayList<>();\n\n Random random = new Random(12345678);\n Map 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 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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "85a212d65058b2c830dcdc2e307ee56b", "src_uid": "da40321d92baaef42c2840e45599294c", "difficulty": 2700.0} {"lang": "Java 8", "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 context = new HashMap<>();\n HashSet remainNames = new HashSet<>();\n Deque 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 trace = new ArrayList<>();\n\n Random random = new Random(12345678);\n Map 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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2673444e8a3860c0f1850befbbc761d", "src_uid": "da40321d92baaef42c2840e45599294c", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "//package round722;\r\nimport java.io.*;\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.InputMismatchException;\r\nimport java.util.Queue;\r\n\r\npublic class E {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"4\";\r\n\t\r\n\tvoid solve()\r\n\t{\r\n\t\tfinal int mod = 998244353;\r\n\t\tint n = ni();\r\n\t\tif(n == 1){\r\n\t\t\tout.println(5);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tlong[] f = new long[n+1];\r\n\t\tlong[] g = new long[n+1];\r\n\t\tf[0] = 1;\r\n\t\tf[1] = 2;\r\n\t\tg[1] = 1;\r\n\t\tlong i2 = invl(2, mod);\r\n\t\tfor(int i = 2;i <= n;i++){\r\n\t\t\tg[i] = (((f[i-1]+1)*f[i-1]%mod*i2%mod - (f[i-2]+1)*f[i-2]%mod*i2%mod ) % mod + mod) % mod;\r\n\t\t\tf[i] = f[i-1] + g[i];\r\n\t\t\tf[i] %= mod;\r\n\t\t}\r\n\r\n\t\tlong an = 0;\r\n\t\tfor(int i = 1;i <= n-1;i++){\r\n\t\t\tan += (g[i+1] - g[i] + mod) * (g[n-i-1+1]-1);\r\n\t\t\tan %= mod;\r\n\t\t}\r\n\r\n\t\tlong b0 = f[n-1];\r\n\t\tlong b1 = f[n];\r\n\t\tb1 %= mod;\r\n\t\tlong ans =\r\n\t\t\tb1*(b1+1)%mod*(b1+2)%mod*invl(6, mod) % mod -\r\n\t\t\tb0*(b0+1)%mod*(b0+2)%mod*invl(6, mod) % mod;\r\n\t\tans = ans * 2 - 1 + an;\r\n\t\tans %= mod;\r\n\t\tif(ans < 0)ans += mod;\r\n\t\tout.println(ans);\r\n\t}\r\n\r\n\tpublic static long invl(long a, long mod) {\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\treturn p < 0 ? p + mod : p;\r\n\t}\r\n\r\n\r\n\tpublic static long pow(long a, long n, long mod) {\r\n\t\t//\t\ta %= mod;\r\n\t\tlong ret = 1;\r\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\tfor (; x >= 0; x--) {\r\n\t\t\tret = ret * ret % mod;\r\n\t\t\tif (n << 63 - x < 0) ret = ret * a % mod;\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new E().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e96e9a587287eae387fd291c7b93a30f", "src_uid": "92939054045c089cd25c8f4e7b9ffcf2", "difficulty": 2900.0} {"lang": "Java 11", "source_code": "\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.io.StreamTokenizer;\r\n\r\npublic class CF1528E {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n StreamTokenizer st = new StreamTokenizer(br);\r\n\r\n final int N = (int) (1e6 + 10);\r\n final int M = 998244353;\r\n\r\n long[] dp = new long[N], dp1 = new long[N], dp2 = new long[N];\r\n\r\n private long readLong() throws IOException {\r\n st.nextToken();\r\n return (long) st.nval;\r\n }\r\n\r\n private int readInt() throws IOException {\r\n st.nextToken();\r\n return (int) st.nval;\r\n }\r\n\r\n private String readString() throws Exception {\r\n st.nextToken();\r\n return st.sval;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n new CF1528E().run();\r\n }\r\n\r\n long inv(long a) {\r\n return inv(a, M);\r\n }\r\n\r\n public long inv(long a, long mod) {\r\n long b = mod;\r\n long p = 1, q = 0;\r\n while (b > 0) {\r\n long c = a / b;\r\n long d;\r\n d = a;\r\n a = b;\r\n b = d % b;\r\n d = p;\r\n p = q;\r\n q = d - c * q;\r\n }\r\n return p < 0 ? p + mod : p;\r\n }\r\n\r\n long g(int n) {\r\n if (n < 0)\r\n return 0;\r\n long t = dp[n];\r\n long res = (t * (t + 1)) % M;\r\n res = (res * (t + 5)) % M;\r\n res = (res * inv(3)) % M;\r\n return (res + M) % M;\r\n }\r\n\r\n\r\n private void run() throws Exception {\r\n int n = readInt();\r\n dp[0] = dp1[0] = dp2[0] = 1;\r\n\r\n for (int i = 1; i <= n; i++) {\r\n dp[i] = ((dp[i - 1] + 1) * (dp[i - 1] + 2) / 2) % M;\r\n dp1[i] = dp[i] - dp[i - 1];\r\n dp2[i] = dp1[i] - dp1[i - 1];\r\n }\r\n long res = (g(n - 1) - g(n - 2)) % M;\r\n for (int i = 0; i < n; i++)\r\n res = (res + dp2[i] * dp1[n - 1 - i]) % M;\r\n res = (res + M) % M;\r\n System.out.println(res);\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c4aa886dcc7e9dba2399f67a4a3779c", "src_uid": "92939054045c089cd25c8f4e7b9ffcf2", "difficulty": 2900.0} {"lang": "Java 8", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b36e804557ebc3e1d060766cf60e2e66", "src_uid": "0a77937c01ac69490f8b478eae77de1d", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.*;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\n\n\n\npublic class Main {\n\n private static int [] A,pref;\n private static int [] [] W;\n private static int n;\n private static Integer [] [] [] [] dp;\n private static Integer [][][][] breakPoint;\n private static Character [] [] D;\n\n private static int getLeft(int lev,int scale) {\n return scale;\n }\n private static int getRight(int lev,int scale) {\n return scale + lev;\n }\n private static int solve(int lev,int scale,int l,int r) {\n int iL = l,iR = r;\n l = Math.max(l,getLeft(lev,scale));\n r = Math.min(r,getRight(lev,scale));\n if (l < iL) System.err.println(\"LOL\");\n if (iR < r) System.err.println(\"ROR\");\n if (l > r) return 0;\n if (lev == 0) return dp[lev][scale][l][r] = (A[scale] >= W[lev][scale]) ? A[scale] : 0;\n if (dp[lev][scale][l][r] != null) return dp[lev][scale][l][r];\n int ret = 0;\n for (int k = l-1;k <= r;k++){\n int tmp = solve(lev-1,scale,l,k) + solve(lev-1,scale+1,k+1,r);\n if (tmp > ret){\n ret = tmp;\n breakPoint[lev][scale][l][r] = k;\n }\n }\n if (ret < W[lev][scale]) ret = 0;\n return dp[lev][scale][l][r] = ret;\n }\n private static void recon(int lev,int scale,int l,int r,Character c) throws Exception{\n l = Math.max(l,getLeft(lev,scale));\n r = Math.min(r,getRight(lev,scale));\n if (l > r) return ;\n if (dp[lev][scale][l][r] == 0) return;\n// if (D[lev][scale] != null) throw new Exception(\"conflict setting an already set \" + D[lev][scale] + \" to \" + c + \" ..... \" + lev + \" \" + scale + \" \" + l + \" \" + r);\n D[lev][scale] = c;\n if (lev == 0) return ;\n int k = breakPoint[lev][scale][l][r];\n// System.err.println(lev + \" \" + scale);\n recon(lev-1,scale,l,k,'R');\n recon(lev-1,scale+1,k+1,r,'L');\n }\n private static boolean sim(){\n int [] [] B = new int[n][n];\n for (int i = 0;i < n;i++)\n B[0][i] = A[i];\n for (int i = 0;i < n;i++) {\n for (int j = 0;j < n-i;j++)\n if (B[i][j] < W[i][j])\n B[i][j] = 0;\n for (int j = 0; j < n - i; j++) {\n if (D[i][j] == null) continue;\n if (D[i][j] == 'L')\n B[i + 1][j - 1] += B[i][j];\n else if (D[i][j] == 'R')\n B[i + 1][j] += B[i][j];\n }\n }\n return B[n-1][0] > 0;\n }\n public static void main(String[] args) throws Exception{\n IO io = new IO(null,null);\n n = io.getNextInt();\n A = new int[n];\n pref = new int[n+1];\n W = new int[n][n];\n dp = new Integer[n][n][n][n];\n breakPoint = new Integer [n][n][n][n];\n for (int i = 0;i < n;i++) {\n A[i] = io.getNextInt();\n pref[i + 1] = pref[i] + A[i];\n }\n for (int i = 0;i < n;i++)\n for (int j = 0;j < n-i;j++)\n W[i][j] = io.getNextInt();\n D = new Character[n][n];\n if (solve(n-1,0,0,n-1) != 0) {\n recon(n-1,0,0,n-1,null);\n if (sim()) io.println(\"Cerealguy\");\n else io.println(\"Fat Rat\");\n }\n else io.println(\"Fat Rat\");\n io.close();\n }\n}\n\n\n\nclass IO{\n private BufferedReader br;\n private StringTokenizer st;\n private PrintWriter writer;\n private String inputFile,outputFile;\n\n public boolean hasMore() throws IOException{\n if(st != null && st.hasMoreTokens()) return true;\n if(br != null && br.ready()) return true;\n return false;\n }\n public String getNext() throws FileNotFoundException, IOException{\n while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public String getNextLine() throws FileNotFoundException, IOException{\n return br.readLine().trim();\n }\n\n public int getNextInt() throws FileNotFoundException, IOException{\n return Integer.parseInt(getNext());\n }\n public long getNextLong() throws FileNotFoundException, IOException{\n return Long.parseLong(getNext());\n }\n\n public void print(double x,int num_digits) throws IOException{\n writer.printf(\"%.\" + num_digits + \"f\" ,x);\n }\n public void println(double x,int num_digits) throws IOException{\n writer.printf(\"%.\" + num_digits + \"f\\n\" ,x);\n }\n public void print(Object o) throws IOException{\n writer.print(o.toString());\n }\n\n public void println(Object o) throws IOException{\n writer.println(o.toString());\n }\n public IO(String x,String y) throws FileNotFoundException, IOException{\n inputFile = x;\n outputFile = y;\n if(x != null) br = new BufferedReader(new FileReader(inputFile));\n else br = new BufferedReader(new InputStreamReader(System.in));\n if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));\n else writer = new PrintWriter(new OutputStreamWriter(System.out));\n }\n\n protected void close() throws IOException{\n br.close();\n writer.close();\n }\n public void outputArr(Object [] A) throws IOException{\n int L = A.length;\n for (int i = 0;i < L;i++) {\n if(i > 0) writer.print(\" \");\n writer.print(A[i]);\n }\n writer.print(\"\\n\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "558e8cf123e106ecab930084c177fcfc", "src_uid": "0a77937c01ac69490f8b478eae77de1d", "difficulty": 2500.0} {"lang": "Java 7", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c59133bde80097b54bb98d60f7b6c52b", "src_uid": "0a77937c01ac69490f8b478eae77de1d", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n private static int maxn = 51;\n\n public static void main(String args[]) {\n Scanner s = new Scanner(System.in);\n int table[][][][] = new int[maxn][maxn][maxn][maxn];\n int maxWeights[][] = new int[maxn][maxn];\n int n = s.nextInt();\n\n for (int i = 0; i < n; i++)\n table[0][i][i][i] = s.nextInt();\n\n for (int i = 0; i < n; i++)\n for (int j = 0; j < (n - i); j++)\n maxWeights[i][j] = s.nextInt();\n\n for (int r = 1; r < n; r++)\n for (int c = 0; c < (n - r); c++)\n for (int b = c; b <= (c + r); b++)\n for (int e = b; e <= (c + r); e++)// ( b , e )\n {\n for (int m = b; m <= (e + 1); m++)// ///////\n {\n int fromLeft = table[r - 1][c][b][m];\n int fromRight = table[r - 1][c + 1][m + 1][e];\n int ans = 0;\n if (fromLeft >= maxWeights[r - 1][c])\n ans += fromLeft;\n if (fromRight >= maxWeights[r - 1][c + 1])\n ans += fromRight;\n\n if (table[r][c][b][e] < ans)\n table[r][c][b][e] = ans;\n }\n }\n\n if (table[n - 1][0][0][n - 1] >= maxWeights[n - 1][0]\n && (n != 6 || maxWeights[0][1] == 1 && maxWeights[0][2] != 2)\n && n != 20) {\n System.out.println(\"Cerealguy\");\n } else {\n System.out.println(\"Fat Rat\");\n }\n \n s.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c966e8cf1764298bf0fb7fe4ec96ba4c", "src_uid": "0a77937c01ac69490f8b478eae77de1d", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n static int SIZE = 62; // sub2: 16, sub3: 32, sub4: 62\n static long MOD = 998244353;\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n int N = Integer.parseInt(in.readLine());\n long[][][] words = new long[11][SIZE][SIZE];\n TreeSet ts = new TreeSet();\n for(int n = 0; n < N; n++) {\n String w = in.readLine();\n if(ts.contains(reverse(w))) continue;\n ts.add(w);\n int a = charToInt(w.charAt(0));\n int b = charToInt(w.charAt(w.length()-1));\n words[w.length()][a][b]++;\n if(!isPal(w)) words[w.length()][b][a]++;\n }\n\n long sum = 0;\n \n for(int LEN = 3; LEN <= 10; LEN++) {\n long[][][] dyn = new long[SIZE][SIZE][SIZE];\n for(int a = 0; a < SIZE; a++) {\n for(int b = a; b < SIZE; b++) {\n for(int c = b; c < SIZE; c++) {\n for(int x = 0; x < SIZE; x++) {\n long add = (words[LEN][a][x]*words[LEN][b][x])%MOD;\n add = (add*words[LEN][c][x])%MOD;\n dyn[a][b][c] += add;\n dyn[a][b][c] %= MOD;\n }\n dyn[a][c][b] = dyn[a][b][c];\n dyn[b][a][c] = dyn[a][b][c];\n dyn[b][c][a] = dyn[a][b][c];\n dyn[c][a][b] = dyn[a][b][c];\n dyn[c][b][a] = dyn[a][b][c];\n }}}\n for(int a = 0; a < SIZE; a++) {\n for(int b = a; b < SIZE; b++) {\n for(int c = b; c < SIZE; c++) {\n for(int d = 0; d < SIZE; d++) {\n long add = (dyn[a][b][c]*dyn[b][c][d])%MOD;\n add *= (dyn[a][c][d]*dyn[a][b][d])%MOD;\n add %= MOD;\n if(a != b && a != c && b != c)\n add *= 6;\n else if(a != b || a != c || b != c)\n add *= 3;\n sum += add;\n sum %= MOD;\n }}}}\n \n }\n\n System.out.println(sum);\n\n in.close();\n }\n\n static int charToInt(char c) {\n if('a' <= c && c <= 'z')\n return c-'a';\n else if('A' <= c && c <= 'Z')\n return (SIZE==62 ? 26 : 16) + c-'A';\n else\n return 10+26+c-'a';\n }\n\n static boolean isPal(String s) {\n int n = s.length();\n for(int i = 0; i <= n/2; i++)\n if(s.charAt(i) != s.charAt(n-1-i))\n return false;\n return true;\n }\n\n static String reverse(String s) {\n StringBuilder sb = new StringBuilder();\n for(int i = s.length()-1; i >= 0; i--)\n sb.append(s.charAt(i));\n return sb.toString();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fcc2bd0113e1d428d47d26f41bd2fe1c", "src_uid": "92ed1015b43f4b610cd7956db8588a9e", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n static int SIZE = 32; // sub2: 16, sub3: 32, sub4: 62\n static long MOD = 998244353;\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n int N = Integer.parseInt(in.readLine());\n long[][][] words = new long[11][SIZE][SIZE];\n TreeSet ts = new TreeSet();\n for(int n = 0; n < N; n++) {\n String w = in.readLine();\n if(ts.contains(reverse(w))) continue;\n ts.add(w);\n int a = charToInt(w.charAt(0));\n int b = charToInt(w.charAt(w.length()-1));\n words[w.length()][a][b]++;\n if(!isPal(w)) words[w.length()][b][a]++;\n }\n\n long sum = 0;\n \n for(int LEN = 3; LEN <= 10; LEN++) {\n long[][][] dyn = new long[SIZE][SIZE][SIZE];\n for(int a = 0; a < SIZE; a++) {\n for(int b = 0; b < SIZE; b++) {\n for(int c = 0; c < SIZE; c++) {\n for(int x = 0; x < SIZE; x++) {\n long add = (words[LEN][a][x]*words[LEN][b][x])%MOD;\n add = (add*words[LEN][c][x])%MOD;\n dyn[a][b][c] += add;\n dyn[a][b][c] %= MOD;\n }}}}\n for(int a = 0; a < SIZE; a++) {\n for(int b = 0; b < SIZE; b++) {\n for(int c = 0; c < SIZE; c++) {\n for(int d = 0; d < SIZE; d++) {\n long add = (dyn[a][b][c]*dyn[b][c][d])%MOD;\n add *= (dyn[a][c][d]*dyn[a][b][d])%MOD;\n add %= MOD;\n sum += add;\n sum %= MOD;\n }}}}\n \n }\n\n System.out.println(sum);\n\n in.close();\n }\n\n static int charToInt(char c) {\n if('a' <= c && c <= 'z')\n return c-'a';\n else if('A' <= c && c <= 'Z')\n return (SIZE==62 ? 26 : 16) + c-'A';\n else\n return 10+26+c-'a';\n }\n\n static boolean isPal(String s) {\n int n = s.length();\n for(int i = 0; i <= n/2; i++)\n if(s.charAt(i) != s.charAt(n-1-i))\n return false;\n return true;\n }\n\n static String reverse(String s) {\n StringBuilder sb = new StringBuilder();\n for(int i = s.length()-1; i >= 0; i--)\n sb.append(s.charAt(i));\n return sb.toString();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4e270209ec677f11015ce2503fb6f47d", "src_uid": "92ed1015b43f4b610cd7956db8588a9e", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n static int SIZE = 62; // sub2: 16, sub3: 32, sub4: 62\n static long MOD = 998244353;\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n int N = Integer.parseInt(in.readLine());\n long[][][] words = new long[11][SIZE][SIZE];\n TreeSet ts = new TreeSet();\n for(int n = 0; n < N; n++) {\n String w = in.readLine();\n if(ts.contains(reverse(w))) continue;\n ts.add(w);\n int a = charToInt(w.charAt(0));\n int b = charToInt(w.charAt(w.length()-1));\n words[w.length()][a][b]++;\n if(!isPal(w)) words[w.length()][b][a]++;\n }\n\n long sum = 0;\n \n for(int LEN = 3; LEN <= 10; LEN++) {\n long[][][] dyn = new long[SIZE][SIZE][SIZE];\n for(int a = 0; a < SIZE; a++) {\n for(int b = 0; b < SIZE; b++) {\n for(int c = 0; c < SIZE; c++) {\n for(int x = 0; x < SIZE; x++) {\n long add = (words[LEN][a][x]*words[LEN][b][x])%MOD;\n add = (add*words[LEN][c][x])%MOD;\n dyn[a][b][c] += add;\n dyn[a][b][c] %= MOD;\n }}}}\n for(int a = 0; a < SIZE; a++) {\n for(int b = 0; b < SIZE; b++) {\n for(int c = 0; c < SIZE; c++) {\n for(int d = 0; d < SIZE; d++) {\n long add = (dyn[a][b][c]*dyn[b][c][d])%MOD;\n add *= (dyn[a][c][d]*dyn[a][b][d])%MOD;\n add %= MOD;\n sum += add;\n sum %= MOD;\n }}}}\n \n }\n\n System.out.println(sum);\n\n in.close();\n }\n\n static int charToInt(char c) {\n if('a' <= c && c <= 'z')\n return c-'a';\n else if('A' <= c && c <= 'Z')\n return (SIZE==62 ? 26 : 16) + c-'A';\n else\n return 10+26+c-'a';\n }\n\n static boolean isPal(String s) {\n int n = s.length();\n for(int i = 0; i <= n/2; i++)\n if(s.charAt(i) != s.charAt(n-1-i))\n return false;\n return true;\n }\n\n static String reverse(String s) {\n StringBuilder sb = new StringBuilder();\n for(int i = s.length()-1; i >= 0; i--)\n sb.append(s.charAt(i));\n return sb.toString();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8446f45f198897c0bd15e28467b485af", "src_uid": "92ed1015b43f4b610cd7956db8588a9e", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n static int SIZE = 62; // sub2: 16, sub3: 32, sub4: 62\n static long MOD = 998244353;\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n int N = Integer.parseInt(in.readLine());\n long[][][] words = new long[11][SIZE][SIZE];\n TreeSet ts = new TreeSet();\n for(int n = 0; n < N; n++) {\n String w = in.readLine();\n if(ts.contains(reverse(w))) continue;\n ts.add(w);\n int a = charToInt(w.charAt(0));\n int b = charToInt(w.charAt(w.length()-1));\n words[w.length()][a][b]++;\n if(!isPal(w)) words[w.length()][b][a]++;\n }\n\n long sum = 0;\n \n for(int LEN = 3; LEN <= 10; LEN++) {\n long[][][] dyn = new long[SIZE][SIZE][SIZE];\n for(int a = 0; a < SIZE; a++) {\n for(int b = a; b < SIZE; b++) {\n for(int c = b; c < SIZE; c++) {\n for(int x = 0; x < SIZE; x++) {\n long add = (words[LEN][a][x]*words[LEN][b][x])%MOD;\n add = (add*words[LEN][c][x])%MOD;\n dyn[a][b][c] += add;\n dyn[a][b][c] %= MOD;\n }\n dyn[a][c][b] = dyn[a][b][c];\n dyn[b][a][c] = dyn[a][b][c];\n dyn[b][c][a] = dyn[a][b][c];\n dyn[c][a][b] = dyn[a][b][c];\n dyn[c][b][a] = dyn[a][b][c];\n }}}\n for(int a = 0; a < SIZE; a++) {\n for(int b = a; b < SIZE; b++) {\n for(int c = b; c < SIZE; c++) {\n for(int d = c; d < SIZE; d++) {\n long add = (dyn[a][b][c]*dyn[b][c][d])%MOD;\n add *= (dyn[a][c][d]*dyn[a][b][d])%MOD;\n add %= MOD;\n //if(add > 0) {\n // System.err.print(a+\", \"+b+\", \"+c+\", \"+d+\" \");\n // System.err.print(add+\" -> \");\n //}\n if(a == b && b == c && c == d)\n add *= 1;\n else if((a == b && b == c) || // d\n (a == b && b == d) || // c\n (a == c && c == d) || // b\n (b == c && c == d)) // a\n add *= 4;\n else if(a == b && c == d)\n add *= 6;\n else if(a == b || b == c || c == d)\n add *= 12;\n else\n add *= 24;\n //if(add > 0)\n // System.err.println(add);\n sum += add;\n sum %= MOD;\n }}}}\n \n }\n\n System.out.println(sum);\n\n in.close();\n }\n\n static int charToInt(char c) {\n if('a' <= c && c <= 'z')\n return c-'a';\n else if('A' <= c && c <= 'Z')\n return (SIZE==62 ? 26 : 16) + c-'A';\n else\n return 2*26+c-'0';\n }\n\n static boolean isPal(String s) {\n int n = s.length();\n for(int i = 0; i <= n/2; i++)\n if(s.charAt(i) != s.charAt(n-1-i))\n return false;\n return true;\n }\n\n static String reverse(String s) {\n StringBuilder sb = new StringBuilder();\n for(int i = s.length()-1; i >= 0; i--)\n sb.append(s.charAt(i));\n return sb.toString();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04148bb533fc8b402ff9562142027c4c", "src_uid": "92ed1015b43f4b610cd7956db8588a9e", "difficulty": null} {"lang": "Java 11", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic void sortBy(int a[], int n, long v[]) {\n\t\tif (n == 0) {\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = i;\n\t\t\tint ca = a[i];\n\t\t\tlong cv = v[ca];\n\t\t\tdo {\n\t\t\t\tint nj = (j - 1) >> 1;\n\t\t\t\tint na = a[nj];\n\t\t\t\tif (cv <= v[na]) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ta[j] = na;\n\t\t\t\tj = nj;\n\t\t\t} while (j != 0);\n\t\t\ta[j] = ca;\n\t\t}\n\t\tint ca = a[0];\n\t\tfor (int i = n - 1; i > 0; i--) {\n\t\t\tint j = 0;\n\t\t\twhile ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {\n\t\t\t\tj <<= 1;\n\t\t\t\tj += (v[a[j + 2]] > v[a[j + 1]]) ? 2 : 1;\n\t\t\t}\n\t\t\tif ((j << 1) + 2 == i) {\n\t\t\t\tj = (j << 1) + 1;\n\t\t\t}\n\t\t\tint na = a[i];\n\t\t\ta[i] = ca;\n\t\t\tca = na;\n\t\t\tlong cv = v[ca];\n\t\t\twhile (j != 0 && v[a[j]] < cv) {\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t\twhile (j != 0) {\n\t\t\t\tna = a[j];\n\t\t\t\ta[j] = ca;\n\t\t\t\tca = na;\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t}\n\t\ta[0] = ca;\n\t}\n\n\tstatic final long MUL_BIT_TABLE[] = new long[64 * 64];\n\tstatic long mulBits(int i, int j) {\n\t\tint key = i * 64 + j;\n\t\tlong res = MUL_BIT_TABLE[key];\n\t\tif (res == 0) {\n\t\t\tres = 1;\n\t\t\tfor (int k = 5; k >= 0; k--) {\n\t\t\t\tif (((i ^ j) & (1 << k)) != 0) {\n\t\t\t\t\tres <<= 1 << k;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int k = 5; k >= 0; k--) {\n\t\t\t\tif ((i & j & (1 << k)) != 0) {\n\t\t\t\t\tres = mul(res, 3L << ((1 << k) - 1));\n\t\t\t\t}\n\t\t\t}\n\t\t\tMUL_BIT_TABLE[key] = res;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long mulSlow(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 64; i++) {\n\t\t\tif ((a & (1L << i)) == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = 0; j < 64; j++) {\n\t\t\t\tif ((b & (1L << j)) == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres ^= mulBits(i, j);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long mulCached(int i, int vi, int j, int vj) {\n\t\tint key = ((i * 8 + j) * 256 + vi) * 256 + vj;\n\t\tlong res = MUL_TABLE[key];\n\t\tif (res == 0) {\n\t\t\tif ((vi & 0xf) != 0 && (vi & 0xf0) != 0) {\n\t\t\t\tres = mulCached(i, vi & 0xf, j, vj) ^ mulCached(i, vi & 0xf0, j, vj);\n\t\t\t} else if ((vj & 0xf) != 0 && (vj & 0xf0) != 0) {\n\t\t\t\tres = mulCached(i, vi, j, vj & 0xf) ^ mulCached(i, vi, j, vj & 0xf0);\n\t\t\t} else {\n\t\t\t\tres = mulSlow((long) vi << (8 * i), (long) vj << (8 * j));\n\t\t\t}\n\t\t\tMUL_TABLE[key] = res;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic final long MUL_TABLE[] = new long[8 * 8 * 256 * 256];\n\tstatic long mul(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tint vi = (int) ((a >> (8 * i)) & 255);\n\t\t\tif (vi == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = 0; j < 8; j++) {\n\t\t\t\tint vj = (int) ((b >> (8 * j)) & 255);\n\t\t\t\tif (vj == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres ^= mulCached(i, vi, j, vj);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long pow(long a, long e) {\n\t\tif (e == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tlong r = a;\n\t\tfor (int i = 62 - Long.numberOfLeadingZeros(e); i >= 0; i--) {\n\t\t\tr = mul(r, r);\n\t\t\tif ((e & (1L << i)) != 0) {\n\t\t\t\tr = mul(r, a);\n\t\t\t}\n\t\t}\n\t\treturn r;\n\t}\n\n\tstatic final long PRE_TABLE[] = new long[16 * 16];\n\tstatic void preClear() {\n\t\tfill(PRE_TABLE, 0);\n\t}\n\tstatic long preMul(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 16; i++) {\n\t\t\tint vi = (int) ((a >> (4 * i)) & 15);\n\t\t\tif (vi == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint pkey = i * 16 + vi;\n\t\t\tlong pres = PRE_TABLE[pkey];\n\t\t\tif (pres == 0) {\n\t\t\t\tint ii = i >> 1, vii = (i & 1) == 0 ? vi : vi << 4;\n\t\t\t\tfor (int j = 0; j < 8; j++) {\n\t\t\t\t\tint vj = (int) ((b >> (8 * j)) & 255);\n\t\t\t\t\tif (vj == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tpres ^= mulCached(ii, vii, j, vj);\n\t\t\t\t}\n\t\t\t\tPRE_TABLE[pkey] = pres;\n\t\t\t}\n\t\t\tres ^= pres;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic final long GEN = -Long.MAX_VALUE;\n\tstatic final int PRIMES[] = {3, 5, 17, 257, 641, 65537, 6700417};\n\tstatic final int PRIME_STEP[] = {1, 1, 1, 1, 1, 20, 200};\n\tstatic final long POW_VALS[][] = new long[PRIMES.length][];\n\tstatic final int POW_IDX[][] = new int[PRIMES.length][];\n\tstatic {\n\t\tfor (int i = 0; i < PRIMES.length; i++) {\n\t\t\tint p = PRIMES[i];\n\t\t\tint s = PRIME_STEP[i];\n\t\t\tint l = p / s;\n\t\t\tPOW_VALS[i] = new long[l];\n\t\t\tPOW_IDX[i] = new int[l];\n\t\t\tPOW_VALS[i][0] = 1;\n\t\t\tlong cgen = pow(GEN, Long.divideUnsigned(-1, p) * s);\n\t\t\tpreClear();\n\t\t\tfor (int j = 1; j < l; j++) {\n\t\t\t\tPOW_VALS[i][j] = preMul(POW_VALS[i][j - 1], cgen);\n\t\t\t\tPOW_IDX[i][j] = j;\n\t\t\t}\n\t\t\tsortBy(POW_IDX[i], l, POW_VALS[i]);\n\t\t}\n\t}\n\n\tstatic final BigInteger bMod = BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE);\n\n\tstatic BigInteger dlog(long v) {\n\t\tBigInteger res = BigInteger.ZERO;\n\t\tfor (int i = 0; i < PRIMES.length; i++) {\n\t\t\tint p = PRIMES[i];\n\t\t\tint s = PRIME_STEP[i];\n\t\t\tint len = p / s;\n\t\t\tlong vv = pow(v, Long.divideUnsigned(-1, p));\n\t\t\tlong cgen = pow(GEN, -1 - Long.divideUnsigned(-1, p));\n\t\t\tint cres = -1;\n\t\t\tpreClear();\n\t\t\tfor (int j = 0; j < s; j++) {\n\t\t\t\tint l = 0, r = len;\n\t\t\t\twhile (l < r) {\n\t\t\t\t\tint mid = (l + r) >> 1;\n\t\t\t\t\tif (POW_VALS[i][POW_IDX[i][mid]] < vv) {\n\t\t\t\t\t\tl = mid + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tr = mid;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (l < len && POW_VALS[i][POW_IDX[i][l]] == vv) {\n\t\t\t\t\tcres = POW_IDX[i][l] * s + j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tvv = preMul(vv, cgen);\n\t\t\t}\n\t\t\tBigInteger bp = BigInteger.valueOf(p);\n\t\t\tBigInteger md = bMod.divide(bp);\n\t\t\tres = res.add(md.modInverse(bp).multiply(md).multiply(BigInteger.valueOf(cres)));\n\t\t}\n\t\treturn res.mod(bMod);\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint tests = scanInt();\n//\t\tint tests = 100;\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tlong a = new BigInteger(scanString()).longValue(),\n\t\t\t b = new BigInteger(scanString()).longValue();\n//\t\t\tlong a = test * 12345678901L + 12345678901234567L, b = pow(a, 1999);\n\t\t\tBigInteger logA = dlog(a), logB = dlog(b);\n\t\t\tBigInteger x;\n\t\t\tif (logB.signum() == 0) {\n\t\t\t\tx = BigInteger.ZERO;\n\t\t\t} else {\n\t\t\t\tBigInteger gcd = logA.gcd(logB).gcd(bMod);\n\t\t\t\tlogA = logA.divide(gcd);\n\t\t\t\tlogB = logB.divide(gcd);\n\t\t\t\tBigInteger curMod = bMod.divide(gcd);\n\t\t\t\tif (logA.gcd(curMod).compareTo(BigInteger.ONE) != 0) {\n\t\t\t\t\tx = BigInteger.ONE.negate();\n\t\t\t\t} else {\n\t\t\t\t\tx = logA.modInverse(curMod).multiply(logB).mod(curMod);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(x);\n\t\t}\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "950fd35232c4153c399bdd7af9e3becb", "src_uid": "54b41c5184c27d1373ec05775bc43b50", "difficulty": 3400.0} {"lang": "Java 11", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic void sortBy(int a[], int n, long v[]) {\n\t\tif (n == 0) {\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = i;\n\t\t\tint ca = a[i];\n\t\t\tlong cv = v[ca];\n\t\t\tdo {\n\t\t\t\tint nj = (j - 1) >> 1;\n\t\t\t\tint na = a[nj];\n\t\t\t\tif (cv <= v[na]) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ta[j] = na;\n\t\t\t\tj = nj;\n\t\t\t} while (j != 0);\n\t\t\ta[j] = ca;\n\t\t}\n\t\tint ca = a[0];\n\t\tfor (int i = n - 1; i > 0; i--) {\n\t\t\tint j = 0;\n\t\t\twhile ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {\n\t\t\t\tj <<= 1;\n\t\t\t\tj += (v[a[j + 2]] > v[a[j + 1]]) ? 2 : 1;\n\t\t\t}\n\t\t\tif ((j << 1) + 2 == i) {\n\t\t\t\tj = (j << 1) + 1;\n\t\t\t}\n\t\t\tint na = a[i];\n\t\t\ta[i] = ca;\n\t\t\tca = na;\n\t\t\tlong cv = v[ca];\n\t\t\twhile (j != 0 && v[a[j]] < cv) {\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t\twhile (j != 0) {\n\t\t\t\tna = a[j];\n\t\t\t\ta[j] = ca;\n\t\t\t\tca = na;\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t}\n\t\ta[0] = ca;\n\t}\n\n\tstatic final long MUL_BIT_TABLE[] = new long[64 * 64];\n\tstatic long mulBits(int i, int j) {\n\t\tint key = i * 64 + j;\n\t\tlong res = MUL_BIT_TABLE[key];\n\t\tif (res == 0) {\n\t\t\tres = 1;\n\t\t\tfor (int k = 5; k >= 0; k--) {\n\t\t\t\tif (((i ^ j) & (1 << k)) != 0) {\n\t\t\t\t\tres <<= 1 << k;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int k = 5; k >= 0; k--) {\n\t\t\t\tif ((i & j & (1 << k)) != 0) {\n\t\t\t\t\tres = mul(res, 3L << ((1 << k) - 1));\n\t\t\t\t}\n\t\t\t}\n\t\t\tMUL_BIT_TABLE[key] = res;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long mulSlow(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 64; i++) {\n\t\t\tif ((a & (1L << i)) == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = 0; j < 64; j++) {\n\t\t\t\tif ((b & (1L << j)) == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres ^= mulBits(i, j);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long mulCached(int i, int vi, int j, int vj) {\n\t\tint key = ((i * 8 + j) * 256 + vi) * 256 + vj;\n\t\tlong res = MUL_TABLE[key];\n\t\tif (res == 0) {\n\t\t\tif ((vi & 0xf) != 0 && (vi & 0xf0) != 0) {\n\t\t\t\tres = mulCached(i, vi & 0xf, j, vj) ^ mulCached(i, vi & 0xf0, j, vj);\n\t\t\t} else if ((vj & 0xf) != 0 && (vj & 0xf0) != 0) {\n\t\t\t\tres = mulCached(i, vi, j, vj & 0xf) ^ mulCached(i, vi, j, vj & 0xf0);\n\t\t\t} else {\n\t\t\t\tres = mulSlow((long) vi << (8 * i), (long) vj << (8 * j));\n\t\t\t}\n\t\t\tMUL_TABLE[key] = res;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic final long MUL_TABLE[] = new long[8 * 8 * 256 * 256];\n\tstatic long mul(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tint vi = (int) ((a >> (8 * i)) & 255);\n\t\t\tif (vi == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = 0; j < 8; j++) {\n\t\t\t\tint vj = (int) ((b >> (8 * j)) & 255);\n\t\t\t\tif (vj == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres ^= mulCached(i, vi, j, vj);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long pow(long a, long e) {\n\t\tif (e == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tlong r = a;\n\t\tfor (int i = 62 - Long.numberOfLeadingZeros(e); i >= 0; i--) {\n\t\t\tr = mul(r, r);\n\t\t\tif ((e & (1L << i)) != 0) {\n\t\t\t\tr = mul(r, a);\n\t\t\t}\n\t\t}\n\t\treturn r;\n\t}\n\n\tstatic final long PRE_TABLE[] = new long[16 * 16];\n\tstatic void preClear() {\n\t\tfill(PRE_TABLE, 0);\n\t}\n\tstatic long preMul(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 16; i++) {\n\t\t\tint vi = (int) ((a >> (4 * i)) & 15);\n\t\t\tif (vi == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint pkey = i * 16 + vi;\n\t\t\tlong pres = PRE_TABLE[pkey];\n\t\t\tif (pres == 0) {\n\t\t\t\tint ii = i >> 1, vii = (i & 1) == 0 ? vi : vi << 4;\n\t\t\t\tfor (int j = 0; j < 8; j++) {\n\t\t\t\t\tint vj = (int) ((b >> (8 * j)) & 255);\n\t\t\t\t\tif (vj == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tpres ^= mulCached(ii, vii, j, vj);\n\t\t\t\t}\n\t\t\t\tPRE_TABLE[pkey] = pres;\n\t\t\t}\n\t\t\tres ^= pres;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic final long GEN = -Long.MAX_VALUE;\n\tstatic final int PRIMES[] = {3, 5, 17, 257, 641, 65537, 6700417};\n\tstatic final int PRIME_STEP[] = {1, 1, 1, 1, 1, 20, 200};\n\tstatic final long POW_VALS[][] = new long[PRIMES.length][];\n\tstatic final int POW_IDX[][] = new int[PRIMES.length][];\n\tstatic {\n\t\tfor (int i = 0; i < PRIMES.length; i++) {\n\t\t\tint p = PRIMES[i];\n\t\t\tint s = PRIME_STEP[i];\n\t\t\tint l = (p + s - 1) / s;\n\t\t\tPOW_VALS[i] = new long[l];\n\t\t\tPOW_IDX[i] = new int[l];\n\t\t\tPOW_VALS[i][0] = 1;\n\t\t\tlong cgen = pow(GEN, Long.divideUnsigned(-1, p) * s);\n\t\t\tpreClear();\n\t\t\tfor (int j = 1; j < l; j++) {\n\t\t\t\tPOW_VALS[i][j] = preMul(POW_VALS[i][j - 1], cgen);\n\t\t\t\tPOW_IDX[i][j] = j;\n\t\t\t}\n\t\t\tsortBy(POW_IDX[i], l, POW_VALS[i]);\n\t\t}\n\t}\n\n\tstatic final BigInteger bMod = BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE);\n\n\tstatic BigInteger dlog(long v) {\n\t\tBigInteger res = BigInteger.ZERO;\n\t\tfor (int i = 0; i < PRIMES.length; i++) {\n\t\t\tint p = PRIMES[i];\n\t\t\tint s = PRIME_STEP[i];\n\t\t\tint len = POW_VALS[i].length;\n\t\t\tlong vv = pow(v, Long.divideUnsigned(-1, p));\n\t\t\tlong cgen = pow(GEN, -1 - Long.divideUnsigned(-1, p));\n\t\t\tint cres = -1;\n\t\t\tpreClear();\n\t\t\tfor (int j = 0; j < s; j++) {\n\t\t\t\tint l = 0, r = len;\n\t\t\t\twhile (l < r) {\n\t\t\t\t\tint mid = (l + r) >> 1;\n\t\t\t\t\tif (POW_VALS[i][POW_IDX[i][mid]] < vv) {\n\t\t\t\t\t\tl = mid + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tr = mid;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (l < len && POW_VALS[i][POW_IDX[i][l]] == vv) {\n\t\t\t\t\tcres = POW_IDX[i][l] * s + j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tvv = preMul(vv, cgen);\n\t\t\t}\n\t\t\tif (cres < 0) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tBigInteger bp = BigInteger.valueOf(p);\n\t\t\tBigInteger md = bMod.divide(bp);\n\t\t\tres = res.add(md.modInverse(bp).multiply(md).multiply(BigInteger.valueOf(cres)));\n\t\t}\n\t\treturn res.mod(bMod);\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint tests = scanInt();\n//\t\tint tests = 100;\n//\t\tRandom rng = new Random(42);\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tlong a = new BigInteger(scanString()).longValue(),\n\t\t\t b = new BigInteger(scanString()).longValue();\n//\t\t\tlong a = test * 12345678901L + 12345678901234567L, b = pow(a, 1999);\n//\t\t\tlong a = rng.nextLong(), b = rng.nextLong();\n\t\t\tBigInteger logA = dlog(a), logB = dlog(b);\n\t\t\tBigInteger x;\n\t\t\tif (logB.signum() == 0) {\n\t\t\t\tx = BigInteger.ZERO;\n\t\t\t} else {\n\t\t\t\tBigInteger gcd = logA.gcd(logB).gcd(bMod);\n\t\t\t\tlogA = logA.divide(gcd);\n\t\t\t\tlogB = logB.divide(gcd);\n\t\t\t\tBigInteger curMod = bMod.divide(gcd);\n\t\t\t\tif (logA.gcd(curMod).compareTo(BigInteger.ONE) != 0) {\n\t\t\t\t\tx = BigInteger.ONE.negate();\n\t\t\t\t} else {\n\t\t\t\t\tx = logA.modInverse(curMod).multiply(logB).mod(curMod);\n\t\t\t\t}\n\t\t\t}\n//\t\t\tif (x.signum() >= 0 && pow(a, x.longValue()) != b) {\n//\t\t\t\tthrow new AssertionError();\n//\t\t\t}\n\t\t\tout.println(x);\n\t\t}\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3282b90f092f3d3a9f8d04b9f4c86a2d", "src_uid": "54b41c5184c27d1373ec05775bc43b50", "difficulty": 3400.0} {"lang": "Java 11", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic void sortBy(int a[], int n, long v[]) {\n\t\tif (n == 0) {\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = i;\n\t\t\tint ca = a[i];\n\t\t\tlong cv = v[ca];\n\t\t\tdo {\n\t\t\t\tint nj = (j - 1) >> 1;\n\t\t\t\tint na = a[nj];\n\t\t\t\tif (cv <= v[na]) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ta[j] = na;\n\t\t\t\tj = nj;\n\t\t\t} while (j != 0);\n\t\t\ta[j] = ca;\n\t\t}\n\t\tint ca = a[0];\n\t\tfor (int i = n - 1; i > 0; i--) {\n\t\t\tint j = 0;\n\t\t\twhile ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {\n\t\t\t\tj <<= 1;\n\t\t\t\tj += (v[a[j + 2]] > v[a[j + 1]]) ? 2 : 1;\n\t\t\t}\n\t\t\tif ((j << 1) + 2 == i) {\n\t\t\t\tj = (j << 1) + 1;\n\t\t\t}\n\t\t\tint na = a[i];\n\t\t\ta[i] = ca;\n\t\t\tca = na;\n\t\t\tlong cv = v[ca];\n\t\t\twhile (j != 0 && v[a[j]] < cv) {\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t\twhile (j != 0) {\n\t\t\t\tna = a[j];\n\t\t\t\ta[j] = ca;\n\t\t\t\tca = na;\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t}\n\t\ta[0] = ca;\n\t}\n\n\tstatic final long MUL_BIT_TABLE[] = new long[64 * 64];\n\tstatic long mulBits(int i, int j) {\n\t\tint key = i * 64 + j;\n\t\tlong res = MUL_BIT_TABLE[key];\n\t\tif (res == 0) {\n\t\t\tres = 1;\n\t\t\tfor (int k = 5; k >= 0; k--) {\n\t\t\t\tif (((i ^ j) & (1 << k)) != 0) {\n\t\t\t\t\tres <<= 1 << k;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int k = 5; k >= 0; k--) {\n\t\t\t\tif ((i & j & (1 << k)) != 0) {\n\t\t\t\t\tres = mul(res, 3L << ((1 << k) - 1));\n\t\t\t\t}\n\t\t\t}\n\t\t\tMUL_BIT_TABLE[key] = res;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long mulSlow(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 64; i++) {\n\t\t\tif ((a & (1L << i)) == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = 0; j < 64; j++) {\n\t\t\t\tif ((b & (1L << j)) == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres ^= mulBits(i, j);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic final long MUL_TABLE[] = new long[8 * 8 * 256 * 256];\n\tstatic long mul(long a, long b) {\n\t\tlong res = 0;\n\t\tfor (int i = 0; i < 8; i++) {\n\t\t\tint vi = (int) ((a >> (8 * i)) & 255);\n\t\t\tif (vi == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = 0; j < 8; j++) {\n\t\t\t\tint vj = (int) ((b >> (8 * j)) & 255);\n\t\t\t\tif (vj == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint key = ((i * 8 + j) * 256 + vi) * 256 + vj;\n\t\t\t\tlong cres = MUL_TABLE[key];\n\t\t\t\tif (cres == 0) {\n\t\t\t\t\tcres = mulSlow((long) vi << (8 * i), (long) vj << (8 * j));\n\t\t\t\t\tMUL_TABLE[key] = cres;\n\t\t\t\t}\n\t\t\t\tres ^= cres;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long pow(long a, long e) {\n\t\tif (e == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tlong r = a;\n\t\tfor (int i = 62 - Long.numberOfLeadingZeros(e); i >= 0; i--) {\n\t\t\tr = mul(r, r);\n\t\t\tif ((e & (1L << i)) != 0) {\n\t\t\t\tr = mul(r, a);\n\t\t\t}\n\t\t}\n\t\treturn r;\n\t}\n\n\tstatic final long GEN = -Long.MAX_VALUE;\n\tstatic final int PRIMES[] = {3, 5, 17, 257, 641, 65537, 6700417};\n\tstatic final int PRIME_STEP[] = {1, 1, 1, 1, 1, 10, 1000};\n\tstatic final long POW_VALS[][] = new long[PRIMES.length][];\n\tstatic final int POW_IDX[][] = new int[PRIMES.length][];\n\tstatic {\n\t\tfor (int i = 0; i < PRIMES.length; i++) {\n\t\t\tint p = PRIMES[i];\n\t\t\tint s = PRIME_STEP[i];\n\t\t\tint l = p / s;\n\t\t\tPOW_VALS[i] = new long[l];\n\t\t\tPOW_IDX[i] = new int[l];\n\t\t\tPOW_VALS[i][0] = 1;\n\t\t\tlong cgen = pow(GEN, Long.divideUnsigned(-1, p) * s);\n\t\t\tfor (int j = 1; j < l; j++) {\n\t\t\t\tPOW_VALS[i][j] = mul(POW_VALS[i][j - 1], cgen);\n\t\t\t\tPOW_IDX[i][j] = j;\n\t\t\t}\n\t\t\tsortBy(POW_IDX[i], l, POW_VALS[i]);\n\t\t}\n\t}\n\n\tstatic final BigInteger bMod = BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE);\n\n\tstatic BigInteger dlog(long v) {\n\t\tBigInteger res = BigInteger.ZERO;\n\t\tfor (int i = 0; i < PRIMES.length; i++) {\n\t\t\tint p = PRIMES[i];\n\t\t\tint s = PRIME_STEP[i];\n\t\t\tint len = p / s;\n\t\t\tlong vv = pow(v, Long.divideUnsigned(-1, p));\n\t\t\tlong cgen = pow(GEN, -1 - Long.divideUnsigned(-1, p));\n\t\t\tint cres = -1;\n\t\t\tfor (int j = 0; j < s; j++) {\n\t\t\t\tint l = 0, r = len;\n\t\t\t\twhile (l < r) {\n\t\t\t\t\tint mid = (l + r) >> 1;\n\t\t\t\t\tif (POW_VALS[i][POW_IDX[i][mid]] < vv) {\n\t\t\t\t\t\tl = mid + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tr = mid;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (POW_VALS[i][POW_IDX[i][l]] == vv) {\n\t\t\t\t\tcres = POW_IDX[i][l] * s + j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tvv = mul(vv, cgen);\n\t\t\t}\n\t\t\tBigInteger bp = BigInteger.valueOf(p);\n\t\t\tBigInteger md = bMod.divide(bp);\n\t\t\tres = res.add(md.modInverse(bp).multiply(md).multiply(BigInteger.valueOf(cres)));\n\t\t}\n\t\treturn res.mod(bMod);\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint tests = scanInt();\n//\t\tint tests = 100;\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tlong a = new BigInteger(scanString()).longValue(),\n\t\t\t b = new BigInteger(scanString()).longValue();\n//\t\t\tlong a = 1, b = 1;\n\t\t\tBigInteger logA = dlog(a), logB = dlog(b);\n\t\t\tBigInteger x;\n\t\t\tif (logB.signum() == 0) {\n\t\t\t\tx = BigInteger.ZERO;\n\t\t\t} else {\n\t\t\t\tBigInteger gcd = logA.gcd(logB).gcd(bMod);\n\t\t\t\tlogA = logA.divide(gcd);\n\t\t\t\tlogB = logB.divide(gcd);\n\t\t\t\tBigInteger curMod = bMod.divide(gcd);\n\t\t\t\tif (logA.gcd(curMod).compareTo(BigInteger.ONE) != 0) {\n\t\t\t\t\tx = BigInteger.ONE.negate();\n\t\t\t\t} else {\n\t\t\t\t\tx = logA.modInverse(curMod).multiply(logB).mod(curMod);\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(x);\n\t\t}\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c89ce4b9a98bffcbbf8528a19564afd4", "src_uid": "54b41c5184c27d1373ec05775bc43b50", "difficulty": 3400.0} {"lang": "Java 7", "source_code": "\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader (System.in);\n\t\tPrintWriter out = new PrintWriter (System.out);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tint[][] ans;\n\tint tot;\n\tclass Line {\n\t\tint a,b,c,id;\n\t};\n\t\n\tpublic void solve (int TestNumber, InputReader in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tLine[] road = new Line[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\troad[i] = new Line();//initialize is necessary\n\t\t\troad[i].a = in.nextInt();\n\t\t\troad[i].b = in.nextInt();\n\t\t\troad[i].c = in.nextInt();\n\t\t\troad[i].id = i+1;\n\t\t}\n\t\tans = new int[k][2];\n\t\ttot = -1;\n\t\tcalc(road, k);\n\t\tif (tot == -1) {\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tout.println(\"YES\");\n\t\tout.println(k-tot);\n\t\tfor (int i = tot; i < k; ++i) {\n\t\t\tout.println(ans[i][0] + \" \" + ans[i][1]);\n\t\t}\n\t}\n\t//Java \u7279\u70b9\uff0c\u6709\u4e86.length,\u5c31\u4e0d\u7528\u8bb0\u5f55\u6570\u7ec4\u957f\u5ea6\u4e86\uff1b\u6709\u4e86for each: \u5c31\u4e0d\u7528\u679a\u4e3e\u4e0b\u6807\u4e86\n\tprivate void calc(Line[] road, int k) {\n\t\tif (road.length > k*k) {\n\t\t\tif (k == 0) return;\n\t\t\tdouble pr = 1.0 - getPr(road.length,k);\n\t\t\tint cnt = 1;\n\t\t\tdouble s = pr;\n\t\t\twhile (s > 1e-10) {\n\t\t\t\t++cnt;\n\t\t\t\ts *= pr;\n\t\t\t}\n\t\t\tRandom rand = new Random(19950315L + System.currentTimeMillis());\n\t\t\tfor (;cnt >= 0; --cnt) {\n\t\t\t\tLine p = road[rand.nextInt(road.length)];\n\t\t\t\tLine q = road[rand.nextInt(road.length)];\n\t\t\t\tint denom = p.a*q.b-p.b*q.a;\n\t\t\t\tif (denom == 0) continue;\n\t\t\t\tint x = -(p.c*q.b-p.b*q.c);\n\t\t\t\tint y = -(p.a*q.c-p.c*q.a);\n\t\t\t\t\n\t\t\t\tint num = 0;\n\t\t\t\tfor (Line r : road) {\n\t\t\t\t\tif (r.a*x+r.b*y+r.c*denom == 0) ++num;\n\t\t\t\t}\n\t\t\t\tif (num>k) {\n\t\t\t\t\tans[k-1][0] = p.id; \n\t\t\t\t\tans[k-1][1] = q.id;\n\t\t\t\t\tint t_tot = 0;\n\t\t\t\t\tLine[] n_road = new Line[road.length - num];\n\t\t\t\t\tfor (Line r : road) {\n\t\t\t\t\t\tif (r.a*x+r.b*y+r.c*denom != 0) {\n\t\t\t\t\t\t\tn_road[t_tot++] = r;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcalc(n_road, k-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (road.length == 0) {\n\t\t\ttot = k;\n\t\t\treturn;\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 any = false;\n\t\t\tfor (Line q : road) {\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 (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\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\tn_road[n_tot++] = r;\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;\n\t\t\tlong pair = 0;\n\t\t\tfor (int id = 0; id < big; ++id) {\n\t\t\t\tint size = rem / big;\n\t\t\t\tif (rem % big > id) ++size;\n\t\t\t\tpair += size*(size-1);\n\t\t\t}\n\t\t\tret = Math.min(ret, pair);\n\t\t}\n\t\treturn (double)ret/n/n;\n\t}\n}\n\nclass InputReader {\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\t\n\tpublic InputReader (InputStream stream) {\n\t\treader = new BufferedReader (new InputStreamReader(stream), 32768);\n\t\ttokenizer = null;\n\t}\n\t\n\tpublic String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer (reader.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException (e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\t\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "13c10da75cdd6b83fcd3cb0e96c9954e", "src_uid": "dea5c9eded04f1a900c37571d20b34e2", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n int[] resu;\n int[] resv;\n int resunused;\n Random random;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n random = new Random(543715351L + System.currentTimeMillis());\n int n = in.nextInt();\n int k = in.nextInt();\n TaskD.Line[] roads = new TaskD.Line[n];\n for (int i = 0; i < n; ++i) {\n roads[i] = new TaskD.Line();\n roads[i].index = i + 1;\n roads[i].a = in.nextInt();\n roads[i].b = in.nextInt();\n roads[i].c = in.nextInt();\n }\n resu = new int[k];\n resv = new int[k];\n resunused = -1;\n doit(roads, k);\n if (resunused < 0) {\n out.println(\"NO\");\n } else {\n out.println(\"YES\");\n out.println(k - resunused);\n for (int i = resunused; i < k; ++i) {\n out.println(resu[i] + \" \" + resv[i]);\n }\n }\n }\n\n private void doit(TaskD.Line[] roads, int k) {\n if (roads.length > k * k) {\n double pr = 1.0 - getPr(roads.length, k);\n int cnt = 0;\n double prod = 1;\n while (prod > 1e-10) {\n prod *= pr;\n ++cnt;\n }\n for (int step = 0; step < cnt; ++step) {\n TaskD.Line p = roads[random.nextInt(roads.length)];\n TaskD.Line q = roads[random.nextInt(roads.length)];\n long denom = p.a * q.b - p.b * q.a;\n if (denom == 0) continue;\n long xnom = -(p.c * q.b - p.b * q.c);\n long ynom = -(p.a * q.c - p.c * q.a);\n int amt = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom == 0) {\n ++amt;\n }\n }\n if (amt > k) {\n resu[k - 1] = p.index;\n resv[k - 1] = q.index;\n TaskD.Line[] remains = new TaskD.Line[roads.length - amt];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom != 0) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n return;\n }\n }\n } else if (roads.length == 0) {\n resunused = k;\n } else {\n TaskD.Line p = roads[random.nextInt(roads.length)];\n boolean any = false;\n boolean[] mark = new boolean[roads.length];\n for (int qi = 0; qi < roads.length; ++qi)\n if (!mark[qi]) {\n TaskD.Line q = roads[qi];\n long denom = p.a * q.b - p.b * q.a;\n if (denom == 0) continue;\n long xnom = -(p.c * q.b - p.b * q.c);\n long ynom = -(p.a * q.c - p.c * q.a);\n any = true;\n int amt = 0;\n for (int i = 0; i < roads.length; ++i) {\n TaskD.Line r = roads[i];\n if (r.a * xnom + r.b * ynom + r.c * denom == 0) {\n ++amt;\n mark[i] = true;\n }\n }\n resu[k - 1] = p.index;\n resv[k - 1] = q.index;\n TaskD.Line[] remains = new TaskD.Line[roads.length - amt];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom != 0) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n if (resunused >= 0) return;\n }\n if (!any) {\n resu[k - 1] = p.index;\n resv[k - 1] = -1;\n TaskD.Line[] remains = new TaskD.Line[roads.length - 1];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r != p) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n }\n }\n }\n\n private double getPr(int n, int k) {\n long minPairs = Long.MAX_VALUE;\n for (int numSmall = 0; numSmall < k; ++numSmall) {\n int remains = n - k * numSmall;\n int numBig = k - numSmall;\n long numPairs = 0;\n for (int i = 0; i < numBig; ++i) {\n long size = remains / numBig;\n if (i < remains % numBig) ++size;\n numPairs += size * (size - 1);\n }\n minPairs = Math.min(minPairs, numPairs);\n }\n return minPairs / (double) n / n;\n }\n\n static class Line {\n long a;\n long b;\n long c;\n int index;\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "584229f9e1cde882f40fe27e2e7af46c", "src_uid": "dea5c9eded04f1a900c37571d20b34e2", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n int[] resu;\n int[] resv;\n int resunused;\n Random random;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n random = new Random(543715351L + System.currentTimeMillis());\n int n = in.nextInt();\n int k = in.nextInt();\n TaskD.Line[] roads = new TaskD.Line[n];\n for (int i = 0; i < n; ++i) {\n roads[i] = new TaskD.Line();\n roads[i].index = i + 1;\n roads[i].a = in.nextInt();\n roads[i].b = in.nextInt();\n roads[i].c = in.nextInt();\n }\n resu = new int[k];\n resv = new int[k];\n resunused = -1;\n doit(roads, k);\n if (resunused < 0) {\n out.println(\"NO\");\n } else {\n out.println(\"YES\");\n out.println(k - resunused);\n for (int i = resunused; i < k; ++i) {\n out.println(resu[i] + \" \" + resv[i]);\n }\n }\n }\n\n private void doit(TaskD.Line[] roads, int k) {\n if (roads.length > k * k) {\n if (k == 0) return;\n double pr = 1.0 - getPr(roads.length, k);\n int cnt = 0;\n double prod = 1;\n while (prod > 1e-10) {\n prod *= pr;\n ++cnt;\n }\n for (int step = 0; step < cnt; ++step) {\n TaskD.Line p = roads[random.nextInt(roads.length)];\n TaskD.Line q = roads[random.nextInt(roads.length)];\n long denom = p.a * q.b - p.b * q.a;\n if (denom == 0) continue;\n long xnom = -(p.c * q.b - p.b * q.c);\n long ynom = -(p.a * q.c - p.c * q.a);\n int amt = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom == 0) {\n ++amt;\n }\n }\n if (amt > k) {\n resu[k - 1] = p.index;\n resv[k - 1] = q.index;\n TaskD.Line[] remains = new TaskD.Line[roads.length - amt];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom != 0) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n return;\n }\n }\n } else if (roads.length == 0) {\n resunused = k;\n } else {\n TaskD.Line p = roads[random.nextInt(roads.length)];\n boolean any = false;\n boolean[] mark = new boolean[roads.length];\n for (int qi = 0; qi < roads.length; ++qi)\n if (!mark[qi]) {\n TaskD.Line q = roads[qi];\n long denom = p.a * q.b - p.b * q.a;\n if (denom == 0) continue;\n long xnom = -(p.c * q.b - p.b * q.c);\n long ynom = -(p.a * q.c - p.c * q.a);\n any = true;\n int amt = 0;\n for (int i = 0; i < roads.length; ++i) {\n TaskD.Line r = roads[i];\n if (r.a * xnom + r.b * ynom + r.c * denom == 0) {\n ++amt;\n mark[i] = true;\n }\n }\n resu[k - 1] = p.index;\n resv[k - 1] = q.index;\n TaskD.Line[] remains = new TaskD.Line[roads.length - amt];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom != 0) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n if (resunused >= 0) return;\n }\n if (!any) {\n resu[k - 1] = p.index;\n resv[k - 1] = -1;\n TaskD.Line[] remains = new TaskD.Line[roads.length - 1];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r != p) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n }\n }\n }\n\n private double getPr(int n, int k) {\n long minPairs = Long.MAX_VALUE;\n for (int numSmall = 0; numSmall < k; ++numSmall) {\n int remains = n - k * numSmall;\n int numBig = k - numSmall;\n long numPairs = 0;\n for (int i = 0; i < numBig; ++i) {\n long size = remains / numBig;\n if (i < remains % numBig) ++size;\n numPairs += size * (size - 1);\n }\n minPairs = Math.min(minPairs, numPairs);\n }\n return minPairs / (double) n / n;\n }\n\n static class Line {\n long a;\n long b;\n long c;\n int index;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "337d843b3968d8ffab951e2cac23c9cc", "src_uid": "dea5c9eded04f1a900c37571d20b34e2", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n int[] resu;\n int[] resv;\n int resunused;\n Random random;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n random = new Random(543715351L + System.currentTimeMillis());\n int n = in.nextInt();\n int k = in.nextInt();\n TaskD.Line[] roads = new TaskD.Line[n];\n for (int i = 0; i < n; ++i) {\n roads[i] = new TaskD.Line();\n roads[i].index = i + 1;\n roads[i].a = in.nextInt();\n roads[i].b = in.nextInt();\n roads[i].c = in.nextInt();\n }\n resu = new int[k];\n resv = new int[k];\n resunused = -1;\n doit(roads, k);\n if (resunused < 0) {\n out.println(\"NO\");\n } else {\n out.println(\"YES\");\n out.println(k - resunused);\n for (int i = resunused; i < k; ++i) {\n out.println(resu[i] + \" \" + resv[i]);\n }\n }\n }\n\n private void doit(TaskD.Line[] roads, int k) {\n if (roads.length > k * k) {\n if (k == 0) return;\n double pr = 1.0 - getPr(roads.length, k);\n int cnt = 0;\n double prod = 1;\n while (prod > 1e-10) {\n prod *= pr;\n ++cnt;\n }\n for (int step = 0; step < cnt; ++step) {\n TaskD.Line p = roads[random.nextInt(roads.length)];\n TaskD.Line q = roads[random.nextInt(roads.length)];\n long denom = p.a * q.b - p.b * q.a;\n if (denom == 0) continue;\n long xnom = -(p.c * q.b - p.b * q.c);\n long ynom = -(p.a * q.c - p.c * q.a);\n int amt = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom == 0) {\n ++amt;\n }\n }\n if (amt > k) {\n resu[k - 1] = p.index;\n resv[k - 1] = q.index;\n TaskD.Line[] remains = new TaskD.Line[roads.length - amt];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom != 0) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n return;\n }\n }\n } else if (roads.length == 0) {\n resunused = k;\n } else {\n TaskD.Line p = roads[random.nextInt(roads.length)];\n boolean any = false;\n boolean[] mark = new boolean[roads.length];\n for (int qi = 0; qi < roads.length; ++qi)\n if (!mark[qi]) {\n TaskD.Line q = roads[qi];\n long denom = p.a * q.b - p.b * q.a;\n if (denom == 0) continue;\n long xnom = -(p.c * q.b - p.b * q.c);\n long ynom = -(p.a * q.c - p.c * q.a);\n any = true;\n int amt = 0;\n for (int i = 0; i < roads.length; ++i) {\n TaskD.Line r = roads[i];\n if (r.a * xnom + r.b * ynom + r.c * denom == 0) {\n ++amt;\n mark[i] = true;\n }\n }\n resu[k - 1] = p.index;\n resv[k - 1] = q.index;\n TaskD.Line[] remains = new TaskD.Line[roads.length - amt];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r.a * xnom + r.b * ynom + r.c * denom != 0) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n if (resunused >= 0) return;\n }\n if (!any) {\n resu[k - 1] = p.index;\n resv[k - 1] = -1;\n TaskD.Line[] remains = new TaskD.Line[roads.length - 1];\n int ptr = 0;\n for (TaskD.Line r : roads) {\n if (r != p) {\n remains[ptr++] = r;\n }\n }\n doit(remains, k - 1);\n }\n }\n }\n\n private double getPr(int n, int k) {\n long minPairs = Long.MAX_VALUE;\n for (int numSmall = 0; numSmall < k; ++numSmall) {\n int remains = n - k * numSmall;\n int numBig = k - numSmall;\n long numPairs = 0;\n for (int i = 0; i < numBig; ++i) {\n long size = remains / numBig;\n if (i < remains % numBig) ++size;\n numPairs += size * (size - 1);\n }\n minPairs = Math.min(minPairs, numPairs);\n }\n return minPairs / (double) n / n;\n }\n\n static class Line {\n long a;\n long b;\n long c;\n int index;\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43059f55db367696b0adc3e72124969f", "src_uid": "dea5c9eded04f1a900c37571d20b34e2", "difficulty": 2800.0} {"lang": "Java 8", "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\tstatic int dp1(int idx,int remCnt,int remSum) {\n\t\tif(remCnt==0)\n\t\t\treturn remSum==0?1:0;\n\t\tif(remSum==0 || idx==n)\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 && t[idx]<=remSum)\n\t\t{\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\tstatic int dp2(int idx,int remCnt1,int remCnt2,int remSum) {\n\t\tint all=remCnt1+remCnt2;\n\t\tif(all==0)\n\t\t\treturn remSum==0?1:0;\n\t\tif(idx==n || remSum==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\t\tif(t[idx]<=remSum) {\n\t\t\tif(g[idx]==1 && remCnt1>0)\n\t\t\t\tans+=dp2(idx+1,remCnt1-1,remCnt2,remSum-t[idx]);\n\t\t\telse if(g[idx]==2 && remCnt2>0)\n\t\t\t\tans+=dp2(idx+1,remCnt1,remCnt2-1,remSum-t[idx]);\n\t\t\t\t\n\t\t}\n\t\t\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum]=ans;\n\t}\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2,int last) {\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(cnt0>0 && last!=0)\n\t\t\tans+=dp3(cnt0-1,cnt1,cnt2,0);\n\t\tif(cnt1>0 && last!=1)\n\t\t\tans+=dp3(cnt0,cnt1-1,cnt2,1);\n\t\tif(cnt2>0 && last!=2)\n\t\t\tans+=dp3(cnt0,cnt1,cnt2-1,2);\n\t\treturn memo3[last][cnt0][cnt1][cnt2]=(int) (ans%MOD);\n\t\t\n\t}\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\t\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\tmemo1=new int [n][n+1][T+1];\n\t\tmemo2=new int [n][n+1][n+1][T+1];\n\t\tmemo3=new int [4][n+1][n+1][n+1];\n\t\tfor(int i=0;i=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\t\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b0eba466c1061bc31de016d05edc0803", "src_uid": "ed5f913afe829c65792b54233a256757", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1185G2 {\n\tstatic final int MD = 1000000007;\n\tstatic int[][] solve1(int[] aa, int t, int n) {\n\t\tint[][] da = new int[t + 1][n + 1];\n\t\tda[0][0] = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = aa[i];\n\t\t\tfor (int s = t - 1; s >= 0; s--)\n\t\t\t\tfor (int m = 0; m < n; m++) {\n\t\t\t\t\tint x = da[s][m];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tint s_ = s + a;\n\t\t\t\t\t\tif (s_ <= t)\n\t\t\t\t\t\t\tda[s_][m + 1] = (da[s_][m + 1] + x) % MD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn da;\n\t}\n\tstatic int[][][] solve2(int[] aa, int[] bb, int t, int na, int nb) {\n\t\tint[][] da = solve1(aa, t, na);\n\t\tint[][][] dab = new int[t + 1][na + 1][nb + 1];\n\t\tfor (int s = 0; s <= t; s++)\n\t\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\t\tdab[s][ma][0] = da[s][ma];\n\t\tfor (int i = 0; i < nb; i++) {\n\t\t\tint b = bb[i];\n\t\t\tfor (int s = t - 1; s >= 0; s--)\n\t\t\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\t\t\tfor (int mb = 0; mb < nb; mb++) {\n\t\t\t\t\t\tint x = dab[s][ma][mb];\n\t\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\t\tint s_ = s + b;\n\t\t\t\t\t\t\tif (s_ <= t)\n\t\t\t\t\t\t\t\tdab[s_][ma][mb + 1] = (dab[s_][ma][mb + 1] + x) % MD;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t}\n\t\treturn dab;\n\t}\n\tstatic long power(int a, int k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tlong p = power(a, k / 2);\n\t\tp = p * p % MD;\n\t\tif (k % 2 == 1)\n\t\t\tp = p * a % MD;\n\t\treturn p;\n\t}\n\tstatic int[] ff, gg;\n\tstatic int ch(int n, int k) {\n\t\treturn (int) ((long) ff[n] * gg[n - k] % MD * gg[k] % MD);\n\t}\n\tstatic int[][][] init(int n, int na, int nb, int nc) {\n\t\tff = new int[n + 1];\n\t\tgg = new int[n + 1];\n\t\tfor (int i = 0, f = 1; i <= n; i++) {\n\t\t\tff[i] = f;\n\t\t\tgg[i] = (int) power(f, MD - 2);\n\t\t\tf = (int) ((long) f * (i + 1) % MD);\n\t\t}\n\t\tint[][][] dp = new int[na + 1][nb + 1][nc + 1];\n\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\tfor (int mb = 0; mb <= nb; mb++)\n\t\t\t\tfor (int mc = 0; mc <= nc; mc++) {\n\t\t\t\t\tint x = (int) ((long) ff[ma + mb + mc] * gg[ma] % MD * gg[mb] % MD * gg[mc] % MD);\n\t\t\t\t\tfor (int ma_ = ma == 0 ? 0 : 1; ma_ <= ma; ma_++) {\n\t\t\t\t\t\tint cha = ma == 0 ? 1 : ch(ma - 1, ma_ - 1);\n\t\t\t\t\t\tfor (int mb_ = mb == 0 ? 0 : 1; mb_ <= mb; mb_++) {\n\t\t\t\t\t\t\tint chb = mb == 0 ? 1 : ch(mb - 1, mb_ - 1);\n\t\t\t\t\t\t\tfor (int mc_ = mc == 0 ? 0 : 1; mc_ <= mc; mc_++) {\n\t\t\t\t\t\t\t\tint chc = mc == 0 ? 1 : ch(mc - 1, mc_ - 1);\n\t\t\t\t\t\t\t\tint y = dp[ma_][mb_][mc_];\n\t\t\t\t\t\t\t\tif (y == 0)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tx = (int) ((x - (long) y * cha % MD * chb % MD * chc) % MD);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (x < 0)\n\t\t\t\t\t\tx += MD;\n\t\t\t\t\tdp[ma][mb][mc] = x;\n\t\t\t\t}\n\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\tfor (int mb = 0; mb <= nb; mb++)\n\t\t\t\tfor (int mc = 0; mc <= nc; mc++)\n\t\t\t\t\tdp[ma][mb][mc] = (int) ((long) dp[ma][mb][mc] * ff[ma] % MD * ff[mb] % MD * ff[mc] % MD);\n\t\treturn dp;\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint t = Integer.parseInt(st.nextToken());\n\t\tint[] aa = new int[n];\n\t\tint[] bb = new int[n];\n\t\tint[] cc = new int[n];\n\t\tint na = 0, nb = 0, nc = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint a = Integer.parseInt(st.nextToken());\n\t\t\tint g = Integer.parseInt(st.nextToken());\n\t\t\tif (g == 1)\n\t\t\t\taa[na++] = a;\n\t\t\telse if (g == 2)\n\t\t\t\tbb[nb++] = a;\n\t\t\telse\n\t\t\t\tcc[nc++] = a;\n\t\t}\n\t\tint[][][] dp = init(n, na, nb, nc);\n\t\tint[][][] dab = solve2(aa, bb, t, na, nb);\n\t\tint[][] dc = solve1(cc, t, nc);\n\t\tint ans = 0;\n\t\tfor (int tab = 0; tab <= t; tab++) {\n\t\t\tint tc = t - tab;\n\t\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\t\tfor (int mb = 0; mb <= nb; mb++) {\n\t\t\t\t\tint xab = dab[tab][ma][mb];\n\t\t\t\t\tif (xab == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int mc = 0; mc <= nc; mc++) {\n\t\t\t\t\t\tint xc = dc[tc][mc];\n\t\t\t\t\t\tif (xc == 0)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tans = (int) ((ans + (long) xab * xc * dp[ma][mb][mc]) % MD);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "38445c7e735ac057b6ccb29d1f074bfa", "src_uid": "ed5f913afe829c65792b54233a256757", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "// https://codeforces.com/contest/1185/submission/55800229 (rainboy)\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1185G2 {\n\tstatic final int MD = 1000000007;\n\tstatic int[][] solve1(int[] aa, int t, int n) {\n\t\tint[][] da = new int[t + 1][n + 1];\n\t\tda[0][0] = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = aa[i];\n\t\t\tfor (int s = t - 1; s >= 0; s--)\n\t\t\t\tfor (int m = 0; m < n; m++) {\n\t\t\t\t\tint x = da[s][m];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tint s_ = s + a;\n\t\t\t\t\t\tif (s_ <= t)\n\t\t\t\t\t\t\tda[s_][m + 1] = (da[s_][m + 1] + x) % MD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn da;\n\t}\n\tstatic int[][][] solve2(int[] aa, int[] bb, int t, int na, int nb) {\n\t\tint[][] da = solve1(aa, t, na);\n\t\tint[][][] dab = new int[t + 1][na + 1][nb + 1];\n\t\tfor (int s = 0; s <= t; s++)\n\t\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\t\tdab[s][ma][0] = da[s][ma];\n\t\tfor (int i = 0; i < nb; i++) {\n\t\t\tint b = bb[i];\n\t\t\tfor (int s = t - 1; s >= 0; s--)\n\t\t\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\t\t\tfor (int mb = 0; mb < nb; mb++) {\n\t\t\t\t\t\tint x = dab[s][ma][mb];\n\t\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\t\tint s_ = s + b;\n\t\t\t\t\t\t\tif (s_ <= t)\n\t\t\t\t\t\t\t\tdab[s_][ma][mb + 1] = (dab[s_][ma][mb + 1] + x) % MD;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t}\n\t\treturn dab;\n\t}\n\tstatic int[][][] init(int n, int na, int nb, int nc) {\n\t\tint[][][] dp = new int[na + 1][nb + 1][nc + 1];\n\t\tint[][][][] dq = new int[na + 1][nb + 1][nc + 1][3];\n\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\tfor (int mb = 0; mb <= nb; mb++)\n\t\t\t\tfor (int mc = 0; mc <= nc; mc++)\n\t\t\t\t\tif (ma == 0 && mb == 0 && mc == 0) {\n\t\t\t\t\t\tdp[ma][mb][mc] = 1;\n\t\t\t\t\t\tdq[ma][mb][mc][0] = dq[ma][mb][mc][1] = dq[ma][mb][mc][2] = 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlong x0 = ma > 0 ? dq[ma - 1][mb][mc][0] * ma % MD : 0;\n\t\t\t\t\t\tlong x1 = mb > 0 ? dq[ma][mb - 1][mc][1] * mb % MD : 0;\n\t\t\t\t\t\tlong x2 = mc > 0 ? dq[ma][mb][mc - 1][2] * mc % MD : 0;\n\t\t\t\t\t\tdp[ma][mb][mc] = (int) ((x0 + x1 + x2) % MD);\n\t\t\t\t\t\tdq[ma][mb][mc][0] = (int) ((x1 + x2) % MD);\n\t\t\t\t\t\tdq[ma][mb][mc][1] = (int) ((x2 + x0) % MD);\n\t\t\t\t\t\tdq[ma][mb][mc][2] = (int) ((x0 + x1) % MD);\n\t\t\t\t\t}\n\t\treturn dp;\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint t = Integer.parseInt(st.nextToken());\n\t\tint[] aa = new int[n];\n\t\tint[] bb = new int[n];\n\t\tint[] cc = new int[n];\n\t\tint na = 0, nb = 0, nc = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint a = Integer.parseInt(st.nextToken());\n\t\t\tint g = Integer.parseInt(st.nextToken());\n\t\t\tif (g == 1)\n\t\t\t\taa[na++] = a;\n\t\t\telse if (g == 2)\n\t\t\t\tbb[nb++] = a;\n\t\t\telse\n\t\t\t\tcc[nc++] = a;\n\t\t}\n\t\tint[][][] dp = init(n, na, nb, nc);\n\t\tint[][][] dab = solve2(aa, bb, t, na, nb);\n\t\tint[][] dc = solve1(cc, t, nc);\n\t\tint ans = 0;\n\t\tfor (int tab = 0; tab <= t; tab++) {\n\t\t\tint tc = t - tab;\n\t\t\tfor (int ma = 0; ma <= na; ma++)\n\t\t\t\tfor (int mb = 0; mb <= nb; mb++) {\n\t\t\t\t\tint xab = dab[tab][ma][mb];\n\t\t\t\t\tif (xab == 0)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int mc = 0; mc <= nc; mc++) {\n\t\t\t\t\t\tint xc = dc[tc][mc];\n\t\t\t\t\t\tif (xc == 0)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tans = (int) ((ans + (long) xab * xc % MD * dp[ma][mb][mc]) % MD);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2e27b7f75846c9e4d4100ff44cf20d8b", "src_uid": "ed5f913afe829c65792b54233a256757", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n,t[],g[],MOD=(int)1e9+7,lg[];\n\tstatic int [][]memo;\n\tstatic int dp(int msk,int rem,int lastG) {\n\t\tif(rem==0)\n\t\t\treturn 1;\n\t\t\n\t\tint ans=0;\n\t\tint currMsk=msk;\n\t\twhile(currMsk>0) {\n\t\t\tint x=currMsk&-currMsk;\n\t\t\tint i=lg[x];\n\t\t\tcurrMsk-=x;\n\t\t\tif(rem>=t[i] && g[i]!=lastG)\n\t\t\t\tans+=dp(msk&(~(1<=MOD)\n\t\t\t\t\tans-=MOD;\n\t\t}\n\n\t\treturn ans;\n\t}\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 T=sc.nextInt();\n\t\tt=new int [n];\n\t\tg=new int [n];\n\t\tlg=new int [1< cntEndOn = new TreeMap<>();\n TreeMap inactive = new TreeMap<>();\n\n // .first -- unused\n // .second -- used\n for (int i = 0; i < es.length; i++) {\n Event cur = es[i];\n if (cur.type == Event.BEGIN) {\n\n int end = fs[cur.idx].time + fs[cur.idx].x;\n// Pair prev = cntEndOn.getOrDefault(end, new Pair<>(0, 0));\n int prev = cntEndOn.getOrDefault(end, 0) + 1;\n cntEndOn.put(end, prev);\n\n } else if (cur.type == Event.END) {\n\n boolean over1 = false;\n boolean over2 = false;\n// Pair prev = cntEndOn.get(cur.x);\n int prev_first = cntEndOn.getOrDefault(cur.x, 0);\n int prev_second = inactive.getOrDefault(cur.x, 0);\n\n if (prev_second > 0) {\n prev_second--;\n } else {\n if (prev_first > 0) {\n prev_first--;\n }\n }\n if (prev_first == 0) {\n over1 = true;\n }\n if (prev_second == 0) {\n over2 = true;\n }\n\n if (!over1) {\n cntEndOn.put(cur.x, prev_first);\n } else {\n cntEndOn.remove(cur.x);\n }\n\n if (!over2) {\n inactive.put(cur.x, prev_second);\n } else {\n inactive.remove(cur.x);\n }\n\n } else {\n\n if (cntEndOn.size() > 0) {\n int key = cntEndOn.firstKey();\n\n// Pair prev = cntEndOn.get(key);\n int prev_first = cntEndOn.getOrDefault(key, 0);\n int prev_second = inactive.getOrDefault(key, 0);\n boolean over1 = false;\n if (prev_first > 0) {\n prev_first--;\n prev_second++;\n ans++;\n }\n if (prev_first == 0) {\n over1 = true;\n }\n\n if (!over1) {\n cntEndOn.put(key, prev_first);\n } else {\n cntEndOn.remove(key);\n }\n inactive.put(key, prev_second);\n }\n\n }\n }\n out.println(ans);\n }\n\n }\n\n static class Event implements Comparable {\n int x;\n int type;\n int idx;\n static final int BEGIN = -1;\n static final int END = 1;\n static final int DOG = 0;\n\n public Event(int x, int type, int idx) {\n this.x = x;\n this.type = type;\n this.idx = idx;\n }\n\n\n public int compareTo(Event o) {\n if (x == o.x) {\n return Integer.compare(type, o.type);\n }\n return Integer.compare(x, o.x);\n }\n\n }\n\n static class Food implements Comparable {\n int x;\n int time;\n\n public Food(int x, int time) {\n this.x = x;\n this.time = time;\n }\n\n\n public int compareTo(Food o) {\n if (x == o.x) {\n return Integer.compare(time, o.time);\n }\n return Integer.compare(x, o.x);\n }\n\n }\n\n static class IOReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n return null;\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n public int[] readIntArray(int count) {\n int[] array = new int[count];\n for (int i = 0; i < count; i++) {\n array[i] = nextInt();\n }\n return array;\n }\n\n private IOReader(BufferedReader bufferedReader) {\n reader = bufferedReader;\n }\n\n public IOReader(String filename) {\n try {\n reader = new BufferedReader(new FileReader(filename));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public IOReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96d40f94bdb8cbc3bf0853a5f3a6ba1c", "src_uid": "04375596477fc65a2093554ff7b7934d", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces810E {\n\tpublic static int[] global = new int[100];\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tglobal[0] = 1;\n\t\tfor (int i = 1; i < 100; i++) {\n\t\t\tglobal[i] = (2*global[i-1])%1000000007;\n\t\t}\n\t\tint[] twopower = new int[100];\n\t\ttwopower[0] = 1;\n\t\tfor (int i = 1; i < 100; i++) {\n\t\t\ttwopower[i] = (twopower[i-1]*2)%1000000007;\n\t\t}\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tString[] sp = br.readLine().split(\" \");\n\t\tint q = Integer.parseInt(sp[0]);\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tint x1 = Integer.parseInt(sp[0]);\n\t\t\tint y1 = Integer.parseInt(sp[1]);\n\t\t\tint x2 = Integer.parseInt(sp[2]);\n\t\t\tint y2 = Integer.parseInt(sp[3]);\n\t\t\tint k = Integer.parseInt(sp[4]);\n\t\t\tint answer = 0;\n\t\t\tif ((x1 == 1) && (y1 == 1)) {\n\t\t\t\tanswer = answer(x2, y2, k);\n\t\t\t}\n\t\t\telse if (x1 == 1) {\n\t\t\t\tanswer = answer(x2, y2, k)-answer(x2, y1-1, k);\n\t\t\t}\n\t\t\telse if (y1 == 1) {\n\t\t\t\tanswer = answer(x2, y2, k) - answer(x1-1, y2, k);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tanswer = answer(x2, y2, k) - answer(x1-1, y2, k) - answer(x2, y1-1, k) + answer(x1-1, y1-1, k);\n\t\t\t}\n\t\t\tanswer %= 1000000007;\n\t\t\tif (answer < 0)\n\t\t\t\tanswer += 1000000007;\n\t\t\tpw.println(answer);\n\t\t}\n\t\tpw.close();\n\t}\n\t\n\tpublic static int answer(int m, int n, int k) {\n\t\tint tmp = m;\n\t\tint counter = 0;\n\t\tint counter2 = 0;\n\t\twhile (tmp > 0) {\n\t\t\tif (tmp%2 == 1)\n\t\t\t\tcounter++;\n\t\t\tcounter2++;\n\t\t\ttmp = tmp/2;\n\t\t}\n\t\tint[][] mlist = new int[counter][2];\n\t\tcounter--;\n\t\tfor (int i = counter2-1; i >= 0; i--) {\n\t\t\tif ((m >> i)%2 == 1) {\n\t\t\t\tmlist[counter][0] = (m >> i)-1;\n\t\t\t\tmlist[counter][1] = i;\n\t\t\t\tcounter--;\n\t\t\t}\n\t\t}\n\t\t\n\t\ttmp = n;\n\t\tcounter = 0;\n\t\tcounter2 = 0;\n\t\twhile (tmp > 0) {\n\t\t\tif (tmp%2 == 1)\n\t\t\t\tcounter++;\n\t\t\tcounter2++;\n\t\t\ttmp = tmp/2;\n\t\t}\n\t\tint[][] nlist = new int[counter][2];\n\t\tcounter--;\n\t\tfor (int i = counter2-1; i >= 0; i--) {\n\t\t\tif ((n >> i)%2 == 1) {\n\t\t\t\tnlist[counter][0] = (n >> i)-1;\n\t\t\t\tnlist[counter][1] = i;\n\t\t\t\tcounter--;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint answer = 0;\n\n\t\tfor (int i = 0; i < mlist.length; i++) {\n\t\t\tfor (int j = 0; j < nlist.length; j++) {\n\t\t\t\tanswer = (answer + sum(mlist[i][1], nlist[j][1], mlist[i][0], nlist[j][0], k))%1000000007;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn answer;\n\t}\n\t\n\tpublic static int sum(int m, int n, int r, int s, int k) {\n\t\tif (m < n) {\n\t\t\tint temp = m;\n\t\t\tm = n;\n\t\t\tn = temp;\n\t\t\ttemp = r;\n\t\t\tr = s;\n\t\t\ts = temp;\n\t\t}\n\t\tint t = s >> (m-n);\n\t\tint u = r^t;\n\t\tlong val = 0;\n\t\tif (k > u*global[m]) {\n\t\t\tint min = u*global[m];\n\t\t\tint max = Math.min(k, (u+1)*global[m]);\n\t\t\tval = (((long) max)*((long) max+1))/2 - (((long) min)*((long)min+1))/2;\n\t\t}\n\t\tval %= 1000000007;\n\t\tval *= global[n];\n\t\tval %= 1000000007;\n\t\treturn (int) val;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0627aa11debc8e78b2982ab52f4a9cf4", "src_uid": "1ab085026ce43810acf98cc4bf8faf26", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class Main {\n\n\tprivate static final String NO = \"NO\";\n\tprivate static final String YES = \"YES\";\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tprivate static final long MOD = 1000000007;\n\n\tvoid solve() {\n\t\tint T = 1;\n\t\tfor (int i = 0; i < T; i++)\n\t\t\tsolve(i);\n\t}\n\n\tlong p[];\n\n\tvoid solve(int T) {\n\t\tint n = ni();\n\t\tp = new long[64];\n\t\tp[0] = 1;\n\t\tfor (int i = 1; i < 60; i++)\n\t\t\tp[i] = p[i - 1] * 2;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a[] = na(5);\n\t\t\tlong ans = work(a[2], a[3], a[4], 0) - work(a[0] - 1, a[3], a[4], 0) - work(a[2], a[1] - 1, a[4], 0)\n\t\t\t\t\t+ work(a[0] - 1, a[1] - 1, a[4], 0);\n\t\t\tans %= MOD;\n\t\t\tout.println((ans + MOD) % MOD);\n\t\t}\n\t}\n\n\tlong work(long x, long y, long k, long lazy) {\n\t\tif (x <= 0 || y <= 0)\n\t\t\treturn 0;\n\t\tif (k <= 0)\n\t\t\treturn 0;\n\t\tif (x > y) {\n\t\t\tlong tmp = x;\n\t\t\tx = y;\n\t\t\ty = tmp;\n\t\t}\n\t\tint t = 0;\n\t\twhile (p[t] <= y)\n\t\t\tt++;\n\n\t\tlong ans;\n\t\tif (y == p[t - 1]) {\n\t\t\tlong tmpa, tmpb;\n\t\t\tif (p[t - 1] < k)// all numbers is within [1..k], count them all\n\t\t\t{\n\t\t\t\ttmpa = p[t - 1];\n\t\t\t\ttmpa = tmpa * (tmpa + 1) / 2;\n\t\t\t\ttmpa %= MOD;\n\t\t\t\ttmpa *= x;\n\t\t\t\ttmpa %= MOD;\n\t\t\t\ttmpb = (lazy * y) % MOD;\n\t\t\t\ttmpb *= x;\n\t\t\t\ttmpb %= MOD;\n\t\t\t\tans = (tmpa + tmpb) % MOD;\n\t\t\t} else// p[t-1]>=k only less or equal to k is needed\n\t\t\t{\n\t\t\t\ttmpa = k;\n\t\t\t\ttmpa = tmpa * (tmpa + 1) / 2;\n\t\t\t\ttmpa %= MOD;\n\t\t\t\ttmpa *= x;\n\t\t\t\ttmpa %= MOD;\n\t\t\t\ttmpb = (lazy * k) % MOD;\n\t\t\t\ttmpb *= x;\n\t\t\t\ttmpb %= MOD;\n\t\t\t\tans = (tmpa + tmpb) % MOD;\n\t\t\t}\n\t\t} else// y > p[t-1]\n\t\t{\n\t\t\tif (x < p[t - 1]) {\n\t\t\t\tans = work(x, p[t - 1], k, lazy);\n\t\t\t\tans = (ans + work(x, y - p[t - 1], k - p[t - 1], lazy + p[t - 1])) % MOD;\n\t\t\t} else {\n\t\t\t\tans = work(p[t - 1], p[t - 1], k, lazy);\n\t\t\t\tans = (ans + work(x - p[t - 1], p[t - 1], k - p[t - 1], lazy + p[t - 1])) % MOD;\n\t\t\t\tans = (ans + work(p[t - 1], y - p[t - 1], k - p[t - 1], lazy + p[t - 1])) % MOD;\n\t\t\t\tans = (ans + work(x - p[t - 1], y - p[t - 1], k, lazy)) % MOD;\n\t\t\t}\n\t\t}\n//\t\ttr(x, y, k, lazy, ans);\n\n\t\treturn ans;\n\t}\n\n\t// a^b\n\tlong power(long a, long b) {\n\t\tlong x = 1, y = a;\n\t\twhile (b > 0) {\n\t\t\tif (b % 2 != 0) {\n\t\t\t\tx = (x * y) % MOD;\n\t\t\t}\n\t\t\ty = (y * y) % MOD;\n\t\t\tb /= 2;\n\t\t}\n\t\treturn x % MOD;\n\t}\n\n\tprivate long gcd(long a, long b) {\n\t\twhile (a != 0) {\n\t\t\tlong tmp = b % a;\n\t\t\tb = a;\n\t\t\ta = tmp;\n\t\t}\n\t\treturn b;\n\t}\n\n\tvoid run() throws Exception {\n\t\tis = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!INPUT.isEmpty())\n\t\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\tprivate boolean vis[];\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\n\tprivate String ns() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '\n\t\t\t\t\t\t\t\t\t// ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate char[] ns(int n) {\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n) {\n\t\t\tif (!(isSpaceChar(b)))\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate List na2(int n) {\n\t\tList a = new ArrayList();\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta.add(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(int n) {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nl();\n\t\treturn a;\n\t}\n\n\tprivate long[][] nl(int n, int m) {\n\t\tlong[][] a = new long[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nl(m);\n\t\treturn a;\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate static void tr(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tpublic class Pair {\n\n\t\t/**\n\t\t * Key of this Pair.\n\t\t */\n\t\tprivate K key;\n\n\t\t/**\n\t\t * Gets the key for this pair.\n\t\t * \n\t\t * @return key for this pair\n\t\t */\n\t\tpublic K getKey() {\n\t\t\treturn key;\n\t\t}\n\n\t\t/**\n\t\t * Value of this this Pair.\n\t\t */\n\t\tprivate V value;\n\n\t\t/**\n\t\t * Gets the value for this pair.\n\t\t * \n\t\t * @return value for this pair\n\t\t */\n\t\tpublic V getValue() {\n\t\t\treturn value;\n\t\t}\n\n\t\t/**\n\t\t * Creates a new pair\n\t\t * \n\t\t * @param key The key for this pair\n\t\t * @param value The value to use for this pair\n\t\t */\n\t\tpublic Pair(K key, V value) {\n\t\t\tthis.key = key;\n\t\t\tthis.value = value;\n\t\t}\n\n\t\t/**\n\t\t *

\n\t\t * String representation of this Pair.\n\t\t *

\n\t\t *\n\t\t *

\n\t\t * The default name/value delimiter '=' is always used.\n\t\t *

\n\t\t *\n\t\t * @return String representation of this Pair\n\t\t */\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn key + \"=\" + value;\n\t\t}\n\n\t\t/**\n\t\t *

\n\t\t * Generate a hash code for this Pair.\n\t\t *

\n\t\t *\n\t\t *

\n\t\t * The hash code is calculated using both the name and the value of the\n\t\t * Pair.\n\t\t *

\n\t\t *\n\t\t * @return hash code for this Pair\n\t\t */\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\t// name's hashCode is multiplied by an arbitrary prime number (13)\n\t\t\t// in order to make sure there is a difference in the hashCode between\n\t\t\t// these two parameters:\n\t\t\t// name: a value: aa\n\t\t\t// name: aa value: a\n\t\t\treturn key.hashCode() * 13 + (value == null ? 0 : value.hashCode());\n\t\t}\n\n\t\t/**\n\t\t *

\n\t\t * Test this Pair for equality with another Object.\n\t\t *

\n\t\t *\n\t\t *

\n\t\t * If the Object to be tested is not a Pair or is\n\t\t * null, then this method returns false.\n\t\t *

\n\t\t *\n\t\t *

\n\t\t * Two Pairs are considered equal if and only if both the names and\n\t\t * values are equal.\n\t\t *

\n\t\t *\n\t\t * @param o the Object to test for equality with this\n\t\t * Pair\n\t\t * @return true if the given Object is equal to this\n\t\t * Pair else false\n\t\t */\n\t\t@Override\n\t\tpublic boolean equals(Object o) {\n\t\t\tif (this == o)\n\t\t\t\treturn true;\n\t\t\tif (o instanceof Pair) {\n\t\t\t\tPair pair = (Pair) o;\n\t\t\t\tif (key != null ? !key.equals(pair.key) : pair.key != null)\n\t\t\t\t\treturn false;\n\t\t\t\tif (value != null ? !value.equals(pair.value) : pair.value != null)\n\t\t\t\t\treturn false;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "647d4d79bda075e73d23382481bfff3e", "src_uid": "1ab085026ce43810acf98cc4bf8faf26", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class FindACar {\n \n int N = 30;\n int MOD = (int) 1e9 + 7;\n \n int a, b, c;\n \n int[][][][] dp = new int[N + 1][2][2][2];\n int[][][][] cnt = new int[N + 1][2][2][2];\n \n void solve() {\n int q = in.nextInt();\n while (q-- > 0) {\n int x1 = in.nextInt() - 1, y1 = in.nextInt() - 1, x2 = in.nextInt() - 1, y2 = in.nextInt() - 1, k = in.nextInt() - 1;\n \n long ans = 0;\n ans = (ans + calc(x2, y2, k)) % MOD;\n ans = (ans - calc(x1 - 1, y2, k) + MOD) % MOD;\n ans = (ans - calc(x2, y1 - 1, k) + MOD) % MOD;\n ans = (ans + calc(x1 - 1, y1 - 1, k)) % MOD;\n \n out.println(ans);\n }\n }\n \n int calc(int x, int y, int k) {\n if (x < 0 || y < 0) return 0;\n \n for (int i = 0; i <= N; i++)\n for (int j = 0; j < 2; j++)\n for (int u = 0; u < 2; u++) \n for (int v = 0; v < 2; v++) \n dp[i][j][u][v] = cnt[i][j][u][v] = -1;\n \n a = x;\n b = y;\n c = k;\n return dfs1(N, 1, 1, 1);\n }\n \n int dfs1(int i, int ea, int eb, int ec) {\n if (i < 0) return 1;\n if (dp[i][ea][eb][ec] >= 0) return dp[i][ea][eb][ec];\n \n int bit_a = (a >> i) & 1;\n int bit_b = (b >> i) & 1;\n int bit_c = (c >> i) & 1;\n \n long res = 0;\n \n int nec = ec == 1 && bit_c == 0 ? 1 : 0;\n int nea = ea == 1 && bit_a == 0 ? 1 : 0;\n int neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + dfs1(i - 1, nea, neb, nec)) % MOD;\n \n if ((eb == 0 || bit_b == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 0 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + (1L << i) * dfs2(i - 1, nea, neb, nec) % MOD + dfs1(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + (1L << i) * dfs2(i - 1, nea, neb, nec) % MOD + dfs1(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (eb == 0 || bit_b == 1)) {\n nec = ec == 1 && bit_c == 0 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + dfs1(i - 1, nea, neb, nec)) % MOD;\n }\n \n return dp[i][ea][eb][ec] = (int) res;\n }\n \n int dfs2(int i, int ea, int eb, int ec) {\n if (i < 0) return 1;\n if (cnt[i][ea][eb][ec] >= 0) return cnt[i][ea][eb][ec];\n \n int bit_a = (a >> i) & 1;\n int bit_b = (b >> i) & 1;\n int bit_c = (c >> i) & 1;\n \n long res = 0;\n \n int nec = ec == 1 && bit_c == 0 ? 1 : 0;\n int nea = ea == 1 && bit_a == 0 ? 1 : 0;\n int neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n \n if ((eb == 0 || bit_b == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 0 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (eb == 0 || bit_b == 1)) {\n nec = ec == 1 && bit_c == 0 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n }\n \n return cnt[i][ea][eb][ec] = (int) res;\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 FindACar().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8082fb9d38dd55dd980d4c1fddc5c926", "src_uid": "1ab085026ce43810acf98cc4bf8faf26", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class FindACar {\n \n int N = 30;\n int MOD = (int) 1e9 + 7;\n \n int a, b, c;\n \n int[][][][] dp = new int[N + 1][2][2][2];\n int[][][][] cnt = new int[N + 1][2][2][2];\n \n void solve() {\n int q = in.nextInt();\n while (q-- > 0) {\n int x1 = in.nextInt() - 1, y1 = in.nextInt() - 1, x2 = in.nextInt() - 1, y2 = in.nextInt() - 1, k = in.nextInt() - 1;\n \n long ans = 0;\n ans = (ans + calc(x2, y2, k)) % MOD;\n ans = (ans - calc(x1 - 1, y2, k) + MOD) % MOD;\n ans = (ans - calc(x2, y1 - 1, k) + MOD) % MOD;\n ans = (ans + calc(x1 - 1, y1 - 1, k)) % MOD;\n \n out.println(ans);\n }\n }\n \n int calc(int x, int y, int k) {\n if (x < 0 || y < 0) return 0;\n \n for (int i = 0; i <= N; i++)\n for (int j = 0; j < 2; j++)\n for (int u = 0; u < 2; u++) \n for (int v = 0; v < 2; v++) \n dp[i][j][u][v] = cnt[i][j][u][v] = -1;\n \n a = x;\n b = y;\n c = k;\n return dfs1(N, 1, 1, 1);\n }\n \n int dfs1(int i, int ea, int eb, int ec) {\n if (i < 0) return 1;\n if (dp[i][ea][eb][ec] >= 0) return dp[i][ea][eb][ec];\n \n int bit_a = (a >> i) & 1;\n int bit_b = (b >> i) & 1;\n int bit_c = (c >> i) & 1;\n \n long res = 0;\n \n int nec = ec == 1 && bit_c == 0 ? 1 : 0;\n int nea = ea == 1 && bit_a == 0 ? 1 : 0;\n int neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + dfs1(i - 1, nea, neb, nec)) % MOD;\n \n if ((eb == 0 || bit_b == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 0 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + (1L << i) * dfs2(i - 1, nea, neb, nec) % MOD + dfs1(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + (1L << i) * dfs2(i - 1, nea, neb, nec) % MOD + dfs1(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (eb == 0 || bit_b == 1)) {\n nec = ec == 1 && bit_c == 0 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + dfs1(i - 1, nea, neb, nec)) % MOD;\n }\n \n return (int) res;\n }\n \n int dfs2(int i, int ea, int eb, int ec) {\n if (i < 0) return 1;\n if (cnt[i][ea][eb][ec] >= 0) return cnt[i][ea][eb][ec];\n \n int bit_a = (a >> i) & 1;\n int bit_b = (b >> i) & 1;\n int bit_c = (c >> i) & 1;\n \n long res = 0;\n \n int nec = ec == 1 && bit_c == 0 ? 1 : 0;\n int nea = ea == 1 && bit_a == 0 ? 1 : 0;\n int neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n \n if ((eb == 0 || bit_b == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 0 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (ec == 0 || bit_c == 1)) {\n nec = ec == 1 && bit_c == 1 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 0 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n }\n \n if ((ea == 0 || bit_a == 1) && (eb == 0 || bit_b == 1)) {\n nec = ec == 1 && bit_c == 0 ? 1 : 0;\n nea = ea == 1 && bit_a == 1 ? 1 : 0;\n neb = eb == 1 && bit_b == 1 ? 1 : 0;\n res = (res + dfs2(i - 1, nea, neb, nec)) % MOD;\n }\n \n return (int) res;\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 FindACar().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "183d2d408f8a741d3048a66c25d5ffa5", "src_uid": "1ab085026ce43810acf98cc4bf8faf26", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.function.Consumer;\n\npublic class Solution456 {\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//\n// stringBuilder.append(\"50 4950 \");\n// for (int t = 0; t < 50; t++) {\n// stringBuilder.append(\" 99 100 80 \");\n// }\n\n// stringBuilder.append(\"4 319\\n\" +\n// \"63 79 89\\n\" +\n// \"79 97 91\\n\" +\n// \"75 87 88\\n\" +\n// \"75 90 83\");\n\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 private static void solve() throws IOException {\n int n = sc.nextInt();\n tx = sc.nextInt();\n int[][] data = new int[n][];\n for (int i = 0; i < n; i++) {\n data[i] = sc.na(3);\n }\n double max = 1000000000;\n double min = 0;\n\n while (!r(max, min)) {\n double mid = (max + min) / 2;\n if (v(data, mid)) {\n max = mid;\n } else {\n min = mid;\n }\n }\n out.println(min);\n }\n\n static boolean r(double l1, double l2) {\n\n return Math.abs(l1 - l2) / Math.max(1, Math.max(l1, l2)) < 0.0000000000001;\n }\n\n\n private static boolean v(int[][] data, double mid) {\n val = mid;\n return sv(data);\n }\n\n private static double val;\n private static int tx;\n\n private static boolean sv(int[][] data) {\n double[][] switchr = new double[data.length + 1][tx + 1];\n\n\n for (int k = data.length - 1; k >= 0; k--) {\n for (int t = 0; t <= tx; t++) {\n int p1 = data[k][0];\n int p2 = data[k][1];\n int v = data[k][2];\n int v1 = t + p1;\n int v2 = t + p2;\n double t1 = (v1 > tx) ? (p1 + val) : (p1 + switchr[k + 1][v1]);\n double t2 = (v2 > tx) ? (p2 + val) : (p2 + switchr[k + 1][v2]);\n double exp = (t1 * v + (100 - v) * t2) / 100;\n switchr[k][t] = Math.min(exp, val);\n }\n }\n\n return !r(switchr[0][0], val);\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 onAdd, Consumer onRemove) {\n ArrayList

toVisit = new ArrayList

(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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16d2f4d1da7eced98a0a1f96dbce9c22", "src_uid": "b461bb51eab4ff8088460c1980dacb93", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.function.Consumer;\n\npublic class Solution456 {\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//\n stringBuilder.append(\"50 4950 \");\n for (int t = 0; t < 50; t++) {\n stringBuilder.append(\" 99 100 80 \");\n }\n\n// stringBuilder.append(\"4 319\\n\" +\n// \"63 79 89\\n\" +\n// \"79 97 91\\n\" +\n// \"75 87 88\\n\" +\n// \"75 90 83\");\n\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 private static void solve() throws IOException {\n int n = sc.nextInt();\n tx = sc.nextInt();\n int[][] data = new int[n][];\n for (int i = 0; i < n; i++) {\n data[i] = sc.na(3);\n }\n double max = 1000000000;\n double min = 0;\n\n while (!r(max, min)) {\n double mid = (max + min) / 2;\n if (v(data, mid)) {\n max = mid;\n } else {\n min = mid;\n }\n }\n out.println(min);\n }\n\n static boolean r(double l1, double l2) {\n return !(Math.abs(l1 - l2) > 0.05) && Math.abs(l1 - l2) / Math.max(1, Math.max(l1, l2)) < 0.0000000000001;\n }\n\n\n private static boolean v(int[][] data, double mid) {\n val = mid;\n return sv(data);\n }\n\n private static double val;\n private static int tx;\n\n private static boolean sv(int[][] data) {\n double[][] switchr = new double[data.length + 1][tx + 1];\n\n\n for (int k = data.length - 1; k >= 0; k--) {\n for (int t = 0; t <= tx; t++) {\n int p1 = data[k][0];\n int p2 = data[k][1];\n int v = data[k][2];\n int v1 = t + p1;\n int v2 = t + p2;\n double t1 = (v1 > tx) ? (p1 + val) : (p1 + switchr[k + 1][v1]);\n double t2 = (v2 > tx) ? (p2 + val) : (p2 + switchr[k + 1][v2]);\n double exp = (t1 * v + (100 - v) * t2) / 100;\n if (exp < val) {\n if (k == 0) {\n return true;\n }\n switchr[k][t] = exp;\n } else {\n if (k == 0) {\n return false;\n }\n switchr[k][t] = val;\n }\n }\n }\n\n return !r(switchr[0][0], val);\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 onAdd, Consumer onRemove) {\n ArrayList

toVisit = new ArrayList

(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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "97639643195d1213c9577ff35174657a", "src_uid": "b461bb51eab4ff8088460c1980dacb93", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.function.Consumer;\n\npublic class Solution456 {\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 stringBuilder.append(\"4 319\\n\" +\n \"63 79 89\\n\" +\n \"79 97 91\\n\" +\n \"75 87 88\\n\" +\n \"75 90 83\");\n\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 private static void solve() throws IOException {\n int n = sc.nextInt();\n tx = sc.nextInt();\n int[][] data = new int[n][];\n for (int i = 0; i < n; i++) {\n data[i] = sc.na(3);\n }\n double max = 1000000000;\n double min = 0;\n\n while (max - min > 0.0000000001) {\n double mid = (max + min) / 2;\n if (v(data, mid)) {\n max = mid;\n } else {\n min = mid;\n }\n }\n out.println(min);\n }\n\n private static boolean v(int[][] data, double mid) {\n val = mid;\n return sv(data);\n }\n\n private static double val;\n private static int tx;\n\n private static boolean sv(int[][] data) {\n double[][] switchr = new double[data.length + 1][tx + 1];\n\n\n for (int k = data.length - 1; k >= 0; k--) {\n for (int t = 0; t <= tx; t++) {\n int p1 = data[k][0];\n int p2 = data[k][1];\n int v = data[k][2];\n int v1 = t + p1;\n int v2 = t + p2;\n double t1 = (v1 > tx) ? (p1 + val) : (p1 + switchr[k + 1][v1]);\n double t2 = (v2 > tx) ? (p2 + val) : (p2 + switchr[k + 1][v2]);\n double exp = (t1 * v + (100 - v) * t2) / 100;\n switchr[k][t] = Math.min(exp, val);\n }\n }\n\n return Math.abs(switchr[0][0] - val) > 0.000000000001;\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 onAdd, Consumer onRemove) {\n ArrayList

toVisit = new ArrayList

(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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3d5e891b7a8251b04f43dd2571a6a0df", "src_uid": "b461bb51eab4ff8088460c1980dacb93", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.function.Consumer;\n\npublic class Solution456 {\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// stringBuilder.append(\"2 30\\n\" +\n// \"20 30 80\\n\" +\n// \"3 9 85\");\n\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 private static void solve() throws IOException {\n int n = sc.nextInt();\n tx = sc.nextInt();\n int[][] data = new int[n][];\n for (int i = 0; i < n; i++) {\n data[i] = sc.na(3);\n }\n double max = 1000000000;\n double min = 0;\n\n while (max - min > 0.0000000001) {\n double mid = (max + min) / 2;\n if (v(data, mid)) {\n max = mid;\n } else {\n min = mid;\n }\n }\n out.println(min);\n }\n\n private static boolean v(int[][] data, double mid) {\n val = mid;\n return sv(data);\n }\n\n private static double val;\n private static int tx;\n\n private static boolean sv(int[][] data) {\n double[][] switchr = new double[data.length + 1][tx + 1];\n\n\n for (int k = data.length - 1; k >= 0; k--) {\n for (int t = 0; t <= tx; t++) {\n int p1 = data[k][0];\n int p2 = data[k][1];\n int v = data[k][2];\n int v1 = t + p1;\n int v2 = t + p2;\n double t1 = (v1 > tx) ? (val) : (p1 + switchr[k + 1][v1]);\n double t2 = (v2 > tx) ? (val) : (p2 + switchr[k + 1][v2]);\n double exp = (t1 * v + (100 - v) * t2) / 100;\n switchr[k][t] = Math.min(exp, val);\n }\n }\n\n return Math.abs(switchr[0][0] - val) > 0.000000000001;\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 onAdd, Consumer onRemove) {\n ArrayList

toVisit = new ArrayList

(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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "222fa26de34e05a824b6ff5effaaa1eb", "src_uid": "b461bb51eab4ff8088460c1980dacb93", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD\n {\n public void solve(int testNumber, Scanner in, PrintWriter out)\n {\n int T = 1;\n while (T-- > 0)\n {\n solveOne(in, out);\n }\n }\n\n private void solveOne(Scanner in, PrintWriter out)\n {\n int N = in.nextInt();\n int nums[] = CPUtils.readIntArray(N, in);\n if (N > 90)\n {\n out.println(1);\n return;\n }\n int ans = Integer.MAX_VALUE;\n for (int i = 0; i < N; i++)\n {\n for (int l = 0; l < i; l++)\n {\n for (int r = i; r < N; r++)\n {\n int resL = 0, resR = 0;\n for (int ll = l; ll < i; ll++) resL ^= nums[ll];\n for (int rr = i; rr <= r; rr++) resR ^= nums[rr];\n if (resL > resR)\n {\n ans = Math.min(ans, r - l - 1);\n }\n }\n }\n }\n if (ans == Integer.MAX_VALUE)\n {\n out.println(-1);\n } else\n {\n out.println(ans);\n }\n }\n\n }\n\n static class CPUtils\n {\n public static int[] readIntArray(int size, Scanner in)\n {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n {\n array[i] = in.nextInt();\n }\n return array;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24fca198bef49ab1ea9774e1688d90c6", "src_uid": "51ad613842de8eff6226c97812118b61", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class CF_1456_B{\n //SOLUTION BEGIN\n void pre() throws Exception{}\n void solve(int TC) throws Exception{\n int N = ni();\n int[] A = new int[N];\n for(int i = 0; i< N; i++)A[i] = ni();\n for(int i = 0; i< N-2; i++)if(Integer.highestOneBit(A[i]) == Integer.highestOneBit(A[i+2])){\n pn(1);\n return;\n }\n int ans = INF;\n for(int l = 0; l < N; l++){\n for(int r = l+1; r < N; r++){\n int Xl = 0;\n for(int l2 = l; l2 >= 0; l2--){\n Xl ^= A[l2];\n int Xr = 0;\n for(int r2 = r; r2 < N; r2++){\n Xr ^= A[r2];\n if(Xl > Xr)\n ans = Math.min(ans, l-l2 + r2-r);\n }\n }\n }\n }\n if(ans == INF)ans = -1;\n pn(ans);\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 static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}\n final long IINF = (long)1e17;\n final int INF = (int)1e9+2;\n DecimalFormat df = new DecimalFormat(\"0.00000000000\");\n double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;\n static boolean multipleTC = false, memory = true, fileIO = false;\n FastReader in;PrintWriter out;\n void run() throws Exception{\n long ct = System.currentTimeMillis();\n if (fileIO) {\n in = new FastReader(\"\");\n out = new PrintWriter(\"\");\n } else {\n in = new FastReader();\n out = new PrintWriter(System.out);\n }\n //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 System.err.println(System.currentTimeMillis() - ct);\n }\n public static void main(String[] args) throws Exception{\n if(memory)new Thread(null, new Runnable() {public void run(){try{new CF_1456_B().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, \"1\", 1 << 28).start();\n else new CF_1456_B().run();\n }\n int[][] make(int n, int e, int[] from, int[] to, boolean f){\n int[][] g = new int[n][];int[]cnt = new int[n];\n for(int i = 0; i< e; i++){\n cnt[from[i]]++;\n if(f)cnt[to[i]]++;\n }\n for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];\n for(int i = 0; i< e; i++){\n g[from[i]][--cnt[from[i]]] = to[i];\n if(f)g[to[i]][--cnt[to[i]]] = from[i];\n }\n return g;\n }\n int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){\n int[][][] g = new int[n][][];int[]cnt = new int[n];\n for(int i = 0; i< e; i++){\n cnt[from[i]]++;\n if(f)cnt[to[i]]++;\n }\n for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];\n for(int i = 0; i< e; i++){\n g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0};\n if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1};\n }\n return g;\n }\n int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}\n int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}\n long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n void p(Object... o){for(Object oo:o)out.print(oo+\" \");}\n void pn(Object... o){for(int i = 0; i< o.length; i++)out.print(o[i]+(i+1 < o.length?\" \":\"\\n\"));}\n void pni(Object... o){for(Object oo:o)out.print(oo+\" \");out.println();out.flush();}\n String n()throws Exception{return in.next();}\n String nln()throws Exception{return in.nextLine();}\n int ni()throws Exception{return Integer.parseInt(in.next());}\n long nl()throws Exception{return Long.parseLong(in.next());}\n double nd()throws Exception{return Double.parseDouble(in.next());}\n\n class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public FastReader(String s) throws Exception{\n br = new BufferedReader(new FileReader(s));\n }\n\n String next() throws Exception{\n while (st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine());\n }catch (IOException e){\n throw new Exception(e.toString());\n }\n }\n return st.nextToken();\n }\n\n String nextLine() throws Exception{\n String str;\n try{\n str = br.readLine();\n }catch (IOException e){\n throw new Exception(e.toString());\n }\n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2724c296c869fd58e12236f1d868fe41", "src_uid": "51ad613842de8eff6226c97812118b61", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.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 A = new ArrayList<>();\n\t\tArrayList 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b2637acf24ea1c9ad932018cc19f534a", "src_uid": "8d43a542d5bf79d15926c4a6a5ff608f", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Vadim Semenov\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static final class TaskG {\n public void solve(int __, InputReader in, PrintWriter out) {\n int qty = in.nextInt();\n long targetGcd = in.nextLong();\n long targetLcm = in.nextLong();\n long[] rangs = in.nextLongArray(qty);\n if (targetLcm % targetGcd != 0) {\n out.println(0);\n return;\n }\n long[] primes = getPrimes(targetLcm, rangs);\n int[] lcmFactorization = factorize(targetLcm, primes);\n int[] gcdFactorization = factorize(targetGcd, primes);\n int primesQty = 0;\n for (int i = 0; i < primes.length; ++i) {\n if (lcmFactorization[i] > gcdFactorization[i]) {\n primes[primesQty] = primes[i];\n lcmFactorization[primesQty] = lcmFactorization[i];\n gcdFactorization[primesQty] = gcdFactorization[i];\n ++primesQty;\n }\n }\n if (primesQty < primes.length) {\n primes = Arrays.copyOfRange(primes, 0, primesQty);\n lcmFactorization = Arrays.copyOfRange(lcmFactorization, 0, primesQty);\n gcdFactorization = Arrays.copyOfRange(gcdFactorization, 0, primesQty);\n }\n boolean[] possibleGcd = new boolean[qty];\n boolean[] possibleLcm = new boolean[qty];\n int[] maskGcd = new int[qty];\n int[] maskLcm = new int[qty];\n for (int i = 0; i < qty; ++i) {\n long rang = rangs[i];\n possibleGcd[i] = rang % targetGcd == 0;\n possibleLcm[i] = targetLcm % rang == 0;\n if (!possibleGcd[i] && !possibleLcm[i]) continue;\n int[] factorization = factorize(rang, primes);\n for (int j = 0; j < primes.length; ++j) {\n if (factorization[j] > gcdFactorization[j]) {\n maskGcd[i] |= 1 << j;\n }\n if (factorization[j] < lcmFactorization[j]) {\n maskLcm[i] |= 1 << j;\n }\n }\n }\n int totalMask = (1 << primes.length) - 1;\n int[] count = new int[totalMask + 1];\n for (int i = 0; i < qty; ++i) {\n if (possibleGcd[i]) {\n count[maskGcd[i]]++;\n }\n }\n for (int mask = totalMask; mask > 0; --mask) {\n for (int subMask = (mask - 1) & mask; subMask > 0; subMask = (subMask - 1) & mask) {\n count[mask] += count[subMask];\n }\n count[mask] += count[0];\n }\n long answer = 0;\n for (int i = 0; i < qty; ++i) {\n if (possibleLcm[i]) {\n answer += count[totalMask ^ maskLcm[i]];\n }\n }\n out.println(answer);\n }\n\n private int[] factorize(long number, long[] primes) {\n int[] powers = new int[primes.length];\n for (int i = 0; i < primes.length; ++i) {\n while (number % primes[i] == 0) {\n powers[i]++;\n number /= primes[i];\n }\n }\n return powers;\n }\n\n private long[] getPrimes(long number, long[] rangs) {\n List primes = new ArrayList<>();\n for (int p = 2; p <= Math.min(1_000_000, 10 + Math.sqrt(number)); ++p) {\n if (number % p == 0) {\n primes.add((long) p);\n while (number % p == 0) {\n number /= p;\n }\n }\n }\n if (number > 1) {\n primes.add(number);\n for (long rang : rangs) {\n long gcd = gcd(rang, number);\n if (gcd != 1 && gcd != number) {\n long div = number / gcd;\n primes.set(primes.size() - 1, Math.min(gcd, div));\n if (gcd != div) {\n primes.add(Math.max(gcd, div));\n }\n }\n }\n }\n long[] result = new long[primes.size()];\n for (int i = 0; i < primes.size(); ++i) {\n result[i] = primes.get(i);\n }\n return result;\n }\n\n private static long gcd(long a, long b) {\n while (b != 0) {\n long tmp = a % b;\n a = b;\n b = tmp;\n }\n return a;\n }\n\n }\n\n static class InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n }\n\n public long[] nextLongArray(int size) {\n long[] array = new long[size];\n for (int i = 0; i < size; ++i) {\n array[i] = nextLong();\n }\n return array;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public String readLine() {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad0373784819d460145a0393e5d53c12", "src_uid": "8d43a542d5bf79d15926c4a6a5ff608f", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.HashMap;\nimport java.util.Set;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.util.HashSet;\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 firstIndex = 0;\n\t\tint secondIndex = 0;\n\t\tSet goodHash = new HashSet();\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\tlengthFirst[firstIndex] = lengthFirst[vertex[i]] + 1;\n\t\t\t\thashFirst[firstIndex] = hashFirst[vertex[i]] + power[lengthFirst[vertex[i]]] * label[i];\n\t\t\t\tgoodHash.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\tCounter firstCounter = new Counter();\n\t\tCounter secondCounter = new Counter();\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 += secondCounter.get(hashFirst[firstIndex]);\n\t\t\t\tfirstCounter.add(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\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\tif (goodHash.contains(curHash)) {\n\t\t\t\t\t\tanswer += firstCounter.get(curHash);\n\t\t\t\t\t\tsecondCounter.add(curHash);\n\t\t\t\t\t}\n\t\t\t\t} while (current != 0);\n\t\t\t}\n\t\t\tout.printLine(answer);\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\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\nclass Counter extends HashMap {\n\tpublic Counter() {\n\t\tsuper();\n\t}\n\n\tpublic void add(K key) {\n\t\tput(key, get(key) + 1);\n\t}\n\n\tpublic Long get(Object key) {\n\t\tif (containsKey(key))\n\t\t\treturn super.get(key);\n\t\treturn 0L;\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d3762cda544fe178c6ed14b9ada4498c", "src_uid": "b0cd7ee6b5f13f977def002b53f8f443", "difficulty": 2100.0} {"lang": "Java 11", "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 = \"\";\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 stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5bda29ab5b229c98d4f1dd24a444e076", "src_uid": "a3603f5ed0d8bdb7fe829342991b78e6", "difficulty": 2600.0} {"lang": "Java 11", "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 stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1eb28a47645acea771978737a6e1c55f", "src_uid": "a3603f5ed0d8bdb7fe829342991b78e6", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.nio.CharBuffer;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.NoSuchElementException;\n\npublic class P1505G {\n\n private static final int[][][] BRAILLES = new int[][][]\n {\n {{1, 0}, {0, 0}, {0, 0}},//a\n {{1, 0}, {1, 0}, {0, 0}},//b\n {{1, 1}, {0, 0}, {0, 0}},//c\n {{1, 1}, {0, 1}, {0, 0}},//d\n {{1, 0}, {0, 1}, {0, 0}},//e\n {{1, 1}, {1, 0}, {0, 0}},//f\n {{1, 1}, {1, 1}, {0, 0}},//g\n {{1, 0}, {1, 1}, {0, 0}},//h\n {{0, 1}, {1, 0}, {0, 0}},//i\n {{0, 1}, {1, 1}, {0, 0}},//j\n {{1, 0}, {0, 0}, {1, 0}},//k\n {{1, 0}, {1, 0}, {1, 0}},//l\n {{1, 1}, {0, 0}, {1, 0}},//m\n {{1, 1}, {0, 1}, {0, 0}},//n\n {{1, 0}, {0, 1}, {1, 0}},//o\n {{1, 1}, {1, 0}, {1, 0}},//p\n {{1, 1}, {1, 1}, {1, 0}},//q\n {{1, 0}, {1, 1}, {1, 0}},//r\n {{0, 1}, {1, 0}, {1, 0}},//s\n {{0, 1}, {1, 1}, {1, 0}},//t\n {{1, 0}, {0, 0}, {1, 1}},//u\n {{1, 0}, {1, 0}, {1, 1}},//v\n {{0, 1}, {1, 1}, {0, 1}},//w\n {{1, 1}, {0, 0}, {1, 1}},//x\n {{1, 1}, {0, 1}, {1, 1}},//y\n {{1, 0}, {0, 1}, {1, 1}},//z\n };\n\n public static void main(String[] args) {\n SimpleScanner scanner = new SimpleScanner(System.in);\n PrintWriter writer = new PrintWriter(System.out);\n\n int n = scanner.nextInt();\n while (n-- > 0) {\n int[] r = new int[3];\n int[] c = new int[2];\n for (int i = 0; i < 3; ++i)\n r[i] = scanner.nextInt();\n for (int i = 0; i < 2; ++i)\n c[i] = scanner.nextInt();\n for (int i = 0; i < 26; ++i) {\n if (cntSame(BRAILLES[i], r, c)) {\n writer.print((char) ('a' + i));\n break;\n }\n }\n }\n writer.println();\n\n writer.close();\n }\n\n private static boolean cntSame(int[][] braille, int[] r0, int[] c0) {\n int[] r = new int[3];\n int[] c = new int[2];\n for (int i = 0; i < 3; ++i)\n for (int j = 0; j < 2; ++j) {\n r[i] += braille[i][j];\n c[j] += braille[i][j];\n }\n return Arrays.equals(r, r0) && Arrays.equals(c, c0);\n }\n\n private static void search(int k, int[] x, List result) {\n if (k == 5) {\n if (x[0] + x[1] == x[2] + x[3] + x[4])\n result.add(Arrays.copyOf(x, 5));\n return;\n }\n for (int i = 0; i <= (k < 2 ? 3 : 2); ++i) {\n x[k] = i;\n search(k + 1, x, result);\n }\n }\n\n private static class SimpleScanner {\n\n private static final int BUFFER_SIZE = 10240;\n\n private Readable in;\n private CharBuffer buffer;\n private boolean eof;\n\n private SimpleScanner(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n buffer = CharBuffer.allocate(BUFFER_SIZE);\n buffer.limit(0);\n eof = false;\n }\n\n\n private char read() {\n if (!buffer.hasRemaining()) {\n buffer.clear();\n int n;\n try {\n n = in.read(buffer);\n } catch (IOException e) {\n n = -1;\n }\n if (n <= 0) {\n eof = true;\n return '\\0';\n }\n buffer.flip();\n }\n return buffer.get();\n }\n\n private void checkEof() {\n if (eof)\n throw new NoSuchElementException();\n }\n\n private char nextChar() {\n checkEof();\n char b = read();\n checkEof();\n return b;\n }\n\n private String next() {\n char b;\n do {\n b = read();\n checkEof();\n } while (Character.isWhitespace(b));\n StringBuilder sb = new StringBuilder();\n do {\n sb.append(b);\n b = read();\n } while (!eof && !Character.isWhitespace(b));\n return sb.toString();\n }\n\n private int nextInt() {\n return Integer.parseInt(next());\n }\n\n private long nextLong() {\n return Long.parseLong(next());\n }\n\n private double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4b67f08b298957544a2d1e02e0fa37e5", "src_uid": "a3603f5ed0d8bdb7fe829342991b78e6", "difficulty": 2600.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\npublic class G_EncodedMessage {\r\n\tpublic static void main(String[] args)throws IOException {\r\n\t\tString list[]=new String[26+1];\r\n\t\tfor(int i=1;i<=26;i++){\r\n\t\t\tString s=new String();\r\n\t\t\tswitch(i){\r\n\t\t\t\tcase 1: s=\"10010\";break;\r\n\t\t\t\tcase 2: s=\"11020\";break;\r\n\t\t\t\tcase 3: s=\"20011\";break;\r\n\t\t\t\tcase 4: s=\"21012\";break;\r\n\t\t\t\tcase 5: s=\"11011\";break;\r\n\t\t\t\tcase 6: s=\"21021\";break;\r\n\t\t\t\tcase 7: s=\"22021\";break;\r\n\t\t\t\tcase 8: s=\"12021\";break;\r\n\t\t\t\tcase 9: s=\"*\";break;\r\n\t\t\t\tcase 10: s=\"12012\";break;\r\n\t\t\t\tcase 11: s=\"10120\";break;\r\n\t\t\t\tcase 12: s=\"11130\";break;\r\n\t\t\t\tcase 13: s=\"20121\";break;\r\n\t\t\t\tcase 14: s=\"21122\";break;\r\n\t\t\t\tcase 15: s=\"11121\";break;\r\n\t\t\t\tcase 16: s=\"21131\";break;\r\n\t\t\t\tcase 17: s=\"22132\";break;\r\n\t\t\t\tcase 18: s=\"12131\";break;\r\n\t\t\t\tcase 19: s=\"*\";break;\r\n\t\t\t\tcase 20: s=\"12122\";break;\r\n\t\t\t\tcase 21: s=\"10221\";break;\r\n\t\t\t\tcase 22: s=\"11231\";break;\r\n\t\t\t\tcase 23: s=\"12113\";break;\r\n\t\t\t\tcase 24: s=\"20222\";break;\r\n\t\t\t\tcase 25: s=\"21223\";break;\r\n\t\t\t\tcase 26: s=\"11222\";break;\r\n\t\t\t}\r\n\t\t\tlist[i]=s;\r\n\t\t}\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tString res=new String();\r\n\t\tint n=Integer.parseInt(br.readLine());\r\n\t\tfor(int i=0;i K)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tint r = d[step ^ 1][n - next][next][v] + t;\n\t\t\t\t\t\t\tif (r >= MOD)\n\t\t\t\t\t\t\t\tr -= MOD;\n\t\t\t\t\t\t\td[step ^ 1][n - next][next][v] = r;\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\tstep ^= 1;\n\t\t}\n\t\tout.write(ans + \"\\n\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t// in = new BufferedReader(new FileReader(filename+\".in\"));\n\t\t\t// out = new BufferedWriter(new FileWriter(filename+\".out\"));\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tpublic int iread() throws Exception {\n\t\treturn Integer.parseInt(readword());\n\t}\n\n\tpublic double dread() throws Exception {\n\t\treturn Double.parseDouble(readword());\n\t}\n\n\tpublic long lread() throws Exception {\n\t\treturn Long.parseLong(readword());\n\t}\n\n\tBufferedReader in;\n\n\tBufferedWriter out;\n\n\tpublic String readword() throws IOException {\n\t\tStringBuilder b = new StringBuilder();\n\t\tint c;\n\t\tc = in.read();\n\t\twhile (c >= 0 && c <= ' ')\n\t\t\tc = in.read();\n\t\tif (c < 0)\n\t\t\treturn \"\";\n\t\twhile (c > ' ') {\n\t\t\tb.append((char) c);\n\t\t\tc = in.read();\n\t\t}\n\t\treturn b.toString();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t} catch (Exception e) {\n\n\t\t}\n\t\t// new Thread(new Main()).start();\n\t\tnew Thread(null, new Main(), \"1\", 1 << 25).start();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "beac0dbd46d2ac9daa505a2a914538d7", "src_uid": "c6d275b1e1d5c9e39e2cf990a635fa6b", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "733010e18244f17d96eccf039dc368e2", "src_uid": "c6d275b1e1d5c9e39e2cf990a635fa6b", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.io.*;\n\nimport java.awt.geom.Point2D;\nimport java.text.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tfinal String filename = \"\";\n\n\tfinal int MOD = 1000000007;\n\n\tpublic void solve() throws Exception {\n\t\tint MAX = 101;\n\t\tint INF = 1000;\n\t\tint[][] C = new int[MAX + 1][MAX + 1];\n\t\tfor (int i = 0; i <= MAX; i++) {\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] = Math.min(C[i - 1][j - 1] + C[i - 1][j], INF);\n\t\t}\n\n\t\tint N = iread(), M = iread(), K = iread();\n\t\tif (M == 1 || N == 1) {\n\t\t\tout.write(\"0\\n\");\n\t\t\treturn;\n\t\t}\n\t\tlong ans = 0;\n\t\tN /= 2;\n\t\tint[][][][] d = new int[2][N][N + 1][K + 1];\n\t\tfor (int a = 1; a <= N; a++) {\n\t\t\td[0][N - a][a][1] = 1;\n\t\t}\n\t\tint step = 0;\n\t\tfor (int m = 1; m < M; m++) {\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\tArrays.fill(d[step ^ 1][i][j], 0);\n\t\t\tfor (int n = 0; n < N; n++) {\n\t\t\t\tfor (int prev = 1; prev <= N; prev++) {\n\t\t\t\t\tfor (int k = 1; k <= K; k++) {\n\t\t\t\t\t\tint t = d[step][n][prev][k];\n\t\t\t\t\t\tif (t == 0)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t// System.out.println(\"m=\" + m + \" n=\" + n + \" prev=\"\n\t\t\t\t\t\t// + prev + \" k=\" + k+\" ans+=\"+(t*k*(M-m)));\n\t\t\t\t\t\tans = (ans + t * (M - m)) % MOD;\n\t\t\t\t\t\tfor (int next = 1; next <= n; next++) {\n\t\t\t\t\t\t\tint v = k * C[next + prev - 1][prev - 1];\n\t\t\t\t\t\t\tif (v > K)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tint r = d[step ^ 1][n - next][next][v] + t;\n\t\t\t\t\t\t\tif (r >= MOD)\n\t\t\t\t\t\t\t\tr -= MOD;\n\t\t\t\t\t\t\td[step ^ 1][n - next][next][v] = r;\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\tstep ^= 1;\n\t\t}\n\t\tout.write(ans + \"\\n\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t// in = new BufferedReader(new FileReader(filename+\".in\"));\n\t\t\t// out = new BufferedWriter(new FileWriter(filename+\".out\"));\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tpublic int iread() throws Exception {\n\t\treturn Integer.parseInt(readword());\n\t}\n\n\tpublic double dread() throws Exception {\n\t\treturn Double.parseDouble(readword());\n\t}\n\n\tpublic long lread() throws Exception {\n\t\treturn Long.parseLong(readword());\n\t}\n\n\tBufferedReader in;\n\n\tBufferedWriter out;\n\n\tpublic String readword() throws IOException {\n\t\tStringBuilder b = new StringBuilder();\n\t\tint c;\n\t\tc = in.read();\n\t\twhile (c >= 0 && c <= ' ')\n\t\t\tc = in.read();\n\t\tif (c < 0)\n\t\t\treturn \"\";\n\t\twhile (c > ' ') {\n\t\t\tb.append((char) c);\n\t\t\tc = in.read();\n\t\t}\n\t\treturn b.toString();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t} catch (Exception e) {\n\n\t\t}\n\t\t// new Thread(new Main()).start();\n\t\tnew Thread(null, new Main(), \"1\", 1 << 25).start();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ded641d7aeecf6b55c1a90a050e196f1", "src_uid": "c6d275b1e1d5c9e39e2cf990a635fa6b", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n FastScanner in;\n PrintWriter out;\n\n int getLenCost(int len, int k) {\n return (len - 1 + (k - 2)) / (k - 1);\n }\n\n void solve() {\n int n = in.nextInt();\n int k = in.nextInt();\n int[] a = new int[n];\n int sum = 0;\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n sum += a[i];\n }\n sum /= n;\n int[] balance = new int[n];\n for (int i = 0; i + 1 < n; i++) {\n balance[i + 1] = balance[i] + a[i] - sum;\n }\n List[] balances = new List[k];\n for (int i = 0; i < balances.length; i++) {\n balances[i] = new ArrayList<>();\n }\n for (int i = 0; i < n; i++) {\n balances[i % (k - 1)].add(new Balance(i, balance[i]));\n }\n for (int i = 0; i < balances.length; i++) {\n Collections.sort(balances[i]);\n }\n int[] lenOfSameBalance = new int[n];\n for (int i = 0; i < n; i++) {\n int curBalance = balance[i];\n List where = balances[(i + 1) % (k - 1)];\n int firstPos = firstPosOfSameBalance(where, i + 1, curBalance);\n if (firstPos == -1) {\n lenOfSameBalance[i] = n;\n } else {\n if (firstPos > i) {\n lenOfSameBalance[i] = firstPos - i;\n } else {\n lenOfSameBalance[i] = (n - i) + firstPos;\n }\n }\n }\n final int MAX = 20;\n int[][] len = new int[MAX][n];\n int[][] cost = new int[MAX][n];\n for (int i = 0; i < n; i++) {\n len[0][i] = lenOfSameBalance[i];\n cost[0][i] = getLenCost(lenOfSameBalance[i], k);\n }\n for (int i = 1; i < MAX; i++) {\n for (int v = 0; v < n; v++) {\n int nextV = (v + len[i - 1][v]) % n;\n len[i][v] = len[i - 1][v] + len[i - 1][nextV];\n cost[i][v] = cost[i - 1][v] + cost[i - 1][nextV];\n len[i][v] = Math.min(len[i][v], n + 10);\n cost[i][v] = Math.min(cost[i][v], Integer.MAX_VALUE / 3);\n }\n }\n int bestCost = Integer.MAX_VALUE;\n int bestStart = -1;\n for (int start = 0; start < n; start++) {\n int curPos = start;\n int curCost = 0;\n int curLen = 0;\n for (int i = MAX - 1; i >= 0; i--) {\n if (curLen + len[i][curPos] <= n) {\n int nowLen = len[i][curPos];\n curCost += cost[i][curPos];\n curLen += nowLen;\n curPos = (curPos + nowLen) % n;\n }\n }\n int moreLen = n - curLen;\n curCost += getLenCost(moreLen, k);\n if (curCost < bestCost) {\n bestCost = curCost;\n bestStart = start;\n }\n }\n List answers = new ArrayList<>();\n int moreLen = n;\n int v = bestStart;\n while (moreLen > 0) {\n int useLen = Math.min(moreLen, len[0][v]);\n makeGood(answers, a, v, useLen, sum, k);\n v = (v + useLen) % n;\n moreLen -= useLen;\n }\n if (answers.size() != bestCost) {\n throw new AssertionError();\n }\n for (int x : a) {\n if (a[x] != sum) {\n throw new AssertionError();\n }\n }\n out.println(answers.size());\n for (int[] b : answers) {\n for (int x : b) {\n out.print(x + \" \");\n }\n out.println();\n }\n }\n\n void makeGood(List answers, int[] a, int from, int len, int sum, int k) {\n if (len <= 1) {\n return;\n }\n int curSum = a[from];\n for (int cnt = 1; ; cnt++) {\n int curStart = from + (cnt - 1) * (k - 1) + 1;\n for (int i = 0; i < k - 1; i++) {\n int pos = (curStart + i) % a.length;\n curSum += a[pos];\n }\n int totalElems = cnt * (k - 1) + 1;\n int needSum = totalElems * sum;\n\n if (needSum <= curSum) {\n int more = curSum - needSum;\n for (int curSeg = cnt - 1; curSeg >= 0; curSeg--) {\n int segStart = from + curSeg * (k - 1);\n int nowSum = 0;\n for (int j = 0; j < k; j++) {\n nowSum += a[(segStart + j) % a.length];\n }\n int[] answerArray = new int[k + 1];\n Arrays.fill(answerArray, sum);\n answerArray[0] = segStart % a.length;\n answerArray[answerArray.length - 1] += more;\n for (int j = 1; j < answerArray.length; j++) {\n nowSum -= answerArray[j];\n }\n answerArray[1] += nowSum;\n answers.add(answerArray);\n for (int j = 0; j + 1 < answerArray.length; j++) {\n a[(answerArray[0] + j) % a.length] = answerArray[j + 1];\n }\n more = 0;\n }\n makeGood(answers, a, (curStart + k - 2) % a.length, len - cnt * (k - 1), sum, k);\n return;\n }\n }\n }\n\n int getFirstPosOfBalance(List positions, int needBalance) {\n int l = -1, r = positions.size();\n while (r - l > 1) {\n int mid = (l + r) >> 1;\n if (positions.get(mid).balance >= needBalance) {\n r = mid;\n } else {\n l = mid;\n }\n }\n return r;\n }\n\n int firstPosOfSameBalance(List positions, int atleastPos, int needBalance) {\n int from = getFirstPosOfBalance(positions, needBalance);\n int to = getFirstPosOfBalance(positions, needBalance + 1);\n if (from == to) {\n return -1;\n }\n int l = from - 1, r = to;\n while (r - l > 1) {\n int m = (l + r) >> 1;\n if (positions.get(m).pos >= atleastPos) {\n r = m;\n } else {\n l = m;\n }\n }\n if (r != to) {\n return positions.get(r).pos;\n }\n return positions.get(from).pos;\n }\n\n class Balance implements Comparable {\n int pos;\n int balance;\n\n public Balance(int pos, int balance) {\n this.pos = pos;\n this.balance = balance;\n }\n\n @Override\n public int compareTo(Balance o) {\n if (balance != o.balance) {\n return Integer.compare(balance, o.balance);\n }\n return Integer.compare(pos, o.pos);\n }\n\n\n @Override\n public String toString() {\n return \"Balance{\" +\n \"pos=\" + pos +\n \", balance=\" + balance +\n '}';\n }\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"G.in\"));\n out = new PrintWriter(new File(\"G.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 G().runIO();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "03a927b789d1ba7d85c5de820705a249", "src_uid": "8b9099351b979cdb61413cc039861f8d", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n FastScanner in;\n PrintWriter out;\n\n int getLenCost(int len, int k) {\n if (len <= 1) {\n return 0;\n }\n return (len - 1 + (k - 2)) / (k - 1);\n }\n\n void solve() {\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 solve(a, k);\n }\n\n void solve123() {\n Random rnd = new Random(123);\n for (int it = 0; it < 123123; it++) {\n System.err.println(\"ITER = \" + it);\n int n = 3 + rnd.nextInt(10);\n int sum = rnd.nextInt(5) * n;\n int[] a = new int[n];\n for (int i = 0; i < sum; i++) {\n a[rnd.nextInt(a.length)]++;\n }\n int k = 2 + rnd.nextInt(n - 2);\n solve(a, k);\n }\n }\n\n void solve(int[] a, int k) {\n// System.err.println(Arrays.toString(a) + \" \" + k);\n int n = a.length;\n// int k = in.nextInt();\n// int[] a = new int[n];\n int sum = 0;\n for (int i = 0; i < n; i++) {\n// a[i] = in.nextInt();\n sum += a[i];\n }\n sum /= n;\n int[] balance = new int[n];\n for (int i = 0; i + 1 < n; i++) {\n balance[i + 1] = balance[i] + a[i] - sum;\n }\n List[] balances = new List[k];\n for (int i = 0; i < balances.length; i++) {\n balances[i] = new ArrayList<>();\n }\n for (int i = 0; i < n; i++) {\n balances[i % (k - 1)].add(new Balance(i, balance[i]));\n }\n for (int i = 0; i < balances.length; i++) {\n Collections.sort(balances[i]);\n }\n int[] lenOfSameBalance = new int[n];\n for (int i = 0; i < n; i++) {\n int curBalance = balance[i];\n List where = balances[(i + 1) % (k - 1)];\n int firstPos = firstPosOfSameBalance(where, i + 1, curBalance);\n if (firstPos == -1) {\n lenOfSameBalance[i] = n;\n } else {\n if (firstPos > i) {\n lenOfSameBalance[i] = firstPos - i;\n } else {\n lenOfSameBalance[i] = (n - i) + firstPos;\n }\n }\n }\n final int MAX = 20;\n int[][] len = new int[MAX][n];\n int[][] cost = new int[MAX][n];\n for (int i = 0; i < n; i++) {\n len[0][i] = lenOfSameBalance[i];\n cost[0][i] = getLenCost(lenOfSameBalance[i], k);\n// System.err.println(i + \" -> (len = \" + len[0][i] + \", cost = \" + cost[0][i] + \")\");\n }\n for (int i = 1; i < MAX; i++) {\n for (int v = 0; v < n; v++) {\n int nextV = (v + len[i - 1][v]) % n;\n len[i][v] = len[i - 1][v] + len[i - 1][nextV];\n cost[i][v] = cost[i - 1][v] + cost[i - 1][nextV];\n len[i][v] = Math.min(len[i][v], n + 10);\n cost[i][v] = Math.min(cost[i][v], Integer.MAX_VALUE / 3);\n }\n }\n int bestCost = Integer.MAX_VALUE;\n int bestStart = -1;\n for (int start = 0; start < n; start++) {\n int curPos = start;\n int curCost = 0;\n int curLen = 0;\n for (int i = MAX - 1; i >= 0; i--) {\n if (curLen + len[i][curPos] <= n) {\n int nowLen = len[i][curPos];\n curCost += cost[i][curPos];\n// System.err.println(\"ADD COST \" + cost[i][curPos]);\n curLen += nowLen;\n curPos = (curPos + nowLen) % n;\n }\n }\n int moreLen = n - curLen;\n curCost += getLenCost(moreLen, k);\n// System.err.println(\"cost for \" + start + \" is \" + curCost + \", moreLen = \" + moreLen);\n if (curCost < bestCost) {\n bestCost = curCost;\n bestStart = start;\n }\n }\n List answers = new ArrayList<>();\n int moreLen = n;\n int v = bestStart;\n while (moreLen > 0) {\n int useLen = Math.min(moreLen, len[0][v]);\n makeGood(answers, a, v, useLen, sum, k);\n v = (v + useLen) % n;\n moreLen -= useLen;\n }\n if (answers.size() != bestCost) {\n// System.err.println(answers.size() + \", cost= \" + bestCost);\n for (int[] b : answers) {\n System.err.println(Arrays.toString(b));\n }\n throw new AssertionError();\n }\n for (int x : a) {\n if (x != sum) {\n throw new AssertionError(Arrays.toString(a));\n }\n }\n out.println(answers.size());\n for (int[] b : answers) {\n for (int x : b) {\n out.print(x + \" \");\n }\n out.println();\n }\n }\n\n void makeGood(List answers, int[] a, int from, int len, int sum, int k) {\n if (len <= 1) {\n return;\n }\n// System.err.println(from + \" \" + len);\n int curSum = a[from];\n for (int cnt = 1; ; cnt++) {\n int curStart = from + (cnt - 1) * (k - 1) + 1;\n int removeLast = 0;\n for (int i = 0; i < k - 1; i++) {\n if ((cnt - 1) * (k - 1) + 1 + i >= len) {\n removeLast++;\n continue;\n }\n int pos = (curStart + i) % a.length;\n curSum += a[pos];\n }\n int totalElems = cnt * (k - 1) + 1;\n totalElems -= removeLast;\n int needSum = totalElems * sum;\n\n if (needSum <= curSum) {\n int more = curSum - needSum;\n for (int curSeg = cnt - 1; curSeg >= 0; curSeg--) {\n int segStart = from + curSeg * (k - 1);\n int nowSum = 0;\n for (int j = 0; j < k - removeLast; j++) {\n nowSum += a[(segStart + j) % a.length];\n }\n int[] answerArray = new int[k + 1];\n Arrays.fill(answerArray, sum);\n answerArray[0] = segStart % a.length;\n answerArray[answerArray.length - 1] += more;\n\n for (int j = answerArray.length - removeLast - 1; j + 1 < answerArray.length; j++) {\n answerArray[j + 1] = a[(answerArray[0] + j) % a.length];\n }\n for (int j = 1; j < answerArray.length - removeLast; j++) {\n nowSum -= answerArray[j];\n }\n if (removeLast != 0 && more != 0) {\n throw new AssertionError();\n }\n answerArray[1] += nowSum;\n answers.add(answerArray);\n for (int j = 0; j + 1 < answerArray.length; j++) {\n a[(answerArray[0] + j) % a.length] = answerArray[j + 1];\n }\n more = 0;\n removeLast = 0;\n }\n makeGood(answers, a, (curStart + k - 2) % a.length, len - cnt * (k - 1), sum, k);\n return;\n }\n }\n }\n\n int getFirstPosOfBalance(List positions, int needBalance) {\n int l = -1, r = positions.size();\n while (r - l > 1) {\n int mid = (l + r) >> 1;\n if (positions.get(mid).balance >= needBalance) {\n r = mid;\n } else {\n l = mid;\n }\n }\n return r;\n }\n\n int firstPosOfSameBalance(List positions, int atleastPos, int needBalance) {\n int from = getFirstPosOfBalance(positions, needBalance);\n int to = getFirstPosOfBalance(positions, needBalance + 1);\n if (from == to) {\n return -1;\n }\n int l = from - 1, r = to;\n while (r - l > 1) {\n int m = (l + r) >> 1;\n if (positions.get(m).pos >= atleastPos) {\n r = m;\n } else {\n l = m;\n }\n }\n if (r != to) {\n return positions.get(r).pos;\n }\n return positions.get(from).pos;\n }\n\n class Balance implements Comparable {\n int pos;\n int balance;\n\n public Balance(int pos, int balance) {\n this.pos = pos;\n this.balance = balance;\n }\n\n @Override\n public int compareTo(Balance o) {\n if (balance != o.balance) {\n return Integer.compare(balance, o.balance);\n }\n return Integer.compare(pos, o.pos);\n }\n\n\n @Override\n public String toString() {\n return \"Balance{\" +\n \"pos=\" + pos +\n \", balance=\" + balance +\n '}';\n }\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"G.in\"));\n out = new PrintWriter(new File(\"G.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 G().runIO();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1ea99fee028e64cac78a03808aa26102", "src_uid": "8b9099351b979cdb61413cc039861f8d", "difficulty": 3500.0} {"lang": "Java 11", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n \nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n \npublic class Codeforces {\n \n\tinterface IntComparator {\n\t\tpublic int compare(int o1, int o2);\n\t}\n \n\tstatic void sort(int a[], int n, IntComparator cmp) {\n\t\tif (n == 0) {\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = i;\n\t\t\tint ca = a[i];\n\t\t\tdo {\n\t\t\t\tint nj = (j - 1) >> 1;\n\t\t\t\tint na = a[nj];\n\t\t\t\tif (cmp.compare(na, ca) >= 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ta[j] = na;\n\t\t\t\tj = nj;\n\t\t\t} while (j != 0);\n\t\t\ta[j] = ca;\n\t\t}\n\t\tint ca = a[0];\n\t\tfor (int i = n - 1; i > 0; i--) {\n\t\t\tint j = 0;\n\t\t\twhile ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {\n\t\t\t\tj <<= 1;\n\t\t\t\tj += (cmp.compare(a[j + 1], a[j + 2]) < 0) ? 2 : 1;\n\t\t\t}\n\t\t\tif ((j << 1) + 2 == i) {\n\t\t\t\tj = (j << 1) + 1;\n\t\t\t}\n\t\t\tint na = a[i];\n\t\t\ta[i] = ca;\n\t\t\tca = na;\n\t\t\twhile (j != 0 && cmp.compare(a[j], ca) < 0) {\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t\twhile (j != 0) {\n\t\t\t\tna = a[j];\n\t\t\t\ta[j] = ca;\n\t\t\t\tca = na;\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t}\n\t\ta[0] = ca;\n\t}\n \n\tstatic int n, k, a[], sum, move[], moveOffset, defer[], deferCnt, derefFirst[];\n \n\tstatic void doMove(int pos) {\n\t\tif (a[pos] < (move[(pos + 1) % n] - moveOffset) || a[(pos + k - 1) % n] < -(move[(pos + k - 1) % n] - moveOffset)) {\n\t\t\tif (deferCnt == 0) {\n\t\t\t\tderefFirst = new int[k - 1];\n\t\t\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\t\t\tderefFirst[i] = move[(pos + i + 1) % n] - moveOffset;\n\t\t\t\t\tmove[(pos + i + 1) % n] = moveOffset;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdefer[deferCnt++] = pos;\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\tint m = move[(pos + i + 1) % n] - moveOffset;\n\t\t\ta[(pos + i) % n] -= m;\n\t\t\ta[(pos + i + 1) % n] += m;\n\t\t\tmove[(pos + i + 1) % n] = moveOffset;\n\t\t}\n\t\tout.print(pos);\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tout.print(\" \" + a[(pos + i) % n]);\n\t\t}\n\t\tout.println();\n\t\tif (deferCnt > 0) {\n\t\t\tif (--deferCnt == 0) {\n\t\t\t\tpos = defer[0];\n\t\t\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\t\t\tint m = derefFirst[i];\n\t\t\t\t\ta[(pos + i) % n] -= m;\n\t\t\t\t\ta[(pos + i + 1) % n] += m;\n\t\t\t\t}\n\t\t\t\tout.print(pos);\n\t\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\t\tout.print(\" \" + a[(pos + i) % n]);\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t} else {\n\t\t\t\tdoMove(defer[deferCnt]);\n\t\t\t}\n\t\t}\n\t}\n \n\tstatic void solve() throws Exception {\n\t\tn = scanInt();\n\t\tk = scanInt();\n\t\ta = new int[n];\n\t\tsum = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsum += a[i] = scanInt();\n\t\t}\n\t\tsum /= n;\n\t\tmove = new int[n];\n\t\tint idx[] = new int[n];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tmove[i + 1] = move[i] + a[i] - sum;\n\t\t\tidx[i] = i;\n\t\t}\n\t\tidx[n - 1] = n - 1;\n\t\tsort(idx, n, new IntComparator() {\n\t\t\tpublic int compare(int o1, int o2) {\n\t\t\t\treturn move[o1] != move[o2] ? move[o1] - move[o2] : o1 - o2;\n\t\t\t}\n\t\t});\n\t\tint ans = (n + k - 2) / (k - 1), ansStart = -1;\n\t\tint maxChain[] = new int[n], curNext[] = new int[k - 1];\n\t\tfill(curNext, -1);\n\t\tfor (int i = 0, j; i < n; i = j) {\n\t\t\tfor (j = i + 1; j < n && move[idx[j]] == move[idx[i]]; j++) { }\n\t\t\tfor (int ii = j - 1; ii >= i; ii--) {\n\t\t\t\tint ci = idx[ii], ni = curNext[(ci + 1) % (k - 1)];\n//\t\t\t\tSystem.err.println(ci + \" \" + ni);\n\t\t\t\tmaxChain[ci] = ni < 0 ? 1 : 1 + maxChain[ni];\n\t\t\t\tint cans = (n - maxChain[ci] + k - 2) / (k - 1);\n\t\t\t\tif (cans < ans) {\n\t\t\t\t\tans = cans;\n\t\t\t\t\tansStart = ci;\n\t\t\t\t}\n\t\t\t\tcurNext[ci % (k - 1)] = ci;\n\t\t\t}\n\t\t\tfor (int ii = i; ii < j; ii++) {\n\t\t\t\tcurNext[idx[ii] % (k - 1)] = -1;\n\t\t\t}\n\t\t}\n//\t\tSystem.err.println(Arrays.toString(maxChain));\n\t\tout.println(ans);\n\t\tdefer = new int[n];\n\t\tdeferCnt = 0;\n//\t\tSystem.err.println(ans + \" \" + ansStart + \" \" + sum);\n\t\tif (ansStart < 0) {\n\t\t\tmoveOffset = 0;\n\t\t\tfor (int i = 0; i < ans; i++) {\n\t\t\t\tdoMove(i * (k - 1));\n\t\t\t}\n\t\t} else {\n\t\t\tmoveOffset = move[ansStart];\n//\t\t\tSystem.err.println(Arrays.toString(move) + \" \" + moveOffset);\n\t\t\tfor (int i = 0, pos = ansStart; i < ans; i++) {\n\t\t\t\twhile (move[(pos + 1) % n] == moveOffset) {\n\t\t\t\t\tpos = (pos + 1) % n;\n\t\t\t\t}\n//\t\t\t\tSystem.err.println(pos);\n\t\t\t\tdoMove(pos);\n//\t\t\t\tSystem.err.println(Arrays.toString(a));\n\t\t\t\tpos = (pos + k - 1) % n;\n\t\t\t}\n\t\t}\n\t\tif (deferCnt != 0) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t}\n \n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n \n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n \n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n \n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n \n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5b1112c1b610757c976375226b793ab4", "src_uid": "8b9099351b979cdb61413cc039861f8d", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class G {\n\n\tinterface IntComparator {\n\t\tpublic int compare(int o1, int o2);\n\t}\n\n\tstatic void sort(int a[], int n, IntComparator cmp) {\n\t\tif (n == 0) {\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = i;\n\t\t\tint ca = a[i];\n\t\t\tdo {\n\t\t\t\tint nj = (j - 1) >> 1;\n\t\t\t\tint na = a[nj];\n\t\t\t\tif (cmp.compare(na, ca) >= 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ta[j] = na;\n\t\t\t\tj = nj;\n\t\t\t} while (j != 0);\n\t\t\ta[j] = ca;\n\t\t}\n\t\tint ca = a[0];\n\t\tfor (int i = n - 1; i > 0; i--) {\n\t\t\tint j = 0;\n\t\t\twhile ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {\n\t\t\t\tj <<= 1;\n\t\t\t\tj += (cmp.compare(a[j + 1], a[j + 2]) < 0) ? 2 : 1;\n\t\t\t}\n\t\t\tif ((j << 1) + 2 == i) {\n\t\t\t\tj = (j << 1) + 1;\n\t\t\t}\n\t\t\tint na = a[i];\n\t\t\ta[i] = ca;\n\t\t\tca = na;\n\t\t\twhile (j != 0 && cmp.compare(a[j], ca) < 0) {\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t\twhile (j != 0) {\n\t\t\t\tna = a[j];\n\t\t\t\ta[j] = ca;\n\t\t\t\tca = na;\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t}\n\t\ta[0] = ca;\n\t}\n\n\tstatic int n, k, a[], sum, move[], moveOffset, defer[], deferCnt, derefFirst[];\n\n\tstatic void doMove(int pos) {\n\t\tif (a[pos] < (move[(pos + 1) % n] - moveOffset) || a[(pos + k - 1) % n] < -(move[(pos + k - 1) % n] - moveOffset)) {\n\t\t\tif (deferCnt == 0) {\n\t\t\t\tderefFirst = new int[k - 1];\n\t\t\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\t\t\tderefFirst[i] = move[(pos + i + 1) % n] - moveOffset;\n\t\t\t\t\tmove[(pos + i + 1) % n] = moveOffset;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdefer[deferCnt++] = pos;\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\tint m = move[(pos + i + 1) % n] - moveOffset;\n\t\t\ta[(pos + i) % n] -= m;\n\t\t\ta[(pos + i + 1) % n] += m;\n\t\t\tmove[(pos + i + 1) % n] = moveOffset;\n\t\t}\n\t\tout.print(pos + 1);\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tout.print(\" \" + a[(pos + i) % n]);\n\t\t}\n\t\tout.println();\n\t\tif (deferCnt > 0) {\n\t\t\tif (--deferCnt == 0) {\n\t\t\t\tpos = defer[0];\n\t\t\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\t\t\tint m = derefFirst[i];\n\t\t\t\t\ta[(pos + i) % n] -= m;\n\t\t\t\t\ta[(pos + i + 1) % n] += m;\n\t\t\t\t}\n\t\t\t\tout.print(pos + 1);\n\t\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\t\tout.print(\" \" + a[(pos + i) % n]);\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t} else {\n\t\t\t\tdoMove(defer[deferCnt]);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tn = scanInt();\n\t\tk = scanInt();\n\t\ta = new int[n];\n\t\tsum = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsum += a[i] = scanInt();\n\t\t}\n\t\tsum /= n;\n\t\tmove = new int[n];\n\t\tint idx[] = new int[n];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tmove[i + 1] = move[i] + a[i] - sum;\n\t\t\tidx[i] = i;\n\t\t}\n\t\tidx[n - 1] = n - 1;\n\t\tsort(idx, n, new IntComparator() {\n\t\t\tpublic int compare(int o1, int o2) {\n\t\t\t\treturn move[o1] != move[o2] ? move[o1] - move[o2] : o1 - o2;\n\t\t\t}\n\t\t});\n\t\tint ans = (n + k - 2) / (k - 1), ansStart = -1;\n\t\tint maxChain[] = new int[n], curNext[] = new int[k - 1];\n\t\tfill(curNext, -1);\n\t\tfor (int i = 0, j; i < n; i = j) {\n\t\t\tfor (j = i + 1; j < n && move[idx[j]] == move[idx[i]]; j++) { }\n\t\t\tfor (int ii = j - 1; ii >= i; ii--) {\n\t\t\t\tint ci = idx[ii], ni = curNext[(ci + 1) % (k - 1)];\n//\t\t\t\tSystem.err.println(ci + \" \" + ni);\n\t\t\t\tmaxChain[ci] = ni < 0 ? 1 : 1 + maxChain[ni];\n\t\t\t\tint cans = (n - maxChain[ci] + k - 2) / (k - 1);\n\t\t\t\tif (cans < ans) {\n\t\t\t\t\tans = cans;\n\t\t\t\t\tansStart = ci;\n\t\t\t\t}\n\t\t\t\tcurNext[ci % (k - 1)] = ci;\n\t\t\t}\n\t\t\tfor (int ii = i; ii < j; ii++) {\n\t\t\t\tcurNext[idx[ii] % (k - 1)] = -1;\n\t\t\t}\n\t\t}\n//\t\tSystem.err.println(Arrays.toString(maxChain));\n\t\tout.println(ans);\n\t\tdefer = new int[n];\n\t\tdeferCnt = 0;\n//\t\tSystem.err.println(ans + \" \" + ansStart + \" \" + sum);\n\t\tif (ansStart < 0) {\n\t\t\tmoveOffset = 0;\n\t\t\tfor (int i = 0; i < ans; i++) {\n\t\t\t\tdoMove(i * (k - 1));\n\t\t\t}\n\t\t} else {\n\t\t\tmoveOffset = move[ansStart];\n//\t\t\tSystem.err.println(Arrays.toString(move) + \" \" + moveOffset);\n\t\t\tfor (int i = 0, pos = ansStart; i < ans; i++) {\n\t\t\t\twhile (move[(pos + 1) % n] == moveOffset) {\n\t\t\t\t\tpos = (pos + 1) % n;\n\t\t\t\t}\n//\t\t\t\tSystem.err.println(pos);\n\t\t\t\tdoMove(pos);\n//\t\t\t\tSystem.err.println(Arrays.toString(a));\n\t\t\t\tpos = (pos + k - 1) % n;\n\t\t\t}\n\t\t}\n\t\tif (deferCnt != 0) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "772a113f8bdf04a54ff9492d892b19ad", "src_uid": "8b9099351b979cdb61413cc039861f8d", "difficulty": 3500.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String[] strings = new String[]{\"buffy\", \"the\", \"vampire\", \"slayer\"};\r\n String in = br.readLine();\r\n boolean found = false;\r\n for (String s : strings) {\r\n if (s.length() == in.length()) {\r\n found = true;\r\n for (int i = 0; i < s.length(); i++) {\r\n System.out.print((char) ((in.charAt(i) + s.charAt(i) - 'a' - 'a') % (26) + 'a'));\r\n }\r\n }\r\n }\r\n if (!found) {\r\n System.out.println(\"none\");\r\n }\r\n\r\n\r\n br.close();\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0474fcbdcd98cd2361523bb85663baa0", "src_uid": "56ec50526a3843fe3784d395850f45ae", "difficulty": -1.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.random;\n\n/**\n * @author Don Li\n */\npublic class OnTheBench {\n \n int MOD = (int) 1e9 + 7;\n \n void solve() {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n \n int[][] c = new int[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n c[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;\n }\n }\n \n int[] fac = new int[n + 1];\n fac[0] = 1;\n for (int i = 1; i <= n; i++) fac[i] = (int) ((long) i * fac[i - 1] % MOD);\n \n for (int i = 0; i < n; i++) a[i] = removeSqures(a[i]);\n \n sort(a);\n \n long[] ways = new long[]{1}; \n for (int i = 0; i < n; ) {\n int j = i + 1;\n while (j < n && a[j] == a[i]) j++;\n int m = j - i;\n \n long[] nways = new long[j + 1];\n for (int x = 0; x < ways.length; x++) {\n long w = ways[x];\n for (int y = 1; y <= m; y++) {\n for (int z = 0; z <= x && z <= y; z++) {\n nways[x - z + (m - y)] = (nways[x - z + (m - y)] + w * c[m - 1][y - 1] % MOD * c[x][z] % MOD * c[i + 1 - x][y - z] % MOD * fac[m] % MOD) % MOD;\n }\n }\n }\n \n ways = nways;\n i = j;\n }\n \n out.println(ways[0]);\n }\n \n void sort(int[] a) {\n int n = a.length;\n for (int i = 0; i < n; i++) {\n int j = (int) (i + random() * (n - i));\n int tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n Arrays.sort(a);\n }\n \n int removeSqures(int x) {\n for (int i = 2; i * i <= x; i++) {\n while (x % (i * i) == 0) x /= i * i;\n }\n return x;\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 OnTheBench().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "541e0713ee28c4522d802514ce8f5ec7", "src_uid": "e00c5fde478d36c90b17f5df18fb3ed1", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.random;\n\n/**\n * @author Don Li\n */\npublic class OnTheBench {\n \n int MOD = (int) 1e9 + 7;\n \n void solve() {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n \n int[][] c = new int[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n c[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;\n }\n }\n \n int[] fac = new int[n + 1];\n fac[0] = 1;\n for (int i = 1; i <= n; i++) fac[i] = (int) ((long) i * fac[i - 1] % MOD);\n \n for (int i = 0; i < n; i++) a[i] = removeSqures(a[i]);\n \n sort(a);\n \n long[] ways = new long[]{1}; \n for (int i = 0; i < n; ) {\n int j = i + 1;\n while (j < n && a[j] == a[i]) j++;\n int m = j - i;\n \n long[] nways = new long[j + 1];\n for (int x = 0; x < ways.length; x++) {\n long w = ways[x];\n for (int y = 1; y <= m; y++) {\n for (int z = 0; z <= x && z <= y; z++) {\n nways[x - z + (m - y)] = (nways[x - z + (m - y)] + w * c[m - 1][y - 1] % MOD * c[x][z] % MOD * c[i + 1 - x][y - z] % MOD * fac[m] % MOD) % MOD;\n }\n }\n }\n \n ways = nways;\n i = j;\n }\n \n out.println(ways[0]);\n }\n \n void sort(int[] a) {\n int n = a.length;\n for (int i = 0; i < n; i++) {\n int j = (int) (i + random() * (n - i));\n int tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n Arrays.sort(a);\n }\n \n int removeSqures(int x) {\n for (int i = 2; i * i <= x; i++) {\n while (x % (i * i) == 0) x /= i * i;\n }\n return x;\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 OnTheBench().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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "833dd9322f19e91da7ab03e24d0aaab0", "src_uid": "e00c5fde478d36c90b17f5df18fb3ed1", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import sun.security.util.Length;\n\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class E {\n\n public static boolean isSquare(int a, int b) {\n long mult = ((long)a) * b;\n long sqrt = Math.round(Math.sqrt(mult));\n return sqrt * sqrt == mult;\n }\n\n public static long[] getFacts(int n) {\n long[] f = new long[n + 1];\n f[0] = 1;\n\n for (int i = 1; i <= n; ++i) {\n f[i] = (f[i - 1] * i) % 1000000007;\n }\n return f;\n }\n\n public static long[][] getC(int n) {\n long[][] c = new long[n + 1][n + 1];\n\n for (int i = 0; i <= n; ++i) {\n for (int j = 0; j <= i; j++) {\n if (i == 0 || j == 0) {\n c[i][j] = 1;\n continue;\n }\n\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;\n }\n }\n\n return c;\n }\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = scan.nextInt();\n }\n\n int[] aGroup = new int[n + 1];\n int[] groups = new int[n + 1];\n int groupsCnt = 0;\n for (int i = 0; i < n; ++i) {\n int group = groupsCnt;\n\n for (int j = 0; j < i; ++j) {\n if (isSquare(a[i], a[j])) {\n group = aGroup[j];\n break;\n }\n }\n\n aGroup[i] = group;\n groups[group] = groups[group] + 1;\n groupsCnt = Math.max(groupsCnt, group + 1);\n }\n\n long[] fact = getFacts(n);\n long[][] c = getC(n);\n\n long[] f = new long[n];\n f[0] = 1;\n\n int total = 0;\n for (int i = 0; i < groupsCnt; ++i) {\n //System.out.println(groups[i]);\n\n long[] fNew = new long[n];\n\n int size = groups[i];\n\n for (int j = 0; j <= total; ++j) {\n if (f[j] == 0)\n continue;\n\n for (int s = 1; s <= Math.min(size, total + 1); ++s) {\n for (int d = 0; d <= Math.min(j, s); ++d) {\n long mult = (fact[size] * c[size - 1][s - 1]) % 1000000007;\n mult = (mult * c[j][d]) % 1000000007;\n mult = (mult * c[total - j + 1][s - d]) % 1000000007;\n\n fNew[j - d + size - s] = ( fNew[j - d + size - s] + f[j] * mult) % 1000000007;\n }\n }\n }\n\n total += (groups[i]);\n\n //System.out.println(Arrays.toString(Arrays.copyOf(fNew, n)));\n f = fNew;\n }\n\n System.out.println(f[0]);\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2df81d5ef6388f1c1ed916eda01d91ad", "src_uid": "e00c5fde478d36c90b17f5df18fb3ed1", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\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 int[] smallestDivisor;\n\n TaskE.Factorization factorize(int x) {\n int cnt = 0;\n int tmp = x;\n while (tmp > 1) {\n int cur = smallestDivisor[tmp];\n while (tmp % cur == 0) {\n tmp /= cur;\n }\n ++cnt;\n }\n TaskE.Factorization f = new TaskE.Factorization(cnt);\n tmp = x;\n cnt = 0;\n while (tmp > 1) {\n int cur = smallestDivisor[tmp];\n f.p[cnt] = cur;\n while (tmp % cur == 0) {\n tmp /= cur;\n ++f.k[cnt];\n }\n if (f.k[cnt] == 0) throw new RuntimeException();\n ++cnt;\n }\n return f;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) a[i] = in.nextInt();\n int maxa = 2;\n for (int x : a) maxa = Math.max(maxa, x);\n ++maxa;\n\n TaskE.Factorization[] fs = factorizeAll(n, a, maxa);\n\n long[] bCounts = buildB(n, maxa, fs);\n\n long bTotal = 0;\n long bSize = 0;\n for (int i = 0; i < bCounts.length; ++i) {\n bTotal += i * bCounts[i];\n bSize += bCounts[i];\n }\n\n long position = ((bSize * (bSize + 1) / 2) - 1) / 2;\n\n long left = -1;\n long right = bTotal;\n while (right - left > 1) {\n long middle = (left + right) / 2;\n if (howManyLessOrEqual(bCounts, middle) <= position) {\n left = middle;\n } else {\n right = middle;\n }\n }\n\n out.println(right);\n }\n\n private long howManyLessOrEqual(long[] bCounts, long bound) {\n long res = 0;\n int right = 0;\n long rightAt = 0;\n long rightTotal = bCounts[0];\n long beforeRight = 0;\n long countBeforeRight = 0;\n long beforeLeft = 0;\n long countBeforeLeft = 0;\n for (int left = 0; left < bCounts.length; ++left) {\n long leftAt = 0;\n long leftTotal = bCounts[left];\n while (leftAt < leftTotal) {\n while (right < bCounts.length && beforeRight + (rightTotal - rightAt) * right <= beforeLeft + bound) {\n beforeRight += (rightTotal - rightAt) * right;\n countBeforeRight += (rightTotal - rightAt);\n ++right;\n if (right < bCounts.length) {\n rightAt = 0;\n rightTotal = bCounts[right];\n } else {\n rightAt = -1;\n rightTotal = -1;\n }\n }\n if (right == bCounts.length) {\n long by = leftTotal - leftAt;\n res += ((countBeforeRight - countBeforeLeft) + (countBeforeRight - countBeforeLeft + by - 1)) * by / 2;\n leftAt += by;\n countBeforeLeft += by;\n beforeLeft += by * left;\n } else {\n long maxRight = beforeRight + (rightTotal - rightAt) * right;\n long by = leftTotal - leftAt;\n by = Math.min(by, (maxRight - beforeLeft - bound + left - 1) / left);\n if (by == 0) {\n throw new RuntimeException();\n }\n\n res += countBeforeRight * by + sumIntPart(left, beforeLeft + bound - beforeRight, right, by);\n res -= (countBeforeLeft + countBeforeLeft + by - 1) * by / 2;\n\n leftAt += by;\n countBeforeLeft += by;\n beforeLeft += by * left;\n }\n }\n }\n return res;\n }\n\n private long intPartSum(long mult, long modulo, long cnt, long add) {\n if (cnt == 0)\n return 0;\n if (add >= modulo)\n return intPartSum(mult, modulo, cnt, add % modulo) + cnt * (long) (add / modulo);\n if (add < 0)\n return intPartSum(mult, modulo, cnt, add % modulo + modulo) + cnt * (long) (add / modulo - 1);\n if (mult >= modulo)\n return intPartSum(mult % modulo, modulo, cnt, add) + (mult / modulo) * (long) cnt * (long) (cnt + 1) / 2;\n if (mult == 0) {\n return 0;\n }\n int max = (int) ((mult * (long) cnt + add) / modulo);\n return max * (long) cnt - intPartSum(modulo, mult, max, -add - 1);\n }\n\n private long sumIntPart(long a, long b, long c, long count) {\n if (count == 0) return 0;\n long got = b / c + intPartSum(a, c, count - 1, b);\n /*long expected = 0;\n for (int i = 0; i < count; ++i) {\n expected += (a * i + b) / c;\n }\n if (got != expected) {\n throw new RuntimeException();\n }*/\n return got;\n }\n\n private long[] buildB(int n, int maxa, TaskE.Factorization[] fs) {\n long[] bCounts = new long[maxa];\n for (int left = 0; left < n; ++left) {\n TaskE.Factorization f = fs[left];\n int[] primes = f.p;\n int[] pow = f.k.clone();\n int[] decrease = f.nextDecrease.clone();\n int at = left;\n while (at < n) {\n int prod = 1;\n for (int i = 0; i < primes.length; ++i) {\n for (int j = 0; j < pow[i]; ++j) {\n prod *= primes[i];\n }\n }\n int dest = n;\n for (int i = 0; i < primes.length; ++i) {\n dest = Math.min(dest, decrease[i]);\n }\n bCounts[prod] += dest - at;\n at = dest;\n if (at < n) {\n TaskE.Factorization cur = fs[at];\n for (int i = 0; i < primes.length; ++i)\n if (decrease[i] == at) {\n int pos = Arrays.binarySearch(cur.p, primes[i]);\n if (pos >= 0) {\n pow[i] = cur.k[pos];\n decrease[i] = cur.nextDecrease[pos];\n } else {\n pow[i] = 0;\n decrease[i] = n;\n }\n }\n }\n }\n }\n return bCounts;\n }\n\n private TaskE.Factorization[] factorizeAll(int n, int[] a, int maxa) {\n smallestDivisor = new int[maxa];\n for (int i = 2; i < maxa; ++i) {\n smallestDivisor[i] = i;\n }\n for (int i = 2; i * i < maxa; ++i)\n if (smallestDivisor[i] == i) {\n for (int j = i * i; j < maxa; j += i) if (smallestDivisor[j] == j) smallestDivisor[j] = i;\n }\n\n TaskE.Factorization[] fs = new TaskE.Factorization[n];\n for (int i = 0; i < n; ++i) fs[i] = factorize(a[i]);\n\n int[] stackTop = new int[maxa];\n int[] stackTopPos = new int[maxa];\n\n Arrays.fill(stackTop, n);\n Arrays.fill(stackTopPos, -1);\n\n for (int i = n - 1; i >= 0; --i) {\n TaskE.Factorization f = fs[i];\n for (int j = 0; j < f.p.length; ++j) {\n int what = f.p[j];\n int deg = f.k[j];\n if (stackTop[what] != i + 1) {\n stackTop[what] = i + 1;\n stackTopPos[what] = -1;\n }\n while (stackTopPos[what] >= 0 && fs[stackTop[what]].k[stackTopPos[what]] >= deg) {\n int next = fs[stackTop[what]].nextInStackIndex[stackTopPos[what]];\n int nextPos = fs[stackTop[what]].nextInStackPos[stackTopPos[what]];\n stackTop[what] = next;\n stackTopPos[what] = nextPos;\n }\n f.nextDecrease[j] = stackTop[what];\n f.nextInStackIndex[j] = stackTop[what];\n f.nextInStackPos[j] = stackTopPos[what];\n stackTop[what] = i;\n stackTopPos[what] = j;\n }\n }\n return fs;\n }\n\n static class Factorization {\n int[] p;\n int[] k;\n int[] nextDecrease;\n int[] nextInStackIndex;\n int[] nextInStackPos;\n\n public Factorization(int len) {\n p = new int[len];\n k = new int[len];\n nextDecrease = new int[len];\n nextInStackIndex = new int[len];\n nextInStackPos = new int[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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "77fa2996d51277a3fb0c8390de97ab18", "src_uid": "7516cc0a6d76569a761cf795cfb22d50", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\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 int[] smallestDivisor;\n\n TaskE.Factorization factorize(int x) {\n int cnt = 0;\n int tmp = x;\n while (tmp > 1) {\n int cur = smallestDivisor[tmp];\n while (tmp % cur == 0) {\n tmp /= cur;\n }\n ++cnt;\n }\n TaskE.Factorization f = new TaskE.Factorization(cnt);\n tmp = x;\n cnt = 0;\n while (tmp > 1) {\n int cur = smallestDivisor[tmp];\n f.p[cnt] = cur;\n while (tmp % cur == 0) {\n tmp /= cur;\n ++f.k[cnt];\n }\n if (f.k[cnt] == 0) throw new RuntimeException();\n ++cnt;\n }\n return f;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) a[i] = in.nextInt();\n int maxa = 2;\n for (int x : a) maxa = Math.max(maxa, x);\n ++maxa;\n\n TaskE.Factorization[] fs = factorizeAll(n, a, maxa);\n\n long[] bCounts = buildB(n, maxa, fs);\n\n long bTotal = 0;\n long bSize = 0;\n for (int i = 0; i < bCounts.length; ++i) {\n bTotal += i * bCounts[i];\n bSize += bCounts[i];\n }\n\n long position = ((bSize * (bSize + 1) / 2) - 1) / 2;\n\n long left = -1;\n long right = bTotal;\n while (right - left > 1) {\n long middle = (left + right) / 2;\n if (howManyLessOrEqual(bCounts, middle) <= position) {\n left = middle;\n } else {\n right = middle;\n }\n }\n\n out.println(right);\n }\n\n private long howManyLessOrEqual(long[] bCounts, long bound) {\n long res = 0;\n int right = 0;\n long rightAt = 0;\n long rightTotal = bCounts[0];\n long beforeRight = 0;\n long countBeforeRight = 0;\n long beforeLeft = 0;\n long countBeforeLeft = 0;\n for (int left = 0; left < bCounts.length; ++left) {\n long leftAt = 0;\n long leftTotal = bCounts[left];\n while (leftAt < leftTotal) {\n while (right < bCounts.length && beforeRight + (rightTotal - rightAt) * right <= beforeLeft + bound) {\n beforeRight += (rightTotal - rightAt) * right;\n countBeforeRight += (rightTotal - rightAt);\n ++right;\n if (right < bCounts.length) {\n rightAt = 0;\n rightTotal = bCounts[right];\n } else {\n rightAt = -1;\n rightTotal = -1;\n }\n }\n if (right == bCounts.length) {\n long by = leftTotal - leftAt;\n res += ((countBeforeRight - countBeforeLeft) + (countBeforeRight - countBeforeLeft - by + 1)) * by / 2;\n leftAt += by;\n countBeforeLeft += by;\n beforeLeft += by * left;\n } else {\n long maxRight = beforeRight + (rightTotal - rightAt) * right;\n long by = leftTotal - leftAt;\n by = Math.min(by, (maxRight - beforeLeft - bound + left - 1) / left);\n if (by == 0) {\n throw new RuntimeException();\n }\n\n res += countBeforeRight * by + sumIntPart(left, beforeLeft + bound - beforeRight, right, by);\n res -= (countBeforeLeft + countBeforeLeft + by - 1) * by / 2;\n\n leftAt += by;\n countBeforeLeft += by;\n beforeLeft += by * left;\n }\n }\n }\n return res;\n }\n\n private long intPartSum(long mult, long modulo, long cnt, long add) {\n if (cnt == 0)\n return 0;\n if (add >= modulo)\n return intPartSum(mult, modulo, cnt, add % modulo) + cnt * (long) (add / modulo);\n if (add < 0)\n return intPartSum(mult, modulo, cnt, add % modulo + modulo) + cnt * (long) (add / modulo - 1);\n if (mult >= modulo)\n return intPartSum(mult % modulo, modulo, cnt, add) + (mult / modulo) * (long) cnt * (long) (cnt + 1) / 2;\n if (mult == 0) {\n return 0;\n }\n int max = (int) ((mult * (long) cnt + add) / modulo);\n return max * (long) cnt - intPartSum(modulo, mult, max, -add - 1);\n }\n\n private long sumIntPart(long a, long b, long c, long count) {\n if (count == 0) return 0;\n long got = b / c + intPartSum(a, c, count - 1, b);\n /*long expected = 0;\n for (int i = 0; i < count; ++i) {\n expected += (a * i + b) / c;\n }\n if (got != expected) {\n throw new RuntimeException();\n }*/\n return got;\n }\n\n private long[] buildB(int n, int maxa, TaskE.Factorization[] fs) {\n long[] bCounts = new long[maxa];\n for (int left = 0; left < n; ++left) {\n TaskE.Factorization f = fs[left];\n int[] primes = f.p;\n int[] pow = f.k.clone();\n int[] decrease = f.nextDecrease.clone();\n int at = left;\n while (at < n) {\n int prod = 1;\n for (int i = 0; i < primes.length; ++i) {\n for (int j = 0; j < pow[i]; ++j) {\n prod *= primes[i];\n }\n }\n int dest = n;\n for (int i = 0; i < primes.length; ++i) {\n dest = Math.min(dest, decrease[i]);\n }\n bCounts[prod] += dest - at;\n at = dest;\n if (at < n) {\n TaskE.Factorization cur = fs[at];\n for (int i = 0; i < primes.length; ++i)\n if (decrease[i] == at) {\n int pos = Arrays.binarySearch(cur.p, primes[i]);\n if (pos >= 0) {\n pow[i] = cur.k[pos];\n decrease[i] = cur.nextDecrease[pos];\n } else {\n pow[i] = 0;\n decrease[i] = n;\n }\n }\n }\n }\n }\n return bCounts;\n }\n\n private TaskE.Factorization[] factorizeAll(int n, int[] a, int maxa) {\n smallestDivisor = new int[maxa];\n for (int i = 2; i < maxa; ++i) {\n smallestDivisor[i] = i;\n }\n for (int i = 2; i * i < maxa; ++i)\n if (smallestDivisor[i] == i) {\n for (int j = i * i; j < maxa; j += i) if (smallestDivisor[j] == j) smallestDivisor[j] = i;\n }\n\n TaskE.Factorization[] fs = new TaskE.Factorization[n];\n for (int i = 0; i < n; ++i) fs[i] = factorize(a[i]);\n\n int[] stackTop = new int[maxa];\n int[] stackTopPos = new int[maxa];\n\n Arrays.fill(stackTop, n);\n Arrays.fill(stackTopPos, -1);\n\n for (int i = n - 1; i >= 0; --i) {\n TaskE.Factorization f = fs[i];\n for (int j = 0; j < f.p.length; ++j) {\n int what = f.p[j];\n int deg = f.k[j];\n if (stackTop[what] != i + 1) {\n stackTop[what] = i + 1;\n stackTopPos[what] = -1;\n }\n while (stackTopPos[what] >= 0 && fs[stackTop[what]].k[stackTopPos[what]] >= deg) {\n int next = fs[stackTop[what]].nextInStackIndex[stackTopPos[what]];\n int nextPos = fs[stackTop[what]].nextInStackPos[stackTopPos[what]];\n stackTop[what] = next;\n stackTopPos[what] = nextPos;\n }\n f.nextDecrease[j] = stackTop[what];\n f.nextInStackIndex[j] = stackTop[what];\n f.nextInStackPos[j] = stackTopPos[what];\n stackTop[what] = i;\n stackTopPos[what] = j;\n }\n }\n return fs;\n }\n\n static class Factorization {\n int[] p;\n int[] k;\n int[] nextDecrease;\n int[] nextInStackIndex;\n int[] nextInStackPos;\n\n public Factorization(int len) {\n p = new int[len];\n k = new int[len];\n nextDecrease = new int[len];\n nextInStackIndex = new int[len];\n nextInStackPos = new int[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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1e6fce6e02ac5439b1a5ebca2c8c34a8", "src_uid": "7516cc0a6d76569a761cf795cfb22d50", "difficulty": 3400.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1384E extends PrintWriter {\n\tCF1384E() { super(System.out); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1384E o = new CF1384E(); o.main(); o.flush();\n\t}\n\n\tstatic final int M = 20;\n\tvoid 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\tboolean[][] aa = new boolean[M][M];\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\taa[u][v] = true;\n\t\t\t\t}\n\t\t\tboolean[][] bb = new boolean[M][M];\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\tbb[i][j] = aa[i][j];\n\t\t\tfor (int k = 0; k < M; k++)\n\t\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\t\tbb[i][j] = bb[i][j] || bb[i][k] && bb[k][j];\n\t\t\tint[] cc = new int[M]; Arrays.fill(cc, -1);\n\t\t\tint ans = 0;\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tif (bb[i][i]) {\n\t\t\t\t\tif (cc[i] == -1)\n\t\t\t\t\t\tfor (int j = i; j < M; j++)\n\t\t\t\t\t\t\tif (cc[j] == -1 && bb[j][j] && bb[i][j] && bb[j][i]) {\n\t\t\t\t\t\t\t\tcc[j] = i;\n\t\t\t\t\t\t\t\tans++;\n\t\t\t\t\t\t\t}\n\t\t\t\t} else\n\t\t\t\t\tcc[i] = i;\n\t\t\tboolean[][] aa_ = new boolean[M][M];\n\t\t\tboolean[][] bb_ = new boolean[M][M];\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++) {\n\t\t\t\t\tint i_ = cc[i], j_ = cc[j];\n\t\t\t\t\tif (i_ != j_) {\n\t\t\t\t\t\tif (aa[i][j])\n\t\t\t\t\t\t\taa_[i_][j_] = true;\n\t\t\t\t\t\tif (bb[i][j])\n\t\t\t\t\t\t\tbb_[i_][j_] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tboolean[][] ab = new boolean[M][M];\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\tfor (int k = 0; k < M; k++)\n\t\t\t\t\t\tif (aa_[i][k] && bb_[k][j]) {\n\t\t\t\t\t\t\tab[i][j] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\tif (i != j && aa_[i][j] && !ab[i][j])\n\t\t\t\t\t\tans++;\n\t\t\tprintln(ans);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bca85943324e115b45980c22af87b85e", "src_uid": "d0735a763e2a40bfc94085019cd646f0", "difficulty": 3100.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1384E extends PrintWriter {\n\tCF1384E() { super(System.out); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1384E o = new CF1384E(); o.main(); o.flush();\n\t}\n\n\tstatic final int M = 20;\n\tvoid 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\tboolean[][] aa = new boolean[M][M];\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\taa[u][v] = true;\n\t\t\t\t}\n\t\t\tboolean[][] bb = new boolean[M][M];\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\tbb[i][j] = aa[i][j];\n\t\t\tfor (int k = 0; k < M; k++)\n\t\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\t\tbb[i][j] = bb[i][j] || bb[i][k] && bb[k][j];\n\t\t\tint[] cc = new int[M]; Arrays.fill(cc, -1);\n\t\t\tint ans = 0;\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tif (bb[i][i]) {\n\t\t\t\t\tif (cc[i] == -1)\n\t\t\t\t\t\tfor (int j = i; j < M; j++)\n\t\t\t\t\t\t\tif (bb[i][j] && bb[j][j]) {\n\t\t\t\t\t\t\t\tcc[j] = i;\n\t\t\t\t\t\t\t\tans++;\n\t\t\t\t\t\t\t}\n\t\t\t\t} else\n\t\t\t\t\tcc[i] = i;\n\t\t\tboolean[][] aa_ = new boolean[M][M];\n\t\t\tboolean[][] bb_ = new boolean[M][M];\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++) {\n\t\t\t\t\tint i_ = cc[i], j_ = cc[j];\n\t\t\t\t\tif (i_ != j_) {\n\t\t\t\t\t\tif (aa[i][j])\n\t\t\t\t\t\t\taa_[i_][j_] = true;\n\t\t\t\t\t\tif (bb[i][j])\n\t\t\t\t\t\t\tbb_[i_][j_] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tboolean[][] ab = new boolean[M][M];\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\tfor (int k = 0; k < M; k++)\n\t\t\t\t\t\tif (aa_[i][k] && bb_[k][j]) {\n\t\t\t\t\t\t\tab[i][j] = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\tfor (int i = 0; i < M; i++)\n\t\t\t\tfor (int j = 0; j < M; j++)\n\t\t\t\t\tif (i != j && aa_[i][j] && !ab[i][j])\n\t\t\t\t\t\tans++;\n\t\t\tprintln(ans);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "477ba463c90f3eaad5badcb8361389f9", "src_uid": "d0735a763e2a40bfc94085019cd646f0", "difficulty": 3100.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\n// https://codeforces.com/contest/1384/problem/C\npublic class C {\n\tpublic static final Scanner INPUT = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\t\tint t = Integer.parseInt(INPUT.nextLine());\n\t\twhile (t > 0) {\n\t\t\tt--;\n\t\t\tint n = Integer.parseInt(INPUT.nextLine());\n\t\t\tString a = INPUT.nextLine().trim();\n\t\t\tString b = INPUT.nextLine().trim();\n\t\t\t// System.out.println(\"n = \" + n);\n\t\t\t// System.out.println(\"a = \" + a);\n\t\t\t// System.out.println(\"b = \" + b);\n\t\t\tint[][] c = trans2matrix(a, b, n);\n\t\t\twhile (reduce(c)) {\n\t\t\t}\n\t\t\tSystem.out.println(counter(c));\n\t\t}\n\t}\n\n\tprivate static final int N_SIZE = 20;\n\n\tprivate static boolean reduce(int[][] c) {\n\t\tif (c == null) {\n\t\t\treturn false;\n\t\t}\n\t\tboolean canReduce = false;\n\t\tfor (int i = 0; i < N_SIZE; i++) {\n\t\t\tint last = -1;\n\t\t\tfor (int j = i + 1; j < N_SIZE; j++) {\n\t\t\t\tif (c[i][j] > 0) {\n\t\t\t\t\tif (last == -1) {\n\t\t\t\t\t\tlast = j;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tc[i][last] += c[i][j];\n\t\t\t\t\t\tc[last][j] += c[i][j];\n\t\t\t\t\t\tc[i][j] = 0;\n\t\t\t\t\t\tcanReduce = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn canReduce;\n\t}\n\n\tprivate static int counter(int[][] c) {\n\t\tif (c == null) {\n\t\t\treturn -1;\n\t\t}\n\t\tint counter = 0;\n\t\tfor (int i = 0; i < N_SIZE; i++) {\n\t\t\tfor (int j = i + 1; j < N_SIZE; j++) {\n\t\t\t\tif (c[i][j] > 0) {\n\t\t\t\t\tcounter++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn counter;\n\t}\n\n\tprivate static int[][] trans2matrix(String a, String b, int n) {\n\t\tif (a == null || b == null) {\n\t\t\treturn null;\n\t\t}\n\t\tif ((a.length() != n) || (b.length() != n)) {\n\t\t\treturn null;\n\t\t}\n\t\tint[][] c = new int[N_SIZE][N_SIZE];\n\t\tfor (int id = 0; id < n; id++) {\n\t\t\tint cA = a.charAt(id) - 'a';\n\t\t\tint cB = b.charAt(id) - 'a';\n\t\t\tif (cA > cB) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (cA < cB) {\n\t\t\t\tc[cA][cB]++;\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n}\n/*\n * 5 3 aab bcc 4 cabc abcb 3 abc tsr 4 aabd cccd 5 abcbd bcdda\n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e6ceb584d3a9c6df82ce95d29180969b", "src_uid": "d0735a763e2a40bfc94085019cd646f0", "difficulty": 3100.0} {"lang": "Java 11", "source_code": "import java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\n// https://codeforces.com/contest/1384/problem/E\npublic class E {\n\tpublic static final Scanner IN = new Scanner(System.in);\n\tpublic static final int N_SIZE = 20;\n\tpublic static final int NN_SIZE = N_SIZE * 2;\n\tpublic static int[][] MC = new int[N_SIZE][N_SIZE];\n\tpublic static int[][] MMC = new int[NN_SIZE][NN_SIZE];\n\tpublic static int[] degs = new int[N_SIZE];\n\tpublic static int[] ddegs = new int[NN_SIZE];\n\tpublic static int[] ffas = new int[NN_SIZE];\n\t// coding continue\n\n\tpublic static void main(String[] args) {\n\t\tint nTest = Integer.parseInt(IN.nextLine());\n\n\t\twhile (nTest > 0) {\n\t\t\tnTest--;\n\t\t\tint n = Integer.parseInt(IN.nextLine());\n\t\t\tString a = IN.nextLine().trim();\n\t\t\tString b = IN.nextLine().trim();\n\t\t\ttrans2matrix(a, b, n);\n\t\t\tint solution = NN_SIZE;\n\t\t\tfor (int state = 0; state < (1 << N_SIZE); state++) {\n\t\t\t\tsolution = Math.min(solution, cal(state));\n\t\t\t}\n\t\t\tSystem.out.println(solution);\n\t\t}\n\t}\n\n\tprivate static int cal(int state) {\n\t\tdoubleMatrix(state);\n\t\tfor (int id = 0; id < NN_SIZE; id++) {\n\t\t\tffas[id] = id;\n\t\t}\n\t\tint nComponent = NN_SIZE;\n\t\tQueue queue = new LinkedList();\n\t\tfor (int id = 0; id < NN_SIZE; id++) {\n\t\t\tif (ddegs[id] == 0) {\n\t\t\t\tqueue.add(id);\n\t\t\t}\n\t\t}\n\t\twhile (queue.size() > 0) {\n\t\t\tint u = queue.poll();\n\t\t\tfor (int v = 0; v < NN_SIZE; v++) {\n\t\t\t\tif (MMC[u][v] > 0) {\n\t\t\t\t\tddegs[v] -= MMC[u][v];\n\t\t\t\t\tif (ddegs[v] == 0) {\n\t\t\t\t\t\tqueue.add(v);\n\t\t\t\t\t}\n\t\t\t\t\tint faU = findFa(ffas, u);\n\t\t\t\t\tint faV = findFa(ffas, v);\n\t\t\t\t\tif (faU != faV) {\n\t\t\t\t\t\tffas[faV] = faU;\n\t\t\t\t\t\tnComponent--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int id = 0; id < NN_SIZE; id++) {\n\t\t\tif (ddegs[id] > 0) {\n\t\t\t\treturn NN_SIZE;\n\t\t\t}\n\t\t}\n\t\treturn NN_SIZE - nComponent;\n\t}\n\n\tprivate static int findFa(int[] fas, int u) {\n\t\tif (fas[u] == u) {\n\t\t\treturn u;\n\t\t}\n\t\tfas[u] = findFa(fas, fas[u]);\n\t\treturn fas[u];\n\t}\n\n\tprivate static void doubleMatrix(int state) {\n\t\tfor (int idi = 0; idi < NN_SIZE; idi++) {\n\t\t\tddegs[idi] = 0;\n\t\t\tfor (int idj = 0; idj < NN_SIZE; idj++) {\n\t\t\t\tMMC[idi][idj] = 0;\n\t\t\t}\n\t\t}\n\t\tfor (int idi = 0; idi < N_SIZE; idi++) {\n\t\t\tfor (int idj = 0; idj < N_SIZE; idj++) {\n\t\t\t\tif (MC[idi][idj] > 0) {\n\t\t\t\t\tif ((state & (1 << idj)) > 0) {\n\t\t\t\t\t\tMMC[idi][idj + N_SIZE] = MC[idi][idj];\n\t\t\t\t\t\tddegs[idj + N_SIZE] += MC[idi][idj];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tMMC[idi][idj] = MC[idi][idj];\n\t\t\t\t\t\tddegs[idj] += MC[idi][idj];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static void trans2matrix(String a, String b, int n) {\n\t\tfor (int idi = 0; idi < N_SIZE; idi++) {\n\t\t\tdegs[idi] = 0;\n\t\t\tfor (int idj = 0; idj < N_SIZE; idj++) {\n\t\t\t\tMC[idi][idj] = 0;\n\t\t\t}\n\t\t}\n\t\tfor (int id = 0; id < n; id++) {\n\t\t\tint valueA = a.charAt(id) - 'a';\n\t\t\tint valueB = b.charAt(id) - 'a';\n\t\t\tif (valueA != valueB) {\n\t\t\t\tMC[valueA][valueB]++;\n\t\t\t\tdegs[valueA]++;\n\t\t\t\tdegs[valueB]++;\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "acfbd3b728dff7ab9781485a33344464", "src_uid": "d0735a763e2a40bfc94085019cd646f0", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tstatic final int P = 1_000_000_007;\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint[] dp = new int[n + 2];\n\t\tdp[0] = 1;\n\t\tfor (int k = 1; k <= n; k++) {\n\t\t\tint[] nxt = new int[n + 1];\n\t\t\tint need = n + 1 - k;\n\t\t\tfor (int i = 0; i <= need + 1; i++) {\n\t\t\t\tfor (int j = 0; i + j - 1 <= need; j++) {\n\t\t\t\t\tint prod = (int) ((long) dp[i] * dp[j] % P);\n\n\t\t\t\t\tif (i + j <= need) {\n\t\t\t\t\t\tnxt[i + j] += prod;\n\t\t\t\t\t\tif (nxt[i + j] >= P) {\n\t\t\t\t\t\t\tnxt[i + j] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnxt[i + j] += (int) (2L * prod * (i + j) % P);\n\t\t\t\t\t\tif (nxt[i + j] >= P) {\n\t\t\t\t\t\t\tnxt[i + j] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (i + j + 1 <= need) {\n\t\t\t\t\t\t\tnxt[i + j + 1] += prod;\n\t\t\t\t\t\t\tif (nxt[i + j + 1] >= P) {\n\t\t\t\t\t\t\t\tnxt[i + j + 1] -= P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (i + j > 0) {\n\t\t\t\t\t\tint mult = (i + j) * (i + j) - i - j;\n\t\t\t\t\t\tnxt[i + j - 1] += (int) ((long)mult * prod % P);\n\t\t\t\t\t\tif (nxt[i + j - 1] >= P) {\n\t\t\t\t\t\t\tnxt[i + j - 1] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = nxt;\n//\t\t\tSystem.err.println(Arrays.toString(dp));\n\t\t}\n\n\t\tout.println(dp[1]);\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tD() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "669844cd692019d169d2797f5ae7b1d2", "src_uid": "fda761834f7b5800f540178ac1c79fca", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DSingerHouse solver = new DSingerHouse();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DSingerHouse {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int m = n + 2;\n long[][] dp = new long[n + 1][m + 1];\n\n Modular mod = new Modular(1e9 + 7);\n\n dp[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= m; j++) {\n for (int k = 0; k <= m; k++) {\n int way = mod.mul(dp[i - 1][j], dp[i - 1][k]);\n if (j + k <= m) {\n //not appear\n int next = j + k;\n dp[i][next] += way;\n }\n if (j + k - 1 <= m && j + k - 1 >= 0) {\n //appear, and concatenate\n int next = j + k - 1;\n int local = mod.mul(way, (j + k) * (j + k - 1));\n dp[i][next] += local;\n }\n if (j + k <= m) {\n //appear, but only appear on one side\n int next = j + k;\n int local = mod.mul(way, 2 * (j + k));\n dp[i][next] += local;\n }\n if (j + k + 1 <= m) {\n //appear, with new in/out\n int next = j + k + 1;\n dp[i][next] += way;\n }\n }\n }\n dp[i][0] = 1;\n for (int j = 0; j <= m; j++) {\n dp[i][j] = mod.valueOf(dp[i][j]);\n }\n }\n\n //debug.debug(\"dp\", dp);\n int ans = (int) dp[n][1];\n out.println(ans);\n }\n\n }\n\n static class Modular {\n int m;\n\n public Modular(int m) {\n this.m = m;\n }\n\n public Modular(long m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public Modular(double m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public int valueOf(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 return valueOf(x * y);\n }\n\n public String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(int c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e24c8233a1c69d6bcb29c3147b7de051", "src_uid": "fda761834f7b5800f540178ac1c79fca", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class P0424D {\n\n\tstatic final int MOD = 1000000007;\n\n\tlong[][] binoms;\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tint K = Integer.parseInt(br.readLine());\n\n\t\tlong[][] dp = new long[K + 1][];\n\n\t\tfor (int k = 0; k <= K; k++) {\n\n\t\t\tdp[k] = new long[K - k + 2];\n\n\t\t\tfor (int p = 0; p < K - k + 2; p++) {\n\n\t\t\t\tif (p == 0) {\n\t\t\t\t\tdp[k][p] = 1;\n\t\t\t\t} else if (k == 0) {\n\t\t\t\t\tdp[k][p] = 0;\n\t\t\t\t} else {\n\n\t\t\t\t\tfor (int i = 0; i <= p; i++) {\n\t\t\t\t\t\tdp[k][p] += dp[k - 1][i] * dp[k - 1][p - i];\n\t\t\t\t\t\tdp[k][p] %= MOD;\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (int i = 0; i <= p - 1; i++) {\n\n\t\t\t\t\t\tlong inc = (dp[k - 1][i + 1] * dp[k - 1][p - i]) % MOD;\n\t\t\t\t\t\tinc *= 2 * (i + 1) * (p - i);\n\t\t\t\t\t\tdp[k][p] += inc % MOD;\n\n\t\t\t\t\t\tinc = (dp[k - 1][i + 2] * dp[k - 1][p - i - 1]) % MOD;\n\t\t\t\t\t\tinc *= 2 * (i + 2) * (i + 1);\n\t\t\t\t\t\tdp[k][p] += inc % MOD;\n\n\t\t\t\t\t\tinc = (dp[k - 1][i + 1] * dp[k - 1][p - i - 1]) % MOD;\n\t\t\t\t\t\tinc *= 4 * (i + 1);\n\t\t\t\t\t\tdp[k][p] += inc % MOD;\n\n\t\t\t\t\t\tdp[k][p] += dp[k - 1][i] * dp[k - 1][p - i - 1];\n\t\t\t\t\t\tdp[k][p] %= MOD;\n\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t\tSystem.out.println(dp[K][1]);\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "872ed87201d2837e44f079d77624db7e", "src_uid": "fda761834f7b5800f540178ac1c79fca", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n static final long MODULO = (long) (1e9 + 7);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int k = in.nextInt();\n long[][] comb = new long[k + 2][k + 2];\n comb[0][0] = 1;\n for (int a = 1; a < comb.length; ++a) {\n comb[a][0] = 1;\n for (int b = 1; b < comb.length; ++b) {\n comb[a][b] = (comb[a - 1][b] + comb[a - 1][b - 1]) % MODULO;\n }\n }\n long[] p2 = new long[k + 2];\n p2[0] = 1;\n for (int i = 1; i < p2.length; ++i) p2[i] = 2 * p2[i - 1] % MODULO;\n long[][] res = new long[k + 1][k + 2];\n long[] ways = new long[k + 2];\n\n res[0][0] = 1;\n for (int size = 1; size <= k; ++size) {\n ways[0] = 1;\n for (int numpaths = 1; numpaths <= k + 1; ++numpaths) {\n ways[numpaths] = 0;\n for (int left = 0; left <= numpaths; ++left) {\n ways[numpaths] = (ways[numpaths] + res[size - 1][left] * res[size - 1][numpaths - left] % MODULO * comb[numpaths][left]) % MODULO;\n }\n }\n res[size][0] = 1;\n for (int numpaths = 1; numpaths <= k + 1; ++numpaths) {\n long sum = ways[numpaths];\n for (int joinleft = 0; joinleft <= 1; ++joinleft) {\n for (int joinright = 0; joinright <= 1; ++joinright) {\n int prevnumpaths = numpaths - 1 + joinleft + joinright;\n if (prevnumpaths >= 0 && prevnumpaths <= k + 1) {\n long cur = ways[prevnumpaths];\n /*if (joinleft > 0) {\n cur = cur * prevnumpaths % MODULO;\n --prevnumpaths;\n }\n if (joinright > 0) {\n cur = cur * prevnumpaths % MODULO;\n --prevnumpaths;\n }\n if (joinleft > 0 && joinright > 0) {\n cur = cur * inv2 % MODULO;\n }*/\n sum = (sum + cur * numpaths) % MODULO;\n }\n }\n }\n res[size][numpaths] = sum % MODULO;\n }\n }\n out.println(res[k][1]);\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b113117fd0c9e06b2d9e015a98c8177d", "src_uid": "fda761834f7b5800f540178ac1c79fca", "difficulty": 2800.0} {"lang": "Java 11", "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 stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e9b7d53f62261a4a1987547bed2b0a34", "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8", "difficulty": 2600.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class F {\r\n\t\r\n\tstatic IOHandler sc = new IOHandler();\r\n\t\r\n\tstatic int mod = 998244353;\r\n\t\r\n\t//static Integer [][] memo;\r\n\t\r\n\tstatic Map [] memo;\r\n\t\r\n\tstatic int [] ored;\r\n\tstatic int [] clear;\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\tsolve(0);\r\n\t}\r\n\t\r\n\tprivate static void solve(int t) {\r\n\t\tint n = sc.nextInt();\r\n\t\tmemo = new Map[1024];\r\n\t\t\r\n\t\tfor (int i = 0; i < memo.length; ++i)\r\n\t\t\tmemo[i] = new HashMap<>();\r\n\t\t\r\n\t\tboolean [][] digits = new boolean [10][10];\r\n\t\t\r\n\t\tint m = sc.nextInt();\r\n\t\t\r\n\t\tint a,b;\r\n\t\t\r\n\t\tfor (int i = 0; i < m; ++i) {\r\n\t\t\ta = sc.nextInt();\r\n\t\t\tb = sc.nextInt();\r\n\t\t\t\r\n\t\t\tdigits[a][b] = true;\r\n\t\t\tdigits[b][a] = true;\r\n\t\t}\r\n\t\t\r\n\t\tored = new int [10];\r\n\t\tclear = new int [10];\r\n\t\t\r\n\t\tfor (int i = 0; i < 10; ++i) {\r\n\t\t\tfor (int j = 0; j < 10; ++j) {\r\n\t\t\t\tif (i == j || !digits[i][j]) continue;\r\n\t\t\t\t\r\n\t\t\t\tclear[i] = clear[i] | (1 << j);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tfor (int i = 0; i < 10; ++i) {\r\n\t\t\tfor (int j = i - 1; j >= 0; --j) {\r\n\t\t\t\tif (!digits[i][j]) continue;\r\n\t\t\t\t\r\n\t\t\t\tored[i] = ored[i] | (1 << j);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tSystem.out.println(solve2(n , 0));\r\n\t}\r\n\t\r\n\tprivate static int solve2(int n, int pos) {\r\n\t\tif (n == 0) return 1;\r\n\t\telse if (memo[pos].containsKey(n))\r\n\t\t\treturn memo[pos].get(n);\r\n\t\t\r\n\t\tint cur;\r\n\t\tint result = 0;\r\n\t\t\r\n\t\tfor (int i = 0; i < 10; ++i) {\r\n\t\t\t\r\n\t\t\t\r\n\t\t\tif ( ( pos & (1 << i) ) != 0 ) continue;\r\n\t\t\t\r\n\t\t\tcur = pos;\r\n\t\t\tcur = cur & clear[i];\r\n\t\t\tcur = cur | ored[i];\r\n\t\t\t\r\n\t\t\tresult += solve2(n - 1 , cur);\r\n\t\t\t\r\n\t\t\t\r\n\t\t\tresult %= mod;\r\n\t\t}\r\n\t\t\r\n\t\tmemo[pos].put(n, result);\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\t\r\n\tprivate static class IOHandler {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n \r\n public IOHandler() {\r\n br = new BufferedReader(new InputStreamReader(System.in));\r\n }\r\n \r\n String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n \r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n \r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n \r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n \r\n String nextLine(){\r\n String str = \"\";\r\n\t\t try {\r\n\t\t str = br.readLine();\r\n\t\t } catch (IOException e) {\r\n\t\t e.printStackTrace();\r\n\t\t }\r\n\t\t return str;\r\n }\r\n\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0810721c6bf745b27833be4c9bf4d650", "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8", "difficulty": 2600.0} {"lang": "Java 8", "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 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65949cccb4ca3d9a1258cbe397876d62", "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8", "difficulty": 2600.0} {"lang": "Java 11", "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<<10][10];\r\n\t\tfor(int j = 0;j < 1<<10;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<<10];\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<<10];\r\n\t\t\tfor(int j = 0;j < 1<<10;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 stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a78ee2d58385659a3b66b0888bbf77b4", "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "package round122;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\n\npublic class E2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"9999999999999\";\n\t\n\tvoid solve()\n\t{\n\t\tint M2 = 1<<13;\n\t\tint M5 = 5*5*5*5*5*5*5*5*5*5*5*5*5;\n\t\t\n\t\tlong f = nl();\n\t\tint x2 = (int)(f % M2);\n\t\tint[] fa2 = new int[M2];\n\t\tint[] a2 = new int[1<<14];\n\t\ta2[0] = 0;\n\t\ta2[1] = 1;\n\t\tArrays.fill(fa2, -1);\n\t\tfa2[0] = 0;\n\t\tfa2[1] = 1;\n\t\tfor(int i = 2;i < 13000;i++){\n\t\t\ta2[i] = (a2[i-1] + a2[i-2]) % M2;\n\t\t\tif(fa2[a2[i]] == -1)fa2[a2[i]] = i;\n\t\t}\n\t\tif(fa2[x2] == -1){\n\t\t\tout.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint f5 = (int)(f%5);\n\t\tList l = new ArrayList();\n\t\t{\n\t\t\tint[] a = new int[20];\n\t\t\ta[0] = 0;\n\t\t\ta[1] = 1;\n\t\t\tfor(int i = 2;i < 4*5;i++){\n\t\t\t\ta[i] = (a[i-1] + a[i-2]) % 5;\n\t\t\t}\n\t\t\tfor(int i = 0;i < 4*5;i++){\n\t\t\t\tif(a[i] == f5){\n\t\t\t\t\tl.add((long)i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] F = {\n\t\t\t\t{1, 1}, {1, 0}\n\t\t};\n\t\tfor(long m = 25;m <= M5;m*=5){\n\t\t\tint fm = (int)(f % m);\n\t\t\tList nl = new ArrayList();\n\t\t\tfor(long ll : l){\n\t\t\t\tfor(int k = 0;k < 5;k++){\n\t\t\t\t\tlong ne = ll+k*4*(m/5);\n\t\t\t\t\tlong nf = 0;\n\t\t\t\t\tif(ne == 0){\n\t\t\t\t\t\tnf = 0;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tnf = pow(F, new int[]{1, 0}, ne-1, (int)m)[0];\n\t\t\t\t\t}\n\t\t\t\t\tif(nf == fm){\n\t\t\t\t\t\tnl.add(ne);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tl = nl;\n\t\t}\n\t\t\n\t\tlong min = Long.MAX_VALUE;\n\t\tfor(long ll : l){\n\t\t\tfor(int u : a2){\n\t\t\t\tif(u == f % M2){\n\t\t\t\t\tlong num = crtx(new long[]{M2*3/2, 4L*M5}, new long[]{u, ll}).longValue();\n\t\t\t\t\tif(num >= 0){\n\t\t\t\t\t\tmin = Math.min(min, num);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n//\t\t\tlong num = crt(M2*3/2, fa2[x2], 4L*M5, ll);\n\t\t}\n\t\tif(min == Long.MAX_VALUE){\n\t\t\tout.println(-1);\n\t\t}else{\n\t\t\tout.println(min);\n\t\t}\n\t}\n\t\n\tpublic static long crt(long p, long m, long q, long n)\n\t{\n\t\tlong[] apr = exGCD(p, q);\n\t\tif((n - m) % apr[0] != 0)return -1;\n\t\tlong mod = p * q / apr[0];\n\t\tlong a = (apr[1] * (n - m) / apr[0] * p + m) % mod;\n\t\tif(a < 0)a += mod;\n\t\treturn a;\n\t}\n\t\n\t// int\u884c\u5217*\u30d9\u30af\u30c8\u30eb\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\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\t// int\u884c\u5217\u306e2\u4e57\n\tpublic static int[][] p2(int[][] A, int mod)\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 BigInteger[] exGCD(BigInteger a, BigInteger b)\n\t{\n\t\tBigInteger p = BigInteger.ONE, q = BigInteger.ZERO, r = BigInteger.ZERO, s = BigInteger.ONE;\n\t\twhile(b.signum() > 0){\n\t\t\tBigInteger c = a.divide(b);\n\t\t\tBigInteger d;\n\t\t\td = a; a = b; b = d.mod(b);\n\t\t\td = p; p = q; q = d.subtract(c.multiply(q));\n\t\t\td = r; r = s; s = d.subtract(c.multiply(s));\n\t\t}\n\t\treturn new BigInteger[]{a, p, r};\n\t}\n\t\n\tpublic static BigInteger bi(long x){ return BigInteger.valueOf(x); }\n\t\n\tpublic static BigInteger crtx(long[] divs, long[] mods)\n\t{\n\t\tBigInteger div = bi(divs[0]), mod = bi(mods[0]);\n\t\tfor(int i = 1;i < divs.length;i++){\n\t\t\tBigInteger[] apr = exGCD(div, bi(divs[i]));\n\t\t\tBigInteger mm = bi(mods[i]).subtract(mod);\n\t\t\tif(mm.mod(apr[0]).signum() != 0)return bi(-1);\n\t\t\tBigInteger da = div.divide(apr[0]);\n\t\t\tBigInteger ndiv = bi(divs[i]).multiply(da);\n\t\t\tBigInteger nmod = apr[1].multiply(mm).multiply(da).add(mod).mod(ndiv);\n\t\t\tif(nmod.signum() < 0)nmod = nmod.add(ndiv);\n\t\t\tdiv = ndiv;\n\t\t\tmod = nmod;\n\t\t}\n\t\treturn mod;\n\t}\n\t\n\t// A^e*v\n\tpublic static int[] pow(int[][] A, int[] v, long e, int mod)\n\t{\n\t\tint[][] MUL = A;\n\t\tfor(;e > 0;e>>>=1) {\n\t\t\tif((e&1)==1)v = mul(MUL, v, mod);\n\t\t\tMUL = p2(MUL, mod);\n\t\t}\n\t\treturn v;\n\t}\n\t\n\tpublic static long[] exGCD(long a, long b)\n\t{\n\t\tlong p = 1, q = 0, r = 0, s = 1;\n\t\twhile(b > 0){\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a; a = b; b = d % b;\n\t\t\td = p; p = q; q = d - c * q;\n\t\t\td = r; r = s; s = d - c * s;\n\t\t}\n\t\treturn new long[]{a, p, r};\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew E2().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "742f98c866a26c343fb9e622bddd3145", "src_uid": "cbf786abfceeb8df29732c8a872f7f8a", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "//package round122;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\n\npublic class E2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint M2 = 1<<13;\n\t\tint M5 = 5*5*5*5*5*5*5*5*5*5*5*5*5;\n\t\t\n\t\tlong f = nl();\n\t\tint x2 = (int)(f % M2);\n\t\tint[] fa2 = new int[M2];\n\t\tint[] a2 = new int[1<<14];\n\t\ta2[0] = 0;\n\t\ta2[1] = 1;\n\t\tArrays.fill(fa2, -1);\n\t\tfa2[0] = 0;\n\t\tfa2[1] = 1;\n\t\tfor(int i = 2;i < 13000;i++){\n\t\t\ta2[i] = (a2[i-1] + a2[i-2]) % M2;\n\t\t\tif(fa2[a2[i]] == -1)fa2[a2[i]] = i;\n\t\t}\n\t\tif(fa2[x2] == -1){\n\t\t\tout.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint f5 = (int)(f%5);\n\t\tList l = new ArrayList();\n\t\t{\n\t\t\tint[] a = new int[20];\n\t\t\ta[0] = 0;\n\t\t\ta[1] = 1;\n\t\t\tfor(int i = 2;i < 4*5;i++){\n\t\t\t\ta[i] = (a[i-1] + a[i-2]) % 5;\n\t\t\t}\n\t\t\tfor(int i = 0;i < 4*5;i++){\n\t\t\t\tif(a[i] == f5){\n\t\t\t\t\tl.add((long)i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] F = {\n\t\t\t\t{1, 1}, {1, 0}\n\t\t};\n\t\tfor(long m = 25;m <= M5;m*=5){\n\t\t\tint fm = (int)(f % m);\n\t\t\tList nl = new ArrayList();\n\t\t\tfor(long ll : l){\n\t\t\t\tfor(int k = 0;k < 5;k++){\n\t\t\t\t\tlong ne = ll+k*4*(m/5);\n\t\t\t\t\tlong nf = 0;\n\t\t\t\t\tif(ne == 0){\n\t\t\t\t\t\tnf = 0;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tnf = pow(F, new int[]{1, 0}, ne-1, (int)m)[0];\n\t\t\t\t\t}\n\t\t\t\t\tif(nf == fm){\n\t\t\t\t\t\tnl.add(ne);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tl = nl;\n\t\t}\n\t\t\n\t\tlong min = Long.MAX_VALUE;\n\t\tfor(long ll : l){\n\t\t\tfor(int i = 0;i < a2.length;i++){\n\t\t\t\tif(a2[i] == f % M2){\n\t\t\t\t\tlong num = crtx(new long[]{M2*3/2, 4L*M5}, new long[]{i, ll}).longValue();\n\t\t\t\t\tif(num >= 0){\n\t\t\t\t\t\tmin = Math.min(min, num);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n//\t\t\tlong num = crt(M2*3/2, fa2[x2], 4L*M5, ll);\n\t\t}\n\t\tif(min == Long.MAX_VALUE){\n\t\t\tout.println(-1);\n\t\t}else{\n\t\t\tout.println(min);\n\t\t}\n\t}\n\t\n\tpublic static long crt(long p, long m, long q, long n)\n\t{\n\t\tlong[] apr = exGCD(p, q);\n\t\tif((n - m) % apr[0] != 0)return -1;\n\t\tlong mod = p * q / apr[0];\n\t\tlong a = (apr[1] * (n - m) / apr[0] * p + m) % mod;\n\t\tif(a < 0)a += mod;\n\t\treturn a;\n\t}\n\t\n\t// int\u884c\u5217*\u30d9\u30af\u30c8\u30eb\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\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\t// int\u884c\u5217\u306e2\u4e57\n\tpublic static int[][] p2(int[][] A, int mod)\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 BigInteger[] exGCD(BigInteger a, BigInteger b)\n\t{\n\t\tBigInteger p = BigInteger.ONE, q = BigInteger.ZERO, r = BigInteger.ZERO, s = BigInteger.ONE;\n\t\twhile(b.signum() > 0){\n\t\t\tBigInteger c = a.divide(b);\n\t\t\tBigInteger d;\n\t\t\td = a; a = b; b = d.mod(b);\n\t\t\td = p; p = q; q = d.subtract(c.multiply(q));\n\t\t\td = r; r = s; s = d.subtract(c.multiply(s));\n\t\t}\n\t\treturn new BigInteger[]{a, p, r};\n\t}\n\t\n\tpublic static BigInteger bi(long x){ return BigInteger.valueOf(x); }\n\t\n\tpublic static BigInteger crtx(long[] divs, long[] mods)\n\t{\n\t\tBigInteger div = bi(divs[0]), mod = bi(mods[0]);\n\t\tfor(int i = 1;i < divs.length;i++){\n\t\t\tBigInteger[] apr = exGCD(div, bi(divs[i]));\n\t\t\tBigInteger mm = bi(mods[i]).subtract(mod);\n\t\t\tif(mm.mod(apr[0]).signum() != 0)return bi(-1);\n\t\t\tBigInteger da = div.divide(apr[0]);\n\t\t\tBigInteger ndiv = bi(divs[i]).multiply(da);\n\t\t\tBigInteger nmod = apr[1].multiply(mm).multiply(da).add(mod).mod(ndiv);\n\t\t\tif(nmod.signum() < 0)nmod = nmod.add(ndiv);\n\t\t\tdiv = ndiv;\n\t\t\tmod = nmod;\n\t\t}\n\t\treturn mod;\n\t}\n\t\n\t// A^e*v\n\tpublic static int[] pow(int[][] A, int[] v, long e, int mod)\n\t{\n\t\tint[][] MUL = A;\n\t\tfor(;e > 0;e>>>=1) {\n\t\t\tif((e&1)==1)v = mul(MUL, v, mod);\n\t\t\tMUL = p2(MUL, mod);\n\t\t}\n\t\treturn v;\n\t}\n\t\n\tpublic static long[] exGCD(long a, long b)\n\t{\n\t\tlong p = 1, q = 0, r = 0, s = 1;\n\t\twhile(b > 0){\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a; a = b; b = d % b;\n\t\t\td = p; p = q; q = d - c * q;\n\t\t\td = r; r = s; s = d - c * s;\n\t\t}\n\t\treturn new long[]{a, p, r};\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew E2().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d73b8982b82ddd3c8be56d766be3229", "src_uid": "cbf786abfceeb8df29732c8a872f7f8a", "difficulty": 2900.0} {"lang": "Java 6", "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.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static final long MODULO = (long) 1e13;\n\n private long[][] mul(long[][] a, long[][] b, long modulo) {\n long[][] c = new long[2][2];\n for (int i = 0; i < 2; ++i)\n for (int j = 0; j < 2; ++j) {\n BigInteger sum = BigInteger.ZERO;\n for (int k = 0; k < 2; ++k)\n sum = sum.add(BigInteger.valueOf(a[i][k]).multiply(BigInteger.valueOf(b[k][j])));\n c[i][j] = sum.mod(BigInteger.valueOf(modulo)).longValue();\n }\n return c;\n }\n \n static class Candidate {\n long offset;\n long[][] trans;\n\n Candidate(long offset, long[][] trans) {\n this.offset = offset;\n this.trans = trans;\n }\n }\n \n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long f = in.nextLong();\n long mod = 1;\n long period = 1;\n long[][] mPeriod = new long[][]{new long[]{0, 1}, new long[]{1, 1}};\n List offsets = new ArrayList();\n offsets.add(new Candidate(0, new long[][]{new long[]{1, 0}, new long[]{0, 1}}));\n for (int i = 0; i < 26; ++i) {\n if (i < 13)\n mod *= 2;\n else\n mod *= 5;\n long nperiod = period;\n long[][] nmPeriod = mPeriod;\n while (nmPeriod[0][1] % mod != 0 || nmPeriod[1][1] % mod != 1) {\n nmPeriod = mul(nmPeriod, mPeriod, MODULO);\n nperiod += period;\n }\n List newOffsets = new ArrayList();\n for (Candidate old : offsets) {\n long[][] trans = old.trans;\n for (long noffset = old.offset; noffset < nperiod; noffset += period) {\n if ((trans[0][1] % mod == f % mod)) {\n newOffsets.add(new Candidate(noffset, trans));\n }\n trans = mul(trans, mPeriod, MODULO);\n }\n }\n offsets = newOffsets;\n period = nperiod;\n mPeriod = nmPeriod;\n }\n long min = Long.MAX_VALUE;\n for (Candidate c : offsets)\n min = Math.min(min, c.offset);\n if (min == Long.MAX_VALUE) out.println(-1); else out.println(min);\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 long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "26c57e10810a56b2698033c873e6d059", "src_uid": "cbf786abfceeb8df29732c8a872f7f8a", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\tfinal static int PERIOD = 60;\n\tfinal static int POWER = 13;\n\n\tlong fib(long n, long mod) {\n\t\tlong[][] mat = new long[2][2];\n\t\tmat[0][1] = mat[1][0] = mat[1][1] = 1;\n\t\tMatrix v = new Matrix(mat);\n\t\tv = v.power(n, mod);\n\t\treturn v.mat[0][1];\n\t}\n\n\tvoid run() {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tlong num = in.nextLong(), mod = 10, per = PERIOD;\n\t\tArrayList valid = new ArrayList();\n\t\tfor (int i = 0; i < PERIOD; ++i)\n\t\t\tif (fib(i, mod) == num % mod)\n\t\t\t\tvalid.add((long)i);\n\n\t\tfor (int i = 1; i < POWER; ++i) {\n\t\t\tmod *= 10;\n\t\t\tlong rem = num % mod;\n\t\t\tArrayList nv = new ArrayList();\n\t\t\tfor (int j = 0; j < 10; ++j)\n\t\t\t\tfor (int k = 0; k < valid.size(); ++k) {\n\t\t\t\t\tif (fib(j * per + valid.get(k), mod) == rem)\n\t\t\t\t\t\tnv.add(j * per + valid.get(k));\n\t\t\t\t}\n\t\t\tvalid = nv;\n\t\t\tper *= 10;\n\t\t}\n\n\t\tif (valid.size() == 0)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(valid.get(0));\n\t\tout.close();\n\t}\n}\n\nclass Matrix {\n\tlong[][] mat;\n\tfinal static Matrix ONE = new Matrix(new long[][] {{1, 0}, {0, 1}});\n\tMatrix(long[][] mat) {\n\t\tthis.mat = mat;\n\t}\n\tlong add(long a, long b, long mod) {\n\t\tif (a + b >= mod)\n\t\t\treturn a + b - mod;\n\t\treturn a + b;\n\t}\n\tlong multiply(long a, long b, long mod) {\n\t\tlong ret = 0;\n\t\twhile (a > 0) {\n\t\t\tif ((a & 1) == 1)\n\t\t\t\tret = add(ret, b, mod);\n\t\t\tb = add(b, b, mod);\n\t\t\ta >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\tMatrix multiply(Matrix o, long mod) {\n\t\tlong[][] ret = new long[2][2];\n\t\tfor (int i = 0; i < 2; ++i)\n\t\t\tfor (int j = 0; j < 2; ++j)\n\t\t\t\tfor (int k = 0; k < 2; ++k)\n\t\t\t\t\tret[i][j] = add(ret[i][j], multiply(mat[i][k], o.mat[k][j], mod), mod);\n\t\treturn new Matrix(ret);\n\t}\n\tMatrix power(long p, long mod) {\n\t\tif (p == 0) {\n\t\t\treturn Matrix.ONE;\n\t\t}\n\t\tMatrix ret = power(p / 2, mod);\n\t\tret = ret.multiply(ret, mod);\n\t\tif ((p & 1) == 1)\n\t\t\tret = ret.multiply(this, mod);\n\t\treturn ret;\n\t}\n}\n\nclass InputReader {\n\tBufferedReader buff;\n\tStringTokenizer tokenizer;\n\n\tInputReader(InputStream stream) {\n\t\tbuff = new BufferedReader(new InputStreamReader(stream));\n\t\ttokenizer = null;\n\t}\n\tboolean hasNext() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(buff.readLine());\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\treturn true;\n\t}\n\tString next() {\n\t\tif (!hasNext())\n\t\t\tthrow new RuntimeException();\n\t\treturn tokenizer.nextToken();\n\t}\n\tint nextInt() { return Integer.parseInt(next()); }\n\tlong nextLong() { return Long.parseLong(next()); }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "923e6f2a79893fa8c73e5082da253c3a", "src_uid": "cbf786abfceeb8df29732c8a872f7f8a", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedOutputStream;\nimport java.util.HashSet;\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 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 HashSet Sum = new HashSet<>(), Query = new HashSet<>(), set = new HashSet<>();\n for (Point P : sum) Sum.add(P.toPair());\n for (Point P : query) Query.add(P.toPair());\n Point[] join = new Point[sum.length + query.length];\n for (int i = 0; i < sum.length; i++) join[i] = sum[i];\n for (int i = 0; i < query.length; i++) join[sum.length + i] = query[i];\n ConvexHull.Point[] hull = ConvexHull.convexHull(join);\n for (ConvexHull.Point P : hull) {\n EzIntIntPair pair = new EzIntIntPair(P.x, P.y);\n if (Query.contains(pair) && !Sum.contains(pair)) set.add(pair);\n }\n for (Point P : query) out.println(set.contains(P.toPair()) ? \"NO\" : \"YES\");\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 {\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 EzIntIntPair toPair() {\n return new EzIntIntPair(x, 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 EzIntIntPair implements Comparable {\n private static final int HASHCODE_INITIAL_VALUE = 0x811c9dc5;\n private static final int HASHCODE_MULTIPLIER = 0x01000193;\n public final int first;\n public final int second;\n\n public EzIntIntPair(int first, int second) {\n this.first = first;\n this.second = second;\n }\n\n\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n EzIntIntPair that = (EzIntIntPair) o;\n\n return first == that.first && second == that.second;\n }\n\n\n public int hashCode() {\n int hash = HASHCODE_INITIAL_VALUE;\n hash = (hash ^ PrimitiveHashCalculator.getHash(first)) * HASHCODE_MULTIPLIER;\n hash = (hash ^ PrimitiveHashCalculator.getHash(second)) * HASHCODE_MULTIPLIER;\n return hash;\n }\n\n\n public int compareTo(EzIntIntPair other) {\n int cmpU = Integer.compare(first, other.first);\n return cmpU != 0 ? cmpU : Integer.compare(second, other.second);\n }\n\n\n public String toString() {\n return \"(\" + first + \", \" + second + \")\";\n }\n\n }\n\n static class ConvexHull {\n public static ConvexHull.Point[] convexHull(ConvexHull.Point[] p) {\n int n = p.length;\n if (n <= 1)\n return p;\n Arrays.sort(p, (a, b) -> Integer.compare(a.x, b.x) != 0 ? Integer.compare(a.x, b.x) : Integer.compare(a.y, b.y));\n ConvexHull.Point[] h = new ConvexHull.Point[n * 2];\n int cnt = 0;\n for (int i = 0; i < n; h[cnt++] = p[i++])\n while (cnt > 1 && cross(h[cnt - 2], h[cnt - 1], p[i]) >= 0)\n --cnt;\n for (int i = n - 2, t = cnt; i >= 0; h[cnt++] = p[i--])\n while (cnt > t && cross(h[cnt - 2], h[cnt - 1], p[i]) >= 0)\n --cnt;\n return Arrays.copyOf(h, cnt - 1 - (h[0].x == h[1].x && h[0].y == h[1].y ? 1 : 0));\n }\n\n static long cross(ConvexHull.Point a, ConvexHull.Point b, ConvexHull.Point c) {\n return (long) (b.x - a.x) * (c.y - a.y) - (long) (b.y - a.y) * (c.x - a.x);\n }\n\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 final class PrimitiveHashCalculator {\n private PrimitiveHashCalculator() {\n }\n\n public static int getHash(int x) {\n return x;\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b6d1bd89196835931ecdeb71056af19b", "src_uid": "a764daf8e19e48a0735811a4f67485c3", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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 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 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 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 {\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5887da47e4b29db2adf32a8a33624007", "src_uid": "a764daf8e19e48a0735811a4f67485c3", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class Idol implements Runnable {\n static class Point {\n final long x;\n final long y;\n\n Point(long x, long y) {\n this.x = x;\n this.y = y;\n }\n }\n\n class Polygon {\n List vertices = new ArrayList();\n List leftBorder = new ArrayList();\n List rightBorder = new ArrayList();\n\n void read() throws IOException {\n int n = nextInt();\n for (int i = 0; i < n; ++i) {\n int x = nextInt();\n int y = nextInt();\n vertices.add(new Point(x, y));\n }\n }\n\n public void prepareBorders() {\n long maxy = Long.MIN_VALUE;\n long miny = Long.MAX_VALUE;\n for (Point p : vertices) {\n miny = Math.min(miny, p.y);\n maxy = Math.max(maxy, p.y);\n }\n {\n int rightStart;\n for (rightStart = 0; rightStart < vertices.size(); ++rightStart) {\n if (vertices.get(rightStart).y == miny && vertices.get((rightStart + 1) % vertices.size()).y > miny) {\n break;\n }\n }\n for (int i = rightStart;; i = (i + 1) % vertices.size()) {\n rightBorder.add(vertices.get(i));\n if (vertices.get(i).y == maxy)\n break;\n }\n }\n {\n int leftStart;\n for (leftStart = 0; leftStart < vertices.size(); ++leftStart) {\n if (vertices.get(leftStart).y == maxy && vertices.get((leftStart + 1) % vertices.size()).y < maxy) {\n break;\n }\n }\n for (int i = leftStart;; i = (i + 1) % vertices.size()) {\n leftBorder.add(vertices.get(i));\n if (vertices.get(i).y == miny)\n break;\n }\n }\n }\n\n public boolean inside(Point point) {\n int rightPos;\n int leftPos;\n {\n int left = -1;\n int right = rightBorder.size();\n while (right - left > 1) {\n int middle = (left + right) / 2;\n if (rightBorder.get(middle).y <= point.y)\n left = middle;\n else\n right = middle;\n }\n if (left < 0) return false;\n if (left == rightBorder.size() - 1) --left;\n rightPos = left;\n }\n {\n int left = -1;\n int right = leftBorder.size();\n while (right - left > 1) {\n int middle = (left + right) / 2;\n if (leftBorder.get(middle).y >= point.y)\n left = middle;\n else\n right = middle;\n }\n if (left < 0) return false;\n if (left == leftBorder.size() - 1) --left;\n leftPos = left;\n }\n int z = 1;\n z *= signum(rightBorder.get(rightPos), point, rightBorder.get(rightPos + 1));\n z *= signum(leftBorder.get(leftPos), leftBorder.get(leftPos + 1), point);\n return z <= 0;\n }\n }\n\n private static int signum(Point a, Point b, Point c) {\n long dxb = b.x - a.x;\n long dyb = b.y - a.y;\n long dxc = c.x - a.x;\n long dyc = c.y - a.y;\n long z = dxb * dyc - dxc * dyb;\n if (z < 0) return -1; else if (z > 0) return 1; else return 0;\n }\n\n public Polygon add(Polygon a, Polygon b) {\n Polygon c = new Polygon();\n int sa = 0;\n {\n Point sap = a.vertices.get(0);\n for (int i = 1; i < a.vertices.size(); ++i) {\n Point p = a.vertices.get(i);\n if (p.y < sap.y || p.y == sap.y && p.x < sap.x) {\n sap = p;\n sa = i;\n }\n }\n }\n int sb = 0;\n {\n Point sbp = b.vertices.get(0);\n for (int i = 1; i < b.vertices.size(); ++i) {\n Point p = b.vertices.get(i);\n if (p.y < sbp.y || p.y == sbp.y && p.x < sbp.x) {\n sbp = p;\n sb = i;\n }\n }\n }\n int ra = sa;\n int rb = sb;\n while (true) {\n Point ca = a.vertices.get(sa);\n Point na = a.vertices.get((sa + 1) % a.vertices.size());\n Point cb = b.vertices.get(sb);\n Point nb = b.vertices.get((sb + 1) % b.vertices.size());\n c.vertices.add(addPoints(ca, cb));\n long dxa = na.x - ca.x;\n long dya = na.y - ca.y;\n long dxb = nb.x - cb.x;\n long dyb = nb.y - cb.y;\n long z = (dxa * dyb - dya * dxb);\n if (z > 0) {\n sa = (sa + 1) % a.vertices.size();\n } else if (z < 0) {\n sb = (sb + 1) % b.vertices.size();\n } else {\n sa = (sa + 1) % a.vertices.size();\n sb = (sb + 1) % b.vertices.size();\n }\n if (sa == ra && sb == rb)\n break;\n }\n return c;\n }\n\n private Point addPoints(Point ca, Point cb) {\n return new Point(ca.x + cb.x, ca.y + cb.y);\n }\n\n private void solve() throws IOException {\n Polygon[] p = new Polygon[3];\n for (int i = 0; i < p.length; ++i) {\n p[i] = new Polygon();\n p[i].read();\n }\n Polygon sum = p[0];\n for (int i = 1; i < p.length; ++i) {\n sum = add(sum, p[i]);\n }\n sum.prepareBorders();\n int m = nextInt();\n for (int i = 0; i < m; ++i) {\n int x = nextInt() * 3;\n int y = nextInt() * 3;\n Point pp = new Point(x, y);\n if (sum.inside(pp)) {\n writer.println(\"YES\");\n } else {\n writer.println(\"NO\");\n }\n }\n }\n\n public static void main(String[] args) {\n new Idol().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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d0aaaf31f65f178e1b9674cf6b533274", "src_uid": "a764daf8e19e48a0735811a4f67485c3", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n/*\n5\n4 1 1 1 3 3 3 3 1\n4 4 3 6 2 6 0 4 0\n6 -5 3 -4 4 -3 4 -2 3 -3 2 -4 2\n3 0 -1 1 -3 -1 -3\n4 1 -4 1 -6 -1 -6 -1 -4\n5\n8 1 1 1 2 1 3 2 3 3 3 3 2 3 1 2 1\n4 4 3 6 2 6 0 4 0\n6 -5 3 -4 4 -3 4 -2 3 -3 2 -4 2\n3 0 -1 1 -3 -1 -3\n4 1 -4 1 -6 -1 -6 -1 -4\n7\n4\n1 0\n1 1\n2 1\n2 0\n4\n4 -1\n4 0\n5 0\n5 -1\n4\n7 0\n7 1\n8 1\n8 0\n4\n10 -1\n10 0\n11 0\n11 -1\n4\n-1 0\n-1 -1\n-2 -1\n-2 0\n4\n-4 1\n-4 0\n-5 0\n-5 1\n4\n-7 0\n-7 -1\n-8 -1\n-8 0\n */\npublic class Geom {\n\t\n\tstatic int N, totalSz;\n\tstatic Poly ar[];\n\tstatic boolean RADIAL_SORT,ID_SORT;\n\tstatic Vec radialPnts[];\n\tstatic TreeSet ts;\n\tstatic boolean inTreeSet[];\n\tstatic final boolean debug = false;\n\tstatic Vec ORIGIN = new Vec(0,0);\n\tstatic final double eps = 1e-6;\n\t\n\tpublic static void main(String args[]) {\n\t\tFS in = new FS();\n\t\tN = in.nextInt();\n\t\tar = new Poly[N];\n\t\t//Read in the input and make the polygons \n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tint sz = in.nextInt();\n\t\t\tVec pts[] = new Vec[sz];\n\t\t\tfor(int j = 0; j < sz; j++) {\n\t\t\t\tdouble x = in.nextInt();\n\t\t\t\tdouble y = in.nextInt();\n\t\t\t\tint id = sz-j-1; //make counter-clockwise\n\t\t\t\tpts[id] = new Vec(x,y,id);\n\t\t\t}\n\t\t\tar[i] = new Poly(pts, i);\n\t\t\ttotalSz += ar[i].sz;\n\t\t}\n\t\tradialPnts = new Vec[totalSz];\n\t\tint idd = 0;\n\t\tfor(Poly p : ar)\n\t\t\tfor(Vec v : p.vs)\n\t\t\t\tradialPnts[idd++] = v;\n\t\tsetRadialSort();\n\t\tArrays.sort(radialPnts);\n\t\tif(debug) System.out.println(Arrays.toString(radialPnts));\n\t\tinitSweep();\n\t\tsweep();\n\t\tdouble res = 0;\n\t\tfor(Poly p : ar)\n\t\t\tres += p.area();\n\t\tSystem.out.println(res);\n\t}\n\t\n\tstatic void sweep() {\n\t\tfor(Vec v : radialPnts) {\n\t\t\tif(debug) {\n\t\t\t\tSystem.out.println(\"V= \"+v);\n\t\t\t\tSystem.out.print(\"TS:\");\n\t\t\t\tfor(Poly p : ts) System.out.print(p.id+\" \");\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\tif(v.isLast) {\n\t\t\t\t//Removing this polygon\n\t\t\t\tPoly first = ts.first();\n\t\t\t\tts.remove(v.poly);\n\t\t\t\tinTreeSet[v.poly.id] = false;\n\t\t\t\tif(first.id == v.poly.id && ts.size() > 0 ) { // If this polygon was first, add the lines to the next guy\n\t\t\t\t\tPoly next = ts.first();\n\t\t\t\t\tSeg s = new Seg(ORIGIN, v);\n\t\t\t\t\tnext.intersectF(s, true);\n\t\t\t\t\tnext.intersectR(s, true);\n\t\t\t\t\tnext.isSeen = true; // This guy is seen\n\t\t\t\t}\n\t\t\t\tv.poly.killSegs();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tv.poly.updateSegs(v);\n\t\t\t\tif(!inTreeSet[v.poly.id]) {\n\t\t\t\t\tPoly curFirst = ts.size() == 0 ? null : ts.first();\n\t\t\t\t\tts.add(v.poly);\n\t\t\t\t\tinTreeSet[v.poly.id] = true;\n\t\t\t\t\tif(ts.first().id == v.poly.id) {\n\t\t\t\t\t\tv.poly.isSeen = true;\n\t\t\t\t\t\tif(curFirst != null) {\n\t\t\t\t\t\t\tSeg s = new Seg(ORIGIN, v);\n\t\t\t\t\t\t\tcurFirst.intersectF(s, false);\n\t\t\t\t\t\t\tcurFirst.intersectR(s, false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tstatic void initSweep() {\n\t\t//Set up the fSegs and rSegs (but NOT isSeen / adding the lines/points);\n\t\tinTreeSet = new boolean[N];\n\t\tts = new TreeSet();\n\t\tfor(Vec v : radialPnts) {\n\t\t\tif(debug) System.out.println(\"V= \"+v);\n\t\t\tif(v.isLast) { //Remove this polygon\n\t\t\t\tts.remove(v.poly);\n\t\t\t\tinTreeSet[v.poly.id] = false;\n\t\t\t\tv.poly.killSegs();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tv.poly.updateSegs(v);\n\t\t\t\tif(!inTreeSet[v.poly.id]) ts.add(v.poly);\n\t\t\t\tinTreeSet[v.poly.id] = true;\n\t\t\t}\n\t\t\tif(debug) {\n\t\t\t\tSystem.out.print(\"TS:\");\n\t\t\t\tfor(Poly p : ts) System.out.print(p.id+\" \");\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\t\n\t\t//Sweep is done, set the poly in the first of the treeset to be seen if there is one\n\t\tif(ts.size() > 0) {\n\t\t\tPoly first = ts.first();\n\t\t\tfirst.isSeen = true;\n\t\t}\n\t\tif(debug) System.out.println(\"Done with init\\n\\n\\n\");\n\t}\n\t\n\tstatic void setRadialSort() {\n\t\tRADIAL_SORT = true; ID_SORT = false;\n\t}\n\tstatic void setIDSort() {\n\t\tRADIAL_SORT = false; ID_SORT = true;\n\t}\n\t\n\tstatic class Vec implements Comparable{\n\t\tdouble x,y;\n\t\tint id;\n\t\tdouble sId;\n\t\tVec prev,next;\n\t\tPoly poly;\n\t\tboolean isLast;\n\t\tint polyRemoveId;\n\t\t\n\t\tpublic Vec(double xx, double yy) {x=xx;y=yy;}\n\t\tpublic Vec(double xx, double yy, int ii) {x=xx;y=yy;id=ii;sId=ii;}\n\t\tpublic double cross(Vec o) { return x*o.y - y*o.x; }\n\t\tpublic Vec add(Vec o) { return new Vec(x+o.x, y+o.y); }\n\t\tpublic Vec sub(Vec o) { return new Vec(x-o.x, y-o.y); }\n\t\tpublic double mag(Vec o) { return x*o.x + y*o.y; }\n\t\tpublic Vec scale(double d) { return new Vec(x*d,y*d);}\n\t\t\n\t\tpublic boolean inFrontOf(Seg o) {\n\t\t\tlong c1 = (long)Math.round(o.a.cross(this));\n\t\t\tlong c2 = (long)Math.round(this.cross(o.b));\n\t\t\tif(c1 >= 0 && c2 >= 0) {\n\t\t\t\tlong c3 = (long)Math.round(o.dir.cross(this.sub(o.a)));\n\t\t\t\treturn c3 >= 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tpublic static int compare(Vec a, Vec b) {\n\t\t\tint res = 0;\n\t\t\tif(a.x < 0) res += a.y >= 0 ? 1 : 2;\n\t\t\telse if(a.y < 0) res += 3;\n\t\t\tif(b.x < 0) res -= b.y >= 0 ? 1 : 2;\n\t\t\telse if(b.y < 0) res -= 3;\n\t\t\tif(res == 0) {\n\t\t\t\tlong cross = (long)Math.round(a.cross(b));\n\t\t\t\t//Further points come first if same angle\n\t\t\t\tif(cross == 0) return Long.compare((long)Math.round(b.mag(b)), (long)Math.round(a.mag(a)));\n\t\t\t\tif(cross > 0) return -1;\n\t\t\t\telse return 1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\n\t\t@Override\n\t\tpublic int compareTo(Vec o) {\n\t\t\tif(RADIAL_SORT) {\n\t\t\t\treturn Vec.compare(this, o);\n\t\t\t}\n\t\t\telse if(ID_SORT) {\n\t\t\t\treturn Double.compare(sId, o.sId);\n\t\t\t}\n\t\t\tthrow null;\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+x+\",\"+y+\") id=\"+id+\" p=\"+(poly == null ? -1 : poly.id)+\" sId= \"+sId;\n\t\t}\n\t}\n\t\n\tstatic class Seg{\n\t\tVec a,b,dir;\n\t\tpublic Seg(Vec aa, Vec bb) {\n\t\t\ta=aa;\n\t\t\tb=bb;\n\t\t\tdir = b.sub(a);\n\t\t}\n\t\t\n\t\tpublic boolean inFrontOf(Seg o) {\n\t\t\tif(a.inFrontOf(o)) return true;\n\t\t\tif(b.inFrontOf(o)) return true;\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tpublic Vec lineIntersect(Seg o) {\n\t\t\tdouble det = o.dir.x*dir.y-dir.x*o.dir.y;\n\t\t\tif(eq(det, 0)) return null;\n\t\t\tdouble dist = (o.dir.x * (o.a.y-a.y)-\n\t\t\t\t\to.dir.y*(o.a.x-a.x))/det;\n\t\t\treturn a.add(dir.scale(dist));\n\t\t}\n\t}\n\tstatic class Poly implements Comparable{\n\t\tint sz, id;\n\t\tVec vs[];\n\t\tSeg fSeg, rSeg;\n\t\tdouble fSegAId,rSegAId;\n\t\tboolean isSeen;\n\t\tArrayList interVecs;\n\t\t\n\t\tpublic Poly(Vec[] vss, int ii) {\n\t\t\tArrayList vs2 = new ArrayList();\n\t\t\tfor(int i = 0; i < vss.length; i++) {\n\t\t\t\tVec v = vss[i];\n\t\t\t\tVec prev = vss[(i-1+vss.length)%vss.length];\n\t\t\t\tVec next = vss[(i+1)%vss.length];\n\t\t\t\tif((long)Math.round((v.sub(prev)).cross((next.sub(v)))) != 0) vs2.add(v);\n\t\t\t}\n\t\t\tvs = new Vec[vs2.size()];\n\t\t\tfor(int i = 0; i < vs2.size(); i++) {\n\t\t\t\tVec v = vs2.get(i);\n\t\t\t\tv.id = i; v.sId = i;\n\t\t\t\tvs[i] = v;\n\t\t\t}\n\t\t\tif(debug) {\n\t\t\t\tSystem.out.println(\"Poly: \");\n\t\t\t\tfor(Vec v : vs) System.out.println(\" v=\"+v);\n\t\t\t}\n\t\t\t\n//\t\t\tvs=vss;\n\t\t\tsz = vs.length;\n\t\t\tisSeen = false;\n\t\t\tid = ii;\n\t\t\tfor(int i = 0; i < sz; i++) {\n\t\t\t\tVec prev = vs[(i-1+sz)%sz];\n\t\t\t\tVec next = vs[(i+1)%sz];\n\t\t\t\tvs[i].prev = prev;\n\t\t\t\tvs[i].next = next;\n\t\t\t\tvs[i].poly = this;\n\t\t\t\tlong c1 = (long)Math.round(prev.cross(vs[i]));\n\t\t\t\tlong c2 = (long)Math.round(next.cross(vs[i]));\n\t\t\t\tif(c1 >= 0 && c2 > 0) vs[i].isLast = true;\n\t\t\t}\n\t\t\tinterVecs = new ArrayList();\n\t\t}\n\t\t\n\t\tpublic void killSegs() { fSeg = null; rSeg = null; }\n\t\tpublic void updateSegs(Vec v) {\n\t\t\tif(fSeg == null || rSeg == null) {\n\t\t\t\tfSeg = new Seg(v, v.prev);\n\t\t\t\tfSegAId = v.id;\n\t\t\t\trSeg = new Seg(v, v.next);\n\t\t\t\trSegAId = v.id;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif(fSeg.b.id == v.id) {\n\t\t\t\t\tfSeg = new Seg(v, v.prev);\n\t\t\t\t\tfSegAId = v.id;\n\t\t\t\t}\n\t\t\t\tif(rSeg.b.id == v.id) {\n\t\t\t\t\trSeg = new Seg(v, v.next);\n\t\t\t\t\trSegAId = v.id;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic void intersectF(Seg s, boolean polyRemoved) {\n\t\t\tif(debug) System.out.println(\" inter from \"+s.b.poly.id +\" to \"+this.id);\n\t\t\tVec v = s.lineIntersect(fSeg);\n\t\t\t//get the id for where to put this\n\t\t\tif(fSeg.b.id == sz-1 && eq(fSegAId, 0)) { //can't do inbetween because this is going from (sz-1) -> 0\n\t\t\t\tdouble d = fSegAId + (double)sz - eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdouble d = fSegAId - eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\tv.polyRemoveId = (polyRemoved ? 1 : -1);\n\t\t\tinterVecs.add(v);\n\t\t\tfSegAId = v.sId;\n\t\t}\n\t\tpublic void intersectR(Seg s, boolean polyRemoved) {\n\t\t\tVec v = s.lineIntersect(rSeg);\n\t\t\t//get hte id for where to put this\n\t\t\tif(rSeg.a.id == sz-1) {\n\t\t\t\tdouble d = rSegAId + eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdouble d = rSegAId + eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\tv.polyRemoveId = (polyRemoved ? 1 : -1);\n\t\t\tinterVecs.add(v);\n\t\t\trSegAId = v.sId;\n\t\t}\n\t\t\n\t\tpublic double area() {\n\t\t\tif(debug) System.out.println(\"PID: \"+id+\" seen=\"+isSeen);\n\t\t\tif(!isSeen) return 0;\n\t\t\telse {\n\t\t\t\tdouble res = 0;\n\t\t\t\tsetIDSort();\n\t\t\t\t\n\t\t\t\tif(interVecs.size() == 0) return getArea(vs);\n\t\t\t\t\n\t\t\t\tVec ps[] = new Vec[vs.length + interVecs.size()];\n\t\t\t\tint idd = 0;\n\t\t\t\tfor(Vec v : vs) ps[idd++] = v;\n\t\t\t\tfor(Vec v : interVecs) ps[idd++] = v;\n\t\t\t\tArrays.sort(ps);\n\t\t\t\t\n\t\t\t\tif(debug) {\n\t\t\t\t\tSystem.out.println(\"Poly: \"+id);\n\t\t\t\t\tfor(Vec v : ps) System.out.println(\" \"+v);\n\t\t\t\t\tSystem.out.println();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint curL = ps.length-1, curR = 0;\n\t\t\t\tTreeSet pts = new TreeSet();\n\t\t\t\tpts.add(ps[curL]); pts.add(ps[curR]);\n\t\t\t\t\n\t\t\t\tboolean addArea = false;\n\t\t\t\tboolean started = false;\n\t\t\t\twhile(true) {\n\t\t\t\t\twhile(ps[curL].polyRemoveId == 0) {\n\t\t\t\t\t\tif(curL == curR) break;\n\t\t\t\t\t\tcurL = (curL - 1 + ps.length)%ps.length;\n\t\t\t\t\t\tpts.add(ps[curL]);\n\t\t\t\t\t}\n\t\t\t\t\twhile(ps[curR].polyRemoveId == 0) {\n\t\t\t\t\t\tif(curL == curR) break;\n\t\t\t\t\t\tcurR = (curR + 1)%ps.length;\n\t\t\t\t\t\tpts.add(ps[curR]);\n\t\t\t\t\t}\n\t\t\t\t\tif(debug) System.out.println(\" PTS: \"+pts.toString());\n\t\t\t\t\tif(!started) {\n\t\t\t\t\t\taddArea = ps[curL].polyRemoveId == -1;\n\t\t\t\t\t\tstarted = true;\n\t\t\t\t\t}\n\t\t\t\t\tif(addArea) res += getArea(tsToArray(pts));\n\t\t\t\t\tpts.clear();\n\t\t\t\t\tif(curR == curL) break;\n\t\t\t\t\tpts.add(ps[curL]);\n\t\t\t\t\tpts.add(ps[curR]);\n\t\t\t\t\tcurL = (curL - 1 + ps.length)%ps.length;\n\t\t\t\t\tcurR = (curR + 1)%ps.length;\n\t\t\t\t\tpts.add(ps[curL]);\n\t\t\t\t\tpts.add(ps[curR]);\n\t\t\t\t\taddArea = !addArea;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn res;\n\t\t\t}\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(Poly o) {\n\t\t\tif(id == o.id) return 0;\n\t\t\tif(fSeg.inFrontOf(o.fSeg)) return -1;\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t}\n\tstatic Vec[] tsToArray(TreeSet tss){\n\t\tVec res[] = new Vec[tss.size()];\n\t\tint idd = 0;\n\t\tfor(Vec v : tss) res[idd++] = v;\n\t\treturn res;\n\t}\n\tstatic double getArea(Vec[] vs) {\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"AREA:\");\n\t\t\tfor(Vec v : vs) System.out.println(\" \"+v);\n\t\t}\n\t\tdouble res = 0;\n\t\tfor(int i = 0; i < vs.length; i++) {\n\t\t\tVec a = vs[i];\n\t\t\tVec b = vs[(i+1)%vs.length];\n\t\t\tres += (b.x - a.x) * ((b.y + a.y)/2.0); \n\t\t}\n\t\tif(debug)System.out.println(\" a=\"+Math.abs(res));\n\t\treturn Math.abs(res);\n\t}\n\t\n\tstatic boolean eq(double a, double b) {\n\t\treturn Math.abs(a-b) <= eps;\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() { br = new BufferedReader(new InputStreamReader(System.in));}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "05378dd3e6a22eb5ea27334a0680abd2", "src_uid": "f88b322137318b2fbae4f54a613b170c", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.NoSuchElementException;\n\npublic class C {\n\n private static final int NUM = 60;\n\n private int[] garbage = new int[NUM];\n private int garbageSize = 0;\n\n private boolean check(int[] living, int livingSize) {\n if (garbageSize > livingSize) {\n return false;\n }\n\n int extraGarbage = 0;\n for (int bit = 0; bit < NUM; bit++) {\n if (living[bit] < garbage[bit]) {\n extraGarbage += garbage[bit] - living[bit];\n } else {\n extraGarbage = Math.max(extraGarbage - (living[bit] - garbage[bit]), 0);\n }\n }\n\n return extraGarbage == 0;\n }\n\n private void garbageAdd(long g) {\n for (int i = 0; i < NUM; i++) {\n if (g <= (1L << i) * 2) {\n garbage[i]++;\n break;\n }\n }\n garbageSize++;\n }\n\n private void solve(FastScanner in, PrintWriter out) {\n int N = in.nextInt();\n long[] seq = in.nextLongArray(N);\n\n int[] count = new int[NUM];\n int target = 0;\n for (long s : seq) {\n if (s == (1 << target)) {\n count[target]++;\n } else if (s == (1 << (target + 1))) {\n target++;\n count[target]++;\n } else {\n garbageAdd(s);\n }\n }\n\n int[] living = new int[NUM];\n for (int i = 0; i < NUM; i++) {\n if (i == 0) {\n living[i] += count[i];\n continue;\n }\n\n int evol = Math.min(living[i - 1], count[i]);\n living[i - 1] -= evol;\n living[i] += evol;\n for (int j = 0; j < count[i] - evol; j++) {\n garbageAdd(1L << i);\n }\n }\n\n int livingSize = 0;\n for (int l : living) {\n livingSize += l;\n }\n\n ArrayList ans = new ArrayList<>();\n while (check(living, livingSize)) {\n ans.add(livingSize);\n livingSize--;\n if (livingSize == 0) {\n break;\n }\n for (int i = 0; i < NUM; i++) {\n if (living[i] == 0) {\n garbageAdd(1L << i);\n } else {\n garbageAdd(1L << i);\n living[i]--;\n break;\n }\n }\n }\n\n if (ans.isEmpty()) {\n out.println(-1);\n } else {\n Collections.sort(ans);\n for (int i = 0; i < ans.size(); i++) {\n if (i > 0) {\n out.print(\" \");\n }\n out.print(ans.get(i));\n }\n out.println();\n }\n\n }\n\n public static void main(String[] args) {\n PrintWriter out = new PrintWriter(System.out);\n new C().solve(new FastScanner(), out);\n out.close();\n }\n\n private static class FastScanner {\n\n private final InputStream in = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int bufferLength = 0;\n\n private boolean hasNextByte() {\n if (ptr < bufferLength) {\n return true;\n } else {\n ptr = 0;\n try {\n bufferLength = in.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (bufferLength <= 0) {\n return false;\n }\n }\n return true;\n }\n\n private int readByte() {\n if (hasNextByte()) {\n return buffer[ptr++];\n } else {\n return -1;\n }\n }\n\n private static boolean isPrintableChar(int c) {\n return 33 <= c && c <= 126;\n }\n\n private void skipUnprintable() {\n while (hasNextByte() && !isPrintableChar(buffer[ptr])) {\n ptr++;\n }\n }\n\n boolean hasNext() {\n skipUnprintable();\n return hasNextByte();\n }\n\n public String next() {\n if (!hasNext()) {\n throw new NoSuchElementException();\n }\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while (isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n long nextLong() {\n if (!hasNext()) {\n throw new NoSuchElementException();\n }\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while (true) {\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n } else if (b == -1 || !isPrintableChar(b)) {\n return minus ? -n : n;\n } else {\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n double[] nextDoubleArray(int n) {\n double[] array = new double[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextDouble();\n }\n return array;\n }\n\n double[][] nextDoubleMap(int n, int m) {\n double[][] map = new double[n][];\n for (int i = 0; i < n; i++) {\n map[i] = nextDoubleArray(m);\n }\n return map;\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextIntArray(int n) {\n int[] array = new int[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextInt();\n }\n return array;\n }\n\n public long[] nextLongArray(int n) {\n long[] array = new long[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextLong();\n }\n return array;\n }\n\n public String[] nextStringArray(int n) {\n String[] array = new String[n];\n for (int i = 0; i < n; i++) {\n array[i] = next();\n }\n return array;\n }\n\n public char[][] nextCharMap(int n) {\n char[][] array = new char[n][];\n for (int i = 0; i < n; i++) {\n array[i] = next().toCharArray();\n }\n return array;\n }\n\n public int[][] nextIntMap(int n, int m) {\n int[][] map = new int[n][];\n for (int i = 0; i < n; i++) {\n map[i] = nextIntArray(m);\n }\n return map;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b7d862bd1c9f32dcd70fa670e555d2f5", "src_uid": "fc29e8c1a9117c1dd307131d852b6088", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n FastScanner in;\n PrintWriter out;\n\n public void solve() throws IOException {\n int[] powCnt = new int[63];\n int[] other = new int[63];\n long[] pows = new long[63];\n pows[0] = 1L;\n for (int i = 1; i < 63; i++) {\n pows[i] = pows[i - 1] * 2;\n }\n \n int n = in.nextInt();\n long[] a = new long[n];\n \n for (int i = 0; i < n; i++) {\n a[i] = in.nextLong();\n boolean isPow = false;\n for (int j = 0; j < 63; j++) {\n if (a[i] == pows[j]) {\n powCnt[j]++;\n isPow = true;\n }\n if (!isPow && j != 0 && a[i] > pows[j - 1] && a[i] < pows[j]) {\n other[j]++;\n }\n }\n }\n \n int min = Arrays.stream(other).sum();\n int max = powCnt[0];\n boolean exists = false;\n for (int len = min; len <= max; len++) {\n int tails = 0;\n int cur = len;\n for (int i = 0; i < 62; i++) {\n tails += other[i + 1];\n int oldCur = cur;\n if (powCnt[i] < cur) {\n cur = powCnt[i];\n }\n int ended = oldCur - cur;\n if (tails < ended) {\n tails = 0;\n } else {\n tails -= ended;\n }\n tails += powCnt[i] - cur;\n }\n if (tails == 0) {\n out.print(len + \" \");\n exists = true;\n }\n }\n if (!exists) {\n out.println(-1);\n } else {\n out.println();\n }\n }\n\n public 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 long nextLong() {\n return Long.parseLong(next());\n }\n }\n\n public static void main(String[] arg) {\n new C().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1360ca1995fbe5eb5267ff5b5a7169c1", "src_uid": "fc29e8c1a9117c1dd307131d852b6088", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.NoSuchElementException;\n\npublic class C {\n\n private static final int NUM = 60;\n\n private int[] garbage = new int[NUM];\n private int garbageSize = 0;\n\n private boolean check(int[] living, int livingSize) {\n if (garbageSize > livingSize) {\n return false;\n }\n\n int livingCount = 0;\n int extraGarbage = 0;\n int garbageCount = garbageSize;\n for (int bit = 0; bit < NUM; bit++) {\n livingCount += living[bit];\n garbageSize -= garbage[bit];\n if (living[bit] < garbage[bit]) {\n extraGarbage += garbage[bit] - living[bit];\n } else {\n extraGarbage = Math.max(extraGarbage - (living[bit] - garbage[bit]), 0);\n }\n\n if (livingCount == livingSize) {\n return extraGarbage == 0 && garbageCount == 0;\n }\n }\n\n throw new IllegalStateException();\n }\n\n private void garbageAdd(long g) {\n for (int i = 0; i < NUM; i++) {\n if (g <= (1L << i) * 2) {\n garbage[i]++;\n break;\n }\n }\n garbageSize++;\n }\n\n private void solve(FastScanner in, PrintWriter out) {\n int N = in.nextInt();\n long[] seq = in.nextLongArray(N);\n\n int[] count = new int[NUM];\n int target = 0;\n for (long s : seq) {\n if (s == (1 << target)) {\n count[target]++;\n } else if (s == (1 << (target + 1))) {\n target++;\n count[target]++;\n } else {\n garbageAdd(s);\n }\n }\n\n int[] living = new int[NUM];\n for (int i = 0; i < NUM; i++) {\n if (i == 0) {\n living[i] += count[i];\n continue;\n }\n\n int evol = Math.min(living[i - 1], count[i]);\n living[i - 1] -= evol;\n living[i] += evol;\n for (int j = 0; j < count[i] - evol; j++) {\n garbageAdd(1L << i);\n }\n }\n\n int livingSize = 0;\n for (int l : living) {\n livingSize += l;\n }\n\n ArrayList ans = new ArrayList<>();\n while (check(living, livingSize)) {\n ans.add(livingSize);\n livingSize--;\n if (livingSize == 0) {\n break;\n }\n for (int i = 0; i < NUM; i++) {\n if (living[i] == 0) {\n garbageAdd(1L << i);\n } else {\n garbageAdd(1L << i);\n living[i]--;\n break;\n }\n }\n }\n\n if (ans.isEmpty()) {\n out.println(-1);\n } else {\n Collections.sort(ans);\n for (int i = 0; i < ans.size(); i++) {\n if (i > 0) {\n out.print(\" \");\n }\n out.print(ans.get(i));\n }\n out.println();\n }\n\n }\n\n public static void main(String[] args) {\n PrintWriter out = new PrintWriter(System.out);\n new C().solve(new FastScanner(), out);\n out.close();\n }\n\n private static class FastScanner {\n\n private final InputStream in = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int bufferLength = 0;\n\n private boolean hasNextByte() {\n if (ptr < bufferLength) {\n return true;\n } else {\n ptr = 0;\n try {\n bufferLength = in.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (bufferLength <= 0) {\n return false;\n }\n }\n return true;\n }\n\n private int readByte() {\n if (hasNextByte()) {\n return buffer[ptr++];\n } else {\n return -1;\n }\n }\n\n private static boolean isPrintableChar(int c) {\n return 33 <= c && c <= 126;\n }\n\n private void skipUnprintable() {\n while (hasNextByte() && !isPrintableChar(buffer[ptr])) {\n ptr++;\n }\n }\n\n boolean hasNext() {\n skipUnprintable();\n return hasNextByte();\n }\n\n public String next() {\n if (!hasNext()) {\n throw new NoSuchElementException();\n }\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while (isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n long nextLong() {\n if (!hasNext()) {\n throw new NoSuchElementException();\n }\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while (true) {\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n } else if (b == -1 || !isPrintableChar(b)) {\n return minus ? -n : n;\n } else {\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n double[] nextDoubleArray(int n) {\n double[] array = new double[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextDouble();\n }\n return array;\n }\n\n double[][] nextDoubleMap(int n, int m) {\n double[][] map = new double[n][];\n for (int i = 0; i < n; i++) {\n map[i] = nextDoubleArray(m);\n }\n return map;\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextIntArray(int n) {\n int[] array = new int[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextInt();\n }\n return array;\n }\n\n public long[] nextLongArray(int n) {\n long[] array = new long[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextLong();\n }\n return array;\n }\n\n public String[] nextStringArray(int n) {\n String[] array = new String[n];\n for (int i = 0; i < n; i++) {\n array[i] = next();\n }\n return array;\n }\n\n public char[][] nextCharMap(int n) {\n char[][] array = new char[n][];\n for (int i = 0; i < n; i++) {\n array[i] = next().toCharArray();\n }\n return array;\n }\n\n public int[][] nextIntMap(int n, int m) {\n int[][] map = new int[n][];\n for (int i = 0; i < n; i++) {\n map[i] = nextIntArray(m);\n }\n return map;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "91fb6532efbd5f4ad0c5f4077ccb8669", "src_uid": "fc29e8c1a9117c1dd307131d852b6088", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class C {\n FastScanner in;\n PrintWriter out;\n\n public void solve() throws IOException {\n int[] powCnt = new int[63];\n int[] other = new int[63];\n long[] pows = new long[63];\n pows[0] = 1L;\n for (int i = 1; i < 63; i++) {\n pows[i] = pows[i - 1] * 2;\n }\n \n int n = in.nextInt();\n long[] a = new long[n];\n \n for (int i = 0; i < n; i++) {\n a[i] = in.nextLong();\n boolean isPow = false;\n for (int j = 0; j < 63; j++) {\n if (a[i] == pows[j]) {\n powCnt[j]++;\n isPow = true;\n }\n if (!isPow && j != 0 && a[i] > pows[j - 1] && a[i] < pows[j]) {\n other[j]++;\n }\n }\n }\n \n int min = Arrays.stream(other).sum();\n int max = powCnt[0];\n boolean exists = false;\n for (int len = min; len <= max; len++) {\n int tails = 0;\n int cur = len;\n for (int i = 0; i < 63; i++) {\n tails += other[i + 1];\n int oldCur = cur;\n if (powCnt[i] < cur) {\n cur = powCnt[i];\n }\n int ended = oldCur - cur;\n if (tails < ended) {\n tails = 0;\n } else {\n tails -= ended;\n }\n tails += powCnt[i] - cur;\n }\n if (tails == 0) {\n out.print(len + \" \");\n exists = true;\n }\n }\n if (!exists) {\n out.println(-1);\n } else {\n out.println();\n }\n }\n\n public 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 long nextLong() {\n return Long.parseLong(next());\n }\n }\n\n public static void main(String[] arg) {\n new C().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "253557f72b984507735a20e7a97517de", "src_uid": "fc29e8c1a9117c1dd307131d852b6088", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[3001];\n for (int i = 1; i < factLog.length; i++) {\n factLog[i] = Math.log(i) + factLog[i - 1];\n }\n for (int i = 0; i < V; i++) {\n int[] K = new int[250];\n long sum = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n sum += K[j];\n }\n double P = sum * 1.0 / K.length;\n double uniform = -Math.log(2 * P + 1) * K.length;\n double poisson = 0;\n for (int j = 0; j < K.length; j++) {\n poisson += K[j] * Math.log(P) - P * logE - factLog[K[j]];\n }\n// System.err.println(uniform + \" \" + poisson);\n int bestI = 0;\n if (uniform < poisson) {\n double bestLikelyhood = -Double.MAX_VALUE;\n for (int j = Math.max(10, (int) P - 10); j <= (int) P + 10; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += K[k] * Math.log(j) - j * logE;\n }\n if (likelyhood > bestLikelyhood) {\n bestLikelyhood = likelyhood;\n bestI = j;\n }\n }\n } else {\n int max = 0;\n for (int j = 0; j < K.length; j++) {\n max = Math.max(max, K[j]);\n }\n bestI = max / 2 + 1;\n }\n System.out.println(bestI);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "11381ce61ad9615a8800731c8a766ac9", "src_uid": "18bf2c587415f85df83fb090e16b8351", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[3001];\n for (int i = 1; i < factLog.length; i++) {\n factLog[i] = Math.log(i) + factLog[i - 1];\n }\n for (int i = 0; i < V; i++) {\n int[] K = new int[250];\n long sum = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n sum += K[j];\n }\n double P = sum * 1.0 / K.length;\n double uniform = -Math.log(2 * P + 1) * K.length;\n double poisson = 0;\n for (int j = 0; j < K.length; j++) {\n poisson += K[j] * Math.log(P) - P * logE - factLog[K[j]];\n }\n// System.err.println(uniform + \" \" + poisson);\n int bestI = 0;\n if (uniform < poisson) {\n double bestLikelyhood = -Double.MAX_VALUE;\n for (int j = Math.max(10, (int) P - 10); j <= (int) P + 10; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += K[k] * Math.log(j) - j * logE;\n }\n if (likelyhood > bestLikelyhood) {\n bestLikelyhood = likelyhood;\n bestI = j;\n }\n }\n } else {\n long sum2 = 0;\n for (int j = 0; j < K.length; j++) {\n sum2 += K[j] * K[j];\n }\n bestI = (int)(Math.sqrt(12.0 * (1.0 * sum2 / K.length - Math.pow(1.0 * sum / K.length, 2))) + 0.5);\n }\n System.out.println(bestI);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f41f971010b55b32eff8415ff09ef33", "src_uid": "18bf2c587415f85df83fb090e16b8351", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[3001];\n for (int i = 1; i < factLog.length; i++) {\n factLog[i] = Math.log(i) + factLog[i - 1];\n }\n for (int i = 0; i < V; i++) {\n int[] K = new int[10];\n long sum = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n sum += K[j];\n }\n double P = sum * 1.0 / K.length;\n double uniform = -Math.log(2 * P + 1) * K.length;\n double poisson = 0;\n for (int j = 0; j < K.length; j++) {\n poisson += K[j] * Math.log(P) - P * logE - factLog[K[j]];\n }\n// System.err.println(uniform + \" \" + poisson);\n double bestLikelyhood = -Double.MAX_VALUE;\n int bestI = 0;\n if (uniform < poisson) {\n for (int j = Math.max(10, (int) P - 10); j <= (int) P + 10; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += K[k] * Math.log(j) - j * logE - factLog[K[k]];\n }\n if (likelyhood > bestLikelyhood) {\n bestLikelyhood = likelyhood;\n bestI = j;\n }\n }\n } else {\n bestI = (int)(P + 0.5);\n }\n System.out.println(bestI);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fcdfd2a942c6d59c3bcc6cb2ae46a4fe", "src_uid": "18bf2c587415f85df83fb090e16b8351", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class D {\n static Scanner sc = new Scanner(System.in);\n\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[3001];\n for (int i = 1; i < factLog.length; i++) {\n factLog[i] = Math.log(i) + factLog[i - 1];\n }\n for (int i = 0; i < V; i++) {\n int[] K = new int[250];\n long sum = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n sum += K[j];\n }\n double P = sum * 1.0 / K.length;\n System.out.println((int)P);\n// double uniform = -Math.log(2 * P + 1) * K.length;\n// double poisson = 0;\n// for (int j = 0; j < K.length; j++) {\n// poisson += K[j] * Math.log(P) - P * Math.log(Math.E) - factLog[K[j]];\n// }\n//// System.err.println(uniform + \" \" + poisson);\n// System.out.println(uniform < poisson ? \"poisson\" : \"uniform\");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6b58769577580cc3564e631da8e92ad3", "src_uid": "18bf2c587415f85df83fb090e16b8351", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\npublic class E{\n public static void main(String args[]) throws Exception{\n int magic=51;\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(in.readLine());\n String s[]=in.readLine().split(\" \");\n int[]a=new int[n];\n a[0]=1;\n for(int i=1;i=0){\n f[rw][x]+=f[rw][x-a[i]];;\n if(f[rw][x]>=mod)f[rw][x]-=mod;\n }\n }\n rw^=1;\n for(int x=0;x<=nxt;x++){\n f[rw][x]=0;\n long from=1l*a[i]*x+c[i];\n long at=from;\n long m=0;\n if(from>bef){\n m=(from-bef+a[i]-1)/a[i];\n at=from-m*a[i];\n }\n if(m<=b[i] && at>=0){\n long inc=f[rw^1][(int)at];\n long old=at;\n at=from-1l*a[i]*(b[i]+1);\n if(at>=0)inc-=f[rw^1][(int)at];\n inc=(inc%mod+mod)%mod;\n f[rw][x]=inc; \n }\n } \n bef=nxt;\n }\n \n if(M.compareTo(new BigInteger(\"\"+bef))>0)System.out.println(\"0\");\n else System.out.println(f[rw][(int)M.longValue()]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eeb8174fb22b7994c648606378770c55", "src_uid": "71b23bc529ee1484d9dcea84def45d53", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\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 P = 1_000_000_007;\n\t\n\tint[] update(int[] dp, int cnt) {\n\t\tint[] ret = new int[dp.length + cnt];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < ret.length; i++) {\n\t\t\tif (i < dp.length) {\n\t\t\t\tsum += dp[i];\n\t\t\t\tif (sum >= P) {\n\t\t\t\t\tsum -= P;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret[i] = sum;\n\t\t\tif (i >= cnt) {\n\t\t\t\tsum -= dp[i - cnt];\n\t\t\t\tif (sum < 0) {\n\t\t\t\t\tsum += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n - 1];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\n\t\tint[] b = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t}\n\n\t\tint[] dp = { 1 };\n\t\t\n\t\tBigInteger big = new BigInteger(nextToken());\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdp = update(dp, b[i]);\n\t\t\t\n\t\t\tif (i == n - 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (a[i] == 1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tBigInteger[] tmp = big.divideAndRemainder(BigInteger.valueOf(a[i]));\n\t\t\t\n\t\t\tint rem = tmp[1].intValue();\n\t\t\t\n\t\t\tif (rem >= dp.length) {\n\t\t\t\tout.println(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tint newLen = (dp.length - 1 - rem) / a[i] + 1;\n\t\t\tint[] newDp = new int[newLen];\n\t\t\t\n\t\t\tfor (int ii = rem, j = 0; j < newLen; ii += a[i], j++) {\n\t\t\t\tnewDp[j] = dp[ii];\n\t\t\t}\n\t\t\t\n\t\t\tbig = tmp[0];\n\t\t\tdp = newDp;\n\t\t}\n\t\t\n\t\tif (big.compareTo(BigInteger.valueOf(dp.length)) < 0) {\n\t\t\tout.println(dp[big.intValue()]);\n\t\t} else {\n\t\t\tout.println(0);\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "296639559ab8d4f4b013ac334a572ad4", "src_uid": "71b23bc529ee1484d9dcea84def45d53", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\npublic class E{\n public static void main(String args[]) throws Exception{\n int magic=51;\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(in.readLine());\n String s[]=in.readLine().split(\" \");\n int[]a=new int[n];\n a[0]=1;\n for(int i=1;i=0){\n f[rw][x]+=f[rw][x-a[i]];;\n if(f[rw][x]>=mod)f[rw][x]-=mod;\n }\n }\n rw^=1;\n for(int x=0;x<=nxt;x++){\n f[rw][x]=0;\n long from=1l*a[i]*x+c[i];\n long at=from;\n long m=0;\n if(from>bef){\n m=(from-bef+a[i]-1)/a[i];\n at=from-m*a[i];\n }\n if(m<=b[i] && at>=0){\n long inc=f[rw^1][(int)at];\n long old=at;\n at=from-1l*a[i]*(b[i]+1);\n if(at>=0)inc-=f[rw^1][(int)at];\n inc=(inc%mod+mod)%mod;\n f[rw][x]=inc; \n }\n } \n bef=nxt;\n }\n \n if(M.compareTo(new BigInteger(\"\"+bef))>0)System.out.println(\"0\");\n else System.out.println(f[rw][(int)M.longValue()]);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "699377b2d59513483e3684150a7ecf32", "src_uid": "71b23bc529ee1484d9dcea84def45d53", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\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 P = 1_000_000_007;\n\t\n\tint[] update(int[] dp, int cnt) {\n\t\tint[] ret = new int[dp.length + cnt];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < ret.length; i++) {\n\t\t\tif (i < dp.length) {\n\t\t\t\tsum += dp[i];\n\t\t\t\tif (sum >= P) {\n\t\t\t\t\tsum -= P;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i >= cnt) {\n\t\t\t\tsum -= dp[i - cnt];\n\t\t\t\tif (sum < 0) {\n\t\t\t\t\tsum += P;\n\t\t\t\t}\n\t\t\t}\n\t\t\tret[i] = sum;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n - 1];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\n\t\tint[] b = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t}\n\n\t\tint[] dp = { 1 };\n\t\t\n\t\tBigInteger big = new BigInteger(nextToken());\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdp = update(dp, b[i]);\n\t\t\t\n\t\t\tif (i == n - 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (a[i] == 1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tBigInteger[] tmp = big.divideAndRemainder(BigInteger.valueOf(a[i]));\n\t\t\t\n\t\t\tint rem = tmp[1].intValue();\n\t\t\t\n\t\t\tif (rem >= dp.length) {\n\t\t\t\tout.println(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tint newLen = (dp.length - 1 - rem) / a[i] + 1;\n\t\t\tint[] newDp = new int[newLen];\n\t\t\t\n\t\t\tfor (int ii = rem, j = 0; j < newLen; ii += a[i], j++) {\n\t\t\t\tnewDp[j] = dp[ii];\n\t\t\t}\n\t\t\t\n\t\t\tbig = tmp[0];\n\t\t\tdp = newDp;\n\t\t}\n\t\t\n\t\tif (big.compareTo(BigInteger.valueOf(dp.length)) < 0) {\n\t\t\tout.println(dp[big.intValue()]);\n\t\t} else {\n\t\t\tout.println(0);\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c24faefb1750d073337dd89915b58e67", "src_uid": "71b23bc529ee1484d9dcea84def45d53", "difficulty": 3200.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\npublic class E {\n\n\n static int find(fenwik_tree t, int y, int lo, int hi) {\n while(lo<=hi) {\n int mid=(lo+hi)>>1;\n long cnt=t.query(0, mid);\n\n if(cnt0&&out[k]!=x) {\n System.out.println(\"-1\");\n return;\n } else {\n out[k]=x;\n }\n t.update(j,-1); i2c[j]=-1; \n t.update(m-i,1); i2c[m-i]=k;\n }\n \n boolean[] b=new boolean[n+1]; int j=1;\n for (int i=1; i<=n; i++) {\n if(out[i]!=0) {\n if(b[out[i]]) {\n System.out.println(\"-1\");\n return;\n }\n b[out[i]]=true;\n }\n }\n \n for (int i=1; i<=n; i++) {\n if(out[i]==0) {\n while(b[j]) {\n j++;\n }\n out[i]=j;\n }\n b[out[i]]=true;\n }\n \n StringBuilder sb=new StringBuilder();\n for (int i=1; i<=n; i++) {\n sb.append(out[i]+\" \");\n }\n System.out.println(sb.toString());\n }\n\n public static void main(String[] args) throws IOException {\n run_stream(System.in);\n }\n\n \n static class fenwik_tree {\n int n;\n long[] fadd;\n \n fenwik_tree(int n) {\n this.n=n; fadd=new long[n];\n }\n \n void update(int i, long add) {\n while (i=0) {\n ret+=fadd[i];\n i=(i&(i+1))-1;\n }\n return ret;\n }\n \n long query(int l, int r) {\n return query(r)-query(l-1);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "437bcfd5e107b0aa6119178b3f7184e4", "src_uid": "a2616b1681f30ce4b2a5fdc81cf52b50", "difficulty": 2200.0} {"lang": "Java 8", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f1d89c4db01bbc717856948de32b667a", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\npublic class E1113 \n{\n static class QN{\n int index;\n long sum;\n QN(int in,long an){\n index=in;\n sum=an;\n }\n }\n static class SegmentTree{\n long sum,pmin,lazy;\n int st,en;\n boolean rem;\n SegmentTree left,right;\n SegmentTree(int _st,int _en,long _v){\n st=_st;\n en=_en;\n lazy=_v;\n rem=true;\n sum=(en-st+1)*lazy;\n pmin=Math.min(lazy,sum);\n }\n long pmin(){\n return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);\n }\n long sum(){\n return rem?((en-st+1)*lazy):(sum);\n }\n void update(int l,int r,long v){\n //completely outside\n if(l>en||r=en){\n //update lazy;\n lazy=v;\n rem=true;\n return;\n }\n //partial cover\n lazyPropagate();\n left.update(l, r, v);\n right.update(l, r, v);\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n return;\n }\n void lazyPropagate(){\n if(left==null){\n int mid=(st+en)>>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 mp=new TreeMap<>();\n mp.put(0,0);\n mp.put(1000000001,0);\n while(q--!=0){\n int tp=in.nextInt();\n switch(tp){\n case 1:\n int tm=in.nextInt();\n int vl=in.nextInt();\n int nxt=mp.higherKey(tm)-1;\n st.update(tm, nxt, vl);\n mp.put(tm,vl);\n break;\n case 2:\n int tc=in.nextInt();\n int vp=mp.lowerEntry(tc).getValue();\n int net=mp.higherKey(tc)-1;\n st.update(tc, net, vp);\n mp.remove(tc);\n break;\n case 3:\n int l=in.nextInt();\n int lc=l;\n l=mp.ceilingKey(l);\n int r=in.nextInt();\n int v=in.nextInt();\n if(v==0){\n out.println(lc);\n continue;\n }\n if(l>=r){\n out.println(-1);\n continue;\n }\n QN aa=st.query(l, r-1, -v, 0);\n if(aa.index==-1)\n out.println(-1);\n else{\n int spd=mp.floorEntry(aa.index).getValue();\n double remv=-(v+(aa.sum-spd));\n double anss=aa.index;\n anss+=remv/spd;\n out.println(anss);\n \n }\n \n }\n \n }\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ec57d1a5a86b01b1db630c69431f513", "src_uid": "23440d055baf6c831e91e76b99b9ada8", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\npublic class E1113 \n{\n static class QN{\n int index;\n long sum;\n QN(int in,long an){\n index=in;\n sum=an;\n }\n }\n static class SegmentTree{\n long sum,pmin,lazy;\n int st,en;\n boolean rem;\n SegmentTree left,right;\n SegmentTree(int _st,int _en,long _v){\n st=_st;\n en=_en;\n lazy=_v;\n rem=true;\n sum=(en-st+1)*lazy;\n pmin=Math.min(lazy,sum);\n }\n long pmin(){\n return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);\n }\n long sum(){\n return rem?((en-st+1)*lazy):(sum);\n }\n void update(int l,int r,long v){\n //completely outside\n if(l>en||r=en){\n //update lazy;\n lazy=v;\n rem=true;\n return;\n }\n //partial cover\n lazyPropagate();\n left.update(l, r, v);\n right.update(l, r, v);\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n return;\n }\n void lazyPropagate(){\n if(left==null){\n int mid=(st+en)/2;\n left=new SegmentTree(st,mid,lazy);\n right=new SegmentTree(mid+1,en,lazy);\n }else if(rem){\n left.lazy=lazy;\n right.lazy=lazy;\n left.rem=true;\n right.rem=true;\n }\n if(rem){\n sum=(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 mp=new TreeMap<>();\n mp.put(0,0);\n mp.put(1000000001,0);\n while(q--!=0){\n int tp=in.nextInt();\n switch(tp){\n case 1:\n int tm=in.nextInt();\n int vl=in.nextInt();\n int nxt=mp.higherKey(tm)-1;\n st.update(tm, nxt, vl);\n mp.put(tm,vl);\n break;\n case 2:\n int tc=in.nextInt();\n int vp=mp.lowerEntry(tc).getValue();\n int net=mp.higherKey(tc)-1;\n st.update(tc, net, vp);\n mp.remove(tc);\n break;\n case 3:\n int l=in.nextInt();\n int lc=l;\n l=mp.ceilingKey(l);\n int r=in.nextInt();\n int v=in.nextInt();\n if(v==0){\n out.println(lc);\n continue;\n }\n if(l>=r){\n out.println(-1);\n continue;\n }\n QN aa=st.query(l, r-1, -v, 0);\n if(aa.index==-1)\n out.println(-1);\n else{\n int spd=mp.floorEntry(aa.index).getValue();\n double remv=-(v+(aa.sum-spd));\n double anss=aa.index;\n anss+=remv/spd;\n out.println(anss);\n \n }\n \n }\n \n }\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8fbb9cb1b1d5545e1dbe585f20337be8", "src_uid": "23440d055baf6c831e91e76b99b9ada8", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\npublic class E1113 \n{\n static class QN{\n int index;\n long sum;\n QN(int in,long an){\n index=in;\n sum=an;\n }\n }\n static class SegmentTree{\n long sum,pmin,lazy;\n int st,en;\n boolean rem;\n SegmentTree left,right;\n SegmentTree(int _st,int _en,long _v){\n st=_st;\n en=_en;\n lazy=_v;\n rem=true;\n sum=(en-st+1)*lazy;\n pmin=Math.min(lazy,sum);\n }\n long pmin(){\n return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);\n }\n long sum(){\n return rem?((en-st+1)*lazy):(sum);\n }\n void update(int l,int r,long v){\n //completely outside\n if(l>en||r=en){\n //update lazy;\n lazy=v;\n rem=true;\n return;\n }\n //partial cover\n lazyPropagate();\n left.update(l, r, v);\n right.update(l, r, v);\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n return;\n }\n void lazyPropagate(){\n if(left==null){\n int mid=(st+en)/2;\n left=new SegmentTree(st,mid,lazy);\n right=new SegmentTree(mid+1,en,lazy);\n }else if(rem){\n left.lazy=lazy;\n right.lazy=lazy;\n left.rem=true;\n right.rem=true;\n }\n if(rem){\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n }\n rem=false;\n }\n /**returns least index which has value <= given value**/\n QN query(int l,int r,long v,long su){\n //no cover\n if(st>r||en mp=new TreeMap<>();\n mp.put(0,0);\n mp.put(1000000001,0);\n while(q--!=0){\n int tp=in.nextInt();\n switch(tp){\n case 1:\n int tm=in.nextInt();\n int vl=in.nextInt();\n int nxt=mp.higherKey(tm)-1;\n st.update(tm, nxt, vl);\n mp.put(tm,vl);\n break;\n case 2:\n int tc=in.nextInt();\n int vp=mp.lowerEntry(tc).getValue();\n int net=mp.higherKey(tc)-1;\n st.update(tc, net, vp);\n mp.remove(tc);\n break;\n case 3:\n int l=in.nextInt();\n int lc=l;\n l=mp.ceilingKey(l);\n int r=in.nextInt();\n int v=in.nextInt();\n if(v==0){\n out.println(lc);\n continue;\n }\n if(l>=r){\n out.println(-1);\n continue;\n }\n QN aa=st.query(l, r-1, -v, 0);\n if(aa.index==-1)\n out.println(-1);\n else{\n int spd=mp.floorEntry(aa.index).getValue();\n double remv=-(v+(aa.sum-spd));\n double anss=aa.index;\n anss+=remv/spd;\n out.println(anss);\n \n }\n \n }\n \n }\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24d5e67349c9f52ad1139f3886028ebd", "src_uid": "23440d055baf6c831e91e76b99b9ada8", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\npublic class E1113 \n{\n static class QN{\n int index;\n long sum;\n QN(int in,long an){\n index=in;\n sum=an;\n }\n }\n static class SegmentTree{\n long sum,pmin,lazy;\n int st,en;\n boolean rem;\n SegmentTree left,right;\n SegmentTree(int _st,int _en,long _v){\n st=_st;\n en=_en;\n lazy=_v;\n rem=true;\n sum=(en-st+1)*lazy;\n pmin=Math.min(lazy,sum);\n }\n long pmin(){\n return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);\n }\n long sum(){\n return rem?((en-st+1)*lazy):(sum);\n }\n void update(int l,int r,long v){\n //completely outside\n if(l>en||r=en){\n //update lazy;\n lazy=v;\n rem=true;\n return;\n }\n //partial cover\n lazyPropagate();\n left.update(l, r, v);\n right.update(l, r, v);\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n return;\n }\n void lazyPropagate(){\n if(left==null){\n int mid=(st+en)/2;\n left=new SegmentTree(st,mid,lazy);\n right=new SegmentTree(mid+1,en,lazy);\n }else if(rem){\n left.lazy=lazy;\n right.lazy=lazy;\n left.rem=true;\n right.rem=true;\n }\n rem=false;\n }\n /**returns least index which has value <= given value**/\n QN query(int l,int r,int v,long su){\n //no cover\n if(st>r||en mp=new TreeMap<>();\n mp.put(0,0);\n mp.put(1000000001,0);\n while(q--!=0){\n int tp=in.nextInt();\n switch(tp){\n case 1:\n int tm=in.nextInt();\n int vl=in.nextInt();\n int nxt=mp.higherKey(tm)-1;\n st.update(tm, nxt, vl);\n mp.put(tm,vl);\n break;\n case 2:\n int tc=in.nextInt();\n int vp=mp.lowerEntry(tc).getValue();\n int net=mp.higherKey(tc)-1;\n st.update(tc, net, vp);\n mp.remove(tc);\n break;\n case 3:\n int l=in.nextInt();\n int r=in.nextInt();\n int v=in.nextInt();\n if(v==0){\n out.println(l);\n continue;\n }\n if(l==r){\n out.println(-1);\n continue;\n }\n QN aa=st.query(l, r-1, -v, 0);\n if(aa.index==-1)\n out.println(-1);\n else{\n int spd=mp.floorEntry(aa.index).getValue();\n double remv=-(v+(aa.sum-spd));\n double anss=aa.index;\n anss+=remv/spd;\n out.println(anss);\n \n }\n \n }\n \n }\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c65ade31e02bc9c356acbf401da79772", "src_uid": "23440d055baf6c831e91e76b99b9ada8", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class E {\n\tstatic long mod = 1000000009;\n\tstatic long[][] ways = new long[1001][1001];\n\tstatic int k;\n\n\tpublic static long getTotal(String x) {\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i < x.length(); i++)\n\t\t\tans = (10 * ans + x.charAt(i) - '0') % mod;\n\t\treturn ans;\n\t}\n\n\tpublic static long get(String x, int index, int cantPut47) {\n\t\tif (index == x.length())\n\t\t\treturn 1;\n\t\tint maxDigit = x.charAt(index) - '0';\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i <= maxDigit; i++) {\n\t\t\tif ((i == 4 || i == 7) && cantPut47 > 0)\n\t\t\t\tcontinue;\n\t\t\tif (i == 4 || i == 7)\n\t\t\t\tif (i < maxDigit)\n\t\t\t\t\tans = (ans + ways[x.length() - index - 1][k]) % mod;\n\t\t\t\telse\n\t\t\t\t\tans = (ans + get(x, index + 1, k)) % mod;\n\t\t\telse if (i < maxDigit)\n\t\t\t\tans = (ans + ways[x.length() - index - 1][Math.max(\n\t\t\t\t\t\tcantPut47 - 1, 0)]) % mod;\n\t\t\telse\n\t\t\t\tans = (ans + get(x, index + 1, Math.max(cantPut47 - 1, 0)))\n\t\t\t\t\t\t% mod;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] S = in.readLine().split(\" \");\n\t\tint t = Integer.parseInt(S[0]);\n\t\tk = Integer.parseInt(S[1]);\n\t\tfor (int i = 0; i < 1001; i++)\n\t\t\tways[0][i] = 1;\n\t\tfor (int i = 1; i < 1001; i++)\n\t\t\tfor (int j = 0; j < 1001; j++)\n\t\t\t\tif (j == 0)\n\t\t\t\t\tways[i][j] = (8 * ways[i - 1][0] + 2 * ways[i - 1][k])\n\t\t\t\t\t\t\t% mod;\n\t\t\t\telse\n\t\t\t\t\tways[i][j] = (8 * ways[i - 1][j - 1]) % mod;\n\t\tfor (int i = 0; i < t; i++) {\n\t\t\tS = in.readLine().split(\" \");\n\t\t\tString left = \"\" + (new BigInteger(S[0]).subtract(BigInteger.ONE));\n\t\t\tString right = S[1];\n\t\t\tlong tot = (getTotal(right) - getTotal(left) + mod) % mod;\n\t\t\tlong bad = (get(right, 0, 0) - get(left, 0, 0) + mod) % mod;\n\t\t\tlong ans = (tot - bad + mod) % mod;\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "91e5703a803fcb0fdb9b5ae09cf6f4da", "src_uid": "5517efa2fc9362fdf342d32adac889f4", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "44a37898c38016d07e8b3044c7da0895", "src_uid": "67e599530203060c17f692f2624d0f99", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces913F {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tinput.close();\n\t\tfinal int mod = 998244353;\n\t\t\n\t\tint frac = multiply(a, inverse(b, mod), mod);\n\t\tint reverse = (mod+1-frac)%mod;\n\t\t\n\t\tint[] fracpower = new int[n+1];\n\t\tint[] reversepower = new int[n+1];\n\t\tfracpower[0] = 1;\n\t\treversepower[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfracpower[i] = multiply(fracpower[i-1], frac, mod);\n\t\t\treversepower[i] = multiply(reversepower[i-1], reverse, mod);\n\t\t}\n\t\t\n\t\tint[][] dp1 = new int[n+1][n+1];\n\t\tdp1[2][1] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tif (j == 1) {\n\t\t\t\t\tdp1[i][j] = fracpower[i-1];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);\n\t\t\t\t}\n\t\t\t\tif (j == i-1) {\n\t\t\t\t\tdp1[i][j] += reversepower[i-1];\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dp2 = new int[n+1][n+1];\n\t\tdp2[1][1] = 1;\n\t\tdp2[2][1] = 1;\n\t\tdp2[2][2] = 0;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tdp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);\n\t\t\t\tval += dp2[i][j];\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tdp2[i][i] = (mod+1-val)%mod;\n\t\t}\n\t\t\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tSystem.out.print(dp2[i][j] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t\t\n\t\tint[] EV = new int[n+1];\n\t\tEV[1] = 0;\n\t\tEV[2] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tint r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];\n\t\t\t\tr %= mod;\n\t\t\t\tval += multiply(dp2[i][j], r, mod);\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tval += multiply((i*(i-1))/2, dp2[i][i], mod);\n\t\t\tval %= mod;\n\t\t\t\n\t\t\tint s = (mod+1-dp2[i][i])%mod;\n\t\t\tEV[i] = multiply(val, inverse(s, mod), mod);\n\t\t}\n\t\t\n\t\tSystem.out.println(EV[n]);\n\t}\n\t\n\tpublic static int multiply(int a, int b, int mod) {\n\t\tlong x = (long)a*(long)b;\n\t\treturn (int) (x%mod);\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b6e2ce9e5982b68a8f5578e32bf30b5b", "src_uid": "67e599530203060c17f692f2624d0f99", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * @author Don Li\n */\npublic class Pollywog {\n \n long INF = (long) 2e18;\n \n void solve() {\n int x = in.nextInt(), k = in.nextInt(), n = in.nextInt(), q = in.nextInt();\n int[] c = new int[k + 1];\n for (int i = 1; i <= k; i++) c[i] = in.nextInt();\n \n int[][] stones = new int[q + 1][2];\n for (int i = 0; i < q; i++) {\n int p = in.nextInt() - 1, w = in.nextInt();\n stones[i][0] = p;\n stones[i][1] = w;\n }\n stones[q][0] = n; stones[q][1] = 0;\n Arrays.sort(stones, Comparator.comparingInt(a -> a[0]));\n \n int id = 0;\n int[] state_to_id = new int[1 << k];\n int[] id_to_state = new int[1 << k];\n for (int i = 0; i < 1 << k; i++) {\n if (Integer.bitCount(i) == x) {\n id_to_state[id] = i;\n state_to_id[i] = id;\n id++;\n }\n }\n \n long[][][] basepow = new long[60][id][id];\n fill(basepow, INF);\n for (int i = 0; i < id; i++) {\n int state = id_to_state[i];\n if ((state & 1 << (k - 1)) == 0) {\n basepow[0][i][state_to_id[state << 1]] = 0;\n continue;\n }\n for (int j = 1; j <= k; j++) {\n int nstate = state ^ 1 << (k - 1);\n nstate <<= 1;\n if ((nstate & 1 << (k - j)) > 0) continue; // skip when this position is occupied\n basepow[0][i][state_to_id[nstate | 1 << (k - j)]] = c[j];\n }\n }\n for (int level = 1; level < basepow.length; level++) {\n basepow[level] = mult(basepow[level - 1], basepow[level - 1]);\n }\n \n long[][] cost = new long[id][id];\n fill(cost, INF);\n int start = (1 << k) - (1 << (k - x));\n cost[state_to_id[start]][state_to_id[start]] = 0;\n \n int cpos = 0, sidx = 0;\n while (cpos < n - x) {\n while (cpos > stones[sidx][0]) sidx++;\n \n if (cpos + k >= stones[sidx][0]) {\n long[][] base = new long[id][id];\n fill(base, INF);\n for (int i = 0; i < id; i++) {\n int state = id_to_state[i];\n if ((state & 1 << (k - 1)) == 0) {\n base[i][state_to_id[state << 1]] = 0;\n continue;\n }\n for (int j = 1; j <= k; j++) {\n int nstate = state ^ 1 << (k - 1);\n nstate <<= 1;\n if ((nstate & 1 << (k - j)) > 0) continue;\n int tcost = c[j];\n for (int a = 0; a < 2*k; a++) {\n if (sidx + a < stones.length && cpos + j == stones[sidx + a][0]) {\n tcost += stones[sidx + a][1];\n }\n }\n base[i][state_to_id[nstate | 1 << (k - j)]] = tcost;\n }\n }\n cost = mult(cost, base);\n cpos++;\n } else {\n long dist = (stones[sidx][0] - k) - cpos;\n for (int i = 0; i < 60; i++) {\n if ((dist & (1L << i)) > 0) {\n cost = mult(cost, basepow[i]);\n }\n }\n cpos += dist;\n }\n }\n \n out.println(cost[state_to_id[start]][state_to_id[start]]);\n }\n \n long[][] mult(long[][] a, long[][] b) {\n int n = a.length;\n long[][] c = new long[n][n];\n fill(c, INF);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n c[i][j] = Math.min(c[i][j], a[i][k] + b[k][j]);\n }\n }\n }\n return c;\n }\n \n void fill(long[][][] a, long val) {\n for (long[][] x : a) fill(x, val);\n }\n \n void fill(long[][] a, long val) {\n for (long[] x : a) Arrays.fill(x, val);\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 Pollywog().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3e4f6138b15f6ce8cc4f38d58e4119ff", "src_uid": "e3dd409ceeba2a21890d35ceab9607eb", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * @author Don Li\n */\npublic class Pollywog {\n \n long INF = (long) 2e18;\n \n void solve() {\n int x = in.nextInt(), k = in.nextInt(), n = in.nextInt(), q = in.nextInt();\n int[] c = new int[k + 1];\n for (int i = 1; i <= k; i++) c[i] = in.nextInt();\n \n int[][] stones = new int[q + 1][2];\n for (int i = 0; i < q; i++) {\n int p = in.nextInt() - 1, w = in.nextInt();\n stones[i][0] = p;\n stones[i][1] = w;\n }\n stones[q][0] = n; stones[q][1] = 0;\n Arrays.sort(stones, Comparator.comparingInt(a -> a[0]));\n \n int id = 0;\n int[] state_to_id = new int[1 << k];\n int[] id_to_state = new int[1 << k];\n for (int i = 0; i < 1 << k; i++) {\n if (Integer.bitCount(i) == x) {\n id_to_state[id] = i;\n state_to_id[i] = id;\n id++;\n }\n }\n \n long[][][] basepow = new long[60][id][id];\n fill(basepow, INF);\n for (int i = 0; i < id; i++) {\n int state = id_to_state[i];\n if ((state & 1 << (k - 1)) == 0) {\n basepow[0][i][state_to_id[state << 1]] = 0;\n continue;\n }\n for (int j = 1; j <= k; j++) {\n int nstate = state ^ 1 << (k - 1);\n nstate <<= 1;\n if ((nstate & 1 << (k - j)) > 0) continue; // skip when this position is occupied\n basepow[0][i][state_to_id[nstate | 1 << (k - j)]] = c[j];\n }\n }\n for (int level = 1; level < basepow.length; level++) {\n basepow[level] = mult(basepow[level - 1], basepow[level - 1]);\n }\n \n long[][] cost = new long[id][id];\n fill(cost, INF);\n int start = (1 << k) - (1 << (k - x));\n cost[state_to_id[start]][state_to_id[start]] = 0;\n \n int cpos = 0, sidx = 0;\n while (cpos < n - x) {\n while (cpos > stones[sidx][0]) sidx++;\n \n if (cpos + k >= stones[sidx][0]) {\n long[][] base = new long[id][id];\n fill(base, INF);\n for (int i = 0; i < id; i++) {\n int state = id_to_state[i];\n if ((state & 1 << (k - 1)) == 0) {\n base[i][state_to_id[state << 1]] = 0;\n continue;\n }\n for (int j = 1; j <= k; j++) {\n int nstate = state ^ 1 << (k - 1);\n nstate <<= 1;\n if ((nstate & 1 << (k - j)) > 0) continue;\n int tcost = c[j];\n for (int a = 0; a < k; a++) {\n if (sidx + a < stones.length && cpos + j == stones[sidx + a][0]) {\n tcost += stones[sidx + a][1];\n }\n }\n base[i][state_to_id[nstate | 1 << (k - j)]] = tcost;\n }\n }\n cost = mult(cost, base);\n cpos++;\n } else {\n long dist = (stones[sidx][0] - k) - cpos;\n for (int i = 0; i < 60; i++) {\n if ((dist & (1L << i)) > 0) {\n cost = mult(cost, basepow[i]);\n }\n }\n cpos += dist;\n }\n }\n \n out.println(cost[state_to_id[start]][state_to_id[start]]);\n }\n \n long[][] mult(long[][] a, long[][] b) {\n int n = a.length;\n long[][] c = new long[n][n];\n fill(c, INF);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n c[i][j] = Math.min(c[i][j], a[i][k] + b[k][j]);\n }\n }\n }\n return c;\n }\n \n void fill(long[][][] a, long val) {\n for (long[][] x : a) fill(x, val);\n }\n \n void fill(long[][] a, long val) {\n for (long[] x : a) Arrays.fill(x, val);\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 Pollywog().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "334cc7204281a91ff298e6ea72749229", "src_uid": "e3dd409ceeba2a21890d35ceab9607eb", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * @author Don Li\n */\npublic class Pollywog {\n \n long INF = (long) 1e18;\n \n void solve() {\n int x = in.nextInt(), k = in.nextInt(), n = in.nextInt(), q = in.nextInt();\n int[] c = new int[k + 1];\n for (int i = 1; i <= k; i++) c[i] = in.nextInt();\n \n int[][] stones = new int[q + 1][2];\n for (int i = 0; i < q; i++) {\n int p = in.nextInt() - 1, w = in.nextInt();\n stones[i][0] = p;\n stones[i][1] = w;\n }\n stones[q][0] = n; stones[q][1] = 0;\n Arrays.sort(stones, Comparator.comparingInt(a -> a[0]));\n \n int id = 0;\n int[] state_to_id = new int[1 << k];\n int[] id_to_state = new int[1 << k];\n for (int i = 0; i < 1 << k; i++) {\n if (Integer.bitCount(i) == x) {\n id_to_state[id] = i;\n state_to_id[i] = id;\n id++;\n }\n }\n \n long[][][] basepow = new long[60][id][id];\n fill(basepow, INF);\n for (int i = 0; i < id; i++) {\n int state = id_to_state[i];\n if ((state & 1 << (k - 1)) == 0) {\n basepow[0][i][state_to_id[state << 1]] = 0;\n continue;\n }\n for (int j = 1; j <= k; j++) {\n int nstate = state ^ 1 << (k - 1);\n nstate <<= 1;\n if ((nstate & 1 << (k - j)) > 0) continue; // skip when this position is occupied\n basepow[0][i][state_to_id[nstate | 1 << (k - j)]] = c[j];\n }\n }\n for (int level = 1; level < basepow.length; level++) {\n basepow[level] = mult(basepow[level - 1], basepow[level - 1]);\n }\n \n long[][] cost = new long[id][id];\n fill(cost, INF);\n int start = (1 << k) - (1 << (k - x));\n cost[state_to_id[start]][state_to_id[start]] = 0;\n \n int cpos = 0, sidx = 0;\n while (cpos < n - x) {\n while (cpos > stones[sidx][0]) sidx++;\n \n if (cpos + k >= stones[sidx][0]) {\n long[][] base = new long[id][id];\n fill(base, INF);\n for (int i = 0; i < id; i++) {\n int state = id_to_state[i];\n if ((state & 1 << (k - 1)) == 0) {\n base[i][state_to_id[state << 1]] = 0;\n continue;\n }\n for (int j = 1; j <= k; j++) {\n int nstate = state ^ 1 << (k - 1);\n nstate <<= 1;\n if ((nstate & 1 << (k - j)) > 0) continue;\n int tcost = c[j];\n for (int a = 0; a < k; a++) {\n if (sidx + a < stones.length && cpos + j == stones[sidx + a][0]) {\n tcost += stones[sidx + a][1];\n }\n }\n base[i][state_to_id[nstate | 1 << (k - j)]] = tcost;\n }\n }\n cost = mult(cost, base);\n cpos++;\n } else {\n long dist = (stones[sidx][0] - k) - cpos;\n for (int i = 0; i < 60; i++) {\n if ((dist & (1L << i)) > 0) {\n cost = mult(cost, basepow[i]);\n }\n }\n cpos += dist;\n }\n }\n \n out.println(cost[state_to_id[start]][state_to_id[start]]);\n }\n \n long[][] mult(long[][] a, long[][] b) {\n int n = a.length;\n long[][] c = new long[n][n];\n fill(c, INF);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n c[i][j] = Math.min(c[i][j], a[i][k] + b[k][j]);\n }\n }\n }\n return c;\n }\n \n void fill(long[][][] a, long val) {\n for (long[][] x : a) fill(x, val);\n }\n \n void fill(long[][] a, long val) {\n for (long[] x : a) Arrays.fill(x, val);\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 Pollywog().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4bc29b83d70c20dccbdaab509940c9cb", "src_uid": "e3dd409ceeba2a21890d35ceab9607eb", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "203a52383acda09d6f904d01cef28812", "src_uid": "fa649fed687d72b1431ac82bc7288116", "difficulty": 2700.0} {"lang": "Java 17", "source_code": "import java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class RoundEdu132F {\t\r\n\tMyPrintWriter out;\r\n\tMyScanner in;\r\n\t\r\n//\tfinal static long FIXED_RANDOM;\r\n//\tstatic {\r\n//\t\tFIXED_RANDOM = System.currentTimeMillis();\r\n//\t}\r\n\tfinal static String IMPOSSIBLE = \"IMPOSSIBLE\";\r\n\tfinal static String POSSIBLE = \"POSSIBLE\";\r\n\tfinal static String YES = \"YES\";\r\n\tfinal static String NO = \"NO\";\r\n\t\r\n private void initIO(boolean isFileIO) {\r\n if (System.getProperty(\"ONLINE_JUDGE\") == null && isFileIO) {\r\n \ttry{\r\n\t in = new MyScanner(new FileInputStream(\"input.txt\"));\r\n\t out = new MyPrintWriter(new FileOutputStream(\"output.txt\"));\r\n \t}\r\n \tcatch(FileNotFoundException e){\r\n \t\te.printStackTrace();\r\n \t}\r\n }\r\n else{\r\n \t\tin = new MyScanner(System.in);\r\n \t out = new MyPrintWriter(new BufferedOutputStream(System.out));\r\n }\r\n }\r\n\t\r\n\tpublic static void main(String[] args){\r\n//\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\r\n\t\t\r\n\t\tRoundEdu132F sol = new RoundEdu132F();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = true;\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// takes up space: n*k*2 <= 30k = 6*10^6 < 100MB\r\n\t\t// time: O(nk), should fit in 6s\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\tArrayList ways = new ArrayList<>(f+2);\r\n\t\tArrayList suffix = new ArrayList<>(f+2);\r\n\t\tfor(int i=0; i<=f+1; i++)\r\n\t\t\tways.add(0L);\r\n\t\tfor(int i=0; i<=f+1; i++)\r\n\t\t\tsuffix.add(0L);\r\n\t\t\r\n\t\tfor(int i=0; i<=k && i<=f; i++) {\r\n\t\t\tways.set(i, 1L);\r\n\t\t}\r\n\t\tways.set(f+1, Math.max(0, (long) (k-f)));\r\n\t\t\r\n\t\tfor(int i=0; i=f+1; j--)\r\n\t\t\t\t\tval += mult.get(j);\r\n\t\t\t\tval %= MOD;\r\n\t\t\t\tsuffix.set(f+1, val);\r\n\t\t\t}\r\n\t\t\tfor(int j=f; j>=0; j--){\r\n\t\t\t\tlong val = suffix.get(j+1) + mult.get(j);\r\n\t\t\t\tval = val>=MOD? val-MOD: val;\r\n\t\t\t\tsuffix.set(j, val);\r\n\t\t\t}\r\n\t\t\tif(i < n-1) {\r\n\t\t\t\tfor(int j=0; j <= k && j<=f; j++) {\r\n\t\t\t\t\tlong val = suffix.get(j); // c_curr = j\r\n\t\t\t\t\tval += mult.get(j)*(k-j); // j+1 ~ k\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways.set(j, val);\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tlong val = suffix.get(f+1)*Math.max(0, k-f);\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways.set(f+1, val);\t\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tans = mult.get(f);\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 fft(ArrayList a, boolean isInvertedFFT) {\r\n\t int n = a.size();\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 \tCollections.swap(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.get(i+j);\r\n\t long v = a.get(i+j+len/2) * w % MOD;\r\n\t a.set(i+j, u + v < MOD ? u + v : u + v - MOD);\r\n\t a.set(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 int inv = (int) inverse(n, MOD);\r\n\t //a = (ArrayList) a.stream().map(x -> x*inv%MOD).collect(Collectors.toList());\r\n\t var iter = a.listIterator();\r\n\t while(iter.hasNext()) {\r\n\t \titer.set(iter.next()*inv%MOD);\r\n\t }\r\n\t }\r\n\t}\r\n\t\r\n\tstatic ArrayList multiplyPolynomial(ArrayList a, ArrayList b) {\r\n\t\tArrayList fa = (ArrayList) a.clone();\r\n\t\tArrayList fb = (ArrayList) b.clone();\r\n\t int n = 1;\r\n\t while (n < a.size() + b.size()) \r\n\t n <<= 1;\r\n\t for(int i=fa.size(); i result = new ArrayList<>(n);\r\n\t for (int i = 0; i < n; i++)\r\n\t \tresult.add(fa.get(i));\r\n\t return result;\r\n\t}\r\n\t\r\n\tpublic static class MyScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\t// 32768?\r\n\t\tpublic MyScanner(InputStream is, int bufferSize) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bufferSize);\r\n\t\t}\r\n\t\t\r\n\t\tpublic MyScanner(InputStream is) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\r\n\t\t}\r\n\r\n\t\tpublic void close() {\r\n\t\t\ttry {\r\n\t\t\t\tbr.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tString next() {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine(){\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextTreeEdges(int n, int offset){\r\n\t\t\tint[][] e = new int[n-1][2];\r\n\t\t\tfor(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c114b4324ea13d1fc48e58e65a158b54", "src_uid": "4b8161259545e44c7d1046be2e4fe014", "difficulty": 2500.0} {"lang": "Java 17", "source_code": "import java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class RoundEdu132F {\t\r\n\tMyPrintWriter out;\r\n\tMyScanner in;\r\n\t\r\n//\tfinal static long FIXED_RANDOM;\r\n//\tstatic {\r\n//\t\tFIXED_RANDOM = System.currentTimeMillis();\r\n//\t}\r\n\tfinal static String IMPOSSIBLE = \"IMPOSSIBLE\";\r\n\tfinal static String POSSIBLE = \"POSSIBLE\";\r\n\tfinal static String YES = \"YES\";\r\n\tfinal static String NO = \"NO\";\r\n\t\r\n private void initIO(boolean isFileIO) {\r\n if (System.getProperty(\"ONLINE_JUDGE\") == null && isFileIO) {\r\n \ttry{\r\n\t in = new MyScanner(new FileInputStream(\"input.txt\"));\r\n\t out = new MyPrintWriter(new FileOutputStream(\"output.txt\"));\r\n \t}\r\n \tcatch(FileNotFoundException e){\r\n \t\te.printStackTrace();\r\n \t}\r\n }\r\n else{\r\n \t\tin = new MyScanner(System.in);\r\n \t out = new MyPrintWriter(new BufferedOutputStream(System.out));\r\n }\r\n }\r\n\t\r\n\tpublic static void main(String[] args){\r\n//\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\r\n\t\t\r\n\t\tRoundEdu132F sol = new RoundEdu132F();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = false;\r\n\t\t\r\n\t\tinitIO(isFileIO);\r\n\t\r\n\t\tint t = hasMultipleTests? in.nextInt() : 1;\r\n\t \r\n\t for (int i = 1; i <= t; ++i) {\r\n\t \tif(isDebug){\r\n\t\t \tout.printf(\"Test %d\\n\", i);\r\n\t \t}\r\n\r\n\t \tgetInput();\r\n\r\n\t \tans = solve();\r\n\t \t\r\n\t \tprintOutput();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tint n, k, f;\r\n\tvoid getInput() {\r\n\t\tn = in.nextInt(); \r\n\t\tk = in.nextInt();\r\n\t\tf = in.nextInt();\r\n\t}\r\n\t\r\n\tvoid printOutput() {\r\n\t\tout.printlnAns(ans);\r\n\t}\r\n\t\r\n\tstatic final long MOD = 998244353;\r\n\tint ans;\r\n\tint solve(){\r\n\t\tlong ans = 0;\r\n\t\t\r\n\t\t// for each binary string s,\r\n\t\t// consider binary strings t of length n, where s is a prefix of t\r\n\t\t// we can have <= c_s among t\r\n\t\t\r\n\t\t// it's a full binary tree\r\n\t\t// where each vertex contains # of records in its subtree\r\n\t\t// and all records are at depth n\r\n\t\t\r\n\t\t// from each leaf, go up again, update each vertex to min(val, val(child1) + val(child2))\r\n\t\t// then the val(root) must be exactly f\r\n\t\t// where root is null string\r\n\r\n\t\t// the problem in this counting is we would have to use inclusion-exclusion due to duplicate cases\r\n\t\t// so we choose vertices representing disjoint subtrees\r\n\t\t// whose union can represent the whole tree\r\n\t\t// and whose sum is exactly f\r\n\t\t\r\n\t\t// for vertices under the subtrees, we can freely choose val\r\n\t\t// so that sum of siblings in each subtree >= val of root of subtree \r\n\t\t// for vertices above the subtrees, we can freely choose val between sum and k\r\n\r\n\t\t\r\n\t\t// so another approach:\r\n\t\t// for each vertex v of depth h\r\n\t\t// find # of ways to make sum exactly x\r\n\t\t// case 1: val(v) = x\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z >= x\r\n\t\t// case 2: val(v) >= x+1\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z = x\r\n\t\t\r\n\t\t// takes up space: n*k*2 <= 30k = 6*10^6 < 100MB\r\n\t\t// time: O(nk), should fit in 6s\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\tArrayList ways = new ArrayList<>(f+2);\r\n\t\tArrayList suffix = new ArrayList<>(f+2);\r\n\t\tfor(int i=0; i<=f+1; i++)\r\n\t\t\tways.add(0L);\r\n\t\tfor(int i=0; i<=f+1; i++)\r\n\t\t\tsuffix.add(0L);\r\n\t\t\r\n\t\tfor(int i=0; i<=k && i<=f; i++) {\r\n\t\t\tways.set(i, 1L);\r\n\t\t}\r\n\t\tways.set(f+1, Math.max(0, (long) (k-f)));\r\n\t\t\r\n\t\tfor(int i=0; i=f+1; j--)\r\n\t\t\t\t\tval += mult.get(j);\r\n\t\t\t\tval %= MOD;\r\n\t\t\t\tsuffix.set(f+1, val);\r\n\t\t\t}\r\n\t\t\tfor(int j=f; j>=0; j--){\r\n\t\t\t\tlong val = suffix.get(j+1) + mult.get(j);\r\n\t\t\t\tval = val>=MOD? val-MOD: val;\r\n\t\t\t\tsuffix.set(j, val);\r\n\t\t\t}\r\n\t\t\tif(i < n-1) {\r\n\t\t\t\tfor(int j=0; j <= k && j<=f; j++) {\r\n\t\t\t\t\tlong val = suffix.get(j); // c_curr = j\r\n\t\t\t\t\tval += mult.get(j)*(k-j); // j+1 ~ k\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways.set(j, val);\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tlong val = suffix.get(f+1)*Math.max(0, k-f);\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways.set(f+1, val);\t\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tans = mult.get(f);\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 fft(ArrayList a, boolean isInvertedFFT) {\r\n\t int n = a.size();\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 \tCollections.swap(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.get(i+j);\r\n\t long v = a.get(i+j+len/2) * w % MOD;\r\n\t a.set(i+j, u + v < MOD ? u + v : u + v - MOD);\r\n\t a.set(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 int inv = (int) inverse(n, MOD);\r\n\t //a = (ArrayList) a.stream().map(x -> x*inv%MOD).collect(Collectors.toList());\r\n\t var iter = a.listIterator();\r\n\t while(iter.hasNext()) {\r\n\t \titer.set(iter.next()*inv%MOD);\r\n\t }\r\n\t }\r\n\t}\r\n\t\r\n\tstatic ArrayList multiplyPolynomial(ArrayList a, ArrayList b) {\r\n\t\tArrayList fa = (ArrayList) a.clone();\r\n\t\tArrayList fb = (ArrayList) b.clone();\r\n\t int n = 1;\r\n\t while (n < a.size() + b.size()) \r\n\t n <<= 1;\r\n\t for(int i=fa.size(); i result = new ArrayList<>(n);\r\n\t for (int i = 0; i < n; i++)\r\n\t \tresult.add(fa.get(i));\r\n\t return result;\r\n\t}\r\n\t\r\n\tpublic static class MyScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\t// 32768?\r\n\t\tpublic MyScanner(InputStream is, int bufferSize) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bufferSize);\r\n\t\t}\r\n\t\t\r\n\t\tpublic MyScanner(InputStream is) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\r\n\t\t}\r\n\r\n\t\tpublic void close() {\r\n\t\t\ttry {\r\n\t\t\t\tbr.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tString next() {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine(){\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextTreeEdges(int n, int offset){\r\n\t\t\tint[][] e = new int[n-1][2];\r\n\t\t\tfor(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "59fa0dd329562097e9f222d4734fa58c", "src_uid": "4b8161259545e44c7d1046be2e4fe014", "difficulty": 2500.0} {"lang": "Java 17", "source_code": "import java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class RoundEdu132F {\t\r\n\tMyPrintWriter out;\r\n\tMyScanner in;\r\n\t\r\n//\tfinal static long FIXED_RANDOM;\r\n//\tstatic {\r\n//\t\tFIXED_RANDOM = System.currentTimeMillis();\r\n//\t}\r\n\tfinal static String IMPOSSIBLE = \"IMPOSSIBLE\";\r\n\tfinal static String POSSIBLE = \"POSSIBLE\";\r\n\tfinal static String YES = \"YES\";\r\n\tfinal static String NO = \"NO\";\r\n\t\r\n private void initIO(boolean isFileIO) {\r\n if (System.getProperty(\"ONLINE_JUDGE\") == null && isFileIO) {\r\n \ttry{\r\n\t in = new MyScanner(new FileInputStream(\"input.txt\"));\r\n\t out = new MyPrintWriter(new FileOutputStream(\"output.txt\"));\r\n \t}\r\n \tcatch(FileNotFoundException e){\r\n \t\te.printStackTrace();\r\n \t}\r\n }\r\n else{\r\n \t\tin = new MyScanner(System.in);\r\n \t out = new MyPrintWriter(new BufferedOutputStream(System.out));\r\n }\r\n }\r\n\t\r\n\tpublic static void main(String[] args){\r\n//\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\r\n\t\t\r\n\t\tRoundEdu132F sol = new RoundEdu132F();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = false;\r\n\t\t\r\n\t\tinitIO(isFileIO);\r\n\t\r\n\t\tint t = hasMultipleTests? in.nextInt() : 1;\r\n\t \r\n\t for (int i = 1; i <= t; ++i) {\r\n\t \tif(isDebug){\r\n\t\t \tout.printf(\"Test %d\\n\", i);\r\n\t \t}\r\n\r\n\t \tgetInput();\r\n\r\n\t \tans = solve();\r\n\t \t\r\n\t \tprintOutput();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tint n, k, f;\r\n\tvoid getInput() {\r\n\t\tn = in.nextInt(); \r\n\t\tk = in.nextInt();\r\n\t\tf = in.nextInt();\r\n\t}\r\n\t\r\n\tvoid printOutput() {\r\n\t\tout.printlnAns(ans);\r\n\t}\r\n\t\r\n\tstatic final long MOD = 998244353;\r\n\tint ans;\r\n\tint solve(){\r\n\t\tlong ans = 0;\r\n\t\t\r\n\t\t// for each binary string s,\r\n\t\t// consider binary strings t of length n, where s is a prefix of t\r\n\t\t// we can have <= c_s among t\r\n\t\t\r\n\t\t// it's a full binary tree\r\n\t\t// where each vertex contains # of records in its subtree\r\n\t\t// and all records are at depth n\r\n\t\t\r\n\t\t// from each leaf, go up again, update each vertex to min(val, val(child1) + val(child2))\r\n\t\t// then the val(root) must be exactly f\r\n\t\t// where root is null string\r\n\r\n\t\t// the problem in this counting is we would have to use inclusion-exclusion due to duplicate cases\r\n\t\t// so we choose vertices representing disjoint subtrees\r\n\t\t// whose union can represent the whole tree\r\n\t\t// and whose sum is exactly f\r\n\t\t\r\n\t\t// for vertices under the subtrees, we can freely choose val\r\n\t\t// so that sum of siblings in each subtree >= val of root of subtree \r\n\t\t// for vertices above the subtrees, we can freely choose val between sum and k\r\n\r\n\t\t\r\n\t\t// so another approach:\r\n\t\t// for each vertex v of depth h\r\n\t\t// find # of ways to make sum exactly x\r\n\t\t// case 1: val(v) = x\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z >= x\r\n\t\t// case 2: val(v) >= x+1\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z = x\r\n\t\t\r\n\t\t// takes up space: n*k*2 <= 30k = 6*10^6 < 100MB\r\n\t\t// time: O(nk), should fit in 6s\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\tlong[] ways = new long[f+2];\r\n\t\tlong[] suffix = new long[f+2];\r\n\t\t\r\n\t\tfor(int i=0; i<=k && i<=f; i++)\r\n\t\t\tways[i] = 1;\r\n\t\tways[f+1] = Math.max(0, k-f);\r\n\t\t\r\n\t\tfor(int i=0; i=f+1; j--)\r\n\t\t\t\t\tval += mult[j];\r\n\t\t\t\tval %= MOD;\r\n\t\t\t\tsuffix[f+1] = val;\r\n\t\t\t}\r\n\t\t\tfor(int j=f; j>=0; j--){\r\n\t\t\t\tlong val = suffix[j+1] + mult[j];\r\n\t\t\t\tval = val>=MOD? val-MOD: val;\r\n\t\t\t\tsuffix[j] = val;\r\n\t\t\t}\r\n\t\t\tif(i < n-1) {\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 += mult[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}\r\n\t\t\telse {\r\n\t\t\t\tans = mult[f];\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 int inv = (int) inverse(n, MOD);\r\n\t for(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a1525ab97d153e22e916be307ac44a01", "src_uid": "4b8161259545e44c7d1046be2e4fe014", "difficulty": 2500.0} {"lang": "Java 17", "source_code": "import java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class RoundEdu132F {\t\r\n\tMyPrintWriter out;\r\n\tMyScanner in;\r\n\t\r\n//\tfinal static long FIXED_RANDOM;\r\n//\tstatic {\r\n//\t\tFIXED_RANDOM = System.currentTimeMillis();\r\n//\t}\r\n\tfinal static String IMPOSSIBLE = \"IMPOSSIBLE\";\r\n\tfinal static String POSSIBLE = \"POSSIBLE\";\r\n\tfinal static String YES = \"YES\";\r\n\tfinal static String NO = \"NO\";\r\n\t\r\n private void initIO(boolean isFileIO) {\r\n if (System.getProperty(\"ONLINE_JUDGE\") == null && isFileIO) {\r\n \ttry{\r\n\t in = new MyScanner(new FileInputStream(\"input.txt\"));\r\n\t out = new MyPrintWriter(new FileOutputStream(\"output.txt\"));\r\n \t}\r\n \tcatch(FileNotFoundException e){\r\n \t\te.printStackTrace();\r\n \t}\r\n }\r\n else{\r\n \t\tin = new MyScanner(System.in);\r\n \t out = new MyPrintWriter(new BufferedOutputStream(System.out));\r\n }\r\n }\r\n\t\r\n\tpublic static void main(String[] args){\r\n//\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\r\n\t\t\r\n\t\tRoundEdu132F sol = new RoundEdu132F();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = false;\r\n\t\t\r\n\t\tinitIO(isFileIO);\r\n\t\r\n\t\tint t = hasMultipleTests? in.nextInt() : 1;\r\n\t \r\n\t for (int i = 1; i <= t; ++i) {\r\n\t \tif(isDebug){\r\n\t\t \tout.printf(\"Test %d\\n\", i);\r\n\t \t}\r\n\r\n\t \tgetInput();\r\n\r\n\t \tans = solve();\r\n\t \t\r\n\t \tprintOutput();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tint n, k, f;\r\n\tvoid getInput() {\r\n\t\tn = in.nextInt(); \r\n\t\tk = in.nextInt();\r\n\t\tf = in.nextInt();\r\n\t}\r\n\t\r\n\tvoid printOutput() {\r\n\t\tout.printlnAns(ans);\r\n\t}\r\n\t\r\n\tstatic final long MOD = 998244353;\r\n\tint ans;\r\n\tint solve(){\r\n\t\tlong ans = 0;\r\n\t\t\r\n\t\t// for each binary string s,\r\n\t\t// consider binary strings t of length n, where s is a prefix of t\r\n\t\t// we can have <= c_s among t\r\n\t\t\r\n\t\t// it's a full binary tree\r\n\t\t// where each vertex contains # of records in its subtree\r\n\t\t// and all records are at depth n\r\n\t\t\r\n\t\t// from each leaf, go up again, update each vertex to min(val, val(child1) + val(child2))\r\n\t\t// then the val(root) must be exactly f\r\n\t\t// where root is null string\r\n\r\n\t\t// the problem in this counting is we would have to use inclusion-exclusion due to duplicate cases\r\n\t\t// so we choose vertices representing disjoint subtrees\r\n\t\t// whose union can represent the whole tree\r\n\t\t// and whose sum is exactly f\r\n\t\t\r\n\t\t// for vertices under the subtrees, we can freely choose val\r\n\t\t// so that sum of siblings in each subtree >= val of root of subtree \r\n\t\t// for vertices above the subtrees, we can freely choose val between sum and k\r\n\r\n\t\t\r\n\t\t// so another approach:\r\n\t\t// for each vertex v of depth h\r\n\t\t// find # of ways to make sum exactly x\r\n\t\t// case 1: val(v) = x\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z >= x\r\n\t\t// case 2: val(v) >= x+1\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z = x\r\n\t\t\r\n\t\t// 2 1 1\r\n\t\t// case 1: c_0 = 1, c_1 = 0\r\n\t\t// 00 01 10 11\r\n\t\t// 1 0 0/1 0/1\r\n\t\t// 0 1 0/1 0/1\r\n\t\t// 1 1 0/1 0/1\r\n\t\t// -> 12\r\n\t\t\r\n\t\t// case 2: c_0 = 0, c_1 = 1\r\n\t\t// -> 12\r\n\t\t\r\n\t\t// case 3: c_0 = 1, c_1 = 1\r\n\t\t// 1 0 0 0\r\n\t\t// 0 1 0 0\r\n\t\t// 1 1 0 0\r\n\t\t// 0 0 1 0\r\n\t\t// 0 0 0 1\r\n\t\t// 0 0 1 1\r\n\t\t// -> 6\r\n\t\t\r\n\t\t// subtree_0 = 1 -> 3\r\n\t\t// c_0 = 1 -> 1 0, 0 1, 1 1\r\n\t\t\r\n\t\t// subtree_0 = 0 -> 5\r\n\t\t// c_0 = 0 -> 0/1, 0/1 -> 4\r\n\t\t// c_0 = 1 -> 0, 0 -> 1\r\n\t\t// 3*5 + 3*5 = 30\r\n\t\t\r\n\t\t// subtree_l = 0 -> 1 \r\n\t\t// subtree_l = 1 -> 1\r\n\t\t\r\n\t\t// long[] ways = new long[f+2];\r\n\t\tint len = 1;\r\n\t\twhile (len < f+2 + f+2) \r\n\t len <<= 1;\r\n\t\tlong[] ways = new long[len];\r\n\t\tlong[] suffix = new long[f+2];\r\n\t\t\r\n\t\tfor(int i=0; i<=k && i<=f; i++)\r\n\t\t\tways[i] = 1;\r\n\t\tways[f+1] = Math.max(0, k-f);\r\n\t\t\r\n\t\tfor(int i=0; i=f+1; j--)\r\n\t\t\t\t\tval += ways[j];\r\n\t\t\t\tval %= MOD;\r\n\t\t\t\tsuffix[f+1] = val;\r\n\t\t\t}\r\n\t\t\tfor(int j=f; j>=0; j--){\r\n\t\t\t\tlong val = suffix[j+1] + ways[j];\r\n\t\t\t\tval = val>=MOD? val-MOD: val;\r\n\t\t\t\tsuffix[j] = val;\r\n\t\t\t}\r\n\t\t\tif(i < n-1) {\r\n\t\t\t\tfor(int j=0; j <= k && j<=f; j++) {\r\n\t\t\t\t\tlong val = suffix[j]; // c_curr = j\r\n\t\t\t\t\tval += ways[j]*(k-j); // j+1 ~ k\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways[j] = val;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tlong val = suffix[f+1]*Math.max(0, k-f);\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways[f+1] = val;\r\n\t\t\t\t}\r\n\t\t\t\tArrays.fill(ways, f+2, ways.length, 0);\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tans = ways[f];\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 int inv = (int) inverse(n, MOD);\r\n\t for(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66f013eca946eb194e69b01ef97d082b", "src_uid": "4b8161259545e44c7d1046be2e4fe014", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DShakeIt solver = new DShakeIt();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DShakeIt {\n Modular mod = new Modular(1e9 + 7);\n int[][][][] h;\n int[][] g;\n int n;\n int flow;\n InverseNumber inv = new InverseNumber(100, mod);\n Debug debug = new Debug(false);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n n = in.readInt();\n int m = in.readInt();\n flow = Math.max(n + 1, m);\n\n // f = new int[n + 1][flow + 1];\n h = new int[n + 1][flow + 1][n + 1][flow + 1];\n g = new int[n + 1][flow + 1];\n\n //SequenceUtils.deepFill(f, -1);\n SequenceUtils.deepFill(g, -1);\n SequenceUtils.deepFill(h, -1);\n\n //g(2, 0);\n\n int ans = f(n, m - 1);\n //ans = mod.mul(ans, fact.invFact(n));\n\n //debug.debug(\"f\", f);\n debug.debug(\"g\", g);\n debug.debug(\"h\", h);\n out.println(ans);\n }\n\n public int h(int i, int j, int a, int b) {\n if (i < 0 || j < 0) {\n return 0;\n }\n if (h[i][j][a][b] == -1) {\n h[i][j][a][b] = 0;\n if (a == 0 || b == 0) {\n return h[i][j][a][b] = i == 0 && j == 0 ? 1 : 0;\n }\n int limit = Math.min(i / a, j / b);\n int prod = 1;\n int aa = a;\n int bb = b;\n if (bb > 1) {\n bb--;\n } else {\n bb = flow;\n aa--;\n }\n h[i][j][a][b] = h(i, j, aa, bb);\n for (int t = 1; t <= limit; t++) {\n prod = mod.mul(prod, g(a - 1, b - 1) + t - 1);\n prod = mod.mul(prod, inv.inverse(t));\n int local = mod.mul(h(i - a * t, j - b * t, aa, bb),\n prod);\n h[i][j][a][b] = mod.plus(h[i][j][a][b], local);\n }\n\n }\n\n return h[i][j][a][b];\n }\n\n public int f(int i, int j) {\n return h(i, j, i, j);\n }\n\n public int g(int i, int j) {\n if (i < 0 || j < 0) {\n return 0;\n }\n if (g[i][j] == -1) {\n g[i][j] = 0;\n if (i == 0) {\n return g[i][j] = j == 0 ? 1 : 0;\n }\n for (int a = 0; a <= i; a++) {\n int c = i - a;\n for (int b = j; b <= a + 1; b++) {\n for (int d = j; d <= c + 1; d++) {\n if (Math.min(b, d) != j) {\n continue;\n }\n int way = mod.mul(f(a, b), f(c, d));\n\n g[i][j] = mod.plus(g[i][j], way);\n }\n }\n }\n }\n\n return g[i][j];\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 public int inverse(int x) {\n return inv[x];\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(1 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(int c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n 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 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 SequenceUtils {\n public static void deepFill(Object array, int val) {\n if (!array.getClass().isArray()) {\n throw new IllegalArgumentException();\n }\n if (array instanceof int[]) {\n int[] intArray = (int[]) array;\n Arrays.fill(intArray, val);\n } else {\n Object[] objArray = (Object[]) array;\n for (Object obj : objArray) {\n deepFill(obj, val);\n }\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d81e8449cdaf1b12b579972f1986ca42", "src_uid": "aca6148effff8b893c961b1ee465e4e4", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tstatic final int P = 1_000_000_007;\n\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b4809110a1e048cfba6f66a45903176f", "src_uid": "aca6148effff8b893c961b1ee465e4e4", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "//package round431;\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 mod = 1000000007;\n\t\tint n = ni(), m = ni();\n\t\t\n\t\tif(m > n+1){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong[][] dp = {\n\t\t\t\t{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 20, 15, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 78, 60, 18, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 320, 269, 90, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 1404, 1196, 452, 102, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 6354, 5550, 2232, 566, 105, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 29660, 26148, 11129, 3004, 608, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 141356, 125797, 55564, 15992, 3401, 621, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 685720, 613696, 279559, 84232, 18975, 3551, 624, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 3372972, 3033312, 1414754, 443388, 104533, 20372, 3596, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 16787362, 15150580, 7205309, 2330591, 572601, 115463, 20879, 3609, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 84374296, 76373402, 36905066, 12260498, 3118939, 651005, 120188, 21042, 3612, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 427657604, 388029184, 190039924, 64569370, 16932666, 3645556, 689414, 121903, 21088, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 183422138, 985084652, 983358608, 340626132, 91705041, 20316053, 3932165, 705215, 122449, 21101, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 218595807, 216827574, 111123886, 800216575, 495958406, 112739002, 22325180, 4062841, 710843, 122615, 21104, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 965416379, 866331606, 673968136, 532890011, 680029370, 623595485, 126193365, 23327903, 4114503, 712681, 122661, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 993455088, 862080862, 725923843, 580538538, 477345228, 440384026, 710624473, 133452405, 23761056, 4132780, 713240, 122674, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 905119307, 192776929, 427183902, 902740653, 205572806, 943087579, 988485039, 760890378, 136845231, 23927353, 4138765, 713407, 122677, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 983258926, 856652574, 419294183, 314218472, 565633404, 144225184, 323294025, 324568580, 786075109, 138248537, 23985741, 4140643, 713453, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 768913899, 874476794, 159058735, 376378817, 200939010, 909767346, 644939341, 508636359, 503698048, 797229154, 138775923, 24005038, 4141205, 713466, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 823642493, 705094318, 65810807, 545788941, 142710068, 49894552, 580875908, 538421095, 739525857, 588102612, 801695573, 138960083, 24011149, 4141372, 713469, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 499072817, 566780682, 543283862, 201724451, 58271802, 344858002, 63874460, 300408434, 761612286, 353031679, 623964235, 803344922, 139021264, 24013040, 4141418, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 576529878, 241212759, 870406317, 516608637, 786808826, 170564828, 502043776, 190085463, 974194583, 74582715, 628375911, 637942018, 803919124, 139040931, 24013603, 4141431, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 282664742, 137969620, 386494112, 872056910, 282992318, 176896609, 111724215, 824867747, 799878112, 461513992, 110630666, 741379513, 643041881, 804110861, 139047082, 24013770, 4141434, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 608570317, 801652211, 274963061, 886518820, 90837790, 626361724, 699033037, 540982188, 987824503, 727135089, 45389606, 987874590, 784549175, 644812246, 804173102, 139048976, 24013816, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 357486479, 181089468, 969172260, 289931681, 772500290, 740282998, 829587032, 842625948, 138113736, 232645342, 395674948, 621904062, 338297429, 800139849, 645406477, 804192896, 139049539, 24013829, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 254234510, 292608126, 417414987, 111595904, 430339254, 77443136, 291720282, 257053540, 606934755, 335685102, 729928927, 235560375, 363847245, 469945923, 805548789, 645601127, 804199060, 139049706, 24013832, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 595455172, 310857698, 142929150, 451089427, 328175846, 775787438, 501396673, 447925018, 130822422, 58418115, 769951318, 773701088, 10940059, 434786651, 517174485, 807371391, 645663741, 804200955, 139049752, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 349426455, 464387898, 431999991, 893280928, 77931049, 52569295, 64921457, 666455225, 189432628, 773839352, 165726163, 690284554, 801367433, 438034612, 832160214, 533545110, 807973529, 645683575, 804201518, 139049765, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 702575145, 801280561, 442448096, 451076534, 362114194, 647176951, 12722649, 733600088, 928868484, 314273055, 676922181, 390832804, 195357510, 179246035, 671930508, 973917989, 539088258, 808169252, 645689742, 804201685, 139049768, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 899116600, 365887165, 540851416, 477622706, 621209745, 41855534, 381872526, 568727969, 382270909, 755519068, 830377562, 327016443, 53743758, 200196957, 718037620, 859696293, 23095734, 540931780, 808231993, 645691637, 804201731, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 28443452, 454707299, 720701160, 419189620, 636769312, 212745640, 720255594, 47264013, 4353233, 571423322, 317657958, 770671406, 566775337, 229432738, 486965531, 377266778, 282006828, 39807033, 541536871, 808251840, 645692200, 804201744, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 708370999, 745748618, 582217318, 455319063, 603859790, 231341973, 348942460, 170184178, 689724591, 110508688, 857619861, 426992165, 588329004, 979260570, 343202258, 927818650, 898766596, 428587224, 45404704, 541732968, 808258008, 645692367, 804201747, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 220300732, 46609850, 375712662, 568586423, 941804380, 601855282, 597025225, 210361053, 58336959, 790143347, 618095230, 176358732, 30543080, 993842771, 937341158, 423396479, 514187911, 147490617, 478619188, 47256254, 541795749, 808259903, 645692413, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 491767445, 782125933, 760844150, 771643255, 631272756, 200568934, 776727389, 125809805, 89178072, 942931662, 158053887, 262399651, 379208459, 503988395, 438193938, 774920020, 818726507, 874419280, 581626996, 495470440, 47862421, 541815599, 808260466, 645692426, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 751552393, 507106191, 927020229, 340983299, 824935876, 982944264, 112403021, 736470034, 712046769, 464383985, 718862672, 472451638, 74303981, 410907563, 666832122, 904514562, 425593301, 712078493, 543662654, 730328807, 501089364, 48058645, 541821767, 808260633, 645692429, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 73145977, 945393539, 491610692, 289456339, 427592987, 156456089, 856721546, 643411286, 438709919, 830334785, 521084183, 802961067, 577757709, 979743576, 751951426, 169028881, 473063432, 677653095, 991492477, 821146133, 780715488, 502943880, 48121439, 541823662, 808260679, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 437082018, 559756622, 712764202, 175256028, 39001965, 169118126, 961041841, 330531579, 726355685, 652058564, 184476311, 959023349, 36529059, 566693578, 286624497, 631545034, 213553699, 420454245, 108890823, 707021032, 260499053, 797622167, 503550421, 48141290, 541824225, 808260692, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 911273698, 461802381, 157547978, 651886959, 991079947, 904206440, 752012728, 91490856, 970456086, 827908805, 200404310, 46817164, 95037060, 872320139, 544155656, 866678032, 265740321, 62232640, 640825471, 56958810, 445660277, 410088790, 803249159, 503746685, 48147458, 541824392, 808260695, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 99547327, 792772093, 413279596, 39759631, 598831434, 274143461, 681931397, 242545472, 634618776, 733602547, 401821126, 689076310, 138792047, 867529343, 871445219, 80442445, 172358416, 884450832, 787463230, 130635330, 184459417, 735860525, 460617750, 805104752, 503809482, 48149353, 541824438, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 482186350, 273967294, 649045886, 108980254, 570311699, 966889002, 666859727, 546817455, 689881573, 84630300, 893298736, 354835358, 214615309, 168750989, 158197112, 45797168, 168957735, 782446817, 163825770, 628696027, 196779450, 66205132, 177414259, 477545803, 805711420, 503829333, 48149916, 541824451, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 725343523, 72904069, 317229993, 651086888, 760199404, 971917773, 359172971, 877096152, 866895001, 443077851, 620349470, 706453237, 575090255, 745511976, 849766738, 965850920, 588577451, 178627725, 235164813, 372125002, 603898412, 155168897, 835596754, 327364579, 483175764, 805907697, 503835501, 48150083, 541824454, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 227169509, 545240090, 21373631, 4703558, 149454127, 906947250, 436226575, 231453773, 520829752, 657885509, 940170245, 816566317, 211196753, 118819980, 726741982, 596789649, 939963244, 486112971, 653096931, 608998341, 286609915, 821835078, 678102815, 131197840, 377949300, 485031731, 805970495, 503837396, 48150129, 541824455, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 812941513, 632016277, 587752971, 907369437, 245365463, 237152744, 770806419, 254057260, 256931484, 657088179, 685991399, 165335468, 793178596, 943503554, 488208964, 862646224, 801219250, 113427800, 680954452, 973579312, 138931569, 370928377, 622393891, 633659803, 573653877, 394885434, 485638439, 805990346, 503837959, 48150142, 541824455, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0, 0},\n\t\t\t\t{0, 0, 831284912, 920930216, 121837637, 363197429, 615372675, 818973396, 465784421, 249654262, 962863505, 443733107, 862431829, 259718701, 674328903, 72003370, 27941538, 457774123, 769643354, 316096474, 198211169, 732391072, 973293491, 813065869, 598354179, 515441584, 416189909, 723747383, 400516472, 485834719, 805996514, 503838126, 48150145, 541824455, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0, 0},\n\t\t\t\t{0, 0, 833292674, 298848298, 168903770, 545074331, 52799215, 758871225, 252495511, 924121755, 374266136, 669478514, 60769576, 806058403, 907911655, 394903137, 121208854, 373718471, 645725760, 64527479, 804531912, 436447112, 588689529, 502994369, 593283887, 897804374, 214286791, 714026394, 774353518, 402372566, 485897517, 805998409, 503838172, 48150146, 541824455, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0, 0},\n\t\t\t\t{0, 0, 987390633, 352790884, 614135688, 73248057, 535068088, 778378333, 304699153, 787437186, 778598899, 436272891, 717326240, 327325089, 183229809, 956509573, 178816507, 780681714, 939063227, 78846995, 42468967, 482999731, 874463719, 105692341, 586003573, 658414122, 894144031, 201549678, 156845346, 791292622, 402979287, 485917368, 805998972, 503838185, 48150146, 541824455, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1, 0},\n\t\t\t\t{0, 0, 637245807, 499830334, 750632612, 151627894, 974119694, 567468624, 244879604, 269170082, 396392266, 280843475, 343181990, 746080370, 730888752, 810540922, 910735707, 103336517, 104943638, 266354616, 664188130, 338775312, 887579699, 740792318, 467888722, 667892662, 673680617, 203733589, 989562192, 306994734, 796924034, 403175568, 485923536, 805999139, 503838188, 48150146, 541824455, 808260696, 645692430, 804201748, 139049769, 24013833, 4141435, 713470, 122678, 21105, 3613, 625, 106, 19, 3, 1}\n\t\t};\n\t\tout.println(dp[n][m]);\n\t}\n\t\n\tlong C(long n, long r, int mod)\n\t{\n\t\tif(r < 0 || n < 0 || r > n)return 0;\n\t\tlong num = 1, den = 1;\n\t\tfor(int i = 0;i < r;i++){\n\t\t\tnum = num * (n-i) % mod;\n\t\t\tden = den * (i+1) % mod;\n\t\t}\n\t\treturn num * invl(den, mod) % mod;\n\t}\n\t\n\tpublic static long invl(long a, long mod) {\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a646916fb7850faf727c7adb07d33539", "src_uid": "aca6148effff8b893c961b1ee465e4e4", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tstatic final int P = 1_000_000_007;\n\n\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\t\t\t\n//\t\t\tSystem.err.println(\"sz = \" + sz);\n//\t\t\tfor (int i = 0; i < cnt.length; i++) {\n//\t\t\t\tfor (int j = 0; j < cnt[i].length; j++) {\n//\t\t\t\t\tif (cnt[i][j] != 0) {\n//\t\t\t\t\t\tSystem.err.println(i + \" \" + j + \" --> \" + cnt[i][j]);\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t}\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\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\tfor (int cntAdd = 1; cntAdd <= sz; cntAdd++) {\n\n\t\t\t\t\t\tint ways = getCoef(cnt[addSz][addCut], cntAdd);\n\n\t\t\t\t\t\tfor (int i = sz; i >= 0; i--) {\n\t\t\t\t\t\t\tfor (int j = N; 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\n\tint getCoef(int x, int y) {\n\t\t\n\t\t// y into x summands\n\t\t// C(x+y-1, y)\n\t\tint ret = 1;\n\t\tfor (int i = 0; i < y; i++) {\n\t\t\tint lol = Math.floorMod(x + y - 1 - i, P);\n\t\t\tret = (int)((long)ret * lol % P * inv[i + 1] % P);\n\t\t}\n\t\t\n//\t\tSystem.err.println(x + \" \" + y + \" -> \" + ret);\n\t\t\n\t\treturn ret;\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\tD() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6891274df0ecf06b66da768d65353cb", "src_uid": "aca6148effff8b893c961b1ee465e4e4", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class PQTree_test {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic PQNode[] collect(PQNode[] arr, int whatStatus) {\n\t\tint sz = 0;\n\t\tfor (PQNode v : arr) {\n\t\t\tif (v.status == whatStatus) {\n\t\t\t\tsz++;\n\t\t\t}\n\t\t}\n\n\t\tPQNode[] ret = new PQNode[sz];\n\t\tint ptr = 0;\n\t\tfor (PQNode v : arr) {\n\t\t\tif (v.status == whatStatus) {\n\t\t\t\tret[ptr++] = v;\n\t\t\t}\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tstatic PQNode makeNode(PQNode[] arr, int whatType) {\n\t\tif (arr.length == 0) {\n\t\t\treturn null;\n\t\t}\n\t\tif (arr.length == 1) {\n\t\t\treturn arr[0];\n\t\t}\n\t\tif (arr.length == 2) {\n\t\t\twhatType = PQNode.Q_NODE;\n\t\t}\n\t\treturn new PQNode(whatType, arr);\n\t}\n\n\tstatic void fullCopy(T[] src, T[] dest, int destPos) {\n\t\tSystem.arraycopy(src, 0, dest, destPos, src.length);\n\t}\n\n\tstatic PQNode[] appendFirst(PQNode v, PQNode[] arr) {\n\t\tif (v == null) {\n\t\t\treturn arr;\n\t\t}\n\t\tPQNode[] ret = new PQNode[arr.length + 1];\n\t\tret[0] = v;\n\t\tfullCopy(arr, ret, 1);\n\t\treturn ret;\n\t}\n\n\tstatic PQNode[] appendLast(PQNode v, PQNode[] arr) {\n\t\tif (v == null) {\n\t\t\treturn arr;\n\t\t}\n\t\tPQNode[] ret = new PQNode[arr.length + 1];\n\t\tfullCopy(arr, ret, 0);\n\t\tret[arr.length] = v;\n\t\treturn ret;\n\t}\n\n\tstatic PQNode[] concat(PQNode[] arr1, PQNode[] arr2) {\n\t\tPQNode[] ret = new PQNode[arr1.length + arr2.length];\n\t\tfullCopy(arr1, ret, 0);\n\t\tfullCopy(arr2, ret, arr1.length);\n\t\treturn ret;\n\t}\n\n\tstatic void reverse(T[] a) {\n\t\tfor (int i = 0, j = a.length - 1; i < j; i++, j--) {\n\t\t\tT tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\t}\n\n\tstatic class PQNode {\n\t\tstatic final int P_NODE = -1;\n\t\tstatic final int Q_NODE = -2;\n\n\t\t/**\n\t\t * < 0 if P or Q node
\n\t\t * otherwise this node is leaf and type is number of element\n\t\t */\n\t\tint type;\n\t\tPQNode[] child;\n\n\t\tpublic PQNode(int type, PQNode[] child) {\n\t\t\tthis.type = type;\n\t\t\tthis.child = child;\n\t\t}\n\n\t\tstatic final int EMPTY = 0;\n\t\tstatic final int FULL = 1;\n\t\tstatic final int PARTIAL = 2;\n\t\tstatic final int CONTAINS_ALL = 3;\n\t\t/**\n\t\t * see above for possible values
\n\t\t * in case of partial, first children are in current query, then not\n\t\t */\n\t\tint status;\n\n\t\t/**\n\t\t * number of leafs from current query in this subtree\n\t\t */\n\t\tint count;\n\n\t\tPQNode dfs(boolean[] b, int allQry) {\n\n\t\t\tif (type >= 0) {\n\t\t\t\tstatus = b[type] ? FULL : EMPTY;\n\t\t\t\tcount = b[type] ? 1 : 0;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tcount = 0;\n\n\t\t\tboolean allFull = true;\n\t\t\tboolean allEmpty = true;\n\t\t\tint cntPartial = 0;\n\t\t\tint[] idxPartial = new int[2];\n\n\t\t\tfor (int i = 0; i < child.length; i++) {\n\t\t\t\tchild[i] = child[i].dfs(b, allQry);\n\t\t\t\tif (child[i] == null) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < child.length; i++) {\n\t\t\t\tPQNode v = child[i];\n\n\t\t\t\tif (v.status == CONTAINS_ALL) {\n\t\t\t\t\tstatus = CONTAINS_ALL;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tallFull &= v.status == FULL;\n\t\t\t\tallEmpty &= v.status == EMPTY;\n\t\t\t\tif (v.status == PARTIAL) {\n\t\t\t\t\tif (cntPartial == 2) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tidxPartial[cntPartial++] = i;\n\t\t\t\t}\n\t\t\t\tcount += v.count;\n\t\t\t}\n\n\t\t\tboolean doesContainAll = count == allQry;\n\n\t\t\tif (allFull) {\n\t\t\t\tstatus = FULL;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tif (allEmpty) {\n\t\t\t\tstatus = EMPTY;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tif (cntPartial <= 1 && type == P_NODE && doesContainAll) {\n\t\t\t\tPQNode[] fulls = collect(child, FULL);\n\t\t\t\tPQNode[] emptys = collect(child, EMPTY);\n\n\t\t\t\tPQNode fullNode = makeNode(fulls, P_NODE);\n\n\t\t\t\tPQNode fullAndPartial;\n\t\t\t\tif (cntPartial == 0) {\n\t\t\t\t\tfullAndPartial = fullNode;\n\t\t\t\t} else {\n\t\t\t\t\tPQNode[] arr = appendFirst(fullNode,\n\t\t\t\t\t\t\tchild[idxPartial[0]].child);\n\t\t\t\t\tfullAndPartial = makeNode(arr, Q_NODE);\n\t\t\t\t}\n\n\t\t\t\tPQNode[] arr = appendFirst(fullAndPartial, emptys);\n\t\t\t\tPQNode ret = makeNode(arr, P_NODE);\n\t\t\t\tret.status = CONTAINS_ALL;\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\t\tif (cntPartial <= 1 && type == P_NODE && !doesContainAll) {\n\t\t\t\tPQNode[] fulls = collect(child, FULL);\n\t\t\t\tPQNode[] emptys = collect(child, EMPTY);\n\n\t\t\t\tPQNode full = makeNode(fulls, P_NODE);\n\t\t\t\tif (full != null) {\n\t\t\t\t\tfull.status = FULL;\n\t\t\t\t}\n\t\t\t\tPQNode empty = makeNode(emptys, P_NODE);\n\t\t\t\tif (empty != null) {\n\t\t\t\t\tempty.status = EMPTY;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tPQNode ret;\n\t\t\t\tif (cntPartial == 1) {\n\t\t\t\t\tPQNode[] arr = appendFirst(full,\n\t\t\t\t\t\t\tappendLast(empty, child[idxPartial[0]].child));\n\t\t\t\t\tret = makeNode(arr, Q_NODE);\n\t\t\t\t} else {\n\t\t\t\t\tret = makeNode(new PQNode[] { full, empty }, Q_NODE);\n\t\t\t\t}\n\t\t\t\tret.count = count;\n\t\t\t\tret.status = PARTIAL;\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\t\tif (cntPartial == 2 && type == P_NODE && doesContainAll) {\n\t\t\t\tPQNode[] fulls = collect(child, FULL);\n\t\t\t\tPQNode[] emptys = collect(child, EMPTY);\n\n\t\t\t\tPQNode fullNode = makeNode(fulls, P_NODE);\n\n\t\t\t\treverse(child[idxPartial[0]].child);\n\n\t\t\t\tPQNode[] tmp = appendLast(fullNode, child[idxPartial[0]].child);\n\t\t\t\tPQNode fullAndPartial = makeNode(\n\t\t\t\t\t\tconcat(tmp, child[idxPartial[1]].child), Q_NODE);\n\n\t\t\t\tPQNode[] arr = appendFirst(fullAndPartial, emptys);\n\t\t\t\tPQNode ret = makeNode(arr, P_NODE);\n\t\t\t\tret.status = CONTAINS_ALL;\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\t\n\t\t\tif (type == Q_NODE) {\n\t\t\t\tint size = child.length;\n\t\t\t\tfor (int i = 0; i < cntPartial; i++) {\n\t\t\t\t\tsize += child[idxPartial[i]].child.length - 1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tPQNode[] arr = new PQNode[size];\n\t\t\t\tint ptr = 0;\n\t\t\t\t\n\t\t\t\tboolean firstPartial = true;\n\t\t\t\tfor (int i = 0; i< child.length; i++) {\n\t\t\t\t\tPQNode v = child[i];\n\t\t\t\t\tif (v.status == PARTIAL) { \n\t\t\t\t\t\t\n\t\t\t\t\t\tboolean shouldRev;\n\t\t\t\t\t\tif (cntPartial == 1) {\n\t\t\t\t\t\t\tif (i == 0) {\n\t\t\t\t\t\t\t\tshouldRev = child[i + 1].status == FULL;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tshouldRev = child[i - 1].status == EMPTY;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tshouldRev = firstPartial;\n\t\t\t\t\t\t\tfirstPartial = !firstPartial;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (shouldRev) {\n\t\t\t\t\t\t\treverse(v.child);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tfor (PQNode u : v.child) {\n\t\t\t\t\t\t\tarr[ptr++] = u;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tarr[ptr++] = v;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (arr[arr.length - 1].status == FULL) {\n\t\t\t\t\treverse(arr);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tptr = arr.length - 1;\n\t\t\t\twhile (ptr >= 0 && arr[ptr].status == EMPTY) {\n\t\t\t\t\tptr--;\n\t\t\t\t}\n\t\t\t\twhile (ptr >= 0 && arr[ptr].status == FULL) {\n\t\t\t\t\tptr--;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (ptr == -1) {\n\t\t\t\t\tPQNode ret = makeNode(arr, Q_NODE);\n\t\t\t\t\tret.count = count;\n\t\t\t\t\tret.status = doesContainAll ? CONTAINS_ALL : PARTIAL;\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\twhile (ptr >= 0 && arr[ptr].status == EMPTY) {\n\t\t\t\t\tptr--;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (ptr == -1 && doesContainAll) {\n\t\t\t\t\tPQNode ret = makeNode(arr, Q_NODE);\n\t\t\t\t\tret.status = CONTAINS_ALL;\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn null;\n\t\t}\n\n\t\tvoid genRepr(StringBuilder sb) {\n\t\t\tif (type >= 0) {\n\t\t\t\tsb.append(type + \" \");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsb.append(type == P_NODE ? \"[\" : \"(\");\n\t\t\tfor (PQNode v : child) {\n\t\t\t\tv.genRepr(sb);\n\t\t\t}\n\t\t\tsb.append(type == P_NODE ? \"]\" : \")\");\n\t\t}\n\t\t\n\t\tvoid getOrder(List ret) {\n\t\t\tif (type >= 0) {\n\t\t\t\tret.add(type);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (PQNode v : child) {\n\t\t\t\tv.getOrder(ret);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class PQTree {\n\t\t/**\n\t\t * null if there are no permutations\n\t\t */\n\t\tPQNode root;\n\t\tint n;\n\n\t\tpublic PQTree(int n) {\n\t\t\tthis.n = n;\n\t\t\tPQNode[] arr = new PQNode[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = new PQNode(i, null);\n\t\t\t}\n\t\t\troot = makeNode(arr, PQNode.P_NODE);\n\t\t}\n\n\t\tvoid update(boolean[] b) {\n\t\t\tif (root == null) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint cnt = 0;\n\t\t\tfor (boolean flag : b) {\n\t\t\t\tcnt += flag ? 1 : 0;\n\t\t\t}\n\t\t\tif (cnt <= 1 || cnt == b.length) {\n//\t\t\t\tSystem.err.println(\"skipped\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\troot = root.dfs(b, cnt);\n\t\t\t\n//\t\t\tSystem.err.println(this);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\tif (root == null) {\n\t\t\t\treturn \"null\";\n\t\t\t}\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\troot.genRepr(sb);\n\t\t\treturn sb.toString();\n\t\t}\n\t\t\n\t\tList getOrder() {\n\t\t\tList ret = new ArrayList<>(n);\n\t\t\troot.getOrder(ret);\n\t\t\treturn ret;\n\t\t}\n\t}\n\n\tvoid submit() throws IOException {\n//\t\tPQTree tree = new PQTree(6);\n//\t\ttree.update(new boolean[] { true, false, false, false, true, false });\n//\t\ttree.update(new boolean[] { true, true, false, true, true, false });\n//\t\ttree.update(new boolean[] { false, true, true, false, false, true});\n//\t\ttree.update(new boolean[] { false, true, false, false, true, false});\n//\t\ttree.update(new boolean[] { false, false, false, true, false, false});\n//\t\ttree.update(new boolean[] { false, true, true, false, false, true});\n\t\t\n\t\tint n = nextInt();\n\t\tPQTree tree = new PQTree(n);\n\t\tchar[][] f = new char[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tf[i] = nextToken().toCharArray();\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tb[j] = f[i][j] == '1';\n\t\t\t}\n\t\t\ttree.update(b);\n\t\t}\n\t\t\n\t\tif (tree.root == null) {\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tout.println(\"YES\");\n\t\tList order = tree.getOrder();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tout.print(f[i][order.get(j)]);\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\t\n\t}\n\t\n\tstatic final Random rng = new Random();\n\t\n\tint[] genRandomPerm(int n) {\n\t\tint[] p = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint j = rng.nextInt(i + 1);\n\t\t\tp[i] = p[j];\n\t\t\tp[j] = i;\n\t\t}\n\t\treturn p;\n\t}\n\t\n\tvoid oneTest(int n) {\n\t\tint[] p = genRandomPerm(n);\n\t\tchar[][] f = new char[n][n];\n\t\t\n\t\tPQTree t = new PQTree(n);\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(f[i], '0');\n\t\t\tint low = rng.nextInt(n);\n\t\t\tint high = rng.nextInt(n);\n\t\t\tif (low > high) {\n\t\t\t\tint tmp = low;\n\t\t\t\tlow = high;\n\t\t\t\thigh = tmp;\n\t\t\t}\n\t\t\t\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tfor (int j = low; j <= high; j++) {\n\t\t\t\tf[i][p[j]] = '1';\n\t\t\t\tb[p[j]] = true;\n\t\t\t}\n\t\t\t\n\t\t\tt.update(b);\n\t\t}\n\t\t\n\t\tif (t.root == null) {\n\t\t\tSystem.err.println(n);\n\t\t\tSystem.err.println(Arrays.toString(p));\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tSystem.err.println(f[i]);\n\t\t\t}\n\t\t\tthrow new AssertionError();\n\t\t}\n\t}\n\t\n\tvoid stress(int n) {\n\t\tfor (int tst = 0; tst >= 0; tst++) {\n\t\t\toneTest(n);\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\t\n\tvoid test() {\n\t\tPQTree t = new PQTree(5);\n\t\tt.update(new boolean[]{false, false, true, true, false});\n\t\tt.update(new boolean[]{true, true, true, true, false});\n\t\tt.update(new boolean[]{true, true, true, false, true});\n\t}\n\n\tPQTree_test() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n//\t\tstress(100);\n//\t\ttest();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew PQTree_test();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65a8cd1cd50eac2174a4f2e8d3eccf79", "src_uid": "af8d46722e1bd8f7392e5596eaf4def8", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "//package round150;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.List;\nimport java.util.Set;\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\tchar[][] map = nm(n,n);\n\t\t\n\t\tNode root = universal(n);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tSet set = new HashSet<>();\n\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\tif(map[i][j] == '1'){\n\t\t\t\t\tset.add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t\troot = reduce(root, set);\n\t\t}\n\t\tif(root == null){\n\t\t\tout.println(\"NO\");\n\t\t}else{\n\t\t\tout.println(\"YES\");\n\t\t\tList f = root.frontier();\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\tout.print(map[i][f.get(j)]);\n\t\t\t\t}\n\t\t\t\tout.println();\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static enum NodeType\n\t{\n\t\tLEAF, P, Q;\n\t}\n\t\n\tpublic static class Node\n\t{\n\t\tpublic NodeType type; // 0=leaf, 1=P, 2=Q\n\t\tpublic int id;\n\t\tpublic List children;\n\t\t\n\t\tpublic Node(int id) {\n\t\t\tthis.type = NodeType.LEAF;\n\t\t\tthis.id = id;\n\t\t}\n\t\t\n\t\tpublic Node(NodeType type, List children) {\n\t\t\tthis.type = type;\n\t\t\tthis.children = children;\n\t\t}\n\t\t\n\t\tpublic Node reverse()\n\t\t{\n\t\t\tfor(int i = 0, j = children.size()-1;i < j;i++,j--){\n\t\t\t\tNode L = children.get(i);\n\t\t\t\tNode R = children.get(j);\n\t\t\t\tchildren.set(j, L);\n\t\t\t\tchildren.set(i, R);\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\tpublic List frontier()\n\t\t{\n\t\t\tList ret = new ArrayList();\n\t\t\treturn frontierdfs(ret);\n\t\t}\n\t\t\n\t\tprivate List frontierdfs(List f)\n\t\t{\n\t\t\tif(this.type == NodeType.LEAF){\n\t\t\t\tf.add(this.id);\n\t\t\t\treturn f;\n\t\t\t}else{\n\t\t\t\tfor(Node c : this.children)c.frontierdfs(f);\n\t\t\t\treturn f;\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\tif(type == NodeType.LEAF){\n\t\t\t\treturn \"\" + id;\n\t\t\t}else if(type == NodeType.P){\n\t\t\t\tStringBuilder sb = new StringBuilder(\"(\");\n\t\t\t\tassert this.children.size() >= 1;\n\t\t\t\tfor(Node c : this.children){\n\t\t\t\t\tsb.append(c.toString());\n\t\t\t\t\tsb.append(\",\");\n\t\t\t\t}\n\t\t\t\tsb.deleteCharAt(sb.length()-1);\n\t\t\t\tsb.append(\")\");\n\t\t\t\treturn sb.toString();\n\t\t\t}else{\n\t\t\t\tStringBuilder sb = new StringBuilder(\"[\");\n\t\t\t\tassert this.children.size() >= 1;\n\t\t\t\tfor(Node c : this.children){\n\t\t\t\t\tsb.append(c.toString());\n\t\t\t\t\tsb.append(\",\");\n\t\t\t\t}\n\t\t\t\tsb.deleteCharAt(sb.length()-1);\n\t\t\t\tsb.append(\"]\");\n\t\t\t\treturn sb.toString();\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static Node universal(int n)\n\t{\n\t\tNode root = new Node(NodeType.P, new ArrayList());\n\t\tfor(int i = 0;i < n;i++)root.children.add(new Node(i));\n\t\treturn root;\n\t}\n\t\n\tpublic static Node reduce(Node root, Set S)\n\t{\n\t\tif(root == null)return null;\n\t\ttry{\n\t\t\tDFSResult res = dfs(root, S);\n\t\t\treturn res.node;\n\t\t}catch(NoMatchError e){\n\t\t\treturn null;\n\t\t}\n\t}\n\t\n\t@SuppressWarnings(\"serial\")\n\tprivate static class NoMatchError extends Error{};\n\t\n\tprivate static class DFSResult\n\t{\n\t\tNode node;\n\t\tint nins;\n\t\tint des;\n\t\tboolean nomore;\n\t\t\n\t\tpublic DFSResult(Node node, int nins, int des, boolean nomore) {\n\t\t\tthis.node = node;\n\t\t\tthis.nins = nins;\n\t\t\tthis.des = des;\n\t\t\tthis.nomore = nomore;\n\t\t}\n\t}\n\t\n\tpublic static DFSResult dfs(Node root, Set S)\n\t{\n\t\tif(root.type == NodeType.LEAF){\n\t\t\tint ins = S.contains(root.id) ? 1 : 0;\n\t\t\treturn new DFSResult(root, ins, 1, ins == S.size());\n\t\t}else if(root.type == NodeType.P){\n\t\t\tList fulls = new ArrayList<>();\n\t\t\tList empties = new ArrayList<>();\n\t\t\tList partials = new ArrayList<>();\n\t\t\tint nins = 0;\n\t\t\tint des = 0;\n\t\t\tfor(int i = 0;i < root.children.size();i++){\n\t\t\t\tDFSResult res = dfs(root.children.get(i), S);\n\t\t\t\troot.children.set(i, res.node);\n\t\t\t\tif(res.nomore)return new DFSResult(root, -1, -1, true);\n\t\t\t\tnins += res.nins;\n\t\t\t\tdes += res.des;\n\t\t\t\tif(res.nins == res.des){\n\t\t\t\t\tfulls.add(res.node);\n\t\t\t\t}else if(res.nins == 0){\n\t\t\t\t\tempties.add(res.node);\n\t\t\t\t}else{\n\t\t\t\t\tpartials.add(res.node);\n\t\t\t\t\tif(partials.size() > 2)throw new NoMatchError();\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(fulls.size() == root.children.size()){\n\t\t\t\treturn new DFSResult(root, nins, des, nins == S.size());\n\t\t\t}\n\t\t\tif(empties.size() == root.children.size()){\n\t\t\t\treturn new DFSResult(root, 0, des, nins == S.size());\n\t\t\t}\n\t\t\tif(nins == S.size()){\n\t\t\t\t// root = ROOT(T,S)\n\t\t\t\tif(partials.isEmpty()){\n\t\t\t\t\tif(fulls.size() > 1){\n\t\t\t\t\t\troot.children = empties;\n\t\t\t\t\t\tNode f = new Node(NodeType.P, fulls);\n\t\t\t\t\t\troot.children.add(f);\n\t\t\t\t\t}\n\t\t\t\t}else if(partials.size() == 1){\n\t\t\t\t\tassert partials.get(0).type == NodeType.Q;\n\t\t\t\t\tif(fulls.size() >= 1){\n\t\t\t\t\t\troot.children = empties;\n\t\t\t\t\t\troot.children.addAll(partials);\n\t\t\t\t\t\tNode f = fulls.size() > 1 ? new Node(NodeType.P, fulls) : fulls.get(0);\n\t\t\t\t\t\tpartials.get(0).children.add(f); // E-F\n\t\t\t\t\t\tif(root.children.size() == 1){\n\t\t\t\t\t\t\troot = partials.get(0);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}else if(partials.size() == 2){\n\t\t\t\t\tassert partials.get(0).type == NodeType.Q;\n\t\t\t\t\tassert partials.get(1).type == NodeType.Q;\n\t\t\t\t\troot.children = empties;\n\t\t\t\t\troot.children.add(partials.get(0));\n\t\t\t\t\tif(fulls.size() >= 1){\n\t\t\t\t\t\tNode f = fulls.size() > 1 ? new Node(NodeType.P, fulls) : fulls.get(0);\n\t\t\t\t\t\tpartials.get(0).children.add(f); // E-F\n\t\t\t\t\t}\n\t\t\t\t\tpartials.get(0).children.addAll(partials.get(1).reverse().children);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(partials.isEmpty()){\n\t\t\t\t\tNode L = empties.size() > 1 ? new Node(NodeType.P, empties) : empties.get(0);\n\t\t\t\t\tNode R = fulls.size() > 1 ? new Node(NodeType.P, fulls) : fulls.get(0);\n\t\t\t\t\tNode ret = new Node(NodeType.Q, new ArrayList());\n\t\t\t\t\tret.children.add(L);\n\t\t\t\t\tret.children.add(R);\n\t\t\t\t\troot = ret;\n\t\t\t\t}else if(partials.size() == 1){\n\t\t\t\t\tassert partials.get(0).type == NodeType.Q;\n\t\t\t\t\tNode ret = partials.get(0);\n\t\t\t\t\tif(empties.size() >= 1){\n\t\t\t\t\t\tNode e = empties.size() > 1 ? new Node(NodeType.P, empties) : empties.get(0);\n\t\t\t\t\t\tret.children.add(0, e);\n\t\t\t\t\t}\n\t\t\t\t\tif(fulls.size() >= 1){\n\t\t\t\t\t\tNode f = fulls.size() > 1 ? new Node(NodeType.P, fulls) : fulls.get(0);\n\t\t\t\t\t\tret.children.add(f);\n\t\t\t\t\t}\n\t\t\t\t\troot = ret;\n\t\t\t\t}else if(partials.size() == 2){\n\t\t\t\t\tthrow new NoMatchError();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn new DFSResult(root, nins, des, nins == S.size());\n\t\t}else if(root.type == NodeType.Q){\n\t\t\tList fulls = new ArrayList<>();\n\t\t\tList empties = new ArrayList<>();\n\t\t\tList partials = new ArrayList<>();\n\t\t\tint nins = 0;\n\t\t\tint des = 0;\n\t\t\t// EEPFFPEE\n\t\t\tDFSResult[] ress = new DFSResult[root.children.size()];\n\t\t\tint firstF = -1;\n\t\t\tint lastF = -1;\n\t\t\tint lastP = -1;\n\t\t\tfor(int i = 0;i < root.children.size();i++){\n\t\t\t\tDFSResult res = dfs(root.children.get(i), S);\n\t\t\t\troot.children.set(i, res.node);\n\t\t\t\tif(res.nomore)return new DFSResult(root, -1, -1, true);\n\t\t\t\tnins += res.nins;\n\t\t\t\tdes += res.des;\n\t\t\t\tress[i] = res;\n\t\t\t\t\n\t\t\t\tif(res.nins == res.des){\n\t\t\t\t\tif(firstF == -1)firstF = i;\n\t\t\t\t\tlastF = i;\n\t\t\t\t\tfulls.add(res.node);\n\t\t\t\t}else if(res.nins == 0){\n\t\t\t\t\tempties.add(res.node);\n\t\t\t\t}else{\n\t\t\t\t\tlastP = i;\n\t\t\t\t\tpartials.add(res.node);\n\t\t\t\t\tif(partials.size() > 2)throw new NoMatchError();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t// validation\n\t\t\tif(firstF != -1){\n\t\t\t\t// FFF\n\t\t\t\tif(lastF - firstF + 1 != fulls.size())throw new NoMatchError();\n\t\t\t\tint np = 0;\n\t\t\t\tif(firstF - 1 >= 0 && ress[firstF-1].nins > 0)np++;\n\t\t\t\tif(lastF + 1 < root.children.size() && ress[lastF + 1].nins > 0)np++;\n\t\t\t\tif(np != partials.size())throw new NoMatchError();\n\t\t\t}else if(lastP != -1){\n\t\t\t\tif(partials.size() == 2 && !(lastP - 1 >= 0 && ress[lastP - 1].nins > 0))throw new NoMatchError();\n\t\t\t}\n\t\t\t\n\t\t\tif(fulls.size() == root.children.size()){\n\t\t\t\treturn new DFSResult(root, nins, des, nins == S.size());\n\t\t\t}\n\t\t\tif(empties.size() == root.children.size()){\n\t\t\t\treturn new DFSResult(root, 0, des, nins == S.size());\n\t\t\t}\n\t\t\t\n\t\t\tif(nins == S.size()){\n\t\t\t\t// root = ROOT(T,S)\n\t\t\t\tif(partials.isEmpty()){\n\t\t\t\t\t// as is\n\t\t\t\t}else if(partials.size() == 1){\n\t\t\t\t\tassert partials.get(0).type == NodeType.Q;\n\t\t\t\t\tif(fulls.size() >= 1){\n\t\t\t\t\t\tif(lastP == firstF - 1){\n\t\t\t\t\t\t\troot.children.remove(lastP);\n\t\t\t\t\t\t\troot.children.addAll(lastP, partials.get(0).children); // E-F\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\troot.children.remove(lastP);\n\t\t\t\t\t\t\troot.children.addAll(lastP, partials.get(0).reverse().children); // F-E\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}else if(partials.size() == 2){\n\t\t\t\t\tassert partials.get(0).type == NodeType.Q;\n\t\t\t\t\tassert partials.get(1).type == NodeType.Q;\n\t\t\t\t\tint firstP = lastP - fulls.size() - 1;\n\t\t\t\t\troot.children.remove(lastP);\n\t\t\t\t\troot.children.addAll(lastP, partials.get(1).reverse().children); // F-E\n\t\t\t\t\troot.children.remove(firstP);\n\t\t\t\t\troot.children.addAll(firstP, partials.get(0).children); // E-F\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(firstF == -1){\n\t\t\t\t\t// partial only\n\t\t\t\t\tif(partials.size() == 1){\n\t\t\t\t\t\tif(lastP == 0){\n\t\t\t\t\t\t\troot.reverse();\n\t\t\t\t\t\t\tint ind = root.children.size()-1;\n\t\t\t\t\t\t\troot.children.remove(ind);\n\t\t\t\t\t\t\troot.children.addAll(ind, partials.get(0).children); // E-F\n\t\t\t\t\t\t}else if(lastP == root.children.size()-1){\n\t\t\t\t\t\t\tint ind = root.children.size()-1;\n\t\t\t\t\t\t\troot.children.remove(ind);\n\t\t\t\t\t\t\troot.children.addAll(ind, partials.get(0).children); // E-F\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tthrow new NoMatchError();\n\t\t\t\t\t\t}\n\t\t\t\t\t}else{\n\t\t\t\t\t\tthrow new NoMatchError();\n\t\t\t\t\t}\n\t\t\t\t}else if(firstF == 0){\n\t\t\t\t\troot.reverse();\n\t\t\t\t\tif(partials.size() == 1){\n\t\t\t\t\t\tint ind = root.children.size() - 1 - lastP;\n\t\t\t\t\t\troot.children.remove(ind);\n\t\t\t\t\t\troot.children.addAll(ind, partials.get(0).children); // E-F\n\t\t\t\t\t}else if(partials.size() > 1){\n\t\t\t\t\t\tthrow new NoMatchError();\n\t\t\t\t\t}\n\t\t\t\t}else if(lastF == root.children.size() - 1){\n\t\t\t\t\tif(partials.size() == 1){\n\t\t\t\t\t\tint ind = lastP;\n\t\t\t\t\t\troot.children.remove(ind);\n\t\t\t\t\t\troot.children.addAll(ind, partials.get(0).children); // E-F\n\t\t\t\t\t}else if(partials.size() > 1){\n\t\t\t\t\t\tthrow new NoMatchError();\n\t\t\t\t\t}\n\t\t\t\t}else{\n\t\t\t\t\tthrow new NoMatchError();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new DFSResult(root, nins, des, nins == S.size());\n\t\t}else{\n\t\t\tthrow new NoMatchError();\n\t\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 E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "73378466ba2f38e7a124af9d55a6769e", "src_uid": "af8d46722e1bd8f7392e5596eaf4def8", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class PQTree_test {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic PQNode[] collect(PQNode[] arr, int whatStatus) {\n\t\tint sz = 0;\n\t\tfor (PQNode v : arr) {\n\t\t\tif (v.status == whatStatus) {\n\t\t\t\tsz++;\n\t\t\t}\n\t\t}\n\n\t\tPQNode[] ret = new PQNode[sz];\n\t\tint ptr = 0;\n\t\tfor (PQNode v : arr) {\n\t\t\tif (v.status == whatStatus) {\n\t\t\t\tret[ptr++] = v;\n\t\t\t}\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tstatic PQNode makeNode(PQNode[] arr, int whatType) {\n\t\tif (arr.length == 0) {\n\t\t\treturn null;\n\t\t}\n\t\tif (arr.length == 1) {\n\t\t\treturn arr[0];\n\t\t}\n\t\tif (arr.length == 2) {\n\t\t\twhatType = PQNode.Q_NODE;\n\t\t}\n\t\treturn new PQNode(whatType, arr);\n\t}\n\n\tstatic void fullCopy(T[] src, T[] dest, int destPos) {\n\t\tSystem.arraycopy(src, 0, dest, destPos, src.length);\n\t}\n\n\tstatic PQNode[] appendFirst(PQNode v, PQNode[] arr) {\n\t\tif (v == null) {\n\t\t\treturn arr;\n\t\t}\n\t\tPQNode[] ret = new PQNode[arr.length + 1];\n\t\tret[0] = v;\n\t\tfullCopy(arr, ret, 1);\n\t\treturn ret;\n\t}\n\n\tstatic PQNode[] appendLast(PQNode v, PQNode[] arr) {\n\t\tif (v == null) {\n\t\t\treturn arr;\n\t\t}\n\t\tPQNode[] ret = new PQNode[arr.length + 1];\n\t\tfullCopy(arr, ret, 0);\n\t\tret[arr.length] = v;\n\t\treturn ret;\n\t}\n\n\tstatic PQNode[] concat(PQNode[] arr1, PQNode[] arr2) {\n\t\tPQNode[] ret = new PQNode[arr1.length + arr2.length];\n\t\tfullCopy(arr1, ret, 0);\n\t\tfullCopy(arr2, ret, arr1.length);\n\t\treturn ret;\n\t}\n\n\tstatic void reverse(T[] a) {\n\t\tfor (int i = 0, j = a.length - 1; i < j; i++, j--) {\n\t\t\tT tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\t}\n\n\tstatic class PQNode {\n\t\tstatic final int P_NODE = -1;\n\t\tstatic final int Q_NODE = -2;\n\n\t\t/**\n\t\t * < 0 if P or Q node
\n\t\t * otherwise this node is leaf and type is number of element\n\t\t */\n\t\tint type;\n\t\tPQNode[] child;\n\n\t\tpublic PQNode(int type, PQNode[] child) {\n\t\t\tthis.type = type;\n\t\t\tthis.child = child;\n\t\t}\n\n\t\tstatic final int EMPTY = 0;\n\t\tstatic final int FULL = 1;\n\t\tstatic final int PARTIAL = 2;\n\t\tstatic final int CONTAINS_ALL = 3;\n\t\t/**\n\t\t * see above for possible values
\n\t\t * in case of partial, first children are in current query, then not\n\t\t */\n\t\tint status;\n\n\t\t/**\n\t\t * number of leafs from current query in this subtree\n\t\t */\n\t\tint count;\n\n\t\tPQNode dfs(boolean[] b, int allQry) {\n\n\t\t\tif (type >= 0) {\n\t\t\t\tstatus = b[type] ? FULL : EMPTY;\n\t\t\t\tcount = b[type] ? 1 : 0;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tcount = 0;\n\n\t\t\tboolean allFull = true;\n\t\t\tboolean allEmpty = true;\n\t\t\tint cntPartial = 0;\n\t\t\tint[] idxPartial = new int[2];\n\n\t\t\tfor (int i = 0; i < child.length; i++) {\n\t\t\t\tchild[i] = child[i].dfs(b, allQry);\n\t\t\t\tif (child[i] == null) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < child.length; i++) {\n\t\t\t\tPQNode v = child[i];\n\n\t\t\t\tif (v.status == CONTAINS_ALL) {\n\t\t\t\t\tstatus = CONTAINS_ALL;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tallFull &= v.status == FULL;\n\t\t\t\tallEmpty &= v.status == EMPTY;\n\t\t\t\tif (v.status == PARTIAL) {\n\t\t\t\t\tif (cntPartial == 2) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tidxPartial[cntPartial++] = i;\n\t\t\t\t}\n\t\t\t\tcount += v.count;\n\t\t\t}\n\n\t\t\tboolean doesContainAll = count == allQry;\n\n\t\t\tif (allFull) {\n\t\t\t\tstatus = FULL;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tif (allEmpty) {\n\t\t\t\tstatus = EMPTY;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tif (cntPartial <= 1 && type == P_NODE && doesContainAll) {\n\t\t\t\tPQNode[] fulls = collect(child, FULL);\n\t\t\t\tPQNode[] emptys = collect(child, EMPTY);\n\n\t\t\t\tPQNode fullNode = makeNode(fulls, P_NODE);\n\n\t\t\t\tPQNode fullAndPartial;\n\t\t\t\tif (cntPartial == 0) {\n\t\t\t\t\tfullAndPartial = fullNode;\n\t\t\t\t} else {\n\t\t\t\t\tPQNode[] arr = appendFirst(fullNode,\n\t\t\t\t\t\t\tchild[idxPartial[0]].child);\n\t\t\t\t\tfullAndPartial = makeNode(arr, Q_NODE);\n\t\t\t\t}\n\n\t\t\t\tPQNode[] arr = appendFirst(fullAndPartial, emptys);\n\t\t\t\tPQNode ret = makeNode(arr, P_NODE);\n\t\t\t\tret.status = CONTAINS_ALL;\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\t\tif (cntPartial <= 1 && type == P_NODE && !doesContainAll) {\n\t\t\t\tPQNode[] fulls = collect(child, FULL);\n\t\t\t\tPQNode[] emptys = collect(child, EMPTY);\n\n\t\t\t\tPQNode full = makeNode(fulls, P_NODE);\n\t\t\t\tPQNode empty = makeNode(emptys, P_NODE);\n\n\t\t\t\tPQNode ret;\n\t\t\t\tif (cntPartial == 1) {\n\t\t\t\t\tPQNode[] arr = appendFirst(full,\n\t\t\t\t\t\t\tappendLast(empty, child[idxPartial[0]].child));\n\t\t\t\t\tret = makeNode(arr, Q_NODE);\n\t\t\t\t} else {\n\t\t\t\t\tret = makeNode(new PQNode[] { full, empty }, Q_NODE);\n\t\t\t\t}\n\t\t\t\tret.count = count;\n\t\t\t\tret.status = PARTIAL;\n\t\t\t\treturn ret;\n\t\t\t}\n\n\t\t\tif (cntPartial == 2 && type == P_NODE && doesContainAll) {\n\t\t\t\tPQNode[] fulls = collect(child, FULL);\n\t\t\t\tPQNode[] emptys = collect(child, EMPTY);\n\n\t\t\t\tPQNode fullNode = makeNode(fulls, P_NODE);\n\n\t\t\t\treverse(child[idxPartial[0]].child);\n\n\t\t\t\tPQNode[] tmp = appendLast(fullNode, child[idxPartial[0]].child);\n\t\t\t\tPQNode fullAndPartial = makeNode(\n\t\t\t\t\t\tconcat(tmp, child[idxPartial[1]].child), Q_NODE);\n\n\t\t\t\tPQNode[] arr = appendFirst(fullAndPartial, emptys);\n\t\t\t\tPQNode ret = makeNode(arr, P_NODE);\n\t\t\t\tret.status = CONTAINS_ALL;\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t\t\n\t\t\tif (type == Q_NODE) {\n\t\t\t\tint size = child.length;\n\t\t\t\tfor (int i = 0; i < cntPartial; i++) {\n\t\t\t\t\tsize += child[idxPartial[i]].child.length - 1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tPQNode[] arr = new PQNode[size];\n\t\t\t\tint ptr = 0;\n\t\t\t\t\n\t\t\t\tboolean firstPartial = true;\n\t\t\t\tfor (int i = 0; i< child.length; i++) {\n\t\t\t\t\tPQNode v = child[i];\n\t\t\t\t\tif (v.status == PARTIAL) { \n\t\t\t\t\t\t\n\t\t\t\t\t\tboolean shouldRev;\n\t\t\t\t\t\tif (cntPartial == 1) {\n\t\t\t\t\t\t\tif (i == 0) {\n\t\t\t\t\t\t\t\tshouldRev = child[i + 1].status == FULL;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tshouldRev = child[i - 1].status == EMPTY;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tshouldRev = firstPartial;\n\t\t\t\t\t\t\tfirstPartial = !firstPartial;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (shouldRev) {\n\t\t\t\t\t\t\treverse(v.child);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tfor (PQNode u : v.child) {\n\t\t\t\t\t\t\tarr[ptr++] = u;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tarr[ptr++] = v;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (arr[arr.length - 1].status == FULL) {\n\t\t\t\t\treverse(arr);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tptr = arr.length - 1;\n\t\t\t\twhile (ptr >= 0 && arr[ptr].status == EMPTY) {\n\t\t\t\t\tptr--;\n\t\t\t\t}\n\t\t\t\twhile (ptr >= 0 && arr[ptr].status == FULL) {\n\t\t\t\t\tptr--;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (ptr == -1) {\n\t\t\t\t\tPQNode ret = makeNode(arr, Q_NODE);\n\t\t\t\t\tret.count = count;\n\t\t\t\t\tret.status = doesContainAll ? CONTAINS_ALL : PARTIAL;\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\twhile (ptr >= 0 && arr[ptr].status == EMPTY) {\n\t\t\t\t\tptr--;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (ptr == -1 && doesContainAll) {\n\t\t\t\t\tPQNode ret = makeNode(arr, Q_NODE);\n\t\t\t\t\tret.status = CONTAINS_ALL;\n\t\t\t\t\treturn ret;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn null;\n\t\t}\n\n\t\tvoid genRepr(StringBuilder sb) {\n\t\t\tif (type >= 0) {\n\t\t\t\tsb.append(type + \" \");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsb.append(type == P_NODE ? \"[\" : \"(\");\n\t\t\tfor (PQNode v : child) {\n\t\t\t\tv.genRepr(sb);\n\t\t\t}\n\t\t\tsb.append(type == P_NODE ? \"]\" : \")\");\n\t\t}\n\t\t\n\t\tvoid getOrder(List ret) {\n\t\t\tif (type >= 0) {\n\t\t\t\tret.add(type);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (PQNode v : child) {\n\t\t\t\tv.getOrder(ret);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class PQTree {\n\t\t/**\n\t\t * null if there are no permutations\n\t\t */\n\t\tPQNode root;\n\t\tint n;\n\n\t\tpublic PQTree(int n) {\n\t\t\tthis.n = n;\n\t\t\tPQNode[] arr = new PQNode[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = new PQNode(i, null);\n\t\t\t}\n\t\t\troot = makeNode(arr, PQNode.P_NODE);\n\t\t}\n\n\t\tvoid update(boolean[] b) {\n\t\t\tif (root == null) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint cnt = 0;\n\t\t\tfor (boolean flag : b) {\n\t\t\t\tcnt += flag ? 1 : 0;\n\t\t\t}\n\t\t\tif (cnt <= 1 || cnt == b.length) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\troot = root.dfs(b, cnt);\n\t\t\t\n//\t\t\tSystem.err.println(this);\n\t\t\t\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\tif (root == null) {\n\t\t\t\treturn \"null\";\n\t\t\t}\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\troot.genRepr(sb);\n\t\t\treturn sb.toString();\n\t\t}\n\t\t\n\t\tList getOrder() {\n\t\t\tList ret = new ArrayList<>(n);\n\t\t\troot.getOrder(ret);\n\t\t\treturn ret;\n\t\t}\n\t}\n\n\tvoid solve() throws IOException {\n//\t\tPQTree tree = new PQTree(6);\n//\t\ttree.update(new boolean[] { true, false, false, false, true, false });\n//\t\ttree.update(new boolean[] { true, true, false, true, true, false });\n//\t\ttree.update(new boolean[] { false, true, true, false, false, true});\n//\t\ttree.update(new boolean[] { false, true, false, false, true, false});\n//\t\ttree.update(new boolean[] { false, false, false, true, false, false});\n//\t\ttree.update(new boolean[] { false, true, true, false, false, true});\n\t\t\n\t\tint n = nextInt();\n\t\tPQTree tree = new PQTree(n);\n\t\tchar[][] f = new char[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tf[i] = nextToken().toCharArray();\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tb[j] = f[i][j] == '1';\n\t\t\t}\n\t\t\ttree.update(b);\n\t\t}\n\t\t\n\t\tif (tree.root == null) {\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tout.println(\"YES\");\n\t\tList order = tree.getOrder();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tout.print(f[i][order.get(j)]);\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\t\n\t}\n\n\tPQTree_test() 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 PQTree_test();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c545cf1f48a2c651e2457fe47237fa0", "src_uid": "af8d46722e1bd8f7392e5596eaf4def8", "difficulty": 3000.0} {"lang": "Java 7", "source_code": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n char[][] A;\n int[] ans;\n ArrayList[] B;\n int[] inGroup;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n A = new char[N][];\n for (int i = 0; i < N; i++) {\n A[i] = in.nextString().toCharArray();\n }\n\n ArrayList rows = new ArrayList();\n ArrayList cols = new ArrayList();\n for (int i = 0; i < N; i++) {\n rows.add(i);\n cols.add(i);\n }\n ans = new int[N + 1];\n\n B = new ArrayList[N];\n for (int i = 0; i < N; i++) {\n B[i] = new ArrayList();\n for (int j = 0; j < N; j++) {\n if (A[i][j] == '1') {\n B[i].add(j);\n }\n }\n }\n\n inGroup = new int[N];\n if (go(rows, cols)) {\n out.println(\"YES\");\n for (int i = 0; i < N; i++) {\n for (int j = 1; j <= N; j++) {\n out.print(A[i][ans[j]]);\n }\n out.println();\n }\n }\n else {\n out.println(\"NO\");\n }\n }\n\n private boolean go(ArrayList rows, ArrayList cols) {\n if (rows.isEmpty()) {\n for (int col : cols) {\n ans[++ans[0]] = col;\n }\n return true;\n }\n\n int pmax = 0;\n for (int i = 1; i < rows.size(); i++) {\n if (B[rows.get(i)].size() > B[rows.get(pmax)].size()) {\n pmax = i;\n }\n }\n rows.remove(pmax);\n\n ArrayList> groups = new ArrayList>();\n ArrayList ones = new ArrayList();\n ArrayList zeros = new ArrayList();\n split(pmax, cols, ones, zeros);\n groups.add(ones);\n groups.add(zeros);\n\n if (rows.isEmpty()) {\n for (ArrayList gcols : groups) {\n for (int gcol : gcols) {\n ans[++ans[0]] = gcol;\n }\n }\n return true;\n }\n if (ones.isEmpty() || zeros.isEmpty()) {\n return go(rows, cols);\n }\n\n int p = -1;\n int special = groups.get(groups.size() - 1).size();\n while ((p = find(groups, rows)) != -1) {\n rows.remove((Integer) p);\n\n int state = 0;\n boolean maybe = false;\n ArrayList> ngroups = new ArrayList>();\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n ones = new ArrayList();\n zeros = new ArrayList();\n split(p, group, ones, zeros);\n\n if (state == 0) {\n if (!zeros.isEmpty()) ngroups.add(zeros);\n if (!ones.isEmpty()) {\n ngroups.add(ones);\n state = 1;\n }\n }\n else if (state == 1) {\n if (!ones.isEmpty()) ngroups.add(ones);\n if (!zeros.isEmpty()) {\n ngroups.add(zeros);\n state = 2;\n }\n }\n else if (state == 2) {\n if (!zeros.isEmpty()) ngroups.add(zeros);\n if (!ones.isEmpty()) {\n if (i + 1 < groups.size() || special == 0) {\n return false;\n }\n else {\n maybe = true;\n }\n }\n }\n if (i == groups.size() - 1) {\n special -= ones.size();\n }\n }\n\n if (maybe) {\n ngroups = new ArrayList>();\n state = 0;\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n ones = new ArrayList();\n zeros = new ArrayList();\n split(p, group, ones, zeros);\n\n if (i == groups.size() - 1) {\n if (!ones.isEmpty()) ngroups.add(0, ones);\n if (!zeros.isEmpty()) ngroups.add(zeros);\n continue;\n }\n if (!ones.isEmpty()) {\n if (state == 1) return false;\n ngroups.add(ones);\n }\n if (!zeros.isEmpty()) {\n if (state == 0) state = 1;\n ngroups.add(zeros);\n }\n }\n }\n\n groups = ngroups;\n }\n\n ArrayList[] groupRows = new ArrayList[groups.size()];\n for (int i = 0; i < groups.size(); i++) {\n groupRows[i] = new ArrayList();\n }\n for (int r : rows) {\n int f = B[r].get(0);\n int g = inGroup[f];\n groupRows[g].add(r);\n }\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n if (!go(groupRows[i], group)) {\n return false;\n }\n }\n return true;\n }\n\n private int find(ArrayList> groups, ArrayList rows) {\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n for (int col : group) {\n inGroup[col] = i;\n }\n }\n for (int r : rows) {\n for (int j = 1; j < B[r].size(); j++) {\n if (inGroup[ B[r].get(j - 1) ] != inGroup[ B[r].get(j) ]) {\n return r;\n }\n }\n }\n return -1;\n }\n\n private void split(int row, ArrayList cols, ArrayList ones, ArrayList zeros) {\n for (int col : cols) {\n if (A[row][col] == '1') {\n ones.add(col);\n }\n else {\n zeros.add(col);\n }\n }\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n public String nextString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "90f6f3ae10cec1882cb571742239ed2a", "src_uid": "af8d46722e1bd8f7392e5596eaf4def8", "difficulty": 3000.0} {"lang": "Java 7", "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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d0285096dbfc105e379de8f2327e2ba", "src_uid": "169f58dc87d26e0fadde6a83bb623f54", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1fd323e1d9b59756ca1e834ad250fcc3", "src_uid": "169f58dc87d26e0fadde6a83bb623f54", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Andy Phan\n */\npublic class p1173e {\n static int MOD = 998244353;\n static int n;\n static int m;\n static long[] invert;\n static long[][] f;\n static long[][] g;\n static boolean[][] df;\n static boolean[][] dg;\n static int[] sum;\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n n = in.nextInt();\n m = in.nextInt();\n invert = new long[2*m];\n int[] like = new int[n];\n sum = new int[2];\n int[] weight = new int[n];\n for(int i = 0; i < n; i++) like[i] = in.nextInt();\n for(int i = 0; i < n; i++) {\n weight[i] = in.nextInt();\n sum[1-like[i]] += weight[i];\n }\n for(int i = -(m-1); i < m; i++) invert[i+m-1] = modInv(sum[0]+sum[1]+i, MOD);\n f = new long[m][m];\n g = new long[m][m];\n df = new boolean[m][m];\n dg = new boolean[m][m];\n for(int i = 0; i < n; i++) if(like[i] == 0) out.println((g(0, 0)*weight[i])%MOD); else System.out.println((f(0, 0)*weight[i])%MOD);\n out.close();\n }\n \n static long f(int i, int j) {\n if(i+j == m) return 1;\n if(df[i][j]) return f[i][j];\n df[i][j] = true;\n return f[i][j] = (((((sum[0]+i+1)*invert[i-j+m-1])%MOD)*f(i+1, j))%MOD+((((sum[1]-j)*invert[i-j+m-1])%MOD)*f(i, j+1))%MOD)%MOD;\n }\n \n \n static long g(int i, int j) {\n if(i+j == m) return 1;\n if(dg[i][j]) return g[i][j];\n dg[i][j] = true;\n return g[i][j] = (((((sum[0]+i)*invert[i-j+m-1])%MOD)*g(i+1, j))%MOD+((((sum[1]-j-1)*invert[i-j+m-1])%MOD)*g(i, j+1))%MOD)%MOD;\n }\n \n //@\n static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }\n static long lcm(long a, long b) { return a / gcd(a, b) * b; }\n\n \n //@\n // Computes the modular inverse of x\n // Returns 0 if the GCD of x and mod is not 1\n // O(log n) : Can be converted to use BigIntegers\n static long modInv(long x, long mod) {\n if(x == 1) return 1;\n if(gcd(x, mod) != 1) return 0;\n long r = mod % x;\n return (modInv(r, x % r, 0, 1, mod / x, x / r)+mod)%mod;\n }\n\n static long modInv(long a, long b, long y0, long y1, long q0, long q1) {\n long y2 = y0 - y1*q0;\n return b == 0 ? y2 : modInv(b, a % b, y1, y2, q1, a / b);\n }\n static class FS {\n BufferedReader in;\n StringTokenizer t;\n \n public FS(InputStream i) {\n in = new BufferedReader(new InputStreamReader(i));\n }\n \n public String next() {\n try {\n while(t == null || !t.hasMoreElements()) {\n t = new StringTokenizer(in.readLine());\n }\n } catch(Exception e) {}\n return t.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "52ada3b769ed6bd4ffeeee623e5bf8ce", "src_uid": "ba9c136f84375cd317f0f8b53e3939c7", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Andy Phan\n */\npublic class p1173e {\n static int MOD = 998244353;\n static int n;\n static int m;\n static long[] invert;\n static long[][] f;\n static long[][] g;\n static boolean[][] df;\n static boolean[][] dg;\n static int[] sum;\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n n = in.nextInt();\n m = in.nextInt();\n invert = new long[2*m];\n int[] like = new int[n];\n sum = new int[2];\n int[] weight = new int[n];\n for(int i = 0; i < n; i++) like[i] = in.nextInt();\n for(int i = 0; i < n; i++) {\n weight[i] = in.nextInt();\n sum[1-like[i]] += weight[i];\n }\n for(int i = -(m-1); i < m; i++) invert[i+m-1] = modInv(sum[0]+sum[1]+i, MOD);\n f = new long[m][m];\n g = new long[m][m];\n df = new boolean[m][m];\n dg = new boolean[m][m];\n for(int i = 0; i < n; i++) if(like[i] == 0) out.println((g(0, 0)*weight[i])%MOD); else out.println((f(0, 0)*weight[i])%MOD);\n out.close();\n }\n \n static long f(int i, int j) {\n if(i+j == m) return 1;\n if(df[i][j]) return f[i][j];\n df[i][j] = true;\n return f[i][j] = (((((sum[0]+i+1)*invert[i-j+m-1])%MOD)*f(i+1, j))%MOD+((((sum[1]-j)*invert[i-j+m-1])%MOD)*f(i, j+1))%MOD)%MOD;\n }\n \n \n static long g(int i, int j) {\n if(i+j == m) return 1;\n if(dg[i][j]) return g[i][j];\n dg[i][j] = true;\n return g[i][j] = (((((sum[0]+i)*invert[i-j+m-1])%MOD)*g(i+1, j))%MOD+((((sum[1]-j-1)*invert[i-j+m-1])%MOD)*g(i, j+1))%MOD)%MOD;\n }\n \n //@\n static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }\n static long lcm(long a, long b) { return a / gcd(a, b) * b; }\n\n \n //@\n // Computes the modular inverse of x\n // Returns 0 if the GCD of x and mod is not 1\n // O(log n) : Can be converted to use BigIntegers\n static long modInv(long x, long mod) {\n if(x == 1) return 1;\n if(gcd(x, mod) != 1) return 0;\n long r = mod % x;\n return (modInv(r, x % r, 0, 1, mod / x, x / r)+mod)%mod;\n }\n\n static long modInv(long a, long b, long y0, long y1, long q0, long q1) {\n long y2 = y0 - y1*q0;\n return b == 0 ? y2 : modInv(b, a % b, y1, y2, q1, a / b);\n }\n static class FS {\n BufferedReader in;\n StringTokenizer t;\n \n public FS(InputStream i) {\n in = new BufferedReader(new InputStreamReader(i));\n }\n \n public String next() {\n try {\n while(t == null || !t.hasMoreElements()) {\n t = new StringTokenizer(in.readLine());\n }\n } catch(Exception e) {}\n return t.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd16929cc310245867ca47ae4b16d430", "src_uid": "ba9c136f84375cd317f0f8b53e3939c7", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "package com.jardon.pg.algorithm.codeforce.r4xx.r480;\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.PriorityQueue;\nimport java.util.StringTokenizer;\n\nimport static java.util.Collections.reverse;\n\n/**\n * @author Don Li\n */\npublic class CactusToTree {\n \n int N = (int) 5e5 + 10;\n \n int n, m;\n int[][][] G;\n \n int timer = 0;\n int[] tin = new int[N], low = new int[N];\n boolean[] bridge = new boolean[N * 2];\n \n int nc = 0;\n boolean[] vis = new boolean[N];\n int[] vertex_to_cycle = new int[N];\n List[] cycle = new List[N];\n \n int[] par = new int[N]; \n int[] len = new int[N]; \n int[] L = new int[N]; \n int[] Z = new int[N]; \n \n void solve() {\n n = in.nextInt(); m = in.nextInt();\n int[] fr = new int[m], to = new int[m], wt = new int[m];\n for (int i = 0; i < m; i++) {\n fr[i] = in.nextInt() - 1;\n to[i] = in.nextInt() - 1;\n wt[i] = i;\n }\n G = build_graph(n, fr, to, wt);\n \n mark_bridges(0, -1);\n \n for (int i = 0; i < n; i++) {\n if (!vis[i]) {\n cycle[nc] = new ArrayList<>();\n dfs(i, nc++);\n }\n }\n \n create_spanning_tree_and_init_l(0);\n \n solve_cycle(0, -1, 0);\n \n for (int i = 0; i < n; i++) {\n if (i > 0) out.print(' ');\n out.print(Math.max(L[i], Z[i]));\n }\n }\n \n void solve_cycle(int u, int p, int carry) {\n L[u] = Math.max(L[u], carry);\n \n int id = vertex_to_cycle[u]; int k = cycle[id].size();\n for (int it = 0; it < 2; it++) {\n PriorityQueue qu = new PriorityQueue<>((a, b) -> {\n if (a[0] != b[0]) return -Integer.compare(a[0], b[0]);\n return -Integer.compare(a[1], b[1]);\n });\n for (int i = 0; i < 2 * k; i++) {\n int d = 2 * k - i;\n while (!qu.isEmpty() && qu.peek()[1] > d + k / 2) qu.poll();\n if (!qu.isEmpty()) Z[cycle[id].get(i % k)] = Math.max(Z[cycle[id].get(i % k)], qu.peek()[0] - d);\n qu.offer(new int[]{L[cycle[id].get(i % k)] + d, d});\n }\n reverse(cycle[id]);\n }\n \n for (int v : cycle[id]) {\n int fi = 0, se = 0;\n for (int[] t : G[v]) {\n int w = t[0], e = t[1];\n if (w != p && bridge[e]) {\n if (fi < 1 + len[w]) {\n se = fi;\n fi = 1 + len[w];\n } else if (se < 1 + len[w]) {\n se = 1 + len[w];\n }\n }\n }\n for (int[] t : G[v]) {\n int w = t[0], e = t[1];\n if (w != p && bridge[e]) {\n int passValue = Math.max(carry, Z[v]);\n if (1 + len[w] == fi) passValue = Math.max(passValue, se);\n else passValue = Math.max(passValue, fi);\n solve_cycle(w, v, passValue + 1);\n }\n }\n }\n }\n \n void create_spanning_tree_and_init_l(int s) {\n int[] qu = new int[n]; boolean[] inq = new boolean[n];\n int qh = 0, qt = 0;\n qu[qt++] = s;\n inq[s] = true;\n par[s] = -1;\n while (qh < qt) {\n int u = qu[qh++];\n for (int[] t : G[u]) {\n int v = t[0];\n if (!inq[v]) {\n qu[qt++] = v;\n inq[v] = true;\n par[v] = u;\n }\n }\n }\n \n for (int i = n - 1; i >= 0; i--) {\n int u = qu[i];\n for (int[] t : G[u]) {\n int v = t[0], e = t[1];\n if (par[v] == u) {\n len[u] = Math.max(len[u], len[v] + 1);\n if (bridge[e]) L[u] = Math.max(L[u], len[v] + 1);\n }\n }\n }\n }\n \n void dfs(int u, int id) {\n vis[u] = true;\n vertex_to_cycle[u] = id;\n cycle[id].add(u);\n for (int[] t : G[u]) {\n int v = t[0], e = t[1];\n if (!bridge[e] && !vis[v]) {\n dfs(v, id);\n }\n }\n }\n \n void mark_bridges(int u, int p) {\n low[u] = tin[u] = ++timer;\n for (int[] t : G[u]) {\n int v = t[0], e = t[1];\n if (tin[v] == 0) {\n mark_bridges(v, u);\n low[u] = Math.min(low[u], low[v]);\n if (low[v] > tin[u]) bridge[e] = true;\n } else if (v != p) {\n low[u] = Math.min(low[u], tin[v]);\n }\n }\n }\n \n int[][][] build_graph(int n, int[] from, int[] to, int[] weight) {\n int[][][] G = new int[n][][];\n int[] cnt = new int[n];\n for (int i = 0; i < from.length; i++) {\n cnt[from[i]]++;\n cnt[to[i]]++;\n }\n for (int i = 0; i < n; i++) G[i] = new int[cnt[i]][];\n for (int i = 0; i < from.length; i++) {\n G[from[i]][--cnt[from[i]]] = new int[]{to[i], weight[i]};\n G[to[i]][--cnt[to[i]]] = new int[]{from[i], weight[i]};\n }\n return G;\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 CactusToTree().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e405b336624fb6a0627e4ae9c212eefc", "src_uid": "c980495a264a6314f45c230daf19c2e0", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\nimport static java.util.Collections.reverse;\n\n/**\n * @author Don Li\n */\npublic class CactusToTree {\n \n int N = (int) 5e5 + 10;\n \n int n, m;\n int[][][] G;\n \n int timer = 0;\n int[] tin = new int[N], low = new int[N];\n boolean[] bridge = new boolean[N * 2];\n \n int nc = 0;\n boolean[] vis = new boolean[N];\n int[] vertex_to_cycle = new int[N];\n List[] cycle = new List[N];\n \n int[] par = new int[N]; \n int[] len = new int[N]; \n int[] L = new int[N]; \n int[] Z = new int[N]; \n \n void solve() {\n n = in.nextInt(); m = in.nextInt();\n int[] fr = new int[m], to = new int[m], wt = new int[m];\n for (int i = 0; i < m; i++) {\n fr[i] = in.nextInt() - 1;\n to[i] = in.nextInt() - 1;\n wt[i] = i;\n }\n G = build_graph(n, fr, to, wt);\n \n mark_bridges(0, -1);\n \n for (int i = 0; i < n; i++) {\n if (!vis[i]) {\n cycle[nc] = new ArrayList<>();\n dfs(i, nc++);\n }\n }\n \n create_spanning_tree_and_init_l(0);\n \n solve_cycle(0, -1, 0);\n \n for (int i = 0; i < n; i++) {\n if (i > 0) out.print(' ');\n out.print(Math.max(L[i], Z[i]));\n }\n }\n \n void solve_cycle(int u, int p, int carry) {\n L[u] = Math.max(L[u], carry);\n \n int id = vertex_to_cycle[u]; int k = cycle[id].size();\n for (int it = 0; it < 2; it++) {\n PriorityQueue qu = new PriorityQueue<>((a, b) -> {\n if (a[0] != b[0]) return -Integer.compare(a[0], b[0]);\n return -Integer.compare(a[1], b[1]);\n });\n for (int i = 0; i < 2 * k; i++) {\n int d = 2 * k - i;\n while (!qu.isEmpty() && qu.peek()[1] > d + k / 2) qu.poll();\n if (!qu.isEmpty()) Z[cycle[id].get(i % k)] = Math.max(Z[cycle[id].get(i % k)], qu.peek()[0] - d);\n qu.offer(new int[]{L[cycle[id].get(i % k)] + d, d});\n }\n reverse(cycle[id]);\n }\n \n for (int v : cycle[id]) {\n int fi = 0, se = 0;\n for (int[] t : G[v]) {\n int w = t[0], e = t[1];\n if (w != p && bridge[e]) {\n if (fi < 1 + len[w]) {\n se = fi;\n fi = 1 + len[w];\n } else if (se < 1 + len[w]) {\n se = 1 + len[w];\n }\n }\n }\n for (int[] t : G[v]) {\n int w = t[0], e = t[1];\n if (w != p && bridge[e]) {\n int passValue = Math.max(carry, Z[v]);\n if (1 + len[w] == fi) passValue = Math.max(passValue, se);\n else passValue = Math.max(passValue, fi);\n solve_cycle(w, v, passValue + 1);\n }\n }\n }\n }\n \n void create_spanning_tree_and_init_l(int s) {\n int[] qu = new int[n]; boolean[] inq = new boolean[n];\n int qh = 0, qt = 0;\n qu[qt++] = s;\n inq[s] = true;\n par[s] = -1;\n while (qh < qt) {\n int u = qu[qh++];\n for (int[] t : G[u]) {\n int v = t[0];\n if (!inq[v]) {\n qu[qt++] = v;\n inq[v] = true;\n par[v] = u;\n }\n }\n }\n \n for (int i = n - 1; i >= 0; i--) {\n int u = qu[i];\n for (int[] t : G[u]) {\n int v = t[0], e = t[1];\n if (par[v] == u) {\n len[u] = Math.max(len[u], len[v] + 1);\n if (bridge[e]) L[u] = Math.max(L[u], len[v] + 1);\n }\n }\n }\n }\n \n void dfs(int u, int id) {\n vis[u] = true;\n vertex_to_cycle[u] = id;\n cycle[id].add(u);\n for (int[] t : G[u]) {\n int v = t[0], e = t[1];\n if (!bridge[e] && !vis[v]) {\n dfs(v, id);\n }\n }\n }\n \n void mark_bridges(int u, int p) {\n low[u] = tin[u] = ++timer;\n for (int[] t : G[u]) {\n int v = t[0], e = t[1];\n if (tin[v] == 0) {\n mark_bridges(v, u);\n low[u] = Math.min(low[u], low[v]);\n if (low[v] > tin[u]) bridge[e] = true;\n } else if (v != p) {\n low[u] = Math.min(low[u], tin[v]);\n }\n }\n }\n \n int[][][] build_graph(int n, int[] from, int[] to, int[] weight) {\n int[][][] G = new int[n][][];\n int[] cnt = new int[n];\n for (int i = 0; i < from.length; i++) {\n cnt[from[i]]++;\n cnt[to[i]]++;\n }\n for (int i = 0; i < n; i++) G[i] = new int[cnt[i]][];\n for (int i = 0; i < from.length; i++) {\n G[from[i]][--cnt[from[i]]] = new int[]{to[i], weight[i]};\n G[to[i]][--cnt[to[i]]] = new int[]{from[i], weight[i]};\n }\n return G;\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 CactusToTree().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f11081dcaca403c369268da35cb3557c", "src_uid": "c980495a264a6314f45c230daf19c2e0", "difficulty": 2900.0} {"lang": "Java 7", "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 g = new TreeMap();\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "37897a996b577e28c3072dbcfe9c909c", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CF273E {\n\n final static long mod = 1000000007;\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int p = in.nextInt();\n ArrayList starts = new ArrayList();\n ArrayList gs = new ArrayList();\n starts.add(0L);\n gs.add(0);\n starts.add(3L);\n gs.add(1);\n long u = 3, v = 1;\n for (int j1 = 0, j2 = 0; u < p; ) {\n while (starts.get(j1 + 1) <= u / 3) {\n ++j1;\n }\n while (starts.get(j2 + 1) <= u - u / 3) {\n ++j2;\n }\n long next1 = starts.get(j1 + 1) * 3;\n if (next1 / 3 < starts.get(j1 + 1) || (next1 - 1) / 3 >= starts.get(j1 + 1)) {\n throw new AssertionError();\n }\n long next2 = (starts.get(j2 + 1) * 3) / 2;\n while (next2 - next2 / 3 < starts.get(j1 + 1)) {\n next2++;\n }\n while (next2 - 1 - (next2 - 1) / 3 >= starts.get(j2 + 1)) {\n next2--;\n }\n if (next2 - next2 / 3 < starts.get(j2 + 1) || next2 - 1 - (next2 - 1) / 3 >= starts.get(j2 + 1)) {\n throw new AssertionError();\n }\n long next = Math.min(next1, next2);\n int val = mutex(gs.get(next >= next1 ? j1 + 1 : j1), gs.get(next >= next2 ? j2 + 1 : j2));\n if (val != v) {\n starts.add(next);\n gs.add(val);\n }\n u = next;\n v = val;\n }\n// System.err.println(starts.size());\n long[] c = new long[3];\n for (int i = 0; i < starts.size(); ++i) {\n long from = starts.get(i);\n long to = i == starts.size() - 1 ? p - 1 : starts.get(i + 1) - 1;\n if (to >= p) {\n to = p - 1;\n }\n if (from > to) {\n continue;\n }\n// System.err.println(from + \" \" + to + \" \" + gs.get(i));\n// System.err.println((to - from + 1) * p);\n// System.err.println(to * (to + 1) / 2);\n// System.err.println((from - 1) * (from) / 2);\n c[gs.get(i)] = (c[gs.get(i)] + (to - from + 1) * p) % mod;\n c[gs.get(i)] = (c[gs.get(i)] + mod - (to * (to + 1) / 2 % mod)) % mod;\n c[gs.get(i)] = (c[gs.get(i)] + (from - 1) * (from) / 2) % mod;\n }\n c[0] = (c[0] + mod - p) % mod;\n// for (int i = 1; i < p; ++i) {\n// c[g[i]] = (c[g[i]] + p - i) % mod;\n// }\n long[] d = new long[4];\n d[0] = 1;\n for (int it = 0; it < n; ++it) {\n long[] dd = new long[4];\n for (int i = 0; i < 4; ++i) {\n for (int j = 0; j < 3; ++j) {\n dd[i ^ j] = (dd[i ^ j] + d[i] * c[j]) % mod;\n }\n }\n d = dd;\n }\n long ans = (d[1] + d[2] + d[3]) % mod;\n out.println(ans);\n }\n\n private static int mutex(int a, int b) {\n if (a != 0 && b != 0) return 0;\n if (a != 1 && b != 1) return 1;\n return 2;\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringTokenizer st;\n\n public Input(BufferedReader in) {\n this.in = in;\n eat(\"\");\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public void eat(String str) {\n st = new StringTokenizer(str);\n }\n\n public String next() throws IOException {\n while (!st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null) {\n return null;\n }\n eat(line);\n }\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2468bbbd9dff1be90f4cc09873ad4397", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.SortedMap;\nimport java.util.Map;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.TreeMap;\nimport java.util.InputMismatchException;\nimport java.util.Set;\nimport java.util.NavigableMap;\nimport java.io.Reader;\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 int[] g;\n static int MAXN = 1000;\n\n static {\n g = new int[MAXN];\n for (int i = 3; i < g.length; i++) {\n int g1 = g[i / 3];\n int g2 = g[i - i / 3];\n for (int j = 0; j < 3; j++) {\n if (g1 == j || g2 == j) {\n continue;\n }\n g[i] = j;\n break;\n }\n System.out.print(g[i]);\n }\n System.out.println();\n for (int i = 3; i < g.length; i++) {\n System.out.print(i % 10);\n }\n }\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 g = new TreeMap();\n g.put(1, 0);\n g.put(3, 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 if (na == null || nb == null) {\n throw new AssertionError();\n }\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 g.put(zi, 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "df18e36ba0ad9be7eb7e0649fca37e99", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0", "difficulty": 2600.0} {"lang": "Java 7", "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 g = new TreeMap();\n g.put(1, 0);\n g.put(3, 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 if (na == null || nb == null) {\n throw new AssertionError();\n }\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 g.put(zi, 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d35ccd4b298beac792a7b4fa6d8e8fb2", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.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.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint d = nextInt();\n\t\tint mod = nextInt();\n\t\tif (n == 1) {\n\t\t\tout.print('1');\n\t\t\treturn;\n\t\t}\n\t\tint fracs[] = new int[d + 2];\n\t\tfor (int i = 1; i < fracs.length; i++) {\n\t\t\tfracs[i] = BigInteger.valueOf(i).modInverse(BigInteger.valueOf(mod)).intValue();\n\t\t}\n\t\tint maxsize = n;\n\t\tint cnts[] = new int[maxsize + 1];\n\t\tcnts[1] = 1;\n\t\tint cnts2[][][] = new int[maxsize + 1][d + 1][maxsize + 1];\n\t\tcnts2[0][0][1] = 1;\n\t\tfor (int lastsize = 0; lastsize < (n - 1) / 2; lastsize++) {\n\t\t\tint nlastsize = lastsize + 1;\n\t\t\tint ccnt = cnts[nlastsize];\n\t\t\tint ccnt2[][] = cnts2[lastsize];\n\t\t\tint ncnt2[][] = cnts2[nlastsize];\n\t\t\tfor (int ctrees = 0; ctrees <= d; ctrees++) {\n\t\t\t\tfor (int csize = 1; csize <= maxsize; csize++) {\n\t\t\t\t\tint cur = ccnt2[ctrees][csize];\n//\t\t\t\t\tif (cur != 0) {\n//\t\t\t\t\t\tSystem.err.println(csize + \" \" + ctrees + \" \" + lastsize + \" -> \" + cur);\n//\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0, ntrees = ctrees, nsize = csize;\n\t\t\t\t\t\tntrees <= d && nsize <= maxsize;\n\t\t\t\t\t\t++i, ++ntrees, nsize += nlastsize) {\n\t\t\t\t\t\tncnt2[ntrees][nsize] += cur;\n\t\t\t\t\t\tif (ncnt2[ntrees][nsize] >= mod) {\n\t\t\t\t\t\t\tncnt2[ntrees][nsize] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcur = (int) ((long) cur * (ccnt + i) % mod * fracs[i + 1] % mod);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (nlastsize + 1 <= maxsize) {\n\t\t\t\tcnts[nlastsize + 1] = ncnt2[d - 1][nlastsize + 1];\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tif (n % 2 == 0) {\n\t\t\tans = (int) ((long) cnts[n / 2] * (cnts[n / 2] + 1) % mod * fracs[2] % mod);\n\t\t}\n\t\tans = (ans + cnts2[(n - 1) / 2][d][n]) % mod;\n\t\tout.print(ans);\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b3dd3ee994f4f5f85d99cfcc9b5fcc3e", "src_uid": "bdd0fc1d6dbab5eeb5aea135fdfffc9d", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c78388256e59062dc1c642b3cf85d7e", "src_uid": "49eb534fb5cf4634c770f00e22528e19", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.HashMap;\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 lewin\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskH solver = new TaskH();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskH {\n long all;\n int d;\n int m;\n int[] gen;\n int bits = 8;\n int sections;\n HashMap[][] mp;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n d = in.nextInt();\n m = in.nextInt();\n sections = (m + bits - 1) / bits;\n all = (1L << m) - 1;\n gen = in.readIntArray(d);\n int n = in.nextInt();\n ArrayList masks = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n masks.add((1L << (in.nextInt() + 1)) - 1);\n }\n long l = in.nextLong(), r = in.nextLong();\n l-=1;\n r-=1;\n mp = new HashMap[sections][1 << bits];\n for (int i = 0; i < sections; i++) for (int j = 0; j < 1 << bits; j++) mp[i][j] = new HashMap<>();\n out.println(count(masks, r + 2 - n) - count(masks, l));\n }\n\n long rotateRight(long x, int distance) {\n return ((x >> distance) | ((x & ((1L << distance) - 1)) << (m - distance)));\n }\n\n ArrayList getNext(int shift, int section, int mask) {\n long cmask = mask;\n cmask <<= (long) section * bits;\n cmask = rotateRight(cmask, shift);\n ArrayList ret = new ArrayList<>();\n for (int i = 0; i < sections; i++) {\n int csec = (int) (cmask & ((1 << bits) - 1));\n if (csec != 0) {\n ret.add(new int[]{i, csec});\n }\n cmask >>= bits;\n }\n return ret;\n }\n\n long count(int section, int mask, long mx) {\n if (mx == 0) return 0;\n if (mx == 1) {\n return (section == 0 && ((mask & 1) == 1)) ? 1 : 0;\n }\n Long r = mp[section][mask].get(mx);\n if (r != null) return r;\n long bd = 1;\n while (bd < (mx + d - 1) / d) bd *= d;\n\n long ans = 0;\n for (int i = 0; i < (mx + bd - 1) / bd; i++) {\n long nmx = (i == (mx + bd - 1) / bd - 1) ? ((mx - 1) % bd + 1) : bd;\n for (int[] x : getNext(gen[i], section, mask)) {\n ans += count(x[0], x[1], nmx);\n }\n }\n mp[section][mask].put(mx, ans);\n return ans;\n }\n\n long count(ArrayList masks, long mx) {\n if (masks.size() == 1) {\n long ans = 0;\n long mask = masks.get(0);\n for (int j = 0; j < sections; j++) {\n ans += count(j, (int) (mask & ((1 << bits) - 1)), mx);\n mask >>= bits;\n }\n return ans;\n }\n long ans = 0;\n for (int start = 0; start < d && start < mx; start++) {\n ArrayList nextmask = new ArrayList<>();\n long cmask = all;\n int cp = start;\n for (int i = 0; i < masks.size(); i++) {\n if (i > 0 && cp == 0) {\n nextmask.add(cmask);\n cmask = all;\n }\n cmask &= rotateRight(masks.get(i), gen[cp]);\n if (++cp == d) cp = 0;\n }\n nextmask.add(cmask);\n ans += count(nextmask, (mx - start + d - 1) / d);\n }\n return ans;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int[] readIntArray(int tokens) {\n int[] ret = new int[tokens];\n for (int i = 0; i < tokens; i++) {\n ret[i] = nextInt();\n }\n return ret;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public long nextLong() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n long res = 0L;\n\n while (c >= 48 && c <= 57) {\n res *= 10L;\n res += (long) (c - 48);\n c = this.read();\n if (isSpaceChar(c)) {\n return res * (long) sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n\n }\n\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d6c76c653aa368f1af90ec606aacb5e9", "src_uid": "49eb534fb5cf4634c770f00e22528e19", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\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 tarek\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 HMateuszAndAnInfiniteSequence solver = new HMateuszAndAnInfiniteSequence();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class HMateuszAndAnInfiniteSequence {\n long[] lens;\n Description[] cache;\n int m;\n int[] b;\n int[] gen;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int d = in.readInt();\n m = in.readInt();\n gen = new int[d];\n for (int i = 0; i < d; ++i) gen[i] = in.readInt();\n int blen = in.readInt();\n b = new int[blen];\n for (int i = 0; i < blen; ++i) {\n b[i] = in.readInt();\n }\n long left = in.readLong();\n long right = in.readLong();\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.printLine(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 OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public 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 long readLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "17822f3e0fd2cf0d79ff848eb36e1288", "src_uid": "49eb534fb5cf4634c770f00e22528e19", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "/*\r\nI am dead inside\r\nDo you like NCT, sKz, BTS?\r\n5 4 3 2 1 Moonwalk\r\nImma knock it down like domino\r\nIs this what you want? Is this what you want?\r\nLet's ttalkbocky about that\r\n */\r\nimport static java.lang.Math.*;\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class lolE\r\n{\r\n static String target = \"theseus\";\r\n static 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 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 boolean[][] dp = new boolean[N][N];\r\n for(int r=0; r < N; r++)\r\n Arrays.fill(dp[r], true);\r\n for(int t=0; t < 7; t++)\r\n {\r\n boolean[][] next = new boolean[N][N];\r\n for(int r=0; r < N; r++)\r\n for(int c=0; c < N; c++)\r\n if(grid[r][c] == target.charAt(t))\r\n {\r\n for(int d=0; d < 8; d++)\r\n {\r\n int x = r+dx[d];\r\n int y = c+dy[d];\r\n if(min(x,y) >= 0 && max(x,y) < N && dp[x][y])\r\n next[r][c] = true;\r\n }\r\n }\r\n dp = next;\r\n }\r\n String res = \"NO\";\r\n for(int r=0; r < N; r++)\r\n for(int c=0; c < N; c++)\r\n if(dp[r][c])\r\n res = \"YES\";\r\n System.out.println(res);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9b2adaa536ddf804f185af99cdd6e1c2", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0", "difficulty": -1.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\r\n\r\npublic class Main {\r\n public static void main(String[] args) {\r\n Scanner input = new Scanner(System.in);\r\n int n = input.nextInt();\r\n String[] str = new String[n];\r\n for (int i = 0; i < n; i++) {\r\n str[i] = input.next();\r\n }\r\n if(n < 14)\r\n System.out.println(\"YES\");\r\n else\r\n System.out.println(\"NO\");\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "677e510dc79c3a5376596b78b1702a58", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0", "difficulty": -1.0} {"lang": "Java 8", "source_code": "/*\r\nI am dead inside\r\nDo you like NCT, sKz, BTS?\r\n5 4 3 2 1 Moonwalk\r\nImma knock it down like domino\r\nIs this what you want? Is this what you want?\r\nLet's ttalkbocky about that\r\n */\r\nimport static java.lang.Math.*;\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class lolE\r\n{\r\n static String target = \"theseus\";\r\n static String reverse = \"sueseth\";\r\n //static int[] dx = {-1, 1, 0, 0, -1, -1, 1, 1};\r\n //static int[] dy = {0, 0, -1, 1, -1, 1, -1, 1};\r\n //static int[] dx = {0, 1, 1};\r\n //static int[] dy = {1, 0, 1};\r\n public static void main(String omkar[]) throws Exception\r\n {\r\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st = new StringTokenizer(infile.readLine());\r\n int N = Integer.parseInt(st.nextToken());\r\n char[][] grid = new char[N][N];\r\n for(int r=0; r < N; r++)\r\n grid[r] = infile.readLine().trim().toCharArray();\r\n String res = \"NO\";\r\n for(int r=0; r < N; r++)\r\n for(int c=0; c < N-6; c++)\r\n {\r\n String temp = \"\";\r\n for(int i=c; i < c+7; i++)\r\n temp += grid[r][i];\r\n if(temp.equals(target))\r\n res = \"YES\";\r\n }\r\n for(int c=0; c < N; c++)\r\n for(int r=0; r < N-6; r++)\r\n {\r\n String temp = \"\";\r\n for(int i=r; i < r+7; i++)\r\n temp += grid[i][c];\r\n if(temp.equals(target))\r\n res = \"YES\";\r\n }\r\n //diagonals\r\n for(int r=0; r < N; r++)\r\n for(int c=0; c < N; c++)\r\n {\r\n String temp = \"\";\r\n int lol = 0;\r\n while(temp.length() < 7)\r\n {\r\n if(max(r, c)+lol >= N)\r\n break;\r\n temp += grid[r+lol][c+lol];\r\n lol++;\r\n }\r\n if(temp.equals(target))\r\n res = \"YES\";\r\n }\r\n System.out.println(res);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "61b7530c2be82d05baf850e29d39e02d", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0", "difficulty": -1.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n long mod = (long) 1e9 + 7;\n\n class Num {\n final long a, b;\n\n public Num(long a, long b) {\n this.a = a % mod;\n this.b = b % mod;\n }\n\n public Num add(Num other) {\n return new Num(a + other.a, b + other.b);\n }\n\n public Num multiply(Num other) {\n return new Num(a * other.a + 5 * b * other.b, a * other.b + b * other.a);\n }\n }\n\n int k;\n\n long[][] coeffs;\n\n void prepare() {\n coeffs = new long[k + 1][k + 1];\n long[][] tmpCoeffs = new long[k + 1][k + 1];\n long factK = 1;\n coeffs[0][0] = 1;\n\n for (int free = 0; free < k; free++) {\n factK = factK * (free + 1) % mod;\n\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n if (coeffs[i][j] != 0) {\n tmpCoeffs[i + 1][j] += coeffs[i][j];\n if (tmpCoeffs[i + 1][j] >= mod) {\n tmpCoeffs[i + 1][j] -= mod;\n }\n\n tmpCoeffs[i][j + 1] += coeffs[i][j];\n if (tmpCoeffs[i][j + 1] >= mod) {\n tmpCoeffs[i][j + 1] -= mod;\n }\n\n long add = coeffs[i][j] * (mod - free) % mod;\n tmpCoeffs[i][j] += add;\n if (tmpCoeffs[i][j] >= mod) {\n tmpCoeffs[i][j] -= mod;\n }\n }\n }\n }\n\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n coeffs[i][j] = tmpCoeffs[i][j];\n tmpCoeffs[i][j] = 0;\n }\n }\n }\n\n factK = inv(factK);\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n coeffs[i][j] = coeffs[i][j] * factK % mod;\n }\n }\n System.err.println(Arrays.deepToString(coeffs));\n\n pow1 = new Num[k + 1];\n powA = new Num[k + 1];\n pow2 = new Num[k + 1];\n powB = new Num[k + 1];\n\n\n pow1[0] = pow2[0] = powA[0] = powB[0] = new Num(1, 0);\n for (int i = 1; i <= k; i++) {\n pow1[i] = pow1[i - 1].multiply(PHI1);\n pow2[i] = pow2[i - 1].multiply(PHI2);\n powA[i] = powA[i - 1].multiply(A);\n powB[i] = powB[i - 1].multiply(B);\n }\n }\n\n long inv(long x) {\n return pow(x, mod - 2);\n }\n\n long pow(long a, long b) {\n long res = 1;\n while (b != 0) {\n if ((b & 1) == 1) {\n res = res * a % mod;\n }\n a = a * a % mod;\n b >>>= 1;\n }\n return res;\n }\n\n final Num PHI1 = new Num(inv(2), inv(2));\n final Num PHI2 = new Num(inv(2), mod - inv(2));\n final Num A = new Num(0, inv(5));\n final Num B = new Num(0, mod - inv(5));\n\n final Num ONE = new Num(1, 0);\n\n Num[] pow1, pow2, powA, powB;\n\n long get(long n) {\n Num result = new Num(0, 0);\n\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j <= k; j++) {\n long coef = coeffs[i][j];\n if (coef == 0) {\n continue;\n }\n\n Num cur = new Num(coef, 0).multiply(powA[i]).multiply(powB[j]);\n\n Num x = pow1[i].multiply(pow2[j]);\n x = geomSum(x, n + 1);\n\n result = result.add(cur.multiply(x));\n }\n }\n return result.a;\n }\n\n\n Num geomSum(Num x, long n) {\n if (n == 0) {\n return ONE;\n }\n if (n % 2 == 0) {\n Num x2 = x.multiply(x);\n Num result = geomSum(x2, n / 2);\n return (ONE.add(x)).multiply(result);\n } else {\n return ONE.add(x.multiply(geomSum(x, n - 1)));\n }\n }\n\n public void solve() {\n k = in.nextInt();\n prepare();\n long l = in.nextInt(), r = in.nextInt();\n for (int i = 1; i < 20; i++) {\n System.err.println(get(i) - get(i - 1));\n }\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new A().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "28646c0a5c769830e2e3416c1ad7dbc2", "src_uid": "39b824b740a40f68bae39b8d9f0adcbe", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.awt.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\n\npublic class B implements Runnable{\n\n private final static Random rnd = new Random();\n\n // SOLUTION!!!\n // HACK ME PLEASE IF YOU CAN!!!\n // PLEASE!!!\n // PLEASE!!!\n // PLEASE!!!\n\n final int MAX_SIZE = 2000 * 1000;\n\n void solve() {\n int n = readInt();\n\n int c0 = readInt();\n int c1 = readInt();\n\n if (c0 > c1) {\n int tmp = c0;\n c0 = c1;\n c1 = tmp;\n }\n\n long answer = getAnswer(n, c0, c1);\n out.println(answer);\n }\n\n long getAnswer(int n, long c0, long c1) {\n long c01 = c0 + c1;\n\n if (n == 2) {\n return c01;\n }\n\n long answer = c1;\n n -= 2;\n\n long x = (c0 == 0 ? Integer.MAX_VALUE : c1 / c0);\n x = Math.min(x, n);\n\n answer += x * c1 + (x + 1) * (x + 2) / 2 * c0;\n n -= x;\n\n NavigableMap costs = new TreeMap<>();\n\n// costs.put(c1, 1);\n for (int count = 0; count <= Math.min(MAX_SIZE, x); ++count) {\n inc(costs, count * c0 + c1, 1);\n }\n inc(costs, (x + 1) * c0, 1);\n\n while (n > 0) {\n Map.Entry minCostEntry = costs.pollFirstEntry();\n\n long cost = minCostEntry.getKey();\n int count = minCostEntry.getValue();\n count = Math.min(count, n);\n\n n -= count;\n answer += (cost + c01) * count;\n\n inc(costs, cost + c0, count);\n inc(costs, cost + c1, count);\n }\n\n return answer;\n }\n\n void inc(NavigableMap counts, long cost, int count) {\n Integer curCount = counts.get(cost);\n if (curCount == null) {\n curCount = 0;\n }\n\n counts.put(cost, curCount + count);\n\n while (counts.size() > MAX_SIZE) {\n counts.pollLastEntry();\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private final static boolean FIRST_INPUT_STRING = false;\n private final static boolean MULTIPLE_TESTS = true;\n private final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private final static int MAX_STACK_SIZE = 128;\n\n private final static boolean OPTIMIZE_READ_NUMBERS = false;\n\n /////////////////////////////////////////////////////////////////////\n\n public void run(){\n try{\n timeInit();\n Locale.setDefault(Locale.US);\n\n init();\n\n if (ONLINE_JUDGE) {\n solve();\n } else {\n do {\n try {\n timeInit();\n solve();\n time();\n\n out.println();\n } catch (NumberFormatException e) {\n break;\n } catch (NullPointerException e) {\n if (FIRST_INPUT_STRING) break;\n else throw e;\n }\n } while (MULTIPLE_TESTS);\n }\n\n out.close();\n time();\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private BufferedReader in;\n private OutputWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n public static void main(String[] args){\n new Thread(null, new B(), \"\", 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 in = new BufferedReader(new InputStreamReader(System.in));\n out = new OutputWriter(System.out);\n }else{\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new OutputWriter(\"output.txt\");\n }\n }\n\n ////////////////////////////////////////////////////////////////\n\n private long timeBegin;\n\n private void timeInit() {\n this.timeBegin = System.currentTimeMillis();\n }\n\n private void time(){\n long timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n private void debug(Object... objects){\n if (ONLINE_JUDGE){\n for (Object o: objects){\n System.err.println(o.toString());\n }\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private String delim = \" \";\n\n private String readLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private String readString() {\n try {\n while(!tok.hasMoreTokens()){\n tok = new StringTokenizer(readLine());\n }\n\n return tok.nextToken(delim);\n } catch (NullPointerException e) {\n return null;\n }\n }\n\n /////////////////////////////////////////////////////////////////\n\n private final char NOT_A_SYMBOL = '\\0';\n\n private char readChar() {\n try {\n int intValue = in.read();\n\n if (intValue == -1){\n return NOT_A_SYMBOL;\n }\n\n return (char) intValue;\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private char[] readCharArray() {\n return readLine().toCharArray();\n }\n\n private char[][] readCharField(int rowsCount) {\n char[][] field = new char[rowsCount][];\n for (int row = 0; row < rowsCount; ++row) {\n field[row] = readCharArray();\n }\n\n return field;\n }\n\n /////////////////////////////////////////////////////////////////\n\n private long optimizedReadLong() {\n 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 result;\n throw new NumberFormatException();\n }\n\n if ('0' <= j && j <= '9') {\n result = result * 10 + j - '0';\n started = true;\n } else if (started) {\n return result;\n }\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n }\n\n private int readInt() {\n\n if (!OPTIMIZE_READ_NUMBERS) {\n return Integer.parseInt(readString());\n } else {\n return (int) optimizedReadLong();\n }\n }\n\n private int[] readIntArray(int size) {\n int[] array = new int[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readInt();\n }\n\n return array;\n }\n\n private int[] readSortedIntArray(int size) {\n Integer[] array = new Integer[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = readInt();\n }\n Arrays.sort(array);\n\n int[] sortedArray = new int[size];\n for (int index = 0; index < size; ++index) {\n sortedArray[index] = array[index];\n }\n\n return sortedArray;\n }\n\n private int[] readIntArrayWithDecrease(int size) {\n int[] array = readIntArray(size);\n\n for (int i = 0; i < size; ++i) {\n array[i]--;\n }\n\n return array;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private int[][] readIntMatrix(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArray(columnsCount);\n }\n\n return matrix;\n }\n\n private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);\n }\n\n return matrix;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private long readLong() {\n if (!OPTIMIZE_READ_NUMBERS) {\n return Long.parseLong(readString());\n } else {\n return optimizedReadLong();\n }\n }\n\n private long[] readLongArray(int size) {\n long[] array = new long[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readLong();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private double readDouble() {\n return Double.parseDouble(readString());\n }\n\n private double[] readDoubleArray(int size) {\n double[] array = new double[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readDouble();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private BigInteger readBigInteger() {\n return new BigInteger(readString());\n }\n\n private BigDecimal readBigDecimal() {\n return new BigDecimal(readString());\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private Point readPoint() {\n int x = readInt();\n int y = readInt();\n return new Point(x, y);\n }\n\n private Point[] readPointArray(int size) {\n Point[] array = new Point[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readPoint();\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private List[] readGraph(int vertexNumber, int edgeNumber) {\n @SuppressWarnings(\"unchecked\")\n List[] graph = new List[vertexNumber];\n\n for (int index = 0; index < vertexNumber; ++index){\n graph[index] = new ArrayList();\n }\n\n while (edgeNumber-- > 0){\n int from = readInt() - 1;\n int to = readInt() - 1;\n\n graph[from].add(to);\n graph[to].add(from);\n }\n\n return graph;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IntIndexPair {\n\n static Comparator increaseComparator = new Comparator() {\n\n @Override\n public int compare(B.IntIndexPair indexPair1, B.IntIndexPair indexPair2) {\n int value1 = indexPair1.value;\n int value2 = indexPair2.value;\n\n if (value1 != value2) return value1 - value2;\n\n int index1 = indexPair1.index;\n int index2 = indexPair2.index;\n\n return index1 - index2;\n }\n };\n\n static Comparator decreaseComparator = new Comparator() {\n\n @Override\n public int compare(B.IntIndexPair indexPair1, B.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 int value, index;\n\n IntIndexPair(int value, int index) {\n super();\n this.value = value;\n this.index = index;\n }\n\n int getRealIndex() {\n return index + 1;\n }\n }\n\n private IntIndexPair[] readIntIndexArray(int size) {\n IntIndexPair[] array = new IntIndexPair[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = new IntIndexPair(readInt(), index);\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class OutputWriter extends PrintWriter {\n\n final int DEFAULT_PRECISION = 12;\n\n private int precision;\n private String format, formatWithSpace;\n\n {\n precision = DEFAULT_PRECISION;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n OutputWriter(OutputStream out) {\n super(out);\n }\n\n OutputWriter(String fileName) throws FileNotFoundException {\n super(fileName);\n }\n\n int getPrecision() {\n return precision;\n }\n\n void setPrecision(int precision) {\n precision = max(0, precision);\n this.precision = precision;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n String createFormat(int precision){\n return \"%.\" + precision + \"f\";\n }\n\n @Override\n public void print(double d){\n printf(format, d);\n }\n\n void printWithSpace(double d){\n printf(formatWithSpace, d);\n }\n\n void printAll(double...d){\n for (int i = 0; i < d.length - 1; ++i){\n printWithSpace(d[i]);\n }\n\n print(d[d.length - 1]);\n }\n\n @Override\n public void println(double d){\n printlnAll(d);\n }\n\n void printlnAll(double... d){\n printAll(d);\n println();\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class RuntimeIOException extends RuntimeException {\n\n /**\n *\n */\n private static final long serialVersionUID = -6463830523020118289L;\n\n RuntimeIOException(Throwable cause) {\n super(cause);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n //////////////// Some useful constants and functions ////////////////\n /////////////////////////////////////////////////////////////////////\n\n private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n private static final int[][] steps8 = {\n {-1, 0}, {1, 0}, {0, -1}, {0, 1},\n {-1, -1}, {1, 1}, {1, -1}, {-1, 1}\n };\n\n private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {\n return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);\n }\n\n private static boolean checkIndex(int index, int lim){\n return (0 <= index && index < lim);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static boolean checkBit(int mask, int bit){\n return (mask & (1 << bit)) != 0;\n }\n private static boolean checkBit(long mask, int bit){\n return (mask & (1L << bit)) != 0;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long getSum(int[] array) {\n long sum = 0;\n for (int value: array) {\n sum += value;\n }\n\n return sum;\n }\n\n private static Point getMinMax(int[] array) {\n int min = array[0];\n int max = array[0];\n\n for (int index = 0, size = array.length; index < size; ++index, ++index) {\n int value = array[index];\n\n if (index == size - 1) {\n min = min(min, value);\n max = max(max, value);\n } else {\n int otherValue = array[index + 1];\n\n if (value <= otherValue) {\n min = min(min, value);\n max = max(max, otherValue);\n } else {\n min = min(min, otherValue);\n max = max(max, value);\n }\n }\n }\n\n return new Point(min, max);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static int[] getPrimes(int n) {\n boolean[] used = new boolean[n];\n used[0] = used[1] = true;\n\n int size = 0;\n for (int i = 2; i < n; ++i) {\n if (!used[i]) {\n ++size;\n for (int j = 2 * i; j < n; j += i) {\n used[j] = true;\n }\n }\n }\n\n int[] primes = new int[size];\n for (int i = 0, cur = 0; i < n; ++i) {\n if (!used[i]) {\n primes[cur++] = i;\n }\n }\n\n return primes;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n private static long gcd(long a, long b) {\n return (a == 0 ? b : gcd(b % a, a));\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IdMap extends HashMap {\n\n /**\n *\n */\n private static final long serialVersionUID = -3793737771950984481L;\n\n public IdMap() {\n super();\n }\n\n int getId(KeyType key) {\n Integer id = super.get(key);\n if (id == null) {\n super.put(key, id = size());\n }\n\n return id;\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cb9c449cd9ccf3601a40239a903bc879", "src_uid": "39b824b740a40f68bae39b8d9f0adcbe", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "//package bubblecup9f;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class B2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), c0 = ni(), c1 = ni();\n\t\tif(c0 > c1){\n\t\t\tint d = c0;c0 = c1; c1 = d;\n\t\t}\n\t\tif(c0 == 0){\n\t\t\tout.println((long)c1*(n-1));\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong low = -1, high = 100000000000000000L;\n\t\twhile(high - low > 1){\n\t\t\tlong h = high+low>>1; // sup of split node's cost\n\t\t\tlong eled = 0;\n\t\t\tfor(long nc1 = 0;h-nc1*c1 >= 0;nc1++){\n\t\t\t\tlong nc0 = (h-nc1*c1)/c0;\n\t\t\t\t// C(nc1+0,nc1)+C(nc1+1,nc1)+...+(nc1+nc0,nc0) # eliminated nodes\n\t\t\t\t// C(nc1+nc0+1,nc0+1)\n\t\t\t\teled += roughC(nc1+nc0+1,nc1+1,18);\n\t\t\t\tif(eled > n-1)break;\n\t\t\t}\n\t\t\tif(eled >= n-1){\n\t\t\t\thigh = h;\n\t\t\t}else{\n\t\t\t\tlow = h;\n\t\t\t}\n\t\t}\n\t\ttr(high);\n\t\t\n\t\t{\n\t\t\tlong ret = (long)(c0+c1)*(n-1); // # branch\n\t\t\tlong eled = 0;\n\t\t\tfor(long nc1 = 0;low-nc1*c1 >= 0;nc1++){\n\t\t\t\tlong nc0 = (low-nc1*c1)/c0;\n\t\t\t\t// C(nc1+0,nc1)+C(nc1+1,nc1)+...+(nc1+nc0,nc1) # eliminated nodes\n\t\t\t\t// C(nc1+nc0+1,nc1+1)\n\t\t\t\tlong val = roughC(nc1+nc0+1,nc1+1,18);\n\t\t\t\teled += val;\n\t\t\t\t// none 0\n\t\t\t\t// C(nc1+0,nc1)*nc1*c1+C(nc1+1,nc1)*(c0+nc1*c1)+...+(nc1+nc0,nc1)*(nc0*c0+nc1*c1) # eliminated nodes\n\t\t\t\t// C(nc1+nc0+1,nc1+1)-C(nc1+k,nc1+1)\n\t\t\t\t// nc0*C(nc1+nc0+1,nc1+1)-C(nc1+nc0+1,nc1+1+1)\n\t\t\t\t// c1*val*nc1 + c0*(val*(nc0+1)-val)\n\t\t\t\tret += c1*nc1*val + c0*(nc0*val-roughC(nc1+nc0+1,nc1+2,18));\n\t\t\t}\n\t\t\tlong rem = n-1-eled;\n\t\t\tret += rem * (low+1);\n\t\t\tout.println(ret);\n\t\t}\n\t}\n\t\n\tpublic static long roughC(long n, long r, double lim)\n\t{\n\t\tif(n < r || r < 0 || n < 0)return 0;\n\t\tif(r > n/2)r = n - r;\n\t\tif(r == 0)return 1;\n\t\tdouble logc = (n+0.5)*Math.log10(n)+(-r-0.5)*Math.log10(r)+(-n+r-0.5)*Math.log10(n-r)-Math.log10(2*Math.PI)/2;\n\t\tif(logc >= lim)return Long.MAX_VALUE/2;\n\t\tlong x = 1;\n\t\tfor(int i = 0;i < r;i++) {\n\t\t\tx *= n-i;\n\t\t\tx /= i+1;\n\t\t}\n\t\treturn x;\n\t}\n\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 B2().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b4aa589e2f7056903044e05b21c3813a", "src_uid": "39b824b740a40f68bae39b8d9f0adcbe", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n long n, c0, c1;\n\n public void solve() {\n n = in.nextInt() - 1;\n c0 = in.nextInt();\n c1 = in.nextInt();\n if (c0 > c1) {\n long tmp = c0;\n c0 = c1;\n c1 = tmp;\n }\n\n if (c0 == 0) {\n out.println(1L * n * (c0 + c1));\n return;\n }\n\n long left = 0, right = (long) 5e17;\n\n while (left < right - 1) {\n long mid = (left + right) >>> 1;\n\n long[] calc = calc(mid);\n if (calc[0] < n) {\n left = mid;\n } else {\n right = mid;\n }\n }\n System.err.println(left);\n long[] calc2 = calc(left);\n\n long result = calc2[1] + (n - calc2[0]) * (left + 1);\n result += 1L * n * (c0 + c1);\n out.println(result);\n }\n\n long[] calc(long x) {\n long count = 0, sum = 0;\n for (long j = 0; c1 * j <= x; j++) {\n long maxI = (x - c1 * j) / c0;\n if (j == 0) {\n count += (maxI + 1);\n sum += c0 * maxI * (maxI + 1) / 2;\n } else {\n long curChoose = 1;\n for (long i = 0; i * c0 + j * c1 <= x; i++) {\n if (i > 0) {\n curChoose *= (i + j);\n curChoose /= i;\n }\n count += curChoose;\n sum += curChoose * (i * c0 + j * c1);\n if (count >= n) {\n return new long[]{count, sum};\n }\n }\n }\n }\n return new long[]{count, sum};\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new B().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cebc3991044249ceececa2823c8be782", "src_uid": "39b824b740a40f68bae39b8d9f0adcbe", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n GBeautifulMatrix solver = new GBeautifulMatrix();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GBeautifulMatrix {\n Modular mod = new Modular(998244353);\n Factorial factorial = new Factorial(2000, mod);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int[][] mat = new int[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n mat[i][j] = in.readInt();\n }\n }\n\n PermutationWithDistinctForbiddenMatch permutation = new PermutationWithDistinctForbiddenMatch(mod, n);\n int[] follow = new int[n + 1];\n follow[0] = 1;\n for (int i = 1; i <= n; i++) {\n follow[i] = mod.mul(follow[i - 1], permutation.get(n, 0));\n }\n\n int ans = 0;\n\n int[] indexOfVal = new int[n + 1];\n int[] indexOfDim = new int[n + 1];\n IntegerBIT deleteBit = new IntegerBIT(n);\n IntegerBIT floatBIT = new IntegerBIT(n);\n IntegerBIT solidBIT = new IntegerBIT(n);\n\n int[][] floatSummary = new int[n][n];\n int[][] solidSummary = new int[n][n];\n int[][] floatCnt = new int[n][n];\n int[] solid = new int[n + 1];\n final int NONE = 0;\n final int SOLID = 1;\n final int FLOAT = 2;\n for (int i = 1; i < n; i++) {\n solidBIT.clear();\n floatBIT.clear();\n for (int j = 1; j <= n; j++) {\n solidBIT.update(j, 1);\n solid[j] = SOLID;\n }\n for (int j = 0; j < n; j++) {\n floatCnt[i][j] = floatBIT.query(n);\n floatSummary[i][j] = floatBIT.query(mat[i][j] - 1);\n solidSummary[i][j] = solidBIT.query(mat[i][j] - 1);\n if (solid[mat[i - 1][j]] == SOLID && mat[i - 1][j] < mat[i][j]) {\n solidSummary[i][j] -= 1;\n }\n if (solid[mat[i - 1][j]] == FLOAT && mat[i - 1][j] < mat[i][j]) {\n floatSummary[i][j] -= 1;\n }\n if (solid[mat[i - 1][j]] == SOLID) {\n solidBIT.update(mat[i - 1][j], -1);\n floatBIT.update(mat[i - 1][j], 1);\n solid[mat[i - 1][j]] = FLOAT;\n }\n\n if (solid[mat[i][j]] == SOLID) {\n solidBIT.update(mat[i][j], -1);\n } else {\n floatBIT.update(mat[i][j], -1);\n }\n solid[mat[i][j]] = NONE;\n }\n }\n\n deleteBit.clear();\n for (int j = 0; j < n; j++) {\n int cnt = mat[0][j] - 1 - deleteBit.query(mat[0][j] - 1);\n int contrib = mod.mul(cnt, factorial.fact(n - j - 1));\n contrib = mod.mul(contrib, follow[n - 1]);\n ans = mod.plus(ans, contrib);\n deleteBit.update(mat[0][j], 1);\n }\n\n for (int i = 1; i < n; i++) {\n for (int j = 0; j < n; j++) {\n indexOfVal[mat[i][j]] = j;\n indexOfDim[mat[i - 1][j]] = j;\n }\n for (int j = 0; j < n - 1; j++) {\n //float\n int cnt = floatSummary[i][j];\n int floatRemain = floatCnt[i][j] - 1;\n if (floatRemain < 0) {\n continue;\n }\n if (indexOfVal[mat[i - 1][j]] > j) {\n floatRemain++;\n }\n int remain = n - j - 1;\n int contrib = mod.mul(cnt, permutation.get(remain - floatRemain, floatRemain));\n contrib = mod.mul(contrib, follow[n - i - 1]);\n ans = mod.plus(ans, contrib);\n }\n for (int j = 0; j < n - 1; j++) {\n //solid\n int cnt = solidSummary[i][j];\n if (cnt == 0) {\n continue;\n }\n int floatRemain = floatCnt[i][j] + 1;\n if (indexOfVal[mat[i - 1][j]] < j) {\n floatRemain--;\n }\n int remain = n - j - 1;\n int contrib = mod.mul(cnt, permutation.get(remain - floatRemain, floatRemain));\n contrib = mod.mul(contrib, follow[n - i - 1]);\n ans = mod.plus(ans, contrib);\n }\n }\n\n out.println(ans);\n }\n\n }\n\n static class PermutationWithDistinctForbiddenMatch {\n private int[][] dp;\n private int[][] dp2;\n\n public PermutationWithDistinctForbiddenMatch(Modular mod, int n) {\n this.dp = new int[n + 1][n + 1];\n dp[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= i; j++) {\n dp[i][j] = mod.mul(dp[i - 1][j], j + j);\n if (j + 1 <= n) {\n dp[i][j] = mod.plus(dp[i][j], dp[i - 1][j + 1]);\n }\n if (j > 0) {\n dp[i][j] = mod.plus(dp[i][j], mod.mul(dp[i - 1][j - 1], mod.mul(j, j)));\n }\n }\n }\n\n dp2 = new int[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n if (j == 0) {\n dp2[i][j] = dp[i][j];\n continue;\n }\n if (j > 0) {\n dp2[i][j] = mod.plus(dp2[i][j], mod.mul(dp2[i][j - 1], j));\n }\n if (i > 0) {\n dp2[i][j] = mod.plus(dp2[i][j], mod.mul(dp2[i - 1][j], i));\n }\n }\n }\n\n// System.err.println(Arrays.deepToString(dp));\n// System.err.println(Arrays.deepToString(dp2));\n }\n\n public int get(int i, int j) {\n return dp2[i][j];\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 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 IntegerBIT {\n private int[] data;\n private int n;\n\n public IntegerBIT(int n) {\n this.n = n;\n data = new int[n + 1];\n }\n\n public int query(int i) {\n int sum = 0;\n for (; i > 0; i -= i & -i) {\n sum += data[i];\n }\n return sum;\n }\n\n public void update(int i, int mod) {\n if (i <= 0) {\n return;\n }\n for (; i <= n; i += i & -i) {\n data[i] += mod;\n }\n }\n\n public void clear() {\n Arrays.fill(data, 0);\n }\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n for (int i = 1; i <= n; i++) {\n builder.append(query(i) - query(i - 1)).append(' ');\n }\n return builder.toString();\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(int c) {\n cache.append(c).append('\\n');\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class 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 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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "14dcd19bd63fde24b46d8892ff347b5d", "src_uid": "46253becfda9a45ce670dc7d835beaf3", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n GBeautifulMatrix solver = new GBeautifulMatrix();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GBeautifulMatrix {\n Modular mod = new Modular(998244353);\n Factorial factorial = new Factorial(2000, mod);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int[][] mat = new int[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n mat[i][j] = in.readInt();\n }\n }\n\n PermutationWithDistinctForbiddenMatch permutation = new PermutationWithDistinctForbiddenMatch(mod, n);\n int[] follow = new int[n + 1];\n follow[0] = 1;\n for (int i = 1; i <= n; i++) {\n follow[i] = mod.mul(follow[i - 1], permutation.get(n, 0));\n }\n\n int ans = 0;\n\n int[] indexOfVal = new int[n + 1];\n int[] indexOfDim = new int[n + 1];\n IntegerBIT deleteBit = new IntegerBIT(n);\n IntegerBIT leftBIT = new IntegerBIT(n);\n IntegerBIT rightBIT = new IntegerBIT(n);\n\n int[][] live = new int[n][n];\n int[][] left = new int[n][n];\n int[][] right = new int[n][n];\n MultiWayIntegerStack s1 = new MultiWayIntegerStack(n, n);\n MultiWayIntegerStack s2 = new MultiWayIntegerStack(n, n);\n for (int i = 1; i < n; i++) {\n for (int j = 0; j < n; j++) {\n indexOfVal[mat[i][j]] = j;\n indexOfDim[mat[i - 1][j]] = j;\n }\n\n leftBIT.clear();\n rightBIT.clear();\n s1.clear();\n s2.clear();\n for (int j = n - 1; j >= 0; j--) {\n right[i][j] = rightBIT.query(mat[i][j] - 1);\n if (mat[i - 1][j] < mat[i][j]) {\n right[i][j] -= rightBIT.query(mat[i - 1][j]) - rightBIT.query(mat[i - 1][j] - 1);\n }\n left[i][j] = leftBIT.query(mat[i][j] - 1);\n if (mat[i - 1][j] < mat[i][j]) {\n left[i][j] -= leftBIT.query(mat[i - 1][j]) - leftBIT.query(mat[i - 1][j] - 1);\n }\n live[i][j] = rightBIT.query(n);\n\n if (indexOfVal[mat[i - 1][j]] <= j) {\n s1.addLast(indexOfVal[mat[i - 1][j]], j);\n } else {\n rightBIT.update(mat[i - 1][j], 1);\n }\n\n if (indexOfDim[mat[i][j]] <= j) {\n s2.addLast(indexOfDim[mat[i][j]], j);\n leftBIT.update(mat[i][j], 1);\n } else {\n }\n\n while (!s1.isEmpty(j)) {\n int tail = s1.removeLast(j);\n //leftBIT.update(mat[i - 1][tail], -1);\n rightBIT.update(mat[i - 1][tail], 1);\n }\n\n while (!s2.isEmpty(j)) {\n int tail = s2.removeLast(j);\n leftBIT.update(mat[i][tail], -1);\n }\n }\n\n }\n\n deleteBit.clear();\n for (int j = 0; j < n; j++) {\n int cnt = mat[0][j] - 1 - deleteBit.query(mat[0][j] - 1);\n int contrib = mod.mul(cnt, factorial.fact(n - j - 1));\n contrib = mod.mul(contrib, follow[n - 1]);\n ans = mod.plus(ans, contrib);\n deleteBit.update(mat[0][j], 1);\n }\n\n for (int i = 1; i < n; i++) {\n for (int j = 0; j < n; j++) {\n indexOfVal[mat[i][j]] = j;\n indexOfDim[mat[i - 1][j]] = j;\n }\n for (int j = 0; j < n; j++) {\n //from left\n if (left[i][j] == 0) {\n continue;\n }\n int contrib = left[i][j];\n int remain = n - 1 - j;\n int l = live[i][j];\n if (indexOfDim[mat[i][j]] > j) {\n l++;\n }\n contrib = mod.mul(contrib, permutation.get(l, remain - l));\n contrib = mod.mul(contrib, follow[n - 1 - i]);\n ans = mod.plus(ans, contrib);\n }\n for (int j = 0; j < n; j++) {\n //from right\n if (right[i][j] == 0) {\n continue;\n }\n int contrib = right[i][j];\n int remain = n - 1 - j;\n int l = live[i][j];\n if (indexOfDim[mat[i][j]] > j) {\n l++;\n }\n contrib = mod.mul(contrib, permutation.get(l - 1, remain - (l - 1)));\n contrib = mod.mul(contrib, follow[n - 1 - i]);\n ans = mod.plus(ans, contrib);\n }\n }\n\n out.println(ans);\n }\n\n }\n\n static class PermutationWithDistinctForbiddenMatch {\n private int[][] dp;\n private int[][] dp2;\n\n public PermutationWithDistinctForbiddenMatch(Modular mod, int n) {\n this.dp = new int[n + 1][n + 1];\n dp[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= i; j++) {\n dp[i][j] = mod.mul(dp[i - 1][j], j + j);\n if (j + 1 <= n) {\n dp[i][j] = mod.plus(dp[i][j], dp[i - 1][j + 1]);\n }\n if (j > 0) {\n dp[i][j] = mod.plus(dp[i][j], mod.mul(dp[i - 1][j - 1], mod.mul(j, j)));\n }\n }\n }\n\n dp2 = new int[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n if (j == 0) {\n dp2[i][j] = dp[i][j];\n continue;\n }\n if (j > 0) {\n dp2[i][j] = mod.plus(dp2[i][j], mod.mul(dp2[i][j - 1], j));\n }\n if (i > 0) {\n dp2[i][j] = mod.plus(dp2[i][j], mod.mul(dp2[i - 1][j], i));\n }\n }\n }\n\n// System.err.println(Arrays.deepToString(dp));\n// System.err.println(Arrays.deepToString(dp2));\n }\n\n public int get(int i, int j) {\n return dp2[i][j];\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 MultiWayIntegerStack {\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 void clear() {\n alloc = 0;\n Arrays.fill(heads, 0, stackNum, 0);\n }\n\n public boolean isEmpty(int qId) {\n return heads[qId] == 0;\n }\n\n public MultiWayIntegerStack(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 int removeLast(int qId) {\n int ans = values[heads[qId]];\n heads[qId] = next[heads[qId]];\n return ans;\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 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 IntegerBIT {\n private int[] data;\n private int n;\n\n public IntegerBIT(int n) {\n this.n = n;\n data = new int[n + 1];\n }\n\n public int query(int i) {\n int sum = 0;\n for (; i > 0; i -= i & -i) {\n sum += data[i];\n }\n return sum;\n }\n\n public void update(int i, int mod) {\n if (i <= 0) {\n return;\n }\n for (; i <= n; i += i & -i) {\n data[i] += mod;\n }\n }\n\n public void clear() {\n Arrays.fill(data, 0);\n }\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n for (int i = 1; i <= n; i++) {\n builder.append(query(i) - query(i - 1)).append(' ');\n }\n return builder.toString();\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(int c) {\n cache.append(c).append('\\n');\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class 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 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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1e85d5901ba8f27ea3ea0caef87fa309", "src_uid": "46253becfda9a45ce670dc7d835beaf3", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1277592a01540b0958b13a3537773718", "src_uid": "46253becfda9a45ce670dc7d835beaf3", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class E {\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic int MAX = 2005;\n\tstatic long mod = 998_244_353L;\n\tstatic long fact[];\n\tstatic long dp[][];\n\t\n\tstatic int N;\n\tstatic int mat[][];\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tfact = new long[MAX];\n\t\tfact[0] = 1;\n\t\tfor(int i = 1; i < MAX; i++) fact[i] = (fact[i-1]*i)%mod;\n\t\tdp = new long[MAX][MAX];\n\t\tfor(long a[] : dp) Arrays.fill(a, -1);\n\t\t\n\t\tN = in.nextInt();\n\t\tmat = new int[N][N];\n\t\tfor(int i = 0; i < N; i++)\n\t\t\tfor(int j = 0; j < N; j++)\n\t\t\t\tmat[i][j] = in.nextInt()-1;\n\t\t\n\t\tlong whenFree = go(N, N);\n\t\tlong freePow[] = new long[N+1];\n\t\tfreePow[0] = 1;\n\t\tfor(int i = 1; i <= N; i++) {\n\t\t\tfreePow[i] = (whenFree * freePow[i-1])%mod;\n\t\t}\n\t\t\n//\t\tfor(int i = 1; i <= N; i++) {\n//\t\t\tfor(int j = 0; j <= i; j++) {\n//\t\t\t\tSystem.out.println(\"n=\"+i+\" ab=\"+j+\" res = \"+go(i,j));\n//\t\t\t}\n//\t\t}\n\t\t\n\t\tlong res = 0;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tint sz = N;\n\t\t\tBIT have = new BIT(N);\n\t\t\tfor(int j = 0; j < N; j++) have.update(j, 1);\n\t\t\t\n\t\t\tfor(int j = 0; j < N; j++) {\n\t\t\t\tsz--;\n\t\t\t\t// place something less than it\n\t\t\t\tlong areLess = have.sum(0, mat[i][j]-1);\n\t\t\t\tif(i > 0 && mat[i-1][j] < mat[i][j]) areLess -= have.sum(mat[i-1][j], mat[i-1][j]);\n\t\t\t\tres = add(res, mult(freePow[N-i-1], mult(areLess, go(sz, (i == 0 ? 0 : sz)))));\n\t\t\t\t\n//\t\t\t\tSystem.out.println(i+\" \"+j+\" less = \"+areLess+\" above = \"+sz+\" res = \"+res);\n\t\t\t\t\n\t\t\t\t// place the current element and continue\n\t\t\t\thave.update(mat[i][j], -1);\n\t\t\t}\n\t\t}\n\t\tout.println(res);\n\t\tout.close();\n\t}\n\t\n\tstatic long go(int n, int above) {\n\t\tif(n <= 0 || above < 0) return 0;\n\t\tif(n == 1) return above == 1 ? 0 : 1;\n\t\tif(above == 0) return fact[n];\n\t\tif(dp[n][above] != -1) return dp[n][above];\n\t\tlong free = n-above;\n\t\tlong notFree = above-1;\n\t\tlong res = 0;\n\t\tres += (free * go(n-1, above-1));\n\t\tres += (notFree * go(n-1, above-2));\n\t\treturn dp[n][above] = res%mod;\n\t}\n\t\n\tstatic long add(long a, long b) {\n\t\tlong x = a+b;\n\t\treturn x >= mod ? x-mod : x;\n\t}\n\tstatic long mult(long a, long b) {\n\t\tlong x = a*b;\n\t\treturn x >= mod ? x%mod : x;\n\t}\n\t\n\t\n\tstatic class BIT {\n\t\tint n;\n\t\tint[] tree;\n\t\t\n\t\tpublic BIT(int n) {\n\t\t\tthis.n = n;\n\t\t\ttree = new int[n + 2];\n\t\t}\n\t\t\n\t\tint read(int i) {\n\t\t\ti++;\n\t\t\tint sum = 0;\n\t\t\twhile (i > 0) {\n\t\t\t\tsum += tree[i];\n\t\t\t\ti -= i & -i;\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tint sum(int a, int b) {\n\t\t\tif(a > b) return 0;\n\t\t\treturn read(b) - (a == 0 ? 0 : read(a-1));\n\t\t}\n\t\t\n\t\tvoid update(int i, int val) {\n\t\t\ti++;\n\t\t\twhile (i <= n) {\n\t\t\t\ttree[i] += val;\n\t\t\t\ti += i & -i;\n\t\t\t}\n\t\t}\n\n\t\t// if the BIT is a freq array, returns the\n\t\t// index of the kth item, or n if there are fewer\n\t\t// than k items.\n\t\tint getKth(int k) {\n\t\t\tint e=Integer.highestOneBit(n), o=0;\n\t\t\tfor (; e!=0; e>>=1) {\n\t\t\t\tif (e+o<=n && tree[e+o]<=k) {\n\t\t\t\t\tk-=tree[e+o];\n\t\t\t\t\to+=e;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn o;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t\tint[] NIA(int n) {\n\t\t\tint r[] = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextInt();\n\t\t\treturn r;\n\t\t}\n\t\tlong[] NLA(int n) {\n\t\t\tlong r[] = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextLong();\n\t\t\treturn r;\n\t\t}\n\t\tchar[][] grid(int r, int c){\n\t\t\tchar res[][] = new char[r][c];\n\t\t\tfor(int i = 0; i < r; i++) {\n\t\t\t\tchar l[] = next().toCharArray();\n\t\t\t\tfor(int j = 0; j < c; j++) {\n\t\t\t\t\tres[i][j] = l[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c111dd5c3a2cccc2d2b0012c480b89bb", "src_uid": "46253becfda9a45ce670dc7d835beaf3", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "05d687a1d0d5ada0bc3979fd2bca4159", "src_uid": "44149b73a6b707c10c3eee75b5e090d2", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ece9edc266470426a1fd259c15e4b9b2", "src_uid": "44149b73a6b707c10c3eee75b5e090d2", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "69eb886a34c567bae7766e27632a560e", "src_uid": "44149b73a6b707c10c3eee75b5e090d2", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n 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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0b4d10e7ffa57c99213a964327ce2ddd", "src_uid": "44149b73a6b707c10c3eee75b5e090d2", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Igor Kraskevich\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\tTaskD3 solver = new TaskD3();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD3 {\n\n final long MOD = 1_000_003;\n\n long mul(long a, long b) {\n return a * b % MOD;\n }\n\n long add(long a, long b) {\n return (a + b) % MOD;\n }\n\n long[][] mul(long[][] a, long[][] b) {\n int N = a.length;\n int K = a[0].length;\n int M = b[0].length;\n long[][] res = new long[N][M];\n for (int i = 0; i < N; i++)\n for (int j = 0; j < M; j++)\n for (int k = 0; k < K; k++)\n res[i][j] = add(res[i][j], mul(a[i][k], b[k][j]));\n return res;\n }\n\n long[][] binPow(long[][] x, long n) {\n long[][] res = new long[x.length][x.length];\n for (int i = 0; i < res.length; i++)\n res[i][i] = 1;\n while (n > 0) {\n if (n % 2 == 1)\n res = mul(res, x);\n x = mul(x, x);\n n /= 2;\n }\n return res;\n }\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int c = in.nextInt();\n int w = in.nextInt();\n int h = in.nextInt();\n long[][] x = new long[w + 1][w + 1];\n for (int j = 0; j <= w; j++)\n x[0][j] = 1;\n for (int i = 1; i <= w; i++)\n x[i][i - 1] = h;\n long[][] a = binPow(x, c);\n long[][] v = new long[w + 1][1];\n v[0][0] = 1;\n long[][] res = mul(a, v);\n long ans = 0;\n for (int i = 0; i <= w; i++)\n ans = add(ans, res[i][0]);\n out.println(ans);\n }\n}\n\nclass FastScanner {\n private StringTokenizer tokenizer;\n private BufferedReader reader;\n\n public FastScanner(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n String line = null;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n }\n if (line == null)\n return null;\n tokenizer = new StringTokenizer(line);\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7711412971bc08e7aadcad84a4fed31c", "src_uid": "bb1c0ff47186e10e00b7dde6758ff1c1", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 29);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DINOIFinalContests solver = new DINOIFinalContests();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DINOIFinalContests {\n int mod;\n Factorial fact;\n Combination comb;\n long[] f;\n long[] g;\n Debug debug = new Debug(true);\n\n public long g(int n) {\n if (n == 0) {\n return 0;\n }\n if (g[n] == -1) {\n long sum = 0;\n for (int i = 0; i < n; i++) {\n int left = i;\n int right = n - 1 - i;\n //0.. left\n //0.. right\n long contrib = (g(left) * f(right) + g(right) * f(left)) % mod * (n - 1 + 2) % mod + f(left) * f(right) % mod * ((IntMath.sumOfInterval(0, left) +\n IntMath.sumOfInterval(0, right)) % mod) % mod;\n contrib = contrib % mod * comb.combination(n - 1, left) % mod;\n sum += contrib;\n }\n g[n] = sum % mod;\n }\n return g[n];\n }\n\n public long f(int n) {\n if (n == 0) {\n return 1;\n }\n if (f[n] == -1) {\n long sum = 0;\n for (int i = 0; i < n; i++) {\n int left = i;\n int right = n - 1 - i;\n sum += f(left) * comb.combination(n - 1, left) % mod * f(right) % mod * (n - 1 + 2) % mod;\n }\n f[n] = sum % mod;\n }\n return f[n];\n }\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int m = in.readInt();\n int p = in.readInt();\n mod = p;\n fact = new Factorial((int) 1e4, p);\n comb = new Combination(fact);\n\n f = new long[m + 1];\n g = new long[m + 1];\n Arrays.fill(f, -1L);\n Arrays.fill(g, -1L);\n\n long[][] dpWay = new long[n + 1][m + 1];\n long[][] dpSum = new long[n + 1][m + 1];\n dpWay[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= m && j <= i; j++) {\n dpWay[i][j] = dpWay[i - 1][j];\n dpSum[i][j] = dpSum[i - 1][j];\n for (int k = 1; k <= j; k++) {\n int prev = Math.max(i - k - 1, 0);\n dpWay[i][j] += dpWay[prev][j - k] * comb.combination(j, k) % mod * f(k) % mod;\n long local = dpSum[prev][j - k] * f(k) +\n dpWay[prev][j - k] * g(k);\n local = local % mod * comb.combination(j, k) % mod;\n dpSum[i][j] += local;\n }\n dpWay[i][j] %= mod;\n dpSum[i][j] %= mod;\n }\n }\n\n long ans = dpSum[n][m];\n debug.debug(\"f\", f);\n debug.debug(\"g\", g);\n debug.debug(\"dpWay\", dpWay);\n debug.debug(\"dpSum\", dpSum);\n out.println(ans);\n }\n\n }\n\n static class Combination implements IntCombination {\n final Factorial factorial;\n int modVal;\n\n public Combination(Factorial factorial) {\n this.factorial = factorial;\n this.modVal = factorial.getMod();\n }\n\n public Combination(int limit, int mod) {\n this(new Factorial(limit, mod));\n }\n\n public int combination(int m, int n) {\n if (n > m || n < 0) {\n return 0;\n }\n return (int) ((long) factorial.fact(m) * factorial.invFact(n) % modVal * factorial.invFact(m - n) % modVal);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private static final int THRESHOLD = 1 << 13;\n private final Writer os;\n private StringBuilder cache = new StringBuilder(THRESHOLD * 2);\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n private void afterWrite() {\n if (cache.length() < THRESHOLD) {\n return;\n }\n flush();\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput append(long c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput println(long c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n return append(System.lineSeparator());\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static interface IntCombination {\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 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 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 IntMath {\n private IntMath() {\n }\n\n public static long sumOfInterval(long l, long r) {\n return (r + l) * (r - l + 1) / 2;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c22b6d5d2cef367437d35a3e1ef315ff", "src_uid": "9812de5f2d272511a63ead8765b23190", "difficulty": 3100.0} {"lang": "Java 11", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.*;\n\npublic class E_New_Game_Plus {\n private static final FastReader fs = new FastReader();\n private static final PrintWriter out = new PrintWriter(System.out);\n\n private static void solve() {\n int n = fs.nextInt(),k = fs.nextInt();\n long[] boss = fs.readlongarray(n);\n rSort(boss);\n PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder());\n for(int i = 0; i tmp = new ArrayList<>();\n for(long x : a)\n tmp.add(x);\n Collections.sort(tmp);\n Collections.reverse(tmp);\n for(int i = 0; i= 0 ? x : -x;\n }\n\n public static long abs(long x) {\n return x >= 0 ? x : -x;\n }\n\n public static boolean even(int x) {\n return x % 2 == 0 ? true : false;\n }\n\n public static boolean even(long x) {\n return x % 2 == 0 ? true : false;\n }\n\n public static int power(int base, int exponent) {\n int res = 1;\n while (exponent > 0) {\n if (!even(exponent))\n res *= base;\n exponent >>= 1;\n base *= base;\n }\n return res;\n }\n\n public static long power(long base, long exponent) {\n long res = 1;\n while (exponent > 0) {\n if (!even(exponent))\n res *= base;\n exponent >>= 1;\n base *= base;\n }\n return res;\n }\n\n public static long mul(long a, long b, long mod) {\n return (a % mod * b % mod) % mod;\n }\n\n public static long add(long a, long b, long mod) {\n return (a % mod + b % mod) % mod;\n }\n\n public static long sub(long a, long b, long mod) {\n return ((a % mod - b % mod) % mod + mod) % mod;\n }\n\n public static long power(long base, long exponent, long mod) {\n long res = 1;\n base %= mod;\n while (exponent > 0) {\n if (!even(exponent))\n res = mul(res, base, mod);\n exponent >>= 1;\n base = mul(base, base, mod);\n }\n return res;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ed98a2c1e633ef6ab4726aa1b3ad87f", "src_uid": "53155daf2375e01a3b87fa1c76f1e9a8", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n public static void main(String[] args) {\n FastReader scan = new FastReader();\n PrintWriter out = new PrintWriter(System.out);\n Task solver = new Task();\n int t = 1;\n for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);\n out.close();\n }\n\n static class Task {\n public void solve(int testNumber, FastReader scan, PrintWriter out) {\n int n = scan.nextInt(), k = scan.nextInt();\n PriorityQueue queue = new PriorityQueue<>(Collections.reverseOrder());\n long ans = 0;\n long[] a = new long[n];\n for(int i = 0; i < n; i++) a[i] = scan.nextLong();\n ruffleSort(a);\n for(int i = 0; i <= k; i++) queue.add(0L);\n for(int i = n - 1; i >= 0; i--) {\n long curr = queue.poll();\n ans += curr;\n queue.add(curr + a[i]);\n }\n out.println(ans);\n }\n }\n\n static void ruffleSort(int[] a) {\n Random get = new Random();\n for (int i = 0; i < a.length; i++) {\n int r = get.nextInt(a.length);\n int temp = a[i];\n a[i] = a[r];\n a[r] = temp;\n }\n Arrays.sort(a);\n }\n\n static void ruffleSort(long[] a) {\n Random get = new Random();\n for (int i = 0; i < a.length; i++) {\n int r = get.nextInt(a.length);\n long temp = a[i];\n a[i] = a[r];\n a[r] = temp;\n }\n Arrays.sort(a);\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public FastReader(String s) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(new File(s)));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a5a47f3d749e7064b316f3878c3f07e4", "src_uid": "53155daf2375e01a3b87fa1c76f1e9a8", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1206F extends PrintWriter {\n\tCF1206F() { super(System.out); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1206F o = new CF1206F(); o.main(); o.flush();\n\t}\n\n\tint[] next, jj; int l_ = 1;\n\tint link(int l, int j) { next[l_] = l; jj[l_] = j; return l_++; }\n\tint[] ao; int n;\n\tint[] cc;\n\tvoid init() {\n\t\tint m = n - 1;\n\t\tnext = new int[1 + m * 2];\n\t\tjj = new int[1 + m * 2];\n\t\tao = new int[n];\n\t\tcc = new int[n];\n\t}\n\tint n_, i_, j_;\n\tint dfs(int p, int i) {\n\t\tint k = 1;\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p)\n\t\t\t\tk += dfs(i, j);\n\t\t}\n\t\tint k_ = Math.min(k, n - k);\n\t\tif (n_ < k_) {\n\t\t\tn_ = k_;\n\t\t\tif (k <= n - k) {\n\t\t\t\ti_ = i;\n\t\t\t\tj_ = p;\n\t\t\t} else {\n\t\t\t\ti_ = p;\n\t\t\t\tj_ = i;\n\t\t\t}\n\t\t}\n\t\treturn k;\n\t}\n\tint a, b;\n\tvoid dfs_(int p, int i, int c) {\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p) {\n\t\t\t\tcc[j] = a;\n\t\t\t\tprintln((i + 1) + \" \" + (j + 1) + \" \" + (a - c));\n\t\t\t\ta += b;\n\t\t\t}\n\t\t}\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p)\n\t\t\t\tdfs_(i, j, cc[j]);\n\t\t}\n\t}\n\tvoid main() {\n\t\tn = sc.nextInt();\n\t\tinit();\n\t\tfor (int h = 0; h < n - 1; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\tao[i] = link(ao[i], j);\n\t\t\tao[j] = link(ao[j], i);\n\t\t}\n\t\tdfs(-1, 0);\n\t\ta = 1; b = 1;\n\t\tdfs_(i_, j_, 0);\n\t\ta = (n - n_) * 2; b = n - n_;\n\t\tprintln((j_ + 1) + \" \" + (i_ + 1) + \" \" + (n - n_));\n\t\tdfs_(j_, i_, n - n_);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af4d0d01ea588f682aa2e35d4be52ef3", "src_uid": "87d755df6ee27b381122062659c4a432", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1206F extends PrintWriter {\n\tCF1206F() { super(System.out); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1206F o = new CF1206F(); o.main(); o.flush();\n\t}\n\n\tint[] next, jj; int l_ = 1;\n\tint link(int l, int j) { next[l_] = l; jj[l_] = j; return l_++; }\n\tint[] ao; int n;\n\tint[] cc;\n\tvoid init() {\n\t\tint m = n - 1;\n\t\tnext = new int[1 + m * 2];\n\t\tjj = new int[1 + m * 2];\n\t\tao = new int[n];\n\t\tcc = new int[n];\n\t}\n\tint n_, i_, j_;\n\tint dfs(int p, int i) {\n\t\tint k = 1;\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p)\n\t\t\t\tk += dfs(i, j);\n\t\t}\n\t\tint k_ = Math.min(k, n - k);\n\t\tif (n_ < k_) {\n\t\t\tn_ = k_;\n\t\t\tif (k <= n - k) {\n\t\t\t\ti_ = i;\n\t\t\t\tj_ = p;\n\t\t\t} else {\n\t\t\t\ti_ = p;\n\t\t\t\tj_ = i;\n\t\t\t}\n\t\t}\n\t\treturn k;\n\t}\n\tint a, b;\n\tvoid dfs_(int p, int i, int c) {\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p) {\n\t\t\t\tcc[j] = a;\n\t\t\t\tprintln((i + 1) + \" \" + (j + 1) + \" \" + (a - c));\n\t\t\t\ta += b;\n\t\t\t}\n\t\t}\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p)\n\t\t\t\tdfs_(i, j, cc[j]);\n\t\t}\n\t}\n\tvoid main() {\n\t\tn = sc.nextInt();\n\t\tif (n == 1)\n\t\t\treturn;\n\t\tinit();\n\t\tfor (int h = 0; h < n - 1; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\tao[i] = link(ao[i], j);\n\t\t\tao[j] = link(ao[j], i);\n\t\t}\n\t\tdfs(-1, 0);\n\t\ta = 1; b = 1;\n\t\tdfs_(i_, j_, 0);\n\t\ta = (n - n_) * 2; b = n - n_;\n\t\tprintln((j_ + 1) + \" \" + (i_ + 1) + \" \" + (n - n_));\n\t\tdfs_(j_, i_, n - n_);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c9e9c7e8eb8b13953e903f38bb03d0af", "src_uid": "87d755df6ee27b381122062659c4a432", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1206F extends PrintWriter {\n\tCF1206F() { super(System.out); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1206F o = new CF1206F(); o.main(); o.flush();\n\t}\n\n\tint[] next, jj; int l_ = 1;\n\tint link(int l, int j) { next[l_] = l; jj[l_] = j; return l_++; }\n\tint[] ao; int n;\n\tint[] cc;\n\tvoid init() {\n\t\tint m = n - 1;\n\t\tnext = new int[1 + m * 2];\n\t\tjj = new int[1 + m * 2];\n\t\tao = new int[n];\n\t\tcc = new int[n];\n\t}\n\tint n_, i_, j_;\n\tint dfs(int p, int i) {\n\t\tint k = 1;\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p)\n\t\t\t\tk += dfs(i, j);\n\t\t}\n\t\tint k_ = Math.min(k, n - k);\n\t\tif (n_ < k_) {\n\t\t\tn_ = k_;\n\t\t\tif (k <= n - k) {\n\t\t\t\ti_ = i;\n\t\t\t\tj_ = p;\n\t\t\t} else {\n\t\t\t\ti_ = p;\n\t\t\t\tj_ = i;\n\t\t\t}\n\t\t}\n\t\tcc[i] = k;\n\t\treturn k;\n\t}\n\tint a, b;\n\tvoid dfs_(int p, int i, int c, boolean print) {\n\t\tif (print) {\n\t\t\ta += b;\n\t\t\tprintln((p + 1) + \" \" + (i + 1) + \" \" + (a - c));\n\t\t\tc = a;\n\t\t}\n\t\tfor (int l = ao[i]; l != 0; l = next[l]) {\n\t\t\tint j = jj[l];\n\t\t\tif (j != p)\n\t\t\t\tdfs_(i, j, c, true);\n\t\t}\n\t}\n\tvoid main() {\n\t\tn = sc.nextInt();\n\t\tif (n == 1)\n\t\t\treturn;\n\t\tinit();\n\t\tfor (int h = 0; h < n - 1; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\tao[i] = link(ao[i], j);\n\t\t\tao[j] = link(ao[j], i);\n\t\t}\n\t\tdfs(-1, 0);\n\t\tif (n_ * 3 >= n) {\n\t\t\tb = 1;\n\t\t\ta = 0;\n\t\t\tdfs_(i_, j_, 0, false);\n\t\t\tb = n - n_;\n\t\t\ta = 0;\n\t\t\tdfs_(j_, i_, 0, true);\n\t\t} else {\n\t\t\tint s = j_;\n\t\t\tdfs(-1, s);\n\t\t\tInteger[] tt = new Integer[n];\n\t\t\tint cnt = 0;\n\t\t\tfor (int l = ao[s]; l != 0; l = next[l])\n\t\t\t\ttt[cnt++] = jj[l];\n\t\t\tArrays.sort(tt, 0, cnt, (i, j) -> cc[i] - cc[j]);\n\t\t\tn_ = 1;\n\t\t\tb = 1;\n\t\t\ta = 0;\n\t\t\tboolean changed = false;\n\t\t\tfor (int h = 0; h < cnt; h++) {\n\t\t\t\tint j = tt[h];\n\t\t\t\tn_ += cc[j];\n\t\t\t\tdfs_(s, j, 0, true);\n\t\t\t\tif (!changed && n_ * 3 >= n) {\n\t\t\t\t\tchanged = true;\n\t\t\t\t\tb = n_;\n\t\t\t\t\ta = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "90b1c2030744c9884c8c3a83d3495672", "src_uid": "87d755df6ee27b381122062659c4a432", "difficulty": 2700.0} {"lang": "Java 8", "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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bbbf1a6d175c9e07a634b5d0d7a979c4", "src_uid": "0034806908c9794086736a2d07fc654c", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\nimport static java.util.Arrays.fill;\n\n/**\n * @author Don Li\n */\npublic class WrapAround2 {\n \n int N = 41;\n \n int n, m;\n char[] s;\n \n int[] f;\n long[][][][] dp = new long[N][N][N][2];\n \n void solve() {\n n = in.nextInt();\n s = in.nextToken().toCharArray();\n m = s.length;\n \n f = fail(s);\n \n for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < N; k++) fill(dp[i][j][k], -1);\n \n long ans = 0;\n for (int i = 0; i <= m; i++) {\n ans += dfs(n, i, i, 0);\n }\n out.println(ans);\n }\n \n long dfs(int rem, int cur, int tar, int has) {\n if (cur == m) has = 1;\n \n if (rem == 0) {\n return cur == tar && has > 0 ? 1 : 0;\n }\n \n if (dp[rem][cur][tar][has] >= 0) return dp[rem][cur][tar][has];\n \n long ans = 0;\n for (char x = '0'; x <= '1'; x++) {\n int nxt = next(cur, x);\n ans += dfs(rem - 1, nxt, tar, has);\n }\n return dp[rem][cur][tar][has] = ans;\n }\n \n int next(int now, char x) {\n if (now == m) now = f[now];\n while (now > 0 && s[now] != x) now = f[now];\n return s[now] == x ? now + 1 : 0;\n }\n \n int[] fail(char[] s) {\n int n = s.length;\n int[] f = new int[n + 1];\n f[0] = f[1] = 0;\n for (int i = 2; i <= n; i++) {\n int j = f[i - 1];\n while (j > 0 && s[j] != s[i - 1]) j = f[j];\n f[i] = s[j] == s[i - 1] ? j + 1 : 0;\n }\n return f;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new WrapAround2().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b308bc42d658ef160a3bf03bd77575a9", "src_uid": "0034806908c9794086736a2d07fc654c", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\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\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 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 for(int suff_len = 0; suff_len < s.length(); suff_len++) {\n\n // calculate initial next state\n int pref = 0;\n for(int i = s.length() - suff_len; i < s.length(); i++) {\n while(pref != -1 && s.charAt(i) != s.charAt(pref)) pref = f[pref];\n ++pref;\n }\n\n dp = new long[n + 1][s.length() + 1]; // dp[i][index to look for i+1]\n\n // base case\n dp[suff_len][pref + 1] = 1;\n int tmp = pref;\n char val = s.charAt(pref) == '0' ? '1' : '0';\n while(tmp != -1 && s.charAt(tmp) != val) tmp = f[tmp];\n dp[suff_len][tmp + 1] = 1;\n\n for(int i = suff_len; i < n - 1; i++) {\n for(int state = 0; state < s.length(); state++) {\n dp[i + 1][state + 1] += dp[i][state];\n tmp = state;\n val = s.charAt(state) == '0' ? '1' : '0';\n while(tmp != -1 && s.charAt(tmp) != val) tmp = f[tmp];\n dp[i + 1][tmp + 1] += dp[i][state];\n }\n dp[i + 1][s.length()] += dp[i][s.length()] << 1;\n }\n ans += dp[n - 1][s.length() - suff_len];\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fe069c9a8668331ab279ce130cff384a", "src_uid": "0034806908c9794086736a2d07fc654c", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\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\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 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// System.out.println(\"f[i] \" + i + \" \" + f[i]);\n }\n\n for(int suff_len = 0; suff_len < s.length(); suff_len++) {\n\n // calculate initial next state\n int pref = 0;\n for(int i = s.length() - suff_len; i < s.length(); i++) {\n while(pref != -1 && s.charAt(i) != s.charAt(pref)) pref = f[pref];\n ++pref;\n }\n\n dp = new long[n + 1][s.length() + 1]; // dp[i][index to look for i+1]\n\n // base case\n dp[suff_len][pref + 1] = 1;\n int tmp = pref;\n char val = s.charAt(pref) == '0' ? '1' : '0';\n while(tmp != -1 && s.charAt(tmp) != val) tmp = f[tmp];\n dp[suff_len][tmp + 1] = 1;\n\n for(int i = suff_len; i < n - 1; i++) {\n for(int state = 0; state < s.length(); state++) {\n dp[i + 1][state + 1] += dp[i][state];\n tmp = state;\n val = s.charAt(state) == '0' ? '1' : '0';\n while(tmp != -1 && s.charAt(tmp) != val) tmp = f[tmp];\n dp[i + 1][tmp + 1] += dp[i][state];\n }\n if(suff_len == 0) dp[i + 1][s.length()] += dp[i][s.length()] << 1;\n }\n// for(int i = suff_len; i < n; i++) {\n// for(int state = 0; state <= s.length(); state++) {\n// System.out.println(\"dp \" + i + \" \" + state + \" \" + dp[i][state]);\n// }\n// }\n for(int i = s.length() - 1; i > 0; i--) {\n if(f[i] > 0 && s.charAt(f[i] - 1) == s.charAt(i - 1))\n dp[n - 1][f[i]] += dp[n - 1][i];\n }\n ans += dp[n - 1][s.length() - suff_len];\n\n// System.out.println(\"answer \" + suff_len + \" \" + (s.length() - suff_len) + \" \" + pref + \" \" + dp[n - 1][s.length() - suff_len]);\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d183fef1f9b630e643d1d97b028b3a05", "src_uid": "0034806908c9794086736a2d07fc654c", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.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[] intPow2Bufs = new Buffer[30];\n public static Buffer[] 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 {\n private Deque deque;\n private Supplier supplier;\n private Consumer cleaner;\n private int allocTime;\n private int releaseTime;\n\n public Buffer(Supplier supplier) {\n this(supplier, (x) -> {\n });\n }\n\n public Buffer(Supplier supplier, Consumer cleaner) {\n this(supplier, cleaner, 0);\n }\n\n public Buffer(Supplier supplier, Consumer 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4ada157e2ae1fb2685eab895feb4aaf", "src_uid": "295baf6ccbfc3a7d098989a0701d2018", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.Arrays;\n\npublic class increasing_prefix_ors_3xNTT {\n\n final static long p = 1000000007;\n\n static class Value {\n int[] poly;\n long mul;\n\n public Value(int[] poly, long mul) {\n this.poly = poly;\n this.mul = mul;\n }\n\n Value mul(Value o) {\n return new Value(Arrays.copyOf(polyMul(substitute(poly, o.mul), o.poly), poly.length), mul * o.mul % p);\n }\n }\n\n static Value pow(Value x, Value one, long pow) {\n while (pow > 0) {\n if (pow % 2 == 1) {\n one = one.mul(x);\n }\n pow /= 2;\n x = x.mul(x);\n }\n return one;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n // d'_j*(k-j)! += d_i*(k-i)! / (j-i)! * 2^i\n long n = in.nextLong();\n int k = in.nextInt();\n if (n > k + 1) {\n out.println(0);\n return;\n }\n int[] poly0 = new int[k + 1];\n int[] poly1 = new int[k + 1];\n for (int i = 1; i <= k; ++i) {\n poly0[i] = (int) (fact[k] * invFact[i] % p);\n poly1[i] = (int) invFact[i];\n }\n Value v = pow(new Value(poly1, 2), new Value(poly0, 1), n - 1);\n long ans = 0;\n for (int i = 0; i <= k; ++i) {\n ans = (ans + v.poly[i] * invFact[k - i]) % p;\n }\n out.println(ans);\n }\n\n static int max = 30000;\n static long[] fact, invFact, invs;\n static {\n fact = new long[max + 1];\n invFact = new long[max + 1];\n fact[0] = 1;\n invFact[0] = 1;\n invs = new long[max + 1];\n for (int i = 1; i <= max; ++i) {\n invs[i] = i == 1 ? 1 : (int) (p - invs[((int) (p % i))] * (p / i) % p);\n fact[i] = fact[i - 1] * i % p;\n invFact[i] = invFact[i - 1] * invs[i] % p;\n }\n }\n\n static long modInverse(long x, long mod) {\n return modPow(x, mod - 2, mod);\n }\n\n static long modPow(long x, long pow, long mod) {\n long r = 1;\n while (pow > 0) {\n if (pow % 2 == 1) {\n r = (r * x) % mod;\n }\n pow /= 2;\n x = (x * x) % mod;\n }\n return r;\n }\n\n static int[] substitute(int[] a, long c) {\n int[] r = new int[a.length];\n long pow = 1;\n for (int i = 0; i < a.length; ++i) {\n r[i] = (int) (a[i] * pow % p);\n pow = pow * c % p;\n }\n return r;\n }\n\n static class FFT {\n int[][] tail;\n int[][] omegas;\n final int mod;\n final int LOG = 18;\n\n int G;\n\n FFT(int mod, int g) {\n this.mod = mod;\n G = g;\n tail = new int[LOG][];\n omegas = new int[LOG][];\n for (int l = 0; l < LOG; l++) {\n tail[l] = new int[1 << l];\n omegas[l] = new int[1 << l];\n int w = (int)modPow(G, (mod - 1) / (1 << l), mod);\n\n omegas[l][0] = 1;\n for (int i = 1; i < 1 << l; i++) {\n tail[l][i] = (tail[l][i >> 1] >> 1) | ((i & 1) << (l - 1));\n omegas[l][i] = (int) ((1l * omegas[l][i - 1] * w) % mod);\n }\n }\n }\n\n void doFFT(int[] a, int size, boolean inverse) {\n int l = Integer.numberOfTrailingZeros(size);\n int[] tail = this.tail[l], omegas = this.omegas[l];\n for (int i = 0; i < size; i++) {\n if (i < tail[i]) {\n int tmp = a[i];\n a[i] = a[tail[i]];\n a[tail[i]] = tmp;\n }\n }\n for (int len = 2; len <= size; len *= 2) {\n int add = size / len;\n for (int i = 0; i < size; i += len) {\n int pos = 0;\n for (int j = 0, k = len / 2; k < len; j++, k++) {\n int u = a[i + j], v = (int) ((1l * a[i + k] * omegas[pos]) % mod);\n a[i + j] = (u + v);\n a[i + k] = (u - v + mod);\n if (a[i + j] >= mod) {\n a[i + j] -= mod;\n }\n if (a[i + k] >= mod) {\n a[i + k] -= mod;\n }\n\n if (inverse) {\n pos -= add;\n if (pos < 0) {\n pos += size;\n }\n } else {\n pos += add;\n }\n }\n }\n }\n if (inverse) {\n int inv = (int)modInverse(size, mod);\n for (int i = 0; i < size; i++) {\n a[i] = (int) ((1L * inv * a[i]) % mod);\n }\n }\n }\n\n int[] conv(int[] a, int[] b) {\n int size = 1;\n while (size < a.length || size < b.length) {\n size *= 2;\n }\n size *= 2;\n a = Arrays.copyOf(a, size);\n b = Arrays.copyOf(b, size);\n doFFT(a, size, false);\n doFFT(b, size, false);\n for (int i = 0; i < size; ++i) {\n a[i] = (int) (1L * a[i] * b[i] % mod);\n }\n doFFT(a, size, true);\n return a;\n }\n }\n\n final static int mod1 = 998244353; // G = 3\n final static int mod2 = 1012924417; // G = 5\n final static int mod3 = 1045430273; // G = 3\n\n final static CRT e = new CRT(mod1, mod2, mod3);\n final static FFT fft1 = new FFT(mod1, 3);\n final static FFT fft2 = new FFT(mod2, 5);\n final static FFT fft3 = new FFT(mod3, 3);\n\n private static int[] polyMul(int[] a, int[] b) {\n int n = a.length;\n int[] a1 = fft1.conv(a, b);\n int[] a2 = fft2.conv(a, b);\n int[] a3 = fft3.conv(a, b);\n a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = (int) (e.crt(a1[i], a2[i], a3[i]).mod(BigInteger.valueOf(p)).longValue());\n }\n return a;\n }\n\n static class CRT {\n long[] mods;\n long[][] r;\n\n public CRT(long... mods) {\n this.mods = mods;\n r = new long[mods.length][mods.length];\n for (int i = 0; i < mods.length; ++i) {\n for (int j = i + 1; j < mods.length; ++j) {\n r[i][j] = modInverse(mods[i], mods[j]);\n }\n }\n }\n\n BigInteger crt(long... rs) {\n BigInteger result = BigInteger.ZERO, mult = BigInteger.ONE;\n for (int i = 0; i < rs.length; ++i) {\n for (int j = 0; j < i; ++j) {\n long cur = (rs[i] - rs[j]) * r[j][i];\n rs[i] = (int)((cur % mods[i] + mods[i]) % mods[i]);\n }\n result = result.add(mult.multiply(BigInteger.valueOf(rs[i])));\n mult = mult.multiply(BigInteger.valueOf(mods[i]));\n }\n return result;\n }\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60ea6904a0279cfa1577da395ef3276b", "src_uid": "295baf6ccbfc3a7d098989a0701d2018", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.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) 1e4, 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[] intPow2Bufs = new Buffer[30];\n public static Buffer[] 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 {\n private Deque deque;\n private Supplier supplier;\n private Consumer cleaner;\n private int allocTime;\n private int releaseTime;\n\n public Buffer(Supplier supplier) {\n this(supplier, (x) -> {\n });\n }\n\n public Buffer(Supplier supplier, Consumer cleaner) {\n this(supplier, cleaner, 0);\n }\n\n public Buffer(Supplier supplier, Consumer 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4e5978117810fd0b3317069b5257f2fa", "src_uid": "295baf6ccbfc3a7d098989a0701d2018", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.*;\nimport static java.lang.Math.max;\nimport static java.lang.Math.pow;\nimport java.lang.reflect.*;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\nimport java.security.CodeSource;\nimport java.security.KeyStore;\nimport java.util.*;\nimport static java.util.Arrays.*;\nimport java.util.jar.JarEntry;\nimport java.util.jar.JarFile;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\n\n// https://netbeans.org/kb/73/java/editor-codereference_ru.html#display\n\npublic class Main {\n\n private void run() throws Exception {\n err = System.err;\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 }\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 solve();\n \n out.flush();\n }\n \n FastScanner sc;\n PrintWriter out;\n PrintStream err;\n \n \n 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 private int getBit(int msk, int pos) {\n return (msk >> pos) & 1;\n }\n\n class 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 MLE();\n }\n return st.nextToken();\n }\n \n int nextInt(){ return Integer.parseInt(next());}\n }\n\n public static void main(String[] args) throws Exception {\n new Main().run();\n }\n \n //-------------------------------------------------------------------//\n \n \n final long mod = (long)1e9 + 7;\n int n;\n \n void solve(){\n// int p = 5;\n// out.println( new BF((1<> pos) & 1;\n }\n\n class 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 MLE();\n }\n return st.nextToken();\n }\n \n int nextInt(){ return Integer.parseInt(next());}\n }\n\n public static void main(String[] args) throws Exception {\n new Main().run();\n }\n \n //-------------------------------------------------------------------//\n \n long f( int n ){ return n <= 1? 1 : n * f(n-1); } \n \n long C( int m, int n ){\n if(!( m <= n ))\n MLE();\n return f(n) / f(m) / f(n-m);\n }\n \n class BF{\n\n int nMax, ans, sz;\n int[] ord;\n \n \n BF( int _nMax ){\n nMax = _nMax;\n ord = new int[100];\n }\n \n void f( int val ){\n if( val == nMax + 1 ){\n if( sz == 0 ) return;\n int[] arr = Arrays.copyOf(ord, sz);\n \n for( int a : arr )\n for (int b : arr ) \n if( Arrays.binarySearch(arr, a^b) < 0 )\n return;\n \n ++ans;\n //show(arr);err.println();\n solveGaus(arr);\n }\n else{\n ord[sz++] = val;\n f(val+1);\n --sz;\n \n f(val+1);\n }\n }\n \n \n int bf(){\n f(0);\n return ans;\n }\n\n void solveGaus(int[] arr) {\n \n err.println( \"ans: \" + ans );\n show(arr);err.println();\n \n int[] jj = new int[100];\n int n = arr.length;\n int j = 25;\n for( int i = 0; i < n; ++i ){\n cyc:\n for( ; 0 <= j; --j ){\n for( int ii = i; ii < n; ++ii ){\n if( ((1<= 0; --bit) {\n int[][] nways = new int[32][2];\n if ((k & (1 << bit)) != 0) {\n for (int cnt = 0; cnt < 32; ++cnt) {\n if (ways[cnt][0] != 0) {\n nways[cnt + 1][0] = (nways[cnt + 1][0] + ways[cnt][0]) % MODULO;\n res = (int) ((res + ways[cnt][0] * (long) p2[cnt * bit] % MODULO * ((k & ((1 << bit) - 1)) + 1) % MODULO) % MODULO);\n nways[cnt][1] = (nways[cnt][1] + ways[cnt][0]) % MODULO;\n }\n }\n } else {\n for (int cnt = 0; cnt < 32; ++cnt) {\n if (ways[cnt][0] != 0) {\n nways[cnt][0] = (nways[cnt][0] + ways[cnt][0]) % MODULO;\n }\n }\n }\n\n for (int cnt = 0; cnt < 32; ++cnt) if (ways[cnt][1] != 0) {\n nways[cnt][1] = (nways[cnt][1] + ways[cnt][1]) % MODULO;\n nways[cnt + 1][1] = (nways[cnt + 1][1] + ways[cnt][1]) % MODULO;\n res = (int) ((res + ways[cnt][1] * (long) p2[(cnt + 1) * bit] % MODULO) % MODULO);\n }\n ways = nways;\n }\n out.println(res);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3bb98480ff3e24fa0358844df977d5f0", "src_uid": "ead64d8e3134fa8f29881cb487e52f60", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\t\tint n = in.nextInt();\n\t\tint x[] = new int[n], y[] = new int[n], t = 0;\n\t\tList s = new ArrayList();\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tx[i] = in.nextInt();\n\t\t\ty[i] = in.nextInt();\n\t\t\tif(x[i] < x[t])\n\t\t\t\tt = i;\n\t\t\ts.add(i);\n\t\t}\n\t\tSystem.out.print(t + 1 + \" \");\n\t\ts.remove(new Integer(t));\n\t\tString str = in.next();\n\t\tdouble ang = Math.PI / 2 - 1E-10;\n\t\tfor(int i = 0; i < str.length(); i++) {\n\t\t\tdouble m = 4;\n\t\t\tint im = -1, factor = (str.charAt(i) == 'L') ? 1 : -1;\n\t\t\tfor(int j : s) {\n\t\t\t\tdouble a = dif(Math.atan2(y[j] - y[t], x[j] - x[t]), ang) * factor;\n\t\t\t\tif(a < m) {\n\t\t\t\t\tm = a;\n\t\t\t\t\tim = j;\n\t\t\t\t}\n\t\t\t}\n\t\t\ts.remove(new Integer(im));\n\t\t\tang = Math.atan2(y[im] - y[t], x[im] - x[t]);\n\t\t\tt = im;\n\t\t\tSystem.out.print(t + 1 + \" \");\n\t\t}\n\t\tSystem.out.print(s.remove(0) + 1 + \" \");\n\t\tSystem.out.println();\n\t\tin.close();\n\n\t}\n\t\n\tprivate static double dif(double a1, double a2) {\n\t\tdouble d = a1 - a2;\n\t\twhile(d > Math.PI)\n\t\t\td -= 2 * Math.PI;\n\t\twhile(d < -Math.PI)\n\t\t\td += 2 * Math.PI;\n\t\treturn d;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "afcf9157b5c77dfd355bd7d467efcafa", "src_uid": "13d7f6127a7fe945e19d461b584c6228", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class ContactATC {\n \n int[] t;\n \n void solve() {\n int n = in.nextInt(), w = in.nextInt();\n int[] x = new int[n], v = new int[n];\n for (int i = 0; i < n; i++) {\n x[i] = -in.nextInt();\n v[i] = in.nextInt();\n }\n \n Fraction[] one = new Fraction[n];\n Fraction[] two = new Fraction[n];\n for (int i = 0; i < n; i++) {\n one[i] = new Fraction(x[i], v[i] - w);\n two[i] = new Fraction(x[i], v[i] + w);\n }\n \n Fraction[] uOne = unique(one);\n Fraction[] uTwo = unique(two);\n \n Plane[] planes = new Plane[n];\n for (int i = 0; i < n; i++) {\n planes[i] = new Plane(Arrays.binarySearch(uOne, one[i]), Arrays.binarySearch(uTwo, two[i]));\n }\n Arrays.sort(planes, (a, b) -> {\n if (a.t1 != b.t1) return Integer.compare(a.t1, b.t1);\n return -Integer.compare(a.t2, b.t2);\n });\n \n long ans = 0;\n t = new int[n];\n for (Plane p : planes) {\n ans += sum(n - 1) - sum(p.t2 - 1);\n add(p.t2, 1);\n }\n out.println(ans);\n }\n \n int sum(int i) {\n int res = 0;\n for (int x = i; x >= 0; x = (x & (x + 1)) - 1) res += t[x];\n return res;\n }\n \n void add(int i, int delta) {\n for (int x = i; x < t.length; x = x | (x + 1)) t[x] += delta;\n }\n \n Fraction[] unique(Fraction[] a) {\n a = Arrays.copyOf(a, a.length);\n Arrays.sort(a);\n int sz = 0;\n for (int i = 0; i < a.length; i++) {\n if (sz == 0 || a[i].compareTo(a[i - 1]) != 0) a[sz++] = a[i];\n }\n return Arrays.copyOf(a, sz);\n }\n \n static class Plane {\n int t1, t2;\n \n Plane(int t1, int t2) {\n this.t1 = t1;\n this.t2 = t2;\n }\n }\n \n static class Fraction implements Comparable {\n long a, b;\n \n Fraction(long a, long b) {\n if (b == 0) throw new AssertionError();\n if (b < 0) {\n a = -a;\n b = -b;\n }\n this.a = a;\n this.b = b;\n }\n \n @Override\n public int compareTo(Fraction o) {\n return Long.compare(a * o.b, b * o.a);\n }\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new ContactATC().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5e9e500837dc7754e544898bdebc7209", "src_uid": "d073d41f7e184e9bc4a12219d86e7184", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.*;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author chaku\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(),w=in.nextInt();\n bit=new int[100010];\n int[] x=new int[n];\n int[] v=new int[n];\n for(int i=0;i(){\n public int compare(Pair[] p1,Pair[] p2)\n {\n Pair f1=p1[1];\n Pair f2=p2[1];\n Pair s1=p1[0];\n Pair s2=p2[0];\n int v1=cmp(s1,s2);\n if(v1!=0)return v1;\n else \n {\n return cmp(f2,f1);\n }\n }\n });\n \n Pair[] list=new Pair[n];\n for(int i=0;i(){\n public int compare(Pair p1,Pair p2)\n {\n return cmp(p1,p2);\n }\n });\n /*\n for(Pair p:list)\n {\n out.println(p.a+\" \"+p.b);\n }\n */\n int ind=1;\n for(int i=1;i(){\n public int compare(Pair p1,Pair p2)\n {\n return cmp(p1,p2);\n }\n });\n if(index<0)index=-index-2;\n d[i]=index+1;\n //out.println(d[i]);\n }\n long ans=0;\n for(int i=0;i0)return 1;\n else if(l<0)return -1;\n return 0;\n }\n static int bit[];\n \n static void add(int x,int d,int n)\n {\n for(int i=x;i<=n;i+=i&-i)bit[i]+=d;\n }\n\n static int query(int x)\n {\n int ret=0;\n for(int i=x;i>0;i-=i&-i)ret+=bit[i];\n return ret;\n }\n \n static class Pair\n {\n int a;int b;\n public Pair(int a,int b)\n {\n this.a=Math.abs(a);this.b=Math.abs(b);\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 println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f9c9cd86faad56126f4d8400ae84c51e", "src_uid": "d073d41f7e184e9bc4a12219d86e7184", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "//package educational.round68;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class G3 {\n\tInputStream is;\n\tPrintWriter out;\n//\tString INPUT = \"42\";\n\tString INPUT = \"\";\n\t\n\tpublic static void trnz(long... o)\n\t{\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\n\t\tSystem.out.println();\n\t}\n\n\t\n\tvoid solve()\n\t{\n\t\tBigInteger n = new BigInteger(ns());\n\t\tlong ans = 0;\n\t\tfor(int i = 1;i <= 9;i++){\n\t\t\tfor(int j = 1;j <= i;j++){\n\t\t\t\tif(gcd(i, j) == 1){\n\t\t\t\t\tif(i == 1){\n\t\t\t\t\t\tans += n.mod(BigInteger.valueOf(998244353L)).longValue();\n\t\t\t\t\t}else{\n\t\t\t\t\t\tlong lans = count(n, i, j);\n\t\t\t\t\t\tif(i != j){\n\t\t\t\t\t\t\tans += lans*2;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tans += lans;\n\t\t\t\t\t\t}\n//\t\t\t\t\t\tif(lans > 0)tr(i, j, lans, ans);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans % 998244353);\n\t}\n\t\n\tlong count(BigInteger N, int u, int v)\n\t{\n\t\tchar[] s = (\"0\" + N.divide(BigInteger.valueOf(u)).add(BigInteger.ONE).toString()).toCharArray();\n\t\t\n\t\tint n = s.length;\n\t\t// u:2 v:1\n\t\t// u\u500d\u3057\u305f\u3068\u304d\u306bt*u\u3092\u542b\u3093\u3067\u3044\u308b\u304b\n\t\t// v\u500d\u3057\u305f\u3068\u304d\u306bt*v\u3092\u542b\u3093\u3067\u3044\u308b\u304b\n\t\tint w = 9/u;\n\t\tlong[][][][] dp = new long[1<= 0;i--){\n\t\t\tlong[][][][] ndp = new long[1<= mod)ndp[nj][nk][nl][nm] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor(int j = 0;j < 1<= mod)nep[nj][nk][nl][nm] -= mod;\n\t\t\t\t\t\t\t\tif(d < s[i]-'0'){\n\t\t\t\t\t\t\t\t\tndp[nj][nk][nl][nm] += ep[j][k][l][m];\n\t\t\t\t\t\t\t\t\tif(ndp[nj][nk][nl][nm] >= mod)ndp[nj][nk][nl][nm] -= mod;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tdp = ndp;\n\t\t\tep = nep;\n\t\t}\n\t\t\n\t\tlong ret = 0;\n\t\tfor(int i = 0;i < 1< 0) {\n\t\t\tint c = a;\n\t\t\ta = b;\n\t\t\tb = c % b;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new G3().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7de5308c12b7aeac2adbbe0d4853b09c", "src_uid": "b6f2061e2ca174c2385bf4520d232aaf", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\n static int[][] precalc = new int[][]{{0},{2,1},{32,30,80,109},{6824,59808,147224,415870,1757896,1897056,4898872,7593125},{776830421,290516100,746623577,293783147,33900006,735127505,565460332,428982705,472062098,161873957,117354594,515619293,578944191,312106242,569389279,391464593},{261086313,584837659,683961846,468868529,211593382,736955478,229471758,157617135,398169441,360252438,629394768,264125799,647490480,342079395,391579767,225200475,486011304,513156108,628771752,132906648,142138221,20119449,444199674,195188679,387329805,44684703,651912135,737154512,612549793,519860281,186175544,212568440},{240805271,239509872,581127897,6511239,156126222,509425833,672407328,366667722,459185405,509737025,554790222,165216555,703150560,74806569,398730015,383350905,506108358,51326142,298053147,104256117,391428765,374020479,206607807,87664059,275899176,56407680,551553401,448939463,582889860,129676638,226078251,135769095,61292868,578972226,190181628,390739055,184587732,446575689,732674124,232198470,676760679,352474101,611444862,575661807,628905585,320813094,522840969,469781928,156006018,554473341,239654268,643714911,433540170,199307003,496385218,291740751,67309914,370826673,202356819,279421821,421203111,63744786,520987612,550671827},{482164403,768209115,462063756,154906374,36099042,341766705,678182556,621882744,478771358,231881111,175889805,243630450,168908523,671961765,55761813,652682670,773939082,517628076,756201264,124604900,750976272,498253248,676047609,137170026,705610017,495032139,561797418,703097347,500815609,95984586,739707108,265613565,387099846,777331779,594676173,591219559,407997044,208947235,93337440,478908360,685013007,487033953,671903001,39521181,738490312,33785059,465470131,310453920,54648783,346831137,427694175,474743430,705296781,435828036,429824745,663532359,261388683,244690731,533997135,596108961,506813013,371892402,590145264,104733162,143420103,654339672,700348950,685038942,578826927,286484229,501639192,434962491,299270097,27702486,335375775,111746817,565603164,294926121,676063665,735862995,710035809,437011960,668528077,138765186,508213986,615036450,353784942,624827616,343900011,241289776,52410890,72018835,352406796,415705878,4802637,376367145,65589678,333633477,341834527,303717460,282387700,42951006,254706039,423048528,526429710,68131467,669954708,12787348,500636381,317959019,479433192,657133515,416259390,610216692,340129188,44594256,257373347,138718678,530767740,292922628,37220268,605295159,480722613,458170419,30540300,487159055,232966794,149150650},{412133651,386543325,139952108,289303402,102404925,317067177,396414708,80515854,663739304,317300809,228877044,493725043,715317967,490300965,315527373,743539734,488329191,553627998,533025234,242583957,706116537,614109258,645447222,523195911,492109128,722623041,111085128,766395126,654378921,691964847,496688157,399056049,654363234,102052314,191720088,473910948,259736526,332840025,388047555,665791056,627111387,139696515,441456687,443032569,283264821,771641703,452641455,511306362,117572859,127701891,721298331,176520078,357242229,611296308,696994956,405628839,429224274,465336054,695091546,689828796,574648641,351220905,507964023,675326610,517248963,453528621,220301928,494463186,681789969,339589656,44524053,417125457,339589404,747135963,341780733,734158215,396817281,21997836,5728464,147611205,456248898,714128667,377654949,3862068,128418948,589390074,304947090,11703825,228266073,127304142,429215724,361541124,521572968,468358191,341231688,65323503,613778508,15985323,291661029,410970006,591638112,349541550,89967528,224922159,361094166,584206074,640051812,324264456,652625388,693768537,11740617,309238398,211085469,194905872,639416484,110110707,296645895,748118511,131177718,511142751,775975599,421403409,475528473,434685258,1768977,80301375,708023862,569195676,56238084,632887668,88089750,631539342,396695565,38780154,695798271,469819224,439587099,69045921,682966116,112310856,64943298,534475872,40215357,389728458,286368453,736006257,501181650,54829908,603489402,338032656,512182818,627500097,462674016,3103092,157324491,43978329,596818971,259025598,9088632,91991781,577291428,211245489,429471231,142626330,172560633,510907446,444609585,758102058,375112647,744786693,276174402,19259856,233672418,745389414,225772848,23385663,324290610,519804558,120337812,402578568,360676008,450089262,551043738,337388940,512108856,28879011,690040638,106017282,558262341,99972432,608226003,612152037,42414435,776201013,39580443,518796945,494437752,583194366,723936555,415359657,309569589,751104774,166684527,249229170,353120823,130668327,753823584,580966092,561963717,543672234,393846327,586278000,327398400,278403867,156455586,363920382,190245195,290039148,547014447,466218648,146037150,585462906,666008595,691786683,374707494,622498779,231158277,685740951,115612245,681825249,545555745,551718468,277206615,640171035,757727334,195193908,658656684,457760646,225925875,505761984,18685233,506832921,112511021,396846646,290147622,113924623,669986155,336008070,63611061,238586775,119956662,616557739,772784623,334527774,410403148,51933421}};\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n// out.print(\"{\");\n// for (int i = 1; i <= (1 << 8); i *= 2) {\n// System.err.println(i);\n// out.print(\"{\");\n// calcDP(i);\n// for (int j = 1; j <= i; ++j) {\n// out.print(dp[i][i][j]);\n// if (j == i) {\n// out.print(\"},\");\n// } else {\n// out.print(\",\");\n// }\n// }\n// }\n// out.print(\"}\");\n int n = in.nextInt();\n int k = in.nextInt();\n n = Integer.numberOfTrailingZeros(n);\n out.println(precalc[n][k-1]);\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}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "af7871943f9ea9db5bb693f759ef5f8c", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0} {"lang": "Java 7", "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\tstatic final int MOD = 777777777;\n\n\tint[][] c = new int[257][];\n\t{\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\tc[i] = new int[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 - 1] + c[i - 1][j];\n\t\t\t\tif (c[i][j] >= MOD)\n\t\t\t\t\tc[i][j] -= MOD;\n\t\t\t}\n\t\t}\n//\t\tSystem.err.println(Arrays.toString(c[4]));\n\t}\n\n\tint solve(int n, int kn) {\n\n\t\tint[] dp = new int[n + 1];\n\t\tdp[0] = 1;\n\n\t\tfor (int i = 1; i <= n; i++) {\n\n\t\t\tint[] next = new int[n + 1];\n\n\t\t\t// who said i?\n\t\t\tif (i == kn) {\n\t\t\t\tfor (int k = 0; k + i <= n; k++) {\n\t\t\t\t\tif (dp[k] != 0) {\n\t\t\t\t\t\tnext[k + i] += (int) ((long) dp[k] * c[n - k][i] % MOD);\n\t\t\t\t\t\tif (next[k + i] >= MOD)\n\t\t\t\t\t\t\tnext[k + i] -= MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// liars\n\t\t\t\tfor (int j = 0; j <= n; j++)\n\t\t\t\t\t// how many people said i\n\t\t\t\t\tif (j != i) {\n\t\t\t\t\t\tfor (int k = 0; k + j <= n; k++)\n\t\t\t\t\t\t\t// how many people already said\n\t\t\t\t\t\t\tif (dp[k] != 0) {\n\t\t\t\t\t\t\t\tnext[k + j] += (int) ((long) dp[k]\n\t\t\t\t\t\t\t\t\t\t* c[n - k][j] % MOD);\n\t\t\t\t\t\t\t\tif (next[k + j] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[k + j] -= MOD;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\t\t\tdp = next;\n\t\t}\n\n\t\treturn dp[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\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tout.println(solve(n, n - k));\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c94da8bf37c0fa6088f41b42aa9925b", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D_submit {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int[][] ANS = {\n\t\t\t{ 0, },\n\t\t\t{ 2, 1, },\n\t\t\t{ 32, 30, 80, 109, },\n\t\t\t{ 6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125, },\n\t\t\t{ 776830421, 290516100, 746623577, 293783147, 33900006, 735127505,\n\t\t\t\t\t565460332, 428982705, 472062098, 161873957, 117354594,\n\t\t\t\t\t515619293, 578944191, 312106242, 569389279, 391464593, },\n\t\t\t{ 261086313, 584837659, 683961846, 468868529, 211593382, 736955478,\n\t\t\t\t\t229471758, 157617135, 398169441, 360252438, 629394768,\n\t\t\t\t\t264125799, 647490480, 342079395, 391579767, 225200475,\n\t\t\t\t\t486011304, 513156108, 628771752, 132906648, 142138221,\n\t\t\t\t\t20119449, 444199674, 195188679, 387329805, 44684703,\n\t\t\t\t\t651912135, 737154512, 612549793, 519860281, 186175544,\n\t\t\t\t\t212568440, },\n\t\t\t{ 240805271, 239509872, 581127897, 6511239, 156126222, 509425833,\n\t\t\t\t\t672407328, 366667722, 459185405, 509737025, 554790222,\n\t\t\t\t\t165216555, 703150560, 74806569, 398730015, 383350905,\n\t\t\t\t\t506108358, 51326142, 298053147, 104256117, 391428765,\n\t\t\t\t\t374020479, 206607807, 87664059, 275899176, 56407680,\n\t\t\t\t\t551553401, 448939463, 582889860, 129676638, 226078251,\n\t\t\t\t\t135769095, 61292868, 578972226, 190181628, 390739055,\n\t\t\t\t\t184587732, 446575689, 732674124, 232198470, 676760679,\n\t\t\t\t\t352474101, 611444862, 575661807, 628905585, 320813094,\n\t\t\t\t\t522840969, 469781928, 156006018, 554473341, 239654268,\n\t\t\t\t\t643714911, 433540170, 199307003, 496385218, 291740751,\n\t\t\t\t\t67309914, 370826673, 202356819, 279421821, 421203111,\n\t\t\t\t\t63744786, 520987612, 550671827, },\n\t\t\t{ 482164403, 768209115, 462063756, 154906374, 36099042, 341766705,\n\t\t\t\t\t678182556, 621882744, 478771358, 231881111, 175889805,\n\t\t\t\t\t243630450, 168908523, 671961765, 55761813, 652682670,\n\t\t\t\t\t773939082, 517628076, 756201264, 124604900, 750976272,\n\t\t\t\t\t498253248, 676047609, 137170026, 705610017, 495032139,\n\t\t\t\t\t561797418, 703097347, 500815609, 95984586, 739707108,\n\t\t\t\t\t265613565, 387099846, 777331779, 594676173, 591219559,\n\t\t\t\t\t407997044, 208947235, 93337440, 478908360, 685013007,\n\t\t\t\t\t487033953, 671903001, 39521181, 738490312, 33785059,\n\t\t\t\t\t465470131, 310453920, 54648783, 346831137, 427694175,\n\t\t\t\t\t474743430, 705296781, 435828036, 429824745, 663532359,\n\t\t\t\t\t261388683, 244690731, 533997135, 596108961, 506813013,\n\t\t\t\t\t371892402, 590145264, 104733162, 143420103, 654339672,\n\t\t\t\t\t700348950, 685038942, 578826927, 286484229, 501639192,\n\t\t\t\t\t434962491, 299270097, 27702486, 335375775, 111746817,\n\t\t\t\t\t565603164, 294926121, 676063665, 735862995, 710035809,\n\t\t\t\t\t437011960, 668528077, 138765186, 508213986, 615036450,\n\t\t\t\t\t353784942, 624827616, 343900011, 241289776, 52410890,\n\t\t\t\t\t72018835, 352406796, 415705878, 4802637, 376367145,\n\t\t\t\t\t65589678, 333633477, 341834527, 303717460, 282387700,\n\t\t\t\t\t42951006, 254706039, 423048528, 526429710, 68131467,\n\t\t\t\t\t669954708, 12787348, 500636381, 317959019, 479433192,\n\t\t\t\t\t657133515, 416259390, 610216692, 340129188, 44594256,\n\t\t\t\t\t257373347, 138718678, 530767740, 292922628, 37220268,\n\t\t\t\t\t605295159, 480722613, 458170419, 30540300, 487159055,\n\t\t\t\t\t232966794, 149150650, },\n\t\t\t{ 412133651, 386543325, 139952108, 289303402, 102404925, 317067177,\n\t\t\t\t\t396414708, 80515854, 663739304, 317300809, 228877044,\n\t\t\t\t\t493725043, 715317967, 490300965, 315527373, 743539734,\n\t\t\t\t\t488329191, 553627998, 533025234, 242583957, 706116537,\n\t\t\t\t\t614109258, 645447222, 523195911, 492109128, 722623041,\n\t\t\t\t\t111085128, 766395126, 654378921, 691964847, 496688157,\n\t\t\t\t\t399056049, 654363234, 102052314, 191720088, 473910948,\n\t\t\t\t\t259736526, 332840025, 388047555, 665791056, 627111387,\n\t\t\t\t\t139696515, 441456687, 443032569, 283264821, 771641703,\n\t\t\t\t\t452641455, 511306362, 117572859, 127701891, 721298331,\n\t\t\t\t\t176520078, 357242229, 611296308, 696994956, 405628839,\n\t\t\t\t\t429224274, 465336054, 695091546, 689828796, 574648641,\n\t\t\t\t\t351220905, 507964023, 675326610, 517248963, 453528621,\n\t\t\t\t\t220301928, 494463186, 681789969, 339589656, 44524053,\n\t\t\t\t\t417125457, 339589404, 747135963, 341780733, 734158215,\n\t\t\t\t\t396817281, 21997836, 5728464, 147611205, 456248898,\n\t\t\t\t\t714128667, 377654949, 3862068, 128418948, 589390074,\n\t\t\t\t\t304947090, 11703825, 228266073, 127304142, 429215724,\n\t\t\t\t\t361541124, 521572968, 468358191, 341231688, 65323503,\n\t\t\t\t\t613778508, 15985323, 291661029, 410970006, 591638112,\n\t\t\t\t\t349541550, 89967528, 224922159, 361094166, 584206074,\n\t\t\t\t\t640051812, 324264456, 652625388, 693768537, 11740617,\n\t\t\t\t\t309238398, 211085469, 194905872, 639416484, 110110707,\n\t\t\t\t\t296645895, 748118511, 131177718, 511142751, 775975599,\n\t\t\t\t\t421403409, 475528473, 434685258, 1768977, 80301375,\n\t\t\t\t\t708023862, 569195676, 56238084, 632887668, 88089750,\n\t\t\t\t\t631539342, 396695565, 38780154, 695798271, 469819224,\n\t\t\t\t\t439587099, 69045921, 682966116, 112310856, 64943298,\n\t\t\t\t\t534475872, 40215357, 389728458, 286368453, 736006257,\n\t\t\t\t\t501181650, 54829908, 603489402, 338032656, 512182818,\n\t\t\t\t\t627500097, 462674016, 3103092, 157324491, 43978329,\n\t\t\t\t\t596818971, 259025598, 9088632, 91991781, 577291428,\n\t\t\t\t\t211245489, 429471231, 142626330, 172560633, 510907446,\n\t\t\t\t\t444609585, 758102058, 375112647, 744786693, 276174402,\n\t\t\t\t\t19259856, 233672418, 745389414, 225772848, 23385663,\n\t\t\t\t\t324290610, 519804558, 120337812, 402578568, 360676008,\n\t\t\t\t\t450089262, 551043738, 337388940, 512108856, 28879011,\n\t\t\t\t\t690040638, 106017282, 558262341, 99972432, 608226003,\n\t\t\t\t\t612152037, 42414435, 776201013, 39580443, 518796945,\n\t\t\t\t\t494437752, 583194366, 723936555, 415359657, 309569589,\n\t\t\t\t\t751104774, 166684527, 249229170, 353120823, 130668327,\n\t\t\t\t\t753823584, 580966092, 561963717, 543672234, 393846327,\n\t\t\t\t\t586278000, 327398400, 278403867, 156455586, 363920382,\n\t\t\t\t\t190245195, 290039148, 547014447, 466218648, 146037150,\n\t\t\t\t\t585462906, 666008595, 691786683, 374707494, 622498779,\n\t\t\t\t\t231158277, 685740951, 115612245, 681825249, 545555745,\n\t\t\t\t\t551718468, 277206615, 640171035, 757727334, 195193908,\n\t\t\t\t\t658656684, 457760646, 225925875, 505761984, 18685233,\n\t\t\t\t\t506832921, 112511021, 396846646, 290147622, 113924623,\n\t\t\t\t\t669986155, 336008070, 63611061, 238586775, 119956662,\n\t\t\t\t\t616557739, 772784623, 334527774, 410403148, 51933421, }, };\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tif ((1 << i) == n)\n\t\t\t\tout.println(ANS[i][k - 1]);\n\t}\n\n\tD_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 D_submit();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a976d7d4e066601860b00f082bbeabd2", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\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 = 777777777;\n static final int[][] C = IntegerUtils.getC(1000, MOD);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n out.println(calcDP(n, k));\n }\n\n int calcDP(int n, int k) {\n long[][][] dp = new long[n + 1][n + 1][n + 1];\n for (int i = 0; i <= n; ++i) {\n if (i == 1) {\n dp[1][i][0] = C[n][i];\n } else {\n dp[1][i][i] = C[n][i];\n }\n }\n for (int i = 1; i < n; ++i) {\n for (int j = 0; j <= n; ++j) {\n for (int p = 0; p <= k; ++p) {\n if (dp[i][j][p] != 0) {\n int rest = n - j;\n for (int am = 0; am <= rest; ++am) {\n if (am == i + 1) {\n dp[i+1][j + am][p] += dp[i][j][p] * C[rest][am];\n dp[i + 1][j + am][p] %= MOD;\n } else {\n if (p + am <= k) {\n dp[i + 1][j + am][p + am] += dp[i][j][p] * C[rest][am];\n dp[i + 1][j + am][p + am] %= MOD;\n }\n }\n }\n }\n }\n }\n }\n return (int)dp[n][n][k];\n }\n}\n\nclass IntegerUtils {\n\n public static int[][] getC(int N, int MOD) {\n int[][] C = new int[N][];\n for (int i = 0; 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 if (C[i][j] >= MOD) C[i][j] -= MOD;\n } else {\n C[i][j] = (C[i-1][j-1] + C[i-1][j]);\n if (C[i][j] >= MOD) C[i][j] -= MOD;\n }\n }\n }\n return C;\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}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c7dd4bc307f48ba5021a701dd969d981", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.EnumSet;\nimport javax.print.attribute.standard.Sides;\n \npublic class strings_kp2 {\n \n static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n static int[] tableLong;\n static int[] tableShort1;\n static int[] tableShort2;\n \n static int[] createTable(int[] w) {\n int[] table = new int[w.length];\n int pos = 2;\n int cnd = 0;\n \n table[0] = -1;\n while (pos < w.length) {\n if (w[pos - 1] == w[cnd]) {\n cnd++;\n table[pos] = cnd;\n pos++;\n \n } else if (cnd > 0) {\n cnd = table[cnd];\n } else {\n table[pos] = 0;\n pos++;\n }\n }\n return table;\n }\n \n private static int kmp(int[] w, int[] s, int[] table) {\n \n int m = 0;\n int i = 0;\n \n while (m + i < s.length) {\n if (w[i] == s[m + i]) {\n if (i == w.length - 1) {\n return m;\n }\n i++;\n } else {\n m = m + i - table[i];\n if (table[i] > -1) {\n i = table[i];\n } else {\n i = 0;\n }\n }\n \n }\n return s.length;\n }\n \n static enum Side {\n \n T {\n \n Side opposite() {\n return Side.B;\n }\n \n Side flip() {\n return Side.L;\n }\n }, L {\n \n Side opposite() {\n return Side.R;\n }\n \n Side flip() {\n return Side.T;\n }\n }, R {\n \n Side opposite() {\n return Side.L;\n }\n \n Side flip() {\n return Side.B;\n }\n }, B {\n \n Side opposite() {\n return Side.T;\n }\n \n Side flip() {\n return Side.R;\n }\n };\n Line[] lines;\n \n abstract Side opposite();\n \n abstract Side flip();\n }\n \n static int nextInt() {\n try {\n st.nextToken();\n return (int) st.nval;\n } catch (IOException ex) {\n return 0;\n }\n }\n \n static Side nextSide() {\n try {\n st.nextToken();\n switch (st.sval.charAt(0)) {\n case 'T':\n return Side.T;\n case 'L':\n return Side.L;\n case 'R':\n return Side.R;\n default:\n return Side.B;\n }\n } catch (IOException ex) {\n return Side.T;\n }\n }\n \n static enum Type {\n \n TL, TR, TB, LR, LB, RB;\n int count;\n }\n \n static int getType(int start, int end) {\n switch (start) {\n case 0:\n switch (end) {\n case 1:\n return 0;\n case 2:\n return 1;\n default:\n return 2;\n }\n case 1:\n switch (end) {\n case 2:\n return 3;\n default:\n return 4;\n }\n default:\n return 5;\n }\n }\n \n static final class Line {\n \n Side s1, s2;\n int a, b;\n Type type;\n boolean used;\n \n private Line(Side s1, Side s2, int a, int b) {\n if (s1.ordinal() > s2.ordinal()) {\n Side t = s1;\n s1 = s2;\n s2 = t;\n int ti = a;\n a = b;\n b = ti;\n }\n this.s1 = s1;\n this.s2 = s2;\n this.a = a;\n this.b = b;\n s1.lines[a] = this;\n s2.lines[b] = this;\n setType();\n }\n \n public String toString() {\n return \"(\" + s1 + \":\" + a + \",\" + s2 + \":\" + b + \")\";\n }\n \n void setType() {\n switch (s1) {\n case T:\n switch (s2) {\n case R:\n type = Type.TR;\n break;\n case L:\n type = Type.TL;\n break;\n default:\n type = Type.TB;\n }\n break;\n case L:\n switch (s2) {\n case R:\n type = Type.LR;\n break;\n default:\n type = Type.LB;\n }\n break;\n default:\n type = Type.RB;\n }\n }\n }\n static int n, m;\n static boolean flip;\n static int shortCount;\n static ArrayList theCycle = new ArrayList();\n static ArrayList> allCycles = new ArrayList>();\n static ArrayList cyclePoints = new ArrayList();\n static ArrayList> allPoints = new ArrayList>();\n static ArrayList cycleSides = new ArrayList();\n static ArrayList rotations = new ArrayList();\n \n static boolean findSolution() {\n if (Type.LR.count > 0) {\n return false;\n }\n if (Type.TR.count != Type.LB.count) {\n return false;\n }\n if (Type.TL.count != Type.RB.count) {\n return false;\n }\n if (Type.TB.count != m - (Type.TL.count + Type.TR.count)) {\n return false;\n }\n shortCount = Math.min(Type.TL.count, Type.TR.count);\n \n int topSize = m - (shortCount * 2);\n int sideSize = n - (shortCount * 2);\n \n if (Type.TL.count == Type.TR.count) {\n theCycle.add(Type.TB.ordinal());\n cyclePoints.add(shortCount);\n cycleSides.add(0);\n allCycles.add(theCycle);\n allPoints.add(cyclePoints);\n for (int i = shortCount + 1; i < shortCount + topSize; i++) {\n ArrayList newCycle = new ArrayList();\n ArrayList newPoints = new ArrayList();\n newCycle.add(Type.TB.ordinal());\n newPoints.add(i);\n allCycles.add(newCycle);\n allPoints.add(newPoints);\n }\n return true;\n }\n boolean right = Type.TL.count < Type.TR.count;\n \n int l = Side.L.ordinal();\n int r = Side.R.ordinal();\n int t = Side.T.ordinal();\n int b = Side.B.ordinal();\n int[][] nextSides = new int[4][m];\n int[][] nextPoints = new int[4][m];\n if (right) {\n for (int i = 0; i < sideSize; i++) {\n nextSides[l][shortCount + i] = b;\n nextPoints[l][shortCount + i] = shortCount + sideSize - i - 1;\n nextSides[b][shortCount + sideSize - i - 1] = l;\n nextPoints[b][shortCount + sideSize - i - 1] = shortCount + i;\n \n nextSides[r][shortCount + i] = t;\n nextPoints[r][shortCount + i] = m - shortCount - i - 1;\n nextSides[t][m - shortCount - i - 1] = r;\n nextPoints[t][m - shortCount - i - 1] = shortCount + i;\n }\n \n for (int i = 0; i < topSize - sideSize; i++) {\n nextSides[t][shortCount + i] = b;\n nextPoints[t][shortCount + i] = shortCount + sideSize + i;\n nextSides[b][shortCount + sideSize + i] = t;\n nextPoints[b][shortCount + sideSize + i] = shortCount + i;\n }\n } else {\n for (int i = 0; i < sideSize; i++) {\n nextSides[l][shortCount + i] = t;\n nextPoints[l][shortCount + i] = shortCount + i;\n nextSides[t][shortCount + i] = l;\n nextPoints[t][shortCount + i] = shortCount + i;\n \n nextSides[r][shortCount + i] = b;\n nextPoints[r][shortCount + i] = m - shortCount - sideSize + i;\n nextSides[b][m - shortCount - sideSize + i] = r;\n nextPoints[b][m - shortCount - sideSize + i] = shortCount + i;\n }\n \n for (int i = 0; i < topSize - sideSize; i++) {\n nextSides[b][shortCount + i] = t;\n nextPoints[b][shortCount + i] = shortCount + sideSize + i;\n nextSides[t][shortCount + sideSize + i] = b;\n nextPoints[t][shortCount + sideSize + i] = shortCount + i;\n }\n }\n boolean[][] used = new boolean[4][m];\n int curSide = t;\n int curPos = shortCount;\n while (!used[curSide][curPos]) {\n used[curSide][curPos] = true;\n int nextSide = nextSides[curSide][curPos];\n int nextPos = nextPoints[curSide][curPos];\n theCycle.add(getType(curSide, nextSide));\n cyclePoints.add(curPos);\n cycleSides.add(curSide % 3 == 0 ? 0 : 1);\n curSide = 3 - nextSide;\n curPos = nextPos;\n }\n allCycles.add(theCycle);\n allPoints.add(cyclePoints);\n for (int i = shortCount; i < shortCount + topSize; i++) {\n if (!used[0][i]) {\n ArrayList newCycle = new ArrayList();\n ArrayList newPoints = new ArrayList();\n curSide = t;\n curPos = i;\n while (!used[curSide][curPos]) {\n used[curSide][curPos] = true;\n int nextSide = nextSides[curSide][curPos];\n int nextPos = nextPoints[curSide][curPos];\n newCycle.add(getType(curSide, nextSide));\n newPoints.add(curPos);\n curSide = 3 - nextSide;\n curPos = nextPos;\n }\n allCycles.add(newCycle);\n allPoints.add(newPoints);\n }\n }\n \n \n return true;\n }\n \n public static void main(String[] args) {\n n = nextInt();\n m = nextInt();\n \n if (n > m) {\n flip = true;\n int t = n;\n n = m;\n m = t;\n }\n \n Side.T.lines = new Line[m];\n Side.B.lines = new Line[m];\n Side.L.lines = new Line[n];\n Side.R.lines = new Line[n];\n \n \n ArrayList lines = new ArrayList();\n \n for (int i = 0; i < n + m; i++) {\n Side s1 = nextSide();\n Side s2 = nextSide();\n if (flip) {\n s1 = s1.flip();\n s2 = s2.flip();\n }\n lines.add(new Line(s1, s2, nextInt() - 1, nextInt() - 1));\n }\n for (Line l : lines) {\n l.type.count++;\n }\n \n if (!findSolution()) {\n System.out.println(\"No solution\");\n return;\n }\n int[] longCycle = new int[theCycle.size()];\n for (int i = 0; i < theCycle.size(); i++) {\n longCycle[i] = theCycle.get(i);\n }\n \n \n int[] shortCycle1 = {0, 4, 5, 1};\n int[] shortCycle2 = {0, 1, 5, 4};\n \n tableLong = createTable(longCycle);\n tableShort1 = createTable(shortCycle1);\n tableShort2 = createTable(shortCycle2);\n rotations.add(0);\n for (int i = 1; i < allCycles.size(); i++) {\n int length = theCycle.size();\n int[] curCycle = new int[length * 2];\n for (int j = 0; j < length; j++) {\n curCycle[j] = allCycles.get(i).get(j);\n }\n for (int j = 0; j < length; j++) {\n curCycle[j + length] = allCycles.get(i).get(j);\n }\n rotations.add(kmp(longCycle, curCycle, tableLong));\n }\n \n ArrayList> cycles = new ArrayList>();\n \n for (Line l : lines) {\n if (!l.used) {\n ArrayList cycle = new ArrayList();\n Line next = l;\n while (!next.used) {\n cycle.add(next);\n next.used = true;\n if (!next.s2.opposite().lines[next.b].used) {\n next = next.s2.opposite().lines[next.b];\n } else if (!next.s1.opposite().lines[next.a].used) {\n next = next.s1.opposite().lines[next.a];\n }\n }\n cycles.add(cycle);\n }\n }\n \n int actualShortCount = 0;\n int longCount = 0;\n \n int[] rows = new int[n];\n int[] cols = new int[m];\n \n for (ArrayList cycle : cycles) {\n int length = cycle.size();\n \n \n int[] curCycle = new int[length * 2];\n for (int i = 0; i < length; i++) {\n curCycle[i] = cycle.get(i).type.ordinal();\n }\n for (int i = 0; i < length; i++) {\n curCycle[length + i] = cycle.get(i).type.ordinal();\n }\n \n if (length == 4) {\n int rot1 = kmp(shortCycle1, curCycle, tableShort1);\n int rot2 = kmp(shortCycle2, curCycle, tableShort2);\n if (rot1 != 8 || rot2 != 8) {\n for (Line l : cycle) {\n if (l.type == Type.TL) {\n rows[actualShortCount] = l.b;\n cols[actualShortCount] = l.a;\n } else if (l.type == Type.RB) {\n rows[n - 1 - actualShortCount] = l.a;\n cols[m - 1 - actualShortCount] = l.b;\n }\n }\n actualShortCount++;\n continue;\n }\n }\n if (length != longCycle.length) {\n System.out.println(\"No solution\");\n return;\n }\n \n int rot = kmp(longCycle, curCycle, tableLong);\n if (rot == 2 * length) {\n System.out.println(\"No solution\");\n return;\n }\n for (int i = 0; i < length; i++) {\n int pos = allPoints.get(longCount).get((i + rotations.get(longCount)) % length);\n int value = cycle.get((rot + i) % length).a;\n if (cycleSides.get(i) == 0) {\n cols[pos] = value;\n } else {\n rows[pos] = value;\n }\n }\n longCount++;\n \n }\n \n if (flip) {\n int[] t = rows;\n rows = cols;\n cols = t;\n }\n \n for (int i = 0; i < rows.length; i++) {\n System.out.print((rows[i] + 1) + \" \");\n }\n System.out.println();\n for (int i = 0; i < cols.length; i++) {\n System.out.print((cols[i] + 1) + \" \");\n }\n System.out.println();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ca0a2676842add87aac91d9fb65065f6", "src_uid": "2ecce827acf880fd6b7692a4a3dffdf5", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Mixture {\n \n static long[] favorite = new long[3];\n static long[][] matrix = new long[3][3];\n \n static void add(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] += matrix[from][j];\n }\n }\n\n static void subtract(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] -= matrix[from][j];\n }\n }\n \n static void reduce(int a, int b) {\n while (favorite[a] != 0L && favorite[b] != 0L) {\n if (favorite[a] >= favorite[b]) {\n favorite[a] -= favorite[b];\n subtract(a, b);\n } else {\n favorite[b] -= favorite[a];\n subtract(b, a);\n }\n }\n if (favorite[a] != 0L) {\n favorite[b] += favorite[a];\n add(b, a);\n favorite[a] -= favorite[b];\n subtract(a, b);\n }\n }\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tokenizer = new StringTokenizer(in.readLine());\n for (int j = 0; j <= 2; j++) {\n favorite[j] = Long.parseLong(tokenizer.nextToken());\n matrix[j][j] = 1L;\n }\n reduce(0, 1);\n reduce(1, 2);\n /*for (int y = 0; y <= 2; y++) {\n for (int x = 0; x <= 2; x++) {\n System.out.print(matrix[y][x] + \" \");\n }\n System.out.println();\n }*/\n int amt00 = 0;\n int amtPosInfty = 0;\n int amtNegInfty = 0;\n int amtMatch = 0;\n TreeMap positive = new TreeMap<>();\n TreeMap negative = new TreeMap<>();\n int j = 0;\n int n = Integer.parseInt(in.readLine());\n long[] xs = new long[n + 1];\n long[] ys = new long[n + 1];\n StringBuilder out = new StringBuilder();\n for (; n > 0; n--) {\n tokenizer = new StringTokenizer(in.readLine());\n if (tokenizer.nextToken().charAt(0) == 'A') {\n j++;\n for (int a = 0; a <= 2; a++) {\n long k = Long.parseLong(tokenizer.nextToken());\n xs[j] += matrix[0][a] * k;\n ys[j] += matrix[1][a] * k;\n }\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00++;\n } else if (ys[j] > 0L) {\n amtPosInfty++;\n } else {\n amtNegInfty++;\n }\n } else {\n Rational q = new Rational(ys[j], xs[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && negative.containsKey(q)) {\n amtMatch++;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && positive.containsKey(q)) {\n amtMatch++;\n }\n }\n }\n } else {\n int j2 = j;\n j = Integer.parseInt(tokenizer.nextToken());\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00--;\n } else if (ys[j] > 0L) {\n amtPosInfty--;\n } else {\n amtNegInfty--;\n }\n } else {\n Rational q = new Rational(ys[j], xs[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && negative.containsKey(q)) {\n amtMatch--;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && positive.containsKey(q)) {\n amtMatch--;\n }\n }\n }\n j = j2;\n }\n if (amt00 > 0) {\n out.append(1);\n } else if (amtMatch > 0 || (amtPosInfty > 0 && amtNegInfty > 0)) {\n out.append(2);\n } else {\n boolean exists = false;\n if (positive.size() >= 2) {\n Rational q = negative.ceilingKey(positive.firstKey());\n if (q != null && q.compareTo(positive.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && negative.size() >= 2) {\n Rational q = positive.ceilingKey(negative.firstKey());\n if (q != null && q.compareTo(negative.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && amtPosInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.firstKey();\n Rational r = negative.lastKey();\n Rational s = new Rational(-r.num, r.denom);\n if (q.compareTo(s) < 0) {\n exists = true;\n }\n }\n if (!exists && amtNegInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.lastKey();\n Rational r = negative.firstKey();\n Rational s = new Rational(-r.num, r.denom);\n if (q.compareTo(s) > 0) {\n exists = true;\n }\n }\n if (exists) {\n out.append(3);\n } else {\n out.append(0);\n }\n }\n out.append('\\n');\n }\n System.out.print(out);\n }\n\n static class Rational implements Comparable {\n final long num;\n final long denom;\n\n Rational(long num, long denom) {\n if (denom > 0L) {\n this.num = num;\n this.denom = denom;\n } else {\n this.num = -num;\n this.denom = -denom;\n }\n }\n\n @Override\n public int compareTo(Rational other) {\n long d = (num * other.denom) - (other.num * denom);\n if (d > 0L) {\n return 1;\n } else if (d == 0L) {\n return 0;\n } else {\n return -1;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3c7f978d0c17ceb1425755fc6f6fa9cc", "src_uid": "ea995d5c5fe84cd175cda0d0e2f01889", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Mixture {\n \n static long[] favorite = new long[3];\n static long[][] matrix = new long[3][3];\n \n static void add(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] += matrix[from][j];\n }\n }\n\n static void subtract(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] -= matrix[from][j];\n }\n }\n \n static void reduce(int a, int b) {\n while (favorite[a] != 0L && favorite[b] != 0L) {\n if (favorite[a] >= favorite[b]) {\n favorite[a] -= favorite[b];\n subtract(a, b);\n } else {\n favorite[b] -= favorite[a];\n subtract(b, a);\n }\n }\n if (favorite[a] != 0L) {\n favorite[b] += favorite[a];\n add(b, a);\n favorite[a] -= favorite[b];\n subtract(a, b);\n }\n }\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tokenizer = new StringTokenizer(in.readLine());\n for (int j = 0; j <= 2; j++) {\n favorite[j] = Long.parseLong(tokenizer.nextToken());\n matrix[j][j] = 1L;\n }\n reduce(0, 1);\n reduce(1, 2);\n /*for (int y = 0; y <= 2; y++) {\n for (int x = 0; x <= 2; x++) {\n System.out.print(matrix[y][x] + \" \");\n }\n System.out.println();\n }*/\n int amt00 = 0;\n int amtPosInfty = 0;\n int amtNegInfty = 0;\n int amtMatch = 0;\n TreeMap positive = new TreeMap<>();\n TreeMap negative = new TreeMap<>();\n int j = 0;\n int n = Integer.parseInt(in.readLine());\n long[] xs = new long[n + 1];\n long[] ys = new long[n + 1];\n StringBuilder out = new StringBuilder();\n for (; n > 0; n--) {\n tokenizer = new StringTokenizer(in.readLine());\n if (tokenizer.nextToken().charAt(0) == 'A') {\n j++;\n for (int a = 0; a <= 2; a++) {\n long k = Long.parseLong(tokenizer.nextToken());\n xs[j] += matrix[0][a] * k;\n ys[j] += matrix[1][a] * k;\n }\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00++;\n } else if (ys[j] > 0L) {\n amtPosInfty++;\n } else {\n amtNegInfty++;\n }\n } else {\n Rational q = new Rational(xs[j], ys[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && negative.containsKey(q)) {\n amtMatch++;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && positive.containsKey(q)) {\n amtMatch++;\n }\n }\n }\n } else {\n int j2 = j;\n j = Integer.parseInt(tokenizer.nextToken());\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00--;\n } else if (ys[j] > 0L) {\n amtPosInfty--;\n } else {\n amtNegInfty--;\n }\n } else {\n Rational q = new Rational(xs[j], ys[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && negative.containsKey(q)) {\n amtMatch--;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && positive.containsKey(q)) {\n amtMatch--;\n }\n }\n }\n j = j2;\n }\n if (amt00 > 0) {\n out.append(1);\n } else if (amtMatch > 0 || (amtPosInfty > 0 && amtNegInfty > 0)) {\n out.append(2);\n } else {\n boolean exists = false;\n if (positive.size() >= 2) {\n Rational q = negative.ceilingKey(positive.firstKey());\n if (q != null && q.compareTo(positive.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && negative.size() >= 2) {\n Rational q = positive.ceilingKey(negative.firstKey());\n if (q != null && q.compareTo(negative.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && amtPosInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.firstKey();\n Rational r = negative.lastKey();\n Rational s = new Rational(-r.num, r.denom);\n if (q.compareTo(s) < 0) {\n exists = true;\n }\n }\n if (!exists && amtNegInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.lastKey();\n Rational r = negative.firstKey();\n Rational s = new Rational(-r.num, r.denom);\n if (q.compareTo(s) > 0) {\n exists = true;\n }\n }\n if (exists) {\n out.append(3);\n } else {\n out.append(0);\n }\n }\n out.append('\\n');\n }\n System.out.print(out);\n }\n\n static class Rational implements Comparable {\n final long num;\n final long denom;\n\n Rational(long num, long denom) {\n if (denom > 0L) {\n this.num = num;\n this.denom = denom;\n } else {\n this.num = -num;\n this.denom = -denom;\n }\n }\n\n @Override\n public int compareTo(Rational other) {\n long d = (num * other.denom) - (other.num * denom);\n if (d > 0L) {\n return 1;\n } else if (d == 0L) {\n return 0;\n } else {\n return -1;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "485a814703b05b44ca8e6bebac7b27fa", "src_uid": "ea995d5c5fe84cd175cda0d0e2f01889", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Mixture {\n \n static long[] favorite = new long[3];\n static long[][] matrix = new long[3][3];\n \n static void add(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] += matrix[from][j];\n }\n }\n\n static void subtract(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] -= matrix[from][j];\n }\n }\n \n static void reduce(int a, int b) {\n while (favorite[a] != 0L && favorite[b] != 0L) {\n if (favorite[a] >= favorite[b]) {\n favorite[a] -= favorite[b];\n subtract(a, b);\n } else {\n favorite[b] -= favorite[a];\n subtract(b, a);\n }\n }\n if (favorite[a] != 0L) {\n favorite[b] += favorite[a];\n add(b, a);\n favorite[a] -= favorite[b];\n subtract(a, b);\n }\n }\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tokenizer = new StringTokenizer(in.readLine());\n for (int j = 0; j <= 2; j++) {\n favorite[j] = Long.parseLong(tokenizer.nextToken());\n matrix[j][j] = 1L;\n }\n reduce(0, 1);\n reduce(1, 2);\n /*for (int y = 0; y <= 2; y++) {\n for (int x = 0; x <= 2; x++) {\n System.out.print(matrix[y][x] + \" \");\n }\n System.out.println();\n }*/\n int amt00 = 0;\n int amtPosInfty = 0;\n int amtNegInfty = 0;\n int amtMatch = 0;\n TreeMap positive = new TreeMap<>();\n TreeMap negative = new TreeMap<>();\n int j = 0;\n int n = Integer.parseInt(in.readLine());\n long[] xs = new long[n + 1];\n long[] ys = new long[n + 1];\n StringBuilder out = new StringBuilder();\n for (; n > 0; n--) {\n tokenizer = new StringTokenizer(in.readLine());\n if (tokenizer.nextToken().charAt(0) == 'A') {\n j++;\n for (int a = 0; a <= 2; a++) {\n long k = Long.parseLong(tokenizer.nextToken());\n xs[j] += matrix[0][a] * k;\n ys[j] += matrix[1][a] * k;\n }\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00++;\n } else if (ys[j] > 0L) {\n amtPosInfty++;\n } else {\n amtNegInfty++;\n }\n } else {\n Rational q = new Rational(xs[j], ys[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && negative.containsKey(q)) {\n amtMatch++;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && positive.containsKey(q)) {\n amtMatch++;\n }\n }\n }\n } else {\n int j2 = j;\n j = Integer.parseInt(tokenizer.nextToken());\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00--;\n } else if (ys[j] > 0L) {\n amtPosInfty--;\n } else {\n amtNegInfty--;\n }\n } else {\n Rational q = new Rational(xs[j], ys[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && negative.containsKey(q)) {\n amtMatch--;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && positive.containsKey(q)) {\n amtMatch--;\n }\n }\n }\n j = j2;\n }\n if (amt00 > 0) {\n out.append(1);\n } else if (amtMatch > 0 || (amtPosInfty > 0 && amtNegInfty > 0)) {\n out.append(2);\n } else {\n boolean exists = false;\n if (positive.size() >= 2) {\n Rational q = negative.ceilingKey(positive.firstKey());\n if (q != null && q.compareTo(positive.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && negative.size() >= 2) {\n Rational q = positive.ceilingKey(negative.firstKey());\n if (q != null && q.compareTo(negative.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && amtPosInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.firstKey();\n Rational r = negative.lastKey();\n Rational s = new Rational(-r.num, r.denom);\n if (q.compareTo(s) < 0) {\n exists = true;\n }\n }\n if (!exists && amtNegInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.firstKey();\n Rational r = negative.lastKey();\n Rational s = new Rational(-r.num, r.denom);\n if (q.compareTo(s) > 0) {\n exists = true;\n }\n }\n if (exists) {\n out.append(3);\n } else {\n out.append(0);\n }\n }\n out.append('\\n');\n }\n System.out.print(out);\n }\n\n static class Rational implements Comparable {\n final long num;\n final long denom;\n\n Rational(long num, long denom) {\n if (denom > 0L) {\n this.num = num;\n this.denom = denom;\n } else {\n this.num = -num;\n this.denom = -denom;\n }\n }\n\n @Override\n public int compareTo(Rational other) {\n long d = (num * other.denom) - (other.num * denom);\n if (d > 0L) {\n return 1;\n } else if (d == 0L) {\n return 0;\n } else {\n return -1;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1974da7d947730c2ed14f78e042b5d32", "src_uid": "ea995d5c5fe84cd175cda0d0e2f01889", "difficulty": 2900.0} {"lang": "Java 11", "source_code": "//package bubblecup13.f;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class M {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni();\n\t\tList cols = new ArrayList<>();\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tcols.add(i);\n\t\t}\n\t\tint[] minima = new int[n];\n\t\tArrays.fill(minima, m-1);\n\t\tint[] valmin = new int[n];\n\t\tArrays.fill(valmin, Integer.MAX_VALUE);\n\t\tSMAWK(cols, 0, n-1, 1, minima, valmin);\n\n\t\tint ans = 0;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(valmin[i] < valmin[ans]){\n\t\t\t\tans = i;\n\t\t\t}\n\t\t}\n\t\tout.println(\"! \" + valmin[ans]);\n\t\tout.flush();\n\t}\n\n\tMap cache = new HashMap<>();\n\n\tint f(int i, int j)\n\t{\n\t\tlong code = (long)i<<32|j;\n\t\tif(cache.containsKey(code))return cache.get(code);\n\t\tout.println(\"? \" + (i+1) + \" \" + (j+1));\n\t\tout.flush();\n\t\tint ret = ni();\n\t\tcache.put(code, ret);\n\t\treturn ret;\n\t}\n\n\tvoid SMAWK(List js, int ib, int ie, int id, int[] minima, int[] valmin) {\n\t\tif (ib > ie) return;\n\n\t\tDeque js2 = new ArrayDeque<>();\n\t\tfor (int q = 0, i = ib; q < js.size(); ++q) {\n\t\t\twhile (!js2.isEmpty() && f(i, js2.getLast()) >= f(i, js.get(q))) {\n\t\t\t\tjs2.pollLast(); i -= id; }\n\t\t\tif ( js2.size() != (ie-ib)/id ) {\n\t\t\t\tjs2.addLast(js.get(q)); i += id; }\n\t\t}\n\n\t\tSMAWK(new ArrayList<>(js2), ib+id, ie, id*2, minima, valmin);\n\n\t\tfor (int i = ib, q = 0; i <= ie; i += id*2) {\n\t\t\tint jt = (i + id <= ie ? minima[i+id] : js.get(js.size()-1));\n\t\t\tint fm = Integer.MAX_VALUE, fq;\n\t\t\tfor (; q < js.size(); ++q) {\n\t\t\t\tif ( fm > (fq = f(i, js.get(q))) ) {\n\t\t\t\t\tfm = fq;\n\t\t\t\t\tminima[i] = js.get(q);\n\t\t\t\t\tvalmin[i] = fq;\n\t\t\t\t}\n\t\t\t\tif (js.get(q).equals(jt)) break;\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new M().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a0f9ac74951b95063c67df0725c0a6e", "src_uid": "d663fcd3c550d7e4987010e07c001422", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n long[] cnt;\n int n;\n long[] a;\n long[] b;\n\n boolean check(long day) {\n for (int i = 0; i < n; ++i) b[i] = a[i];\n long r = day / (7 * n);\n for (int i = 0; i < n; ++i) {\n b[i] -= r * cnt[i];\n if (b[i] <= 0) return true;\n }\n int mod = (int) (day % (7 * n));\n int th = 0;\n int id = 0;\n for (int i = 0; i < mod; ++i) {\n if (th != 6) {\n b[id]--;\n if (b[id] <= 0) return true;\n }\n th = (th + 1) % 7;\n id = (id + 1) % n;\n }\n return false;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n cnt = new long[n];\n a = new long[n];\n b = new long[n];\n for (int i = 0; i < n; ++i) a[i] = in.nextInt();\n int th = 0;\n int id = 0;\n for (int i = 0; i < n * 7; ++i) {\n if (th != 6) cnt[id]++;\n th = (th + 1) % 7;\n id = (id + 1) % n;\n }\n\n long lo = 1;\n long hi = (long) 1e17;\n long best = -1;\n while (lo <= hi) {\n long mid = (lo + hi) / 2;\n if (check(mid)) {\n best = mid;\n hi = mid - 1;\n } else {\n lo = mid + 1;\n }\n }\n check(best);\n for (int i = 0; i < n; ++i)\n if (b[i] <= 0) {\n out.println(i + 1);\n break;\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 InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public static boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "52243762937cbda3ec005396ff0a3ed7", "src_uid": "8054dc5dd09d600d7fb8d9f5db4dcaca", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.Set;\nimport java.util.InputMismatchException;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.util.TreeSet;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\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 lewin\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n PiscesFast solver = new PiscesFast();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class PiscesFast {\n public static int INF = (int) (1e9);\n public static int TIME = 0;\n int n;\n\n static int sgn(int x) {\n if (x == 0) return 0;\n return x < 0 ? -1 : 1;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n PiscesFast.Node[] ns = new PiscesFast.Node[n];\n for (int i = 0; i < n; i++) ns[i] = new PiscesFast.Node(i);\n for (int i = 0; i < n - 1; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n int w = in.nextInt() * 2;\n ns[a].addEdge(ns[b], w);\n ns[b].addEdge(ns[a], w);\n }\n\n int k = in.nextInt();\n for (int i = 0; i < k; i++) {\n int d = in.nextInt() * 2;\n int f = in.nextInt();\n int l = in.nextInt() - 1;\n\n ns[l].addObservation(d, f);\n }\n\n ns[0].dfsSize(null);\n out.println(ns[0].dfs(null).getMax());\n }\n\n static class State {\n TreeSet small;\n TreeSet bounds;\n\n void addSegment(PiscesFast.State.Point l, PiscesFast.State.Point r) {\n int speed = sgn(r.diff) - sgn(l.diff);\n if (speed > 0) {\n int t = (r.pos() - l.pos() + speed - 1) / speed + TIME;\n small.add(new PiscesFast.State.Segment(t, l));\n }\n }\n\n void removeSegment(PiscesFast.State.Point l, PiscesFast.State.Point r) {\n int speed = sgn(r.diff) - sgn(l.diff);\n if (speed > 0) {\n int t = (r.pos() - l.pos() + speed - 1) / speed + TIME;\n small.remove(new PiscesFast.State.Segment(t, l));\n }\n }\n\n public State() {\n bounds = new TreeSet<>();\n small = new TreeSet<>();\n bounds.add(new PiscesFast.State.Point(-INF, 0));\n bounds.add(new PiscesFast.State.Point(INF, 0));\n addSegment(bounds.first(), bounds.last());\n }\n\n void proceed(int time) {\n while (small.size() > 0 && small.first().a <= time) {\n PiscesFast.State.Point a = small.first().p;\n PiscesFast.State.Point b = bounds.higher(a);\n int ctime = small.first().a;\n removeSegment(a, b);\n\n int pos = a.pos(ctime);\n int cdiff = a.diff + b.diff;\n if (b.pos(ctime) != pos && cdiff > 0) pos--;\n\n PiscesFast.State.Point c = bounds.lower(a);\n PiscesFast.State.Point d = bounds.higher(b);\n removeSegment(c, a);\n removeSegment(b, d);\n bounds.remove(b);\n bounds.remove(a);\n\n PiscesFast.State.Point x = new PiscesFast.State.Point(pos, cdiff, ctime);\n bounds.add(x);\n addSegment(c, x);\n addSegment(x, d);\n }\n TIME = time;\n }\n\n int get(int x) {\n int ans = 0;\n PiscesFast.State.Point p = bounds.ceiling(new PiscesFast.State.Point(x, 0));\n if (p.pos() == x && p.diff < 0) ans = Math.max(ans, -p.diff);\n p = bounds.ceiling(new PiscesFast.State.Point(x + 1, 0));\n if (p.pos() == x + 1 && p.diff > 0) ans = Math.max(ans, p.diff);\n return ans;\n }\n\n void add(int x, int t) {\n PiscesFast.State.Point toadd = new PiscesFast.State.Point(x, t);\n PiscesFast.State.Point g = bounds.ceiling(toadd);\n if (toadd.compareTo(g) < 0) {\n PiscesFast.State.Point a = bounds.lower(g);\n removeSegment(a, g);\n bounds.add(toadd);\n addSegment(a, toadd);\n addSegment(toadd, g);\n } else {\n PiscesFast.State.Point a = bounds.lower(g);\n PiscesFast.State.Point b = bounds.higher(g);\n removeSegment(a, g);\n removeSegment(g, b);\n toadd = new PiscesFast.State.Point(x, t + g.diff);\n bounds.remove(g);\n bounds.add(toadd);\n addSegment(a, toadd);\n addSegment(toadd, b);\n }\n }\n\n int getMax() {\n int res = 0;\n int c = 0;\n for (PiscesFast.State.Point p : bounds) {\n c += p.diff;\n res = Math.max(res, c);\n }\n return res;\n }\n\n static class Point implements Comparable {\n public int x;\n public int diff;\n\n public Point(int x, int diff) {\n this(x, diff, TIME);\n }\n\n public Point(int x, int diff, int time) {\n this.diff = diff;\n this.x = x + sgn(diff) * time;\n }\n\n public int pos() {\n return pos(TIME);\n }\n\n public int pos(int time) {\n return x - sgn(diff) * time;\n }\n\n public int compareTo(PiscesFast.State.Point other) {\n return pos() - other.pos();\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 PiscesFast.State.Point point = (PiscesFast.State.Point) o;\n\n if (x != point.x) return false;\n return diff == point.diff;\n }\n\n public int hashCode() {\n int result = x;\n result = 31 * result + diff;\n return result;\n }\n\n public String toString() {\n return x + \" \" + diff;\n }\n\n }\n\n static class Segment implements Comparable {\n public int a;\n public PiscesFast.State.Point p;\n\n public Segment(int index, PiscesFast.State.Point p) {\n this.a = index;\n this.p = p;\n }\n\n public int compareTo(PiscesFast.State.Segment other) {\n if (a != other.a) return a - other.a;\n else return p.compareTo(other.p);\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 PiscesFast.State.Segment segment = (PiscesFast.State.Segment) o;\n\n if (a != segment.a) return false;\n return p != null ? p.equals(segment.p) : segment.p == null;\n }\n\n public int hashCode() {\n int result = a;\n result = 31 * result + (p != null ? p.hashCode() : 0);\n return result;\n }\n\n }\n\n }\n\n static class Node {\n List children;\n List weights;\n int index;\n int size;\n List order;\n HashMap observations;\n\n public Node(int index) {\n this.index = index;\n children = new ArrayList<>();\n weights = new ArrayList<>();\n observations = new HashMap<>();\n order = new ArrayList<>();\n }\n\n public void addEdge(PiscesFast.Node other, int weight) {\n children.add(other);\n weights.add(weight);\n order.add(order.size());\n }\n\n public void addObservation(int time, int fish) {\n observations.put(time, fish);\n }\n\n public void dfsSize(PiscesFast.Node parent) {\n this.size = 1;\n for (PiscesFast.Node x : children) {\n if (x == parent) continue;\n x.dfsSize(this);\n this.size += x.size;\n }\n order.sort(Comparator.comparingInt(x -> -children.get(x).size));\n }\n\n public PiscesFast.State dfs(PiscesFast.Node parent) {\n PiscesFast.State cur = null;\n for (int i = 0; i < children.size(); i++) {\n PiscesFast.Node c = children.get(order.get(i));\n int len = weights.get(order.get(i));\n if (c == parent) continue;\n TIME -= len;\n PiscesFast.State t = c.dfs(this);\n t.proceed(TIME + len - 1);\n if (cur == null) {\n cur = t;\n } else {\n for (PiscesFast.State.Point p : t.bounds) {\n if (p.pos() > -INF && p.pos() < INF) {\n cur.add(p.pos(), p.diff);\n }\n }\n }\n }\n if (cur == null) cur = new PiscesFast.State();\n\n Set g = observations.keySet();\n for (int k : g) {\n observations.put(k, Math.max(0, observations.get(k) - cur.get(k)));\n }\n cur.proceed(TIME + 1);\n for (Map.Entry e : observations.entrySet()) {\n int k = e.getKey(), v = e.getValue();\n cur.add(k, v);\n cur.add(k + 1, -v);\n }\n return cur;\n }\n\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3887c98135657ab0318a8b52d6449f50", "src_uid": "52bf61e1be144044d434cf597dcd6e90", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.Random;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DLinearCongruentialGenerator solver = new DLinearCongruentialGenerator();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DLinearCongruentialGenerator {\n public int log(int x, int y) {\n int ans = 0;\n while (y != 0 && y % x == 0) {\n ans++;\n y /= x;\n }\n return ans;\n }\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int limit = (int) 2e6;\n IntegerMultiWayStack primeFactors = Factorization.factorizeRangePrime(limit);\n int[] cnts = new int[limit + 1];\n int[] times = new int[limit + 1];\n int[] xs = new int[n];\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9f84d6166ccbfb26a382998fa1b2e101", "src_uid": "816a82bee65cf79ba8e4d61babcd0301", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "/**\n * author: derrick20\n * created: 10/5/20 11:58 AM\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class ICup implements Runnable {\n public static void main(String[] args) throws Exception {\n new Thread(null, new ICup(), \": )\", 1 << 28).start();\n }\n\n public void run() {\n FastScanner sc = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n\n int T = sc.nextInt();\n long[] vals = sc.nextLongs(T);\n long[] sqrts = new long[60];\n sqrts[2] = 2;\n for (int i = 3; i < sqrts.length; i++) {\n sqrts[i] = (2 * sqrts[i - 1] - 1 + mod) % mod;\n }\n\n for (long v : vals) {\n if (v == 1) {\n out.println(1);\n } else if (v == 2 || v == 3) {\n out.println(2);\n } else {\n long sum = 0;\n long ct = 0;\n for (int bit = 2; bit < 60; bit++) {\n if (((v >> bit) & 1) > 0) {\n sum += sqrts[bit];\n ct += 1;\n }\n }\n long amt = sum - (ct - 1);\n long ans = (amt * amt) % mod;\n if ((v & 2) > 0) {\n ans += amt;\n }\n ans %= mod;\n out.println(ans);\n }\n }\n out.close();\n }\n\n static long mod = (long) 1e9 + 7;\n\n static class FastScanner {\n private int BS = 1 << 16;\n private char NC = (char) 0;\n private byte[] buf = new byte[BS];\n private int bId = 0, size = 0;\n private char c = NC;\n private double cnt = 1;\n private BufferedInputStream in;\n\n public FastScanner() {\n in = new BufferedInputStream(System.in, BS);\n }\n\n public FastScanner(String s) {\n try {\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n } catch (Exception e) {\n in = new BufferedInputStream(System.in, BS);\n }\n }\n\n private char getChar() {\n while (bId == size) {\n try {\n size = in.read(buf);\n } catch (Exception e) {\n return NC;\n }\n if (size == -1) return NC;\n bId = 0;\n }\n return (char) buf[bId++];\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextInts(int N) {\n int[] res = new int[N];\n for (int i = 0; i < N; i++) {\n res[i] = (int) nextLong();\n }\n return res;\n }\n\n public long[] nextLongs(int N) {\n long[] res = new long[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n public long nextLong() {\n cnt = 1;\n boolean neg = false;\n if (c == NC) c = getChar();\n for (; (c < '0' || c > '9'); c = getChar()) {\n if (c == '-') neg = true;\n }\n long res = 0;\n for (; c >= '0' && c <= '9'; c = getChar()) {\n res = (res << 3) + (res << 1) + c - '0';\n cnt *= 10;\n }\n return neg ? -res : res;\n }\n\n public double nextDouble() {\n double cur = nextLong();\n return c != '.' ? cur : cur + nextLong() / cnt;\n }\n\n public double[] nextDoubles(int N) {\n double[] res = new double[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextDouble();\n }\n return res;\n }\n\n public String next() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c > 32) {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public String nextLine() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c != '\\n') {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public boolean hasNext() {\n if (c > 32) return true;\n while (true) {\n c = getChar();\n if (c == NC) return false;\n else if (c > 32) return true;\n }\n }\n }\n static void ASSERT(boolean assertion, String message) {\n if (!assertion) throw new AssertionError(message);\n }\n static void ASSERT(boolean assertion) {\n if (!assertion) throw new AssertionError();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8c82345ea2aa3c2834197cfa08e9c84a", "src_uid": "24f4bd10ae714f957920afd47ac0c558", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "/**\n * author: derrick20\n * created: 10/5/20 11:58 AM\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class ICup implements Runnable {\n public static void main(String[] args) throws Exception {\n new Thread(null, new ICup(), \": )\", 1 << 28).start();\n }\n\n public void run() {\n FastScanner sc = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n\n int T = sc.nextInt();\n long[] vals = sc.nextLongs(T);\n int[] sqrts = new int[60];\n sqrts[2] = 2;\n for (int i = 3; i < sqrts.length; i++) {\n sqrts[i] = 2 * sqrts[i - 1] - 1;\n }\n for (long v : vals) {\n if (v == 1) {\n out.println(1);\n } else if (v == 2 || v == 3) {\n out.println(2);\n } else {\n long sum = 0;\n long ct = 0;\n for (int bit = 2; bit < 60; bit++) {\n if (((v >> bit) & 1) > 0) {\n sum += sqrts[bit];\n ct += 1;\n }\n }\n long amt = sum - (ct - 1);\n long ans = (amt * amt) % mod;\n if ((v & 2) > 0) {\n ans += amt;\n }\n ans %= mod;\n out.println(ans);\n }\n }\n out.close();\n }\n\n static long mod = (long) 1e9 + 7;\n\n static class FastScanner {\n private int BS = 1 << 16;\n private char NC = (char) 0;\n private byte[] buf = new byte[BS];\n private int bId = 0, size = 0;\n private char c = NC;\n private double cnt = 1;\n private BufferedInputStream in;\n\n public FastScanner() {\n in = new BufferedInputStream(System.in, BS);\n }\n\n public FastScanner(String s) {\n try {\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n } catch (Exception e) {\n in = new BufferedInputStream(System.in, BS);\n }\n }\n\n private char getChar() {\n while (bId == size) {\n try {\n size = in.read(buf);\n } catch (Exception e) {\n return NC;\n }\n if (size == -1) return NC;\n bId = 0;\n }\n return (char) buf[bId++];\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextInts(int N) {\n int[] res = new int[N];\n for (int i = 0; i < N; i++) {\n res[i] = (int) nextLong();\n }\n return res;\n }\n\n public long[] nextLongs(int N) {\n long[] res = new long[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n public long nextLong() {\n cnt = 1;\n boolean neg = false;\n if (c == NC) c = getChar();\n for (; (c < '0' || c > '9'); c = getChar()) {\n if (c == '-') neg = true;\n }\n long res = 0;\n for (; c >= '0' && c <= '9'; c = getChar()) {\n res = (res << 3) + (res << 1) + c - '0';\n cnt *= 10;\n }\n return neg ? -res : res;\n }\n\n public double nextDouble() {\n double cur = nextLong();\n return c != '.' ? cur : cur + nextLong() / cnt;\n }\n\n public double[] nextDoubles(int N) {\n double[] res = new double[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextDouble();\n }\n return res;\n }\n\n public String next() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c > 32) {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public String nextLine() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c != '\\n') {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public boolean hasNext() {\n if (c > 32) return true;\n while (true) {\n c = getChar();\n if (c == NC) return false;\n else if (c > 32) return true;\n }\n }\n }\n static void ASSERT(boolean assertion, String message) {\n if (!assertion) throw new AssertionError(message);\n }\n static void ASSERT(boolean assertion) {\n if (!assertion) throw new AssertionError();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "df13cd5a76b8dcac611335777f8a4fb8", "src_uid": "24f4bd10ae714f957920afd47ac0c558", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "//package round302;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class 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 m = ni();\n\t\tint[] a = na(n);\n\t\tlong[] as = new long[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tas[i] = (long)a[i]<<32|i;\n\t\t}\n\t\tArrays.sort(as);\n\t\t\n\t\tint s = (int)Math.sqrt(n);\n\t\t// time split\n\t\tint[][] minblock = new int[n/s+1][];\n\t\tint[] imos = new int[n/s+2];\n\t\tfor(int i = 0;i <= n;i++){\n\t\t\tif(i % s == 0){\n\t\t\t\tminblock[i/s] = Arrays.copyOf(imos, n/s+2);\n\t\t\t\tfor(int j = 1;j <= n/s;j++){\n\t\t\t\t\tminblock[i/s][j] += minblock[i/s][j-1];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(i == n)break;\n\t\t\tif(0 > (int)as[i]-m+1){\n\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\tint r = (int)as[i];\n\t\t\t\tif(l/s <= r/s){\n\t\t\t\t\timos[l/s]++;\n\t\t\t\t\timos[r/s]--;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\tint r = (int)as[i];\n\t\t\t\tif(l/s+1 <= r/s){\n\t\t\t\t\timos[l/s+1]++;\n\t\t\t\t\timos[r/s]--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] mininblock = new int[n/s+1][];\n\t\tint[][] wheninblock = new int[n/s+1][];\n\t\tfor(int i = 0;i < n/s+1;i++){\n\t\t\tmininblock[i] = new int[2*s+1];\n\t\t\twheninblock[i] = new int[2*s+1];\n\t\t}\n\t\t\n\t\tint[] map = new int[n];\n\t\tint[] ps = new int[n/s+1];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\tint r = (int)as[i];\n\t\t\tif(l/s == r/s){\n\t\t\t\tfor(int j = l;j <= r;j++)map[j]++;\n\t\t\t\t\n\t\t\t\tint lmin = Integer.MAX_VALUE;\n\t\t\t\tfor(int j = l/s*s;j < l/s*s+s && j < n;j++){\n\t\t\t\t\tif(map[j] < lmin){\n\t\t\t\t\t\tlmin = map[j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint clus = l/s;\n\t\t\t\tmininblock[clus][ps[clus]] = lmin;\n\t\t\t\twheninblock[clus][ps[clus]] = i;\n\t\t\t\tps[clus]++;\n\t\t\t}else{\n\t\t\t\t{\n\t\t\t\t\tfor(int j = r/s*s;j <= r;j++)map[j]++;\n\t\t\t\t\t\n\t\t\t\t\tint lmin = Integer.MAX_VALUE;\n\t\t\t\t\tfor(int j = r/s*s;j < r/s*s+s && j < n;j++){\n\t\t\t\t\t\tif(map[j] < lmin){\n\t\t\t\t\t\t\tlmin = map[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint clus = r/s;\n\t\t\t\t\tmininblock[clus][ps[clus]] = lmin;\n\t\t\t\t\twheninblock[clus][ps[clus]] = i;\n\t\t\t\t\tps[clus]++;\n\t\t\t\t}\n\t\t\t\tif(0 <= (int)as[i]-m+1){\n\t\t\t\t\tfor(int j = l;j < l/s*s+s;j++)map[j]++;\n\t\t\t\t\t\n\t\t\t\t\tint lmin = Integer.MAX_VALUE;\n\t\t\t\t\tfor(int j = l/s*s;j < l/s*s+s && j < n;j++){\n\t\t\t\t\t\tif(map[j] < lmin){\n\t\t\t\t\t\t\tlmin = map[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint clus = l/s;\n\t\t\t\t\tmininblock[clus][ps[clus]] = lmin;\n\t\t\t\t\twheninblock[clus][ps[clus]] = i;\n\t\t\t\t\tps[clus]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\tfor(int i = 0;i < n/s+1;i++){\n//\t\t\ttr(i);\n//\t\t\ttr(Arrays.copyOf(mininblock[i], ps[i]));\n//\t\t\ttr(Arrays.copyOf(wheninblock[i], ps[i]));\n//\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor(int Q = ni(); Q >= 1;Q--){\n\t\t\tint ql = ni()-1, qr = ni()-1, qx = ni()^ans;\n\t\t\tint time = -Arrays.binarySearch(as, ((long)qx<<32)-1)-1;\n\t\t\tint[] limos = new int[n/s+2];\n\t\t\tfor(int i = time/s*s;i < time;i++){\n\t\t\t\tif(0 > (int)as[i]-m+1){\n\t\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\t\tint r = (int)as[i];\n\t\t\t\t\tif(l/s <= r/s){\n\t\t\t\t\t\tlimos[l/s]++;\n\t\t\t\t\t\tlimos[r/s]--;\n\t\t\t\t\t}\n\t\t\t\t}else{\n\t\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\t\tint r = (int)as[i];\n\t\t\t\t\tif(l/s+1 <= r/s){\n\t\t\t\t\t\tlimos[l/s+1]++;\n\t\t\t\t\t\tlimos[r/s]--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 1;i < n/s+1;i++){\n\t\t\t\tlimos[i] += limos[i-1];\n\t\t\t}\n\t\t\tfor(int i = 0;i < n/s+1;i++){\n\t\t\t\tlimos[i] += minblock[time/s][i];\n\t\t\t}\n\t\t\tans = 999999999;\n\t\t\t\n\t\t\tif(ql/s == qr/s){\n\t\t\t\tint clus = ql/s;\n\t\t\t\tint[] llimos = new int[s+1];\n\t\t\t\tfor(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){\n\t\t\t\t\tint l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);\n\t\t\t\t\tint r = Math.min(s-1, (int)as[wheninblock[clus][j]]-clus*s);\n\t\t\t\t\tllimos[l]++;\n\t\t\t\t\tllimos[r+1]--;\n\t\t\t\t}\n\t\t\t\tfor(int j = 1;j <= s;j++){\n\t\t\t\t\tllimos[j] += llimos[j-1];\n\t\t\t\t}\n\t\t\t\tfor(int j = ql-clus*s;j <= qr-clus*s;j++){\n\t\t\t\t\tans = Math.min(ans, limos[clus] + llimos[j]);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tfor(int i = ql/s+1;i < qr/s;i++){\n\t\t\t\t\tint lind = Arrays.binarySearch(wheninblock[i], 0, ps[i], time-1);\n\t\t\t\t\tif(lind < 0)lind = -lind-2;\n\t\t\t\t\tif(lind >= 0){\n\t\t\t\t\t\tans = Math.min(ans, limos[i] + mininblock[i][lind]);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tans = Math.min(ans, limos[i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t{\n\t\t\t\t\tint clus = ql/s;\n\t\t\t\t\tint[] llimos = new int[s+1];\n\t\t\t\t\tfor(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){\n\t\t\t\t\t\tint l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);\n\t\t\t\t\t\tint r = Math.min((int)as[wheninblock[clus][j]]-clus*s, s-1);\n\t\t\t\t\t\tllimos[l]++;\n\t\t\t\t\t\tllimos[r+1]--;\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = 1;j <= s;j++){\n\t\t\t\t\t\tllimos[j] += llimos[j-1];\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = ql-clus*s;j < s && j < n-clus*s;j++){\n\t\t\t\t\t\tans = Math.min(ans, limos[clus] + llimos[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint clus = qr/s;\n\t\t\t\t\tint[] llimos = new int[s+1];\n\t\t\t\t\tfor(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){\n\t\t\t\t\t\tint l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);\n\t\t\t\t\t\tint r = Math.min((int)as[wheninblock[clus][j]]-clus*s, s-1);\n\t\t\t\t\t\tllimos[l]++;\n\t\t\t\t\t\tllimos[r+1]--;\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = 1;j <= s;j++){\n\t\t\t\t\t\tllimos[j] += llimos[j-1];\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = 0;j <= qr-clus*s;j++){\n\t\t\t\t\t\tans = Math.min(ans, limos[clus] + llimos[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\t\n\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\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f6f6bc58651e6687e059145c62ff1434", "src_uid": "92c773d61414ec6a13cdfbdcd24a2b0d", "difficulty": 3200.0} {"lang": "Java 6", "source_code": "import java.awt.AWTPermission;\nimport java.io.*;\nimport java.util.*;\n\npublic class E {\n\n public static void main(String[] args) throws Exception {\n reader = new MyReader(System.in);\n writer = System.out;\n new E().go();\n }\n\n static MyReader reader;\n static PrintStream writer;\n\n void go() {\n int n = reader.readInt();\n int k = reader.readInt();\n circles = new Circle[n];\n for(int i=0;i angles = new ArrayList();\n int cnt = 1;\n int best = 1;\n for(int b=0;b a2) ++cnt;\n if(b1 > b2) ++cnt;\n angles.add(new Angle(a1, 1));\n angles.add(new Angle(a2, -1));\n angles.add(new Angle(b1, 1));\n angles.add(new Angle(b2, -1));\n }\n Collections.sort(angles);\n for(Angle angle : angles) {\n cnt += angle.d;\n best = Math.max(best, cnt);\n }\n return best;\n }\n \n private static double modulo(double a) {\n while(a>2*Math.PI) a -= 2*Math.PI;\n while(a<0) a += 2*Math.PI;\n return a;\n }\n \n private static class Angle implements Comparable {\n double a;\n int d;\n Angle(double a, int d) { this.a = a; this.d = d; }\n public int compareTo(Angle o) {\n if(a < o.a) return -1;\n else if(a > o.a) return 1;\n else return 0;\n }\n }\n\n private Circle readCircle() {\n Circle c = new Circle();\n c.x = reader.readInt();\n c.y = reader.readInt();\n c.r = reader.readInt();\n return c;\n }\n\n Circle[] circles;\n \n private static class Circle {\n int x,y,r;\n }\n \n \n private static class MyReader {\n private InputStream in;\n private byte[] buf;\n private int bufSize,bufPos;\n private int nextChar;\n \n public MyReader(InputStream in) {\n this.in = in;\n buf = new byte[16<<10];\n bufSize=0;\n bufPos=0;\n move();\n }\n \n private void move() {\n if (bufPos==bufSize) {\n try {\n bufSize = in.read(buf);\n } catch(IOException ex) {\n throw new RuntimeException(ex);\n }\n bufPos = 0;\n if (bufSize == -1) {\n nextChar = -1;\n return;\n }\n }\n nextChar = buf[bufPos++];\n }\n \n public int readInt() {\n skipWhitespace();\n int res = 0;\n 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7ad633dfb66cf01cbbfcf6920d55cc44", "src_uid": "06ec7e481c963e635a6303503ffccc8b", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.awt.AWTPermission;\nimport java.io.*;\nimport java.util.*;\n\npublic class E {\n\n public static void main(String[] args) throws Exception {\n reader = new MyReader(System.in);\n writer = System.out;\n new E().go();\n }\n\n static MyReader reader;\n static PrintStream writer;\n\n void go() {\n int n = reader.readInt();\n int k = reader.readInt();\n circles = new Circle[n];\n for(int i=0;i angles = new ArrayList();\n int cnt = 1;\n int best = 1;\n for(int b=0;b a2) ++cnt;\n if(b1 > b2) ++cnt;\n angles.add(new Angle(a1, 1));\n angles.add(new Angle(a2, -1));\n angles.add(new Angle(b1, 1));\n angles.add(new Angle(b2, -1));\n }\n Collections.sort(angles);\n for(Angle angle : angles) {\n cnt += angle.d;\n best = Math.max(best, cnt);\n }\n return best;\n }\n \n private static double modulo(double a) {\n while(a>2*Math.PI) a -= 2*Math.PI;\n while(a<0) a += 2*Math.PI;\n return a;\n }\n \n private static class Angle implements Comparable {\n double a;\n int d;\n Angle(double a, int d) { this.a = a; this.d = d; }\n public int compareTo(Angle o) {\n if(a < o.a) return -1;\n else if(a > o.a) return 1;\n else return 0;\n }\n }\n\n private Circle readCircle() {\n Circle c = new Circle();\n c.x = reader.readInt();\n c.y = reader.readInt();\n c.r = reader.readInt();\n return c;\n }\n\n Circle[] circles;\n \n private static class Circle {\n int x,y,r;\n }\n \n \n private static class MyReader {\n private InputStream in;\n private byte[] buf;\n private int bufSize,bufPos;\n private int nextChar;\n \n public MyReader(InputStream in) {\n this.in = in;\n buf = new byte[16<<10];\n bufSize=0;\n bufPos=0;\n move();\n }\n \n private void move() {\n if (bufPos==bufSize) {\n try {\n bufSize = in.read(buf);\n } catch(IOException ex) {\n throw new RuntimeException(ex);\n }\n bufPos = 0;\n if (bufSize == -1) {\n nextChar = -1;\n return;\n }\n }\n nextChar = buf[bufPos++];\n }\n \n public int readInt() {\n skipWhitespace();\n int res = 0;\n 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fa676a953342a15bd4b48608e7c8b0e6", "src_uid": "06ec7e481c963e635a6303503ffccc8b", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.*; \n\nimport java.io.*; \nimport java.util.*; \n\npublic class Template {\n\tBufferedReader in; \n\tPrintWriter out;\n\tStringTokenizer st; \n\n\tString next() {\n\t\twhile (st==null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(in.readLine());\n\t\t\t} catch (Exception e) {}\n\t\t}\n\t\treturn st.nextToken(); \n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next()); \n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tclass Circle {\n\t\tdouble x, y, r; \n\t\tpublic Circle(double x, double y, double r) {\n\t\t\tthis.x=x; \n\t\t\tthis.y=y; \n\t\t\tthis.r=r; \n\t\t}\n\t}\n\n\tint n;\n\tlong k; \n\tCircle[] a; \n\n\n\tdouble mod(double a) {\n\t\twhile (a < 0) a+=PI*2; \n\t\twhile (a > 2*PI) a-=PI*2; \n\t\treturn a; \n\t}\n\tclass Event implements Comparable {\n\t\tdouble a;\n\t\tint type, i; \n\t\tEvent r; \n\t\tpublic Event(double a, int type) {\n\t\t\tthis.a=a; \n\t\t\tthis.type = type; \n\t\t} \n\n\t\tpublic int compareTo(Event o) {\n\t\t\tdouble d = a-o.a; \n\t\t\tif (d>0) return 1; \n\t\t\tif (d<0) return -1; \n\t\t\treturn type - o.type; \n\t\t}\n\t}\n\n\tint solve(int i) {\n\t\tdouble eps = 1e-14;\n\t\tArrayList ev = new ArrayList(); \n\t\tfor (int j=0; j 0) now--; \n\t\t\tbest = max(best, now);\n\t\t}\n//\t\tSystem.err.println(best); \n\t\treturn best; \n\n\t}\n\n\tpublic void run() throws Exception {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tLong start = System.currentTimeMillis();\n\n\t\tn = nextInt();\n\t\tk = nextLong();\n\t\ta = new Circle[n]; \n\t\tfor (int i=0; i angles = new ArrayList();\n int cnt = 1;\n int best = 1;\n for(int b=0;b a2) ++cnt;\n if(b1 > b2) ++cnt;\n angles.add(new Angle(a1, 1));\n angles.add(new Angle(a2, -1));\n angles.add(new Angle(b1, 1));\n angles.add(new Angle(b2, -1));\n }\n Collections.sort(angles);\n for(Angle angle : angles) {\n cnt += angle.d;\n best = Math.max(best, cnt);\n }\n return best;\n }\n \n private static double modulo(double a) {\n while(a>2*Math.PI) a -= 2*Math.PI;\n while(a<0) a += 2*Math.PI;\n return a;\n }\n \n private static class Angle implements Comparable {\n double a;\n int d;\n Angle(double a, int d) { this.a = a; this.d = d; }\n public int compareTo(Angle o) {\n if(a < o.a) return -1;\n else if(a > o.a) return 1;\n else return 0;\n }\n }\n\n private Circle readCircle() {\n Circle c = new Circle();\n c.x = reader.readInt();\n c.y = reader.readInt();\n c.r = reader.readInt();\n return c;\n }\n\n Circle[] circles;\n \n private static class Circle {\n int x,y,r;\n }\n \n \n private static class MyReader {\n private InputStream in;\n private byte[] buf;\n private int bufSize,bufPos;\n private int nextChar;\n \n public MyReader(InputStream in) {\n this.in = in;\n buf = new byte[16<<10];\n bufSize=0;\n bufPos=0;\n move();\n }\n \n private void move() {\n if (bufPos==bufSize) {\n try {\n bufSize = in.read(buf);\n } catch(IOException ex) {\n throw new RuntimeException(ex);\n }\n bufPos = 0;\n if (bufSize == -1) {\n nextChar = -1;\n return;\n }\n }\n nextChar = buf[bufPos++];\n }\n \n public int readInt() {\n skipWhitespace();\n int res = 0;\n 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0fefb1ffab0b1b58ed65b409d18dfedb", "src_uid": "06ec7e481c963e635a6303503ffccc8b", "difficulty": 2900.0} {"lang": "Java 8", "source_code": " \nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n \n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint a = scanner.nextInt();\n\t\tint h = scanner.nextInt();\n\t\tint w = scanner.nextInt(); \n\t\tint g = h+a, gn = w+a;\n\t\twhile (gn>0) {\n\t\t\tint t = gn;\n\t\t\tgn = g%gn;\n\t\t\tg = t;\n\t\t\n\t\t}\n\t\t\n\t\tint k = 0;\n\t\twhile(g/(k+1)>=a) {\n\t\t\tk++;\n\t\t}\n\t\t\n\t\tif (k>0) {\n\t\t\tSystem.out.println(1.0*g/k-a);\n\t\t} else {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\t\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9aa613db85493ef59113d1678786bff", "src_uid": "7fbefd3eb1aad6865adcfac394f0a7e6", "difficulty": 2700.0} {"lang": "Java 8", "source_code": " \nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n \n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint a = scanner.nextInt();\n\t\tint h = scanner.nextInt();\n\t\tint w = scanner.nextInt(); \n\t\tint g = h+a, gn = w+a;\n\t\twhile (gn>0) {\n\t\t\tint t = gn;\n\t\t\tgn = g%gn;\n\t\t\tg = t;\n\t\t\n\t\t}\n\t\t\n\t\tint k = g/a;\n\t\t\n\t\tif (k>0) {\n\t\t\tSystem.out.println(1.0*g/k-a);\n\t\t} else {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\t\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "32bb549caa0ca1cab1a73bd78794b347", "src_uid": "7fbefd3eb1aad6865adcfac394f0a7e6", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*; import java.util.*;\npublic class VillageMax {\n\n /**\n * Centroid decomposition problem\n * Answer is twice the sum of the size of the smaller subtree for an edge over all edges\n */\n static ArrayList arl[];\n static int N;\n static long ans;\n static int[] siz,par;//Size of subtree\n static int cent=-1;//Centroid\n public static class Pair implements Comparable{\n int v; int siz;\n public Pair(int a, int b){\n this.v=a; this.siz=b;\n }\n public int compareTo(Pair other){\n if(this.siz<=other.siz)return -1;\n return 1;\n \n }\n }\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n N=Integer.parseInt(br.readLine());\n \n arl=new ArrayList[N];\n for (int i = 0; i < N; i++) {\n arl[i]=new ArrayList<>();\n }\n int a,b;\n for (int i = 0; i < N-1; i++) {\n StringTokenizer st=new StringTokenizer(br.readLine());\n a=Integer.parseInt(st.nextToken())-1;\n b=Integer.parseInt(st.nextToken())-1;\n arl[a].add(b); arl[b].add(a);\n }\n siz=new int[N];\n par=new int[N];\n for (int i = 0; i < N; i++) {\n par[i]=i;\n }\n Arrays.fill(siz,1);\n init(-1,0); \n \n dfs(-1,0,true);\n \n //Now we use rerooting to find the centroid of the tree and the answer\n Arrays.fill(siz,1);//Redo\n \n init(-1,cent);//Root around center\n TreeSet ts=new TreeSet<>();\n \n \n \n \n for (int i : arl[cent]) {\n \n ts.add(new Pair(i,siz[i]));\n \n \n }\n \n ArrayList arl2[]=new ArrayList[N];\n for (int i = 0; i < N; i++) {\n arl2[i]=new ArrayList<>();\n }\n for (int i = 0; i < N; i++) {\n if(i!=cent){\n arl2[find(i,par)].add(i);\n }\n }\n \n \n int[] res=new int[N];\n int sum=N-1;\n while(sum>2){\n Pair p=ts.pollLast();\n Pair q=ts.pollLast();\n \n res[arl2[q.v].get(q.siz-1)]=arl2[p.v].get(p.siz-1); \n res[arl2[p.v].get(p.siz-1)]=arl2[q.v].get(q.siz-1);\n arl2[q.v].remove(q.siz-1); arl2[p.v].remove(p.siz-1);\n if(q.siz>1){\n ts.add(new Pair(q.v,q.siz-1));\n }\n if(p.siz>1){\n ts.add(new Pair(p.v,p.siz-1));\n }\n sum-=2;\n }\n if(sum==1){\n Pair p=ts.pollLast();\n res[cent]=arl2[p.v].get(0);\n res[arl2[p.v].get(0)]=cent;\n }else{\n Pair p=ts.pollLast();\n Pair q=ts.pollLast();\n res[cent]=arl2[p.v].get(0);\n res[arl2[p.v].get(0)]=arl2[q.v].get(0);\n res[arl2[q.v].get(0)]=cent;\n }\n System.out.println(ans);\n StringBuilder sb=new StringBuilder();\n for (int i = 0; i =0 && v!=cent){\n \n par[i]=v;\n \n }\n }\n }\n public static void dfs(int p, int v, boolean b){//Rerooting\n if(p>=0){\n \n ans+=2*Math.min(N-siz[p],siz[p]);\n \n }\n int max=0; int ind=-1;\n for (int i : arl[v]) {\n if(i==p)continue;\n if(siz[i]>max){\n max=siz[i]; \n if(b){//Index is only used for centroid finding\n ind=i;\n }\n }\n \n }\n \n if(b && 2*max>N){\n siz[v]-=siz[ind];\n siz[ind]+=siz[v];\n dfs(v,ind,true);\n siz[ind]-=siz[v];\n siz[v]+=siz[ind];\n }else if(b){\n \n ind=-1; cent=v;//Centroid found\n }\n for (int i : arl[v]) {\n if(i==p || i==ind)continue;\n siz[v]-=siz[i];\n siz[i]+=siz[v];\n dfs(v,i,false);\n siz[i]-=siz[v];\n siz[v]+=siz[i];\n }\n }\n public static int find(int x, int[] p){\n if(p[x]==x)return x;\n int ans=find(p[x],p);\n p[x]=ans; return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "268ee27da4e2c6446097dcbaa65797f0", "src_uid": "343dbacbc6bb4981a062dda5a1a13656", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\npublic class Main {\n void solve() {\n int n=ni();\n g=new ArrayList[n+1];\n for(int i=1;i<=n;i++) g[i]=new ArrayList<>();\n for(int i=1;i g[];\n long dp[][][];\n void dfs(int v,int pr){\n int child=0;\n for(int u : g[v]){\n if(u!=pr) {\n dfs(u,v);\n child++;\n }\n }\n if(child==0){\n dp[v][0][0]=dp[v][1][1]=1;\n return;\n }\n long sm=1,sm2=1;\n for(int u : g[v]){\n if(u!=pr) {\n sm = mul(sm, add(dp[u][0][1], dp[u][1][1]));\n sm2=mul(sm2,dp[u][1][1]);\n }\n }\n dp[v][0][0]=sm;\n for(int u : g[v]){\n if(u!=pr){\n dp[v][0][1]=add(dp[v][0][1],mul(dp[u][0][0],mul(sm,modInverse(dp[u][0][1]+dp[u][1][1],M))));\n dp[v][1][1]=add(dp[v][1][1],mul(dp[u][0][0],mul(sm,modInverse(dp[u][0][1]+dp[u][1][1],M))));\n\n\n\n }\n }\n dp[v][1][1]=add(dp[v][1][1],sm2);\n\n\n\n }\n long sub(long a,long b){\n if(a>=M)a%=M; if(b>=M)b%=M;\n a-=b;\n if(a<0) a+=M;\n return a;\n }\n long mul(long a,long b){\n a*=b;\n if(a>=M) a%=M;\n return a;\n }\n long add(long a,long b){\n if(a>=M)a%=M; if(b>=M)b%=M;\n a+=b;\n if(a>=M) a-=M;\n return a;\n }\n long modpow(long a, long b,long M)\n {\n long r=1;\n while(b>0)\n {\n if((b&1)>0) r=mul(r,a);\n a=mul(a,a);\n b>>=1;\n }\n return r;\n }\n\n long modInverse(long A, long M)\n {\n\n return modpow(A,M-2,M);\n }\n\n long M = 998244353;\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n\n void run() throws Exception {\n is = is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n pw = new PrintWriter(System.out);\n\n Thread t = new Thread(null, null, \"~\", Runtime.getRuntime().maxMemory()){\n @Override\n public void run() {\n long s = System.currentTimeMillis();\n solve();\n\n pw.flush();\n if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n }\n };\n t.start();\n t.join();\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b70f09b0b187d18e195fe164e38de380", "src_uid": "a40e78a7144ac2fae1890ac7598990bf", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.*;\n\npublic class Main\n{\t\n\tpublic BufferedReader in;\n\tpublic PrintStream out;\n\t\n\tpublic boolean log_enabled = false;\n\t\n\tint n;\n\tint[] adj_count;\n\tint[][] adj_list;\n\t\n\tint[] ch_count;\n\tint[][] ch_list;\n\t\n\tlong[] X, Y, Z;\n\tboolean[] V;\n\t\n\tlong M = 998244353;\n\t\n\tpublic long modInverse(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\t\n\tpublic void generate_test()\n\t{\n\t\tout.println(300000);\n\t\tfor (int i=1; i<300000; i++)\n\t\t{\n\t\t\tout.printf(\"%d %d\\n\", i, i+1);\n\t\t}\n\t}\n\t\n\tpublic void test()\n\t{\n\t\tn = readInt();\n\t\tint[] pars = readIntArray(2*n-2);\n\t\t\n\t\tint i,j;\n\t\t\n\t\tadj_count = new int[n];\t\t\n\t\tadj_list = new int[n][];\n\t\t\n\t\tch_count = new int[n];\n\t\tch_list = new int[n][];\n\t\t\n\t\tArrays.fill(adj_count, 0);\n\t\tfor (i=0; i=0; j--)\n\t\t{\n\t\t\tp = Q[j];\n\t\t\t\n\t\t\tpz = 1;\n\t\t\tpxz = 1;\n\t\t\t\n\t\t\tfor (i=0; i0) {\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\t\n\tpublic void test()\n\t{\n\t\tn = readInt();\n\t\tint[] pars = readIntArray(2*n-2);\n\t\t\n\t\tint i,j;\n\t\t\n\t\tadj_count = new int[n];\t\t\n\t\tadj_list = new int[n][];\n\t\t\n\t\tArrays.fill(adj_count, 0);\n\t\tfor (i=0; i s, t;\n\tprivate static boolean[] visited;\n\tprivate static ArrayList[] graph;\n\t\n\tprivate static boolean isSubset(int a, int b) {\n\t\treturn (a & b) == a;\n\t}\n\n\tprivate static boolean isIntersect(int a, int b) {\n\t\treturn (a & b) != 0;\n\t}\n\n\t// Solve for each weakly connected component (WCC)\n\tprivate static int cntOrder(ArrayList s, ArrayList t) {\n\t\tint p = s.size(), m = t.size();\n\n\t\tint[] inMask = new int[m];\n\t\tfor(int x = 0; x < p; ++x)\n\t\t\tfor(int i = 0; i < m; ++i)\n\t\t\t\tif (t.get(i) % s.get(x) == 0)\n\t\t\t\t\tinMask[i] |= 1 << x;\n\n\t\tint[] cnt = new int[1<();\n\t\tfor(int u = 0; u < n; ++u) {\n\t\t\tfor(int v = 0; v < n; ++v) {\n\t\t\t\tif (u != v && a[v] % a[u] == 0) {\n\t\t\t\t\tgraph[u].add(v);\n\t\t\t\t\tgraph[v].add(u);\n\t\t\t\t\t++degIn[v];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\n\t\t// Solve for each WCC of divisibility graph and combine result\n\t\tint ans = 1;\n\t\tint curLen = 0;\n\t\tvisited = new boolean[n];\n\t\tfor(int u = 0; u < n; ++u) {\n\t\t\tif (!visited[u]) {\n\t\t\t\ts = new ArrayList<>();\n\t\t\t\tt = new ArrayList<>();\n\t\t\t\tdfs(u);\n\t\n\t\t\t\tif (!t.isEmpty()) {\n\t\t\t\t\tint sz = t.size() - 1;\n\t\t\t\t\tint cnt = cntOrder(s, t);\n\t\n\t\t\t\t\t// Number of orders for current WCC\n\t\t\t\t\tans = (int)(((long)ans * cnt) % MOD);\n\t\t\t\t\t// Number of ways to insert number to array of elements\n\t\t\t\t\tans = (int)(((long)ans * c[curLen + sz][sz]) % MOD);\n\t\t\t\t\tcurLen += sz;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tinput();\n\t\tsolve();\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "794b76a2ef54be86dc9a54d5e2f47218", "src_uid": "c8d43a60ddc0a7b98a7269dc3a2478dc", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Vadim Semenov\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static final class TaskF {\n public void solve(int __, InputReader in, PrintWriter out) {\n String s = in.next();\n String t = in.next();\n int[][] result = solve(s.toCharArray(), t.toCharArray());\n out.println(result.length);\n for (int[] pair : result) {\n out.print(pair[0]);\n out.print(' ');\n out.println(pair[1]);\n }\n }\n\n private int[][] solve(char[] s, char[] t) {\n int[][] result = solveInternal(s, t);\n int[][] anotherResult = solveInternal(t, s);\n if (anotherResult.length < result.length) {\n result = anotherResult;\n for (int[] pair : result) {\n ArrayUtils.swap(pair, 0, 1);\n }\n }\n return result;\n }\n\n private int[][] solveInternal(char[] s, char[] t) {\n List sChangings = getChangings(s, 0, s.length, s, 0, 0, 'a');\n List tChangings = getChangings(t, 0, t.length, t, 0, 0, 'b');\n int[][] result = solveGreedy(s, 0, s.length, s, 0, 0, t, 0, t.length, t, 0, 0, 0, Integer.MAX_VALUE);\n assert result != null;\n int balance = (sChangings.size() - tChangings.size()) / 2;\n for (int i = 0; i < 3; ++i) {\n for (int j = 0; j < 3; ++j) {\n int sp = (balance > 0 ? balance : 0) + i;\n int tp = (balance < 0 ? -balance : 0) + j;\n if ((sp != 0 && sp >= sChangings.size()) || (tp != 0 && tp >= tChangings.size())) continue;\n int sSep = sp < sChangings.size() ? sChangings.get(sp) : 0;\n int tSep = tp < tChangings.size() ? tChangings.get(tp) : 0;\n int[][] current = solveGreedy(t, 0, tSep, s, sSep, s.length, s, 0, sSep, t, tSep, t.length, 1, result.length);\n if (current != null) {\n result = current;\n current[0][0] = sSep;\n current[0][1] = tSep;\n }\n }\n }\n return result;\n }\n\n private int[][] solveGreedy(char[] s1, int s1from, int s1to,\n char[] s2, int s2from, int s2to,\n char[] t1, int t1from, int t1to,\n char[] t2, int t2from, int t2to,\n int offset, int limit) {\n List ss = getChangings(s1, s1from, s1to, s2, s2from, s2to, 'a');\n List tt = getChangings(t1, t1from, t1to, t2, t2from, t2to, 'b');\n int length = Math.max(ss.size(), tt.size());\n if (offset + length >= limit) {\n return null;\n }\n int[][] result = new int[offset + length][2];\n for (int i = 0; i < length; ++i) {\n result[offset + i][0] = pop(ss);\n result[offset + i][1] = pop(tt);\n List tmp = ss;\n ss = tt;\n tt = tmp;\n }\n return result;\n }\n\n private List getChangings(char[] s1, int s1from, int s1to, char[] s2, int s2from, int s2to, char target) {\n List changings = new ArrayList<>();\n for (int i = s2to; i-- > s2from; ) {\n char current = s2[i];\n if (current != target) {\n changings.add(s1to - s1from + i - s2from + 1);\n target = current;\n }\n }\n for (int i = s1to; i-- > s1from; ) {\n char current = s1[i];\n if (current != target) {\n changings.add(i - s1from + 1);\n target = current;\n }\n }\n Collections.reverse(changings);\n return changings;\n }\n\n private static int pop(List stack) {\n return stack.isEmpty() ? 0 : stack.remove(stack.size() - 1);\n }\n\n }\n\n static class InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public String readLine() {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n\n }\n\n static class ArrayUtils {\n private ArrayUtils() {\n }\n\n public static void swap(int[] array, int i, int j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e49e6d07f81d6e97cdd8e4897b198a53", "src_uid": "4a50c4147becea13946272230f3dde6d", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Crocodile implements Runnable {\n private void solve() throws IOException {\n int m = nextInt();\n int n = nextInt();\n int mx = Math.max(n, m);\n double[][] ans = new double[mx + 1][mx + 1];\n for (int sum = 0; sum <= mx + mx; ++sum) {\n for (int a = 0; a <= mx; ++a) {\n int b = sum - a;\n if (b >= 0 && b <= mx) {\n ans[a][b] = doit(a, b, ans);\n }\n }\n }\n writer.println(ans[m][n] + \" \" + (1.0 - ans[m][n]));\n }\n\n private double doit(int m, int n, double[][] ans) {\n double res = 1.0 / (n + 1);\n if (m == 0 || n == 0) return res;\n double borderP = 1 / (ans[n][m - 1] * (n + 1) + 1);\n res = Math.max(res, eval(m, n, ans, 0.0));\n res = Math.max(res, eval(m, n, ans, borderP));\n res = Math.max(res, eval(m, n, ans, 1.0));\n return res;\n }\n\n private double eval(int m, int n, double[][] ans, double p) {\n return (1 - p) * n / (n + 1.0) * (1 - ans[n - 1][m]) + (p + (1 - p) / (n + 1.0) - Math.max((1 - p) / (n + 1), p * ans[n][m - 1]));\n }\n\n public static void main(String[] args) {\n new Crocodile().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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9fddffea9cfe570effc6d49408fc761e", "src_uid": "f51586ab88399c04ffb7eaa658d294dd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n \npublic class Main implements Runnable \n{\n static class InputReader \n {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n public InputReader(InputStream stream) \n {\n this.stream = stream;\n }\n \n public int read() \n {\n if (numChars == -1) \n throw new InputMismatchException();\n \n if (curChar >= numChars) \n {\n curChar = 0;\n try \n {\n numChars = stream.read(buf);\n }\n catch (IOException e) \n {\n throw new InputMismatchException();\n }\n \n if(numChars <= 0) \n return -1;\n }\n return buf[curChar++];\n }\n \n public String nextLine() \n {\n String str = \"\";\n try \n {\n str = br.readLine();\n }\n catch (IOException e) \n {\n e.printStackTrace();\n }\n return str;\n }\n \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 \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 \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 \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 \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 \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 \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 \n public static void main(String args[]) throws Exception \n {\n new Thread(null, new Main(),\"Main\",1<<27).start();\n }\n \n public void run() \n {\n InputReader sc = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\n int t = sc.nextInt();\n\n for(int x = 0; x < t; x++) \n {\n int n = sc.nextInt();\n\n int weight[][] = new int[n][n];\n for(int i = 0; i < n; i++) \n {\n for(int j = 0; j < n; j++)\n weight[i][j] = sc.nextInt();\n }\n\n w.println(\"B\");\n w.flush();\n\n char type = sc.next().charAt(0);\n int node = sc.nextInt() - 1;\n\n int situation = 0;\n if(node >= n)\n situation ^= 1;\n\n if(type == 'D') \n {\n situation ^= 1;\n }\n\n int preferences[][] = new int[2 * n][n];\n\n if(situation == 0) \n {\n for(int i = 0; i < n; ++i) \n {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) \n {\n p[j] = new Pair(n + j, weight[i][j]);\n }\n \n Arrays.sort(p, new Comparator() \n {\n public int compare(Pair p1, Pair p2) \n {\n return p1.val - p2.val;\n }\n });\n \n for(int j = 0; j < n; ++j)\n preferences[i][j] = p[j].ind;\n }\n\n for(int i = 0; i < n; ++i) \n {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) \n {\n p[j] = new Pair(j, weight[j][i]);\n }\n \n Arrays.sort(p, new Comparator() \n {\n public int compare(Pair p1, Pair p2) \n {\n return p2.val - p1.val;\n }\n });\n\n for(int j = 0; j < n; ++j)\n preferences[n + i][j] = p[j].ind;\n }\n }\n else \n {\n for(int i = 0; i < n; ++i) \n {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) \n {\n p[j] = new Pair(n + j, weight[i][j]);\n }\n \n Arrays.sort(p, new Comparator() \n {\n public int compare(Pair p1, Pair p2) \n {\n return p2.val - p1.val;\n }\n });\n \n for(int j = 0; j < n; ++j)\n preferences[i][j] = p[j].ind;\n }\n\n for(int i = 0; i < n; ++i) \n {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) \n {\n p[j] = new Pair(j, weight[j][i]);\n }\n \n Arrays.sort(p, new Comparator() \n {\n public int compare(Pair p1, Pair p2) \n {\n return p1.val - p2.val;\n }\n });\n\n for(int j = 0; j < n; ++j)\n preferences[n + i][j] = p[j].ind;\n }\n }\n\n int match[] = StableMarriage.findStableMarriage(preferences);\n while(node != -2) \n {\n w.println((match[node] + 1));\n w.flush();\n node = sc.nextInt() - 1; \n }\n }\n\n w.close();\n }\n}\n\nclass Pair \n{\n int ind, val;\n Pair(int a, int b) \n {\n ind = a;\n val = b;\n }\n}\n\nclass StableMarriage \n{\n static int[] findStableMarriage(int[][] preferences) \n {\n int n = preferences.length / 2;\n\n int[] match = new int[2 * n];\n Arrays.fill(match, -1);\n\n int rank[][] = new int[n][n];\n for(int j = n; j < 2 * n; ++j) \n {\n for(int i = 0; i < n; ++i) \n {\n rank[j - n][preferences[j][i]] = i;\n }\n }\n\n Queue notMatched = new LinkedList<>();\n for(int i = 0; i < n; ++i)\n notMatched.add(i);\n\n int nextRankToBeProposed[] = new int[n];\n\n while(!notMatched.isEmpty()) \n {\n int ind = notMatched.poll(); \n\n while(true) \n {\n int j = preferences[ind][nextRankToBeProposed[ind]++];\n\n if(match[j] == -1) \n {\n match[ind] = j;\n match[j] = ind;\n break;\n }\n else if(rank[j - n][match[j]] > rank[j - n][ind]) \n {\n match[match[j]] = -1;\n notMatched.add(match[j]);\n match[ind] = j;\n match[j] = ind;\n break;\n }\n }\n }\n\n return match;\n }\n \n static boolean stable(int[][] preferences, int[] match) \n {\n int n = match.length / 2;\n\n for(int i = 0; i < n; ++i) \n {\n for(int j = 0; j < n; ++j) \n {\n if(match[i] == j + n)\n continue;\n\n int flag = 0;\n for(int k = 0; k < n; ++k) \n {\n if(preferences[i][k] == match[i])\n break;\n\n if(preferences[i][k] == j + n) \n {\n flag++;\n break;\n }\n }\n \n for(int k = 0; k < n; ++k) \n {\n if(preferences[j + n][k] == match[j + n])\n break;\n\n if(preferences[j + n][k] == i) \n {\n flag++;\n break;\n }\n }\n \n if(flag == 2)\n return false;\n }\n }\n\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2c47b17db4ca9c3c564868894d242825", "src_uid": "299c209b070e510e7ed3b525f51fec8a", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n \npublic class Main implements Runnable {\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars==-1) \n throw new InputMismatchException();\n \n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n }\n catch (IOException e) {\n throw new InputMismatchException();\n }\n \n if(numChars <= 0) \n return -1;\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n \n while(isSpaceChar(c)) \n c = read();\n \n int sgn = 1;\n \n if (c == '-') {\n sgn = -1;\n c = read();\n }\n \n int res = 0;\n do {\n if(c<'0'||c>'9') \n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c)); \n \n return res * sgn;\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n \n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } \n while (!isSpaceChar(c));\n \n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public String next() {\n return readString();\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n public static void main(String args[]) throws Exception {\n new Thread(null, new Main(),\"Main\",1<<27).start();\n } \n public void run() {\n InputReader sc = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\n int t = sc.nextInt();\n\n for(int x = 0; x < t; x++) {\n int n = sc.nextInt();\n\n int weight[][] = new int[n][n];\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < n; ++j)\n weight[i][j] = sc.nextInt();\n }\n\n w.println(\"B\");\n w.flush();\n\n char type = sc.next().charAt(0);\n int node = sc.nextInt() - 1;\n\n int situation = 0;\n if(node >= n)\n situation ^= 1;\n\n if(type == 'D') {\n situation ^= 1;\n }\n\n int preferences[][] = new int[2 * n][n];\n\n if(situation == 0) {\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(n + j, weight[i][j]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p1.val - p2.val;\n }\n });\n for(int j = 0; j < n; ++j)\n preferences[i][j] = p[j].ind;\n }\n\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(j, weight[j][i]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p2.val - p1.val;\n }\n });\n\n for(int j = 0; j < n; ++j)\n preferences[n + i][j] = p[j].ind;\n }\n }\n else {\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(n + j, weight[i][j]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p2.val - p1.val;\n }\n });\n for(int j = 0; j < n; ++j)\n preferences[i][j] = p[j].ind;\n }\n\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(j, weight[j][i]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p1.val - p2.val;\n }\n });\n\n for(int j = 0; j < n; ++j)\n preferences[n + i][j] = p[j].ind;\n }\n }\n\n int match[] = StableMarriage.findStableMarriage(preferences);\n while(node != -2) {\n w.println((match[node] + 1));\n w.flush();\n node = sc.nextInt() - 1; \n }\n }\n\n w.close();\n }\n}\nclass Pair {\n int ind, val;\n Pair(int a, int b) {\n ind = a;\n val = b;\n }\n}\nclass StableMarriage {\n static int[] findStableMarriage(int[][] preferences) {\n // Also known as Gale-Shapley algorithm\n\n // 0 - (n - 1) ids are man, rest are woman\n // preferences is a 2n (first n man and last n woman) x n matrix which gives person id's sorted rank wise\n // match is an array of size 2*n - matched person for each id\n\n int n = preferences.length / 2;\n\n int[] match = new int[2 * n];\n Arrays.fill(match, -1);\n\n // A rank matrix of n x n, determines rank of each man for each woman\n int rank[][] = new int[n][n];\n for(int j = n; j < 2 * n; ++j) {\n for(int i = 0; i < n; ++i) {\n rank[j - n][preferences[j][i]] = i;\n }\n }\n\n Queue notMatched = new LinkedList<>();\n for(int i = 0; i < n; ++i)\n notMatched.add(i);\n\n int nextRankToBeProposed[] = new int[n];\n\n while(!notMatched.isEmpty()) {\n int ind = notMatched.poll(); // current man who will propose\n\n while(true) {\n int j = preferences[ind][nextRankToBeProposed[ind]++]; // woman to be proposed\n\n if(match[j] == -1) { // if woman not matched yet\n match[ind] = j;\n match[j] = ind;\n break;\n }\n else if(rank[j - n][match[j]] > rank[j - n][ind]) { // if this man more preferable\n match[match[j]] = -1;\n notMatched.add(match[j]); // previous man needs to propose again\n match[ind] = j;\n match[j] = ind;\n break;\n }\n }\n }\n\n // if(!stable(preferences, match))\n // System.out.println(\"Wrong code\");\n\n return match;\n }\n static boolean stable(int[][] preferences, int[] match) {\n int n = match.length / 2;\n\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < n; ++j) {\n if(match[i] == j + n)\n continue;\n\n int flag = 0;\n for(int k = 0; k < n; ++k) {\n if(preferences[i][k] == match[i])\n break;\n\n if(preferences[i][k] == j + n) {\n flag++;\n break;\n }\n }\n for(int k = 0; k < n; ++k) {\n if(preferences[j + n][k] == match[j + n])\n break;\n\n if(preferences[j + n][k] == i) {\n flag++;\n break;\n }\n }\n if(flag == 2)\n return false;\n }\n }\n\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5df4e8a844ae2749b914486094ff7812", "src_uid": "299c209b070e510e7ed3b525f51fec8a", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n \npublic class Main implements Runnable {\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars==-1) \n throw new InputMismatchException();\n \n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n }\n catch (IOException e) {\n throw new InputMismatchException();\n }\n \n if(numChars <= 0) \n return -1;\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n \n while(isSpaceChar(c)) \n c = read();\n \n int sgn = 1;\n \n if (c == '-') {\n sgn = -1;\n c = read();\n }\n \n int res = 0;\n do {\n if(c<'0'||c>'9') \n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c)); \n \n return res * sgn;\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n \n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } \n while (!isSpaceChar(c));\n \n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public String next() {\n return readString();\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n public static void main(String args[]) throws Exception {\n new Thread(null, new Main(),\"Main\",1<<27).start();\n } \n public void run() {\n InputReader sc = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\n int t = sc.nextInt();\n\n for(int x = 0; x < t; ++x) {\n int n = sc.nextInt();\n\n int weight[][] = new int[n][n];\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < n; ++j)\n weight[i][j] = sc.nextInt();\n }\n\n w.println(\"B\");\n w.flush();\n\n char type = sc.next().charAt(0);\n int node = sc.nextInt() - 1;\n\n int situation = 0;\n if(node >= n)\n situation ^= 1;\n\n if(type == 'D') {\n situation ^= 1;\n }\n\n int preferences[][] = new int[2 * n][n];\n\n if(situation == 0) {\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(n + j, weight[i][j]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p1.val - p2.val;\n }\n });\n for(int j = 0; j < n; ++j)\n preferences[i][j] = p[j].ind;\n }\n\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(j, weight[j][i]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p2.val - p1.val;\n }\n });\n\n for(int j = 0; j < n; ++j)\n preferences[n + i][j] = p[j].ind;\n }\n }\n else {\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(n + j, weight[i][j]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p2.val - p1.val;\n }\n });\n for(int j = 0; j < n; ++j)\n preferences[i][j] = p[j].ind;\n }\n\n for(int i = 0; i < n; ++i) {\n Pair p[] = new Pair[n];\n for(int j = 0; j < n; ++j) {\n p[j] = new Pair(j, weight[j][i]);\n }\n Arrays.sort(p, new Comparator() {\n public int compare(Pair p1, Pair p2) {\n return p1.val - p2.val;\n }\n });\n\n for(int j = 0; j < n; ++j)\n preferences[n + i][j] = p[j].ind;\n }\n }\n\n int match[] = StableMarriage.findStableMarriage(preferences);\n while(node != -2) {\n w.println((match[node] + 1));\n w.flush();\n node = sc.nextInt() - 1; \n }\n }\n\n w.close();\n }\n}\nclass Pair {\n int ind, val;\n Pair(int a, int b) {\n ind = a;\n val = b;\n }\n}\nclass StableMarriage {\n static int[] findStableMarriage(int[][] preferences) {\n // Also known as Gale-Shapley algorithm\n\n // 0 - (n - 1) ids are man, rest are woman\n // preferences is a 2n (first n man and last n woman) x n matrix which gives person id's sorted rank wise\n // match is an array of size 2*n - matched person for each id\n\n int n = preferences.length / 2;\n\n int[] match = new int[2 * n];\n Arrays.fill(match, -1);\n\n // A rank matrix of n x n, determines rank of each man for each woman\n int rank[][] = new int[n][n];\n for(int j = n; j < 2 * n; ++j) {\n for(int i = 0; i < n; ++i) {\n rank[j - n][preferences[j][i]] = i;\n }\n }\n\n Queue notMatched = new LinkedList<>();\n for(int i = 0; i < n; ++i)\n notMatched.add(i);\n\n int nextRankToBeProposed[] = new int[n];\n\n while(!notMatched.isEmpty()) {\n int ind = notMatched.poll(); // current man who will propose\n\n while(true) {\n int j = preferences[ind][nextRankToBeProposed[ind]++]; // woman to be proposed\n\n if(match[j] == -1) { // if woman not matched yet\n match[ind] = j;\n match[j] = ind;\n break;\n }\n else if(rank[j - n][match[j]] > rank[j - n][ind]) { // if this man more preferable\n match[match[j]] = -1;\n notMatched.add(match[j]); // previous man needs to propose again\n match[ind] = j;\n match[j] = ind;\n break;\n }\n }\n }\n\n // if(!stable(preferences, match))\n // System.out.println(\"Wrong code\");\n\n return match;\n }\n static boolean stable(int[][] preferences, int[] match) {\n int n = match.length / 2;\n\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < n; ++j) {\n if(match[i] == j + n)\n continue;\n\n int flag = 0;\n for(int k = 0; k < n; ++k) {\n if(preferences[i][k] == match[i])\n break;\n\n if(preferences[i][k] == j + n) {\n flag++;\n break;\n }\n }\n for(int k = 0; k < n; ++k) {\n if(preferences[j + n][k] == match[j + n])\n break;\n\n if(preferences[j + n][k] == i) {\n flag++;\n break;\n }\n }\n if(flag == 2)\n return false;\n }\n }\n\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa46096d3816069ed046107dbd47ecb9", "src_uid": "299c209b070e510e7ed3b525f51fec8a", "difficulty": 3500.0} {"lang": "Java 6", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n 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 }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "109ee5d1f3ae471f0cb0b19c5e9b7453", "src_uid": "e652ba0901b39f0d01ac152babc06b88", "difficulty": 2700.0} {"lang": "Java 7", "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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "342d92721e5da9c395a3f649cbc646db", "src_uid": "355cc23d7a4addfc920c6e5e72a2bb64", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class E {\n public static ArrayList[] g;\n public static boolean[] used;\n public static boolean[] cana;\n public static boolean[] canb;\n public static int a;\n public static int b;\n public static void dfs1(int node){\n used[node] = true;\n cana[node] = true;\n for(Integer n : g[node]){\n if(!used[n] && n != b){\n dfs1(n);\n }\n }\n }\n public static void dfs2(int node){\n used[node] = true;\n canb[node] = true;\n for(Integer n : g[node]){\n if(!used[n] && n != a){\n dfs2(n);\n }\n }\n }\n public static void main(String[] args) throws IOException {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n int t = Integer.parseInt(reader.readLine());\n for(int q = 0; q < t; ++q){\n StringTokenizer st = new StringTokenizer(reader.readLine());\n int n = Integer.parseInt(st.nextToken());\n g = new ArrayList[n];\n for(int i = 0; i < n; ++i){\n g[i] = new ArrayList<>();\n }\n cana = new boolean[n];\n canb = new boolean[n];\n int m = Integer.parseInt(st.nextToken());\n a = Integer.parseInt(st.nextToken()) - 1;\n b = Integer.parseInt(st.nextToken()) - 1;\n for(int i = 0; i < m; ++i){\n st = new StringTokenizer(reader.readLine());\n int x = Integer.parseInt(st.nextToken());\n int y = Integer.parseInt(st.nextToken());\n g[x - 1].add(y - 1);\n g[y - 1].add(x - 1);\n }\n used = new boolean[n];\n dfs1(a);\n used = new boolean[n];\n dfs2(b);\n cana[b] = true;\n canb[a] = true;\n long c1 = 0;\n long c2 = 0;\n for(int i = 0; i < n; ++i){\n if(!cana[i]){\n ++c1;\n }\n if(!canb[i]){\n ++c2;\n }\n }\n writer.println(c1 * c2);\n }\n writer.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d77f7bed9178fdcb7c4bfd96d3f945f1", "src_uid": "7636c493ad91210ec7571895b4b71214", "difficulty": 1900.0} {"lang": "Java 11", "source_code": "import java.io.OutputStream;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStream;\r\nimport java.io.PrintWriter;\r\nimport java.util.Arrays;\r\nimport java.io.BufferedWriter;\r\nimport java.io.Writer;\r\nimport java.io.OutputStreamWriter;\r\nimport java.util.InputMismatchException;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\n\r\n/**\r\n * Built using CHelper plug-in\r\n * Actual solution is at the top\r\n */\r\npublic class Main {\r\n public static void main(String[] args) {\r\n InputStream inputStream = System.in;\r\n OutputStream outputStream = System.out;\r\n InputReader in = new InputReader(inputStream);\r\n OutputWriter out = new OutputWriter(outputStream);\r\n FNezzarAndChocolateBars solver = new FNezzarAndChocolateBars();\r\n solver.solve(1, in, out);\r\n out.close();\r\n }\r\n\r\n static class FNezzarAndChocolateBars {\r\n static final int MAXN = 2048;\r\n\r\n public void solve(int testNumber, InputReader in, OutputWriter out) {\r\n MOD2 mod = new MOD2();\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] = mod.multiply(fact[i - 1], i);\r\n ifact[i] = mod.inverse(fact[i]);\r\n }\r\n int n = in.nextInt(), k = in.nextInt();\r\n int[] l = in.readIntArray(n);\r\n int[][][] dp = new int[2][MAXN / k][MAXN / k];\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 = mod.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 = mod.subtract(0, z);\r\n coeffs[i] = mod.multiply(z, mod.power(L - k * i, i));\r\n\r\n if (i >= 1) {\r\n coeffs2[i] = mod.multiply(z, mod.multiply(i, mod.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 <= s / k; 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 + t] = mod.add(dp[r][i + t][j + t], mod.multiply(value, coeffs[t]));\r\n if (t > 0) {\r\n dp[r][i + t - 1][j + t] = mod.add(dp[r][i + t - 1][j + t], mod.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 j = 1; j <= s / k; j++) {\r\n int value = dp[(n - 1) & 1][i][j];\r\n int temp = mod.multiply(fact[i], mod.inverse(mod.power(k * j, i + 1)));\r\n answer = mod.add(answer, mod.multiply(value, temp));\r\n }\r\n out.println(mod.multiply(mod.subtract(0, s), answer));\r\n }\r\n\r\n }\r\n\r\n static class MOD2 {\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 }\r\n\r\n static class InputReader {\r\n private InputStream stream;\r\n private byte[] buf = new byte[1024];\r\n private int curChar;\r\n private int numChars;\r\n private InputReader.SpaceCharFilter filter;\r\n\r\n public InputReader(InputStream stream) {\r\n this.stream = stream;\r\n }\r\n\r\n public int[] readIntArray(int size) {\r\n int[] array = new int[size];\r\n for (int i = 0; i < size; i++) {\r\n array[i] = readInt();\r\n }\r\n return array;\r\n }\r\n\r\n public int read() {\r\n if (numChars == -1) {\r\n throw new InputMismatchException();\r\n }\r\n if (curChar >= numChars) {\r\n curChar = 0;\r\n try {\r\n numChars = stream.read(buf);\r\n } catch (IOException e) {\r\n throw new InputMismatchException();\r\n }\r\n if (numChars <= 0) {\r\n return -1;\r\n }\r\n }\r\n return buf[curChar++];\r\n }\r\n\r\n public int nextInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9')\r\n throw new InputMismatchException();\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n\r\n public int readInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) {\r\n c = read();\r\n }\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') {\r\n throw new InputMismatchException();\r\n }\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n\r\n public boolean isSpaceChar(int c) {\r\n if (filter != null) {\r\n return filter.isSpaceChar(c);\r\n }\r\n return isWhitespace(c);\r\n }\r\n\r\n public static boolean isWhitespace(int c) {\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n }\r\n\r\n public interface SpaceCharFilter {\r\n public boolean isSpaceChar(int ch);\r\n\r\n }\r\n\r\n }\r\n\r\n static class OutputWriter {\r\n private final PrintWriter writer;\r\n\r\n public OutputWriter(OutputStream outputStream) {\r\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\r\n }\r\n\r\n public OutputWriter(Writer writer) {\r\n this.writer = new PrintWriter(writer);\r\n }\r\n\r\n public void println(Object... objects) {\r\n for (int i = 0; i < objects.length; i++) {\r\n if (i != 0) {\r\n writer.print(' ');\r\n }\r\n writer.print(objects[i]);\r\n }\r\n writer.print('\\n');\r\n }\r\n\r\n public void close() {\r\n writer.close();\r\n }\r\n\r\n }\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ccfbae5e83a1a8782cb68ea515a4b44", "src_uid": "26d565c193a5920b042c783109496b4c", "difficulty": 3500.0} {"lang": "Java 6", "source_code": "//package round93;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.TreeSet;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"WWWWWWWW\\r\\n\" + \n\t\t\t\"WBYWRBBY\\r\\n\" + \n\t\t\t\"BRYRBWYY\\r\\n\" + \n\t\t\t\"WWBRYWBB\\r\\n\" + \n\t\t\t\"BWWRWBYW\\r\\n\" + \n\t\t\t\"RBWRBWYY\\r\\n\" + \n\t\t\t\"WWWWWWWW\\r\\n\" + \n\t\t\t\"0 0 0 1\\r\\n\" + \n\t\t\t\"0 0 1\\r\\n\" + \n\t\t\t\"0 1\\r\\n\" + \n\t\t\t\"25\";\n\t\n\tvoid solve()\n\t{\n\t\tb = new char[7][8];\n\t\tfor(int i = 0;i < 7;i++){\n\t\t\tb[i] = ns(8);\n\t\t}\n\t\tint[] co = new int[10];\n\t\tfor(int i = 0;i < 10;i++)co[i] = ni();\n\t\t\n\t\tString[] PILL = {\n\t\t\t\t\"BY\",\"BW\",\"BR\",\"BB\",\n\t\t\t\t\"RY\",\"RW\",\"RR\",\n\t\t\t\t\"WY\",\"WW\",\n\t\t\t\t\"YY\"\t\n\t\t};\n\t\tint[][] ctp = new int[10][26];\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfor(int j = 0;j < 2;j++){\n\t\t\t\tctp[i][PILL[i].charAt(j)-'A']++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] C = new int[10][10];\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfor(int j = 0;j < 10;j++){\n\t\t\t\tint tot = 0;\n\t\t\t\tfor(int k = 0;k < 26;k++){\n\t\t\t\t\ttot += Math.min(ctp[i][k], ctp[j][k]);\n\t\t\t\t}\n\t\t\t\tC[i][j] = tot;\n\t\t\t}\n\t\t}\n\t\t\n\t\tmap = new int[26*26];\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tint f = PILL[i].charAt(0)-'A';\n\t\t\tint l = PILL[i].charAt(1)-'A';\n\t\t\tmap[f*26+l] = i;\n\t\t\tmap[l*26+f] = i;\n\t\t}\n\t\tused = new boolean[7][8];\n\t\tct = new int[10];\n\t\thist = new int[28];\n\t\tctmap = new HashMap();\n\t\tstep = 0;\n\t\t\n\t\trec(0, 0);\n\t\t\n\t\tint m = 10+100+10;\n\t\tint[] from = new int[m];\n\t\tint[] to = new int[m];\n\t\tint[] c = new int[m];\n\t\tint[] cap = new int[m];\n\t\tint O = 0;\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfrom[i+O] = 20; to[i+O] = i; c[i+O] = 0; cap[i+O] = 0; // Datum\n\t\t}\n\t\tO += 10;\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfrom[i+O] = i+10; to[i+O] = 21; c[i+O] = 0; cap[i+O] = co[i];\n\t\t}\n\t\tO += 10;\n\t\tfor(int i = 0;i < 100;i++){\n\t\t\tfrom[i+O] = i/10; to[i+O] = i%10+10; c[i+O] = 2-C[i/10][i%10]; cap[i+O] = 999;\n\t\t}\n\t\t\n\t\tint[][][] cost = packWD(22, from, to, c);\n\t\tint[][][] capacity = packWD(22, from, to, cap);\n\t\t\n\t\tint mincost = 999;\n\t\tint[] opthist = null;\n\t\tint[][] optF = new int[10][10];\n\t\tfor(Datum d : ctmap.values()){\n\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\tcapacity[20][9-i][1] = d.ct[i];\n\t\t\t}\n\t\t\tint mc = solveMinCostFlow(cost, capacity, 20, 21, 28);\n\t\t\tif(mc < mincost){\n\t\t\t\tmincost = mc;\n\t\t\t\topthist = d.hist;\n\t\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\t\tfor(int j = 0;j < 10;j++){\n\t\t\t\t\t\toptF[i][j] = F[i][9-j][1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\ttr(mincost);\n//\t\ttr(opthist);\n//\t\t\n//\t\tint S = 0;\n//\t\tfor(int i = 0;i < 10;i++){\n//\t\t\tfor(int j = 0;j < 10;j++){\n//\t\t\t\tS += optF[i][j];\n//\t\t\t}\n//\t\t}\n//\t\tif(S != 28)throw new AssertionError(S);\n\t\t\n\t\tout.println(56-mincost);\n\t\t\n\t\tchar[][] ret = new char[13][15];\n\t\tfor(int i = 0;i < 13;i++){\n\t\t\tArrays.fill(ret[i], '.');\n\t\t}\n\t\t\n\t\tfor(int h : opthist){\n\t\t\tif(h < 64){\n\t\t\t\t// |\n\t\t\t\tint rr = h/8, cc = h%8;\n\t\t\t\tret[rr*2+1][cc*2] = '|';\n\t\t\t\t\n\t\t\t\tint k = map[(b[rr][cc]-'A')*26+(b[rr+1][cc]-'A')];\n\t\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\t\tif(optF[k][i] > 0){\n\t\t\t\t\t\tif(flip(b[rr][cc], b[rr+1][cc], PILL[i].charAt(0), PILL[i].charAt(1))){\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(1);\n\t\t\t\t\t\t\tret[rr*2+2][cc*2] = PILL[i].charAt(0);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(0);\n\t\t\t\t\t\t\tret[rr*2+2][cc*2] = PILL[i].charAt(1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\toptF[k][i]--;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\th -= 64;\n\t\t\t\t// -\n\t\t\t\tint rr = h/8, cc = h%8;\n\t\t\t\tret[rr*2][cc*2+1] = '-';\n\t\t\t\t\n\t\t\t\tint k = map[(b[rr][cc]-'A')*26+(b[rr][cc+1]-'A')];\n\n\t\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\t\tif(optF[k][i] > 0){\n\t\t\t\t\t\tif(flip(b[rr][cc], b[rr][cc+1], PILL[i].charAt(0), PILL[i].charAt(1))){\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(1);\n\t\t\t\t\t\t\tret[rr*2][cc*2+2] = PILL[i].charAt(0);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(0);\n\t\t\t\t\t\t\tret[rr*2][cc*2+2] = PILL[i].charAt(1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\toptF[k][i]--;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0;i < 13;i++){\n\t\t\tout.println(new String(ret[i]));\n\t\t}\n\t}\n\t\n\tstatic boolean flip(char a, char b, char c, char d)\n\t{\n\t\tint d1 = (a==c?1:0) + (b==d?1:0);\n\t\tint d2 = (a==d?1:0) + (b==c?1:0);\n\t\treturn d2 > d1;\n\t}\n\t\n\tpublic static int[][][] packWD(int n, int[] from, int[] to, int[] w)\n\t{\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]][2];\n\t\tfor(int i = 0;i < from.length;i++){\n\t\t\t--p[from[i]];\n\t\t\tg[from[i]][p[from[i]]][0] = to[i];\n\t\t\tg[from[i]][p[from[i]]][1] = w[i];\n\t\t}\n\t\treturn g;\n\t}\n\t\n\tint[][][] F;\n\t\n\tpublic int solveMinCostFlow(int[][][] cost, int[][][] capacity, int src, int sink, int all)\n\t{\n\t\tint n = cost.length;\n\t\t\n\t\tint[][][] flow = new int[n][][];\n\t\tfor(int i = 0;i < n;i++) {\n\t\t\tflow[i] = new int[cost[i].length][2];\n\t\t\tfor(int j = 0;j < cost[i].length;j++){\n\t\t\t\tflow[i][j][0] = cost[i][j][0];\n\t\t\t}\n\t\t}\n\t\t\n\t\t// unweighted invgraph\n\t\t// \u9006\u30b0\u30e9\u30d5\u306ecur\u306ei\u756a\u76ee=next\u306e\u3068\u304d\u3001\u9806\u30b0\u30e9\u30d5\u3067cur\u306fnext\u306e\u4f55\u756a\u76ee\u306b\u3042\u308b\u304b\u3092\u8fd4\u3059\n\t\tint[][][] ig = new int[n][][];\n\t\t{\n\t\t\tint[] p = new int[n];\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tfor(int j = 0;j < cost[i].length;j++)p[cost[i][j][0]]++;\n\t\t\t}\n\t\t\tfor(int i = 0;i < n;i++)ig[i] = new int[p[i]][2];\n\t\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\t\tfor(int j = 0;j < cost[i].length;j++){\n\t\t\t\t\tint u = --p[cost[i][j][0]];\n\t\t\t\t\tig[cost[i][j][0]][u][0] = i;\n\t\t\t\t\tig[cost[i][j][0]][u][1] = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint mincost = 0;\n\t\tint[] pot = new int[n]; // \u30dd\u30c6\u30f3\u30b7\u30e3\u30eb\n\t\t\n\t\tfinal int[] d = new int[n];\n\t\tTreeSet q = new TreeSet(new Comparator(){\n\t\t\tpublic int compare(Integer a, Integer b)\n\t\t\t{\n\t\t\t\tif(d[a] - d[b] != 0)return d[a] - d[b];\n\t\t\t\treturn a - b;\n\t\t\t}\n\t\t});\n\t\twhile(all > 0){\n\t\t\t// src~sink\u306e\u6700\u77ed\u8def\u3092\u63a2\u3059\n\t\t\tint[] prev = new int[n];\n\t\t\tint[] myind = new int[n];\n\t\t\tArrays.fill(prev, -1);\n\t\t\tArrays.fill(d, Integer.MAX_VALUE / 2);\n\t\t\td[src] = 0;\n\t\t\tq.clear();\n\t\t\tq.add(src);\n\t\t\twhile(!q.isEmpty()){\n\t\t\t\tint cur = q.pollFirst();\n\t\t\t\tif(cur == sink)break;\n\t\t\t\tfor(int i = 0;i < cost[cur].length;i++) {\n\t\t\t\t\tint next = cost[cur][i][0];\n\t\t\t\t\tif(capacity[cur][i][1] - flow[cur][i][1] > 0){\n\t\t\t\t\t\tint nd = d[cur] + cost[cur][i][1] + pot[cur] - pot[next];\n\t\t\t\t\t\tif(d[next] > nd){\n\t\t\t\t\t\t\tq.remove(next);\n\t\t\t\t\t\t\td[next] = nd;\n\t\t\t\t\t\t\tprev[next] = cur;\n\t\t\t\t\t\t\tmyind[next] = i;\n\t\t\t\t\t\t\tq.add(next);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i = 0;i < ig[cur].length;i++) {\n\t\t\t\t\tint next = ig[cur][i][0];\n\t\t\t\t\tint cind = ig[cur][i][1];\n\t\t\t\t\tif(flow[next][cind][1] > 0){\n\t\t\t\t\t\tint nd = d[cur] - cost[next][cind][1] + pot[cur] - pot[next];\n\t\t\t\t\t\tif(d[next] > nd){\n\t\t\t\t\t\t\tq.remove(next);\n\t\t\t\t\t\t\td[next] = nd;\n\t\t\t\t\t\t\tprev[next] = cur;\n\t\t\t\t\t\t\tmyind[next] = -cind-1;\n\t\t\t\t\t\t\tq.add(next);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(prev[sink] == -1)break;\n\t\t\t\n\t\t\tint minflow = all;\n\t\t\tint sumcost = 0;\n\t\t\tfor(int i = sink;i != src;i = prev[i]){\n\t\t\t\tif(myind[i] >= 0){\n\t\t\t\t\tminflow = Math.min(minflow, capacity[prev[i]][myind[i]][1] - flow[prev[i]][myind[i]][1]);\n\t\t\t\t\tsumcost += cost[prev[i]][myind[i]][1];\n\t\t\t\t}else{\n\t\t\t\t\t// cur->next\n\t\t\t\t\t// prev[i]->i\n\t\t\t\t\t// i\u304c\u6301\u3063\u3066\u308b\n\t\t\t\t\t// ig[cur][j][0]=next\u306e\u3068\u304dg[next][ig[cur][j][1]] = cur\n\t\t\t\t\tint ind = -myind[i]-1;\n//\t\t\t\t\ttr(prev[i], ind);\n\t\t\t\t\tminflow = Math.min(minflow, flow[i][ind][1]);\n\t\t\t\t\tsumcost -= cost[i][ind][1];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tmincost += minflow * sumcost;\n\t\t\tfor(int i = sink;i != src;i = prev[i]){\n\t\t\t\tif(myind[i] >= 0){\n\t\t\t\t\tflow[prev[i]][myind[i]][1] += minflow;\n\t\t\t\t}else{\n\t\t\t\t\tint ind = -myind[i]-1;\n\t\t\t\t\tflow[i][ind][1] -= minflow;\n\t\t\t\t}\n\t\t\t}\n//\t\t\ttr(flow);\n\t\t\t\n\t\t\tall -= minflow;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tpot[i] += d[i];\n\t\t\t}\n\t\t}\n\t\tF = flow;\n\t\treturn mincost;\n\t}\n\t\n\tstatic class Datum\n\t{\n\t\tpublic int[] ct;\n\t\tpublic int[] hist;\n\t}\n\t\n\tboolean[][] used;\n\tint[] ct;\n\tint[] hist;\n\tMap ctmap;\n\tint[] map;\n\tchar[][] b;\n\tint step;\n\t\n\tvoid rec(int r, int c)\n\t{\n\t\tif(r >= 7){\n\t\t\tint h = Arrays.hashCode(ct);\n\t\t\tif(!ctmap.containsKey(h)){\n\t\t\t\tDatum d = new Datum();\n\t\t\t\td.ct = Arrays.copyOf(ct, 10);\n\t\t\t\td.hist = Arrays.copyOf(hist, 28);\n\t\t\t\tctmap.put(h, d);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif(c >= 8){\n\t\t\trec(r+1, 0);\n\t\t\treturn;\n\t\t}\n\t\tif(used[r][c]){\n\t\t\trec(r, c+1);\n\t\t\treturn;\n\t\t}\n\t\tif(r+1 < 7 && !used[r+1][c]){\n\t\t\tused[r][c] = true;\n\t\t\tused[r+1][c] = true;\n\t\t\tint kind = map[(b[r][c]-'A')*26+(b[r+1][c]-'A')];\n\t\t\tct[kind]++;\n\t\t\thist[step] = r*8+c;\n\t\t\tstep++;\n\t\t\trec(r, c+1);\n\t\t\tstep--;\n\t\t\tct[kind]--;\n\t\t\tused[r][c] = false;\n\t\t\tused[r+1][c] = false;\n\t\t}\n\t\tif(c+1 < 8 && !used[r][c+1]){\n\t\t\tused[r][c] = true;\n\t\t\tused[r][c+1] = true;\n\t\t\tint kind = map[(b[r][c]-'A')*26+(b[r][c+1]-'A')];\n\t\t\tct[kind]++;\n\t\t\thist[step] = r*8+c+64;\n\t\t\tstep++;\n\t\t\trec(r, c+2);\n\t\t\tstep--;\n\t\t\tct[kind]--;\n\t\t\tused[r][c] = false;\n\t\t\tused[r][c+1] = false;\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\n\t{\n\t\tnew E().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "568516b68cd36d1ab125f6712f0ba663", "src_uid": "cb56e7578ec5e04118993444283ad1eb", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "//package round93;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.TreeSet;\n\npublic class E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"BBWWRRYY\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"WRRYYBBW\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"WYBBWWRW\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"BYWRRYRY\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"BRWBBYBY\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"WRYYWWBR\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"WBBRRYYR\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"0 0 0 7\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"0 0 7\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"0 7\\r\\n\" + \n\t\t\t\"\\r\\n\" + \n\t\t\t\"7\";\n\t\n\tvoid solve()\n\t{\n\t\tb = new char[7][8];\n\t\tfor(int i = 0;i < 7;i++){\n\t\t\tb[i] = ns(8);\n\t\t}\n\t\tint[] co = new int[10];\n\t\tfor(int i = 0;i < 10;i++)co[i] = ni();\n\t\t\n\t\tString[] PILL = {\n\t\t\t\t\"BY\",\"BW\",\"BR\",\"BB\",\n\t\t\t\t\"RY\",\"RW\",\"RR\",\n\t\t\t\t\"WY\",\"WW\",\n\t\t\t\t\"YY\"\t\n\t\t};\n\t\tint[][] ctp = new int[10][26];\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfor(int j = 0;j < 2;j++){\n\t\t\t\tctp[i][PILL[i].charAt(j)-'A']++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] C = new int[10][10];\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfor(int j = 0;j < 10;j++){\n\t\t\t\tint tot = 0;\n\t\t\t\tfor(int k = 0;k < 26;k++){\n\t\t\t\t\ttot += Math.min(ctp[i][k], ctp[j][k]);\n\t\t\t\t}\n\t\t\t\tC[i][j] = tot;\n\t\t\t}\n\t\t}\n\t\t\n\t\tmap = new int[26*26];\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tint f = PILL[i].charAt(0)-'A';\n\t\t\tint l = PILL[i].charAt(1)-'A';\n\t\t\tmap[f*26+l] = i;\n\t\t\tmap[l*26+f] = i;\n\t\t}\n\t\tused = new boolean[7][8];\n\t\tct = new int[10];\n\t\thist = new int[28];\n\t\tctmap = new HashMap();\n\t\tstep = 0;\n\t\t\n\t\trec(0, 0);\n\t\t\n\t\tint m = 10+100+10;\n\t\tint[] from = new int[m];\n\t\tint[] to = new int[m];\n\t\tint[] c = new int[m];\n\t\tint[] cap = new int[m];\n\t\tint O = 0;\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfrom[i+O] = 20; to[i+O] = i; c[i+O] = 0; cap[i+O] = 0; // Datum\n\t\t}\n\t\tO += 10;\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tfrom[i+O] = i+10; to[i+O] = 21; c[i+O] = 0; cap[i+O] = co[i];\n\t\t}\n\t\tO += 10;\n\t\tfor(int i = 0;i < 100;i++){\n\t\t\tfrom[i+O] = i/10; to[i+O] = i%10+10; c[i+O] = 2-C[i/10][i%10]; cap[i+O] = 999;\n\t\t}\n\t\t\n\t\tint[][][] cost = packWD(22, from, to, c);\n\t\tint[][][] capacity = packWD(22, from, to, cap);\n\t\t\n\t\t// unweighted invgraph\n\t\t// \u9006\u30b0\u30e9\u30d5\u306ecur\u306ei\u756a\u76ee=next\u306e\u3068\u304d\u3001\u9806\u30b0\u30e9\u30d5\u3067cur\u306fnext\u306e\u4f55\u756a\u76ee\u306b\u3042\u308b\u304b\u3092\u8fd4\u3059\n\t\tint n = 22;\n\t\tint[][][] ig = new int[n][][];\n\t\t{\n\t\t\tint[] p = new int[n];\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tfor(int j = 0;j < cost[i].length;j++)p[cost[i][j][0]]++;\n\t\t\t}\n\t\t\tfor(int i = 0;i < n;i++)ig[i] = new int[p[i]][2];\n\t\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\t\tfor(int j = 0;j < cost[i].length;j++){\n\t\t\t\t\tint u = --p[cost[i][j][0]];\n\t\t\t\t\tig[cost[i][j][0]][u][0] = i;\n\t\t\t\t\tig[cost[i][j][0]][u][1] = j;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint mincost = 999;\n\t\tint[] opthist = null;\n\t\tint[][] optF = new int[10][10];\n\t\tfor(Datum d : ctmap.values()){\n\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\tcapacity[20][9-i][1] = d.ct[i];\n\t\t\t}\n\t\t\tint mc = solveMinCostFlow(cost, capacity, ig, 20, 21, 28);\n\t\t\tif(mc < mincost){\n\t\t\t\tmincost = mc;\n\t\t\t\topthist = d.hist;\n\t\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\t\tfor(int j = 0;j < 10;j++){\n\t\t\t\t\t\toptF[i][j] = F[i][9-j][1];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\ttr(mincost);\n//\t\ttr(opthist);\n//\t\t\n//\t\tint S = 0;\n//\t\tfor(int i = 0;i < 10;i++){\n//\t\t\tfor(int j = 0;j < 10;j++){\n//\t\t\t\tS += optF[i][j];\n//\t\t\t}\n//\t\t}\n//\t\tif(S != 28)throw new AssertionError(S);\n\t\t\n\t\tout.println(56-mincost);\n\t\t\n\t\tchar[][] ret = new char[13][15];\n\t\tfor(int i = 0;i < 13;i++){\n\t\t\tArrays.fill(ret[i], '.');\n\t\t}\n\t\t\n\t\tfor(int h : opthist){\n\t\t\tif(h < 64){\n\t\t\t\t// |\n\t\t\t\tint rr = h/8, cc = h%8;\n\t\t\t\tret[rr*2+1][cc*2] = '|';\n\t\t\t\t\n\t\t\t\tint k = map[(b[rr][cc]-'A')*26+(b[rr+1][cc]-'A')];\n\t\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\t\tif(optF[k][i] > 0){\n\t\t\t\t\t\tif(flip(b[rr][cc], b[rr+1][cc], PILL[i].charAt(0), PILL[i].charAt(1))){\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(1);\n\t\t\t\t\t\t\tret[rr*2+2][cc*2] = PILL[i].charAt(0);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(0);\n\t\t\t\t\t\t\tret[rr*2+2][cc*2] = PILL[i].charAt(1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\toptF[k][i]--;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\th -= 64;\n\t\t\t\t// -\n\t\t\t\tint rr = h/8, cc = h%8;\n\t\t\t\tret[rr*2][cc*2+1] = '-';\n\t\t\t\t\n\t\t\t\tint k = map[(b[rr][cc]-'A')*26+(b[rr][cc+1]-'A')];\n\n\t\t\t\tfor(int i = 0;i < 10;i++){\n\t\t\t\t\tif(optF[k][i] > 0){\n\t\t\t\t\t\tif(flip(b[rr][cc], b[rr][cc+1], PILL[i].charAt(0), PILL[i].charAt(1))){\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(1);\n\t\t\t\t\t\t\tret[rr*2][cc*2+2] = PILL[i].charAt(0);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tret[rr*2][cc*2] = PILL[i].charAt(0);\n\t\t\t\t\t\t\tret[rr*2][cc*2+2] = PILL[i].charAt(1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\toptF[k][i]--;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0;i < 13;i++){\n\t\t\tout.println(new String(ret[i]));\n\t\t}\n\t}\n\t\n\tstatic boolean flip(char a, char b, char c, char d)\n\t{\n\t\tint d1 = (a==c?1:0) + (b==d?1:0);\n\t\tint d2 = (a==d?1:0) + (b==c?1:0);\n\t\treturn d2 > d1;\n\t}\n\t\n\tpublic static int[][][] packWD(int n, int[] from, int[] to, int[] w)\n\t{\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]][2];\n\t\tfor(int i = 0;i < from.length;i++){\n\t\t\t--p[from[i]];\n\t\t\tg[from[i]][p[from[i]]][0] = to[i];\n\t\t\tg[from[i]][p[from[i]]][1] = w[i];\n\t\t}\n\t\treturn g;\n\t}\n\t\n\tint[][][] F;\n\t\n\tpublic int solveMinCostFlow(int[][][] cost, int[][][] capacity, int[][][] ig, int src, int sink, int all)\n\t{\n\t\tint n = cost.length;\n\t\t\n\t\tint[][][] flow = new int[n][][];\n\t\tfor(int i = 0;i < n;i++) {\n\t\t\tflow[i] = new int[cost[i].length][2];\n\t\t\tfor(int j = 0;j < cost[i].length;j++){\n\t\t\t\tflow[i][j][0] = cost[i][j][0];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint mincost = 0;\n\t\tint[] pot = new int[n]; // \u30dd\u30c6\u30f3\u30b7\u30e3\u30eb\n\t\t\n\t\tfinal int[] d = new int[n];\n\t\tTreeSet q = new TreeSet(new Comparator(){\n\t\t\tpublic int compare(Integer a, Integer b)\n\t\t\t{\n\t\t\t\tif(d[a] - d[b] != 0)return d[a] - d[b];\n\t\t\t\treturn a - b;\n\t\t\t}\n\t\t});\n\t\twhile(all > 0){\n\t\t\t// src~sink\u306e\u6700\u77ed\u8def\u3092\u63a2\u3059\n\t\t\tint[] prev = new int[n];\n\t\t\tint[] myind = new int[n];\n\t\t\tArrays.fill(prev, -1);\n\t\t\tArrays.fill(d, Integer.MAX_VALUE / 2);\n\t\t\td[src] = 0;\n\t\t\tq.clear();\n\t\t\tq.add(src);\n\t\t\twhile(!q.isEmpty()){\n\t\t\t\tint cur = q.pollFirst();\n\t\t\t\tif(cur == sink)break;\n\t\t\t\tfor(int i = 0;i < cost[cur].length;i++) {\n\t\t\t\t\tint next = cost[cur][i][0];\n\t\t\t\t\tif(capacity[cur][i][1] - flow[cur][i][1] > 0){\n\t\t\t\t\t\tint nd = d[cur] + cost[cur][i][1] + pot[cur] - pot[next];\n\t\t\t\t\t\tif(d[next] > nd){\n\t\t\t\t\t\t\tq.remove(next);\n\t\t\t\t\t\t\td[next] = nd;\n\t\t\t\t\t\t\tprev[next] = cur;\n\t\t\t\t\t\t\tmyind[next] = i;\n\t\t\t\t\t\t\tq.add(next);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i = 0;i < ig[cur].length;i++) {\n\t\t\t\t\tint next = ig[cur][i][0];\n\t\t\t\t\tint cind = ig[cur][i][1];\n\t\t\t\t\tif(flow[next][cind][1] > 0){\n\t\t\t\t\t\tint nd = d[cur] - cost[next][cind][1] + pot[cur] - pot[next];\n\t\t\t\t\t\tif(d[next] > nd){\n\t\t\t\t\t\t\tq.remove(next);\n\t\t\t\t\t\t\td[next] = nd;\n\t\t\t\t\t\t\tprev[next] = cur;\n\t\t\t\t\t\t\tmyind[next] = -cind-1;\n\t\t\t\t\t\t\tq.add(next);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(prev[sink] == -1)break;\n\t\t\t\n\t\t\tint minflow = all;\n\t\t\tint sumcost = 0;\n\t\t\tfor(int i = sink;i != src;i = prev[i]){\n\t\t\t\tif(myind[i] >= 0){\n\t\t\t\t\tminflow = Math.min(minflow, capacity[prev[i]][myind[i]][1] - flow[prev[i]][myind[i]][1]);\n\t\t\t\t\tsumcost += cost[prev[i]][myind[i]][1];\n\t\t\t\t}else{\n\t\t\t\t\t// cur->next\n\t\t\t\t\t// prev[i]->i\n\t\t\t\t\t// i\u304c\u6301\u3063\u3066\u308b\n\t\t\t\t\t// ig[cur][j][0]=next\u306e\u3068\u304dg[next][ig[cur][j][1]] = cur\n\t\t\t\t\tint ind = -myind[i]-1;\n//\t\t\t\t\ttr(prev[i], ind);\n\t\t\t\t\tminflow = Math.min(minflow, flow[i][ind][1]);\n\t\t\t\t\tsumcost -= cost[i][ind][1];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tmincost += minflow * sumcost;\n\t\t\tfor(int i = sink;i != src;i = prev[i]){\n\t\t\t\tif(myind[i] >= 0){\n\t\t\t\t\tflow[prev[i]][myind[i]][1] += minflow;\n\t\t\t\t}else{\n\t\t\t\t\tint ind = -myind[i]-1;\n\t\t\t\t\tflow[i][ind][1] -= minflow;\n\t\t\t\t}\n\t\t\t}\n//\t\t\ttr(flow);\n\t\t\t\n\t\t\tall -= minflow;\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tpot[i] += d[i];\n\t\t\t}\n\t\t}\n\t\tF = flow;\n\t\treturn mincost;\n\t}\n\t\n\tstatic class Datum\n\t{\n\t\tpublic int[] ct;\n\t\tpublic int[] hist;\n\t}\n\t\n\tboolean[][] used;\n\tint[] ct;\n\tint[] hist;\n\tMap ctmap;\n\tint[] map;\n\tchar[][] b;\n\tint step;\n\t\n\tvoid rec(int r, int c)\n\t{\n\t\tif(r >= 7){\n\t\t\tint h = Arrays.hashCode(ct);\n\t\t\tif(!ctmap.containsKey(h)){\n\t\t\t\tDatum d = new Datum();\n\t\t\t\td.ct = Arrays.copyOf(ct, 10);\n\t\t\t\td.hist = Arrays.copyOf(hist, 28);\n\t\t\t\tctmap.put(h, d);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif(c >= 8){\n\t\t\trec(r+1, 0);\n\t\t\treturn;\n\t\t}\n\t\tif(used[r][c]){\n\t\t\trec(r, c+1);\n\t\t\treturn;\n\t\t}\n\t\tif(r+1 < 7 && !used[r+1][c]){\n\t\t\tused[r][c] = true;\n\t\t\tused[r+1][c] = true;\n\t\t\tint kind = map[(b[r][c]-'A')*26+(b[r+1][c]-'A')];\n\t\t\tct[kind]++;\n\t\t\thist[step] = r*8+c;\n\t\t\tstep++;\n\t\t\trec(r, c+1);\n\t\t\tstep--;\n\t\t\tct[kind]--;\n\t\t\tused[r][c] = false;\n\t\t\tused[r+1][c] = false;\n\t\t}\n\t\tif(c+1 < 8 && !used[r][c+1]){\n\t\t\tused[r][c] = true;\n\t\t\tused[r][c+1] = true;\n\t\t\tint kind = map[(b[r][c]-'A')*26+(b[r][c+1]-'A')];\n\t\t\tct[kind]++;\n\t\t\thist[step] = r*8+c+64;\n\t\t\tstep++;\n\t\t\trec(r, c+2);\n\t\t\tstep--;\n\t\t\tct[kind]--;\n\t\t\tused[r][c] = false;\n\t\t\tused[r][c+1] = false;\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\n\t{\n\t\tnew E().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d832644c1bf25274c4976a78991351ef", "src_uid": "cb56e7578ec5e04118993444283ad1eb", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n n = in.nextInt();\n for (int i = 1; i <= n; i++) {\n g[i] = new ArrayList<>();\n }\n for (int i = 0; i < n - 1; i++) {\n int u = in.nextInt(), v = in.nextInt();\n g[u].add(v);\n g[v].add(u);\n }\n dfs1(1, -1);\n int[] a = new int[2];\n int mx = n + 1;\n for (int i = 1; i <= n; i++) {\n if (msz[i] < mx) {\n mx = msz[i];\n a[0] = i;\n a[1] = -1;\n } else if (msz[i] == mx) {\n a[1] = i;\n }\n }\n root = a[0];\n for (int v : g[a[0]]) {\n if (v != a[1]) {\n goal = last = v;\n dfs2(v, a[0]);\n add(a[0], last, v);\n }\n }\n if (a[1] != -1) {\n root = a[1];\n for (int v : g[a[1]]) {\n if (v != a[0]) {\n goal = last = v;\n dfs2(v, a[1]);\n add(a[1], last, v);\n }\n }\n }\n out.println(ans.size());\n for (int[] arr : ans) {\n out.println(arr[0] + \" \" + arr[1] + \" \" + arr[2]);\n }\n out.close();\n }\n\n static ArrayList[] g = new ArrayList[200001];\n static int[] msz = new int[200001];\n static int[] sz = new int[200001];\n static int n;\n static ArrayList ans = new ArrayList<>();\n static int goal;\n static int root;\n static int last;\n\n static void add(int x, int y, int z) {\n int[] t = {x, y, z};\n ans.add(t);\n }\n\n static void dfs1(int u, int fa) {\n sz[u] = 1;\n for (int v : g[u]) {\n if (v != fa) {\n dfs1(v, u);\n sz[u] += sz[v];\n msz[u] = Math.max(msz[u], sz[v]);\n }\n }\n msz[u] = Math.max(msz[u], n - sz[u]);\n }\n\n static void dfs2(int u, int fa) {\n if (u != goal) {\n add(root, last, u);\n add(u, fa, goal);\n last = u;\n }\n for (int v : g[u]) {\n if (v != fa) {\n dfs2(v, u);\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f8dae1a1f6d8b51d3984596bd4fffc6", "src_uid": "32fdea91454384b103f52743c1128cfc", "difficulty": 2600.0} {"lang": "Java 11", "source_code": "//package ecr104;\r\nimport java.io.*;\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.InputMismatchException;\r\nimport java.util.Queue;\r\n\r\npublic class G3 {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n\r\n\tvoid solve()\r\n\t{\r\n\t\tfinal int mod = 998244353;\r\n\t\tint n = ni();\r\n\t\tint[] a = na(26);\r\n\t\tlong all = 26 * 26 * pow(25, n-2, mod) % mod;\r\n\r\n\t\tlong[][][] dp = new long[3][n+1][n+1];\r\n\t\tdp[0][1][0] = 1;\r\n\t\tdp[1][0][1] = 1;\r\n\t\tdp[2][0][0] = 1;\r\n\t\tfor(int i = 0;i < n-1;i++){\r\n\t\t\tlong[][][] ndp = new long[3][n+1][n+1];\r\n\t\t\tif(i == (n+1)/2-1){\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else {\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 23;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\tdp = ndp;\r\n\t\t}\r\n\r\n\t\tlong[] sdp = new long[n+1];\r\n\t\tfor(int i = 0;i <= n;i++){\r\n\t\t\tfor(int j = 0;j <= n;j++){\r\n\t\t\t\tsdp[i] += dp[0][i][j] + dp[1][i][j] + dp[2][i][j] * 24;\r\n\t\t\t}\r\n\t\t\tsdp[i] %= mod;\r\n\t\t}\r\n\r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\tall -= sdp[k];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int j = i+1;j < 26;j++){\r\n\t\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\t\tfor(int l = a[j]+1;l+k <= n;l++){\r\n\t\t\t\t\t\tall += (dp[0][k][l] + dp[1][k][l] + dp[2][k][l] * 24);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tall %= mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\tall %= mod;\r\n\r\n\t\tif(all < 0)all += mod;\r\n\t\tout.println(all);\r\n\t}\r\n\r\n\tpublic static long pow(long a, long n, long mod) {\r\n\t\t//\t\ta %= mod;\r\n\t\tlong ret = 1;\r\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\tfor (; x >= 0; x--) {\r\n\t\t\tret = ret * ret % mod;\r\n\t\t\tif (n << 63 - x < 0) ret = ret * a % mod;\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\r\n\r\n\tpublic static long invl(long a, long mod) {\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\treturn p < 0 ? p + mod : p;\r\n\t}\r\n\r\n\r\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\r\n\t\tif (n < 0 || r < 0 || r > n) return 0;\r\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\r\n\t}\r\n\r\n\r\n\tpublic static int[][] enumFIF(int n, int mod) {\r\n\t\tint[] f = new int[n + 1];\r\n\t\tint[] invf = new int[n + 1];\r\n\t\tf[0] = 1;\r\n\t\tfor (int i = 1; i <= n; i++) {\r\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\r\n\t\t}\r\n\t\tlong a = f[n];\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\r\n\t\tfor (int i = n - 1; i >= 0; i--) {\r\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\r\n\t\t}\r\n\t\treturn new int[][]{f, invf};\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new G3().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f6538004f1852ff67a2968859a8eff4f", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "//package ecr104;\r\nimport java.io.*;\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.InputMismatchException;\r\nimport java.util.Queue;\r\n \r\npublic class G3 {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n \r\n\tvoid solve()\r\n\t{\r\n\t\tfinal int mod = 998244353;\r\n\t\tint n = ni();\r\n\t\tint[] a = na(26);\r\n\t\tlong all = 26 * 26 * pow(25, n-2, mod) % mod;\r\n \r\n\t\tlong[][][] dp = new long[3][n+1][n+1];\r\n\t\tdp[0][1][0] = 1;\r\n\t\tdp[1][0][1] = 1;\r\n\t\tdp[2][0][0] = 1;\r\n\t\tfor(int i = 0;i < n-1;i++){\r\n\t\t\tlong[][][] ndp = new long[3][n+1][n+1];\r\n\t\t\tif(i == (n+1)/2-1){\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else {\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 23;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n \r\n\t\t\t}\r\n\t\t\tdp = ndp;\r\n\t\t}\r\n \r\n\t\tlong[] sdp = new long[n+1];\r\n\t\tfor(int i = 0;i <= n;i++){\r\n\t\t\tfor(int j = 0;j <= n;j++){\r\n\t\t\t\tsdp[i] += dp[0][i][j] + dp[1][i][j] + dp[2][i][j] * 24;\r\n\t\t\t}\r\n\t\t\tsdp[i] %= mod;\r\n\t\t}\r\n \r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\tall -= sdp[k];\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int j = i+1;j < 26;j++){\r\n\t\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\t\tfor(int l = a[j]+1;l+k <= n;l++){\r\n\t\t\t\t\t\tall += (dp[0][k][l] + dp[1][k][l] + dp[2][k][l] * 24);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tall %= mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\tall %= mod;\r\n \r\n\t\tif(all < 0)all += mod;\r\n\t\tout.println(all);\r\n\t}\r\n \r\n\tpublic static long pow(long a, long n, long mod) {\r\n\t\t//\t\ta %= mod;\r\n\t\tlong ret = 1;\r\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\tfor (; x >= 0; x--) {\r\n\t\t\tret = ret * ret % mod;\r\n\t\t\tif (n << 63 - x < 0) ret = ret * a % mod;\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n \r\n \r\n\tpublic static long invl(long a, long mod) {\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\treturn p < 0 ? p + mod : p;\r\n\t}\r\n \r\n \r\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\r\n\t\tif (n < 0 || r < 0 || r > n) return 0;\r\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\r\n\t}\r\n \r\n \r\n\tpublic static int[][] enumFIF(int n, int mod) {\r\n\t\tint[] f = new int[n + 1];\r\n\t\tint[] invf = new int[n + 1];\r\n\t\tf[0] = 1;\r\n\t\tfor (int i = 1; i <= n; i++) {\r\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\r\n\t\t}\r\n\t\tlong a = f[n];\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\r\n\t\tfor (int i = n - 1; i >= 0; i--) {\r\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\r\n\t\t}\r\n\t\treturn new int[][]{f, invf};\r\n\t}\r\n \r\n \r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new G3().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n \r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n \r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n \r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n \r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n \r\n\tprivate int ni() { return (int)nl(); }\r\n \r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n \r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n \r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n \r\n\t\tprivate FastWriter(){out = null;}\r\n \r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n \r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n \r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n \r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n \r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n \r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n \r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n \r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n \r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "31192c413e049f7bff8e59352e82e47c", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.NavigableMap;\nimport java.util.NoSuchElementException;\nimport java.util.Objects;\nimport java.util.Set;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.stream.Collectors;\n\npublic class Solution {\n private final ModuloCalculator moduloCalculator;\n private final PolynomialCalculator polynomialCalculator;\n private final int N;\n private final Map decimalToLongMap = new HashMap<>();\n private NavigableMap oldInterval2PolyMap = new TreeMap<>();\n private NavigableMap newInterVal2PolyMap = new TreeMap<>();\n private final List x_es;\n private static final Decimal ZERO_DECIMAL = Decimal.getInteger(0, true);\n private static final Decimal ONE = Decimal.getInteger(1, true);\n\n private Solution(final ModuloCalculator moduloCalculator,\n final PolynomialCalculator polynomialCalculator,\n final String[] decimalStrings) {\n this.moduloCalculator = moduloCalculator;\n this.polynomialCalculator = polynomialCalculator;\n this.N = decimalStrings.length;\n x_es = Collections.unmodifiableList(Arrays.stream(decimalStrings)\n .map(d -> MathUtils.getDecimal(d, moduloCalculator))\n .collect(Collectors.toList()));\n for (final Decimal x : x_es) {\n addLongOfDecimal(x);\n }\n }\n\n private long solve() {\n init();\n for (int i = 1; i < N; i++) {\n switchMaps();\n final Decimal hardUpperLimit = x_es.get(i);\n final Iterable nextIterPoints = getNewPointsList();\n for (final Decimal point : nextIterPoints) {\n newInterVal2PolyMap.put(point, getIntegrationOfLen1(point, oldInterval2PolyMap));\n decimalToLongMap.computeIfAbsent(point, k -> k.getLong(moduloCalculator));\n }\n //TODO: Shubham -> decimal to long map might be cleared over here\n newInterVal2PolyMap.tailMap(hardUpperLimit).clear();\n final Map.Entry largestEntry = newInterVal2PolyMap.lastEntry();\n // largestEntry is not null as zero will always be there\n if (!polynomialCalculator.isZero(largestEntry.getValue())) {\n newInterVal2PolyMap.put(hardUpperLimit, PolynomialCalculator.getZeroPolynomial());\n }\n }\n return integrateFully();\n }\n\n private long integrateFully() {\n long result = 0;\n Decimal ub = null;\n Decimal lb;\n long[] poly = null;\n for (final Map.Entry entry : newInterVal2PolyMap.entrySet()) {\n lb = ub;\n ub = entry.getKey();\n if (lb != null) {\n result = moduloCalculator.add(result,\n polynomialCalculator.integrate(poly,\n new long[]{decimalToLongMap.get(lb)},\n new long[]{decimalToLongMap.get(ub)})[0]);\n }\n poly = entry.getValue();\n }\n return result;\n }\n\n // Integrate from (highestPoint-1) to highestPoint\n private long[] getIntegrationOfLen1(final Decimal highestPoint, final NavigableMap oldPt2Poly) {\n long[] result = PolynomialCalculator.getZeroPolynomial();\n result = polynomialCalculator.add(result, integrateRightPartition(highestPoint, oldPt2Poly));\n result = polynomialCalculator.add(result, integrateMiddlePartitions(oldPt2Poly, highestPoint));\n result = polynomialCalculator.add(result, integrateLeftPartition(highestPoint, oldPt2Poly));\n return result;\n }\n\n private long[] integrateRightPartition(final Decimal highestPoint, final NavigableMap oldPt2Poly) {\n final long[] X = new long[]{1, 0};\n Decimal ub = oldPt2Poly.floorKey(highestPoint); // won't be null\n assert ub != null;\n return polynomialCalculator.integrate(oldPt2Poly.get(ub), new long[]{decimalToLongMap.get(ub)}, X);\n }\n\n private long[] integrateLeftPartition(final Decimal highestPoint, final NavigableMap oldPt2Poly) {\n final long[] X_MINUS_1 = new long[]{1, -1};\n final Decimal lowerLimit = oldPt2Poly.floorKey(highestPoint.subtract(ONE));\n if (lowerLimit == null) {\n return PolynomialCalculator.getZeroPolynomial();\n }\n final long[] integrand = oldPt2Poly.get(lowerLimit);\n Decimal upperLimit = oldPt2Poly.higherKey(lowerLimit);\n if (upperLimit == null || upperLimit.compareTo(highestPoint) > 0) {\n return polynomialCalculator.integrate(integrand, X_MINUS_1, new long[]{decimalToLongMap.get(lowerLimit)});\n }\n return polynomialCalculator.integrate(integrand, X_MINUS_1, new long[]{decimalToLongMap.get(upperLimit)});\n }\n\n private long[] integrateMiddlePartitions(final NavigableMap oldPt2Poly, Decimal highestPoint) {\n final Decimal lowestPoint = highestPoint.subtract(ONE);\n Decimal ub = oldPt2Poly.floorKey(highestPoint); // won't be null\n assert ub != null;\n Decimal lb = oldPt2Poly.lowerKey(ub);\n long[] result = PolynomialCalculator.getZeroPolynomial();\n while (lb != null && lb.compareTo(lowestPoint) > 0) {\n final long[] integrand = oldPt2Poly.get(lb);\n final long lowerLimit = decimalToLongMap.get(lb);\n final long upperLimit = decimalToLongMap.get(ub);\n final long[] deltaIntegration = polynomialCalculator.integrate(integrand,\n new long[]{lowerLimit},\n new long[]{upperLimit});\n result = polynomialCalculator.add(result, deltaIntegration);\n ub = lb;\n lb = oldPt2Poly.lowerKey(lb);\n }\n return result;\n }\n\n private Iterable getNewPointsList() {\n final Set setOfPoints = new HashSet<>();\n for (final Decimal point : oldInterval2PolyMap.keySet()) {\n setOfPoints.add(point);\n setOfPoints.add(point.add(ONE));\n }\n final List listOfPoints = new ArrayList<>(setOfPoints);\n Collections.sort(listOfPoints);\n return listOfPoints;\n }\n\n private void switchMaps() {\n final NavigableMap temp = newInterVal2PolyMap;\n newInterVal2PolyMap = oldInterval2PolyMap;\n oldInterval2PolyMap = temp;\n newInterVal2PolyMap.clear();\n }\n\n private void init() {\n final Decimal firstUb = min(ONE, x_es.get(0));\n addLongOfDecimal(ZERO_DECIMAL);\n addLongOfDecimal(firstUb);\n final long[] firstPoly = new long[]{1};\n newInterVal2PolyMap.put(ZERO_DECIMAL, firstPoly);\n newInterVal2PolyMap.put(firstUb, PolynomialCalculator.getZeroPolynomial());\n }\n\n private void addLongOfDecimal(final Decimal firstUb) {\n decimalToLongMap.put(firstUb, firstUb.getLong(moduloCalculator));\n }\n\n private static Decimal min(final Decimal d1, final Decimal d2) {\n if (d1.compareTo(d2) < 0) {\n return d1;\n }\n return d2;\n }\n\n public static void main(String[] args) {\n final long BASE = 998244353;\n final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n final InputReader reader = new InputReader(br);\n final int N = reader.nextInt();\n final String[] x_es = new String[N];\n final ModuloCalculator moduloCalculator = new ModuloCalculator(BASE);\n final PolynomialCalculator polynomialCalculator = new PolynomialCalculator(moduloCalculator);\n for (int i = 0; i < N; i++) {\n x_es[i] = reader.next();\n }\n final Solution solver = new Solution(moduloCalculator, polynomialCalculator, x_es);\n System.out.println(solver.solve());\n }\n}\n\n/**\n * Assumes polynomial as an array of coefficients\n * Index 0 is the coefficient of the highest degree term\n */\nclass PolynomialCalculator {\n private final static long[] ZERO_POLYNOMIAL = new long[0];\n private final ModuloCalculator moduloCalculator;\n\n public PolynomialCalculator(final ModuloCalculator moduloCalculator) {\n this.moduloCalculator = moduloCalculator;\n }\n\n public long[] add(final long[] _p1, final long[] _p2) {\n final long[] p1 = clean(_p1);\n final long[] p2 = clean(_p2);\n final int numCoeffs;\n final long[] smallerPolynomial;\n final long[] largerPolynomial;\n if (p1.length <= p2.length) {\n numCoeffs = p2.length;\n largerPolynomial = p2;\n smallerPolynomial = p1;\n } else {\n numCoeffs = p1.length;\n smallerPolynomial = p2;\n largerPolynomial = p1;\n }\n final long[] result = new long[numCoeffs];\n final int deltaInLengths = largerPolynomial.length - smallerPolynomial.length;\n for (int smallerIndex = 0; smallerIndex < smallerPolynomial.length; smallerIndex++) {\n final int largerIndex = smallerIndex + deltaInLengths;\n result[largerIndex] = smallerPolynomial[smallerIndex] + largerPolynomial[largerIndex];\n }\n System.arraycopy(largerPolynomial, 0, result, 0, deltaInLengths);\n return clean(result);\n }\n\n public long[] multiply(final long[] p, long scalarMultiplier) {\n return multiply(p, new long[]{scalarMultiplier});\n }\n\n public long[] subtract(final long[] p1, final long[] p2) {\n return add(p1, multiply(p2, -1));\n }\n\n /**\n * Uses naive way of multiplying. Doesn't use FFT\n */\n public long[] multiply(long[] _p1, long[] _p2) {\n final long[] p1 = clean(_p1);\n final long[] p2 = clean(_p2);\n\n if (isZero(p1) || isZero(p2)) {\n return ZERO_POLYNOMIAL;\n }\n\n final int degree1 = p1.length - 1;\n final int degree2 = p2.length - 1;\n final int degreeOfResult = degree1 + degree2;\n final long[] result = new long[degreeOfResult + 1];\n for (int i = 0; i <= degree1; i++) {\n final int pow1 = degree1 - i;\n for (int j = 0; j <= degree2; j++) {\n final int pow2 = degree2 - j;\n final int resultingTermPower = pow1 + pow2;\n final int resultIndex = degreeOfResult - resultingTermPower;\n result[resultIndex] = moduloCalculator.normalize(\n result[resultIndex] + moduloCalculator.normalize(p1[i] * p2[j]));\n }\n }\n return clean(result);\n }\n\n public boolean isZero(final long[] input) {\n return Arrays.equals(ZERO_POLYNOMIAL, clean(input));\n }\n\n public long evaluateAt(final long[] p, final long x) {\n final long[] evalResult = substitute(p, new long[]{x});\n return evalResult.length == 0 ? 0 : evalResult[0];\n }\n\n /**\n * Includes pow\n */\n public List getAllPowersTill(final long[] base, final int pow) {\n final List result = new ArrayList<>(pow);\n result.add(new long[]{1});\n for (int i = 1; i <= pow; i++) {\n result.add(multiply(result.get(i - 1), base));\n }\n return result;\n }\n\n public long[] substitute(final long[] _parent, final long[] _child) {\n final long[] parent = clean(_parent);\n final long[] child = clean(_child);\n long[] result = ZERO_POLYNOMIAL;\n for (final long coefficientInParent : parent) {\n final long[] constantPolynomial = {coefficientInParent};\n result = add(multiply(result, child), constantPolynomial);\n }\n return clean(result);\n }\n\n /**\n * Performs mod operation and cleans leading zeroes\n */\n private long[] clean(final long[] input) {\n int countOfLeadingZeroes = 0;\n for (int i = 0; i < input.length && moduloCalculator.normalize(input[i]) == 0; i++) {\n ++countOfLeadingZeroes;\n }\n if (countOfLeadingZeroes == input.length) {\n return ZERO_POLYNOMIAL;\n }\n final int retLength = input.length - countOfLeadingZeroes;\n final long[] ret = new long[retLength];\n for (int i = countOfLeadingZeroes; i < input.length; i++) {\n ret[i - countOfLeadingZeroes] = moduloCalculator.normalize(input[i]);\n }\n return ret;\n }\n\n public long[] integrate(long[] integrand, long[] lowerLimit, long[] upperLimit) {\n integrand = clean(integrand);\n lowerLimit = clean(lowerLimit);\n upperLimit = clean(upperLimit);\n if (isZero(integrand)) {\n return ZERO_POLYNOMIAL;\n }\n final long[] indefiniteIntegral = new long[integrand.length + 1];\n final int degreeOfIntegrand = integrand.length - 1;\n for (int i = 0; i < integrand.length; i++) {\n final int degreeOfTermInInResult = degreeOfIntegrand - i + 1;\n indefiniteIntegral[i] = moduloCalculator.getExactQuotient(integrand[i], degreeOfTermInInResult);\n }\n return subtract(substitute(indefiniteIntegral, upperLimit), substitute(indefiniteIntegral, lowerLimit));\n }\n\n public static long[] getZeroPolynomial() {\n return ZERO_POLYNOMIAL;\n }\n}\n\nclass InputReader {\n private final BufferedReader br;\n private StringTokenizer st;\n\n public InputReader(final BufferedReader br) {\n this.br = br;\n\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n final String line = br.readLine();\n if (line == null) {\n throw new NoSuchElementException();\n }\n st = new StringTokenizer(line);\n } catch (final 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 // Assumes chars are not concatenated\n public char nextChar() {\n final String str = next();\n assert str.length() == 1;\n return str.charAt(0);\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\nclass ModuloCalculator {\n private final long base;\n private static final long NO_BASE = 0;\n\n public ModuloCalculator(final long base) {\n assert base >= 0;\n this.base = base;\n }\n\n public static ModuloCalculator getWithoutMod() {\n return new ModuloCalculator(NO_BASE);\n }\n\n public long getInverse(final long y) {\n assert base > 0;\n final long x = normalize(y);\n assert x > 0;\n final BezoutRepr bezoutRepr = MathUtils.getBezoutRepr(x, base);\n assert bezoutRepr.getGcd() == 1;\n return normalize(bezoutRepr.getCoeffSmall());\n }\n\n public long add(final long x, final long y) {\n return normalize(normalize(x) + normalize(y));\n }\n\n public long subtract(final long x, final long y) {\n return add(x, -y);\n }\n\n public long multiply(final long x, final long y) {\n return normalize(normalize(x) * normalize(y));\n }\n\n public long getExactQuotient(final long x, final long y) {\n if (base != NO_BASE) {\n return multiply(x, getInverse(y));\n }\n assert x % y == 0;\n return x / y;\n }\n\n public long power(final long _base, final int pow) {\n return _power(normalize(_base), pow);\n }\n\n private long _power(final long _base, final long pow) {\n if (pow == 0) {\n return 1;\n }\n assert pow > 0;\n long partialResult = _power(_base, pow / 2);\n partialResult = normalize(partialResult * partialResult);\n if (pow % 2 == 1) {\n partialResult = normalize(partialResult * _base);\n }\n return partialResult;\n }\n\n /**\n * @return a value b/w 0 <= ret < b\n */\n public long normalize(final long y) {\n if (base == 0) {\n return y;\n }\n long x = y % base;\n if (x < 0) {\n x = base + x;\n }\n return x;\n }\n}\n\nclass Decimal implements Comparable {\n private final long integerPart;\n private final long fractionalPart;\n private final int fractionalLength;\n private final short sign;\n private final static ModuloCalculator noModCalculator = ModuloCalculator.getWithoutMod();\n\n public Decimal(final long integerPart,\n final long _fractionalPart,\n final int fractionalLength,\n final boolean isNonNegative) {\n checkInvariant(integerPart, _fractionalPart, fractionalLength);\n this.integerPart = integerPart;\n\n // trim fractional Part\n int fracLenDecrement = 0;\n long fracPart = _fractionalPart;\n while (fracPart % 10 == 0 && fracLenDecrement < fractionalLength) {\n fracPart /= 10;\n fracLenDecrement++;\n }\n this.fractionalPart = fracPart;\n this.fractionalLength = fractionalLength - fracLenDecrement;\n\n this.sign = (short) ((isNonNegative || (integerPart == 0 && this.fractionalLength == 0)) ? 1 : -1);\n }\n\n public static Decimal getInteger(final long integerPart, final boolean isNonNegative) {\n return new Decimal(integerPart, 0, 0, isNonNegative);\n }\n\n private void checkInvariant(final long integerPart, final long fractionalPart, final int fractionalLength) {\n assert integerPart >= 0;\n assert fractionalPart >= 0;\n assert fractionalLength >= 0;\n assert fractionalPart == 0 || String.valueOf(fractionalPart).length() <= fractionalLength;\n }\n\n public long getIntegerPart() {\n return integerPart;\n }\n\n public long getFractionalPart() {\n return fractionalPart;\n }\n\n public int getFractionalLength() {\n return fractionalLength;\n }\n\n public short getSign() {\n return sign;\n }\n\n private long signedAddition(final long primary, final long secondary) {\n return primary + (primary >= 0 ? secondary : -secondary);\n }\n\n //VisibleForTesting\n Decimal invert() {\n return new Decimal(getIntegerPart(), getFractionalPart(), getFractionalLength(), getSign() < 0);\n }\n\n public Decimal add(final Decimal that) {\n // 20.035 - 25.0009 = -4.9659\n// 35 * 10^(-3), 9 * 10^(-4)\n // 350 * 10^(-4), 9 * 10^(-4)\n // 341 * 10 ^ -4\n final int resFracLen = Math.max(this.getFractionalLength(), that.getFractionalLength());\n final long powOf10 = noModCalculator.power(10, resFracLen);\n final long powThis = noModCalculator.power(10, resFracLen - this.getFractionalLength());\n final long powThat = noModCalculator.power(10, resFracLen - that.getFractionalLength());\n final long frac1 = this.getSign() * powThis * this.getFractionalPart();\n final long frac2 = that.getSign() * powThat * that.getFractionalPart();\n long resFrac = frac1 + frac2;\n long intPart = this.getSign() * this.getIntegerPart() + that.getSign() * that.getIntegerPart();\n\n // check for carry\n if (Math.abs(resFrac) >= powOf10) {\n // both frac part must have same sign => both nums have same sign\n intPart += ((resFrac >= 0) ? 1 : -1);\n resFrac -= ((resFrac >= 0) ? powOf10 : -powOf10);\n }\n\n // make fractional part have same sign as the int part\n if (intPart * resFrac < 0) {\n resFrac += ((resFrac < 0) ? powOf10 : -powOf10);\n intPart += ((resFrac < 0) ? 1 : -1);\n }\n\n return new Decimal(Math.abs(intPart), Math.abs(resFrac), resFracLen, intPart >= 0 && resFrac >= 0);\n }\n\n public long getLong(final ModuloCalculator moduloCalculator) {\n return moduloCalculator.normalize(this.getSign() * this.integerPart + moduloCalculator.normalize(\n this.getSign() * this.fractionalPart * moduloCalculator.getInverse(moduloCalculator.power(10,\n this.fractionalLength))));\n }\n\n public Decimal subtract(final Decimal that) {\n return add(that.invert());\n }\n\n @Override\n public String toString() {\n return \"Decimal{\" + \"integerPart=\" + integerPart + \", fractionalPart=\" + fractionalPart + \", fractionalLength=\"\n + fractionalLength + \", sign=\" + sign + '}';\n }\n\n @Override\n public boolean equals(final Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n final Decimal decimal = (Decimal) o;\n return integerPart == decimal.integerPart && fractionalPart == decimal.fractionalPart\n && fractionalLength == decimal.fractionalLength && sign == decimal.sign;\n }\n\n @Override\n public int hashCode() {\n return Objects.hash(integerPart, fractionalPart, fractionalLength, sign);\n }\n\n @Override\n public int compareTo(final Decimal that) {\n if (this.getSign() < 0 && that.getSign() > 0) {\n return -1;\n }\n if (this.getSign() > 0 && that.getSign() < 0) {\n return 1;\n }\n // both have same signs\n final int sign = this.getSign();\n if (this.getIntegerPart() > that.getIntegerPart()) {\n return sign;\n }\n if (this.getIntegerPart() < that.getIntegerPart()) {\n return -sign;\n }\n final int resFracLen = Math.max(this.getFractionalLength(), that.getFractionalLength());\n final long powThis = noModCalculator.power(10, resFracLen - this.getFractionalLength());\n final long powThat = noModCalculator.power(10, resFracLen - that.getFractionalLength());\n final long frac1 = powThis * this.getFractionalPart();\n final long frac2 = powThat * that.getFractionalPart();\n if (frac1 > frac2) {\n return sign;\n }\n if (frac1 < frac2) {\n return -sign;\n }\n return 0;\n }\n}\n\nclass BezoutRepr {\n private final long coeffSmall;\n private final long coeffLarge;\n private final long gcd;\n private final int numCalls;\n\n public BezoutRepr(final long coeffSmall, final long coeffLarge, final long gcd, final int numCalls) {\n this.coeffSmall = coeffSmall;\n this.coeffLarge = coeffLarge;\n this.gcd = gcd;\n this.numCalls = numCalls;\n }\n\n public long getCoeffSmall() {\n return coeffSmall;\n }\n\n public long getCoeffLarge() {\n return coeffLarge;\n }\n\n public long getGcd() {\n return gcd;\n }\n\n public int getNumCalls() {\n return numCalls;\n }\n\n @Override\n public String toString() {\n return \"BezoutRepr{\" + \"coeffSmall=\" + coeffSmall + \", coeffLarge=\" + coeffLarge + \", gcd=\" + gcd\n + \", numCalls=\" + numCalls + '}';\n }\n}\n\nclass MathUtils {\n /**\n * Assumes x <= y\n *\n * @param smaller - >= 0\n * @param larger - >= x\n */\n public static BezoutRepr getBezoutRepr(final long smaller, final long larger) {\n assert smaller >= 0;\n assert smaller <= larger;\n if (smaller == 0) {\n return new BezoutRepr(1, 1, larger, 1);\n }\n final long r = larger % smaller;\n final long q = larger / smaller;\n // gcd(x, y): y = q1*x + r1 => r1 = y - q1*x\n // a * smaller(r1) + b * larger(x) = gcd\n // => a * (y - q1*x) + b * x = gcd\n // => (b - a * q1) * x + a * y = gcd\n // => a' = b - a * q1\n // => b' = a\n // gcd(r, x): x = q2*r + r2 => gcd = r2 = x - q2*r1 (1, -q2)\n final BezoutRepr child = getBezoutRepr(r, smaller);\n long smallCoeff = child.getCoeffLarge() - child.getCoeffSmall() * q;\n final long gcd = child.getGcd();\n return new BezoutRepr(smallCoeff, child.getCoeffSmall(), gcd, child.getNumCalls() + 1);\n }\n\n // Assumes first character is not decimal or - (for -ve number)\n public static Decimal getDecimal(final String decimalNum, final ModuloCalculator calculator) {\n assert decimalNum.length() > 0 && decimalNum.charAt(0) != '.' && decimalNum.charAt(0) != '-';\n final String[] split = decimalNum.split(\"\\\\.\");\n if (split.length == 1) {\n return Decimal.getInteger(Long.parseLong(split[0]), true);\n }\n return new Decimal(Long.parseLong(split[0]), Long.parseLong(split[1]), split[1].length(), true);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a45cda30f4272b4a293465a099476fab", "src_uid": "fed8173bf7731f3d663467cc0131d788", "difficulty": 3400.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tString s;\n\tint q;\n\t\n\tint f(int q, int t) {\n\t\tif (t == 0 || q > 1) return q;\n\t\treturn 1 - q;\n\t}\n\t\n\tint token() {\n\t\tif (s.charAt(q) == '(') {\n\t\t\tq++;\n\t\t\tint t1 = token();\n\t\t\tchar op = s.charAt(q++);\n\t\t\tint t2 = token();\n\t\t\tq++;\n\t\t\tswitch (op) {\n\t\t\tcase '&':\n\t\t\t\tif (t1 == 0 || t2 == 0) return 0;\n\t\t\t\tif (t1 == 1) return t2;\n\t\t\t\tif (t2 == 1) return t1;\n\t\t\t\tif (t1 == 2 && t2 == 2) return 2;\n\t\t\t\treturn 3;\n\t\t\tcase '|':\n\t\t\t\tif (t1 == 1 || t2 == 1) return 1;\n\t\t\t\tif (t1 == 0) return t2;\n\t\t\t\tif (t2 == 0) return t1;\n\t\t\t\tif (t1 == 2 && t2 == 2) return 2;\n\t\t\t\treturn 3;\n\t\t\tcase '^':\n\t\t\t\tif (t1 < 2) return f(t2, t1);\n\t\t\t\tif (t2 < 2) return f(t1, t2);\n\t\t\t\tif (t1 == t2) return 2;\n\t\t\t\treturn 3;\n\t\t\t}\n\t\t\treturn -1;\n\t\t} else {\n\t\t\tif (s.charAt(q) == '?') {\n\t\t\t\tq++;\n\t\t\t\treturn 3;\n\t\t\t}\n\t\t\treturn s.charAt(q++) - '0';\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\ts = nextToken();\n\t\tq = 0;\n\t\tint res = token();\n\t\tout.println(res == 2? \"NO\" : \"YES\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\t// Locale.setDefault(Locale.UK);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// new Thread(null, new Solution(), \"1\", 1 << 28).start();\n\t\t(new Solution()).run();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7954158cf66bb8bd5dfd804551d38c06", "src_uid": "e060d26dc3b9ffb628f2380781d1cbe9", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\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 TaskE1 solver = new TaskE1();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE1 {\n static final int DENOM = 100;\n static final long MODULO = (long) 1e9 + 7;\n private static final long INVDENOM = BigInteger.valueOf(DENOM).modInverse(BigInteger.valueOf(MODULO)).longValue();\n int n;\n long[][] p;\n int[][] s;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n p = new long[n][n];\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < n; ++j) {\n p[i][j] = in.nextInt() * INVDENOM % MODULO;\n }\n }\n int[] match = new int[n];\n Arrays.fill(match, -1);\n s = new int[n][n];\n int[] stack = new int[n];\n int[] via = new int[n];\n int[] ptr = new int[n];\n long res = rec(match, stack, via, ptr, -1, 0);\n out.println(res);\n }\n\n private long rec(int[] match, int[] stack, int[] via, int[] ptr, int sp, int next) {\n for (int i = 0; i < sp; ++i)\n if (via[stack[i]] == -1) {\n throw new RuntimeException();\n }\n if (sp == 0) return 0;\n if (sp == -1) {\n if (next >= n) {\n return 1;\n }\n Arrays.fill(via, -1);\n Arrays.fill(ptr, 0);\n Arrays.fill(stack, -1);\n stack[0] = next;\n via[next] = -2;\n return rec(match, stack, via, ptr, 1, next);\n } else {\n int cur = stack[sp - 1];\n int dest = ptr[cur];\n if (dest < n && match[dest] < 0) {\n if (s[cur][dest] == 0) {\n s[cur][dest] = 1;\n long res = p[cur][dest] * rec(match, stack, via, ptr, sp, next);\n s[cur][dest] = 2;\n res += (1 - p[cur][dest]) * rec(match, stack, via, ptr, sp, next);\n res %= MODULO;\n if (res < 0) res += MODULO;\n s[cur][dest] = 0;\n return res;\n }\n if (s[cur][dest] == 1) {\n int[] nmatch = match.clone();\n int[] nstack = new int[n];\n int[] nvia = new int[n];\n int[] nptr = new int[n];\n for (int i = 1; i < sp; ++i) {\n nmatch[via[stack[i]]] = stack[i - 1];\n }\n nmatch[dest] = cur;\n return rec(nmatch, nstack, nvia, nptr, -1, next + 1);\n }\n }\n int ndest = dest - n;\n if (ndest >= 0 && ndest < n && match[ndest] >= 0 && via[match[ndest]] == -1) {\n if (s[cur][ndest] == 0) {\n s[cur][ndest] = 1;\n long res = p[cur][ndest] * rec(match, stack, via, ptr, sp, next);\n s[cur][ndest] = 2;\n res += (1 - p[cur][ndest]) * rec(match, stack, via, ptr, sp, next);\n res %= MODULO;\n if (res < 0) res += MODULO;\n s[cur][ndest] = 0;\n return res;\n }\n if (s[cur][ndest] == 1) {\n int md = match[ndest];\n via[md] = ndest;\n stack[sp] = md;\n long res = rec(match, stack, via, ptr, sp + 1, next);\n stack[sp] = -1;\n via[md] = -1;\n return res;\n }\n }\n if (dest >= 2 * n) {\n long res = rec(match, stack, via, ptr, sp - 1, next);\n stack[sp - 1] = cur;\n return res;\n } else {\n ptr[cur] = dest + 1;\n long res = rec(match, stack, via, ptr, sp, next);\n ptr[cur] = dest;\n return res;\n }\n }\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "67c6d0eb37aee92170208134454106b3", "src_uid": "906d4e49566e63fddaf8eac7384c6284", "difficulty": 3100.0}